All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Framework for exporting System-on-Chip information via sysfs
@ 2011-07-12 13:08 Lee Jones
  2011-07-12 13:08 ` [PATCH 2/3] mach-ux500: export " Lee Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Lee Jones @ 2011-07-12 13:08 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/base/Kconfig    |   10 +++++
 drivers/base/Makefile   |    1 +
 drivers/base/soc.c      |   98 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sys_soc.h |   45 +++++++++++++++++++++
 4 files changed, 154 insertions(+), 0 deletions(-)
 create mode 100644 drivers/base/soc.c
 create mode 100644 include/linux/sys_soc.h

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d57e8d0..2feab2b 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -168,4 +168,14 @@ config SYS_HYPERVISOR
 	bool
 	default n
 
+config ARCH_NO_SYSDEV_OPS
+	bool
+	---help---
+	  To be selected by architectures that don't use sysdev class or
+	  sysdev driver power management (suspend/resume) and shutdown
+	  operations.
+
+config SYS_SOC
+	bool
+
 endmenu
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 4c5701c..a0d246d 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -18,6 +18,7 @@ ifeq ($(CONFIG_SYSFS),y)
 obj-$(CONFIG_MODULES)	+= module.o
 endif
 obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
+obj-$(CONFIG_SYS_SOC) += soc.o
 
 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
 
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
new file mode 100644
index 0000000..30659f4
--- /dev/null
+++ b/drivers/base/soc.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2011
+ *
+ * Author: Lee Jones <lee.jones@linaro.org> for ST-Ericsson.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/stat.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+struct device_attribute soc_attrs[] = {
+	__ATTR(machine,  S_IRUGO, NULL, NULL),
+	__ATTR(family,   S_IRUGO, NULL, NULL),
+	__ATTR(soc_id,   S_IRUGO, NULL, NULL),
+	__ATTR(revision, S_IRUGO, NULL, NULL),
+	__ATTR_NULL,
+};
+
+const char *soc_names[] = { "1", "2", "3", "4", "5", "6", "7", "8" };
+static int soc_count = 0;
+
+static struct device soc_grandparent = {
+	.init_name = "soc",
+};
+
+static int soc_device_create_files(struct device *soc);
+static void soc_device_remove_files(struct device *soc);
+
+static int __init soc_device_create_files(struct device *soc)
+{
+	int ret = 0;
+	int i   = 0;
+
+	while (soc_attrs[i].attr.name != NULL) {
+		ret = device_create_file(soc, &soc_attrs[i++]);
+		if (ret)
+			goto out;
+	}
+	return ret;
+
+out:
+	soc_device_remove_files(soc);
+	return ret;
+}
+
+static void __exit soc_device_remove_files(struct device *soc)
+{
+	int i = 0;
+
+	while (soc_attrs[i++].attr.name != NULL)
+		device_remove_file(soc, &soc_attrs[i]);
+}
+
+int __init soc_device_register(struct device *soc_parent,
+			struct soc_callback_functions *soc_callbacks)
+{
+	int ret;
+
+	soc_attrs[MACHINE].show = soc_callbacks->get_machine_fn;
+	soc_attrs[FAMILY].show = soc_callbacks->get_family_fn;
+	soc_attrs[SOCID].show = soc_callbacks->get_soc_id_fn;
+	soc_attrs[REVISION].show = soc_callbacks->get_revision_fn;
+
+	if (!soc_count) {
+		/* Register top-level SoC device '/sys/devices/soc' */
+		ret = device_register(&soc_grandparent);
+		if (ret)
+			return ret;
+	}
+
+	soc_parent->init_name = soc_names[soc_count];
+	soc_parent->parent = &soc_grandparent;
+
+	ret = device_register(soc_parent);
+	if (ret)
+		return ret;
+
+	soc_device_create_files(soc_parent);
+
+	soc_count++;
+
+	return ret;
+}
+
+void __exit soc_device_unregister(struct device *soc_parent)
+{
+	/* Unregister and free SoC from sysfs */
+	soc_device_remove_files(soc_parent);
+	device_unregister(soc_parent);
+
+	if (--soc_count == 0)
+		/* Unregister top-level SoC device '/sys/devices/soc' */
+	device_unregister(&soc_grandparent);
+}
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
new file mode 100644
index 0000000..94d5707
--- /dev/null
+++ b/include/linux/sys_soc.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2011
+ * Author: Lee Jones <lee.jones@linaro.org> for ST-Ericsson.
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+#ifndef __SYS_SOC_H
+#define __SYS_SOC_H
+
+#include <linux/kobject.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+
+#define MAX_SOCS 8
+#define MACHINE  0
+#define FAMILY   1
+#define SOCID    2
+#define REVISION 3
+
+struct soc_callback_functions {
+	ssize_t (*get_machine_fn)(struct device *dev,
+				struct device_attribute *attr, char *buf);
+	ssize_t (*get_family_fn)(struct device *dev,
+				struct device_attribute *attr, char *buf);
+	ssize_t (*get_soc_id_fn)(struct device *dev,
+				struct device_attribute *attr, char *buf);
+	ssize_t (*get_revision_fn)(struct device *dev,
+				struct device_attribute *attr, char *buf);
+};
+
+/**
+ * soc_device_register - register SoC as a device
+ * @soc_attr: Array of sysfs file attributes
+ * @soc: Parent node '/sys/devices/soc'
+ */
+int soc_device_register(struct device *soc_parent,
+			struct soc_callback_functions *soc_callbacks);
+
+/**
+ *  soc_device_unregister - unregister SoC as a device
+ * @soc_attr: Array of sysfs file attributes
+ * @soc: Parent node '/sys/devices/soc'
+ */
+void soc_device_unregister(struct device *soc_parent);
+
+#endif /* __SYS_SOC_H */
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 27+ messages in thread
* [PATCH 0/3] Export valuable System-on-Chip information to user-space via sysfs
@ 2011-04-14 14:49 Lee Jones
  2011-04-14 14:49 ` [PATCH 2/3] mach-ux500: export System-on-Chip information " Lee Jones
  0 siblings, 1 reply; 27+ messages in thread
From: Lee Jones @ 2011-04-14 14:49 UTC (permalink / raw)
  To: linux-arm-kernel

This patch-set is based on Maxime Coquelin's <maxime.coquelin-nonst@stericsson.com> previous attempts. All advice has been taken and this is the resultant work. The main points taken into consideration are:
 * Ability to support multiple SoCs on any one device
 * Each SoC is registered as a _real_ device

Documentation/ABI/testing/sysfs-devices-soc |   16 +++++
 arch/arm/mach-ux500/Kconfig                 |    1 +
 arch/arm/mach-ux500/id.c                    |   96 +++++++++++++++++++++++++++
 drivers/base/Kconfig                        |    3 +
 drivers/base/Makefile                       |    1 +
 drivers/base/soc.c                          |   96 +++++++++++++++++++++++++++
 include/linux/sys_soc.h                     |   29 ++++++++
 7 files changed, 242 insertions(+), 0 deletions(-)

^ permalink raw reply	[flat|nested] 27+ messages in thread
* [PATCH 2/3] mach-ux500: export System-on-Chip information via sysfs
@ 2011-04-11 18:01 Lee Jones
  0 siblings, 0 replies; 27+ messages in thread
From: Lee Jones @ 2011-04-11 18:01 UTC (permalink / raw)
  To: linux-arm-kernel

From: Lee Jones <lee.jones@linaro.org>

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/mach-ux500/Kconfig |    1 +
 arch/arm/mach-ux500/id.c    |   96 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-ux500/Kconfig b/arch/arm/mach-ux500/Kconfig
index c6b2375..ffee422 100644
--- a/arch/arm/mach-ux500/Kconfig
+++ b/arch/arm/mach-ux500/Kconfig
@@ -25,6 +25,7 @@ config MACH_U8500
 	bool "U8500 Development platform"
 	depends on UX500_SOC_DB8500
 	select TPS6105X
+	select SYS_SOC
 	help
 	  Include support for the mop500 development platform.
 
diff --git a/arch/arm/mach-ux500/id.c b/arch/arm/mach-ux500/id.c
index d35122e..74492ee 100644
--- a/arch/arm/mach-ux500/id.c
+++ b/arch/arm/mach-ux500/id.c
@@ -2,12 +2,17 @@
  * Copyright (C) ST-Ericsson SA 2010
  *
  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * Author: Lee Jones <lee.jones@linaro.org> for ST-Ericsson
  * License terms: GNU General Public License (GPL) version 2
  */
 
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/sys_soc.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/platform_device.h>
 
 #include <asm/cputype.h>
 #include <asm/tlbflush.h>
@@ -105,3 +110,94 @@ void __init ux500_map_io(void)
 
 	ux500_print_soc_info(asicid);
 }
