cpu-8815.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright STMicroelectronics, 2007.
  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/device.h>
  21. #include <linux/amba/bus.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/io.h>
  24. #include <linux/slab.h>
  25. #include <linux/irq.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/irqchip.h>
  28. #include <linux/platform_data/clk-nomadik.h>
  29. #include <linux/platform_data/pinctrl-nomadik.h>
  30. #include <linux/pinctrl/machine.h>
  31. #include <linux/platform_data/clocksource-nomadik-mtu.h>
  32. #include <linux/of_irq.h>
  33. #include <linux/of_gpio.h>
  34. #include <linux/of_address.h>
  35. #include <linux/of_platform.h>
  36. #include <linux/mtd/fsmc.h>
  37. #include <linux/gpio.h>
  38. #include <linux/amba/mmci.h>
  39. #include <mach/hardware.h>
  40. #include <mach/irqs.h>
  41. #include <asm/mach/arch.h>
  42. #include <asm/mach/map.h>
  43. #include <asm/mach/time.h>
  44. #include <asm/mach-types.h>
  45. #include <asm/cacheflush.h>
  46. #include <asm/hardware/cache-l2x0.h>
  47. static unsigned long out_low[] = { PIN_OUTPUT_LOW };
  48. static unsigned long out_high[] = { PIN_OUTPUT_HIGH };
  49. static unsigned long in_nopull[] = { PIN_INPUT_NOPULL };
  50. static unsigned long in_pullup[] = { PIN_INPUT_PULLUP };
  51. static struct pinctrl_map __initdata nhk8815_pinmap[] = {
  52. PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"),
  53. PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"),
  54. /* Hog in MMC/SD card mux */
  55. PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"),
  56. /* MCCLK */
  57. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low),
  58. /* MCCMD */
  59. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup),
  60. /* MCCMDDIR */
  61. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high),
  62. /* MCDAT3-0 */
  63. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup),
  64. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup),
  65. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup),
  66. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup),
  67. /* MCDAT0DIR */
  68. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high),
  69. /* MCDAT31DIR */
  70. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high),
  71. /* MCMSFBCLK */
  72. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup),
  73. /* CD input GPIO */
  74. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull),
  75. /* CD bias drive */
  76. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low),
  77. /* I2C0 */
  78. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup),
  79. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup),
  80. /* I2C1 */
  81. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup),
  82. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup),
  83. /* I2C2 */
  84. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup),
  85. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup),
  86. };
  87. /* All SoC devices live in the same area (see hardware.h) */
  88. static struct map_desc nomadik_io_desc[] __initdata = {
  89. {
  90. .virtual = NOMADIK_IO_VIRTUAL,
  91. .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL),
  92. .length = NOMADIK_IO_SIZE,
  93. .type = MT_DEVICE,
  94. }
  95. /* static ram and secured ram may be added later */
  96. };
  97. static void __init cpu8815_map_io(void)
  98. {
  99. iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
  100. }
  101. static void cpu8815_restart(char mode, const char *cmd)
  102. {
  103. void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
  104. /* FIXME: use egpio when implemented */
  105. /* Write anything to Reset status register */
  106. writel(1, src_rstsr);
  107. }
  108. /* Initial value for SRC control register: all timers use MXTAL/8 source */
  109. #define SRC_CR_INIT_MASK 0x00007fff
  110. #define SRC_CR_INIT_VAL 0x2aaa8000
  111. static void __init cpu8815_timer_init_of(void)
  112. {
  113. struct device_node *mtu;
  114. void __iomem *base;
  115. int irq;
  116. u32 src_cr;
  117. /* We need this to be up now */
  118. nomadik_clk_init();
  119. mtu = of_find_node_by_path("/mtu0");
  120. if (!mtu)
  121. return;
  122. base = of_iomap(mtu, 0);
  123. if (WARN_ON(!base))
  124. return;
  125. irq = irq_of_parse_and_map(mtu, 0);
  126. pr_info("Remapped MTU @ %p, irq: %d\n", base, irq);
  127. /* Configure timer sources in "system reset controller" ctrl reg */
  128. src_cr = readl(base);
  129. src_cr &= SRC_CR_INIT_MASK;
  130. src_cr |= SRC_CR_INIT_VAL;
  131. writel(src_cr, base);
  132. nmdk_timer_init(base, irq);
  133. }
  134. static struct fsmc_nand_timings cpu8815_nand_timings = {
  135. .thiz = 0,
  136. .thold = 0x10,
  137. .twait = 0x0A,
  138. .tset = 0,
  139. };
  140. static struct fsmc_nand_platform_data cpu8815_nand_data = {
  141. .nand_timings = &cpu8815_nand_timings,
  142. };
  143. /*
  144. * The SMSC911x IRQ is connected to a GPIO pin, but the driver expects
  145. * to simply request an IRQ passed as a resource. So the GPIO pin needs
  146. * to be requested by this hog and set as input.
  147. */
  148. static int __init cpu8815_eth_init(void)
  149. {
  150. struct device_node *eth;
  151. int gpio, irq, err;
  152. eth = of_find_node_by_path("/usb-s8815/ethernet-gpio");
  153. if (!eth) {
  154. pr_info("could not find any ethernet GPIO\n");
  155. return 0;
  156. }
  157. gpio = of_get_gpio(eth, 0);
  158. err = gpio_request(gpio, "eth_irq");
  159. if (err) {
  160. pr_info("failed to request ethernet GPIO\n");
  161. return -ENODEV;
  162. }
  163. err = gpio_direction_input(gpio);
  164. if (err) {
  165. pr_info("failed to set ethernet GPIO as input\n");
  166. return -ENODEV;
  167. }
  168. irq = gpio_to_irq(gpio);
  169. pr_info("enabled USB-S8815 ethernet GPIO %d, IRQ %d\n", gpio, irq);
  170. return 0;
  171. }
  172. device_initcall(cpu8815_eth_init);
  173. /*
  174. * TODO:
  175. * cannot be set from device tree, convert to a proper DT
  176. * binding.
  177. */
  178. static struct mmci_platform_data mmcsd_plat_data = {
  179. .ocr_mask = MMC_VDD_29_30,
  180. };
  181. /*
  182. * This GPIO pin turns on a line that is used to detect card insertion
  183. * on this board.
  184. */
  185. static int __init cpu8815_mmcsd_init(void)
  186. {
  187. struct device_node *cdbias;
  188. int gpio, err;
  189. cdbias = of_find_node_by_path("/usb-s8815/mmcsd-gpio");
  190. if (!cdbias) {
  191. pr_info("could not find MMC/SD card detect bias node\n");
  192. return 0;
  193. }
  194. gpio = of_get_gpio(cdbias, 0);
  195. if (gpio < 0) {
  196. pr_info("could not obtain MMC/SD card detect bias GPIO\n");
  197. return 0;
  198. }
  199. err = gpio_request(gpio, "card detect bias");
  200. if (err) {
  201. pr_info("failed to request card detect bias GPIO %d\n", gpio);
  202. return -ENODEV;
  203. }
  204. err = gpio_direction_output(gpio, 0);
  205. if (err){
  206. pr_info("failed to set GPIO %d as output, low\n", gpio);
  207. return err;
  208. }
  209. pr_info("enabled USB-S8815 CD bias GPIO %d, low\n", gpio);
  210. return 0;
  211. }
  212. device_initcall(cpu8815_mmcsd_init);
  213. /* These are mostly to get the right device names for the clock lookups */
  214. static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = {
  215. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO0_BASE,
  216. "gpio.0", NULL),
  217. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO1_BASE,
  218. "gpio.1", NULL),
  219. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO2_BASE,
  220. "gpio.2", NULL),
  221. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO3_BASE,
  222. "gpio.3", NULL),
  223. OF_DEV_AUXDATA("stericsson,nmk-pinctrl-stn8815", 0,
  224. "pinctrl-stn8815", NULL),
  225. OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE,
  226. "uart0", NULL),
  227. OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE,
  228. "uart1", NULL),
  229. OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE,
  230. "rng", NULL),
  231. OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE,
  232. "rtc-pl031", NULL),
  233. OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE,
  234. "fsmc-nand", &cpu8815_nand_data),
  235. OF_DEV_AUXDATA("arm,primecell", NOMADIK_SDI_BASE,
  236. "mmci", &mmcsd_plat_data),
  237. { /* sentinel */ },
  238. };
  239. static void __init cpu8815_init_of(void)
  240. {
  241. #ifdef CONFIG_CACHE_L2X0
  242. /* At full speed latency must be >=2, so 0x249 in low bits */
  243. l2x0_of_init(0x00730249, 0xfe000fff);
  244. #endif
  245. pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
  246. of_platform_populate(NULL, of_default_bus_match_table,
  247. cpu8815_auxdata_lookup, NULL);
  248. }
  249. static const char * cpu8815_board_compat[] = {
  250. "calaosystems,usb-s8815",
  251. NULL,
  252. };
  253. DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815")
  254. .map_io = cpu8815_map_io,
  255. .init_irq = irqchip_init,
  256. .init_time = cpu8815_timer_init_of,
  257. .init_machine = cpu8815_init_of,
  258. .restart = cpu8815_restart,
  259. .dt_compat = cpu8815_board_compat,
  260. MACHINE_END