generic.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * arch/arm/mach-imx/generic.c
  3. *
  4. * author: Sascha Hauer
  5. * Created: april 20th, 2004
  6. * Copyright: Synertronixx GmbH
  7. *
  8. * Common code for i.MX machines
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/platform_device.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/string.h>
  30. #include <asm/arch/imxfb.h>
  31. #include <asm/hardware.h>
  32. #include <asm/arch/imx-regs.h>
  33. #include <asm/mach/map.h>
  34. #include <asm/arch/mmc.h>
  35. void imx_gpio_mode(int gpio_mode)
  36. {
  37. unsigned int pin = gpio_mode & GPIO_PIN_MASK;
  38. unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
  39. unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> GPIO_OCR_SHIFT;
  40. unsigned int tmp;
  41. /* Pullup enable */
  42. if(gpio_mode & GPIO_PUEN)
  43. PUEN(port) |= (1<<pin);
  44. else
  45. PUEN(port) &= ~(1<<pin);
  46. /* Data direction */
  47. if(gpio_mode & GPIO_OUT)
  48. DDIR(port) |= 1<<pin;
  49. else
  50. DDIR(port) &= ~(1<<pin);
  51. /* Primary / alternate function */
  52. if(gpio_mode & GPIO_AF)
  53. GPR(port) |= (1<<pin);
  54. else
  55. GPR(port) &= ~(1<<pin);
  56. /* use as gpio? */
  57. if(gpio_mode & GPIO_GIUS)
  58. GIUS(port) |= (1<<pin);
  59. else
  60. GIUS(port) &= ~(1<<pin);
  61. /* Output / input configuration */
  62. /* FIXME: I'm not very sure about OCR and ICONF, someone
  63. * should have a look over it
  64. */
  65. if(pin<16) {
  66. tmp = OCR1(port);
  67. tmp &= ~( 3<<(pin*2));
  68. tmp |= (ocr << (pin*2));
  69. OCR1(port) = tmp;
  70. ICONFA1(port) &= ~( 3<<(pin*2));
  71. ICONFA1(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << (pin * 2);
  72. ICONFB1(port) &= ~( 3<<(pin*2));
  73. ICONFB1(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << (pin * 2);
  74. } else {
  75. tmp = OCR2(port);
  76. tmp &= ~( 3<<((pin-16)*2));
  77. tmp |= (ocr << ((pin-16)*2));
  78. OCR2(port) = tmp;
  79. ICONFA2(port) &= ~( 3<<((pin-16)*2));
  80. ICONFA2(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << ((pin-16) * 2);
  81. ICONFB2(port) &= ~( 3<<((pin-16)*2));
  82. ICONFB2(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << ((pin-16) * 2);
  83. }
  84. }
  85. EXPORT_SYMBOL(imx_gpio_mode);
  86. /*
  87. * get the system pll clock in Hz
  88. *
  89. * mfi + mfn / (mfd +1)
  90. * f = 2 * f_ref * --------------------
  91. * pd + 1
  92. */
  93. static unsigned int imx_decode_pll(unsigned int pll)
  94. {
  95. u32 mfi = (pll >> 10) & 0xf;
  96. u32 mfn = pll & 0x3ff;
  97. u32 mfd = (pll >> 16) & 0x3ff;
  98. u32 pd = (pll >> 26) & 0xf;
  99. u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
  100. mfi = mfi <= 5 ? 5 : mfi;
  101. return (2 * (f_ref>>10) * ( (mfi<<10) + (mfn<<10) / (mfd+1) )) / (pd+1);
  102. }
  103. unsigned int imx_get_system_clk(void)
  104. {
  105. return imx_decode_pll(SPCTL0);
  106. }
  107. EXPORT_SYMBOL(imx_get_system_clk);
  108. unsigned int imx_get_mcu_clk(void)
  109. {
  110. return imx_decode_pll(MPCTL0);
  111. }
  112. EXPORT_SYMBOL(imx_get_mcu_clk);
  113. /*
  114. * get peripheral clock 1 ( UART[12], Timer[12], PWM )
  115. */
  116. unsigned int imx_get_perclk1(void)
  117. {
  118. return imx_get_system_clk() / (((PCDR) & 0xf)+1);
  119. }
  120. EXPORT_SYMBOL(imx_get_perclk1);
  121. /*
  122. * get peripheral clock 2 ( LCD, SD, SPI[12] )
  123. */
  124. unsigned int imx_get_perclk2(void)
  125. {
  126. return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
  127. }
  128. EXPORT_SYMBOL(imx_get_perclk2);
  129. /*
  130. * get peripheral clock 3 ( SSI )
  131. */
  132. unsigned int imx_get_perclk3(void)
  133. {
  134. return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
  135. }
  136. EXPORT_SYMBOL(imx_get_perclk3);
  137. /*
  138. * get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
  139. */
  140. unsigned int imx_get_hclk(void)
  141. {
  142. return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
  143. }
  144. EXPORT_SYMBOL(imx_get_hclk);
  145. static struct resource imx_mmc_resources[] = {
  146. [0] = {
  147. .start = 0x00214000,
  148. .end = 0x002140FF,
  149. .flags = IORESOURCE_MEM,
  150. },
  151. [1] = {
  152. .start = (SDHC_INT),
  153. .end = (SDHC_INT),
  154. .flags = IORESOURCE_IRQ,
  155. },
  156. };
  157. static u64 imxmmmc_dmamask = 0xffffffffUL;
  158. static struct platform_device imx_mmc_device = {
  159. .name = "imx-mmc",
  160. .id = 0,
  161. .dev = {
  162. .dma_mask = &imxmmmc_dmamask,
  163. .coherent_dma_mask = 0xffffffff,
  164. },
  165. .num_resources = ARRAY_SIZE(imx_mmc_resources),
  166. .resource = imx_mmc_resources,
  167. };
  168. void __init imx_set_mmc_info(struct imxmmc_platform_data *info)
  169. {
  170. imx_mmc_device.dev.platform_data = info;
  171. }
  172. EXPORT_SYMBOL(imx_set_mmc_info);
  173. static struct resource imx_uart1_resources[] = {
  174. [0] = {
  175. .start = 0x00206000,
  176. .end = 0x002060FF,
  177. .flags = IORESOURCE_MEM,
  178. },
  179. [1] = {
  180. .start = (UART1_MINT_RX),
  181. .end = (UART1_MINT_RX),
  182. .flags = IORESOURCE_IRQ,
  183. },
  184. [2] = {
  185. .start = (UART1_MINT_TX),
  186. .end = (UART1_MINT_TX),
  187. .flags = IORESOURCE_IRQ,
  188. },
  189. };
  190. static struct platform_device imx_uart1_device = {
  191. .name = "imx-uart",
  192. .id = 0,
  193. .num_resources = ARRAY_SIZE(imx_uart1_resources),
  194. .resource = imx_uart1_resources,
  195. };
  196. static struct resource imx_uart2_resources[] = {
  197. [0] = {
  198. .start = 0x00207000,
  199. .end = 0x002070FF,
  200. .flags = IORESOURCE_MEM,
  201. },
  202. [1] = {
  203. .start = (UART2_MINT_RX),
  204. .end = (UART2_MINT_RX),
  205. .flags = IORESOURCE_IRQ,
  206. },
  207. [2] = {
  208. .start = (UART2_MINT_TX),
  209. .end = (UART2_MINT_TX),
  210. .flags = IORESOURCE_IRQ,
  211. },
  212. };
  213. static struct platform_device imx_uart2_device = {
  214. .name = "imx-uart",
  215. .id = 1,
  216. .num_resources = ARRAY_SIZE(imx_uart2_resources),
  217. .resource = imx_uart2_resources,
  218. };
  219. static struct imxfb_mach_info imx_fb_info;
  220. void __init set_imx_fb_info(struct imxfb_mach_info *hard_imx_fb_info)
  221. {
  222. memcpy(&imx_fb_info,hard_imx_fb_info,sizeof(struct imxfb_mach_info));
  223. }
  224. EXPORT_SYMBOL(set_imx_fb_info);
  225. static struct resource imxfb_resources[] = {
  226. [0] = {
  227. .start = 0x00205000,
  228. .end = 0x002050FF,
  229. .flags = IORESOURCE_MEM,
  230. },
  231. [1] = {
  232. .start = LCDC_INT,
  233. .end = LCDC_INT,
  234. .flags = IORESOURCE_IRQ,
  235. },
  236. };
  237. static u64 fb_dma_mask = ~(u64)0;
  238. static struct platform_device imxfb_device = {
  239. .name = "imx-fb",
  240. .id = 0,
  241. .dev = {
  242. .platform_data = &imx_fb_info,
  243. .dma_mask = &fb_dma_mask,
  244. .coherent_dma_mask = 0xffffffff,
  245. },
  246. .num_resources = ARRAY_SIZE(imxfb_resources),
  247. .resource = imxfb_resources,
  248. };
  249. static struct platform_device *devices[] __initdata = {
  250. &imx_mmc_device,
  251. &imxfb_device,
  252. &imx_uart1_device,
  253. &imx_uart2_device,
  254. };
  255. static struct map_desc imx_io_desc[] __initdata = {
  256. {
  257. .virtual = IMX_IO_BASE,
  258. .pfn = __phys_to_pfn(IMX_IO_PHYS),
  259. .length = IMX_IO_SIZE,
  260. .type = MT_DEVICE
  261. }
  262. };
  263. void __init
  264. imx_map_io(void)
  265. {
  266. iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc));
  267. }
  268. static int __init imx_init(void)
  269. {
  270. return platform_add_devices(devices, ARRAY_SIZE(devices));
  271. }
  272. subsys_initcall(imx_init);