Clk drivers for NXP LPC18xx family
Subsystems (3)
v3 cover Clk drivers for NXP LPC18xx family
This patch set adds support for the two main clock peripherals in the LPC18xx/43xx MCU family.
The Clock Generation Unit (CGU) is the base source of all clocks. It has five external inputs and contains PLLs, dividers and muxes. The outputs from the CGU are then routed to a Clock Control Unit (CCU) and a few peripherals directly. There are two CCUs in the MCU. The CCU is a collection of gates and a few dividers that sits between the CGU and most of the peripherals. These clock drivers are needed by the timer at early boot so both are using CLK_OF_DECLARE.
Which clocks that are available depends on the specific device and it's peripherals. It's possible in DT to setup the routing between the CGU and the CCUs.
The biggest change in v3 is the way parent names for CCU clocks are retrieved. Previous version used names from the 'clock-output-names' node on CGU and of_clk_get_parent_name(). In this version the clock names has been moved into the CGU driver and are retrieved from the CCU driver by of_clk_get() and __clk_get_name().
The of_clk_get_index function is used to map CCU branches to to the base clocks by using the CGU ID retrieved with of_clk_get_index. An alternative approach would be to put the base clock names directly in the CCU driver where the CGU ID is today. See clk_branches table in clk-lpc18xx-ccu.c. If this is the prefered way of doing this please let me know and I'll quickly put out a new version.
Changes since v2:
- use 'clock-controller' as node name in doc
- add patch with of_clk_get_index function
- drop 'clock-indices' and 'clock-output-names' from cgu node
- move base clock names into cgu driver
- use of_clk_get/__clk_get_name in ccu to get parent name for composite clocks.
- other misc fixes to ccu driver and cgu doc
Changes since v1:
- reorganize cgu clk structs
- macros to create cgu clk structs
- move drivers to nxp subdir
- rebase on v4.1-rc1
The last patch (dts changes) are only included in this patch set for illustration purposes. DTS changes will be sent separately to the ARM SoC team later.
Base support for LPC18xx is now in arm-soc next. Pinctrl, gpio and reset drivers are also upstream.
Joachim Eastwood (6):
clk: add lpc18xx cgu clk driver
doc: dt: add documentation for lpc1850-cgu clk driver
clk: add function to retrieve clk id from dt
clk: add lpc18xx ccu clk driver
doc: dt: add documentation for lpc1850-ccu clk driver
ARM: dts: lpc18xx: add clock nodes for cgu and ccu
.../devicetree/bindings/clock/lpc1850-ccu.txt | 146 +++++ .../devicetree/bindings/clock/lpc1850-cgu.txt | 131 +++++ arch/arm/boot/dts/lpc18xx.dtsi | 77 ++- arch/arm/boot/dts/lpc4350-hitex-eval.dts | 4 - drivers/clk/Makefile | 1 + drivers/clk/clk.c | 18 + drivers/clk/nxp/Makefile | 2 + drivers/clk/nxp/clk-lpc18xx-ccu.c | 305 ++++++++++ drivers/clk/nxp/clk-lpc18xx-cgu.c | 635 +++++++++++++++++++++ include/dt-bindings/clock/lpc18xx-ccu.h | 74 +++ include/dt-bindings/clock/lpc18xx-cgu.h | 41 ++ include/linux/clk-provider.h | 1 + 12 files changed, 1417 insertions(+), 18 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-ccu.txt create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-cgu.txt create mode 100644 drivers/clk/nxp/Makefile create mode 100644 drivers/clk/nxp/clk-lpc18xx-ccu.c create mode 100644 drivers/clk/nxp/clk-lpc18xx-cgu.c create mode 100644 include/dt-bindings/clock/lpc18xx-ccu.h create mode 100644 include/dt-bindings/clock/lpc18xx-cgu.h
Signature · 1 line
1.8.0
PATCH v3 1/6 clk: add lpc18xx cgu clk driver
Add driver for NXP LPC18xx/43xx Clock Generation Unit (CGU). The CGU contains several clock generators and output stages that route the clocks either directly to peripherals or to a Clock Control Unit (CCU).
--- drivers/clk/Makefile | 1 + drivers/clk/nxp/Makefile | 1 + drivers/clk/nxp/clk-lpc18xx-cgu.c | 635 ++++++++++++++++++++++++++++++++ include/dt-bindings/clock/lpc18xx-cgu.h | 41 +++ 4 files changed, 678 insertions(+) create mode 100644 drivers/clk/nxp/Makefile create mode 100644 drivers/clk/nxp/clk-lpc18xx-cgu.c create mode 100644 include/dt-bindings/clock/lpc18xx-cgu.h
drivers/clk/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_ARCH_MMP) += mmp/ endif obj-$(CONFIG_PLAT_ORION) += mvebu/ obj-$(CONFIG_ARCH_MXS) += mxs/ +obj-$(CONFIG_ARCH_LPC18XX) += nxp/ obj-$(CONFIG_MACH_PISTACHIO) += pistachio/ obj-$(CONFIG_COMMON_CLK_PXA) += pxa/ obj-$(CONFIG_COMMON_CLK_QCOM) += qcom/
drivers/clk/nxp/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_ARCH_LPC18XX) += clk-lpc18xx-cgu.o
drivers/clk/nxp/clk-lpc18xx-cgu.c new file +635 -0
635 lines not on this page · raw message
include/dt-bindings/clock/lpc18xx-cgu.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v3 2/6 doc: dt: add documentation for lpc1850-cgu clk driver
In reply to Joachim EastwoodAdd DT binding documentation for lpc1850-cgu driver.
--- .../devicetree/bindings/clock/lpc1850-cgu.txt | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-cgu.txt
Documentation/devicetree/bindings/clock/lpc1850-cgu.txt new file +131 -0
@@ -0,0 +1,131 @@ +* NXP LPC1850 Clock Generation Unit (CGU) + +The CGU generates multiple independent clocks for the core and the +peripheral blocks of the LPC18xx. Each independent clock is called +a base clock and itself is one of the inputs to the two Clock +Control Units (CCUs) which control the branch clocks to the +individual peripherals. + +The CGU selects the inputs to the clock generators from multiple +clock sources, controls the clock generation, and routes the outputs +of the clock generators through the clock source bus to the output +stages. Each output stage provides an independent clock source and +corresponds to one of the base clocks for the LPC18xx. + + - Above text taken from NXP LPC1850 User Manual. + + +This binding uses the common clock binding: + Documentation/devicetree/bindings/clock/clock-bindings.txt + +Required properties: +- compatible: + Should be "nxp,lpc1850-cgu" +- reg: + Shall define the base and range of the address space + containing clock control registers +- #clock-cells: + Shall have value <1>. The permitted clock-specifier values + are the base clock numbers defined below. +- clocks: + Shall contain a list of phandles for the external input + sources to the CGU. The list shall be in the following + order: xtal, 32khz, enet_rx_clk, enet_tx_clk, gp_clkin. +- clock-indices: + Shall be an ordered list of numbers defining the base clock + number provided by the CGU. +- clock-output-names: + Shall be an ordered list of strings defining the names of + the clocks provided by the CGU. + +Which base clocks that are available on the CGU depends on the +specific LPC part. Base clocks are numbered from 0 to 27. + +Number: Name: Description: + 0 BASE_SAFE_CLK Base safe clock (always on) for WWDT + 1 BASE_USB0_CLK Base clock for USB0 + 2 BASE_PERIPH_CLK Base clock for Cortex-M0SUB subsystem, + SPI, and SGPIO + 3 BASE_USB1_CLK Base clock for USB1 + 4 BASE_CPU_CLK System base clock for ARM Cortex-M core + and APB peripheral blocks #0 and #2 + 5 BASE_SPIFI_CLK Base clock for SPIFI + 6 BASE_SPI_CLK Base clock for SPI + 7 BASE_PHY_RX_CLK Base clock for Ethernet PHY Receive clock + 8 BASE_PHY_TX_CLK Base clock for Ethernet PHY Transmit clock + 9 BASE_APB1_CLK Base clock for APB peripheral block # 1 +10 BASE_APB3_CLK Base clock for APB peripheral block # 3 +11 BASE_LCD_CLK Base clock for LCD +12 BASE_ADCHS_CLK Base clock for ADCHS +13 BASE_SDIO_CLK Base clock for SD/MMC +14 BASE_SSP0_CLK Base clock for SSP0 +15 BASE_SSP1_CLK Base clock for SSP1 +16 BASE_UART0_CLK Base clock for UART0 +17 BASE_UART1_CLK Base clock for UART1 +18 BASE_UART2_CLK Base clock for UART2 +19 BASE_UART3_CLK Base clock for UART3 +20 BASE_OUT_CLK Base clock for CLKOUT pin +24-21 - Reserved +25 BASE_AUDIO_CLK Base clock for audio system (I2S) +26 BASE_CGU_OUT0_CLK Base clock for CGU_OUT0 clock output +27 BASE_CGU_OUT1_CLK Base clock for CGU_OUT1 clock output + +BASE_PERIPH_CLK and BASE_SPI_CLK is only available on LPC43xx. +BASE_ADCHS_CLK is only available on LPC4370. + + +Example board file: + +/ { + clocks { + xtal: xtal { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <12000000>; + }; + + xtal32: xtal32 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <32768>; + }; + + enet_rx_clk: enet_rx_clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "enet_rx_clk"; + }; + + enet_tx_clk: enet_tx_clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "enet_tx_clk"; + }; + + gp_clkin: gp_clkin { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "gp_clkin"; + }; + }; + + soc { + cgu: clock-controller at 40050000 { + compatible = "nxp,lpc1850-cgu"; + reg = <0x40050000 0x1000>; + #clock-cells = <1>; + clocks = <&xtal>, <&creg_clk 1>, <&enet_rx_clk>, <&enet_tx_clk>, <&gp_clkin>; + }; + + /* A CGU and CCU clock consumer */ + lcdc: lcdc at 40008000 { + ... + clocks = <&cgu BASE_LCD_CLK>, <&ccu1 CLK_CPU_LCD>; + clock-names = "clcdclk", "apb_pclk"; + ... + }; + }; +};
Signature · 1 line
1.8.0
PATCH v3 3/6 clk: add function to retrieve clk id from dt
In reply to Joachim Eastwoodof_clk_get_index can be used to retrieve the clock index/id from the device tree. This can be used in drivers to setup routing between different clock devices.
--- drivers/clk/clk.c | 18 ++++++++++++++++++ include/linux/clk-provider.h | 1 + 2 files changed, 19 insertions(+)
drivers/clk/clk.c +18 -0
@@ -3060,6 +3060,24 @@ const char *of_clk_get_parent_name(struct device_node *np, int index) }EXPORT_SYMBOL_GPL (of_clk_get_parent_name); +int of_clk_get_index (struct device_node *np,int index) +{ +struct of_phandle_args clkspec; +int rc; + +if (index <0 ) +return -EINVAL ; + + rc =of_parse_phandle_with_args (np,"clocks" ,"#clock-cells" , index, + &clkspec); +if (rc) +return -EINVAL ; + +of_node_put (clkspec.np); +return clkspec.args_count ? clkspec.args[0 ] : -EINVAL ; +} +EXPORT_SYMBOL_GPL (of_clk_get_index); +struct clock_provider {of_clk_init_cb_t clk_init_cb;struct device_node *np;
include/linux/clk-provider.h +1 -0
@@ -625,6 +625,7 @@ struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,struct clk *of_clk_src_onecell_get (struct of_phandle_args *clkspec,void *data);int of_clk_get_parent_count (struct device_node *np);const char *of_clk_get_parent_name (struct device_node *np,int index); +int of_clk_get_index (struct device_node *np,int index);void of_clk_init (const struct of_device_id *matches);
Signature · 1 line
1.8.0
PATCH v3 4/6 clk: add lpc18xx ccu clk driver
In reply to Joachim EastwoodAdd driver for NXP LPC18xx/43xx Clock Control Unit (CCU). The CCU provides fine grained gating of most clocks present in the SoC.
--- drivers/clk/nxp/Makefile | 1 + drivers/clk/nxp/clk-lpc18xx-ccu.c | 305 ++++++++++++++++++++++++++++++++ include/dt-bindings/clock/lpc18xx-ccu.h | 74 ++++++++ 3 files changed, 380 insertions(+) create mode 100644 drivers/clk/nxp/clk-lpc18xx-ccu.c create mode 100644 include/dt-bindings/clock/lpc18xx-ccu.h
drivers/clk/nxp/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_ARCH_LPC18XX) += clk-lpc18xx-cgu.o +obj-$(CONFIG_ARCH_LPC18XX) += clk-lpc18xx-ccu.o
drivers/clk/nxp/clk-lpc18xx-ccu.c new file +305 -0
305 lines not on this page · raw message
include/dt-bindings/clock/lpc18xx-ccu.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v3 5/6 doc: dt: add documentation for lpc1850-ccu clk driver
In reply to Joachim EastwoodAdd DT binding documentation for lpc1850-ccu clk driver.
--- .../devicetree/bindings/clock/lpc1850-ccu.txt | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-ccu.txt
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +146 -0
@@ -0,0 +1,146 @@ +* NXP LPC1850 Clock Control Unit (CCU) + +Each CGU base clock has several clock branches which can be turned on +or off independently by the Clock Control Units CCU1 or CCU2. The +branch clocks are distributed between CCU1 and CCU2. + + - Above text taken from NXP LPC1850 User Manual. + +This binding uses the common clock binding: + Documentation/devicetree/bindings/clock/clock-bindings.txt + +Required properties: +- compatible: + Should be "nxp,lpc1850-ccu" +- reg: + Shall define the base and range of the address space + containing clock control registers +- #clock-cells: + Shall have value <1>. The permitted clock-specifier values + are the branch clock names defined in table below. +- clocks: + Shall contain a list of phandles for the base clocks routed + from the CGU to the specific CCU. See mapping of base clocks + and CCU in table below. + +Which brach clocks that are available on the CCU depends on the +specific LPC part. + +CCU1 branch clocks: +Base clock Branch clock Description +BASE_APB3_CLK CLK_APB3_BUS APB3 bus clock. + CLK_APB3_I2C1 Clock to the I2C1 register interface + and I2C1 peripheral clock. + CLK_APB3_DAC Clock to the DAC register interface. + CLK_APB3_ADC0 Clock to the ADC0 register interface + and ADC0 peripheral clock. + CLK_APB3_ADC1 Clock to the ADC1 register interface + and ADC1 peripheral clock. + CLK_APB3_CAN0 Clock to the C_CAN0 register interface + and C_CAN0 peripheral clock. +BASE_APB1_CLK CLK_APB1_BUS APB1 bus clock. + CLK_APB1_MOTOCON_PWM Clock to the PWM Motor control block and + PWM Motor control peripheral clock. + CLK_APB1_I2C0 Clock to the I2C0 register interface and + I2C0 peripheral clock. + CLK_APB1_I2S Clock to the I2S0 and I2S1 register interfaces + and I2S0 and I2S1 peripheral clock. + CLK_APB1_CAN1 Clock to the C_CAN1 register interface and + C_CAN1 peripheral clock. +BASE_SPIFI_CLK CLK_SPIFI Clock for the SPIFI SCKI clock input. +BASE_CPU_CLK CLK_CPU_BUS M4 bus clock. + CLK_CPU_SPIFI Clock to the SPIFI register interface. + CLK_CPU_GPIO Clock to the GPIO register interface + CLK_CPU_LCD Clock to the LCD register interface. + CLK_CPU_ETHERNET Clock to the Ethernet register interface. + CLK_CPU_USB0 Clock to the USB0 register interface. + CLK_CPU_EMC Clock to the External memory controller. + CLK_CPU_SDIO Clock to the SD/MMC register interface. + CLK_CPU_DMA Clock to the DMA register interface. + CLK_CPU_CORE Clock to the Cortex-M core + CLK_CPU_SCT Clock to the SCT register interface. + CLK_CPU_USB1 Clock to the USB1 register interface. + CLK_CPU_EMC_DIV Clock to the EMC with clock divider. + CLK_CPU_FLASHA Clock to the flash bank A. + CLK_CPU_FLASHB Clock to the flash bank B. + CLK_CPU_M0APP Clock to the M0APP coprocessor. + CLK_CPU_ADCHS Clock to the ADCHS. + CLK_CPU_EEPROM Clock to the EEPROM. + CLK_CPU_WWDT Clock to the WWDT register interface. + CLK_CPU_UART0 Clock to the USART0 register interface. + CLK_CPU_UART1 Clock to the UART1 register interface. + CLK_CPU_SSP0 Clock to the SSP0 register interface. + CLK_CPU_TIMER0 Clock to the timer0 register interface and + timer0 peripheral clock. + CLK_CPU_TIMER1 Clock to the timer1 register interface and + timer1 peripheral clock. + CLK_CPU_SCU Clock to the System control unit register interface. + CLK_CPU_CREG Clock to the CREG register interface. + CLK_CPU_RITIMER Clock to the RI timer register interface and + RI timer peripheral clock. + CLK_CPU_UART2 Clock to the UART2 register interface. + CLK_CPU_UART3 Clock to the UART3 register interface. + CLK_CPU_TIMER2 Clock to the timer2 register interface and + timer2 peripheral clock. + CLK_CPU_TIMER3 Clock to the timer3 register interface and + timer3 peripheral clock. + CLK_CPU_SSP1 Clock to the SSP1 register interface. + CLK_CPU_QEI Clock to the QEI register interface and + QEI peripheral clock. +BASE_PERIPH_CLK CLK_PERIPH_BUS Clock to the peripheral bus and the + Cortex-M0 subsystem AHB multilayer matrix. + CLK_PERIPH_CORE Clock to the Cortex-M0 subsystem core. + CLK_PERIPH_SGPIO Clock to the SGPIO interface. +BASE_USB0_CLK CLK_USB0 USB0 peripheral clock. +BASE_USB1_CLK CLK_USB1 USB1 peripheral clock. +BASE_SPI_CLK CLK_SPI Clock to the SPI interface. +BASE_ADCHS_CLK CLK_ADCHS ADCHS clock. + +CCU2 branch clocks: +BASE_AUDIO_CLK CLK_AUDIO Audio system (I2S) clock. +BASE_UART3_CLK CLK_APB2_UART3 USART3 peripheral clock. +BASE_UART2_CLK CLK_APB2_UART2 USART2 peripheral clock. +BASE_UART1_CLK CLK_APB0_UART1 UART1 peripheral clock. +BASE_UART0_CLK CLK_APB0_UART0 USART0 peripheral clock. +BASE_SSP1_CLK CLK_APB2_SSP1 SSP1 peripheral clock. +BASE_SSP0_CLK CLK_APB0_SSP0 SSP0 peripheral clock. +BASE_SDIO_CLK CLK_SDIO SD/MMC peripheral clock. + +Not all branch clocks are available on all LPC parts. Check the user +manual for your specific part. + +Note that CLK_M3_x and CLK_M4_x have been renamed to CLK_CPU_x here +be more generic since both LPC18xx (M3) and LPC43xx (M4) are +supported. + + +Example board file: + +soc { + ccu1: clock-controller at 40051000 { + compatible = "nxp,lpc1850-ccu"; + reg = <0x40051000 0x1000>; + #clock-cells = <1>; + clocks = <&cgu BASE_APB3_CLK>, <&cgu BASE_APB1_CLK>, + <&cgu BASE_SPIFI_CLK>, <&cgu BASE_CPU_CLK>, + <&cgu BASE_PERIPH_CLK>, <&cgu BASE_USB0_CLK>, + <&cgu BASE_USB1_CLK>, <&cgu BASE_SPI_CLK>; + }; + + ccu2: clock-controller at 40052000 { + compatible = "nxp,lpc1850-ccu"; + reg = <0x40052000 0x1000>; + #clock-cells = <1>; + clocks = <&cgu BASE_AUDIO_CLK>, <&cgu BASE_UART3_CLK>, + <&cgu BASE_UART2_CLK>, <&cgu BASE_UART1_CLK>, + <&cgu BASE_UART0_CLK>, <&cgu BASE_SSP1_CLK>, + <&cgu BASE_SSP0_CLK>, <&cgu BASE_SDIO_CLK>; + }; + + /* A user of CCU brach clocks */ + uart1: serial at 40082000 { + ... + clocks = <&ccu2 CLK_APB0_UART1>, <&ccu1 CLK_CPU_UART1>; + ... + }; +};
Signature · 1 line
1.8.0
PATCH v3 6/6 ARM: dts: lpc18xx: add clock nodes for cgu and ccu
In reply to Joachim Eastwood--- arch/arm/boot/dts/lpc18xx.dtsi | 77 ++++++++++++++++++++++++++------ arch/arm/boot/dts/lpc4350-hitex-eval.dts | 4 -- 2 files changed, 63 insertions(+), 18 deletions(-)
arch/arm/boot/dts/lpc18xx.dtsi +63 -14
@@ -13,6 +13,9 @@ #include "armv7-m.dtsi" +#include "dt-bindings/clock/lpc18xx-cgu.h" +#include "dt-bindings/clock/lpc18xx-ccu.h" + / { cpus { #address-cells = <1>;
@@ -22,6 +25,7 @@ compatible = "arm,cortex-m3"; device_type = "cpu"; reg = <0x0>; + clocks = <&ccu1 CLK_CPU_CORE>; }; };
@@ -32,23 +36,68 @@ clock-frequency = <12000000>; }; - /* Temporary hardcode PLL1 until clk drivers are merged */ - pll1: pll1 { - compatible = "fixed-factor-clock"; - clocks = <&xtal>; + xtal32: xtal32 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <32768>; + }; + + enet_rx_clk: enet_rx_clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "enet_rx_clk"; + }; + + enet_tx_clk: enet_tx_clk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "enet_tx_clk"; + }; + + gp_clkin: gp_clkin { + compatible = "fixed-clock"; #clock-cells = <0>; - clock-div = <1>; - clock-mult = <12>; + clock-frequency = <0>; + clock-output-names = "gp_clkin"; }; }; soc { + cgu: clock-controller at 40050000 { + compatible = "nxp,lpc1850-cgu"; + reg = <0x40050000 0x1000>; + #clock-cells = <1>; + clocks = <&xtal>, <&xtal32>, <&enet_rx_clk>, <&enet_tx_clk>, <&gp_clkin>; + }; + + ccu1: clock-controller at 40051000 { + compatible = "nxp,lpc1850-ccu"; + reg = <0x40051000 0x1000>; + #clock-cells = <1>; + clocks = <&cgu BASE_APB3_CLK>, <&cgu BASE_APB1_CLK>, + <&cgu BASE_SPIFI_CLK>, <&cgu BASE_CPU_CLK>, + <&cgu BASE_PERIPH_CLK>, <&cgu BASE_USB0_CLK>, + <&cgu BASE_USB1_CLK>, <&cgu BASE_SPI_CLK>; + }; + + ccu2: clock-controller at 40052000 { + compatible = "nxp,lpc1850-ccu"; + reg = <0x40052000 0x1000>; + #clock-cells = <1>; + clocks = <&cgu BASE_AUDIO_CLK>, <&cgu BASE_UART3_CLK>, + <&cgu BASE_UART2_CLK>, <&cgu BASE_UART1_CLK>, + <&cgu BASE_UART0_CLK>, <&cgu BASE_SSP1_CLK>, + <&cgu BASE_SSP0_CLK>, <&cgu BASE_SDIO_CLK>; + }; + uart0: serial at 40081000 { compatible = "ns16550a"; reg = <0x40081000 0x1000>; reg-shift = <2>; interrupts = <24>; - clocks = <&pll1>; + clocks = <&ccu2 CLK_APB0_UART0>, <&ccu1 CLK_CPU_UART0>; status = "disabled"; };
@@ -57,7 +106,7 @@ reg = <0x40082000 0x1000>; reg-shift = <2>; interrupts = <25>; - clocks = <&pll1>; + clocks = <&ccu2 CLK_APB0_UART1>, <&ccu1 CLK_CPU_UART1>; status = "disabled"; };
@@ -65,7 +114,7 @@ compatible = "nxp,lpc3220-timer"; reg = <0x40084000 0x1000>; interrupts = <12>; - clocks = <&pll1>; + clocks = <&ccu1 CLK_CPU_TIMER0>; clock-names = "timerclk"; };
@@ -73,7 +122,7 @@ compatible = "nxp,lpc3220-timer"; reg = <0x40085000 0x1000>; interrupts = <13>; - clocks = <&pll1>; + clocks = <&ccu1 CLK_CPU_TIMER1>; clock-names = "timerclk"; };
@@ -82,7 +131,7 @@ reg = <0x400c1000 0x1000>; reg-shift = <2>; interrupts = <26>; - clocks = <&pll1>; + clocks = <&ccu2 CLK_APB2_UART2>, <&ccu1 CLK_CPU_UART2>; status = "disabled"; };
@@ -91,7 +140,7 @@ reg = <0x400c2000 0x1000>; reg-shift = <2>; interrupts = <27>; - clocks = <&pll1>; + clocks = <&ccu2 CLK_APB2_UART3>, <&ccu1 CLK_CPU_UART3>; status = "disabled"; };
@@ -99,7 +148,7 @@ compatible = "nxp,lpc3220-timer"; reg = <0x400c3000 0x1000>; interrupts = <14>; - clocks = <&pll1>; + clocks = <&ccu1 CLK_CPU_TIMER2>; clock-names = "timerclk"; };
@@ -107,7 +156,7 @@ compatible = "nxp,lpc3220-timer"; reg = <0x400c4000 0x1000>; interrupts = <15>; - clocks = <&pll1>; + clocks = <&ccu1 CLK_CPU_TIMER3>; clock-names = "timerclk"; }; };
arch/arm/boot/dts/lpc4350-hitex-eval.dts +0 -4
@@ -36,10 +36,6 @@ }; }; -&pll1 { - clock-mult = <15>; -}; - &uart0 { status = "okay"; };
Signature · 1 line
1.8.0
PATCH v3 4/6 clk: add lpc18xx ccu clk driver
In reply to Joachim EastwoodHi Joachim,
Quoting Joachim Eastwood (2015-05-18 15:35:57)
<snip>
Quoted 52 lines
drivers/clk/nxp/clk-lpc18xx-ccu.c new file +52
-0+static void lpc18xx_ccu_register_branch_clks (void __iomem *reg_base, +int base_clk_id, +const char *parent) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (clk_branches); i++) { +if (clk_branches[i].base_id != base_clk_id) +continue ; + +lpc18xx_ccu_register_branch_gate_div (&clk_branches[i], reg_base, + parent); + +if (clk_branches[i].flags &CCU_BRANCH_IS_BUS ) + parent = clk_branches[i].name; + } +} + +static void __init lpc18xx_ccu_init (struct device_node *np) +{ +struct lpc18xx_branch_clk_data *clk_data; +int num_base_ids, *base_ids; +void __iomem *reg_base; +const char *parent; +int base_clk_id; +int i; + + reg_base =of_iomap (np,0 ); +if (!reg_base) { +pr_warn ("%s: failed to map address range\n" , __func__); +return ; + } + + clk_data =kzalloc (sizeof (*clk_data),GFP_KERNEL ); +if (!clk_data) +return ; + + num_base_ids =of_clk_get_parent_count (np); + + base_ids =kcalloc (num_base_ids,sizeof (int ),GFP_KERNEL ); +if (!base_ids) { +kfree (clk_data); +return ; + } + + clk_data->base_ids = base_ids; + clk_data->num_base_ids = num_base_ids; + +for (i =0 ; i < num_base_ids; i++) { +struct clk *clk =of_clk_get (np, i); +if (IS_ERR (clk)) { + pr_warn("%s: failed to get clock at idx %d\n",
drivers/clk/nxp/clk-lpc18xx-ccu.c line 300
Quoted 10 lines
drivers/clk/nxp/clk-lpc18xx-ccu.c new file +10
-0+ __func__, i); +continue ; + } + + parent =__clk_get_name (clk); + base_clk_id =of_clk_get_index (np, i); + + clk_data->base_ids[i] = base_clk_id; +lpc18xx_ccu_register_branch_clks (reg_base, base_clk_id, + parent);
Thanks for sending V3. This driver is getting close!
So the main thing I don't understand is why you do not encode the CGU clock parent string names into this CCU driver. If I understand your approach correctly, you do the following in lpc18xx_ccu_init:
1) count the number of parent clocks (ostensibly CGU clocks)
2) iterate through all of those CGU clocks, extracting a base_id value (loop #1)
3) using this base_id as a key you walk through an array in the CCU driver trying to find a matching base_id value
(loop #2)
4) after finding the corresponding CCU clocks you get the parent clock with of_clk_get
5) using of_clk_get you fetch its name with __clk_get_name
6) you pass this parent name into a fairly typical looking registration function
Assuming I got all of that right, I hope we can simplify it considerably.
You already have an array of CCU clock information in this driver, clk_branches[]. Why not encode the parent string name here? This would involve adding a "parent_name" member to struct lpc18xx_clk_branch.
Doing the above, your O(n^2)-ish registration function becomes O(n):
1) iterate through the array of the CCU clocks (clk_branchs[])
2) register them
3) profit
I'm starting to think any reference to base_id is sign that things are wrong in your driver. I am unconvinced that you need to "share" this base_id across CGU and CCU drivers in the way you do. If I'm wrong please help me to understand.
As a wild thought, if you do not want to encode parent string names into this driver, have you tried to use the clock-names property in the CCU blob? You do not need clock-output-names in the CGU blob either. But this is just an idea. It is far for straightforward for you t encode the parent names in your clk_branches[] array.
Thanks,
Mike
PATCH v3 5/6 doc: dt: add documentation for lpc1850-ccu clk driver
In reply to Joachim EastwoodQuoting Joachim Eastwood (2015-05-18 15:35:58)
Quoted 37 lines
Add DT binding documentation for lpc1850-ccu clk driver.
Signed-off-by Joachim Eastwood <[email protected]>--- .../devicetree/bindings/clock/lpc1850-ccu.txt | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-ccu.txtDocumentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +23
-0@@ -0,0 +1,146 @@ +* NXP LPC1850 Clock Control Unit (CCU) + +Each CGU base clock has several clock branches which can be turned on +or off independently by the Clock Control Units CCU1 or CCU2. The +branch clocks are distributed between CCU1 and CCU2. + + - Above text taken from NXP LPC1850 User Manual. + +This binding uses the common clock binding: + Documentation/devicetree/bindings/clock/clock-bindings.txt + +Required properties: +- compatible: + Should be "nxp,lpc1850-ccu" +- reg: + Shall define the base and range of the address space + containing clock control registers +- #clock-cells: + Shall have value <1>. The permitted clock-specifier values + are the branch clock names defined in table below. +- clocks: + Shall contain a list of phandles for the base clocks routed + from the CGU to the specific CCU. See mapping of base clocks
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt line 33
Quoted 10 lines
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +10
-0+ and CCU in table below. + +Which brach clocks that are available on the CCU depends on the +specific LPC part. + +CCU1 branch clocks: +Base clock Branch clock Description +BASE_APB3_CLK CLK_APB3_BUS APB3 bus clock. + CLK_APB3_I2C1 Clock to the I2C1 register interface + and I2C1 peripheral clock.
You don't need to make these explicit here. Just specify that the header containing these constants is located at nclude/dt-bindings/clock/lpc18xx-ccu.h
(DT people please correct me if this is bad etiquette)
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt line 110
Quoted 3 lines
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +3
-0+ +Not all branch clocks are available on all LPC parts. Check the user +manual for your specific part.
How many varieties of LPC part are there? Should these varieties each have their own .dtsi that make it clear which branch clocks are available on that part?
Regards,
Mike
Quoted 39 lines
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +36
-0+ +Note that CLK_M3_x and CLK_M4_x have been renamed to CLK_CPU_x here +be more generic since both LPC18xx (M3) and LPC43xx (M4) are +supported. + + +Example board file: + +soc { + ccu1: clock-controller at 40051000 { + compatible = "nxp,lpc1850-ccu"; + reg = <0x40051000 0x1000>; + #clock-cells = <1>; + clocks = <&cgu BASE_APB3_CLK>, <&cgu BASE_APB1_CLK>, + <&cgu BASE_SPIFI_CLK>, <&cgu BASE_CPU_CLK>, + <&cgu BASE_PERIPH_CLK>, <&cgu BASE_USB0_CLK>, + <&cgu BASE_USB1_CLK>, <&cgu BASE_SPI_CLK>; + }; + + ccu2: clock-controller at 40052000 { + compatible = "nxp,lpc1850-ccu"; + reg = <0x40052000 0x1000>; + #clock-cells = <1>; + clocks = <&cgu BASE_AUDIO_CLK>, <&cgu BASE_UART3_CLK>, + <&cgu BASE_UART2_CLK>, <&cgu BASE_UART1_CLK>, + <&cgu BASE_UART0_CLK>, <&cgu BASE_SSP1_CLK>, + <&cgu BASE_SSP0_CLK>, <&cgu BASE_SDIO_CLK>; + }; + + /* A user of CCU brach clocks */ + uart1: serial at 40082000 { + ... + clocks = <&ccu2 CLK_APB0_UART1>, <&ccu1 CLK_CPU_UART1>; + ... + }; +};Signature · 1 line
1.8.0
PATCH v3 4/6 clk: add lpc18xx ccu clk driver
In reply to Michael TurquetteQuoting Michael Turquette (2015-05-27 20:44:24)
Quoted 69 lines
Hi Joachim,
Quoting Joachim Eastwood (2015-05-18 15:35:57)
<snip>Quoted 52 lines
drivers/clk/nxp/clk-lpc18xx-ccu.c new file +52
-0+static void lpc18xx_ccu_register_branch_clks (void __iomem *reg_base, +int base_clk_id, +const char *parent) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (clk_branches); i++) { +if (clk_branches[i].base_id != base_clk_id) +continue ; + +lpc18xx_ccu_register_branch_gate_div (&clk_branches[i], reg_base, + parent); + +if (clk_branches[i].flags &CCU_BRANCH_IS_BUS ) + parent = clk_branches[i].name; + } +} + +static void __init lpc18xx_ccu_init (struct device_node *np) +{ +struct lpc18xx_branch_clk_data *clk_data; +int num_base_ids, *base_ids; +void __iomem *reg_base; +const char *parent; +int base_clk_id; +int i; + + reg_base =of_iomap (np,0 ); +if (!reg_base) { +pr_warn ("%s: failed to map address range\n" , __func__); +return ; + } + + clk_data =kzalloc (sizeof (*clk_data),GFP_KERNEL ); +if (!clk_data) +return ; + + num_base_ids =of_clk_get_parent_count (np); + + base_ids =kcalloc (num_base_ids,sizeof (int ),GFP_KERNEL ); +if (!base_ids) { +kfree (clk_data); +return ; + } + + clk_data->base_ids = base_ids; + clk_data->num_base_ids = num_base_ids; + +for (i =0 ; i < num_base_ids; i++) { +struct clk *clk =of_clk_get (np, i); +if (IS_ERR (clk)) { + pr_warn("%s: failed to get clock at idx %d\n",drivers/clk/nxp/clk-lpc18xx-ccu.c line 300
Quoted 10 lines
drivers/clk/nxp/clk-lpc18xx-ccu.c new file +10
-0+ __func__, i); +continue ; + } + + parent =__clk_get_name (clk); + base_clk_id =of_clk_get_index (np, i); + + clk_data->base_ids[i] = base_clk_id; +lpc18xx_ccu_register_branch_clks (reg_base, base_clk_id, + parent);Thanks for sending V3. This driver is getting close!
Quoted 3 lines
So the main thing I don't understand is why you do not encode the CGU clock parent string names into this CCU driver. If I understand your approach correctly, you do the following in
lpc18xx_ccu_init:
Ugh, I just saw that you mentioned this approach in your cover letter. No need for you to answer all of my questions then.
Please make the change to encode the parent string names directly. V4 should be good to go after that.
Thanks,
Mike
Quoted 39 lines
1) count the number of parent clocks (ostensibly CGU clocks)
2) iterate through all of those CGU clocks, extracting abase_idvalue (loop #1)
3) using thisbase_idas a key you walk through an array in the CCU driver trying to find a matchingbase_idvalue
(loop #2)
4) after finding the corresponding CCU clocks you get the parent clock withof_clk_get
5) usingof_clk_getyou fetch its name with__clk_get_name
6) you pass this parent name into a fairly typical looking registration functionAssuming I got all of that right, I hope we can simplify it considerably.
You already have an array of CCU clock information in this driver, clk_branches[]. Why not encode the parent string name here? This would involve adding a "
parent_name" member to structlpc18xx_clk_branch.Doing the above, your O(n^2)-ish registration function becomes O(n):
1) iterate through the array of the CCU clocks (clk_branchs[])
2) register them
3) profitI'm starting to think any reference to
base_idis sign that things are wrong in your driver. I am unconvinced that you need to "share" thisbase_idacross CGU and CCU drivers in the way you do. If I'm wrong please help me to understand.As a wild thought, if you do not want to encode parent string names into this driver, have you tried to use the clock-names property in the CCU blob? You do not need clock-output-names in the CGU blob either. But this is just an idea. It is far for straightforward for you t encode the parent names in your clk_branches[] array.
Thanks,
Mike
PATCH v3 5/6 doc: dt: add documentation for lpc1850-ccu clk driver
In reply to Michael TurquetteQuoted 53 lines · Michael Turquette
Quoting Joachim Eastwood (2015-05-18 15:35:58)
Quoted 37 lines
Add DT binding documentation for lpc1850-ccu clk driver.
Signed-off-by Joachim Eastwood <[email protected]>--- .../devicetree/bindings/clock/lpc1850-ccu.txt | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/lpc1850-ccu.txtDocumentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +23
-0@@ -0,0 +1,146 @@ +* NXP LPC1850 Clock Control Unit (CCU) + +Each CGU base clock has several clock branches which can be turned on +or off independently by the Clock Control Units CCU1 or CCU2. The +branch clocks are distributed between CCU1 and CCU2. + + - Above text taken from NXP LPC1850 User Manual. + +This binding uses the common clock binding: + Documentation/devicetree/bindings/clock/clock-bindings.txt + +Required properties: +- compatible: + Should be "nxp,lpc1850-ccu" +- reg: + Shall define the base and range of the address space + containing clock control registers +- #clock-cells: + Shall have value <1>. The permitted clock-specifier values + are the branch clock names defined in table below. +- clocks: + Shall contain a list of phandles for the base clocks routed + from the CGU to the specific CCU. See mapping of base clocksDocumentation/devicetree/bindings/clock/lpc1850-ccu.txt line 33
Quoted 10 lines
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +10
-0+ and CCU in table below. + +Which brach clocks that are available on the CCU depends on the +specific LPC part. + +CCU1 branch clocks: +Base clock Branch clock Description +BASE_APB3_CLK CLK_APB3_BUS APB3 bus clock. + CLK_APB3_I2C1 Clock to the I2C1 register interface + and I2C1 peripheral clock.You don't need to make these explicit here. Just specify that the header containing these constants is located at
nclude/dt-bindings/clock/lpc18xx-ccu.h
Quoted 1 line
(DT people please correct me if this is bad etiquette)
Okey, I'll ditch it for v4 unless someone yells out.
Quoted 5 lines
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt line 110
Quoted 3 lines
Documentation/devicetree/bindings/clock/lpc1850-ccu.txt new file +3
-0+ +Not all branch clocks are available on all LPC parts. Check the user +manual for your specific part.How many varieties of LPC part are there?
Being a micro controller there are a lot of parts with small variations in peripherals and Flash sizes.
For the clock stuff; the LPC43xx series added 3 base clocks to the CCU over the LPC18xx series. One of these clocks is only present on the LPC4370.
So for the CGU base clocks there aren't a whole lot of variants I guess.
Quoted 2 lines
Should these varieties each have their own .dtsi that make it clear which branch clocks are available on that part?
Good question.
For now my approach have been to stick everything in one common file (lpc18xx.dtsi), but this can be changed of course. Right now I think we should just wait and see which parts that are added to mainline and then split things as required.
regards,
Joachim Eastwood
PATCH v3 4/6 clk: add lpc18xx ccu clk driver
In reply to Michael TurquetteHi Michael,
Quoted 1 line · Michael Turquette
Thanks for sending V3. This driver is getting close!
Thanks for your patience.
Quoted 23 lines
So the main thing I don't understand is why you do not encode the CGU clock parent string names into this CCU driver. If I understand your approach correctly, you do the following in
lpc18xx_ccu_init:1) count the number of parent clocks (ostensibly CGU clocks)
2) iterate through all of those CGU clocks, extracting abase_idvalue (loop #1)
3) using thisbase_idas a key you walk through an array in the CCU driver trying to find a matchingbase_idvalue
(loop #2)
4) after finding the corresponding CCU clocks you get the parent clock withof_clk_get
5) usingof_clk_getyou fetch its name with__clk_get_name
6) you pass this parent name into a fairly typical looking registration functionAssuming I got all of that right, I hope we can simplify it considerably.
You already have an array of CCU clock information in this driver, clk_branches[]. Why not encode the parent string name here? This would involve adding a "
parent_name" member to structlpc18xx_clk_branch.
Quoted 5 lines
Doing the above, your O(n^2)-ish registration function becomes O(n):
1) iterate through the array of the CCU clocks (clk_branchs[])
2) register them
3) profit
Since there are two instances of the CCU IP block and the clk_branchs[] table contain branch clocks from both of them the driver needs to know on which CCU instance the clocks belong.
So just registering all clocks in clk_branchs[] we would end up with all the clocks on both CCU nodes and some clock ids would conflict.
An alternative approach could be to split the clk_branchs[]. Each one with branch clocks for the respective CCU. But the driver would still need to know which of the tables to register. This could be done either by using two DT compac strings; like "nxp,lpc1850-ccu1" and "...-ccu2" or by having a 'id' propery in DT. I don't find these two approaches very appealing.
So the reason for some of the complexity in the driver is to keep it generic and work on multiple CCU instances by looking at the connected clocks.
I hope this make it more understandable. Sorry for failing to describe the hardware properly.
Either way I'll send out a v4 with parent clocks in the clk_branchs[] and which use a clock-names property to match the clocks between the CCU. Let me know what you think when you get a chance to look at it.
Quoted 4 lines
I'm starting to think any reference to
base_idis sign that things are wrong in your driver. I am unconvinced that you need to "share" thisbase_idacross CGU and CCU drivers in the way you do. If I'm wrong please help me to understand.
I don't mind putting the parent clock names in the clk_branches[] but the driver still needs to distinguish between the CCUs in the system and register the correct clocks on them.
If you have a another good way of doing so I am all ears.
I have put up the full DT in the link if you would like to take a look.
http://slexy.org/raw/s21h9lCxQa
You may also find the data sheet at the link below. There is a figure of the CGU and both CCUs at page 161, Figure 34.
http://www.nxp.com/documents/user_manual/UM10503.pdf
regards,
Joachim Eastwood