+
+#ifdef CONFIG_SYS_SOC
+#define U8500_BB_UID_BASE (U8500_BACKUPRAM1_BASE + 0xFC0)
+#define U8500_BB_UID_LENGTH 5
+
+static ssize_t ux500_get_family(struct device *dev,
+                                struct device_attribute *attr,
+                                char *buf)
+{
+	return sprintf(buf, "Ux500\n");
+}
+
+static ssize_t ux500_get_machine(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf)
+{
+	return sprintf(buf, "DB%4x\n", dbx500_partnumber());
+}
+
+static ssize_t ux500_get_soc_id(struct device *dev,
+                                struct device_attribute *attr,
+                                char *buf)
+{
+	void __iomem *uid_base;
+	int i;
+	ssize_t sz = 0;
+
+	if (dbx500_partnumber() == 0x8500) {
+		uid_base = __io_address(U8500_BB_UID_BASE);
+		for (i = 0; i < U8500_BB_UID_LENGTH; i++)
+			sz += sprintf(buf + sz, "%08x", readl(uid_base + i * sizeof(u32)));
+		sz += sprintf(buf + sz, "\n");
+	} else {
+		/* Don't know where it is located for U5500 */
+		sz = sprintf(buf, "N/A\n");
+	}
+
+	return sz;
+}
+
+static ssize_t ux500_get_revision(struct device *dev,
+                                  struct device_attribute *attr,
+                                  char *buf)
+{
+	unsigned int rev = dbx500_revision();
+
+	if (rev == 0x01)
+		return sprintf(buf, "%s\n", "ED");
+	else if (rev >= 0xA0)
+		return sprintf(buf, "%d.%d\n" , (rev >> 4) - 0xA + 1, rev & 0xf);
+
+	return sprintf(buf, "%s", "Unknown\n");
+}
+
+static ssize_t ux500_get_process(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf)
+{
+	if (dbx500_id.process == 0x00)
+		return sprintf(buf, "Standard\n");
+
+	return sprintf(buf, "%02xnm\n", dbx500_id.process);
+}
+
+struct device_attribute soc_one_attrs[] = {
+	__ATTR(machine,  S_IRUGO, ux500_get_machine,  NULL),
+	__ATTR(family,   S_IRUGO, ux500_get_family,   NULL),
+	__ATTR(soc_id,   S_IRUGO, ux500_get_soc_id,   NULL),
+	__ATTR(revision, S_IRUGO, ux500_get_revision, NULL),
+	__ATTR(process,  S_IRUGO, ux500_get_process,  NULL),
+	__ATTR_NULL,
+};
+
+struct device_attribute *each_soc_attrs[] = {
+	soc_one_attrs,
+	NULL,
+};
+
+static int __init ux500_soc_sysfs_init(void)
+{
+	return soc_device_register(each_soc_attrs, ARRAY_SIZE(each_soc_attrs));
+}
+module_init(ux500_soc_sysfs_init);
+
+static void __exit ux500_soc_sysfs_exit(void)
+{
+	return soc_device_unregister(each_soc_attrs, ARRAY_SIZE(each_soc_attrs));
+}
+module_exit(ux500_soc_sysfs_exit);
+
+#endif
-- 
1.7.4.1

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

end of thread, other threads:[~2011-07-15 14:02 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-12 13:08 [PATCH 1/3] Framework for exporting System-on-Chip information via sysfs Lee Jones
2011-07-12 13:08 ` [PATCH 2/3] mach-ux500: export " Lee Jones
2011-07-12 16:29   ` Saravana Kannan
2011-07-13  7:55     ` Lee Jones
2011-07-13 16:40       ` Saravana Kannan
2011-07-13 20:32         ` Greg KH
2011-07-13 20:51           ` Arnd Bergmann
2011-07-14  6:42             ` Lee Jones
2011-07-14 12:58               ` Arnd Bergmann
2011-07-14 13:04                 ` Lee Jones
2011-07-14 17:25             ` Saravana Kannan
2011-07-15  6:27               ` Lee Jones
2011-07-12 16:47   ` Arnd Bergmann
2011-07-13  8:10     ` Lee Jones
2011-07-13 13:42       ` Arnd Bergmann
2011-07-13 14:31         ` Lee Jones
2011-07-13 16:20           ` Arnd Bergmann
2011-07-12 13:08 ` [PATCH 3/3] Add documenation for new sysfs devices/soc functionallity Lee Jones
2011-07-12 14:13 ` [PATCH 1/3] Framework for exporting System-on-Chip information via sysfs Baruch Siach
2011-07-12 16:08   ` Greg KH
2011-07-13  7:16     ` Lee Jones
2011-07-13  7:53       ` Greg KH
2011-07-13  8:27         ` Lee Jones
2011-07-15 14:02 ` Arnd Bergmann
  -- strict thread matches above, loose matches on Subject: below --
2011-04-14 14:49 [PATCH 0/3] Export valuable System-on-Chip information to user-space " Lee Jones
2011-04-14 14:49 ` [PATCH 2/3] mach-ux500: export System-on-Chip information " Lee Jones
2011-04-17 18:40   ` Arnd Bergmann
2011-04-11 18:01 Lee Jones

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.