diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-06 11:06:19 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-06 11:06:19 -0500 |
commit | 6dfa5ca3c9a35cb395ab1f51e0e500106c85dff4 (patch) | |
tree | 3ea208e88338d40fd9e4d0ea51f55cafecd64ff0 | |
parent | d7d838a6ebbab6e786148133b6cf9617144603b4 (diff) |
i2c-powermac: Include the i2c_adapter in struct pmac_i2c_bus
Include the i2c_adapter in struct pmac_i2c_bus. This avoids memory
fragmentation and allows for several code cleanups.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Michel Daenzer <michel@daenzer.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
-rw-r--r-- | arch/powerpc/include/asm/pmac_low_i2c.h | 6 | ||||
-rw-r--r-- | arch/powerpc/platforms/powermac/low_i2c.c | 25 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-powermac.c | 15 |
3 files changed, 9 insertions, 37 deletions
diff --git a/arch/powerpc/include/asm/pmac_low_i2c.h b/arch/powerpc/include/asm/pmac_low_i2c.h index 131011bd7e76..01d71826d92f 100644 --- a/arch/powerpc/include/asm/pmac_low_i2c.h +++ b/arch/powerpc/include/asm/pmac_low_i2c.h | |||
@@ -72,11 +72,7 @@ extern int pmac_i2c_get_type(struct pmac_i2c_bus *bus); | |||
72 | extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus); | 72 | extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus); |
73 | extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus); | 73 | extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus); |
74 | 74 | ||
75 | /* i2c layer adapter attach/detach */ | 75 | /* i2c layer adapter helpers */ |
76 | extern void pmac_i2c_attach_adapter(struct pmac_i2c_bus *bus, | ||
77 | struct i2c_adapter *adapter); | ||
78 | extern void pmac_i2c_detach_adapter(struct pmac_i2c_bus *bus, | ||
79 | struct i2c_adapter *adapter); | ||
80 | extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus); | 76 | extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus); |
81 | extern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter); | 77 | extern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter); |
82 | 78 | ||
diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c index 414ca9849f23..345e2da56767 100644 --- a/arch/powerpc/platforms/powermac/low_i2c.c +++ b/arch/powerpc/platforms/powermac/low_i2c.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/interrupt.h> | 42 | #include <linux/interrupt.h> |
43 | #include <linux/timer.h> | 43 | #include <linux/timer.h> |
44 | #include <linux/mutex.h> | 44 | #include <linux/mutex.h> |
45 | #include <linux/i2c.h> | ||
45 | #include <asm/keylargo.h> | 46 | #include <asm/keylargo.h> |
46 | #include <asm/uninorth.h> | 47 | #include <asm/uninorth.h> |
47 | #include <asm/io.h> | 48 | #include <asm/io.h> |
@@ -80,7 +81,7 @@ struct pmac_i2c_bus | |||
80 | struct device_node *busnode; | 81 | struct device_node *busnode; |
81 | int type; | 82 | int type; |
82 | int flags; | 83 | int flags; |
83 | struct i2c_adapter *adapter; | 84 | struct i2c_adapter adapter; |
84 | void *hostdata; | 85 | void *hostdata; |
85 | int channel; /* some hosts have multiple */ | 86 | int channel; /* some hosts have multiple */ |
86 | int mode; /* current mode */ | 87 | int mode; /* current mode */ |
@@ -1014,25 +1015,9 @@ int pmac_i2c_get_channel(struct pmac_i2c_bus *bus) | |||
1014 | EXPORT_SYMBOL_GPL(pmac_i2c_get_channel); | 1015 | EXPORT_SYMBOL_GPL(pmac_i2c_get_channel); |
1015 | 1016 | ||
1016 | 1017 | ||
1017 | void pmac_i2c_attach_adapter(struct pmac_i2c_bus *bus, | ||
1018 | struct i2c_adapter *adapter) | ||
1019 | { | ||
1020 | WARN_ON(bus->adapter != NULL); | ||
1021 | bus->adapter = adapter; | ||
1022 | } | ||
1023 | EXPORT_SYMBOL_GPL(pmac_i2c_attach_adapter); | ||
1024 | |||
1025 | void pmac_i2c_detach_adapter(struct pmac_i2c_bus *bus, | ||
1026 | struct i2c_adapter *adapter) | ||
1027 | { | ||
1028 | WARN_ON(bus->adapter != adapter); | ||
1029 | bus->adapter = NULL; | ||
1030 | } | ||
1031 | EXPORT_SYMBOL_GPL(pmac_i2c_detach_adapter); | ||
1032 | |||
1033 | struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus) | 1018 | struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus) |
1034 | { | 1019 | { |
1035 | return bus->adapter; | 1020 | return &bus->adapter; |
1036 | } | 1021 | } |
1037 | EXPORT_SYMBOL_GPL(pmac_i2c_get_adapter); | 1022 | EXPORT_SYMBOL_GPL(pmac_i2c_get_adapter); |
1038 | 1023 | ||
@@ -1041,7 +1026,7 @@ struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter) | |||
1041 | struct pmac_i2c_bus *bus; | 1026 | struct pmac_i2c_bus *bus; |
1042 | 1027 | ||
1043 | list_for_each_entry(bus, &pmac_i2c_busses, link) | 1028 | list_for_each_entry(bus, &pmac_i2c_busses, link) |
1044 | if (bus->adapter == adapter) | 1029 | if (&bus->adapter == adapter) |
1045 | return bus; | 1030 | return bus; |
1046 | return NULL; | 1031 | return NULL; |
1047 | } | 1032 | } |
@@ -1053,7 +1038,7 @@ int pmac_i2c_match_adapter(struct device_node *dev, struct i2c_adapter *adapter) | |||
1053 | 1038 | ||
1054 | if (bus == NULL) | 1039 | if (bus == NULL) |
1055 | return 0; | 1040 | return 0; |
1056 | return (bus->adapter == adapter); | 1041 | return (&bus->adapter == adapter); |
1057 | } | 1042 | } |
1058 | EXPORT_SYMBOL_GPL(pmac_i2c_match_adapter); | 1043 | EXPORT_SYMBOL_GPL(pmac_i2c_match_adapter); |
1059 | 1044 | ||
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index 5c22d9f0289b..b58fb7026597 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c | |||
@@ -204,19 +204,16 @@ static const struct i2c_algorithm i2c_powermac_algorithm = { | |||
204 | static int __devexit i2c_powermac_remove(struct platform_device *dev) | 204 | static int __devexit i2c_powermac_remove(struct platform_device *dev) |
205 | { | 205 | { |
206 | struct i2c_adapter *adapter = platform_get_drvdata(dev); | 206 | struct i2c_adapter *adapter = platform_get_drvdata(dev); |
207 | struct pmac_i2c_bus *bus = i2c_get_adapdata(adapter); | ||
208 | int rc; | 207 | int rc; |
209 | 208 | ||
210 | rc = i2c_del_adapter(adapter); | 209 | rc = i2c_del_adapter(adapter); |
211 | pmac_i2c_detach_adapter(bus, adapter); | ||
212 | i2c_set_adapdata(adapter, NULL); | ||
213 | /* We aren't that prepared to deal with this... */ | 210 | /* We aren't that prepared to deal with this... */ |
214 | if (rc) | 211 | if (rc) |
215 | printk(KERN_WARNING | 212 | printk(KERN_WARNING |
216 | "i2c-powermac.c: Failed to remove bus %s !\n", | 213 | "i2c-powermac.c: Failed to remove bus %s !\n", |
217 | adapter->name); | 214 | adapter->name); |
218 | platform_set_drvdata(dev, NULL); | 215 | platform_set_drvdata(dev, NULL); |
219 | kfree(adapter); | 216 | memset(adapter, 0, sizeof(*adapter)); |
220 | 217 | ||
221 | return 0; | 218 | return 0; |
222 | } | 219 | } |
@@ -261,23 +258,17 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev) | |||
261 | snprintf(name, 32, "%s %d", basename, pmac_i2c_get_channel(bus)); | 258 | snprintf(name, 32, "%s %d", basename, pmac_i2c_get_channel(bus)); |
262 | of_node_put(parent); | 259 | of_node_put(parent); |
263 | 260 | ||
264 | adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); | 261 | adapter = pmac_i2c_get_adapter(bus); |
265 | if (adapter == NULL) { | ||
266 | printk(KERN_ERR "i2c-powermac: can't allocate inteface !\n"); | ||
267 | return -ENOMEM; | ||
268 | } | ||
269 | platform_set_drvdata(dev, adapter); | 262 | platform_set_drvdata(dev, adapter); |
270 | strcpy(adapter->name, name); | 263 | strcpy(adapter->name, name); |
271 | adapter->algo = &i2c_powermac_algorithm; | 264 | adapter->algo = &i2c_powermac_algorithm; |
272 | i2c_set_adapdata(adapter, bus); | 265 | i2c_set_adapdata(adapter, bus); |
273 | adapter->dev.parent = &dev->dev; | 266 | adapter->dev.parent = &dev->dev; |
274 | pmac_i2c_attach_adapter(bus, adapter); | ||
275 | rc = i2c_add_adapter(adapter); | 267 | rc = i2c_add_adapter(adapter); |
276 | if (rc) { | 268 | if (rc) { |
277 | printk(KERN_ERR "i2c-powermac: Adapter %s registration " | 269 | printk(KERN_ERR "i2c-powermac: Adapter %s registration " |
278 | "failed\n", name); | 270 | "failed\n", name); |
279 | i2c_set_adapdata(adapter, NULL); | 271 | memset(adapter, 0, sizeof(*adapter)); |
280 | pmac_i2c_detach_adapter(bus, adapter); | ||
281 | } | 272 | } |
282 | 273 | ||
283 | printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); | 274 | printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); |