mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node'
@ 2015-12-07  7:52 Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 2/7] drivers: bus: Match against id_table first Andrey Smirnov
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

In order for cdev_by_device_node() to be able to return approprate
character device for <&ocotp> phandle cdev->device_node needs to be
initialized with dev->device_node. This patche takes care of that

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/ocotp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index c99a003..6ff5ee4 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -426,6 +426,7 @@ static int imx_ocotp_probe(struct device_d *dev)
 	cdev->priv	= priv;
 	cdev->size	= 192;
 	cdev->name	= "imx-ocotp";
+	cdev->device_node = dev->device_node;

 	ret = devfs_create(cdev);

--
2.5.0

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

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

* [PATCH 2/7] drivers: bus: Match against id_table first
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
@ 2015-12-07  7:52 ` Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 3/7] i2c: Port two utility functions from Linux kernel Andrey Smirnov
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Matching against driver's name before looking throught its id_table
can lead to a somewhat strange and unintuitive behaviour where a
device whose driver's name matches one of the lines in id_table (which
is not unheard of in Linux kernel) will be probed against said driver
with 'id_table' field set to NULL which in turn will result in
dev_get_drvdata erroring out with -ENODEV.

This patch changes the behaviour such that device_match() only tries
to match against driver's name only if id_table of that driver is not
present.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/base/bus.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 1264e40..b889a48 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -54,9 +54,6 @@ int device_match(struct device_d *dev, struct driver_d *drv)
 	    drv->of_compatible)
 		return of_match(dev, drv);

-	if (!strcmp(dev->name, drv->name))
-		return 0;
-
 	if (drv->id_table) {
 		const struct platform_device_id *id = drv->id_table;

@@ -67,6 +64,8 @@ int device_match(struct device_d *dev, struct driver_d *drv)
 			}
 			id++;
 		}
+	} else if (!strcmp(dev->name, drv->name)) {
+		return 0;
 	}

 	return -1;
--
2.5.0

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

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

* [PATCH 3/7] i2c: Port two utility functions from Linux kernel
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 2/7] drivers: bus: Match against id_table first Andrey Smirnov
@ 2015-12-07  7:52 ` Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 4/7] drivers: Introduce hardware monitoring subsystem Andrey Smirnov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/i2c/i2c.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index 33a4791..cf784ca 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -194,6 +194,21 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
 extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
 				     u8 command, u16 value);

+static inline s32
+i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
+{
+	s32 value = i2c_smbus_read_word_data(client, command);
+
+	return (value < 0) ? value : swab16(value);
+}
+
+static inline s32
+i2c_smbus_write_word_swapped(const struct i2c_client *client,
+			     u8 command, u16 value)
+{
+	return i2c_smbus_write_word_data(client, command, swab16(value));
+}
+
 /* Returns the number of read bytes */
 extern s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client,
 					 u8 command, u8 length, u8 *values);
--
2.5.0

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

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

