Commit da0a5f0c authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Kumar Gala

[POWERPC] Add bootwrapper function to get virtual reg from the device tree.

This patch adds a new generic device tree processing function that retrieves
virtual reg addresses from the device tree to the bootwrapper code. It also
updates the bootwrapper code to use the new function.

dt_get_virtual_reg() retrieves the virtual reg addresses from the
"virtual-reg" property. If the property can't be found, it uses the "reg"
property and walks the tree to translate it to absolute addresses.
Signed-off-by: default avatarLaurent Pinchart <laurentp@cse-semaphore.com>
Acked-by: default avatarScott Wood <scottwood@freescale.com>
Signed-off-by: default avatarKumar Gala <galak@kernel.crashing.org>
parent d464df26
...@@ -177,7 +177,6 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp) ...@@ -177,7 +177,6 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)
{ {
void *reg_virt[2]; void *reg_virt[2];
int is_smc = 0, is_cpm2 = 0, n; int is_smc = 0, is_cpm2 = 0, n;
unsigned long reg_phys;
void *parent, *muram; void *parent, *muram;
if (dt_is_compatible(devp, "fsl,cpm1-smc-uart")) { if (dt_is_compatible(devp, "fsl,cpm1-smc-uart")) {
...@@ -206,15 +205,8 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp) ...@@ -206,15 +205,8 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)
if (n < 4) if (n < 4)
return -1; return -1;
n = getprop(devp, "virtual-reg", reg_virt, sizeof(reg_virt)); if (dt_get_virtual_reg(devp, reg_virt, 2) < 2)
if (n < (int)sizeof(reg_virt)) { return -1;
for (n = 0; n < 2; n++) {
if (!dt_xlate_reg(devp, n, &reg_phys, NULL))
return -1;
reg_virt[n] = (void *)reg_phys;
}
}
if (is_smc) if (is_smc)
smc = reg_virt[0]; smc = reg_virt[0];
...@@ -227,15 +219,8 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp) ...@@ -227,15 +219,8 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)
if (!parent) if (!parent)
return -1; return -1;
n = getprop(parent, "virtual-reg", reg_virt, sizeof(reg_virt)); if (dt_get_virtual_reg(parent, &cpcr, 1) < 1)
if (n < (int)sizeof(reg_virt)) { return -1;
if (!dt_xlate_reg(parent, 0, &reg_phys, NULL))
return -1;
reg_virt[0] = (void *)reg_phys;
}
cpcr = reg_virt[0];
muram = finddevice("/soc/cpm/muram/data"); muram = finddevice("/soc/cpm/muram/data");
if (!muram) if (!muram)
...@@ -246,15 +231,8 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp) ...@@ -246,15 +231,8 @@ int cpm_console_init(void *devp, struct serial_console_data *scdp)
* is one for both parent and child. * is one for both parent and child.
*/ */
n = getprop(muram, "virtual-reg", reg_virt, sizeof(reg_virt)); if (dt_get_virtual_reg(muram, (void **)&muram_start, 1) < 1)
if (n < (int)sizeof(reg_virt)) { return -1;
if (!dt_xlate_reg(muram, 0, &reg_phys, NULL))
return -1;
reg_virt[0] = (void *)reg_phys;
}
muram_start = reg_virt[0];
n = getprop(muram, "reg", &muram_offset, 4); n = getprop(muram, "reg", &muram_offset, 4);
if (n < 4) if (n < 4)
......
...@@ -350,3 +350,23 @@ int dt_is_compatible(void *node, const char *compat) ...@@ -350,3 +350,23 @@ int dt_is_compatible(void *node, const char *compat)
return 0; return 0;
} }
int dt_get_virtual_reg(void *node, void **addr, int nres)
{
unsigned long xaddr;
int n;
n = getprop(node, "virtual-reg", addr, nres * 4);
if (n > 0)
return n / 4;
for (n = 0; n < nres; n++) {
if (!dt_xlate_reg(node, n, &xaddr, NULL))
break;
addr[n] = (void *)xaddr;
}
return n;
}
...@@ -51,14 +51,9 @@ static unsigned char psc_getc(void) ...@@ -51,14 +51,9 @@ static unsigned char psc_getc(void)
int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp) int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp)
{ {
int n;
/* Get the base address of the psc registers */ /* Get the base address of the psc registers */
n = getprop(devp, "virtual-reg", &psc, sizeof(psc)); if (dt_get_virtual_reg(devp, &psc, 1) < 1)
if (n != sizeof(psc)) { return -1;
if (!dt_xlate_reg(devp, 0, (void *)&psc, NULL))
return -1;
}
scdp->open = psc_open; scdp->open = psc_open;
scdp->putc = psc_putc; scdp->putc = psc_putc;
......
...@@ -55,15 +55,9 @@ static u8 ns16550_tstc(void) ...@@ -55,15 +55,9 @@ static u8 ns16550_tstc(void)
int ns16550_console_init(void *devp, struct serial_console_data *scdp) int ns16550_console_init(void *devp, struct serial_console_data *scdp)
{ {
int n; int n;
unsigned long reg_phys;
n = getprop(devp, "virtual-reg", &reg_base, sizeof(reg_base)); if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1)
if (n != sizeof(reg_base)) { return -1;
if (!dt_xlate_reg(devp, 0, &reg_phys, NULL))
return -1;
reg_base = (void *)reg_phys;
}
n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift)); n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift));
if (n != sizeof(reg_shift)) if (n != sizeof(reg_shift))
......
...@@ -95,6 +95,7 @@ int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size); ...@@ -95,6 +95,7 @@ int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr); int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
int dt_is_compatible(void *node, const char *compat); int dt_is_compatible(void *node, const char *compat);
void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize); void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
int dt_get_virtual_reg(void *node, void **addr, int nres);
static inline void *finddevice(const char *name) static inline void *finddevice(const char *name)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment