aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/feature-removal-schedule.txt9
-rw-r--r--Documentation/i2c/writing-clients16
-rw-r--r--drivers/i2c/i2c-core.c83
-rw-r--r--include/linux/i2c.h39
4 files changed, 20 insertions, 127 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 9163dade0706..f8cd450be9aa 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -368,15 +368,6 @@ Who: Krzysztof Piotr Oledzki <ole@ans.pl>
368 368
369--------------------------- 369---------------------------
370 370
371What: i2c_attach_client(), i2c_detach_client(), i2c_driver->detach_client()
372When: 2.6.30
373Check: i2c_attach_client i2c_detach_client
374Why: Deprecated by the new (standard) device driver binding model. Use
375 i2c_driver->probe() and ->remove() instead.
376Who: Jean Delvare <khali@linux-fr.org>
377
378---------------------------
379
380What: fscher and fscpos drivers 371What: fscher and fscpos drivers
381When: June 2009 372When: June 2009
382Why: Deprecated by the new fschmd driver. 373Why: Deprecated by the new fschmd driver.
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index c1a06f989cf7..7860aafb483d 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -126,19 +126,9 @@ different) configuration information, as do drivers handling chip variants
126that can't be distinguished by protocol probing, or which need some board 126that can't be distinguished by protocol probing, or which need some board
127specific information to operate correctly. 127specific information to operate correctly.
128 128
129Accordingly, the I2C stack now has two models for associating I2C devices
130with their drivers: the original "legacy" model, and a newer one that's
131fully compatible with the Linux 2.6 driver model. These models do not mix,
132since the "legacy" model requires drivers to create "i2c_client" device
133objects after SMBus style probing, while the Linux driver model expects
134drivers to be given such device objects in their probe() routines.
135 129
136The legacy model is deprecated now and will soon be removed, so we no 130Device/Driver Binding
137longer document it here. 131---------------------
138
139
140Standard Driver Model Binding ("New Style")
141-------------------------------------------
142 132
143System infrastructure, typically board-specific initialization code or 133System infrastructure, typically board-specific initialization code or
144boot firmware, reports what I2C devices exist. For example, there may be 134boot firmware, reports what I2C devices exist. For example, there may be
@@ -201,7 +191,7 @@ a given I2C bus. This is for example the case of hardware monitoring
201devices on a PC's SMBus. In that case, you may want to let your driver 191devices on a PC's SMBus. In that case, you may want to let your driver
202detect supported devices automatically. This is how the legacy model 192detect supported devices automatically. This is how the legacy model
203was working, and is now available as an extension to the standard 193was working, and is now available as an extension to the standard
204driver model (so that we can finally get rid of the legacy model.) 194driver model.
205 195
206You simply have to define a detect callback which will attempt to 196You simply have to define a detect callback which will attempt to
207identify supported devices (returning 0 for supported ones and -ENODEV 197identify supported devices (returning 0 for supported ones and -ENODEV
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index fc18fdbffd3f..dc8bc9131447 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -43,6 +43,7 @@ static DEFINE_IDR(i2c_adapter_idr);
43 43
44#define is_newstyle_driver(d) ((d)->probe || (d)->remove || (d)->detect) 44#define is_newstyle_driver(d) ((d)->probe || (d)->remove || (d)->detect)
45 45
46static int i2c_attach_client(struct i2c_client *client);
46static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); 47static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
47 48
48/* ------------------------------------------------------------------------- */ 49/* ------------------------------------------------------------------------- */
@@ -83,10 +84,6 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
83{ 84{
84 struct i2c_client *client = to_i2c_client(dev); 85 struct i2c_client *client = to_i2c_client(dev);
85 86
86 /* by definition, legacy drivers can't hotplug */
87 if (dev->driver)
88 return 0;
89
90 if (add_uevent_var(env, "MODALIAS=%s%s", 87 if (add_uevent_var(env, "MODALIAS=%s%s",
91 I2C_MODULE_PREFIX, client->name)) 88 I2C_MODULE_PREFIX, client->name))
92 return -ENOMEM; 89 return -ENOMEM;
@@ -455,7 +452,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
455 452
456 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 453 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
457 454
458 /* create pre-declared device nodes for new-style drivers */ 455 /* create pre-declared device nodes */
459 if (adap->nr < __i2c_first_dynamic_bus_num) 456 if (adap->nr < __i2c_first_dynamic_bus_num)
460 i2c_scan_static_board_info(adap); 457 i2c_scan_static_board_info(adap);
461 458
@@ -617,26 +614,9 @@ int i2c_del_adapter(struct i2c_adapter *adap)
617 if (res) 614 if (res)
618 goto out_unlock; 615 goto out_unlock;
619 616
620 /* detach any active clients. This must be done first, because 617 /* Detach any active clients */
621 * it can fail; in which case we give up. */
622 list_for_each_entry_safe_reverse(client, _n, &adap->clients, list) { 618 list_for_each_entry_safe_reverse(client, _n, &adap->clients, list) {
623 struct i2c_driver *driver; 619 i2c_unregister_device(client);
624
625 driver = client->driver;
626
627 /* new style, follow standard driver model */
628 if (!driver || is_newstyle_driver(driver)) {
629 i2c_unregister_device(client);
630 continue;
631 }
632
633 /* legacy drivers create and remove clients themselves */
634 if ((res = driver->detach_client(client))) {
635 dev_err(&adap->dev, "detach_client failed for client "
636 "[%s] at address 0x%02x\n", client->name,
637 client->addr);
638 goto out_unlock;
639 }
640 } 620 }
641 621
642 /* clean up the sysfs representation */ 622 /* clean up the sysfs representation */
@@ -680,11 +660,7 @@ static int __attach_adapter(struct device *dev, void *data)
680 660
681/* 661/*
682 * An i2c_driver is used with one or more i2c_client (device) nodes to access 662 * An i2c_driver is used with one or more i2c_client (device) nodes to access
683 * i2c slave chips, on a bus instance associated with some i2c_adapter. There 663 * i2c slave chips, on a bus instance associated with some i2c_adapter.
684 * are two models for binding the driver to its device: "new style" drivers
685 * follow the standard Linux driver model and just respond to probe() calls
686 * issued if the driver core sees they match(); "legacy" drivers create device
687 * nodes themselves.
688 */ 664 */
689 665
690int i2c_register_driver(struct module *owner, struct i2c_driver *driver) 666int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
@@ -695,21 +671,11 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
695 if (unlikely(WARN_ON(!i2c_bus_type.p))) 671 if (unlikely(WARN_ON(!i2c_bus_type.p)))
696 return -EAGAIN; 672 return -EAGAIN;
697 673
698 /* new style driver methods can't mix with legacy ones */
699 if (is_newstyle_driver(driver)) {
700 if (driver->detach_adapter || driver->detach_client) {
701 printk(KERN_WARNING
702 "i2c-core: driver [%s] is confused\n",
703 driver->driver.name);
704 return -EINVAL;
705 }
706 }
707
708 /* add the driver to the list of i2c drivers in the driver core */ 674 /* add the driver to the list of i2c drivers in the driver core */
709 driver->driver.owner = owner; 675 driver->driver.owner = owner;
710 driver->driver.bus = &i2c_bus_type; 676 driver->driver.bus = &i2c_bus_type;
711 677
712 /* for new style drivers, when registration returns the driver core 678 /* When registration returns, the driver core
713 * will have called probe() for all matching-but-unbound devices. 679 * will have called probe() for all matching-but-unbound devices.
714 */ 680 */
715 res = driver_register(&driver->driver); 681 res = driver_register(&driver->driver);
@@ -748,29 +714,11 @@ static int __detach_adapter(struct device *dev, void *data)
748 if (is_newstyle_driver(driver)) 714 if (is_newstyle_driver(driver))
749 return 0; 715 return 0;
750 716
751 /* Have a look at each adapter, if clients of this driver are still
752 * attached. If so, detach them to be able to kill the driver
753 * afterwards.
754 */
755 if (driver->detach_adapter) { 717 if (driver->detach_adapter) {
756 if (driver->detach_adapter(adapter)) 718 if (driver->detach_adapter(adapter))
757 dev_err(&adapter->dev, 719 dev_err(&adapter->dev,
758 "detach_adapter failed for driver [%s]\n", 720 "detach_adapter failed for driver [%s]\n",
759 driver->driver.name); 721 driver->driver.name);
760 } else {
761 struct i2c_client *client, *_n;
762
763 list_for_each_entry_safe(client, _n, &adapter->clients, list) {
764 if (client->driver != driver)
765 continue;
766 dev_dbg(&adapter->dev,
767 "detaching client [%s] at 0x%02x\n",
768 client->name, client->addr);
769 if (driver->detach_client(client))
770 dev_err(&adapter->dev, "detach_client "
771 "failed for client [%s] at 0x%02x\n",
772 client->name, client->addr);
773 }
774 } 722 }
775 723
776 return 0; 724 return 0;
@@ -812,7 +760,7 @@ static int i2c_check_addr(struct i2c_adapter *adapter, int addr)
812 return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); 760 return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr);
813} 761}
814 762
815int i2c_attach_client(struct i2c_client *client) 763static int i2c_attach_client(struct i2c_client *client)
816{ 764{
817 struct i2c_adapter *adapter = client->adapter; 765 struct i2c_adapter *adapter = client->adapter;
818 int res; 766 int res;
@@ -854,23 +802,6 @@ out_err:
854 "(%d)\n", client->name, client->addr, res); 802 "(%d)\n", client->name, client->addr, res);
855 return res; 803 return res;
856} 804}
857EXPORT_SYMBOL(i2c_attach_client);
858
859int i2c_detach_client(struct i2c_client *client)
860{
861 struct i2c_adapter *adapter = client->adapter;
862
863 mutex_lock(&adapter->clist_lock);
864 list_del(&client->list);
865 mutex_unlock(&adapter->clist_lock);
866
867 init_completion(&client->released);
868 device_unregister(&client->dev);
869 wait_for_completion(&client->released);
870
871 return 0;
872}
873EXPORT_SYMBOL(i2c_detach_client);
874 805
875/** 806/**
876 * i2c_use_client - increments the reference count of the i2c client structure 807 * i2c_use_client - increments the reference count of the i2c client structure
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index b3f4606afa0e..43a3545670b8 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -100,9 +100,8 @@ extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
100 * @class: What kind of i2c device we instantiate (for detect) 100 * @class: What kind of i2c device we instantiate (for detect)
101 * @attach_adapter: Callback for bus addition (for legacy drivers) 101 * @attach_adapter: Callback for bus addition (for legacy drivers)
102 * @detach_adapter: Callback for bus removal (for legacy drivers) 102 * @detach_adapter: Callback for bus removal (for legacy drivers)
103 * @detach_client: Callback for device removal (for legacy drivers) 103 * @probe: Callback for device binding
104 * @probe: Callback for device binding (new-style drivers) 104 * @remove: Callback for device unbinding
105 * @remove: Callback for device unbinding (new-style drivers)
106 * @shutdown: Callback for device shutdown 105 * @shutdown: Callback for device shutdown
107 * @suspend: Callback for device suspend 106 * @suspend: Callback for device suspend
108 * @resume: Callback for device resume 107 * @resume: Callback for device resume
@@ -137,26 +136,14 @@ struct i2c_driver {
137 int id; 136 int id;
138 unsigned int class; 137 unsigned int class;
139 138
140 /* Notifies the driver that a new bus has appeared. This routine 139 /* Notifies the driver that a new bus has appeared or is about to be
141 * can be used by the driver to test if the bus meets its conditions 140 * removed. You should avoid using this if you can, it will probably
142 * & seek for the presence of the chip(s) it supports. If found, it 141 * be removed in a near future.
143 * registers the client(s) that are on the bus to the i2c admin. via
144 * i2c_attach_client. (LEGACY I2C DRIVERS ONLY)
145 */ 142 */
146 int (*attach_adapter)(struct i2c_adapter *); 143 int (*attach_adapter)(struct i2c_adapter *);
147 int (*detach_adapter)(struct i2c_adapter *); 144 int (*detach_adapter)(struct i2c_adapter *);
148 145
149 /* tells the driver that a client is about to be deleted & gives it 146 /* Standard driver model interfaces */
150 * the chance to remove its private data. Also, if the client struct
151 * has been dynamically allocated by the driver in the function above,
152 * it must be freed here. (LEGACY I2C DRIVERS ONLY)
153 */
154 int (*detach_client)(struct i2c_client *) __deprecated;
155
156 /* Standard driver model interfaces, for "new style" i2c drivers.
157 * With the driver model, device enumeration is NEVER done by drivers;
158 * it's done by infrastructure. (NEW STYLE DRIVERS ONLY)
159 */
160 int (*probe)(struct i2c_client *, const struct i2c_device_id *); 147 int (*probe)(struct i2c_client *, const struct i2c_device_id *);
161 int (*remove)(struct i2c_client *); 148 int (*remove)(struct i2c_client *);
162 149
@@ -248,11 +235,10 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
248 * that, such as chip type, configuration, associated IRQ, and so on. 235 * that, such as chip type, configuration, associated IRQ, and so on.
249 * 236 *
250 * i2c_board_info is used to build tables of information listing I2C devices 237 * i2c_board_info is used to build tables of information listing I2C devices
251 * that are present. This information is used to grow the driver model tree 238 * that are present. This information is used to grow the driver model tree.
252 * for "new style" I2C drivers. For mainboards this is done statically using 239 * For mainboards this is done statically using i2c_register_board_info();
253 * i2c_register_board_info(); bus numbers identify adapters that aren't 240 * bus numbers identify adapters that aren't yet available. For add-on boards,
254 * yet available. For add-on boards, i2c_new_device() does this dynamically 241 * i2c_new_device() does this dynamically with the adapter already known.
255 * with the adapter already known.
256 */ 242 */
257struct i2c_board_info { 243struct i2c_board_info {
258 char type[I2C_NAME_SIZE]; 244 char type[I2C_NAME_SIZE];
@@ -425,11 +411,6 @@ static inline int i2c_add_driver(struct i2c_driver *driver)
425 return i2c_register_driver(THIS_MODULE, driver); 411 return i2c_register_driver(THIS_MODULE, driver);
426} 412}
427 413
428/* These are deprecated, your driver should use the standard .probe()
429 * and .remove() methods instead. */
430extern int __deprecated i2c_attach_client(struct i2c_client *);
431extern int __deprecated i2c_detach_client(struct i2c_client *);
432
433extern struct i2c_client *i2c_use_client(struct i2c_client *client); 414extern struct i2c_client *i2c_use_client(struct i2c_client *client);
434extern void i2c_release_client(struct i2c_client *client); 415extern void i2c_release_client(struct i2c_client *client);
435 416