Re: [PATCH v9 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

2015-01-28 Thread Lyra Zhang
Hi, Baruch

I'm sorry that I didn't receive your previous email.
and my explanations are below.

On Wed, Jan 28, 2015 at 2:12 PM, Baruch Siach  wrote:
> Hi Chunyan Zhang,
>
> On Wed, Jan 28, 2015 at 10:47:41AM +0800, Chunyan Zhang wrote:
> [...]
>> +static inline void sprd_rx(struct uart_port *port)
>> +{
>> + struct tty_port *tty = &port->state->port;
>> + unsigned int ch, flag, lsr, max_count = SPRD_TIMEOUT;
>> +
>> + while ((serial_in(port, SPRD_STS1) & 0x00ff) && max_count--) {
>> + lsr = serial_in(port, SPRD_LSR);
>> + ch = serial_in(port, SPRD_RXD);
>> + flag = TTY_NORMAL;
>> + port->icount.rx++;
>> +
>> + if (lsr & (SPRD_LSR_BI | SPRD_LSR_PE |
>> + SPRD_LSR_FE | SPRD_LSR_OE))
>> + if (handle_lsr_errors(port, &lsr, &flag))
>> + continue;
>> + if (uart_handle_sysrq_char(port, ch))
>> + continue;
>
> My comment[1] on a previous version of this patch still stands.
> uart_handle_sysrq_char is a NOP when SUPPORT_SYSRQ is not defined.
>

yes, there are two definitions in serial_core.h, and it returns 0 when
SUPPORT_SYSRQ is not defined.
so, I think my code behavior does not hurt, right?

>> +
>> + uart_insert_char(port, lsr, SPRD_LSR_OE, ch, flag);
>> + }
>> +
>> + tty_flip_buffer_push(tty);
>> +}
>
> [...]
>
>> +static void sprd_console_write(struct console *co, const char *s,
>> +   unsigned int count)
>> +{
>> + struct uart_port *port = &sprd_port[co->index]->port;
>> + int locked = 1;
>> + unsigned long flags;
>> +
>> + if (port->sysrq)
>> + locked = 0;
>
> The sysrq field of struct uart_port is only defined when
> CONFIG_SERIAL_CORE_CONSOLE or SUPPORT_SYSRQ are defined. You should #ifdef
> this part accordingly to avoid build breakage.
>

we have this part to been included under #ifdef
CONFIG_SERIAL_SPRD_CONSOLE which is selected with SERIAL_CORE_CONSOLE.

Thank you very much!

Chunyan

>> + else if (oops_in_progress)
>> + locked = spin_trylock_irqsave(&port->lock, flags);
>> + else
>> + spin_lock_irqsave(&port->lock, flags);
>> +
>> + uart_console_write(port, s, count, sprd_console_putchar);
>> +
>> + /* wait for transmitter to become empty */
>> + wait_for_xmitr(port);
>> +
>> + if (locked)
>> + spin_unlock_irqrestore(&port->lock, flags);
>> +}
>
> [1]
> http://article.gmane.org/gmane.linux.drivers.devicetree/106483
>
> baruch
>
> --
>  http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
> =}ooO--U--Ooo{=
>- bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

2015-01-28 Thread Lyra Zhang
On Wed, Jan 28, 2015 at 5:54 PM, Baruch Siach  wrote:
> Hi Lyra Zhang,
>
> On Wed, Jan 28, 2015 at 04:46:33PM +0800, Lyra Zhang wrote:
>> On Wed, Jan 28, 2015 at 2:12 PM, Baruch Siach  wrote:
>> > On Wed, Jan 28, 2015 at 10:47:41AM +0800, Chunyan Zhang wrote:
>> >> + if (uart_handle_sysrq_char(port, ch))
>> >> + continue;
>> >
>> > My comment[1] on a previous version of this patch still stands.
>> > uart_handle_sysrq_char is a NOP when SUPPORT_SYSRQ is not defined.
>>
>> yes, there are two definitions in serial_core.h, and it returns 0 when
>> SUPPORT_SYSRQ is not defined.
>> so, I think my code behavior does not hurt, right?
>
> Right. I just wanted to point out that you can easily define SUPPORT_SYSRQ as
> appropriate like many other serial drivers do to get sysrq support.
>

Ok, I got it. I'll add SUPPORT_SYSRQ definition, and send v10 to Greg.

thanks,
Chunyan

> baruch
>
> --
>  http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
> =}ooO--U--Ooo{=
>- bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

2015-01-28 Thread Baruch Siach
Hi Lyra Zhang,

On Wed, Jan 28, 2015 at 04:46:33PM +0800, Lyra Zhang wrote:
> On Wed, Jan 28, 2015 at 2:12 PM, Baruch Siach  wrote:
> > On Wed, Jan 28, 2015 at 10:47:41AM +0800, Chunyan Zhang wrote:
> >> + if (uart_handle_sysrq_char(port, ch))
> >> + continue;
> >
> > My comment[1] on a previous version of this patch still stands.
> > uart_handle_sysrq_char is a NOP when SUPPORT_SYSRQ is not defined.
> 
> yes, there are two definitions in serial_core.h, and it returns 0 when
> SUPPORT_SYSRQ is not defined.
> so, I think my code behavior does not hurt, right?

Right. I just wanted to point out that you can easily define SUPPORT_SYSRQ as 
appropriate like many other serial drivers do to get sysrq support.

baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

2015-01-27 Thread Baruch Siach
Hi Chunyan Zhang,

On Wed, Jan 28, 2015 at 10:47:41AM +0800, Chunyan Zhang wrote:
[...]
> +static inline void sprd_rx(struct uart_port *port)
> +{
> + struct tty_port *tty = &port->state->port;
> + unsigned int ch, flag, lsr, max_count = SPRD_TIMEOUT;
> +
> + while ((serial_in(port, SPRD_STS1) & 0x00ff) && max_count--) {
> + lsr = serial_in(port, SPRD_LSR);
> + ch = serial_in(port, SPRD_RXD);
> + flag = TTY_NORMAL;
> + port->icount.rx++;
> +
> + if (lsr & (SPRD_LSR_BI | SPRD_LSR_PE |
> + SPRD_LSR_FE | SPRD_LSR_OE))
> + if (handle_lsr_errors(port, &lsr, &flag))
> + continue;
> + if (uart_handle_sysrq_char(port, ch))
> + continue;

My comment[1] on a previous version of this patch still stands. 
uart_handle_sysrq_char is a NOP when SUPPORT_SYSRQ is not defined.

> +
> + uart_insert_char(port, lsr, SPRD_LSR_OE, ch, flag);
> + }
> +
> + tty_flip_buffer_push(tty);
> +}

[...]

> +static void sprd_console_write(struct console *co, const char *s,
> +   unsigned int count)
> +{
> + struct uart_port *port = &sprd_port[co->index]->port;
> + int locked = 1;
> + unsigned long flags;
> +
> + if (port->sysrq)
> + locked = 0;

The sysrq field of struct uart_port is only defined when 
CONFIG_SERIAL_CORE_CONSOLE or SUPPORT_SYSRQ are defined. You should #ifdef 
this part accordingly to avoid build breakage.

> + else if (oops_in_progress)
> + locked = spin_trylock_irqsave(&port->lock, flags);
> + else
> + spin_lock_irqsave(&port->lock, flags);
> +
> + uart_console_write(port, s, count, sprd_console_putchar);
> +
> + /* wait for transmitter to become empty */
> + wait_for_xmitr(port);
> +
> + if (locked)
> + spin_unlock_irqrestore(&port->lock, flags);
> +}

[1]
http://article.gmane.org/gmane.linux.drivers.devicetree/106483

baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

2015-01-27 Thread Peter Hurley
On 01/27/2015 09:47 PM, Chunyan Zhang wrote:
> Add a full sc9836-uart driver for SC9836 SoC which is based on the
> spreadtrum sharkl64 platform.
> This driver also support earlycon.

Reviewed-by: Peter Hurley 


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 2/2] tty/serial: Add Spreadtrum sc9836-uart driver support

