generic.c 6.3 KB

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