* [PATCH 1/1] net: can: sja1000: Validate initialization state in start method
@ 2014-08-08 12:30 Mirza Krak
2014-08-14 10:18 ` Marc Kleine-Budde
0 siblings, 1 reply; 4+ messages in thread
From: Mirza Krak @ 2014-08-08 12:30 UTC (permalink / raw)
To: linux-can, mkl; +Cc: Mirza Krak
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>
---
drivers/net/can/sja1000/sja1000.c | 62 +++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index f31499a..ba9d423 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -170,6 +170,35 @@ static void set_normal_mode(struct net_device *dev)
netdev_err(dev, "setting SJA1000 into normal mode failed!\n");
}
+/*
+ * initialize SJA1000 chip:
+ * - reset chip
+ * - set output mode
+ * - set baudrate
+ * - enable interrupts
+ * - start operating mode
+ */
+static void chipset_init(struct net_device *dev)
+{
+ struct sja1000_priv *priv = netdev_priv(dev);
+
+ /* set clock divider and output control register */
+ priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN);
+
+ /* set acceptance filter (accept all) */
+ priv->write_reg(priv, SJA1000_ACCC0, 0x00);
+ priv->write_reg(priv, SJA1000_ACCC1, 0x00);
+ priv->write_reg(priv, SJA1000_ACCC2, 0x00);
+ priv->write_reg(priv, SJA1000_ACCC3, 0x00);
+
+ priv->write_reg(priv, SJA1000_ACCM0, 0xFF);
+ priv->write_reg(priv, SJA1000_ACCM1, 0xFF);
+ priv->write_reg(priv, SJA1000_ACCM2, 0xFF);
+ priv->write_reg(priv, SJA1000_ACCM3, 0xFF);
+
+ priv->write_reg(priv, SJA1000_OCR, priv->ocr | OCR_MODE_NORMAL);
+}
+
static void sja1000_start(struct net_device *dev)
{
struct sja1000_priv *priv = netdev_priv(dev);
@@ -178,6 +207,10 @@ static void sja1000_start(struct net_device *dev)
if (priv->can.state != CAN_STATE_STOPPED)
set_reset_mode(dev);
+ /* Initialize chip if uninitialized at this stage */
+ if (!(priv->read_reg(priv, SJA1000_CDR) & CDR_PELICAN))
+ chipset_init(dev);
+
/* Clear error counters and error code capture */
priv->write_reg(priv, SJA1000_TXERR, 0x0);
priv->write_reg(priv, SJA1000_RXERR, 0x0);
@@ -235,35 +268,6 @@ static int sja1000_get_berr_counter(const struct net_device *dev,
}
/*
- * initialize SJA1000 chip:
- * - reset chip
- * - set output mode
- * - set baudrate
- * - enable interrupts
- * - start operating mode
- */
-static void chipset_init(struct net_device *dev)
-{
- struct sja1000_priv *priv = netdev_priv(dev);
-
- /* set clock divider and output control register */
- priv->write_reg(priv, SJA1000_CDR, priv->cdr | CDR_PELICAN);
-
- /* set acceptance filter (accept all) */
- priv->write_reg(priv, SJA1000_ACCC0, 0x00);
- priv->write_reg(priv, SJA1000_ACCC1, 0x00);
- priv->write_reg(priv, SJA1000_ACCC2, 0x00);
- priv->write_reg(priv, SJA1000_ACCC3, 0x00);
-
- priv->write_reg(priv, SJA1000_ACCM0, 0xFF);
- priv->write_reg(priv, SJA1000_ACCM1, 0xFF);
- priv->write_reg(priv, SJA1000_ACCM2, 0xFF);
- priv->write_reg(priv, SJA1000_ACCM3, 0xFF);
-
- priv->write_reg(priv, SJA1000_OCR, priv->ocr | OCR_MODE_NORMAL);
-}
-
-/*
* transmit a CAN message
* message layout in the sk_buff should be like this:
* xx xx xx xx ff ll 00 11 22 33 44 55 66 77
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] net: can: sja1000: Validate initialization state in start method
2014-08-08 12:30 [PATCH 1/1] net: can: sja1000: Validate initialization state in start method Mirza Krak
@ 2014-08-14 10:18 ` Marc Kleine-Budde
2014-08-21 8:44 ` Mirza Krak
0 siblings, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2014-08-14 10:18 UTC (permalink / raw)
To: Mirza Krak, linux-can
[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]
On 08/08/2014 02:30 PM, Mirza Krak wrote:
> 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.
Not good. :/
However, you can manually unbind the device from the driver:
> ➜ (pts/0) mkl@hermippe:drivers/sja1000_plx_pci ll
> total 0
> lrwxrwxrwx 1 root root 0 Aug 14 12:15 0000:01:02.0 -> ../../../../devices/pci0000:00/0000:00:1e.0/0000:01:02.0
> --w------- 1 root root 4096 Aug 14 12:15 bind
> lrwxrwxrwx 1 root root 0 Aug 14 12:15 module -> ../../../../module/plx_pci
> --w------- 1 root root 4096 Aug 14 12:15 new_id
> --w------- 1 root root 4096 Aug 14 12:15 remove_id
> --w------- 1 root root 4096 Aug 14 12:15 uevent
> --w------- 1 root root 4096 Aug 14 12:15 unbind
> ➜ (pts/0) mkl@hermippe:drivers/sja1000_plx_pci echo 0000:01:02.0 | sudo tee unbind
And then rebind it:
> ➜ (pts/0) mkl@hermippe:drivers/sja1000_plx_pci echo 0000:01:02.0 | sudo tee bind
> This patch adds a check in sja1000_start if the chip is initialized, if
> not we initialize it.
Applied to can.
Thanks,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] net: can: sja1000: Validate initialization state in start method
2014-08-14 10:18 ` Marc Kleine-Budde
@ 2014-08-21 8:44 ` Mirza Krak
2014-08-21 9:26 ` Marc Kleine-Budde
0 siblings, 1 reply; 4+ messages in thread
From: Mirza Krak @ 2014-08-21 8:44 UTC (permalink / raw)
To: Marc Kleine-Budde, linux-can
On 2014-08-14 12:18, Marc Kleine-Budde wrote:
> On 08/08/2014 02:30 PM, Mirza Krak wrote:
>> 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.
> Not good. :/
>
> However, you can manually unbind the device from the driver:
>
>> ➜ (pts/0) mkl@hermippe:drivers/sja1000_plx_pci ll
>> total 0
>> lrwxrwxrwx 1 root root 0 Aug 14 12:15 0000:01:02.0 -> ../../../../devices/pci0000:00/0000:00:1e.0/0000:01:02.0
>> --w------- 1 root root 4096 Aug 14 12:15 bind
>> lrwxrwxrwx 1 root root 0 Aug 14 12:15 module -> ../../../../module/plx_pci
>> --w------- 1 root root 4096 Aug 14 12:15 new_id
>> --w------- 1 root root 4096 Aug 14 12:15 remove_id
>> --w------- 1 root root 4096 Aug 14 12:15 uevent
>> --w------- 1 root root 4096 Aug 14 12:15 unbind
>> ➜ (pts/0) mkl@hermippe:drivers/sja1000_plx_pci echo 0000:01:02.0 | sudo tee unbind
> And then rebind it:
>
>> ➜ (pts/0) mkl@hermippe:drivers/sja1000_plx_pci echo 0000:01:02.0 | sudo tee bind
Aah I see. You learn something new everyday.
>> This patch adds a check in sja1000_start if the chip is initialized, if
>> not we initialize it.
> Applied to can.
I am sorry but applied to what? I haven't seen it been applied anywhere
when browsing linux-can on gitorious.
>
> Thanks,
> Marc
>
--
Med Vänliga Hälsningar / Best Regards
*******************************************************************
Mirza Krak
Host Mobility AB
mirza.krak@hostmobility.com
Anders Personsgatan 12, 416 64 Göteborg
Sweden
http://www.hostmobility.com
Direct: +46 31 31 32 704
Phone: +46 31 31 32 700
Fax: +46 31 80 67 51
Mobile: +46 730 28 06 22
*******************************************************************
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] net: can: sja1000: Validate initialization state in start method
2014-08-21 8:44 ` Mirza Krak
@ 2014-08-21 9:26 ` Marc Kleine-Budde
0 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2014-08-21 9:26 UTC (permalink / raw)
To: Mirza Krak, linux-can
[-- Attachment #1: Type: text/plain, Size: 774 bytes --]
On 08/21/2014 10:44 AM, Mirza Krak wrote:
[...]
>>> This patch adds a check in sja1000_start if the chip is initialized, if
>>> not we initialize it.
>> Applied to can.
> I am sorry but applied to what? I haven't seen it been applied anywhere
> when browsing linux-can on gitorious.
Until 5 minutes ago, it was on my hard drive only :D
But now it's included in the pull request I send to David, you can find
it on gitorious under the tag linux-can-fixes-for-3.17-20140821.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-21 9:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-08 12:30 [PATCH 1/1] net: can: sja1000: Validate initialization state in start method Mirza Krak
2014-08-14 10:18 ` Marc Kleine-Budde
2014-08-21 8:44 ` Mirza Krak
2014-08-21 9:26 ` Marc Kleine-Budde
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.