Skip to contentSkip to conversation

hwmon: (ltc4245) expose all GPIO pins as

PATCH In review Ira W. Snyder 3 participants 11 messages Apr 13, 2010 – May 26, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 hwmon: (ltc4245) expose all GPIO pins as

Add support for exposing all GPIO pins as analog voltages. Though this is not an ideal use of the chip, some hardware engineers may decide that the LTC4245 meets their design requirements when studying the datasheet.

The GPIO pins are sampled in round-robin fashion, meaning that a slow reader will see stale data. A userspace application can detect this, because it will get -EAGAIN when reading from a sysfs file which contains stale data.

---
 Documentation/hwmon/ltc4245 |   13 +++++-
 drivers/hwmon/Kconfig       |   10 +++++
 drivers/hwmon/ltc4245.c     |   95 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 116 insertions(+), 2 deletions(-)
Documentation/hwmon/ltc4245 +12 -1
index 86b5880..1c0599f 100644
@@ -72,9 +72,20 @@ in6_min_alarm		5v  output undervoltage alarm
 in7_min_alarm		3v  output undervoltage alarm
 in8_min_alarm		Vee (-12v) output undervoltage alarm
 
-in9_input		GPIO voltage data
+in9_input		GPIO voltage data (see note 1)
+in10_input		GPIO voltage data (see note 1)
+in11_input		GPIO voltage data (see note 1)
 
 power1_input		12v power usage (mW)
 power2_input		5v  power usage (mW)
 power3_input		3v  power usage (mW)
 power4_input		Vee (-12v) power usage (mW)
+
+
+Note 1
+------
+
+If you have configured your kernel with CONFIG_SENSORS_LTC4245_EXTRA_GPIOS=y
+then all three GPIO voltage lines will be sampled in round-robin fashion. If
+the data becomes stale, -EAGAIN will be returned when you read the sysfs
+attribute containing the sensor reading.
drivers/hwmon/Kconfig +10 -0
index e4595e6..e9c99cb 100644
@@ -623,6 +623,16 @@ config SENSORS_LTC4245
 	  This driver can also be built as a module. If so, the module will
 	  be called ltc4245.
 
+config SENSORS_LTC4245_EXTRA_GPIOS
+	bool "LTC4245: sample all GPIO pins as analog voltages"
+	depends on SENSORS_LTC4245
+	default n
+	help
+	  If you say yes here, the LTC4245 driver will read all of the GPIO
+	  pins in rotation, reporting them as extra voltage channels.
+
+	  Please read the Documentation/hwmon/ltc4245 file for more details.
+
 config SENSORS_LM95241
 	tristate "National Semiconductor LM95241 sensor chip"
 	depends on I2C
drivers/hwmon/ltc4245.c +94 -1

133 lines not on this page · raw message

Signature · 7 lines
1.5.4.3


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

Hi Ira,

Sorry for the late answer.

Quoted 8 lines · Ira W. Snyder

Add support for exposing all GPIO pins as analog voltages. Though this is not an ideal use of the chip, some hardware engineers may decide that the LTC4245 meets their design requirements when studying the datasheet.

The GPIO pins are sampled in round-robin fashion, meaning that a slow reader will see stale data. A userspace application can detect this, because it will get -EAGAIN when reading from a sysfs file which contains stale data.

A userspace application _or library_. In practice, most monitoring applications will rely on libsensors.

Quoted 24 lines
---
 Documentation/hwmon/ltc4245 |   13 +++++-
 drivers/hwmon/Kconfig       |   10 +++++
 drivers/hwmon/ltc4245.c     |   95 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 116 insertions(+), 2 deletions(-)
Documentation/hwmon/ltc4245 +3 -1
index 86b5880..1c0599f 100644
@@ -72,9 +72,20 @@ in6_min_alarm		5v  output undervoltage alarm
 in7_min_alarm		3v  output undervoltage alarm
 in8_min_alarm		Vee (-12v) output undervoltage alarm
 
-in9_input		GPIO voltage data
+in9_input		GPIO voltage data (see note 1)
+in10_input		GPIO voltage data (see note 1)
+in11_input		GPIO voltage data (see note 1)
 
 power1_input		12v power usage (mW)
 power2_input		5v  power usage (mW)
 power3_input		3v  power usage (mW)

Documentation/hwmon/ltc4245 in6_min_alarm 5v output undervoltage alarm · line 91

Quoted 10 lines
Documentation/hwmon/ltc4245 +9 -0
 power4_input		Vee (-12v) power usage (mW)
+
+
+Note 1
+------
+
+If you have configured your kernel with CONFIG_SENSORS_LTC4245_EXTRA_GPIOS=y
+then all three GPIO voltage lines will be sampled in round-robin fashion. If
+the data becomes stale, -EAGAIN will be returned when you read the sysfs
+attribute containing the sensor reading.

Please also clarify the case CONFIG_SENSORS_LTC4245_EXTRA_GPIOS=n.

Quoted 8 lines
drivers/hwmon/Kconfig +0 -0
index e4595e6..e9c99cb 100644
@@ -623,6 +623,16 @@ config SENSORS_LTC4245
 	  This driver can also be built as a module. If so, the module will
 	  be called ltc4245.
 

drivers/hwmon/Kconfig config SENSORS_LTC4245 · line 635

Quoted 10 lines
drivers/hwmon/Kconfig +10 -0
+config SENSORS_LTC4245_EXTRA_GPIOS
+	bool "LTC4245: sample all GPIO pins as analog voltages"
+	depends on SENSORS_LTC4245
+	default n
+	help
+	  If you say yes here, the LTC4245 driver will read all of the GPIO
+	  pins in rotation, reporting them as extra voltage channels.
+
+	  Please read the Documentation/hwmon/ltc4245 file for more details.
+

I have to admit that I am surprised that you made this a build-time configuration option. This isn't flexible. Distributions will have to make a decision for all their users at once. Not only this, but the behavior will have to be the same for all LTC4245 chips in a given system, even when using a custom kernel (not that I really expect multiple LTC4245 chips on the same board, but you never know...)

I presume that your idea was to make this feature as little intrusive as possible for regular users? I thank you for this, but I'm not quite sure this is the best approach. A module option, or a per-device attribute, would be more flexible. That being said, you're the one in need for this option, so I won't argue further. I'm fine taking whatever approach seems preferable to you.

Quoted 8 lines
drivers/hwmon/Kconfig +0 -0
 config SENSORS_LM95241
 	tristate "National Semiconductor LM95241 sensor chip"
 	depends on I2C
drivers/hwmon/ltc4245.c +0 -0
index 84e6f32..33fdc02 100644

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 65

Quoted 6 lines
drivers/hwmon/ltc4245.c +3 -0
@@ -60,8 +60,70 @@ struct ltc4245_data {
 
 	/* Voltage registers */
 	u8 vregs[0x0d];
+
+	/* GPIO ADC registers */
+	unsigned int last_gpio;

This field is never initialized, meaning it starts with value 0 (GPIO1). There is, however, no guarantee that the chip has GPIO1 routed to the ADC when the driver is loaded. OTOH, you read the GPIO configuration in cregs[LTC4245_GPIO] already, so last_gpio is somewhat redundant, and you could instead use cregs[LTC4245_GPIO] directly.

Quoted 12 lines
drivers/hwmon/ltc4245.c +10 -0
+	int gpios[3];
 };
 
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+/*
+ * Update the readings from all three GPIO pins. This means that the old
+ * readings will be delayed.
+ *
+ * LOCKING: must hold data->update_lock
+ */
+static void ltc4245_update_gpios(struct device *dev)
+{

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 87

Quoted 10 lines
drivers/hwmon/ltc4245.c +10 -0
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ltc4245_data *data = i2c_get_clientdata(client);
+	u8 gpio_curr, gpio_next, gpio, ctl;
+	int i;
+
+	/*
+	 * If the last reading was 10 seconds ago, then we mark all old GPIO
+	 * readings as stale by setting them to zero volts
+	 */
+	if (time_after(jiffies, data->last_updated + 10 * HZ)) {

10 seconds is much. If one reads the values every 10 seconds, you will report 20-seconds old readings without complaining. I would lower this delay to 5 seconds, tops.

Quoted 13 lines
drivers/hwmon/ltc4245.c +13 -0
+		dev_dbg(&client->dev, "Marking GPIOs invalid\n");
+		for (i = 0; i < ARRAY_SIZE(data->gpios); i++)
+			data->gpios[i] = -EAGAIN;
+	}
+
+	/* Read the GPIO voltage from the GPIOADC register */
+	gpio_curr = data->last_gpio;
+	data->gpios[gpio_curr] = data->vregs[LTC4245_GPIOADC - 0x10];
+
+	/* Find the next GPIO pin to read */
+	gpio_next = (data->last_gpio + 1) % ARRAY_SIZE(data->gpios);
+
+	/*

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 110

Quoted 10 lines
drivers/hwmon/ltc4245.c +10 -0
+	 * Calculate the correct setting for the GPIO register so it will
+	 * sample the next GPIO pin
+	 */
+	gpio = (data->cregs[LTC4245_GPIO] & 0x3f) | ((gpio_next + 1) << 6);
+	ctl = data->cregs[LTC4245_CONTROL];
+
+	/* Update the GPIO register */
+	i2c_smbus_write_byte_data(client, LTC4245_CONTROL, ctl | 0x80);
+	i2c_smbus_write_byte_data(client, LTC4245_GPIO, gpio);
+	i2c_smbus_write_byte_data(client, LTC4245_CONTROL, ctl);

Not sure why you toggle bit C7? The datasheet says that it must be toggled for writing to registers 0x10 to 0x1F, but LTC4245_GPIO is register 0x06. Is there any other reason I'm missing?

Quoted 5 lines
drivers/hwmon/ltc4245.c +5 -0
+
+	/* Update saved data */
+	data->cregs[LTC4245_GPIO] = gpio;
+	data->last_gpio = gpio_next;
+}

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 125

Quoted 10 lines
drivers/hwmon/ltc4245.c +10 -0
+#else
+static void ltc4245_update_gpios(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ltc4245_data *data = i2c_get_clientdata(client);
+
+	/* Just copy the data from the the GPIOADC register */
+	data->gpios[0] = data->vregs[LTC4245_GPIOADC - 0x10];
+}
+#endif

Not sure why you define this stub function. If you want your patch to be as little intrusive as possible, you can skip ltc4245_update_gpios altogether in the general case, and handle in9 as every other voltage input as the driver was doing before your patch.

Quoted 38 lines
drivers/hwmon/ltc4245.c +20 -0
+
 static struct ltc4245_data *ltc4245_update_device(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
@@ -93,6 +155,9 @@ static struct ltc4245_data *ltc4245_update_device(struct device *dev)
 				data->vregs[i] = val;
 		}
 
+		/* Update GPIO readings */
+		ltc4245_update_gpios(dev);
+
 		data->last_updated = jiffies;
 		data->valid = 1;
 	}
@@ -233,6 +298,22 @@ static ssize_t ltc4245_show_alarm(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0);
 }
 
+static ssize_t ltc4245_show_gpio(struct device *dev,
+				 struct device_attribute *da,
+				 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ltc4245_data *data = ltc4245_update_device(dev);
+	int val = data->gpios[attr->index];
+
+	/* handle stale GPIO's */
+	if (val < 0)
+		return val;
+
+	/* Convert to millivolts and print */
+	return snprintf(buf, PAGE_SIZE, "%u\n", val * 10);
+}
+
 /* These macros are used below in constructing device attribute objects
  * for use with sysfs_create_group() to make a sysfs device file
  * for each register.

drivers/hwmon/ltc4245.c static ssize_t ltc4245_show_alarm(struct device *dev, · line 340

Quoted 6 lines
drivers/hwmon/ltc4245.c +3 -0
@@ -254,6 +335,10 @@ static ssize_t ltc4245_show_alarm(struct device *dev,
 	static SENSOR_DEVICE_ATTR_2(name, S_IRUGO, \
 	ltc4245_show_alarm, NULL, (mask), reg)
 
+#define LTC4245_GPIO(name, gpio_num) \
+	static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
+	ltc4245_show_gpio, NULL, gpio_num)

You already have an enum value by that name, this is confusing. That's what you get for prefixing your register names with only LTC4245_ instead of LTC4245_REG_ as most drivers are doing.

Quoted 28 lines
drivers/hwmon/ltc4245.c +10 -1
+
 /* Construct a sensor_device_attribute structure for each register */
 
 /* Input voltages */
@@ -293,7 +378,11 @@ LTC4245_ALARM(in7_min_alarm,	(1 << 2),	LTC4245_FAULT2);
 LTC4245_ALARM(in8_min_alarm,	(1 << 3),	LTC4245_FAULT2);
 
 /* GPIO voltages */
-LTC4245_VOLTAGE(in9_input,			LTC4245_GPIOADC);
+LTC4245_GPIO(in9_input,				0);
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+LTC4245_GPIO(in10_input,			1);
+LTC4245_GPIO(in11_input,			2);
+#endif
 
 /* Power Consumption (virtual) */
 LTC4245_POWER(power1_input,			LTC4245_12VSENSE);
@@ -336,6 +425,10 @@ static struct attribute *ltc4245_attributes[] = {
 	&sensor_dev_attr_in8_min_alarm.dev_attr.attr,
 
 	&sensor_dev_attr_in9_input.dev_attr.attr,
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+	&sensor_dev_attr_in10_input.dev_attr.attr,
+	&sensor_dev_attr_in11_input.dev_attr.attr,
+#endif
 
 	&sensor_dev_attr_power1_input.dev_attr.attr,
 	&sensor_dev_attr_power2_input.dev_attr.attr,
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 80 lines · Jean Delvare

Hi Ira,

Sorry for the late answer.

Quoted 8 lines · Ira W. Snyder

Add support for exposing all GPIO pins as analog voltages. Though this is not an ideal use of the chip, some hardware engineers may decide that the LTC4245 meets their design requirements when studying the datasheet.

The GPIO pins are sampled in round-robin fashion, meaning that a slow reader will see stale data. A userspace application can detect this, because it will get -EAGAIN when reading from a sysfs file which contains stale data.

A userspace application _or library_. In practice, most monitoring applications will rely on libsensors.

Quoted 24 lines
---
 Documentation/hwmon/ltc4245 |   13 +++++-
 drivers/hwmon/Kconfig       |   10 +++++
 drivers/hwmon/ltc4245.c     |   95 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 116 insertions(+), 2 deletions(-)
Documentation/hwmon/ltc4245 +3 -1
index 86b5880..1c0599f 100644
@@ -72,9 +72,20 @@ in6_min_alarm		5v  output undervoltage alarm
 in7_min_alarm		3v  output undervoltage alarm
 in8_min_alarm		Vee (-12v) output undervoltage alarm
 
-in9_input		GPIO voltage data
+in9_input		GPIO voltage data (see note 1)
+in10_input		GPIO voltage data (see note 1)
+in11_input		GPIO voltage data (see note 1)
 
 power1_input		12v power usage (mW)
 power2_input		5v  power usage (mW)
 power3_input		3v  power usage (mW)

Documentation/hwmon/ltc4245 in6_min_alarm 5v output undervoltage alarm · line 91

Quoted 10 lines
Documentation/hwmon/ltc4245 +9 -0
 power4_input		Vee (-12v) power usage (mW)
+
+
+Note 1
+------
+
+If you have configured your kernel with CONFIG_SENSORS_LTC4245_EXTRA_GPIOS=y
+then all three GPIO voltage lines will be sampled in round-robin fashion. If
+the data becomes stale, -EAGAIN will be returned when you read the sysfs
+attribute containing the sensor reading.

Please also clarify the case CONFIG_SENSORS_LTC4245_EXTRA_GPIOS=n.

Quoted 8 lines
drivers/hwmon/Kconfig +0 -0
index e4595e6..e9c99cb 100644
@@ -623,6 +623,16 @@ config SENSORS_LTC4245
 	  This driver can also be built as a module. If so, the module will
 	  be called ltc4245.
 

drivers/hwmon/Kconfig config SENSORS_LTC4245 · line 635

Quoted 10 lines
drivers/hwmon/Kconfig +10 -0
+config SENSORS_LTC4245_EXTRA_GPIOS
+	bool "LTC4245: sample all GPIO pins as analog voltages"
+	depends on SENSORS_LTC4245
+	default n
+	help
+	  If you say yes here, the LTC4245 driver will read all of the GPIO
+	  pins in rotation, reporting them as extra voltage channels.
+
+	  Please read the Documentation/hwmon/ltc4245 file for more details.
+

I have to admit that I am surprised that you made this a build-time configuration option. This isn't flexible. Distributions will have to make a decision for all their users at once. Not only this, but the behavior will have to be the same for all LTC4245 chips in a given system, even when using a custom kernel (not that I really expect multiple LTC4245 chips on the same board, but you never know...)

Quoted 7 lines

I presume that your idea was to make this feature as little intrusive as possible for regular users? I thank you for this, but I'm not quite sure this is the best approach. A module option, or a per-device attribute, would be more flexible. That being said, you're the one in need for this option, so I won't argue further. I'm fine taking whatever approach seems preferable to you.

That's correct. I know you're concerned about code size, so I tried to keep things as minimal as possible for what you consider to be the correct use of the chip.

My only board with this chip is a powerpc, and uses the OpenFirmware (OF) bindings to tell the driver which i2c address the chip is at. I'd be happier to do this with platform data, but I have absolutely no idea how to do that with the OF bindings. I'm not sure it is even possible.

Quoted 9 lines
Quoted 9 lines
drivers/hwmon/Kconfig +0 -0
 config SENSORS_LM95241
 	tristate "National Semiconductor LM95241 sensor chip"
 	depends on I2C
drivers/hwmon/ltc4245.c +0 -0
index 84e6f32..33fdc02 100644
@@ -60,8 +60,70 @@ struct ltc4245_data {
 
Quoted 12 lines

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 65

Quoted 5 lines
drivers/hwmon/ltc4245.c +3 -0
 	/* Voltage registers */
 	u8 vregs[0x0d];
+
+	/* GPIO ADC registers */
+	unsigned int last_gpio;

This field is never initialized, meaning it starts with value 0 (GPIO1). There is, however, no guarantee that the chip has GPIO1 routed to the ADC when the driver is loaded. OTOH, you read the GPIO configuration in cregs[LTC4245_GPIO] already, so last_gpio is somewhat redundant, and you could instead use cregs[LTC4245_GPIO] directly.

I'll make an updated patch which uses the register instead.

Quoted 18 lines
Quoted 18 lines
drivers/hwmon/ltc4245.c +16 -0
+	int gpios[3];
 };
 
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+/*
+ * Update the readings from all three GPIO pins. This means that the old
+ * readings will be delayed.
+ *
+ * LOCKING: must hold data->update_lock
+ */
+static void ltc4245_update_gpios(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ltc4245_data *data = i2c_get_clientdata(client);
+	u8 gpio_curr, gpio_next, gpio, ctl;
+	int i;
+
+	/*
Quoted 9 lines

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 87

Quoted 4 lines
drivers/hwmon/ltc4245.c +4 -0
+	 * If the last reading was 10 seconds ago, then we mark all old GPIO
+	 * readings as stale by setting them to zero volts
+	 */
+	if (time_after(jiffies, data->last_updated + 10 * HZ)) {

10 seconds is much. If one reads the values every 10 seconds, you will report 20-seconds old readings without complaining. I would lower this delay to 5 seconds, tops.

Ok, 5 seconds it is.

Quoted 19 lines
Quoted 19 lines
drivers/hwmon/ltc4245.c +19 -0
+		dev_dbg(&client->dev, "Marking GPIOs invalid\n");
+		for (i = 0; i < ARRAY_SIZE(data->gpios); i++)
+			data->gpios[i] = -EAGAIN;
+	}
+
+	/* Read the GPIO voltage from the GPIOADC register */
+	gpio_curr = data->last_gpio;
+	data->gpios[gpio_curr] = data->vregs[LTC4245_GPIOADC - 0x10];
+
+	/* Find the next GPIO pin to read */
+	gpio_next = (data->last_gpio + 1) % ARRAY_SIZE(data->gpios);
+
+	/*
+	 * Calculate the correct setting for the GPIO register so it will
+	 * sample the next GPIO pin
+	 */
+	gpio = (data->cregs[LTC4245_GPIO] & 0x3f) | ((gpio_next + 1) << 6);
+	ctl = data->cregs[LTC4245_CONTROL];
+
Quoted 9 lines

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 110

Quoted 4 lines
drivers/hwmon/ltc4245.c +4 -0
+	/* Update the GPIO register */
+	i2c_smbus_write_byte_data(client, LTC4245_CONTROL, ctl | 0x80);
+	i2c_smbus_write_byte_data(client, LTC4245_GPIO, gpio);
+	i2c_smbus_write_byte_data(client, LTC4245_CONTROL, ctl);

Not sure why you toggle bit C7? The datasheet says that it must be toggled for writing to registers 0x10 to 0x1F, but LTC4245_GPIO is register 0x06. Is there any other reason I'm missing?

Nope, you're exactly right. I'll remove the write to the LTC4245_CONTROL register.

I guess I read the note about setting/clearing the bit for the LTC4245_GPIOADC (0x1c) register, and then my mind carried it over to the LTC4245_GPIO (0x06) register too. Good catch.

Quoted 12 lines
Quoted 12 lines
drivers/hwmon/ltc4245.c +12 -0
+
+	/* Update saved data */
+	data->cregs[LTC4245_GPIO] = gpio;
+	data->last_gpio = gpio_next;
+}
+#else
+static void ltc4245_update_gpios(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ltc4245_data *data = i2c_get_clientdata(client);
+
+	/* Just copy the data from the the GPIOADC register */
Quoted 9 lines

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 125

Quoted 3 lines
drivers/hwmon/ltc4245.c +3 -0
+	data->gpios[0] = data->vregs[LTC4245_GPIOADC - 0x10];
+}
+#endif

Not sure why you define this stub function. If you want your patch to be as little intrusive as possible, you can skip ltc4245_update_gpios altogether in the general case, and handle in9 as every other voltage input as the driver was doing before your patch.

I did it so ltc4245_update_gpios() could be called in both cases, without any conditional logic. See the hunk below. I just call ltc4245_update_gpios() without any #ifdef, it "just works" in both cases.

This is the usual thing Linux does with headers. For example, see include/linux/pci.h pci_enable_msix() function. When CONFIG_PCI_MSI=n they stub out the function so it does the right thing: return an error.

Quoted 41 lines
Quoted 41 lines
drivers/hwmon/ltc4245.c +20 -0
+
 static struct ltc4245_data *ltc4245_update_device(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
@@ -93,6 +155,9 @@ static struct ltc4245_data *ltc4245_update_device(struct device *dev)
 				data->vregs[i] = val;
 		}
 
+		/* Update GPIO readings */
+		ltc4245_update_gpios(dev);
+
 		data->last_updated = jiffies;
 		data->valid = 1;
 	}
@@ -233,6 +298,22 @@ static ssize_t ltc4245_show_alarm(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0);
 }
 
+static ssize_t ltc4245_show_gpio(struct device *dev,
+				 struct device_attribute *da,
+				 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ltc4245_data *data = ltc4245_update_device(dev);
+	int val = data->gpios[attr->index];
+
+	/* handle stale GPIO's */
+	if (val < 0)
+		return val;
+
+	/* Convert to millivolts and print */
+	return snprintf(buf, PAGE_SIZE, "%u\n", val * 10);
+}
+
 /* These macros are used below in constructing device attribute objects
  * for use with sysfs_create_group() to make a sysfs device file
  * for each register.
@@ -254,6 +335,10 @@ static ssize_t ltc4245_show_alarm(struct device *dev,
 	static SENSOR_DEVICE_ATTR_2(name, S_IRUGO, \
 	ltc4245_show_alarm, NULL, (mask), reg)
 
Quoted 8 lines

drivers/hwmon/ltc4245.c static ssize_t ltc4245_show_alarm(struct device *dev, · line 340

Quoted 3 lines
drivers/hwmon/ltc4245.c +3 -0
+#define LTC4245_GPIO(name, gpio_num) \
+	static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
+	ltc4245_show_gpio, NULL, gpio_num)

You already have an enum value by that name, this is confusing. That's what you get for prefixing your register names with only LTC4245_ instead of LTC4245_REG_ as most drivers are doing.

The driver works, so I guess the compiler isn't confused. How about I rename the macro? Is there a different name you would suggest?

Quoted 20 lines
Quoted 20 lines
drivers/hwmon/ltc4245.c +6 -1
+
 /* Construct a sensor_device_attribute structure for each register */
 
 /* Input voltages */
@@ -293,7 +378,11 @@ LTC4245_ALARM(in7_min_alarm,	(1 << 2),	LTC4245_FAULT2);
 LTC4245_ALARM(in8_min_alarm,	(1 << 3),	LTC4245_FAULT2);
 
 /* GPIO voltages */
-LTC4245_VOLTAGE(in9_input,			LTC4245_GPIOADC);
+LTC4245_GPIO(in9_input,				0);
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+LTC4245_GPIO(in10_input,			1);
+LTC4245_GPIO(in11_input,			2);
+#endif
 
 /* Power Consumption (virtual) */
 LTC4245_POWER(power1_input,			LTC4245_12VSENSE);
@@ -336,6 +425,10 @@ static struct attribute *ltc4245_attributes[] = {
 	&sensor_dev_attr_in8_min_alarm.dev_attr.attr,
 
Quoted 9 lines

drivers/hwmon/ltc4245.c static struct attribute *ltc4245_attributes[] = { · line 434

Quoted 8 lines
drivers/hwmon/ltc4245.c +4 -0
 	&sensor_dev_attr_in9_input.dev_attr.attr,
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+	&sensor_dev_attr_in10_input.dev_attr.attr,
+	&sensor_dev_attr_in11_input.dev_attr.attr,
+#endif
 
 	&sensor_dev_attr_power1_input.dev_attr.attr,
 	&sensor_dev_attr_power2_input.dev_attr.attr,

One more question: if I use a module parameter or platform data to enable the extra GPIOs, how would I handle this array? I don't see how I can make it work other than generating two different (mostly redundant) arrays and registering a different one for each configuration.

Ira

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder

Hi Ira,

Quoted 23 lines · Ira W. Snyder
Quoted 13 lines · Jean Delvare
Quoted 12 lines · Ira W. Snyder
drivers/hwmon/ltc4245.c +12 -0
+
+	/* Update saved data */
+	data->cregs[LTC4245_GPIO] = gpio;
+	data->last_gpio = gpio_next;
+}
+#else
+static void ltc4245_update_gpios(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ltc4245_data *data = i2c_get_clientdata(client);
+
+	/* Just copy the data from the the GPIOADC register */
Quoted 8 lines

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 125

Quoted 3 lines
drivers/hwmon/ltc4245.c +3 -0
+	data->gpios[0] = data->vregs[LTC4245_GPIOADC - 0x10];
+}
+#endif

Not sure why you define this stub function. If you want your patch to be as little intrusive as possible, you can skip ltc4245_update_gpios altogether in the general case, and handle in9 as every other voltage input as the driver was doing before your patch.

Quoted 8 lines

I did it so ltc4245_update_gpios() could be called in both cases, without any conditional logic. See the hunk below. I just call ltc4245_update_gpios() without any #ifdef, it "just works" in both cases.

This is the usual thing Linux does with headers. For example, see include/linux/pci.h pci_enable_msix() function. When CONFIG_PCI_MSI=n they stub out the function so it does the right thing: return an error.

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Quoted 11 lines
Quoted 8 lines

drivers/hwmon/ltc4245.c static ssize_t ltc4245_show_alarm(struct device *dev, · line 340

Quoted 4 lines

(...)

drivers/hwmon/ltc4245.c +3 -0
+#define LTC4245_GPIO(name, gpio_num) \
+	static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
+	ltc4245_show_gpio, NULL, gpio_num)

You already have an enum value by that name, this is confusing. That's what you get for prefixing your register names with only LTC4245_ instead of LTC4245_REG_ as most drivers are doing.

The driver works, so I guess the compiler isn't confused. How about I rename the macro? Is there a different name you would suggest?

I was about to suggest LTC4245_GPIOADC, you that one already exists too. LTC4245_VOLTAGE_GPIO maybe?

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/hwmon/ltc4245.c +4 -0
@@ -336,6 +425,10 @@ static struct attribute *ltc4245_attributes[] = {
 	&sensor_dev_attr_in8_min_alarm.dev_attr.attr,
 
 	&sensor_dev_attr_in9_input.dev_attr.attr,
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+	&sensor_dev_attr_in10_input.dev_attr.attr,
+	&sensor_dev_attr_in11_input.dev_attr.attr,
+#endif
 
Quoted 8 lines
Quoted 3 lines

drivers/hwmon/ltc4245.c static struct attribute *ltc4245_attributes[] = { · line 434

Quoted 2 lines
drivers/hwmon/ltc4245.c +0 -0
 	&sensor_dev_attr_power1_input.dev_attr.attr,
 	&sensor_dev_attr_power2_input.dev_attr.attr,

One more question: if I use a module parameter or platform data to enable the extra GPIOs, how would I handle this array? I don't see how I can make it work other than generating two different (mostly redundant) arrays and registering a different one for each configuration.

No, you would move in10 and in11 to a separate array of attributes, with a dedicated attribute group. The general code path would register ltc4245_group, and your platform specific code path would additionally register that other group. See drivers/hwmon/adm1025.c for an example, the in4* attributes are in a separate group.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 31 lines · Jean Delvare

Hi Ira,

Quoted 28 lines · Ira W. Snyder
Quoted 13 lines · Jean Delvare
Quoted 12 lines · Ira W. Snyder
drivers/hwmon/ltc4245.c +12 -0
+
+	/* Update saved data */
+	data->cregs[LTC4245_GPIO] = gpio;
+	data->last_gpio = gpio_next;
+}
+#else
+static void ltc4245_update_gpios(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ltc4245_data *data = i2c_get_clientdata(client);
+
+	/* Just copy the data from the the GPIOADC register */
Quoted 8 lines

drivers/hwmon/ltc4245.c struct ltc4245_data { · line 125

Quoted 3 lines
drivers/hwmon/ltc4245.c +3 -0
+	data->gpios[0] = data->vregs[LTC4245_GPIOADC - 0x10];
+}
+#endif

Not sure why you define this stub function. If you want your patch to be as little intrusive as possible, you can skip ltc4245_update_gpios altogether in the general case, and handle in9 as every other voltage input as the driver was doing before your patch.

I did it so ltc4245_update_gpios() could be called in both cases, without any conditional logic. See the hunk below. I just call ltc4245_update_gpios() without any #ifdef, it "just works" in both cases.

Quoted 8 lines
Quoted 3 lines

This is the usual thing Linux does with headers. For example, see include/linux/pci.h pci_enable_msix() function. When CONFIG_PCI_MSI=n they stub out the function so it does the right thing: return an error.

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Oh, ok. The ltc4245_show_voltage() function reads the voltage register values directly from data->vregs[]. When the extra GPIO inputs are enabled, I have two choices:

1) store them in the new data->gpios[] array
2) store them in data->vregs[]

For #1, ltc4245_show_voltage() doesn't work anymore, since it reads voltage register values from data->vregs[].

For #2, I would have to re-expand data->vregs[] to include all of the GPIO inputs, like it was before. Also, I would need to make ltc4245_get_voltage() handle the -EAGAIN error code.

I think the code is easier to understand if all the GPIOs are treated in the same way, and not completely special for GPIOADC1 vs GPIOADC[23]. That's why I chose #1.

If I do a hybrid approach (store GPIOADC1 in data->vregs[] and GPIOADC[23] in data->gpios[]), then I have to make ltc4245_get_voltage() robust against errors too. Is this what you're suggesting?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

drivers/hwmon/ltc4245.c static ssize_t ltc4245_show_alarm(struct device *dev, · line 340

Quoted 4 lines

(...)

drivers/hwmon/ltc4245.c +3 -0
+#define LTC4245_GPIO(name, gpio_num) \
+	static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
+	ltc4245_show_gpio, NULL, gpio_num)

You already have an enum value by that name, this is confusing. That's what you get for prefixing your register names with only LTC4245_ instead of LTC4245_REG_ as most drivers are doing.

Quoted 6 lines
Quoted 2 lines

The driver works, so I guess the compiler isn't confused. How about I rename the macro? Is there a different name you would suggest?

I was about to suggest LTC4245_GPIOADC, you that one already exists too. LTC4245_VOLTAGE_GPIO maybe?

Seems fine.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/hwmon/ltc4245.c +4 -0
@@ -336,6 +425,10 @@ static struct attribute *ltc4245_attributes[] = {
 	&sensor_dev_attr_in8_min_alarm.dev_attr.attr,
 
 	&sensor_dev_attr_in9_input.dev_attr.attr,
+#ifdef CONFIG_SENSORS_LTC4245_EXTRA_GPIOS
+	&sensor_dev_attr_in10_input.dev_attr.attr,
+	&sensor_dev_attr_in11_input.dev_attr.attr,
+#endif
 
Quoted 8 lines
Quoted 3 lines

drivers/hwmon/ltc4245.c static struct attribute *ltc4245_attributes[] = { · line 434

Quoted 2 lines
drivers/hwmon/ltc4245.c +0 -0
 	&sensor_dev_attr_power1_input.dev_attr.attr,
 	&sensor_dev_attr_power2_input.dev_attr.attr,

One more question: if I use a module parameter or platform data to enable the extra GPIOs, how would I handle this array? I don't see how I can make it work other than generating two different (mostly redundant) arrays and registering a different one for each configuration.

Quoted 6 lines

No, you would move in10 and in11 to a separate array of attributes, with a dedicated attribute group. The general code path would register ltc4245_group, and your platform specific code path would additionally register that other group. See drivers/hwmon/adm1025.c for an example, the in4* attributes are in a separate group.

Ok.

Any thoughts about the kernel config option vs. platform data, and how it relates to the OF bindings?

Ira

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#5 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 19 lines · Ira W. Snyder
Quoted 3 lines · Jean Delvare

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Oh, ok. The ltc4245_show_voltage() function reads the voltage register values directly from data->vregs[]. When the extra GPIO inputs are enabled, I have two choices:

1) store them in the new data->gpios[] array
2) store them in data->vregs[]

For #1, ltc4245_show_voltage() doesn't work anymore, since it reads voltage register values from data->vregs[].

For #2, I would have to re-expand data->vregs[] to include all of the GPIO inputs, like it was before. Also, I would need to make ltc4245_get_voltage() handle the -EAGAIN error code.

Quoted 7 lines

I think the code is easier to understand if all the GPIOs are treated in the same way, and not completely special for GPIOADC1 vs GPIOADC[23]. That's why I chose #1.

If I do a hybrid approach (store GPIOADC1 in data->vregs[] and GPIOADC[23] in data->gpios[]), then I have to make ltc4245_get_voltage() robust against errors too. Is this what you're suggesting?

No. But let's wait and see if you move to OF platform data, the whole question will be moot. If you keep the config option approach, I'll propose an iterative patch and we can discuss it then.

Quoted 3 lines

(...)
Any thoughts about the kernel config option vs. platform data, and how it relates to the OF bindings?

I would prefer platform-data-based. But I fear I don't know anything about OF bindings. Better ask the embedded folks (e.g. Grant Likely), they will know.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#6 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 32 lines · Jean Delvare
Quoted 19 lines · Ira W. Snyder
Quoted 3 lines · Jean Delvare

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Oh, ok. The ltc4245_show_voltage() function reads the voltage register values directly from data->vregs[]. When the extra GPIO inputs are enabled, I have two choices:

1) store them in the new data->gpios[] array
2) store them in data->vregs[]

