diff mbox series

[v3] i2c: eeprom: Use reg property instead of offset and size

Message ID a0b1de2bdb9f4bd93507a3129ec8617b60ea18ca.1595412832.git.michal.simek@xilinx.com
State Accepted
Delegated to: Heiko Schocher
Headers show
Series [v3] i2c: eeprom: Use reg property instead of offset and size | expand

Commit Message

Michal Simek July 22, 2020, 10:13 a.m. UTC
Remove adhoc dt binding for fixed-partition definition for i2c eeprom.
fixed-partition are using reg property instead of offset/size pair.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v3:
- Add test for sandbox
- Fix issues related to OF_TRANSLATE
- Remove address/size cells from parent because of OF_TRANSLATE

Changes in v2:
- Bootcount tested on zynqmp zcu104
- Add missing address/size cells
- Use dev_read_addr_size_index
- Check parameters

Just build tested - ge_bx50v3_defconfig
Tested on zcu104

---
 arch/arm/dts/imx53-ppd-uboot.dtsi    | 12 ++++++------
 arch/arm/dts/imx6q-bx50v3-uboot.dtsi | 10 +++++-----
 arch/sandbox/dts/test.dts            | 13 +++++++++++++
 configs/sandbox_defconfig            |  1 +
 drivers/misc/i2c_eeprom.c            | 15 ++++++++-------
 test/dm/bootcount.c                  |  8 ++++++++
 6 files changed, 41 insertions(+), 18 deletions(-)

Comments

Simon Glass July 28, 2020, 6:58 p.m. UTC | #1
On Wed, 22 Jul 2020 at 04:14, Michal Simek <michal.simek@xilinx.com> wrote:
>
> Remove adhoc dt binding for fixed-partition definition for i2c eeprom.
> fixed-partition are using reg property instead of offset/size pair.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> Changes in v3:
> - Add test for sandbox
> - Fix issues related to OF_TRANSLATE
> - Remove address/size cells from parent because of OF_TRANSLATE
>
> Changes in v2:
> - Bootcount tested on zynqmp zcu104
> - Add missing address/size cells
> - Use dev_read_addr_size_index
> - Check parameters
>
> Just build tested - ge_bx50v3_defconfig
> Tested on zcu104
>
> ---
>  arch/arm/dts/imx53-ppd-uboot.dtsi    | 12 ++++++------
>  arch/arm/dts/imx6q-bx50v3-uboot.dtsi | 10 +++++-----
>  arch/sandbox/dts/test.dts            | 13 +++++++++++++
>  configs/sandbox_defconfig            |  1 +
>  drivers/misc/i2c_eeprom.c            | 15 ++++++++-------
>  test/dm/bootcount.c                  |  8 ++++++++
>  6 files changed, 41 insertions(+), 18 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Michal Simek Aug. 20, 2020, 7:52 a.m. UTC | #2
st 22. 7. 2020 v 12:14 odesílatel Michal Simek <michal.simek@xilinx.com> napsal:
>
> Remove adhoc dt binding for fixed-partition definition for i2c eeprom.
> fixed-partition are using reg property instead of offset/size pair.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> Changes in v3:
> - Add test for sandbox
> - Fix issues related to OF_TRANSLATE
> - Remove address/size cells from parent because of OF_TRANSLATE
>
> Changes in v2:
> - Bootcount tested on zynqmp zcu104
> - Add missing address/size cells
> - Use dev_read_addr_size_index
> - Check parameters
>
> Just build tested - ge_bx50v3_defconfig
> Tested on zcu104
>
> ---
>  arch/arm/dts/imx53-ppd-uboot.dtsi    | 12 ++++++------
>  arch/arm/dts/imx6q-bx50v3-uboot.dtsi | 10 +++++-----
>  arch/sandbox/dts/test.dts            | 13 +++++++++++++
>  configs/sandbox_defconfig            |  1 +
>  drivers/misc/i2c_eeprom.c            | 15 ++++++++-------
>  test/dm/bootcount.c                  |  8 ++++++++
>  6 files changed, 41 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arm/dts/imx53-ppd-uboot.dtsi b/arch/arm/dts/imx53-ppd-uboot.dtsi
> index d38a1bc264c9..d61b7cb87642 100644
> --- a/arch/arm/dts/imx53-ppd-uboot.dtsi
> +++ b/arch/arm/dts/imx53-ppd-uboot.dtsi
> @@ -24,15 +24,15 @@
>  &eeprom {
>         partitions {
>                 compatible = "fixed-partitions";
> +               #address-cells = <1>;
> +               #size-cells = <1>;
>
> -               vpd {
> -                       offset = <0>;
> -                       size = <1022>;
> +               vpd@0 {
> +                       reg = <0 1022>;
>                 };
>
> -               bootcount: bootcount {
> -                       offset = <1022>;
> -                       size = <2>;
> +               bootcount: bootcount@1022 {
> +                       reg = <1022 2>;
>                 };
>         };
>  };
> diff --git a/arch/arm/dts/imx6q-bx50v3-uboot.dtsi b/arch/arm/dts/imx6q-bx50v3-uboot.dtsi
> index df446e0ed149..01321cab781b 100644
> --- a/arch/arm/dts/imx6q-bx50v3-uboot.dtsi
> +++ b/arch/arm/dts/imx6q-bx50v3-uboot.dtsi
> @@ -23,15 +23,15 @@
>  &eeprom {
>         partitions {
>                 compatible = "fixed-partitions";
> +               #address-cells = <1>;
> +               #size-cells = <1>;
>
> -               vpd {
> -                       offset = <0>;
> -                       size = <1022>;
> +               vpd@0 {
> +                       reg = <0 1022>;
>                 };
>
>                 bootcount: bootcount {
> -                       offset = <1022>;
> -                       size = <2>;
> +                       reg = <1022 2>;
>                 };
>         };
>  };
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index 1b33cd4c0878..19522a9e4778 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -403,6 +403,14 @@
>                         reg = <0x2c>;
>                         compatible = "i2c-eeprom";
>                         sandbox,emul = <&emul_eeprom>;
> +                       partitions {
> +                               compatible = "fixed-partitions";
> +                               #address-cells = <1>;
> +                               #size-cells = <1>;
> +                               bootcount_i2c: bootcount@10 {
> +                                       reg = <10 2>;
> +                               };
> +                       };
>                 };
>
>                 rtc_0: rtc@43 {
> @@ -450,6 +458,11 @@
>                 offset = <0x13>;
>         };
>
> +       bootcount {
> +               compatible = "u-boot,bootcount-i2c-eeprom";
> +               i2c-eeprom = <&bootcount_i2c>;
> +       };
> +
>         adc@0 {
>                 compatible = "sandbox,adc";
>                 vdd-supply = <&buck2>;
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index 6059d668af77..320e564eb8e7 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -106,6 +106,7 @@ CONFIG_AXI_SANDBOX=y
>  CONFIG_BOOTCOUNT_LIMIT=y
>  CONFIG_DM_BOOTCOUNT=y
>  CONFIG_DM_BOOTCOUNT_RTC=y
> +CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y
>  CONFIG_CLK=y
>  CONFIG_CLK_COMPOSITE_CCF=y
>  CONFIG_SANDBOX_CLK_CCF=y
> diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c
> index 45c34d388c8a..3651ba4871ef 100644
> --- a/drivers/misc/i2c_eeprom.c
> +++ b/drivers/misc/i2c_eeprom.c
> @@ -301,19 +301,20 @@ static int i2c_eeprom_partition_probe(struct udevice *dev)
>  static int i2c_eeprom_partition_ofdata_to_platdata(struct udevice *dev)
>  {
>         struct i2c_eeprom_partition *priv = dev_get_priv(dev);
> -       u32 offset, size;
> +       u32 reg[2];
>         int ret;
>
> -       ret = dev_read_u32(dev, "offset", &offset);
> +       ret = dev_read_u32_array(dev, "reg", reg, 2);
>         if (ret)
>                 return ret;
>
> -       ret = dev_read_u32(dev, "size", &size);
> -       if (ret)
> -               return ret;
> +       if (!reg[1])
> +               return -EINVAL;
> +
> +       priv->offset = reg[0];
> +       priv->size = reg[1];
>
> -       priv->offset = offset;
> -       priv->size = size;
> +       debug("%s: base %x, size %x\n", __func__, priv->offset, priv->size);
>
>         return 0;
>  }
> diff --git a/test/dm/bootcount.c b/test/dm/bootcount.c
> index be0c27890706..06460d505e31 100644
> --- a/test/dm/bootcount.c
> +++ b/test/dm/bootcount.c
> @@ -24,6 +24,14 @@ static int dm_test_bootcount(struct unit_test_state *uts)
>         ut_assertok(dm_bootcount_get(dev, &val));
>         ut_assert(val == 0xab);
>
> +       ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 1, &dev));
> +       ut_assertok(dm_bootcount_set(dev, 0));
> +       ut_assertok(dm_bootcount_get(dev, &val));
> +       ut_assert(val == 0);
> +       ut_assertok(dm_bootcount_set(dev, 0xab));
> +       ut_assertok(dm_bootcount_get(dev, &val));
> +       ut_assert(val == 0xab);
> +
>         return 0;
>  }
>
> --
> 2.27.0
>

Applied.
M
diff mbox series

