linux-ti33x-psp 3.2: add support for Towertech TT3201 CAN cape
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / 0022-beaglebone-add-support-for-Towertech-TT3201-CAN-cape.patch
1 From af31b4d5a2d52284b169633b9a601c39c7300300 Mon Sep 17 00:00:00 2001
2 From: Alessandro Zummo <a.zummo@towertech.it>
3 Date: Thu, 9 Feb 2012 12:46:52 +0100
4 Subject: [PATCH 22/22] beaglebone: add support for Towertech TT3201 CAN cape
6 Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
7 ---
8  arch/arm/mach-omap2/board-am335xevm.c |   54 ++++++++++++++++++++++++++++++++-
9  arch/arm/mach-omap2/mux33xx.c         |    4 +-
10  drivers/net/can/dev.c                 |    8 ++--
11  drivers/net/can/mcp251x.c             |   47 ++++++++++++++++++++++------
12  4 files changed, 96 insertions(+), 17 deletions(-)
14 diff --git a/arch/arm/mach-omap2/board-am335xevm.c b/arch/arm/mach-omap2/board-am335xevm.c
15 index 538466d..36efca1 100644
16 --- a/arch/arm/mach-omap2/board-am335xevm.c
17 +++ b/arch/arm/mach-omap2/board-am335xevm.c
18 @@ -38,6 +38,7 @@
19  #include <linux/pwm_backlight.h>
20  #include <linux/pwm/pwm.h>
21  #include <linux/w1-gpio.h>
22 +#include <linux/can/platform/mcp251x.h>
23  
24  /* LCD controller is similar to DA850 */
25  #include <video/da8xx-fb.h>
26 @@ -829,6 +830,15 @@ static struct pinmux_config d_can_ia_pin_mux[] = {
27         {NULL, 0},
28  };
29  
30 +static struct pinmux_config tt3201_pin_mux[] = {
31 +       {"uart1_rxd.d_can1_tx", OMAP_MUX_MODE2 | AM33XX_PIN_OUTPUT },
32 +       {"uart1_txd.d_can1_rx", OMAP_MUX_MODE2 | AM33XX_PIN_INPUT_PULLUP },
33 +       {"mcasp0_fsr.gpio3_19", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT_PULLUP },
34 +       {"mcasp0_ahclkx.gpio3_21", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT_PULLUP },
35 +       {"ecap0_in_pwm0_out.spi1_cs1", OMAP_MUX_MODE2 | AM33XX_PIN_OUTPUT_PULLUP },
36 +       {NULL, 0},
37 +};
38 +
39  /* Module pin mux for uart2 */
40  static struct pinmux_config uart2_pin_mux[] = {
41         {"spi0_sclk.uart2_rxd", OMAP_MUX_MODE1 | AM33XX_SLEWCTRL_SLOW |
42 @@ -1788,6 +1798,44 @@ static void i2c1_init(int evm_id, int profile)
43         return;
44  }
45  
46 +static struct mcp251x_platform_data mcp251x_info = {
47 +       .oscillator_frequency = 16000000,
48 +};
49 +
50 +static struct spi_board_info tt3201_spi_info[] = {
51 +       {
52 +               .modalias       = "mcp2515",
53 +               .max_speed_hz   = 10000000,
54 +               .bus_num        = 2,
55 +               .chip_select    = 0,
56 +               .mode           = SPI_MODE_0,
57 +               .platform_data  = &mcp251x_info,
58 +       },
59 +       {
60 +               .modalias       = "mcp2515",
61 +               .max_speed_hz   = 10000000,
62 +               .bus_num        = 2,
63 +               .chip_select    = 1,
64 +               .mode           = SPI_MODE_0,
65 +               .platform_data  = &mcp251x_info,
66 +       },
67 +};
68 +
69 +static void tt3201_init(int evm_id, int profile)
70 +{
71 +       pr_info("TowerTech TT3201 CAN Cape\n");
72 +
73 +       setup_pin_mux(spi1_pin_mux);
74 +       setup_pin_mux(tt3201_pin_mux);
75 +
76 +       tt3201_spi_info[0].irq = gpio_to_irq(GPIO_TO_PIN(3, 19));
77 +       tt3201_spi_info[1].irq = gpio_to_irq(GPIO_TO_PIN(3, 21));
78 +
79 +       spi_register_board_info(tt3201_spi_info,
80 +               ARRAY_SIZE(tt3201_spi_info));
81 +
82 +       am33xx_d_can_init(1);
83 +}
84  static void beaglebone_cape_setup(struct memory_accessor *mem_acc, void *context)
85  {
86         capecount++;
87 @@ -1835,7 +1883,11 @@ static void beaglebone_cape_setup(struct memory_accessor *mem_acc, void *context
88                 beaglebone_tsadcpins_free = 0;
89         }
90         
91 -       
92 +       if (!strncmp("TT3201-001", cape_config.partnumber, 10)) {
93 +               pr_info("BeagleBone cape: initializing CAN cape\n");
94 +               tt3201_init(0,0);
95 +       }
96 +
97         if ((capecount > 3) && (beaglebone_tsadcpins_free == 1)) {
98                 pr_info("BeagleBone cape: exporting ADC pins to sysfs\n");
99                 bone_tsc_init(0,0);
100 diff --git a/arch/arm/mach-omap2/mux33xx.c b/arch/arm/mach-omap2/mux33xx.c
101 index 0a06241..e4f3bd9 100644
102 --- a/arch/arm/mach-omap2/mux33xx.c
103 +++ b/arch/arm/mach-omap2/mux33xx.c
104 @@ -318,10 +318,10 @@ static struct omap_mux __initdata am33xx_muxmodes[] = {
105                 "uart1_rtsn", NULL, "d_can0_rx", "i2c2_scl",
106                 "spi1_cs1", NULL, NULL, "gpio0_13"),
107         _AM33XX_MUXENTRY(UART1_RXD, 0,
108 -               "uart1_rxd", "mmc1_sdwp", NULL, NULL,
109 +               "uart1_rxd", "mmc1_sdwp", "d_can1_tx", NULL,
110                 NULL, "pr1_uart0_rxd_mux1", NULL, "gpio0_14"),
111         _AM33XX_MUXENTRY(UART1_TXD, 0,
112 -               "uart1_txd", "mmc2_sdwp", NULL, NULL,
113 +               "uart1_txd", "mmc2_sdwp", "d_can1_rx", NULL,
114                 NULL, "pr1_uart0_txd_mux1", NULL, "gpio0_15"),
115         _AM33XX_MUXENTRY(I2C0_SDA, 0,
116                 "i2c0_sda", NULL, NULL, NULL,
117 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
118 index 25695bd..bc1e87e 100644
119 --- a/drivers/net/can/dev.c
120 +++ b/drivers/net/can/dev.c
121 @@ -392,7 +392,7 @@ void can_restart(unsigned long data)
122         stats->rx_bytes += cf->can_dlc;
123  
124  restart:
125 -       dev_dbg(dev->dev.parent, "restarted\n");
126 +       netdev_dbg(dev, "restarted\n");
127         priv->can_stats.restarts++;
128  
129         /* Now restart the device */
130 @@ -400,7 +400,7 @@ restart:
131  
132         netif_carrier_on(dev);
133         if (err)
134 -               dev_err(dev->dev.parent, "Error %d during restart", err);
135 +               netdev_err(dev, "error %d during restart", err);
136  }
137  
138  int can_restart_now(struct net_device *dev)
139 @@ -433,7 +433,7 @@ void can_bus_off(struct net_device *dev)
140  {
141         struct can_priv *priv = netdev_priv(dev);
142  
143 -       dev_dbg(dev->dev.parent, "bus-off\n");
144 +       netdev_dbg(dev, "bus-off\n");
145  
146         netif_carrier_off(dev);
147         priv->can_stats.bus_off++;
148 @@ -545,7 +545,7 @@ int open_candev(struct net_device *dev)
149         struct can_priv *priv = netdev_priv(dev);
150  
151         if (!priv->bittiming.tq && !priv->bittiming.bitrate) {
152 -               dev_err(dev->dev.parent, "bit-timing not yet defined\n");
153 +               netdev_err(dev, "bit-timing not yet defined\n");
154                 return -EINVAL;
155         }
156  
157 diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
158 index 330140e..b3e231c 100644
159 --- a/drivers/net/can/mcp251x.c
160 +++ b/drivers/net/can/mcp251x.c
161 @@ -93,8 +93,9 @@
162  #  define CANCTRL_REQOP_LOOPBACK    0x40
163  #  define CANCTRL_REQOP_SLEEP      0x20
164  #  define CANCTRL_REQOP_NORMAL     0x00
165 -#  define CANCTRL_OSM              0x08
166  #  define CANCTRL_ABAT             0x10
167 +#  define CANCTRL_OSM              0x08
168 +#  define CANCTRL_CLKEN                    0x04
169  #define TEC          0x1c
170  #define REC          0x1d
171  #define CNF1         0x2a
172 @@ -287,7 +288,7 @@ static void mcp251x_clean(struct net_device *net)
173  /*
174   * Note about handling of error return of mcp251x_spi_trans: accessing
175   * registers via SPI is not really different conceptually than using
176 - * normal I/O assembler instructions, although it's much more
177 + * normal I/O assembly instructions, although it's much more
178   * complicated from a practical POV. So it's not advisable to always
179   * check the return value of this function. Imagine that every
180   * read{b,l}, write{b,l} and friends would be bracketed in "if ( < 0)
181 @@ -490,7 +491,7 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx)
182  
183  static void mcp251x_hw_sleep(struct spi_device *spi)
184  {
185 -       mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_SLEEP);
186 +//     mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_SLEEP);
187  }
188  
189  static netdev_tx_t mcp251x_hard_start_xmit(struct sk_buff *skb,
190 @@ -547,13 +548,16 @@ static int mcp251x_set_normal_mode(struct spi_device *spi)
191  
192         if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) {
193                 /* Put device into loopback mode */
194 -               mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LOOPBACK);
195 +               mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LOOPBACK | CANCTRL_CLKEN);
196         } else if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
197                 /* Put device into listen-only mode */
198 -               mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LISTEN_ONLY);
199 +               mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LISTEN_ONLY | CANCTRL_CLKEN);
200         } else {
201                 /* Put device into normal mode */
202 -               mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_NORMAL);
203 +               mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_NORMAL | CANCTRL_CLKEN);
205 +                netdev_info(priv->net, "CANCTRL: 0x%02x\n",
206 +                  mcp251x_read_reg(spi, CANCTRL));
207  
208                 /* Wait for the device to enter normal mode */
209                 timeout = jiffies + HZ;
210 @@ -585,11 +589,15 @@ static int mcp251x_do_set_bittiming(struct net_device *net)
211                           (bt->prop_seg - 1));
212         mcp251x_write_bits(spi, CNF3, CNF3_PHSEG2_MASK,
213                            (bt->phase_seg2 - 1));
214 -       dev_info(&spi->dev, "CNF: 0x%02x 0x%02x 0x%02x\n",
216 +       netdev_info(net, "CNF: 0x%02x 0x%02x 0x%02x\n",
217                  mcp251x_read_reg(spi, CNF1),
218                  mcp251x_read_reg(spi, CNF2),
219                  mcp251x_read_reg(spi, CNF3));
220  
221 +       netdev_info(net, "CANCTRL: 0x%02x\n",
222 +                mcp251x_read_reg(spi, CANCTRL));
224         return 0;
225  }
226  
227 @@ -600,6 +608,7 @@ static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
228  
229         mcp251x_write_reg(spi, RXBCTRL(0),
230                           RXBCTRL_BUKT | RXBCTRL_RXM0 | RXBCTRL_RXM1);
232         mcp251x_write_reg(spi, RXBCTRL(1),
233                           RXBCTRL_RXM0 | RXBCTRL_RXM1);
234         return 0;
235 @@ -728,7 +737,9 @@ static void mcp251x_tx_work_handler(struct work_struct *ws)
236         mutex_lock(&priv->mcp_lock);
237         if (priv->tx_skb) {
238                 if (priv->can.state == CAN_STATE_BUS_OFF) {
240                         mcp251x_clean(net);
242                 } else {
243                         frame = (struct can_frame *)priv->tx_skb->data;
244  
245 @@ -827,21 +838,37 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
246  
247                 /* Update can state */
248                 if (eflag & EFLG_TXBO) {
250 +                       netdev_err(net, "err: bus off\n");
252                         new_state = CAN_STATE_BUS_OFF;
253                         can_id |= CAN_ERR_BUSOFF;
254                 } else if (eflag & EFLG_TXEP) {
256 +                       netdev_err(net, "err: txep\n");
258                         new_state = CAN_STATE_ERROR_PASSIVE;
259                         can_id |= CAN_ERR_CRTL;
260                         data1 |= CAN_ERR_CRTL_TX_PASSIVE;
262                 } else if (eflag & EFLG_RXEP) {
264 +                       netdev_err(net, "err: rxep\n");
266                         new_state = CAN_STATE_ERROR_PASSIVE;
267                         can_id |= CAN_ERR_CRTL;
268                         data1 |= CAN_ERR_CRTL_RX_PASSIVE;
269                 } else if (eflag & EFLG_TXWAR) {
271 +                       netdev_err(net, "err: txwar\n");
273                         new_state = CAN_STATE_ERROR_WARNING;
274                         can_id |= CAN_ERR_CRTL;
275                         data1 |= CAN_ERR_CRTL_TX_WARNING;
276                 } else if (eflag & EFLG_RXWAR) {
278 +                       netdev_err(net, "err: rxwar\n");
280                         new_state = CAN_STATE_ERROR_WARNING;
281                         can_id |= CAN_ERR_CRTL;
282                         data1 |= CAN_ERR_CRTL_RX_WARNING;
283 @@ -918,7 +945,7 @@ static int mcp251x_open(struct net_device *net)
284  
285         ret = open_candev(net);
286         if (ret) {
287 -               dev_err(&spi->dev, "unable to set initial baudrate!\n");
288 +               netdev_err(net, "failed to open can device\n");
289                 return ret;
290         }
291  
292 @@ -934,7 +961,7 @@ static int mcp251x_open(struct net_device *net)
293                   pdata->irq_flags ? pdata->irq_flags : IRQF_TRIGGER_FALLING,
294                   DEVICE_NAME, priv);
295         if (ret) {
296 -               dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq);
297 +               netdev_err(net, "failed to acquire irq %d\n", spi->irq);
298                 if (pdata->transceiver_enable)
299                         pdata->transceiver_enable(0);
300                 close_candev(net);
301 @@ -1071,7 +1098,7 @@ static int __devinit mcp251x_can_probe(struct spi_device *spi)
302  
303         ret = register_candev(net);
304         if (!ret) {
305 -               dev_info(&spi->dev, "probed\n");
306 +               netdev_info(priv->net, "probed\n");
307                 return ret;
308         }
309  error_probe:
310 -- 
311 1.7.2.5