cregit-Linux how code gets into the kernel

Release 4.14 drivers/i2c/i2c-core-base.c

Directory: drivers/i2c
/*
 * Linux I2C core
 *
 * Copyright (C) 1995-99 Simon G. Vogl
 *   With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>
 *   Mux support by Rodolfo Giometti <giometti@enneenne.com> and
 *   Michael Lawnick <michael.lawnick.ext@nsn.com>
 *
 * Copyright (C) 2013-2017 Wolfram Sang <wsa@the-dreams.de>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 */


#define pr_fmt(fmt) "i2c-core: " fmt

#include <dt-bindings/i2c/i2c.h>
#include <linux/acpi.h>
#include <linux/clk/clk-conf.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/idr.h>
#include <linux/init.h>
#include <linux/irqflags.h>
#include <linux/jump_label.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of_device.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
#include <linux/pm_wakeirq.h>
#include <linux/property.h>
#include <linux/rwsem.h>
#include <linux/slab.h>

#include "i2c-core.h"


#define CREATE_TRACE_POINTS
#include <trace/events/i2c.h>


#define I2C_ADDR_OFFSET_TEN_BIT	0xa000

#define I2C_ADDR_OFFSET_SLAVE	0x1000


#define I2C_ADDR_7BITS_MAX	0x77

#define I2C_ADDR_7BITS_COUNT	(I2C_ADDR_7BITS_MAX + 1)

/*
 * core_lock protects i2c_adapter_idr, and guarantees that device detection,
 * deletion of detected devices, and attach_adapter calls are serialized
 */
static DEFINE_MUTEX(core_lock);
static DEFINE_IDR(i2c_adapter_idr);

static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);


static struct static_key i2c_trace_msg = STATIC_KEY_INIT_FALSE;

static bool is_registered;