2015-01-27 Thread Chunyan Zhang
Add a full sc9836-uart driver for SC9836 SoC which is based on the
spreadtrum sharkl64 platform.
This driver also support earlycon.

Originally-by: Lanqing Liu 
Signed-off-by: Orson Zhai 
Signed-off-by: Chunyan Zhang 
Acked-by: Arnd Bergmann 
---
 drivers/tty/serial/Kconfig   |   18 +
 drivers/tty/serial/Makefile  |1 +
 drivers/tty/serial/sprd_serial.c |  789 ++
 include/uapi/linux/serial_core.h |3 +
 4 files changed, 811 insertions(+)
 create mode 100644 drivers/tty/serial/sprd_serial.c

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index c79b43c..13211f7 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1577,6 +1577,24 @@ config SERIAL_MEN_Z135
  This driver can also be build as a module. If so, the module will be 
called
  men_z135_uart.ko
 
+config SERIAL_SPRD
+   tristate "Support for Spreadtrum serial"
+   depends on ARCH_SPRD
+   select SERIAL_CORE
+   help
+ This enables the driver for the Spreadtrum's serial.
+
+config SERIAL_SPRD_CONSOLE
+   bool "Spreadtrum UART console support"
+   depends on SERIAL_SPRD=y
+   select SERIAL_CORE_CONSOLE
+   select SERIAL_EARLYCON
+   help
+ Support for early debug console using Spreadtrum's serial. This 
enables
+ the console before standard serial driver is probed. This is enabled
+ with "earlycon" on the kernel command line. The console is
+ enabled when early_param is processed.
+
 endmenu
 
 config SERIAL_MCTRL_GPIO
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index 9a548ac..4801aca 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -93,6 +93,7 @@ obj-$(CONFIG_SERIAL_ARC)  += arc_uart.o
 obj-$(CONFIG_SERIAL_RP2)   += rp2.o
 obj-$(CONFIG_SERIAL_FSL_LPUART)+= fsl_lpuart.o
 obj-$(CONFIG_SERIAL_MEN_Z135)  += men_z135_uart.o
