Re: [PATCH v5 2/5] can: m_can: Migrate the m_can code to use the framework

2019-02-28 Thread Dan Murphy
Hello

On 2/28/19 1:41 PM, Wolfgang Grandegger wrote:
> Hello Dan,
> 
> Am 28.02.19 um 18:57 schrieb Dan Murphy:
>> Wolfgang
>>
>> On 2/28/19 11:33 AM, Wolfgang Grandegger wrote:
>>> Am 14.02.19 um 19:27 schrieb Dan Murphy:
 Migrate the m_can code to use the m_can_platform framework
 code.

 Signed-off-by: Dan Murphy 
 ---

 v5 - Updated copyright, change m_can_classdev to m_can_priv, removed extra
 KCONFIG flag - https://lore.kernel.org/patchwork/patch/1033095/

  drivers/net/can/m_can/Kconfig  |   8 +-
  drivers/net/can/m_can/Makefile |   1 +
  drivers/net/can/m_can/m_can.c  | 745 -
  3 files changed, 367 insertions(+), 387 deletions(-)

 diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
 index 04f20dd39007..66e31022a5fa 100644
 --- a/drivers/net/can/m_can/Kconfig
 +++ b/drivers/net/can/m_can/Kconfig
 @@ -1,5 +1,11 @@
  config CAN_M_CAN
 +  tristate "Bosch M_CAN support"
 +  ---help---
 +Say Y here if you want to support for Bosch M_CAN controller.
>>>
>>> Typo?
>>>
>>
>> Maybe like you pointed out to update the help.
> 
> I was just not sure if it's correct English... but you know better!
> 

I actually added some additional content explaining what the flag was for and 
remove the "to" 

>>
 +
 +config CAN_M_CAN_PLATFORM
 +  tristate "Bosch M_CAN support for io-mapped devices"
depends on HAS_IOMEM
 -  tristate "Bosch M_CAN devices"
 +  depends on CAN_M_CAN
---help---
  Say Y here if you want to support for Bosch M_CAN controller.
>>>
>>> Please update the help.
>>
>> Ack
>>>
 diff --git a/drivers/net/can/m_can/Makefile 
 b/drivers/net/can/m_can/Makefile
 index 8bbd7f24f5be..057bbcdb3c74 100644
 --- a/drivers/net/can/m_can/Makefile
 +++ b/drivers/net/can/m_can/Makefile
 @@ -3,3 +3,4 @@
  #
  
  obj-$(CONFIG_CAN_M_CAN) += m_can.o
 +obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o
 diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
 index 9b449400376b..2ceccb870557 100644
 --- a/drivers/net/can/m_can/m_can.c
 +++ b/drivers/net/can/m_can/m_can.c
> ... snip ...
 @@ -924,6 +885,9 @@ static irqreturn_t m_can_isr(int irq, void *dev_id)
}
}
  
 +  if (priv->ops->clr_dev_interrupts)
 +  priv->ops->clr_dev_interrupts(priv);
>>>
>>> post_irq _handler?
>>>
>>
>> I can clear them on entry as well
> 
> OK!
> 
> ...snip...
> 
 -  niso_timeout = readl_poll_timeout((priv->base + M_CAN_CCCR), cccr_poll,
 -(cccr_poll == cccr_reg), 0, 10);
 +  for (i = 0; i <= 10; i++) {
 +  cccr_poll = m_can_read(priv, M_CAN_CCCR);
 +  if (cccr_poll == cccr_reg)
 +  niso_timeout = 0;
 +  }
>>>
>>> There is no break and delay in the loop? What was the reason why you
>>> can't use readl_poll_timeout()?
>>>
>>
>> OK a break if NISO is supported then and probably could add a 1us delay 
>> original code on
>> line 1232 had no delay but timeout at 10us.
>>
>> readl_poll_timeout is for iomapped devices.  How would this work for 
>> peripherial devices?
> 
> Well, it takes much more time to read the register via SPI... maybe using
> 
>   if (priv->is_peripherial) ...
> 
> to handle the different timings would make sense here.
> 

We really should isolate IO access calls away from the framework and have the 
registrars perform all
IO calls.

It may be better to create a call back to check for NISO support but I would 
think only IO mapped
code is the only special case.

Also a call back may be a bit much since this NISO function is only called in 
setup which is a one and done
function during registration.



  
/* Clear NISO */
cccr_reg &= ~(CCCR_NISO);
 @@ -1242,107 +1210,95 @@ static bool m_can_niso_supported(const struct 
 m_can_priv *priv)
return !niso_timeout;
  }
> ... snip...
> 
 -static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
 -  struct net_device *dev)
 +static void m_can_tx_handler(struct m_can_priv *priv)
  {
 -  struct m_can_priv *priv = netdev_priv(dev);
 -  struct canfd_frame *cf = (struct canfd_frame *)skb->data;
 +  struct canfd_frame *cf = (struct canfd_frame *)priv->skb->data;
 +  struct net_device *dev = priv->net;
 +  struct sk_buff *skb = priv->skb;
>>>
>>> Maybe "tx_skb" is a clearer member name..
>>
>> Again this was named skb to minimize deltas from original code.
> 
> I mean "priv->tx_skb"!
> 

Ack.  Changed for clarity I guess your point was made in my own confusion (heh).

Dan

>> skb was passed into the start_xmit function and used throughout the function.
>>
>> Since there was little delta in this function I opt'd to keep the names as 
>> is.
>>
> 
> Wolfgang.
> 


-- 

Re: [PATCH v5 2/5] can: m_can: Migrate the m_can code to use the framework

2019-02-28 Thread Wolfgang Grandegger
Hello Dan,

Am 28.02.19 um 18:57 schrieb Dan Murphy:
> Wolfgang
> 
> On 2/28/19 11:33 AM, Wolfgang Grandegger wrote:
>> Am 14.02.19 um 19:27 schrieb Dan Murphy:
>>> Migrate the m_can code to use the m_can_platform framework
>>> code.
>>>
>>> Signed-off-by: Dan Murphy 
>>> ---
>>>
>>> v5 - Updated copyright, change m_can_classdev to m_can_priv, removed extra
>>> KCONFIG flag - https://lore.kernel.org/patchwork/patch/1033095/
>>>
>>>  drivers/net/can/m_can/Kconfig  |   8 +-
>>>  drivers/net/can/m_can/Makefile |   1 +
>>>  drivers/net/can/m_can/m_can.c  | 745 -
>>>  3 files changed, 367 insertions(+), 387 deletions(-)
>>>
>>> diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
>>> index 04f20dd39007..66e31022a5fa 100644
>>> --- a/drivers/net/can/m_can/Kconfig
>>> +++ b/drivers/net/can/m_can/Kconfig
>>> @@ -1,5 +1,11 @@
>>>  config CAN_M_CAN
>>> +   tristate "Bosch M_CAN support"
>>> +   ---help---
>>> + Say Y here if you want to support for Bosch M_CAN controller.
>>
>> Typo?
>>
> 
> Maybe like you pointed out to update the help.

I was just not sure if it's correct English... but you know better!

> 
>>> +
>>> +config CAN_M_CAN_PLATFORM
>>> +   tristate "Bosch M_CAN support for io-mapped devices"
>>> depends on HAS_IOMEM
>>> -   tristate "Bosch M_CAN devices"
>>> +   depends on CAN_M_CAN
>>> ---help---
>>>   Say Y here if you want to support for Bosch M_CAN controller.
>>
>> Please update the help.
> 
> Ack
>>
>>> diff --git a/drivers/net/can/m_can/Makefile b/drivers/net/can/m_can/Makefile
>>> index 8bbd7f24f5be..057bbcdb3c74 100644
>>> --- a/drivers/net/can/m_can/Makefile
>>> +++ b/drivers/net/can/m_can/Makefile
>>> @@ -3,3 +3,4 @@
>>>  #
>>>  
>>>  obj-$(CONFIG_CAN_M_CAN) += m_can.o
>>> +obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o
>>> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
>>> index 9b449400376b..2ceccb870557 100644
>>> --- a/drivers/net/can/m_can/m_can.c
>>> +++ b/drivers/net/can/m_can/m_can.c
... snip ...
>>> @@ -924,6 +885,9 @@ static irqreturn_t m_can_isr(int irq, void *dev_id)
>>> }
>>> }
>>>  
>>> +   if (priv->ops->clr_dev_interrupts)
>>> +   priv->ops->clr_dev_interrupts(priv);
>>
>> post_irq _handler?
>>
> 
> I can clear them on entry as well

OK!

...snip...

