2020-01-31 18:39:16

by Dan Murphy

[permalink] [raw]
Subject: [PATCH linux-master 0/3] MCAN updates for clock discovery

Hello

These are the initial fixes for issues found in and requested in
https://lore.kernel.org/patchwork/patch/1165091/

For the clock discovery and initialization.

Dan

Dan Murphy (3):
can: tcan4x5x: Move clock init to TCAN driver
can: m_can_platform: Move clock discovery and init to platform
can: m_can: Remove unused clock function from the framework

drivers/net/can/m_can/m_can.c | 16 ------
drivers/net/can/m_can/m_can.h | 3 -
drivers/net/can/m_can/m_can_platform.c | 37 +++++++++---
drivers/net/can/m_can/tcan4x5x.c | 78 +++++++++++++++++++-------
4 files changed, 89 insertions(+), 45 deletions(-)

--
2.25.0


2020-01-31 18:39:20

by Dan Murphy

[permalink] [raw]
Subject: [PATCH linux-master 3/3] can: m_can: Remove unused clock function from the framework

Remove the unused clock function from the framework as the clock
discovery, initilaization and management are all within the registrars
code.

Signed-off-by: Dan Murphy <[email protected]>
---
drivers/net/can/m_can/m_can.c | 16 ----------------
drivers/net/can/m_can/m_can.h | 3 ---
2 files changed, 19 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 02c5795b7393..5794be1ef3ef 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1751,22 +1751,6 @@ void m_can_init_ram(struct m_can_classdev *cdev)
}
EXPORT_SYMBOL_GPL(m_can_init_ram);

-int m_can_class_get_clocks(struct m_can_classdev *m_can_dev)
-{
- int ret = 0;
-
- m_can_dev->hclk = devm_clk_get(m_can_dev->dev, "hclk");
- m_can_dev->cclk = devm_clk_get(m_can_dev->dev, "cclk");
-
- if (IS_ERR(m_can_dev->cclk)) {
- dev_err(m_can_dev->dev, "no clock found\n");
- ret = -ENODEV;
- }
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(m_can_class_get_clocks);
-
struct m_can_classdev *m_can_class_allocate_dev(struct device *dev)
{
struct m_can_classdev *class_dev = NULL;
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index 49f42b50627a..c20a716b14cc 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -74,8 +74,6 @@ struct m_can_classdev {
struct napi_struct napi;
struct net_device *net;
struct device *dev;
- struct clk *hclk;
- struct clk *cclk;

struct workqueue_struct *tx_wq;
struct work_struct tx_work;
@@ -101,7 +99,6 @@ struct m_can_classdev {
struct m_can_classdev *m_can_class_allocate_dev(struct device *dev);
int m_can_class_register(struct m_can_classdev *cdev);
void m_can_class_unregister(struct m_can_classdev *cdev);
-int m_can_class_get_clocks(struct m_can_classdev *cdev);
void m_can_init_ram(struct m_can_classdev *priv);
void m_can_config_endisable(struct m_can_classdev *priv, bool enable);

--
2.25.0

2020-01-31 18:39:31

by Dan Murphy

[permalink] [raw]
Subject: [PATCH linux-master 1/3] can: tcan4x5x: Move clock init to TCAN driver

Move the clock discovery and initialization from the m_can framework to
the registrar. This allows for registrars to have unique clock
initialization. The TCAN device only needs the CAN clock reference.

Signed-off-by: Dan Murphy <[email protected]>
---
drivers/net/can/m_can/tcan4x5x.c | 78 ++++++++++++++++++++++++--------
1 file changed, 59 insertions(+), 19 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x.c b/drivers/net/can/m_can/tcan4x5x.c
index eacd428e07e9..9821babef55e 100644
--- a/drivers/net/can/m_can/tcan4x5x.c
+++ b/drivers/net/can/m_can/tcan4x5x.c
@@ -124,6 +124,8 @@ struct tcan4x5x_priv {
struct gpio_desc *device_state_gpio;
struct regulator *power;

+ struct clk *cclk;
+
/* Register based ip */
int mram_start;
int reg_offset;
@@ -429,6 +431,27 @@ static struct m_can_ops tcan4x5x_ops = {
.clear_interrupts = tcan4x5x_clear_interrupts,
};

+static int tcan4x5x_get_clock(struct tcan4x5x_priv *priv,
+ struct m_can_classdev *m_can_dev)
+{
+ int freq;
+
+ priv->cclk = devm_clk_get(m_can_dev->dev, "cclk");
+ if (IS_ERR(priv->cclk)) {
+ dev_err(m_can_dev->dev, "no CAN clock source defined\n");
+ freq = TCAN4X5X_EXT_CLK_DEF;
+ priv->cclk = NULL;
+
+ } else {
+ freq = clk_get_rate(priv->cclk);
+ /* Sanity check */
+ if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF)
+ return -ERANGE;
+ }
+
+ return freq;
+}
+
static int tcan4x5x_can_probe(struct spi_device *spi)
{
struct tcan4x5x_priv *priv;
@@ -451,17 +474,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi)

mcan_class->device_data = priv;

- m_can_class_get_clocks(mcan_class);
- if (IS_ERR(mcan_class->cclk)) {
- dev_err(&spi->dev, "no CAN clock source defined\n");
- freq = TCAN4X5X_EXT_CLK_DEF;
- } else {
- freq = clk_get_rate(mcan_class->cclk);
- }
-
- /* Sanity check */
- if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF)
- return -ERANGE;
+ freq = tcan4x5x_get_clock(priv, mcan_class);
+ if (freq < 0)
+ return freq;

priv->reg_offset = TCAN4X5X_MCAN_OFFSET;
priv->mram_start = TCAN4X5X_MRAM_START;
@@ -483,14 +498,14 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
spi->bits_per_word = 32;
ret = spi_setup(spi);
if (ret)
- goto out_clk;
+ return ret;

priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
&spi->dev, &tcan4x5x_regmap);

ret = tcan4x5x_power_enable(priv->power, 1);
if (ret)
- goto out_clk;
+ return ret;

ret = tcan4x5x_parse_config(mcan_class);
if (ret)
@@ -509,12 +524,6 @@ static int tcan4x5x_can_probe(struct spi_device *spi)

out_power:
tcan4x5x_power_enable(priv->power, 0);
-out_clk:
- if (!IS_ERR(mcan_class->cclk)) {
- clk_disable_unprepare(mcan_class->cclk);
- clk_disable_unprepare(mcan_class->hclk);
- }
-
dev_err(&spi->dev, "Probe failed, err=%d\n", ret);
return ret;
}
@@ -530,6 +539,37 @@ static int tcan4x5x_can_remove(struct spi_device *spi)
return 0;
}

+static int __maybe_unused tcan4x5x_runtime_suspend(struct device *dev)
+{
+ struct net_device *ndev = dev_get_drvdata(dev);
+ struct m_can_classdev *mcan_class = netdev_priv(ndev);
+ struct tcan4x5x_priv *priv = mcan_class->device_data;
+
+ m_can_class_suspend(dev);
+
+ if (priv->cclk)
+ clk_disable_unprepare(priv->cclk);
+
+ return 0;
+}
+
+static int __maybe_unused tcan4x5x_runtime_resume(struct device *dev)
+{
+ struct net_device *ndev = dev_get_drvdata(dev);
+ struct m_can_classdev *mcan_class = netdev_priv(ndev);
+ struct tcan4x5x_priv *priv = mcan_class->device_data;
+
+ if (priv->cclk)
+ return clk_prepare_enable(priv->cclk);
+
+ return 0;
+}
+
+static const struct dev_pm_ops m_can_pmops = {
+ SET_RUNTIME_PM_OPS(tcan4x5x_runtime_suspend,
+ tcan4x5x_runtime_resume, NULL)
+};
+
static const struct of_device_id tcan4x5x_of_match[] = {
{ .compatible = "ti,tcan4x5x", },
{ }
--
2.25.0

2020-01-31 18:39:49

by Dan Murphy

[permalink] [raw]
Subject: [PATCH linux-master 2/3] can: m_can_platform: Move clock discovery and init to platform

Move the clock discovery and init to the platform driver as the platform
driver needs an additional clock to the CAN clock to be initilialized
and managed.

Signed-off-by: Dan Murphy <[email protected]>
---
drivers/net/can/m_can/m_can_platform.c | 37 +++++++++++++++++++++-----
1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
index 38ea5e600fb8..8bd459317eba 100644
--- a/drivers/net/can/m_can/m_can_platform.c
+++ b/drivers/net/can/m_can/m_can_platform.c
@@ -12,6 +12,9 @@
struct m_can_plat_priv {
void __iomem *base;
void __iomem *mram_base;
+
+ struct clk *hclk;
+ struct clk *cclk;
};

static u32 iomap_read_reg(struct m_can_classdev *cdev, int reg)
@@ -53,6 +56,22 @@ static struct m_can_ops m_can_plat_ops = {
.read_fifo = iomap_read_fifo,
};

+static int m_can_plat_get_clocks(struct m_can_plat_priv *priv,
+ struct m_can_classdev *mcan_class)
+{
+ int ret = 0;
+
+ priv->hclk = devm_clk_get(mcan_class->dev, "hclk");
+
+ priv->cclk = devm_clk_get(mcan_class->dev, "cclk");
+ if (IS_ERR(priv->cclk)) {
+ dev_err(mcan_class->dev, "no clock found\n");
+ ret = -ENODEV;
+ }
+
+ return ret;
+}
+
static int m_can_plat_probe(struct platform_device *pdev)
{
struct m_can_classdev *mcan_class;
@@ -72,7 +91,9 @@ static int m_can_plat_probe(struct platform_device *pdev)

mcan_class->device_data = priv;

- m_can_class_get_clocks(mcan_class);
+ ret = m_can_plat_get_clocks(priv, mcan_class);
+ if (ret)
+ return ret;

res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "m_can");
addr = devm_ioremap_resource(&pdev->dev, res);
@@ -100,7 +121,7 @@ static int m_can_plat_probe(struct platform_device *pdev)

mcan_class->net->irq = irq;
mcan_class->pm_clock_support = 1;
- mcan_class->can.clock.freq = clk_get_rate(mcan_class->cclk);
+ mcan_class->can.clock.freq = clk_get_rate(priv->cclk);
mcan_class->dev = &pdev->dev;

mcan_class->ops = &m_can_plat_ops;
@@ -143,11 +164,12 @@ static int __maybe_unused m_can_runtime_suspend(struct device *dev)
{
struct net_device *ndev = dev_get_drvdata(dev);
struct m_can_classdev *mcan_class = netdev_priv(ndev);
+ struct m_can_plat_priv *priv = mcan_class->device_data;

m_can_class_suspend(dev);

- clk_disable_unprepare(mcan_class->cclk);
- clk_disable_unprepare(mcan_class->hclk);
+ clk_disable_unprepare(priv->cclk);
+ clk_disable_unprepare(priv->hclk);

return 0;
}
@@ -156,15 +178,16 @@ static int __maybe_unused m_can_runtime_resume(struct device *dev)
{
struct net_device *ndev = dev_get_drvdata(dev);
struct m_can_classdev *mcan_class = netdev_priv(ndev);
+ struct m_can_plat_priv *priv = mcan_class->device_data;
int err;

- err = clk_prepare_enable(mcan_class->hclk);
+ err = clk_prepare_enable(priv->hclk);
if (err)
return err;

- err = clk_prepare_enable(mcan_class->cclk);
+ err = clk_prepare_enable(priv->cclk);
if (err)
- clk_disable_unprepare(mcan_class->hclk);
+ clk_disable_unprepare(priv->hclk);

return err;
}
--
2.25.0

2020-02-19 13:12:36

by Dan Murphy

[permalink] [raw]
Subject: Re: [PATCH linux-master 0/3] MCAN updates for clock discovery

Bump

On 1/31/20 12:34 PM, Dan Murphy wrote:
> Hello
>
> These are the initial fixes for issues found in and requested in
> https://lore.kernel.org/patchwork/patch/1165091/
>
> For the clock discovery and initialization.
>
> Dan
>
> Dan Murphy (3):
> can: tcan4x5x: Move clock init to TCAN driver
> can: m_can_platform: Move clock discovery and init to platform
> can: m_can: Remove unused clock function from the framework
>
> drivers/net/can/m_can/m_can.c | 16 ------
> drivers/net/can/m_can/m_can.h | 3 -
> drivers/net/can/m_can/m_can_platform.c | 37 +++++++++---
> drivers/net/can/m_can/tcan4x5x.c | 78 +++++++++++++++++++-------
> 4 files changed, 89 insertions(+), 45 deletions(-)
>

2020-02-21 14:31:41

by Dan Murphy

[permalink] [raw]
Subject: Re: [PATCH linux-master 1/3] can: tcan4x5x: Move clock init to TCAN driver

Hello

On 1/31/20 12:34 PM, Dan Murphy wrote:
> Move the clock discovery and initialization from the m_can framework to
> the registrar. This allows for registrars to have unique clock
> initialization. The TCAN device only needs the CAN clock reference.
>
> Signed-off-by: Dan Murphy <[email protected]>
> ---

I would like to have these 3 patches reviewed and integrated (post
review) so I can work on other issues identified.

Dan


2020-02-21 14:44:38

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH linux-master 1/3] can: tcan4x5x: Move clock init to TCAN driver

On 2/21/20 3:25 PM, Dan Murphy wrote:
> Hello
>
> On 1/31/20 12:34 PM, Dan Murphy wrote:
>> Move the clock discovery and initialization from the m_can framework to
>> the registrar. This allows for registrars to have unique clock
>> initialization. The TCAN device only needs the CAN clock reference.
>>
>> Signed-off-by: Dan Murphy <[email protected]>
>> ---
>
> I would like to have these 3 patches reviewed and integrated (post
> review) so I can work on other issues identified.

Applied to linux-can-next/testing.

tnx,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2020-02-25 19:36:32

by Dan Murphy

[permalink] [raw]
Subject: Re: [PATCH linux-master 1/3] can: tcan4x5x: Move clock init to TCAN driver

Marc

On 2/21/20 8:43 AM, Marc Kleine-Budde wrote:
> On 2/21/20 3:25 PM, Dan Murphy wrote:
>> Hello
>>
>> On 1/31/20 12:34 PM, Dan Murphy wrote:
>>> Move the clock discovery and initialization from the m_can framework to
>>> the registrar. This allows for registrars to have unique clock
>>> initialization. The TCAN device only needs the CAN clock reference.
>>>
>>> Signed-off-by: Dan Murphy <[email protected]>
>>> ---
>> I would like to have these 3 patches reviewed and integrated (post
>> review) so I can work on other issues identified.
> Applied to linux-can-next/testing.

I am not seeing these patches applied

I am looking here
https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git/log/?h=testing

But they could be in a different repo

Dan

>
> tnx,
> Marc
>

2020-02-25 20:49:33

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH linux-master 1/3] can: tcan4x5x: Move clock init to TCAN driver

On 2/25/20 6:45 PM, Dan Murphy wrote:
> Marc
>
> On 2/21/20 8:43 AM, Marc Kleine-Budde wrote:
>> On 2/21/20 3:25 PM, Dan Murphy wrote:
>>> Hello
>>>
>>> On 1/31/20 12:34 PM, Dan Murphy wrote:
>>>> Move the clock discovery and initialization from the m_can framework to
>>>> the registrar. This allows for registrars to have unique clock
>>>> initialization. The TCAN device only needs the CAN clock reference.
>>>>
>>>> Signed-off-by: Dan Murphy <[email protected]>
>>>> ---
>>> I would like to have these 3 patches reviewed and integrated (post
>>> review) so I can work on other issues identified.
>> Applied to linux-can-next/testing.
>
> I am not seeing these patches applied
>
> I am looking here
> https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git/log/?h=testing
>
> But they could be in a different repo

I've just pushed to that branch.

Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |