mpc885ads_setup.c 6.8 KB

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