Commit d2653e92 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare
Browse files

i2c: Add support for device alias names


Based on earlier work by Jon Smirl and Jochen Friedrich.

This patch allows new-style i2c chip drivers to have alias names using
the official kernel aliasing system and MODULE_DEVICE_TABLE(). At this
point, the old i2c driver binding scheme (driver_name/type) is still
supported.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: Jochen Friedrich <jochen@scram.de>
Cc: Jon Smirl <jonsmirl@gmail.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
parent ee56d977
...@@ -164,7 +164,8 @@ I2C device drivers using this binding model work just like any other ...@@ -164,7 +164,8 @@ I2C device drivers using this binding model work just like any other
kind of driver in Linux: they provide a probe() method to bind to kind of driver in Linux: they provide a probe() method to bind to
those devices, and a remove() method to unbind. those devices, and a remove() method to unbind.
static int foo_probe(struct i2c_client *client); static int foo_probe(struct i2c_client *client,
const struct i2c_device_id *id);
static int foo_remove(struct i2c_client *client); static int foo_remove(struct i2c_client *client);
Remember that the i2c_driver does not create those client handles. The Remember that the i2c_driver does not create those client handles. The
......
...@@ -192,7 +192,8 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) ...@@ -192,7 +192,8 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
gc->owner = THIS_MODULE; gc->owner = THIS_MODULE;
} }
static int __devinit pca953x_probe(struct i2c_client *client) static int __devinit pca953x_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{ {
struct pca953x_platform_data *pdata; struct pca953x_platform_data *pdata;
struct pca953x_chip *chip; struct pca953x_chip *chip;
......
...@@ -142,7 +142,8 @@ static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value) ...@@ -142,7 +142,8 @@ static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static int pcf857x_probe(struct i2c_client *client) static int pcf857x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct pcf857x_platform_data *pdata; struct pcf857x_platform_data *pdata;
struct pcf857x *gpio; struct pcf857x *gpio;
......
...@@ -117,7 +117,8 @@ struct f75375_data { ...@@ -117,7 +117,8 @@ struct f75375_data {
static int f75375_attach_adapter(struct i2c_adapter *adapter); static int f75375_attach_adapter(struct i2c_adapter *adapter);
static int f75375_detect(struct i2c_adapter *adapter, int address, int kind); static int f75375_detect(struct i2c_adapter *adapter, int address, int kind);
static int f75375_detach_client(struct i2c_client *client); static int f75375_detach_client(struct i2c_client *client);
static int f75375_probe(struct i2c_client *client); static int f75375_probe(struct i2c_client *client,
const struct i2c_device_id *id);
static int f75375_remove(struct i2c_client *client); static int f75375_remove(struct i2c_client *client);
static struct i2c_driver f75375_legacy_driver = { static struct i2c_driver f75375_legacy_driver = {
...@@ -628,7 +629,8 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data, ...@@ -628,7 +629,8 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data,
} }
static int f75375_probe(struct i2c_client *client) static int f75375_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct f75375_data *data = i2c_get_clientdata(client); struct f75375_data *data = i2c_get_clientdata(client);
struct f75375s_platform_data *f75375s_pdata = client->dev.platform_data; struct f75375s_platform_data *f75375s_pdata = client->dev.platform_data;
...@@ -748,7 +750,7 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -748,7 +750,7 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind)
if ((err = i2c_attach_client(client))) if ((err = i2c_attach_client(client)))
goto exit_free; goto exit_free;
if ((err = f75375_probe(client)) < 0) if ((err = f75375_probe(client, NULL)) < 0)
goto exit_detach; goto exit_detach;
return 0; return 0;
......
...@@ -200,7 +200,8 @@ static struct bin_attribute ds1682_eeprom_attr = { ...@@ -200,7 +200,8 @@ static struct bin_attribute ds1682_eeprom_attr = {
/* /*
* Called when a ds1682 device is matched with this driver * Called when a ds1682 device is matched with this driver
*/ */
static int ds1682_probe(struct i2c_client *client) static int ds1682_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
int rc; int rc;
......
...@@ -1149,7 +1149,8 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m) ...@@ -1149,7 +1149,8 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m)
static struct i2c_driver menelaus_i2c_driver; static struct i2c_driver menelaus_i2c_driver;
static int menelaus_probe(struct i2c_client *client) static int menelaus_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct menelaus_chip *menelaus; struct menelaus_chip *menelaus;
int rev = 0, val; int rev = 0, val;
......
...@@ -532,7 +532,8 @@ static int __exit tps65010_remove(struct i2c_client *client) ...@@ -532,7 +532,8 @@ static int __exit tps65010_remove(struct i2c_client *client)
return 0; return 0;
} }
static int tps65010_probe(struct i2c_client *client) static int tps65010_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct tps65010 *tps; struct tps65010 *tps;
int status; int status;
......
...@@ -364,7 +364,8 @@ static int tsl2550_init_client(struct i2c_client *client) ...@@ -364,7 +364,8 @@ static int tsl2550_init_client(struct i2c_client *client)
*/ */
static struct i2c_driver tsl2550_driver; static struct i2c_driver tsl2550_driver;
static int __devinit tsl2550_probe(struct i2c_client *client) static int __devinit tsl2550_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct tsl2550_data *data; struct tsl2550_data *data;
......
...@@ -48,6 +48,17 @@ static DEFINE_IDR(i2c_adapter_idr); ...@@ -48,6 +48,17 @@ static DEFINE_IDR(i2c_adapter_idr);
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client)
{
while (id->name[0]) {
if (strcmp(client->name, id->name) == 0)
return id;
id++;
}
return NULL;
}
static int i2c_device_match(struct device *dev, struct device_driver *drv) static int i2c_device_match(struct device *dev, struct device_driver *drv)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
...@@ -59,6 +70,10 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv) ...@@ -59,6 +70,10 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
if (!is_newstyle_driver(driver)) if (!is_newstyle_driver(driver))
return 0; return 0;
/* match on an id table if there is one */
if (driver->id_table)
return i2c_match_id(driver->id_table, client) != NULL;
/* new style drivers use the same kind of driver matching policy /* new style drivers use the same kind of driver matching policy
* as platform devices or SPI: compare device and driver IDs. * as platform devices or SPI: compare device and driver IDs.
*/ */
...@@ -73,11 +88,17 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) ...@@ -73,11 +88,17 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
/* by definition, legacy drivers can't hotplug */ /* by definition, legacy drivers can't hotplug */
if (dev->driver || !client->driver_name) if (dev->driver)
return 0; return 0;
if (add_uevent_var(env, "MODALIAS=%s", client->driver_name)) if (client->driver_name[0]) {
return -ENOMEM; if (add_uevent_var(env, "MODALIAS=%s", client->driver_name))
return -ENOMEM;
} else {
if (add_uevent_var(env, "MODALIAS=%s%s",
I2C_MODULE_PREFIX, client->name))
return -ENOMEM;
}
dev_dbg(dev, "uevent\n"); dev_dbg(dev, "uevent\n");
return 0; return 0;
} }
...@@ -90,13 +111,19 @@ static int i2c_device_probe(struct device *dev) ...@@ -90,13 +111,19 @@ static int i2c_device_probe(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct i2c_driver *driver = to_i2c_driver(dev->driver); struct i2c_driver *driver = to_i2c_driver(dev->driver);
const struct i2c_device_id *id;
int status; int status;
if (!driver->probe) if (!driver->probe)
return -ENODEV; return -ENODEV;
client->driver = driver; client->driver = driver;
dev_dbg(dev, "probe\n"); dev_dbg(dev, "probe\n");
status = driver->probe(client);
if (driver->id_table)
id = i2c_match_id(driver->id_table, client);
else
id = NULL;
status = driver->probe(client, id);
if (status) if (status)
client->driver = NULL; client->driver = NULL;
return status; return status;
...@@ -179,9 +206,9 @@ static ssize_t show_client_name(struct device *dev, struct device_attribute *att ...@@ -179,9 +206,9 @@ static ssize_t show_client_name(struct device *dev, struct device_attribute *att
static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
return client->driver_name return client->driver_name[0]
? sprintf(buf, "%s\n", client->driver_name) ? sprintf(buf, "%s\n", client->driver_name)
: 0; : sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
} }
static struct device_attribute i2c_dev_attrs[] = { static struct device_attribute i2c_dev_attrs[] = {
...@@ -300,15 +327,21 @@ void i2c_unregister_device(struct i2c_client *client) ...@@ -300,15 +327,21 @@ void i2c_unregister_device(struct i2c_client *client)
EXPORT_SYMBOL_GPL(i2c_unregister_device); EXPORT_SYMBOL_GPL(i2c_unregister_device);
static int dummy_nop(struct i2c_client *client) static int dummy_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
return 0;
}
static int dummy_remove(struct i2c_client *client)
{ {
return 0; return 0;
} }
static struct i2c_driver dummy_driver = { static struct i2c_driver dummy_driver = {
.driver.name = "dummy", .driver.name = "dummy",
.probe = dummy_nop, .probe = dummy_probe,
.remove = dummy_nop, .remove = dummy_remove,
}; };
/** /**
......
...@@ -142,7 +142,8 @@ static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg) ...@@ -142,7 +142,8 @@ static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int cs5345_probe(struct i2c_client *client) static int cs5345_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
/* Check if the adapter supports the needed features */ /* Check if the adapter supports the needed features */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
......
...@@ -135,7 +135,8 @@ static int cs53l32a_command(struct i2c_client *client, unsigned cmd, void *arg) ...@@ -135,7 +135,8 @@ static int cs53l32a_command(struct i2c_client *client, unsigned cmd, void *arg)
* concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
*/ */
static int cs53l32a_probe(struct i2c_client *client) static int cs53l32a_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
int i; int i;
......
...@@ -1209,7 +1209,8 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd, ...@@ -1209,7 +1209,8 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int cx25840_probe(struct i2c_client *client) static int cx25840_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{ {
struct cx25840_state *state; struct cx25840_state *state;
u32 id; u32 id;
......
...@@ -126,7 +126,8 @@ static int m52790_command(struct i2c_client *client, unsigned int cmd, ...@@ -126,7 +126,8 @@ static int m52790_command(struct i2c_client *client, unsigned int cmd,
/* i2c implementation */ /* i2c implementation */
static int m52790_probe(struct i2c_client *client) static int m52790_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct m52790_state *state; struct m52790_state *state;
......
...@@ -805,7 +805,7 @@ static int msp_resume(struct i2c_client *client) ...@@ -805,7 +805,7 @@ static int msp_resume(struct i2c_client *client)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int msp_probe(struct i2c_client *client) static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
{ {
struct msp_state *state; struct msp_state *state;
int (*thread_func)(void *data) = NULL; int (*thread_func)(void *data) = NULL;
......
...@@ -620,7 +620,8 @@ static void mt9m001_video_remove(struct soc_camera_device *icd) ...@@ -620,7 +620,8 @@ static void mt9m001_video_remove(struct soc_camera_device *icd)
soc_camera_video_stop(&mt9m001->icd); soc_camera_video_stop(&mt9m001->icd);
} }
static int mt9m001_probe(struct i2c_client *client) static int mt9m001_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{ {
struct mt9m001 *mt9m001; struct mt9m001 *mt9m001;
struct soc_camera_device *icd; struct soc_camera_device *icd;
......
...@@ -745,7 +745,8 @@ static void mt9v022_video_remove(struct soc_camera_device *icd) ...@@ -745,7 +745,8 @@ static void mt9v022_video_remove(struct soc_camera_device *icd)
soc_camera_video_stop(&mt9v022->icd); soc_camera_video_stop(&mt9v022->icd);
} }
static int mt9v022_probe(struct i2c_client *client) static int mt9v022_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{ {
struct mt9v022 *mt9v022; struct mt9v022 *mt9v022;
struct soc_camera_device *icd; struct soc_camera_device *icd;
......
...@@ -1450,7 +1450,8 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar ...@@ -1450,7 +1450,8 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int saa7115_probe(struct i2c_client *client) static int saa7115_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct saa711x_state *state; struct saa711x_state *state;
int i; int i;
......
...@@ -661,7 +661,8 @@ static int saa7127_command(struct i2c_client *client, ...@@ -661,7 +661,8 @@ static int saa7127_command(struct i2c_client *client,
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int saa7127_probe(struct i2c_client *client) static int saa7127_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{ {
struct saa7127_state *state; struct saa7127_state *state;
struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */ struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */
......
...@@ -1418,7 +1418,8 @@ static int saa717x_command(struct i2c_client *client, unsigned cmd, void *arg) ...@@ -1418,7 +1418,8 @@ static int saa717x_command(struct i2c_client *client, unsigned cmd, void *arg)
/* i2c implementation */ /* i2c implementation */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int saa717x_probe(struct i2c_client *client) static int saa717x_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{ {
struct saa717x_state *decoder; struct saa717x_state *decoder;
u8 id = 0; u8 id = 0;
......
...@@ -840,7 +840,8 @@ static struct v4l2_int_device tcm825x_int_device = { ...@@ -840,7 +840,8 @@ static struct v4l2_int_device tcm825x_int_device = {
}, },
}; };
static int tcm825x_probe(struct i2c_client *client) static int tcm825x_probe(struct i2c_client *client,
const struct i2c_device_id *did)
{ {
struct tcm825x_sensor *sensor = &tcm825x; struct tcm825x_sensor *sensor = &tcm825x;
int rval; int rval;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment