1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 1995-99 Simon G. Vogl
6 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>
7 * Mux support by Rodolfo Giometti <giometti@enneenne.com> and
8 * Michael Lawnick <michael.lawnick.ext@nsn.com>
10 * Copyright (C) 2013-2017 Wolfram Sang <wsa@the-dreams.de>
13 #define pr_fmt(fmt) "i2c-core: " fmt
15 #include <dt-bindings/i2c/i2c.h>
16 #include <linux/acpi.h>
17 #include <linux/clk/clk-conf.h>
18 #include <linux/completion.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
21 #include <linux/errno.h>
22 #include <linux/gpio/consumer.h>
23 #include <linux/i2c.h>
24 #include <linux/i2c-smbus.h>
25 #include <linux/idr.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/irqflags.h>
29 #include <linux/jump_label.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/mutex.h>
33 #include <linux/of_device.h>
35 #include <linux/of_irq.h>
36 #include <linux/pm_domain.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/pm_wakeirq.h>
39 #include <linux/property.h>
40 #include <linux/rwsem.h>
41 #include <linux/slab.h>
45 #define CREATE_TRACE_POINTS
46 #include <trace/events/i2c.h>
48 #define I2C_ADDR_OFFSET_TEN_BIT 0xa000
49 #define I2C_ADDR_OFFSET_SLAVE 0x1000
51 #define I2C_ADDR_7BITS_MAX 0x77
52 #define I2C_ADDR_7BITS_COUNT (I2C_ADDR_7BITS_MAX + 1)
54 #define I2C_ADDR_DEVICE_ID 0x7c
57 * core_lock protects i2c_adapter_idr, and guarantees that device detection,
58 * deletion of detected devices are serialized
60 static DEFINE_MUTEX(core_lock);
61 static DEFINE_IDR(i2c_adapter_idr);
63 static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
65 static DEFINE_STATIC_KEY_FALSE(i2c_trace_msg_key);
66 static bool is_registered;
68 int i2c_transfer_trace_reg(void)
70 static_branch_inc(&i2c_trace_msg_key);
74 void i2c_transfer_trace_unreg(void)
76 static_branch_dec(&i2c_trace_msg_key);
79 const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
80 const struct i2c_client *client)
86 if (strcmp(client->name, id->name) == 0)
92 EXPORT_SYMBOL_GPL(i2c_match_id);
94 static int i2c_device_match(struct device *dev, struct device_driver *drv)
96 struct i2c_client *client = i2c_verify_client(dev);
97 struct i2c_driver *driver;
100 /* Attempt an OF style match */
101 if (i2c_of_match_device(drv->of_match_table, client))
104 /* Then ACPI style match */
105 if (acpi_driver_match_device(dev, drv))
108 driver = to_i2c_driver(drv);
110 /* Finally an I2C match */
111 if (i2c_match_id(driver->id_table, client))
117 static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
119 struct i2c_client *client = to_i2c_client(dev);
122 rc = of_device_uevent_modalias(dev, env);
126 rc = acpi_device_uevent_modalias(dev, env);
130 return add_uevent_var(env, "MODALIAS=%s%s", I2C_MODULE_PREFIX, client->name);
133 /* i2c bus recovery routines */
134 static int get_scl_gpio_value(struct i2c_adapter *adap)
136 return gpiod_get_value_cansleep(adap->bus_recovery_info->scl_gpiod);
139 static void set_scl_gpio_value(struct i2c_adapter *adap, int val)
141 gpiod_set_value_cansleep(adap->bus_recovery_info->scl_gpiod, val);
144 static int get_sda_gpio_value(struct i2c_adapter *adap)
146 return gpiod_get_value_cansleep(adap->bus_recovery_info->sda_gpiod);
149 static void set_sda_gpio_value(struct i2c_adapter *adap, int val)
151 gpiod_set_value_cansleep(adap->bus_recovery_info->sda_gpiod, val);
154 static int i2c_generic_bus_free(struct i2c_adapter *adap)
156 struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
157 int ret = -EOPNOTSUPP;
159 if (bri->get_bus_free)
160 ret = bri->get_bus_free(adap);
161 else if (bri->get_sda)
162 ret = bri->get_sda(adap);
167 return ret ? 0 : -EBUSY;
171 * We are generating clock pulses. ndelay() determines durating of clk pulses.
172 * We will generate clock with rate 100 KHz and so duration of both clock levels
173 * is: delay in ns = (10^6 / 100) / 2
175 #define RECOVERY_NDELAY 5000
176 #define RECOVERY_CLK_CNT 9
178 int i2c_generic_scl_recovery(struct i2c_adapter *adap)
180 struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
181 int i = 0, scl = 1, ret = 0;
183 if (bri->prepare_recovery)
184 bri->prepare_recovery(adap);
187 * If we can set SDA, we will always create a STOP to ensure additional
188 * pulses will do no harm. This is achieved by letting SDA follow SCL
189 * half a cycle later. Check the 'incomplete_write_byte' fault injector
190 * for details. Note that we must honour tsu:sto, 4us, but lets use 5us
191 * here for simplicity.
193 bri->set_scl(adap, scl);
194 ndelay(RECOVERY_NDELAY);
196 bri->set_sda(adap, scl);
197 ndelay(RECOVERY_NDELAY / 2);
200 * By this time SCL is high, as we need to give 9 falling-rising edges
202 while (i++ < RECOVERY_CLK_CNT * 2) {
204 /* SCL shouldn't be low here */
205 if (!bri->get_scl(adap)) {
207 "SCL is stuck low, exit recovery\n");
214 bri->set_scl(adap, scl);
215 /* Creating STOP again, see above */
217 /* Honour minimum tsu:sto */
218 ndelay(RECOVERY_NDELAY);
220 /* Honour minimum tf and thd:dat */
221 ndelay(RECOVERY_NDELAY / 2);
224 bri->set_sda(adap, scl);
225 ndelay(RECOVERY_NDELAY / 2);
228 ret = i2c_generic_bus_free(adap);
234 /* If we can't check bus status, assume recovery worked */
235 if (ret == -EOPNOTSUPP)
238 if (bri->unprepare_recovery)
239 bri->unprepare_recovery(adap);
243 EXPORT_SYMBOL_GPL(i2c_generic_scl_recovery);
245 int i2c_recover_bus(struct i2c_adapter *adap)
247 if (!adap->bus_recovery_info)
250 dev_dbg(&adap->dev, "Trying i2c bus recovery\n");
251 return adap->bus_recovery_info->recover_bus(adap);
253 EXPORT_SYMBOL_GPL(i2c_recover_bus);
255 static void i2c_init_recovery(struct i2c_adapter *adap)
257 struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
258 char *err_str, *err_level = KERN_ERR;
263 if (!bri->recover_bus) {
264 err_str = "no suitable method provided";
265 err_level = KERN_DEBUG;
269 if (bri->scl_gpiod && bri->recover_bus == i2c_generic_scl_recovery) {
270 bri->get_scl = get_scl_gpio_value;
271 bri->set_scl = set_scl_gpio_value;
272 if (bri->sda_gpiod) {
273 bri->get_sda = get_sda_gpio_value;
274 /* FIXME: add proper flag instead of '0' once available */
275 if (gpiod_get_direction(bri->sda_gpiod) == 0)
276 bri->set_sda = set_sda_gpio_value;
281 if (bri->recover_bus == i2c_generic_scl_recovery) {
282 /* Generic SCL recovery */
283 if (!bri->set_scl || !bri->get_scl) {
284 err_str = "no {get|set}_scl() found";
287 if (!bri->set_sda && !bri->get_sda) {
288 err_str = "either get_sda() or set_sda() needed";
295 dev_printk(err_level, &adap->dev, "Not using recovery: %s\n", err_str);
296 adap->bus_recovery_info = NULL;
299 static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
301 struct i2c_adapter *adap = client->adapter;
304 if (!adap->host_notify_domain)
307 if (client->flags & I2C_CLIENT_TEN)
310 irq = irq_create_mapping(adap->host_notify_domain, client->addr);
312 return irq > 0 ? irq : -ENXIO;
315 static int i2c_device_probe(struct device *dev)
317 struct i2c_client *client = i2c_verify_client(dev);
318 struct i2c_driver *driver;
324 driver = to_i2c_driver(dev->driver);
326 client->irq = client->init_irq;
328 if (!client->irq && !driver->disable_i2c_core_irq_mapping) {
331 if (client->flags & I2C_CLIENT_HOST_NOTIFY) {
332 dev_dbg(dev, "Using Host Notify IRQ\n");
333 /* Keep adapter active when Host Notify is required */
334 pm_runtime_get_sync(&client->adapter->dev);
335 irq = i2c_smbus_host_notify_to_irq(client);
336 } else if (dev->of_node) {
337 irq = of_irq_get_byname(dev->of_node, "irq");
338 if (irq == -EINVAL || irq == -ENODATA)
339 irq = of_irq_get(dev->of_node, 0);
340 } else if (ACPI_COMPANION(dev)) {
341 irq = i2c_acpi_get_irq(client);
343 if (irq == -EPROBE_DEFER) {
345 goto put_sync_adapter;
355 * An I2C ID table is not mandatory, if and only if, a suitable OF
356 * or ACPI ID table is supplied for the probing device.
358 if (!driver->id_table &&
359 !acpi_driver_match_device(dev, dev->driver) &&
360 !i2c_of_match_device(dev->driver->of_match_table, client)) {
362 goto put_sync_adapter;
365 if (client->flags & I2C_CLIENT_WAKE) {
368 wakeirq = of_irq_get_byname(dev->of_node, "wakeup");
369 if (wakeirq == -EPROBE_DEFER) {
371 goto put_sync_adapter;
374 device_init_wakeup(&client->dev, true);
376 if (wakeirq > 0 && wakeirq != client->irq)
377 status = dev_pm_set_dedicated_wake_irq(dev, wakeirq);
378 else if (client->irq > 0)
379 status = dev_pm_set_wake_irq(dev, client->irq);
384 dev_warn(&client->dev, "failed to set up wakeup irq\n");
387 dev_dbg(dev, "probe\n");
389 status = of_clk_set_defaults(dev->of_node, false);
391 goto err_clear_wakeup_irq;
393 status = dev_pm_domain_attach(&client->dev, true);
395 goto err_clear_wakeup_irq;
398 * When there are no more users of probe(),
399 * rename probe_new to probe.
401 if (driver->probe_new)
402 status = driver->probe_new(client);
403 else if (driver->probe)
404 status = driver->probe(client,
405 i2c_match_id(driver->id_table, client));
410 goto err_detach_pm_domain;
414 err_detach_pm_domain:
415 dev_pm_domain_detach(&client->dev, true);
416 err_clear_wakeup_irq:
417 dev_pm_clear_wake_irq(&client->dev);
418 device_init_wakeup(&client->dev, false);
420 if (client->flags & I2C_CLIENT_HOST_NOTIFY)
421 pm_runtime_put_sync(&client->adapter->dev);
426 static int i2c_device_remove(struct device *dev)
428 struct i2c_client *client = i2c_verify_client(dev);
429 struct i2c_driver *driver;
432 if (!client || !dev->driver)
435 driver = to_i2c_driver(dev->driver);
436 if (driver->remove) {
437 dev_dbg(dev, "remove\n");
438 status = driver->remove(client);
441 dev_pm_domain_detach(&client->dev, true);
443 dev_pm_clear_wake_irq(&client->dev);
444 device_init_wakeup(&client->dev, false);
447 if (client->flags & I2C_CLIENT_HOST_NOTIFY)
448 pm_runtime_put(&client->adapter->dev);
453 static void i2c_device_shutdown(struct device *dev)
455 struct i2c_client *client = i2c_verify_client(dev);
456 struct i2c_driver *driver;
458 if (!client || !dev->driver)
460 driver = to_i2c_driver(dev->driver);
461 if (driver->shutdown)
462 driver->shutdown(client);
463 else if (client->irq > 0)
464 disable_irq(client->irq);
467 static void i2c_client_dev_release(struct device *dev)
469 kfree(to_i2c_client(dev));
473 show_name(struct device *dev, struct device_attribute *attr, char *buf)
475 return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
476 to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
478 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
481 show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
483 struct i2c_client *client = to_i2c_client(dev);
486 len = of_device_modalias(dev, buf, PAGE_SIZE);
490 len = acpi_device_modalias(dev, buf, PAGE_SIZE -1);
494 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
496 static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
498 static struct attribute *i2c_dev_attrs[] = {
500 /* modalias helps coldplug: modprobe $(cat .../modalias) */
501 &dev_attr_modalias.attr,
504 ATTRIBUTE_GROUPS(i2c_dev);
506 struct bus_type i2c_bus_type = {
508 .match = i2c_device_match,
509 .probe = i2c_device_probe,
510 .remove = i2c_device_remove,
511 .shutdown = i2c_device_shutdown,
513 EXPORT_SYMBOL_GPL(i2c_bus_type);
515 struct device_type i2c_client_type = {
516 .groups = i2c_dev_groups,
517 .uevent = i2c_device_uevent,
518 .release = i2c_client_dev_release,
520 EXPORT_SYMBOL_GPL(i2c_client_type);
524 * i2c_verify_client - return parameter as i2c_client, or NULL
525 * @dev: device, probably from some driver model iterator
527 * When traversing the driver model tree, perhaps using driver model
528 * iterators like @device_for_each_child(), you can't assume very much
529 * about the nodes you find. Use this function to avoid oopses caused
530 * by wrongly treating some non-I2C device as an i2c_client.
532 struct i2c_client *i2c_verify_client(struct device *dev)
534 return (dev->type == &i2c_client_type)
538 EXPORT_SYMBOL(i2c_verify_client);
541 /* Return a unique address which takes the flags of the client into account */
542 static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client)
544 unsigned short addr = client->addr;
546 /* For some client flags, add an arbitrary offset to avoid collisions */
547 if (client->flags & I2C_CLIENT_TEN)
548 addr |= I2C_ADDR_OFFSET_TEN_BIT;
550 if (client->flags & I2C_CLIENT_SLAVE)
551 addr |= I2C_ADDR_OFFSET_SLAVE;
556 /* This is a permissive address validity check, I2C address map constraints
557 * are purposely not enforced, except for the general call address. */
558 static int i2c_check_addr_validity(unsigned int addr, unsigned short flags)
560 if (flags & I2C_CLIENT_TEN) {
561 /* 10-bit address, all values are valid */
565 /* 7-bit address, reject the general call address */
566 if (addr == 0x00 || addr > 0x7f)
572 /* And this is a strict address validity check, used when probing. If a
573 * device uses a reserved address, then it shouldn't be probed. 7-bit
574 * addressing is assumed, 10-bit address devices are rare and should be
575 * explicitly enumerated. */
576 int i2c_check_7bit_addr_validity_strict(unsigned short addr)
579 * Reserved addresses per I2C specification:
580 * 0x00 General call address / START byte
582 * 0x02 Reserved for different bus format
583 * 0x03 Reserved for future purposes
584 * 0x04-0x07 Hs-mode master code
585 * 0x78-0x7b 10-bit slave addressing
586 * 0x7c-0x7f Reserved for future purposes
588 if (addr < 0x08 || addr > 0x77)
593 static int __i2c_check_addr_busy(struct device *dev, void *addrp)
595 struct i2c_client *client = i2c_verify_client(dev);
596 int addr = *(int *)addrp;
598 if (client && i2c_encode_flags_to_addr(client) == addr)
603 /* walk up mux tree */
604 static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr)
606 struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
609 result = device_for_each_child(&adapter->dev, &addr,
610 __i2c_check_addr_busy);
612 if (!result && parent)
613 result = i2c_check_mux_parents(parent, addr);
618 /* recurse down mux tree */
619 static int i2c_check_mux_children(struct device *dev, void *addrp)
623 if (dev->type == &i2c_adapter_type)
624 result = device_for_each_child(dev, addrp,
625 i2c_check_mux_children);
627 result = __i2c_check_addr_busy(dev, addrp);
632 static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
634 struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter);
638 result = i2c_check_mux_parents(parent, addr);
641 result = device_for_each_child(&adapter->dev, &addr,
642 i2c_check_mux_children);
648 * i2c_adapter_lock_bus - Get exclusive access to an I2C bus segment
649 * @adapter: Target I2C bus segment
650 * @flags: I2C_LOCK_ROOT_ADAPTER locks the root i2c adapter, I2C_LOCK_SEGMENT
651 * locks only this branch in the adapter tree
653 static void i2c_adapter_lock_bus(struct i2c_adapter *adapter,
656 rt_mutex_lock_nested(&adapter->bus_lock, i2c_adapter_depth(adapter));
660 * i2c_adapter_trylock_bus - Try to get exclusive access to an I2C bus segment
661 * @adapter: Target I2C bus segment
662 * @flags: I2C_LOCK_ROOT_ADAPTER trylocks the root i2c adapter, I2C_LOCK_SEGMENT
663 * trylocks only this branch in the adapter tree
665 static int i2c_adapter_trylock_bus(struct i2c_adapter *adapter,
668 return rt_mutex_trylock(&adapter->bus_lock);
672 * i2c_adapter_unlock_bus - Release exclusive access to an I2C bus segment
673 * @adapter: Target I2C bus segment
674 * @flags: I2C_LOCK_ROOT_ADAPTER unlocks the root i2c adapter, I2C_LOCK_SEGMENT
675 * unlocks only this branch in the adapter tree
677 static void i2c_adapter_unlock_bus(struct i2c_adapter *adapter,
680 rt_mutex_unlock(&adapter->bus_lock);
683 static void i2c_dev_set_name(struct i2c_adapter *adap,
684 struct i2c_client *client,
685 struct i2c_board_info const *info)
687 struct acpi_device *adev = ACPI_COMPANION(&client->dev);
689 if (info && info->dev_name) {
690 dev_set_name(&client->dev, "i2c-%s", info->dev_name);
695 dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
699 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
700 i2c_encode_flags_to_addr(client));
703 int i2c_dev_irq_from_resources(const struct resource *resources,
704 unsigned int num_resources)
706 struct irq_data *irqd;
709 for (i = 0; i < num_resources; i++) {
710 const struct resource *r = &resources[i];
712 if (resource_type(r) != IORESOURCE_IRQ)
715 if (r->flags & IORESOURCE_BITS) {
716 irqd = irq_get_irq_data(r->start);
720 irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
730 * i2c_new_client_device - instantiate an i2c device
731 * @adap: the adapter managing the device
732 * @info: describes one I2C device; bus_num is ignored
735 * Create an i2c device. Binding is handled through driver model
736 * probe()/remove() methods. A driver may be bound to this device when we
737 * return from this function, or any later moment (e.g. maybe hotplugging will
738 * load the driver module). This call is not appropriate for use by mainboard
739 * initialization logic, which usually runs during an arch_initcall() long
740 * before any i2c_adapter could exist.
742 * This returns the new i2c client, which may be saved for later use with
743 * i2c_unregister_device(); or an ERR_PTR to describe the error.
746 i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
748 struct i2c_client *client;
751 client = kzalloc(sizeof *client, GFP_KERNEL);
753 return ERR_PTR(-ENOMEM);
755 client->adapter = adap;
757 client->dev.platform_data = info->platform_data;
758 client->flags = info->flags;
759 client->addr = info->addr;
761 client->init_irq = info->irq;
762 if (!client->init_irq)
763 client->init_irq = i2c_dev_irq_from_resources(info->resources,
764 info->num_resources);
766 strlcpy(client->name, info->type, sizeof(client->name));
768 status = i2c_check_addr_validity(client->addr, client->flags);
770 dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n",
771 client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr);
775 /* Check for address business */
776 status = i2c_check_addr_busy(adap, i2c_encode_flags_to_addr(client));
780 client->dev.parent = &client->adapter->dev;
781 client->dev.bus = &i2c_bus_type;
782 client->dev.type = &i2c_client_type;
783 client->dev.of_node = of_node_get(info->of_node);
784 client->dev.fwnode = info->fwnode;
786 i2c_dev_set_name(adap, client, info);
788 if (info->properties) {
789 status = device_add_properties(&client->dev, info->properties);
792 "Failed to add properties to client %s: %d\n",
793 client->name, status);
794 goto out_err_put_of_node;
798 status = device_register(&client->dev);
802 dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n",
803 client->name, dev_name(&client->dev));
808 if (info->properties)
809 device_remove_properties(&client->dev);
811 of_node_put(info->of_node);
814 "Failed to register i2c client %s at 0x%02x (%d)\n",
815 client->name, client->addr, status);
818 return ERR_PTR(status);
820 EXPORT_SYMBOL_GPL(i2c_new_client_device);
823 * i2c_new_device - instantiate an i2c device
824 * @adap: the adapter managing the device
825 * @info: describes one I2C device; bus_num is ignored
828 * This deprecated function has the same functionality as
829 * @i2c_new_client_device, it just returns NULL instead of an ERR_PTR in case of
830 * an error for compatibility with current I2C API. It will be removed once all
831 * users are converted.
833 * This returns the new i2c client, which may be saved for later use with
834 * i2c_unregister_device(); or NULL to indicate an error.
837 i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
839 struct i2c_client *ret;
841 ret = i2c_new_client_device(adap, info);
842 return IS_ERR(ret) ? NULL : ret;
844 EXPORT_SYMBOL_GPL(i2c_new_device);
848 * i2c_unregister_device - reverse effect of i2c_new_device()
849 * @client: value returned from i2c_new_device()
852 void i2c_unregister_device(struct i2c_client *client)
854 if (IS_ERR_OR_NULL(client))
857 if (client->dev.of_node) {
858 of_node_clear_flag(client->dev.of_node, OF_POPULATED);
859 of_node_put(client->dev.of_node);
862 if (ACPI_COMPANION(&client->dev))
863 acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
864 device_unregister(&client->dev);
866 EXPORT_SYMBOL_GPL(i2c_unregister_device);
869 static const struct i2c_device_id dummy_id[] = {
874 static int dummy_probe(struct i2c_client *client,
875 const struct i2c_device_id *id)
880 static int dummy_remove(struct i2c_client *client)
885 static struct i2c_driver dummy_driver = {
886 .driver.name = "dummy",
887 .probe = dummy_probe,
888 .remove = dummy_remove,
889 .id_table = dummy_id,
893 * i2c_new_dummy_device - return a new i2c device bound to a dummy driver
894 * @adapter: the adapter managing the device
895 * @address: seven bit address to be used
898 * This returns an I2C client bound to the "dummy" driver, intended for use
899 * with devices that consume multiple addresses. Examples of such chips
900 * include various EEPROMS (like 24c04 and 24c08 models).
902 * These dummy devices have two main uses. First, most I2C and SMBus calls
903 * except i2c_transfer() need a client handle; the dummy will be that handle.
904 * And second, this prevents the specified address from being bound to a
907 * This returns the new i2c client, which should be saved for later use with
908 * i2c_unregister_device(); or an ERR_PTR to describe the error.
910 struct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
912 struct i2c_board_info info = {
913 I2C_BOARD_INFO("dummy", address),
916 return i2c_new_client_device(adapter, &info);
918 EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
921 * i2c_new_dummy - return a new i2c device bound to a dummy driver
922 * @adapter: the adapter managing the device
923 * @address: seven bit address to be used
926 * This deprecated function has the same functionality as @i2c_new_dummy_device,
927 * it just returns NULL instead of an ERR_PTR in case of an error for
928 * compatibility with current I2C API. It will be removed once all users are
931 * This returns the new i2c client, which should be saved for later use with
932 * i2c_unregister_device(); or NULL to indicate an error.
934 struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
936 struct i2c_client *ret;
938 ret = i2c_new_dummy_device(adapter, address);
939 return IS_ERR(ret) ? NULL : ret;
941 EXPORT_SYMBOL_GPL(i2c_new_dummy);
943 struct i2c_dummy_devres {
944 struct i2c_client *client;
947 static void devm_i2c_release_dummy(struct device *dev, void *res)
949 struct i2c_dummy_devres *this = res;
951 i2c_unregister_device(this->client);
955 * devm_i2c_new_dummy_device - return a new i2c device bound to a dummy driver
956 * @dev: device the managed resource is bound to
957 * @adapter: the adapter managing the device
958 * @address: seven bit address to be used
961 * This is the device-managed version of @i2c_new_dummy_device. It returns the
962 * new i2c client or an ERR_PTR in case of an error.
964 struct i2c_client *devm_i2c_new_dummy_device(struct device *dev,
965 struct i2c_adapter *adapter,
968 struct i2c_dummy_devres *dr;
969 struct i2c_client *client;
971 dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL);
973 return ERR_PTR(-ENOMEM);
975 client = i2c_new_dummy_device(adapter, address);
976 if (IS_ERR(client)) {
985 EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
988 * i2c_new_ancillary_device - Helper to get the instantiated secondary address
989 * and create the associated device
990 * @client: Handle to the primary client
991 * @name: Handle to specify which secondary address to get
992 * @default_addr: Used as a fallback if no secondary address was specified
995 * I2C clients can be composed of multiple I2C slaves bound together in a single
996 * component. The I2C client driver then binds to the master I2C slave and needs
997 * to create I2C dummy clients to communicate with all the other slaves.
999 * This function creates and returns an I2C dummy client whose I2C address is
1000 * retrieved from the platform firmware based on the given slave name. If no
1001 * address is specified by the firmware default_addr is used.
1003 * On DT-based platforms the address is retrieved from the "reg" property entry
1004 * cell whose "reg-names" value matches the slave name.
1006 * This returns the new i2c client, which should be saved for later use with
1007 * i2c_unregister_device(); or an ERR_PTR to describe the error.
1009 struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
1013 struct device_node *np = client->dev.of_node;
1014 u32 addr = default_addr;
1018 i = of_property_match_string(np, "reg-names", name);
1020 of_property_read_u32_index(np, "reg", i, &addr);
1023 dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
1024 return i2c_new_dummy_device(client->adapter, addr);
1026 EXPORT_SYMBOL_GPL(i2c_new_ancillary_device);
1028 /* ------------------------------------------------------------------------- */
1030 /* I2C bus adapters -- one roots each I2C or SMBUS segment */
1032 static void i2c_adapter_dev_release(struct device *dev)
1034 struct i2c_adapter *adap = to_i2c_adapter(dev);
1035 complete(&adap->dev_released);
1038 unsigned int i2c_adapter_depth(struct i2c_adapter *adapter)
1040 unsigned int depth = 0;
1042 while ((adapter = i2c_parent_is_i2c_adapter(adapter)))
1045 WARN_ONCE(depth >= MAX_LOCKDEP_SUBCLASSES,
1046 "adapter depth exceeds lockdep subclass limit\n");
1050 EXPORT_SYMBOL_GPL(i2c_adapter_depth);
1053 * Let users instantiate I2C devices through sysfs. This can be used when
1054 * platform initialization code doesn't contain the proper data for
1055 * whatever reason. Also useful for drivers that do device detection and
1056 * detection fails, either because the device uses an unexpected address,
1057 * or this is a compatible device with different ID register values.
1059 * Parameter checking may look overzealous, but we really don't want
1060 * the user to provide incorrect parameters.
1063 i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
1064 const char *buf, size_t count)
1066 struct i2c_adapter *adap = to_i2c_adapter(dev);
1067 struct i2c_board_info info;
1068 struct i2c_client *client;
1072 memset(&info, 0, sizeof(struct i2c_board_info));
1074 blank = strchr(buf, ' ');
1076 dev_err(dev, "%s: Missing parameters\n", "new_device");
1079 if (blank - buf > I2C_NAME_SIZE - 1) {
1080 dev_err(dev, "%s: Invalid device name\n", "new_device");
1083 memcpy(info.type, buf, blank - buf);
1085 /* Parse remaining parameters, reject extra parameters */
1086 res = sscanf(++blank, "%hi%c", &info.addr, &end);
1088 dev_err(dev, "%s: Can't parse I2C address\n", "new_device");
1091 if (res > 1 && end != '\n') {
1092 dev_err(dev, "%s: Extra parameters\n", "new_device");
1096 if ((info.addr & I2C_ADDR_OFFSET_TEN_BIT) == I2C_ADDR_OFFSET_TEN_BIT) {
1097 info.addr &= ~I2C_ADDR_OFFSET_TEN_BIT;
1098 info.flags |= I2C_CLIENT_TEN;
1101 if (info.addr & I2C_ADDR_OFFSET_SLAVE) {
1102 info.addr &= ~I2C_ADDR_OFFSET_SLAVE;
1103 info.flags |= I2C_CLIENT_SLAVE;
1106 client = i2c_new_client_device(adap, &info);
1108 return PTR_ERR(client);
1110 /* Keep track of the added device */
1111 mutex_lock(&adap->userspace_clients_lock);
1112 list_add_tail(&client->detected, &adap->userspace_clients);
1113 mutex_unlock(&adap->userspace_clients_lock);
1114 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
1115 info.type, info.addr);
1119 static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
1122 * And of course let the users delete the devices they instantiated, if
1123 * they got it wrong. This interface can only be used to delete devices
1124 * instantiated by i2c_sysfs_new_device above. This guarantees that we
1125 * don't delete devices to which some kernel code still has references.
1127 * Parameter checking may look overzealous, but we really don't want
1128 * the user to delete the wrong device.
1131 i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
1132 const char *buf, size_t count)
1134 struct i2c_adapter *adap = to_i2c_adapter(dev);
1135 struct i2c_client *client, *next;
1136 unsigned short addr;
1140 /* Parse parameters, reject extra parameters */
1141 res = sscanf(buf, "%hi%c", &addr, &end);
1143 dev_err(dev, "%s: Can't parse I2C address\n", "delete_device");
1146 if (res > 1 && end != '\n') {
1147 dev_err(dev, "%s: Extra parameters\n", "delete_device");
1151 /* Make sure the device was added through sysfs */
1153 mutex_lock_nested(&adap->userspace_clients_lock,
1154 i2c_adapter_depth(adap));
1155 list_for_each_entry_safe(client, next, &adap->userspace_clients,
1157 if (i2c_encode_flags_to_addr(client) == addr) {
1158 dev_info(dev, "%s: Deleting device %s at 0x%02hx\n",
1159 "delete_device", client->name, client->addr);
1161 list_del(&client->detected);
1162 i2c_unregister_device(client);
1167 mutex_unlock(&adap->userspace_clients_lock);
1170 dev_err(dev, "%s: Can't find device in list\n",
1174 static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL,
1175 i2c_sysfs_delete_device);
1177 static struct attribute *i2c_adapter_attrs[] = {
1178 &dev_attr_name.attr,
1179 &dev_attr_new_device.attr,
1180 &dev_attr_delete_device.attr,
1183 ATTRIBUTE_GROUPS(i2c_adapter);
1185 struct device_type i2c_adapter_type = {
1186 .groups = i2c_adapter_groups,
1187 .release = i2c_adapter_dev_release,
1189 EXPORT_SYMBOL_GPL(i2c_adapter_type);
1192 * i2c_verify_adapter - return parameter as i2c_adapter or NULL
1193 * @dev: device, probably from some driver model iterator
1195 * When traversing the driver model tree, perhaps using driver model
1196 * iterators like @device_for_each_child(), you can't assume very much
1197 * about the nodes you find. Use this function to avoid oopses caused
1198 * by wrongly treating some non-I2C device as an i2c_adapter.
1200 struct i2c_adapter *i2c_verify_adapter(struct device *dev)
1202 return (dev->type == &i2c_adapter_type)
1203 ? to_i2c_adapter(dev)
1206 EXPORT_SYMBOL(i2c_verify_adapter);
1208 #ifdef CONFIG_I2C_COMPAT
1209 static struct class_compat *i2c_adapter_compat_class;
1212 static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
1214 struct i2c_devinfo *devinfo;
1216 down_read(&__i2c_board_lock);
1217 list_for_each_entry(devinfo, &__i2c_board_list, list) {
1218 if (devinfo->busnum == adapter->nr
1219 && !i2c_new_device(adapter,
1220 &devinfo->board_info))
1221 dev_err(&adapter->dev,
1222 "Can't create device at 0x%02x\n",
1223 devinfo->board_info.addr);
1225 up_read(&__i2c_board_lock);
1228 static int i2c_do_add_adapter(struct i2c_driver *driver,
1229 struct i2c_adapter *adap)
1231 /* Detect supported devices on that bus, and instantiate them */
1232 i2c_detect(adap, driver);
1237 static int __process_new_adapter(struct device_driver *d, void *data)
1239 return i2c_do_add_adapter(to_i2c_driver(d), data);
1242 static const struct i2c_lock_operations i2c_adapter_lock_ops = {
1243 .lock_bus = i2c_adapter_lock_bus,
1244 .trylock_bus = i2c_adapter_trylock_bus,
1245 .unlock_bus = i2c_adapter_unlock_bus,
1248 static void i2c_host_notify_irq_teardown(struct i2c_adapter *adap)
1250 struct irq_domain *domain = adap->host_notify_domain;
1251 irq_hw_number_t hwirq;
1256 for (hwirq = 0 ; hwirq < I2C_ADDR_7BITS_COUNT ; hwirq++)
1257 irq_dispose_mapping(irq_find_mapping(domain, hwirq));
1259 irq_domain_remove(domain);
1260 adap->host_notify_domain = NULL;
1263 static int i2c_host_notify_irq_map(struct irq_domain *h,
1265 irq_hw_number_t hw_irq_num)
1267 irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
1272 static const struct irq_domain_ops i2c_host_notify_irq_ops = {
1273 .map = i2c_host_notify_irq_map,
1276 static int i2c_setup_host_notify_irq_domain(struct i2c_adapter *adap)
1278 struct irq_domain *domain;
1280 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_HOST_NOTIFY))
1283 domain = irq_domain_create_linear(adap->dev.fwnode,
1284 I2C_ADDR_7BITS_COUNT,
1285 &i2c_host_notify_irq_ops, adap);
1289 adap->host_notify_domain = domain;
1295 * i2c_handle_smbus_host_notify - Forward a Host Notify event to the correct
1297 * @adap: the adapter
1298 * @addr: the I2C address of the notifying device
1299 * Context: can't sleep
1301 * Helper function to be called from an I2C bus driver's interrupt
1302 * handler. It will schedule the Host Notify IRQ.
1304 int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr)
1311 irq = irq_find_mapping(adap->host_notify_domain, addr);
1315 generic_handle_irq(irq);
1319 EXPORT_SYMBOL_GPL(i2c_handle_smbus_host_notify);
1321 static int i2c_register_adapter(struct i2c_adapter *adap)
1325 /* Can't register until after driver model init */
1326 if (WARN_ON(!is_registered)) {
1332 if (WARN(!adap->name[0], "i2c adapter has no name"))
1336 pr_err("adapter '%s': no algo supplied!\n", adap->name);
1340 if (!adap->lock_ops)
1341 adap->lock_ops = &i2c_adapter_lock_ops;
1343 adap->locked_flags = 0;
1344 rt_mutex_init(&adap->bus_lock);
1345 rt_mutex_init(&adap->mux_lock);
1346 mutex_init(&adap->userspace_clients_lock);
1347 INIT_LIST_HEAD(&adap->userspace_clients);
1349 /* Set default timeout to 1 second if not already set */
1350 if (adap->timeout == 0)
1353 /* register soft irqs for Host Notify */
1354 res = i2c_setup_host_notify_irq_domain(adap);
1356 pr_err("adapter '%s': can't create Host Notify IRQs (%d)\n",
1361 dev_set_name(&adap->dev, "i2c-%d", adap->nr);
1362 adap->dev.bus = &i2c_bus_type;
1363 adap->dev.type = &i2c_adapter_type;
1364 res = device_register(&adap->dev);
1366 pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
1370 res = of_i2c_setup_smbus_alert(adap);
1374 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
1376 pm_runtime_no_callbacks(&adap->dev);
1377 pm_suspend_ignore_children(&adap->dev, true);
1378 pm_runtime_enable(&adap->dev);
1380 #ifdef CONFIG_I2C_COMPAT
1381 res = class_compat_create_link(i2c_adapter_compat_class, &adap->dev,
1384 dev_warn(&adap->dev,
1385 "Failed to create compatibility class link\n");
1388 i2c_init_recovery(adap);
1390 /* create pre-declared device nodes */
1391 of_i2c_register_devices(adap);
1392 i2c_acpi_install_space_handler(adap);
1393 i2c_acpi_register_devices(adap);
1395 if (adap->nr < __i2c_first_dynamic_bus_num)
1396 i2c_scan_static_board_info(adap);
1398 /* Notify drivers */
1399 mutex_lock(&core_lock);
1400 bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
1401 mutex_unlock(&core_lock);
1406 init_completion(&adap->dev_released);
1407 device_unregister(&adap->dev);
1408 wait_for_completion(&adap->dev_released);
1410 mutex_lock(&core_lock);
1411 idr_remove(&i2c_adapter_idr, adap->nr);
1412 mutex_unlock(&core_lock);
1417 * __i2c_add_numbered_adapter - i2c_add_numbered_adapter where nr is never -1
1418 * @adap: the adapter to register (with adap->nr initialized)
1419 * Context: can sleep
1421 * See i2c_add_numbered_adapter() for details.
1423 static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
1427 mutex_lock(&core_lock);
1428 id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1, GFP_KERNEL);
1429 mutex_unlock(&core_lock);
1430 if (WARN(id < 0, "couldn't get idr"))
1431 return id == -ENOSPC ? -EBUSY : id;
1433 return i2c_register_adapter(adap);
1437 * i2c_add_adapter - declare i2c adapter, use dynamic bus number
1438 * @adapter: the adapter to add
1439 * Context: can sleep
1441 * This routine is used to declare an I2C adapter when its bus number
1442 * doesn't matter or when its bus number is specified by an dt alias.
1443 * Examples of bases when the bus number doesn't matter: I2C adapters
1444 * dynamically added by USB links or PCI plugin cards.
1446 * When this returns zero, a new bus number was allocated and stored
1447 * in adap->nr, and the specified adapter became available for clients.
1448 * Otherwise, a negative errno value is returned.
1450 int i2c_add_adapter(struct i2c_adapter *adapter)
1452 struct device *dev = &adapter->dev;
1456 id = of_alias_get_id(dev->of_node, "i2c");
1459 return __i2c_add_numbered_adapter(adapter);
1463 mutex_lock(&core_lock);
1464 id = idr_alloc(&i2c_adapter_idr, adapter,
1465 __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
1466 mutex_unlock(&core_lock);
1467 if (WARN(id < 0, "couldn't get idr"))
1472 return i2c_register_adapter(adapter);
1474 EXPORT_SYMBOL(i2c_add_adapter);
1477 * i2c_add_numbered_adapter - declare i2c adapter, use static bus number
1478 * @adap: the adapter to register (with adap->nr initialized)
1479 * Context: can sleep
1481 * This routine is used to declare an I2C adapter when its bus number
1482 * matters. For example, use it for I2C adapters from system-on-chip CPUs,
1483 * or otherwise built in to the system's mainboard, and where i2c_board_info
1484 * is used to properly configure I2C devices.
1486 * If the requested bus number is set to -1, then this function will behave
1487 * identically to i2c_add_adapter, and will dynamically assign a bus number.
1489 * If no devices have pre-been declared for this bus, then be sure to
1490 * register the adapter before any dynamically allocated ones. Otherwise
1491 * the required bus ID may not be available.
1493 * When this returns zero, the specified adapter became available for
1494 * clients using the bus number provided in adap->nr. Also, the table
1495 * of I2C devices pre-declared using i2c_register_board_info() is scanned,
1496 * and the appropriate driver model device nodes are created. Otherwise, a
1497 * negative errno value is returned.
1499 int i2c_add_numbered_adapter(struct i2c_adapter *adap)
1501 if (adap->nr == -1) /* -1 means dynamically assign bus id */
1502 return i2c_add_adapter(adap);
1504 return __i2c_add_numbered_adapter(adap);
1506 EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
1508 static void i2c_do_del_adapter(struct i2c_driver *driver,
1509 struct i2c_adapter *adapter)
1511 struct i2c_client *client, *_n;
1513 /* Remove the devices we created ourselves as the result of hardware
1514 * probing (using a driver's detect method) */
1515 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
1516 if (client->adapter == adapter) {
1517 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
1518 client->name, client->addr);
1519 list_del(&client->detected);
1520 i2c_unregister_device(client);
1525 static int __unregister_client(struct device *dev, void *dummy)
1527 struct i2c_client *client = i2c_verify_client(dev);
1528 if (client && strcmp(client->name, "dummy"))
1529 i2c_unregister_device(client);
1533 static int __unregister_dummy(struct device *dev, void *dummy)
1535 struct i2c_client *client = i2c_verify_client(dev);
1536 i2c_unregister_device(client);
1540 static int __process_removed_adapter(struct device_driver *d, void *data)
1542 i2c_do_del_adapter(to_i2c_driver(d), data);
1547 * i2c_del_adapter - unregister I2C adapter
1548 * @adap: the adapter being unregistered
1549 * Context: can sleep
1551 * This unregisters an I2C adapter which was previously registered
1552 * by @i2c_add_adapter or @i2c_add_numbered_adapter.
1554 void i2c_del_adapter(struct i2c_adapter *adap)
1556 struct i2c_adapter *found;
1557 struct i2c_client *client, *next;
1559 /* First make sure that this adapter was ever added */
1560 mutex_lock(&core_lock);
1561 found = idr_find(&i2c_adapter_idr, adap->nr);
1562 mutex_unlock(&core_lock);
1563 if (found != adap) {
1564 pr_debug("attempting to delete unregistered adapter [%s]\n", adap->name);
1568 i2c_acpi_remove_space_handler(adap);
1569 /* Tell drivers about this removal */
1570 mutex_lock(&core_lock);
1571 bus_for_each_drv(&i2c_bus_type, NULL, adap,
1572 __process_removed_adapter);
1573 mutex_unlock(&core_lock);
1575 /* Remove devices instantiated from sysfs */
1576 mutex_lock_nested(&adap->userspace_clients_lock,
1577 i2c_adapter_depth(adap));
1578 list_for_each_entry_safe(client, next, &adap->userspace_clients,
1580 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
1582 list_del(&client->detected);
1583 i2c_unregister_device(client);
1585 mutex_unlock(&adap->userspace_clients_lock);
1587 /* Detach any active clients. This can't fail, thus we do not
1588 * check the returned value. This is a two-pass process, because
1589 * we can't remove the dummy devices during the first pass: they
1590 * could have been instantiated by real devices wishing to clean
1591 * them up properly, so we give them a chance to do that first. */
1592 device_for_each_child(&adap->dev, NULL, __unregister_client);
1593 device_for_each_child(&adap->dev, NULL, __unregister_dummy);
1595 #ifdef CONFIG_I2C_COMPAT
1596 class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
1600 /* device name is gone after device_unregister */
1601 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
1603 pm_runtime_disable(&adap->dev);
1605 i2c_host_notify_irq_teardown(adap);
1607 /* wait until all references to the device are gone
1609 * FIXME: This is old code and should ideally be replaced by an
1610 * alternative which results in decoupling the lifetime of the struct
1611 * device from the i2c_adapter, like spi or netdev do. Any solution
1612 * should be thoroughly tested with DEBUG_KOBJECT_RELEASE enabled!
1614 init_completion(&adap->dev_released);
1615 device_unregister(&adap->dev);
1616 wait_for_completion(&adap->dev_released);
1619 mutex_lock(&core_lock);
1620 idr_remove(&i2c_adapter_idr, adap->nr);
1621 mutex_unlock(&core_lock);
1623 /* Clear the device structure in case this adapter is ever going to be
1625 memset(&adap->dev, 0, sizeof(adap->dev));
1627 EXPORT_SYMBOL(i2c_del_adapter);
1630 * i2c_parse_fw_timings - get I2C related timing parameters from firmware
1631 * @dev: The device to scan for I2C timing properties
1632 * @t: the i2c_timings struct to be filled with values
1633 * @use_defaults: bool to use sane defaults derived from the I2C specification
1634 * when properties are not found, otherwise use 0
1636 * Scan the device for the generic I2C properties describing timing parameters
1637 * for the signal and fill the given struct with the results. If a property was
1638 * not found and use_defaults was true, then maximum timings are assumed which
1639 * are derived from the I2C specification. If use_defaults is not used, the
1640 * results will be 0, so drivers can apply their own defaults later. The latter
1641 * is mainly intended for avoiding regressions of existing drivers which want
1642 * to switch to this function. New drivers almost always should use the defaults.
1645 void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults)
1649 memset(t, 0, sizeof(*t));
1651 ret = device_property_read_u32(dev, "clock-frequency", &t->bus_freq_hz);
1652 if (ret && use_defaults)
1653 t->bus_freq_hz = 100000;
1655 ret = device_property_read_u32(dev, "i2c-scl-rising-time-ns", &t->scl_rise_ns);
1656 if (ret && use_defaults) {
1657 if (t->bus_freq_hz <= 100000)
1658 t->scl_rise_ns = 1000;
1659 else if (t->bus_freq_hz <= 400000)
1660 t->scl_rise_ns = 300;
1662 t->scl_rise_ns = 120;
1665 ret = device_property_read_u32(dev, "i2c-scl-falling-time-ns", &t->scl_fall_ns);
1666 if (ret && use_defaults) {
1667 if (t->bus_freq_hz <= 400000)
1668 t->scl_fall_ns = 300;
1670 t->scl_fall_ns = 120;
1673 device_property_read_u32(dev, "i2c-scl-internal-delay-ns", &t->scl_int_delay_ns);
1675 ret = device_property_read_u32(dev, "i2c-sda-falling-time-ns", &t->sda_fall_ns);
1676 if (ret && use_defaults)
1677 t->sda_fall_ns = t->scl_fall_ns;
1679 device_property_read_u32(dev, "i2c-sda-hold-time-ns", &t->sda_hold_ns);
1681 EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
1683 /* ------------------------------------------------------------------------- */
1685 int i2c_for_each_dev(void *data, int (*fn)(struct device *dev, void *data))
1689 mutex_lock(&core_lock);
1690 res = bus_for_each_dev(&i2c_bus_type, NULL, data, fn);
1691 mutex_unlock(&core_lock);
1695 EXPORT_SYMBOL_GPL(i2c_for_each_dev);
1697 static int __process_new_driver(struct device *dev, void *data)
1699 if (dev->type != &i2c_adapter_type)
1701 return i2c_do_add_adapter(data, to_i2c_adapter(dev));
1705 * An i2c_driver is used with one or more i2c_client (device) nodes to access
1706 * i2c slave chips, on a bus instance associated with some i2c_adapter.
1709 int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
1713 /* Can't register until after driver model init */
1714 if (WARN_ON(!is_registered))
1717 /* add the driver to the list of i2c drivers in the driver core */
1718 driver->driver.owner = owner;
1719 driver->driver.bus = &i2c_bus_type;
1720 INIT_LIST_HEAD(&driver->clients);
1722 /* When registration returns, the driver core
1723 * will have called probe() for all matching-but-unbound devices.
1725 res = driver_register(&driver->driver);
1729 pr_debug("driver [%s] registered\n", driver->driver.name);
1731 /* Walk the adapters that are already present */
1732 i2c_for_each_dev(driver, __process_new_driver);
1736 EXPORT_SYMBOL(i2c_register_driver);
1738 static int __process_removed_driver(struct device *dev, void *data)
1740 if (dev->type == &i2c_adapter_type)
1741 i2c_do_del_adapter(data, to_i2c_adapter(dev));
1746 * i2c_del_driver - unregister I2C driver
1747 * @driver: the driver being unregistered
1748 * Context: can sleep
1750 void i2c_del_driver(struct i2c_driver *driver)
1752 i2c_for_each_dev(driver, __process_removed_driver);
1754 driver_unregister(&driver->driver);
1755 pr_debug("driver [%s] unregistered\n", driver->driver.name);
1757 EXPORT_SYMBOL(i2c_del_driver);
1759 /* ------------------------------------------------------------------------- */
1762 * i2c_use_client - increments the reference count of the i2c client structure
1763 * @client: the client being referenced
1765 * Each live reference to a client should be refcounted. The driver model does
1766 * that automatically as part of driver binding, so that most drivers don't
1767 * need to do this explicitly: they hold a reference until they're unbound
1770 * A pointer to the client with the incremented reference counter is returned.
1772 struct i2c_client *i2c_use_client(struct i2c_client *client)
1774 if (client && get_device(&client->dev))
1778 EXPORT_SYMBOL(i2c_use_client);
1781 * i2c_release_client - release a use of the i2c client structure
1782 * @client: the client being no longer referenced
1784 * Must be called when a user of a client is finished with it.
1786 void i2c_release_client(struct i2c_client *client)
1789 put_device(&client->dev);
1791 EXPORT_SYMBOL(i2c_release_client);
1793 struct i2c_cmd_arg {
1798 static int i2c_cmd(struct device *dev, void *_arg)
1800 struct i2c_client *client = i2c_verify_client(dev);
1801 struct i2c_cmd_arg *arg = _arg;
1802 struct i2c_driver *driver;
1804 if (!client || !client->dev.driver)
1807 driver = to_i2c_driver(client->dev.driver);
1808 if (driver->command)
1809 driver->command(client, arg->cmd, arg->arg);
1813 void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
1815 struct i2c_cmd_arg cmd_arg;
1819 device_for_each_child(&adap->dev, &cmd_arg, i2c_cmd);
1821 EXPORT_SYMBOL(i2c_clients_command);
1823 static int __init i2c_init(void)
1827 retval = of_alias_get_highest_id("i2c");
1829 down_write(&__i2c_board_lock);
1830 if (retval >= __i2c_first_dynamic_bus_num)
1831 __i2c_first_dynamic_bus_num = retval + 1;
1832 up_write(&__i2c_board_lock);
1834 retval = bus_register(&i2c_bus_type);
1838 is_registered = true;
1840 #ifdef CONFIG_I2C_COMPAT
1841 i2c_adapter_compat_class = class_compat_register("i2c-adapter");
1842 if (!i2c_adapter_compat_class) {
1847 retval = i2c_add_driver(&dummy_driver);
1851 if (IS_ENABLED(CONFIG_OF_DYNAMIC))
1852 WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier));
1853 if (IS_ENABLED(CONFIG_ACPI))
1854 WARN_ON(acpi_reconfig_notifier_register(&i2c_acpi_notifier));
1859 #ifdef CONFIG_I2C_COMPAT
1860 class_compat_unregister(i2c_adapter_compat_class);
1863 is_registered = false;
1864 bus_unregister(&i2c_bus_type);
1868 static void __exit i2c_exit(void)
1870 if (IS_ENABLED(CONFIG_ACPI))
1871 WARN_ON(acpi_reconfig_notifier_unregister(&i2c_acpi_notifier));
1872 if (IS_ENABLED(CONFIG_OF_DYNAMIC))
1873 WARN_ON(of_reconfig_notifier_unregister(&i2c_of_notifier));
1874 i2c_del_driver(&dummy_driver);
1875 #ifdef CONFIG_I2C_COMPAT
1876 class_compat_unregister(i2c_adapter_compat_class);
1878 bus_unregister(&i2c_bus_type);
1879 tracepoint_synchronize_unregister();
1882 /* We must initialize early, because some subsystems register i2c drivers
1883 * in subsys_initcall() code, but are linked (and initialized) before i2c.
1885 postcore_initcall(i2c_init);
1886 module_exit(i2c_exit);
1888 /* ----------------------------------------------------
1889 * the functional interface to the i2c busses.
1890 * ----------------------------------------------------
1893 /* Check if val is exceeding the quirk IFF quirk is non 0 */
1894 #define i2c_quirk_exceeded(val, quirk) ((quirk) && ((val) > (quirk)))
1896 static int i2c_quirk_error(struct i2c_adapter *adap, struct i2c_msg *msg, char *err_msg)
1898 dev_err_ratelimited(&adap->dev, "adapter quirk: %s (addr 0x%04x, size %u, %s)\n",
1899 err_msg, msg->addr, msg->len,
1900 msg->flags & I2C_M_RD ? "read" : "write");
1904 static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1906 const struct i2c_adapter_quirks *q = adap->quirks;
1907 int max_num = q->max_num_msgs, i;
1908 bool do_len_check = true;
1910 if (q->flags & I2C_AQ_COMB) {
1913 /* special checks for combined messages */
1915 if (q->flags & I2C_AQ_COMB_WRITE_FIRST && msgs[0].flags & I2C_M_RD)
1916 return i2c_quirk_error(adap, &msgs[0], "1st comb msg must be write");
1918 if (q->flags & I2C_AQ_COMB_READ_SECOND && !(msgs[1].flags & I2C_M_RD))
1919 return i2c_quirk_error(adap, &msgs[1], "2nd comb msg must be read");
1921 if (q->flags & I2C_AQ_COMB_SAME_ADDR && msgs[0].addr != msgs[1].addr)
1922 return i2c_quirk_error(adap, &msgs[0], "comb msg only to same addr");
1924 if (i2c_quirk_exceeded(msgs[0].len, q->max_comb_1st_msg_len))
1925 return i2c_quirk_error(adap, &msgs[0], "msg too long");
1927 if (i2c_quirk_exceeded(msgs[1].len, q->max_comb_2nd_msg_len))
1928 return i2c_quirk_error(adap, &msgs[1], "msg too long");
1930 do_len_check = false;
1934 if (i2c_quirk_exceeded(num, max_num))
1935 return i2c_quirk_error(adap, &msgs[0], "too many messages");
1937 for (i = 0; i < num; i++) {
1938 u16 len = msgs[i].len;
1940 if (msgs[i].flags & I2C_M_RD) {
1941 if (do_len_check && i2c_quirk_exceeded(len, q->max_read_len))
1942 return i2c_quirk_error(adap, &msgs[i], "msg too long");
1944 if (q->flags & I2C_AQ_NO_ZERO_LEN_READ && len == 0)
1945 return i2c_quirk_error(adap, &msgs[i], "no zero length");
1947 if (do_len_check && i2c_quirk_exceeded(len, q->max_write_len))
1948 return i2c_quirk_error(adap, &msgs[i], "msg too long");
1950 if (q->flags & I2C_AQ_NO_ZERO_LEN_WRITE && len == 0)
1951 return i2c_quirk_error(adap, &msgs[i], "no zero length");
1959 * __i2c_transfer - unlocked flavor of i2c_transfer
1960 * @adap: Handle to I2C bus
1961 * @msgs: One or more messages to execute before STOP is issued to
1962 * terminate the operation; each message begins with a START.
1963 * @num: Number of messages to be executed.
1965 * Returns negative errno, else the number of messages executed.
1967 * Adapter lock must be held when calling this function. No debug logging
1968 * takes place. adap->algo->master_xfer existence isn't checked.
1970 int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1972 unsigned long orig_jiffies;
1975 if (WARN_ON(!msgs || num < 1))
1978 ret = __i2c_check_suspended(adap);
1982 if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
1986 * i2c_trace_msg_key gets enabled when tracepoint i2c_transfer gets
1987 * enabled. This is an efficient way of keeping the for-loop from
1988 * being executed when not needed.
1990 if (static_branch_unlikely(&i2c_trace_msg_key)) {
1992 for (i = 0; i < num; i++)
1993 if (msgs[i].flags & I2C_M_RD)
1994 trace_i2c_read(adap, &msgs[i], i);
1996 trace_i2c_write(adap, &msgs[i], i);
1999 /* Retry automatically on arbitration loss */
2000 orig_jiffies = jiffies;
2001 for (ret = 0, try = 0; try <= adap->retries; try++) {
2002 if (i2c_in_atomic_xfer_mode() && adap->algo->master_xfer_atomic)
2003 ret = adap->algo->master_xfer_atomic(adap, msgs, num);
2005 ret = adap->algo->master_xfer(adap, msgs, num);
2009 if (time_after(jiffies, orig_jiffies + adap->timeout))
2013 if (static_branch_unlikely(&i2c_trace_msg_key)) {
2015 for (i = 0; i < ret; i++)
2016 if (msgs[i].flags & I2C_M_RD)
2017 trace_i2c_reply(adap, &msgs[i], i);
2018 trace_i2c_result(adap, num, ret);
2023 EXPORT_SYMBOL(__i2c_transfer);
2026 * i2c_transfer - execute a single or combined I2C message
2027 * @adap: Handle to I2C bus
2028 * @msgs: One or more messages to execute before STOP is issued to
2029 * terminate the operation; each message begins with a START.
2030 * @num: Number of messages to be executed.
2032 * Returns negative errno, else the number of messages executed.
2034 * Note that there is no requirement that each message be sent to
2035 * the same slave address, although that is the most common model.
2037 int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
2041 if (!adap->algo->master_xfer) {
2042 dev_dbg(&adap->dev, "I2C level transfers not supported\n");
2046 /* REVISIT the fault reporting model here is weak:
2048 * - When we get an error after receiving N bytes from a slave,
2049 * there is no way to report "N".
2051 * - When we get a NAK after transmitting N bytes to a slave,
2052 * there is no way to report "N" ... or to let the master
2053 * continue executing the rest of this combined message, if
2054 * that's the appropriate response.
2056 * - When for example "num" is two and we successfully complete
2057 * the first message but get an error part way through the
2058 * second, it's unclear whether that should be reported as
2059 * one (discarding status on the second message) or errno
2060 * (discarding status on the first one).
2062 ret = __i2c_lock_bus_helper(adap);
2066 ret = __i2c_transfer(adap, msgs, num);
2067 i2c_unlock_bus(adap, I2C_LOCK_SEGMENT);
2071 EXPORT_SYMBOL(i2c_transfer);
2074 * i2c_transfer_buffer_flags - issue a single I2C message transferring data
2076 * @client: Handle to slave device
2077 * @buf: Where the data is stored
2078 * @count: How many bytes to transfer, must be less than 64k since msg.len is u16
2079 * @flags: The flags to be used for the message, e.g. I2C_M_RD for reads
2081 * Returns negative errno, or else the number of bytes transferred.
2083 int i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf,
2084 int count, u16 flags)
2087 struct i2c_msg msg = {
2088 .addr = client->addr,
2089 .flags = flags | (client->flags & I2C_M_TEN),
2094 ret = i2c_transfer(client->adapter, &msg, 1);
2097 * If everything went ok (i.e. 1 msg transferred), return #bytes
2098 * transferred, else error code.
2100 return (ret == 1) ? count : ret;
2102 EXPORT_SYMBOL(i2c_transfer_buffer_flags);
2105 * i2c_get_device_id - get manufacturer, part id and die revision of a device
2106 * @client: The device to query
2107 * @id: The queried information
2109 * Returns negative errno on error, zero on success.
2111 int i2c_get_device_id(const struct i2c_client *client,
2112 struct i2c_device_identity *id)
2114 struct i2c_adapter *adap = client->adapter;
2115 union i2c_smbus_data raw_id;
2118 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
2121 raw_id.block[0] = 3;
2122 ret = i2c_smbus_xfer(adap, I2C_ADDR_DEVICE_ID, 0,
2123 I2C_SMBUS_READ, client->addr << 1,
2124 I2C_SMBUS_I2C_BLOCK_DATA, &raw_id);
2128 id->manufacturer_id = (raw_id.block[1] << 4) | (raw_id.block[2] >> 4);
2129 id->part_id = ((raw_id.block[2] & 0xf) << 5) | (raw_id.block[3] >> 3);
2130 id->die_revision = raw_id.block[3] & 0x7;
2133 EXPORT_SYMBOL_GPL(i2c_get_device_id);
2135 /* ----------------------------------------------------
2136 * the i2c address scanning function
2137 * Will not work for 10-bit addresses!
2138 * ----------------------------------------------------
2142 * Legacy default probe function, mostly relevant for SMBus. The default
2143 * probe method is a quick write, but it is known to corrupt the 24RF08
2144 * EEPROMs due to a state machine bug, and could also irreversibly
2145 * write-protect some EEPROMs, so for address ranges 0x30-0x37 and 0x50-0x5f,
2146 * we use a short byte read instead. Also, some bus drivers don't implement
2147 * quick write, so we fallback to a byte read in that case too.
2148 * On x86, there is another special case for FSC hardware monitoring chips,
2149 * which want regular byte reads (address 0x73.) Fortunately, these are the
2150 * only known chips using this I2C address on PC hardware.
2151 * Returns 1 if probe succeeded, 0 if not.
2153 static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr)
2156 union i2c_smbus_data dummy;
2159 if (addr == 0x73 && (adap->class & I2C_CLASS_HWMON)
2160 && i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE_DATA))
2161 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
2162 I2C_SMBUS_BYTE_DATA, &dummy);
2165 if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50)
2166 && i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK))
2167 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0,
2168 I2C_SMBUS_QUICK, NULL);
2169 else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE))
2170 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
2171 I2C_SMBUS_BYTE, &dummy);
2173 dev_warn(&adap->dev, "No suitable probing method supported for address 0x%02X\n",
2181 static int i2c_detect_address(struct i2c_client *temp_client,
2182 struct i2c_driver *driver)
2184 struct i2c_board_info info;
2185 struct i2c_adapter *adapter = temp_client->adapter;
2186 int addr = temp_client->addr;
2189 /* Make sure the address is valid */
2190 err = i2c_check_7bit_addr_validity_strict(addr);
2192 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
2197 /* Skip if already in use (7 bit, no need to encode flags) */
2198 if (i2c_check_addr_busy(adapter, addr))
2201 /* Make sure there is something at this address */
2202 if (!i2c_default_probe(adapter, addr))
2205 /* Finally call the custom detection function */
2206 memset(&info, 0, sizeof(struct i2c_board_info));
2208 err = driver->detect(temp_client, &info);
2210 /* -ENODEV is returned if the detection fails. We catch it
2211 here as this isn't an error. */
2212 return err == -ENODEV ? 0 : err;
2215 /* Consistency check */
2216 if (info.type[0] == '\0') {
2217 dev_err(&adapter->dev,
2218 "%s detection function provided no name for 0x%x\n",
2219 driver->driver.name, addr);
2221 struct i2c_client *client;
2223 /* Detection succeeded, instantiate the device */
2224 if (adapter->class & I2C_CLASS_DEPRECATED)
2225 dev_warn(&adapter->dev,
2226 "This adapter will soon drop class based instantiation of devices. "
2227 "Please make sure client 0x%02x gets instantiated by other means. "
2228 "Check 'Documentation/i2c/instantiating-devices.rst' for details.\n",
2231 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n",
2232 info.type, info.addr);
2233 client = i2c_new_device(adapter, &info);
2235 list_add_tail(&client->detected, &driver->clients);
2237 dev_err(&adapter->dev, "Failed creating %s at 0x%02x\n",
2238 info.type, info.addr);
2243 static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
2245 const unsigned short *address_list;
2246 struct i2c_client *temp_client;
2248 int adap_id = i2c_adapter_id(adapter);
2250 address_list = driver->address_list;
2251 if (!driver->detect || !address_list)
2254 /* Warn that the adapter lost class based instantiation */
2255 if (adapter->class == I2C_CLASS_DEPRECATED) {
2256 dev_dbg(&adapter->dev,
2257 "This adapter dropped support for I2C classes and won't auto-detect %s devices anymore. "
2258 "If you need it, check 'Documentation/i2c/instantiating-devices.rst' for alternatives.\n",
2259 driver->driver.name);
2263 /* Stop here if the classes do not match */
2264 if (!(adapter->class & driver->class))
2267 /* Set up a temporary client to help detect callback */
2268 temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
2271 temp_client->adapter = adapter;
2273 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
2274 dev_dbg(&adapter->dev,
2275 "found normal entry for adapter %d, addr 0x%02x\n",
2276 adap_id, address_list[i]);
2277 temp_client->addr = address_list[i];
2278 err = i2c_detect_address(temp_client, driver);
2287 int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr)
2289 return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
2290 I2C_SMBUS_QUICK, NULL) >= 0;
2292 EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read);
2295 i2c_new_probed_device(struct i2c_adapter *adap,
2296 struct i2c_board_info *info,
2297 unsigned short const *addr_list,
2298 int (*probe)(struct i2c_adapter *adap, unsigned short addr))
2303 probe = i2c_default_probe;
2305 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
2306 /* Check address validity */
2307 if (i2c_check_7bit_addr_validity_strict(addr_list[i]) < 0) {
2308 dev_warn(&adap->dev, "Invalid 7-bit address 0x%02x\n",
2313 /* Check address availability (7 bit, no need to encode flags) */
2314 if (i2c_check_addr_busy(adap, addr_list[i])) {
2316 "Address 0x%02x already in use, not probing\n",
2321 /* Test address responsiveness */
2322 if (probe(adap, addr_list[i]))
2326 if (addr_list[i] == I2C_CLIENT_END) {
2327 dev_dbg(&adap->dev, "Probing failed, no device found\n");
2331 info->addr = addr_list[i];
2332 return i2c_new_device(adap, info);
2334 EXPORT_SYMBOL_GPL(i2c_new_probed_device);
2336 struct i2c_adapter *i2c_get_adapter(int nr)
2338 struct i2c_adapter *adapter;
2340 mutex_lock(&core_lock);
2341 adapter = idr_find(&i2c_adapter_idr, nr);
2345 if (try_module_get(adapter->owner))
2346 get_device(&adapter->dev);
2351 mutex_unlock(&core_lock);
2354 EXPORT_SYMBOL(i2c_get_adapter);
2356 void i2c_put_adapter(struct i2c_adapter *adap)
2361 module_put(adap->owner);
2362 /* Should be last, otherwise we risk use-after-free with 'adap' */
2363 put_device(&adap->dev);
2365 EXPORT_SYMBOL(i2c_put_adapter);
2368 * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg
2369 * @msg: the message to be checked
2370 * @threshold: the minimum number of bytes for which using DMA makes sense.
2371 * Should at least be 1.
2373 * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO.
2374 * Or a valid pointer to be used with DMA. After use, release it by
2375 * calling i2c_put_dma_safe_msg_buf().
2377 * This function must only be called from process context!
2379 u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
2381 /* also skip 0-length msgs for bogus thresholds of 0 */
2383 pr_debug("DMA buffer for addr=0x%02x with length 0 is bogus\n",
2385 if (msg->len < threshold || msg->len == 0)
2388 if (msg->flags & I2C_M_DMA_SAFE)
2391 pr_debug("using bounce buffer for addr=0x%02x, len=%d\n",
2392 msg->addr, msg->len);
2394 if (msg->flags & I2C_M_RD)
2395 return kzalloc(msg->len, GFP_KERNEL);
2397 return kmemdup(msg->buf, msg->len, GFP_KERNEL);
2399 EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf);
2402 * i2c_put_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg
2403 * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL.
2404 * @msg: the message which the buffer corresponds to
2405 * @xferred: bool saying if the message was transferred
2407 void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred)
2409 if (!buf || buf == msg->buf)
2412 if (xferred && msg->flags & I2C_M_RD)
2413 memcpy(msg->buf, buf, msg->len);
2417 EXPORT_SYMBOL_GPL(i2c_put_dma_safe_msg_buf);
2419 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
2420 MODULE_DESCRIPTION("I2C-Bus main module");
2421 MODULE_LICENSE("GPL");