All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] hwinit support for non-TI devices
@ 2014-05-13 13:40 Marc Kleine-Budde
  2014-05-13 13:40 ` [PATCH v4 1/3] can: c_can: make {read,write}_reg functions const Marc Kleine-Budde
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2014-05-13 13:40 UTC (permalink / raw)
  To: linux-can; +Cc: kernel

Hello,

picking uo Pavel Machek's and Thor Thayer's patches.

changes since v3:
- split make const into seperate patch (1/3)
- squash make const of 32 bit accessor functions into existing 32-bit accesses (2/3)
- the remaining changes are on 3/3

Marc


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4 1/3] can: c_can: make {read,write}_reg functions const
  2014-05-13 13:40 [PATCH v4 0/3] hwinit support for non-TI devices Marc Kleine-Budde
@ 2014-05-13 13:40 ` Marc Kleine-Budde
  2014-05-13 13:40 ` [PATCH v4 2/3] can: c_can: Add and make use of 32-bit accesses functions Marc Kleine-Budde
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2014-05-13 13:40 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Pavel Machek, Thor Thayer, Marc Kleine-Budde

From: Pavel Machek <pavel@denx.de>

This patch makes the {read,write}_reg functions const, this is a preparation to
make use of {read,write}_reg in the hwinit callback.

Signed-off-by: Thor Thayer <tthayer@altera.com>
Signed-off-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.h          |  4 ++--
 drivers/net/can/c_can/c_can_platform.c | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index c56f1b1..b948b55 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -176,8 +176,8 @@ struct c_can_priv {
 	atomic_t tx_active;
 	unsigned long tx_dir;
 	int last_status;
-	u16 (*read_reg) (struct c_can_priv *priv, enum reg index);
-	void (*write_reg) (struct c_can_priv *priv, enum reg index, u16 val);
+	u16 (*read_reg) (const struct c_can_priv *priv, enum reg index);
+	void (*write_reg) (const struct c_can_priv *priv, enum reg index, u16 val);
 	void __iomem *base;
 	const u16 *regs;
 	void *priv;		/* for board-specific data */
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index 1df0b32..0b44f4d 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -47,31 +47,31 @@ static DEFINE_SPINLOCK(raminit_lock);
  * registers can be aligned to a 16-bit boundary or 32-bit boundary etc.
  * Handle the same by providing a common read/write interface.
  */
-static u16 c_can_plat_read_reg_aligned_to_16bit(struct c_can_priv *priv,
+static u16 c_can_plat_read_reg_aligned_to_16bit(const struct c_can_priv *priv,
 						enum reg index)
 {
 	return readw(priv->base + priv->regs[index]);
 }
 
-static void c_can_plat_write_reg_aligned_to_16bit(struct c_can_priv *priv,
+static void c_can_plat_write_reg_aligned_to_16bit(const struct c_can_priv *priv,
 						enum reg index, u16 val)
 {
 	writew(val, priv->base + priv->regs[index]);
 }
 
-static u16 c_can_plat_read_reg_aligned_to_32bit(struct c_can_priv *priv,
+static u16 c_can_plat_read_reg_aligned_to_32bit(const struct c_can_priv *priv,
 						enum reg index)
 {
 	return readw(priv->base + 2 * priv->regs[index]);
 }
 
-static void c_can_plat_write_reg_aligned_to_32bit(struct c_can_priv *priv,
+static void c_can_plat_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
 						enum reg index, u16 val)
 {
 	writew(val, priv->base + 2 * priv->regs[index]);
 }
 
-static void c_can_hw_raminit_wait(const struct c_can_priv *priv, u32 mask,
+static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
 				  u32 val)
 {
 	/* We look only at the bits of our instance. */
-- 
2.0.0.rc0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 2/3] can: c_can: Add and make use of 32-bit accesses functions
  2014-05-13 13:40 [PATCH v4 0/3] hwinit support for non-TI devices Marc Kleine-Budde
  2014-05-13 13:40 ` [PATCH v4 1/3] can: c_can: make {read,write}_reg functions const Marc Kleine-Budde
