Discussion:
[PATCH v2 0/3] net: can: Use syscon regmap for TI specific RAMINIT register
Roger Quadros
2014-09-09 14:31:07 UTC
Permalink
Hi,

Some hardware (TI am43xx) has a buggy RAMINIT DONE mechanism and it might
not always set the DONE bit. This will result in a lockup in c_can_hw_raminit_wait_ti(),
so patch 1 adds a timeout mechanism there.

There is a non compliancy within TI platforms with respect to the
layout of the RAMINIT register. The patches 2 and 3 address this issue
and make a flexible but standard way of defining the RAMINIT hardware register
layout in the device tree. The RAMINIT register is accessed using the syscon
regmap framework.

Patches available at
***@github.com:rogerq/linux.git [for-v3.18/can]

Changelog:

v2:
- added "ti" vendor prefix to TI specific raminit properties.
- split DTS changes into a separate series

cheers,
-roger
---

Roger Quadros (3):
can: c_can_platform: Fix c_can_hw_raminit_ti() and add timeout
net: can: c_can: Add syscon/regmap RAMINIT mechanism
net: can: c_can: Add support for START pulse in RAMINIT sequence

.../devicetree/bindings/net/can/c_can.txt | 10 ++
drivers/net/can/c_can/c_can.h | 12 +-
drivers/net/can/c_can/c_can_platform.c | 123 ++++++++++++++++-----
3 files changed, 114 insertions(+), 31 deletions(-)
--
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Roger Quadros
2014-09-09 14:31:09 UTC
Permalink
Some TI SoCs like DRA7 have a RAMINIT register specification
different from the other AMxx SoCs and as expected by the
existing driver.

To add more insanity, this register is shared with other
IPs like DSS, PCIe and PWM.

Provides a more generic mechanism to specify the RAMINIT
register location and START/DONE bit position and use the
syscon/regmap framework to access the register.

Signed-off-by: Roger Quadros <***@ti.com>
---
.../devicetree/bindings/net/can/c_can.txt | 7 ++
drivers/net/can/c_can/c_can.h | 11 ++-
drivers/net/can/c_can/c_can_platform.c | 109 +++++++++++++++------
3 files changed, 95 insertions(+), 32 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index 8f1ae81..e12d1a1 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
@@ -13,6 +13,13 @@ Optional properties:
- ti,hwmods : Must be "d_can<n>" or "c_can<n>", n being the
instance number

+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
+
Note: "ti,hwmods" field is used to fetch the base address and irq
resources from TI, omap hwmod data base during device registration.
Future plan is to migrate hwmod data base contents into device tree
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 99ad1aa..bf68822 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -169,6 +169,14 @@ enum c_can_dev_id {
BOSCH_D_CAN,
};

+/* Out of band RAMINIT register access via syscon regmap */
+struct c_can_raminit {
+ struct regmap *syscon; /* for raminit ctrl. reg. access */
+ unsigned int reg; /* register index within syscon */
+ u8 start_bit; /* START bit position in raminit reg. */
+ u8 done_bit; /* DONE bit position in raminit reg. */
+};
+
/* c_can private data structure */
struct c_can_priv {
struct can_priv can; /* must be the first member */
@@ -186,8 +194,7 @@ struct c_can_priv {
const u16 *regs;
void *priv; /* for board-specific data */
enum c_can_dev_id type;
- u32 __iomem *raminit_ctrlreg;
- int instance;
+ struct c_can_raminit raminit_sys; /* RAMINIT via syscon regmap */
void (*raminit) (const struct c_can_priv *priv, bool enable);
u32 comm_rcv_high;
u32 rxmasked;
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index b144e71..fb0c35b 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -32,14 +32,13 @@
#include <linux/clk.h>
#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>

#include <linux/can/dev.h>

#include "c_can.h"

-#define CAN_RAMINIT_START_MASK(i) (0x001 << (i))
-#define CAN_RAMINIT_DONE_MASK(i) (0x100 << (i))
-#define CAN_RAMINIT_ALL_MASK(i) (0x101 << (i))
#define DCAN_RAM_INIT_BIT (1 << 3)
static DEFINE_SPINLOCK(raminit_lock);
/*
@@ -72,48 +71,59 @@ static void c_can_plat_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
writew(val, priv->base + 2 * priv->regs[index]);
}

-static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
- u32 val)
+static void c_can_hw_raminit_wait_syscon(const struct c_can_priv *priv,
+ u32 mask, u32 val)
{
int timeout = 0;
+ const struct c_can_raminit *raminit = &priv->raminit_sys;
+ u32 ctrl;
+
/* We look only at the bits of our instance. */
val &= mask;
- while ((readl(priv->raminit_ctrlreg) & mask) != val) {
+ do {
udelay(1);
timeout++;

+ regmap_read(raminit->syscon, raminit->reg, &ctrl);
if (timeout == 1000) {
dev_err(&priv->dev->dev, "%s: time out\n", __func__);
break;
}
- }
+ } while ((ctrl & mask) != val);
}

-static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
+static void c_can_hw_raminit_syscon(const struct c_can_priv *priv, bool enable)
{
- u32 mask = CAN_RAMINIT_ALL_MASK(priv->instance);
+ u32 mask;
u32 ctrl;
+ const struct c_can_raminit *raminit = &priv->raminit_sys;

spin_lock(&raminit_lock);

- ctrl = readl(priv->raminit_ctrlreg);
+ mask = 1 << raminit->start_bit | 1 << raminit->done_bit;
+ regmap_read(raminit->syscon, raminit->reg, &ctrl);
+
/* We clear the done and start bit first. The start bit is
* looking at the 0 -> transition, but is not self clearing;
* And we clear the init done bit as well.
+ * NOTE: DONE must be written with 1 to clear it.
*/
- ctrl &= ~CAN_RAMINIT_START_MASK(priv->instance);
- ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
- writel(ctrl, priv->raminit_ctrlreg);
- ctrl &= ~CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, mask, ctrl);
+ ctrl &= ~(1 << raminit->start_bit);
+ ctrl |= 1 << raminit->done_bit;
+ regmap_write(raminit->syscon, raminit->reg, ctrl);
+
+ ctrl &= ~(1 << raminit->done_bit);
+ c_can_hw_raminit_wait_syscon(priv, mask, ctrl);

if (enable) {
/* Set start bit and wait for the done bit. */
- ctrl |= CAN_RAMINIT_START_MASK(priv->instance);
- writel(ctrl, priv->raminit_ctrlreg);
- ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, mask, ctrl);
+ ctrl |= 1 << raminit->start_bit;
+ regmap_write(raminit->syscon, raminit->reg, ctrl);
+
+ ctrl |= 1 << raminit->done_bit;
+ c_can_hw_raminit_wait_syscon(priv, mask, ctrl);
}
+
spin_unlock(&raminit_lock);
}

