Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-integrator/lm.c |
| 3 | * |
| 4 | * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/device.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 13 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 15 | #include <mach/lm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #define to_lm_device(d) container_of(d, struct lm_device, dev) |
| 18 | #define to_lm_driver(d) container_of(d, struct lm_driver, drv) |
| 19 | |
| 20 | static int lm_match(struct device *dev, struct device_driver *drv) |
| 21 | { |
| 22 | return 1; |
| 23 | } |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static int lm_bus_probe(struct device *dev) |
| 26 | { |
| 27 | struct lm_device *lmdev = to_lm_device(dev); |
| 28 | struct lm_driver *lmdrv = to_lm_driver(dev->driver); |
| 29 | |
| 30 | return lmdrv->probe(lmdev); |
| 31 | } |
| 32 | |
| 33 | static int lm_bus_remove(struct device *dev) |
| 34 | { |
| 35 | struct lm_device *lmdev = to_lm_device(dev); |
| 36 | struct lm_driver *lmdrv = to_lm_driver(dev->driver); |
| 37 | |
Russell King | 5c0784c | 2006-01-05 14:33:35 +0000 | [diff] [blame] | 38 | if (lmdrv->remove) |
| 39 | lmdrv->remove(lmdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
Russell King | 5c0784c | 2006-01-05 14:33:35 +0000 | [diff] [blame] | 43 | static struct bus_type lm_bustype = { |
| 44 | .name = "logicmodule", |
| 45 | .match = lm_match, |
| 46 | .probe = lm_bus_probe, |
| 47 | .remove = lm_bus_remove, |
| 48 | // .suspend = lm_bus_suspend, |
| 49 | // .resume = lm_bus_resume, |
| 50 | }; |
| 51 | |
| 52 | static int __init lm_init(void) |
| 53 | { |
| 54 | return bus_register(&lm_bustype); |
| 55 | } |
| 56 | |
| 57 | postcore_initcall(lm_init); |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | int lm_driver_register(struct lm_driver *drv) |
| 60 | { |
| 61 | drv->drv.bus = &lm_bustype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return driver_register(&drv->drv); |
| 63 | } |
| 64 | |
| 65 | void lm_driver_unregister(struct lm_driver *drv) |
| 66 | { |
| 67 | driver_unregister(&drv->drv); |
| 68 | } |
| 69 | |
| 70 | static void lm_device_release(struct device *dev) |
| 71 | { |
| 72 | struct lm_device *d = to_lm_device(dev); |
| 73 | |
| 74 | kfree(d); |
| 75 | } |
| 76 | |
| 77 | int lm_device_register(struct lm_device *dev) |
| 78 | { |
| 79 | int ret; |
| 80 | |
| 81 | dev->dev.release = lm_device_release; |
| 82 | dev->dev.bus = &lm_bustype; |
| 83 | |
Kay Sievers | 3f97870 | 2008-05-30 17:42:11 +0200 | [diff] [blame] | 84 | ret = dev_set_name(&dev->dev, "lm%d", dev->id); |
| 85 | if (ret) |
| 86 | return ret; |
| 87 | dev->resource.name = dev_name(&dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | ret = request_resource(&iomem_resource, &dev->resource); |
| 90 | if (ret == 0) { |
| 91 | ret = device_register(&dev->dev); |
| 92 | if (ret) |
| 93 | release_resource(&dev->resource); |
| 94 | } |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | EXPORT_SYMBOL(lm_driver_register); |
| 99 | EXPORT_SYMBOL(lm_driver_unregister); |