kurobox_pro-setup.c 10 KB

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