Root/
1 | /* |
2 | * UWB Multi-interface Controller device management. |
3 | * |
4 | * Copyright (C) 2007 Cambridge Silicon Radio Ltd. |
5 | * |
6 | * This file is released under the GNU GPL v2. |
7 | */ |
8 | #include <linux/kernel.h> |
9 | #include <linux/export.h> |
10 | #include <linux/slab.h> |
11 | #include <linux/uwb/umc.h> |
12 | |
13 | static void umc_device_release(struct device *dev) |
14 | { |
15 | struct umc_dev *umc = to_umc_dev(dev); |
16 | |
17 | kfree(umc); |
18 | } |
19 | |
20 | /** |
21 | * umc_device_create - allocate a child UMC device |
22 | * @parent: parent of the new UMC device. |
23 | * @n: index of the new device. |
24 | * |
25 | * The new UMC device will have a bus ID of the parent with '-n' |
26 | * appended. |
27 | */ |
28 | struct umc_dev *umc_device_create(struct device *parent, int n) |
29 | { |
30 | struct umc_dev *umc; |
31 | |
32 | umc = kzalloc(sizeof(struct umc_dev), GFP_KERNEL); |
33 | if (umc) { |
34 | dev_set_name(&umc->dev, "%s-%d", dev_name(parent), n); |
35 | umc->dev.parent = parent; |
36 | umc->dev.bus = &umc_bus_type; |
37 | umc->dev.release = umc_device_release; |
38 | |
39 | umc->dev.dma_mask = parent->dma_mask; |
40 | } |
41 | return umc; |
42 | } |
43 | EXPORT_SYMBOL_GPL(umc_device_create); |
44 | |
45 | /** |
46 | * umc_device_register - register a UMC device |
47 | * @umc: pointer to the UMC device |
48 | * |
49 | * The memory resource for the UMC device is acquired and the device |
50 | * registered with the system. |
51 | */ |
52 | int umc_device_register(struct umc_dev *umc) |
53 | { |
54 | int err; |
55 | |
56 | err = request_resource(umc->resource.parent, &umc->resource); |
57 | if (err < 0) { |
58 | dev_err(&umc->dev, "can't allocate resource range %pR: %d\n", |
59 | &umc->resource, err); |
60 | goto error_request_resource; |
61 | } |
62 | |
63 | err = device_register(&umc->dev); |
64 | if (err < 0) |
65 | goto error_device_register; |
66 | return 0; |
67 | |
68 | error_device_register: |
69 | release_resource(&umc->resource); |
70 | error_request_resource: |
71 | return err; |
72 | } |
73 | EXPORT_SYMBOL_GPL(umc_device_register); |
74 | |
75 | /** |
76 | * umc_device_unregister - unregister a UMC device |
77 | * @umc: pointer to the UMC device |
78 | * |
79 | * First we unregister the device, make sure the driver can do it's |
80 | * resource release thing and then we try to release any left over |
81 | * resources. We take a ref to the device, to make sure it doesn't |
82 | * disappear under our feet. |
83 | */ |
84 | void umc_device_unregister(struct umc_dev *umc) |
85 | { |
86 | struct device *dev; |
87 | if (!umc) |
88 | return; |
89 | dev = get_device(&umc->dev); |
90 | device_unregister(&umc->dev); |
91 | release_resource(&umc->resource); |
92 | put_device(dev); |
93 | } |
94 | EXPORT_SYMBOL_GPL(umc_device_unregister); |
95 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9