aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-mpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-mpc.c')
-rw-r--r--drivers/i2c/busses/i2c-mpc.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 03c23ce98edb..9ad3e9262e8a 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -288,6 +288,100 @@ static struct i2c_adapter mpc_ops = {
288 .retries = 1 288 .retries = 1
289}; 289};
290 290
291static int fsl_i2c_probe(struct device *device)
292{
293 int result = 0;
294 struct mpc_i2c *i2c;
295 struct platform_device *pdev = to_platform_device(device);
296 struct fsl_i2c_platform_data *pdata;
297 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
298
299 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
300
301 if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) {
302 return -ENOMEM;
303 }
304 memset(i2c, 0, sizeof(*i2c));
305
306 i2c->irq = platform_get_irq(pdev, 0);
307 i2c->flags = pdata->device_flags;
308 init_waitqueue_head(&i2c->queue);
309
310 i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
311
312 if (!i2c->base) {
313 printk(KERN_ERR "i2c-mpc - failed to map controller\n");
314 result = -ENOMEM;
315 goto fail_map;
316 }
317
318 if (i2c->irq != 0)
319 if ((result = request_irq(i2c->irq, mpc_i2c_isr,
320 SA_SHIRQ, "i2c-mpc", i2c)) < 0) {
321 printk(KERN_ERR
322 "i2c-mpc - failed to attach interrupt\n");
323 goto fail_irq;
324 }
325
326 mpc_i2c_setclock(i2c);
327 dev_set_drvdata(device, i2c);
328
329 i2c->adap = mpc_ops;
330 i2c_set_adapdata(&i2c->adap, i2c);
331 i2c->adap.dev.parent = &pdev->dev;
332 if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
333 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
334 goto fail_add;
335 }
336
337 return result;
338
339 fail_add:
340 if (i2c->irq != 0)
341 free_irq(i2c->irq, NULL);
342 fail_irq:
343 iounmap(i2c->base);
344 fail_map:
345 kfree(i2c);
346 return result;
347};
348
349static int fsl_i2c_remove(struct device *device)
350{
351 struct mpc_i2c *i2c = dev_get_drvdata(device);
352
353 i2c_del_adapter(&i2c->adap);
354 dev_set_drvdata(device, NULL);
355
356 if (i2c->irq != 0)
357 free_irq(i2c->irq, i2c);
358
359 iounmap(i2c->base);
360 kfree(i2c);
361 return 0;
362};
363
364/* Structure for a device driver */
365static struct device_driver fsl_i2c_driver = {
366 .name = "fsl-i2c",
367 .bus = &platform_bus_type,
368 .probe = fsl_i2c_probe,
369 .remove = fsl_i2c_remove,
370};
371
372static int __init fsl_i2c_init(void)
373{
374 return driver_register(&fsl_i2c_driver);
375}
376
377static void __exit fsl_i2c_exit(void)
378{
379 driver_unregister(&fsl_i2c_driver);
380}
381
382module_init(fsl_i2c_init);
383module_exit(fsl_i2c_exit);
384
291MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 385MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
292MODULE_DESCRIPTION 386MODULE_DESCRIPTION
293 ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors"); 387 ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors");