All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Introduce MEN 14F021P00 Board Management Controller driver set
@ 2014-05-16 16:36 ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

The BMC is a PIC Mikrocontroller which assembled on almost all
of our 3U Compact PCI CPU boards and a few Box PCs.
The 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

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

Andreas Werner (3):
  drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog
    driver
  drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver

 drivers/leds/Kconfig            |   6 +
 drivers/leds/Makefile           |   2 +-
 drivers/leds/leds-menf21bmc.c   | 135 +++++++++++++++++++++
 drivers/mfd/Kconfig             |  12 ++
 drivers/mfd/Makefile            |   1 +
 drivers/mfd/menf21bmc.c         | 193 +++++++++++++++++++++++++++++
 drivers/watchdog/Kconfig        |   7 ++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/menf21bmc_wd.c | 263 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/menf21bmc.h   |  32 +++++
 10 files changed, 651 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-menf21bmc.c
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 drivers/watchdog/menf21bmc_wd.c
 create mode 100644 include/linux/mfd/menf21bmc.h

-- 
1.9.2

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

* [PATCH 0/3] Introduce MEN 14F021P00 Board Management Controller driver set
@ 2014-05-16 16:36 ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

The BMC is a PIC Mikrocontroller which assembled on almost all
of our 3U Compact PCI CPU boards and a few Box PCs.
The 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

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

Andreas Werner (3):
  drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog
    driver
  drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver

 drivers/leds/Kconfig            |   6 +
 drivers/leds/Makefile           |   2 +-
 drivers/leds/leds-menf21bmc.c   | 135 +++++++++++++++++++++
 drivers/mfd/Kconfig             |  12 ++
 drivers/mfd/Makefile            |   1 +
 drivers/mfd/menf21bmc.c         | 193 +++++++++++++++++++++++++++++
 drivers/watchdog/Kconfig        |   7 ++
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/menf21bmc_wd.c | 263 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/menf21bmc.h   |  32 +++++
 10 files changed, 651 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-menf21bmc.c
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 drivers/watchdog/menf21bmc_wd.c
 create mode 100644 include/linux/mfd/menf21bmc.h

-- 
1.9.2


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

* [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-16 16:36 ` Andreas Werner
@ 2014-05-16 16:37   ` Andreas Werner
  -1 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mfd/Kconfig           |  12 +++
 drivers/mfd/Makefile          |   1 +
 drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/menf21bmc.h |  32 +++++++
 4 files changed, 238 insertions(+)
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 include/linux/mfd/menf21bmc.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index ab5a43c..7c2e8d2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -427,6 +427,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.
+	  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 5913208..8f2be38 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -167,3 +167,4 @@ 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
diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
new file mode 100644
index 0000000..77de1a8
--- /dev/null
+++ b/drivers/mfd/menf21bmc.c
@@ -0,0 +1,193 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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>
+#include <linux/mfd/menf21bmc.h>
+
+#define BMC_CMD_REV_MAJOR	0x80
+#define BMC_CMD_REV_MINOR	0x81
+#define BMC_CMD_REV_MAIN	0x82
+#define BMC_CMD_REV_BUILD	0x83
+#define BMC_CMD_REV_VERI	0x84
+
+static struct mfd_cell menf21bmc_cell[] = {
+	{
+		.name = "menf21bmc_wd",
+	},
+	{
+		.name = "menf21bmc_led",
+	},
+};
+
+static int
+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_read_byte_data(client, reg);
+	mutex_unlock(&data->lock);
+
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
+		return ret;
+	}
+
+	*val = (uint8_t)ret;
+
+	return 0;
+}
+
+static int
+menf21bmc_read_word_data(struct i2c_client *client, u8 reg, uint16_t *val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_read_word_data(client, reg);
+	mutex_unlock(&data->lock);
+
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to read word at 0x%02x\n", reg);
+		return ret;
+	}
+	*val = (uint16_t)ret;
+
+	return 0;
+}
+
+static int menf21bmc_write_byte_data(struct i2c_client *client, u8 reg, u8 val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_write_byte_data(client, reg, val);
+	mutex_unlock(&data->lock);
+
+	return ret;
+}
+
+static int menf21bmc_write_word_data(struct i2c_client *client, u8 reg, u16 val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_write_word_data(client, reg, val);
+	mutex_unlock(&data->lock);
+
+	return ret;
+}
+
+static int menf21bmc_write_byte(struct i2c_client *client, u8 val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_write_byte(client, val);
+	mutex_unlock(&data->lock);
+
+	return ret;
+}
+
+static int
+menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
+{
+	struct menf21bmc *data;
+	uint16_t rev_major, rev_minor, rev_main, rev_build, rev_veri;
+	int ret = 0;
+
+	dev_dbg(&client->dev, "menf21bmc_probe\n");
+
+	if (!i2c_check_functionality(client->adapter,
+						I2C_FUNC_SMBUS_BYTE_DATA |
+						I2C_FUNC_SMBUS_WORD_DATA |
+						I2C_FUNC_SMBUS_BYTE))
+		return -EIO;
+
+	data = devm_kzalloc(&client->dev, sizeof(struct menf21bmc), GFP_KERNEL);
+	if (data == NULL)
+		return -ENOMEM;
+
+	mutex_init(&data->lock);
+
+	i2c_set_clientdata(client, data);
+	data->client = client;
+	data->read_word_data = menf21bmc_read_word_data;
+	data->read_byte_data = menf21bmc_read_byte_data;
+	data->write_word_data = menf21bmc_write_word_data;
+	data->write_byte_data = menf21bmc_write_byte_data;
+	data->write_byte = menf21bmc_write_byte;
+
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_MAJOR, &rev_major);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_MINOR, &rev_minor);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_MAIN, &rev_main);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_BUILD, &rev_build);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_VERI, &rev_veri);
+
+	if (ret) {
+		dev_err(&client->dev, "Cannot get Firmware Revision\n");
+		return -EIO;
+	}
+
+	dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
+					rev_major, rev_minor, rev_main);
+	dev_info(&client->dev, "Build: %d Verificaton Marker: %d\n",
+							rev_build, rev_veri);
+
+	ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
+				ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(&client->dev, "mfd_add_devices failed\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",
+		.owner	= THIS_MODULE,
+	},
+	.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");
diff --git a/include/linux/mfd/menf21bmc.h b/include/linux/mfd/menf21bmc.h
new file mode 100644
index 0000000..49df41fe
--- /dev/null
+++ b/include/linux/mfd/menf21bmc.h
@@ -0,0 +1,32 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC)
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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.
+ *
+ */
+
+#ifndef MENF21BMC_H
+#define MENF21BMC_H
+
+struct menf21bmc {
+	struct i2c_client *client;
+	struct mutex lock;
+
+	int (*read_word_data)(struct i2c_client *client,
+						u8 reg, uint16_t *val);
+	int (*read_byte_data)(struct i2c_client *client, u8 reg, uint8_t *val);
+	int (*write_word_data)(struct i2c_client *client, u8 reg, u16 val);
+	int (*write_byte_data)(struct i2c_client *client, u8 reg, u8 val);
+	int (*write_byte)(struct i2c_client *client, u8 val);
+};
+
+#endif /* MENF21BMC_H */
+
+
-- 
1.9.2

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

* [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-05-16 16:37   ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mfd/Kconfig           |  12 +++
 drivers/mfd/Makefile          |   1 +
 drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/menf21bmc.h |  32 +++++++
 4 files changed, 238 insertions(+)
 create mode 100644 drivers/mfd/menf21bmc.c
 create mode 100644 include/linux/mfd/menf21bmc.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index ab5a43c..7c2e8d2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -427,6 +427,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.
+	  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 5913208..8f2be38 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -167,3 +167,4 @@ 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
diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
new file mode 100644
index 0000000..77de1a8
--- /dev/null
+++ b/drivers/mfd/menf21bmc.c
@@ -0,0 +1,193 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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>
+#include <linux/mfd/menf21bmc.h>
+
+#define BMC_CMD_REV_MAJOR	0x80
+#define BMC_CMD_REV_MINOR	0x81
+#define BMC_CMD_REV_MAIN	0x82
+#define BMC_CMD_REV_BUILD	0x83
+#define BMC_CMD_REV_VERI	0x84
+
+static struct mfd_cell menf21bmc_cell[] = {
+	{
+		.name = "menf21bmc_wd",
+	},
+	{
+		.name = "menf21bmc_led",
+	},
+};
+
+static int
+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_read_byte_data(client, reg);
+	mutex_unlock(&data->lock);
+
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
+		return ret;
+	}
+
+	*val = (uint8_t)ret;
+
+	return 0;
+}
+
+static int
+menf21bmc_read_word_data(struct i2c_client *client, u8 reg, uint16_t *val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_read_word_data(client, reg);
+	mutex_unlock(&data->lock);
+
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to read word at 0x%02x\n", reg);
+		return ret;
+	}
+	*val = (uint16_t)ret;
+
+	return 0;
+}
+
+static int menf21bmc_write_byte_data(struct i2c_client *client, u8 reg, u8 val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_write_byte_data(client, reg, val);
+	mutex_unlock(&data->lock);
+
+	return ret;
+}
+
+static int menf21bmc_write_word_data(struct i2c_client *client, u8 reg, u16 val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_write_word_data(client, reg, val);
+	mutex_unlock(&data->lock);
+
+	return ret;
+}
+
+static int menf21bmc_write_byte(struct i2c_client *client, u8 val)
+{
+	int ret;
+	struct menf21bmc *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->lock);
+	ret = i2c_smbus_write_byte(client, val);
+	mutex_unlock(&data->lock);
+
+	return ret;
+}
+
+static int
+menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
+{
+	struct menf21bmc *data;
+	uint16_t rev_major, rev_minor, rev_main, rev_build, rev_veri;
+	int ret = 0;
+
+	dev_dbg(&client->dev, "menf21bmc_probe\n");
+
+	if (!i2c_check_functionality(client->adapter,
+						I2C_FUNC_SMBUS_BYTE_DATA |
+						I2C_FUNC_SMBUS_WORD_DATA |
+						I2C_FUNC_SMBUS_BYTE))
+		return -EIO;
+
+	data = devm_kzalloc(&client->dev, sizeof(struct menf21bmc), GFP_KERNEL);
+	if (data == NULL)
+		return -ENOMEM;
+
+	mutex_init(&data->lock);
+
+	i2c_set_clientdata(client, data);
+	data->client = client;
+	data->read_word_data = menf21bmc_read_word_data;
+	data->read_byte_data = menf21bmc_read_byte_data;
+	data->write_word_data = menf21bmc_write_word_data;
+	data->write_byte_data = menf21bmc_write_byte_data;
+	data->write_byte = menf21bmc_write_byte;
+
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_MAJOR, &rev_major);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_MINOR, &rev_minor);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_MAIN, &rev_main);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_BUILD, &rev_build);
+	ret |= menf21bmc_read_word_data(client, BMC_CMD_REV_VERI, &rev_veri);
+
+	if (ret) {
+		dev_err(&client->dev, "Cannot get Firmware Revision\n");
+		return -EIO;
+	}
+
+	dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
+					rev_major, rev_minor, rev_main);
+	dev_info(&client->dev, "Build: %d Verificaton Marker: %d\n",
+							rev_build, rev_veri);
+
+	ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
+				ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(&client->dev, "mfd_add_devices failed\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",
+		.owner	= THIS_MODULE,
+	},
+	.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");
diff --git a/include/linux/mfd/menf21bmc.h b/include/linux/mfd/menf21bmc.h
new file mode 100644
index 0000000..49df41fe
--- /dev/null
+++ b/include/linux/mfd/menf21bmc.h
@@ -0,0 +1,32 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC)
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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.
+ *
+ */
+
+#ifndef MENF21BMC_H
+#define MENF21BMC_H
+
+struct menf21bmc {
+	struct i2c_client *client;
+	struct mutex lock;
+
+	int (*read_word_data)(struct i2c_client *client,
+						u8 reg, uint16_t *val);
+	int (*read_byte_data)(struct i2c_client *client, u8 reg, uint8_t *val);
+	int (*write_word_data)(struct i2c_client *client, u8 reg, u16 val);
+	int (*write_byte_data)(struct i2c_client *client, u8 reg, u8 val);
+	int (*write_byte)(struct i2c_client *client, u8 val);
+};
+
+#endif /* MENF21BMC_H */
+
+
-- 
1.9.2


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

