* [PATCH v6 0/3] can: sja1000: support for technologic version
@ 2016-01-20 15:43 Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 1/3] can: sja1000: of: add per-compatible init hook Marc Kleine-Budde
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2016-01-20 15:43 UTC (permalink / raw)
To: linux-can; +Cc: netdev
This is Damien Riegel's series with minor changes.
regards,
Marc
---
This patchset introduces support for the technologic version of the
SJA1000. Access to IP's registers are proxied through a window,
requiring two bus accesses to read or write a register. These accesses
must be protected by a spinlock to prevent race conditions. Currently,
there is no easy way to allocate and initialize this spinlock.
SJA1000 already provides a way to allocate private data, but
sja1000_platform.c makes no use of it.
Patch 1 adds the capability to allocate and initialize private data on a
per-compatible basis in sja1000_platform.c.
Patch 2 updates device tree documentation to add the technologic
version.
Patch 3 updates the driver to implement the technologic version
Changes in v6:
- fix static const struct of_device_id sp_of_table
Changes in v5:
- remove empty "static struct sja1000_of_data nxp_data", again
- add additional check for of_id->data
Changes in v4:
- add sp_ prefix to technologic functions
- add empty "static struct sja1000_of_data nxp_data"
- make "struct sja1000_of_data technologic_data" static
- get rid of "?" operator in sp_probe()
Changes in v3:
- moved sp_of_table above sp_probe as it is used in this function
- removed functions added in v2 and do everyting in sp_probe
Changes in v2:
- added a patch to allocate and initialize private data
- changed device tree documentation
- added a spinlock to protect bus accesses
- changed sp_{read,write}_reg16 to io{read,write}16
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v6 1/3] can: sja1000: of: add per-compatible init hook
2016-01-20 15:43 [PATCH v6 0/3] can: sja1000: support for technologic version Marc Kleine-Budde
@ 2016-01-20 15:43 ` Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 2/3] can: sja1000: add documentation for Technologic Systems version Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 3/3] can: sja1000: of: add compatibility with " Marc Kleine-Budde
2 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2016-01-20 15:43 UTC (permalink / raw)
To: linux-can; +Cc: netdev, Damien Riegel, Marc Kleine-Budde
From: Damien Riegel <damien.riegel@savoirfairelinux.com>
This commit adds the capability to allocate and init private data
embedded in the sja1000_priv structure on a per-compatible basis. The
device node is passed as a parameter of the init callback to allow
parsing of custom device tree properties.
Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/sja1000/sja1000_platform.c | 40 +++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 0552ed46a206..777d312f1779 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -27,6 +27,7 @@
#include <linux/can/platform/sja1000.h>
#include <linux/io.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/of_irq.h>
#include "sja1000.h"
@@ -40,6 +41,11 @@ MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus");
MODULE_ALIAS("platform:" DRV_NAME);
MODULE_LICENSE("GPL v2");
+struct sja1000_of_data {
+ size_t priv_sz;
+ int (*init)(struct sja1000_priv *priv, struct device_node *of);
+};
+
static u8 sp_read_reg8(const struct sja1000_priv *priv, int reg)
{
return ioread8(priv->reg_base + reg);
@@ -154,6 +160,12 @@ static void sp_populate_of(struct sja1000_priv *priv, struct device_node *of)
priv->cdr |= CDR_CBP; /* default */
}
+static const struct of_device_id sp_of_table[] = {
+ { .compatible = "nxp,sja1000", .data = NULL, },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, sp_of_table);
+
static int sp_probe(struct platform_device *pdev)
{
int err, irq = 0;
@@ -163,6 +175,9 @@ static int sp_probe(struct platform_device *pdev)
struct resource *res_mem, *res_irq = NULL;
struct sja1000_platform_data *pdata;
struct device_node *of = pdev->dev.of_node;
+ const struct of_device_id *of_id;
+ const struct sja1000_of_data *of_data = NULL;
+ size_t priv_sz = 0;
pdata = dev_get_platdata(&pdev->dev);
if (!pdata && !of) {
@@ -191,7 +206,13 @@ static int sp_probe(struct platform_device *pdev)
if (!irq && !res_irq)
return -ENODEV;
- dev = alloc_sja1000dev(0);
+ of_id = of_match_device(sp_of_table, &pdev->dev);
+ if (of_id && of_id->data) {
+ of_data = of_id->data;
+ priv_sz = of_data->priv_sz;
+ }
+
+ dev = alloc_sja1000dev(priv_sz);
if (!dev)
return -ENOMEM;
priv = netdev_priv(dev);
@@ -208,10 +229,17 @@ static int sp_probe(struct platform_device *pdev)
dev->irq = irq;
priv->reg_base = addr;
- if (of)
+ if (of) {
sp_populate_of(priv, of);
- else
+
+ if (of_data && of_data->init) {
+ err = of_data->init(priv, of);
+ if (err)
+ goto exit_free;
+ }
+ } else {
sp_populate(priv, pdata, res_mem->flags);
+ }
platform_set_drvdata(pdev, dev);
SET_NETDEV_DEV(dev, &pdev->dev);
@@ -242,12 +270,6 @@ static int sp_remove(struct platform_device *pdev)
return 0;
}
-static const struct of_device_id sp_of_table[] = {
- {.compatible = "nxp,sja1000"},
- {},
-};
-MODULE_DEVICE_TABLE(of, sp_of_table);
-
static struct platform_driver sp_driver = {
.probe = sp_probe,
.remove = sp_remove,
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v6 2/3] can: sja1000: add documentation for Technologic Systems version
2016-01-20 15:43 [PATCH v6 0/3] can: sja1000: support for technologic version Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 1/3] can: sja1000: of: add per-compatible init hook Marc Kleine-Budde
@ 2016-01-20 15:43 ` Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 3/3] can: sja1000: of: add compatibility with " Marc Kleine-Budde
2 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2016-01-20 15:43 UTC (permalink / raw)
To: linux-can; +Cc: netdev, Damien Riegel, Marc Kleine-Budde
From: Damien Riegel <damien.riegel@savoirfairelinux.com>
This commit adds documentation for the Technologic Systems version of
SJA1000. The difference with the NXP version is in the way the registers
are accessed.
Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Documentation/devicetree/bindings/net/can/sja1000.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/net/can/sja1000.txt b/Documentation/devicetree/bindings/net/can/sja1000.txt
index b4a6d53fb01a..ac3160eca96a 100644
--- a/Documentation/devicetree/bindings/net/can/sja1000.txt
+++ b/Documentation/devicetree/bindings/net/can/sja1000.txt
@@ -2,7 +2,7 @@ Memory mapped SJA1000 CAN controller from NXP (formerly Philips)
Required properties:
-- compatible : should be "nxp,sja1000".
+- compatible : should be one of "nxp,sja1000", "technologic,sja1000".
- reg : should specify the chip select, address offset and size required
to map the registers of the SJA1000. The size is usually 0x80.
@@ -14,6 +14,7 @@ Optional properties:
- reg-io-width : Specify the size (in bytes) of the IO accesses that
should be performed on the device. Valid value is 1, 2 or 4.
+ This property is ignored for technologic version.
Default to 1 (8 bits).
- nxp,external-clock-frequency : Frequency of the external oscillator
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v6 3/3] can: sja1000: of: add compatibility with Technologic Systems version
2016-01-20 15:43 [PATCH v6 0/3] can: sja1000: support for technologic version Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 1/3] can: sja1000: of: add per-compatible init hook Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 2/3] can: sja1000: add documentation for Technologic Systems version Marc Kleine-Budde
@ 2016-01-20 15:43 ` Marc Kleine-Budde
2016-01-21 15:28 ` Damien Riegel
2 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2016-01-20 15:43 UTC (permalink / raw)
To: linux-can; +Cc: netdev, Damien Riegel, Marc Kleine-Budde
From: Damien Riegel <damien.riegel@savoirfairelinux.com>
Technologic Systems provides an IP compatible with the SJA1000,
instantiated in an FPGA. Because of some bus widths issue, access to
registers is made through a "window" that works like this:
base + 0x0: address to read/write
base + 0x2: 8-bit register value
This commit adds a new compatible device, "technologic,sja1000", with
read and write functions using the window mechanism.
Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/sja1000/sja1000_platform.c | 47 ++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 777d312f1779..dc9c6db96c3c 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -46,6 +46,10 @@ struct sja1000_of_data {
int (*init)(struct sja1000_priv *priv, struct device_node *of);
};
+struct technologic_priv {
+ spinlock_t io_lock;
+};
+
static u8 sp_read_reg8(const struct sja1000_priv *priv, int reg)
{
return ioread8(priv->reg_base + reg);
@@ -76,6 +80,43 @@ static void sp_write_reg32(const struct sja1000_priv *priv, int reg, u8 val)
iowrite8(val, priv->reg_base + reg * 4);
}
+static u8 sp_technologic_read_reg16(const struct sja1000_priv *priv, int reg)
+{
+ struct technologic_priv *tp = priv->priv;
+ unsigned long flags;
+ u8 val;
+
+ spin_lock_irqsave(&tp->io_lock, flags);
+ iowrite16(reg, priv->reg_base + 0);
+ val = ioread16(priv->reg_base + 2);
+ spin_unlock_irqrestore(&tp->io_lock, flags);
+
+ return val;
+}
+
+static void sp_technologic_write_reg16(const struct sja1000_priv *priv,
+ int reg, u8 val)
+{
+ struct technologic_priv *tp = priv->priv;
+ unsigned long flags;
+
+ spin_lock_irqsave(&tp->io_lock, flags);
+ iowrite16(reg, priv->reg_base + 0);
+ iowrite16(val, priv->reg_base + 2);
+ spin_unlock_irqrestore(&tp->io_lock, flags);
+}
+
+static int sp_technologic_init(struct sja1000_priv *priv, struct device_node *of)
+{
+ struct technologic_priv *tp = priv->priv;
+
+ priv->read_reg = sp_technologic_read_reg16;
+ priv->write_reg = sp_technologic_write_reg16;
+ spin_lock_init(&tp->io_lock);
+
+ return 0;
+}
+
static void sp_populate(struct sja1000_priv *priv,
struct sja1000_platform_data *pdata,
unsigned long resource_mem_flags)
@@ -160,8 +201,14 @@ static void sp_populate_of(struct sja1000_priv *priv, struct device_node *of)
priv->cdr |= CDR_CBP; /* default */
}
+static struct sja1000_of_data technologic_data = {
+ .priv_sz = sizeof(struct technologic_priv),
+ .init = sp_technologic_init,
+};
+
static const struct of_device_id sp_of_table[] = {
{ .compatible = "nxp,sja1000", .data = NULL, },
+ { .compatible = "technologic,sja1000", .data = &technologic_data, },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, sp_of_table);
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v6 3/3] can: sja1000: of: add compatibility with Technologic Systems version
2016-01-20 15:43 ` [PATCH v6 3/3] can: sja1000: of: add compatibility with " Marc Kleine-Budde
@ 2016-01-21 15:28 ` Damien Riegel
2016-01-21 16:15 ` Marc Kleine-Budde
0 siblings, 1 reply; 6+ messages in thread
From: Damien Riegel @ 2016-01-21 15:28 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can, netdev
Hi Marc,
I tested the new technologic version and it works as expected. Would be
nice if someone could test the nxp version to ensure no regressions has
been introduced (I don't have such hardware here).
On Wed, Jan 20, 2016 at 04:43:31PM +0100, Marc Kleine-Budde wrote:
> From: Damien Riegel <damien.riegel@savoirfairelinux.com>
>
> Technologic Systems provides an IP compatible with the SJA1000,
> instantiated in an FPGA. Because of some bus widths issue, access to
> registers is made through a "window" that works like this:
>
> base + 0x0: address to read/write
> base + 0x2: 8-bit register value
>
> This commit adds a new compatible device, "technologic,sja1000", with
> read and write functions using the window mechanism.
>
> Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Tested-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 3/3] can: sja1000: of: add compatibility with Technologic Systems version
2016-01-21 15:28 ` Damien Riegel
@ 2016-01-21 16:15 ` Marc Kleine-Budde
0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2016-01-21 16:15 UTC (permalink / raw)
To: Damien Riegel; +Cc: linux-can, netdev
[-- Attachment #1: Type: text/plain, Size: 584 bytes --]
On 01/21/2016 04:28 PM, Damien Riegel wrote:
> I tested the new technologic version and it works as expected.
Thanks.
> Would be nice if someone could test the nxp version to ensure no
> regressions has been introduced (I don't have such hardware here).
I don't have the hardware, either.
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: 455 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-01-21 16:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-20 15:43 [PATCH v6 0/3] can: sja1000: support for technologic version Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 1/3] can: sja1000: of: add per-compatible init hook Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 2/3] can: sja1000: add documentation for Technologic Systems version Marc Kleine-Budde
2016-01-20 15:43 ` [PATCH v6 3/3] can: sja1000: of: add compatibility with " Marc Kleine-Budde
2016-01-21 15:28 ` Damien Riegel
2016-01-21 16:15 ` Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).