diff mbox

[2/2] cpufreq: brcmstb-avs-cpufreq: prefer SCMI cpufreq if supported

Message ID 20180418155643.36464-3-code@mmayer.net (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Markus Mayer April 18, 2018, 3:56 p.m. UTC
From: Jim Quinlan <jim2101024@gmail.com>

If the SCMI cpufreq driver is supported, we bail, so that the new
approach can be used.

Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Florian Fainelli April 18, 2018, 4:37 p.m. UTC | #1
On 04/18/2018 08:56 AM, Markus Mayer wrote:
> From: Jim Quinlan <jim2101024@gmail.com>
> 
> If the SCMI cpufreq driver is supported, we bail, so that the new
> approach can be used.
> 
> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> ---
>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> index b07559b9ed99..b4861a730162 100644
> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> @@ -164,6 +164,8 @@
>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
>  #define BRCM_AVS_HOST_INTR	"sw_intr"
>  
> +#define ARM_SCMI_COMPAT		"arm,scmi"
> +
>  struct pmap {
>  	unsigned int mode;
>  	unsigned int p1;
> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>  	struct device *dev;
>  	int host_irq, ret;
>  
> +	/*
> +	 * If the SCMI cpufreq driver is supported, we bail, so that the more
> +	 * modern approach can be used.
> +	 */
> +	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
> +		struct device_node *np;
> +
> +		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
> +		if (np) {
> +			of_node_put(np);
> +			return -ENXIO;
> +		}

We would probably want to make sure that the node is also enabled (that
is, does not have a status = "disabled" property) otherwise the check
can be defeated. Something like:

		if (np && of_device_is_available(np))

should be good for that.

Thanks!
Viresh Kumar April 19, 2018, 4:16 a.m. UTC | #2
On 18-04-18, 08:56, Markus Mayer wrote:
> From: Jim Quinlan <jim2101024@gmail.com>
> 
> If the SCMI cpufreq driver is supported, we bail, so that the new
> approach can be used.
> 
> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> ---
>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> index b07559b9ed99..b4861a730162 100644
> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> @@ -164,6 +164,8 @@
>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
>  #define BRCM_AVS_HOST_INTR	"sw_intr"
>  
> +#define ARM_SCMI_COMPAT		"arm,scmi"
> +
>  struct pmap {
>  	unsigned int mode;
>  	unsigned int p1;
> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>  	struct device *dev;
>  	int host_irq, ret;
>  
> +	/*
> +	 * If the SCMI cpufreq driver is supported, we bail, so that the more
> +	 * modern approach can be used.
> +	 */
> +	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
> +		struct device_node *np;
> +
> +		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
> +		if (np) {
> +			of_node_put(np);
> +			return -ENXIO;
> +		}
> +	}
> +

What about adding !CONFIG_ARM_SCMI_PROTOCOL in Kconfig dependency and don't
compile the driver at all ?
Sudeep Holla April 19, 2018, 10:35 a.m. UTC | #3
On 18/04/18 16:56, Markus Mayer wrote:
> From: Jim Quinlan <jim2101024@gmail.com>
> 
> If the SCMI cpufreq driver is supported, we bail, so that the new
> approach can be used.
> 
> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> ---
>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> index b07559b9ed99..b4861a730162 100644
> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> @@ -164,6 +164,8 @@
>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
>  #define BRCM_AVS_HOST_INTR	"sw_intr"
>  
> +#define ARM_SCMI_COMPAT		"arm,scmi"
> +
>  struct pmap {
>  	unsigned int mode;
>  	unsigned int p1;
> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>  	struct device *dev;
>  	int host_irq, ret;
>  

Will this platform have both SCMI and BRCM_AVS_CPU_DATA nodes enabled ?
If so, is it not better to just keep only the preferred node enabled
instead ?

> +	/*
> +	 * If the SCMI cpufreq driver is supported, we bail, so that the more
> +	 * modern approach can be used.
> +	 */
> +	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
> +		struct device_node *np;
> +
> +		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
> +		if (np) {
> +			of_node_put(np);
> +			return -ENXIO;
> +		}
> +	}
> +

Clearly not a good approach.
Sudeep Holla April 19, 2018, 10:37 a.m. UTC | #4
On 19/04/18 05:16, Viresh Kumar wrote:
> On 18-04-18, 08:56, Markus Mayer wrote:
>> From: Jim Quinlan <jim2101024@gmail.com>
>>
>> If the SCMI cpufreq driver is supported, we bail, so that the new
>> approach can be used.
>>
>> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
>> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
>> ---
>>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>
>> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> index b07559b9ed99..b4861a730162 100644
>> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> @@ -164,6 +164,8 @@
>>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
>>  #define BRCM_AVS_HOST_INTR	"sw_intr"
>>  
>> +#define ARM_SCMI_COMPAT		"arm,scmi"
>> +
>>  struct pmap {
>>  	unsigned int mode;
>>  	unsigned int p1;
>> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>>  	struct device *dev;
>>  	int host_irq, ret;
>>  
>> +	/*
>> +	 * If the SCMI cpufreq driver is supported, we bail, so that the more
>> +	 * modern approach can be used.
>> +	 */
>> +	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
>> +		struct device_node *np;
>> +
>> +		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
>> +		if (np) {
>> +			of_node_put(np);
>> +			return -ENXIO;
>> +		}
>> +	}
>> +
> 
> What about adding !CONFIG_ARM_SCMI_PROTOCOL in Kconfig dependency and don't
> compile the driver at all ?
> 

Unfortunately, that may not be good idea with single image needing both
configs to be enabled.
Florian Fainelli April 19, 2018, 4:21 p.m. UTC | #5
On 04/19/2018 03:35 AM, Sudeep Holla wrote:
> 
> 
> On 18/04/18 16:56, Markus Mayer wrote:
>> From: Jim Quinlan <jim2101024@gmail.com>
>>
>> If the SCMI cpufreq driver is supported, we bail, so that the new
>> approach can be used.
>>
>> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
>> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
>> ---
>>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>
>> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> index b07559b9ed99..b4861a730162 100644
>> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> @@ -164,6 +164,8 @@
>>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
>>  #define BRCM_AVS_HOST_INTR	"sw_intr"
>>  
>> +#define ARM_SCMI_COMPAT		"arm,scmi"
>> +
>>  struct pmap {
>>  	unsigned int mode;
>>  	unsigned int p1;
>> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>>  	struct device *dev;
>>  	int host_irq, ret;
>>  
> 
> Will this platform have both SCMI and BRCM_AVS_CPU_DATA nodes enabled ?
> If so, is it not better to just keep only the preferred node enabled
> instead ?

The kernel image has both drivers enabled, the Device Tree blob we pass
contains both nodes, and should flip the status properties based on what
is available. We had some internal discussion about that specific
change, and we ended up having the patch being submitted to seek
external advice, I guess we have an answer now this is not desired.
Markus Mayer April 19, 2018, 10:10 p.m. UTC | #6
On 18 April 2018 at 09:37, Florian Fainelli <f.fainelli@gmail.com> wrote:
> On 04/18/2018 08:56 AM, Markus Mayer wrote:
>> From: Jim Quinlan <jim2101024@gmail.com>
>>
>> If the SCMI cpufreq driver is supported, we bail, so that the new
>> approach can be used.
>>
>> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
>> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
>> ---
>>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>>
>> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> index b07559b9ed99..b4861a730162 100644
>> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>> @@ -164,6 +164,8 @@
>>  #define BRCM_AVS_CPU_INTR    "brcm,avs-cpu-l2-intr"
>>  #define BRCM_AVS_HOST_INTR   "sw_intr"
>>
>> +#define ARM_SCMI_COMPAT              "arm,scmi"
>> +
>>  struct pmap {
>>       unsigned int mode;
>>       unsigned int p1;
>> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>>       struct device *dev;
>>       int host_irq, ret;
>>
>> +     /*
>> +      * If the SCMI cpufreq driver is supported, we bail, so that the more
>> +      * modern approach can be used.
>> +      */
>> +     if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
>> +             struct device_node *np;
>> +
>> +             np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
>> +             if (np) {
>> +                     of_node_put(np);
>> +                     return -ENXIO;
>> +             }
>
> We would probably want to make sure that the node is also enabled (that
> is, does not have a status = "disabled" property) otherwise the check
> can be defeated. Something like:
>
>                 if (np && of_device_is_available(np))

Would we want something like this instead?

                 if (np) {
                                  bool bail_early =
(of_device_is_available(np) > 0);

                                  of_node_put(np);
                                  if (bail_early)
                                          return -ENXIO;
                 }

To ensure of_node_put() is called?

> should be good for that.
>
> Thanks!
> --
> Florian
Viresh Kumar April 20, 2018, 4:42 a.m. UTC | #7
On 19-04-18, 11:37, Sudeep Holla wrote:
> 
> 
> On 19/04/18 05:16, Viresh Kumar wrote:
> > On 18-04-18, 08:56, Markus Mayer wrote:
> >> From: Jim Quinlan <jim2101024@gmail.com>
> >>
> >> If the SCMI cpufreq driver is supported, we bail, so that the new
> >> approach can be used.
> >>
> >> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
> >> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> >> ---
> >>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
> >>  1 file changed, 16 insertions(+)
> >>
> >> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> >> index b07559b9ed99..b4861a730162 100644
> >> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
> >> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
> >> @@ -164,6 +164,8 @@
> >>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
> >>  #define BRCM_AVS_HOST_INTR	"sw_intr"
> >>  
> >> +#define ARM_SCMI_COMPAT		"arm,scmi"
> >> +
> >>  struct pmap {
> >>  	unsigned int mode;
> >>  	unsigned int p1;
> >> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
> >>  	struct device *dev;
> >>  	int host_irq, ret;
> >>  
> >> +	/*
> >> +	 * If the SCMI cpufreq driver is supported, we bail, so that the more
> >> +	 * modern approach can be used.
> >> +	 */
> >> +	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
> >> +		struct device_node *np;
> >> +
> >> +		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
> >> +		if (np) {
> >> +			of_node_put(np);
> >> +			return -ENXIO;
> >> +		}
> >> +	}
> >> +
> > 
> > What about adding !CONFIG_ARM_SCMI_PROTOCOL in Kconfig dependency and don't
> > compile the driver at all ?
> > 
> 
> Unfortunately, that may not be good idea with single image needing both
> configs to be enabled.

Sure, but looking at the above code, it looked like they don't need the other
config if SCMI is enabled.
Sudeep Holla April 20, 2018, 9:15 a.m. UTC | #8
On 20/04/18 05:42, Viresh Kumar wrote:
> On 19-04-18, 11:37, Sudeep Holla wrote:
>>
>>
>> On 19/04/18 05:16, Viresh Kumar wrote:
>>> On 18-04-18, 08:56, Markus Mayer wrote:
>>>> From: Jim Quinlan <jim2101024@gmail.com>
>>>>
>>>> If the SCMI cpufreq driver is supported, we bail, so that the new
>>>> approach can be used.
>>>>
>>>> Signed-off-by: Jim Quinlan <jim2101024@gmail.com>
>>>> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
>>>> ---
>>>>  drivers/cpufreq/brcmstb-avs-cpufreq.c | 16 ++++++++++++++++
>>>>  1 file changed, 16 insertions(+)
>>>>
>>>> diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>>>> index b07559b9ed99..b4861a730162 100644
>>>> --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
>>>> +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
>>>> @@ -164,6 +164,8 @@
>>>>  #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
>>>>  #define BRCM_AVS_HOST_INTR	"sw_intr"
>>>>  
>>>> +#define ARM_SCMI_COMPAT		"arm,scmi"
>>>> +
>>>>  struct pmap {
>>>>  	unsigned int mode;
>>>>  	unsigned int p1;
>>>> @@ -511,6 +513,20 @@ static int brcm_avs_prepare_init(struct platform_device *pdev)
>>>>  	struct device *dev;
>>>>  	int host_irq, ret;
>>>>  
>>>> +	/*
>>>> +	 * If the SCMI cpufreq driver is supported, we bail, so that the more
>>>> +	 * modern approach can be used.
>>>> +	 */
>>>> +	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
>>>> +		struct device_node *np;
>>>> +
>>>> +		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
>>>> +		if (np) {
>>>> +			of_node_put(np);
>>>> +			return -ENXIO;
>>>> +		}
>>>> +	}
>>>> +
>>>
>>> What about adding !CONFIG_ARM_SCMI_PROTOCOL in Kconfig dependency and don't
>>> compile the driver at all ?
>>>
>>
>> Unfortunately, that may not be good idea with single image needing both
>> configs to be enabled.
> 
> Sure, but looking at the above code, it looked like they don't need the other
> config if SCMI is enabled.
> 

Yes, I understand that. But if they just want to run a distro kernel or
a defconfig with all the options enabled, then it's not possible. But if
they always build kernel with some custom config options, then fine.

It still doesn't give the flexibility to switch between the two
implementations boot time based on some firmware config(e.g. DT status
property).
Viresh Kumar April 20, 2018, 9:35 a.m. UTC | #9
On 20-04-18, 10:15, Sudeep Holla wrote:
> It still doesn't give the flexibility to switch between the two
> implementations boot time based on some firmware config(e.g. DT status
> property).

I agree, but it didn't look like they need flexibility :)

Lets see how the intend to use it. If they are *always* going to use SCPI if
that is available, then it should be solved at Kconfig level only. Else they
shouldn't put such code in the driver to quit early.
Florian Fainelli April 20, 2018, 4:50 p.m. UTC | #10
On 04/20/2018 02:35 AM, Viresh Kumar wrote:
> On 20-04-18, 10:15, Sudeep Holla wrote:
>> It still doesn't give the flexibility to switch between the two
>> implementations boot time based on some firmware config(e.g. DT status
>> property).
> 
> I agree, but it didn't look like they need flexibility :)
> 
> Lets see how the intend to use it. If they are *always* going to use SCPI if
> that is available, then it should be solved at Kconfig level only. Else they
> shouldn't put such code in the driver to quit early.

We have both drivers (brcmstb-avs-cpufreq and scmi-cpufreq) enabled in
our kernel configuration, however, depending on the firmware version, we
may have a number of combinations:

- arm,scmi DT node is present and enabled (status = okay) as well as
brcmstb-avs-cpufreq being present and enabled
- arm,scmi DT node is present but disabled (status = disabled) and
brcmstb-avs-cpufreq is being present and enabled

If you think this is a self inflicted, downstream and backwards/forwards
compatible relevant only change, I suppose we are fine with that too.
Viresh Kumar April 23, 2018, 4:23 a.m. UTC | #11
On 20-04-18, 09:50, Florian Fainelli wrote:
> On 04/20/2018 02:35 AM, Viresh Kumar wrote:
> > On 20-04-18, 10:15, Sudeep Holla wrote:
> >> It still doesn't give the flexibility to switch between the two
> >> implementations boot time based on some firmware config(e.g. DT status
> >> property).
> > 
> > I agree, but it didn't look like they need flexibility :)
> > 
> > Lets see how the intend to use it. If they are *always* going to use SCPI if
> > that is available, then it should be solved at Kconfig level only. Else they
> > shouldn't put such code in the driver to quit early.
> 
> We have both drivers (brcmstb-avs-cpufreq and scmi-cpufreq) enabled in
> our kernel configuration, however, depending on the firmware version, we
> may have a number of combinations:
> 
> - arm,scmi DT node is present and enabled (status = okay) as well as
> brcmstb-avs-cpufreq being present and enabled
> - arm,scmi DT node is present but disabled (status = disabled) and
> brcmstb-avs-cpufreq is being present and enabled

In this case the Kconfig thing I have been talking about doesn't apply anymore.
diff mbox

Patch

diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index b07559b9ed99..b4861a730162 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -164,6 +164,8 @@ 
 #define BRCM_AVS_CPU_INTR	"brcm,avs-cpu-l2-intr"
 #define BRCM_AVS_HOST_INTR	"sw_intr"
 
+#define ARM_SCMI_COMPAT		"arm,scmi"
+
 struct pmap {
 	unsigned int mode;
 	unsigned int p1;
@@ -511,6 +513,20 @@  static int brcm_avs_prepare_init(struct platform_device *pdev)
 	struct device *dev;
 	int host_irq, ret;
 
+	/*
+	 * If the SCMI cpufreq driver is supported, we bail, so that the more
+	 * modern approach can be used.
+	 */
+	if (IS_ENABLED(CONFIG_ARM_SCMI_PROTOCOL)) {
+		struct device_node *np;
+
+		np = of_find_compatible_node(NULL, NULL, ARM_SCMI_COMPAT);
+		if (np) {
+			of_node_put(np);
+			return -ENXIO;
+		}
+	}
+
 	dev = &pdev->dev;
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)