/* * gs_buf_putr * * As per gs_buf_put, but add '\r' to any '\n's */ static unsigned gs_buf_putr(struct gs_buf *gb,const char *buf,unsigned count) { unsigned i; unsigned j; unsigned ret; for(i = 0, j = 0; i < count; i++){ if(buf[i] != '\n') continue; ret = gs_buf_put(gb,buf+j,i-j); if(ret !=i-j) return j+ret; j += ret; /* Do not lose an \n on a buffer seam. */ if(gs_buf_space_avail(gb) < 2) return j; gs_buf_put(gb,"\r\n",2); j++; } if( j < count ){ j += gs_buf_put(gb,buf+j, count = j); } return j; }
/*NOTE: can not add any print information, or it will printk a lot of print info for ever*/ void ttyGs_console_write(struct console *co,const char *buf, unsigned count) { int total = 0; int port_num = 0; struct gs_port *port; unsigned long flags; int retval=0; if(co == NULL) // if console unregister, then exit return; //mutex_lock(&ports[port_num].lock); port = ports[port_num].port; //mutex_unlock(&ports[port_num].lock); if (!(port->port_usb)) //if usb cable unplug, exit immediately return; total = count; while(total) { unsigned int i; unsigned int lf; /*search for LF so we can insert CR if necessary */ for (i = 0, lf = 0 ; i < total ; i++) { if (*(buf + i) == 10) { lf = 1; i++; break; } } spin_lock_irqsave(&port->port_lock, flags); if (i) retval = gs_buf_put(&port->port_write_buf, buf, i); if (port->port_usb) //if usb cable unplug, exit immediately gs_start_tx(port); else break; //TODO: if usb disconnect, then we should exit also. //there is no sense, when have no listenning on host if(lf) { /* append CR after LF */ unsigned char cr = 13; retval = gs_buf_put(&port->port_write_buf, &cr, 1); } spin_unlock_irqrestore(&port->port_lock, flags); total -= i; buf += i; } //TODO: flush remaining strings gs_port_flush_char(port); return; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; #if ACM_ZLP struct usb_ep *in; #endif pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (count) count = gs_buf_put(&port->port_write_buf, buf, count); #if ACM_ZLP if (port->port_usb) { in = port->port_usb->in; s3c_multiple = 0; if ( count != 0 && (count % in->maxpacket == 0)) { s3c_multiple = 1; } } #endif /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port; unsigned long flags; int status; if (tty->driver_data == (void *)0) { pr_warn("tty->driver_data is zero\n"); return 0; } port = tty->driver_data; pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (count) count = gs_buf_put(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); if (port->port_write_buf.buf_full) wait_event_interruptible_timeout(port->full_wait, !port->port_write_buf.buf_full, GS_FULL_TIMEOUT * HZ); spin_lock_irqsave(&port->port_lock, flags); if (unlikely(port->port_write_buf.buf_buf == NULL)) { spin_unlock_irqrestore(&port->port_lock, flags); return 0; } if (count) count = gs_buf_put(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; //ALPS00423739 if(!port) { printk("ERROR!!! port is closed!! %s, line %d: port = %p\n", __func__, __LINE__, port); /*abort immediately after disconnect */ return -EINVAL; } //ALPS00423739 pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (count) count = gs_buf_put(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = NULL; unsigned long flags; int status; if(!tty || !buf){ pr_err("%s error: wrong parameter! *tty=0x%x, *buf=0x%x", __func__, (unsigned int) tty, (unsigned int) buf); return 0; } port = tty->driver_data; if(!port){ pr_err("%s error: port = NULL! already closed??\n", __func__); return 0; } pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (count) count = gs_buf_put(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_put_char(struct tty_struct *tty, unsigned char ch) { struct gs_port *port = NULL; unsigned long flags; int status; if(!tty ){ pr_err("%s error: wrong parameter! *tty=0x%x", __func__, (unsigned int) tty); return 0; } port = tty->driver_data; if(!port){ pr_err("%s error: port = NULL! already closed??\n", __func__); return 0; } pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %p\n", port->port_num, tty, ch, __builtin_return_address(0)); spin_lock_irqsave(&port->port_lock, flags); status = gs_buf_put(&port->port_write_buf, &ch, 1); spin_unlock_irqrestore(&port->port_lock, flags); return status; }
static int gs_put_char(struct tty_struct *tty, unsigned char ch) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %p\n", port->port_num, tty, ch, __builtin_return_address(0)); spin_lock_irqsave(&port->port_lock, flags); status = gs_buf_put(&port->port_write_buf, &ch, 1); spin_unlock_irqrestore(&port->port_lock, flags); return status; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (count) count = gs_buf_put(&port->port_write_buf, buf, count); if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (unlikely(!port->open_count)) { spin_unlock_irqrestore(&port->port_lock, flags); return -EINVAL; } if (unlikely(!port->port_usb || port->is_suspend)) { port->stat_write_not_conn++; spin_unlock_irqrestore(&port->port_lock, flags); return -ESHUTDOWN; } /* * we don't have enough room for some data * may be the host don't start read, so drop the data. * otherwise the printed thread may pending forever. */ if (!port->line_state_on && list_empty(&port->write_pool)) { port->stat_write_no_mem++; spin_unlock_irqrestore(&port->port_lock, flags); return -ENOMEM; } if (count) count = gs_buf_put(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port);/* [false alarm]:fortify disable */ spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static int gs_put_char(struct tty_struct *tty, unsigned char ch) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; //ALPS00423739 if(!port) { printk("ERROR!!! port is closed!! %s, line %d: port = %p\n", __func__, __LINE__, port); /*abort immediately after disconnect */ return -EINVAL; } //ALPS00423739 pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %pf\n", port->port_num, tty, ch, __builtin_return_address(0)); spin_lock_irqsave(&port->port_lock, flags); status = gs_buf_put(&port->port_write_buf, &ch, 1); spin_unlock_irqrestore(&port->port_lock, flags); return status; }
static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct gs_port *port = tty->driver_data; unsigned long flags; int status; #ifdef CONFIG_USB_G_LGE_ANDROID if (!port) return 0; #endif pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", port->port_num, tty, count); spin_lock_irqsave(&port->port_lock, flags); if (count) count = gs_buf_put(&port->port_write_buf, buf, count); /* treat count == 0 as flush_chars() */ if (port->port_usb) status = gs_start_tx(port); spin_unlock_irqrestore(&port->port_lock, flags); return count; }
static void gs_console_write(struct console *co, const char *buf, unsigned count) { struct gs_port *port = ports[ACM_CONSOLE_IDX].port; unsigned long flags; int no_data = 0; if (count == 0 || NULL == port) return; /* write the data to usb console buffer */ spin_lock_irqsave(&gs_console_ctx.lock, flags); if (gs_buf_space_avail(&gs_console_ctx.buf_info) < count) { port->stat_con_write_no_room++; no_data = 1; } (void)gs_buf_put(&gs_console_ctx.buf_info, buf, count); spin_unlock_irqrestore(&gs_console_ctx.lock, flags); /* we can delay a little time to get the more msg */ if (!no_data) schedule_delayed_work(&gs_console_ctx.write_work, 1); return; }