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>
36 #include <asm/mpc8xx.h>
38 extern unsigned char __res[];
40 static void setup_fec1_ioports(void);
41 static void setup_scc1_ioports(void);
42 static void setup_smc1_ioports(void);
43 static void setup_smc2_ioports(void);
45 static struct fs_mii_bus_info fec_mii_bus_info = {
50 static struct fs_mii_bus_info scc_mii_bus_info = {
51 .method = fsmii_fixed,
57 static struct fs_platform_info mpc8xx_fec_pdata[] = {
71 .bus_info = &fec_mii_bus_info,
75 static struct fs_platform_info mpc8xx_scc_pdata = {
86 .bus_info = &scc_mii_bus_info,
90 static struct fs_uart_platform_info mpc866_uart_pdata[] = {
93 .fs_no = fsid_smc1_uart,
94 .init_ioports = setup_smc1_ioports,
102 .fs_no = fsid_smc2_uart,
103 .init_ioports = setup_smc2_ioports,
111 void __init board_init(void)
113 volatile cpm8xx_t *cp = cpmp;
116 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
118 if (bcsr_io == NULL) {
119 printk(KERN_CRIT "Could not remap BCSR1\n");
123 #ifdef CONFIG_SERIAL_CPM_SMC1
124 cp->cp_simode &= ~(0xe0000000 >> 17); /* brg1 */
125 clrbits32(bcsr_io,(0x80000000 >> 7));
126 cp->cp_smc[0].smc_smcm |= (SMCM_RX | SMCM_TX);
127 cp->cp_smc[0].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
129 setbits32(bcsr_io,(0x80000000 >> 7));
131 cp->cp_pbpar &= ~(0x000000c0);
132 cp->cp_pbdir |= 0x000000c0;
133 cp->cp_smc[0].smc_smcmr = 0;
134 cp->cp_smc[0].smc_smce = 0;
137 #ifdef CONFIG_SERIAL_CPM_SMC2
138 cp->cp_simode &= ~(0xe0000000 >> 1);
139 cp->cp_simode |= (0x20000000 >> 1); /* brg2 */
140 clrbits32(bcsr_io,(0x80000000 >> 13));
141 cp->cp_smc[1].smc_smcm |= (SMCM_RX | SMCM_TX);
142 cp->cp_smc[1].smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
144 clrbits32(bcsr_io,(0x80000000 >> 13));
145 cp->cp_pbpar &= ~(0x00000c00);
146 cp->cp_pbdir |= 0x00000c00;
147 cp->cp_smc[1].smc_smcmr = 0;
148 cp->cp_smc[1].smc_smce = 0;
153 static void setup_fec1_ioports(void)
155 immap_t *immap = (immap_t *) IMAP_ADDR;
157 setbits16(&immap->im_ioport.iop_pdpar, 0x1fff);
158 setbits16(&immap->im_ioport.iop_pddir, 0x1fff);
161 static void setup_scc1_ioports(void)
163 immap_t *immap = (immap_t *) IMAP_ADDR;
166 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
168 if (bcsr_io == NULL) {
169 printk(KERN_CRIT "Could not remap BCSR1\n");
175 clrbits32(bcsr_io,BCSR1_ETHEN);
177 /* Configure port A pins for Txd and Rxd.
179 /* Disable receive and transmit in case EPPC-Bug started it.
181 setbits16(&immap->im_ioport.iop_papar, PA_ENET_RXD | PA_ENET_TXD);
182 clrbits16(&immap->im_ioport.iop_padir, PA_ENET_RXD | PA_ENET_TXD);
183 clrbits16(&immap->im_ioport.iop_paodr, PA_ENET_TXD);
185 /* Configure port C pins to enable CLSN and RENA.
187 clrbits16(&immap->im_ioport.iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
188 clrbits16(&immap->im_ioport.iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
189 setbits16(&immap->im_ioport.iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
190 /* Configure port A for TCLK and RCLK.
192 setbits16(&immap->im_ioport.iop_papar, PA_ENET_TCLK | PA_ENET_RCLK);
193 clrbits16(&immap->im_ioport.iop_padir, PA_ENET_TCLK | PA_ENET_RCLK);
194 clrbits32(&immap->im_cpm.cp_pbpar, PB_ENET_TENA);
195 clrbits32(&immap->im_cpm.cp_pbdir, PB_ENET_TENA);
197 /* Configure Serial Interface clock routing.
198 * First, clear all SCC bits to zero, then set the ones we want.
200 clrbits32(&immap->im_cpm.cp_sicr, SICR_ENET_MASK);
201 setbits32(&immap->im_cpm.cp_sicr, SICR_ENET_CLKRT);
203 /* In the original SCC enet driver the following code is placed at
204 the end of the initialization */
205 setbits32(&immap->im_cpm.cp_pbpar, PB_ENET_TENA);
206 setbits32(&immap->im_cpm.cp_pbdir, PB_ENET_TENA);
210 static void mpc866ads_fixup_enet_pdata(struct platform_device *pdev, int fs_no)
212 struct fs_platform_info *fpi = pdev->dev.platform_data;
214 volatile cpm8xx_t *cp;
215 bd_t *bd = (bd_t *) __res;
219 /* Get pointer to Communication Processor */
223 fpi = &mpc8xx_fec_pdata[0];
224 fpi->init_ioports = &setup_fec1_ioports;
228 fpi = &mpc8xx_scc_pdata;
229 fpi->init_ioports = &setup_scc1_ioports;
233 printk(KERN_WARNING"Device %s is not supported!\n", pdev->name);
237 pdev->dev.platform_data = fpi;
240 e = (unsigned char *)&bd->bi_enetaddr;
241 for (i = 0; i < 6; i++)
242 fpi->macaddr[i] = *e++;
244 fpi->macaddr[5 - pdev->id]++;
248 static void mpc866ads_fixup_fec_enet_pdata(struct platform_device *pdev,
251 /* This is for FEC devices only */
252 if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-fec")))
254 mpc866ads_fixup_enet_pdata(pdev, fsid_fec1 + pdev->id - 1);
257 static void mpc866ads_fixup_scc_enet_pdata(struct platform_device *pdev,
260 /* This is for SCC devices only */
261 if (!pdev || !pdev->name || (!strstr(pdev->name, "fsl-cpm-scc")))
264 mpc866ads_fixup_enet_pdata(pdev, fsid_scc1 + pdev->id - 1);
267 static void setup_smc1_ioports(void)
269 immap_t *immap = (immap_t *) IMAP_ADDR;
271 unsigned int iobits = 0x000000c0;
273 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
275 if (bcsr_io == NULL) {
276 printk(KERN_CRIT "Could not remap BCSR1\n");
280 clrbits32(bcsr_io,BCSR1_RS232EN_1);
283 setbits32(&immap->im_cpm.cp_pbpar, iobits);
284 clrbits32(&immap->im_cpm.cp_pbdir, iobits);
285 clrbits16(&immap->im_cpm.cp_pbodr, iobits);
289 static void setup_smc2_ioports(void)
291 immap_t *immap = (immap_t *) IMAP_ADDR;
293 unsigned int iobits = 0x00000c00;
295 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
297 if (bcsr_io == NULL) {
298 printk(KERN_CRIT "Could not remap BCSR1\n");
302 clrbits32(bcsr_io,BCSR1_RS232EN_2);
306 #ifndef CONFIG_SERIAL_CPM_ALT_SMC2
307 setbits32(&immap->im_cpm.cp_pbpar, iobits);
308 clrbits32(&immap->im_cpm.cp_pbdir, iobits);
309 clrbits16(&immap->im_cpm.cp_pbodr, iobits);
311 setbits16(&immap->im_ioport.iop_papar, iobits);
312 clrbits16(&immap->im_ioport.iop_padir, iobits);
313 clrbits16(&immap->im_ioport.iop_paodr, iobits);
318 static void __init mpc866ads_fixup_uart_pdata(struct platform_device *pdev,
321 bd_t *bd = (bd_t *) __res;
322 struct fs_uart_platform_info *pinfo;
323 int num = ARRAY_SIZE(mpc866_uart_pdata);
325 int id = fs_uart_id_smc2fsid(idx);
327 /* no need to alter anything if console */
328 if ((id <= num) && (!pdev->dev.platform_data)) {
329 pinfo = &mpc866_uart_pdata[id];
330 pinfo->uart_clk = bd->bi_intfreq;
331 pdev->dev.platform_data = pinfo;
335 static int mpc866ads_platform_notify(struct device *dev)
337 static const struct platform_notify_dev_map dev_map[] = {
339 .bus_id = "fsl-cpm-fec",
340 .rtn = mpc866ads_fixup_fec_enet_pdata,
343 .bus_id = "fsl-cpm-scc",
344 .rtn = mpc866ads_fixup_scc_enet_pdata,
347 .bus_id = "fsl-cpm-smc:uart",
348 .rtn = mpc866ads_fixup_uart_pdata
355 platform_notify_map(dev_map,dev);
360 int __init mpc866ads_init(void)
362 printk(KERN_NOTICE "mpc866ads: Init\n");
364 platform_notify = mpc866ads_platform_notify;
366 ppc_sys_device_initfunc();
367 ppc_sys_device_disable_all();
369 #ifdef MPC8xx_SECOND_ETH_SCC1
370 ppc_sys_device_enable(MPC8xx_CPM_SCC1);
372 ppc_sys_device_enable(MPC8xx_CPM_FEC1);
374 /* Since either of the uarts could be used as console, they need to ready */
375 #ifdef CONFIG_SERIAL_CPM_SMC1
376 ppc_sys_device_enable(MPC8xx_CPM_SMC1);
377 ppc_sys_device_setfunc(MPC8xx_CPM_SMC1, PPC_SYS_FUNC_UART);
380 #ifdef CONFIG_SERIAL_CPM_SMC
381 ppc_sys_device_enable(MPC8xx_CPM_SMC2);
382 ppc_sys_device_setfunc(MPC8xx_CPM_SMC2, PPC_SYS_FUNC_UART);
389 To prevent confusion, console selection is gross:
390 by 0 assumed SMC1 and by 1 assumed SMC2
392 struct platform_device* early_uart_get_pdev(int index)
394 bd_t *bd = (bd_t *) __res;
395 struct fs_uart_platform_info *pinfo;
397 struct platform_device* pdev = NULL;
398 if(index) { /*assume SMC2 here*/
399 pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC2];
400 pinfo = &mpc866_uart_pdata[1];
401 } else { /*over SMC1*/
402 pdev = &ppc_sys_platform_devices[MPC8xx_CPM_SMC1];
403 pinfo = &mpc866_uart_pdata[0];
406 pinfo->uart_clk = bd->bi_intfreq;
407 pdev->dev.platform_data = pinfo;
408 ppc_sys_fixup_mem_resource(pdev, IMAP_ADDR);
412 arch_initcall(mpc866ads_init);