blob: 68e0f41a35aafd6536ef9b91dbae5cd8f189ddd4 [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},
Jeff Hugodfb9c9a2012-04-10 14:22:47 -060086 {5, "APPS_RIVA_ANT_CMD", NULL, SMD_APPS_WCNSS},
87 {6, "APPS_RIVA_ANT_DATA", NULL, SMD_APPS_WCNSS},
Eric Holmberg513ad582011-12-14 16:27:13 -070088 {7, "DATA1", NULL, SMD_APPS_MODEM},
Eric Holmbergbe1dc5f2011-12-14 21:35:12 -070089 {11, "DATA11", NULL, SMD_APPS_MODEM},
Eric Holmberg513ad582011-12-14 16:27:13 -070090 {21, "DATA21", NULL, SMD_APPS_MODEM},
91 {27, "GPSNMEA", NULL, SMD_APPS_MODEM},
92 {36, "LOOPBACK", "LOOPBACK_TTY", SMD_APPS_MODEM},
93};
94#define DS_IDX 0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095#define LOOPBACK_IDX 36
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096
97static struct delayed_work loopback_work;
98static struct smd_tty_info smd_tty[MAX_SMD_TTYS];
99
100static int is_in_reset(struct smd_tty_info *info)
101{
102 return info->in_reset;
103}
104
105static void buf_req_retry(unsigned long param)
106{
107 struct smd_tty_info *info = (struct smd_tty_info *)param;
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700108 unsigned long flags;
109
110 spin_lock_irqsave(&info->reset_lock, flags);
111 if (info->is_open) {
112 spin_unlock_irqrestore(&info->reset_lock, flags);
113 tasklet_hi_schedule(&info->tty_tsklt);
114 return;
115 }
116 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117}
118
119static void smd_tty_read(unsigned long param)
120{
121 unsigned char *ptr;
122 int avail;
123 struct smd_tty_info *info = (struct smd_tty_info *)param;
124 struct tty_struct *tty = info->tty;
125
126 if (!tty)
127 return;
128
129 for (;;) {
130 if (is_in_reset(info)) {
131 /* signal TTY clients using TTY_BREAK */
132 tty_insert_flip_char(tty, 0x00, TTY_BREAK);
133 tty_flip_buffer_push(tty);
134 break;
135 }
136
137 if (test_bit(TTY_THROTTLED, &tty->flags)) break;
138 avail = smd_read_avail(info->ch);
139 if (avail == 0)
140 break;
141
142 if (avail > MAX_TTY_BUF_SIZE)
143 avail = MAX_TTY_BUF_SIZE;
144
145 avail = tty_prepare_flip_string(tty, &ptr, avail);
146 if (avail <= 0) {
147 if (!timer_pending(&info->buf_req_timer)) {
148 init_timer(&info->buf_req_timer);
149 info->buf_req_timer.expires = jiffies +
150 ((30 * HZ)/1000);
151 info->buf_req_timer.function = buf_req_retry;
152 info->buf_req_timer.data = param;
153 add_timer(&info->buf_req_timer);
154 }
155 return;
156 }
157
158 if (smd_read(info->ch, ptr, avail) != avail) {
159 /* shouldn't be possible since we're in interrupt
160 ** context here and nobody else could 'steal' our
161 ** characters.
162 */
163 printk(KERN_ERR "OOPS - smd_tty_buffer mismatch?!");
164 }
165
166 wake_lock_timeout(&info->wake_lock, HZ / 2);
167 tty_flip_buffer_push(tty);
168 }
169
170 /* XXX only when writable and necessary */
171 tty_wakeup(tty);
172}
173
174static void smd_tty_notify(void *priv, unsigned event)
175{
176 struct smd_tty_info *info = priv;
177 unsigned long flags;
178
179 switch (event) {
180 case SMD_EVENT_DATA:
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700181 spin_lock_irqsave(&info->reset_lock, flags);
182 if (!info->is_open) {
183 spin_unlock_irqrestore(&info->reset_lock, flags);
184 break;
185 }
186 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 /* There may be clients (tty framework) that are blocked
188 * waiting for space to write data, so if a possible read
189 * interrupt came in wake anyone waiting and disable the
190 * interrupts
191 */
192 if (smd_write_avail(info->ch)) {
193 smd_disable_read_intr(info->ch);
194 if (info->tty)
195 wake_up_interruptible(&info->tty->write_wait);
196 }
197 tasklet_hi_schedule(&info->tty_tsklt);
198 break;
199
200 case SMD_EVENT_OPEN:
201 spin_lock_irqsave(&info->reset_lock, flags);
202 info->in_reset = 0;
203 info->in_reset_updated = 1;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600204 info->is_open = 1;
205 wake_up_interruptible(&info->ch_opened_wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206 spin_unlock_irqrestore(&info->reset_lock, flags);
207 break;
208
209 case SMD_EVENT_CLOSE:
210 spin_lock_irqsave(&info->reset_lock, flags);
211 info->in_reset = 1;
212 info->in_reset_updated = 1;
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600213 info->is_open = 0;
214 wake_up_interruptible(&info->ch_opened_wait_queue);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 spin_unlock_irqrestore(&info->reset_lock, flags);
216 /* schedule task to send TTY_BREAK */
217 tasklet_hi_schedule(&info->tty_tsklt);
218
219 if (info->tty->index == LOOPBACK_IDX)
220 schedule_delayed_work(&loopback_work,
221 msecs_to_jiffies(1000));
222 break;
223 }
224}
225
226static uint32_t is_modem_smsm_inited(void)
227{
228 uint32_t modem_state;
229 uint32_t ready_state = (SMSM_INIT | SMSM_SMDINIT);
230
231 modem_state = smsm_get_state(SMSM_MODEM_STATE);
232 return (modem_state & ready_state) == ready_state;
233}
234
235static int smd_tty_open(struct tty_struct *tty, struct file *f)
236{
237 int res = 0;
Eric Holmberg513ad582011-12-14 16:27:13 -0700238 unsigned int n = tty->index;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239 struct smd_tty_info *info;
Eric Holmberga53cf232012-02-28 13:41:44 -0700240 const char *peripheral = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241
242
Eric Holmberg513ad582011-12-14 16:27:13 -0700243 if (n >= MAX_SMD_TTYS || !smd_tty[n].smd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700244 return -ENODEV;
245
246 info = smd_tty + n;
247
248 mutex_lock(&smd_tty_lock);
249 tty->driver_data = info;
250
251 if (info->open_count++ == 0) {
Eric Holmberga53cf232012-02-28 13:41:44 -0700252 peripheral = smd_edge_to_subsystem(smd_tty[n].smd->edge);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 if (peripheral) {
Eric Holmberg513ad582011-12-14 16:27:13 -0700254 info->pil = pil_get(peripheral);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 if (IS_ERR(info->pil)) {
256 res = PTR_ERR(info->pil);
257 goto out;
258 }
259
260 /* Wait for the modem SMSM to be inited for the SMD
261 * Loopback channel to be allocated at the modem. Since
262 * the wait need to be done atmost once, using msleep
263 * doesn't degrade the performance.
264 */
Eric Holmberg513ad582011-12-14 16:27:13 -0700265 if (n == LOOPBACK_IDX) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266 if (!is_modem_smsm_inited())
267 msleep(5000);
268 smsm_change_state(SMSM_APPS_STATE,
269 0, SMSM_SMD_LOOPBACK);
270 msleep(100);
271 }
272
273
274 /*
275 * Wait for a channel to be allocated so we know
276 * the modem is ready enough.
277 */
278 if (smd_tty_modem_wait) {
279 res = wait_for_completion_interruptible_timeout(
280 &info->ch_allocated,
281 msecs_to_jiffies(smd_tty_modem_wait *
282 1000));
283
284 if (res == 0) {
285 pr_err("Timed out waiting for SMD"
286 " channel\n");
287 res = -ETIMEDOUT;
288 goto release_pil;
289 } else if (res < 0) {
290 pr_err("Error waiting for SMD channel:"
291 " %d\n",
292 res);
293 goto release_pil;
294 }
295
296 res = 0;
297 }
298 }
299
300
301 info->tty = tty;
302 tasklet_init(&info->tty_tsklt, smd_tty_read,
303 (unsigned long)info);
304 wake_lock_init(&info->wake_lock, WAKE_LOCK_SUSPEND,
Eric Holmberg513ad582011-12-14 16:27:13 -0700305 smd_tty[n].smd->port_name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306 if (!info->ch) {
Eric Holmberg513ad582011-12-14 16:27:13 -0700307 res = smd_named_open_on_edge(smd_tty[n].smd->port_name,
308 smd_tty[n].smd->edge,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700309 &info->ch, info,
310 smd_tty_notify);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600311 if (res < 0) {
312 pr_err("%s: %s open failed %d\n", __func__,
Eric Holmberg513ad582011-12-14 16:27:13 -0700313 smd_tty[n].smd->port_name, res);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600314 goto release_pil;
315 }
316
317 res = wait_event_interruptible_timeout(
318 info->ch_opened_wait_queue,
319 info->is_open, (2 * HZ));
320 if (res == 0)
321 res = -ETIMEDOUT;
322 if (res < 0) {
323 pr_err("%s: wait for %s smd_open failed %d\n",
Eric Holmberg513ad582011-12-14 16:27:13 -0700324 __func__, smd_tty[n].smd->port_name,
325 res);
Karthikeyan Ramasubramaniand5e63af2011-07-29 11:30:59 -0600326 goto release_pil;
327 }
328 res = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700329 }
330 }
331
332release_pil:
333 if (res < 0)
334 pil_put(info->pil);
335 else
336 smd_disable_read_intr(info->ch);
337out:
338 mutex_unlock(&smd_tty_lock);
339
340 return res;
341}
342
343static void smd_tty_close(struct tty_struct *tty, struct file *f)
344{
345 struct smd_tty_info *info = tty->driver_data;
Karthikeyan Ramasubramaniand563de52011-11-22 08:38:17 -0700346 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700347
348 if (info == 0)
349 return;
350
351 mutex_lock(&smd_tty_lock);
352 if (--info->open_count == 0) {
Karthikeyan Ramasubramaniand563de52011-11-22 08:38:17 -0700353 spin_lock_irqsave(&info->reset_lock, flags);
354 info->is_open = 0;
355 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700356 if (info->tty) {
357 tasklet_kill(&info->tty_tsklt);
358 wake_lock_destroy(&info->wake_lock);
359 info->tty = 0;
360 }
361 tty->driver_data = 0;
362 del_timer(&info->buf_req_timer);
363 if (info->ch) {
364 smd_close(info->ch);
365 info->ch = 0;
366 pil_put(info->pil);
367 }
368 }
369 mutex_unlock(&smd_tty_lock);
370}
371
372static int smd_tty_write(struct tty_struct *tty, const unsigned char *buf, int len)
373{
374 struct smd_tty_info *info = tty->driver_data;
375 int avail;
376
377 /* if we're writing to a packet channel we will
378 ** never be able to write more data than there
379 ** is currently space for
380 */
381 if (is_in_reset(info))
382 return -ENETRESET;
383
384 avail = smd_write_avail(info->ch);
385 /* if no space, we'll have to setup a notification later to wake up the
386 * tty framework when space becomes avaliable
387 */
388 if (!avail) {
389 smd_enable_read_intr(info->ch);
390 return 0;
391 }
392 if (len > avail)
393 len = avail;
394
395 return smd_write(info->ch, buf, len);
396}
397
398static int smd_tty_write_room(struct tty_struct *tty)
399{
400 struct smd_tty_info *info = tty->driver_data;
401 return smd_write_avail(info->ch);
402}
403
404static int smd_tty_chars_in_buffer(struct tty_struct *tty)
405{
406 struct smd_tty_info *info = tty->driver_data;
407 return smd_read_avail(info->ch);
408}
409
410static void smd_tty_unthrottle(struct tty_struct *tty)
411{
412 struct smd_tty_info *info = tty->driver_data;
Karthikeyan Ramasubramanianf8ad4132011-11-22 09:11:18 -0700413 unsigned long flags;
414
415 spin_lock_irqsave(&info->reset_lock, flags);
416 if (info->is_open) {
417 spin_unlock_irqrestore(&info->reset_lock, flags);
418 tasklet_hi_schedule(&info->tty_tsklt);
419 return;
420 }
421 spin_unlock_irqrestore(&info->reset_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700422}
423
424/*
425 * Returns the current TIOCM status bits including:
426 * SMD Signals (DTR/DSR, CTS/RTS, CD, RI)
427 * TIOCM_OUT1 - reset state (1=in reset)
428 * TIOCM_OUT2 - reset state updated (1=updated)
429 */
430static int smd_tty_tiocmget(struct tty_struct *tty)
431{
432 struct smd_tty_info *info = tty->driver_data;
433 unsigned long flags;
434 int tiocm;
435
436 tiocm = smd_tiocmget(info->ch);
437
438 spin_lock_irqsave(&info->reset_lock, flags);
439 tiocm |= (info->in_reset ? TIOCM_OUT1 : 0);
440 if (info->in_reset_updated) {
441 tiocm |= TIOCM_OUT2;
442 info->in_reset_updated = 0;
443 }
444 spin_unlock_irqrestore(&info->reset_lock, flags);
445
446 return tiocm;
447}
448
449static int smd_tty_tiocmset(struct tty_struct *tty,
450 unsigned int set, unsigned int clear)
451{
452 struct smd_tty_info *info = tty->driver_data;
453
454 if (info->in_reset)
455 return -ENETRESET;
456
457 return smd_tiocmset(info->ch, set, clear);
458}
459
460static void loopback_probe_worker(struct work_struct *work)
461{
462 /* wait for modem to restart before requesting loopback server */
463 if (!is_modem_smsm_inited())
464 schedule_delayed_work(&loopback_work, msecs_to_jiffies(1000));
465 else
466 smsm_change_state(SMSM_APPS_STATE,
467 0, SMSM_SMD_LOOPBACK);
468}
469
470static struct tty_operations smd_tty_ops = {
471 .open = smd_tty_open,
472 .close = smd_tty_close,
473 .write = smd_tty_write,
474 .write_room = smd_tty_write_room,
475 .chars_in_buffer = smd_tty_chars_in_buffer,
476 .unthrottle = smd_tty_unthrottle,
477 .tiocmget = smd_tty_tiocmget,
478 .tiocmset = smd_tty_tiocmset,
479};
480
481static int smd_tty_dummy_probe(struct platform_device *pdev)
482{
Eric Holmberg513ad582011-12-14 16:27:13 -0700483 int n;
484 int idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700485
Eric Holmberg513ad582011-12-14 16:27:13 -0700486 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
487 idx = smd_configs[n].tty_dev_index;
488
489 if (!smd_configs[n].dev_name)
490 continue;
491
Eric Holmbergdaf36d12012-02-08 17:05:21 -0700492 if (pdev->id == smd_configs[n].edge &&
493 !strncmp(pdev->name, smd_configs[n].dev_name,
Eric Holmberg513ad582011-12-14 16:27:13 -0700494 SMD_MAX_CH_NAME_LEN)) {
495 complete_all(&smd_tty[idx].ch_allocated);
496 return 0;
497 }
498 }
499 pr_err("%s: unknown device '%s'\n", __func__, pdev->name);
500
501 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700502}
503
504static struct tty_driver *smd_tty_driver;
505
506static int __init smd_tty_init(void)
507{
508 int ret;
Eric Holmberg513ad582011-12-14 16:27:13 -0700509 int n;
510 int idx;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700511
512 smd_tty_driver = alloc_tty_driver(MAX_SMD_TTYS);
513 if (smd_tty_driver == 0)
514 return -ENOMEM;
515
516 smd_tty_driver->owner = THIS_MODULE;
517 smd_tty_driver->driver_name = "smd_tty_driver";
518 smd_tty_driver->name = "smd";
519 smd_tty_driver->major = 0;
520 smd_tty_driver->minor_start = 0;
521 smd_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
522 smd_tty_driver->subtype = SERIAL_TYPE_NORMAL;
523 smd_tty_driver->init_termios = tty_std_termios;
524 smd_tty_driver->init_termios.c_iflag = 0;
525 smd_tty_driver->init_termios.c_oflag = 0;
526 smd_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
527 smd_tty_driver->init_termios.c_lflag = 0;
528 smd_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS |
529 TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
530 tty_set_operations(smd_tty_driver, &smd_tty_ops);
531
532 ret = tty_register_driver(smd_tty_driver);
Eric Holmberg513ad582011-12-14 16:27:13 -0700533 if (ret) {
534 put_tty_driver(smd_tty_driver);
535 pr_err("%s: driver registration failed %d\n", __func__, ret);
536 return ret;
Jeff Hugo4c0ba6c2011-07-15 11:47:13 -0600537 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700538
Eric Holmberg513ad582011-12-14 16:27:13 -0700539 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
540 idx = smd_configs[n].tty_dev_index;
541
542 if (smd_configs[n].dev_name == NULL)
543 smd_configs[n].dev_name = smd_configs[n].port_name;
544
545 if (idx == DS_IDX) {
546 /*
547 * DS port uses the kernel API starting with
548 * 8660 Fusion. Only register the userspace
549 * platform device for older targets.
550 */
551 int legacy_ds = 0;
552
553 legacy_ds |= cpu_is_msm7x01() || cpu_is_msm7x25();
554 legacy_ds |= cpu_is_msm7x27() || cpu_is_msm7x30();
555 legacy_ds |= cpu_is_qsd8x50() || cpu_is_msm8x55();
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +0530556 /*
557 * use legacy mode for 8660 Standalone (subtype 0)
558 */
Eric Holmberg513ad582011-12-14 16:27:13 -0700559 legacy_ds |= cpu_is_msm8x60() &&
Angshuman Sarkar4b931ed2012-01-05 13:38:36 +0530560 (socinfo_get_platform_subtype() == 0x0);
Eric Holmberg513ad582011-12-14 16:27:13 -0700561
562 if (!legacy_ds)
563 continue;
564 }
565
566 tty_register_device(smd_tty_driver, idx, 0);
567 init_completion(&smd_tty[idx].ch_allocated);
568
569 /* register platform device */
570 smd_tty[idx].driver.probe = smd_tty_dummy_probe;
571 smd_tty[idx].driver.driver.name = smd_configs[n].dev_name;
572 smd_tty[idx].driver.driver.owner = THIS_MODULE;
573 spin_lock_init(&smd_tty[idx].reset_lock);
574 smd_tty[idx].is_open = 0;
575 init_waitqueue_head(&smd_tty[idx].ch_opened_wait_queue);
576 ret = platform_driver_register(&smd_tty[idx].driver);
577
578 if (ret) {
579 pr_err("%s: init failed %d (%d)\n", __func__, idx, ret);
580 smd_tty[idx].driver.probe = NULL;
581 goto out;
582 }
583 smd_tty[idx].smd = &smd_configs[n];
584 }
585 INIT_DELAYED_WORK(&loopback_work, loopback_probe_worker);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586 return 0;
587
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588out:
Eric Holmberg513ad582011-12-14 16:27:13 -0700589 /* unregister platform devices */
590 for (n = 0; n < ARRAY_SIZE(smd_configs); ++n) {
591 idx = smd_configs[n].tty_dev_index;
592
593 if (smd_tty[idx].driver.probe) {
594 platform_driver_unregister(&smd_tty[idx].driver);
595 tty_unregister_device(smd_tty_driver, idx);
596 }
597 }
598
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599 tty_unregister_driver(smd_tty_driver);
600 put_tty_driver(smd_tty_driver);
601 return ret;
602}
603
604module_init(smd_tty_init);