mpc885ads_setup.c 13 KB

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