Skip to contentSkip to conversation

Add Amlogic secure monitor and NVMEM drivers

PATCH Superseded Carlo Caione 5 participants 15 messages Jun 19, 2016 – Jun 28, 2016

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add Amlogic secure monitor and NVMEM drivers

From: Carlo Caione <[email protected]>

I decided to respin again the secure monitor driver this time with the NVMEM driver in the same patchset to have a clear view on how a generic driver can use the monitor.

The latest patchset for the secure monitor with the Changelog is here [1].

[1] http://www.spinics.net/lists/arm-kernel/msg510441.html

Carlo Caione (6):
firmware: Amlogic: Add secure monitor driver
documentation: Add secure monitor bindings documentation
ARM64: dts: amlogic: gxbb: Enable secure monitor
nvmem: amlogic: Add Amlogic Meson EFUSE driver
documentation: Add nvmem bindings documentation
ARM64: dts: amlogic: gxbb: Enable NVMEM

 .../bindings/firmware/meson/meson_sm.txt           |  15 ++
 .../devicetree/bindings/nvmem/amlogic-efuse.txt    |  39 +++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |  24 ++
 drivers/firmware/Kconfig                           |   1 +
 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/meson/Kconfig                     |   8 +
 drivers/firmware/meson/Makefile                    |   1 +
 drivers/firmware/meson/meson_sm.c                  | 266 +++++++++++++++++++++
 drivers/nvmem/Kconfig                              |  11 +
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/meson-efuse.c                        | 130 ++++++++++
 include/linux/firmware/meson/meson_sm.h            |  32 +++
 12 files changed, 530 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
 create mode 100644 Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt
 create mode 100644 drivers/firmware/meson/Kconfig
 create mode 100644 drivers/firmware/meson/Makefile
 create mode 100644 drivers/firmware/meson/meson_sm.c
 create mode 100644 drivers/nvmem/meson-efuse.c
 create mode 100644 include/linux/firmware/meson/meson_sm.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/6 firmware: Amlogic: Add secure monitor driver

From: Carlo Caione <[email protected]>

Introduce a driver to provide calls into secure monitor mode.

In the Amlogic SoCs these calls are used for multiple reasons: access to NVMEM, set USB boot, enable JTAG, etc...

---
 drivers/firmware/Kconfig                |   1 +
 drivers/firmware/Makefile               |   1 +
 drivers/firmware/meson/Kconfig          |   8 +
 drivers/firmware/meson/Makefile         |   1 +
 drivers/firmware/meson/meson_sm.c       | 266 ++++++++++++++++++++++++++++++++
 include/linux/firmware/meson/meson_sm.h |  32 ++++
 6 files changed, 309 insertions(+)
 create mode 100644 drivers/firmware/meson/Kconfig
 create mode 100644 drivers/firmware/meson/Makefile
 create mode 100644 drivers/firmware/meson/meson_sm.c
 create mode 100644 include/linux/firmware/meson/meson_sm.h
drivers/firmware/Kconfig +1 -0
index 6664f11..686e395 100644
@@ -199,5 +199,6 @@ config HAVE_ARM_SMCCC
 source "drivers/firmware/broadcom/Kconfig"
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
+source "drivers/firmware/meson/Kconfig"
 
 endmenu
drivers/firmware/Makefile +1 -0
index 474bada..fc4bb09 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_QCOM_SCM_32)	+= qcom_scm-32.o
 CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch armv7-a\n.arch_extension sec,-DREQUIRES_SEC=1) -march=armv7-a
 
 obj-y				+= broadcom/
+obj-y				+= meson/
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
 obj-$(CONFIG_UEFI_CPER)		+= efi/
drivers/firmware/meson/Kconfig new file +8 -0
new file mode 100644
index 0000000..fff11a3
@@ -0,0 +1,8 @@
+#
+# Amlogic Secure Monitor driver
+#
+config MESON_SM
+	bool
+	default ARCH_MESON
+	help
+	  Say y here to enable the Amlogic secure monitor driver
drivers/firmware/meson/Makefile new file +1 -0
new file mode 100644
index 0000000..9ab3884
@@ -0,0 +1 @@
+obj-$(CONFIG_MESON_SM) +=	meson_sm.o
drivers/firmware/meson/meson_sm.c new file +266 -0

266 lines not on this page · raw message

include/linux/firmware/meson/meson_sm.h new file +32 -0
new file mode 100644
index 0000000..81136b0
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_FW_H_
+#define _MESON_SM_FW_H_
+
+#define SM_EFUSE_READ		0
+#define SM_EFUSE_WRITE		1
+#define SM_EFUSE_USER_MAX	2
+
+struct meson_sm_firmware;
+
+int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
+		  u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
+			unsigned int b_size, unsigned int cmd_index,
+			u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
+		       unsigned int cmd_index, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4);
+struct meson_sm_firmware *meson_sm_get_fw(void);
+
+#endif /* _MESON_SM_FW_H_ */
Signature · 1 line
2.7.4
#2 lore raw

PATCH 1/6 firmware: Amlogic: Add secure monitor driver

Quoted 8 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Introduce a driver to provide calls into secure monitor mode.

In the Amlogic SoCs these calls are used for multiple reasons: access to NVMEM, set USB boot, enable JTAG, etc...

Hey Mark,
can you take a look to this patch? Not sure who is supposed to ACK / review it.

Thanks,

Signature · 1 line
Carlo Caione
#3 lore raw

PATCH 1/6 firmware: Amlogic: Add secure monitor driver

In reply to Carlo Caione

Hi,

Quoted 78 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Introduce a driver to provide calls into secure monitor mode.

