blob: 4ce5f0f32fba08c71365596ed4be95a0b9ab69b0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* i2c-core.c - a device driver for the iic-bus interface */
2/* ------------------------------------------------------------------------- */
3/* Copyright (C) 1995-99 Simon G. Vogl
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
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
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18/* ------------------------------------------------------------------------- */
19
20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
Jean Delvare421ef472005-10-26 21:28:55 +020022 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
23 Jean Delvare <khali@linux-fr.org> */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/errno.h>
28#include <linux/slab.h>
29#include <linux/i2c.h>
30#include <linux/init.h>
31#include <linux/idr.h>
32#include <linux/seq_file.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010033#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/uaccess.h>
35
36
37static LIST_HEAD(adapters);
38static LIST_HEAD(drivers);
39static DECLARE_MUTEX(core_lists);
40static DEFINE_IDR(i2c_adapter_idr);
41
42/* match always succeeds, as we want the probe() to tell if we really accept this match */
43static int i2c_device_match(struct device *dev, struct device_driver *drv)
44{
45 return 1;
46}
47
48static int i2c_bus_suspend(struct device * dev, pm_message_t state)
49{
50 int rc = 0;
51
52 if (dev->driver && dev->driver->suspend)
Russell King9480e302005-10-28 09:52:56 -070053 rc = dev->driver->suspend(dev, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return rc;
55}
56
57static int i2c_bus_resume(struct device * dev)
58{
59 int rc = 0;
60
61 if (dev->driver && dev->driver->resume)
Russell King9480e302005-10-28 09:52:56 -070062 rc = dev->driver->resume(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return rc;
64}
65
Jean Delvareefde7232005-07-20 23:03:50 +020066struct bus_type i2c_bus_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .name = "i2c",
68 .match = i2c_device_match,
69 .suspend = i2c_bus_suspend,
70 .resume = i2c_bus_resume,
71};
72
73static int i2c_device_probe(struct device *dev)
74{
75 return -ENODEV;
76}
77
78static int i2c_device_remove(struct device *dev)
79{
80 return 0;
81}
82
Jean Delvareefde7232005-07-20 23:03:50 +020083void i2c_adapter_dev_release(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
86 complete(&adap->dev_released);
87}
88
Jean Delvareefde7232005-07-20 23:03:50 +020089struct device_driver i2c_adapter_driver = {
Laurent Riffard6586bcd2005-10-17 22:54:45 +020090 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .name = "i2c_adapter",
92 .bus = &i2c_bus_type,
93 .probe = i2c_device_probe,
94 .remove = i2c_device_remove,
95};
96
97static void i2c_adapter_class_dev_release(struct class_device *dev)
98{
99 struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev);
100 complete(&adap->class_dev_released);
101}
102
Jean Delvareefde7232005-07-20 23:03:50 +0200103struct class i2c_adapter_class = {
Laurent Riffard6586bcd2005-10-17 22:54:45 +0200104 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .name = "i2c-adapter",
106 .release = &i2c_adapter_class_dev_release,
107};
108
Yani Ioannoue404e272005-05-17 06:42:58 -0400109static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
112 return sprintf(buf, "%s\n", adap->name);
113}
114static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
115
116
117static void i2c_client_release(struct device *dev)
118{
119 struct i2c_client *client = to_i2c_client(dev);
120 complete(&client->released);
121}
122
Yani Ioannoue404e272005-05-17 06:42:58 -0400123static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 struct i2c_client *client = to_i2c_client(dev);
126 return sprintf(buf, "%s\n", client->name);
127}
128
129/*
130 * We can't use the DEVICE_ATTR() macro here as we want the same filename for a
131 * different type of a device. So beware if the DEVICE_ATTR() macro ever
132 * changes, this definition will also have to change.
133 */
134static struct device_attribute dev_attr_client_name = {
135 .attr = {.name = "name", .mode = S_IRUGO, .owner = THIS_MODULE },
136 .show = &show_client_name,
137};
138
139
140/* ---------------------------------------------------
141 * registering functions
142 * ---------------------------------------------------
143 */
144
145/* -----
146 * i2c_add_adapter is called from within the algorithm layer,
147 * when a new hw adapter registers. A new device is register to be
148 * available for clients.
149 */
150int i2c_add_adapter(struct i2c_adapter *adap)
151{
152 int id, res = 0;
153 struct list_head *item;
154 struct i2c_driver *driver;
155
156 down(&core_lists);
157
158 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
159 res = -ENOMEM;
160 goto out_unlock;
161 }
162
Mark M. Hoffmana0920e12005-06-28 00:21:30 -0400163 res = idr_get_new(&i2c_adapter_idr, adap, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 if (res < 0) {
165 if (res == -EAGAIN)
166 res = -ENOMEM;
167 goto out_unlock;
168 }
169
170 adap->nr = id & MAX_ID_MASK;
171 init_MUTEX(&adap->bus_lock);
172 init_MUTEX(&adap->clist_lock);
173 list_add_tail(&adap->list,&adapters);
174 INIT_LIST_HEAD(&adap->clients);
175
176 /* Add the adapter to the driver core.
177 * If the parent pointer is not set up,
178 * we add this adapter to the host bus.
179 */
180 if (adap->dev.parent == NULL)
181 adap->dev.parent = &platform_bus;
182 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
183 adap->dev.driver = &i2c_adapter_driver;
184 adap->dev.release = &i2c_adapter_dev_release;
185 device_register(&adap->dev);
186 device_create_file(&adap->dev, &dev_attr_name);
187
188 /* Add this adapter to the i2c_adapter class */
189 memset(&adap->class_dev, 0x00, sizeof(struct class_device));
190 adap->class_dev.dev = &adap->dev;
191 adap->class_dev.class = &i2c_adapter_class;
192 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
193 class_device_register(&adap->class_dev);
194
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200195 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* inform drivers of new adapters */
198 list_for_each(item,&drivers) {
199 driver = list_entry(item, struct i2c_driver, list);
Jean Delvare8a994752005-11-26 20:28:06 +0100200 if (driver->attach_adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* We ignore the return code; if it fails, too bad */
202 driver->attach_adapter(adap);
203 }
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205out_unlock:
206 up(&core_lists);
207 return res;
208}
209
210
211int i2c_del_adapter(struct i2c_adapter *adap)
212{
213 struct list_head *item, *_n;
214 struct i2c_adapter *adap_from_list;
215 struct i2c_driver *driver;
216 struct i2c_client *client;
217 int res = 0;
218
219 down(&core_lists);
220
221 /* First make sure that this adapter was ever added */
222 list_for_each_entry(adap_from_list, &adapters, list) {
223 if (adap_from_list == adap)
224 break;
225 }
226 if (adap_from_list != adap) {
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200227 pr_debug("i2c-core: attempting to delete unregistered "
228 "adapter [%s]\n", adap->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 res = -EINVAL;
230 goto out_unlock;
231 }
232
233 list_for_each(item,&drivers) {
234 driver = list_entry(item, struct i2c_driver, list);
235 if (driver->detach_adapter)
236 if ((res = driver->detach_adapter(adap))) {
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200237 dev_err(&adap->dev, "detach_adapter failed "
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100238 "for driver [%s]\n",
239 driver->driver.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 goto out_unlock;
241 }
242 }
243
244 /* detach any active clients. This must be done first, because
Tobias Klausera551acc2005-05-19 21:40:38 +0200245 * it can fail; in which case we give up. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 list_for_each_safe(item, _n, &adap->clients) {
247 client = list_entry(item, struct i2c_client, list);
248
249 /* detaching devices is unconditional of the set notify
250 * flag, as _all_ clients that reside on the adapter
251 * must be deleted, as this would cause invalid states.
252 */
253 if ((res=client->driver->detach_client(client))) {
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200254 dev_err(&adap->dev, "detach_client failed for client "
255 "[%s] at address 0x%02x\n", client->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 client->addr);
257 goto out_unlock;
258 }
259 }
260
261 /* clean up the sysfs representation */
262 init_completion(&adap->dev_released);
263 init_completion(&adap->class_dev_released);
264 class_device_unregister(&adap->class_dev);
265 device_remove_file(&adap->dev, &dev_attr_name);
266 device_unregister(&adap->dev);
267 list_del(&adap->list);
268
269 /* wait for sysfs to drop all references */
270 wait_for_completion(&adap->dev_released);
271 wait_for_completion(&adap->class_dev_released);
272
273 /* free dynamically allocated bus id */
274 idr_remove(&i2c_adapter_idr, adap->nr);
275
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200276 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 out_unlock:
279 up(&core_lists);
280 return res;
281}
282
283
284/* -----
285 * What follows is the "upwards" interface: commands for talking to clients,
286 * which implement the functions to access the physical information of the
287 * chips.
288 */
289
290int i2c_add_driver(struct i2c_driver *driver)
291{
292 struct list_head *item;
293 struct i2c_adapter *adapter;
294 int res = 0;
295
296 down(&core_lists);
297
298 /* add the driver to the list of i2c drivers in the driver core */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 driver->driver.bus = &i2c_bus_type;
300 driver->driver.probe = i2c_device_probe;
301 driver->driver.remove = i2c_device_remove;
302
303 res = driver_register(&driver->driver);
304 if (res)
305 goto out_unlock;
306
307 list_add_tail(&driver->list,&drivers);
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100308 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 /* now look for instances of driver on our adapters */
Jean Delvare8a994752005-11-26 20:28:06 +0100311 if (driver->attach_adapter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 list_for_each(item,&adapters) {
313 adapter = list_entry(item, struct i2c_adapter, list);
314 driver->attach_adapter(adapter);
315 }
316 }
317
318 out_unlock:
319 up(&core_lists);
320 return res;
321}
322
323int i2c_del_driver(struct i2c_driver *driver)
324{
325 struct list_head *item1, *item2, *_n;
326 struct i2c_client *client;
327 struct i2c_adapter *adap;
328
329 int res = 0;
330
331 down(&core_lists);
332
333 /* Have a look at each adapter, if clients of this driver are still
334 * attached. If so, detach them to be able to kill the driver
335 * afterwards.
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200336 *
337 * Removing clients does not depend on the notify flag, else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 * invalid operation might (will!) result, when using stale client
339 * pointers.
340 */
341 list_for_each(item1,&adapters) {
342 adap = list_entry(item1, struct i2c_adapter, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (driver->detach_adapter) {
344 if ((res = driver->detach_adapter(adap))) {
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200345 dev_err(&adap->dev, "detach_adapter failed "
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100346 "for driver [%s]\n",
347 driver->driver.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 goto out_unlock;
349 }
350 } else {
351 list_for_each_safe(item2, _n, &adap->clients) {
352 client = list_entry(item2, struct i2c_client, list);
353 if (client->driver != driver)
354 continue;
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200355 dev_dbg(&adap->dev, "detaching client [%s] "
356 "at 0x%02x\n", client->name,
357 client->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if ((res = driver->detach_client(client))) {
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200359 dev_err(&adap->dev, "detach_client "
360 "failed for client [%s] at "
361 "0x%02x\n", client->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 client->addr);
363 goto out_unlock;
364 }
365 }
366 }
367 }
368
369 driver_unregister(&driver->driver);
370 list_del(&driver->list);
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100371 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 out_unlock:
374 up(&core_lists);
375 return 0;
376}
377
378static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr)
379{
380 struct list_head *item;
381 struct i2c_client *client;
382
383 list_for_each(item,&adapter->clients) {
384 client = list_entry(item, struct i2c_client, list);
385 if (client->addr == addr)
386 return -EBUSY;
387 }
388 return 0;
389}
390
391int i2c_check_addr(struct i2c_adapter *adapter, int addr)
392{
393 int rval;
394
395 down(&adapter->clist_lock);
396 rval = __i2c_check_addr(adapter, addr);
397 up(&adapter->clist_lock);
398
399 return rval;
400}
401
402int i2c_attach_client(struct i2c_client *client)
403{
404 struct i2c_adapter *adapter = client->adapter;
405
406 down(&adapter->clist_lock);
407 if (__i2c_check_addr(client->adapter, client->addr)) {
408 up(&adapter->clist_lock);
409 return -EBUSY;
410 }
411 list_add_tail(&client->list,&adapter->clients);
412 up(&adapter->clist_lock);
413
414 if (adapter->client_register) {
415 if (adapter->client_register(client)) {
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200416 dev_dbg(&adapter->dev, "client_register "
417 "failed for client [%s] at 0x%02x\n",
418 client->name, client->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420 }
421
Jean Delvarecde78592005-11-26 21:00:54 +0100422 client->usage_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 client->dev.parent = &client->adapter->dev;
425 client->dev.driver = &client->driver->driver;
426 client->dev.bus = &i2c_bus_type;
427 client->dev.release = &i2c_client_release;
428
429 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
430 "%d-%04x", i2c_adapter_id(adapter), client->addr);
Jean Delvareb6d7b3d2005-07-31 19:02:53 +0200431 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
432 client->name, client->dev.bus_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 device_register(&client->dev);
434 device_create_file(&client->dev, &dev_attr_client_name);
435
436 return 0;
437}
438
439
440int i2c_detach_client(struct i2c_client *client)
441{
442 struct i2c_adapter *adapter = client->adapter;
443 int res = 0;
444
Jean Delvarecde78592005-11-26 21:00:54 +0100445 if (client->usage_count > 0) {
Jean Delvare7bef5592005-07-27 22:14:49 +0200446 dev_warn(&client->dev, "Client [%s] still busy, "
447 "can't detach\n", client->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return -EBUSY;
Jean Delvare7bef5592005-07-27 22:14:49 +0200449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 if (adapter->client_unregister) {
452 res = adapter->client_unregister(client);
453 if (res) {
454 dev_err(&client->dev,
Jean Delvare86749e82005-07-29 12:15:29 -0700455 "client_unregister [%s] failed, "
456 "client not detached\n", client->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 goto out;
458 }
459 }
460
461 down(&adapter->clist_lock);
462 list_del(&client->list);
463 init_completion(&client->released);
464 device_remove_file(&client->dev, &dev_attr_client_name);
465 device_unregister(&client->dev);
466 up(&adapter->clist_lock);
467 wait_for_completion(&client->released);
468
469 out:
470 return res;
471}
472
473static int i2c_inc_use_client(struct i2c_client *client)
474{
475
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100476 if (!try_module_get(client->driver->driver.owner))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return -ENODEV;
478 if (!try_module_get(client->adapter->owner)) {
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100479 module_put(client->driver->driver.owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return -ENODEV;
481 }
482
483 return 0;
484}
485
486static void i2c_dec_use_client(struct i2c_client *client)
487{
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100488 module_put(client->driver->driver.owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 module_put(client->adapter->owner);
490}
491
492int i2c_use_client(struct i2c_client *client)
493{
494 int ret;
495
496 ret = i2c_inc_use_client(client);
497 if (ret)
498 return ret;
499
Jean Delvarecde78592005-11-26 21:00:54 +0100500 client->usage_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505int i2c_release_client(struct i2c_client *client)
506{
Jean Delvarecde78592005-11-26 21:00:54 +0100507 if (!client->usage_count) {
508 pr_debug("i2c-core: %s used one too many times\n",
509 __FUNCTION__);
510 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
Jean Delvarecde78592005-11-26 21:00:54 +0100513 client->usage_count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 i2c_dec_use_client(client);
515
516 return 0;
517}
518
519void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
520{
521 struct list_head *item;
522 struct i2c_client *client;
523
524 down(&adap->clist_lock);
525 list_for_each(item,&adap->clients) {
526 client = list_entry(item, struct i2c_client, list);
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100527 if (!try_module_get(client->driver->driver.owner))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 continue;
529 if (NULL != client->driver->command) {
530 up(&adap->clist_lock);
531 client->driver->command(client,cmd,arg);
532 down(&adap->clist_lock);
533 }
Laurent Riffard35d8b2e2005-11-26 20:34:05 +0100534 module_put(client->driver->driver.owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
536 up(&adap->clist_lock);
537}
538
539static int __init i2c_init(void)
540{
541 int retval;
542
543 retval = bus_register(&i2c_bus_type);
544 if (retval)
545 return retval;
546 retval = driver_register(&i2c_adapter_driver);
547 if (retval)
548 return retval;
549 return class_register(&i2c_adapter_class);
550}
551
552static void __exit i2c_exit(void)
553{
554 class_unregister(&i2c_adapter_class);
555 driver_unregister(&i2c_adapter_driver);
556 bus_unregister(&i2c_bus_type);
557}
558
559subsys_initcall(i2c_init);
560module_exit(i2c_exit);
561
562/* ----------------------------------------------------
563 * the functional interface to the i2c busses.
564 * ----------------------------------------------------
565 */
566
567int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
568{
569 int ret;
570
571 if (adap->algo->master_xfer) {
572#ifdef DEBUG
573 for (ret = 0; ret < num; ret++) {
574 dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, "
575 "len=%d\n", ret, msgs[ret].flags & I2C_M_RD ?
576 'R' : 'W', msgs[ret].addr, msgs[ret].len);
577 }
578#endif
579
580 down(&adap->bus_lock);
581 ret = adap->algo->master_xfer(adap,msgs,num);
582 up(&adap->bus_lock);
583
584 return ret;
585 } else {
586 dev_dbg(&adap->dev, "I2C level transfers not supported\n");
587 return -ENOSYS;
588 }
589}
590
591int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
592{
593 int ret;
594 struct i2c_adapter *adap=client->adapter;
595 struct i2c_msg msg;
596
Jean Delvare815f55f2005-05-07 22:58:46 +0200597 msg.addr = client->addr;
598 msg.flags = client->flags & I2C_M_TEN;
599 msg.len = count;
600 msg.buf = (char *)buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Jean Delvare815f55f2005-05-07 22:58:46 +0200602 ret = i2c_transfer(adap, &msg, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Jean Delvare815f55f2005-05-07 22:58:46 +0200604 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
605 transmitted, else error code. */
606 return (ret == 1) ? count : ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
609int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
610{
611 struct i2c_adapter *adap=client->adapter;
612 struct i2c_msg msg;
613 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Jean Delvare815f55f2005-05-07 22:58:46 +0200615 msg.addr = client->addr;
616 msg.flags = client->flags & I2C_M_TEN;
617 msg.flags |= I2C_M_RD;
618 msg.len = count;
619 msg.buf = buf;
620
621 ret = i2c_transfer(adap, &msg, 1);
622
623 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
624 transmitted, else error code. */
625 return (ret == 1) ? count : ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
628
629int i2c_control(struct i2c_client *client,
630 unsigned int cmd, unsigned long arg)
631{
632 int ret = 0;
633 struct i2c_adapter *adap = client->adapter;
634
635 dev_dbg(&client->adapter->dev, "i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg);
636 switch (cmd) {
637 case I2C_RETRIES:
638 adap->retries = arg;
639 break;
640 case I2C_TIMEOUT:
641 adap->timeout = arg;
642 break;
643 default:
644 if (adap->algo->algo_control!=NULL)
645 ret = adap->algo->algo_control(adap,cmd,arg);
646 }
647 return ret;
648}
649
650/* ----------------------------------------------------
651 * the i2c address scanning function
652 * Will not work for 10-bit addresses!
653 * ----------------------------------------------------
654 */
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200655static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
656 int (*found_proc) (struct i2c_adapter *, int, int))
Jean Delvare9fc6adf2005-07-31 21:20:43 +0200657{
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200658 int err;
Jean Delvare9fc6adf2005-07-31 21:20:43 +0200659
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200660 /* Make sure the address is valid */
661 if (addr < 0x03 || addr > 0x77) {
662 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
663 addr);
664 return -EINVAL;
Jean Delvare9fc6adf2005-07-31 21:20:43 +0200665 }
666
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200667 /* Skip if already in use */
668 if (i2c_check_addr(adapter, addr))
669 return 0;
670
671 /* Make sure there is something at this address, unless forced */
Jean Delvare4c9337d2005-08-09 20:28:10 +0200672 if (kind < 0) {
673 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0,
674 I2C_SMBUS_QUICK, NULL) < 0)
675 return 0;
676
677 /* prevent 24RF08 corruption */
678 if ((addr & ~0x0f) == 0x50)
679 i2c_smbus_xfer(adapter, addr, 0, 0, 0,
680 I2C_SMBUS_QUICK, NULL);
681 }
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200682
683 /* Finally call the custom detection function */
684 err = found_proc(adapter, addr, kind);
685
686 /* -ENODEV can be returned if there is a chip at the given address
687 but it isn't supported by this chip driver. We catch it here as
688 this isn't an error. */
689 return (err == -ENODEV) ? 0 : err;
Jean Delvare9fc6adf2005-07-31 21:20:43 +0200690}
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692int i2c_probe(struct i2c_adapter *adapter,
693 struct i2c_client_address_data *address_data,
694 int (*found_proc) (struct i2c_adapter *, int, int))
695{
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200696 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 int adap_id = i2c_adapter_id(adapter);
698
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200699 /* Force entries are done first, and are not affected by ignore
700 entries */
701 if (address_data->forces) {
702 unsigned short **forces = address_data->forces;
703 int kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200705 for (kind = 0; forces[kind]; kind++) {
706 for (i = 0; forces[kind][i] != I2C_CLIENT_END;
707 i += 2) {
708 if (forces[kind][i] == adap_id
709 || forces[kind][i] == ANY_I2C_BUS) {
710 dev_dbg(&adapter->dev, "found force "
711 "parameter for adapter %d, "
712 "addr 0x%02x, kind %d\n",
713 adap_id, forces[kind][i + 1],
714 kind);
715 err = i2c_probe_address(adapter,
716 forces[kind][i + 1],
717 kind, found_proc);
718 if (err)
719 return err;
720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200724
Jean Delvare4366dc92005-09-25 16:50:06 +0200725 /* Stop here if we can't use SMBUS_QUICK */
726 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
727 if (address_data->probe[0] == I2C_CLIENT_END
728 && address_data->normal_i2c[0] == I2C_CLIENT_END)
729 return 0;
730
731 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
732 "can't probe for chips\n");
733 return -1;
734 }
735
Jean Delvarea89ba0b2005-08-09 20:17:55 +0200736 /* Probe entries are done second, and are not affected by ignore
737 entries either */
738 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
739 if (address_data->probe[i] == adap_id
740 || address_data->probe[i] == ANY_I2C_BUS) {
741 dev_dbg(&adapter->dev, "found probe parameter for "
742 "adapter %d, addr 0x%02x\n", adap_id,
743 address_data->probe[i + 1]);
744 err = i2c_probe_address(adapter,
745 address_data->probe[i + 1],
746 -1, found_proc);
747 if (err)
748 return err;
749 }
750 }
751
752 /* Normal entries are done last, unless shadowed by an ignore entry */
753 for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) {
754 int j, ignore;
755
756 ignore = 0;
757 for (j = 0; address_data->ignore[j] != I2C_CLIENT_END;
758 j += 2) {
759 if ((address_data->ignore[j] == adap_id ||
760 address_data->ignore[j] == ANY_I2C_BUS)
761 && address_data->ignore[j + 1]
762 == address_data->normal_i2c[i]) {
763 dev_dbg(&adapter->dev, "found ignore "
764 "parameter for adapter %d, "
765 "addr 0x%02x\n", adap_id,
766 address_data->ignore[j + 1]);
767 }
768 ignore = 1;
769 break;
770 }
771 if (ignore)
772 continue;
773
774 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
775 "addr 0x%02x\n", adap_id,
776 address_data->normal_i2c[i]);
777 err = i2c_probe_address(adapter, address_data->normal_i2c[i],
778 -1, found_proc);
779 if (err)
780 return err;
781 }
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return 0;
784}
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786struct i2c_adapter* i2c_get_adapter(int id)
787{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 struct i2c_adapter *adapter;
789
790 down(&core_lists);
Mark M. Hoffmana0920e12005-06-28 00:21:30 -0400791 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
792 if (adapter && !try_module_get(adapter->owner))
793 adapter = NULL;
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 up(&core_lists);
Mark M. Hoffmana0920e12005-06-28 00:21:30 -0400796 return adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
799void i2c_put_adapter(struct i2c_adapter *adap)
800{
801 module_put(adap->owner);
802}
803
804/* The SMBus parts */
805
806#define POLY (0x1070U << 3)
807static u8
808crc8(u16 data)
809{
810 int i;
811
812 for(i = 0; i < 8; i++) {
813 if (data & 0x8000)
814 data = data ^ POLY;
815 data = data << 1;
816 }
817 return (u8)(data >> 8);
818}
819
Jean Delvare421ef472005-10-26 21:28:55 +0200820/* Incremental CRC8 over count bytes in the array pointed to by p */
821static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
823 int i;
824
825 for(i = 0; i < count; i++)
Jean Delvare421ef472005-10-26 21:28:55 +0200826 crc = crc8((crc ^ p[i]) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return crc;
828}
829
Jean Delvare421ef472005-10-26 21:28:55 +0200830/* Assume a 7-bit address, which is reasonable for SMBus */
831static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Jean Delvare421ef472005-10-26 21:28:55 +0200833 /* The address will be sent first */
834 u8 addr = (msg->addr << 1) | !!(msg->flags & I2C_M_RD);
835 pec = i2c_smbus_pec(pec, &addr, 1);
836
837 /* The data buffer follows */
838 return i2c_smbus_pec(pec, msg->buf, msg->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
Jean Delvare421ef472005-10-26 21:28:55 +0200841/* Used for write only transactions */
842static inline void i2c_smbus_add_pec(struct i2c_msg *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Jean Delvare421ef472005-10-26 21:28:55 +0200844 msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg);
845 msg->len++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Jean Delvare421ef472005-10-26 21:28:55 +0200848/* Return <0 on CRC error
849 If there was a write before this read (most cases) we need to take the
850 partial CRC from the write part into account.
851 Note that this function does modify the message (we need to decrease the
852 message length to hide the CRC byte from the caller). */
853static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854{
Jean Delvare421ef472005-10-26 21:28:55 +0200855 u8 rpec = msg->buf[--msg->len];
856 cpec = i2c_smbus_msg_pec(cpec, msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 if (rpec != cpec) {
859 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n",
860 rpec, cpec);
861 return -1;
862 }
863 return 0;
864}
865
866s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value)
867{
868 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
869 value,0,I2C_SMBUS_QUICK,NULL);
870}
871
872s32 i2c_smbus_read_byte(struct i2c_client *client)
873{
874 union i2c_smbus_data data;
875 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
876 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data))
877 return -1;
878 else
879 return 0x0FF & data.byte;
880}
881
882s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
883{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
Jean Delvare421ef472005-10-26 21:28:55 +0200885 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}
887
888s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
889{
890 union i2c_smbus_data data;
891 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
892 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data))
893 return -1;
894 else
895 return 0x0FF & data.byte;
896}
897
898s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
899{
900 union i2c_smbus_data data;
901 data.byte = value;
902 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
903 I2C_SMBUS_WRITE,command,
904 I2C_SMBUS_BYTE_DATA,&data);
905}
906
907s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
908{
909 union i2c_smbus_data data;
910 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
911 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data))
912 return -1;
913 else
914 return 0x0FFFF & data.word;
915}
916
917s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
918{
919 union i2c_smbus_data data;
920 data.word = value;
921 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
922 I2C_SMBUS_WRITE,command,
923 I2C_SMBUS_WORD_DATA,&data);
924}
925
926s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
927 u8 length, u8 *values)
928{
929 union i2c_smbus_data data;
930 int i;
931 if (length > I2C_SMBUS_BLOCK_MAX)
932 length = I2C_SMBUS_BLOCK_MAX;
933 for (i = 1; i <= length; i++)
934 data.block[i] = values[i-1];
935 data.block[0] = length;
936 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
937 I2C_SMBUS_WRITE,command,
938 I2C_SMBUS_BLOCK_DATA,&data);
939}
940
941/* Returns the number of read bytes */
942s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values)
943{
944 union i2c_smbus_data data;
945 int i;
946 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
947 I2C_SMBUS_READ,command,
948 I2C_SMBUS_I2C_BLOCK_DATA,&data))
949 return -1;
950 else {
951 for (i = 1; i <= data.block[0]; i++)
952 values[i-1] = data.block[i];
953 return data.block[0];
954 }
955}
956
957/* Simulate a SMBus command using the i2c protocol
958 No checking of parameters is done! */
959static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
960 unsigned short flags,
961 char read_write, u8 command, int size,
962 union i2c_smbus_data * data)
963{
964 /* So we need to generate a series of msgs. In the case of writing, we
965 need to use only one message; when reading, we need two. We initialize
966 most things with sane defaults, to keep the code below somewhat
967 simpler. */
Hideki Iwamoto5c50d182005-09-25 17:01:11 +0200968 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
969 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 int num = read_write == I2C_SMBUS_READ?2:1;
971 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
972 { addr, flags | I2C_M_RD, 0, msgbuf1 }
973 };
974 int i;
Jean Delvare421ef472005-10-26 21:28:55 +0200975 u8 partial_pec = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 msgbuf0[0] = command;
978 switch(size) {
979 case I2C_SMBUS_QUICK:
980 msg[0].len = 0;
981 /* Special case: The read/write field is used as data */
982 msg[0].flags = flags | (read_write==I2C_SMBUS_READ)?I2C_M_RD:0;
983 num = 1;
984 break;
985 case I2C_SMBUS_BYTE:
986 if (read_write == I2C_SMBUS_READ) {
987 /* Special case: only a read! */
988 msg[0].flags = I2C_M_RD | flags;
989 num = 1;
990 }
991 break;
992 case I2C_SMBUS_BYTE_DATA:
993 if (read_write == I2C_SMBUS_READ)
994 msg[1].len = 1;
995 else {
996 msg[0].len = 2;
997 msgbuf0[1] = data->byte;
998 }
999 break;
1000 case I2C_SMBUS_WORD_DATA:
1001 if (read_write == I2C_SMBUS_READ)
1002 msg[1].len = 2;
1003 else {
1004 msg[0].len=3;
1005 msgbuf0[1] = data->word & 0xff;
1006 msgbuf0[2] = (data->word >> 8) & 0xff;
1007 }
1008 break;
1009 case I2C_SMBUS_PROC_CALL:
1010 num = 2; /* Special case */
1011 read_write = I2C_SMBUS_READ;
1012 msg[0].len = 3;
1013 msg[1].len = 2;
1014 msgbuf0[1] = data->word & 0xff;
1015 msgbuf0[2] = (data->word >> 8) & 0xff;
1016 break;
1017 case I2C_SMBUS_BLOCK_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if (read_write == I2C_SMBUS_READ) {
1019 dev_err(&adapter->dev, "Block read not supported "
1020 "under I2C emulation!\n");
1021 return -1;
1022 } else {
1023 msg[0].len = data->block[0] + 2;
1024 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
1025 dev_err(&adapter->dev, "smbus_access called with "
1026 "invalid block write size (%d)\n",
1027 data->block[0]);
1028 return -1;
1029 }
Hideki Iwamoto5c50d182005-09-25 17:01:11 +02001030 for (i = 1; i < msg[0].len; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 msgbuf0[i] = data->block[i-1];
1032 }
1033 break;
1034 case I2C_SMBUS_BLOCK_PROC_CALL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 dev_dbg(&adapter->dev, "Block process call not supported "
1036 "under I2C emulation!\n");
1037 return -1;
1038 case I2C_SMBUS_I2C_BLOCK_DATA:
1039 if (read_write == I2C_SMBUS_READ) {
Jean Delvare30dac742005-10-08 00:15:59 +02001040 msg[1].len = I2C_SMBUS_BLOCK_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 } else {
1042 msg[0].len = data->block[0] + 1;
Jean Delvare30dac742005-10-08 00:15:59 +02001043 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with "
1045 "invalid block write size (%d)\n",
1046 data->block[0]);
1047 return -1;
1048 }
1049 for (i = 1; i <= data->block[0]; i++)
1050 msgbuf0[i] = data->block[i];
1051 }
1052 break;
1053 default:
1054 dev_err(&adapter->dev, "smbus_access called with invalid size (%d)\n",
1055 size);
1056 return -1;
1057 }
1058
Jean Delvare421ef472005-10-26 21:28:55 +02001059 i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
1060 && size != I2C_SMBUS_I2C_BLOCK_DATA);
1061 if (i) {
1062 /* Compute PEC if first message is a write */
1063 if (!(msg[0].flags & I2C_M_RD)) {
1064 if (num == 1) /* Write only */
1065 i2c_smbus_add_pec(&msg[0]);
1066 else /* Write followed by read */
1067 partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
1068 }
1069 /* Ask for PEC if last message is a read */
1070 if (msg[num-1].flags & I2C_M_RD)
1071 msg[num-1].len++;
1072 }
1073
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 if (i2c_transfer(adapter, msg, num) < 0)
1075 return -1;
1076
Jean Delvare421ef472005-10-26 21:28:55 +02001077 /* Check PEC if last message is a read */
1078 if (i && (msg[num-1].flags & I2C_M_RD)) {
1079 if (i2c_smbus_check_pec(partial_pec, &msg[num-1]) < 0)
1080 return -1;
1081 }
1082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 if (read_write == I2C_SMBUS_READ)
1084 switch(size) {
1085 case I2C_SMBUS_BYTE:
1086 data->byte = msgbuf0[0];
1087 break;
1088 case I2C_SMBUS_BYTE_DATA:
1089 data->byte = msgbuf1[0];
1090 break;
1091 case I2C_SMBUS_WORD_DATA:
1092 case I2C_SMBUS_PROC_CALL:
1093 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
1094 break;
1095 case I2C_SMBUS_I2C_BLOCK_DATA:
1096 /* fixed at 32 for now */
Jean Delvare30dac742005-10-08 00:15:59 +02001097 data->block[0] = I2C_SMBUS_BLOCK_MAX;
1098 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 data->block[i+1] = msgbuf1[i];
1100 break;
1101 }
1102 return 0;
1103}
1104
1105
1106s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1107 char read_write, u8 command, int size,
1108 union i2c_smbus_data * data)
1109{
1110 s32 res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 if (adapter->algo->smbus_xfer) {
1115 down(&adapter->bus_lock);
1116 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
1117 command,size,data);
1118 up(&adapter->bus_lock);
1119 } else
1120 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1121 command,size,data);
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return res;
1124}
1125
1126
Jean Delvareefde7232005-07-20 23:03:50 +02001127/* Next four are needed by i2c-isa */
1128EXPORT_SYMBOL_GPL(i2c_adapter_dev_release);
1129EXPORT_SYMBOL_GPL(i2c_adapter_driver);
1130EXPORT_SYMBOL_GPL(i2c_adapter_class);
1131EXPORT_SYMBOL_GPL(i2c_bus_type);
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133EXPORT_SYMBOL(i2c_add_adapter);
1134EXPORT_SYMBOL(i2c_del_adapter);
1135EXPORT_SYMBOL(i2c_add_driver);
1136EXPORT_SYMBOL(i2c_del_driver);
1137EXPORT_SYMBOL(i2c_attach_client);
1138EXPORT_SYMBOL(i2c_detach_client);
1139EXPORT_SYMBOL(i2c_use_client);
1140EXPORT_SYMBOL(i2c_release_client);
1141EXPORT_SYMBOL(i2c_clients_command);
1142EXPORT_SYMBOL(i2c_check_addr);
1143
1144EXPORT_SYMBOL(i2c_master_send);
1145EXPORT_SYMBOL(i2c_master_recv);
1146EXPORT_SYMBOL(i2c_control);
1147EXPORT_SYMBOL(i2c_transfer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148EXPORT_SYMBOL(i2c_get_adapter);
1149EXPORT_SYMBOL(i2c_put_adapter);
1150EXPORT_SYMBOL(i2c_probe);
1151
1152EXPORT_SYMBOL(i2c_smbus_xfer);
1153EXPORT_SYMBOL(i2c_smbus_write_quick);
1154EXPORT_SYMBOL(i2c_smbus_read_byte);
1155EXPORT_SYMBOL(i2c_smbus_write_byte);
1156EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1157EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1158EXPORT_SYMBOL(i2c_smbus_read_word_data);
1159EXPORT_SYMBOL(i2c_smbus_write_word_data);
1160EXPORT_SYMBOL(i2c_smbus_write_block_data);
1161EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1162
1163MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1164MODULE_DESCRIPTION("I2C-Bus main module");
1165MODULE_LICENSE("GPL");