diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2008-04-28 18:34:13 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2008-04-29 03:22:23 -0400 |
commit | d948a8daa059cf5b3e7f002e7b92acf00fc70c49 (patch) | |
tree | a7fed0c0d5f4b599a6999f58619e2d8df1e68852 /drivers/pnp | |
parent | af11cb2d521f9d7e10c565bafe8f2358772baa65 (diff) |
PNP: factor pnp_init_resource_table() and pnp_clean_resource_table()
Move the common part of pnp_init_resource_table() and
pnp_clean_resource_table() into a new pnp_init_resource().
This reduces a little code duplication and will be
useful later to initialize an individual resource.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/pnp')
-rw-r--r-- | drivers/pnp/base.h | 2 | ||||
-rw-r--r-- | drivers/pnp/manager.c | 98 |
2 files changed, 54 insertions, 46 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index 0c5cb1d58c6c..eb43fc6bff11 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h | |||
@@ -18,3 +18,5 @@ int pnp_check_irq(struct pnp_dev * dev, int idx); | |||
18 | int pnp_check_dma(struct pnp_dev * dev, int idx); | 18 | int pnp_check_dma(struct pnp_dev * dev, int idx); |
19 | 19 | ||
20 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); | 20 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); |
21 | |||
22 | void pnp_init_resource(struct resource *res); | ||
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c index d407c07b5b9d..8267efd679a1 100644 --- a/drivers/pnp/manager.c +++ b/drivers/pnp/manager.c | |||
@@ -234,42 +234,52 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) | |||
234 | dev_dbg(&dev->dev, " disable dma %d\n", idx); | 234 | dev_dbg(&dev->dev, " disable dma %d\n", idx); |
235 | } | 235 | } |
236 | 236 | ||
237 | void pnp_init_resource(struct resource *res) | ||
238 | { | ||
239 | unsigned long type; | ||
240 | |||
241 | type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM | | ||
242 | IORESOURCE_IRQ | IORESOURCE_DMA); | ||
243 | |||
244 | res->name = NULL; | ||
245 | res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
246 | if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) { | ||
247 | res->start = -1; | ||
248 | res->end = -1; | ||
249 | } else { | ||
250 | res->start = 0; | ||
251 | res->end = 0; | ||
252 | } | ||
253 | } | ||
254 | |||
237 | /** | 255 | /** |
238 | * pnp_init_resources - Resets a resource table to default values. | 256 | * pnp_init_resources - Resets a resource table to default values. |
239 | * @table: pointer to the desired resource table | 257 | * @table: pointer to the desired resource table |
240 | */ | 258 | */ |
241 | void pnp_init_resources(struct pnp_dev *dev) | 259 | void pnp_init_resources(struct pnp_dev *dev) |
242 | { | 260 | { |
243 | struct pnp_resource_table *table = &dev->res; | 261 | struct resource *res; |
244 | int idx; | 262 | int idx; |
245 | 263 | ||
246 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { | 264 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { |
247 | table->irq_resource[idx].name = NULL; | 265 | res = &dev->res.irq_resource[idx]; |
248 | table->irq_resource[idx].start = -1; | 266 | res->flags = IORESOURCE_IRQ; |
249 | table->irq_resource[idx].end = -1; | 267 | pnp_init_resource(res); |
250 | table->irq_resource[idx].flags = | ||
251 | IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
252 | } | 268 | } |
253 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { | 269 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { |
254 | table->dma_resource[idx].name = NULL; | 270 | res = &dev->res.dma_resource[idx]; |
255 | table->dma_resource[idx].start = -1; | 271 | res->flags = IORESOURCE_DMA; |
256 | table->dma_resource[idx].end = -1; | 272 | pnp_init_resource(res); |
257 | table->dma_resource[idx].flags = | ||
258 | IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
259 | } | 273 | } |
260 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { | 274 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { |
261 | table->port_resource[idx].name = NULL; | 275 | res = &dev->res.port_resource[idx]; |
262 | table->port_resource[idx].start = 0; | 276 | res->flags = IORESOURCE_IO; |
263 | table->port_resource[idx].end = 0; | 277 | pnp_init_resource(res); |
264 | table->port_resource[idx].flags = | ||
265 | IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
266 | } | 278 | } |
267 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { | 279 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { |
268 | table->mem_resource[idx].name = NULL; | 280 | res = &dev->res.mem_resource[idx]; |
269 | table->mem_resource[idx].start = 0; | 281 | res->flags = IORESOURCE_MEM; |
270 | table->mem_resource[idx].end = 0; | 282 | pnp_init_resource(res); |
271 | table->mem_resource[idx].flags = | ||
272 | IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
273 | } | 283 | } |
274 | } | 284 | } |
275 | 285 | ||
@@ -279,40 +289,36 @@ void pnp_init_resources(struct pnp_dev *dev) | |||
279 | */ | 289 | */ |
280 | static void pnp_clean_resource_table(struct pnp_dev *dev) | 290 | static void pnp_clean_resource_table(struct pnp_dev *dev) |
281 | { | 291 | { |
282 | struct pnp_resource_table *res = &dev->res; | 292 | struct resource *res; |
283 | int idx; | 293 | int idx; |
284 | 294 | ||
285 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { | 295 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { |
286 | if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO)) | 296 | res = &dev->res.irq_resource[idx]; |
287 | continue; | 297 | if (res->flags & IORESOURCE_AUTO) { |
288 | res->irq_resource[idx].start = -1; | 298 | res->flags = IORESOURCE_IRQ; |
289 | res->irq_resource[idx].end = -1; | 299 | pnp_init_resource(res); |
290 | res->irq_resource[idx].flags = | 300 | } |
291 | IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
292 | } | 301 | } |
293 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { | 302 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { |
294 | if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO)) | 303 | res = &dev->res.dma_resource[idx]; |
295 | continue; | 304 | if (res->flags & IORESOURCE_AUTO) { |
296 | res->dma_resource[idx].start = -1; | 305 | res->flags = IORESOURCE_DMA; |
297 | res->dma_resource[idx].end = -1; | 306 | pnp_init_resource(res); |
298 | res->dma_resource[idx].flags = | 307 | } |
299 | IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
300 | } | 308 | } |
301 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { | 309 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { |
302 | if (!(res->port_resource[idx].flags & IORESOURCE_AUTO)) | 310 | res = &dev->res.port_resource[idx]; |
303 | continue; | 311 | if (res->flags & IORESOURCE_AUTO) { |
304 | res->port_resource[idx].start = 0; | 312 | res->flags = IORESOURCE_IO; |
305 | res->port_resource[idx].end = 0; | 313 | pnp_init_resource(res); |
306 | res->port_resource[idx].flags = | 314 | } |
307 | IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
308 | } | 315 | } |
309 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { | 316 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { |
310 | if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO)) | 317 | res = &dev->res.mem_resource[idx]; |
311 | continue; | 318 | if (res->flags & IORESOURCE_AUTO) { |
312 | res->mem_resource[idx].start = 0; | 319 | res->flags = IORESOURCE_MEM; |
313 | res->mem_resource[idx].end = 0; | 320 | pnp_init_resource(res); |
314 | res->mem_resource[idx].flags = | 321 | } |
315 | IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET; | ||
316 | } | 322 | } |
317 | } | 323 | } |
318 | 324 | ||