kurobox_pro-setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/arm/mach-orion5x/kurobox_pro-setup.c
  4. *
  5. * Maintainer: Ronen Shitrit <[email protected]>
  6. */
  7. #include <linux/gpio.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/pci.h>
  12. #include <linux/irq.h>
  13. #include <linux/delay.h>
  14. #include <linux/mtd/physmap.h>
  15. #include <linux/mtd/rawnand.h>
  16. #include <linux/mv643xx_eth.h>
  17. #include <linux/i2c.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/ata_platform.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/pci.h>
  23. #include <linux/platform_data/mtd-orion_nand.h>
  24. #include "common.h"
  25. #include "mpp.h"
  26. #include "orion5x.h"
  27. /*****************************************************************************
  28. * KUROBOX-PRO Info
  29. ****************************************************************************/
  30. /*
  31. * 256K NOR flash Device bus boot chip select
  32. */
  33. #define KUROBOX_PRO_NOR_BOOT_BASE 0xf4000000
  34. #define KUROBOX_PRO_NOR_BOOT_SIZE SZ_256K
  35. /*
  36. * 256M NAND flash on Device bus chip select 1
  37. */
  38. #define KUROBOX_PRO_NAND_BASE 0xfc000000
  39. #define KUROBOX_PRO_NAND_SIZE SZ_2M
  40. /*****************************************************************************
  41. * 256MB NAND Flash on Device bus CS0
  42. ****************************************************************************/
  43. static struct mtd_partition kurobox_pro_nand_parts[] = {
  44. {
  45. .name = "uImage",
  46. .offset = 0,
  47. .size = SZ_4M,
  48. }, {
  49. .name = "rootfs",
  50. .offset = SZ_4M,
  51. .size = SZ_64M,
  52. }, {
  53. .name = "extra",
  54. .offset = SZ_4M + SZ_64M,
  55. .size = SZ_256M - (SZ_4M + SZ_64M),
  56. },
  57. };
  58. static struct resource kurobox_pro_nand_resource = {
  59. .flags = IORESOURCE_MEM,
  60. .start = KUROBOX_PRO_NAND_BASE,
  61. .end = KUROBOX_PRO_NAND_BASE + KUROBOX_PRO_NAND_SIZE - 1,
  62. };
  63. static struct orion_nand_data kurobox_pro_nand_data = {
  64. .parts = kurobox_pro_nand_parts,
  65. .nr_parts = ARRAY_SIZE(kurobox_pro_nand_parts),
  66. .cle = 0,
  67. .ale = 1,
  68. .width = 8,
  69. };
  70. static struct platform_device kurobox_pro_nand_flash = {
  71. .name = "orion_nand",
  72. .id = -1,
  73. .dev = {
  74. .platform_data = &kurobox_pro_nand_data,
  75. },
  76. .resource = &kurobox_pro_nand_resource,
  77. .num_resources = 1,
  78. };
  79. /*****************************************************************************
  80. * 256KB NOR Flash on BOOT Device
  81. ****************************************************************************/
  82. static struct physmap_flash_data kurobox_pro_nor_flash_data = {
  83. .width = 1,
  84. };
  85. static struct resource kurobox_pro_nor_flash_resource = {
  86. .flags = IORESOURCE_MEM,
  87. .start = KUROBOX_PRO_NOR_BOOT_BASE,
  88. .end = KUROBOX_PRO_NOR_BOOT_BASE + KUROBOX_PRO_NOR_BOOT_SIZE - 1,
  89. };
  90. static struct platform_device kurobox_pro_nor_flash = {
  91. .name = "physmap-flash",
  92. .id = 0,
  93. .dev = {
  94. .platform_data = &kurobox_pro_nor_flash_data,
  95. },
  96. .num_resources = 1,
  97. .resource = &kurobox_pro_nor_flash_resource,
  98. };
  99. /*****************************************************************************
  100. * PCI
  101. ****************************************************************************/
  102. static int __init kurobox_pro_pci_map_irq(const struct pci_dev *dev, u8 slot,
  103. u8 pin)
  104. {
  105. int irq;
  106. /*
  107. * Check for devices with hard-wired IRQs.
  108. */
  109. irq = orion5x_pci_map_irq(dev, slot, pin);
  110. if (irq != -1)
  111. return irq;
  112. /*
  113. * PCI isn't used on the Kuro
  114. */
  115. return -1;
  116. }
  117. static struct hw_pci kurobox_pro_pci __initdata = {
  118. .nr_controllers = 2,
  119. .setup = orion5x_pci_sys_setup,
  120. .scan = orion5x_pci_sys_scan_bus,
  121. .map_irq = kurobox_pro_pci_map_irq,
  122. };
  123. static int __init kurobox_pro_pci_init(void)
  124. {
  125. if (machine_is_kurobox_pro()) {
  126. orion5x_pci_disable();
  127. pci_common_init(&kurobox_pro_pci);
  128. }
  129. return 0;
  130. }
  131. subsys_initcall(kurobox_pro_pci_init);
  132. /*****************************************************************************
  133. * Ethernet
  134. ****************************************************************************/
  135. static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
  136. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  137. };
  138. /*****************************************************************************
  139. * RTC 5C372a on I2C bus
  140. ****************************************************************************/
  141. static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
  142. I2C_BOARD_INFO("rs5c372a", 0x32),
  143. };
  144. /*****************************************************************************
  145. * SATA
  146. ****************************************************************************/
  147. static struct mv_sata_platform_data kurobox_pro_sata_data = {
  148. .n_ports = 2,
  149. };
  150. /*****************************************************************************
  151. * Kurobox Pro specific power off method via UART1-attached microcontroller
  152. ****************************************************************************/
  153. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  154. static int kurobox_pro_miconread(unsigned char *buf, int count)
  155. {
  156. int i;
  157. int timeout;
  158. for (i = 0; i < count; i++) {
  159. timeout = 10;
  160. while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
  161. if (--timeout == 0)
  162. break;
  163. udelay(1000);
  164. }
  165. if (timeout == 0)
  166. break;
  167. buf[i] = readl(UART1_REG(RX));
  168. }
  169. /* return read bytes */
  170. return i;
  171. }
  172. static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
  173. {
  174. int i = 0;
  175. while (count--) {
  176. while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
  177. barrier();
  178. writel(buf[i++], UART1_REG(TX));
  179. }
  180. return 0;
  181. }
  182. static int kurobox_pro_miconsend(const unsigned char *data, int count)
  183. {
  184. int i;
  185. unsigned char checksum = 0;
  186. unsigned char recv_buf[40];
  187. unsigned char send_buf[40];
  188. unsigned char correct_ack[3];
  189. int retry = 2;
  190. /* Generate checksum */
  191. for (i = 0; i < count; i++)
  192. checksum -= data[i];
  193. do {
  194. /* Send data */
  195. kurobox_pro_miconwrite(data, count);
  196. /* send checksum */
  197. kurobox_pro_miconwrite(&checksum, 1);
  198. if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
  199. printk(KERN_ERR ">%s: receive failed.\n", __func__);
  200. /* send preamble to clear the receive buffer */
  201. memset(&send_buf, 0xff, sizeof(send_buf));
  202. kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
  203. /* make dummy reads */
  204. mdelay(100);
  205. kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
  206. } else {
  207. /* Generate expected ack */
  208. correct_ack[0] = 0x01;
  209. correct_ack[1] = data[1];
  210. correct_ack[2] = 0x00;
  211. /* checksum Check */
  212. if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
  213. recv_buf[3]) & 0xFF) {
  214. printk(KERN_ERR ">%s: Checksum Error : "
  215. "Received data[%02x, %02x, %02x, %02x]"
  216. "\n", __func__, recv_buf[0],
  217. recv_buf[1], recv_buf[2], recv_buf[3]);
  218. } else {
  219. /* Check Received Data */
  220. if (correct_ack[0] == recv_buf[0] &&
  221. correct_ack[1] == recv_buf[1] &&
  222. correct_ack[2] == recv_buf[2]) {
  223. /* Interval for next command */
  224. mdelay(10);
  225. /* Receive ACK */
  226. return 0;
  227. }
  228. }
  229. /* Received NAK or illegal Data */
  230. printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
  231. "Received\n", __func__);
  232. }
  233. } while (retry--);
  234. /* Interval for next command */
  235. mdelay(10);
  236. return -1;
  237. }
  238. static void kurobox_pro_power_off(void)
  239. {
  240. const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
  241. const unsigned char shutdownwait[] = {0x00, 0x0c};
  242. const unsigned char poweroff[] = {0x00, 0x06};
  243. /* 38400 baud divisor */
  244. const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
  245. pr_info("%s: triggering power-off...\n", __func__);
  246. /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
  247. writel(0x83, UART1_REG(LCR));
  248. writel(divisor & 0xff, UART1_REG(DLL));
  249. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  250. writel(0x1b, UART1_REG(LCR));
  251. writel(0x00, UART1_REG(IER));
  252. writel(0x07, UART1_REG(FCR));
  253. writel(0x00, UART1_REG(MCR));
  254. /* Send the commands to shutdown the Kurobox Pro */
  255. kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
  256. kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
  257. kurobox_pro_miconsend(poweroff, sizeof(poweroff));
  258. }
  259. /*****************************************************************************
  260. * General Setup
  261. ****************************************************************************/
  262. static unsigned int kurobox_pro_mpp_modes[] __initdata = {
  263. MPP0_UNUSED,
  264. MPP1_UNUSED,
  265. MPP2_GPIO, /* GPIO Micon */
  266. MPP3_GPIO, /* GPIO Rtc */
  267. MPP4_UNUSED,
  268. MPP5_UNUSED,
  269. MPP6_NAND, /* NAND Flash REn */
  270. MPP7_NAND, /* NAND Flash WEn */
  271. MPP8_UNUSED,
  272. MPP9_UNUSED,
  273. MPP10_UNUSED,
  274. MPP11_UNUSED,
  275. MPP12_SATA_LED, /* SATA 0 presence */
  276. MPP13_SATA_LED, /* SATA 1 presence */
  277. MPP14_SATA_LED, /* SATA 0 active */
  278. MPP15_SATA_LED, /* SATA 1 active */
  279. MPP16_UART, /* UART1 RXD */
  280. MPP17_UART, /* UART1 TXD */
  281. MPP18_UART, /* UART1 CTSn */
  282. MPP19_UART, /* UART1 RTSn */
  283. 0,
  284. };
  285. static void __init kurobox_pro_init(void)
  286. {
  287. /*
  288. * Setup basic Orion functions. Need to be called early.
  289. */
  290. orion5x_init();
  291. orion5x_mpp_conf(kurobox_pro_mpp_modes);
  292. /*
  293. * Configure peripherals.
  294. */
  295. orion5x_ehci0_init();
  296. orion5x_ehci1_init();
  297. orion5x_eth_init(&kurobox_pro_eth_data);
  298. orion5x_i2c_init();
  299. orion5x_sata_init(&kurobox_pro_sata_data);
  300. orion5x_uart0_init();
  301. orion5x_uart1_init();
  302. orion5x_xor_init();
  303. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  304. ORION_MBUS_DEVBUS_BOOT_ATTR,
  305. KUROBOX_PRO_NOR_BOOT_BASE,
  306. KUROBOX_PRO_NOR_BOOT_SIZE);
  307. platform_device_register(&kurobox_pro_nor_flash);
  308. if (machine_is_kurobox_pro()) {
  309. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(0),
  310. ORION_MBUS_DEVBUS_ATTR(0),
  311. KUROBOX_PRO_NAND_BASE,
  312. KUROBOX_PRO_NAND_SIZE);
  313. platform_device_register(&kurobox_pro_nand_flash);
  314. }
  315. i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
  316. /* register Kurobox Pro specific power-off method */
  317. pm_power_off = kurobox_pro_power_off;
  318. }
  319. #ifdef CONFIG_MACH_KUROBOX_PRO
  320. MACHINE_START(KUROBOX_PRO, "Buffalo/Revogear Kurobox Pro")
  321. /* Maintainer: Ronen Shitrit <[email protected]> */
  322. .atag_offset = 0x100,
  323. .nr_irqs = ORION5X_NR_IRQS,
  324. .init_machine = kurobox_pro_init,
  325. .map_io = orion5x_map_io,
  326. .init_early = orion5x_init_early,
  327. .init_irq = orion5x_init_irq,
  328. .init_time = orion5x_timer_init,
  329. .fixup = tag_fixup_mem32,
  330. .restart = orion5x_restart,
  331. MACHINE_END
  332. #endif
  333. #ifdef CONFIG_MACH_LINKSTATION_PRO
  334. MACHINE_START(LINKSTATION_PRO, "Buffalo Linkstation Pro/Live")
  335. /* Maintainer: Byron Bradley <[email protected]> */
  336. .atag_offset = 0x100,
  337. .nr_irqs = ORION5X_NR_IRQS,
  338. .init_machine = kurobox_pro_init,
  339. .map_io = orion5x_map_io,
  340. .init_early = orion5x_init_early,
  341. .init_irq = orion5x_init_irq,
  342. .init_time = orion5x_timer_init,
  343. .fixup = tag_fixup_mem32,
  344. .restart = orion5x_restart,
  345. MACHINE_END
  346. #endif