mpc866ads_setup.c 9.5 KB

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