public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api
@ 2011-06-30 19:00 Grant Likely
  2011-06-30 20:57 ` Rob Herring
  2011-07-01 16:32 ` Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: Grant Likely @ 2011-06-30 19:00 UTC (permalink / raw)
  To: devicetree-discuss, Arnd Bergmann, linux-kernel, linux-serial,
	Alan Cox

Simplifies the code a bit and drops a few lines.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

I've only actually build tested this, but this shows some of the cleanup
achieved using the of_property_read_u32() API.  If this gets merged in the
v3.1 merge window then it will need to go via the devicetree/next branch.

g.

 drivers/tty/serial/of_serial.c |   37 +++++++++++++++----------------------
 1 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 36038ed..dbfbfda 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -32,17 +32,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
 {
 	struct resource resource;
 	struct device_node *np = ofdev->dev.of_node;
-	const __be32 *clk, *spd;
-	const __be32 *prop;
-	int ret, prop_size;
+	u32 clk, spd, prop;
+	int ret;
 
 	memset(port, 0, sizeof *port);
-	spd = of_get_property(np, "current-speed", NULL);
-	clk = of_get_property(np, "clock-frequency", NULL);
-	if (!clk) {
+	if (of_property_read_u32(np, "clock-frequency", &clk)) {
 		dev_warn(&ofdev->dev, "no clock-frequency property set\n");
 		return -ENODEV;
 	}
+	/* If current-speed was set, then try not to change it. */
+	if (of_property_read_u32(np, "current-speed", &spd) == 0)
+		port->custom_divisor = clk / (16 * spd);
 
 	ret = of_address_to_resource(np, 0, &resource);
 	if (ret) {
@@ -54,20 +54,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
 	port->mapbase = resource.start;
 
 	/* Check for shifted address mapping */
-	prop = of_get_property(np, "reg-offset", &prop_size);
-	if (prop && (prop_size == sizeof(u32)))
-		port->mapbase += be32_to_cpup(prop);
+	if (of_property_read_u32(np, "reg-offset", &prop) == 0)
+		port->mapbase += prop;
 
 	/* Check for registers offset within the devices address range */
-	prop = of_get_property(np, "reg-shift", &prop_size);
-	if (prop && (prop_size == sizeof(u32)))
-		port->regshift = be32_to_cpup(prop);
+	if (of_property_read_u32(np, "reg-shift", &prop) == 0)
+		port->regshift = prop;
 
 	port->irq = irq_of_parse_and_map(np, 0);
 	port->iotype = UPIO_MEM;
-	prop = of_get_property(np, "reg-io-width", &prop_size);
-	if (prop && (prop_size == sizeof(u32))) {
-		switch (be32_to_cpup(prop)) {
+	if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
+		switch (prop) {
 		case 1:
 			port->iotype = UPIO_MEM;
 			break;
@@ -75,21 +72,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
 			port->iotype = UPIO_MEM32;
 			break;
 		default:
-			dev_warn(&ofdev->dev,
-				 "unsupported io width (%d bytes)\n",
-				 be32_to_cpup(prop));
+			dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n",
+				 prop);
 			return -EINVAL;
 		}
 	}
 
 	port->type = type;
-	port->uartclk = be32_to_cpup(clk);
+	port->uartclk = clk;
 	port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
 		| UPF_FIXED_PORT | UPF_FIXED_TYPE;
 	port->dev = &ofdev->dev;
-	/* If current-speed was set, then try not to change it. */
-	if (spd)
-		port->custom_divisor = be32_to_cpup(clk) / (16 * (be32_to_cpup(spd)));
 
 	return 0;
 }


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

* Re: [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api
  2011-06-30 19:00 [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api Grant Likely
@ 2011-06-30 20:57 ` Rob Herring
  2011-06-30 21:01   ` Grant Likely
  2011-07-01 16:32 ` Arnd Bergmann
  1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring @ 2011-06-30 20:57 UTC (permalink / raw)
  To: Grant Likely
  Cc: devicetree-discuss, Arnd Bergmann, linux-kernel, linux-serial,
	Alan Cox

Grant,

On 06/30/2011 02:00 PM, Grant Likely wrote:
> Simplifies the code a bit and drops a few lines.
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> 
> I've only actually build tested this, but this shows some of the cleanup
> achieved using the of_property_read_u32() API.  If this gets merged in the
> v3.1 merge window then it will need to go via the devicetree/next branch.
> 
> g.

You can't give yourself bonus points. ;)

> 
>  drivers/tty/serial/of_serial.c |   37 +++++++++++++++----------------------
>  1 files changed, 15 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
> index 36038ed..dbfbfda 100644
> --- a/drivers/tty/serial/of_serial.c
> +++ b/drivers/tty/serial/of_serial.c
> @@ -32,17 +32,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
>  {
>  	struct resource resource;
>  	struct device_node *np = ofdev->dev.of_node;
> -	const __be32 *clk, *spd;
> -	const __be32 *prop;
> -	int ret, prop_size;
> +	u32 clk, spd, prop;
> +	int ret;
>  
>  	memset(port, 0, sizeof *port);
> -	spd = of_get_property(np, "current-speed", NULL);
> -	clk = of_get_property(np, "clock-frequency", NULL);
> -	if (!clk) {
> +	if (of_property_read_u32(np, "clock-frequency", &clk)) {

s/clk/port->uartclk/

And below, then remove clk.

>  		dev_warn(&ofdev->dev, "no clock-frequency property set\n");
>  		return -ENODEV;
>  	}
> +	/* If current-speed was set, then try not to change it. */
> +	if (of_property_read_u32(np, "current-speed", &spd) == 0)
> +		port->custom_divisor = clk / (16 * spd);
>  
>  	ret = of_address_to_resource(np, 0, &resource);
>  	if (ret) {
> @@ -54,20 +54,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
>  	port->mapbase = resource.start;
>  
>  	/* Check for shifted address mapping */
> -	prop = of_get_property(np, "reg-offset", &prop_size);
> -	if (prop && (prop_size == sizeof(u32)))
> -		port->mapbase += be32_to_cpup(prop);
> +	if (of_property_read_u32(np, "reg-offset", &prop) == 0)
> +		port->mapbase += prop;
>  
>  	/* Check for registers offset within the devices address range */
> -	prop = of_get_property(np, "reg-shift", &prop_size);
> -	if (prop && (prop_size == sizeof(u32)))
> -		port->regshift = be32_to_cpup(prop);
> +	if (of_property_read_u32(np, "reg-shift", &prop) == 0)
> +		port->regshift = prop;

Can be further simplified:

of_property_read_u32(np, "reg-shift", &port->regshift);

Rob

>  
>  	port->irq = irq_of_parse_and_map(np, 0);
>  	port->iotype = UPIO_MEM;
> -	prop = of_get_property(np, "reg-io-width", &prop_size);
> -	if (prop && (prop_size == sizeof(u32))) {
> -		switch (be32_to_cpup(prop)) {
> +	if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
> +		switch (prop) {
>  		case 1:
>  			port->iotype = UPIO_MEM;
>  			break;
> @@ -75,21 +72,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
>  			port->iotype = UPIO_MEM32;
>  			break;
>  		default:
> -			dev_warn(&ofdev->dev,
> -				 "unsupported io width (%d bytes)\n",
> -				 be32_to_cpup(prop));
> +			dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n",
> +				 prop);
>  			return -EINVAL;
>  		}
>  	}
>  
>  	port->type = type;
> -	port->uartclk = be32_to_cpup(clk);
> +	port->uartclk = clk;
>  	port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
>  		| UPF_FIXED_PORT | UPF_FIXED_TYPE;
>  	port->dev = &ofdev->dev;
> -	/* If current-speed was set, then try not to change it. */
> -	if (spd)
> -		port->custom_divisor = be32_to_cpup(clk) / (16 * (be32_to_cpup(spd)));
>  
>  	return 0;
>  }
> 
> _______________________________________________
> devicetree-discuss mailing list
> devicetree-discuss@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/devicetree-discuss


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

* Re: [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api
  2011-06-30 20:57 ` Rob Herring
@ 2011-06-30 21:01   ` Grant Likely
  0 siblings, 0 replies; 4+ messages in thread
From: Grant Likely @ 2011-06-30 21:01 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree-discuss, Arnd Bergmann, linux-kernel, linux-serial,
	Alan Cox

On Thu, Jun 30, 2011 at 2:57 PM, Rob Herring <robherring2@gmail.com> wrote:
> Grant,
>
> On 06/30/2011 02:00 PM, Grant Likely wrote:
>> Simplifies the code a bit and drops a few lines.
>>
>> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
>> ---
>>
>> I've only actually build tested this, but this shows some of the cleanup
>> achieved using the of_property_read_u32() API.  If this gets merged in the
>> v3.1 merge window then it will need to go via the devicetree/next branch.
>>
>> g.
>
> You can't give yourself bonus points. ;)
>
>>
>>  drivers/tty/serial/of_serial.c |   37 +++++++++++++++----------------------
>>  1 files changed, 15 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
>> index 36038ed..dbfbfda 100644
>> --- a/drivers/tty/serial/of_serial.c
>> +++ b/drivers/tty/serial/of_serial.c
>> @@ -32,17 +32,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
>>  {
>>       struct resource resource;
>>       struct device_node *np = ofdev->dev.of_node;
>> -     const __be32 *clk, *spd;
>> -     const __be32 *prop;
>> -     int ret, prop_size;
>> +     u32 clk, spd, prop;
>> +     int ret;
>>
>>       memset(port, 0, sizeof *port);
>> -     spd = of_get_property(np, "current-speed", NULL);
>> -     clk = of_get_property(np, "clock-frequency", NULL);
>> -     if (!clk) {
>> +     if (of_property_read_u32(np, "clock-frequency", &clk)) {
>
> s/clk/port->uartclk/
>
> And below, then remove clk.
>
>>               dev_warn(&ofdev->dev, "no clock-frequency property set\n");
>>               return -ENODEV;
>>       }
>> +     /* If current-speed was set, then try not to change it. */
>> +     if (of_property_read_u32(np, "current-speed", &spd) == 0)
>> +             port->custom_divisor = clk / (16 * spd);
>>
>>       ret = of_address_to_resource(np, 0, &resource);
>>       if (ret) {
>> @@ -54,20 +54,17 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
>>       port->mapbase = resource.start;
>>
>>       /* Check for shifted address mapping */
>> -     prop = of_get_property(np, "reg-offset", &prop_size);
>> -     if (prop && (prop_size == sizeof(u32)))
>> -             port->mapbase += be32_to_cpup(prop);
>> +     if (of_property_read_u32(np, "reg-offset", &prop) == 0)
>> +             port->mapbase += prop;
>>
>>       /* Check for registers offset within the devices address range */
>> -     prop = of_get_property(np, "reg-shift", &prop_size);
>> -     if (prop && (prop_size == sizeof(u32)))
>> -             port->regshift = be32_to_cpup(prop);
>> +     if (of_property_read_u32(np, "reg-shift", &prop) == 0)
>> +             port->regshift = prop;
>
> Can be further simplified:
>
> of_property_read_u32(np, "reg-shift", &port->regshift);

Hey Rob, thanks for the review.

I thought about that, but the new api specifically needs to be passed
a u32 pointer, not an unsigned char pointer which is what is in the
port structure.  That goes for the clk value too.  Even for unsigned
int values, i need the u32 bounce variable because it would break on
64 bit platforms.

g.

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

* Re: [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api
  2011-06-30 19:00 [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api Grant Likely
  2011-06-30 20:57 ` Rob Herring
@ 2011-07-01 16:32 ` Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2011-07-01 16:32 UTC (permalink / raw)
  To: Grant Likely; +Cc: devicetree-discuss, linux-kernel, linux-serial, Alan Cox

On Thursday 30 June 2011, Grant Likely wrote:
> Simplifies the code a bit and drops a few lines.
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

Looks good to me, and Rob's comment makes sense as well.

Acked-by: Arnd Bergmann <arnd@arndb.de>

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

end of thread, other threads:[~2011-07-01 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-30 19:00 [PATCH] tty/serial: change of_serial to use new of_property_read_u32() api Grant Likely
2011-06-30 20:57 ` Rob Herring
2011-06-30 21:01   ` Grant Likely
2011-07-01 16:32 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox