can: mcp251xfd: Try to get crystal clock rate from property
PATCH v2 1/2 can: mcp251xfd: Try to get crystal clock rate from property
In some configurations, mainly ACPI-based, the clock frequency of the device is supplied by very well established 'clock-frequency' property. Hence, try to get it from the property at last if no other providers are available.
---
v2: new patch
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +7 -2
@@ -2856,7 +2856,7 @@ static int mcp251xfd_probe(struct spi_device *spi)struct gpio_desc *rx_int;struct regulator *reg_vdd, *reg_xceiver;struct clk *clk; -u32 freq; +u32 freq, rate;int err;if (!spi->irq)
@@ -2883,11 +2883,16 @@ static int mcp251xfd_probe(struct spi_device *spi)return dev_err_probe (&spi->dev,PTR_ERR (reg_xceiver),"Failed to get Transceiver regulator!\n" ); - clk =devm_clk_get (&spi->dev,NULL ); +/* Always ask for fixed clock rate from a property. */ +device_property_read_u32 (&spi->dev,"clock-frequency" , &rate); + + clk =devm_clk_get_optional (&spi->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&spi->dev,PTR_ERR (clk),"Failed to get Oscillator (clock)!\n" ); freq =clk_get_rate (clk); +if (freq ==0 ) + freq = rate;/* Sanity check */ if (freq < MCP251XFD_SYSCLOCK_HZ_MIN ||
Signature · 1 line
2.30.2
PATCH v2 2/2 can: mcp251xfd: Fix header block to clarify independence from OF
The driver is neither dependent on OF, nor it requires any OF headers. Fix header block to clarify independence from OF.
---
v2: included property.h
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -2
@@ -15,10 +15,10 @@#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/device.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> -#include <linux/of.h> -#include <linux/of_device.h> #include <linux/pm_runtime.h> +#include <linux/property.h> #include <asm/unaligned.h>
Signature · 1 line
2.30.2
Marc Kleine-Budde
maintainerQuoted 24 lines · Andy Shevchenko
In some configurations, mainly ACPI-based, the clock frequency of the device is supplied by very well established 'clock-frequency' property. Hence, try to get it from the property at last if no other providers are available.
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchdrivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1
-1@@ -2856,7 +2856,7 @@ static int mcp251xfd_probe(struct spi_device *spi)struct gpio_desc *rx_int;struct regulator *reg_vdd, *reg_xceiver;struct clk *clk; -u32 freq; +u32 freq, rate;int err;if (!spi->irq)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2887
Quoted 6 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2
-1@@ -2883,11 +2883,16 @@ static int mcp251xfd_probe(struct spi_device *spi)return dev_err_probe (&spi->dev,PTR_ERR (reg_xceiver),"Failed to get Transceiver regulator!\n" ); - clk =devm_clk_get (&spi->dev,NULL ); +/* Always ask for fixed clock rate from a property. */ +device_property_read_u32 (&spi->dev,"clock-frequency" , &rate);
what about error handling....?
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2895
Quoted 8 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +4
-0+ + clk =devm_clk_get_optional (&spi->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&spi->dev,PTR_ERR (clk),"Failed to get Oscillator (clock)!\n" ); freq =clk_get_rate (clk); +if (freq ==0 ) + freq = rate;
... this means we don't fail if there is neither a clk nor a clock-frequency property. I've send a v3 to fix this.
Quoted 7 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0
-0/* Sanity check */ if (freq < MCP251XFD_SYSCLOCK_HZ_MIN ||Signature · 1 line
2.30.2
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 |
Quoted 5 lines · Marc Kleine-Budde
Quoted 3 lines · Andy Shevchenko
In some configurations, mainly ACPI-based, the clock frequency of the device is supplied by very well established 'clock-frequency' property. Hence, try to get it from the property at last if no other providers are available.
Quoted 8 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2887
Quoted 6 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2
-1return dev_err_probe (&spi->dev,PTR_ERR (reg_xceiver),"Failed to get Transceiver regulator!\n" ); - clk =devm_clk_get (&spi->dev,NULL ); +/* Always ask for fixed clock rate from a property. */ +device_property_read_u32 (&spi->dev,"clock-frequency" , &rate);what about error handling....?
Not needed, but rate should be assigned to 0, which is missed.
Quoted 10 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2895
Quoted 7 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3
-0+ clk =devm_clk_get_optional (&spi->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&spi->dev,PTR_ERR (clk),"Failed to get Oscillator (clock)!\n" ); freq =clk_get_rate (clk); +if (freq ==0 ) + freq = rate;... this means we don't fail if there is neither a clk nor a clock-frequency property.
The following will check for it (which is already in the code)
if (freq <= MCP251XFD_SYSCLOCK_HZ_MAX / MCP251XFD_OSC_PLL_MULTIPLIER) {Quoted 1 line
I've send a v3 to fix this.
You mean I have to send v3?
Sure!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 28 lines · Andy Shevchenko
Quoted 5 lines · Marc Kleine-Budde
Quoted 3 lines · Andy Shevchenko
In some configurations, mainly ACPI-based, the clock frequency of the device is supplied by very well established 'clock-frequency' property. Hence, try to get it from the property at last if no other providers are available.
Quoted 8 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2887
Quoted 6 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2
-1return dev_err_probe (&spi->dev,PTR_ERR (reg_xceiver),"Failed to get Transceiver regulator!\n" ); - clk =devm_clk_get (&spi->dev,NULL ); +/* Always ask for fixed clock rate from a property. */ +device_property_read_u32 (&spi->dev,"clock-frequency" , &rate);what about error handling....?
Not needed, but rate should be assigned to 0, which is missed.
Quoted 10 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2895
Quoted 7 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3
-0+ clk =devm_clk_get_optional (&spi->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&spi->dev,PTR_ERR (clk),"Failed to get Oscillator (clock)!\n" ); freq =clk_get_rate (clk); +if (freq ==0 ) + freq = rate;... this means we don't fail if there is neither a clk nor a clock-frequency property.
Quoted 3 lines
The following will check for it (which is already in the code)
if (freq <= MCP251XFD_SYSCLOCK_HZ_MAX / MCP251XFD_OSC_PLL_MULTIPLIER) {
Even before, actually,
/* Sanity check */
if (freq < MCP251XFD_SYSCLOCK_HZ_MIN ||
freq > MCP251XFD_SYSCLOCK_HZ_MAX) {Quoted 4 lines
Quoted 1 line
I've send a v3 to fix this.
You mean I have to send v3?
Sure!
So, I am going to send a v3 with amended commit message and assigning rate to 0.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Marc Kleine-Budde
maintainerQuoted 28 lines · Andy Shevchenko
Quoted 5 lines · Marc Kleine-Budde
Quoted 3 lines · Andy Shevchenko
In some configurations, mainly ACPI-based, the clock frequency of the device is supplied by very well established 'clock-frequency' property. Hence, try to get it from the property at last if no other providers are available.
Quoted 8 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2887
Quoted 6 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2
-1return dev_err_probe (&spi->dev,PTR_ERR (reg_xceiver),"Failed to get Transceiver regulator!\n" ); - clk =devm_clk_get (&spi->dev,NULL ); +/* Always ask for fixed clock rate from a property. */ +device_property_read_u32 (&spi->dev,"clock-frequency" , &rate);what about error handling....?
Not needed, but rate should be assigned to 0, which is missed.
Quoted 10 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2895
Quoted 7 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3
-0+ clk =devm_clk_get_optional (&spi->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&spi->dev,PTR_ERR (clk),"Failed to get Oscillator (clock)!\n" ); freq =clk_get_rate (clk); +if (freq ==0 ) + freq = rate;... this means we don't fail if there is neither a clk nor a clock-frequency property.
Quoted 3 lines
The following will check for it (which is already in the code)
if (freq <= MCP251XFD_SYSCLOCK_HZ_MAX / MCP251XFD_OSC_PLL_MULTIPLIER) {
Good point.
Quoted 4 lines
Quoted 1 line
I've send a v3 to fix this.
You mean I have to send v3?
Sure!
I have send a v3, see:
https://lore.kernel.org/r/[email protected]
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 |