blob: 203854ddd1bb34df9ff90eae917c72515524aa41 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Manuel Lauss27dd65a2009-10-04 14:55:28 +02002/*
3 * devoard misc stuff.
4 */
5
6#include <linux/init.h>
Manuel Lauss206aa6c2009-10-19 12:53:37 +02007#include <linux/mtd/mtd.h>
8#include <linux/mtd/map.h>
9#include <linux/mtd/physmap.h>
Manuel Lauss27dd65a2009-10-04 14:55:28 +020010#include <linux/slab.h>
11#include <linux/platform_device.h>
Manuel Lauss32fd6902009-12-08 19:18:13 +010012#include <linux/pm.h>
13
Manuel Lauss278bf052012-01-21 18:13:14 +010014#include <asm/bootinfo.h>
Manuel Lauss092ea462014-08-20 21:36:30 +020015#include <asm/idle.h>
Manuel Lauss32fd6902009-12-08 19:18:13 +010016#include <asm/reboot.h>
Manuel Lauss278bf052012-01-21 18:13:14 +010017#include <asm/mach-au1x00/au1000.h>
Manuel Lauss32fd6902009-12-08 19:18:13 +010018#include <asm/mach-db1x00/bcsr.h>
19
Manuel Lauss278bf052012-01-21 18:13:14 +010020#include <prom.h>
21
22void __init prom_init(void)
23{
24 unsigned char *memsize_str;
25 unsigned long memsize;
26
27 prom_argc = (int)fw_arg0;
28 prom_argv = (char **)fw_arg1;
29 prom_envp = (char **)fw_arg2;
30
31 prom_init_cmdline();
32 memsize_str = prom_getenv("memsize");
33 if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
34 memsize = 64 << 20; /* all devboards have at least 64MB RAM */
35
36 add_memory_region(0, memsize, BOOT_MEM_RAM);
37}
38
39void prom_putchar(unsigned char c)
40{
Manuel Laussbd8510d2012-09-13 17:44:39 +020041 if (alchemy_get_cputype() == ALCHEMY_CPU_AU1300)
42 alchemy_uart_putchar(AU1300_UART2_PHYS_ADDR, c);
43 else
44 alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
Manuel Lauss278bf052012-01-21 18:13:14 +010045}
46
Manuel Lauss1c043f12011-11-10 12:06:22 +000047
48static struct platform_device db1x00_rtc_dev = {
49 .name = "rtc-au1xxx",
50 .id = -1,
51};
52
53
Manuel Lauss32fd6902009-12-08 19:18:13 +010054static void db1x_power_off(void)
55{
56 bcsr_write(BCSR_RESETS, 0);
57 bcsr_write(BCSR_SYSTEM, BCSR_SYSTEM_PWROFF | BCSR_SYSTEM_RESET);
Manuel Lauss092ea462014-08-20 21:36:30 +020058 while (1) /* sit and spin */
59 cpu_wait();
Manuel Lauss32fd6902009-12-08 19:18:13 +010060}
61
62static void db1x_reset(char *c)
63{
64 bcsr_write(BCSR_RESETS, 0);
65 bcsr_write(BCSR_SYSTEM, 0);
66}
67
Manuel Lauss1c043f12011-11-10 12:06:22 +000068static int __init db1x_late_setup(void)
Manuel Lauss32fd6902009-12-08 19:18:13 +010069{
70 if (!pm_power_off)
71 pm_power_off = db1x_power_off;
72 if (!_machine_halt)
73 _machine_halt = db1x_power_off;
74 if (!_machine_restart)
75 _machine_restart = db1x_reset;
76
Manuel Lauss1c043f12011-11-10 12:06:22 +000077 platform_device_register(&db1x00_rtc_dev);
78
Manuel Lauss32fd6902009-12-08 19:18:13 +010079 return 0;
80}
Manuel Lauss1c043f12011-11-10 12:06:22 +000081device_initcall(db1x_late_setup);
Manuel Lauss27dd65a2009-10-04 14:55:28 +020082
83/* register a pcmcia socket */
Manuel Lauss11b897c2010-02-24 17:40:21 +010084int __init db1x_register_pcmcia_socket(phys_addr_t pcmcia_attr_start,
85 phys_addr_t pcmcia_attr_end,
86 phys_addr_t pcmcia_mem_start,
87 phys_addr_t pcmcia_mem_end,
88 phys_addr_t pcmcia_io_start,
89 phys_addr_t pcmcia_io_end,
Manuel Lauss27dd65a2009-10-04 14:55:28 +020090 int card_irq,
91 int cd_irq,
92 int stschg_irq,
93 int eject_irq,
94 int id)
95{
96 int cnt, i, ret;
97 struct resource *sr;
98 struct platform_device *pd;
99
100 cnt = 5;
101 if (eject_irq)
102 cnt++;
103 if (stschg_irq)
104 cnt++;
105
Kees Cook6396bb22018-06-12 14:03:40 -0700106 sr = kcalloc(cnt, sizeof(struct resource), GFP_KERNEL);
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200107 if (!sr)
108 return -ENOMEM;
109
110 pd = platform_device_alloc("db1xxx_pcmcia", id);
111 if (!pd) {
112 ret = -ENOMEM;
113 goto out;
114 }
115
Manuel Lauss11b897c2010-02-24 17:40:21 +0100116 sr[0].name = "pcmcia-attr";
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200117 sr[0].flags = IORESOURCE_MEM;
Manuel Lauss11b897c2010-02-24 17:40:21 +0100118 sr[0].start = pcmcia_attr_start;
119 sr[0].end = pcmcia_attr_end;
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200120
Manuel Lauss11b897c2010-02-24 17:40:21 +0100121 sr[1].name = "pcmcia-mem";
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200122 sr[1].flags = IORESOURCE_MEM;
Manuel Lauss11b897c2010-02-24 17:40:21 +0100123 sr[1].start = pcmcia_mem_start;
124 sr[1].end = pcmcia_mem_end;
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200125
Manuel Lauss11b897c2010-02-24 17:40:21 +0100126 sr[2].name = "pcmcia-io";
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200127 sr[2].flags = IORESOURCE_MEM;
Manuel Lauss11b897c2010-02-24 17:40:21 +0100128 sr[2].start = pcmcia_io_start;
129 sr[2].end = pcmcia_io_end;
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200130
131 sr[3].name = "insert";
132 sr[3].flags = IORESOURCE_IRQ;
133 sr[3].start = sr[3].end = cd_irq;
134
135 sr[4].name = "card";
136 sr[4].flags = IORESOURCE_IRQ;
137 sr[4].start = sr[4].end = card_irq;
138
139 i = 5;
140 if (stschg_irq) {
Manuel Lauss11b897c2010-02-24 17:40:21 +0100141 sr[i].name = "stschg";
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200142 sr[i].flags = IORESOURCE_IRQ;
Manuel Lauss11b897c2010-02-24 17:40:21 +0100143 sr[i].start = sr[i].end = stschg_irq;
Manuel Lauss27dd65a2009-10-04 14:55:28 +0200144 i++;
145 }
146 if (eject_irq) {
147 sr[i].name = "eject";
148 sr[i].flags = IORESOURCE_IRQ;
149 sr[i].start = sr[i].end = eject_irq;
150 }
151
152 pd->resource = sr;
153 pd->num_resources = cnt;
154
155 ret = platform_device_add(pd);
156 if (!ret)
157 return 0;
158
159 platform_device_put(pd);
160out:
161 kfree(sr);
162 return ret;
163}
Manuel Lauss206aa6c2009-10-19 12:53:37 +0200164
165#define YAMON_SIZE 0x00100000
166#define YAMON_ENV_SIZE 0x00040000
167
168int __init db1x_register_norflash(unsigned long size, int width,
169 int swapped)
170{
171 struct physmap_flash_data *pfd;
172 struct platform_device *pd;
173 struct mtd_partition *parts;
174 struct resource *res;
175 int ret, i;
176
177 if (size < (8 * 1024 * 1024))
178 return -EINVAL;
179
180 ret = -ENOMEM;
Kees Cook6396bb22018-06-12 14:03:40 -0700181 parts = kcalloc(5, sizeof(struct mtd_partition), GFP_KERNEL);
Manuel Lauss206aa6c2009-10-19 12:53:37 +0200182 if (!parts)
183 goto out;
184
185 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
186 if (!res)
187 goto out1;
188
189 pfd = kzalloc(sizeof(struct physmap_flash_data), GFP_KERNEL);
190 if (!pfd)
191 goto out2;
192
193 pd = platform_device_alloc("physmap-flash", 0);
194 if (!pd)
195 goto out3;
196
197 /* NOR flash ends at 0x20000000, regardless of size */
198 res->start = 0x20000000 - size;
199 res->end = 0x20000000 - 1;
200 res->flags = IORESOURCE_MEM;
201
202 /* partition setup. Most Develboards have a switch which allows
203 * to swap the physical locations of the 2 NOR flash banks.
204 */
205 i = 0;
206 if (!swapped) {
207 /* first NOR chip */
208 parts[i].offset = 0;
209 parts[i].name = "User FS";
210 parts[i].size = size / 2;
211 i++;
212 }
213
214 parts[i].offset = MTDPART_OFS_APPEND;
215 parts[i].name = "User FS 2";
216 parts[i].size = (size / 2) - (0x20000000 - 0x1fc00000);
217 i++;
218
219 parts[i].offset = MTDPART_OFS_APPEND;
220 parts[i].name = "YAMON";
221 parts[i].size = YAMON_SIZE;
222 parts[i].mask_flags = MTD_WRITEABLE;
223 i++;
224
225 parts[i].offset = MTDPART_OFS_APPEND;
226 parts[i].name = "raw kernel";
227 parts[i].size = 0x00400000 - YAMON_SIZE - YAMON_ENV_SIZE;
228 i++;
229
230 parts[i].offset = MTDPART_OFS_APPEND;
231 parts[i].name = "YAMON Env";
232 parts[i].size = YAMON_ENV_SIZE;
233 parts[i].mask_flags = MTD_WRITEABLE;
234 i++;
235
236 if (swapped) {
237 parts[i].offset = MTDPART_OFS_APPEND;
238 parts[i].name = "User FS";
239 parts[i].size = size / 2;
240 i++;
241 }
242
243 pfd->width = width;
244 pfd->parts = parts;
245 pfd->nr_parts = 5;
246
247 pd->dev.platform_data = pfd;
248 pd->resource = res;
249 pd->num_resources = 1;
250
251 ret = platform_device_add(pd);
252 if (!ret)
253 return ret;
254
255 platform_device_put(pd);
256out3:
257 kfree(pfd);
258out2:
259 kfree(res);
260out1:
261 kfree(parts);
262out:
263 return ret;
264}