Merge branches 'clk-baikal', 'clk-broadcom', 'clk-vc5' and 'clk-versaclock' into clk-next

- Convert Baikal-T1 CCU driver to platform driver
- Split reset support out of primary Baikal-T1 CCU driver
- Add some missing clks required for RPiVid Video Decoder on RaspberryPi
- Mark PLLC critical on bcm2835
- Support for Renesas VersaClock7 clock generator family

* clk-baikal:
clk: baikal-t1: Convert to platform device driver
clk: baikal-t1: Add DDR/PCIe directly controlled resets support
dt-bindings: clk: baikal-t1: Add DDR/PCIe reset IDs
clk: baikal-t1: Move reset-controls code into a dedicated module
clk: baikal-t1: Add SATA internal ref clock buffer
clk: baikal-t1: Add shared xGMAC ref/ptp clocks internal parent
clk: baikal-t1: Fix invalid xGMAC PTP clock divider
clk: vc5: Fix 5P49V6901 outputs disabling when enabling FOD

* clk-broadcom:
clk: bcm: rpi: Add support for VEC clock
clk: bcm: rpi: Handle pixel clock in firmware
clk: bcm: rpi: Add support HEVC clock
clk: bcm2835: fix bcm2835_clock_rate_from_divisor declaration
clk: bcm2835: Round UART input clock up
clk: bcm2835: Make peripheral PLLC critical

* clk-vc5:
clk: vc5: Add support for IDT/Renesas VersaClock 5P49V6975
dt-bindings: clock: vc5: Add 5P49V6975
clk: vc5: Use regmap_{set,clear}_bits() where appropriate
clk: vc5: Check IO access results

* clk-versaclock:
clk: Renesas versaclock7 ccf device driver
dt-bindings: Renesas versaclock7 device tree bindings