>>> -   niso_timeout = readl_poll_timeout((priv->base + M_CAN_CCCR), cccr_poll,
>>> - (cccr_poll == cccr_reg), 0, 10);
>>> +   for (i = 0; i <= 10; i++) {
>>> +   cccr_poll = m_can_read(priv, M_CAN_CCCR);
>>> +   if (cccr_poll == cccr_reg)
>>> +   niso_timeout = 0;
>>> +   }
>>
>> There is no break and delay in the loop? What was the reason why you
>> can't use readl_poll_timeout()?
>>
> 
> OK a break if NISO is supported then and probably could add a 1us delay 
> original code on
> line 1232 had no delay but timeout at 10us.
> 
> readl_poll_timeout is for iomapped devices.  How would this work for 
> peripherial devices?

Well, it takes much more time to read the register via SPI... maybe using

if (priv->is_peripherial) ...

to handle the different timings would make sense here.

>>>  
>>> /* Clear NISO */
>>> cccr_reg &= ~(CCCR_NISO);
>>> @@ -1242,107 +1210,95 @@ static bool m_can_niso_supported(const struct 
>>> m_can_priv *priv)
>>> return !niso_timeout;
>>>  }
... snip...

>>> -static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
>>> -   struct net_device *dev)
>>> +static void m_can_tx_handler(struct m_can_priv *priv)
>>>  {
>>> -   struct m_can_priv *priv = netdev_priv(dev);
>>> -   struct canfd_frame *cf = (struct canfd_frame *)skb->data;
>>> +   struct canfd_frame *cf = (struct canfd_frame *)priv->skb->data;
>>> +   struct net_device *dev = priv->net;
>>> +   struct sk_buff *skb = priv->skb;
>>
>> Maybe "tx_skb" is a clearer member name..
> 
> Again this was named skb to minimize deltas from original code.

I mean "priv->tx_skb"!

> skb was passed into the start_xmit function and used throughout the function.
> 
> Since there was little delta in this function I opt'd to keep the names as is.
> 

Wolfgang.


Re: [PATCH v5 2/5] can: m_can: Migrate the m_can code to use the framework

2019-02-28 Thread Dan Murphy
Wolfgang

On 2/28/19 11:33 AM, Wolfgang Grandegger wrote:
> Am 14.02.19 um 19:27 schrieb Dan Murphy:
>> Migrate the m_can code to use the m_can_platform framework
>> code.
>>
>> Signed-off-by: Dan Murphy 
>> ---
>>
>> v5 - Updated copyright, change m_can_classdev to m_can_priv, removed extra
>> KCONFIG flag - https://lore.kernel.org/patchwork/patch/1033095/
>>
>>  drivers/net/can/m_can/Kconfig  |   8 +-
>>  drivers/net/can/m_can/Makefile |   1 +
>>  drivers/net/can/m_can/m_can.c  | 745 -
>>  3 files changed, 367 insertions(+), 387 deletions(-)
>>
>> diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
>> index 04f20dd39007..66e31022a5fa 100644
>> --- a/drivers/net/can/m_can/Kconfig
>> +++ b/drivers/net/can/m_can/Kconfig
>> @@ -1,5 +1,11 @@
>>  config CAN_M_CAN
>> +tristate "Bosch M_CAN support"
>> +---help---
>> +  Say Y here if you want to support for Bosch M_CAN controller.
> 
> Typo?
> 

Maybe like you pointed out to update the help.

>> +
>> +config CAN_M_CAN_PLATFORM
>> +tristate "Bosch M_CAN support for io-mapped devices"
>>  depends on HAS_IOMEM
>> -tristate "Bosch M_CAN devices"
>> +depends on CAN_M_CAN
>>  ---help---
>>Say Y here if you want to support for Bosch M_CAN controller.
> 
> Please update the help.

Ack
> 
>> diff --git a/drivers/net/can/m_can/Makefile b/drivers/net/can/m_can/Makefile
>> index 8bbd7f24f5be..057bbcdb3c74 100644
>> --- a/drivers/net/can/m_can/Makefile
>> +++ b/drivers/net/can/m_can/Makefile
>> @@ -3,3 +3,4 @@
>>  #
>>  
>>  obj-$(CONFIG_CAN_M_CAN) += m_can.o
>> +obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o
>> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
>> index 9b449400376b..2ceccb870557 100644
>> --- a/drivers/net/can/m_can/m_can.c
>> +++ b/drivers/net/can/m_can/m_can.c
>> @@ -1,20 +1,16 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +// CAN bus driver for Bosch M_CAN controller
>> +// Copyright (C) 2014 Freescale Semiconductor, Inc.
>> +//  Dong Aisheng 
>> +// Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
>> +
>>  /*
>> - * CAN bus driver for Bosch M_CAN controller
>> - *
>> - * Copyright (C) 2014 Freescale Semiconductor, Inc.
>> - *  Dong Aisheng 
>> - *
>>   * Bosch M_CAN user manual can be obtained from:
>>   * http://www.bosch-semiconductors.de/media/pdf_1/ipmodules_1/m_can/
>>   * mcan_users_manual_v302.pdf
>>   *
>> - * This file is licensed under the terms of the GNU General Public
>> - * License version 2. This program is licensed "as is" without any
>> - * warranty of any kind, whether express or implied.
>>   */
>>  
>> -#include 
>> -#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -28,87 +24,14 @@
>>  #include 
>>  #include 
>>  
>> +#include "m_can.h"
>> +
>>  /* napi related */
>>  #define M_CAN_NAPI_WEIGHT   64
>>  
>>  /* message ram configuration data length */
>>  #define MRAM_CFG_LEN8
>>  
>> -/* registers definition */
>> -enum m_can_reg {
>> -M_CAN_CREL  = 0x0,
>> -M_CAN_ENDN  = 0x4,
>> -M_CAN_CUST  = 0x8,
>> -M_CAN_DBTP  = 0xc,
>> -M_CAN_TEST  = 0x10,
>> -M_CAN_RWD   = 0x14,
>> -M_CAN_CCCR  = 0x18,
>> -M_CAN_NBTP  = 0x1c,
>> -M_CAN_TSCC  = 0x20,
>> -M_CAN_TSCV  = 0x24,
>> -M_CAN_TOCC  = 0x28,
>> -M_CAN_TOCV  = 0x2c,
>> -M_CAN_ECR   = 0x40,
>> -M_CAN_PSR   = 0x44,
>> -/* TDCR Register only available for version >=3.1.x */
>> -M_CAN_TDCR  = 0x48,
>> -M_CAN_IR= 0x50,
>> -M_CAN_IE= 0x54,
>> -M_CAN_ILS   = 0x58,
>> -M_CAN_ILE   = 0x5c,
>> -M_CAN_GFC   = 0x80,
>> -M_CAN_SIDFC = 0x84,
>> -M_CAN_XIDFC = 0x88,
>> -M_CAN_XIDAM = 0x90,
>> -M_CAN_HPMS  = 0x94,
>> -M_CAN_NDAT1 = 0x98,
>> -M_CAN_NDAT2 = 0x9c,
>> -M_CAN_RXF0C = 0xa0,
>> -M_CAN_RXF0S = 0xa4,
>> -M_CAN_RXF0A = 0xa8,
>> -M_CAN_RXBC  = 0xac,
>> -M_CAN_RXF1C = 0xb0,
>> -M_CAN_RXF1S = 0xb4,
>> -M_CAN_RXF1A = 0xb8,
>> -M_CAN_RXESC = 0xbc,
>> -M_CAN_TXBC  = 0xc0,
>> -M_CAN_TXFQS = 0xc4,
>> -M_CAN_TXESC = 0xc8,
>> -M_CAN_TXBRP = 0xcc,
>> -M_CAN_TXBAR = 0xd0,
>> -M_CAN_TXBCR = 0xd4,
>> -M_CAN_TXBTO = 0xd8,
>> -M_CAN_TXBCF = 0xdc,
>> -M_CAN_TXBTIE= 0xe0,
>> -M_CAN_TXBCIE= 0xe4,
>> -M_CAN_TXEFC = 0xf0,
>> -M_CAN_TXEFS = 0xf4,
>> -M_CAN_TXEFA = 0xf8,
>> -};
>> -
>> -/* m_can lec values */
>> -enum m_can_lec_type {
>> -LEC_NO_ERROR = 0,
>> -LEC_STUFF_ERROR,
>> -LEC_FORM_ERROR,
>> -LEC_ACK_ERROR,
>> -LEC_BIT1_ERROR,
>> -LEC_BIT0_ERROR,
>> -LEC_CRC_ERROR,
>> -LEC_UNUSED,
>> -};
>> -
>> -enum m_can_mram_cfg {
>> -MRAM_SIDF = 0,
>> -MRAM_XIDF,
>> -MRAM_RXF0,
>> -MRAM_RXF1,
>> -MRAM_RXB,
>> -MRAM_TXE,
>> 

Re: [PATCH v5 2/5] can: m_can: Migrate the m_can code to use the framework

2019-02-28 Thread Wolfgang Grandegger
Am 14.02.19 um 19:27 schrieb Dan Murphy:
> Migrate the m_can code to use the m_can_platform framework
> code.
> 
> Signed-off-by: Dan Murphy 
> ---
> 
> v5 - Updated copyright, change m_can_classdev to m_can_priv, removed extra
> KCONFIG flag - https://lore.kernel.org/patchwork/patch/1033095/
> 
>  drivers/net/can/m_can/Kconfig  |   8 +-
>  drivers/net/can/m_can/Makefile |   1 +
>  drivers/net/can/m_can/m_can.c  | 745 -
>  3 files changed, 367 insertions(+), 387 deletions(-)
> 
> diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
> index 04f20dd39007..66e31022a5fa 100644
> --- a/drivers/net/can/m_can/Kconfig
> +++ b/drivers/net/can/m_can/Kconfig
> @@ -1,5 +1,11 @@
>  config CAN_M_CAN
> + tristate "Bosch M_CAN support"
> + ---help---
> +   Say Y here if you want to support for Bosch M_CAN controller.

Typo?

> +
> +config CAN_M_CAN_PLATFORM
> + tristate "Bosch M_CAN support for io-mapped devices"
>   depends on HAS_IOMEM
> - tristate "Bosch M_CAN devices"
> + depends on CAN_M_CAN
>   ---help---
> Say Y here if you want to support for Bosch M_CAN controller.

Please update the help.

> diff --git a/drivers/net/can/m_can/Makefile b/drivers/net/can/m_can/Makefile
> index 8bbd7f24f5be..057bbcdb3c74 100644
> --- a/drivers/net/can/m_can/Makefile
> +++ b/drivers/net/can/m_can/Makefile
> @@ -3,3 +3,4 @@
>  #
>  
>  obj-$(CONFIG_CAN_M_CAN) += m_can.o
> +obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 9b449400376b..2ceccb870557 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -1,20 +1,16 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// CAN bus driver for Bosch M_CAN controller
> +// Copyright (C) 2014 Freescale Semiconductor, Inc.
> +//  Dong Aisheng 
> +// Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
> +
>  /*
> - * CAN bus driver for Bosch M_CAN controller
> - *
> - * Copyright (C) 2014 Freescale Semiconductor, Inc.
> - *   Dong Aisheng 
> - *
>   * Bosch M_CAN user manual can be obtained from:
>   * http://www.bosch-semiconductors.de/media/pdf_1/ipmodules_1/m_can/
>   * mcan_users_manual_v302.pdf
>   *
> - * This file is licensed under the terms of the GNU General Public
> - * License version 2. This program is licensed "as is" without any
> - * warranty of any kind, whether express or implied.
>   */
>  
> -#include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -28,87 +24,14 @@
>  #include 
>  #include 
>  
> +#include "m_can.h"
> +
>  /* napi related */
>  #define M_CAN_NAPI_WEIGHT64
>  
>  /* message ram configuration data length */
>  #define MRAM_CFG_LEN 8
>  
> -/* registers definition */
> -enum m_can_reg {
> - M_CAN_CREL  = 0x0,
> - M_CAN_ENDN  = 0x4,
> - M_CAN_CUST  = 0x8,
> - M_CAN_DBTP  = 0xc,
> - M_CAN_TEST  = 0x10,
> - M_CAN_RWD   = 0x14,
> - M_CAN_CCCR  = 0x18,
> - M_CAN_NBTP  = 0x1c,
> - M_CAN_TSCC  = 0x20,
> - M_CAN_TSCV  = 0x24,
> - M_CAN_TOCC  = 0x28,
> - M_CAN_TOCV  = 0x2c,
> - M_CAN_ECR   = 0x40,
> - M_CAN_PSR   = 0x44,
> -/* TDCR Register only available for version >=3.1.x */
> - M_CAN_TDCR  = 0x48,
> - M_CAN_IR= 0x50,
> - M_CAN_IE= 0x54,
> - M_CAN_ILS   = 0x58,
> - M_CAN_ILE   = 0x5c,
> - M_CAN_GFC   = 0x80,
> - M_CAN_SIDFC = 0x84,
> - M_CAN_XIDFC = 0x88,
> - M_CAN_XIDAM = 0x90,
> - M_CAN_HPMS  = 0x94,
> - M_CAN_NDAT1 = 0x98,
> - M_CAN_NDAT2 = 0x9c,
> - M_CAN_RXF0C = 0xa0,
> - M_CAN_RXF0S = 0xa4,
> - M_CAN_RXF0A = 0xa8,
> - M_CAN_RXBC  = 0xac,
> - M_CAN_RXF1C = 0xb0,
> - M_CAN_RXF1S = 0xb4,
> - M_CAN_RXF1A = 0xb8,
> - M_CAN_RXESC = 0xbc,
> - M_CAN_TXBC  = 0xc0,
> - M_CAN_TXFQS = 0xc4,
> - M_CAN_TXESC = 0xc8,
> - M_CAN_TXBRP = 0xcc,
> - M_CAN_TXBAR = 0xd0,
> - M_CAN_TXBCR = 0xd4,
> - M_CAN_TXBTO = 0xd8,
> - M_CAN_TXBCF = 0xdc,
> - M_CAN_TXBTIE= 0xe0,
> - M_CAN_TXBCIE= 0xe4,
> - M_CAN_TXEFC = 0xf0,
> - M_CAN_TXEFS = 0xf4,
> - M_CAN_TXEFA = 0xf8,
> -};
> -
> -/* m_can lec values */
> -enum m_can_lec_type {
> - LEC_NO_ERROR = 0,
> - LEC_STUFF_ERROR,
> - LEC_FORM_ERROR,
> - LEC_ACK_ERROR,
> - LEC_BIT1_ERROR,
> - LEC_BIT0_ERROR,
> - LEC_CRC_ERROR,
> - LEC_UNUSED,
> -};
> -
> -enum m_can_mram_cfg {
> - MRAM_SIDF = 0,
> - MRAM_XIDF,
> - MRAM_RXF0,
> - MRAM_RXF1,
> - MRAM_RXB,
> - MRAM_TXE,
> - MRAM_TXB,
> - MRAM_CFG_NUM,
> -};
> -
>  /* Core Release Register (CREL) */
>  #define CREL_REL_SHIFT   28
>  #define CREL_REL_MASK(0xF << CREL_REL_SHIFT)
> @@ -343,77 

[PATCH v5 2/5] can: m_can: Migrate the m_can code to use the framework

2019-02-14 Thread Dan Murphy
Migrate the m_can code to use the m_can_platform framework
code.

Signed-off-by: Dan Murphy 
---

v5 - Updated copyright, change m_can_classdev to m_can_priv, removed extra
KCONFIG flag - https://lore.kernel.org/patchwork/patch/1033095/

 drivers/net/can/m_can/Kconfig  |   8 +-
 drivers/net/can/m_can/Makefile |   1 +
 drivers/net/can/m_can/m_can.c  | 745 -
 3 files changed, 367 insertions(+), 387 deletions(-)

diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
index 04f20dd39007..66e31022a5fa 100644
--- a/drivers/net/can/m_can/Kconfig
+++ b/drivers/net/can/m_can/Kconfig
@@ -1,5 +1,11 @@
 config CAN_M_CAN
+   tristate "Bosch M_CAN support"
+   ---help---
+ Say Y here if you want to support for Bosch M_CAN controller.
+
+config CAN_M_CAN_PLATFORM
+   tristate "Bosch M_CAN support for io-mapped devices"
depends on HAS_IOMEM
-   tristate "Bosch M_CAN devices"
+   depends on CAN_M_CAN
---help---
  Say Y here if you want to support for Bosch M_CAN controller.
diff --git a/drivers/net/can/m_can/Makefile b/drivers/net/can/m_can/Makefile
index 8bbd7f24f5be..057bbcdb3c74 100644
--- a/drivers/net/can/m_can/Makefile
+++ b/drivers/net/can/m_can/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_CAN_M_CAN) += m_can.o
+obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 9b449400376b..2ceccb870557 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1,20 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+// CAN bus driver for Bosch M_CAN controller
+// Copyright (C) 2014 Freescale Semiconductor, Inc.
+//  Dong Aisheng 
+// Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.com/
+
 /*
- * CAN bus driver for Bosch M_CAN controller
- *
- * Copyright (C) 2014 Freescale Semiconductor, Inc.
- * Dong Aisheng 
- *
  * Bosch M_CAN user manual can be obtained from:
  * http://www.bosch-semiconductors.de/media/pdf_1/ipmodules_1/m_can/
  * mcan_users_manual_v302.pdf
  *
- * This file is licensed under the terms of the GNU General Public
- * License version 2. This program is licensed "as is" without any
- * warranty of any kind, whether express or implied.
  */
 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -28,87 +24,14 @@
 #include 
 #include 
 
+#include "m_can.h"
+
 /* napi related */
 #define M_CAN_NAPI_WEIGHT  64
 
 /* message ram configuration data length */
 #define MRAM_CFG_LEN   8
 
-/* registers definition */
-enum m_can_reg {
-   M_CAN_CREL  = 0x0,
-   M_CAN_ENDN  = 0x4,
-   M_CAN_CUST  = 0x8,
-   M_CAN_DBTP  = 0xc,
-   M_CAN_TEST  = 0x10,
-   M_CAN_RWD   = 0x14,
-   M_CAN_CCCR  = 0x18,
-   M_CAN_NBTP  = 0x1c,
-   M_CAN_TSCC  = 0x20,
-   M_CAN_TSCV  = 0x24,
-   M_CAN_TOCC  = 0x28,
-   M_CAN_TOCV  = 0x2c,
-   M_CAN_ECR   = 0x40,
-   M_CAN_PSR   = 0x44,
-/* TDCR Register only available for version >=3.1.x */
-   M_CAN_TDCR  = 0x48,
-   M_CAN_IR= 0x50,
-   M_CAN_IE= 0x54,
-   M_CAN_ILS   = 0x58,
-   M_CAN_ILE   = 0x5c,
-   M_CAN_GFC   = 0x80,
-   M_CAN_SIDFC = 0x84,
-   M_CAN_XIDFC = 0x88,
-   M_CAN_XIDAM = 0x90,
-   M_CAN_HPMS  = 0x94,
-   M_CAN_NDAT1 = 0x98,
-   M_CAN_NDAT2 = 0x9c,
-   M_CAN_RXF0C = 0xa0,
-   M_CAN_RXF0S = 0xa4,
-   M_CAN_RXF0A = 0xa8,
-   M_CAN_RXBC  = 0xac,
-   M_CAN_RXF1C = 0xb0,
-   M_CAN_RXF1S = 0xb4,
-   M_CAN_RXF1A = 0xb8,
-   M_CAN_RXESC = 0xbc,
-   M_CAN_TXBC  = 0xc0,
-   M_CAN_TXFQS = 0xc4,
-   M_CAN_TXESC = 0xc8,
-   M_CAN_TXBRP = 0xcc,
-   M_CAN_TXBAR = 0xd0,
-   M_CAN_TXBCR = 0xd4,
-   M_CAN_TXBTO = 0xd8,
-   M_CAN_TXBCF = 0xdc,
-   M_CAN_TXBTIE= 0xe0,
-   M_CAN_TXBCIE= 0xe4,
-   M_CAN_TXEFC = 0xf0,
-   M_CAN_TXEFS = 0xf4,
-   M_CAN_TXEFA = 0xf8,
-};
-
-/* m_can lec values */
-enum m_can_lec_type {
-   LEC_NO_ERROR = 0,
-   LEC_STUFF_ERROR,
-   LEC_FORM_ERROR,
-   LEC_ACK_ERROR,
-   LEC_BIT1_ERROR,
-   LEC_BIT0_ERROR,
-   LEC_CRC_ERROR,
-   LEC_UNUSED,
-};
-
-enum m_can_mram_cfg {
-   MRAM_SIDF = 0,
-   MRAM_XIDF,
-   MRAM_RXF0,
-   MRAM_RXF1,
-   MRAM_RXB,
-   MRAM_TXE,
-   MRAM_TXB,
-   MRAM_CFG_NUM,
-};
-
 /* Core Release Register (CREL) */
 #define CREL_REL_SHIFT 28
 #define CREL_REL_MASK  (0xF << CREL_REL_SHIFT)
@@ -343,77 +266,89 @@ enum m_can_mram_cfg {
 #define TX_BUF_MM_MASK (0xff << TX_BUF_MM_SHIFT)
 
 /* Tx event FIFO Element */
-/* E1 */
 #define TX_EVENT_MM_SHIFT  TX_BUF_MM_SHIFT
 #define TX_EVENT_MM_MASK   (0xff << TX_EVENT_MM_SHIFT)
 
-/* address offset and