blob: 98e5df9008d1e332becd16f94e7067039cd8c302 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/smd_tty.c
2 *
3 * Copyright (C) 2007 Google, Inc.
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +05304 * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005 * Author: Brian Swetland <swetland@google.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/fs.h>
20#include <linux/cdev.h>
21#include <linux/device.h>
22#include <linux/interrupt.h>
23#include <linux/delay.h>
24#include <linux/wakelock.h>
25#include <linux/platform_device.h>
26#include <linux/sched.h>
Devin Kim36b2b8c2012-08-29 23:21:22 -070027#include <linux/pm_qos.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028
29#include <linux/tty.h>
30#include <linux/tty_driver.h>
31#include <linux/tty_flip.h>
32
33#include <mach/msm_smd.h>
34#include <mach/peripheral-loader.h>
Jeff Hugo4c0ba6c2011-07-15 11:47:13 -060035#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036
37#include "smd_private.h"
38
39#define MAX_SMD_TTYS 37
40#define MAX_TTY_BUF_SIZE 2048
41
42static DEFINE_MUTEX(smd_tty_lock);
43
44static uint smd_tty_modem_wait;
45module_param_named(modem_wait, smd_tty_modem_wait,
46 uint, S_IRUGO | S_IWUSR | S_IWGRP);
47
48struct smd_tty_info {
49 smd_channel_t *ch;
50 struct tty_struct *tty;
51 struct wake_lock wake_lock;
52 int open_count;
53 struct tasklet_struct tty_tsklt;
54 struct timer_list buf_req_timer;
55 struct completion ch_allocated;
56 struct platform_driver driver;
57 void *pil;
58 int in_reset;
59 int in_reset_updated;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -060060 int is_open;
61 wait_queue_head_t ch_opened_wait_queue;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062 spinlock_t reset_lock;
Eric Holmberg513ad582011-12-14 16:27:13 -070063 struct smd_config *smd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064};
65
Eric Holmberg513ad582011-12-14 16:27:13 -070066/**
67 * SMD port configuration.
68 *
69 * @tty_dev_index Index into smd_tty[]
70 * @port_name Name of the SMD port
71 * @dev_name Name of the TTY Device (if NULL, @port_name is used)
72 * @edge SMD edge
73 */
74struct smd_config {
75 uint32_t tty_dev_index;
76 const char *port_name;
77 const char *dev_name;
78 uint32_t edge;
79};
80
81static struct smd_config smd_configs[] = {
82 {0, "DS", NULL, SMD_APPS_MODEM},
83 {1, "APPS_FM", NULL, SMD_APPS_WCNSS},
84 {2, "APPS_RIVA_BT_ACL", NULL, SMD_APPS_WCNSS},
85 {3, "APPS_RIVA_BT_CMD", NULL, SMD_APPS_WCNSS},
86 {4, "MBALBRIDGE", NULL, SMD_APPS_MODEM},
Jeff Hugodfb9c9a2012-04-10 14:22:47 -060087 {5, "APPS_RIVA_ANT_CMD", NULL, SMD_APPS_WCNSS},
88 {6, "APPS_RIVA_ANT_DATA", NULL, SMD_APPS_WCNSS},
Eric Holmberg513ad582011-12-14 16:27:13 -070089 {7, "DATA1", NULL, SMD_APPS_MODEM},
Eric Holmbergbe1dc5f2011-12-14 21:35:12 -070090 {11, "DATA11", NULL, SMD_APPS_MODEM},
Eric Holmberg513ad582011-12-14 16:27:13 -070091 {21, "DATA21", NULL, SMD_APPS_MODEM},
92 {27, "GPSNMEA", NULL, SMD_APPS_MODEM},
93 {36, "LOOPBACK", "LOOPBACK_TTY", SMD_APPS_MODEM},
94};
95#define DS_IDX 0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096#define LOOPBACK_IDX 36
Devin Kim36b2b8c2012-08-29 23:21:22 -070097#define BT_ACL_IDX 2
98#define BT_CMD_IDX 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099
100static struct delayed_work loopback_work;
101static struct smd_tty_info smd_tty[MAX_SMD_TTYS];
Devin Kim36b2b8c2012-08-29 23:21:22 -0700102static struct pm_qos_request smd_tty_qos_req;
103static struct work_struct pm_qos_set_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104
105static int is_in_reset(struct smd_tty_info *info)
106{
107 return info->in_reset;
108}
109
Devin Kim36b2b8c2012-08-29 23:21:22 -0700110static void pm_qos_set_worker(struct work_struct *work)
111{
112 /* keep the request for 500ms */
113 pm_qos_update_request_timeout(&smd_tty_qos_req,
114 0, jiffies_to_usecs(HZ / 2));
115}
116
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117static void buf_req_retry(unsigned long param)
118{
119 struct smd_tty_info *info = (struct smd_tty_info *)param;
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700120 unsigned long flags;
121
122 spin_lock_irqsave(&info->reset_lock, flags);
123 if (info->is_open) {
124 spin_unlock_irqrestore(&info->reset_lock, flags);
125 tasklet_hi_schedule(&info->tty_tsklt);
126 return;
127 }
128 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129}
130
131static void smd_tty_read(unsigned long param)
132{
133 unsigned char *ptr;
134 int avail;
135 struct smd_tty_info *info = (struct smd_tty_info *)param;
136 struct tty_struct *tty = info->tty;
137
138 if (!tty)
139 return;
140
141 for (;;) {
142 if (is_in_reset(info)) {
143 /* signal TTY clients using TTY_BREAK */
144 tty_insert_flip_char(tty, 0x00, TTY_BREAK);
145 tty_flip_buffer_push(tty);
146 break;
147 }
148
149 if (test_bit(TTY_THROTTLED, &tty->flags)) break;
150 avail = smd_read_avail(info->ch);
151 if (avail == 0)
152 break;
153
154 if (avail > MAX_TTY_BUF_SIZE)
155 avail = MAX_TTY_BUF_SIZE;
156
157 avail = tty_prepare_flip_string(tty, &ptr, avail);
158 if (avail <= 0) {
Stephen Boyd49a1e882012-07-02 17:28:13 -0700159 mod_timer(&info->buf_req_timer,
160 jiffies + msecs_to_jiffies(30));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700161 return;
162 }
163
164 if (smd_read(info->ch, ptr, avail) != avail) {
165 /* shouldn't be possible since we're in interrupt
166 ** context here and nobody else could 'steal' our
167 ** characters.
168 */
169 printk(KERN_ERR "OOPS - smd_tty_buffer mismatch?!");
170 }
171
Devin Kim36b2b8c2012-08-29 23:21:22 -0700172#ifdef CONFIG_HAS_WAKELOCK
173 pr_debug("%s: lock wakelock %s\n", __func__, info->wake_lock.name);
174#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175 wake_lock_timeout(&info->wake_lock, HZ / 2);
176 tty_flip_buffer_push(tty);
177 }
178
179 /* XXX only when writable and necessary */
180 tty_wakeup(tty);
181}
182
183static void smd_tty_notify(void *priv, unsigned event)
184{
185 struct smd_tty_info *info = priv;
186 unsigned long flags;
187
188 switch (event) {
189 case SMD_EVENT_DATA:
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700190 spin_lock_irqsave(&info->reset_lock, flags);
191 if (!info->is_open) {
192 spin_unlock_irqrestore(&info->reset_lock, flags);
193 break;
194 }
195 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700196 /* There may be clients (tty framework) that are blocked
197 * waiting for space to write data, so if a possible read
198 * interrupt came in wake anyone waiting and disable the
199 * interrupts
200 */
201 if (smd_write_avail(info->ch)) {
202 smd_disable_read_intr(info->ch);
Devin Kim36b2b8c2012-08-29 23:21:22 -0700203 if (info->tty) {
204 unsigned int n = info->tty->index;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 wake_up_interruptible(&info->tty->write_wait);
Devin Kim36b2b8c2012-08-29 23:21:22 -0700206
207 /* use pm_qos for BT performance */
208 if (n == BT_ACL_IDX || n == BT_CMD_IDX)
209 schedule_work(&pm_qos_set_work);
210 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 }
212 tasklet_hi_schedule(&info->tty_tsklt);
213 break;
214
215 case SMD_EVENT_OPEN:
216 spin_lock_irqsave(&info->reset_lock, flags);
217 info->in_reset = 0;
218 info->in_reset_updated = 1;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600219 info->is_open = 1;
220 wake_up_interruptible(&info->ch_opened_wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221 spin_unlock_irqrestore(&info->reset_lock, flags);
222 break;
223
224 case SMD_EVENT_CLOSE:
225 spin_lock_irqsave(&info->reset_lock, flags);
226 info->in_reset = 1;
227 info->in_reset_updated = 1;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600228 info->is_open = 0;
229 wake_up_interruptible(&info->ch_opened_wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230 spin_unlock_irqrestore(&info->reset_lock, flags);
231 /* schedule task to send TTY_BREAK */
232 tasklet_hi_schedule(&info->tty_tsklt);
233
234 if (info->tty->index == LOOPBACK_IDX)
235 schedule_delayed_work(&loopback_work,
236 msecs_to_jiffies(1000));
237 break;
238 }
239}
240
241static uint32_t is_modem_smsm_inited(void)
242{
243 uint32_t modem_state;
244 uint32_t ready_state = (SMSM_INIT | SMSM_SMDINIT);
245
246 modem_state = smsm_get_state(SMSM_MODEM_STATE);
247 return (modem_state & ready_state) == ready_state;
248}
249
250static int smd_tty_open(struct tty_struct *tty, struct file *f)
251{
252 int res = 0;
Eric Holmberg513ad582011-12-14 16:27:13 -0700253 unsigned int n = tty->index;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254 struct smd_tty_info *info;
Eric Holmberga53cf232012-02-28 13:41:44 -0700255 const char *peripheral = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700256
257
Eric Holmberg513ad582011-12-14 16:27:13 -0700258 if (n >= MAX_SMD_TTYS || !smd_tty[n].smd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700259 return -ENODEV;
260
261 info = smd_tty + n;
262
263 mutex_lock(&smd_tty_lock);
264 tty->driver_data = info;
265
266 if (info->open_count++ == 0) {
Eric Holmberga53cf232012-02-28 13:41:44 -0700267 peripheral = smd_edge_to_subsystem(smd_tty[n].smd->edge);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268 if (peripheral) {
Eric Holmberg513ad582011-12-14 16:27:13 -0700269 info->pil = pil_get(peripheral);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 if (IS_ERR(info->pil)) {
271 res = PTR_ERR(info->pil);
272 goto out;
273 }
274
275 /* Wait for the modem SMSM to be inited for the SMD
276 * Loopback channel to be allocated at the modem. Since
277 * the wait need to be done atmost once, using msleep
278 * doesn't degrade the performance.
279 */
Eric Holmberg513ad582011-12-14 16:27:13 -0700280 if (n == LOOPBACK_IDX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700281 if (!is_modem_smsm_inited())
282 msleep(5000);
283 smsm_change_state(SMSM_APPS_STATE,
284 0, SMSM_SMD_LOOPBACK);
285 msleep(100);
286 }
287
288
289 /*
290 * Wait for a channel to be allocated so we know
291 * the modem is ready enough.
292 */
293 if (smd_tty_modem_wait) {
294 res = wait_for_completion_interruptible_timeout(
295 &info->ch_allocated,
296 msecs_to_jiffies(smd_tty_modem_wait *
297 1000));
298
299 if (res == 0) {
300 pr_err("Timed out waiting for SMD"
301 " channel\n");
302 res = -ETIMEDOUT;
303 goto release_pil;
304 } else if (res < 0) {
305 pr_err("Error waiting for SMD channel:"
306 " %d\n",
307 res);
308 goto release_pil;
309 }
310
311 res = 0;
312 }
313 }
314
315
316 info->tty = tty;
317 tasklet_init(&info->tty_tsklt, smd_tty_read,
318 (unsigned long)info);
319 wake_lock_init(&info->wake_lock, WAKE_LOCK_SUSPEND,
Eric Holmberg513ad582011-12-14 16:27:13 -0700320 smd_tty[n].smd->port_name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700321 if (!info->ch) {
Eric Holmberg513ad582011-12-14 16:27:13 -0700322 res = smd_named_open_on_edge(smd_tty[n].smd->port_name,
323 smd_tty[n].smd->edge,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324 &info->ch, info,
325 smd_tty_notify);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600326 if (res < 0) {
327 pr_err("%s: %s open failed %d\n", __func__,
Eric Holmberg513ad582011-12-14 16:27:13 -0700328 smd_tty[n].smd->port_name, res);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600329 goto release_pil;
330 }
331
332 res = wait_event_interruptible_timeout(
333 info->ch_opened_wait_queue,
334 info->is_open, (2 * HZ));
335 if (res == 0)
336 res = -ETIMEDOUT;
337 if (res < 0) {
338 pr_err("%s: wait for %s smd_open failed %d\n",
Eric Holmberg513ad582011-12-14 16:27:13 -0700339 __func__, smd_tty[n].smd->port_name,
340 res);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600341 goto release_pil;
342 }
343 res = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700344 }
345 }
346
347release_pil:
348 if (res < 0)
349 pil_put(info->pil);
350 else
351 smd_disable_read_intr(info->ch);
352out:
353 mutex_unlock(&smd_tty_lock);
354
355 return res;
356}
357
358static void smd_tty_close(struct tty_struct *tty, struct file *f)
359{
360 struct smd_tty_info *info = tty->driver_data;
Karthikeyan Ramasubramaniand563de52011-11-22 08:38:17 -0700361 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700362
363 if (info == 0)
364 return;
365
366 mutex_lock(&smd_tty_lock);
367 if (--info->open_count == 0) {
Karthikeyan Ramasubramaniand563de52011-11-22 08:38:17 -0700368 spin_lock_irqsave(&info->reset_lock, flags);
369 info->is_open = 0;
370 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700371 if (info->tty) {
372 tasklet_kill(&info->tty_tsklt);
373 wake_lock_destroy(&info->wake_lock);
374 info->tty = 0;
375 }
376 tty->driver_data = 0;
377 del_timer(&info->buf_req_timer);
378 if (info->ch) {
379 smd_close(info->ch);
380 info->ch = 0;
381 pil_put(info->pil);
382 }
383 }
384 mutex_unlock(&smd_tty_lock);
385}
386
387static int smd_tty_write(struct tty_struct *tty, const unsigned char *buf, int len)
388{
389 struct smd_tty_info *info = tty->driver_data;
390 int avail;
391
392 /* if we're writing to a packet channel we will
393 ** never be able to write more data than there
394 ** is currently space for
395 */
396 if (is_in_reset(info))
397 return -ENETRESET;
398
399 avail = smd_write_avail(info->ch);
400 /* if no space, we'll have to setup a notification later to wake up the
401 * tty framework when space becomes avaliable
402 */
403 if (!avail) {
404 smd_enable_read_intr(info->ch);
405 return 0;
406 }
407 if (len > avail)
408 len = avail;
409
410 return smd_write(info->ch, buf, len);
411}
412
413static int smd_tty_write_room(struct tty_struct *tty)
414{
415 struct smd_tty_info *info = tty->driver_data;
416 return smd_write_avail(info->ch);
417}
418
419static int smd_tty_chars_in_buffer(struct tty_struct *tty)
420{
421 struct smd_tty_info *info = tty->driver_data;
422 return smd_read_avail(info->ch);
423}
424
425static void smd_tty_unthrottle(struct tty_struct *tty)
426{
427 struct smd_tty_info *info = tty->driver_data;
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700428 unsigned long flags;
429
430 spin_lock_irqsave(&info->reset_lock, flags);
431 if (info->is_open) {
432 spin_unlock_irqrestore(&info->reset_lock, flags);
433 tasklet_hi_schedule(&info->tty_tsklt);
434 return;
435 }
436 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437}
438
439/*
440 * Returns the current TIOCM status bits including:
441 * SMD Signals (DTR/DSR, CTS/RTS, CD, RI)
442 * TIOCM_OUT1 - reset state (1=in reset)
443 * TIOCM_OUT2 - reset state updated (1=updated)
444 */
445static int smd_tty_tiocmget(struct tty_struct *tty)
446{
447 struct smd_tty_info *info = tty->driver_data;
448 unsigned long flags;
449 int tiocm;
450
451 tiocm = smd_tiocmget(info->ch);
452
453 spin_lock_irqsave(&info->reset_lock, flags);
454 tiocm |= (info->in_reset ? TIOCM_OUT1 : 0);
455 if (info->in_reset_updated) {
456 tiocm |= TIOCM_OUT2;
457 info->in_reset_updated = 0;
458 }
459 spin_unlock_irqrestore(&info->reset_lock, flags);
460
461 return tiocm;
462}
463
464static int smd_tty_tiocmset(struct tty_struct *tty,
465 unsigned int set, unsigned int clear)
466{
467 struct smd_tty_info *info = tty->driver_data;
468
469 if (info->in_reset)
470 return -ENETRESET;
471
472 return smd_tiocmset(info->ch, set, clear);
473}
474
475static void loopback_probe_worker(struct work_struct *work)
476{
477 /* wait for modem to restart before requesting loopback server */
478 if (!is_modem_smsm_inited())
479 schedule_delayed_work(&loopback_work, msecs_to_jiffies(1000));
480 else
481 smsm_change_state(SMSM_APPS_STATE,
482 0, SMSM_SMD_LOOPBACK);
483}
484
485static struct tty_operations smd_tty_ops = {
486 .open = smd_tty_open,
487 .close = smd_tty_close,
488 .write = smd_tty_write,
489 .write_room = smd_tty_write_room,
490 .chars_in_buffer = smd_tty_chars_in_buffer,
491 .unthrottle = smd_tty_unthrottle,
492 .tiocmget = smd_tty_tiocmget,
493 .tiocmset = smd_tty_tiocmset,
494};
495
496static int smd_tty_dummy_probe(struct platform_device *pdev)
497{
Eric Holmberg513ad582011-12-14 16:27:13 -0700498 int n;
499 int idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700500
Eric Holmberg513ad582011-12-14 16:27:13 -0700501 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
502 idx = smd_configs[n].tty_dev_index;
503
504 if (!smd_configs[n].dev_name)
505 continue;
506
Eric Holmbergdaf36d12012-02-08 17:05:21 -0700507 if (pdev->id == smd_configs[n].edge &&
508 !strncmp(pdev->name, smd_configs[n].dev_name,
Eric Holmberg513ad582011-12-14 16:27:13 -0700509 SMD_MAX_CH_NAME_LEN)) {
510 complete_all(&smd_tty[idx].ch_allocated);
511 return 0;
512 }
513 }
514 pr_err("%s: unknown device '%s'\n", __func__, pdev->name);
515
516 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700517}
518
519static struct tty_driver *smd_tty_driver;
520
521static int __init smd_tty_init(void)
522{
523 int ret;
Eric Holmberg513ad582011-12-14 16:27:13 -0700524 int n;
525 int idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700526
527 smd_tty_driver = alloc_tty_driver(MAX_SMD_TTYS);
528 if (smd_tty_driver == 0)
529 return -ENOMEM;
530
531 smd_tty_driver->owner = THIS_MODULE;
532 smd_tty_driver->driver_name = "smd_tty_driver";
533 smd_tty_driver->name = "smd";
534 smd_tty_driver->major = 0;
535 smd_tty_driver->minor_start = 0;
536 smd_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
537 smd_tty_driver->subtype = SERIAL_TYPE_NORMAL;
538 smd_tty_driver->init_termios = tty_std_termios;
539 smd_tty_driver->init_termios.c_iflag = 0;
540 smd_tty_driver->init_termios.c_oflag = 0;
541 smd_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
542 smd_tty_driver->init_termios.c_lflag = 0;
543 smd_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS |
544 TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
545 tty_set_operations(smd_tty_driver, &smd_tty_ops);
546
547 ret = tty_register_driver(smd_tty_driver);
Eric Holmberg513ad582011-12-14 16:27:13 -0700548 if (ret) {
549 put_tty_driver(smd_tty_driver);
550 pr_err("%s: driver registration failed %d\n", __func__, ret);
551 return ret;
Jeff Hugo4c0ba6c2011-07-15 11:47:13 -0600552 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700553
Eric Holmberg513ad582011-12-14 16:27:13 -0700554 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
555 idx = smd_configs[n].tty_dev_index;
556
557 if (smd_configs[n].dev_name == NULL)
558 smd_configs[n].dev_name = smd_configs[n].port_name;
559
560 if (idx == DS_IDX) {
561 /*
562 * DS port uses the kernel API starting with
563 * 8660 Fusion. Only register the userspace
564 * platform device for older targets.
565 */
566 int legacy_ds = 0;
567
568 legacy_ds |= cpu_is_msm7x01() || cpu_is_msm7x25();
569 legacy_ds |= cpu_is_msm7x27() || cpu_is_msm7x30();
570 legacy_ds |= cpu_is_qsd8x50() || cpu_is_msm8x55();
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +0530571 /*
572 * use legacy mode for 8660 Standalone (subtype 0)
573 */
Eric Holmberg513ad582011-12-14 16:27:13 -0700574 legacy_ds |= cpu_is_msm8x60() &&
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +0530575 (socinfo_get_platform_subtype() == 0x0);
Eric Holmberg513ad582011-12-14 16:27:13 -0700576
577 if (!legacy_ds)
578 continue;
579 }
580
581 tty_register_device(smd_tty_driver, idx, 0);
582 init_completion(&smd_tty[idx].ch_allocated);
583
584 /* register platform device */
585 smd_tty[idx].driver.probe = smd_tty_dummy_probe;
586 smd_tty[idx].driver.driver.name = smd_configs[n].dev_name;
587 smd_tty[idx].driver.driver.owner = THIS_MODULE;
588 spin_lock_init(&smd_tty[idx].reset_lock);
589 smd_tty[idx].is_open = 0;
Stephen Boyd49a1e882012-07-02 17:28:13 -0700590 setup_timer(&smd_tty[idx].buf_req_timer, buf_req_retry,
591 (unsigned long)&smd_tty[idx]);
Eric Holmberg513ad582011-12-14 16:27:13 -0700592 init_waitqueue_head(&smd_tty[idx].ch_opened_wait_queue);
593 ret = platform_driver_register(&smd_tty[idx].driver);
594
595 if (ret) {
596 pr_err("%s: init failed %d (%d)\n", __func__, idx, ret);
597 smd_tty[idx].driver.probe = NULL;
598 goto out;
599 }
600 smd_tty[idx].smd = &smd_configs[n];
601 }
Devin Kim36b2b8c2012-08-29 23:21:22 -0700602 INIT_WORK(&pm_qos_set_work, pm_qos_set_worker);
Eric Holmberg513ad582011-12-14 16:27:13 -0700603 INIT_DELAYED_WORK(&loopback_work, loopback_probe_worker);
Devin Kim36b2b8c2012-08-29 23:21:22 -0700604 pm_qos_add_request(&smd_tty_qos_req, PM_QOS_CPU_DMA_LATENCY,
605 PM_QOS_DEFAULT_VALUE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700606 return 0;
607
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700608out:
Eric Holmberg513ad582011-12-14 16:27:13 -0700609 /* unregister platform devices */
610 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
611 idx = smd_configs[n].tty_dev_index;
612
613 if (smd_tty[idx].driver.probe) {
614 platform_driver_unregister(&smd_tty[idx].driver);
615 tty_unregister_device(smd_tty_driver, idx);
616 }
617 }
618
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700619 tty_unregister_driver(smd_tty_driver);
620 put_tty_driver(smd_tty_driver);
621 return ret;
622}
623
624module_init(smd_tty_init);