/arch/arm/mach-imx/generic.c

https://bitbucket.org/evzijst/gittest · C · 274 lines · 190 code · 32 blank · 52 comment · 11 complexity · cafb8c5eb8eca4ad3ddc5de04a65c49f MD5 · raw file

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