Patch

diff --git a/arch/arm/dts/imx53-ppd-uboot.dtsi b/arch/arm/dts/imx53-ppd-uboot.dtsi
index d38a1bc264c9..d61b7cb87642 100644
--- a/arch/arm/dts/imx53-ppd-uboot.dtsi
+++ b/arch/arm/dts/imx53-ppd-uboot.dtsi
@@ -24,15 +24,15 @@ 
 &eeprom {
 	partitions {
 		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
 
-		vpd {
-			offset = <0>;
-			size = <1022>;
+		vpd@0 {
+			reg = <0 1022>;
 		};
 
-		bootcount: bootcount {
-			offset = <1022>;
-			size = <2>;
+		bootcount: bootcount@1022 {
+			reg = <1022 2>;
 		};
 	};
 };
diff --git a/arch/arm/dts/imx6q-bx50v3-uboot.dtsi b/arch/arm/dts/imx6q-bx50v3-uboot.dtsi
index df446e0ed149..01321cab781b 100644
--- a/arch/arm/dts/imx6q-bx50v3-uboot.dtsi
+++ b/arch/arm/dts/imx6q-bx50v3-uboot.dtsi
@@ -23,15 +23,15 @@ 
 &eeprom {
 	partitions {
 		compatible = "fixed-partitions";
+		#address-cells = <1>;
+		#size-cells = <1>;
 
-		vpd {
-			offset = <0>;
-			size = <1022>;
+		vpd@0 {
+			reg = <0 1022>;
 		};
 
 		bootcount: bootcount {
-			offset = <1022>;
-			size = <2>;
+			reg = <1022 2>;
 		};
 	};
 };
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 1b33cd4c0878..19522a9e4778 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -403,6 +403,14 @@ 
 			reg = <0x2c>;
 			compatible = "i2c-eeprom";
 			sandbox,emul = <&emul_eeprom>;
+			partitions {
+				compatible = "fixed-partitions";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				bootcount_i2c: bootcount@10 {
+					reg = <10 2>;
+				};
+			};
 		};
 
 		rtc_0: rtc@43 {
@@ -450,6 +458,11 @@ 
 		offset = <0x13>;
 	};
 
+	bootcount {
+		compatible = "u-boot,bootcount-i2c-eeprom";
+		i2c-eeprom = <&bootcount_i2c>;
+	};
+
 	adc@0 {
 		compatible = "sandbox,adc";
 		vdd-supply = <&buck2>;
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 6059d668af77..320e564eb8e7 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -106,6 +106,7 @@  CONFIG_AXI_SANDBOX=y
 CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_DM_BOOTCOUNT=y
 CONFIG_DM_BOOTCOUNT_RTC=y
+CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y
 CONFIG_CLK=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SANDBOX_CLK_CCF=y
diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c
index 45c34d388c8a..3651ba4871ef 100644
--- a/drivers/misc/i2c_eeprom.c
+++ b/drivers/misc/i2c_eeprom.c
@@ -301,19 +301,20 @@  static int i2c_eeprom_partition_probe(struct udevice *dev)
 static int i2c_eeprom_partition_ofdata_to_platdata(struct udevice *dev)
 {
 	struct i2c_eeprom_partition *priv = dev_get_priv(dev);
-	u32 offset, size;
+	u32 reg[2];
 	int ret;
 
-	ret = dev_read_u32(dev, "offset", &offset);
+	ret = dev_read_u32_array(dev, "reg", reg, 2);
 	if (ret)
 		return ret;
 
-	ret = dev_read_u32(dev, "size", &size);
-	if (ret)
-		return ret;
+	if (!reg[1])
+		return -EINVAL;
+
+	priv->offset = reg[0];
+	priv->size = reg[1];
 
-	priv->offset = offset;
-	priv->size = size;
+	debug("%s: base %x, size %x\n", __func__, priv->offset, priv->size);
 
 	return 0;
 }
diff --git a/test/dm/bootcount.c b/test/dm/bootcount.c
index be0c27890706..06460d505e31 100644
--- a/test/dm/bootcount.c
+++ b/test/dm/bootcount.c
@@ -24,6 +24,14 @@  static int dm_test_bootcount(struct unit_test_state *uts)
 	ut_assertok(dm_bootcount_get(dev, &val));
 	ut_assert(val == 0xab);
 
+	ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 1, &dev));
+	ut_assertok(dm_bootcount_set(dev, 0));
+	ut_assertok(dm_bootcount_get(dev, &val));
+	ut_assert(val == 0);
+	ut_assertok(dm_bootcount_set(dev, 0xab));
+	ut_assertok(dm_bootcount_get(dev, &val));
+	ut_assert(val == 0xab);
+
 	return 0;
 }