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
65 u16 sc
; /* Status and Control */
66 u16 len
; /* Data length in buffer */
67 u8
*addr
; /* Buffer address in host memory */
71 static struct cpm_param
*param
;
72 static struct cpm_smc
*smc
;
73 static struct cpm_scc
*scc
;
74 static struct cpm_bd
*tbdf
, *rbdf
;
76 static void *cbd_addr
;
77 static u32 cbd_offset
;
79 static void (*do_cmd
)(int op
);
80 static void (*enable_port
)(void);
81 static void (*disable_port
)(void);
83 #define CPM_CMD_STOP_TX 4
84 #define CPM_CMD_RESTART_TX 6
85 #define CPM_CMD_INIT_RX_TX 0
87 static void cpm1_cmd(int op
)
89 while (in_be16(cpcr
) & 1)
92 out_be16(cpcr
, (op
<< 8) | cpm_cmd
| 1);
94 while (in_be16(cpcr
) & 1)
98 static void cpm2_cmd(int op
)
100 while (in_be32(cpcr
) & 0x10000)
103 out_be32(cpcr
, op
| cpm_cmd
| 0x10000);
105 while (in_be32(cpcr
) & 0x10000)
109 static void smc_disable_port(void)
111 do_cmd(CPM_CMD_STOP_TX
);
112 out_be16(&smc
->smcmr
, in_be16(&smc
->smcmr
) & ~3);
115 static void scc_disable_port(void)
117 do_cmd(CPM_CMD_STOP_TX
);
118 out_be32(&scc
->gsmrl
, in_be32(&scc
->gsmrl
) & ~0x30);
121 static void smc_enable_port(void)
123 out_be16(&smc
->smcmr
, in_be16(&smc
->smcmr
) | 3);
124 do_cmd(CPM_CMD_RESTART_TX
);
127 static void scc_enable_port(void)
129 out_be32(&scc
->gsmrl
, in_be32(&scc
->gsmrl
) | 0x30);
130 do_cmd(CPM_CMD_RESTART_TX
);
133 static int cpm_serial_open(void)
137 out_8(¶m
->rfcr
, 0x10);
138 out_8(¶m
->tfcr
, 0x10);
139 out_be16(¶m
->mrblr
, 1);
140 out_be16(¶m
->maxidl
, 0);
141 out_be16(¶m
->brkec
, 0);
142 out_be16(¶m
->brkln
, 0);
143 out_be16(¶m
->brkcr
, 0);
146 rbdf
->addr
= (u8
*)rbdf
- 1;
151 tbdf
->addr
= (u8
*)rbdf
- 2;
156 out_be16(¶m
->rbase
, cbd_offset
);
157 out_be16(¶m
->tbase
, cbd_offset
+ sizeof(struct cpm_bd
));
159 do_cmd(CPM_CMD_INIT_RX_TX
);
165 static void cpm_serial_putc(unsigned char c
)
167 while (tbdf
->sc
& 0x8000)
177 static unsigned char cpm_serial_tstc(void)
180 return !(rbdf
->sc
& 0x8000);
183 static unsigned char cpm_serial_getc(void)
187 while (!cpm_serial_tstc())
198 int cpm_console_init(void *devp
, struct serial_console_data
*scdp
)
202 int is_smc
= 0, is_cpm2
= 0;
203 void *parent
, *muram
;
205 unsigned long muram_offset
, muram_size
;
207 if (dt_is_compatible(devp
, "fsl,cpm1-smc-uart")) {
209 } else if (dt_is_compatible(devp
, "fsl,cpm2-scc-uart")) {
211 } else if (dt_is_compatible(devp
, "fsl,cpm2-smc-uart")) {
217 enable_port
= smc_enable_port
;
218 disable_port
= smc_disable_port
;
220 enable_port
= scc_enable_port
;
221 disable_port
= scc_disable_port
;
229 if (getprop(devp
, "fsl,cpm-command", &cpm_cmd
, 4) < 4)
232 if (dt_get_virtual_reg(devp
, vreg
, 2) < 2)
242 parent
= get_parent(devp
);
246 if (dt_get_virtual_reg(parent
, &cpcr
, 1) < 1)
249 muram
= finddevice("/soc/cpm/muram/data");
253 /* For bootwrapper-compatible device trees, we assume that the first
254 * entry has at least 128 bytes, and that #address-cells/#data-cells
255 * is one for both parent and child.
258 if (dt_get_virtual_reg(muram
, &muram_addr
, 1) < 1)
261 if (getprop(muram
, "reg", reg
, 8) < 8)
264 muram_offset
= reg
[0];
267 /* Store the buffer descriptors at the end of the first muram chunk.
268 * For SMC ports on CPM2-based platforms, relocate the parameter RAM
269 * just before the buffer descriptors.
272 cbd_offset
= muram_offset
+ muram_size
- 2 * sizeof(struct cpm_bd
);
274 if (is_cpm2
&& is_smc
) {
275 u16
*smc_base
= (u16
*)param
;
278 pram_offset
= cbd_offset
- 64;
279 pram_offset
= _ALIGN_DOWN(pram_offset
, 64);
282 out_be16(smc_base
, pram_offset
);
283 param
= muram_addr
- muram_offset
+ pram_offset
;
286 cbd_addr
= muram_addr
- muram_offset
+ cbd_offset
;
288 scdp
->open
= cpm_serial_open
;
289 scdp
->putc
= cpm_serial_putc
;
290 scdp
->getc
= cpm_serial_getc
;
291 scdp
->tstc
= cpm_serial_tstc
;