generic.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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/device.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <asm/arch/imxfb.h>
  30. #include <asm/hardware.h>
  31. #include <asm/arch/imx-regs.h>
  32. #include <asm/mach/map.h>
  33. void imx_gpio_mode(int gpio_mode)
  34. {
  35. unsigned int pin = gpio_mode & GPIO_PIN_MASK;
  36. unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
  37. unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> GPIO_OCR_SHIFT;
  38. unsigned int tmp;
  39. /* Pullup enable */
  40. if(gpio_mode & GPIO_PUEN)
  41. PUEN(port) |= (1<<pin);
  42. else
  43. PUEN(port) &= ~(1<<pin);
  44. /* Data direction */
  45. if(gpio_mode & GPIO_OUT)
  46. DDIR(port) |= 1<<pin;
  47. else
  48. DDIR(port) &= ~(1<<pin);
  49. /* Primary / alternate function */
  50. if(gpio_mode & GPIO_AF)
  51. GPR(port) |= (1<<pin);
  52. else
  53. GPR(port) &= ~(1<<pin);
  54. /* use as gpio? */
  55. if(gpio_mode & GPIO_GIUS)
  56. GIUS(port) |= (1<<pin);
  57. else
  58. GIUS(port) &= ~(1<<pin);
  59. /* Output / input configuration */
  60. /* FIXME: I'm not very sure about OCR and ICONF, someone
  61. * should have a look over it
  62. */
  63. if(pin<16) {
  64. tmp = OCR1(port);
  65. tmp &= ~( 3<<(pin*2));
  66. tmp |= (ocr << (pin*2));
  67. OCR1(port) = tmp;
  68. ICONFA1(port) &= ~( 3<<(pin*2));
  69. ICONFA1(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << (pin * 2);
  70. ICONFB1(port) &= ~( 3<<(pin*2));
  71. ICONFB1(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << (pin * 2);
  72. } else {
  73. tmp = OCR2(port);
  74. tmp &= ~( 3<<((pin-16)*2));
  75. tmp |= (ocr << ((pin-16)*2));
  76. OCR2(port) = tmp;
  77. ICONFA2(port) &= ~( 3<<((pin-16)*2));
  78. ICONFA2(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << ((pin-16) * 2);
  79. ICONFB2(port) &= ~( 3<<((pin-16)*2));
  80. ICONFB2(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << ((pin-16) * 2);
  81. }
  82. }
  83. EXPORT_SYMBOL(imx_gpio_mode);
  84. /*
  85. * get the system pll clock in Hz
  86. *
  87. * mfi + mfn / (mfd +1)
  88. * f = 2 * f_ref * --------------------
  89. * pd + 1
  90. */
  91. static unsigned int imx_decode_pll(unsigned int pll)
  92. {
  93. u32 mfi = (pll >> 10) & 0xf;
  94. u32 mfn = pll & 0x3ff;
  95. u32 mfd = (pll >> 16) & 0x3ff;
  96. u32 pd = (pll >> 26) & 0xf;
  97. u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
  98. mfi = mfi <= 5 ? 5 : mfi;
  99. return (2 * (f_ref>>10) * ( (mfi<<10) + (mfn<<10) / (mfd+1) )) / (pd+1);
  100. }
  101. unsigned int imx_get_system_clk(void)
  102. {
  103. return imx_decode_pll(SPCTL0);
  104. }
  105. EXPORT_SYMBOL(imx_get_system_clk);
  106. unsigned int imx_get_mcu_clk(void)
  107. {
  108. return imx_decode_pll(MPCTL0);
  109. }
  110. EXPORT_SYMBOL(imx_get_mcu_clk);
  111. /*
  112. * get peripheral clock 1 ( UART[12], Timer[12], PWM )
  113. */
  114. unsigned int imx_get_perclk1(void)
  115. {
  116. return imx_get_system_clk() / (((PCDR) & 0xf)+1);
  117. }
  118. EXPORT_SYMBOL(imx_get_perclk1);
  119. /*
  120. * get peripheral clock 2 ( LCD, SD, SPI[12] )
  121. */
  122. unsigned int imx_get_perclk2(void)
  123. {
  124. return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
  125. }
  126. EXPORT_SYMBOL(imx_get_perclk2);
  127. /*
  128. * get peripheral clock 3 ( SSI )
  129. */
  130. unsigned int imx_get_perclk3(void)
  131. {
  132. return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
  133. }
  134. EXPORT_SYMBOL(imx_get_perclk3);
  135. /*
  136. * get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
  137. */
  138. unsigned int imx_get_hclk(void)
  139. {
  140. return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
  141. }
  142. EXPORT_SYMBOL(imx_get_hclk);
  143. static struct resource imx_mmc_resources[] = {
  144. [0] = {
  145. .start = 0x00214000,
  146. .end = 0x002140FF,
  147. .flags = IORESOURCE_MEM,
  148. },
  149. [1] = {
  150. .start = (SDHC_INT),
  151. .end = (SDHC_INT),
  152. .flags = IORESOURCE_IRQ,
  153. },
  154. };
  155. static struct platform_device imx_mmc_device = {
  156. .name = "imx-mmc",
  157. .id = 0,
  158. .num_resources = ARRAY_SIZE(imx_mmc_resources),
  159. .resource = imx_mmc_resources,
  160. };
  161. static struct resource imx_uart1_resources[] = {
  162. [0] = {
  163. .start = 0x00206000,
  164. .end = 0x002060FF,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. [1] = {
  168. .start = (UART1_MINT_RX),
  169. .end = (UART1_MINT_RX),
  170. .flags = IORESOURCE_IRQ,
  171. },
  172. [2] = {
  173. .start = (UART1_MINT_TX),
  174. .end = (UART1_MINT_TX),
  175. .flags = IORESOURCE_IRQ,
  176. },
  177. };
  178. static struct platform_device imx_uart1_device = {
  179. .name = "imx-uart",
  180. .id = 0,
  181. .num_resources = ARRAY_SIZE(imx_uart1_resources),
  182. .resource = imx_uart1_resources,
  183. };
  184. static struct resource imx_uart2_resources[] = {
  185. [0] = {
  186. .start = 0x00207000,
  187. .end = 0x002070FF,
  188. .flags = IORESOURCE_MEM,
  189. },
  190. [1] = {
  191. .start = (UART2_MINT_RX),
  192. .end = (UART2_MINT_RX),
  193. .flags = IORESOURCE_IRQ,
  194. },
  195. [2] = {
  196. .start = (UART2_MINT_TX),
  197. .end = (UART2_MINT_TX),
  198. .flags = IORESOURCE_IRQ,
  199. },
  200. };
  201. static struct platform_device imx_uart2_device = {
  202. .name = "imx-uart",
  203. .id = 1,
  204. .num_resources = ARRAY_SIZE(imx_uart2_resources),
  205. .resource = imx_uart2_resources,
  206. };
  207. static struct imxfb_mach_info imx_fb_info;
  208. void __init set_imx_fb_info(struct imxfb_mach_info *hard_imx_fb_info)
  209. {
  210. memcpy(&imx_fb_info,hard_imx_fb_info,sizeof(struct imxfb_mach_info));
  211. }
  212. EXPORT_SYMBOL(set_imx_fb_info);
  213. static struct resource imxfb_resources[] = {
  214. [0] = {
  215. .start = 0x00205000,
  216. .end = 0x002050FF,
  217. .flags = IORESOURCE_MEM,
  218. },
  219. [1] = {
  220. .start = LCDC_INT,
  221. .end = LCDC_INT,
  222. .flags = IORESOURCE_IRQ,
  223. },
  224. };
  225. static u64 fb_dma_mask = ~(u64)0;
  226. static struct platform_device imxfb_device = {
  227. .name = "imx-fb",
  228. .id = 0,
  229. .dev = {
  230. .platform_data = &imx_fb_info,
  231. .dma_mask = &fb_dma_mask,
  232. .coherent_dma_mask = 0xffffffff,
  233. },
  234. .num_resources = ARRAY_SIZE(imxfb_resources),
  235. .resource = imxfb_resources,
  236. };
  237. static struct platform_device *devices[] __initdata = {
  238. &imx_mmc_device,
  239. &imxfb_device,
  240. &imx_uart1_device,
  241. &imx_uart2_device,
  242. };
  243. static struct map_desc imx_io_desc[] __initdata = {
  244. {
  245. .virtual = IMX_IO_BASE,
  246. .pfn = __phys_to_pfn(IMX_IO_PHYS),
  247. .length = IMX_IO_SIZE,
  248. .type = MT_DEVICE
  249. }
  250. };
  251. void __init
  252. imx_map_io(void)
  253. {
  254. iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc));
  255. }
  256. static int __init imx_init(void)
  257. {
  258. return platform_add_devices(devices, ARRAY_SIZE(devices));
  259. }
  260. subsys_initcall(imx_init);