* [PATCHv2 0/3] add DT endianness binding support @ 2014-04-23 6:46 Xiubo Li 2014-04-23 6:46 ` [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness Xiubo Li ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Xiubo Li @ 2014-04-23 6:46 UTC (permalink / raw) To: broonie, rob Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, linux-doc, linux-kernel, Xiubo Li Change in V2: - Namespace the properties using the prefix sring. - Add one binding ducomentation off regmap. Xiubo Li (3): dt/bindings: Add the DT binding documentation for endianness regmap: Add the DT binding documentation for endianness regmap: add DT endianness binding support. .../devicetree/bindings/endianness/endianness.txt | 55 +++++++++++++ .../bindings/regmap/regmap-endianness.txt | 48 +++++++++++ drivers/base/regmap/regmap.c | 96 +++++++++++++++++++--- 3 files changed, 188 insertions(+), 11 deletions(-) create mode 100644 Documentation/devicetree/bindings/endianness/endianness.txt create mode 100644 Documentation/devicetree/bindings/regmap/regmap-endianness.txt -- 1.8.4 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness 2014-04-23 6:46 [PATCHv2 0/3] add DT endianness binding support Xiubo Li @ 2014-04-23 6:46 ` Xiubo Li 2014-04-23 8:34 ` Mark Rutland 2014-04-23 6:46 ` [PATCHv2 2/3] regmap: " Xiubo Li 2014-04-23 6:46 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li 2 siblings, 1 reply; 12+ messages in thread From: Xiubo Li @ 2014-04-23 6:46 UTC (permalink / raw) To: broonie, rob Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, linux-doc, linux-kernel, Xiubo Li Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> --- .../devicetree/bindings/endianness/endianness.txt | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/endianness/endianness.txt diff --git a/Documentation/devicetree/bindings/endianness/endianness.txt b/Documentation/devicetree/bindings/endianness/endianness.txt new file mode 100644 index 0000000..64f1d5e --- /dev/null +++ b/Documentation/devicetree/bindings/endianness/endianness.txt @@ -0,0 +1,55 @@ +Device-Tree binding for device endianness + +The endianness mode of CPU & Device scenarios: + Index CPU Device + ------------------------ + 1 LE LE + 2 LE BE + 3 BE BE + 4 BE LE + +For one device driver, which will run in different scenarios above +on different SoCs using the devicetree, we need one way to simplify +this. + +Required properties: +- [prefix]-endian: this is one string property and must be one + of 'be', 'le' and 'native' if it is present. + +The endianness mode: + 'le' : device is in little endian mode, + 'be' : device is in big endian mode, + 'native' : device is in the same endian mode with the CPU. + +Examples: +Scenario 1 : CPU in LE mode & device in LE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + [prefix]-endian = 'native'; +}; + +Scenario 2 : CPU in LE mode & device in BE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + [prefix]-endian = 'be'; +}; + +Scenario 3 : CPU in BE mode & device in BE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + [prefix]-endian = 'native'; +}; + +Scenario 4 : CPU in BE mode & device in LE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + [prefix]-endian = 'le'; +}; -- 1.8.4 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness 2014-04-23 6:46 ` [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness Xiubo Li @ 2014-04-23 8:34 ` Mark Rutland 2014-04-30 5:08 ` Li.Xiubo 0 siblings, 1 reply; 12+ messages in thread From: Mark Rutland @ 2014-04-23 8:34 UTC (permalink / raw) To: Xiubo Li Cc: broonie, rob, robh+dt, Pawel Moll, ijc+devicetree, galak, linux-doc, linux-kernel On Wed, Apr 23, 2014 at 07:46:33AM +0100, Xiubo Li wrote: > Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> > --- > .../devicetree/bindings/endianness/endianness.txt | 55 ++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > create mode 100644 Documentation/devicetree/bindings/endianness/endianness.txt > > diff --git a/Documentation/devicetree/bindings/endianness/endianness.txt b/Documentation/devicetree/bindings/endianness/endianness.txt > new file mode 100644 > index 0000000..64f1d5e > --- /dev/null > +++ b/Documentation/devicetree/bindings/endianness/endianness.txt > @@ -0,0 +1,55 @@ > +Device-Tree binding for device endianness > + > +The endianness mode of CPU & Device scenarios: > + Index CPU Device > + ------------------------ > + 1 LE LE > + 2 LE BE > + 3 BE BE > + 4 BE LE > + > +For one device driver, which will run in different scenarios above > +on different SoCs using the devicetree, we need one way to simplify > +this. > + > +Required properties: > +- [prefix]-endian: this is one string property and must be one > + of 'be', 'le' and 'native' if it is present. What exactly is the prefix? This file name and file heading implies this is a common endianness binding, which it is not. There are many existing bindings that have mechanisms for describing the endianness of components, and they have settled on a different pattern. We already have many bindings with {big,little}-endian{,-*} boolean properties. It would be better to take that common case and document that as the standard way of doing things rather than inventing a completely different mechanism. > +The endianness mode: > + 'le' : device is in little endian mode, > + 'be' : device is in big endian mode, > + 'native' : device is in the same endian mode with the CPU. What exactly do you mean by native? A device which always matches the endianness of the CPU even if it changes? How common is that? > + > +Examples: > +Scenario 1 : CPU in LE mode & device in LE mode. > +dev: dev@40031000 { > + compatible = "name"; > + reg = <0x40031000 0x1000>; > + ... > + [prefix]-endian = 'native'; > +}; If the device is LE, then surely we should describe the device as LE. The kernel knows what endianness it is, might choose to change the CPU endianness, but regardless can do the right thing. Telling it a device is native is useless unless the device changes endianness with the CPU. > + > +Scenario 2 : CPU in LE mode & device in BE mode. > +dev: dev@40031000 { > + compatible = "name"; > + reg = <0x40031000 0x1000>; > + ... > + [prefix]-endian = 'be'; > +}; > + > +Scenario 3 : CPU in BE mode & device in BE mode. > +dev: dev@40031000 { > + compatible = "name"; > + reg = <0x40031000 0x1000>; > + ... > + [prefix]-endian = 'native'; > +}; Likewise. Thanks, Mark. ^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness 2014-04-23 8:34 ` Mark Rutland @ 2014-04-30 5:08 ` Li.Xiubo 0 siblings, 0 replies; 12+ messages in thread From: Li.Xiubo @ 2014-04-30 5:08 UTC (permalink / raw) To: Mark Rutland Cc: broonie, rob, robh+dt, Pawel Moll, ijc+devicetree, galak, linux-doc, linux-kernel > > diff --git a/Documentation/devicetree/bindings/endianness/endianness.txt > b/Documentation/devicetree/bindings/endianness/endianness.txt > > new file mode 100644 > > index 0000000..64f1d5e > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/endianness/endianness.txt > > @@ -0,0 +1,55 @@ > > +Device-Tree binding for device endianness > > + > > +The endianness mode of CPU & Device scenarios: > > + Index CPU Device > > + ------------------------ > > + 1 LE LE > > + 2 LE BE > > + 3 BE BE > > + 4 BE LE > > + > > +For one device driver, which will run in different scenarios above > > +on different SoCs using the devicetree, we need one way to simplify > > +this. > > + > > +Required properties: > > +- [prefix]-endian: this is one string property and must be one > > + of 'be', 'le' and 'native' if it is present. > > What exactly is the prefix? > > This file name and file heading implies this is a common endianness > binding, which it is not. There are many existing bindings that have > mechanisms for describing the endianness of components, and they have > settled on a different pattern. > > We already have many bindings with {big,little}-endian{,-*} boolean > properties. It would be better to take that common case and document > that as the standard way of doing things rather than inventing a > completely different mechanism. > Well, yes, I'll follow your advice. > > +The endianness mode: > > + 'le' : device is in little endian mode, > > + 'be' : device is in big endian mode, > > + 'native' : device is in the same endian mode with the CPU. > > What exactly do you mean by native? A device which always matches the > endianness of the CPU even if it changes? How common is that? > It's originally based the regmap, and the 'native' is make no sense here, I'll reconstruct this. > > + > > +Examples: > > +Scenario 1 : CPU in LE mode & device in LE mode. > > +dev: dev@40031000 { > > + compatible = "name"; > > + reg = <0x40031000 0x1000>; > > + ... > > + [prefix]-endian = 'native'; > > +}; > > If the device is LE, then surely we should describe the device as LE. > The kernel knows what endianness it is, might choose to change the CPU > endianness, but regardless can do the right thing. Telling it a device > is native is useless unless the device changes endianness with the CPU. > Yes, you are right. > > + > > +Scenario 2 : CPU in LE mode & device in BE mode. > > +dev: dev@40031000 { > > + compatible = "name"; > > + reg = <0x40031000 0x1000>; > > + ... > > + [prefix]-endian = 'be'; > > +}; > > + > > +Scenario 3 : CPU in BE mode & device in BE mode. > > +dev: dev@40031000 { > > + compatible = "name"; > > + reg = <0x40031000 0x1000>; > > + ... > > + [prefix]-endian = 'native'; > > +}; > > Likewise. > > Thanks, > Mark. > ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv2 2/3] regmap: Add the DT binding documentation for endianness 2014-04-23 6:46 [PATCHv2 0/3] add DT endianness binding support Xiubo Li 2014-04-23 6:46 ` [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness Xiubo Li @ 2014-04-23 6:46 ` Xiubo Li 2014-04-23 8:40 ` Mark Rutland 2014-04-23 6:46 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li 2 siblings, 1 reply; 12+ messages in thread From: Xiubo Li @ 2014-04-23 6:46 UTC (permalink / raw) To: broonie, rob Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, linux-doc, linux-kernel, Xiubo Li Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> --- .../bindings/regmap/regmap-endianness.txt | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/regmap/regmap-endianness.txt diff --git a/Documentation/devicetree/bindings/regmap/regmap-endianness.txt b/Documentation/devicetree/bindings/regmap/regmap-endianness.txt new file mode 100644 index 0000000..1d838c5 --- /dev/null +++ b/Documentation/devicetree/bindings/regmap/regmap-endianness.txt @@ -0,0 +1,48 @@ +Device-Tree bindings for regmap endianness + +Required properties: +- regmap-reg-endian: register endianness, see ../endianness/endianness.txt + for detail. +- regmap-val-endian: value endianness, see ../endianness/endianness.txt for + detail. + +The Endianness flags supported by regmap: +DT properties Macros +---------------------------------------- + 'le' REGMAP_ENDIAN_LITTLE + 'be' REGMAP_ENDIAN_BIG + 'native' REGMAP_ENDIAN_NATIVE + Absent REGMAP_ENDIAN_DEFAULT + +Examples for using the regmap-mmio: +Scenario 1 : CPU in LE mode & device in LE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + regmap-val-endian = 'native'; or just absent. +}; + +Scenario 2 : CPU in LE mode & device in BE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + regmap-val-endian = 'be'; +}; + +Scenario 3 : CPU in BE mode & device in BE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + regmap-val-endian = 'native'; or just absent. +}; + +Scenario 4 : CPU in BE mode & device in LE mode. +dev: dev@40031000 { + compatible = "name"; + reg = <0x40031000 0x1000>; + ... + regmap-val-endian = 'le'; +}; -- 1.8.4 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv2 2/3] regmap: Add the DT binding documentation for endianness 2014-04-23 6:46 ` [PATCHv2 2/3] regmap: " Xiubo Li @ 2014-04-23 8:40 ` Mark Rutland 2014-04-28 8:52 ` Li.Xiubo 0 siblings, 1 reply; 12+ messages in thread From: Mark Rutland @ 2014-04-23 8:40 UTC (permalink / raw) To: Xiubo Li Cc: broonie, rob, robh+dt, Pawel Moll, ijc+devicetree, galak, linux-doc, linux-kernel On Wed, Apr 23, 2014 at 07:46:34AM +0100, Xiubo Li wrote: > Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> > --- > .../bindings/regmap/regmap-endianness.txt | 48 ++++++++++++++++++++++ > 1 file changed, 48 insertions(+) > create mode 100644 Documentation/devicetree/bindings/regmap/regmap-endianness.txt > > diff --git a/Documentation/devicetree/bindings/regmap/regmap-endianness.txt b/Documentation/devicetree/bindings/regmap/regmap-endianness.txt > new file mode 100644 > index 0000000..1d838c5 > --- /dev/null > +++ b/Documentation/devicetree/bindings/regmap/regmap-endianness.txt > @@ -0,0 +1,48 @@ > +Device-Tree bindings for regmap endianness As regmap is a Linux internal detail, I don't see why it needs to leak into bindings. > +Required properties: > +- regmap-reg-endian: register endianness, see ../endianness/endianness.txt > + for detail. > +- regmap-val-endian: value endianness, see ../endianness/endianness.txt for I'm not familiar with regmap. What is the difference between register and value endianness? > + detail. > + > +The Endianness flags supported by regmap: > +DT properties Macros > +---------------------------------------- > + 'le' REGMAP_ENDIAN_LITTLE > + 'be' REGMAP_ENDIAN_BIG > + 'native' REGMAP_ENDIAN_NATIVE > + Absent REGMAP_ENDIAN_DEFAULT As mentinoned earlier, I think we should stick to the common convention of device-specific {big,little}-endian{,-*} boolean properties. The common case might just be a simple big-endian property, with LE assumed (or the inverse with a little-endian property). Cheers, Mark. ^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCHv2 2/3] regmap: Add the DT binding documentation for endianness 2014-04-23 8:40 ` Mark Rutland @ 2014-04-28 8:52 ` Li.Xiubo 0 siblings, 0 replies; 12+ messages in thread From: Li.Xiubo @ 2014-04-28 8:52 UTC (permalink / raw) To: Mark Rutland Cc: broonie, rob, robh+dt, Pawel Moll, ijc+devicetree, galak, linux-doc, linux-kernel > Subject: Re: [PATCHv2 2/3] regmap: Add the DT binding documentation for > endianness > > On Wed, Apr 23, 2014 at 07:46:34AM +0100, Xiubo Li wrote: > > Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> > > --- > > .../bindings/regmap/regmap-endianness.txt | 48 > ++++++++++++++++++++++ > > 1 file changed, 48 insertions(+) > > create mode 100644 Documentation/devicetree/bindings/regmap/regmap- > endianness.txt > > > > diff --git a/Documentation/devicetree/bindings/regmap/regmap-endianness.txt > b/Documentation/devicetree/bindings/regmap/regmap-endianness.txt > > new file mode 100644 > > index 0000000..1d838c5 > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/regmap/regmap-endianness.txt > > @@ -0,0 +1,48 @@ > > +Device-Tree bindings for regmap endianness > > As regmap is a Linux internal detail, I don't see why it needs to leak > into bindings. > > > +Required properties: > > +- regmap-reg-endian: register endianness, see ../endianness/endianness.txt > > + for detail. > > +- regmap-val-endian: value endianness, see ../endianness/endianness.txt for > > I'm not familiar with regmap. What is the difference between register > and value endianness? > Sorry for late, I'm very busy these days. The register endianness here is used for the I2C and SPI protocol, which will Send the register address(which maybe 8-bit or 16-bit) before its values. BRs Xiubo ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv2 3/3] regmap: add DT endianness binding support. 2014-04-23 6:46 [PATCHv2 0/3] add DT endianness binding support Xiubo Li 2014-04-23 6:46 ` [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness Xiubo Li 2014-04-23 6:46 ` [PATCHv2 2/3] regmap: " Xiubo Li @ 2014-04-23 6:46 ` Xiubo Li 2 siblings, 0 replies; 12+ messages in thread From: Xiubo Li @ 2014-04-23 6:46 UTC (permalink / raw) To: broonie, rob Cc: robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak, linux-doc, linux-kernel, Xiubo Li For many drivers which will support rich endianness of CPU<-->Dev need define DT properties by itself without the binding support. The value endianness using regmap-mmio, for example: Index CPU Device Endianess flag for DT property ------------------------------------------------------------ 1 LE LE - 2 LE BE 'big-endian' 3 BE BE - 4 BE LE 'little-endian' ============ Here add DT endianness binding support will define two string properties of the register and value endiannesses: 'regmap-reg-endian' and 'regmap-val-endian'. And the value of them will be: 'le' : REGMAP_ENDIAN_LITTLE 'be' : REGMAP_ENDIAN_BIG 'native' : REGMAP_ENDIAN_NATIVE Absent : REGMAP_ENDIAN_DEFAULT The value endianness for regmap-mmio, for example: Index CPU Device Endianess flag for DT property ------------------------------------------------------------ 1 LE LE 'native' or absent 2 LE BE 'be' 3 BE BE 'native' or absent 4 BE LE 'le' Please see the following documetation for detail usage: Documentation/devicetree/bindings/regmap/regmap-endianness.txt Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> --- drivers/base/regmap/regmap.c | 96 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 8e8cea1..cfc9302 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -15,6 +15,7 @@ #include <linux/export.h> #include <linux/mutex.h> #include <linux/err.h> +#include <linux/of.h> #include <linux/rbtree.h> #include <linux/sched.h> @@ -423,6 +424,81 @@ static void regmap_range_exit(struct regmap *map) } /** + * of_regmap_endian_get_by_name() - Parse and lookup the endianness referenced + * by a device node + * @np: pointer to clock consumer node + * @name: name of consumer's endianness input + * + * This function parses the device endianness property, and uses them to + * determine the endianness of the registers and values. + */ +static int of_regmap_endian_get_by_name(struct device_node *np, + const char *endian_name, + enum regmap_endian *out_endian) +{ + const char *endianness; + int ret; + + if (!out_endian) + return -EINVAL; + + /* Set the default endianness */ + *out_endian = REGMAP_ENDIAN_DEFAULT; + + /* Absent or being to use the flag from config of the drivers */ + if (!of_find_property(np, endian_name, NULL)) + return 0; + + ret = of_property_read_string(np, endian_name, &endianness); + if (ret) + return ret; + + if (!strcmp("le", endianness)) + *out_endian = REGMAP_ENDIAN_LITTLE; + else if (!strcmp("be", endianness)) + *out_endian = REGMAP_ENDIAN_BIG; + else if (!strcmp("native", endianness)) + *out_endian = REGMAP_ENDIAN_NATIVE; + + return 0; +} + +static int of_regmap_get_endian(struct device *dev, + const struct regmap_bus *bus, + const struct regmap_config *config, + const char *endian_name, + enum regmap_endian *out_endian) +{ + int ret; + + if (!out_endian) + return -EINVAL; + + if (dev) { + ret = of_regmap_endian_get_by_name(dev->of_node, endian_name, + out_endian); + if (ret < 0) + return ret; + } + + if (*out_endian != REGMAP_ENDIAN_DEFAULT) + return 0; + + /* + * Parsing the endianness from driver's config + * or bus, this is to be compatible with the + * none DT and the old drivers. + */ + *out_endian = config->reg_format_endian; + if (*out_endian == REGMAP_ENDIAN_DEFAULT) + *out_endian = bus->reg_format_endian_default; + if (*out_endian == REGMAP_ENDIAN_DEFAULT) + *out_endian = REGMAP_ENDIAN_BIG; + + return 0; +} + +/** * regmap_init(): Initialise register map * * @dev: Device that will be interacted with @@ -518,17 +594,15 @@ struct regmap *regmap_init(struct device *dev, map->reg_read = _regmap_bus_read; } - reg_endian = config->reg_format_endian; - if (reg_endian == REGMAP_ENDIAN_DEFAULT) - reg_endian = bus->reg_format_endian_default; - if (reg_endian == REGMAP_ENDIAN_DEFAULT) - reg_endian = REGMAP_ENDIAN_BIG; - - val_endian = config->val_format_endian; - if (val_endian == REGMAP_ENDIAN_DEFAULT) - val_endian = bus->val_format_endian_default; - if (val_endian == REGMAP_ENDIAN_DEFAULT) - val_endian = REGMAP_ENDIAN_BIG; + ret = of_regmap_get_endian(dev, bus, config, "regmap-reg-endian", + ®_endian); + if (ret) + return ERR_PTR(ret); + + ret = of_regmap_get_endian(dev, bus, config, "regmap-val-endian", + &val_endian); + if (ret) + return ERR_PTR(ret); switch (config->reg_bits + map->reg_shift) { case 2: -- 1.8.4 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCHv2 0/3] regmap: add LE and DT binding for endianness @ 2014-04-02 10:09 Xiubo Li 2014-04-02 10:09 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li 0 siblings, 1 reply; 12+ messages in thread From: Xiubo Li @ 2014-04-02 10:09 UTC (permalink / raw) To: broonie; +Cc: linux-doc, linux-kernel, Xiubo Li For this patch series has dependency, so resend them together. Change in v2: - resend 'regmap: implement LE formatting/parsing for 16/32-bit values.' - resend 'regmap: Add the DT binding documentation for endianness' - fix the commit message of 'regmap: add DT endianness binding support.' Xiubo Li (3): regmap: implement LE formatting/parsing for 16/32-bit values. regmap: Add the DT binding documentation for endianness regmap: add DT endianness binding support. .../bindings/regmap/regmap-endianness.txt | 49 +++++++ drivers/base/regmap/regmap.c | 141 +++++++++++++++++++-- 2 files changed, 180 insertions(+), 10 deletions(-) create mode 100644 Documentation/devicetree/bindings/regmap/regmap-endianness.txt -- 1.8.4 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCHv2 3/3] regmap: add DT endianness binding support. 2014-04-02 10:09 [PATCHv2 0/3] regmap: add LE and DT binding for endianness Xiubo Li @ 2014-04-02 10:09 ` Xiubo Li 2014-04-02 19:50 ` Mark Brown 0 siblings, 1 reply; 12+ messages in thread From: Xiubo Li @ 2014-04-02 10:09 UTC (permalink / raw) To: broonie; +Cc: linux-doc, linux-kernel, Xiubo Li For many drivers which will support rich endianness of CPU<-->Dev need define DT properties by itself without the binding support. The value endianness using regmap-mmio, for example: Index CPU Device Endianess flag for DT property ------------------------------------------------------------ 1 LE LE - 2 LE BE 'big-endian' 3 BE BE - 4 BE LE 'little-endian' ============ Here add DT endianness binding support will define two string properties of the register and value endiannesses: 'reg-endian' and 'val-endian'. And the value of them will be: 'LE' : REGMAP_ENDIAN_LITTLE 'BE' : REGMAP_ENDIAN_BIG 'NT' : REGMAP_ENDIAN_NATIVE Absent : REGMAP_ENDIAN_DEFAULT The value endianness using regmap-mmio, for example: Index CPU Device Endianess flag for DT property ------------------------------------------------------------ 1 LE LE 'NT' or absent 2 LE BE 'BE' 3 BE BE 'NT' or absent 4 BE LE 'LE' Please see the following documetation for detail usage: Documentation/devicetree/bindings/regmap/regmap-endianness.txt Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com> --- drivers/base/regmap/regmap.c | 91 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 11 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 8e8cea1..36a96cc 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -15,6 +15,7 @@ #include <linux/export.h> #include <linux/mutex.h> #include <linux/err.h> +#include <linux/of.h> #include <linux/rbtree.h> #include <linux/sched.h> @@ -423,6 +424,78 @@ static void regmap_range_exit(struct regmap *map) } /** + * of_regmap_endian_get_by_name() - Parse and lookup the endianness referenced + * by a device node + * @np: pointer to clock consumer node + * @name: name of consumer's endianness input + * + * This function parses the device endianness property, and uses them to + * determine the endianness of the registers and values. + */ +static int of_regmap_endian_get_by_name(struct device_node *np, + const char *endian_name, + enum regmap_endian *out_endian) +{ + const char *endianness; + int ret; + + if (!out_endian) + return -EINVAL; + + /* Set the default endianness */ + *out_endian = REGMAP_ENDIAN_DEFAULT; + + /* Absent or being to use the flag from config of the drivers */ + if (!of_find_property(np, endian_name, NULL)) + return 0; + + ret = of_property_read_string(np, endian_name, &endianness); + if (ret) + return ret; + + if (!strcmp("LE", endianness)) + *out_endian = REGMAP_ENDIAN_LITTLE; + else if (!strcmp("BE", endianness)) + *out_endian = REGMAP_ENDIAN_BIG; + else if (!strcmp("NT", endianness)) + *out_endian = REGMAP_ENDIAN_NATIVE; + + return 0; +} + +static int of_regmap_get_endian(struct device *dev, + const struct regmap_bus *bus, + const struct regmap_config *config, + const char *endian_name, + enum regmap_endian *out_endian) +{ + int ret; + + if (!out_endian) + return -EINVAL; + + if (dev) { + ret = of_regmap_endian_get_by_name(dev->of_node, endian_name, + out_endian); + if (ret) + return ret; + } + + /* To be compatible with the none DT or the old drivers */ + if (*out_endian != REGMAP_ENDIAN_DEFAULT) + return 0; + + /* Parsing the endianness from driver's config or bus */ + *out_endian = config->reg_format_endian; + if (*out_endian == REGMAP_ENDIAN_DEFAULT) + *out_endian = bus->reg_format_endian_default; + if (*out_endian == REGMAP_ENDIAN_DEFAULT) + *out_endian = REGMAP_ENDIAN_BIG; + + return 0; +} + +/** * regmap_init(): Initialise register map * * @dev: Device that will be interacted with @@ -518,17 +591,13 @@ struct regmap *regmap_init(struct device *dev, map->reg_read = _regmap_bus_read; } - reg_endian = config->reg_format_endian; - if (reg_endian == REGMAP_ENDIAN_DEFAULT) - reg_endian = bus->reg_format_endian_default; - if (reg_endian == REGMAP_ENDIAN_DEFAULT) - reg_endian = REGMAP_ENDIAN_BIG; - - val_endian = config->val_format_endian; - if (val_endian == REGMAP_ENDIAN_DEFAULT) - val_endian = bus->val_format_endian_default; - if (val_endian == REGMAP_ENDIAN_DEFAULT) - val_endian = REGMAP_ENDIAN_BIG; + ret = of_regmap_get_endian(dev, bus, config, "reg_endian", ®_endian); + if (ret) + return ERR_PTR(ret); + + ret = of_regmap_get_endian(dev, bus, config, "val_endian", &val_endian); + if (ret) + return ERR_PTR(ret); switch (config->reg_bits + map->reg_shift) { case 2: -- 1.8.4 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCHv2 3/3] regmap: add DT endianness binding support. 2014-04-02 10:09 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li @ 2014-04-02 19:50 ` Mark Brown 2014-04-03 5:26 ` Li.Xiubo 0 siblings, 1 reply; 12+ messages in thread From: Mark Brown @ 2014-04-02 19:50 UTC (permalink / raw) To: Xiubo Li; +Cc: linux-doc, linux-kernel [-- Attachment #1: Type: text/plain, Size: 474 bytes --] On Wed, Apr 02, 2014 at 06:09:09PM +0800, Xiubo Li wrote: > + ret = of_regmap_get_endian(dev, bus, config, "reg_endian", ®_endian); > + if (ret) > + return ERR_PTR(ret); > + > + ret = of_regmap_get_endian(dev, bus, config, "val_endian", &val_endian); > + if (ret) > + return ERR_PTR(ret); Actually, if we're going to be doing this for all devices then we probably need to namespace the properties too. Not sure what to do for a prefix though. One for the DT folks. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCHv2 3/3] regmap: add DT endianness binding support. 2014-04-02 19:50 ` Mark Brown @ 2014-04-03 5:26 ` Li.Xiubo 2014-04-14 21:07 ` Mark Brown 0 siblings, 1 reply; 12+ messages in thread From: Li.Xiubo @ 2014-04-03 5:26 UTC (permalink / raw) To: Mark Brown; +Cc: linux-doc, linux-kernel > Subject: Re: [PATCHv2 3/3] regmap: add DT endianness binding support. > > On Wed, Apr 02, 2014 at 06:09:09PM +0800, Xiubo Li wrote: > > > + ret = of_regmap_get_endian(dev, bus, config, "reg_endian", ®_endian); > > + if (ret) > > + return ERR_PTR(ret); > > + > > + ret = of_regmap_get_endian(dev, bus, config, "val_endian", &val_endian); > > + if (ret) > > + return ERR_PTR(ret); > > Actually, if we're going to be doing this for all devices then we > probably need to namespace the properties too. Not sure what to do for > a prefix though. One for the DT folks. How about using one prefix string of each regmap bus? Such as: Prefix 'regmap-mmio' for regmap-mmio, Prefix 'regmap-i2c' for regmap-i2c, Precix 'regmap-spi' for regmap-spi ... Or just using the same prefix 'regmap' for all of them ? Thanks, BRs Xiubo ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCHv2 3/3] regmap: add DT endianness binding support. 2014-04-03 5:26 ` Li.Xiubo @ 2014-04-14 21:07 ` Mark Brown 0 siblings, 0 replies; 12+ messages in thread From: Mark Brown @ 2014-04-14 21:07 UTC (permalink / raw) To: Li.Xiubo; +Cc: linux-doc, linux-kernel [-- Attachment #1: Type: text/plain, Size: 595 bytes --] On Thu, Apr 03, 2014 at 05:26:57AM +0000, Li.Xiubo@freescale.com wrote: > > Actually, if we're going to be doing this for all devices then we > > probably need to namespace the properties too. Not sure what to do for > > a prefix though. One for the DT folks. > How about using one prefix string of each regmap bus? > Such as: > Prefix 'regmap-mmio' for regmap-mmio, > Prefix 'regmap-i2c' for regmap-i2c, > Precix 'regmap-spi' for regmap-spi > ... > Or just using the same prefix 'regmap' for all of them ? I don't see any point in defining separate per bus properties so just one prefix. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-04-30 5:09 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-04-23 6:46 [PATCHv2 0/3] add DT endianness binding support Xiubo Li 2014-04-23 6:46 ` [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness Xiubo Li 2014-04-23 8:34 ` Mark Rutland 2014-04-30 5:08 ` Li.Xiubo 2014-04-23 6:46 ` [PATCHv2 2/3] regmap: " Xiubo Li 2014-04-23 8:40 ` Mark Rutland 2014-04-28 8:52 ` Li.Xiubo 2014-04-23 6:46 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li -- strict thread matches above, loose matches on Subject: below -- 2014-04-02 10:09 [PATCHv2 0/3] regmap: add LE and DT binding for endianness Xiubo Li 2014-04-02 10:09 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li 2014-04-02 19:50 ` Mark Brown 2014-04-03 5:26 ` Li.Xiubo 2014-04-14 21:07 ` Mark Brown
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.