aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2013-04-09 20:36:38 -0400
committerWolfram Sang <wsa@the-dreams.de>2013-04-15 12:17:06 -0400
commit76cf3fc844a46b5cdb94da98bffcbd45d4c355b8 (patch)
tree488d4ad6e6cc31496d8c2e66897fd5c9e589d160 /drivers/i2c
parentca0c1ff528a332e6f83d4566c2c8eb05b108c83c (diff)
i2c-designware-pci: use managed functions pcim_* and devm_*
This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c68
1 files changed, 17 insertions, 51 deletions
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index eed149d0b68d..aacb64e916a5 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -212,8 +212,6 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
212{ 212{
213 struct dw_i2c_dev *dev; 213 struct dw_i2c_dev *dev;
214 struct i2c_adapter *adap; 214 struct i2c_adapter *adap;
215 unsigned long start, len;
216 void __iomem *base;
217 int r; 215 int r;
218 struct dw_pci_controller *controller; 216 struct dw_pci_controller *controller;
219 217
@@ -225,51 +223,30 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
225 223
226 controller = &dw_pci_controllers[id->driver_data]; 224 controller = &dw_pci_controllers[id->driver_data];
227 225
228 r = pci_enable_device(pdev); 226 r = pcim_enable_device(pdev);
229 if (r) { 227 if (r) {
230 dev_err(&pdev->dev, "Failed to enable I2C PCI device (%d)\n", 228 dev_err(&pdev->dev, "Failed to enable I2C PCI device (%d)\n",
231 r); 229 r);
232 goto exit; 230 return r;
233 } 231 }
234 232
235 /* Determine the address of the I2C area */ 233 r = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
236 start = pci_resource_start(pdev, 0);
237 len = pci_resource_len(pdev, 0);
238 if (!start || len == 0) {
239 dev_err(&pdev->dev, "base address not set\n");
240 r = -ENODEV;
241 goto exit;
242 }
243
244 r = pci_request_region(pdev, 0, DRIVER_NAME);
245 if (r) { 234 if (r) {
246 dev_err(&pdev->dev, "failed to request I2C region "
247 "0x%lx-0x%lx\n", start,
248 (unsigned long)pci_resource_end(pdev, 0));
249 goto exit;
250 }
251
252 base = ioremap_nocache(start, len);
253 if (!base) {
254 dev_err(&pdev->dev, "I/O memory remapping failed\n"); 235 dev_err(&pdev->dev, "I/O memory remapping failed\n");
255 r = -ENOMEM; 236 return r;
256 goto err_release_region;
257 } 237 }
258 238
259 239 dev = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL);
260 dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); 240 if (!dev)
261 if (!dev) { 241 return -ENOMEM;
262 r = -ENOMEM;
263 goto err_release_region;
264 }
265 242
266 init_completion(&dev->cmd_complete); 243 init_completion(&dev->cmd_complete);
267 mutex_init(&dev->lock); 244 mutex_init(&dev->lock);
268 dev->clk = NULL; 245 dev->clk = NULL;
269 dev->controller = controller; 246 dev->controller = controller;
270 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; 247 dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz;
271 dev->base = base; 248 dev->base = pcim_iomap_table(pdev)[0];
272 dev->dev = get_device(&pdev->dev); 249 dev->dev = &pdev->dev;
273 dev->functionality = 250 dev->functionality =
274 I2C_FUNC_I2C | 251 I2C_FUNC_I2C |
275 I2C_FUNC_SMBUS_BYTE | 252 I2C_FUNC_SMBUS_BYTE |
@@ -284,7 +261,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
284 dev->rx_fifo_depth = controller->rx_fifo_depth; 261 dev->rx_fifo_depth = controller->rx_fifo_depth;
285 r = i2c_dw_init(dev); 262 r = i2c_dw_init(dev);
286 if (r) 263 if (r)
287 goto err_iounmap; 264 return r;
288 265
289 adap = &dev->adapter; 266 adap = &dev->adapter;
290 i2c_set_adapdata(adap, dev); 267 i2c_set_adapdata(adap, dev);
@@ -296,10 +273,11 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
296 snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d", 273 snprintf(adap->name, sizeof(adap->name), "i2c-designware-pci-%d",
297 adap->nr); 274 adap->nr);
298 275
299 r = request_irq(pdev->irq, i2c_dw_isr, IRQF_SHARED, adap->name, dev); 276 r = devm_request_irq(&pdev->dev, pdev->irq, i2c_dw_isr, IRQF_SHARED,
277 adap->name, dev);
300 if (r) { 278 if (r) {
301 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); 279 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
302 goto err_iounmap; 280 return r;
303 } 281 }
304 282
305 i2c_dw_disable_int(dev); 283 i2c_dw_disable_int(dev);
@@ -307,24 +285,16 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
307 r = i2c_add_numbered_adapter(adap); 285 r = i2c_add_numbered_adapter(adap);
308 if (r) { 286 if (r) {
309 dev_err(&pdev->dev, "failure adding adapter\n"); 287 dev_err(&pdev->dev, "failure adding adapter\n");
310 goto err_free_irq; 288 return r;
311 } 289 }
312 290
291 /* Increase reference counter */
292 get_device(&pdev->dev);
293
313 pm_runtime_put_noidle(&pdev->dev); 294 pm_runtime_put_noidle(&pdev->dev);
314 pm_runtime_allow(&pdev->dev); 295 pm_runtime_allow(&pdev->dev);
315 296
316 return 0; 297 return 0;
317
318err_free_irq:
319 free_irq(pdev->irq, dev);
320err_iounmap:
321 iounmap(dev->base);
322 put_device(&pdev->dev);
323 kfree(dev);
324err_release_region:
325 pci_release_region(pdev, 0);
326exit:
327 return r;
328} 298}
329 299
330static void i2c_dw_pci_remove(struct pci_dev *pdev) 300static void i2c_dw_pci_remove(struct pci_dev *pdev)
@@ -337,10 +307,6 @@ static void i2c_dw_pci_remove(struct pci_dev *pdev)
337 307
338 i2c_del_adapter(&dev->adapter); 308 i2c_del_adapter(&dev->adapter);
339 put_device(&pdev->dev); 309 put_device(&pdev->dev);
340
341 free_irq(dev->irq, dev);
342 kfree(dev);
343 pci_release_region(pdev, 0);
344} 310}
345 311
346/* work with hotplug and coldplug */ 312/* work with hotplug and coldplug */