diff options
-rw-r--r-- | drivers/serial/Kconfig | 21 | ||||
-rw-r--r-- | drivers/serial/Makefile | 1 | ||||
-rw-r--r-- | drivers/serial/max3107-aava.c | 344 | ||||
-rw-r--r-- | drivers/serial/max3107.c | 413 | ||||
-rw-r--r-- | drivers/serial/max3107.h | 85 | ||||
-rw-r--r-- | include/linux/serial_core.h | 4 |
6 files changed, 531 insertions, 337 deletions
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index fd406273cb71..c34c217878b3 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig | |||
@@ -542,20 +542,29 @@ config SERIAL_S5PV210 | |||
542 | help | 542 | help |
543 | Serial port support for Samsung's S5P Family of SoC's | 543 | Serial port support for Samsung's S5P Family of SoC's |
544 | 544 | ||
545 | |||
546 | config SERIAL_MAX3100 | ||
547 | tristate "MAX3100 support" | ||
548 | depends on SPI | ||
549 | select SERIAL_CORE | ||
550 | help | ||
551 | MAX3100 chip support | ||
552 | |||
545 | config SERIAL_MAX3107 | 553 | config SERIAL_MAX3107 |
546 | tristate "MAX3107 support" | 554 | tristate "MAX3107 support" |
547 | depends on SPI && GPIOLIB | 555 | depends on SPI |
548 | select SERIAL_CORE | 556 | select SERIAL_CORE |
549 | default y | ||
550 | help | 557 | help |
551 | MAX3107 chip support | 558 | MAX3107 chip support |
552 | 559 | ||
553 | config SERIAL_MAX3100 | 560 | config SERIAL_MAX3107_AAVA |
554 | tristate "MAX3100 support" | 561 | tristate "MAX3107 AAVA platform support" |
555 | depends on SPI | 562 | depends on X86_MRST && SERIAL_MAX3107 && GPIOLIB |
556 | select SERIAL_CORE | 563 | select SERIAL_CORE |
557 | help | 564 | help |
558 | MAX3100 chip support | 565 | Support for the MAX3107 chip configuration found on the AAVA |
566 | platform. Includes the extra initialisation and GPIO support | ||
567 | neded for this device. | ||
559 | 568 | ||
560 | config SERIAL_DZ | 569 | config SERIAL_DZ |
561 | bool "DECstation DZ serial driver" | 570 | bool "DECstation DZ serial driver" |
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 4cd0c0694917..424067ac3347 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile | |||
@@ -47,6 +47,7 @@ obj-$(CONFIG_SERIAL_S3C6400) += s3c6400.o | |||
47 | obj-$(CONFIG_SERIAL_S5PV210) += s5pv210.o | 47 | obj-$(CONFIG_SERIAL_S5PV210) += s5pv210.o |
48 | obj-$(CONFIG_SERIAL_MAX3100) += max3100.o | 48 | obj-$(CONFIG_SERIAL_MAX3100) += max3100.o |
49 | obj-$(CONFIG_SERIAL_MAX3107) += max3107.o | 49 | obj-$(CONFIG_SERIAL_MAX3107) += max3107.o |
50 | obj-$(CONFIG_SERIAL_MAX3107_AAVA) += max3107-aava.o | ||
50 | obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o | 51 | obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o |
51 | obj-$(CONFIG_SERIAL_MUX) += mux.o | 52 | obj-$(CONFIG_SERIAL_MUX) += mux.o |
52 | obj-$(CONFIG_SERIAL_68328) += 68328serial.o | 53 | obj-$(CONFIG_SERIAL_68328) += 68328serial.o |
diff --git a/drivers/serial/max3107-aava.c b/drivers/serial/max3107-aava.c new file mode 100644 index 000000000000..a1fe304f2f52 --- /dev/null +++ b/drivers/serial/max3107-aava.c | |||
@@ -0,0 +1,344 @@ | |||
1 | /* | ||
2 | * max3107.c - spi uart protocol driver for Maxim 3107 | ||
3 | * Based on max3100.c | ||
4 | * by Christian Pellegrin <chripell@evolware.org> | ||
5 | * and max3110.c | ||
6 | * by Feng Tang <feng.tang@intel.com> | ||
7 | * | ||
8 | * Copyright (C) Aavamobile 2009 | ||
9 | * | ||
10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | * | ||
26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include <linux/delay.h> | ||
31 | #include <linux/device.h> | ||
32 | #include <linux/serial_core.h> | ||
33 | #include <linux/serial.h> | ||
34 | #include <linux/spi/spi.h> | ||
35 | #include <linux/freezer.h> | ||
36 | #include <linux/platform_device.h> | ||
37 | #include <linux/gpio.h> | ||
38 | #include <linux/sfi.h> | ||
39 | #include <asm/mrst.h> | ||
40 | #include "max3107.h" | ||
41 | |||
42 | /* GPIO direction to input function */ | ||
43 | static int max3107_gpio_direction_in(struct gpio_chip *chip, unsigned offset) | ||
44 | { | ||
45 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
46 | u16 buf[1]; /* Buffer for SPI transfer */ | ||
47 | |||
48 | if (offset >= MAX3107_GPIO_COUNT) { | ||
49 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
50 | return -EINVAL; | ||
51 | } | ||
52 | |||
53 | /* Read current GPIO configuration register */ | ||
54 | buf[0] = MAX3107_GPIOCFG_REG; | ||
55 | /* Perform SPI transfer */ | ||
56 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { | ||
57 | dev_err(&s->spi->dev, "SPI transfer GPIO read failed\n"); | ||
58 | return -EIO; | ||
59 | } | ||
60 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
61 | |||
62 | /* Set GPIO to input */ | ||
63 | buf[0] &= ~(0x0001 << offset); | ||
64 | |||
65 | /* Write new GPIO configuration register value */ | ||
66 | buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIOCFG_REG); | ||
67 | /* Perform SPI transfer */ | ||
68 | if (max3107_rw(s, (u8 *)buf, NULL, 2)) { | ||
69 | dev_err(&s->spi->dev, "SPI transfer GPIO write failed\n"); | ||
70 | return -EIO; | ||
71 | } | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | /* GPIO direction to output function */ | ||
76 | static int max3107_gpio_direction_out(struct gpio_chip *chip, unsigned offset, | ||
77 | int value) | ||
78 | { | ||
79 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
80 | u16 buf[2]; /* Buffer for SPI transfers */ | ||
81 | |||
82 | if (offset >= MAX3107_GPIO_COUNT) { | ||
83 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
84 | return -EINVAL; | ||
85 | } | ||
86 | |||
87 | /* Read current GPIO configuration and data registers */ | ||
88 | buf[0] = MAX3107_GPIOCFG_REG; | ||
89 | buf[1] = MAX3107_GPIODATA_REG; | ||
90 | /* Perform SPI transfer */ | ||
91 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 4)) { | ||
92 | dev_err(&s->spi->dev, "SPI transfer gpio failed\n"); | ||
93 | return -EIO; | ||
94 | } | ||
95 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
96 | buf[1] &= MAX3107_SPI_RX_DATA_MASK; | ||
97 | |||
98 | /* Set GPIO to output */ | ||
99 | buf[0] |= (0x0001 << offset); | ||
100 | /* Set value */ | ||
101 | if (value) | ||
102 | buf[1] |= (0x0001 << offset); | ||
103 | else | ||
104 | buf[1] &= ~(0x0001 << offset); | ||
105 | |||
106 | /* Write new GPIO configuration and data register values */ | ||
107 | buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIOCFG_REG); | ||
108 | buf[1] |= (MAX3107_WRITE_BIT | MAX3107_GPIODATA_REG); | ||
109 | /* Perform SPI transfer */ | ||
110 | if (max3107_rw(s, (u8 *)buf, NULL, 4)) { | ||
111 | dev_err(&s->spi->dev, | ||
112 | "SPI transfer for GPIO conf data w failed\n"); | ||
113 | return -EIO; | ||
114 | } | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | /* GPIO value query function */ | ||
119 | static int max3107_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
120 | { | ||
121 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
122 | u16 buf[1]; /* Buffer for SPI transfer */ | ||
123 | |||
124 | if (offset >= MAX3107_GPIO_COUNT) { | ||
125 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
126 | return -EINVAL; | ||
127 | } | ||
128 | |||
129 | /* Read current GPIO data register */ | ||
130 | buf[0] = MAX3107_GPIODATA_REG; | ||
131 | /* Perform SPI transfer */ | ||
132 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { | ||
133 | dev_err(&s->spi->dev, "SPI transfer GPIO data r failed\n"); | ||
134 | return -EIO; | ||
135 | } | ||
136 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
137 | |||
138 | /* Return value */ | ||
139 | return buf[0] & (0x0001 << offset); | ||
140 | } | ||
141 | |||
142 | /* GPIO value set function */ | ||
143 | static void max3107_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
144 | { | ||
145 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
146 | u16 buf[2]; /* Buffer for SPI transfers */ | ||
147 | |||
148 | if (offset >= MAX3107_GPIO_COUNT) { | ||
149 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | /* Read current GPIO configuration registers*/ | ||
154 | buf[0] = MAX3107_GPIODATA_REG; | ||
155 | buf[1] = MAX3107_GPIOCFG_REG; | ||
156 | /* Perform SPI transfer */ | ||
157 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 4)) { | ||
158 | dev_err(&s->spi->dev, | ||
159 | "SPI transfer for GPIO data and config read failed\n"); | ||
160 | return; | ||
161 | } | ||
162 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
163 | buf[1] &= MAX3107_SPI_RX_DATA_MASK; | ||
164 | |||
165 | if (!(buf[1] & (0x0001 << offset))) { | ||
166 | /* Configured as input, can't set value */ | ||
167 | dev_warn(&s->spi->dev, | ||
168 | "Trying to set value for input GPIO\n"); | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | /* Set value */ | ||
173 | if (value) | ||
174 | buf[0] |= (0x0001 << offset); | ||
175 | else | ||
176 | buf[0] &= ~(0x0001 << offset); | ||
177 | |||
178 | /* Write new GPIO data register value */ | ||
179 | buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIODATA_REG); | ||
180 | /* Perform SPI transfer */ | ||
181 | if (max3107_rw(s, (u8 *)buf, NULL, 2)) | ||
182 | dev_err(&s->spi->dev, "SPI transfer GPIO data w failed\n"); | ||
183 | } | ||
184 | |||
185 | /* GPIO chip data */ | ||
186 | static struct gpio_chip max3107_gpio_chip = { | ||
187 | .owner = THIS_MODULE, | ||
188 | .direction_input = max3107_gpio_direction_in, | ||
189 | .direction_output = max3107_gpio_direction_out, | ||
190 | .get = max3107_gpio_get, | ||
191 | .set = max3107_gpio_set, | ||
192 | .can_sleep = 1, | ||
193 | .base = MAX3107_GPIO_BASE, | ||
194 | .ngpio = MAX3107_GPIO_COUNT, | ||
195 | }; | ||
196 | |||
197 | /** | ||
198 | * max3107_aava_reset - reset on AAVA systems | ||
199 | * @spi: The SPI device we are probing | ||
200 | * | ||
201 | * Reset the device ready for probing. | ||
202 | */ | ||
203 | |||
204 | static int max3107_aava_reset(struct spi_device *spi) | ||
205 | { | ||
206 | /* Reset the chip */ | ||
207 | if (gpio_request(MAX3107_RESET_GPIO, "max3107")) { | ||
208 | pr_err("Requesting RESET GPIO failed\n"); | ||
209 | return -EIO; | ||
210 | } | ||
211 | if (gpio_direction_output(MAX3107_RESET_GPIO, 0)) { | ||
212 | pr_err("Setting RESET GPIO to 0 failed\n"); | ||
213 | gpio_free(MAX3107_RESET_GPIO); | ||
214 | return -EIO; | ||
215 | } | ||
216 | msleep(MAX3107_RESET_DELAY); | ||
217 | if (gpio_direction_output(MAX3107_RESET_GPIO, 1)) { | ||
218 | pr_err("Setting RESET GPIO to 1 failed\n"); | ||
219 | gpio_free(MAX3107_RESET_GPIO); | ||
220 | return -EIO; | ||
221 | } | ||
222 | gpio_free(MAX3107_RESET_GPIO); | ||
223 | msleep(MAX3107_WAKEUP_DELAY); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | static int max3107_aava_configure(struct max3107_port *s) | ||
228 | { | ||
229 | int retval; | ||
230 | |||
231 | /* Initialize GPIO chip data */ | ||
232 | s->chip = max3107_gpio_chip; | ||
233 | s->chip.label = s->spi->modalias; | ||
234 | s->chip.dev = &s->spi->dev; | ||
235 | |||
236 | /* Add GPIO chip */ | ||
237 | retval = gpiochip_add(&s->chip); | ||
238 | if (retval) { | ||
239 | dev_err(&s->spi->dev, "Adding GPIO chip failed\n"); | ||
240 | return retval; | ||
241 | } | ||
242 | |||
243 | /* Temporary fix for EV2 boot problems, set modem reset to 0 */ | ||
244 | max3107_gpio_direction_out(&s->chip, 3, 0); | ||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | #if 0 | ||
249 | /* This will get enabled once we have the board stuff merged for this | ||
250 | specific case */ | ||
251 | |||
252 | static const struct baud_table brg13_ext[] = { | ||
253 | { 300, MAX3107_BRG13_B300 }, | ||
254 | { 600, MAX3107_BRG13_B600 }, | ||
255 | { 1200, MAX3107_BRG13_B1200 }, | ||
256 | { 2400, MAX3107_BRG13_B2400 }, | ||
257 | { 4800, MAX3107_BRG13_B4800 }, | ||
258 | { 9600, MAX3107_BRG13_B9600 }, | ||
259 | { 19200, MAX3107_BRG13_B19200 }, | ||
260 | { 57600, MAX3107_BRG13_B57600 }, | ||
261 | { 115200, MAX3107_BRG13_B115200 }, | ||
262 | { 230400, MAX3107_BRG13_B230400 }, | ||
263 | { 460800, MAX3107_BRG13_B460800 }, | ||
264 | { 921600, MAX3107_BRG13_B921600 }, | ||
265 | { 0, 0 } | ||
266 | }; | ||
267 | |||
268 | static void max3107_aava_init(struct max3107_port *s) | ||
269 | { | ||
270 | /*override for AAVA SC specific*/ | ||
271 | if (mrst_platform_id() == MRST_PLATFORM_AAVA_SC) { | ||
272 | if (get_koski_build_id() <= KOSKI_EV2) | ||
273 | if (s->ext_clk) { | ||
274 | s->brg_cfg = MAX3107_BRG13_B9600; | ||
275 | s->baud_tbl = (struct baud_table *)brg13_ext; | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | #endif | ||
280 | |||
281 | static int __devexit max3107_aava_remove(struct spi_device *spi) | ||
282 | { | ||
283 | struct max3107_port *s = dev_get_drvdata(&spi->dev); | ||
284 | |||
285 | /* Remove GPIO chip */ | ||
286 | if (gpiochip_remove(&s->chip)) | ||
287 | dev_warn(&spi->dev, "Removing GPIO chip failed\n"); | ||
288 | |||
289 | /* Then do the default remove */ | ||
290 | return max3107_remove(spi); | ||
291 | } | ||
292 | |||
293 | /* Platform data */ | ||
294 | static struct max3107_plat aava_plat_data = { | ||
295 | .loopback = 0, | ||
296 | .ext_clk = 1, | ||
297 | /* .init = max3107_aava_init, */ | ||
298 | .configure = max3107_aava_configure, | ||
299 | .hw_suspend = max3107_hw_susp, | ||
300 | .polled_mode = 0, | ||
301 | .poll_time = 0, | ||
302 | }; | ||
303 | |||
304 | |||
305 | static int __devinit max3107_probe_aava(struct spi_device *spi) | ||
306 | { | ||
307 | int err = max3107_aava_reset(spi); | ||
308 | if (err < 0) | ||
309 | return err; | ||
310 | return max3107_probe(spi, &aava_plat_data); | ||
311 | } | ||
312 | |||
313 | /* Spi driver data */ | ||
314 | static struct spi_driver max3107_driver = { | ||
315 | .driver = { | ||
316 | .name = "aava-max3107", | ||
317 | .bus = &spi_bus_type, | ||
318 | .owner = THIS_MODULE, | ||
319 | }, | ||
320 | .probe = max3107_probe_aava, | ||
321 | .remove = __devexit_p(max3107_aava_remove), | ||
322 | .suspend = max3107_suspend, | ||
323 | .resume = max3107_resume, | ||
324 | }; | ||
325 | |||
326 | /* Driver init function */ | ||
327 | static int __init max3107_init(void) | ||
328 | { | ||
329 | return spi_register_driver(&max3107_driver); | ||
330 | } | ||
331 | |||
332 | /* Driver exit function */ | ||
333 | static void __exit max3107_exit(void) | ||
334 | { | ||
335 | spi_unregister_driver(&max3107_driver); | ||
336 | } | ||
337 | |||
338 | module_init(max3107_init); | ||
339 | module_exit(max3107_exit); | ||
340 | |||
341 | MODULE_DESCRIPTION("MAX3107 driver"); | ||
342 | MODULE_AUTHOR("Aavamobile"); | ||
343 | MODULE_ALIAS("aava-max3107-spi"); | ||
344 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/serial/max3107.c b/drivers/serial/max3107.c index a96ddd388ffd..67283c1a57ff 100644 --- a/drivers/serial/max3107.c +++ b/drivers/serial/max3107.c | |||
@@ -31,98 +31,12 @@ | |||
31 | #include <linux/device.h> | 31 | #include <linux/device.h> |
32 | #include <linux/serial_core.h> | 32 | #include <linux/serial_core.h> |
33 | #include <linux/serial.h> | 33 | #include <linux/serial.h> |
34 | #include <linux/gpio.h> | ||
34 | #include <linux/spi/spi.h> | 35 | #include <linux/spi/spi.h> |
35 | #include <linux/freezer.h> | 36 | #include <linux/freezer.h> |
36 | #include <linux/platform_device.h> | ||
37 | #include <linux/gpio.h> | ||
38 | #include <linux/sfi.h> | ||
39 | #include <asm/mrst.h> | ||
40 | #include "max3107.h" | 37 | #include "max3107.h" |
41 | 38 | ||
42 | struct baud_table { | 39 | static const struct baud_table brg26_ext[] = { |
43 | int baud; | ||
44 | u32 new_brg; | ||
45 | }; | ||
46 | |||
47 | struct max3107_port { | ||
48 | /* UART port structure */ | ||
49 | struct uart_port port; | ||
50 | |||
51 | /* SPI device structure */ | ||
52 | struct spi_device *spi; | ||
53 | |||
54 | /* GPIO chip stucture */ | ||
55 | struct gpio_chip chip; | ||
56 | |||
57 | /* Workqueue that does all the magic */ | ||
58 | struct workqueue_struct *workqueue; | ||
59 | struct work_struct work; | ||
60 | |||
61 | /* Lock for shared data */ | ||
62 | spinlock_t data_lock; | ||
63 | |||
64 | /* Device configuration */ | ||
65 | int ext_clk; /* 1 if external clock used */ | ||
66 | int loopback; /* Current loopback mode state */ | ||
67 | int baud; /* Current baud rate */ | ||
68 | |||
69 | /* State flags */ | ||
70 | int suspended; /* Indicates suspend mode */ | ||
71 | int tx_fifo_empty; /* Flag for TX FIFO state */ | ||
72 | int rx_enabled; /* Flag for receiver state */ | ||
73 | int tx_enabled; /* Flag for transmitter state */ | ||
74 | |||
75 | u16 irqen_reg; /* Current IRQ enable register value */ | ||
76 | /* Shared data */ | ||
77 | u16 mode1_reg; /* Current mode1 register value*/ | ||
78 | int mode1_commit; /* Flag for setting new mode1 register value */ | ||
79 | u16 lcr_reg; /* Current LCR register value */ | ||
80 | int lcr_commit; /* Flag for setting new LCR register value */ | ||
81 | u32 brg_cfg; /* Current Baud rate generator config */ | ||
82 | int brg_commit; /* Flag for setting new baud rate generator | ||
83 | * config | ||
84 | */ | ||
85 | struct baud_table *baud_tbl; | ||
86 | int handle_irq; /* Indicates that IRQ should be handled */ | ||
87 | |||
88 | /* Rx buffer and str*/ | ||
89 | u16 *rxbuf; | ||
90 | u8 *rxstr; | ||
91 | /* Tx buffer*/ | ||
92 | u16 *txbuf; | ||
93 | }; | ||
94 | |||
95 | /* Platform data structure */ | ||
96 | struct max3107_plat { | ||
97 | /* Loopback mode enable */ | ||
98 | int loopback; | ||
99 | /* External clock enable */ | ||
100 | int ext_clk; | ||
101 | /* HW suspend function */ | ||
102 | void (*max3107_hw_suspend) (struct max3107_port *s, int suspend); | ||
103 | /* Polling mode enable */ | ||
104 | int polled_mode; | ||
105 | /* Polling period if polling mode enabled */ | ||
106 | int poll_time; | ||
107 | }; | ||
108 | |||
109 | static struct baud_table brg13_ext[] = { | ||
110 | { 300, MAX3107_BRG13_B300 }, | ||
111 | { 600, MAX3107_BRG13_B600 }, | ||
112 | { 1200, MAX3107_BRG13_B1200 }, | ||
113 | { 2400, MAX3107_BRG13_B2400 }, | ||
114 | { 4800, MAX3107_BRG13_B4800 }, | ||
115 | { 9600, MAX3107_BRG13_B9600 }, | ||
116 | { 19200, MAX3107_BRG13_B19200 }, | ||
117 | { 57600, MAX3107_BRG13_B57600 }, | ||
118 | { 115200, MAX3107_BRG13_B115200 }, | ||
119 | { 230400, MAX3107_BRG13_B230400 }, | ||
120 | { 460800, MAX3107_BRG13_B460800 }, | ||
121 | { 921600, MAX3107_BRG13_B921600 }, | ||
122 | { 0, 0 } | ||
123 | }; | ||
124 | |||
125 | static struct baud_table brg26_ext[] = { | ||
126 | { 300, MAX3107_BRG26_B300 }, | 40 | { 300, MAX3107_BRG26_B300 }, |
127 | { 600, MAX3107_BRG26_B600 }, | 41 | { 600, MAX3107_BRG26_B600 }, |
128 | { 1200, MAX3107_BRG26_B1200 }, | 42 | { 1200, MAX3107_BRG26_B1200 }, |
@@ -138,7 +52,7 @@ static struct baud_table brg26_ext[] = { | |||
138 | { 0, 0 } | 52 | { 0, 0 } |
139 | }; | 53 | }; |
140 | 54 | ||
141 | static struct baud_table brg13_int[] = { | 55 | static const struct baud_table brg13_int[] = { |
142 | { 300, MAX3107_BRG13_IB300 }, | 56 | { 300, MAX3107_BRG13_IB300 }, |
143 | { 600, MAX3107_BRG13_IB600 }, | 57 | { 600, MAX3107_BRG13_IB600 }, |
144 | { 1200, MAX3107_BRG13_IB1200 }, | 58 | { 1200, MAX3107_BRG13_IB1200 }, |
@@ -157,7 +71,7 @@ static struct baud_table brg13_int[] = { | |||
157 | static u32 get_new_brg(int baud, struct max3107_port *s) | 71 | static u32 get_new_brg(int baud, struct max3107_port *s) |
158 | { | 72 | { |
159 | int i; | 73 | int i; |
160 | struct baud_table *baud_tbl = s->baud_tbl; | 74 | const struct baud_table *baud_tbl = s->baud_tbl; |
161 | 75 | ||
162 | for (i = 0; i < 13; i++) { | 76 | for (i = 0; i < 13; i++) { |
163 | if (baud == baud_tbl[i].baud) | 77 | if (baud == baud_tbl[i].baud) |
@@ -168,7 +82,7 @@ static u32 get_new_brg(int baud, struct max3107_port *s) | |||
168 | } | 82 | } |
169 | 83 | ||
170 | /* Perform SPI transfer for write/read of device register(s) */ | 84 | /* Perform SPI transfer for write/read of device register(s) */ |
171 | static int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len) | 85 | int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len) |
172 | { | 86 | { |
173 | struct spi_message spi_msg; | 87 | struct spi_message spi_msg; |
174 | struct spi_transfer spi_xfer; | 88 | struct spi_transfer spi_xfer; |
@@ -213,6 +127,7 @@ static int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len) | |||
213 | #endif | 127 | #endif |
214 | return 0; | 128 | return 0; |
215 | } | 129 | } |
130 | EXPORT_SYMBOL_GPL(max3107_rw); | ||
216 | 131 | ||
217 | /* Puts received data to circular buffer */ | 132 | /* Puts received data to circular buffer */ |
218 | static void put_data_to_circ_buf(struct max3107_port *s, unsigned char *data, | 133 | static void put_data_to_circ_buf(struct max3107_port *s, unsigned char *data, |
@@ -611,16 +526,10 @@ static void max3107_register_init(struct max3107_port *s) | |||
611 | s->brg_cfg = MAX3107_BRG13_IB9600; | 526 | s->brg_cfg = MAX3107_BRG13_IB9600; |
612 | s->baud_tbl = (struct baud_table *)brg13_int; | 527 | s->baud_tbl = (struct baud_table *)brg13_int; |
613 | } | 528 | } |
614 | #if 0 | 529 | |
615 | /*override for AAVA SC specific*/ | 530 | if (s->pdata->init) |
616 | if (mrst_platform_id() == MRST_PLATFORM_AAVA_SC) { | 531 | s->pdata->init(s); |
617 | if (get_koski_build_id() <= KOSKI_EV2) | 532 | |
618 | if (s->ext_clk) { | ||
619 | s->brg_cfg = MAX3107_BRG13_B9600; | ||
620 | s->baud_tbl = (struct baud_table *)brg13_ext; | ||
621 | } | ||
622 | } | ||
623 | #endif | ||
624 | buf[0] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVMSB_REG) | 533 | buf[0] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVMSB_REG) |
625 | | ((s->brg_cfg >> 16) & MAX3107_SPI_TX_DATA_MASK); | 534 | | ((s->brg_cfg >> 16) & MAX3107_SPI_TX_DATA_MASK); |
626 | buf[1] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVLSB_REG) | 535 | buf[1] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVLSB_REG) |
@@ -734,7 +643,7 @@ static irqreturn_t max3107_irq(int irqno, void *dev_id) | |||
734 | * used but that would mess the GPIOs | 643 | * used but that would mess the GPIOs |
735 | * | 644 | * |
736 | */ | 645 | */ |
737 | static void max3107_hw_susp(struct max3107_port *s, int suspend) | 646 | void max3107_hw_susp(struct max3107_port *s, int suspend) |
738 | { | 647 | { |
739 | pr_debug("enter, suspend %d\n", suspend); | 648 | pr_debug("enter, suspend %d\n", suspend); |
740 | 649 | ||
@@ -752,6 +661,7 @@ static void max3107_hw_susp(struct max3107_port *s, int suspend) | |||
752 | max3107_set_sleep(s, MAX3107_DISABLE_AUTOSLEEP); | 661 | max3107_set_sleep(s, MAX3107_DISABLE_AUTOSLEEP); |
753 | } | 662 | } |
754 | } | 663 | } |
664 | EXPORT_SYMBOL_GPL(max3107_hw_susp); | ||
755 | 665 | ||
756 | /* Modem status IRQ enabling */ | 666 | /* Modem status IRQ enabling */ |
757 | static void max3107_enable_ms(struct uart_port *port) | 667 | static void max3107_enable_ms(struct uart_port *port) |
@@ -899,10 +809,8 @@ static void max3107_shutdown(struct uart_port *port) | |||
899 | { | 809 | { |
900 | struct max3107_port *s = container_of(port, struct max3107_port, port); | 810 | struct max3107_port *s = container_of(port, struct max3107_port, port); |
901 | 811 | ||
902 | if (s->suspended) { | 812 | if (s->suspended && s->pdata->hw_suspend) |
903 | /* Resume HW */ | 813 | s->pdata->hw_suspend(s, 0); |
904 | max3107_hw_susp(s, 0); | ||
905 | } | ||
906 | 814 | ||
907 | /* Free the interrupt */ | 815 | /* Free the interrupt */ |
908 | free_irq(s->spi->irq, s); | 816 | free_irq(s->spi->irq, s); |
@@ -915,7 +823,8 @@ static void max3107_shutdown(struct uart_port *port) | |||
915 | } | 823 | } |
916 | 824 | ||
917 | /* Suspend HW */ | 825 | /* Suspend HW */ |
918 | max3107_hw_susp(s, 1); | 826 | if (s->pdata->hw_suspend) |
827 | s->pdata->hw_suspend(s, 1); | ||
919 | } | 828 | } |
920 | 829 | ||
921 | /* Port startup function */ | 830 | /* Port startup function */ |
@@ -941,7 +850,8 @@ static int max3107_startup(struct uart_port *port) | |||
941 | } | 850 | } |
942 | 851 | ||
943 | /* Resume HW */ | 852 | /* Resume HW */ |
944 | max3107_hw_susp(s, 0); | 853 | if (s->pdata->hw_suspend) |
854 | s->pdata->hw_suspend(s, 0); | ||
945 | 855 | ||
946 | /* Init registers */ | 856 | /* Init registers */ |
947 | max3107_register_init(s); | 857 | max3107_register_init(s); |
@@ -973,16 +883,14 @@ static int max3107_request_port(struct uart_port *port) | |||
973 | static void max3107_config_port(struct uart_port *port, int flags) | 883 | static void max3107_config_port(struct uart_port *port, int flags) |
974 | { | 884 | { |
975 | struct max3107_port *s = container_of(port, struct max3107_port, port); | 885 | struct max3107_port *s = container_of(port, struct max3107_port, port); |
976 | 886 | s->port.type = PORT_MAX3107; | |
977 | /* Use PORT_MAX3100 since we are at least int the same series */ | ||
978 | s->port.type = PORT_MAX3100; | ||
979 | } | 887 | } |
980 | 888 | ||
981 | /* Port verify function */ | 889 | /* Port verify function */ |
982 | static int max3107_verify_port(struct uart_port *port, | 890 | static int max3107_verify_port(struct uart_port *port, |
983 | struct serial_struct *ser) | 891 | struct serial_struct *ser) |
984 | { | 892 | { |
985 | if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3100) | 893 | if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3107) |
986 | return 0; | 894 | return 0; |
987 | 895 | ||
988 | return -EINVAL; | 896 | return -EINVAL; |
@@ -1000,157 +908,6 @@ static void max3107_break_ctl(struct uart_port *port, int break_state) | |||
1000 | /* We don't support break control, do nothing */ | 908 | /* We don't support break control, do nothing */ |
1001 | } | 909 | } |
1002 | 910 | ||
1003 | /* GPIO direction to input function */ | ||
1004 | static int max3107_gpio_direction_in(struct gpio_chip *chip, unsigned offset) | ||
1005 | { | ||
1006 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
1007 | u16 buf[1]; /* Buffer for SPI transfer */ | ||
1008 | |||
1009 | if (offset >= MAX3107_GPIO_COUNT) { | ||
1010 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
1011 | return -EINVAL; | ||
1012 | } | ||
1013 | |||
1014 | /* Read current GPIO configuration register */ | ||
1015 | buf[0] = MAX3107_GPIOCFG_REG; | ||
1016 | /* Perform SPI transfer */ | ||
1017 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { | ||
1018 | dev_err(&s->spi->dev, "SPI transfer GPIO read failed\n"); | ||
1019 | return -EIO; | ||
1020 | } | ||
1021 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
1022 | |||
1023 | /* Set GPIO to input */ | ||
1024 | buf[0] &= ~(0x0001 << offset); | ||
1025 | |||
1026 | /* Write new GPIO configuration register value */ | ||
1027 | buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIOCFG_REG); | ||
1028 | /* Perform SPI transfer */ | ||
1029 | if (max3107_rw(s, (u8 *)buf, NULL, 2)) { | ||
1030 | dev_err(&s->spi->dev, "SPI transfer GPIO write failed\n"); | ||
1031 | return -EIO; | ||
1032 | } | ||
1033 | return 0; | ||
1034 | } | ||
1035 | |||
1036 | /* GPIO direction to output function */ | ||
1037 | static int max3107_gpio_direction_out(struct gpio_chip *chip, unsigned offset, | ||
1038 | int value) | ||
1039 | { | ||
1040 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
1041 | u16 buf[2]; /* Buffer for SPI transfers */ | ||
1042 | |||
1043 | if (offset >= MAX3107_GPIO_COUNT) { | ||
1044 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
1045 | return -EINVAL; | ||
1046 | } | ||
1047 | |||
1048 | /* Read current GPIO configuration and data registers */ | ||
1049 | buf[0] = MAX3107_GPIOCFG_REG; | ||
1050 | buf[1] = MAX3107_GPIODATA_REG; | ||
1051 | /* Perform SPI transfer */ | ||
1052 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 4)) { | ||
1053 | dev_err(&s->spi->dev, "SPI transfer gpio failed\n"); | ||
1054 | return -EIO; | ||
1055 | } | ||
1056 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
1057 | buf[1] &= MAX3107_SPI_RX_DATA_MASK; | ||
1058 | |||
1059 | /* Set GPIO to output */ | ||
1060 | buf[0] |= (0x0001 << offset); | ||
1061 | /* Set value */ | ||
1062 | if (value) | ||
1063 | buf[1] |= (0x0001 << offset); | ||
1064 | else | ||
1065 | buf[1] &= ~(0x0001 << offset); | ||
1066 | |||
1067 | /* Write new GPIO configuration and data register values */ | ||
1068 | buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIOCFG_REG); | ||
1069 | buf[1] |= (MAX3107_WRITE_BIT | MAX3107_GPIODATA_REG); | ||
1070 | /* Perform SPI transfer */ | ||
1071 | if (max3107_rw(s, (u8 *)buf, NULL, 4)) { | ||
1072 | dev_err(&s->spi->dev, | ||
1073 | "SPI transfer for GPIO conf data w failed\n"); | ||
1074 | return -EIO; | ||
1075 | } | ||
1076 | return 0; | ||
1077 | } | ||
1078 | |||
1079 | /* GPIO value query function */ | ||
1080 | static int max3107_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
1081 | { | ||
1082 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
1083 | u16 buf[1]; /* Buffer for SPI transfer */ | ||
1084 | |||
1085 | if (offset >= MAX3107_GPIO_COUNT) { | ||
1086 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
1087 | return -EINVAL; | ||
1088 | } | ||
1089 | |||
1090 | /* Read current GPIO data register */ | ||
1091 | buf[0] = MAX3107_GPIODATA_REG; | ||
1092 | /* Perform SPI transfer */ | ||
1093 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { | ||
1094 | dev_err(&s->spi->dev, "SPI transfer GPIO data r failed\n"); | ||
1095 | return -EIO; | ||
1096 | } | ||
1097 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
1098 | |||
1099 | /* Return value */ | ||
1100 | return buf[0] & (0x0001 << offset); | ||
1101 | } | ||
1102 | |||
1103 | /* GPIO value set function */ | ||
1104 | static void max3107_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
1105 | { | ||
1106 | struct max3107_port *s = container_of(chip, struct max3107_port, chip); | ||
1107 | u16 buf[2]; /* Buffer for SPI transfers */ | ||
1108 | |||
1109 | if (offset >= MAX3107_GPIO_COUNT) { | ||
1110 | dev_err(&s->spi->dev, "Invalid GPIO\n"); | ||
1111 | return; | ||
1112 | } | ||
1113 | |||
1114 | /* Read current GPIO configuration registers*/ | ||
1115 | buf[0] = MAX3107_GPIODATA_REG; | ||
1116 | buf[1] = MAX3107_GPIOCFG_REG; | ||
1117 | /* Perform SPI transfer */ | ||
1118 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 4)) { | ||
1119 | dev_err(&s->spi->dev, | ||
1120 | "SPI transfer for GPIO data and config read failed\n"); | ||
1121 | return; | ||
1122 | } | ||
1123 | buf[0] &= MAX3107_SPI_RX_DATA_MASK; | ||
1124 | buf[1] &= MAX3107_SPI_RX_DATA_MASK; | ||
1125 | |||
1126 | if (!(buf[1] & (0x0001 << offset))) { | ||
1127 | /* Configured as input, can't set value */ | ||
1128 | dev_warn(&s->spi->dev, | ||
1129 | "Trying to set value for input GPIO\n"); | ||
1130 | return; | ||
1131 | } | ||
1132 | |||
1133 | /* Set value */ | ||
1134 | if (value) | ||
1135 | buf[0] |= (0x0001 << offset); | ||
1136 | else | ||
1137 | buf[0] &= ~(0x0001 << offset); | ||
1138 | |||
1139 | /* Write new GPIO data register value */ | ||
1140 | buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIODATA_REG); | ||
1141 | /* Perform SPI transfer */ | ||
1142 | if (max3107_rw(s, (u8 *)buf, NULL, 2)) | ||
1143 | dev_err(&s->spi->dev, "SPI transfer GPIO data w failed\n"); | ||
1144 | } | ||
1145 | |||
1146 | /* Platform data */ | ||
1147 | static struct max3107_plat max3107_plat_data = { | ||
1148 | .loopback = 0, | ||
1149 | .ext_clk = 1, | ||
1150 | .max3107_hw_suspend = &max3107_hw_susp, | ||
1151 | .polled_mode = 0, | ||
1152 | .poll_time = 0, | ||
1153 | }; | ||
1154 | 911 | ||
1155 | /* Port functions */ | 912 | /* Port functions */ |
1156 | static struct uart_ops max3107_ops = { | 913 | static struct uart_ops max3107_ops = { |
@@ -1180,52 +937,48 @@ static struct uart_driver max3107_uart_driver = { | |||
1180 | .nr = 1, | 937 | .nr = 1, |
1181 | }; | 938 | }; |
1182 | 939 | ||
1183 | /* GPIO chip data */ | 940 | static int driver_registered = 0; |
1184 | static struct gpio_chip max3107_gpio_chip = { | 941 | |
1185 | .owner = THIS_MODULE, | 942 | |
1186 | .direction_input = max3107_gpio_direction_in, | 943 | |
1187 | .direction_output = max3107_gpio_direction_out, | 944 | /* 'Generic' platform data */ |
1188 | .get = max3107_gpio_get, | 945 | static struct max3107_plat generic_plat_data = { |
1189 | .set = max3107_gpio_set, | 946 | .loopback = 0, |
1190 | .can_sleep = 1, | 947 | .ext_clk = 1, |
1191 | .base = MAX3107_GPIO_BASE, | 948 | .hw_suspend = max3107_hw_susp, |
1192 | .ngpio = MAX3107_GPIO_COUNT, | 949 | .polled_mode = 0, |
950 | .poll_time = 0, | ||
1193 | }; | 951 | }; |
1194 | /* Device probe function */ | 952 | |
1195 | static int __devinit max3107_probe(struct spi_device *spi) | 953 | |
954 | /*******************************************************************/ | ||
955 | |||
956 | /** | ||
957 | * max3107_probe - SPI bus probe entry point | ||
958 | * @spi: the spi device | ||
959 | * | ||
960 | * SPI wants us to probe this device and if appropriate claim it. | ||
961 | * Perform any platform specific requirements and then initialise | ||
962 | * the device. | ||
963 | */ | ||
964 | |||
965 | int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | ||
1196 | { | 966 | { |
1197 | struct max3107_port *s; | 967 | struct max3107_port *s; |
1198 | struct max3107_plat *pdata = &max3107_plat_data; | ||
1199 | u16 buf[2]; /* Buffer for SPI transfers */ | 968 | u16 buf[2]; /* Buffer for SPI transfers */ |
1200 | int retval; | 969 | int retval; |
1201 | 970 | ||
1202 | pr_info("enter max3107 probe\n"); | 971 | pr_info("enter max3107 probe\n"); |
1203 | 972 | ||
1204 | /* Reset the chip */ | ||
1205 | if (gpio_request(MAX3107_RESET_GPIO, "max3107")) { | ||
1206 | pr_err("Requesting RESET GPIO failed\n"); | ||
1207 | return -EIO; | ||
1208 | } | ||
1209 | if (gpio_direction_output(MAX3107_RESET_GPIO, 0)) { | ||
1210 | pr_err("Setting RESET GPIO to 0 failed\n"); | ||
1211 | gpio_free(MAX3107_RESET_GPIO); | ||
1212 | return -EIO; | ||
1213 | } | ||
1214 | msleep(MAX3107_RESET_DELAY); | ||
1215 | if (gpio_direction_output(MAX3107_RESET_GPIO, 1)) { | ||
1216 | pr_err("Setting RESET GPIO to 1 failed\n"); | ||
1217 | gpio_free(MAX3107_RESET_GPIO); | ||
1218 | return -EIO; | ||
1219 | } | ||
1220 | gpio_free(MAX3107_RESET_GPIO); | ||
1221 | msleep(MAX3107_WAKEUP_DELAY); | ||
1222 | |||
1223 | /* Allocate port structure */ | 973 | /* Allocate port structure */ |
1224 | s = kzalloc(sizeof(*s), GFP_KERNEL); | 974 | s = kzalloc(sizeof(*s), GFP_KERNEL); |
1225 | if (!s) { | 975 | if (!s) { |
1226 | pr_err("Allocating port structure failed\n"); | 976 | pr_err("Allocating port structure failed\n"); |
1227 | return -ENOMEM; | 977 | return -ENOMEM; |
1228 | } | 978 | } |
979 | |||
980 | s->pdata = pdata; | ||
981 | |||
1229 | /* SPI Rx buffer | 982 | /* SPI Rx buffer |
1230 | * +2 for RX FIFO interrupt | 983 | * +2 for RX FIFO interrupt |
1231 | * disabling and RX level query | 984 | * disabling and RX level query |
@@ -1298,10 +1051,13 @@ static int __devinit max3107_probe(struct spi_device *spi) | |||
1298 | } | 1051 | } |
1299 | 1052 | ||
1300 | /* Register UART driver */ | 1053 | /* Register UART driver */ |
1301 | retval = uart_register_driver(&max3107_uart_driver); | 1054 | if (!driver_registered) { |
1302 | if (retval) { | 1055 | retval = uart_register_driver(&max3107_uart_driver); |
1303 | dev_err(&s->spi->dev, "Registering UART driver failed\n"); | 1056 | if (retval) { |
1304 | return retval; | 1057 | dev_err(&s->spi->dev, "Registering UART driver failed\n"); |
1058 | return retval; | ||
1059 | } | ||
1060 | driver_registered = 1; | ||
1305 | } | 1061 | } |
1306 | 1062 | ||
1307 | /* Initialize UART port data */ | 1063 | /* Initialize UART port data */ |
@@ -1312,8 +1068,7 @@ static int __devinit max3107_probe(struct spi_device *spi) | |||
1312 | s->port.uartclk = 9600; | 1068 | s->port.uartclk = 9600; |
1313 | s->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; | 1069 | s->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; |
1314 | s->port.irq = s->spi->irq; | 1070 | s->port.irq = s->spi->irq; |
1315 | /* Use PORT_MAX3100 since we are at least in the same series */ | 1071 | s->port.type = PORT_MAX3107; |
1316 | s->port.type = PORT_MAX3100; | ||
1317 | 1072 | ||
1318 | /* Add UART port */ | 1073 | /* Add UART port */ |
1319 | retval = uart_add_one_port(&max3107_uart_driver, &s->port); | 1074 | retval = uart_add_one_port(&max3107_uart_driver, &s->port); |
@@ -1322,44 +1077,31 @@ static int __devinit max3107_probe(struct spi_device *spi) | |||
1322 | return retval; | 1077 | return retval; |
1323 | } | 1078 | } |
1324 | 1079 | ||
1325 | /* Initialize GPIO chip data */ | 1080 | if (pdata->configure) { |
1326 | s->chip = max3107_gpio_chip; | 1081 | retval = pdata->configure(s); |
1327 | s->chip.label = spi->modalias; | 1082 | if (retval < 0) |
1328 | s->chip.dev = &spi->dev; | 1083 | return retval; |
1329 | |||
1330 | /* Add GPIO chip */ | ||
1331 | retval = gpiochip_add(&s->chip); | ||
1332 | if (retval) { | ||
1333 | dev_err(&s->spi->dev, "Adding GPIO chip failed\n"); | ||
1334 | return retval; | ||
1335 | } | 1084 | } |
1336 | 1085 | ||
1337 | /* Temporary fix for EV2 boot problems, set modem reset to 0 */ | ||
1338 | max3107_gpio_direction_out(&s->chip, 3, 0); | ||
1339 | |||
1340 | /* Go to suspend mode */ | 1086 | /* Go to suspend mode */ |
1341 | max3107_hw_susp(s, 1); | 1087 | if (pdata->hw_suspend) |
1088 | pdata->hw_suspend(s, 1); | ||
1342 | 1089 | ||
1343 | return 0; | 1090 | return 0; |
1344 | } | 1091 | } |
1092 | EXPORT_SYMBOL_GPL(max3107_probe); | ||
1345 | 1093 | ||
1346 | /* Driver remove function */ | 1094 | /* Driver remove function */ |
1347 | static int __devexit max3107_remove(struct spi_device *spi) | 1095 | int max3107_remove(struct spi_device *spi) |
1348 | { | 1096 | { |
1349 | struct max3107_port *s = dev_get_drvdata(&spi->dev); | 1097 | struct max3107_port *s = dev_get_drvdata(&spi->dev); |
1350 | 1098 | ||
1351 | pr_info("enter max3107 remove\n"); | 1099 | pr_info("enter max3107 remove\n"); |
1352 | 1100 | ||
1353 | /* Remove GPIO chip */ | ||
1354 | if (gpiochip_remove(&s->chip)) | ||
1355 | dev_warn(&s->spi->dev, "Removing GPIO chip failed\n"); | ||
1356 | |||
1357 | /* Remove port */ | 1101 | /* Remove port */ |
1358 | if (uart_remove_one_port(&max3107_uart_driver, &s->port)) | 1102 | if (uart_remove_one_port(&max3107_uart_driver, &s->port)) |
1359 | dev_warn(&s->spi->dev, "Removing UART port failed\n"); | 1103 | dev_warn(&s->spi->dev, "Removing UART port failed\n"); |
1360 | 1104 | ||
1361 | /* Unregister UART driver */ | ||
1362 | uart_unregister_driver(&max3107_uart_driver); | ||
1363 | 1105 | ||
1364 | /* Free TxRx buffer */ | 1106 | /* Free TxRx buffer */ |
1365 | kfree(s->rxbuf); | 1107 | kfree(s->rxbuf); |
@@ -1371,9 +1113,10 @@ static int __devexit max3107_remove(struct spi_device *spi) | |||
1371 | 1113 | ||
1372 | return 0; | 1114 | return 0; |
1373 | } | 1115 | } |
1116 | EXPORT_SYMBOL_GPL(max3107_remove); | ||
1374 | 1117 | ||
1375 | /* Driver suspend function */ | 1118 | /* Driver suspend function */ |
1376 | static int max3107_suspend(struct spi_device *spi, pm_message_t state) | 1119 | int max3107_suspend(struct spi_device *spi, pm_message_t state) |
1377 | { | 1120 | { |
1378 | #ifdef CONFIG_PM | 1121 | #ifdef CONFIG_PM |
1379 | struct max3107_port *s = dev_get_drvdata(&spi->dev); | 1122 | struct max3107_port *s = dev_get_drvdata(&spi->dev); |
@@ -1384,13 +1127,15 @@ static int max3107_suspend(struct spi_device *spi, pm_message_t state) | |||
1384 | uart_suspend_port(&max3107_uart_driver, &s->port); | 1127 | uart_suspend_port(&max3107_uart_driver, &s->port); |
1385 | 1128 | ||
1386 | /* Go to suspend mode */ | 1129 | /* Go to suspend mode */ |
1387 | max3107_hw_susp(s, 1); | 1130 | if (s->pdata->hw_suspend) |
1131 | s->pdata->hw_suspend(s, 1); | ||
1388 | #endif /* CONFIG_PM */ | 1132 | #endif /* CONFIG_PM */ |
1389 | return 0; | 1133 | return 0; |
1390 | } | 1134 | } |
1135 | EXPORT_SYMBOL_GPL(max3107_suspend); | ||
1391 | 1136 | ||
1392 | /* Driver resume function */ | 1137 | /* Driver resume function */ |
1393 | static int max3107_resume(struct spi_device *spi) | 1138 | int max3107_resume(struct spi_device *spi) |
1394 | { | 1139 | { |
1395 | #ifdef CONFIG_PM | 1140 | #ifdef CONFIG_PM |
1396 | struct max3107_port *s = dev_get_drvdata(&spi->dev); | 1141 | struct max3107_port *s = dev_get_drvdata(&spi->dev); |
@@ -1398,13 +1143,20 @@ static int max3107_resume(struct spi_device *spi) | |||
1398 | pr_debug("enter resume\n"); | 1143 | pr_debug("enter resume\n"); |
1399 | 1144 | ||
1400 | /* Resume from suspend */ | 1145 | /* Resume from suspend */ |
1401 | max3107_hw_susp(s, 0); | 1146 | if (s->pdata->hw_suspend) |
1147 | s->pdata->hw_suspend(s, 0); | ||
1402 | 1148 | ||
1403 | /* Resume UART port */ | 1149 | /* Resume UART port */ |
1404 | uart_resume_port(&max3107_uart_driver, &s->port); | 1150 | uart_resume_port(&max3107_uart_driver, &s->port); |
1405 | #endif /* CONFIG_PM */ | 1151 | #endif /* CONFIG_PM */ |
1406 | return 0; | 1152 | return 0; |
1407 | } | 1153 | } |
1154 | EXPORT_SYMBOL_GPL(max3107_resume); | ||
1155 | |||
1156 | static int max3107_probe_generic(struct spi_device *spi) | ||
1157 | { | ||
1158 | return max3107_probe(spi, &generic_plat_data); | ||
1159 | } | ||
1408 | 1160 | ||
1409 | /* Spi driver data */ | 1161 | /* Spi driver data */ |
1410 | static struct spi_driver max3107_driver = { | 1162 | static struct spi_driver max3107_driver = { |
@@ -1413,7 +1165,7 @@ static struct spi_driver max3107_driver = { | |||
1413 | .bus = &spi_bus_type, | 1165 | .bus = &spi_bus_type, |
1414 | .owner = THIS_MODULE, | 1166 | .owner = THIS_MODULE, |
1415 | }, | 1167 | }, |
1416 | .probe = max3107_probe, | 1168 | .probe = max3107_probe_generic, |
1417 | .remove = __devexit_p(max3107_remove), | 1169 | .remove = __devexit_p(max3107_remove), |
1418 | .suspend = max3107_suspend, | 1170 | .suspend = max3107_suspend, |
1419 | .resume = max3107_resume, | 1171 | .resume = max3107_resume, |
@@ -1430,6 +1182,9 @@ static int __init max3107_init(void) | |||
1430 | static void __exit max3107_exit(void) | 1182 | static void __exit max3107_exit(void) |
1431 | { | 1183 | { |
1432 | pr_info("enter max3107 exit\n"); | 1184 | pr_info("enter max3107 exit\n"); |
1185 | /* Unregister UART driver */ | ||
1186 | if (driver_registered) | ||
1187 | uart_unregister_driver(&max3107_uart_driver); | ||
1433 | spi_unregister_driver(&max3107_driver); | 1188 | spi_unregister_driver(&max3107_driver); |
1434 | } | 1189 | } |
1435 | 1190 | ||
@@ -1438,5 +1193,5 @@ module_exit(max3107_exit); | |||
1438 | 1193 | ||
1439 | MODULE_DESCRIPTION("MAX3107 driver"); | 1194 | MODULE_DESCRIPTION("MAX3107 driver"); |
1440 | MODULE_AUTHOR("Aavamobile"); | 1195 | MODULE_AUTHOR("Aavamobile"); |
1441 | MODULE_ALIAS("max3107-spi-uart"); | 1196 | MODULE_ALIAS("max3107-spi"); |
1442 | MODULE_LICENSE("GPLv2"); | 1197 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/serial/max3107.h b/drivers/serial/max3107.h index a5625d1f263d..72b30415f417 100644 --- a/drivers/serial/max3107.h +++ b/drivers/serial/max3107.h | |||
@@ -10,8 +10,8 @@ | |||
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #ifndef _LINUX_SERIAL_MAX3107_H | 13 | #ifndef _MAX3107_H |
14 | #define _LINUX_SERIAL_MAX3107_H | 14 | #define _MAX3107_H |
15 | 15 | ||
16 | /* Serial error status definitions */ | 16 | /* Serial error status definitions */ |
17 | #define MAX3107_PARITY_ERROR 1 | 17 | #define MAX3107_PARITY_ERROR 1 |
@@ -355,4 +355,85 @@ | |||
355 | #define MAX3107_BRG13_IB460800 (0x000000 | 0x00) | 355 | #define MAX3107_BRG13_IB460800 (0x000000 | 0x00) |
356 | #define MAX3107_BRG13_IB921600 (0x000000 | 0x00) | 356 | #define MAX3107_BRG13_IB921600 (0x000000 | 0x00) |
357 | 357 | ||
358 | |||
359 | struct baud_table { | ||
360 | int baud; | ||
361 | u32 new_brg; | ||
362 | }; | ||
363 | |||
364 | struct max3107_port { | ||
365 | /* UART port structure */ | ||
366 | struct uart_port port; | ||
367 | |||
368 | /* SPI device structure */ | ||
369 | struct spi_device *spi; | ||
370 | |||
371 | /* GPIO chip stucture */ | ||
372 | struct gpio_chip chip; | ||
373 | |||
374 | /* Workqueue that does all the magic */ | ||
375 | struct workqueue_struct *workqueue; | ||
376 | struct work_struct work; | ||
377 | |||
378 | /* Lock for shared data */ | ||
379 | spinlock_t data_lock; | ||
380 | |||
381 | /* Device configuration */ | ||
382 | int ext_clk; /* 1 if external clock used */ | ||
383 | int loopback; /* Current loopback mode state */ | ||
384 | int baud; /* Current baud rate */ | ||
385 | |||
386 | /* State flags */ | ||
387 | int suspended; /* Indicates suspend mode */ | ||
388 | int tx_fifo_empty; /* Flag for TX FIFO state */ | ||
389 | int rx_enabled; /* Flag for receiver state */ | ||
390 | int tx_enabled; /* Flag for transmitter state */ | ||
391 | |||
392 | u16 irqen_reg; /* Current IRQ enable register value */ | ||
393 | /* Shared data */ | ||
394 | u16 mode1_reg; /* Current mode1 register value*/ | ||
395 | int mode1_commit; /* Flag for setting new mode1 register value */ | ||
396 | u16 lcr_reg; /* Current LCR register value */ | ||
397 | int lcr_commit; /* Flag for setting new LCR register value */ | ||
398 | u32 brg_cfg; /* Current Baud rate generator config */ | ||
399 | int brg_commit; /* Flag for setting new baud rate generator | ||
400 | * config | ||
401 | */ | ||
402 | struct baud_table *baud_tbl; | ||
403 | int handle_irq; /* Indicates that IRQ should be handled */ | ||
404 | |||
405 | /* Rx buffer and str*/ | ||
406 | u16 *rxbuf; | ||
407 | u8 *rxstr; | ||
408 | /* Tx buffer*/ | ||
409 | u16 *txbuf; | ||
410 | |||
411 | struct max3107_plat *pdata; /* Platform data */ | ||
412 | }; | ||
413 | |||
414 | /* Platform data structure */ | ||
415 | struct max3107_plat { | ||
416 | /* Loopback mode enable */ | ||
417 | int loopback; | ||
418 | /* External clock enable */ | ||
419 | int ext_clk; | ||
420 | /* Called during the register initialisation */ | ||
421 | void (*init)(struct max3107_port *s); | ||
422 | /* Called when the port is found and configured */ | ||
423 | int (*configure)(struct max3107_port *s); | ||
424 | /* HW suspend function */ | ||
425 | void (*hw_suspend) (struct max3107_port *s, int suspend); | ||
426 | /* Polling mode enable */ | ||
427 | int polled_mode; | ||
428 | /* Polling period if polling mode enabled */ | ||
429 | int poll_time; | ||
430 | }; | ||
431 | |||
432 | extern int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len); | ||
433 | extern void max3107_hw_susp(struct max3107_port *s, int suspend); | ||
434 | extern int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata); | ||
435 | extern int max3107_remove(struct spi_device *spi); | ||
436 | extern int max3107_suspend(struct spi_device *spi, pm_message_t state); | ||
437 | extern int max3107_resume(struct spi_device *spi); | ||
438 | |||
358 | #endif /* _LINUX_SERIAL_MAX3107_H */ | 439 | #endif /* _LINUX_SERIAL_MAX3107_H */ |
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 32928161fab6..9ddc866ccc09 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h | |||
@@ -186,6 +186,10 @@ | |||
186 | #define PORT_ALTERA_JTAGUART 91 | 186 | #define PORT_ALTERA_JTAGUART 91 |
187 | #define PORT_ALTERA_UART 92 | 187 | #define PORT_ALTERA_UART 92 |
188 | 188 | ||
189 | /* MAX3107 */ | ||
190 | #define PORT_MAX3107 94 | ||
191 | |||
192 | |||
189 | #ifdef __KERNEL__ | 193 | #ifdef __KERNEL__ |
190 | 194 | ||
191 | #include <linux/compiler.h> | 195 | #include <linux/compiler.h> |