All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/4] Introduce MEN 14F021P BMC driver series
@ 2014-08-13  8:38 ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

This patch set add support for the MEN 14F021P00 Board Management called BMC.

The BMC is a PIC Mikrocontroller which assembled on almost all of our
3U Compact PCI CPU board and a few Box PCs.
main part of the BMC is to start and monitor the board, but there are a
lot more features which can be accessed using an I2C Host interface

Features supported in this Patchset:
        - Watchdog
        - LEDs
	- HWMON

The Patchset includes a MFD Core driver, Watchdog, hwmon  and LEDs driver.

Changes in v4:
	- fixed some style issues
	- fixed GPL license version
	- added hwmon voltage monitoring slave driver

Changes in v3:
        - deleted i2c_smbus wrapper functions and use native one
        - some cosmentics and variable renaming to be more clear
        - renamed "leave production" mode to "exit production mode"

Changes in v2:
        - changed i2c_smbus_read wrapper function to return both, value
          and error.
        - moved "leave production mode" from Watchdog driver to mfd core.
        - fixed some return values in the watchdog driver to return the original
          error value instead of -EIO.


Andreas Werner (4):
  drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog
    driver
  drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver

 drivers/hwmon/Kconfig            |   7 ++
 drivers/hwmon/Makefile           |   1 +
 drivers/hwmon/menf21bmc_hwmon.c  | 238 +++++++++++++++++++++++++++++++++++++++
 drivers/leds/Kconfig             |   6 +
 drivers/leds/Makefile            |   1 +
 drivers/leds/leds-menf21bmc.c    | 131 +++++++++++++++++++++
 drivers/mfd/Kconfig              |  12 ++
 drivers/mfd/Makefile             |   1 +
 drivers/mfd/menf21bmc.c          | 132 ++++++++++++++++++++++
 drivers/watchdog/Kconfig         |   7 ++
 drivers/watchdog/Makefile        |   1 +
 drivers/watchdog/menf21bmc_wdt.c | 203 +++++++++++++++++++++++++++++++++
 12 files changed, 740 insertions(+)
 create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
 create mode 100644 drivers/leds/leds-menf21bmc.c
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 drivers/watchdog/menf21bmc_wdt.c

-- 
2.0.4

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

* [PATCH v4 0/4] Introduce MEN 14F021P BMC driver series
@ 2014-08-13  8:38 ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

This patch set add support for the MEN 14F021P00 Board Management called BMC.

The BMC is a PIC Mikrocontroller which assembled on almost all of our
3U Compact PCI CPU board and a few Box PCs.
main part of the BMC is to start and monitor the board, but there are a
lot more features which can be accessed using an I2C Host interface

Features supported in this Patchset:
        - Watchdog
        - LEDs
	- HWMON

The Patchset includes a MFD Core driver, Watchdog, hwmon  and LEDs driver.

Changes in v4:
	- fixed some style issues
	- fixed GPL license version
	- added hwmon voltage monitoring slave driver

Changes in v3:
        - deleted i2c_smbus wrapper functions and use native one
        - some cosmentics and variable renaming to be more clear
        - renamed "leave production" mode to "exit production mode"

Changes in v2:
        - changed i2c_smbus_read wrapper function to return both, value
          and error.
        - moved "leave production mode" from Watchdog driver to mfd core.
        - fixed some return values in the watchdog driver to return the original
          error value instead of -EIO.


Andreas Werner (4):
  drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog
    driver
  drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver

 drivers/hwmon/Kconfig            |   7 ++
 drivers/hwmon/Makefile           |   1 +
 drivers/hwmon/menf21bmc_hwmon.c  | 238 +++++++++++++++++++++++++++++++++++++++
 drivers/leds/Kconfig             |   6 +
 drivers/leds/Makefile            |   1 +
 drivers/leds/leds-menf21bmc.c    | 131 +++++++++++++++++++++
 drivers/mfd/Kconfig              |  12 ++
 drivers/mfd/Makefile             |   1 +
 drivers/mfd/menf21bmc.c          | 132 ++++++++++++++++++++++
 drivers/watchdog/Kconfig         |   7 ++
 drivers/watchdog/Makefile        |   1 +
 drivers/watchdog/menf21bmc_wdt.c | 203 +++++++++++++++++++++++++++++++++
 12 files changed, 740 insertions(+)
 create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
 create mode 100644 drivers/leds/leds-menf21bmc.c
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 drivers/watchdog/menf21bmc_wdt.c

-- 
2.0.4


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

* [lm-sensors] [PATCH v4 0/4] Introduce MEN 14F021P BMC driver series
@ 2014-08-13  8:38 ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

This patch set add support for the MEN 14F021P00 Board Management called BMC.

The BMC is a PIC Mikrocontroller which assembled on almost all of our
3U Compact PCI CPU board and a few Box PCs.
main part of the BMC is to start and monitor the board, but there are a
lot more features which can be accessed using an I2C Host interface

Features supported in this Patchset:
        - Watchdog
        - LEDs
	- HWMON

The Patchset includes a MFD Core driver, Watchdog, hwmon  and LEDs driver.

Changes in v4:
	- fixed some style issues
	- fixed GPL license version
	- added hwmon voltage monitoring slave driver

Changes in v3:
        - deleted i2c_smbus wrapper functions and use native one
        - some cosmentics and variable renaming to be more clear
        - renamed "leave production" mode to "exit production mode"

Changes in v2:
        - changed i2c_smbus_read wrapper function to return both, value
          and error.
        - moved "leave production mode" from Watchdog driver to mfd core.
        - fixed some return values in the watchdog driver to return the original
          error value instead of -EIO.


Andreas Werner (4):
  drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog
    driver
  drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver

 drivers/hwmon/Kconfig            |   7 ++
 drivers/hwmon/Makefile           |   1 +
 drivers/hwmon/menf21bmc_hwmon.c  | 238 +++++++++++++++++++++++++++++++++++++++
 drivers/leds/Kconfig             |   6 +
 drivers/leds/Makefile            |   1 +
 drivers/leds/leds-menf21bmc.c    | 131 +++++++++++++++++++++
 drivers/mfd/Kconfig              |  12 ++
 drivers/mfd/Makefile             |   1 +
 drivers/mfd/menf21bmc.c          | 132 ++++++++++++++++++++++
 drivers/watchdog/Kconfig         |   7 ++
 drivers/watchdog/Makefile        |   1 +
 drivers/watchdog/menf21bmc_wdt.c | 203 +++++++++++++++++++++++++++++++++
 12 files changed, 740 insertions(+)
 create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
 create mode 100644 drivers/leds/leds-menf21bmc.c
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 drivers/watchdog/menf21bmc_wdt.c

-- 
2.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-08-13  8:38 ` Andreas Werner
  (?)
@ 2014-08-13  8:39   ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

The MEN 14F021P00 Board Management Controller provides an
I2C interface to the host to access the feature implemented in the BMC.
The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
and on a few Box/Display Computer.

Added MFD Core driver, supporting the I2C communication to the device.

The MFD driver currently supports the following features:
 	- Watchdog
 	- LEDs
	- Hwmon (voltage monitoring)

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mfd/Kconfig     |  12 +++++
 drivers/mfd/Makefile    |   1 +
 drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 drivers/mfd/menf21bmc.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b8d9ca0..bf155b9 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -453,6 +453,18 @@ config MFD_MAX8998
 	  additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_MENF21BMC
+	tristate "MEN 14F021P00 Board Management Controller Support"
+	depends on I2C=y
+	select MFD_CORE
+	help
+	  Say yes here to add support for the MEN 14F021P00 BMC
+	  which is a Board Management Controller connected to the I2C bus.
+	  The device supports multiple sub-devices like LED, HWMON  and WDT.
+	  This driver provides common support for accessing the devices;
+	  additional drivers must be enabled in order to use the
+	  functionality of the BMC device.
+
 config EZX_PCAP
 	bool "Motorola EZXPCAP Support"
 	depends on SPI_MASTER
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 4e2bc25..37bf336 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711)	+= as3711.o
 obj-$(CONFIG_MFD_AS3722)	+= as3722.o
 obj-$(CONFIG_MFD_STW481X)	+= stw481x.o
 obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
+obj-$(CONFIG_MFD_MENF21BMC)	+= menf21bmc.o
 
 intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
 obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
new file mode 100644
index 0000000..a6eb03f
--- /dev/null
+++ b/drivers/mfd/menf21bmc.c
@@ -0,0 +1,132 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/mfd/core.h>
+
+#define BMC_CMD_WDT_EXIT_PROD	0x18
+#define BMC_CMD_WDT_PROD_STAT	0x19
+#define BMC_CMD_REV_MAJOR	0x80
+#define BMC_CMD_REV_MINOR	0x81
+#define BMC_CMD_REV_MAIN	0x82
+
+static struct mfd_cell menf21bmc_cell[] = {
+	{ .name = "menf21bmc_wdt", },
+	{ .name = "menf21bmc_led", },
+	{ .name = "menf21bmc_hwmon", }
+};
+
+static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
+{
+	int val, ret;
+
+	val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
+	if (val < 0)
+		return val;
+
+	/*
+	 * Production mode should be not active after delivery of the Board.
+	 * To be sure we check it, inform the user and exit the mode
+	 * if active.
+	 */
+	if (val == 0x00) {
+		dev_info(&client->dev,
+			"BMC in production mode. Exit production mode\n");
+
+		ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int
+menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
+{
+	int ret;
+	int rev_major, rev_minor, rev_main;
+
+	ret = i2c_check_functionality(client->adapter,
+				      I2C_FUNC_SMBUS_BYTE_DATA |
+				      I2C_FUNC_SMBUS_WORD_DATA |
+				      I2C_FUNC_SMBUS_BYTE);
+	if (!ret)
+		return -ENODEV;
+
+	rev_major = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAJOR);
+	if (rev_major < 0) {
+		dev_err(&client->dev, "failed to get BMC major revision\n");
+		return rev_major;
+	}
+
+	rev_minor = i2c_smbus_read_word_data(client, BMC_CMD_REV_MINOR);
+	if (rev_minor < 0) {
+		dev_err(&client->dev, "failed to get BMC minor revision\n");
+		return rev_minor;
+	}
+
+	rev_main = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAIN);
+	if (rev_main < 0) {
+		dev_err(&client->dev, "failed to get BMC main revision\n");
+		return rev_main;
+	}
+
+	dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
+					rev_major, rev_minor, rev_main);
+
+	/*
+	 * We have to exit the Production Mode of the BMC to activate the
+	 * Watchdog functionality and the BIOS life sign monitoring.
+	 */
+	ret = menf21bmc_wdt_exit_prod_mode(client);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to leave production mode\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
+				ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to add BMC sub-devices\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int menf21bmc_remove(struct i2c_client *client)
+{
+	mfd_remove_devices(&client->dev);
+	return 0;
+}
+
+static const struct i2c_device_id menf21bmc_id_table[] = {
+	{ "menf21bmc", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, menf21bmc_id_table);
+
+static struct i2c_driver menf21bmc_driver = {
+	.driver.name	= "menf21bmc",
+	.id_table	= menf21bmc_id_table,
+	.probe		= menf21bmc_probe,
+	.remove		= menf21bmc_remove,
+};
+
+module_i2c_driver(menf21bmc_driver);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC mfd core driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
-- 
2.0.4

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

* [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-13  8:39   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

The MEN 14F021P00 Board Management Controller provides an
I2C interface to the host to access the feature implemented in the BMC.
The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
and on a few Box/Display Computer.

Added MFD Core driver, supporting the I2C communication to the device.

The MFD driver currently supports the following features:
 	- Watchdog
 	- LEDs
	- Hwmon (voltage monitoring)

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mfd/Kconfig     |  12 +++++
 drivers/mfd/Makefile    |   1 +
 drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 drivers/mfd/menf21bmc.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b8d9ca0..bf155b9 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -453,6 +453,18 @@ config MFD_MAX8998
 	  additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_MENF21BMC
+	tristate "MEN 14F021P00 Board Management Controller Support"
+	depends on I2C=y
+	select MFD_CORE
+	help
+	  Say yes here to add support for the MEN 14F021P00 BMC
+	  which is a Board Management Controller connected to the I2C bus.
+	  The device supports multiple sub-devices like LED, HWMON  and WDT.
+	  This driver provides common support for accessing the devices;
+	  additional drivers must be enabled in order to use the
+	  functionality of the BMC device.
+
 config EZX_PCAP
 	bool "Motorola EZXPCAP Support"
 	depends on SPI_MASTER
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 4e2bc25..37bf336 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711)	+= as3711.o
 obj-$(CONFIG_MFD_AS3722)	+= as3722.o
 obj-$(CONFIG_MFD_STW481X)	+= stw481x.o
 obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
+obj-$(CONFIG_MFD_MENF21BMC)	+= menf21bmc.o
 
 intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
 obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
new file mode 100644
index 0000000..a6eb03f
--- /dev/null
+++ b/drivers/mfd/menf21bmc.c
@@ -0,0 +1,132 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/mfd/core.h>
+
+#define BMC_CMD_WDT_EXIT_PROD	0x18
+#define BMC_CMD_WDT_PROD_STAT	0x19
+#define BMC_CMD_REV_MAJOR	0x80
+#define BMC_CMD_REV_MINOR	0x81
+#define BMC_CMD_REV_MAIN	0x82
+
+static struct mfd_cell menf21bmc_cell[] = {
+	{ .name = "menf21bmc_wdt", },
+	{ .name = "menf21bmc_led", },
+	{ .name = "menf21bmc_hwmon", }
+};
+
+static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
+{
+	int val, ret;
+
+	val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
+	if (val < 0)
+		return val;
+
+	/*
+	 * Production mode should be not active after delivery of the Board.
+	 * To be sure we check it, inform the user and exit the mode
+	 * if active.
+	 */
+	if (val == 0x00) {
+		dev_info(&client->dev,
+			"BMC in production mode. Exit production mode\n");
+
+		ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int
+menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
+{
+	int ret;
+	int rev_major, rev_minor, rev_main;
+
+	ret = i2c_check_functionality(client->adapter,
+				      I2C_FUNC_SMBUS_BYTE_DATA |
+				      I2C_FUNC_SMBUS_WORD_DATA |
+				      I2C_FUNC_SMBUS_BYTE);
+	if (!ret)
+		return -ENODEV;
+
+	rev_major = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAJOR);
+	if (rev_major < 0) {
+		dev_err(&client->dev, "failed to get BMC major revision\n");
+		return rev_major;
+	}
+
+	rev_minor = i2c_smbus_read_word_data(client, BMC_CMD_REV_MINOR);
+	if (rev_minor < 0) {
+		dev_err(&client->dev, "failed to get BMC minor revision\n");
+		return rev_minor;
+	}
+
+	rev_main = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAIN);
+	if (rev_main < 0) {
+		dev_err(&client->dev, "failed to get BMC main revision\n");
+		return rev_main;
+	}
+
+	dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
+					rev_major, rev_minor, rev_main);
+
+	/*
+	 * We have to exit the Production Mode of the BMC to activate the
+	 * Watchdog functionality and the BIOS life sign monitoring.
+	 */
+	ret = menf21bmc_wdt_exit_prod_mode(client);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to leave production mode\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
+				ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to add BMC sub-devices\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int menf21bmc_remove(struct i2c_client *client)
+{
+	mfd_remove_devices(&client->dev);
+	return 0;
+}
+
+static const struct i2c_device_id menf21bmc_id_table[] = {
+	{ "menf21bmc", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, menf21bmc_id_table);
+
+static struct i2c_driver menf21bmc_driver = {
+	.driver.name	= "menf21bmc",
+	.id_table	= menf21bmc_id_table,
+	.probe		= menf21bmc_probe,
+	.remove		= menf21bmc_remove,
+};
+
+module_i2c_driver(menf21bmc_driver);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC mfd core driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
-- 
2.0.4


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

* [lm-sensors] [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-13  8:39   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

The MEN 14F021P00 Board Management Controller provides an
I2C interface to the host to access the feature implemented in the BMC.
The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
and on a few Box/Display Computer.

Added MFD Core driver, supporting the I2C communication to the device.

The MFD driver currently supports the following features:
 	- Watchdog
 	- LEDs
	- Hwmon (voltage monitoring)

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mfd/Kconfig     |  12 +++++
 drivers/mfd/Makefile    |   1 +
 drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 drivers/mfd/menf21bmc.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b8d9ca0..bf155b9 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -453,6 +453,18 @@ config MFD_MAX8998
 	  additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_MENF21BMC
+	tristate "MEN 14F021P00 Board Management Controller Support"
+	depends on I2C=y
+	select MFD_CORE
+	help
+	  Say yes here to add support for the MEN 14F021P00 BMC
+	  which is a Board Management Controller connected to the I2C bus.
+	  The device supports multiple sub-devices like LED, HWMON  and WDT.
+	  This driver provides common support for accessing the devices;
+	  additional drivers must be enabled in order to use the
+	  functionality of the BMC device.
+
 config EZX_PCAP
 	bool "Motorola EZXPCAP Support"
 	depends on SPI_MASTER
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 4e2bc25..37bf336 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -169,6 +169,7 @@ obj-$(CONFIG_MFD_AS3711)	+= as3711.o
 obj-$(CONFIG_MFD_AS3722)	+= as3722.o
 obj-$(CONFIG_MFD_STW481X)	+= stw481x.o
 obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
+obj-$(CONFIG_MFD_MENF21BMC)	+= menf21bmc.o
 
 intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
 obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
new file mode 100644
index 0000000..a6eb03f
--- /dev/null
+++ b/drivers/mfd/menf21bmc.c
@@ -0,0 +1,132 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/mfd/core.h>
+
+#define BMC_CMD_WDT_EXIT_PROD	0x18
+#define BMC_CMD_WDT_PROD_STAT	0x19
+#define BMC_CMD_REV_MAJOR	0x80
+#define BMC_CMD_REV_MINOR	0x81
+#define BMC_CMD_REV_MAIN	0x82
+
+static struct mfd_cell menf21bmc_cell[] = {
+	{ .name = "menf21bmc_wdt", },
+	{ .name = "menf21bmc_led", },
+	{ .name = "menf21bmc_hwmon", }
+};
+
+static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
+{
+	int val, ret;
+
+	val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
+	if (val < 0)
+		return val;
+
+	/*
+	 * Production mode should be not active after delivery of the Board.
+	 * To be sure we check it, inform the user and exit the mode
+	 * if active.
+	 */
+	if (val = 0x00) {
+		dev_info(&client->dev,
+			"BMC in production mode. Exit production mode\n");
+
+		ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int
+menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
+{
+	int ret;
+	int rev_major, rev_minor, rev_main;
+
+	ret = i2c_check_functionality(client->adapter,
+				      I2C_FUNC_SMBUS_BYTE_DATA |
+				      I2C_FUNC_SMBUS_WORD_DATA |
+				      I2C_FUNC_SMBUS_BYTE);
+	if (!ret)
+		return -ENODEV;
+
+	rev_major = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAJOR);
+	if (rev_major < 0) {
+		dev_err(&client->dev, "failed to get BMC major revision\n");
+		return rev_major;
+	}
+
+	rev_minor = i2c_smbus_read_word_data(client, BMC_CMD_REV_MINOR);
+	if (rev_minor < 0) {
+		dev_err(&client->dev, "failed to get BMC minor revision\n");
+		return rev_minor;
+	}
+
+	rev_main = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAIN);
+	if (rev_main < 0) {
+		dev_err(&client->dev, "failed to get BMC main revision\n");
+		return rev_main;
+	}
+
+	dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
+					rev_major, rev_minor, rev_main);
+
+	/*
+	 * We have to exit the Production Mode of the BMC to activate the
+	 * Watchdog functionality and the BIOS life sign monitoring.
+	 */
+	ret = menf21bmc_wdt_exit_prod_mode(client);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to leave production mode\n");
+		return ret;
+	}
+
+	ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
+				ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to add BMC sub-devices\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int menf21bmc_remove(struct i2c_client *client)
+{
+	mfd_remove_devices(&client->dev);
+	return 0;
+}
+
+static const struct i2c_device_id menf21bmc_id_table[] = {
+	{ "menf21bmc", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, menf21bmc_id_table);
+
+static struct i2c_driver menf21bmc_driver = {
+	.driver.name	= "menf21bmc",
+	.id_table	= menf21bmc_id_table,
+	.probe		= menf21bmc_probe,
+	.remove		= menf21bmc_remove,
+};
+
+module_i2c_driver(menf21bmc_driver);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC mfd core driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
-- 
2.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog driver
  2014-08-13  8:38 ` Andreas Werner
  (?)
@ 2014-08-13  8:39   ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC Watchdog.
The BMC is a Board Management Controller including watchdog functionality.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/watchdog/Kconfig         |   7 ++
 drivers/watchdog/Makefile        |   1 +
 drivers/watchdog/menf21bmc_wdt.c | 203 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/watchdog/menf21bmc_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 76dd541..f96431d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -95,6 +95,13 @@ config GPIO_WATCHDOG
 	  If you say yes here you get support for watchdog device
 	  controlled through GPIO-line.
 
