pbias regulator fixes
cover pbias regulator fixes
Patch series contains a couple of fixes. One that disables pbias properly (write the correct value to disable regulator instead of writing 0). And the other is to get the correct address to enable/disable the pbias regulator.
Tested on DRA7 (tests pbias_mmc_omap5) and OMAP5 panda (tests pbias_mmc_omap4).
Kishon Vijay Abraham I (2):
regulator: pbias: use untranslated address to program pbias regulator
regulator: pbias: Fix broken pbias disable functionality
drivers/regulator/pbias-regulator.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 regulator: pbias: use untranslated address to program pbias regulator
vsel_reg and enable_reg of the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node is moved as a child node of syscon, vsel_reg and enable_reg has the absolute address because of the address translation that happens while creating device from device tree node.
So avoid using platform_get_resource and use of_get_address in order to get only the offset (untranslated address) and populate these in vsel_reg and enable_reg.
--- drivers/regulator/pbias-regulator.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/regulator/pbias-regulator.c +11 -5
@@ -22,6 +22,7 @@#include <linux/regulator/driver.h> #include <linux/regulator/machine.h> #include <linux/regulator/of_regulator.h> +#include <linux/of_address.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/of.h>
@@ -108,12 +109,14 @@ static int pbias_regulator_probe(struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;struct pbias_regulator_data *drvdata; -struct resource *res;struct regulator_config cfg = { };struct regmap *syscon;const struct pbias_reg_info *info;int ret =0 ;int count, idx, data_idx =0 ; +const __be32 *addrp; +int ns; +unsigned int reg; count =of_regulator_match (&pdev->dev, np, pbias_matches,PBIAS_NUM_REGS );
@@ -141,10 +144,13 @@ static int pbias_regulator_probe(struct platform_device *pdev)if (!info)return -ENODEV ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) + addrp =of_get_address (np,0 ,NULL ,NULL ); +if (!addrp)return -EINVAL ; + ns =of_n_size_cells (np); + reg =of_read_number (addrp, ns); + drvdata[data_idx].syscon = syscon; drvdata[data_idx].info = info; drvdata[data_idx].desc.name = info->name;
@@ -154,9 +160,9 @@ static int pbias_regulator_probe(struct platform_device *pdev) drvdata[data_idx].desc.volt_table = pbias_volt_table; drvdata[data_idx].desc.n_voltages =2 ; drvdata[data_idx].desc.enable_time = info->enable_time; - drvdata[data_idx].desc.vsel_reg = res->start; + drvdata[data_idx].desc.vsel_reg = reg; drvdata[data_idx].desc.vsel_mask = info->vmode; - drvdata[data_idx].desc.enable_reg = res->start; + drvdata[data_idx].desc.enable_reg = reg; drvdata[data_idx].desc.enable_mask = info->enable_mask; drvdata[data_idx].desc.enable_val = info->enable;
Signature · 1 line
1.7.9.5
PATCH 2/2 regulator: pbias: Fix broken pbias disable functionality
In reply to Kishon Vijay Abraham Iregulator_disable of pbias always writes '0' to the enable_reg. However actual disable value of pbias regulator is not always '0'. Fix it by populating the disable_val in pbias_reg_info for the various platforms and assign it to the disable_val of pbias regulator descriptor. This will be used by regulator_disable_regmap while disabling pbias regulator.
--- drivers/regulator/pbias-regulator.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/regulator/pbias-regulator.c +5 -0
@@ -31,6 +31,7 @@struct pbias_reg_info {u32 enable;u32 enable_mask; +u32 disable_val;u32 vmode;unsigned int enable_time;char *name;
@@ -63,6 +64,7 @@ static const struct pbias_reg_info pbias_mmc_omap2430 = { .enable = BIT(1), .enable_mask = BIT(1), .vmode = BIT(0), + .disable_val = 0, .enable_time = 100, .name = "pbias_mmc_omap2430" };
@@ -78,6 +80,7 @@ static const struct pbias_reg_info pbias_sim_omap3 = {static const struct pbias_reg_info pbias_mmc_omap4 = { .enable =BIT (26 ) |BIT (22 ), .enable_mask =BIT (26 ) |BIT (25 ) |BIT (22 ), + .disable_val =BIT (25 ), .vmode =BIT (21 ), .enable_time =100 , .name ="pbias_mmc_omap4"
@@ -86,6 +89,7 @@ static const struct pbias_reg_info pbias_mmc_omap4 = {static const struct pbias_reg_info pbias_mmc_omap5 = { .enable =BIT (27 ) |BIT (26 ), .enable_mask =BIT (27 ) |BIT (25 ) |BIT (26 ), + .disable_val =BIT (25 ), .vmode =BIT (21 ), .enable_time =100 , .name ="pbias_mmc_omap5"
@@ -165,6 +169,7 @@ static int pbias_regulator_probe(struct platform_device *pdev) drvdata[data_idx].desc.enable_reg = reg; drvdata[data_idx].desc.enable_mask = info->enable_mask; drvdata[data_idx].desc.enable_val = info->enable; + drvdata[data_idx].desc.disable_val = info->disable_val; cfg.init_data = pbias_matches[idx].init_data; cfg.driver_data = &drvdata[data_idx];
Signature · 1 line
1.7.9.5
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
In reply to Kishon Vijay Abraham IQuoted 9 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node is moved as a child node of syscon,vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
Quoted 3 lines
Cc <[email protected]>Cc Tero Kristo <[email protected]>Signed-off-by Kishon Vijay Abraham I <[email protected]>
For dra7-evm:
Signature · 2 lines
regards, -grygorii
Tony Lindgren
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
In reply to Kishon Vijay Abraham IQuoted 8 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node is moved as a child node of syscon,vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
I think this gets fixed automatically with your other series adding the "simple-bus" to the nodes. For the children of_ioremap and friends should do the right thing, but without help from the bus things won't work right without "simple-bus".
Regards,
Tony
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Hi Tony,
Quoted 10 lines · Tony Lindgren
Quoted 8 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node is moved as a child node of syscon,vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
Quoted 2 lines
I think this gets fixed automatically with your other series adding the "simple-bus" to the nodes. For the children
of_ioremap
Nope. The probe of pbias regulator fails as Grygorii has already pointed out here [1].
Thanks
Kishon
[1] -> http://www.spinics.net/lists/linux-omap/msg120462.html
Tony Lindgren
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 13 lines · Kishon Vijay Abraham I
Hi Tony,
Quoted 10 lines · Tony Lindgren
Quoted 8 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node is moved as a child node of syscon,vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
Quoted 5 lines
Quoted 2 lines
I think this gets fixed automatically with your other series adding the "simple-bus" to the nodes. For the children
of_ioremapNope. The probe of pbias regulator fails as Grygorii has already pointed out here [1].
Oh I see, you want the offset from syscon, not the virtual address of the register. Yeah then it makes sense to me. You could also get the offset by doing res->start & 0xff or something but I don't know if that's any better. I guess ideallly we'd have some syscon function to get the offest from the syscon base if it does not exist already.
Regards,
Tony
Quoted 1 line
[1] -> http://www.spinics.net/lists/linux-omap/msg120462.html
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 17 lines · Tony Lindgren
Quoted 16 lines · Kishon Vijay Abraham I
Hi Tony,
Quoted 12 lines · Tony Lindgren
Quoted 8 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node is moved as a child node of syscon,vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.I think this gets fixed automatically with your other series adding the "simple-bus" to the nodes. For the children
of_ioremap
Quoted 8 lines
Quoted 2 lines
Nope. The probe of pbias regulator fails as Grygorii has already pointed out here [1].
Oh I see, you want the offset from syscon, not the virtual address of the register. Yeah then it makes sense to me. You could also get the offset by doing
res->start&0xffor something but I don't know if that's any better. I guess ideallly we'd have some syscon function to get the offest from the syscon base if it does not exist already.
Hypothetically, the "syscon" property can be used to get register offset syscon = <&scm_conf 0xe00>;
and even "reg" property can be dropped if driver uses syscon/regmap only for io.
But, in this particular case, such change will lead to DT compatibility issues :(
Signature · 2 lines
regards, -grygorii
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
In reply to Kishon Vijay Abraham IQuoted 2 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree node
I'm having a hard time understanding this statement, sorry. What makes you say that they "shouild actually have the offset from syscon"? What is the problem that this is supposed to fix?
Quoted 6 lines
is moved as a child node of syscon,
vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
This sounds like we're going in the wrong direction, we're moving from a more generic API to a firmware specific one. Why is this a good fix?
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Hi Mark Brown,
Quoted 8 lines · Mark Brown
Quoted 2 lines · Kishon Vijay Abraham I
vsel_regandenable_regof the pbias regulator descriptor should actually have the offset from syscon. However after the pbias device tree nodeI'm having a hard time understanding this statement, sorry. What makes you say that they "shouild actually have the offset from syscon"? What is the problem that this is supposed to fix?
The register to program pbias regulator is 0x4A002E00. The syscon base address is 0x4a002000. So the vsel_reg and enable_reg should have the offset from syscon base address. regulator_enable_regmap gets the base address from 'regmap' and offset from 'enable_reg' in order to program the pbias regulator.
But without this patch vsel_reg and enable_reg have the absolute address instead of just the offset.
Quoted 10 lines
Quoted 7 lines
is moved as a child node of syscon,
vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.This sounds like we're going in the wrong direction, we're moving from a more generic API to a firmware specific one. Why is this a good fix?
platform_get_resource can be used if we need the absolute address but here we need only the offset.
Thanks
Kishon
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 10 lines · Kishon Vijay Abraham I
Quoted 8 lines · Mark Brown
Quoted 6 lines · Kishon Vijay Abraham I
is moved as a child node of syscon,
vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
Quoted 5 lines
Quoted 2 lines
This sounds like we're going in the wrong direction, we're moving from a more generic API to a firmware specific one. Why is this a good fix?
platform_get_resourcecan be used if we need the absolute address but here we need only the offset.
So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that. What you're saying above is pretty much "this happens to work" but my concern is that the solution that happens to work isn't really what we want to do.
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Hi Mark Brown,
Quoted 11 lines · Mark Brown
Quoted 9 lines · Kishon Vijay Abraham I
Quoted 8 lines · Mark Brown
Quoted 6 lines · Kishon Vijay Abraham I
is moved as a child node of syscon,
vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This sounds like we're going in the wrong direction, we're moving from a more generic API to a firmware specific one. Why is this a good fix?
platform_get_resourcecan be used if we need the absolute address but here we need only the offset.So substract this address from the start of the resource to get the
That would mean from the offset (provided in dt) get the absolute address and then again from the absolute address get the offset.
Quoted 1 line
offset? Or provide a wrapper function in the resource code which does
Why not use 'of_get_address' which does the same thing? Moreover it's not a resource we are dealing with here. It's a resource only for the syscon driver.
Quoted 3 lines
that. What you're saying above is pretty much "this happens to work" but my concern is that the solution that happens to work isn't really what we want to do.
Not just makes this work, this is also the most reasonable solution available IMHO.
The most ideal way would have been to use something like what Grygorii mentioned to use syscon = <&scm_conf 0xe00> and then use the phandle to get the offset. But then with this we'll be breaking older dtbs.
Thanks
Kishon
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 2 lines · Kishon Vijay Abraham I
Quoted 1 line · Mark Brown
On Tue, Aug 18, 2015 at 11:23:54AM +0530, Kishon Vijay Abraham I wrote:
Please fix your mail client to word wrap within paragraphs.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
platform_get_resourcecan be used if we need the absolute address but here we need only the offset.So substract this address from the start of the resource to get the
That would mean from the offset (provided in dt) get the absolute address and then again from the absolute address get the offset.
Sure, that's how the Linux APIs work right now and why I'm suggesting you might want a wrapper.
Quoted 4 lines
Quoted 1 line
offset? Or provide a wrapper function in the resource code which does
Why not use '
of_get_address' which does the same thing? Moreover it's not a resource we are dealing with here. It's a resource only for the syscon driver.
This is how the OF description you've done is intended to be parsed and hence is interpreted by the generic code, it's just a detail of the syscon implementation that you need to translate it into an offset.
Quoted 5 lines
Quoted 3 lines
that. What you're saying above is pretty much "this happens to work" but my concern is that the solution that happens to work isn't really what we want to do.
Not just makes this work, this is also the most reasonable solution available IMHO.
In general moving to a lower level inteface is not usually a step forward. As far as I can tell the driver already has all the information it needs from the more generic APIs, it's just not interpreting it in the way that the APIs it's trying to use wants. It just needs to fix the way it interprets the data it's passing through.
Quoted 3 lines
The most ideal way would have been to use something like what Grygorii mentioned to use syscon = <
&scm_conf0xe00> and then use the phandle to get the offset. But then with this we'll be breaking older dtbs.
There is no need to break older DTs, that would clearly be a bad idea.
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
In reply to Mark BrownHi Mark,
Quoted 14 lines · Mark Brown
Quoted 12 lines · Kishon Vijay Abraham I
Quoted 11 lines · Mark Brown
Quoted 6 lines · Kishon Vijay Abraham I
is moved as a child node of syscon,
vsel_regandenable_reghas the absolute address because of the address translation that happens while creating device from device tree node.
So avoid usingplatform_get_resourceand useof_get_addressin order to get only the offset (untranslated address) and populate these invsel_regandenable_reg.This sounds like we're going in the wrong direction, we're moving from a more generic API to a firmware specific one. Why is this a good fix?
Quoted 6 lines
Quoted 2 lines
platform_get_resourcecan be used if we need the absolute address but here we need only the offset.So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that.
I'd be very appreciated if you have and can share any thought on How can we get this absolute base address to substract?
Below is what we have in DT:
l4_cfg: l4@4a000000 {
compatible = "ti,dra7-l4-cfg", "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0 0x4a000000 0x22c000>;
[GS] <=== 0x4a000000 is our top level l4 base address
scm: scm@2000 {
compatible = "ti,dra7-scm-core", "simple-bus";
reg = <0x2000 0x2000>;
#address-cells = <1>;
#size-cells = <1>;
ranges = <0 0x2000 0x2000>;
[GS] <=== 0x4a002000 is our scm-core base address
IORESOURCE_MEM: 0x4a002000 : 4A003FFF
scm_conf: scm_conf@0 {
compatible = "syscon", "simple-bus";
reg = <0x0 0x1400>;
#address-cells = <1>;
#size-cells = <1>;
[GS] <=== 0x4a002000 is our syscon base address
IORESOURCE_MEM: 0x4a002000 : 4A0033FF
pbias_regulator: pbias_regulator {
compatible = "ti,pbias-omap";
reg = <0xe00 0x4>;
[GS] <=== 0x4a002E00 is our pbias base address
IORESOURCE_MEM: 0x4a002E00 : 4A002E03
Here we should use reg_offset=0xE00 as input parameter for regmap APIs.
syscon = <&scm_conf>;
pbias_mmc_reg: pbias_mmc_omap5 {
regulator-name = "pbias_mmc_omap5";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <3000000>;
};
};
scm_conf_clocks: clocks {
#address-cells = <1>;
#size-cells = <0>;
};
};As I understood, all of_address APIs/code is designed to parse/translate addresses in top-bottom direction, and it looks nontrivial to get any kind of base addresses from driver's side (except of its own address), because it will require reverse DT parsing in bottom-top direction. Maybe I missed smth?
Signature · 2 lines
regards, -grygorii
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 8 lines · Grygorii Strashko
Quoted 3 lines · Mark Brown
So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that.
I'd be very appreciated if you have and can share any thought on How can we get this absolute base address to substract?
Ask the syscon device for its resource? Or have it provide an absolute address based interface for that matter?
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Hi Mark,
Quoted 11 lines · Mark Brown
Quoted 8 lines · Grygorii Strashko
Quoted 3 lines · Mark Brown
So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that.
I'd be very appreciated if you have and can share any thought on How can we get this absolute base address to substract?
Ask the syscon device for its resource? Or have it provide an absolute
Even if we get the absolute address of syscon, we have to do the subtraction only for the newer dtbs (previous dtbs already have only the offset). Do you recommend adding a new property to differentiate between older dtbs and newer dtbs? Any other suggestions here?
Quoted 1 line
address based interface for that matter?
Syscon doesn't directly expose any API's to write to it's register. Rather it uses regmap APIs to read/write to it's register. I'm not sure if it's possible to add regmap APIs to write to a register with absolute address. Any hints?
Thanks
Kishon
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 11 lines · Kishon Vijay Abraham I
Quoted 10 lines · Mark Brown
Quoted 8 lines · Grygorii Strashko
Quoted 3 lines · Mark Brown
So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that.
I'd be very appreciated if you have and can share any thought on How can we get this absolute base address to substract?
Quoted 6 lines
Quoted 1 line
Ask the syscon device for its resource? Or have it provide an absolute
Even if we get the absolute address of syscon, we have to do the subtraction only for the newer dtbs (previous dtbs already have only the offset). Do you recommend adding a new property to differentiate between older dtbs and newer dtbs? Any other suggestions here?
Hang on. This is the first I've heard of any DTs not just having absolute addresses. How does any of this work - has it ever worked, and is the situation completely understood? My original concern with this was that I coudn't understand the commit log and your original response seemed to indicate that we always have the absolute address :( Perhaps this is something to do with the brief mention of having moved the DT node for some reason?
We at least need some sort of coherent explanation of the problem and a comprehensible fix to go with it. Right now it seems like things are just being moved about to hide problems without either of these things which seems like it makes the code less clear and more fragile.
Quoted 6 lines
Quoted 1 line
address based interface for that matter?
Syscon doesn't directly expose any API's to write to it's register. Rather it uses regmap APIs to read/write to it's register. I'm not sure if it's possible to add regmap APIs to write to a register with absolute address. Any hints?
Yes, I'm aware that it is regmap based! What I am suggesting is that if people are making DTs like yours with devices that are children of the syscon then presumably it might be useful for it to allow client drivers to pass absolute addresses in so that it can translate for them.
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Hi Mark,
Quoted 14 lines · Mark Brown
Quoted 13 lines · Kishon Vijay Abraham I
Quoted 11 lines · Mark Brown
Quoted 8 lines · Grygorii Strashko
Quoted 3 lines · Mark Brown
So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that.
I'd be very appreciated if you have and can share any thought on How can we get this absolute base address to substract?
Ask the syscon device for its resource? Or have it provide an absolute
Quoted 8 lines
Quoted 4 lines
Even if we get the absolute address of syscon, we have to do the subtraction only for the newer dtbs (previous dtbs already have only the offset). Do you recommend adding a new property to differentiate between older dtbs and newer dtbs? Any other suggestions here?
Hang on. This is the first I've heard of any DTs not just having absolute addresses. How does any of this work - has it ever worked, and is the situation completely understood? My original concern with this
Before commit d919501feffa8715147582c3ffce96fad0c7016f ARM: dts: dra7:
add minimal l4 bus layout with control module support, the dt was like
ocp {
dra7_ctrl_general: tisyscon@4a002e00 {
compatible = "syscon";
reg = <0x4a002e00 0x7c>;
};
pbias_regulator: pbias_regulator {
compatible = "ti,pbias-omap";
reg = <0 0x4>;
syscon = <&dra7_ctrl_general>;
};
};Here platform_get_resource in pbias driver returns '0' which is populated in vsel_reg and enable_reg. And regulator_enable_regmap uses the base address from tisyscon@4a002e00 which is '0x4a002e00' and offset from enable_reg which is '0' inorder to write to the pbias register.
But after commit d919501fef, the dt became like this (after a couple of fixes)
ocp {
l4_cfg: l4@4a000000 {
compatible = "ti,dra7-l4-cfg", "simple-bus";
ranges = <0 0x4a000000 0x22c000>;
scm: scm@2000 {
compatible = "ti,dra7-scm-core", "simple-bus";
reg = <0x2000 0x2000>;
ranges = <0 0x2000 0x2000>;
scm_conf: scm_conf@0 {
compatible = "syscon", "simple-bus";
reg = <0x0 0x1400>;
ranges = <0 0x0 0x1400>;
pbias_regulator: pbias_regulator {
compatible = "ti,pbias-omap";
reg = <0xe00 0x4>;
syscon = <&scm_conf>;
};
};
};
};
};Here platform_get_resource in pbias driver returns '4a002e00' which is populated in vsel_reg and enable_reg. And regulator_enable_regmap uses the base address from scm_conf@0 which is '0x4a002000' and offset from enable_reg which is '4a002e00' inorder to write to the pbias register and it results in a abort.
Quoted 2 lines
was that I coudn't understand the commit log and your original response seemed to indicate that we always have the absolute address :( Perhaps
We started having the absolute address only after the dt change (commit d919501fef and a couple of more dt fixes).
Quoted 7 lines
this is something to do with the brief mention of having moved the DT node for some reason?
We at least need some sort of coherent explanation of the problem and a comprehensible fix to go with it. Right now it seems like things are just being moved about to hide problems without either of these things which seems like it makes the code less clear and more fragile.
hmm.. IMO the actual problem was modelling the 'offset' as a resource (by populating the offset in 'reg' property) which was added when the initial pbias dt node was created. And now since the pbias dt node is being moved around, it's causing inadvertent address translation breaking the pbias driver. IMHO the value in 'reg' property of pbias dt node should be treated as 'offset' instead of address 'resource' and that's what my patch tried to do.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
address based interface for that matter?
Syscon doesn't directly expose any API's to write to it's register. Rather it uses regmap APIs to read/write to it's register. I'm not sure if it's possible to add regmap APIs to write to a register with absolute address. Any hints?
Quoted 4 lines
Yes, I'm aware that it is regmap based! What I am suggesting is that if people are making DTs like yours with devices that are children of the syscon then presumably it might be useful for it to allow client drivers to pass absolute addresses in so that it can translate for them.
Arnd, Lee?
Thanks
Kishon
Re: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Now fixed Lee Jones mail address!
Quoted 120 lines · Kishon Vijay Abraham I
Hi Mark,
Quoted 14 lines · Mark Brown
Quoted 13 lines · Kishon Vijay Abraham I
Quoted 11 lines · Mark Brown
Quoted 8 lines · Grygorii Strashko
Quoted 3 lines · Mark Brown
So substract this address from the start of the resource to get the offset? Or provide a wrapper function in the resource code which does that.
I'd be very appreciated if you have and can share any thought on How can we get this absolute base address to substract?
Ask the syscon device for its resource? Or have it provide an absolute
Quoted 8 lines
Quoted 4 lines
Even if we get the absolute address of syscon, we have to do the subtraction only for the newer dtbs (previous dtbs already have only the offset). Do you recommend adding a new property to differentiate between older dtbs and newer dtbs? Any other suggestions here?
Hang on. This is the first I've heard of any DTs not just having absolute addresses. How does any of this work - has it ever worked, and is the situation completely understood? My original concern with this
Before commit
d919501feffa8715147582c3ffce96fad0c7016fARM: dts: dra7:
add minimal l4 bus layout with control module support, the dt was likeocp { dra7_ctrl_general: tisyscon@4a002e00 { compatible = "syscon"; reg = <0x4a002e00 0x7c>; }; pbias_regulator: pbias_regulator { compatible = "ti,pbias-omap"; reg = <0 0x4>; syscon = <&dra7_ctrl_general>; }; };Here
platform_get_resourcein pbias driver returns '0' which is populated invsel_regandenable_reg. Andregulator_enable_regmapuses the base address from tisyscon@4a002e00 which is '0x4a002e00' and offset fromenable_regwhich is '0' inorder to write to the pbias register.But after commit
d919501fef, the dt became like this (after a couple of fixes)ocp { l4_cfg: l4@4a000000 { compatible = "ti,dra7-l4-cfg", "simple-bus"; ranges = <0 0x4a000000 0x22c000>; scm: scm@2000 { compatible = "ti,dra7-scm-core", "simple-bus"; reg = <0x2000 0x2000>; ranges = <0 0x2000 0x2000>; scm_conf: scm_conf@0 { compatible = "syscon", "simple-bus"; reg = <0x0 0x1400>; ranges = <0 0x0 0x1400>; pbias_regulator: pbias_regulator { compatible = "ti,pbias-omap"; reg = <0xe00 0x4>; syscon = <&scm_conf>; }; }; }; }; };Here
platform_get_resourcein pbias driver returns '4a002e00' which is populated invsel_regandenable_reg. Andregulator_enable_regmapuses the base address from scm_conf@0 which is '0x4a002000' and offset fromenable_regwhich is '4a002e00' inorder to write to the pbias register and it results in a abort.Quoted 2 lines
was that I coudn't understand the commit log and your original response seemed to indicate that we always have the absolute address :( Perhaps
We started having the absolute address only after the dt change (commit
d919501fefand a couple of more dt fixes).Quoted 7 lines
this is something to do with the brief mention of having moved the DT node for some reason?
We at least need some sort of coherent explanation of the problem and a comprehensible fix to go with it. Right now it seems like things are just being moved about to hide problems without either of these things which seems like it makes the code less clear and more fragile.
hmm.. IMO the actual problem was modelling the 'offset' as a resource (by populating the offset in 'reg' property) which was added when the initial pbias dt node was created. And now since the pbias dt node is being moved around, it's causing inadvertent address translation breaking the pbias driver. IMHO the value in 'reg' property of pbias dt node should be treated as 'offset' instead of address 'resource' and that's what my patch tried to do.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
address based interface for that matter?
Syscon doesn't directly expose any API's to write to it's register. Rather it uses regmap APIs to read/write to it's register. I'm not sure if it's possible to add regmap APIs to write to a register with absolute address. Any hints?
Quoted 4 lines
Yes, I'm aware that it is regmap based! What I am suggesting is that if people are making DTs like yours with devices that are children of the syscon then presumably it might be useful for it to allow client drivers to pass absolute addresses in so that it can translate for them.
Arnd, Lee?
Thanks
Kishon
Tony Lindgren
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
In reply to Kishon Vijay Abraham IHi,
I think the fix is rather easy here.. See below.
Quoted 4 lines · Kishon Vijay Abraham I
Before commit
d919501feffa8715147582c3ffce96fad0c7016fARM: dts: dra7:
add minimal l4 bus layout with control module support, the dt was like
Quoted 12 lines
ocp {
dra7_ctrl_general: tisyscon@4a002e00 {
compatible = "syscon";
reg = <0x4a002e00 0x7c>;
};
pbias_regulator: pbias_regulator {
compatible = "ti,pbias-omap";
reg = <0 0x4>;
syscon = <&dra7_ctrl_general>;
};
};Yes the reg = <0 0x4> above is wrong, it's not an offset from the ocp but from the syscon base.
Quoted 19 lines
But after commit
d919501fef, the dt became like this (after a couple of fixes)ocp { l4_cfg: l4@4a000000 { compatible = "ti,dra7-l4-cfg", "simple-bus"; ranges = <0 0x4a000000 0x22c000>; scm: scm@2000 { compatible = "ti,dra7-scm-core", "simple-bus"; reg = <0x2000 0x2000>; ranges = <0 0x2000 0x2000>; scm_conf: scm_conf@0 { compatible = "syscon", "simple-bus"; reg = <0x0 0x1400>; ranges = <0 0x0 0x1400>; pbias_regulator: pbias_regulator {
Quoted 8 lines
compatible = "ti,pbias-omap";
reg = <0xe00 0x4>;
syscon = <&scm_conf>;
};
};
};
};
};And here we properly describe the hardware interconnect layout and of_ioremap and friends do the right thing. And reg = <0xxe00 0x4> is correct offset from the scm_conf base.
Why don't you just make reg unused for pbias_regulator since we already use regmap for this driver?
Then in the pbias driver just define the register offset from the syscon base? You may need to set it based on the compatible value, but it's not like it's going to change for SoC.
If we eventually add some API to calculate reg base offset from the syscon base it's easy to update the driver to use that.
Cheers,
Tony
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 10 lines · Tony Lindgren
Why don't you just make reg unused for
pbias_regulatorsince we already use regmap for this driver?Then in the pbias driver just define the register offset from the syscon base? You may need to set it based on the compatible value, but it's not like it's going to change for SoC.
If we eventually add some API to calculate reg base offset from the syscon base it's easy to update the driver to use that.
That'd work. The other thing I was thinking we could do is to get syscon to treat any excessively large address that gets passed in that looks like an absolute address appropriately.
Tony Lindgren
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 9 lines · Mark Brown
Quoted 6 lines · Tony Lindgren
Why don't you just make reg unused for
pbias_regulatorsince we already use regmap for this driver?Then in the pbias driver just define the register offset from the syscon base? You may need to set it based on the compatible value, but it's not like it's going to change for SoC.
Quoted 7 lines
Quoted 3 lines
If we eventually add some API to calculate reg base offset from the syscon base it's easy to update the driver to use that.
That'd work. The other thing I was thinking we could do is to get syscon to treat any excessively large address that gets passed in that looks like an absolute address appropriately.
Hmm wouldn't that get messy for 64-bit :) How about something like:
unsigned long syscon_regmap_get_offset(struct regmap *syscon,
void __iomem *base)
Not sure if that's something that some drivers would start to misuse with read/writel though.. Presumably not if the driver already is using syscon.
Regards,
Tony
Mark Brown
maintainerRe: [PATCH 1/2] regulator: pbias: use untranslated address to program pbias regulator
Quoted 8 lines · Tony Lindgren
Quoted 3 lines · Mark Brown
That'd work. The other thing I was thinking we could do is to get syscon to treat any excessively large address that gets passed in that looks like an absolute address appropriately.
Hmm wouldn't that get messy for 64-bit :) How about something like:
Meh, it'd probably be fine - I was thinking falling back to trying to substract the base address if the passed address was out of bounds. It's not super elegant though, something that directly does the right thing would be better.
Quoted 6 lines
unsigned long syscon_regmap_get_offset(struct regmap *syscon,
void__iomem*base)Not sure if that's something that some drivers would start to misuse with read/writel though.. Presumably not if the driver already is using syscon.
It should be really easy to spot abuse I'd hope.