i2c: core: helper function to detect slave mode
This function has the purpose of mode detection by checking the device nodes for a reg matching with the I2C_OWN_SLAVE_ADDREESS flag. Currently only checks using OF functions (ACPI slave not supported yet). Signed-off-by: Luis Oliveira <lolivei@synopsys.com> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>zero-colors
parent
50b918c5a6
commit
cefae80249
|
@ -3690,6 +3690,39 @@ int i2c_slave_unregister(struct i2c_client *client)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(i2c_slave_unregister);
|
EXPORT_SYMBOL_GPL(i2c_slave_unregister);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* i2c_detect_slave_mode - detect operation mode
|
||||||
|
* @dev: The device owning the bus
|
||||||
|
*
|
||||||
|
* This checks the device nodes for an I2C slave by checking the address
|
||||||
|
* used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
|
||||||
|
* flag this means the device is configured to act as a I2C slave and it will
|
||||||
|
* be listening at that address.
|
||||||
|
*
|
||||||
|
* Returns true if an I2C own slave address is detected, otherwise returns
|
||||||
|
* false.
|
||||||
|
*/
|
||||||
|
bool i2c_detect_slave_mode(struct device *dev)
|
||||||
|
{
|
||||||
|
if (IS_BUILTIN(CONFIG_OF) && dev->of_node) {
|
||||||
|
struct device_node *child;
|
||||||
|
u32 reg;
|
||||||
|
|
||||||
|
for_each_child_of_node(dev->of_node, child) {
|
||||||
|
of_property_read_u32(child, "reg", ®);
|
||||||
|
if (reg & I2C_OWN_SLAVE_ADDRESS) {
|
||||||
|
of_node_put(child);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) {
|
||||||
|
dev_dbg(dev, "ACPI slave is not supported yet\n");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(i2c_detect_slave_mode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
|
MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
|
||||||
|
|
|
@ -282,6 +282,7 @@ enum i2c_slave_event {
|
||||||
|
|
||||||
extern int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
|
extern int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
|
||||||
extern int i2c_slave_unregister(struct i2c_client *client);
|
extern int i2c_slave_unregister(struct i2c_client *client);
|
||||||
|
extern bool i2c_detect_slave_mode(struct device *dev);
|
||||||
|
|
||||||
static inline int i2c_slave_event(struct i2c_client *client,
|
static inline int i2c_slave_event(struct i2c_client *client,
|
||||||
enum i2c_slave_event event, u8 *val)
|
enum i2c_slave_event event, u8 *val)
|
||||||
|
|
Loading…
Reference in New Issue