mach-qong.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Copyright (C) 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/types.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/memory.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/mtd/physmap.h>
  20. #include <linux/mtd/nand.h>
  21. #include <linux/gpio.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/time.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/page.h>
  27. #include <asm/setup.h>
  28. #include "common.h"
  29. #include "devices-imx31.h"
  30. #include "hardware.h"
  31. #include "iomux-mx3.h"
  32. /* FPGA defines */
  33. #define QONG_FPGA_VERSION(major, minor, rev) \
  34. (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF))
  35. #define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR
  36. #define QONG_FPGA_PERIPH_SIZE (1 << 24)
  37. #define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR
  38. #define QONG_FPGA_CTRL_SIZE 0x10
  39. /* FPGA control registers */
  40. #define QONG_FPGA_CTRL_VERSION 0x00
  41. #define QONG_DNET_ID 1
  42. #define QONG_DNET_BASEADDR \
  43. (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE)
  44. #define QONG_DNET_SIZE 0x00001000
  45. static const struct imxuart_platform_data uart_pdata __initconst = {
  46. .flags = IMXUART_HAVE_RTSCTS,
  47. };
  48. static int uart_pins[] = {
  49. MX31_PIN_CTS1__CTS1,
  50. MX31_PIN_RTS1__RTS1,
  51. MX31_PIN_TXD1__TXD1,
  52. MX31_PIN_RXD1__RXD1
  53. };
  54. static inline void __init mxc_init_imx_uart(void)
  55. {
  56. mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins),
  57. "uart-0");
  58. imx31_add_imx_uart0(&uart_pdata);
  59. }
  60. static struct resource dnet_resources[] = {
  61. {
  62. .name = "dnet-memory",
  63. .start = QONG_DNET_BASEADDR,
  64. .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1,
  65. .flags = IORESOURCE_MEM,
  66. }, {
  67. /* irq number is run-time assigned */
  68. .flags = IORESOURCE_IRQ,
  69. },
  70. };
  71. static struct platform_device dnet_device = {
  72. .name = "dnet",
  73. .id = -1,
  74. .num_resources = ARRAY_SIZE(dnet_resources),
  75. .resource = dnet_resources,
  76. };
  77. static int __init qong_init_dnet(void)
  78. {
  79. int ret;
  80. dnet_resources[1].start =
  81. gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1));
  82. dnet_resources[1].end =
  83. gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_DTR_DCE1));
  84. ret = platform_device_register(&dnet_device);
  85. return ret;
  86. }
  87. /* MTD NOR flash */
  88. static struct physmap_flash_data qong_flash_data = {
  89. .width = 2,
  90. };
  91. static struct resource qong_flash_resource = {
  92. .start = MX31_CS0_BASE_ADDR,
  93. .end = MX31_CS0_BASE_ADDR + SZ_128M - 1,
  94. .flags = IORESOURCE_MEM,
  95. };
  96. static struct platform_device qong_nor_mtd_device = {
  97. .name = "physmap-flash",
  98. .id = 0,
  99. .dev = {
  100. .platform_data = &qong_flash_data,
  101. },
  102. .resource = &qong_flash_resource,
  103. .num_resources = 1,
  104. };
  105. static void qong_init_nor_mtd(void)
  106. {
  107. (void)platform_device_register(&qong_nor_mtd_device);
  108. }
  109. /*
  110. * Hardware specific access to control-lines
  111. */
  112. static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  113. {
  114. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  115. if (cmd == NAND_CMD_NONE)
  116. return;
  117. if (ctrl & NAND_CLE)
  118. writeb(cmd, nand_chip->IO_ADDR_W + (1 << 24));
  119. else
  120. writeb(cmd, nand_chip->IO_ADDR_W + (1 << 23));
  121. }
  122. /*
  123. * Read the Device Ready pin.
  124. */
  125. static int qong_nand_device_ready(struct mtd_info *mtd)
  126. {
  127. return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB));
  128. }
  129. static void qong_nand_select_chip(struct mtd_info *mtd, int chip)
  130. {
  131. if (chip >= 0)
  132. gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
  133. else
  134. gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1);
  135. }
  136. static struct platform_nand_data qong_nand_data = {
  137. .chip = {
  138. .nr_chips = 1,
  139. .chip_delay = 20,
  140. .options = 0,
  141. },
  142. .ctrl = {
  143. .cmd_ctrl = qong_nand_cmd_ctrl,
  144. .dev_ready = qong_nand_device_ready,
  145. .select_chip = qong_nand_select_chip,
  146. }
  147. };
  148. static struct resource qong_nand_resource = {
  149. .start = MX31_CS3_BASE_ADDR,
  150. .end = MX31_CS3_BASE_ADDR + SZ_32M - 1,
  151. .flags = IORESOURCE_MEM,
  152. };
  153. static struct platform_device qong_nand_device = {
  154. .name = "gen_nand",
  155. .id = -1,
  156. .dev = {
  157. .platform_data = &qong_nand_data,
  158. },
  159. .num_resources = 1,
  160. .resource = &qong_nand_resource,
  161. };
  162. static void __init qong_init_nand_mtd(void)
  163. {
  164. /* init CS */
  165. imx_writel(0x00004f00, MX31_IO_ADDRESS(MX31_WEIM_CSCRxU(3)));
  166. imx_writel(0x20013b31, MX31_IO_ADDRESS(MX31_WEIM_CSCRxL(3)));
  167. imx_writel(0x00020800, MX31_IO_ADDRESS(MX31_WEIM_CSCRxA(3)));
  168. mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true);
  169. /* enable pin */
  170. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B, IOMUX_CONFIG_GPIO));
  171. if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), "nand_enable"))
  172. gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
  173. /* ready/busy pin */
  174. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB, IOMUX_CONFIG_GPIO));
  175. if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB), "nand_rdy"))
  176. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB));
  177. /* write protect pin */
  178. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B, IOMUX_CONFIG_GPIO));
  179. if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B), "nand_wp"))
  180. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B));
  181. platform_device_register(&qong_nand_device);
  182. }
  183. static void __init qong_init_fpga(void)
  184. {
  185. void __iomem *regs;
  186. u32 fpga_ver;
  187. regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE);
  188. if (!regs) {
  189. printk(KERN_ERR "%s: failed to map registers, aborting.\n",
  190. __func__);
  191. return;
  192. }
  193. fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION);
  194. iounmap(regs);
  195. printk(KERN_INFO "Qong FPGA version %d.%d.%d\n",
  196. (fpga_ver & 0xF000) >> 12,
  197. (fpga_ver & 0x0F00) >> 8, fpga_ver & 0x00FF);
  198. if (fpga_ver < QONG_FPGA_VERSION(0, 8, 7)) {
  199. printk(KERN_ERR "qong: Unexpected FPGA version, FPGA-based "
  200. "devices won't be registered!\n");
  201. return;
  202. }
  203. /* register FPGA-based devices */
  204. qong_init_nand_mtd();
  205. qong_init_dnet();
  206. }
  207. /*
  208. * Board specific initialization.
  209. */
  210. static void __init qong_init(void)
  211. {
  212. imx31_soc_init();
  213. mxc_init_imx_uart();
  214. qong_init_nor_mtd();
  215. imx31_add_imx2_wdt();
  216. }
  217. static void __init qong_timer_init(void)
  218. {
  219. mx31_clocks_init(26000000);
  220. }
  221. MACHINE_START(QONG, "Dave/DENX QongEVB-LITE")
  222. /* Maintainer: DENX Software Engineering GmbH */
  223. .atag_offset = 0x100,
  224. .map_io = mx31_map_io,
  225. .init_early = imx31_init_early,
  226. .init_irq = mx31_init_irq,
  227. .init_time = qong_timer_init,
  228. .init_machine = qong_init,
  229. .init_late = qong_init_fpga,
  230. .restart = mxc_restart,
  231. MACHINE_END