+config MENF21BMC_WATCHDOG
+	tristate "MEN 14F021P00 BMC Watchdog"
+	depends on MFD_MENF21BMC
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC Watchdog.
+
 config WM831X_WATCHDOG
 	tristate "WM831x watchdog"
 	depends on MFD_WM831X
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 468c320..de17014 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -178,3 +178,4 @@ obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
+obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c
new file mode 100644
index 0000000..604824d
--- /dev/null
+++ b/drivers/watchdog/menf21bmc_wdt.c
@@ -0,0 +1,203 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_wdt"
+
+#define BMC_CMD_WD_ON		0x11
+#define BMC_CMD_WD_OFF		0x12
+#define BMC_CMD_WD_TRIG		0x13
+#define BMC_CMD_WD_TIME		0x14
+#define BMC_CMD_WD_STATE	0x17
+#define BMC_WD_OFF_VAL		0x69
+#define BMC_CMD_RST_RSN		0x92
+
+#define BMC_WD_TIMEOUT_MIN	1	/* in sec */
+#define BMC_WD_TIMEOUT_MAX	6553	/* in sec */
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct menf21bmc_wdt {
+	struct watchdog_device wdt;
+	struct i2c_client *i2c_client;
+};
+
+static int menf21bmc_wdt_set_bootstatus(struct menf21bmc_wdt *data)
+{
+	int rst_rsn;
+
+	rst_rsn = i2c_smbus_read_byte_data(data->i2c_client, BMC_CMD_RST_RSN);
+	if (rst_rsn < 0)
+		return rst_rsn;
+
+	if (rst_rsn == 0x02)
+		data->wdt.bootstatus |= WDIOF_CARDRESET;
+	else if (rst_rsn == 0x05)
+		data->wdt.bootstatus |= WDIOF_EXTERN1;
+	else if (rst_rsn == 0x06)
+		data->wdt.bootstatus |= WDIOF_EXTERN2;
+	else if (rst_rsn == 0x0A)
+		data->wdt.bootstatus |= WDIOF_POWERUNDER;
+
+	return 0;
+}
+
+static int menf21bmc_wdt_start(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_ON);
+}
+
+static int menf21bmc_wdt_stop(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte_data(drv_data->i2c_client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static int
+menf21bmc_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout)
+{
+	int ret;
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	/*
+	 *  BMC Watchdog does have a resolution of 100ms.
+	 *  Watchdog API defines the timeout in seconds, so we have to
+	 *  multiply the value.
+	 */
+	ret = i2c_smbus_write_word_data(drv_data->i2c_client,
+						BMC_CMD_WD_TIME, timeout * 10);
+	if (ret < 0)
+		return ret;
+
+	wdt->timeout = timeout;
+
+	return 0;
+}
+
+static int menf21bmc_wdt_ping(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_TRIG);
+}
+
+static const struct watchdog_info menf21bmc_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = DEVNAME,
+};
+
+static const struct watchdog_ops menf21bmc_wdt_ops = {
+	.owner		= THIS_MODULE,
+	.start		= menf21bmc_wdt_start,
+	.stop		= menf21bmc_wdt_stop,
+	.ping		= menf21bmc_wdt_ping,
+	.set_timeout	= menf21bmc_wdt_settimeout,
+};
+
+static int menf21bmc_wdt_probe(struct platform_device *pdev)
+{
+	int ret, bmc_timeout;
+	struct menf21bmc_wdt *drv_data;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+	drv_data = devm_kzalloc(&pdev->dev,
+				sizeof(struct menf21bmc_wdt), GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+
+	drv_data->wdt.ops = &menf21bmc_wdt_ops;
+	drv_data->wdt.info = &menf21bmc_wdt_info;
+	drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN;
+	drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX;
+	drv_data->i2c_client = i2c_client;
+
+	/*
+	 * Get the current wdt timeout value from the BMC because
+	 * the BMC will save the value set before if the system restarts.
+	 */
+	bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client,
+							BMC_CMD_WD_TIME);
+	if (bmc_timeout < 0) {
+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+		return bmc_timeout;
+	}
+
+	watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev);
+	watchdog_set_nowayout(&drv_data->wdt, nowayout);
+	watchdog_set_drvdata(&drv_data->wdt, drv_data);
+	platform_set_drvdata(pdev, drv_data);
+
+	ret = menf21bmc_wdt_set_bootstatus(drv_data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+		return ret;
+	}
+
+	ret = watchdog_register_device(&drv_data->wdt);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register Watchdog device\n");
+		return ret;
+	}
+
+	dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
+
+	return 0;
+}
+
+static int menf21bmc_wdt_remove(struct platform_device *pdev)
+{
+	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+	dev_warn(&pdev->dev,
+		"Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
+
+	watchdog_unregister_device(&drv_data->wdt);
+
+	return 0;
+}
+
+static void menf21bmc_wdt_shutdown(struct platform_device *pdev)
+{
+	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+	i2c_smbus_write_word_data(drv_data->i2c_client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static struct  platform_driver menf21bmc_wdt = {
+	.driver		= {
+		.owner = THIS_MODULE,
+		.name	= DEVNAME,
+	},
+	.probe		= menf21bmc_wdt_probe,
+	.remove		= menf21bmc_wdt_remove,
+	.shutdown	= menf21bmc_wdt_shutdown,
+};
+
+module_platform_driver(menf21bmc_wdt);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_wdt");
-- 
2.0.4

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

* [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog driver
@ 2014-08-13  8:39   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC Watchdog.
The BMC is a Board Management Controller including watchdog functionality.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/watchdog/Kconfig         |   7 ++
 drivers/watchdog/Makefile        |   1 +
 drivers/watchdog/menf21bmc_wdt.c | 203 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/watchdog/menf21bmc_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 76dd541..f96431d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -95,6 +95,13 @@ config GPIO_WATCHDOG
 	  If you say yes here you get support for watchdog device
 	  controlled through GPIO-line.
 
+config MENF21BMC_WATCHDOG
+	tristate "MEN 14F021P00 BMC Watchdog"
+	depends on MFD_MENF21BMC
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC Watchdog.
+
 config WM831X_WATCHDOG
 	tristate "WM831x watchdog"
 	depends on MFD_WM831X
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 468c320..de17014 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -178,3 +178,4 @@ obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
+obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c
new file mode 100644
index 0000000..604824d
--- /dev/null
+++ b/drivers/watchdog/menf21bmc_wdt.c
@@ -0,0 +1,203 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_wdt"
+
+#define BMC_CMD_WD_ON		0x11
+#define BMC_CMD_WD_OFF		0x12
+#define BMC_CMD_WD_TRIG		0x13
+#define BMC_CMD_WD_TIME		0x14
+#define BMC_CMD_WD_STATE	0x17
+#define BMC_WD_OFF_VAL		0x69
+#define BMC_CMD_RST_RSN		0x92
+
+#define BMC_WD_TIMEOUT_MIN	1	/* in sec */
+#define BMC_WD_TIMEOUT_MAX	6553	/* in sec */
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct menf21bmc_wdt {
+	struct watchdog_device wdt;
+	struct i2c_client *i2c_client;
+};
+
+static int menf21bmc_wdt_set_bootstatus(struct menf21bmc_wdt *data)
+{
+	int rst_rsn;
+
+	rst_rsn = i2c_smbus_read_byte_data(data->i2c_client, BMC_CMD_RST_RSN);
+	if (rst_rsn < 0)
+		return rst_rsn;
+
+	if (rst_rsn == 0x02)
+		data->wdt.bootstatus |= WDIOF_CARDRESET;
+	else if (rst_rsn == 0x05)
+		data->wdt.bootstatus |= WDIOF_EXTERN1;
+	else if (rst_rsn == 0x06)
+		data->wdt.bootstatus |= WDIOF_EXTERN2;
+	else if (rst_rsn == 0x0A)
+		data->wdt.bootstatus |= WDIOF_POWERUNDER;
+
+	return 0;
+}
+
+static int menf21bmc_wdt_start(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_ON);
+}
+
+static int menf21bmc_wdt_stop(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte_data(drv_data->i2c_client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static int
+menf21bmc_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout)
+{
+	int ret;
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	/*
+	 *  BMC Watchdog does have a resolution of 100ms.
+	 *  Watchdog API defines the timeout in seconds, so we have to
+	 *  multiply the value.
+	 */
+	ret = i2c_smbus_write_word_data(drv_data->i2c_client,
+						BMC_CMD_WD_TIME, timeout * 10);
+	if (ret < 0)
+		return ret;
+
+	wdt->timeout = timeout;
+
+	return 0;
+}
+
+static int menf21bmc_wdt_ping(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_TRIG);
+}
+
+static const struct watchdog_info menf21bmc_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = DEVNAME,
+};
+
+static const struct watchdog_ops menf21bmc_wdt_ops = {
+	.owner		= THIS_MODULE,
+	.start		= menf21bmc_wdt_start,
+	.stop		= menf21bmc_wdt_stop,
+	.ping		= menf21bmc_wdt_ping,
+	.set_timeout	= menf21bmc_wdt_settimeout,
+};
+
+static int menf21bmc_wdt_probe(struct platform_device *pdev)
+{
+	int ret, bmc_timeout;
+	struct menf21bmc_wdt *drv_data;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+	drv_data = devm_kzalloc(&pdev->dev,
+				sizeof(struct menf21bmc_wdt), GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+
+	drv_data->wdt.ops = &menf21bmc_wdt_ops;
+	drv_data->wdt.info = &menf21bmc_wdt_info;
+	drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN;
+	drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX;
+	drv_data->i2c_client = i2c_client;
+
+	/*
+	 * Get the current wdt timeout value from the BMC because
+	 * the BMC will save the value set before if the system restarts.
+	 */
+	bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client,
+							BMC_CMD_WD_TIME);
+	if (bmc_timeout < 0) {
+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+		return bmc_timeout;
+	}
+
+	watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev);
+	watchdog_set_nowayout(&drv_data->wdt, nowayout);
+	watchdog_set_drvdata(&drv_data->wdt, drv_data);
+	platform_set_drvdata(pdev, drv_data);
+
+	ret = menf21bmc_wdt_set_bootstatus(drv_data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+		return ret;
+	}
+
+	ret = watchdog_register_device(&drv_data->wdt);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register Watchdog device\n");
+		return ret;
+	}
+
+	dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
+
+	return 0;
+}
+
+static int menf21bmc_wdt_remove(struct platform_device *pdev)
+{
+	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+	dev_warn(&pdev->dev,
+		"Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
+
+	watchdog_unregister_device(&drv_data->wdt);
+
+	return 0;
+}
+
+static void menf21bmc_wdt_shutdown(struct platform_device *pdev)
+{
+	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+	i2c_smbus_write_word_data(drv_data->i2c_client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static struct  platform_driver menf21bmc_wdt = {
+	.driver		= {
+		.owner = THIS_MODULE,
+		.name	= DEVNAME,
+	},
+	.probe		= menf21bmc_wdt_probe,
+	.remove		= menf21bmc_wdt_remove,
+	.shutdown	= menf21bmc_wdt_shutdown,
+};
+
+module_platform_driver(menf21bmc_wdt);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_wdt");
-- 
2.0.4


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

* [lm-sensors] [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog dri
@ 2014-08-13  8:39   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC Watchdog.
The BMC is a Board Management Controller including watchdog functionality.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/watchdog/Kconfig         |   7 ++
 drivers/watchdog/Makefile        |   1 +
 drivers/watchdog/menf21bmc_wdt.c | 203 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/watchdog/menf21bmc_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 76dd541..f96431d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -95,6 +95,13 @@ config GPIO_WATCHDOG
 	  If you say yes here you get support for watchdog device
 	  controlled through GPIO-line.
 
+config MENF21BMC_WATCHDOG
+	tristate "MEN 14F021P00 BMC Watchdog"
+	depends on MFD_MENF21BMC
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC Watchdog.
+
 config WM831X_WATCHDOG
 	tristate "WM831x watchdog"
 	depends on MFD_WM831X
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 468c320..de17014 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -178,3 +178,4 @@ obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
+obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
diff --git a/drivers/watchdog/menf21bmc_wdt.c b/drivers/watchdog/menf21bmc_wdt.c
new file mode 100644
index 0000000..604824d
--- /dev/null
+++ b/drivers/watchdog/menf21bmc_wdt.c
@@ -0,0 +1,203 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_wdt"
+
+#define BMC_CMD_WD_ON		0x11
+#define BMC_CMD_WD_OFF		0x12
+#define BMC_CMD_WD_TRIG		0x13
+#define BMC_CMD_WD_TIME		0x14
+#define BMC_CMD_WD_STATE	0x17
+#define BMC_WD_OFF_VAL		0x69
+#define BMC_CMD_RST_RSN		0x92
+
+#define BMC_WD_TIMEOUT_MIN	1	/* in sec */
+#define BMC_WD_TIMEOUT_MAX	6553	/* in sec */
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct menf21bmc_wdt {
+	struct watchdog_device wdt;
+	struct i2c_client *i2c_client;
+};
+
+static int menf21bmc_wdt_set_bootstatus(struct menf21bmc_wdt *data)
+{
+	int rst_rsn;
+
+	rst_rsn = i2c_smbus_read_byte_data(data->i2c_client, BMC_CMD_RST_RSN);
+	if (rst_rsn < 0)
+		return rst_rsn;
+
+	if (rst_rsn = 0x02)
+		data->wdt.bootstatus |= WDIOF_CARDRESET;
+	else if (rst_rsn = 0x05)
+		data->wdt.bootstatus |= WDIOF_EXTERN1;
+	else if (rst_rsn = 0x06)
+		data->wdt.bootstatus |= WDIOF_EXTERN2;
+	else if (rst_rsn = 0x0A)
+		data->wdt.bootstatus |= WDIOF_POWERUNDER;
+
+	return 0;
+}
+
+static int menf21bmc_wdt_start(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_ON);
+}
+
+static int menf21bmc_wdt_stop(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte_data(drv_data->i2c_client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static int
+menf21bmc_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout)
+{
+	int ret;
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	/*
+	 *  BMC Watchdog does have a resolution of 100ms.
+	 *  Watchdog API defines the timeout in seconds, so we have to
+	 *  multiply the value.
+	 */
+	ret = i2c_smbus_write_word_data(drv_data->i2c_client,
+						BMC_CMD_WD_TIME, timeout * 10);
+	if (ret < 0)
+		return ret;
+
+	wdt->timeout = timeout;
+
+	return 0;
+}
+
+static int menf21bmc_wdt_ping(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt);
+
+	return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_TRIG);
+}
+
+static const struct watchdog_info menf21bmc_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = DEVNAME,
+};
+
+static const struct watchdog_ops menf21bmc_wdt_ops = {
+	.owner		= THIS_MODULE,
+	.start		= menf21bmc_wdt_start,
+	.stop		= menf21bmc_wdt_stop,
+	.ping		= menf21bmc_wdt_ping,
+	.set_timeout	= menf21bmc_wdt_settimeout,
+};
+
+static int menf21bmc_wdt_probe(struct platform_device *pdev)
+{
+	int ret, bmc_timeout;
+	struct menf21bmc_wdt *drv_data;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+	drv_data = devm_kzalloc(&pdev->dev,
+				sizeof(struct menf21bmc_wdt), GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+
+	drv_data->wdt.ops = &menf21bmc_wdt_ops;
+	drv_data->wdt.info = &menf21bmc_wdt_info;
+	drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN;
+	drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX;
+	drv_data->i2c_client = i2c_client;
+
+	/*
+	 * Get the current wdt timeout value from the BMC because
+	 * the BMC will save the value set before if the system restarts.
+	 */
+	bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client,
+							BMC_CMD_WD_TIME);
+	if (bmc_timeout < 0) {
+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+		return bmc_timeout;
+	}
+
+	watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev);
+	watchdog_set_nowayout(&drv_data->wdt, nowayout);
+	watchdog_set_drvdata(&drv_data->wdt, drv_data);
+	platform_set_drvdata(pdev, drv_data);
+
+	ret = menf21bmc_wdt_set_bootstatus(drv_data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+		return ret;
+	}
+
+	ret = watchdog_register_device(&drv_data->wdt);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register Watchdog device\n");
+		return ret;
+	}
+
+	dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n");
+
+	return 0;
+}
+
+static int menf21bmc_wdt_remove(struct platform_device *pdev)
+{
+	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+	dev_warn(&pdev->dev,
+		"Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
+
+	watchdog_unregister_device(&drv_data->wdt);
+
+	return 0;
+}
+
+static void menf21bmc_wdt_shutdown(struct platform_device *pdev)
+{
+	struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev);
+
+	i2c_smbus_write_word_data(drv_data->i2c_client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static struct  platform_driver menf21bmc_wdt = {
+	.driver		= {
+		.owner = THIS_MODULE,
+		.name	= DEVNAME,
+	},
+	.probe		= menf21bmc_wdt_probe,
+	.remove		= menf21bmc_wdt_remove,
+	.shutdown	= menf21bmc_wdt_shutdown,
+};
+
+module_platform_driver(menf21bmc_wdt);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_wdt");
-- 
2.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  2014-08-13  8:38 ` Andreas Werner
  (?)
@ 2014-08-13  8:40   ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC LEDs.
The BMC is a Board Management Controller including four LEDs which
can be switched on and off.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/leds/Kconfig          |   6 ++
 drivers/leds/Makefile         |   1 +
 drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 drivers/leds/leds-menf21bmc.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 27cf0cd..d38ff3f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -458,6 +458,12 @@ config LEDS_OT200
 	  This option enables support for the LEDs on the Bachmann OT200.
 	  Say Y to enable LEDs on the Bachmann OT200.
 
+config LEDS_MENF21BMC
+	tristate "LED support for the MEN 14F021P00 BMC"
+	depends on LEDS_CLASS && MFD_MENF21BMC
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC LEDs.
+
 comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
 
 config LEDS_BLINKM
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3c03666..cadc433 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
 obj-$(CONFIG_LEDS_VERSATILE)		+= leds-versatile.o
+obj-$(CONFIG_LEDS_MENF21BMC)		+= leds-menf21bmc.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
new file mode 100644
index 0000000..4621f72
--- /dev/null
+++ b/drivers/leds/leds-menf21bmc.c
@@ -0,0 +1,131 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
+ *
+ *  This is the core LED driver of the MEN 14F021P00 BMC.
+ *  There are four LEDs available which can be switched on and off.
+ *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/i2c.h>
+
+#define BMC_CMD_LED_GET_SET	0xA0
+#define BMC_BIT_LED_STATUS	BIT(0)
+#define BMC_BIT_LED_HOTSWAP	BIT(1)
+#define BMC_BIT_LED_USER1	BIT(2)
+#define BMC_BIT_LED_USER2	BIT(3)
+
+struct menf21bmc_led {
+	struct led_classdev cdev;
+	u8 led_bit;
+	const char *name;
+	struct i2c_client *i2c_client;
+};
+
+static struct menf21bmc_led leds[] = {
+	{
+		.name = "menf21bmc:led_status",
+		.led_bit = BMC_BIT_LED_STATUS,
+	},
+	{
+		.name = "menf21bmc:led_hotswap",
+		.led_bit = BMC_BIT_LED_HOTSWAP,
+	},
+	{
+		.name = "menf21bmc:led_user1",
+		.led_bit = BMC_BIT_LED_USER1,
+	},
+	{
+		.name = "menf21bmc:led_user2",
+		.led_bit = BMC_BIT_LED_USER2,
+	}
+};
+
+static DEFINE_MUTEX(led_lock);
+
+static void
+menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	int led_val;
+	struct menf21bmc_led *led = container_of(led_cdev,
+					struct menf21bmc_led, cdev);
+
+	mutex_lock(&led_lock);
+	led_val = i2c_smbus_read_byte_data(led->i2c_client,
+						BMC_CMD_LED_GET_SET);
+	if (led_val < 0)
+		goto err_out;
+
+	if (value == LED_OFF)
+		led_val &= ~led->led_bit;
+	else
+		led_val |= led->led_bit;
+
+	i2c_smbus_write_byte_data(led->i2c_client,
+					BMC_CMD_LED_GET_SET, led_val);
+err_out:
+	mutex_unlock(&led_lock);
+}
+
+static int menf21bmc_led_probe(struct platform_device *pdev)
+{
+	int i;
+	int ret;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+	for (i = 0; i < ARRAY_SIZE(leds); i++) {
+		leds[i].cdev.name = leds[i].name;
+		leds[i].cdev.brightness_set = menf21bmc_led_set;
+		leds[i].i2c_client = i2c_client;
+		ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
+		if (ret < 0)
+			goto err_free_leds;
+	}
+	dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
+
+	return 0;
+
+err_free_leds:
+	dev_err(&pdev->dev, "failed to register LED device\n");
+
+	for (i = i - 1; i >= 0; i--)
+		led_classdev_unregister(&leds[i].cdev);
+
+	return ret;
+}
+
+static int menf21bmc_led_remove(struct platform_device *pdev)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(leds); i++)
+		led_classdev_unregister(&leds[i].cdev);
+
+	return 0;
+}
+
+static struct platform_driver menf21bmc_led = {
+	.probe		= menf21bmc_led_probe,
+	.remove		= menf21bmc_led_remove,
+	.driver		= {
+		.name		= "menf21bmc_led",
+		.owner		= THIS_MODULE,
+	},
+};
+
+module_platform_driver(menf21bmc_led);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_led");
-- 
2.0.4

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

* [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
@ 2014-08-13  8:40   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC LEDs.
The BMC is a Board Management Controller including four LEDs which
can be switched on and off.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/leds/Kconfig          |   6 ++
 drivers/leds/Makefile         |   1 +
 drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 drivers/leds/leds-menf21bmc.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 27cf0cd..d38ff3f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -458,6 +458,12 @@ config LEDS_OT200
 	  This option enables support for the LEDs on the Bachmann OT200.
 	  Say Y to enable LEDs on the Bachmann OT200.
 
+config LEDS_MENF21BMC
+	tristate "LED support for the MEN 14F021P00 BMC"
+	depends on LEDS_CLASS && MFD_MENF21BMC
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC LEDs.
+
 comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
 
 config LEDS_BLINKM
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3c03666..cadc433 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
 obj-$(CONFIG_LEDS_VERSATILE)		+= leds-versatile.o
+obj-$(CONFIG_LEDS_MENF21BMC)		+= leds-menf21bmc.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
new file mode 100644
index 0000000..4621f72
--- /dev/null
+++ b/drivers/leds/leds-menf21bmc.c
@@ -0,0 +1,131 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
+ *
+ *  This is the core LED driver of the MEN 14F021P00 BMC.
+ *  There are four LEDs available which can be switched on and off.
+ *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/i2c.h>
+
+#define BMC_CMD_LED_GET_SET	0xA0
+#define BMC_BIT_LED_STATUS	BIT(0)
+#define BMC_BIT_LED_HOTSWAP	BIT(1)
+#define BMC_BIT_LED_USER1	BIT(2)
+#define BMC_BIT_LED_USER2	BIT(3)
+
+struct menf21bmc_led {
+	struct led_classdev cdev;
+	u8 led_bit;
+	const char *name;
+	struct i2c_client *i2c_client;
+};
+
+static struct menf21bmc_led leds[] = {
+	{
+		.name = "menf21bmc:led_status",
+		.led_bit = BMC_BIT_LED_STATUS,
+	},
+	{
+		.name = "menf21bmc:led_hotswap",
+		.led_bit = BMC_BIT_LED_HOTSWAP,
+	},
+	{
+		.name = "menf21bmc:led_user1",
+		.led_bit = BMC_BIT_LED_USER1,
+	},
+	{
+		.name = "menf21bmc:led_user2",
+		.led_bit = BMC_BIT_LED_USER2,
+	}
+};
+
+static DEFINE_MUTEX(led_lock);
+
+static void
+menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	int led_val;
+	struct menf21bmc_led *led = container_of(led_cdev,
+					struct menf21bmc_led, cdev);
+
+	mutex_lock(&led_lock);
+	led_val = i2c_smbus_read_byte_data(led->i2c_client,
+						BMC_CMD_LED_GET_SET);
+	if (led_val < 0)
+		goto err_out;
+
+	if (value == LED_OFF)
+		led_val &= ~led->led_bit;
+	else
+		led_val |= led->led_bit;
+
+	i2c_smbus_write_byte_data(led->i2c_client,
+					BMC_CMD_LED_GET_SET, led_val);
+err_out:
+	mutex_unlock(&led_lock);
+}
+
+static int menf21bmc_led_probe(struct platform_device *pdev)
+{
+	int i;
+	int ret;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+	for (i = 0; i < ARRAY_SIZE(leds); i++) {
+		leds[i].cdev.name = leds[i].name;
+		leds[i].cdev.brightness_set = menf21bmc_led_set;
+		leds[i].i2c_client = i2c_client;
+		ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
+		if (ret < 0)
+			goto err_free_leds;
+	}
+	dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
+
+	return 0;
+
+err_free_leds:
+	dev_err(&pdev->dev, "failed to register LED device\n");
+
+	for (i = i - 1; i >= 0; i--)
+		led_classdev_unregister(&leds[i].cdev);
+
+	return ret;
+}
+
+static int menf21bmc_led_remove(struct platform_device *pdev)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(leds); i++)
+		led_classdev_unregister(&leds[i].cdev);
+
+	return 0;
+}
+
+static struct platform_driver menf21bmc_led = {
+	.probe		= menf21bmc_led_probe,
+	.remove		= menf21bmc_led_remove,
+	.driver		= {
+		.name		= "menf21bmc_led",
+		.owner		= THIS_MODULE,
+	},
+};
+
+module_platform_driver(menf21bmc_led);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_led");
-- 
2.0.4

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

* [lm-sensors] [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
@ 2014-08-13  8:40   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC LEDs.
The BMC is a Board Management Controller including four LEDs which
can be switched on and off.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/leds/Kconfig          |   6 ++
 drivers/leds/Makefile         |   1 +
 drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 drivers/leds/leds-menf21bmc.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 27cf0cd..d38ff3f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -458,6 +458,12 @@ config LEDS_OT200
 	  This option enables support for the LEDs on the Bachmann OT200.
 	  Say Y to enable LEDs on the Bachmann OT200.
 
+config LEDS_MENF21BMC
+	tristate "LED support for the MEN 14F021P00 BMC"
+	depends on LEDS_CLASS && MFD_MENF21BMC
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC LEDs.
+
 comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
 
 config LEDS_BLINKM
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3c03666..cadc433 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)		+= leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)		+= leds-blinkm.o
 obj-$(CONFIG_LEDS_VERSATILE)		+= leds-versatile.o
+obj-$(CONFIG_LEDS_MENF21BMC)		+= leds-menf21bmc.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
new file mode 100644
index 0000000..4621f72
--- /dev/null
+++ b/drivers/leds/leds-menf21bmc.c
@@ -0,0 +1,131 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
+ *
+ *  This is the core LED driver of the MEN 14F021P00 BMC.
+ *  There are four LEDs available which can be switched on and off.
+ *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/i2c.h>
+
+#define BMC_CMD_LED_GET_SET	0xA0
+#define BMC_BIT_LED_STATUS	BIT(0)
+#define BMC_BIT_LED_HOTSWAP	BIT(1)
+#define BMC_BIT_LED_USER1	BIT(2)
+#define BMC_BIT_LED_USER2	BIT(3)
+
+struct menf21bmc_led {
+	struct led_classdev cdev;
+	u8 led_bit;
+	const char *name;
+	struct i2c_client *i2c_client;
+};
+
+static struct menf21bmc_led leds[] = {
+	{
+		.name = "menf21bmc:led_status",
+		.led_bit = BMC_BIT_LED_STATUS,
+	},
+	{
+		.name = "menf21bmc:led_hotswap",
+		.led_bit = BMC_BIT_LED_HOTSWAP,
+	},
+	{
+		.name = "menf21bmc:led_user1",
+		.led_bit = BMC_BIT_LED_USER1,
+	},
+	{
+		.name = "menf21bmc:led_user2",
+		.led_bit = BMC_BIT_LED_USER2,
+	}
+};
+
+static DEFINE_MUTEX(led_lock);
+
+static void
+menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
+{
+	int led_val;
+	struct menf21bmc_led *led = container_of(led_cdev,
+					struct menf21bmc_led, cdev);
+
+	mutex_lock(&led_lock);
+	led_val = i2c_smbus_read_byte_data(led->i2c_client,
+						BMC_CMD_LED_GET_SET);
+	if (led_val < 0)
+		goto err_out;
+
+	if (value = LED_OFF)
+		led_val &= ~led->led_bit;
+	else
+		led_val |= led->led_bit;
+
+	i2c_smbus_write_byte_data(led->i2c_client,
+					BMC_CMD_LED_GET_SET, led_val);
+err_out:
+	mutex_unlock(&led_lock);
+}
+
+static int menf21bmc_led_probe(struct platform_device *pdev)
+{
+	int i;
+	int ret;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+
+	for (i = 0; i < ARRAY_SIZE(leds); i++) {
+		leds[i].cdev.name = leds[i].name;
+		leds[i].cdev.brightness_set = menf21bmc_led_set;
+		leds[i].i2c_client = i2c_client;
+		ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
+		if (ret < 0)
+			goto err_free_leds;
+	}
+	dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
+
+	return 0;
+
+err_free_leds:
+	dev_err(&pdev->dev, "failed to register LED device\n");
+
+	for (i = i - 1; i >= 0; i--)
+		led_classdev_unregister(&leds[i].cdev);
+
+	return ret;
+}
+
+static int menf21bmc_led_remove(struct platform_device *pdev)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(leds); i++)
+		led_classdev_unregister(&leds[i].cdev);
+
+	return 0;
+}
+
+static struct platform_driver menf21bmc_led = {
+	.probe		= menf21bmc_led_probe,
+	.remove		= menf21bmc_led_remove,
+	.driver		= {
+		.name		= "menf21bmc_led",
+		.owner		= THIS_MODULE,
+	},
+};
+
+module_platform_driver(menf21bmc_led);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_led");
-- 
2.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-13  8:38 ` Andreas Werner
  (?)
@ 2014-08-13  8:40   ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC Hardware Monitoring.
The BMC is a Board Management Controller including monitoring of the
board voltages.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/hwmon/Kconfig           |   7 ++
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 246 insertions(+)
 create mode 100644 drivers/hwmon/menf21bmc_hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 37908ff..437c00f 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -828,6 +828,13 @@ config SENSORS_MCP3021
 	  This driver can also be built as a module.  If so, the module
 	  will be called mcp3021.
 
+config SENSORS_MENF21BMC_HWMON
+	tristate "MEN 14F021P00 BMC Hardware Monitoring"
+	depends on MFD_MENF21BMC && I2C
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC
+	  hardware monitoring.
+
 config SENSORS_ADCXX
 	tristate "National Semiconductor ADCxxxSxxx"
 	depends on SPI_MASTER
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1362382..56ab872 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
+obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
 obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
 obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
 obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
new file mode 100644
index 0000000..ecb0ef1
--- /dev/null
+++ b/drivers/hwmon/menf21bmc_hwmon.c
@@ -0,0 +1,238 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
+ *
+ *  This is the core hwmon driver of the MEN 14F021P00 BMC.
+ *  The BMC monitors the board voltages which can be access with this
+ *  driver through sysfs.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/jiffies.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_hwmon"
+
+#define BMC_VOLT_COUNT	5
+#define MENF21BMC_V33	0
+#define MENF21BMC_V5	1
+#define MENF21BMC_V12	2
+#define MENF21BMC_V5_SB	3
+#define MENF21BMC_VBAT	4
+
+#define BMC_CMD_GET_NUM_VOLT 0x8E
+#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
+#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
+#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
+
+struct menf21bmc_hwmon {
+	char valid;
+	struct i2c_client *i2c_client;
+	unsigned long last_update;
+	u16 in_val[BMC_VOLT_COUNT];
+	u16 in_min[BMC_VOLT_COUNT];
+	u16 in_max[BMC_VOLT_COUNT];
+};
+
+static const char *const input_names[] = {
+	[MENF21BMC_V33]		= "MON_3,3V",
+	[MENF21BMC_V5]		= "MON_5V",
+	[MENF21BMC_V12]		= "MON_12V",
+	[MENF21BMC_V5_SB]	= "5V_STANDBY",
+	[MENF21BMC_VBAT]	= "VBAT"
+};
+
+static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
+{
+	int i;
+	uint16_t val;
+	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
+	struct menf21bmc_hwmon *data_ret = drv_data;
+
+	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
+		for (i = 0; i < BMC_VOLT_COUNT; i++) {
+			val = i2c_smbus_read_word_data(drv_data->i2c_client,
+						       IDX_TO_VOLT_INP_CMD(i));
+			if (val < 0)
+				goto abort;
+
+			drv_data->in_val[i] = val;
+		}
+		drv_data->last_update = jiffies;
+		drv_data->valid = 1;
+	}
+abort:
+	return data_ret;
+}
+
+static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
+{
+	int i;
+	uint16_t val;
+
+	for (i = 0; i < BMC_VOLT_COUNT; i++) {
+		val = i2c_smbus_read_word_data(drv_data->i2c_client,
+					       IDX_TO_VOLT_MIN_CMD(i));
+		if (val < 0)
+			return val;
+
+		drv_data->in_min[i] = val;
+
+		val = i2c_smbus_read_word_data(drv_data->i2c_client,
+					       IDX_TO_VOLT_MAX_CMD(i));
+		if (val < 0)
+			return val;
+
+		drv_data->in_max[i] = val;
+	}
+	return 0;
+}
+
+static ssize_t
+show_label(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%s\n", input_names[attr->index]);
+}
+
+static ssize_t
+show_in(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	uint16_t val;
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	val = drv_data->in_val[attr->index];
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t
+show_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
+}
+
+static ssize_t
+show_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
+}
+
+#define create_voltage_sysfs(idx)			\
+static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
+			show_in, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
+			show_min, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
+			show_max, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
+			show_label, NULL, idx);
+
+create_voltage_sysfs(0);
+create_voltage_sysfs(1);
+create_voltage_sysfs(2);
+create_voltage_sysfs(3);
+create_voltage_sysfs(4);
+
+static struct attribute *menf21bmc_hwmon_attr_volts[] = {
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_min.dev_attr.attr,
+	&sensor_dev_attr_in0_max.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_min.dev_attr.attr,
+	&sensor_dev_attr_in1_max.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_min.dev_attr.attr,
+	&sensor_dev_attr_in2_max.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_min.dev_attr.attr,
+	&sensor_dev_attr_in3_max.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_min.dev_attr.attr,
+	&sensor_dev_attr_in4_max.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
+	.attrs = menf21bmc_hwmon_attr_volts,
+};
+
+static const struct attribute_group *menf21bmc_hwmon_groups[] = {
+	&menf21bmc_hwmon_attr_group_volts,
+	NULL
+};
+
+static int menf21bmc_hwmon_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct menf21bmc_hwmon *drv_data;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+	struct device *hwmon_dev;
+
+	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
+				GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+
+	drv_data->i2c_client = i2c_client;
+	platform_set_drvdata(pdev, drv_data);
+
+	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to read sensor limits");
+		return ret;
+	}
+
+	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
+							   DEVNAME, drv_data,
+							   menf21bmc_hwmon_groups);
+
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
+
+	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
+
+	return 0;
+}
+
+static struct platform_driver menf21bmc_hwmon = {
+	.probe		= menf21bmc_hwmon_probe,
+	.driver		= {
+		.name		= DEVNAME,
+		.owner		= THIS_MODULE,
+	},
+};
+
+module_platform_driver(menf21bmc_hwmon);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_hwmon");
-- 
2.0.4

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

* [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
@ 2014-08-13  8:40   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC Hardware Monitoring.
The BMC is a Board Management Controller including monitoring of the
board voltages.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/hwmon/Kconfig           |   7 ++
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 246 insertions(+)
 create mode 100644 drivers/hwmon/menf21bmc_hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 37908ff..437c00f 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -828,6 +828,13 @@ config SENSORS_MCP3021
 	  This driver can also be built as a module.  If so, the module
 	  will be called mcp3021.
 
+config SENSORS_MENF21BMC_HWMON
+	tristate "MEN 14F021P00 BMC Hardware Monitoring"
+	depends on MFD_MENF21BMC && I2C
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC
+	  hardware monitoring.
+
 config SENSORS_ADCXX
 	tristate "National Semiconductor ADCxxxSxxx"
 	depends on SPI_MASTER
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1362382..56ab872 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
+obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
 obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
 obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
 obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
new file mode 100644
index 0000000..ecb0ef1
--- /dev/null
+++ b/drivers/hwmon/menf21bmc_hwmon.c
@@ -0,0 +1,238 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
+ *
+ *  This is the core hwmon driver of the MEN 14F021P00 BMC.
+ *  The BMC monitors the board voltages which can be access with this
+ *  driver through sysfs.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/jiffies.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_hwmon"
+
+#define BMC_VOLT_COUNT	5
+#define MENF21BMC_V33	0
+#define MENF21BMC_V5	1
+#define MENF21BMC_V12	2
+#define MENF21BMC_V5_SB	3
+#define MENF21BMC_VBAT	4
+
+#define BMC_CMD_GET_NUM_VOLT 0x8E
+#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
+#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
+#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
+
+struct menf21bmc_hwmon {
+	char valid;
+	struct i2c_client *i2c_client;
+	unsigned long last_update;
+	u16 in_val[BMC_VOLT_COUNT];
+	u16 in_min[BMC_VOLT_COUNT];
+	u16 in_max[BMC_VOLT_COUNT];
+};
+
+static const char *const input_names[] = {
+	[MENF21BMC_V33]		= "MON_3,3V",
+	[MENF21BMC_V5]		= "MON_5V",
+	[MENF21BMC_V12]		= "MON_12V",
+	[MENF21BMC_V5_SB]	= "5V_STANDBY",
+	[MENF21BMC_VBAT]	= "VBAT"
+};
+
+static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
+{
+	int i;
+	uint16_t val;
+	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
+	struct menf21bmc_hwmon *data_ret = drv_data;
+
+	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
+		for (i = 0; i < BMC_VOLT_COUNT; i++) {
+			val = i2c_smbus_read_word_data(drv_data->i2c_client,
+						       IDX_TO_VOLT_INP_CMD(i));
+			if (val < 0)
+				goto abort;
+
+			drv_data->in_val[i] = val;
+		}
+		drv_data->last_update = jiffies;
+		drv_data->valid = 1;
+	}
+abort:
+	return data_ret;
+}
+
+static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
+{
+	int i;
+	uint16_t val;
+
+	for (i = 0; i < BMC_VOLT_COUNT; i++) {
+		val = i2c_smbus_read_word_data(drv_data->i2c_client,
+					       IDX_TO_VOLT_MIN_CMD(i));
+		if (val < 0)
+			return val;
+
+		drv_data->in_min[i] = val;
+
+		val = i2c_smbus_read_word_data(drv_data->i2c_client,
+					       IDX_TO_VOLT_MAX_CMD(i));
+		if (val < 0)
+			return val;
+
+		drv_data->in_max[i] = val;
+	}
+	return 0;
+}
+
+static ssize_t
+show_label(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%s\n", input_names[attr->index]);
+}
+
+static ssize_t
+show_in(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	uint16_t val;
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	val = drv_data->in_val[attr->index];
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t
+show_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
+}
+
+static ssize_t
+show_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
+}
+
+#define create_voltage_sysfs(idx)			\
+static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
+			show_in, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
+			show_min, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
+			show_max, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
+			show_label, NULL, idx);
+
+create_voltage_sysfs(0);
+create_voltage_sysfs(1);
+create_voltage_sysfs(2);
+create_voltage_sysfs(3);
+create_voltage_sysfs(4);
+
+static struct attribute *menf21bmc_hwmon_attr_volts[] = {
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_min.dev_attr.attr,
+	&sensor_dev_attr_in0_max.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_min.dev_attr.attr,
+	&sensor_dev_attr_in1_max.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_min.dev_attr.attr,
+	&sensor_dev_attr_in2_max.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_min.dev_attr.attr,
+	&sensor_dev_attr_in3_max.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_min.dev_attr.attr,
+	&sensor_dev_attr_in4_max.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
+	.attrs = menf21bmc_hwmon_attr_volts,
+};
+
+static const struct attribute_group *menf21bmc_hwmon_groups[] = {
+	&menf21bmc_hwmon_attr_group_volts,
+	NULL
+};
+
+static int menf21bmc_hwmon_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct menf21bmc_hwmon *drv_data;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+	struct device *hwmon_dev;
+
+	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
+				GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+
+	drv_data->i2c_client = i2c_client;
+	platform_set_drvdata(pdev, drv_data);
+
+	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to read sensor limits");
+		return ret;
+	}
+
+	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
+							   DEVNAME, drv_data,
+							   menf21bmc_hwmon_groups);
+
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
+
+	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
+
+	return 0;
+}
+
+static struct platform_driver menf21bmc_hwmon = {
+	.probe		= menf21bmc_hwmon_probe,
+	.driver		= {
+		.name		= DEVNAME,
+		.owner		= THIS_MODULE,
+	},
+};
+
+module_platform_driver(menf21bmc_hwmon);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_hwmon");
-- 
2.0.4


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

* [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
@ 2014-08-13  8:40   ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-13  8:40 UTC (permalink / raw)
  To: linux-kernel
  Cc: andreas.werner, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, linux, lm-sensors

Added driver to support the 14F021P00 BMC Hardware Monitoring.
The BMC is a Board Management Controller including monitoring of the
board voltages.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/hwmon/Kconfig           |   7 ++
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 246 insertions(+)
 create mode 100644 drivers/hwmon/menf21bmc_hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 37908ff..437c00f 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -828,6 +828,13 @@ config SENSORS_MCP3021
 	  This driver can also be built as a module.  If so, the module
 	  will be called mcp3021.
 
+config SENSORS_MENF21BMC_HWMON
+	tristate "MEN 14F021P00 BMC Hardware Monitoring"
+	depends on MFD_MENF21BMC && I2C
+	help
+	  Say Y here to include support for the MEN 14F021P00 BMC
+	  hardware monitoring.
+
 config SENSORS_ADCXX
 	tristate "National Semiconductor ADCxxxSxxx"
 	depends on SPI_MASTER
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1362382..56ab872 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
 obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
+obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
 obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
 obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
 obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
new file mode 100644
index 0000000..ecb0ef1
--- /dev/null
+++ b/drivers/hwmon/menf21bmc_hwmon.c
@@ -0,0 +1,238 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
+ *
+ *  This is the core hwmon driver of the MEN 14F021P00 BMC.
+ *  The BMC monitors the board voltages which can be access with this
+ *  driver through sysfs.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ *  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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/jiffies.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+
+#define DEVNAME "menf21bmc_hwmon"
+
+#define BMC_VOLT_COUNT	5
+#define MENF21BMC_V33	0
+#define MENF21BMC_V5	1
+#define MENF21BMC_V12	2
+#define MENF21BMC_V5_SB	3
+#define MENF21BMC_VBAT	4
+
+#define BMC_CMD_GET_NUM_VOLT 0x8E
+#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
+#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
+#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
+
+struct menf21bmc_hwmon {
+	char valid;
+	struct i2c_client *i2c_client;
+	unsigned long last_update;
+	u16 in_val[BMC_VOLT_COUNT];
+	u16 in_min[BMC_VOLT_COUNT];
+	u16 in_max[BMC_VOLT_COUNT];
+};
+
+static const char *const input_names[] = {
+	[MENF21BMC_V33]		= "MON_3,3V",
+	[MENF21BMC_V5]		= "MON_5V",
+	[MENF21BMC_V12]		= "MON_12V",
+	[MENF21BMC_V5_SB]	= "5V_STANDBY",
+	[MENF21BMC_VBAT]	= "VBAT"
+};
+
+static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
+{
+	int i;
+	uint16_t val;
+	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
+	struct menf21bmc_hwmon *data_ret = drv_data;
+
+	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
+		for (i = 0; i < BMC_VOLT_COUNT; i++) {
+			val = i2c_smbus_read_word_data(drv_data->i2c_client,
+						       IDX_TO_VOLT_INP_CMD(i));
+			if (val < 0)
+				goto abort;
+
+			drv_data->in_val[i] = val;
+		}
+		drv_data->last_update = jiffies;
+		drv_data->valid = 1;
+	}
+abort:
+	return data_ret;
+}
+
+static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
+{
+	int i;
+	uint16_t val;
+
+	for (i = 0; i < BMC_VOLT_COUNT; i++) {
+		val = i2c_smbus_read_word_data(drv_data->i2c_client,
+					       IDX_TO_VOLT_MIN_CMD(i));
+		if (val < 0)
+			return val;
+
+		drv_data->in_min[i] = val;
+
+		val = i2c_smbus_read_word_data(drv_data->i2c_client,
+					       IDX_TO_VOLT_MAX_CMD(i));
+		if (val < 0)
+			return val;
+
+		drv_data->in_max[i] = val;
+	}
+	return 0;
+}
+
+static ssize_t
+show_label(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%s\n", input_names[attr->index]);
+}
+
+static ssize_t
+show_in(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	uint16_t val;
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	val = drv_data->in_val[attr->index];
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t
+show_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
+}
+
+static ssize_t
+show_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
+
+	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
+}
+
+#define create_voltage_sysfs(idx)			\
+static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
+			show_in, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
+			show_min, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
+			show_max, NULL, idx);		\
+static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
+			show_label, NULL, idx);
+
+create_voltage_sysfs(0);
+create_voltage_sysfs(1);
+create_voltage_sysfs(2);
+create_voltage_sysfs(3);
+create_voltage_sysfs(4);
+
+static struct attribute *menf21bmc_hwmon_attr_volts[] = {
+	&sensor_dev_attr_in0_input.dev_attr.attr,
+	&sensor_dev_attr_in0_min.dev_attr.attr,
+	&sensor_dev_attr_in0_max.dev_attr.attr,
+	&sensor_dev_attr_in0_label.dev_attr.attr,
+
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in1_min.dev_attr.attr,
+	&sensor_dev_attr_in1_max.dev_attr.attr,
+	&sensor_dev_attr_in1_label.dev_attr.attr,
+
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in2_min.dev_attr.attr,
+	&sensor_dev_attr_in2_max.dev_attr.attr,
+	&sensor_dev_attr_in2_label.dev_attr.attr,
+
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in3_min.dev_attr.attr,
+	&sensor_dev_attr_in3_max.dev_attr.attr,
+	&sensor_dev_attr_in3_label.dev_attr.attr,
+
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	&sensor_dev_attr_in4_min.dev_attr.attr,
+	&sensor_dev_attr_in4_max.dev_attr.attr,
+	&sensor_dev_attr_in4_label.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
+	.attrs = menf21bmc_hwmon_attr_volts,
+};
+
+static const struct attribute_group *menf21bmc_hwmon_groups[] = {
+	&menf21bmc_hwmon_attr_group_volts,
+	NULL
+};
+
+static int menf21bmc_hwmon_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct menf21bmc_hwmon *drv_data;
+	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
+	struct device *hwmon_dev;
+
+	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
+				GFP_KERNEL);
+	if (!drv_data)
+		return -ENOMEM;
+
+	drv_data->i2c_client = i2c_client;
+	platform_set_drvdata(pdev, drv_data);
+
+	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to read sensor limits");
+		return ret;
+	}
+
+	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
+							   DEVNAME, drv_data,
+							   menf21bmc_hwmon_groups);
+
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
+
+	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
+
+	return 0;
+}
+
+static struct platform_driver menf21bmc_hwmon = {
+	.probe		= menf21bmc_hwmon_probe,
+	.driver		= {
+		.name		= DEVNAME,
+		.owner		= THIS_MODULE,
+	},
+};
+
+module_platform_driver(menf21bmc_hwmon);
+
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:menf21bmc_hwmon");
-- 
2.0.4


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-08-13  8:39   ` Andreas Werner
  (?)
@ 2014-08-21 11:30     ` Lee Jones
  -1 siblings, 0 replies; 45+ messages in thread
From: Lee Jones @ 2014-08-21 11:30 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, jdelvare, linux, lm-sensors

On Wed, 13 Aug 2014, Andreas Werner wrote:
> The MEN 14F021P00 Board Management Controller provides an
> I2C interface to the host to access the feature implemented in the BMC.
> The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> and on a few Box/Display Computer.
> 
> Added MFD Core driver, supporting the I2C communication to the device.
> 
> The MFD driver currently supports the following features:
>  	- Watchdog
>  	- LEDs
> 	- Hwmon (voltage monitoring)
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/mfd/Kconfig     |  12 +++++
>  drivers/mfd/Makefile    |   1 +
>  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 145 insertions(+)
>  create mode 100644 drivers/mfd/menf21bmc.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index b8d9ca0..bf155b9 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -453,6 +453,18 @@ config MFD_MAX8998
>  	  additional drivers must be enabled in order to use the functionality
>  	  of the device.
>  
> +config MFD_MENF21BMC
> +	tristate "MEN 14F021P00 Board Management Controller Support"
> +	depends on I2C=y

Why must I2C be built-in?

> +	select MFD_CORE
> +	help
> +	  Say yes here to add support for the MEN 14F021P00 BMC
> +	  which is a Board Management Controller connected to the I2C bus.
> +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> +	  This driver provides common support for accessing the devices;
> +	  additional drivers must be enabled in order to use the
> +	  functionality of the BMC device.
> +

Apart from that the patch looks good to me.

I'm assuming this can go in via the MFD tree by itself?

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 11:30     ` Lee Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Lee Jones @ 2014-08-21 11:30 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, jdelvare, linux, lm-sensors

On Wed, 13 Aug 2014, Andreas Werner wrote:
> The MEN 14F021P00 Board Management Controller provides an
> I2C interface to the host to access the feature implemented in the BMC.
> The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> and on a few Box/Display Computer.
> 
> Added MFD Core driver, supporting the I2C communication to the device.
> 
> The MFD driver currently supports the following features:
>  	- Watchdog
>  	- LEDs
> 	- Hwmon (voltage monitoring)
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/mfd/Kconfig     |  12 +++++
>  drivers/mfd/Makefile    |   1 +
>  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 145 insertions(+)
>  create mode 100644 drivers/mfd/menf21bmc.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index b8d9ca0..bf155b9 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -453,6 +453,18 @@ config MFD_MAX8998
>  	  additional drivers must be enabled in order to use the functionality
>  	  of the device.
>  
> +config MFD_MENF21BMC
> +	tristate "MEN 14F021P00 Board Management Controller Support"
> +	depends on I2C=y

Why must I2C be built-in?

> +	select MFD_CORE
> +	help
> +	  Say yes here to add support for the MEN 14F021P00 BMC
> +	  which is a Board Management Controller connected to the I2C bus.
> +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> +	  This driver provides common support for accessing the devices;
> +	  additional drivers must be enabled in order to use the
> +	  functionality of the BMC device.
> +

Apart from that the patch looks good to me.

I'm assuming this can go in via the MFD tree by itself?

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [lm-sensors] [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 11:30     ` Lee Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Lee Jones @ 2014-08-21 11:30 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, jdelvare, linux, lm-sensors

T24gV2VkLCAxMyBBdWcgMjAxNCwgQW5kcmVhcyBXZXJuZXIgd3JvdGU6Cj4gVGhlIE1FTiAxNEYw
MjFQMDAgQm9hcmQgTWFuYWdlbWVudCBDb250cm9sbGVyIHByb3ZpZGVzIGFuCj4gSTJDIGludGVy
ZmFjZSB0byB0aGUgaG9zdCB0byBhY2Nlc3MgdGhlIGZlYXR1cmUgaW1wbGVtZW50ZWQgaW4gdGhl
IEJNQy4KPiBUaGUgQk1DIGlzIGEgUElDIE1pY3JvbnRyb2xsZXIgYXNzZW1ibGVkIG9uIENQQ0kg
Q2FyZCBmcm9tIE1FTiBNaWtyb2VsZWt0cm9uaWsKPiBhbmQgb24gYSBmZXcgQm94L0Rpc3BsYXkg
Q29tcHV0ZXIuCj4gCj4gQWRkZWQgTUZEIENvcmUgZHJpdmVyLCBzdXBwb3J0aW5nIHRoZSBJMkMg
Y29tbXVuaWNhdGlvbiB0byB0aGUgZGV2aWNlLgo+IAo+IFRoZSBNRkQgZHJpdmVyIGN1cnJlbnRs
eSBzdXBwb3J0cyB0aGUgZm9sbG93aW5nIGZlYXR1cmVzOgo+ICAJLSBXYXRjaGRvZwo+ICAJLSBM
RURzCj4gCS0gSHdtb24gKHZvbHRhZ2UgbW9uaXRvcmluZykKPiAKPiBTaWduZWQtb2ZmLWJ5OiBB
bmRyZWFzIFdlcm5lciA8YW5kcmVhcy53ZXJuZXJAbWVuLmRlPgo+IC0tLQo+ICBkcml2ZXJzL21m
ZC9LY29uZmlnICAgICB8ICAxMiArKysrKwo+ICBkcml2ZXJzL21mZC9NYWtlZmlsZSAgICB8ICAg
MSArCj4gIGRyaXZlcnMvbWZkL21lbmYyMWJtYy5jIHwgMTMyICsrKysrKysrKysrKysrKysrKysr
KysrKysrKysrKysrKysrKysrKysrKysrKysrKwo+ICAzIGZpbGVzIGNoYW5nZWQsIDE0NSBpbnNl
cnRpb25zKCspCj4gIGNyZWF0ZSBtb2RlIDEwMDY0NCBkcml2ZXJzL21mZC9tZW5mMjFibWMuYwo+
IAo+IGRpZmYgLS1naXQgYS9kcml2ZXJzL21mZC9LY29uZmlnIGIvZHJpdmVycy9tZmQvS2NvbmZp
Zwo+IGluZGV4IGI4ZDljYTAuLmJmMTU1YjkgMTAwNjQ0Cj4gLS0tIGEvZHJpdmVycy9tZmQvS2Nv
bmZpZwo+ICsrKyBiL2RyaXZlcnMvbWZkL0tjb25maWcKPiBAQCAtNDUzLDYgKzQ1MywxOCBAQCBj
b25maWcgTUZEX01BWDg5OTgKPiAgCSAgYWRkaXRpb25hbCBkcml2ZXJzIG11c3QgYmUgZW5hYmxl
ZCBpbiBvcmRlciB0byB1c2UgdGhlIGZ1bmN0aW9uYWxpdHkKPiAgCSAgb2YgdGhlIGRldmljZS4K
PiAgCj4gK2NvbmZpZyBNRkRfTUVORjIxQk1DCj4gKwl0cmlzdGF0ZSAiTUVOIDE0RjAyMVAwMCBC
b2FyZCBNYW5hZ2VtZW50IENvbnRyb2xsZXIgU3VwcG9ydCIKPiArCWRlcGVuZHMgb24gSTJDPXkK
CldoeSBtdXN0IEkyQyBiZSBidWlsdC1pbj8KCj4gKwlzZWxlY3QgTUZEX0NPUkUKPiArCWhlbHAK
PiArCSAgU2F5IHllcyBoZXJlIHRvIGFkZCBzdXBwb3J0IGZvciB0aGUgTUVOIDE0RjAyMVAwMCBC
TUMKPiArCSAgd2hpY2ggaXMgYSBCb2FyZCBNYW5hZ2VtZW50IENvbnRyb2xsZXIgY29ubmVjdGVk
IHRvIHRoZSBJMkMgYnVzLgo+ICsJICBUaGUgZGV2aWNlIHN1cHBvcnRzIG11bHRpcGxlIHN1Yi1k
ZXZpY2VzIGxpa2UgTEVELCBIV01PTiAgYW5kIFdEVC4KPiArCSAgVGhpcyBkcml2ZXIgcHJvdmlk
ZXMgY29tbW9uIHN1cHBvcnQgZm9yIGFjY2Vzc2luZyB0aGUgZGV2aWNlczsKPiArCSAgYWRkaXRp
b25hbCBkcml2ZXJzIG11c3QgYmUgZW5hYmxlZCBpbiBvcmRlciB0byB1c2UgdGhlCj4gKwkgIGZ1
bmN0aW9uYWxpdHkgb2YgdGhlIEJNQyBkZXZpY2UuCj4gKwoKQXBhcnQgZnJvbSB0aGF0IHRoZSBw
YXRjaCBsb29rcyBnb29kIHRvIG1lLgoKSSdtIGFzc3VtaW5nIHRoaXMgY2FuIGdvIGluIHZpYSB0
aGUgTUZEIHRyZWUgYnkgaXRzZWxmPwoKQWNrZWQtYnk6IExlZSBKb25lcyA8bGVlLmpvbmVzQGxp
bmFyby5vcmc+CgotLSAKTGVlIEpvbmVzCkxpbmFybyBTVE1pY3JvZWxlY3Ryb25pY3MgTGFuZGlu
ZyBUZWFtIExlYWQKTGluYXJvLm9yZyDilIIgT3BlbiBzb3VyY2Ugc29mdHdhcmUgZm9yIEFSTSBT
b0NzCkZvbGxvdyBMaW5hcm86IEZhY2Vib29rIHwgVHdpdHRlciB8IEJsb2cKCl9fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCmxtLXNlbnNvcnMgbWFpbGluZyBs
aXN0CmxtLXNlbnNvcnNAbG0tc2Vuc29ycy5vcmcKaHR0cDovL2xpc3RzLmxtLXNlbnNvcnMub3Jn
L21haWxtYW4vbGlzdGluZm8vbG0tc2Vuc29ycw=

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-08-21 13:57       ` Andreas Werner
  (?)
@ 2014-08-21 13:25         ` Lee Jones
  -1 siblings, 0 replies; 45+ messages in thread
From: Lee Jones @ 2014-08-21 13:25 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, jdelvare, linux, lm-sensors

On Thu, 21 Aug 2014, Andreas Werner wrote:
> On Thu, Aug 21, 2014 at 12:30:46PM +0100, Lee Jones wrote:
> > On Wed, 13 Aug 2014, Andreas Werner wrote:
> > > The MEN 14F021P00 Board Management Controller provides an
> > > I2C interface to the host to access the feature implemented in the BMC.
> > > The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> > > and on a few Box/Display Computer.
> > > 
> > > Added MFD Core driver, supporting the I2C communication to the device.
> > > 
> > > The MFD driver currently supports the following features:
> > >  	- Watchdog
> > >  	- LEDs
> > > 	- Hwmon (voltage monitoring)
> > > 
> > > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > > ---
> > >  drivers/mfd/Kconfig     |  12 +++++
> > >  drivers/mfd/Makefile    |   1 +
> > >  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 145 insertions(+)
> > >  create mode 100644 drivers/mfd/menf21bmc.c
> > > 
> > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > > index b8d9ca0..bf155b9 100644
> > > --- a/drivers/mfd/Kconfig
> > > +++ b/drivers/mfd/Kconfig
> > > @@ -453,6 +453,18 @@ config MFD_MAX8998
> > >  	  additional drivers must be enabled in order to use the functionality
> > >  	  of the device.
> > >  
> > > +config MFD_MENF21BMC
> > > +	tristate "MEN 14F021P00 Board Management Controller Support"
> > > +	depends on I2C=y
> > 
> > Why must I2C be built-in?
> 
> Sorry my mistake, I2C must not be built in.
> 
> > 
> > > +	select MFD_CORE
> > > +	help
> > > +	  Say yes here to add support for the MEN 14F021P00 BMC
> > > +	  which is a Board Management Controller connected to the I2C bus.
> > > +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> > > +	  This driver provides common support for accessing the devices;
> > > +	  additional drivers must be enabled in order to use the
> > > +	  functionality of the BMC device.
> > > +
> > 
> > Apart from that the patch looks good to me.
> > 
> > I'm assuming this can go in via the MFD tree by itself?
> 
> Yes why not.
> Do you want to have a single patch for the MFD or
> is it better to wait for the other Subsystem maintainer that I 
> can resend a patch v5?

When you resent, apply my Ack and I'll pick it up when the other
Maintainers are happy.

> > 
> > Acked-by: Lee Jones <lee.jones@linaro.org>
> > 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 13:25         ` Lee Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Lee Jones @ 2014-08-21 13:25 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, jdelvare, linux, lm-sensors

On Thu, 21 Aug 2014, Andreas Werner wrote:
> On Thu, Aug 21, 2014 at 12:30:46PM +0100, Lee Jones wrote:
> > On Wed, 13 Aug 2014, Andreas Werner wrote:
> > > The MEN 14F021P00 Board Management Controller provides an
> > > I2C interface to the host to access the feature implemented in the BMC.
> > > The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> > > and on a few Box/Display Computer.
> > > 
> > > Added MFD Core driver, supporting the I2C communication to the device.
> > > 
> > > The MFD driver currently supports the following features:
> > >  	- Watchdog
> > >  	- LEDs
> > > 	- Hwmon (voltage monitoring)
> > > 
> > > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > > ---
> > >  drivers/mfd/Kconfig     |  12 +++++
> > >  drivers/mfd/Makefile    |   1 +
> > >  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 145 insertions(+)
> > >  create mode 100644 drivers/mfd/menf21bmc.c
> > > 
> > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > > index b8d9ca0..bf155b9 100644
> > > --- a/drivers/mfd/Kconfig
> > > +++ b/drivers/mfd/Kconfig
> > > @@ -453,6 +453,18 @@ config MFD_MAX8998
> > >  	  additional drivers must be enabled in order to use the functionality
> > >  	  of the device.
> > >  
> > > +config MFD_MENF21BMC
> > > +	tristate "MEN 14F021P00 Board Management Controller Support"
> > > +	depends on I2C=y
> > 
> > Why must I2C be built-in?
> 
> Sorry my mistake, I2C must not be built in.
> 
> > 
> > > +	select MFD_CORE
> > > +	help
> > > +	  Say yes here to add support for the MEN 14F021P00 BMC
> > > +	  which is a Board Management Controller connected to the I2C bus.
> > > +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> > > +	  This driver provides common support for accessing the devices;
> > > +	  additional drivers must be enabled in order to use the
> > > +	  functionality of the BMC device.
> > > +
> > 
> > Apart from that the patch looks good to me.
> > 
> > I'm assuming this can go in via the MFD tree by itself?
> 
> Yes why not.
> Do you want to have a single patch for the MFD or
> is it better to wait for the other Subsystem maintainer that I 
> can resend a patch v5?

When you resent, apply my Ack and I'll pick it up when the other
Maintainers are happy.

> > 
> > Acked-by: Lee Jones <lee.jones@linaro.org>
> > 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [lm-sensors] [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 13:25         ` Lee Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Lee Jones @ 2014-08-21 13:25 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, jdelvare, linux, lm-sensors

T24gVGh1LCAyMSBBdWcgMjAxNCwgQW5kcmVhcyBXZXJuZXIgd3JvdGU6Cj4gT24gVGh1LCBBdWcg
MjEsIDIwMTQgYXQgMTI6MzA6NDZQTSArMDEwMCwgTGVlIEpvbmVzIHdyb3RlOgo+ID4gT24gV2Vk
LCAxMyBBdWcgMjAxNCwgQW5kcmVhcyBXZXJuZXIgd3JvdGU6Cj4gPiA+IFRoZSBNRU4gMTRGMDIx
UDAwIEJvYXJkIE1hbmFnZW1lbnQgQ29udHJvbGxlciBwcm92aWRlcyBhbgo+ID4gPiBJMkMgaW50
ZXJmYWNlIHRvIHRoZSBob3N0IHRvIGFjY2VzcyB0aGUgZmVhdHVyZSBpbXBsZW1lbnRlZCBpbiB0
aGUgQk1DLgo+ID4gPiBUaGUgQk1DIGlzIGEgUElDIE1pY3JvbnRyb2xsZXIgYXNzZW1ibGVkIG9u
IENQQ0kgQ2FyZCBmcm9tIE1FTiBNaWtyb2VsZWt0cm9uaWsKPiA+ID4gYW5kIG9uIGEgZmV3IEJv
eC9EaXNwbGF5IENvbXB1dGVyLgo+ID4gPiAKPiA+ID4gQWRkZWQgTUZEIENvcmUgZHJpdmVyLCBz
dXBwb3J0aW5nIHRoZSBJMkMgY29tbXVuaWNhdGlvbiB0byB0aGUgZGV2aWNlLgo+ID4gPiAKPiA+
ID4gVGhlIE1GRCBkcml2ZXIgY3VycmVudGx5IHN1cHBvcnRzIHRoZSBmb2xsb3dpbmcgZmVhdHVy
ZXM6Cj4gPiA+ICAJLSBXYXRjaGRvZwo+ID4gPiAgCS0gTEVEcwo+ID4gPiAJLSBId21vbiAodm9s
dGFnZSBtb25pdG9yaW5nKQo+ID4gPiAKPiA+ID4gU2lnbmVkLW9mZi1ieTogQW5kcmVhcyBXZXJu
ZXIgPGFuZHJlYXMud2VybmVyQG1lbi5kZT4KPiA+ID4gLS0tCj4gPiA+ICBkcml2ZXJzL21mZC9L
Y29uZmlnICAgICB8ICAxMiArKysrKwo+ID4gPiAgZHJpdmVycy9tZmQvTWFrZWZpbGUgICAgfCAg
IDEgKwo+ID4gPiAgZHJpdmVycy9tZmQvbWVuZjIxYm1jLmMgfCAxMzIgKysrKysrKysrKysrKysr
KysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrCj4gPiA+ICAzIGZpbGVzIGNoYW5nZWQs
IDE0NSBpbnNlcnRpb25zKCspCj4gPiA+ICBjcmVhdGUgbW9kZSAxMDA2NDQgZHJpdmVycy9tZmQv
bWVuZjIxYm1jLmMKPiA+ID4gCj4gPiA+IGRpZmYgLS1naXQgYS9kcml2ZXJzL21mZC9LY29uZmln
IGIvZHJpdmVycy9tZmQvS2NvbmZpZwo+ID4gPiBpbmRleCBiOGQ5Y2EwLi5iZjE1NWI5IDEwMDY0
NAo+ID4gPiAtLS0gYS9kcml2ZXJzL21mZC9LY29uZmlnCj4gPiA+ICsrKyBiL2RyaXZlcnMvbWZk
L0tjb25maWcKPiA+ID4gQEAgLTQ1Myw2ICs0NTMsMTggQEAgY29uZmlnIE1GRF9NQVg4OTk4Cj4g
PiA+ICAJICBhZGRpdGlvbmFsIGRyaXZlcnMgbXVzdCBiZSBlbmFibGVkIGluIG9yZGVyIHRvIHVz
ZSB0aGUgZnVuY3Rpb25hbGl0eQo+ID4gPiAgCSAgb2YgdGhlIGRldmljZS4KPiA+ID4gIAo+ID4g
PiArY29uZmlnIE1GRF9NRU5GMjFCTUMKPiA+ID4gKwl0cmlzdGF0ZSAiTUVOIDE0RjAyMVAwMCBC
b2FyZCBNYW5hZ2VtZW50IENvbnRyb2xsZXIgU3VwcG9ydCIKPiA+ID4gKwlkZXBlbmRzIG9uIEky
Qz15Cj4gPiAKPiA+IFdoeSBtdXN0IEkyQyBiZSBidWlsdC1pbj8KPiAKPiBTb3JyeSBteSBtaXN0
YWtlLCBJMkMgbXVzdCBub3QgYmUgYnVpbHQgaW4uCj4gCj4gPiAKPiA+ID4gKwlzZWxlY3QgTUZE
X0NPUkUKPiA+ID4gKwloZWxwCj4gPiA+ICsJICBTYXkgeWVzIGhlcmUgdG8gYWRkIHN1cHBvcnQg
Zm9yIHRoZSBNRU4gMTRGMDIxUDAwIEJNQwo+ID4gPiArCSAgd2hpY2ggaXMgYSBCb2FyZCBNYW5h
Z2VtZW50IENvbnRyb2xsZXIgY29ubmVjdGVkIHRvIHRoZSBJMkMgYnVzLgo+ID4gPiArCSAgVGhl
IGRldmljZSBzdXBwb3J0cyBtdWx0aXBsZSBzdWItZGV2aWNlcyBsaWtlIExFRCwgSFdNT04gIGFu
ZCBXRFQuCj4gPiA+ICsJICBUaGlzIGRyaXZlciBwcm92aWRlcyBjb21tb24gc3VwcG9ydCBmb3Ig
YWNjZXNzaW5nIHRoZSBkZXZpY2VzOwo+ID4gPiArCSAgYWRkaXRpb25hbCBkcml2ZXJzIG11c3Qg
YmUgZW5hYmxlZCBpbiBvcmRlciB0byB1c2UgdGhlCj4gPiA+ICsJICBmdW5jdGlvbmFsaXR5IG9m
IHRoZSBCTUMgZGV2aWNlLgo+ID4gPiArCj4gPiAKPiA+IEFwYXJ0IGZyb20gdGhhdCB0aGUgcGF0
Y2ggbG9va3MgZ29vZCB0byBtZS4KPiA+IAo+ID4gSSdtIGFzc3VtaW5nIHRoaXMgY2FuIGdvIGlu
IHZpYSB0aGUgTUZEIHRyZWUgYnkgaXRzZWxmPwo+IAo+IFllcyB3aHkgbm90Lgo+IERvIHlvdSB3
YW50IHRvIGhhdmUgYSBzaW5nbGUgcGF0Y2ggZm9yIHRoZSBNRkQgb3IKPiBpcyBpdCBiZXR0ZXIg
dG8gd2FpdCBmb3IgdGhlIG90aGVyIFN1YnN5c3RlbSBtYWludGFpbmVyIHRoYXQgSSAKPiBjYW4g
cmVzZW5kIGEgcGF0Y2ggdjU/CgpXaGVuIHlvdSByZXNlbnQsIGFwcGx5IG15IEFjayBhbmQgSSds
bCBwaWNrIGl0IHVwIHdoZW4gdGhlIG90aGVyCk1haW50YWluZXJzIGFyZSBoYXBweS4KCj4gPiAK
PiA+IEFja2VkLWJ5OiBMZWUgSm9uZXMgPGxlZS5qb25lc0BsaW5hcm8ub3JnPgo+ID4gCgotLSAK
TGVlIEpvbmVzCkxpbmFybyBTVE1pY3JvZWxlY3Ryb25pY3MgTGFuZGluZyBUZWFtIExlYWQKTGlu
YXJvLm9yZyDilIIgT3BlbiBzb3VyY2Ugc29mdHdhcmUgZm9yIEFSTSBTb0NzCkZvbGxvdyBMaW5h
cm86IEZhY2Vib29rIHwgVHdpdHRlciB8IEJsb2cKCl9fX19fX19fX19fX19fX19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fCmxtLXNlbnNvcnMgbWFpbGluZyBsaXN0CmxtLXNlbnNvcnNA
bG0tc2Vuc29ycy5vcmcKaHR0cDovL2xpc3RzLmxtLXNlbnNvcnMub3JnL21haWxtYW4vbGlzdGlu
Zm8vbG0tc2Vuc29ycw=

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-08-21 11:30     ` Lee Jones
  (?)
  (?)
@ 2014-08-21 13:57       ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-21 13:57 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andreas Werner, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, jdelvare, linux, lm-sensors

On Thu, Aug 21, 2014 at 12:30:46PM +0100, Lee Jones wrote:
> On Wed, 13 Aug 2014, Andreas Werner wrote:
> > The MEN 14F021P00 Board Management Controller provides an
> > I2C interface to the host to access the feature implemented in the BMC.
> > The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> > and on a few Box/Display Computer.
> > 
> > Added MFD Core driver, supporting the I2C communication to the device.
> > 
> > The MFD driver currently supports the following features:
> >  	- Watchdog
> >  	- LEDs
> > 	- Hwmon (voltage monitoring)
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/mfd/Kconfig     |  12 +++++
> >  drivers/mfd/Makefile    |   1 +
> >  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 145 insertions(+)
> >  create mode 100644 drivers/mfd/menf21bmc.c
> > 
> > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > index b8d9ca0..bf155b9 100644
> > --- a/drivers/mfd/Kconfig
> > +++ b/drivers/mfd/Kconfig
> > @@ -453,6 +453,18 @@ config MFD_MAX8998
> >  	  additional drivers must be enabled in order to use the functionality
> >  	  of the device.
> >  
> > +config MFD_MENF21BMC
> > +	tristate "MEN 14F021P00 Board Management Controller Support"
> > +	depends on I2C=y
> 
> Why must I2C be built-in?

Sorry my mistake, I2C must not be built in.

> 
> > +	select MFD_CORE
> > +	help
> > +	  Say yes here to add support for the MEN 14F021P00 BMC
> > +	  which is a Board Management Controller connected to the I2C bus.
> > +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> > +	  This driver provides common support for accessing the devices;
> > +	  additional drivers must be enabled in order to use the
> > +	  functionality of the BMC device.
> > +
> 
> Apart from that the patch looks good to me.
> 
> I'm assuming this can go in via the MFD tree by itself?

Yes why not.
Do you want to have a single patch for the MFD or
is it better to wait for the other Subsystem maintainer that I 
can resend a patch v5?


Regards
Andy

> 
> Acked-by: Lee Jones <lee.jones@linaro.org>
> 
> -- 
> Lee Jones
> Linaro STMicroelectronics Landing Team Lead
> Linaro.org │ Open source software for ARM SoCs
> Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 13:57       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-21 13:57 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andreas Werner, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, jdelvare, linux, lm-sensors

On Thu, Aug 21, 2014 at 12:30:46PM +0100, Lee Jones wrote:
> On Wed, 13 Aug 2014, Andreas Werner wrote:
> > The MEN 14F021P00 Board Management Controller provides an
> > I2C interface to the host to access the feature implemented in the BMC.
> > The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> > and on a few Box/Display Computer.
> > 
> > Added MFD Core driver, supporting the I2C communication to the device.
> > 
> > The MFD driver currently supports the following features:
> >  	- Watchdog
> >  	- LEDs
> > 	- Hwmon (voltage monitoring)
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/mfd/Kconfig     |  12 +++++
> >  drivers/mfd/Makefile    |   1 +
> >  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 145 insertions(+)
> >  create mode 100644 drivers/mfd/menf21bmc.c
> > 
> > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > index b8d9ca0..bf155b9 100644
> > --- a/drivers/mfd/Kconfig
> > +++ b/drivers/mfd/Kconfig
> > @@ -453,6 +453,18 @@ config MFD_MAX8998
> >  	  additional drivers must be enabled in order to use the functionality
> >  	  of the device.
> >  
> > +config MFD_MENF21BMC
> > +	tristate "MEN 14F021P00 Board Management Controller Support"
> > +	depends on I2C=y
> 
> Why must I2C be built-in?

Sorry my mistake, I2C must not be built in.

> 
> > +	select MFD_CORE
> > +	help
> > +	  Say yes here to add support for the MEN 14F021P00 BMC
> > +	  which is a Board Management Controller connected to the I2C bus.
> > +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> > +	  This driver provides common support for accessing the devices;
> > +	  additional drivers must be enabled in order to use the
> > +	  functionality of the BMC device.
> > +
> 
> Apart from that the patch looks good to me.
> 
> I'm assuming this can go in via the MFD tree by itself?

Yes why not.
Do you want to have a single patch for the MFD or
is it better to wait for the other Subsystem maintainer that I 
can resend a patch v5?


Regards
Andy

> 
> Acked-by: Lee Jones <lee.jones@linaro.org>
> 
> -- 
> Lee Jones
> Linaro STMicroelectronics Landing Team Lead
> Linaro.org │ Open source software for ARM SoCs
> Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [lm-sensors] [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 13:57       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-21 13:57 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andreas Werner, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, jdelvare, linux, lm-sensors

T24gVGh1LCBBdWcgMjEsIDIwMTQgYXQgMTI6MzA6NDZQTSArMDEwMCwgTGVlIEpvbmVzIHdyb3Rl
Ogo+IE9uIFdlZCwgMTMgQXVnIDIwMTQsIEFuZHJlYXMgV2VybmVyIHdyb3RlOgo+ID4gVGhlIE1F
TiAxNEYwMjFQMDAgQm9hcmQgTWFuYWdlbWVudCBDb250cm9sbGVyIHByb3ZpZGVzIGFuCj4gPiBJ
MkMgaW50ZXJmYWNlIHRvIHRoZSBob3N0IHRvIGFjY2VzcyB0aGUgZmVhdHVyZSBpbXBsZW1lbnRl
ZCBpbiB0aGUgQk1DLgo+ID4gVGhlIEJNQyBpcyBhIFBJQyBNaWNyb250cm9sbGVyIGFzc2VtYmxl
ZCBvbiBDUENJIENhcmQgZnJvbSBNRU4gTWlrcm9lbGVrdHJvbmlrCj4gPiBhbmQgb24gYSBmZXcg
Qm94L0Rpc3BsYXkgQ29tcHV0ZXIuCj4gPiAKPiA+IEFkZGVkIE1GRCBDb3JlIGRyaXZlciwgc3Vw
cG9ydGluZyB0aGUgSTJDIGNvbW11bmljYXRpb24gdG8gdGhlIGRldmljZS4KPiA+IAo+ID4gVGhl
IE1GRCBkcml2ZXIgY3VycmVudGx5IHN1cHBvcnRzIHRoZSBmb2xsb3dpbmcgZmVhdHVyZXM6Cj4g
PiAgCS0gV2F0Y2hkb2cKPiA+ICAJLSBMRURzCj4gPiAJLSBId21vbiAodm9sdGFnZSBtb25pdG9y
aW5nKQo+ID4gCj4gPiBTaWduZWQtb2ZmLWJ5OiBBbmRyZWFzIFdlcm5lciA8YW5kcmVhcy53ZXJu
ZXJAbWVuLmRlPgo+ID4gLS0tCj4gPiAgZHJpdmVycy9tZmQvS2NvbmZpZyAgICAgfCAgMTIgKysr
KysKPiA+ICBkcml2ZXJzL21mZC9NYWtlZmlsZSAgICB8ICAgMSArCj4gPiAgZHJpdmVycy9tZmQv
bWVuZjIxYm1jLmMgfCAxMzIgKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysr
KysrKysrKysrCj4gPiAgMyBmaWxlcyBjaGFuZ2VkLCAxNDUgaW5zZXJ0aW9ucygrKQo+ID4gIGNy
ZWF0ZSBtb2RlIDEwMDY0NCBkcml2ZXJzL21mZC9tZW5mMjFibWMuYwo+ID4gCj4gPiBkaWZmIC0t
Z2l0IGEvZHJpdmVycy9tZmQvS2NvbmZpZyBiL2RyaXZlcnMvbWZkL0tjb25maWcKPiA+IGluZGV4
IGI4ZDljYTAuLmJmMTU1YjkgMTAwNjQ0Cj4gPiAtLS0gYS9kcml2ZXJzL21mZC9LY29uZmlnCj4g
PiArKysgYi9kcml2ZXJzL21mZC9LY29uZmlnCj4gPiBAQCAtNDUzLDYgKzQ1MywxOCBAQCBjb25m
aWcgTUZEX01BWDg5OTgKPiA+ICAJICBhZGRpdGlvbmFsIGRyaXZlcnMgbXVzdCBiZSBlbmFibGVk
IGluIG9yZGVyIHRvIHVzZSB0aGUgZnVuY3Rpb25hbGl0eQo+ID4gIAkgIG9mIHRoZSBkZXZpY2Uu
Cj4gPiAgCj4gPiArY29uZmlnIE1GRF9NRU5GMjFCTUMKPiA+ICsJdHJpc3RhdGUgIk1FTiAxNEYw
MjFQMDAgQm9hcmQgTWFuYWdlbWVudCBDb250cm9sbGVyIFN1cHBvcnQiCj4gPiArCWRlcGVuZHMg
b24gSTJDPXkKPiAKPiBXaHkgbXVzdCBJMkMgYmUgYnVpbHQtaW4/CgpTb3JyeSBteSBtaXN0YWtl
LCBJMkMgbXVzdCBub3QgYmUgYnVpbHQgaW4uCgo+IAo+ID4gKwlzZWxlY3QgTUZEX0NPUkUKPiA+
ICsJaGVscAo+ID4gKwkgIFNheSB5ZXMgaGVyZSB0byBhZGQgc3VwcG9ydCBmb3IgdGhlIE1FTiAx
NEYwMjFQMDAgQk1DCj4gPiArCSAgd2hpY2ggaXMgYSBCb2FyZCBNYW5hZ2VtZW50IENvbnRyb2xs
ZXIgY29ubmVjdGVkIHRvIHRoZSBJMkMgYnVzLgo+ID4gKwkgIFRoZSBkZXZpY2Ugc3VwcG9ydHMg
bXVsdGlwbGUgc3ViLWRldmljZXMgbGlrZSBMRUQsIEhXTU9OICBhbmQgV0RULgo+ID4gKwkgIFRo
aXMgZHJpdmVyIHByb3ZpZGVzIGNvbW1vbiBzdXBwb3J0IGZvciBhY2Nlc3NpbmcgdGhlIGRldmlj
ZXM7Cj4gPiArCSAgYWRkaXRpb25hbCBkcml2ZXJzIG11c3QgYmUgZW5hYmxlZCBpbiBvcmRlciB0
byB1c2UgdGhlCj4gPiArCSAgZnVuY3Rpb25hbGl0eSBvZiB0aGUgQk1DIGRldmljZS4KPiA+ICsK
PiAKPiBBcGFydCBmcm9tIHRoYXQgdGhlIHBhdGNoIGxvb2tzIGdvb2QgdG8gbWUuCj4gCj4gSSdt
IGFzc3VtaW5nIHRoaXMgY2FuIGdvIGluIHZpYSB0aGUgTUZEIHRyZWUgYnkgaXRzZWxmPwoKWWVz
IHdoeSBub3QuCkRvIHlvdSB3YW50IHRvIGhhdmUgYSBzaW5nbGUgcGF0Y2ggZm9yIHRoZSBNRkQg
b3IKaXMgaXQgYmV0dGVyIHRvIHdhaXQgZm9yIHRoZSBvdGhlciBTdWJzeXN0ZW0gbWFpbnRhaW5l
ciB0aGF0IEkgCmNhbiByZXNlbmQgYSBwYXRjaCB2NT8KCgpSZWdhcmRzCkFuZHkKCj4gCj4gQWNr
ZWQtYnk6IExlZSBKb25lcyA8bGVlLmpvbmVzQGxpbmFyby5vcmc+Cj4gCj4gLS0gCj4gTGVlIEpv
bmVzCj4gTGluYXJvIFNUTWljcm9lbGVjdHJvbmljcyBMYW5kaW5nIFRlYW0gTGVhZAo+IExpbmFy
by5vcmcg4pSCIE9wZW4gc291cmNlIHNvZnR3YXJlIGZvciBBUk0gU29Dcwo+IEZvbGxvdyBMaW5h
cm86IEZhY2Vib29rIHwgVHdpdHRlciB8IEJsb2cKCl9fX19fX19fX19fX19fX19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fCmxtLXNlbnNvcnMgbWFpbGluZyBsaXN0CmxtLXNlbnNvcnNA
bG0tc2Vuc29ycy5vcmcKaHR0cDovL2xpc3RzLmxtLXNlbnNvcnMub3JnL21haWxtYW4vbGlzdGlu
Zm8vbG0tc2Vuc29ycw=

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

* Re: [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-08-21 13:57       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-21 13:57 UTC (permalink / raw)
  To: Lee Jones
  Cc: Andreas Werner, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, jdelvare, linux, lm-sensors

On Thu, Aug 21, 2014 at 12:30:46PM +0100, Lee Jones wrote:
> On Wed, 13 Aug 2014, Andreas Werner wrote:
> > The MEN 14F021P00 Board Management Controller provides an
> > I2C interface to the host to access the feature implemented in the BMC.
> > The BMC is a PIC Microntroller assembled on CPCI Card from MEN Mikroelektronik
> > and on a few Box/Display Computer.
> > 
> > Added MFD Core driver, supporting the I2C communication to the device.
> > 
> > The MFD driver currently supports the following features:
> >  	- Watchdog
> >  	- LEDs
> > 	- Hwmon (voltage monitoring)
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/mfd/Kconfig     |  12 +++++
> >  drivers/mfd/Makefile    |   1 +
> >  drivers/mfd/menf21bmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 145 insertions(+)
> >  create mode 100644 drivers/mfd/menf21bmc.c
> > 
> > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > index b8d9ca0..bf155b9 100644
> > --- a/drivers/mfd/Kconfig
> > +++ b/drivers/mfd/Kconfig
> > @@ -453,6 +453,18 @@ config MFD_MAX8998
> >  	  additional drivers must be enabled in order to use the functionality
> >  	  of the device.
> >  
> > +config MFD_MENF21BMC
> > +	tristate "MEN 14F021P00 Board Management Controller Support"
> > +	depends on I2C=y
> 
> Why must I2C be built-in?

Sorry my mistake, I2C must not be built in.

> 
> > +	select MFD_CORE
> > +	help
> > +	  Say yes here to add support for the MEN 14F021P00 BMC
> > +	  which is a Board Management Controller connected to the I2C bus.
> > +	  The device supports multiple sub-devices like LED, HWMON  and WDT.
> > +	  This driver provides common support for accessing the devices;
> > +	  additional drivers must be enabled in order to use the
> > +	  functionality of the BMC device.
> > +
> 
> Apart from that the patch looks good to me.
> 
> I'm assuming this can go in via the MFD tree by itself?

Yes why not.
Do you want to have a single patch for the MFD or
is it better to wait for the other Subsystem maintainer that I 
can resend a patch v5?


Regards
Andy

> 
> Acked-by: Lee Jones <lee.jones@linaro.org>
> 
> -- 
> Lee Jones
> Linaro STMicroelectronics Landing Team Lead
> Linaro.org │ Open source software for ARM SoCs
> Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-13  8:40   ` Andreas Werner
@ 2014-08-21 18:37     ` Guenter Roeck
  -1 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-21 18:37 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Hardware Monitoring.
> The BMC is a Board Management Controller including monitoring of the
> board voltages.
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/hwmon/Kconfig           |   7 ++
>  drivers/hwmon/Makefile          |   1 +
>  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 246 insertions(+)
>  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 37908ff..437c00f 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -828,6 +828,13 @@ config SENSORS_MCP3021
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called mcp3021.
>  
> +config SENSORS_MENF21BMC_HWMON
> +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> +	depends on MFD_MENF21BMC && I2C
> +	help
> +	  Say Y here to include support for the MEN 14F021P00 BMC
> +	  hardware monitoring.
> +
>  config SENSORS_ADCXX
>  	tristate "National Semiconductor ADCxxxSxxx"
>  	depends on SPI_MASTER
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 1362382..56ab872 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
>  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
>  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
>  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
>  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
>  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
>  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> new file mode 100644
> index 0000000..ecb0ef1
> --- /dev/null
> +++ b/drivers/hwmon/menf21bmc_hwmon.c
> @@ -0,0 +1,238 @@
> +/*
> + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> + *
> + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> + *  The BMC monitors the board voltages which can be access with this
> + *  driver through sysfs.
> + *
> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> + *
> + *  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.

The license statement below states GPL v2, which contradicts the statement here.
Maybe it should just be GPL below ?

> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/jiffies.h>
> +#include <linux/slab.h>
> +#include <linux/i2c.h>
> +
> +#define DEVNAME "menf21bmc_hwmon"
> +
While that makes sense for the driver name, it doesn't really for the hwmon
device. You might want to consider just using "menf21bmc" when you register the
hwmon device.

> +#define BMC_VOLT_COUNT	5
> +#define MENF21BMC_V33	0
> +#define MENF21BMC_V5	1
> +#define MENF21BMC_V12	2
> +#define MENF21BMC_V5_SB	3
> +#define MENF21BMC_VBAT	4
> +
> +#define BMC_CMD_GET_NUM_VOLT 0x8E
> +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> +
> +struct menf21bmc_hwmon {
> +	char valid;
> +	struct i2c_client *i2c_client;
> +	unsigned long last_update;
> +	u16 in_val[BMC_VOLT_COUNT];
> +	u16 in_min[BMC_VOLT_COUNT];
> +	u16 in_max[BMC_VOLT_COUNT];
> +};
> +
> +static const char *const input_names[] = {
> +	[MENF21BMC_V33]		= "MON_3,3V",
> +	[MENF21BMC_V5]		= "MON_5V",
> +	[MENF21BMC_V12]		= "MON_12V",
> +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> +	[MENF21BMC_VBAT]	= "VBAT"
> +};
> +
> +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> +{
> +	int i;
> +	uint16_t val;
> +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> +	struct menf21bmc_hwmon *data_ret = drv_data;
> +
> +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> +						       IDX_TO_VOLT_INP_CMD(i));
> +			if (val < 0)
> +				goto abort;

I don't really see the point here. You ignore the return value,
yet you abort reading further values. The caller will assume that there was no
error even though the values in in_val were either never initialized or are out
of date.

> +
> +			drv_data->in_val[i] = val;
> +		}
> +		drv_data->last_update = jiffies;
> +		drv_data->valid = 1;
> +	}
> +abort:
> +	return data_ret;

At the same time you do have a separate variable to return.
One of those doesn't make sense.
If the idea was to return an error in data_ret, you would have to assign it
accordingly, and check in the calling code if there was an error or not.

> +}
> +
> +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> +{
> +	int i;
> +	uint16_t val;
> +
> +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> +					       IDX_TO_VOLT_MIN_CMD(i));
> +		if (val < 0)
> +			return val;
> +
> +		drv_data->in_min[i] = val;
> +
> +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> +					       IDX_TO_VOLT_MAX_CMD(i));
> +		if (val < 0)
> +			return val;
> +
> +		drv_data->in_max[i] = val;
> +	}
> +	return 0;
> +}
> +
> +static ssize_t
> +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +
> +	return sprintf(buf, "%s\n", input_names[attr->index]);
> +}
> +
> +static ssize_t
> +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	uint16_t val;
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> +
> +	val = drv_data->in_val[attr->index];
> +	return sprintf(buf, "%d\n", val);
> +}
> +
> +static ssize_t
> +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> +
> +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> +}
> +
> +static ssize_t
> +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> +
> +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> +}
> +
You could merge all the above functions into one by using a dual-indexed array
and sensor_device_attribute_2. If you don't, it does not really make sense to
call _hwmon_update to update the input voltages just to display the limits
(which you don't update).

> +#define create_voltage_sysfs(idx)			\
> +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> +			show_in, NULL, idx);		\
> +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> +			show_min, NULL, idx);		\
> +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> +			show_max, NULL, idx);		\
> +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> +			show_label, NULL, idx);
> +
> +create_voltage_sysfs(0);
> +create_voltage_sysfs(1);
> +create_voltage_sysfs(2);
> +create_voltage_sysfs(3);
> +create_voltage_sysfs(4);
> +
> +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> +	&sensor_dev_attr_in0_input.dev_attr.attr,
> +	&sensor_dev_attr_in0_min.dev_attr.attr,
> +	&sensor_dev_attr_in0_max.dev_attr.attr,
> +	&sensor_dev_attr_in0_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in1_input.dev_attr.attr,
> +	&sensor_dev_attr_in1_min.dev_attr.attr,
> +	&sensor_dev_attr_in1_max.dev_attr.attr,
> +	&sensor_dev_attr_in1_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in2_input.dev_attr.attr,
> +	&sensor_dev_attr_in2_min.dev_attr.attr,
> +	&sensor_dev_attr_in2_max.dev_attr.attr,
> +	&sensor_dev_attr_in2_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in3_input.dev_attr.attr,
> +	&sensor_dev_attr_in3_min.dev_attr.attr,
> +	&sensor_dev_attr_in3_max.dev_attr.attr,
> +	&sensor_dev_attr_in3_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in4_input.dev_attr.attr,
> +	&sensor_dev_attr_in4_min.dev_attr.attr,
> +	&sensor_dev_attr_in4_max.dev_attr.attr,
> +	&sensor_dev_attr_in4_label.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> +	.attrs = menf21bmc_hwmon_attr_volts,
> +};
> +
> +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> +	&menf21bmc_hwmon_attr_group_volts,
> +	NULL
> +};

Please use the ATTRIBUTE_GROUPS() macro.

> +
> +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> +{
> +	int ret;
> +	struct menf21bmc_hwmon *drv_data;
> +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> +	struct device *hwmon_dev;
> +
> +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> +				GFP_KERNEL);
> +	if (!drv_data)
> +		return -ENOMEM;
> +
> +	drv_data->i2c_client = i2c_client;
> +	platform_set_drvdata(pdev, drv_data);

What is this used for ?

> +
> +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to read sensor limits");
> +		return ret;
> +	}
> +
> +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> +							   DEVNAME, drv_data,
> +							   menf21bmc_hwmon_groups);
> +
> +	if (IS_ERR(hwmon_dev))
> +		return PTR_ERR(hwmon_dev);
> +
> +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> +
> +	return 0;
> +}
> +
> +static struct platform_driver menf21bmc_hwmon = {
> +	.probe		= menf21bmc_hwmon_probe,
> +	.driver		= {
> +		.name		= DEVNAME,
> +		.owner		= THIS_MODULE,
> +	},
> +};
> +
> +module_platform_driver(menf21bmc_hwmon);
> +
> +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:menf21bmc_hwmon");
> -- 
> 2.0.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv
@ 2014-08-21 18:37     ` Guenter Roeck
  0 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-21 18:37 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Hardware Monitoring.
