mpc885ads_setup.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Platform setup for the Freescale mpc885ads board
  3. *
  4. * Vitaly Bordug <vbordug@ru.mvista.com>
  5. *
  6. * Copyright 2005 MontaVista Software Inc.
  7. *
  8. * Heavily modified by Scott Wood <scottwood@freescale.com>
  9. * Copyright 2007 Freescale Semiconductor, Inc.
  10. *
  11. * This file is licensed under the terms of the GNU General Public License
  12. * version 2. This program is licensed "as is" without any warranty of any
  13. * kind, whether express or implied.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/param.h>
  18. #include <linux/string.h>
  19. #include <linux/ioport.h>
  20. #include <linux/device.h>
  21. #include <linux/delay.h>
  22. #include <linux/fs_enet_pd.h>
  23. #include <linux/fs_uart_pd.h>
  24. #include <linux/fsl_devices.h>
  25. #include <linux/mii.h>
  26. #include <linux/of_platform.h>
  27. #include <asm/delay.h>
  28. #include <asm/io.h>
  29. #include <asm/machdep.h>
  30. #include <asm/page.h>
  31. #include <asm/processor.h>
  32. #include <asm/time.h>
  33. #include <asm/mpc8xx.h>
  34. #include <asm/8xx_immap.h>
  35. #include <asm/cpm1.h>
  36. #include <asm/fs_pd.h>
  37. #include <asm/udbg.h>
  38. #include "mpc885ads.h"
  39. #include "mpc8xx.h"
  40. static u32 __iomem *bcsr, *bcsr5;
  41. #ifdef CONFIG_PCMCIA_M8XX
  42. static void pcmcia_hw_setup(int slot, int enable)
  43. {
  44. if (enable)
  45. clrbits32(&bcsr[1], BCSR1_PCCEN);
  46. else
  47. setbits32(&bcsr[1], BCSR1_PCCEN);
  48. }
  49. static int pcmcia_set_voltage(int slot, int vcc, int vpp)
  50. {
  51. u32 reg = 0;
  52. switch (vcc) {
  53. case 0:
  54. break;
  55. case 33:
  56. reg |= BCSR1_PCCVCC0;
  57. break;
  58. case 50:
  59. reg |= BCSR1_PCCVCC1;
  60. break;
  61. default:
  62. return 1;
  63. }
  64. switch (vpp) {
  65. case 0:
  66. break;
  67. case 33:
  68. case 50:
  69. if (vcc == vpp)
  70. reg |= BCSR1_PCCVPP1;
  71. else
  72. return 1;
  73. break;
  74. case 120:
  75. if ((vcc == 33) || (vcc == 50))
  76. reg |= BCSR1_PCCVPP0;
  77. else
  78. return 1;
  79. default:
  80. return 1;
  81. }
  82. /* first, turn off all power */
  83. clrbits32(&bcsr[1], 0x00610000);
  84. /* enable new powersettings */
  85. setbits32(&bcsr[1], reg);
  86. return 0;
  87. }
  88. #endif
  89. struct cpm_pin {
  90. int port, pin, flags;
  91. };
  92. static struct cpm_pin mpc885ads_pins[] = {
  93. /* SMC1 */
  94. {CPM_PORTB, 24, CPM_PIN_INPUT}, /* RX */
  95. {CPM_PORTB, 25, CPM_PIN_INPUT | CPM_PIN_SECONDARY}, /* TX */
  96. /* SMC2 */
  97. #ifndef CONFIG_MPC8xx_SECOND_ETH_FEC2
  98. {CPM_PORTE, 21, CPM_PIN_INPUT}, /* RX */
  99. {CPM_PORTE, 20, CPM_PIN_INPUT | CPM_PIN_SECONDARY}, /* TX */
  100. #endif
  101. /* SCC3 */
  102. {CPM_PORTA, 9, CPM_PIN_INPUT}, /* RX */
  103. {CPM_PORTA, 8, CPM_PIN_INPUT}, /* TX */
  104. {CPM_PORTC, 4, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_GPIO}, /* RENA */
  105. {CPM_PORTC, 5, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_GPIO}, /* CLSN */
  106. {CPM_PORTE, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY}, /* TENA */
  107. {CPM_PORTE, 17, CPM_PIN_INPUT}, /* CLK5 */
  108. {CPM_PORTE, 16, CPM_PIN_INPUT}, /* CLK6 */
  109. /* MII1 */
  110. {CPM_PORTA, 0, CPM_PIN_INPUT},
  111. {CPM_PORTA, 1, CPM_PIN_INPUT},
  112. {CPM_PORTA, 2, CPM_PIN_INPUT},
  113. {CPM_PORTA, 3, CPM_PIN_INPUT},
  114. {CPM_PORTA, 4, CPM_PIN_OUTPUT},
  115. {CPM_PORTA, 10, CPM_PIN_OUTPUT},
  116. {CPM_PORTA, 11, CPM_PIN_OUTPUT},
  117. {CPM_PORTB, 19, CPM_PIN_INPUT},
  118. {CPM_PORTB, 31, CPM_PIN_INPUT},
  119. {CPM_PORTC, 12, CPM_PIN_INPUT},
  120. {CPM_PORTC, 13, CPM_PIN_INPUT},
  121. {CPM_PORTE, 30, CPM_PIN_OUTPUT},
  122. {CPM_PORTE, 31, CPM_PIN_OUTPUT},
  123. /* MII2 */
  124. #ifdef CONFIG_MPC8xx_SECOND_ETH_FEC2
  125. {CPM_PORTE, 14, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  126. {CPM_PORTE, 15, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  127. {CPM_PORTE, 16, CPM_PIN_OUTPUT},
  128. {CPM_PORTE, 17, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  129. {CPM_PORTE, 18, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  130. {CPM_PORTE, 19, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  131. {CPM_PORTE, 20, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  132. {CPM_PORTE, 21, CPM_PIN_OUTPUT},
  133. {CPM_PORTE, 22, CPM_PIN_OUTPUT},
  134. {CPM_PORTE, 23, CPM_PIN_OUTPUT},
  135. {CPM_PORTE, 24, CPM_PIN_OUTPUT},
  136. {CPM_PORTE, 25, CPM_PIN_OUTPUT},
  137. {CPM_PORTE, 26, CPM_PIN_OUTPUT},
  138. {CPM_PORTE, 27, CPM_PIN_OUTPUT},
  139. {CPM_PORTE, 28, CPM_PIN_OUTPUT},
  140. {CPM_PORTE, 29, CPM_PIN_OUTPUT},
  141. #endif
  142. /* I2C */
  143. {CPM_PORTB, 26, CPM_PIN_INPUT | CPM_PIN_OPENDRAIN},
  144. {CPM_PORTB, 27, CPM_PIN_INPUT | CPM_PIN_OPENDRAIN},
  145. };
  146. static void __init init_ioports(void)
  147. {
  148. int i;
  149. for (i = 0; i < ARRAY_SIZE(mpc885ads_pins); i++) {
  150. struct cpm_pin *pin = &mpc885ads_pins[i];
  151. cpm1_set_pin(pin->port, pin->pin, pin->flags);
  152. }
  153. cpm1_clk_setup(CPM_CLK_SMC1, CPM_BRG1, CPM_CLK_RTX);
  154. cpm1_clk_setup(CPM_CLK_SMC2, CPM_BRG2, CPM_CLK_RTX);
  155. cpm1_clk_setup(CPM_CLK_SCC3, CPM_CLK5, CPM_CLK_TX);
  156. cpm1_clk_setup(CPM_CLK_SCC3, CPM_CLK6, CPM_CLK_RX);
  157. /* Set FEC1 and FEC2 to MII mode */
  158. clrbits32(&mpc8xx_immr->im_cpm.cp_cptr, 0x00000180);
  159. }
  160. static void __init mpc885ads_setup_arch(void)
  161. {
  162. struct device_node *np;
  163. cpm_reset();
  164. init_ioports();
  165. np = of_find_compatible_node(NULL, NULL, "fsl,mpc885ads-bcsr");
  166. if (!np) {
  167. printk(KERN_CRIT "Could not find fsl,mpc885ads-bcsr node\n");
  168. return;
  169. }
  170. bcsr = of_iomap(np, 0);
  171. bcsr5 = of_iomap(np, 1);
  172. of_node_put(np);
  173. if (!bcsr || !bcsr5) {
  174. printk(KERN_CRIT "Could not remap BCSR\n");
  175. return;
  176. }
  177. clrbits32(&bcsr[1], BCSR1_RS232EN_1);
  178. #ifdef CONFIG_MPC8xx_SECOND_ETH_FEC2
  179. setbits32(&bcsr[1], BCSR1_RS232EN_2);
  180. #else
  181. clrbits32(&bcsr[1], BCSR1_RS232EN_2);
  182. #endif
  183. clrbits32(bcsr5, BCSR5_MII1_EN);
  184. setbits32(bcsr5, BCSR5_MII1_RST);
  185. udelay(1000);
  186. clrbits32(bcsr5, BCSR5_MII1_RST);
  187. #ifdef CONFIG_MPC8xx_SECOND_ETH_FEC2
  188. clrbits32(bcsr5, BCSR5_MII2_EN);
  189. setbits32(bcsr5, BCSR5_MII2_RST);
  190. udelay(1000);
  191. clrbits32(bcsr5, BCSR5_MII2_RST);
  192. #else
  193. setbits32(bcsr5, BCSR5_MII2_EN);
  194. #endif
  195. #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
  196. clrbits32(&bcsr[4], BCSR4_ETH10_RST);
  197. udelay(1000);
  198. setbits32(&bcsr[4], BCSR4_ETH10_RST);
  199. setbits32(&bcsr[1], BCSR1_ETHEN);
  200. np = of_find_node_by_path("/soc@ff000000/cpm@9c0/serial@a80");
  201. #else
  202. np = of_find_node_by_path("/soc@ff000000/cpm@9c0/ethernet@a40");
  203. #endif
  204. /* The SCC3 enet registers overlap the SMC1 registers, so
  205. * one of the two must be removed from the device tree.
  206. */
  207. if (np) {
  208. of_detach_node(np);
  209. of_node_put(np);
  210. }
  211. #ifdef CONFIG_PCMCIA_M8XX
  212. /* Set up board specific hook-ups.*/
  213. m8xx_pcmcia_ops.hw_ctrl = pcmcia_hw_setup;
  214. m8xx_pcmcia_ops.voltage_set = pcmcia_set_voltage;
  215. #endif
  216. }
  217. static int __init mpc885ads_probe(void)
  218. {
  219. unsigned long root = of_get_flat_dt_root();
  220. return of_flat_dt_is_compatible(root, "fsl,mpc885ads");
  221. }
  222. static struct of_device_id __initdata of_bus_ids[] = {
  223. { .name = "soc", },
  224. { .name = "cpm", },
  225. { .name = "localbus", },
  226. {},
  227. };
  228. static int __init declare_of_platform_devices(void)
  229. {
  230. /* Publish the QE devices */
  231. of_platform_bus_probe(NULL, of_bus_ids, NULL);
  232. return 0;
  233. }
  234. machine_device_initcall(mpc885_ads, declare_of_platform_devices);
  235. define_machine(mpc885_ads) {
  236. .name = "Freescale MPC885 ADS",
  237. .probe = mpc885ads_probe,
  238. .setup_arch = mpc885ads_setup_arch,
  239. .init_IRQ = mpc8xx_pics_init,
  240. .get_irq = mpc8xx_get_irq,
  241. .restart = mpc8xx_restart,
  242. .calibrate_decr = mpc8xx_calibrate_decr,
  243. .set_rtc_time = mpc8xx_set_rtc_time,
  244. .get_rtc_time = mpc8xx_get_rtc_time,
  245. .progress = udbg_progress,
  246. };