Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target...
[linux-2.6-block.git] / arch / arm / mach-imx / devices / platform-ipu-core.c
CommitLineData
afa77ef3
UKK
1/*
2 * Copyright (C) 2011 Pengutronix
3 * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 */
b7f080cf 9#include <linux/dma-mapping.h>
50f2de61
SG
10
11#include "../hardware.h"
e0557c0d 12#include "devices-common.h"
afa77ef3
UKK
13
14#define imx_ipu_core_entry_single(soc) \
15{ \
16 .iobase = soc ## _IPU_CTRL_BASE_ADDR, \
17 .synirq = soc ## _INT_IPU_SYN, \
18 .errirq = soc ## _INT_IPU_ERR, \
19}
20
21#ifdef CONFIG_SOC_IMX31
22const struct imx_ipu_core_data imx31_ipu_core_data __initconst =
23 imx_ipu_core_entry_single(MX31);
24#endif
25
26#ifdef CONFIG_SOC_IMX35
27const struct imx_ipu_core_data imx35_ipu_core_data __initconst =
28 imx_ipu_core_entry_single(MX35);
29#endif
30
31static struct platform_device *imx_ipu_coredev __initdata;
32
33struct platform_device *__init imx_add_ipu_core(
88289c80 34 const struct imx_ipu_core_data *data)
afa77ef3
UKK
35{
36 /* The resource order is important! */
37 struct resource res[] = {
38 {
39 .start = data->iobase,
40 .end = data->iobase + 0x5f,
41 .flags = IORESOURCE_MEM,
42 }, {
43 .start = data->iobase + 0x88,
44 .end = data->iobase + 0xb3,
45 .flags = IORESOURCE_MEM,
46 }, {
47 .start = data->synirq,
48 .end = data->synirq,
49 .flags = IORESOURCE_IRQ,
50 }, {
51 .start = data->errirq,
52 .end = data->errirq,
53 .flags = IORESOURCE_IRQ,
54 },
55 };
56
57 return imx_ipu_coredev = imx_add_platform_device("ipu-core", -1,
88289c80 58 res, ARRAY_SIZE(res), NULL, 0);
afa77ef3
UKK
59}
60
61struct platform_device *__init imx_alloc_mx3_camera(
62 const struct imx_ipu_core_data *data,
63 const struct mx3_camera_pdata *pdata)
64{
65 struct resource res[] = {
66 {
67 .start = data->iobase + 0x60,
68 .end = data->iobase + 0x87,
69 .flags = IORESOURCE_MEM,
70 },
71 };
72 int ret = -ENOMEM;
73 struct platform_device *pdev;
74
75 if (IS_ERR_OR_NULL(imx_ipu_coredev))
76 return ERR_PTR(-ENODEV);
77
78 pdev = platform_device_alloc("mx3-camera", 0);
79 if (!pdev)
d1d70e5d 80 return ERR_PTR(-ENOMEM);
afa77ef3
UKK
81
82 pdev->dev.dma_mask = kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
83 if (!pdev->dev.dma_mask)
84 goto err;
85
86 *pdev->dev.dma_mask = DMA_BIT_MASK(32);
87 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
88
89 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
90 if (ret)
91 goto err;
92
93 if (pdata) {
94 struct mx3_camera_pdata *copied_pdata;
95
96 ret = platform_device_add_data(pdev, pdata, sizeof(*pdata));
97 if (ret) {
98err:
99 kfree(pdev->dev.dma_mask);
100 platform_device_put(pdev);
101 return ERR_PTR(-ENODEV);
102 }
103 copied_pdata = dev_get_platdata(&pdev->dev);
104 copied_pdata->dma_dev = &imx_ipu_coredev->dev;
105 }
106
107 return pdev;
108}
109
110struct platform_device *__init imx_add_mx3_sdc_fb(
111 const struct imx_ipu_core_data *data,
112 struct mx3fb_platform_data *pdata)
113{
114 struct resource res[] = {
115 {
116 .start = data->iobase + 0xb4,
117 .end = data->iobase + 0x1bf,
118 .flags = IORESOURCE_MEM,
119 },
120 };
121
122 if (IS_ERR_OR_NULL(imx_ipu_coredev))
123 return ERR_PTR(-ENODEV);
124
125 pdata->dma_dev = &imx_ipu_coredev->dev;
126
127 return imx_add_platform_device_dmamask("mx3_sdc_fb", -1,
128 res, ARRAY_SIZE(res), pdata, sizeof(*pdata),
129 DMA_BIT_MASK(32));
130}