Skip to contentSkip to conversation

clk: Add driver for the si544 clock generator chip

PATCH Superseded Mike Looijmans 3 participants 4 messages Mar 13, 2018 – Mar 16, 2018

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: Add driver for the si544 clock generator chip

This patch adds the driver and devicetree documentation for the Silicon Labs SI544 clock generator chip. This is an I2C controlled oscillator capable of generating clock signals ranging from 200kHz to 1500MHz.

---
 .../devicetree/bindings/clock/silabs,si544.txt     |  25 ++
 drivers/clk/Kconfig                                |  10 +
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-si544.c                            | 421 +++++++++++++++++++++
 4 files changed, 457 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/silabs,si544.txt
 create mode 100644 drivers/clk/clk-si544.c
Documentation/devicetree/bindings/clock/silabs,si544.txt new file +25 -0
new file mode 100644
index 0000000..eec1787
@@ -0,0 +1,25 @@
+Binding for Silicon Labs 544 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] Si544 datasheet
+    https://www.silabs.com/documents/public/data-sheets/si544-datasheet.pdf
+
+Required properties:
+ - compatible: One of "silabs,si514a", "silabs,si514b" "silabs,si514c" according
+               to the speed grade of the chip.
+ - 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 "si544".
+
+Example:
+	si544: clock-generator@55 {
+		reg = <0x55>;
+		#clock-cells = <0>;
+		compatible = "silabs,si544b";
+	};
drivers/clk/Kconfig +10 -0
index 98ce9fc..5c7dc8e 100644
@@ -91,6 +91,16 @@ config COMMON_CLK_SI514
 	  This driver supports the Silicon Labs 514 programmable clock
 	  generator.
 
+config COMMON_CLK_SI544
+	tristate "Clock driver for SiLabs 544 devices"
+	depends on I2C
+	depends on OF
+	select REGMAP_I2C
+	help
+	---help---
+	  This driver supports the Silicon Labs 544 programmable clock
+	  generator.
+
 config COMMON_CLK_SI570
 	tristate "Clock driver for SiLabs 570 and compatible devices"
 	depends on I2C
drivers/clk/Makefile +1 -0
index 71ec41e..bde614a 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
 obj-$(CONFIG_COMMON_CLK_SCPI)           += clk-scpi.o
 obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
 obj-$(CONFIG_COMMON_CLK_SI514)		+= clk-si514.o
+obj-$(CONFIG_COMMON_CLK_SI544)		+= clk-si544.o
 obj-$(CONFIG_COMMON_CLK_SI570)		+= clk-si570.o
 obj-$(CONFIG_ARCH_STM32)		+= clk-stm32f4.o
 obj-$(CONFIG_ARCH_STM32)		+= clk-stm32h7.o
drivers/clk/clk-si544.c new file +421 -0

421 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

Hi Mike,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v4.16-rc4]
[also build test WARNING on next-20180314]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Mike-Looijmans/clk-Add-driver-for-the-si544-clock-generator-chip/20180314-122736

smatch warnings:
drivers/clk/clk-si544.c:188 si544_calc_muldiv() warn: impossible condition '((frequency * tmp) >= 10800000000) => (0-u32max >= 10800000000)'

# https://github.com/0day-ci/linux/commit/aba3d3de8751c1457bcf0b75bcc901f289a18426
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout aba3d3de8751c1457bcf0b75bcc901f289a18426
vim +188 drivers/clk/clk-si544.c