@@ -202,6 +212,8 @@ static int c_can_plat_probe(struct platform_device *pdev)
struct resource *mem, *res;
int irq;
struct clk *clk;
+ struct device_node *np = pdev->dev.of_node;
+ u32 val;

if (pdev->dev.of_node) {
match = of_match_device(c_can_of_table, &pdev->dev);
@@ -271,11 +283,6 @@ static int c_can_plat_probe(struct platform_device *pdev)
priv->read_reg32 = d_can_plat_read_reg32;
priv->write_reg32 = d_can_plat_write_reg32;

- if (pdev->dev.of_node)
- priv->instance = of_alias_get_id(pdev->dev.of_node, "d_can");
- else
- priv->instance = pdev->id;
-
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
/* Not all D_CAN modules have a separate register for the D_CAN
* RAM initialization. Use default RAM init bit in D_CAN module
@@ -286,12 +293,54 @@ static int c_can_plat_probe(struct platform_device *pdev)
break;
}

- priv->raminit_ctrlreg = devm_ioremap(&pdev->dev, res->start,
- resource_size(res));
- if (!priv->raminit_ctrlreg || priv->instance < 0)
- dev_info(&pdev->dev, "control memory is not used for raminit\n");
- else
- priv->raminit = c_can_hw_raminit_ti;
+ /* If separate RAMINIT register is specified access
+ * it using syscon regmap. Mostly for TI platforms.
+ */
+ ret = -EINVAL;
+ if (!np) {
+ dev_err(&pdev->dev,
+ "separate RAMINIT reg. not supported on non DT\n");
+ goto exit_free_device;
+ }
+
+ priv->raminit_sys.syscon = syscon_regmap_lookup_by_phandle(np,
+ "ti,raminit-syscon");
+ if (IS_ERR(priv->raminit_sys.syscon)) {
+ dev_err(&pdev->dev,
+ "couldn't get syscon regmap for RAMINIT reg.\n");
+ goto exit_free_device;
+ }
+
+ priv->raminit_sys.reg = res->start;
+ if (of_property_read_u32(np, "ti,raminit-start-bit",
+ &val)) {
+ dev_err(&pdev->dev,
+ "missing ti,raminit-start-bit property\n");
+ goto exit_free_device;
+ }
+
+ if (val > 31) {
+ dev_err(&pdev->dev,
+ "invalid ti,raminit-start-bit property\n");
+ goto exit_free_device;
+ }
+
+ priv->raminit_sys.start_bit = val;
+ if (of_property_read_u32(np, "ti,raminit-done-bit",
+ &val)) {
+ dev_err(&pdev->dev,
+ "missing ti,raminit-done-bit property\n");
+ goto exit_free_device;
+ }
+
+ if (val > 31) {
+ dev_err(&pdev->dev,
+ "invalid ti,raminit-done-bit property\n");
+ goto exit_free_device;
+ }
+
+ priv->raminit_sys.done_bit = val;
+ priv->raminit = c_can_hw_raminit_syscon;
break;
default:
ret = -EINVAL;
--
1.8.3.2
Wolfram Sang
2014-09-30 13:26:50 UTC
Permalink
Post by Roger Quadros
Some TI SoCs like DRA7 have a RAMINIT register specification
different from the other AMxx SoCs and as expected by the
existing driver.
To add more insanity, this register is shared with other
IPs like DSS, PCIe and PWM.
Provides a more generic mechanism to specify the RAMINIT
register location and START/DONE bit position and use the
syscon/regmap framework to access the register.
---
.../devicetree/bindings/net/can/c_can.txt | 7 ++
drivers/net/can/c_can/c_can.h | 11 ++-
drivers/net/can/c_can/c_can_platform.c | 109 +++++++++++++++------
3 files changed, 95 insertions(+), 32 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index 8f1ae81..e12d1a1 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
- ti,hwmods : Must be "d_can<n>" or "c_can<n>", n being the
instance number
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
Post by Roger Quadros
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
This should not be encoded in DT! This is not describing hardware setup.
The driver should know where the bits are for the syscon phandle,
depending on which SoC it runs...
Roger Quadros
2014-09-30 13:33:43 UTC
Permalink
Post by Wolfram Sang
Post by Roger Quadros
Some TI SoCs like DRA7 have a RAMINIT register specification
different from the other AMxx SoCs and as expected by the
existing driver.
To add more insanity, this register is shared with other
IPs like DSS, PCIe and PWM.
Provides a more generic mechanism to specify the RAMINIT
register location and START/DONE bit position and use the
syscon/regmap framework to access the register.
---
.../devicetree/bindings/net/can/c_can.txt | 7 ++
drivers/net/can/c_can/c_can.h | 11 ++-
drivers/net/can/c_can/c_can_platform.c | 109 +++++++++++++++------
3 files changed, 95 insertions(+), 32 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index 8f1ae81..e12d1a1 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
- ti,hwmods : Must be "d_can<n>" or "c_can<n>", n being the
instance number
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
I had used plain "syscon" in the earlier revisions but was asked to make it a TI specific
property since only TI uses this mechanism.
Post by Wolfram Sang
Post by Roger Quadros
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
This should not be encoded in DT! This is not describing hardware setup.
The driver should know where the bits are for the syscon phandle,
depending on which SoC it runs...
OK. I'll think of matching the compatible ID with SOC specific data in the driver.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Wolfram Sang
2014-09-30 13:52:26 UTC
Permalink
Post by Roger Quadros
Post by Wolfram Sang
Post by Roger Quadros
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
I had used plain "syscon" in the earlier revisions but was asked to make it a TI specific
property since only TI uses this mechanism.
I see, when was that? Currently, it looks messy :( Grepping through the
dts files in 3.17-rc7, I see that bcm7445 uses "syscon" and variants
with prefixes, STE uses it, too. Samsung uses "samsung,syscon-phandle",
st uses "st,syscon"...

The MACID readout patches for AM335x (just applied right now) also use
"syscon": https://patchwork.ozlabs.org/patch/394289/

I'd vote for a generic "syscon" to be OK, yet I guess the DT maintainers
will have the final word.
Post by Roger Quadros
Post by Wolfram Sang
Post by Roger Quadros
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
This should not be encoded in DT! This is not describing hardware setup.
The driver should know where the bits are for the syscon phandle,
depending on which SoC it runs...
OK. I'll think of matching the compatible ID with SOC specific data in the driver.
Great, thanks!
Roger Quadros
2014-09-30 13:58:01 UTC
Permalink
Post by Wolfram Sang
Post by Roger Quadros
Post by Wolfram Sang
Post by Roger Quadros
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
I had used plain "syscon" in the earlier revisions but was asked to make it a TI specific
property since only TI uses this mechanism.
I see, when was that? Currently, it looks messy :( Grepping through the
dts files in 3.17-rc7, I see that bcm7445 uses "syscon" and variants
with prefixes, STE uses it, too. Samsung uses "samsung,syscon-phandle",
st uses "st,syscon"...
The MACID readout patches for AM335x (just applied right now) also use
"syscon": https://patchwork.ozlabs.org/patch/394289/
I'd vote for a generic "syscon" to be OK, yet I guess the DT maintainers
will have the final word.
Now that I actually checked, it was never just "syscon" but just without the "ti" vendor prefix.
Sorry for the misinformation.

As just TI is using this out of band RAMINIT mechanism, should it be "ti,syscon" or just "syscon"?

cheers,
-roger
Wolfram Sang
2014-09-30 14:19:10 UTC
Permalink
Post by Roger Quadros
As just TI is using this out of band RAMINIT mechanism, should it be "ti,syscon" or just "syscon"?
Yes, only TI uses this out-of-band RAMINIT (currently, at least). So, we
need an (optional) way to describe that. However, accessing syscon
registers in general is not TI specific and a generic way to do this
should be used. Which looks to me like the "syscon" property to allow
access to the register. Still, we should ask DT maintainers about it,
maybe they prefer a more precise property like "syscon-raminit" to allow
for further syscon extensions later or something...
Marc Kleine-Budde
2014-09-30 14:22:08 UTC
Permalink
Post by Wolfram Sang
Post by Roger Quadros
As just TI is using this out of band RAMINIT mechanism, should it be "ti,syscon" or just "syscon"?
Yes, only TI uses this out-of-band RAMINIT (currently, at least). So, we
need an (optional) way to describe that. However, accessing syscon
registers in general is not TI specific and a generic way to do this
should be used. Which looks to me like the "syscon" property to allow
access to the register. Still, we should ask DT maintainers about it,
maybe they prefer a more precise property like "syscon-raminit" to allow
for further syscon extensions later or something...
What do you think about putting the bit information in the
syscon-raminit phandle as additional arguments?

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 |
Wolfram Sang
2014-09-30 14:49:50 UTC
Permalink
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Roger Quadros
As just TI is using this out of band RAMINIT mechanism, should it be "ti,syscon" or just "syscon"?
Yes, only TI uses this out-of-band RAMINIT (currently, at least). So, we
need an (optional) way to describe that. However, accessing syscon
registers in general is not TI specific and a generic way to do this
should be used. Which looks to me like the "syscon" property to allow
access to the register. Still, we should ask DT maintainers about it,
maybe they prefer a more precise property like "syscon-raminit" to allow
for further syscon extensions later or something...
What do you think about putting the bit information in the
syscon-raminit phandle as additional arguments?
Then we'd have <n> syscon phandles for <n> instances?

Also, judging from Markus patch [1] there is already some
infrastructure, namely syscon_regmap_lookup_by_phandle(). From a
glimpse, it doesn't look viable to add such a support to it.

So, I'd rather drop additional arguments.

Why would you like to have it encoded in DT?
Marc Kleine-Budde
2014-09-30 15:01:06 UTC
Permalink
Post by Wolfram Sang
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Roger Quadros
As just TI is using this out of band RAMINIT mechanism, should it be "ti,syscon" or just "syscon"?
Yes, only TI uses this out-of-band RAMINIT (currently, at least). So, we
need an (optional) way to describe that. However, accessing syscon
registers in general is not TI specific and a generic way to do this
should be used. Which looks to me like the "syscon" property to allow
access to the register. Still, we should ask DT maintainers about it,
maybe they prefer a more precise property like "syscon-raminit" to allow
for further syscon extensions later or something...
What do you think about putting the bit information in the
syscon-raminit phandle as additional arguments?
Then we'd have <n> syscon phandles for <n> instances?
Also, judging from Markus patch [1] there is already some
infrastructure, namely syscon_regmap_lookup_by_phandle(). From a
glimpse, it doesn't look viable to add such a support to it.
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
additional parameters. Have a look at:

drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c

First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
Post by Wolfram Sang
So, I'd rather drop additional arguments.
Why would you like to have it encoded in DT?
Where put the information then? Into the driver, but where do you get
the reference which instance of the DCAN you are, so that you can look
up the correct bits?

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 |
Wolfram Sang
2014-09-30 15:25:50 UTC
Permalink
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>

Phew... Then we should really have a "syscon-raminit" property probably,
so that at least plain "syscon" has a consistent syntax?
Post by Marc Kleine-Budde
Post by Wolfram Sang
So, I'd rather drop additional arguments.
Why would you like to have it encoded in DT?
Where put the information then? Into the driver, but where do you get
the reference which instance of the DCAN you are, so that you can look
up the correct bits?
Agreed. I thought we had this information in the driver already, but we
haven't...
Marc Kleine-Budde
2014-09-30 16:04:19 UTC
Permalink
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.

Roger, can we derive both start and done bit from a common reg_shift?
Post by Wolfram Sang
Phew... Then we should really have a "syscon-raminit" property probably,
so that at least plain "syscon" has a consistent syntax?
I think^whope we can have the same syntax as the stmmc :D
Post by Wolfram Sang
Post by Marc Kleine-Budde
Post by Wolfram Sang
So, I'd rather drop additional arguments.
Why would you like to have it encoded in DT?
Where put the information then? Into the driver, but where do you get
the reference which instance of the DCAN you are, so that you can look
up the correct bits?
Agreed. I thought we had this information in the driver already, but we
haven't...
The current driver relies on the of_alias_get_id(), which isn't
considered best practice, is it? So I want to avoid this when switching
to syscon.

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 |
Roger Quadros
2014-10-01 08:45:51 UTC
Permalink
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.
Roger, can we derive both start and done bit from a common reg_shift?
I'm sorry I didn't understand what you meant.

<&syscon_phandl> <reg offset> <start bit> <stop bit> should work well for us.
Even though reg offset is the same for both the DCAN instances.
Post by Marc Kleine-Budde
Post by Wolfram Sang
Phew... Then we should really have a "syscon-raminit" property probably,
so that at least plain "syscon" has a consistent syntax?
I think^whope we can have the same syntax as the stmmc :D
I agree too.
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Post by Wolfram Sang
So, I'd rather drop additional arguments.
Why would you like to have it encoded in DT?
Where put the information then? Into the driver, but where do you get
the reference which instance of the DCAN you are, so that you can look
up the correct bits?
Agreed. I thought we had this information in the driver already, but we
haven't...
The current driver relies on the of_alias_get_id(), which isn't
considered best practice, is it? So I want to avoid this when switching
to syscon.
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-10-01 08:47:58 UTC
Permalink
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.
Roger, can we derive both start and done bit from a common reg_shift?
I'm sorry I didn't understand what you meant.
<&syscon_phandl> <reg offset> <start bit> <stop bit> should work well for us.
Even though reg offset is the same for both the DCAN instances.
What's start bit and stop bit for instance 0 and 1 on that SoC that has
two instances??

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 |
Roger Quadros
2014-10-01 09:06:55 UTC
Permalink
Post by Marc Kleine-Budde
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.
Roger, can we derive both start and done bit from a common reg_shift?
I'm sorry I didn't understand what you meant.
<&syscon_phandl> <reg offset> <start bit> <stop bit> should work well for us.
Even though reg offset is the same for both the DCAN instances.
What's start bit and stop bit for instance 0 and 1 on that SoC that has
two instances??
we have 3 SoCs at the moment, all have 2 DCAN instances.

AM33xx & AM43xx
instance start stop
1 0 8
2 1 9

DRA7xx
instance start stop
1 3 1
2 5 2

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-10-01 10:01:58 UTC
Permalink
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.
Roger, can we derive both start and done bit from a common reg_shift?
I'm sorry I didn't understand what you meant.
<&syscon_phandl> <reg offset> <start bit> <stop bit> should work well for us.
Even though reg offset is the same for both the DCAN instances.
What's start bit and stop bit for instance 0 and 1 on that SoC that has
two instances?
we have 3 SoCs at the moment, all have 2 DCAN instances.
AM33xx & AM43xx
instance start stop
1 0 8
2 1 9
If we use a 0-based numbering for the instances:
instance start stop
0 (0 << instance) (8 << instance)
1 (0 << instance) (8 << instance)
Post by Roger Quadros
DRA7xx
instance start stop
1 3 1
2 5 2
^
5 or 4?

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 |
Roger Quadros
2014-10-01 10:12:55 UTC
Permalink
Post by Marc Kleine-Budde
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.
Roger, can we derive both start and done bit from a common reg_shift?
I'm sorry I didn't understand what you meant.
<&syscon_phandl> <reg offset> <start bit> <stop bit> should work well for us.
Even though reg offset is the same for both the DCAN instances.
What's start bit and stop bit for instance 0 and 1 on that SoC that has
two instances?
we have 3 SoCs at the moment, all have 2 DCAN instances.
AM33xx & AM43xx
instance start stop
1 0 8
2 1 9
instance start stop
0 (0 << instance) (8 << instance)
1 (0 << instance) (8 << instance)
How does the instance number get set? What happens on boards where the first instance is unused
while the second one is in use?
Post by Marc Kleine-Budde
Post by Roger Quadros
DRA7xx
instance start stop
1 3 1
2 5 2
^
5 or 4?
Unfortunately it is 5 ;)
We have display IP related bit in between 3 and 5 :P

cheers,
-roger

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-10-01 10:26:57 UTC
Permalink
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Marc Kleine-Budde
Yes, but syscon_regmap_lookup_by_phandle() doesn't need any support for
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
First get the regmap, then the 1st argument is the offset in the regmap,
the 2nd and 3rd could be the bits.
So, for one driver the extra arguments are: <reg> <start_bit> <stop_bit>
For another driver (the stmmac example): <reg_offset> <reg_shift>
The DCAN's "reg" is a "reg_offset" as in the stmmc.
Roger, can we derive both start and done bit from a common reg_shift?
I'm sorry I didn't understand what you meant.
<&syscon_phandl> <reg offset> <start bit> <stop bit> should work well for us.
Even though reg offset is the same for both the DCAN instances.
What's start bit and stop bit for instance 0 and 1 on that SoC that has
two instances?
we have 3 SoCs at the moment, all have 2 DCAN instances.
AM33xx & AM43xx
instance start stop
1 0 8
2 1 9
instance start stop
0 (0 << instance) (8 << instance)
1 (0 << instance) (8 << instance)
How does the instance number get set? What happens on boards where
the first instance is unused while the second one is in use?
Via a single "instance" parameter of the syscon phandle....
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Roger Quadros
DRA7xx
instance start stop
1 3 1
2 5 2
^
5 or 4?
Unfortunately it is 5 ;)
We have display IP related bit in between 3 and 5 :P
What on earth were the HW engineers thinking????????????

...if we just have the instance parameter in the syscon phandle, we have
to put the mapping into the driver, which makes IMHO no sense, because
you have to touch the driver, if there is another SoC with the DCAN core.

AFAICS we have these options:
1) syscon phandle with three parameters:
reg offset, start bit shift, stop bit shift
(the name of the syscon phandle is a different topic)
2) a single ti,start-stop-bit option with two parameter
3) two ti,* entries with a single parameter each
(as in Roger's initial patch)

Wolfram, which solution do you prefer? I'm in favour of 3 (+ plus a
phandle with a reg offset parameter).