* [PATCH 4/7] drivers: Introduce hardware monitoring subsystem
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 2/7] drivers: bus: Match against id_table first Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 3/7] i2c: Port two utility functions from Linux kernel Andrey Smirnov
@ 2015-12-07  7:52 ` Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 5/7] commands: Add 'hwmon' command Andrey Smirnov
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

This commit introduces hardware monitoring system designed to
facilitate data retreival from sensors reporing signed scalar values
with no more than 32-bit of precision.

The system was designed after a, similar in simplicity, 'rtc'
subsystem and doesn't share very much in common with it's namesake
from Linux kernel.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/Kconfig        |  1 +
 drivers/Makefile       |  1 +
 drivers/hwmon/Kconfig  | 16 ++++++++++++++++
 drivers/hwmon/Makefile |  5 +++++
 drivers/hwmon/class.c  | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hwmon.h        | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 105 insertions(+)
 create mode 100644 drivers/hwmon/Kconfig
 create mode 100644 drivers/hwmon/Makefile
 create mode 100644 drivers/hwmon/class.c
 create mode 100644 include/hwmon.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 5984ccc..5527049 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -31,5 +31,6 @@ source "drivers/pci/Kconfig"
 source "drivers/rtc/Kconfig"
 source "drivers/firmware/Kconfig"
 source "drivers/phy/Kconfig"
+source "drivers/hwmon/Kconfig"

 endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 3afbb61..de2ee70 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -31,3 +31,4 @@ obj-y += rtc/
 obj-$(CONFIG_FIRMWARE) += firmware/
 obj-$(CONFIG_GENERIC_PHY) += phy/
 obj-$(CONFIG_HABV4) += habv4/
+obj-y += hwmon/
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
new file mode 100644
index 0000000..6ce06a7
--- /dev/null
+++ b/drivers/hwmon/Kconfig
@@ -0,0 +1,16 @@
+#
+# HWMON class/drivers configuration
+#
+
+menuconfig HWMON
+	tristate "Hardware Monitoring support"
+	default y
+	help
+	  Hardware monitoring devices let you monitor the hardware
+	  health of a system. If you want this support you should say
+	  Y here and also to the specific driver(s) for your sensors
+	  chip(s) below.
+
+if HWMON
+
+endif # HWMON
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
new file mode 100644
index 0000000..47a2e58
--- /dev/null
+++ b/drivers/hwmon/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for sensor chip drivers.
+#
+
+obj-$(CONFIG_HWMON)		+= class.o
diff --git a/drivers/hwmon/class.c b/drivers/hwmon/class.c
new file mode 100644
index 0000000..898c0d8
--- /dev/null
+++ b/drivers/hwmon/class.c
@@ -0,0 +1,50 @@
+/*
+ * Hwmon barebox subsystem, base class
+ *
+ * Copyright (C) 2015 Andrey Smirnov <andrew.smirnov@gmail.com>
+ *
+ * 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/err.h>
+#include <hwmon.h>
+
+LIST_HEAD(hwmon_sensor_list);
+EXPORT_SYMBOL(hwmon_sensor_list);
+
+int hwmon_sensor_register(struct hwmon_sensor *sensor)
+{
+	struct device_d *dev = &sensor->class_dev;
+
+	if (!sensor->read)
+		return -EINVAL;
+
+	dev->id = DEVICE_ID_DYNAMIC;
+	strcpy(dev->name, "sensor");
+	if (sensor->dev)
+		dev->parent = sensor->dev;
+	platform_device_register(dev);
+
+	list_add_tail(&sensor->list, &hwmon_sensor_list);
+
+	return 0;
+}
+EXPORT_SYMBOL(hwmon_sensor_register);
+
+int hwmon_sensor_read(struct hwmon_sensor *sensor, s32 *reading)
+{
+	if (!sensor->read)
+		return -EINVAL;
+
+	return sensor->read(sensor, reading);
+}
+EXPORT_SYMBOL(hwmon_sensor_read);
diff --git a/include/hwmon.h b/include/hwmon.h
new file mode 100644
index 0000000..2897e47
--- /dev/null
+++ b/include/hwmon.h
@@ -0,0 +1,32 @@
+#ifndef __HWMON_H__
+#define __HWMON_H__
+
+#include <common.h>
+#include <driver.h>
+#include <linux/types.h>
+
+enum hwmon_sensor_type {
+	SENSOR_TEMPERATURE,
+};
+
+struct hwmon_sensor {
+	int (*read) (struct hwmon_sensor *, s32 *);
+	const char *name;
+
+	struct device_d *dev;
+	struct device_d class_dev;
+
+	enum hwmon_sensor_type type;
+
+	struct list_head list;
+};
+
+
+int hwmon_sensor_register(struct hwmon_sensor *sensor);
+int hwmon_sensor_read(struct hwmon_sensor *sensor, s32 *reading);
+
+extern struct list_head hwmon_sensor_list;
+#define for_each_hwmon_sensor(sensor) list_for_each_entry(sensor, &hwmon_sensor_list, list)
+
+
+#endif
--
2.5.0

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

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

* [PATCH 5/7] commands: Add 'hwmon' command
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
                   ` (2 preceding siblings ...)
  2015-12-07  7:52 ` [PATCH 4/7] drivers: Introduce hardware monitoring subsystem Andrey Smirnov
@ 2015-12-07  7:52 ` Andrey Smirnov
  2015-12-10 11:20   ` Antony Pavlov
  2015-12-07  7:52 ` [PATCH 6/7] hwmon: Port Linux driver for LM75 sensor Andrey Smirnov
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 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  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)
 create mode 100644 commands/hwmon.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 1743670..a338efd 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1799,6 +1799,14 @@ config CMD_HWCLOCK
 	help
 	  The hwclock command allows to query or set the hardware clock (RTC).

