generic.c 5.8 KB

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