Add driver for the si514 clock generator chip
Subsystems (2)
PATCH 1/1 Add driver for the si514 clock generator chip
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscilator capable of generating clock signals ranging from 100kHz to 250MHz.
--- .../devicetree/bindings/clock/silabs,si514.txt | 27 ++ drivers/clk/Kconfig | 10 + drivers/clk/Makefile | 1 + drivers/clk/clk-si514.c | 393 +++++++++++++++++++++ 4 files changed, 431 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/silabs,si514.txt create mode 100644 drivers/clk/clk-si514.c
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +27 -0
@@ -0,0 +1,27 @@ +Binding for Silicon Labs 514 programmable I2C clock generator. + +Reference +This binding uses the common clock binding[1]. Details about the device can be +found in the datasheet[2]. + +[1] Documentation/devicetree/bindings/clock/clock-bindings.txt +[2] Si514 datasheet + http://www.silabs.com/Support%20Documents/TechnicalDocs/si514.pdf + +Required properties: + - compatible: Shall be "silabs,si514" + - reg: I2C device address. + - #clock-cells: From common clock bindings: Shall be 0. + +Optional properties: + - clock-output-names: From common clock bindings. Recommended to be "si514". + - clock-frequency: Output frequency to generate. This defines the output + frequency set during boot. It can be reprogrammed during + runtime through the common clock framework. + +Example: + si514: clock-generator@55 { + reg = <0x55>; + #clock-cells = <0>; + compatible = "silabs,si514"; + };
drivers/clk/Kconfig +10 -0
@@ -68,6 +68,16 @@ config COMMON_CLK_SI5351 This driver supports Silicon Labs 5351A/B/C programmable clock generators. +config COMMON_CLK_SI514 + tristate "Clock driver for SiLabs 514 devices" + depends on I2C + depends on OF + select REGMAP_I2C + help + ---help--- + This driver supports the Silicon Labs 514 programmable clock + generator. + config COMMON_CLK_SI570 tristate "Clock driver for SiLabs 570 and compatible devices" depends on I2C
drivers/clk/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o +obj-$(CONFIG_COMMON_CLK_SI514) += clk-si514.o obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
drivers/clk/clk-si514.c new file +393 -0
393 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 1/1 Add driver for the si514 clock generator chip
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscilator capable of generating clock signals ranging from 100kHz to 250MHz.
---
v2: Fix e-mail address list (using old maintainer list, sorry).
Rebase on master.
.../devicetree/bindings/clock/silabs,si514.txt | 27 ++ drivers/clk/Kconfig | 10 + drivers/clk/Makefile | 1 + drivers/clk/clk-si514.c | 393 +++++++++++++++++++++ 4 files changed, 431 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/silabs,si514.txt create mode 100644 drivers/clk/clk-si514.c
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +27 -0
@@ -0,0 +1,27 @@ +Binding for Silicon Labs 514 programmable I2C clock generator. + +Reference +This binding uses the common clock binding[1]. Details about the device can be +found in the datasheet[2]. + +[1] Documentation/devicetree/bindings/clock/clock-bindings.txt +[2] Si514 datasheet + http://www.silabs.com/Support%20Documents/TechnicalDocs/si514.pdf + +Required properties: + - compatible: Shall be "silabs,si514" + - reg: I2C device address. + - #clock-cells: From common clock bindings: Shall be 0. + +Optional properties: + - clock-output-names: From common clock bindings. Recommended to be "si514". + - clock-frequency: Output frequency to generate. This defines the output + frequency set during boot. It can be reprogrammed during + runtime through the common clock framework. + +Example: + si514: clock-generator@55 { + reg = <0x55>; + #clock-cells = <0>; + compatible = "silabs,si514"; + };
drivers/clk/Kconfig +10 -0
@@ -68,6 +68,16 @@ config COMMON_CLK_SI5351 This driver supports Silicon Labs 5351A/B/C programmable clock generators. +config COMMON_CLK_SI514 + tristate "Clock driver for SiLabs 514 devices" + depends on I2C + depends on OF + select REGMAP_I2C + help + ---help--- + This driver supports the Silicon Labs 514 programmable clock + generator. + config COMMON_CLK_SI570 tristate "Clock driver for SiLabs 570 and compatible devices" depends on I2C
drivers/clk/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o +obj-$(CONFIG_COMMON_CLK_SI514) += clk-si514.o obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o obj-$(CONFIG_ARCH_STM32) += clk-stm32f4.o
drivers/clk/clk-si514.c new file +393 -0
393 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 3 lines · Mike Looijmans
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscilator capable of generating clock signals ranging from 100kHz
s/oscilator/oscillator/
Quoted 20 lines
to 250MHz.
Signed-off-by Mike Looijmans <[email protected]>---
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +10
-0@@ -0,0 +1,27 @@ +Binding for Silicon Labs 514 programmable I2C clock generator. + +Reference +This binding uses the common clock binding[1]. Details about the device can be +found in the datasheet[2]. + +[1] Documentation/devicetree/bindings/clock/clock-bindings.txt +[2] Si514 datasheet + http://www.silabs.com/Support%20Documents/TechnicalDocs/si514.pdf +
Documentation/devicetree/bindings/clock/silabs,si514.txt line 20
Quoted 10 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +10
-0+Required properties: + - compatible: Shall be "silabs,si514" + - reg: I2C device address. + - #clock-cells: From common clock bindings: Shall be 0. + +Optional properties: + - clock-output-names: From common clock bindings. Recommended to be "si514". + - clock-frequency: Output frequency to generate. This defines the output + frequency set during boot. It can be reprogrammed during + runtime through the common clock framework.
Can we use assigned clock rates instead of this property?
Quoted 12 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +7
-0+ +Example: + si514: clock-generator@55 { + reg = <0x55>; + #clock-cells = <0>; + compatible = "silabs,si514"; + };drivers/clk/Kconfig +0
-0
drivers/clk/Kconfig config COMMON_CLK_SI5351 · line 74
Quoted 7 lines
drivers/clk/Kconfig +4
-0@@ -68,6 +68,16 @@ config COMMON_CLK_SI5351 This driver supports Silicon Labs 5351A/B/C programmable clock generators. +config COMMON_CLK_SI514 + tristate "Clock driver for SiLabs 514 devices" + depends on I2C + depends on OF
It actually depends on this to build?
Quoted 15 lines
drivers/clk/Kconfig +6
-0+ select REGMAP_I2C + help + ---help--- + This driver supports the Silicon Labs 514 programmable clock + generator. + config COMMON_CLK_SI570 tristate "Clock driver for SiLabs 570 and compatible devices" depends on I2Cdrivers/clk/clk-si514.c new file +0
-0
drivers/clk/clk-si514.c line 2
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0@@ -0,0 +1,393 @@ + +#include <linux/clk-provider.h>
I'd expect some sort of linux/clk.h include here if we're using clk APIs.
Quoted 5 lines
drivers/clk/clk-si514.c new file +5
-0+#include <linux/delay.h> +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/regmap.h> +#include <linux/slab.h>
[...]
drivers/clk/clk-si514.c
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0+ +/* Program clock settings into hardware */
This comment is useless.
Quoted 14 lines
drivers/clk/clk-si514.c new file +14
-0+static int si514_set_muldiv (struct clk_si514 *data, +struct clk_si514_muldiv *settings) +{ +u8 lp; +u8 reg[7 ]; +int err; + +/* Calculate LP1/LP2 according to table 13 in the datasheet */ +/* 65.259980246 */ +if ((settings->m_int <65 ) || + ((settings->m_int ==65 ) && (settings->m_frac <=139575831 ))) + lp =0x22 ; +/* 67.859763463 */ + else if ((settings->m_int < 67) ||
drivers/clk/clk-si514.c line 124
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+ ((settings->m_int == 67) && (settings->m_frac <= 461581994))) + lp =0x23 ; +/* 72.937624981 */ + else if ((settings->m_int < 72) || + ((settings->m_int == 72) && (settings->m_frac <= 503383578))) + lp =0x33 ; +/* 75.843265046 */ + else if ((settings->m_int < 75) || + ((settings->m_int == 75) && (settings->m_frac <= 452724474))) + lp =0x34 ;
Drop the extra parenthesis on these if statements.
Quoted 5 lines
drivers/clk/clk-si514.c new file +5
-0+else + lp =0x44 ; + + err =regmap_write (data->regmap,SI514_REG_LP , lp); +if (err <0 )
drivers/clk/clk-si514.c line 139
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return err; + + reg[0 ] = settings->m_frac &0xff ; + reg[1 ] = (settings->m_frac >>8 ) &0xff ; + reg[2 ] = (settings->m_frac >>16 ) &0xff ; + reg[3 ] = ((settings->m_frac >>24 ) | (settings->m_int <<5 )) &0xff ; + reg[4 ] = (settings->m_int >>3 ) &0xff ; + reg[5 ] = (settings->hs_div) &0xff ; + reg[6 ] = (((settings->hs_div) >>8 ) | + (settings->ls_div_bits <<4 )) &0xff ;
The & 0xff part is redundant. Assignment truncates for us.
drivers/clk/clk-si514.c line 145
Quoted 6 lines
drivers/clk/clk-si514.c new file +6
-0+ + err =regmap_bulk_write (data->regmap,SI514_REG_HS_DIV , reg +5 ,2 ); +if (err <0 ) +return err; +/* Writing to SI514_REG_M_INT_FRAC triggers the clock change, so that +* must be written last */
Please fix multi-line commenting style.
Quoted 13 lines
drivers/clk/clk-si514.c new file +13
-0+return regmap_bulk_write (data->regmap,SI514_REG_M_FRAC1 , reg,5 ); +} + +/* Calculate divider settings for a given frequency */ +static int si514_calc_muldiv (struct clk_si514_muldiv *settings, +unsigned long frequency) +{ +u64 m; +u32 ls_freq; +u32 tmp; +u8 res; + +if ((frequency <SI514_MIN_FREQ ) || (frequency >SI514_MAX_FREQ ))
drivers/clk/clk-si514.c line 168
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return -EINVAL ; + +/* Determine the minimum value of LS_DIV and resulting target freq. */ + ls_freq = frequency; +if (frequency >= (FVCO_MIN /HS_DIV_MAX )) + settings->ls_div_bits =0 ; +else { + res =1 ; + tmp =2 *HS_DIV_MAX ; +while (tmp <= (HS_DIV_MAX *32 )) {
Please add some space here between HS_DIV_MAX and 32.
drivers/clk/clk-si514.c line 170
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0+if ((frequency * tmp) >=FVCO_MIN ) +break ;/* We're done */
Yep, that's what break in a loop usually means.
Quoted 15 lines
drivers/clk/clk-si514.c new file +15
-0+ ++res; + tmp <<=1 ; + } + settings->ls_div_bits = res; + ls_freq = frequency << res; + } + +/* Determine minimum HS_DIV, round up to even number */ + settings->hs_div =DIV_ROUND_UP (FVCO_MIN >>1 , ls_freq) <<1 ; + +/* M = LS_DIV x HS_DIV x frequency / F_XO (in fixed-point) */ + m = ((u64)(ls_freq * settings->hs_div) <<29 ) + (FXO /2 ); +do_div (m,FXO ); + settings->m_frac = (u32 )m & (BIT (29 ) -1 ); + settings->m_int = (u32)(m >>29 );
drivers/clk/clk-si514.c line 195
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+ +return 0 ; +} + +/* Calculate resulting frequency given the register settings */ +static unsigned long si514_calc_rate (struct clk_si514_muldiv *settings) +{ +u64 m = settings->m_frac | ((u64 )settings->m_int <<29 ); + + return ((u32)(((m * FXO) + (FXO/2)) >> 29)) /
Please add space after /
drivers/clk/clk-si514.c line 196
Quoted 1 line
drivers/clk/clk-si514.c new file +1
-0+ (settings->hs_div *BIT (settings->ls_div_bits));
And drop the extra parenthesis. It would be nice if we didn't do it all in one line too. Use some local variables.
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0+} +
[...]
drivers/clk/clk-si514.c line 233
Quoted 11 lines
drivers/clk/clk-si514.c new file +11
-0+ + err =si514_calc_muldiv (&settings, rate); +if (err) +return err; + +return si514_calc_rate (&settings); +} + +/* Update output frequency for big frequency changes (> 1000 ppm). +* The chip supports <1000ppm changes "on the fly", we haven't implemented +* that here. */
Please fix comment style.
Quoted 15 lines
drivers/clk/clk-si514.c new file +15
-0+static int si514_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct clk_si514 *data =to_clk_si514 (hw); +struct clk_si514_muldiv settings; +int err; + + err =si514_calc_muldiv (&settings, rate); +if (err) +return err; + +si514_enable_output (data, false); + + err =si514_set_muldiv (data, &settings); +if (err <0 )
drivers/clk/clk-si514.c line 258
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return err;/* Undefined state now, best to leave disabled */ + +/* Trigger calibration */ + err =regmap_write (data->regmap,SI514_REG_CONTROL ,SI514_CONTROL_FCAL ); + +/* Applying a new frequency can take up to 10ms */ +usleep_range (10000 ,12000 ); + +si514_enable_output (data, true); +
Should we enable if regmap_write() failed?
drivers/clk/clk-si514.c line 293
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return err; +} + +static const struct clk_ops si514_clk_ops = { + .recalc_rate = si514_recalc_rate, + .round_rate = si514_round_rate, + .set_rate = si514_set_rate, +}; + +static struct regmap_config si514_regmap_config = {
const?
drivers/clk/clk-si514.c line 357
Quoted 6 lines
drivers/clk/clk-si514.c new file +6
-0+ } + } + +/* Display a message indicating that we've successfully registered */ +dev_info (&client->dev,"registered, current frequency %lu Hz\n" , +clk_get_rate (clk));
Please remove this.
Quoted 4 lines
drivers/clk/clk-si514.c new file +4
-0+ +return 0 ; +} +
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 5 lines · Stephen Boyd
Quoted 3 lines · Mike Looijmans
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscilator capable of generating clock signals ranging from 100kHz
Quoted 7 lines
s/oscilator/oscillator/
=
Quoted 5 lines
to 250MHz.
Signed-off-by Mike Looijmans <[email protected]>---
= renamed from Documentation/devicetree/bindings/clock/silabs,si514.txt +0
-0
Documentation/devicetree/bindings/clock/silabs,si514.txt
Quoted 9 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt line 4
Quoted 9 lines
new file mode 100644
index 0000000..05964d1Documentation/devicetree/bindings/clock/silabs,si514.txt new file +4
-0@@ -0,0 +1,27 @@ +Binding for Silicon Labs 514 programmable I2C clock generator. + +Reference +This binding uses the common clock binding[1]. Details about the device=
can be
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +5
-0+found in the datasheet[2]. + +[1] Documentation/devicetree/bindings/clock/clock-bindings.txt +[2] Si514 datasheet + http://www.silabs.com/Support%20Documents/TechnicalDocs/si514.pdf
Quoted 8 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt
Quoted 8 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +8
-0+ +Required properties: + - compatible: Shall be "silabs,si514" + - reg: I2C device address. + - #clock-cells: From common clock bindings: Shall be 0. + +Optional properties: + - clock-output-names: From common clock bindings. Recommended to be "s=
i514".
Quoted 1 line
Documentation/devicetree/bindings/clock/silabs,si514.txt line 18
Quoted 1 line
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +1
-0+ - clock-frequency: Output frequency to generate. This defines the outp=
ut
Quoted 4 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt line 20
Quoted 2 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +2
-0+ frequency set during boot. It can be reprogrammed during + runtime through the common clock framework.Can we use assigned clock rates instead of this property?
I'll first need to learn what 'assigned clock rates' means. But I suspect t= he=20
answer will be yes.
Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +7
-0+ +Example: + si514: clock-generator@55 { + reg =3D <0x55>; + #clock-cells =3D <0>; + compatible =3D "silabs,si514"; + };drivers/clk/Kconfig +0
-0@@ -68,6 +68,16 @@ config COMMON_CLK_SI5351 This driver supports Silicon Labs 5351A/B/C programmable clock generators.
Quoted 6 lines
drivers/clk/Kconfig config COMMON_CLK_SI5351 · line 74
Quoted 4 lines
drivers/clk/Kconfig +4
-0+config COMMON_CLK_SI514 + tristate "Clock driver for SiLabs 514 devices" + depends on I2C + depends on OFIt actually depends on this to build?
It calls various 'of_' methods unconditionally, so I'd think so.
Quoted 12 lines
Quoted 12 lines
drivers/clk/Kconfig +6
-0+ select REGMAP_I2C + help + ---help--- + This driver supports the Silicon Labs 514 programmable clock + generator. + config COMMON_CLK_SI570 tristate "Clock driver for SiLabs 570 and compatible devices" depends on I2Cdrivers/clk/clk-si514.c new file +0
-0
Quoted 8 lines
drivers/clk/clk-si514.c line 2
Quoted 5 lines
drivers/clk/clk-si514.c new file +2
-0@@ -0,0 +1,393 @@ + +#include <linux/clk-provider.h> I'd expect some sort of
linux/clk.hinclude here if we're using clk APIs.
It probably got dragged in by the clk-provider.h include, including it=20 specifically would be more appropriate.
Quoted 125 lines
Quoted 6 lines
drivers/clk/clk-si514.c new file +5
-0+#include <linux/delay.h> +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/regmap.h> +#include <linux/slab.h> [...]
drivers/clk/clk-si514.c
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0+ +/* Program clock settings into hardware */ This comment is useless.
Quoted 14 lines
drivers/clk/clk-si514.c new file +14
-0+static int si514_set_muldiv (struct clk_si514 *data, +struct clk_si514_muldiv *settings) +{ +u8 lp; +u8 reg[7 ]; +int err; + +/* Calculate LP1/LP2 according to table 13 in the datasheet */ +/* 65.259980246 */ +if ((settings->m_int <65 ) || + ((settings->m_int =3D=3D 65) && (settings->m_frac <=3D 139575831))) + lp =3D 0x22; +/* 67.859763463 */ + else if ((settings->m_int < 67) ||drivers/clk/clk-si514.c
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+ ((settings->m_int =3D=3D 67) && (settings->m_frac <=3D 461581994))) + lp =3D 0x23; +/* 72.937624981 */ + else if ((settings->m_int < 72) || + ((settings->m_int =3D=3D 72) && (settings->m_frac <=3D 503383578))) + lp =3D 0x33; +/* 75.843265046 */ + else if ((settings->m_int < 75) || + ((settings->m_int =3D=3D 75) && (settings->m_frac <=3D 452724474))) + lp =3D 0x34;Drop the extra parenthesis on these if statements.
Quoted 5 lines
drivers/clk/clk-si514.c new file +5
-0+else + lp =3D 0x44; + + err =3D regmap_write(data->regmap, SI514_REG_LP, lp); +if (err <0 )drivers/clk/clk-si514.c
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return err; + + reg[0] =3D settings->m_frac & 0xff; + reg[1 ] =3D (settings->m_frac >>8 ) &0xff ; + reg[2 ] =3D (settings->m_frac >>16 ) &0xff ; + reg[3 ] =3D ((settings->m_frac >>24 ) | (settings->m_int <<5 )) &0xff ; + reg[4 ] =3D (settings->m_int >>3 ) &0xff ; + reg[5 ] =3D (settings->hs_div) &0xff ; + reg[6 ] =3D (((settings->hs_div) >>8 ) | + (settings->ls_div_bits <<4 )) &0xff ;The &
0xffpart is redundant. Assignment truncates for us.drivers/clk/clk-si514.c line 145
Quoted 6 lines
drivers/clk/clk-si514.c new file +6
-0+ + err =3D regmap_bulk_write(data->regmap, SI514_REG_HS_DIV, reg + 5, 2); +if (err <0 ) +return err; +/* Writing to SI514_REG_M_INT_FRAC triggers the clock change, so that +* must be written last */ Please fix multi-line commenting style.
Quoted 13 lines
drivers/clk/clk-si514.c new file +13
-0+return regmap_bulk_write (data->regmap,SI514_REG_M_FRAC1 , reg,5 ); +} + +/* Calculate divider settings for a given frequency */ +static int si514_calc_muldiv (struct clk_si514_muldiv *settings, +unsigned long frequency) +{ +u64 m; +u32 ls_freq; +u32 tmp; +u8 res; + +if ((frequency <SI514_MIN_FREQ ) || (frequency >SI514_MAX_FREQ ))drivers/clk/clk-si514.c
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return -EINVAL ; + +/* Determine the minimum value of LS_DIV and resulting target freq. */ + ls_freq =3D frequency; +if (frequency >=3D (FVCO_MIN /HS_DIV_MAX )) + settings->ls_div_bits =3D 0; +else { + res =3D 1; + tmp =3D 2 * HS_DIV_MAX; +while (tmp <=3D (HS_DIV_MAX *32 )) {Please add some space here between
HS_DIV_MAXand 32.drivers/clk/clk-si514.c
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0+ if ((frequency * tmp) >=3D FVCO_MIN) +break ;/* We're done */ Yep, that's what break in a loop usually means.
Quoted 15 lines
drivers/clk/clk-si514.c new file +15
-0+ ++res; + tmp <<=3D 1; + } + settings->ls_div_bits =3D res; + ls_freq =3D frequency << res; + } + +/* Determine minimum HS_DIV, round up to even number */ + settings->hs_div =3D DIV_ROUND_UP(FVCO_MIN >> 1, ls_freq) << 1; + +/* M =3D LS_DIV x HS_DIV x frequency / F_XO (in fixed-point) */ + m =3D ((u64)(ls_freq * settings->hs_div) <<29 ) + (FXO /2 ); +do_div (m,FXO ); + settings->m_frac =3D (u32)m & (BIT(29) - 1); + settings->m_int =3D (u32)(m >>29 );drivers/clk/clk-si514.c line 195
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+ +return 0 ; +} + +/* Calculate resulting frequency given the register settings */ +static unsigned long si514_calc_rate (struct clk_si514_muldiv *settings) +{ + u64 m =3D settings->m_frac | ((u64)settings->m_int << 29); + + return ((u32)(((m * FXO) + (FXO/2)) >> 29)) /Please add space after /
Quoted 4 lines
drivers/clk/clk-si514.c line 196
Quoted 1 line
drivers/clk/clk-si514.c new file +1
-0+ (settings->hs_div *BIT (settings->ls_div_bits));And drop the extra parenthesis. It would be nice if we didn't do it all in one line too. Use some local variables.
I'll refactor it into something more readable.
Quoted 13 lines
Quoted 2 lines
drivers/clk/clk-si514.c new file +2
-0+} +[...]
drivers/clk/clk-si514.c
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+ + err =3D si514_calc_muldiv(&settings, rate); +if (err) +return err; + +return si514_calc_rate (&settings); +} + +/* Update output frequency for big frequency changes (> 1000 ppm). +* The chip supports <1000ppm changes "on the fly", we haven't implemen=
ted
Quoted 15 lines
Quoted 1 line
+ * that here. */
Please fix comment style.
Quoted 11 lines
drivers/clk/clk-si514.c new file +11
-0+static int si514_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ + struct clk_si514 *data =3D to_clk_si514(hw); +struct clk_si514_muldiv settings; +int err; + + err =3D si514_calc_muldiv(&settings, rate); +if (err) +return err; +
Quoted 8 lines
drivers/clk/clk-si514.c
Quoted 8 lines
drivers/clk/clk-si514.c new file +8
-0+si514_enable_output (data, false); + + err =3D si514_set_muldiv(data, &settings); +if (err <0 ) +return err;/* Undefined state now, best to leave disabled */ + +/* Trigger calibration */ + err =3D regmap_write(data->regmap, SI514_REG_CONTROL, SI514_CONTROL_FC=
AL);
Quoted 8 lines
drivers/clk/clk-si514.c line 258
Quoted 6 lines
drivers/clk/clk-si514.c new file +6
-0+ +/* Applying a new frequency can take up to 10ms */ +usleep_range (10000 ,12000 ); + +si514_enable_output (data, true); +Should we enable if
regmap_write()failed?
Good question, I don't recall why I made this choice.
For a client, when set_rate returns error, it would expect either the clock= =20
still running at the old frequency, or not running at all. From that=20 perspective, since the PLL has been reprogrammed, the better choice would b= e=20
to leave it disabled. Expected behaviour for the client is going to be to f= ix=20
the I2C bus problems and try again.
Quoted 22 lines
drivers/clk/clk-si514.c
Quoted 10 lines
drivers/clk/clk-si514.c new file +10
-0+return err; +} + +static const struct clk_ops si514_clk_ops =3D { + .recalc_rate =3D si514_recalc_rate, + .round_rate =3D si514_round_rate, + .set_rate =3D si514_set_rate, +}; + +static struct regmap_config si514_regmap_config =3D {const?
drivers/clk/clk-si514.c line 357
Quoted 6 lines
drivers/clk/clk-si514.c new file +6
-0+ } + } + +/* Display a message indicating that we've successfully registered */ +dev_info (&client->dev,"registered, current frequency %lu Hz\n" , +clk_get_rate (clk));Please remove this.
Quoted 5 lines
drivers/clk/clk-si514.c line 99
Quoted 4 lines
drivers/clk/clk-si514.c new file +4
-0+ +return 0 ; +} +
I'll post a v2 patch with the requested changes soon. Thank you for your re= view.
Mike.
Kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products
Eindhovenseweg 32-C, NL-5683 KH Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
Telefax: +31 (0) 499 33 69 70
E-mail: [email protected]
Website: www.topicproducts.com
Please consider the environment before printing this e-mail
PATCH v3 1/1 Add driver for the si514 clock generator chip
In reply to Stephen BoydThis patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscillator capable of generating clock signals ranging from 100kHz to 250MHz.
---
v3: After review from Stephen Boyd
Removed "clock-frequency" DT property Do not enable output if PLL calibration failed Fix parenthesis, multiline comments, spacing
.../devicetree/bindings/clock/silabs,si514.txt | 24 ++ drivers/clk/Kconfig | 10 + drivers/clk/Makefile | 1 + drivers/clk/clk-si514.c | 383 +++++++++++++++++++++ 4 files changed, 418 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/silabs,si514.txt create mode 100644 drivers/clk/clk-si514.c
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +24 -0
@@ -0,0 +1,24 @@ +Binding for Silicon Labs 514 programmable I2C clock generator. + +Reference +This binding uses the common clock binding[1]. Details about the device can be +found in the datasheet[2]. + +[1] Documentation/devicetree/bindings/clock/clock-bindings.txt +[2] Si514 datasheet + http://www.silabs.com/Support%20Documents/TechnicalDocs/si514.pdf + +Required properties: + - compatible: Shall be "silabs,si514" + - reg: I2C device address. + - #clock-cells: From common clock bindings: Shall be 0. + +Optional properties: + - clock-output-names: From common clock bindings. Recommended to be "si514". + +Example: + si514: clock-generator@55 { + reg = <0x55>; + #clock-cells = <0>; + compatible = "silabs,si514"; + };
drivers/clk/Kconfig +10 -0
@@ -68,6 +68,16 @@ config COMMON_CLK_SI5351 This driver supports Silicon Labs 5351A/B/C programmable clock generators. +config COMMON_CLK_SI514 + tristate "Clock driver for SiLabs 514 devices" + depends on I2C + depends on OF + select REGMAP_I2C + help + ---help--- + This driver supports the Silicon Labs 514 programmable clock + generator. + config COMMON_CLK_SI570 tristate "Clock driver for SiLabs 570 and compatible devices" depends on I2C
drivers/clk/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_CLK_QORIQ) += clk-qoriq.o obj-$(CONFIG_COMMON_CLK_RK808) += clk-rk808.o obj-$(CONFIG_COMMON_CLK_S2MPS11) += clk-s2mps11.o obj-$(CONFIG_COMMON_CLK_SI5351) += clk-si5351.o +obj-$(CONFIG_COMMON_CLK_SI514) += clk-si514.o obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o obj-$(CONFIG_COMMON_CLK_CDCE925) += clk-cdce925.o obj-$(CONFIG_ARCH_STM32) += clk-stm32f4.o
drivers/clk/clk-si514.c new file +383 -0
383 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 10 lines · Mike Looijmans
Quoted 6 lines · Stephen Boyd
Documentation/devicetree/bindings/clock/silabs,si514.txt line 20
Quoted 4 lines
+ - clock-output-names: From common clock bindings. Recommended to be "si514".
+ - clock-frequency: Output frequency to generate. This defines the outputDocumentation/devicetree/bindings/clock/silabs,si514.txt new file +2
-0+ frequency set during boot. It can be reprogrammed during + runtime through the common clock framework.Can we use assigned clock rates instead of this property?
I'll first need to learn what 'assigned clock rates' means. But I suspect the answer will be yes.
See the "Assigned clock parents and rates" section of Documentation/devicetree/bindings/clock/clock-bindings.txt and commit 86be408bfbd8 (clk: Support for clock parents and rates assigned from device tree, 2014-06-18).
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/clock/silabs,si514.txt new file +7
-0+ +Example: + si514: clock-generator@55 { + reg = <0x55>; + #clock-cells = <0>; + compatible = "silabs,si514"; + };drivers/clk/Kconfig +0
-0@@ -68,6 +68,16 @@ config COMMON_CLK_SI5351 This driver supports Silicon Labs 5351A/B/C programmable clock generators.
Quoted 8 lines
Quoted 6 lines
drivers/clk/Kconfig config COMMON_CLK_SI5351 · line 74
Quoted 4 lines
drivers/clk/Kconfig +4
-0+config COMMON_CLK_SI514 + tristate "Clock driver for SiLabs 514 devices" + depends on I2C + depends on OFIt actually depends on this to build?
It calls various '
of_' methods unconditionally, so I'd think so.
Aren't there stubs for those if CONFIG_OF=n?
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Stephen Boyd
AppliedQuoted 7 lines · Mike Looijmans
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscillator capable of generating clock signals ranging from 100kHz to 250MHz.
Signed-off-by Mike Looijmans <[email protected]>---
Applied to clk-next. We can handle any stuff about assigned rates in a follow up patch.
Also, I squashed in this for some cleanup.
drivers/clk/clk-si514.c +5 -9
@@ -16,7 +16,6 @@* GNU General Public License for more details. */ -#include <linux/clk.h> #include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/module.h>
@@ -87,14 +86,11 @@ static int si514_get_muldiv(struct clk_si514 *data,if (err)return err; - settings->m_frac = - reg[0 ] | - ((u32 )reg[1 ] <<8 ) | - ((u32 )reg[2 ] <<16 ) | - ((u32)(reg[3 ] &0x1F ) <<24 ); - settings->m_int = ((reg[4 ] &0x3f ) <<3 ) | (reg[3 ] >>5 ); + settings->m_frac = reg[0 ] | reg[1 ] <<8 | reg[2 ] <<16 | + (reg[3 ] &0x1F ) <<24 ; + settings->m_int = (reg[4 ] &0x3f ) <<3 | reg[3 ] >>5 ; settings->ls_div_bits = (reg[6 ] >>4 ) &0x07 ; - settings->hs_div = ((u16)(reg[6 ] &0x03 ) <<8 ) | reg[5 ]; + settings->hs_div = (reg[6 ] &0x03 ) <<8 | reg[5 ];return 0 ; }
@@ -132,7 +128,7 @@ static int si514_set_muldiv(struct clk_si514 *data, reg[0 ] = settings->m_frac; reg[1 ] = settings->m_frac >>8 ; reg[2 ] = settings->m_frac >>16 ; - reg[3 ] = (settings->m_frac >>24 ) | (settings->m_int <<5 ); + reg[3 ] = settings->m_frac >>24 | settings->m_int <<5 ; reg[4 ] = settings->m_int >>3 ; reg[5 ] = settings->hs_div; reg[6 ] = (settings->hs_div >>8 ) | (settings->ls_div_bits <<4 );
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 19 lines · Stephen Boyd
Quoted 7 lines · Mike Looijmans
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscillator capable of generating clock signals ranging from 100kHz to 250MHz.
Signed-off-by Mike Looijmans <[email protected]>---
Applied to clk-next. We can handle any stuff about assigned rates in a follow up patch.
Also, I squashed in this for some cleanup.
drivers/clk/clk-si514.c +0
-0
drivers/clk/clk-si514.c line 19
Quoted 4 lines
drivers/clk/clk-si514.c +0
-1@@ -16,7 +16,6 @@* GNU General Public License for more details. */ -#include <linux/clk.h>
Interesting - I only added this include because of your comment:
"I'd expect some sort of linux/clk.h include here if we're using clk APIs."
Could you elaborate on that, I'm confused now...
Mike.
Kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
Telefax: +31 (0) 499 33 69 70
E-mail: [email protected]
Website: www.topicproducts.com
Please consider the environment before printing this e-mail
Quoted 23 lines · Mike Looijmans
Quoted 22 lines · Stephen Boyd
Quoted 7 lines · Mike Looijmans
This patch adds the driver and devicetree documentation for the Silicon Labs SI514 clock generator chip. This is an I2C controlled oscillator capable of generating clock signals ranging from 100kHz to 250MHz.
Signed-off-by Mike Looijmans <[email protected]>---
Applied to clk-next. We can handle any stuff about assigned rates in a follow up patch.
Also, I squashed in this for some cleanup.
drivers/clk/clk-si514.c +0
-0@@ -16,7 +16,6 @@* GNU General Public License for more details. */
Quoted 8 lines
drivers/clk/clk-si514.c line 19
Quoted 1 line
drivers/clk/clk-si514.c +0
-1-#include <linux/clk.h> Interesting - I only added this include because of your comment:
"I'd expect some sort oflinux/clk.hinclude here if we're using clk APIs."Could you elaborate on that, I'm confused now...
The driver is only using the clk provider APIs that are in clk-provider.h, because you removed the part that was calling clk_set_rate() (which is a clk consumer API). So before that change we would have needed the clk.h include, but now it compiles fine without it.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project