Rev 4104 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4104 | Rev 5271 | ||
---|---|---|---|
1 | /* i2c-core.c - a device driver for the iic-bus interface */ |
1 | /* i2c-core.c - a device driver for the iic-bus interface */ |
2 | /* ------------------------------------------------------------------------- */ |
2 | /* ------------------------------------------------------------------------- */ |
3 | /* Copyright (C) 1995-99 Simon G. Vogl |
3 | /* Copyright (C) 1995-99 Simon G. Vogl |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
18 | MA 02110-1301 USA. */ |
18 | MA 02110-1301 USA. */ |
19 | /* ------------------------------------------------------------------------- */ |
19 | /* ------------------------------------------------------------------------- */ |
20 | 20 | ||
21 | /* With some changes from Kyösti Mälkki |
21 | /* With some changes from Kyösti Mälkki |
22 | All SMBus-related things are written by Frodo Looijaard |
22 | All SMBus-related things are written by Frodo Looijaard |
23 | SMBus 2.0 support by Mark Studebaker |
23 | SMBus 2.0 support by Mark Studebaker |
24 | Jean Delvare |
24 | Jean Delvare |
25 | Mux support by Rodolfo Giometti |
25 | Mux support by Rodolfo Giometti |
26 | Michael Lawnick |
26 | Michael Lawnick |
27 | 27 | ||
28 | #include |
28 | #include |
29 | #include |
29 | #include |
- | 30 | #include |
|
30 | #include |
31 | #include |
31 | #include |
32 | #include |
32 | #include |
33 | #include |
33 | #include |
34 | #include |
34 | #include |
- | |
35 | #include |
35 | #include |
36 | - | ||
37 | - | ||
38 | - | ||
39 | - | ||
40 | - | ||
41 | - | ||
42 | - | ||
43 | - | ||
44 | - | ||
45 | - | ||
46 | - | ||
47 | - | ||
- | 36 | #include |
|
48 | - | ||
49 | - | ||
50 | - | ||
51 | - | ||
52 | - | ||
53 | - | ||
54 | - | ||
55 | - | ||
56 | - | ||
57 | - | ||
58 | - | ||
59 | - | ||
60 | - | ||
61 | - | ||
62 | - | ||
63 | - | ||
64 | - | ||
65 | - | ||
66 | - | ||
67 | 37 | ||
68 | 38 | ||
69 | 39 | ||
70 | #if 0 |
40 | #if 0 |
71 | 41 | ||
72 | static ssize_t |
42 | static ssize_t |
73 | show_modalias(struct device *dev, struct device_attribute *attr, char *buf) |
43 | show_modalias(struct device *dev, struct device_attribute *attr, char *buf) |
74 | { |
44 | { |
75 | struct i2c_client *client = to_i2c_client(dev); |
45 | struct i2c_client *client = to_i2c_client(dev); |
76 | return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); |
46 | return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); |
77 | } |
47 | } |
78 | 48 | ||
79 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
49 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
80 | static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); |
50 | static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); |
81 | 51 | ||
82 | static struct attribute *i2c_dev_attrs[] = { |
52 | static struct attribute *i2c_dev_attrs[] = { |
83 | &dev_attr_name.attr, |
53 | &dev_attr_name.attr, |
84 | /* modalias helps coldplug: modprobe $(cat .../modalias) */ |
54 | /* modalias helps coldplug: modprobe $(cat .../modalias) */ |
85 | &dev_attr_modalias.attr, |
55 | &dev_attr_modalias.attr, |
86 | NULL |
56 | NULL |
87 | }; |
57 | }; |
88 | 58 | ||
89 | static struct attribute_group i2c_dev_attr_group = { |
59 | static struct attribute_group i2c_dev_attr_group = { |
90 | .attrs = i2c_dev_attrs, |
60 | .attrs = i2c_dev_attrs, |
91 | }; |
61 | }; |
92 | 62 | ||
93 | static const struct attribute_group *i2c_dev_attr_groups[] = { |
63 | static const struct attribute_group *i2c_dev_attr_groups[] = { |
94 | &i2c_dev_attr_group, |
64 | &i2c_dev_attr_group, |
95 | NULL |
65 | NULL |
96 | }; |
66 | }; |
97 | 67 | ||
98 | static const struct dev_pm_ops i2c_device_pm_ops = { |
68 | static const struct dev_pm_ops i2c_device_pm_ops = { |
99 | .suspend = i2c_device_pm_suspend, |
69 | .suspend = i2c_device_pm_suspend, |
100 | .resume = i2c_device_pm_resume, |
70 | .resume = i2c_device_pm_resume, |
101 | .freeze = i2c_device_pm_freeze, |
71 | .freeze = i2c_device_pm_freeze, |
102 | .thaw = i2c_device_pm_thaw, |
72 | .thaw = i2c_device_pm_thaw, |
103 | .poweroff = i2c_device_pm_poweroff, |
73 | .poweroff = i2c_device_pm_poweroff, |
104 | .restore = i2c_device_pm_restore, |
74 | .restore = i2c_device_pm_restore, |
105 | SET_RUNTIME_PM_OPS( |
75 | SET_RUNTIME_PM_OPS( |
106 | pm_generic_runtime_suspend, |
76 | pm_generic_runtime_suspend, |
107 | pm_generic_runtime_resume, |
77 | pm_generic_runtime_resume, |
108 | NULL |
78 | NULL |
109 | ) |
79 | ) |
110 | }; |
80 | }; |
111 | 81 | ||
112 | struct bus_type i2c_bus_type = { |
82 | struct bus_type i2c_bus_type = { |
113 | .name = "i2c", |
83 | .name = "i2c", |
114 | .match = i2c_device_match, |
84 | .match = i2c_device_match, |
115 | .probe = i2c_device_probe, |
85 | .probe = i2c_device_probe, |
116 | .remove = i2c_device_remove, |
86 | .remove = i2c_device_remove, |
117 | .shutdown = i2c_device_shutdown, |
87 | .shutdown = i2c_device_shutdown, |
118 | .pm = &i2c_device_pm_ops, |
88 | .pm = &i2c_device_pm_ops, |
119 | }; |
89 | }; |
120 | EXPORT_SYMBOL_GPL(i2c_bus_type); |
90 | EXPORT_SYMBOL_GPL(i2c_bus_type); |
121 | 91 | ||
122 | static struct device_type i2c_client_type = { |
92 | static struct device_type i2c_client_type = { |
123 | .groups = i2c_dev_attr_groups, |
93 | .groups = i2c_dev_attr_groups, |
124 | .uevent = i2c_device_uevent, |
94 | .uevent = i2c_device_uevent, |
125 | .release = i2c_client_dev_release, |
95 | .release = i2c_client_dev_release, |
126 | }; |
96 | }; |
127 | 97 | ||
128 | 98 | ||
129 | /** |
99 | /** |
130 | * i2c_verify_client - return parameter as i2c_client, or NULL |
100 | * i2c_verify_client - return parameter as i2c_client, or NULL |
131 | * @dev: device, probably from some driver model iterator |
101 | * @dev: device, probably from some driver model iterator |
132 | * |
102 | * |
133 | * When traversing the driver model tree, perhaps using driver model |
103 | * When traversing the driver model tree, perhaps using driver model |
134 | * iterators like @device_for_each_child(), you can't assume very much |
104 | * iterators like @device_for_each_child(), you can't assume very much |
135 | * about the nodes you find. Use this function to avoid oopses caused |
105 | * about the nodes you find. Use this function to avoid oopses caused |
136 | * by wrongly treating some non-I2C device as an i2c_client. |
106 | * by wrongly treating some non-I2C device as an i2c_client. |
137 | */ |
107 | */ |
138 | struct i2c_client *i2c_verify_client(struct device *dev) |
108 | struct i2c_client *i2c_verify_client(struct device *dev) |
139 | { |
109 | { |
140 | return (dev->type == &i2c_client_type) |
110 | return (dev->type == &i2c_client_type) |
141 | ? to_i2c_client(dev) |
111 | ? to_i2c_client(dev) |
142 | : NULL; |
112 | : NULL; |
143 | } |
113 | } |
144 | EXPORT_SYMBOL(i2c_verify_client); |
114 | EXPORT_SYMBOL(i2c_verify_client); |
145 | 115 | ||
146 | 116 | ||
147 | /* This is a permissive address validity check, I2C address map constraints |
117 | /* This is a permissive address validity check, I2C address map constraints |
148 | * are purposely not enforced, except for the general call address. */ |
118 | * are purposely not enforced, except for the general call address. */ |
149 | static int i2c_check_client_addr_validity(const struct i2c_client *client) |
119 | static int i2c_check_client_addr_validity(const struct i2c_client *client) |
150 | { |
120 | { |
151 | if (client->flags & I2C_CLIENT_TEN) { |
121 | if (client->flags & I2C_CLIENT_TEN) { |
152 | /* 10-bit address, all values are valid */ |
122 | /* 10-bit address, all values are valid */ |
153 | if (client->addr > 0x3ff) |
123 | if (client->addr > 0x3ff) |
154 | return -EINVAL; |
124 | return -EINVAL; |
155 | } else { |
125 | } else { |
156 | /* 7-bit address, reject the general call address */ |
126 | /* 7-bit address, reject the general call address */ |
157 | if (client->addr == 0x00 || client->addr > 0x7f) |
127 | if (client->addr == 0x00 || client->addr > 0x7f) |
158 | return -EINVAL; |
128 | return -EINVAL; |
159 | } |
129 | } |
160 | return 0; |
130 | return 0; |
161 | } |
131 | } |
162 | 132 | ||
163 | /* And this is a strict address validity check, used when probing. If a |
133 | /* And this is a strict address validity check, used when probing. If a |
164 | * device uses a reserved address, then it shouldn't be probed. 7-bit |
134 | * device uses a reserved address, then it shouldn't be probed. 7-bit |
165 | * addressing is assumed, 10-bit address devices are rare and should be |
135 | * addressing is assumed, 10-bit address devices are rare and should be |
166 | * explicitly enumerated. */ |
136 | * explicitly enumerated. */ |
167 | static int i2c_check_addr_validity(unsigned short addr) |
137 | static int i2c_check_addr_validity(unsigned short addr) |
168 | { |
138 | { |
169 | /* |
139 | /* |
170 | * Reserved addresses per I2C specification: |
140 | * Reserved addresses per I2C specification: |
171 | * 0x00 General call address / START byte |
141 | * 0x00 General call address / START byte |
172 | * 0x01 CBUS address |
142 | * 0x01 CBUS address |
173 | * 0x02 Reserved for different bus format |
143 | * 0x02 Reserved for different bus format |
174 | * 0x03 Reserved for future purposes |
144 | * 0x03 Reserved for future purposes |
175 | * 0x04-0x07 Hs-mode master code |
145 | * 0x04-0x07 Hs-mode master code |
176 | * 0x78-0x7b 10-bit slave addressing |
146 | * 0x78-0x7b 10-bit slave addressing |
177 | * 0x7c-0x7f Reserved for future purposes |
147 | * 0x7c-0x7f Reserved for future purposes |
178 | */ |
148 | */ |
179 | if (addr < 0x08 || addr > 0x77) |
149 | if (addr < 0x08 || addr > 0x77) |
180 | return -EINVAL; |
150 | return -EINVAL; |
181 | return 0; |
151 | return 0; |
182 | } |
152 | } |
183 | 153 | ||
184 | static int __i2c_check_addr_busy(struct device *dev, void *addrp) |
154 | static int __i2c_check_addr_busy(struct device *dev, void *addrp) |
185 | { |
155 | { |
186 | struct i2c_client *client = i2c_verify_client(dev); |
156 | struct i2c_client *client = i2c_verify_client(dev); |
187 | int addr = *(int *)addrp; |
157 | int addr = *(int *)addrp; |
188 | 158 | ||
189 | if (client && client->addr == addr) |
159 | if (client && client->addr == addr) |
190 | return -EBUSY; |
160 | return -EBUSY; |
191 | return 0; |
161 | return 0; |
192 | } |
162 | } |
193 | 163 | ||
194 | /* walk up mux tree */ |
164 | /* walk up mux tree */ |
195 | static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) |
165 | static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) |
196 | { |
166 | { |
197 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
167 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
198 | int result; |
168 | int result; |
199 | 169 | ||
200 | result = device_for_each_child(&adapter->dev, &addr, |
170 | result = device_for_each_child(&adapter->dev, &addr, |
201 | __i2c_check_addr_busy); |
171 | __i2c_check_addr_busy); |
202 | 172 | ||
203 | if (!result && parent) |
173 | if (!result && parent) |
204 | result = i2c_check_mux_parents(parent, addr); |
174 | result = i2c_check_mux_parents(parent, addr); |
205 | 175 | ||
206 | return result; |
176 | return result; |
207 | } |
177 | } |
208 | 178 | ||
209 | /* recurse down mux tree */ |
179 | /* recurse down mux tree */ |
210 | static int i2c_check_mux_children(struct device *dev, void *addrp) |
180 | static int i2c_check_mux_children(struct device *dev, void *addrp) |
211 | { |
181 | { |
212 | int result; |
182 | int result; |
213 | 183 | ||
214 | if (dev->type == &i2c_adapter_type) |
184 | if (dev->type == &i2c_adapter_type) |
215 | result = device_for_each_child(dev, addrp, |
185 | result = device_for_each_child(dev, addrp, |
216 | i2c_check_mux_children); |
186 | i2c_check_mux_children); |
217 | else |
187 | else |
218 | result = __i2c_check_addr_busy(dev, addrp); |
188 | result = __i2c_check_addr_busy(dev, addrp); |
219 | 189 | ||
220 | return result; |
190 | return result; |
221 | } |
191 | } |
222 | 192 | ||
223 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) |
193 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) |
224 | { |
194 | { |
225 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
195 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
226 | int result = 0; |
196 | int result = 0; |
227 | 197 | ||
228 | if (parent) |
198 | if (parent) |
229 | result = i2c_check_mux_parents(parent, addr); |
199 | result = i2c_check_mux_parents(parent, addr); |
230 | 200 | ||
231 | if (!result) |
201 | if (!result) |
232 | result = device_for_each_child(&adapter->dev, &addr, |
202 | result = device_for_each_child(&adapter->dev, &addr, |
233 | i2c_check_mux_children); |
203 | i2c_check_mux_children); |
234 | 204 | ||
235 | return result; |
205 | return result; |
236 | } |
206 | } |
237 | 207 | ||
238 | /** |
208 | /** |
239 | * i2c_lock_adapter - Get exclusive access to an I2C bus segment |
209 | * i2c_lock_adapter - Get exclusive access to an I2C bus segment |
240 | * @adapter: Target I2C bus segment |
210 | * @adapter: Target I2C bus segment |
241 | */ |
211 | */ |
242 | void i2c_lock_adapter(struct i2c_adapter *adapter) |
212 | void i2c_lock_adapter(struct i2c_adapter *adapter) |
243 | { |
213 | { |
244 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
214 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
245 | 215 | ||
246 | if (parent) |
216 | if (parent) |
247 | i2c_lock_adapter(parent); |
217 | i2c_lock_adapter(parent); |
248 | else |
218 | else |
249 | rt_mutex_lock(&adapter->bus_lock); |
219 | rt_mutex_lock(&adapter->bus_lock); |
250 | } |
220 | } |
251 | EXPORT_SYMBOL_GPL(i2c_lock_adapter); |
221 | EXPORT_SYMBOL_GPL(i2c_lock_adapter); |
252 | 222 | ||
253 | /** |
223 | /** |
254 | * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment |
224 | * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment |
255 | * @adapter: Target I2C bus segment |
225 | * @adapter: Target I2C bus segment |
256 | */ |
226 | */ |
257 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) |
227 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) |
258 | { |
228 | { |
259 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
229 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
260 | 230 | ||
261 | if (parent) |
231 | if (parent) |
262 | return i2c_trylock_adapter(parent); |
232 | return i2c_trylock_adapter(parent); |
263 | else |
233 | else |
264 | return rt_mutex_trylock(&adapter->bus_lock); |
234 | return rt_mutex_trylock(&adapter->bus_lock); |
265 | } |
235 | } |
266 | 236 | ||
267 | /** |
237 | /** |
268 | * i2c_unlock_adapter - Release exclusive access to an I2C bus segment |
238 | * i2c_unlock_adapter - Release exclusive access to an I2C bus segment |
269 | * @adapter: Target I2C bus segment |
239 | * @adapter: Target I2C bus segment |
270 | */ |
240 | */ |
271 | void i2c_unlock_adapter(struct i2c_adapter *adapter) |
241 | void i2c_unlock_adapter(struct i2c_adapter *adapter) |
272 | { |
242 | { |
273 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
243 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
274 | 244 | ||
275 | if (parent) |
245 | if (parent) |
276 | i2c_unlock_adapter(parent); |
246 | i2c_unlock_adapter(parent); |
277 | else |
247 | else |
278 | rt_mutex_unlock(&adapter->bus_lock); |
248 | rt_mutex_unlock(&adapter->bus_lock); |
279 | } |
249 | } |
280 | EXPORT_SYMBOL_GPL(i2c_unlock_adapter); |
250 | EXPORT_SYMBOL_GPL(i2c_unlock_adapter); |
281 | 251 | ||
282 | #endif |
252 | #endif |
283 | 253 | ||
284 | 254 | ||
285 | /** |
255 | /** |
286 | * i2c_transfer - execute a single or combined I2C message |
256 | * i2c_transfer - execute a single or combined I2C message |
287 | * @adap: Handle to I2C bus |
257 | * @adap: Handle to I2C bus |
288 | * @msgs: One or more messages to execute before STOP is issued to |
258 | * @msgs: One or more messages to execute before STOP is issued to |
289 | * terminate the operation; each message begins with a START. |
259 | * terminate the operation; each message begins with a START. |
290 | * @num: Number of messages to be executed. |
260 | * @num: Number of messages to be executed. |
291 | * |
261 | * |
292 | * Returns negative errno, else the number of messages executed. |
262 | * Returns negative errno, else the number of messages executed. |
293 | * |
263 | * |
294 | * Note that there is no requirement that each message be sent to |
264 | * Note that there is no requirement that each message be sent to |
295 | * the same slave address, although that is the most common model. |
265 | * the same slave address, although that is the most common model. |
296 | */ |
266 | */ |
297 | int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) |
267 | int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) |
298 | { |
268 | { |
299 | unsigned long orig_jiffies; |
269 | unsigned long orig_jiffies; |
300 | int ret, try; |
270 | int ret, try; |
301 | 271 | ||
302 | /* REVISIT the fault reporting model here is weak: |
272 | /* REVISIT the fault reporting model here is weak: |
303 | * |
273 | * |
304 | * - When we get an error after receiving N bytes from a slave, |
274 | * - When we get an error after receiving N bytes from a slave, |
305 | * there is no way to report "N". |
275 | * there is no way to report "N". |
306 | * |
276 | * |
307 | * - When we get a NAK after transmitting N bytes to a slave, |
277 | * - When we get a NAK after transmitting N bytes to a slave, |
308 | * there is no way to report "N" ... or to let the master |
278 | * there is no way to report "N" ... or to let the master |
309 | * continue executing the rest of this combined message, if |
279 | * continue executing the rest of this combined message, if |
310 | * that's the appropriate response. |
280 | * that's the appropriate response. |
311 | * |
281 | * |
312 | * - When for example "num" is two and we successfully complete |
282 | * - When for example "num" is two and we successfully complete |
313 | * the first message but get an error part way through the |
283 | * the first message but get an error part way through the |
314 | * second, it's unclear whether that should be reported as |
284 | * second, it's unclear whether that should be reported as |
315 | * one (discarding status on the second message) or errno |
285 | * one (discarding status on the second message) or errno |
316 | * (discarding status on the first one). |
286 | * (discarding status on the first one). |
317 | */ |
287 | */ |
318 | 288 | ||
319 | if (adap->algo->master_xfer) { |
289 | if (adap->algo->master_xfer) { |
320 | 290 | ||
321 | /* Retry automatically on arbitration loss */ |
291 | /* Retry automatically on arbitration loss */ |
322 | orig_jiffies = GetTimerTicks(); |
292 | orig_jiffies = GetTimerTicks(); |
323 | 293 | ||
324 | for (ret = 0, try = 0; try <= adap->retries; try++) { |
294 | for (ret = 0, try = 0; try <= adap->retries; try++) { |
325 | 295 | ||
326 | ret = adap->algo->master_xfer(adap, msgs, num); |
296 | ret = adap->algo->master_xfer(adap, msgs, num); |
327 | if (ret != -EAGAIN) |
297 | if (ret != -EAGAIN) |
328 | break; |
298 | break; |
329 | 299 | ||
330 | if (time_after(GetTimerTicks(), orig_jiffies + adap->timeout)) |
300 | if (time_after((unsigned long)GetTimerTicks(), orig_jiffies + adap->timeout)) |
331 | break; |
301 | break; |
332 | 302 | ||
333 | delay(1); |
303 | delay(1); |
334 | } |
304 | } |
335 | // mutex_unlock(&adap->bus_lock); |
305 | // mutex_unlock(&adap->bus_lock); |
336 | return ret; |
306 | return ret; |
337 | } else { |
307 | } else { |
338 | dbgprintf("I2C level transfers not supported\n"); |
308 | dbgprintf("I2C level transfers not supported\n"); |
339 | return -EOPNOTSUPP; |
309 | return -EOPNOTSUPP; |
340 | } |
310 | } |
341 | } |
311 | } |
342 | EXPORT_SYMBOL(i2c_transfer); |
312 | EXPORT_SYMBOL(i2c_transfer); |
343 | 313 | ||
344 | 314 | ||
345 | /** |
315 | /** |
346 | * i2c_new_device - instantiate an i2c device |
316 | * i2c_new_device - instantiate an i2c device |
347 | * @adap: the adapter managing the device |
317 | * @adap: the adapter managing the device |
348 | * @info: describes one I2C device; bus_num is ignored |
318 | * @info: describes one I2C device; bus_num is ignored |
349 | * Context: can sleep |
319 | * Context: can sleep |
350 | * |
320 | * |
351 | * Create an i2c device. Binding is handled through driver model |
321 | * Create an i2c device. Binding is handled through driver model |
352 | * probe()/remove() methods. A driver may be bound to this device when we |
322 | * probe()/remove() methods. A driver may be bound to this device when we |
353 | * return from this function, or any later moment (e.g. maybe hotplugging will |
323 | * return from this function, or any later moment (e.g. maybe hotplugging will |
354 | * load the driver module). This call is not appropriate for use by mainboard |
324 | * load the driver module). This call is not appropriate for use by mainboard |
355 | * initialization logic, which usually runs during an arch_initcall() long |
325 | * initialization logic, which usually runs during an arch_initcall() long |
356 | * before any i2c_adapter could exist. |
326 | * before any i2c_adapter could exist. |
357 | * |
327 | * |
358 | * This returns the new i2c client, which may be saved for later use with |
328 | * This returns the new i2c client, which may be saved for later use with |
359 | * i2c_unregister_device(); or NULL to indicate an error. |
329 | * i2c_unregister_device(); or NULL to indicate an error. |
360 | */ |
330 | */ |
361 | struct i2c_client * |
331 | struct i2c_client * |
362 | i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) |
332 | i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) |
363 | { |
333 | { |
364 | struct i2c_client *client; |
334 | struct i2c_client *client; |
365 | int status; |
335 | int status; |
366 | 336 | ||
367 | client = kzalloc(sizeof *client, GFP_KERNEL); |
337 | client = kzalloc(sizeof *client, GFP_KERNEL); |
368 | if (!client) |
338 | if (!client) |
369 | return NULL; |
339 | return NULL; |
370 | 340 | ||
371 | client->adapter = adap; |
341 | client->adapter = adap; |
372 | 342 | ||
373 | client->flags = info->flags; |
343 | client->flags = info->flags; |
374 | client->addr = info->addr; |
344 | client->addr = info->addr; |
375 | client->irq = info->irq; |
345 | client->irq = info->irq; |
376 | 346 | ||
377 | strlcpy(client->name, info->type, sizeof(client->name)); |
347 | strlcpy(client->name, info->type, sizeof(client->name)); |
378 | 348 | ||
379 | return client; |
349 | return client; |
380 | }=>> |
350 | }=>> |