diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2011-06-30 14:39:12 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2011-07-04 02:44:09 -0400 |
commit | b84e773119e1401e6ebd8906fb0b2a43bbe64871 (patch) | |
tree | eaa157c0dd97d18d17b933e58912fd1dcd3a717b /drivers/tty/serial/of_serial.c | |
parent | f09bc831b7693f93ecb95dea7180d55b45b88e76 (diff) |
tty/serial: change of_serial to use new of_property_read_u32() api
Simplifies the code a bit and drops a few lines.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'drivers/tty/serial/of_serial.c')
-rw-r--r-- | drivers/tty/serial/of_serial.c | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c index 36038ed8f09..dbfbfda2753 100644 --- a/drivers/tty/serial/of_serial.c +++ b/drivers/tty/serial/of_serial.c | |||
@@ -32,17 +32,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev, | |||
32 | { | 32 | { |
33 | struct resource resource; | 33 | struct resource resource; |
34 | struct device_node *np = ofdev->dev.of_node; | 34 | struct device_node *np = ofdev->dev.of_node; |
35 | const __be32 *clk, *spd; | 35 | u32 clk, spd, prop; |
36 | const __be32 *prop; | 36 | int ret; |
37 | int ret, prop_size; | ||
38 | 37 | ||
39 | memset(port, 0, sizeof *port); | 38 | memset(port, 0, sizeof *port); |
40 | spd = of_get_property(np, "current-speed", NULL); | 39 | if (of_property_read_u32(np, "clock-frequency", &clk)) { |
41 | clk = of_get_property(np, "clock-frequency", NULL); | ||
42 | if (!clk) { | ||
43 | dev_warn(&ofdev->dev, "no clock-frequency property set\n"); | 40 | dev_warn(&ofdev->dev, "no clock-frequency property set\n"); |
44 | return -ENODEV; | 41 | return -ENODEV; |
45 | } | 42 | } |
43 | /* If current-speed was set, then try not to change it. */ | ||
44 | if (of_property_read_u32(np, "current-speed", &spd) == 0) | ||
45 | port->custom_divisor = clk / (16 * spd); | ||
46 | 46 | ||
47 | ret = of_address_to_resource(np, 0, &resource); | 47 | ret = of_address_to_resource(np, 0, &resource); |
48 | if (ret) { | 48 | if (ret) { |
@@ -54,20 +54,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev, | |||
54 | port->mapbase = resource.start; | 54 | port->mapbase = resource.start; |
55 | 55 | ||
56 | /* Check for shifted address mapping */ | 56 | /* Check for shifted address mapping */ |
57 | prop = of_get_property(np, "reg-offset", &prop_size); | 57 | if (of_property_read_u32(np, "reg-offset", &prop) == 0) |
58 | if (prop && (prop_size == sizeof(u32))) | 58 | port->mapbase += prop; |
59 | port->mapbase += be32_to_cpup(prop); | ||
60 | 59 | ||
61 | /* Check for registers offset within the devices address range */ | 60 | /* Check for registers offset within the devices address range */ |
62 | prop = of_get_property(np, "reg-shift", &prop_size); | 61 | if (of_property_read_u32(np, "reg-shift", &prop) == 0) |
63 | if (prop && (prop_size == sizeof(u32))) | 62 | port->regshift = prop; |
64 | port->regshift = be32_to_cpup(prop); | ||
65 | 63 | ||
66 | port->irq = irq_of_parse_and_map(np, 0); | 64 | port->irq = irq_of_parse_and_map(np, 0); |
67 | port->iotype = UPIO_MEM; | 65 | port->iotype = UPIO_MEM; |
68 | prop = of_get_property(np, "reg-io-width", &prop_size); | 66 | if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { |
69 | if (prop && (prop_size == sizeof(u32))) { | 67 | switch (prop) { |
70 | switch (be32_to_cpup(prop)) { | ||
71 | case 1: | 68 | case 1: |
72 | port->iotype = UPIO_MEM; | 69 | port->iotype = UPIO_MEM; |
73 | break; | 70 | break; |
@@ -75,21 +72,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev, | |||
75 | port->iotype = UPIO_MEM32; | 72 | port->iotype = UPIO_MEM32; |
76 | break; | 73 | break; |
77 | default: | 74 | default: |
78 | dev_warn(&ofdev->dev, | 75 | dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n", |
79 | "unsupported io width (%d bytes)\n", | 76 | prop); |
80 | be32_to_cpup(prop)); | ||
81 | return -EINVAL; | 77 | return -EINVAL; |
82 | } | 78 | } |
83 | } | 79 | } |
84 | 80 | ||
85 | port->type = type; | 81 | port->type = type; |
86 | port->uartclk = be32_to_cpup(clk); | 82 | port->uartclk = clk; |
87 | port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP | 83 | port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP |
88 | | UPF_FIXED_PORT | UPF_FIXED_TYPE; | 84 | | UPF_FIXED_PORT | UPF_FIXED_TYPE; |
89 | port->dev = &ofdev->dev; | 85 | port->dev = &ofdev->dev; |
90 | /* If current-speed was set, then try not to change it. */ | ||
91 | if (spd) | ||
92 | port->custom_divisor = be32_to_cpup(clk) / (16 * (be32_to_cpup(spd))); | ||
93 | 86 | ||
94 | return 0; | 87 | return 0; |
95 | } | 88 | } |