ts72xx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. * arch/arm/mach-ep93xx/ts72xx.c
  3. * Technologic Systems TS72xx SBC support.
  4. *
  5. * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/io.h>
  17. #include <linux/mtd/rawnand.h>
  18. #include <linux/mtd/partitions.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/spi/flash.h>
  21. #include <linux/spi/mmc_spi.h>
  22. #include <linux/mmc/host.h>
  23. #include <linux/platform_data/spi-ep93xx.h>
  24. #include <mach/gpio-ep93xx.h>
  25. #include <mach/hardware.h>
  26. #include <mach/irqs.h>
  27. #include <mach/gpio-ep93xx.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/mach/arch.h>
  31. #include "soc.h"
  32. #include "ts72xx.h"
  33. /*************************************************************************
  34. * IO map
  35. *************************************************************************/
  36. static struct map_desc ts72xx_io_desc[] __initdata = {
  37. {
  38. .virtual = (unsigned long)TS72XX_MODEL_VIRT_BASE,
  39. .pfn = __phys_to_pfn(TS72XX_MODEL_PHYS_BASE),
  40. .length = TS72XX_MODEL_SIZE,
  41. .type = MT_DEVICE,
  42. }, {
  43. .virtual = (unsigned long)TS72XX_OPTIONS_VIRT_BASE,
  44. .pfn = __phys_to_pfn(TS72XX_OPTIONS_PHYS_BASE),
  45. .length = TS72XX_OPTIONS_SIZE,
  46. .type = MT_DEVICE,
  47. }, {
  48. .virtual = (unsigned long)TS72XX_OPTIONS2_VIRT_BASE,
  49. .pfn = __phys_to_pfn(TS72XX_OPTIONS2_PHYS_BASE),
  50. .length = TS72XX_OPTIONS2_SIZE,
  51. .type = MT_DEVICE,
  52. }, {
  53. .virtual = (unsigned long)TS72XX_CPLDVER_VIRT_BASE,
  54. .pfn = __phys_to_pfn(TS72XX_CPLDVER_PHYS_BASE),
  55. .length = TS72XX_CPLDVER_SIZE,
  56. .type = MT_DEVICE,
  57. }
  58. };
  59. static void __init ts72xx_map_io(void)
  60. {
  61. ep93xx_map_io();
  62. iotable_init(ts72xx_io_desc, ARRAY_SIZE(ts72xx_io_desc));
  63. }
  64. /*************************************************************************
  65. * NAND flash
  66. *************************************************************************/
  67. #define TS72XX_NAND_CONTROL_ADDR_LINE 22 /* 0xN0400000 */
  68. #define TS72XX_NAND_BUSY_ADDR_LINE 23 /* 0xN0800000 */
  69. static void ts72xx_nand_hwcontrol(struct mtd_info *mtd,
  70. int cmd, unsigned int ctrl)
  71. {
  72. struct nand_chip *chip = mtd_to_nand(mtd);
  73. if (ctrl & NAND_CTRL_CHANGE) {
  74. void __iomem *addr = chip->IO_ADDR_R;
  75. unsigned char bits;
  76. addr += (1 << TS72XX_NAND_CONTROL_ADDR_LINE);
  77. bits = __raw_readb(addr) & ~0x07;
  78. bits |= (ctrl & NAND_NCE) << 2; /* bit 0 -> bit 2 */
  79. bits |= (ctrl & NAND_CLE); /* bit 1 -> bit 1 */
  80. bits |= (ctrl & NAND_ALE) >> 2; /* bit 2 -> bit 0 */
  81. __raw_writeb(bits, addr);
  82. }
  83. if (cmd != NAND_CMD_NONE)
  84. __raw_writeb(cmd, chip->IO_ADDR_W);
  85. }
  86. static int ts72xx_nand_device_ready(struct mtd_info *mtd)
  87. {
  88. struct nand_chip *chip = mtd_to_nand(mtd);
  89. void __iomem *addr = chip->IO_ADDR_R;
  90. addr += (1 << TS72XX_NAND_BUSY_ADDR_LINE);
  91. return !!(__raw_readb(addr) & 0x20);
  92. }
  93. #define TS72XX_BOOTROM_PART_SIZE (SZ_16K)
  94. #define TS72XX_REDBOOT_PART_SIZE (SZ_2M + SZ_1M)
  95. static struct mtd_partition ts72xx_nand_parts[] = {
  96. {
  97. .name = "TS-BOOTROM",
  98. .offset = 0,
  99. .size = TS72XX_BOOTROM_PART_SIZE,
  100. .mask_flags = MTD_WRITEABLE, /* force read-only */
  101. }, {
  102. .name = "Linux",
  103. .offset = MTDPART_OFS_RETAIN,
  104. .size = TS72XX_REDBOOT_PART_SIZE,
  105. /* leave so much for last partition */
  106. }, {
  107. .name = "RedBoot",
  108. .offset = MTDPART_OFS_APPEND,
  109. .size = MTDPART_SIZ_FULL,
  110. .mask_flags = MTD_WRITEABLE, /* force read-only */
  111. },
  112. };
  113. static struct platform_nand_data ts72xx_nand_data = {
  114. .chip = {
  115. .nr_chips = 1,
  116. .chip_offset = 0,
  117. .chip_delay = 15,
  118. },
  119. .ctrl = {
  120. .cmd_ctrl = ts72xx_nand_hwcontrol,
  121. .dev_ready = ts72xx_nand_device_ready,
  122. },
  123. };
  124. static struct resource ts72xx_nand_resource[] = {
  125. {
  126. .start = 0, /* filled in later */
  127. .end = 0, /* filled in later */
  128. .flags = IORESOURCE_MEM,
  129. },
  130. };
  131. static struct platform_device ts72xx_nand_flash = {
  132. .name = "gen_nand",
  133. .id = -1,
  134. .dev.platform_data = &ts72xx_nand_data,
  135. .resource = ts72xx_nand_resource,
  136. .num_resources = ARRAY_SIZE(ts72xx_nand_resource),
  137. };
  138. void __init ts72xx_register_flash(struct mtd_partition *parts, int n,
  139. resource_size_t start)
  140. {
  141. /*
  142. * TS7200 has NOR flash all other TS72xx board have NAND flash.
  143. */
  144. if (board_is_ts7200()) {
  145. ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_16M);
  146. } else {
  147. ts72xx_nand_resource[0].start = start;
  148. ts72xx_nand_resource[0].end = start + SZ_16M - 1;
  149. ts72xx_nand_data.chip.partitions = parts;
  150. ts72xx_nand_data.chip.nr_partitions = n;
  151. platform_device_register(&ts72xx_nand_flash);
  152. }
  153. }
  154. /*************************************************************************
  155. * RTC M48T86
  156. *************************************************************************/
  157. #define TS72XX_RTC_INDEX_PHYS_BASE (EP93XX_CS1_PHYS_BASE + 0x00800000)
  158. #define TS72XX_RTC_DATA_PHYS_BASE (EP93XX_CS1_PHYS_BASE + 0x01700000)
  159. static struct resource ts72xx_rtc_resources[] = {
  160. DEFINE_RES_MEM(TS72XX_RTC_INDEX_PHYS_BASE, 0x01),
  161. DEFINE_RES_MEM(TS72XX_RTC_DATA_PHYS_BASE, 0x01),
  162. };
  163. static struct platform_device ts72xx_rtc_device = {
  164. .name = "rtc-m48t86",
  165. .id = -1,
  166. .resource = ts72xx_rtc_resources,
  167. .num_resources = ARRAY_SIZE(ts72xx_rtc_resources),
  168. };
  169. /*************************************************************************
  170. * Watchdog (in CPLD)
  171. *************************************************************************/
  172. #define TS72XX_WDT_CONTROL_PHYS_BASE (EP93XX_CS2_PHYS_BASE + 0x03800000)
  173. #define TS72XX_WDT_FEED_PHYS_BASE (EP93XX_CS2_PHYS_BASE + 0x03c00000)
  174. static struct resource ts72xx_wdt_resources[] = {
  175. DEFINE_RES_MEM(TS72XX_WDT_CONTROL_PHYS_BASE, 0x01),
  176. DEFINE_RES_MEM(TS72XX_WDT_FEED_PHYS_BASE, 0x01),
  177. };
  178. static struct platform_device ts72xx_wdt_device = {
  179. .name = "ts72xx-wdt",
  180. .id = -1,
  181. .resource = ts72xx_wdt_resources,
  182. .num_resources = ARRAY_SIZE(ts72xx_wdt_resources),
  183. };
  184. /*************************************************************************
  185. * ETH
  186. *************************************************************************/
  187. static struct ep93xx_eth_data __initdata ts72xx_eth_data = {
  188. .phy_id = 1,
  189. };
  190. /*************************************************************************
  191. * SPI SD/MMC host
  192. *************************************************************************/
  193. #define BK3_EN_SDCARD_PHYS_BASE 0x12400000
  194. #define BK3_EN_SDCARD_PWR 0x0
  195. #define BK3_DIS_SDCARD_PWR 0x0C
  196. static void bk3_mmc_spi_setpower(struct device *dev, unsigned int vdd)
  197. {
  198. void __iomem *pwr_sd = ioremap(BK3_EN_SDCARD_PHYS_BASE, SZ_4K);
  199. if (!pwr_sd) {
  200. pr_err("Failed to enable SD card power!");
  201. return;
  202. }
  203. pr_debug("%s: SD card pwr %s VDD:0x%x\n", __func__,
  204. !!vdd ? "ON" : "OFF", vdd);
  205. if (!!vdd)
  206. __raw_writeb(BK3_EN_SDCARD_PWR, pwr_sd);
  207. else
  208. __raw_writeb(BK3_DIS_SDCARD_PWR, pwr_sd);
  209. iounmap(pwr_sd);
  210. }
  211. static struct mmc_spi_platform_data bk3_spi_mmc_data = {
  212. .detect_delay = 500,
  213. .powerup_msecs = 100,
  214. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  215. .caps = MMC_CAP_NONREMOVABLE,
  216. .setpower = bk3_mmc_spi_setpower,
  217. };
  218. /*************************************************************************
  219. * SPI Bus - SD card access
  220. *************************************************************************/
  221. static struct spi_board_info bk3_spi_board_info[] __initdata = {
  222. {
  223. .modalias = "mmc_spi",
  224. .platform_data = &bk3_spi_mmc_data,
  225. .max_speed_hz = 7.4E6,
  226. .bus_num = 0,
  227. .chip_select = 0,
  228. .mode = SPI_MODE_0,
  229. },
  230. };
  231. /*
  232. * This is a stub -> the FGPIO[3] pin is not connected on the schematic
  233. * The all work is performed automatically by !SPI_FRAME (SFRM1) and
  234. * goes through CPLD
  235. */
  236. static int bk3_spi_chipselects[] __initdata = {
  237. EP93XX_GPIO_LINE_F(3),
  238. };
  239. static struct ep93xx_spi_info bk3_spi_master __initdata = {
  240. .chipselect = bk3_spi_chipselects,
  241. .num_chipselect = ARRAY_SIZE(bk3_spi_chipselects),
  242. .use_dma = 1,
  243. };
  244. /*************************************************************************
  245. * TS72XX support code
  246. *************************************************************************/
  247. #if IS_ENABLED(CONFIG_FPGA_MGR_TS73XX)
  248. /* Relative to EP93XX_CS1_PHYS_BASE */
  249. #define TS73XX_FPGA_LOADER_BASE 0x03c00000
  250. static struct resource ts73xx_fpga_resources[] = {
  251. {
  252. .start = EP93XX_CS1_PHYS_BASE + TS73XX_FPGA_LOADER_BASE,
  253. .end = EP93XX_CS1_PHYS_BASE + TS73XX_FPGA_LOADER_BASE + 1,
  254. .flags = IORESOURCE_MEM,
  255. },
  256. };
  257. static struct platform_device ts73xx_fpga_device = {
  258. .name = "ts73xx-fpga-mgr",
  259. .id = -1,
  260. .resource = ts73xx_fpga_resources,
  261. .num_resources = ARRAY_SIZE(ts73xx_fpga_resources),
  262. };
  263. #endif
  264. /*************************************************************************
  265. * SPI Bus
  266. *************************************************************************/
  267. static struct spi_board_info ts72xx_spi_devices[] __initdata = {
  268. {
  269. .modalias = "tmp122",
  270. .max_speed_hz = 2 * 1000 * 1000,
  271. .bus_num = 0,
  272. .chip_select = 0,
  273. },
  274. };
  275. static int ts72xx_spi_chipselects[] __initdata = {
  276. EP93XX_GPIO_LINE_F(2), /* DIO_17 */
  277. };
  278. static struct ep93xx_spi_info ts72xx_spi_info __initdata = {
  279. .chipselect = ts72xx_spi_chipselects,
  280. .num_chipselect = ARRAY_SIZE(ts72xx_spi_chipselects),
  281. };
  282. static void __init ts72xx_init_machine(void)
  283. {
  284. ep93xx_init_devices();
  285. ts72xx_register_flash(ts72xx_nand_parts, ARRAY_SIZE(ts72xx_nand_parts),
  286. is_ts9420_installed() ?
  287. EP93XX_CS7_PHYS_BASE : EP93XX_CS6_PHYS_BASE);
  288. platform_device_register(&ts72xx_rtc_device);
  289. platform_device_register(&ts72xx_wdt_device);
  290. ep93xx_register_eth(&ts72xx_eth_data, 1);
  291. #if IS_ENABLED(CONFIG_FPGA_MGR_TS73XX)
  292. if (board_is_ts7300())
  293. platform_device_register(&ts73xx_fpga_device);
  294. #endif
  295. ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices,
  296. ARRAY_SIZE(ts72xx_spi_devices));
  297. }
  298. MACHINE_START(TS72XX, "Technologic Systems TS-72xx SBC")
  299. /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
  300. .atag_offset = 0x100,
  301. .map_io = ts72xx_map_io,
  302. .init_irq = ep93xx_init_irq,
  303. .init_time = ep93xx_timer_init,
  304. .init_machine = ts72xx_init_machine,
  305. .init_late = ep93xx_init_late,
  306. .restart = ep93xx_restart,
  307. MACHINE_END
  308. /*************************************************************************
  309. * EP93xx I2S audio peripheral handling
  310. *************************************************************************/
  311. static struct resource ep93xx_i2s_resource[] = {
  312. DEFINE_RES_MEM(EP93XX_I2S_PHYS_BASE, 0x100),
  313. DEFINE_RES_IRQ_NAMED(IRQ_EP93XX_SAI, "spilink i2s slave"),
  314. };
  315. static struct platform_device ep93xx_i2s_device = {
  316. .name = "ep93xx-spilink-i2s",
  317. .id = -1,
  318. .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
  319. .resource = ep93xx_i2s_resource,
  320. };
  321. /*************************************************************************
  322. * BK3 support code
  323. *************************************************************************/
  324. static struct mtd_partition bk3_nand_parts[] = {
  325. {
  326. .name = "System",
  327. .offset = 0x00000000,
  328. .size = 0x01e00000,
  329. }, {
  330. .name = "Data",
  331. .offset = 0x01e00000,
  332. .size = 0x05f20000
  333. }, {
  334. .name = "RedBoot",
  335. .offset = 0x07d20000,
  336. .size = 0x002e0000,
  337. .mask_flags = MTD_WRITEABLE, /* force RO */
  338. },
  339. };
  340. static void __init bk3_init_machine(void)
  341. {
  342. ep93xx_init_devices();
  343. ts72xx_register_flash(bk3_nand_parts, ARRAY_SIZE(bk3_nand_parts),
  344. EP93XX_CS6_PHYS_BASE);
  345. ep93xx_register_eth(&ts72xx_eth_data, 1);
  346. ep93xx_register_spi(&bk3_spi_master, bk3_spi_board_info,
  347. ARRAY_SIZE(bk3_spi_board_info));
  348. /* Configure ep93xx's I2S to use AC97 pins */
  349. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
  350. platform_device_register(&ep93xx_i2s_device);
  351. }
  352. MACHINE_START(BK3, "Liebherr controller BK3.1")
  353. /* Maintainer: Lukasz Majewski <lukma@denx.de> */
  354. .atag_offset = 0x100,
  355. .map_io = ts72xx_map_io,
  356. .init_irq = ep93xx_init_irq,
  357. .init_time = ep93xx_timer_init,
  358. .init_machine = bk3_init_machine,
  359. .init_late = ep93xx_init_late,
  360. .restart = ep93xx_restart,
  361. MACHINE_END