cpu-8815.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. #include "cpu-8815.h"
  48. /* The 8815 has 4 GPIO blocks, let's register them immediately */
  49. static resource_size_t __initdata cpu8815_gpio_base[] = {
  50. NOMADIK_GPIO0_BASE,
  51. NOMADIK_GPIO1_BASE,
  52. NOMADIK_GPIO2_BASE,
  53. NOMADIK_GPIO3_BASE,
  54. };
  55. static struct platform_device *
  56. cpu8815_add_gpio(int id, resource_size_t addr, int irq,
  57. struct nmk_gpio_platform_data *pdata)
  58. {
  59. struct resource resources[] = {
  60. {
  61. .start = addr,
  62. .end = addr + 127,
  63. .flags = IORESOURCE_MEM,
  64. },
  65. {
  66. .start = irq,
  67. .end = irq,
  68. .flags = IORESOURCE_IRQ,
  69. }
  70. };
  71. return platform_device_register_resndata(NULL, "gpio", id,
  72. resources, ARRAY_SIZE(resources),
  73. pdata, sizeof(*pdata));
  74. }
  75. void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
  76. struct nmk_gpio_platform_data *pdata)
  77. {
  78. int first = 0;
  79. int i;
  80. for (i = 0; i < num; i++, first += 32, irq++) {
  81. pdata->first_gpio = first;
  82. pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
  83. pdata->num_gpio = 32;
  84. cpu8815_add_gpio(i, base[i], irq, pdata);
  85. }
  86. }
  87. static unsigned long out_low[] = { PIN_OUTPUT_LOW };
  88. static unsigned long out_high[] = { PIN_OUTPUT_HIGH };
  89. static unsigned long in_nopull[] = { PIN_INPUT_NOPULL };
  90. static unsigned long in_pullup[] = { PIN_INPUT_PULLUP };
  91. static struct pinctrl_map __initdata nhk8815_pinmap[] = {
  92. PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"),
  93. PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"),
  94. /* Hog in MMC/SD card mux */
  95. PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"),
  96. /* MCCLK */
  97. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low),
  98. /* MCCMD */
  99. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup),
  100. /* MCCMDDIR */
  101. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high),
  102. /* MCDAT3-0 */
  103. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup),
  104. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup),
  105. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup),
  106. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup),
  107. /* MCDAT0DIR */
  108. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high),
  109. /* MCDAT31DIR */
  110. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high),
  111. /* MCMSFBCLK */
  112. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup),
  113. /* CD input GPIO */
  114. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull),
  115. /* CD bias drive */
  116. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low),
  117. /* I2C0 */
  118. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup),
  119. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup),
  120. /* I2C1 */
  121. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup),
  122. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup),
  123. /* I2C2 */
  124. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup),
  125. PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup),
  126. };
  127. static inline void
  128. cpu8815_add_pinctrl(struct device *parent, const char *name)
  129. {
  130. struct platform_device_info pdevinfo = {
  131. .parent = parent,
  132. .name = name,
  133. .id = -1,
  134. };
  135. pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
  136. platform_device_register_full(&pdevinfo);
  137. }
  138. static int __init cpu8815_init(void)
  139. {
  140. struct nmk_gpio_platform_data pdata = {
  141. /* No custom data yet */
  142. };
  143. /* For e.g. device tree boots */
  144. if (!machine_is_nomadik())
  145. return 0;
  146. cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
  147. IRQ_GPIO0, &pdata);
  148. cpu8815_add_pinctrl(NULL, "pinctrl-stn8815");
  149. amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0);
  150. amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0);
  151. return 0;
  152. }
  153. arch_initcall(cpu8815_init);
  154. /* All SoC devices live in the same area (see hardware.h) */
  155. static struct map_desc nomadik_io_desc[] __initdata = {
  156. {
  157. .virtual = NOMADIK_IO_VIRTUAL,
  158. .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL),
  159. .length = NOMADIK_IO_SIZE,
  160. .type = MT_DEVICE,
  161. }
  162. /* static ram and secured ram may be added later */
  163. };
  164. void __init cpu8815_map_io(void)
  165. {
  166. iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc));
  167. }
  168. void __init cpu8815_init_irq(void)
  169. {
  170. /* This modified VIC cell has two register blocks, at 0 and 0x20 */
  171. vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0);
  172. vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0);
  173. /*
  174. * Init clocks here so that they are available for system timer
  175. * initialization.
  176. */
  177. nomadik_clk_init();
  178. }
  179. /*
  180. * This function is called from the board init ("init_machine").
  181. */
  182. void __init cpu8815_platform_init(void)
  183. {
  184. #ifdef CONFIG_CACHE_L2X0
  185. /* At full speed latency must be >=2, so 0x249 in low bits */
  186. l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff);
  187. #endif
  188. return;
  189. }
  190. void cpu8815_restart(char mode, const char *cmd)
  191. {
  192. void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18);
  193. /* FIXME: use egpio when implemented */
  194. /* Write anything to Reset status register */
  195. writel(1, src_rstsr);
  196. }
  197. #ifdef CONFIG_OF
  198. /* Initial value for SRC control register: all timers use MXTAL/8 source */
  199. #define SRC_CR_INIT_MASK 0x00007fff
  200. #define SRC_CR_INIT_VAL 0x2aaa8000
  201. static void __init cpu8815_timer_init_of(void)
  202. {
  203. struct device_node *mtu;
  204. void __iomem *base;
  205. int irq;
  206. u32 src_cr;
  207. /* We need this to be up now */
  208. nomadik_clk_init();
  209. mtu = of_find_node_by_path("/mtu0");
  210. if (!mtu)
  211. return;
  212. base = of_iomap(mtu, 0);
  213. if (WARN_ON(!base))
  214. return;
  215. irq = irq_of_parse_and_map(mtu, 0);
  216. pr_info("Remapped MTU @ %p, irq: %d\n", base, irq);
  217. /* Configure timer sources in "system reset controller" ctrl reg */
  218. src_cr = readl(base);
  219. src_cr &= SRC_CR_INIT_MASK;
  220. src_cr |= SRC_CR_INIT_VAL;
  221. writel(src_cr, base);
  222. nmdk_timer_init(base, irq);
  223. }
  224. static struct fsmc_nand_timings cpu8815_nand_timings = {
  225. .thiz = 0,
  226. .thold = 0x10,
  227. .twait = 0x0A,
  228. .tset = 0,
  229. };
  230. static struct fsmc_nand_platform_data cpu8815_nand_data = {
  231. .nand_timings = &cpu8815_nand_timings,
  232. };
  233. /*
  234. * The SMSC911x IRQ is connected to a GPIO pin, but the driver expects
  235. * to simply request an IRQ passed as a resource. So the GPIO pin needs
  236. * to be requested by this hog and set as input.
  237. */
  238. static int __init cpu8815_eth_init(void)
  239. {
  240. struct device_node *eth;
  241. int gpio, irq, err;
  242. eth = of_find_node_by_path("/usb-s8815/ethernet-gpio");
  243. if (!eth) {
  244. pr_info("could not find any ethernet GPIO\n");
  245. return 0;
  246. }
  247. gpio = of_get_gpio(eth, 0);
  248. err = gpio_request(gpio, "eth_irq");
  249. if (err) {
  250. pr_info("failed to request ethernet GPIO\n");
  251. return -ENODEV;
  252. }
  253. err = gpio_direction_input(gpio);
  254. if (err) {
  255. pr_info("failed to set ethernet GPIO as input\n");
  256. return -ENODEV;
  257. }
  258. irq = gpio_to_irq(gpio);
  259. pr_info("enabled USB-S8815 ethernet GPIO %d, IRQ %d\n", gpio, irq);
  260. return 0;
  261. }
  262. device_initcall(cpu8815_eth_init);
  263. /*
  264. * TODO:
  265. * cannot be set from device tree, convert to a proper DT
  266. * binding.
  267. */
  268. static struct mmci_platform_data mmcsd_plat_data = {
  269. .ocr_mask = MMC_VDD_29_30,
  270. };
  271. /*
  272. * This GPIO pin turns on a line that is used to detect card insertion
  273. * on this board.
  274. */
  275. static int __init cpu8815_mmcsd_init(void)
  276. {
  277. struct device_node *cdbias;
  278. int gpio, err;
  279. cdbias = of_find_node_by_path("/usb-s8815/mmcsd-gpio");
  280. if (!cdbias) {
  281. pr_info("could not find MMC/SD card detect bias node\n");
  282. return 0;
  283. }
  284. gpio = of_get_gpio(cdbias, 0);
  285. if (gpio < 0) {
  286. pr_info("could not obtain MMC/SD card detect bias GPIO\n");
  287. return 0;
  288. }
  289. err = gpio_request(gpio, "card detect bias");
  290. if (err) {
  291. pr_info("failed to request card detect bias GPIO %d\n", gpio);
  292. return -ENODEV;
  293. }
  294. err = gpio_direction_output(gpio, 0);
  295. if (err){
  296. pr_info("failed to set GPIO %d as output, low\n", gpio);
  297. return err;
  298. }
  299. pr_info("enabled USB-S8815 CD bias GPIO %d, low\n", gpio);
  300. return 0;
  301. }
  302. device_initcall(cpu8815_mmcsd_init);
  303. /* These are mostly to get the right device names for the clock lookups */
  304. static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = {
  305. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO0_BASE,
  306. "gpio.0", NULL),
  307. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO1_BASE,
  308. "gpio.1", NULL),
  309. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO2_BASE,
  310. "gpio.2", NULL),
  311. OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO3_BASE,
  312. "gpio.3", NULL),
  313. OF_DEV_AUXDATA("stericsson,nmk-pinctrl-stn8815", 0,
  314. "pinctrl-stn8815", NULL),
  315. OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE,
  316. "uart0", NULL),
  317. OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE,
  318. "uart1", NULL),
  319. OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE,
  320. "rng", NULL),
  321. OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE,
  322. "rtc-pl031", NULL),
  323. OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE,
  324. "fsmc-nand", &cpu8815_nand_data),
  325. OF_DEV_AUXDATA("arm,primecell", NOMADIK_SDI_BASE,
  326. "mmci", &mmcsd_plat_data),
  327. { /* sentinel */ },
  328. };
  329. static void __init cpu8815_init_of(void)
  330. {
  331. #ifdef CONFIG_CACHE_L2X0
  332. /* At full speed latency must be >=2, so 0x249 in low bits */
  333. l2x0_of_init(0x00730249, 0xfe000fff);
  334. #endif
  335. pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap));
  336. of_platform_populate(NULL, of_default_bus_match_table,
  337. cpu8815_auxdata_lookup, NULL);
  338. }
  339. static const char * cpu8815_board_compat[] = {
  340. "calaosystems,usb-s8815",
  341. NULL,
  342. };
  343. DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815")
  344. .map_io = cpu8815_map_io,
  345. .init_irq = irqchip_init,
  346. .init_time = cpu8815_timer_init_of,
  347. .init_machine = cpu8815_init_of,
  348. .restart = cpu8815_restart,
  349. .dt_compat = cpu8815_board_compat,
  350. MACHINE_END
  351. #endif