aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core-of.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-14 03:21:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-14 03:21:46 -0400
commit9bca19a01d50143b736f0f59eb3ccc05b1106172 (patch)
tree3321118b4a6bd4c949634bbdbb3d2c03454ae33b /drivers/i2c/i2c-core-of.c
parent463f202172c31b9c36278001cabfbad4e12da42e (diff)
parent53e39628ac228fada53cc0106be62c6f65f67501 (diff)
Merge branch 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: - mainly feature additions to drivers (stm32f7, qup, xlp9xx, mlxcpld, ...) - conversion to use the i2c_8bit_addr_from_msg macro consistently - move includes to platform_data - core updates to allow the (still in review) I3C subsystem to connect - and the regular share of smaller driver updates * 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (68 commits) i2c: qup: fix building without CONFIG_ACPI i2c: tegra: Remove suspend-resume i2c: imx-lpi2c: Switch to SPDX identifier i2c: mxs: Switch to SPDX identifier i2c: busses: make use of i2c_8bit_addr_from_msg i2c: algos: make use of i2c_8bit_addr_from_msg i2c: rcar: document R8A77980 bindings i2c: qup: Add command-line parameter to override SCL frequency i2c: qup: Correct duty cycle for FM and FM+ i2c: qup: Add support for Fast Mode Plus i2c: qup: add probe path for Centriq ACPI devices i2c: robotfuzz-osif: drop pointless test i2c: robotfuzz-osif: remove pointless local variable i2c: rk3x: Don't print visible virtual mapping MMIO address i2c: opal: don't check number of messages in the driver i2c: ibm_iic: don't check number of messages in the driver i2c: imx: Switch to SPDX identifier i2c: mux: pca954x: merge calls to of_match_device and of_device_get_match_data i2c: mux: demux-pinctrl: use proper parent device for demux adapter i2c: mux: improve error message for failed symlink ...
Diffstat (limited to 'drivers/i2c/i2c-core-of.c')
-rw-r--r--drivers/i2c/i2c-core-of.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index c405270a98b4..6cb7ad608bcd 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -22,53 +22,64 @@
22 22
23#include "i2c-core.h" 23#include "i2c-core.h"
24 24
25static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap, 25int of_i2c_get_board_info(struct device *dev, struct device_node *node,
26 struct device_node *node) 26 struct i2c_board_info *info)
27{ 27{
28 struct i2c_client *client;
29 struct i2c_board_info info = {};
30 struct dev_archdata dev_ad = {};
31 u32 addr; 28 u32 addr;
32 int ret; 29 int ret;
33 30
34 dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node); 31 memset(info, 0, sizeof(*info));
35 32
36 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { 33 if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) {
37 dev_err(&adap->dev, "of_i2c: modalias failure on %pOF\n", 34 dev_err(dev, "of_i2c: modalias failure on %pOF\n", node);
38 node); 35 return -EINVAL;
39 return ERR_PTR(-EINVAL);
40 } 36 }
41 37
42 ret = of_property_read_u32(node, "reg", &addr); 38 ret = of_property_read_u32(node, "reg", &addr);
43 if (ret) { 39 if (ret) {
44 dev_err(&adap->dev, "of_i2c: invalid reg on %pOF\n", node); 40 dev_err(dev, "of_i2c: invalid reg on %pOF\n", node);
45 return ERR_PTR(ret); 41 return ret;
46 } 42 }
47 43
48 if (addr & I2C_TEN_BIT_ADDRESS) { 44 if (addr & I2C_TEN_BIT_ADDRESS) {
49 addr &= ~I2C_TEN_BIT_ADDRESS; 45 addr &= ~I2C_TEN_BIT_ADDRESS;
50 info.flags |= I2C_CLIENT_TEN; 46 info->flags |= I2C_CLIENT_TEN;
51 } 47 }
52 48
53 if (addr & I2C_OWN_SLAVE_ADDRESS) { 49 if (addr & I2C_OWN_SLAVE_ADDRESS) {
54 addr &= ~I2C_OWN_SLAVE_ADDRESS; 50 addr &= ~I2C_OWN_SLAVE_ADDRESS;
55 info.flags |= I2C_CLIENT_SLAVE; 51 info->flags |= I2C_CLIENT_SLAVE;
56 } 52 }
57 53
58 info.addr = addr; 54 info->addr = addr;
59 info.archdata = &dev_ad; 55 info->of_node = node;
60 info.of_node = of_node_get(node);
61 56
62 if (of_property_read_bool(node, "host-notify")) 57 if (of_property_read_bool(node, "host-notify"))
63 info.flags |= I2C_CLIENT_HOST_NOTIFY; 58 info->flags |= I2C_CLIENT_HOST_NOTIFY;
64 59
65 if (of_get_property(node, "wakeup-source", NULL)) 60 if (of_get_property(node, "wakeup-source", NULL))
66 info.flags |= I2C_CLIENT_WAKE; 61 info->flags |= I2C_CLIENT_WAKE;
62
63 return 0;
64}
65EXPORT_SYMBOL_GPL(of_i2c_get_board_info);
66
67static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
68 struct device_node *node)
69{
70 struct i2c_client *client;
71 struct i2c_board_info info;
72 int ret;
73
74 dev_dbg(&adap->dev, "of_i2c: register %pOF\n", node);
75
76 ret = of_i2c_get_board_info(&adap->dev, node, &info);
77 if (ret)
78 return ERR_PTR(ret);
67 79
68 client = i2c_new_device(adap, &info); 80 client = i2c_new_device(adap, &info);
69 if (!client) { 81 if (!client) {
70 dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", node); 82 dev_err(&adap->dev, "of_i2c: Failure registering %pOF\n", node);
71 of_node_put(node);
72 return ERR_PTR(-EINVAL); 83 return ERR_PTR(-EINVAL);
73 } 84 }
74 return client; 85 return client;