1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/kernel.h>
20#include <linux/slab.h>
21#include <linux/init.h>
22#include <linux/platform_device.h>
23#include <linux/amba/bus.h>
24
25struct platform_device *__init mxs_add_platform_device_dmamask(
26 const char *name, int id,
27 const struct resource *res, unsigned int num_resources,
28 const void *data, size_t size_data, u64 dmamask)
29{
30 int ret = -ENOMEM;
31 struct platform_device *pdev;
32
33 pdev = platform_device_alloc(name, id);
34 if (!pdev)
35 goto err;
36
37 if (dmamask) {
38
39
40
41
42
43
44 pdev->dev.dma_mask =
45 kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
46 if (!pdev->dev.dma_mask)
47
48 goto err;
49
50 *pdev->dev.dma_mask = dmamask;
51 pdev->dev.coherent_dma_mask = dmamask;
52 }
53
54 if (res) {
55 ret = platform_device_add_resources(pdev, res, num_resources);
56 if (ret)
57 goto err;
58 }
59
60 if (data) {
61 ret = platform_device_add_data(pdev, data, size_data);
62 if (ret)
63 goto err;
64 }
65
66 ret = platform_device_add(pdev);
67 if (ret) {
68err:
69 platform_device_put(pdev);
70 return ERR_PTR(ret);
71 }
72
73 return pdev;
74}
75
76int __init mxs_add_amba_device(const struct amba_device *dev)
77{
78 struct amba_device *adev = kmalloc(sizeof(*adev), GFP_KERNEL);
79
80 if (!adev) {
81 pr_err("%s: failed to allocate memory", __func__);
82 return -ENOMEM;
83 }
84
85 *adev = *dev;
86
87 return amba_device_register(adev, &iomem_resource);
88}
89