ACPI / LPSS: fractional divider clocks
Subsystems (2)
cover ACPI / LPSS: fractional divider clocks
Hi,
This serie is about getting support for the m over n fractional divisors that are available for SPI and UART in Intel LPSS. We will need support for it with the UART.
Fractional dividers appear to be quite common so I'm suggesting a new basic clk type for them in the first patch.
Heikki Krogerus (2):
clk: new basic clk type for fractional divider ACPI / LPSS: Support for fractional divider clock
drivers/acpi/acpi_lpss.c | 37 ++++++++-- drivers/clk/Makefile | 1 + drivers/clk/clk-fractional-divider.c | 132 +++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 31 ++++++++ 4 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 drivers/clk/clk-fractional-divider.c
Signature · 1 line
2.0.0.rc0
PATCH 1/2 clk: new basic clk type for fractional divider
Fractional divider clocks are fairly common. This adds basic type for them.
--- drivers/clk/Makefile | 1 + drivers/clk/clk-fractional-divider.c | 132 +++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 31 ++++++++ 3 files changed, 164 insertions(+) create mode 100644 drivers/clk/clk-fractional-divider.c
drivers/clk/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o obj-$(CONFIG_COMMON_CLK) += clk-gate.o obj-$(CONFIG_COMMON_CLK) += clk-mux.o obj-$(CONFIG_COMMON_CLK) += clk-composite.o +obj-$(CONFIG_COMMON_CLK) += clk-fractional-divider.o # hardware specific clock types # please keep this section sorted lexicographically by file/directory path name
drivers/clk/clk-fractional-divider.c new file +132 -0
132 lines not on this page · raw message
include/linux/clk-provider.h +31 -0
@@ -413,6 +413,37 @@ struct clk *clk_register_fixed_factor(struct device *dev, const char *name, const char *parent_name, unsigned long flags, unsigned int mult, unsigned int div); +/** +* struct clk_fractional_divider - adjustable fractional divider clock +* +* @hw: handle between common and hardware-specific interfaces +* @reg: register containing the divider +* @mshift: shift to the numerator bit field +* @mwidth: width of the numerator bit field +* @nshift: shift to the denominator bit field +* @nwidth: width of the denominator bit field +* @lock: register lock +* +* Clock with adjustable fractional divider affecting its output frequency. +*/ + +struct clk_fractional_divider { +struct clk_hw hw; +void __iomem *reg; +u8 mshift; +u32 mmask; +u8 nshift; +u32 nmask; +u8 flags; +spinlock_t *lock; +}; + +extern const struct clk_ops clk_fractional_divider_ops; +struct clk *clk_register_fractional_divider (struct device *dev, +const char *name,const char *parent_name,unsigned long flags, +void __iomem *reg,u8 mshift,u8 mwidth,u8 nshift,u8 nwidth, +u8 clk_divider_flags,spinlock_t *lock); +/*** * struct clk_composite - aggregate clock of mux, divider and gate clocks *
Signature · 1 line
2.0.0.rc0
PATCH 2/2 ACPI / LPSS: Support for fractional divider clock
In reply to Heikki KrogerusThe dividers are available for UART and SPI on both Lynxpoint and Baytrail. With SPI, handling the dividers is optional, but in case of UART they should be adjusted according to the requested baud rate.
--- drivers/acpi/acpi_lpss.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/acpi/acpi_lpss.c +30 -7
@@ -58,6 +58,7 @@ struct lpss_device_desc {unsigned int prv_offset;size_t prv_size_override;bool clk_gate; +bool clk_divider;struct lpss_shared_clock *shared_clock;void (*setup)(struct lpss_private_data *pdata); };
@@ -119,16 +120,11 @@ static struct lpss_device_desc byt_pwm_dev_desc = { .shared_clock = &pwm_clock, }; -static struct lpss_shared_clock uart_clock = { - .name ="uart_clk" , - .rate =44236800 , -}; -static struct lpss_device_desc byt_uart_dev_desc = { .clk_required = true, .prv_offset =0x800 , .clk_gate = true, - .shared_clock = &uart_clock, + .clk_divider = true, .setup = lpss_uart_setup, };
@@ -246,8 +242,35 @@ static int register_device_clock(struct acpi_device *adev, parent = shared_clock->name; } +if (dev_desc->clk_divider) { +char *name =kzalloc (strlen (dev_name (&adev->dev)) +8 , +GFP_KERNEL ); +if (!name) +return -ENOMEM ; +strcpy (name,"div_clk-" ); +strcat (name,dev_name (&adev->dev)); + + clk =clk_register_fractional_divider (NULL , name, parent,0 , + pdata->mmio_base + dev_desc->prv_offset, +1 ,15 ,16 ,15 ,0 ,NULL ); + parent = name; + + name =kzalloc (strlen (dev_name (&adev->dev)) +11 ,GFP_KERNEL ); +if (!name) +return -ENOMEM ; +strcpy (name,"clk_update-" ); +strcat (name,dev_name (&adev->dev)); + + clk =clk_register_gate (NULL , name, parent, +CLK_SET_RATE_PARENT |CLK_SET_RATE_GATE , + pdata->mmio_base + dev_desc->prv_offset, +31 ,0 ,NULL ); + parent = name; + } +if (dev_desc->clk_gate) { - clk =clk_register_gate (NULL ,dev_name (&adev->dev), parent,0 , + clk =clk_register_gate (NULL ,dev_name (&adev->dev), parent, +CLK_SET_RATE_PARENT , pdata->mmio_base + dev_desc->prv_offset,0 ,0 ,NULL ); pdata->clk = clk;
Signature · 1 line
2.0.0.rc0
Re: [PATCH 2/2] ACPI / LPSS: Support for fractional divider clock
Quoted 41 lines · Heikki Krogerus
The dividers are available for UART and SPI on both Lynxpoint and Baytrail. With SPI, handling the dividers is optional, but in case of UART they should be adjusted according to the requested baud rate.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/acpi/acpi_lpss.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)drivers/acpi/acpi_lpss.c +2
-6@@ -58,6 +58,7 @@ struct lpss_device_desc {unsigned int prv_offset;size_t prv_size_override;bool clk_gate; +bool clk_divider;struct lpss_shared_clock *shared_clock;void (*setup)(struct lpss_private_data *pdata); };@@ -119,16 +120,11 @@ static struct lpss_device_desc byt_pwm_dev_desc = { .shared_clock = &pwm_clock, }; -static struct lpss_shared_clock uart_clock = { - .name ="uart_clk" , - .rate =44236800 , -}; -static struct lpss_device_desc byt_uart_dev_desc = { .clk_required = true, .prv_offset =0x800 , .clk_gate = true, - .shared_clock = &uart_clock, + .clk_divider = true, .setup = lpss_uart_setup, };
drivers/acpi/acpi_lpss.c static int register_device_clock(struct acpi_device *adev, · line 251
Quoted 10 lines
drivers/acpi/acpi_lpss.c +7
-0@@ -246,8 +242,35 @@ static int register_device_clock(struct acpi_device *adev, parent = shared_clock->name; } +if (dev_desc->clk_divider) { +char *name =kzalloc (strlen (dev_name (&adev->dev)) +8 , +GFP_KERNEL ); +if (!name) +return -ENOMEM ; +strcpy (name,"div_clk-" ); +strcat (name,dev_name (&adev->dev));
Just kasprintf() instead of a few LOCs?
drivers/acpi/acpi_lpss.c static int register_device_clock(struct acpi_device *adev, · line 262
Quoted 11 lines
drivers/acpi/acpi_lpss.c +11
-0+ + clk =clk_register_fractional_divider (NULL , name, parent,0 , + pdata->mmio_base + dev_desc->prv_offset, +1 ,15 ,16 ,15 ,0 ,NULL ); + parent = name; + + name =kzalloc (strlen (dev_name (&adev->dev)) +11 ,GFP_KERNEL ); +if (!name) +return -ENOMEM ; +strcpy (name,"clk_update-" ); +strcat (name,dev_name (&adev->dev));
Ditto.
Quoted 15 lines
drivers/acpi/acpi_lpss.c +10
-1+ + clk =clk_register_gate (NULL , name, parent, +CLK_SET_RATE_PARENT |CLK_SET_RATE_GATE , + pdata->mmio_base + dev_desc->prv_offset, +31 ,0 ,NULL ); + parent = name; + } +if (dev_desc->clk_gate) { - clk =clk_register_gate (NULL ,dev_name (&adev->dev), parent,0 , + clk =clk_register_gate (NULL ,dev_name (&adev->dev), parent, +CLK_SET_RATE_PARENT , pdata->mmio_base + dev_desc->prv_offset,0 ,0 ,NULL ); pdata->clk = clk;
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH 2/2] ACPI / LPSS: Support for fractional divider clock
Quoted 1 line · Andy Shevchenko
Just
kasprintf()instead of a few LOCs?
Thanks Andy. I didn't even know about it :).
Signature · 1 line
heikki