+2182 -224
+2
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml
··· 56 - idt,5p49v5935 57 - idt,5p49v6901 58 - idt,5p49v6965 59 60 reg: 61 description: I2C device address ··· 135 enum: 136 - idt,5p49v5933 137 - idt,5p49v5935 138 then: 139 # Devices with builtin crystal + optional external input 140 properties:
··· 56 - idt,5p49v5935 57 - idt,5p49v6901 58 - idt,5p49v6965 59 + - idt,5p49v6975 60 61 reg: 62 description: I2C device address ··· 134 enum: 135 - idt,5p49v5933 136 - idt,5p49v5935 137 + - idt,5p49v6975 138 then: 139 # Devices with builtin crystal + optional external input 140 properties:
+64
Documentation/devicetree/bindings/clock/renesas,versaclock7.yaml
···
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/clock/renesas,versaclock7.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Renesas Versaclock7 Programmable Clock Device Tree Bindings 8 + 9 + maintainers: 10 + - Alex Helms <alexander.helms.jy@renesas.com> 11 + 12 + description: | 13 + Renesas Versaclock7 is a family of configurable clock generator and 14 + jitter attenuator ICs with fractional and integer dividers. 15 + 16 + properties: 17 + '#clock-cells': 18 + const: 1 19 + 20 + compatible: 21 + enum: 22 + - renesas,rc21008a 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + clocks: 28 + items: 29 + - description: External crystal or oscillator 30 + 31 + clock-names: 32 + items: 33 + - const: xin 34 + 35 + required: 36 + - '#clock-cells' 37 + - compatible 38 + - reg 39 + - clocks 40 + - clock-names 41 + 42 + additionalProperties: false 43 + 44 + examples: 45 + - | 46 + vc7_xin: clock { 47 + compatible = "fixed-clock"; 48 + #clock-cells = <0>; 49 + clock-frequency = <49152000>; 50 + }; 51 + 52 + i2c@0 { 53 + reg = <0x0 0x100>; 54 + #address-cells = <1>; 55 + #size-cells = <0>; 56 + 57 + vc7: clock-controller@9 { 58 + compatible = "renesas,rc21008a"; 59 + reg = <0x9>; 60 + #clock-cells = <1>; 61 + clocks = <&vc7_xin>; 62 + clock-names = "xin"; 63 + }; 64 + };
+6
MAINTAINERS
··· 17442 F: Documentation/devicetree/bindings/mtd/renesas-nandc.yaml 17443 F: drivers/mtd/nand/raw/renesas-nand-controller.c 17444 17445 RESET CONTROLLER FRAMEWORK 17446 M: Philipp Zabel <p.zabel@pengutronix.de> 17447 S: Maintained
··· 17442 F: Documentation/devicetree/bindings/mtd/renesas-nandc.yaml 17443 F: drivers/mtd/nand/raw/renesas-nand-controller.c 17444 17445 + RENESAS VERSACLOCK 7 CLOCK DRIVER 17446 + M: Alex Helms <alexander.helms.jy@renesas.com> 17447 + S: Maintained 17448 + F: Documentation/devicetree/bindings/clock/renesas,versaclock7.yaml 17449 + F: drivers/clk/clk-versaclock7.c 17450 + 17451 RESET CONTROLLER FRAMEWORK 17452 M: Philipp Zabel <p.zabel@pengutronix.de> 17453 S: Maintained
+9
drivers/clk/Kconfig
··· 377 This driver supports the IDT VersaClock 5 and VersaClock 6 378 programmable clock generators. 379 380 config COMMON_CLK_STM32MP135 381 def_bool COMMON_CLK && MACH_STM32MP13 382 help
··· 377 This driver supports the IDT VersaClock 5 and VersaClock 6 378 programmable clock generators. 379 380 + config COMMON_CLK_VC7 381 + tristate "Clock driver for Renesas Versaclock 7 devices" 382 + depends on I2C 383 + depends on OF 384 + select REGMAP_I2C 385 + help 386 + Renesas Versaclock7 is a family of configurable clock generator 387 + and jitter attenuator ICs with fractional and integer dividers. 388 + 389 config COMMON_CLK_STM32MP135 390 def_bool COMMON_CLK && MACH_STM32MP13 391 help
+1
drivers/clk/Makefile
··· 73 obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o 74 obj-$(CONFIG_COMMON_CLK_RS9_PCIE) += clk-renesas-pcie.o 75 obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o 76 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o 77 obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o 78
··· 73 obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o 74 obj-$(CONFIG_COMMON_CLK_RS9_PCIE) += clk-renesas-pcie.o 75 obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o 76 + obj-$(CONFIG_COMMON_CLK_VC7) += clk-versaclock7.o 77 obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o 78 obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o 79
+11 -1
drivers/clk/baikal-t1/Kconfig
··· 29 30 config CLK_BT1_CCU_DIV 31 bool "Baikal-T1 CCU Dividers support" 32 - select RESET_CONTROLLER 33 select MFD_SYSCON 34 default MIPS_BAIKAL_T1 35 help ··· 37 SoC. CCU dividers can be either configurable or with fixed divider, 38 either gateable or ungateable. Some of the CCU dividers can be as well 39 used to reset the domains they're supplying clock to. 40 41 endif
··· 29 30 config CLK_BT1_CCU_DIV 31 bool "Baikal-T1 CCU Dividers support" 32 select MFD_SYSCON 33 default MIPS_BAIKAL_T1 34 help ··· 38 SoC. CCU dividers can be either configurable or with fixed divider, 39 either gateable or ungateable. Some of the CCU dividers can be as well 40 used to reset the domains they're supplying clock to. 41 + 42 + config CLK_BT1_CCU_RST 43 + bool "Baikal-T1 CCU Resets support" 44 + select RESET_CONTROLLER 45 + select MFD_SYSCON 46 + default MIPS_BAIKAL_T1 47 + help 48 + Enable this to support the CCU reset blocks responsible for the 49 + AXI-bus and some subsystems reset. These are mainly the 50 + self-deasserted reset controls but there are several lines which 51 + can be directly asserted/de-asserted (PCIe and DDR sub-domains). 52 53 endif
+1
drivers/clk/baikal-t1/Makefile
··· 1 # SPDX-License-Identifier: GPL-2.0-only 2 obj-$(CONFIG_CLK_BT1_CCU_PLL) += ccu-pll.o clk-ccu-pll.o 3 obj-$(CONFIG_CLK_BT1_CCU_DIV) += ccu-div.o clk-ccu-div.o
··· 1 # SPDX-License-Identifier: GPL-2.0-only 2 obj-$(CONFIG_CLK_BT1_CCU_PLL) += ccu-pll.o clk-ccu-pll.o 3 obj-$(CONFIG_CLK_BT1_CCU_DIV) += ccu-div.o clk-ccu-div.o 4 + obj-$(CONFIG_CLK_BT1_CCU_RST) += ccu-rst.o
+65 -19
drivers/clk/baikal-t1/ccu-div.c
··· 34 #define CCU_DIV_CTL_CLKDIV_MASK(_width) \ 35 GENMASK((_width) + CCU_DIV_CTL_CLKDIV_FLD - 1, CCU_DIV_CTL_CLKDIV_FLD) 36 #define CCU_DIV_CTL_LOCK_SHIFTED BIT(27) 37 #define CCU_DIV_CTL_LOCK_NORMAL BIT(31) 38 39 - #define CCU_DIV_RST_DELAY_US 1 40 #define CCU_DIV_LOCK_CHECK_RETRIES 50 41 42 #define CCU_DIV_CLKDIV_MIN 0 ··· 170 return !!(val & CCU_DIV_CTL_EN); 171 } 172 173 static unsigned long ccu_div_var_recalc_rate(struct clk_hw *hw, 174 unsigned long parent_rate) 175 { ··· 322 return 0; 323 } 324 325 - int ccu_div_reset_domain(struct ccu_div *div) 326 - { 327 - unsigned long flags; 328 - 329 - if (!div || !(div->features & CCU_DIV_RESET_DOMAIN)) 330 - return -EINVAL; 331 - 332 - spin_lock_irqsave(&div->lock, flags); 333 - regmap_update_bits(div->sys_regs, div->reg_ctl, 334 - CCU_DIV_CTL_RST, CCU_DIV_CTL_RST); 335 - spin_unlock_irqrestore(&div->lock, flags); 336 - 337 - /* The next delay must be enough to cover all the resets. */ 338 - udelay(CCU_DIV_RST_DELAY_US); 339 - 340 - return 0; 341 - } 342 - 343 #ifdef CONFIG_DEBUG_FS 344 345 struct ccu_div_dbgfs_bit { ··· 339 CCU_DIV_DBGFS_BIT_ATTR("div_en", CCU_DIV_CTL_EN), 340 CCU_DIV_DBGFS_BIT_ATTR("div_rst", CCU_DIV_CTL_RST), 341 CCU_DIV_DBGFS_BIT_ATTR("div_bypass", CCU_DIV_CTL_SET_CLKDIV), 342 CCU_DIV_DBGFS_BIT_ATTR("div_lock", CCU_DIV_CTL_LOCK_NORMAL) 343 }; 344 ··· 458 continue; 459 } 460 461 bits[didx] = ccu_div_bits[bidx]; 462 bits[didx].div = div; 463 ··· 497 &ccu_div_dbgfs_fixed_clkdiv_fops); 498 } 499 500 static void ccu_div_fixed_debug_init(struct clk_hw *hw, struct dentry *dentry) 501 { 502 struct ccu_div *div = to_ccu_div(hw); ··· 524 525 #define ccu_div_var_debug_init NULL 526 #define ccu_div_gate_debug_init NULL 527 #define ccu_div_fixed_debug_init NULL 528 529 #endif /* !CONFIG_DEBUG_FS */ ··· 554 .round_rate = ccu_div_fixed_round_rate, 555 .set_rate = ccu_div_fixed_set_rate, 556 .debug_init = ccu_div_gate_debug_init 557 }; 558 559 static const struct clk_ops ccu_div_fixed_ops = { ··· 609 } else if (div_init->type == CCU_DIV_GATE) { 610 hw_init.ops = &ccu_div_gate_ops; 611 div->divider = div_init->divider; 612 } else if (div_init->type == CCU_DIV_FIXED) { 613 hw_init.ops = &ccu_div_fixed_ops; 614 div->divider = div_init->divider; ··· 624 goto err_free_div; 625 } 626 parent_data.fw_name = div_init->parent_name; 627 hw_init.parent_data = &parent_data; 628 hw_init.num_parents = 1; 629
··· 34 #define CCU_DIV_CTL_CLKDIV_MASK(_width) \ 35 GENMASK((_width) + CCU_DIV_CTL_CLKDIV_FLD - 1, CCU_DIV_CTL_CLKDIV_FLD) 36 #define CCU_DIV_CTL_LOCK_SHIFTED BIT(27) 37 + #define CCU_DIV_CTL_GATE_REF_BUF BIT(28) 38 #define CCU_DIV_CTL_LOCK_NORMAL BIT(31) 39 40 #define CCU_DIV_LOCK_CHECK_RETRIES 50 41 42 #define CCU_DIV_CLKDIV_MIN 0 ··· 170 return !!(val & CCU_DIV_CTL_EN); 171 } 172 173 + static int ccu_div_buf_enable(struct clk_hw *hw) 174 + { 175 + struct ccu_div *div = to_ccu_div(hw); 176 + unsigned long flags; 177 + 178 + spin_lock_irqsave(&div->lock, flags); 179 + regmap_update_bits(div->sys_regs, div->reg_ctl, 180 + CCU_DIV_CTL_GATE_REF_BUF, 0); 181 + spin_unlock_irqrestore(&div->lock, flags); 182 + 183 + return 0; 184 + } 185 + 186 + static void ccu_div_buf_disable(struct clk_hw *hw) 187 + { 188 + struct ccu_div *div = to_ccu_div(hw); 189 + unsigned long flags; 190 + 191 + spin_lock_irqsave(&div->lock, flags); 192 + regmap_update_bits(div->sys_regs, div->reg_ctl, 193 + CCU_DIV_CTL_GATE_REF_BUF, CCU_DIV_CTL_GATE_REF_BUF); 194 + spin_unlock_irqrestore(&div->lock, flags); 195 + } 196 + 197 + static int ccu_div_buf_is_enabled(struct clk_hw *hw) 198 + { 199 + struct ccu_div *div = to_ccu_div(hw); 200 + u32 val = 0; 201 + 202 + regmap_read(div->sys_regs, div->reg_ctl, &val); 203 + 204 + return !(val & CCU_DIV_CTL_GATE_REF_BUF); 205 + } 206 + 207 static unsigned long ccu_div_var_recalc_rate(struct clk_hw *hw, 208 unsigned long parent_rate) 209 { ··· 288 return 0; 289 } 290 291 #ifdef CONFIG_DEBUG_FS 292 293 struct ccu_div_dbgfs_bit { ··· 323 CCU_DIV_DBGFS_BIT_ATTR("div_en", CCU_DIV_CTL_EN), 324 CCU_DIV_DBGFS_BIT_ATTR("div_rst", CCU_DIV_CTL_RST), 325 CCU_DIV_DBGFS_BIT_ATTR("div_bypass", CCU_DIV_CTL_SET_CLKDIV), 326 + CCU_DIV_DBGFS_BIT_ATTR("div_buf", CCU_DIV_CTL_GATE_REF_BUF), 327 CCU_DIV_DBGFS_BIT_ATTR("div_lock", CCU_DIV_CTL_LOCK_NORMAL) 328 }; 329 ··· 441 continue; 442 } 443 444 + if (!strcmp("div_buf", name)) 445 + continue; 446 + 447 bits[didx] = ccu_div_bits[bidx]; 448 bits[didx].div = div; 449 ··· 477 &ccu_div_dbgfs_fixed_clkdiv_fops); 478 } 479 480 + static void ccu_div_buf_debug_init(struct clk_hw *hw, struct dentry *dentry) 481 + { 482 + struct ccu_div *div = to_ccu_div(hw); 483 + struct ccu_div_dbgfs_bit *bit; 484 + 485 + bit = kmalloc(sizeof(*bit), GFP_KERNEL); 486 + if (!bit) 487 + return; 488 + 489 + *bit = ccu_div_bits[3]; 490 + bit->div = div; 491 + debugfs_create_file_unsafe(bit->name, ccu_div_dbgfs_mode, dentry, bit, 492 + &ccu_div_dbgfs_bit_fops); 493 + } 494 + 495 static void ccu_div_fixed_debug_init(struct clk_hw *hw, struct dentry *dentry) 496 { 497 struct ccu_div *div = to_ccu_div(hw); ··· 489 490 #define ccu_div_var_debug_init NULL 491 #define ccu_div_gate_debug_init NULL 492 + #define ccu_div_buf_debug_init NULL 493 #define ccu_div_fixed_debug_init NULL 494 495 #endif /* !CONFIG_DEBUG_FS */ ··· 518 .round_rate = ccu_div_fixed_round_rate, 519 .set_rate = ccu_div_fixed_set_rate, 520 .debug_init = ccu_div_gate_debug_init 521 + }; 522 + 523 + static const struct clk_ops ccu_div_buf_ops = { 524 + .enable = ccu_div_buf_enable, 525 + .disable = ccu_div_buf_disable, 526 + .is_enabled = ccu_div_buf_is_enabled, 527 + .debug_init = ccu_div_buf_debug_init 528 }; 529 530 static const struct clk_ops ccu_div_fixed_ops = { ··· 566 } else if (div_init->type == CCU_DIV_GATE) { 567 hw_init.ops = &ccu_div_gate_ops; 568 div->divider = div_init->divider; 569 + } else if (div_init->type == CCU_DIV_BUF) { 570 + hw_init.ops = &ccu_div_buf_ops; 571 } else if (div_init->type == CCU_DIV_FIXED) { 572 hw_init.ops = &ccu_div_fixed_ops; 573 div->divider = div_init->divider; ··· 579 goto err_free_div; 580 } 581 parent_data.fw_name = div_init->parent_name; 582 + parent_data.name = div_init->parent_name; 583 hw_init.parent_data = &parent_data; 584 hw_init.num_parents = 1; 585
+14 -3
drivers/clk/baikal-t1/ccu-div.h
··· 14 #include <linux/of.h> 15 16 /* 17 * CCU Divider private flags 18 * @CCU_DIV_SKIP_ONE: Due to some reason divider can't be set to 1. 19 * It can be 0 though, which is functionally the same. 20 * @CCU_DIV_SKIP_ONE_TO_THREE: For some reason divider can't be within [1,3]. 21 * It can be either 0 or greater than 3. 22 * @CCU_DIV_LOCK_SHIFTED: Find lock-bit at non-standard position. 23 - * @CCU_DIV_RESET_DOMAIN: Provide reset clock domain method. 24 */ 25 #define CCU_DIV_SKIP_ONE BIT(1) 26 #define CCU_DIV_SKIP_ONE_TO_THREE BIT(2) 27 #define CCU_DIV_LOCK_SHIFTED BIT(3) ··· 42 * enum ccu_div_type - CCU Divider types 43 * @CCU_DIV_VAR: Clocks gate with variable divider. 44 * @CCU_DIV_GATE: Clocks gate with fixed divider. 45 * @CCU_DIV_FIXED: Ungateable clock with fixed divider. 46 */ 47 enum ccu_div_type { 48 CCU_DIV_VAR, 49 CCU_DIV_GATE, 50 CCU_DIV_FIXED 51 }; 52 ··· 117 struct ccu_div *ccu_div_hw_register(const struct ccu_div_init_data *init); 118 119 void ccu_div_hw_unregister(struct ccu_div *div); 120 - 121 - int ccu_div_reset_domain(struct ccu_div *div); 122 123 #endif /* __CLK_BT1_CCU_DIV_H__ */
··· 14 #include <linux/of.h> 15 16 /* 17 + * CCU Divider private clock IDs 18 + * @CCU_SYS_SATA_CLK: CCU SATA internal clock 19 + * @CCU_SYS_XGMAC_CLK: CCU XGMAC internal clock 20 + */ 21 + #define CCU_SYS_SATA_CLK -1 22 + #define CCU_SYS_XGMAC_CLK -2 23 + 24 + /* 25 * CCU Divider private flags 26 + * @CCU_DIV_BASIC: Basic divider clock required by the kernel as early as 27 + * possible. 28 * @CCU_DIV_SKIP_ONE: Due to some reason divider can't be set to 1. 29 * It can be 0 though, which is functionally the same. 30 * @CCU_DIV_SKIP_ONE_TO_THREE: For some reason divider can't be within [1,3]. 31 * It can be either 0 or greater than 3. 32 * @CCU_DIV_LOCK_SHIFTED: Find lock-bit at non-standard position. 33 + * @CCU_DIV_RESET_DOMAIN: There is a clock domain reset handle. 34 */ 35 + #define CCU_DIV_BASIC BIT(0) 36 #define CCU_DIV_SKIP_ONE BIT(1) 37 #define CCU_DIV_SKIP_ONE_TO_THREE BIT(2) 38 #define CCU_DIV_LOCK_SHIFTED BIT(3) ··· 31 * enum ccu_div_type - CCU Divider types 32 * @CCU_DIV_VAR: Clocks gate with variable divider. 33 * @CCU_DIV_GATE: Clocks gate with fixed divider. 34 + * @CCU_DIV_BUF: Clock gate with no divider. 35 * @CCU_DIV_FIXED: Ungateable clock with fixed divider. 36 */ 37 enum ccu_div_type { 38 CCU_DIV_VAR, 39 CCU_DIV_GATE, 40 + CCU_DIV_BUF, 41 CCU_DIV_FIXED 42 }; 43 ··· 104 struct ccu_div *ccu_div_hw_register(const struct ccu_div_init_data *init); 105 106 void ccu_div_hw_unregister(struct ccu_div *div); 107 108 #endif /* __CLK_BT1_CCU_DIV_H__ */
+8
drivers/clk/baikal-t1/ccu-pll.h
··· 14 #include <linux/of.h> 15 16 /* 17 * struct ccu_pll_init_data - CCU PLL initialization data 18 * @id: Clock private identifier. 19 * @name: Clocks name. ··· 28 * @sys_regs: Baikal-T1 System Controller registers map. 29 * @np: Pointer to the node describing the CCU PLLs. 30 * @flags: PLL clock flags. 31 */ 32 struct ccu_pll_init_data { 33 unsigned int id; ··· 38 struct regmap *sys_regs; 39 struct device_node *np; 40 unsigned long flags; 41 }; 42 43 /*
··· 14 #include <linux/of.h> 15 16 /* 17 + * CCU PLL private flags 18 + * @CCU_PLL_BASIC: Basic PLL required by the kernel as early as possible. 19 + */ 20 + #define CCU_PLL_BASIC BIT(0) 21 + 22 + /* 23 * struct ccu_pll_init_data - CCU PLL initialization data 24 * @id: Clock private identifier. 25 * @name: Clocks name. ··· 22 * @sys_regs: Baikal-T1 System Controller registers map. 23 * @np: Pointer to the node describing the CCU PLLs. 24 * @flags: PLL clock flags. 25 + * @features: PLL private features. 26 */ 27 struct ccu_pll_init_data { 28 unsigned int id; ··· 31 struct regmap *sys_regs; 32 struct device_node *np; 33 unsigned long flags; 34 + unsigned long features; 35 }; 36 37 /*
+217
drivers/clk/baikal-t1/ccu-rst.c
···
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC 4 + * 5 + * Authors: 6 + * Serge Semin <Sergey.Semin@baikalelectronics.ru> 7 + * 8 + * Baikal-T1 CCU Resets interface driver 9 + */ 10 + 11 + #define pr_fmt(fmt) "bt1-ccu-rst: " fmt 12 + 13 + #include <linux/bits.h> 14 + #include <linux/delay.h> 15 + #include <linux/kernel.h> 16 + #include <linux/of.h> 17 + #include <linux/printk.h> 18 + #include <linux/regmap.h> 19 + #include <linux/reset-controller.h> 20 + #include <linux/slab.h> 21 + 22 + #include <dt-bindings/reset/bt1-ccu.h> 23 + 24 + #include "ccu-rst.h" 25 + 26 + #define CCU_AXI_MAIN_BASE 0x030 27 + #define CCU_AXI_DDR_BASE 0x034 28 + #define CCU_AXI_SATA_BASE 0x038 29 + #define CCU_AXI_GMAC0_BASE 0x03C 30 + #define CCU_AXI_GMAC1_BASE 0x040 31 + #define CCU_AXI_XGMAC_BASE 0x044 32 + #define CCU_AXI_PCIE_M_BASE 0x048 33 + #define CCU_AXI_PCIE_S_BASE 0x04C 34 + #define CCU_AXI_USB_BASE 0x050 35 + #define CCU_AXI_HWA_BASE 0x054 36 + #define CCU_AXI_SRAM_BASE 0x058 37 + 38 + #define CCU_SYS_DDR_BASE 0x02c 39 + #define CCU_SYS_SATA_REF_BASE 0x060 40 + #define CCU_SYS_APB_BASE 0x064 41 + #define CCU_SYS_PCIE_BASE 0x144 42 + 43 + #define CCU_RST_DELAY_US 1 44 + 45 + #define CCU_RST_TRIG(_base, _ofs) \ 46 + { \ 47 + .type = CCU_RST_TRIG, \ 48 + .base = _base, \ 49 + .mask = BIT(_ofs), \ 50 + } 51 + 52 + #define CCU_RST_DIR(_base, _ofs) \ 53 + { \ 54 + .type = CCU_RST_DIR, \ 55 + .base = _base, \ 56 + .mask = BIT(_ofs), \ 57 + } 58 + 59 + struct ccu_rst_info { 60 + enum ccu_rst_type type; 61 + unsigned int base; 62 + unsigned int mask; 63 + }; 64 + 65 + /* 66 + * Each AXI-bus clock divider is equipped with the corresponding clock-consumer 67 + * domain reset (it's self-deasserted reset control). 68 + */ 69 + static const struct ccu_rst_info axi_rst_info[] = { 70 + [CCU_AXI_MAIN_RST] = CCU_RST_TRIG(CCU_AXI_MAIN_BASE, 1), 71 + [CCU_AXI_DDR_RST] = CCU_RST_TRIG(CCU_AXI_DDR_BASE, 1), 72 + [CCU_AXI_SATA_RST] = CCU_RST_TRIG(CCU_AXI_SATA_BASE, 1), 73 + [CCU_AXI_GMAC0_RST] = CCU_RST_TRIG(CCU_AXI_GMAC0_BASE, 1), 74 + [CCU_AXI_GMAC1_RST] = CCU_RST_TRIG(CCU_AXI_GMAC1_BASE, 1), 75 + [CCU_AXI_XGMAC_RST] = CCU_RST_TRIG(CCU_AXI_XGMAC_BASE, 1), 76 + [CCU_AXI_PCIE_M_RST] = CCU_RST_TRIG(CCU_AXI_PCIE_M_BASE, 1), 77 + [CCU_AXI_PCIE_S_RST] = CCU_RST_TRIG(CCU_AXI_PCIE_S_BASE, 1), 78 + [CCU_AXI_USB_RST] = CCU_RST_TRIG(CCU_AXI_USB_BASE, 1), 79 + [CCU_AXI_HWA_RST] = CCU_RST_TRIG(CCU_AXI_HWA_BASE, 1), 80 + [CCU_AXI_SRAM_RST] = CCU_RST_TRIG(CCU_AXI_SRAM_BASE, 1), 81 + }; 82 + 83 + /* 84 + * SATA reference clock domain and APB-bus domain are connected with the 85 + * sefl-deasserted reset control, which can be activated via the corresponding 86 + * clock divider register. DDR and PCIe sub-domains can be reset with directly 87 + * controlled reset signals. Resetting the DDR controller though won't end up 88 + * well while the Linux kernel is working. 89 + */ 90 + static const struct ccu_rst_info sys_rst_info[] = { 91 + [CCU_SYS_SATA_REF_RST] = CCU_RST_TRIG(CCU_SYS_SATA_REF_BASE, 1), 92 + [CCU_SYS_APB_RST] = CCU_RST_TRIG(CCU_SYS_APB_BASE, 1), 93 + [CCU_SYS_DDR_FULL_RST] = CCU_RST_DIR(CCU_SYS_DDR_BASE, 1), 94 + [CCU_SYS_DDR_INIT_RST] = CCU_RST_DIR(CCU_SYS_DDR_BASE, 2), 95 + [CCU_SYS_PCIE_PCS_PHY_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 0), 96 + [CCU_SYS_PCIE_PIPE0_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 4), 97 + [CCU_SYS_PCIE_CORE_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 8), 98 + [CCU_SYS_PCIE_PWR_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 9), 99 + [CCU_SYS_PCIE_STICKY_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 10), 100 + [CCU_SYS_PCIE_NSTICKY_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 11), 101 + [CCU_SYS_PCIE_HOT_RST] = CCU_RST_DIR(CCU_SYS_PCIE_BASE, 12), 102 + }; 103 + 104 + static int ccu_rst_reset(struct reset_controller_dev *rcdev, unsigned long idx) 105 + { 106 + struct ccu_rst *rst = to_ccu_rst(rcdev); 107 + const struct ccu_rst_info *info = &rst->rsts_info[idx]; 108 + 109 + if (info->type != CCU_RST_TRIG) 110 + return -EOPNOTSUPP; 111 + 112 + regmap_update_bits(rst->sys_regs, info->base, info->mask, info->mask); 113 + 114 + /* The next delay must be enough to cover all the resets. */ 115 + udelay(CCU_RST_DELAY_US); 116 + 117 + return 0; 118 + } 119 + 120 + static int ccu_rst_set(struct reset_controller_dev *rcdev, 121 + unsigned long idx, bool high) 122 + { 123 + struct ccu_rst *rst = to_ccu_rst(rcdev); 124 + const struct ccu_rst_info *info = &rst->rsts_info[idx]; 125 + 126 + if (info->type != CCU_RST_DIR) 127 + return high ? -EOPNOTSUPP : 0; 128 + 129 + return regmap_update_bits(rst->sys_regs, info->base, 130 + info->mask, high ? info->mask : 0); 131 + } 132 + 133 + static int ccu_rst_assert(struct reset_controller_dev *rcdev, 134 + unsigned long idx) 135 + { 136 + return ccu_rst_set(rcdev, idx, true); 137 + } 138 + 139 + static int ccu_rst_deassert(struct reset_controller_dev *rcdev, 140 + unsigned long idx) 141 + { 142 + return ccu_rst_set(rcdev, idx, false); 143 + } 144 + 145 + static int ccu_rst_status(struct reset_controller_dev *rcdev, 146 + unsigned long idx) 147 + { 148 + struct ccu_rst *rst = to_ccu_rst(rcdev); 149 + const struct ccu_rst_info *info = &rst->rsts_info[idx]; 150 + u32 val; 151 + 152 + if (info->type != CCU_RST_DIR) 153 + return -EOPNOTSUPP; 154 + 155 + regmap_read(rst->sys_regs, info->base, &val); 156 + 157 + return !!(val & info->mask); 158 + } 159 + 160 + static const struct reset_control_ops ccu_rst_ops = { 161 + .reset = ccu_rst_reset, 162 + .assert = ccu_rst_assert, 163 + .deassert = ccu_rst_deassert, 164 + .status = ccu_rst_status, 165 + }; 166 + 167 + struct ccu_rst *ccu_rst_hw_register(const struct ccu_rst_init_data *rst_init) 168 + { 169 + struct ccu_rst *rst; 170 + int ret; 171 + 172 + if (!rst_init) 173 + return ERR_PTR(-EINVAL); 174 + 175 + rst = kzalloc(sizeof(*rst), GFP_KERNEL); 176 + if (!rst) 177 + return ERR_PTR(-ENOMEM); 178 + 179 + rst->sys_regs = rst_init->sys_regs; 180 + if (of_device_is_compatible(rst_init->np, "baikal,bt1-ccu-axi")) { 181 + rst->rcdev.nr_resets = ARRAY_SIZE(axi_rst_info); 182 + rst->rsts_info = axi_rst_info; 183 + } else if (of_device_is_compatible(rst_init->np, "baikal,bt1-ccu-sys")) { 184 + rst->rcdev.nr_resets = ARRAY_SIZE(sys_rst_info); 185 + rst->rsts_info = sys_rst_info; 186 + } else { 187 + pr_err("Incompatible DT node '%s' specified\n", 188 + of_node_full_name(rst_init->np)); 189 + ret = -EINVAL; 190 + goto err_kfree_rst; 191 + } 192 + 193 + rst->rcdev.owner = THIS_MODULE; 194 + rst->rcdev.ops = &ccu_rst_ops; 195 + rst->rcdev.of_node = rst_init->np; 196 + 197 + ret = reset_controller_register(&rst->rcdev); 198 + if (ret) { 199 + pr_err("Couldn't register '%s' reset controller\n", 200 + of_node_full_name(rst_init->np)); 201 + goto err_kfree_rst; 202 + } 203 + 204 + return rst; 205 + 206 + err_kfree_rst: 207 + kfree(rst); 208 + 209 + return ERR_PTR(ret); 210 + } 211 + 212 + void ccu_rst_hw_unregister(struct ccu_rst *rst) 213 + { 214 + reset_controller_unregister(&rst->rcdev); 215 + 216 + kfree(rst); 217 + }
+67
drivers/clk/baikal-t1/ccu-rst.h
···
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2021 BAIKAL ELECTRONICS, JSC 4 + * 5 + * Baikal-T1 CCU Resets interface driver 6 + */ 7 + #ifndef __CLK_BT1_CCU_RST_H__ 8 + #define __CLK_BT1_CCU_RST_H__ 9 + 10 + #include <linux/of.h> 11 + #include <linux/regmap.h> 12 + #include <linux/reset-controller.h> 13 + 14 + struct ccu_rst_info; 15 + 16 + /* 17 + * enum ccu_rst_type - CCU Reset types 18 + * @CCU_RST_TRIG: Self-deasserted reset signal. 19 + * @CCU_RST_DIR: Directly controlled reset signal. 20 + */ 21 + enum ccu_rst_type { 22 + CCU_RST_TRIG, 23 + CCU_RST_DIR, 24 + }; 25 + 26 + /* 27 + * struct ccu_rst_init_data - CCU Resets initialization data 28 + * @sys_regs: Baikal-T1 System Controller registers map. 29 + * @np: Pointer to the node with the System CCU block. 30 + */ 31 + struct ccu_rst_init_data { 32 + struct regmap *sys_regs; 33 + struct device_node *np; 34 + }; 35 + 36 + /* 37 + * struct ccu_rst - CCU Reset descriptor 38 + * @rcdev: Reset controller descriptor. 39 + * @sys_regs: Baikal-T1 System Controller registers map. 40 + * @rsts_info: Reset flag info (base address and mask). 41 + */ 42 + struct ccu_rst { 43 + struct reset_controller_dev rcdev; 44 + struct regmap *sys_regs; 45 + const struct ccu_rst_info *rsts_info; 46 + }; 47 + #define to_ccu_rst(_rcdev) container_of(_rcdev, struct ccu_rst, rcdev) 48 + 49 + #ifdef CONFIG_CLK_BT1_CCU_RST 50 + 51 + struct ccu_rst *ccu_rst_hw_register(const struct ccu_rst_init_data *init); 52 + 53 + void ccu_rst_hw_unregister(struct ccu_rst *rst); 54 + 55 + #else 56 + 57 + static inline 58 + struct ccu_rst *ccu_rst_hw_register(const struct ccu_rst_init_data *init) 59 + { 60 + return NULL; 61 + } 62 + 63 + static inline void ccu_rst_hw_unregister(struct ccu_rst *rst) {} 64 + 65 + #endif 66 + 67 + #endif /* __CLK_BT1_CCU_RST_H__ */
+148 -112
drivers/clk/baikal-t1/clk-ccu-div.c
··· 12 #define pr_fmt(fmt) "bt1-ccu-div: " fmt 13 14 #include <linux/kernel.h> 15 #include <linux/printk.h> 16 #include <linux/slab.h> 17 #include <linux/clk-provider.h> ··· 25 #include <linux/regmap.h> 26 27 #include <dt-bindings/clock/bt1-ccu.h> 28 - #include <dt-bindings/reset/bt1-ccu.h> 29 30 #include "ccu-div.h" 31 32 #define CCU_AXI_MAIN_BASE 0x030 33 #define CCU_AXI_DDR_BASE 0x034 ··· 77 .divider = _divider \ 78 } 79 80 #define CCU_DIV_FIXED_INFO(_id, _name, _pname, _divider) \ 81 { \ 82 .id = _id, \ ··· 94 .parent_name = _pname, \ 95 .type = CCU_DIV_FIXED, \ 96 .divider = _divider \ 97 - } 98 - 99 - #define CCU_DIV_RST_MAP(_rst_id, _clk_id) \ 100 - { \ 101 - .rst_id = _rst_id, \ 102 - .clk_id = _clk_id \ 103 } 104 105 struct ccu_div_info { ··· 110 unsigned long features; 111 }; 112 113 - struct ccu_div_rst_map { 114 - unsigned int rst_id; 115 - unsigned int clk_id; 116 - }; 117 - 118 struct ccu_div_data { 119 struct device_node *np; 120 struct regmap *sys_regs; ··· 118 const struct ccu_div_info *divs_info; 119 struct ccu_div **divs; 120 121 - unsigned int rst_num; 122 - const struct ccu_div_rst_map *rst_map; 123 - struct reset_controller_dev rcdev; 124 }; 125 - #define to_ccu_div_data(_rcdev) container_of(_rcdev, struct ccu_div_data, rcdev) 126 127 /* 128 * AXI Main Interconnect (axi_main_clk) and DDR AXI-bus (axi_ddr_clk) clocks ··· 166 CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN) 167 }; 168 169 - static const struct ccu_div_rst_map axi_rst_map[] = { 170 - CCU_DIV_RST_MAP(CCU_AXI_MAIN_RST, CCU_AXI_MAIN_CLK), 171 - CCU_DIV_RST_MAP(CCU_AXI_DDR_RST, CCU_AXI_DDR_CLK), 172 - CCU_DIV_RST_MAP(CCU_AXI_SATA_RST, CCU_AXI_SATA_CLK), 173 - CCU_DIV_RST_MAP(CCU_AXI_GMAC0_RST, CCU_AXI_GMAC0_CLK), 174 - CCU_DIV_RST_MAP(CCU_AXI_GMAC1_RST, CCU_AXI_GMAC1_CLK), 175 - CCU_DIV_RST_MAP(CCU_AXI_XGMAC_RST, CCU_AXI_XGMAC_CLK), 176 - CCU_DIV_RST_MAP(CCU_AXI_PCIE_M_RST, CCU_AXI_PCIE_M_CLK), 177 - CCU_DIV_RST_MAP(CCU_AXI_PCIE_S_RST, CCU_AXI_PCIE_S_CLK), 178 - CCU_DIV_RST_MAP(CCU_AXI_USB_RST, CCU_AXI_USB_CLK), 179 - CCU_DIV_RST_MAP(CCU_AXI_HWA_RST, CCU_AXI_HWA_CLK), 180 - CCU_DIV_RST_MAP(CCU_AXI_SRAM_RST, CCU_AXI_SRAM_CLK) 181 - }; 182 - 183 /* 184 * APB-bus clock is marked as critical since it's a main communication bus 185 * for the SoC devices registers IO-operations. 186 */ 187 static const struct ccu_div_info sys_info[] = { 188 - CCU_DIV_VAR_INFO(CCU_SYS_SATA_REF_CLK, "sys_sata_ref_clk", 189 "sata_clk", CCU_SYS_SATA_REF_BASE, 4, 190 CLK_SET_RATE_GATE, 191 CCU_DIV_SKIP_ONE | CCU_DIV_LOCK_SHIFTED | 192 CCU_DIV_RESET_DOMAIN), 193 CCU_DIV_VAR_INFO(CCU_SYS_APB_CLK, "sys_apb_clk", 194 "pcie_clk", CCU_SYS_APB_BASE, 5, 195 - CLK_IS_CRITICAL, CCU_DIV_RESET_DOMAIN), 196 CCU_DIV_GATE_INFO(CCU_SYS_GMAC0_TX_CLK, "sys_gmac0_tx_clk", 197 "eth_clk", CCU_SYS_GMAC0_BASE, 5), 198 CCU_DIV_FIXED_INFO(CCU_SYS_GMAC0_PTP_CLK, "sys_gmac0_ptp_clk", ··· 190 "eth_clk", CCU_SYS_GMAC1_BASE, 5), 191 CCU_DIV_FIXED_INFO(CCU_SYS_GMAC1_PTP_CLK, "sys_gmac1_ptp_clk", 192 "eth_clk", 10), 193 - CCU_DIV_GATE_INFO(CCU_SYS_XGMAC_REF_CLK, "sys_xgmac_ref_clk", 194 - "eth_clk", CCU_SYS_XGMAC_BASE, 8), 195 CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_PTP_CLK, "sys_xgmac_ptp_clk", 196 - "eth_clk", 10), 197 CCU_DIV_GATE_INFO(CCU_SYS_USB_CLK, "sys_usb_clk", 198 "eth_clk", CCU_SYS_USB_BASE, 10), 199 CCU_DIV_VAR_INFO(CCU_SYS_PVT_CLK, "sys_pvt_clk", ··· 215 "ref_clk", 25), 216 CCU_DIV_VAR_INFO(CCU_SYS_TIMER0_CLK, "sys_timer0_clk", 217 "ref_clk", CCU_SYS_TIMER0_BASE, 17, 218 - CLK_SET_RATE_GATE, 0), 219 CCU_DIV_VAR_INFO(CCU_SYS_TIMER1_CLK, "sys_timer1_clk", 220 "ref_clk", CCU_SYS_TIMER1_BASE, 17, 221 - CLK_SET_RATE_GATE, 0), 222 CCU_DIV_VAR_INFO(CCU_SYS_TIMER2_CLK, "sys_timer2_clk", 223 "ref_clk", CCU_SYS_TIMER2_BASE, 17, 224 - CLK_SET_RATE_GATE, 0), 225 CCU_DIV_VAR_INFO(CCU_SYS_WDT_CLK, "sys_wdt_clk", 226 "eth_clk", CCU_SYS_WDT_BASE, 17, 227 CLK_SET_RATE_GATE, CCU_DIV_SKIP_ONE_TO_THREE) 228 }; 229 230 - static const struct ccu_div_rst_map sys_rst_map[] = { 231 - CCU_DIV_RST_MAP(CCU_SYS_SATA_REF_RST, CCU_SYS_SATA_REF_CLK), 232 - CCU_DIV_RST_MAP(CCU_SYS_APB_RST, CCU_SYS_APB_CLK), 233 - }; 234 235 static struct ccu_div *ccu_div_find_desc(struct ccu_div_data *data, 236 unsigned int clk_id) 237 { 238 - struct ccu_div *div; 239 int idx; 240 241 for (idx = 0; idx < data->divs_num; ++idx) { 242 - div = data->divs[idx]; 243 - if (div && div->id == clk_id) 244 - return div; 245 } 246 247 return ERR_PTR(-EINVAL); 248 } 249 - 250 - static int ccu_div_reset(struct reset_controller_dev *rcdev, 251 - unsigned long rst_id) 252 - { 253 - struct ccu_div_data *data = to_ccu_div_data(rcdev); 254 - const struct ccu_div_rst_map *map; 255 - struct ccu_div *div; 256 - int idx, ret; 257 - 258 - for (idx = 0, map = data->rst_map; idx < data->rst_num; ++idx, ++map) { 259 - if (map->rst_id == rst_id) 260 - break; 261 - } 262 - if (idx == data->rst_num) { 263 - pr_err("Invalid reset ID %lu specified\n", rst_id); 264 - return -EINVAL; 265 - } 266 - 267 - div = ccu_div_find_desc(data, map->clk_id); 268 - if (IS_ERR(div)) { 269 - pr_err("Invalid clock ID %d in mapping\n", map->clk_id); 270 - return PTR_ERR(div); 271 - } 272 - 273 - ret = ccu_div_reset_domain(div); 274 - if (ret) { 275 - pr_err("Reset isn't supported by divider %s\n", 276 - clk_hw_get_name(ccu_div_get_clk_hw(div))); 277 - } 278 - 279 - return ret; 280 - } 281 - 282 - static const struct reset_control_ops ccu_div_rst_ops = { 283 - .reset = ccu_div_reset, 284 - }; 285 286 static struct ccu_div_data *ccu_div_create_data(struct device_node *np) 287 { ··· 280 if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) { 281 data->divs_num = ARRAY_SIZE(axi_info); 282 data->divs_info = axi_info; 283 - data->rst_num = ARRAY_SIZE(axi_rst_map); 284 - data->rst_map = axi_rst_map; 285 } else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) { 286 data->divs_num = ARRAY_SIZE(sys_info); 287 data->divs_info = sys_info; 288 - data->rst_num = ARRAY_SIZE(sys_rst_map); 289 - data->rst_map = sys_rst_map; 290 } else { 291 pr_err("Incompatible DT node '%s' specified\n", 292 of_node_full_name(np)); ··· 333 clk_id = clkspec->args[0]; 334 div = ccu_div_find_desc(data, clk_id); 335 if (IS_ERR(div)) { 336 - pr_info("Invalid clock ID %d specified\n", clk_id); 337 return ERR_CAST(div); 338 } 339 340 return ccu_div_get_clk_hw(div); 341 } 342 343 - static int ccu_div_clk_register(struct ccu_div_data *data) 344 { 345 int idx, ret; 346 347 for (idx = 0; idx < data->divs_num; ++idx) { 348 const struct ccu_div_info *info = &data->divs_info[idx]; 349 struct ccu_div_init_data init = {0}; 350 351 init.id = info->id; 352 init.name = info->name; ··· 373 init.base = info->base; 374 init.sys_regs = data->sys_regs; 375 init.divider = info->divider; 376 } else { 377 init.divider = info->divider; 378 } ··· 389 } 390 } 391 392 - ret = of_clk_add_hw_provider(data->np, ccu_div_of_clk_hw_get, data); 393 - if (ret) { 394 - pr_err("Couldn't register dividers '%s' clock provider\n", 395 - of_node_full_name(data->np)); 396 - goto err_hw_unregister; 397 - } 398 - 399 return 0; 400 401 err_hw_unregister: 402 - for (--idx; idx >= 0; --idx) 403 ccu_div_hw_unregister(data->divs[idx]); 404 405 return ret; 406 } 407 408 - static void ccu_div_clk_unregister(struct ccu_div_data *data) 409 { 410 int idx; 411 412 - of_clk_del_provider(data->np); 413 414 - for (idx = 0; idx < data->divs_num; ++idx) 415 ccu_div_hw_unregister(data->divs[idx]); 416 } 417 418 static int ccu_div_rst_register(struct ccu_div_data *data) 419 { 420 - int ret; 421 422 - data->rcdev.ops = &ccu_div_rst_ops; 423 - data->rcdev.of_node = data->np; 424 - data->rcdev.nr_resets = data->rst_num; 425 426 - ret = reset_controller_register(&data->rcdev); 427 - if (ret) 428 pr_err("Couldn't register divider '%s' reset controller\n", 429 of_node_full_name(data->np)); 430 431 return ret; 432 } 433 434 - static void ccu_div_init(struct device_node *np) 435 { 436 struct ccu_div_data *data; 437 int ret; ··· 499 if (ret) 500 goto err_free_data; 501 502 - ret = ccu_div_clk_register(data); 503 if (ret) 504 goto err_free_data; 505 506 - ret = ccu_div_rst_register(data); 507 if (ret) 508 goto err_clk_unregister; 509 510 return; 511 512 err_clk_unregister: 513 - ccu_div_clk_unregister(data); 514 515 err_free_data: 516 ccu_div_free_data(data); 517 } 518 - 519 - CLK_OF_DECLARE(ccu_axi, "baikal,bt1-ccu-axi", ccu_div_init); 520 - CLK_OF_DECLARE(ccu_sys, "baikal,bt1-ccu-sys", ccu_div_init);
··· 12 #define pr_fmt(fmt) "bt1-ccu-div: " fmt 13 14 #include <linux/kernel.h> 15 + #include <linux/platform_device.h> 16 #include <linux/printk.h> 17 #include <linux/slab.h> 18 #include <linux/clk-provider.h> ··· 24 #include <linux/regmap.h> 25 26 #include <dt-bindings/clock/bt1-ccu.h> 27 28 #include "ccu-div.h" 29 + #include "ccu-rst.h" 30 31 #define CCU_AXI_MAIN_BASE 0x030 32 #define CCU_AXI_DDR_BASE 0x034 ··· 76 .divider = _divider \ 77 } 78 79 + #define CCU_DIV_BUF_INFO(_id, _name, _pname, _base, _flags) \ 80 + { \ 81 + .id = _id, \ 82 + .name = _name, \ 83 + .parent_name = _pname, \ 84 + .base = _base, \ 85 + .type = CCU_DIV_BUF, \ 86 + .flags = _flags \ 87 + } 88 + 89 #define CCU_DIV_FIXED_INFO(_id, _name, _pname, _divider) \ 90 { \ 91 .id = _id, \ ··· 83 .parent_name = _pname, \ 84 .type = CCU_DIV_FIXED, \ 85 .divider = _divider \ 86 } 87 88 struct ccu_div_info { ··· 105 unsigned long features; 106 }; 107 108 struct ccu_div_data { 109 struct device_node *np; 110 struct regmap *sys_regs; ··· 118 const struct ccu_div_info *divs_info; 119 struct ccu_div **divs; 120 121 + struct ccu_rst *rsts; 122 }; 123 124 /* 125 * AXI Main Interconnect (axi_main_clk) and DDR AXI-bus (axi_ddr_clk) clocks ··· 169 CLK_SET_RATE_GATE, CCU_DIV_RESET_DOMAIN) 170 }; 171 172 /* 173 * APB-bus clock is marked as critical since it's a main communication bus 174 * for the SoC devices registers IO-operations. 175 */ 176 static const struct ccu_div_info sys_info[] = { 177 + CCU_DIV_VAR_INFO(CCU_SYS_SATA_CLK, "sys_sata_clk", 178 "sata_clk", CCU_SYS_SATA_REF_BASE, 4, 179 CLK_SET_RATE_GATE, 180 CCU_DIV_SKIP_ONE | CCU_DIV_LOCK_SHIFTED | 181 CCU_DIV_RESET_DOMAIN), 182 + CCU_DIV_BUF_INFO(CCU_SYS_SATA_REF_CLK, "sys_sata_ref_clk", 183 + "sys_sata_clk", CCU_SYS_SATA_REF_BASE, 184 + CLK_SET_RATE_PARENT), 185 CCU_DIV_VAR_INFO(CCU_SYS_APB_CLK, "sys_apb_clk", 186 "pcie_clk", CCU_SYS_APB_BASE, 5, 187 + CLK_IS_CRITICAL, CCU_DIV_BASIC | CCU_DIV_RESET_DOMAIN), 188 CCU_DIV_GATE_INFO(CCU_SYS_GMAC0_TX_CLK, "sys_gmac0_tx_clk", 189 "eth_clk", CCU_SYS_GMAC0_BASE, 5), 190 CCU_DIV_FIXED_INFO(CCU_SYS_GMAC0_PTP_CLK, "sys_gmac0_ptp_clk", ··· 204 "eth_clk", CCU_SYS_GMAC1_BASE, 5), 205 CCU_DIV_FIXED_INFO(CCU_SYS_GMAC1_PTP_CLK, "sys_gmac1_ptp_clk", 206 "eth_clk", 10), 207 + CCU_DIV_GATE_INFO(CCU_SYS_XGMAC_CLK, "sys_xgmac_clk", 208 + "eth_clk", CCU_SYS_XGMAC_BASE, 1), 209 + CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_REF_CLK, "sys_xgmac_ref_clk", 210 + "sys_xgmac_clk", 8), 211 CCU_DIV_FIXED_INFO(CCU_SYS_XGMAC_PTP_CLK, "sys_xgmac_ptp_clk", 212 + "sys_xgmac_clk", 8), 213 CCU_DIV_GATE_INFO(CCU_SYS_USB_CLK, "sys_usb_clk", 214 "eth_clk", CCU_SYS_USB_BASE, 10), 215 CCU_DIV_VAR_INFO(CCU_SYS_PVT_CLK, "sys_pvt_clk", ··· 227 "ref_clk", 25), 228 CCU_DIV_VAR_INFO(CCU_SYS_TIMER0_CLK, "sys_timer0_clk", 229 "ref_clk", CCU_SYS_TIMER0_BASE, 17, 230 + CLK_SET_RATE_GATE, CCU_DIV_BASIC), 231 CCU_DIV_VAR_INFO(CCU_SYS_TIMER1_CLK, "sys_timer1_clk", 232 "ref_clk", CCU_SYS_TIMER1_BASE, 17, 233 + CLK_SET_RATE_GATE, CCU_DIV_BASIC), 234 CCU_DIV_VAR_INFO(CCU_SYS_TIMER2_CLK, "sys_timer2_clk", 235 "ref_clk", CCU_SYS_TIMER2_BASE, 17, 236 + CLK_SET_RATE_GATE, CCU_DIV_BASIC), 237 CCU_DIV_VAR_INFO(CCU_SYS_WDT_CLK, "sys_wdt_clk", 238 "eth_clk", CCU_SYS_WDT_BASE, 17, 239 CLK_SET_RATE_GATE, CCU_DIV_SKIP_ONE_TO_THREE) 240 }; 241 242 + static struct ccu_div_data *axi_data; 243 + static struct ccu_div_data *sys_data; 244 + 245 + static void ccu_div_set_data(struct ccu_div_data *data) 246 + { 247 + struct device_node *np = data->np; 248 + 249 + if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) 250 + axi_data = data; 251 + else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) 252 + sys_data = data; 253 + else 254 + pr_err("Invalid DT node '%s' specified\n", of_node_full_name(np)); 255 + } 256 + 257 + static struct ccu_div_data *ccu_div_get_data(struct device_node *np) 258 + { 259 + if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) 260 + return axi_data; 261 + else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) 262 + return sys_data; 263 + 264 + pr_err("Invalid DT node '%s' specified\n", of_node_full_name(np)); 265 + 266 + return NULL; 267 + } 268 269 static struct ccu_div *ccu_div_find_desc(struct ccu_div_data *data, 270 unsigned int clk_id) 271 { 272 int idx; 273 274 for (idx = 0; idx < data->divs_num; ++idx) { 275 + if (data->divs_info[idx].id == clk_id) 276 + return data->divs[idx]; 277 } 278 279 return ERR_PTR(-EINVAL); 280 } 281 282 static struct ccu_div_data *ccu_div_create_data(struct device_node *np) 283 { ··· 308 if (of_device_is_compatible(np, "baikal,bt1-ccu-axi")) { 309 data->divs_num = ARRAY_SIZE(axi_info); 310 data->divs_info = axi_info; 311 } else if (of_device_is_compatible(np, "baikal,bt1-ccu-sys")) { 312 data->divs_num = ARRAY_SIZE(sys_info); 313 data->divs_info = sys_info; 314 } else { 315 pr_err("Incompatible DT node '%s' specified\n", 316 of_node_full_name(np)); ··· 365 clk_id = clkspec->args[0]; 366 div = ccu_div_find_desc(data, clk_id); 367 if (IS_ERR(div)) { 368 + if (div != ERR_PTR(-EPROBE_DEFER)) 369 + pr_info("Invalid clock ID %d specified\n", clk_id); 370 + 371 return ERR_CAST(div); 372 } 373 374 return ccu_div_get_clk_hw(div); 375 } 376 377 + static int ccu_div_clk_register(struct ccu_div_data *data, bool defer) 378 { 379 int idx, ret; 380 381 for (idx = 0; idx < data->divs_num; ++idx) { 382 const struct ccu_div_info *info = &data->divs_info[idx]; 383 struct ccu_div_init_data init = {0}; 384 + 385 + if (!!(info->features & CCU_DIV_BASIC) ^ defer) { 386 + if (!data->divs[idx]) 387 + data->divs[idx] = ERR_PTR(-EPROBE_DEFER); 388 + 389 + continue; 390 + } 391 392 init.id = info->id; 393 init.name = info->name; ··· 396 init.base = info->base; 397 init.sys_regs = data->sys_regs; 398 init.divider = info->divider; 399 + } else if (init.type == CCU_DIV_BUF) { 400 + init.base = info->base; 401 + init.sys_regs = data->sys_regs; 402 } else { 403 init.divider = info->divider; 404 } ··· 409 } 410 } 411 412 return 0; 413 414 err_hw_unregister: 415 + for (--idx; idx >= 0; --idx) { 416 + if (!!(data->divs_info[idx].features & CCU_DIV_BASIC) ^ defer) 417 + continue; 418 + 419 ccu_div_hw_unregister(data->divs[idx]); 420 + } 421 422 return ret; 423 } 424 425 + static void ccu_div_clk_unregister(struct ccu_div_data *data, bool defer) 426 { 427 int idx; 428 429 + /* Uninstall only the clocks registered on the specfied stage */ 430 + for (idx = 0; idx < data->divs_num; ++idx) { 431 + if (!!(data->divs_info[idx].features & CCU_DIV_BASIC) ^ defer) 432 + continue; 433 434 ccu_div_hw_unregister(data->divs[idx]); 435 + } 436 + } 437 + 438 + static int ccu_div_of_register(struct ccu_div_data *data) 439 + { 440 + int ret; 441 + 442 + ret = of_clk_add_hw_provider(data->np, ccu_div_of_clk_hw_get, data); 443 + if (ret) { 444 + pr_err("Couldn't register dividers '%s' clock provider\n", 445 + of_node_full_name(data->np)); 446 + } 447 + 448 + return ret; 449 } 450 451 static int ccu_div_rst_register(struct ccu_div_data *data) 452 { 453 + struct ccu_rst_init_data init = {0}; 454 455 + init.sys_regs = data->sys_regs; 456 + init.np = data->np; 457 458 + data->rsts = ccu_rst_hw_register(&init); 459 + if (IS_ERR(data->rsts)) { 460 pr_err("Couldn't register divider '%s' reset controller\n", 461 of_node_full_name(data->np)); 462 + return PTR_ERR(data->rsts); 463 + } 464 + 465 + return 0; 466 + } 467 + 468 + static int ccu_div_probe(struct platform_device *pdev) 469 + { 470 + struct ccu_div_data *data; 471 + int ret; 472 + 473 + data = ccu_div_get_data(dev_of_node(&pdev->dev)); 474 + if (!data) 475 + return -EINVAL; 476 + 477 + ret = ccu_div_clk_register(data, false); 478 + if (ret) 479 + return ret; 480 + 481 + ret = ccu_div_rst_register(data); 482 + if (ret) 483 + goto err_clk_unregister; 484 + 485 + return 0; 486 + 487 + err_clk_unregister: 488 + ccu_div_clk_unregister(data, false); 489 490 return ret; 491 } 492 493 + static const struct of_device_id ccu_div_of_match[] = { 494 + { .compatible = "baikal,bt1-ccu-axi" }, 495 + { .compatible = "baikal,bt1-ccu-sys" }, 496 + { } 497 + }; 498 + 499 + static struct platform_driver ccu_div_driver = { 500 + .probe = ccu_div_probe, 501 + .driver = { 502 + .name = "clk-ccu-div", 503 + .of_match_table = ccu_div_of_match, 504 + .suppress_bind_attrs = true, 505 + }, 506 + }; 507 + builtin_platform_driver(ccu_div_driver); 508 + 509 + static __init void ccu_div_init(struct device_node *np) 510 { 511 struct ccu_div_data *data; 512 int ret; ··· 464 if (ret) 465 goto err_free_data; 466 467 + ret = ccu_div_clk_register(data, true); 468 if (ret) 469 goto err_free_data; 470 471 + ret = ccu_div_of_register(data); 472 if (ret) 473 goto err_clk_unregister; 474 + 475 + ccu_div_set_data(data); 476 477 return; 478 479 err_clk_unregister: 480 + ccu_div_clk_unregister(data, true); 481 482 err_free_data: 483 ccu_div_free_data(data); 484 } 485 + CLK_OF_DECLARE_DRIVER(ccu_axi, "baikal,bt1-ccu-axi", ccu_div_init); 486 + CLK_OF_DECLARE_DRIVER(ccu_sys, "baikal,bt1-ccu-sys", ccu_div_init);
+98 -27
drivers/clk/baikal-t1/clk-ccu-pll.c
··· 12 #define pr_fmt(fmt) "bt1-ccu-pll: " fmt 13 14 #include <linux/kernel.h> 15 #include <linux/printk.h> 16 #include <linux/slab.h> 17 #include <linux/clk-provider.h> ··· 32 #define CCU_PCIE_PLL_BASE 0x018 33 #define CCU_ETH_PLL_BASE 0x020 34 35 - #define CCU_PLL_INFO(_id, _name, _pname, _base, _flags) \ 36 - { \ 37 - .id = _id, \ 38 - .name = _name, \ 39 - .parent_name = _pname, \ 40 - .base = _base, \ 41 - .flags = _flags \ 42 } 43 44 #define CCU_PLL_NUM ARRAY_SIZE(pll_info) ··· 50 const char *parent_name; 51 unsigned int base; 52 unsigned long flags; 53 }; 54 55 /* ··· 64 */ 65 static const struct ccu_pll_info pll_info[] = { 66 CCU_PLL_INFO(CCU_CPU_PLL, "cpu_pll", "ref_clk", CCU_CPU_PLL_BASE, 67 - CLK_IS_CRITICAL), 68 CCU_PLL_INFO(CCU_SATA_PLL, "sata_pll", "ref_clk", CCU_SATA_PLL_BASE, 69 - CLK_IS_CRITICAL | CLK_SET_RATE_GATE), 70 CCU_PLL_INFO(CCU_DDR_PLL, "ddr_pll", "ref_clk", CCU_DDR_PLL_BASE, 71 - CLK_IS_CRITICAL | CLK_SET_RATE_GATE), 72 CCU_PLL_INFO(CCU_PCIE_PLL, "pcie_pll", "ref_clk", CCU_PCIE_PLL_BASE, 73 - CLK_IS_CRITICAL), 74 CCU_PLL_INFO(CCU_ETH_PLL, "eth_pll", "ref_clk", CCU_ETH_PLL_BASE, 75 - CLK_IS_CRITICAL | CLK_SET_RATE_GATE) 76 }; 77 78 struct ccu_pll_data { ··· 81 struct ccu_pll *plls[CCU_PLL_NUM]; 82 }; 83 84 static struct ccu_pll *ccu_pll_find_desc(struct ccu_pll_data *data, 85 unsigned int clk_id) 86 { 87 - struct ccu_pll *pll; 88 int idx; 89 90 for (idx = 0; idx < CCU_PLL_NUM; ++idx) { 91 - pll = data->plls[idx]; 92 - if (pll && pll->id == clk_id) 93 - return pll; 94 } 95 96 return ERR_PTR(-EINVAL); ··· 136 clk_id = clkspec->args[0]; 137 pll = ccu_pll_find_desc(data, clk_id); 138 if (IS_ERR(pll)) { 139 - pr_info("Invalid PLL clock ID %d specified\n", clk_id); 140 return ERR_CAST(pll); 141 } 142 143 return ccu_pll_get_clk_hw(pll); 144 } 145 146 - static int ccu_pll_clk_register(struct ccu_pll_data *data) 147 { 148 int idx, ret; 149 150 for (idx = 0; idx < CCU_PLL_NUM; ++idx) { 151 const struct ccu_pll_info *info = &pll_info[idx]; 152 struct ccu_pll_init_data init = {0}; 153 154 init.id = info->id; 155 init.name = info->name; ··· 168 init.sys_regs = data->sys_regs; 169 init.np = data->np; 170 init.flags = info->flags; 171 172 data->plls[idx] = ccu_pll_hw_register(&init); 173 if (IS_ERR(data->plls[idx])) { ··· 179 } 180 } 181 182 ret = of_clk_add_hw_provider(data->np, ccu_pll_of_clk_hw_get, data); 183 if (ret) { 184 pr_err("Couldn't register PLL provider of '%s'\n", 185 of_node_full_name(data->np)); 186 - goto err_hw_unregister; 187 } 188 - 189 - return 0; 190 - 191 - err_hw_unregister: 192 - for (--idx; idx >= 0; --idx) 193 - ccu_pll_hw_unregister(data->plls[idx]); 194 195 return ret; 196 } 197 198 static __init void ccu_pll_init(struct device_node *np) 199 { ··· 256 if (ret) 257 goto err_free_data; 258 259 - ret = ccu_pll_clk_register(data); 260 if (ret) 261 goto err_free_data; 262 263 return; 264 265 err_free_data: 266 ccu_pll_free_data(data); 267 } 268 - CLK_OF_DECLARE(ccu_pll, "baikal,bt1-ccu-pll", ccu_pll_init);
··· 12 #define pr_fmt(fmt) "bt1-ccu-pll: " fmt 13 14 #include <linux/kernel.h> 15 + #include <linux/platform_device.h> 16 #include <linux/printk.h> 17 #include <linux/slab.h> 18 #include <linux/clk-provider.h> ··· 31 #define CCU_PCIE_PLL_BASE 0x018 32 #define CCU_ETH_PLL_BASE 0x020 33 34 + #define CCU_PLL_INFO(_id, _name, _pname, _base, _flags, _features) \ 35 + { \ 36 + .id = _id, \ 37 + .name = _name, \ 38 + .parent_name = _pname, \ 39 + .base = _base, \ 40 + .flags = _flags, \ 41 + .features = _features, \ 42 } 43 44 #define CCU_PLL_NUM ARRAY_SIZE(pll_info) ··· 48 const char *parent_name; 49 unsigned int base; 50 unsigned long flags; 51 + unsigned long features; 52 }; 53 54 /* ··· 61 */ 62 static const struct ccu_pll_info pll_info[] = { 63 CCU_PLL_INFO(CCU_CPU_PLL, "cpu_pll", "ref_clk", CCU_CPU_PLL_BASE, 64 + CLK_IS_CRITICAL, CCU_PLL_BASIC), 65 CCU_PLL_INFO(CCU_SATA_PLL, "sata_pll", "ref_clk", CCU_SATA_PLL_BASE, 66 + CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0), 67 CCU_PLL_INFO(CCU_DDR_PLL, "ddr_pll", "ref_clk", CCU_DDR_PLL_BASE, 68 + CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0), 69 CCU_PLL_INFO(CCU_PCIE_PLL, "pcie_pll", "ref_clk", CCU_PCIE_PLL_BASE, 70 + CLK_IS_CRITICAL, CCU_PLL_BASIC), 71 CCU_PLL_INFO(CCU_ETH_PLL, "eth_pll", "ref_clk", CCU_ETH_PLL_BASE, 72 + CLK_IS_CRITICAL | CLK_SET_RATE_GATE, 0) 73 }; 74 75 struct ccu_pll_data { ··· 78 struct ccu_pll *plls[CCU_PLL_NUM]; 79 }; 80 81 + static struct ccu_pll_data *pll_data; 82 + 83 static struct ccu_pll *ccu_pll_find_desc(struct ccu_pll_data *data, 84 unsigned int clk_id) 85 { 86 int idx; 87 88 for (idx = 0; idx < CCU_PLL_NUM; ++idx) { 89 + if (pll_info[idx].id == clk_id) 90 + return data->plls[idx]; 91 } 92 93 return ERR_PTR(-EINVAL); ··· 133 clk_id = clkspec->args[0]; 134 pll = ccu_pll_find_desc(data, clk_id); 135 if (IS_ERR(pll)) { 136 + if (pll != ERR_PTR(-EPROBE_DEFER)) 137 + pr_info("Invalid PLL clock ID %d specified\n", clk_id); 138 + 139 return ERR_CAST(pll); 140 } 141 142 return ccu_pll_get_clk_hw(pll); 143 } 144 145 + static int ccu_pll_clk_register(struct ccu_pll_data *data, bool defer) 146 { 147 int idx, ret; 148 149 for (idx = 0; idx < CCU_PLL_NUM; ++idx) { 150 const struct ccu_pll_info *info = &pll_info[idx]; 151 struct ccu_pll_init_data init = {0}; 152 + 153 + /* Defer non-basic PLLs allocation for the probe stage */ 154 + if (!!(info->features & CCU_PLL_BASIC) ^ defer) { 155 + if (!data->plls[idx]) 156 + data->plls[idx] = ERR_PTR(-EPROBE_DEFER); 157 + 158 + continue; 159 + } 160 161 init.id = info->id; 162 init.name = info->name; ··· 155 init.sys_regs = data->sys_regs; 156 init.np = data->np; 157 init.flags = info->flags; 158 + init.features = info->features; 159 160 data->plls[idx] = ccu_pll_hw_register(&init); 161 if (IS_ERR(data->plls[idx])) { ··· 165 } 166 } 167 168 + return 0; 169 + 170 + err_hw_unregister: 171 + for (--idx; idx >= 0; --idx) { 172 + if (!!(pll_info[idx].features & CCU_PLL_BASIC) ^ defer) 173 + continue; 174 + 175 + ccu_pll_hw_unregister(data->plls[idx]); 176 + } 177 + 178 + return ret; 179 + } 180 + 181 + static void ccu_pll_clk_unregister(struct ccu_pll_data *data, bool defer) 182 + { 183 + int idx; 184 + 185 + /* Uninstall only the clocks registered on the specfied stage */ 186 + for (idx = 0; idx < CCU_PLL_NUM; ++idx) { 187 + if (!!(pll_info[idx].features & CCU_PLL_BASIC) ^ defer) 188 + continue; 189 + 190 + ccu_pll_hw_unregister(data->plls[idx]); 191 + } 192 + } 193 + 194 + static int ccu_pll_of_register(struct ccu_pll_data *data) 195 + { 196 + int ret; 197 + 198 ret = of_clk_add_hw_provider(data->np, ccu_pll_of_clk_hw_get, data); 199 if (ret) { 200 pr_err("Couldn't register PLL provider of '%s'\n", 201 of_node_full_name(data->np)); 202 } 203 204 return ret; 205 } 206 + 207 + static int ccu_pll_probe(struct platform_device *pdev) 208 + { 209 + struct ccu_pll_data *data = pll_data; 210 + 211 + if (!data) 212 + return -EINVAL; 213 + 214 + return ccu_pll_clk_register(data, false); 215 + } 216 + 217 + static const struct of_device_id ccu_pll_of_match[] = { 218 + { .compatible = "baikal,bt1-ccu-pll" }, 219 + { } 220 + }; 221 + 222 + static struct platform_driver ccu_pll_driver = { 223 + .probe = ccu_pll_probe, 224 + .driver = { 225 + .name = "clk-ccu-pll", 226 + .of_match_table = ccu_pll_of_match, 227 + .suppress_bind_attrs = true, 228 + }, 229 + }; 230 + builtin_platform_driver(ccu_pll_driver); 231 232 static __init void ccu_pll_init(struct device_node *np) 233 { ··· 194 if (ret) 195 goto err_free_data; 196 197 + ret = ccu_pll_clk_register(data, true); 198 if (ret) 199 goto err_free_data; 200 201 + ret = ccu_pll_of_register(data); 202 + if (ret) 203 + goto err_clk_unregister; 204 + 205 + pll_data = data; 206 + 207 return; 208 + 209 + err_clk_unregister: 210 + ccu_pll_clk_unregister(data, true); 211 212 err_free_data: 213 ccu_pll_free_data(data); 214 } 215 + CLK_OF_DECLARE_DRIVER(ccu_pll, "baikal,bt1-ccu-pll", ccu_pll_init);
+37 -6
drivers/clk/bcm/clk-bcm2835.c
··· 30 #include <linux/debugfs.h> 31 #include <linux/delay.h> 32 #include <linux/io.h> 33 #include <linux/module.h> 34 #include <linux/of_device.h> 35 #include <linux/platform_device.h> ··· 503 bool low_jitter; 504 505 u32 tcnt_mux; 506 }; 507 508 struct bcm2835_gate_data { ··· 969 return div; 970 } 971 972 - static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock, 973 - unsigned long parent_rate, 974 - u32 div) 975 { 976 const struct bcm2835_clock_data *data = clock->data; 977 u64 temp; ··· 996 return temp; 997 } 998 999 static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw, 1000 unsigned long parent_rate) 1001 { 1002 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw); 1003 struct bcm2835_cprman *cprman = clock->cprman; 1004 const struct bcm2835_clock_data *data = clock->data; 1005 u32 div; 1006 1007 if (data->int_bits == 0 && data->frac_bits == 0) ··· 1031 1032 div = cprman_read(cprman, data->div_reg); 1033 1034 - return bcm2835_clock_rate_from_divisor(clock, parent_rate, div); 1035 } 1036 1037 static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock) ··· 1814 .load_mask = CM_PLLC_LOADPER, 1815 .hold_mask = CM_PLLC_HOLDPER, 1816 .fixed_divider = 1, 1817 - .flags = CLK_SET_RATE_PARENT), 1818 1819 /* 1820 * PLLD is the display PLL, used to drive DSI display panels. ··· 2173 .div_reg = CM_UARTDIV, 2174 .int_bits = 10, 2175 .frac_bits = 12, 2176 - .tcnt_mux = 28), 2177 2178 /* TV encoder clock. Only operating frequency is 108Mhz. */ 2179 [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK(
··· 30 #include <linux/debugfs.h> 31 #include <linux/delay.h> 32 #include <linux/io.h> 33 + #include <linux/math.h> 34 #include <linux/module.h> 35 #include <linux/of_device.h> 36 #include <linux/platform_device.h> ··· 502 bool low_jitter; 503 504 u32 tcnt_mux; 505 + 506 + bool round_up; 507 }; 508 509 struct bcm2835_gate_data { ··· 966 return div; 967 } 968 969 + static unsigned long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock, 970 + unsigned long parent_rate, 971 + u32 div) 972 { 973 const struct bcm2835_clock_data *data = clock->data; 974 u64 temp; ··· 993 return temp; 994 } 995 996 + static unsigned long bcm2835_round_rate(unsigned long rate) 997 + { 998 + unsigned long scaler; 999 + unsigned long limit; 1000 + 1001 + limit = rate / 100000; 1002 + 1003 + scaler = 1; 1004 + while (scaler < limit) 1005 + scaler *= 10; 1006 + 1007 + /* 1008 + * If increasing a clock by less than 0.1% changes it 1009 + * from ..999.. to ..000.., round up. 1010 + */ 1011 + if ((rate + scaler - 1) / scaler % 1000 == 0) 1012 + rate = roundup(rate, scaler); 1013 + 1014 + return rate; 1015 + } 1016 + 1017 static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw, 1018 unsigned long parent_rate) 1019 { 1020 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw); 1021 struct bcm2835_cprman *cprman = clock->cprman; 1022 const struct bcm2835_clock_data *data = clock->data; 1023 + unsigned long rate; 1024 u32 div; 1025 1026 if (data->int_bits == 0 && data->frac_bits == 0) ··· 1006 1007 div = cprman_read(cprman, data->div_reg); 1008 1009 + rate = bcm2835_clock_rate_from_divisor(clock, parent_rate, div); 1010 + 1011 + if (data->round_up) 1012 + rate = bcm2835_round_rate(rate); 1013 + 1014 + return rate; 1015 } 1016 1017 static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock) ··· 1784 .load_mask = CM_PLLC_LOADPER, 1785 .hold_mask = CM_PLLC_HOLDPER, 1786 .fixed_divider = 1, 1787 + .flags = CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), 1788 1789 /* 1790 * PLLD is the display PLL, used to drive DSI display panels. ··· 2143 .div_reg = CM_UARTDIV, 2144 .int_bits = 10, 2145 .frac_bits = 12, 2146 + .tcnt_mux = 28, 2147 + .round_up = true), 2148 2149 /* TV encoder clock. Only operating frequency is 108Mhz. */ 2150 [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK(
+11
drivers/clk/bcm/clk-raspberrypi.c
··· 33 RPI_FIRMWARE_EMMC2_CLK_ID, 34 RPI_FIRMWARE_M2MC_CLK_ID, 35 RPI_FIRMWARE_PIXEL_BVB_CLK_ID, 36 RPI_FIRMWARE_NUM_CLK_ID, 37 }; 38 ··· 52 [RPI_FIRMWARE_EMMC2_CLK_ID] = "emmc2", 53 [RPI_FIRMWARE_M2MC_CLK_ID] = "m2mc", 54 [RPI_FIRMWARE_PIXEL_BVB_CLK_ID] = "pixel-bvb", 55 }; 56 57 #define RPI_FIRMWARE_STATE_ENABLE_BIT BIT(0) ··· 131 [RPI_FIRMWARE_V3D_CLK_ID] = { 132 .export = true, 133 }, 134 [RPI_FIRMWARE_PIXEL_BVB_CLK_ID] = { 135 .export = true, 136 }, 137 };
··· 33 RPI_FIRMWARE_EMMC2_CLK_ID, 34 RPI_FIRMWARE_M2MC_CLK_ID, 35 RPI_FIRMWARE_PIXEL_BVB_CLK_ID, 36 + RPI_FIRMWARE_VEC_CLK_ID, 37 RPI_FIRMWARE_NUM_CLK_ID, 38 }; 39 ··· 51 [RPI_FIRMWARE_EMMC2_CLK_ID] = "emmc2", 52 [RPI_FIRMWARE_M2MC_CLK_ID] = "m2mc", 53 [RPI_FIRMWARE_PIXEL_BVB_CLK_ID] = "pixel-bvb", 54 + [RPI_FIRMWARE_VEC_CLK_ID] = "vec", 55 }; 56 57 #define RPI_FIRMWARE_STATE_ENABLE_BIT BIT(0) ··· 129 [RPI_FIRMWARE_V3D_CLK_ID] = { 130 .export = true, 131 }, 132 + [RPI_FIRMWARE_PIXEL_CLK_ID] = { 133 + .export = true, 134 + }, 135 + [RPI_FIRMWARE_HEVC_CLK_ID] = { 136 + .export = true, 137 + }, 138 [RPI_FIRMWARE_PIXEL_BVB_CLK_ID] = { 139 + .export = true, 140 + }, 141 + [RPI_FIRMWARE_VEC_CLK_ID] = { 142 .export = true, 143 }, 144 };
+103 -56
drivers/clk/clk-versaclock5.c
··· 153 IDT_VC5_5P49V5935, 154 IDT_VC6_5P49V6901, 155 IDT_VC6_5P49V6965, 156 }; 157 158 /* Structure to describe features of a particular VC5 model */ ··· 231 container_of(hw, struct vc5_driver_data, clk_mux); 232 const u8 mask = VC5_PRIM_SRC_SHDN_EN_XTAL | VC5_PRIM_SRC_SHDN_EN_CLKIN; 233 unsigned int src; 234 235 - regmap_read(vc5->regmap, VC5_PRIM_SRC_SHDN, &src); 236 src &= mask; 237 238 if (src == VC5_PRIM_SRC_SHDN_EN_XTAL) ··· 291 struct vc5_driver_data *vc5 = 292 container_of(hw, struct vc5_driver_data, clk_mul); 293 unsigned int premul; 294 295 - regmap_read(vc5->regmap, VC5_PRIM_SRC_SHDN, &premul); 296 if (premul & VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ) 297 parent_rate *= 2; 298 ··· 324 else 325 mask = 0; 326 327 - regmap_update_bits(vc5->regmap, VC5_PRIM_SRC_SHDN, 328 - VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ, 329 - mask); 330 - 331 - return 0; 332 } 333 334 static const struct clk_ops vc5_dbl_ops = { ··· 341 struct vc5_driver_data *vc5 = 342 container_of(hw, struct vc5_driver_data, clk_pfd); 343 unsigned int prediv, div; 344 345 - regmap_read(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, &prediv); 346 347 /* The bypass_prediv is set, PLL fed from Ref_in directly. */ 348 if (prediv & VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV) 349 return parent_rate; 350 351 - regmap_read(vc5->regmap, VC5_REF_DIVIDER, &div); 352 353 /* The Sel_prediv2 is set, PLL fed from prediv2 (Ref_in / 2) */ 354 if (div & VC5_REF_DIVIDER_SEL_PREDIV2) ··· 388 struct vc5_driver_data *vc5 = 389 container_of(hw, struct vc5_driver_data, clk_pfd); 390 unsigned long idiv; 391 u8 div; 392 393 /* CLKIN within range of PLL input, feed directly to PLL. */ 394 if (parent_rate <= 50000000) { 395 - regmap_update_bits(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, 396 - VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV, 397 - VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV); 398 - regmap_update_bits(vc5->regmap, VC5_REF_DIVIDER, 0xff, 0x00); 399 - return 0; 400 } 401 402 idiv = DIV_ROUND_UP(parent_rate, rate); ··· 409 else 410 div = VC5_REF_DIVIDER_REF_DIV(idiv); 411 412 - regmap_update_bits(vc5->regmap, VC5_REF_DIVIDER, 0xff, div); 413 - regmap_update_bits(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, 414 - VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV, 0); 415 416 - return 0; 417 } 418 419 static const struct clk_ops vc5_pfd_ops = { ··· 566 hwdata->div_int >> 4, hwdata->div_int << 4, 567 0 568 }; 569 570 - regmap_bulk_write(vc5->regmap, VC5_OUT_DIV_FRAC(hwdata->num, 0), 571 - data, 14); 572 573 /* 574 * Toggle magic bit in undocumented register for unknown reason. ··· 579 * datasheet somewhat implies this is needed, but the register 580 * and the bit is not documented. 581 */ 582 - regmap_update_bits(vc5->regmap, VC5_GLOBAL_REGISTER, 583 - VC5_GLOBAL_REGISTER_GLOBAL_RESET, 0); 584 - regmap_update_bits(vc5->regmap, VC5_GLOBAL_REGISTER, 585 - VC5_GLOBAL_REGISTER_GLOBAL_RESET, 586 - VC5_GLOBAL_REGISTER_GLOBAL_RESET); 587 - return 0; 588 } 589 590 static const struct clk_ops vc5_fod_ops = { ··· 613 * registers. 614 */ 615 if (vc5->chip_info->flags & VC5_HAS_BYPASS_SYNC_BIT) { 616 - ret = regmap_update_bits(vc5->regmap, 617 - VC5_RESERVED_X0(hwdata->num), 618 - VC5_RESERVED_X0_BYPASS_SYNC, 619 - VC5_RESERVED_X0_BYPASS_SYNC); 620 if (ret) 621 return ret; 622 } ··· 624 * If the input mux is disabled, enable it first and 625 * select source from matching FOD. 626 */ 627 - regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src); 628 if ((src & mask) == 0) { 629 src = VC5_OUT_DIV_CONTROL_RESET | VC5_OUT_DIV_CONTROL_EN_FOD; 630 ret = regmap_update_bits(vc5->regmap, ··· 638 } 639 640 /* Enable the clock buffer */ 641 - regmap_update_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1), 642 - VC5_CLK_OUTPUT_CFG1_EN_CLKBUF, 643 - VC5_CLK_OUTPUT_CFG1_EN_CLKBUF); 644 if (hwdata->clk_output_cfg0_mask) { 645 dev_dbg(&vc5->client->dev, "Update output %d mask 0x%0X val 0x%0X\n", 646 hwdata->num, hwdata->clk_output_cfg0_mask, 647 hwdata->clk_output_cfg0); 648 649 - regmap_update_bits(vc5->regmap, 650 - VC5_CLK_OUTPUT_CFG(hwdata->num, 0), 651 - hwdata->clk_output_cfg0_mask, 652 - hwdata->clk_output_cfg0); 653 } 654 655 return 0; ··· 665 struct vc5_driver_data *vc5 = hwdata->vc5; 666 667 /* Disable the clock buffer */ 668 - regmap_update_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1), 669 - VC5_CLK_OUTPUT_CFG1_EN_CLKBUF, 0); 670 } 671 672 static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw) ··· 681 const u8 extclk = VC5_OUT_DIV_CONTROL_SELB_NORM | 682 VC5_OUT_DIV_CONTROL_SEL_EXT; 683 unsigned int src; 684 685 - regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src); 686 src &= mask; 687 688 if (src == 0) /* Input mux set to DISABLED */ ··· 754 case IDT_VC5_5P49V5935: 755 case IDT_VC6_5P49V6901: 756 case IDT_VC6_5P49V6965: 757 default: 758 return n; 759 } ··· 849 { 850 u32 value; 851 int mapped_value; 852 853 - if (!of_property_read_u32(node, "idt,xtal-load-femtofarads", &value)) { 854 - mapped_value = vc5_map_cap_value(value); 855 - if (mapped_value < 0) 856 - return mapped_value; 857 858 - /* 859 - * The mapped_value is really the high 6 bits of 860 - * VC5_XTAL_X1_LOAD_CAP and VC5_XTAL_X2_LOAD_CAP, so 861 - * shift the value 2 places. 862 - */ 863 - regmap_update_bits(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, ~0x03, mapped_value << 2); 864 - regmap_update_bits(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, ~0x03, mapped_value << 2); 865 - } 866 867 - return 0; 868 } 869 870 static int vc5_update_slew(struct device_node *np_output, ··· 991 "could not read idt,output-enable-active\n"); 992 } 993 994 - regmap_update_bits(vc5->regmap, VC5_PRIM_SRC_SHDN, src_mask, src_val); 995 996 /* Register clock input mux */ 997 memset(&init, 0, sizeof(init)); ··· 1242 .model = IDT_VC6_5P49V6901, 1243 .clk_fod_cnt = 4, 1244 .clk_out_cnt = 5, 1245 - .flags = VC5_HAS_PFD_FREQ_DBL, 1246 }; 1247 1248 static const struct vc5_chip_info idt_5p49v6965_info = { ··· 1252 .flags = VC5_HAS_BYPASS_SYNC_BIT, 1253 }; 1254 1255 static const struct i2c_device_id vc5_id[] = { 1256 { "5p49v5923", .driver_data = IDT_VC5_5P49V5923 }, 1257 { "5p49v5925", .driver_data = IDT_VC5_5P49V5925 }, ··· 1266 { "5p49v5935", .driver_data = IDT_VC5_5P49V5935 }, 1267 { "5p49v6901", .driver_data = IDT_VC6_5P49V6901 }, 1268 { "5p49v6965", .driver_data = IDT_VC6_5P49V6965 }, 1269 { } 1270 }; 1271 MODULE_DEVICE_TABLE(i2c, vc5_id); ··· 1278 { .compatible = "idt,5p49v5935", .data = &idt_5p49v5935_info }, 1279 { .compatible = "idt,5p49v6901", .data = &idt_5p49v6901_info }, 1280 { .compatible = "idt,5p49v6965", .data = &idt_5p49v6965_info }, 1281 { }, 1282 }; 1283 MODULE_DEVICE_TABLE(of, clk_vc5_of_match);
··· 153 IDT_VC5_5P49V5935, 154 IDT_VC6_5P49V6901, 155 IDT_VC6_5P49V6965, 156 + IDT_VC6_5P49V6975, 157 }; 158 159 /* Structure to describe features of a particular VC5 model */ ··· 230 container_of(hw, struct vc5_driver_data, clk_mux); 231 const u8 mask = VC5_PRIM_SRC_SHDN_EN_XTAL | VC5_PRIM_SRC_SHDN_EN_CLKIN; 232 unsigned int src; 233 + int ret; 234 235 + ret = regmap_read(vc5->regmap, VC5_PRIM_SRC_SHDN, &src); 236 + if (ret) 237 + return 0; 238 + 239 src &= mask; 240 241 if (src == VC5_PRIM_SRC_SHDN_EN_XTAL) ··· 286 struct vc5_driver_data *vc5 = 287 container_of(hw, struct vc5_driver_data, clk_mul); 288 unsigned int premul; 289 + int ret; 290 291 + ret = regmap_read(vc5->regmap, VC5_PRIM_SRC_SHDN, &premul); 292 + if (ret) 293 + return 0; 294 + 295 if (premul & VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ) 296 parent_rate *= 2; 297 ··· 315 else 316 mask = 0; 317 318 + return regmap_update_bits(vc5->regmap, VC5_PRIM_SRC_SHDN, 319 + VC5_PRIM_SRC_SHDN_EN_DOUBLE_XTAL_FREQ, 320 + mask); 321 } 322 323 static const struct clk_ops vc5_dbl_ops = { ··· 334 struct vc5_driver_data *vc5 = 335 container_of(hw, struct vc5_driver_data, clk_pfd); 336 unsigned int prediv, div; 337 + int ret; 338 339 + ret = regmap_read(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, &prediv); 340 + if (ret) 341 + return 0; 342 343 /* The bypass_prediv is set, PLL fed from Ref_in directly. */ 344 if (prediv & VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV) 345 return parent_rate; 346 347 + ret = regmap_read(vc5->regmap, VC5_REF_DIVIDER, &div); 348 + if (ret) 349 + return 0; 350 351 /* The Sel_prediv2 is set, PLL fed from prediv2 (Ref_in / 2) */ 352 if (div & VC5_REF_DIVIDER_SEL_PREDIV2) ··· 376 struct vc5_driver_data *vc5 = 377 container_of(hw, struct vc5_driver_data, clk_pfd); 378 unsigned long idiv; 379 + int ret; 380 u8 div; 381 382 /* CLKIN within range of PLL input, feed directly to PLL. */ 383 if (parent_rate <= 50000000) { 384 + ret = regmap_set_bits(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, 385 + VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV); 386 + if (ret) 387 + return ret; 388 + 389 + return regmap_update_bits(vc5->regmap, VC5_REF_DIVIDER, 0xff, 0x00); 390 } 391 392 idiv = DIV_ROUND_UP(parent_rate, rate); ··· 395 else 396 div = VC5_REF_DIVIDER_REF_DIV(idiv); 397 398 + ret = regmap_update_bits(vc5->regmap, VC5_REF_DIVIDER, 0xff, div); 399 + if (ret) 400 + return ret; 401 402 + return regmap_clear_bits(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV, 403 + VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV); 404 } 405 406 static const struct clk_ops vc5_pfd_ops = { ··· 551 hwdata->div_int >> 4, hwdata->div_int << 4, 552 0 553 }; 554 + int ret; 555 556 + ret = regmap_bulk_write(vc5->regmap, VC5_OUT_DIV_FRAC(hwdata->num, 0), 557 + data, 14); 558 + if (ret) 559 + return ret; 560 561 /* 562 * Toggle magic bit in undocumented register for unknown reason. ··· 561 * datasheet somewhat implies this is needed, but the register 562 * and the bit is not documented. 563 */ 564 + ret = regmap_clear_bits(vc5->regmap, VC5_GLOBAL_REGISTER, 565 + VC5_GLOBAL_REGISTER_GLOBAL_RESET); 566 + if (ret) 567 + return ret; 568 + 569 + return regmap_set_bits(vc5->regmap, VC5_GLOBAL_REGISTER, 570 + VC5_GLOBAL_REGISTER_GLOBAL_RESET); 571 } 572 573 static const struct clk_ops vc5_fod_ops = { ··· 594 * registers. 595 */ 596 if (vc5->chip_info->flags & VC5_HAS_BYPASS_SYNC_BIT) { 597 + ret = regmap_set_bits(vc5->regmap, 598 + VC5_RESERVED_X0(hwdata->num), 599 + VC5_RESERVED_X0_BYPASS_SYNC); 600 if (ret) 601 return ret; 602 } ··· 606 * If the input mux is disabled, enable it first and 607 * select source from matching FOD. 608 */ 609 + ret = regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src); 610 + if (ret) 611 + return ret; 612 + 613 if ((src & mask) == 0) { 614 src = VC5_OUT_DIV_CONTROL_RESET | VC5_OUT_DIV_CONTROL_EN_FOD; 615 ret = regmap_update_bits(vc5->regmap, ··· 617 } 618 619 /* Enable the clock buffer */ 620 + ret = regmap_set_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1), 621 + VC5_CLK_OUTPUT_CFG1_EN_CLKBUF); 622 + if (ret) 623 + return ret; 624 + 625 if (hwdata->clk_output_cfg0_mask) { 626 dev_dbg(&vc5->client->dev, "Update output %d mask 0x%0X val 0x%0X\n", 627 hwdata->num, hwdata->clk_output_cfg0_mask, 628 hwdata->clk_output_cfg0); 629 630 + ret = regmap_update_bits(vc5->regmap, 631 + VC5_CLK_OUTPUT_CFG(hwdata->num, 0), 632 + hwdata->clk_output_cfg0_mask, 633 + hwdata->clk_output_cfg0); 634 + if (ret) 635 + return ret; 636 } 637 638 return 0; ··· 640 struct vc5_driver_data *vc5 = hwdata->vc5; 641 642 /* Disable the clock buffer */ 643 + regmap_clear_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1), 644 + VC5_CLK_OUTPUT_CFG1_EN_CLKBUF); 645 } 646 647 static unsigned char vc5_clk_out_get_parent(struct clk_hw *hw) ··· 656 const u8 extclk = VC5_OUT_DIV_CONTROL_SELB_NORM | 657 VC5_OUT_DIV_CONTROL_SEL_EXT; 658 unsigned int src; 659 + int ret; 660 661 + ret = regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src); 662 + if (ret) 663 + return 0; 664 + 665 src &= mask; 666 667 if (src == 0) /* Input mux set to DISABLED */ ··· 725 case IDT_VC5_5P49V5935: 726 case IDT_VC6_5P49V6901: 727 case IDT_VC6_5P49V6965: 728 + case IDT_VC6_5P49V6975: 729 default: 730 return n; 731 } ··· 819 { 820 u32 value; 821 int mapped_value; 822 + int ret; 823 824 + if (of_property_read_u32(node, "idt,xtal-load-femtofarads", &value)) 825 + return 0; 826 827 + mapped_value = vc5_map_cap_value(value); 828 + if (mapped_value < 0) 829 + return mapped_value; 830 831 + /* 832 + * The mapped_value is really the high 6 bits of 833 + * VC5_XTAL_X1_LOAD_CAP and VC5_XTAL_X2_LOAD_CAP, so 834 + * shift the value 2 places. 835 + */ 836 + ret = regmap_update_bits(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, ~0x03, 837 + mapped_value << 2); 838 + if (ret) 839 + return ret; 840 + 841 + return regmap_update_bits(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, ~0x03, 842 + mapped_value << 2); 843 } 844 845 static int vc5_update_slew(struct device_node *np_output, ··· 956 "could not read idt,output-enable-active\n"); 957 } 958 959 + ret = regmap_update_bits(vc5->regmap, VC5_PRIM_SRC_SHDN, src_mask, 960 + src_val); 961 + if (ret) 962 + return ret; 963 964 /* Register clock input mux */ 965 memset(&init, 0, sizeof(init)); ··· 1204 .model = IDT_VC6_5P49V6901, 1205 .clk_fod_cnt = 4, 1206 .clk_out_cnt = 5, 1207 + .flags = VC5_HAS_PFD_FREQ_DBL | VC5_HAS_BYPASS_SYNC_BIT, 1208 }; 1209 1210 static const struct vc5_chip_info idt_5p49v6965_info = { ··· 1214 .flags = VC5_HAS_BYPASS_SYNC_BIT, 1215 }; 1216 1217 + static const struct vc5_chip_info idt_5p49v6975_info = { 1218 + .model = IDT_VC6_5P49V6975, 1219 + .clk_fod_cnt = 4, 1220 + .clk_out_cnt = 5, 1221 + .flags = VC5_HAS_BYPASS_SYNC_BIT | VC5_HAS_INTERNAL_XTAL, 1222 + }; 1223 + 1224 static const struct i2c_device_id vc5_id[] = { 1225 { "5p49v5923", .driver_data = IDT_VC5_5P49V5923 }, 1226 { "5p49v5925", .driver_data = IDT_VC5_5P49V5925 }, ··· 1221 { "5p49v5935", .driver_data = IDT_VC5_5P49V5935 }, 1222 { "5p49v6901", .driver_data = IDT_VC6_5P49V6901 }, 1223 { "5p49v6965", .driver_data = IDT_VC6_5P49V6965 }, 1224 + { "5p49v6975", .driver_data = IDT_VC6_5P49V6975 }, 1225 { } 1226 }; 1227 MODULE_DEVICE_TABLE(i2c, vc5_id); ··· 1232 { .compatible = "idt,5p49v5935", .data = &idt_5p49v5935_info }, 1233 { .compatible = "idt,5p49v6901", .data = &idt_5p49v6901_info }, 1234 { .compatible = "idt,5p49v6965", .data = &idt_5p49v6965_info }, 1235 + { .compatible = "idt,5p49v6975", .data = &idt_5p49v6975_info }, 1236 { }, 1237 }; 1238 MODULE_DEVICE_TABLE(of, clk_vc5_of_match);
+1311
drivers/clk/clk-versaclock7.c
···
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Common clock framework driver for the Versaclock7 family of timing devices. 4 + * 5 + * Copyright (c) 2022 Renesas Electronics Corporation 6 + */ 7 + 8 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9 + 10 + #include <linux/bitfield.h> 11 + #include <linux/clk.h> 12 + #include <linux/clk-provider.h> 13 + #include <linux/i2c.h> 14 + #include <linux/math64.h> 15 + #include <linux/module.h> 16 + #include <linux/of.h> 17 + #include <linux/of_platform.h> 18 + #include <linux/regmap.h> 19 + #include <linux/swab.h> 20 + 21 + /* 22 + * 16-bit register address: the lower 8 bits of the register address come 23 + * from the offset addr byte and the upper 8 bits come from the page register. 24 + */ 25 + #define VC7_PAGE_ADDR 0xFD 26 + #define VC7_PAGE_WINDOW 256 27 + #define VC7_MAX_REG 0x364 28 + 29 + /* Maximum number of banks supported by VC7 */ 30 + #define VC7_NUM_BANKS 7 31 + 32 + /* Maximum number of FODs supported by VC7 */ 33 + #define VC7_NUM_FOD 3 34 + 35 + /* Maximum number of IODs supported by VC7 */ 36 + #define VC7_NUM_IOD 4 37 + 38 + /* Maximum number of outputs supported by VC7 */ 39 + #define VC7_NUM_OUT 12 40 + 41 + /* VCO valid range is 9.5 GHz to 10.7 GHz */ 42 + #define VC7_APLL_VCO_MIN 9500000000UL 43 + #define VC7_APLL_VCO_MAX 10700000000UL 44 + 45 + /* APLL denominator is fixed at 2^27 */ 46 + #define VC7_APLL_DENOMINATOR_BITS 27 47 + 48 + /* FOD 1st stage denominator is fixed 2^34 */ 49 + #define VC7_FOD_DENOMINATOR_BITS 34 50 + 51 + /* IOD can operate between 1kHz and 650MHz */ 52 + #define VC7_IOD_RATE_MIN 1000UL 53 + #define VC7_IOD_RATE_MAX 650000000UL 54 + #define VC7_IOD_MIN_DIVISOR 14 55 + #define VC7_IOD_MAX_DIVISOR 0x1ffffff /* 25-bit */ 56 + 57 + #define VC7_FOD_RATE_MIN 1000UL 58 + #define VC7_FOD_RATE_MAX 650000000UL 59 + #define VC7_FOD_1ST_STAGE_RATE_MIN 33000000UL /* 33 MHz */ 60 + #define VC7_FOD_1ST_STAGE_RATE_MAX 650000000UL /* 650 MHz */ 61 + #define VC7_FOD_1ST_INT_MAX 324 62 + #define VC7_FOD_2ND_INT_MIN 2 63 + #define VC7_FOD_2ND_INT_MAX 0x1ffff /* 17-bit */ 64 + 65 + /* VC7 Registers */ 66 + 67 + #define VC7_REG_XO_CNFG 0x2C 68 + #define VC7_REG_XO_CNFG_COUNT 4 69 + #define VC7_REG_XO_IB_H_DIV_SHIFT 24 70 + #define VC7_REG_XO_IB_H_DIV_MASK GENMASK(28, VC7_REG_XO_IB_H_DIV_SHIFT) 71 + 72 + #define VC7_REG_APLL_FB_DIV_FRAC 0x120 73 + #define VC7_REG_APLL_FB_DIV_FRAC_COUNT 4 74 + #define VC7_REG_APLL_FB_DIV_FRAC_MASK GENMASK(26, 0) 75 + 76 + #define VC7_REG_APLL_FB_DIV_INT 0x124 77 + #define VC7_REG_APLL_FB_DIV_INT_COUNT 2 78 + #define VC7_REG_APLL_FB_DIV_INT_MASK GENMASK(9, 0) 79 + 80 + #define VC7_REG_APLL_CNFG 0x127 81 + #define VC7_REG_APLL_EN_DOUBLER BIT(0) 82 + 83 + #define VC7_REG_OUT_BANK_CNFG(idx) (0x280 + (0x4 * (idx))) 84 + #define VC7_REG_OUTPUT_BANK_SRC_MASK GENMASK(2, 0) 85 + 86 + #define VC7_REG_FOD_INT_CNFG(idx) (0x1E0 + (0x10 * (idx))) 87 + #define VC7_REG_FOD_INT_CNFG_COUNT 8 88 + #define VC7_REG_FOD_1ST_INT_MASK GENMASK(8, 0) 89 + #define VC7_REG_FOD_2ND_INT_SHIFT 9 90 + #define VC7_REG_FOD_2ND_INT_MASK GENMASK(25, VC7_REG_FOD_2ND_INT_SHIFT) 91 + #define VC7_REG_FOD_FRAC_SHIFT 26 92 + #define VC7_REG_FOD_FRAC_MASK GENMASK_ULL(59, VC7_REG_FOD_FRAC_SHIFT) 93 + 94 + #define VC7_REG_IOD_INT_CNFG(idx) (0x1C0 + (0x8 * (idx))) 95 + #define VC7_REG_IOD_INT_CNFG_COUNT 4 96 + #define VC7_REG_IOD_INT_MASK GENMASK(24, 0) 97 + 98 + #define VC7_REG_ODRV_EN(idx) (0x240 + (0x4 * (idx))) 99 + #define VC7_REG_OUT_DIS BIT(0) 100 + 101 + struct vc7_driver_data; 102 + static const struct regmap_config vc7_regmap_config; 103 + 104 + /* Supported Renesas VC7 models */ 105 + enum vc7_model { 106 + VC7_RC21008A, 107 + }; 108 + 109 + struct vc7_chip_info { 110 + const enum vc7_model model; 111 + const unsigned int banks[VC7_NUM_BANKS]; 112 + const unsigned int num_banks; 113 + const unsigned int outputs[VC7_NUM_OUT]; 114 + const unsigned int num_outputs; 115 + }; 116 + 117 + /* 118 + * Changing the APLL frequency is currently not supported. 119 + * The APLL will consist of an opaque block between the XO and FOD/IODs and 120 + * its frequency will be computed based on the current state of the device. 121 + */ 122 + struct vc7_apll_data { 123 + struct clk *clk; 124 + struct vc7_driver_data *vc7; 125 + u8 xo_ib_h_div; 126 + u8 en_doubler; 127 + u16 apll_fb_div_int; 128 + u32 apll_fb_div_frac; 129 + }; 130 + 131 + struct vc7_fod_data { 132 + struct clk_hw hw; 133 + struct vc7_driver_data *vc7; 134 + unsigned int num; 135 + u32 fod_1st_int; 136 + u32 fod_2nd_int; 137 + u64 fod_frac; 138 + }; 139 + 140 + struct vc7_iod_data { 141 + struct clk_hw hw; 142 + struct vc7_driver_data *vc7; 143 + unsigned int num; 144 + u32 iod_int; 145 + }; 146 + 147 + struct vc7_out_data { 148 + struct clk_hw hw; 149 + struct vc7_driver_data *vc7; 150 + unsigned int num; 151 + unsigned int out_dis; 152 + }; 153 + 154 + struct vc7_driver_data { 155 + struct i2c_client *client; 156 + struct regmap *regmap; 157 + const struct vc7_chip_info *chip_info; 158 + 159 + struct clk *pin_xin; 160 + struct vc7_apll_data clk_apll; 161 + struct vc7_fod_data clk_fod[VC7_NUM_FOD]; 162 + struct vc7_iod_data clk_iod[VC7_NUM_IOD]; 163 + struct vc7_out_data clk_out[VC7_NUM_OUT]; 164 + }; 165 + 166 + struct vc7_bank_src_map { 167 + enum vc7_bank_src_type { 168 + VC7_FOD, 169 + VC7_IOD, 170 + } type; 171 + union _divider { 172 + struct vc7_iod_data *iod; 173 + struct vc7_fod_data *fod; 174 + } src; 175 + }; 176 + 177 + static struct clk_hw *vc7_of_clk_get(struct of_phandle_args *clkspec, 178 + void *data) 179 + { 180 + struct vc7_driver_data *vc7 = data; 181 + unsigned int idx = clkspec->args[0]; 182 + 183 + if (idx >= vc7->chip_info->num_outputs) 184 + return ERR_PTR(-EINVAL); 185 + 186 + return &vc7->clk_out[idx].hw; 187 + } 188 + 189 + static const unsigned int RC21008A_index_to_output_mapping[] = { 190 + 1, 2, 3, 6, 7, 8, 10, 11 191 + }; 192 + 193 + static int vc7_map_index_to_output(const enum vc7_model model, const unsigned int i) 194 + { 195 + switch (model) { 196 + case VC7_RC21008A: 197 + return RC21008A_index_to_output_mapping[i]; 198 + default: 199 + return i; 200 + } 201 + } 202 + 203 + /* bank to output mapping, same across all variants */ 204 + static const unsigned int output_bank_mapping[] = { 205 + 0, /* Output 0 */ 206 + 1, /* Output 1 */ 207 + 2, /* Output 2 */ 208 + 2, /* Output 3 */ 209 + 3, /* Output 4 */ 210 + 3, /* Output 5 */ 211 + 3, /* Output 6 */ 212 + 3, /* Output 7 */ 213 + 4, /* Output 8 */ 214 + 4, /* Output 9 */ 215 + 5, /* Output 10 */ 216 + 6 /* Output 11 */ 217 + }; 218 + 219 + /** 220 + * vc7_64_mul_64_to_128() - Multiply two u64 and return an unsigned 128-bit integer 221 + * as an upper and lower part. 222 + * 223 + * @left: The left argument. 224 + * @right: The right argument. 225 + * @hi: The upper 64-bits of the 128-bit product. 226 + * @lo: The lower 64-bits of the 128-bit product. 227 + * 228 + * From mul_64_64 in crypto/ecc.c:350 in the linux kernel, accessed in v5.17.2. 229 + */ 230 + static void vc7_64_mul_64_to_128(u64 left, u64 right, u64 *hi, u64 *lo) 231 + { 232 + u64 a0 = left & 0xffffffffull; 233 + u64 a1 = left >> 32; 234 + u64 b0 = right & 0xffffffffull; 235 + u64 b1 = right >> 32; 236 + u64 m0 = a0 * b0; 237 + u64 m1 = a0 * b1; 238 + u64 m2 = a1 * b0; 239 + u64 m3 = a1 * b1; 240 + 241 + m2 += (m0 >> 32); 242 + m2 += m1; 243 + 244 + /* Overflow */ 245 + if (m2 < m1) 246 + m3 += 0x100000000ull; 247 + 248 + *lo = (m0 & 0xffffffffull) | (m2 << 32); 249 + *hi = m3 + (m2 >> 32); 250 + } 251 + 252 + /** 253 + * vc7_128_div_64_to_64() - Divides a 128-bit uint by a 64-bit divisor, return a 64-bit quotient. 254 + * 255 + * @numhi: The uppper 64-bits of the dividend. 256 + * @numlo: The lower 64-bits of the dividend. 257 + * @den: The denominator (divisor). 258 + * @r: The remainder, pass NULL if the remainder is not needed. 259 + * 260 + * Originally from libdivide, modified to use kernel u64/u32 types. 261 + * 262 + * See https://github.com/ridiculousfish/libdivide/blob/master/libdivide.h#L471. 263 + * 264 + * Return: The 64-bit quotient of the division. 265 + * 266 + * In case of overflow of division by zero, max(u64) is returned. 267 + */ 268 + static u64 vc7_128_div_64_to_64(u64 numhi, u64 numlo, u64 den, u64 *r) 269 + { 270 + /* 271 + * We work in base 2**32. 272 + * A uint32 holds a single digit. A uint64 holds two digits. 273 + * Our numerator is conceptually [num3, num2, num1, num0]. 274 + * Our denominator is [den1, den0]. 275 + */ 276 + const u64 b = ((u64)1 << 32); 277 + 278 + /* The high and low digits of our computed quotient. */ 279 + u32 q1, q0; 280 + 281 + /* The normalization shift factor */ 282 + int shift; 283 + 284 + /* 285 + * The high and low digits of our denominator (after normalizing). 286 + * Also the low 2 digits of our numerator (after normalizing). 287 + */ 288 + u32 den1, den0, num1, num0; 289 + 290 + /* A partial remainder; */ 291 + u64 rem; 292 + 293 + /* 294 + * The estimated quotient, and its corresponding remainder (unrelated 295 + * to true remainder). 296 + */ 297 + u64 qhat, rhat; 298 + 299 + /* Variables used to correct the estimated quotient. */ 300 + u64 c1, c2; 301 + 302 + /* Check for overflow and divide by 0. */ 303 + if (numhi >= den) { 304 + if (r) 305 + *r = ~0ull; 306 + return ~0ull; 307 + } 308 + 309 + /* 310 + * Determine the normalization factor. We multiply den by this, so that 311 + * its leading digit is at least half b. In binary this means just 312 + * shifting left by the number of leading zeros, so that there's a 1 in 313 + * the MSB. 314 + * 315 + * We also shift numer by the same amount. This cannot overflow because 316 + * numhi < den. The expression (-shift & 63) is the same as (64 - 317 + * shift), except it avoids the UB of shifting by 64. The funny bitwise 318 + * 'and' ensures that numlo does not get shifted into numhi if shift is 319 + * 0. clang 11 has an x86 codegen bug here: see LLVM bug 50118. The 320 + * sequence below avoids it. 321 + */ 322 + shift = __builtin_clzll(den); 323 + den <<= shift; 324 + numhi <<= shift; 325 + numhi |= (numlo >> (-shift & 63)) & (-(s64)shift >> 63); 326 + numlo <<= shift; 327 + 328 + /* 329 + * Extract the low digits of the numerator and both digits of the 330 + * denominator. 331 + */ 332 + num1 = (u32)(numlo >> 32); 333 + num0 = (u32)(numlo & 0xFFFFFFFFu); 334 + den1 = (u32)(den >> 32); 335 + den0 = (u32)(den & 0xFFFFFFFFu); 336 + 337 + /* 338 + * We wish to compute q1 = [n3 n2 n1] / [d1 d0]. 339 + * Estimate q1 as [n3 n2] / [d1], and then correct it. 340 + * Note while qhat may be 2 digits, q1 is always 1 digit. 341 + */ 342 + qhat = div64_u64_rem(numhi, den1, &rhat); 343 + c1 = qhat * den0; 344 + c2 = rhat * b + num1; 345 + if (c1 > c2) 346 + qhat -= (c1 - c2 > den) ? 2 : 1; 347 + q1 = (u32)qhat; 348 + 349 + /* Compute the true (partial) remainder. */ 350 + rem = numhi * b + num1 - q1 * den; 351 + 352 + /* 353 + * We wish to compute q0 = [rem1 rem0 n0] / [d1 d0]. 354 + * Estimate q0 as [rem1 rem0] / [d1] and correct it. 355 + */ 356 + qhat = div64_u64_rem(rem, den1, &rhat); 357 + c1 = qhat * den0; 358 + c2 = rhat * b + num0; 359 + if (c1 > c2) 360 + qhat -= (c1 - c2 > den) ? 2 : 1; 361 + q0 = (u32)qhat; 362 + 363 + /* Return remainder if requested. */ 364 + if (r) 365 + *r = (rem * b + num0 - q0 * den) >> shift; 366 + return ((u64)q1 << 32) | q0; 367 + } 368 + 369 + static int vc7_get_bank_clk(struct vc7_driver_data *vc7, 370 + unsigned int bank_idx, 371 + unsigned int output_bank_src, 372 + struct vc7_bank_src_map *map) 373 + { 374 + /* Mapping from Table 38 in datasheet */ 375 + if (bank_idx == 0 || bank_idx == 1) { 376 + switch (output_bank_src) { 377 + case 0: 378 + map->type = VC7_IOD, 379 + map->src.iod = &vc7->clk_iod[0]; 380 + return 0; 381 + case 1: 382 + map->type = VC7_IOD, 383 + map->src.iod = &vc7->clk_iod[1]; 384 + return 0; 385 + case 4: 386 + map->type = VC7_FOD, 387 + map->src.fod = &vc7->clk_fod[0]; 388 + return 0; 389 + case 5: 390 + map->type = VC7_FOD, 391 + map->src.fod = &vc7->clk_fod[1]; 392 + return 0; 393 + default: 394 + break; 395 + } 396 + } else if (bank_idx == 2) { 397 + switch (output_bank_src) { 398 + case 1: 399 + map->type = VC7_IOD, 400 + map->src.iod = &vc7->clk_iod[1]; 401 + return 0; 402 + case 4: 403 + map->type = VC7_FOD, 404 + map->src.fod = &vc7->clk_fod[0]; 405 + return 0; 406 + case 5: 407 + map->type = VC7_FOD, 408 + map->src.fod = &vc7->clk_fod[1]; 409 + return 0; 410 + default: 411 + break; 412 + } 413 + } else if (bank_idx == 3) { 414 + switch (output_bank_src) { 415 + case 4: 416 + map->type = VC7_FOD, 417 + map->src.fod = &vc7->clk_fod[0]; 418 + return 0; 419 + case 5: 420 + map->type = VC7_FOD, 421 + map->src.fod = &vc7->clk_fod[1]; 422 + return 0; 423 + case 6: 424 + map->type = VC7_FOD, 425 + map->src.fod = &vc7->clk_fod[2]; 426 + return 0; 427 + default: 428 + break; 429 + } 430 + } else if (bank_idx == 4) { 431 + switch (output_bank_src) { 432 + case 0: 433 + /* CLKIN1 not supported in this driver */ 434 + break; 435 + case 2: 436 + map->type = VC7_IOD, 437 + map->src.iod = &vc7->clk_iod[2]; 438 + return 0; 439 + case 5: 440 + map->type = VC7_FOD, 441 + map->src.fod = &vc7->clk_fod[1]; 442 + return 0; 443 + case 6: 444 + map->type = VC7_FOD, 445 + map->src.fod = &vc7->clk_fod[2]; 446 + return 0; 447 + case 7: 448 + /* CLKIN0 not supported in this driver */ 449 + break; 450 + default: 451 + break; 452 + } 453 + } else if (bank_idx == 5) { 454 + switch (output_bank_src) { 455 + case 0: 456 + /* CLKIN1 not supported in this driver */ 457 + break; 458 + case 1: 459 + /* XIN_REFIN not supported in this driver */ 460 + break; 461 + case 2: 462 + map->type = VC7_IOD, 463 + map->src.iod = &vc7->clk_iod[2]; 464 + return 0; 465 + case 3: 466 + map->type = VC7_IOD, 467 + map->src.iod = &vc7->clk_iod[3]; 468 + return 0; 469 + case 5: 470 + map->type = VC7_FOD, 471 + map->src.fod = &vc7->clk_fod[1]; 472 + return 0; 473 + case 6: 474 + map->type = VC7_FOD, 475 + map->src.fod = &vc7->clk_fod[2]; 476 + return 0; 477 + case 7: 478 + /* CLKIN0 not supported in this driver */ 479 + break; 480 + default: 481 + break; 482 + } 483 + } else if (bank_idx == 6) { 484 + switch (output_bank_src) { 485 + case 0: 486 + /* CLKIN1 not supported in this driver */ 487 + break; 488 + case 2: 489 + map->type = VC7_IOD, 490 + map->src.iod = &vc7->clk_iod[2]; 491 + return 0; 492 + case 3: 493 + map->type = VC7_IOD, 494 + map->src.iod = &vc7->clk_iod[3]; 495 + return 0; 496 + case 5: 497 + map->type = VC7_FOD, 498 + map->src.fod = &vc7->clk_fod[1]; 499 + return 0; 500 + case 6: 501 + map->type = VC7_FOD, 502 + map->src.fod = &vc7->clk_fod[2]; 503 + return 0; 504 + case 7: 505 + /* CLKIN0 not supported in this driver */ 506 + break; 507 + default: 508 + break; 509 + } 510 + } 511 + 512 + pr_warn("bank_src%d = %d is not supported\n", bank_idx, output_bank_src); 513 + return -1; 514 + } 515 + 516 + static int vc7_read_apll(struct vc7_driver_data *vc7) 517 + { 518 + int err; 519 + u32 val32; 520 + u16 val16; 521 + 522 + err = regmap_bulk_read(vc7->regmap, 523 + VC7_REG_XO_CNFG, 524 + (u32 *)&val32, 525 + VC7_REG_XO_CNFG_COUNT); 526 + if (err) { 527 + dev_err(&vc7->client->dev, "failed to read XO_CNFG\n"); 528 + return err; 529 + } 530 + 531 + vc7->clk_apll.xo_ib_h_div = (val32 & VC7_REG_XO_IB_H_DIV_MASK) 532 + >> VC7_REG_XO_IB_H_DIV_SHIFT; 533 + 534 + err = regmap_read(vc7->regmap, 535 + VC7_REG_APLL_CNFG, 536 + &val32); 537 + if (err) { 538 + dev_err(&vc7->client->dev, "failed to read APLL_CNFG\n"); 539 + return err; 540 + } 541 + 542 + vc7->clk_apll.en_doubler = val32 & VC7_REG_APLL_EN_DOUBLER; 543 + 544 + err = regmap_bulk_read(vc7->regmap, 545 + VC7_REG_APLL_FB_DIV_FRAC, 546 + (u32 *)&val32, 547 + VC7_REG_APLL_FB_DIV_FRAC_COUNT); 548 + if (err) { 549 + dev_err(&vc7->client->dev, "failed to read APLL_FB_DIV_FRAC\n"); 550 + return err; 551 + } 552 + 553 + vc7->clk_apll.apll_fb_div_frac = val32 & VC7_REG_APLL_FB_DIV_FRAC_MASK; 554 + 555 + err = regmap_bulk_read(vc7->regmap, 556 + VC7_REG_APLL_FB_DIV_INT, 557 + (u16 *)&val16, 558 + VC7_REG_APLL_FB_DIV_INT_COUNT); 559 + if (err) { 560 + dev_err(&vc7->client->dev, "failed to read APLL_FB_DIV_INT\n"); 561 + return err; 562 + } 563 + 564 + vc7->clk_apll.apll_fb_div_int = val16 & VC7_REG_APLL_FB_DIV_INT_MASK; 565 + 566 + return 0; 567 + } 568 + 569 + static int vc7_read_fod(struct vc7_driver_data *vc7, unsigned int idx) 570 + { 571 + int err; 572 + u64 val; 573 + 574 + err = regmap_bulk_read(vc7->regmap, 575 + VC7_REG_FOD_INT_CNFG(idx), 576 + (u64 *)&val, 577 + VC7_REG_FOD_INT_CNFG_COUNT); 578 + if (err) { 579 + dev_err(&vc7->client->dev, "failed to read FOD%d\n", idx); 580 + return err; 581 + } 582 + 583 + vc7->clk_fod[idx].fod_1st_int = (val & VC7_REG_FOD_1ST_INT_MASK); 584 + vc7->clk_fod[idx].fod_2nd_int = 585 + (val & VC7_REG_FOD_2ND_INT_MASK) >> VC7_REG_FOD_2ND_INT_SHIFT; 586 + vc7->clk_fod[idx].fod_frac = (val & VC7_REG_FOD_FRAC_MASK) 587 + >> VC7_REG_FOD_FRAC_SHIFT; 588 + 589 + return 0; 590 + } 591 + 592 + static int vc7_write_fod(struct vc7_driver_data *vc7, unsigned int idx) 593 + { 594 + int err; 595 + u64 val; 596 + 597 + /* 598 + * FOD dividers are part of an atomic group where fod_1st_int, 599 + * fod_2nd_int, and fod_frac must be written together. The new divider 600 + * is applied when the MSB of fod_frac is written. 601 + */ 602 + 603 + err = regmap_bulk_read(vc7->regmap, 604 + VC7_REG_FOD_INT_CNFG(idx), 605 + (u64 *)&val, 606 + VC7_REG_FOD_INT_CNFG_COUNT); 607 + if (err) { 608 + dev_err(&vc7->client->dev, "failed to read FOD%d\n", idx); 609 + return err; 610 + } 611 + 612 + val = u64_replace_bits(val, 613 + vc7->clk_fod[idx].fod_1st_int, 614 + VC7_REG_FOD_1ST_INT_MASK); 615 + val = u64_replace_bits(val, 616 + vc7->clk_fod[idx].fod_2nd_int, 617 + VC7_REG_FOD_2ND_INT_MASK); 618 + val = u64_replace_bits(val, 619 + vc7->clk_fod[idx].fod_frac, 620 + VC7_REG_FOD_FRAC_MASK); 621 + 622 + err = regmap_bulk_write(vc7->regmap, 623 + VC7_REG_FOD_INT_CNFG(idx), 624 + (u64 *)&val, 625 + sizeof(u64)); 626 + if (err) { 627 + dev_err(&vc7->client->dev, "failed to write FOD%d\n", idx); 628 + return err; 629 + } 630 + 631 + return 0; 632 + } 633 + 634 + static int vc7_read_iod(struct vc7_driver_data *vc7, unsigned int idx) 635 + { 636 + int err; 637 + u32 val; 638 + 639 + err = regmap_bulk_read(vc7->regmap, 640 + VC7_REG_IOD_INT_CNFG(idx), 641 + (u32 *)&val, 642 + VC7_REG_IOD_INT_CNFG_COUNT); 643 + if (err) { 644 + dev_err(&vc7->client->dev, "failed to read IOD%d\n", idx); 645 + return err; 646 + } 647 + 648 + vc7->clk_iod[idx].iod_int = (val & VC7_REG_IOD_INT_MASK); 649 + 650 + return 0; 651 + } 652 + 653 + static int vc7_write_iod(struct vc7_driver_data *vc7, unsigned int idx) 654 + { 655 + int err; 656 + u32 val; 657 + 658 + /* 659 + * IOD divider field is atomic and all bits must be written. 660 + * The new divider is applied when the MSB of iod_int is written. 661 + */ 662 + 663 + err = regmap_bulk_read(vc7->regmap, 664 + VC7_REG_IOD_INT_CNFG(idx), 665 + (u32 *)&val, 666 + VC7_REG_IOD_INT_CNFG_COUNT); 667 + if (err) { 668 + dev_err(&vc7->client->dev, "failed to read IOD%d\n", idx); 669 + return err; 670 + } 671 + 672 + val = u32_replace_bits(val, 673 + vc7->clk_iod[idx].iod_int, 674 + VC7_REG_IOD_INT_MASK); 675 + 676 + err = regmap_bulk_write(vc7->regmap, 677 + VC7_REG_IOD_INT_CNFG(idx), 678 + (u32 *)&val, 679 + sizeof(u32)); 680 + if (err) { 681 + dev_err(&vc7->client->dev, "failed to write IOD%d\n", idx); 682 + return err; 683 + } 684 + 685 + return 0; 686 + } 687 + 688 + static int vc7_read_output(struct vc7_driver_data *vc7, unsigned int idx) 689 + { 690 + int err; 691 + unsigned int val, out_num; 692 + 693 + out_num = vc7_map_index_to_output(vc7->chip_info->model, idx); 694 + err = regmap_read(vc7->regmap, 695 + VC7_REG_ODRV_EN(out_num), 696 + &val); 697 + if (err) { 698 + dev_err(&vc7->client->dev, "failed to read ODRV_EN[%d]\n", idx); 699 + return err; 700 + } 701 + 702 + vc7->clk_out[idx].out_dis = val & VC7_REG_OUT_DIS; 703 + 704 + return 0; 705 + } 706 + 707 + static int vc7_write_output(struct vc7_driver_data *vc7, unsigned int idx) 708 + { 709 + int err; 710 + unsigned int out_num; 711 + 712 + out_num = vc7_map_index_to_output(vc7->chip_info->model, idx); 713 + err = regmap_write_bits(vc7->regmap, 714 + VC7_REG_ODRV_EN(out_num), 715 + VC7_REG_OUT_DIS, 716 + vc7->clk_out[idx].out_dis); 717 + 718 + if (err) { 719 + dev_err(&vc7->client->dev, "failed to write ODRV_EN[%d]\n", idx); 720 + return err; 721 + } 722 + 723 + return 0; 724 + } 725 + 726 + static unsigned long vc7_get_apll_rate(struct vc7_driver_data *vc7) 727 + { 728 + int err; 729 + unsigned long xtal_rate; 730 + u64 refin_div, apll_rate; 731 + 732 + xtal_rate = clk_get_rate(vc7->pin_xin); 733 + err = vc7_read_apll(vc7); 734 + if (err) { 735 + dev_err(&vc7->client->dev, "unable to read apll\n"); 736 + return err; 737 + } 738 + 739 + /* 0 is bypassed, 1 is reserved */ 740 + if (vc7->clk_apll.xo_ib_h_div < 2) 741 + refin_div = xtal_rate; 742 + else 743 + refin_div = div64_u64(xtal_rate, vc7->clk_apll.xo_ib_h_div); 744 + 745 + if (vc7->clk_apll.en_doubler) 746 + refin_div *= 2; 747 + 748 + /* divider = int + (frac / 2^27) */ 749 + apll_rate = (refin_div * vc7->clk_apll.apll_fb_div_int) + 750 + ((refin_div * vc7->clk_apll.apll_fb_div_frac) >> VC7_APLL_DENOMINATOR_BITS); 751 + 752 + pr_debug("%s - xo_ib_h_div: %u, apll_fb_div_int: %u, apll_fb_div_frac: %u\n", 753 + __func__, vc7->clk_apll.xo_ib_h_div, vc7->clk_apll.apll_fb_div_int, 754 + vc7->clk_apll.apll_fb_div_frac); 755 + pr_debug("%s - refin_div: %llu, apll rate: %llu\n", 756 + __func__, refin_div, apll_rate); 757 + 758 + return apll_rate; 759 + } 760 + 761 + static void vc7_calc_iod_divider(unsigned long rate, unsigned long parent_rate, 762 + u32 *divider) 763 + { 764 + *divider = DIV_ROUND_UP(parent_rate, rate); 765 + if (*divider < VC7_IOD_MIN_DIVISOR) 766 + *divider = VC7_IOD_MIN_DIVISOR; 767 + if (*divider > VC7_IOD_MAX_DIVISOR) 768 + *divider = VC7_IOD_MAX_DIVISOR; 769 + } 770 + 771 + static void vc7_calc_fod_1st_stage(unsigned long rate, unsigned long parent_rate, 772 + u32 *div_int, u64 *div_frac) 773 + { 774 + u64 rem; 775 + 776 + *div_int = (u32)div64_u64_rem(parent_rate, rate, &rem); 777 + *div_frac = div64_u64(rem << VC7_FOD_DENOMINATOR_BITS, rate); 778 + } 779 + 780 + static unsigned long vc7_calc_fod_1st_stage_rate(unsigned long parent_rate, 781 + u32 fod_1st_int, u64 fod_frac) 782 + { 783 + u64 numer, denom, hi, lo, divisor; 784 + 785 + numer = fod_frac; 786 + denom = BIT_ULL(VC7_FOD_DENOMINATOR_BITS); 787 + 788 + if (fod_frac) { 789 + vc7_64_mul_64_to_128(parent_rate, denom, &hi, &lo); 790 + divisor = ((u64)fod_1st_int * denom) + numer; 791 + return vc7_128_div_64_to_64(hi, lo, divisor, NULL); 792 + } 793 + 794 + return div64_u64(parent_rate, fod_1st_int); 795 + } 796 + 797 + static unsigned long vc7_calc_fod_2nd_stage_rate(unsigned long parent_rate, 798 + u32 fod_1st_int, u32 fod_2nd_int, u64 fod_frac) 799 + { 800 + unsigned long fod_1st_stage_rate; 801 + 802 + fod_1st_stage_rate = vc7_calc_fod_1st_stage_rate(parent_rate, fod_1st_int, fod_frac); 803 + 804 + if (fod_2nd_int < 2) 805 + return fod_1st_stage_rate; 806 + 807 + /* 808 + * There is a div-by-2 preceding the 2nd stage integer divider 809 + * (not shown on block diagram) so the actual 2nd stage integer 810 + * divisor is 2 * N. 811 + */ 812 + return div64_u64(fod_1st_stage_rate >> 1, fod_2nd_int); 813 + } 814 + 815 + static void vc7_calc_fod_divider(unsigned long rate, unsigned long parent_rate, 816 + u32 *fod_1st_int, u32 *fod_2nd_int, u64 *fod_frac) 817 + { 818 + unsigned int allow_frac, i, best_frac_i; 819 + unsigned long first_stage_rate; 820 + 821 + vc7_calc_fod_1st_stage(rate, parent_rate, fod_1st_int, fod_frac); 822 + first_stage_rate = vc7_calc_fod_1st_stage_rate(parent_rate, *fod_1st_int, *fod_frac); 823 + 824 + *fod_2nd_int = 0; 825 + 826 + /* Do we need the second stage integer divider? */ 827 + if (first_stage_rate < VC7_FOD_1ST_STAGE_RATE_MIN) { 828 + allow_frac = 0; 829 + best_frac_i = VC7_FOD_2ND_INT_MIN; 830 + 831 + for (i = VC7_FOD_2ND_INT_MIN; i <= VC7_FOD_2ND_INT_MAX; i++) { 832 + /* 833 + * 1) There is a div-by-2 preceding the 2nd stage integer divider 834 + * (not shown on block diagram) so the actual 2nd stage integer 835 + * divisor is 2 * N. 836 + * 2) Attempt to find an integer solution first. This means stepping 837 + * through each 2nd stage integer and recalculating the 1st stage 838 + * until the 1st stage frequency is out of bounds. If no integer 839 + * solution is found, use the best fractional solution. 840 + */ 841 + vc7_calc_fod_1st_stage(parent_rate, rate * 2 * i, fod_1st_int, fod_frac); 842 + first_stage_rate = vc7_calc_fod_1st_stage_rate(parent_rate, 843 + *fod_1st_int, 844 + *fod_frac); 845 + 846 + /* Remember the first viable fractional solution */ 847 + if (best_frac_i == VC7_FOD_2ND_INT_MIN && 848 + first_stage_rate > VC7_FOD_1ST_STAGE_RATE_MIN) { 849 + best_frac_i = i; 850 + } 851 + 852 + /* Is the divider viable? Prefer integer solutions over fractional. */ 853 + if (*fod_1st_int < VC7_FOD_1ST_INT_MAX && 854 + first_stage_rate >= VC7_FOD_1ST_STAGE_RATE_MIN && 855 + (allow_frac || *fod_frac == 0)) { 856 + *fod_2nd_int = i; 857 + break; 858 + } 859 + 860 + /* Ran out of divisors or the 1st stage frequency is out of range */ 861 + if (i >= VC7_FOD_2ND_INT_MAX || 862 + first_stage_rate > VC7_FOD_1ST_STAGE_RATE_MAX) { 863 + allow_frac = 1; 864 + i = best_frac_i; 865 + 866 + /* Restore the best frac and rerun the loop for the last time */ 867 + if (best_frac_i != VC7_FOD_2ND_INT_MIN) 868 + i--; 869 + 870 + continue; 871 + } 872 + } 873 + } 874 + } 875 + 876 + static unsigned long vc7_fod_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 877 + { 878 + struct vc7_fod_data *fod = container_of(hw, struct vc7_fod_data, hw); 879 + struct vc7_driver_data *vc7 = fod->vc7; 880 + int err; 881 + unsigned long fod_rate; 882 + 883 + err = vc7_read_fod(vc7, fod->num); 884 + if (err) { 885 + dev_err(&vc7->client->dev, "error reading registers for %s\n", 886 + clk_hw_get_name(hw)); 887 + return err; 888 + } 889 + 890 + pr_debug("%s - %s: parent_rate: %lu\n", __func__, clk_hw_get_name(hw), parent_rate); 891 + 892 + fod_rate = vc7_calc_fod_2nd_stage_rate(parent_rate, fod->fod_1st_int, 893 + fod->fod_2nd_int, fod->fod_frac); 894 + 895 + pr_debug("%s - %s: fod_1st_int: %u, fod_2nd_int: %u, fod_frac: %llu\n", 896 + __func__, clk_hw_get_name(hw), 897 + fod->fod_1st_int, fod->fod_2nd_int, fod->fod_frac); 898 + pr_debug("%s - %s rate: %lu\n", __func__, clk_hw_get_name(hw), fod_rate); 899 + 900 + return fod_rate; 901 + } 902 + 903 + static long vc7_fod_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) 904 + { 905 + struct vc7_fod_data *fod = container_of(hw, struct vc7_fod_data, hw); 906 + unsigned long fod_rate; 907 + 908 + pr_debug("%s - %s: requested rate: %lu, parent_rate: %lu\n", 909 + __func__, clk_hw_get_name(hw), rate, *parent_rate); 910 + 911 + vc7_calc_fod_divider(rate, *parent_rate, 912 + &fod->fod_1st_int, &fod->fod_2nd_int, &fod->fod_frac); 913 + fod_rate = vc7_calc_fod_2nd_stage_rate(*parent_rate, fod->fod_1st_int, 914 + fod->fod_2nd_int, fod->fod_frac); 915 + 916 + pr_debug("%s - %s: fod_1st_int: %u, fod_2nd_int: %u, fod_frac: %llu\n", 917 + __func__, clk_hw_get_name(hw), 918 + fod->fod_1st_int, fod->fod_2nd_int, fod->fod_frac); 919 + pr_debug("%s - %s rate: %lu\n", __func__, clk_hw_get_name(hw), fod_rate); 920 + 921 + return fod_rate; 922 + } 923 + 924 + static int vc7_fod_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) 925 + { 926 + struct vc7_fod_data *fod = container_of(hw, struct vc7_fod_data, hw); 927 + struct vc7_driver_data *vc7 = fod->vc7; 928 + unsigned long fod_rate; 929 + 930 + pr_debug("%s - %s: rate: %lu, parent_rate: %lu\n", 931 + __func__, clk_hw_get_name(hw), rate, parent_rate); 932 + 933 + if (rate < VC7_FOD_RATE_MIN || rate > VC7_FOD_RATE_MAX) { 934 + dev_err(&vc7->client->dev, 935 + "requested frequency %lu Hz for %s is out of range\n", 936 + rate, clk_hw_get_name(hw)); 937 + return -EINVAL; 938 + } 939 + 940 + vc7_write_fod(vc7, fod->num); 941 + 942 + fod_rate = vc7_calc_fod_2nd_stage_rate(parent_rate, fod->fod_1st_int, 943 + fod->fod_2nd_int, fod->fod_frac); 944 + 945 + pr_debug("%s - %s: fod_1st_int: %u, fod_2nd_int: %u, fod_frac: %llu\n", 946 + __func__, clk_hw_get_name(hw), 947 + fod->fod_1st_int, fod->fod_2nd_int, fod->fod_frac); 948 + pr_debug("%s - %s rate: %lu\n", __func__, clk_hw_get_name(hw), fod_rate); 949 + 950 + return 0; 951 + } 952 + 953 + static const struct clk_ops vc7_fod_ops = { 954 + .recalc_rate = vc7_fod_recalc_rate, 955 + .round_rate = vc7_fod_round_rate, 956 + .set_rate = vc7_fod_set_rate, 957 + }; 958 + 959 + static unsigned long vc7_iod_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) 960 + { 961 + struct vc7_iod_data *iod = container_of(hw, struct vc7_iod_data, hw); 962 + struct vc7_driver_data *vc7 = iod->vc7; 963 + int err; 964 + unsigned long iod_rate; 965 + 966 + err = vc7_read_iod(vc7, iod->num); 967 + if (err) { 968 + dev_err(&vc7->client->dev, "error reading registers for %s\n", 969 + clk_hw_get_name(hw)); 970 + return err; 971 + } 972 + 973 + iod_rate = div64_u64(parent_rate, iod->iod_int); 974 + 975 + pr_debug("%s - %s: iod_int: %u\n", __func__, clk_hw_get_name(hw), iod->iod_int); 976 + pr_debug("%s - %s rate: %lu\n", __func__, clk_hw_get_name(hw), iod_rate); 977 + 978 + return iod_rate; 979 + } 980 + 981 + static long vc7_iod_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) 982 + { 983 + struct vc7_iod_data *iod = container_of(hw, struct vc7_iod_data, hw); 984 + unsigned long iod_rate; 985 + 986 + pr_debug("%s - %s: requested rate: %lu, parent_rate: %lu\n", 987 + __func__, clk_hw_get_name(hw), rate, *parent_rate); 988 + 989 + vc7_calc_iod_divider(rate, *parent_rate, &iod->iod_int); 990 + iod_rate = div64_u64(*parent_rate, iod->iod_int); 991 + 992 + pr_debug("%s - %s: iod_int: %u\n", __func__, clk_hw_get_name(hw), iod->iod_int); 993 + pr_debug("%s - %s rate: %ld\n", __func__, clk_hw_get_name(hw), iod_rate); 994 + 995 + return iod_rate; 996 + } 997 + 998 + static int vc7_iod_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) 999 + { 1000 + struct vc7_iod_data *iod = container_of(hw, struct vc7_iod_data, hw); 1001 + struct vc7_driver_data *vc7 = iod->vc7; 1002 + unsigned long iod_rate; 1003 + 1004 + pr_debug("%s - %s: rate: %lu, parent_rate: %lu\n", 1005 + __func__, clk_hw_get_name(hw), rate, parent_rate); 1006 + 1007 + if (rate < VC7_IOD_RATE_MIN || rate > VC7_IOD_RATE_MAX) { 1008 + dev_err(&vc7->client->dev, 1009 + "requested frequency %lu Hz for %s is out of range\n", 1010 + rate, clk_hw_get_name(hw)); 1011 + return -EINVAL; 1012 + } 1013 + 1014 + vc7_write_iod(vc7, iod->num); 1015 + 1016 + iod_rate = div64_u64(parent_rate, iod->iod_int); 1017 + 1018 + pr_debug("%s - %s: iod_int: %u\n", __func__, clk_hw_get_name(hw), iod->iod_int); 1019 + pr_debug("%s - %s rate: %ld\n", __func__, clk_hw_get_name(hw), iod_rate); 1020 + 1021 + return 0; 1022 + } 1023 + 1024 + static const struct clk_ops vc7_iod_ops = { 1025 + .recalc_rate = vc7_iod_recalc_rate, 1026 + .round_rate = vc7_iod_round_rate, 1027 + .set_rate = vc7_iod_set_rate, 1028 + }; 1029 + 1030 + static int vc7_clk_out_prepare(struct clk_hw *hw) 1031 + { 1032 + struct vc7_out_data *out = container_of(hw, struct vc7_out_data, hw); 1033 + struct vc7_driver_data *vc7 = out->vc7; 1034 + int err; 1035 + 1036 + out->out_dis = 0; 1037 + 1038 + err = vc7_write_output(vc7, out->num); 1039 + if (err) { 1040 + dev_err(&vc7->client->dev, "error writing registers for %s\n", 1041 + clk_hw_get_name(hw)); 1042 + return err; 1043 + } 1044 + 1045 + pr_debug("%s - %s: clk prepared\n", __func__, clk_hw_get_name(hw)); 1046 + 1047 + return 0; 1048 + } 1049 + 1050 + static void vc7_clk_out_unprepare(struct clk_hw *hw) 1051 + { 1052 + struct vc7_out_data *out = container_of(hw, struct vc7_out_data, hw); 1053 + struct vc7_driver_data *vc7 = out->vc7; 1054 + int err; 1055 + 1056 + out->out_dis = 1; 1057 + 1058 + err = vc7_write_output(vc7, out->num); 1059 + if (err) { 1060 + dev_err(&vc7->client->dev, "error writing registers for %s\n", 1061 + clk_hw_get_name(hw)); 1062 + return; 1063 + } 1064 + 1065 + pr_debug("%s - %s: clk unprepared\n", __func__, clk_hw_get_name(hw)); 1066 + } 1067 + 1068 + static int vc7_clk_out_is_enabled(struct clk_hw *hw) 1069 + { 1070 + struct vc7_out_data *out = container_of(hw, struct vc7_out_data, hw); 1071 + struct vc7_driver_data *vc7 = out->vc7; 1072 + int err, is_enabled; 1073 + 1074 + err = vc7_read_output(vc7, out->num); 1075 + if (err) { 1076 + dev_err(&vc7->client->dev, "error reading registers for %s\n", 1077 + clk_hw_get_name(hw)); 1078 + return err; 1079 + } 1080 + 1081 + is_enabled = !out->out_dis; 1082 + 1083 + pr_debug("%s - %s: is_enabled=%d\n", __func__, clk_hw_get_name(hw), is_enabled); 1084 + 1085 + return is_enabled; 1086 + } 1087 + 1088 + static const struct clk_ops vc7_clk_out_ops = { 1089 + .prepare = vc7_clk_out_prepare, 1090 + .unprepare = vc7_clk_out_unprepare, 1091 + .is_enabled = vc7_clk_out_is_enabled, 1092 + }; 1093 + 1094 + static int vc7_probe(struct i2c_client *client) 1095 + { 1096 + struct vc7_driver_data *vc7; 1097 + struct clk_init_data clk_init; 1098 + struct vc7_bank_src_map bank_src_map; 1099 + const char *node_name, *apll_name; 1100 + const char *parent_names[1]; 1101 + unsigned int i, val, bank_idx, out_num; 1102 + unsigned long apll_rate; 1103 + int ret; 1104 + 1105 + vc7 = devm_kzalloc(&client->dev, sizeof(*vc7), GFP_KERNEL); 1106 + if (!vc7) 1107 + return -ENOMEM; 1108 + 1109 + i2c_set_clientdata(client, vc7); 1110 + vc7->client = client; 1111 + vc7->chip_info = of_device_get_match_data(&client->dev); 1112 + 1113 + vc7->pin_xin = devm_clk_get(&client->dev, "xin"); 1114 + if (PTR_ERR(vc7->pin_xin) == -EPROBE_DEFER) { 1115 + return dev_err_probe(&client->dev, -EPROBE_DEFER, 1116 + "xin not specified\n"); 1117 + } 1118 + 1119 + vc7->regmap = devm_regmap_init_i2c(client, &vc7_regmap_config); 1120 + if (IS_ERR(vc7->regmap)) { 1121 + return dev_err_probe(&client->dev, PTR_ERR(vc7->regmap), 1122 + "failed to allocate register map\n"); 1123 + } 1124 + 1125 + if (of_property_read_string(client->dev.of_node, "clock-output-names", 1126 + &node_name)) 1127 + node_name = client->dev.of_node->name; 1128 + 1129 + /* Register APLL */ 1130 + apll_rate = vc7_get_apll_rate(vc7); 1131 + apll_name = kasprintf(GFP_KERNEL, "%s_apll", node_name); 1132 + vc7->clk_apll.clk = clk_register_fixed_rate(&client->dev, apll_name, 1133 + __clk_get_name(vc7->pin_xin), 1134 + 0, apll_rate); 1135 + kfree(apll_name); /* ccf made a copy of the name */ 1136 + if (IS_ERR(vc7->clk_apll.clk)) { 1137 + return dev_err_probe(&client->dev, PTR_ERR(vc7->clk_apll.clk), 1138 + "failed to register apll\n"); 1139 + } 1140 + 1141 + /* Register FODs */ 1142 + for (i = 0; i < VC7_NUM_FOD; i++) { 1143 + memset(&clk_init, 0, sizeof(clk_init)); 1144 + clk_init.name = kasprintf(GFP_KERNEL, "%s_fod%d", node_name, i); 1145 + clk_init.ops = &vc7_fod_ops; 1146 + clk_init.parent_names = parent_names; 1147 + parent_names[0] = __clk_get_name(vc7->clk_apll.clk); 1148 + clk_init.num_parents = 1; 1149 + vc7->clk_fod[i].num = i; 1150 + vc7->clk_fod[i].vc7 = vc7; 1151 + vc7->clk_fod[i].hw.init = &clk_init; 1152 + ret = devm_clk_hw_register(&client->dev, &vc7->clk_fod[i].hw); 1153 + if (ret) 1154 + goto err_clk_register; 1155 + kfree(clk_init.name); /* ccf made a copy of the name */ 1156 + } 1157 + 1158 + /* Register IODs */ 1159 + for (i = 0; i < VC7_NUM_IOD; i++) { 1160 + memset(&clk_init, 0, sizeof(clk_init)); 1161 + clk_init.name = kasprintf(GFP_KERNEL, "%s_iod%d", node_name, i); 1162 + clk_init.ops = &vc7_iod_ops; 1163 + clk_init.parent_names = parent_names; 1164 + parent_names[0] = __clk_get_name(vc7->clk_apll.clk); 1165 + clk_init.num_parents = 1; 1166 + vc7->clk_iod[i].num = i; 1167 + vc7->clk_iod[i].vc7 = vc7; 1168 + vc7->clk_iod[i].hw.init = &clk_init; 1169 + ret = devm_clk_hw_register(&client->dev, &vc7->clk_iod[i].hw); 1170 + if (ret) 1171 + goto err_clk_register; 1172 + kfree(clk_init.name); /* ccf made a copy of the name */ 1173 + } 1174 + 1175 + /* Register outputs */ 1176 + for (i = 0; i < vc7->chip_info->num_outputs; i++) { 1177 + out_num = vc7_map_index_to_output(vc7->chip_info->model, i); 1178 + 1179 + /* 1180 + * This driver does not support remapping FOD/IOD to banks. 1181 + * The device state is read and the driver is setup to match 1182 + * the device's existing mapping. 1183 + */ 1184 + bank_idx = output_bank_mapping[out_num]; 1185 + 1186 + regmap_read(vc7->regmap, VC7_REG_OUT_BANK_CNFG(bank_idx), &val); 1187 + val &= VC7_REG_OUTPUT_BANK_SRC_MASK; 1188 + 1189 + memset(&bank_src_map, 0, sizeof(bank_src_map)); 1190 + ret = vc7_get_bank_clk(vc7, bank_idx, val, &bank_src_map); 1191 + if (ret) { 1192 + dev_err_probe(&client->dev, ret, 1193 + "unable to register output %d\n", i); 1194 + return ret; 1195 + } 1196 + 1197 + switch (bank_src_map.type) { 1198 + case VC7_FOD: 1199 + parent_names[0] = clk_hw_get_name(&bank_src_map.src.fod->hw); 1200 + break; 1201 + case VC7_IOD: 1202 + parent_names[0] = clk_hw_get_name(&bank_src_map.src.iod->hw); 1203 + break; 1204 + } 1205 + 1206 + memset(&clk_init, 0, sizeof(clk_init)); 1207 + clk_init.name = kasprintf(GFP_KERNEL, "%s_out%d", node_name, i); 1208 + clk_init.ops = &vc7_clk_out_ops; 1209 + clk_init.flags = CLK_SET_RATE_PARENT; 1210 + clk_init.parent_names = parent_names; 1211 + clk_init.num_parents = 1; 1212 + vc7->clk_out[i].num = i; 1213 + vc7->clk_out[i].vc7 = vc7; 1214 + vc7->clk_out[i].hw.init = &clk_init; 1215 + ret = devm_clk_hw_register(&client->dev, &vc7->clk_out[i].hw); 1216 + if (ret) 1217 + goto err_clk_register; 1218 + kfree(clk_init.name); /* ccf made a copy of the name */ 1219 + } 1220 + 1221 + ret = of_clk_add_hw_provider(client->dev.of_node, vc7_of_clk_get, vc7); 1222 + if (ret) { 1223 + dev_err_probe(&client->dev, ret, "unable to add clk provider\n"); 1224 + goto err_clk; 1225 + } 1226 + 1227 + return ret; 1228 + 1229 + err_clk_register: 1230 + dev_err_probe(&client->dev, ret, 1231 + "unable to register %s\n", clk_init.name); 1232 + kfree(clk_init.name); /* ccf made a copy of the name */ 1233 + err_clk: 1234 + clk_unregister_fixed_rate(vc7->clk_apll.clk); 1235 + return ret; 1236 + } 1237 + 1238 + static int vc7_remove(struct i2c_client *client) 1239 + { 1240 + struct vc7_driver_data *vc7 = i2c_get_clientdata(client); 1241 + 1242 + of_clk_del_provider(client->dev.of_node); 1243 + clk_unregister_fixed_rate(vc7->clk_apll.clk); 1244 + 1245 + return 0; 1246 + } 1247 + 1248 + static bool vc7_volatile_reg(struct device *dev, unsigned int reg) 1249 + { 1250 + if (reg == VC7_PAGE_ADDR) 1251 + return false; 1252 + 1253 + return true; 1254 + } 1255 + 1256 + static const struct vc7_chip_info vc7_rc21008a_info = { 1257 + .model = VC7_RC21008A, 1258 + .num_banks = 6, 1259 + .num_outputs = 8, 1260 + }; 1261 + 1262 + static struct regmap_range_cfg vc7_range_cfg[] = { 1263 + { 1264 + .range_min = 0, 1265 + .range_max = VC7_MAX_REG, 1266 + .selector_reg = VC7_PAGE_ADDR, 1267 + .selector_mask = 0xFF, 1268 + .selector_shift = 0, 1269 + .window_start = 0, 1270 + .window_len = VC7_PAGE_WINDOW, 1271 + }}; 1272 + 1273 + static const struct regmap_config vc7_regmap_config = { 1274 + .reg_bits = 8, 1275 + .val_bits = 8, 1276 + .max_register = VC7_MAX_REG, 1277 + .ranges = vc7_range_cfg, 1278 + .num_ranges = ARRAY_SIZE(vc7_range_cfg), 1279 + .volatile_reg = vc7_volatile_reg, 1280 + .cache_type = REGCACHE_RBTREE, 1281 + .can_multi_write = true, 1282 + .reg_format_endian = REGMAP_ENDIAN_LITTLE, 1283 + .val_format_endian = REGMAP_ENDIAN_LITTLE, 1284 + }; 1285 + 1286 + static const struct i2c_device_id vc7_i2c_id[] = { 1287 + { "rc21008a", VC7_RC21008A }, 1288 + {} 1289 + }; 1290 + MODULE_DEVICE_TABLE(i2c, vc7_i2c_id); 1291 + 1292 + static const struct of_device_id vc7_of_match[] = { 1293 + { .compatible = "renesas,rc21008a", .data = &vc7_rc21008a_info }, 1294 + {} 1295 + }; 1296 + MODULE_DEVICE_TABLE(of, vc7_of_match); 1297 + 1298 + static struct i2c_driver vc7_i2c_driver = { 1299 + .driver = { 1300 + .name = "vc7", 1301 + .of_match_table = vc7_of_match, 1302 + }, 1303 + .probe_new = vc7_probe, 1304 + .remove = vc7_remove, 1305 + .id_table = vc7_i2c_id, 1306 + }; 1307 + module_i2c_driver(vc7_i2c_driver); 1308 + 1309 + MODULE_LICENSE("GPL"); 1310 + MODULE_AUTHOR("Alex Helms <alexander.helms.jy@renesas.com"); 1311 + MODULE_DESCRIPTION("Renesas Versaclock7 common clock framework driver");
+9
include/dt-bindings/reset/bt1-ccu.h
··· 21 22 #define CCU_SYS_SATA_REF_RST 0 23 #define CCU_SYS_APB_RST 1 24 25 #endif /* __DT_BINDINGS_RESET_BT1_CCU_H */
··· 21 22 #define CCU_SYS_SATA_REF_RST 0 23 #define CCU_SYS_APB_RST 1 24 + #define CCU_SYS_DDR_FULL_RST 2 25 + #define CCU_SYS_DDR_INIT_RST 3 26 + #define CCU_SYS_PCIE_PCS_PHY_RST 4 27 + #define CCU_SYS_PCIE_PIPE0_RST 5 28 + #define CCU_SYS_PCIE_CORE_RST 6 29 + #define CCU_SYS_PCIE_PWR_RST 7 30 + #define CCU_SYS_PCIE_STICKY_RST 8 31 + #define CCU_SYS_PCIE_NSTICKY_RST 9 32 + #define CCU_SYS_PCIE_HOT_RST 10 33 34 #endif /* __DT_BINDINGS_RESET_BT1_CCU_H */