In the Amlogic SoCs these calls are used for multiple reasons: access to NVMEM, set USB boot, enable JTAG, etc...

---
 drivers/firmware/Kconfig                |   1 +
 drivers/firmware/Makefile               |   1 +
 drivers/firmware/meson/Kconfig          |   8 +
 drivers/firmware/meson/Makefile         |   1 +
 drivers/firmware/meson/meson_sm.c       | 266 ++++++++++++++++++++++++++++++++
 include/linux/firmware/meson/meson_sm.h |  32 ++++
 6 files changed, 309 insertions(+)
 create mode 100644 drivers/firmware/meson/Kconfig
 create mode 100644 drivers/firmware/meson/Makefile
 create mode 100644 drivers/firmware/meson/meson_sm.c
 create mode 100644 include/linux/firmware/meson/meson_sm.h
drivers/firmware/Kconfig +1 -0
index 6664f11..686e395 100644
@@ -199,5 +199,6 @@ config HAVE_ARM_SMCCC
 source "drivers/firmware/broadcom/Kconfig"
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
+source "drivers/firmware/meson/Kconfig"
 
 endmenu
drivers/firmware/Makefile +1 -0
index 474bada..fc4bb09 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_QCOM_SCM_32)	+= qcom_scm-32.o
 CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch armv7-a\n.arch_extension sec,-DREQUIRES_SEC=1) -march=armv7-a
 
 obj-y				+= broadcom/
+obj-y				+= meson/
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
 obj-$(CONFIG_UEFI_CPER)		+= efi/
drivers/firmware/meson/Kconfig new file +8 -0
new file mode 100644
index 0000000..fff11a3
@@ -0,0 +1,8 @@
+#
+# Amlogic Secure Monitor driver
+#
+config MESON_SM
+	bool
+	default ARCH_MESON
+	help
+	  Say y here to enable the Amlogic secure monitor driver
drivers/firmware/meson/Makefile new file +1 -0
new file mode 100644
index 0000000..9ab3884
@@ -0,0 +1 @@
+obj-$(CONFIG_MESON_SM) +=	meson_sm.o
drivers/firmware/meson/meson_sm.c new file +7 -0
new file mode 100644
index 0000000..8e6b9dc
@@ -0,0 +1,266 @@
+/*
+ * Amlogic Secure Monitor driver
+ *
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

drivers/firmware/meson/meson_sm.c line 17

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+#include <asm/cacheflush.h>
+#include <asm/compiler.h>

As far as I can see, these aren't necessary. There aren't any variadic functions, there's no cache maintenance. I'm guessing compiler.h is left over from pre-SMCCCC code that used __asmeq().

drivers/firmware/meson/meson_sm.c line 21

Quoted 4 lines
drivers/firmware/meson/meson_sm.c new file +4 -0
+#include <linux/arm-smccc.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>

Likewise for ioport.h and module.h. All the io accessors we use are in io.h, and we only need export.h for EXPORT_SYMBOL().

drivers/firmware/meson/meson_sm.c line 22

Quoted 1 line
drivers/firmware/meson/meson_sm.c new file +1 -0
+#include <linux/platform_device.h>

This isn't a platform_driver. Was it meant to be? It would be nicer if so, using builtin_platform_driver and having the usual infrastrucutre drive the matching.

drivers/firmware/meson/meson_sm.c line 25

Quoted 3 lines
drivers/firmware/meson/meson_sm.c new file +3 -0
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/smp.h>

We don't appear to use anything from smp.h any more, so I beleive that can go too.

drivers/firmware/meson/meson_sm.c line 26

Quoted 1 line
drivers/firmware/meson/meson_sm.c new file +1 -0
+#include <linux/firmware/meson/meson_sm.h>

You also need <linux/printk.h>, and <linux/bug.h> for pr_* and WARN_ON respectively. I believe that <linux/types.h> is mean to be included for u32 and friends, though they're defined through some magic in transitive includes.

Quoted 34 lines
drivers/firmware/meson/meson_sm.c new file +34 -0
+
+struct meson_sm_cmd {
+	unsigned int index;
+	u32 smc_id;
+};
+#define CMD(d, s) { .index = (d), .smc_id = (s), }
+
+struct meson_sm_chip {
+	unsigned int shmem_size;
+	u32 cmd_shmem_in_base;
+	u32 cmd_shmem_out_base;
+	struct meson_sm_cmd cmd[];
+};
+
+struct meson_sm_chip gxbb_chip = {
+	.shmem_size		= 0x1000,
+	.cmd_shmem_in_base	= 0x82000020,
+	.cmd_shmem_out_base	= 0x82000021,
+	.cmd = {
+		CMD(SM_EFUSE_READ,	0x82000030),
+		CMD(SM_EFUSE_WRITE,	0x82000031),
+		CMD(SM_EFUSE_USER_MAX,	0x82000033),
+		{ /* sentinel */ },
+	},
+};
+
+struct meson_sm_firmware {
+	const struct meson_sm_chip *chip;
+	void __iomem *sm_shmem_in_base;
+	void __iomem *sm_shmem_out_base;
+};
+
+static struct meson_sm_firmware fw;
+

drivers/firmware/meson/meson_sm.c line 70

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+static u32 meson_sm_get_cmd(const struct meson_sm_chip *chip, unsigned int cmd_index)
+{
+	unsigned int i;
+
+	for (i = 0; chip->cmd[i].smc_id; i++)
+		if (chip->cmd[i].index == cmd_index)
+			return chip->cmd[i].smc_id;
+
+	return 0;
+}