aba3d3de Mike Looijmans 2018-03-13  168  
aba3d3de Mike Looijmans 2018-03-13  169  /* Calculate divider settings for a given frequency */
aba3d3de Mike Looijmans 2018-03-13  170  static int si544_calc_muldiv(struct clk_si544_muldiv *settings,
aba3d3de Mike Looijmans 2018-03-13  171  	unsigned long frequency)
aba3d3de Mike Looijmans 2018-03-13  172  {
aba3d3de Mike Looijmans 2018-03-13  173  	u64 vco;
aba3d3de Mike Looijmans 2018-03-13  174  	u32 ls_freq;
aba3d3de Mike Looijmans 2018-03-13  175  	u32 tmp;
aba3d3de Mike Looijmans 2018-03-13  176  	u8 res;
aba3d3de Mike Looijmans 2018-03-13  177  
aba3d3de Mike Looijmans 2018-03-13  178  	/* Determine the minimum value of LS_DIV and resulting target freq. */
aba3d3de Mike Looijmans 2018-03-13  179  	ls_freq = frequency;
aba3d3de Mike Looijmans 2018-03-13  180  	settings->ls_div_bits = 0;
aba3d3de Mike Looijmans 2018-03-13  181  
aba3d3de Mike Looijmans 2018-03-13  182  	if (frequency >= (FVCO_MIN / HS_DIV_MAX))
aba3d3de Mike Looijmans 2018-03-13  183  		settings->ls_div_bits = 0;
aba3d3de Mike Looijmans 2018-03-13  184  	else {
aba3d3de Mike Looijmans 2018-03-13  185  		res = 1;
aba3d3de Mike Looijmans 2018-03-13  186  		tmp = 2 * HS_DIV_MAX;
aba3d3de Mike Looijmans 2018-03-13  187  		while (tmp <= (HS_DIV_MAX * 32)) {
aba3d3de Mike Looijmans 2018-03-13 @188  			if ((frequency * tmp) >= FVCO_MIN)
aba3d3de Mike Looijmans 2018-03-13  189  				break;
aba3d3de Mike Looijmans 2018-03-13  190  			++res;
aba3d3de Mike Looijmans 2018-03-13  191  			tmp <<= 1;
aba3d3de Mike Looijmans 2018-03-13  192  		}
aba3d3de Mike Looijmans 2018-03-13  193  		settings->ls_div_bits = res;
aba3d3de Mike Looijmans 2018-03-13  194  		ls_freq = frequency << res;
aba3d3de Mike Looijmans 2018-03-13  195  	}
aba3d3de Mike Looijmans 2018-03-13  196  
aba3d3de Mike Looijmans 2018-03-13  197  	/* Determine minimum HS_DIV by rounding up */
aba3d3de Mike Looijmans 2018-03-13  198  	vco = FVCO_MIN + ls_freq - 1;
aba3d3de Mike Looijmans 2018-03-13  199  	do_div(vco, ls_freq);
aba3d3de Mike Looijmans 2018-03-13  200  	settings->hs_div = vco;
aba3d3de Mike Looijmans 2018-03-13  201  	/* round up to even number if needed */
aba3d3de Mike Looijmans 2018-03-13  202  	if ((settings->hs_div > HS_DIV_MAX_ODD) && (settings->hs_div & 1))
aba3d3de Mike Looijmans 2018-03-13  203  		++settings->hs_div;
aba3d3de Mike Looijmans 2018-03-13  204  	/* Calculate VCO frequency (in 10..12GHz range) */
aba3d3de Mike Looijmans 2018-03-13  205  	vco = (u64)ls_freq * settings->hs_div;
aba3d3de Mike Looijmans 2018-03-13  206  	/* Calculate the integer part of the feedback divider */
aba3d3de Mike Looijmans 2018-03-13  207  	tmp = do_div(vco, FXO);
aba3d3de Mike Looijmans 2018-03-13  208  	settings->fb_div_int = vco;
aba3d3de Mike Looijmans 2018-03-13  209  	/* And the fractional bits using the remainder */
aba3d3de Mike Looijmans 2018-03-13  210  	vco = (u64)tmp << 32;
aba3d3de Mike Looijmans 2018-03-13  211  	do_div(vco, FXO);
aba3d3de Mike Looijmans 2018-03-13  212  	settings->fb_div_frac = vco;
aba3d3de Mike Looijmans 2018-03-13  213  
aba3d3de Mike Looijmans 2018-03-13  214  	return 0;
aba3d3de Mike Looijmans 2018-03-13  215  }
aba3d3de Mike Looijmans 2018-03-13  216  

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
Quoted 7 lines · Dan Carpenter

Hi Mike,
=20
Thank you for the patch! Perhaps something to improve:
=20
[auto build test WARNING on v4.16-rc4]
[also build test WARNING on next-20180314]
[if your patch is applied to the wrong git tree, please drop us a note to=

help improve the system]

Quoted 2 lines

=20
url: https://github.com/0day-ci/linux/commits/Mike-Looijmans/clk-Add-d=

