ts72xx.c 12 KB

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