mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Werner <andreas.werner@men.de>
To: <linux-kernel@vger.kernel.org>
Cc: <lee.jones@linaro.org>, <sameo@linux.intel.com>
Subject: [PATCH 1/4] mfd/menf21bmc: remove auto exiting of production mode and add sysfs interface
Date: Wed, 16 Dec 2015 16:29:04 +0100	[thread overview]
Message-ID: <89356f7802fa3ea22e1ebae18774e26a9f2ee68f.1450279483.git.andreas.werner@men.de> (raw)
In-Reply-To: <cover.1450279483.git.andreas.werner@men.de>

Changed "exit production mode" from automatic exiting to
manually using the sysfs interface.

If the driver exit the production mode automatically, the board will
not start anymore if the bootloader does not already have the "BIOS life sign"
feature.

This patch remove the auto mechanism and add a sysfs interface to manually
exiting the production e.g. during the EOL test of the board.

Signed-off-by: Andreas Werner <andreas.werner@men.de>
---
 drivers/mfd/menf21bmc.c | 65 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/menf21bmc.c b/drivers/mfd/menf21bmc.c
index 1c27434..742ffe7 100644
--- a/drivers/mfd/menf21bmc.c
+++ b/drivers/mfd/menf21bmc.c
@@ -27,31 +27,57 @@ static struct mfd_cell menf21bmc_cell[] = {
 	{ .name = "menf21bmc_hwmon", }
 };
 
-static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
+static ssize_t menf21bmc_mode_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
 {
-	int val, ret;
+	struct i2c_client *client = to_i2c_client(dev);
+	int val;
 
 	val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
 	if (val < 0)
 		return val;
 
+	return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t menf21bmc_mode_store(struct device *dev,
+				   struct device_attribute *attr,
+				   const char *buf, size_t size)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	unsigned long mode_val;
+	int ret;
+
+	if (kstrtoul(buf, 0, &mode_val))
+		return -EINVAL;
+
 	/*
-	 * Production mode should be not active after delivery of the Board.
-	 * To be sure we check it, inform the user and exit the mode
-	 * if active.
+	 * We cannot set the production mode (0).
+	 * This is the default mode. If exited once,
+	 * it cannot be set anymore.
 	 */
-	if (val == 0x00) {
-		dev_info(&client->dev,
-			"BMC in production mode. Exit production mode\n");
+	if (!mode_val)
+		return -EINVAL;
 
-		ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
-		if (ret < 0)
-			return ret;
-	}
+	ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
+	if (ret < 0)
+		return ret;
 
-	return 0;
+	return size;
 }
 
+static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, menf21bmc_mode_show,
+		   menf21bmc_mode_store);
+
+static struct attribute *menf21bmc_attributes[] = {
+	&dev_attr_mode.attr,
+	NULL
+};
+
+static const struct attribute_group menf21bmc_attr_group = {
+	.attrs = menf21bmc_attributes,
+};
+
 static int
 menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
 {
@@ -86,20 +112,15 @@ menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
 	dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
 		 rev_major, rev_minor, rev_main);
 
-	/*
-	 * We have to exit the Production Mode of the BMC to activate the
-	 * Watchdog functionality and the BIOS life sign monitoring.
-	 */
-	ret = menf21bmc_wdt_exit_prod_mode(client);
-	if (ret < 0) {
-		dev_err(&client->dev, "failed to leave production mode\n");
+	ret = sysfs_create_group(&client->dev.kobj, &menf21bmc_attr_group);
+	if (ret)
 		return ret;
-	}
 
 	ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
 			      ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
 	if (ret < 0) {
 		dev_err(&client->dev, "failed to add BMC sub-devices\n");
+		sysfs_remove_group(&client->dev.kobj, &menf21bmc_attr_group);
 		return ret;
 	}
 
@@ -108,7 +129,9 @@ menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
 
 static int menf21bmc_remove(struct i2c_client *client)
 {
+	sysfs_remove_group(&client->dev.kobj, &menf21bmc_attr_group);
 	mfd_remove_devices(&client->dev);
+
 	return 0;
 }
 
-- 
2.6.2


  reply	other threads:[~2015-12-16 15:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-16 15:28 [PATCH 0/4] remove auto exit of production and added " Andreas Werner
2015-12-16 15:29 ` Andreas Werner [this message]
2016-01-11 10:32   ` [PATCH 1/4] mfd/menf21bmc: remove auto exiting of production mode and add " Lee Jones
2016-01-11 10:33     ` Lee Jones
2016-01-11 10:49       ` Andreas Werner
2016-01-11 11:24         ` Lee Jones
2015-12-16 15:29 ` [PATCH 2/4] doc/ABI: added sysfs description for the menf21bmc MFD driver Andreas Werner
2016-01-11 10:28   ` Lee Jones
2016-01-11 10:37     ` Andreas Werner
2015-12-16 15:29 ` [PATCH 3/4] mfd/menf21bmc.c: add additional sysfs entries for BMC status information Andreas Werner
2016-01-11 10:30   ` Lee Jones
2016-01-11 10:38     ` Andreas Werner
2015-12-16 15:30 ` [PATCH 4/4] doc/ABI: add documentation for the additional sysfs " Andreas Werner
2016-01-11 10:28   ` Lee Jones
2016-01-11 10:36     ` [PATCH 4/4] doc/ABI: add documentation for the additional sysfs status informationj Andreas Werner
2016-01-06 12:45 ` [PATCH 0/4] remove auto exit of production and added sysfs interface Andreas Werner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=89356f7802fa3ea22e1ebae18774e26a9f2ee68f.1450279483.git.andreas.werner@men.de \
    --to=andreas.werner@men.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®