river-for-the-si544-clock-generator-chip/20180314-122736

Quoted 3 lines

=20
smatch warnings:
drivers/clk/clk-si544.c:188 si544_calc_muldiv() warn: impossible conditio=

n '((frequency * tmp) >=3D 10800000000) =3D> (0-u32max >=3D 10800000000)'

Indeed, there's a u64 cast missing.

I've also missed that the hs_div cannot be odd when ls_div is non-zero.

I'll compose a v2 patch fixing these issues.

Quoted 1 line

# https://github.com/0day-ci/linux/commit/aba3d3de8751c1457bcf0b75bcc901f=

289a18426

Quoted 7 lines

git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout aba3d3de8751c1457bcf0b75bcc901f289a18426
vim +188 drivers/clk/clk-si544.c
=20
aba3d3de Mike Looijmans 2018-03-13 168
aba3d3de Mike Looijmans 2018-03-13 169 /* Calculate divider settings fo=

r a given frequency */

Quoted 1 line

aba3d3de Mike Looijmans 2018-03-13 170 static int si544_calc_muldiv(str=

uct clk_si544_muldiv *settings,

Quoted 8 lines
aba3d3de Mike Looijmans 2018-03-13  171  	unsigned long frequency)
aba3d3de Mike Looijmans 2018-03-13  172  {
aba3d3de Mike Looijmans 2018-03-13  173  	u64 vco;
aba3d3de Mike Looijmans 2018-03-13  174  	u32 ls_freq;
aba3d3de Mike Looijmans 2018-03-13  175  	u32 tmp;
aba3d3de Mike Looijmans 2018-03-13  176  	u8 res;
aba3d3de Mike Looijmans 2018-03-13  177
aba3d3de Mike Looijmans 2018-03-13  178  	/* Determine the minimum value =

of LS_DIV and resulting target freq. */

Quoted 4 lines
aba3d3de Mike Looijmans 2018-03-13  179  	ls_freq =3D frequency;
aba3d3de Mike Looijmans 2018-03-13  180  	settings->ls_div_bits =3D 0;
aba3d3de Mike Looijmans 2018-03-13  181
aba3d3de Mike Looijmans 2018-03-13  182  	if (frequency >=3D (FVCO_MIN / =

HS_DIV_MAX))

Quoted 5 lines
aba3d3de Mike Looijmans 2018-03-13  183  		settings->ls_div_bits =3D 0;
aba3d3de Mike Looijmans 2018-03-13  184  	else {
aba3d3de Mike Looijmans 2018-03-13  185  		res =3D 1;
aba3d3de Mike Looijmans 2018-03-13  186  		tmp =3D 2 * HS_DIV_MAX;
aba3d3de Mike Looijmans 2018-03-13  187  		while (tmp <=3D (HS_DIV_MAX * =

32)) {

Quoted 1 line

aba3d3de Mike Looijmans 2018-03-13 @188 if ((frequency * tmp) >=3D FV=

CO_MIN)

Quoted 9 lines
aba3d3de Mike Looijmans 2018-03-13  189  				break;
aba3d3de Mike Looijmans 2018-03-13  190  			++res;
aba3d3de Mike Looijmans 2018-03-13  191  			tmp <<=3D 1;
aba3d3de Mike Looijmans 2018-03-13  192  		}
aba3d3de Mike Looijmans 2018-03-13  193  		settings->ls_div_bits =3D res;
aba3d3de Mike Looijmans 2018-03-13  194  		ls_freq =3D frequency << res;
aba3d3de Mike Looijmans 2018-03-13  195  	}
aba3d3de Mike Looijmans 2018-03-13  196
aba3d3de Mike Looijmans 2018-03-13  197  	/* Determine minimum HS_DIV by =

rounding up */

Quoted 4 lines
aba3d3de Mike Looijmans 2018-03-13  198  	vco =3D FVCO_MIN + ls_freq - 1;
aba3d3de Mike Looijmans 2018-03-13  199  	do_div(vco, ls_freq);
aba3d3de Mike Looijmans 2018-03-13  200  	settings->hs_div =3D vco;
aba3d3de Mike Looijmans 2018-03-13  201  	/* round up to even number if n=

eeded */

Quoted 1 line

aba3d3de Mike Looijmans 2018-03-13 202 if ((settings->hs_div > HS_DIV_=

MAX_ODD) && (settings->hs_div & 1))

Quoted 2 lines
aba3d3de Mike Looijmans 2018-03-13  203  		++settings->hs_div;
aba3d3de Mike Looijmans 2018-03-13  204  	/* Calculate VCO frequency (in =

10..12GHz range) */

Quoted 1 line

aba3d3de Mike Looijmans 2018-03-13 205 vco =3D (u64)ls_freq * settings=

->hs_div;

Quoted 1 line

aba3d3de Mike Looijmans 2018-03-13 206 /* Calculate the integer part o=

f the feedback divider */

Quoted 3 lines
aba3d3de Mike Looijmans 2018-03-13  207  	tmp =3D do_div(vco, FXO);
aba3d3de Mike Looijmans 2018-03-13  208  	settings->fb_div_int =3D vco;
aba3d3de Mike Looijmans 2018-03-13  209  	/* And the fractional bits usin=

g the remainder */

Quoted 10 lines
aba3d3de Mike Looijmans 2018-03-13  210  	vco =3D (u64)tmp << 32;
aba3d3de Mike Looijmans 2018-03-13  211  	do_div(vco, FXO);
aba3d3de Mike Looijmans 2018-03-13  212  	settings->fb_div_frac =3D vco;
aba3d3de Mike Looijmans 2018-03-13  213
aba3d3de Mike Looijmans 2018-03-13  214  	return 0;
aba3d3de Mike Looijmans 2018-03-13  215  }
aba3d3de Mike Looijmans 2018-03-13  216

