mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3 0/6] AIODEV subsystem
@ 2016-05-16 16:45 Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 1/6] drivers: Introduce " Andrey Smirnov
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:45 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Hi everyone,

Here's the third version of AIODEV patchset. The change list is the
following:

Changes since v2:

	- TEMPMON driver converted to use existing DT bindings

	- As a result of the above NVMEM subsystem was dropped

	- TEMPMON driver converted to use syscon_base_lookup_by_phandle

Changes since v1:

	- Patches fixed to use IIO DT bindings

	- Channel's index is now cached and no O(n) complex lookup is
          perfomed when a channel is queried by its index

	- Added GPL v2 headers

	- Incorporated Sascha's feedback to simplify code


Andrey Smirnov (5):
  RDU2: Add more peripheral reset code
  commands: Add 'hwmon' command
  syscon: Do not return NULL when driver is not selected
  syscon: Decrease driver registration priority
  aiodev: Add TEMPMON driver

Sascha Hauer (2):
  drivers: Introduce AIODEV subsystem
  aiodev: Add basic LM75 temperature driver

 arch/arm/boards/zii-imx6q-rdu2/board.c |  65 +++++++-
 arch/arm/dts/imx6q-zii-rdu2.dts        |   5 +
 arch/arm/dts/imx6qdl.dtsi              |  14 ++
 arch/arm/dts/imx6sx.dtsi               |  14 ++
 commands/Kconfig                       |   8 +
 commands/Makefile                      |   1 +
 commands/hwmon.c                       |  35 +++++
 drivers/Kconfig                        |   1 +
 drivers/Makefile                       |   2 +
 drivers/aiodev/Kconfig                 |  22 +++
 drivers/aiodev/Makefile                |   4 +
 drivers/aiodev/core.c                  | 148 +++++++++++++++++++
 drivers/aiodev/imx_thermal.c           | 216 +++++++++++++++++++++++++++
 drivers/aiodev/lm75.c                  | 262 +++++++++++++++++++++++++++++++++
 drivers/mfd/syscon.c                   |   2 +-
 include/aiodev.h                       |  59 ++++++++
 include/mfd/syscon.h                   |   4 +-
 17 files changed, 851 insertions(+), 11 deletions(-)
 create mode 100644 commands/hwmon.c
 create mode 100644 drivers/aiodev/Kconfig
 create mode 100644 drivers/aiodev/Makefile
 create mode 100644 drivers/aiodev/core.c
 create mode 100644 drivers/aiodev/imx_thermal.c
 create mode 100644 drivers/aiodev/lm75.c
 create mode 100644 include/aiodev.h

