2 * CPM serial console support.
4 * Copyright 2007 Freescale Semiconductor, Inc.
5 * Author: Scott Wood <scottwood@freescale.com>
7 * It is assumed that the firmware (or the platform file) has already set
48 u16 sc
; /* Status and Control */
49 u16 len
; /* Data length in buffer */
50 u8
*addr
; /* Buffer address in host memory */
54 static struct cpm_param
*param
;
55 static struct cpm_smc
*smc
;
56 static struct cpm_scc
*scc
;
57 struct cpm_bd
*tbdf
, *rbdf
;
59 static u8
*muram_start
;
60 static u32 muram_offset
;
62 static void (*do_cmd
)(int op
);
63 static void (*enable_port
)(void);
64 static void (*disable_port
)(void);
66 #define CPM_CMD_STOP_TX 4
67 #define CPM_CMD_RESTART_TX 6
68 #define CPM_CMD_INIT_RX_TX 0
70 static void cpm1_cmd(int op
)
72 while (in_be16(cpcr
) & 1)
75 out_be16(cpcr
, (op
<< 8) | cpm_cmd
| 1);
77 while (in_be16(cpcr
) & 1)
81 static void cpm2_cmd(int op
)
83 while (in_be32(cpcr
) & 0x10000)
86 out_be32(cpcr
, op
| cpm_cmd
| 0x10000);
88 while (in_be32(cpcr
) & 0x10000)
92 static void smc_disable_port(void)
94 do_cmd(CPM_CMD_STOP_TX
);
95 out_be16(&smc
->smcmr
, in_be16(&smc
->smcmr
) & ~3);
98 static void scc_disable_port(void)
100 do_cmd(CPM_CMD_STOP_TX
);
101 out_be32(&scc
->gsmrl
, in_be32(&scc
->gsmrl
) & ~0x30);
104 static void smc_enable_port(void)
106 out_be16(&smc
->smcmr
, in_be16(&smc
->smcmr
) | 3);
107 do_cmd(CPM_CMD_RESTART_TX
);
110 static void scc_enable_port(void)
112 out_be32(&scc
->gsmrl
, in_be32(&scc
->gsmrl
) | 0x30);
113 do_cmd(CPM_CMD_RESTART_TX
);
116 static int cpm_serial_open(void)
120 out_8(¶m
->rfcr
, 0x10);
121 out_8(¶m
->tfcr
, 0x10);
123 rbdf
= (struct cpm_bd
*)muram_start
;
124 rbdf
->addr
= (u8
*)(rbdf
+ 2);
129 tbdf
->addr
= (u8
*)(rbdf
+ 2) + 1;
134 out_be16(¶m
->rbase
, muram_offset
);
135 out_be16(¶m
->tbase
, muram_offset
+ sizeof(struct cpm_bd
));
137 do_cmd(CPM_CMD_INIT_RX_TX
);
143 static void cpm_serial_putc(unsigned char c
)
145 while (tbdf
->sc
& 0x8000)
155 static unsigned char cpm_serial_tstc(void)
158 return !(rbdf
->sc
& 0x8000);
161 static unsigned char cpm_serial_getc(void)
165 while (!cpm_serial_tstc())
176 int cpm_console_init(void *devp
, struct serial_console_data
*scdp
)
179 int is_smc
= 0, is_cpm2
= 0, n
;
180 unsigned long reg_phys
;
181 void *parent
, *muram
;
183 if (dt_is_compatible(devp
, "fsl,cpm1-smc-uart")) {
185 } else if (dt_is_compatible(devp
, "fsl,cpm2-scc-uart")) {
187 } else if (dt_is_compatible(devp
, "fsl,cpm2-smc-uart")) {
193 enable_port
= smc_enable_port
;
194 disable_port
= smc_disable_port
;
196 enable_port
= scc_enable_port
;
197 disable_port
= scc_disable_port
;
205 n
= getprop(devp
, "fsl,cpm-command", &cpm_cmd
, 4);
209 n
= getprop(devp
, "virtual-reg", reg_virt
, sizeof(reg_virt
));
210 if (n
< (int)sizeof(reg_virt
)) {
211 for (n
= 0; n
< 2; n
++) {
212 if (!dt_xlate_reg(devp
, n
, ®_phys
, NULL
))
215 reg_virt
[n
] = (void *)reg_phys
;
226 parent
= get_parent(devp
);
230 n
= getprop(parent
, "virtual-reg", reg_virt
, sizeof(reg_virt
));
231 if (n
< (int)sizeof(reg_virt
)) {
232 if (!dt_xlate_reg(parent
, 0, ®_phys
, NULL
))
235 reg_virt
[0] = (void *)reg_phys
;
240 muram
= finddevice("/soc/cpm/muram/data");
244 /* For bootwrapper-compatible device trees, we assume that the first
245 * entry has at least 18 bytes, and that #address-cells/#data-cells
246 * is one for both parent and child.
249 n
= getprop(muram
, "virtual-reg", reg_virt
, sizeof(reg_virt
));
250 if (n
< (int)sizeof(reg_virt
)) {
251 if (!dt_xlate_reg(muram
, 0, ®_phys
, NULL
))
254 reg_virt
[0] = (void *)reg_phys
;
257 muram_start
= reg_virt
[0];
259 n
= getprop(muram
, "reg", &muram_offset
, 4);
263 scdp
->open
= cpm_serial_open
;
264 scdp
->putc
= cpm_serial_putc
;
265 scdp
->getc
= cpm_serial_getc
;
266 scdp
->tstc
= cpm_serial_tstc
;