* [PATCH 2/3] drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog driver
  2014-05-16 16:36 ` Andreas Werner
@ 2014-05-16 16:37   ` Andreas Werner
  -1 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.

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

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2b4c1fc..ede3201 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 1b5f3d5..0a5465d 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_wd.o
diff --git a/drivers/watchdog/menf21bmc_wd.c b/drivers/watchdog/menf21bmc_wd.c
new file mode 100644
index 0000000..31ccea8
--- /dev/null
+++ b/drivers/watchdog/menf21bmc_wd.c
@@ -0,0 +1,263 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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/mfd/menf21bmc.h>
+
+#define DEVNAME "menf21bmc_wd"
+
+#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_CMD_WD_ARM_SET	0x18
+#define BMC_CMD_WD_ARM_GET	0x19
+#define BMC_CMD_ARM_STATE	0x19
+#define BMC_WD_OFF_VAL		0x69
+#define BMC_CMD_RST_RSN		0x92
+
+#define BMC_WD_TIMEOUT_MIN	1	/*  in sec -> BMC min = 0.1 s */
+#define BMC_WD_TIMEOUT_MAX	6553	/*  in sec -> BMC max = 6553,5 s */
+
+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_wd_data {
+	struct watchdog_device wdt;
+	struct menf21bmc *menf21bmc;
+};
+
+static int menf21bmc_wd_set_bootstatus(struct menf21bmc_wd_data *data)
+{
+	u8 rst_rsn;
+	int ret;
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	ret = menf21bmc->read_byte_data(menf21bmc->client,
+						BMC_CMD_RST_RSN, &rst_rsn);
+	if (ret < 0)
+		return -EIO;
+
+	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_wd_leave_prod_mode(struct platform_device *pdev)
+{
+	int ret;
+	uint8_t val;
+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	ret = menf21bmc->read_byte_data(menf21bmc->client,
+						BMC_CMD_WD_ARM_GET, &val);
+	if (ret < 0)
+		return -EIO;
+
+	/*
+	 * Production mode should be not active after delivery of the Board.
+	 * To be sure we check it, inform the user and leave the mode
+	 * if active.
+	 */
+	if (val == 0x00) {
+		dev_info(&pdev->dev,
+			"BMC in production mode. Leave production mode\n");
+
+		ret = menf21bmc->write_byte(menf21bmc->client,
+							BMC_CMD_WD_ARM_SET);
+		if (ret < 0)
+			return -EIO;
+	}
+
+	return 0;
+}
+
+static int menf21bmc_wd_start(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_ON);
+}
+
+static int menf21bmc_wd_stop(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	return menf21bmc->write_byte_data(menf21bmc->client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static int
+menf21bmc_wd_settimeout(struct watchdog_device *wdt, unsigned int timeout)
+{
+	int ret;
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	/*
+	 *  BMC Watchdog does have a resolution of 100ms.
+	 *  Watchdog API defines the timeout in seconds, so we have to
+	 *  multiply the value.
+	 */
+	ret = menf21bmc->write_word_data(menf21bmc->client,
+						BMC_CMD_WD_TIME, timeout * 10);
+	if (ret < 0)
+		return -EIO;
+
+	wdt->timeout = timeout;
+
+	return 0;
+}
+
+static int menf21bmc_wd_ping(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_TRIG);
+}
+
+static const struct watchdog_info menf21bmc_wd_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = DEVNAME,
+};
+
+static const struct watchdog_ops menf21bmc_wd_ops = {
+	.owner		= THIS_MODULE,
+	.start		= menf21bmc_wd_start,
+	.stop		= menf21bmc_wd_stop,
+	.ping		= menf21bmc_wd_ping,
+	.set_timeout	= menf21bmc_wd_settimeout,
+};
+
+static int menf21bmc_wd_probe(struct platform_device *pdev)
+{
+	int ret;
+	uint16_t bmc_timeout;
+	struct menf21bmc_wd_data *driver_data;
+	struct watchdog_device *menf21bmc_wd;
+	struct menf21bmc *menf21bmc = dev_get_drvdata(pdev->dev.parent);
+
+	driver_data = devm_kzalloc(&pdev->dev,
+				sizeof(struct menf21bmc_wd_data), GFP_KERNEL);
+	if (!driver_data)
+		return -ENOMEM;
+
+	driver_data->menf21bmc = menf21bmc;
+
+	menf21bmc_wd = &driver_data->wdt;
+	menf21bmc_wd->ops = &menf21bmc_wd_ops;
+	menf21bmc_wd->info = &menf21bmc_wd_info;
+	menf21bmc_wd->min_timeout = BMC_WD_TIMEOUT_MIN;
+	menf21bmc_wd->max_timeout = BMC_WD_TIMEOUT_MAX;
+
+
+	/*
+	 * Get the current wdt timeout value from the BMC because
+	 * the BMC will save the value set before if the system restarts.
+	 */
+	ret = menf21bmc->read_word_data(menf21bmc->client,
+					 BMC_CMD_WD_TIME, &bmc_timeout);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+		return ret;
+	}
+
+	watchdog_init_timeout(menf21bmc_wd, bmc_timeout / 10, &pdev->dev);
+
+	watchdog_set_nowayout(menf21bmc_wd, nowayout);
+	watchdog_set_drvdata(menf21bmc_wd, driver_data);
+	platform_set_drvdata(pdev, driver_data);
+
+	/*
+	 * We have to leave the Production Mode of the BMC to activate the
+	 * Watchdog functionality.
+	 */
+	ret = menf21bmc_wd_leave_prod_mode(pdev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to leave production mode\n");
+		return ret;
+	}
+
+	ret = menf21bmc_wd_set_bootstatus(driver_data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+		return ret;
+	}
+
+	ret = watchdog_register_device(&driver_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_wd_remove(struct platform_device *pdev)
+{
+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
+
+	dev_warn(&pdev->dev,
+		"Untregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
+
+	watchdog_unregister_device(&data->wdt);
+
+	return 0;
+}
+
+static void menf21bmc_wd_shutdown(struct platform_device *pdev)
+{
+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	menf21bmc->write_word_data(menf21bmc->client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static struct  platform_driver menf21bmc_wd = {
+	.driver		= {
+		.owner = THIS_MODULE,
+		.name	= DEVNAME,
+	},
+	.probe		= menf21bmc_wd_probe,
+	.remove		= menf21bmc_wd_remove,
+	.shutdown	= menf21bmc_wd_shutdown,
+};
+
+module_platform_driver(menf21bmc_wd);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:menf21bmc_wd");
-- 
1.9.2

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

* [PATCH 2/3] drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog driver
@ 2014-05-16 16:37   ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.

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

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2b4c1fc..ede3201 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 1b5f3d5..0a5465d 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_wd.o
diff --git a/drivers/watchdog/menf21bmc_wd.c b/drivers/watchdog/menf21bmc_wd.c
new file mode 100644
index 0000000..31ccea8
--- /dev/null
+++ b/drivers/watchdog/menf21bmc_wd.c
@@ -0,0 +1,263 @@
+/*
+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
+ *
+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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/mfd/menf21bmc.h>
+
+#define DEVNAME "menf21bmc_wd"
+
+#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_CMD_WD_ARM_SET	0x18
+#define BMC_CMD_WD_ARM_GET	0x19
+#define BMC_CMD_ARM_STATE	0x19
+#define BMC_WD_OFF_VAL		0x69
+#define BMC_CMD_RST_RSN		0x92
+
+#define BMC_WD_TIMEOUT_MIN	1	/*  in sec -> BMC min = 0.1 s */
+#define BMC_WD_TIMEOUT_MAX	6553	/*  in sec -> BMC max = 6553,5 s */
+
+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_wd_data {
+	struct watchdog_device wdt;
+	struct menf21bmc *menf21bmc;
+};
+
+static int menf21bmc_wd_set_bootstatus(struct menf21bmc_wd_data *data)
+{
+	u8 rst_rsn;
+	int ret;
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	ret = menf21bmc->read_byte_data(menf21bmc->client,
+						BMC_CMD_RST_RSN, &rst_rsn);
+	if (ret < 0)
+		return -EIO;
+
+	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_wd_leave_prod_mode(struct platform_device *pdev)
+{
+	int ret;
+	uint8_t val;
+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	ret = menf21bmc->read_byte_data(menf21bmc->client,
+						BMC_CMD_WD_ARM_GET, &val);
+	if (ret < 0)
+		return -EIO;
+
+	/*
+	 * Production mode should be not active after delivery of the Board.
+	 * To be sure we check it, inform the user and leave the mode
+	 * if active.
+	 */
+	if (val == 0x00) {
+		dev_info(&pdev->dev,
+			"BMC in production mode. Leave production mode\n");
+
+		ret = menf21bmc->write_byte(menf21bmc->client,
+							BMC_CMD_WD_ARM_SET);
+		if (ret < 0)
+			return -EIO;
+	}
+
+	return 0;
+}
+
+static int menf21bmc_wd_start(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_ON);
+}
+
+static int menf21bmc_wd_stop(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	return menf21bmc->write_byte_data(menf21bmc->client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static int
+menf21bmc_wd_settimeout(struct watchdog_device *wdt, unsigned int timeout)
+{
+	int ret;
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	/*
+	 *  BMC Watchdog does have a resolution of 100ms.
+	 *  Watchdog API defines the timeout in seconds, so we have to
+	 *  multiply the value.
+	 */
+	ret = menf21bmc->write_word_data(menf21bmc->client,
+						BMC_CMD_WD_TIME, timeout * 10);
+	if (ret < 0)
+		return -EIO;
+
+	wdt->timeout = timeout;
+
+	return 0;
+}
+
+static int menf21bmc_wd_ping(struct watchdog_device *wdt)
+{
+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_TRIG);
+}
+
+static const struct watchdog_info menf21bmc_wd_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = DEVNAME,
+};
+
+static const struct watchdog_ops menf21bmc_wd_ops = {
+	.owner		= THIS_MODULE,
+	.start		= menf21bmc_wd_start,
+	.stop		= menf21bmc_wd_stop,
+	.ping		= menf21bmc_wd_ping,
+	.set_timeout	= menf21bmc_wd_settimeout,
+};
+
+static int menf21bmc_wd_probe(struct platform_device *pdev)
+{
+	int ret;
+	uint16_t bmc_timeout;
+	struct menf21bmc_wd_data *driver_data;
+	struct watchdog_device *menf21bmc_wd;
+	struct menf21bmc *menf21bmc = dev_get_drvdata(pdev->dev.parent);
+
+	driver_data = devm_kzalloc(&pdev->dev,
+				sizeof(struct menf21bmc_wd_data), GFP_KERNEL);
+	if (!driver_data)
+		return -ENOMEM;
+
+	driver_data->menf21bmc = menf21bmc;
+
+	menf21bmc_wd = &driver_data->wdt;
+	menf21bmc_wd->ops = &menf21bmc_wd_ops;
+	menf21bmc_wd->info = &menf21bmc_wd_info;
+	menf21bmc_wd->min_timeout = BMC_WD_TIMEOUT_MIN;
+	menf21bmc_wd->max_timeout = BMC_WD_TIMEOUT_MAX;
+
+
+	/*
+	 * Get the current wdt timeout value from the BMC because
+	 * the BMC will save the value set before if the system restarts.
+	 */
+	ret = menf21bmc->read_word_data(menf21bmc->client,
+					 BMC_CMD_WD_TIME, &bmc_timeout);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
+		return ret;
+	}
+
+	watchdog_init_timeout(menf21bmc_wd, bmc_timeout / 10, &pdev->dev);
+
+	watchdog_set_nowayout(menf21bmc_wd, nowayout);
+	watchdog_set_drvdata(menf21bmc_wd, driver_data);
+	platform_set_drvdata(pdev, driver_data);
+
+	/*
+	 * We have to leave the Production Mode of the BMC to activate the
+	 * Watchdog functionality.
+	 */
+	ret = menf21bmc_wd_leave_prod_mode(pdev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to leave production mode\n");
+		return ret;
+	}
+
+	ret = menf21bmc_wd_set_bootstatus(driver_data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
+		return ret;
+	}
+
+	ret = watchdog_register_device(&driver_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_wd_remove(struct platform_device *pdev)
+{
+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
+
+	dev_warn(&pdev->dev,
+		"Untregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
+
+	watchdog_unregister_device(&data->wdt);
+
+	return 0;
+}
+
+static void menf21bmc_wd_shutdown(struct platform_device *pdev)
+{
+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
+	struct menf21bmc *menf21bmc = data->menf21bmc;
+
+	menf21bmc->write_word_data(menf21bmc->client,
+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
+}
+
+static struct  platform_driver menf21bmc_wd = {
+	.driver		= {
+		.owner = THIS_MODULE,
+		.name	= DEVNAME,
+	},
+	.probe		= menf21bmc_wd_probe,
+	.remove		= menf21bmc_wd_remove,
+	.shutdown	= menf21bmc_wd_shutdown,
+};
+
+module_platform_driver(menf21bmc_wd);
+
+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:menf21bmc_wd");
-- 
1.9.2


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

* [PATCH 3/3] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
  2014-05-16 16:36 ` Andreas Werner
@ 2014-05-16 16:37   ` Andreas Werner
  -1 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.

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

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1e81d7a..8f98e0f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -466,6 +466,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 79c5155..1c465fe 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -54,7 +54,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..1548d08
--- /dev/null
+++ b/drivers/leds/leds-menf21bmc.c
@@ -0,0 +1,135 @@
+/*
+ *  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
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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/mfd/menf21bmc.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_data {
+	struct led_classdev cdev;
+	struct menf21bmc *menf21bmc;
+	u8 led_bit;
+	const char *name;
+};
+
+static struct menf21bmc_led_data 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)
+{
+	u8 led_val;
+	int ret;
+	struct menf21bmc_led_data *led = container_of(led_cdev,
+					struct menf21bmc_led_data, cdev);
+	struct menf21bmc *menf21bmc = led->menf21bmc;
+
+	mutex_lock(&led_lock);
+	ret = menf21bmc->read_byte_data(menf21bmc->client,
+						BMC_CMD_LED_GET_SET, &led_val);
+	if (!ret) {
+		if (value == LED_OFF)
+			led_val &= ~led->led_bit;
+		else
+			led_val |= led->led_bit;
+
+		menf21bmc->write_byte_data(menf21bmc->client,
+						BMC_CMD_LED_GET_SET, led_val);
+	}
+	mutex_unlock(&led_lock);
+}
+
+static int menf21bmc_led_probe(struct platform_device *pdev)
+{
+	int i;
+	int ret;
+	struct menf21bmc *menf21bmc = dev_get_drvdata(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].menf21bmc = menf21bmc;
+
+		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 devicei\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");
+MODULE_ALIAS("platform:menf21bmc_led");
-- 
1.9.2

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

* [PATCH 3/3] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver
@ 2014-05-16 16:37   ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-16 16:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

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

This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.

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

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1e81d7a..8f98e0f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -466,6 +466,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 79c5155..1c465fe 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -54,7 +54,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..1548d08
--- /dev/null
+++ b/drivers/leds/leds-menf21bmc.c
@@ -0,0 +1,135 @@
+/*
+ *  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
+ *  Author: Andreas Werner <andreas.werner@men.de>
+ *  All rights reserved.
+ *
+ *  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/mfd/menf21bmc.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_data {
+	struct led_classdev cdev;
+	struct menf21bmc *menf21bmc;
+	u8 led_bit;
+	const char *name;
+};
+
+static struct menf21bmc_led_data 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)
+{
+	u8 led_val;
+	int ret;
+	struct menf21bmc_led_data *led = container_of(led_cdev,
+					struct menf21bmc_led_data, cdev);
+	struct menf21bmc *menf21bmc = led->menf21bmc;
+
+	mutex_lock(&led_lock);
+	ret = menf21bmc->read_byte_data(menf21bmc->client,
+						BMC_CMD_LED_GET_SET, &led_val);
+	if (!ret) {
+		if (value == LED_OFF)
+			led_val &= ~led->led_bit;
+		else
+			led_val |= led->led_bit;
+
+		menf21bmc->write_byte_data(menf21bmc->client,
+						BMC_CMD_LED_GET_SET, led_val);
+	}
+	mutex_unlock(&led_lock);
+}
+
+static int menf21bmc_led_probe(struct platform_device *pdev)
+{
+	int i;
+	int ret;
+	struct menf21bmc *menf21bmc = dev_get_drvdata(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].menf21bmc = menf21bmc;
+
+		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 devicei\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");
+MODULE_ALIAS("platform:menf21bmc_led");
-- 
1.9.2


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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-16 16:37   ` Andreas Werner
  (?)
@ 2014-05-17 15:47   ` Guenter Roeck
  2014-05-19 12:43       ` Andreas Werner
  -1 siblings, 1 reply; 21+ messages in thread
From: Guenter Roeck @ 2014-05-17 15:47 UTC (permalink / raw)
  To: Andreas Werner, linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

On 05/16/2014 09:37 AM, 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
>
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>   drivers/mfd/Kconfig           |  12 +++
>   drivers/mfd/Makefile          |   1 +
>   drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
>   include/linux/mfd/menf21bmc.h |  32 +++++++
>   4 files changed, 238 insertions(+)
>   create mode 100644 drivers/mfd/menf21bmc.c
>   create mode 100644 include/linux/mfd/menf21bmc.h
>
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index ab5a43c..7c2e8d2 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -427,6 +427,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.
> +	  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 5913208..8f2be38 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -167,3 +167,4 @@ 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
> diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> new file mode 100644
> index 0000000..77de1a8
> --- /dev/null
> +++ b/drivers/mfd/menf21bmc.c
> @@ -0,0 +1,193 @@
> +/*
> + *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> + *
> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> + *  Author: Andreas Werner <andreas.werner@men.de>
> + *  All rights reserved.
> + *
> + *  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>
> +#include <linux/mfd/menf21bmc.h>
> +
> +#define BMC_CMD_REV_MAJOR	0x80
> +#define BMC_CMD_REV_MINOR	0x81
> +#define BMC_CMD_REV_MAIN	0x82
> +#define BMC_CMD_REV_BUILD	0x83
> +#define BMC_CMD_REV_VERI	0x84
> +
> +static struct mfd_cell menf21bmc_cell[] = {
> +	{
> +		.name = "menf21bmc_wd",
> +	},
> +	{
> +		.name = "menf21bmc_led",
> +	},
> +};
> +
> +static int
> +menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> +{
> +	int ret;
> +	struct menf21bmc *data = i2c_get_clientdata(client);
> +
> +	mutex_lock(&data->lock);
> +	ret = i2c_smbus_read_byte_data(client, reg);
> +	mutex_unlock(&data->lock);
> +
> +	if (ret < 0) {
> +		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> +		return ret;
> +	}
> +
> +	*val = (uint8_t)ret;
> +
> +	return 0;
> +}
> +
I personally would prefer if you would retain the original API, which returns both value
and error code as return value. I don't see the benefit of changing the API as you did -
it just complicates the code.

Thanks,
Guenter

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

* Re: [PATCH 2/3] drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog driver
  2014-05-16 16:37   ` Andreas Werner
  (?)
@ 2014-05-17 15:57   ` Guenter Roeck
  2014-05-19 12:20       ` Andreas Werner
  -1 siblings, 1 reply; 21+ messages in thread
From: Guenter Roeck @ 2014-05-17 15:57 UTC (permalink / raw)
  To: Andreas Werner, linux-kernel
  Cc: sameo, lee.jones, wim, linux-watchdog, cooloney, rpurdie,
	linux-leds, johannes.thumshirn, thomas.schnuerer, wernerandy

On 05/16/2014 09:37 AM, Andreas Werner wrote:
> Added driver to support the 14F021P00 BMC Watchdog.
> The BMC is a Board Management Controller including watchdog functionality.
>
> This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.
>
> Signed-off-by: Andreas Werner <andreas.werner@men.de>
> ---
>   drivers/watchdog/Kconfig        |   7 ++
>   drivers/watchdog/Makefile       |   1 +
>   drivers/watchdog/menf21bmc_wd.c | 263 ++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 271 insertions(+)
>   create mode 100644 drivers/watchdog/menf21bmc_wd.c
>
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 2b4c1fc..ede3201 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 1b5f3d5..0a5465d 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_wd.o
> diff --git a/drivers/watchdog/menf21bmc_wd.c b/drivers/watchdog/menf21bmc_wd.c
> new file mode 100644
> index 0000000..31ccea8
> --- /dev/null
> +++ b/drivers/watchdog/menf21bmc_wd.c
> @@ -0,0 +1,263 @@
> +/*
> + *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
> + *
> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> + *  Author: Andreas Werner <andreas.werner@men.de>
> + *  All rights reserved.
> + *
> + *  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/mfd/menf21bmc.h>
> +
> +#define DEVNAME "menf21bmc_wd"
> +
> +#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_CMD_WD_ARM_SET	0x18
> +#define BMC_CMD_WD_ARM_GET	0x19
> +#define BMC_CMD_ARM_STATE	0x19
> +#define BMC_WD_OFF_VAL		0x69
> +#define BMC_CMD_RST_RSN		0x92
> +
> +#define BMC_WD_TIMEOUT_MIN	1	/*  in sec -> BMC min = 0.1 s */

I find the comment a bit confusing. The timeout is in seconds. The BMC minimum
timeout may be 0.1s, but that is not reflected in the define. Maybe replace
the comment with something like
					/* in sec (BMC min = 0.1 s) */

> +#define BMC_WD_TIMEOUT_MAX	6553	/*  in sec -> BMC max = 6553,5 s */
> +
> +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_wd_data {
> +	struct watchdog_device wdt;
> +	struct menf21bmc *menf21bmc;
> +};
> +
> +static int menf21bmc_wd_set_bootstatus(struct menf21bmc_wd_data *data)
> +{
> +	u8 rst_rsn;
> +	int ret;
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	ret = menf21bmc->read_byte_data(menf21bmc->client,
> +						BMC_CMD_RST_RSN, &rst_rsn);
> +	if (ret < 0)
> +		return -EIO;
> +
Please return the original error.

> +	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_wd_leave_prod_mode(struct platform_device *pdev)
> +{
> +	int ret;
> +	uint8_t val;
> +	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	ret = menf21bmc->read_byte_data(menf21bmc->client,
> +						BMC_CMD_WD_ARM_GET, &val);
> +	if (ret < 0)
> +		return -EIO;
> +
Please return the original error.

> +	/*
> +	 * Production mode should be not active after delivery of the Board.
> +	 * To be sure we check it, inform the user and leave the mode
> +	 * if active.
> +	 */
> +	if (val == 0x00) {
> +		dev_info(&pdev->dev,
> +			"BMC in production mode. Leave production mode\n");
> +
> +		ret = menf21bmc->write_byte(menf21bmc->client,
> +							BMC_CMD_WD_ARM_SET);
> +		if (ret < 0)
> +			return -EIO;

Please return the original error.

> +	}
> +
> +	return 0;
> +}
> +
> +static int menf21bmc_wd_start(struct watchdog_device *wdt)
> +{
> +	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_ON);
> +}
> +
> +static int menf21bmc_wd_stop(struct watchdog_device *wdt)
> +{
> +	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	return menf21bmc->write_byte_data(menf21bmc->client,
> +					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
> +}
> +
> +static int
> +menf21bmc_wd_settimeout(struct watchdog_device *wdt, unsigned int timeout)
> +{
> +	int ret;
> +	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	/*
> +	 *  BMC Watchdog does have a resolution of 100ms.
> +	 *  Watchdog API defines the timeout in seconds, so we have to
> +	 *  multiply the value.
> +	 */
> +	ret = menf21bmc->write_word_data(menf21bmc->client,
> +						BMC_CMD_WD_TIME, timeout * 10);
> +	if (ret < 0)
> +		return -EIO;
> +
Please return the original error.

> +	wdt->timeout = timeout;
> +
> +	return 0;
> +}
> +
> +static int menf21bmc_wd_ping(struct watchdog_device *wdt)
> +{
> +	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_TRIG);
> +}
> +
> +static const struct watchdog_info menf21bmc_wd_info = {
> +	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
> +	.identity = DEVNAME,
> +};
> +
> +static const struct watchdog_ops menf21bmc_wd_ops = {
> +	.owner		= THIS_MODULE,
> +	.start		= menf21bmc_wd_start,
> +	.stop		= menf21bmc_wd_stop,
> +	.ping		= menf21bmc_wd_ping,
> +	.set_timeout	= menf21bmc_wd_settimeout,
> +};
> +
> +static int menf21bmc_wd_probe(struct platform_device *pdev)
> +{
> +	int ret;
> +	uint16_t bmc_timeout;
> +	struct menf21bmc_wd_data *driver_data;
> +	struct watchdog_device *menf21bmc_wd;
> +	struct menf21bmc *menf21bmc = dev_get_drvdata(pdev->dev.parent);
> +
> +	driver_data = devm_kzalloc(&pdev->dev,
> +				sizeof(struct menf21bmc_wd_data), GFP_KERNEL);
> +	if (!driver_data)
> +		return -ENOMEM;
> +
> +	driver_data->menf21bmc = menf21bmc;
> +
> +	menf21bmc_wd = &driver_data->wdt;
> +	menf21bmc_wd->ops = &menf21bmc_wd_ops;
> +	menf21bmc_wd->info = &menf21bmc_wd_info;
> +	menf21bmc_wd->min_timeout = BMC_WD_TIMEOUT_MIN;
> +	menf21bmc_wd->max_timeout = BMC_WD_TIMEOUT_MAX;
> +
> +
Please no more than one empty line.

> +	/*
> +	 * Get the current wdt timeout value from the BMC because
> +	 * the BMC will save the value set before if the system restarts.
> +	 */
> +	ret = menf21bmc->read_word_data(menf21bmc->client,
> +					 BMC_CMD_WD_TIME, &bmc_timeout);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
> +		return ret;
> +	}
> +
> +	watchdog_init_timeout(menf21bmc_wd, bmc_timeout / 10, &pdev->dev);
> +
> +	watchdog_set_nowayout(menf21bmc_wd, nowayout);
> +	watchdog_set_drvdata(menf21bmc_wd, driver_data);
> +	platform_set_drvdata(pdev, driver_data);
> +
> +	/*
> +	 * We have to leave the Production Mode of the BMC to activate the
> +	 * Watchdog functionality.
> +	 */
> +	ret = menf21bmc_wd_leave_prod_mode(pdev);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "failed to leave production mode\n");
> +		return ret;
> +	}
> +
Shouldn't this be in the mfd code ?


> +	ret = menf21bmc_wd_set_bootstatus(driver_data);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
> +		return ret;
> +	}
> +
> +	ret = watchdog_register_device(&driver_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_wd_remove(struct platform_device *pdev)
> +{
> +	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> +
> +	dev_warn(&pdev->dev,
> +		"Untregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
> +
> +	watchdog_unregister_device(&data->wdt);
> +
> +	return 0;
> +}
> +
> +static void menf21bmc_wd_shutdown(struct platform_device *pdev)
> +{
> +	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> +	struct menf21bmc *menf21bmc = data->menf21bmc;
> +
> +	menf21bmc->write_word_data(menf21bmc->client,
> +					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
> +}
> +
> +static struct  platform_driver menf21bmc_wd = {
> +	.driver		= {
> +		.owner = THIS_MODULE,
> +		.name	= DEVNAME,
> +	},
> +	.probe		= menf21bmc_wd_probe,
> +	.remove		= menf21bmc_wd_remove,
> +	.shutdown	= menf21bmc_wd_shutdown,
> +};
> +
> +module_platform_driver(menf21bmc_wd);
> +
> +MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
> +MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:menf21bmc_wd");
>

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

* Re: [PATCH 2/3] drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog driver
  2014-05-17 15:57   ` Guenter Roeck
@ 2014-05-19 12:20       ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-19 12:20 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Sat, May 17, 2014 at 08:57:27AM -0700, Guenter Roeck wrote:
> On 05/16/2014 09:37 AM, Andreas Werner wrote:
> >Added driver to support the 14F021P00 BMC Watchdog.
> >The BMC is a Board Management Controller including watchdog functionality.
> >
> >This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.
> >
> >Signed-off-by: Andreas Werner <andreas.werner@men.de>
> >---
> >  drivers/watchdog/Kconfig        |   7 ++
> >  drivers/watchdog/Makefile       |   1 +
> >  drivers/watchdog/menf21bmc_wd.c | 263 ++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 271 insertions(+)
> >  create mode 100644 drivers/watchdog/menf21bmc_wd.c
> >
> >diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> >index 2b4c1fc..ede3201 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 1b5f3d5..0a5465d 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_wd.o
> >diff --git a/drivers/watchdog/menf21bmc_wd.c b/drivers/watchdog/menf21bmc_wd.c
> >new file mode 100644
> >index 0000000..31ccea8
> >--- /dev/null
> >+++ b/drivers/watchdog/menf21bmc_wd.c
> >@@ -0,0 +1,263 @@
> >+/*
> >+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
> >+ *
> >+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> >+ *  Author: Andreas Werner <andreas.werner@men.de>
> >+ *  All rights reserved.
> >+ *
> >+ *  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/mfd/menf21bmc.h>
> >+
> >+#define DEVNAME "menf21bmc_wd"
> >+
> >+#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_CMD_WD_ARM_SET	0x18
> >+#define BMC_CMD_WD_ARM_GET	0x19
> >+#define BMC_CMD_ARM_STATE	0x19
> >+#define BMC_WD_OFF_VAL		0x69
> >+#define BMC_CMD_RST_RSN		0x92
> >+
> >+#define BMC_WD_TIMEOUT_MIN	1	/*  in sec -> BMC min = 0.1 s */
> 
> I find the comment a bit confusing. The timeout is in seconds. The BMC minimum
> timeout may be 0.1s, but that is not reflected in the define. Maybe replace
> the comment with something like
> 					/* in sec (BMC min = 0.1 s) */

OK. I think I just write /* in sec */ as the comment because
it is explained in menf21bmc_wd_settimout() function.

> 
> >+#define BMC_WD_TIMEOUT_MAX	6553	/*  in sec -> BMC max = 6553,5 s */
> >+
> >+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_wd_data {
> >+	struct watchdog_device wdt;
> >+	struct menf21bmc *menf21bmc;
> >+};
> >+
> >+static int menf21bmc_wd_set_bootstatus(struct menf21bmc_wd_data *data)
> >+{
> >+	u8 rst_rsn;
> >+	int ret;
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	ret = menf21bmc->read_byte_data(menf21bmc->client,
> >+						BMC_CMD_RST_RSN, &rst_rsn);
> >+	if (ret < 0)
> >+		return -EIO;
> >+
> Please return the original error.
I agree, will be changed.
> 
> >+	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_wd_leave_prod_mode(struct platform_device *pdev)
> >+{
> >+	int ret;
> >+	uint8_t val;
> >+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	ret = menf21bmc->read_byte_data(menf21bmc->client,
> >+						BMC_CMD_WD_ARM_GET, &val);
> >+	if (ret < 0)
> >+		return -EIO;
> >+
> Please return the original error.

I agree, will be changed.

> 
> >+	/*
> >+	 * Production mode should be not active after delivery of the Board.
> >+	 * To be sure we check it, inform the user and leave the mode
> >+	 * if active.
> >+	 */
> >+	if (val == 0x00) {
> >+		dev_info(&pdev->dev,
> >+			"BMC in production mode. Leave production mode\n");
> >+
> >+		ret = menf21bmc->write_byte(menf21bmc->client,
> >+							BMC_CMD_WD_ARM_SET);
> >+		if (ret < 0)
> >+			return -EIO;
> 
> Please return the original error.

I agree, will be changed.

> 
> >+	}
> >+
> >+	return 0;
> >+}
> >+
> >+static int menf21bmc_wd_start(struct watchdog_device *wdt)
> >+{
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_ON);
> >+}
> >+
> >+static int menf21bmc_wd_stop(struct watchdog_device *wdt)
> >+{
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	return menf21bmc->write_byte_data(menf21bmc->client,
> >+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
> >+}
> >+
> >+static int
> >+menf21bmc_wd_settimeout(struct watchdog_device *wdt, unsigned int timeout)
> >+{
> >+	int ret;
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	/*
> >+	 *  BMC Watchdog does have a resolution of 100ms.
> >+	 *  Watchdog API defines the timeout in seconds, so we have to
> >+	 *  multiply the value.
> >+	 */
> >+	ret = menf21bmc->write_word_data(menf21bmc->client,
> >+						BMC_CMD_WD_TIME, timeout * 10);
> >+	if (ret < 0)
> >+		return -EIO;
> >+
> Please return the original error.

I agree, will be changed.

> 
> >+	wdt->timeout = timeout;
> >+
> >+	return 0;
> >+}
> >+
> >+static int menf21bmc_wd_ping(struct watchdog_device *wdt)
> >+{
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_TRIG);
> >+}
> >+
> >+static const struct watchdog_info menf21bmc_wd_info = {
> >+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
> >+	.identity = DEVNAME,
> >+};
> >+
> >+static const struct watchdog_ops menf21bmc_wd_ops = {
> >+	.owner		= THIS_MODULE,
> >+	.start		= menf21bmc_wd_start,
> >+	.stop		= menf21bmc_wd_stop,
> >+	.ping		= menf21bmc_wd_ping,
> >+	.set_timeout	= menf21bmc_wd_settimeout,
> >+};
> >+
> >+static int menf21bmc_wd_probe(struct platform_device *pdev)
> >+{
> >+	int ret;
> >+	uint16_t bmc_timeout;
> >+	struct menf21bmc_wd_data *driver_data;
> >+	struct watchdog_device *menf21bmc_wd;
> >+	struct menf21bmc *menf21bmc = dev_get_drvdata(pdev->dev.parent);
> >+
> >+	driver_data = devm_kzalloc(&pdev->dev,
> >+				sizeof(struct menf21bmc_wd_data), GFP_KERNEL);
> >+	if (!driver_data)
> >+		return -ENOMEM;
> >+
> >+	driver_data->menf21bmc = menf21bmc;
> >+
> >+	menf21bmc_wd = &driver_data->wdt;
> >+	menf21bmc_wd->ops = &menf21bmc_wd_ops;
> >+	menf21bmc_wd->info = &menf21bmc_wd_info;
> >+	menf21bmc_wd->min_timeout = BMC_WD_TIMEOUT_MIN;
> >+	menf21bmc_wd->max_timeout = BMC_WD_TIMEOUT_MAX;
> >+
> >+
> Please no more than one empty line.

arg, i thought I've catched them all but missed one.

> 
> >+	/*
> >+	 * Get the current wdt timeout value from the BMC because
> >+	 * the BMC will save the value set before if the system restarts.
> >+	 */
> >+	ret = menf21bmc->read_word_data(menf21bmc->client,
> >+					 BMC_CMD_WD_TIME, &bmc_timeout);
> >+	if (ret < 0) {
> >+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
> >+		return ret;
> >+	}
> >+
> >+	watchdog_init_timeout(menf21bmc_wd, bmc_timeout / 10, &pdev->dev);
> >+
> >+	watchdog_set_nowayout(menf21bmc_wd, nowayout);
> >+	watchdog_set_drvdata(menf21bmc_wd, driver_data);
> >+	platform_set_drvdata(pdev, driver_data);
> >+
> >+	/*
> >+	 * We have to leave the Production Mode of the BMC to activate the
> >+	 * Watchdog functionality.
> >+	 */
> >+	ret = menf21bmc_wd_leave_prod_mode(pdev);
> >+	if (ret < 0) {
> >+		dev_err(&pdev->dev, "failed to leave production mode\n");
> >+		return ret;
> >+	}
> >+
> Shouldn't this be in the mfd code ?

Yes and no :-)
The Production mode needs to be left just to activate the watchdog. That is the
reason why I've put these code inside of the watchdog driver.

The other thing is, that we leave the prodcution which is related to the whole BMC,
so may be it is really better to put this in the mfd core.

I think I will put it in the mfd core.

> 
> 
> >+	ret = menf21bmc_wd_set_bootstatus(driver_data);
> >+	if (ret < 0) {
> >+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
> >+		return ret;
> >+	}
> >+
> >+	ret = watchdog_register_device(&driver_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_wd_remove(struct platform_device *pdev)
> >+{
> >+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> >+
> >+	dev_warn(&pdev->dev,
> >+		"Untregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
> >+
> >+	watchdog_unregister_device(&data->wdt);
> >+
> >+	return 0;
> >+}
> >+
> >+static void menf21bmc_wd_shutdown(struct platform_device *pdev)
> >+{
> >+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	menf21bmc->write_word_data(menf21bmc->client,
> >+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
> >+}
> >+
> >+static struct  platform_driver menf21bmc_wd = {
> >+	.driver		= {
> >+		.owner = THIS_MODULE,
> >+		.name	= DEVNAME,
> >+	},
> >+	.probe		= menf21bmc_wd_probe,
> >+	.remove		= menf21bmc_wd_remove,
> >+	.shutdown	= menf21bmc_wd_shutdown,
> >+};
> >+
> >+module_platform_driver(menf21bmc_wd);
> >+
> >+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
> >+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> >+MODULE_LICENSE("GPL");
> >+MODULE_ALIAS("platform:menf21bmc_wd");
> >
> 

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

* Re: [PATCH 2/3] drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog driver
@ 2014-05-19 12:20       ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-19 12:20 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Sat, May 17, 2014 at 08:57:27AM -0700, Guenter Roeck wrote:
> On 05/16/2014 09:37 AM, Andreas Werner wrote:
> >Added driver to support the 14F021P00 BMC Watchdog.
> >The BMC is a Board Management Controller including watchdog functionality.
> >
> >This driver use the I2C interface to the BMC using the menf21bmc MFD Core driver.
> >
> >Signed-off-by: Andreas Werner <andreas.werner@men.de>
> >---
> >  drivers/watchdog/Kconfig        |   7 ++
> >  drivers/watchdog/Makefile       |   1 +
> >  drivers/watchdog/menf21bmc_wd.c | 263 ++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 271 insertions(+)
> >  create mode 100644 drivers/watchdog/menf21bmc_wd.c
> >
> >diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> >index 2b4c1fc..ede3201 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 1b5f3d5..0a5465d 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_wd.o
> >diff --git a/drivers/watchdog/menf21bmc_wd.c b/drivers/watchdog/menf21bmc_wd.c
> >new file mode 100644
> >index 0000000..31ccea8
> >--- /dev/null
> >+++ b/drivers/watchdog/menf21bmc_wd.c
> >@@ -0,0 +1,263 @@
> >+/*
> >+ *  MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver.
> >+ *
> >+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> >+ *  Author: Andreas Werner <andreas.werner@men.de>
> >+ *  All rights reserved.
> >+ *
> >+ *  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/mfd/menf21bmc.h>
> >+
> >+#define DEVNAME "menf21bmc_wd"
> >+
> >+#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_CMD_WD_ARM_SET	0x18
> >+#define BMC_CMD_WD_ARM_GET	0x19
> >+#define BMC_CMD_ARM_STATE	0x19
> >+#define BMC_WD_OFF_VAL		0x69
> >+#define BMC_CMD_RST_RSN		0x92
> >+
> >+#define BMC_WD_TIMEOUT_MIN	1	/*  in sec -> BMC min = 0.1 s */
> 
> I find the comment a bit confusing. The timeout is in seconds. The BMC minimum
> timeout may be 0.1s, but that is not reflected in the define. Maybe replace
> the comment with something like
> 					/* in sec (BMC min = 0.1 s) */

OK. I think I just write /* in sec */ as the comment because
it is explained in menf21bmc_wd_settimout() function.

> 
> >+#define BMC_WD_TIMEOUT_MAX	6553	/*  in sec -> BMC max = 6553,5 s */
> >+
> >+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_wd_data {
> >+	struct watchdog_device wdt;
> >+	struct menf21bmc *menf21bmc;
> >+};
> >+
> >+static int menf21bmc_wd_set_bootstatus(struct menf21bmc_wd_data *data)
> >+{
> >+	u8 rst_rsn;
> >+	int ret;
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	ret = menf21bmc->read_byte_data(menf21bmc->client,
> >+						BMC_CMD_RST_RSN, &rst_rsn);
> >+	if (ret < 0)
> >+		return -EIO;
> >+
> Please return the original error.
I agree, will be changed.
> 
> >+	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_wd_leave_prod_mode(struct platform_device *pdev)
> >+{
> >+	int ret;
> >+	uint8_t val;
> >+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	ret = menf21bmc->read_byte_data(menf21bmc->client,
> >+						BMC_CMD_WD_ARM_GET, &val);
> >+	if (ret < 0)
> >+		return -EIO;
> >+
> Please return the original error.

I agree, will be changed.

> 
> >+	/*
> >+	 * Production mode should be not active after delivery of the Board.
> >+	 * To be sure we check it, inform the user and leave the mode
> >+	 * if active.
> >+	 */
> >+	if (val == 0x00) {
> >+		dev_info(&pdev->dev,
> >+			"BMC in production mode. Leave production mode\n");
> >+
> >+		ret = menf21bmc->write_byte(menf21bmc->client,
> >+							BMC_CMD_WD_ARM_SET);
> >+		if (ret < 0)
> >+			return -EIO;
> 
> Please return the original error.

I agree, will be changed.

> 
> >+	}
> >+
> >+	return 0;
> >+}
> >+
> >+static int menf21bmc_wd_start(struct watchdog_device *wdt)
> >+{
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_ON);
> >+}
> >+
> >+static int menf21bmc_wd_stop(struct watchdog_device *wdt)
> >+{
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	return menf21bmc->write_byte_data(menf21bmc->client,
> >+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
> >+}
> >+
> >+static int
> >+menf21bmc_wd_settimeout(struct watchdog_device *wdt, unsigned int timeout)
> >+{
> >+	int ret;
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	/*
> >+	 *  BMC Watchdog does have a resolution of 100ms.
> >+	 *  Watchdog API defines the timeout in seconds, so we have to
> >+	 *  multiply the value.
> >+	 */
> >+	ret = menf21bmc->write_word_data(menf21bmc->client,
> >+						BMC_CMD_WD_TIME, timeout * 10);
> >+	if (ret < 0)
> >+		return -EIO;
> >+
> Please return the original error.

I agree, will be changed.

> 
> >+	wdt->timeout = timeout;
> >+
> >+	return 0;
> >+}
> >+
> >+static int menf21bmc_wd_ping(struct watchdog_device *wdt)
> >+{
> >+	struct menf21bmc_wd_data *data = watchdog_get_drvdata(wdt);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	return menf21bmc->write_byte(menf21bmc->client, BMC_CMD_WD_TRIG);
> >+}
> >+
> >+static const struct watchdog_info menf21bmc_wd_info = {
> >+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
> >+	.identity = DEVNAME,
> >+};
> >+
> >+static const struct watchdog_ops menf21bmc_wd_ops = {
> >+	.owner		= THIS_MODULE,
> >+	.start		= menf21bmc_wd_start,
> >+	.stop		= menf21bmc_wd_stop,
> >+	.ping		= menf21bmc_wd_ping,
> >+	.set_timeout	= menf21bmc_wd_settimeout,
> >+};
> >+
> >+static int menf21bmc_wd_probe(struct platform_device *pdev)
> >+{
> >+	int ret;
> >+	uint16_t bmc_timeout;
> >+	struct menf21bmc_wd_data *driver_data;
> >+	struct watchdog_device *menf21bmc_wd;
> >+	struct menf21bmc *menf21bmc = dev_get_drvdata(pdev->dev.parent);
> >+
> >+	driver_data = devm_kzalloc(&pdev->dev,
> >+				sizeof(struct menf21bmc_wd_data), GFP_KERNEL);
> >+	if (!driver_data)
> >+		return -ENOMEM;
> >+
> >+	driver_data->menf21bmc = menf21bmc;
> >+
> >+	menf21bmc_wd = &driver_data->wdt;
> >+	menf21bmc_wd->ops = &menf21bmc_wd_ops;
> >+	menf21bmc_wd->info = &menf21bmc_wd_info;
> >+	menf21bmc_wd->min_timeout = BMC_WD_TIMEOUT_MIN;
> >+	menf21bmc_wd->max_timeout = BMC_WD_TIMEOUT_MAX;
> >+
> >+
> Please no more than one empty line.

arg, i thought I've catched them all but missed one.

> 
> >+	/*
> >+	 * Get the current wdt timeout value from the BMC because
> >+	 * the BMC will save the value set before if the system restarts.
> >+	 */
> >+	ret = menf21bmc->read_word_data(menf21bmc->client,
> >+					 BMC_CMD_WD_TIME, &bmc_timeout);
> >+	if (ret < 0) {
> >+		dev_err(&pdev->dev, "failed to get current WDT timeout\n");
> >+		return ret;
> >+	}
> >+
> >+	watchdog_init_timeout(menf21bmc_wd, bmc_timeout / 10, &pdev->dev);
> >+
> >+	watchdog_set_nowayout(menf21bmc_wd, nowayout);
> >+	watchdog_set_drvdata(menf21bmc_wd, driver_data);
> >+	platform_set_drvdata(pdev, driver_data);
> >+
> >+	/*
> >+	 * We have to leave the Production Mode of the BMC to activate the
> >+	 * Watchdog functionality.
> >+	 */
> >+	ret = menf21bmc_wd_leave_prod_mode(pdev);
> >+	if (ret < 0) {
> >+		dev_err(&pdev->dev, "failed to leave production mode\n");
> >+		return ret;
> >+	}
> >+
> Shouldn't this be in the mfd code ?

Yes and no :-)
The Production mode needs to be left just to activate the watchdog. That is the
reason why I've put these code inside of the watchdog driver.

The other thing is, that we leave the prodcution which is related to the whole BMC,
so may be it is really better to put this in the mfd core.

I think I will put it in the mfd core.

> 
> 
> >+	ret = menf21bmc_wd_set_bootstatus(driver_data);
> >+	if (ret < 0) {
> >+		dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n");
> >+		return ret;
> >+	}
> >+
> >+	ret = watchdog_register_device(&driver_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_wd_remove(struct platform_device *pdev)
> >+{
> >+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> >+
> >+	dev_warn(&pdev->dev,
> >+		"Untregister MEN 14F021P00 BMC Watchdog device, board may reset\n");
> >+
> >+	watchdog_unregister_device(&data->wdt);
> >+
> >+	return 0;
> >+}
> >+
> >+static void menf21bmc_wd_shutdown(struct platform_device *pdev)
> >+{
> >+	struct menf21bmc_wd_data *data = platform_get_drvdata(pdev);
> >+	struct menf21bmc *menf21bmc = data->menf21bmc;
> >+
> >+	menf21bmc->write_word_data(menf21bmc->client,
> >+					BMC_CMD_WD_OFF, BMC_WD_OFF_VAL);
> >+}
> >+
> >+static struct  platform_driver menf21bmc_wd = {
> >+	.driver		= {
> >+		.owner = THIS_MODULE,
> >+		.name	= DEVNAME,
> >+	},
> >+	.probe		= menf21bmc_wd_probe,
> >+	.remove		= menf21bmc_wd_remove,
> >+	.shutdown	= menf21bmc_wd_shutdown,
> >+};
> >+
> >+module_platform_driver(menf21bmc_wd);
> >+
> >+MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver");
> >+MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
> >+MODULE_LICENSE("GPL");
> >+MODULE_ALIAS("platform:menf21bmc_wd");
> >
> 

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-17 15:47   ` Guenter Roeck
@ 2014-05-19 12:43       ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-19 12:43 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
> On 05/16/2014 09:37 AM, 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
> >
> >Signed-off-by: Andreas Werner <andreas.werner@men.de>
> >---
> >  drivers/mfd/Kconfig           |  12 +++
> >  drivers/mfd/Makefile          |   1 +
> >  drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/mfd/menf21bmc.h |  32 +++++++
> >  4 files changed, 238 insertions(+)
> >  create mode 100644 drivers/mfd/menf21bmc.c
> >  create mode 100644 include/linux/mfd/menf21bmc.h
> >
> >diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> >index ab5a43c..7c2e8d2 100644
> >--- a/drivers/mfd/Kconfig
> >+++ b/drivers/mfd/Kconfig
> >@@ -427,6 +427,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.
> >+	  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 5913208..8f2be38 100644
> >--- a/drivers/mfd/Makefile
> >+++ b/drivers/mfd/Makefile
> >@@ -167,3 +167,4 @@ 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
> >diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> >new file mode 100644
> >index 0000000..77de1a8
> >--- /dev/null
> >+++ b/drivers/mfd/menf21bmc.c
> >@@ -0,0 +1,193 @@
> >+/*
> >+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> >+ *
> >+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> >+ *  Author: Andreas Werner <andreas.werner@men.de>
> >+ *  All rights reserved.
> >+ *
> >+ *  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>
> >+#include <linux/mfd/menf21bmc.h>
> >+
> >+#define BMC_CMD_REV_MAJOR	0x80
> >+#define BMC_CMD_REV_MINOR	0x81
> >+#define BMC_CMD_REV_MAIN	0x82
> >+#define BMC_CMD_REV_BUILD	0x83
> >+#define BMC_CMD_REV_VERI	0x84
> >+
> >+static struct mfd_cell menf21bmc_cell[] = {
> >+	{
> >+		.name = "menf21bmc_wd",
> >+	},
> >+	{
> >+		.name = "menf21bmc_led",
> >+	},
> >+};
> >+
> >+static int
> >+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> >+{
> >+	int ret;
> >+	struct menf21bmc *data = i2c_get_clientdata(client);
> >+
> >+	mutex_lock(&data->lock);
> >+	ret = i2c_smbus_read_byte_data(client, reg);
> >+	mutex_unlock(&data->lock);
> >+
> >+	if (ret < 0) {
> >+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> >+		return ret;
> >+	}
> >+
> >+	*val = (uint8_t)ret;
> >+
> >+	return 0;
> >+}
> >+
> I personally would prefer if you would retain the original API, which returns both value
> and error code as return value. I don't see the benefit of changing the API as you did -
> it just complicates the code.
> 
> Thanks,
> Guenter
> 
I think it is ok for a wrapper like this because it does not really change an API because
it is menf21bmc related.

I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.

I personally prefer this way because the return of the function and the return 
value of the i2c_smbus_read - which is the value read from the device - are seperated.

If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
If it is ok on your side for a wrapper like this, we can let it as it is.

Thanks
Andy

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-05-19 12:43       ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-19 12:43 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, lee.jones, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
> On 05/16/2014 09:37 AM, 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
> >
> >Signed-off-by: Andreas Werner <andreas.werner@men.de>
> >---
> >  drivers/mfd/Kconfig           |  12 +++
> >  drivers/mfd/Makefile          |   1 +
> >  drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/mfd/menf21bmc.h |  32 +++++++
> >  4 files changed, 238 insertions(+)
> >  create mode 100644 drivers/mfd/menf21bmc.c
> >  create mode 100644 include/linux/mfd/menf21bmc.h
> >
> >diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> >index ab5a43c..7c2e8d2 100644
> >--- a/drivers/mfd/Kconfig
> >+++ b/drivers/mfd/Kconfig
> >@@ -427,6 +427,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.
> >+	  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 5913208..8f2be38 100644
> >--- a/drivers/mfd/Makefile
> >+++ b/drivers/mfd/Makefile
> >@@ -167,3 +167,4 @@ 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
> >diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> >new file mode 100644
> >index 0000000..77de1a8
> >--- /dev/null
> >+++ b/drivers/mfd/menf21bmc.c
> >@@ -0,0 +1,193 @@
> >+/*
> >+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> >+ *
> >+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> >+ *  Author: Andreas Werner <andreas.werner@men.de>
> >+ *  All rights reserved.
> >+ *
> >+ *  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>
> >+#include <linux/mfd/menf21bmc.h>
> >+
> >+#define BMC_CMD_REV_MAJOR	0x80
> >+#define BMC_CMD_REV_MINOR	0x81
> >+#define BMC_CMD_REV_MAIN	0x82
> >+#define BMC_CMD_REV_BUILD	0x83
> >+#define BMC_CMD_REV_VERI	0x84
> >+
> >+static struct mfd_cell menf21bmc_cell[] = {
> >+	{
> >+		.name = "menf21bmc_wd",
> >+	},
> >+	{
> >+		.name = "menf21bmc_led",
> >+	},
> >+};
> >+
> >+static int
> >+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> >+{
> >+	int ret;
> >+	struct menf21bmc *data = i2c_get_clientdata(client);
> >+
> >+	mutex_lock(&data->lock);
> >+	ret = i2c_smbus_read_byte_data(client, reg);
> >+	mutex_unlock(&data->lock);
> >+
> >+	if (ret < 0) {
> >+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> >+		return ret;
> >+	}
> >+
> >+	*val = (uint8_t)ret;
> >+
> >+	return 0;
> >+}
> >+
> I personally would prefer if you would retain the original API, which returns both value
> and error code as return value. I don't see the benefit of changing the API as you did -
> it just complicates the code.
> 
> Thanks,
> Guenter
> 
I think it is ok for a wrapper like this because it does not really change an API because
it is menf21bmc related.

I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.

I personally prefer this way because the return of the function and the return 
value of the i2c_smbus_read - which is the value read from the device - are seperated.

If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
If it is ok on your side for a wrapper like this, we can let it as it is.

Thanks
Andy


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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-19 12:43       ` Andreas Werner
  (?)
@ 2014-05-19 13:23       ` Guenter Roeck
  2014-05-19 17:39         ` Lee Jones
  -1 siblings, 1 reply; 21+ messages in thread
From: Guenter Roeck @ 2014-05-19 13:23 UTC (permalink / raw)
  To: Andreas Werner
  Cc: linux-kernel, sameo, lee.jones, wim, linux-watchdog, cooloney,
	rpurdie, linux-leds, johannes.thumshirn, thomas.schnuerer,
	wernerandy

On 05/19/2014 05:43 AM, Andreas Werner wrote:
> aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
>> On 05/16/2014 09:37 AM, 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
>>>
>>> Signed-off-by: Andreas Werner <andreas.werner@men.de>
>>> ---
>>>   drivers/mfd/Kconfig           |  12 +++
>>>   drivers/mfd/Makefile          |   1 +
>>>   drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
>>>   include/linux/mfd/menf21bmc.h |  32 +++++++
>>>   4 files changed, 238 insertions(+)
>>>   create mode 100644 drivers/mfd/menf21bmc.c
>>>   create mode 100644 include/linux/mfd/menf21bmc.h
>>>
>>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>>> index ab5a43c..7c2e8d2 100644
>>> --- a/drivers/mfd/Kconfig
>>> +++ b/drivers/mfd/Kconfig
>>> @@ -427,6 +427,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.
>>> +	  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 5913208..8f2be38 100644
>>> --- a/drivers/mfd/Makefile
>>> +++ b/drivers/mfd/Makefile
>>> @@ -167,3 +167,4 @@ 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
>>> diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
>>> new file mode 100644
>>> index 0000000..77de1a8
>>> --- /dev/null
>>> +++ b/drivers/mfd/menf21bmc.c
>>> @@ -0,0 +1,193 @@
>>> +/*
>>> + *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
>>> + *
>>> + *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
>>> + *  Author: Andreas Werner <andreas.werner@men.de>
>>> + *  All rights reserved.
>>> + *
>>> + *  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>
>>> +#include <linux/mfd/menf21bmc.h>
>>> +
>>> +#define BMC_CMD_REV_MAJOR	0x80
>>> +#define BMC_CMD_REV_MINOR	0x81
>>> +#define BMC_CMD_REV_MAIN	0x82
>>> +#define BMC_CMD_REV_BUILD	0x83
>>> +#define BMC_CMD_REV_VERI	0x84
>>> +
>>> +static struct mfd_cell menf21bmc_cell[] = {
>>> +	{
>>> +		.name = "menf21bmc_wd",
>>> +	},
>>> +	{
>>> +		.name = "menf21bmc_led",
>>> +	},
>>> +};
>>> +
>>> +static int
>>> +menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
>>> +{
>>> +	int ret;
>>> +	struct menf21bmc *data = i2c_get_clientdata(client);
>>> +
>>> +	mutex_lock(&data->lock);
>>> +	ret = i2c_smbus_read_byte_data(client, reg);
>>> +	mutex_unlock(&data->lock);
>>> +
>>> +	if (ret < 0) {
>>> +		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
>>> +		return ret;
>>> +	}
>>> +
>>> +	*val = (uint8_t)ret;
>>> +
>>> +	return 0;
>>> +}
>>> +
>> I personally would prefer if you would retain the original API, which returns both value
>> and error code as return value. I don't see the benefit of changing the API as you did -
>> it just complicates the code.
>>
>> Thanks,
>> Guenter
>>
> I think it is ok for a wrapper like this because it does not really change an API because
> it is menf21bmc related.
>
> I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.
>
> I personally prefer this way because the return of the function and the return
> value of the i2c_smbus_read - which is the value read from the device - are seperated.
>
> If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
> If it is ok on your side for a wrapper like this, we can let it as it is.
>

Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
as unnecessary, adding complexity, and pointless. Sure, you can always find examples
for everything somewhere in the kernel, but that doesn't make it better.

Guenter

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-19 13:23       ` Guenter Roeck
@ 2014-05-19 17:39         ` Lee Jones
  2014-05-20  7:47             ` Andreas Werner
  0 siblings, 1 reply; 21+ messages in thread
From: Lee Jones @ 2014-05-19 17:39 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andreas Werner, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, johannes.thumshirn,
	thomas.schnuerer, wernerandy

On Mon, 19 May 2014, Guenter Roeck wrote:

> On 05/19/2014 05:43 AM, Andreas Werner wrote:
> >aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
> >>On 05/16/2014 09:37 AM, 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
> >>>
> >>>Signed-off-by: Andreas Werner <andreas.werner@men.de>
> >>>---
> >>>  drivers/mfd/Kconfig           |  12 +++
> >>>  drivers/mfd/Makefile          |   1 +
> >>>  drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
> >>>  include/linux/mfd/menf21bmc.h |  32 +++++++
> >>>  4 files changed, 238 insertions(+)
> >>>  create mode 100644 drivers/mfd/menf21bmc.c
> >>>  create mode 100644 include/linux/mfd/menf21bmc.h
> >>>
> >>>diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> >>>index ab5a43c..7c2e8d2 100644
> >>>--- a/drivers/mfd/Kconfig
> >>>+++ b/drivers/mfd/Kconfig
> >>>@@ -427,6 +427,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.
> >>>+	  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 5913208..8f2be38 100644
> >>>--- a/drivers/mfd/Makefile
> >>>+++ b/drivers/mfd/Makefile
> >>>@@ -167,3 +167,4 @@ 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
> >>>diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> >>>new file mode 100644
> >>>index 0000000..77de1a8
> >>>--- /dev/null
> >>>+++ b/drivers/mfd/menf21bmc.c
> >>>@@ -0,0 +1,193 @@
> >>>+/*
> >>>+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> >>>+ *
> >>>+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> >>>+ *  Author: Andreas Werner <andreas.werner@men.de>
> >>>+ *  All rights reserved.
> >>>+ *
> >>>+ *  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>
> >>>+#include <linux/mfd/menf21bmc.h>
> >>>+
> >>>+#define BMC_CMD_REV_MAJOR	0x80
> >>>+#define BMC_CMD_REV_MINOR	0x81
> >>>+#define BMC_CMD_REV_MAIN	0x82
> >>>+#define BMC_CMD_REV_BUILD	0x83
> >>>+#define BMC_CMD_REV_VERI	0x84
> >>>+
> >>>+static struct mfd_cell menf21bmc_cell[] = {
> >>>+	{
> >>>+		.name = "menf21bmc_wd",
> >>>+	},
> >>>+	{
> >>>+		.name = "menf21bmc_led",
> >>>+	},
> >>>+};
> >>>+
> >>>+static int
> >>>+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> >>>+{
> >>>+	int ret;
> >>>+	struct menf21bmc *data = i2c_get_clientdata(client);
> >>>+
> >>>+	mutex_lock(&data->lock);
> >>>+	ret = i2c_smbus_read_byte_data(client, reg);
> >>>+	mutex_unlock(&data->lock);
> >>>+
> >>>+	if (ret < 0) {
> >>>+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> >>>+		return ret;
> >>>+	}
> >>>+
> >>>+	*val = (uint8_t)ret;
> >>>+
> >>>+	return 0;
> >>>+}
> >>>+
> >>I personally would prefer if you would retain the original API, which returns both value
> >>and error code as return value. I don't see the benefit of changing the API as you did -
> >>it just complicates the code.
> >>
> >>Thanks,
> >>Guenter
> >>
> >I think it is ok for a wrapper like this because it does not really change an API because
> >it is menf21bmc related.
> >
> >I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.
> >
> >I personally prefer this way because the return of the function and the return
> >value of the i2c_smbus_read - which is the value read from the device - are seperated.
> >
> >If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
> >If it is ok on your side for a wrapper like this, we can let it as it is.
> >
> 
> Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
> as unnecessary, adding complexity, and pointless. Sure, you can always find examples
> for everything somewhere in the kernel, but that doesn't make it better.

I'm inclined to agree with Guenter, this patch is just noise.

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-20  7:47             ` Andreas Werner
@ 2014-05-20  7:06               ` Lee Jones
  -1 siblings, 0 replies; 21+ messages in thread
From: Lee Jones @ 2014-05-20  7:06 UTC (permalink / raw)
  To: Andreas Werner
  Cc: Guenter Roeck, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, johannes.thumshirn,
	thomas.schnuerer, wernerandy

> > > Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
> > > as unnecessary, adding complexity, and pointless. Sure, you can always find examples
> > > for everything somewhere in the kernel, but that doesn't make it better.
> > 
> > I'm inclined to agree with Guenter, this patch is just noise.
> 
> Ok no problem, i will fix it and resend the patch.
> For now I know it for the future :-)
> 
> Any other comments about the patch series?

If you submit a v2, I'll re-review the bits you leave in.

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-05-20  7:06               ` Lee Jones
  0 siblings, 0 replies; 21+ messages in thread
From: Lee Jones @ 2014-05-20  7:06 UTC (permalink / raw)
  To: Andreas Werner
  Cc: Guenter Roeck, linux-kernel, sameo, wim, linux-watchdog,
	cooloney, rpurdie, linux-leds, johannes.thumshirn,
	thomas.schnuerer, wernerandy

> > > Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
> > > as unnecessary, adding complexity, and pointless. Sure, you can always find examples
> > > for everything somewhere in the kernel, but that doesn't make it better.
> > 
> > I'm inclined to agree with Guenter, this patch is just noise.
> 
> Ok no problem, i will fix it and resend the patch.
> For now I know it for the future :-)
> 
> Any other comments about the patch series?

If you submit a v2, I'll re-review the bits you leave in.

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
  2014-05-19 17:39         ` Lee Jones
  2014-05-20  7:47             ` Andreas Werner
@ 2014-05-20  7:47             ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-20  7:47 UTC (permalink / raw)
  To: Lee Jones
  Cc: Guenter Roeck, Andreas Werner, linux-kernel, sameo, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Mon, May 19, 2014 at 06:39:53PM +0100, Lee Jones wrote:
> On Mon, 19 May 2014, Guenter Roeck wrote:
> 
> > On 05/19/2014 05:43 AM, Andreas Werner wrote:
> > >aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
> > >>On 05/16/2014 09:37 AM, 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
> > >>>
> > >>>Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > >>>---
> > >>>  drivers/mfd/Kconfig           |  12 +++
> > >>>  drivers/mfd/Makefile          |   1 +
> > >>>  drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
> > >>>  include/linux/mfd/menf21bmc.h |  32 +++++++
> > >>>  4 files changed, 238 insertions(+)
> > >>>  create mode 100644 drivers/mfd/menf21bmc.c
> > >>>  create mode 100644 include/linux/mfd/menf21bmc.h
> > >>>
> > >>>diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > >>>index ab5a43c..7c2e8d2 100644
> > >>>--- a/drivers/mfd/Kconfig
> > >>>+++ b/drivers/mfd/Kconfig
> > >>>@@ -427,6 +427,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.
> > >>>+	  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 5913208..8f2be38 100644
> > >>>--- a/drivers/mfd/Makefile
> > >>>+++ b/drivers/mfd/Makefile
> > >>>@@ -167,3 +167,4 @@ 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
> > >>>diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> > >>>new file mode 100644
> > >>>index 0000000..77de1a8
> > >>>--- /dev/null
> > >>>+++ b/drivers/mfd/menf21bmc.c
> > >>>@@ -0,0 +1,193 @@
> > >>>+/*
> > >>>+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> > >>>+ *
> > >>>+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > >>>+ *  Author: Andreas Werner <andreas.werner@men.de>
> > >>>+ *  All rights reserved.
> > >>>+ *
> > >>>+ *  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>
> > >>>+#include <linux/mfd/menf21bmc.h>
> > >>>+
> > >>>+#define BMC_CMD_REV_MAJOR	0x80
> > >>>+#define BMC_CMD_REV_MINOR	0x81
> > >>>+#define BMC_CMD_REV_MAIN	0x82
> > >>>+#define BMC_CMD_REV_BUILD	0x83
> > >>>+#define BMC_CMD_REV_VERI	0x84
> > >>>+
> > >>>+static struct mfd_cell menf21bmc_cell[] = {
> > >>>+	{
> > >>>+		.name = "menf21bmc_wd",
> > >>>+	},
> > >>>+	{
> > >>>+		.name = "menf21bmc_led",
> > >>>+	},
> > >>>+};
> > >>>+
> > >>>+static int
> > >>>+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> > >>>+{
> > >>>+	int ret;
> > >>>+	struct menf21bmc *data = i2c_get_clientdata(client);
> > >>>+
> > >>>+	mutex_lock(&data->lock);
> > >>>+	ret = i2c_smbus_read_byte_data(client, reg);
> > >>>+	mutex_unlock(&data->lock);
> > >>>+
> > >>>+	if (ret < 0) {
> > >>>+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> > >>>+		return ret;
> > >>>+	}
> > >>>+
> > >>>+	*val = (uint8_t)ret;
> > >>>+
> > >>>+	return 0;
> > >>>+}
> > >>>+
> > >>I personally would prefer if you would retain the original API, which returns both value
> > >>and error code as return value. I don't see the benefit of changing the API as you did -
> > >>it just complicates the code.
> > >>
> > >>Thanks,
> > >>Guenter
> > >>
> > >I think it is ok for a wrapper like this because it does not really change an API because
> > >it is menf21bmc related.
> > >
> > >I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.
> > >
> > >I personally prefer this way because the return of the function and the return
> > >value of the i2c_smbus_read - which is the value read from the device - are seperated.
> > >
> > >If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
> > >If it is ok on your side for a wrapper like this, we can let it as it is.
> > >
> > 
> > Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
> > as unnecessary, adding complexity, and pointless. Sure, you can always find examples
> > for everything somewhere in the kernel, but that doesn't make it better.
> 
> I'm inclined to agree with Guenter, this patch is just noise.

Ok no problem, i will fix it and resend the patch.
For now I know it for the future :-)

Any other comments about the patch series?

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

Regards
Andy

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-05-20  7:47             ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-20  7:47 UTC (permalink / raw)
  To: Lee Jones
  Cc: Guenter Roeck, Andreas Werner, linux-kernel, sameo, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Mon, May 19, 2014 at 06:39:53PM +0100, Lee Jones wrote:
> On Mon, 19 May 2014, Guenter Roeck wrote:
> 
> > On 05/19/2014 05:43 AM, Andreas Werner wrote:
> > >aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
> > >>On 05/16/2014 09:37 AM, 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
> > >>>
> > >>>Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > >>>---
> > >>>  drivers/mfd/Kconfig           |  12 +++
> > >>>  drivers/mfd/Makefile          |   1 +
> > >>>  drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
> > >>>  include/linux/mfd/menf21bmc.h |  32 +++++++
> > >>>  4 files changed, 238 insertions(+)
> > >>>  create mode 100644 drivers/mfd/menf21bmc.c
> > >>>  create mode 100644 include/linux/mfd/menf21bmc.h
> > >>>
> > >>>diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > >>>index ab5a43c..7c2e8d2 100644
> > >>>--- a/drivers/mfd/Kconfig
> > >>>+++ b/drivers/mfd/Kconfig
> > >>>@@ -427,6 +427,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.
> > >>>+	  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 5913208..8f2be38 100644
> > >>>--- a/drivers/mfd/Makefile
> > >>>+++ b/drivers/mfd/Makefile
> > >>>@@ -167,3 +167,4 @@ 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
> > >>>diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> > >>>new file mode 100644
> > >>>index 0000000..77de1a8
> > >>>--- /dev/null
> > >>>+++ b/drivers/mfd/menf21bmc.c
> > >>>@@ -0,0 +1,193 @@
> > >>>+/*
> > >>>+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> > >>>+ *
> > >>>+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > >>>+ *  Author: Andreas Werner <andreas.werner@men.de>
> > >>>+ *  All rights reserved.
> > >>>+ *
> > >>>+ *  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>
> > >>>+#include <linux/mfd/menf21bmc.h>
> > >>>+
> > >>>+#define BMC_CMD_REV_MAJOR	0x80
> > >>>+#define BMC_CMD_REV_MINOR	0x81
> > >>>+#define BMC_CMD_REV_MAIN	0x82
> > >>>+#define BMC_CMD_REV_BUILD	0x83
> > >>>+#define BMC_CMD_REV_VERI	0x84
> > >>>+
> > >>>+static struct mfd_cell menf21bmc_cell[] = {
> > >>>+	{
> > >>>+		.name = "menf21bmc_wd",
> > >>>+	},
> > >>>+	{
> > >>>+		.name = "menf21bmc_led",
> > >>>+	},
> > >>>+};
> > >>>+
> > >>>+static int
> > >>>+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> > >>>+{
> > >>>+	int ret;
> > >>>+	struct menf21bmc *data = i2c_get_clientdata(client);
> > >>>+
> > >>>+	mutex_lock(&data->lock);
> > >>>+	ret = i2c_smbus_read_byte_data(client, reg);
> > >>>+	mutex_unlock(&data->lock);
> > >>>+
> > >>>+	if (ret < 0) {
> > >>>+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> > >>>+		return ret;
> > >>>+	}
> > >>>+
> > >>>+	*val = (uint8_t)ret;
> > >>>+
> > >>>+	return 0;
> > >>>+}
> > >>>+
> > >>I personally would prefer if you would retain the original API, which returns both value
> > >>and error code as return value. I don't see the benefit of changing the API as you did -
> > >>it just complicates the code.
> > >>
> > >>Thanks,
> > >>Guenter
> > >>
> > >I think it is ok for a wrapper like this because it does not really change an API because
> > >it is menf21bmc related.
> > >
> > >I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.
> > >
> > >I personally prefer this way because the return of the function and the return
> > >value of the i2c_smbus_read - which is the value read from the device - are seperated.
> > >
> > >If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
> > >If it is ok on your side for a wrapper like this, we can let it as it is.
> > >
> > 
> > Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
> > as unnecessary, adding complexity, and pointless. Sure, you can always find examples
> > for everything somewhere in the kernel, but that doesn't make it better.
> 
> I'm inclined to agree with Guenter, this patch is just noise.

Ok no problem, i will fix it and resend the patch.
For now I know it for the future :-)

Any other comments about the patch series?

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

Regards
Andy

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

* Re: [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver
@ 2014-05-20  7:47             ` Andreas Werner
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Werner @ 2014-05-20  7:47 UTC (permalink / raw)
  To: Lee Jones
  Cc: Guenter Roeck, Andreas Werner, linux-kernel, sameo, wim,
	linux-watchdog, cooloney, rpurdie, linux-leds,
	johannes.thumshirn, thomas.schnuerer, wernerandy

aOn Mon, May 19, 2014 at 06:39:53PM +0100, Lee Jones wrote:
> On Mon, 19 May 2014, Guenter Roeck wrote:
> 
> > On 05/19/2014 05:43 AM, Andreas Werner wrote:
> > >aOn Sat, May 17, 2014 at 08:47:42AM -0700, Guenter Roeck wrote:
> > >>On 05/16/2014 09:37 AM, 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
> > >>>
> > >>>Signed-off-by: Andreas Werner <andreas.werner@men.de>
> > >>>---
> > >>>  drivers/mfd/Kconfig           |  12 +++
> > >>>  drivers/mfd/Makefile          |   1 +
> > >>>  drivers/mfd/menf21bmc.c       | 193 ++++++++++++++++++++++++++++++++++++++++++
> > >>>  include/linux/mfd/menf21bmc.h |  32 +++++++
> > >>>  4 files changed, 238 insertions(+)
> > >>>  create mode 100644 drivers/mfd/menf21bmc.c
> > >>>  create mode 100644 include/linux/mfd/menf21bmc.h
> > >>>
> > >>>diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > >>>index ab5a43c..7c2e8d2 100644
> > >>>--- a/drivers/mfd/Kconfig
> > >>>+++ b/drivers/mfd/Kconfig
> > >>>@@ -427,6 +427,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.
> > >>>+	  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 5913208..8f2be38 100644
> > >>>--- a/drivers/mfd/Makefile
> > >>>+++ b/drivers/mfd/Makefile
> > >>>@@ -167,3 +167,4 @@ 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
> > >>>diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
> > >>>new file mode 100644
> > >>>index 0000000..77de1a8
> > >>>--- /dev/null
> > >>>+++ b/drivers/mfd/menf21bmc.c
> > >>>@@ -0,0 +1,193 @@
> > >>>+/*
> > >>>+ *  MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
> > >>>+ *
> > >>>+ *  Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
> > >>>+ *  Author: Andreas Werner <andreas.werner@men.de>
> > >>>+ *  All rights reserved.
> > >>>+ *
> > >>>+ *  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>
> > >>>+#include <linux/mfd/menf21bmc.h>
> > >>>+
> > >>>+#define BMC_CMD_REV_MAJOR	0x80
> > >>>+#define BMC_CMD_REV_MINOR	0x81
> > >>>+#define BMC_CMD_REV_MAIN	0x82
> > >>>+#define BMC_CMD_REV_BUILD	0x83
> > >>>+#define BMC_CMD_REV_VERI	0x84
> > >>>+
> > >>>+static struct mfd_cell menf21bmc_cell[] = {
> > >>>+	{
> > >>>+		.name = "menf21bmc_wd",
> > >>>+	},
> > >>>+	{
> > >>>+		.name = "menf21bmc_led",
> > >>>+	},
> > >>>+};
> > >>>+
> > >>>+static int
> > >>>+menf21bmc_read_byte_data(struct i2c_client *client, u8 reg, uint8_t *val)
> > >>>+{
> > >>>+	int ret;
> > >>>+	struct menf21bmc *data = i2c_get_clientdata(client);
> > >>>+
> > >>>+	mutex_lock(&data->lock);
> > >>>+	ret = i2c_smbus_read_byte_data(client, reg);
> > >>>+	mutex_unlock(&data->lock);
> > >>>+
> > >>>+	if (ret < 0) {
> > >>>+		dev_err(&client->dev, "failed to read byte at 0x%02x\n", reg);
> > >>>+		return ret;
> > >>>+	}
> > >>>+
> > >>>+	*val = (uint8_t)ret;
> > >>>+
> > >>>+	return 0;
> > >>>+}
> > >>>+
> > >>I personally would prefer if you would retain the original API, which returns both value
> > >>and error code as return value. I don't see the benefit of changing the API as you did -
> > >>it just complicates the code.
> > >>
> > >>Thanks,
> > >>Guenter
> > >>
> > >I think it is ok for a wrapper like this because it does not really change an API because
> > >it is menf21bmc related.
> > >
> > >I did the same in rtc-rx8581, and it was already done in rtc_ds1307.c.
> > >
> > >I personally prefer this way because the return of the function and the return
> > >value of the i2c_smbus_read - which is the value read from the device - are seperated.
> > >
> > >If it is a no go for the mfd/wdt core i can change it back to the original i2c_smbus API.
> > >If it is ok on your side for a wrapper like this, we can let it as it is.
> > >
> > 
> > Not my call to make; depends on the mfd maintainer. I would not accept it, as I see it
> > as unnecessary, adding complexity, and pointless. Sure, you can always find examples
> > for everything somewhere in the kernel, but that doesn't make it better.
> 
> I'm inclined to agree with Guenter, this patch is just noise.

Ok no problem, i will fix it and resend the patch.
For now I know it for the future :-)

Any other comments about the patch series?

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

Regards
Andy
--
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] 21+ messages in thread

end of thread, other threads:[~2014-05-20  7:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-16 16:36 [PATCH 0/3] Introduce MEN 14F021P00 Board Management Controller driver set Andreas Werner
2014-05-16 16:36 ` Andreas Werner
2014-05-16 16:37 ` [PATCH 1/3] drivers/mfd/menf21bmc: introduce MEN 14F021P00 BMC MFD Core driver Andreas Werner
2014-05-16 16:37   ` Andreas Werner
2014-05-17 15:47   ` Guenter Roeck
2014-05-19 12:43     ` Andreas Werner
2014-05-19 12:43       ` Andreas Werner
2014-05-19 13:23       ` Guenter Roeck
2014-05-19 17:39         ` Lee Jones
2014-05-20  7:47           ` Andreas Werner
2014-05-20  7:47             ` Andreas Werner
2014-05-20  7:47             ` Andreas Werner
2014-05-20  7:06             ` Lee Jones
2014-05-20  7:06               ` Lee Jones
2014-05-16 16:37 ` [PATCH 2/3] drivers/watchdog/menf21bmc_wd: introduce MEN 14F021P00 BMC Watchdog driver Andreas Werner
2014-05-16 16:37   ` Andreas Werner
2014-05-17 15:57   ` Guenter Roeck
2014-05-19 12:20     ` Andreas Werner
2014-05-19 12:20       ` Andreas Werner
2014-05-16 16:37 ` [PATCH 3/3] drivers/leds/leds-menf21bmc: introduce MEN 14F021P00 BMC LED driver Andreas Werner
2014-05-16 16:37   ` Andreas Werner

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.