-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v3 1/6] drivers: Introduce AIODEV subsystem
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
@ 2016-05-16 16:45 ` Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 2/6] commands: Add 'hwmon' command Andrey Smirnov
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:45 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

From: Sascha Hauer <s.hauer@pengutronix.de>

AIODEV/Aiodevice is a analog I/O framework that can be thought of as a
simplified hybrid between 'hwmon' and 'IIO' subsystems of Linux kernel

This commit is very heavily based on 'iodevice' framework proposal
written by Sascha Hauer.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/Kconfig         |   1 +
 drivers/Makefile        |   2 +
 drivers/aiodev/Kconfig  |   8 +++
 drivers/aiodev/Makefile |   2 +
 drivers/aiodev/core.c   | 148 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/aiodev.h        |  59 +++++++++++++++++++
 6 files changed, 220 insertions(+)
 create mode 100644 drivers/aiodev/Kconfig
 create mode 100644 drivers/aiodev/Makefile
 create mode 100644 drivers/aiodev/core.c
 create mode 100644 include/aiodev.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 3236696..cc086ac 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -1,6 +1,7 @@
 menu "Drivers"
 
 source "drivers/of/Kconfig"
+source "drivers/aiodev/Kconfig"
 source "drivers/amba/Kconfig"
 source "drivers/serial/Kconfig"
 source "drivers/net/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index a4467a0..5946fb3 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -32,3 +32,5 @@ obj-$(CONFIG_FIRMWARE) += firmware/
 obj-$(CONFIG_GENERIC_PHY) += phy/
 obj-$(CONFIG_HAB) += hab/
 obj-$(CONFIG_CRYPTO_HW) += crypto/
+obj-$(CONFIG_AIODEV) += aiodev/
+
diff --git a/drivers/aiodev/Kconfig b/drivers/aiodev/Kconfig
new file mode 100644
index 0000000..d6d4ac0
--- /dev/null
+++ b/drivers/aiodev/Kconfig
@@ -0,0 +1,8 @@
+#
+# Misc strange devices
+#
+menuconfig AIODEV
+	bool "Analog I/O drivers"
+
+if AIODEV
+endif
diff --git a/drivers/aiodev/Makefile b/drivers/aiodev/Makefile
new file mode 100644
index 0000000..806464e
--- /dev/null
+++ b/drivers/aiodev/Makefile
@@ -0,0 +1,2 @@
+
+obj-$(CONFIG_AIODEV) += core.o
diff --git a/drivers/aiodev/core.c b/drivers/aiodev/core.c
new file mode 100644
index 0000000..79f935d
--- /dev/null
+++ b/drivers/aiodev/core.c
@@ -0,0 +1,148 @@
+/*
+ * core.c - Code implementing core functionality of AIODEV susbsystem
+ *
+ * Copyright (c) 2015 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * Copyright (c) 2015 Zodiac Inflight Innovation
+ * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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 <common.h>
+#include <aiodev.h>
+#include <linux/list.h>
+#include <malloc.h>
+
+LIST_HEAD(aiodevices);
+EXPORT_SYMBOL(aiodevices);
+
+struct aiochannel *aiochannel_get_by_name(const char *name)
+{
+	struct aiodevice *aiodev;
+	int i;
+
+	list_for_each_entry(aiodev, &aiodevices, list) {
+		for (i = 0; i < aiodev->num_channels; i++)
+			if (!strcmp(name, aiodev->channels[i]->name))
+				return aiodev->channels[i];
+	}
+
+	return ERR_PTR(-ENOENT);
+}
+EXPORT_SYMBOL(aiochannel_get_by_name);
+
+struct aiochannel *aiochannel_get(struct device_d *dev, int index)
+{
+	struct of_phandle_args spec;
+	struct aiodevice *aiodev;
+	int ret, chnum = 0;
+
+	if (!dev->device_node)
+		return ERR_PTR(-EINVAL);
+
+	ret = of_parse_phandle_with_args(dev->device_node,
+					 "io-channels",
+					 "#io-channel-cells",
+					 index, &spec);
+        if (ret)
+                return ERR_PTR(ret);
+
+	list_for_each_entry(aiodev, &aiodevices, list) {
+		if (aiodev->hwdev->device_node == spec.np)
+			goto found;
+	}
+
+	return ERR_PTR(-EPROBE_DEFER);
+
+found:
+	if (spec.args_count)
+		chnum = spec.args[0];
+
+	if (chnum >= aiodev->num_channels)
+		return ERR_PTR(-EINVAL);
+
+	return aiodev->channels[chnum];
+}
+EXPORT_SYMBOL(aiochannel_get);
+
+int aiochannel_get_value(struct aiochannel *aiochan, int *value)
+{
+	struct aiodevice *aiodev = aiochan->aiodev;
+
+	return aiodev->read(aiochan, value);
+}
+EXPORT_SYMBOL(aiochannel_get_value);
+
+int aiochannel_get_index(struct aiochannel *aiochan)
+{
+	return aiochan->index;
+}
+EXPORT_SYMBOL(aiochannel_get_index);
+
+static int aiochannel_param_get_value(struct param_d *p, void *priv)
+{
+	struct aiochannel *aiochan = priv;
+
+	return aiochannel_get_value(aiochan, &aiochan->value);
+}
+
+int aiodevice_register(struct aiodevice *aiodev)
+{
+	int i, ret;
+
+	if (!aiodev->name && aiodev->hwdev &&
+	    aiodev->hwdev->device_node) {
+		aiodev->dev.id = DEVICE_ID_SINGLE;
+
+		aiodev->name = of_alias_get(aiodev->hwdev->device_node);
+		if (!aiodev->name)
+			aiodev->name = aiodev->hwdev->device_node->name;
+	}
+
+	if (!aiodev->name) {
+		aiodev->name = "aiodev";
+		aiodev->dev.id = DEVICE_ID_DYNAMIC;
+	}
+
+	strcpy(aiodev->dev.name, aiodev->name);
+
+	aiodev->dev.parent = aiodev->hwdev;
+
+	ret = register_device(&aiodev->dev);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < aiodev->num_channels; i++) {
+		struct aiochannel *aiochan = aiodev->channels[i];
+		char *name;
+
+		aiochan->index  = i;
+		aiochan->aiodev = aiodev;
+
+		name = xasprintf("in_value%d_%s", i, aiochan->unit);
+
+		dev_add_param_int(&aiodev->dev, name, NULL,
+				  aiochannel_param_get_value,
+				  &aiochan->value, "%d", aiochan);
+
+		aiochan->name = xasprintf("%s.%s", aiodev->name, name);
+
+		free(name);
+	}
+
+	list_add_tail(&aiodev->list, &aiodevices);
+
+	return 0;
+}
+EXPORT_SYMBOL(aiodevice_register);
diff --git a/include/aiodev.h b/include/aiodev.h
new file mode 100644
index 0000000..0d4f7a2
--- /dev/null
+++ b/include/aiodev.h
@@ -0,0 +1,59 @@
+/*
+ * core.c - Code implementing core functionality of AIODEV susbsystem
+ *
+ * Copyright (c) 2015 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ * Copyright (c) 2015 Zodiac Inflight Innovation
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef __AIODEVICE_H
+#define __AIODEVICE_H
+
+struct aiodevice;
+struct aiochannel {
+	int index;
+	char *unit;
+	struct aiodevice *aiodev;
+
+	int value;
+	char *name;
+};
+
+struct aiodevice {
+	const char *name;
+	int (*read)(struct aiochannel *, int *val);
+	struct device_d dev;
+	struct device_d *hwdev;
+	struct aiochannel **channels;
+	int num_channels;
+	struct list_head list;
+};
+
+int aiodevice_register(struct aiodevice *aiodev);
+
+struct aiochannel *aiochannel_get(struct device_d *dev, int index);
+struct aiochannel *aiochannel_get_by_name(const char *name);
+
+int aiochannel_get_value(struct aiochannel *aiochan, int *value);
+int aiochannel_get_index(struct aiochannel *aiochan);
+
+static inline const char *aiochannel_get_unit(struct aiochannel *aiochan)
+{
+	return aiochan->unit;
+}
+
+extern struct list_head aiodevices;
+#define for_each_aiodevice(aiodevice) list_for_each_entry(aiodevice, &aiodevices, list)
+
+#endif
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v3 2/6] commands: Add 'hwmon' command
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 1/6] drivers: Introduce " Andrey Smirnov
@ 2016-05-16 16:45 ` Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 3/6] syscon: Do not return NULL when driver is not selected Andrey Smirnov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:45 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Add 'hwmon' command which allows to display the readings of all
hardware monitoring sensors registered with Barebox.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/Kconfig  |  8 ++++++++
 commands/Makefile |  1 +
 commands/hwmon.c  | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 commands/hwmon.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 57f2878..44a457b 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1830,6 +1830,14 @@ config CMD_HWCLOCK
 	help
 	  The hwclock command allows to query or set the hardware clock (RTC).
 
