diff mbox

ARM/serial: at91: specify RTS in DT using gpio

Message ID 1383665383-5606-1-git-send-email-nicolas.ferre@atmel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nicolas Ferre Nov. 5, 2013, 3:29 p.m. UTC
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 Documentation/devicetree/bindings/serial/atmel-usart.txt |  3 +++
 drivers/tty/serial/atmel_serial.c                        | 13 ++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

Comments

Jean-Christophe PLAGNIOL-VILLARD Nov. 5, 2013, 3:59 p.m. UTC | #1
On Nov 5, 2013, at 11:29 PM, Nicolas Ferre <nicolas.ferre@atmel.com> wrote:

> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> ---
> Documentation/devicetree/bindings/serial/atmel-usart.txt |  3 +++
> drivers/tty/serial/atmel_serial.c                        | 13 ++++++++++---
> 2 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/serial/atmel-usart.txt b/Documentation/devicetree/bindings/serial/atmel-usart.txt
> index 2191dcb..3adc61c 100644
> --- a/Documentation/devicetree/bindings/serial/atmel-usart.txt
> +++ b/Documentation/devicetree/bindings/serial/atmel-usart.txt
> @@ -10,6 +10,8 @@ Required properties:
> Optional properties:
> - atmel,use-dma-rx: use of PDC or DMA for receiving data
> - atmel,use-dma-tx: use of PDC or DMA for transmitting data
> +- rts-gpios: specify a GPIO for RTS line. It will use specified PIO instead of the peripheral
> +  function pin for the USART RTS feature. If unsure, don't specify this property.
> - add dma bindings for dma transfer:
> 	- dmas: DMA specifier, consisting of a phandle to DMA controller node,
> 		memory peripheral interface and USART DMA channel ID, FIFO configuration.
> @@ -28,6 +30,7 @@ Example:
> 		interrupts = <7>;
> 		atmel,use-dma-rx;
> 		atmel,use-dma-tx;
> +		rts-gpios = <&pioD 15 0>;
> 	};

gpios means 2 gpio 

I’ll rts-gpio as we can only use one anyway



