#include <asm/io.h>\r
#include <asm/irq.h>\r
\r
+#include <mach/iomux.h>\r
+#include <mach/gpio.h>\r
+\r
+\r
\r
#define PORT_RK 90\r
#define UART_USR 0x1F /* UART Status Register */\r
#define USE_TIMER 1 // use timer for dma transport\r
#define THRE_MODE 0X00 //0yhh\r
\r
+//define which uart the bluetooth use on which board\r
+#ifdef CONFIG_MACH_RK29_PHONESDK\r
+#define BLUETOOTH_UART 2\r
+#else\r
+#define BLUETOOTH_UART 2\r
+#endif\r
+\r
+\r
static struct uart_driver serial_rk_reg;\r
\r
/*\r
* Debugging.\r
*/\r
-#define DBG_PORT 1\r
+\r
+#define DBG_PORT 2 // 0,1,2,3, other numbers is default\r
+#if 0\r
+#define DBG(msg...) printk(msg);\r
+#define DEBUG_INTR(fmt...) if (!uart_console(&up->port)) DBG(fmt)\r
+#else\r
+#define DBG(...)\r
+#define DEBUG_INTR(fmt...) do { } while (0)\r
+#endif\r
+\r
#ifdef CONFIG_SERIAL_CORE_CONSOLE\r
#define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line)\r
#else\r
#define uart_console(port) (0)\r
#endif\r
\r
-#ifdef DEBUG\r
-extern void printascii(const char *);\r
-\r
-static void dbg(const char *fmt, ...)\r
-{\r
- va_list va;\r
- char buff[256];\r
-\r
- va_start(va, fmt);\r
- vsprintf(buff, fmt, va);\r
- va_end(va);\r
-\r
- printascii(buff);\r
-}\r
-\r
-#define DEBUG_INTR(fmt...) if (!uart_console(&up->port)) dbg(fmt)\r
-#else\r
-#define DEBUG_INTR(fmt...) do { } while (0)\r
-#endif\r
\r
\r
/* added by hhb@rock-chips.com for uart dma transfer */\r
{\r
struct uart_rk_port *up =\r
container_of(port, struct uart_rk_port, port);\r
-/*\r
- * struct circ_buf *xmit = &port->state->xmit;\r
- int size = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE);\r
- if(size > 64){\r
- serial_rk_start_tx_dma(port);\r
- }\r
- else{\r
- serial_rk_enable_ier_thri(up);\r
- }\r
-*/\r
-\r
if(0 == serial_rk_start_tx_dma(port)){\r
serial_rk_enable_ier_thri(up);\r
}\r
-\r
}\r
\r
\r
receive_chars(struct uart_rk_port *up, unsigned int *status)\r
{\r
struct tty_struct *tty = up->port.state->port.tty;\r
+ struct uart_port *port = &up->port;\r
unsigned char ch, lsr = *status;\r
int max_count = 256;\r
char flag;\r
\r
+ if(DBG_PORT == port->line) {\r
+ DBG("RX:");\r
+ }\r
+\r
do {\r
if (likely(lsr & UART_LSR_DR))\r
ch = serial_in(up, UART_RX);\r
goto ignore_char;\r
\r
uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);\r
-\r
+ if(DBG_PORT == port->line) {\r
+ DBG("0x%x, ", ch);\r
+ }\r
ignore_char:\r
lsr = serial_in(up, UART_LSR);\r
} while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));\r
tty_flip_buffer_push(tty);\r
spin_lock(&up->port.lock);\r
*status = lsr;\r
+\r
+ if(DBG_PORT == port->line) {\r
+ DBG("\n");\r
+ }\r
+\r
}\r
\r
static void transmit_chars(struct uart_rk_port *up)\r
{\r
struct circ_buf *xmit = &up->port.state->xmit;\r
+ struct uart_port *port = &up->port;\r
int count;\r
\r
if (up->port.x_char) {\r
return;\r
}\r
\r
+ if(DBG_PORT == port->line) {\r
+ DBG("TX:");\r
+ }\r
+\r
count = up->tx_loadsz;\r
do {\r
serial_out(up, UART_TX, xmit->buf[xmit->tail]);\r
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);\r
up->port.icount.tx++;\r
+ if(DBG_PORT == port->line) {\r
+ DBG("0x%x, ", xmit->buf[xmit->tail]);\r
+ }\r
if (uart_circ_empty(xmit))\r
break;\r
} while (--count > 0);\r
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)\r
uart_write_wakeup(&up->port);\r
\r
+ if(DBG_PORT == port->line) {\r
+ DBG("\n");\r
+ }\r
+\r
DEBUG_INTR("THRE...");\r
\r
if (uart_circ_empty(xmit))\r
struct uart_rk_port *up =\r
container_of(port, struct uart_rk_port, port);\r
unsigned char cval, fcr = 0;\r
- unsigned long flags, bits;\r
+ unsigned long flags;\r
unsigned int baud, quot;\r
\r
dev_dbg(port->dev, "+%s\n", __func__);\r
\r
- //start bit\r
- bits += 1;\r
switch (termios->c_cflag & CSIZE) {\r
case CS5:\r
cval = UART_LCR_WLEN5;\r
- bits += 5;\r
break;\r
case CS6:\r
cval = UART_LCR_WLEN6;\r
- bits += 6;\r
break;\r
case CS7:\r
cval = UART_LCR_WLEN7;\r
- bits += 7;\r
break;\r
default:\r
case CS8:\r
cval = UART_LCR_WLEN8;\r
- bits += 8;\r
break;\r
}\r
\r
if (termios->c_cflag & CSTOPB){\r
cval |= UART_LCR_STOP;\r
- bits += 2;\r
- }\r
- else{\r
- bits += 1;\r
}\r
if (termios->c_cflag & PARENB){\r
cval |= UART_LCR_PARITY;\r
- bits += 1;\r
}\r
if (!(termios->c_cflag & PARODD)){\r
cval |= UART_LCR_EPAR;\r
\r
quot = uart_get_divisor(port, baud);\r
\r
-\r
- dev_info(up->port.dev, "*****baud:%d*******\n", baud);\r
- dev_info(up->port.dev, "*****quot:%d*******\n", quot);\r
-\r
if (baud < 2400){\r
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;\r
}\r
//added by hhb@rock-chips.com\r
if(up->prk29_uart_dma_t->use_timer == 1){\r
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00 | UART_FCR_T_TRIG_01;\r
- //set time out value according to the baud rate\r
-/*\r
- up->prk29_uart_dma_t->rx_timeout = bits*1000*1024/baud + 1;\r
-\r
- if(up->prk29_uart_dma_t->rx_timeout < 10){\r
- up->prk29_uart_dma_t->rx_timeout = 10;\r
- }\r
- if(up->prk29_uart_dma_t->rx_timeout > 25){\r
- up->prk29_uart_dma_t->rx_timeout = 25;\r
- }\r
- printk("%s:time:%d, bits:%d, baud:%d\n", __func__, up->prk29_uart_dma_t->rx_timeout, bits, baud);\r
- up->prk29_uart_dma_t->rx_timeout = 7;\r
-*/\r
}\r
else{\r
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 | UART_FCR_T_TRIG_01;\r
up->mcr &= ~UART_MCR_AFE;\r
if (termios->c_cflag & CRTSCTS){\r
up->mcr |= UART_MCR_AFE;\r
- //dev_info(up->port.dev, "*****UART_MCR_AFE*******\n");\r
}\r
\r
-\r
/*\r
* Ok, we're now changing the port state. Do it with\r
* interrupts disabled.\r
{\r
struct uart_rk_port *up = platform_get_drvdata(dev);\r
\r
- if (up)\r
+ if (up){\r
uart_suspend_port(&serial_rk_reg, &up->port);\r
+ if(up->port.line == BLUETOOTH_UART){\r
+ rk29_mux_api_set(GPIO2A7_UART2RTSN_NAME, GPIO2L_GPIO2A7);\r
+ gpio_request(RK29_PIN2_PA7, "uart_rts");\r
+ gpio_direction_output(RK29_PIN2_PA7, 0);\r
+ gpio_set_value(RK29_PIN2_PA7, GPIO_HIGH);\r
+ }else{\r
+ serial_out(up, UART_MCR, 0);\r
+ }\r
+ }\r
return 0;\r
}\r
\r
+\r
+static struct timer_list uart2_tl;\r
+static bool timer_init = false;\r
+static void timer_resume_uart2(unsigned long arg)\r
+{\r
+ DBG("%s---\n", __FUNCTION__);\r
+ gpio_set_value(RK29_PIN2_PA7, GPIO_LOW);\r
+ rk29_mux_api_set(GPIO2A7_UART2RTSN_NAME, GPIO2L_UART2_RTS_N);\r
+}\r
+\r
static int serial_rk_resume(struct platform_device *dev)\r
{\r
struct uart_rk_port *up = platform_get_drvdata(dev);\r
\r
- if (up)\r
+ if (up){\r
uart_resume_port(&serial_rk_reg, &up->port);\r
+\r
+ if(up->port.line == BLUETOOTH_UART){\r
+ if(!timer_init){\r
+ init_timer(&uart2_tl);\r
+ uart2_tl.expires = jiffies + msecs_to_jiffies(30);\r
+ uart2_tl.function = timer_resume_uart2;\r
+ add_timer(&uart2_tl);\r
+ timer_init = true;\r
+ }\r
+ else{\r
+ mod_timer(&uart2_tl,jiffies + msecs_to_jiffies(30));\r
+ }\r
+ }\r
+ }\r
return 0;\r
}\r
\r