[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / beaglebone / 0020-beaglebone-add-support-for-Towertech-TT3201-CAN-cape.patch
1 From fc2a970788a0181b495f79a78b35e6bdd6987aa8 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 20/56] 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 | 8 ++--
10 drivers/net/can/dev.c | 8 ++--
11 drivers/net/can/mcp251x.c | 47 ++++++++++++++++++++++------
12 4 files changed, 98 insertions(+), 19 deletions(-)
14 diff --git a/arch/arm/mach-omap2/board-am335xevm.c b/arch/arm/mach-omap2/board-am335xevm.c
15 index 3ba4bbc..a8dfcdf 100644
16 --- a/arch/arm/mach-omap2/board-am335xevm.c
17 +++ b/arch/arm/mach-omap2/board-am335xevm.c
18 @@ -40,6 +40,7 @@
19 #include <linux/pwm/pwm.h>
20 #include <linux/opp.h>
21 #include <linux/w1-gpio.h>
22 +#include <linux/can/platform/mcp251x.h>
24 /* LCD controller is similar to DA850 */
25 #include <video/da8xx-fb.h>
26 @@ -843,6 +844,15 @@ static struct pinmux_config d_can_ia_pin_mux[] = {
27 {NULL, 0},
28 };
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 @@ -1852,6 +1862,44 @@ static void i2c1_init(int evm_id, int profile)
43 return;
44 }
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 @@ -1899,7 +1947,11 @@ static void beaglebone_cape_setup(struct memory_accessor *mem_acc, void *context
88 beaglebone_tsadcpins_free = 0;
89 }
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 0f71646..25dcedb 100644
102 --- a/arch/arm/mach-omap2/mux33xx.c
103 +++ b/arch/arm/mach-omap2/mux33xx.c
104 @@ -312,16 +312,16 @@ static struct omap_mux __initdata am33xx_muxmodes[] = {
105 "uart0_txd", "spi1_cs1", "d_can0_rx", "i2c2_scl",
106 NULL, NULL, NULL, "gpio1_11"),
107 _AM33XX_MUXENTRY(UART1_CTSN, 0,
108 - "uart1_ctsn", NULL, NULL, "i2c2_sda",
109 + "uart1_ctsn", NULL, "d_can0_tx", "i2c2_sda",
110 "spi1_cs0", NULL, NULL, "gpio0_12"),
111 _AM33XX_MUXENTRY(UART1_RTSN, 0,
112 - "uart1_rtsn", NULL, NULL, "i2c2_scl",
113 + "uart1_rtsn", NULL, "d_can0_rx", "i2c2_scl",
114 "spi1_cs1", NULL, NULL, "gpio0_13"),
115 _AM33XX_MUXENTRY(UART1_RXD, 0,
116 - "uart1_rxd", "mmc1_sdwp", NULL, "i2c1_sda",
117 + "uart1_rxd", "mmc1_sdwp", "d_can1_tx", "i2c1_sda",
118 NULL, "pr1_uart0_rxd_mux1", NULL, "gpio0_14"),
119 _AM33XX_MUXENTRY(UART1_TXD, 0,
120 - "uart1_txd", "mmc2_sdwp", NULL, "i2c1_scl",
121 + "uart1_txd", "mmc2_sdwp", "d_can1_rx", "i2c1_scl",
122 NULL, "pr1_uart0_txd_mux1", NULL, "gpio0_15"),
123 _AM33XX_MUXENTRY(I2C0_SDA, 0,
124 "i2c0_sda", NULL, NULL, NULL,
125 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
126 index 25695bd..bc1e87e 100644
127 --- a/drivers/net/can/dev.c
128 +++ b/drivers/net/can/dev.c
129 @@ -392,7 +392,7 @@ void can_restart(unsigned long data)
130 stats->rx_bytes += cf->can_dlc;
132 restart:
133 - dev_dbg(dev->dev.parent, "restarted\n");
134 + netdev_dbg(dev, "restarted\n");
135 priv->can_stats.restarts++;
137 /* Now restart the device */
138 @@ -400,7 +400,7 @@ restart:
140 netif_carrier_on(dev);
141 if (err)
142 - dev_err(dev->dev.parent, "Error %d during restart", err);
143 + netdev_err(dev, "error %d during restart", err);
144 }
146 int can_restart_now(struct net_device *dev)
147 @@ -433,7 +433,7 @@ void can_bus_off(struct net_device *dev)
148 {
149 struct can_priv *priv = netdev_priv(dev);
151 - dev_dbg(dev->dev.parent, "bus-off\n");
152 + netdev_dbg(dev, "bus-off\n");
154 netif_carrier_off(dev);
155 priv->can_stats.bus_off++;
156 @@ -545,7 +545,7 @@ int open_candev(struct net_device *dev)
157 struct can_priv *priv = netdev_priv(dev);
159 if (!priv->bittiming.tq && !priv->bittiming.bitrate) {
160 - dev_err(dev->dev.parent, "bit-timing not yet defined\n");
161 + netdev_err(dev, "bit-timing not yet defined\n");
162 return -EINVAL;
163 }
165 diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
166 index 330140e..b3e231c 100644
167 --- a/drivers/net/can/mcp251x.c
168 +++ b/drivers/net/can/mcp251x.c
169 @@ -93,8 +93,9 @@
170 # define CANCTRL_REQOP_LOOPBACK 0x40
171 # define CANCTRL_REQOP_SLEEP 0x20
172 # define CANCTRL_REQOP_NORMAL 0x00
173 -# define CANCTRL_OSM 0x08
174 # define CANCTRL_ABAT 0x10
175 +# define CANCTRL_OSM 0x08
176 +# define CANCTRL_CLKEN 0x04
177 #define TEC 0x1c
178 #define REC 0x1d
179 #define CNF1 0x2a
180 @@ -287,7 +288,7 @@ static void mcp251x_clean(struct net_device *net)
181 /*
182 * Note about handling of error return of mcp251x_spi_trans: accessing
183 * registers via SPI is not really different conceptually than using
184 - * normal I/O assembler instructions, although it's much more
185 + * normal I/O assembly instructions, although it's much more
186 * complicated from a practical POV. So it's not advisable to always
187 * check the return value of this function. Imagine that every
188 * read{b,l}, write{b,l} and friends would be bracketed in "if ( < 0)
189 @@ -490,7 +491,7 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx)
191 static void mcp251x_hw_sleep(struct spi_device *spi)
192 {
193 - mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_SLEEP);
194 +// mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_SLEEP);
195 }
197 static netdev_tx_t mcp251x_hard_start_xmit(struct sk_buff *skb,
198 @@ -547,13 +548,16 @@ static int mcp251x_set_normal_mode(struct spi_device *spi)
200 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) {
201 /* Put device into loopback mode */
202 - mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LOOPBACK);
203 + mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LOOPBACK | CANCTRL_CLKEN);
204 } else if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
205 /* Put device into listen-only mode */
206 - mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LISTEN_ONLY);
207 + mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_LISTEN_ONLY | CANCTRL_CLKEN);
208 } else {
209 /* Put device into normal mode */
210 - mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_NORMAL);
211 + mcp251x_write_reg(spi, CANCTRL, CANCTRL_REQOP_NORMAL | CANCTRL_CLKEN);
212 +
213 + netdev_info(priv->net, "CANCTRL: 0x%02x\n",
214 + mcp251x_read_reg(spi, CANCTRL));
216 /* Wait for the device to enter normal mode */
217 timeout = jiffies + HZ;
218 @@ -585,11 +589,15 @@ static int mcp251x_do_set_bittiming(struct net_device *net)
219 (bt->prop_seg - 1));
220 mcp251x_write_bits(spi, CNF3, CNF3_PHSEG2_MASK,
221 (bt->phase_seg2 - 1));
222 - dev_info(&spi->dev, "CNF: 0x%02x 0x%02x 0x%02x\n",
223 +
224 + netdev_info(net, "CNF: 0x%02x 0x%02x 0x%02x\n",
225 mcp251x_read_reg(spi, CNF1),
226 mcp251x_read_reg(spi, CNF2),
227 mcp251x_read_reg(spi, CNF3));
229 + netdev_info(net, "CANCTRL: 0x%02x\n",
230 + mcp251x_read_reg(spi, CANCTRL));
231 +
232 return 0;
233 }
235 @@ -600,6 +608,7 @@ static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
237 mcp251x_write_reg(spi, RXBCTRL(0),
238 RXBCTRL_BUKT | RXBCTRL_RXM0 | RXBCTRL_RXM1);
239 +
240 mcp251x_write_reg(spi, RXBCTRL(1),
241 RXBCTRL_RXM0 | RXBCTRL_RXM1);
242 return 0;
243 @@ -728,7 +737,9 @@ static void mcp251x_tx_work_handler(struct work_struct *ws)
244 mutex_lock(&priv->mcp_lock);
245 if (priv->tx_skb) {
246 if (priv->can.state == CAN_STATE_BUS_OFF) {
247 +
248 mcp251x_clean(net);
249 +
250 } else {
251 frame = (struct can_frame *)priv->tx_skb->data;
253 @@ -827,21 +838,37 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
255 /* Update can state */
256 if (eflag & EFLG_TXBO) {
257 +
258 + netdev_err(net, "err: bus off\n");
259 +
260 new_state = CAN_STATE_BUS_OFF;
261 can_id |= CAN_ERR_BUSOFF;
262 } else if (eflag & EFLG_TXEP) {
263 +
264 + netdev_err(net, "err: txep\n");
265 +
266 new_state = CAN_STATE_ERROR_PASSIVE;
267 can_id |= CAN_ERR_CRTL;
268 data1 |= CAN_ERR_CRTL_TX_PASSIVE;
269 +
270 } else if (eflag & EFLG_RXEP) {
271 +
272 + netdev_err(net, "err: rxep\n");
273 +
274 new_state = CAN_STATE_ERROR_PASSIVE;
275 can_id |= CAN_ERR_CRTL;
276 data1 |= CAN_ERR_CRTL_RX_PASSIVE;
277 } else if (eflag & EFLG_TXWAR) {
278 +
279 + netdev_err(net, "err: txwar\n");
280 +
281 new_state = CAN_STATE_ERROR_WARNING;
282 can_id |= CAN_ERR_CRTL;
283 data1 |= CAN_ERR_CRTL_TX_WARNING;
284 } else if (eflag & EFLG_RXWAR) {
285 +
286 + netdev_err(net, "err: rxwar\n");
287 +
288 new_state = CAN_STATE_ERROR_WARNING;
289 can_id |= CAN_ERR_CRTL;
290 data1 |= CAN_ERR_CRTL_RX_WARNING;
291 @@ -918,7 +945,7 @@ static int mcp251x_open(struct net_device *net)
293 ret = open_candev(net);
294 if (ret) {
295 - dev_err(&spi->dev, "unable to set initial baudrate!\n");
296 + netdev_err(net, "failed to open can device\n");
297 return ret;
298 }
300 @@ -934,7 +961,7 @@ static int mcp251x_open(struct net_device *net)
301 pdata->irq_flags ? pdata->irq_flags : IRQF_TRIGGER_FALLING,
302 DEVICE_NAME, priv);
303 if (ret) {
304 - dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq);
305 + netdev_err(net, "failed to acquire irq %d\n", spi->irq);
306 if (pdata->transceiver_enable)
307 pdata->transceiver_enable(0);
308 close_candev(net);
309 @@ -1071,7 +1098,7 @@ static int __devinit mcp251x_can_probe(struct spi_device *spi)
311 ret = register_candev(net);
312 if (!ret) {
313 - dev_info(&spi->dev, "probed\n");
314 + netdev_info(priv->net, "probed\n");
315 return ret;
316 }
317 error_probe:
318 --
319 1.7.7.6