All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] rockchip: Support otp on rv1126
@ 2023-10-31  2:07 Tim Lunn
  2023-10-31  2:07 ` [PATCH 1/2] rockchip: otp: Add support for RV1126 Tim Lunn
  2023-10-31  2:07 ` [PATCH 2/2] rockchip: rv1126: Read cpuid from otp and set ethaddr Tim Lunn
  0 siblings, 2 replies; 5+ messages in thread
From: Tim Lunn @ 2023-10-31  2:07 UTC (permalink / raw)
  To: u-boot; +Cc: Simon Glass, Philipp Tomsich, Kever Yang, Tim Lunn

This series adds support for reading the otp on rv1126 and
then uses this to generate a persistant MAC address from cpuid.

Tim Lunn (2):
  rockchip: otp: Add support for RV1126
  rockchip: rv1126: Read cpuid from otp and set ethaddr

 arch/arm/dts/rv1126-u-boot.dtsi | 12 ++++++
 arch/arm/mach-rockchip/Kconfig  |  2 +
 drivers/misc/rockchip-otp.c     | 76 +++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+)


base-commit: cbba1b7766bd93d74e28202c46e69095ac13760b
-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] rockchip: otp: Add support for RV1126
  2023-10-31  2:07 [PATCH 0/2] rockchip: Support otp on rv1126 Tim Lunn
@ 2023-10-31  2:07 ` Tim Lunn
  2023-11-07  4:03   ` Kever Yang
  2023-10-31  2:07 ` [PATCH 2/2] rockchip: rv1126: Read cpuid from otp and set ethaddr Tim Lunn
  1 sibling, 1 reply; 5+ messages in thread
From: Tim Lunn @ 2023-10-31  2:07 UTC (permalink / raw)
  To: u-boot; +Cc: Simon Glass, Philipp Tomsich, Kever Yang, Tim Lunn

Extend the otp driver to read rv1126 otp. This driver code was
adapted from the Rockchip BSP stack.

Signed-off-by: Tim Lunn <tim@feathertop.org>
---
 drivers/misc/rockchip-otp.c | 76 +++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/drivers/misc/rockchip-otp.c b/drivers/misc/rockchip-otp.c
index 4814e0e501..4f757083a1 100644
--- a/drivers/misc/rockchip-otp.c
+++ b/drivers/misc/rockchip-otp.c
@@ -61,11 +61,20 @@
 #define RK3588_OTPC_INT_ST		0x0084
 #define RK3588_RD_DONE			BIT(1)
 
+#define RV1126_OTP_NVM_CEB		0x00
+#define RV1126_OTP_NVM_RSTB		0x04
+#define RV1126_OTP_NVM_ST		0x18
+#define RV1126_OTP_NVM_RADDR		0x1C
+#define RV1126_OTP_NVM_RSTART		0x20
+#define RV1126_OTP_NVM_RDATA		0x24
+#define RV1126_OTP_READ_ST		0x30
+
 struct rockchip_otp_plat {
 	void __iomem *base;
 };
 
 struct rockchip_otp_data {
+	int (*init)(struct udevice *dev);
 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
 	int offset;
 	int size;
@@ -232,6 +241,48 @@ static int rockchip_rk3588_otp_read(struct udevice *dev, int offset,
 	return 0;
 }
 
+static int rockchip_rv1126_otp_init(struct udevice *dev)
+{
+	struct rockchip_otp_plat *otp = dev_get_plat(dev);
+	int ret;
+
+	writel(0x0, otp->base + RV1126_OTP_NVM_CEB);
+	ret = rockchip_otp_poll_timeout(otp, 0x1, RV1126_OTP_NVM_ST);
+
+	if (ret)
+		return ret;
+
+	writel(0x1, otp->base + RV1126_OTP_NVM_RSTB);
+	ret = rockchip_otp_poll_timeout(otp, 0x4, RV1126_OTP_NVM_ST);
+
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int rockchip_rv1126_otp_read(struct udevice *dev, int offset, void *buf,
+				    int size)
+{
+	struct rockchip_otp_plat *otp = dev_get_plat(dev);
+	u32 status = 0;
+	u8 *buffer = buf;
+	int ret = 0;
+
+	while (size--) {
+		writel(offset++, otp->base + RV1126_OTP_NVM_RADDR);
+		writel(0x1, otp->base + RV1126_OTP_NVM_RSTART);
+		ret = readl_poll_timeout(otp->base + RV1126_OTP_READ_ST,
+					 status, !status, OTPC_TIMEOUT);
+		if (ret)
+			return ret;
+
+		*buffer++ = (u8)(readl(otp->base + RV1126_OTP_NVM_RDATA) & 0xFF);
+	}
+
+	return 0;
+}
+
 static int rockchip_otp_read(struct udevice *dev, int offset,
 			     void *buf, int size)
 {
@@ -286,6 +337,20 @@ static int rockchip_otp_of_to_plat(struct udevice *dev)
 	return 0;
 }
 
+static int rockchip_otp_probe(struct udevice *dev)
+{
+	struct rockchip_otp_data *data;
+
+	data = (struct rockchip_otp_data *)dev_get_driver_data(dev);
+	if (!data)
+		return -EINVAL;
+
+	if (data->init)
+		return data->init(dev);
+
+	return 0;
+}
+
 static const struct rockchip_otp_data px30_data = {
 	.read = rockchip_px30_otp_read,
 	.size = 0x40,
@@ -304,6 +369,12 @@ static const struct rockchip_otp_data rk3588_data = {
 	.block_size = 4,
 };
 
+static const struct rockchip_otp_data rv1126_data = {
+	.init = rockchip_rv1126_otp_init,
+	.read = rockchip_rv1126_otp_read,
+	.size = 0x40,
+};
+
 static const struct udevice_id rockchip_otp_ids[] = {
 	{
 		.compatible = "rockchip,px30-otp",
@@ -321,6 +392,10 @@ static const struct udevice_id rockchip_otp_ids[] = {
 		.compatible = "rockchip,rk3588-otp",
 		.data = (ulong)&rk3588_data,
 	},
+	{
+		.compatible = "rockchip,rv1126-otp",
+		.data = (ulong)&rv1126_data,
+	},
 	{}
 };
 
@@ -331,4 +406,5 @@ U_BOOT_DRIVER(rockchip_otp) = {
 	.of_to_plat = rockchip_otp_of_to_plat,
 	.plat_auto = sizeof(struct rockchip_otp_plat),
 	.ops = &rockchip_otp_ops,
+	.probe = rockchip_otp_probe,
 };
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] rockchip: rv1126: Read cpuid from otp and set ethaddr
  2023-10-31  2:07 [PATCH 0/2] rockchip: Support otp on rv1126 Tim Lunn
  2023-10-31  2:07 ` [PATCH 1/2] rockchip: otp: Add support for RV1126 Tim Lunn
@ 2023-10-31  2:07 ` Tim Lunn
  2023-11-07  4:03   ` Kever Yang
  1 sibling, 1 reply; 5+ messages in thread
From: Tim Lunn @ 2023-10-31  2:07 UTC (permalink / raw)
  To: u-boot; +Cc: Simon Glass, Philipp Tomsich, Kever Yang, Tim Lunn

Provide configuration to read cpuid and generate a persistant
MAC address in ethaddr

Signed-off-by: Tim Lunn <tim@feathertop.org>
---
 arch/arm/dts/rv1126-u-boot.dtsi | 12 ++++++++++++
 arch/arm/mach-rockchip/Kconfig  |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/dts/rv1126-u-boot.dtsi b/arch/arm/dts/rv1126-u-boot.dtsi
index 5e348278f2..811a3cee98 100644
--- a/arch/arm/dts/rv1126-u-boot.dtsi
+++ b/arch/arm/dts/rv1126-u-boot.dtsi
@@ -15,6 +15,18 @@
 		compatible = "rockchip,rv1126-dmc";
 		bootph-all;
 	};
+
+	otp: otp@ff5c0000 {
+		compatible = "rockchip,rv1126-otp";
+		reg = <0xff5c0000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		status = "okay";
+
+		cpu_id: id@7 {
+			reg = <0x07 0x10>;
+		};
+	};
 };
 
 &gpio0 {
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index a6c69c300d..5e993383cf 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -359,6 +359,8 @@ config ROCKCHIP_RV1126
 	select BOARD_LATE_INIT
 	imply ROCKCHIP_COMMON_BOARD
 	imply OF_LIBFDT_OVERLAY
+	imply ROCKCHIP_OTP
+	imply MISC_INIT_R
 	imply TPL_DM
 	imply TPL_LIBCOMMON_SUPPORT
 	imply TPL_LIBGENERIC_SUPPORT
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] rockchip: otp: Add support for RV1126
  2023-10-31  2:07 ` [PATCH 1/2] rockchip: otp: Add support for RV1126 Tim Lunn
@ 2023-11-07  4:03   ` Kever Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Kever Yang @ 2023-11-07  4:03 UTC (permalink / raw)
  To: Tim Lunn, u-boot; +Cc: Simon Glass, Philipp Tomsich


On 2023/10/31 10:07, Tim Lunn wrote:
> Extend the otp driver to read rv1126 otp. This driver code was
> adapted from the Rockchip BSP stack.
>
> Signed-off-by: Tim Lunn <tim@feathertop.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>

Thanks,
- Kever
> ---
>   drivers/misc/rockchip-otp.c | 76 +++++++++++++++++++++++++++++++++++++
>   1 file changed, 76 insertions(+)
>
> diff --git a/drivers/misc/rockchip-otp.c b/drivers/misc/rockchip-otp.c
> index 4814e0e501..4f757083a1 100644
> --- a/drivers/misc/rockchip-otp.c
> +++ b/drivers/misc/rockchip-otp.c
> @@ -61,11 +61,20 @@
>   #define RK3588_OTPC_INT_ST		0x0084
>   #define RK3588_RD_DONE			BIT(1)
>   
> +#define RV1126_OTP_NVM_CEB		0x00
> +#define RV1126_OTP_NVM_RSTB		0x04
> +#define RV1126_OTP_NVM_ST		0x18
> +#define RV1126_OTP_NVM_RADDR		0x1C
> +#define RV1126_OTP_NVM_RSTART		0x20
> +#define RV1126_OTP_NVM_RDATA		0x24
> +#define RV1126_OTP_READ_ST		0x30
> +
>   struct rockchip_otp_plat {
>   	void __iomem *base;
>   };
>   
>   struct rockchip_otp_data {
> +	int (*init)(struct udevice *dev);
>   	int (*read)(struct udevice *dev, int offset, void *buf, int size);
>   	int offset;
>   	int size;
> @@ -232,6 +241,48 @@ static int rockchip_rk3588_otp_read(struct udevice *dev, int offset,
>   	return 0;
>   }
>   
> +static int rockchip_rv1126_otp_init(struct udevice *dev)
> +{
> +	struct rockchip_otp_plat *otp = dev_get_plat(dev);
> +	int ret;
> +
> +	writel(0x0, otp->base + RV1126_OTP_NVM_CEB);
> +	ret = rockchip_otp_poll_timeout(otp, 0x1, RV1126_OTP_NVM_ST);
> +
> +	if (ret)
> +		return ret;
> +
> +	writel(0x1, otp->base + RV1126_OTP_NVM_RSTB);
> +	ret = rockchip_otp_poll_timeout(otp, 0x4, RV1126_OTP_NVM_ST);
> +
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static int rockchip_rv1126_otp_read(struct udevice *dev, int offset, void *buf,
> +				    int size)
> +{
> +	struct rockchip_otp_plat *otp = dev_get_plat(dev);
> +	u32 status = 0;
> +	u8 *buffer = buf;
> +	int ret = 0;
> +
> +	while (size--) {
> +		writel(offset++, otp->base + RV1126_OTP_NVM_RADDR);
> +		writel(0x1, otp->base + RV1126_OTP_NVM_RSTART);
> +		ret = readl_poll_timeout(otp->base + RV1126_OTP_READ_ST,
> +					 status, !status, OTPC_TIMEOUT);
> +		if (ret)
> +			return ret;
> +
> +		*buffer++ = (u8)(readl(otp->base + RV1126_OTP_NVM_RDATA) & 0xFF);
> +	}
> +
> +	return 0;
> +}
> +
>   static int rockchip_otp_read(struct udevice *dev, int offset,
>   			     void *buf, int size)
>   {
> @@ -286,6 +337,20 @@ static int rockchip_otp_of_to_plat(struct udevice *dev)
>   	return 0;
>   }
>   
> +static int rockchip_otp_probe(struct udevice *dev)
> +{
> +	struct rockchip_otp_data *data;
> +
> +	data = (struct rockchip_otp_data *)dev_get_driver_data(dev);
> +	if (!data)
> +		return -EINVAL;
> +
> +	if (data->init)
> +		return data->init(dev);
> +
> +	return 0;
> +}
> +
>   static const struct rockchip_otp_data px30_data = {
>   	.read = rockchip_px30_otp_read,
>   	.size = 0x40,
> @@ -304,6 +369,12 @@ static const struct rockchip_otp_data rk3588_data = {
>   	.block_size = 4,
>   };
>   
> +static const struct rockchip_otp_data rv1126_data = {
> +	.init = rockchip_rv1126_otp_init,
> +	.read = rockchip_rv1126_otp_read,
> +	.size = 0x40,
> +};
> +
>   static const struct udevice_id rockchip_otp_ids[] = {
>   	{
>   		.compatible = "rockchip,px30-otp",
> @@ -321,6 +392,10 @@ static const struct udevice_id rockchip_otp_ids[] = {
>   		.compatible = "rockchip,rk3588-otp",
>   		.data = (ulong)&rk3588_data,
>   	},
> +	{
> +		.compatible = "rockchip,rv1126-otp",
> +		.data = (ulong)&rv1126_data,
> +	},
>   	{}
>   };
>   
> @@ -331,4 +406,5 @@ U_BOOT_DRIVER(rockchip_otp) = {
>   	.of_to_plat = rockchip_otp_of_to_plat,
>   	.plat_auto = sizeof(struct rockchip_otp_plat),
>   	.ops = &rockchip_otp_ops,
> +	.probe = rockchip_otp_probe,
>   };

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] rockchip: rv1126: Read cpuid from otp and set ethaddr
  2023-10-31  2:07 ` [PATCH 2/2] rockchip: rv1126: Read cpuid from otp and set ethaddr Tim Lunn
@ 2023-11-07  4:03   ` Kever Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Kever Yang @ 2023-11-07  4:03 UTC (permalink / raw)
  To: Tim Lunn, u-boot; +Cc: Simon Glass, Philipp Tomsich


On 2023/10/31 10:07, Tim Lunn wrote:
> Provide configuration to read cpuid and generate a persistant
> MAC address in ethaddr
>
> Signed-off-by: Tim Lunn <tim@feathertop.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>

Thanks,
- Kever
> ---
>   arch/arm/dts/rv1126-u-boot.dtsi | 12 ++++++++++++
>   arch/arm/mach-rockchip/Kconfig  |  2 ++
>   2 files changed, 14 insertions(+)
>
> diff --git a/arch/arm/dts/rv1126-u-boot.dtsi b/arch/arm/dts/rv1126-u-boot.dtsi
> index 5e348278f2..811a3cee98 100644
> --- a/arch/arm/dts/rv1126-u-boot.dtsi
> +++ b/arch/arm/dts/rv1126-u-boot.dtsi
> @@ -15,6 +15,18 @@
>   		compatible = "rockchip,rv1126-dmc";
>   		bootph-all;
>   	};
> +
> +	otp: otp@ff5c0000 {
> +		compatible = "rockchip,rv1126-otp";
> +		reg = <0xff5c0000 0x1000>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +		status = "okay";
> +
> +		cpu_id: id@7 {
> +			reg = <0x07 0x10>;
> +		};
> +	};
>   };
>   
>   &gpio0 {
> diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
> index a6c69c300d..5e993383cf 100644
> --- a/arch/arm/mach-rockchip/Kconfig
> +++ b/arch/arm/mach-rockchip/Kconfig
> @@ -359,6 +359,8 @@ config ROCKCHIP_RV1126
>   	select BOARD_LATE_INIT
>   	imply ROCKCHIP_COMMON_BOARD
>   	imply OF_LIBFDT_OVERLAY
> +	imply ROCKCHIP_OTP
> +	imply MISC_INIT_R
>   	imply TPL_DM
>   	imply TPL_LIBCOMMON_SUPPORT
>   	imply TPL_LIBGENERIC_SUPPORT

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-07  4:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-31  2:07 [PATCH 0/2] rockchip: Support otp on rv1126 Tim Lunn
2023-10-31  2:07 ` [PATCH 1/2] rockchip: otp: Add support for RV1126 Tim Lunn
2023-11-07  4:03   ` Kever Yang
2023-10-31  2:07 ` [PATCH 2/2] rockchip: rv1126: Read cpuid from otp and set ethaddr Tim Lunn
2023-11-07  4:03   ` Kever Yang

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.