mach-qong.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 <mach/hardware.h>
  23. #include <mach/irqs.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/time.h>
  27. #include <asm/mach/map.h>
  28. #include <mach/common.h>
  29. #include <asm/page.h>
  30. #include <asm/setup.h>
  31. #include <mach/iomux-mx3.h>
  32. #include "devices-imx31.h"
  33. #include "devices.h"
  34. /* FPGA defines */
  35. #define QONG_FPGA_VERSION(major, minor, rev) \
  36. (((major & 0xF) << 12) | ((minor & 0xF) << 8) | (rev & 0xFF))
  37. #define QONG_FPGA_BASEADDR MX31_CS1_BASE_ADDR
  38. #define QONG_FPGA_PERIPH_SIZE (1 << 24)
  39. #define QONG_FPGA_CTRL_BASEADDR QONG_FPGA_BASEADDR
  40. #define QONG_FPGA_CTRL_SIZE 0x10
  41. /* FPGA control registers */
  42. #define QONG_FPGA_CTRL_VERSION 0x00
  43. #define QONG_DNET_ID 1
  44. #define QONG_DNET_BASEADDR \
  45. (QONG_FPGA_BASEADDR + QONG_DNET_ID * QONG_FPGA_PERIPH_SIZE)
  46. #define QONG_DNET_SIZE 0x00001000
  47. #define QONG_FPGA_IRQ IOMUX_TO_IRQ(MX31_PIN_DTR_DCE1)
  48. /*
  49. * This file contains the board-specific initialization routines.
  50. */
  51. static const struct imxuart_platform_data uart_pdata __initconst = {
  52. .flags = IMXUART_HAVE_RTSCTS,
  53. };
  54. static int uart_pins[] = {
  55. MX31_PIN_CTS1__CTS1,
  56. MX31_PIN_RTS1__RTS1,
  57. MX31_PIN_TXD1__TXD1,
  58. MX31_PIN_RXD1__RXD1
  59. };
  60. static inline void __init mxc_init_imx_uart(void)
  61. {
  62. mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins),
  63. "uart-0");
  64. imx31_add_imx_uart0(&uart_pdata);
  65. }
  66. static struct resource dnet_resources[] = {
  67. {
  68. .name = "dnet-memory",
  69. .start = QONG_DNET_BASEADDR,
  70. .end = QONG_DNET_BASEADDR + QONG_DNET_SIZE - 1,
  71. .flags = IORESOURCE_MEM,
  72. }, {
  73. .start = QONG_FPGA_IRQ,
  74. .end = QONG_FPGA_IRQ,
  75. .flags = IORESOURCE_IRQ,
  76. },
  77. };
  78. static struct platform_device dnet_device = {
  79. .name = "dnet",
  80. .id = -1,
  81. .num_resources = ARRAY_SIZE(dnet_resources),
  82. .resource = dnet_resources,
  83. };
  84. static int __init qong_init_dnet(void)
  85. {
  86. int ret;
  87. ret = platform_device_register(&dnet_device);
  88. return ret;
  89. }
  90. /* MTD NOR flash */
  91. static struct physmap_flash_data qong_flash_data = {
  92. .width = 2,
  93. };
  94. static struct resource qong_flash_resource = {
  95. .start = MX31_CS0_BASE_ADDR,
  96. .end = MX31_CS0_BASE_ADDR + SZ_128M - 1,
  97. .flags = IORESOURCE_MEM,
  98. };
  99. static struct platform_device qong_nor_mtd_device = {
  100. .name = "physmap-flash",
  101. .id = 0,
  102. .dev = {
  103. .platform_data = &qong_flash_data,
  104. },
  105. .resource = &qong_flash_resource,
  106. .num_resources = 1,
  107. };
  108. static void qong_init_nor_mtd(void)
  109. {
  110. (void)platform_device_register(&qong_nor_mtd_device);
  111. }
  112. /*
  113. * Hardware specific access to control-lines
  114. */
  115. static void qong_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  116. {
  117. struct nand_chip *nand_chip = mtd->priv;
  118. if (cmd == NAND_CMD_NONE)
  119. return;
  120. if (ctrl & NAND_CLE)
  121. writeb(cmd, nand_chip->IO_ADDR_W + (1 << 24));
  122. else
  123. writeb(cmd, nand_chip->IO_ADDR_W + (1 << 23));
  124. }
  125. /*
  126. * Read the Device Ready pin.
  127. */
  128. static int qong_nand_device_ready(struct mtd_info *mtd)
  129. {
  130. return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_NFRB));
  131. }
  132. static void qong_nand_select_chip(struct mtd_info *mtd, int chip)
  133. {
  134. if (chip >= 0)
  135. gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
  136. else
  137. gpio_set_value(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 1);
  138. }
  139. static struct platform_nand_data qong_nand_data = {
  140. .chip = {
  141. .nr_chips = 1,
  142. .chip_delay = 20,
  143. .options = 0,
  144. },
  145. .ctrl = {
  146. .cmd_ctrl = qong_nand_cmd_ctrl,
  147. .dev_ready = qong_nand_device_ready,
  148. .select_chip = qong_nand_select_chip,
  149. }
  150. };
  151. static struct resource qong_nand_resource = {
  152. .start = MX31_CS3_BASE_ADDR,
  153. .end = MX31_CS3_BASE_ADDR + SZ_32M - 1,
  154. .flags = IORESOURCE_MEM,
  155. };
  156. static struct platform_device qong_nand_device = {
  157. .name = "gen_nand",
  158. .id = -1,
  159. .dev = {
  160. .platform_data = &qong_nand_data,
  161. },
  162. .num_resources = 1,
  163. .resource = &qong_nand_resource,
  164. };
  165. static void __init qong_init_nand_mtd(void)
  166. {
  167. /* init CS */
  168. mx31_setup_weimcs(3, 0x00004f00, 0x20013b31, 0x00020800);
  169. mxc_iomux_set_gpr(MUX_SDCTL_CSD1_SEL, true);
  170. /* enable pin */
  171. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFCE_B, IOMUX_CONFIG_GPIO));
  172. if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), "nand_enable"))
  173. gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_NFCE_B), 0);
  174. /* ready/busy pin */
  175. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFRB, IOMUX_CONFIG_GPIO));
  176. if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFRB), "nand_rdy"))
  177. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFRB));
  178. /* write protect pin */
  179. mxc_iomux_mode(IOMUX_MODE(MX31_PIN_NFWP_B, IOMUX_CONFIG_GPIO));
  180. if (!gpio_request(IOMUX_TO_GPIO(MX31_PIN_NFWP_B), "nand_wp"))
  181. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_NFWP_B));
  182. platform_device_register(&qong_nand_device);
  183. }
  184. static void __init qong_init_fpga(void)
  185. {
  186. void __iomem *regs;
  187. u32 fpga_ver;
  188. regs = ioremap(QONG_FPGA_CTRL_BASEADDR, QONG_FPGA_CTRL_SIZE);
  189. if (!regs) {
  190. printk(KERN_ERR "%s: failed to map registers, aborting.\n",
  191. __func__);
  192. return;
  193. }
  194. fpga_ver = readl(regs + QONG_FPGA_CTRL_VERSION);
  195. iounmap(regs);
  196. printk(KERN_INFO "Qong FPGA version %d.%d.%d\n",
  197. (fpga_ver & 0xF000) >> 12,
  198. (fpga_ver & 0x0F00) >> 8, fpga_ver & 0x00FF);
  199. if (fpga_ver < QONG_FPGA_VERSION(0, 8, 7)) {
  200. printk(KERN_ERR "qong: Unexpected FPGA version, FPGA-based "
  201. "devices won't be registered!\n");
  202. return;
  203. }
  204. /* register FPGA-based devices */
  205. qong_init_nand_mtd();
  206. qong_init_dnet();
  207. }
  208. /*
  209. * Board specific initialization.
  210. */
  211. static void __init mxc_board_init(void)
  212. {
  213. mxc_init_imx_uart();
  214. qong_init_nor_mtd();
  215. qong_init_fpga();
  216. }
  217. static void __init qong_timer_init(void)
  218. {
  219. mx31_clocks_init(26000000);
  220. }
  221. static struct sys_timer qong_timer = {
  222. .init = qong_timer_init,
  223. };
  224. /*
  225. * The following uses standard kernel macros defined in arch.h in order to
  226. * initialize __mach_desc_QONG data structure.
  227. */
  228. MACHINE_START(QONG, "Dave/DENX QongEVB-LITE")
  229. /* Maintainer: DENX Software Engineering GmbH */
  230. .phys_io = MX31_AIPS1_BASE_ADDR,
  231. .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
  232. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  233. .map_io = mx31_map_io,
  234. .init_irq = mx31_init_irq,
  235. .init_machine = mxc_board_init,
  236. .timer = &qong_timer,
  237. MACHINE_END