> 
> - use DMA:
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index b4e0794..71f8ea9 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -35,6 +35,7 @@
> #include <linux/platform_device.h>
> #include <linux/of.h>
> #include <linux/of_device.h>
> +#include <linux/of_gpio.h>
> #include <linux/dma-mapping.h>
> #include <linux/atmel_pdc.h>
> #include <linux/atmel_serial.h>
> @@ -2327,6 +2328,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
> 	struct device_node *np = pdev->dev.of_node;
> 	struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
> 	void *data;
> +	int rts_pin = -EINVAL;
> 	int ret = -ENODEV;
> 
> 	BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
> @@ -2364,13 +2366,18 @@ static int atmel_serial_probe(struct platform_device *pdev)
> 	 * structs to indicate "no RTS GPIO" instead of open-coding some
> 	 * invalid value everywhere.
> 	 */
> -	if (pdata->rts_gpio > 0) {
> -		ret = devm_gpio_request(&pdev->dev, pdata->rts_gpio, "RTS");
> +	if (pdata && pdata->rts_gpio > 0)
> +		rts_pin = pdata->rts_gpio;
> +	else if (np)
> +		rts_pin = of_get_named_gpio(np, "rts-gpios", 0);
> +

	use directly port->rts_gpio  so we can drop the assign after

	if the gpio is invalid the port->rts_gpio need to be < 0 too

Best Regards,
J.

> +	if (gpio_is_valid(rts_pin)) {
> +		ret = devm_gpio_request(&pdev->dev, rts_pin, "RTS");
> 		if (ret) {
> 			dev_err(&pdev->dev, "error requesting RTS GPIO\n");
> 			goto err;
> 		}
> -		port->rts_gpio = pdata->rts_gpio;
> +		port->rts_gpio = rts_pin;
> 		ret = gpio_direction_output(port->rts_gpio, 0);
> 		if (ret) {
> 			dev_err(&pdev->dev, "error setting up RTS GPIO\n");
> -- 
> 1.8.2.2
>
Andrew Lunn Nov. 5, 2013, 4:18 p.m. UTC | #2
On Tue, Nov 05, 2013 at 11:59:38PM +0800, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 
> On Nov 5, 2013, at 11:29 PM, Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> 
> > Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> > ---
> > Documentation/devicetree/bindings/serial/atmel-usart.txt |  3 +++
> > drivers/tty/serial/atmel_serial.c                        | 13 ++++++++++---
> > 2 files changed, 13 insertions(+), 3 deletions(-)
> > 
> > diff --git a/Documentation/devicetree/bindings/serial/atmel-usart.txt b/Documentation/devicetree/bindings/serial/atmel-usart.txt
> > index 2191dcb..3adc61c 100644
> > --- a/Documentation/devicetree/bindings/serial/atmel-usart.txt
> > +++ b/Documentation/devicetree/bindings/serial/atmel-usart.txt
> > @@ -10,6 +10,8 @@ Required properties:
> > Optional properties:
> > - atmel,use-dma-rx: use of PDC or DMA for receiving data
> > - atmel,use-dma-tx: use of PDC or DMA for transmitting data
> > +- rts-gpios: specify a GPIO for RTS line. It will use specified PIO instead of the peripheral
> > +  function pin for the USART RTS feature. If unsure, don't specify this property.
> > - add dma bindings for dma transfer:
> > 	- dmas: DMA specifier, consisting of a phandle to DMA controller node,
> > 		memory peripheral interface and USART DMA channel ID, FIFO configuration.
> > @@ -28,6 +30,7 @@ Example:
> > 		interrupts = <7>;
> > 		atmel,use-dma-rx;
> > 		atmel,use-dma-tx;
> > +		rts-gpios = <&pioD 15 0>;
> > 	};
> 
> gpios means 2 gpio 
> 
> I’ll rts-gpio as we can only use one anyway

Hi Jean

Have you read Documentation/devicetree/bindings/gpio/gpio.txt ?

It says:

GPIO properties should be named "[<name>-]gpios". Exact meaning of
each gpios property must be documented in the device tree binding for
each device.

There is also an example of a node with a single gpio using the
property name gpios. So plural is correct, even if there is only one
gpio.

	Andrew
Nicolas Ferre Nov. 5, 2013, 4:57 p.m. UTC | #3
On 05/11/2013 16:59, Jean-Christophe PLAGNIOL-VILLARD :
>
> On Nov 5, 2013, at 11:29 PM, Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
>
>> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
>> ---
>> Documentation/devicetree/bindings/serial/atmel-usart.txt |  3 +++
>> drivers/tty/serial/atmel_serial.c                        | 13 ++++++++++---
>> 2 files changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/serial/atmel-usart.txt b/Documentation/devicetree/bindings/serial/atmel-usart.txt
>> index 2191dcb..3adc61c 100644
>> --- a/Documentation/devicetree/bindings/serial/atmel-usart.txt
>> +++ b/Documentation/devicetree/bindings/serial/atmel-usart.txt
>> @@ -10,6 +10,8 @@ Required properties:
>> Optional properties:
>> - atmel,use-dma-rx: use of PDC or DMA for receiving data
>> - atmel,use-dma-tx: use of PDC or DMA for transmitting data
>> +- rts-gpios: specify a GPIO for RTS line. It will use specified PIO instead of the peripheral
>> +  function pin for the USART RTS feature. If unsure, don't specify this property.
>> - add dma bindings for dma transfer:
>> 	- dmas: DMA specifier, consisting of a phandle to DMA controller node,
>> 		memory peripheral interface and USART DMA channel ID, FIFO configuration.
>> @@ -28,6 +30,7 @@ Example:
>> 		interrupts = <7>;
>> 		atmel,use-dma-rx;
>> 		atmel,use-dma-tx;
>> +		rts-gpios = <&pioD 15 0>;
>> 	};
>
> gpios means 2 gpio
>
> I’ll rts-gpio as we can only use one anyway

Cf. Andrew's comment.


>> - use DMA:
>> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
>> index b4e0794..71f8ea9 100644
>> --- a/drivers/tty/serial/atmel_serial.c
>> +++ b/drivers/tty/serial/atmel_serial.c
>> @@ -35,6 +35,7 @@
>> #include <linux/platform_device.h>
>> #include <linux/of.h>
>> #include <linux/of_device.h>
>> +#include <linux/of_gpio.h>
>> #include <linux/dma-mapping.h>
>> #include <linux/atmel_pdc.h>
>> #include <linux/atmel_serial.h>
>> @@ -2327,6 +2328,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
>> 	struct device_node *np = pdev->dev.of_node;
>> 	struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
>> 	void *data;
>> +	int rts_pin = -EINVAL;
>> 	int ret = -ENODEV;
>>
>> 	BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
>> @@ -2364,13 +2366,18 @@ static int atmel_serial_probe(struct platform_device *pdev)
>> 	 * structs to indicate "no RTS GPIO" instead of open-coding some
>> 	 * invalid value everywhere.
>> 	 */
>> -	if (pdata->rts_gpio > 0) {
>> -		ret = devm_gpio_request(&pdev->dev, pdata->rts_gpio, "RTS");
>> +	if (pdata && pdata->rts_gpio > 0)
>> +		rts_pin = pdata->rts_gpio;
>> +	else if (np)
>> +		rts_pin = of_get_named_gpio(np, "rts-gpios", 0);
>> +
>
> 	use directly port->rts_gpio  so we can drop the assign after
>
> 	if the gpio is invalid the port->rts_gpio need to be < 0 too

Yes this is definitively an option. I cook a v2 right now.

>
> Best Regards,
> J.
>
>> +	if (gpio_is_valid(rts_pin)) {
>> +		ret = devm_gpio_request(&pdev->dev, rts_pin, "RTS");
>> 		if (ret) {
>> 			dev_err(&pdev->dev, "error requesting RTS GPIO\n");
>> 			goto err;
>> 		}
>> -		port->rts_gpio = pdata->rts_gpio;
>> +		port->rts_gpio = rts_pin;
>> 		ret = gpio_direction_output(port->rts_gpio, 0);
>> 		if (ret) {
>> 			dev_err(&pdev->dev, "error setting up RTS GPIO\n");
>> --
>> 1.8.2.2
>>
>
>
>
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/serial/atmel-usart.txt b/Documentation/devicetree/bindings/serial/atmel-usart.txt
index 2191dcb..3adc61c 100644
--- a/Documentation/devicetree/bindings/serial/atmel-usart.txt
+++ b/Documentation/devicetree/bindings/serial/atmel-usart.txt
@@ -10,6 +10,8 @@  Required properties:
 Optional properties:
 - atmel,use-dma-rx: use of PDC or DMA for receiving data
 - atmel,use-dma-tx: use of PDC or DMA for transmitting data
+- rts-gpios: specify a GPIO for RTS line. It will use specified PIO instead of the peripheral
+  function pin for the USART RTS feature. If unsure, don't specify this property.
 - add dma bindings for dma transfer:
 	- dmas: DMA specifier, consisting of a phandle to DMA controller node,
 		memory peripheral interface and USART DMA channel ID, FIFO configuration.
@@ -28,6 +30,7 @@  Example:
 		interrupts = <7>;
 		atmel,use-dma-rx;
 		atmel,use-dma-tx;
+		rts-gpios = <&pioD 15 0>;
 	};
 
 - use DMA:
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index b4e0794..71f8ea9 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -35,6 +35,7 @@ 
 #include <linux/platform_device.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/of_gpio.h>
 #include <linux/dma-mapping.h>
 #include <linux/atmel_pdc.h>
 #include <linux/atmel_serial.h>
@@ -2327,6 +2328,7 @@  static int atmel_serial_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
 	void *data;
+	int rts_pin = -EINVAL;
 	int ret = -ENODEV;
 
 	BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
@@ -2364,13 +2366,18 @@  static int atmel_serial_probe(struct platform_device *pdev)
 	 * structs to indicate "no RTS GPIO" instead of open-coding some
 	 * invalid value everywhere.
 	 */
-	if (pdata->rts_gpio > 0) {
-		ret = devm_gpio_request(&pdev->dev, pdata->rts_gpio, "RTS");
+	if (pdata && pdata->rts_gpio > 0)
+		rts_pin = pdata->rts_gpio;
+	else if (np)
+		rts_pin = of_get_named_gpio(np, "rts-gpios", 0);
+
+	if (gpio_is_valid(rts_pin)) {
+		ret = devm_gpio_request(&pdev->dev, rts_pin, "RTS");
 		if (ret) {
 			dev_err(&pdev->dev, "error requesting RTS GPIO\n");
 			goto err;
 		}
-		port->rts_gpio = pdata->rts_gpio;
+		port->rts_gpio = rts_pin;
 		ret = gpio_direction_output(port->rts_gpio, 0);
 		if (ret) {
 			dev_err(&pdev->dev, "error setting up RTS GPIO\n");