puzzled,
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 |
Wolfram Sang
2014-10-01 10:43:18 UTC
Permalink
Post by Marc Kleine-Budde
Post by Roger Quadros
Unfortunately it is 5 ;)
We have display IP related bit in between 3 and 5 :P
What on earth were the HW engineers thinking????????????
"Let's test my RNG on the bit-placement of this register" :)
Post by Marc Kleine-Budde
...if we just have the instance parameter in the syscon phandle, we have
to put the mapping into the driver, which makes IMHO no sense, because
you have to touch the driver, if there is another SoC with the DCAN core.
... which would be my preferred solution. I think new SoCs should have
some kind of:

compatible = "commodore,c64ultra", "bosch,d_can";

in the DT anyhow to allow for SoC specific quirks/adjustments. And
custom raminit belongs to that IMO (see the ti routine getting more and
more specific).
Roger Quadros
2014-10-01 10:57:54 UTC
Permalink
Post by Wolfram Sang
Post by Marc Kleine-Budde
Post by Roger Quadros
Unfortunately it is 5 ;)
We have display IP related bit in between 3 and 5 :P
What on earth were the HW engineers thinking????????????
"Let's test my RNG on the bit-placement of this register" :)
:D
Post by Wolfram Sang
Post by Marc Kleine-Budde
...if we just have the instance parameter in the syscon phandle, we have
to put the mapping into the driver, which makes IMHO no sense, because
you have to touch the driver, if there is another SoC with the DCAN core.
My guess is that TI won't come up with a 3rd variant so we won't have to
touch the driver, but you never know for sure.
Post by Wolfram Sang
... which would be my preferred solution. I think new SoCs should have
compatible = "commodore,c64ultra", "bosch,d_can";
in the DT anyhow to allow for SoC specific quirks/adjustments. And
custom raminit belongs to that IMO (see the ti routine getting more and
more specific).
Right. For now we need 2 start/stop definations for the existing TI Socs.