Given that the sentinel has index == 0 and smc_id == 0, you could simplify this to something like:

	struct meson_sm_cmd *cmd = chip->cmd;

	while (cmd->smc_id && cmd->index != cmd_index)
		cmd++;

	return cmd->smc_id;
Quoted 9 lines
drivers/firmware/meson/meson_sm.c new file +9 -0
+
+static u32 __meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(cmd, arg0, arg1, arg2, arg3, arg4, 0, 0, &res);
+	return res.a0;
+}
+

drivers/firmware/meson/meson_sm.c line 89

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size)
+{
+	u32 sm_phy_base;
+
+	sm_phy_base = __meson_sm_call(cmd_shmem, 0, 0, 0, 0, 0);
+	if (!sm_phy_base)
+		return 0;
+
+	return ioremap_cache(sm_phy_base, size);
+}

Does this work on !4K page kernels?

Above I saw that for GXBB the shmem_size was 0x1000. I can imagine that mapping an extra 60K with cacheable attributes isn't going to be safe, even if the kernel happens to do that.

Either we need to handle that, or rule out working for !4K kernels (either with a Kconfig dependency, or some runtime detection).

Quoted 81 lines
drivers/firmware/meson/meson_sm.c new file +81 -0
+/**
+ * meson_sm_call - generic SMC32 call to the secure-monitor
+ *
+ * @fw:		Meson secure-monitor firmware pointer
+ * @cmd_index:	Index of the SMC32 function ID
+ * @ret:	Returned value
+ * @arg0:	SMC32 Argument 0
+ * @arg1:	SMC32 Argument 1
+ * @arg2:	SMC32 Argument 2
+ * @arg3:	SMC32 Argument 3
+ * @arg4:	SMC32 Argument 4
+ *
+ * Return:	0 on success, a negative value on error
+ */
+int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
+		  u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 cmd, lret;
+
+	if (!fw)
+		return -EINVAL;
+
+	cmd = meson_sm_get_cmd(fw->chip, cmd_index);
+	if (!cmd)
+		return -EINVAL;
+
+	lret = __meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (ret)
+		*ret = lret;
+
+	return 0;
+}
+EXPORT_SYMBOL(meson_sm_call);
+
+/**
+ * meson_sm_call_read - retrieve data from secure-monitor
+ *
+ * @fw:		Meson secure-monitor firmware pointer
+ * @buffer:	Buffer to store the retrieved data
+ * @cmd_index:	Index of the SMC32 function ID
+ * @arg0:	SMC32 Argument 0
+ * @arg1:	SMC32 Argument 1
+ * @arg2:	SMC32 Argument 2
+ * @arg3:	SMC32 Argument 3
+ * @arg4:	SMC32 Argument 4
+ *
+ * Return:	size of read data on success, a negative value on error
+ */
+int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
+		       unsigned int cmd_index, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	if (!fw->chip->cmd_shmem_out_base)
+		return -EINVAL;
+
+	if (meson_sm_call(fw, cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
+		return -EINVAL;
+
+	if (!size || size > fw->chip->shmem_size)
+		return -EINVAL;
+
+	if (buffer)
+		memcpy(buffer, fw->sm_shmem_out_base, size);
+
+	return size;
+}
+EXPORT_SYMBOL(meson_sm_call_read);
+
+/**
+ * meson_sm_call_write - send data to secure-monitor
+ *
+ * @fw:		Meson secure-monitor firmware pointer
+ * @buffer:	Buffer containing data to send
+ * @b_size:	Size of the data to send
+ * @cmd_index:	Index of the SMC32 function ID
+ * @arg0:	SMC32 Argument 0
+ * @arg1:	SMC32 Argument 1
+ * @arg2:	SMC32 Argument 2

drivers/firmware/meson/meson_sm.c line 181

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+ * @arg3:	SMC32 Argument 3
+ * @arg4:	SMC32 Argument 4
+ *
+ * Return:	size of sent data on success, a negative value on error
+ */
+int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
+			unsigned int b_size, unsigned int cmd_index,
+			u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;

The b_size vs size thing is somewhat confusing.

could we s/size/written/ and s/b_size/size/ ?

Quoted 25 lines
drivers/firmware/meson/meson_sm.c new file +25 -0
+
+	if (b_size > fw->chip->shmem_size)
+		return -EINVAL;
+
+	if (!fw->chip->cmd_shmem_in_base)
+		return -EINVAL;
+
+	memcpy(fw->sm_shmem_in_base, buffer, b_size);
+
+	if (meson_sm_call(fw, cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
+		return -EINVAL;
+
+	if (!size)
+		return -EINVAL;
+
+	return size;
+}
+EXPORT_SYMBOL(meson_sm_call_write);
+
+/**
+ * meson_sm_get_fw - get Meson firmware struct
+ *
+ * Return:		Meson secure-monitor firmware struct on success, NULL on error
+ */
+struct meson_sm_firmware *meson_sm_get_fw(void)

drivers/firmware/meson/meson_sm.c line 216

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+{
+	/*
+	 * Returns NULL is the firmware device is not ready.
+	 */
+	if (!fw.chip)
+		return NULL;
+
+	return &fw;
+}
+EXPORT_SYMBOL(meson_sm_get_fw);

Do any external callers actually need direct access to the fw struct fields? Or is this just so they can pass this to meson_sm_call and friends?

Given we have a singleton anyway, can't we just have the meson_sm_call* functions check whether fw is initialised, and return -ENOENT/-ENXIO if not?

Quoted 8 lines
drivers/firmware/meson/meson_sm.c new file +8 -0
+
+static const struct of_device_id meson_sm_ids[] = {
+	{ .compatible = "amlogic,meson-gxbb-sm", .data = &gxbb_chip },
+	{ /* sentinel */ },
+};
+
+int __init meson_sm_init(void)
+{

drivers/firmware/meson/meson_sm.c line 234

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+	const struct meson_sm_chip *chip;
+	const struct of_device_id *matched_np;
+	struct device_node *np;
+
+	np = of_find_matching_node_and_match(NULL, meson_sm_ids, &matched_np);
+	if (!np) {
+		pr_err("no matching node\n");
+		return -EINVAL;
+	}
+

This is going to be pointlessly noisy on every non-amlogic board out there.

Please make this a platform driver, such that this is only called when a node is present, avoiding some mess there.

drivers/firmware/meson/meson_sm.c line 239

Quoted 5 lines
drivers/firmware/meson/meson_sm.c new file +5 -0
+	chip = matched_np->data;
+	if (!chip) {
+		pr_err("unable to setup secure-monitor data\n");
+		return -EINVAL;
+	}

Using a platform driver would also avoid the necessity of this check, so long as you know each of_device_id entry has a valid data field.

drivers/firmware/meson/meson_sm.c line 246

Quoted 7 lines
drivers/firmware/meson/meson_sm.c new file +7 -0
+
+	if (chip->cmd_shmem_in_base) {
+		fw.sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,
+							 chip->shmem_size);
+		if (WARN_ON(!fw.sm_shmem_in_base))
+			goto out;
+	}

As above, I'm worried this may explode on !4K kernels (and also somewhat worried that it might not blow up here, but rather elsewhere at runtime).

drivers/firmware/meson/meson_sm.c line 256

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+
+	if (chip->cmd_shmem_out_base) {
+		fw.sm_shmem_out_base = meson_sm_map_shmem(chip->cmd_shmem_out_base,
+							  chip->shmem_size);
+		if (WARN_ON(!fw.sm_shmem_out_base))
+			goto out;
+	}
+
+	fw.chip = chip;
+	pr_info("secure-monitor enabled\n");

This may be ambiguous to those not familiar with this driver. It would be worth having:

#define pr_fmt(fmt) "meson-sm: " fmt

before the include of <linux/printk.h>, which would make it clear that the log messages came from this particular secure monitor driver.

drivers/firmware/meson/meson_sm.c line 264

Quoted 8 lines
drivers/firmware/meson/meson_sm.c new file +8 -0
+
+	return 0;
+
+out:
+	if (fw.sm_shmem_in_base)
+		iounmap(fw.sm_shmem_in_base);
+
+	return -EINVAL;

It would be nicer to have:

out_in_base:

	iounmap(fw.sm_shmem_in_base);

out:
return -EINVAL

With the earlier gotos fixed up appropriately.

Quoted 16 lines
drivers/firmware/meson/meson_sm.c new file +2 -0
+}
+device_initcall(meson_sm_init);
include/linux/firmware/meson/meson_sm.h new file +8 -0
new file mode 100644
index 0000000..81136b0
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *

include/linux/firmware/meson/meson_sm.h line 18

Quoted 10 lines
include/linux/firmware/meson/meson_sm.h new file +10 -0
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_FW_H_
+#define _MESON_SM_FW_H_
+
+#define SM_EFUSE_READ		0
+#define SM_EFUSE_WRITE		1
+#define SM_EFUSE_USER_MAX	2

This looks like enum material, even if only for the definitions here.

include/linux/firmware/meson/meson_sm.h line 30

Quoted 12 lines
include/linux/firmware/meson/meson_sm.h new file +12 -0
+
+struct meson_sm_firmware;
+
+int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
+		  u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
+			unsigned int b_size, unsigned int cmd_index,
+			u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
+		       unsigned int cmd_index, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4);
+struct meson_sm_firmware *meson_sm_get_fw(void);

