Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: i2c-smbus: add of_i2c_setup_smbus_alert

This commit adds of_i2c_setup_smbus_alert which allows the smbalert
driver to be attached to an i2c adapter via the device tree.

Signed-off-by: Phil Reid <preid@electromag.com.au>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Phil Reid and committed by
Wolfram Sang
69d17246 3c0a60be

+42 -3
+2 -2
Documentation/devicetree/bindings/i2c/i2c.txt
··· 59 59 interrupts used by the device. 60 60 61 61 - interrupt-names 62 - "irq" and "wakeup" names are recognized by I2C core, other names are 63 - left to individual drivers. 62 + "irq", "wakeup" and "smbus_alert" names are recognized by I2C core, 63 + other names are left to individual drivers. 64 64 65 65 - host-notify 66 66 device uses SMBus host notify protocol instead of interrupt line.
+22
drivers/i2c/i2c-core-smbus.c
··· 625 625 return i2c_new_device(adapter, &ara_board_info); 626 626 } 627 627 EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); 628 + 629 + #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) 630 + int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter) 631 + { 632 + struct i2c_client *client; 633 + int irq; 634 + 635 + irq = of_property_match_string(adapter->dev.of_node, "interrupt-names", 636 + "smbus_alert"); 637 + if (irq == -EINVAL || irq == -ENODATA) 638 + return 0; 639 + else if (irq < 0) 640 + return irq; 641 + 642 + client = i2c_setup_smbus_alert(adapter, NULL); 643 + if (!client) 644 + return -ENODEV; 645 + 646 + return 0; 647 + } 648 + EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert); 649 + #endif
+9 -1
drivers/i2c/i2c-smbus.c
··· 21 21 #include <linux/interrupt.h> 22 22 #include <linux/kernel.h> 23 23 #include <linux/module.h> 24 + #include <linux/of_irq.h> 24 25 #include <linux/slab.h> 25 26 #include <linux/workqueue.h> 26 27 ··· 140 139 if (!alert) 141 140 return -ENOMEM; 142 141 143 - irq = setup->irq; 142 + if (setup) { 143 + irq = setup->irq; 144 + } else { 145 + irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert"); 146 + if (irq <= 0) 147 + return irq; 148 + } 149 + 144 150 INIT_WORK(&alert->alert, smbalert_work); 145 151 alert->ara = ara; 146 152
+9
include/linux/i2c-smbus.h
··· 49 49 struct i2c_smbus_alert_setup *setup); 50 50 int i2c_handle_smbus_alert(struct i2c_client *ara); 51 51 52 + #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF) 53 + int of_i2c_setup_smbus_alert(struct i2c_adapter *adap); 54 + #else 55 + static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap) 56 + { 57 + return 0; 58 + } 59 + #endif 60 + 52 61 #endif /* _LINUX_I2C_SMBUS_H */