+config CMD_HWMON
+	bool
+	depends on HWMON
+	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 d985341..6c5158c 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -105,6 +105,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..84c0c70
--- /dev/null
+++ b/commands/hwmon.c
@@ -0,0 +1,47 @@
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <string.h>
+#include <environment.h>
+#include <hwmon.h>
+
+static int do_hwmon(int argc, char *argv[])
+{
+	struct hwmon_sensor *s;
+
+	for_each_hwmon_sensor(s) {
+		s32 value;
+		int ret = hwmon_sensor_read(s, &value);
+
+		if (ret < 0) {
+			printf("%s -- failed to read the sensor (%d)\n", s->name, ret);
+			continue;
+		}
+
+		switch (s->type) {
+		case SENSOR_TEMPERATURE:
+			printf("name: %s, reading: %d.%03d C\n",
+			       s->name, (int)(value / 1000), (int)abs(value % 1000));
+			break;
+		default:
+			printf("%s -- unknow type of sensor\n", s->name);
+			break;
+		}
+	}
+
+	return 0;
+}
+
+#if 0
+BAREBOX_CMD_HELP_START(hwmon)
+BAREBOX_CMD_HELP_END
+#endif
+
+BAREBOX_CMD_START(hwmon)
+	.cmd		= do_hwmon,
+	BAREBOX_CMD_DESC("query hardware sensors (HWMON)")
+	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+	/* BAREBOX_CMD_HELP(cmd_hwmon_help) */
+BAREBOX_CMD_END
--
2.5.0

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

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

* [PATCH 6/7] hwmon: Port Linux driver for LM75 sensor
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
                   ` (3 preceding siblings ...)
  2015-12-07  7:52 ` [PATCH 5/7] commands: Add 'hwmon' command Andrey Smirnov
