aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 16:06:58 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 16:06:58 -0500
commit7ef58b32f571bffb7763c6252ad7527562081f34 (patch)
tree6d1493304ec7a47e4d9e3e84dc9f6e53547dff91 /drivers/i2c
parent413fd0e3fbf52873f2310eb75bfa6c7b72847277 (diff)
parentc46ca3c8310b61d253a39ff1375ea97912794cd1 (diff)
Merge tag 'devicetree-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux
Pull devicetree changes from Grant Likely: "Lots of activity in the devicetree code for v3.18. Most of it is related to getting all of the overlay support code in place, but there are other important things in there. Highlights: - OF_RECONFIG notifiers for SPI, I2C and Platform devices. Those subsystems can now respond to live changes to the device tree. - CONFIG_OF_OVERLAY method for applying live changes to the device tree - Removal of the of_allnodes list. This used to be used to iterate over all the nodes in the device tree, but it is unnecessary because the same thing can be done by iterating over the list of child pointers. Getting rid of of_allnodes saves some memory and avoids the possibility of of_allnodes being sorted differently from the child lists. - Support for retrieving original DTB blob via sysfs. Needed by kexec. - More unittests - Documentation and minor bug fixes" * tag 'devicetree-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux: (42 commits) of: Delete unnecessary check before calling "of_node_put()" of: Drop ->next pointer from struct device_node spi: Check for spi_of_notifier when CONFIG_OF_DYNAMIC=y of: support passing console options with stdout-path of: add optional options parameter to of_find_node_by_path() of: Add bindings for chosen node, stdout-path of: Remove unneeded and incorrect MODULE_DEVICE_TABLE ARM: dt: fix up PL011 device tree bindings of: base, fix of_property_read_string_helper kernel-doc of: remove select of non-existant OF_DEVICE config symbol spi/of: Add OF notifier handler spi/of: Create new device registration method and accessors i2c/of: Add OF_RECONFIG notifier handler i2c/of: Factor out Devicetree registration code of/overlay: Add overlay unittests of/overlay: Introduce DT overlay support of/reconfig: Add OF_DYNAMIC notifier for platform_bus_type of/reconfig: Always use the same structure for notifiers of/reconfig: Add debug output for OF_RECONFIG notifiers of/reconfig: Add empty stubs for the of_reconfig methods ...
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c149
1 files changed, 104 insertions, 45 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 68aeb8eedae0..229a89e84b0f 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -49,6 +49,7 @@
49#include <linux/acpi.h> 49#include <linux/acpi.h>
50#include <linux/jump_label.h> 50#include <linux/jump_label.h>
51#include <asm/uaccess.h> 51#include <asm/uaccess.h>
52#include <linux/err.h>
52 53
53#include "i2c-core.h" 54#include "i2c-core.h"
54 55
@@ -1369,63 +1370,69 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
1369/* OF support code */ 1370/* OF support code */
1370 1371
1371#if IS_ENABLED(CONFIG_OF) 1372#if IS_ENABLED(CONFIG_OF)
1372static void of_i2c_register_devices(struct i2c_adapter *adap) 1373static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
1374 struct device_node *node)
1373{ 1375{
1374 void *result; 1376 struct i2c_client *result;
1375 struct device_node *node; 1377 struct i2c_board_info info = {};
1378 struct dev_archdata dev_ad = {};
1379 const __be32 *addr;
1380 int len;
1376 1381
1377 /* Only register child devices if the adapter has a node pointer set */ 1382 dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);
1378 if (!adap->dev.of_node)
1379 return;
1380 1383
1381 dev_dbg(&adap->dev, "of_i2c: walking child nodes\n"); 1384 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
1385 dev_err(&adap->dev, "of_i2c: modalias failure on %s\n",
1386 node->full_name);
1387 return ERR_PTR(-EINVAL);
1388 }
1382 1389
1383 for_each_available_child_of_node(adap->dev.of_node, node) { 1390 addr = of_get_property(node, "reg", &len);
1384 struct i2c_board_info info = {}; 1391 if (!addr || (len < sizeof(int))) {
1385 struct dev_archdata dev_ad = {}; 1392 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
1386 const __be32 *addr; 1393 node->full_name);
1387 int len; 1394 return ERR_PTR(-EINVAL);
1395 }
1388 1396
1389 dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name); 1397 info.addr = be32_to_cpup(addr);
1398 if (info.addr > (1 << 10) - 1) {
1399 dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",
1400 info.addr, node->full_name);
1401 return ERR_PTR(-EINVAL);
1402 }
1390 1403
1391 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { 1404 info.irq = irq_of_parse_and_map(node, 0);
1392 dev_err(&adap->dev, "of_i2c: modalias failure on %s\n", 1405 info.of_node = of_node_get(node);
1393 node->full_name); 1406 info.archdata = &dev_ad;
1394 continue;
1395 }
1396 1407
1397 addr = of_get_property(node, "reg", &len); 1408 if (of_get_property(node, "wakeup-source", NULL))
1398 if (!addr || (len < sizeof(int))) { 1409 info.flags |= I2C_CLIENT_WAKE;
1399 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
1400 node->full_name);
1401 continue;
1402 }
1403 1410
1404 info.addr = be32_to_cpup(addr); 1411 request_module("%s%s", I2C_MODULE_PREFIX, info.type);
1405 if (info.addr > (1 << 10) - 1) { 1412
1406 dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n", 1413 result = i2c_new_device(adap, &info);
1407 info.addr, node->full_name); 1414 if (result == NULL) {
1408 continue; 1415 dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
1409 } 1416 node->full_name);
1417 of_node_put(node);
1418 irq_dispose_mapping(info.irq);
1419 return ERR_PTR(-EINVAL);
1420 }
1421 return result;
1422}
1410 1423
1411 info.irq = irq_of_parse_and_map(node, 0); 1424static void of_i2c_register_devices(struct i2c_adapter *adap)
1412 info.of_node = of_node_get(node); 1425{
1413 info.archdata = &dev_ad; 1426 struct device_node *node;
1414 1427
1415 if (of_get_property(node, "wakeup-source", NULL)) 1428 /* Only register child devices if the adapter has a node pointer set */
1416 info.flags |= I2C_CLIENT_WAKE; 1429 if (!adap->dev.of_node)
1430 return;
1417 1431
1418 request_module("%s%s", I2C_MODULE_PREFIX, info.type); 1432 dev_dbg(&adap->dev, "of_i2c: walking child nodes\n");
1419 1433
1420 result = i2c_new_device(adap, &info); 1434 for_each_available_child_of_node(adap->dev.of_node, node)
1421 if (result == NULL) { 1435 of_i2c_register_device(adap, node);
1422 dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
1423 node->full_name);
1424 of_node_put(node);
1425 irq_dispose_mapping(info.irq);
1426 continue;
1427 }
1428 }
1429} 1436}
1430 1437
1431static int of_dev_node_match(struct device *dev, void *data) 1438static int of_dev_node_match(struct device *dev, void *data)
@@ -1945,6 +1952,52 @@ void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
1945} 1952}
1946EXPORT_SYMBOL(i2c_clients_command); 1953EXPORT_SYMBOL(i2c_clients_command);
1947 1954
1955#if IS_ENABLED(CONFIG_OF_DYNAMIC)
1956static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
1957 void *arg)
1958{
1959 struct of_reconfig_data *rd = arg;
1960 struct i2c_adapter *adap;
1961 struct i2c_client *client;
1962
1963 switch (of_reconfig_get_state_change(action, rd)) {
1964 case OF_RECONFIG_CHANGE_ADD:
1965 adap = of_find_i2c_adapter_by_node(rd->dn->parent);
1966 if (adap == NULL)
1967 return NOTIFY_OK; /* not for us */
1968
1969 client = of_i2c_register_device(adap, rd->dn);
1970 put_device(&adap->dev);
1971
1972 if (IS_ERR(client)) {
1973 pr_err("%s: failed to create for '%s'\n",
1974 __func__, rd->dn->full_name);
1975 return notifier_from_errno(PTR_ERR(client));
1976 }
1977 break;
1978 case OF_RECONFIG_CHANGE_REMOVE:
1979 /* find our device by node */
1980 client = of_find_i2c_device_by_node(rd->dn);
1981 if (client == NULL)
1982 return NOTIFY_OK; /* no? not meant for us */
1983
1984 /* unregister takes one ref away */
1985 i2c_unregister_device(client);
1986
1987 /* and put the reference of the find */
1988 put_device(&client->dev);
1989 break;
1990 }
1991
1992 return NOTIFY_OK;
1993}
1994static struct notifier_block i2c_of_notifier = {
1995 .notifier_call = of_i2c_notify,
1996};
1997#else
1998extern struct notifier_block i2c_of_notifier;
1999#endif /* CONFIG_OF_DYNAMIC */
2000
1948static int __init i2c_init(void) 2001static int __init i2c_init(void)
1949{ 2002{
1950 int retval; 2003 int retval;
@@ -1962,6 +2015,10 @@ static int __init i2c_init(void)
1962 retval = i2c_add_driver(&dummy_driver); 2015 retval = i2c_add_driver(&dummy_driver);
1963 if (retval) 2016 if (retval)
1964 goto class_err; 2017 goto class_err;
2018
2019 if (IS_ENABLED(CONFIG_OF_DYNAMIC))
2020 WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier));
2021
1965 return 0; 2022 return 0;
1966 2023
1967class_err: 2024class_err:
@@ -1975,6 +2032,8 @@ bus_err:
1975 2032
1976static void __exit i2c_exit(void) 2033static void __exit i2c_exit(void)
1977{ 2034{
2035 if (IS_ENABLED(CONFIG_OF_DYNAMIC))
2036 WARN_ON(of_reconfig_notifier_unregister(&i2c_of_notifier));
1978 i2c_del_driver(&dummy_driver); 2037 i2c_del_driver(&dummy_driver);
1979#ifdef CONFIG_I2C_COMPAT 2038#ifdef CONFIG_I2C_COMPAT
1980 class_compat_unregister(i2c_adapter_compat_class); 2039 class_compat_unregister(i2c_adapter_compat_class);