> The BMC is a Board Management Controller including monitoring of the
> board voltages.
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/hwmon/Kconfig           |   7 ++
>  drivers/hwmon/Makefile          |   1 +
>  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 246 insertions(+)
>  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 37908ff..437c00f 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -828,6 +828,13 @@ config SENSORS_MCP3021
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called mcp3021.
>  
> +config SENSORS_MENF21BMC_HWMON
> +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> +	depends on MFD_MENF21BMC && I2C
> +	help
> +	  Say Y here to include support for the MEN 14F021P00 BMC
> +	  hardware monitoring.
> +
>  config SENSORS_ADCXX
>  	tristate "National Semiconductor ADCxxxSxxx"
>  	depends on SPI_MASTER
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 1362382..56ab872 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
>  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
>  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
>  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
>  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
>  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
>  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> new file mode 100644
> index 0000000..ecb0ef1
> --- /dev/null
> +++ b/drivers/hwmon/menf21bmc_hwmon.c
> @@ -0,0 +1,238 @@
> +/*
> + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> + *
> + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> + *  The BMC monitors the board voltages which can be access with this
> + *  driver through sysfs.
> + *
> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> + *
> + *  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.

The license statement below states GPL v2, which contradicts the statement here.
Maybe it should just be GPL below ?

> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/jiffies.h>
> +#include <linux/slab.h>
> +#include <linux/i2c.h>
> +
> +#define DEVNAME "menf21bmc_hwmon"
> +
While that makes sense for the driver name, it doesn't really for the hwmon
device. You might want to consider just using "menf21bmc" when you register the
hwmon device.

> +#define BMC_VOLT_COUNT	5
> +#define MENF21BMC_V33	0
> +#define MENF21BMC_V5	1
> +#define MENF21BMC_V12	2
> +#define MENF21BMC_V5_SB	3
> +#define MENF21BMC_VBAT	4
> +
> +#define BMC_CMD_GET_NUM_VOLT 0x8E
> +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> +
> +struct menf21bmc_hwmon {
> +	char valid;
> +	struct i2c_client *i2c_client;
> +	unsigned long last_update;
> +	u16 in_val[BMC_VOLT_COUNT];
> +	u16 in_min[BMC_VOLT_COUNT];
> +	u16 in_max[BMC_VOLT_COUNT];
> +};
> +
> +static const char *const input_names[] = {
> +	[MENF21BMC_V33]		= "MON_3,3V",
> +	[MENF21BMC_V5]		= "MON_5V",
> +	[MENF21BMC_V12]		= "MON_12V",
> +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> +	[MENF21BMC_VBAT]	= "VBAT"
> +};
> +
> +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> +{
> +	int i;
> +	uint16_t val;
> +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> +	struct menf21bmc_hwmon *data_ret = drv_data;
> +
> +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> +						       IDX_TO_VOLT_INP_CMD(i));
> +			if (val < 0)
> +				goto abort;

I don't really see the point here. You ignore the return value,
yet you abort reading further values. The caller will assume that there was no
error even though the values in in_val were either never initialized or are out
of date.

> +
> +			drv_data->in_val[i] = val;
> +		}
> +		drv_data->last_update = jiffies;
> +		drv_data->valid = 1;
> +	}
> +abort:
> +	return data_ret;

At the same time you do have a separate variable to return.
One of those doesn't make sense.
If the idea was to return an error in data_ret, you would have to assign it
accordingly, and check in the calling code if there was an error or not.

> +}
> +
> +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> +{
> +	int i;
> +	uint16_t val;
> +
> +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> +					       IDX_TO_VOLT_MIN_CMD(i));
> +		if (val < 0)
> +			return val;
> +
> +		drv_data->in_min[i] = val;
> +
> +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> +					       IDX_TO_VOLT_MAX_CMD(i));
> +		if (val < 0)
> +			return val;
> +
> +		drv_data->in_max[i] = val;
> +	}
> +	return 0;
> +}
> +
> +static ssize_t
> +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +
> +	return sprintf(buf, "%s\n", input_names[attr->index]);
> +}
> +
> +static ssize_t
> +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	uint16_t val;
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> +
> +	val = drv_data->in_val[attr->index];
> +	return sprintf(buf, "%d\n", val);
> +}
> +
> +static ssize_t
> +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> +
> +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> +}
> +
> +static ssize_t
> +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> +
> +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> +}
> +
You could merge all the above functions into one by using a dual-indexed array
and sensor_device_attribute_2. If you don't, it does not really make sense to
call _hwmon_update to update the input voltages just to display the limits
(which you don't update).

> +#define create_voltage_sysfs(idx)			\
> +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> +			show_in, NULL, idx);		\
> +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> +			show_min, NULL, idx);		\
> +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> +			show_max, NULL, idx);		\
> +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> +			show_label, NULL, idx);
> +
> +create_voltage_sysfs(0);
> +create_voltage_sysfs(1);
> +create_voltage_sysfs(2);
> +create_voltage_sysfs(3);
> +create_voltage_sysfs(4);
> +
> +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> +	&sensor_dev_attr_in0_input.dev_attr.attr,
> +	&sensor_dev_attr_in0_min.dev_attr.attr,
> +	&sensor_dev_attr_in0_max.dev_attr.attr,
> +	&sensor_dev_attr_in0_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in1_input.dev_attr.attr,
> +	&sensor_dev_attr_in1_min.dev_attr.attr,
> +	&sensor_dev_attr_in1_max.dev_attr.attr,
> +	&sensor_dev_attr_in1_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in2_input.dev_attr.attr,
> +	&sensor_dev_attr_in2_min.dev_attr.attr,
> +	&sensor_dev_attr_in2_max.dev_attr.attr,
> +	&sensor_dev_attr_in2_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in3_input.dev_attr.attr,
> +	&sensor_dev_attr_in3_min.dev_attr.attr,
> +	&sensor_dev_attr_in3_max.dev_attr.attr,
> +	&sensor_dev_attr_in3_label.dev_attr.attr,
> +
> +	&sensor_dev_attr_in4_input.dev_attr.attr,
> +	&sensor_dev_attr_in4_min.dev_attr.attr,
> +	&sensor_dev_attr_in4_max.dev_attr.attr,
> +	&sensor_dev_attr_in4_label.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> +	.attrs = menf21bmc_hwmon_attr_volts,
> +};
> +
> +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> +	&menf21bmc_hwmon_attr_group_volts,
> +	NULL
> +};

Please use the ATTRIBUTE_GROUPS() macro.

> +
> +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> +{
> +	int ret;
> +	struct menf21bmc_hwmon *drv_data;
> +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> +	struct device *hwmon_dev;
> +
> +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> +				GFP_KERNEL);
> +	if (!drv_data)
> +		return -ENOMEM;
> +
> +	drv_data->i2c_client = i2c_client;
> +	platform_set_drvdata(pdev, drv_data);

What is this used for ?

> +
> +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to read sensor limits");
> +		return ret;
> +	}
> +
> +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> +							   DEVNAME, drv_data,
> +							   menf21bmc_hwmon_groups);
> +
> +	if (IS_ERR(hwmon_dev))
> +		return PTR_ERR(hwmon_dev);
> +
> +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> +
> +	return 0;
> +}
> +
> +static struct platform_driver menf21bmc_hwmon = {
> +	.probe		= menf21bmc_hwmon_probe,
> +	.driver		= {
> +		.name		= DEVNAME,
> +		.owner		= THIS_MODULE,
> +	},
> +};
> +
> +module_platform_driver(menf21bmc_hwmon);
> +
> +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:menf21bmc_hwmon");
> -- 
> 2.0.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog driver
  2014-08-13  8:39   ` [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog driver Andreas Werner
@ 2014-08-21 18:42     ` Guenter Roeck
  -1 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-21 18:42 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Wed, Aug 13, 2014 at 10:39:59AM +0200, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Watchdog.
> The BMC is a Board Management Controller including watchdog functionality.
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

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

* Re: [lm-sensors] [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog
@ 2014-08-21 18:42     ` Guenter Roeck
  0 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-21 18:42 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Wed, Aug 13, 2014 at 10:39:59AM +0200, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Watchdog.
> The BMC is a Board Management Controller including watchdog functionality.
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-13  8:40   ` Andreas Werner
@ 2014-08-21 18:45     ` Guenter Roeck
  -1 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-21 18:45 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Hardware Monitoring.
> The BMC is a Board Management Controller including monitoring of the
> board voltages.
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/hwmon/Kconfig           |   7 ++
>  drivers/hwmon/Makefile          |   1 +
>  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++

Forgot: Please also provide Documentation/hwmon/menf21bmc.

Thanks,
Guenter

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

* Re: [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv
@ 2014-08-21 18:45     ` Guenter Roeck
  0 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-21 18:45 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Hardware Monitoring.
> The BMC is a Board Management Controller including monitoring of the
> board voltages.
> 
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/hwmon/Kconfig           |   7 ++
>  drivers/hwmon/Makefile          |   1 +
>  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++

Forgot: Please also provide Documentation/hwmon/menf21bmc.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-21 18:37     ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Guenter Roeck
  (?)
@ 2014-08-22  8:38       ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-22  8:38 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds, jdelvare,
	lm-sensors

On Thu, Aug 21, 2014 at 11:37:52AM -0700, Guenter Roeck wrote:
> On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > The BMC is a Board Management Controller including monitoring of the
> > board voltages.
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/hwmon/Kconfig           |   7 ++
> >  drivers/hwmon/Makefile          |   1 +
> >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 246 insertions(+)
> >  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> > 
> > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> > index 37908ff..437c00f 100644
> > --- a/drivers/hwmon/Kconfig
> > +++ b/drivers/hwmon/Kconfig
> > @@ -828,6 +828,13 @@ config SENSORS_MCP3021
> >  	  This driver can also be built as a module.  If so, the module
> >  	  will be called mcp3021.
> >  
> > +config SENSORS_MENF21BMC_HWMON
> > +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> > +	depends on MFD_MENF21BMC && I2C
> > +	help
> > +	  Say Y here to include support for the MEN 14F021P00 BMC
> > +	  hardware monitoring.
> > +
> >  config SENSORS_ADCXX
> >  	tristate "National Semiconductor ADCxxxSxxx"
> >  	depends on SPI_MASTER
> > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> > index 1362382..56ab872 100644
> > --- a/drivers/hwmon/Makefile
> > +++ b/drivers/hwmon/Makefile
> > @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
> >  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
> >  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
> >  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> > +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
> >  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
> >  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
> >  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> > diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> > new file mode 100644
> > index 0000000..ecb0ef1
> > --- /dev/null
> > +++ b/drivers/hwmon/menf21bmc_hwmon.c
> > @@ -0,0 +1,238 @@
> > +/*
> > + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> > + *
> > + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> > + *  The BMC monitors the board voltages which can be access with this
> > + *  driver through sysfs.
> > + *
> > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > + *
> > + *  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.
> 
> The license statement below states GPL v2, which contradicts the statement here.
> Maybe it should just be GPL below ?

Why dos it contradict? This is both GPLv2, in the header and in the MODULE_LICENSE
like i have changed it in the other slave devices and the mfd.

> 
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/hwmon.h>
> > +#include <linux/hwmon-sysfs.h>
> > +#include <linux/jiffies.h>
> > +#include <linux/slab.h>
> > +#include <linux/i2c.h>
> > +
> > +#define DEVNAME "menf21bmc_hwmon"
> > +
> While that makes sense for the driver name, it doesn't really for the hwmon
> device. You might want to consider just using "menf21bmc" when you register the
> hwmon device.
>

menf21bmc is the name of the MFD driver. This name is to distinguish each of
the slaves. For that the name represent that this device is a slave of "menf21bmc"
and a "hwmon" of its own.
 
> > +#define BMC_VOLT_COUNT	5
> > +#define MENF21BMC_V33	0
> > +#define MENF21BMC_V5	1
> > +#define MENF21BMC_V12	2
> > +#define MENF21BMC_V5_SB	3
> > +#define MENF21BMC_VBAT	4
> > +
> > +#define BMC_CMD_GET_NUM_VOLT 0x8E
> > +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> > +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> > +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> > +
> > +struct menf21bmc_hwmon {
> > +	char valid;
> > +	struct i2c_client *i2c_client;
> > +	unsigned long last_update;
> > +	u16 in_val[BMC_VOLT_COUNT];
> > +	u16 in_min[BMC_VOLT_COUNT];
> > +	u16 in_max[BMC_VOLT_COUNT];
> > +};
> > +
> > +static const char *const input_names[] = {
> > +	[MENF21BMC_V33]		= "MON_3,3V",
> > +	[MENF21BMC_V5]		= "MON_5V",
> > +	[MENF21BMC_V12]		= "MON_12V",
> > +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> > +	[MENF21BMC_VBAT]	= "VBAT"
> > +};
> > +
> > +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> > +{
> > +	int i;
> > +	uint16_t val;
> > +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> > +	struct menf21bmc_hwmon *data_ret = drv_data;
> > +
> > +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> > +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +						       IDX_TO_VOLT_INP_CMD(i));
> > +			if (val < 0)
> > +				goto abort;
> 
> I don't really see the point here. You ignore the return value,
> yet you abort reading further values. The caller will assume that there was no
> error even though the values in in_val were either never initialized or are out
> of date.
> 

Argh thats true.
I have checked out some other drivers and they just read the value from the 
i2c bus and save the value into the struct without error checking.
Is that the normal way?
If yes then the caller hast to check if the value is a correct voltage value.

The other way what i see is to read the value, check if there is no error and then
save the new value to the struct. If there is an error during read then we just
do not update the value and let it as it is.
If I go this way then i do not need the second struct as the return value.

> > +
> > +			drv_data->in_val[i] = val;
> > +		}
> > +		drv_data->last_update = jiffies;
> > +		drv_data->valid = 1;
> > +	}
> > +abort:
> > +	return data_ret;
> 
> At the same time you do have a separate variable to return.
> One of those doesn't make sense.
> If the idea was to return an error in data_ret, you would have to assign it
> accordingly, and check in the calling code if there was an error or not.

Will be changed, see above.

> 
> > +}
> > +
> > +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> > +{
> > +	int i;
> > +	uint16_t val;
> > +
> > +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +					       IDX_TO_VOLT_MIN_CMD(i));
> > +		if (val < 0)
> > +			return val;
> > +
> > +		drv_data->in_min[i] = val;
> > +
> > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +					       IDX_TO_VOLT_MAX_CMD(i));
> > +		if (val < 0)
> > +			return val;
> > +
> > +		drv_data->in_max[i] = val;
> > +	}
> > +	return 0;
> > +}
> > +
> > +static ssize_t
> > +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +
> > +	return sprintf(buf, "%s\n", input_names[attr->index]);
> > +}
> > +
> > +static ssize_t
> > +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	uint16_t val;
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	val = drv_data->in_val[attr->index];
> > +	return sprintf(buf, "%d\n", val);
> > +}
> > +
> > +static ssize_t
> > +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> > +}
> > +
> > +static ssize_t
> > +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> > +}
> > +
> You could merge all the above functions into one by using a dual-indexed array
> and sensor_device_attribute_2. If you don't, it does not really make sense to
> call _hwmon_update to update the input voltages just to display the limits
> (which you don't update).
> 

I do not want to merge it to one function. I will delete the upate call
for min and max values.

> > +#define create_voltage_sysfs(idx)			\
> > +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> > +			show_in, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> > +			show_min, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> > +			show_max, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> > +			show_label, NULL, idx);
> > +
> > +create_voltage_sysfs(0);
> > +create_voltage_sysfs(1);
> > +create_voltage_sysfs(2);
> > +create_voltage_sysfs(3);
> > +create_voltage_sysfs(4);
> > +
> > +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> > +	&sensor_dev_attr_in0_input.dev_attr.attr,
> > +	&sensor_dev_attr_in0_min.dev_attr.attr,
> > +	&sensor_dev_attr_in0_max.dev_attr.attr,
> > +	&sensor_dev_attr_in0_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in1_input.dev_attr.attr,
> > +	&sensor_dev_attr_in1_min.dev_attr.attr,
> > +	&sensor_dev_attr_in1_max.dev_attr.attr,
> > +	&sensor_dev_attr_in1_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in2_input.dev_attr.attr,
> > +	&sensor_dev_attr_in2_min.dev_attr.attr,
> > +	&sensor_dev_attr_in2_max.dev_attr.attr,
> > +	&sensor_dev_attr_in2_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in3_input.dev_attr.attr,
> > +	&sensor_dev_attr_in3_min.dev_attr.attr,
> > +	&sensor_dev_attr_in3_max.dev_attr.attr,
> > +	&sensor_dev_attr_in3_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in4_input.dev_attr.attr,
> > +	&sensor_dev_attr_in4_min.dev_attr.attr,
> > +	&sensor_dev_attr_in4_max.dev_attr.attr,
> > +	&sensor_dev_attr_in4_label.dev_attr.attr,
> > +	NULL
> > +};
> > +
> > +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> > +	.attrs = menf21bmc_hwmon_attr_volts,
> > +};
> > +
> > +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> > +	&menf21bmc_hwmon_attr_group_volts,
> > +	NULL
> > +};
> 
> Please use the ATTRIBUTE_GROUPS() macro.

Ok i will use the macro.

> 
> > +
> > +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> > +{
> > +	int ret;
> > +	struct menf21bmc_hwmon *drv_data;
> > +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > +	struct device *hwmon_dev;
> > +
> > +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> > +				GFP_KERNEL);
> > +	if (!drv_data)
> > +		return -ENOMEM;
> > +
> > +	drv_data->i2c_client = i2c_client;
> > +	platform_set_drvdata(pdev, drv_data);
> 
> What is this used for ?

For the update function. I need to access the drv_data there.
May this could change, depends on the changes of the update function.
> 
> > +
> > +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "failed to read sensor limits");
> > +		return ret;
> > +	}
> > +
> > +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> > +							   DEVNAME, drv_data,
> > +							   menf21bmc_hwmon_groups);
> > +
> > +	if (IS_ERR(hwmon_dev))
> > +		return PTR_ERR(hwmon_dev);
> > +
> > +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> > +
> > +	return 0;
> > +}
> > +
> > +static struct platform_driver menf21bmc_hwmon = {
> > +	.probe		= menf21bmc_hwmon_probe,
> > +	.driver		= {
> > +		.name		= DEVNAME,
> > +		.owner		= THIS_MODULE,
> > +	},
> > +};
> > +
> > +module_platform_driver(menf21bmc_hwmon);
> > +
> > +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> > +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> > +MODULE_LICENSE("GPL v2");
> > +MODULE_ALIAS("platform:menf21bmc_hwmon");
> > -- 
> > 2.0.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
@ 2014-08-22  8:38       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-22  8:38 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds, jdelvare,
	lm-sensors

On Thu, Aug 21, 2014 at 11:37:52AM -0700, Guenter Roeck wrote:
> On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > The BMC is a Board Management Controller including monitoring of the
> > board voltages.
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/hwmon/Kconfig           |   7 ++
> >  drivers/hwmon/Makefile          |   1 +
> >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 246 insertions(+)
> >  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> > 
> > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> > index 37908ff..437c00f 100644
> > --- a/drivers/hwmon/Kconfig
> > +++ b/drivers/hwmon/Kconfig
> > @@ -828,6 +828,13 @@ config SENSORS_MCP3021
> >  	  This driver can also be built as a module.  If so, the module
> >  	  will be called mcp3021.
> >  
> > +config SENSORS_MENF21BMC_HWMON
> > +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> > +	depends on MFD_MENF21BMC && I2C
> > +	help
> > +	  Say Y here to include support for the MEN 14F021P00 BMC
> > +	  hardware monitoring.
> > +
> >  config SENSORS_ADCXX
> >  	tristate "National Semiconductor ADCxxxSxxx"
> >  	depends on SPI_MASTER
> > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> > index 1362382..56ab872 100644
> > --- a/drivers/hwmon/Makefile
> > +++ b/drivers/hwmon/Makefile
> > @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
> >  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
> >  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
> >  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> > +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
> >  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
> >  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
> >  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> > diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> > new file mode 100644
> > index 0000000..ecb0ef1
> > --- /dev/null
> > +++ b/drivers/hwmon/menf21bmc_hwmon.c
> > @@ -0,0 +1,238 @@
> > +/*
> > + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> > + *
> > + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> > + *  The BMC monitors the board voltages which can be access with this
> > + *  driver through sysfs.
> > + *
> > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > + *
> > + *  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.
> 
> The license statement below states GPL v2, which contradicts the statement here.
> Maybe it should just be GPL below ?

Why dos it contradict? This is both GPLv2, in the header and in the MODULE_LICENSE
like i have changed it in the other slave devices and the mfd.

> 
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/hwmon.h>
> > +#include <linux/hwmon-sysfs.h>
> > +#include <linux/jiffies.h>
> > +#include <linux/slab.h>
> > +#include <linux/i2c.h>
> > +
> > +#define DEVNAME "menf21bmc_hwmon"
> > +
> While that makes sense for the driver name, it doesn't really for the hwmon
> device. You might want to consider just using "menf21bmc" when you register the
> hwmon device.
>

menf21bmc is the name of the MFD driver. This name is to distinguish each of
the slaves. For that the name represent that this device is a slave of "menf21bmc"
and a "hwmon" of its own.
 
> > +#define BMC_VOLT_COUNT	5
> > +#define MENF21BMC_V33	0
> > +#define MENF21BMC_V5	1
> > +#define MENF21BMC_V12	2
> > +#define MENF21BMC_V5_SB	3
> > +#define MENF21BMC_VBAT	4
> > +
> > +#define BMC_CMD_GET_NUM_VOLT 0x8E
> > +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> > +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> > +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> > +
> > +struct menf21bmc_hwmon {
> > +	char valid;
> > +	struct i2c_client *i2c_client;
> > +	unsigned long last_update;
> > +	u16 in_val[BMC_VOLT_COUNT];
> > +	u16 in_min[BMC_VOLT_COUNT];
> > +	u16 in_max[BMC_VOLT_COUNT];
> > +};
> > +
> > +static const char *const input_names[] = {
> > +	[MENF21BMC_V33]		= "MON_3,3V",
> > +	[MENF21BMC_V5]		= "MON_5V",
> > +	[MENF21BMC_V12]		= "MON_12V",
> > +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> > +	[MENF21BMC_VBAT]	= "VBAT"
> > +};
> > +
> > +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> > +{
> > +	int i;
> > +	uint16_t val;
> > +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> > +	struct menf21bmc_hwmon *data_ret = drv_data;
> > +
> > +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> > +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +						       IDX_TO_VOLT_INP_CMD(i));
> > +			if (val < 0)
> > +				goto abort;
> 
> I don't really see the point here. You ignore the return value,
> yet you abort reading further values. The caller will assume that there was no
> error even though the values in in_val were either never initialized or are out
> of date.
> 

Argh thats true.
I have checked out some other drivers and they just read the value from the 
i2c bus and save the value into the struct without error checking.
Is that the normal way?
If yes then the caller hast to check if the value is a correct voltage value.

The other way what i see is to read the value, check if there is no error and then
save the new value to the struct. If there is an error during read then we just
do not update the value and let it as it is.
If I go this way then i do not need the second struct as the return value.

> > +
> > +			drv_data->in_val[i] = val;
> > +		}
> > +		drv_data->last_update = jiffies;
> > +		drv_data->valid = 1;
> > +	}
> > +abort:
> > +	return data_ret;
> 
> At the same time you do have a separate variable to return.
> One of those doesn't make sense.
> If the idea was to return an error in data_ret, you would have to assign it
> accordingly, and check in the calling code if there was an error or not.

Will be changed, see above.

> 
> > +}
> > +
> > +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> > +{
> > +	int i;
> > +	uint16_t val;
> > +
> > +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +					       IDX_TO_VOLT_MIN_CMD(i));
> > +		if (val < 0)
> > +			return val;
> > +
> > +		drv_data->in_min[i] = val;
> > +
> > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +					       IDX_TO_VOLT_MAX_CMD(i));
> > +		if (val < 0)
> > +			return val;
> > +
> > +		drv_data->in_max[i] = val;
> > +	}
> > +	return 0;
> > +}
> > +
> > +static ssize_t
> > +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +
> > +	return sprintf(buf, "%s\n", input_names[attr->index]);
> > +}
> > +
> > +static ssize_t
> > +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	uint16_t val;
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	val = drv_data->in_val[attr->index];
> > +	return sprintf(buf, "%d\n", val);
> > +}
> > +
> > +static ssize_t
> > +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> > +}
> > +
> > +static ssize_t
> > +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> > +}
> > +
> You could merge all the above functions into one by using a dual-indexed array
> and sensor_device_attribute_2. If you don't, it does not really make sense to
> call _hwmon_update to update the input voltages just to display the limits
> (which you don't update).
> 

I do not want to merge it to one function. I will delete the upate call
for min and max values.

> > +#define create_voltage_sysfs(idx)			\
> > +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> > +			show_in, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> > +			show_min, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> > +			show_max, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> > +			show_label, NULL, idx);
> > +
> > +create_voltage_sysfs(0);
> > +create_voltage_sysfs(1);
> > +create_voltage_sysfs(2);
> > +create_voltage_sysfs(3);
> > +create_voltage_sysfs(4);
> > +
> > +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> > +	&sensor_dev_attr_in0_input.dev_attr.attr,
> > +	&sensor_dev_attr_in0_min.dev_attr.attr,
> > +	&sensor_dev_attr_in0_max.dev_attr.attr,
> > +	&sensor_dev_attr_in0_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in1_input.dev_attr.attr,
> > +	&sensor_dev_attr_in1_min.dev_attr.attr,
> > +	&sensor_dev_attr_in1_max.dev_attr.attr,
> > +	&sensor_dev_attr_in1_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in2_input.dev_attr.attr,
> > +	&sensor_dev_attr_in2_min.dev_attr.attr,
> > +	&sensor_dev_attr_in2_max.dev_attr.attr,
> > +	&sensor_dev_attr_in2_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in3_input.dev_attr.attr,
> > +	&sensor_dev_attr_in3_min.dev_attr.attr,
> > +	&sensor_dev_attr_in3_max.dev_attr.attr,
> > +	&sensor_dev_attr_in3_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in4_input.dev_attr.attr,
> > +	&sensor_dev_attr_in4_min.dev_attr.attr,
> > +	&sensor_dev_attr_in4_max.dev_attr.attr,
> > +	&sensor_dev_attr_in4_label.dev_attr.attr,
> > +	NULL
> > +};
> > +
> > +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> > +	.attrs = menf21bmc_hwmon_attr_volts,
> > +};
> > +
> > +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> > +	&menf21bmc_hwmon_attr_group_volts,
> > +	NULL
> > +};
> 
> Please use the ATTRIBUTE_GROUPS() macro.

Ok i will use the macro.

> 
> > +
> > +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> > +{
> > +	int ret;
> > +	struct menf21bmc_hwmon *drv_data;
> > +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > +	struct device *hwmon_dev;
> > +
> > +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> > +				GFP_KERNEL);
> > +	if (!drv_data)
> > +		return -ENOMEM;
> > +
> > +	drv_data->i2c_client = i2c_client;
> > +	platform_set_drvdata(pdev, drv_data);
> 
> What is this used for ?

For the update function. I need to access the drv_data there.
May this could change, depends on the changes of the update function.
> 
> > +
> > +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "failed to read sensor limits");
> > +		return ret;
> > +	}
> > +
> > +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> > +							   DEVNAME, drv_data,
> > +							   menf21bmc_hwmon_groups);
> > +
> > +	if (IS_ERR(hwmon_dev))
> > +		return PTR_ERR(hwmon_dev);
> > +
> > +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> > +
> > +	return 0;
> > +}
> > +
> > +static struct platform_driver menf21bmc_hwmon = {
> > +	.probe		= menf21bmc_hwmon_probe,
> > +	.driver		= {
> > +		.name		= DEVNAME,
> > +		.owner		= THIS_MODULE,
> > +	},
> > +};
> > +
> > +module_platform_driver(menf21bmc_hwmon);
> > +
> > +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> > +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> > +MODULE_LICENSE("GPL v2");
> > +MODULE_ALIAS("platform:menf21bmc_hwmon");
> > -- 
> > 2.0.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 

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

* Re: [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv
@ 2014-08-22  8:38       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-22  8:38 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds, jdelvare,
	lm-sensors

On Thu, Aug 21, 2014 at 11:37:52AM -0700, Guenter Roeck wrote:
> On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > The BMC is a Board Management Controller including monitoring of the
> > board voltages.
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/hwmon/Kconfig           |   7 ++
> >  drivers/hwmon/Makefile          |   1 +
> >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 246 insertions(+)
> >  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> > 
> > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> > index 37908ff..437c00f 100644
> > --- a/drivers/hwmon/Kconfig
> > +++ b/drivers/hwmon/Kconfig
> > @@ -828,6 +828,13 @@ config SENSORS_MCP3021
> >  	  This driver can also be built as a module.  If so, the module
> >  	  will be called mcp3021.
> >  
> > +config SENSORS_MENF21BMC_HWMON
> > +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> > +	depends on MFD_MENF21BMC && I2C
> > +	help
> > +	  Say Y here to include support for the MEN 14F021P00 BMC
> > +	  hardware monitoring.
> > +
> >  config SENSORS_ADCXX
> >  	tristate "National Semiconductor ADCxxxSxxx"
> >  	depends on SPI_MASTER
> > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> > index 1362382..56ab872 100644
> > --- a/drivers/hwmon/Makefile
> > +++ b/drivers/hwmon/Makefile
> > @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
> >  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
> >  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
> >  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> > +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
> >  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
> >  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
> >  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> > diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> > new file mode 100644
> > index 0000000..ecb0ef1
> > --- /dev/null
> > +++ b/drivers/hwmon/menf21bmc_hwmon.c
> > @@ -0,0 +1,238 @@
> > +/*
> > + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> > + *
> > + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> > + *  The BMC monitors the board voltages which can be access with this
> > + *  driver through sysfs.
> > + *
> > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > + *
> > + *  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.
> 
> The license statement below states GPL v2, which contradicts the statement here.
> Maybe it should just be GPL below ?

Why dos it contradict? This is both GPLv2, in the header and in the MODULE_LICENSE
like i have changed it in the other slave devices and the mfd.

> 
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/hwmon.h>
> > +#include <linux/hwmon-sysfs.h>
> > +#include <linux/jiffies.h>
> > +#include <linux/slab.h>
> > +#include <linux/i2c.h>
> > +
> > +#define DEVNAME "menf21bmc_hwmon"
> > +
> While that makes sense for the driver name, it doesn't really for the hwmon
> device. You might want to consider just using "menf21bmc" when you register the
> hwmon device.
>

menf21bmc is the name of the MFD driver. This name is to distinguish each of
the slaves. For that the name represent that this device is a slave of "menf21bmc"
and a "hwmon" of its own.
 
> > +#define BMC_VOLT_COUNT	5
> > +#define MENF21BMC_V33	0
> > +#define MENF21BMC_V5	1
> > +#define MENF21BMC_V12	2
> > +#define MENF21BMC_V5_SB	3
> > +#define MENF21BMC_VBAT	4
> > +
> > +#define BMC_CMD_GET_NUM_VOLT 0x8E
> > +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> > +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> > +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> > +
> > +struct menf21bmc_hwmon {
> > +	char valid;
> > +	struct i2c_client *i2c_client;
> > +	unsigned long last_update;
> > +	u16 in_val[BMC_VOLT_COUNT];
> > +	u16 in_min[BMC_VOLT_COUNT];
> > +	u16 in_max[BMC_VOLT_COUNT];
> > +};
> > +
> > +static const char *const input_names[] = {
> > +	[MENF21BMC_V33]		= "MON_3,3V",
> > +	[MENF21BMC_V5]		= "MON_5V",
> > +	[MENF21BMC_V12]		= "MON_12V",
> > +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> > +	[MENF21BMC_VBAT]	= "VBAT"
> > +};
> > +
> > +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> > +{
> > +	int i;
> > +	uint16_t val;
> > +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> > +	struct menf21bmc_hwmon *data_ret = drv_data;
> > +
> > +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> > +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +						       IDX_TO_VOLT_INP_CMD(i));
> > +			if (val < 0)
> > +				goto abort;
> 
> I don't really see the point here. You ignore the return value,
> yet you abort reading further values. The caller will assume that there was no
> error even though the values in in_val were either never initialized or are out
> of date.
> 

Argh thats true.
I have checked out some other drivers and they just read the value from the 
i2c bus and save the value into the struct without error checking.
Is that the normal way?
If yes then the caller hast to check if the value is a correct voltage value.

The other way what i see is to read the value, check if there is no error and then
save the new value to the struct. If there is an error during read then we just
do not update the value and let it as it is.
If I go this way then i do not need the second struct as the return value.

> > +
> > +			drv_data->in_val[i] = val;
> > +		}
> > +		drv_data->last_update = jiffies;
> > +		drv_data->valid = 1;
> > +	}
> > +abort:
> > +	return data_ret;
> 
> At the same time you do have a separate variable to return.
> One of those doesn't make sense.
> If the idea was to return an error in data_ret, you would have to assign it
> accordingly, and check in the calling code if there was an error or not.

Will be changed, see above.

> 
> > +}
> > +
> > +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> > +{
> > +	int i;
> > +	uint16_t val;
> > +
> > +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +					       IDX_TO_VOLT_MIN_CMD(i));
> > +		if (val < 0)
> > +			return val;
> > +
> > +		drv_data->in_min[i] = val;
> > +
> > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > +					       IDX_TO_VOLT_MAX_CMD(i));
> > +		if (val < 0)
> > +			return val;
> > +
> > +		drv_data->in_max[i] = val;
> > +	}
> > +	return 0;
> > +}
> > +
> > +static ssize_t
> > +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +
> > +	return sprintf(buf, "%s\n", input_names[attr->index]);
> > +}
> > +
> > +static ssize_t
> > +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	uint16_t val;
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	val = drv_data->in_val[attr->index];
> > +	return sprintf(buf, "%d\n", val);
> > +}
> > +
> > +static ssize_t
> > +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> > +}
> > +
> > +static ssize_t
> > +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> > +{
> > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > +
> > +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> > +}
> > +
> You could merge all the above functions into one by using a dual-indexed array
> and sensor_device_attribute_2. If you don't, it does not really make sense to
> call _hwmon_update to update the input voltages just to display the limits
> (which you don't update).
> 

I do not want to merge it to one function. I will delete the upate call
for min and max values.

> > +#define create_voltage_sysfs(idx)			\
> > +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> > +			show_in, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> > +			show_min, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> > +			show_max, NULL, idx);		\
> > +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> > +			show_label, NULL, idx);
> > +
> > +create_voltage_sysfs(0);
> > +create_voltage_sysfs(1);
> > +create_voltage_sysfs(2);
> > +create_voltage_sysfs(3);
> > +create_voltage_sysfs(4);
> > +
> > +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> > +	&sensor_dev_attr_in0_input.dev_attr.attr,
> > +	&sensor_dev_attr_in0_min.dev_attr.attr,
> > +	&sensor_dev_attr_in0_max.dev_attr.attr,
> > +	&sensor_dev_attr_in0_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in1_input.dev_attr.attr,
> > +	&sensor_dev_attr_in1_min.dev_attr.attr,
> > +	&sensor_dev_attr_in1_max.dev_attr.attr,
> > +	&sensor_dev_attr_in1_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in2_input.dev_attr.attr,
> > +	&sensor_dev_attr_in2_min.dev_attr.attr,
> > +	&sensor_dev_attr_in2_max.dev_attr.attr,
> > +	&sensor_dev_attr_in2_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in3_input.dev_attr.attr,
> > +	&sensor_dev_attr_in3_min.dev_attr.attr,
> > +	&sensor_dev_attr_in3_max.dev_attr.attr,
> > +	&sensor_dev_attr_in3_label.dev_attr.attr,
> > +
> > +	&sensor_dev_attr_in4_input.dev_attr.attr,
> > +	&sensor_dev_attr_in4_min.dev_attr.attr,
> > +	&sensor_dev_attr_in4_max.dev_attr.attr,
> > +	&sensor_dev_attr_in4_label.dev_attr.attr,
> > +	NULL
> > +};
> > +
> > +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> > +	.attrs = menf21bmc_hwmon_attr_volts,
> > +};
> > +
> > +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> > +	&menf21bmc_hwmon_attr_group_volts,
> > +	NULL
> > +};
> 
> Please use the ATTRIBUTE_GROUPS() macro.

Ok i will use the macro.

> 
> > +
> > +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> > +{
> > +	int ret;
> > +	struct menf21bmc_hwmon *drv_data;
> > +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > +	struct device *hwmon_dev;
> > +
> > +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> > +				GFP_KERNEL);
> > +	if (!drv_data)
> > +		return -ENOMEM;
> > +
> > +	drv_data->i2c_client = i2c_client;
> > +	platform_set_drvdata(pdev, drv_data);
> 
> What is this used for ?

For the update function. I need to access the drv_data there.
May this could change, depends on the changes of the update function.
> 
> > +
> > +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "failed to read sensor limits");
> > +		return ret;
> > +	}
> > +
> > +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> > +							   DEVNAME, drv_data,
> > +							   menf21bmc_hwmon_groups);
> > +
> > +	if (IS_ERR(hwmon_dev))
> > +		return PTR_ERR(hwmon_dev);
> > +
> > +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> > +
> > +	return 0;
> > +}
> > +
> > +static struct platform_driver menf21bmc_hwmon = {
> > +	.probe		= menf21bmc_hwmon_probe,
> > +	.driver		= {
> > +		.name		= DEVNAME,
> > +		.owner		= THIS_MODULE,
> > +	},
> > +};
> > +
> > +module_platform_driver(menf21bmc_hwmon);
> > +
> > +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> > +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> > +MODULE_LICENSE("GPL v2");
> > +MODULE_ALIAS("platform:menf21bmc_hwmon");
> > -- 
> > 2.0.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-21 18:45     ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Guenter Roeck
  (?)
@ 2014-08-22  8:39       ` Andreas Werner
  -1 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-22  8:39 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds, jdelvare,
	lm-sensors

On Thu, Aug 21, 2014 at 11:45:01AM -0700, Guenter Roeck wrote:
> On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > The BMC is a Board Management Controller including monitoring of the
> > board voltages.
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/hwmon/Kconfig           |   7 ++
> >  drivers/hwmon/Makefile          |   1 +
> >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> 
> Forgot: Please also provide Documentation/hwmon/menf21bmc.
> 

Did not know that i have to do it.
But you are right it is good to have one.

> Thanks,
> Guenter

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
@ 2014-08-22  8:39       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-22  8:39 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds, jdelvare,
	lm-sensors

On Thu, Aug 21, 2014 at 11:45:01AM -0700, Guenter Roeck wrote:
> On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > The BMC is a Board Management Controller including monitoring of the
> > board voltages.
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/hwmon/Kconfig           |   7 ++
> >  drivers/hwmon/Makefile          |   1 +
> >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> 
> Forgot: Please also provide Documentation/hwmon/menf21bmc.
> 

Did not know that i have to do it.
But you are right it is good to have one.

> Thanks,
> Guenter

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

* Re: [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv
@ 2014-08-22  8:39       ` Andreas Werner
  0 siblings, 0 replies; 45+ messages in thread
From: Andreas Werner @ 2014-08-22  8:39 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds, jdelvare,
	lm-sensors

On Thu, Aug 21, 2014 at 11:45:01AM -0700, Guenter Roeck wrote:
> On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > The BMC is a Board Management Controller including monitoring of the
> > board voltages.
> > 
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/hwmon/Kconfig           |   7 ++
> >  drivers/hwmon/Makefile          |   1 +
> >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> 
> Forgot: Please also provide Documentation/hwmon/menf21bmc.
> 

Did not know that i have to do it.
But you are right it is good to have one.

> Thanks,
> Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-22  8:38       ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
@ 2014-08-22  9:02         ` Guenter Roeck
  -1 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-22  9:02 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Fri, Aug 22, 2014 at 10:38:11AM +0200, Andreas Werner wrote:
> On Thu, Aug 21, 2014 at 11:37:52AM -0700, Guenter Roeck wrote:
> > On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > > The BMC is a Board Management Controller including monitoring of the
> > > board voltages.
> > > 
> > > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > > ---
> > >  drivers/hwmon/Kconfig           |   7 ++
> > >  drivers/hwmon/Makefile          |   1 +
> > >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 246 insertions(+)
> > >  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> > > 
> > > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> > > index 37908ff..437c00f 100644
> > > --- a/drivers/hwmon/Kconfig
> > > +++ b/drivers/hwmon/Kconfig
> > > @@ -828,6 +828,13 @@ config SENSORS_MCP3021
> > >  	  This driver can also be built as a module.  If so, the module
> > >  	  will be called mcp3021.
> > >  
> > > +config SENSORS_MENF21BMC_HWMON
> > > +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> > > +	depends on MFD_MENF21BMC && I2C
> > > +	help
> > > +	  Say Y here to include support for the MEN 14F021P00 BMC
> > > +	  hardware monitoring.
> > > +
> > >  config SENSORS_ADCXX
> > >  	tristate "National Semiconductor ADCxxxSxxx"
> > >  	depends on SPI_MASTER
> > > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> > > index 1362382..56ab872 100644
> > > --- a/drivers/hwmon/Makefile
> > > +++ b/drivers/hwmon/Makefile
> > > @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
> > >  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
> > >  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
> > >  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> > > +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
> > >  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
> > >  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
> > >  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> > > diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> > > new file mode 100644
> > > index 0000000..ecb0ef1
> > > --- /dev/null
> > > +++ b/drivers/hwmon/menf21bmc_hwmon.c
> > > @@ -0,0 +1,238 @@
> > > +/*
> > > + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> > > + *
> > > + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> > > + *  The BMC monitors the board voltages which can be access with this
> > > + *  driver through sysfs.
> > > + *
> > > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > > + *
> > > + *  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.
> > 
> > The license statement below states GPL v2, which contradicts the statement here.
> > Maybe it should just be GPL below ?
> 
> Why dos it contradict? This is both GPLv2, in the header and in the MODULE_LICENSE
> like i have changed it in the other slave devices and the mfd.
> 
Ok, your call.

> > 
> > > + */
> > > +
> > > +#include <linux/module.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/hwmon.h>
> > > +#include <linux/hwmon-sysfs.h>
> > > +#include <linux/jiffies.h>
> > > +#include <linux/slab.h>
> > > +#include <linux/i2c.h>
> > > +
> > > +#define DEVNAME "menf21bmc_hwmon"
> > > +
> > While that makes sense for the driver name, it doesn't really for the hwmon
> > device. You might want to consider just using "menf21bmc" when you register the
> > hwmon device.
> >
> 
> menf21bmc is the name of the MFD driver. This name is to distinguish each of
> the slaves. For that the name represent that this device is a slave of "menf21bmc"
> and a "hwmon" of its own.
>  
Yes, but that doesn' mean that the name registered with the hwmon subsystem has
to have "hwmon" in it; this is independent of the driver name. That is still
redundant. Anyway, your driver, your call.