int i2c_transfer_trace_reg(void) { static_key_slow_inc(&i2c_trace_msg); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David Howells1275.00%150.00%
Steven Rostedt425.00%150.00%
Total16100.00%2100.00%


void i2c_transfer_trace_unreg(void) { static_key_slow_dec(&i2c_trace_msg); }

Contributors

PersonTokensPropCommitsCommitProp
David Howells13100.00%1100.00%
Total13100.00%1100.00%


const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, const struct i2c_client *client) { if (!(id && client)) return NULL; while (id->name[0]) { if (strcmp(client->name, id->name) == 0) return id; id++; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare5582.09%150.00%
Lee Jones1217.91%150.00%
Total67100.00%2100.00%

EXPORT_SYMBOL_GPL(i2c_match_id);
static int i2c_device_match(struct device *dev, struct device_driver *drv) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; /* Attempt an OF style match */ if (i2c_of_match_device(drv->of_match_table, client)) return 1; /* Then ACPI style match */ if (acpi_driver_match_device(dev, drv)) return 1; driver = to_i2c_driver(drv); /* Finally an I2C match */ if (i2c_match_id(driver->id_table, client)) return 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar4148.81%114.29%
Adrian Bunk1517.86%114.29%
David Brownell1315.48%114.29%
Lee Jones910.71%228.57%
Grant C. Likely44.76%114.29%
Jean Delvare22.38%114.29%
Total84100.00%7100.00%


static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) { struct i2c_client *client = to_i2c_client(dev); int rc; rc = acpi_device_uevent_modalias(dev, env); if (rc != -ENODEV) return rc; return add_uevent_var(env, "MODALIAS=%s%s", I2C_MODULE_PREFIX, client->name); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar3962.90%133.33%
Rui Zhang2235.48%133.33%
Wolfram Sang11.61%133.33%
Total62100.00%3100.00%

/* i2c bus recovery routines */
static int get_scl_gpio_value(struct i2c_adapter *adap) { return gpio_get_value(adap->bus_recovery_info->scl_gpio); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar21100.00%1100.00%
Total21100.00%1100.00%


static void set_scl_gpio_value(struct i2c_adapter *adap, int val) { gpio_set_value(adap->bus_recovery_info->scl_gpio, val); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar25100.00%1100.00%
Total25100.00%1100.00%


static int get_sda_gpio_value(struct i2c_adapter *adap) { return gpio_get_value(adap->bus_recovery_info->sda_gpio); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar21100.00%1100.00%
Total21100.00%1100.00%


static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap) { struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; struct device *dev = &adap->dev; int ret = 0; ret = gpio_request_one(bri->scl_gpio, GPIOF_OPEN_DRAIN | GPIOF_OUT_INIT_HIGH, "i2c-scl"); if (ret) { dev_warn(dev, "Can't get SCL gpio: %d\n", bri->scl_gpio); return ret; } if (bri->get_sda) { if (gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda")) { /* work without SDA polling */ dev_warn(dev, "Can't get SDA gpio: %d. Not using SDA polling\n", bri->sda_gpio); bri->get_sda = NULL; } } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar114100.00%1100.00%
Total114100.00%1100.00%


static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap) { struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; if (bri->get_sda) gpio_free(bri->sda_gpio); gpio_free(bri->scl_gpio); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar40100.00%1100.00%
Total40100.00%1100.00%

/* * We are generating clock pulses. ndelay() determines durating of clk pulses. * We will generate clock with rate 100 KHz and so duration of both clock levels * is: delay in ns = (10^6 / 100) / 2 */ #define RECOVERY_NDELAY 5000 #define RECOVERY_CLK_CNT 9
static int i2c_generic_recovery(struct i2c_adapter *adap) { struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; int i = 0, val = 1, ret = 0; if (bri->prepare_recovery) bri->prepare_recovery(adap); bri->set_scl(adap, val); ndelay(RECOVERY_NDELAY); /* * By this time SCL is high, as we need to give 9 falling-rising edges */ while (i++ < RECOVERY_CLK_CNT * 2) { if (val) { /* Break if SDA is high */ if (bri->get_sda && bri->get_sda(adap)) break; /* SCL shouldn't be low here */ if (!bri->get_scl(adap)) { dev_err(&adap->dev, "SCL is stuck low, exit recovery\n"); ret = -EBUSY; break; } } val = !val; bri->set_scl(adap, val); ndelay(RECOVERY_NDELAY); } if (bri->unprepare_recovery) bri->unprepare_recovery(adap); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar14189.81%133.33%
Jan Lübbe148.92%133.33%
Grygorii Strashko21.27%133.33%
Total157100.00%3100.00%


int i2c_generic_scl_recovery(struct i2c_adapter *adap) { return i2c_generic_recovery(adap); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar1275.00%133.33%
Mika Westerberg318.75%133.33%
Grant C. Likely16.25%133.33%
Total16100.00%3100.00%

EXPORT_SYMBOL_GPL(i2c_generic_scl_recovery);
int i2c_generic_gpio_recovery(struct i2c_adapter *adap) { int ret; ret = i2c_get_gpios_for_recovery(adap); if (ret) return ret; ret = i2c_generic_recovery(adap); i2c_put_gpios_for_recovery(adap); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar2969.05%125.00%
Jean Delvare819.05%250.00%
David Brownell511.90%125.00%
Total42100.00%4100.00%

EXPORT_SYMBOL_GPL(i2c_generic_gpio_recovery);
int i2c_recover_bus(struct i2c_adapter *adap) { if (!adap->bus_recovery_info) return -EOPNOTSUPP; dev_dbg(&adap->dev, "Trying i2c bus recovery\n"); return adap->bus_recovery_info->recover_bus(adap); }

Contributors

PersonTokensPropCommitsCommitProp
Viresh Kumar1946.34%125.00%
David Brownell1536.59%125.00%
Jean Delvare512.20%125.00%
Adrian Bunk24.88%125.00%
Total41100.00%4100.00%

EXPORT_SYMBOL_GPL(i2c_recover_bus);
static void i2c_init_recovery(struct i2c_adapter *adap) { struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; char *err_str; if (!bri) return; if (!bri->recover_bus) { err_str = "no recover_bus() found"; goto err; } /* Generic GPIO recovery */ if (bri->recover_bus == i2c_generic_gpio_recovery) { if (!gpio_is_valid(bri->scl_gpio)) { err_str = "invalid SCL gpio"; goto err; } if (gpio_is_valid(bri->sda_gpio)) bri->get_sda = get_sda_gpio_value; else bri->get_sda = NULL; bri->get_scl = get_scl_gpio_value; bri->set_scl = set_scl_gpio_value; } else if (bri->recover_bus == i2c_generic_scl_recovery) { /* Generic SCL recovery */ if (!bri->set_scl || !bri->get_scl) { err_str = "no {get|set}_scl() found"; goto err; } } return; err: dev_err(&adap->dev, "Not using recovery: %s\n", err_str); adap->bus_recovery_info = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Wolfram Sang164100.00%1100.00%
Total164100.00%1100.00%


static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client) { struct i2c_adapter *adap = client->adapter; unsigned int irq; if (!adap->host_notify_domain) return -ENXIO; if (client->flags & I2C_CLIENT_TEN) return -EINVAL; irq = irq_find_mapping(adap->host_notify_domain, client->addr); if (!irq) irq = irq_create_mapping(adap->host_notify_domain, client->addr); return irq > 0 ? irq : -ENXIO; }

Contributors

PersonTokensPropCommitsCommitProp
Benjamin Tissoires89100.00%1100.00%
Total89100.00%1100.00%


static int i2c_device_probe(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; int status; if (!client) return 0; driver = to_i2c_driver(dev->driver); if (!client->irq && !driver->disable_i2c_core_irq_mapping) { int irq = -ENOENT; if (client->flags & I2C_CLIENT_HOST_NOTIFY) { dev_dbg(dev, "Using Host Notify IRQ\n"); irq = i2c_smbus_host_notify_to_irq(client); } else if (dev->of_node) { irq = of_irq_get_byname(dev->of_node, "irq"); if (irq == -EINVAL || irq == -ENODATA) irq = of_irq_get(dev->of_node, 0); } else if (ACPI_COMPANION(dev)) { irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0); } if (irq == -EPROBE_DEFER) return irq; if (irq < 0) irq = 0; client->irq = irq; } /* * An I2C ID table is not mandatory, if and only if, a suitable OF * or ACPI ID table is supplied for the probing device. */ if (!driver->id_table && !i2c_acpi_match_device(dev->driver->acpi_match_table, client) && !i2c_of_match_device(dev->driver->of_match_table, client)) return -ENODEV; if (client->flags & I2C_CLIENT_WAKE) { int wakeirq = -ENOENT; if (dev->of_node) { wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); if (wakeirq == -EPROBE_DEFER) return wakeirq; } device_init_wakeup(&client->dev, true); if (wakeirq > 0 && wakeirq != client->irq) status = dev_pm_set_dedicated_wake_irq(dev, wakeirq); else if (client->irq > 0) status = dev_pm_set_wake_irq(dev, client->irq); else status = 0; if (status) dev_warn(&client->dev, "failed to set up wakeup irq\n"); } dev_dbg(dev, "probe\n"); status = of_clk_set_defaults(dev->of_node, false); if (status < 0) goto err_clear_wakeup_irq; status = dev_pm_domain_attach(&client->dev, true); if (status == -EPROBE_DEFER) goto err_clear_wakeup_irq; /* * When there are no more users of probe(), * rename probe_new to probe. */ if (driver->probe_new) status = driver->probe_new(client); else if (driver->probe) status = driver->probe(client, i2c_match_id(driver->id_table, client)); else status = -EINVAL; if (status) goto err_detach_pm_domain; return 0; err_detach_pm_domain: dev_pm_domain_detach(&client->dev, true); err_clear_wakeup_irq: dev_pm_clear_wake_irq(&client->dev); device_init_wakeup(&client->dev, false); return status; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov17537.00%28.33%
Lee Jones439.09%28.33%
Jean Delvare336.98%312.50%
Laurent Pinchart336.98%14.17%
Mika Westerberg326.77%14.17%
David Brownell296.13%28.33%
Marc Pignat194.02%14.17%
Lv Zheng183.81%14.17%
Sylwester Nawrocki173.59%14.17%
Hans de Goede142.96%14.17%
Andy Shevchenko132.75%28.33%
Geert Uytterhoeven132.75%14.17%
Ulf Hansson102.11%14.17%
Adrian Bunk91.90%14.17%
Hans Verkuil71.48%14.17%
Kieran Bingham40.85%14.17%
Grygorii Strashko30.63%14.17%
Javier Martinez Canillas10.21%14.17%
Total473100.00%24100.00%


static int i2c_device_remove(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; int status = 0; if (!client || !dev->driver) return 0; driver = to_i2c_driver(dev->driver); if (driver->remove) { dev_dbg(dev, "remove\n"); status = driver->remove(client); } dev_pm_domain_detach(&client->dev, true); dev_pm_clear_wake_irq(&client->dev); device_init_wakeup(&client->dev, false); return status; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell7266.67%225.00%
Dmitry Torokhov1816.67%112.50%
Lv Zheng98.33%112.50%
Jean Delvare43.70%112.50%
Wolfram Sang21.85%112.50%
Adrian Bunk21.85%112.50%
Ulf Hansson10.93%112.50%
Total108100.00%8100.00%


static void i2c_device_shutdown(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; if (!client || !dev->driver) return; driver = to_i2c_driver(dev->driver); if (driver->shutdown) driver->shutdown(client); }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell2949.15%120.00%
Jean Delvare1423.73%120.00%
Adrian Bunk1322.03%120.00%
Mark Brown23.39%120.00%
Greg Kroah-Hartman11.69%120.00%
Total59100.00%5100.00%


static void i2c_client_dev_release(struct device *dev) { kfree(to_i2c_client(dev)); }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell19100.00%1100.00%
Total19100.00%1100.00%


static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%s\n", dev->type == &i2c_client_type ? to_i2c_client(dev)->name : to_i2c_adapter(dev)->name); }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell3061.22%150.00%
Jean Delvare1938.78%150.00%
Total49100.00%2100.00%

static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) { struct i2c_client *client = to_i2c_client(dev); int len; len = acpi_device_modalias(dev, buf, PAGE_SIZE -1); if (len != -ENODEV) return len; return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell3245.71%133.33%
Rui Zhang2637.14%133.33%
Jean Delvare1217.14%133.33%
Total70100.00%3100.00%

static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); static struct attribute *i2c_dev_attrs[] = { &dev_attr_name.attr, /* modalias helps coldplug: modprobe $(cat .../modalias) */ &dev_attr_modalias.attr, NULL }; ATTRIBUTE_GROUPS(i2c_dev); struct bus_type i2c_bus_type = { .name = "i2c", .match = i2c_device_match, .probe = i2c_device_probe, .remove = i2c_device_remove, .shutdown = i2c_device_shutdown, }; EXPORT_SYMBOL_GPL(i2c_bus_type); struct device_type i2c_client_type = { .groups = i2c_dev_groups, .uevent = i2c_device_uevent, .release = i2c_client_dev_release, }; EXPORT_SYMBOL_GPL(i2c_client_type); /** * i2c_verify_client - return parameter as i2c_client, or NULL * @dev: device, probably from some driver model iterator * * When traversing the driver model tree, perhaps using driver model * iterators like @device_for_each_child(), you can't assume very much * about the nodes you find. Use this function to avoid oopses caused * by wrongly treating some non-I2C device as an i2c_client. */
struct i2c_client *i2c_verify_client(struct device *dev) { return (dev->type == &i2c_client_type) ? to_i2c_client(dev) : NULL; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell2793.10%150.00%
Jean Delvare26.90%150.00%
Total29100.00%2100.00%

EXPORT_SYMBOL(i2c_verify_client); /* Return a unique address which takes the flags of the client into account */
static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client) { unsigned short addr = client->addr; /* For some client flags, add an arbitrary offset to avoid collisions */ if (client->flags & I2C_CLIENT_TEN) addr |= I2C_ADDR_OFFSET_TEN_BIT; if (client->flags & I2C_CLIENT_SLAVE) addr |= I2C_ADDR_OFFSET_SLAVE; return addr; }

Contributors

PersonTokensPropCommitsCommitProp
Wolfram Sang48100.00%1100.00%
Total48100.00%1100.00%

/* This is a permissive address validity check, I2C address map constraints * are purposely not enforced, except for the general call address. */
int i2c_check_addr_validity(unsigned addr, unsigned short flags) { if (flags & I2C_CLIENT_TEN) { /* 10-bit address, all values are valid */ if (addr > 0x3ff) return -EINVAL; } else { /* 7-bit address, reject the general call address */ if (addr == 0x00 || addr > 0x7f) return -EINVAL; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare4586.54%133.33%
Wolfram Sang713.46%266.67%
Total52100.00%3100.00%

/* And this is a strict address validity check, used when probing. If a * device uses a reserved address, then it shouldn't be probed. 7-bit * addressing is assumed, 10-bit address devices are rare and should be * explicitly enumerated. */
int i2c_check_7bit_addr_validity_strict(unsigned short addr) { /* * Reserved addresses per I2C specification: * 0x00 General call address / START byte * 0x01 CBUS address * 0x02 Reserved for different bus format * 0x03 Reserved for future purposes * 0x04-0x07 Hs-mode master code * 0x78-0x7b 10-bit slave addressing * 0x7c-0x7f Reserved for future purposes */ if (addr < 0x08 || addr > 0x77) return -EINVAL; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare2696.30%150.00%
Wolfram Sang13.70%150.00%
Total27100.00%2100.00%


static int __i2c_check_addr_busy(struct device *dev, void *addrp) { struct i2c_client *client = i2c_verify_client(dev); int addr = *(int *)addrp; if (client && i2c_encode_flags_to_addr(client) == addr) return -EBUSY; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare5094.34%150.00%
Wolfram Sang35.66%150.00%
Total53100.00%2100.00%

/* walk up mux tree */
static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) { struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); int result; result = device_for_each_child(&adapter->dev, &addr, __i2c_check_addr_busy); if (!result && parent) result = i2c_check_mux_parents(parent, addr); return result; }

Contributors

PersonTokensPropCommitsCommitProp
Michael Lawnick5081.97%150.00%
Jean Delvare1118.03%150.00%
Total61100.00%2100.00%

/* recurse down mux tree */
static int i2c_check_mux_children(struct device *dev, void *addrp) { int result; if (dev->type == &i2c_adapter_type) result = device_for_each_child(dev, addrp, i2c_check_mux_children); else result = __i2c_check_addr_busy(dev, addrp); return result; }

Contributors

PersonTokensPropCommitsCommitProp
Michael Lawnick51100.00%1100.00%
Total51100.00%1100.00%


static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) { struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); int result = 0; if (parent) result = i2c_check_mux_parents(parent, addr); if (!result) result = device_for_each_child(&adapter->dev, &addr, i2c_check_mux_children); return result; }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare3756.92%266.67%
Michael Lawnick2843.08%133.33%
Total65100.00%3100.00%

/** * i2c_adapter_lock_bus - Get exclusive access to an I2C bus segment * @adapter: Target I2C bus segment * @flags: I2C_LOCK_ROOT_ADAPTER locks the root i2c adapter, I2C_LOCK_SEGMENT * locks only this branch in the adapter tree */
static void i2c_adapter_lock_bus(struct i2c_adapter *adapter, unsigned int flags) { rt_mutex_lock(&adapter->bus_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare1773.91%150.00%
Peter Rosin626.09%150.00%
Total23100.00%2100.00%

/** * i2c_adapter_trylock_bus - Try to get exclusive access to an I2C bus segment * @adapter: Target I2C bus segment * @flags: I2C_LOCK_ROOT_ADAPTER trylocks the root i2c adapter, I2C_LOCK_SEGMENT * trylocks only this branch in the adapter tree */
static int i2c_adapter_trylock_bus(struct i2c_adapter *adapter, unsigned int flags) { return rt_mutex_trylock(&adapter->bus_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare1979.17%150.00%
Peter Rosin520.83%150.00%
Total24100.00%2100.00%

/** * i2c_adapter_unlock_bus - Release exclusive access to an I2C bus segment * @adapter: Target I2C bus segment * @flags: I2C_LOCK_ROOT_ADAPTER unlocks the root i2c adapter, I2C_LOCK_SEGMENT * unlocks only this branch in the adapter tree */
static void i2c_adapter_unlock_bus(struct i2c_adapter *adapter, unsigned int flags) { rt_mutex_unlock(&adapter->bus_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jean Delvare1773.91%150.00%
Peter Rosin626.09%150.00%
Total23100.00%2100.00%


static void i2c_dev_set_name(struct i2c_adapter *adap, struct i2c_client *client) { struct acpi_device *adev = ACPI_COMPANION(&client->dev); if (adev) { dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev)); return; } dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), i2c_encode_flags_to_addr(client)); }

Contributors

PersonTokensPropCommitsCommitProp
Jarkko Nikula6895.77%150.00%
Wolfram Sang34.23%150.00%
Total71100.00%2100.00%


static int i2c_dev_irq_from_resources(const struct resource *resources, unsigned int num_resources) { struct irq_data *irqd; int i; for (i = 0; i < num_resources; i++) { const struct resource *r = &resources[i]; if (resource_type(r) != IORESOURCE_IRQ) continue; if (r->flags & IORESOURCE_BITS) { irqd = irq_get_irq_data(r->start); if (!irqd) break; irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS); } return r->start; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov105100.00%1100.00%
Total105100.00%1100.00%

/** * i2c_new_device - instantiate an i2c device * @adap: the adapter managing the device * @info: describes one I2C device; bus_num is ignored * Context: can sleep * * Create an i2c device. Binding is handled through driver model * probe()/remove() methods. A driver may be bound to this device when we * return from this function, or any later moment (e.g. maybe hotplugging will * load the driver module). This call is not appropriate for use by mainboard * initialization logic, which usually runs during an arch_initcall() long * before any i2c_adapter could exist. * * This returns the new i2c client, which may be saved for later use with * i2c_unregister_device(); or NULL to indicate an error. */
struct i2c_client * i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) { struct i2c_client *client; int status; client = kzalloc(sizeof *client, GFP_KERNEL); if (!client) return NULL; client->adapter = adap; client->dev.platform_data = info->platform_data; if (info->archdata) client->dev.archdata = *info->archdata; client->flags = info->flags; client->addr = info->addr; client->irq = info->irq; if (!client->irq) client->irq = i2c_dev_irq_from_resources(info->resources, info->num_resources); strlcpy(client->name, info->type, sizeof(client->name)); status = i2c_check_addr_validity(client->addr, client->flags); if (status) { dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n", client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr); goto out_err_silent; } /* Check for address business */ status = i2c_check_addr_busy(adap, i2c_encode_flags_to_addr(client)); if (status) goto out_err; client->dev.parent = &client->adapter->dev; client->dev.bus = &i2c_bus_type; client->dev.type = &i2c_client_type; client->dev.of_node = info->of_node; client->dev.fwnode = info->fwnode;