qong.c 7.0 KB

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