Skip to content

Commit

Permalink
powerpc, of_serial: Endianness issues setting up the serial ports
Browse files Browse the repository at this point in the history
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: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
Ian Munsie authored and Grant Likely committed Oct 7, 2010
1 parent 2548558 commit f14362d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions arch/powerpc/kernel/legacy_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ static int __init add_legacy_port(struct device_node *np, int want_index,
phys_addr_t taddr, unsigned long irq,
upf_t flags, int irq_check_parent)
{
const u32 *clk, *spd;
const __be32 *clk, *spd;
u32 clock = BASE_BAUD * 16;
int index;

/* get clock freq. if present */
clk = of_get_property(np, "clock-frequency", NULL);
if (clk && *clk)
clock = *clk;
clock = be32_to_cpup(clk);

/* get default speed if present */
spd = of_get_property(np, "current-speed", NULL);
Expand Down Expand Up @@ -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].np = of_node_get(np);
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;

printk(KERN_DEBUG "Found legacy serial port %d for %s\n",
Expand Down Expand Up @@ -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,
struct device_node *isa_brg)
{
const u32 *reg;
const __be32 *reg;
const char *typep;
int index = -1;
u64 taddr;
Expand All @@ -181,7 +181,7 @@ static int __init add_legacy_isa_port(struct device_node *np,
return -1;

/* 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;

/* Now look for an "ibm,aix-loc" property that gives us ordering
Expand All @@ -202,7 +202,7 @@ static int __init add_legacy_isa_port(struct device_node *np,
taddr = 0;

/* 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);

}
Expand Down Expand Up @@ -251,9 +251,9 @@ static int __init add_legacy_pci_port(struct device_node *np,
* we get to their "reg" property
*/
if (np != pci_dev) {
const u32 *reg = of_get_property(np, "reg", NULL);
if (reg && (*reg < 4))
index = lindex = *reg;
const __be32 *reg = of_get_property(np, "reg", NULL);
if (reg && (be32_to_cpup(reg) < 4))
index = lindex = be32_to_cpup(reg);
}

/* Local index means it's the Nth port in the PCI chip. Unfortunately
Expand Down Expand Up @@ -507,7 +507,7 @@ static int __init check_legacy_serial_console(void)
struct device_node *prom_stdout = NULL;
int i, speed = 0, offset = 0;
const char *name;
const u32 *spd;
const __be32 *spd;

DBG(" -> check_legacy_serial_console()\n");

Expand Down Expand Up @@ -547,7 +547,7 @@ static int __init check_legacy_serial_console(void)
}
spd = of_get_property(prom_stdout, "current-speed", NULL);
if (spd)
speed = *spd;
speed = be32_to_cpup(spd);

if (strcmp(name, "serial") != 0)
goto not_found;
Expand Down
12 changes: 6 additions & 6 deletions drivers/serial/of_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
{
struct resource resource;
struct device_node *np = ofdev->dev.of_node;
const unsigned int *clk, *spd;
const u32 *prop;
const __be32 *clk, *spd;
const __be32 *prop;
int ret, prop_size;

memset(port, 0, sizeof *port);
Expand All @@ -55,23 +55,23 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
/* Check for shifted address mapping */
prop = of_get_property(np, "reg-offset", &prop_size);
if (prop && (prop_size == sizeof(u32)))
port->mapbase += *prop;
port->mapbase += be32_to_cpup(prop);

/* Check for registers offset within the devices address range */
prop = of_get_property(np, "reg-shift", &prop_size);
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->iotype = UPIO_MEM;
port->type = type;
port->uartclk = *clk;
port->uartclk = be32_to_cpup(clk);
port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
| UPF_FIXED_PORT | UPF_FIXED_TYPE;
port->dev = &ofdev->dev;
/* If current-speed was set, then try not to change it. */
if (spd)
port->custom_divisor = *clk / (16 * (*spd));
port->custom_divisor = be32_to_cpup(clk) / (16 * (be32_to_cpup(spd)));

return 0;
}
Expand Down

0 comments on commit f14362d

Please sign in to comment.