All of lore.kernel.org
 help / color / mirror / Atom feed
From: <michaelsh@nvidia.com>
To: <linux@roeck-us.net>, <linux-hwmon@vger.kernel.org>, <vadimp@nvidia.com>
Cc: Michael Shych <michaelsh@nvidia.com>
Subject: [PATCH v3 3/3] hwmon: powr1220: Add support for Lattice's POWR1014 power manager IC
Date: Tue, 18 Jan 2022 09:56:11 +0200	[thread overview]
Message-ID: <20220118075611.10665-4-michaelsh@nvidia.com> (raw)
In-Reply-To: <20220118075611.10665-1-michaelsh@nvidia.com>

From: Michael Shych <michaelsh@nvidia.com>

This patch adds support for Lattice's POWR1014 power manager IC.
Read access to all the ADCs on the chip are supported through
the "hwmon" "sysfs" files.

The main differences of POWR1014 compared to POWR1220 are
amount of VMON input lines: 10 on POWR1014 and 12 lines on POWR1220 and
number of output control signals: 14 on POWR1014 and 20 on POWR1220.

Signed-off-by: Michael Shych <michaelsh@nvidia.com>
Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
---
v2->v3
Fixes according to Guenter Roeck notes
1. Correct commit notes.
2. Don't use usleep_range
3. Change devicenames in alphanumeric order.
4. Chanhge if statement
v1->v2
Fix added by Michael: Fix incorrect device id.
---
 drivers/hwmon/powr1220.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/powr1220.c b/drivers/hwmon/powr1220.c
index 1d4e005977b6..2a5e168a52a9 100644
--- a/drivers/hwmon/powr1220.c
+++ b/drivers/hwmon/powr1220.c
@@ -22,6 +22,8 @@
 #define ADC_STEP_MV			2
 #define ADC_MAX_LOW_MEASUREMENT_MV	2000
 
+enum powr1xxx_chips { powr1014, powr1220 };
+
 enum powr1220_regs {
 	VMON_STATUS0,
 	VMON_STATUS1,
@@ -74,6 +76,7 @@ enum powr1220_adc_values {
 struct powr1220_data {
 	struct i2c_client *client;
 	struct mutex update_lock;
+	u8 max_channels;
 	bool adc_valid[MAX_POWR1220_ADC_VALUES];
 	 /* the next value is in jiffies */
 	unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES];
@@ -171,6 +174,11 @@ static umode_t
 powr1220_is_visible(const void *data, enum hwmon_sensor_types type, u32
 		    attr, int channel)
 {
+	struct powr1220_data *chip_data = (struct powr1220_data *)data;
+
+	if (channel >= chip_data->max_channels)
+		return 0;
+
 	switch (type) {
 	case hwmon_in:
 		switch (attr) {
@@ -271,6 +279,8 @@ static const struct hwmon_chip_info powr1220_chip_info = {
 	.info = powr1220_info,
 };
 
+static const struct i2c_device_id powr1220_ids[];
+
 static int powr1220_probe(struct i2c_client *client)
 {
 	struct powr1220_data *data;
@@ -283,6 +293,15 @@ static int powr1220_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
+	switch (i2c_match_id(powr1220_ids, client)->driver_data) {
+	case powr1014:
+		data->max_channels = 10;
+		break;
+	default:
+		data->max_channels = 12;
+		break;
+	}
+
 	mutex_init(&data->update_lock);
 	data->client = client;
 
@@ -296,7 +315,8 @@ static int powr1220_probe(struct i2c_client *client)
 }
 
 static const struct i2c_device_id powr1220_ids[] = {
-	{ "powr1220", 0, },
+	{ "powr1014", powr1014, },
+	{ "powr1220", powr1220, },
 	{ }
 };
 
-- 
2.14.1


  parent reply	other threads:[~2022-01-18  7:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18  7:56 [PATCH v3 0/3] hwmon: powr1220: add powr104 support michaelsh
2022-01-18  7:56 ` [PATCH v3 1/3] hwmon: powr1220: Cosmetic changes michaelsh
2022-01-21 14:10   ` Guenter Roeck
2022-01-18  7:56 ` [PATCH v3 2/3] hwmon: powr1220: Upgrade driver to support hwmon info infrastructure michaelsh
2022-01-21 14:12   ` Guenter Roeck
2022-01-18  7:56 ` michaelsh [this message]
2022-01-21 14:13   ` [PATCH v3 3/3] hwmon: powr1220: Add support for Lattice's POWR1014 power manager IC Guenter Roeck

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=20220118075611.10665-4-michaelsh@nvidia.com \
    --to=michaelsh@nvidia.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=vadimp@nvidia.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 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.