From: <atull@opensource.altera.com>
To: <linux@roeck-us.net>, <jdelvare@suse.de>
Cc: <lm-sensors@lm-sensors.org>, <lgirdwood@gmail.com>,
<broonie@kernel.org>, <linux-kernel@vger.kernel.org>,
<delicious.quinoa@gmail.com>, <dinguyen@opensource.altera.com>,
<yvanderv@opensource.altera.com>,
Alan Tull <atull@opensource.altera.com>
Subject: [PATCH 1/2] pmbus: add regulator support
Date: Thu, 21 Aug 2014 17:21:25 -0500 [thread overview]
Message-ID: <1408659686-29106-2-git-send-email-atull@opensource.altera.com> (raw)
In-Reply-To: <1408659686-29106-1-git-send-email-atull@opensource.altera.com>
From: Alan Tull <atull@opensource.altera.com>
Enable pmbus device drivers to add regulator functionality.
To add a regulator, it's pretty straightforward. The pmbus
device driver needs to add regulator information to its
pmbus_driver_info struct:
* num_regulators : number of regulators
* reg_init : array of struct regulator_init_data
* reg_desc : array of struct regulator_desc
Signed-off-by: Alan Tull <atull@opensource.altera.com>
---
drivers/hwmon/pmbus/pmbus.h | 7 +++++++
drivers/hwmon/pmbus/pmbus_core.c | 40 ++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index fa9beb3..a45722f 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -19,6 +19,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <linux/regulator/driver.h>
+
#ifndef PMBUS_H
#define PMBUS_H
@@ -365,6 +367,11 @@ struct pmbus_driver_info {
*/
int (*identify)(struct i2c_client *client,
struct pmbus_driver_info *info);
+
+ /* Regulator functionality, if supported by this chip driver. */
+ int num_regulators;
+ struct regulator_init_data *reg_init;
+ const struct regulator_desc *reg_desc;
};
/* Function declarations */
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 291d11f..10315ee 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -29,6 +29,8 @@
#include <linux/hwmon-sysfs.h>
#include <linux/jiffies.h>
#include <linux/i2c/pmbus.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
#include "pmbus.h"
/*
@@ -1727,6 +1729,39 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
return 0;
}
+#if IS_ENABLED(CONFIG_REGULATOR)
+static int pmbus_register_regulators(struct pmbus_data *data)
+{
+ struct regulator_dev *rdev;
+ struct regulator_config config = { };
+ const struct pmbus_driver_info *info = data->info;
+ struct device *dev = data->dev;
+ int i;
+
+ config.dev = dev;
+ config.driver_data = data;
+
+ for (i = 0; i < info->num_regulators; i++) {
+ config.init_data = &info->reg_init[i];
+ rdev = devm_regulator_register(dev, &info->reg_desc[i],
+ &config);
+ if (IS_ERR(rdev)) {
+ dev_err(dev, "failed to register regulator %s\n",
+ info->reg_desc[i].name);
+ hwmon_device_unregister(data->hwmon_dev);
+ return PTR_ERR(rdev);
+ }
+ }
+
+ return 0;
+}
+#else
+static int pmbus_register_regulators(struct pmbus_data *data)
+{
+ return 0;
+}
+#endif
+
int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
struct pmbus_driver_info *info)
{
@@ -1781,6 +1816,11 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
dev_err(dev, "Failed to register hwmon device\n");
goto out_kfree;
}
+
+ ret = pmbus_register_regulators(data);
+ if (ret)
+ goto out_kfree;
+
return 0;
out_kfree:
--
1.7.9.5
next prev parent reply other threads:[~2014-08-21 22:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-21 22:21 [PATCH 0/2] add regulator support for pmbus and ltc2978 atull
2014-08-21 22:21 ` atull [this message]
2014-08-21 22:21 ` [PATCH 2/2] pmbus: ltc2978: add regulator gating atull
2014-08-22 0:36 ` Mark Brown
2014-08-22 1:18 ` Guenter Roeck
2014-08-22 1:26 ` Mark Brown
2014-08-22 2:30 ` Guenter Roeck
2014-08-22 15:30 ` atull
2014-08-22 21:14 ` [PATCH 0/2] add regulator support for pmbus and ltc2978 atull
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=1408659686-29106-2-git-send-email-atull@opensource.altera.com \
--to=atull@opensource.altera.com \
--cc=broonie@kernel.org \
--cc=delicious.quinoa@gmail.com \
--cc=dinguyen@opensource.altera.com \
--cc=jdelvare@suse.de \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=lm-sensors@lm-sensors.org \
--cc=yvanderv@opensource.altera.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;
as well as URLs for NNTP newsgroup(s).