blob: 1468b6af96e2f0d65e29d24acd1d21bfec795876 [file] [log] [blame]
Manuel Lauss64cd04d2011-11-10 12:03:26 +00001/*
2 * DBAu1300 init and platform device setup.
3 *
4 * (c) 2009 Manuel Lauss <manuel.lauss@googlemail.com>
5 */
6
Manuel Lauss415e0fe2014-07-23 16:36:52 +02007#include <linux/clk.h>
Manuel Lauss64cd04d2011-11-10 12:03:26 +00008#include <linux/dma-mapping.h>
9#include <linux/gpio.h>
10#include <linux/gpio_keys.h>
11#include <linux/init.h>
12#include <linux/input.h> /* KEY_* codes */
13#include <linux/i2c.h>
14#include <linux/io.h>
15#include <linux/leds.h>
Ulf Hanssond815cf82017-01-13 14:14:05 +010016#include <linux/interrupt.h>
Manuel Lauss64cd04d2011-11-10 12:03:26 +000017#include <linux/ata_platform.h>
18#include <linux/mmc/host.h>
19#include <linux/module.h>
20#include <linux/mtd/mtd.h>
21#include <linux/mtd/nand.h>
22#include <linux/mtd/partitions.h>
23#include <linux/platform_device.h>
24#include <linux/smsc911x.h>
Manuel Laussc64bb5f2014-08-20 21:36:33 +020025#include <linux/wm97xx.h>
Manuel Lauss64cd04d2011-11-10 12:03:26 +000026
27#include <asm/mach-au1x00/au1000.h>
Alban Bedel832f5da2015-08-02 18:30:11 +020028#include <asm/mach-au1x00/gpio-au1300.h>
Manuel Lauss64cd04d2011-11-10 12:03:26 +000029#include <asm/mach-au1x00/au1100_mmc.h>
Manuel Laussa9b71a82011-11-10 12:06:21 +000030#include <asm/mach-au1x00/au1200fb.h>
Manuel Lauss64cd04d2011-11-10 12:03:26 +000031#include <asm/mach-au1x00/au1xxx_dbdma.h>
32#include <asm/mach-au1x00/au1xxx_psc.h>
Manuel Lauss64cd04d2011-11-10 12:03:26 +000033#include <asm/mach-db1x00/bcsr.h>
34#include <asm/mach-au1x00/prom.h>
35
36#include "platform.h"
37
Manuel Laussa16afa52014-03-26 10:41:48 +010038/* FPGA (external mux) interrupt sources */
39#define DB1300_FIRST_INT (ALCHEMY_GPIC_INT_LAST + 1)
40#define DB1300_IDE_INT (DB1300_FIRST_INT + 0)
41#define DB1300_ETH_INT (DB1300_FIRST_INT + 1)
42#define DB1300_CF_INT (DB1300_FIRST_INT + 2)
43#define DB1300_VIDEO_INT (DB1300_FIRST_INT + 4)
44#define DB1300_HDMI_INT (DB1300_FIRST_INT + 5)
45#define DB1300_DC_INT (DB1300_FIRST_INT + 6)
46#define DB1300_FLASH_INT (DB1300_FIRST_INT + 7)
47#define DB1300_CF_INSERT_INT (DB1300_FIRST_INT + 8)
48#define DB1300_CF_EJECT_INT (DB1300_FIRST_INT + 9)
49#define DB1300_AC97_INT (DB1300_FIRST_INT + 10)
50#define DB1300_AC97_PEN_INT (DB1300_FIRST_INT + 11)
51#define DB1300_SD1_INSERT_INT (DB1300_FIRST_INT + 12)
52#define DB1300_SD1_EJECT_INT (DB1300_FIRST_INT + 13)
53#define DB1300_OTG_VBUS_OC_INT (DB1300_FIRST_INT + 14)
54#define DB1300_HOST_VBUS_OC_INT (DB1300_FIRST_INT + 15)
55#define DB1300_LAST_INT (DB1300_FIRST_INT + 15)
56
57/* SMSC9210 CS */
58#define DB1300_ETH_PHYS_ADDR 0x19000000
59#define DB1300_ETH_PHYS_END 0x197fffff
60
61/* ATA CS */
62#define DB1300_IDE_PHYS_ADDR 0x18800000
63#define DB1300_IDE_REG_SHIFT 5
64#define DB1300_IDE_PHYS_LEN (16 << DB1300_IDE_REG_SHIFT)
65
66/* NAND CS */
67#define DB1300_NAND_PHYS_ADDR 0x20000000
68#define DB1300_NAND_PHYS_END 0x20000fff
69
70
Manuel Lauss64cd04d2011-11-10 12:03:26 +000071static struct i2c_board_info db1300_i2c_devs[] __initdata = {
72 { I2C_BOARD_INFO("wm8731", 0x1b), }, /* I2S audio codec */
73 { I2C_BOARD_INFO("ne1619", 0x2d), }, /* adm1025-compat hwmon */
74};
75
76/* multifunction pins to assign to GPIO controller */
77static int db1300_gpio_pins[] __initdata = {
78 AU1300_PIN_LCDPWM0, AU1300_PIN_PSC2SYNC1, AU1300_PIN_WAKE1,
79 AU1300_PIN_WAKE2, AU1300_PIN_WAKE3, AU1300_PIN_FG3AUX,
80 AU1300_PIN_EXTCLK1,
81 -1, /* terminator */
82};
83
84/* multifunction pins to assign to device functions */
85static int db1300_dev_pins[] __initdata = {
86 /* wake-from-str pins 0-3 */
87 AU1300_PIN_WAKE0,
88 /* external clock sources for PSC0 */
89 AU1300_PIN_EXTCLK0,
90 /* 8bit MMC interface on SD0: 6-9 */
91 AU1300_PIN_SD0DAT4, AU1300_PIN_SD0DAT5, AU1300_PIN_SD0DAT6,
92 AU1300_PIN_SD0DAT7,
93 /* UART1 pins: 11-18 */
94 AU1300_PIN_U1RI, AU1300_PIN_U1DCD, AU1300_PIN_U1DSR,
95 AU1300_PIN_U1CTS, AU1300_PIN_U1RTS, AU1300_PIN_U1DTR,
96 AU1300_PIN_U1RX, AU1300_PIN_U1TX,
97 /* UART0 pins: 19-24 */
98 AU1300_PIN_U0RI, AU1300_PIN_U0DCD, AU1300_PIN_U0DSR,
99 AU1300_PIN_U0CTS, AU1300_PIN_U0RTS, AU1300_PIN_U0DTR,
100 /* UART2: 25-26 */
101 AU1300_PIN_U2RX, AU1300_PIN_U2TX,
102 /* UART3: 27-28 */
103 AU1300_PIN_U3RX, AU1300_PIN_U3TX,
104 /* LCD controller PWMs, ext pixclock: 30-31 */
105 AU1300_PIN_LCDPWM1, AU1300_PIN_LCDCLKIN,
106 /* SD1 interface: 32-37 */
107 AU1300_PIN_SD1DAT0, AU1300_PIN_SD1DAT1, AU1300_PIN_SD1DAT2,
108 AU1300_PIN_SD1DAT3, AU1300_PIN_SD1CMD, AU1300_PIN_SD1CLK,
109 /* SD2 interface: 38-43 */
110 AU1300_PIN_SD2DAT0, AU1300_PIN_SD2DAT1, AU1300_PIN_SD2DAT2,
111 AU1300_PIN_SD2DAT3, AU1300_PIN_SD2CMD, AU1300_PIN_SD2CLK,
112 /* PSC0/1 clocks: 44-45 */
113 AU1300_PIN_PSC0CLK, AU1300_PIN_PSC1CLK,
114 /* PSCs: 46-49/50-53/54-57/58-61 */
115 AU1300_PIN_PSC0SYNC0, AU1300_PIN_PSC0SYNC1, AU1300_PIN_PSC0D0,
116 AU1300_PIN_PSC0D1,
117 AU1300_PIN_PSC1SYNC0, AU1300_PIN_PSC1SYNC1, AU1300_PIN_PSC1D0,
118 AU1300_PIN_PSC1D1,
Ralf Baechle70342282013-01-22 12:59:30 +0100119 AU1300_PIN_PSC2SYNC0, AU1300_PIN_PSC2D0,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000120 AU1300_PIN_PSC2D1,
121 AU1300_PIN_PSC3SYNC0, AU1300_PIN_PSC3SYNC1, AU1300_PIN_PSC3D0,
122 AU1300_PIN_PSC3D1,
123 /* PCMCIA interface: 62-70 */
124 AU1300_PIN_PCE2, AU1300_PIN_PCE1, AU1300_PIN_PIOS16,
125 AU1300_PIN_PIOR, AU1300_PIN_PWE, AU1300_PIN_PWAIT,
126 AU1300_PIN_PREG, AU1300_PIN_POE, AU1300_PIN_PIOW,
127 /* camera interface H/V sync inputs: 71-72 */
128 AU1300_PIN_CIMLS, AU1300_PIN_CIMFS,
129 /* PSC2/3 clocks: 73-74 */
130 AU1300_PIN_PSC2CLK, AU1300_PIN_PSC3CLK,
131 -1, /* terminator */
132};
133
134static void __init db1300_gpio_config(void)
135{
136 int *i;
137
138 i = &db1300_dev_pins[0];
139 while (*i != -1)
140 au1300_pinfunc_to_dev(*i++);
141
142 i = &db1300_gpio_pins[0];
143 while (*i != -1)
144 au1300_gpio_direction_input(*i++);/* implies pin_to_gpio */
145
146 au1300_set_dbdma_gpio(1, AU1300_PIN_FG3AUX);
147}
148
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000149/**********************************************************************/
150
151static void au1300_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
152 unsigned int ctrl)
153{
Boris BREZILLONb1afda02015-12-01 12:03:01 +0100154 struct nand_chip *this = mtd_to_nand(mtd);
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000155 unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
156
157 ioaddr &= 0xffffff00;
158
159 if (ctrl & NAND_CLE) {
160 ioaddr += MEM_STNAND_CMD;
161 } else if (ctrl & NAND_ALE) {
162 ioaddr += MEM_STNAND_ADDR;
163 } else {
164 /* assume we want to r/w real data by default */
165 ioaddr += MEM_STNAND_DATA;
166 }
167 this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
168 if (cmd != NAND_CMD_NONE) {
169 __raw_writeb(cmd, this->IO_ADDR_W);
170 wmb();
171 }
172}
173
174static int au1300_nand_device_ready(struct mtd_info *mtd)
175{
Manuel Lauss9cf12162014-07-23 16:36:25 +0200176 return alchemy_rdsmem(AU1000_MEM_STSTAT) & 1;
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000177}
178
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000179static struct mtd_partition db1300_nand_parts[] = {
180 {
181 .name = "NAND FS 0",
Ralf Baechle70342282013-01-22 12:59:30 +0100182 .offset = 0,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000183 .size = 8 * 1024 * 1024,
184 },
185 {
186 .name = "NAND FS 1",
Ralf Baechle70342282013-01-22 12:59:30 +0100187 .offset = MTDPART_OFS_APPEND,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000188 .size = MTDPART_SIZ_FULL
189 },
190};
191
192struct platform_nand_data db1300_nand_platdata = {
193 .chip = {
194 .nr_chips = 1,
195 .chip_offset = 0,
196 .nr_partitions = ARRAY_SIZE(db1300_nand_parts),
197 .partitions = db1300_nand_parts,
198 .chip_delay = 20,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000199 },
200 .ctrl = {
201 .dev_ready = au1300_nand_device_ready,
202 .cmd_ctrl = au1300_nand_cmd_ctrl,
203 },
204};
205
206static struct resource db1300_nand_res[] = {
207 [0] = {
208 .start = DB1300_NAND_PHYS_ADDR,
209 .end = DB1300_NAND_PHYS_ADDR + 0xff,
210 .flags = IORESOURCE_MEM,
211 },
212};
213
214static struct platform_device db1300_nand_dev = {
215 .name = "gen_nand",
216 .num_resources = ARRAY_SIZE(db1300_nand_res),
217 .resource = db1300_nand_res,
218 .id = -1,
219 .dev = {
220 .platform_data = &db1300_nand_platdata,
221 }
222};
223
224/**********************************************************************/
225
226static struct resource db1300_eth_res[] = {
227 [0] = {
228 .start = DB1300_ETH_PHYS_ADDR,
229 .end = DB1300_ETH_PHYS_END,
230 .flags = IORESOURCE_MEM,
231 },
232 [1] = {
233 .start = DB1300_ETH_INT,
234 .end = DB1300_ETH_INT,
235 .flags = IORESOURCE_IRQ,
236 },
237};
238
239static struct smsc911x_platform_config db1300_eth_config = {
240 .phy_interface = PHY_INTERFACE_MODE_MII,
241 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
242 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
243 .flags = SMSC911X_USE_32BIT,
244};
245
246static struct platform_device db1300_eth_dev = {
247 .name = "smsc911x",
248 .id = -1,
249 .num_resources = ARRAY_SIZE(db1300_eth_res),
250 .resource = db1300_eth_res,
251 .dev = {
252 .platform_data = &db1300_eth_config,
253 },
254};
255
256/**********************************************************************/
257
258static struct resource au1300_psc1_res[] = {
259 [0] = {
260 .start = AU1300_PSC1_PHYS_ADDR,
261 .end = AU1300_PSC1_PHYS_ADDR + 0x0fff,
262 .flags = IORESOURCE_MEM,
263 },
264 [1] = {
265 .start = AU1300_PSC1_INT,
266 .end = AU1300_PSC1_INT,
267 .flags = IORESOURCE_IRQ,
268 },
269 [2] = {
270 .start = AU1300_DSCR_CMD0_PSC1_TX,
271 .end = AU1300_DSCR_CMD0_PSC1_TX,
272 .flags = IORESOURCE_DMA,
273 },
274 [3] = {
275 .start = AU1300_DSCR_CMD0_PSC1_RX,
276 .end = AU1300_DSCR_CMD0_PSC1_RX,
277 .flags = IORESOURCE_DMA,
278 },
279};
280
281static struct platform_device db1300_ac97_dev = {
282 .name = "au1xpsc_ac97",
283 .id = 1, /* PSC ID. match with AC97 codec ID! */
284 .num_resources = ARRAY_SIZE(au1300_psc1_res),
285 .resource = au1300_psc1_res,
286};
287
288/**********************************************************************/
289
290static struct resource au1300_psc2_res[] = {
291 [0] = {
292 .start = AU1300_PSC2_PHYS_ADDR,
293 .end = AU1300_PSC2_PHYS_ADDR + 0x0fff,
294 .flags = IORESOURCE_MEM,
295 },
296 [1] = {
297 .start = AU1300_PSC2_INT,
298 .end = AU1300_PSC2_INT,
299 .flags = IORESOURCE_IRQ,
300 },
301 [2] = {
302 .start = AU1300_DSCR_CMD0_PSC2_TX,
303 .end = AU1300_DSCR_CMD0_PSC2_TX,
304 .flags = IORESOURCE_DMA,
305 },
306 [3] = {
307 .start = AU1300_DSCR_CMD0_PSC2_RX,
308 .end = AU1300_DSCR_CMD0_PSC2_RX,
309 .flags = IORESOURCE_DMA,
310 },
311};
312
313static struct platform_device db1300_i2s_dev = {
314 .name = "au1xpsc_i2s",
315 .id = 2, /* PSC ID */
316 .num_resources = ARRAY_SIZE(au1300_psc2_res),
317 .resource = au1300_psc2_res,
318};
319
320/**********************************************************************/
321
322static struct resource au1300_psc3_res[] = {
323 [0] = {
324 .start = AU1300_PSC3_PHYS_ADDR,
325 .end = AU1300_PSC3_PHYS_ADDR + 0x0fff,
326 .flags = IORESOURCE_MEM,
327 },
328 [1] = {
329 .start = AU1300_PSC3_INT,
330 .end = AU1300_PSC3_INT,
331 .flags = IORESOURCE_IRQ,
332 },
333 [2] = {
334 .start = AU1300_DSCR_CMD0_PSC3_TX,
335 .end = AU1300_DSCR_CMD0_PSC3_TX,
336 .flags = IORESOURCE_DMA,
337 },
338 [3] = {
339 .start = AU1300_DSCR_CMD0_PSC3_RX,
340 .end = AU1300_DSCR_CMD0_PSC3_RX,
341 .flags = IORESOURCE_DMA,
342 },
343};
344
345static struct platform_device db1300_i2c_dev = {
346 .name = "au1xpsc_smbus",
347 .id = 0, /* bus number */
348 .num_resources = ARRAY_SIZE(au1300_psc3_res),
349 .resource = au1300_psc3_res,
350};
351
352/**********************************************************************/
353
354/* proper key assignments when facing the LCD panel. For key assignments
355 * according to the schematics swap up with down and left with right.
356 * I chose to use it to emulate the arrow keys of a keyboard.
357 */
358static struct gpio_keys_button db1300_5waysw_arrowkeys[] = {
359 {
360 .code = KEY_DOWN,
361 .gpio = AU1300_PIN_LCDPWM0,
362 .type = EV_KEY,
363 .debounce_interval = 1,
364 .active_low = 1,
365 .desc = "5waysw-down",
366 },
367 {
368 .code = KEY_UP,
369 .gpio = AU1300_PIN_PSC2SYNC1,
370 .type = EV_KEY,
371 .debounce_interval = 1,
372 .active_low = 1,
373 .desc = "5waysw-up",
374 },
375 {
376 .code = KEY_RIGHT,
377 .gpio = AU1300_PIN_WAKE3,
378 .type = EV_KEY,
379 .debounce_interval = 1,
380 .active_low = 1,
381 .desc = "5waysw-right",
382 },
383 {
384 .code = KEY_LEFT,
385 .gpio = AU1300_PIN_WAKE2,
386 .type = EV_KEY,
387 .debounce_interval = 1,
388 .active_low = 1,
389 .desc = "5waysw-left",
390 },
391 {
392 .code = KEY_ENTER,
393 .gpio = AU1300_PIN_WAKE1,
394 .type = EV_KEY,
395 .debounce_interval = 1,
396 .active_low = 1,
397 .desc = "5waysw-push",
398 },
399};
400
401static struct gpio_keys_platform_data db1300_5waysw_data = {
402 .buttons = db1300_5waysw_arrowkeys,
403 .nbuttons = ARRAY_SIZE(db1300_5waysw_arrowkeys),
404 .rep = 1,
405 .name = "db1300-5wayswitch",
406};
407
408static struct platform_device db1300_5waysw_dev = {
409 .name = "gpio-keys",
410 .dev = {
411 .platform_data = &db1300_5waysw_data,
412 },
413};
414
415/**********************************************************************/
416
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000417static struct pata_platform_info db1300_ide_info = {
418 .ioport_shift = DB1300_IDE_REG_SHIFT,
419};
420
421#define IDE_ALT_START (14 << DB1300_IDE_REG_SHIFT)
422static struct resource db1300_ide_res[] = {
423 [0] = {
424 .start = DB1300_IDE_PHYS_ADDR,
425 .end = DB1300_IDE_PHYS_ADDR + IDE_ALT_START - 1,
426 .flags = IORESOURCE_MEM,
427 },
428 [1] = {
429 .start = DB1300_IDE_PHYS_ADDR + IDE_ALT_START,
430 .end = DB1300_IDE_PHYS_ADDR + DB1300_IDE_PHYS_LEN - 1,
431 .flags = IORESOURCE_MEM,
432 },
433 [2] = {
434 .start = DB1300_IDE_INT,
435 .end = DB1300_IDE_INT,
436 .flags = IORESOURCE_IRQ,
437 },
438};
439
440static struct platform_device db1300_ide_dev = {
441 .dev = {
442 .platform_data = &db1300_ide_info,
443 },
444 .name = "pata_platform",
445 .resource = db1300_ide_res,
446 .num_resources = ARRAY_SIZE(db1300_ide_res),
447};
448
449/**********************************************************************/
450
451static irqreturn_t db1300_mmc_cd(int irq, void *ptr)
452{
Manuel Lausscc108152017-02-14 13:03:28 +0100453 disable_irq_nosync(irq);
454 return IRQ_WAKE_THREAD;
455}
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000456
Manuel Lausscc108152017-02-14 13:03:28 +0100457static irqreturn_t db1300_mmc_cdfn(int irq, void *ptr)
458{
459 void (*mmc_cd)(struct mmc_host *, unsigned long);
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000460
461 /* link against CONFIG_MMC=m. We can only be called once MMC core has
462 * initialized the controller, so symbol_get() should always succeed.
463 */
464 mmc_cd = symbol_get(mmc_detect_change);
Manuel Lausscc108152017-02-14 13:03:28 +0100465 mmc_cd(ptr, msecs_to_jiffies(200));
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000466 symbol_put(mmc_detect_change);
467
Manuel Lausscc108152017-02-14 13:03:28 +0100468 msleep(100); /* debounce */
469 if (irq == DB1300_SD1_INSERT_INT)
470 enable_irq(DB1300_SD1_EJECT_INT);
471 else
472 enable_irq(DB1300_SD1_INSERT_INT);
473
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000474 return IRQ_HANDLED;
475}
476
477static int db1300_mmc_card_readonly(void *mmc_host)
478{
479 /* it uses SD1 interface, but the DB1200's SD0 bit in the CPLD */
480 return bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP;
481}
482
483static int db1300_mmc_card_inserted(void *mmc_host)
484{
485 return bcsr_read(BCSR_SIGSTAT) & (1 << 12); /* insertion irq signal */
486}
487
488static int db1300_mmc_cd_setup(void *mmc_host, int en)
489{
490 int ret;
491
492 if (en) {
Manuel Lausscc108152017-02-14 13:03:28 +0100493 ret = request_threaded_irq(DB1300_SD1_INSERT_INT, db1300_mmc_cd,
494 db1300_mmc_cdfn, 0, "sd_insert", mmc_host);
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000495 if (ret)
496 goto out;
497
Manuel Lausscc108152017-02-14 13:03:28 +0100498 ret = request_threaded_irq(DB1300_SD1_EJECT_INT, db1300_mmc_cd,
499 db1300_mmc_cdfn, 0, "sd_eject", mmc_host);
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000500 if (ret) {
501 free_irq(DB1300_SD1_INSERT_INT, mmc_host);
502 goto out;
503 }
504
505 if (db1300_mmc_card_inserted(mmc_host))
506 enable_irq(DB1300_SD1_EJECT_INT);
507 else
508 enable_irq(DB1300_SD1_INSERT_INT);
509
510 } else {
511 free_irq(DB1300_SD1_INSERT_INT, mmc_host);
512 free_irq(DB1300_SD1_EJECT_INT, mmc_host);
513 }
514 ret = 0;
515out:
516 return ret;
517}
518
519static void db1300_mmcled_set(struct led_classdev *led,
520 enum led_brightness brightness)
521{
522 if (brightness != LED_OFF)
523 bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
524 else
525 bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
526}
527
528static struct led_classdev db1300_mmc_led = {
Ralf Baechle70342282013-01-22 12:59:30 +0100529 .brightness_set = db1300_mmcled_set,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000530};
531
532struct au1xmmc_platform_data db1300_sd1_platdata = {
533 .cd_setup = db1300_mmc_cd_setup,
534 .card_inserted = db1300_mmc_card_inserted,
535 .card_readonly = db1300_mmc_card_readonly,
536 .led = &db1300_mmc_led,
537};
538
539static struct resource au1300_sd1_res[] = {
540 [0] = {
541 .start = AU1300_SD1_PHYS_ADDR,
542 .end = AU1300_SD1_PHYS_ADDR,
543 .flags = IORESOURCE_MEM,
544 },
545 [1] = {
546 .start = AU1300_SD1_INT,
547 .end = AU1300_SD1_INT,
548 .flags = IORESOURCE_IRQ,
549 },
550 [2] = {
551 .start = AU1300_DSCR_CMD0_SDMS_TX1,
552 .end = AU1300_DSCR_CMD0_SDMS_TX1,
553 .flags = IORESOURCE_DMA,
554 },
555 [3] = {
556 .start = AU1300_DSCR_CMD0_SDMS_RX1,
557 .end = AU1300_DSCR_CMD0_SDMS_RX1,
558 .flags = IORESOURCE_DMA,
559 },
560};
561
562static struct platform_device db1300_sd1_dev = {
563 .dev = {
564 .platform_data = &db1300_sd1_platdata,
565 },
566 .name = "au1xxx-mmc",
567 .id = 1,
568 .resource = au1300_sd1_res,
569 .num_resources = ARRAY_SIZE(au1300_sd1_res),
570};
571
572/**********************************************************************/
573
574static int db1300_movinand_inserted(void *mmc_host)
575{
576 return 0; /* disable for now, it doesn't work yet */
577}
578
579static int db1300_movinand_readonly(void *mmc_host)
580{
581 return 0;
582}
583
584static void db1300_movinand_led_set(struct led_classdev *led,
585 enum led_brightness brightness)
586{
587 if (brightness != LED_OFF)
588 bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED1, 0);
589 else
590 bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED1);
591}
592
593static struct led_classdev db1300_movinand_led = {
594 .brightness_set = db1300_movinand_led_set,
595};
596
597struct au1xmmc_platform_data db1300_sd0_platdata = {
598 .card_inserted = db1300_movinand_inserted,
599 .card_readonly = db1300_movinand_readonly,
600 .led = &db1300_movinand_led,
601 .mask_host_caps = MMC_CAP_NEEDS_POLL,
602};
603
604static struct resource au1300_sd0_res[] = {
605 [0] = {
606 .start = AU1100_SD0_PHYS_ADDR,
607 .end = AU1100_SD0_PHYS_ADDR,
608 .flags = IORESOURCE_MEM,
609 },
610 [1] = {
611 .start = AU1300_SD0_INT,
612 .end = AU1300_SD0_INT,
613 .flags = IORESOURCE_IRQ,
614 },
615 [2] = {
616 .start = AU1300_DSCR_CMD0_SDMS_TX0,
617 .end = AU1300_DSCR_CMD0_SDMS_TX0,
618 .flags = IORESOURCE_DMA,
619 },
620 [3] = {
621 .start = AU1300_DSCR_CMD0_SDMS_RX0,
622 .end = AU1300_DSCR_CMD0_SDMS_RX0,
623 .flags = IORESOURCE_DMA,
624 },
625};
626
627static struct platform_device db1300_sd0_dev = {
628 .dev = {
629 .platform_data = &db1300_sd0_platdata,
630 },
631 .name = "au1xxx-mmc",
632 .id = 0,
633 .resource = au1300_sd0_res,
634 .num_resources = ARRAY_SIZE(au1300_sd0_res),
635};
636
637/**********************************************************************/
638
639static struct platform_device db1300_wm9715_dev = {
640 .name = "wm9712-codec",
641 .id = 1, /* ID of PSC for AC97 audio, see asoc glue! */
642};
643
644static struct platform_device db1300_ac97dma_dev = {
645 .name = "au1xpsc-pcm",
646 .id = 1, /* PSC ID */
647};
648
649static struct platform_device db1300_i2sdma_dev = {
650 .name = "au1xpsc-pcm",
651 .id = 2, /* PSC ID */
652};
653
654static struct platform_device db1300_sndac97_dev = {
655 .name = "db1300-ac97",
656};
657
658static struct platform_device db1300_sndi2s_dev = {
659 .name = "db1300-i2s",
660};
661
662/**********************************************************************/
663
Manuel Laussa9b71a82011-11-10 12:06:21 +0000664static int db1300fb_panel_index(void)
665{
666 return 9; /* DB1300_800x480 */
667}
668
669static int db1300fb_panel_init(void)
670{
671 /* Apply power (Vee/Vdd logic is inverted on Panel DB1300_800x480) */
672 bcsr_mod(BCSR_BOARD, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD,
673 BCSR_BOARD_LCDBL);
674 return 0;
675}
676
677static int db1300fb_panel_shutdown(void)
678{
679 /* Remove power (Vee/Vdd logic is inverted on Panel DB1300_800x480) */
680 bcsr_mod(BCSR_BOARD, BCSR_BOARD_LCDBL,
681 BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD);
682 return 0;
683}
684
685static struct au1200fb_platdata db1300fb_pd = {
686 .panel_index = db1300fb_panel_index,
687 .panel_init = db1300fb_panel_init,
Ralf Baechle70342282013-01-22 12:59:30 +0100688 .panel_shutdown = db1300fb_panel_shutdown,
Manuel Laussa9b71a82011-11-10 12:06:21 +0000689};
690
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000691static struct resource au1300_lcd_res[] = {
692 [0] = {
693 .start = AU1200_LCD_PHYS_ADDR,
694 .end = AU1200_LCD_PHYS_ADDR + 0x800 - 1,
695 .flags = IORESOURCE_MEM,
696 },
697 [1] = {
698 .start = AU1300_LCD_INT,
699 .end = AU1300_LCD_INT,
700 .flags = IORESOURCE_IRQ,
701 }
702};
703
704static u64 au1300_lcd_dmamask = DMA_BIT_MASK(32);
705
706static struct platform_device db1300_lcd_dev = {
707 .name = "au1200-lcd",
708 .id = 0,
709 .dev = {
710 .dma_mask = &au1300_lcd_dmamask,
711 .coherent_dma_mask = DMA_BIT_MASK(32),
Manuel Laussa9b71a82011-11-10 12:06:21 +0000712 .platform_data = &db1300fb_pd,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000713 },
714 .num_resources = ARRAY_SIZE(au1300_lcd_res),
715 .resource = au1300_lcd_res,
716};
717
718/**********************************************************************/
719
Manuel Laussc64bb5f2014-08-20 21:36:33 +0200720static void db1300_wm97xx_irqen(struct wm97xx *wm, int enable)
721{
722 if (enable)
723 enable_irq(DB1300_AC97_PEN_INT);
724 else
725 disable_irq_nosync(DB1300_AC97_PEN_INT);
726}
727
728static struct wm97xx_mach_ops db1300_wm97xx_ops = {
729 .irq_enable = db1300_wm97xx_irqen,
730 .irq_gpio = WM97XX_GPIO_3,
731};
732
733static int db1300_wm97xx_probe(struct platform_device *pdev)
734{
735 struct wm97xx *wm = platform_get_drvdata(pdev);
736
737 /* external pendown indicator */
738 wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
739 WM97XX_GPIO_POL_LOW, WM97XX_GPIO_STICKY,
740 WM97XX_GPIO_WAKE);
741
742 /* internal "virtual" pendown gpio */
743 wm97xx_config_gpio(wm, WM97XX_GPIO_3, WM97XX_GPIO_OUT,
744 WM97XX_GPIO_POL_LOW, WM97XX_GPIO_NOTSTICKY,
745 WM97XX_GPIO_NOWAKE);
746
747 wm->pen_irq = DB1300_AC97_PEN_INT;
748
749 return wm97xx_register_mach_ops(wm, &db1300_wm97xx_ops);
750}
751
752static struct platform_driver db1300_wm97xx_driver = {
753 .driver.name = "wm97xx-touch",
754 .driver.owner = THIS_MODULE,
755 .probe = db1300_wm97xx_probe,
756};
757
758/**********************************************************************/
759
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000760static struct platform_device *db1300_dev[] __initdata = {
761 &db1300_eth_dev,
762 &db1300_i2c_dev,
763 &db1300_5waysw_dev,
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000764 &db1300_nand_dev,
765 &db1300_ide_dev,
766 &db1300_sd0_dev,
767 &db1300_sd1_dev,
768 &db1300_lcd_dev,
769 &db1300_ac97_dev,
770 &db1300_i2s_dev,
771 &db1300_wm9715_dev,
772 &db1300_ac97dma_dev,
773 &db1300_i2sdma_dev,
774 &db1300_sndac97_dev,
775 &db1300_sndi2s_dev,
776};
777
Manuel Laussbd8510d2012-09-13 17:44:39 +0200778int __init db1300_dev_setup(void)
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000779{
780 int swapped, cpldirq;
Manuel Lauss415e0fe2014-07-23 16:36:52 +0200781 struct clk *c;
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000782
783 /* setup CPLD IRQ muxer */
784 cpldirq = au1300_gpio_to_irq(AU1300_PIN_EXTCLK1);
785 irq_set_irq_type(cpldirq, IRQ_TYPE_LEVEL_HIGH);
786 bcsr_init_irq(DB1300_FIRST_INT, DB1300_LAST_INT, cpldirq);
787
788 /* insert/eject IRQs: one always triggers so don't enable them
789 * when doing request_irq() on them. DB1200 has this bug too.
790 */
791 irq_set_status_flags(DB1300_SD1_INSERT_INT, IRQ_NOAUTOEN);
792 irq_set_status_flags(DB1300_SD1_EJECT_INT, IRQ_NOAUTOEN);
793 irq_set_status_flags(DB1300_CF_INSERT_INT, IRQ_NOAUTOEN);
794 irq_set_status_flags(DB1300_CF_EJECT_INT, IRQ_NOAUTOEN);
795
796 /*
797 * setup board
798 */
799 prom_get_ethernet_addr(&db1300_eth_config.mac[0]);
800
801 i2c_register_board_info(0, db1300_i2c_devs,
802 ARRAY_SIZE(db1300_i2c_devs));
803
Manuel Laussc64bb5f2014-08-20 21:36:33 +0200804 if (platform_driver_register(&db1300_wm97xx_driver))
805 pr_warn("DB1300: failed to init touch pen irq support!\n");
806
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000807 /* Audio PSC clock is supplied by codecs (PSC1, 2) */
808 __raw_writel(PSC_SEL_CLK_SERCLK,
809 (void __iomem *)KSEG1ADDR(AU1300_PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
810 wmb();
811 __raw_writel(PSC_SEL_CLK_SERCLK,
812 (void __iomem *)KSEG1ADDR(AU1300_PSC2_PHYS_ADDR) + PSC_SEL_OFFSET);
813 wmb();
Manuel Laussc02a5052014-08-20 21:36:32 +0200814 /* I2C driver wants 50MHz, get as close as possible */
Manuel Lauss415e0fe2014-07-23 16:36:52 +0200815 c = clk_get(NULL, "psc3_intclk");
816 if (!IS_ERR(c)) {
Manuel Laussc02a5052014-08-20 21:36:32 +0200817 clk_set_rate(c, 50000000);
Manuel Lauss415e0fe2014-07-23 16:36:52 +0200818 clk_prepare_enable(c);
819 clk_put(c);
820 }
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000821 __raw_writel(PSC_SEL_CLK_INTCLK,
822 (void __iomem *)KSEG1ADDR(AU1300_PSC3_PHYS_ADDR) + PSC_SEL_OFFSET);
823 wmb();
824
825 /* enable power to USB ports */
826 bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_USBHPWR | BCSR_RESETS_OTGPWR);
827
828 /* although it is socket #0, it uses the CPLD bits which previous boards
829 * have used for socket #1.
830 */
831 db1x_register_pcmcia_socket(
832 AU1000_PCMCIA_ATTR_PHYS_ADDR,
833 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x00400000 - 1,
834 AU1000_PCMCIA_MEM_PHYS_ADDR,
835 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x00400000 - 1,
836 AU1000_PCMCIA_IO_PHYS_ADDR,
837 AU1000_PCMCIA_IO_PHYS_ADDR + 0x00010000 - 1,
838 DB1300_CF_INT, DB1300_CF_INSERT_INT, 0, DB1300_CF_EJECT_INT, 1);
839
840 swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1200_SWAPBOOT;
841 db1x_register_norflash(64 << 20, 2, swapped);
842
843 return platform_add_devices(db1300_dev, ARRAY_SIZE(db1300_dev));
844}
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000845
846
Manuel Laussbd8510d2012-09-13 17:44:39 +0200847int __init db1300_board_setup(void)
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000848{
849 unsigned short whoami;
850
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000851 bcsr_init(DB1300_BCSR_PHYS_ADDR,
852 DB1300_BCSR_PHYS_ADDR + DB1300_BCSR_HEXLED_OFS);
853
854 whoami = bcsr_read(BCSR_WHOAMI);
Manuel Lauss970e2682014-02-20 14:59:24 +0100855 if (BCSR_WHOAMI_BOARD(whoami) != BCSR_WHOAMI_DB1300)
856 return -ENODEV;
857
858 db1300_gpio_config();
859
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000860 printk(KERN_INFO "NetLogic DBAu1300 Development Platform.\n\t"
861 "BoardID %d CPLD Rev %d DaughtercardID %d\n",
862 BCSR_WHOAMI_BOARD(whoami), BCSR_WHOAMI_CPLD(whoami),
863 BCSR_WHOAMI_DCID(whoami));
864
865 /* enable UARTs, YAMON only enables #2 */
866 alchemy_uart_enable(AU1300_UART0_PHYS_ADDR);
867 alchemy_uart_enable(AU1300_UART1_PHYS_ADDR);
868 alchemy_uart_enable(AU1300_UART3_PHYS_ADDR);
Manuel Laussbd8510d2012-09-13 17:44:39 +0200869
870 return 0;
Manuel Lauss64cd04d2011-11-10 12:03:26 +0000871}