but where to store the raminit start/stop bits? The driver_data currently seems to
contain the CAN type C_CAN vs D_CAN without containing it in a platform_data structure.

Is it OK to create a new platform_data structure for CAN and put the type and raminit start/stop
bits there?

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-10-01 11:06:39 UTC
Permalink
Post by Roger Quadros
Post by Wolfram Sang
Post by Marc Kleine-Budde
...if we just have the instance parameter in the syscon phandle, we have
to put the mapping into the driver, which makes IMHO no sense, because
you have to touch the driver, if there is another SoC with the DCAN core.
My guess is that TI won't come up with a 3rd variant so we won't have
to touch the driver, but you never know for sure.
When I comes to 99% compatible hardware.... I've seen some.
Post by Roger Quadros
Post by Wolfram Sang
... which would be my preferred solution. I think new SoCs should have
compatible = "commodore,c64ultra", "bosch,d_can";
in the DT anyhow to allow for SoC specific quirks/adjustments. And
custom raminit belongs to that IMO (see the ti routine getting more and
more specific).
Right. For now we need 2 start/stop definations for the existing TI Socs.
but where to store the raminit start/stop bits? The driver_data currently seems to
contain the CAN type C_CAN vs D_CAN without containing it in a platform_data structure.
Is it OK to create a new platform_data structure for CAN and put the type and raminit start/stop
bits there?
Yes, have a look how it's handled in the flexcan driver.

