* [PATCH 0/1] add devm_of_clk_get() and devm_of_clk_get_by_name() functions
@ 2015-09-30 7:46 Paul Osmialowski
2015-09-30 7:46 ` [PATCH v2] clk: " Paul Osmialowski
0 siblings, 1 reply; 3+ messages in thread
From: Paul Osmialowski @ 2015-09-30 7:46 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Russell King, linux-clk, linux-kernel
Cc: Paul Osmialowski
From: Paul Osmialowski <pawelo@king.net.pl>
While working on my pinctrl driver I've found lack of devres compatible
equivalent for of_clk_get() function. I'd like to use it for the following
(incomplete) piece of device tree configuration:
pinctrl: pinctrl {
compatible = "fsl,kinetis-pinctrl";
#address-cells = <1>;
#size-cells = <1>;
ranges;
port_a@40049000 {
compatible = "fsl,kinetis-pin-bank";
reg = <0x40049000 0x1000>;
clocks = <&sim SIM_CLK_SCGC5_PORTA>;
};
port_b@4004a000 {
compatible = "fsl,kinetis-pin-bank";
reg = <0x4004a000 0x1000>;
clocks = <&sim SIM_CLK_SCGC5_PORTB>;
};
...
};
In my pinconf-generic compatible fsl,kinetis-pinctrl driver, I'm iterating
over fsl,kinetis-pin-bank nodes using for_each_child_of_node(dev->of_node,
child) along with of_match_node() in order to grab resources (I/O base
address, clock gate).
Normally, I'd have to use of_clk_get() on each pin bank device_node and
then worry about proper resource release myself.
IMHO using devres infrastructure for this is far better. This patch adds
missing functions needed to do it that way.
Paul Osmialowski (1):
clk: add devm_of_clk_get() and devm_of_clk_get_by_name() functions
drivers/clk/clk-devres.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
include/linux/clk.h | 20 ++++++++++++++++++++
2 files changed, 66 insertions(+)
--
2.4.9
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v2] clk: add devm_of_clk_get() and devm_of_clk_get_by_name() functions 2015-09-30 7:46 [PATCH 0/1] add devm_of_clk_get() and devm_of_clk_get_by_name() functions Paul Osmialowski @ 2015-09-30 7:46 ` Paul Osmialowski 2015-09-30 9:13 ` kbuild test robot 0 siblings, 1 reply; 3+ messages in thread From: Paul Osmialowski @ 2015-09-30 7:46 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Russell King, linux-clk, linux-kernel Cc: Paul Osmialowski From: Paul Osmialowski <pawelo@king.net.pl> These two functions are added to ease management of clocks obtained from OF device nodes. They are particulary useful while iterating over DT subnodes using e.g. for_each_child_of_node(dev->of_node, child) in order do get resources (i.e. clocks) for subdevices defined by these DT subnodes. For example: some_device { compatible = "something" #address-cells = <1>; #size-cells = <1>; ranges; subdevice1: some_subdevice@some_address1 { reg = <0xsome_address1 0xsome_size> clocks = <&some_clock1> } subdevice2: some_subdevice@some_address2 { reg = <0xsome_address2 0xsome_size> clocks = <&some_clock2> } } Normally, I'd have to use of_clk_get() on each subdevice node and then worry about proper resource release myself. IMHO using devres infrastructure for this is far better. This patch adds missing functions needed to do it a better way. Signed-off-by: Paul Osmialowski <pawelo@king.net.pl> --- Documentation/driver-model/devres.txt | 2 ++ drivers/clk/clk-devres.c | 46 +++++++++++++++++++++++++++++++++++ include/linux/clk.h | 46 +++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 831a536..f3ad67a 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -235,6 +235,8 @@ certainly invest a bit more effort into libata core layer). CLOCK devm_clk_get() + devm_of_clk_get() + devm_of_clk_get_by_name() devm_clk_put() DMA diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index 8f57154..197075a 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -34,6 +34,52 @@ struct clk *devm_clk_get(struct device *dev, const char *id) } EXPORT_SYMBOL(devm_clk_get); +#ifdef CONFIG_OF + +struct clk *devm_of_clk_get(struct device *dev, struct device_node *np, + int index) +{ + struct clk **ptr, *clk; + + ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + clk = of_clk_get(np, index); + if (!IS_ERR(clk)) { + *ptr = clk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return clk; +} +EXPORT_SYMBOL(devm_of_clk_get); + +struct clk *devm_of_clk_get_by_name(struct device *dev, struct device_node *np, + const char *name) +{ + struct clk **ptr, *clk; + + ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + clk = of_clk_get_by_name(np, name); + if (!IS_ERR(clk)) { + *ptr = clk; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return clk; +} +EXPORT_SYMBOL(devm_of_clk_get_by_name); + +#endif /* CONFIG_OF */ + static int devm_clk_match(struct device *dev, void *res, void *data) { struct clk **c = res; diff --git a/include/linux/clk.h b/include/linux/clk.h index 0df4a51..8f31f9a 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -504,4 +504,50 @@ static inline struct clk *of_clk_get_by_name(struct device_node *np, } #endif +#if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) +/** + * devm_of_clk_get - obtain a managed reference to a clock producer + * from device tree node (by index). + * @dev: device for clock "consumer" + * @np: device tree node + * @index: clock consumer index (within the node) + * + * devm_of_clk_get should not be called from within interrupt context. + * + * The clock will automatically be freed when the device is unbound + * from the bus. + */ +struct clk *devm_of_clk_get(struct device *dev, struct device_node *np, + int index); + +/** + * devm_of_clk_get_by_name - obtain a managed reference to a clock producer + * from device tree node (by name). + * @dev: device for clock "consumer" + * @np: device tree node + * @name: clock consumer name (within the node) + * + * devm_of_clk_get_by_name should not be called from within interrupt context. + * + * The clock will automatically be freed when the device is unbound + * from the bus. + */ +struct clk *devm_of_clk_get_by_name(struct device *dev, struct device_node *np, + const char *name); + +#else +static inline struct clk *devm_of_clk_get(struct device *dev, + struct device_node *np, + int index) +{ + return ERR_PTR(-ENOENT); +} +static inline struct clk *devm_of_clk_get_by_name(struct device *dev, + struct device_node *np, + const char *name) +{ + return ERR_PTR(-ENOENT); +} +#endif + #endif -- 2.4.9 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] clk: add devm_of_clk_get() and devm_of_clk_get_by_name() functions 2015-09-30 7:46 ` [PATCH v2] clk: " Paul Osmialowski @ 2015-09-30 9:13 ` kbuild test robot 0 siblings, 0 replies; 3+ messages in thread From: kbuild test robot @ 2015-09-30 9:13 UTC (permalink / raw) To: Paul Osmialowski Cc: kbuild-all, Michael Turquette, Stephen Boyd, Russell King, linux-clk, linux-kernel, Paul Osmialowski [-- Attachment #1: Type: text/plain, Size: 2335 bytes --] Hi Paul, [auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore] config: arm-sa1100 (attached as .config) reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross git checkout 4b38631724b90dc5a717a4467cbf9377e3bf9af2 # save the attached .config to linux build tree make.cross ARCH=arm All error/warnings (new ones prefixed by >>): >> drivers/clk/clk-devres.c:39:13: error: redefinition of 'devm_of_clk_get' struct clk *devm_of_clk_get(struct device *dev, struct device_node *np, ^ In file included from drivers/clk/clk-devres.c:7:0: include/linux/clk.h:539:27: note: previous definition of 'devm_of_clk_get' was here static inline struct clk *devm_of_clk_get(struct device *dev, ^ >> drivers/clk/clk-devres.c:60:13: error: redefinition of 'devm_of_clk_get_by_name' struct clk *devm_of_clk_get_by_name(struct device *dev, struct device_node *np, ^ In file included from drivers/clk/clk-devres.c:7:0: include/linux/clk.h:545:27: note: previous definition of 'devm_of_clk_get_by_name' was here static inline struct clk *devm_of_clk_get_by_name(struct device *dev, ^ vim +/devm_of_clk_get +39 drivers/clk/clk-devres.c 33 return clk; 34 } 35 EXPORT_SYMBOL(devm_clk_get); 36 37 #ifdef CONFIG_OF 38 > 39 struct clk *devm_of_clk_get(struct device *dev, struct device_node *np, 40 int index) 41 { 42 struct clk **ptr, *clk; 43 44 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL); 45 if (!ptr) 46 return ERR_PTR(-ENOMEM); 47 48 clk = of_clk_get(np, index); 49 if (!IS_ERR(clk)) { 50 *ptr = clk; 51 devres_add(dev, ptr); 52 } else { 53 devres_free(ptr); 54 } 55 56 return clk; 57 } 58 EXPORT_SYMBOL(devm_of_clk_get); 59 > 60 struct clk *devm_of_clk_get_by_name(struct device *dev, struct device_node *np, 61 const char *name) 62 { 63 struct clk **ptr, *clk; --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation [-- Attachment #2: .config.gz --] [-- Type: application/octet-stream, Size: 21715 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-09-30 9:14 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-09-30 7:46 [PATCH 0/1] add devm_of_clk_get() and devm_of_clk_get_by_name() functions Paul Osmialowski 2015-09-30 7:46 ` [PATCH v2] clk: " Paul Osmialowski 2015-09-30 9:13 ` kbuild test robot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®