• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/arch/arm/mach-mmp/
1/*
2 * linux/arch/arm/mach-mmp/devices.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/init.h>
10#include <linux/platform_device.h>
11#include <linux/dma-mapping.h>
12
13#include <asm/irq.h>
14#include <mach/devices.h>
15
16int __init pxa_register_device(struct pxa_device_desc *desc,
17				void *data, size_t size)
18{
19	struct platform_device *pdev;
20	struct resource res[2 + MAX_RESOURCE_DMA];
21	int i, ret = 0, nres = 0;
22
23	pdev = platform_device_alloc(desc->drv_name, desc->id);
24	if (pdev == NULL)
25		return -ENOMEM;
26
27	pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
28
29	memset(res, 0, sizeof(res));
30
31	if (desc->start != -1ul && desc->size > 0) {
32		res[nres].start	= desc->start;
33		res[nres].end	= desc->start + desc->size - 1;
34		res[nres].flags	= IORESOURCE_MEM;
35		nres++;
36	}
37
38	if (desc->irq != NO_IRQ) {
39		res[nres].start	= desc->irq;
40		res[nres].end	= desc->irq;
41		res[nres].flags	= IORESOURCE_IRQ;
42		nres++;
43	}
44
45	for (i = 0; i < MAX_RESOURCE_DMA; i++, nres++) {
46		if (desc->dma[i] == 0)
47			break;
48
49		res[nres].start	= desc->dma[i];
50		res[nres].end	= desc->dma[i];
51		res[nres].flags	= IORESOURCE_DMA;
52	}
53
54	ret = platform_device_add_resources(pdev, res, nres);
55	if (ret) {
56		platform_device_put(pdev);
57		return ret;
58	}
59
60	if (data && size) {
61		ret = platform_device_add_data(pdev, data, size);
62		if (ret) {
63			platform_device_put(pdev);
64			return ret;
65		}
66	}
67
68	return platform_device_add(pdev);
69}
70