Skip to contentSkip to conversation

nvmem: sunxi-sid: add SID controller support for H6

PATCH In review Yangtao Li 4 participants 10 messages Apr 2, 2019 – Apr 4, 2019

Subsystems (3)
lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

v2 cover nvmem: sunxi-sid: add SID controller support for H6

Add SID support for H6, and do some cleanup.
For endianness issue, add a new ref_read func.

Yangtao Li (5):
nvmem: sunxi-sid: fix wrong description in kernel doc
nvmem: sunxi-sid: add binding for H6's SID controller
nvmem: sunxi-sid: convert to SPDX license tags
nvmem: sunxi-sid: add new reg_read func
nvmem: sunxi-sid: add support for H6's SID controller
---
v2:
-add a new ref_read func
-only support H6 now

---
 .../bindings/nvmem/allwinner,sunxi-sid.txt    |  3 +-
 drivers/nvmem/sunxi_sid.c                     | 47 +++++++++++++++----
 2 files changed, 39 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.0
author
#1 lore raw

PATCH v2 1/5 nvmem: sunxi-sid: fix wrong description in kernel doc

qfprom->sunxi-sid

---
 Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt +1 -1
index 99c4ba6a3f61..d37017e343b1 100644
@@ -12,7 +12,7 @@ Required properties:
 - reg: Should contain registers location and length
 
 = Data cells =
-Are child nodes of qfprom, bindings of which as described in
+Are child nodes of sunxi-sid, bindings of which as described in
 bindings/nvmem/nvmem.txt
 
 Example for sun4i:
Signature · 1 line
2.17.0
author
#2 lore raw

PATCH v2 2/5 nvmem: sunxi-sid: add binding for H6's SID controller

In reply to Yangtao Li

Add a binding for H6's SID controller.

---
 Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt +1 -0
index d37017e343b1..cfb18b4ef8f7 100644
@@ -8,6 +8,7 @@ Required properties:
   "allwinner,sun8i-h3-sid"
   "allwinner,sun50i-a64-sid"
   "allwinner,sun50i-h5-sid"
+  "allwinner,sun50i-h6-sid"
 
 - reg: Should contain registers location and length
 
Signature · 1 line
2.17.0
author
#3 lore raw

PATCH v2 3/5 nvmem: sunxi-sid: convert to SPDX license tags

In reply to Yangtao Li

Updates license to use SPDX-License-Identifier.

---
 drivers/nvmem/sunxi_sid.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/nvmem/sunxi_sid.c +1 -10
index 570a2e354f30..54620d72ddb9 100644
@@ -1,18 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Allwinner sunXi SoCs Security ID support.
  *
  * Copyright (c) 2013 Oliver Schinagl <[email protected]>
  * Copyright (C) 2014 Maxime Ripard <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
  */
 
 #include <linux/device.h>
Signature · 1 line
2.17.0
author
#4 lore raw

PATCH v2 4/5 nvmem: sunxi-sid: add new reg_read func

In reply to Yangtao Li

Because there was an endianness issue. It seems that reg_read function which the nvmem the driver currently exposes is wrong. So add the new read function, the new function is used when the native_endian flag is set.

---
 drivers/nvmem/sunxi_sid.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/nvmem/sunxi_sid.c +29 -0
index 54620d72ddb9..5b8a42f686cd 100644
@@ -37,6 +37,7 @@ struct sunxi_sid_cfg {
 	u32	value_offset;
 	u32	size;
 	bool	need_register_readout;
+	bool	native_endian;
 };
 
 struct sunxi_sid {
@@ -75,6 +76,31 @@ static int sunxi_sid_read(void *context, unsigned int offset,
 	return 0;
 }
 
+static u8 sunxi_sid_read_byte_native(const struct sunxi_sid *sid,
+			      const unsigned int offset)
+{
+	u32 sid_key;
+
+	sid_key = ioread32(sid->base + round_down(offset, 4));
+	sid_key >>= (offset % 4) * 8;
+
+	return sid_key;
+}
+
+static int sunxi_sid_read_native(void *context, unsigned int offset,
+			  void *val, size_t bytes)
+{
+	struct sunxi_sid *sid = context;
+	u8 *buf = val;
+
+	offset += sid->value_offset;
+
+	while (bytes--)
+		*buf++ = sunxi_sid_read_byte_native(sid, offset++);
+
+	return 0;
+}
+
 static int sun8i_sid_register_readout(const struct sunxi_sid *sid,
 				      const unsigned int offset,
 				      u32 *out)
@@ -169,9 +195,12 @@ static int sunxi_sid_probe(struct platform_device *pdev)
 	econfig.dev = dev;
 	if (cfg->need_register_readout)
 		econfig.reg_read = sun8i_sid_read_by_reg;
+	else if (cfg->native_endian)
+		econfig.reg_read = sunxi_sid_read_native;
 	else
 		econfig.reg_read = sunxi_sid_read;
 	econfig.priv = sid;
+
 	nvmem = devm_nvmem_register(dev, &econfig);
 	if (IS_ERR(nvmem))
 		return PTR_ERR(nvmem);
Signature · 1 line
2.17.0
#5 lore raw

Re: [PATCH v2 4/5] nvmem: sunxi-sid: add new reg_read func

Quoted 6 lines · Yangtao Li

Because there was an endianness issue. It seems that reg_read function which the nvmem the driver currently exposes is wrong. So add the new read function, the new function is used when the native_endian flag is set.

This patch and 5/5 does not apply cleanly on nvmem-next. Also I would need an ack from Maxime to be able to apply it.

thanks,
srini

#6 lore raw

Re: [PATCH v2 4/5] nvmem: sunxi-sid: add new reg_read func

Quoted 8 lines · Srinivas Kandagatla
Quoted 5 lines · Yangtao Li

Because there was an endianness issue. It seems that reg_read function which the nvmem the driver currently exposes is wrong. So add the new read function, the new function is used when the native_endian flag is set.

Quoted 4 lines
Quoted 1 line

This patch and 5/5 does not apply cleanly on nvmem-next. Also I would need an ack from Maxime to be able to apply it.

Chen-Yu has mostly been taking care of this recently, so I'd like his feedback on this.

Maxime

--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

#7 lore raw

Re: [PATCH v2 4/5] nvmem: sunxi-sid: add new reg_read func

Quoted 10 lines · Maxime Ripard
Quoted 8 lines · Srinivas Kandagatla
Quoted 5 lines · Yangtao Li

Because there was an endianness issue. It seems that reg_read function which the nvmem the driver currently exposes is wrong. So add the new read function, the new function is used when the native_endian flag is set.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This patch and 5/5 does not apply cleanly on nvmem-next. Also I would need an ack from Maxime to be able to apply it.

Chen-Yu has mostly been taking care of this recently, so I'd like his feedback on this.

As you previously requested, my patches already switch everything to native endianess. There's no need to differentiate between the old and the new now. So this patch and the native_endian flag is not needed.

ChenYu

author
#8 lore raw

PATCH v2 5/5 nvmem: sunxi-sid: add support for H6's SID controller

In reply to Yangtao Li

Add support for H6's SID controller. It supports 4K-bit EFUSE, bigger than before. And convert to use sunxi_sid_read_native func.

---
 drivers/nvmem/sunxi_sid.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/nvmem/sunxi_sid.c +7 -0
index 5b8a42f686cd..3c2b06140490 100644
@@ -239,11 +239,18 @@ static const struct sunxi_sid_cfg sun50i_a64_cfg = {
 	.size = 0x100,
 };
 
+static const struct sunxi_sid_cfg sun50i_h6_cfg = {
+	.value_offset = 0x200,
+	.size = 0x200,
+	.native_endian = true,
+};
+
 static const struct of_device_id sunxi_sid_of_match[] = {
 	{ .compatible = "allwinner,sun4i-a10-sid", .data = &sun4i_a10_cfg },
 	{ .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg },
 	{ .compatible = "allwinner,sun8i-h3-sid", .data = &sun8i_h3_cfg },
 	{ .compatible = "allwinner,sun50i-a64-sid", .data = &sun50i_a64_cfg },
+	{ .compatible = "allwinner,sun50i-h6-sid", .data = &sun50i_h6_cfg },
 	{/* sentinel */},
 };
 MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);
Signature · 1 line
2.17.0
#9 lore raw
In reply to Yangtao Li
Quoted 7 lines · Yangtao Li

Add SID support for H6, and do some cleanup.
For endianness issue, add a new ref_read func.

Yangtao Li (5):
nvmem: sunxi-sid: fix wrong description in kernel doc
nvmem: sunxi-sid: add binding for H6's SID controller
nvmem: sunxi-sid: convert to SPDX license tags

Applied first 3 patches, please resend last two patches after rebase on top of next.

Thanks,
srini