···6868 int (*is_enabled)(struct clk_hw *hw);6969 unsigned long (*recalc_rate)(struct clk_hw *hw,7070 unsigned long parent_rate);7171- long (*round_rate)(struct clk_hw *hw, unsigned long,7272- unsigned long *);7171+ long (*round_rate)(struct clk_hw *hw,7272+ unsigned long rate,7373+ unsigned long *parent_rate);7374 long (*determine_rate)(struct clk_hw *hw,7475 unsigned long rate,7576 unsigned long *best_parent_rate,7677 struct clk **best_parent_clk);7778 int (*set_parent)(struct clk_hw *hw, u8 index);7879 u8 (*get_parent)(struct clk_hw *hw);7979- int (*set_rate)(struct clk_hw *hw, unsigned long);8080+ int (*set_rate)(struct clk_hw *hw,8181+ unsigned long rate,8282+ unsigned long parent_rate);8083 int (*set_rate_and_parent)(struct clk_hw *hw,8184 unsigned long rate,8282- unsigned long parent_rate, u8 index);8585+ unsigned long parent_rate,8686+ u8 index);8387 unsigned long (*recalc_accuracy)(struct clk_hw *hw,8484- unsigned long parent_accuracy);8888+ unsigned long parent_accuracy);8589 void (*init)(struct clk_hw *hw);9090+ int (*debug_init)(struct clk_hw *hw,9191+ struct dentry *dentry);8692 };87938894 Part 3 - hardware clk implementations
···10101111Required properties:1212- compatible1313- Shall have one of the following values:1414- - "brcm,bcm11351-root-ccu"1515- - "brcm,bcm11351-aon-ccu"1616- - "brcm,bcm11351-hub-ccu"1717- - "brcm,bcm11351-master-ccu"1818- - "brcm,bcm11351-slave-ccu"1313+ Shall have a value of the form "brcm,<model>-<which>-ccu",1414+ where <model> is a Broadcom SoC model number and <which> is1515+ the name of a defined CCU. For example:1616+ "brcm,bcm11351-root-ccu"1717+ The compatible strings used for each supported SoC family1818+ are defined below.1919- reg2020 Shall define the base and range of the address space2121 containing clock control registers···2626 Shall be an ordered list of strings defining the names of2727 the clocks provided by the CCU.28282929+Device tree example:29303030-BCM281XX family SoCs use Kona CCUs. The following table defines3131-the set of CCUs and clock specifiers for BCM281XX clocks. When3232-a clock consumer references a clocks, its symbolic specifier3333-(rather than its numeric index value) should be used. These3434-specifiers are defined in "include/dt-bindings/clock/bcm281xx.h".3131+ slave_ccu: slave_ccu {3232+ compatible = "brcm,bcm11351-slave-ccu";3333+ reg = <0x3e011000 0x0f00>;3434+ #clock-cells = <1>;3535+ clock-output-names = "uartb",3636+ "uartb2",3737+ "uartb3",3838+ "uartb4";3939+ };4040+4141+ ref_crystal_clk: ref_crystal {4242+ #clock-cells = <0>;4343+ compatible = "fixed-clock";4444+ clock-frequency = <26000000>;4545+ };4646+4747+ uart@3e002000 {4848+ compatible = "brcm,bcm11351-dw-apb-uart", "snps,dw-apb-uart";4949+ status = "disabled";5050+ reg = <0x3e002000 0x1000>;5151+ clocks = <&slave_ccu BCM281XX_SLAVE_CCU_UARTB3>;5252+ interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;5353+ reg-shift = <2>;5454+ reg-io-width = <4>;5555+ };5656+5757+BCM281XX family5858+---------------5959+CCU compatible string values for SoCs in the BCM281XX family are:6060+ "brcm,bcm11351-root-ccu"6161+ "brcm,bcm11351-aon-ccu"6262+ "brcm,bcm11351-hub-ccu"6363+ "brcm,bcm11351-master-ccu"6464+ "brcm,bcm11351-slave-ccu"6565+6666+The following table defines the set of CCUs and clock specifiers for6767+BCM281XX family clocks. When a clock consumer references a clocks,6868+its symbolic specifier (rather than its numeric index value) should6969+be used. These specifiers are defined in:7070+ "include/dt-bindings/clock/bcm281xx.h"35713672 CCU Clock Type Index Specifier3773 --- ----- ---- ----- ---------···10064 slave pwm peri 9 BCM281XX_SLAVE_CCU_PWM1016510266103103-Device tree example:6767+BCM21664 family6868+---------------6969+CCU compatible string values for SoCs in the BCM21664 family are:7070+ "brcm,bcm21664-root-ccu"7171+ "brcm,bcm21664-aon-ccu"7272+ "brcm,bcm21664-master-ccu"7373+ "brcm,bcm21664-slave-ccu"10474105105- slave_ccu: slave_ccu {106106- compatible = "brcm,bcm11351-slave-ccu";107107- reg = <0x3e011000 0x0f00>;108108- #clock-cells = <1>;109109- clock-output-names = "uartb",110110- "uartb2",111111- "uartb3",112112- "uartb4";113113- };7575+The following table defines the set of CCUs and clock specifiers for7676+BCM21664 family clocks. When a clock consumer references a clocks,7777+its symbolic specifier (rather than its numeric index value) should7878+be used. These specifiers are defined in:7979+ "include/dt-bindings/clock/bcm21664.h"11480115115- ref_crystal_clk: ref_crystal {116116- #clock-cells = <0>;117117- compatible = "fixed-clock";118118- clock-frequency = <26000000>;119119- };8181+ CCU Clock Type Index Specifier8282+ --- ----- ---- ----- ---------8383+ root frac_1m peri 0 BCM21664_ROOT_CCU_FRAC_1M12084121121- uart@3e002000 {122122- compatible = "brcm,bcm11351-dw-apb-uart", "snps,dw-apb-uart";123123- status = "disabled";124124- reg = <0x3e002000 0x1000>;125125- clocks = <&slave_ccu BCM281XX_SLAVE_CCU_UARTB3>;126126- interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;127127- reg-shift = <2>;128128- reg-io-width = <4>;129129- };8585+ aon hub_timer peri 0 BCM21664_AON_CCU_HUB_TIMER8686+8787+ master sdio1 peri 0 BCM21664_MASTER_CCU_SDIO18888+ master sdio2 peri 1 BCM21664_MASTER_CCU_SDIO28989+ master sdio3 peri 2 BCM21664_MASTER_CCU_SDIO39090+ master sdio4 peri 3 BCM21664_MASTER_CCU_SDIO49191+ master sdio1_sleep peri 4 BCM21664_MASTER_CCU_SDIO1_SLEEP9292+ master sdio2_sleep peri 5 BCM21664_MASTER_CCU_SDIO2_SLEEP9393+ master sdio3_sleep peri 6 BCM21664_MASTER_CCU_SDIO3_SLEEP9494+ master sdio4_sleep peri 7 BCM21664_MASTER_CCU_SDIO4_SLEEP9595+9696+ slave uartb peri 0 BCM21664_SLAVE_CCU_UARTB9797+ slave uartb2 peri 1 BCM21664_SLAVE_CCU_UARTB29898+ slave uartb3 peri 2 BCM21664_SLAVE_CCU_UARTB39999+ slave uartb4 peri 3 BCM21664_SLAVE_CCU_UARTB4100100+ slave bsc1 peri 4 BCM21664_SLAVE_CCU_BSC1101101+ slave bsc2 peri 5 BCM21664_SLAVE_CCU_BSC2102102+ slave bsc3 peri 6 BCM21664_SLAVE_CCU_BSC3103103+ slave bsc4 peri 7 BCM21664_SLAVE_CCU_BSC4
···4444 clocks by index. The names should reflect the clock output signal4545 names for the device.46464747-clock-indices: If the identifyng number for the clocks in the node4848- is not linear from zero, then the this mapping allows4949- the mapping of identifiers into the clock-output-names5050- array.4747+clock-indices: If the identifying number for the clocks in the node4848+ is not linear from zero, then this allows the mapping of4949+ identifiers into the clock-output-names array.51505251For example, if we have two clocks <&oscillator 1> and <&oscillator 3>:5352···5758 clock-output-names = "clka", "clkb";5859 }59606060- This ensures we do not have any empty nodes in clock-output-names6161+ This ensures we do not have any empty strings in clock-output-names616262636364==Clock consumers==
···1212Optional properties:1313- clock-accuracy : accuracy of clock in ppb (parts per billion).1414 Should be a single cell.1515-- gpios : From common gpio binding; gpio connection to clock enable pin.1615- clock-output-names : From common clock binding.17161817Example:
···11+* Hisilicon Hix5hd2 Clock Controller22+33+The hix5hd2 clock controller generates and supplies clock to various44+controllers within the hix5hd2 SoC.55+66+Required Properties:77+88+- compatible: should be "hisilicon,hix5hd2-clock"99+- reg: Address and length of the register set1010+- #clock-cells: Should be <1>1111+1212+Each clock is assigned an identifier and client nodes use this identifier1313+to specify the clock which they consume.1414+1515+All these identifier could be found in <dt-bindings/clock/hix5hd2-clock.h>.1616+1717+Examples:1818+ clock: clock@f8a22000 {1919+ compatible = "hisilicon,hix5hd2-clock";2020+ reg = <0xf8a22000 0x1000>;2121+ #clock-cells = <1>;2222+ };2323+2424+ uart0: uart@f8b00000 {2525+ compatible = "arm,pl011", "arm,primecell";2626+ reg = <0xf8b00000 0x1000>;2727+ interrupts = <0 49 4>;2828+ clocks = <&clock HIX5HD2_FIXED_83M>;2929+ clock-names = "apb_pclk";3030+ status = "disabled";3131+ };
···2929 2 = l2clk (L2 Cache clock derived from CPU0 clock)3030 3 = ddrclk (DDR controller clock derived from CPU0 clock)31313232+The following is a list of provided IDs and clock names on Orion5x:3333+ 0 = tclk (Internal Bus clock)3434+ 1 = cpuclk (CPU0 clock)3535+ 2 = ddrclk (DDR controller clock derived from CPU0 clock)3636+3237Required properties:3338- compatible : shall be one of the following:3439 "marvell,armada-370-core-clock" - For Armada 370 SoC core clocks···4338 "marvell,dove-core-clock" - for Dove SoC core clocks4439 "marvell,kirkwood-core-clock" - for Kirkwood SoC (except mv88f6180)4540 "marvell,mv88f6180-core-clock" - for Kirkwood MV88f6180 SoC4141+ "marvell,mv88f5182-core-clock" - for Orion MV88F5182 SoC4242+ "marvell,mv88f5281-core-clock" - for Orion MV88F5281 SoC4343+ "marvell,mv88f6183-core-clock" - for Orion MV88F6183 SoC4644- reg : shall be the register address of the Sample-At-Reset (SAR) register4745- #clock-cells : from common clock binding; shall be set to 14846
···44Required properties :55- compatible : shall contain only one of the following:6677+ "qcom,gcc-apq8064"78 "qcom,gcc-msm8660"89 "qcom,gcc-msm8960"910 "qcom,gcc-msm8974"
···1010Required Properties:11111212 - compatible: Must be one of the following1313+ - "renesas,r8a7779-mstp-clocks" for R8A7779 (R-Car H1) MSTP gate clocks1314 - "renesas,r8a7790-mstp-clocks" for R8A7790 (R-Car H2) MSTP gate clocks1415 - "renesas,r8a7791-mstp-clocks" for R8A7791 (R-Car M2) MSTP gate clocks1516 - "renesas,cpg-mstp-clock" for generic MSTP gate clocks
···11+These bindings should be considered EXPERIMENTAL for now.22+33+* Renesas R8A7740 Clock Pulse Generator (CPG)44+55+The CPG generates core clocks for the R8A7740 SoC. It includes three PLLs66+and several fixed ratio and variable ratio dividers.77+88+Required Properties:99+1010+ - compatible: Must be "renesas,r8a7740-cpg-clocks"1111+1212+ - reg: Base address and length of the memory resource used by the CPG1313+1414+ - clocks: Reference to the three parent clocks1515+ - #clock-cells: Must be 11616+ - clock-output-names: The names of the clocks. Supported clocks are1717+ "system", "pllc0", "pllc1", "pllc2", "r", "usb24s", "i", "zg", "b",1818+ "m1", "hp", "hpp", "usbp", "s", "zb", "m3", and "cp".1919+2020+ - renesas,mode: board-specific settings of the MD_CK* bits2121+2222+2323+Example2424+-------2525+2626+cpg_clocks: cpg_clocks@e6150000 {2727+ compatible = "renesas,r8a7740-cpg-clocks";2828+ reg = <0xe6150000 0x10000>;2929+ clocks = <&extal1_clk>, <&extal2_clk>, <&extalr_clk>;3030+ #clock-cells = <1>;3131+ clock-output-names = "system", "pllc0", "pllc1",3232+ "pllc2", "r",3333+ "usb24s",3434+ "i", "zg", "b", "m1", "hp",3535+ "hpp", "usbp", "s", "zb", "m3",3636+ "cp";3737+};3838+3939+&cpg_clocks {4040+ renesas,mode = <0x05>;4141+};
···11+* Renesas R8A7779 Clock Pulse Generator (CPG)22+33+The CPG generates core clocks for the R8A7779. It includes one PLL and44+several fixed ratio dividers55+66+Required Properties:77+88+ - compatible: Must be "renesas,r8a7779-cpg-clocks"99+ - reg: Base address and length of the memory resource used by the CPG1010+1111+ - clocks: Reference to the parent clock1212+ - #clock-cells: Must be 11313+ - clock-output-names: The names of the clocks. Supported clocks are "plla",1414+ "z", "zs", "s", "s1", "p", "b", "out".1515+1616+1717+Example1818+-------1919+2020+ cpg_clocks: cpg_clocks@ffc80000 {2121+ compatible = "renesas,r8a7779-cpg-clocks";2222+ reg = <0 0xffc80000 0 0x30>;2323+ clocks = <&extal_clk>;2424+ #clock-cells = <1>;2525+ clock-output-names = "plla", "z", "zs", "s", "s1", "p",2626+ "b", "out";2727+ };
···66 help77 Enable common clock framework support for Broadcom SoCs88 using "Kona" style clock control units, including those99- in the BCM281xx family.99+ in the BCM281xx and BCM21664 families.
···25252626/* Validity checking */27272828+static bool ccu_data_offsets_valid(struct ccu_data *ccu)2929+{3030+ struct ccu_policy *ccu_policy = &ccu->policy;3131+ u32 limit;3232+3333+ limit = ccu->range - sizeof(u32);3434+ limit = round_down(limit, sizeof(u32));3535+ if (ccu_policy_exists(ccu_policy)) {3636+ if (ccu_policy->enable.offset > limit) {3737+ pr_err("%s: bad policy enable offset for %s "3838+ "(%u > %u)\n", __func__,3939+ ccu->name, ccu_policy->enable.offset, limit);4040+ return false;4141+ }4242+ if (ccu_policy->control.offset > limit) {4343+ pr_err("%s: bad policy control offset for %s "4444+ "(%u > %u)\n", __func__,4545+ ccu->name, ccu_policy->control.offset, limit);4646+ return false;4747+ }4848+ }4949+5050+ return true;5151+}5252+2853static bool clk_requires_trigger(struct kona_clk *bcm_clk)2954{3055 struct peri_clk_data *peri = bcm_clk->u.peri;···7954static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk)8055{8156 struct peri_clk_data *peri;5757+ struct bcm_clk_policy *policy;8258 struct bcm_clk_gate *gate;5959+ struct bcm_clk_hyst *hyst;8360 struct bcm_clk_div *div;8461 struct bcm_clk_sel *sel;8562 struct bcm_clk_trig *trig;···91649265 BUG_ON(bcm_clk->type != bcm_clk_peri);9366 peri = bcm_clk->u.peri;9494- name = bcm_clk->name;6767+ name = bcm_clk->init_data.name;9568 range = bcm_clk->ccu->range;96699770 limit = range - sizeof(u32);9871 limit = round_down(limit, sizeof(u32));99727373+ policy = &peri->policy;7474+ if (policy_exists(policy)) {7575+ if (policy->offset > limit) {7676+ pr_err("%s: bad policy offset for %s (%u > %u)\n",7777+ __func__, name, policy->offset, limit);7878+ return false;7979+ }8080+ }8181+10082 gate = &peri->gate;8383+ hyst = &peri->hyst;10184 if (gate_exists(gate)) {10285 if (gate->offset > limit) {10386 pr_err("%s: bad gate offset for %s (%u > %u)\n",10487 __func__, name, gate->offset, limit);10588 return false;10689 }9090+9191+ if (hyst_exists(hyst)) {9292+ if (hyst->offset > limit) {9393+ pr_err("%s: bad hysteresis offset for %s "9494+ "(%u > %u)\n", __func__,9595+ name, hyst->offset, limit);9696+ return false;9797+ }9898+ }9999+ } else if (hyst_exists(hyst)) {100100+ pr_err("%s: hysteresis but no gate for %s\n", __func__, name);101101+ return false;107102 }108103109104 div = &peri->div;···216167 return true;217168}218169170170+static bool171171+ccu_policy_valid(struct ccu_policy *ccu_policy, const char *ccu_name)172172+{173173+ struct bcm_lvm_en *enable = &ccu_policy->enable;174174+ struct bcm_policy_ctl *control;175175+176176+ if (!bit_posn_valid(enable->bit, "policy enable", ccu_name))177177+ return false;178178+179179+ control = &ccu_policy->control;180180+ if (!bit_posn_valid(control->go_bit, "policy control GO", ccu_name))181181+ return false;182182+183183+ if (!bit_posn_valid(control->atl_bit, "policy control ATL", ccu_name))184184+ return false;185185+186186+ if (!bit_posn_valid(control->ac_bit, "policy control AC", ccu_name))187187+ return false;188188+189189+ return true;190190+}191191+192192+static bool policy_valid(struct bcm_clk_policy *policy, const char *clock_name)193193+{194194+ if (!bit_posn_valid(policy->bit, "policy", clock_name))195195+ return false;196196+197197+ return true;198198+}199199+219200/*220201 * All gates, if defined, have a status bit, and for hardware-only221202 * gates, that's it. Gates that can be software controlled also···271192 } else {272193 BUG_ON(!gate_is_hw_controllable(gate));273194 }195195+196196+ return true;197197+}198198+199199+static bool hyst_valid(struct bcm_clk_hyst *hyst, const char *clock_name)200200+{201201+ if (!bit_posn_valid(hyst->en_bit, "hysteresis enable", clock_name))202202+ return false;203203+204204+ if (!bit_posn_valid(hyst->val_bit, "hysteresis value", clock_name))205205+ return false;274206275207 return true;276208}···402312peri_clk_data_valid(struct kona_clk *bcm_clk)403313{404314 struct peri_clk_data *peri;315315+ struct bcm_clk_policy *policy;405316 struct bcm_clk_gate *gate;317317+ struct bcm_clk_hyst *hyst;406318 struct bcm_clk_sel *sel;407319 struct bcm_clk_div *div;408320 struct bcm_clk_div *pre_div;···422330 return false;423331424332 peri = bcm_clk->u.peri;425425- name = bcm_clk->name;333333+ name = bcm_clk->init_data.name;334334+335335+ policy = &peri->policy;336336+ if (policy_exists(policy) && !policy_valid(policy, name))337337+ return false;338338+426339 gate = &peri->gate;427340 if (gate_exists(gate) && !gate_valid(gate, "gate", name))341341+ return false;342342+343343+ hyst = &peri->hyst;344344+ if (hyst_exists(hyst) && !hyst_valid(hyst, name))428345 return false;429346430347 sel = &peri->sel;···668567 struct clk_init_data *init_data)669568{670569 clk_sel_teardown(&data->sel, init_data);671671- init_data->ops = NULL;672570}673571674572/*···676576 * that can be assigned if the clock has one or more parent clocks677577 * associated with it.678578 */679679-static int peri_clk_setup(struct ccu_data *ccu, struct peri_clk_data *data,680680- struct clk_init_data *init_data)579579+static int580580+peri_clk_setup(struct peri_clk_data *data, struct clk_init_data *init_data)681581{682682- init_data->ops = &kona_peri_clk_ops;683582 init_data->flags = CLK_IGNORE_UNUSED;684583685584 return clk_sel_setup(data->clocks, &data->sel, init_data);···716617 bcm_clk_teardown(bcm_clk);717618}718619719719-struct clk *kona_clk_setup(struct ccu_data *ccu, const char *name,720720- enum bcm_clk_type type, void *data)620620+struct clk *kona_clk_setup(struct kona_clk *bcm_clk)721621{722722- struct kona_clk *bcm_clk;723723- struct clk_init_data *init_data;622622+ struct clk_init_data *init_data = &bcm_clk->init_data;724623 struct clk *clk = NULL;725624726726- bcm_clk = kzalloc(sizeof(*bcm_clk), GFP_KERNEL);727727- if (!bcm_clk) {728728- pr_err("%s: failed to allocate bcm_clk for %s\n", __func__,729729- name);730730- return NULL;731731- }732732- bcm_clk->ccu = ccu;733733- bcm_clk->name = name;734734-735735- init_data = &bcm_clk->init_data;736736- init_data->name = name;737737- switch (type) {625625+ switch (bcm_clk->type) {738626 case bcm_clk_peri:739739- if (peri_clk_setup(ccu, data, init_data))740740- goto out_free;627627+ if (peri_clk_setup(bcm_clk->u.data, init_data))628628+ return NULL;741629 break;742630 default:743743- data = NULL;744744- break;631631+ pr_err("%s: clock type %d invalid for %s\n", __func__,632632+ (int)bcm_clk->type, init_data->name);633633+ return NULL;745634 }746746- bcm_clk->type = type;747747- bcm_clk->u.data = data;748635749636 /* Make sure everything makes sense before we set it up */750637 if (!kona_clk_valid(bcm_clk)) {751751- pr_err("%s: clock data invalid for %s\n", __func__, name);638638+ pr_err("%s: clock data invalid for %s\n", __func__,639639+ init_data->name);752640 goto out_teardown;753641 }754642···743657 clk = clk_register(NULL, &bcm_clk->hw);744658 if (IS_ERR(clk)) {745659 pr_err("%s: error registering clock %s (%ld)\n", __func__,746746- name, PTR_ERR(clk));660660+ init_data->name, PTR_ERR(clk));747661 goto out_teardown;748662 }749663 BUG_ON(!clk);···751665 return clk;752666out_teardown:753667 bcm_clk_teardown(bcm_clk);754754-out_free:755755- kfree(bcm_clk);756668757669 return NULL;758670}···759675{760676 u32 i;761677762762- for (i = 0; i < ccu->data.clk_num; i++)763763- kona_clk_teardown(ccu->data.clks[i]);764764- kfree(ccu->data.clks);678678+ for (i = 0; i < ccu->clk_data.clk_num; i++)679679+ kona_clk_teardown(ccu->clk_data.clks[i]);680680+ kfree(ccu->clk_data.clks);765681}766682767683static void kona_ccu_teardown(struct ccu_data *ccu)768684{769769- if (!ccu)770770- return;771771-685685+ kfree(ccu->clk_data.clks);686686+ ccu->clk_data.clks = NULL;772687 if (!ccu->base)773773- goto done;688688+ return;774689775690 of_clk_del_provider(ccu->node); /* safe if never added */776691 ccu_clks_teardown(ccu);777692 list_del(&ccu->links);778693 of_node_put(ccu->node);694694+ ccu->node = NULL;779695 iounmap(ccu->base);780780-done:781781- kfree(ccu->name);782782- kfree(ccu);696696+ ccu->base = NULL;697697+}698698+699699+static bool ccu_data_valid(struct ccu_data *ccu)700700+{701701+ struct ccu_policy *ccu_policy;702702+703703+ if (!ccu_data_offsets_valid(ccu))704704+ return false;705705+706706+ ccu_policy = &ccu->policy;707707+ if (ccu_policy_exists(ccu_policy))708708+ if (!ccu_policy_valid(ccu_policy, ccu->name))709709+ return false;710710+711711+ return true;783712}784713785714/*786715 * Set up a CCU. Call the provided ccu_clks_setup callback to787716 * initialize the array of clocks provided by the CCU.788717 */789789-void __init kona_dt_ccu_setup(struct device_node *node,790790- int (*ccu_clks_setup)(struct ccu_data *))718718+void __init kona_dt_ccu_setup(struct ccu_data *ccu,719719+ struct device_node *node)791720{792792- struct ccu_data *ccu;793721 struct resource res = { 0 };794722 resource_size_t range;723723+ unsigned int i;795724 int ret;796725797797- ccu = kzalloc(sizeof(*ccu), GFP_KERNEL);798798- if (ccu)799799- ccu->name = kstrdup(node->name, GFP_KERNEL);800800- if (!ccu || !ccu->name) {801801- pr_err("%s: unable to allocate CCU struct for %s\n",802802- __func__, node->name);803803- kfree(ccu);726726+ if (ccu->clk_data.clk_num) {727727+ size_t size;804728805805- return;729729+ size = ccu->clk_data.clk_num * sizeof(*ccu->clk_data.clks);730730+ ccu->clk_data.clks = kzalloc(size, GFP_KERNEL);731731+ if (!ccu->clk_data.clks) {732732+ pr_err("%s: unable to allocate %u clocks for %s\n",733733+ __func__, ccu->clk_data.clk_num, node->name);734734+ return;735735+ }806736 }807737808738 ret = of_address_to_resource(node, 0, &res);···834736 }835737836738 ccu->range = (u32)range;739739+740740+ if (!ccu_data_valid(ccu)) {741741+ pr_err("%s: ccu data not valid for %s\n", __func__, node->name);742742+ goto out_err;743743+ }744744+837745 ccu->base = ioremap(res.start, ccu->range);838746 if (!ccu->base) {839747 pr_err("%s: unable to map CCU registers for %s\n", __func__,840748 node->name);841749 goto out_err;842750 }843843-844844- spin_lock_init(&ccu->lock);845845- INIT_LIST_HEAD(&ccu->links);846751 ccu->node = of_node_get(node);847847-848752 list_add_tail(&ccu->links, &ccu_list);849753850850- /* Set up clocks array (in ccu->data) */851851- if (ccu_clks_setup(ccu))852852- goto out_err;754754+ /*755755+ * Set up each defined kona clock and save the result in756756+ * the clock framework clock array (in ccu->data). Then757757+ * register as a provider for these clocks.758758+ */759759+ for (i = 0; i < ccu->clk_data.clk_num; i++) {760760+ if (!ccu->kona_clks[i].ccu)761761+ continue;762762+ ccu->clk_data.clks[i] = kona_clk_setup(&ccu->kona_clks[i]);763763+ }853764854854- ret = of_clk_add_provider(node, of_clk_src_onecell_get, &ccu->data);765765+ ret = of_clk_add_provider(node, of_clk_src_onecell_get, &ccu->clk_data);855766 if (ret) {856767 pr_err("%s: error adding ccu %s as provider (%d)\n", __func__,857768 node->name, ret);
+203-9
drivers/clk/bcm/clk-kona.c
···16161717#include <linux/delay.h>18181919+/*2020+ * "Policies" affect the frequencies of bus clocks provided by a2121+ * CCU. (I believe these polices are named "Deep Sleep", "Economy",2222+ * "Normal", and "Turbo".) A lower policy number has lower power2323+ * consumption, and policy 2 is the default.2424+ */2525+#define CCU_POLICY_COUNT 42626+1927#define CCU_ACCESS_PASSWORD 0xA5A5002028#define CLK_GATE_DELAY_LOOP 20002129···215207 return true;216208 udelay(1);217209 }210210+ pr_warn("%s: %s/0x%04x bit %u was never %s\n", __func__,211211+ ccu->name, reg_offset, bit, want ? "set" : "clear");212212+218213 return false;214214+}215215+216216+/* Policy operations */217217+218218+static bool __ccu_policy_engine_start(struct ccu_data *ccu, bool sync)219219+{220220+ struct bcm_policy_ctl *control = &ccu->policy.control;221221+ u32 offset;222222+ u32 go_bit;223223+ u32 mask;224224+ bool ret;225225+226226+ /* If we don't need to control policy for this CCU, we're done. */227227+ if (!policy_ctl_exists(control))228228+ return true;229229+230230+ offset = control->offset;231231+ go_bit = control->go_bit;232232+233233+ /* Ensure we're not busy before we start */234234+ ret = __ccu_wait_bit(ccu, offset, go_bit, false);235235+ if (!ret) {236236+ pr_err("%s: ccu %s policy engine wouldn't go idle\n",237237+ __func__, ccu->name);238238+ return false;239239+ }240240+241241+ /*242242+ * If it's a synchronous request, we'll wait for the voltage243243+ * and frequency of the active load to stabilize before244244+ * returning. To do this we select the active load by245245+ * setting the ATL bit.246246+ *247247+ * An asynchronous request instead ramps the voltage in the248248+ * background, and when that process stabilizes, the target249249+ * load is copied to the active load and the CCU frequency250250+ * is switched. We do this by selecting the target load251251+ * (ATL bit clear) and setting the request auto-copy (AC bit252252+ * set).253253+ *254254+ * Note, we do NOT read-modify-write this register.255255+ */256256+ mask = (u32)1 << go_bit;257257+ if (sync)258258+ mask |= 1 << control->atl_bit;259259+ else260260+ mask |= 1 << control->ac_bit;261261+ __ccu_write(ccu, offset, mask);262262+263263+ /* Wait for indication that operation is complete. */264264+ ret = __ccu_wait_bit(ccu, offset, go_bit, false);265265+ if (!ret)266266+ pr_err("%s: ccu %s policy engine never started\n",267267+ __func__, ccu->name);268268+269269+ return ret;270270+}271271+272272+static bool __ccu_policy_engine_stop(struct ccu_data *ccu)273273+{274274+ struct bcm_lvm_en *enable = &ccu->policy.enable;275275+ u32 offset;276276+ u32 enable_bit;277277+ bool ret;278278+279279+ /* If we don't need to control policy for this CCU, we're done. */280280+ if (!policy_lvm_en_exists(enable))281281+ return true;282282+283283+ /* Ensure we're not busy before we start */284284+ offset = enable->offset;285285+ enable_bit = enable->bit;286286+ ret = __ccu_wait_bit(ccu, offset, enable_bit, false);287287+ if (!ret) {288288+ pr_err("%s: ccu %s policy engine already stopped\n",289289+ __func__, ccu->name);290290+ return false;291291+ }292292+293293+ /* Now set the bit to stop the engine (NO read-modify-write) */294294+ __ccu_write(ccu, offset, (u32)1 << enable_bit);295295+296296+ /* Wait for indication that it has stopped. */297297+ ret = __ccu_wait_bit(ccu, offset, enable_bit, false);298298+ if (!ret)299299+ pr_err("%s: ccu %s policy engine never stopped\n",300300+ __func__, ccu->name);301301+302302+ return ret;303303+}304304+305305+/*306306+ * A CCU has four operating conditions ("policies"), and some clocks307307+ * can be disabled or enabled based on which policy is currently in308308+ * effect. Such clocks have a bit in a "policy mask" register for309309+ * each policy indicating whether the clock is enabled for that310310+ * policy or not. The bit position for a clock is the same for all311311+ * four registers, and the 32-bit registers are at consecutive312312+ * addresses.313313+ */314314+static bool policy_init(struct ccu_data *ccu, struct bcm_clk_policy *policy)315315+{316316+ u32 offset;317317+ u32 mask;318318+ int i;319319+ bool ret;320320+321321+ if (!policy_exists(policy))322322+ return true;323323+324324+ /*325325+ * We need to stop the CCU policy engine to allow update326326+ * of our policy bits.327327+ */328328+ if (!__ccu_policy_engine_stop(ccu)) {329329+ pr_err("%s: unable to stop CCU %s policy engine\n",330330+ __func__, ccu->name);331331+ return false;332332+ }333333+334334+ /*335335+ * For now, if a clock defines its policy bit we just mark336336+ * it "enabled" for all four policies.337337+ */338338+ offset = policy->offset;339339+ mask = (u32)1 << policy->bit;340340+ for (i = 0; i < CCU_POLICY_COUNT; i++) {341341+ u32 reg_val;342342+343343+ reg_val = __ccu_read(ccu, offset);344344+ reg_val |= mask;345345+ __ccu_write(ccu, offset, reg_val);346346+ offset += sizeof(u32);347347+ }348348+349349+ /* We're done updating; fire up the policy engine again. */350350+ ret = __ccu_policy_engine_start(ccu, true);351351+ if (!ret)352352+ pr_err("%s: unable to restart CCU %s policy engine\n",353353+ __func__, ccu->name);354354+355355+ return ret;219356}220357221358/* Gate operations */···525372 enable ? "enable" : "disable", name);526373527374 return -EIO;375375+}376376+377377+/* Hysteresis operations */378378+379379+/*380380+ * If a clock gate requires a turn-off delay it will have381381+ * "hysteresis" register bits defined. The first, if set, enables382382+ * the delay; and if enabled, the second bit determines whether the383383+ * delay is "low" or "high" (1 means high). For now, if it's384384+ * defined for a clock, we set it.385385+ */386386+static bool hyst_init(struct ccu_data *ccu, struct bcm_clk_hyst *hyst)387387+{388388+ u32 offset;389389+ u32 reg_val;390390+ u32 mask;391391+392392+ if (!hyst_exists(hyst))393393+ return true;394394+395395+ offset = hyst->offset;396396+ mask = (u32)1 << hyst->en_bit;397397+ mask |= (u32)1 << hyst->val_bit;398398+399399+ reg_val = __ccu_read(ccu, offset);400400+ reg_val |= mask;401401+ __ccu_write(ccu, offset, reg_val);402402+403403+ return true;528404}529405530406/* Trigger operations */···988806 struct kona_clk *bcm_clk = to_kona_clk(hw);989807 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;990808991991- return clk_gate(bcm_clk->ccu, bcm_clk->name, gate, true);809809+ return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true);992810}993811994812static void kona_peri_clk_disable(struct clk_hw *hw)···996814 struct kona_clk *bcm_clk = to_kona_clk(hw);997815 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;998816999999- (void)clk_gate(bcm_clk->ccu, bcm_clk->name, gate, false);817817+ (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false);1000818}10018191002820static int kona_peri_clk_is_enabled(struct clk_hw *hw)···10548721055873 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index);1056874 if (ret == -ENXIO) {10571057- pr_err("%s: gating failure for %s\n", __func__, bcm_clk->name);875875+ pr_err("%s: gating failure for %s\n", __func__,876876+ bcm_clk->init_data.name);1058877 ret = -EIO; /* Don't proliferate weird errors */1059878 } else if (ret == -EIO) {1060879 pr_err("%s: %strigger failed for %s\n", __func__,1061880 trig == &data->pre_trig ? "pre-" : "",10621062- bcm_clk->name);881881+ bcm_clk->init_data.name);1063882 }10648831065884 return ret;···1119936 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div,1120937 &data->trig, scaled_div);1121938 if (ret == -ENXIO) {11221122- pr_err("%s: gating failure for %s\n", __func__, bcm_clk->name);939939+ pr_err("%s: gating failure for %s\n", __func__,940940+ bcm_clk->init_data.name);1123941 ret = -EIO; /* Don't proliferate weird errors */1124942 } else if (ret == -EIO) {11251125- pr_err("%s: trigger failed for %s\n", __func__, bcm_clk->name);943943+ pr_err("%s: trigger failed for %s\n", __func__,944944+ bcm_clk->init_data.name);1126945 }11279461128947 return ret;···1146961{1147962 struct ccu_data *ccu = bcm_clk->ccu;1148963 struct peri_clk_data *peri = bcm_clk->u.peri;11491149- const char *name = bcm_clk->name;964964+ const char *name = bcm_clk->init_data.name;1150965 struct bcm_clk_trig *trig;11519661152967 BUG_ON(bcm_clk->type != bcm_clk_peri);1153968969969+ if (!policy_init(ccu, &peri->policy)) {970970+ pr_err("%s: error initializing policy for %s\n",971971+ __func__, name);972972+ return false;973973+ }1154974 if (!gate_init(ccu, &peri->gate)) {1155975 pr_err("%s: error initializing gate for %s\n", __func__, name);976976+ return false;977977+ }978978+ if (!hyst_init(ccu, &peri->hyst)) {979979+ pr_err("%s: error initializing hyst for %s\n", __func__, name);1156980 return false;1157981 }1158982 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) {···12081014{12091015 unsigned long flags;12101016 unsigned int which;12111211- struct clk **clks = ccu->data.clks;10171017+ struct clk **clks = ccu->clk_data.clks;12121018 bool success = true;1213101912141020 flags = ccu_lock(ccu);12151021 __ccu_write_enable(ccu);1216102212171217- for (which = 0; which < ccu->data.clk_num; which++) {10231023+ for (which = 0; which < ccu->clk_data.clk_num; which++) {12181024 struct kona_clk *bcm_clk;1219102512201026 if (!clks[which])
+133-27
drivers/clk/bcm/clk-kona.h
···4343#define FLAG_FLIP(obj, type, flag) ((obj)->flags ^= FLAG(type, flag))4444#define FLAG_TEST(obj, type, flag) (!!((obj)->flags & FLAG(type, flag)))45454646+/* CCU field state tests */4747+4848+#define ccu_policy_exists(ccu_policy) ((ccu_policy)->enable.offset != 0)4949+4650/* Clock field state tests */5151+5252+#define policy_exists(policy) ((policy)->offset != 0)47534854#define gate_exists(gate) FLAG_TEST(gate, GATE, EXISTS)4955#define gate_is_enabled(gate) FLAG_TEST(gate, GATE, ENABLED)···60546155#define gate_flip_enabled(gate) FLAG_FLIP(gate, GATE, ENABLED)62565757+#define hyst_exists(hyst) ((hyst)->offset != 0)5858+6359#define divider_exists(div) FLAG_TEST(div, DIV, EXISTS)6460#define divider_is_fixed(div) FLAG_TEST(div, DIV, FIXED)6561#define divider_has_fraction(div) (!divider_is_fixed(div) && \···69617062#define selector_exists(sel) ((sel)->width != 0)7163#define trigger_exists(trig) FLAG_TEST(trig, TRIG, EXISTS)6464+6565+#define policy_lvm_en_exists(enable) ((enable)->offset != 0)6666+#define policy_ctl_exists(control) ((control)->offset != 0)72677368/* Clock type, used to tell common block what it's part of */7469enum bcm_clk_type {···8271};83728473/*8585- * Each CCU defines a mapped area of memory containing registers8686- * used to manage clocks implemented by the CCU. Access to memory8787- * within the CCU's space is serialized by a spinlock. Before any8888- * (other) address can be written, a special access "password" value8989- * must be written to its WR_ACCESS register (located at the base9090- * address of the range). We keep track of the name of each CCU as9191- * it is set up, and maintain them in a list.7474+ * CCU policy control for clocks. Clocks can be enabled or disabled7575+ * based on the CCU policy in effect. One bit in each policy mask7676+ * register (one per CCU policy) represents whether the clock is7777+ * enabled when that policy is effect or not. The CCU policy engine7878+ * must be stopped to update these bits, and must be restarted again7979+ * afterward.9280 */9393-struct ccu_data {9494- void __iomem *base; /* base of mapped address space */9595- spinlock_t lock; /* serialization lock */9696- bool write_enabled; /* write access is currently enabled */9797- struct list_head links; /* for ccu_list */9898- struct device_node *node;9999- struct clk_onecell_data data;100100- const char *name;101101- u32 range; /* byte range of address space */8181+struct bcm_clk_policy {8282+ u32 offset; /* first policy mask register offset */8383+ u32 bit; /* bit used in all mask registers */10284};8585+8686+/* Policy initialization macro */8787+8888+#define POLICY(_offset, _bit) \8989+ { \9090+ .offset = (_offset), \9191+ .bit = (_bit), \9292+ }1039310494/*10595 * Gating control and status is managed by a 32-bit gate register.···205193 .offset = (_offset), \206194 .status_bit = (_status_bit), \207195 .flags = FLAG(GATE, HW)|FLAG(GATE, EXISTS), \196196+ }197197+198198+/* Gate hysteresis for clocks */199199+struct bcm_clk_hyst {200200+ u32 offset; /* hyst register offset (normally CLKGATE) */201201+ u32 en_bit; /* bit used to enable hysteresis */202202+ u32 val_bit; /* if enabled: 0 = low delay; 1 = high delay */203203+};204204+205205+/* Hysteresis initialization macro */206206+207207+#define HYST(_offset, _en_bit, _val_bit) \208208+ { \209209+ .offset = (_offset), \210210+ .en_bit = (_en_bit), \211211+ .val_bit = (_val_bit), \208212 }209213210214/*···388360 }389361390362struct peri_clk_data {363363+ struct bcm_clk_policy policy;391364 struct bcm_clk_gate gate;365365+ struct bcm_clk_hyst hyst;392366 struct bcm_clk_trig pre_trig;393367 struct bcm_clk_div pre_div;394368 struct bcm_clk_trig trig;···403373404374struct kona_clk {405375 struct clk_hw hw;406406- struct clk_init_data init_data;407407- const char *name; /* name of this clock */376376+ struct clk_init_data init_data; /* includes name of this clock */408377 struct ccu_data *ccu; /* ccu this clock is associated with */409378 enum bcm_clk_type type;410379 union {···414385#define to_kona_clk(_hw) \415386 container_of(_hw, struct kona_clk, hw)416387388388+/* Initialization macro for an entry in a CCU's kona_clks[] array. */389389+#define KONA_CLK(_ccu_name, _clk_name, _type) \390390+ { \391391+ .init_data = { \392392+ .name = #_clk_name, \393393+ .ops = &kona_ ## _type ## _clk_ops, \394394+ }, \395395+ .ccu = &_ccu_name ## _ccu_data, \396396+ .type = bcm_clk_ ## _type, \397397+ .u.data = &_clk_name ## _data, \398398+ }399399+#define LAST_KONA_CLK { .type = bcm_clk_none }400400+401401+/*402402+ * CCU policy control. To enable software update of the policy403403+ * tables the CCU policy engine must be stopped by setting the404404+ * software update enable bit (LVM_EN). After an update the engine405405+ * is restarted using the GO bit and either the GO_ATL or GO_AC bit.406406+ */407407+struct bcm_lvm_en {408408+ u32 offset; /* LVM_EN register offset */409409+ u32 bit; /* POLICY_CONFIG_EN bit in register */410410+};411411+412412+/* Policy enable initialization macro */413413+#define CCU_LVM_EN(_offset, _bit) \414414+ { \415415+ .offset = (_offset), \416416+ .bit = (_bit), \417417+ }418418+419419+struct bcm_policy_ctl {420420+ u32 offset; /* POLICY_CTL register offset */421421+ u32 go_bit;422422+ u32 atl_bit; /* GO, GO_ATL, and GO_AC bits */423423+ u32 ac_bit;424424+};425425+426426+/* Policy control initialization macro */427427+#define CCU_POLICY_CTL(_offset, _go_bit, _ac_bit, _atl_bit) \428428+ { \429429+ .offset = (_offset), \430430+ .go_bit = (_go_bit), \431431+ .ac_bit = (_ac_bit), \432432+ .atl_bit = (_atl_bit), \433433+ }434434+435435+struct ccu_policy {436436+ struct bcm_lvm_en enable;437437+ struct bcm_policy_ctl control;438438+};439439+440440+/*441441+ * Each CCU defines a mapped area of memory containing registers442442+ * used to manage clocks implemented by the CCU. Access to memory443443+ * within the CCU's space is serialized by a spinlock. Before any444444+ * (other) address can be written, a special access "password" value445445+ * must be written to its WR_ACCESS register (located at the base446446+ * address of the range). We keep track of the name of each CCU as447447+ * it is set up, and maintain them in a list.448448+ */449449+struct ccu_data {450450+ void __iomem *base; /* base of mapped address space */451451+ spinlock_t lock; /* serialization lock */452452+ bool write_enabled; /* write access is currently enabled */453453+ struct ccu_policy policy;454454+ struct list_head links; /* for ccu_list */455455+ struct device_node *node;456456+ struct clk_onecell_data clk_data;457457+ const char *name;458458+ u32 range; /* byte range of address space */459459+ struct kona_clk kona_clks[]; /* must be last */460460+};461461+462462+/* Initialization for common fields in a Kona ccu_data structure */463463+#define KONA_CCU_COMMON(_prefix, _name, _ccuname) \464464+ .name = #_name "_ccu", \465465+ .lock = __SPIN_LOCK_UNLOCKED(_name ## _ccu_data.lock), \466466+ .links = LIST_HEAD_INIT(_name ## _ccu_data.links), \467467+ .clk_data = { \468468+ .clk_num = _prefix ## _ ## _ccuname ## _CCU_CLOCK_COUNT, \469469+ }470470+417471/* Exported globals */418472419473extern struct clk_ops kona_peri_clk_ops;420420-421421-/* Help functions */422422-423423-#define PERI_CLK_SETUP(clks, ccu, id, name) \424424- clks[id] = kona_clk_setup(ccu, #name, bcm_clk_peri, &name ## _data)425474426475/* Externally visible functions */427476···508401extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value,509402 u32 billionths);510403511511-extern struct clk *kona_clk_setup(struct ccu_data *ccu, const char *name,512512- enum bcm_clk_type type, void *data);513513-extern void __init kona_dt_ccu_setup(struct device_node *node,514514- int (*ccu_clks_setup)(struct ccu_data *));404404+extern struct clk *kona_clk_setup(struct kona_clk *bcm_clk);405405+extern void __init kona_dt_ccu_setup(struct ccu_data *ccu,406406+ struct device_node *node);515407extern bool __init kona_ccu_init(struct ccu_data *ccu);516408517409#endif /* _CLK_KONA_H */
···2727static DEFINE_MUTEX(clocks_mutex);28282929#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)3030+3131+/**3232+ * of_clk_get_by_clkspec() - Lookup a clock form a clock provider3333+ * @clkspec: pointer to a clock specifier data structure3434+ *3535+ * This function looks up a struct clk from the registered list of clock3636+ * providers, an input is a clock specifier data structure as returned3737+ * from the of_parse_phandle_with_args() function call.3838+ */3939+struct clk *of_clk_get_by_clkspec(struct of_phandle_args *clkspec)4040+{4141+ struct clk *clk;4242+4343+ if (!clkspec)4444+ return ERR_PTR(-EINVAL);4545+4646+ of_clk_lock();4747+ clk = __of_clk_get_from_provider(clkspec);4848+4949+ if (!IS_ERR(clk) && !__clk_get(clk))5050+ clk = ERR_PTR(-ENOENT);5151+5252+ of_clk_unlock();5353+ return clk;5454+}5555+3056struct clk *of_clk_get(struct device_node *np, int index)3157{3258 struct of_phandle_args clkspec;···6741 if (rc)6842 return ERR_PTR(rc);69437070- of_clk_lock();7171- clk = __of_clk_get_from_provider(&clkspec);7272-7373- if (!IS_ERR(clk) && !__clk_get(clk))7474- clk = ERR_PTR(-ENOENT);7575-7676- of_clk_unlock();4444+ clk = of_clk_get_by_clkspec(&clkspec);7745 of_node_put(clkspec.np);7846 return clk;7947}
···1313 i2c, USB, SD/eMMC, etc.14141515config MSM_GCC_89601616- tristate "MSM8960 Global Clock Controller"1616+ tristate "APQ8064/MSM8960 Global Clock Controller"1717 depends on COMMON_CLK_QCOM1818 help1919- Support for the global clock controller on msm8960 devices.1919+ Support for the global clock controller on apq8064/msm8960 devices.2020 Say Y if you want to use peripheral devices such as UART, SPI,2121 i2c, USB, SD/eMMC, SATA, PCIe, etc.2222
···11+/*22+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.33+ *44+ * This software is licensed under the terms of the GNU General Public55+ * License version 2, as published by the Free Software Foundation, and66+ * may be copied, distributed, and modified under those terms.77+ *88+ * This program is distributed in the hope that it will be useful,99+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1010+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111+ * GNU General Public License for more details.1212+ */1313+1414+#include <linux/export.h>1515+#include <linux/regmap.h>1616+#include <linux/platform_device.h>1717+#include <linux/clk-provider.h>1818+#include <linux/reset-controller.h>1919+2020+#include "common.h"2121+#include "clk-regmap.h"2222+#include "reset.h"2323+2424+struct qcom_cc {2525+ struct qcom_reset_controller reset;2626+ struct clk_onecell_data data;2727+ struct clk *clks[];2828+};2929+3030+int qcom_cc_probe(struct platform_device *pdev, const struct qcom_cc_desc *desc)3131+{3232+ void __iomem *base;3333+ struct resource *res;3434+ int i, ret;3535+ struct device *dev = &pdev->dev;3636+ struct clk *clk;3737+ struct clk_onecell_data *data;3838+ struct clk **clks;3939+ struct regmap *regmap;4040+ struct qcom_reset_controller *reset;4141+ struct qcom_cc *cc;4242+ size_t num_clks = desc->num_clks;4343+ struct clk_regmap **rclks = desc->clks;4444+4545+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);4646+ base = devm_ioremap_resource(dev, res);4747+ if (IS_ERR(base))4848+ return PTR_ERR(base);4949+5050+ regmap = devm_regmap_init_mmio(dev, base, desc->config);5151+ if (IS_ERR(regmap))5252+ return PTR_ERR(regmap);5353+5454+ cc = devm_kzalloc(dev, sizeof(*cc) + sizeof(*clks) * num_clks,5555+ GFP_KERNEL);5656+ if (!cc)5757+ return -ENOMEM;5858+5959+ clks = cc->clks;6060+ data = &cc->data;6161+ data->clks = clks;6262+ data->clk_num = num_clks;6363+6464+ for (i = 0; i < num_clks; i++) {6565+ if (!rclks[i])6666+ continue;6767+ clk = devm_clk_register_regmap(dev, rclks[i]);6868+ if (IS_ERR(clk))6969+ return PTR_ERR(clk);7070+ clks[i] = clk;7171+ }7272+7373+ ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get, data);7474+ if (ret)7575+ return ret;7676+7777+ reset = &cc->reset;7878+ reset->rcdev.of_node = dev->of_node;7979+ reset->rcdev.ops = &qcom_reset_ops;8080+ reset->rcdev.owner = dev->driver->owner;8181+ reset->rcdev.nr_resets = desc->num_resets;8282+ reset->regmap = regmap;8383+ reset->reset_map = desc->resets;8484+ platform_set_drvdata(pdev, &reset->rcdev);8585+8686+ ret = reset_controller_register(&reset->rcdev);8787+ if (ret)8888+ of_clk_del_provider(dev->of_node);8989+9090+ return ret;9191+}9292+EXPORT_SYMBOL_GPL(qcom_cc_probe);9393+9494+void qcom_cc_remove(struct platform_device *pdev)9595+{9696+ of_clk_del_provider(pdev->dev.of_node);9797+ reset_controller_unregister(platform_get_drvdata(pdev));9898+}9999+EXPORT_SYMBOL_GPL(qcom_cc_remove);
+34
drivers/clk/qcom/common.h
···11+/*22+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.33+ *44+ * This software is licensed under the terms of the GNU General Public55+ * License version 2, as published by the Free Software Foundation, and66+ * may be copied, distributed, and modified under those terms.77+ *88+ * This program is distributed in the hope that it will be useful,99+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1010+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111+ * GNU General Public License for more details.1212+ */1313+#ifndef __QCOM_CLK_COMMON_H__1414+#define __QCOM_CLK_COMMON_H__1515+1616+struct platform_device;1717+struct regmap_config;1818+struct clk_regmap;1919+struct qcom_reset_map;2020+2121+struct qcom_cc_desc {2222+ const struct regmap_config *config;2323+ struct clk_regmap **clks;2424+ size_t num_clks;2525+ const struct qcom_reset_map *resets;2626+ size_t num_resets;2727+};2828+2929+extern int qcom_cc_probe(struct platform_device *pdev,3030+ const struct qcom_cc_desc *desc);3131+3232+extern void qcom_cc_remove(struct platform_device *pdev);3333+3434+#endif
···53535454#define NUM_MIO_PINS 5455555656+#define DBG_CLK_CTRL_CLKACT_TRC BIT(0)5757+#define DBG_CLK_CTRL_CPU_1XCLKACT BIT(1)5858+5659enum zynq_clk {5760 armpll, ddrpll, iopll,5861 cpu_6or4x, cpu_3or2x, cpu_2x, cpu_1x,···501498 clks[dbg_apb] = clk_register_gate(NULL, clk_output_name[dbg_apb],502499 clk_output_name[cpu_1x], 0, SLCR_DBG_CLK_CTRL, 1, 0,503500 &dbgclk_lock);501501+502502+ /* leave debug clocks in the state the bootloader set them up to */503503+ tmp = clk_readl(SLCR_DBG_CLK_CTRL);504504+ if (tmp & DBG_CLK_CTRL_CLKACT_TRC)505505+ if (clk_prepare_enable(clks[dbg_trc]))506506+ pr_warn("%s: trace clk enable failed\n", __func__);507507+ if (tmp & DBG_CLK_CTRL_CPU_1XCLKACT)508508+ if (clk_prepare_enable(clks[dbg_apb]))509509+ pr_warn("%s: debug APB clk enable failed\n", __func__);504510505511 /* One gated clock for all APER clocks. */506512 clks[dma] = clk_register_gate(NULL, clk_output_name[dma],
+62
include/dt-bindings/clock/bcm21664.h
···11+/*22+ * Copyright (C) 2013 Broadcom Corporation33+ * Copyright 2013 Linaro Limited44+ *55+ * This program is free software; you can redistribute it and/or66+ * modify it under the terms of the GNU General Public License as77+ * published by the Free Software Foundation version 2.88+ *99+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any1010+ * kind, whether express or implied; without even the implied warranty1111+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ */1414+1515+#ifndef _CLOCK_BCM21664_H1616+#define _CLOCK_BCM21664_H1717+1818+/*1919+ * This file defines the values used to specify clocks provided by2020+ * the clock control units (CCUs) on Broadcom BCM21664 family SoCs.2121+ */2222+2323+/* bcm21664 CCU device tree "compatible" strings */2424+#define BCM21664_DT_ROOT_CCU_COMPAT "brcm,bcm21664-root-ccu"2525+#define BCM21664_DT_AON_CCU_COMPAT "brcm,bcm21664-aon-ccu"2626+#define BCM21664_DT_MASTER_CCU_COMPAT "brcm,bcm21664-master-ccu"2727+#define BCM21664_DT_SLAVE_CCU_COMPAT "brcm,bcm21664-slave-ccu"2828+2929+/* root CCU clock ids */3030+3131+#define BCM21664_ROOT_CCU_FRAC_1M 03232+#define BCM21664_ROOT_CCU_CLOCK_COUNT 13333+3434+/* aon CCU clock ids */3535+3636+#define BCM21664_AON_CCU_HUB_TIMER 03737+#define BCM21664_AON_CCU_CLOCK_COUNT 13838+3939+/* master CCU clock ids */4040+4141+#define BCM21664_MASTER_CCU_SDIO1 04242+#define BCM21664_MASTER_CCU_SDIO2 14343+#define BCM21664_MASTER_CCU_SDIO3 24444+#define BCM21664_MASTER_CCU_SDIO4 34545+#define BCM21664_MASTER_CCU_SDIO1_SLEEP 44646+#define BCM21664_MASTER_CCU_SDIO2_SLEEP 54747+#define BCM21664_MASTER_CCU_SDIO3_SLEEP 64848+#define BCM21664_MASTER_CCU_SDIO4_SLEEP 74949+#define BCM21664_MASTER_CCU_CLOCK_COUNT 85050+5151+/* slave CCU clock ids */5252+5353+#define BCM21664_SLAVE_CCU_UARTB 05454+#define BCM21664_SLAVE_CCU_UARTB2 15555+#define BCM21664_SLAVE_CCU_UARTB3 25656+#define BCM21664_SLAVE_CCU_BSC1 35757+#define BCM21664_SLAVE_CCU_BSC2 45858+#define BCM21664_SLAVE_CCU_BSC3 55959+#define BCM21664_SLAVE_CCU_BSC4 66060+#define BCM21664_SLAVE_CCU_CLOCK_COUNT 76161+6262+#endif /* _CLOCK_BCM21664_H */
+12
include/dt-bindings/clock/bcm281xx.h
···2020 * the clock control units (CCUs) on Broadcom BCM281XX family SoCs.2121 */22222323+/*2424+ * These are the bcm281xx CCU device tree "compatible" strings.2525+ * We're stuck with using "bcm11351" in the string because wild2626+ * cards aren't allowed, and that name was the first one defined2727+ * in this family of devices.2828+ */2929+#define BCM281XX_DT_ROOT_CCU_COMPAT "brcm,bcm11351-root-ccu"3030+#define BCM281XX_DT_AON_CCU_COMPAT "brcm,bcm11351-aon-ccu"3131+#define BCM281XX_DT_HUB_CCU_COMPAT "brcm,bcm11351-hub-ccu"3232+#define BCM281XX_DT_MASTER_CCU_COMPAT "brcm,bcm11351-master-ccu"3333+#define BCM281XX_DT_SLAVE_CCU_COMPAT "brcm,bcm11351-slave-ccu"3434+2335/* root CCU clock ids */24362537#define BCM281XX_ROOT_CCU_FRAC_1M 0
+58
include/dt-bindings/clock/hix5hd2-clock.h
···11+/*22+ * Copyright (c) 2014 Linaro Ltd.33+ * Copyright (c) 2014 Hisilicon Limited.44+ *55+ * This program is free software; you can redistribute it and/or modify it66+ * under the terms and conditions of the GNU General Public License,77+ * version 2, as published by the Free Software Foundation.88+ */99+1010+#ifndef __DTS_HIX5HD2_CLOCK_H1111+#define __DTS_HIX5HD2_CLOCK_H1212+1313+/* fixed rate */1414+#define HIX5HD2_FIXED_1200M 11515+#define HIX5HD2_FIXED_400M 21616+#define HIX5HD2_FIXED_48M 31717+#define HIX5HD2_FIXED_24M 41818+#define HIX5HD2_FIXED_600M 51919+#define HIX5HD2_FIXED_300M 62020+#define HIX5HD2_FIXED_75M 72121+#define HIX5HD2_FIXED_200M 82222+#define HIX5HD2_FIXED_100M 92323+#define HIX5HD2_FIXED_40M 102424+#define HIX5HD2_FIXED_150M 112525+#define HIX5HD2_FIXED_1728M 122626+#define HIX5HD2_FIXED_28P8M 132727+#define HIX5HD2_FIXED_432M 142828+#define HIX5HD2_FIXED_345P6M 152929+#define HIX5HD2_FIXED_288M 163030+#define HIX5HD2_FIXED_60M 173131+#define HIX5HD2_FIXED_750M 183232+#define HIX5HD2_FIXED_500M 193333+#define HIX5HD2_FIXED_54M 203434+#define HIX5HD2_FIXED_27M 213535+#define HIX5HD2_FIXED_1500M 223636+#define HIX5HD2_FIXED_375M 233737+#define HIX5HD2_FIXED_187M 243838+#define HIX5HD2_FIXED_250M 253939+#define HIX5HD2_FIXED_125M 264040+#define HIX5HD2_FIXED_2P02M 274141+#define HIX5HD2_FIXED_50M 284242+#define HIX5HD2_FIXED_25M 294343+#define HIX5HD2_FIXED_83M 304444+4545+/* mux clocks */4646+#define HIX5HD2_SFC_MUX 644747+#define HIX5HD2_MMC_MUX 654848+#define HIX5HD2_FEPHY_MUX 664949+5050+/* gate clocks */5151+#define HIX5HD2_SFC_RST 1285252+#define HIX5HD2_SFC_CLK 1295353+#define HIX5HD2_MMC_CIU_CLK 1305454+#define HIX5HD2_MMC_BIU_CLK 1315555+#define HIX5HD2_MMC_CIU_RST 1325656+5757+#define HIX5HD2_NR_CLKS 2565858+#endif /* __DTS_HIX5HD2_CLOCK_H */
···4040 * through the clk_* api.4141 *4242 * @prepare: Prepare the clock for enabling. This must not return until4343- * the clock is fully prepared, and it's safe to call clk_enable.4444- * This callback is intended to allow clock implementations to4545- * do any initialisation that may sleep. Called with4646- * prepare_lock held.4343+ * the clock is fully prepared, and it's safe to call clk_enable.4444+ * This callback is intended to allow clock implementations to4545+ * do any initialisation that may sleep. Called with4646+ * prepare_lock held.4747 *4848 * @unprepare: Release the clock from its prepared state. This will typically4949- * undo any work done in the @prepare callback. Called with5050- * prepare_lock held.4949+ * undo any work done in the @prepare callback. Called with5050+ * prepare_lock held.5151 *5252 * @is_prepared: Queries the hardware to determine if the clock is prepared.5353 * This function is allowed to sleep. Optional, if this op is not···5858 * Called with prepare mutex held. This function may sleep.5959 *6060 * @enable: Enable the clock atomically. This must not return until the6161- * clock is generating a valid clock signal, usable by consumer6262- * devices. Called with enable_lock held. This function must not6363- * sleep.6161+ * clock is generating a valid clock signal, usable by consumer6262+ * devices. Called with enable_lock held. This function must not6363+ * sleep.6464 *6565 * @disable: Disable the clock atomically. Called with enable_lock held.6666- * This function must not sleep.6666+ * This function must not sleep.6767 *6868 * @is_enabled: Queries the hardware to determine if the clock is enabled.6969- * This function must not sleep. Optional, if this op is not7070- * set then the enable count will be used.6969+ * This function must not sleep. Optional, if this op is not7070+ * set then the enable count will be used.7171 *7272 * @disable_unused: Disable the clock atomically. Only called from7373 * clk_disable_unused for gate clocks with special needs.···7575 * sleep.7676 *7777 * @recalc_rate Recalculate the rate of this clock, by querying hardware. The7878- * parent rate is an input parameter. It is up to the caller to7979- * ensure that the prepare_mutex is held across this call.8080- * Returns the calculated rate. Optional, but recommended - if8181- * this op is not set then clock rate will be initialized to 0.7878+ * parent rate is an input parameter. It is up to the caller to7979+ * ensure that the prepare_mutex is held across this call.8080+ * Returns the calculated rate. Optional, but recommended - if8181+ * this op is not set then clock rate will be initialized to 0.8282 *8383 * @round_rate: Given a target rate as input, returns the closest rate actually8484- * supported by the clock.8484+ * supported by the clock. The parent rate is an input/output8585+ * parameter.8586 *8687 * @determine_rate: Given a target rate as input, returns the closest rate8788 * actually supported by the clock, and optionally the parent clock8889 * that should be used to provide the clock rate.8990 *9090- * @get_parent: Queries the hardware to determine the parent of a clock. The9191- * return value is a u8 which specifies the index corresponding to9292- * the parent clock. This index can be applied to either the9393- * .parent_names or .parents arrays. In short, this function9494- * translates the parent value read from hardware into an array9595- * index. Currently only called when the clock is initialized by9696- * __clk_init. This callback is mandatory for clocks with9797- * multiple parents. It is optional (and unnecessary) for clocks9898- * with 0 or 1 parents.9999- *10091 * @set_parent: Change the input source of this clock; for clocks with multiple101101- * possible parents specify a new parent by passing in the index102102- * as a u8 corresponding to the parent in either the .parent_names103103- * or .parents arrays. This function in affect translates an104104- * array index into the value programmed into the hardware.105105- * Returns 0 on success, -EERROR otherwise.9292+ * possible parents specify a new parent by passing in the index9393+ * as a u8 corresponding to the parent in either the .parent_names9494+ * or .parents arrays. This function in affect translates an9595+ * array index into the value programmed into the hardware.9696+ * Returns 0 on success, -EERROR otherwise.9797+ *9898+ * @get_parent: Queries the hardware to determine the parent of a clock. The9999+ * return value is a u8 which specifies the index corresponding to100100+ * the parent clock. This index can be applied to either the101101+ * .parent_names or .parents arrays. In short, this function102102+ * translates the parent value read from hardware into an array103103+ * index. Currently only called when the clock is initialized by104104+ * __clk_init. This callback is mandatory for clocks with105105+ * multiple parents. It is optional (and unnecessary) for clocks106106+ * with 0 or 1 parents.106107 *107108 * @set_rate: Change the rate of this clock. The requested rate is specified108109 * by the second argument, which should typically be the return109110 * of .round_rate call. The third argument gives the parent rate110111 * which is likely helpful for most .set_rate implementation.111112 * Returns 0 on success, -EERROR otherwise.112112- *113113- * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy114114- * is expressed in ppb (parts per billion). The parent accuracy is115115- * an input parameter.116116- * Returns the calculated accuracy. Optional - if this op is not117117- * set then clock accuracy will be initialized to parent accuracy118118- * or 0 (perfect clock) if clock has no parent.119113 *120114 * @set_rate_and_parent: Change the rate and the parent of this clock. The121115 * requested rate is specified by the second argument, which···121127 * for clocks that can tolerate switching the rate and the parent122128 * separately via calls to .set_parent and .set_rate.123129 * Returns 0 on success, -EERROR otherwise.130130+ *131131+ * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy132132+ * is expressed in ppb (parts per billion). The parent accuracy is133133+ * an input parameter.134134+ * Returns the calculated accuracy. Optional - if this op is not135135+ * set then clock accuracy will be initialized to parent accuracy136136+ * or 0 (perfect clock) if clock has no parent.137137+ *138138+ * @init: Perform platform-specific initialization magic.139139+ * This is not not used by any of the basic clock types.140140+ * Please consider other ways of solving initialization problems141141+ * before using this callback, as its use is discouraged.124142 *125143 * @debug_init: Set up type-specific debugfs entries for this clock. This126144 * is called once, after the debugfs directory entry for this···163157 void (*disable_unused)(struct clk_hw *hw);164158 unsigned long (*recalc_rate)(struct clk_hw *hw,165159 unsigned long parent_rate);166166- long (*round_rate)(struct clk_hw *hw, unsigned long,167167- unsigned long *);160160+ long (*round_rate)(struct clk_hw *hw, unsigned long rate,161161+ unsigned long *parent_rate);168162 long (*determine_rate)(struct clk_hw *hw, unsigned long rate,169163 unsigned long *best_parent_rate,170164 struct clk **best_parent_clk);171165 int (*set_parent)(struct clk_hw *hw, u8 index);172166 u8 (*get_parent)(struct clk_hw *hw);173173- int (*set_rate)(struct clk_hw *hw, unsigned long,174174- unsigned long);167167+ int (*set_rate)(struct clk_hw *hw, unsigned long rate,168168+ unsigned long parent_rate);175169 int (*set_rate_and_parent)(struct clk_hw *hw,176170 unsigned long rate,177171 unsigned long parent_rate, u8 index);···260254 *261255 * Flags:262256 * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to263263- * enable the clock. Setting this flag does the opposite: setting the bit264264- * disable the clock and clearing it enables the clock257257+ * enable the clock. Setting this flag does the opposite: setting the bit258258+ * disable the clock and clearing it enables the clock265259 * CLK_GATE_HIWORD_MASK - The gate settings are only in lower 16-bit266266- * of this register, and mask of gate bits are in higher 16-bit of this267267- * register. While setting the gate bits, higher 16-bit should also be268268- * updated to indicate changing gate bits.260260+ * of this register, and mask of gate bits are in higher 16-bit of this261261+ * register. While setting the gate bits, higher 16-bit should also be262262+ * updated to indicate changing gate bits.269263 */270264struct clk_gate {271265 struct clk_hw hw;···304298 *305299 * Flags:306300 * CLK_DIVIDER_ONE_BASED - by default the divisor is the value read from the307307- * register plus one. If CLK_DIVIDER_ONE_BASED is set then the divider is308308- * the raw value read from the register, with the value of zero considered301301+ * register plus one. If CLK_DIVIDER_ONE_BASED is set then the divider is302302+ * the raw value read from the register, with the value of zero considered309303 * invalid, unless CLK_DIVIDER_ALLOW_ZERO is set.310304 * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from311311- * the hardware register305305+ * the hardware register312306 * CLK_DIVIDER_ALLOW_ZERO - Allow zero divisors. For dividers which have313307 * CLK_DIVIDER_ONE_BASED set, it is possible to end up with a zero divisor.314308 * Some hardware implementations gracefully handle this case and allow a315309 * zero divisor by not modifying their input clock316310 * (divide by one / bypass).317311 * CLK_DIVIDER_HIWORD_MASK - The divider settings are only in lower 16-bit318318- * of this register, and mask of divider bits are in higher 16-bit of this319319- * register. While setting the divider bits, higher 16-bit should also be320320- * updated to indicate changing divider bits.312312+ * of this register, and mask of divider bits are in higher 16-bit of this313313+ * register. While setting the divider bits, higher 16-bit should also be314314+ * updated to indicate changing divider bits.315315+ * CLK_DIVIDER_ROUND_CLOSEST - Makes the best calculated divider to be rounded316316+ * to the closest integer instead of the up one.317317+ * CLK_DIVIDER_READ_ONLY - The divider settings are preconfigured and should318318+ * not be changed by the clock framework.321319 */322320struct clk_divider {323321 struct clk_hw hw;···337327#define CLK_DIVIDER_POWER_OF_TWO BIT(1)338328#define CLK_DIVIDER_ALLOW_ZERO BIT(2)339329#define CLK_DIVIDER_HIWORD_MASK BIT(3)330330+#define CLK_DIVIDER_ROUND_CLOSEST BIT(4)331331+#define CLK_DIVIDER_READ_ONLY BIT(5)340332341333extern const struct clk_ops clk_divider_ops;334334+extern const struct clk_ops clk_divider_ro_ops;342335struct clk *clk_register_divider(struct device *dev, const char *name,343336 const char *parent_name, unsigned long flags,344337 void __iomem *reg, u8 shift, u8 width,···369356 * CLK_MUX_INDEX_ONE - register index starts at 1, not 0370357 * CLK_MUX_INDEX_BIT - register index is a single bit (power of two)371358 * CLK_MUX_HIWORD_MASK - The mux settings are only in lower 16-bit of this372372- * register, and mask of mux bits are in higher 16-bit of this register.373373- * While setting the mux bits, higher 16-bit should also be updated to374374- * indicate changing mux bits.359359+ * register, and mask of mux bits are in higher 16-bit of this register.360360+ * While setting the mux bits, higher 16-bit should also be updated to361361+ * indicate changing mux bits.375362 */376363struct clk_mux {377364 struct clk_hw hw;
+3
include/linux/clk/shmobile.h
···11/*22 * Copyright 2013 Ideas On Board SPRL33+ * Copyright 2013, 2014 Horms Solutions Ltd.34 *45 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>66+ * Contact: Simon Horman <horms@verge.net.au>57 *68 * This program is free software; you can redistribute it and/or modify79 * it under the terms of the GNU General Public License as published by···16141715#include <linux/types.h>18161717+void r8a7779_clocks_init(u32 mode);1918void rcar_gen2_clocks_init(u32 mode);20192120#endif
+22
include/linux/clk/sunxi.h
···11+/*22+ * Copyright 2013 - Hans de Goede <hdegoede@redhat.com>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or77+ * (at your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful,1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ */1414+1515+#ifndef __LINUX_CLK_SUNXI_H_1616+#define __LINUX_CLK_SUNXI_H_1717+1818+#include <linux/clk.h>1919+2020+void clk_sunxi_mmc_phase_control(struct clk *clk, u8 sample, u8 output);2121+2222+#endif