blob: d8560247df7b8e6613d8451dae0eab96e88bdd37 [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>
27
28#include <linux/tty.h>
29#include <linux/tty_driver.h>
30#include <linux/tty_flip.h>
31
32#include <mach/msm_smd.h>
33#include <mach/peripheral-loader.h>
Jeff Hugo4c0ba6c2011-07-15 11:47:13 -060034#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035
36#include "smd_private.h"
37
38#define MAX_SMD_TTYS 37
39#define MAX_TTY_BUF_SIZE 2048
40
41static DEFINE_MUTEX(smd_tty_lock);
42
43static uint smd_tty_modem_wait;
44module_param_named(modem_wait, smd_tty_modem_wait,
45 uint, S_IRUGO | S_IWUSR | S_IWGRP);
46
47struct smd_tty_info {
48 smd_channel_t *ch;
49 struct tty_struct *tty;
50 struct wake_lock wake_lock;
51 int open_count;
52 struct tasklet_struct tty_tsklt;
53 struct timer_list buf_req_timer;
54 struct completion ch_allocated;
55 struct platform_driver driver;
56 void *pil;
57 int in_reset;
58 int in_reset_updated;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -060059 int is_open;
60 wait_queue_head_t ch_opened_wait_queue;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061 spinlock_t reset_lock;
Eric Holmberg513ad582011-12-14 16:27:13 -070062 struct smd_config *smd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070063};
64
Eric Holmberg513ad582011-12-14 16:27:13 -070065/**
66 * SMD port configuration.
67 *
68 * @tty_dev_index Index into smd_tty[]
69 * @port_name Name of the SMD port
70 * @dev_name Name of the TTY Device (if NULL, @port_name is used)
71 * @edge SMD edge
72 */
73struct smd_config {
74 uint32_t tty_dev_index;
75 const char *port_name;
76 const char *dev_name;
77 uint32_t edge;
78};
79
80static struct smd_config smd_configs[] = {
81 {0, "DS", NULL, SMD_APPS_MODEM},
82 {1, "APPS_FM", NULL, SMD_APPS_WCNSS},
83 {2, "APPS_RIVA_BT_ACL", NULL, SMD_APPS_WCNSS},
84 {3, "APPS_RIVA_BT_CMD", NULL, SMD_APPS_WCNSS},
85 {4, "MBALBRIDGE", NULL, SMD_APPS_MODEM},
86 {7, "DATA1", NULL, SMD_APPS_MODEM},
Eric Holmbergbe1dc5f2011-12-14 21:35:12 -070087 {11, "DATA11", NULL, SMD_APPS_MODEM},
Eric Holmberg513ad582011-12-14 16:27:13 -070088 {21, "DATA21", NULL, SMD_APPS_MODEM},
89 {27, "GPSNMEA", NULL, SMD_APPS_MODEM},
90 {36, "LOOPBACK", "LOOPBACK_TTY", SMD_APPS_MODEM},
91};
92#define DS_IDX 0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093#define LOOPBACK_IDX 36
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094
95static struct delayed_work loopback_work;
96static struct smd_tty_info smd_tty[MAX_SMD_TTYS];
97
98static int is_in_reset(struct smd_tty_info *info)
99{
100 return info->in_reset;
101}
102
103static void buf_req_retry(unsigned long param)
104{
105 struct smd_tty_info *info = (struct smd_tty_info *)param;
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700106 unsigned long flags;
107
108 spin_lock_irqsave(&info->reset_lock, flags);
109 if (info->is_open) {
110 spin_unlock_irqrestore(&info->reset_lock, flags);
111 tasklet_hi_schedule(&info->tty_tsklt);
112 return;
113 }
114 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700115}
116
117static void smd_tty_read(unsigned long param)
118{
119 unsigned char *ptr;
120 int avail;
121 struct smd_tty_info *info = (struct smd_tty_info *)param;
122 struct tty_struct *tty = info->tty;
123
124 if (!tty)
125 return;
126
127 for (;;) {
128 if (is_in_reset(info)) {
129 /* signal TTY clients using TTY_BREAK */
130 tty_insert_flip_char(tty, 0x00, TTY_BREAK);
131 tty_flip_buffer_push(tty);
132 break;
133 }
134
135 if (test_bit(TTY_THROTTLED, &tty->flags)) break;
136 avail = smd_read_avail(info->ch);
137 if (avail == 0)
138 break;
139
140 if (avail > MAX_TTY_BUF_SIZE)
141 avail = MAX_TTY_BUF_SIZE;
142
143 avail = tty_prepare_flip_string(tty, &ptr, avail);
144 if (avail <= 0) {
145 if (!timer_pending(&info->buf_req_timer)) {
146 init_timer(&info->buf_req_timer);
147 info->buf_req_timer.expires = jiffies +
148 ((30 * HZ)/1000);
149 info->buf_req_timer.function = buf_req_retry;
150 info->buf_req_timer.data = param;
151 add_timer(&info->buf_req_timer);
152 }
153 return;
154 }
155
156 if (smd_read(info->ch, ptr, avail) != avail) {
157 /* shouldn't be possible since we're in interrupt
158 ** context here and nobody else could 'steal' our
159 ** characters.
160 */
161 printk(KERN_ERR "OOPS - smd_tty_buffer mismatch?!");
162 }
163
164 wake_lock_timeout(&info->wake_lock, HZ / 2);
165 tty_flip_buffer_push(tty);
166 }
167
168 /* XXX only when writable and necessary */
169 tty_wakeup(tty);
170}
171
172static void smd_tty_notify(void *priv, unsigned event)
173{
174 struct smd_tty_info *info = priv;
175 unsigned long flags;
176
177 switch (event) {
178 case SMD_EVENT_DATA:
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700179 spin_lock_irqsave(&info->reset_lock, flags);
180 if (!info->is_open) {
181 spin_unlock_irqrestore(&info->reset_lock, flags);
182 break;
183 }
184 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 /* There may be clients (tty framework) that are blocked
186 * waiting for space to write data, so if a possible read
187 * interrupt came in wake anyone waiting and disable the
188 * interrupts
189 */
190 if (smd_write_avail(info->ch)) {
191 smd_disable_read_intr(info->ch);
192 if (info->tty)
193 wake_up_interruptible(&info->tty->write_wait);
194 }
195 tasklet_hi_schedule(&info->tty_tsklt);
196 break;
197
198 case SMD_EVENT_OPEN:
199 spin_lock_irqsave(&info->reset_lock, flags);
200 info->in_reset = 0;
201 info->in_reset_updated = 1;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600202 info->is_open = 1;
203 wake_up_interruptible(&info->ch_opened_wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 spin_unlock_irqrestore(&info->reset_lock, flags);
205 break;
206
207 case SMD_EVENT_CLOSE:
208 spin_lock_irqsave(&info->reset_lock, flags);
209 info->in_reset = 1;
210 info->in_reset_updated = 1;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600211 info->is_open = 0;
212 wake_up_interruptible(&info->ch_opened_wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 spin_unlock_irqrestore(&info->reset_lock, flags);
214 /* schedule task to send TTY_BREAK */
215 tasklet_hi_schedule(&info->tty_tsklt);
216
217 if (info->tty->index == LOOPBACK_IDX)
218 schedule_delayed_work(&loopback_work,
219 msecs_to_jiffies(1000));
220 break;
221 }
222}
223
224static uint32_t is_modem_smsm_inited(void)
225{
226 uint32_t modem_state;
227 uint32_t ready_state = (SMSM_INIT | SMSM_SMDINIT);
228
229 modem_state = smsm_get_state(SMSM_MODEM_STATE);
230 return (modem_state & ready_state) == ready_state;
231}
232
233static int smd_tty_open(struct tty_struct *tty, struct file *f)
234{
235 int res = 0;
Eric Holmberg513ad582011-12-14 16:27:13 -0700236 unsigned int n = tty->index;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700237 struct smd_tty_info *info;
Eric Holmberga53cf232012-02-28 13:41:44 -0700238 const char *peripheral = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239
240
Eric Holmberg513ad582011-12-14 16:27:13 -0700241 if (n >= MAX_SMD_TTYS || !smd_tty[n].smd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700242 return -ENODEV;
243
244 info = smd_tty + n;
245
246 mutex_lock(&smd_tty_lock);
247 tty->driver_data = info;
248
249 if (info->open_count++ == 0) {
Eric Holmberga53cf232012-02-28 13:41:44 -0700250 peripheral = smd_edge_to_subsystem(smd_tty[n].smd->edge);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251 if (peripheral) {
Eric Holmberg513ad582011-12-14 16:27:13 -0700252 info->pil = pil_get(peripheral);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 if (IS_ERR(info->pil)) {
254 res = PTR_ERR(info->pil);
255 goto out;
256 }
257
258 /* Wait for the modem SMSM to be inited for the SMD
259 * Loopback channel to be allocated at the modem. Since
260 * the wait need to be done atmost once, using msleep
261 * doesn't degrade the performance.
262 */
Eric Holmberg513ad582011-12-14 16:27:13 -0700263 if (n == LOOPBACK_IDX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264 if (!is_modem_smsm_inited())
265 msleep(5000);
266 smsm_change_state(SMSM_APPS_STATE,
267 0, SMSM_SMD_LOOPBACK);
268 msleep(100);
269 }
270
271
272 /*
273 * Wait for a channel to be allocated so we know
274 * the modem is ready enough.
275 */
276 if (smd_tty_modem_wait) {
277 res = wait_for_completion_interruptible_timeout(
278 &info->ch_allocated,
279 msecs_to_jiffies(smd_tty_modem_wait *
280 1000));
281
282 if (res == 0) {
283 pr_err("Timed out waiting for SMD"
284 " channel\n");
285 res = -ETIMEDOUT;
286 goto release_pil;
287 } else if (res < 0) {
288 pr_err("Error waiting for SMD channel:"
289 " %d\n",
290 res);
291 goto release_pil;
292 }
293
294 res = 0;
295 }
296 }
297
298
299 info->tty = tty;
300 tasklet_init(&info->tty_tsklt, smd_tty_read,
301 (unsigned long)info);
302 wake_lock_init(&info->wake_lock, WAKE_LOCK_SUSPEND,
Eric Holmberg513ad582011-12-14 16:27:13 -0700303 smd_tty[n].smd->port_name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700304 if (!info->ch) {
Eric Holmberg513ad582011-12-14 16:27:13 -0700305 res = smd_named_open_on_edge(smd_tty[n].smd->port_name,
306 smd_tty[n].smd->edge,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700307 &info->ch, info,
308 smd_tty_notify);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600309 if (res < 0) {
310 pr_err("%s: %s open failed %d\n", __func__,
Eric Holmberg513ad582011-12-14 16:27:13 -0700311 smd_tty[n].smd->port_name, res);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600312 goto release_pil;
313 }
314
315 res = wait_event_interruptible_timeout(
316 info->ch_opened_wait_queue,
317 info->is_open, (2 * HZ));
318 if (res == 0)
319 res = -ETIMEDOUT;
320 if (res < 0) {
321 pr_err("%s: wait for %s smd_open failed %d\n",
Eric Holmberg513ad582011-12-14 16:27:13 -0700322 __func__, smd_tty[n].smd->port_name,
323 res);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600324 goto release_pil;
325 }
326 res = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700327 }
328 }
329
330release_pil:
331 if (res < 0)
332 pil_put(info->pil);
333 else
334 smd_disable_read_intr(info->ch);
335out:
336 mutex_unlock(&smd_tty_lock);
337
338 return res;
339}
340
341static void smd_tty_close(struct tty_struct *tty, struct file *f)
342{
343 struct smd_tty_info *info = tty->driver_data;
Karthikeyan Ramasubramaniand563de52011-11-22 08:38:17 -0700344 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700345
346 if (info == 0)
347 return;
348
349 mutex_lock(&smd_tty_lock);
350 if (--info->open_count == 0) {
Karthikeyan Ramasubramaniand563de52011-11-22 08:38:17 -0700351 spin_lock_irqsave(&info->reset_lock, flags);
352 info->is_open = 0;
353 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700354 if (info->tty) {
355 tasklet_kill(&info->tty_tsklt);
356 wake_lock_destroy(&info->wake_lock);
357 info->tty = 0;
358 }
359 tty->driver_data = 0;
360 del_timer(&info->buf_req_timer);
361 if (info->ch) {
362 smd_close(info->ch);
363 info->ch = 0;
364 pil_put(info->pil);
365 }
366 }
367 mutex_unlock(&smd_tty_lock);
368}
369
370static int smd_tty_write(struct tty_struct *tty, const unsigned char *buf, int len)
371{
372 struct smd_tty_info *info = tty->driver_data;
373 int avail;
374
375 /* if we're writing to a packet channel we will
376 ** never be able to write more data than there
377 ** is currently space for
378 */
379 if (is_in_reset(info))
380 return -ENETRESET;
381
382 avail = smd_write_avail(info->ch);
383 /* if no space, we'll have to setup a notification later to wake up the
384 * tty framework when space becomes avaliable
385 */
386 if (!avail) {
387 smd_enable_read_intr(info->ch);
388 return 0;
389 }
390 if (len > avail)
391 len = avail;
392
393 return smd_write(info->ch, buf, len);
394}
395
396static int smd_tty_write_room(struct tty_struct *tty)
397{
398 struct smd_tty_info *info = tty->driver_data;
399 return smd_write_avail(info->ch);
400}
401
402static int smd_tty_chars_in_buffer(struct tty_struct *tty)
403{
404 struct smd_tty_info *info = tty->driver_data;
405 return smd_read_avail(info->ch);
406}
407
408static void smd_tty_unthrottle(struct tty_struct *tty)
409{
410 struct smd_tty_info *info = tty->driver_data;
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700411 unsigned long flags;
412
413 spin_lock_irqsave(&info->reset_lock, flags);
414 if (info->is_open) {
415 spin_unlock_irqrestore(&info->reset_lock, flags);
416 tasklet_hi_schedule(&info->tty_tsklt);
417 return;
418 }
419 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700420}
421
422/*
423 * Returns the current TIOCM status bits including:
424 * SMD Signals (DTR/DSR, CTS/RTS, CD, RI)
425 * TIOCM_OUT1 - reset state (1=in reset)
426 * TIOCM_OUT2 - reset state updated (1=updated)
427 */
428static int smd_tty_tiocmget(struct tty_struct *tty)
429{
430 struct smd_tty_info *info = tty->driver_data;
431 unsigned long flags;
432 int tiocm;
433
434 tiocm = smd_tiocmget(info->ch);
435
436 spin_lock_irqsave(&info->reset_lock, flags);
437 tiocm |= (info->in_reset ? TIOCM_OUT1 : 0);
438 if (info->in_reset_updated) {
439 tiocm |= TIOCM_OUT2;
440 info->in_reset_updated = 0;
441 }
442 spin_unlock_irqrestore(&info->reset_lock, flags);
443
444 return tiocm;
445}
446
447static int smd_tty_tiocmset(struct tty_struct *tty,
448 unsigned int set, unsigned int clear)
449{
450 struct smd_tty_info *info = tty->driver_data;
451
452 if (info->in_reset)
453 return -ENETRESET;
454
455 return smd_tiocmset(info->ch, set, clear);
456}
457
458static void loopback_probe_worker(struct work_struct *work)
459{
460 /* wait for modem to restart before requesting loopback server */
461 if (!is_modem_smsm_inited())
462 schedule_delayed_work(&loopback_work, msecs_to_jiffies(1000));
463 else
464 smsm_change_state(SMSM_APPS_STATE,
465 0, SMSM_SMD_LOOPBACK);
466}
467
468static struct tty_operations smd_tty_ops = {
469 .open = smd_tty_open,
470 .close = smd_tty_close,
471 .write = smd_tty_write,
472 .write_room = smd_tty_write_room,
473 .chars_in_buffer = smd_tty_chars_in_buffer,
474 .unthrottle = smd_tty_unthrottle,
475 .tiocmget = smd_tty_tiocmget,
476 .tiocmset = smd_tty_tiocmset,
477};
478
479static int smd_tty_dummy_probe(struct platform_device *pdev)
480{
Eric Holmberg513ad582011-12-14 16:27:13 -0700481 int n;
482 int idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483
Eric Holmberg513ad582011-12-14 16:27:13 -0700484 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
485 idx = smd_configs[n].tty_dev_index;
486
487 if (!smd_configs[n].dev_name)
488 continue;
489
490 if (!strncmp(pdev->name, smd_configs[n].dev_name,
491 SMD_MAX_CH_NAME_LEN)) {
492 complete_all(&smd_tty[idx].ch_allocated);
493 return 0;
494 }
495 }
496 pr_err("%s: unknown device '%s'\n", __func__, pdev->name);
497
498 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700499}
500
501static struct tty_driver *smd_tty_driver;
502
503static int __init smd_tty_init(void)
504{
505 int ret;
Eric Holmberg513ad582011-12-14 16:27:13 -0700506 int n;
507 int idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508
509 smd_tty_driver = alloc_tty_driver(MAX_SMD_TTYS);
510 if (smd_tty_driver == 0)
511 return -ENOMEM;
512
513 smd_tty_driver->owner = THIS_MODULE;
514 smd_tty_driver->driver_name = "smd_tty_driver";
515 smd_tty_driver->name = "smd";
516 smd_tty_driver->major = 0;
517 smd_tty_driver->minor_start = 0;
518 smd_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
519 smd_tty_driver->subtype = SERIAL_TYPE_NORMAL;
520 smd_tty_driver->init_termios = tty_std_termios;
521 smd_tty_driver->init_termios.c_iflag = 0;
522 smd_tty_driver->init_termios.c_oflag = 0;
523 smd_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
524 smd_tty_driver->init_termios.c_lflag = 0;
525 smd_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS |
526 TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
527 tty_set_operations(smd_tty_driver, &smd_tty_ops);
528
529 ret = tty_register_driver(smd_tty_driver);
Eric Holmberg513ad582011-12-14 16:27:13 -0700530 if (ret) {
531 put_tty_driver(smd_tty_driver);
532 pr_err("%s: driver registration failed %d\n", __func__, ret);
533 return ret;
Jeff Hugo4c0ba6c2011-07-15 11:47:13 -0600534 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700535
Eric Holmberg513ad582011-12-14 16:27:13 -0700536 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
537 idx = smd_configs[n].tty_dev_index;
538
539 if (smd_configs[n].dev_name == NULL)
540 smd_configs[n].dev_name = smd_configs[n].port_name;
541
542 if (idx == DS_IDX) {
543 /*
544 * DS port uses the kernel API starting with
545 * 8660 Fusion. Only register the userspace
546 * platform device for older targets.
547 */
548 int legacy_ds = 0;
549
550 legacy_ds |= cpu_is_msm7x01() || cpu_is_msm7x25();
551 legacy_ds |= cpu_is_msm7x27() || cpu_is_msm7x30();
552 legacy_ds |= cpu_is_qsd8x50() || cpu_is_msm8x55();
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +0530553 /*
554 * use legacy mode for 8660 Standalone (subtype 0)
555 */
Eric Holmberg513ad582011-12-14 16:27:13 -0700556 legacy_ds |= cpu_is_msm8x60() &&
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +0530557 (socinfo_get_platform_subtype() == 0x0);
Eric Holmberg513ad582011-12-14 16:27:13 -0700558
559 if (!legacy_ds)
560 continue;
561 }
562
563 tty_register_device(smd_tty_driver, idx, 0);
564 init_completion(&smd_tty[idx].ch_allocated);
565
566 /* register platform device */
567 smd_tty[idx].driver.probe = smd_tty_dummy_probe;
568 smd_tty[idx].driver.driver.name = smd_configs[n].dev_name;
569 smd_tty[idx].driver.driver.owner = THIS_MODULE;
570 spin_lock_init(&smd_tty[idx].reset_lock);
571 smd_tty[idx].is_open = 0;
572 init_waitqueue_head(&smd_tty[idx].ch_opened_wait_queue);
573 ret = platform_driver_register(&smd_tty[idx].driver);
574
575 if (ret) {
576 pr_err("%s: init failed %d (%d)\n", __func__, idx, ret);
577 smd_tty[idx].driver.probe = NULL;
578 goto out;
579 }
580 smd_tty[idx].smd = &smd_configs[n];
581 }
582 INIT_DELAYED_WORK(&loopback_work, loopback_probe_worker);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 return 0;
584
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700585out:
Eric Holmberg513ad582011-12-14 16:27:13 -0700586 /* unregister platform devices */
587 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
588 idx = smd_configs[n].tty_dev_index;
589
590 if (smd_tty[idx].driver.probe) {
591 platform_driver_unregister(&smd_tty[idx].driver);
592 tty_unregister_device(smd_tty_driver, idx);
593 }
594 }
595
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700596 tty_unregister_driver(smd_tty_driver);
597 put_tty_driver(smd_tty_driver);
598 return ret;
599}
600
601module_init(smd_tty_init);