kurobox_pro-setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/pci.h>
  14. #include <linux/irq.h>
  15. #include <linux/delay.h>
  16. #include <linux/mtd/physmap.h>
  17. #include <linux/mtd/nand.h>
  18. #include <linux/mv643xx_eth.h>
  19. #include <linux/i2c.h>
  20. #include <linux/serial_reg.h>
  21. #include <linux/ata_platform.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/gpio.h>
  24. #include <asm/mach/arch.h>
  25. #include <asm/mach/pci.h>
  26. #include <asm/arch/orion5x.h>
  27. #include <asm/plat-orion/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(struct pci_dev *dev, u8 slot, u8 pin)
  106. {
  107. int irq;
  108. /*
  109. * Check for devices with hard-wired IRQs.
  110. */
  111. irq = orion5x_pci_map_irq(dev, slot, pin);
  112. if (irq != -1)
  113. return irq;
  114. /*
  115. * PCI isn't used on the Kuro
  116. */
  117. return -1;
  118. }
  119. static struct hw_pci kurobox_pro_pci __initdata = {
  120. .nr_controllers = 2,
  121. .swizzle = pci_std_swizzle,
  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. pci_common_init(&kurobox_pro_pci);
  130. return 0;
  131. }
  132. subsys_initcall(kurobox_pro_pci_init);
  133. /*****************************************************************************
  134. * Ethernet
  135. ****************************************************************************/
  136. static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
  137. .phy_addr = 8,
  138. };
  139. /*****************************************************************************
  140. * RTC 5C372a on I2C bus
  141. ****************************************************************************/
  142. static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
  143. I2C_BOARD_INFO("rs5c372a", 0x32),
  144. };
  145. /*****************************************************************************
  146. * SATA
  147. ****************************************************************************/
  148. static struct mv_sata_platform_data kurobox_pro_sata_data = {
  149. .n_ports = 2,
  150. };
  151. /*****************************************************************************
  152. * Kurobox Pro specific power off method via UART1-attached microcontroller
  153. ****************************************************************************/
  154. #define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
  155. static int kurobox_pro_miconread(unsigned char *buf, int count)
  156. {
  157. int i;
  158. int timeout;
  159. for (i = 0; i < count; i++) {
  160. timeout = 10;
  161. while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
  162. if (--timeout == 0)
  163. break;
  164. udelay(1000);
  165. }
  166. if (timeout == 0)
  167. break;
  168. buf[i] = readl(UART1_REG(RX));
  169. }
  170. /* return read bytes */
  171. return i;
  172. }
  173. static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
  174. {
  175. int i = 0;
  176. while (count--) {
  177. while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
  178. barrier();
  179. writel(buf[i++], UART1_REG(TX));
  180. }
  181. return 0;
  182. }
  183. static int kurobox_pro_miconsend(const unsigned char *data, int count)
  184. {
  185. int i;
  186. unsigned char checksum = 0;
  187. unsigned char recv_buf[40];
  188. unsigned char send_buf[40];
  189. unsigned char correct_ack[3];
  190. int retry = 2;
  191. /* Generate checksum */
  192. for (i = 0; i < count; i++)
  193. checksum -= data[i];
  194. do {
  195. /* Send data */
  196. kurobox_pro_miconwrite(data, count);
  197. /* send checksum */
  198. kurobox_pro_miconwrite(&checksum, 1);
  199. if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
  200. printk(KERN_ERR ">%s: receive failed.\n", __func__);
  201. /* send preamble to clear the receive buffer */
  202. memset(&send_buf, 0xff, sizeof(send_buf));
  203. kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
  204. /* make dummy reads */
  205. mdelay(100);
  206. kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
  207. } else {
  208. /* Generate expected ack */
  209. correct_ack[0] = 0x01;
  210. correct_ack[1] = data[1];
  211. correct_ack[2] = 0x00;
  212. /* checksum Check */
  213. if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
  214. recv_buf[3]) & 0xFF) {
  215. printk(KERN_ERR ">%s: Checksum Error : "
  216. "Received data[%02x, %02x, %02x, %02x]"
  217. "\n", __func__, recv_buf[0],
  218. recv_buf[1], recv_buf[2], recv_buf[3]);
  219. } else {
  220. /* Check Received Data */
  221. if (correct_ack[0] == recv_buf[0] &&
  222. correct_ack[1] == recv_buf[1] &&
  223. correct_ack[2] == recv_buf[2]) {
  224. /* Interval for next command */
  225. mdelay(10);
  226. /* Receive ACK */
  227. return 0;
  228. }
  229. }
  230. /* Received NAK or illegal Data */
  231. printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
  232. "Received\n", __func__);
  233. }
  234. } while (retry--);
  235. /* Interval for next command */
  236. mdelay(10);
  237. return -1;
  238. }
  239. static void kurobox_pro_power_off(void)
  240. {
  241. const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
  242. const unsigned char shutdownwait[] = {0x00, 0x0c};
  243. const unsigned char poweroff[] = {0x00, 0x06};
  244. /* 38400 baud divisor */
  245. const unsigned divisor = ((ORION5X_TCLK + (8 * 38400)) / (16 * 38400));
  246. pr_info("%s: triggering power-off...\n", __func__);
  247. /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
  248. writel(0x83, UART1_REG(LCR));
  249. writel(divisor & 0xff, UART1_REG(DLL));
  250. writel((divisor >> 8) & 0xff, UART1_REG(DLM));
  251. writel(0x1b, UART1_REG(LCR));
  252. writel(0x00, UART1_REG(IER));
  253. writel(0x07, UART1_REG(FCR));
  254. writel(0x00, UART1_REG(MCR));
  255. /* Send the commands to shutdown the Kurobox Pro */
  256. kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
  257. kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
  258. kurobox_pro_miconsend(poweroff, sizeof(poweroff));
  259. }
  260. /*****************************************************************************
  261. * General Setup
  262. ****************************************************************************/
  263. static struct orion5x_mpp_mode kurobox_pro_mpp_modes[] __initdata = {
  264. { 0, MPP_UNUSED },
  265. { 1, MPP_UNUSED },
  266. { 2, MPP_GPIO }, /* GPIO Micon */
  267. { 3, MPP_GPIO }, /* GPIO Rtc */
  268. { 4, MPP_UNUSED },
  269. { 5, MPP_UNUSED },
  270. { 6, MPP_NAND }, /* NAND Flash REn */
  271. { 7, MPP_NAND }, /* NAND Flash WEn */
  272. { 8, MPP_UNUSED },
  273. { 9, MPP_UNUSED },
  274. { 10, MPP_UNUSED },
  275. { 11, MPP_UNUSED },
  276. { 12, MPP_SATA_LED }, /* SATA 0 presence */
  277. { 13, MPP_SATA_LED }, /* SATA 1 presence */
  278. { 14, MPP_SATA_LED }, /* SATA 0 active */
  279. { 15, MPP_SATA_LED }, /* SATA 1 active */
  280. { 16, MPP_UART }, /* UART1 RXD */
  281. { 17, MPP_UART }, /* UART1 TXD */
  282. { 18, MPP_UART }, /* UART1 CTSn */
  283. { 19, MPP_UART }, /* UART1 RTSn */
  284. { -1 },
  285. };
  286. static void __init kurobox_pro_init(void)
  287. {
  288. /*
  289. * Setup basic Orion functions. Need to be called early.
  290. */
  291. orion5x_init();
  292. orion5x_mpp_conf(kurobox_pro_mpp_modes);
  293. /*
  294. * Configure peripherals.
  295. */
  296. orion5x_ehci0_init();
  297. orion5x_ehci1_init();
  298. orion5x_eth_init(&kurobox_pro_eth_data);
  299. orion5x_i2c_init();
  300. orion5x_sata_init(&kurobox_pro_sata_data);
  301. orion5x_uart0_init();
  302. orion5x_uart1_init();
  303. orion5x_setup_dev_boot_win(KUROBOX_PRO_NOR_BOOT_BASE,
  304. KUROBOX_PRO_NOR_BOOT_SIZE);
  305. platform_device_register(&kurobox_pro_nor_flash);
  306. if (machine_is_kurobox_pro()) {
  307. orion5x_setup_dev0_win(KUROBOX_PRO_NAND_BASE,
  308. KUROBOX_PRO_NAND_SIZE);
  309. platform_device_register(&kurobox_pro_nand_flash);
  310. }
  311. i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
  312. /* register Kurobox Pro specific power-off method */
  313. pm_power_off = kurobox_pro_power_off;
  314. }
  315. #ifdef CONFIG_MACH_KUROBOX_PRO
  316. MACHINE_START(KUROBOX_PRO, "Buffalo/Revogear Kurobox Pro")
  317. /* Maintainer: Ronen Shitrit <rshitrit@marvell.com> */
  318. .phys_io = ORION5X_REGS_PHYS_BASE,
  319. .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  320. .boot_params = 0x00000100,
  321. .init_machine = kurobox_pro_init,
  322. .map_io = orion5x_map_io,
  323. .init_irq = orion5x_init_irq,
  324. .timer = &orion5x_timer,
  325. .fixup = tag_fixup_mem32,
  326. MACHINE_END
  327. #endif
  328. #ifdef CONFIG_MACH_LINKSTATION_PRO
  329. MACHINE_START(LINKSTATION_PRO, "Buffalo Linkstation Pro/Live")
  330. /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
  331. .phys_io = ORION5X_REGS_PHYS_BASE,
  332. .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  333. .boot_params = 0x00000100,
  334. .init_machine = kurobox_pro_init,
  335. .map_io = orion5x_map_io,
  336. .init_irq = orion5x_init_irq,
  337. .timer = &orion5x_timer,
  338. .fixup = tag_fixup_mem32,
  339. MACHINE_END
  340. #endif