As above, I'm not sure if it makes sense for meson_sm_firmware to leak into drivers, though you may have a use-case for that describe in a previous bit of reply.

Thanks,
Mark.

#4 lore raw

PATCH 1/6 firmware: Amlogic: Add secure monitor driver

Quoted 3 lines · Mark Rutland

Hi,

On Sun, Jun 19, 2016 at 02:38:59PM +0200, Carlo Caione wrote:

[...]

Quoted 7 lines

drivers/firmware/meson/meson_sm.c line 17

Quoted 3 lines
drivers/firmware/meson/meson_sm.c new file +3 -0
+#include <stdarg.h>
+#include <asm/cacheflush.h>
+#include <asm/compiler.h>

As far as I can see, these aren't necessary. There aren't any variadic functions, there's no cache maintenance. I'm guessing compiler.h is left over from pre-SMCCCC code that used __asmeq().

Also I forgot to clean-up the headers list from the previous iterations.

Quoted 7 lines

drivers/firmware/meson/meson_sm.c line 21

Quoted 4 lines
drivers/firmware/meson/meson_sm.c new file +4 -0
+#include <linux/arm-smccc.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>

Likewise for ioport.h and module.h. All the io accessors we use are in io.h, and we only need export.h for EXPORT_SYMBOL().

ok

Quoted 5 lines
Quoted 1 line

+#include <linux/platform_device.h>

This isn't a platform_driver. Was it meant to be? It would be nicer if so, using builtin_platform_driver and having the usual infrastrucutre drive the matching.

It was a platform driver in the first versions but I changed to this form after Rob suggested to have it in the /firmware node and without compatibility to the "simple-bus".

Quoted 6 lines

drivers/firmware/meson/meson_sm.c line 25