=20
---
0-DAY kernel test infrastructure Open Source Technology Ce=

nter

Quoted 1 line

https://lists.01.org/pipermail/kbuild-all Intel Corpora=

tion

Quoted 1 line

=20

Kind regards,

Mike Looijmans
System Expert

TOPIC Products
Materiaalweg 4, NL-5681 RJ Best
Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
E-mail: [email protected]
Website: www.topicproducts.com

Please consider the environment before printing this e-mail

maintainer
#3 lore raw
In reply to Mike Looijmans

Quoting Mike Looijmans (2018-03-13 01:43:59)

D=

Quoted 1 line
D= renamed from Documentation/devicetree/bindings/clock/silabs,si544.txt +0 -0

ocumentation/devicetree/bindings/clock/silabs,si544.txt

Documentation/devicetree/bindings/clock/silabs,si544.txt line 4

Quoted 9 lines

new file mode 100644
index 0000000..eec1787

Documentation/devicetree/bindings/clock/silabs,si544.txt new file +4 -0
@@ -0,0 +1,25 @@
+Binding for Silicon Labs 544 programmable I2C clock generator.
+
+Reference
+This binding uses the common clock binding[1]. Details about the device =

can be

Documentation/devicetree/bindings/clock/silabs,si544.txt

Quoted 5 lines
Documentation/devicetree/bindings/clock/silabs,si544.txt new file +5 -0
+found in the datasheet[2].
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+[2] Si544 datasheet
+    https://www.silabs.com/documents/public/data-sheets/si544-datasheet.=

pdf

Can this reference stuff go to the bottom of this document?

Documentation/devicetree/bindings/clock/silabs,si544.txt

Quoted 3 lines
Documentation/devicetree/bindings/clock/silabs,si544.txt new file +3 -0
+
+Required properties:
+ - compatible: One of "silabs,si514a", "silabs,si514b" "silabs,si514c" a=

ccording

Documentation/devicetree/bindings/clock/silabs,si544.txt

Quoted 6 lines
Documentation/devicetree/bindings/clock/silabs,si544.txt new file +6 -0
+               to the speed grade of the chip.
+ - 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 "si=

544".

Documentation/devicetree/bindings/clock/silabs,si544.txt line 21

Quoted 3 lines
Documentation/devicetree/bindings/clock/silabs,si544.txt new file +3 -0
+
+Example:
+       si544: clock-generator@55 {

I'm not sure clock-generator is in the list of node names, but we have some of these already so alright.

Quoted 9 lines
Documentation/devicetree/bindings/clock/silabs,si544.txt new file +4 -0
+               reg =3D <0x55>;
+               #clock-cells =3D <0>;
+               compatible =3D "silabs,si544b";
+       };
drivers/clk/Kconfig +0 -0
index 98ce9fc..5c7dc8e 100644

drivers/clk/Kconfig config COMMON_CLK_SI514 · line 98

Quoted 8 lines
drivers/clk/Kconfig +4 -0
@@ -91,6 +91,16 @@ config COMMON_CLK_SI514
          This driver supports the Silicon Labs 514 programmable clock
          generator.
 =
 
+config COMMON_CLK_SI544
+       tristate "Clock driver for SiLabs 544 devices"
+       depends on I2C
+       depends on OF

Does it depend on anything in OF to build?

Quoted 21 lines
drivers/clk/Kconfig +6 -0
+       select REGMAP_I2C
+       help
+       ---help---
+         This driver supports the Silicon Labs 544 programmable clock
+         generator.
+
 config COMMON_CLK_SI570
        tristate "Clock driver for SiLabs 570 and compatible devices"

depends on I2C

drivers/clk/clk-si544.c new file +6 -0
new file mode 100644
index 0000000..1947e48
@@ -0,0 +1,421 @@
+/*
+ * Driver for Silicon Labs Si544 Programmable Oscillator
+ *
+ * Copyright (C) 2018 Topic Embedded Products
+ *
+ * Author: Mike Looijmans <[email protected]>

drivers/clk/clk-si544.c line 16

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.

Can we have SPDX style license here?

drivers/clk/clk-si544.c line 26

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+
+/* I2C registers (decimal as in datasheet) */

Heh.

Quoted 42 lines
drivers/clk/clk-si544.c new file +42 -0
+#define SI544_REG_CONTROL      7
+#define SI544_REG_OE_STATE     17
+#define SI544_REG_HS_DIV       23
+#define SI544_REG_LS_HS_DIV    24
+#define SI544_REG_FBDIV0       26
+#define SI544_REG_FBDIV8       27
+#define SI544_REG_FBDIV16      28
+#define SI544_REG_FBDIV24      29
+#define SI544_REG_FBDIV32      30
+#define SI544_REG_FBDIV40      31
+#define SI544_REG_FCAL_OVR     69
+#define SI544_REG_ADPLL_DELTA_M0       231
+#define SI544_REG_ADPLL_DELTA_M8       232
+#define SI544_REG_ADPLL_DELTA_M16      233
+#define SI544_REG_PAGE_SELECT  255
+
+/* Register values */
+#define SI544_CONTROL_RESET    BIT(7)
+#define SI544_CONTROL_MS_ICAL2 BIT(3)
+
+#define SI544_OE_STATE_ODC_OE  BIT(0)
+
+/* Max freq depends on speed grade */
+#define SI544_MIN_FREQ     200000U
+
+/* Si544 Internal oscilator runs at 55.05 MHz */
+#define FXO              55050000U
+
+/* VCO range is 10.8 .. 12.1 GHz, max depends on speed grade */
+#define FVCO_MIN       10800000000ULL
+
+#define HS_DIV_MAX     2046
+#define HS_DIV_MAX_ODD 33
+
+enum si544_speed_grade {
+       si544a,
+       si544b,
+       si544c,
+};
+
+struct clk_si544 {
+       struct clk_hw hw;

drivers/clk/clk-si544.c

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+       struct regmap *regmap;
+       struct i2c_client *i2c_client;
+       enum si544_speed_grade speed_grade;
+};
+#define to_clk_si544(_hw)      container_of(_hw, struct clk_si544, hw)
+
+/* Multiplier/divider settings */
+struct clk_si544_muldiv {
+       u32 fb_div_frac;  /* Integer part of feedback divider (32 bits) */
+       u16 fb_div_int;  /* Fractional part of feedback divider (11 bits)=

*/

drivers/clk/clk-si544.c line 81

Quoted 3 lines
drivers/clk/clk-si544.c new file +3 -0
+       u16 hs_div; /* 1st divider, 5..2046, must be even when >33 */
+       u8 ls_div_bits; /* 2nd divider, as 2^x, range 0..5 */
+};

Can you use kernel-doc style instead of inline comments please.

