Skip to contentSkip to conversation

can: c_can: Add support for Bosch D_CAN controller

PATCH Superseded AnilKumar Ch 3 participants 7 messages Apr 20, 2012 – Apr 24, 2012 CAN network drivers

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 can: c_can: Add support for Bosch D_CAN controller

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

Current D_CAN implementation has following limitations, this is done to avoid large changes to the C_CAN driver.
1. Message objects are limited to 32, 16 for RX and 16 for TX. C_CAN IP supports upto 32 message objects but in case of D_CAN we can configure upto 128 message objects.
2. Using two 16bit reads/writes for accessing the 32bit D_CAN registers.
3. These patches have been tested on little endian machine, there might be some hidden endian-related issues due to the nature of the accesses (32-bit registers accessed as 2 16-bit registers). However, I do not have a big-endian D_CAN implementation to confirm.

---
 drivers/net/can/c_can/c_can.c          |  139 ++++++++++++++++----------------
 drivers/net/can/c_can/c_can.h          |   93 +++++++++++++++++++++-
 drivers/net/can/c_can/c_can_platform.c |   47 +++++++++--
 include/linux/can/platform/c_can.h     |   42 ++++++++++
 4 files changed, 245 insertions(+), 76 deletions(-)
 create mode 100644 include/linux/can/platform/c_can.h
drivers/net/can/c_can/c_can.c +71 -68
index 09fcc50..4abb09d 100644
@@ -38,6 +38,7 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/error.h>
+#include <linux/can/platform/c_can.h>
 
 #include "c_can.h"
 
@@ -219,24 +220,24 @@ static u32 c_can_read_reg32(struct c_can_priv *priv, void *reg)
 static void c_can_enable_all_interrupts(struct c_can_priv *priv,
 						int enable)
 {
-	unsigned int cntrl_save = priv->read_reg(priv,
-						&priv->regs->control);
+	unsigned int cntrl_save;
 
+	C_CAN_READ(cntrl_save, priv, regs->control);
 	if (enable)
 		cntrl_save |= (CONTROL_SIE | CONTROL_EIE | CONTROL_IE);
 	else
 		cntrl_save &= ~(CONTROL_EIE | CONTROL_IE | CONTROL_SIE);
 
-	priv->write_reg(priv, &priv->regs->control, cntrl_save);
+	C_CAN_WRITE(priv, regs->control, cntrl_save);
 }
 
 static inline int c_can_msg_obj_is_busy(struct c_can_priv *priv, int iface)
 {
 	int count = MIN_TIMEOUT_VALUE;
+	u32 com_req;
 
-	while (count && priv->read_reg(priv,
-				&priv->regs->ifregs[iface].com_req) &
-				IF_COMR_BUSY) {
+	C_CAN_READ(com_req, priv, regs->ifregs[iface].com_req);
+	while (count && com_req & IF_COMR_BUSY) {
 		count--;
 		udelay(1);
 	}
@@ -258,9 +259,9 @@ static inline void c_can_object_get(struct net_device *dev,
 	 * register and message RAM must be complete in 6 CAN-CLK
 	 * period.
 	 */
-	priv->write_reg(priv, &priv->regs->ifregs[iface].com_mask,
+	C_CAN_WRITE(priv, regs->ifregs[iface].com_mask,
 			IFX_WRITE_LOW_16BIT(mask));
-	priv->write_reg(priv, &priv->regs->ifregs[iface].com_req,
+	C_CAN_WRITE(priv, regs->ifregs[iface].com_req,
 			IFX_WRITE_LOW_16BIT(objno));
 
 	if (c_can_msg_obj_is_busy(priv, iface))
@@ -278,9 +279,9 @@ static inline void c_can_object_put(struct net_device *dev,
 	 * register and message RAM must be complete in 6 CAN-CLK
 	 * period.
 	 */
-	priv->write_reg(priv, &priv->regs->ifregs[iface].com_mask,
+	C_CAN_WRITE(priv, regs->ifregs[iface].com_mask,
 			(IF_COMM_WR | IFX_WRITE_LOW_16BIT(mask)));
-	priv->write_reg(priv, &priv->regs->ifregs[iface].com_req,
+	C_CAN_WRITE(priv, regs->ifregs[iface].com_req,
 			IFX_WRITE_LOW_16BIT(objno));
 
 	if (c_can_msg_obj_is_busy(priv, iface))
@@ -306,18 +307,18 @@ static void c_can_write_msg_object(struct net_device *dev,
 
 	flags |= IF_ARB_MSGVAL;
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].arb1,
+	C_CAN_WRITE(priv, regs->ifregs[iface].arb1,
 				IFX_WRITE_LOW_16BIT(id));
-	priv->write_reg(priv, &priv->regs->ifregs[iface].arb2, flags |
+	C_CAN_WRITE(priv, regs->ifregs[iface].arb2, flags |
 				IFX_WRITE_HIGH_16BIT(id));
 
 	for (i = 0; i < frame->can_dlc; i += 2) {
-		priv->write_reg(priv, &priv->regs->ifregs[iface].data[i / 2],
+		C_CAN_WRITE(priv, regs->ifregs[iface].data[i / 2],
 				frame->data[i] | (frame->data[i + 1] << 8));
 	}
 
 	/* enable interrupt for this message object */
-	priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl,
+	C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl,
 			IF_MCONT_TXIE | IF_MCONT_TXRQST | IF_MCONT_EOB |
 			frame->can_dlc);
 	c_can_object_put(dev, iface, objno, IF_COMM_ALL);
@@ -329,7 +330,7 @@ static inline void c_can_mark_rx_msg_obj(struct net_device *dev,
 {
 	struct c_can_priv *priv = netdev_priv(dev);
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl,
+	C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl,
 			ctrl_mask & ~(IF_MCONT_MSGLST | IF_MCONT_INTPND));
 	c_can_object_put(dev, iface, obj, IF_COMM_CONTROL);
 
@@ -343,7 +344,7 @@ static inline void c_can_activate_all_lower_rx_msg_obj(struct net_device *dev,
 	struct c_can_priv *priv = netdev_priv(dev);
 
 	for (i = C_CAN_MSG_OBJ_RX_FIRST; i <= C_CAN_MSG_RX_LOW_LAST; i++) {
-		priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl,
+		C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl,
 				ctrl_mask & ~(IF_MCONT_MSGLST |
 					IF_MCONT_INTPND | IF_MCONT_NEWDAT));
 		c_can_object_put(dev, iface, i, IF_COMM_CONTROL);
@@ -356,7 +357,7 @@ static inline void c_can_activate_rx_msg_obj(struct net_device *dev,
 {
 	struct c_can_priv *priv = netdev_priv(dev);
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl,
+	C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl,
 			ctrl_mask & ~(IF_MCONT_MSGLST |
 				IF_MCONT_INTPND | IF_MCONT_NEWDAT));
 	c_can_object_put(dev, iface, obj, IF_COMM_CONTROL);
@@ -374,7 +375,7 @@ static void c_can_handle_lost_msg_obj(struct net_device *dev,
 
 	c_can_object_get(dev, iface, objno, IF_COMM_ALL & ~IF_COMM_TXRQST);
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl,
+	C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl,
 			IF_MCONT_CLR_MSGLST);
 
 	c_can_object_put(dev, 0, objno, IF_COMM_CONTROL);
@@ -410,9 +411,9 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, int ctrl)
 
 	frame->can_dlc = get_can_dlc(ctrl & 0x0F);
 
-	flags =	priv->read_reg(priv, &priv->regs->ifregs[iface].arb2);
-	val = priv->read_reg(priv, &priv->regs->ifregs[iface].arb1) |
-		(flags << 16);
+	C_CAN_READ(flags, priv, regs->ifregs[iface].arb2);
+	C_CAN_READ(val, priv, regs->ifregs[iface].arb1);
+	val |= (flags << 16);
 
 	if (flags & IF_ARB_MSGXTD)
 		frame->can_id = (val & CAN_EFF_MASK) | CAN_EFF_FLAG;
@@ -423,8 +424,8 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, int ctrl)
 		frame->can_id |= CAN_RTR_FLAG;
 	else {
 		for (i = 0; i < frame->can_dlc; i += 2) {
-			data = priv->read_reg(priv,
-				&priv->regs->ifregs[iface].data[i / 2]);
+			C_CAN_READ(data, priv,
+				regs->ifregs[iface].data[i / 2]);
 			frame->data[i] = data;
 			frame->data[i + 1] = data >> 8;
 		}
@@ -443,41 +444,45 @@ static void c_can_setup_receive_object(struct net_device *dev, int iface,
 					unsigned int id, unsigned int mcont)
 {
 	struct c_can_priv *priv = netdev_priv(dev);
+	u32 msgval1;
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].mask1,
+	C_CAN_WRITE(priv, regs->ifregs[iface].mask1,
 			IFX_WRITE_LOW_16BIT(mask));
-	priv->write_reg(priv, &priv->regs->ifregs[iface].mask2,
+	C_CAN_WRITE(priv, regs->ifregs[iface].mask2,
 			IFX_WRITE_HIGH_16BIT(mask));
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].arb1,
+	C_CAN_WRITE(priv, regs->ifregs[iface].arb1,
 			IFX_WRITE_LOW_16BIT(id));
-	priv->write_reg(priv, &priv->regs->ifregs[iface].arb2,
+	C_CAN_WRITE(priv, regs->ifregs[iface].arb2,
 			(IF_ARB_MSGVAL | IFX_WRITE_HIGH_16BIT(id)));
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl, mcont);
+	C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl, mcont);
 	c_can_object_put(dev, iface, objno, IF_COMM_ALL & ~IF_COMM_TXRQST);
 
-	netdev_dbg(dev, "obj no:%d, msgval:0x%08x\n", objno,
-			c_can_read_reg32(priv, &priv->regs->msgval1));
+	C_CAN_READ_REG32(msgval1, priv, regs->msgval1);
+	netdev_dbg(dev, "obj no:%d, msgval:0x%08x\n", objno, msgval1);
 }
 
 static void c_can_inval_msg_object(struct net_device *dev, int iface, int objno)
 {
 	struct c_can_priv *priv = netdev_priv(dev);
+	u32 msgval1;
 
-	priv->write_reg(priv, &priv->regs->ifregs[iface].arb1, 0);
-	priv->write_reg(priv, &priv->regs->ifregs[iface].arb2, 0);
-	priv->write_reg(priv, &priv->regs->ifregs[iface].msg_cntrl, 0);
+	C_CAN_WRITE(priv, regs->ifregs[iface].arb1, 0);
+	C_CAN_WRITE(priv, regs->ifregs[iface].arb2, 0);
+	C_CAN_WRITE(priv, regs->ifregs[iface].msg_cntrl, 0);
 
 	c_can_object_put(dev, iface, objno, IF_COMM_ARB | IF_COMM_CONTROL);
+	C_CAN_READ_REG32(msgval1, priv, regs->msgval1);
 
-	netdev_dbg(dev, "obj no:%d, msgval:0x%08x\n", objno,
-			c_can_read_reg32(priv, &priv->regs->msgval1));
+	netdev_dbg(dev, "obj no:%d, msgval:0x%08x\n", objno, msgval1);
 }
 
 static inline int c_can_is_next_tx_obj_busy(struct c_can_priv *priv, int objno)
 {
-	int val = c_can_read_reg32(priv, &priv->regs->txrqst1);
+	int val;
+
+	C_CAN_READ_REG32(val, priv, regs->txrqst1);
 
 	/*
 	 * as transmission request register's bit n-1 corresponds to
@@ -540,12 +545,12 @@ 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, &priv->regs->control);
-	priv->write_reg(priv, &priv->regs->control,
+	C_CAN_READ(ctrl_save, priv, regs->control);
+	C_CAN_WRITE(priv, regs->control,
 			ctrl_save | CONTROL_CCE | CONTROL_INIT);
-	priv->write_reg(priv, &priv->regs->btr, reg_btr);
-	priv->write_reg(priv, &priv->regs->brp_ext, reg_brpe);
-	priv->write_reg(priv, &priv->regs->control, ctrl_save);
+	C_CAN_WRITE(priv, regs->btr, reg_btr);
+	C_CAN_WRITE(priv, regs->brp_ext, reg_brpe);
+	C_CAN_WRITE(priv, regs->control, ctrl_save);
 
 	return 0;
 }
@@ -587,36 +592,35 @@ static void c_can_chip_config(struct net_device *dev)
 	struct c_can_priv *priv = netdev_priv(dev);
 
 	/* enable automatic retransmission */
-	priv->write_reg(priv, &priv->regs->control,
-			CONTROL_ENABLE_AR);
+	C_CAN_WRITE(priv, regs->control, CONTROL_ENABLE_AR);
 
 	if (priv->can.ctrlmode & (CAN_CTRLMODE_LISTENONLY &
 					CAN_CTRLMODE_LOOPBACK)) {
 		/* loopback + silent mode : useful for hot self-test */
-		priv->write_reg(priv, &priv->regs->control, CONTROL_EIE |
+		C_CAN_WRITE(priv, regs->control, CONTROL_EIE |
 				CONTROL_SIE | CONTROL_IE | CONTROL_TEST);
-		priv->write_reg(priv, &priv->regs->test,
+		C_CAN_WRITE(priv, regs->test,
 				TEST_LBACK | TEST_SILENT);
 	} else if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) {
 		/* loopback mode : useful for self-test function */
-		priv->write_reg(priv, &priv->regs->control, CONTROL_EIE |
+		C_CAN_WRITE(priv, regs->control, CONTROL_EIE |
 				CONTROL_SIE | CONTROL_IE | CONTROL_TEST);
-		priv->write_reg(priv, &priv->regs->test, TEST_LBACK);
+		C_CAN_WRITE(priv, regs->test, TEST_LBACK);
 	} else if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
 		/* silent mode : bus-monitoring mode */
-		priv->write_reg(priv, &priv->regs->control, CONTROL_EIE |
+		C_CAN_WRITE(priv, regs->control, CONTROL_EIE |
 				CONTROL_SIE | CONTROL_IE | CONTROL_TEST);
-		priv->write_reg(priv, &priv->regs->test, TEST_SILENT);
+		C_CAN_WRITE(priv, regs->test, TEST_SILENT);
 	} else
 		/* normal mode*/
-		priv->write_reg(priv, &priv->regs->control,
+		C_CAN_WRITE(priv, regs->control,
 				CONTROL_EIE | CONTROL_SIE | CONTROL_IE);
 
 	/* configure message objects */
 	c_can_configure_msg_objects(dev);
 
 	/* set a `lec` value so that we can check for updates later */
-	priv->write_reg(priv, &priv->regs->status, LEC_UNUSED);
+	C_CAN_WRITE(priv, regs->status, LEC_UNUSED);
 
 	/* set bittiming params */
 	c_can_set_bittiming(dev);
@@ -669,7 +673,7 @@ static int c_can_get_berr_counter(const struct net_device *dev,
 	unsigned int reg_err_counter;
 	struct c_can_priv *priv = netdev_priv(dev);
 
-	reg_err_counter = priv->read_reg(priv, &priv->regs->err_cnt);
+	C_CAN_READ(reg_err_counter, priv, regs->err_cnt);
 	bec->rxerr = (reg_err_counter & ERR_CNT_REC_MASK) >>
 				ERR_CNT_REC_SHIFT;
 	bec->txerr = reg_err_counter & ERR_CNT_TEC_MASK;
@@ -690,20 +694,19 @@ static int c_can_get_berr_counter(const struct net_device *dev,
  */
 static void c_can_do_tx(struct net_device *dev)
 {
-	u32 val;
+	u32 val, msg_cntrl;
 	u32 msg_obj_no;
 	struct c_can_priv *priv = netdev_priv(dev);
 	struct net_device_stats *stats = &dev->stats;
 
 	for (/* nix */; (priv->tx_next - priv->tx_echo) > 0; priv->tx_echo++) {
 		msg_obj_no = get_tx_echo_msg_obj(priv);
-		val = c_can_read_reg32(priv, &priv->regs->txrqst1);
+		C_CAN_READ_REG32(val, priv, regs->txrqst1);
 		if (!(val & (1 << (msg_obj_no - 1)))) {
 			can_get_echo_skb(dev,
 					msg_obj_no - C_CAN_MSG_OBJ_TX_FIRST);
-			stats->tx_bytes += priv->read_reg(priv,
-					&priv->regs->ifregs[0].msg_cntrl)
-					& IF_MCONT_DLC_MASK;
+			C_CAN_READ(msg_cntrl, priv, regs->ifregs[0].msg_cntrl);
+			stats->tx_bytes += msg_cntrl & IF_MCONT_DLC_MASK;
 			stats->tx_packets++;
 			c_can_inval_msg_object(dev, 0, msg_obj_no);
 		} else {
@@ -744,11 +747,11 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
 	u32 num_rx_pkts = 0;
 	unsigned int msg_obj, msg_ctrl_save;
 	struct c_can_priv *priv = netdev_priv(dev);
-	u32 val = c_can_read_reg32(priv, &priv->regs->intpnd1);
+	u32 val;
 
+	C_CAN_READ_REG32(val, priv, regs->intpnd1);
 	for (msg_obj = C_CAN_MSG_OBJ_RX_FIRST;
 			msg_obj <= C_CAN_MSG_OBJ_RX_LAST && quota > 0;
-			val = c_can_read_reg32(priv, &priv->regs->intpnd1),
 			msg_obj++) {
 		/*
 		 * as interrupt pending register's bit n-1 corresponds to
@@ -757,8 +760,8 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
 		if (val & (1 << (msg_obj - 1))) {
 			c_can_object_get(dev, 0, msg_obj, IF_COMM_ALL &
 					~IF_COMM_TXRQST);
-			msg_ctrl_save = priv->read_reg(priv,
-					&priv->regs->ifregs[0].msg_cntrl);
+			C_CAN_READ(msg_ctrl_save, priv,
+					regs->ifregs[0].msg_cntrl);
 
 			if (msg_ctrl_save & IF_MCONT_EOB)
 				return num_rx_pkts;
@@ -791,6 +794,7 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
 			num_rx_pkts++;
 			quota--;
 		}
+		C_CAN_READ_REG32(val, priv, regs->intpnd1);
 	}
 
 	return num_rx_pkts;
@@ -819,7 +823,7 @@ static int c_can_handle_state_change(struct net_device *dev,
 		return 0;
 
 	c_can_get_berr_counter(dev, &bec);
-	reg_err_counter = priv->read_reg(priv, &priv->regs->err_cnt);
+	C_CAN_READ(reg_err_counter, priv, regs->err_cnt);
 	rx_err_passive = (reg_err_counter & ERR_CNT_RP_MASK) >>
 				ERR_CNT_RP_SHIFT;
 
@@ -935,7 +939,7 @@ static int c_can_handle_bus_err(struct net_device *dev,
 	}
 
 	/* set a `lec` value so that we can check for updates later */
-	priv->write_reg(priv, &priv->regs->status, LEC_UNUSED);
+	C_CAN_WRITE(priv, regs->status, LEC_UNUSED);
 
 	netif_receive_skb(skb);
 	stats->rx_packets++;
@@ -956,16 +960,15 @@ static int c_can_poll(struct napi_struct *napi, int quota)
 
 	/* status events have the highest priority */
 	if (priv->irqstatus == STATUS_INTERRUPT) {
-		priv->current_status = priv->read_reg(priv,
-					&priv->regs->status);
+		C_CAN_READ(priv->current_status, priv, regs->status);
 
 		/* handle Tx/Rx events */
 		if (priv->current_status & STATUS_TXOK)
-			priv->write_reg(priv, &priv->regs->status,
+			C_CAN_WRITE(priv, regs->status,
 					priv->current_status & ~STATUS_TXOK);
 
 		if (priv->current_status & STATUS_RXOK)
-			priv->write_reg(priv, &priv->regs->status,
+			C_CAN_WRITE(priv, regs->status,
 					priv->current_status & ~STATUS_RXOK);
 
 		/* handle state changes */
@@ -1031,7 +1034,7 @@ static irqreturn_t c_can_isr(int irq, void *dev_id)
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct c_can_priv *priv = netdev_priv(dev);
 
-	priv->irqstatus = priv->read_reg(priv, &priv->regs->interrupt);
+	C_CAN_READ(priv->irqstatus, priv, regs->interrupt);
 	if (!priv->irqstatus)
 		return IRQ_NONE;
 
drivers/net/can/c_can/c_can.h +92 -1

110 lines not on this page · raw message

drivers/net/can/c_can/c_can_platform.c +40 -7

96 lines not on this page · raw message

include/linux/can/platform/c_can.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 16 lines · AnilKumar Ch

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

Quoted 3 lines

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

I don't like macros. I've two further possible solutions:

a) Access the registers via an array. The array index is a "virtual" register, the array's value the physical offset within the c_can or d_can controller.
b) AFAICS you need more than three registers to get the CAN core working. Another possibility is to implement an accessor function for each register.

Other, hopefully better, solutions are open for discussion.

Marc

Signature · 4 lines
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   |
#2 lore raw
Quoted 17 lines · Marc Kleine-Budde
Quoted 16 lines · AnilKumar Ch

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

Quoted 5 lines
Quoted 3 lines

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

I don't like macros. I've two further possible solutions:

Yes, I don't like that part either, also because of the

"if (priv->dev_type == DEV_TYPE_D_CAN)"

for each read/write access.

Quoted 3 lines

a) Access the registers via an array. The array index is a "virtual" register, the array's value the physical offset within the c_can or d_can controller.

I was thinking about that as well but using absolute addresses. This would avoid further calculations for 16/32 bit aligned accesses.

Quoted 3 lines

b) AFAICS you need more than three registers to get the CAN core working. Another possibility is to implement an accessor function for each register.

... offsetof() might be useful for this approach.

Quoted 1 line

Other, hopefully better, solutions are open for discussion.

The solutions above are not really elegant, but so far I do not have better ideas.

Wolfgang.

#3 lore raw
Quoted 28 lines · Wolfgang Grandegger
Quoted 17 lines · Marc Kleine-Budde
Quoted 16 lines · AnilKumar Ch

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

Quoted 5 lines
Quoted 3 lines

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

I don't like macros. I've two further possible solutions:

Yes, I don't like that part either, also because of the

"if (priv->dev_type == DEV_TYPE_D_CAN)"

Quoted 8 lines

for each read/write access.

Quoted 3 lines

a) Access the registers via an array. The array index is a "virtual" register, the array's value the physical offset within the c_can or d_can controller.

I was thinking about that as well but using absolute addresses. This would avoid further calculations for 16/32 bit aligned accesses.

Yes, this way we might get rid of this calculation, too.

Quoted 5 lines
Quoted 3 lines

b) AFAICS you need more than three registers to get the CAN core working. Another possibility is to implement an accessor function for each register.

... offsetof() might be useful for this approach.

Please elaborate.

Quoted 4 lines
Quoted 1 line

Other, hopefully better, solutions are open for discussion.

The solutions above are not really elegant, but so far I do not have better ideas.

Marc

Signature · 4 lines
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   |
#4 lore raw
Quoted 40 lines · Marc Kleine-Budde
Quoted 28 lines · Wolfgang Grandegger
Quoted 17 lines · Marc Kleine-Budde
Quoted 16 lines · AnilKumar Ch

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

Quoted 5 lines
Quoted 3 lines

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

I don't like macros. I've two further possible solutions:

Yes, I don't like that part either, also because of the

"if (priv->dev_type == DEV_TYPE_D_CAN)"

Quoted 8 lines

for each read/write access.

Quoted 3 lines

a) Access the registers via an array. The array index is a "virtual" register, the array's value the physical offset within the c_can or d_can controller.

I was thinking about that as well but using absolute addresses. This would avoid further calculations for 16/32 bit aligned accesses.

Yes, this way we might get rid of this calculation, too.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

b) AFAICS you need more than three registers to get the CAN core working. Another possibility is to implement an accessor function for each register.

... offsetof() might be useful for this approach.

Please elaborate.

#define c_can_write_reg_func(member) \
	static inline void write_##reg(struct c_can_priv *priv, u32 val) \
	{ \
		priv->write_reg(priv, offsetof(struct c_can_regs, member), val); \
	}

And similar for read and d_can. Then in the init part:

	if (priv->dev_type == DEV_TYPE_C_CAN) {
		c_can_write_reg_func(control);
		c_can_write_reg_func(status);
		...
	} else {
		d_can_write_reg_func(control);
		d_can_write_reg_func(status);
		...
	}

Maybe we could even get rid of priv->write_reg (for memory mapped i/o only!).

Wolfgang.

#5 lore raw
Quoted 36 lines · Wolfgang Grandegger
Quoted 35 lines · Marc Kleine-Budde
Quoted 34 lines · Wolfgang Grandegger
Quoted 17 lines · Marc Kleine-Budde
Quoted 16 lines · AnilKumar Ch

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

Quoted 5 lines
Quoted 3 lines

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

I don't like macros. I've two further possible solutions:

Yes, I don't like that part either, also because of the

"if (priv->dev_type == DEV_TYPE_D_CAN)"

for each read/write access.

Quoted 3 lines

a) Access the registers via an array. The array index is a "virtual" register, the array's value the physical offset within the c_can or d_can controller.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I was thinking about that as well but using absolute addresses. This would avoid further calculations for 16/32 bit aligned accesses.

Yes, this way we might get rid of this calculation, too.

Okay. I can spin a patch with this approach. The reason I took the current approach is because I did not want to shift the existing code from an overlay structure to an array based approach.

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

b) AFAICS you need more than three registers to get the CAN core working. Another possibility is to implement an accessor function for each register.

... offsetof() might be useful for this approach.

Please elaborate.

#define c_can_write_reg_func(member) \
	static inline void write_##reg(struct c_can_priv *priv, u32 val) \

You mean "write_##member" here?

Quoted 16 lines
	{ \
		priv->write_reg(priv, offsetof(struct c_can_regs, member), val); \
	}

And similar for read and d_can. Then in the init part:

	if (priv->dev_type == DEV_TYPE_C_CAN) {
		c_can_write_reg_func(control);
		c_can_write_reg_func(status);
		...
	} else {
		d_can_write_reg_func(control);
		d_can_write_reg_func(status);
		...
	}
Quoted 1 line

Maybe we could even get rid of priv->write_reg (for memory mapped i/o only!).

As per my understanding the scope of these inline function definitions is within the if-else construct. Once defined within the if-else, I cannot see how these functions will be used elsewhere in the code (must be missing something?).

Regards,
AnilKumar

#6 lore raw
Quoted 51 lines · Chimata
Quoted 36 lines · Wolfgang Grandegger
Quoted 35 lines · Marc Kleine-Budde
Quoted 34 lines · Wolfgang Grandegger
Quoted 17 lines · Marc Kleine-Budde
Quoted 16 lines · AnilKumar Ch

This patch adds the support for D_CAN controller driver to the existing C_CAN driver.

Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/
ipmodules_1/can/d_can_users_manual_111.pdf

The following are the design choices made while adding D_CAN to C_CAN driver:
A new overlay structure is added for d_can controller and care is taken to make sure its member names match with equavalent c_can structure members (even if the d_can specification calls them slightly differently). Note that d_can controller has more registers, so structure members of d_can are more than those in c_can.

Quoted 5 lines
Quoted 3 lines

A new set if read/write macros are used to access the registers common between c_can and d_can. To get the basic d_can functionality working it is sufficient to access just these registers.

I don't like macros. I've two further possible solutions:

Yes, I don't like that part either, also because of the

"if (priv->dev_type == DEV_TYPE_D_CAN)"

for each read/write access.

Quoted 3 lines

a) Access the registers via an array. The array index is a "virtual" register, the array's value the physical offset within the c_can or d_can controller.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

I was thinking about that as well but using absolute addresses. This would avoid further calculations for 16/32 bit aligned accesses.

Yes, this way we might get rid of this calculation, too.

Okay. I can spin a patch with this approach. The reason I took the current approach is because I did not want to shift the existing code from an overlay structure to an array based approach.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

b) AFAICS you need more than three registers to get the CAN core working. Another possibility is to implement an accessor function for each register.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

... offsetof() might be useful for this approach.

Please elaborate.

#define c_can_write_reg_func(member) \
	static inline void write_##reg(struct c_can_priv *priv, u32 val) \

You mean "write_##member" here?

Yep, s/member/reg/.

Quoted 16 lines
Quoted 16 lines
	{ \
		priv->write_reg(priv, offsetof(struct c_can_regs, member), val); \
	}

And similar for read and d_can. Then in the init part:

	if (priv->dev_type == DEV_TYPE_C_CAN) {
		c_can_write_reg_func(control);
		c_can_write_reg_func(status);
		...
	} else {
		d_can_write_reg_func(control);
		d_can_write_reg_func(status);
		...
	}
Quoted 5 lines
Quoted 1 line

Maybe we could even get rid of priv->write_reg (for memory mapped i/o only!).

As per my understanding the scope of these inline function definitions is within the if-else construct. Once defined within the if-else, I cannot see how these functions will be used elsewhere in the code (must be missing something?).

Well, declaring the functions at run-time is nonsense. We would need a table/array or something similar to your macros anyway ==> forget it.

Wolfgang.