1 /*arch/powerpc/platforms/8xx/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>
20 #include <linux/delay.h>
21 #include <linux/root_dev.h>
23 #include <linux/fs_enet_pd.h>
24 #include <linux/fs_uart_pd.h>
25 #include <linux/fsl_devices.h>
26 #include <linux/mii.h>
28 #include <asm/delay.h>
30 #include <asm/machdep.h>
32 #include <asm/processor.h>
33 #include <asm/system.h>
35 #include <asm/ppcboot.h>
36 #include <asm/mpc8xx.h>
37 #include <asm/8xx_immap.h>
38 #include <asm/commproc.h>
39 #include <asm/fs_pd.h>
42 extern void cpm_reset(void);
43 extern void mpc8xx_show_cpuinfo(struct seq_file *);
44 extern void mpc8xx_restart(char *cmd);
45 extern void mpc8xx_calibrate_decr(void);
46 extern int mpc8xx_set_rtc_time(struct rtc_time *tm);
47 extern void mpc8xx_get_rtc_time(struct rtc_time *tm);
48 extern void m8xx_pic_init(void);
49 extern unsigned int mpc8xx_get_irq(void);
51 static void init_smc1_uart_ioports(struct fs_uart_platform_info *fpi);
52 static void init_smc2_uart_ioports(struct fs_uart_platform_info *fpi);
53 static void init_scc3_ioports(struct fs_platform_info *ptr);
55 #ifdef CONFIG_PCMCIA_M8XX
56 static void pcmcia_hw_setup(int slot, int enable)
60 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
62 clrbits32(bcsr_io, BCSR1_PCCEN);
64 setbits32(bcsr_io, BCSR1_PCCEN);
69 static int pcmcia_set_voltage(int slot, int vcc, int vpp)
74 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
100 if ((vcc == 33) || (vcc == 50))
101 reg |= BCSR1_PCCVPP0;
108 /* first, turn off all power */
109 clrbits32(bcsr_io, 0x00610000);
111 /* enable new powersettings */
112 setbits32(bcsr_io, reg);
119 void __init mpc885ads_board_setup(void)
122 unsigned int *bcsr_io;
125 #ifdef CONFIG_FS_ENET
129 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
130 cp = (cpm8xx_t *) immr_map(im_cpm);
132 if (bcsr_io == NULL) {
133 printk(KERN_CRIT "Could not remap BCSR\n");
136 #ifdef CONFIG_SERIAL_CPM_SMC1
137 clrbits32(bcsr_io, BCSR1_RS232EN_1);
138 clrbits32(&cp->cp_simode, 0xe0000000 >> 17); /* brg1 */
139 tmpval8 = in_8(&(cp->cp_smc[0].smc_smcm)) | (SMCM_RX | SMCM_TX);
140 out_8(&(cp->cp_smc[0].smc_smcm), tmpval8);
141 clrbits16(&cp->cp_smc[0].smc_smcmr, SMCMR_REN | SMCMR_TEN); /* brg1 */
143 setbits32(bcsr_io, BCSR1_RS232EN_1);
144 out_be16(&cp->cp_smc[0].smc_smcmr, 0);
145 out_8(&cp->cp_smc[0].smc_smce, 0);
148 #ifdef CONFIG_SERIAL_CPM_SMC2
149 clrbits32(bcsr_io, BCSR1_RS232EN_2);
150 clrbits32(&cp->cp_simode, 0xe0000000 >> 1);
151 setbits32(&cp->cp_simode, 0x20000000 >> 1); /* brg2 */
152 tmpval8 = in_8(&(cp->cp_smc[1].smc_smcm)) | (SMCM_RX | SMCM_TX);
153 out_8(&(cp->cp_smc[1].smc_smcm), tmpval8);
154 clrbits16(&cp->cp_smc[1].smc_smcmr, SMCMR_REN | SMCMR_TEN);
156 init_smc2_uart_ioports(0);
158 setbits32(bcsr_io, BCSR1_RS232EN_2);
159 out_be16(&cp->cp_smc[1].smc_smcmr, 0);
160 out_8(&cp->cp_smc[1].smc_smce, 0);
165 #ifdef CONFIG_FS_ENET
166 /* use MDC for MII (common) */
167 io_port = (iop8xx_t *) immr_map(im_ioport);
168 setbits16(&io_port->iop_pdpar, 0x0080);
169 clrbits16(&io_port->iop_pddir, 0x0080);
171 bcsr_io = ioremap(BCSR5, sizeof(unsigned long));
172 clrbits32(bcsr_io, BCSR5_MII1_EN);
173 clrbits32(bcsr_io, BCSR5_MII1_RST);
174 #ifndef CONFIG_FC_ENET_HAS_SCC
175 clrbits32(bcsr_io, BCSR5_MII2_EN);
176 clrbits32(bcsr_io, BCSR5_MII2_RST);
184 #ifdef CONFIG_PCMCIA_M8XX
185 /*Set up board specific hook-ups */
186 m8xx_pcmcia_ops.hw_ctrl = pcmcia_hw_setup;
187 m8xx_pcmcia_ops.voltage_set = pcmcia_set_voltage;
191 static void init_fec1_ioports(struct fs_platform_info *ptr)
193 cpm8xx_t *cp = (cpm8xx_t *) immr_map(im_cpm);
194 iop8xx_t *io_port = (iop8xx_t *) immr_map(im_ioport);
196 /* configure FEC1 pins */
197 setbits16(&io_port->iop_papar, 0xf830);
198 setbits16(&io_port->iop_padir, 0x0830);
199 clrbits16(&io_port->iop_padir, 0xf000);
201 setbits32(&cp->cp_pbpar, 0x00001001);
202 clrbits32(&cp->cp_pbdir, 0x00001001);
204 setbits16(&io_port->iop_pcpar, 0x000c);
205 clrbits16(&io_port->iop_pcdir, 0x000c);
207 setbits32(&cp->cp_pepar, 0x00000003);
208 setbits32(&cp->cp_pedir, 0x00000003);
209 clrbits32(&cp->cp_peso, 0x00000003);
210 clrbits32(&cp->cp_cptr, 0x00000100);
216 static void init_fec2_ioports(struct fs_platform_info *ptr)
218 cpm8xx_t *cp = (cpm8xx_t *) immr_map(im_cpm);
219 iop8xx_t *io_port = (iop8xx_t *) immr_map(im_ioport);
221 /* configure FEC2 pins */
222 setbits32(&cp->cp_pepar, 0x0003fffc);
223 setbits32(&cp->cp_pedir, 0x0003fffc);
224 clrbits32(&cp->cp_peso, 0x000087fc);
225 setbits32(&cp->cp_peso, 0x00037800);
226 clrbits32(&cp->cp_cptr, 0x00000080);
232 void init_fec_ioports(struct fs_platform_info *fpi)
234 int fec_no = fs_get_fec_index(fpi->fs_no);
238 init_fec1_ioports(fpi);
241 init_fec2_ioports(fpi);
244 printk(KERN_ERR "init_fec_ioports: invalid FEC number\n");
249 static void init_scc3_ioports(struct fs_platform_info *fpi)
255 bcsr_io = ioremap(BCSR_ADDR, BCSR_SIZE);
256 io_port = (iop8xx_t *) immr_map(im_ioport);
257 cp = (cpm8xx_t *) immr_map(im_cpm);
259 if (bcsr_io == NULL) {
260 printk(KERN_CRIT "Could not remap BCSR\n");
266 clrbits32(bcsr_io + 4, BCSR4_ETH10_RST);
268 setbits32(bcsr_io + 4, BCSR4_ETH10_RST);
269 /* Configure port A pins for Txd and Rxd.
271 setbits16(&io_port->iop_papar, PA_ENET_RXD | PA_ENET_TXD);
272 clrbits16(&io_port->iop_padir, PA_ENET_RXD | PA_ENET_TXD);
274 /* Configure port C pins to enable CLSN and RENA.
276 clrbits16(&io_port->iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
277 clrbits16(&io_port->iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
278 setbits16(&io_port->iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
280 /* Configure port E for TCLK and RCLK.
282 setbits32(&cp->cp_pepar, PE_ENET_TCLK | PE_ENET_RCLK);
283 clrbits32(&cp->cp_pepar, PE_ENET_TENA);
284 clrbits32(&cp->cp_pedir, PE_ENET_TCLK | PE_ENET_RCLK | PE_ENET_TENA);
285 clrbits32(&cp->cp_peso, PE_ENET_TCLK | PE_ENET_RCLK);
286 setbits32(&cp->cp_peso, PE_ENET_TENA);
288 /* Configure Serial Interface clock routing.
289 * First, clear all SCC bits to zero, then set the ones we want.
291 clrbits32(&cp->cp_sicr, SICR_ENET_MASK);
292 setbits32(&cp->cp_sicr, SICR_ENET_CLKRT);
294 /* Disable Rx and Tx. SMC1 sshould be stopped if SCC3 eternet are used.
296 clrbits16(&cp->cp_smc[0].smc_smcmr, SMCMR_REN | SMCMR_TEN);
297 /* On the MPC885ADS SCC ethernet PHY is initialized in the full duplex mode
298 * by H/W setting after reset. SCC ethernet controller support only half duplex.
299 * This discrepancy of modes causes a lot of carrier lost errors.
302 /* In the original SCC enet driver the following code is placed at
303 the end of the initialization */
304 setbits32(&cp->cp_pepar, PE_ENET_TENA);
305 clrbits32(&cp->cp_pedir, PE_ENET_TENA);
306 setbits32(&cp->cp_peso, PE_ENET_TENA);
308 setbits32(bcsr_io + 4, BCSR1_ETHEN);
314 void init_scc_ioports(struct fs_platform_info *fpi)
316 int scc_no = fs_get_scc_index(fpi->fs_no);
320 init_scc3_ioports(fpi);
323 printk(KERN_ERR "init_scc_ioports: invalid SCC number\n");
328 static void init_smc1_uart_ioports(struct fs_uart_platform_info *ptr)
333 cp = (cpm8xx_t *) immr_map(im_cpm);
334 setbits32(&cp->cp_pepar, 0x000000c0);
335 clrbits32(&cp->cp_pedir, 0x000000c0);
336 clrbits32(&cp->cp_peso, 0x00000040);
337 setbits32(&cp->cp_peso, 0x00000080);
340 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
342 if (bcsr_io == NULL) {
343 printk(KERN_CRIT "Could not remap BCSR1\n");
346 clrbits32(bcsr_io, BCSR1_RS232EN_1);
350 static void init_smc2_uart_ioports(struct fs_uart_platform_info *fpi)
355 cp = (cpm8xx_t *) immr_map(im_cpm);
356 setbits32(&cp->cp_pepar, 0x00000c00);
357 clrbits32(&cp->cp_pedir, 0x00000c00);
358 clrbits32(&cp->cp_peso, 0x00000400);
359 setbits32(&cp->cp_peso, 0x00000800);
362 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
364 if (bcsr_io == NULL) {
365 printk(KERN_CRIT "Could not remap BCSR1\n");
368 clrbits32(bcsr_io, BCSR1_RS232EN_2);
372 void init_smc_ioports(struct fs_uart_platform_info *data)
374 int smc_no = fs_uart_id_fsid2smc(data->fs_no);
378 init_smc1_uart_ioports(data);
379 data->brg = data->clk_rx;
382 init_smc2_uart_ioports(data);
383 data->brg = data->clk_rx;
386 printk(KERN_ERR "init_scc_ioports: invalid SCC number\n");
391 int platform_device_skip(const char *model, int id)
393 #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
394 const char *dev = "FEC";
397 const char *dev = "SCC";
401 if (!strcmp(model, dev) && n == id)
407 static void __init mpc885ads_setup_arch(void)
411 mpc885ads_board_setup();
416 static int __init mpc885ads_probe(void)
418 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
422 if (strcmp(model, "MPC885ADS"))
428 define_machine(mpc885_ads)
430 .name = "MPC885 ADS",.probe = mpc885ads_probe,.setup_arch =
431 mpc885ads_setup_arch,.init_IRQ =
432 m8xx_pic_init,.show_cpuinfo = mpc8xx_show_cpuinfo,.get_irq =
433 mpc8xx_get_irq,.restart = mpc8xx_restart,.calibrate_decr =
434 mpc8xx_calibrate_decr,.set_rtc_time =
435 mpc8xx_set_rtc_time,.get_rtc_time = mpc8xx_get_rtc_time,};