+config CMD_HWMON
+	bool
+	depends on AIODEV
+	prompt "hwmon command"
+	default y
+	help
+	  The hwmon command allows to query hardware sensors.
+
 config CMD_I2C
 	bool
 	depends on I2C
diff --git a/commands/Makefile b/commands/Makefile
index 065d649..3c8ad77 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -107,6 +107,7 @@ obj-$(CONFIG_CMD_REGULATOR)	+= regulator.o
 obj-$(CONFIG_CMD_LSPCI)		+= lspci.o
 obj-$(CONFIG_CMD_IMD)		+= imd.o
 obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
+obj-$(CONFIG_CMD_HWMON)		+= hwmon.o
 obj-$(CONFIG_CMD_USBGADGET)	+= usbgadget.o
 obj-$(CONFIG_CMD_FIRMWARELOAD)	+= firmwareload.o
 obj-$(CONFIG_CMD_CMP)		+= cmp.o
diff --git a/commands/hwmon.c b/commands/hwmon.c
new file mode 100644
index 0000000..ace4503
--- /dev/null
+++ b/commands/hwmon.c
@@ -0,0 +1,35 @@
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <string.h>
+#include <environment.h>
+#include <aiodev.h>
+
+static int do_hwmon(int argc, char *argv[])
+{
+	int i;
+	struct aiodevice *aiodev;
+
+	for_each_aiodevice(aiodev) {
+		for (i = 0; i < aiodev->num_channels; i++) {
+			struct aiochannel *chan = aiodev->channels[i];
+			int value;
+			int ret = aiochannel_get_value(chan, &value);
+
+			if (!ret)
+				printf("%s: %d %s\n", chan->name, value, chan->unit);
+			else
+				printf("%s: failed to read (%d)\n", chan->name, ret);
+		}
+	}
+
+	return 0;
+}
+
+BAREBOX_CMD_START(hwmon)
+	.cmd		= do_hwmon,
+	BAREBOX_CMD_DESC("query hardware sensors (HWMON)")
+	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+BAREBOX_CMD_END
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v3 3/6] syscon: Do not return NULL when driver is not selected
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 1/6] drivers: Introduce " Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 2/6] commands: Add 'hwmon' command Andrey Smirnov
@ 2016-05-16 16:45 ` Andrey Smirnov
  2016-05-16 16:45 ` [PATCH v3 4/6] syscon: Decrease driver registration priority Andrey Smirnov
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:45 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Both syscon_base_lookup_by_pdevname() and
syscon_base_lookup_by_phandle(), when implemented, do not return NULL,
so none of the code using those function is written to check for that.