> > > +#define BMC_VOLT_COUNT	5
> > > +#define MENF21BMC_V33	0
> > > +#define MENF21BMC_V5	1
> > > +#define MENF21BMC_V12	2
> > > +#define MENF21BMC_V5_SB	3
> > > +#define MENF21BMC_VBAT	4
> > > +
> > > +#define BMC_CMD_GET_NUM_VOLT 0x8E
> > > +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> > > +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> > > +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> > > +
> > > +struct menf21bmc_hwmon {
> > > +	char valid;
> > > +	struct i2c_client *i2c_client;
> > > +	unsigned long last_update;
> > > +	u16 in_val[BMC_VOLT_COUNT];
> > > +	u16 in_min[BMC_VOLT_COUNT];
> > > +	u16 in_max[BMC_VOLT_COUNT];
> > > +};
> > > +
> > > +static const char *const input_names[] = {
> > > +	[MENF21BMC_V33]		= "MON_3,3V",
> > > +	[MENF21BMC_V5]		= "MON_5V",
> > > +	[MENF21BMC_V12]		= "MON_12V",
> > > +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> > > +	[MENF21BMC_VBAT]	= "VBAT"
> > > +};
> > > +
> > > +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> > > +{
> > > +	int i;
> > > +	uint16_t val;
> > > +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> > > +	struct menf21bmc_hwmon *data_ret = drv_data;
> > > +
> > > +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> > > +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > > +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > > +						       IDX_TO_VOLT_INP_CMD(i));
> > > +			if (val < 0)
> > > +				goto abort;
> > 
> > I don't really see the point here. You ignore the return value,
> > yet you abort reading further values. The caller will assume that there was no
> > error even though the values in in_val were either never initialized or are out
> > of date.
> > 
> 
> Argh thats true.
> I have checked out some other drivers and they just read the value from the 
> i2c bus and save the value into the struct without error checking.
> Is that the normal way?
> If yes then the caller hast to check if the value is a correct voltage value.

You have a number of options: Ignore the error, but consistently. Not a good
idea, not done by recent drivers, but if you think your chip never reports an
error fine with me. Abort if an error occurs, and return the error code from the
function. Store the error in the data, and check the data for error in the
calling code.

My personal preference would be to return an error code from the function (with
PTR_ERR) and check it in the calling code (with ERR_PTR), but it is really your
call.

> 
> The other way what i see is to read the value, check if there is no error and then
> save the new value to the struct. If there is an error during read then we just
> do not update the value and let it as it is.

This is akin to ignoring errors. Again, I don't think this would be a good idea,
but it is your call to make.

> If I go this way then i do not need the second struct as the return value.
> 
> > > +
> > > +			drv_data->in_val[i] = val;
> > > +		}
> > > +		drv_data->last_update = jiffies;
> > > +		drv_data->valid = 1;
> > > +	}
> > > +abort:
> > > +	return data_ret;
> > 
> > At the same time you do have a separate variable to return.
> > One of those doesn't make sense.
> > If the idea was to return an error in data_ret, you would have to assign it
> > accordingly, and check in the calling code if there was an error or not.
> 
> Will be changed, see above.
> 
> > 
> > > +}
> > > +
> > > +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> > > +{
> > > +	int i;
> > > +	uint16_t val;
> > > +
> > > +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > > +					       IDX_TO_VOLT_MIN_CMD(i));
> > > +		if (val < 0)
> > > +			return val;
> > > +
> > > +		drv_data->in_min[i] = val;
> > > +
> > > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > > +					       IDX_TO_VOLT_MAX_CMD(i));
> > > +		if (val < 0)
> > > +			return val;
> > > +
> > > +		drv_data->in_max[i] = val;
> > > +	}
> > > +	return 0;
> > > +}
> > > +
> > > +static ssize_t
> > > +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +
> > > +	return sprintf(buf, "%s\n", input_names[attr->index]);
> > > +}
> > > +
> > > +static ssize_t
> > > +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	uint16_t val;
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > > +
> > > +	val = drv_data->in_val[attr->index];
> > > +	return sprintf(buf, "%d\n", val);
> > > +}
> > > +
> > > +static ssize_t
> > > +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > > +
> > > +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> > > +}
> > > +
> > > +static ssize_t
> > > +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > > +
> > > +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> > > +}
> > > +
> > You could merge all the above functions into one by using a dual-indexed array
> > and sensor_device_attribute_2. If you don't, it does not really make sense to
> > call _hwmon_update to update the input voltages just to display the limits
> > (which you don't update).
> > 
> 
> I do not want to merge it to one function. I will delete the upate call
> for min and max values.
> 
> > > +#define create_voltage_sysfs(idx)			\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> > > +			show_in, NULL, idx);		\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> > > +			show_min, NULL, idx);		\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> > > +			show_max, NULL, idx);		\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> > > +			show_label, NULL, idx);
> > > +
> > > +create_voltage_sysfs(0);
> > > +create_voltage_sysfs(1);
> > > +create_voltage_sysfs(2);
> > > +create_voltage_sysfs(3);
> > > +create_voltage_sysfs(4);
> > > +
> > > +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> > > +	&sensor_dev_attr_in0_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in0_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in0_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in0_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in1_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in1_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in1_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in1_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in2_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in2_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in2_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in2_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in3_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in3_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in3_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in3_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in4_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in4_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in4_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in4_label.dev_attr.attr,
> > > +	NULL
> > > +};
> > > +
> > > +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> > > +	.attrs = menf21bmc_hwmon_attr_volts,
> > > +};
> > > +
> > > +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> > > +	&menf21bmc_hwmon_attr_group_volts,
> > > +	NULL
> > > +};
> > 
> > Please use the ATTRIBUTE_GROUPS() macro.
> 
> Ok i will use the macro.
> 
> > 
> > > +
> > > +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> > > +{
> > > +	int ret;
> > > +	struct menf21bmc_hwmon *drv_data;
> > > +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > > +	struct device *hwmon_dev;
> > > +
> > > +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> > > +				GFP_KERNEL);
> > > +	if (!drv_data)
> > > +		return -ENOMEM;
> > > +
> > > +	drv_data->i2c_client = i2c_client;
> > > +	platform_set_drvdata(pdev, drv_data);
> > 
> > What is this used for ?
> 
> For the update function. I need to access the drv_data there.
> May this could change, depends on the changes of the update function.

drv_data is passed to the registration function below, which attaches it to the
hwmon device. dev_get_drvdata gets it from the hwmon device, not from the
platform device. I don't see any code which reads drv_data from the platform
device. You might need it if the driver had a remove function, but that is not
the case.

Guenter

> > 
> > > +
> > > +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> > > +	if (ret) {
> > > +		dev_err(&pdev->dev, "failed to read sensor limits");
> > > +		return ret;
> > > +	}
> > > +
> > > +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> > > +							   DEVNAME, drv_data,
> > > +							   menf21bmc_hwmon_groups);
> > > +
> > > +	if (IS_ERR(hwmon_dev))
> > > +		return PTR_ERR(hwmon_dev);
> > > +
> > > +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static struct platform_driver menf21bmc_hwmon = {
> > > +	.probe		= menf21bmc_hwmon_probe,
> > > +	.driver		= {
> > > +		.name		= DEVNAME,
> > > +		.owner		= THIS_MODULE,
> > > +	},
> > > +};
> > > +
> > > +module_platform_driver(menf21bmc_hwmon);
> > > +
> > > +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> > > +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> > > +MODULE_LICENSE("GPL v2");
> > > +MODULE_ALIAS("platform:menf21bmc_hwmon");
> > > -- 
> > > 2.0.4
> > > 
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > 
> 

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

* Re: [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv
@ 2014-08-22  9:02         ` Guenter Roeck
  0 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-22  9:02 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Fri, Aug 22, 2014 at 10:38:11AM +0200, Andreas Werner wrote:
> On Thu, Aug 21, 2014 at 11:37:52AM -0700, Guenter Roeck wrote:
> > On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > > The BMC is a Board Management Controller including monitoring of the
> > > board voltages.
> > > 
> > > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > > ---
> > >  drivers/hwmon/Kconfig           |   7 ++
> > >  drivers/hwmon/Makefile          |   1 +
> > >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 246 insertions(+)
> > >  create mode 100644 drivers/hwmon/menf21bmc_hwmon.c
> > > 
> > > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> > > index 37908ff..437c00f 100644
> > > --- a/drivers/hwmon/Kconfig
> > > +++ b/drivers/hwmon/Kconfig
> > > @@ -828,6 +828,13 @@ config SENSORS_MCP3021
> > >  	  This driver can also be built as a module.  If so, the module
> > >  	  will be called mcp3021.
> > >  
> > > +config SENSORS_MENF21BMC_HWMON
> > > +	tristate "MEN 14F021P00 BMC Hardware Monitoring"
> > > +	depends on MFD_MENF21BMC && I2C
> > > +	help
> > > +	  Say Y here to include support for the MEN 14F021P00 BMC
> > > +	  hardware monitoring.
> > > +
> > >  config SENSORS_ADCXX
> > >  	tristate "National Semiconductor ADCxxxSxxx"
> > >  	depends on SPI_MASTER
> > > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> > > index 1362382..56ab872 100644
> > > --- a/drivers/hwmon/Makefile
> > > +++ b/drivers/hwmon/Makefile
> > > @@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
> > >  obj-$(CONFIG_SENSORS_MAX6697)	+= max6697.o
> > >  obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
> > >  obj-$(CONFIG_SENSORS_MCP3021)	+= mcp3021.o
> > > +obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
> > >  obj-$(CONFIG_SENSORS_NCT6683)	+= nct6683.o
> > >  obj-$(CONFIG_SENSORS_NCT6775)	+= nct6775.o
> > >  obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
> > > diff --git a/drivers/hwmon/menf21bmc_hwmon.c b/drivers/hwmon/menf21bmc_hwmon.c
> > > new file mode 100644
> > > index 0000000..ecb0ef1
> > > --- /dev/null
> > > +++ b/drivers/hwmon/menf21bmc_hwmon.c
> > > @@ -0,0 +1,238 @@
> > > +/*
> > > + *  MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
> > > + *
> > > + *  This is the core hwmon driver of the MEN 14F021P00 BMC.
> > > + *  The BMC monitors the board voltages which can be access with this
> > > + *  driver through sysfs.
> > > + *
> > > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > > + *
> > > + *  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.
> > 
> > The license statement below states GPL v2, which contradicts the statement here.
> > Maybe it should just be GPL below ?
> 
> Why dos it contradict? This is both GPLv2, in the header and in the MODULE_LICENSE
> like i have changed it in the other slave devices and the mfd.
> 
Ok, your call.

> > 
> > > + */
> > > +
> > > +#include <linux/module.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/hwmon.h>
> > > +#include <linux/hwmon-sysfs.h>
> > > +#include <linux/jiffies.h>
> > > +#include <linux/slab.h>
> > > +#include <linux/i2c.h>
> > > +
> > > +#define DEVNAME "menf21bmc_hwmon"
> > > +
> > While that makes sense for the driver name, it doesn't really for the hwmon
> > device. You might want to consider just using "menf21bmc" when you register the
> > hwmon device.
> >
> 
> menf21bmc is the name of the MFD driver. This name is to distinguish each of
> the slaves. For that the name represent that this device is a slave of "menf21bmc"
> and a "hwmon" of its own.
>  
Yes, but that doesn' mean that the name registered with the hwmon subsystem has
to have "hwmon" in it; this is independent of the driver name. That is still
redundant. Anyway, your driver, your call.

> > > +#define BMC_VOLT_COUNT	5
> > > +#define MENF21BMC_V33	0
> > > +#define MENF21BMC_V5	1
> > > +#define MENF21BMC_V12	2
> > > +#define MENF21BMC_V5_SB	3
> > > +#define MENF21BMC_VBAT	4
> > > +
> > > +#define BMC_CMD_GET_NUM_VOLT 0x8E
> > > +#define IDX_TO_VOLT_MIN_CMD(idx) (0x40 + idx)
> > > +#define IDX_TO_VOLT_MAX_CMD(idx) (0x50 + idx)
> > > +#define IDX_TO_VOLT_INP_CMD(idx) (0x60 + idx)
> > > +
> > > +struct menf21bmc_hwmon {
> > > +	char valid;
> > > +	struct i2c_client *i2c_client;
> > > +	unsigned long last_update;
> > > +	u16 in_val[BMC_VOLT_COUNT];
> > > +	u16 in_min[BMC_VOLT_COUNT];
> > > +	u16 in_max[BMC_VOLT_COUNT];
> > > +};
> > > +
> > > +static const char *const input_names[] = {
> > > +	[MENF21BMC_V33]		= "MON_3,3V",
> > > +	[MENF21BMC_V5]		= "MON_5V",
> > > +	[MENF21BMC_V12]		= "MON_12V",
> > > +	[MENF21BMC_V5_SB]	= "5V_STANDBY",
> > > +	[MENF21BMC_VBAT]	= "VBAT"
> > > +};
> > > +
> > > +static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
> > > +{
> > > +	int i;
> > > +	uint16_t val;
> > > +	struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
> > > +	struct menf21bmc_hwmon *data_ret = drv_data;
> > > +
> > > +	if (time_after(jiffies, drv_data->last_update + HZ) || !drv_data->valid) {
> > > +		for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > > +			val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > > +						       IDX_TO_VOLT_INP_CMD(i));
> > > +			if (val < 0)
> > > +				goto abort;
> > 
> > I don't really see the point here. You ignore the return value,
> > yet you abort reading further values. The caller will assume that there was no
> > error even though the values in in_val were either never initialized or are out
> > of date.
> > 
> 
> Argh thats true.
> I have checked out some other drivers and they just read the value from the 
> i2c bus and save the value into the struct without error checking.
> Is that the normal way?
> If yes then the caller hast to check if the value is a correct voltage value.

You have a number of options: Ignore the error, but consistently. Not a good
idea, not done by recent drivers, but if you think your chip never reports an
error fine with me. Abort if an error occurs, and return the error code from the
function. Store the error in the data, and check the data for error in the
calling code.

My personal preference would be to return an error code from the function (with
PTR_ERR) and check it in the calling code (with ERR_PTR), but it is really your
call.

> 
> The other way what i see is to read the value, check if there is no error and then
> save the new value to the struct. If there is an error during read then we just
> do not update the value and let it as it is.

This is akin to ignoring errors. Again, I don't think this would be a good idea,
but it is your call to make.

> If I go this way then i do not need the second struct as the return value.
> 
> > > +
> > > +			drv_data->in_val[i] = val;
> > > +		}
> > > +		drv_data->last_update = jiffies;
> > > +		drv_data->valid = 1;
> > > +	}
> > > +abort:
> > > +	return data_ret;
> > 
> > At the same time you do have a separate variable to return.
> > One of those doesn't make sense.
> > If the idea was to return an error in data_ret, you would have to assign it
> > accordingly, and check in the calling code if there was an error or not.
> 
> Will be changed, see above.
> 
> > 
> > > +}
> > > +
> > > +static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
> > > +{
> > > +	int i;
> > > +	uint16_t val;
> > > +
> > > +	for (i = 0; i < BMC_VOLT_COUNT; i++) {
> > > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > > +					       IDX_TO_VOLT_MIN_CMD(i));
> > > +		if (val < 0)
> > > +			return val;
> > > +
> > > +		drv_data->in_min[i] = val;
> > > +
> > > +		val = i2c_smbus_read_word_data(drv_data->i2c_client,
> > > +					       IDX_TO_VOLT_MAX_CMD(i));
> > > +		if (val < 0)
> > > +			return val;
> > > +
> > > +		drv_data->in_max[i] = val;
> > > +	}
> > > +	return 0;
> > > +}
> > > +
> > > +static ssize_t
> > > +show_label(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +
> > > +	return sprintf(buf, "%s\n", input_names[attr->index]);
> > > +}
> > > +
> > > +static ssize_t
> > > +show_in(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	uint16_t val;
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > > +
> > > +	val = drv_data->in_val[attr->index];
> > > +	return sprintf(buf, "%d\n", val);
> > > +}
> > > +
> > > +static ssize_t
> > > +show_min(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > > +
> > > +	return sprintf(buf, "%d\n", drv_data->in_min[attr->index]);
> > > +}
> > > +
> > > +static ssize_t
> > > +show_max(struct device *dev, struct device_attribute *devattr, char *buf)
> > > +{
> > > +	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
> > > +	struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
> > > +
> > > +	return sprintf(buf, "%d\n", drv_data->in_max[attr->index]);
> > > +}
> > > +
> > You could merge all the above functions into one by using a dual-indexed array
> > and sensor_device_attribute_2. If you don't, it does not really make sense to
> > call _hwmon_update to update the input voltages just to display the limits
> > (which you don't update).
> > 
> 
> I do not want to merge it to one function. I will delete the upate call
> for min and max values.
> 
> > > +#define create_voltage_sysfs(idx)			\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_input, S_IRUGO,	\
> > > +			show_in, NULL, idx);		\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_min, S_IRUGO,	\
> > > +			show_min, NULL, idx);		\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_max, S_IRUGO,	\
> > > +			show_max, NULL, idx);		\
> > > +static SENSOR_DEVICE_ATTR(in##idx##_label, S_IRUGO,	\
> > > +			show_label, NULL, idx);
> > > +
> > > +create_voltage_sysfs(0);
> > > +create_voltage_sysfs(1);
> > > +create_voltage_sysfs(2);
> > > +create_voltage_sysfs(3);
> > > +create_voltage_sysfs(4);
> > > +
> > > +static struct attribute *menf21bmc_hwmon_attr_volts[] = {
> > > +	&sensor_dev_attr_in0_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in0_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in0_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in0_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in1_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in1_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in1_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in1_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in2_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in2_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in2_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in2_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in3_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in3_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in3_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in3_label.dev_attr.attr,
> > > +
> > > +	&sensor_dev_attr_in4_input.dev_attr.attr,
> > > +	&sensor_dev_attr_in4_min.dev_attr.attr,
> > > +	&sensor_dev_attr_in4_max.dev_attr.attr,
> > > +	&sensor_dev_attr_in4_label.dev_attr.attr,
> > > +	NULL
> > > +};
> > > +
> > > +static const struct attribute_group menf21bmc_hwmon_attr_group_volts = {
> > > +	.attrs = menf21bmc_hwmon_attr_volts,
> > > +};
> > > +
> > > +static const struct attribute_group *menf21bmc_hwmon_groups[] = {
> > > +	&menf21bmc_hwmon_attr_group_volts,
> > > +	NULL
> > > +};
> > 
> > Please use the ATTRIBUTE_GROUPS() macro.
> 
> Ok i will use the macro.
> 
> > 
> > > +
> > > +static int menf21bmc_hwmon_probe(struct platform_device *pdev)
> > > +{
> > > +	int ret;
> > > +	struct menf21bmc_hwmon *drv_data;
> > > +	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > > +	struct device *hwmon_dev;
> > > +
> > > +	drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_hwmon),
> > > +				GFP_KERNEL);
> > > +	if (!drv_data)
> > > +		return -ENOMEM;
> > > +
> > > +	drv_data->i2c_client = i2c_client;
> > > +	platform_set_drvdata(pdev, drv_data);
> > 
> > What is this used for ?
> 
> For the update function. I need to access the drv_data there.
> May this could change, depends on the changes of the update function.

drv_data is passed to the registration function below, which attaches it to the
hwmon device. dev_get_drvdata gets it from the hwmon device, not from the
platform device. I don't see any code which reads drv_data from the platform
device. You might need it if the driver had a remove function, but that is not
the case.

Guenter

> > 
> > > +
> > > +	ret = menf21bmc_hwmon_get_volt_limits(drv_data);
> > > +	if (ret) {
> > > +		dev_err(&pdev->dev, "failed to read sensor limits");
> > > +		return ret;
> > > +	}
> > > +
> > > +	hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
> > > +							   DEVNAME, drv_data,
> > > +							   menf21bmc_hwmon_groups);
> > > +
> > > +	if (IS_ERR(hwmon_dev))
> > > +		return PTR_ERR(hwmon_dev);
> > > +
> > > +	dev_info(&pdev->dev, "MEN 14F021P00 BMC hwmon device enabled");
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static struct platform_driver menf21bmc_hwmon = {
> > > +	.probe		= menf21bmc_hwmon_probe,
> > > +	.driver		= {
> > > +		.name		= DEVNAME,
> > > +		.owner		= THIS_MODULE,
> > > +	},
> > > +};
> > > +
> > > +module_platform_driver(menf21bmc_hwmon);
> > > +
> > > +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> > > +MODULE_DESCRIPTION("MEN 14F021P00 BMC hwmon");
> > > +MODULE_LICENSE("GPL v2");
> > > +MODULE_ALIAS("platform:menf21bmc_hwmon");
> > > -- 
> > > 2.0.4
> > > 
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > 
> 

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver
  2014-08-22  8:39       ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
@ 2014-08-22  9:04         ` Guenter Roeck
  -1 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-22  9:04 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Fri, Aug 22, 2014 at 10:39:31AM +0200, Andreas Werner wrote:
> On Thu, Aug 21, 2014 at 11:45:01AM -0700, Guenter Roeck wrote:
> > On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > > The BMC is a Board Management Controller including monitoring of the
> > > board voltages.
> > > 
> > > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > > ---
> > >  drivers/hwmon/Kconfig           |   7 ++
> > >  drivers/hwmon/Makefile          |   1 +
> > >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> > 
> > Forgot: Please also provide Documentation/hwmon/menf21bmc.
> > 
> 
> Did not know that i have to do it.
> But you are right it is good to have one.
> 
Documentation/hwmon/submitting-patches is quite useful.

Thanks,
Guenter

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

* Re: [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv
@ 2014-08-22  9:04         ` Guenter Roeck
  0 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-22  9:04 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, jdelvare, lm-sensors

On Fri, Aug 22, 2014 at 10:39:31AM +0200, Andreas Werner wrote:
> On Thu, Aug 21, 2014 at 11:45:01AM -0700, Guenter Roeck wrote:
> > On Wed, Aug 13, 2014 at 10:40:37AM +0200, Andreas Werner wrote:
> > > Added driver to support the 14F021P00 BMC Hardware Monitoring.
> > > The BMC is a Board Management Controller including monitoring of the
> > > board voltages.
> > > 
> > > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > > ---
> > >  drivers/hwmon/Kconfig           |   7 ++
> > >  drivers/hwmon/Makefile          |   1 +
> > >  drivers/hwmon/menf21bmc_hwmon.c | 238 ++++++++++++++++++++++++++++++++++++++++
> > 
> > Forgot: Please also provide Documentation/hwmon/menf21bmc.
> > 
> 
> Did not know that i have to do it.
> But you are right it is good to have one.
> 
Documentation/hwmon/submitting-patches is quite useful.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  2014-08-13  8:40   ` Andreas Werner
@ 2014-08-25 18:53     ` Bryan Wu
  -1 siblings, 0 replies; 45+ messages in thread
From: Bryan Wu @ 2014-08-25 18:53 UTC (permalink / raw)
  To: Andreas Werner
  Cc: lkml, Samuel Ortiz, Lee Jones, wim, linux-watchdog,
	rpurdie@rpsys.net, Linux LED Subsystem, Jean Delvare, linux,
	lm-sensors

On Wed, Aug 13, 2014 at 1:40 AM, Andreas Werner <andreas.werner@men.de> wrote:
> Added driver to support the 14F021P00 BMC LEDs.
> The BMC is a Board Management Controller including four LEDs which
> can be switched on and off.
>
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/leds/Kconfig          |   6 ++
>  drivers/leds/Makefile         |   1 +
>  drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 138 insertions(+)
>  create mode 100644 drivers/leds/leds-menf21bmc.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 27cf0cd..d38ff3f 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -458,6 +458,12 @@ config LEDS_OT200
>           This option enables support for the LEDs on the Bachmann OT200.
>           Say Y to enable LEDs on the Bachmann OT200.
>
> +config LEDS_MENF21BMC
> +       tristate "LED support for the MEN 14F021P00 BMC"
> +       depends on LEDS_CLASS && MFD_MENF21BMC
> +       help
> +         Say Y here to include support for the MEN 14F021P00 BMC LEDs.
> +
>  comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
>
>  config LEDS_BLINKM
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 3c03666..cadc433 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)            += leds-max8997.o
>  obj-$(CONFIG_LEDS_LM355x)              += leds-lm355x.o
>  obj-$(CONFIG_LEDS_BLINKM)              += leds-blinkm.o
>  obj-$(CONFIG_LEDS_VERSATILE)           += leds-versatile.o
> +obj-$(CONFIG_LEDS_MENF21BMC)           += leds-menf21bmc.o
>
>  # LED SPI Drivers
>  obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
> diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
> new file mode 100644
> index 0000000..4621f72
> --- /dev/null
> +++ b/drivers/leds/leds-menf21bmc.c
> @@ -0,0 +1,131 @@
> +/*
> + *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
> + *
> + *  This is the core LED driver of the MEN 14F021P00 BMC.
> + *  There are four LEDs available which can be switched on and off.
> + *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
> + *
> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> + *
> + *  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 <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/leds.h>
> +#include <linux/i2c.h>
> +
> +#define BMC_CMD_LED_GET_SET    0xA0
> +#define BMC_BIT_LED_STATUS     BIT(0)
> +#define BMC_BIT_LED_HOTSWAP    BIT(1)
> +#define BMC_BIT_LED_USER1      BIT(2)
> +#define BMC_BIT_LED_USER2      BIT(3)
> +
> +struct menf21bmc_led {
> +       struct led_classdev cdev;
> +       u8 led_bit;
> +       const char *name;
> +       struct i2c_client *i2c_client;
> +};
> +
> +static struct menf21bmc_led leds[] = {
> +       {
> +               .name = "menf21bmc:led_status",
> +               .led_bit = BMC_BIT_LED_STATUS,
> +       },
> +       {
> +               .name = "menf21bmc:led_hotswap",
> +               .led_bit = BMC_BIT_LED_HOTSWAP,
> +       },
> +       {
> +               .name = "menf21bmc:led_user1",
> +               .led_bit = BMC_BIT_LED_USER1,
> +       },
> +       {
> +               .name = "menf21bmc:led_user2",
> +               .led_bit = BMC_BIT_LED_USER2,
> +       }
> +};
> +
> +static DEFINE_MUTEX(led_lock);
> +
> +static void
> +menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
> +{
> +       int led_val;
> +       struct menf21bmc_led *led = container_of(led_cdev,
> +                                       struct menf21bmc_led, cdev);
> +
> +       mutex_lock(&led_lock);
> +       led_val = i2c_smbus_read_byte_data(led->i2c_client,
> +                                               BMC_CMD_LED_GET_SET);
> +       if (led_val < 0)
> +               goto err_out;
> +
> +       if (value == LED_OFF)
> +               led_val &= ~led->led_bit;
> +       else
> +               led_val |= led->led_bit;
> +
> +       i2c_smbus_write_byte_data(led->i2c_client,
> +                                       BMC_CMD_LED_GET_SET, led_val);
> +err_out:
> +       mutex_unlock(&led_lock);
> +}
> +
> +static int menf21bmc_led_probe(struct platform_device *pdev)
> +{
> +       int i;
> +       int ret;
> +       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> +
> +       for (i = 0; i < ARRAY_SIZE(leds); i++) {
> +               leds[i].cdev.name = leds[i].name;
> +               leds[i].cdev.brightness_set = menf21bmc_led_set;
> +               leds[i].i2c_client = i2c_client;
> +               ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
> +               if (ret < 0)
> +                       goto err_free_leds;
> +       }
> +       dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
> +
> +       return 0;
> +
> +err_free_leds:
> +       dev_err(&pdev->dev, "failed to register LED device\n");
> +
> +       for (i = i - 1; i >= 0; i--)
> +               led_classdev_unregister(&leds[i].cdev);
> +
> +       return ret;
> +}
> +
> +static int menf21bmc_led_remove(struct platform_device *pdev)
> +{
> +       int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(leds); i++)
> +               led_classdev_unregister(&leds[i].cdev);
> +
> +       return 0;
> +}
> +
> +static struct platform_driver menf21bmc_led = {
> +       .probe          = menf21bmc_led_probe,
> +       .remove         = menf21bmc_led_remove,
> +       .driver         = {
> +               .name           = "menf21bmc_led",
> +               .owner          = THIS_MODULE,
> +       },
> +};
> +

I still think this driver should be an I2C driver which is simply than
a platform driver.
Did I miss some discussion about this in our email?

Thanks,
-Bryan

> +module_platform_driver(menf21bmc_led);
> +
> +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> +MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:menf21bmc_led");
> --
> 2.0.4
>

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

* Re: [lm-sensors] [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
@ 2014-08-25 18:53     ` Bryan Wu
  0 siblings, 0 replies; 45+ messages in thread
From: Bryan Wu @ 2014-08-25 18:53 UTC (permalink / raw)
  To: Andreas Werner
  Cc: lkml, Samuel Ortiz, Lee Jones, wim, linux-watchdog,
	rpurdie@rpsys.net, Linux LED Subsystem, Jean Delvare, linux,
	lm-sensors

On Wed, Aug 13, 2014 at 1:40 AM, Andreas Werner <andreas.werner@men.de> wrote:
> Added driver to support the 14F021P00 BMC LEDs.
> The BMC is a Board Management Controller including four LEDs which
> can be switched on and off.
>
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>  drivers/leds/Kconfig          |   6 ++
>  drivers/leds/Makefile         |   1 +
>  drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 138 insertions(+)
>  create mode 100644 drivers/leds/leds-menf21bmc.c
>
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 27cf0cd..d38ff3f 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -458,6 +458,12 @@ config LEDS_OT200
>           This option enables support for the LEDs on the Bachmann OT200.
>           Say Y to enable LEDs on the Bachmann OT200.
>
> +config LEDS_MENF21BMC
> +       tristate "LED support for the MEN 14F021P00 BMC"
> +       depends on LEDS_CLASS && MFD_MENF21BMC
> +       help
> +         Say Y here to include support for the MEN 14F021P00 BMC LEDs.
> +
>  comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
>
>  config LEDS_BLINKM
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 3c03666..cadc433 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)            += leds-max8997.o
>  obj-$(CONFIG_LEDS_LM355x)              += leds-lm355x.o
>  obj-$(CONFIG_LEDS_BLINKM)              += leds-blinkm.o
>  obj-$(CONFIG_LEDS_VERSATILE)           += leds-versatile.o
> +obj-$(CONFIG_LEDS_MENF21BMC)           += leds-menf21bmc.o
>
>  # LED SPI Drivers
>  obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
> diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
> new file mode 100644
> index 0000000..4621f72
> --- /dev/null
> +++ b/drivers/leds/leds-menf21bmc.c
> @@ -0,0 +1,131 @@
> +/*
> + *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
> + *
> + *  This is the core LED driver of the MEN 14F021P00 BMC.
> + *  There are four LEDs available which can be switched on and off.
> + *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
> + *
> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> + *
> + *  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 <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/leds.h>
> +#include <linux/i2c.h>
> +
> +#define BMC_CMD_LED_GET_SET    0xA0
> +#define BMC_BIT_LED_STATUS     BIT(0)
> +#define BMC_BIT_LED_HOTSWAP    BIT(1)
> +#define BMC_BIT_LED_USER1      BIT(2)
> +#define BMC_BIT_LED_USER2      BIT(3)
> +
> +struct menf21bmc_led {
> +       struct led_classdev cdev;
> +       u8 led_bit;
> +       const char *name;
> +       struct i2c_client *i2c_client;
> +};
> +
> +static struct menf21bmc_led leds[] = {
> +       {
> +               .name = "menf21bmc:led_status",
> +               .led_bit = BMC_BIT_LED_STATUS,
> +       },
> +       {
> +               .name = "menf21bmc:led_hotswap",
> +               .led_bit = BMC_BIT_LED_HOTSWAP,
> +       },
> +       {
> +               .name = "menf21bmc:led_user1",
> +               .led_bit = BMC_BIT_LED_USER1,
> +       },
> +       {
> +               .name = "menf21bmc:led_user2",
> +               .led_bit = BMC_BIT_LED_USER2,
> +       }
> +};
> +
> +static DEFINE_MUTEX(led_lock);
> +
> +static void
> +menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
> +{
> +       int led_val;
> +       struct menf21bmc_led *led = container_of(led_cdev,
> +                                       struct menf21bmc_led, cdev);
> +
> +       mutex_lock(&led_lock);
> +       led_val = i2c_smbus_read_byte_data(led->i2c_client,
> +                                               BMC_CMD_LED_GET_SET);
> +       if (led_val < 0)
> +               goto err_out;
> +
> +       if (value = LED_OFF)
> +               led_val &= ~led->led_bit;
> +       else
> +               led_val |= led->led_bit;
> +
> +       i2c_smbus_write_byte_data(led->i2c_client,
> +                                       BMC_CMD_LED_GET_SET, led_val);
> +err_out:
> +       mutex_unlock(&led_lock);
> +}
> +
> +static int menf21bmc_led_probe(struct platform_device *pdev)
> +{
> +       int i;
> +       int ret;
> +       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> +
> +       for (i = 0; i < ARRAY_SIZE(leds); i++) {
> +               leds[i].cdev.name = leds[i].name;
> +               leds[i].cdev.brightness_set = menf21bmc_led_set;
> +               leds[i].i2c_client = i2c_client;
> +               ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
> +               if (ret < 0)
> +                       goto err_free_leds;
> +       }
> +       dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
> +
> +       return 0;
> +
> +err_free_leds:
> +       dev_err(&pdev->dev, "failed to register LED device\n");
> +
> +       for (i = i - 1; i >= 0; i--)
> +               led_classdev_unregister(&leds[i].cdev);
> +
> +       return ret;
> +}
> +
> +static int menf21bmc_led_remove(struct platform_device *pdev)
> +{
> +       int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(leds); i++)
> +               led_classdev_unregister(&leds[i].cdev);
> +
> +       return 0;
> +}
> +
> +static struct platform_driver menf21bmc_led = {
> +       .probe          = menf21bmc_led_probe,
> +       .remove         = menf21bmc_led_remove,
> +       .driver         = {
> +               .name           = "menf21bmc_led",
> +               .owner          = THIS_MODULE,
> +       },
> +};
> +

I still think this driver should be an I2C driver which is simply than
a platform driver.
Did I miss some discussion about this in our email?

Thanks,
-Bryan

> +module_platform_driver(menf21bmc_led);
> +
> +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> +MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:menf21bmc_led");
> --
> 2.0.4
>

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  2014-08-25 18:53     ` [lm-sensors] " Bryan Wu
@ 2014-08-25 19:05       ` Guenter Roeck
  -1 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-25 19:05 UTC (permalink / raw)
  To: Bryan Wu
  Cc: Andreas Werner, lkml, Samuel Ortiz, Lee Jones, wim,
	linux-watchdog, rpurdie@rpsys.net, Linux LED Subsystem,
	Jean Delvare, lm-sensors

On Mon, Aug 25, 2014 at 11:53:32AM -0700, Bryan Wu wrote:
> On Wed, Aug 13, 2014 at 1:40 AM, Andreas Werner <andreas.werner@men.de> wrote:
> > Added driver to support the 14F021P00 BMC LEDs.
> > The BMC is a Board Management Controller including four LEDs which
> > can be switched on and off.
> >
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/leds/Kconfig          |   6 ++
> >  drivers/leds/Makefile         |   1 +
> >  drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 138 insertions(+)
> >  create mode 100644 drivers/leds/leds-menf21bmc.c
> >
> > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> > index 27cf0cd..d38ff3f 100644
> > --- a/drivers/leds/Kconfig
> > +++ b/drivers/leds/Kconfig
> > @@ -458,6 +458,12 @@ config LEDS_OT200
> >           This option enables support for the LEDs on the Bachmann OT200.
> >           Say Y to enable LEDs on the Bachmann OT200.
> >
> > +config LEDS_MENF21BMC
> > +       tristate "LED support for the MEN 14F021P00 BMC"
> > +       depends on LEDS_CLASS && MFD_MENF21BMC
> > +       help
> > +         Say Y here to include support for the MEN 14F021P00 BMC LEDs.
> > +
> >  comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
> >
> >  config LEDS_BLINKM
> > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> > index 3c03666..cadc433 100644
> > --- a/drivers/leds/Makefile
> > +++ b/drivers/leds/Makefile
> > @@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)            += leds-max8997.o
> >  obj-$(CONFIG_LEDS_LM355x)              += leds-lm355x.o
> >  obj-$(CONFIG_LEDS_BLINKM)              += leds-blinkm.o
> >  obj-$(CONFIG_LEDS_VERSATILE)           += leds-versatile.o
> > +obj-$(CONFIG_LEDS_MENF21BMC)           += leds-menf21bmc.o
> >
> >  # LED SPI Drivers
> >  obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
> > diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
> > new file mode 100644
> > index 0000000..4621f72
> > --- /dev/null
> > +++ b/drivers/leds/leds-menf21bmc.c
> > @@ -0,0 +1,131 @@
> > +/*
> > + *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
> > + *
> > + *  This is the core LED driver of the MEN 14F021P00 BMC.
> > + *  There are four LEDs available which can be switched on and off.
> > + *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
> > + *
> > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > + *
> > + *  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 <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/leds.h>
> > +#include <linux/i2c.h>
> > +
> > +#define BMC_CMD_LED_GET_SET    0xA0
> > +#define BMC_BIT_LED_STATUS     BIT(0)
> > +#define BMC_BIT_LED_HOTSWAP    BIT(1)
> > +#define BMC_BIT_LED_USER1      BIT(2)
> > +#define BMC_BIT_LED_USER2      BIT(3)
> > +
> > +struct menf21bmc_led {
> > +       struct led_classdev cdev;
> > +       u8 led_bit;
> > +       const char *name;
> > +       struct i2c_client *i2c_client;
> > +};
> > +
> > +static struct menf21bmc_led leds[] = {
> > +       {
> > +               .name = "menf21bmc:led_status",
> > +               .led_bit = BMC_BIT_LED_STATUS,
> > +       },
> > +       {
> > +               .name = "menf21bmc:led_hotswap",
> > +               .led_bit = BMC_BIT_LED_HOTSWAP,
> > +       },
> > +       {
> > +               .name = "menf21bmc:led_user1",
> > +               .led_bit = BMC_BIT_LED_USER1,
> > +       },
> > +       {
> > +               .name = "menf21bmc:led_user2",
> > +               .led_bit = BMC_BIT_LED_USER2,
> > +       }
> > +};
> > +
> > +static DEFINE_MUTEX(led_lock);
> > +
> > +static void
> > +menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
> > +{
> > +       int led_val;
> > +       struct menf21bmc_led *led = container_of(led_cdev,
> > +                                       struct menf21bmc_led, cdev);
> > +
> > +       mutex_lock(&led_lock);
> > +       led_val = i2c_smbus_read_byte_data(led->i2c_client,
> > +                                               BMC_CMD_LED_GET_SET);
> > +       if (led_val < 0)
> > +               goto err_out;
> > +
> > +       if (value == LED_OFF)
> > +               led_val &= ~led->led_bit;
> > +       else
> > +               led_val |= led->led_bit;
> > +
> > +       i2c_smbus_write_byte_data(led->i2c_client,
> > +                                       BMC_CMD_LED_GET_SET, led_val);
> > +err_out:
> > +       mutex_unlock(&led_lock);
> > +}
> > +
> > +static int menf21bmc_led_probe(struct platform_device *pdev)
> > +{
> > +       int i;
> > +       int ret;
> > +       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > +
> > +       for (i = 0; i < ARRAY_SIZE(leds); i++) {
> > +               leds[i].cdev.name = leds[i].name;
> > +               leds[i].cdev.brightness_set = menf21bmc_led_set;
> > +               leds[i].i2c_client = i2c_client;
> > +               ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
> > +               if (ret < 0)
> > +                       goto err_free_leds;
> > +       }
> > +       dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
> > +
> > +       return 0;
> > +
> > +err_free_leds:
> > +       dev_err(&pdev->dev, "failed to register LED device\n");
> > +
> > +       for (i = i - 1; i >= 0; i--)
> > +               led_classdev_unregister(&leds[i].cdev);
> > +
> > +       return ret;
> > +}
> > +
> > +static int menf21bmc_led_remove(struct platform_device *pdev)
> > +{
> > +       int i;
> > +
> > +       for (i = 0; i < ARRAY_SIZE(leds); i++)
> > +               led_classdev_unregister(&leds[i].cdev);
> > +
> > +       return 0;
> > +}
> > +
> > +static struct platform_driver menf21bmc_led = {
> > +       .probe          = menf21bmc_led_probe,
> > +       .remove         = menf21bmc_led_remove,
> > +       .driver         = {
> > +               .name           = "menf21bmc_led",
> > +               .owner          = THIS_MODULE,
> > +       },
> > +};
> > +
> 
> I still think this driver should be an I2C driver which is simply than
> a platform driver.
> Did I miss some discussion about this in our email?
> 
It is not possible to instantiate multiple drivers (watchdog, hwmon, led
in this case) with a single i2c chip.

Thanks,
Guenter

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

* Re: [lm-sensors] [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
@ 2014-08-25 19:05       ` Guenter Roeck
  0 siblings, 0 replies; 45+ messages in thread
From: Guenter Roeck @ 2014-08-25 19:05 UTC (permalink / raw)
  To: Bryan Wu
  Cc: Andreas Werner, lkml, Samuel Ortiz, Lee Jones, wim,
	linux-watchdog, rpurdie@rpsys.net, Linux LED Subsystem,
	Jean Delvare, lm-sensors

On Mon, Aug 25, 2014 at 11:53:32AM -0700, Bryan Wu wrote:
> On Wed, Aug 13, 2014 at 1:40 AM, Andreas Werner <andreas.werner@men.de> wrote:
> > Added driver to support the 14F021P00 BMC LEDs.
> > The BMC is a Board Management Controller including four LEDs which
> > can be switched on and off.
> >
> > Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > ---
> >  drivers/leds/Kconfig          |   6 ++
> >  drivers/leds/Makefile         |   1 +
> >  drivers/leds/leds-menf21bmc.c | 131 ++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 138 insertions(+)
> >  create mode 100644 drivers/leds/leds-menf21bmc.c
> >
> > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> > index 27cf0cd..d38ff3f 100644
> > --- a/drivers/leds/Kconfig
> > +++ b/drivers/leds/Kconfig
> > @@ -458,6 +458,12 @@ config LEDS_OT200
> >           This option enables support for the LEDs on the Bachmann OT200.
> >           Say Y to enable LEDs on the Bachmann OT200.
> >
> > +config LEDS_MENF21BMC
> > +       tristate "LED support for the MEN 14F021P00 BMC"
> > +       depends on LEDS_CLASS && MFD_MENF21BMC
> > +       help
> > +         Say Y here to include support for the MEN 14F021P00 BMC LEDs.
> > +
> >  comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)"
> >
> >  config LEDS_BLINKM
> > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> > index 3c03666..cadc433 100644
> > --- a/drivers/leds/Makefile
> > +++ b/drivers/leds/Makefile
> > @@ -53,6 +53,7 @@ obj-$(CONFIG_LEDS_MAX8997)            += leds-max8997.o
> >  obj-$(CONFIG_LEDS_LM355x)              += leds-lm355x.o
> >  obj-$(CONFIG_LEDS_BLINKM)              += leds-blinkm.o
> >  obj-$(CONFIG_LEDS_VERSATILE)           += leds-versatile.o
> > +obj-$(CONFIG_LEDS_MENF21BMC)           += leds-menf21bmc.o
> >
> >  # LED SPI Drivers
> >  obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
> > diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
> > new file mode 100644
> > index 0000000..4621f72
> > --- /dev/null
> > +++ b/drivers/leds/leds-menf21bmc.c
> > @@ -0,0 +1,131 @@
> > +/*
> > + *  MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
> > + *
> > + *  This is the core LED driver of the MEN 14F021P00 BMC.
> > + *  There are four LEDs available which can be switched on and off.
> > + *  STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
> > + *
> > + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > + *
> > + *  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 <linux/module.h>
> > +#include <linux/kernel.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/leds.h>
> > +#include <linux/i2c.h>
> > +
> > +#define BMC_CMD_LED_GET_SET    0xA0
> > +#define BMC_BIT_LED_STATUS     BIT(0)
> > +#define BMC_BIT_LED_HOTSWAP    BIT(1)
> > +#define BMC_BIT_LED_USER1      BIT(2)
> > +#define BMC_BIT_LED_USER2      BIT(3)
> > +
> > +struct menf21bmc_led {
> > +       struct led_classdev cdev;
> > +       u8 led_bit;
> > +       const char *name;
> > +       struct i2c_client *i2c_client;
> > +};
> > +
> > +static struct menf21bmc_led leds[] = {
> > +       {
> > +               .name = "menf21bmc:led_status",
> > +               .led_bit = BMC_BIT_LED_STATUS,
> > +       },
> > +       {
> > +               .name = "menf21bmc:led_hotswap",
> > +               .led_bit = BMC_BIT_LED_HOTSWAP,
> > +       },
> > +       {
> > +               .name = "menf21bmc:led_user1",
> > +               .led_bit = BMC_BIT_LED_USER1,
> > +       },
> > +       {
> > +               .name = "menf21bmc:led_user2",
> > +               .led_bit = BMC_BIT_LED_USER2,
> > +       }
> > +};
> > +
> > +static DEFINE_MUTEX(led_lock);
> > +
> > +static void
> > +menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
> > +{
> > +       int led_val;
> > +       struct menf21bmc_led *led = container_of(led_cdev,
> > +                                       struct menf21bmc_led, cdev);
> > +
> > +       mutex_lock(&led_lock);
> > +       led_val = i2c_smbus_read_byte_data(led->i2c_client,
> > +                                               BMC_CMD_LED_GET_SET);
> > +       if (led_val < 0)
> > +               goto err_out;
> > +
> > +       if (value = LED_OFF)
> > +               led_val &= ~led->led_bit;
> > +       else
> > +               led_val |= led->led_bit;
> > +
> > +       i2c_smbus_write_byte_data(led->i2c_client,
> > +                                       BMC_CMD_LED_GET_SET, led_val);
> > +err_out:
> > +       mutex_unlock(&led_lock);
> > +}
> > +
> > +static int menf21bmc_led_probe(struct platform_device *pdev)
> > +{
> > +       int i;
> > +       int ret;
> > +       struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
> > +
> > +       for (i = 0; i < ARRAY_SIZE(leds); i++) {
> > +               leds[i].cdev.name = leds[i].name;
> > +               leds[i].cdev.brightness_set = menf21bmc_led_set;
> > +               leds[i].i2c_client = i2c_client;
> > +               ret = led_classdev_register(&pdev->dev, &leds[i].cdev);
> > +               if (ret < 0)
> > +                       goto err_free_leds;
> > +       }
> > +       dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
> > +
> > +       return 0;
> > +
> > +err_free_leds:
> > +       dev_err(&pdev->dev, "failed to register LED device\n");
> > +
> > +       for (i = i - 1; i >= 0; i--)
> > +               led_classdev_unregister(&leds[i].cdev);
> > +
> > +       return ret;
> > +}
> > +
> > +static int menf21bmc_led_remove(struct platform_device *pdev)
> > +{
> > +       int i;
> > +
> > +       for (i = 0; i < ARRAY_SIZE(leds); i++)
> > +               led_classdev_unregister(&leds[i].cdev);
> > +
> > +       return 0;
> > +}
> > +
> > +static struct platform_driver menf21bmc_led = {
> > +       .probe          = menf21bmc_led_probe,
> > +       .remove         = menf21bmc_led_remove,
> > +       .driver         = {
> > +               .name           = "menf21bmc_led",
> > +               .owner          = THIS_MODULE,
> > +       },
> > +};
> > +
> 
> I still think this driver should be an I2C driver which is simply than
> a platform driver.
> Did I miss some discussion about this in our email?
> 
It is not possible to instantiate multiple drivers (watchdog, hwmon, led
in this case) with a single i2c chip.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

end of thread, other threads:[~2014-08-25 19:06 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-13  8:38 [PATCH v4 0/4] Introduce MEN 14F021P BMC driver series Andreas Werner
2014-08-13  8:38 ` [lm-sensors] " Andreas Werner
2014-08-13  8:38 ` Andreas Werner
2014-08-13  8:39 ` [PATCH v4 1/4] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver Andreas Werner
2014-08-13  8:39   ` [lm-sensors] " Andreas Werner
2014-08-13  8:39   ` Andreas Werner
2014-08-21 11:30   ` Lee Jones
2014-08-21 11:30     ` [lm-sensors] " Lee Jones
2014-08-21 11:30     ` Lee Jones
2014-08-21 13:57     ` Andreas Werner
2014-08-21 13:57       ` Andreas Werner
2014-08-21 13:57       ` [lm-sensors] " Andreas Werner
2014-08-21 13:57       ` Andreas Werner
2014-08-21 13:25       ` Lee Jones
2014-08-21 13:25         ` [lm-sensors] " Lee Jones
2014-08-21 13:25         ` Lee Jones
2014-08-13  8:39 ` [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog driver Andreas Werner
2014-08-13  8:39   ` [lm-sensors] [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog dri Andreas Werner
2014-08-13  8:39   ` [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog driver Andreas Werner
2014-08-21 18:42   ` Guenter Roeck
2014-08-21 18:42     ` [lm-sensors] [PATCH v4 2/4] drivers/watchdog/menf21bmc_wdt: introduce MEN 14F021P00 BMC Watchdog Guenter Roeck
2014-08-13  8:40 ` [PATCH v4 3/4] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver Andreas Werner
2014-08-13  8:40   ` [lm-sensors] " Andreas Werner
2014-08-13  8:40   ` Andreas Werner
2014-08-25 18:53   ` Bryan Wu
2014-08-25 18:53     ` [lm-sensors] " Bryan Wu
2014-08-25 19:05     ` Guenter Roeck
2014-08-25 19:05       ` [lm-sensors] " Guenter Roeck
2014-08-13  8:40 ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
2014-08-13  8:40   ` [lm-sensors] " Andreas Werner
2014-08-13  8:40   ` Andreas Werner
2014-08-21 18:37   ` Guenter Roeck
2014-08-21 18:37     ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Guenter Roeck
2014-08-22  8:38     ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
2014-08-22  8:38       ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Andreas Werner
2014-08-22  8:38       ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
2014-08-22  9:02       ` Guenter Roeck
2014-08-22  9:02         ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Guenter Roeck
2014-08-21 18:45   ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Guenter Roeck
2014-08-21 18:45     ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Guenter Roeck
2014-08-22  8:39     ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
2014-08-22  8:39       ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Andreas Werner
2014-08-22  8:39       ` [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driver Andreas Werner
2014-08-22  9:04       ` Guenter Roeck
2014-08-22  9:04         ` [lm-sensors] [PATCH v4 4/4] drivers/hwmon/menf21bmc_hwmon: introduce MEN14F021P00 BMC HWMON driv Guenter Roeck

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.