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;
192 static void init_fec1_ioports(struct fs_platform_info* ptr)
194 cpm8xx_t *cp = (cpm8xx_t *)immr_map(im_cpm);
195 iop8xx_t *io_port = (iop8xx_t *)immr_map(im_ioport);
197 /* configure FEC1 pins */
198 setbits16(&io_port->iop_papar, 0xf830);
199 setbits16(&io_port->iop_padir, 0x0830);
200 clrbits16(&io_port->iop_padir, 0xf000);
202 setbits32(&cp->cp_pbpar, 0x00001001);
203 clrbits32(&cp->cp_pbdir, 0x00001001);
205 setbits16(&io_port->iop_pcpar, 0x000c);
206 clrbits16(&io_port->iop_pcdir, 0x000c);
208 setbits32(&cp->cp_pepar, 0x00000003);
209 setbits32(&cp->cp_pedir, 0x00000003);
210 clrbits32(&cp->cp_peso, 0x00000003);
211 clrbits32(&cp->cp_cptr, 0x00000100);
218 static void init_fec2_ioports(struct fs_platform_info* ptr)
220 cpm8xx_t *cp = (cpm8xx_t *)immr_map(im_cpm);
221 iop8xx_t *io_port = (iop8xx_t *)immr_map(im_ioport);
223 /* configure FEC2 pins */
224 setbits32(&cp->cp_pepar, 0x0003fffc);
225 setbits32(&cp->cp_pedir, 0x0003fffc);
226 clrbits32(&cp->cp_peso, 0x000087fc);
227 setbits32(&cp->cp_peso, 0x00037800);
228 clrbits32(&cp->cp_cptr, 0x00000080);
234 void init_fec_ioports(struct fs_platform_info *fpi)
236 int fec_no = fs_get_fec_index(fpi->fs_no);
240 init_fec1_ioports(fpi);
243 init_fec2_ioports(fpi);
246 printk(KERN_ERR "init_fec_ioports: invalid FEC number\n");
251 static void init_scc3_ioports(struct fs_platform_info* fpi)
257 bcsr_io = ioremap(BCSR_ADDR, BCSR_SIZE);
258 io_port = (iop8xx_t *)immr_map(im_ioport);
259 cp = (cpm8xx_t *)immr_map(im_cpm);
261 if (bcsr_io == NULL) {
262 printk(KERN_CRIT "Could not remap BCSR\n");
268 clrbits32(bcsr_io+4, BCSR4_ETH10_RST);
270 setbits32(bcsr_io+4, BCSR4_ETH10_RST);
271 /* Configure port A pins for Txd and Rxd.
273 setbits16(&io_port->iop_papar, PA_ENET_RXD | PA_ENET_TXD);
274 clrbits16(&io_port->iop_padir, PA_ENET_RXD | PA_ENET_TXD);
276 /* Configure port C pins to enable CLSN and RENA.
278 clrbits16(&io_port->iop_pcpar, PC_ENET_CLSN | PC_ENET_RENA);
279 clrbits16(&io_port->iop_pcdir, PC_ENET_CLSN | PC_ENET_RENA);
280 setbits16(&io_port->iop_pcso, PC_ENET_CLSN | PC_ENET_RENA);
282 /* Configure port E for TCLK and RCLK.
284 setbits32(&cp->cp_pepar, PE_ENET_TCLK | PE_ENET_RCLK);
285 clrbits32(&cp->cp_pepar, PE_ENET_TENA);
286 clrbits32(&cp->cp_pedir,
287 PE_ENET_TCLK | PE_ENET_RCLK | PE_ENET_TENA);
288 clrbits32(&cp->cp_peso, PE_ENET_TCLK | PE_ENET_RCLK);
289 setbits32(&cp->cp_peso, PE_ENET_TENA);
291 /* Configure Serial Interface clock routing.
292 * First, clear all SCC bits to zero, then set the ones we want.
294 clrbits32(&cp->cp_sicr, SICR_ENET_MASK);
295 setbits32(&cp->cp_sicr, SICR_ENET_CLKRT);
297 /* Disable Rx and Tx. SMC1 sshould be stopped if SCC3 eternet are used.
299 clrbits16(&cp->cp_smc[0].smc_smcmr, SMCMR_REN | SMCMR_TEN);
300 /* On the MPC885ADS SCC ethernet PHY is initialized in the full duplex mode
301 * by H/W setting after reset. SCC ethernet controller support only half duplex.
302 * This discrepancy of modes causes a lot of carrier lost errors.
305 /* In the original SCC enet driver the following code is placed at
306 the end of the initialization */
307 setbits32(&cp->cp_pepar, PE_ENET_TENA);
308 clrbits32(&cp->cp_pedir, PE_ENET_TENA);
309 setbits32(&cp->cp_peso, PE_ENET_TENA);
311 setbits32(bcsr_io+4, BCSR1_ETHEN);
317 void init_scc_ioports(struct fs_platform_info *fpi)
319 int scc_no = fs_get_scc_index(fpi->fs_no);
323 init_scc3_ioports(fpi);
326 printk(KERN_ERR "init_scc_ioports: invalid SCC number\n");
333 static void init_smc1_uart_ioports(struct fs_uart_platform_info* ptr)
338 cp = (cpm8xx_t *)immr_map(im_cpm);
339 setbits32(&cp->cp_pepar, 0x000000c0);
340 clrbits32(&cp->cp_pedir, 0x000000c0);
341 clrbits32(&cp->cp_peso, 0x00000040);
342 setbits32(&cp->cp_peso, 0x00000080);
345 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
347 if (bcsr_io == NULL) {
348 printk(KERN_CRIT "Could not remap BCSR1\n");
351 clrbits32(bcsr_io,BCSR1_RS232EN_1);
355 static void init_smc2_uart_ioports(struct fs_uart_platform_info* fpi)
360 cp = (cpm8xx_t *)immr_map(im_cpm);
361 setbits32(&cp->cp_pepar, 0x00000c00);
362 clrbits32(&cp->cp_pedir, 0x00000c00);
363 clrbits32(&cp->cp_peso, 0x00000400);
364 setbits32(&cp->cp_peso, 0x00000800);
367 bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
369 if (bcsr_io == NULL) {
370 printk(KERN_CRIT "Could not remap BCSR1\n");
373 clrbits32(bcsr_io,BCSR1_RS232EN_2);
377 void init_smc_ioports(struct fs_uart_platform_info *data)
379 int smc_no = fs_uart_id_fsid2smc(data->fs_no);
383 init_smc1_uart_ioports(data);
384 data->brg = data->clk_rx;
387 init_smc2_uart_ioports(data);
388 data->brg = data->clk_rx;
391 printk(KERN_ERR "init_scc_ioports: invalid SCC number\n");
396 int platform_device_skip(const char *model, int id)
398 #ifdef CONFIG_MPC8xx_SECOND_ETH_SCC3
399 const char *dev = "FEC";
402 const char *dev = "SCC";
406 if (!strcmp(model, dev) && n == id)
412 static void __init mpc885ads_setup_arch(void)
414 struct device_node *cpu;
416 cpu = of_find_node_by_type(NULL, "cpu");
418 const unsigned int *fp;
420 fp = of_get_property(cpu, "clock-frequency", NULL);
422 loops_per_jiffy = *fp / HZ;
424 loops_per_jiffy = 50000000 / HZ;
430 mpc885ads_board_setup();
435 static int __init mpc885ads_probe(void)
437 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
441 if (strcmp(model, "MPC885ADS"))
447 define_machine(mpc885_ads) {
448 .name = "MPC885 ADS",
449 .probe = mpc885ads_probe,
450 .setup_arch = mpc885ads_setup_arch,
451 .init_IRQ = m8xx_pic_init,
452 .show_cpuinfo = mpc8xx_show_cpuinfo,
453 .get_irq = mpc8xx_get_irq,
454 .restart = mpc8xx_restart,
455 .calibrate_decr = mpc8xx_calibrate_decr,
456 .set_rtc_time = mpc8xx_set_rtc_time,
457 .get_rtc_time = mpc8xx_get_rtc_time,