Change returns to ERR_PTR(-ENOSYS), to avoid having that problem.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/mfd/syscon.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/mfd/syscon.h b/include/mfd/syscon.h
index 2044520..651d4c2 100644
--- a/include/mfd/syscon.h
+++ b/include/mfd/syscon.h
@@ -21,13 +21,13 @@ void __iomem *syscon_base_lookup_by_phandle
 #else
 static inline void __iomem *syscon_base_lookup_by_pdevname(const char *s)
 {
-	return NULL;
+	return ERR_PTR(-ENOSYS);
 }
 
 static inline void __iomem *syscon_base_lookup_by_phandle
 	(struct device_node *np, const char *property)
 {
-	return NULL;
+	return ERR_PTR(-ENOSYS);
 }
 #endif
 
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v3 4/6] syscon: Decrease driver registration priority
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
                   ` (2 preceding siblings ...)
  2016-05-16 16:45 ` [PATCH v3 3/6] syscon: Do not return NULL when driver is not selected Andrey Smirnov
@ 2016-05-16 16:45 ` Andrey Smirnov
  2016-05-16 16:46 ` [PATCH v3 5/6] aiodev: Add TEMPMON driver Andrey Smirnov
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:45 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

A number of devices on i.MX6 list "syscon" as second compatibility
string, among them, most importantly, is "iomuxv3" pinmux driver, which
gets probed at "postcore_initcall". Probing this driver at
"core_initcall" results in "syscon" driver usurping pinmux device and
preventing "iomuxv3" driver from loading and correctly initializing
pinmux of the system (which in turn results in a lot of sadness).

Moving this driver to be initialized at "device_initcall" time resolves
the issue.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/mfd/syscon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 9589a03..ee62da0 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -111,7 +111,7 @@ static int __init syscon_init(void)
 {
 	return platform_driver_register(&syscon_driver);
 }
-core_initcall(syscon_init);
+device_initcall(syscon_init);
 
 MODULE_AUTHOR("Dong Aisheng <dong.aisheng@linaro.org>");
 MODULE_DESCRIPTION("System Control driver");
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v3 5/6] aiodev: Add TEMPMON driver
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
                   ` (3 preceding siblings ...)
  2016-05-16 16:45 ` [PATCH v3 4/6] syscon: Decrease driver registration priority Andrey Smirnov
