提交 f14362d1 编写于 作者: I Ian Munsie 提交者: Grant Likely

powerpc, of_serial: Endianness issues setting up the serial ports

The speed and clock of the serial ports is retrieved from the device
tree in both the PowerPC legacy serial code and the Open Firmware serial
driver, therefore they need to handle the fact that the device tree is
always big endian, while the CPU may not be.

Also fix other device tree references in the legacy serial code.
Signed-off-by: NIan Munsie <imunsie@au1.ibm.com>
Signed-off-by: NGrant Likely <grant.likely@secretlab.ca>
上级 25485584
...@@ -52,14 +52,14 @@ static int __init add_legacy_port(struct device_node *np, int want_index, ...@@ -52,14 +52,14 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
phys_addr_t taddr, unsigned long irq, phys_addr_t taddr, unsigned long irq,
upf_t flags, int irq_check_parent) upf_t flags, int irq_check_parent)
{ {
const u32 *clk, *spd; const __be32 *clk, *spd;
u32 clock = BASE_BAUD * 16; u32 clock = BASE_BAUD * 16;
int index; int index;
/* get clock freq. if present */ /* get clock freq. if present */
clk = of_get_property(np, "clock-frequency", NULL); clk = of_get_property(np, "clock-frequency", NULL);
if (clk && *clk) if (clk && *clk)
clock = *clk; clock = be32_to_cpup(clk);
/* get default speed if present */ /* get default speed if present */
spd = of_get_property(np, "current-speed", NULL); spd = of_get_property(np, "current-speed", NULL);
...@@ -109,7 +109,7 @@ static int __init add_legacy_port(struct device_node *np, int want_index, ...@@ -109,7 +109,7 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
legacy_serial_infos[index].taddr = taddr; legacy_serial_infos[index].taddr = taddr;
legacy_serial_infos[index].np = of_node_get(np); legacy_serial_infos[index].np = of_node_get(np);
legacy_serial_infos[index].clock = clock; legacy_serial_infos[index].clock = clock;
legacy_serial_infos[index].speed = spd ? *spd : 0; legacy_serial_infos[index].speed = spd ? be32_to_cpup(spd) : 0;
legacy_serial_infos[index].irq_check_parent = irq_check_parent; legacy_serial_infos[index].irq_check_parent = irq_check_parent;
printk(KERN_DEBUG "Found legacy serial port %d for %s\n", printk(KERN_DEBUG "Found legacy serial port %d for %s\n",
...@@ -168,7 +168,7 @@ static int __init add_legacy_soc_port(struct device_node *np, ...@@ -168,7 +168,7 @@ static int __init add_legacy_soc_port(struct device_node *np,
static int __init add_legacy_isa_port(struct device_node *np, static int __init add_legacy_isa_port(struct device_node *np,
struct device_node *isa_brg) struct device_node *isa_brg)
{ {
const u32 *reg; const __be32 *reg;
const char *typep; const char *typep;
int index = -1; int index = -1;
u64 taddr; u64 taddr;
...@@ -181,7 +181,7 @@ static int __init add_legacy_isa_port(struct device_node *np, ...@@ -181,7 +181,7 @@ static int __init add_legacy_isa_port(struct device_node *np,
return -1; return -1;
/* Verify it's an IO port, we don't support anything else */ /* Verify it's an IO port, we don't support anything else */
if (!(reg[0] & 0x00000001)) if (!(be32_to_cpu(reg[0]) & 0x00000001))
return -1; return -1;
/* Now look for an "ibm,aix-loc" property that gives us ordering /* Now look for an "ibm,aix-loc" property that gives us ordering
...@@ -202,7 +202,7 @@ static int __init add_legacy_isa_port(struct device_node *np, ...@@ -202,7 +202,7 @@ static int __init add_legacy_isa_port(struct device_node *np,
taddr = 0; taddr = 0;
/* Add port, irq will be dealt with later */ /* Add port, irq will be dealt with later */
return add_legacy_port(np, index, UPIO_PORT, reg[1], taddr, return add_legacy_port(np, index, UPIO_PORT, be32_to_cpu(reg[1]), taddr,
NO_IRQ, UPF_BOOT_AUTOCONF, 0); NO_IRQ, UPF_BOOT_AUTOCONF, 0);
} }
...@@ -251,9 +251,9 @@ static int __init add_legacy_pci_port(struct device_node *np, ...@@ -251,9 +251,9 @@ static int __init add_legacy_pci_port(struct device_node *np,
* we get to their "reg" property * we get to their "reg" property
*/ */
if (np != pci_dev) { if (np != pci_dev) {
const u32 *reg = of_get_property(np, "reg", NULL); const __be32 *reg = of_get_property(np, "reg", NULL);
if (reg && (*reg < 4)) if (reg && (be32_to_cpup(reg) < 4))
index = lindex = *reg; index = lindex = be32_to_cpup(reg);
} }
/* Local index means it's the Nth port in the PCI chip. Unfortunately /* Local index means it's the Nth port in the PCI chip. Unfortunately
...@@ -507,7 +507,7 @@ static int __init check_legacy_serial_console(void) ...@@ -507,7 +507,7 @@ static int __init check_legacy_serial_console(void)
struct device_node *prom_stdout = NULL; struct device_node *prom_stdout = NULL;
int i, speed = 0, offset = 0; int i, speed = 0, offset = 0;
const char *name; const char *name;
const u32 *spd; const __be32 *spd;
DBG(" -> check_legacy_serial_console()\n"); DBG(" -> check_legacy_serial_console()\n");
...@@ -547,7 +547,7 @@ static int __init check_legacy_serial_console(void) ...@@ -547,7 +547,7 @@ static int __init check_legacy_serial_console(void)
} }
spd = of_get_property(prom_stdout, "current-speed", NULL); spd = of_get_property(prom_stdout, "current-speed", NULL);
if (spd) if (spd)
speed = *spd; speed = be32_to_cpup(spd);
if (strcmp(name, "serial") != 0) if (strcmp(name, "serial") != 0)
goto not_found; goto not_found;
......
...@@ -31,8 +31,8 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev, ...@@ -31,8 +31,8 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
{ {
struct resource resource; struct resource resource;
struct device_node *np = ofdev->dev.of_node; struct device_node *np = ofdev->dev.of_node;
const unsigned int *clk, *spd; const __be32 *clk, *spd;
const u32 *prop; const __be32 *prop;
int ret, prop_size; int ret, prop_size;
memset(port, 0, sizeof *port); memset(port, 0, sizeof *port);
...@@ -55,23 +55,23 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev, ...@@ -55,23 +55,23 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
/* Check for shifted address mapping */ /* Check for shifted address mapping */
prop = of_get_property(np, "reg-offset", &prop_size); prop = of_get_property(np, "reg-offset", &prop_size);
if (prop && (prop_size == sizeof(u32))) if (prop && (prop_size == sizeof(u32)))
port->mapbase += *prop; port->mapbase += be32_to_cpup(prop);
/* Check for registers offset within the devices address range */ /* Check for registers offset within the devices address range */
prop = of_get_property(np, "reg-shift", &prop_size); prop = of_get_property(np, "reg-shift", &prop_size);
if (prop && (prop_size == sizeof(u32))) if (prop && (prop_size == sizeof(u32)))
port->regshift = *prop; port->regshift = be32_to_cpup(prop);
port->irq = irq_of_parse_and_map(np, 0); port->irq = irq_of_parse_and_map(np, 0);
port->iotype = UPIO_MEM; port->iotype = UPIO_MEM;
port->type = type; port->type = type;
port->uartclk = *clk; port->uartclk = be32_to_cpup(clk);
port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
| UPF_FIXED_PORT | UPF_FIXED_TYPE; | UPF_FIXED_PORT | UPF_FIXED_TYPE;
port->dev = &ofdev->dev; port->dev = &ofdev->dev;
/* If current-speed was set, then try not to change it. */ /* If current-speed was set, then try not to change it. */
if (spd) if (spd)
port->custom_divisor = *clk / (16 * (*spd)); port->custom_divisor = be32_to_cpup(clk) / (16 * (be32_to_cpup(spd)));
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册