Skip to contentSkip to conversation

MCAN updates for clock discovery

PATCH In review Dan Murphy 2 participants 9 messages Jan 31, 2020 – Feb 25, 2020

Subsystems (2)
lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

cover 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(-)
Signature · 1 line
2.25.0
author
#1 lore raw

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

---
 drivers/net/can/m_can/tcan4x5x.c | 78 ++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 19 deletions(-)
drivers/net/can/m_can/tcan4x5x.c +59 -19
index eacd428e07e9..9821babef55e 100644
@@ -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", },
 	{ }
Signature · 1 line
2.25.0
author
#2 lore raw

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

Hello

Quoted 6 lines · Dan Murphy

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.

---

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

Dan

#3 lore raw

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

Quoted 7 lines · Dan Murphy

Hello

Quoted 4 lines · Dan Murphy

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.

Quoted 5 lines
Quoted 2 lines

---

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

Signature · 4 lines
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 |
author
#4 lore raw

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

Marc

Quoted 8 lines · Marc Kleine-Budde
Quoted 7 lines · Dan Murphy

Hello

Quoted 4 lines · Dan Murphy

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.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

---

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

Quoted 4 lines

tnx,
Marc

#5 lore raw

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

Quoted 15 lines · Dan Murphy

Marc

Quoted 12 lines · Marc Kleine-Budde
Quoted 11 lines · Dan Murphy

Hello

Quoted 6 lines · Dan Murphy

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.

---

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

Quoted 8 lines
Quoted 1 line

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

Signature · 4 lines
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 |
author
#6 lore raw

PATCH 2/3 can: m_can_platform: Move clock discovery and init to platform

In reply to Dan Murphy

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.

---
 drivers/net/can/m_can/m_can_platform.c | 37 +++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/net/can/m_can/m_can_platform.c +30 -7
index 38ea5e600fb8..8bd459317eba 100644
@@ -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;
 }
Signature · 1 line
2.25.0
author
#7 lore raw

PATCH 3/3 can: m_can: Remove unused clock function from the framework

In reply to Dan Murphy

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

---
 drivers/net/can/m_can/m_can.c | 16 ----------------
 drivers/net/can/m_can/m_can.h |  3 ---
 2 files changed, 19 deletions(-)
drivers/net/can/m_can/m_can.c +0 -16
index 02c5795b7393..5794be1ef3ef 100644
@@ -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;
drivers/net/can/m_can/m_can.h +0 -3
index 49f42b50627a..c20a716b14cc 100644
@@ -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);
 
Signature · 1 line
2.25.0
author
#8 lore raw
In reply to Dan Murphy

Bump

Quoted 20 lines · Dan Murphy

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