Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[deliverable/linux.git] / arch / arm / mach-omap2 / serial.c
CommitLineData
1dbae815 1/*
f30c2269 2 * arch/arm/mach-omap2/serial.c
1dbae815
TL
3 *
4 * OMAP2 serial support.
5 *
6e81176d 6 * Copyright (C) 2005-2008 Nokia Corporation
1dbae815
TL
7 * Author: Paul Mundt <paul.mundt@nokia.com>
8 *
4af4016c
KH
9 * Major rework for PM support by Kevin Hilman
10 *
1dbae815
TL
11 * Based off of arch/arm/mach-omap/omap1/serial.c
12 *
44169075
SS
13 * Copyright (C) 2009 Texas Instruments
14 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com
15 *
1dbae815
TL
16 * This file is subject to the terms and conditions of the GNU General Public
17 * License. See the file "COPYING" in the main directory of this archive
18 * for more details.
19 */
20#include <linux/kernel.h>
21#include <linux/init.h>
f8ce2547 22#include <linux/clk.h>
fced80c7 23#include <linux/io.h>
e03d37d8 24#include <linux/delay.h>
6f251e9d
KH
25#include <linux/platform_device.h>
26#include <linux/slab.h>
3244fcd2 27#include <linux/pm_runtime.h>
0d8e2d0d 28#include <linux/console.h>
45c3eb7d 29#include <linux/omap-dma.h>
6f251e9d 30
6f251e9d 31#include <plat/omap-serial.h>
4af4016c 32
2a296c8f
TL
33#include "common.h"
34#include "omap_hwmod.h"
35#include "omap_device.h"
1d5aef49 36#include "omap-pm.h"
e4c060db 37#include "soc.h"
59fb659b 38#include "prm2xxx_3xxx.h"
4af4016c 39#include "pm.h"
59fb659b 40#include "cm2xxx_3xxx.h"
4af4016c 41#include "prm-regbits-34xx.h"
4814ced5 42#include "control.h"
40e44399 43#include "mux.h"
3d82cbbb 44#include "serial.h"
4af4016c 45
301fe8ee 46/*
c86845db
D
47 * NOTE: By default the serial auto_suspend timeout is disabled as it causes
48 * lost characters over the serial ports. This means that the UART clocks will
49 * stay on until power/autosuspend_delay is set for the uart from sysfs.
50 * This also causes that any deeper omap sleep states are blocked.
301fe8ee 51 */
c86845db 52#define DEFAULT_AUTOSUSPEND_DELAY -1
4af4016c 53
6f251e9d
KH
54#define MAX_UART_HWMOD_NAME_LEN 16
55
4af4016c
KH
56struct omap_uart_state {
57 int num;
4af4016c 58
4af4016c 59 struct list_head node;
6f251e9d 60 struct omap_hwmod *oh;
91930652 61 struct omap_device_pad default_omap_uart_pads[2];
4af4016c
KH
62};
63
4af4016c 64static LIST_HEAD(uart_list);
6f251e9d 65static u8 num_uarts;
8612bd22 66static u8 console_uart_id = -1;
08f86b3e 67static u8 no_console_suspend;
36fc2d15 68static u8 uart_debug;
1dbae815 69
a9e210e0 70#define DEFAULT_RXDMA_POLLRATE 1 /* RX DMA polling rate (us) */
c86845db 71#define DEFAULT_RXDMA_BUFSIZE 4096 /* RX DMA buffer size */
a9e210e0 72#define DEFAULT_RXDMA_TIMEOUT (3 * HZ)/* RX DMA timeout (jiffies) */
c86845db
D
73
74static struct omap_uart_port_info omap_serial_default_info[] __initdata = {
75 {
76 .dma_enabled = false,
77 .dma_rx_buf_size = DEFAULT_RXDMA_BUFSIZE,
a9e210e0 78 .dma_rx_poll_rate = DEFAULT_RXDMA_POLLRATE,
c86845db
D
79 .dma_rx_timeout = DEFAULT_RXDMA_TIMEOUT,
80 .autosuspend_timeout = DEFAULT_AUTOSUSPEND_DELAY,
81 },
82};
83
4af4016c 84#ifdef CONFIG_PM
d8ee4ea6 85static void omap_uart_enable_wakeup(struct device *dev, bool enable)
4af4016c 86{
d8ee4ea6 87 struct platform_device *pdev = to_platform_device(dev);
62f3ec5f 88 struct omap_device *od = to_omap_device(pdev);
4af4016c 89
62f3ec5f
G
90 if (!od)
91 return;
4af4016c 92
62f3ec5f
G
93 if (enable)
94 omap_hwmod_enable_wakeup(od->hwmods[0]);
95 else
96 omap_hwmod_disable_wakeup(od->hwmods[0]);
ba87a9be
JH
97}
98
94734749
G
99/*
100 * Errata i291: [UART]:Cannot Acknowledge Idle Requests
101 * in Smartidle Mode When Configured for DMA Operations.
102 * WA: configure uart in force idle mode.
103 */
d8ee4ea6 104static void omap_uart_set_noidle(struct device *dev)
94734749 105{
d8ee4ea6 106 struct platform_device *pdev = to_platform_device(dev);
94734749
G
107 struct omap_device *od = to_omap_device(pdev);
108
109 omap_hwmod_set_slave_idlemode(od->hwmods[0], HWMOD_IDLEMODE_NO);
110}
111
d8ee4ea6 112static void omap_uart_set_smartidle(struct device *dev)
94734749 113{
d8ee4ea6 114 struct platform_device *pdev = to_platform_device(dev);
94734749 115 struct omap_device *od = to_omap_device(pdev);
5ae256dc 116 u8 idlemode;
94734749 117
5ae256dc
SS
118 if (od->hwmods[0]->class->sysc->idlemodes & SIDLE_SMART_WKUP)
119 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
120 else
121 idlemode = HWMOD_IDLEMODE_SMART;
122
123 omap_hwmod_set_slave_idlemode(od->hwmods[0], idlemode);
94734749
G
124}
125
4af4016c 126#else
d8ee4ea6 127static void omap_uart_enable_wakeup(struct device *dev, bool enable)
62f3ec5f 128{}
d8ee4ea6
FB
129static void omap_uart_set_noidle(struct device *dev) {}
130static void omap_uart_set_smartidle(struct device *dev) {}
4af4016c
KH
131#endif /* CONFIG_PM */
132
7496ba30 133#ifdef CONFIG_OMAP_MUX
91930652
G
134
135#define OMAP_UART_DEFAULT_PAD_NAME_LEN 28
136static char rx_pad_name[OMAP_UART_DEFAULT_PAD_NAME_LEN],
137 tx_pad_name[OMAP_UART_DEFAULT_PAD_NAME_LEN] __initdata;
138
139static void __init
140omap_serial_fill_uart_tx_rx_pads(struct omap_board_data *bdata,
141 struct omap_uart_state *uart)
142{
143 uart->default_omap_uart_pads[0].name = rx_pad_name;
144 uart->default_omap_uart_pads[0].flags = OMAP_DEVICE_PAD_REMUX |
145 OMAP_DEVICE_PAD_WAKEUP;
146 uart->default_omap_uart_pads[0].enable = OMAP_PIN_INPUT |
147 OMAP_MUX_MODE0;
148 uart->default_omap_uart_pads[0].idle = OMAP_PIN_INPUT | OMAP_MUX_MODE0;
149 uart->default_omap_uart_pads[1].name = tx_pad_name;
150 uart->default_omap_uart_pads[1].enable = OMAP_PIN_OUTPUT |
151 OMAP_MUX_MODE0;
152 bdata->pads = uart->default_omap_uart_pads;
153 bdata->pads_cnt = ARRAY_SIZE(uart->default_omap_uart_pads);
154}
155
156static void __init omap_serial_check_wakeup(struct omap_board_data *bdata,
157 struct omap_uart_state *uart)
7496ba30 158{
91930652
G
159 struct omap_mux_partition *tx_partition = NULL, *rx_partition = NULL;
160 struct omap_mux *rx_mux = NULL, *tx_mux = NULL;
161 char *rx_fmt, *tx_fmt;
162 int uart_nr = bdata->id + 1;
163
164 if (bdata->id != 2) {
165 rx_fmt = "uart%d_rx.uart%d_rx";
166 tx_fmt = "uart%d_tx.uart%d_tx";
167 } else {
168 rx_fmt = "uart%d_rx_irrx.uart%d_rx_irrx";
169 tx_fmt = "uart%d_tx_irtx.uart%d_tx_irtx";
170 }
171
172 snprintf(rx_pad_name, OMAP_UART_DEFAULT_PAD_NAME_LEN, rx_fmt,
173 uart_nr, uart_nr);
174 snprintf(tx_pad_name, OMAP_UART_DEFAULT_PAD_NAME_LEN, tx_fmt,
175 uart_nr, uart_nr);
176
177 if (omap_mux_get_by_name(rx_pad_name, &rx_partition, &rx_mux) >= 0 &&
178 omap_mux_get_by_name
179 (tx_pad_name, &tx_partition, &tx_mux) >= 0) {
180 u16 tx_mode, rx_mode;
181
182 tx_mode = omap_mux_read(tx_partition, tx_mux->reg_offset);
183 rx_mode = omap_mux_read(rx_partition, rx_mux->reg_offset);
184
185 /*
186 * Check if uart is used in default tx/rx mode i.e. in mux mode0
187 * if yes then configure rx pin for wake up capability
188 */
189 if (OMAP_MODE_UART(rx_mode) && OMAP_MODE_UART(tx_mode))
190 omap_serial_fill_uart_tx_rx_pads(bdata, uart);
191 }
7496ba30
G
192}
193#else
91930652
G
194static void __init omap_serial_check_wakeup(struct omap_board_data *bdata,
195 struct omap_uart_state *uart)
196{
197}
7496ba30
G
198#endif
199
8c3d4534 200static char *cmdline_find_option(char *str)
8612bd22
G
201{
202 extern char *saved_command_line;
203
204 return strstr(saved_command_line, str);
205}
206
3e16f925 207static int __init omap_serial_early_init(void)
1dbae815 208{
6f251e9d
KH
209 do {
210 char oh_name[MAX_UART_HWMOD_NAME_LEN];
211 struct omap_hwmod *oh;
212 struct omap_uart_state *uart;
8612bd22 213 char uart_name[MAX_UART_HWMOD_NAME_LEN];
21b90340 214
6f251e9d 215 snprintf(oh_name, MAX_UART_HWMOD_NAME_LEN,
969996a5 216 "uart%d", num_uarts + 1);
6f251e9d
KH
217 oh = omap_hwmod_lookup(oh_name);
218 if (!oh)
219 break;
220
221 uart = kzalloc(sizeof(struct omap_uart_state), GFP_KERNEL);
222 if (WARN_ON(!uart))
3e16f925 223 return -ENODEV;
1dbae815 224
6f251e9d 225 uart->oh = oh;
969996a5 226 uart->num = num_uarts++;
6f251e9d 227 list_add_tail(&uart->node, &uart_list);
8612bd22
G
228 snprintf(uart_name, MAX_UART_HWMOD_NAME_LEN,
229 "%s%d", OMAP_SERIAL_NAME, uart->num);
230
231 if (cmdline_find_option(uart_name)) {
232 console_uart_id = uart->num;
08f86b3e 233
36fc2d15
G
234 if (console_loglevel >= 10) {
235 uart_debug = true;
7852ec05
PW
236 pr_info("%s used as console in debug mode: uart%d clocks will not be gated",
237 uart_name, uart->num);
36fc2d15
G
238 }
239
08f86b3e
G
240 if (cmdline_find_option("no_console_suspend"))
241 no_console_suspend = true;
242
8612bd22
G
243 /*
244 * omap-uart can be used for earlyprintk logs
245 * So if omap-uart is used as console then prevent
246 * uart reset and idle to get logs from omap-uart
247 * until uart console driver is available to take
248 * care for console messages.
249 * Idling or resetting omap-uart while printing logs
250 * early boot logs can stall the boot-up.
251 */
252 oh->flags |= HWMOD_INIT_NO_IDLE | HWMOD_INIT_NO_RESET;
253 }
6f251e9d 254 } while (1);
3e16f925
TL
255
256 return 0;
b3c6df3a 257}
3e16f925 258core_initcall(omap_serial_early_init);
b3c6df3a 259
f62349ee
MW
260/**
261 * omap_serial_init_port() - initialize single serial port
40e44399 262 * @bdata: port specific board data pointer
c86845db 263 * @info: platform specific data pointer
f62349ee 264 *
40e44399 265 * This function initialies serial driver for given port only.
f62349ee
MW
266 * Platforms can call this function instead of omap_serial_init()
267 * if they don't plan to use all available UARTs as serial ports.
268 *
269 * Don't mix calls to omap_serial_init_port() and omap_serial_init(),
270 * use only one of the two.
271 */
c86845db
D
272void __init omap_serial_init_port(struct omap_board_data *bdata,
273 struct omap_uart_port_info *info)
b3c6df3a 274{
f62349ee 275 struct omap_uart_state *uart;
6f251e9d 276 struct omap_hwmod *oh;
3528c58e 277 struct platform_device *pdev;
6f251e9d
KH
278 void *pdata = NULL;
279 u32 pdata_size = 0;
280 char *name;
6f251e9d 281 struct omap_uart_port_info omap_up;
970a724d 282
40e44399 283 if (WARN_ON(!bdata))
6f251e9d 284 return;
40e44399
TL
285 if (WARN_ON(bdata->id < 0))
286 return;
287 if (WARN_ON(bdata->id >= num_uarts))
e88d556d 288 return;
f62349ee 289
6f251e9d 290 list_for_each_entry(uart, &uart_list, node)
40e44399 291 if (bdata->id == uart->num)
6f251e9d 292 break;
c86845db
D
293 if (!info)
294 info = omap_serial_default_info;
f2eeeae0 295
6f251e9d 296 oh = uart->oh;
6f251e9d
KH
297 name = DRIVER_NAME;
298
c86845db 299 omap_up.dma_enabled = info->dma_enabled;
6f251e9d 300 omap_up.uartclk = OMAP24XX_BASE_BAUD * 16;
273558b3 301 omap_up.flags = UPF_BOOT_AUTOCONF;
ec3bebc6 302 omap_up.get_context_loss_count = omap_pm_get_dev_context_loss_count;
be4b0281 303 omap_up.set_forceidle = omap_uart_set_smartidle;
94734749 304 omap_up.set_noidle = omap_uart_set_noidle;
62f3ec5f 305 omap_up.enable_wakeup = omap_uart_enable_wakeup;
c86845db
D
306 omap_up.dma_rx_buf_size = info->dma_rx_buf_size;
307 omap_up.dma_rx_timeout = info->dma_rx_timeout;
a9e210e0 308 omap_up.dma_rx_poll_rate = info->dma_rx_poll_rate;
c86845db 309 omap_up.autosuspend_timeout = info->autosuspend_timeout;
9574f36f
N
310 omap_up.DTR_gpio = info->DTR_gpio;
311 omap_up.DTR_inverted = info->DTR_inverted;
312 omap_up.DTR_present = info->DTR_present;
94734749 313
6f251e9d
KH
314 pdata = &omap_up;
315 pdata_size = sizeof(struct omap_uart_port_info);
6f251e9d
KH
316
317 if (WARN_ON(!oh))
318 return;
319
3528c58e 320 pdev = omap_device_build(name, uart->num, oh, pdata, pdata_size,
f718e2c0 321 NULL, 0, false);
a032d33b
PW
322 if (IS_ERR(pdev)) {
323 WARN(1, "Could not build omap_device for %s: %s.\n", name,
324 oh->name);
325 return;
326 }
6f251e9d 327
08f86b3e
G
328 if ((console_uart_id == bdata->id) && no_console_suspend)
329 omap_device_disable_idle_on_suspend(pdev);
330
40e44399
TL
331 oh->mux = omap_hwmod_mux_init(bdata->pads, bdata->pads_cnt);
332
44b1d42a
KH
333 if (console_uart_id == bdata->id) {
334 omap_device_enable(pdev);
335 pm_runtime_set_active(&pdev->dev);
336 }
337
6f251e9d
KH
338 oh->dev_attr = uart;
339
36fc2d15
G
340 if (((cpu_is_omap34xx() || cpu_is_omap44xx()) && bdata->pads)
341 && !uart_debug)
3528c58e 342 device_init_wakeup(&pdev->dev, true);
f62349ee
MW
343}
344
345/**
c86845db
D
346 * omap_serial_board_init() - initialize all supported serial ports
347 * @info: platform specific data pointer
f62349ee
MW
348 *
349 * Initializes all available UARTs as serial ports. Platforms
350 * can call this function when they want to have default behaviour
351 * for serial ports (e.g initialize them all as serial ports).
352 */
c86845db 353void __init omap_serial_board_init(struct omap_uart_port_info *info)
f62349ee 354{
6f251e9d 355 struct omap_uart_state *uart;
40e44399 356 struct omap_board_data bdata;
f62349ee 357
40e44399
TL
358 list_for_each_entry(uart, &uart_list, node) {
359 bdata.id = uart->num;
360 bdata.flags = 0;
361 bdata.pads = NULL;
362 bdata.pads_cnt = 0;
7496ba30 363
91930652 364 omap_serial_check_wakeup(&bdata, uart);
7496ba30 365
c86845db
D
366 if (!info)
367 omap_serial_init_port(&bdata, NULL);
368 else
369 omap_serial_init_port(&bdata, &info[uart->num]);
40e44399 370 }
1dbae815 371}
c86845db
D
372
373/**
374 * omap_serial_init() - initialize all supported serial ports
375 *
376 * Initializes all available UARTs.
377 * Platforms can call this function when they want to have default behaviour
378 * for serial ports (e.g initialize them all as serial ports).
379 */
380void __init omap_serial_init(void)
381{
382 omap_serial_board_init(NULL);
383}
This page took 0.555226 seconds and 5 git commands to generate.