Quoted 11 lines
drivers/clk/clk-si544.c new file +11 -0
+
+static bool is_valid_frequency(const struct clk_si544 *data,
+       unsigned long frequency)
+{
+       unsigned long max_freq;
+
+       if (frequency < SI544_MIN_FREQ)
+               return false;
+
+       switch (data->speed_grade) {
+       case si544a:

drivers/clk/clk-si544.c line 160

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+               max_freq =3D 1500000000;
+               break;
+       case si544b:
+               max_freq =3D 800000000;
+               break;
+       case si544c:
+               max_freq =3D 350000000;
+               break;
+       default:
+               return false;

Drop this default case and let the compiler complain if we get a new enum to handle.

drivers/clk/clk-si544.c line 166

Quoted 6 lines
drivers/clk/clk-si544.c new file +6 -0
+       }
+
+       if (frequency > max_freq)
+               return false;
+
+       return true;

Replace with 'return frequency <=3D max_freq'?

drivers/clk/clk-si544.c

Quoted 12 lines
drivers/clk/clk-si544.c new file +12 -0
+}
+
+/* Calculate divider settings for a given frequency */
+static int si544_calc_muldiv(struct clk_si544_muldiv *settings,
+       unsigned long frequency)
+{
+       u64 vco;
+       u32 ls_freq;
+       u32 tmp;
+       u8 res;
+
+       /* Determine the minimum value of LS_DIV and resulting target fre=

q. */

drivers/clk/clk-si544.c line 124

Quoted 4 lines
drivers/clk/clk-si544.c new file +4 -0
+       ls_freq =3D frequency;
+       settings->ls_div_bits =3D 0;
+
+       if (frequency >=3D (FVCO_MIN / HS_DIV_MAX))

Maybe FVCO_MIN/HS_DIV_MAX has a name that can be defined? MIN_DIV_FREQ?

drivers/clk/clk-si544.c line 126

Quoted 2 lines
drivers/clk/clk-si544.c new file +2 -0
+               settings->ls_div_bits =3D 0;
+       else {

Style: Please add braces on the if arm too.

Quoted 8 lines
drivers/clk/clk-si544.c new file +8 -0
+               res =3D 1;
+               tmp =3D 2 * HS_DIV_MAX;
+               while (tmp <=3D (HS_DIV_MAX * 32)) {
+                       if ((frequency * tmp) >=3D FVCO_MIN)
+                               break;
+                       ++res;
+                       tmp <<=3D 1;
+               }

drivers/clk/clk-si544.c line 202

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+               settings->ls_div_bits =3D res;
+               ls_freq =3D frequency << res;
+       }
+
+       /* Determine minimum HS_DIV by rounding up */
+       vco =3D FVCO_MIN + ls_freq - 1;
+       do_div(vco, ls_freq);
+       settings->hs_div =3D vco;
+       /* round up to even number if needed */
+       if ((settings->hs_div > HS_DIV_MAX_ODD) && (settings->hs_div & 1))

Drop useless parenthesis please.

drivers/clk/clk-si544.c

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+               ++settings->hs_div;
+       /* Calculate VCO frequency (in 10..12GHz range) */
+       vco =3D (u64)ls_freq * settings->hs_div;
+       /* Calculate the integer part of the feedback divider */
+       tmp =3D do_div(vco, FXO);
+       settings->fb_div_int =3D vco;
+       /* And the fractional bits using the remainder */
+       vco =3D (u64)tmp << 32;
+       do_div(vco, FXO);
+       settings->fb_div_frac =3D vco;

This is all packed together. Please add a newline before each comment to make it easier to read.

drivers/clk/clk-si544.c

Quoted 13 lines
drivers/clk/clk-si544.c new file +13 -0
+
+       return 0;
+}
+
+/* Calculate resulting frequency given the register settings */
+static unsigned long si544_calc_rate(struct clk_si544_muldiv *settings)
+{
+       u32 d =3D settings->hs_div * BIT(settings->ls_div_bits);
+       u64 vco;
+
+       /* Calculate VCO while preventing overflow */
+       vco =3D (u64)settings->fb_div_int * FXO;
+       vco +=3D (((u64)settings->fb_div_frac * FXO) + (FXO / 2)) >> 32;

Yay for the smatch checking stuff on the list! Try to put things on more lines to keep stuff easier to follow.

Quoted 6 lines
drivers/clk/clk-si544.c new file +6 -0
+
+       do_div(vco, d);
+
+       return vco;
+}
+

