clk: clk-cdce925: Add regulator support
PATCH 1/1 clk: clk-cdce925: Add regulator support
The cdce925 power supplies could be controllable on some platforms. Enable them before communicating with the cdce925.
---
Notes:
We see a kernel panic later in the boot if the regulator is not enabled. Unsure what in the driver is causing that. Something to do with regmap perhaps?
drivers/clk/clk-cdce925.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/clk/clk-cdce925.c +34 -0
@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/i2c.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/gcd.h>
@@ -602,6 +603,30 @@ static int cdce925_regmap_i2c_read(void *context,return &data->clk[idx].hw; } +static void cdce925_regulator_disable (void *regulator) +{ +regulator_disable (regulator); +} + +static int cdce925_regulator_enable (struct device *dev,const char *name) +{ +struct regulator *regulator; +int err; + + regulator =devm_regulator_get (dev, name); +if (IS_ERR (regulator)) +return PTR_ERR (regulator); + + err =regulator_enable (regulator); +if (err) { +dev_err (dev,"Failed to enable %s: %d\n" , name, err); +return err; + } + +return devm_add_action_or_reset (dev, cdce925_regulator_disable, + regulator); +} +/* The CDCE925 uses a funky way to read/write registers. Bulk mode is * just weird, so just use the single byte mode exclusively. */ static struct regmap_bus regmap_cdce925_bus = {
@@ -630,6 +655,15 @@ static int cdce925_probe(struct i2c_client *client, };dev_dbg (&client->dev,"%s\n" , __func__); + + err =cdce925_regulator_enable (&client->dev,"vdd" ); +if (err) +return err; + + err =cdce925_regulator_enable (&client->dev,"vddout" ); +if (err) +return err; + data =devm_kzalloc (&client->dev,sizeof (*data),GFP_KERNEL );if (!data)return -ENOMEM ;
Signature · 1 line
1.8.3.1
Stephen Boyd
maintainerQuoting Phil Reid (2019-06-13 20:52:43)
Quoted 35 lines
The cdce925 power supplies could be controllable on some platforms. Enable them before communicating with the cdce925.
Signed-off-by Phil Reid <[email protected]>---
Notes:
We see a kernel panic later in the boot if the regulator is not enabled. Unsure what in the driver is causing that. Something to do with regmap perhaps?drivers/clk/clk-cdce925.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)drivers/clk/clk-cdce925.c +6
-0@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/i2c.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/gcd.h> @@ -602,6 +603,30 @@ static int cdce925_regmap_i2c_read(void *context,return &data->clk[idx].hw; } +static void cdce925_regulator_disable (void *regulator) +{ +regulator_disable (regulator); +} +
drivers/clk/clk-cdce925.c static int cdce925_regmap_i2c_read(void *context, · line 620
Quoted 10 lines
drivers/clk/clk-cdce925.c +10
-0+static int cdce925_regulator_enable (struct device *dev,const char *name) +{ +struct regulator *regulator; +int err; + + regulator =devm_regulator_get (dev, name); +if (IS_ERR (regulator)) +return PTR_ERR (regulator); + + err =regulator_enable (regulator);
The regulator is never turned off though. Are these regulators really just always on regulators that don't need to be managed by this driver?
Also, is there an update to the DT binding somewhere?
Quoted 31 lines · Stephen Boyd
Quoting Phil Reid (2019-06-13 20:52:43)
Quoted 30 lines
The cdce925 power supplies could be controllable on some platforms. Enable them before communicating with the cdce925.
Signed-off-by Phil Reid <[email protected]>---
Notes:
We see a kernel panic later in the boot if the regulator is not enabled. Unsure what in the driver is causing that. Something to do with regmap perhaps?drivers/clk/clk-cdce925.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)drivers/clk/clk-cdce925.c +1
-0@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/i2c.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/gcd.h> @@ -602,6 +603,30 @@ static int cdce925_regmap_i2c_read(void *context,return &data->clk[idx].hw; }
Quoted 16 lines
Quoted 5 lines
drivers/clk/clk-cdce925.c +5
-0+static void cdce925_regulator_disable (void *regulator) +{ +regulator_disable (regulator); +} +drivers/clk/clk-cdce925.c static int cdce925_regmap_i2c_read(void *context, · line 620
Quoted 10 lines
drivers/clk/clk-cdce925.c +10
-0+static int cdce925_regulator_enable (struct device *dev,const char *name) +{ +struct regulator *regulator; +int err; + + regulator =devm_regulator_get (dev, name); +if (IS_ERR (regulator)) +return PTR_ERR (regulator); + + err =regulator_enable (regulator);
G'day Stephen,
Thanks for looking at this.
Quoted 3 lines
The regulator is never turned off though. Are these regulators really just always on regulators that don't need to be managed by this driver?
For our system the regulator needs to be enabled before we try talking to the chip. Funny that.
Unloading the driver will disable the regulator thru the devm call to cdce925_regulator_disable
drivers/clk/clk-cdce925.c static int cdce925_regmap_i2c_read(void *context, · line 628
Quoted 3 lines
drivers/clk/clk-cdce925.c +3
-0+return devm_add_action_or_reset (dev, cdce925_regulator_disable, + regulator); +}
In the future suspend/resume support could be added to power the device down. The system I have doesn't support suspending thou.
Quoted 2 lines
Also, is there an update to the DT binding somewhere?
No I didn't update that.
It seems a bit adhoc if supply reference are including in the DT docs. I can add something if your happy with the pathc in general.
Signature · 2 lines
Regards Phil Reid
Stephen Boyd
maintainerQuoting Phil Reid (2019-06-25 18:06:29)
Quoted 8 lines · Stephen Boyd
Quoted 5 lines
Quoting Phil Reid (2019-06-13 20:52:43)
Quoted 3 lines
drivers/clk/clk-cdce925.c +3
-0+return PTR_ERR (regulator); + + err =regulator_enable (regulator);G'day Stephen,
Quoted 8 lines
Thanks for looking at this.
Quoted 3 lines
The regulator is never turned off though. Are these regulators really just always on regulators that don't need to be managed by this driver?
For our system the regulator needs to be enabled before we try talking to the chip. Funny that.
Unloading the driver will disable the regulator thru the devm call tocdce925_regulator_disable
Ok. Is it a regulator that is expected to just always be on though? Or does the datasheet for this device indicate that these supplies can be turned on and off when the device isn't in use?
Quoted 5 lines
drivers/clk/clk-cdce925.c static int cdce925_regmap_i2c_read(void *context, · line 628
Quoted 4 lines
drivers/clk/clk-cdce925.c +3
-0+return devm_add_action_or_reset (dev, cdce925_regulator_disable, + regulator); +}
Quoted 9 lines
In the future suspend/resume support could be added to power the device down. The system I have doesn't support suspending thou.
Quoted 2 lines
Also, is there an update to the DT binding somewhere?
No I didn't update that.
It seems a bit adhoc if supply reference are including in the DT docs. I can add something if your happy with the pathc in general.
Yes, the binding needs an update to list out the supplies. If they're not always going to be enabled because they're controlled supplies in the design then it makes sense to me to add them to the binding and use them from this driver so that things operate properly.
Quoted 13 lines · Stephen Boyd
Quoting Phil Reid (2019-06-25 18:06:29)
Quoted 12 lines · Stephen Boyd
Quoted 5 lines
Quoting Phil Reid (2019-06-13 20:52:43)
Quoted 3 lines
drivers/clk/clk-cdce925.c +3
-0+return PTR_ERR (regulator); + + err =regulator_enable (regulator);G'day Stephen,
Thanks for looking at this.
Quoted 3 lines
The regulator is never turned off though. Are these regulators really just always on regulators that don't need to be managed by this driver?
Quoted 8 lines
Quoted 4 lines
For our system the regulator needs to be enabled before we try talking to the chip. Funny that.
Unloading the driver will disable the regulator thru the devm call tocdce925_regulator_disableOk. Is it a regulator that is expected to just always be on though? Or does the datasheet for this device indicate that these supplies can be turned on and off when the device isn't in use?
Sorry I'm not understanding what your asking.
Should we be using some other method to ensure there is power to this device before probingHow do I then ensure the dependency to that power supply?
I can't see why that part of the system can't be shut down, provided that inputs are also isolated correctly when the regulator is disabled etc.
The data sheet says that input can execeed VDD / VDDOUT provide clamp current ratings are observed.
It is also seems permissible to disable Vddout independently of Vdd (for some variants).
Quoted 23 lines
Quoted 6 lines
drivers/clk/clk-cdce925.c static int cdce925_regmap_i2c_read(void *context, · line 628
Quoted 5 lines
drivers/clk/clk-cdce925.c +3
-0+return devm_add_action_or_reset (dev, cdce925_regulator_disable, + regulator); +}Quoted 9 lines
In the future suspend/resume support could be added to power the device down. The system I have doesn't support suspending thou.
Quoted 2 lines
Also, is there an update to the DT binding somewhere?
No I didn't update that.
It seems a bit adhoc if supply reference are including in the DT docs. I can add something if your happy with the pathc in general.Yes, the binding needs an update to list out the supplies. If they're not always going to be enabled because they're controlled supplies in the design then it makes sense to me to add them to the binding and use them from this driver so that things operate properly.
Signature · 2 lines
Regards Phil Reid
Stephen Boyd
maintainerQuoting Phil Reid (2019-06-25 21:03:20)
Quoted 19 lines · Stephen Boyd
Quoted 18 lines
Quoting Phil Reid (2019-06-25 18:06:29)
Quoted 16 lines · Stephen Boyd
Quoted 5 lines
Quoting Phil Reid (2019-06-13 20:52:43)
Quoted 3 lines
drivers/clk/clk-cdce925.c +3
-0+return PTR_ERR (regulator); + + err =regulator_enable (regulator);G'day Stephen,
Thanks for looking at this.
Quoted 3 lines
The regulator is never turned off though. Are these regulators really just always on regulators that don't need to be managed by this driver?
For our system the regulator needs to be enabled before we try talking to the chip. Funny that.
Unloading the driver will disable the regulator thru the devm call tocdce925_regulator_disable
Quoted 7 lines
Quoted 3 lines
Ok. Is it a regulator that is expected to just always be on though? Or does the datasheet for this device indicate that these supplies can be turned on and off when the device isn't in use?
Sorry I'm not understanding what your asking.
Should we be using some other method to ensure there is power to this device before probingHow do I then ensure the dependency to that power supply?
No, I'm not an expert in this clk driver so I have no idea if this is some sort of supply that is typically always on or if software is expected to manage the regulator at runtime. I'm just asking to make sure that your use case requires this be managed at runtime instead of turned on immediately when the regulator driver probes and left on forever.
Quoted 7 lines
I can't see why that part of the system can't be shut down, provided that inputs are also isolated correctly when the regulator is disabled etc.
The data sheet says that input can execeed VDD / VDDOUT provide clamp current ratings are observed.It is also seems permissible to disable Vddout independently of Vdd (for some variants).
Sounds like it's all fine then. Just document it in the binding and it should be fine to add.