diff mbox

[3/3] can: m_can: add loopback and monitor mode support

Message ID 1403863246-18822-4-git-send-email-b29396@freescale.com
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Dong Aisheng June 27, 2014, 10 a.m. UTC
add loopback and monitor mode support.

Signed-off-by: Dong Aisheng <b29396@freescale.com>
---
 drivers/net/can/m_can.c |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

Comments

Marc Kleine-Budde July 1, 2014, 10:38 a.m. UTC | #1
On 06/27/2014 12:00 PM, Dong Aisheng wrote:
> add loopback and monitor mode support.
> 
> Signed-off-by: Dong Aisheng <b29396@freescale.com>

Looks good. When finished with the review, I thinks it better to squash
all patches into a single patch.

Marc
Dong Aisheng July 2, 2014, 6:32 a.m. UTC | #2
On Tue, Jul 01, 2014 at 12:38:48PM +0200, Marc Kleine-Budde wrote:
> On 06/27/2014 12:00 PM, Dong Aisheng wrote:
> > add loopback and monitor mode support.
> > 
> > Signed-off-by: Dong Aisheng <b29396@freescale.com>
> 
> Looks good. When finished with the review, I thinks it better to squash
> all patches into a single patch.
> 

I'm ok with it.
Thanks for the review.

Regards
Dong Aisheng

> 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   |
> 


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

Patch

diff --git a/drivers/net/can/m_can.c b/drivers/net/can/m_can.c
index e4aed71..bbe8a7d 100644
--- a/drivers/net/can/m_can.c
+++ b/drivers/net/can/m_can.c
@@ -94,8 +94,12 @@  enum m_can_lec_type {
 	LEC_CRC_ERROR,
 	LEC_UNUSED,
 };
+/* Test Register (TEST) */
+#define TEST_LBCK	BIT(4)
 
 /* CC Control Register(CCCR) */
+#define CCCR_TEST	BIT(7)
+#define CCCR_MON	BIT(5)
 #define CCCR_CCE	BIT(1)
 #define CCCR_INIT	BIT(0)
 
@@ -661,13 +665,13 @@  static int m_can_set_bittiming(struct net_device *dev)
  * - configure rx fifo
  * - accept non-matching frame into fifo 0
  * - configure tx buffer
+ * - configure mode
  * - setup bittiming
- * - TODO:
- *   1) other working modes support like monitor, loopback...
  */
 static void m_can_chip_config(struct net_device *dev)
 {
 	struct m_can_priv *priv = netdev_priv(dev);
+	u32 cccr, test;
 
 	m_can_config_endisable(priv, true);
 
@@ -694,6 +698,22 @@  static void m_can_chip_config(struct net_device *dev)
 	m_can_write(priv, M_CAN_RXF1C, (priv->rxf1_elems << RXFC_FS_OFF) |
 		RXFC_FWM_1 | (priv->mram_off + priv->rxf1_off));
 
+	cccr = m_can_read(priv, M_CAN_CCCR);
+	cccr &= ~(CCCR_TEST | CCCR_MON);
+	test = m_can_read(priv, M_CAN_TEST);
+	test &= ~TEST_LBCK;
+
+	if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
+		cccr |= CCCR_MON;
+
+	if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) {
+		cccr |= CCCR_TEST;
+		test |= TEST_LBCK;
+	}
+
+	m_can_write(priv, M_CAN_CCCR, cccr);
+	m_can_write(priv, M_CAN_TEST, test);
+
 	/* enable all interrupts */
 	m_can_write(priv, M_CAN_IR, IR_ALL_INT);
 	m_can_write(priv, M_CAN_IE, IR_ALL_INT);