From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936908AbdAER1Z (ORCPT ); Thu, 5 Jan 2017 12:27:25 -0500 Received: from smtprelay.synopsys.com ([198.182.60.111]:52064 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936309AbdAER0N (ORCPT ); Thu, 5 Jan 2017 12:26:13 -0500 From: Luis Oliveira To: wsa@the-dreams.de, robh+dt@kernel.org, mark.rutland@arm.com, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Luis.Oliveira@synopsys.com, Ramiro.Oliveira@synopsys.com, Joao.Pinto@synopsys.com, CARLOS.PALMINHA@synopsys.com Subject: [PATCH] i2c: core: helper function to detect slave mode Date: Thu, 5 Jan 2017 17:24:14 +0000 Message-Id: X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Due to the need of checking if the I2C slave address is our own (in other words: if we are the I2C slave) I created a helper function (proposed to me by @Andy) to enable that check. Currently (because I am not able to test it using ACPI) it only supports devicetree declarations. drivers/i2c/i2c-core.c | 19 +++++++++++++++++++ include/linux/i2c.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 3de95a29024c..48e705b23c59 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -3691,6 +3691,25 @@ int i2c_slave_unregister(struct i2c_client *client) return ret; } EXPORT_SYMBOL_GPL(i2c_slave_unregister); + +int i2c_slave_mode_detect(struct device *dev) +{ + struct device_node *child; + u32 reg; + + if (IS_BUILTIN(CONFIG_OF) && dev->of_node) { + for_each_child_of_node(dev->of_node, child) { + of_property_read_u32(child, "reg", ®); + if (reg & I2C_OWN_SLAVE_ADDRESS) + return 1; + } + } else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) { + dev_dbg(dev, "ACPI slave is not supported yet\n"); + } + return 0; +} +EXPORT_SYMBOL_GPL(i2c_slave_mode_detect); + #endif MODULE_AUTHOR("Simon G. Vogl "); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index b2109c522dec..53cf99569af5 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -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_unregister(struct i2c_client *client); +extern int i2c_slave_mode_detect(struct device *dev); static inline int i2c_slave_event(struct i2c_client *client, enum i2c_slave_event event, u8 *val) -- 2.11.0