* [PATCH v3 0/3] can: sja1000: support for technologic version
@ 2016-01-12 22:31 Damien Riegel
2016-01-12 22:31 ` [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook Damien Riegel
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Damien Riegel @ 2016-01-12 22:31 UTC (permalink / raw)
To: linux-kernel, linux-can, netdev
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
Wolfgang Grandegger, Marc Kleine-Budde, kernel, Damien Riegel
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 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
Damien Riegel (3):
can: sja1000: of: add per-compatible init hook
can: sja1000: add documentation for Technologic Systems version
can: sja1000: of: add compatibility with Technologic Systems version
.../devicetree/bindings/net/can/sja1000.txt | 3 +-
drivers/net/can/sja1000/sja1000_platform.c | 75 ++++++++++++++++++++--
2 files changed, 70 insertions(+), 8 deletions(-)
--
2.5.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook
2016-01-12 22:31 [PATCH v3 0/3] can: sja1000: support for technologic version Damien Riegel
@ 2016-01-12 22:31 ` Damien Riegel
2016-01-13 11:21 ` Marc Kleine-Budde
2016-01-12 22:31 ` [PATCH v3 2/3] can: sja1000: add documentation for Technologic Systems version Damien Riegel
2016-01-12 22:31 ` [PATCH v3 3/3] can: sja1000: of: add compatibility with " Damien Riegel
2 siblings, 1 reply; 5+ messages in thread
From: Damien Riegel @ 2016-01-12 22:31 UTC (permalink / raw)
To: linux-kernel, linux-can, netdev
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
Wolfgang Grandegger, Marc Kleine-Budde, kernel, Damien Riegel
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>
---
drivers/net/can/sja1000/sja1000_platform.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 0552ed4..ea4e18b 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -40,6 +40,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 +159,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"},
+ {},
+};
+MODULE_DEVICE_TABLE(of, sp_of_table);
+
static int sp_probe(struct platform_device *pdev)
{
int err, irq = 0;
@@ -163,6 +174,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 *id = of_match_node(sp_of_table, of);
+ const struct sja1000_of_data *of_data = id ? id->data : NULL;
+ size_t priv_sz = of_data ? of_data->priv_sz : 0;
pdata = dev_get_platdata(&pdev->dev);
if (!pdata && !of) {
@@ -191,7 +205,7 @@ static int sp_probe(struct platform_device *pdev)
if (!irq && !res_irq)
return -ENODEV;
- dev = alloc_sja1000dev(0);
+ dev = alloc_sja1000dev(priv_sz);
if (!dev)
return -ENOMEM;
priv = netdev_priv(dev);
@@ -213,6 +227,12 @@ static int sp_probe(struct platform_device *pdev)
else
sp_populate(priv, pdata, res_mem->flags);
+ if (of_data && of_data->init) {
+ err = of_data->init(priv, of);
+ if (err)
+ goto exit_free;
+ }
+
platform_set_drvdata(pdev, dev);
SET_NETDEV_DEV(dev, &pdev->dev);
@@ -242,12 +262,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.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/3] can: sja1000: add documentation for Technologic Systems version
2016-01-12 22:31 [PATCH v3 0/3] can: sja1000: support for technologic version Damien Riegel
2016-01-12 22:31 ` [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook Damien Riegel
@ 2016-01-12 22:31 ` Damien Riegel
2016-01-12 22:31 ` [PATCH v3 3/3] can: sja1000: of: add compatibility with " Damien Riegel
2 siblings, 0 replies; 5+ messages in thread
From: Damien Riegel @ 2016-01-12 22:31 UTC (permalink / raw)
To: linux-kernel, linux-can, netdev
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
Wolfgang Grandegger, Marc Kleine-Budde, kernel, Damien Riegel
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>
---
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 b4a6d53..ac3160e 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.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/3] can: sja1000: of: add compatibility with Technologic Systems version
2016-01-12 22:31 [PATCH v3 0/3] can: sja1000: support for technologic version Damien Riegel
2016-01-12 22:31 ` [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook Damien Riegel
2016-01-12 22:31 ` [PATCH v3 2/3] can: sja1000: add documentation for Technologic Systems version Damien Riegel
@ 2016-01-12 22:31 ` Damien Riegel
2 siblings, 0 replies; 5+ messages in thread
From: Damien Riegel @ 2016-01-12 22:31 UTC (permalink / raw)
To: linux-kernel, linux-can, netdev
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
Wolfgang Grandegger, Marc Kleine-Budde, kernel, Damien Riegel
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>
---
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 ea4e18b..84c95cd 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -45,6 +45,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);
@@ -75,6 +79,43 @@ static void sp_write_reg32(const struct sja1000_priv *priv, int reg, u8 val)
iowrite8(val, priv->reg_base + reg * 4);
}
+static u8 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 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 technologic_init(struct sja1000_priv *priv, struct device_node *of)
+{
+ struct technologic_priv *tp = priv->priv;
+
+ priv->read_reg = technologic_read_reg16;
+ priv->write_reg = 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)
@@ -159,8 +200,14 @@ static void sp_populate_of(struct sja1000_priv *priv, struct device_node *of)
priv->cdr |= CDR_CBP; /* default */
}
+struct sja1000_of_data technologic_data = {
+ .priv_sz = sizeof(struct technologic_priv),
+ .init = technologic_init,
+};
+
static const struct of_device_id sp_of_table[] = {
{.compatible = "nxp,sja1000"},
+ {.compatible = "technologic,sja1000", .data = &technologic_data},
{},
};
MODULE_DEVICE_TABLE(of, sp_of_table);
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook
2016-01-12 22:31 ` [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook Damien Riegel
@ 2016-01-13 11:21 ` Marc Kleine-Budde
0 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2016-01-13 11:21 UTC (permalink / raw)
To: Damien Riegel, linux-kernel, linux-can, netdev
Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
Wolfgang Grandegger, kernel
[-- Attachment #1: Type: text/plain, Size: 2474 bytes --]
On 01/12/2016 11:31 PM, Damien Riegel wrote:
> 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>
> ---
> drivers/net/can/sja1000/sja1000_platform.c | 28 +++++++++++++++++++++-------
> 1 file changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
> index 0552ed4..ea4e18b 100644
> --- a/drivers/net/can/sja1000/sja1000_platform.c
> +++ b/drivers/net/can/sja1000/sja1000_platform.c
> @@ -40,6 +40,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 +159,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"},
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, sp_of_table);
> +
> static int sp_probe(struct platform_device *pdev)
> {
> int err, irq = 0;
> @@ -163,6 +174,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 *id = of_match_node(sp_of_table, of);
Have you tested this with of == NULL? I think it should work as
__of_find_property returns NULL if np is NULL.
> + const struct sja1000_of_data *of_data = id ? id->data : NULL;
> + size_t priv_sz = of_data ? of_data->priv_sz : 0;
I've move the code a bit around to get rid of the ? operator. I'll send
a new series.
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] 5+ messages in thread
end of thread, other threads:[~2016-01-13 11:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-12 22:31 [PATCH v3 0/3] can: sja1000: support for technologic version Damien Riegel
2016-01-12 22:31 ` [PATCH v3 1/3] can: sja1000: of: add per-compatible init hook Damien Riegel
2016-01-13 11:21 ` Marc Kleine-Budde
2016-01-12 22:31 ` [PATCH v3 2/3] can: sja1000: add documentation for Technologic Systems version Damien Riegel
2016-01-12 22:31 ` [PATCH v3 3/3] can: sja1000: of: add compatibility with " Damien Riegel
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.