From: Angelo Dureghello <angelo@kernel-space.org>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: gerg@linux-m68k.org, wg@grandegger.com, geert@linux-m68k.org,
linux-m68k@vger.kernel.org, linux-can@vger.kernel.org,
qiangqing.zhang@nxp.com
Subject: Re: [PATCH 5/5] can: flexcan: add mcf5441x support
Date: Wed, 9 Jun 2021 11:05:15 +0200 [thread overview]
Message-ID: <7780a03b-dd3d-0bcc-58f4-537689ed7048@kernel-space.org> (raw)
In-Reply-To: <20210609085627.432kdoxrdklt5vsa@pengutronix.de>
Hi Mark,
thanks for the feedbacks,
On 09/06/21 10:56 AM, Marc Kleine-Budde wrote:
> On 08.06.2021 22:45:42, Angelo Dureghello wrote:
>> Add flexcan support for NXP ColdFire mcf5441x family.
>>
>> This flexcan module is quite similar to imx6 flexcan module, but
>> with some exceptions:
>>
>> - 3 separate interrupt sources, MB, BOFF and ERR,
>
> Please don't hard code the 2 extra interrupts as offsets, but create
> proper IRQ resources.
>
ok
>> - implements 16 mb only,
>> - m68k architecture is not supporting devicetrees, so a
>> platform data check/case has been added,
>
> You might want to revert:
>
> | 2c0ac9208135 can: flexcan: convert the driver to DT-only
>
> and use it as a starting point.
>
ok
>> - ColdFire is m68k, so big-endian cpu, with a little-endian flexcan
>> module.
>>
>> Signed-off-by: Angelo Dureghello <angelo@kernel-space.org>
>> ---
>> drivers/net/can/flexcan.c | 80 +++++++++++++++++++++++++++++++--------
>> 1 file changed, 65 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
>> index 57f3635ad8d7..af95273327cd 100644
>> --- a/drivers/net/can/flexcan.c
>> +++ b/drivers/net/can/flexcan.c
>> @@ -28,6 +28,7 @@
>> #include <linux/of_device.h>
>> #include <linux/pinctrl/consumer.h>
>> #include <linux/platform_device.h>
>> +#include <linux/platform_data/flexcan-mcf.h>
>> #include <linux/pm_runtime.h>
>> #include <linux/regmap.h>
>> #include <linux/regulator/consumer.h>
>> @@ -205,6 +206,10 @@
>>
>> #define FLEXCAN_TIMEOUT_US (250)
>>
>> +#define FLEXCAN_OFFS_INT_BOFF 1
>> +#define FLEXCAN_OFFS_INT_ERR 3
>> +#define FLEXCAN_MB_CNT_MCF 16
>> +
>> /* FLEXCAN hardware feature flags
>> *
>> * Below is some version info we got:
>> @@ -246,6 +251,8 @@
>> #define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)
>> /* Setup stop mode with SCU firmware to support wakeup */
>> #define FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW BIT(11)
>> +/* Setup for flexcan module as in mcf, 16 mb, 3 separate interrupts */
>> +#define FLEXCAN_QUIRK_SETUP_MCF BIT(12)
>>
>> /* Structure of the message buffer */
>> struct flexcan_mb {
>> @@ -371,6 +378,12 @@ struct flexcan_priv {
>> void (*write)(u32 val, void __iomem *addr);
>> };
>>
>> +static const struct flexcan_devtype_data fsl_mcf_devtype_data = {
>> + .quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
>> + FLEXCAN_QUIRK_BROKEN_PERR_STATE |
>> + FLEXCAN_QUIRK_SETUP_MCF,
>> +};
>> +
>> static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
>> .quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
>> FLEXCAN_QUIRK_BROKEN_PERR_STATE |
>> @@ -637,13 +650,17 @@ static int flexcan_clks_enable(const struct flexcan_priv *priv)
>> {
>> int err;
>>
>> - err = clk_prepare_enable(priv->clk_ipg);
>> - if (err)
>> - return err;
>> + if (priv->clk_ipg) {
>> + err = clk_prepare_enable(priv->clk_ipg);
>> + if (err)
>> + return err;
>> + }
>>
>> - err = clk_prepare_enable(priv->clk_per);
>> - if (err)
>> - clk_disable_unprepare(priv->clk_ipg);
>> + if (priv->clk_per) {
>> + err = clk_prepare_enable(priv->clk_per);
>> + if (err)
>> + clk_disable_unprepare(priv->clk_ipg);
>> + }
>>
>> return err;
>> }
>> @@ -1401,8 +1418,13 @@ static int flexcan_rx_offload_setup(struct net_device *dev)
>> priv->mb_size = sizeof(struct flexcan_mb) + CANFD_MAX_DLEN;
>> else
>> priv->mb_size = sizeof(struct flexcan_mb) + CAN_MAX_DLEN;
>> - priv->mb_count = (sizeof(priv->regs->mb[0]) / priv->mb_size) +
>> - (sizeof(priv->regs->mb[1]) / priv->mb_size);
>> +
>> + if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_MCF) {
>> + priv->mb_count = FLEXCAN_MB_CNT_MCF;
>> + } else {
>> + priv->mb_count = (sizeof(priv->regs->mb[0]) / priv->mb_size) +
>> + (sizeof(priv->regs->mb[1]) / priv->mb_size);
>> + }
>
> nitpick: no { } needed
>
ok
>>
>> if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP)
>> priv->tx_mb_reserved =
>> @@ -1774,6 +1796,18 @@ static int flexcan_open(struct net_device *dev)
>> if (err)
>> goto out_can_rx_offload_disable;
>>
>> + if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_MCF) {
>> + err = request_irq(dev->irq + FLEXCAN_OFFS_INT_BOFF,
>> + flexcan_irq, IRQF_SHARED, dev->name, dev);
>> + if (err)
>> + goto out_can_rx_offload_disable;
>> +
>> + err = request_irq(dev->irq + FLEXCAN_OFFS_INT_ERR,
>> + flexcan_irq, IRQF_SHARED, dev->name, dev);
>> + if (err)
>> + goto out_can_rx_offload_disable;
>
> I'm missing the free_irq() in error handling and the flexcan_close()
> function. Please test your driver if it work still after several
> modprobe rmmod cycles.
>
forgot, will fix
>> + }
>> +
>> flexcan_chip_interrupts_enable(dev);
>>
>> can_led_event(dev, CAN_LED_EVENT_OPEN);
>> @@ -2047,7 +2081,9 @@ static int flexcan_probe(struct platform_device *pdev)
>> struct regulator *reg_xceiver;
>> struct clk *clk_ipg = NULL, *clk_per = NULL;
>> struct flexcan_regs __iomem *regs;
>> + struct mcf_flexcan_platform_data *pdata;
>> int err, irq;
>> + bool big_endian_module;
>> u8 clk_src = 1;
>> u32 clock_freq = 0;
>>
>> @@ -2059,11 +2095,17 @@ static int flexcan_probe(struct platform_device *pdev)
>> else if (IS_ERR(reg_xceiver))
>> return PTR_ERR(reg_xceiver);
>>
>> - if (pdev->dev.of_node) {
>> - of_property_read_u32(pdev->dev.of_node,
>> - "clock-frequency", &clock_freq);
>> - of_property_read_u8(pdev->dev.of_node,
>> - "fsl,clk-source", &clk_src);
>> + pdata = dev_get_platdata(&pdev->dev);
>> + if (pdata) {
>> + clock_freq = pdata->clock_frequency;
>> + clk_src = pdata->clk_src;
>> + } else {
>> + if (pdev->dev.of_node) {
>
> else if
>
ok
>> + of_property_read_u32(pdev->dev.of_node,
>> + "clock-frequency", &clock_freq);
>> + of_property_read_u8(pdev->dev.of_node,
>> + "fsl,clk-source", &clk_src);
>> + }
>> }
>>
>> if (!clock_freq) {
>> @@ -2091,6 +2133,11 @@ static int flexcan_probe(struct platform_device *pdev)
>>
>> devtype_data = of_device_get_match_data(&pdev->dev);
>>
>> + if (pdata && !devtype_data) {
>> + devtype_data =
>> + (struct flexcan_devtype_data *)&fsl_mcf_devtype_data;
>
> That looks broken, see 2c0ac9208135 how to do this properly. Please add a
> name "flexcan-mcf" to the id_table and use fsl_mcf_devtype_data as
> driver_data.
ok
>
>> + }
>> +
>> if ((devtype_data->quirks & FLEXCAN_QUIRK_SUPPORT_FD) &&
>> !(devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP)) {
>> dev_err(&pdev->dev, "CAN-FD mode doesn't work with FIFO mode!\n");
>> @@ -2110,8 +2157,11 @@ static int flexcan_probe(struct platform_device *pdev)
>>
>> priv = netdev_priv(dev);
>>
>> - if (of_property_read_bool(pdev->dev.of_node, "big-endian") ||
>> - devtype_data->quirks & FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN) {
>> + big_endian_module = pdata ? pdata->big_endian :
>> + of_property_read_bool(pdev->dev.of_node, "big-endian");
>
> Please add the FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN to you
> fsl_mcf_devtype_data if needed. There's no need to add a 3rd way of
> configuring this.
i think that quirk is for big endian flexcan modules.
In my case, cpu is big endian but flexcan registers are
little endian, thgis is why i am not using that quirk.
>
>> +
>> + if (big_endian_module ||
>> + (devtype_data->quirks & FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN)) {
>> priv->read = flexcan_read_be;
>> priv->write = flexcan_write_be;
>> } else {
>> --
>> 2.31.1
>>
>>
>
> Marc
>
will fix all to a v2
Thanks !
Regards,
--
Angelo Dureghello
+++ kernelspace +++
+E: angelo AT kernel-space.org
+W: www.kernel-space.org
next prev parent reply other threads:[~2021-06-09 9:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 20:45 [PATCH 1/5] can: flexcan: add platform data for ColdFire Angelo Dureghello
2021-06-08 20:45 ` [PATCH 2/5] m68k: stmark2: update board setup Angelo Dureghello
2021-06-08 20:45 ` [PATCH 3/5] m68k: m5441x: add flexcan support Angelo Dureghello
2021-06-09 13:24 ` Greg Ungerer
2021-06-10 7:59 ` Angelo Dureghello
2021-06-11 12:38 ` Greg Ungerer
2021-06-08 20:45 ` [PATCH 4/5] can: flexcan: enable Kconfig for ColdFire Angelo Dureghello
2021-06-08 20:45 ` [PATCH 5/5] can: flexcan: add mcf5441x support Angelo Dureghello
2021-06-09 2:05 ` Joakim Zhang
2021-06-09 8:12 ` Geert Uytterhoeven
2021-06-09 8:42 ` Angelo Dureghello
2021-06-09 13:18 ` Greg Ungerer
2021-06-09 8:35 ` Angelo Dureghello
2021-06-09 8:56 ` Marc Kleine-Budde
2021-06-09 9:05 ` Angelo Dureghello [this message]
2021-06-09 2:05 ` [PATCH 1/5] can: flexcan: add platform data for ColdFire Joakim Zhang
2021-06-09 7:57 ` Angelo Dureghello
2021-06-09 8:14 ` Geert Uytterhoeven
2021-06-09 8:56 ` Angelo Dureghello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7780a03b-dd3d-0bcc-58f4-537689ed7048@kernel-space.org \
--to=angelo@kernel-space.org \
--cc=geert@linux-m68k.org \
--cc=gerg@linux-m68k.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-m68k@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=qiangqing.zhang@nxp.com \
--cc=wg@grandegger.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox