Re: [U-Boot] [PATCH v8 9/9] net: macb: Fix check for little-endian system in gmac_configure_dma()

2019-06-24 Thread Ramon Fried
On Tue, Jun 25, 2019 at 7:15 AM Anup Patel  wrote:
>
> Instead of depending on CONFIG_SYS_LITTLE_ENDIAN, we check at runtime
> whether underlying system is little-endian or big-endian. This way
> we are not dependent on any U-Boot specific OR compiler specific macro
> to check system endianness.
>
> Signed-off-by: Anup Patel 
> Reviewed-by: Bin Meng 
> ---
>  drivers/net/macb.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/macb.c b/drivers/net/macb.c
> index 7fedb9ae0e..942d469572 100644
> --- a/drivers/net/macb.c
> +++ b/drivers/net/macb.c
> @@ -85,6 +85,8 @@ struct macb_device {
> void*regs;
> void*regs1;
>
> +   boolis_big_endian;
> +
> const struct macb_config*config;
>
> unsigned intrx_tail;
> @@ -739,11 +741,10 @@ static void gmac_configure_dma(struct macb_device *macb)
> dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L);
> dmacfg &= ~GEM_BIT(ENDIA_PKT);
>
> -#ifdef CONFIG_SYS_LITTLE_ENDIAN
> -   dmacfg &= ~GEM_BIT(ENDIA_DESC);
> -#else
> +   if (macb->is_big_endian)
> dmacfg |= GEM_BIT(ENDIA_DESC); /* CPU in big endian */
> -#endif
> +   else
> +   dmacfg &= ~GEM_BIT(ENDIA_DESC);
>
> dmacfg &= ~GEM_BIT(ADDR64);
> gem_writel(macb, DMACFG, dmacfg);
> @@ -1230,6 +1231,9 @@ static int macb_eth_probe(struct udevice *dev)
>
> macb->regs = (void *)pdata->iobase;
>
> +   macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678) ?
> +   true : false;
> +
> macb->config = (struct macb_config *)dev_get_driver_data(dev);
> if (!macb->config)
> macb->config = _gem_config;
> --
> 2.17.1
>
Reviewed-By: Ramon Fried 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 9/9] net: macb: Fix check for little-endian system in gmac_configure_dma()

2019-06-24 Thread Anup Patel
Instead of depending on CONFIG_SYS_LITTLE_ENDIAN, we check at runtime
whether underlying system is little-endian or big-endian. This way
we are not dependent on any U-Boot specific OR compiler specific macro
to check system endianness.

Signed-off-by: Anup Patel 
Reviewed-by: Bin Meng 
---
 drivers/net/macb.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 7fedb9ae0e..942d469572 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -85,6 +85,8 @@ struct macb_device {
void*regs;
void*regs1;
 
+   boolis_big_endian;
+
const struct macb_config*config;
 
unsigned intrx_tail;
@@ -739,11 +741,10 @@ static void gmac_configure_dma(struct macb_device *macb)
dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L);
dmacfg &= ~GEM_BIT(ENDIA_PKT);
 
-#ifdef CONFIG_SYS_LITTLE_ENDIAN
-   dmacfg &= ~GEM_BIT(ENDIA_DESC);
-#else
+   if (macb->is_big_endian)
dmacfg |= GEM_BIT(ENDIA_DESC); /* CPU in big endian */
-#endif
+   else
+   dmacfg &= ~GEM_BIT(ENDIA_DESC);
 
dmacfg &= ~GEM_BIT(ADDR64);
gem_writel(macb, DMACFG, dmacfg);
@@ -1230,6 +1231,9 @@ static int macb_eth_probe(struct udevice *dev)
 
macb->regs = (void *)pdata->iobase;
 
+   macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678) ?
+   true : false;
+
macb->config = (struct macb_config *)dev_get_driver_data(dev);
if (!macb->config)
macb->config = _gem_config;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot