ts72xx.c 12 KB

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