aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/boot/cpm-serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/boot/cpm-serial.c')
-rw-r--r--arch/powerpc/boot/cpm-serial.c117
1 files changed, 71 insertions, 46 deletions
diff --git a/arch/powerpc/boot/cpm-serial.c b/arch/powerpc/boot/cpm-serial.c
index 28296facb2ae..19dc15abe43d 100644
--- a/arch/powerpc/boot/cpm-serial.c
+++ b/arch/powerpc/boot/cpm-serial.c
@@ -11,6 +11,7 @@
11#include "types.h" 11#include "types.h"
12#include "io.h" 12#include "io.h"
13#include "ops.h" 13#include "ops.h"
14#include "page.h"
14 15
15struct cpm_scc { 16struct cpm_scc {
16 u32 gsmrl; 17 u32 gsmrl;
@@ -42,6 +43,22 @@ struct cpm_param {
42 u16 tbase; 43 u16 tbase;
43 u8 rfcr; 44 u8 rfcr;
44 u8 tfcr; 45 u8 tfcr;
46 u16 mrblr;
47 u32 rstate;
48 u8 res1[4];
49 u16 rbptr;
50 u8 res2[6];
51 u32 tstate;
52 u8 res3[4];
53 u16 tbptr;
54 u8 res4[6];
55 u16 maxidl;
56 u16 idlc;
57 u16 brkln;
58 u16 brkec;
59 u16 brkcr;
60 u16 rmask;
61 u8 res5[4];
45}; 62};
46 63
47struct cpm_bd { 64struct cpm_bd {
@@ -54,10 +71,10 @@ static void *cpcr;
54static struct cpm_param *param; 71static struct cpm_param *param;
55static struct cpm_smc *smc; 72static struct cpm_smc *smc;
56static struct cpm_scc *scc; 73static struct cpm_scc *scc;
57struct cpm_bd *tbdf, *rbdf; 74static struct cpm_bd *tbdf, *rbdf;
58static u32 cpm_cmd; 75static u32 cpm_cmd;
59static u8 *muram_start; 76static void *cbd_addr;
60static u32 muram_offset; 77static u32 cbd_offset;
61 78
62static void (*do_cmd)(int op); 79static void (*do_cmd)(int op);
63static void (*enable_port)(void); 80static void (*enable_port)(void);
@@ -119,20 +136,25 @@ static int cpm_serial_open(void)
119 136
120 out_8(&param->rfcr, 0x10); 137 out_8(&param->rfcr, 0x10);
121 out_8(&param->tfcr, 0x10); 138 out_8(&param->tfcr, 0x10);
122 139 out_be16(&param->mrblr, 1);
123 rbdf = (struct cpm_bd *)muram_start; 140 out_be16(&param->maxidl, 0);
124 rbdf->addr = (u8 *)(rbdf + 2); 141 out_be16(&param->brkec, 0);
142 out_be16(&param->brkln, 0);
143 out_be16(&param->brkcr, 0);
144
145 rbdf = cbd_addr;
146 rbdf->addr = (u8 *)rbdf - 1;
125 rbdf->sc = 0xa000; 147 rbdf->sc = 0xa000;
126 rbdf->len = 1; 148 rbdf->len = 1;
127 149
128 tbdf = rbdf + 1; 150 tbdf = rbdf + 1;
129 tbdf->addr = (u8 *)(rbdf + 2) + 1; 151 tbdf->addr = (u8 *)rbdf - 2;
130 tbdf->sc = 0x2000; 152 tbdf->sc = 0x2000;
131 tbdf->len = 1; 153 tbdf->len = 1;
132 154
133 sync(); 155 sync();
134 out_be16(&param->rbase, muram_offset); 156 out_be16(&param->rbase, cbd_offset);
135 out_be16(&param->tbase, muram_offset + sizeof(struct cpm_bd)); 157 out_be16(&param->tbase, cbd_offset + sizeof(struct cpm_bd));
136 158
137 do_cmd(CPM_CMD_INIT_RX_TX); 159 do_cmd(CPM_CMD_INIT_RX_TX);
138 160
@@ -175,10 +197,12 @@ static unsigned char cpm_serial_getc(void)
175 197
176int cpm_console_init(void *devp, struct serial_console_data *scdp) 198int cpm_console_init(void *devp, struct serial_console_data *scdp)
177{ 199{
178 void *reg_virt[2]; 200 void *vreg[2];
179 int is_smc = 0, is_cpm2 = 0, n; 201 u32 reg[2];
180 unsigned long reg_phys; 202 int is_smc = 0, is_cpm2 = 0;
181 void *parent, *muram; 203 void *parent, *muram;
204 void *muram_addr;
205 unsigned long muram_offset, muram_size;
182 206
183 if (dt_is_compatible(devp, "fsl,cpm1-smc-uart")) { 207 if (dt_is_compatible(devp, "fsl,cpm1-smc-uart")) {
184 is_smc = 1; 208 is_smc = 1;
@@ -202,63 +226,64 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)
202 else 226 else
203 do_cmd = cpm1_cmd; 227 do_cmd = cpm1_cmd;
204 228
205 n = getprop(devp, "fsl,cpm-command", &cpm_cmd, 4); 229 if (getprop(devp, "fsl,cpm-command", &cpm_cmd, 4) < 4)
206 if (n < 4)
207 return -1; 230 return -1;
208 231
209 n = getprop(devp, "virtual-reg", reg_virt, sizeof(reg_virt)); 232 if (dt_get_virtual_reg(devp, vreg, 2) < 2)
210 if (n < (int)sizeof(reg_virt)) { 233 return -1;
211 for (n = 0; n < 2; n++) {
212 if (!dt_xlate_reg(devp, n, &reg_phys, NULL))
213 return -1;
214
215 reg_virt[n] = (void *)reg_phys;
216 }
217 }
218 234
219 if (is_smc) 235 if (is_smc)
220 smc = reg_virt[0]; 236 smc = vreg[0];
221 else 237 else
222 scc = reg_virt[0]; 238 scc = vreg[0];
223 239
224 param = reg_virt[1]; 240 param = vreg[1];
225 241
226 parent = get_parent(devp); 242 parent = get_parent(devp);
227 if (!parent) 243 if (!parent)
228 return -1; 244 return -1;
229 245
230 n = getprop(parent, "virtual-reg", reg_virt, sizeof(reg_virt)); 246 if (dt_get_virtual_reg(parent, &cpcr, 1) < 1)
231 if (n < (int)sizeof(reg_virt)) { 247 return -1;
232 if (!dt_xlate_reg(parent, 0, &reg_phys, NULL))
233 return -1;
234
235 reg_virt[0] = (void *)reg_phys;
236 }
237
238 cpcr = reg_virt[0];
239 248
240 muram = finddevice("/soc/cpm/muram/data"); 249 muram = finddevice("/soc/cpm/muram/data");
241 if (!muram) 250 if (!muram)
242 return -1; 251 return -1;
243 252
244 /* For bootwrapper-compatible device trees, we assume that the first 253 /* For bootwrapper-compatible device trees, we assume that the first
245 * entry has at least 18 bytes, and that #address-cells/#data-cells 254 * entry has at least 128 bytes, and that #address-cells/#data-cells
246 * is one for both parent and child. 255 * is one for both parent and child.
247 */ 256 */
248 257
249 n = getprop(muram, "virtual-reg", reg_virt, sizeof(reg_virt)); 258 if (dt_get_virtual_reg(muram, &muram_addr, 1) < 1)
250 if (n < (int)sizeof(reg_virt)) { 259 return -1;
251 if (!dt_xlate_reg(muram, 0, &reg_phys, NULL))
252 return -1;
253 260
254 reg_virt[0] = (void *)reg_phys; 261 if (getprop(muram, "reg", reg, 8) < 8)
255 } 262 return -1;
256 263
257 muram_start = reg_virt[0]; 264 muram_offset = reg[0];
265 muram_size = reg[1];
258 266
259 n = getprop(muram, "reg", &muram_offset, 4); 267 /* Store the buffer descriptors at the end of the first muram chunk.
260 if (n < 4) 268 * For SMC ports on CPM2-based platforms, relocate the parameter RAM
261 return -1; 269 * just before the buffer descriptors.
270 */
271
272 cbd_offset = muram_offset + muram_size - 2 * sizeof(struct cpm_bd);
273
274 if (is_cpm2 && is_smc) {
275 u16 *smc_base = (u16 *)param;
276 u16 pram_offset;
277
278 pram_offset = cbd_offset - 64;
279 pram_offset = _ALIGN_DOWN(pram_offset, 64);
280
281 disable_port();
282 out_be16(smc_base, pram_offset);
283 param = muram_addr - muram_offset + pram_offset;
284 }
285
286 cbd_addr = muram_addr - muram_offset + cbd_offset;
262 287
263 scdp->open = cpm_serial_open; 288 scdp->open = cpm_serial_open;
264 scdp->putc = cpm_serial_putc; 289 scdp->putc = cpm_serial_putc;