aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-14 11:30:04 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-14 11:30:04 -0400
commit9def255631bb742264d334d77819e1ae5278a515 (patch)
treeef319955bb0b1acded8c0b957914bd72f810ee1e /drivers
parent67a37308ae37f8948d3c26f75a18f0ddb77ac198 (diff)
i2c-parport-light: Don't register a platform device resource
The i2c-parport-light driver isn't a real platform driver, so it should not instantiate platform devices with resources. The resource management system can't cope with colliding resources, and we are likely to create such a colliding resource. So, better just try to grab the I/O ports we need right at module initialization time, and bail out if we can't. It has the added benefit that the module will no longer load if it isn't going to work, which is definitely more user-friendly. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c39
1 files changed, 8 insertions, 31 deletions
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index c6faf9bdad18..b2b8380f6602 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -123,11 +123,6 @@ static struct i2c_adapter parport_adapter = {
123static int __devinit i2c_parport_probe(struct platform_device *pdev) 123static int __devinit i2c_parport_probe(struct platform_device *pdev)
124{ 124{
125 int err; 125 int err;
126 struct resource *res;
127
128 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
129 if (!request_region(res->start, res->end - res->start + 1, DRVNAME))
130 return -EBUSY;
131 126
132 /* Reset hardware to a sane state (SCL and SDA high) */ 127 /* Reset hardware to a sane state (SCL and SDA high) */
133 parport_setsda(NULL, 1); 128 parport_setsda(NULL, 1);
@@ -138,29 +133,19 @@ static int __devinit i2c_parport_probe(struct platform_device *pdev)
138 133
139 parport_adapter.dev.parent = &pdev->dev; 134 parport_adapter.dev.parent = &pdev->dev;
140 err = i2c_bit_add_bus(&parport_adapter); 135 err = i2c_bit_add_bus(&parport_adapter);
141 if (err) { 136 if (err)
142 dev_err(&pdev->dev, "Unable to register with I2C\n"); 137 dev_err(&pdev->dev, "Unable to register with I2C\n");
143 goto exit_region;
144 }
145 return 0;
146
147exit_region:
148 release_region(res->start, res->end - res->start + 1);
149 return err; 138 return err;
150} 139}
151 140
152static int __devexit i2c_parport_remove(struct platform_device *pdev) 141static int __devexit i2c_parport_remove(struct platform_device *pdev)
153{ 142{
154 struct resource *res;
155
156 i2c_del_adapter(&parport_adapter); 143 i2c_del_adapter(&parport_adapter);
157 144
158 /* Un-init if needed (power off...) */ 145 /* Un-init if needed (power off...) */
159 if (adapter_parm[type].init.val) 146 if (adapter_parm[type].init.val)
160 line_set(0, &adapter_parm[type].init); 147 line_set(0, &adapter_parm[type].init);
161 148
162 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
163 release_region(res->start, res->end - res->start + 1);
164 return 0; 149 return 0;
165} 150}
166 151
@@ -175,12 +160,6 @@ static struct platform_driver i2c_parport_driver = {
175 160
176static int __init i2c_parport_device_add(u16 address) 161static int __init i2c_parport_device_add(u16 address)
177{ 162{
178 struct resource res = {
179 .start = address,
180 .end = address + 2,
181 .name = DRVNAME,
182 .flags = IORESOURCE_IO,
183 };
184 int err; 163 int err;
185 164
186 pdev = platform_device_alloc(DRVNAME, -1); 165 pdev = platform_device_alloc(DRVNAME, -1);
@@ -190,13 +169,6 @@ static int __init i2c_parport_device_add(u16 address)
190 goto exit; 169 goto exit;
191 } 170 }
192 171
193 err = platform_device_add_resources(pdev, &res, 1);
194 if (err) {
195 printk(KERN_ERR DRVNAME ": Device resource addition failed "
196 "(%d)\n", err);
197 goto exit_device_put;
198 }
199
200 err = platform_device_add(pdev); 172 err = platform_device_add(pdev);
201 if (err) { 173 if (err) {
202 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 174 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
@@ -231,13 +203,16 @@ static int __init i2c_parport_init(void)
231 base = DEFAULT_BASE; 203 base = DEFAULT_BASE;
232 } 204 }
233 205
206 if (!request_region(base, 3, DRVNAME))
207 return -EBUSY;
208
234 if (!adapter_parm[type].getscl.val) 209 if (!adapter_parm[type].getscl.val)
235 parport_algo_data.getscl = NULL; 210 parport_algo_data.getscl = NULL;
236 211
237 /* Sets global pdev as a side effect */ 212 /* Sets global pdev as a side effect */
238 err = i2c_parport_device_add(base); 213 err = i2c_parport_device_add(base);
239 if (err) 214 if (err)
240 goto exit; 215 goto exit_release;
241 216
242 err = platform_driver_register(&i2c_parport_driver); 217 err = platform_driver_register(&i2c_parport_driver);
243 if (err) 218 if (err)
@@ -247,7 +222,8 @@ static int __init i2c_parport_init(void)
247 222
248exit_device: 223exit_device:
249 platform_device_unregister(pdev); 224 platform_device_unregister(pdev);
250exit: 225exit_release:
226 release_region(base, 3);
251 return err; 227 return err;
252} 228}
253 229
@@ -255,6 +231,7 @@ static void __exit i2c_parport_exit(void)
255{ 231{
256 platform_driver_unregister(&i2c_parport_driver); 232 platform_driver_unregister(&i2c_parport_driver);
257 platform_device_unregister(pdev); 233 platform_device_unregister(pdev);
234 release_region(base, 3);
258} 235}
259 236
260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 237MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");