generic.c 6.6 KB

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