+obj-$(CONFIG_SERIAL_SPRD) += sprd_serial.o
 
 # GPIOLIB helpers for modem control lines
 obj-$(CONFIG_SERIAL_MCTRL_GPIO)+= serial_mctrl_gpio.o
diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
new file mode 100644
index 000..a08a57f
--- /dev/null
+++ b/drivers/tty/serial/sprd_serial.c
@@ -0,0 +1,789 @@
+/*
+ * Copyright (C) 2012-2015 Spreadtrum Communications Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* device name */
+#define UART_NR_MAX8
+#define SPRD_TTY_NAME  "ttyS"
+#define SPRD_FIFO_SIZE 128
+#define SPRD_DEF_RATE  2600
+#define SPRD_BAUD_IO_LIMIT 300
+#define SPRD_TIMEOUT   256
+
+/* the offset of serial registers and BITs for them */
+/* data registers */
+#define SPRD_TXD   0x
+#define SPRD_RXD   0x0004
+
+/* line status register and its BITs  */
+#define SPRD_LSR   0x0008
+#define SPRD_LSR_OEBIT(4)
+#define SPRD_LSR_FEBIT(3)
+#define SPRD_LSR_PEBIT(2)
+#define SPRD_LSR_BIBIT(7)
+#define SPRD_LSR_TX_OVER   BIT(15)
+
+/* data number in TX and RX fifo */
+#define SPRD_STS1  0x000C
+
+/* interrupt enable register and its BITs */
+#define SPRD_IEN   0x0010
+#define SPRD_IEN_RX_FULL   BIT(0)
+#define SPRD_IEN_TX_EMPTY  BIT(1)
+#define SPRD_IEN_BREAK_DETECT  BIT(7)
+#define SPRD_IEN_TIMEOUT   BIT(13)
+
+/* interrupt clear register */
+#define SPRD_ICLR  0x0014
+
+/* line control register */
+#define SPRD_LCR   0x0018
+#define SPRD_LCR_STOP_1BIT 0x10
+#define SPRD_LCR_STOP_2BIT 0x30
+#define SPRD_LCR_DATA_LEN  (BIT(2) | BIT(3))
+#define SPRD_LCR_DATA_LEN5 0x0
+#define SPRD_LCR_DATA_LEN6 0x4
+#define SPRD_LCR_DATA_LEN7 0x8
+#define SPRD_LCR_DATA_LEN8 0xc
+#define SPRD_LCR_PARITY(BIT(0) | BIT(1))
+#define SPRD_LCR_PARITY_EN 0x2
+#define SPRD_LCR_EVEN_PAR  0x0
+#define SPRD_LCR_ODD_PAR   0x1
+
+/* control register 1 */
+#define SPRD_CTL1  0x001C
+#define RX_HW_FLOW_CTL_THLDBIT(6)
+#define RX_HW_FLOW_CTL_EN  BIT(7)
+#define TX_HW_FLOW_CTL_EN  BIT(8)
+#define RX_TOUT_THLD_DEF   0x3E00
+#define RX_HFC_THLD_DEF0x40
+
+/* fifo threshold register */
+#define SPRD_CTL2  0x0020
+#define THLD_TX_EMPTY  0x40
+#define THLD_RX_FULL   0x40
+
+/* config baud rate reg