clk: fixed-rate: Don't open code kstrdup()
Subsystems (2)
PATCH 1/4 clk: fixed-rate: Don't open code kstrdup()
Save a little code by using the library function.
--- drivers/clk/clk-fixed-rate.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
drivers/clk/clk-fixed-rate.c +1 -6
@@ -45,7 +45,6 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, {struct clk_fixed_rate *fixed;char **parent_names =NULL ; -u8 len; fixed =kzalloc (sizeof (struct clk_fixed_rate ),GFP_KERNEL );
@@ -63,14 +62,10 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name,if (! parent_names) goto out; - len =sizeof (char ) *strlen (parent_name); - - parent_names[0 ] =kmalloc (len,GFP_KERNEL ); + parent_names[0 ] =kstrdup (parent_name,GFP_KERNEL );if (!parent_names[0 ]) goto out; - -strncpy (parent_names[0 ], parent_name, len); } out:
Signature · 1 line
1.7.9.1
PATCH 2/4 clk: Constify parent name arrays
Drivers should be able to declare their arrays of parent names as const so the APIs need to accept const arguments.
--- drivers/clk/clk-fixed-rate.c | 2 +- drivers/clk/clk-mux.c | 2 +- drivers/clk/clk.c | 2 +- include/linux/clk-private.h | 2 +- include/linux/clk-provider.h | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-)
drivers/clk/clk-fixed-rate.c +1 -1
@@ -44,7 +44,7 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, unsigned long fixed_rate) {struct clk_fixed_rate *fixed; -char **parent_names =NULL ; +const char **parent_names =NULL ; fixed =kzalloc (sizeof (struct clk_fixed_rate ),GFP_KERNEL );
drivers/clk/clk-mux.c +1 -1
@@ -91,7 +91,7 @@ struct clk_ops clk_mux_ops = {EXPORT_SYMBOL_GPL (clk_mux_ops);struct clk *clk_register_mux (struct device *dev,const char *name, -char **parent_names,u8 num_parents,unsigned long flags, +const char **parent_names,u8 num_parents,unsigned long flags,void __iomem *reg,u8 shift,u8 width,u8 clk_mux_flags,spinlock_t *lock) {
drivers/clk/clk.c +1 -1
@@ -1322,7 +1322,7 @@ out:*/ struct clk *clk_register (struct device *dev,const char *name,const struct clk_ops *ops,struct clk_hw *hw, -char **parent_names,u8 num_parents,unsigned long flags) +const char **parent_names,u8 num_parents,unsigned long flags) {struct clk *clk;
include/linux/clk-private.h +1 -1
@@ -30,7 +30,7 @@ struct clk {const struct clk_ops *ops;struct clk_hw *hw;struct clk *parent; -char **parent_names; +const char **parent_names;struct clk **parents;u8 num_parents;unsigned long rate;
include/linux/clk-provider.h +3 -3
@@ -212,7 +212,7 @@ struct clk_divider {u8 width;u8 flags;spinlock_t *lock; -char *parent[1 ]; +const char *parent[1 ]; };#define CLK_DIVIDER_ONE_BASED BIT(0)
@@ -253,7 +253,7 @@ struct clk_mux {#define CLK_MUX_INDEX_BIT BIT(1)struct clk *clk_register_mux (struct device *dev,const char *name, -char **parent_names,u8 num_parents,unsigned long flags, +const char **parent_names,u8 num_parents,unsigned long flags,void __iomem *reg,u8 shift,u8 width,u8 clk_mux_flags,spinlock_t *lock);
@@ -274,7 +274,7 @@ struct clk *clk_register_mux(struct device *dev, const char *name,*/ struct clk *clk_register (struct device *dev,const char *name,const struct clk_ops *ops,struct clk_hw *hw, -char **parent_names,u8 num_parents,unsigned long flags); +const char **parent_names,u8 num_parents,unsigned long flags);/* helper functions */ const char *__clk_get_name (struct clk *clk);
Signature · 1 line
1.7.9.1
PATCH 3/4 clk: Provide dummy clk_unregister()
In reply to Mark BrownWhile there's no actual implementation behind it having the call to use in drivers makes them feel neater from a driver author point of view. An actual implementation can wait for someone who needs to use the function in a real system.
--- drivers/clk/clk.c | 12 ++++++++++++ include/linux/clk-provider.h | 1 + 2 files changed, 13 insertions(+), 0 deletions(-)
drivers/clk/clk.c +12 -0
@@ -1344,6 +1344,18 @@ struct clk *clk_register(struct device *dev, const char *name, }EXPORT_SYMBOL_GPL (clk_register); +/** +* clk_unregister - unregister a currently registered clock +* @clk: clock to unregister +* +* Currently unimplemented. +*/ +int clk_unregister (struct clk *clk) +{ +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (clk_unregister); +/*** clk rate change notifiers ***/ /**
include/linux/clk-provider.h +1 -0
@@ -275,6 +275,7 @@ struct clk *clk_register_mux(struct device *dev, const char *name,struct clk *clk_register (struct device *dev,const char *name,const struct clk_ops *ops,struct clk_hw *hw,const char **parent_names,u8 num_parents,unsigned long flags); +int clk_unregister (struct clk *clk);/* helper functions */ const char *__clk_get_name (struct clk *clk);
Signature · 1 line
1.7.9.1
PATCH 4/4 clk: wm831x: Add initial WM831x clock driver
In reply to Mark BrownThe WM831x and WM832x series of PMICs contain a flexible clocking subsystem intended to provide always on and system core clocks. It features:
- A 32.768kHz crystal oscillator which can optionally be used to pass through an externally generated clock.
- A FLL which can be clocked from either the 32.768kHz oscillator or the CLKIN pin.
- A CLKOUT pin which can bring out either the oscillator or the FLL output.
- The 32.768kHz clock can also optionally be brought out on the GPIO pins of the device.
This driver fully supports the 32.768kHz oscillator and CLKOUT. The FLL is supported only in AUTO mode, the full flexibility of the FLL cannot currently be used.
Due to a lack of access to systems where the core SoC has been converted to use the generic clock API this driver has been compile tested only.
--- MAINTAINERS | 1 + drivers/clk/Kconfig | 7 + drivers/clk/Makefile | 1 + drivers/clk/clk-wm831x.c | 412 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 421 insertions(+), 0 deletions(-) create mode 100644 drivers/clk/clk-wm831x.c
MAINTAINERS +1 -0
@@ -7475,6 +7475,7 @@ W: http://opensource.wolfsonmicro.com/content/linux-drivers-wolfson-devices S: Supported F: Documentation/hwmon/wm83?? F: arch/arm/mach-s3c64xx/mach-crag6410* +F: drivers/clk/clk-wm83*.c F: drivers/leds/leds-wm83*.c F: drivers/hwmon/wm83??-hwmon.c F: drivers/input/misc/wm831x-on.c
drivers/clk/Kconfig +7 -0
@@ -44,4 +44,11 @@ config COMMON_CLK_DEBUG clk_flags, clk_prepare_count, clk_enable_count & clk_notifier_count. +config COMMON_CLK_WM831X + tristate "Clock driver for WM831x/2x PMICs" + depends on MFD_WM831X + ---help--- + Supports the clocking subsystem of the WM831x/2x series of + PMICs from Wolfson Microlectronics. + endmenu
drivers/clk/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \ clk-mux.o clk-divider.o +obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o
drivers/clk/clk-wm831x.c new file +412 -0
412 lines not on this page · raw message
Signature · 1 line
1.7.9.1
Quoted 3 lines · Mark Brown
Save a little code by using the library function.
Signed-off-by Mark Brown <[email protected]>
Hi Mark,
Thanks for the patch. I've already solved this in my clk-fixes branch (working on it now, not yet on the list). I'm going to re-use the same approach for the fixed-rate clock as is used for the divider and gate; the registration functions for those types store the parent_name in the struct clk_foo and use kstrdup as your patch does below.
Thanks again,
Mike
Quoted 40 lines
---
?drivers/clk/clk-fixed-rate.c | ? ?7 +------
?1 files changed, 1 insertions(+), 6 deletions(-)drivers/clk/clk-fixed-rate.c +1
-6@@ -45,7 +45,6 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, ?{ ? ? ? ?struct clk_fixed_rate *fixed; ? ? ? ?char **parent_names = NULL; - ? ? ? u8 len; ? ? ? ?fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);@@ -63,14 +62,10 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, ? ? ? ? ? ? ? ?if (! parent_names) ? ? ? ? ? ? ? ? ? ? ? ?goto out; - ? ? ? ? ? ? ? len = sizeof(char) * strlen(parent_name); - - ? ? ? ? ? ? ? parent_names[0] = kmalloc(len, GFP_KERNEL); + ? ? ? ? ? ? ? parent_names[0] = kstrdup(parent_name, GFP_KERNEL); ? ? ? ? ? ? ? ?if (!parent_names[0]) ? ? ? ? ? ? ? ? ? ? ? ?goto out; - - ? ? ? ? ? ? ? strncpy(parent_names[0], parent_name, len); ? ? ? ?}?out:
--
1.7.9.1_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 3/4] clk: Provide dummy clk_unregister()
In reply to Mark BrownQuoted 4 lines · Mark Brown
While there's no actual implementation behind it having the call to use in drivers makes them feel neater from a driver author point of view. An actual implementation can wait for someone who needs to use the function in a real system.
Thanks for the patch Mark. I'll include this in my fixes branch.
Regards,
Mike
Quoted 49 lines
Signed-off-by Mark Brown <[email protected]>---
?drivers/clk/clk.c ? ? ? ? ? ?| ? 12 ++++++++++++ ?include/linux/clk-provider.h | ? ?1 +
?2 files changed, 13 insertions(+), 0 deletions(-)drivers/clk/clk.c +12
-0@@ -1344,6 +1344,18 @@ struct clk *clk_register(struct device *dev, const char *name, ?} ?EXPORT_SYMBOL_GPL(clk_register); +/** +* clk_unregister - unregister a currently registered clock +* @clk: clock to unregister +* +* Currently unimplemented. +*/ +int clk_unregister (struct clk *clk) +{ + ? ? ? return -EINVAL; +} +EXPORT_SYMBOL_GPL (clk_unregister); +?/*** ? ? ? ?clk rate change notifiers ? ? ? ?***/
?/**
include/linux/clk-provider.h +1
-0@@ -275,6 +275,7 @@ struct clk *clk_register_mux(struct device *dev, const char *name, ?struct clk *clk_register(struct device *dev, const char *name, ? ? ? ? ? ? ? ?const struct clk_ops *ops, struct clk_hw *hw, ? ? ? ? ? ? ? ?const char **parent_names, u8 num_parents, unsigned long flags); +int clk_unregister (struct clk *clk);?/* helper functions */
?const char *__clk_get_name(struct clk *clk);
--
1.7.9.1_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 4/4] clk: wm831x: Add initial WM831x clock driver
In reply to Mark BrownQuoted 22 lines · Mark Brown
The WM831x and WM832x series of PMICs contain a flexible clocking subsystem intended to provide always on and system core clocks. It features:
- A 32.768kHz crystal oscillator which can optionally be used to pass through an externally generated clock.
- A FLL which can be clocked from either the 32.768kHz oscillator or the CLKIN pin.
- A CLKOUT pin which can bring out either the oscillator or the FLL output.
- The 32.768kHz clock can also optionally be brought out on the GPIO pins of the device.This driver fully supports the 32.768kHz oscillator and CLKOUT. The FLL is supported only in AUTO mode, the full flexibility of the FLL cannot currently be used.
Due to a lack of access to systems where the core SoC has been converted to use the generic clock API this driver has been compile tested only.
Signed-off-by Mark Brown <[email protected]>---
[...]
drivers/clk/clk-wm831x.c line 287
Quoted 6 lines
drivers/clk/clk-wm831x.c new file +6
-0+ +static unsigned long wm831x_clkout_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +return parent_rate; +}
You should be able to drop this. The clock framework will use the parent rate automatically if recalc_rate is not present.
drivers/clk/clk-wm831x.c line 321
Quoted 9 lines
drivers/clk/clk-wm831x.c new file +9
-0+ +static int wm831x_clkout_set_parent (struct clk_hw *hw,u8 parent) +{ + struct wm831x_clk *clkdata = container_of(hw, struct wm831x_clk, + clkout_hw); +struct wm831x *wm831x = clkdata->wm831x; + +if (parent >ARRAY_SIZE (wm831x_clkout_parents)) +return -EINVAL ;
Unless you mistrust the clock framework isn't necessary. The framework checks this already.
Quoted 13 lines
drivers/clk/clk-wm831x.c new file +13
-0+ +static __devinit int wm831x_clk_probe (struct platform_device *pdev) +{ +struct wm831x *wm831x =dev_get_drvdata (pdev->dev.parent); +struct wm831x_clk *clkdata; +int ret; + + clkdata =devm_kzalloc (&pdev->dev,sizeof (*clkdata),GFP_KERNEL ); +if (!clkdata) +return -ENOMEM ; + +/* XTAL_ENA can only be set via OTP/InstantConfig so just read once */ + ret =wm831x_reg_read (wm831x,WM831X_CLOCK_CONTROL_2 );
drivers/clk/clk-wm831x.c line 358
Quoted 10 lines
drivers/clk/clk-wm831x.c new file +10
-0+if (ret <0 ) { +dev_err (wm831x->dev,"Unable to read CLOCK_CONTROL_2: %d\n" , + ret); +return ret; + } + clkdata->xtal_ena = ret &WM831X_XTAL_ENA ; + +if (!clk_register (&pdev->dev,"xtal" , &wm831x_xtal_ops, + &clkdata->xtal_hw,NULL ,0 ,CLK_IS_ROOT )) +return -EINVAL ;
The clock names are unique identifiers for the clock, so clocks in drivers should probably have dev_name encoded into them.
You could also use the fixed rate generic clock here.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH 4/4] clk: wm831x: Add initial WM831x clock driver
Quoted 8 lines · Sascha Hauer
drivers/clk/clk-wm831x.c line 358
Quoted 3 lines · Mark Brown
drivers/clk/clk-wm831x.c new file +3
-0+if (!clk_register (&pdev->dev,"xtal" , &wm831x_xtal_ops, + &clkdata->xtal_hw,NULL ,0 ,CLK_IS_ROOT )) +return -EINVAL ;The clock names are unique identifiers for the clock, so clocks in drivers should probably have
dev_nameencoded into them.
No, that's not sensible. We shouldn't be open coding this into each individual driver that provides clocks, and we shouldn't have clock users having to guess at what scheme the driver author used to dedupe the clocks. As a driver author you would assume that the reason we're providing the struct device to the registration function in the first place is so that the core has the information it needs to do that.
I did provide patches to do what you suggest in the core for one of the earlier versions of the API, I have to say I didn't check to see if they got dropped during the general lulls.
Quoted 1 line
You could also use the fixed rate generic clock here.
It doesn't really do what I want with reporting the enables - for
diagnostic purposes I wanted to always have the clock present but
non-enablable so we could actually look at the clock tree and see
what's going on directly when there's no clock coming out.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120322/c06289f3/attachment.sig>
Re: [PATCH 4/4] clk: wm831x: Add initial WM831x clock driver
Quoted 17 lines · Mark Brown
Quoted 8 lines · Sascha Hauer
drivers/clk/clk-wm831x.c line 358
Quoted 3 lines · Mark Brown
drivers/clk/clk-wm831x.c new file +3
-0+if (!clk_register (&pdev->dev,"xtal" , &wm831x_xtal_ops, + &clkdata->xtal_hw,NULL ,0 ,CLK_IS_ROOT )) +return -EINVAL ;The clock names are unique identifiers for the clock, so clocks in drivers should probably have
dev_nameencoded into them.No, that's not sensible. We shouldn't be open coding this into each individual driver that provides clocks, and we shouldn't have clock users having to guess at what scheme the driver author used to dedupe the clocks. As a driver author you would assume that the reason we're providing the struct device to the registration function in the first place is so that the core has the information it needs to do that.
Quoted 3 lines
I did provide patches to do what you suggest in the core for one of the earlier versions of the API, I have to say I didn't check to see if they got dropped during the general lulls.
It seems they got dropped. Currently the clock framework does nothing with the device argument. But right, it could use this argument to generate a suitable name.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH 4/4] clk: wm831x: Add initial WM831x clock driver
Quoted 10 lines · Sascha Hauer
Quoted 4 lines · Mark Brown
No, that's not sensible. We shouldn't be open coding this into each individual driver that provides clocks, and we shouldn't have clock users having to guess at what scheme the driver author used to dedupe the clocks. As a driver author you would assume that the reason we're
It seems they got dropped. Currently the clock framework does nothing with the device argument. But right, it could use this argument to generate a suitable name.
Indeed, and as with adding the stub clk_unregister() it seems like it's
better at this point to just code the drivers as we'd expect them to
work and fill out the framework to handle this rather than introducing
workarounds in the drivers.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120322/5d75411a/attachment.sig>
Re: [PATCH 4/4] clk: wm831x: Add initial WM831x clock driver
Quoted 8 lines · Mark Brown
Quoted 6 lines · Sascha Hauer
Quoted 4 lines · Mark Brown
No, that's not sensible. ?We shouldn't be open coding this into each individual driver that provides clocks, and we shouldn't have clock users having to guess at what scheme the driver author used to dedupe the clocks. ?As a driver author you would assume that the reason we're
Quoted 8 lines
Quoted 3 lines
It seems they got dropped. Currently the clock framework does nothing with the device argument. But right, it could use this argument to generate a suitable name.
Indeed, and as with adding the stub
clk_unregister()it seems like it's better at this point to just code the drivers as we'd expect them to work and fill out the framework to handle this rather than introducing workarounds in the drivers.
Agreed. I put this off some time back, but I figured the WM831X driver would bring the issue back up.
I'm happy for the core to concatenate the strings when a struct device *dev is passed in. However the reason I dropped this in the first place is that I have some ideas on providing something like clk_get directly from the common clk core and I hadn't figured out all of the details yet. For now we can handle the string concatenation in the core and figure out those tricky details if/when the time comes to provide a clk_get which is more closely linked to the clock framework implementation.
I'll roll in a patch for my fixes series.
Regards,
Mike
Re: [PATCH 4/4] clk: wm831x: Add initial WM831x clock driver
Quoted 8 lines · Mike
I'm happy for the core to concatenate the strings when a struct device *dev is passed in. However the reason I dropped this in the first place is that I have some ideas on providing something like
clk_getdirectly from the common clk core and I hadn't figured out all of the details yet. For now we can handle the string concatenation in the core and figure out those tricky details if/when the time comes to provide aclk_getwhich is more closely linked to the clock framework implementation.
Yeah, it's that sort of feature that most pushes against doing it in the
drivers - for example, the regulator API never ends up doing anything
like the concatenation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120322/cdebbec9/attachment.sig>