mpc885ads_setup.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*arch/ppc/platforms/mpc885ads-setup.c
  2. *
  3. * Platform setup for the Freescale mpc885ads board
  4. *
  5. * Vitaly Bordug <vbordug@ru.mvista.com>
  6. *
  7. * Copyright 2005 MontaVista Software Inc.
  8. *
  9. * This file is licensed under the terms of the GNU General Public License
  10. * version 2. This program is licensed "as is" without any warranty of any
  11. * kind, whether express or implied.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/param.h>
  17. #include <linux/string.h>
  18. #include <linux/ioport.h>
  19. #include <linux/device.h>
  20. #include <linux/fs_enet_pd.h>
  21. #include <linux/mii.h>
  22. #include <asm/delay.h>
  23. #include <asm/io.h>
  24. #include <asm/machdep.h>
  25. #include <asm/page.h>
  26. #include <asm/processor.h>
  27. #include <asm/system.h>
  28. #include <asm/time.h>
  29. #include <asm/ppcboot.h>
  30. #include <asm/8xx_immap.h>
  31. #include <asm/commproc.h>
  32. #include <asm/ppc_sys.h>
  33. extern unsigned char __res[];
  34. static void __init mpc885ads_scc_phy_init(char);
  35. static struct fs_mii_bus_info fec_mii_bus_info = {
  36. .method = fsmii_fec,
  37. .id = 0,
  38. };
  39. static struct fs_mii_bus_info scc_mii_bus_info = {
  40. #ifdef CONFIG_SCC_ENET_8xx_FIXED
  41. .method = fsmii_fixed,
  42. #else
  43. .method = fsmii_fec,
  44. #endif
  45. .id = 0,
  46. };
  47. static struct fs_platform_info mpc8xx_fec_pdata[] = {
  48. {
  49. .rx_ring = 128,
  50. .tx_ring = 16,
  51. .rx_copybreak = 240,
  52. .use_napi = 1,
  53. .napi_weight = 17,
  54. .phy_addr = 0,
  55. .phy_irq = SIU_IRQ7,
  56. .bus_info = &fec_mii_bus_info,
  57. }, {
  58. .rx_ring = 128,
  59. .tx_ring = 16,
  60. .rx_copybreak = 240,
  61. .use_napi = 1,
  62. .napi_weight = 17,
  63. .phy_addr = 1,
  64. .phy_irq = SIU_IRQ7,
  65. .bus_info = &fec_mii_bus_info,
  66. }
  67. };
  68. static struct fs_platform_info mpc8xx_scc_pdata = {
  69. .rx_ring = 64,
  70. .tx_ring = 8,
  71. .rx_copybreak = 240,
  72. .use_napi = 1,
  73. .napi_weight = 17,
  74. .phy_addr = 2,
  75. #ifdef CONFIG_MPC8xx_SCC_ENET_FIXED
  76. .phy_irq = -1,
  77. #else
  78. .phy_irq = SIU_IRQ7,
  79. #endif
  80. .bus_info = &scc_mii_bus_info,
  81. };
  82. void __init board_init(void)
  83. {
  84. volatile cpm8xx_t *cp = cpmp;
  85. unsigned int *bcsr_io;
  86. #ifdef CONFIG_FS_ENET
  87. immap_t *immap = (immap_t *) IMAP_ADDR;
  88. #endif
  89. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  90. if (bcsr_io == NULL) {
  91. printk(KERN_CRIT "Could not remap BCSR\n");
  92. return;
  93. }
  94. #ifdef CONFIG_SERIAL_CPM_SMC1
  95. cp->cp_simode &= ~(0xe0000000 >> 17); /* brg1 */
  96. clrbits32(bcsr_io, BCSR1_RS232EN_1);
  97. #else
  98. setbits32(bcsr_io,BCSR1_RS232EN_1);
  99. cp->cp_smc[0].smc_smcmr = 0;
  100. cp->cp_smc[0].smc_smce = 0;
  101. #endif
  102. #ifdef CONFIG_SERIAL_CPM_SMC2
  103. cp->cp_simode &= ~(0xe0000000 >> 1);
  104. cp->cp_simode |= (0x20000000 >> 1); /* brg2 */
  105. clrbits32(bcsr_io,BCSR1_RS232EN_2);
  106. #else
  107. setbits32(bcsr_io,BCSR1_RS232EN_2);
  108. cp->cp_smc[1].smc_smcmr = 0;
  109. cp->cp_smc[1].smc_smce = 0;
  110. #endif
  111. iounmap(bcsr_io);
  112. #ifdef CONFIG_FS_ENET
  113. /* use MDC for MII (common) */
  114. setbits16(&immap->im_ioport.iop_pdpar, 0x0080);
  115. clrbits16(&immap->im_ioport.iop_pddir, 0x0080);
  116. #endif
  117. }
  118. static void setup_fec1_ioports(void)
  119. {
  120. immap_t *immap = (immap_t *) IMAP_ADDR;
  121. /* configure FEC1 pins */
  122. setbits16(&immap->im_ioport.iop_papar, 0xf830);
  123. setbits16(&immap->im_ioport.iop_padir, 0x0830);
  124. clrbits16(&immap->im_ioport.iop_padir, 0xf000);
  125. setbits32(&immap->im_cpm.cp_pbpar, 0x00001001);
  126. clrbits32(&immap->im_cpm.cp_pbdir, 0x00001001);
  127. setbits16(&immap->im_ioport.iop_pcpar, 0x000c);
  128. clrbits16(&immap->im_ioport.iop_pcdir, 0x000c);
  129. setbits32(&immap->im_cpm.cp_pepar, 0x00000003);
  130. setbits32(&immap->im_cpm.cp_pedir, 0x00000003);
  131. clrbits32(&immap->im_cpm.cp_peso, 0x00000003);
  132. clrbits32(&immap->im_cpm.cp_cptr, 0x00000100);
  133. }
  134. static void setup_fec2_ioports(void)
  135. {
  136. immap_t *immap = (immap_t *) IMAP_ADDR;
  137. /* configure FEC2 pins */
  138. setbits32(&immap->im_cpm.cp_pepar, 0x0003fffc);
  139. setbits32(&immap->im_cpm.cp_pedir, 0x0003fffc);
  140. setbits32(&immap->im_cpm.cp_peso, 0x00037800);
  141. clrbits32(&immap->im_cpm.cp_peso, 0x000087fc);
  142. clrbits32(&immap->im_cpm.cp_cptr, 0x00000080);
  143. }
  144. static void setup_scc3_ioports(void)
  145. {
  146. immap_t *immap = (immap_t *) IMAP_ADDR;
  147. unsigned *bcsr_io;
  148. bcsr_io = ioremap(BCSR_ADDR, BCSR_SIZE);
  149. if (bcsr_io == NULL) {
  150. printk(KERN_CRIT "Could not remap BCSR\n");
  151. return;
  152. }
  153. /* Enable the PHY.
  154. */
  155. setbits32(bcsr_io+4, BCSR4_ETH10_RST);
  156. /* Configure port A pins for Txd and Rxd.
  157. */
  158. setbits16(&immap->im_ioport.iop_papar, PA_ENET_RXD | PA_ENET_TXD);
  159. clrbits16(&immap->im_ioport.iop_padir, PA_ENET_RXD | PA_ENET_TXD);
  160. /* Configure port C pins to enable CLSN and RENA.
  161. */
  162. clrbits16(&immap->im_ioport.iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
  163. clrbits16(&immap->im_ioport.iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
  164. setbits16(&immap->im_ioport.iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
  165. /* Configure port E for TCLK and RCLK.
  166. */
  167. setbits32(&immap->im_cpm.cp_pepar, PE_ENET_TCLK | PE_ENET_RCLK);
  168. clrbits32(&immap->im_cpm.cp_pepar, PE_ENET_TENA);
  169. clrbits32(&immap->im_cpm.cp_pedir,
  170. PE_ENET_TCLK | PE_ENET_RCLK | PE_ENET_TENA);
  171. clrbits32(&immap->im_cpm.cp_peso, PE_ENET_TCLK | PE_ENET_RCLK);
  172. setbits32(&immap->im_cpm.cp_peso, PE_ENET_TENA);
  173. /* Configure Serial Interface clock routing.
  174. * First, clear all SCC bits to zero, then set the ones we want.
  175. */
  176. clrbits32(&immap->im_cpm.cp_sicr, SICR_ENET_MASK);
  177. setbits32(&immap->im_cpm.cp_sicr, SICR_ENET_CLKRT);
  178. /* Disable Rx and Tx. SMC1 sshould be stopped if SCC3 eternet are used.
  179. */
  180. immap->im_cpm.cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  181. /* On the MPC885ADS SCC ethernet PHY is initialized in the full duplex mode
  182. * by H/W setting after reset. SCC ethernet controller support only half duplex.
  183. * This discrepancy of modes causes a lot of carrier lost errors.
  184. */
  185. /* In the original SCC enet driver the following code is placed at
  186. the end of the initialization */
  187. setbits32(&immap->im_cpm.cp_pepar, PE_ENET_TENA);
  188. clrbits32(&immap->im_cpm.cp_pedir, PE_ENET_TENA);
  189. setbits32(&immap->im_cpm.cp_peso, PE_ENET_TENA);
  190. setbits32(bcsr_io+1, BCSR1_ETHEN);
  191. iounmap(bcsr_io);
  192. }
  193. static void mpc885ads_fixup_enet_pdata(struct platform_device *pdev, int fs_no)
  194. {
  195. struct fs_platform_info *fpi = pdev->dev.platform_data;
  196. volatile cpm8xx_t *cp;
  197. bd_t *bd = (bd_t *) __res;
  198. char *e;
  199. int i;
  200. /* Get pointer to Communication Processor */
  201. cp = cpmp;
  202. switch (fs_no) {
  203. case fsid_fec1:
  204. fpi = &mpc8xx_fec_pdata[0];
  205. fpi->init_ioports = &setup_fec1_ioports;
  206. break;
  207. case fsid_fec2:
  208. fpi = &mpc8xx_fec_pdata[1];
  209. fpi->init_ioports = &setup_fec2_ioports;
  210. break;
  211. case fsid_scc3:
  212. fpi = &mpc8xx_scc_pdata;
  213. fpi->init_ioports = &setup_scc3_ioports;
  214. mpc885ads_scc_phy_init(fpi->phy_addr);
  215. break;
  216. default:
  217. printk(KERN_WARNING"Device %s is not supported!\n", pdev->name);
  218. return;
  219. }
  220. pdev->dev.platform_data = fpi;
  221. fpi->fs_no = fs_no;
  222. e = (unsigned char *)&bd->bi_enetaddr;
  223. for (i = 0; i < 6; i++)
  224. fpi->macaddr[i] = *e++;
  225. fpi->macaddr[5 - pdev->id]++;
  226. }
  227. static void mpc885ads_fixup_fec_enet_pdata(struct platform_device *pdev,
  228. int idx)
  229. {
  230. /* This is for FEC devices only */
  231. if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-fec")))
  232. return;
  233. mpc885ads_fixup_enet_pdata(pdev, fsid_fec1 + pdev->id - 1);
  234. }
  235. static void __init mpc885ads_fixup_scc_enet_pdata(struct platform_device *pdev,
  236. int idx)
  237. {
  238. /* This is for SCC devices only */
  239. if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-scc")))
  240. return;
  241. mpc885ads_fixup_enet_pdata(pdev, fsid_scc1 + pdev->id - 1);
  242. }
  243. /* SCC ethernet controller does not have MII management channel. FEC1 MII
  244. * channel is used to communicate with the 10Mbit PHY.
  245. */
  246. #define MII_ECNTRL_PINMUX 0x4
  247. #define FEC_ECNTRL_PINMUX 0x00000004
  248. #define FEC_RCNTRL_MII_MODE 0x00000004
  249. /* Make MII read/write commands.
  250. */
  251. #define mk_mii_write(REG, VAL, PHY_ADDR) (0x50020000 | (((REG) & 0x1f) << 18) | \
  252. ((VAL) & 0xffff) | ((PHY_ADDR) << 23))
  253. static void mpc885ads_scc_phy_init(char phy_addr)
  254. {
  255. volatile immap_t *immap;
  256. volatile fec_t *fecp;
  257. bd_t *bd;
  258. bd = (bd_t *) __res;
  259. immap = (immap_t *) IMAP_ADDR; /* pointer to internal registers */
  260. fecp = &(immap->im_cpm.cp_fec);
  261. /* Enable MII pins of the FEC1
  262. */
  263. setbits16(&immap->im_ioport.iop_pdpar, 0x0080);
  264. clrbits16(&immap->im_ioport.iop_pddir, 0x0080);
  265. /* Set MII speed to 2.5 MHz
  266. */
  267. out_be32(&fecp->fec_mii_speed,
  268. ((((bd->bi_intfreq + 4999999) / 2500000) / 2) & 0x3F) << 1);
  269. /* Enable FEC pin MUX
  270. */
  271. setbits32(&fecp->fec_ecntrl, MII_ECNTRL_PINMUX);
  272. setbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE);
  273. out_be32(&fecp->fec_mii_data,
  274. mk_mii_write(MII_BMCR, BMCR_ISOLATE, phy_addr));
  275. udelay(100);
  276. out_be32(&fecp->fec_mii_data,
  277. mk_mii_write(MII_ADVERTISE,
  278. ADVERTISE_10HALF | ADVERTISE_CSMA, phy_addr));
  279. udelay(100);
  280. /* Disable FEC MII settings
  281. */
  282. clrbits32(&fecp->fec_ecntrl, MII_ECNTRL_PINMUX);
  283. clrbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE);
  284. out_be32(&fecp->fec_mii_speed, 0);
  285. }
  286. static int mpc885ads_platform_notify(struct device *dev)
  287. {
  288. static const struct platform_notify_dev_map dev_map[] = {
  289. {
  290. .bus_id = "fsl-cpm-fec",
  291. .rtn = mpc885ads_fixup_fec_enet_pdata,
  292. },
  293. {
  294. .bus_id = "fsl-cpm-scc",
  295. .rtn = mpc885ads_fixup_scc_enet_pdata,
  296. },
  297. {
  298. .bus_id = NULL
  299. }
  300. };
  301. platform_notify_map(dev_map,dev);
  302. }
  303. int __init mpc885ads_init(void)
  304. {
  305. printk(KERN_NOTICE "mpc885ads: Init\n");
  306. platform_notify = mpc885ads_platform_notify;
  307. ppc_sys_device_initfunc();
  308. ppc_sys_device_disable_all();
  309. ppc_sys_device_enable(MPC8xx_CPM_FEC1);
  310. #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
  311. ppc_sys_device_enable(MPC8xx_CPM_SCC1);
  312. #endif
  313. #ifdef CONFIG_MPC8xx_SECOND_ETH_FEC2
  314. ppc_sys_device_enable(MPC8xx_CPM_FEC2);
  315. #endif
  316. return 0;
  317. }
  318. arch_initcall(mpc885ads_init);