Skip to contentSkip to conversation

i2c: smbusalert# support

PATCH In review David Brownell 1 participant 1 message Apr 16, 2008

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

PATCH 4/5 i2c: smbusalert# support

Infrastructure supporting SMBALERT# interrupts and the related SMBus protocols. These are defined as "optional" by the spec.

- The i2c_adapter now includes a work_struct doing the work of talking to the Alert Response Address until nobody responds any more (and hence the IRQ is no longer asserted). Follows SMBus 2.0 not 1.1; there seems to be no point in trying to handle ten-bit addresses.

- Some of the ways that work_struct could be driven:

* Adapter driver provides an IRQ, which is bound to a handler which schedules that work_struct (using keventd for now).

* Adapter driver schedules that work struct itself, maybe even on a workqueue of its own. It asks the core to set it up by setting i2c_adapter.do_setup_alert ... SMBALERT# could be a subcase of the adapter's normal interrupt handler. (Or, some boards may want to use polling.)

- The "i2c-gpio" driver now handles an optional named resource for that SMBus alert signal. Named since, when this is substituted for a misbehaving "native" driver, positional ids should be left alone. (It might be better to put this logic into i2c core, to apply whenever the i2c_adapter.dev.parent is a platform device.)

- There's a new driver method used to report that a given device has issued an alert. Its parameter includes the one bit of information provided by the device in its alert response message.

The IRQ driven code path is always enabled, if it's available.

---
NOTE: the i2c list archives hold a previous SMBALERT# patch from Hendrik Sattler <[email protected]> on Sept 7 2006. This patch improves on that one one in several respects.

NOTE: The SMBus "Host Notify" protocol is sometimes used for similar purposes. Although host support for it is "mandatory", there seems to be no Linux support for it. The minimal support would seem to involve a callback accepting the 17 bits of data provided by the slave device, plus I2C adapter updates needed to receive those unsolicited messages.

 drivers/i2c/busses/i2c-gpio.c |    6 +
 drivers/i2c/i2c-core.c        |  127 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/i2c.h           |   13 ++++
 3 files changed, 146 insertions(+)
drivers/i2c/busses/i2c-gpio.c +6 -0
@@ -82,6 +82,7 @@ static int __init i2c_gpio_probe(struct 
 	struct i2c_gpio_platform_data *pdata;
 	struct i2c_algo_bit_data *bit_data;
 	struct i2c_adapter *adap;
+	struct resource *smbalert;
 	int ret;
 
 	pdata = pdev->dev.platform_data;
@@ -143,6 +144,11 @@ static int __init i2c_gpio_probe(struct 
 	adap->class = I2C_CLASS_HWMON;
 	adap->dev.parent = &pdev->dev;
 
+	smbalert = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
+			"smbalert#");
+	if (smbalert)
+		adap->irq = smbalert->start;
+
 	/*
 	 * If "dev->id" is negative we consider it as zero.
 	 * The reason to do so is to avoid sysfs names that only make
drivers/i2c/i2c-core.c +127 -0

175 lines not on this page · raw message

include/linux/i2c.h +13 -0
@@ -34,6 +34,7 @@
 #include <linux/device.h>	/* for struct device */
 #include <linux/sched.h>	/* for completion */
 #include <linux/mutex.h>
+#include <linux/workqueue.h>
 
 /* --- General options ------------------------------------------------	*/
 
@@ -134,6 +135,11 @@ struct i2c_driver {
 	int (*suspend)(struct i2c_client *, pm_message_t mesg);
 	int (*resume)(struct i2c_client *);
 
+	/* SMBus alert protocol support; the low bit of the code sometimes
+	 * passes event data (e.g. exceeding upper vs lower limit).
+	 */
+	void (*alert)(struct i2c_client *, bool flag);
+
 	/* a ioctl like command that can be used to perform specific functions
 	 * with the device.
 	 */
@@ -333,6 +339,13 @@ struct i2c_adapter {
 	struct list_head clients;	/* DEPRECATED */
 	char name[48];
 	struct completion dev_released;
+
+	/* SMBALERT# support */
+	unsigned		do_setup_alert:1;
+	unsigned		has_alert_irq:1;
+	int			irq;
+	struct i2c_client	*ara;
+	struct work_struct	alert;
 };
 #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
 

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