2015-12-24 17:43:07

by Damien Riegel

[permalink] [raw]
Subject: [PATCH v2 0/3] can: sja1000: support for technologic version

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 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 | 86 +++++++++++++++++++++-
2 files changed, 86 insertions(+), 3 deletions(-)

--
2.5.0


2015-12-24 17:43:48

by Damien Riegel

[permalink] [raw]
Subject: [PATCH v2 1/3] can: sja1000: of: add per-compatible init hook

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 <[email protected]>
---
drivers/net/can/sja1000/sja1000_platform.c | 39 ++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 0552ed4..e0572d0 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,7 +159,8 @@ static void sp_populate_of(struct sja1000_priv *priv, struct device_node *of)
priv->cdr |= CDR_CBP; /* default */
}

-static int sp_probe(struct platform_device *pdev)
+static int __sp_probe(struct platform_device *pdev,
+ const struct sja1000_of_data *of_data)
{
int err, irq = 0;
void __iomem *addr;
@@ -163,6 +169,7 @@ 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;
+ size_t priv_sz = of_data ? of_data->priv_sz : 0;

pdata = dev_get_platdata(&pdev->dev);
if (!pdata && !of) {
@@ -191,7 +198,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 +220,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);

@@ -248,6 +261,28 @@ static const struct of_device_id sp_of_table[] = {
};
MODULE_DEVICE_TABLE(of, sp_of_table);

+static const struct sja1000_of_data *sp_get_of_data(struct device_node *of)
+{
+ const struct of_device_id *id;
+
+ if (!of)
+ return NULL;
+
+ id = of_match_node(sp_of_table, of);
+ if (!id)
+ return NULL;
+
+ return id->data;
+}
+
+static int sp_probe(struct platform_device *pdev)
+{
+ struct device_node *of = pdev->dev.of_node;
+ const struct sja1000_of_data *of_data = sp_get_of_data(of);
+
+ return __sp_probe(pdev, of_data);
+}
+
static struct platform_driver sp_driver = {
.probe = sp_probe,
.remove = sp_remove,
--
2.5.0

2015-12-24 17:44:04

by Damien Riegel

[permalink] [raw]
Subject: [PATCH v2 2/3] can: sja1000: add documentation for Technologic Systems version

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 <[email protected]>
---
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

2015-12-24 17:44:00

by Damien Riegel

[permalink] [raw]
Subject: [PATCH v2 3/3] can: sja1000: of: add compatibility with Technologic Systems version

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 <[email protected]>
---
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 e0572d0..bfb124d 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)
@@ -255,8 +296,14 @@ static int sp_remove(struct platform_device *pdev)
return 0;
}

+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