For #1, ltc4245_show_voltage() doesn't work anymore, since it reads voltage register values from data->vregs[].

For #2, I would have to re-expand data->vregs[] to include all of the GPIO inputs, like it was before. Also, I would need to make ltc4245_get_voltage() handle the -EAGAIN error code.

Quoted 7 lines

I think the code is easier to understand if all the GPIOs are treated in the same way, and not completely special for GPIOADC1 vs GPIOADC[23]. That's why I chose #1.

If I do a hybrid approach (store GPIOADC1 in data->vregs[] and GPIOADC[23] in data->gpios[]), then I have to make ltc4245_get_voltage() robust against errors too. Is this what you're suggesting?

No. But let's wait and see if you move to OF platform data, the whole question will be moot. If you keep the config option approach, I'll propose an iterative patch and we can discuss it then.

Quoted 8 lines
Quoted 3 lines

(...)
Any thoughts about the kernel config option vs. platform data, and how it relates to the OF bindings?

I would prefer platform-data-based. But I fear I don't know anything about OF bindings. Better ask the embedded folks (e.g. Grant Likely), they will know.

Grant, you're listed in MAINTAINERS as the OF bindings maintainer. Is it currently possible for the i2c OF binding to pass platform_data to hwmon drivers that are probed via the device tree? If so, can you point me to an example. If not, can you suggest what I should do?

Here is a short example from my device tree (a lightly modified 834x_mds device tree):

i2c@3100 {
	#address-cells = <1>;
	#size-cells = <0>;
	cell-index = <1>;
	compatible = "fsl-i2c";
	reg = <0x3100 0x100>;
	interrupts = <15 0x8>;
	interrupt-parent = <&ipic>;
	clock-frequency = <400000>;

	ltc4245@XX {
		compatible = "LLTC,ltc4245";
		reg = <0>;	// from bootloader
	};
};

I'd like to be able to send platform data to the drivers/hwmon/ltc4245.c driver. On my platform, this is probed automatically using the device tree snippet above.

Thanks,
Ira

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#7 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 66 lines · Ira W. Snyder
Quoted 32 lines · Jean Delvare
Quoted 19 lines · Ira W. Snyder
Quoted 3 lines · Jean Delvare

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Oh, ok. The ltc4245_show_voltage() function reads the voltage register values directly from data->vregs[]. When the extra GPIO inputs are enabled, I have two choices:

1) store them in the new data->gpios[] array
2) store them in data->vregs[]

For #1, ltc4245_show_voltage() doesn't work anymore, since it reads voltage register values from data->vregs[].

For #2, I would have to re-expand data->vregs[] to include all of the GPIO inputs, like it was before. Also, I would need to make ltc4245_get_voltage() handle the -EAGAIN error code.

Quoted 7 lines

I think the code is easier to understand if all the GPIOs are treated in the same way, and not completely special for GPIOADC1 vs GPIOADC[23]. That's why I chose #1.

If I do a hybrid approach (store GPIOADC1 in data->vregs[] and GPIOADC[23] in data->gpios[]), then I have to make ltc4245_get_voltage() robust against errors too. Is this what you're suggesting?

No. But let's wait and see if you move to OF platform data, the whole question will be moot. If you keep the config option approach, I'll propose an iterative patch and we can discuss it then.

Quoted 8 lines
Quoted 3 lines

(...)
Any thoughts about the kernel config option vs. platform data, and how it relates to the OF bindings?

I would prefer platform-data-based. But I fear I don't know anything about OF bindings. Better ask the embedded folks (e.g. Grant Likely), they will know.

Grant, you're listed in MAINTAINERS as the OF bindings maintainer. Is it currently possible for the i2c OF binding to pass platform_data to hwmon drivers that are probed via the device tree? If so, can you point me to an example. If not, can you suggest what I should do?

Here is a short example from my device tree (a lightly modified 834x_mds device tree):

i2c@3100 {
       #address-cells = <1>;
       #size-cells = <0>;
       cell-index = <1>;
       compatible = "fsl-i2c";
       reg = <0x3100 0x100>;
       interrupts = <15 0x8>;
       interrupt-parent = <&ipic>;
       clock-frequency = <400000>;

       ltc4245@XX {
               compatible = "LLTC,ltc4245";
               reg = <0>;      // from bootloader
       };
};

Quoted 3 lines

I'd like to be able to send platform data to the drivers/hwmon/ltc4245.c driver. On my platform, this is probed automatically using the device tree snippet above.

What is in the platform data? As of the .35 merge window, the device node pointer lives in struct device, so it is available to all Linux device drivers if CONFIG_OF is set. If it is simply data that needs to be passed, then the driver itself can extract it from the tree in the absence of pdata. If you need to pass function pointers or the like, then probably the best thing to do is to register a bus notifier in the platform code before registering devices. That way the platform code can intercept the device and register pdata before the device is bound to a driver.

g.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#8 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 67 lines · Grant Likely
Quoted 66 lines · Ira W. Snyder
Quoted 32 lines · Jean Delvare
Quoted 19 lines · Ira W. Snyder
Quoted 3 lines · Jean Delvare

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Oh, ok. The ltc4245_show_voltage() function reads the voltage register values directly from data->vregs[]. When the extra GPIO inputs are enabled, I have two choices:

1) store them in the new data->gpios[] array
2) store them in data->vregs[]

For #1, ltc4245_show_voltage() doesn't work anymore, since it reads voltage register values from data->vregs[].

For #2, I would have to re-expand data->vregs[] to include all of the GPIO inputs, like it was before. Also, I would need to make ltc4245_get_voltage() handle the -EAGAIN error code.

Quoted 7 lines

I think the code is easier to understand if all the GPIOs are treated in the same way, and not completely special for GPIOADC1 vs GPIOADC[23]. That's why I chose #1.

If I do a hybrid approach (store GPIOADC1 in data->vregs[] and GPIOADC[23] in data->gpios[]), then I have to make ltc4245_get_voltage() robust against errors too. Is this what you're suggesting?

