Uwe Kleine-König | afa77ef | 2011-03-03 21:32:02 +0100 | [diff] [blame] | 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 | */ |
| 9 | #include <mach/hardware.h> |
| 10 | #include <mach/devices-common.h> |
| 11 | |
| 12 | #define imx_ipu_core_entry_single(soc) \ |
| 13 | { \ |
| 14 | .iobase = soc ## _IPU_CTRL_BASE_ADDR, \ |
| 15 | .synirq = soc ## _INT_IPU_SYN, \ |
| 16 | .errirq = soc ## _INT_IPU_ERR, \ |
| 17 | } |
| 18 | |
| 19 | #ifdef CONFIG_SOC_IMX31 |
| 20 | const struct imx_ipu_core_data imx31_ipu_core_data __initconst = |
| 21 | imx_ipu_core_entry_single(MX31); |
| 22 | #endif |
| 23 | |
| 24 | #ifdef CONFIG_SOC_IMX35 |
| 25 | const struct imx_ipu_core_data imx35_ipu_core_data __initconst = |
| 26 | imx_ipu_core_entry_single(MX35); |
| 27 | #endif |
| 28 | |
| 29 | static struct platform_device *imx_ipu_coredev __initdata; |
| 30 | |
| 31 | struct platform_device *__init imx_add_ipu_core( |
| 32 | const struct imx_ipu_core_data *data, |
| 33 | const struct ipu_platform_data *pdata) |
| 34 | { |
| 35 | /* The resource order is important! */ |
| 36 | struct resource res[] = { |
| 37 | { |
| 38 | .start = data->iobase, |
| 39 | .end = data->iobase + 0x5f, |
| 40 | .flags = IORESOURCE_MEM, |
| 41 | }, { |
| 42 | .start = data->iobase + 0x88, |
| 43 | .end = data->iobase + 0xb3, |
| 44 | .flags = IORESOURCE_MEM, |
| 45 | }, { |
| 46 | .start = data->synirq, |
| 47 | .end = data->synirq, |
| 48 | .flags = IORESOURCE_IRQ, |
| 49 | }, { |
| 50 | .start = data->errirq, |
| 51 | .end = data->errirq, |
| 52 | .flags = IORESOURCE_IRQ, |
| 53 | }, |
| 54 | }; |
| 55 | |
| 56 | return imx_ipu_coredev = imx_add_platform_device("ipu-core", -1, |
| 57 | res, ARRAY_SIZE(res), pdata, sizeof(*pdata)); |
| 58 | } |
| 59 | |
| 60 | struct platform_device *__init imx_alloc_mx3_camera( |
| 61 | const struct imx_ipu_core_data *data, |
| 62 | const struct mx3_camera_pdata *pdata) |
| 63 | { |
| 64 | struct resource res[] = { |
| 65 | { |
| 66 | .start = data->iobase + 0x60, |
| 67 | .end = data->iobase + 0x87, |
| 68 | .flags = IORESOURCE_MEM, |
| 69 | }, |
| 70 | }; |
| 71 | int ret = -ENOMEM; |
| 72 | struct platform_device *pdev; |
| 73 | |
| 74 | if (IS_ERR_OR_NULL(imx_ipu_coredev)) |
| 75 | return ERR_PTR(-ENODEV); |
| 76 | |
| 77 | pdev = platform_device_alloc("mx3-camera", 0); |
| 78 | if (!pdev) |
| 79 | goto err; |
| 80 | |
| 81 | pdev->dev.dma_mask = kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL); |
| 82 | if (!pdev->dev.dma_mask) |
| 83 | goto err; |
| 84 | |
| 85 | *pdev->dev.dma_mask = DMA_BIT_MASK(32); |
| 86 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 87 | |
| 88 | ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); |
| 89 | if (ret) |
| 90 | goto err; |
| 91 | |
| 92 | if (pdata) { |
| 93 | struct mx3_camera_pdata *copied_pdata; |
| 94 | |
| 95 | ret = platform_device_add_data(pdev, pdata, sizeof(*pdata)); |
| 96 | if (ret) { |
| 97 | err: |
| 98 | kfree(pdev->dev.dma_mask); |
| 99 | platform_device_put(pdev); |
| 100 | return ERR_PTR(-ENODEV); |
| 101 | } |
| 102 | copied_pdata = dev_get_platdata(&pdev->dev); |
| 103 | copied_pdata->dma_dev = &imx_ipu_coredev->dev; |
| 104 | } |
| 105 | |
| 106 | return pdev; |
| 107 | } |
| 108 | |
| 109 | struct platform_device *__init imx_add_mx3_sdc_fb( |
| 110 | const struct imx_ipu_core_data *data, |
| 111 | struct mx3fb_platform_data *pdata) |
| 112 | { |
| 113 | struct resource res[] = { |
| 114 | { |
| 115 | .start = data->iobase + 0xb4, |
| 116 | .end = data->iobase + 0x1bf, |
| 117 | .flags = IORESOURCE_MEM, |
| 118 | }, |
| 119 | }; |
| 120 | |
| 121 | if (IS_ERR_OR_NULL(imx_ipu_coredev)) |
| 122 | return ERR_PTR(-ENODEV); |
| 123 | |
| 124 | pdata->dma_dev = &imx_ipu_coredev->dev; |
| 125 | |
| 126 | return imx_add_platform_device_dmamask("mx3_sdc_fb", -1, |
| 127 | res, ARRAY_SIZE(res), pdata, sizeof(*pdata), |
| 128 | DMA_BIT_MASK(32)); |
| 129 | } |