db1200.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /*
  2. * DBAu1200/PBAu1200 board platform device registration
  3. *
  4. * Copyright (C) 2008-2011 Manuel Lauss
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/clk.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/gpio.h>
  23. #include <linux/i2c.h>
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/io.h>
  28. #include <linux/leds.h>
  29. #include <linux/mmc/host.h>
  30. #include <linux/mtd/mtd.h>
  31. #include <linux/mtd/nand.h>
  32. #include <linux/mtd/partitions.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/serial_8250.h>
  35. #include <linux/spi/spi.h>
  36. #include <linux/spi/flash.h>
  37. #include <linux/smc91x.h>
  38. #include <linux/ata_platform.h>
  39. #include <asm/mach-au1x00/au1000.h>
  40. #include <asm/mach-au1x00/au1100_mmc.h>
  41. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  42. #include <asm/mach-au1x00/au1xxx_psc.h>
  43. #include <asm/mach-au1x00/au1200fb.h>
  44. #include <asm/mach-au1x00/au1550_spi.h>
  45. #include <asm/mach-db1x00/bcsr.h>
  46. #include "platform.h"
  47. #define BCSR_INT_IDE 0x0001
  48. #define BCSR_INT_ETH 0x0002
  49. #define BCSR_INT_PC0 0x0004
  50. #define BCSR_INT_PC0STSCHG 0x0008
  51. #define BCSR_INT_PC1 0x0010
  52. #define BCSR_INT_PC1STSCHG 0x0020
  53. #define BCSR_INT_DC 0x0040
  54. #define BCSR_INT_FLASHBUSY 0x0080
  55. #define BCSR_INT_PC0INSERT 0x0100
  56. #define BCSR_INT_PC0EJECT 0x0200
  57. #define BCSR_INT_PC1INSERT 0x0400
  58. #define BCSR_INT_PC1EJECT 0x0800
  59. #define BCSR_INT_SD0INSERT 0x1000
  60. #define BCSR_INT_SD0EJECT 0x2000
  61. #define BCSR_INT_SD1INSERT 0x4000
  62. #define BCSR_INT_SD1EJECT 0x8000
  63. #define DB1200_IDE_PHYS_ADDR 0x18800000
  64. #define DB1200_IDE_REG_SHIFT 5
  65. #define DB1200_IDE_PHYS_LEN (16 << DB1200_IDE_REG_SHIFT)
  66. #define DB1200_ETH_PHYS_ADDR 0x19000300
  67. #define DB1200_NAND_PHYS_ADDR 0x20000000
  68. #define PB1200_IDE_PHYS_ADDR 0x0C800000
  69. #define PB1200_ETH_PHYS_ADDR 0x0D000300
  70. #define PB1200_NAND_PHYS_ADDR 0x1C000000
  71. #define DB1200_INT_BEGIN (AU1000_MAX_INTR + 1)
  72. #define DB1200_IDE_INT (DB1200_INT_BEGIN + 0)
  73. #define DB1200_ETH_INT (DB1200_INT_BEGIN + 1)
  74. #define DB1200_PC0_INT (DB1200_INT_BEGIN + 2)
  75. #define DB1200_PC0_STSCHG_INT (DB1200_INT_BEGIN + 3)
  76. #define DB1200_PC1_INT (DB1200_INT_BEGIN + 4)
  77. #define DB1200_PC1_STSCHG_INT (DB1200_INT_BEGIN + 5)
  78. #define DB1200_DC_INT (DB1200_INT_BEGIN + 6)
  79. #define DB1200_FLASHBUSY_INT (DB1200_INT_BEGIN + 7)
  80. #define DB1200_PC0_INSERT_INT (DB1200_INT_BEGIN + 8)
  81. #define DB1200_PC0_EJECT_INT (DB1200_INT_BEGIN + 9)
  82. #define DB1200_PC1_INSERT_INT (DB1200_INT_BEGIN + 10)
  83. #define DB1200_PC1_EJECT_INT (DB1200_INT_BEGIN + 11)
  84. #define DB1200_SD0_INSERT_INT (DB1200_INT_BEGIN + 12)
  85. #define DB1200_SD0_EJECT_INT (DB1200_INT_BEGIN + 13)
  86. #define PB1200_SD1_INSERT_INT (DB1200_INT_BEGIN + 14)
  87. #define PB1200_SD1_EJECT_INT (DB1200_INT_BEGIN + 15)
  88. #define DB1200_INT_END (DB1200_INT_BEGIN + 15)
  89. const char *get_system_type(void);
  90. static int __init db1200_detect_board(void)
  91. {
  92. int bid;
  93. /* try the DB1200 first */
  94. bcsr_init(DB1200_BCSR_PHYS_ADDR,
  95. DB1200_BCSR_PHYS_ADDR + DB1200_BCSR_HEXLED_OFS);
  96. if (BCSR_WHOAMI_DB1200 == BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI))) {
  97. unsigned short t = bcsr_read(BCSR_HEXLEDS);
  98. bcsr_write(BCSR_HEXLEDS, ~t);
  99. if (bcsr_read(BCSR_HEXLEDS) != t) {
  100. bcsr_write(BCSR_HEXLEDS, t);
  101. return 0;
  102. }
  103. }
  104. /* okay, try the PB1200 then */
  105. bcsr_init(PB1200_BCSR_PHYS_ADDR,
  106. PB1200_BCSR_PHYS_ADDR + PB1200_BCSR_HEXLED_OFS);
  107. bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
  108. if ((bid == BCSR_WHOAMI_PB1200_DDR1) ||
  109. (bid == BCSR_WHOAMI_PB1200_DDR2)) {
  110. unsigned short t = bcsr_read(BCSR_HEXLEDS);
  111. bcsr_write(BCSR_HEXLEDS, ~t);
  112. if (bcsr_read(BCSR_HEXLEDS) != t) {
  113. bcsr_write(BCSR_HEXLEDS, t);
  114. return 0;
  115. }
  116. }
  117. return 1; /* it's neither */
  118. }
  119. int __init db1200_board_setup(void)
  120. {
  121. unsigned short whoami;
  122. if (db1200_detect_board())
  123. return -ENODEV;
  124. whoami = bcsr_read(BCSR_WHOAMI);
  125. switch (BCSR_WHOAMI_BOARD(whoami)) {
  126. case BCSR_WHOAMI_PB1200_DDR1:
  127. case BCSR_WHOAMI_PB1200_DDR2:
  128. case BCSR_WHOAMI_DB1200:
  129. break;
  130. default:
  131. return -ENODEV;
  132. }
  133. printk(KERN_INFO "Alchemy/AMD/RMI %s Board, CPLD Rev %d"
  134. " Board-ID %d Daughtercard ID %d\n", get_system_type(),
  135. (whoami >> 4) & 0xf, (whoami >> 8) & 0xf, whoami & 0xf);
  136. return 0;
  137. }
  138. /******************************************************************************/
  139. static struct mtd_partition db1200_spiflash_parts[] = {
  140. {
  141. .name = "spi_flash",
  142. .offset = 0,
  143. .size = MTDPART_SIZ_FULL,
  144. },
  145. };
  146. static struct flash_platform_data db1200_spiflash_data = {
  147. .name = "s25fl001",
  148. .parts = db1200_spiflash_parts,
  149. .nr_parts = ARRAY_SIZE(db1200_spiflash_parts),
  150. .type = "m25p10",
  151. };
  152. static struct spi_board_info db1200_spi_devs[] __initdata = {
  153. {
  154. /* TI TMP121AIDBVR temp sensor */
  155. .modalias = "tmp121",
  156. .max_speed_hz = 2000000,
  157. .bus_num = 0,
  158. .chip_select = 0,
  159. .mode = 0,
  160. },
  161. {
  162. /* Spansion S25FL001D0FMA SPI flash */
  163. .modalias = "m25p80",
  164. .max_speed_hz = 50000000,
  165. .bus_num = 0,
  166. .chip_select = 1,
  167. .mode = 0,
  168. .platform_data = &db1200_spiflash_data,
  169. },
  170. };
  171. static struct i2c_board_info db1200_i2c_devs[] __initdata = {
  172. { I2C_BOARD_INFO("24c04", 0x52), }, /* AT24C04-10 I2C eeprom */
  173. { I2C_BOARD_INFO("ne1619", 0x2d), }, /* adm1025-compat hwmon */
  174. { I2C_BOARD_INFO("wm8731", 0x1b), }, /* I2S audio codec WM8731 */
  175. };
  176. /**********************************************************************/
  177. static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  178. unsigned int ctrl)
  179. {
  180. struct nand_chip *this = mtd->priv;
  181. unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
  182. ioaddr &= 0xffffff00;
  183. if (ctrl & NAND_CLE) {
  184. ioaddr += MEM_STNAND_CMD;
  185. } else if (ctrl & NAND_ALE) {
  186. ioaddr += MEM_STNAND_ADDR;
  187. } else {
  188. /* assume we want to r/w real data by default */
  189. ioaddr += MEM_STNAND_DATA;
  190. }
  191. this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
  192. if (cmd != NAND_CMD_NONE) {
  193. __raw_writeb(cmd, this->IO_ADDR_W);
  194. wmb();
  195. }
  196. }
  197. static int au1200_nand_device_ready(struct mtd_info *mtd)
  198. {
  199. return alchemy_rdsmem(AU1000_MEM_STSTAT) & 1;
  200. }
  201. static struct mtd_partition db1200_nand_parts[] = {
  202. {
  203. .name = "NAND FS 0",
  204. .offset = 0,
  205. .size = 8 * 1024 * 1024,
  206. },
  207. {
  208. .name = "NAND FS 1",
  209. .offset = MTDPART_OFS_APPEND,
  210. .size = MTDPART_SIZ_FULL
  211. },
  212. };
  213. struct platform_nand_data db1200_nand_platdata = {
  214. .chip = {
  215. .nr_chips = 1,
  216. .chip_offset = 0,
  217. .nr_partitions = ARRAY_SIZE(db1200_nand_parts),
  218. .partitions = db1200_nand_parts,
  219. .chip_delay = 20,
  220. },
  221. .ctrl = {
  222. .dev_ready = au1200_nand_device_ready,
  223. .cmd_ctrl = au1200_nand_cmd_ctrl,
  224. },
  225. };
  226. static struct resource db1200_nand_res[] = {
  227. [0] = {
  228. .start = DB1200_NAND_PHYS_ADDR,
  229. .end = DB1200_NAND_PHYS_ADDR + 0xff,
  230. .flags = IORESOURCE_MEM,
  231. },
  232. };
  233. static struct platform_device db1200_nand_dev = {
  234. .name = "gen_nand",
  235. .num_resources = ARRAY_SIZE(db1200_nand_res),
  236. .resource = db1200_nand_res,
  237. .id = -1,
  238. .dev = {
  239. .platform_data = &db1200_nand_platdata,
  240. }
  241. };
  242. /**********************************************************************/
  243. static struct smc91x_platdata db1200_eth_data = {
  244. .flags = SMC91X_NOWAIT | SMC91X_USE_16BIT,
  245. .leda = RPC_LED_100_10,
  246. .ledb = RPC_LED_TX_RX,
  247. };
  248. static struct resource db1200_eth_res[] = {
  249. [0] = {
  250. .start = DB1200_ETH_PHYS_ADDR,
  251. .end = DB1200_ETH_PHYS_ADDR + 0xf,
  252. .flags = IORESOURCE_MEM,
  253. },
  254. [1] = {
  255. .start = DB1200_ETH_INT,
  256. .end = DB1200_ETH_INT,
  257. .flags = IORESOURCE_IRQ,
  258. },
  259. };
  260. static struct platform_device db1200_eth_dev = {
  261. .dev = {
  262. .platform_data = &db1200_eth_data,
  263. },
  264. .name = "smc91x",
  265. .id = -1,
  266. .num_resources = ARRAY_SIZE(db1200_eth_res),
  267. .resource = db1200_eth_res,
  268. };
  269. /**********************************************************************/
  270. static struct pata_platform_info db1200_ide_info = {
  271. .ioport_shift = DB1200_IDE_REG_SHIFT,
  272. };
  273. #define IDE_ALT_START (14 << DB1200_IDE_REG_SHIFT)
  274. static struct resource db1200_ide_res[] = {
  275. [0] = {
  276. .start = DB1200_IDE_PHYS_ADDR,
  277. .end = DB1200_IDE_PHYS_ADDR + IDE_ALT_START - 1,
  278. .flags = IORESOURCE_MEM,
  279. },
  280. [1] = {
  281. .start = DB1200_IDE_PHYS_ADDR + IDE_ALT_START,
  282. .end = DB1200_IDE_PHYS_ADDR + DB1200_IDE_PHYS_LEN - 1,
  283. .flags = IORESOURCE_MEM,
  284. },
  285. [2] = {
  286. .start = DB1200_IDE_INT,
  287. .end = DB1200_IDE_INT,
  288. .flags = IORESOURCE_IRQ,
  289. },
  290. };
  291. static u64 au1200_ide_dmamask = DMA_BIT_MASK(32);
  292. static struct platform_device db1200_ide_dev = {
  293. .name = "pata_platform",
  294. .id = 0,
  295. .dev = {
  296. .dma_mask = &au1200_ide_dmamask,
  297. .coherent_dma_mask = DMA_BIT_MASK(32),
  298. .platform_data = &db1200_ide_info,
  299. },
  300. .num_resources = ARRAY_SIZE(db1200_ide_res),
  301. .resource = db1200_ide_res,
  302. };
  303. /**********************************************************************/
  304. /* SD carddetects: they're supposed to be edge-triggered, but ack
  305. * doesn't seem to work (CPLD Rev 2). Instead, the screaming one
  306. * is disabled and its counterpart enabled. The 500ms timeout is
  307. * because the carddetect isn't debounced in hardware.
  308. */
  309. static irqreturn_t db1200_mmc_cd(int irq, void *ptr)
  310. {
  311. void(*mmc_cd)(struct mmc_host *, unsigned long);
  312. if (irq == DB1200_SD0_INSERT_INT) {
  313. disable_irq_nosync(DB1200_SD0_INSERT_INT);
  314. enable_irq(DB1200_SD0_EJECT_INT);
  315. } else {
  316. disable_irq_nosync(DB1200_SD0_EJECT_INT);
  317. enable_irq(DB1200_SD0_INSERT_INT);
  318. }
  319. /* link against CONFIG_MMC=m */
  320. mmc_cd = symbol_get(mmc_detect_change);
  321. if (mmc_cd) {
  322. mmc_cd(ptr, msecs_to_jiffies(500));
  323. symbol_put(mmc_detect_change);
  324. }
  325. return IRQ_HANDLED;
  326. }
  327. static int db1200_mmc_cd_setup(void *mmc_host, int en)
  328. {
  329. int ret;
  330. if (en) {
  331. ret = request_irq(DB1200_SD0_INSERT_INT, db1200_mmc_cd,
  332. 0, "sd_insert", mmc_host);
  333. if (ret)
  334. goto out;
  335. ret = request_irq(DB1200_SD0_EJECT_INT, db1200_mmc_cd,
  336. 0, "sd_eject", mmc_host);
  337. if (ret) {
  338. free_irq(DB1200_SD0_INSERT_INT, mmc_host);
  339. goto out;
  340. }
  341. if (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT)
  342. enable_irq(DB1200_SD0_EJECT_INT);
  343. else
  344. enable_irq(DB1200_SD0_INSERT_INT);
  345. } else {
  346. free_irq(DB1200_SD0_INSERT_INT, mmc_host);
  347. free_irq(DB1200_SD0_EJECT_INT, mmc_host);
  348. }
  349. ret = 0;
  350. out:
  351. return ret;
  352. }
  353. static void db1200_mmc_set_power(void *mmc_host, int state)
  354. {
  355. if (state) {
  356. bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD0PWR);
  357. msleep(400); /* stabilization time */
  358. } else
  359. bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD0PWR, 0);
  360. }
  361. static int db1200_mmc_card_readonly(void *mmc_host)
  362. {
  363. return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 1 : 0;
  364. }
  365. static int db1200_mmc_card_inserted(void *mmc_host)
  366. {
  367. return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT) ? 1 : 0;
  368. }
  369. static void db1200_mmcled_set(struct led_classdev *led,
  370. enum led_brightness brightness)
  371. {
  372. if (brightness != LED_OFF)
  373. bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
  374. else
  375. bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
  376. }
  377. static struct led_classdev db1200_mmc_led = {
  378. .brightness_set = db1200_mmcled_set,
  379. };
  380. /* -- */
  381. static irqreturn_t pb1200_mmc1_cd(int irq, void *ptr)
  382. {
  383. void(*mmc_cd)(struct mmc_host *, unsigned long);
  384. if (irq == PB1200_SD1_INSERT_INT) {
  385. disable_irq_nosync(PB1200_SD1_INSERT_INT);
  386. enable_irq(PB1200_SD1_EJECT_INT);
  387. } else {
  388. disable_irq_nosync(PB1200_SD1_EJECT_INT);
  389. enable_irq(PB1200_SD1_INSERT_INT);
  390. }
  391. /* link against CONFIG_MMC=m */
  392. mmc_cd = symbol_get(mmc_detect_change);
  393. if (mmc_cd) {
  394. mmc_cd(ptr, msecs_to_jiffies(500));
  395. symbol_put(mmc_detect_change);
  396. }
  397. return IRQ_HANDLED;
  398. }
  399. static int pb1200_mmc1_cd_setup(void *mmc_host, int en)
  400. {
  401. int ret;
  402. if (en) {
  403. ret = request_irq(PB1200_SD1_INSERT_INT, pb1200_mmc1_cd, 0,
  404. "sd1_insert", mmc_host);
  405. if (ret)
  406. goto out;
  407. ret = request_irq(PB1200_SD1_EJECT_INT, pb1200_mmc1_cd, 0,
  408. "sd1_eject", mmc_host);
  409. if (ret) {
  410. free_irq(PB1200_SD1_INSERT_INT, mmc_host);
  411. goto out;
  412. }
  413. if (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD1INSERT)
  414. enable_irq(PB1200_SD1_EJECT_INT);
  415. else
  416. enable_irq(PB1200_SD1_INSERT_INT);
  417. } else {
  418. free_irq(PB1200_SD1_INSERT_INT, mmc_host);
  419. free_irq(PB1200_SD1_EJECT_INT, mmc_host);
  420. }
  421. ret = 0;
  422. out:
  423. return ret;
  424. }
  425. static void pb1200_mmc1led_set(struct led_classdev *led,
  426. enum led_brightness brightness)
  427. {
  428. if (brightness != LED_OFF)
  429. bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED1, 0);
  430. else
  431. bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED1);
  432. }
  433. static struct led_classdev pb1200_mmc1_led = {
  434. .brightness_set = pb1200_mmc1led_set,
  435. };
  436. static void pb1200_mmc1_set_power(void *mmc_host, int state)
  437. {
  438. if (state) {
  439. bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD1PWR);
  440. msleep(400); /* stabilization time */
  441. } else
  442. bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD1PWR, 0);
  443. }
  444. static int pb1200_mmc1_card_readonly(void *mmc_host)
  445. {
  446. return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD1WP) ? 1 : 0;
  447. }
  448. static int pb1200_mmc1_card_inserted(void *mmc_host)
  449. {
  450. return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD1INSERT) ? 1 : 0;
  451. }
  452. static struct au1xmmc_platform_data db1200_mmc_platdata[2] = {
  453. [0] = {
  454. .cd_setup = db1200_mmc_cd_setup,
  455. .set_power = db1200_mmc_set_power,
  456. .card_inserted = db1200_mmc_card_inserted,
  457. .card_readonly = db1200_mmc_card_readonly,
  458. .led = &db1200_mmc_led,
  459. },
  460. [1] = {
  461. .cd_setup = pb1200_mmc1_cd_setup,
  462. .set_power = pb1200_mmc1_set_power,
  463. .card_inserted = pb1200_mmc1_card_inserted,
  464. .card_readonly = pb1200_mmc1_card_readonly,
  465. .led = &pb1200_mmc1_led,
  466. },
  467. };
  468. static struct resource au1200_mmc0_resources[] = {
  469. [0] = {
  470. .start = AU1100_SD0_PHYS_ADDR,
  471. .end = AU1100_SD0_PHYS_ADDR + 0xfff,
  472. .flags = IORESOURCE_MEM,
  473. },
  474. [1] = {
  475. .start = AU1200_SD_INT,
  476. .end = AU1200_SD_INT,
  477. .flags = IORESOURCE_IRQ,
  478. },
  479. [2] = {
  480. .start = AU1200_DSCR_CMD0_SDMS_TX0,
  481. .end = AU1200_DSCR_CMD0_SDMS_TX0,
  482. .flags = IORESOURCE_DMA,
  483. },
  484. [3] = {
  485. .start = AU1200_DSCR_CMD0_SDMS_RX0,
  486. .end = AU1200_DSCR_CMD0_SDMS_RX0,
  487. .flags = IORESOURCE_DMA,
  488. }
  489. };
  490. static u64 au1xxx_mmc_dmamask = DMA_BIT_MASK(32);
  491. static struct platform_device db1200_mmc0_dev = {
  492. .name = "au1xxx-mmc",
  493. .id = 0,
  494. .dev = {
  495. .dma_mask = &au1xxx_mmc_dmamask,
  496. .coherent_dma_mask = DMA_BIT_MASK(32),
  497. .platform_data = &db1200_mmc_platdata[0],
  498. },
  499. .num_resources = ARRAY_SIZE(au1200_mmc0_resources),
  500. .resource = au1200_mmc0_resources,
  501. };
  502. static struct resource au1200_mmc1_res[] = {
  503. [0] = {
  504. .start = AU1100_SD1_PHYS_ADDR,
  505. .end = AU1100_SD1_PHYS_ADDR + 0xfff,
  506. .flags = IORESOURCE_MEM,
  507. },
  508. [1] = {
  509. .start = AU1200_SD_INT,
  510. .end = AU1200_SD_INT,
  511. .flags = IORESOURCE_IRQ,
  512. },
  513. [2] = {
  514. .start = AU1200_DSCR_CMD0_SDMS_TX1,
  515. .end = AU1200_DSCR_CMD0_SDMS_TX1,
  516. .flags = IORESOURCE_DMA,
  517. },
  518. [3] = {
  519. .start = AU1200_DSCR_CMD0_SDMS_RX1,
  520. .end = AU1200_DSCR_CMD0_SDMS_RX1,
  521. .flags = IORESOURCE_DMA,
  522. }
  523. };
  524. static struct platform_device pb1200_mmc1_dev = {
  525. .name = "au1xxx-mmc",
  526. .id = 1,
  527. .dev = {
  528. .dma_mask = &au1xxx_mmc_dmamask,
  529. .coherent_dma_mask = DMA_BIT_MASK(32),
  530. .platform_data = &db1200_mmc_platdata[1],
  531. },
  532. .num_resources = ARRAY_SIZE(au1200_mmc1_res),
  533. .resource = au1200_mmc1_res,
  534. };
  535. /**********************************************************************/
  536. static int db1200fb_panel_index(void)
  537. {
  538. return (bcsr_read(BCSR_SWITCHES) >> 8) & 0x0f;
  539. }
  540. static int db1200fb_panel_init(void)
  541. {
  542. /* Apply power */
  543. bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD |
  544. BCSR_BOARD_LCDBL);
  545. return 0;
  546. }
  547. static int db1200fb_panel_shutdown(void)
  548. {
  549. /* Remove power */
  550. bcsr_mod(BCSR_BOARD, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD |
  551. BCSR_BOARD_LCDBL, 0);
  552. return 0;
  553. }
  554. static struct au1200fb_platdata db1200fb_pd = {
  555. .panel_index = db1200fb_panel_index,
  556. .panel_init = db1200fb_panel_init,
  557. .panel_shutdown = db1200fb_panel_shutdown,
  558. };
  559. static struct resource au1200_lcd_res[] = {
  560. [0] = {
  561. .start = AU1200_LCD_PHYS_ADDR,
  562. .end = AU1200_LCD_PHYS_ADDR + 0x800 - 1,
  563. .flags = IORESOURCE_MEM,
  564. },
  565. [1] = {
  566. .start = AU1200_LCD_INT,
  567. .end = AU1200_LCD_INT,
  568. .flags = IORESOURCE_IRQ,
  569. }
  570. };
  571. static u64 au1200_lcd_dmamask = DMA_BIT_MASK(32);
  572. static struct platform_device au1200_lcd_dev = {
  573. .name = "au1200-lcd",
  574. .id = 0,
  575. .dev = {
  576. .dma_mask = &au1200_lcd_dmamask,
  577. .coherent_dma_mask = DMA_BIT_MASK(32),
  578. .platform_data = &db1200fb_pd,
  579. },
  580. .num_resources = ARRAY_SIZE(au1200_lcd_res),
  581. .resource = au1200_lcd_res,
  582. };
  583. /**********************************************************************/
  584. static struct resource au1200_psc0_res[] = {
  585. [0] = {
  586. .start = AU1550_PSC0_PHYS_ADDR,
  587. .end = AU1550_PSC0_PHYS_ADDR + 0xfff,
  588. .flags = IORESOURCE_MEM,
  589. },
  590. [1] = {
  591. .start = AU1200_PSC0_INT,
  592. .end = AU1200_PSC0_INT,
  593. .flags = IORESOURCE_IRQ,
  594. },
  595. [2] = {
  596. .start = AU1200_DSCR_CMD0_PSC0_TX,
  597. .end = AU1200_DSCR_CMD0_PSC0_TX,
  598. .flags = IORESOURCE_DMA,
  599. },
  600. [3] = {
  601. .start = AU1200_DSCR_CMD0_PSC0_RX,
  602. .end = AU1200_DSCR_CMD0_PSC0_RX,
  603. .flags = IORESOURCE_DMA,
  604. },
  605. };
  606. static struct platform_device db1200_i2c_dev = {
  607. .name = "au1xpsc_smbus",
  608. .id = 0, /* bus number */
  609. .num_resources = ARRAY_SIZE(au1200_psc0_res),
  610. .resource = au1200_psc0_res,
  611. };
  612. static void db1200_spi_cs_en(struct au1550_spi_info *spi, int cs, int pol)
  613. {
  614. if (cs)
  615. bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_SPISEL);
  616. else
  617. bcsr_mod(BCSR_RESETS, BCSR_RESETS_SPISEL, 0);
  618. }
  619. static struct au1550_spi_info db1200_spi_platdata = {
  620. .mainclk_hz = 50000000, /* PSC0 clock */
  621. .num_chipselect = 2,
  622. .activate_cs = db1200_spi_cs_en,
  623. };
  624. static u64 spi_dmamask = DMA_BIT_MASK(32);
  625. static struct platform_device db1200_spi_dev = {
  626. .dev = {
  627. .dma_mask = &spi_dmamask,
  628. .coherent_dma_mask = DMA_BIT_MASK(32),
  629. .platform_data = &db1200_spi_platdata,
  630. },
  631. .name = "au1550-spi",
  632. .id = 0, /* bus number */
  633. .num_resources = ARRAY_SIZE(au1200_psc0_res),
  634. .resource = au1200_psc0_res,
  635. };
  636. static struct resource au1200_psc1_res[] = {
  637. [0] = {
  638. .start = AU1550_PSC1_PHYS_ADDR,
  639. .end = AU1550_PSC1_PHYS_ADDR + 0xfff,
  640. .flags = IORESOURCE_MEM,
  641. },
  642. [1] = {
  643. .start = AU1200_PSC1_INT,
  644. .end = AU1200_PSC1_INT,
  645. .flags = IORESOURCE_IRQ,
  646. },
  647. [2] = {
  648. .start = AU1200_DSCR_CMD0_PSC1_TX,
  649. .end = AU1200_DSCR_CMD0_PSC1_TX,
  650. .flags = IORESOURCE_DMA,
  651. },
  652. [3] = {
  653. .start = AU1200_DSCR_CMD0_PSC1_RX,
  654. .end = AU1200_DSCR_CMD0_PSC1_RX,
  655. .flags = IORESOURCE_DMA,
  656. },
  657. };
  658. /* AC97 or I2S device */
  659. static struct platform_device db1200_audio_dev = {
  660. /* name assigned later based on switch setting */
  661. .id = 1, /* PSC ID */
  662. .num_resources = ARRAY_SIZE(au1200_psc1_res),
  663. .resource = au1200_psc1_res,
  664. };
  665. /* DB1200 ASoC card device */
  666. static struct platform_device db1200_sound_dev = {
  667. /* name assigned later based on switch setting */
  668. .id = 1, /* PSC ID */
  669. };
  670. static struct platform_device db1200_stac_dev = {
  671. .name = "ac97-codec",
  672. .id = 1, /* on PSC1 */
  673. };
  674. static struct platform_device db1200_audiodma_dev = {
  675. .name = "au1xpsc-pcm",
  676. .id = 1, /* PSC ID */
  677. };
  678. static struct platform_device *db1200_devs[] __initdata = {
  679. NULL, /* PSC0, selected by S6.8 */
  680. &db1200_ide_dev,
  681. &db1200_mmc0_dev,
  682. &au1200_lcd_dev,
  683. &db1200_eth_dev,
  684. &db1200_nand_dev,
  685. &db1200_audiodma_dev,
  686. &db1200_audio_dev,
  687. &db1200_stac_dev,
  688. &db1200_sound_dev,
  689. };
  690. static struct platform_device *pb1200_devs[] __initdata = {
  691. &pb1200_mmc1_dev,
  692. };
  693. /* Some peripheral base addresses differ on the PB1200 */
  694. static int __init pb1200_res_fixup(void)
  695. {
  696. /* CPLD Revs earlier than 4 cause problems */
  697. if (BCSR_WHOAMI_CPLD(bcsr_read(BCSR_WHOAMI)) <= 3) {
  698. printk(KERN_ERR "WARNING!!!\n");
  699. printk(KERN_ERR "WARNING!!!\n");
  700. printk(KERN_ERR "PB1200 must be at CPLD rev 4. Please have\n");
  701. printk(KERN_ERR "the board updated to latest revisions.\n");
  702. printk(KERN_ERR "This software will not work reliably\n");
  703. printk(KERN_ERR "on anything older than CPLD rev 4.!\n");
  704. printk(KERN_ERR "WARNING!!!\n");
  705. printk(KERN_ERR "WARNING!!!\n");
  706. return 1;
  707. }
  708. db1200_nand_res[0].start = PB1200_NAND_PHYS_ADDR;
  709. db1200_nand_res[0].end = PB1200_NAND_PHYS_ADDR + 0xff;
  710. db1200_ide_res[0].start = PB1200_IDE_PHYS_ADDR;
  711. db1200_ide_res[0].end = PB1200_IDE_PHYS_ADDR + DB1200_IDE_PHYS_LEN - 1;
  712. db1200_eth_res[0].start = PB1200_ETH_PHYS_ADDR;
  713. db1200_eth_res[0].end = PB1200_ETH_PHYS_ADDR + 0xff;
  714. return 0;
  715. }
  716. int __init db1200_dev_setup(void)
  717. {
  718. unsigned long pfc;
  719. unsigned short sw;
  720. int swapped, bid;
  721. struct clk *c;
  722. bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
  723. if ((bid == BCSR_WHOAMI_PB1200_DDR1) ||
  724. (bid == BCSR_WHOAMI_PB1200_DDR2)) {
  725. if (pb1200_res_fixup())
  726. return -ENODEV;
  727. }
  728. /* GPIO7 is low-level triggered CPLD cascade */
  729. irq_set_irq_type(AU1200_GPIO7_INT, IRQ_TYPE_LEVEL_LOW);
  730. bcsr_init_irq(DB1200_INT_BEGIN, DB1200_INT_END, AU1200_GPIO7_INT);
  731. /* SMBus/SPI on PSC0, Audio on PSC1 */
  732. pfc = alchemy_rdsys(AU1000_SYS_PINFUNC);
  733. pfc &= ~(SYS_PINFUNC_P0A | SYS_PINFUNC_P0B);
  734. pfc &= ~(SYS_PINFUNC_P1A | SYS_PINFUNC_P1B | SYS_PINFUNC_FS3);
  735. pfc |= SYS_PINFUNC_P1C; /* SPI is configured later */
  736. alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
  737. /* get 50MHz for I2C driver on PSC0 */
  738. c = clk_get(NULL, "psc0_intclk");
  739. if (!IS_ERR(c)) {
  740. pfc = clk_round_rate(c, 50000000);
  741. if ((pfc < 1) || (abs(50000000 - pfc) > 2500000))
  742. pr_warn("DB1200: cant get I2C close to 50MHz\n");
  743. else
  744. clk_set_rate(c, pfc);
  745. clk_prepare_enable(c);
  746. clk_put(c);
  747. }
  748. /* insert/eject pairs: one of both is always screaming. To avoid
  749. * issues they must not be automatically enabled when initially
  750. * requested.
  751. */
  752. irq_set_status_flags(DB1200_SD0_INSERT_INT, IRQ_NOAUTOEN);
  753. irq_set_status_flags(DB1200_SD0_EJECT_INT, IRQ_NOAUTOEN);
  754. irq_set_status_flags(DB1200_PC0_INSERT_INT, IRQ_NOAUTOEN);
  755. irq_set_status_flags(DB1200_PC0_EJECT_INT, IRQ_NOAUTOEN);
  756. irq_set_status_flags(DB1200_PC1_INSERT_INT, IRQ_NOAUTOEN);
  757. irq_set_status_flags(DB1200_PC1_EJECT_INT, IRQ_NOAUTOEN);
  758. i2c_register_board_info(0, db1200_i2c_devs,
  759. ARRAY_SIZE(db1200_i2c_devs));
  760. spi_register_board_info(db1200_spi_devs,
  761. ARRAY_SIZE(db1200_i2c_devs));
  762. /* SWITCHES: S6.8 I2C/SPI selector (OFF=I2C ON=SPI)
  763. * S6.7 AC97/I2S selector (OFF=AC97 ON=I2S)
  764. * or S12 on the PB1200.
  765. */
  766. /* NOTE: GPIO215 controls OTG VBUS supply. In SPI mode however
  767. * this pin is claimed by PSC0 (unused though, but pinmux doesn't
  768. * allow to free it without crippling the SPI interface).
  769. * As a result, in SPI mode, OTG simply won't work (PSC0 uses
  770. * it as an input pin which is pulled high on the boards).
  771. */
  772. pfc = alchemy_rdsys(AU1000_SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
  773. /* switch off OTG VBUS supply */
  774. gpio_request(215, "otg-vbus");
  775. gpio_direction_output(215, 1);
  776. printk(KERN_INFO "%s device configuration:\n", get_system_type());
  777. sw = bcsr_read(BCSR_SWITCHES);
  778. if (sw & BCSR_SWITCHES_DIP_8) {
  779. db1200_devs[0] = &db1200_i2c_dev;
  780. bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC0MUX, 0);
  781. pfc |= (2 << 17); /* GPIO2 block owns GPIO215 */
  782. printk(KERN_INFO " S6.8 OFF: PSC0 mode I2C\n");
  783. printk(KERN_INFO " OTG port VBUS supply available!\n");
  784. } else {
  785. db1200_devs[0] = &db1200_spi_dev;
  786. bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC0MUX);
  787. pfc |= (1 << 17); /* PSC0 owns GPIO215 */
  788. printk(KERN_INFO " S6.8 ON : PSC0 mode SPI\n");
  789. printk(KERN_INFO " OTG port VBUS supply disabled\n");
  790. }
  791. alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
  792. /* Audio: DIP7 selects I2S(0)/AC97(1), but need I2C for I2S!
  793. * so: DIP7=1 || DIP8=0 => AC97, DIP7=0 && DIP8=1 => I2S
  794. */
  795. sw &= BCSR_SWITCHES_DIP_8 | BCSR_SWITCHES_DIP_7;
  796. if (sw == BCSR_SWITCHES_DIP_8) {
  797. bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC1MUX);
  798. db1200_audio_dev.name = "au1xpsc_i2s";
  799. db1200_sound_dev.name = "db1200-i2s";
  800. printk(KERN_INFO " S6.7 ON : PSC1 mode I2S\n");
  801. } else {
  802. bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC1MUX, 0);
  803. db1200_audio_dev.name = "au1xpsc_ac97";
  804. db1200_sound_dev.name = "db1200-ac97";
  805. printk(KERN_INFO " S6.7 OFF: PSC1 mode AC97\n");
  806. }
  807. /* Audio PSC clock is supplied externally. (FIXME: platdata!!) */
  808. __raw_writel(PSC_SEL_CLK_SERCLK,
  809. (void __iomem *)KSEG1ADDR(AU1550_PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
  810. wmb();
  811. db1x_register_pcmcia_socket(
  812. AU1000_PCMCIA_ATTR_PHYS_ADDR,
  813. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1,
  814. AU1000_PCMCIA_MEM_PHYS_ADDR,
  815. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1,
  816. AU1000_PCMCIA_IO_PHYS_ADDR,
  817. AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1,
  818. DB1200_PC0_INT, DB1200_PC0_INSERT_INT,
  819. /*DB1200_PC0_STSCHG_INT*/0, DB1200_PC0_EJECT_INT, 0);
  820. db1x_register_pcmcia_socket(
  821. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004000000,
  822. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1,
  823. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004000000,
  824. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1,
  825. AU1000_PCMCIA_IO_PHYS_ADDR + 0x004000000,
  826. AU1000_PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1,
  827. DB1200_PC1_INT, DB1200_PC1_INSERT_INT,
  828. /*DB1200_PC1_STSCHG_INT*/0, DB1200_PC1_EJECT_INT, 1);
  829. swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1200_SWAPBOOT;
  830. db1x_register_norflash(64 << 20, 2, swapped);
  831. platform_add_devices(db1200_devs, ARRAY_SIZE(db1200_devs));
  832. /* PB1200 is a DB1200 with a 2nd MMC and Camera connector */
  833. if ((bid == BCSR_WHOAMI_PB1200_DDR1) ||
  834. (bid == BCSR_WHOAMI_PB1200_DDR2))
  835. platform_add_devices(pb1200_devs, ARRAY_SIZE(pb1200_devs));
  836. return 0;
  837. }