No. But let's wait and see if you move to OF platform data, the whole question will be moot. If you keep the config option approach, I'll propose an iterative patch and we can discuss it then.

Quoted 8 lines
Quoted 3 lines

(...)
Any thoughts about the kernel config option vs. platform data, and how it relates to the OF bindings?

I would prefer platform-data-based. But I fear I don't know anything about OF bindings. Better ask the embedded folks (e.g. Grant Likely), they will know.

Grant, you're listed in MAINTAINERS as the OF bindings maintainer. Is it currently possible for the i2c OF binding to pass platform_data to hwmon drivers that are probed via the device tree? If so, can you point me to an example. If not, can you suggest what I should do?

Here is a short example from my device tree (a lightly modified 834x_mds device tree):

i2c@3100 {
       #address-cells = <1>;
       #size-cells = <0>;
       cell-index = <1>;
       compatible = "fsl-i2c";
       reg = <0x3100 0x100>;
       interrupts = <15 0x8>;
       interrupt-parent = <&ipic>;
       clock-frequency = <400000>;

       ltc4245@XX {
               compatible = "LLTC,ltc4245";
               reg = <0>;      // from bootloader
       };
};

Quoted 5 lines
Quoted 3 lines

I'd like to be able to send platform data to the drivers/hwmon/ltc4245.c driver. On my platform, this is probed automatically using the device tree snippet above.

What is in the platform data?

A bool/int should be sufficient.

Quoted 9 lines

As of the .35 merge window, the device
node pointer lives in struct device, so it is available to all Linux device drivers if CONFIG_OF is set. If it is simply data that needs to be passed, then the driver itself can extract it from the tree in the absence of pdata. If you need to pass function pointers or the like, then probably the best thing to do is to register a bus notifier in the platform code before registering devices. That way the platform code can intercept the device and register pdata before the device is bound to a driver.

Ok, so I should wrap the OF detection code in CONFIG_OF in my driver, right? I just quickly browsed through the code, and it seems like it should be straightforward to use pdata and then fall back on OF data.

Jean, give me a few hours to cook up another patch, now that I have this information from Grant.

Thanks for the quick reply!
Ira

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#9 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 2 lines · Ira W. Snyder

Jean, give me a few hours to cook up another patch, now that I have this information from Grant.

I can give you 9, as I'm on my way to bed.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#10 lore raw

Re: [lm-sensors] [PATCH 2/2] hwmon: (ltc4245) expose all GPIO pins

In reply to Ira W. Snyder
Quoted 86 lines · Ira W. Snyder
Quoted 67 lines · Grant Likely
Quoted 66 lines · Ira W. Snyder
Quoted 32 lines · Jean Delvare
Quoted 19 lines · Ira W. Snyder
Quoted 3 lines · Jean Delvare

Sorry for not being clear. I wasn't objecting to the stub's existence, but to the fact that it was doing something. I expected it to do nothing at all, and ltc4245_show_voltage() would be used for in9.

Oh, ok. The ltc4245_show_voltage() function reads the voltage register values directly from data->vregs[]. When the extra GPIO inputs are enabled, I have two choices:

1) store them in the new data->gpios[] array
2) store them in data->vregs[]

For #1, ltc4245_show_voltage() doesn't work anymore, since it reads voltage register values from data->vregs[].

For #2, I would have to re-expand data->vregs[] to include all of the GPIO inputs, like it was before. Also, I would need to make ltc4245_get_voltage() handle the -EAGAIN error code.

Quoted 7 lines

I think the code is easier to understand if all the GPIOs are treated in the same way, and not completely special for GPIOADC1 vs GPIOADC[23]. That's why I chose #1.

If I do a hybrid approach (store GPIOADC1 in data->vregs[] and GPIOADC[23] in data->gpios[]), then I have to make ltc4245_get_voltage() robust against errors too. Is this what you're suggesting?

No. But let's wait and see if you move to OF platform data, the whole question will be moot. If you keep the config option approach, I'll propose an iterative patch and we can discuss it then.

Quoted 8 lines
Quoted 3 lines

(...)
Any thoughts about the kernel config option vs. platform data, and how it relates to the OF bindings?

I would prefer platform-data-based. But I fear I don't know anything about OF bindings. Better ask the embedded folks (e.g. Grant Likely), they will know.

Grant, you're listed in MAINTAINERS as the OF bindings maintainer. Is it currently possible for the i2c OF binding to pass platform_data to hwmon drivers that are probed via the device tree? If so, can you point me to an example. If not, can you suggest what I should do?

Here is a short example from my device tree (a lightly modified 834x_mds device tree):

i2c@3100 {
á á á á#address-cells = <1>;
á á á á#size-cells = <0>;
á á á ácell-index = <1>;
á á á ácompatible = "fsl-i2c";
á á á áreg = <0x3100 0x100>;
á á á áinterrupts = <15 0x8>;
á á á áinterrupt-parent = <&ipic>;
á á á áclock-frequency = <400000>;

á á á áltc4245@XX {
á á á á á á á ácompatible = "LLTC,ltc4245";
á á á á á á á áreg = <0>; á á á// from bootloader
á á á á};
};

Quoted 5 lines
Quoted 3 lines

I'd like to be able to send platform data to the drivers/hwmon/ltc4245.c driver. On my platform, this is probed automatically using the device tree snippet above.

What is in the platform data?

A bool/int should be sufficient.

Quoted 9 lines

As of the .35 merge window, the device
node pointer lives in struct device, so it is available to all Linux device drivers if CONFIG_OF is set.  If it is simply data that needs to be passed, then the driver itself can extract it from the tree in the absence of pdata.  If you need to pass function pointers or the like, then probably the best thing to do is to register a bus notifier in the platform code before registering devices.  That way the platform code can intercept the device and register pdata before the device is bound to a driver.

Quoted 3 lines

Ok, so I should wrap the OF detection code in CONFIG_OF in my driver, right? I just quickly browsed through the code, and it seems like it should be straightforward to use pdata and then fall back on OF data.

Correct. The goal is to allow the driver-specific OF adapter code to live with the driver, while still having as little as possible impact on driver design as a whole.

g.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors