generic.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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, u32 f_ref)
  94. {
  95. unsigned long long ll;
  96. unsigned long quot;
  97. u32 mfi = (pll >> 10) & 0xf;
  98. u32 mfn = pll & 0x3ff;
  99. u32 mfd = (pll >> 16) & 0x3ff;
  100. u32 pd = (pll >> 26) & 0xf;
  101. mfi = mfi <= 5 ? 5 : mfi;
  102. ll = 2 * (unsigned long long)f_ref * ( (mfi<<16) + (mfn<<16) / (mfd+1) );
  103. quot = (pd+1) * (1<<16);
  104. ll += quot / 2;
  105. do_div(ll, quot);
  106. return (unsigned int) ll;
  107. }
  108. unsigned int imx_get_system_clk(void)
  109. {
  110. u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
  111. return imx_decode_pll(SPCTL0, f_ref);
  112. }
  113. EXPORT_SYMBOL(imx_get_system_clk);
  114. unsigned int imx_get_mcu_clk(void)
  115. {
  116. return imx_decode_pll(MPCTL0, CLK32 * 512);
  117. }
  118. EXPORT_SYMBOL(imx_get_mcu_clk);
  119. /*
  120. * get peripheral clock 1 ( UART[12], Timer[12], PWM )
  121. */
  122. unsigned int imx_get_perclk1(void)
  123. {
  124. return imx_get_system_clk() / (((PCDR) & 0xf)+1);
  125. }
  126. EXPORT_SYMBOL(imx_get_perclk1);
  127. /*
  128. * get peripheral clock 2 ( LCD, SD, SPI[12] )
  129. */
  130. unsigned int imx_get_perclk2(void)
  131. {
  132. return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
  133. }
  134. EXPORT_SYMBOL(imx_get_perclk2);
  135. /*
  136. * get peripheral clock 3 ( SSI )
  137. */
  138. unsigned int imx_get_perclk3(void)
  139. {
  140. return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
  141. }
  142. EXPORT_SYMBOL(imx_get_perclk3);
  143. /*
  144. * get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
  145. */
  146. unsigned int imx_get_hclk(void)
  147. {
  148. return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
  149. }
  150. EXPORT_SYMBOL(imx_get_hclk);
  151. static struct resource imx_mmc_resources[] = {
  152. [0] = {
  153. .start = 0x00214000,
  154. .end = 0x002140FF,
  155. .flags = IORESOURCE_MEM,
  156. },
  157. [1] = {
  158. .start = (SDHC_INT),
  159. .end = (SDHC_INT),
  160. .flags = IORESOURCE_IRQ,
  161. },
  162. };
  163. static u64 imxmmmc_dmamask = 0xffffffffUL;
  164. static struct platform_device imx_mmc_device = {
  165. .name = "imx-mmc",
  166. .id = 0,
  167. .dev = {
  168. .dma_mask = &imxmmmc_dmamask,
  169. .coherent_dma_mask = 0xffffffff,
  170. },
  171. .num_resources = ARRAY_SIZE(imx_mmc_resources),
  172. .resource = imx_mmc_resources,
  173. };
  174. void __init imx_set_mmc_info(struct imxmmc_platform_data *info)
  175. {
  176. imx_mmc_device.dev.platform_data = info;
  177. }
  178. EXPORT_SYMBOL(imx_set_mmc_info);
  179. static struct imxfb_mach_info imx_fb_info;
  180. void __init set_imx_fb_info(struct imxfb_mach_info *hard_imx_fb_info)
  181. {
  182. memcpy(&imx_fb_info,hard_imx_fb_info,sizeof(struct imxfb_mach_info));
  183. }
  184. EXPORT_SYMBOL(set_imx_fb_info);
  185. static struct resource imxfb_resources[] = {
  186. [0] = {
  187. .start = 0x00205000,
  188. .end = 0x002050FF,
  189. .flags = IORESOURCE_MEM,
  190. },
  191. [1] = {
  192. .start = LCDC_INT,
  193. .end = LCDC_INT,
  194. .flags = IORESOURCE_IRQ,
  195. },
  196. };
  197. static u64 fb_dma_mask = ~(u64)0;
  198. static struct platform_device imxfb_device = {
  199. .name = "imx-fb",
  200. .id = 0,
  201. .dev = {
  202. .platform_data = &imx_fb_info,
  203. .dma_mask = &fb_dma_mask,
  204. .coherent_dma_mask = 0xffffffff,
  205. },
  206. .num_resources = ARRAY_SIZE(imxfb_resources),
  207. .resource = imxfb_resources,
  208. };
  209. static struct platform_device *devices[] __initdata = {
  210. &imx_mmc_device,
  211. &imxfb_device,
  212. };
  213. static struct map_desc imx_io_desc[] __initdata = {
  214. {
  215. .virtual = IMX_IO_BASE,
  216. .pfn = __phys_to_pfn(IMX_IO_PHYS),
  217. .length = IMX_IO_SIZE,
  218. .type = MT_DEVICE
  219. }
  220. };
  221. void __init
  222. imx_map_io(void)
  223. {
  224. iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc));
  225. }
  226. static int __init imx_init(void)
  227. {
  228. return platform_add_devices(devices, ARRAY_SIZE(devices));
  229. }
  230. subsys_initcall(imx_init);