@ 2016-05-16 16:46 ` Andrey Smirnov
  2016-05-16 16:46 ` [PATCH v3 6/6] aiodev: Add basic LM75 temperature driver Andrey Smirnov
  2016-05-18  5:49 ` [PATCH v3 0/6] AIODEV subsystem Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:46 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Port TEMPMON driver from U-Boot

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/dts/imx6qdl.dtsi    |   1 +
 drivers/aiodev/Kconfig       |   8 ++
 drivers/aiodev/Makefile      |   1 +
 drivers/aiodev/imx_thermal.c | 216 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+)
 create mode 100644 drivers/aiodev/imx_thermal.c

diff --git a/arch/arm/dts/imx6qdl.dtsi b/arch/arm/dts/imx6qdl.dtsi
index 828be9c..06b1039 100644
--- a/arch/arm/dts/imx6qdl.dtsi
+++ b/arch/arm/dts/imx6qdl.dtsi
@@ -8,3 +8,4 @@
 		ipu0 = &ipu1;
 	};
 };
+
diff --git a/drivers/aiodev/Kconfig b/drivers/aiodev/Kconfig
index d6d4ac0..185c44e 100644
--- a/drivers/aiodev/Kconfig
+++ b/drivers/aiodev/Kconfig
@@ -5,4 +5,12 @@ menuconfig AIODEV
 	bool "Analog I/O drivers"
 
 if AIODEV
+
+config IMX_THERMAL
+       tristate "Temperature sensor driver for Freescale i.MX SoCs"
+       select MFD_SYSCON
+       help
+         Support for Temperature Monitor (TEMPMON) found on Freescale
+         i.MX SoCs.
+
 endif
diff --git a/drivers/aiodev/Makefile b/drivers/aiodev/Makefile
index 806464e..5480a8a 100644
--- a/drivers/aiodev/Makefile
+++ b/drivers/aiodev/Makefile
@@ -1,2 +1,3 @@
 
 obj-$(CONFIG_AIODEV) += core.o
+obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
diff --git a/drivers/aiodev/imx_thermal.c b/drivers/aiodev/imx_thermal.c
new file mode 100644
index 0000000..6c36d2f
--- /dev/null
+++ b/drivers/aiodev/imx_thermal.c
@@ -0,0 +1,216 @@
+/*
+ * imx_thermal
+ *
+ * Copyright (c) 2015 Zodiac Inflight Innovation
+ * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
+ *
+ * based on the code of analogous driver from U-Boot:
+ * (C) Copyright 2014-2015 Freescale Semiconductor, Inc.
+ * Author: Nitin Garg <nitin.garg@freescale.com>
+ *             Ye Li <Ye.Li@freescale.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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 <common.h>
+#include <init.h>
+#include <malloc.h>
+#include <clock.h>
+#include <driver.h>
+#include <xfuncs.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/math64.h>
+#include <linux/log2.h>
+#include <linux/clk.h>
+#include <mach/clock.h>
+#include <mach/imx6-anadig.h>
+#include <io.h>
+#include <aiodev.h>
+#include <mfd/syscon.h>
+
+#define FACTOR0			10000000
+#define MEASURE_FREQ		327
+#define OCOTP_ANA1_OFFSET      (0xE * sizeof(uint32_t))
+
+struct imx_thermal_data {
+	int c1, c2;
+	void __iomem *base;
+	struct clk *clk;
+
+	struct aiodevice aiodev;
+	struct aiochannel aiochan;
+};
+
+static inline struct imx_thermal_data *
+to_imx_thermal_data(struct aiochannel *chan)
+{
+	return container_of(chan, struct imx_thermal_data, aiochan);
+}
+
+
+static int imx_thermal_read(struct aiochannel *chan, int *val)
+{
+	uint64_t start;
+	uint32_t tempsense0, tempsense1;
+	uint16_t n_meas;
+	struct imx_thermal_data *imx_thermal = to_imx_thermal_data(chan);
+
+	/*
+	 * now we only use single measure, every time we read
+	 * the temperature, we will power on/down anadig thermal
+	 * module
+	 */
+	writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN,
+	       imx_thermal->base + HW_ANADIG_TEMPSENSE0_CLR);
+	writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF,
+	       imx_thermal->base + HW_ANADIG_ANA_MISC0_SET);
+
+	/* setup measure freq */
+	tempsense1 = readl(imx_thermal->base + HW_ANADIG_TEMPSENSE1);
+	tempsense1 &= ~BM_ANADIG_TEMPSENSE1_MEASURE_FREQ;
+	tempsense1 |= MEASURE_FREQ;
+	writel(tempsense1, imx_thermal->base + HW_ANADIG_TEMPSENSE1);
+
+	/* start the measurement process */
+	writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP,
+		imx_thermal->base + HW_ANADIG_TEMPSENSE0_CLR);
+	writel(BM_ANADIG_TEMPSENSE0_FINISHED,
+		imx_thermal->base + HW_ANADIG_TEMPSENSE0_CLR);
+	writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP,
+	       imx_thermal->base + HW_ANADIG_TEMPSENSE0_SET);
+
+	/* make sure that the latest temp is valid */
+	start = get_time_ns();
+	do {
+		tempsense0 = readl(imx_thermal->base + HW_ANADIG_TEMPSENSE0);
+
+		if (is_timeout(start, 1 * SECOND)) {
+			dev_err(imx_thermal->aiodev.hwdev,
+				"Timeout waiting for measurement\n");
+			return -EIO;
+		}
+	} while (!(tempsense0 & BM_ANADIG_TEMPSENSE0_FINISHED));
+
+	n_meas = (tempsense0 & BM_ANADIG_TEMPSENSE0_TEMP_VALUE)
+		>> BP_ANADIG_TEMPSENSE0_TEMP_VALUE;
+	writel(BM_ANADIG_TEMPSENSE0_FINISHED,
+	       imx_thermal->base + HW_ANADIG_TEMPSENSE0_CLR);
+
+	*val = (int)n_meas * imx_thermal->c1 + imx_thermal->c2;
+
+	/* power down anatop thermal sensor */
+	writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN,
+	       imx_thermal->base + HW_ANADIG_TEMPSENSE0_SET);
+	writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF,
+	       imx_thermal->base + HW_ANADIG_ANA_MISC0_CLR);
+
+	return 0;
+}
+
+static int imx_thermal_probe(struct device_d *dev)
+{
+	uint32_t ocotp_ana1;
+	struct device_node *node;
+	struct imx_thermal_data *imx_thermal;
+	struct cdev *ocotp;
+	int t1, n1, t2, n2;
+	int ret;
+
+	node = of_parse_phandle(dev->device_node, "fsl,tempmon-data", 0);
+	if (!node) {
+		dev_err(dev, "No calibration data source\n");
+		return -ENODEV;
+	}
+
+	printf("node = %p\n", node);
+
+	ocotp = cdev_by_device_node(node);
+	if (!ocotp) {
+		dev_err(dev, "No OCOTP character device\n");
+		return -ENODEV;
+	}
+
+	ret = cdev_read(ocotp, &ocotp_ana1, sizeof(ocotp_ana1),
+			OCOTP_ANA1_OFFSET, 0);
+	if (ret != sizeof(ocotp_ana1)) {
+		dev_err(dev, "Failed to read calibration data\n");
+		return ret < 0 ? ret : -EIO;
+	}
+
+	imx_thermal = xzalloc(sizeof(*imx_thermal));
+	imx_thermal->base = syscon_base_lookup_by_phandle(dev->device_node,
+							  "fsl,tempmon");
+	if (IS_ERR(imx_thermal->base)) {
+		dev_err(dev, "Could not get ANATOP address\n");
+		ret = PTR_ERR(imx_thermal->base);
+		goto free_imx_thermal;
+	}
+
+	n1 = ocotp_ana1 >> 20;
+	t1 = 25;
+	n2 = (ocotp_ana1 & 0x000FFF00) >> 8;
+	t2 = ocotp_ana1 & 0xFF;
+
+	imx_thermal->c1 = (-1000 * (t2 - t1)) / (n1 - n2);
+	imx_thermal->c2 = 1000 * t2 + (1000 * n2 * (t2 - t1)) / (n1 - n2);
+
+	imx_thermal->clk = clk_get(dev, NULL);
+	if (IS_ERR(imx_thermal->clk)) {
+		ret = PTR_ERR(imx_thermal->clk);
+		goto free_imx_thermal;
+	}
+
+	ret = clk_enable(imx_thermal->clk);
+	if (ret) {
+		dev_err(dev, "Failed to enable clock: %s\n",
+			  strerror(ret));
+		goto put_clock;
+	}
+
+	imx_thermal->aiodev.num_channels = 1;
+	imx_thermal->aiodev.hwdev = dev;
+	imx_thermal->aiodev.channels =
+		xmalloc(imx_thermal->aiodev.num_channels *
+			sizeof(imx_thermal->aiodev.channels[0]));
+	imx_thermal->aiodev.channels[0] = &imx_thermal->aiochan;
+	imx_thermal->aiochan.unit = "mC";
+	imx_thermal->aiodev.read = imx_thermal_read;
+
+	ret = aiodevice_register(&imx_thermal->aiodev);
+	if (!ret)
+		goto done;
+
+	clk_disable(imx_thermal->clk);
+put_clock:
+	clk_put(imx_thermal->clk);
+free_imx_thermal:
+	kfree(imx_thermal);
+done:	
+	return ret;
+}
+
+static const struct of_device_id of_imx_thermal_match[] = {
+	{ .compatible = "fsl,imx6q-tempmon", },
+	{ .compatible = "fsl,imx6sx-tempmon", },
+	{ /* end */ }
+};
+
+
+static struct driver_d imx_thermal_driver = {
+	.name		= "imx_thermal",
+	.probe		= imx_thermal_probe,
+	.of_compatible	= DRV_OF_COMPAT(of_imx_thermal_match),
+};
+
+device_platform_driver(imx_thermal_driver);
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v3 6/6] aiodev: Add basic LM75 temperature driver
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
                   ` (4 preceding siblings ...)
  2016-05-16 16:46 ` [PATCH v3 5/6] aiodev: Add TEMPMON driver Andrey Smirnov
@ 2016-05-16 16:46 ` Andrey Smirnov
  2016-05-18  5:49 ` [PATCH v3 0/6] AIODEV subsystem Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Andrey Smirnov @ 2016-05-16 16:46 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

From: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/aiodev/Kconfig  |   6 ++
 drivers/aiodev/Makefile |   1 +
 drivers/aiodev/lm75.c   | 262 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 269 insertions(+)
 create mode 100644 drivers/aiodev/lm75.c

diff --git a/drivers/aiodev/Kconfig b/drivers/aiodev/Kconfig
index 185c44e..0ecf6f4 100644
--- a/drivers/aiodev/Kconfig
+++ b/drivers/aiodev/Kconfig
@@ -13,4 +13,10 @@ config IMX_THERMAL
          Support for Temperature Monitor (TEMPMON) found on Freescale
          i.MX SoCs.
 
+config LM75
+	tristate "LM75 driver"
+	depends on I2C
+	help
+	  Support for LM75 and similar devices
+
 endif
diff --git a/drivers/aiodev/Makefile b/drivers/aiodev/Makefile
index 5480a8a..c3d2b08 100644
--- a/drivers/aiodev/Makefile
+++ b/drivers/aiodev/Makefile
@@ -1,3 +1,4 @@
 
 obj-$(CONFIG_AIODEV) += core.o
 obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
+obj-$(CONFIG_LM75) += lm75.o
diff --git a/drivers/aiodev/lm75.c b/drivers/aiodev/lm75.c
new file mode 100644
index 0000000..b4da5a0
--- /dev/null
+++ b/drivers/aiodev/lm75.c
@@ -0,0 +1,262 @@
+/*
+ * lm75.c - Part of lm_sensors, Linux kernel modules for hardware
+ *	 monitoring
+ * Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <xfuncs.h>
+#include <i2c/i2c.h>
+#include <aiodev.h>
+
+/*
+ * This driver handles the LM75 and compatible digital temperature sensors.
+ */
+
+/* straight from the datasheet */
+#define LM75_TEMP_MIN (-55000)
+#define LM75_TEMP_MAX 125000
+#define LM75_SHUTDOWN 0x01
+
+enum lm75_type {		/* keep sorted in alphabetical order */
+	adt75,
+	ds1775,
+	ds75,
+	ds7505,
+	g751,
+	lm75,
+	lm75a,
+	lm75b,
+	max6625,
+	max6626,
+	mcp980x,
+	stds75,
+	tcn75,
+	tmp100,
+	tmp101,
+	tmp105,
+	tmp112,
+	tmp175,
+	tmp275,
+	tmp75,
+	tmp75c,
+};
+
+/* The LM75 registers */
+#define LM75_REG_CONF		0x01
+static const u8 LM75_REG_TEMP[3] = {
+	0x00,		/* input */
+	0x03,		/* max */
+	0x02,		/* hyst */
+};
+
+/* Each client has this additional data */
+struct lm75_data {
+	struct i2c_client	*client;
+	struct device_d		dev;
+	u8			resolution;	/* In bits, between 9 and 12 */
+	struct aiochannel	aiochan;
+	struct aiodevice	aiodev;
+};
+
+static int lm75_read_value(struct lm75_data *data, u8 reg)
+{
+	if (reg == LM75_REG_CONF)
+		return i2c_smbus_read_byte_data(data->client, reg);
+	else
+		return i2c_smbus_read_word_swapped(data->client, reg);
+}
+
+static int lm75_write_value(struct lm75_data *data, u8 reg, u16 value)
+{
+	if (reg == LM75_REG_CONF)
+		return i2c_smbus_write_byte_data(data->client, reg, value);
+	else
+		return i2c_smbus_write_word_swapped(data->client, reg, value);
+}
+
+static long lm75_reg_to_mc(s16 temp, u8 resolution)
+{
+	return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
+}
+
+static int lm75_get_temp(struct aiochannel *chan, int *val)
+{
+	struct lm75_data *data = container_of(chan, struct lm75_data, aiochan);
+	int status;
+
+	status = lm75_read_value(data, LM75_REG_TEMP[0]);
+	if (status < 0) {
+		dev_err(&data->client->dev,
+			"LM75: Failed to read value: reg %d, error %d\n",
+			LM75_REG_TEMP[0], status);
+		return status;
+	}
+
+	*val = lm75_reg_to_mc(status, data->resolution);
+
+	return 0;
+}
+
+static int lm75_probe(struct device_d *dev)
+{
+	struct lm75_data *data;
+	int status;
+	u8 set_mask, clr_mask;
+	int new, ret;
+	enum lm75_type kind;
+
+	ret = dev_get_drvdata(dev, (const void **)&kind);
+	if (ret)
+		return ret;
+
+	data = xzalloc(sizeof(*data));
+
+	data->client = to_i2c_client(dev);
+
+	/* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
+	 * Then tweak to be more precise when appropriate.
+	 */
+	set_mask = 0;
+	clr_mask = LM75_SHUTDOWN;		/* continuous conversions */
+
+	switch (kind) {
+	case adt75:
+		clr_mask |= 1 << 5;		/* not one-shot mode */
+		data->resolution = 12;
+		break;
+	case ds1775:
+	case ds75:
+	case stds75:
+		clr_mask |= 3 << 5;
+		set_mask |= 2 << 5;		/* 11-bit mode */
+		data->resolution = 11;
+		break;
+	case ds7505:
+		set_mask |= 3 << 5;		/* 12-bit mode */
+		data->resolution = 12;
+		break;
+	case g751:
+	case lm75:
+	case lm75a:
+		data->resolution = 9;
+		break;
+	case lm75b:
+		data->resolution = 11;
+		break;
+	case max6625:
+		data->resolution = 9;
+		break;
+	case max6626:
+		data->resolution = 12;
+		break;
+	case tcn75:
+		data->resolution = 9;
+		break;
+	case mcp980x:
+		/* fall through */
+	case tmp100:
+	case tmp101:
+		set_mask |= 3 << 5;		/* 12-bit mode */
+		data->resolution = 12;
+		clr_mask |= 1 << 7;		/* not one-shot mode */
+		break;
+	case tmp112:
+		set_mask |= 3 << 5;		/* 12-bit mode */
+		clr_mask |= 1 << 7;		/* not one-shot mode */
+		data->resolution = 12;
+		break;
+	case tmp105:
+	case tmp175:
+	case tmp275:
+	case tmp75:
+		set_mask |= 3 << 5;		/* 12-bit mode */
+		clr_mask |= 1 << 7;		/* not one-shot mode */
+		data->resolution = 12;
+		break;
+	case tmp75c:
+		clr_mask |= 1 << 5;		/* not one-shot mode */
+		data->resolution = 12;
+		break;
+	}
+
+	/* configure as specified */
+	status = lm75_read_value(data, LM75_REG_CONF);
+	if (status < 0) {
+		dev_dbg(dev, "Can't read config? %d\n", status);
+		return status;
+	}
+
+	new = status & ~clr_mask;
+	new |= set_mask;
+	if (status != new)
+		lm75_write_value(data, LM75_REG_CONF, new);
+
+	data->aiodev.num_channels = 1;
+	data->aiodev.hwdev = dev;
+	data->aiodev.read = lm75_get_temp;
+	data->aiodev.channels = xmalloc(sizeof(void *));
+	data->aiodev.channels[0] = &data->aiochan;
+	data->aiochan.unit = "mC";
+
+	ret = aiodevice_register(&data->aiodev);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static const struct platform_device_id lm75_ids[] = {
+	{ .name = "adt75", .driver_data = adt75, },
+	{ .name = "ds1775", .driver_data = ds1775, },
+	{ .name = "ds75", .driver_data = ds75, },
+	{ .name = "ds7505", .driver_data = ds7505, },
+	{ .name = "g751", .driver_data = g751, },
+	{ .name = "lm75", .driver_data = lm75, },
+	{ .name = "lm75a", .driver_data = lm75a, },
+	{ .name = "lm75b", .driver_data = lm75b, },
+	{ .name = "max6625", .driver_data = max6625, },
+	{ .name = "max6626", .driver_data = max6626, },
+	{ .name = "mcp980x", .driver_data = mcp980x, },
+	{ .name = "stds75", .driver_data = stds75, },
+	{ .name = "tcn75", .driver_data = tcn75, },
+	{ .name = "tmp100", .driver_data = tmp100, },
+	{ .name = "tmp101", .driver_data = tmp101, },
+	{ .name = "tmp105", .driver_data = tmp105, },
+	{ .name = "tmp112", .driver_data = tmp112, },
+	{ .name = "tmp175", .driver_data = tmp175, },
+	{ .name = "tmp275", .driver_data = tmp275, },
+	{ .name = "tmp75", .driver_data = tmp75, },
+	{ .name = "tmp75c", .driver_data = tmp75c, },
+	{ /* LIST END */ }
+};
+
+static struct driver_d lm75_driver = {
+	.name  = "lm75",
+	.probe = lm75_probe,
+	.id_table = lm75_ids,
+};
+
+static int lm75_init(void)
+{
+	i2c_driver_register(&lm75_driver);
+	return 0;
+}
+
+device_initcall(lm75_init);
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH v3 0/6] AIODEV subsystem
  2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
                   ` (5 preceding siblings ...)
  2016-05-16 16:46 ` [PATCH v3 6/6] aiodev: Add basic LM75 temperature driver Andrey Smirnov
@ 2016-05-18  5:49 ` Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2016-05-18  5:49 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Mon, May 16, 2016 at 09:45:55AM -0700, Andrey Smirnov wrote:
> Hi everyone,
> 
> Here's the third version of AIODEV patchset. The change list is the
> following:
> 
> Changes since v2:
> 
> 	- TEMPMON driver converted to use existing DT bindings
> 
> 	- As a result of the above NVMEM subsystem was dropped
> 
> 	- TEMPMON driver converted to use syscon_base_lookup_by_phandle
> 
> Changes since v1:
> 
> 	- Patches fixed to use IIO DT bindings
> 
> 	- Channel's index is now cached and no O(n) complex lookup is
>           perfomed when a channel is queried by its index
> 
> 	- Added GPL v2 headers
> 
> 	- Incorporated Sascha's feedback to simplify code
> 
> 
> Andrey Smirnov (5):
>   RDU2: Add more peripheral reset code
>   commands: Add 'hwmon' command
>   syscon: Do not return NULL when driver is not selected
>   syscon: Decrease driver registration priority
>   aiodev: Add TEMPMON driver
> 
> Sascha Hauer (2):
>   drivers: Introduce AIODEV subsystem
>   aiodev: Add basic LM75 temperature driver

Applied, thanks for continuing the work on this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2016-05-18  5:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-16 16:45 [PATCH v3 0/6] AIODEV subsystem Andrey Smirnov
2016-05-16 16:45 ` [PATCH v3 1/6] drivers: Introduce " Andrey Smirnov
2016-05-16 16:45 ` [PATCH v3 2/6] commands: Add 'hwmon' command Andrey Smirnov
2016-05-16 16:45 ` [PATCH v3 3/6] syscon: Do not return NULL when driver is not selected Andrey Smirnov
2016-05-16 16:45 ` [PATCH v3 4/6] syscon: Decrease driver registration priority Andrey Smirnov
2016-05-16 16:46 ` [PATCH v3 5/6] aiodev: Add TEMPMON driver Andrey Smirnov
2016-05-16 16:46 ` [PATCH v3 6/6] aiodev: Add basic LM75 temperature driver Andrey Smirnov
2016-05-18  5:49 ` [PATCH v3 0/6] AIODEV subsystem Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox