]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/mips/mti-sead3/sead3-platform.c
9f9e91471f178df97d2facc6d63824ae24b4e1ca
[karo-tx-linux.git] / arch / mips / mti-sead3 / sead3-platform.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2012 MIPS Technologies, Inc.  All rights reserved.
7  */
8 #include <linux/dma-mapping.h>
9 #include <linux/init.h>
10 #include <linux/irq.h>
11 #include <linux/irqchip/mips-gic.h>
12 #include <linux/irqdomain.h>
13 #include <linux/leds.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/of.h>
16 #include <linux/platform_device.h>
17
18 #include <asm/mips-boards/sead3int.h>
19
20 static struct mtd_partition sead3_mtd_partitions[] = {
21         {
22                 .name =         "User FS",
23                 .offset =       0x00000000,
24                 .size =         0x01fc0000,
25         }, {
26                 .name =         "Board Config",
27                 .offset =       0x01fc0000,
28                 .size =         0x00040000,
29                 .mask_flags =   MTD_WRITEABLE
30         },
31 };
32
33 static struct physmap_flash_data sead3_flash_data = {
34         .width          = 4,
35         .nr_parts       = ARRAY_SIZE(sead3_mtd_partitions),
36         .parts          = sead3_mtd_partitions
37 };
38
39 static struct resource sead3_flash_resource = {
40         .start          = 0x1c000000,
41         .end            = 0x1dffffff,
42         .flags          = IORESOURCE_MEM
43 };
44
45 static struct platform_device sead3_flash = {
46         .name           = "physmap-flash",
47         .id             = 0,
48         .dev            = {
49                 .platform_data  = &sead3_flash_data,
50         },
51         .num_resources  = 1,
52         .resource       = &sead3_flash_resource,
53 };
54
55 #define LEDFLAGS(bits, shift)           \
56         ((bits << 8) | (shift << 8))
57
58 #define LEDBITS(id, shift, bits)        \
59         .name = id #shift,              \
60         .flags = LEDFLAGS(bits, shift)
61
62 static struct led_info led_data_info[] = {
63         { LEDBITS("bit", 0, 1) },
64         { LEDBITS("bit", 1, 1) },
65         { LEDBITS("bit", 2, 1) },
66         { LEDBITS("bit", 3, 1) },
67         { LEDBITS("bit", 4, 1) },
68         { LEDBITS("bit", 5, 1) },
69         { LEDBITS("bit", 6, 1) },
70         { LEDBITS("bit", 7, 1) },
71         { LEDBITS("all", 0, 8) },
72 };
73
74 static struct led_platform_data led_data = {
75         .num_leds       = ARRAY_SIZE(led_data_info),
76         .leds           = led_data_info
77 };
78
79 static struct resource pled_resources[] = {
80         {
81                 .start  = 0x1f000210,
82                 .end    = 0x1f000217,
83                 .flags  = IORESOURCE_MEM
84         }
85 };
86
87 static struct platform_device pled_device = {
88         .name                   = "sead3::pled",
89         .id                     = 0,
90         .dev                    = {
91                 .platform_data  = &led_data,
92         },
93         .num_resources          = ARRAY_SIZE(pled_resources),
94         .resource               = pled_resources
95 };
96
97
98 static struct resource fled_resources[] = {
99         {
100                 .start                  = 0x1f000218,
101                 .end                    = 0x1f00021f,
102                 .flags                  = IORESOURCE_MEM
103         }
104 };
105
106 static struct platform_device fled_device = {
107         .name                   = "sead3::fled",
108         .id                     = 0,
109         .dev                    = {
110                 .platform_data  = &led_data,
111         },
112         .num_resources          = ARRAY_SIZE(fled_resources),
113         .resource               = fled_resources
114 };
115
116 static struct platform_device sead3_led_device = {
117         .name   = "sead3-led",
118         .id     = -1,
119 };
120
121 static struct resource ehci_resources[] = {
122         {
123                 .start                  = 0x1b200000,
124                 .end                    = 0x1b200fff,
125                 .flags                  = IORESOURCE_MEM
126         }, {
127                 .flags                  = IORESOURCE_IRQ
128         }
129 };
130
131 static u64 sead3_usbdev_dma_mask = DMA_BIT_MASK(32);
132
133 static struct platform_device ehci_device = {
134         .name           = "sead3-ehci",
135         .id             = 0,
136         .dev            = {
137                 .dma_mask               = &sead3_usbdev_dma_mask,
138                 .coherent_dma_mask      = DMA_BIT_MASK(32)
139         },
140         .num_resources  = ARRAY_SIZE(ehci_resources),
141         .resource       = ehci_resources
142 };
143
144 static struct platform_device *sead3_platform_devices[] __initdata = {
145         &sead3_flash,
146         &pled_device,
147         &fled_device,
148         &sead3_led_device,
149         &ehci_device,
150 };
151
152 static int __init sead3_platforms_device_init(void)
153 {
154         const char *intc_compat;
155         struct device_node *node;
156         struct irq_domain *irqd;
157
158         if (gic_present)
159                 intc_compat = "mti,gic";
160         else
161                 intc_compat = "mti,cpu-interrupt-controller";
162
163         node = of_find_compatible_node(NULL, NULL, intc_compat);
164         if (!node) {
165                 pr_err("unable to find interrupt controller DT node\n");
166                 return -ENODEV;
167         }
168
169         irqd = irq_find_host(node);
170         if (!irqd) {
171                 pr_err("unable to find interrupt controller IRQ domain\n");
172                 return -ENODEV;
173         }
174
175         if (gic_present) {
176                 ehci_resources[1].start =
177                         irq_create_mapping(irqd, GIC_INT_EHCI);
178         } else {
179                 ehci_resources[1].start =
180                         irq_create_mapping(irqd, CPU_INT_EHCI);
181         }
182
183         return platform_add_devices(sead3_platform_devices,
184                                     ARRAY_SIZE(sead3_platform_devices));
185 }
186
187 device_initcall(sead3_platforms_device_init);