linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled()
@ 2022-08-06 22:56 Andy Shevchenko
  2022-08-06 22:56 ` [PATCH v1 2/2] serial: pic32_uart: Convert to use GPIO descriptors Andy Shevchenko
  2022-08-10  8:26 ` [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled() Ilpo Järvinen
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-08-06 22:56 UTC (permalink / raw)
  To: Jiri Slaby, Greg Kroah-Hartman, linux-serial, linux-kernel
  Cc: Andy Shevchenko

The serial core already provides a helper to check if the given port
is an enabled console. Utilize it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/pic32_uart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c
index f418f1de66b3..1562c2a48467 100644
--- a/drivers/tty/serial/pic32_uart.c
+++ b/drivers/tty/serial/pic32_uart.c
@@ -943,7 +943,7 @@ static int pic32_uart_probe(struct platform_device *pdev)
 	}
 
 #ifdef CONFIG_SERIAL_PIC32_CONSOLE
-	if (uart_console(port) && (pic32_console.flags & CON_ENABLED)) {
+	if (uart_console_enabled(port)) {
 		/* The peripheral clock has been enabled by console_setup,
 		 * so disable it till the port is used.
 		 */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] serial: pic32_uart: Convert to use GPIO descriptors
  2022-08-06 22:56 [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled() Andy Shevchenko
@ 2022-08-06 22:56 ` Andy Shevchenko
  2022-08-10  8:26 ` [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled() Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-08-06 22:56 UTC (permalink / raw)
  To: Jiri Slaby, Greg Kroah-Hartman, linux-serial, linux-kernel
  Cc: Andy Shevchenko

Plain global GPIO numbering schema is deprecated and is being removed
from the kernel. Convert this driver to use a new GPIO descriptor based
schema.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/pic32_uart.c | 48 +++++++++------------------------
 1 file changed, 12 insertions(+), 36 deletions(-)

diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c
index 1562c2a48467..56516a72d661 100644
--- a/drivers/tty/serial/pic32_uart.c
+++ b/drivers/tty/serial/pic32_uart.c
@@ -50,7 +50,7 @@
  * @irq_rx_name: irq rx name
  * @irq_tx: virtual tx interrupt number
  * @irq_tx_name: irq tx name
- * @cts_gpio: clear to send gpio
+ * @cts_gpiod: clear to send GPIO
  * @dev: device descriptor
  **/
 struct pic32_sport {
@@ -65,8 +65,7 @@ struct pic32_sport {
 	const char *irq_tx_name;
 	bool enable_tx_irq;
 
-	bool hw_flow_ctrl;
-	int cts_gpio;
+	struct gpio_desc *cts_gpiod;
 
 	struct clk *clk;
 
@@ -158,25 +157,16 @@ static void pic32_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
 					PIC32_UART_MODE_LPBK);
 }
 
-/* get the state of CTS input pin for this port */
-static unsigned int get_cts_state(struct pic32_sport *sport)
-{
-	/* read and invert UxCTS */
-	if (gpio_is_valid(sport->cts_gpio))
-		return !gpio_get_value(sport->cts_gpio);
-
-	return 1;
-}
-
 /* serial core request to return the state of misc UART input pins */
 static unsigned int pic32_uart_get_mctrl(struct uart_port *port)
 {
 	struct pic32_sport *sport = to_pic32_sport(port);
 	unsigned int mctrl = 0;
 
-	if (!sport->hw_flow_ctrl)
+	/* get the state of CTS input pin for this port */
+	if (!sport->cts_gpiod)
 		mctrl |= TIOCM_CTS;
-	else if (get_cts_state(sport))
+	else if (gpiod_get_value(sport->cts_gpiod))
 		mctrl |= TIOCM_CTS;
 
 	/* DSR and CD are not supported in PIC32, so return 1
@@ -648,7 +638,7 @@ static void pic32_uart_set_termios(struct uart_port *port,
 					PIC32_UART_MODE_PDSEL0);
 	}
 	/* if hw flow ctrl, then the pins must be specified in device tree */
-	if ((new->c_cflag & CRTSCTS) && sport->hw_flow_ctrl) {
+	if ((new->c_cflag & CRTSCTS) && sport->cts_gpiod) {
 		/* enable hardware flow control */
 		pic32_uart_writel(sport, PIC32_SET(PIC32_UART_MODE),
 					PIC32_UART_MODE_UEN1);
@@ -875,7 +865,8 @@ static struct uart_driver pic32_uart_driver = {
 
 static int pic32_uart_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
 	struct pic32_sport *sport;
 	int uart_idx = 0;
 	struct resource *res_mem;
@@ -904,25 +895,10 @@ static int pic32_uart_probe(struct platform_device *pdev)
 	/* Hardware flow control: gpios
 	 * !Note: Basically, CTS is needed for reading the status.
 	 */
-	sport->hw_flow_ctrl = false;
-	sport->cts_gpio = of_get_named_gpio(np, "cts-gpios", 0);
-	if (gpio_is_valid(sport->cts_gpio)) {
-		sport->hw_flow_ctrl = true;
-
-		ret = devm_gpio_request(sport->dev,
-					sport->cts_gpio, "CTS");
-		if (ret) {
-			dev_err(&pdev->dev,
-				"error requesting CTS GPIO\n");
-			goto err;
-		}
-
-		ret = gpio_direction_input(sport->cts_gpio);
-		if (ret) {
-			dev_err(&pdev->dev, "error setting CTS GPIO\n");
-			goto err;
-		}
-	}
+	sport->cts_gpiod = devm_gpiod_get_optional(dev, "cts", GPIOD_IN);
+	if (IS_ERR(sport->cts_gpiod))
+		return dev_err_probe(dev, PTR_ERR(sport->cts_gpiod), "error requesting CTS GPIO\n");
+	gpiod_set_consumer_name(sport->cts_gpiod, "CTS");
 
 	pic32_sports[uart_idx] = sport;
 	port = &sport->port;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled()
  2022-08-06 22:56 [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled() Andy Shevchenko
  2022-08-06 22:56 ` [PATCH v1 2/2] serial: pic32_uart: Convert to use GPIO descriptors Andy Shevchenko
@ 2022-08-10  8:26 ` Ilpo Järvinen
  1 sibling, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2022-08-10  8:26 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jiri Slaby, Greg Kroah-Hartman, linux-serial, LKML

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

On Sun, 7 Aug 2022, Andy Shevchenko wrote:

> The serial core already provides a helper to check if the given port
> is an enabled console. Utilize it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

> ---
>  drivers/tty/serial/pic32_uart.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c
> index f418f1de66b3..1562c2a48467 100644
> --- a/drivers/tty/serial/pic32_uart.c
> +++ b/drivers/tty/serial/pic32_uart.c
> @@ -943,7 +943,7 @@ static int pic32_uart_probe(struct platform_device *pdev)
>  	}
>  
>  #ifdef CONFIG_SERIAL_PIC32_CONSOLE
> -	if (uart_console(port) && (pic32_console.flags & CON_ENABLED)) {
> +	if (uart_console_enabled(port)) {
>  		/* The peripheral clock has been enabled by console_setup,
>  		 * so disable it till the port is used.
>  		 */
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-10  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-06 22:56 [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled() Andy Shevchenko
2022-08-06 22:56 ` [PATCH v1 2/2] serial: pic32_uart: Convert to use GPIO descriptors Andy Shevchenko
2022-08-10  8:26 ` [PATCH v1 1/2] serial: pic32_uart: Utilize uart_console_enabled() Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).