All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Ferre <nicolas.ferre@atmel.com>
To: Richard Genoud <noreply.rgenoud@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Alexander Shiyan" <shc_work@mail.ru>,
	linux-serial@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	"Richard Genoud" <richard.genoud@gmail.com>
Subject: Re: [PATCH v6 3/3] tty/serial: at91: add interrupts for modem control lines
Date: Mon, 10 Mar 2014 18:21:04 +0100	[thread overview]
Message-ID: <531DF480.7090706@atmel.com> (raw)
In-Reply-To: <1394469951-21192-4-git-send-email-richard.genoud@gmail.com>

On 10/03/2014 17:45, Richard Genoud :
> Handle CTS/DSR/RI/DCD GPIO interrupts in atmel_serial.
> 
> Signed-off-by: Richard Genoud <richard.genoud@gmail.com>

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Thanks Richard.

> ---
>  drivers/tty/serial/atmel_serial.c | 125 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 122 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index 43ca659c1d4b..3fceae099c44 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -45,6 +45,7 @@
>  #include <linux/gpio.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/err.h>
> +#include <linux/irq.h>
>  
>  #include <asm/io.h>
>  #include <asm/ioctls.h>
> @@ -167,7 +168,9 @@ struct atmel_uart_port {
>  
>  	struct serial_rs485	rs485;		/* rs485 settings */
>  	struct mctrl_gpios	*gpios;
> +	int			gpio_irq[UART_GPIO_MAX];
>  	unsigned int		tx_done_mask;
> +	bool			ms_irq_enabled;
>  	bool			is_usart;	/* usart or uart */
>  	struct timer_list	uart_timer;	/* uart timer */
>  	int (*prepare_rx)(struct uart_port *port);
> @@ -489,8 +492,38 @@ static void atmel_stop_rx(struct uart_port *port)
>   */
>  static void atmel_enable_ms(struct uart_port *port)
>  {
> -	UART_PUT_IER(port, ATMEL_US_RIIC | ATMEL_US_DSRIC
> -			| ATMEL_US_DCDIC | ATMEL_US_CTSIC);
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> +	uint32_t ier = 0;
> +
> +	/*
> +	 * Interrupt should not be enabled twice
> +	 */
> +	if (atmel_port->ms_irq_enabled)
> +		return;
> +
> +	atmel_port->ms_irq_enabled = true;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_CTS] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_CTS]);
> +	else
> +		ier |= ATMEL_US_CTSIC;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_DSR] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_DSR]);
> +	else
> +		ier |= ATMEL_US_DSRIC;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_RI] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_RI]);
> +	else
> +		ier |= ATMEL_US_RIIC;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_DCD] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_DCD]);
> +	else
> +		ier |= ATMEL_US_DCDIC;
> +
> +	UART_PUT_IER(port, ier);
>  }
>  
>  /*
> @@ -1079,11 +1112,31 @@ atmel_handle_status(struct uart_port *port, unsigned int pending,
>  static irqreturn_t atmel_interrupt(int irq, void *dev_id)
>  {
>  	struct uart_port *port = dev_id;
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
>  	unsigned int status, pending, pass_counter = 0;
> +	bool gpio_handled = false;
>  
>  	do {
>  		status = atmel_get_lines_status(port);
>  		pending = status & UART_GET_IMR(port);
> +		if (!gpio_handled) {
> +			/*
> +			 * Dealing with GPIO interrupt
> +			 */
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_CTS])
> +				pending |= ATMEL_US_CTSIC;
> +
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_DSR])
> +				pending |= ATMEL_US_DSRIC;
> +
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_RI])
> +				pending |= ATMEL_US_RIIC;
> +
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_DCD])
> +				pending |= ATMEL_US_DCDIC;
> +
> +			gpio_handled = true;
> +		}
>  		if (!pending)
>  			break;
>  
> @@ -1563,6 +1616,45 @@ static void atmel_get_ip_name(struct uart_port *port)
>  	}
>  }
>  
> +static void atmel_free_gpio_irq(struct uart_port *port)
> +{
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> +	enum mctrl_gpio_idx i;
> +
> +	for (i = 0; i < UART_GPIO_MAX; i++)
> +		if (atmel_port->gpio_irq[i] >= 0)
> +			free_irq(atmel_port->gpio_irq[i], port);
> +}
> +
> +static int atmel_request_gpio_irq(struct uart_port *port)
> +{
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> +	int *irq = atmel_port->gpio_irq;
> +	enum mctrl_gpio_idx i;
> +	int err = 0;
> +
> +	for (i = 0; (i < UART_GPIO_MAX) && !err; i++) {
> +		if (irq[i] < 0)
> +			continue;
> +
> +		irq_set_status_flags(irq[i], IRQ_NOAUTOEN);
> +		err = request_irq(irq[i], atmel_interrupt, IRQ_TYPE_EDGE_BOTH,
> +				  "atmel_serial", port);
> +		if (err)
> +			dev_err(port->dev, "atmel_startup - Can't get %d irq\n",
> +				irq[i]);
> +	}
> +
> +	/*
> +	 * If something went wrong, rollback.
> +	 */
> +	while (err && (--i >= 0))
> +		if (irq[i] >= 0)
> +			free_irq(irq[i], port);
> +
> +	return err;
> +}
> +
>  /*
>   * Perform initialization and enable port for reception
>   */
> @@ -1579,6 +1671,7 @@ static int atmel_startup(struct uart_port *port)
>  	 * handle an unexpected interrupt
>  	 */
>  	UART_PUT_IDR(port, -1);
> +	atmel_port->ms_irq_enabled = false;
>  
>  	/*
>  	 * Allocate the IRQ
> @@ -1591,6 +1684,13 @@ static int atmel_startup(struct uart_port *port)
>  	}
>  
>  	/*
> +	 * Get the GPIO lines IRQ
> +	 */
> +	retval = atmel_request_gpio_irq(port);
> +	if (retval)
> +		goto free_irq;
> +
> +	/*
>  	 * Initialize DMA (if necessary)
>  	 */
>  	atmel_init_property(atmel_port, pdev);
> @@ -1654,6 +1754,11 @@ static int atmel_startup(struct uart_port *port)
>  	}
>  
>  	return 0;
> +
> +free_irq:
> +	free_irq(port->irq, port);
> +
> +	return retval;
>  }
>  
>  /*
> @@ -1701,9 +1806,12 @@ static void atmel_shutdown(struct uart_port *port)
>  	atmel_port->rx_ring.tail = 0;
>  
>  	/*
> -	 * Free the interrupt
> +	 * Free the interrupts
>  	 */
>  	free_irq(port->irq, port);
> +	atmel_free_gpio_irq(port);
> +
> +	atmel_port->ms_irq_enabled = false;
>  }
>  
>  /*
> @@ -2366,10 +2474,21 @@ static int atmel_serial_resume(struct platform_device *pdev)
>  
>  static int atmel_init_gpios(struct atmel_uart_port *p, struct device *dev)
>  {
> +	enum mctrl_gpio_idx i;
> +	struct gpio_desc *gpiod;
> +
>  	p->gpios = mctrl_gpio_init(dev, 0);
>  	if (IS_ERR_OR_NULL(p->gpios))
>  		return -1;
>  
> +	for (i = 0; i < UART_GPIO_MAX; i++) {
> +		gpiod = mctrl_gpio_to_gpiod(p->gpios, i);
> +		if (gpiod && (gpiod_get_direction(gpiod) == GPIOF_DIR_IN))
> +			p->gpio_irq[i] = gpiod_to_irq(gpiod);
> +		else
> +			p->gpio_irq[i] = -EINVAL;
> +	}
> +
>  	return 0;
>  }
>  
> 


-- 
Nicolas Ferre

WARNING: multiple messages have this Message-ID (diff)
From: nicolas.ferre@atmel.com (Nicolas Ferre)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 3/3] tty/serial: at91: add interrupts for modem control lines
Date: Mon, 10 Mar 2014 18:21:04 +0100	[thread overview]
Message-ID: <531DF480.7090706@atmel.com> (raw)
In-Reply-To: <1394469951-21192-4-git-send-email-richard.genoud@gmail.com>

On 10/03/2014 17:45, Richard Genoud :
> Handle CTS/DSR/RI/DCD GPIO interrupts in atmel_serial.
> 
> Signed-off-by: Richard Genoud <richard.genoud@gmail.com>

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Thanks Richard.

> ---
>  drivers/tty/serial/atmel_serial.c | 125 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 122 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index 43ca659c1d4b..3fceae099c44 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -45,6 +45,7 @@
>  #include <linux/gpio.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/err.h>
> +#include <linux/irq.h>
>  
>  #include <asm/io.h>
>  #include <asm/ioctls.h>
> @@ -167,7 +168,9 @@ struct atmel_uart_port {
>  
>  	struct serial_rs485	rs485;		/* rs485 settings */
>  	struct mctrl_gpios	*gpios;
> +	int			gpio_irq[UART_GPIO_MAX];
>  	unsigned int		tx_done_mask;
> +	bool			ms_irq_enabled;
>  	bool			is_usart;	/* usart or uart */
>  	struct timer_list	uart_timer;	/* uart timer */
>  	int (*prepare_rx)(struct uart_port *port);
> @@ -489,8 +492,38 @@ static void atmel_stop_rx(struct uart_port *port)
>   */
>  static void atmel_enable_ms(struct uart_port *port)
>  {
> -	UART_PUT_IER(port, ATMEL_US_RIIC | ATMEL_US_DSRIC
> -			| ATMEL_US_DCDIC | ATMEL_US_CTSIC);
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> +	uint32_t ier = 0;
> +
> +	/*
> +	 * Interrupt should not be enabled twice
> +	 */
> +	if (atmel_port->ms_irq_enabled)
> +		return;
> +
> +	atmel_port->ms_irq_enabled = true;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_CTS] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_CTS]);
> +	else
> +		ier |= ATMEL_US_CTSIC;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_DSR] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_DSR]);
> +	else
> +		ier |= ATMEL_US_DSRIC;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_RI] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_RI]);
> +	else
> +		ier |= ATMEL_US_RIIC;
> +
> +	if (atmel_port->gpio_irq[UART_GPIO_DCD] >= 0)
> +		enable_irq(atmel_port->gpio_irq[UART_GPIO_DCD]);
> +	else
> +		ier |= ATMEL_US_DCDIC;
> +
> +	UART_PUT_IER(port, ier);
>  }
>  
>  /*
> @@ -1079,11 +1112,31 @@ atmel_handle_status(struct uart_port *port, unsigned int pending,
>  static irqreturn_t atmel_interrupt(int irq, void *dev_id)
>  {
>  	struct uart_port *port = dev_id;
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
>  	unsigned int status, pending, pass_counter = 0;
> +	bool gpio_handled = false;
>  
>  	do {
>  		status = atmel_get_lines_status(port);
>  		pending = status & UART_GET_IMR(port);
> +		if (!gpio_handled) {
> +			/*
> +			 * Dealing with GPIO interrupt
> +			 */
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_CTS])
> +				pending |= ATMEL_US_CTSIC;
> +
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_DSR])
> +				pending |= ATMEL_US_DSRIC;
> +
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_RI])
> +				pending |= ATMEL_US_RIIC;
> +
> +			if (irq == atmel_port->gpio_irq[UART_GPIO_DCD])
> +				pending |= ATMEL_US_DCDIC;
> +
> +			gpio_handled = true;
> +		}
>  		if (!pending)
>  			break;
>  
> @@ -1563,6 +1616,45 @@ static void atmel_get_ip_name(struct uart_port *port)
>  	}
>  }
>  
> +static void atmel_free_gpio_irq(struct uart_port *port)
> +{
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> +	enum mctrl_gpio_idx i;
> +
> +	for (i = 0; i < UART_GPIO_MAX; i++)
> +		if (atmel_port->gpio_irq[i] >= 0)
> +			free_irq(atmel_port->gpio_irq[i], port);
> +}
> +
> +static int atmel_request_gpio_irq(struct uart_port *port)
> +{
> +	struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> +	int *irq = atmel_port->gpio_irq;
> +	enum mctrl_gpio_idx i;
> +	int err = 0;
> +
> +	for (i = 0; (i < UART_GPIO_MAX) && !err; i++) {
> +		if (irq[i] < 0)
> +			continue;
> +
> +		irq_set_status_flags(irq[i], IRQ_NOAUTOEN);
> +		err = request_irq(irq[i], atmel_interrupt, IRQ_TYPE_EDGE_BOTH,
> +				  "atmel_serial", port);
> +		if (err)
> +			dev_err(port->dev, "atmel_startup - Can't get %d irq\n",
> +				irq[i]);
> +	}
> +
> +	/*
> +	 * If something went wrong, rollback.
> +	 */
> +	while (err && (--i >= 0))
> +		if (irq[i] >= 0)
> +			free_irq(irq[i], port);
> +
> +	return err;
> +}
> +
>  /*
>   * Perform initialization and enable port for reception
>   */
> @@ -1579,6 +1671,7 @@ static int atmel_startup(struct uart_port *port)
>  	 * handle an unexpected interrupt
>  	 */
>  	UART_PUT_IDR(port, -1);
> +	atmel_port->ms_irq_enabled = false;
>  
>  	/*
>  	 * Allocate the IRQ
> @@ -1591,6 +1684,13 @@ static int atmel_startup(struct uart_port *port)
>  	}
>  
>  	/*
> +	 * Get the GPIO lines IRQ
> +	 */
> +	retval = atmel_request_gpio_irq(port);
> +	if (retval)
> +		goto free_irq;
> +
> +	/*
>  	 * Initialize DMA (if necessary)
>  	 */
>  	atmel_init_property(atmel_port, pdev);
> @@ -1654,6 +1754,11 @@ static int atmel_startup(struct uart_port *port)
>  	}
>  
>  	return 0;
> +
> +free_irq:
> +	free_irq(port->irq, port);
> +
> +	return retval;
>  }
>  
>  /*
> @@ -1701,9 +1806,12 @@ static void atmel_shutdown(struct uart_port *port)
>  	atmel_port->rx_ring.tail = 0;
>  
>  	/*
> -	 * Free the interrupt
> +	 * Free the interrupts
>  	 */
>  	free_irq(port->irq, port);
> +	atmel_free_gpio_irq(port);
> +
> +	atmel_port->ms_irq_enabled = false;
>  }
>  
>  /*
> @@ -2366,10 +2474,21 @@ static int atmel_serial_resume(struct platform_device *pdev)
>  
>  static int atmel_init_gpios(struct atmel_uart_port *p, struct device *dev)
>  {
> +	enum mctrl_gpio_idx i;
> +	struct gpio_desc *gpiod;
> +
>  	p->gpios = mctrl_gpio_init(dev, 0);
>  	if (IS_ERR_OR_NULL(p->gpios))
>  		return -1;
>  
> +	for (i = 0; i < UART_GPIO_MAX; i++) {
> +		gpiod = mctrl_gpio_to_gpiod(p->gpios, i);
> +		if (gpiod && (gpiod_get_direction(gpiod) == GPIOF_DIR_IN))
> +			p->gpio_irq[i] = gpiod_to_irq(gpiod);
> +		else
> +			p->gpio_irq[i] = -EINVAL;
> +	}
> +
>  	return 0;
>  }
>  
> 


-- 
Nicolas Ferre

  reply	other threads:[~2014-03-10 17:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 16:45 [PATCH v6 0/3] tty/serial: Add helpers to use GPIOs to control modem lines and implement atmel_serial.c Richard Genoud
2014-03-10 16:45 ` Richard Genoud
2014-03-10 16:45 ` [PATCH v6 1/3] tty/serial: Add GPIOLIB helpers for controlling modem lines Richard Genoud
2014-03-10 16:45   ` Richard Genoud
2014-03-17 23:23   ` Greg Kroah-Hartman
2014-03-17 23:23     ` Greg Kroah-Hartman
2014-03-18 10:13     ` Richard Genoud
2014-03-18 10:13       ` Richard Genoud
2014-03-22 10:14       ` Richard Genoud
2014-03-22 10:14         ` Richard Genoud
2014-04-02 15:09     ` Richard Genoud
2014-04-02 15:09       ` Richard Genoud
2014-04-02 23:13       ` Greg Kroah-Hartman
2014-04-02 23:13         ` Greg Kroah-Hartman
2014-04-03  9:35         ` Richard Genoud
2014-04-03  9:35           ` Richard Genoud
2014-04-22 13:08   ` Yegor Yefremov
2014-04-22 13:08     ` Yegor Yefremov
2014-04-25 14:56     ` Richard Genoud
2014-04-25 14:56       ` Richard Genoud
2014-04-25 18:37       ` Yegor Yefremov
2014-04-25 18:37         ` Yegor Yefremov
2014-03-10 16:45 ` [PATCH v6 2/3] tty/serial: at91: use mctrl_gpio helpers Richard Genoud
2014-03-10 16:45   ` Richard Genoud
2014-03-10 17:20   ` Nicolas Ferre
2014-03-10 17:20     ` Nicolas Ferre
2014-03-10 16:45 ` [PATCH v6 3/3] tty/serial: at91: add interrupts for modem control lines Richard Genoud
2014-03-10 16:45   ` Richard Genoud
2014-03-10 17:21   ` Nicolas Ferre [this message]
2014-03-10 17:21     ` Nicolas Ferre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=531DF480.7090706@atmel.com \
    --to=nicolas.ferre@atmel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=noreply.rgenoud@gmail.com \
    --cc=richard.genoud@gmail.com \
    --cc=shc_work@mail.ru \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.