29 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
37 #include <linux/tty.h>
40 #include <linux/slab.h>
51 #define FIFO_SIZE PAGE_SIZE
52 #define WAKEUP_CHARS 256
96 kref_init(&port->
kref);
102 spin_lock(&sdio_uart_table_lock);
103 for (index = 0; index <
UART_NR; index++) {
104 if (!sdio_uart_table[index]) {
111 spin_unlock(&sdio_uart_table_lock);
120 if (index >= UART_NR)
123 spin_lock(&sdio_uart_table_lock);
124 port = sdio_uart_table[
index];
126 kref_get(&port->
kref);
127 spin_unlock(&sdio_uart_table_lock);
132 static void sdio_uart_port_destroy(
struct kref *
kref)
142 kref_put(&port->
kref, sdio_uart_port_destroy);
152 spin_lock(&sdio_uart_table_lock);
154 spin_unlock(&sdio_uart_table_lock);
180 sdio_uart_port_put(port);
196 static inline void sdio_uart_release_func(
struct sdio_uart_port *port)
214 static unsigned int sdio_uart_get_mctrl(
struct sdio_uart_port *port)
238 unsigned char mcr = 0;
254 static inline void sdio_uart_update_mctrl(
struct sdio_uart_port *port,
255 unsigned int set,
unsigned int clear)
260 port->
mctrl = (old & ~clear) |
set;
261 if (old != port->
mctrl)
262 sdio_uart_write_mctrl(port, port->
mctrl);
265 #define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0)
266 #define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x)
272 unsigned char cval,
fcr = 0;
273 unsigned int baud, quot;
302 if (baud <= port->uartclk)
361 sdio_out(port,
UART_DLL, quot & 0xff);
362 sdio_out(port,
UART_DLM, quot >> 8);
366 sdio_uart_write_mctrl(port, port->
mctrl);
393 unsigned int *status)
396 unsigned int ch,
flag;
423 if (*status & UART_LSR_BI)
425 else if (*status & UART_LSR_PE)
427 else if (*status & UART_LSR_FE)
433 tty_insert_flip_char(tty, ch, flag);
444 }
while ((*status &
UART_LSR_DR) && (max_count-- > 0));
470 sdio_uart_stop_tx(port);
476 for (count = 0; count < len; count++) {
477 sdio_out(port,
UART_TX, iobuf[count]);
485 sdio_uart_stop_tx(port);
490 static void sdio_uart_check_modem_status(
struct sdio_uart_port *port)
507 if (status & UART_MSR_DCD)
521 if (tty && (tty->termios.c_cflag &
CRTSCTS)) {
526 sdio_uart_start_tx(port);
532 sdio_uart_stop_tx(port);
543 static void sdio_uart_irq(
struct sdio_func *func)
546 unsigned int iir, lsr;
565 if (lsr & UART_LSR_DR)
566 sdio_uart_receive_chars(port, &lsr);
567 sdio_uart_check_modem_status(port);
569 sdio_uart_transmit_chars(port);
573 static int uart_carrier_raised(
struct tty_port *tport)
577 unsigned int ret = sdio_uart_claim_func(port);
580 ret = sdio_uart_get_mctrl(port);
581 sdio_uart_release_func(port);
600 int ret = sdio_uart_claim_func(port);
607 sdio_uart_release_func(port);
639 ret = sdio_uart_claim_func(port);
674 sdio_uart_change_speed(port, &tty->termios,
NULL);
676 if (tty->termios.c_cflag &
CBAUD)
679 if (tty->termios.c_cflag &
CRTSCTS)
680 if (!(sdio_uart_get_mctrl(port) &
TIOCM_CTS))
686 sdio_uart_irq(port->
func);
688 sdio_uart_release_func(port);
694 sdio_uart_release_func(port);
708 static void sdio_uart_shutdown(
struct tty_port *tport)
714 ret = sdio_uart_claim_func(port);
718 sdio_uart_stop_rx(port);
737 sdio_uart_release_func(port);
759 sdio_uart_port_put(port);
771 static void sdio_uart_cleanup(
struct tty_struct *tty)
775 sdio_uart_port_put(port);
782 static int sdio_uart_open(
struct tty_struct *tty,
struct file *filp)
788 static void sdio_uart_close(
struct tty_struct *tty,
struct file * filp)
794 static void sdio_uart_hangup(
struct tty_struct *tty)
800 static int sdio_uart_write(
struct tty_struct *tty,
const unsigned char *
buf,
811 int err = sdio_uart_claim_func(port);
813 sdio_uart_start_tx(port);
814 sdio_uart_irq(port->
func);
815 sdio_uart_release_func(port);
823 static int sdio_uart_write_room(
struct tty_struct *tty)
829 static int sdio_uart_chars_in_buffer(
struct tty_struct *tty)
835 static void sdio_uart_send_xchar(
struct tty_struct *tty,
char ch)
841 if (sdio_uart_claim_func(port) != 0)
843 sdio_uart_start_tx(port);
844 sdio_uart_irq(port->
func);
845 sdio_uart_release_func(port);
849 static void sdio_uart_throttle(
struct tty_struct *tty)
856 if (sdio_uart_claim_func(port) != 0)
861 sdio_uart_start_tx(port);
864 if (tty->termios.c_cflag &
CRTSCTS)
867 sdio_uart_irq(port->
func);
868 sdio_uart_release_func(port);
871 static void sdio_uart_unthrottle(
struct tty_struct *tty)
878 if (sdio_uart_claim_func(port) != 0)
886 sdio_uart_start_tx(port);
890 if (tty->termios.c_cflag &
CRTSCTS)
893 sdio_uart_irq(port->
func);
894 sdio_uart_release_func(port);
897 static void sdio_uart_set_termios(
struct tty_struct *tty,
901 unsigned int cflag = tty->termios.c_cflag;
903 if (sdio_uart_claim_func(port) != 0)
906 sdio_uart_change_speed(port, &tty->termios, old_termios);
913 if (!(old_termios->
c_cflag & CBAUD) && (cflag & CBAUD)) {
921 if ((old_termios->
c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
923 sdio_uart_start_tx(port);
927 if (!(old_termios->
c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
928 if (!(sdio_uart_get_mctrl(port) &
TIOCM_CTS)) {
930 sdio_uart_stop_tx(port);
934 sdio_uart_release_func(port);
937 static int sdio_uart_break_ctl(
struct tty_struct *tty,
int break_state)
942 result = sdio_uart_claim_func(port);
946 if (break_state == -1)
952 sdio_uart_release_func(port);
956 static int sdio_uart_tiocmget(
struct tty_struct *tty)
961 result = sdio_uart_claim_func(port);
963 result = port->
mctrl | sdio_uart_get_mctrl(port);
964 sdio_uart_release_func(port);
970 static int sdio_uart_tiocmset(
struct tty_struct *tty,
971 unsigned int set,
unsigned int clear)
976 result = sdio_uart_claim_func(port);
978 sdio_uart_update_mctrl(port,
set, clear);
979 sdio_uart_release_func(port);
985 static int sdio_uart_proc_show(
struct seq_file *
m,
void *
v)
989 seq_printf(m,
"serinfo:1.0 driver%s%s revision:%s\n",
991 for (i = 0; i <
UART_NR; i++) {
1007 if (port->
icount.overrun)
1023 sdio_uart_port_put(port);
1037 .open = sdio_uart_proc_open,
1044 .dtr_rts = uart_dtr_rts,
1045 .carrier_raised = uart_carrier_raised,
1046 .shutdown = sdio_uart_shutdown,
1047 .activate = sdio_uart_activate,
1051 .open = sdio_uart_open,
1052 .close = sdio_uart_close,
1053 .write = sdio_uart_write,
1054 .write_room = sdio_uart_write_room,
1055 .chars_in_buffer = sdio_uart_chars_in_buffer,
1056 .send_xchar = sdio_uart_send_xchar,
1057 .throttle = sdio_uart_throttle,
1058 .unthrottle = sdio_uart_unthrottle,
1059 .set_termios = sdio_uart_set_termios,
1060 .hangup = sdio_uart_hangup,
1061 .break_ctl = sdio_uart_break_ctl,
1062 .tiocmget = sdio_uart_tiocmget,
1063 .tiocmset = sdio_uart_tiocmset,
1064 .install = sdio_uart_install,
1065 .cleanup = sdio_uart_cleanup,
1066 .proc_fops = &sdio_uart_proc_fops,
1069 static struct tty_driver *sdio_uart_tty_driver;
1071 static int sdio_uart_probe(
struct sdio_func *func,
1082 pr_warning(
"%s: need info on UART class basic setup\n",
1092 for (tpl = func->
tuples; tpl; tpl = tpl->
next) {
1093 if (tpl->
code != 0x91)
1097 if (tpl->
data[1] == 0)
1102 "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
1107 pr_debug(
"%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
1110 (tpl->
data[5] << 8) |
1111 (tpl->
data[6] << 16);
1112 pr_debug(
"%s: regs offset = 0x%x\n",
1117 pr_debug(
"%s: clk %d baudcode %u 4800-div %u\n",
1128 port->
port.ops = &sdio_uart_port_ops;
1130 ret = sdio_uart_add_port(port);
1136 sdio_uart_tty_driver, port->
index, &func->
dev);
1138 sdio_uart_port_remove(port);
1146 static void sdio_uart_remove(
struct sdio_func *func)
1151 sdio_uart_port_remove(port);
1163 .probe = sdio_uart_probe,
1164 .remove = sdio_uart_remove,
1165 .name =
"sdio_uart",
1166 .id_table = sdio_uart_ids,
1169 static int __init sdio_uart_init(
void)
1174 sdio_uart_tty_driver = tty_drv = alloc_tty_driver(UART_NR);
1179 tty_drv->
name =
"ttySDIO";
1208 static void __exit sdio_uart_exit(
void)