mpc885ads_setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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/fs_uart_pd.h>
  22. #include <linux/mii.h>
  23. #include <asm/delay.h>
  24. #include <asm/io.h>
  25. #include <asm/machdep.h>
  26. #include <asm/page.h>
  27. #include <asm/processor.h>
  28. #include <asm/system.h>
  29. #include <asm/time.h>
  30. #include <asm/ppcboot.h>
  31. #include <asm/8xx_immap.h>
  32. #include <asm/commproc.h>
  33. #include <asm/ppc_sys.h>
  34. extern unsigned char __res[];
  35. static void setup_smc1_ioports(void);
  36. static void setup_smc2_ioports(void);
  37. static void __init mpc885ads_scc_phy_init(char);
  38. static struct fs_uart_platform_info mpc885_uart_pdata[] = {
  39. [fsid_smc1_uart] = {
  40. .brg = 1,
  41. .fs_no = fsid_smc1_uart,
  42. .init_ioports = setup_smc1_ioports,
  43. .tx_num_fifo = 4,
  44. .tx_buf_size = 32,
  45. .rx_num_fifo = 4,
  46. .rx_buf_size = 32,
  47. },
  48. [fsid_smc2_uart] = {
  49. .brg = 2,
  50. .fs_no = fsid_smc2_uart,
  51. .init_ioports = setup_smc2_ioports,
  52. .tx_num_fifo = 4,
  53. .tx_buf_size = 32,
  54. .rx_num_fifo = 4,
  55. .rx_buf_size = 32,
  56. },
  57. };
  58. static struct fs_mii_bus_info fec_mii_bus_info = {
  59. .method = fsmii_fec,
  60. .id = 0,
  61. };
  62. static struct fs_mii_bus_info scc_mii_bus_info = {
  63. #ifdef CONFIG_SCC_ENET_8xx_FIXED
  64. .method = fsmii_fixed,
  65. #else
  66. .method = fsmii_fec,
  67. #endif
  68. .id = 0,
  69. };
  70. static struct fs_platform_info mpc8xx_fec_pdata[] = {
  71. {
  72. .rx_ring = 128,
  73. .tx_ring = 16,
  74. .rx_copybreak = 240,
  75. .use_napi = 1,
  76. .napi_weight = 17,
  77. .phy_addr = 0,
  78. .phy_irq = SIU_IRQ7,
  79. .bus_info = &fec_mii_bus_info,
  80. }, {
  81. .rx_ring = 128,
  82. .tx_ring = 16,
  83. .rx_copybreak = 240,
  84. .use_napi = 1,
  85. .napi_weight = 17,
  86. .phy_addr = 1,
  87. .phy_irq = SIU_IRQ7,
  88. .bus_info = &fec_mii_bus_info,
  89. }
  90. };
  91. static struct fs_platform_info mpc8xx_scc_pdata = {
  92. .rx_ring = 64,
  93. .tx_ring = 8,
  94. .rx_copybreak = 240,
  95. .use_napi = 1,
  96. .napi_weight = 17,
  97. .phy_addr = 2,
  98. #ifdef CONFIG_MPC8xx_SCC_ENET_FIXED
  99. .phy_irq = -1,
  100. #else
  101. .phy_irq = SIU_IRQ7,
  102. #endif
  103. .bus_info = &scc_mii_bus_info,
  104. };
  105. void __init board_init(void)
  106. {
  107. volatile cpm8xx_t *cp = cpmp;
  108. unsigned int *bcsr_io;
  109. #ifdef CONFIG_FS_ENET
  110. immap_t *immap = (immap_t *) IMAP_ADDR;
  111. #endif
  112. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  113. if (bcsr_io == NULL) {
  114. printk(KERN_CRIT "Could not remap BCSR\n");
  115. return;
  116. }
  117. #ifdef CONFIG_SERIAL_CPM_SMC1
  118. cp->cp_simode &= ~(0xe0000000 >> 17); /* brg1 */
  119. clrbits32(bcsr_io, BCSR1_RS232EN_1);
  120. cp->cp_smc[0].smc_smcm |= (SMCM_RX | SMCM_TX);
  121. cp->cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  122. #else
  123. setbits32(bcsr_io,BCSR1_RS232EN_1);
  124. cp->cp_smc[0].smc_smcmr = 0;
  125. cp->cp_smc[0].smc_smce = 0;
  126. #endif
  127. #ifdef CONFIG_SERIAL_CPM_SMC2
  128. cp->cp_simode &= ~(0xe0000000 >> 1);
  129. cp->cp_simode |= (0x20000000 >> 1); /* brg2 */
  130. clrbits32(bcsr_io,BCSR1_RS232EN_2);
  131. cp->cp_smc[1].smc_smcm |= (SMCM_RX | SMCM_TX);
  132. cp->cp_smc[1].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  133. #else
  134. setbits32(bcsr_io,BCSR1_RS232EN_2);
  135. cp->cp_smc[1].smc_smcmr = 0;
  136. cp->cp_smc[1].smc_smce = 0;
  137. #endif
  138. iounmap(bcsr_io);
  139. #ifdef CONFIG_FS_ENET
  140. /* use MDC for MII (common) */
  141. setbits16(&immap->im_ioport.iop_pdpar, 0x0080);
  142. clrbits16(&immap->im_ioport.iop_pddir, 0x0080);
  143. #endif
  144. }
  145. static void setup_fec1_ioports(void)
  146. {
  147. immap_t *immap = (immap_t *) IMAP_ADDR;
  148. /* configure FEC1 pins */
  149. setbits16(&immap->im_ioport.iop_papar, 0xf830);
  150. setbits16(&immap->im_ioport.iop_padir, 0x0830);
  151. clrbits16(&immap->im_ioport.iop_padir, 0xf000);
  152. setbits32(&immap->im_cpm.cp_pbpar, 0x00001001);
  153. clrbits32(&immap->im_cpm.cp_pbdir, 0x00001001);
  154. setbits16(&immap->im_ioport.iop_pcpar, 0x000c);
  155. clrbits16(&immap->im_ioport.iop_pcdir, 0x000c);
  156. setbits32(&immap->im_cpm.cp_pepar, 0x00000003);
  157. setbits32(&immap->im_cpm.cp_pedir, 0x00000003);
  158. clrbits32(&immap->im_cpm.cp_peso, 0x00000003);
  159. clrbits32(&immap->im_cpm.cp_cptr, 0x00000100);
  160. }
  161. static void setup_fec2_ioports(void)
  162. {
  163. immap_t *immap = (immap_t *) IMAP_ADDR;
  164. /* configure FEC2 pins */
  165. setbits32(&immap->im_cpm.cp_pepar, 0x0003fffc);
  166. setbits32(&immap->im_cpm.cp_pedir, 0x0003fffc);
  167. setbits32(&immap->im_cpm.cp_peso, 0x00037800);
  168. clrbits32(&immap->im_cpm.cp_peso, 0x000087fc);
  169. clrbits32(&immap->im_cpm.cp_cptr, 0x00000080);
  170. }
  171. static void setup_scc3_ioports(void)
  172. {
  173. immap_t *immap = (immap_t *) IMAP_ADDR;
  174. unsigned *bcsr_io;
  175. bcsr_io = ioremap(BCSR_ADDR, BCSR_SIZE);
  176. if (bcsr_io == NULL) {
  177. printk(KERN_CRIT "Could not remap BCSR\n");
  178. return;
  179. }
  180. /* Enable the PHY.
  181. */
  182. setbits32(bcsr_io+4, BCSR4_ETH10_RST);
  183. /* Configure port A pins for Txd and Rxd.
  184. */
  185. setbits16(&immap->im_ioport.iop_papar, PA_ENET_RXD | PA_ENET_TXD);
  186. clrbits16(&immap->im_ioport.iop_padir, PA_ENET_RXD | PA_ENET_TXD);
  187. /* Configure port C pins to enable CLSN and RENA.
  188. */
  189. clrbits16(&immap->im_ioport.iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
  190. clrbits16(&immap->im_ioport.iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
  191. setbits16(&immap->im_ioport.iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
  192. /* Configure port E for TCLK and RCLK.
  193. */
  194. setbits32(&immap->im_cpm.cp_pepar, PE_ENET_TCLK | PE_ENET_RCLK);
  195. clrbits32(&immap->im_cpm.cp_pepar, PE_ENET_TENA);
  196. clrbits32(&immap->im_cpm.cp_pedir,
  197. PE_ENET_TCLK | PE_ENET_RCLK | PE_ENET_TENA);
  198. clrbits32(&immap->im_cpm.cp_peso, PE_ENET_TCLK | PE_ENET_RCLK);
  199. setbits32(&immap->im_cpm.cp_peso, PE_ENET_TENA);
  200. /* Configure Serial Interface clock routing.
  201. * First, clear all SCC bits to zero, then set the ones we want.
  202. */
  203. clrbits32(&immap->im_cpm.cp_sicr, SICR_ENET_MASK);
  204. setbits32(&immap->im_cpm.cp_sicr, SICR_ENET_CLKRT);
  205. /* Disable Rx and Tx. SMC1 sshould be stopped if SCC3 eternet are used.
  206. */
  207. immap->im_cpm.cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  208. /* On the MPC885ADS SCC ethernet PHY is initialized in the full duplex mode
  209. * by H/W setting after reset. SCC ethernet controller support only half duplex.
  210. * This discrepancy of modes causes a lot of carrier lost errors.
  211. */
  212. /* In the original SCC enet driver the following code is placed at
  213. the end of the initialization */
  214. setbits32(&immap->im_cpm.cp_pepar, PE_ENET_TENA);
  215. clrbits32(&immap->im_cpm.cp_pedir, PE_ENET_TENA);
  216. setbits32(&immap->im_cpm.cp_peso, PE_ENET_TENA);
  217. setbits32(bcsr_io+1, BCSR1_ETHEN);
  218. iounmap(bcsr_io);
  219. }
  220. static void mpc885ads_fixup_enet_pdata(struct platform_device *pdev, int fs_no)
  221. {
  222. struct fs_platform_info *fpi = pdev->dev.platform_data;
  223. volatile cpm8xx_t *cp;
  224. bd_t *bd = (bd_t *) __res;
  225. char *e;
  226. int i;
  227. /* Get pointer to Communication Processor */
  228. cp = cpmp;
  229. switch (fs_no) {
  230. case fsid_fec1:
  231. fpi = &mpc8xx_fec_pdata[0];
  232. fpi->init_ioports = &setup_fec1_ioports;
  233. break;
  234. case fsid_fec2:
  235. fpi = &mpc8xx_fec_pdata[1];
  236. fpi->init_ioports = &setup_fec2_ioports;
  237. break;
  238. case fsid_scc3:
  239. fpi = &mpc8xx_scc_pdata;
  240. fpi->init_ioports = &setup_scc3_ioports;
  241. mpc885ads_scc_phy_init(fpi->phy_addr);
  242. break;
  243. default:
  244. printk(KERN_WARNING"Device %s is not supported!\n", pdev->name);
  245. return;
  246. }
  247. pdev->dev.platform_data = fpi;
  248. fpi->fs_no = fs_no;
  249. e = (unsigned char *)&bd->bi_enetaddr;
  250. for (i = 0; i < 6; i++)
  251. fpi->macaddr[i] = *e++;
  252. fpi->macaddr[5 - pdev->id]++;
  253. }
  254. static void mpc885ads_fixup_fec_enet_pdata(struct platform_device *pdev,
  255. int idx)
  256. {
  257. /* This is for FEC devices only */
  258. if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-fec")))
  259. return;
  260. mpc885ads_fixup_enet_pdata(pdev, fsid_fec1 + pdev->id - 1);
  261. }
  262. static void __init mpc885ads_fixup_scc_enet_pdata(struct platform_device *pdev,
  263. int idx)
  264. {
  265. /* This is for SCC devices only */
  266. if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-scc")))
  267. return;
  268. mpc885ads_fixup_enet_pdata(pdev, fsid_scc1 + pdev->id - 1);
  269. }
  270. /* SCC ethernet controller does not have MII management channel. FEC1 MII
  271. * channel is used to communicate with the 10Mbit PHY.
  272. */
  273. #define MII_ECNTRL_PINMUX 0x4
  274. #define FEC_ECNTRL_PINMUX 0x00000004
  275. #define FEC_RCNTRL_MII_MODE 0x00000004
  276. /* Make MII read/write commands.
  277. */
  278. #define mk_mii_write(REG, VAL, PHY_ADDR) (0x50020000 | (((REG) & 0x1f) << 18) | \
  279. ((VAL) & 0xffff) | ((PHY_ADDR) << 23))
  280. static void mpc885ads_scc_phy_init(char phy_addr)
  281. {
  282. volatile immap_t *immap;
  283. volatile fec_t *fecp;
  284. bd_t *bd;
  285. bd = (bd_t *) __res;
  286. immap = (immap_t *) IMAP_ADDR; /* pointer to internal registers */
  287. fecp = &(immap->im_cpm.cp_fec);
  288. /* Enable MII pins of the FEC1
  289. */
  290. setbits16(&immap->im_ioport.iop_pdpar, 0x0080);
  291. clrbits16(&immap->im_ioport.iop_pddir, 0x0080);
  292. /* Set MII speed to 2.5 MHz
  293. */
  294. out_be32(&fecp->fec_mii_speed,
  295. ((((bd->bi_intfreq + 4999999) / 2500000) / 2) & 0x3F) << 1);
  296. /* Enable FEC pin MUX
  297. */
  298. setbits32(&fecp->fec_ecntrl, MII_ECNTRL_PINMUX);
  299. setbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE);
  300. out_be32(&fecp->fec_mii_data,
  301. mk_mii_write(MII_BMCR, BMCR_ISOLATE, phy_addr));
  302. udelay(100);
  303. out_be32(&fecp->fec_mii_data,
  304. mk_mii_write(MII_ADVERTISE,
  305. ADVERTISE_10HALF | ADVERTISE_CSMA, phy_addr));
  306. udelay(100);
  307. /* Disable FEC MII settings
  308. */
  309. clrbits32(&fecp->fec_ecntrl, MII_ECNTRL_PINMUX);
  310. clrbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE);
  311. out_be32(&fecp->fec_mii_speed, 0);
  312. }
  313. static void setup_smc1_ioports(void)
  314. {
  315. immap_t *immap = (immap_t *) IMAP_ADDR;
  316. unsigned *bcsr_io;
  317. unsigned int iobits = 0x000000c0;
  318. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  319. if (bcsr_io == NULL) {
  320. printk(KERN_CRIT "Could not remap BCSR1\n");
  321. return;
  322. }
  323. clrbits32(bcsr_io,BCSR1_RS232EN_1);
  324. iounmap(bcsr_io);
  325. setbits32(&immap->im_cpm.cp_pbpar, iobits);
  326. clrbits32(&immap->im_cpm.cp_pbdir, iobits);
  327. clrbits16(&immap->im_cpm.cp_pbodr, iobits);
  328. }
  329. static void setup_smc2_ioports(void)
  330. {
  331. immap_t *immap = (immap_t *) IMAP_ADDR;
  332. unsigned *bcsr_io;
  333. unsigned int iobits = 0x00000c00;
  334. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  335. if (bcsr_io == NULL) {
  336. printk(KERN_CRIT "Could not remap BCSR1\n");
  337. return;
  338. }
  339. clrbits32(bcsr_io,BCSR1_RS232EN_2);
  340. iounmap(bcsr_io);
  341. #ifndef CONFIG_SERIAL_CPM_ALT_SMC2
  342. setbits32(&immap->im_cpm.cp_pbpar, iobits);
  343. clrbits32(&immap->im_cpm.cp_pbdir, iobits);
  344. clrbits16(&immap->im_cpm.cp_pbodr, iobits);
  345. #else
  346. setbits16(&immap->im_ioport.iop_papar, iobits);
  347. clrbits16(&immap->im_ioport.iop_padir, iobits);
  348. clrbits16(&immap->im_ioport.iop_paodr, iobits);
  349. #endif
  350. }
  351. static void __init mpc885ads_fixup_uart_pdata(struct platform_device *pdev,
  352. int idx)
  353. {
  354. bd_t *bd = (bd_t *) __res;
  355. struct fs_uart_platform_info *pinfo;
  356. int num = ARRAY_SIZE(mpc885_uart_pdata);
  357. int id = fs_uart_id_smc2fsid(idx);
  358. /* no need to alter anything if console */
  359. if ((id <= num) && (!pdev->dev.platform_data)) {
  360. pinfo = &mpc885_uart_pdata[id];
  361. pinfo->uart_clk = bd->bi_intfreq;
  362. pdev->dev.platform_data = pinfo;
  363. }
  364. }
  365. static int mpc885ads_platform_notify(struct device *dev)
  366. {
  367. static const struct platform_notify_dev_map dev_map[] = {
  368. {
  369. .bus_id = "fsl-cpm-fec",
  370. .rtn = mpc885ads_fixup_fec_enet_pdata,
  371. },
  372. {
  373. .bus_id = "fsl-cpm-scc",
  374. .rtn = mpc885ads_fixup_scc_enet_pdata,
  375. },
  376. {
  377. .bus_id = "fsl-cpm-smc:uart",
  378. .rtn = mpc885ads_fixup_uart_pdata
  379. },
  380. {
  381. .bus_id = NULL
  382. }
  383. };
  384. platform_notify_map(dev_map,dev);
  385. return 0;
  386. }
  387. int __init mpc885ads_init(void)
  388. {
  389. printk(KERN_NOTICE "mpc885ads: Init\n");
  390. platform_notify = mpc885ads_platform_notify;
  391. ppc_sys_device_initfunc();
  392. ppc_sys_device_disable_all();
  393. ppc_sys_device_enable(MPC8xx_CPM_FEC1);
  394. #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
  395. ppc_sys_device_enable(MPC8xx_CPM_SCC1);
  396. #endif
  397. #ifdef CONFIG_MPC8xx_SECOND_ETH_FEC2
  398. ppc_sys_device_enable(MPC8xx_CPM_FEC2);
  399. #endif
  400. #ifdef CONFIG_SERIAL_CPM_SMC1
  401. ppc_sys_device_enable(MPC8xx_CPM_SMC1);
  402. ppc_sys_device_setfunc(MPC8xx_CPM_SMC1, PPC_SYS_FUNC_UART);
  403. #endif
  404. #ifdef CONFIG_SERIAL_CPM_SMC2
  405. ppc_sys_device_enable(MPC8xx_CPM_SMC2);
  406. ppc_sys_device_setfunc(MPC8xx_CPM_SMC2, PPC_SYS_FUNC_UART);
  407. #endif
  408. return 0;
  409. }
  410. arch_initcall(mpc885ads_init);
  411. /*
  412. To prevent confusion, console selection is gross:
  413. by 0 assumed SMC1 and by 1 assumed SMC2
  414. */
  415. struct platform_device* early_uart_get_pdev(int index)
  416. {
  417. bd_t *bd = (bd_t *) __res;
  418. struct fs_uart_platform_info *pinfo;
  419. struct platform_device* pdev = NULL;
  420. if(index) { /*assume SMC2 here*/
  421. pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC2];
  422. pinfo = &mpc885_uart_pdata[1];
  423. } else { /*over SMC1*/
  424. pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC1];
  425. pinfo = &mpc885_uart_pdata[0];
  426. }
  427. pinfo->uart_clk = bd->bi_intfreq;
  428. pdev->dev.platform_data = pinfo;
  429. ppc_sys_fixup_mem_resource(pdev, IMAP_ADDR);
  430. return NULL;
  431. }