mpc8272ads_setup.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * arch/ppc/platforms/82xx/pq2ads_pd.c
  3. *
  4. * MPC82xx Board-specific PlatformDevice descriptions
  5. *
  6. * 2005 (c) MontaVista Software, Inc.
  7. * Vitaly Bordug <vbordug@ru.mvista.com>
  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/device.h>
  16. #include <linux/ioport.h>
  17. #include <linux/fs_enet_pd.h>
  18. #include <linux/platform_device.h>
  19. #include <asm/io.h>
  20. #include <asm/mpc8260.h>
  21. #include <asm/cpm2.h>
  22. #include <asm/immap_cpm2.h>
  23. #include <asm/irq.h>
  24. #include <asm/ppc_sys.h>
  25. #include <asm/ppcboot.h>
  26. #include <linux/fs_uart_pd.h>
  27. #include "pq2ads_pd.h"
  28. static void init_fcc1_ioports(void);
  29. static void init_fcc2_ioports(void);
  30. static void init_scc1_uart_ioports(void);
  31. static void init_scc4_uart_ioports(void);
  32. static struct fs_uart_platform_info mpc8272_uart_pdata[] = {
  33. [fsid_scc1_uart] = {
  34. .init_ioports = init_scc1_uart_ioports,
  35. .fs_no = fsid_scc1_uart,
  36. .brg = 1,
  37. .tx_num_fifo = 4,
  38. .tx_buf_size = 32,
  39. .rx_num_fifo = 4,
  40. .rx_buf_size = 32,
  41. },
  42. [fsid_scc4_uart] = {
  43. .init_ioports = init_scc4_uart_ioports,
  44. .fs_no = fsid_scc4_uart,
  45. .brg = 4,
  46. .tx_num_fifo = 4,
  47. .tx_buf_size = 32,
  48. .rx_num_fifo = 4,
  49. .rx_buf_size = 32,
  50. },
  51. };
  52. static struct fs_mii_bus_info mii_bus_info = {
  53. .method = fsmii_bitbang,
  54. .id = 0,
  55. .i.bitbang = {
  56. .mdio_port = fsiop_portc,
  57. .mdio_bit = 18,
  58. .mdc_port = fsiop_portc,
  59. .mdc_bit = 19,
  60. .delay = 1,
  61. },
  62. };
  63. static struct fs_platform_info mpc82xx_fcc1_pdata = {
  64. .fs_no = fsid_fcc1,
  65. .cp_page = CPM_CR_FCC1_PAGE,
  66. .cp_block = CPM_CR_FCC1_SBLOCK,
  67. .clk_trx = (PC_F1RXCLK | PC_F1TXCLK),
  68. .clk_route = CMX1_CLK_ROUTE,
  69. .clk_mask = CMX1_CLK_MASK,
  70. .init_ioports = init_fcc1_ioports,
  71. .phy_addr = 0,
  72. #ifdef PHY_INTERRUPT
  73. .phy_irq = PHY_INTERRUPT,
  74. #else
  75. .phy_irq = -1;
  76. #endif
  77. .mem_offset = FCC1_MEM_OFFSET,
  78. .bus_info = &mii_bus_info,
  79. .rx_ring = 32,
  80. .tx_ring = 32,
  81. .rx_copybreak = 240,
  82. .use_napi = 0,
  83. .napi_weight = 17,
  84. };
  85. static struct fs_platform_info mpc82xx_fcc2_pdata = {
  86. .fs_no = fsid_fcc2,
  87. .cp_page = CPM_CR_FCC2_PAGE,
  88. .cp_block = CPM_CR_FCC2_SBLOCK,
  89. .clk_trx = (PC_F2RXCLK | PC_F2TXCLK),
  90. .clk_route = CMX2_CLK_ROUTE,
  91. .clk_mask = CMX2_CLK_MASK,
  92. .init_ioports = init_fcc2_ioports,
  93. .phy_addr = 3,
  94. #ifdef PHY_INTERRUPT
  95. .phy_irq = PHY_INTERRUPT,
  96. #else
  97. .phy_irq = -1;
  98. #endif
  99. .mem_offset = FCC2_MEM_OFFSET,
  100. .bus_info = &mii_bus_info,
  101. .rx_ring = 32,
  102. .tx_ring = 32,
  103. .rx_copybreak = 240,
  104. .use_napi = 0,
  105. .napi_weight = 17,
  106. };
  107. static void init_fcc1_ioports(void)
  108. {
  109. struct io_port *io;
  110. u32 tempval;
  111. cpm2_map_t* immap = ioremap(CPM_MAP_ADDR, sizeof(cpm2_map_t));
  112. u32 *bcsr = ioremap(BCSR_ADDR+4, sizeof(u32));
  113. io = &immap->im_ioport;
  114. /* Enable the PHY */
  115. clrbits32(bcsr, BCSR1_FETHIEN);
  116. setbits32(bcsr, BCSR1_FETH_RST);
  117. /* FCC1 pins are on port A/C. */
  118. /* Configure port A and C pins for FCC1 Ethernet. */
  119. tempval = in_be32(&io->iop_pdira);
  120. tempval &= ~PA1_DIRA0;
  121. tempval |= PA1_DIRA1;
  122. out_be32(&io->iop_pdira, tempval);
  123. tempval = in_be32(&io->iop_psora);
  124. tempval &= ~PA1_PSORA0;
  125. tempval |= PA1_PSORA1;
  126. out_be32(&io->iop_psora, tempval);
  127. setbits32(&io->iop_ppara,PA1_DIRA0 | PA1_DIRA1);
  128. /* Alter clocks */
  129. tempval = PC_F1TXCLK|PC_F1RXCLK;
  130. clrbits32(&io->iop_psorc, tempval);
  131. clrbits32(&io->iop_pdirc, tempval);
  132. setbits32(&io->iop_pparc, tempval);
  133. clrbits32(&immap->im_cpmux.cmx_fcr, CMX1_CLK_MASK);
  134. setbits32(&immap->im_cpmux.cmx_fcr, CMX1_CLK_ROUTE);
  135. iounmap(bcsr);
  136. iounmap(immap);
  137. }
  138. static void init_fcc2_ioports(void)
  139. {
  140. cpm2_map_t* immap = ioremap(CPM_MAP_ADDR, sizeof(cpm2_map_t));
  141. u32 *bcsr = ioremap(BCSR_ADDR+12, sizeof(u32));
  142. struct io_port *io;
  143. u32 tempval;
  144. immap = cpm2_immr;
  145. io = &immap->im_ioport;
  146. /* Enable the PHY */
  147. clrbits32(bcsr, BCSR3_FETHIEN2);
  148. setbits32(bcsr, BCSR3_FETH2_RST);
  149. /* FCC2 are port B/C. */
  150. /* Configure port A and C pins for FCC2 Ethernet. */
  151. tempval = in_be32(&io->iop_pdirb);
  152. tempval &= ~PB2_DIRB0;
  153. tempval |= PB2_DIRB1;
  154. out_be32(&io->iop_pdirb, tempval);
  155. tempval = in_be32(&io->iop_psorb);
  156. tempval &= ~PB2_PSORB0;
  157. tempval |= PB2_PSORB1;
  158. out_be32(&io->iop_psorb, tempval);
  159. setbits32(&io->iop_pparb,PB2_DIRB0 | PB2_DIRB1);
  160. tempval = PC_F2RXCLK|PC_F2TXCLK;
  161. /* Alter clocks */
  162. clrbits32(&io->iop_psorc,tempval);
  163. clrbits32(&io->iop_pdirc,tempval);
  164. setbits32(&io->iop_pparc,tempval);
  165. clrbits32(&immap->im_cpmux.cmx_fcr, CMX2_CLK_MASK);
  166. setbits32(&immap->im_cpmux.cmx_fcr, CMX2_CLK_ROUTE);
  167. iounmap(bcsr);
  168. iounmap(immap);
  169. }
  170. static void __init mpc8272ads_fixup_enet_pdata(struct platform_device *pdev,
  171. int idx)
  172. {
  173. bd_t* bi = (void*)__res;
  174. int fs_no = fsid_fcc1+pdev->id-1;
  175. mpc82xx_fcc1_pdata.dpram_offset = mpc82xx_fcc2_pdata.dpram_offset = (u32)cpm2_immr->im_dprambase;
  176. mpc82xx_fcc1_pdata.fcc_regs_c = mpc82xx_fcc2_pdata.fcc_regs_c = (u32)cpm2_immr->im_fcc_c;
  177. switch(fs_no) {
  178. case fsid_fcc1:
  179. memcpy(&mpc82xx_fcc1_pdata.macaddr,bi->bi_enetaddr,6);
  180. pdev->dev.platform_data = &mpc82xx_fcc1_pdata;
  181. break;
  182. case fsid_fcc2:
  183. memcpy(&mpc82xx_fcc2_pdata.macaddr,bi->bi_enetaddr,6);
  184. mpc82xx_fcc2_pdata.macaddr[5] ^= 1;
  185. pdev->dev.platform_data = &mpc82xx_fcc2_pdata;
  186. break;
  187. }
  188. }
  189. static void mpc8272ads_fixup_uart_pdata(struct platform_device *pdev,
  190. int idx)
  191. {
  192. bd_t *bd = (bd_t *) __res;
  193. struct fs_uart_platform_info *pinfo;
  194. int num = ARRAY_SIZE(mpc8272_uart_pdata);
  195. int id = fs_uart_id_scc2fsid(idx);
  196. /* no need to alter anything if console */
  197. if ((id <= num) && (!pdev->dev.platform_data)) {
  198. pinfo = &mpc8272_uart_pdata[id];
  199. pinfo->uart_clk = bd->bi_intfreq;
  200. pdev->dev.platform_data = pinfo;
  201. }
  202. }
  203. static void init_scc1_uart_ioports(void)
  204. {
  205. cpm2_map_t* immap = ioremap(CPM_MAP_ADDR, sizeof(cpm2_map_t));
  206. /* SCC1 is only on port D */
  207. setbits32(&immap->im_ioport.iop_ppard,0x00000003);
  208. clrbits32(&immap->im_ioport.iop_psord,0x00000001);
  209. setbits32(&immap->im_ioport.iop_psord,0x00000002);
  210. clrbits32(&immap->im_ioport.iop_pdird,0x00000001);
  211. setbits32(&immap->im_ioport.iop_pdird,0x00000002);
  212. /* Wire BRG1 to SCC1 */
  213. clrbits32(&immap->im_cpmux.cmx_scr,0x00ffffff);
  214. iounmap(immap);
  215. }
  216. static void init_scc4_uart_ioports(void)
  217. {
  218. cpm2_map_t* immap = ioremap(CPM_MAP_ADDR, sizeof(cpm2_map_t));
  219. setbits32(&immap->im_ioport.iop_ppard,0x00000600);
  220. clrbits32(&immap->im_ioport.iop_psord,0x00000600);
  221. clrbits32(&immap->im_ioport.iop_pdird,0x00000200);
  222. setbits32(&immap->im_ioport.iop_pdird,0x00000400);
  223. /* Wire BRG4 to SCC4 */
  224. clrbits32(&immap->im_cpmux.cmx_scr,0x000000ff);
  225. setbits32(&immap->im_cpmux.cmx_scr,0x0000001b);
  226. iounmap(immap);
  227. }
  228. static int mpc8272ads_platform_notify(struct device *dev)
  229. {
  230. static const struct platform_notify_dev_map dev_map[] = {
  231. {
  232. .bus_id = "fsl-cpm-fcc",
  233. .rtn = mpc8272ads_fixup_enet_pdata,
  234. },
  235. {
  236. .bus_id = "fsl-cpm-scc:uart",
  237. .rtn = mpc8272ads_fixup_uart_pdata,
  238. },
  239. {
  240. .bus_id = NULL
  241. }
  242. };
  243. platform_notify_map(dev_map,dev);
  244. return 0;
  245. }
  246. int __init mpc8272ads_init(void)
  247. {
  248. printk(KERN_NOTICE "mpc8272ads: Init\n");
  249. platform_notify = mpc8272ads_platform_notify;
  250. ppc_sys_device_initfunc();
  251. ppc_sys_device_disable_all();
  252. ppc_sys_device_enable(MPC82xx_CPM_FCC1);
  253. ppc_sys_device_enable(MPC82xx_CPM_FCC2);
  254. /* to be ready for console, let's attach pdata here */
  255. #ifdef CONFIG_SERIAL_CPM_SCC1
  256. ppc_sys_device_setfunc(MPC82xx_CPM_SCC1, PPC_SYS_FUNC_UART);
  257. ppc_sys_device_enable(MPC82xx_CPM_SCC1);
  258. #endif
  259. #ifdef CONFIG_SERIAL_CPM_SCC4
  260. ppc_sys_device_setfunc(MPC82xx_CPM_SCC4, PPC_SYS_FUNC_UART);
  261. ppc_sys_device_enable(MPC82xx_CPM_SCC4);
  262. #endif
  263. return 0;
  264. }
  265. /*
  266. To prevent confusion, console selection is gross:
  267. by 0 assumed SCC1 and by 1 assumed SCC4
  268. */
  269. struct platform_device* early_uart_get_pdev(int index)
  270. {
  271. bd_t *bd = (bd_t *) __res;
  272. struct fs_uart_platform_info *pinfo;
  273. struct platform_device* pdev = NULL;
  274. if(index) { /*assume SCC4 here*/
  275. pdev = &ppc_sys_platform_devices[MPC82xx_CPM_SCC4];
  276. pinfo = &mpc8272_uart_pdata[fsid_scc4_uart];
  277. } else { /*over SCC1*/
  278. pdev = &ppc_sys_platform_devices[MPC82xx_CPM_SCC1];
  279. pinfo = &mpc8272_uart_pdata[fsid_scc1_uart];
  280. }
  281. pinfo->uart_clk = bd->bi_intfreq;
  282. pdev->dev.platform_data = pinfo;
  283. ppc_sys_fixup_mem_resource(pdev, CPM_MAP_ADDR);
  284. return NULL;
  285. }
  286. arch_initcall(mpc8272ads_init);