regards,
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 |
Wolfram Sang
2014-10-01 11:10:34 UTC
Permalink
Post by Roger Quadros
Is it OK to create a new platform_data structure for CAN and put the type and raminit start/stop
bits there?
I'd say yes, don't see a reason not to.
Marc Kleine-Budde
2014-10-01 11:11:44 UTC
Permalink
Post by Wolfram Sang
compatible = "commodore,c64ultra", "bosch,d_can";
\o/
--
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 |
Marc Kleine-Budde
2014-09-30 13:45:36 UTC
Permalink
Post by Wolfram Sang
Post by Roger Quadros
Some TI SoCs like DRA7 have a RAMINIT register specification
different from the other AMxx SoCs and as expected by the
existing driver.
To add more insanity, this register is shared with other
IPs like DSS, PCIe and PWM.
Provides a more generic mechanism to specify the RAMINIT
register location and START/DONE bit position and use the
syscon/regmap framework to access the register.
---
.../devicetree/bindings/net/can/c_can.txt | 7 ++
drivers/net/can/c_can/c_can.h | 11 ++-
drivers/net/can/c_can/c_can_platform.c | 109 +++++++++++++++------
3 files changed, 95 insertions(+), 32 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index 8f1ae81..e12d1a1 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
- ti,hwmods : Must be "d_can<n>" or "c_can<n>", n being the
instance number
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
Post by Roger Quadros
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
This should not be encoded in DT! This is not describing hardware setup.
The driver should know where the bits are for the syscon phandle,
depending on which SoC it runs...
Is the register shared by more than one core? If so the information has
to go somewhere. Using an alias in the DT is probably the wrong approach.

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 |
Roger Quadros
2014-09-30 14:02:41 UTC
Permalink
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Roger Quadros
Some TI SoCs like DRA7 have a RAMINIT register specification
different from the other AMxx SoCs and as expected by the
existing driver.
To add more insanity, this register is shared with other
IPs like DSS, PCIe and PWM.
Provides a more generic mechanism to specify the RAMINIT
register location and START/DONE bit position and use the
syscon/regmap framework to access the register.
---
.../devicetree/bindings/net/can/c_can.txt | 7 ++
drivers/net/can/c_can/c_can.h | 11 ++-
drivers/net/can/c_can/c_can_platform.c | 109 +++++++++++++++------
3 files changed, 95 insertions(+), 32 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index 8f1ae81..e12d1a1 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
- ti,hwmods : Must be "d_can<n>" or "c_can<n>", n being the
instance number
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
Post by Roger Quadros
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
This should not be encoded in DT! This is not describing hardware setup.
The driver should know where the bits are for the syscon phandle,
depending on which SoC it runs...
Is the register shared by more than one core? If so the information has
to go somewhere. Using an alias in the DT is probably the wrong approach.
In case of the DRA7xx Soc, this syscon register is shared by multiple cores. (CAN, Display, etc), sigh!!
For AM335x and AM43xx SoCs, the register is used only for DCAN. but shared by 2 DCAN instances.

