Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/smd_tty.c |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
| 4 | * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 5 | * 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 Hugo | 4c0ba6c | 2011-07-15 11:47:13 -0600 | [diff] [blame] | 34 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | |
| 36 | #include "smd_private.h" |
| 37 | |
| 38 | #define MAX_SMD_TTYS 37 |
| 39 | #define MAX_TTY_BUF_SIZE 2048 |
| 40 | |
| 41 | static DEFINE_MUTEX(smd_tty_lock); |
| 42 | |
| 43 | static uint smd_tty_modem_wait; |
| 44 | module_param_named(modem_wait, smd_tty_modem_wait, |
| 45 | uint, S_IRUGO | S_IWUSR | S_IWGRP); |
| 46 | |
| 47 | struct 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 Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 59 | int is_open; |
| 60 | wait_queue_head_t ch_opened_wait_queue; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 61 | spinlock_t reset_lock; |
| 62 | }; |
| 63 | |
| 64 | #define LOOPBACK_IDX 36 |
| 65 | static char *smd_ch_name[] = { |
| 66 | [0] = "DS", |
| 67 | [1] = "APPS_FM", |
| 68 | [2] = "APPS_RIVA_BT_ACL", |
| 69 | [3] = "APPS_RIVA_BT_CMD", |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 70 | [4] = "MBALBRIDGE", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | [7] = "DATA1", |
| 72 | [21] = "DATA21", |
| 73 | [27] = "GPSNMEA", |
| 74 | [36] = "LOOPBACK", |
| 75 | }; |
| 76 | |
| 77 | static uint32_t smd_ch_edge[] = { |
| 78 | [0] = SMD_APPS_MODEM, |
| 79 | [1] = SMD_APPS_WCNSS, |
| 80 | [2] = SMD_APPS_WCNSS, |
| 81 | [3] = SMD_APPS_WCNSS, |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 82 | [4] = SMD_APPS_MODEM, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 83 | [7] = SMD_APPS_MODEM, |
| 84 | [21] = SMD_APPS_MODEM, |
| 85 | [27] = SMD_APPS_MODEM, |
| 86 | [36] = SMD_APPS_MODEM, |
| 87 | }; |
| 88 | |
| 89 | |
| 90 | static struct delayed_work loopback_work; |
| 91 | static struct smd_tty_info smd_tty[MAX_SMD_TTYS]; |
| 92 | |
| 93 | static int is_in_reset(struct smd_tty_info *info) |
| 94 | { |
| 95 | return info->in_reset; |
| 96 | } |
| 97 | |
| 98 | static void buf_req_retry(unsigned long param) |
| 99 | { |
| 100 | struct smd_tty_info *info = (struct smd_tty_info *)param; |
| 101 | tasklet_hi_schedule(&info->tty_tsklt); |
| 102 | } |
| 103 | |
| 104 | static void smd_tty_read(unsigned long param) |
| 105 | { |
| 106 | unsigned char *ptr; |
| 107 | int avail; |
| 108 | struct smd_tty_info *info = (struct smd_tty_info *)param; |
| 109 | struct tty_struct *tty = info->tty; |
| 110 | |
| 111 | if (!tty) |
| 112 | return; |
| 113 | |
| 114 | for (;;) { |
| 115 | if (is_in_reset(info)) { |
| 116 | /* signal TTY clients using TTY_BREAK */ |
| 117 | tty_insert_flip_char(tty, 0x00, TTY_BREAK); |
| 118 | tty_flip_buffer_push(tty); |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | if (test_bit(TTY_THROTTLED, &tty->flags)) break; |
| 123 | avail = smd_read_avail(info->ch); |
| 124 | if (avail == 0) |
| 125 | break; |
| 126 | |
| 127 | if (avail > MAX_TTY_BUF_SIZE) |
| 128 | avail = MAX_TTY_BUF_SIZE; |
| 129 | |
| 130 | avail = tty_prepare_flip_string(tty, &ptr, avail); |
| 131 | if (avail <= 0) { |
| 132 | if (!timer_pending(&info->buf_req_timer)) { |
| 133 | init_timer(&info->buf_req_timer); |
| 134 | info->buf_req_timer.expires = jiffies + |
| 135 | ((30 * HZ)/1000); |
| 136 | info->buf_req_timer.function = buf_req_retry; |
| 137 | info->buf_req_timer.data = param; |
| 138 | add_timer(&info->buf_req_timer); |
| 139 | } |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | if (smd_read(info->ch, ptr, avail) != avail) { |
| 144 | /* shouldn't be possible since we're in interrupt |
| 145 | ** context here and nobody else could 'steal' our |
| 146 | ** characters. |
| 147 | */ |
| 148 | printk(KERN_ERR "OOPS - smd_tty_buffer mismatch?!"); |
| 149 | } |
| 150 | |
| 151 | wake_lock_timeout(&info->wake_lock, HZ / 2); |
| 152 | tty_flip_buffer_push(tty); |
| 153 | } |
| 154 | |
| 155 | /* XXX only when writable and necessary */ |
| 156 | tty_wakeup(tty); |
| 157 | } |
| 158 | |
| 159 | static void smd_tty_notify(void *priv, unsigned event) |
| 160 | { |
| 161 | struct smd_tty_info *info = priv; |
| 162 | unsigned long flags; |
| 163 | |
| 164 | switch (event) { |
| 165 | case SMD_EVENT_DATA: |
| 166 | /* There may be clients (tty framework) that are blocked |
| 167 | * waiting for space to write data, so if a possible read |
| 168 | * interrupt came in wake anyone waiting and disable the |
| 169 | * interrupts |
| 170 | */ |
| 171 | if (smd_write_avail(info->ch)) { |
| 172 | smd_disable_read_intr(info->ch); |
| 173 | if (info->tty) |
| 174 | wake_up_interruptible(&info->tty->write_wait); |
| 175 | } |
| 176 | tasklet_hi_schedule(&info->tty_tsklt); |
| 177 | break; |
| 178 | |
| 179 | case SMD_EVENT_OPEN: |
| 180 | spin_lock_irqsave(&info->reset_lock, flags); |
| 181 | info->in_reset = 0; |
| 182 | info->in_reset_updated = 1; |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 183 | info->is_open = 1; |
| 184 | wake_up_interruptible(&info->ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | spin_unlock_irqrestore(&info->reset_lock, flags); |
| 186 | break; |
| 187 | |
| 188 | case SMD_EVENT_CLOSE: |
| 189 | spin_lock_irqsave(&info->reset_lock, flags); |
| 190 | info->in_reset = 1; |
| 191 | info->in_reset_updated = 1; |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 192 | info->is_open = 0; |
| 193 | wake_up_interruptible(&info->ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 194 | spin_unlock_irqrestore(&info->reset_lock, flags); |
| 195 | /* schedule task to send TTY_BREAK */ |
| 196 | tasklet_hi_schedule(&info->tty_tsklt); |
| 197 | |
| 198 | if (info->tty->index == LOOPBACK_IDX) |
| 199 | schedule_delayed_work(&loopback_work, |
| 200 | msecs_to_jiffies(1000)); |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | static uint32_t is_modem_smsm_inited(void) |
| 206 | { |
| 207 | uint32_t modem_state; |
| 208 | uint32_t ready_state = (SMSM_INIT | SMSM_SMDINIT); |
| 209 | |
| 210 | modem_state = smsm_get_state(SMSM_MODEM_STATE); |
| 211 | return (modem_state & ready_state) == ready_state; |
| 212 | } |
| 213 | |
| 214 | static int smd_tty_open(struct tty_struct *tty, struct file *f) |
| 215 | { |
| 216 | int res = 0; |
| 217 | int n = tty->index; |
| 218 | struct smd_tty_info *info; |
| 219 | char *peripheral = NULL; |
| 220 | |
| 221 | |
| 222 | if (!smd_ch_name[n]) |
| 223 | return -ENODEV; |
| 224 | |
| 225 | info = smd_tty + n; |
| 226 | |
| 227 | mutex_lock(&smd_tty_lock); |
| 228 | tty->driver_data = info; |
| 229 | |
| 230 | if (info->open_count++ == 0) { |
| 231 | if (smd_ch_edge[n] == SMD_APPS_MODEM) |
| 232 | peripheral = "modem"; |
| 233 | |
| 234 | if (peripheral) { |
| 235 | info->pil = pil_get("modem"); |
| 236 | if (IS_ERR(info->pil)) { |
| 237 | res = PTR_ERR(info->pil); |
| 238 | goto out; |
| 239 | } |
| 240 | |
| 241 | /* Wait for the modem SMSM to be inited for the SMD |
| 242 | * Loopback channel to be allocated at the modem. Since |
| 243 | * the wait need to be done atmost once, using msleep |
| 244 | * doesn't degrade the performance. |
| 245 | */ |
| 246 | if (n == 36) { |
| 247 | if (!is_modem_smsm_inited()) |
| 248 | msleep(5000); |
| 249 | smsm_change_state(SMSM_APPS_STATE, |
| 250 | 0, SMSM_SMD_LOOPBACK); |
| 251 | msleep(100); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | /* |
| 256 | * Wait for a channel to be allocated so we know |
| 257 | * the modem is ready enough. |
| 258 | */ |
| 259 | if (smd_tty_modem_wait) { |
| 260 | res = wait_for_completion_interruptible_timeout( |
| 261 | &info->ch_allocated, |
| 262 | msecs_to_jiffies(smd_tty_modem_wait * |
| 263 | 1000)); |
| 264 | |
| 265 | if (res == 0) { |
| 266 | pr_err("Timed out waiting for SMD" |
| 267 | " channel\n"); |
| 268 | res = -ETIMEDOUT; |
| 269 | goto release_pil; |
| 270 | } else if (res < 0) { |
| 271 | pr_err("Error waiting for SMD channel:" |
| 272 | " %d\n", |
| 273 | res); |
| 274 | goto release_pil; |
| 275 | } |
| 276 | |
| 277 | res = 0; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | |
| 282 | info->tty = tty; |
| 283 | tasklet_init(&info->tty_tsklt, smd_tty_read, |
| 284 | (unsigned long)info); |
| 285 | wake_lock_init(&info->wake_lock, WAKE_LOCK_SUSPEND, |
| 286 | smd_ch_name[n]); |
| 287 | if (!info->ch) { |
| 288 | res = smd_named_open_on_edge(smd_ch_name[n], |
| 289 | smd_ch_edge[n], |
| 290 | &info->ch, info, |
| 291 | smd_tty_notify); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 292 | if (res < 0) { |
| 293 | pr_err("%s: %s open failed %d\n", __func__, |
| 294 | smd_ch_name[n], res); |
| 295 | goto release_pil; |
| 296 | } |
| 297 | |
| 298 | res = wait_event_interruptible_timeout( |
| 299 | info->ch_opened_wait_queue, |
| 300 | info->is_open, (2 * HZ)); |
| 301 | if (res == 0) |
| 302 | res = -ETIMEDOUT; |
| 303 | if (res < 0) { |
| 304 | pr_err("%s: wait for %s smd_open failed %d\n", |
| 305 | __func__, smd_ch_name[n], res); |
| 306 | goto release_pil; |
| 307 | } |
| 308 | res = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | release_pil: |
| 313 | if (res < 0) |
| 314 | pil_put(info->pil); |
| 315 | else |
| 316 | smd_disable_read_intr(info->ch); |
| 317 | out: |
| 318 | mutex_unlock(&smd_tty_lock); |
| 319 | |
| 320 | return res; |
| 321 | } |
| 322 | |
| 323 | static void smd_tty_close(struct tty_struct *tty, struct file *f) |
| 324 | { |
| 325 | struct smd_tty_info *info = tty->driver_data; |
Karthikeyan Ramasubramanian | d563de5 | 2011-11-22 08:38:17 -0700 | [diff] [blame^] | 326 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 327 | |
| 328 | if (info == 0) |
| 329 | return; |
| 330 | |
| 331 | mutex_lock(&smd_tty_lock); |
| 332 | if (--info->open_count == 0) { |
Karthikeyan Ramasubramanian | d563de5 | 2011-11-22 08:38:17 -0700 | [diff] [blame^] | 333 | spin_lock_irqsave(&info->reset_lock, flags); |
| 334 | info->is_open = 0; |
| 335 | spin_unlock_irqrestore(&info->reset_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 336 | if (info->tty) { |
| 337 | tasklet_kill(&info->tty_tsklt); |
| 338 | wake_lock_destroy(&info->wake_lock); |
| 339 | info->tty = 0; |
| 340 | } |
| 341 | tty->driver_data = 0; |
| 342 | del_timer(&info->buf_req_timer); |
| 343 | if (info->ch) { |
| 344 | smd_close(info->ch); |
| 345 | info->ch = 0; |
| 346 | pil_put(info->pil); |
| 347 | } |
| 348 | } |
| 349 | mutex_unlock(&smd_tty_lock); |
| 350 | } |
| 351 | |
| 352 | static int smd_tty_write(struct tty_struct *tty, const unsigned char *buf, int len) |
| 353 | { |
| 354 | struct smd_tty_info *info = tty->driver_data; |
| 355 | int avail; |
| 356 | |
| 357 | /* if we're writing to a packet channel we will |
| 358 | ** never be able to write more data than there |
| 359 | ** is currently space for |
| 360 | */ |
| 361 | if (is_in_reset(info)) |
| 362 | return -ENETRESET; |
| 363 | |
| 364 | avail = smd_write_avail(info->ch); |
| 365 | /* if no space, we'll have to setup a notification later to wake up the |
| 366 | * tty framework when space becomes avaliable |
| 367 | */ |
| 368 | if (!avail) { |
| 369 | smd_enable_read_intr(info->ch); |
| 370 | return 0; |
| 371 | } |
| 372 | if (len > avail) |
| 373 | len = avail; |
| 374 | |
| 375 | return smd_write(info->ch, buf, len); |
| 376 | } |
| 377 | |
| 378 | static int smd_tty_write_room(struct tty_struct *tty) |
| 379 | { |
| 380 | struct smd_tty_info *info = tty->driver_data; |
| 381 | return smd_write_avail(info->ch); |
| 382 | } |
| 383 | |
| 384 | static int smd_tty_chars_in_buffer(struct tty_struct *tty) |
| 385 | { |
| 386 | struct smd_tty_info *info = tty->driver_data; |
| 387 | return smd_read_avail(info->ch); |
| 388 | } |
| 389 | |
| 390 | static void smd_tty_unthrottle(struct tty_struct *tty) |
| 391 | { |
| 392 | struct smd_tty_info *info = tty->driver_data; |
| 393 | tasklet_hi_schedule(&info->tty_tsklt); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * Returns the current TIOCM status bits including: |
| 399 | * SMD Signals (DTR/DSR, CTS/RTS, CD, RI) |
| 400 | * TIOCM_OUT1 - reset state (1=in reset) |
| 401 | * TIOCM_OUT2 - reset state updated (1=updated) |
| 402 | */ |
| 403 | static int smd_tty_tiocmget(struct tty_struct *tty) |
| 404 | { |
| 405 | struct smd_tty_info *info = tty->driver_data; |
| 406 | unsigned long flags; |
| 407 | int tiocm; |
| 408 | |
| 409 | tiocm = smd_tiocmget(info->ch); |
| 410 | |
| 411 | spin_lock_irqsave(&info->reset_lock, flags); |
| 412 | tiocm |= (info->in_reset ? TIOCM_OUT1 : 0); |
| 413 | if (info->in_reset_updated) { |
| 414 | tiocm |= TIOCM_OUT2; |
| 415 | info->in_reset_updated = 0; |
| 416 | } |
| 417 | spin_unlock_irqrestore(&info->reset_lock, flags); |
| 418 | |
| 419 | return tiocm; |
| 420 | } |
| 421 | |
| 422 | static int smd_tty_tiocmset(struct tty_struct *tty, |
| 423 | unsigned int set, unsigned int clear) |
| 424 | { |
| 425 | struct smd_tty_info *info = tty->driver_data; |
| 426 | |
| 427 | if (info->in_reset) |
| 428 | return -ENETRESET; |
| 429 | |
| 430 | return smd_tiocmset(info->ch, set, clear); |
| 431 | } |
| 432 | |
| 433 | static void loopback_probe_worker(struct work_struct *work) |
| 434 | { |
| 435 | /* wait for modem to restart before requesting loopback server */ |
| 436 | if (!is_modem_smsm_inited()) |
| 437 | schedule_delayed_work(&loopback_work, msecs_to_jiffies(1000)); |
| 438 | else |
| 439 | smsm_change_state(SMSM_APPS_STATE, |
| 440 | 0, SMSM_SMD_LOOPBACK); |
| 441 | } |
| 442 | |
| 443 | static struct tty_operations smd_tty_ops = { |
| 444 | .open = smd_tty_open, |
| 445 | .close = smd_tty_close, |
| 446 | .write = smd_tty_write, |
| 447 | .write_room = smd_tty_write_room, |
| 448 | .chars_in_buffer = smd_tty_chars_in_buffer, |
| 449 | .unthrottle = smd_tty_unthrottle, |
| 450 | .tiocmget = smd_tty_tiocmget, |
| 451 | .tiocmset = smd_tty_tiocmset, |
| 452 | }; |
| 453 | |
| 454 | static int smd_tty_dummy_probe(struct platform_device *pdev) |
| 455 | { |
| 456 | if (!strncmp(pdev->name, smd_ch_name[0], |
| 457 | strnlen(smd_ch_name[0], SMD_MAX_CH_NAME_LEN))) |
| 458 | complete_all(&smd_tty[0].ch_allocated); |
| 459 | else if (!strncmp(pdev->name, smd_ch_name[1], |
| 460 | strnlen(smd_ch_name[1], SMD_MAX_CH_NAME_LEN))) |
| 461 | complete_all(&smd_tty[1].ch_allocated); |
| 462 | else if (!strncmp(pdev->name, smd_ch_name[2], |
| 463 | strnlen(smd_ch_name[2], SMD_MAX_CH_NAME_LEN))) |
| 464 | complete_all(&smd_tty[2].ch_allocated); |
| 465 | else if (!strncmp(pdev->name, smd_ch_name[3], |
| 466 | strnlen(smd_ch_name[3], SMD_MAX_CH_NAME_LEN))) |
| 467 | complete_all(&smd_tty[3].ch_allocated); |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 468 | else if (!strncmp(pdev->name, smd_ch_name[4], |
| 469 | strnlen(smd_ch_name[4], SMD_MAX_CH_NAME_LEN))) |
| 470 | complete_all(&smd_tty[4].ch_allocated); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 471 | else if (!strncmp(pdev->name, smd_ch_name[7], |
| 472 | strnlen(smd_ch_name[7], SMD_MAX_CH_NAME_LEN))) |
| 473 | complete_all(&smd_tty[7].ch_allocated); |
| 474 | else if (!strncmp(pdev->name, smd_ch_name[21], |
| 475 | strnlen(smd_ch_name[21], SMD_MAX_CH_NAME_LEN))) |
| 476 | complete_all(&smd_tty[21].ch_allocated); |
| 477 | else if (!strncmp(pdev->name, smd_ch_name[27], |
| 478 | strnlen(smd_ch_name[27], SMD_MAX_CH_NAME_LEN))) |
| 479 | complete_all(&smd_tty[27].ch_allocated); |
| 480 | else if (!strncmp(pdev->name, "LOOPBACK_TTY", |
| 481 | strnlen("LOOPBACK_TTY", SMD_MAX_CH_NAME_LEN))) |
| 482 | complete_all(&smd_tty[36].ch_allocated); |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static struct tty_driver *smd_tty_driver; |
| 488 | |
| 489 | static int __init smd_tty_init(void) |
| 490 | { |
| 491 | int ret; |
Jeff Hugo | 4c0ba6c | 2011-07-15 11:47:13 -0600 | [diff] [blame] | 492 | int ds_registered = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 493 | |
| 494 | smd_tty_driver = alloc_tty_driver(MAX_SMD_TTYS); |
| 495 | if (smd_tty_driver == 0) |
| 496 | return -ENOMEM; |
| 497 | |
| 498 | smd_tty_driver->owner = THIS_MODULE; |
| 499 | smd_tty_driver->driver_name = "smd_tty_driver"; |
| 500 | smd_tty_driver->name = "smd"; |
| 501 | smd_tty_driver->major = 0; |
| 502 | smd_tty_driver->minor_start = 0; |
| 503 | smd_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 504 | smd_tty_driver->subtype = SERIAL_TYPE_NORMAL; |
| 505 | smd_tty_driver->init_termios = tty_std_termios; |
| 506 | smd_tty_driver->init_termios.c_iflag = 0; |
| 507 | smd_tty_driver->init_termios.c_oflag = 0; |
| 508 | smd_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; |
| 509 | smd_tty_driver->init_termios.c_lflag = 0; |
| 510 | smd_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS | |
| 511 | TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
| 512 | tty_set_operations(smd_tty_driver, &smd_tty_ops); |
| 513 | |
| 514 | ret = tty_register_driver(smd_tty_driver); |
| 515 | if (ret) return ret; |
| 516 | |
| 517 | /* this should be dynamic */ |
| 518 | tty_register_device(smd_tty_driver, 0, 0); |
| 519 | tty_register_device(smd_tty_driver, 1, 0); |
| 520 | tty_register_device(smd_tty_driver, 2, 0); |
| 521 | tty_register_device(smd_tty_driver, 3, 0); |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 522 | tty_register_device(smd_tty_driver, 4, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 523 | tty_register_device(smd_tty_driver, 7, 0); |
| 524 | tty_register_device(smd_tty_driver, 21, 0); |
| 525 | tty_register_device(smd_tty_driver, 27, 0); |
| 526 | tty_register_device(smd_tty_driver, 36, 0); |
| 527 | |
| 528 | init_completion(&smd_tty[0].ch_allocated); |
| 529 | init_completion(&smd_tty[1].ch_allocated); |
| 530 | init_completion(&smd_tty[2].ch_allocated); |
| 531 | init_completion(&smd_tty[3].ch_allocated); |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 532 | init_completion(&smd_tty[4].ch_allocated); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 533 | init_completion(&smd_tty[7].ch_allocated); |
| 534 | init_completion(&smd_tty[21].ch_allocated); |
| 535 | init_completion(&smd_tty[27].ch_allocated); |
| 536 | init_completion(&smd_tty[36].ch_allocated); |
| 537 | |
| 538 | smd_tty[0].driver.probe = smd_tty_dummy_probe; |
| 539 | smd_tty[0].driver.driver.name = smd_ch_name[0]; |
| 540 | smd_tty[0].driver.driver.owner = THIS_MODULE; |
| 541 | spin_lock_init(&smd_tty[0].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 542 | smd_tty[0].is_open = 0; |
| 543 | init_waitqueue_head(&smd_tty[0].ch_opened_wait_queue); |
Jeff Hugo | 4c0ba6c | 2011-07-15 11:47:13 -0600 | [diff] [blame] | 544 | /* |
| 545 | * DS port is opened in the kernel starting with 8660 fusion. |
| 546 | * Only register the platform driver for targets older than that. |
| 547 | */ |
| 548 | if (cpu_is_msm7x01() || cpu_is_msm7x25() || cpu_is_msm7x27() || |
| 549 | cpu_is_msm7x27a() || cpu_is_msm7x27aa() || |
| 550 | cpu_is_msm7x25a() || cpu_is_msm7x25aa() || |
| 551 | cpu_is_msm7x30() || cpu_is_qsd8x50() || |
| 552 | cpu_is_msm8x55() || (cpu_is_msm8x60() && |
| 553 | socinfo_get_platform_subtype() == 0x1)) { |
| 554 | ret = platform_driver_register(&smd_tty[0].driver); |
| 555 | if (ret) |
| 556 | goto out; |
| 557 | ds_registered = 1; |
| 558 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 559 | smd_tty[1].driver.probe = smd_tty_dummy_probe; |
| 560 | smd_tty[1].driver.driver.name = smd_ch_name[1]; |
| 561 | smd_tty[1].driver.driver.owner = THIS_MODULE; |
| 562 | spin_lock_init(&smd_tty[1].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 563 | smd_tty[1].is_open = 0; |
| 564 | init_waitqueue_head(&smd_tty[1].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 565 | ret = platform_driver_register(&smd_tty[1].driver); |
| 566 | if (ret) |
| 567 | goto unreg0; |
| 568 | smd_tty[2].driver.probe = smd_tty_dummy_probe; |
| 569 | smd_tty[2].driver.driver.name = smd_ch_name[2]; |
| 570 | smd_tty[2].driver.driver.owner = THIS_MODULE; |
| 571 | spin_lock_init(&smd_tty[2].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 572 | smd_tty[2].is_open = 0; |
| 573 | init_waitqueue_head(&smd_tty[2].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 574 | ret = platform_driver_register(&smd_tty[2].driver); |
| 575 | if (ret) |
| 576 | goto unreg1; |
| 577 | smd_tty[3].driver.probe = smd_tty_dummy_probe; |
| 578 | smd_tty[3].driver.driver.name = smd_ch_name[3]; |
| 579 | smd_tty[3].driver.driver.owner = THIS_MODULE; |
| 580 | spin_lock_init(&smd_tty[3].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 581 | smd_tty[3].is_open = 0; |
| 582 | init_waitqueue_head(&smd_tty[3].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 583 | ret = platform_driver_register(&smd_tty[3].driver); |
| 584 | if (ret) |
| 585 | goto unreg2; |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 586 | smd_tty[4].driver.probe = smd_tty_dummy_probe; |
| 587 | smd_tty[4].driver.driver.name = smd_ch_name[4]; |
| 588 | smd_tty[4].driver.driver.owner = THIS_MODULE; |
| 589 | spin_lock_init(&smd_tty[4].reset_lock); |
| 590 | smd_tty[4].is_open = 0; |
| 591 | init_waitqueue_head(&smd_tty[4].ch_opened_wait_queue); |
| 592 | ret = platform_driver_register(&smd_tty[4].driver); |
| 593 | if (ret) |
| 594 | goto unreg3; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 595 | smd_tty[7].driver.probe = smd_tty_dummy_probe; |
| 596 | smd_tty[7].driver.driver.name = smd_ch_name[7]; |
| 597 | smd_tty[7].driver.driver.owner = THIS_MODULE; |
| 598 | spin_lock_init(&smd_tty[7].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 599 | smd_tty[7].is_open = 0; |
| 600 | init_waitqueue_head(&smd_tty[7].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 601 | ret = platform_driver_register(&smd_tty[7].driver); |
| 602 | if (ret) |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 603 | goto unreg4; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 604 | smd_tty[21].driver.probe = smd_tty_dummy_probe; |
| 605 | smd_tty[21].driver.driver.name = smd_ch_name[21]; |
| 606 | smd_tty[21].driver.driver.owner = THIS_MODULE; |
| 607 | spin_lock_init(&smd_tty[21].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 608 | smd_tty[21].is_open = 0; |
| 609 | init_waitqueue_head(&smd_tty[21].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 610 | ret = platform_driver_register(&smd_tty[21].driver); |
| 611 | if (ret) |
| 612 | goto unreg7; |
| 613 | smd_tty[27].driver.probe = smd_tty_dummy_probe; |
| 614 | smd_tty[27].driver.driver.name = smd_ch_name[27]; |
| 615 | smd_tty[27].driver.driver.owner = THIS_MODULE; |
| 616 | spin_lock_init(&smd_tty[27].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 617 | smd_tty[27].is_open = 0; |
| 618 | init_waitqueue_head(&smd_tty[27].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 619 | ret = platform_driver_register(&smd_tty[27].driver); |
| 620 | if (ret) |
| 621 | goto unreg21; |
| 622 | smd_tty[36].driver.probe = smd_tty_dummy_probe; |
| 623 | smd_tty[36].driver.driver.name = "LOOPBACK_TTY"; |
| 624 | smd_tty[36].driver.driver.owner = THIS_MODULE; |
| 625 | spin_lock_init(&smd_tty[36].reset_lock); |
Karthikeyan Ramasubramanian | d5e63af | 2011-07-29 11:30:59 -0600 | [diff] [blame] | 626 | smd_tty[36].is_open = 0; |
| 627 | init_waitqueue_head(&smd_tty[36].ch_opened_wait_queue); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 628 | INIT_DELAYED_WORK(&loopback_work, loopback_probe_worker); |
| 629 | ret = platform_driver_register(&smd_tty[36].driver); |
| 630 | if (ret) |
| 631 | goto unreg27; |
| 632 | |
| 633 | return 0; |
| 634 | |
| 635 | unreg27: |
| 636 | platform_driver_unregister(&smd_tty[27].driver); |
| 637 | unreg21: |
| 638 | platform_driver_unregister(&smd_tty[21].driver); |
| 639 | unreg7: |
| 640 | platform_driver_unregister(&smd_tty[7].driver); |
Angshuman Sarkar | 8fa3eb6 | 2011-09-15 16:50:07 +0530 | [diff] [blame] | 641 | unreg4: |
| 642 | platform_driver_unregister(&smd_tty[4].driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 643 | unreg3: |
| 644 | platform_driver_unregister(&smd_tty[3].driver); |
| 645 | unreg2: |
| 646 | platform_driver_unregister(&smd_tty[2].driver); |
| 647 | unreg1: |
| 648 | platform_driver_unregister(&smd_tty[1].driver); |
| 649 | unreg0: |
Jeff Hugo | 4c0ba6c | 2011-07-15 11:47:13 -0600 | [diff] [blame] | 650 | if (ds_registered) |
| 651 | platform_driver_unregister(&smd_tty[0].driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 652 | out: |
| 653 | tty_unregister_device(smd_tty_driver, 0); |
| 654 | tty_unregister_device(smd_tty_driver, 1); |
| 655 | tty_unregister_device(smd_tty_driver, 2); |
| 656 | tty_unregister_device(smd_tty_driver, 3); |
| 657 | tty_unregister_device(smd_tty_driver, 7); |
| 658 | tty_unregister_device(smd_tty_driver, 21); |
| 659 | tty_unregister_device(smd_tty_driver, 27); |
| 660 | tty_unregister_device(smd_tty_driver, 36); |
| 661 | tty_unregister_driver(smd_tty_driver); |
| 662 | put_tty_driver(smd_tty_driver); |
| 663 | return ret; |
| 664 | } |
| 665 | |
| 666 | module_init(smd_tty_init); |