@ 2014-05-13 13:40 ` Marc Kleine-Budde
  2014-05-13 13:40 ` [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices Marc Kleine-Budde
  2014-05-13 14:26 ` [PATCH v4 0/3] " Marc Kleine-Budde
  3 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2014-05-13 13:40 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Pavel Machek, Thor Thayer, Marc Kleine-Budde

From: Pavel Machek <pavel@denx.de>

Add helpers for 32-bit accesses and replace open-coded 32-bit access
with calls to helpers. Minimum changes are done to the pci case, as I
don't have access to that hardware.

Tested-by: Thor Thayer <tthayer@altera.com>
Signed-off-by: Thor Thayer <tthayer@altera.com>
Signed-off-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.c          | 15 +++++----------
 drivers/net/can/c_can/c_can.h          |  2 ++
 drivers/net/can/c_can/c_can_pci.c      | 19 +++++++++++++++++++
 drivers/net/can/c_can/c_can_platform.c | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index a2ca820..e154b4c 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -252,8 +252,7 @@ static void c_can_obj_update(struct net_device *dev, int iface, u32 cmd, u32 obj
 	struct c_can_priv *priv = netdev_priv(dev);
 	int cnt, reg = C_CAN_IFACE(COMREQ_REG, iface);
 
-	priv->write_reg(priv, reg + 1, cmd);
-	priv->write_reg(priv, reg, obj);
+	priv->write_reg32(priv, reg, (cmd << 16) | obj);
 
 	for (cnt = MIN_TIMEOUT_VALUE; cnt; cnt--) {
 		if (!(priv->read_reg(priv, reg) & IF_COMR_BUSY))
@@ -328,8 +327,7 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface,
 		change_bit(idx, &priv->tx_dir);
 	}
 
-	priv->write_reg(priv, C_CAN_IFACE(ARB1_REG, iface), arb);
-	priv->write_reg(priv, C_CAN_IFACE(ARB2_REG, iface), arb >> 16);
+	priv->write_reg32(priv, C_CAN_IFACE(ARB1_REG, iface), arb);
 
 	priv->write_reg(priv, C_CAN_IFACE(MSGCTRL_REG, iface), ctrl);
 
@@ -391,8 +389,7 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl)
 
 	frame->can_dlc = get_can_dlc(ctrl & 0x0F);
 
-	arb = priv->read_reg(priv, C_CAN_IFACE(ARB1_REG, iface));
-	arb |= priv->read_reg(priv, C_CAN_IFACE(ARB2_REG, iface)) << 16;
+	arb = priv->read_reg32(priv, C_CAN_IFACE(ARB1_REG, iface));
 
 	if (arb & IF_ARB_MSGXTD)
 		frame->can_id = (arb & CAN_EFF_MASK) | CAN_EFF_FLAG;
@@ -424,12 +421,10 @@ static void c_can_setup_receive_object(struct net_device *dev, int iface,
 	struct c_can_priv *priv = netdev_priv(dev);
 
 	mask |= BIT(29);
-	priv->write_reg(priv, C_CAN_IFACE(MASK1_REG, iface), mask);
-	priv->write_reg(priv, C_CAN_IFACE(MASK2_REG, iface), mask >> 16);
+	priv->write_reg32(priv, C_CAN_IFACE(MASK1_REG, iface), mask);
 
 	id |= IF_ARB_MSGVAL;
-	priv->write_reg(priv, C_CAN_IFACE(ARB1_REG, iface), id);
-	priv->write_reg(priv, C_CAN_IFACE(ARB2_REG, iface), id >> 16);
+	priv->write_reg32(priv, C_CAN_IFACE(ARB1_REG, iface), id);
 
 	priv->write_reg(priv, C_CAN_IFACE(MSGCTRL_REG, iface), mcont);
 	c_can_object_put(dev, iface, obj, IF_COMM_RCV_SETUP);
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index b948b55..44433e1 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -178,6 +178,8 @@ struct c_can_priv {
 	int last_status;
 	u16 (*read_reg) (const struct c_can_priv *priv, enum reg index);
 	void (*write_reg) (const struct c_can_priv *priv, enum reg index, u16 val);
+	u32 (*read_reg32) (const struct c_can_priv *priv, enum reg index);
+	void (*write_reg32) (const struct c_can_priv *priv, enum reg index, u32 val);
 	void __iomem *base;
 	const u16 *regs;
 	void *priv;		/* for board-specific data */
diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c
index 58f71e1..db14880 100644
--- a/drivers/net/can/c_can/c_can_pci.c
+++ b/drivers/net/can/c_can/c_can_pci.c
@@ -83,6 +83,23 @@ static void c_can_pci_write_reg_32bit(struct c_can_priv *priv,
 	iowrite32((u32)val, priv->base + 2 * priv->regs[index]);
 }
 
+static u32 c_can_plat_read_reg32(struct c_can_priv *priv, enum reg index)
+{
+	u32 val;
+
+	val = priv->read_reg(priv, index);
+	val |= ((u32) priv->read_reg(priv, index + 1)) << 16;
+
+	return val;
+}
+
+static void c_can_plat_write_reg32(struct c_can_priv *priv, enum reg index,
+		u32 val)
+{
+	priv->write_reg(priv, index + 1, val >> 16);
+	priv->write_reg(priv, index, val);
+}
+
 static void c_can_pci_reset_pch(const struct c_can_priv *priv, bool enable)
 {
 	if (enable) {
@@ -187,6 +204,8 @@ static int c_can_pci_probe(struct pci_dev *pdev,
 		ret = -EINVAL;
 		goto out_free_c_can;
 	}
+	priv->read_reg32 = c_can_plat_read_reg32;
+	priv->write_reg32 = c_can_plat_write_reg32;
 
 	priv->raminit = c_can_pci_data->init;
 
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index 0b44f4d..e71bb76 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -108,6 +108,34 @@ static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
 	spin_unlock(&raminit_lock);
 }
 
+static u32 c_can_plat_read_reg32(const struct c_can_priv *priv, enum reg index)
+{
+	u32 val;
+
+	val = priv->read_reg(priv, index);
+	val |= ((u32) priv->read_reg(priv, index + 1)) << 16;
+
+	return val;
+}
+
+static void c_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index,
+		u32 val)
+{
+	priv->write_reg(priv, index + 1, val>>16);
+	priv->write_reg(priv, index, val);
+}
+
+static u32 d_can_plat_read_reg32(const struct c_can_priv *priv, enum reg index)
+{
+	return readl(priv->base + priv->regs[index]);
+}
+
+static void d_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index,
+		u32 val)
+{
+	writel(val, priv->base + priv->regs[index]);
+}
+
 static struct platform_device_id c_can_id_table[] = {
 	[BOSCH_C_CAN_PLATFORM] = {
 		.name = KBUILD_MODNAME,
@@ -201,11 +229,15 @@ static int c_can_plat_probe(struct platform_device *pdev)
 		case IORESOURCE_MEM_32BIT:
 			priv->read_reg = c_can_plat_read_reg_aligned_to_32bit;
 			priv->write_reg = c_can_plat_write_reg_aligned_to_32bit;
+			priv->read_reg32 = c_can_plat_read_reg32;
+			priv->write_reg32 = c_can_plat_write_reg32;
 			break;
 		case IORESOURCE_MEM_16BIT:
 		default:
 			priv->read_reg = c_can_plat_read_reg_aligned_to_16bit;
 			priv->write_reg = c_can_plat_write_reg_aligned_to_16bit;
+			priv->read_reg32 = c_can_plat_read_reg32;
+			priv->write_reg32 = c_can_plat_write_reg32;
 			break;
 		}
 		break;
@@ -214,6 +246,8 @@ static int c_can_plat_probe(struct platform_device *pdev)
 		priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
 		priv->read_reg = c_can_plat_read_reg_aligned_to_16bit;
 		priv->write_reg = c_can_plat_write_reg_aligned_to_16bit;
+		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");
-- 
2.0.0.rc0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices
  2014-05-13 13:40 [PATCH v4 0/3] hwinit support for non-TI devices Marc Kleine-Budde
  2014-05-13 13:40 ` [PATCH v4 1/3] can: c_can: make {read,write}_reg functions const Marc Kleine-Budde
  2014-05-13 13:40 ` [PATCH v4 2/3] can: c_can: Add and make use of 32-bit accesses functions Marc Kleine-Budde
@ 2014-05-13 13:40 ` Marc Kleine-Budde
  2014-05-27 12:05   ` Pavel Machek
  2014-05-13 14:26 ` [PATCH v4 0/3] " Marc Kleine-Budde
  3 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2014-05-13 13:40 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Pavel Machek, Thor Thayer, Marc Kleine-Budde

From: Pavel Machek <pavel@denx.de>

Non-TI chips (including socfpga) needs different raminit sequence. Implement
it.

Tested-by: Thor Thayer <tthayer@altera.com>
Signed-off-by: Thor Thayer <tthayer@altera.com>
Signed-off-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.h          |  2 ++
 drivers/net/can/c_can/c_can_platform.c | 40 ++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 44433e1..99ad1aa 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -78,6 +78,7 @@ enum reg {
 	C_CAN_INTPND2_REG,
 	C_CAN_MSGVAL1_REG,
 	C_CAN_MSGVAL2_REG,
+	C_CAN_FUNCTION_REG,
 };
 
 static const u16 reg_map_c_can[] = {
@@ -129,6 +130,7 @@ static const u16 reg_map_d_can[] = {
 	[C_CAN_BRPEXT_REG]	= 0x0E,
 	[C_CAN_INT_REG]		= 0x10,
 	[C_CAN_TEST_REG]	= 0x14,
+	[C_CAN_FUNCTION_REG]	= 0x18,
 	[C_CAN_TXRQST1_REG]	= 0x88,
 	[C_CAN_TXRQST2_REG]	= 0x8A,
 	[C_CAN_NEWDAT1_REG]	= 0x9C,
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index e71bb76..a560953 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -40,6 +40,7 @@
 #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);
 /*
  * 16-bit c_can registers can be arranged differently in the memory
@@ -80,7 +81,7 @@ static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
 		udelay(1);
 }
 
-static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
+static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
 {
 	u32 mask = CAN_RAMINIT_ALL_MASK(priv->instance);
 	u32 ctrl;
@@ -96,14 +97,14 @@ static void c_can_hw_raminit(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(priv, ctrl, mask);
+	c_can_hw_raminit_wait_ti(priv, ctrl, mask);
 
 	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(priv, ctrl, mask);
+		c_can_hw_raminit_wait_ti(priv, ctrl, mask);
 	}
 	spin_unlock(&raminit_lock);
 }
@@ -136,6 +137,28 @@ static void d_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index
 	writel(val, priv->base + priv->regs[index]);
 }
 
+static void c_can_hw_raminit_wait(const struct c_can_priv *priv, u32 mask)
+{
+	while (priv->read_reg32(priv, C_CAN_FUNCTION_REG) & mask)
+		udelay(1);
+}
+
+static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
+{
+	u32 ctrl;
+
+	ctrl = priv->read_reg32(priv, C_CAN_FUNCTION_REG);
+	ctrl &= ~DCAN_RAM_INIT_BIT;
+	priv->write_reg32(priv, C_CAN_FUNCTION_REG, ctrl);
+	c_can_hw_raminit_wait(priv, ctrl);
+
+	if (enable) {
+		ctrl |= DCAN_RAM_INIT_BIT;
+		priv->write_reg32(priv, C_CAN_FUNCTION_REG, ctrl);
+		c_can_hw_raminit_wait(priv, ctrl);
+	}
+}
+
 static struct platform_device_id c_can_id_table[] = {
 	[BOSCH_C_CAN_PLATFORM] = {
 		.name = KBUILD_MODNAME,
@@ -255,11 +278,20 @@ static int c_can_plat_probe(struct platform_device *pdev)
 			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
+		 * if not specified in DT.
+		 */
+		if (!res) {
+			priv->raminit = c_can_hw_raminit;
+			break;
+		}
+
 		priv->raminit_ctrlreg = devm_ioremap_resource(&pdev->dev, res);
 		if (IS_ERR(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;
+			priv->raminit = c_can_hw_raminit_ti;
 		break;
 	default:
 		ret = -EINVAL;
-- 
2.0.0.rc0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/3] hwinit support for non-TI devices
  2014-05-13 13:40 [PATCH v4 0/3] hwinit support for non-TI devices Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2014-05-13 13:40 ` [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices Marc Kleine-Budde
@ 2014-05-13 14:26 ` Marc Kleine-Budde
  3 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2014-05-13 14:26 UTC (permalink / raw)
  To: linux-can; +Cc: kernel

[-- Attachment #1: Type: text/plain, Size: 666 bytes --]

On 05/13/2014 03:40 PM, Marc Kleine-Budde wrote:
> Hello,
> 
> picking uo Pavel Machek's and Thor Thayer's patches.
> 
> changes since v3:
> - split make const into seperate patch (1/3)
> - squash make const of 32 bit accessor functions into existing 32-bit accesses (2/3)
> - the remaining changes are on 3/3

The "const" for the pci driver is missing, I'll post a v5.

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: 242 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices
  2014-05-13 13:40 ` [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices Marc Kleine-Budde
@ 2014-05-27 12:05   ` Pavel Machek
  2014-05-27 17:01     ` Thor Thayer
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2014-05-27 12:05 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can, kernel, Thor Thayer, gsi

Hi!


> Non-TI chips (including socfpga) needs different raminit sequence. Implement
> it.
> 
> Tested-by: Thor Thayer <tthayer@altera.com>
> Signed-off-by: Thor Thayer <tthayer@altera.com>
> Signed-off-by: Pavel Machek <pavel@denx.de>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

Thanks for the series. This should mean working can on socfpga...

Just for the record, these are the changes that were on rocketboards
originally and that are not merged. They do not seem to be required
according to my testing.

If anyone knows why to do them, it would be good idea to speak up now.

Best regards,
								Pavel

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index e154b4c..824ec21 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -48,6 +48,7 @@
 #define C_CAN_IFACE(reg, iface)	(C_CAN_IF1_##reg + (iface) * IF_ENUM_REG_LEN)
 
 /* control extension register D_CAN specific */
+#define CONTROL_MIL		BIT(17)
 #define CONTROL_EX_PDR		BIT(8)
 
 /* control register */
@@ -239,12 +240,20 @@ static inline void c_can_reset_ram(const struct c_can_priv *priv, bool enable)
 
 static void c_can_irq_control(struct c_can_priv *priv, bool enable)
 {
-	u32 ctrl = priv->read_reg(priv,	C_CAN_CTRL_REG) & ~CONTROL_IRQMSK;
+	u32 ctrl;
+
+	if (priv->type == BOSCH_D_CAN)
+		ctrl = priv->read_reg32(priv, C_CAN_CTRL_REG) & ~CONTROL_IRQMSK;
+	else
+		ctrl = priv->read_reg(priv, C_CAN_CTRL_REG) & ~CONTROL_IRQMSK;
 
 	if (enable)
 		ctrl |= CONTROL_IRQMSK;
 
-	priv->write_reg(priv, C_CAN_CTRL_REG, ctrl);
+	if (priv->type == BOSCH_D_CAN)
+		priv->write_reg32(priv, C_CAN_CTRL_REG, ctrl);
+	else
+		priv->write_reg(priv, C_CAN_CTRL_REG, ctrl);
 }
 
 static void c_can_obj_update(struct net_device *dev, int iface, u32 cmd, u32 obj)
@@ -505,16 +514,22 @@ static int c_can_set_bittiming(struct net_device *dev)
 	netdev_info(dev,
 		"setting BTR=%04x BRPE=%04x\n", reg_btr, reg_brpe);
 
-	ctrl_save = priv->read_reg(priv, C_CAN_CTRL_REG);
+	if (priv->type == BOSCH_D_CAN)
+		ctrl_save = priv->read_reg32(priv, C_CAN_CTRL_REG);
+	else
+		ctrl_save = priv->read_reg(priv, C_CAN_CTRL_REG);
 	ctrl_save &= ~CONTROL_INIT;
-	priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_CCE | CONTROL_INIT);
+	priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_CCE | CONTROL_INIT); /* FIXME: want to do write32? */
 	res = c_can_wait_for_ctrl_init(dev, priv, CONTROL_INIT);
 	if (res)
 		return res;
 
 	priv->write_reg(priv, C_CAN_BTR_REG, reg_btr);
 	priv->write_reg(priv, C_CAN_BRPEXT_REG, reg_brpe);
-	priv->write_reg(priv, C_CAN_CTRL_REG, ctrl_save);
+	if (priv->type == BOSCH_D_CAN)
+		priv->write_reg32(priv, C_CAN_CTRL_REG, ctrl_save);
+	else
+		priv->write_reg(priv, C_CAN_CTRL_REG, ctrl_save);
 
 	return c_can_wait_for_ctrl_init(dev, priv, 0);
 }
@@ -1235,7 +1250,7 @@ int c_can_power_up(struct net_device *dev)
 
 	/* Clear PDR and INIT bits */
 	val = priv->read_reg(priv, C_CAN_CTRL_EX_REG);
-	val &= ~CONTROL_EX_PDR;
+	val &= ~(CONTROL_EX_PDR | CONTROL_MIL);
 	priv->write_reg(priv, C_CAN_CTRL_EX_REG, val);
 	val = priv->read_reg(priv, C_CAN_CTRL_REG);
 	val &= ~CONTROL_INIT;


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices
  2014-05-27 12:05   ` Pavel Machek
@ 2014-05-27 17:01     ` Thor Thayer
  0 siblings, 0 replies; 7+ messages in thread
From: Thor Thayer @ 2014-05-27 17:01 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Marc Kleine-Budde, linux-can, kernel, Thor Thayer, gsi

On Tue, May 27, 2014 at 7:05 AM, Pavel Machek <pavel@denx.de> wrote:
> Hi!
>
>
>> Non-TI chips (including socfpga) needs different raminit sequence. Implement
>> it.
>>
>> Tested-by: Thor Thayer <tthayer@altera.com>
>> Signed-off-by: Thor Thayer <tthayer@altera.com>
>> Signed-off-by: Pavel Machek <pavel@denx.de>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>
> Thanks for the series. This should mean working can on socfpga...
>
> Just for the record, these are the changes that were on rocketboards
> originally and that are not merged. They do not seem to be required
> according to my testing.
>
> If anyone knows why to do them, it would be good idea to speak up now.
>
> Best regards,
>                                                                 Pavel

Hi Pavel!

For the rocketboards changes, I grabbed the series of changes from
Benedict Spranger submitted ([PATCH 05/16] c_can: use 32 bit access
for D_CAN) on 9/9/2013 after searching for D_CAN patches. This patch
solved my packet problems but that could have been due to the issues
that Thomas Gleixner found.

As far as the CONTROL_MIL bit, this doesn't appear to be necessary and
should not be added.

I tested the checked-in changes on the Altera Development Kit to a
Microchip CAN analyzer. Everything looks fine. It appears these
additional changes aren't needed.

Regards,
                                              Thor

>
> diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
> index e154b4c..824ec21 100644
> --- a/drivers/net/can/c_can/c_can.c
> +++ b/drivers/net/can/c_can/c_can.c
> @@ -48,6 +48,7 @@
>  #define C_CAN_IFACE(reg, iface)        (C_CAN_IF1_##reg + (iface) * IF_ENUM_REG_LEN)
>
>  /* control extension register D_CAN specific */
> +#define CONTROL_MIL            BIT(17)
>  #define CONTROL_EX_PDR         BIT(8)
>
>  /* control register */
> @@ -239,12 +240,20 @@ static inline void c_can_reset_ram(const struct c_can_priv *priv, bool enable)
>
>  static void c_can_irq_control(struct c_can_priv *priv, bool enable)
>  {
> -       u32 ctrl = priv->read_reg(priv, C_CAN_CTRL_REG) & ~CONTROL_IRQMSK;
> +       u32 ctrl;
> +
> +       if (priv->type == BOSCH_D_CAN)
> +               ctrl = priv->read_reg32(priv, C_CAN_CTRL_REG) & ~CONTROL_IRQMSK;
> +       else
> +               ctrl = priv->read_reg(priv, C_CAN_CTRL_REG) & ~CONTROL_IRQMSK;
>
>         if (enable)
>                 ctrl |= CONTROL_IRQMSK;
>
> -       priv->write_reg(priv, C_CAN_CTRL_REG, ctrl);
> +       if (priv->type == BOSCH_D_CAN)
> +               priv->write_reg32(priv, C_CAN_CTRL_REG, ctrl);
> +       else
> +               priv->write_reg(priv, C_CAN_CTRL_REG, ctrl);
>  }
>
>  static void c_can_obj_update(struct net_device *dev, int iface, u32 cmd, u32 obj)
> @@ -505,16 +514,22 @@ static int c_can_set_bittiming(struct net_device *dev)
>         netdev_info(dev,
>                 "setting BTR=%04x BRPE=%04x\n", reg_btr, reg_brpe);
>
> -       ctrl_save = priv->read_reg(priv, C_CAN_CTRL_REG);
> +       if (priv->type == BOSCH_D_CAN)
> +               ctrl_save = priv->read_reg32(priv, C_CAN_CTRL_REG);
> +       else
> +               ctrl_save = priv->read_reg(priv, C_CAN_CTRL_REG);
>         ctrl_save &= ~CONTROL_INIT;
> -       priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_CCE | CONTROL_INIT);
> +       priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_CCE | CONTROL_INIT); /* FIXME: want to do write32? */
>         res = c_can_wait_for_ctrl_init(dev, priv, CONTROL_INIT);
>         if (res)
>                 return res;
>
>         priv->write_reg(priv, C_CAN_BTR_REG, reg_btr);
>         priv->write_reg(priv, C_CAN_BRPEXT_REG, reg_brpe);
> -       priv->write_reg(priv, C_CAN_CTRL_REG, ctrl_save);
> +       if (priv->type == BOSCH_D_CAN)
> +               priv->write_reg32(priv, C_CAN_CTRL_REG, ctrl_save);
> +       else
> +               priv->write_reg(priv, C_CAN_CTRL_REG, ctrl_save);
>
>         return c_can_wait_for_ctrl_init(dev, priv, 0);
>  }
> @@ -1235,7 +1250,7 @@ int c_can_power_up(struct net_device *dev)
>
>         /* Clear PDR and INIT bits */
>         val = priv->read_reg(priv, C_CAN_CTRL_EX_REG);
> -       val &= ~CONTROL_EX_PDR;
> +       val &= ~(CONTROL_EX_PDR | CONTROL_MIL);
>         priv->write_reg(priv, C_CAN_CTRL_EX_REG, val);
>         val = priv->read_reg(priv, C_CAN_CTRL_REG);
>         val &= ~CONTROL_INIT;
>
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-05-27 17:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-13 13:40 [PATCH v4 0/3] hwinit support for non-TI devices Marc Kleine-Budde
2014-05-13 13:40 ` [PATCH v4 1/3] can: c_can: make {read,write}_reg functions const Marc Kleine-Budde
2014-05-13 13:40 ` [PATCH v4 2/3] can: c_can: Add and make use of 32-bit accesses functions Marc Kleine-Budde
2014-05-13 13:40 ` [PATCH v4 3/3] can: c_can: add hwinit support for non-TI devices Marc Kleine-Budde
2014-05-27 12:05   ` Pavel Machek
2014-05-27 17:01     ` Thor Thayer
2014-05-13 14:26 ` [PATCH v4 0/3] " Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.