Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753006AbaDDMoo (ORCPT ); Fri, 4 Apr 2014 08:44:44 -0400 Received: from mail-wg0-f50.google.com ([74.125.82.50]:43741 "EHLO mail-wg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752915AbaDDMof (ORCPT ); Fri, 4 Apr 2014 08:44:35 -0400 From: Pantelis Antoniou To: Grant Likely Cc: Rob Herring , Stephen Warren , Matt Porter , Koen Kooi , Alison Chaiken , Dinh Nguyen , Jan Lubbe , Alexander Sverdlin , Michael Stickel , Guenter Roeck , Dirk Behme , Alan Tull , Sascha Hauer , Michael Bohan , Ionut Nicu , Michal Simek , Matt Ranostay , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pete Popov , Dan Malek , Georgi Vlaev , Pantelis Antoniou , Pantelis Antoniou Subject: [PATCH v4 6/8] OF: i2c: Add overlay bus handler Date: Fri, 4 Apr 2014 15:43:59 +0300 Message-Id: <1396615441-29630-7-git-send-email-pantelis.antoniou@konsulko.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1396615441-29630-1-git-send-email-pantelis.antoniou@konsulko.com> References: <1396615441-29630-1-git-send-email-pantelis.antoniou@konsulko.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the bus handler registration needed for performing overlays containing i2c devices. Signed-off-by: Pantelis Antoniou --- drivers/i2c/i2c-core.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index aee3b99..017fb03 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1082,10 +1082,89 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) return i2c_verify_adapter(dev); } EXPORT_SYMBOL(of_find_i2c_adapter_by_node); + +#ifdef CONFIG_OF_OVERLAY +static int i2c_handler_create(struct of_overlay_device_entry *de, + int revert) +{ + struct device_node *dn; + struct i2c_adapter *adap; + struct i2c_client *client; + + if (!de || !de->np) + return -ENOTSUPP; + + dn = de->np; + + adap = of_find_i2c_adapter_by_node(dn->parent); + if (adap == NULL) + return -ENOTSUPP; + + client = of_i2c_register_device(adap, dn); + put_device(&adap->dev); + + if (client == NULL) { + pr_err("%s: failed to create i2c client device " + "for '%s'\n", + __func__, dn->full_name); + /* of_i2c_device_create tosses the real error code */ + return -EINVAL; + } + + return 0; +} + +static int i2c_handler_remove(struct of_overlay_device_entry *de, + int revert) +{ + struct device_node *dn; + struct i2c_client *client; + + if (!de || !de->np) + return -ENOTSUPP; + + dn = de->np; + + client = of_find_i2c_device_by_node(dn); + if (client == NULL) + return -ENOTSUPP; + + /* unregister takes one ref away */ + i2c_unregister_device(client); + + /* and put the reference of the find */ + put_device(&client->dev); + + return 0; +} + +static const struct of_overlay_handler_ops i2c_handler_ops = { + .create = i2c_handler_create, + .remove = i2c_handler_remove, +}; + +static struct of_overlay_handler i2c_handler = { + .name = "i2c", + .ops = &i2c_handler_ops, +}; + +static int __init i2c_bus_handler_register(void) +{ + return of_overlay_handler_register(&i2c_handler); +} +#endif + #else static void of_i2c_register_devices(struct i2c_adapter *adap) { } #endif /* CONFIG_OF */ +#if !defined(CONFIG_OF) || !defined(CONFIG_OF_OVERLAY) +static inline int i2c_bus_handler_register(void) +{ + return 0; +} +#endif + /* ACPI support code */ #if IS_ENABLED(CONFIG_ACPI) @@ -1677,8 +1756,14 @@ static int __init i2c_init(void) retval = i2c_add_driver(&dummy_driver); if (retval) goto class_err; - return 0; + retval = i2c_bus_handler_register(); + if (retval) + goto bus_handler_err; + + return 0; +bus_handler_err: + i2c_del_driver(&dummy_driver); class_err: #ifdef CONFIG_I2C_COMPAT class_compat_unregister(i2c_adapter_compat_class); -- 1.7.12 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/