1 /*arch/ppc/platforms/mpc885ads-setup.c
3 * Platform setup for the Freescale mpc885ads board
5 * Vitaly Bordug <vbordug@ru.mvista.com>
7 * Copyright 2005 MontaVista Software Inc.
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.
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>
21 #include <linux/fs_enet_pd.h>
22 #include <linux/fs_uart_pd.h>
23 #include <linux/mii.h>
25 #include <asm/delay.h>
27 #include <asm/machdep.h>
29 #include <asm/processor.h>
30 #include <asm/system.h>
32 #include <asm/ppcboot.h>
33 #include <asm/8xx_immap.h>
34 #include <asm/commproc.h>
35 #include <asm/ppc_sys.h>
37 extern unsigned char __res[];
38 static void setup_smc1_ioports(void);
39 static void setup_smc2_ioports(void);
41 static void __init mpc885ads_scc_phy_init(char);
43 static struct fs_uart_platform_info mpc885_uart_pdata[] = {
46 .fs_no = fsid_smc1_uart,
47 .init_ioports = setup_smc1_ioports,
55 .fs_no = fsid_smc2_uart,
56 .init_ioports = setup_smc2_ioports,
64 static struct fs_mii_bus_info fec_mii_bus_info = {
69 static struct fs_mii_bus_info scc_mii_bus_info = {
70 #ifdef CONFIG_SCC_ENET_8xx_FIXED
71 .method = fsmii_fixed,
79 static struct fs_platform_info mpc8xx_fec_pdata[] = {
91 .bus_info = &fec_mii_bus_info,
103 .bus_info = &fec_mii_bus_info,
107 static struct fs_platform_info mpc8xx_scc_pdata = {
116 #ifdef CONFIG_MPC8xx_SCC_ENET_FIXED
122 .bus_info = &scc_mii_bus_info,
125 void __init board_init(void)
127 volatile cpm8xx_t *cp = cpmp;
128 unsigned int *bcsr_io;
130 #ifdef CONFIG_FS_ENET
131 immap_t *immap = (immap_t *) IMAP_ADDR;
133 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
135 if (bcsr_io == NULL) {
136 printk(KERN_CRIT "Could not remap BCSR\n");
139 #ifdef CONFIG_SERIAL_CPM_SMC1
140 cp->cp_simode &= ~(0xe0000000 >> 17); /* brg1 */
141 clrbits32(bcsr_io, BCSR1_RS232EN_1);
142 cp->cp_smc[0].smc_smcm |= (SMCM_RX | SMCM_TX);
143 cp->cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
145 setbits32(bcsr_io,BCSR1_RS232EN_1);
146 cp->cp_smc[0].smc_smcmr = 0;
147 cp->cp_smc[0].smc_smce = 0;
150 #ifdef CONFIG_SERIAL_CPM_SMC2
151 cp->cp_simode &= ~(0xe0000000 >> 1);
152 cp->cp_simode |= (0x20000000 >> 1); /* brg2 */
153 clrbits32(bcsr_io,BCSR1_RS232EN_2);
154 cp->cp_smc[1].smc_smcm |= (SMCM_RX | SMCM_TX);
155 cp->cp_smc[1].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
157 setbits32(bcsr_io,BCSR1_RS232EN_2);
158 cp->cp_smc[1].smc_smcmr = 0;
159 cp->cp_smc[1].smc_smce = 0;
163 #ifdef CONFIG_FS_ENET
164 /* use MDC for MII (common) */
165 setbits16(&immap->im_ioport.iop_pdpar, 0x0080);
166 clrbits16(&immap->im_ioport.iop_pddir, 0x0080);
170 static void setup_fec1_ioports(void)
172 immap_t *immap = (immap_t *) IMAP_ADDR;
174 /* configure FEC1 pins */
175 setbits16(&immap->im_ioport.iop_papar, 0xf830);
176 setbits16(&immap->im_ioport.iop_padir, 0x0830);
177 clrbits16(&immap->im_ioport.iop_padir, 0xf000);
178 setbits32(&immap->im_cpm.cp_pbpar, 0x00001001);
180 clrbits32(&immap->im_cpm.cp_pbdir, 0x00001001);
181 setbits16(&immap->im_ioport.iop_pcpar, 0x000c);
182 clrbits16(&immap->im_ioport.iop_pcdir, 0x000c);
183 setbits32(&immap->im_cpm.cp_pepar, 0x00000003);
185 setbits32(&immap->im_cpm.cp_pedir, 0x00000003);
186 clrbits32(&immap->im_cpm.cp_peso, 0x00000003);
187 clrbits32(&immap->im_cpm.cp_cptr, 0x00000100);
190 static void setup_fec2_ioports(void)
192 immap_t *immap = (immap_t *) IMAP_ADDR;
194 /* configure FEC2 pins */
195 setbits32(&immap->im_cpm.cp_pepar, 0x0003fffc);
196 setbits32(&immap->im_cpm.cp_pedir, 0x0003fffc);
197 setbits32(&immap->im_cpm.cp_peso, 0x00037800);
198 clrbits32(&immap->im_cpm.cp_peso, 0x000087fc);
199 clrbits32(&immap->im_cpm.cp_cptr, 0x00000080);
202 static void setup_scc3_ioports(void)
204 immap_t *immap = (immap_t *) IMAP_ADDR;
207 bcsr_io = ioremap(BCSR_ADDR, BCSR_SIZE);
209 if (bcsr_io == NULL) {
210 printk(KERN_CRIT "Could not remap BCSR\n");
216 setbits32(bcsr_io+4, BCSR4_ETH10_RST);
217 /* Configure port A pins for Txd and Rxd.
219 setbits16(&immap->im_ioport.iop_papar, PA_ENET_RXD | PA_ENET_TXD);
220 clrbits16(&immap->im_ioport.iop_padir, PA_ENET_RXD | PA_ENET_TXD);
222 /* Configure port C pins to enable CLSN and RENA.
224 clrbits16(&immap->im_ioport.iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
225 clrbits16(&immap->im_ioport.iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
226 setbits16(&immap->im_ioport.iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
228 /* Configure port E for TCLK and RCLK.
230 setbits32(&immap->im_cpm.cp_pepar, PE_ENET_TCLK | PE_ENET_RCLK);
231 clrbits32(&immap->im_cpm.cp_pepar, PE_ENET_TENA);
232 clrbits32(&immap->im_cpm.cp_pedir,
233 PE_ENET_TCLK | PE_ENET_RCLK | PE_ENET_TENA);
234 clrbits32(&immap->im_cpm.cp_peso, PE_ENET_TCLK | PE_ENET_RCLK);
235 setbits32(&immap->im_cpm.cp_peso, PE_ENET_TENA);
237 /* Configure Serial Interface clock routing.
238 * First, clear all SCC bits to zero, then set the ones we want.
240 clrbits32(&immap->im_cpm.cp_sicr, SICR_ENET_MASK);
241 setbits32(&immap->im_cpm.cp_sicr, SICR_ENET_CLKRT);
243 /* Disable Rx and Tx. SMC1 sshould be stopped if SCC3 eternet are used.
245 immap->im_cpm.cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
246 /* On the MPC885ADS SCC ethernet PHY is initialized in the full duplex mode
247 * by H/W setting after reset. SCC ethernet controller support only half duplex.
248 * This discrepancy of modes causes a lot of carrier lost errors.
251 /* In the original SCC enet driver the following code is placed at
252 the end of the initialization */
253 setbits32(&immap->im_cpm.cp_pepar, PE_ENET_TENA);
254 clrbits32(&immap->im_cpm.cp_pedir, PE_ENET_TENA);
255 setbits32(&immap->im_cpm.cp_peso, PE_ENET_TENA);
257 setbits32(bcsr_io+1, BCSR1_ETHEN);
261 static void mpc885ads_fixup_enet_pdata(struct platform_device *pdev, int fs_no)
263 struct fs_platform_info *fpi = pdev->dev.platform_data;
265 volatile cpm8xx_t *cp;
266 bd_t *bd = (bd_t *) __res;
270 /* Get pointer to Communication Processor */
274 fpi = &mpc8xx_fec_pdata[0];
275 fpi->init_ioports = &setup_fec1_ioports;
278 fpi = &mpc8xx_fec_pdata[1];
279 fpi->init_ioports = &setup_fec2_ioports;
282 fpi = &mpc8xx_scc_pdata;
283 fpi->init_ioports = &setup_scc3_ioports;
284 mpc885ads_scc_phy_init(fpi->phy_addr);
287 printk(KERN_WARNING"Device %s is not supported!\n", pdev->name);
291 pdev->dev.platform_data = fpi;
294 e = (unsigned char *)&bd->bi_enetaddr;
295 for (i = 0; i < 6; i++)
296 fpi->macaddr[i] = *e++;
298 fpi->macaddr[5 - pdev->id]++;
302 static void mpc885ads_fixup_fec_enet_pdata(struct platform_device *pdev,
305 /* This is for FEC devices only */
306 if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-fec")))
308 mpc885ads_fixup_enet_pdata(pdev, fsid_fec1 + pdev->id - 1);
311 static void __init mpc885ads_fixup_scc_enet_pdata(struct platform_device *pdev,
314 /* This is for SCC devices only */
315 if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-scc")))
318 mpc885ads_fixup_enet_pdata(pdev, fsid_scc1 + pdev->id - 1);
321 /* SCC ethernet controller does not have MII management channel. FEC1 MII
322 * channel is used to communicate with the 10Mbit PHY.
325 #define MII_ECNTRL_PINMUX 0x4
326 #define FEC_ECNTRL_PINMUX 0x00000004
327 #define FEC_RCNTRL_MII_MODE 0x00000004
329 /* Make MII read/write commands.
331 #define mk_mii_write(REG, VAL, PHY_ADDR) (0x50020000 | (((REG) & 0x1f) << 18) | \
332 ((VAL) & 0xffff) | ((PHY_ADDR) << 23))
334 static void mpc885ads_scc_phy_init(char phy_addr)
336 volatile immap_t *immap;
337 volatile fec_t *fecp;
341 immap = (immap_t *) IMAP_ADDR; /* pointer to internal registers */
342 fecp = &(immap->im_cpm.cp_fec);
344 /* Enable MII pins of the FEC1
346 setbits16(&immap->im_ioport.iop_pdpar, 0x0080);
347 clrbits16(&immap->im_ioport.iop_pddir, 0x0080);
348 /* Set MII speed to 2.5 MHz
350 out_be32(&fecp->fec_mii_speed,
351 ((((bd->bi_intfreq + 4999999) / 2500000) / 2) & 0x3F) << 1);
353 /* Enable FEC pin MUX
355 setbits32(&fecp->fec_ecntrl, MII_ECNTRL_PINMUX);
356 setbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE);
358 out_be32(&fecp->fec_mii_data,
359 mk_mii_write(MII_BMCR, BMCR_ISOLATE, phy_addr));
361 out_be32(&fecp->fec_mii_data,
362 mk_mii_write(MII_ADVERTISE,
363 ADVERTISE_10HALF | ADVERTISE_CSMA, phy_addr));
366 /* Disable FEC MII settings
368 clrbits32(&fecp->fec_ecntrl, MII_ECNTRL_PINMUX);
369 clrbits32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE);
370 out_be32(&fecp->fec_mii_speed, 0);
373 static void setup_smc1_ioports(void)
375 immap_t *immap = (immap_t *) IMAP_ADDR;
377 unsigned int iobits = 0x000000c0;
379 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
381 if (bcsr_io == NULL) {
382 printk(KERN_CRIT "Could not remap BCSR1\n");
385 clrbits32(bcsr_io,BCSR1_RS232EN_1);
388 setbits32(&immap->im_cpm.cp_pbpar, iobits);
389 clrbits32(&immap->im_cpm.cp_pbdir, iobits);
390 clrbits16(&immap->im_cpm.cp_pbodr, iobits);
393 static void setup_smc2_ioports(void)
395 immap_t *immap = (immap_t *) IMAP_ADDR;
397 unsigned int iobits = 0x00000c00;
399 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
401 if (bcsr_io == NULL) {
402 printk(KERN_CRIT "Could not remap BCSR1\n");
405 clrbits32(bcsr_io,BCSR1_RS232EN_2);
408 #ifndef CONFIG_SERIAL_CPM_ALT_SMC2
409 setbits32(&immap->im_cpm.cp_pbpar, iobits);
410 clrbits32(&immap->im_cpm.cp_pbdir, iobits);
411 clrbits16(&immap->im_cpm.cp_pbodr, iobits);
413 setbits16(&immap->im_ioport.iop_papar, iobits);
414 clrbits16(&immap->im_ioport.iop_padir, iobits);
415 clrbits16(&immap->im_ioport.iop_paodr, iobits);
419 static void __init mpc885ads_fixup_uart_pdata(struct platform_device *pdev,
422 bd_t *bd = (bd_t *) __res;
423 struct fs_uart_platform_info *pinfo;
424 int num = ARRAY_SIZE(mpc885_uart_pdata);
426 int id = fs_uart_id_smc2fsid(idx);
428 /* no need to alter anything if console */
429 if ((id <= num) && (!pdev->dev.platform_data)) {
430 pinfo = &mpc885_uart_pdata[id];
431 pinfo->uart_clk = bd->bi_intfreq;
432 pdev->dev.platform_data = pinfo;
437 static int mpc885ads_platform_notify(struct device *dev)
440 static const struct platform_notify_dev_map dev_map[] = {
442 .bus_id = "fsl-cpm-fec",
443 .rtn = mpc885ads_fixup_fec_enet_pdata,
446 .bus_id = "fsl-cpm-scc",
447 .rtn = mpc885ads_fixup_scc_enet_pdata,
450 .bus_id = "fsl-cpm-smc:uart",
451 .rtn = mpc885ads_fixup_uart_pdata
458 platform_notify_map(dev_map,dev);
463 int __init mpc885ads_init(void)
465 printk(KERN_NOTICE "mpc885ads: Init\n");
467 platform_notify = mpc885ads_platform_notify;
469 ppc_sys_device_initfunc();
470 ppc_sys_device_disable_all();
472 ppc_sys_device_enable(MPC8xx_CPM_FEC1);
474 #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
475 ppc_sys_device_enable(MPC8xx_CPM_SCC1);
478 #ifdef CONFIG_MPC8xx_SECOND_ETH_FEC2
479 ppc_sys_device_enable(MPC8xx_CPM_FEC2);
482 #ifdef CONFIG_SERIAL_CPM_SMC1
483 ppc_sys_device_enable(MPC8xx_CPM_SMC1);
484 ppc_sys_device_setfunc(MPC8xx_CPM_SMC1, PPC_SYS_FUNC_UART);
487 #ifdef CONFIG_SERIAL_CPM_SMC2
488 ppc_sys_device_enable(MPC8xx_CPM_SMC2);
489 ppc_sys_device_setfunc(MPC8xx_CPM_SMC2, PPC_SYS_FUNC_UART);
494 arch_initcall(mpc885ads_init);
497 To prevent confusion, console selection is gross:
498 by 0 assumed SMC1 and by 1 assumed SMC2
500 struct platform_device* early_uart_get_pdev(int index)
502 bd_t *bd = (bd_t *) __res;
503 struct fs_uart_platform_info *pinfo;
505 struct platform_device* pdev = NULL;
506 if(index) { /*assume SMC2 here*/
507 pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC2];
508 pinfo = &mpc885_uart_pdata[1];
509 } else { /*over SMC1*/
510 pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC1];
511 pinfo = &mpc885_uart_pdata[0];
514 pinfo->uart_clk = bd->bi_intfreq;
515 pdev->dev.platform_data = pinfo;
516 ppc_sys_fixup_mem_resource(pdev, IMAP_ADDR);