Shouldn't the information for the CAN specific bits lie in the CAN driver?

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-09-30 14:11:08 UTC
Permalink
Post by Roger Quadros
Post by Marc Kleine-Budde
Post by Wolfram Sang
Post by Roger Quadros
Some TI SoCs like DRA7 have a RAMINIT register specification
different from the other AMxx SoCs and as expected by the
existing driver.
To add more insanity, this register is shared with other
IPs like DSS, PCIe and PWM.
Provides a more generic mechanism to specify the RAMINIT
register location and START/DONE bit position and use the
syscon/regmap framework to access the register.
---
.../devicetree/bindings/net/can/c_can.txt | 7 ++
drivers/net/can/c_can/c_can.h | 11 ++-
drivers/net/can/c_can/c_can_platform.c | 109 +++++++++++++++------
3 files changed, 95 insertions(+), 32 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index 8f1ae81..e12d1a1 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
- ti,hwmods : Must be "d_can<n>" or "c_can<n>", n being the
instance number
+- ti,raminit-syscon : Handle to system control region that contains the
+ RAMINIT register. If specified, the second memory resource
+ in the reg property must index into the RAMINIT
+ register within the syscon region
There seems to be a simple "syscon" property these days.
Post by Roger Quadros
+- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
+- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
This should not be encoded in DT! This is not describing hardware setup.
The driver should know where the bits are for the syscon phandle,
depending on which SoC it runs...
Is the register shared by more than one core? If so the information has
to go somewhere. Using an alias in the DT is probably the wrong approach.
In case of the DRA7xx Soc, this syscon register is shared by multiple cores. (CAN, Display, etc), sigh!!
For AM335x and AM43xx SoCs, the register is used only for DCAN. but shared by 2 DCAN instances.
Shouldn't the information for the CAN specific bits lie in the CAN driver?
As there are more than one DCAN instance on the same SOC the information
which DCAN instance uses which bits in the register has to go somewhere.
We might add these bits as the 3rd and 4th parameter to the syscon phandle.

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 |
Roger Quadros
2014-09-09 14:31:08 UTC
Permalink
Pass the correct 'mask' and 'value' bits to c_can_hw_raminit_wait_ti().
They seem to have been swapped in the usage instances.

TI's RAMINIT DONE mechanism is buggy and may not always be
set after the START bit is set. So add a timeout mechanism to
c_can_hw_raminit_wait_ti().

