diff options
author | Heikki Krogerus <heikki.krogerus@linux.intel.com> | 2013-01-10 04:25:08 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-16 02:03:00 -0500 |
commit | a7260c8ce07d06da4cbb09120b4e9e8074d122cc (patch) | |
tree | bc83481d2eaea9cc72c38536f085cbcc11cb3ae7 /drivers/tty/serial/8250 | |
parent | f93366ff9ac282fc01effe70df0dd84418f8344e (diff) |
serial: 8250_dw: Move device tree code to separate function
Trivial cleanup. This makes it easier to add different
methods to enumerate the device, for example ACPI 5.0
enumeration.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Jamie Iles <jamie@jamieiles.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/serial/8250')
-rw-r--r-- | drivers/tty/serial/8250/8250_dw.c | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index e1749012e8e3..d96e02e25be4 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c | |||
@@ -87,25 +87,51 @@ static int dw8250_handle_irq(struct uart_port *p) | |||
87 | return 0; | 87 | return 0; |
88 | } | 88 | } |
89 | 89 | ||
90 | static int dw8250_probe_of(struct uart_port *p) | ||
91 | { | ||
92 | struct device_node *np = p->dev->of_node; | ||
93 | u32 val; | ||
94 | |||
95 | if (!of_property_read_u32(np, "reg-io-width", &val)) { | ||
96 | switch (val) { | ||
97 | case 1: | ||
98 | break; | ||
99 | case 4: | ||
100 | p->iotype = UPIO_MEM32; | ||
101 | p->serial_in = dw8250_serial_in32; | ||
102 | p->serial_out = dw8250_serial_out32; | ||
103 | break; | ||
104 | default: | ||
105 | dev_err(p->dev, "unsupported reg-io-width (%u)\n", val); | ||
106 | return -EINVAL; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | if (!of_property_read_u32(np, "reg-shift", &val)) | ||
111 | p->regshift = val; | ||
112 | |||
113 | if (of_property_read_u32(np, "clock-frequency", &val)) { | ||
114 | dev_err(p->dev, "no clock-frequency property set\n"); | ||
115 | return -EINVAL; | ||
116 | } | ||
117 | p->uartclk = val; | ||
118 | |||
119 | return 0; | ||
120 | } | ||
121 | |||
90 | static int dw8250_probe(struct platform_device *pdev) | 122 | static int dw8250_probe(struct platform_device *pdev) |
91 | { | 123 | { |
92 | struct uart_8250_port uart = {}; | 124 | struct uart_8250_port uart = {}; |
93 | struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 125 | struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
94 | struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 126 | struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
95 | struct device_node *np = pdev->dev.of_node; | ||
96 | u32 val; | ||
97 | struct dw8250_data *data; | 127 | struct dw8250_data *data; |
128 | int err; | ||
98 | 129 | ||
99 | if (!regs || !irq) { | 130 | if (!regs || !irq) { |
100 | dev_err(&pdev->dev, "no registers/irq defined\n"); | 131 | dev_err(&pdev->dev, "no registers/irq defined\n"); |
101 | return -EINVAL; | 132 | return -EINVAL; |
102 | } | 133 | } |
103 | 134 | ||
104 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | ||
105 | if (!data) | ||
106 | return -ENOMEM; | ||
107 | uart.port.private_data = data; | ||
108 | |||
109 | spin_lock_init(&uart.port.lock); | 135 | spin_lock_init(&uart.port.lock); |
110 | uart.port.mapbase = regs->start; | 136 | uart.port.mapbase = regs->start; |
111 | uart.port.irq = irq->start; | 137 | uart.port.irq = irq->start; |
@@ -121,30 +147,20 @@ static int dw8250_probe(struct platform_device *pdev) | |||
121 | uart.port.iotype = UPIO_MEM; | 147 | uart.port.iotype = UPIO_MEM; |
122 | uart.port.serial_in = dw8250_serial_in; | 148 | uart.port.serial_in = dw8250_serial_in; |
123 | uart.port.serial_out = dw8250_serial_out; | 149 | uart.port.serial_out = dw8250_serial_out; |
124 | if (!of_property_read_u32(np, "reg-io-width", &val)) { | 150 | |
125 | switch (val) { | 151 | if (pdev->dev.of_node) { |
126 | case 1: | 152 | err = dw8250_probe_of(&uart.port); |
127 | break; | 153 | if (err) |
128 | case 4: | 154 | return err; |
129 | uart.port.iotype = UPIO_MEM32; | 155 | } else { |
130 | uart.port.serial_in = dw8250_serial_in32; | 156 | return -ENODEV; |
131 | uart.port.serial_out = dw8250_serial_out32; | ||
132 | break; | ||
133 | default: | ||
134 | dev_err(&pdev->dev, "unsupported reg-io-width (%u)\n", | ||
135 | val); | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | } | 157 | } |
139 | 158 | ||
140 | if (!of_property_read_u32(np, "reg-shift", &val)) | 159 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
141 | uart.port.regshift = val; | 160 | if (!data) |
161 | return -ENOMEM; | ||
142 | 162 | ||
143 | if (of_property_read_u32(np, "clock-frequency", &val)) { | 163 | uart.port.private_data = data; |
144 | dev_err(&pdev->dev, "no clock-frequency property set\n"); | ||
145 | return -EINVAL; | ||
146 | } | ||
147 | uart.port.uartclk = val; | ||
148 | 164 | ||
149 | data->line = serial8250_register_8250_port(&uart); | 165 | data->line = serial8250_register_8250_port(&uart); |
150 | if (data->line < 0) | 166 | if (data->line < 0) |
@@ -187,17 +203,17 @@ static int dw8250_resume(struct platform_device *pdev) | |||
187 | #define dw8250_resume NULL | 203 | #define dw8250_resume NULL |
188 | #endif /* CONFIG_PM */ | 204 | #endif /* CONFIG_PM */ |
189 | 205 | ||
190 | static const struct of_device_id dw8250_match[] = { | 206 | static const struct of_device_id dw8250_of_match[] = { |
191 | { .compatible = "snps,dw-apb-uart" }, | 207 | { .compatible = "snps,dw-apb-uart" }, |
192 | { /* Sentinel */ } | 208 | { /* Sentinel */ } |
193 | }; | 209 | }; |
194 | MODULE_DEVICE_TABLE(of, dw8250_match); | 210 | MODULE_DEVICE_TABLE(of, dw8250_of_match); |
195 | 211 | ||
196 | static struct platform_driver dw8250_platform_driver = { | 212 | static struct platform_driver dw8250_platform_driver = { |
197 | .driver = { | 213 | .driver = { |
198 | .name = "dw-apb-uart", | 214 | .name = "dw-apb-uart", |
199 | .owner = THIS_MODULE, | 215 | .owner = THIS_MODULE, |
200 | .of_match_table = dw8250_match, | 216 | .of_match_table = dw8250_of_match, |
201 | }, | 217 | }, |
202 | .probe = dw8250_probe, | 218 | .probe = dw8250_probe, |
203 | .remove = dw8250_remove, | 219 | .remove = dw8250_remove, |