mach-mx31_3ds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  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/delay.h>
  19. #include <linux/types.h>
  20. #include <linux/init.h>
  21. #include <linux/clk.h>
  22. #include <linux/irq.h>
  23. #include <linux/gpio.h>
  24. #include <linux/smsc911x.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/mfd/mc13783.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/regulator/machine.h>
  29. #include <linux/fsl_devices.h>
  30. #include <linux/input/matrix_keypad.h>
  31. #include <mach/hardware.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/time.h>
  35. #include <asm/memory.h>
  36. #include <asm/mach/map.h>
  37. #include <mach/common.h>
  38. #include <mach/imx-uart.h>
  39. #include <mach/iomux-mx3.h>
  40. #include <mach/mxc_nand.h>
  41. #include <mach/spi.h>
  42. #include "devices.h"
  43. /* Definitions for components on the Debug board */
  44. /* Base address of CPLD controller on the Debug board */
  45. #define DEBUG_BASE_ADDRESS CS5_IO_ADDRESS(MX3x_CS5_BASE_ADDR)
  46. /* LAN9217 ethernet base address */
  47. #define LAN9217_BASE_ADDR MX3x_CS5_BASE_ADDR
  48. /* CPLD config and interrupt base address */
  49. #define CPLD_ADDR (DEBUG_BASE_ADDRESS + 0x20000)
  50. /* status, interrupt */
  51. #define CPLD_INT_STATUS_REG (CPLD_ADDR + 0x10)
  52. #define CPLD_INT_MASK_REG (CPLD_ADDR + 0x38)
  53. #define CPLD_INT_RESET_REG (CPLD_ADDR + 0x20)
  54. /* magic word for debug CPLD */
  55. #define CPLD_MAGIC_NUMBER1_REG (CPLD_ADDR + 0x40)
  56. #define CPLD_MAGIC_NUMBER2_REG (CPLD_ADDR + 0x48)
  57. /* CPLD code version */
  58. #define CPLD_CODE_VER_REG (CPLD_ADDR + 0x50)
  59. /* magic word for debug CPLD */
  60. #define CPLD_MAGIC_NUMBER3_REG (CPLD_ADDR + 0x58)
  61. /* CPLD IRQ line for external uart, external ethernet etc */
  62. #define EXPIO_PARENT_INT IOMUX_TO_IRQ(MX31_PIN_GPIO1_1)
  63. #define MXC_EXP_IO_BASE (MXC_BOARD_IRQ_START)
  64. #define MXC_IRQ_TO_EXPIO(irq) ((irq) - MXC_EXP_IO_BASE)
  65. #define EXPIO_INT_ENET (MXC_EXP_IO_BASE + 0)
  66. #define MXC_MAX_EXP_IO_LINES 16
  67. /*
  68. * This file contains the board-specific initialization routines.
  69. */
  70. static int mx31_3ds_pins[] = {
  71. /* UART1 */
  72. MX31_PIN_CTS1__CTS1,
  73. MX31_PIN_RTS1__RTS1,
  74. MX31_PIN_TXD1__TXD1,
  75. MX31_PIN_RXD1__RXD1,
  76. IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
  77. /* SPI 1 */
  78. MX31_PIN_CSPI2_SCLK__SCLK,
  79. MX31_PIN_CSPI2_MOSI__MOSI,
  80. MX31_PIN_CSPI2_MISO__MISO,
  81. MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
  82. MX31_PIN_CSPI2_SS0__SS0,
  83. MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
  84. /* MC13783 IRQ */
  85. IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
  86. /* USB OTG reset */
  87. IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
  88. /* USB OTG */
  89. MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
  90. MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
  91. MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
  92. MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
  93. MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
  94. MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
  95. MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
  96. MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
  97. MX31_PIN_USBOTG_CLK__USBOTG_CLK,
  98. MX31_PIN_USBOTG_DIR__USBOTG_DIR,
  99. MX31_PIN_USBOTG_NXT__USBOTG_NXT,
  100. MX31_PIN_USBOTG_STP__USBOTG_STP,
  101. /*Keyboard*/
  102. MX31_PIN_KEY_ROW0_KEY_ROW0,
  103. MX31_PIN_KEY_ROW1_KEY_ROW1,
  104. MX31_PIN_KEY_ROW2_KEY_ROW2,
  105. MX31_PIN_KEY_COL0_KEY_COL0,
  106. MX31_PIN_KEY_COL1_KEY_COL1,
  107. MX31_PIN_KEY_COL2_KEY_COL2,
  108. MX31_PIN_KEY_COL3_KEY_COL3,
  109. };
  110. /*
  111. * Matrix keyboard
  112. */
  113. static const uint32_t mx31_3ds_keymap[] = {
  114. KEY(0, 0, KEY_UP),
  115. KEY(0, 1, KEY_DOWN),
  116. KEY(1, 0, KEY_RIGHT),
  117. KEY(1, 1, KEY_LEFT),
  118. KEY(1, 2, KEY_ENTER),
  119. KEY(2, 0, KEY_F6),
  120. KEY(2, 1, KEY_F8),
  121. KEY(2, 2, KEY_F9),
  122. KEY(2, 3, KEY_F10),
  123. };
  124. static struct matrix_keymap_data mx31_3ds_keymap_data = {
  125. .keymap = mx31_3ds_keymap,
  126. .keymap_size = ARRAY_SIZE(mx31_3ds_keymap),
  127. };
  128. /* Regulators */
  129. static struct regulator_init_data pwgtx_init = {
  130. .constraints = {
  131. .boot_on = 1,
  132. .always_on = 1,
  133. },
  134. };
  135. static struct mc13783_regulator_init_data mx31_3ds_regulators[] = {
  136. {
  137. .id = MC13783_REGU_PWGT1SPI, /* Power Gate for ARM core. */
  138. .init_data = &pwgtx_init,
  139. }, {
  140. .id = MC13783_REGU_PWGT2SPI, /* Power Gate for L2 Cache. */
  141. .init_data = &pwgtx_init,
  142. },
  143. };
  144. /* MC13783 */
  145. static struct mc13783_platform_data mc13783_pdata __initdata = {
  146. .regulators = mx31_3ds_regulators,
  147. .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
  148. .flags = MC13783_USE_REGULATOR,
  149. };
  150. /* SPI */
  151. static int spi1_internal_chipselect[] = {
  152. MXC_SPI_CS(0),
  153. MXC_SPI_CS(2),
  154. };
  155. static struct spi_imx_master spi1_pdata = {
  156. .chipselect = spi1_internal_chipselect,
  157. .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
  158. };
  159. static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
  160. {
  161. .modalias = "mc13783",
  162. .max_speed_hz = 1000000,
  163. .bus_num = 1,
  164. .chip_select = 1, /* SS2 */
  165. .platform_data = &mc13783_pdata,
  166. .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
  167. .mode = SPI_CS_HIGH,
  168. },
  169. };
  170. /*
  171. * NAND Flash
  172. */
  173. static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = {
  174. .width = 1,
  175. .hw_ecc = 1,
  176. #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
  177. .flash_bbt = 1,
  178. #endif
  179. };
  180. /*
  181. * USB OTG
  182. */
  183. #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
  184. PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
  185. #define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
  186. static void mx31_3ds_usbotg_init(void)
  187. {
  188. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
  189. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
  190. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
  191. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
  192. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
  193. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
  194. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
  195. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
  196. mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
  197. mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
  198. mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
  199. mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
  200. gpio_request(USBOTG_RST_B, "otgusb-reset");
  201. gpio_direction_output(USBOTG_RST_B, 0);
  202. mdelay(1);
  203. gpio_set_value(USBOTG_RST_B, 1);
  204. }
  205. static struct fsl_usb2_platform_data usbotg_pdata = {
  206. .operating_mode = FSL_USB2_DR_DEVICE,
  207. .phy_mode = FSL_USB2_PHY_ULPI,
  208. };
  209. static struct imxuart_platform_data uart_pdata = {
  210. .flags = IMXUART_HAVE_RTSCTS,
  211. };
  212. /*
  213. * Support for the SMSC9217 on the Debug board.
  214. */
  215. static struct smsc911x_platform_config smsc911x_config = {
  216. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  217. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  218. .flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
  219. .phy_interface = PHY_INTERFACE_MODE_MII,
  220. };
  221. static struct resource smsc911x_resources[] = {
  222. {
  223. .start = LAN9217_BASE_ADDR,
  224. .end = LAN9217_BASE_ADDR + 0xff,
  225. .flags = IORESOURCE_MEM,
  226. }, {
  227. .start = EXPIO_INT_ENET,
  228. .end = EXPIO_INT_ENET,
  229. .flags = IORESOURCE_IRQ,
  230. },
  231. };
  232. static struct platform_device smsc911x_device = {
  233. .name = "smsc911x",
  234. .id = -1,
  235. .num_resources = ARRAY_SIZE(smsc911x_resources),
  236. .resource = smsc911x_resources,
  237. .dev = {
  238. .platform_data = &smsc911x_config,
  239. },
  240. };
  241. /*
  242. * Routines for the CPLD on the debug board. It contains a CPLD handling
  243. * LEDs, switches, interrupts for Ethernet.
  244. */
  245. static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc)
  246. {
  247. uint32_t imr_val;
  248. uint32_t int_valid;
  249. uint32_t expio_irq;
  250. imr_val = __raw_readw(CPLD_INT_MASK_REG);
  251. int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val;
  252. expio_irq = MXC_EXP_IO_BASE;
  253. for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
  254. if ((int_valid & 1) == 0)
  255. continue;
  256. generic_handle_irq(expio_irq);
  257. }
  258. }
  259. /*
  260. * Disable an expio pin's interrupt by setting the bit in the imr.
  261. * @param irq an expio virtual irq number
  262. */
  263. static void expio_mask_irq(uint32_t irq)
  264. {
  265. uint16_t reg;
  266. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  267. /* mask the interrupt */
  268. reg = __raw_readw(CPLD_INT_MASK_REG);
  269. reg |= 1 << expio;
  270. __raw_writew(reg, CPLD_INT_MASK_REG);
  271. }
  272. /*
  273. * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
  274. * @param irq an expanded io virtual irq number
  275. */
  276. static void expio_ack_irq(uint32_t irq)
  277. {
  278. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  279. /* clear the interrupt status */
  280. __raw_writew(1 << expio, CPLD_INT_RESET_REG);
  281. __raw_writew(0, CPLD_INT_RESET_REG);
  282. /* mask the interrupt */
  283. expio_mask_irq(irq);
  284. }
  285. /*
  286. * Enable a expio pin's interrupt by clearing the bit in the imr.
  287. * @param irq a expio virtual irq number
  288. */
  289. static void expio_unmask_irq(uint32_t irq)
  290. {
  291. uint16_t reg;
  292. uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
  293. /* unmask the interrupt */
  294. reg = __raw_readw(CPLD_INT_MASK_REG);
  295. reg &= ~(1 << expio);
  296. __raw_writew(reg, CPLD_INT_MASK_REG);
  297. }
  298. static struct irq_chip expio_irq_chip = {
  299. .ack = expio_ack_irq,
  300. .mask = expio_mask_irq,
  301. .unmask = expio_unmask_irq,
  302. };
  303. static int __init mx31_3ds_init_expio(void)
  304. {
  305. int i;
  306. int ret;
  307. /* Check if there's a debug board connected */
  308. if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) ||
  309. (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) ||
  310. (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) {
  311. /* No Debug board found */
  312. return -ENODEV;
  313. }
  314. pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n",
  315. __raw_readw(CPLD_CODE_VER_REG));
  316. /*
  317. * Configure INT line as GPIO input
  318. */
  319. ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq");
  320. if (ret)
  321. pr_warning("could not get LAN irq gpio\n");
  322. else
  323. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1));
  324. /* Disable the interrupts and clear the status */
  325. __raw_writew(0, CPLD_INT_MASK_REG);
  326. __raw_writew(0xFFFF, CPLD_INT_RESET_REG);
  327. __raw_writew(0, CPLD_INT_RESET_REG);
  328. __raw_writew(0x1F, CPLD_INT_MASK_REG);
  329. for (i = MXC_EXP_IO_BASE;
  330. i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
  331. i++) {
  332. set_irq_chip(i, &expio_irq_chip);
  333. set_irq_handler(i, handle_level_irq);
  334. set_irq_flags(i, IRQF_VALID);
  335. }
  336. set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW);
  337. set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler);
  338. return 0;
  339. }
  340. /*
  341. * This structure defines the MX31 memory map.
  342. */
  343. static struct map_desc mx31_3ds_io_desc[] __initdata = {
  344. {
  345. .virtual = MX31_CS5_BASE_ADDR_VIRT,
  346. .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR),
  347. .length = MX31_CS5_SIZE,
  348. .type = MT_DEVICE,
  349. },
  350. };
  351. /*
  352. * Set up static virtual mappings.
  353. */
  354. static void __init mx31_3ds_map_io(void)
  355. {
  356. mx31_map_io();
  357. iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc));
  358. }
  359. /*!
  360. * Board specific initialization.
  361. */
  362. static void __init mxc_board_init(void)
  363. {
  364. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  365. "mx31_3ds");
  366. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  367. mxc_register_device(&mxc_nand_device, &imx31_3ds_nand_flash_pdata);
  368. mxc_register_device(&mxc_spi_device1, &spi1_pdata);
  369. spi_register_board_info(mx31_3ds_spi_devs,
  370. ARRAY_SIZE(mx31_3ds_spi_devs));
  371. mxc_register_device(&imx_kpp_device, &mx31_3ds_keymap_data);
  372. mx31_3ds_usbotg_init();
  373. mxc_register_device(&mxc_otg_udc_device, &usbotg_pdata);
  374. if (!mx31_3ds_init_expio())
  375. platform_device_register(&smsc911x_device);
  376. }
  377. static void __init mx31_3ds_timer_init(void)
  378. {
  379. mx31_clocks_init(26000000);
  380. }
  381. static struct sys_timer mx31_3ds_timer = {
  382. .init = mx31_3ds_timer_init,
  383. };
  384. /*
  385. * The following uses standard kernel macros defined in arch.h in order to
  386. * initialize __mach_desc_MX31_3DS data structure.
  387. */
  388. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  389. /* Maintainer: Freescale Semiconductor, Inc. */
  390. .phys_io = MX31_AIPS1_BASE_ADDR,
  391. .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
  392. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  393. .map_io = mx31_3ds_map_io,
  394. .init_irq = mx31_init_irq,
  395. .init_machine = mxc_board_init,
  396. .timer = &mx31_3ds_timer,
  397. MACHINE_END