@ 2015-12-07  7:52 ` Andrey Smirnov
  2015-12-07  7:52 ` [PATCH 7/7] hwmon: Port TEMPMON sensor driver Andrey Smirnov
  2015-12-07 10:23 ` [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Sascha Hauer
  6 siblings, 0 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/hwmon/Kconfig  |   9 +++
 drivers/hwmon/Makefile |   2 +
 drivers/hwmon/lm75.c   | 194 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/hwmon/lm75.h   |  48 ++++++++++++
 4 files changed, 253 insertions(+)
 create mode 100644 drivers/hwmon/lm75.c
 create mode 100644 drivers/hwmon/lm75.h

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 6ce06a7..db51d26 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -13,4 +13,13 @@ menuconfig HWMON

 if HWMON

+config SENSORS_LM75
+	tristate "National Semiconductor LM75 and compatibles"
+	depends on I2C
+	help
+	  If you say yes here you get support for one common type of
+	  temperature sensor chip, with models including:
+
+		- National Semiconductor LM75, LM75A
+
 endif # HWMON
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 47a2e58..e73e681 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -3,3 +3,5 @@
 #

 obj-$(CONFIG_HWMON)		+= class.o
+
+obj-$(CONFIG_SENSORS_LM75)	+= lm75.o
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
new file mode 100644
index 0000000..5df85bf
--- /dev/null
+++ b/drivers/hwmon/lm75.c
@@ -0,0 +1,194 @@
+/*
+ * 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 <malloc.h>
+#include <xfuncs.h>
+#include <errno.h>
+#include <i2c/i2c.h>
+#include <i2c/i2c.h>
+#include <linux/err.h>
+#include <hwmon.h>
+#include "lm75.h"
+
+
+/*
+ * This driver handles the LM75 and compatible digital temperature sensors.
+ */
+
+enum lm75_type {		/* keep sorted in alphabetical order */
+	lm75,
+};
+
+
+
+/* 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 hwmon_sensor	sensor;
+
+	u8			resolution;	/* In bits, between 9 and 12 */
+};
+
+static inline struct lm75_data *to_lm75_data(struct hwmon_sensor *sensor)
+{
+	return container_of(sensor, struct lm75_data, sensor);
+}
+
+/*
+ * All registers are word-sized, except for the configuration register.
+ * LM75 uses a high-byte first convention, which is exactly opposite to
+ * the SMBus standard.
+ */
+static s32 lm75_read_value(struct i2c_client *client, u8 reg)
+{
+	if (reg == LM75_REG_CONF)
+		return i2c_smbus_read_byte_data(client, reg);
+	else
+		return i2c_smbus_read_word_swapped(client, reg);
+}
+
+static s32 lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
+{
+	if (reg == LM75_REG_CONF)
+		return i2c_smbus_write_byte_data(client, reg, value);
+	else
+		return i2c_smbus_write_word_swapped(client, reg, value);
+}
+
+static inline s32 lm75_reg_to_mc(s16 temp, u8 resolution)
+{
+	return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8);
+}
+
+static int lm75_read_temp(struct hwmon_sensor *sensor, s32 *reading)
+{
+	struct lm75_data *data = to_lm75_data(sensor);
+
+	s32 ret = lm75_read_value(data->client, LM75_REG_TEMP[0]);
+
+	if (ret < 0)
+		return ret;
+
+	*reading = lm75_reg_to_mc((s16)ret, data->resolution);
+	return 0;
+}
+
+static int lm75_probe(struct device_d *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct lm75_data *data;
+	int err;
+	u8 set_mask, clr_mask;
+	int new;
+	enum lm75_type kind;
+
+	err = dev_get_drvdata(dev, (const void **)&kind);
+	if (err) {
+		dev_err(dev, "Can't get driver data\n");
+		return err;
+	}
+
+	data = xzalloc(sizeof(struct lm75_data));
+	if (!data)
+		return -ENOMEM;
+
+	data->client = client;
+
+	/* 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 lm75:
+		data->resolution = 9;
+		break;
+	}
+
+	/* configure as specified */
+	err = lm75_read_value(client, LM75_REG_CONF);
+	if (err < 0) {
+		dev_err(dev, "Can't read config? %d\n", err);
+		goto exit;
+	}
+
+	new = err & ~clr_mask;
+	new |= set_mask;
+	if (err != new)
+		lm75_write_value(client, LM75_REG_CONF, new);
+	dev_dbg(dev, "Config %02x\n", new);
+
+	if (!dev->device_node) {
+		dev_err(dev, "No device_node associated with the device\n");
+		err = -EINVAL;
+		goto exit;
+	}
+
+	data->sensor.name = of_get_property(dev->device_node,
+					    "barebox,sensor-name",
+					    NULL);
+	if (!data->sensor.name) {
+		dev_err(dev, "No sensor-name specified\n");
+		err = -EINVAL;
+		goto exit;
+	}
+
+	data->sensor.read = lm75_read_temp;
+	data->sensor.dev = dev;
+
+	err = hwmon_sensor_register(&data->sensor);
+
+exit:
+	if (err) {
+		free(data);
+		return err;
+	}
+
+	return 0;
+}
+
+static const struct platform_device_id lm75_ids[] = {
+	{ "lm75", lm75, },
+	{ /* LIST END */ }
+};
+
+static struct driver_d lm75_driver = {
+	.name		= "lm75",
+	.probe		= lm75_probe,
+	.id_table	= lm75_ids,
+};
+
+static int lm75_init(void)
+{
+	return i2c_driver_register(&lm75_driver);
+}
+device_initcall(lm75_init);
diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h
new file mode 100644
index 0000000..9ffe83e
--- /dev/null
+++ b/drivers/hwmon/lm75.h
@@ -0,0 +1,48 @@
+/*
+    lm75.h - Part of lm_sensors, Linux kernel modules for hardware
+	      monitoring
+    Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com>
+
+    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.
+*/
+
+/*
+    This file contains common code for encoding/decoding LM75 type
+    temperature readings, which are emulated by many of the chips
+    we support.  As the user is unlikely to load more than one driver
+    which contains this code, we don't worry about the wasted space.
+*/
+
+
+/* straight from the datasheet */
+#define LM75_TEMP_MIN (-55000)
+#define LM75_TEMP_MAX 125000
+#define LM75_SHUTDOWN 0x01
+
+/* TEMP: 0.001C/bit (-55C to +125C)
+   REG: (0.5C/bit, two's complement) << 7 */
+static inline u16 LM75_TEMP_TO_REG(long temp)
+{
+	int ntemp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
+	ntemp += (ntemp < 0 ? -250 : 250);
+	return (u16)((ntemp / 500) << 7);
+}
+
+static inline int LM75_TEMP_FROM_REG(u16 reg)
+{
+	/* use integer division instead of equivalent right shift to
+	   guarantee arithmetic shift and preserve the sign */
+	return ((s16)reg / 128) * 500;
+}
--
2.5.0

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

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

* [PATCH 7/7] hwmon: Port TEMPMON sensor driver
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
                   ` (4 preceding siblings ...)
  2015-12-07  7:52 ` [PATCH 6/7] hwmon: Port Linux driver for LM75 sensor Andrey Smirnov
@ 2015-12-07  7:52 ` Andrey Smirnov
  2015-12-07 19:05   ` Trent Piepho
  2015-12-07 10:23 ` [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Sascha Hauer
  6 siblings, 1 reply; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Port TEMPMON sensor driver from U-Boot.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/hwmon/Kconfig       |   6 ++
 drivers/hwmon/Makefile      |   1 +
 drivers/hwmon/imx_thermal.c | 234 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 241 insertions(+)
 create mode 100644 drivers/hwmon/imx_thermal.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index db51d26..92e27ea 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -22,4 +22,10 @@ config SENSORS_LM75

 		- National Semiconductor LM75, LM75A

+config SENSORS_IMX_THERMAL
+       tristate "Temperature sensor driver for Freescale i.MX SoCs"
+       help
+         Support for Temperature Monitor (TEMPMON) found on Freescale
+         i.MX SoCs.
+
 endif # HWMON
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index e73e681..4a0d316 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_HWMON)		+= class.o

 obj-$(CONFIG_SENSORS_LM75)	+= lm75.o
