Message ID | 1374560679-14666-3-git-send-email-rnayak@ti.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Rajendra, On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: [..] > diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > index 12fa589..e5c804b 100644 > --- a/arch/arm/mach-omap2/omap_hwmod.c > +++ b/arch/arm/mach-omap2/omap_hwmod.c > @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) > return ret; > } > > +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, > + struct device_node *np, > + int *opt_clks_cnt) > +{ > + int i, clks_cnt; > + const char *clk_name; > + const char **opt_clk_names; > + > + clks_cnt = of_property_count_strings(np, "clock-names"); > + if (!clks_cnt) > + return NULL; > + > + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); > + if (!opt_clk_names) > + return NULL; > + > + for (i = 0; i < clks_cnt; i++) { > + of_property_read_string_index(np, "clock-names", i, &clk_name); > + if (!strcmp(clk_name, "fck")) Could we instead parse for names that are "optional,role_name" instead of assuming anything other than fck is optional clocks? > + continue; > + opt_clks_cnt++; > + opt_clk_names[i] = clk_name; > + } > + return opt_clk_names; > +} > + [...] -- Regards, Nishanth Menon
On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: > Hi Rajendra, > > On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: > [..] >> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >> index 12fa589..e5c804b 100644 >> --- a/arch/arm/mach-omap2/omap_hwmod.c >> +++ b/arch/arm/mach-omap2/omap_hwmod.c >> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >> return ret; >> } >> >> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >> + struct device_node *np, >> + int *opt_clks_cnt) >> +{ >> + int i, clks_cnt; >> + const char *clk_name; >> + const char **opt_clk_names; >> + >> + clks_cnt = of_property_count_strings(np, "clock-names"); >> + if (!clks_cnt) >> + return NULL; >> + >> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >> + if (!opt_clk_names) >> + return NULL; >> + >> + for (i = 0; i < clks_cnt; i++) { >> + of_property_read_string_index(np, "clock-names", i, &clk_name); >> + if (!strcmp(clk_name, "fck")) > > Could we instead parse for names that are "optional,role_name" instead > of assuming anything other than fck is optional clocks? you mean look for anything with optional,*? because the role names would change. > >> + continue; >> + opt_clks_cnt++; >> + opt_clk_names[i] = clk_name; >> + } >> + return opt_clk_names; >> +} >> + > [...] > -- > Regards, > Nishanth Menon >
On 08/14/2013 08:20 AM, Rajendra Nayak wrote: > On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >> Hi Rajendra, >> >> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >> [..] >>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>> index 12fa589..e5c804b 100644 >>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>> return ret; >>> } >>> >>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>> + struct device_node *np, >>> + int *opt_clks_cnt) >>> +{ >>> + int i, clks_cnt; >>> + const char *clk_name; >>> + const char **opt_clk_names; >>> + >>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>> + if (!clks_cnt) >>> + return NULL; >>> + >>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>> + if (!opt_clk_names) >>> + return NULL; >>> + >>> + for (i = 0; i < clks_cnt; i++) { >>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>> + if (!strcmp(clk_name, "fck")) >> >> Could we instead parse for names that are "optional,role_name" instead >> of assuming anything other than fck is optional clocks? > > you mean look for anything with optional,*? because the role names would change. > yes. the idea being, we now have a meaning to the clock name - there are two types of clocks here.. functional and optional, we *might* have facility to add interface clock(we dont know interface clock handling yet, but something in the future).. we might increase the support for number of functional clocks.. it might help to keep the format such that it is a "bit extendable". >> >>> + continue; >>> + opt_clks_cnt++; >>> + opt_clk_names[i] = clk_name; >>> + } >>> + return opt_clk_names; >>> +} >>> + >> [...] >> -- >> Regards, >> Nishanth Menon >> >
On Wednesday 14 August 2013 07:09 PM, Nishanth Menon wrote: > On 08/14/2013 08:20 AM, Rajendra Nayak wrote: >> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >>> Hi Rajendra, >>> >>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >>> [..] >>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>>> index 12fa589..e5c804b 100644 >>>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>>> return ret; >>>> } >>>> >>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>>> + struct device_node *np, >>>> + int *opt_clks_cnt) >>>> +{ >>>> + int i, clks_cnt; >>>> + const char *clk_name; >>>> + const char **opt_clk_names; >>>> + >>>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>>> + if (!clks_cnt) >>>> + return NULL; >>>> + >>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>>> + if (!opt_clk_names) >>>> + return NULL; >>>> + >>>> + for (i = 0; i < clks_cnt; i++) { >>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>>> + if (!strcmp(clk_name, "fck")) >>> >>> Could we instead parse for names that are "optional,role_name" instead >>> of assuming anything other than fck is optional clocks? >> >> you mean look for anything with optional,*? because the role names would change. >> > > yes. the idea being, we now have a meaning to the clock name - there are two types of clocks here.. functional and optional, we *might* have facility to add interface clock(we dont know interface clock handling yet, but something in the future).. we might increase the support for number of functional clocks.. it might help to keep the format such that it is a "bit extendable". right, makes sense, will update. > >>> >>>> + continue; >>>> + opt_clks_cnt++; >>>> + opt_clk_names[i] = clk_name; >>>> + } >>>> + return opt_clk_names; >>>> +} >>>> + >>> [...] >>> -- >>> Regards, >>> Nishanth Menon >>> >> > >
[Adding Mike Turquette and dt maintainers to Cc] On Tue, Jul 23, 2013 at 07:24:38AM +0100, Rajendra Nayak wrote: > With clocks for OMAP moving to DT, its now possible to pass all optional clock > data for each device from DT instead of having it in hwmod. > > Signed-off-by: Rajendra Nayak <rnayak@ti.com> > --- > arch/arm/mach-omap2/omap_hwmod.c | 66 ++++++++++++++++++++++++++++++++++++-- > 1 file changed, 64 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > index 12fa589..e5c804b 100644 > --- a/arch/arm/mach-omap2/omap_hwmod.c > +++ b/arch/arm/mach-omap2/omap_hwmod.c > @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) > return ret; > } > > +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, > + struct device_node *np, > + int *opt_clks_cnt) > +{ > + int i, clks_cnt; > + const char *clk_name; > + const char **opt_clk_names; > + > + clks_cnt = of_property_count_strings(np, "clock-names"); > + if (!clks_cnt) > + return NULL; > + > + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); > + if (!opt_clk_names) > + return NULL; > + > + for (i = 0; i < clks_cnt; i++) { > + of_property_read_string_index(np, "clock-names", i, &clk_name); > + if (!strcmp(clk_name, "fck")) > + continue; > + opt_clks_cnt++; > + opt_clk_names[i] = clk_name; > + } > + return opt_clk_names; > +} > + > +static int _init_opt_clks_dt(struct omap_hwmod *oh, struct device_node *np) > +{ > + struct clk *c; > + int i, opt_clks_cnt = 0; > + int ret = 0; > + const char **opt_clk_names; > + > + opt_clk_names = _parse_opt_clks_dt(oh, np, &opt_clks_cnt); > + if (!opt_clk_names) > + return -EINVAL; > + > + oh->opt_clks = kzalloc(sizeof(struct omap_hwmod_opt_clk *) > + * opt_clks_cnt, GFP_KERNEL); > + if (!oh->opt_clks) > + return -ENOMEM; > + > + oh->opt_clks_cnt = opt_clks_cnt; > + > + for (i = 0; i < oh->opt_clks_cnt; i++) { > + c = of_clk_get_by_name(np, opt_clk_names[i]); > + if (IS_ERR(c)) { > + pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n", > + oh->name, opt_clk_names[i]); > + ret = -EINVAL; > + } > + oh->opt_clks[i]._clk = c; > + oh->opt_clks[i].role = opt_clk_names[i]; > + oh->opt_clks_cnt++; > + clk_prepare(oh->opt_clks[i]._clk); > + } > + return ret; > +} I don't like this. clock-names is used to represent the names of clocks as inputs to the device. The driver must know the names of each and every one of the clock inputs it intends to use -- there's a finite number, and if it doesn't know about it it clearly has no idea how that clock's meant to be used. Consider a future revision of the hardware that has an additional clock input. Some new feature may require that clock, but your driver won't support that new feature, so you don't need it. Preparing that clock is a waste of power, and could cause issues if for some reason the clock was mutually exlcusive with another clock (so preparing it would make the hardware unusable). If the new revision *requires* that clock to provide the same interface otherwise, it's not backwards compatible and needs a new binding, and the driver needs to be extended to support it. Given that, preparing all the clocks you've been handed is a hack. Simply request by name the ones you know you need, and attempt to request the optional ones as necessary. Don't blindly go and prepare everything. Thanks, Mark.
[Adding Mike Turquette and dt maintainers] On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: > On 08/14/2013 08:20 AM, Rajendra Nayak wrote: > > On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: > >> Hi Rajendra, > >> > >> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: > >> [..] > >>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > >>> index 12fa589..e5c804b 100644 > >>> --- a/arch/arm/mach-omap2/omap_hwmod.c > >>> +++ b/arch/arm/mach-omap2/omap_hwmod.c > >>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) > >>> return ret; > >>> } > >>> > >>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, > >>> + struct device_node *np, > >>> + int *opt_clks_cnt) > >>> +{ > >>> + int i, clks_cnt; > >>> + const char *clk_name; > >>> + const char **opt_clk_names; > >>> + > >>> + clks_cnt = of_property_count_strings(np, "clock-names"); > >>> + if (!clks_cnt) > >>> + return NULL; > >>> + > >>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); > >>> + if (!opt_clk_names) > >>> + return NULL; > >>> + > >>> + for (i = 0; i < clks_cnt; i++) { > >>> + of_property_read_string_index(np, "clock-names", i, &clk_name); > >>> + if (!strcmp(clk_name, "fck")) > >> > >> Could we instead parse for names that are "optional,role_name" instead > >> of assuming anything other than fck is optional clocks? > > > > you mean look for anything with optional,*? because the role names would change. > > > > yes. the idea being, we now have a meaning to the clock name - there are > two types of clocks here.. functional and optional, we *might* have > facility to add interface clock(we dont know interface clock handling > yet, but something in the future).. we might increase the support for > number of functional clocks.. it might help to keep the format such that > it is a "bit extendable". I completely disagree. The only things that should appear in clock-names are the names of the clock inputs that appear in the manual for the device. The driver should know which ones are optional, as that's a fixed property of the IP and the way the driver uses it. You should not be embedding additional semantics in name properties. Thanks, Mark.
On Wednesday 14 August 2013 07:15 PM, Mark Rutland wrote: > [Adding Mike Turquette and dt maintainers to Cc] > > On Tue, Jul 23, 2013 at 07:24:38AM +0100, Rajendra Nayak wrote: >> With clocks for OMAP moving to DT, its now possible to pass all optional clock >> data for each device from DT instead of having it in hwmod. >> >> Signed-off-by: Rajendra Nayak <rnayak@ti.com> >> --- >> arch/arm/mach-omap2/omap_hwmod.c | 66 ++++++++++++++++++++++++++++++++++++-- >> 1 file changed, 64 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >> index 12fa589..e5c804b 100644 >> --- a/arch/arm/mach-omap2/omap_hwmod.c >> +++ b/arch/arm/mach-omap2/omap_hwmod.c >> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >> return ret; >> } >> >> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >> + struct device_node *np, >> + int *opt_clks_cnt) >> +{ >> + int i, clks_cnt; >> + const char *clk_name; >> + const char **opt_clk_names; >> + >> + clks_cnt = of_property_count_strings(np, "clock-names"); >> + if (!clks_cnt) >> + return NULL; >> + >> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >> + if (!opt_clk_names) >> + return NULL; >> + >> + for (i = 0; i < clks_cnt; i++) { >> + of_property_read_string_index(np, "clock-names", i, &clk_name); >> + if (!strcmp(clk_name, "fck")) >> + continue; >> + opt_clks_cnt++; >> + opt_clk_names[i] = clk_name; >> + } >> + return opt_clk_names; >> +} >> + >> +static int _init_opt_clks_dt(struct omap_hwmod *oh, struct device_node *np) >> +{ >> + struct clk *c; >> + int i, opt_clks_cnt = 0; >> + int ret = 0; >> + const char **opt_clk_names; >> + >> + opt_clk_names = _parse_opt_clks_dt(oh, np, &opt_clks_cnt); >> + if (!opt_clk_names) >> + return -EINVAL; >> + >> + oh->opt_clks = kzalloc(sizeof(struct omap_hwmod_opt_clk *) >> + * opt_clks_cnt, GFP_KERNEL); >> + if (!oh->opt_clks) >> + return -ENOMEM; >> + >> + oh->opt_clks_cnt = opt_clks_cnt; >> + >> + for (i = 0; i < oh->opt_clks_cnt; i++) { >> + c = of_clk_get_by_name(np, opt_clk_names[i]); >> + if (IS_ERR(c)) { >> + pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n", >> + oh->name, opt_clk_names[i]); >> + ret = -EINVAL; >> + } >> + oh->opt_clks[i]._clk = c; >> + oh->opt_clks[i].role = opt_clk_names[i]; >> + oh->opt_clks_cnt++; >> + clk_prepare(oh->opt_clks[i]._clk); >> + } >> + return ret; >> +} > > I don't like this. > > clock-names is used to represent the names of clocks as inputs to the > device. The driver must know the names of each and every one of the > clock inputs it intends to use -- there's a finite number, and if it > doesn't know about it it clearly has no idea how that clock's meant to > be used. > > Consider a future revision of the hardware that has an additional clock > input. Some new feature may require that clock, but your driver won't > support that new feature, so you don't need it. Preparing that clock is > a waste of power, and could cause issues if for some reason the clock > was mutually exlcusive with another clock (so preparing it would make > the hardware unusable). If the new revision *requires* that clock to > provide the same interface otherwise, it's not backwards compatible and > needs a new binding, and the driver needs to be extended to support it. > > Given that, preparing all the clocks you've been handed is a hack. Mark, this is a piece of platform code (hwmod framework for omap) which does a enable/reset/idle of all devices on the SoC early at boot to get rid of bootloader dependencies. This isn;t something used by the drivers when they enable the devices. I don't see any issue with 'waste of power'. The framework (unlike the driver) has no knowledge of what clocks are needed and hence does a enable all momentarily to reset and put the device in a known state. > Simply request by name the ones you know you need, and attempt to > request the optional ones as necessary. Don't blindly go and prepare > everything. > > Thanks, > Mark. >
On Wed, Aug 14, 2013 at 02:49:04PM +0100, Mark Rutland wrote: > [Adding Mike Turquette and dt maintainers] > > On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: > > yes. the idea being, we now have a meaning to the clock name - there are > > two types of clocks here.. functional and optional, we *might* have > > facility to add interface clock(we dont know interface clock handling > > yet, but something in the future).. we might increase the support for > > number of functional clocks.. it might help to keep the format such that > > it is a "bit extendable". > > I completely disagree. The only things that should appear in clock-names > are the names of the clock inputs that appear in the manual for the > device. The driver should know which ones are optional, as that's a > fixed property of the IP and the way the driver uses it. > > You should not be embedding additional semantics in name properties. Agreed. I've been on at people about this for years, and every time they go off and do something else, it ultimately ends up coming back to bite them. Clock names _are_ the clock input names as far as device drivers are concerned, and nothing else. If there are optional clocks, then the driver should be doing as Mark says - the driver should try to get them, and if it fails to get them then they're quite simply not provided by the platform. If there are optional clocks which the device driver does not know about (or even need to know about) then that too should not be a problem - the driver just doesn't have to touch them. If they're optional, but required for the device to function, then the driver should get them and control them as necessary.
On 08/14/2013 08:49 AM, Mark Rutland wrote: > [Adding Mike Turquette and dt maintainers] > > On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: >> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: >>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >>>> Hi Rajendra, >>>> >>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >>>> [..] >>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>>>> index 12fa589..e5c804b 100644 >>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>>>> return ret; >>>>> } >>>>> >>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>>>> + struct device_node *np, >>>>> + int *opt_clks_cnt) >>>>> +{ >>>>> + int i, clks_cnt; >>>>> + const char *clk_name; >>>>> + const char **opt_clk_names; >>>>> + >>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>>>> + if (!clks_cnt) >>>>> + return NULL; >>>>> + >>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>>>> + if (!opt_clk_names) >>>>> + return NULL; >>>>> + >>>>> + for (i = 0; i < clks_cnt; i++) { >>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>>>> + if (!strcmp(clk_name, "fck")) >>>> >>>> Could we instead parse for names that are "optional,role_name" instead >>>> of assuming anything other than fck is optional clocks? >>> >>> you mean look for anything with optional,*? because the role names would change. >>> >> >> yes. the idea being, we now have a meaning to the clock name - there are >> two types of clocks here.. functional and optional, we *might* have >> facility to add interface clock(we dont know interface clock handling >> yet, but something in the future).. we might increase the support for >> number of functional clocks.. it might help to keep the format such that >> it is a "bit extendable". > > I completely disagree. The only things that should appear in clock-names > are the names of the clock inputs that appear in the manual for the > device. The driver should know which ones are optional, as that's a > fixed property of the IP and the way the driver uses it. > > You should not be embedding additional semantics in name properties. we use an level of abstraction called omap_device and hwmod to allow devices to use a generic pm_runtime. drivers for specific blocks dont normally need to know about the clocks to deal with. This allows maximum reuse consider concept is generic enough. The traditional way of dealing with this has been to encode the *names* *inside* hwmod!!! which is obviously the wrong way to deal with with clock nodes in dts. This series moves away from that approach - which is good. Now, the question is: clocks-names = "....." is not sufficient to indicate a list of clocks of different functions 3 types of clocks may exist for OMAP h/w blocks: a) functional clock (1 usually, but we are starting to see multiple fclks). this drives the actual functionality b) optional clocks - additional clocks such as debounce clock etc. - there can be n such clocks c) interface clocks - this drives the register interface on the bus. - there can be n such clocks and additional headaches for interface - currently embedded inside hwmod. you could do: A) embedd in the sematics of the name clock-names="fck", "optional,role1", "optional,role2"; clocks= <&clk_a>, <&clk_x>, <&clk_y>; OR: B) embedd in the property name optional-clock-names="optional,role1", "optional,role2"; optional-clocks=<&clk_x>, <&clk_y>; functional-clock-names="fck"; functional-clocks=<&clk_a>; are you suggesting (b) here?
On Wed, Aug 14, 2013 at 02:54:57PM +0100, Rajendra Nayak wrote: > On Wednesday 14 August 2013 07:15 PM, Mark Rutland wrote: > > [Adding Mike Turquette and dt maintainers to Cc] > > > > On Tue, Jul 23, 2013 at 07:24:38AM +0100, Rajendra Nayak wrote: > >> With clocks for OMAP moving to DT, its now possible to pass all optional clock > >> data for each device from DT instead of having it in hwmod. > >> > >> Signed-off-by: Rajendra Nayak <rnayak@ti.com> > >> --- > >> arch/arm/mach-omap2/omap_hwmod.c | 66 ++++++++++++++++++++++++++++++++++++-- > >> 1 file changed, 64 insertions(+), 2 deletions(-) > >> > >> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > >> index 12fa589..e5c804b 100644 > >> --- a/arch/arm/mach-omap2/omap_hwmod.c > >> +++ b/arch/arm/mach-omap2/omap_hwmod.c > >> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) > >> return ret; > >> } > >> > >> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, > >> + struct device_node *np, > >> + int *opt_clks_cnt) > >> +{ > >> + int i, clks_cnt; > >> + const char *clk_name; > >> + const char **opt_clk_names; > >> + > >> + clks_cnt = of_property_count_strings(np, "clock-names"); > >> + if (!clks_cnt) > >> + return NULL; > >> + > >> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); > >> + if (!opt_clk_names) > >> + return NULL; > >> + > >> + for (i = 0; i < clks_cnt; i++) { > >> + of_property_read_string_index(np, "clock-names", i, &clk_name); > >> + if (!strcmp(clk_name, "fck")) > >> + continue; > >> + opt_clks_cnt++; > >> + opt_clk_names[i] = clk_name; > >> + } > >> + return opt_clk_names; > >> +} > >> + > >> +static int _init_opt_clks_dt(struct omap_hwmod *oh, struct device_node *np) > >> +{ > >> + struct clk *c; > >> + int i, opt_clks_cnt = 0; > >> + int ret = 0; > >> + const char **opt_clk_names; > >> + > >> + opt_clk_names = _parse_opt_clks_dt(oh, np, &opt_clks_cnt); > >> + if (!opt_clk_names) > >> + return -EINVAL; > >> + > >> + oh->opt_clks = kzalloc(sizeof(struct omap_hwmod_opt_clk *) > >> + * opt_clks_cnt, GFP_KERNEL); > >> + if (!oh->opt_clks) > >> + return -ENOMEM; > >> + > >> + oh->opt_clks_cnt = opt_clks_cnt; > >> + > >> + for (i = 0; i < oh->opt_clks_cnt; i++) { > >> + c = of_clk_get_by_name(np, opt_clk_names[i]); > >> + if (IS_ERR(c)) { > >> + pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n", > >> + oh->name, opt_clk_names[i]); > >> + ret = -EINVAL; > >> + } > >> + oh->opt_clks[i]._clk = c; > >> + oh->opt_clks[i].role = opt_clk_names[i]; > >> + oh->opt_clks_cnt++; > >> + clk_prepare(oh->opt_clks[i]._clk); > >> + } > >> + return ret; > >> +} > > > > I don't like this. > > > > clock-names is used to represent the names of clocks as inputs to the > > device. The driver must know the names of each and every one of the > > clock inputs it intends to use -- there's a finite number, and if it > > doesn't know about it it clearly has no idea how that clock's meant to > > be used. > > > > Consider a future revision of the hardware that has an additional clock > > input. Some new feature may require that clock, but your driver won't > > support that new feature, so you don't need it. Preparing that clock is > > a waste of power, and could cause issues if for some reason the clock > > was mutually exlcusive with another clock (so preparing it would make > > the hardware unusable). If the new revision *requires* that clock to > > provide the same interface otherwise, it's not backwards compatible and > > needs a new binding, and the driver needs to be extended to support it. > > > > Given that, preparing all the clocks you've been handed is a hack. > > Mark, this is a piece of platform code (hwmod framework for omap) which > does a enable/reset/idle of all devices on the SoC early at boot to get > rid of bootloader dependencies. This isn;t something used by the drivers > when they enable the devices. I don't see any issue with 'waste of power'. > The framework (unlike the driver) has no knowledge of what clocks are > needed and hence does a enable all momentarily to reset and put the device in a > known state. Ok, I'd misunderstood there. Apologies for the noise. Thanks, Mark.
On Wednesday 14 August 2013 07:28 PM, Nishanth Menon wrote: > On 08/14/2013 08:49 AM, Mark Rutland wrote: >> [Adding Mike Turquette and dt maintainers] >> >> On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: >>> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: >>>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >>>>> Hi Rajendra, >>>>> >>>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >>>>> [..] >>>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>>>>> index 12fa589..e5c804b 100644 >>>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>>>>> return ret; >>>>>> } >>>>>> >>>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>>>>> + struct device_node *np, >>>>>> + int *opt_clks_cnt) >>>>>> +{ >>>>>> + int i, clks_cnt; >>>>>> + const char *clk_name; >>>>>> + const char **opt_clk_names; >>>>>> + >>>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>>>>> + if (!clks_cnt) >>>>>> + return NULL; >>>>>> + >>>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>>>>> + if (!opt_clk_names) >>>>>> + return NULL; >>>>>> + >>>>>> + for (i = 0; i < clks_cnt; i++) { >>>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>>>>> + if (!strcmp(clk_name, "fck")) >>>>> >>>>> Could we instead parse for names that are "optional,role_name" instead >>>>> of assuming anything other than fck is optional clocks? >>>> >>>> you mean look for anything with optional,*? because the role names would change. >>>> >>> >>> yes. the idea being, we now have a meaning to the clock name - there are >>> two types of clocks here.. functional and optional, we *might* have >>> facility to add interface clock(we dont know interface clock handling >>> yet, but something in the future).. we might increase the support for >>> number of functional clocks.. it might help to keep the format such that >>> it is a "bit extendable". >> >> I completely disagree. The only things that should appear in clock-names >> are the names of the clock inputs that appear in the manual for the >> device. The driver should know which ones are optional, as that's a >> fixed property of the IP and the way the driver uses it. >> >> You should not be embedding additional semantics in name properties. > > we use an level of abstraction called omap_device and hwmod to allow devices to use a generic pm_runtime. drivers for specific blocks dont normally need to know about the clocks to deal with. This allows maximum reuse consider concept is generic enough. They do know about the optional clocks though and request and release them when needed. The need for hwmod to know about optional clocks (and enable all) arises from the fact that some of these devices need *some* optional clocks for a successful reset. And given hmwod has no knowledge about which optional ones (if at all) will be needed, it goes ahead and enables all before doing a reset. This is something done only at init time and *not* something thats done every time the device is enabled by the driver using pm_runtime. > > The traditional way of dealing with this has been to encode the *names* *inside* hwmod!!! which is obviously the wrong way to deal with with clock nodes in dts. > > This series moves away from that approach - which is good. Now, the question is: > > clocks-names = "....." is not sufficient to indicate a list of clocks of different functions > > 3 types of clocks may exist for OMAP h/w blocks: > a) functional clock (1 usually, but we are starting to see multiple fclks). this drives the actual functionality > b) optional clocks - additional clocks such as debounce clock etc. - there can be n such clocks > c) interface clocks - this drives the register interface on the bus. - there can be n such clocks and additional headaches for interface - currently embedded inside hwmod. > > you could do: > A) embedd in the sematics of the name > clock-names="fck", "optional,role1", "optional,role2"; > clocks= <&clk_a>, <&clk_x>, <&clk_y>; > OR: > B) embedd in the property name > optional-clock-names="optional,role1", "optional,role2"; > optional-clocks=<&clk_x>, <&clk_y>; > functional-clock-names="fck"; > functional-clocks=<&clk_a>; > > are you suggesting (b) here? >
On Wed, Aug 14, 2013 at 02:58:25PM +0100, Nishanth Menon wrote: > On 08/14/2013 08:49 AM, Mark Rutland wrote: > > [Adding Mike Turquette and dt maintainers] > > > > On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: > >> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: > >>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: > >>>> Hi Rajendra, > >>>> > >>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: > >>>> [..] > >>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > >>>>> index 12fa589..e5c804b 100644 > >>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c > >>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c > >>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) > >>>>> return ret; > >>>>> } > >>>>> > >>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, > >>>>> + struct device_node *np, > >>>>> + int *opt_clks_cnt) > >>>>> +{ > >>>>> + int i, clks_cnt; > >>>>> + const char *clk_name; > >>>>> + const char **opt_clk_names; > >>>>> + > >>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); > >>>>> + if (!clks_cnt) > >>>>> + return NULL; > >>>>> + > >>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); > >>>>> + if (!opt_clk_names) > >>>>> + return NULL; > >>>>> + > >>>>> + for (i = 0; i < clks_cnt; i++) { > >>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); > >>>>> + if (!strcmp(clk_name, "fck")) > >>>> > >>>> Could we instead parse for names that are "optional,role_name" instead > >>>> of assuming anything other than fck is optional clocks? > >>> > >>> you mean look for anything with optional,*? because the role names would change. > >>> > >> > >> yes. the idea being, we now have a meaning to the clock name - there are > >> two types of clocks here.. functional and optional, we *might* have > >> facility to add interface clock(we dont know interface clock handling > >> yet, but something in the future).. we might increase the support for > >> number of functional clocks.. it might help to keep the format such that > >> it is a "bit extendable". > > > > I completely disagree. The only things that should appear in clock-names > > are the names of the clock inputs that appear in the manual for the > > device. The driver should know which ones are optional, as that's a > > fixed property of the IP and the way the driver uses it. > > > > You should not be embedding additional semantics in name properties. > > we use an level of abstraction called omap_device and hwmod to allow > devices to use a generic pm_runtime. drivers for specific blocks dont > normally need to know about the clocks to deal with. This allows maximum > reuse consider concept is generic enough. > > The traditional way of dealing with this has been to encode the *names* > *inside* hwmod!!! which is obviously the wrong way to deal with with > clock nodes in dts. > > This series moves away from that approach - which is good. Now, the > question is: > > clocks-names = "....." is not sufficient to indicate a list of clocks > of different functions > > 3 types of clocks may exist for OMAP h/w blocks: > a) functional clock (1 usually, but we are starting to see multiple > fclks). this drives the actual functionality > b) optional clocks - additional clocks such as debounce clock etc. - > there can be n such clocks > c) interface clocks - this drives the register interface on the bus. - > there can be n such clocks and additional headaches for interface - > currently embedded inside hwmod. I don't see why these can't all be supported without embedding additional details in the clock-names property. When you say "there can be n such clocks", do you mean that different devices may have different numbers of clocks, or that a given device could have an arbitrary set? Surely the design of the IP imposes a maximum limit on the number of clocks a device may have? > > you could do: > A) embedd in the sematics of the name > clock-names="fck", "optional,role1", "optional,role2"; > clocks= <&clk_a>, <&clk_x>, <&clk_y>; > OR: Does the name of the clock itself not encode this? Surely "fclk" would be your functional clock, "dbncclk" or similar would be an (optional) debounce clock, "apbclk" would be an interface clock? Surely you must know their type by which input they are and how they are to be used? From the sounds of your other reply, the issue is that you're poking clocks for arbitrary devices, without knowing the semantics of those clocks, because you're doing it form outside the driver. I don't have a good solution to this, but your proposed solution is not one I'm happy with. > B) embedd in the property name > optional-clock-names="optional,role1", "optional,role2"; > optional-clocks=<&clk_x>, <&clk_y>; > functional-clock-names="fck"; > functional-clocks=<&clk_a>; > > are you suggesting (b) here? I'm suggesting neither. Thanks, Mark.
On Wednesday 14 August 2013 07:35 PM, Rajendra Nayak wrote: > On Wednesday 14 August 2013 07:28 PM, Nishanth Menon wrote: >> On 08/14/2013 08:49 AM, Mark Rutland wrote: >>> [Adding Mike Turquette and dt maintainers] >>> >>> On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: >>>> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: >>>>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >>>>>> Hi Rajendra, >>>>>> >>>>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >>>>>> [..] >>>>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>>>>>> index 12fa589..e5c804b 100644 >>>>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>>>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>>>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>>>>>> return ret; >>>>>>> } >>>>>>> >>>>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>>>>>> + struct device_node *np, >>>>>>> + int *opt_clks_cnt) >>>>>>> +{ >>>>>>> + int i, clks_cnt; >>>>>>> + const char *clk_name; >>>>>>> + const char **opt_clk_names; >>>>>>> + >>>>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>>>>>> + if (!clks_cnt) >>>>>>> + return NULL; >>>>>>> + >>>>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>>>>>> + if (!opt_clk_names) >>>>>>> + return NULL; >>>>>>> + >>>>>>> + for (i = 0; i < clks_cnt; i++) { >>>>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>>>>>> + if (!strcmp(clk_name, "fck")) >>>>>> >>>>>> Could we instead parse for names that are "optional,role_name" instead >>>>>> of assuming anything other than fck is optional clocks? >>>>> >>>>> you mean look for anything with optional,*? because the role names would change. >>>>> >>>> >>>> yes. the idea being, we now have a meaning to the clock name - there are >>>> two types of clocks here.. functional and optional, we *might* have >>>> facility to add interface clock(we dont know interface clock handling >>>> yet, but something in the future).. we might increase the support for >>>> number of functional clocks.. it might help to keep the format such that >>>> it is a "bit extendable". >>> >>> I completely disagree. The only things that should appear in clock-names >>> are the names of the clock inputs that appear in the manual for the >>> device. The driver should know which ones are optional, as that's a >>> fixed property of the IP and the way the driver uses it. >>> >>> You should not be embedding additional semantics in name properties. >> >> we use an level of abstraction called omap_device and hwmod to allow devices to use a generic pm_runtime. drivers for specific blocks dont normally need to know about the clocks to deal with. This allows maximum reuse consider concept is generic enough. > > They do know about the optional clocks though and request and release them when needed. The need for hwmod to know about optional clocks > (and enable all) arises from the fact that some of these devices need *some* optional clocks for a successful reset. > And given hmwod has no knowledge about which optional ones (if at all) will be needed, it goes ahead and enables all before doing a reset. > This is something done only at init time and *not* something thats done every time the device is enabled by the driver using pm_runtime. We do seem to have a flag 'HWMOD_CONTROL_OPT_CLKS_IN_RESET' which says which ones really need optional clocks to be controlled. I guess for the rest hwmod can even ignore optional clocks completely. > >> >> The traditional way of dealing with this has been to encode the *names* *inside* hwmod!!! which is obviously the wrong way to deal with with clock nodes in dts. >> >> This series moves away from that approach - which is good. Now, the question is: >> >> clocks-names = "....." is not sufficient to indicate a list of clocks of different functions >> >> 3 types of clocks may exist for OMAP h/w blocks: >> a) functional clock (1 usually, but we are starting to see multiple fclks). this drives the actual functionality >> b) optional clocks - additional clocks such as debounce clock etc. - there can be n such clocks >> c) interface clocks - this drives the register interface on the bus. - there can be n such clocks and additional headaches for interface - currently embedded inside hwmod. >> >> you could do: >> A) embedd in the sematics of the name >> clock-names="fck", "optional,role1", "optional,role2"; >> clocks= <&clk_a>, <&clk_x>, <&clk_y>; >> OR: >> B) embedd in the property name >> optional-clock-names="optional,role1", "optional,role2"; >> optional-clocks=<&clk_x>, <&clk_y>; >> functional-clock-names="fck"; >> functional-clocks=<&clk_a>; >> >> are you suggesting (b) here? >> >
[].. > > From the sounds of your other reply, the issue is that you're poking > clocks for arbitrary devices, without knowing the semantics of those > clocks, because you're doing it form outside the driver. Thats right.
On Wed, Aug 14, 2013 at 03:05:25PM +0100, Rajendra Nayak wrote: > On Wednesday 14 August 2013 07:28 PM, Nishanth Menon wrote: > > On 08/14/2013 08:49 AM, Mark Rutland wrote: > >> [Adding Mike Turquette and dt maintainers] > >> > >> On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: > >>> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: > >>>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: > >>>>> Hi Rajendra, > >>>>> > >>>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: > >>>>> [..] > >>>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c > >>>>>> index 12fa589..e5c804b 100644 > >>>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c > >>>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c > >>>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) > >>>>>> return ret; > >>>>>> } > >>>>>> > >>>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, > >>>>>> + struct device_node *np, > >>>>>> + int *opt_clks_cnt) > >>>>>> +{ > >>>>>> + int i, clks_cnt; > >>>>>> + const char *clk_name; > >>>>>> + const char **opt_clk_names; > >>>>>> + > >>>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); > >>>>>> + if (!clks_cnt) > >>>>>> + return NULL; > >>>>>> + > >>>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); > >>>>>> + if (!opt_clk_names) > >>>>>> + return NULL; > >>>>>> + > >>>>>> + for (i = 0; i < clks_cnt; i++) { > >>>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); > >>>>>> + if (!strcmp(clk_name, "fck")) > >>>>> > >>>>> Could we instead parse for names that are "optional,role_name" instead > >>>>> of assuming anything other than fck is optional clocks? > >>>> > >>>> you mean look for anything with optional,*? because the role names would change. > >>>> > >>> > >>> yes. the idea being, we now have a meaning to the clock name - there are > >>> two types of clocks here.. functional and optional, we *might* have > >>> facility to add interface clock(we dont know interface clock handling > >>> yet, but something in the future).. we might increase the support for > >>> number of functional clocks.. it might help to keep the format such that > >>> it is a "bit extendable". > >> > >> I completely disagree. The only things that should appear in clock-names > >> are the names of the clock inputs that appear in the manual for the > >> device. The driver should know which ones are optional, as that's a > >> fixed property of the IP and the way the driver uses it. > >> > >> You should not be embedding additional semantics in name properties. > > > > we use an level of abstraction called omap_device and hwmod to allow devices to use a generic pm_runtime. drivers for specific blocks dont normally need to know about the clocks to deal with. This allows maximum reuse consider concept is generic enough. > > They do know about the optional clocks though and request and release them when needed. The need for hwmod to know about optional clocks > (and enable all) arises from the fact that some of these devices need *some* optional clocks for a successful reset. > And given hmwod has no knowledge about which optional ones (if at all) will be needed, it goes ahead and enables all before doing a reset. > This is something done only at init time and *not* something thats done every time the device is enabled by the driver using pm_runtime. To clarify: I was initially confused as to the purpose of the code. I'm not against a one-off clock initialisation to put everything into a sane state. If we can't trust the bootloaders, that seems like a necessary evil. I'll leave Mike to comment on whether and how that should be done. I do not think we should be embedding clock semantics in clock-names. That's not the way the property is intended to be used, it breaks uniformity, and it's an abuse of the system that may come back to bite us later. Thanks, Mark.
On Wednesday 14 August 2013 07:43 PM, Mark Rutland wrote: > On Wed, Aug 14, 2013 at 03:05:25PM +0100, Rajendra Nayak wrote: >> On Wednesday 14 August 2013 07:28 PM, Nishanth Menon wrote: >>> On 08/14/2013 08:49 AM, Mark Rutland wrote: >>>> [Adding Mike Turquette and dt maintainers] >>>> >>>> On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: >>>>> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: >>>>>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >>>>>>> Hi Rajendra, >>>>>>> >>>>>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >>>>>>> [..] >>>>>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>>>>>>> index 12fa589..e5c804b 100644 >>>>>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>>>>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>>>>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>>>>>>> return ret; >>>>>>>> } >>>>>>>> >>>>>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>>>>>>> + struct device_node *np, >>>>>>>> + int *opt_clks_cnt) >>>>>>>> +{ >>>>>>>> + int i, clks_cnt; >>>>>>>> + const char *clk_name; >>>>>>>> + const char **opt_clk_names; >>>>>>>> + >>>>>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>>>>>>> + if (!clks_cnt) >>>>>>>> + return NULL; >>>>>>>> + >>>>>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>>>>>>> + if (!opt_clk_names) >>>>>>>> + return NULL; >>>>>>>> + >>>>>>>> + for (i = 0; i < clks_cnt; i++) { >>>>>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>>>>>>> + if (!strcmp(clk_name, "fck")) >>>>>>> >>>>>>> Could we instead parse for names that are "optional,role_name" instead >>>>>>> of assuming anything other than fck is optional clocks? >>>>>> >>>>>> you mean look for anything with optional,*? because the role names would change. >>>>>> >>>>> >>>>> yes. the idea being, we now have a meaning to the clock name - there are >>>>> two types of clocks here.. functional and optional, we *might* have >>>>> facility to add interface clock(we dont know interface clock handling >>>>> yet, but something in the future).. we might increase the support for >>>>> number of functional clocks.. it might help to keep the format such that >>>>> it is a "bit extendable". >>>> >>>> I completely disagree. The only things that should appear in clock-names >>>> are the names of the clock inputs that appear in the manual for the >>>> device. The driver should know which ones are optional, as that's a >>>> fixed property of the IP and the way the driver uses it. >>>> >>>> You should not be embedding additional semantics in name properties. >>> >>> we use an level of abstraction called omap_device and hwmod to allow devices to use a generic pm_runtime. drivers for specific blocks dont normally need to know about the clocks to deal with. This allows maximum reuse consider concept is generic enough. >> >> They do know about the optional clocks though and request and release them when needed. The need for hwmod to know about optional clocks >> (and enable all) arises from the fact that some of these devices need *some* optional clocks for a successful reset. >> And given hmwod has no knowledge about which optional ones (if at all) will be needed, it goes ahead and enables all before doing a reset. >> This is something done only at init time and *not* something thats done every time the device is enabled by the driver using pm_runtime. > > To clarify: > > I was initially confused as to the purpose of the code. I'm not against > a one-off clock initialisation to put everything into a sane state. If > we can't trust the bootloaders, that seems like a necessary evil. I'll > leave Mike to comment on whether and how that should be done. > > I do not think we should be embedding clock semantics in clock-names. > That's not the way the property is intended to be used, it breaks > uniformity, and it's an abuse of the system that may come back to bite > us later. Mark, that makes sense. Nishanth, thinking some more of this, the 'optional,role-name' also won't work for the simple reason that drivers who do clk_get(node, 'role-name') would then simply fail. So I guess we need to figure out a better way to handle this. > > Thanks, > Mark. >
On 08/14/2013 09:20 AM, Rajendra Nayak wrote: > On Wednesday 14 August 2013 07:43 PM, Mark Rutland wrote: >> On Wed, Aug 14, 2013 at 03:05:25PM +0100, Rajendra Nayak wrote: >>> On Wednesday 14 August 2013 07:28 PM, Nishanth Menon wrote: >>>> On 08/14/2013 08:49 AM, Mark Rutland wrote: >>>>> [Adding Mike Turquette and dt maintainers] >>>>> >>>>> On Wed, Aug 14, 2013 at 02:39:44PM +0100, Nishanth Menon wrote: >>>>>> On 08/14/2013 08:20 AM, Rajendra Nayak wrote: >>>>>>> On Wednesday 14 August 2013 06:18 PM, Nishanth Menon wrote: >>>>>>>> Hi Rajendra, >>>>>>>> >>>>>>>> On Tue, Jul 23, 2013 at 1:24 AM, Rajendra Nayak <rnayak@ti.com> wrote: >>>>>>>> [..] >>>>>>>>> diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c >>>>>>>>> index 12fa589..e5c804b 100644 >>>>>>>>> --- a/arch/arm/mach-omap2/omap_hwmod.c >>>>>>>>> +++ b/arch/arm/mach-omap2/omap_hwmod.c >>>>>>>>> @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) >>>>>>>>> return ret; >>>>>>>>> } >>>>>>>>> >>>>>>>>> +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, >>>>>>>>> + struct device_node *np, >>>>>>>>> + int *opt_clks_cnt) >>>>>>>>> +{ >>>>>>>>> + int i, clks_cnt; >>>>>>>>> + const char *clk_name; >>>>>>>>> + const char **opt_clk_names; >>>>>>>>> + >>>>>>>>> + clks_cnt = of_property_count_strings(np, "clock-names"); >>>>>>>>> + if (!clks_cnt) >>>>>>>>> + return NULL; >>>>>>>>> + >>>>>>>>> + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); >>>>>>>>> + if (!opt_clk_names) >>>>>>>>> + return NULL; >>>>>>>>> + >>>>>>>>> + for (i = 0; i < clks_cnt; i++) { >>>>>>>>> + of_property_read_string_index(np, "clock-names", i, &clk_name); >>>>>>>>> + if (!strcmp(clk_name, "fck")) >>>>>>>> >>>>>>>> Could we instead parse for names that are "optional,role_name" instead >>>>>>>> of assuming anything other than fck is optional clocks? >>>>>>> >>>>>>> you mean look for anything with optional,*? because the role names would change. >>>>>>> >>>>>> >>>>>> yes. the idea being, we now have a meaning to the clock name - there are >>>>>> two types of clocks here.. functional and optional, we *might* have >>>>>> facility to add interface clock(we dont know interface clock handling >>>>>> yet, but something in the future).. we might increase the support for >>>>>> number of functional clocks.. it might help to keep the format such that >>>>>> it is a "bit extendable". >>>>> >>>>> I completely disagree. The only things that should appear in clock-names >>>>> are the names of the clock inputs that appear in the manual for the >>>>> device. The driver should know which ones are optional, as that's a >>>>> fixed property of the IP and the way the driver uses it. >>>>> >>>>> You should not be embedding additional semantics in name properties. >>>> >>>> we use an level of abstraction called omap_device and hwmod to allow devices to use a generic pm_runtime. drivers for specific blocks dont normally need to know about the clocks to deal with. This allows maximum reuse consider concept is generic enough. >>> >>> They do know about the optional clocks though and request and release them when needed. The need for hwmod to know about optional clocks >>> (and enable all) arises from the fact that some of these devices need *some* optional clocks for a successful reset. >>> And given hmwod has no knowledge about which optional ones (if at all) will be needed, it goes ahead and enables all before doing a reset. >>> This is something done only at init time and *not* something thats done every time the device is enabled by the driver using pm_runtime. >> >> To clarify: >> >> I was initially confused as to the purpose of the code. I'm not against >> a one-off clock initialisation to put everything into a sane state. If >> we can't trust the bootloaders, that seems like a necessary evil. I'll >> leave Mike to comment on whether and how that should be done. >> >> I do not think we should be embedding clock semantics in clock-names. >> That's not the way the property is intended to be used, it breaks >> uniformity, and it's an abuse of the system that may come back to bite >> us later. > > Mark, that makes sense. > > Nishanth, thinking some more of this, the 'optional,role-name' also won't work > for the simple reason that drivers who do clk_get(node, 'role-name') would > then simply fail. > > So I guess we need to figure out a better way to handle this. you are right :( we do have types of clock inputs to a device and therein lies our problem :(
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 12fa589..e5c804b 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -805,6 +805,65 @@ static int _init_interface_clks(struct omap_hwmod *oh) return ret; } +static const char **_parse_opt_clks_dt(struct omap_hwmod *oh, + struct device_node *np, + int *opt_clks_cnt) +{ + int i, clks_cnt; + const char *clk_name; + const char **opt_clk_names; + + clks_cnt = of_property_count_strings(np, "clock-names"); + if (!clks_cnt) + return NULL; + + opt_clk_names = kzalloc(sizeof(char *)*clks_cnt, GFP_KERNEL); + if (!opt_clk_names) + return NULL; + + for (i = 0; i < clks_cnt; i++) { + of_property_read_string_index(np, "clock-names", i, &clk_name); + if (!strcmp(clk_name, "fck")) + continue; + opt_clks_cnt++; + opt_clk_names[i] = clk_name; + } + return opt_clk_names; +} + +static int _init_opt_clks_dt(struct omap_hwmod *oh, struct device_node *np) +{ + struct clk *c; + int i, opt_clks_cnt = 0; + int ret = 0; + const char **opt_clk_names; + + opt_clk_names = _parse_opt_clks_dt(oh, np, &opt_clks_cnt); + if (!opt_clk_names) + return -EINVAL; + + oh->opt_clks = kzalloc(sizeof(struct omap_hwmod_opt_clk *) + * opt_clks_cnt, GFP_KERNEL); + if (!oh->opt_clks) + return -ENOMEM; + + oh->opt_clks_cnt = opt_clks_cnt; + + for (i = 0; i < oh->opt_clks_cnt; i++) { + c = of_clk_get_by_name(np, opt_clk_names[i]); + if (IS_ERR(c)) { + pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n", + oh->name, opt_clk_names[i]); + ret = -EINVAL; + } + oh->opt_clks[i]._clk = c; + oh->opt_clks[i].role = opt_clk_names[i]; + oh->opt_clks_cnt++; + clk_prepare(oh->opt_clks[i]._clk); + } + return ret; +} + /** * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks * @oh: struct omap_hwmod * @@ -812,13 +871,16 @@ static int _init_interface_clks(struct omap_hwmod *oh) * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk * clock pointers. Returns 0 on success or -EINVAL on error. */ -static int _init_opt_clks(struct omap_hwmod *oh) +static int _init_opt_clks(struct omap_hwmod *oh, struct device_node *np) { struct omap_hwmod_opt_clk *oc; struct clk *c; int i; int ret = 0; + if (of_get_property(np, "clocks", NULL)) + return _init_opt_clks_dt(oh, np); + for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) { c = clk_get(NULL, oc->clk); if (IS_ERR(c)) { @@ -1580,7 +1642,7 @@ static int _init_clocks(struct omap_hwmod *oh, void *data, ret |= _init_main_clk(oh, np); ret |= _init_interface_clks(oh); - ret |= _init_opt_clks(oh); + ret |= _init_opt_clks(oh, np); if (!ret) oh->_state = _HWMOD_STATE_CLKS_INITED;
With clocks for OMAP moving to DT, its now possible to pass all optional clock data for each device from DT instead of having it in hwmod. Signed-off-by: Rajendra Nayak <rnayak@ti.com> --- arch/arm/mach-omap2/omap_hwmod.c | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-)