Quoted 3 lines
drivers/firmware/meson/meson_sm.c new file +3 -0
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/smp.h>

We don't appear to use anything from smp.h any more, so I beleive that can go too.

ok

Quoted 6 lines
Quoted 1 line

+#include <linux/firmware/meson/meson_sm.h>

You also need <linux/printk.h>, and <linux/bug.h> for pr_* and WARN_ON respectively. I believe that <linux/types.h> is mean to be included for u32 and friends, though they're defined through some magic in transitive includes.

ok

[...]

Quoted 14 lines

drivers/firmware/meson/meson_sm.c line 70

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+static u32 meson_sm_get_cmd(const struct meson_sm_chip *chip, unsigned int cmd_index)
+{
+	unsigned int i;
+
+	for (i = 0; chip->cmd[i].smc_id; i++)
+		if (chip->cmd[i].index == cmd_index)
+			return chip->cmd[i].smc_id;
+
+	return 0;
+}

Given that the sentinel has index == 0 and smc_id == 0, you could simplify this to something like:

Quoted 6 lines
	struct meson_sm_cmd *cmd = chip->cmd;

	while (cmd->smc_id && cmd->index != cmd_index)
		cmd++;

	return cmd->smc_id;

yeah, better I think

Quoted 22 lines
Quoted 9 lines
drivers/firmware/meson/meson_sm.c new file +9 -0
+
+static u32 __meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(cmd, arg0, arg1, arg2, arg3, arg4, 0, 0, &res);
+	return res.a0;
+}
+

drivers/firmware/meson/meson_sm.c line 89

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+static void __iomem *meson_sm_map_shmem(u32 cmd_shmem, unsigned int size)
+{
+	u32 sm_phy_base;
+
+	sm_phy_base = __meson_sm_call(cmd_shmem, 0, 0, 0, 0, 0);
+	if (!sm_phy_base)
+		return 0;
+
+	return ioremap_cache(sm_phy_base, size);
+}

Does this work on !4K page kernels?

Quoted 3 lines

Above I saw that for GXBB the shmem_size was 0x1000. I can imagine that mapping an extra 60K with cacheable attributes isn't going to be safe, even if the kernel happens to do that.

Agree

Quoted 2 lines

Either we need to handle that, or rule out working for !4K kernels (either with a Kconfig dependency, or some runtime detection).

Probably it's better to stay on the safe side and just to rule !4K kernels out with Kconfig

[...]

Quoted 11 lines

drivers/firmware/meson/meson_sm.c line 181

Quoted 7 lines

+ * Return: size of sent data on success, a negative value on error
+ */

drivers/firmware/meson/meson_sm.c new file +5 -0
+int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
+			unsigned int b_size, unsigned int cmd_index,
+			u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;

The b_size vs size thing is somewhat confusing.

could we s/size/written/ and s/b_size/size/ ?

ok

Quoted 40 lines
Quoted 25 lines
drivers/firmware/meson/meson_sm.c new file +25 -0
+
+	if (b_size > fw->chip->shmem_size)
+		return -EINVAL;
+
+	if (!fw->chip->cmd_shmem_in_base)
+		return -EINVAL;
+
+	memcpy(fw->sm_shmem_in_base, buffer, b_size);
+
+	if (meson_sm_call(fw, cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
+		return -EINVAL;
+
+	if (!size)
+		return -EINVAL;
+
+	return size;
+}
+EXPORT_SYMBOL(meson_sm_call_write);
+
+/**
+ * meson_sm_get_fw - get Meson firmware struct
+ *
+ * Return:		Meson secure-monitor firmware struct on success, NULL on error
+ */
+struct meson_sm_firmware *meson_sm_get_fw(void)

drivers/firmware/meson/meson_sm.c line 216

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+{
+	/*
+	 * Returns NULL is the firmware device is not ready.
+	 */
+	if (!fw.chip)
+		return NULL;
+
+	return &fw;
+}
+EXPORT_SYMBOL(meson_sm_get_fw);

Do any external callers actually need direct access to the fw struct fields? Or is this just so they can pass this to meson_sm_call and friends?

Quoted 3 lines

Given we have a singleton anyway, can't we just have the meson_sm_call* functions check whether fw is initialised, and return -ENOENT/-ENXIO if not?

Yes, the meson_sm_get_fw() was used to enforce probe ordering when the driver was a platform driver. Since this is now probed on device_initcall() I think we can safely remove this.

Quoted 13 lines
Quoted 13 lines
drivers/firmware/meson/meson_sm.c new file +13 -0
+
+static const struct of_device_id meson_sm_ids[] = {
+	{ .compatible = "amlogic,meson-gxbb-sm", .data = &gxbb_chip },
+	{ /* sentinel */ },
+};
+
+int __init meson_sm_init(void)
+{
+	const struct meson_sm_chip *chip;
+	const struct of_device_id *matched_np;
+	struct device_node *np;
+
+	np = of_find_matching_node_and_match(NULL, meson_sm_ids, &matched_np);
Quoted 8 lines

drivers/firmware/meson/meson_sm.c line 234

Quoted 5 lines
drivers/firmware/meson/meson_sm.c new file +5 -0
+	if (!np) {
+		pr_err("no matching node\n");
+		return -EINVAL;
+	}
+

This is going to be pointlessly noisy on every non-amlogic board out there.

ouch, right

Quoted 2 lines

Please make this a platform driver, such that this is only called when a node is present, avoiding some mess there.

Since Rob required this to be under /firmware (and using no "simple-bus" compatible to trigger the automatic creation) making it a platform driver just adds a lot of boilerplate code. If this doesn't mean a NACK on your side, I still would leave the code as is with the device_initcall() calling the init.

Quoted 9 lines

drivers/firmware/meson/meson_sm.c line 239

Quoted 5 lines
drivers/firmware/meson/meson_sm.c new file +5 -0
+	chip = matched_np->data;
+	if (!chip) {
+		pr_err("unable to setup secure-monitor data\n");
+		return -EINVAL;
+	}

Using a platform driver would also avoid the necessity of this check, so long as you know each of_device_id entry has a valid data field.

Quoted 11 lines

drivers/firmware/meson/meson_sm.c line 246

Quoted 7 lines
drivers/firmware/meson/meson_sm.c new file +7 -0
+
+	if (chip->cmd_shmem_in_base) {
+		fw.sm_shmem_in_base = meson_sm_map_shmem(chip->cmd_shmem_in_base,
+							 chip->shmem_size);
+		if (WARN_ON(!fw.sm_shmem_in_base))
+			goto out;
+	}

As above, I'm worried this may explode on !4K kernels (and also somewhat worried that it might not blow up here, but rather elsewhere at runtime).

ok

Quoted 14 lines

drivers/firmware/meson/meson_sm.c line 256

Quoted 10 lines
drivers/firmware/meson/meson_sm.c new file +10 -0
+
+	if (chip->cmd_shmem_out_base) {
+		fw.sm_shmem_out_base = meson_sm_map_shmem(chip->cmd_shmem_out_base,
+							  chip->shmem_size);
+		if (WARN_ON(!fw.sm_shmem_out_base))
+			goto out;
+	}
+
+	fw.chip = chip;
+	pr_info("secure-monitor enabled\n");

This may be ambiguous to those not familiar with this driver. It would be worth having:

Quoted 4 lines

#define pr_fmt(fmt) "meson-sm: " fmt

before the include of <linux/printk.h>, which would make it clear that the log messages came from this particular secure monitor driver.

good idea

Quoted 11 lines

drivers/firmware/meson/meson_sm.c line 264

Quoted 8 lines
drivers/firmware/meson/meson_sm.c new file +8 -0
+
+	return 0;
+
+out:
+	if (fw.sm_shmem_in_base)
+		iounmap(fw.sm_shmem_in_base);
+
+	return -EINVAL;

It would be nicer to have:

Quoted 6 lines

out_in_base:

	iounmap(fw.sm_shmem_in_base);

out:
return -EINVAL

With the earlier gotos fixed up appropriately.

agreed

Quoted 20 lines
Quoted 20 lines
(quoted diff) +2 -0
+}
+device_initcall(meson_sm_init);
include/linux/firmware/meson/meson_sm.h new file +12 -0
new file mode 100644
index 0000000..81136b0
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
Quoted 8 lines

include/linux/firmware/meson/meson_sm.h line 18

Quoted 6 lines
include/linux/firmware/meson/meson_sm.h new file +6 -0
+#ifndef _MESON_SM_FW_H_
+#define _MESON_SM_FW_H_
+
+#define SM_EFUSE_READ		0
+#define SM_EFUSE_WRITE		1
+#define SM_EFUSE_USER_MAX	2

This looks like enum material, even if only for the definitions here.

ok

Quoted 8 lines
Quoted 8 lines
include/linux/firmware/meson/meson_sm.h new file +8 -0
+
+struct meson_sm_firmware;
+
+int meson_sm_call(struct meson_sm_firmware *fw, unsigned int cmd_index,
+		  u32 *ret, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_write(struct meson_sm_firmware *fw, void *buffer,
+			unsigned int b_size, unsigned int cmd_index,
+			u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
Quoted 8 lines

include/linux/firmware/meson/meson_sm.h line 30

Quoted 4 lines
include/linux/firmware/meson/meson_sm.h new file +4 -0
+int meson_sm_call_read(struct meson_sm_firmware *fw, void *buffer,
+		       unsigned int cmd_index, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4);
+struct meson_sm_firmware *meson_sm_get_fw(void);

As above, I'm not sure if it makes sense for meson_sm_firmware to leak into drivers, though you may have a use-case for that describe in a previous bit of reply.

Not really, as written before that was used to enforce probe ordering. I'll take that out in the next revision.

Thank you for your review,

Signature · 1 line
Carlo Caione
#5 lore raw

PATCH 1/6 firmware: Amlogic: Add secure monitor driver

Hi,

Quoted 14 lines · Carlo Caione
Quoted 10 lines · Mark Rutland

drivers/firmware/meson/meson_sm.c line 234

Quoted 6 lines · Carlo Caione
drivers/firmware/meson/meson_sm.c new file +6 -0
+	np = of_find_matching_node_and_match(NULL, meson_sm_ids, &matched_np);
+	if (!np) {
+		pr_err("no matching node\n");
+		return -EINVAL;
+	}
+

This is going to be pointlessly noisy on every non-amlogic board out there.

ouch, right

Quoted 8 lines
Quoted 2 lines

Please make this a platform driver, such that this is only called when a node is present, avoiding some mess there.

Since Rob required this to be under /firmware (and using no "simple-bus" compatible to trigger the automatic creation) making it a platform driver just adds a lot of boilerplate code. If this doesn't mean a NACK on your side, I still would leave the code as is with the device_initcall() calling the init.

Ok. So long as this isn't noisy where the node is not present, that's fine by me.

Thanks,
Mark.

#6 lore raw

PATCH 2/6 documentation: Add secure monitor bindings documentation

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add the binding documentation for the Amlogic secure monitor driver.

---
 .../devicetree/bindings/firmware/meson/meson_sm.txt       | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
Documentation/devicetree/bindings/firmware/meson/meson_sm.txt new file +15 -0
new file mode 100644
index 0000000..c248cd4
@@ -0,0 +1,15 @@
+* Amlogic Secure Monitor
+
+In the Amlogic SoCs the Secure Monitor code is used to provide access to the
+NVMEM, enable JTAG, set USB boot, etc...
+
+Required properties for the secure monitor node:
+- compatible: Should be "amlogic,meson-gxbb-sm"
+
+Example:
+
+	firmware {
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
Signature · 1 line
2.7.4
maintainer
#7 lore raw

PATCH 2/6 documentation: Add secure monitor bindings documentation

Quoted 9 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Add the binding documentation for the Amlogic secure monitor driver.

---
 .../devicetree/bindings/firmware/meson/meson_sm.txt       | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt

Please add acks when reposting.

Rob

#8 lore raw

PATCH 2/6 documentation: Add secure monitor bindings documentation

Quoted 5 lines · Rob Herring
Quoted 4 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Add the binding documentation for the Amlogic secure monitor driver.

Quoted 7 lines
Quoted 5 lines
---
 .../devicetree/bindings/firmware/meson/meson_sm.txt       | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt

Please add acks when reposting.

I didn't add your ACK since the patch is slightly different. I'll add it back in the next revision.

Thanks,

Signature · 1 line
Carlo Caione  |  +39.340.80.30.096  |  Endless
#9 lore raw

PATCH 3/6 ARM64: dts: amlogic: gxbb: Enable secure monitor

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add the secure monitor node in the Amlogic Meson GXBB DTSI file to enable it.

---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +6 -0
index 76b3b6d..407f24c 100644
@@ -98,6 +98,12 @@
 		method = "smc";
 	};
 
+	firmware {
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
Signature · 1 line
2.7.4
#10 lore raw

PATCH 4/6 nvmem: amlogic: Add Amlogic Meson EFUSE driver

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add Amlogic EFUSE driver to access hardware data like ethernet address, serial number or IDs.

---
 drivers/nvmem/Kconfig       |  11 ++++
 drivers/nvmem/Makefile      |   2 +
 drivers/nvmem/meson-efuse.c | 130 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/nvmem/meson-efuse.c
drivers/nvmem/Kconfig +11 -0
index ca52952..ef17bc9 100644
@@ -102,4 +102,15 @@ config NVMEM_VF610_OCOTP
 	  This driver can also be build as a module. If so, the module will
 	  be called nvmem-vf610-ocotp.
 
+config MESON_EFUSE
+	tristate "Amlogic eFuse Support"
+	depends on ARCH_MESON || COMPILE_TEST
+	select REGMAP_MMIO
+	help
+	  This is a driver to retrieve specific values from the eFuse found on
+	  the Amlogic Meson SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem_meson_efuse.
+
 endif
drivers/nvmem/Makefile +2 -0
index 45ab1ae..8f942a0 100644
@@ -22,3 +22,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID)	+= nvmem_sunxi_sid.o
 nvmem_sunxi_sid-y		:= sunxi_sid.o
 obj-$(CONFIG_NVMEM_VF610_OCOTP)	+= nvmem-vf610-ocotp.o
 nvmem-vf610-ocotp-y		:= vf610-ocotp.o
+obj-$(CONFIG_MESON_EFUSE)	+= nvmem_meson_efuse.o
+nvmem_meson_efuse-y		:= meson-efuse.o
drivers/nvmem/meson-efuse.c new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
2.7.4
#11 lore raw

PATCH 4/6 nvmem: amlogic: Add Amlogic Meson EFUSE driver

Hi Carlo,

Quoted 18 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Add Amlogic EFUSE driver to access hardware data like ethernet address, serial number or IDs.

---
  drivers/nvmem/Kconfig       |  11 ++++
  drivers/nvmem/Makefile      |   2 +
  drivers/nvmem/meson-efuse.c | 130 ++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 143 insertions(+)

create mode 100644 drivers/nvmem/meson-efuse.c

drivers/nvmem/Kconfig +0 -0
index ca52952..ef17bc9 100644

drivers/nvmem/Kconfig config NVMEM_VF610_OCOTP · line 108

Quoted 7 lines
drivers/nvmem/Kconfig +4 -0
@@ -102,4 +102,15 @@ config NVMEM_VF610_OCOTP
  	  This driver can also be build as a module. If so, the module will
  	  be called nvmem-vf610-ocotp.
 
+config MESON_EFUSE
+	tristate "Amlogic eFuse Support"
+	depends on ARCH_MESON || COMPILE_TEST
+	select REGMAP_MMIO

NVMEM recently moved out of using regmap, as regmap did not provide better abstraction, could you rebase your patch on top of mainline.

Thanks,
srini

Quoted 155 lines
drivers/nvmem/Kconfig +7 -0
+	help
+	  This is a driver to retrieve specific values from the eFuse found on
+	  the Amlogic Meson SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem_meson_efuse.
+
  endif
drivers/nvmem/Makefile +2 -0
index 45ab1ae..8f942a0 100644
@@ -22,3 +22,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID)	+= nvmem_sunxi_sid.o
  nvmem_sunxi_sid-y		:= sunxi_sid.o
  obj-$(CONFIG_NVMEM_VF610_OCOTP)	+= nvmem-vf610-ocotp.o
  nvmem-vf610-ocotp-y		:= vf610-ocotp.o
+obj-$(CONFIG_MESON_EFUSE)	+= nvmem_meson_efuse.o
+nvmem_meson_efuse-y		:= meson-efuse.o
drivers/nvmem/meson-efuse.c new file +130 -0
new file mode 100644
index 0000000..7c80e1c
@@ -0,0 +1,130 @@
+/*
+ * Amlogic eFuse Driver
+ *
+ * Copyright (c) 2016 Endless Computers, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#include <linux/firmware/meson/meson_sm.h>
+
+static struct meson_sm_firmware *fw;
+
+static int meson_efuse_write(void *context, const void *data, size_t count)
+{
+	/* Nothing TBD, Read-Only */
+	return 0;
+}
+
+static int meson_efuse_read(void *context,
+			    const void *reg, size_t reg_size,
+			    void *val, size_t val_size)
+{
+	unsigned int offset = *(u32 *)reg;
+	u8 *buf = val;
+	int ret;
+
+	ret = meson_sm_call_read(fw, buf, SM_EFUSE_READ, offset,
+				 val_size, 0, 0, 0);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static struct nvmem_config econfig = {
+	.name = "meson-efuse",
+	.owner = THIS_MODULE,
+	.read_only = true,
+};
+
+static struct regmap_bus meson_efuse_bus = {
+	.read = meson_efuse_read,
+	.write = meson_efuse_write,
+	.reg_format_endian_default = REGMAP_ENDIAN_NATIVE,
+	.val_format_endian_default = REGMAP_ENDIAN_NATIVE,
+};
+
+static struct regmap_config meson_efuse_regmap_config = {
+	.reg_bits = 32,
+	.reg_stride = 1,
+	.val_bits = 8,
+};
+
+static const struct of_device_id meson_efuse_match[] = {
+	{ .compatible = "amlogic,meson-gxbb-efuse", },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, meson_efuse_match);
+
+static int meson_efuse_probe(struct platform_device *pdev)
+{
+	struct nvmem_device *nvmem;
+	struct regmap *regmap;
+	unsigned int size;
+
+	fw = meson_sm_get_fw();
+	if (!fw)
+		return -EPROBE_DEFER;
+
+	if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
+		return -EINVAL;
+	meson_efuse_regmap_config.max_register = size - 1;
+
+	regmap = devm_regmap_init(&pdev->dev, &meson_efuse_bus,
+				  NULL, &meson_efuse_regmap_config);
+	if (IS_ERR(regmap)) {
+		dev_err(&pdev->dev, "regmap init failed\n");
+		return PTR_ERR(regmap);
+	}
+
+	econfig.dev = &pdev->dev;
+	nvmem = nvmem_register(&econfig);
+	if (IS_ERR(nvmem))
+		return PTR_ERR(nvmem);
+
+	platform_set_drvdata(pdev, nvmem);
+
+	return 0;
+}
+
+static int meson_efuse_remove(struct platform_device *pdev)
+{
+	struct nvmem_device *nvmem = platform_get_drvdata(pdev);
+
+	return nvmem_unregister(nvmem);
+}
+
+static struct platform_driver meson_efuse_driver = {
+	.probe = meson_efuse_probe,
+	.remove = meson_efuse_remove,
+	.driver = {
+		.name = "meson-efuse",
+		.of_match_table = meson_efuse_match,
+	},
+};
+
+module_platform_driver(meson_efuse_driver);
+
+MODULE_AUTHOR("Carlo Caione <[email protected]>");
+MODULE_DESCRIPTION("Amlogic Meson NVMEM driver");
+MODULE_LICENSE("GPL v2");
#12 lore raw

PATCH 5/6 documentation: Add nvmem bindings documentation

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

This patch add the bindings document of Amlogic eFuse driver.

---
 .../devicetree/bindings/nvmem/amlogic-efuse.txt    | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt
Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt new file +39 -0
new file mode 100644
index 0000000..fafd85b
@@ -0,0 +1,39 @@
+= Amlogic eFuse device tree bindings =
+
+Required properties:
+- compatible: should be "amlogic,meson-gxbb-efuse"
+
+= Data cells =
+Are child nodes of eFuse, bindings of which as described in
+bindings/nvmem/nvmem.txt
+
+Example:
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		sn: sn at 14 {
+			reg = <0x14 0x10>;
+		};
+
+		eth_mac: eth_mac at 34 {
+			reg = <0x34 0x10>;
+		};
+
+		bid: bid at 46 {
+			reg = <0x46 0x30>;
+		};
+	};
+
+= Data consumers =
+Are device nodes which consume nvmem data cells.
+
+For example:
+
+	eth_mac {
+		...
+		nvmem-cells = <&eth_mac>;
+		nvmem-cell-names = "eth_mac";
+	};
Signature · 1 line
2.7.4
maintainer
#13 lore raw

PATCH 5/6 documentation: Add nvmem bindings documentation

Quoted 9 lines · Carlo Caione

From: Carlo Caione <[email protected]>

This patch add the bindings document of Amlogic eFuse driver.

---
 .../devicetree/bindings/nvmem/amlogic-efuse.txt    | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt
#14 lore raw

PATCH 6/6 ARM64: dts: amlogic: gxbb: Enable NVMEM

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add the NVMEM device node in the DTSI.

---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +18 -0
index 407f24c..0e0f7c0 100644
@@ -104,6 +104,24 @@
 		};
 	};
 
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		sn: sn at 14 {
+			reg = <0x14 0x10>;
+		};
+
+		eth_mac: eth_mac at 34 {
+			reg = <0x34 0x10>;
+		};
+
+		bid: bid at 46 {
+			reg = <0x46 0x30>;
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
Signature · 1 line
2.7.4