+obj-$(CONFIG_SENSORS_IMX_THERMAL) += imx_thermal.o
diff --git a/drivers/hwmon/imx_thermal.c b/drivers/hwmon/imx_thermal.c
new file mode 100644
index 0000000..f9c506b
--- /dev/null
+++ b/drivers/hwmon/imx_thermal.c
@@ -0,0 +1,234 @@
+/*
+ * tempmon.c - handle most I2C EEPROMs
+ *
+ * Copyright (C) 2005-2007 David Brownell
+ * Copyright (C) 2008 Wolfram Sang, Pengutronix
+ *
+ * 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.
+ */
+
+#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 <hwmon.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 hwmon_sensor sensor;
+};
+
+static inline struct imx_thermal_data *
+to_imx_thermal_data(struct hwmon_sensor *sensor)
+{
+	return container_of(sensor, struct imx_thermal_data, sensor);
+}
+
+
+static int imx_thermal_read_temperature(struct hwmon_sensor *sensor,
+					s32 *reading)
+{
+	uint64_t start;
+	uint32_t tempsense0, tempsense1;
+	uint16_t n_meas;
+	struct imx_thermal_data *imx_thermal = to_imx_thermal_data(sensor);
+
+	/*
+	 * 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->sensor.dev,
+				"timeout waiting for TEMPMON 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);
+
+	*reading = (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;
+	struct device_d *anatop;
+	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;
+	}
+
+	ocotp = cdev_by_device_node(node);
+	if (!ocotp) {
+		dev_err(dev, "no OCOTP character device\n");
+		return -ENODEV;
+	}
+
+	ret = cdev_do_open(ocotp, O_RDONLY);
+	if (!ret) {
+		ret = cdev_read(ocotp,
+				&ocotp_ana1, sizeof(ocotp_ana1),
+				OCOTP_ANA1_OFFSET, 0);
+
+		cdev_close(ocotp);
+
+		if (ret != sizeof(ocotp_ana1)) {
+			dev_err(dev, "failed to read calibration data\n");
+			return -EINVAL;
+		}
+	} else {
+		dev_err(dev, "failed to open %s\n", ocotp->name);
+		return -EINVAL;
+	}
+
+	if (ocotp_ana1 == 0 || ocotp_ana1 == ~0) {
+		dev_err(dev, "invalid sensor calibration data\n");
+		return -EINVAL;
+	}
+
+	node = of_parse_phandle(dev->device_node, "fsl,tempmon", 0);
+	if (!node) {
+		dev_err(dev, "failed to get the value of 'fsl,tempmon'\n");
+		return -ENODEV;
+	}
+
+	anatop = of_find_device_by_node(node);
+	if (!anatop) {
+		dev_err(dev, "failed to find 'fsl,tempmon' device\n");
+		return -ENODEV;
+
+	}
+
+	imx_thermal = xzalloc(sizeof(*imx_thermal));
+
+	imx_thermal->base = dev_request_mem_region(anatop, 0);
+	if (IS_ERR(imx_thermal->base)) {
+		ret = PTR_ERR(imx_thermal->base);
+		goto fail;
+	}
+
+	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 fail;
+	}
+
+	clk_enable(imx_thermal->clk);
+
+	if (!dev->device_node) {
+		dev_err(dev, "No device_node associated with the device\n");
+		ret = -EINVAL;
+		goto disable_clock;
+	}
+
+	imx_thermal->sensor.name = of_get_property(dev->device_node,
+						   "barebox,sensor-name",
+						   NULL);
+	if (!imx_thermal->sensor.name) {
+		dev_err(dev, "No sensor-name specified\n");
+		ret = -EINVAL;
+		goto disable_clock;
+	}
+
+	imx_thermal->sensor.read = imx_thermal_read_temperature;
+	imx_thermal->sensor.dev = dev;
+
+	return hwmon_sensor_register(&imx_thermal->sensor);
+
+disable_clock:
+	clk_disable(imx_thermal->clk);
+fail:
+	kfree(imx_thermal);
+	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),
+};
+
+static int imx_thermal_init(void)
+{
+	platform_driver_register(&imx_thermal_driver);
+	return 0;
+}
+device_initcall(imx_thermal_init);
--
2.5.0

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

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

* Re: [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node'
  2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
                   ` (5 preceding siblings ...)
  2015-12-07  7:52 ` [PATCH 7/7] hwmon: Port TEMPMON sensor driver Andrey Smirnov
@ 2015-12-07 10:23 ` Sascha Hauer
  2015-12-07 19:35   ` Andrey Smirnov
  6 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2015-12-07 10:23 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey,

I had to port the LM75 driver to barebox just a few days ago and so came
up with exactly the same patch 2/7 and 3/7. I applied 1-3 right away.

In my case I not only have a LM75 but also a PT100 connected to a
Microchip MCP3421 which in Linux is abstracted as a IIO device. IIO has
the advantage that it's more formalized and has it's own device tree
binding that allows to connect sensor devices with their consumers. I
picked some of the pieces from IIO and created something I called
iodevice. I'll post it in the next few days. One thing I am missing in
your approach is the readout of values as device parameters so that the
values can be evaluated in scripts. On the other hand you have a command
that allows to show the values of all sensors which I currently don't
have. Maybe we can distil the best of both approaches.

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] 14+ messages in thread

* Re: [PATCH 7/7] hwmon: Port TEMPMON sensor driver
  2015-12-07  7:52 ` [PATCH 7/7] hwmon: Port TEMPMON sensor driver Andrey Smirnov
@ 2015-12-07 19:05   ` Trent Piepho
  2015-12-07 19:40     ` Andrey Smirnov
  0 siblings, 1 reply; 14+ messages in thread
From: Trent Piepho @ 2015-12-07 19:05 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Sun, 2015-12-06 at 23:52 -0800, Andrey Smirnov wrote:
> +
> +       imx_thermal->sensor.name = of_get_property(dev->device_node,
> +
> "barebox,sensor-name",
> +                                                  NULL);

Wouldn't aliases the proper OF way to do this?
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node'
  2015-12-07 10:23 ` [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Sascha Hauer
@ 2015-12-07 19:35   ` Andrey Smirnov
  0 siblings, 0 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07 19:35 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Mon, Dec 7, 2015 at 2:23 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> Hi Andrey,
>
> I had to port the LM75 driver to barebox just a few days ago and so came
> up with exactly the same patch 2/7 and 3/7. I applied 1-3 right away.
>

Shucks! I had those three patches sitting on my laptop for a couple of
weeks. Sorry for procrastinating with submitting them, could have
saved you some trouble :-)


> In my case I not only have a LM75 but also a PT100 connected to a
> Microchip MCP3421 which in Linux is abstracted as a IIO device. IIO has
> the advantage that it's more formalized and has it's own device tree
> binding that allows to connect sensor devices with their consumers. I
> picked some of the pieces from IIO and created something I called
> iodevice. I'll post it in the next few days. One thing I am missing in
> your approach is the readout of values as device parameters so that the
> values can be evaluated in scripts. On the other hand you have a command
> that allows to show the values of all sensors which I currently don't
> have. Maybe we can distil the best of both approaches.

I would be more than happy to work on combining our code. How about
you go ahead and submit your framework/drivers and I'll rework TEMPMON
and hwmon (should we rename the command?) patches to use it. I doubt
there would be anything worth salvaging in my LM75 driver, so we can
just drop that patch.

Sounds good?

Thanks,
Andrey

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

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

* Re: [PATCH 7/7] hwmon: Port TEMPMON sensor driver
  2015-12-07 19:05   ` Trent Piepho
@ 2015-12-07 19:40     ` Andrey Smirnov
  2015-12-07 19:52       ` Trent Piepho
  0 siblings, 1 reply; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07 19:40 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

On Mon, Dec 7, 2015 at 11:05 AM, Trent Piepho <tpiepho@kymetacorp.com> wrote:
> On Sun, 2015-12-06 at 23:52 -0800, Andrey Smirnov wrote:
>> +
>> +       imx_thermal->sensor.name = of_get_property(dev->device_node,
>> +
>> "barebox,sensor-name",
>> +                                                  NULL);
>
> Wouldn't aliases the proper OF way to do this?

I must admit I am not familiar with the feature you are talking about
(or maybe I am just not understanding what you mean well), can you
give me a very brief example? Given my ignorance I wouldn't be
surprised that it is.

Thanks,
Andrey

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

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

* Re: [PATCH 7/7] hwmon: Port TEMPMON sensor driver
  2015-12-07 19:40     ` Andrey Smirnov
@ 2015-12-07 19:52       ` Trent Piepho
  2015-12-07 19:56         ` Andrey Smirnov
  0 siblings, 1 reply; 14+ messages in thread
From: Trent Piepho @ 2015-12-07 19:52 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Mon, 2015-12-07 at 11:40 -0800, Andrey Smirnov wrote:
> On Mon, Dec 7, 2015 at 11:05 AM, Trent Piepho <tpiepho@kymetacorp.com> wrote:
> > On Sun, 2015-12-06 at 23:52 -0800, Andrey Smirnov wrote:
> >> +
> >> +       imx_thermal->sensor.name = of_get_property(dev->device_node,
> >> +
> >> "barebox,sensor-name",
> >> +                                                  NULL);
> >
> > Wouldn't aliases the proper OF way to do this?
> 
> I must admit I am not familiar with the feature you are talking about
> (or maybe I am just not understanding what you mean well), can you
> give me a very brief example? Given my ignorance I wouldn't be
> surprised that it is.

There is an aliases section at the root of the OF tree, which has
properties set to a phandle for the device the property's name serves as
an alias for.  There was a patch to this list last week sometime that
added alias support to the at24 driver for naming eeproms.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 7/7] hwmon: Port TEMPMON sensor driver
  2015-12-07 19:52       ` Trent Piepho
@ 2015-12-07 19:56         ` Andrey Smirnov
  0 siblings, 0 replies; 14+ messages in thread
From: Andrey Smirnov @ 2015-12-07 19:56 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

On Mon, Dec 7, 2015 at 11:52 AM, Trent Piepho <tpiepho@kymetacorp.com> wrote:
> On Mon, 2015-12-07 at 11:40 -0800, Andrey Smirnov wrote:
>> On Mon, Dec 7, 2015 at 11:05 AM, Trent Piepho <tpiepho@kymetacorp.com> wrote:
>> > On Sun, 2015-12-06 at 23:52 -0800, Andrey Smirnov wrote:
>> >> +
>> >> +       imx_thermal->sensor.name = of_get_property(dev->device_node,
>> >> +
>> >> "barebox,sensor-name",
>> >> +                                                  NULL);
>> >
>> > Wouldn't aliases the proper OF way to do this?
>>
>> I must admit I am not familiar with the feature you are talking about
>> (or maybe I am just not understanding what you mean well), can you
>> give me a very brief example? Given my ignorance I wouldn't be
>> surprised that it is.
>
> There is an aliases section at the root of the OF tree, which has
> properties set to a phandle for the device the property's name serves as
> an alias for.  There was a patch to this list last week sometime that
> added alias support to the at24 driver for naming eeproms.

Ah, I see. Yes, that definitely would be a better way to do what I am
trying to do. I'll keep that feature in mind for next version of the
patch.

Thank you,
Andrey

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

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

* Re: [PATCH 5/7] commands: Add 'hwmon' command
  2015-12-07  7:52 ` [PATCH 5/7] commands: Add 'hwmon' command Andrey Smirnov
@ 2015-12-10 11:20   ` Antony Pavlov
  0 siblings, 0 replies; 14+ messages in thread
From: Antony Pavlov @ 2015-12-10 11:20 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Sun,  6 Dec 2015 23:52:41 -0800
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:

> 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  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 56 insertions(+)
>  create mode 100644 commands/hwmon.c
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 1743670..a338efd 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -1799,6 +1799,14 @@ config CMD_HWCLOCK
>  	help
>  	  The hwclock command allows to query or set the hardware clock (RTC).
> 
> +config CMD_HWMON
> +	bool
> +	depends on HWMON
> +	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 d985341..6c5158c 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -105,6 +105,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..84c0c70
> --- /dev/null
> +++ b/commands/hwmon.c
> @@ -0,0 +1,47 @@
> +#include <common.h>
> +#include <command.h>
> +#include <getopt.h>
> +#include <linux/err.h>
> +#include <linux/ctype.h>
> +#include <string.h>
> +#include <environment.h>
> +#include <hwmon.h>
> +
> +static int do_hwmon(int argc, char *argv[])
> +{
> +	struct hwmon_sensor *s;
> +
> +	for_each_hwmon_sensor(s) {
> +		s32 value;
> +		int ret = hwmon_sensor_read(s, &value);
> +
> +		if (ret < 0) {
> +			printf("%s -- failed to read the sensor (%d)\n", s->name, ret);
> +			continue;
> +		}
> +
> +		switch (s->type) {
> +		case SENSOR_TEMPERATURE:
> +			printf("name: %s, reading: %d.%03d C\n",
> +			       s->name, (int)(value / 1000), (int)abs(value % 1000));
> +			break;
> +		default:
> +			printf("%s -- unknow type of sensor\n", s->name);
> +			break;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +#if 0
> +BAREBOX_CMD_HELP_START(hwmon)
> +BAREBOX_CMD_HELP_END
> +#endif
> +

Please complete help stuff.


-- 
-- 
Best regards,
  Antony Pavlov

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

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

end of thread, other threads:[~2015-12-10 10:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-07  7:52 [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Andrey Smirnov
2015-12-07  7:52 ` [PATCH 2/7] drivers: bus: Match against id_table first Andrey Smirnov
2015-12-07  7:52 ` [PATCH 3/7] i2c: Port two utility functions from Linux kernel Andrey Smirnov
2015-12-07  7:52 ` [PATCH 4/7] drivers: Introduce hardware monitoring subsystem Andrey Smirnov
2015-12-07  7:52 ` [PATCH 5/7] commands: Add 'hwmon' command Andrey Smirnov
2015-12-10 11:20   ` Antony Pavlov
2015-12-07  7:52 ` [PATCH 6/7] hwmon: Port Linux driver for LM75 sensor Andrey Smirnov
2015-12-07  7:52 ` [PATCH 7/7] hwmon: Port TEMPMON sensor driver Andrey Smirnov
2015-12-07 19:05   ` Trent Piepho
2015-12-07 19:40     ` Andrey Smirnov
2015-12-07 19:52       ` Trent Piepho
2015-12-07 19:56         ` Andrey Smirnov
2015-12-07 10:23 ` [PATCH 1/7] imx: ocotp: Add code to initialize 'cdev->device_node' Sascha Hauer
2015-12-07 19:35   ` Andrey Smirnov

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