Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
umc-dev.c
Go to the documentation of this file.
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 
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 }
44 
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:
70 error_request_resource:
71  return err;
72 }
74 
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);
92  put_device(dev);
93 }