diff options
author | Mirza Krak <mirza.krak@hostmobility.com> | 2014-08-08 08:30:50 -0400 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2014-08-21 04:49:34 -0400 |
commit | 9e37bc6c635a85e0ae3067f19d6f84e1c4516a6c (patch) | |
tree | b2d78309495db7433d427c35f463727e18faf4ab | |
parent | 02784f1b05b8f241c8180af88869e717e2758593 (diff) |
can: sja1000: Validate initialization state in start method
When sja1000 is not compiled as module the SJA1000 chip is only
initialized during device registration on kernel boot. Should the chip
get a hardware reset there is no way to reinitialize it without re-
booting the Linux kernel.
This patch adds a check in sja1000_start if the chip is initialized, if
not we initialize it.
Signed-off-by: Mirza Krak <mirza.krak@hostmobility.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | drivers/net/can/sja1000/sja1000.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c index d1692154ed1b..b27ac6074afb 100644 --- a/drivers/net/can/sja1000/sja1000.c +++ b/drivers/net/can/sja1000/sja1000.c | |||
@@ -172,6 +172,35 @@ static void set_normal_mode(struct net_device *dev) | |||
172 | netdev_err(dev, "setting SJA1000 into normal mode failed!\n"); | 172 | netdev_err(dev, "setting SJA1000 into normal mode failed!\n"); |
173 | } | 173 | } |
174 | 174 | ||
175 | /* | ||
176 | * initialize SJA1000 chip: | ||
177 | * - reset chip | ||
178 | * - set output mode | ||
179 | * - set baudrate | ||
180 | * - enable interrupts | ||
181 | * - start operating mode | ||
182 | */ | ||
183 | static void chipset_init(struct net_device *dev) | ||
184 | { | ||
185 | struct sja1000_priv *priv = netdev_priv(dev); | ||
186 | |||
187 | /* set clock divider and output control register */ | ||
188 | priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN); | ||
189 | |||
190 | /* set acceptance filter (accept all) */ | ||
191 | priv->write_reg(priv, SJA1000_ACCC0, 0x00); | ||
192 | priv->write_reg(priv, SJA1000_ACCC1, 0x00); | ||
193 | priv->write_reg(priv, SJA1000_ACCC2, 0x00); | ||
194 | priv->write_reg(priv, SJA1000_ACCC3, 0x00); | ||
195 | |||
196 | priv->write_reg(priv, SJA1000_ACCM0, 0xFF); | ||
197 | priv->write_reg(priv, SJA1000_ACCM1, 0xFF); | ||
198 | priv->write_reg(priv, SJA1000_ACCM2, 0xFF); | ||
199 | priv->write_reg(priv, SJA1000_ACCM3, 0xFF); | ||
200 | |||
201 | priv->write_reg(priv, SJA1000_OCR, priv->ocr | OCR_MODE_NORMAL); | ||
202 | } | ||
203 | |||
175 | static void sja1000_start(struct net_device *dev) | 204 | static void sja1000_start(struct net_device *dev) |
176 | { | 205 | { |
177 | struct sja1000_priv *priv = netdev_priv(dev); | 206 | struct sja1000_priv *priv = netdev_priv(dev); |
@@ -180,6 +209,10 @@ static void sja1000_start(struct net_device *dev) | |||
180 | if (priv->can.state != CAN_STATE_STOPPED) | 209 | if (priv->can.state != CAN_STATE_STOPPED) |
181 | set_reset_mode(dev); | 210 | set_reset_mode(dev); |
182 | 211 | ||
212 | /* Initialize chip if uninitialized at this stage */ | ||
213 | if (!(priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN)) | ||
214 | chipset_init(dev); | ||
215 | |||
183 | /* Clear error counters and error code capture */ | 216 | /* Clear error counters and error code capture */ |
184 | priv->write_reg(priv, SJA1000_TXERR, 0x0); | 217 | priv->write_reg(priv, SJA1000_TXERR, 0x0); |
185 | priv->write_reg(priv, SJA1000_RXERR, 0x0); | 218 | priv->write_reg(priv, SJA1000_RXERR, 0x0); |
@@ -237,35 +270,6 @@ static int sja1000_get_berr_counter(const struct net_device *dev, | |||
237 | } | 270 | } |
238 | 271 | ||
239 | /* | 272 | /* |
240 | * initialize SJA1000 chip: | ||
241 | * - reset chip | ||
242 | * - set output mode | ||
243 | * - set baudrate | ||
244 | * - enable interrupts | ||
245 | * - start operating mode | ||
246 | */ | ||
247 | static void chipset_init(struct net_device *dev) | ||
248 | { | ||
249 | struct sja1000_priv *priv = netdev_priv(dev); | ||
250 | |||
251 | /* set clock divider and output control register */ | ||
252 | priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN); | ||
253 | |||
254 | /* set acceptance filter (accept all) */ | ||
255 | priv->write_reg(priv, SJA1000_ACCC0, 0x00); | ||
256 | priv->write_reg(priv, SJA1000_ACCC1, 0x00); | ||
257 | priv->write_reg(priv, SJA1000_ACCC2, 0x00); | ||
258 | priv->write_reg(priv, SJA1000_ACCC3, 0x00); | ||
259 | |||
260 | priv->write_reg(priv, SJA1000_ACCM0, 0xFF); | ||
261 | priv->write_reg(priv, SJA1000_ACCM1, 0xFF); | ||
262 | priv->write_reg(priv, SJA1000_ACCM2, 0xFF); | ||
263 | priv->write_reg(priv, SJA1000_ACCM3, 0xFF); | ||
264 | |||
265 | priv->write_reg(priv, SJA1000_OCR, priv->ocr | OCR_MODE_NORMAL); | ||
266 | } | ||
267 | |||
268 | /* | ||
269 | * transmit a CAN message | 273 | * transmit a CAN message |
270 | * message layout in the sk_buff should be like this: | 274 | * message layout in the sk_buff should be like this: |
271 | * xx xx xx xx ff ll 00 11 22 33 44 55 66 77 | 275 | * xx xx xx xx ff ll 00 11 22 33 44 55 66 77 |