kurobox_pro-setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 <linux/platform_data/mtd-orion_nand.h>
  27. #include "common.h"
  28. #include "mpp.h"
  29. #include "orion5x.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. .setup = orion5x_pci_sys_setup,
  123. .scan = orion5x_pci_sys_scan_bus,
  124. .map_irq = kurobox_pro_pci_map_irq,
  125. };
  126. static int __init kurobox_pro_pci_init(void)
  127. {
  128. if (machine_is_kurobox_pro()) {
  129. orion5x_pci_disable();
  130. pci_common_init(&kurobox_pro_pci);
  131. }
  132. return 0;
  133. }
  134. subsys_initcall(kurobox_pro_pci_init);
  135. /*****************************************************************************
  136. * Ethernet
  137. ****************************************************************************/
  138. static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
  139. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  140. };
  141. /*****************************************************************************
  142. * RTC 5C372a on I2C bus
  143. ****************************************************************************/
  144. static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
  145. I2C_BOARD_INFO("rs5c372a", 0x32),
  146. };
  147. /*****************************************************************************
  148. * SATA
  149. ****************************************************************************/
  150. static struct mv_sata_platform_data kurobox_pro_sata_data = {
  151. .n_ports = 2,
  152. };
  153. /*****************************************************************************
  154. * Kurobox Pro specific power off method via UART1-attached microcontroller
  155. ****************************************************************************/
  156. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  157. static int kurobox_pro_miconread(unsigned char *buf, int count)
  158. {
  159. int i;
  160. int timeout;
  161. for (i = 0; i < count; i++) {
  162. timeout = 10;
  163. while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
  164. if (--timeout == 0)
  165. break;
  166. udelay(1000);
  167. }
  168. if (timeout == 0)
  169. break;
  170. buf[i] = readl(UART1_REG(RX));
  171. }
  172. /* return read bytes */
  173. return i;
  174. }
  175. static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
  176. {
  177. int i = 0;
  178. while (count--) {
  179. while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
  180. barrier();
  181. writel(buf[i++], UART1_REG(TX));
  182. }
  183. return 0;
  184. }
  185. static int kurobox_pro_miconsend(const unsigned char *data, int count)
  186. {
  187. int i;
  188. unsigned char checksum = 0;
  189. unsigned char recv_buf[40];
  190. unsigned char send_buf[40];
  191. unsigned char correct_ack[3];
  192. int retry = 2;
  193. /* Generate checksum */
  194. for (i = 0; i < count; i++)
  195. checksum -= data[i];
  196. do {
  197. /* Send data */
  198. kurobox_pro_miconwrite(data, count);
  199. /* send checksum */
  200. kurobox_pro_miconwrite(&checksum, 1);
  201. if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
  202. printk(KERN_ERR ">%s: receive failed.\n", __func__);
  203. /* send preamble to clear the receive buffer */
  204. memset(&send_buf, 0xff, sizeof(send_buf));
  205. kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
  206. /* make dummy reads */
  207. mdelay(100);
  208. kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
  209. } else {
  210. /* Generate expected ack */
  211. correct_ack[0] = 0x01;
  212. correct_ack[1] = data[1];
  213. correct_ack[2] = 0x00;
  214. /* checksum Check */
  215. if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
  216. recv_buf[3]) & 0xFF) {
  217. printk(KERN_ERR ">%s: Checksum Error : "
  218. "Received data[%02x, %02x, %02x, %02x]"
  219. "\n", __func__, recv_buf[0],
  220. recv_buf[1], recv_buf[2], recv_buf[3]);
  221. } else {
  222. /* Check Received Data */
  223. if (correct_ack[0] == recv_buf[0] &&
  224. correct_ack[1] == recv_buf[1] &&
  225. correct_ack[2] == recv_buf[2]) {
  226. /* Interval for next command */
  227. mdelay(10);
  228. /* Receive ACK */
  229. return 0;
  230. }
  231. }
  232. /* Received NAK or illegal Data */
  233. printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
  234. "Received\n", __func__);
  235. }
  236. } while (retry--);
  237. /* Interval for next command */
  238. mdelay(10);
  239. return -1;
  240. }
  241. static void kurobox_pro_power_off(void)
  242. {
  243. const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
  244. const unsigned char shutdownwait[] = {0x00, 0x0c};
  245. const unsigned char poweroff[] = {0x00, 0x06};
  246. /* 38400 baud divisor */
  247. const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
  248. pr_info("%s: triggering power-off...\n", __func__);
  249. /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
  250. writel(0x83, UART1_REG(LCR));
  251. writel(divisor & 0xff, UART1_REG(DLL));
  252. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  253. writel(0x1b, UART1_REG(LCR));
  254. writel(0x00, UART1_REG(IER));
  255. writel(0x07, UART1_REG(FCR));
  256. writel(0x00, UART1_REG(MCR));
  257. /* Send the commands to shutdown the Kurobox Pro */
  258. kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
  259. kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
  260. kurobox_pro_miconsend(poweroff, sizeof(poweroff));
  261. }
  262. /*****************************************************************************
  263. * General Setup
  264. ****************************************************************************/
  265. static unsigned int kurobox_pro_mpp_modes[] __initdata = {
  266. MPP0_UNUSED,
  267. MPP1_UNUSED,
  268. MPP2_GPIO, /* GPIO Micon */
  269. MPP3_GPIO, /* GPIO Rtc */
  270. MPP4_UNUSED,
  271. MPP5_UNUSED,
  272. MPP6_NAND, /* NAND Flash REn */
  273. MPP7_NAND, /* NAND Flash WEn */
  274. MPP8_UNUSED,
  275. MPP9_UNUSED,
  276. MPP10_UNUSED,
  277. MPP11_UNUSED,
  278. MPP12_SATA_LED, /* SATA 0 presence */
  279. MPP13_SATA_LED, /* SATA 1 presence */
  280. MPP14_SATA_LED, /* SATA 0 active */
  281. MPP15_SATA_LED, /* SATA 1 active */
  282. MPP16_UART, /* UART1 RXD */
  283. MPP17_UART, /* UART1 TXD */
  284. MPP18_UART, /* UART1 CTSn */
  285. MPP19_UART, /* UART1 RTSn */
  286. 0,
  287. };
  288. static void __init kurobox_pro_init(void)
  289. {
  290. /*
  291. * Setup basic Orion functions. Need to be called early.
  292. */
  293. orion5x_init();
  294. orion5x_mpp_conf(kurobox_pro_mpp_modes);
  295. /*
  296. * Configure peripherals.
  297. */
  298. orion5x_ehci0_init();
  299. orion5x_ehci1_init();
  300. orion5x_eth_init(&kurobox_pro_eth_data);
  301. orion5x_i2c_init();
  302. orion5x_sata_init(&kurobox_pro_sata_data);
  303. orion5x_uart0_init();
  304. orion5x_uart1_init();
  305. orion5x_xor_init();
  306. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  307. ORION_MBUS_DEVBUS_BOOT_ATTR,
  308. KUROBOX_PRO_NOR_BOOT_BASE,
  309. KUROBOX_PRO_NOR_BOOT_SIZE);
  310. platform_device_register(&kurobox_pro_nor_flash);
  311. if (machine_is_kurobox_pro()) {
  312. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_TARGET(0),
  313. ORION_MBUS_DEVBUS_ATTR(0),
  314. KUROBOX_PRO_NAND_BASE,
  315. KUROBOX_PRO_NAND_SIZE);
  316. platform_device_register(&kurobox_pro_nand_flash);
  317. }
  318. i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
  319. /* register Kurobox Pro specific power-off method */
  320. pm_power_off = kurobox_pro_power_off;
  321. }
  322. #ifdef CONFIG_MACH_KUROBOX_PRO
  323. MACHINE_START(KUROBOX_PRO, "Buffalo/Revogear Kurobox Pro")
  324. /* Maintainer: Ronen Shitrit <rshitrit@marvell.com> */
  325. .atag_offset = 0x100,
  326. .nr_irqs = ORION5X_NR_IRQS,
  327. .init_machine = kurobox_pro_init,
  328. .map_io = orion5x_map_io,
  329. .init_early = orion5x_init_early,
  330. .init_irq = orion5x_init_irq,
  331. .init_time = orion5x_timer_init,
  332. .fixup = tag_fixup_mem32,
  333. .restart = orion5x_restart,
  334. MACHINE_END
  335. #endif
  336. #ifdef CONFIG_MACH_LINKSTATION_PRO
  337. MACHINE_START(LINKSTATION_PRO, "Buffalo Linkstation Pro/Live")
  338. /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
  339. .atag_offset = 0x100,
  340. .nr_irqs = ORION5X_NR_IRQS,
  341. .init_machine = kurobox_pro_init,
  342. .map_io = orion5x_map_io,
  343. .init_early = orion5x_init_early,
  344. .init_irq = orion5x_init_irq,
  345. .init_time = orion5x_timer_init,
  346. .fixup = tag_fixup_mem32,
  347. .restart = orion5x_restart,
  348. MACHINE_END
  349. #endif