diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2008-04-28 18:33:54 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2008-04-29 03:22:16 -0400 |
commit | bda1e4e5a3d976046378cd495a63e1ee0847deec (patch) | |
tree | d646e0057940116440d8f2c53ea7fc225d97a0a0 /drivers/pnp/core.c | |
parent | 25eb846189d20db4114cebf14fee96d69bef4667 (diff) |
PNP: add pnp_alloc_dev()
Add pnp_alloc_dev() to allocate a struct pnp_dev and fill in the
protocol, instance number, and initial PNP ID. Now it is always
valid to use dev_printk() on any pnp_dev pointer.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/pnp/core.c')
-rw-r--r-- | drivers/pnp/core.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c index 7d366ca672d3..cf37701a4f9e 100644 --- a/drivers/pnp/core.c +++ b/drivers/pnp/core.c | |||
@@ -109,15 +109,42 @@ static void pnp_release_device(struct device *dmdev) | |||
109 | kfree(dev); | 109 | kfree(dev); |
110 | } | 110 | } |
111 | 111 | ||
112 | int __pnp_add_device(struct pnp_dev *dev) | 112 | struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid) |
113 | { | 113 | { |
114 | int ret; | 114 | struct pnp_dev *dev; |
115 | struct pnp_id *dev_id; | ||
115 | 116 | ||
116 | pnp_fixup_device(dev); | 117 | dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); |
118 | if (!dev) | ||
119 | return NULL; | ||
120 | |||
121 | dev->protocol = protocol; | ||
122 | dev->number = id; | ||
123 | dev->dma_mask = DMA_24BIT_MASK; | ||
124 | |||
125 | dev->dev.parent = &dev->protocol->dev; | ||
117 | dev->dev.bus = &pnp_bus_type; | 126 | dev->dev.bus = &pnp_bus_type; |
118 | dev->dev.dma_mask = &dev->dma_mask; | 127 | dev->dev.dma_mask = &dev->dma_mask; |
119 | dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK; | 128 | dev->dev.coherent_dma_mask = dev->dma_mask; |
120 | dev->dev.release = &pnp_release_device; | 129 | dev->dev.release = &pnp_release_device; |
130 | |||
131 | sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number, | ||
132 | dev->number); | ||
133 | |||
134 | dev_id = pnp_add_id(dev, pnpid); | ||
135 | if (!dev_id) { | ||
136 | kfree(dev); | ||
137 | return NULL; | ||
138 | } | ||
139 | |||
140 | return dev; | ||
141 | } | ||
142 | |||
143 | int __pnp_add_device(struct pnp_dev *dev) | ||
144 | { | ||
145 | int ret; | ||
146 | |||
147 | pnp_fixup_device(dev); | ||
121 | dev->status = PNP_READY; | 148 | dev->status = PNP_READY; |
122 | spin_lock(&pnp_lock); | 149 | spin_lock(&pnp_lock); |
123 | list_add_tail(&dev->global_list, &pnp_global); | 150 | list_add_tail(&dev->global_list, &pnp_global); |
@@ -145,9 +172,6 @@ int pnp_add_device(struct pnp_dev *dev) | |||
145 | if (dev->card) | 172 | if (dev->card) |
146 | return -EINVAL; | 173 | return -EINVAL; |
147 | 174 | ||
148 | dev->dev.parent = &dev->protocol->dev; | ||
149 | sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number, | ||
150 | dev->number); | ||
151 | ret = __pnp_add_device(dev); | 175 | ret = __pnp_add_device(dev); |
152 | if (ret) | 176 | if (ret) |
153 | return ret; | 177 | return ret; |