Signed-off-by: Roger Quadros <***@ti.com>
---
drivers/net/can/c_can/c_can_platform.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index 109cb44..b144e71 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -75,10 +75,18 @@ static void c_can_plat_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
u32 val)
{
+ int timeout = 0;
/* We look only at the bits of our instance. */
val &= mask;
- while ((readl(priv->raminit_ctrlreg) & mask) != val)
+ while ((readl(priv->raminit_ctrlreg) & mask) != val) {
udelay(1);
+ timeout++;
+
+ if (timeout == 1000) {
+ dev_err(&priv->dev->dev, "%s: time out\n", __func__);
+ break;
+ }
+ }
}

static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
@@ -97,14 +105,14 @@ static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
writel(ctrl, priv->raminit_ctrlreg);
ctrl &= ~CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, ctrl, mask);
+ c_can_hw_raminit_wait_ti(priv, mask, ctrl);

if (enable) {
/* Set start bit and wait for the done bit. */
ctrl |= CAN_RAMINIT_START_MASK(priv->instance);
writel(ctrl, priv->raminit_ctrlreg);
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, ctrl, mask);
+ c_can_hw_raminit_wait_ti(priv, mask, ctrl);
}
spin_unlock(&raminit_lock);
}
--
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-09-09 14:34:05 UTC
Permalink
Post by Roger Quadros
Pass the correct 'mask' and 'value' bits to c_can_hw_raminit_wait_ti().
They seem to have been swapped in the usage instances.
Can you split this fix into a seperate patch, please.
Post by Roger Quadros
TI's RAMINIT DONE mechanism is buggy and may not always be
set after the START bit is set. So add a timeout mechanism to
c_can_hw_raminit_wait_ti().
What should happen if the timeout occurs?

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 |
Roger Quadros
2014-09-09 14:39:52 UTC
Permalink
Post by Marc Kleine-Budde
Post by Roger Quadros
Pass the correct 'mask' and 'value' bits to c_can_hw_raminit_wait_ti().
They seem to have been swapped in the usage instances.
Can you split this fix into a seperate patch, please.
OK.
Post by Marc Kleine-Budde
Post by Roger Quadros
TI's RAMINIT DONE mechanism is buggy and may not always be
set after the START bit is set. So add a timeout mechanism to
c_can_hw_raminit_wait_ti().
What should happen if the timeout occurs?
I'm not sure yet. I will verify if the hardware still works or not in that case.
If it doesn't work then we should fail.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Marc Kleine-Budde
2014-09-16 14:13:33 UTC
Permalink
Post by Marc Kleine-Budde
Post by Roger Quadros
Pass the correct 'mask' and 'value' bits to c_can_hw_raminit_wait_ti().
They seem to have been swapped in the usage instances.
Can you split this fix into a seperate patch, please.
OK.
I've added this fix only to the can-tree.

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 |
Nishanth Menon
2014-09-09 14:34:22 UTC
Permalink
Post by Roger Quadros
Pass the correct 'mask' and 'value' bits to c_can_hw_raminit_wait_ti().
They seem to have been swapped in the usage instances.
TI's RAMINIT DONE mechanism is buggy and may not always be
set after the START bit is set. So add a timeout mechanism to
c_can_hw_raminit_wait_ti().
---
drivers/net/can/c_can/c_can_platform.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index 109cb44..b144e71 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -75,10 +75,18 @@ static void c_can_plat_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
u32 val)
{
+ int timeout = 0;
/* We look only at the bits of our instance. */
val &= mask;
- while ((readl(priv->raminit_ctrlreg) & mask) != val)
+ while ((readl(priv->raminit_ctrlreg) & mask) != val) {
udelay(1);
+ timeout++;
+
+ if (timeout == 1000) {
How did we come up with this number?
Post by Roger Quadros
+ dev_err(&priv->dev->dev, "%s: time out\n", __func__);
+ break;
lets say we did timeout..
Post by Roger Quadros
+ }
+ }
}
static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
@@ -97,14 +105,14 @@ static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
writel(ctrl, priv->raminit_ctrlreg);
ctrl &= ~CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, ctrl, mask);
+ c_can_hw_raminit_wait_ti(priv, mask, ctrl);
if (enable) {
/* Set start bit and wait for the done bit. */
ctrl |= CAN_RAMINIT_START_MASK(priv->instance);
writel(ctrl, priv->raminit_ctrlreg);
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, ctrl, mask);
+ c_can_hw_raminit_wait_ti(priv, mask, ctrl);
is it possible for us to continue? does it make sense for us to change
that void to a int and handle error cascading?
Post by Roger Quadros
}
spin_unlock(&raminit_lock);
}
--
Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Roger Quadros
2014-09-09 14:45:40 UTC
Permalink
Post by Nishanth Menon
Post by Roger Quadros
Pass the correct 'mask' and 'value' bits to c_can_hw_raminit_wait_ti().
They seem to have been swapped in the usage instances.
TI's RAMINIT DONE mechanism is buggy and may not always be
set after the START bit is set. So add a timeout mechanism to
c_can_hw_raminit_wait_ti().
---
drivers/net/can/c_can/c_can_platform.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index 109cb44..b144e71 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -75,10 +75,18 @@ static void c_can_plat_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
u32 val)
{
+ int timeout = 0;
/* We look only at the bits of our instance. */
val &= mask;
- while ((readl(priv->raminit_ctrlreg) & mask) != val)
+ while ((readl(priv->raminit_ctrlreg) & mask) != val) {
udelay(1);
+ timeout++;
+
+ if (timeout == 1000) {
How did we come up with this number?
wild guess ;), that it should be set in a few microseconds and the delay is not too
large.

Till I don't hear from hardware guys, it will remain a guess.
Post by Nishanth Menon
Post by Roger Quadros
+ dev_err(&priv->dev->dev, "%s: time out\n", __func__);
+ break;
lets say we did timeout..
Post by Roger Quadros
+ }
+ }
}
static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
@@ -97,14 +105,14 @@ static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
writel(ctrl, priv->raminit_ctrlreg);
ctrl &= ~CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, ctrl, mask);
+ c_can_hw_raminit_wait_ti(priv, mask, ctrl);
if (enable) {
/* Set start bit and wait for the done bit. */
ctrl |= CAN_RAMINIT_START_MASK(priv->instance);
writel(ctrl, priv->raminit_ctrlreg);
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
- c_can_hw_raminit_wait_ti(priv, ctrl, mask);
+ c_can_hw_raminit_wait_ti(priv, mask, ctrl);
is it possible for us to continue? does it make sense for us to change
that void to a int and handle error cascading?
I will verify this first to check if the hardware works or not in the failing case.
Considering we never checked for the DONE bit in our earlier TI releases maybe it works.

But I'll verify and get back.
Post by Nishanth Menon
Post by Roger Quadros
}
spin_unlock(&raminit_lock);
}
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Nishanth Menon
2014-09-09 14:51:16 UTC
Permalink
On 09/09/2014 09:45 AM, Roger Quadros wrote:
[...]
Post by Roger Quadros
Post by Nishanth Menon
Post by Roger Quadros
/* We look only at the bits of our instance. */
val &= mask;
- while ((readl(priv->raminit_ctrlreg) & mask) != val)
+ while ((readl(priv->raminit_ctrlreg) & mask) != val) {
udelay(1);
+ timeout++;
+
+ if (timeout == 1000) {
How did we come up with this number?
wild guess ;), that it should be set in a few microseconds and the delay is not too
large.
Till I don't hear from hardware guys, it will remain a guess.
in cases like these, I suggest using emperical data as point ->
example doing some 10,000 iterations of the operation and picking up
the worse case number and double it.

Either way, you need to document the same, else a few years down the
line, when that number is in question, no one will know what it's
basis was..
--
Regards,
Nishanth Menon
Roger Quadros
2014-09-09 14:54:26 UTC
Permalink
Post by Nishanth Menon
[...]
Post by Roger Quadros
Post by Nishanth Menon
Post by Roger Quadros
/* We look only at the bits of our instance. */
val &= mask;
- while ((readl(priv->raminit_ctrlreg) & mask) != val)
+ while ((readl(priv->raminit_ctrlreg) & mask) != val) {
udelay(1);
+ timeout++;
+
+ if (timeout == 1000) {
How did we come up with this number?
wild guess ;), that it should be set in a few microseconds and the delay is not too
large.
Till I don't hear from hardware guys, it will remain a guess.
in cases like these, I suggest using emperical data as point ->
example doing some 10,000 iterations of the operation and picking up
the worse case number and double it.
In my tests the bit was either set immediately or never at all.
Not sure if we should increase it further.
Post by Nishanth Menon
Either way, you need to document the same, else a few years down the
line, when that number is in question, no one will know what it's
basis was..
OK. I'll add a comment there.

cheers,
-roger
Roger Quadros
2014-09-09 14:31:10 UTC
Permalink
Some SoCs e.g. (TI DRA7xx) need a START pulse to start the
RAMINIT sequence i.e. START bit must be set and cleared before
checking for the DONE bit status. Add a new DT property "raminit-pulse"
to specify if this mechanism must be used for RAMINIT.

Signed-off-by: Roger Quadros <***@ti.com>
---
Documentation/devicetree/bindings/net/can/c_can.txt | 3 +++
drivers/net/can/c_can/c_can.h | 1 +
drivers/net/can/c_can/c_can_platform.c | 8 ++++++++
3 files changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/can/c_can.txt b/Documentation/devicetree/bindings/net/can/c_can.txt
index e12d1a1..705411f 100644
--- a/Documentation/devicetree/bindings/net/can/c_can.txt
+++ b/Documentation/devicetree/bindings/net/can/c_can.txt
@@ -19,6 +19,9 @@ Optional properties:
register within the syscon region
- ti,raminit-start-bit : Bit posistion of START bit in the RAMINIT register
- ti,raminit-done-bit : Bit position of DONE bit in the RAMINIT register
+- ti,raminit-pulse : Property must exist if START pulse is needed for RAMINIT
+ sequence i.e. START bit will be set and cleared before
+ checking for DONE bit.

Note: "ti,hwmods" field is used to fetch the base address and irq
resources from TI, omap hwmod data base during device registration.
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index bf68822..85b5ad0 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -175,6 +175,7 @@ struct c_can_raminit {
unsigned int reg; /* register index within syscon */
u8 start_bit; /* START bit position in raminit reg. */
u8 done_bit; /* DONE bit position in raminit reg. */
+ bool needs_pulse; /* If set, sets and clears START bit (pulse) */
};

/* c_can private data structure */
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index fb0c35b..5ae9eb3 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -120,6 +120,12 @@ static void c_can_hw_raminit_syscon(const struct c_can_priv *priv, bool enable)
ctrl |= 1 << raminit->start_bit;
regmap_write(raminit->syscon, raminit->reg, ctrl);

+ /* clear START bit if start pulse is needed */
+ if (raminit->needs_pulse) {
+ ctrl &= ~(1 << raminit->start_bit);
+ regmap_write(raminit->syscon, raminit->reg, ctrl);
+ }
+
ctrl |= 1 << raminit->done_bit;
c_can_hw_raminit_wait_syscon(priv, mask, ctrl);
}
@@ -340,6 +346,8 @@ static int c_can_plat_probe(struct platform_device *pdev)
}

priv->raminit_sys.done_bit = val;
+ priv->raminit_sys.needs_pulse = of_property_read_bool(np,
+ "ti,raminit-pulse");
priv->raminit = c_can_hw_raminit_syscon;
break;
default:
--
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...