diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2007-10-01 10:33:53 -0400 |
---|---|---|
committer | Jens Axboe <axboe@carl.home.kernel.dk> | 2007-10-10 03:25:58 -0400 |
commit | 1b455466549f46bab0a75a7a296a9331a38fd6fa (patch) | |
tree | 2b912166ff08995d3508cf1888280a5a47d01a53 /drivers/block/xsysace.c | |
parent | edec49616c7b4ad7ceb3b936a8d95b10652ee677 (diff) |
Sysace: Move structure allocation from bus binding into common code
Split the determination of device registers/irqs/etc from the actual
allocation and initialization of the device structure. This cleans
up the code a bit in preparation to add an of_platform bus binding
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/block/xsysace.c')
-rw-r--r-- | drivers/block/xsysace.c | 99 |
1 files changed, 61 insertions, 38 deletions
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c index b10447611afd..555939bd2d53 100644 --- a/drivers/block/xsysace.c +++ b/drivers/block/xsysace.c | |||
@@ -1033,7 +1033,7 @@ static int __devinit ace_setup(struct ace_device *ace) | |||
1033 | if (ace->irq != NO_IRQ) | 1033 | if (ace->irq != NO_IRQ) |
1034 | free_irq(ace->irq, ace); | 1034 | free_irq(ace->irq, ace); |
1035 | err_ioremap: | 1035 | err_ioremap: |
1036 | printk(KERN_INFO "xsysace: error initializing device at 0x%lx\n", | 1036 | dev_info(ace->dev, "xsysace: error initializing device at 0x%lx\n", |
1037 | ace->physaddr); | 1037 | ace->physaddr); |
1038 | return -ENOMEM; | 1038 | return -ENOMEM; |
1039 | } | 1039 | } |
@@ -1056,68 +1056,91 @@ static void __devexit ace_teardown(struct ace_device *ace) | |||
1056 | iounmap(ace->baseaddr); | 1056 | iounmap(ace->baseaddr); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | /* --------------------------------------------------------------------- | 1059 | static int __devinit |
1060 | * Platform Bus Support | 1060 | ace_alloc(struct device *dev, int id, unsigned long physaddr, |
1061 | */ | 1061 | int irq, int bus_width) |
1062 | |||
1063 | static int __devinit ace_probe(struct platform_device *dev) | ||
1064 | { | 1062 | { |
1065 | struct ace_device *ace; | 1063 | struct ace_device *ace; |
1066 | int i; | 1064 | int rc; |
1065 | dev_dbg(dev, "ace_alloc(%p)\n", dev); | ||
1067 | 1066 | ||
1068 | dev_dbg(&dev->dev, "ace_probe(%p)\n", dev); | 1067 | if (!physaddr) { |
1068 | rc = -ENODEV; | ||
1069 | goto err_noreg; | ||
1070 | } | ||
1069 | 1071 | ||
1070 | /* | 1072 | /* Allocate and initialize the ace device structure */ |
1071 | * Allocate the ace device structure | ||
1072 | */ | ||
1073 | ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL); | 1073 | ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL); |
1074 | if (!ace) | 1074 | if (!ace) { |
1075 | rc = -ENOMEM; | ||
1075 | goto err_alloc; | 1076 | goto err_alloc; |
1076 | |||
1077 | ace->dev = &dev->dev; | ||
1078 | ace->id = dev->id; | ||
1079 | ace->irq = NO_IRQ; | ||
1080 | |||
1081 | for (i = 0; i < dev->num_resources; i++) { | ||
1082 | if (dev->resource[i].flags & IORESOURCE_MEM) | ||
1083 | ace->physaddr = dev->resource[i].start; | ||
1084 | if (dev->resource[i].flags & IORESOURCE_IRQ) | ||
1085 | ace->irq = dev->resource[i].start; | ||
1086 | } | 1077 | } |
1087 | 1078 | ||
1088 | /* FIXME: Should get bus_width from the platform_device struct */ | 1079 | ace->dev = dev; |
1089 | ace->bus_width = 1; | 1080 | ace->id = id; |
1090 | 1081 | ace->physaddr = physaddr; | |
1091 | platform_set_drvdata(dev, ace); | 1082 | ace->irq = irq; |
1083 | ace->bus_width = bus_width; | ||
1092 | 1084 | ||
1093 | /* Call the bus-independant setup code */ | 1085 | /* Call the setup code */ |
1094 | if (ace_setup(ace) != 0) | 1086 | if ((rc = ace_setup(ace)) != 0) |
1095 | goto err_setup; | 1087 | goto err_setup; |
1096 | 1088 | ||
1089 | dev_set_drvdata(dev, ace); | ||
1097 | return 0; | 1090 | return 0; |
1098 | 1091 | ||
1099 | err_setup: | 1092 | err_setup: |
1100 | platform_set_drvdata(dev, NULL); | 1093 | dev_set_drvdata(dev, NULL); |
1101 | kfree(ace); | 1094 | kfree(ace); |
1102 | err_alloc: | 1095 | err_alloc: |
1103 | printk(KERN_ERR "xsysace: could not initialize device\n"); | 1096 | err_noreg: |
1104 | return -ENOMEM; | 1097 | dev_err(dev, "could not initialize device, err=%i\n", rc); |
1098 | return rc; | ||
1105 | } | 1099 | } |
1106 | 1100 | ||
1107 | /* | 1101 | static void __devexit ace_free(struct device *dev) |
1108 | * Platform bus remove() method | ||
1109 | */ | ||
1110 | static int __devexit ace_remove(struct platform_device *dev) | ||
1111 | { | 1102 | { |
1112 | struct ace_device *ace = platform_get_drvdata(dev); | 1103 | struct ace_device *ace = dev_get_drvdata(dev); |
1113 | dev_dbg(&dev->dev, "ace_remove(%p)\n", dev); | 1104 | dev_dbg(dev, "ace_free(%p)\n", dev); |
1114 | 1105 | ||
1115 | if (ace) { | 1106 | if (ace) { |
1116 | ace_teardown(ace); | 1107 | ace_teardown(ace); |
1117 | platform_set_drvdata(dev, NULL); | 1108 | dev_set_drvdata(dev, NULL); |
1118 | kfree(ace); | 1109 | kfree(ace); |
1119 | } | 1110 | } |
1111 | } | ||
1112 | |||
1113 | /* --------------------------------------------------------------------- | ||
1114 | * Platform Bus Support | ||
1115 | */ | ||
1116 | |||
1117 | static int __devinit ace_probe(struct platform_device *dev) | ||
1118 | { | ||
1119 | unsigned long physaddr = 0; | ||
1120 | int bus_width = 1; /* FIXME: should not be hard coded */ | ||
1121 | int id = dev->id; | ||
1122 | int irq = NO_IRQ; | ||
1123 | int i; | ||
1124 | |||
1125 | dev_dbg(&dev->dev, "ace_probe(%p)\n", dev); | ||
1126 | |||
1127 | for (i = 0; i < dev->num_resources; i++) { | ||
1128 | if (dev->resource[i].flags & IORESOURCE_MEM) | ||
1129 | physaddr = dev->resource[i].start; | ||
1130 | if (dev->resource[i].flags & IORESOURCE_IRQ) | ||
1131 | irq = dev->resource[i].start; | ||
1132 | } | ||
1133 | |||
1134 | /* Call the bus-independant setup code */ | ||
1135 | return ace_alloc(&dev->dev, id, physaddr, irq, bus_width); | ||
1136 | } | ||
1120 | 1137 | ||
1138 | /* | ||
1139 | * Platform bus remove() method | ||
1140 | */ | ||
1141 | static int __devexit ace_remove(struct platform_device *dev) | ||
1142 | { | ||
1143 | ace_free(&dev->dev); | ||
1121 | return 0; | 1144 | return 0; |
1122 | } | 1145 | } |
1123 | 1146 | ||