Patchwork can: sja1000: use cpu endian

login
register
mail settings
Submitter Christoph Fritz
Date April 8, 2013, 1:48 p.m.
Message ID <1365428932.5760.52.camel@lovely>
Download mbox | patch
Permalink /patch/234783/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Christoph Fritz - April 8, 2013, 1:48 p.m.
Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/net/can/sja1000/sja1000_of_platform.c |   26 ++++++++++++------------
 1 files changed, 13 insertions(+), 13 deletions(-)
Marc Kleine-Budde - April 8, 2013, 1:57 p.m.
On 04/08/2013 03:48 PM, Christoph Fritz wrote:

Please add a patch description to the patch, as some subsystem
maintainers don't take patches without it.

What about using of_property_read_u32, instead of open coding it?

Marc

> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/net/can/sja1000/sja1000_of_platform.c |   26 ++++++++++++------------
>  1 files changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c
> index 6433b81..83a13d2 100644
> --- a/drivers/net/can/sja1000/sja1000_of_platform.c
> +++ b/drivers/net/can/sja1000/sja1000_of_platform.c
> @@ -97,7 +97,7 @@ static int sja1000_ofp_probe(struct platform_device *ofdev)
>  	struct sja1000_priv *priv;
>  	struct resource res;
>  	const u32 *prop;
> -	int err, irq, res_size, prop_size;
> +	int err, irq, res_size;
>  	void __iomem *base;
>  
>  	err = of_address_to_resource(np, 0, &res);
> @@ -138,27 +138,27 @@ static int sja1000_ofp_probe(struct platform_device *ofdev)
>  	priv->read_reg = sja1000_ofp_read_reg;
>  	priv->write_reg = sja1000_ofp_write_reg;
>  
> -	prop = of_get_property(np, "nxp,external-clock-frequency", &prop_size);
> -	if (prop && (prop_size ==  sizeof(u32)))
> -		priv->can.clock.freq = *prop / 2;
> +	prop = of_get_property(np, "nxp,external-clock-frequency", NULL);
> +	if (prop)
> +		priv->can.clock.freq = be32_to_cpup(prop) / 2;
>  	else
>  		priv->can.clock.freq = SJA1000_OFP_CAN_CLOCK; /* default */
>  
> -	prop = of_get_property(np, "nxp,tx-output-mode", &prop_size);
> -	if (prop && (prop_size == sizeof(u32)))
> -		priv->ocr |= *prop & OCR_MODE_MASK;
> +	prop = of_get_property(np, "nxp,tx-output-mode", NULL);
> +	if (prop)
> +		priv->ocr |= be32_to_cpup(prop) & OCR_MODE_MASK;
>  	else
>  		priv->ocr |= OCR_MODE_NORMAL; /* default */
>  
> -	prop = of_get_property(np, "nxp,tx-output-config", &prop_size);
> -	if (prop && (prop_size == sizeof(u32)))
> -		priv->ocr |= (*prop << OCR_TX_SHIFT) & OCR_TX_MASK;
> +	prop = of_get_property(np, "nxp,tx-output-config", NULL);
> +	if (prop)
> +		priv->ocr |= (be32_to_cpup(prop) << OCR_TX_SHIFT) & OCR_TX_MASK;
>  	else
>  		priv->ocr |= OCR_TX0_PULLDOWN; /* default */
>  
> -	prop = of_get_property(np, "nxp,clock-out-frequency", &prop_size);
> -	if (prop && (prop_size == sizeof(u32)) && *prop) {
> -		u32 divider = priv->can.clock.freq * 2 / *prop;
> +	prop = of_get_property(np, "nxp,clock-out-frequency", NULL);
> +	if (prop) {
> +		u32 divider = priv->can.clock.freq * 2 / be32_to_cpup(prop);
>  
>  		if (divider > 1)
>  			priv->cdr |= divider / 2 - 1;
>

Patch

diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c
index 6433b81..83a13d2 100644
--- a/drivers/net/can/sja1000/sja1000_of_platform.c
+++ b/drivers/net/can/sja1000/sja1000_of_platform.c
@@ -97,7 +97,7 @@  static int sja1000_ofp_probe(struct platform_device *ofdev)
 	struct sja1000_priv *priv;
 	struct resource res;
 	const u32 *prop;
-	int err, irq, res_size, prop_size;
+	int err, irq, res_size;
 	void __iomem *base;
 
 	err = of_address_to_resource(np, 0, &res);
@@ -138,27 +138,27 @@  static int sja1000_ofp_probe(struct platform_device *ofdev)
 	priv->read_reg = sja1000_ofp_read_reg;
 	priv->write_reg = sja1000_ofp_write_reg;
 
-	prop = of_get_property(np, "nxp,external-clock-frequency", &prop_size);
-	if (prop && (prop_size ==  sizeof(u32)))
-		priv->can.clock.freq = *prop / 2;
+	prop = of_get_property(np, "nxp,external-clock-frequency", NULL);
+	if (prop)
+		priv->can.clock.freq = be32_to_cpup(prop) / 2;
 	else
 		priv->can.clock.freq = SJA1000_OFP_CAN_CLOCK; /* default */
 
-	prop = of_get_property(np, "nxp,tx-output-mode", &prop_size);
-	if (prop && (prop_size == sizeof(u32)))
-		priv->ocr |= *prop & OCR_MODE_MASK;
+	prop = of_get_property(np, "nxp,tx-output-mode", NULL);
+	if (prop)
+		priv->ocr |= be32_to_cpup(prop) & OCR_MODE_MASK;
 	else
 		priv->ocr |= OCR_MODE_NORMAL; /* default */
 
-	prop = of_get_property(np, "nxp,tx-output-config", &prop_size);
-	if (prop && (prop_size == sizeof(u32)))
-		priv->ocr |= (*prop << OCR_TX_SHIFT) & OCR_TX_MASK;
+	prop = of_get_property(np, "nxp,tx-output-config", NULL);
+	if (prop)
+		priv->ocr |= (be32_to_cpup(prop) << OCR_TX_SHIFT) & OCR_TX_MASK;
 	else
 		priv->ocr |= OCR_TX0_PULLDOWN; /* default */
 
-	prop = of_get_property(np, "nxp,clock-out-frequency", &prop_size);
-	if (prop && (prop_size == sizeof(u32)) && *prop) {
-		u32 divider = priv->can.clock.freq * 2 / *prop;
+	prop = of_get_property(np, "nxp,clock-out-frequency", NULL);
+	if (prop) {
+		u32 divider = priv->can.clock.freq * 2 / be32_to_cpup(prop);
 
 		if (divider > 1)
 			priv->cdr |= divider / 2 - 1;