mpc866ads_setup.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. #include <asm/mpc8xx.h>
  34. extern unsigned char __res[];
  35. static void setup_fec1_ioports(void);
  36. static void setup_scc1_ioports(void);
  37. static void setup_smc1_ioports(void);
  38. static void setup_smc2_ioports(void);
  39. static struct fs_mii_bus_info fec_mii_bus_info = {
  40. .method = fsmii_fec,
  41. .id = 0,
  42. };
  43. static struct fs_mii_bus_info scc_mii_bus_info = {
  44. .method = fsmii_fixed,
  45. .id = 0,
  46. .i.fixed.speed = 10,
  47. .i.fixed.duplex = 0,
  48. };
  49. static struct fs_platform_info mpc8xx_fec_pdata[] = {
  50. {
  51. .rx_ring = 128,
  52. .tx_ring = 16,
  53. .rx_copybreak = 240,
  54. .use_napi = 1,
  55. .napi_weight = 17,
  56. .phy_addr = 15,
  57. .phy_irq = -1,
  58. .use_rmii = 0,
  59. .bus_info = &fec_mii_bus_info,
  60. }
  61. };
  62. static struct fs_platform_info mpc8xx_scc_pdata = {
  63. .rx_ring = 64,
  64. .tx_ring = 8,
  65. .rx_copybreak = 240,
  66. .use_napi = 1,
  67. .napi_weight = 17,
  68. .phy_addr = -1,
  69. .phy_irq = -1,
  70. .bus_info = &scc_mii_bus_info,
  71. };
  72. static struct fs_uart_platform_info mpc866_uart_pdata[] = {
  73. [fsid_smc1_uart] = {
  74. .brg = 1,
  75. .fs_no = fsid_smc1_uart,
  76. .init_ioports = setup_smc1_ioports,
  77. .tx_num_fifo = 4,
  78. .tx_buf_size = 32,
  79. .rx_num_fifo = 4,
  80. .rx_buf_size = 32,
  81. },
  82. [fsid_smc2_uart] = {
  83. .brg = 2,
  84. .fs_no = fsid_smc2_uart,
  85. .init_ioports = setup_smc2_ioports,
  86. .tx_num_fifo = 4,
  87. .tx_buf_size = 32,
  88. .rx_num_fifo = 4,
  89. .rx_buf_size = 32,
  90. },
  91. };
  92. void __init board_init(void)
  93. {
  94. volatile cpm8xx_t *cp = cpmp;
  95. unsigned *bcsr_io;
  96. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  97. if (bcsr_io == NULL) {
  98. printk(KERN_CRIT "Could not remap BCSR1\n");
  99. return;
  100. }
  101. #ifdef CONFIG_SERIAL_CPM_SMC1
  102. cp->cp_simode &= ~(0xe0000000 >> 17); /* brg1 */
  103. clrbits32(bcsr_io,(0x80000000 >> 7));
  104. cp->cp_smc[0].smc_smcm |= (SMCM_RX | SMCM_TX);
  105. cp->cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  106. #else
  107. setbits32(bcsr_io,(0x80000000 >> 7));
  108. cp->cp_pbpar &= ~(0x000000c0);
  109. cp->cp_pbdir |= 0x000000c0;
  110. cp->cp_smc[0].smc_smcmr = 0;
  111. cp->cp_smc[0].smc_smce = 0;
  112. #endif
  113. #ifdef CONFIG_SERIAL_CPM_SMC2
  114. cp->cp_simode &= ~(0xe0000000 >> 1);
  115. cp->cp_simode |= (0x20000000 >> 1); /* brg2 */
  116. clrbits32(bcsr_io,(0x80000000 >> 13));
  117. cp->cp_smc[1].smc_smcm |= (SMCM_RX | SMCM_TX);
  118. cp->cp_smc[1].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  119. #else
  120. clrbits32(bcsr_io,(0x80000000 >> 13));
  121. cp->cp_pbpar &= ~(0x00000c00);
  122. cp->cp_pbdir |= 0x00000c00;
  123. cp->cp_smc[1].smc_smcmr = 0;
  124. cp->cp_smc[1].smc_smce = 0;
  125. #endif
  126. iounmap(bcsr_io);
  127. }
  128. static void setup_fec1_ioports(void)
  129. {
  130. immap_t *immap = (immap_t *) IMAP_ADDR;
  131. setbits16(&immap->im_ioport.iop_pdpar, 0x1fff);
  132. setbits16(&immap->im_ioport.iop_pddir, 0x1fff);
  133. }
  134. static void setup_scc1_ioports(void)
  135. {
  136. immap_t *immap = (immap_t *) IMAP_ADDR;
  137. unsigned *bcsr_io;
  138. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  139. if (bcsr_io == NULL) {
  140. printk(KERN_CRIT "Could not remap BCSR1\n");
  141. return;
  142. }
  143. /* Enable the PHY.
  144. */
  145. clrbits32(bcsr_io,BCSR1_ETHEN);
  146. /* Configure port A pins for Txd and Rxd.
  147. */
  148. /* Disable receive and transmit in case EPPC-Bug started it.
  149. */
  150. setbits16(&immap->im_ioport.iop_papar, PA_ENET_RXD | PA_ENET_TXD);
  151. clrbits16(&immap->im_ioport.iop_padir, PA_ENET_RXD | PA_ENET_TXD);
  152. clrbits16(&immap->im_ioport.iop_paodr, PA_ENET_TXD);
  153. /* Configure port C pins to enable CLSN and RENA.
  154. */
  155. clrbits16(&immap->im_ioport.iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
  156. clrbits16(&immap->im_ioport.iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
  157. setbits16(&immap->im_ioport.iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
  158. /* Configure port A for TCLK and RCLK.
  159. */
  160. setbits16(&immap->im_ioport.iop_papar, PA_ENET_TCLK | PA_ENET_RCLK);
  161. clrbits16(&immap->im_ioport.iop_padir, PA_ENET_TCLK | PA_ENET_RCLK);
  162. clrbits32(&immap->im_cpm.cp_pbpar, PB_ENET_TENA);
  163. clrbits32(&immap->im_cpm.cp_pbdir, PB_ENET_TENA);
  164. /* Configure Serial Interface clock routing.
  165. * First, clear all SCC bits to zero, then set the ones we want.
  166. */
  167. clrbits32(&immap->im_cpm.cp_sicr, SICR_ENET_MASK);
  168. setbits32(&immap->im_cpm.cp_sicr, SICR_ENET_CLKRT);
  169. /* In the original SCC enet driver the following code is placed at
  170. the end of the initialization */
  171. setbits32(&immap->im_cpm.cp_pbpar, PB_ENET_TENA);
  172. setbits32(&immap->im_cpm.cp_pbdir, PB_ENET_TENA);
  173. }
  174. static void mpc866ads_fixup_enet_pdata(struct platform_device *pdev, int fs_no)
  175. {
  176. struct fs_platform_info *fpi = pdev->dev.platform_data;
  177. volatile cpm8xx_t *cp;
  178. bd_t *bd = (bd_t *) __res;
  179. char *e;
  180. int i;
  181. /* Get pointer to Communication Processor */
  182. cp = cpmp;
  183. switch (fs_no) {
  184. case fsid_fec1:
  185. fpi = &mpc8xx_fec_pdata[0];
  186. fpi->init_ioports = &setup_fec1_ioports;
  187. break;
  188. case fsid_scc1:
  189. fpi = &mpc8xx_scc_pdata;
  190. fpi->init_ioports = &setup_scc1_ioports;
  191. break;
  192. default:
  193. printk(KERN_WARNING"Device %s is not supported!\n", pdev->name);
  194. return;
  195. }
  196. pdev->dev.platform_data = fpi;
  197. fpi->fs_no = fs_no;
  198. e = (unsigned char *)&bd->bi_enetaddr;
  199. for (i = 0; i < 6; i++)
  200. fpi->macaddr[i] = *e++;
  201. fpi->macaddr[5 - pdev->id]++;
  202. }
  203. static void mpc866ads_fixup_fec_enet_pdata(struct platform_device *pdev,
  204. int idx)
  205. {
  206. /* This is for FEC devices only */
  207. if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-fec")))
  208. return;
  209. mpc866ads_fixup_enet_pdata(pdev, fsid_fec1 + pdev->id - 1);
  210. }
  211. static void mpc866ads_fixup_scc_enet_pdata(struct platform_device *pdev,
  212. int idx)
  213. {
  214. /* This is for SCC devices only */
  215. if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-scc")))
  216. return;
  217. mpc866ads_fixup_enet_pdata(pdev, fsid_scc1 + pdev->id - 1);
  218. }
  219. static void setup_smc1_ioports(void)
  220. {
  221. immap_t *immap = (immap_t *) IMAP_ADDR;
  222. unsigned *bcsr_io;
  223. unsigned int iobits = 0x000000c0;
  224. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  225. if (bcsr_io == NULL) {
  226. printk(KERN_CRIT "Could not remap BCSR1\n");
  227. return;
  228. }
  229. clrbits32(bcsr_io,BCSR1_RS232EN_1);
  230. iounmap(bcsr_io);
  231. setbits32(&immap->im_cpm.cp_pbpar, iobits);
  232. clrbits32(&immap->im_cpm.cp_pbdir, iobits);
  233. clrbits16(&immap->im_cpm.cp_pbodr, iobits);
  234. }
  235. static void setup_smc2_ioports(void)
  236. {
  237. immap_t *immap = (immap_t *) IMAP_ADDR;
  238. unsigned *bcsr_io;
  239. unsigned int iobits = 0x00000c00;
  240. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  241. if (bcsr_io == NULL) {
  242. printk(KERN_CRIT "Could not remap BCSR1\n");
  243. return;
  244. }
  245. clrbits32(bcsr_io,BCSR1_RS232EN_2);
  246. iounmap(bcsr_io);
  247. #ifndef CONFIG_SERIAL_CPM_ALT_SMC2
  248. setbits32(&immap->im_cpm.cp_pbpar, iobits);
  249. clrbits32(&immap->im_cpm.cp_pbdir, iobits);
  250. clrbits16(&immap->im_cpm.cp_pbodr, iobits);
  251. #else
  252. setbits16(&immap->im_ioport.iop_papar, iobits);
  253. clrbits16(&immap->im_ioport.iop_padir, iobits);
  254. clrbits16(&immap->im_ioport.iop_paodr, iobits);
  255. #endif
  256. }
  257. static void __init mpc866ads_fixup_uart_pdata(struct platform_device *pdev,
  258. int idx)
  259. {
  260. bd_t *bd = (bd_t *) __res;
  261. struct fs_uart_platform_info *pinfo;
  262. int num = ARRAY_SIZE(mpc866_uart_pdata);
  263. int id = fs_uart_id_smc2fsid(idx);
  264. /* no need to alter anything if console */
  265. if ((id <= num) && (!pdev->dev.platform_data)) {
  266. pinfo = &mpc866_uart_pdata[id];
  267. pinfo->uart_clk = bd->bi_intfreq;
  268. pdev->dev.platform_data = pinfo;
  269. }
  270. }
  271. static int mpc866ads_platform_notify(struct device *dev)
  272. {
  273. static const struct platform_notify_dev_map dev_map[] = {
  274. {
  275. .bus_id = "fsl-cpm-fec",
  276. .rtn = mpc866ads_fixup_fec_enet_pdata,
  277. },
  278. {
  279. .bus_id = "fsl-cpm-scc",
  280. .rtn = mpc866ads_fixup_scc_enet_pdata,
  281. },
  282. {
  283. .bus_id = "fsl-cpm-smc:uart",
  284. .rtn = mpc866ads_fixup_uart_pdata
  285. },
  286. {
  287. .bus_id = NULL
  288. }
  289. };
  290. platform_notify_map(dev_map,dev);
  291. return 0;
  292. }
  293. int __init mpc866ads_init(void)
  294. {
  295. printk(KERN_NOTICE "mpc866ads: Init\n");
  296. platform_notify = mpc866ads_platform_notify;
  297. ppc_sys_device_initfunc();
  298. ppc_sys_device_disable_all();
  299. #ifdef MPC8xx_SECOND_ETH_SCC1
  300. ppc_sys_device_enable(MPC8xx_CPM_SCC1);
  301. #endif
  302. ppc_sys_device_enable(MPC8xx_CPM_FEC1);
  303. /* Since either of the uarts could be used as console, they need to ready */
  304. #ifdef CONFIG_SERIAL_CPM_SMC1
  305. ppc_sys_device_enable(MPC8xx_CPM_SMC1);
  306. ppc_sys_device_setfunc(MPC8xx_CPM_SMC1, PPC_SYS_FUNC_UART);
  307. #endif
  308. #ifdef CONFIG_SERIAL_CPM_SMC
  309. ppc_sys_device_enable(MPC8xx_CPM_SMC2);
  310. ppc_sys_device_setfunc(MPC8xx_CPM_SMC2, PPC_SYS_FUNC_UART);
  311. #endif
  312. return 0;
  313. }
  314. /*
  315. To prevent confusion, console selection is gross:
  316. by 0 assumed SMC1 and by 1 assumed SMC2
  317. */
  318. struct platform_device* early_uart_get_pdev(int index)
  319. {
  320. bd_t *bd = (bd_t *) __res;
  321. struct fs_uart_platform_info *pinfo;
  322. struct platform_device* pdev = NULL;
  323. if(index) { /*assume SMC2 here*/
  324. pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC2];
  325. pinfo = &mpc866_uart_pdata[1];
  326. } else { /*over SMC1*/
  327. pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC1];
  328. pinfo = &mpc866_uart_pdata[0];
  329. }
  330. pinfo->uart_clk = bd->bi_intfreq;
  331. pdev->dev.platform_data = pinfo;
  332. ppc_sys_fixup_mem_resource(pdev, IMAP_ADDR);
  333. return NULL;
  334. }
  335. arch_initcall(mpc866ads_init);