Commit 6dfa5ca3 authored by Jean Delvare's avatar Jean Delvare

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: default avatarJean Delvare <khali@linux-fr.org>
Tested-by: default avatarMichel Daenzer <michel@daenzer.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
parent d7d838a6
...@@ -72,11 +72,7 @@ extern int pmac_i2c_get_type(struct pmac_i2c_bus *bus); ...@@ -72,11 +72,7 @@ extern int pmac_i2c_get_type(struct pmac_i2c_bus *bus);
extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus); extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus);
extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus); extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus);
/* i2c layer adapter attach/detach */ /* i2c layer adapter helpers */
extern void pmac_i2c_attach_adapter(struct pmac_i2c_bus *bus,
struct i2c_adapter *adapter);
extern void pmac_i2c_detach_adapter(struct pmac_i2c_bus *bus,
struct i2c_adapter *adapter);
extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus); extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus);
extern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter); extern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter);
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/i2c.h>
#include <asm/keylargo.h> #include <asm/keylargo.h>
#include <asm/uninorth.h> #include <asm/uninorth.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -80,7 +81,7 @@ struct pmac_i2c_bus ...@@ -80,7 +81,7 @@ struct pmac_i2c_bus
struct device_node *busnode; struct device_node *busnode;
int type; int type;
int flags; int flags;
struct i2c_adapter *adapter; struct i2c_adapter adapter;
void *hostdata; void *hostdata;
int channel; /* some hosts have multiple */ int channel; /* some hosts have multiple */
int mode; /* current mode */ int mode; /* current mode */
...@@ -1014,25 +1015,9 @@ int pmac_i2c_get_channel(struct pmac_i2c_bus *bus) ...@@ -1014,25 +1015,9 @@ int pmac_i2c_get_channel(struct pmac_i2c_bus *bus)
EXPORT_SYMBOL_GPL(pmac_i2c_get_channel); EXPORT_SYMBOL_GPL(pmac_i2c_get_channel);
void pmac_i2c_attach_adapter(struct pmac_i2c_bus *bus,
struct i2c_adapter *adapter)
{
WARN_ON(bus->adapter != NULL);
bus->adapter = adapter;
}
EXPORT_SYMBOL_GPL(pmac_i2c_attach_adapter);
void pmac_i2c_detach_adapter(struct pmac_i2c_bus *bus,
struct i2c_adapter *adapter)
{
WARN_ON(bus->adapter != adapter);
bus->adapter = NULL;
}
EXPORT_SYMBOL_GPL(pmac_i2c_detach_adapter);
struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus) struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus)
{ {
return bus->adapter; return &bus->adapter;
} }
EXPORT_SYMBOL_GPL(pmac_i2c_get_adapter); EXPORT_SYMBOL_GPL(pmac_i2c_get_adapter);
...@@ -1041,7 +1026,7 @@ struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter) ...@@ -1041,7 +1026,7 @@ struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter)
struct pmac_i2c_bus *bus; struct pmac_i2c_bus *bus;
list_for_each_entry(bus, &pmac_i2c_busses, link) list_for_each_entry(bus, &pmac_i2c_busses, link)
if (bus->adapter == adapter) if (&bus->adapter == adapter)
return bus; return bus;
return NULL; return NULL;
} }
...@@ -1053,7 +1038,7 @@ int pmac_i2c_match_adapter(struct device_node *dev, struct i2c_adapter *adapter) ...@@ -1053,7 +1038,7 @@ int pmac_i2c_match_adapter(struct device_node *dev, struct i2c_adapter *adapter)
if (bus == NULL) if (bus == NULL)
return 0; return 0;
return (bus->adapter == adapter); return (&bus->adapter == adapter);
} }
EXPORT_SYMBOL_GPL(pmac_i2c_match_adapter); EXPORT_SYMBOL_GPL(pmac_i2c_match_adapter);
......
...@@ -204,19 +204,16 @@ static const struct i2c_algorithm i2c_powermac_algorithm = { ...@@ -204,19 +204,16 @@ static const struct i2c_algorithm i2c_powermac_algorithm = {
static int __devexit i2c_powermac_remove(struct platform_device *dev) static int __devexit i2c_powermac_remove(struct platform_device *dev)
{ {
struct i2c_adapter *adapter = platform_get_drvdata(dev); struct i2c_adapter *adapter = platform_get_drvdata(dev);
struct pmac_i2c_bus *bus = i2c_get_adapdata(adapter);
int rc; int rc;
rc = i2c_del_adapter(adapter); rc = i2c_del_adapter(adapter);
pmac_i2c_detach_adapter(bus, adapter);
i2c_set_adapdata(adapter, NULL);
/* We aren't that prepared to deal with this... */ /* We aren't that prepared to deal with this... */
if (rc) if (rc)
printk(KERN_WARNING printk(KERN_WARNING
"i2c-powermac.c: Failed to remove bus %s !\n", "i2c-powermac.c: Failed to remove bus %s !\n",
adapter->name); adapter->name);
platform_set_drvdata(dev, NULL); platform_set_drvdata(dev, NULL);
kfree(adapter); memset(adapter, 0, sizeof(*adapter));
return 0; return 0;
} }
...@@ -261,23 +258,17 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev) ...@@ -261,23 +258,17 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
snprintf(name, 32, "%s %d", basename, pmac_i2c_get_channel(bus)); snprintf(name, 32, "%s %d", basename, pmac_i2c_get_channel(bus));
of_node_put(parent); of_node_put(parent);
adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); adapter = pmac_i2c_get_adapter(bus);
if (adapter == NULL) {
printk(KERN_ERR "i2c-powermac: can't allocate inteface !\n");
return -ENOMEM;
}
platform_set_drvdata(dev, adapter); platform_set_drvdata(dev, adapter);
strcpy(adapter->name, name); strcpy(adapter->name, name);
adapter->algo = &i2c_powermac_algorithm; adapter->algo = &i2c_powermac_algorithm;
i2c_set_adapdata(adapter, bus); i2c_set_adapdata(adapter, bus);
adapter->dev.parent = &dev->dev; adapter->dev.parent = &dev->dev;
pmac_i2c_attach_adapter(bus, adapter);
rc = i2c_add_adapter(adapter); rc = i2c_add_adapter(adapter);
if (rc) { if (rc) {
printk(KERN_ERR "i2c-powermac: Adapter %s registration " printk(KERN_ERR "i2c-powermac: Adapter %s registration "
"failed\n", name); "failed\n", name);
i2c_set_adapdata(adapter, NULL); memset(adapter, 0, sizeof(*adapter));
pmac_i2c_detach_adapter(bus, adapter);
} }
printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); printk(KERN_INFO "PowerMac i2c bus %s registered\n", name);
......
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