Now that we have the EEPROM framework, we can consolidate the common driver
code. Move the driver to the framework, and hopefully, it will fix the sysfs
file creation race.

Signed-off-by: Maxime Ripard <maxime.ripard@xxxxxxxxxxxxxxxxxx>
[srinivas.kandagatla: Moved to regmap based EEPROM framework]
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxx>
---
 Documentation/devicetree/bindings/eeprom/allwinner,sunxi-sid.txt |   21 +++
 Documentation/devicetree/bindings/misc/allwinner,sunxi-sid.txt   |   17 --
 drivers/eeprom/Kconfig                                           |   11 +
 drivers/eeprom/Makefile                                          |    2 
 drivers/eeprom/sunxi-sid.c                                       |   64 ++++++++++
 drivers/misc/eeprom/Kconfig                                      |   13 --
 drivers/misc/eeprom/Makefile                                     |    1 
 7 files changed, 98 insertions(+), 31 deletions(-)
 delete mode 100644 Documentation/ABI/testing/sysfs-driver-sunxi-sid
 create mode 100644 Documentation/devicetree/bindings/eeprom/allwinner,sunxi-sid.txt
 delete mode 100644 Documentation/devicetree/bindings/misc/allwinner,sunxi-sid.txt
 create mode 100644 drivers/eeprom/sunxi-sid.c
 delete mode 100644 drivers/misc/eeprom/sunxi_sid.c

Index: linux-4.4.39-rt50/Documentation/devicetree/bindings/eeprom/allwinner,sunxi-sid.txt
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-4.4.39-rt50/Documentation/devicetree/bindings/eeprom/allwinner,sunxi-sid.txt	2017-01-26 23:47:59.939197579 +0100
@@ -0,0 +1,21 @@
+Allwinner sunxi-sid
+
+Required properties:
+- compatible: "allwinner,sun4i-a10-sid" or "allwinner,sun7i-a20-sid"
+- reg: Should contain registers location and length
+
+= Data cells =
+Are child nodes of qfprom, bindings of which as described in
+bindings/eeprom/eeprom.txt
+
+Example for sun4i:
+	sid@01c23800 {
+		compatible = "allwinner,sun4i-a10-sid";
+		reg = <0x01c23800 0x10>
+	};
+
+Example for sun7i:
+	sid@01c23800 {
+		compatible = "allwinner,sun7i-a20-sid";
+		reg = <0x01c23800 0x200>
+	};
Index: linux-4.4.39-rt50/drivers/eeprom/Kconfig
===================================================================
--- linux-4.4.39-rt50.orig/drivers/eeprom/Kconfig	2017-01-26 23:47:02.000000000 +0100
+++ linux-4.4.39-rt50/drivers/eeprom/Kconfig	2017-01-26 23:47:59.995197354 +0100
@@ -22,4 +22,15 @@
 	  This driver can also be built as a module. If so, the module
 	  will be called eeprom-qfprom.
 
+config EEPROM_SUNXI_SID
+	tristate "Allwinner SoCs SID support"
+	depends on ARCH_SUNXI
+	select REGMAP_MMIO
+	help
+	  This is a driver for the 'security ID' available on various Allwinner
+	  devices.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called eeprom-sunxi-sid.
+
 endif
Index: linux-4.4.39-rt50/drivers/eeprom/Makefile
===================================================================
--- linux-4.4.39-rt50.orig/drivers/eeprom/Makefile	2017-01-26 23:47:02.000000000 +0100
+++ linux-4.4.39-rt50/drivers/eeprom/Makefile	2017-01-26 23:48:00.028197223 +0100
@@ -9,3 +9,5 @@
 # Devices
 obj-$(CONFIG_QCOM_QFPROM)	+= eeprom_qfprom.o
 eeprom_qfprom-y			:= qfprom.o
+obj-$(CONFIG_EEPROM_SUNXI_SID)	+= eeprom-sunxi-sid.o
+eeprom-sunxi-sid-y		:= sunxi-sid.o
Index: linux-4.4.39-rt50/drivers/eeprom/sunxi-sid.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-4.4.39-rt50/drivers/eeprom/sunxi-sid.c	2017-01-26 23:48:00.056197111 +0100
@@ -0,0 +1,64 @@
+/*
+ * Allwinner sunXi SoCs Security ID support.
+ *
+ * Copyright (c) 2013 Oliver Schinagl <oliver@xxxxxxxxxxx>
+ * Copyright (C) 2014 Maxime Ripard <maxime.ripard@xxxxxxxxxxxxxxxxxx>
+ *
+ * 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/module.h>
+#include <linux/of.h>
+#include "eeprom-mmio.h"
+
+static bool sunxi_sid_writeable_reg(struct device *dev, unsigned int reg)
+{
+	return false;
+}
+
+static struct eeprom_config econfig = {
+	.name = "sunix-sid",
+	.owner = THIS_MODULE,
+};
+
+static struct regmap_config sunxi_sid_regmap_config = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.writeable_reg = sunxi_sid_writeable_reg,
+};
+
+static struct eeprom_mmio_data sunxi_data = {
+	.eeprom_config = &econfig,
+	.regmap_config = &sunxi_sid_regmap_config,
+};
+
+static const struct of_device_id sunxi_sid_of_match[] = {
+	{ .compatible = "allwinner,sun4i-a10-sid", .data = &sunxi_data},
+	{ .compatible = "allwinner,sun7i-a20-sid", .data = &sunxi_data},
+	{/* sentinel */},
+};
+MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);
+
+static struct platform_driver sunxi_sid_driver = {
+	.probe = eeprom_mmio_probe,
+	.remove = eeprom_mmio_remove,
+	.driver = {
+		.name = "eeprom-sunxi-sid",
+		.of_match_table = sunxi_sid_of_match,
+	},
+};
+module_platform_driver(sunxi_sid_driver);
+
+MODULE_AUTHOR("Oliver Schinagl <oliver@xxxxxxxxxxx>");
+MODULE_DESCRIPTION("Allwinner sunxi security id driver");
+MODULE_LICENSE("GPL");