[PATCH RESEND 5/5] clk: ccf: call clock provided ops directly for endisable()

Yang Xiwen forbidden405 at outlook.com
Wed Nov 1 19:50:47 CET 2023


On 11/2/2023 2:19 AM, Sean Anderson wrote:
> On 8/17/23 13:04, Yang Xiwen via B4 Relay wrote:
>> From: Yang Xiwen <forbidden405 at outlook.com>
>>
>> Calling into CCF framework will cause a clock being enabled twice
>> instead of once (clk->enable_count becomes 2 rather than 1), thus making
>> it hard to disable (needs to call clk_disable() twice).
>> Fix that by calling clock provided ops directly.
> 
> Can you describe this scenario more? From what I can tell, clk_enable
> doesn't
> increment enable_count for CCF clocks.
> 
Well, it's hard to describe clearly. But I can only tell this patch
fixed the issue when i was trying to write an Ethernet driver[1] which
calls clk_disable() and expects the clock to be disabled after that.
Also I found that CCF driver does not have a corresponding test file. I
will try to write a test for that in next release.
> --Sean
> 
>> Signed-off-by: Yang Xiwen <forbidden405 at outlook.com>
>> ---
>>   drivers/clk/clk.c | 12 +++++++++++-
>>   1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>> index a38daaac0c..00d082c46f 100644
>> --- a/drivers/clk/clk.c
>> +++ b/drivers/clk/clk.c
>> @@ -14,6 +14,7 @@
>>   #include <dm/uclass.h>
>>   #include <dm/lists.h>
>>   #include <dm/device-internal.h>
>> +#include <linux/clk-provider.h>
>>     int clk_register(struct clk *clk, const char *drv_name,
>>            const char *name, const char *parent_name)
>> @@ -115,11 +116,20 @@ int ccf_clk_set_parent(struct clk *clk, struct
>> clk *parent)
>>   static int ccf_clk_endisable(struct clk *clk, bool enable)
>>   {
>>       struct clk *c;
>> +    const struct clk_ops *ops;
>>       int err = clk_get_by_id(clk->id, &c);
>>         if (err)
>>           return err;
>> -    return enable ? clk_enable(c) : clk_disable(c);
>> +    else
>> +        ops = clk_dev_ops(c->dev);
>> +
>> +    if (enable && ops->enable)
>> +        return ops->enable(c);
>> +    else if (!enable && ops->disable)
>> +        return ops->disable(c);
>> +
>> +    return -ENOSYS;
>>   }
>>     int ccf_clk_enable(struct clk *clk)
>>
> 
[1]
https://lore.kernel.org/all/20230814-wip-hisi_femac-trunk-v2-0-1e29f400585d@outlook.com/

-- 
Best regards,
Yang Xiwen



More information about the U-Boot mailing list