drivers/clk/clk-si544.c

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+static unsigned long si544_recalc_rate(struct clk_hw *hw,
+               unsigned long parent_rate)
+{
+       struct clk_si544 *data =3D to_clk_si544(hw);
+       struct clk_si544_muldiv settings;
+       int err;
+
+       err =3D si544_get_muldiv(data, &settings);
+       if (err) {
+               dev_err(&data->i2c_client->dev, "unable to retrieve setti=

ngs\n");

This error message could become quite spammy given that we typically call recalc_rate() many times.

Quoted 5 lines
drivers/clk/clk-si544.c new file +5 -0
+               return 0;
+       }
+
+       return si544_calc_rate(&settings);
+}

drivers/clk/clk-si544.c line 256

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+
+static long si544_round_rate(struct clk_hw *hw, unsigned long rate,
+               unsigned long *parent_rate)
+{
+       struct clk_si544 *data =3D to_clk_si544(hw);
+       struct clk_si544_muldiv settings;
+       int err;
+
+       if (!rate)
+               return 0;

Why? Do certain drivers call round_rate() with 0 and we want to ignore those cases and not return an error?

Quoted 12 lines
drivers/clk/clk-si544.c new file +12 -0
+
+       if (!is_valid_frequency(data, rate))
+               return -EINVAL;
+
+       err =3D si544_calc_muldiv(&settings, rate);
+       if (err)
+               return err;
+
+       return si544_calc_rate(&settings);
+}
+
+

[...]

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+
+static int si544_probe(struct i2c_client *client,
+               const struct i2c_device_id *id)
+{
+       struct clk_si544 *data;
+       struct clk_init_data init;
+       int err;
+
+       data =3D devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+       if (!data)

drivers/clk/clk-si544.c

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+               return -ENOMEM;
+
+       init.ops =3D &si544_clk_ops;
+       init.flags =3D 0;
+       init.num_parents =3D 0;
+       data->hw.init =3D &init;
+       data->i2c_client =3D client;
+       data->speed_grade =3D id->driver_data;
+
+       if (of_property_read_string(client->dev.of_node, "clock-output-na=

mes",

drivers/clk/clk-si544.c

Quoted 4 lines
drivers/clk/clk-si544.c new file +4 -0
+                       &init.name))
+               init.name =3D client->dev.of_node->name;
+
+       data->regmap =3D devm_regmap_init_i2c(client, &si544_regmap_confi=

g);

drivers/clk/clk-si544.c

Quoted 2 lines
drivers/clk/clk-si544.c new file +2 -0
+       if (IS_ERR(data->regmap)) {
+               dev_err(&client->dev, "failed to allocate register map\n"=

);

Do we need another allocation failure message?

Quoted 6 lines
drivers/clk/clk-si544.c new file +6 -0
+               return PTR_ERR(data->regmap);
+       }
+
+       i2c_set_clientdata(client, data);
+
+       /* Select page 0, just to be sure, there appear to be no more */

drivers/clk/clk-si544.c

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+       err =3D regmap_write(data->regmap, SI544_REG_PAGE_SELECT, 0);
+       if (err < 0)
+               return err;
+
+       err =3D devm_clk_hw_register(&client->dev, &data->hw);
+       if (err) {
+               dev_err(&client->dev, "clock registration failed\n");
+               return err;
+       }
+       err =3D of_clk_add_hw_provider(client->dev.of_node, of_clk_hw_sim=

ple_get,

devm_of_clk_add_hw_provider()?

Quoted 4 lines
drivers/clk/clk-si544.c new file +4 -0
+                                    &data->hw);
+       if (err) {
+               dev_err(&client->dev, "unable to add clk provider\n");
+               return err;

drivers/clk/clk-si544.c line 390

Quoted 10 lines
drivers/clk/clk-si544.c new file +10 -0
+       }
+
+       return 0;
+}
+
+static int si544_remove(struct i2c_client *client)
+{
+       of_clk_del_provider(client->dev.of_node);
+       return 0;
+}

Drop?