Re: [PATCH v2 0/5] Linux's serdev framwork port

2018-04-16 Thread Sascha Hauer
On Thu, Apr 12, 2018 at 02:33:12PM -0700, Andrey Smirnov wrote:
> Hi everyone:
> 
> In an effort to bring this kernel driver
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/mfd/rave-sp.c?h=v4.16-rc7
> to Barebox, I ended up creating a miniature and extremely simplified
> version of 'serdev' subsystem which is presented in this patchset.
> 
> Changes since [v1]:
> 
>   - Blocking read function was added as example of API usage
> 
>   - "serial: Check result of console_unregister()" was converted
>   to become "serial: Drop .remove functions from all drivers"
> 
>   - Minor spelling fixes
> 
>   - Original serdev framework patch modified to allow devices
>   that do not require polling (I don't have such a usecase,
>   but for the sake of being generic I added one line needed
>   for that)
> 
>   - SERIAL_DEV_BUS Kconfig symbol moved into
>   drivers/serial/Kconfig (where it, IMHO, fits much better)
> 
>   - Added a patch to dynamically adjust serdev's polling
>   interval via device paramter. This was warranted by the
>   problems that arose from real-life usage.
> 
> Feedback is wellcome!
> 
> Thanks,
> Andrey Smirnov
> 
> [v1] https://www.spinics.net/lists/u-boot-v2/msg32322.html

Applied, thanks

Sascha

> 
> Andrey Smirnov (5):
>   console: Introduce console_drain()
>   console: Add simplified 'serdev' framework from Linux kernel
>   serdev: Add trivial blocking read function
>   serial: Drop .remove functions from all drivers
>   serdev: Allow polling interval to be adjusted at runtime
> 
>  common/Makefile  |   1 +
>  common/console.c |  24 -
>  common/serdev.c  | 208 
> +++
>  drivers/serial/Kconfig   |   6 ++
>  drivers/serial/serial_auart.c|  11 ---
>  drivers/serial/serial_cadence.c  |   9 --
>  drivers/serial/serial_clps711x.c |  10 --
>  drivers/serial/serial_imx.c  |  10 --
>  drivers/serial/serial_lpuart.c   |  13 ---
>  drivers/serial/serial_pxa.c  |   9 --
>  drivers/serial/serial_s3c.c  |  10 --
>  drivers/serial/stm-serial.c  |  10 --
>  include/console.h| 110 +
>  include/serdev.h |  44 +
>  lib/xymodem.c|  30 +-
>  15 files changed, 395 insertions(+), 110 deletions(-)
>  create mode 100644 common/serdev.c
>  create mode 100644 include/serdev.h
> 
> -- 
> 2.14.3
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] gitignore: Add *.pblx files

2018-04-16 Thread Sascha Hauer
On Thu, Apr 12, 2018 at 02:38:59PM -0700, Andrey Smirnov wrote:
> Looks like *.pblx was accidentally dropped from ignored files list and
> now my "git status" is clobbered by every *.pblx image that is being
> built (that's quite a lot for imx_v7_defconfig). Re-add original rule
> to prevent that.
> 
> Fixes eed8a41c5 ("gitignore: ignore pblx.simximg files")
> 
> Cc: Steffen Trumtrar 
> Signed-off-by: Andrey Smirnov 

Applied, thanks

I usually don't see these because I always build out of tree.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] serial/lpuart: Do not enable UART FIFO

2018-04-16 Thread Sascha Hauer
On Thu, Apr 12, 2018 at 02:41:43PM -0700, Andrey Smirnov wrote:
> Using FIFO in LPUART results in subtle serial input draining issues
> which are quite difficult to reproduce and troubleshoot. Since the
> change offered only moderate performance gain revert the code to
> operate in no-FIFO mode to avoid FIFO-related problems alltogether.
> 
> Signed-off-by: Andrey Smirnov 

Applied, thanks

Sascha

> ---
>  drivers/serial/serial_lpuart.c |  4 +---
>  include/serial/lpuart.h| 21 +
>  2 files changed, 6 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
> index 52fb6d39c..8f87f7b9c 100644
> --- a/drivers/serial/serial_lpuart.c
> +++ b/drivers/serial/serial_lpuart.c
> @@ -170,9 +170,7 @@ static int lpuart_serial_probe(struct device_d *dev)
>  
>   cdev->linux_console_name = "ttyLP";
>  
> - lpuart_setup_with_fifo(lpuart->base,
> -clk_get_rate(lpuart->clk),
> -15);
> + lpuart_setup(lpuart->base, clk_get_rate(lpuart->clk));
>  
>   ret = console_register(cdev);
>   if (!ret) {
> diff --git a/include/serial/lpuart.h b/include/serial/lpuart.h
> index 917f644a5..a920291de 100644
> --- a/include/serial/lpuart.h
> +++ b/include/serial/lpuart.h
> @@ -238,22 +238,17 @@ static inline void lpuart_setbrg(void __iomem *base,
>   writeb(bfra, base + UARTCR4);
>  }
>  
> -static inline void lpuart_setup_with_fifo(void __iomem *base,
> -   unsigned int refclock,
> -   unsigned int twfifo)
> +static inline void lpuart_setup(void __iomem *base,
> + unsigned int refclock)
>  {
>   /* Disable UART */
>   writeb(0, base + UARTCR2);
>   writeb(0, base + UARTMODEM);
>   writeb(0, base + UARTCR1);
>  
> - if (twfifo) {
> - writeb(UARTPFIFO_TXFE | UARTPFIFO_RXFE, base + UARTPFIFO);
> - writeb((u8)twfifo, base + UARTTWFIFO);
> - } else {
> - writeb(0, base + UARTPFIFO);
> - writeb(0, base + UARTTWFIFO);
> - }
> + writeb(0, base + UARTPFIFO);
> + writeb(0, base + UARTTWFIFO);
> +
>   writeb(1, base + UARTRWFIFO);
>   writeb(UARTCFIFO_RXFLUSH | UARTCFIFO_TXFLUSH, base + UARTCFIFO);
>  
> @@ -262,12 +257,6 @@ static inline void lpuart_setup_with_fifo(void __iomem 
> *base,
>   writeb(UARTCR2_TE | UARTCR2_RE, base + UARTCR2);
>  }
>  
> -static inline void lpuart_setup(void __iomem *base,
> - unsigned int refclock)
> -{
> - lpuart_setup_with_fifo(base, refclock, 0x00);
> -}
> -
>  static inline void lpuart_putc(void __iomem *base, int c)
>  {
>   if (!(readb(base + UARTCR2) & UARTCR2_TE))
> -- 
> 2.14.3
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 03/10] ARM: i.MX6: Record reset reason as a part of startup

2018-04-16 Thread Sascha Hauer
Hi Andrey,

On Sat, Apr 14, 2018 at 10:50:17AM -0700, Andrey Smirnov wrote:
> Signed-off-by: Andrey Smirnov 
> ---
>  arch/arm/mach-imx/imx6.c  | 4 +++-
>  arch/arm/mach-imx/include/mach/reset-reason.h | 2 ++
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
> index 14a1cba5a..3d81c2785 100644
> --- a/arch/arm/mach-imx/imx6.c
> +++ b/arch/arm/mach-imx/imx6.c
> @@ -19,6 +19,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -151,6 +152,7 @@ int imx6_init(void)
>  {
>   const char *cputypestr;
>   u32 mx6_silicon_revision;
> + void __iomem *src = IOMEM(MX6_SRC_BASE_ADDR);
>  
>   imx6_init_lowlevel();
>  
> @@ -195,7 +197,7 @@ int imx6_init(void)
>   }
>  
>   imx_set_silicon_revision(cputypestr, mx6_silicon_revision);
> -
> + imx_set_reset_reason(src + IMX6_SRC_SRSR);

This will get overwritten by the watchdog driver if enabled.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 04/10] ARM: i.MX7: Record reset reason as a part of startup

2018-04-16 Thread Sascha Hauer
On Sat, Apr 14, 2018 at 10:50:18AM -0700, Andrey Smirnov wrote:
> Signed-off-by: Andrey Smirnov 
> ---
>  arch/arm/mach-imx/imx7.c  | 3 +++
>  arch/arm/mach-imx/include/mach/reset-reason.h | 1 +
>  2 files changed, 4 insertions(+)
> 
> diff --git a/arch/arm/mach-imx/imx7.c b/arch/arm/mach-imx/imx7.c
> index 4eef99c87..a5debd06c 100644
> --- a/arch/arm/mach-imx/imx7.c
> +++ b/arch/arm/mach-imx/imx7.c
> @@ -19,6 +19,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  void imx7_init_lowlevel(void)
> @@ -171,6 +172,7 @@ int imx7_init(void)
>  {
>   const char *cputypestr;
>   u32 imx7_silicon_revision;
> + void __iomem *src = IOMEM(MX7_SRC_BASE_ADDR);
>  
>   imx7_init_lowlevel();
>  
> @@ -197,6 +199,7 @@ int imx7_init(void)
>   }
>  
>   imx_set_silicon_revision(cputypestr, imx7_silicon_revision);
> + imx_set_reset_reason(src + IMX7_SRC_SRSR);

Same here.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 08/10] ARM: VFxxx: Add code to detect reset reason

2018-04-16 Thread Sascha Hauer
On Sat, Apr 14, 2018 at 10:50:22AM -0700, Andrey Smirnov wrote:
> Signed-off-by: Andrey Smirnov 
> ---
>  arch/arm/mach-imx/imx.c   | 78 
> +--
>  arch/arm/mach-imx/include/mach/reset-reason.h | 11 
>  2 files changed, 62 insertions(+), 27 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
> index fb1160de9..e84713766 100644
> --- a/arch/arm/mach-imx/imx.c
> +++ b/arch/arm/mach-imx/imx.c
> @@ -158,6 +158,7 @@ void imx_set_reset_reason(void __iomem *srsr)
>  {
>   enum reset_src_type type = RESET_UKWN;
>   const u32 reg = readl(srsr);
> + const bool is_vf610 = cpu_is_vf610();
>  
>   /*
>* SRSR register captures ALL reset event that occured since
> @@ -166,37 +167,60 @@ void imx_set_reset_reason(void __iomem *srsr)
>*/
>   writel(reg, srsr);
>  
> - switch (reg) {
> - case IMX_SRC_SRSR_IPP_RESET: /* FALLTHROUGH */
> - case IMX_SRC_SRSR_IPP_RESET | IMX_SRC_SRSR_WDOG1_RESET:
> - type = RESET_POR;
> - break;
> - case IMX_SRC_SRSR_WDOG3_RESET: /* FALLTHROUGH */
> - case IMX_SRC_SRSR_WDOG4_RESET: /* FALLTHROUGH */
> - case IMX_SRC_SRSR_WDOG1_RESET:
> - type = RESET_WDG;
> - break;
> - case IMX_SRC_SRSR_JTAG_RESET: /* FALLTHROUGH */
> - case IMX_SRC_SRSR_JTAG_SW_RESET:
> - type = RESET_JTAG;
> - break;
> - case IMX_SRC_SRSR_TEMPSENSE_RESET:
> - type = RESET_THERM;
> - break;
> - case IMX_SRC_SRSR_WARM_BOOT:
> - type = RESET_RST;
> - break;
> + if (is_vf610) {

The caller already knows this is a vf610 and the code path for vf610 is
completely different. Please add a vf610_set_reset_reason() instead of
clobbering the i.MX function with this.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value

2018-04-16 Thread Sascha Hauer
On Sat, Apr 14, 2018 at 10:50:48AM -0700, Andrey Smirnov wrote:
> The location of BMDO field in SBMR/SBMR2 registers is consistent
> across all i.MX SoCs starting from i.MX53. Add simple helper function
> imx53_get_bmod and use it to avoid code duplication.
> 
> Signed-off-by: Andrey Smirnov 
> ---
>  arch/arm/mach-imx/boot.c | 25 ++---
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
> index 4657fa017..56f9fb5d4 100644
> --- a/arch/arm/mach-imx/boot.c
> +++ b/arch/arm/mach-imx/boot.c
> @@ -169,12 +169,23 @@ void imx51_get_boot_source(enum bootsource *src, int 
> *instance)
>  }
>  
>  #define IMX53_SRC_SBMR   0x4
> +
> +static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
> +{
> + return (r & GENMASK(msb, lsb)) >> lsb;
> +}

If you like GENMASK then maybe the FIELD_GET and FIELD_PREP macros from
the Linux kernel are for you aswell.

#define SRC_SBMR_BMOD   GENMASK(25, 24)

> +
> +static unsigned int imx53_get_bmod(uint32_t r)
> +{
> + return sbmr(r, 25, 24);

return FIELD_GET(SRC_SBMR_BMOD, r);

Sascha

> +}
> +
>  void imx53_get_boot_source(enum bootsource *src, int *instance)
>  {
>   void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
>   uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
>  
> - if (((cfg1 >> 24) & 0x3) == 0x3) {
> + if (imx53_get_bmod(cfg1) == 0x3) {
>   *src = BOOTSOURCE_USB;
>   *instance = 0;
>   return;
> @@ -225,12 +236,8 @@ void imx6_get_boot_source(enum bootsource *src, int 
> *instance)
>   uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
>   uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
>   uint32_t boot_cfg_4_2_0;
> - int boot_mode;
>  
> - /* BMOD[1:0] */
> - boot_mode = (sbmr2 >> 24) & 0x3;
> -
> - switch (boot_mode) {
> + switch (imx53_get_bmod(sbmr2)) {
>   case 0: /* Fuses, fall through */
>   case 2: /* internal boot */
>   goto internal_boot;
> @@ -290,12 +297,8 @@ void imx7_get_boot_source(enum bootsource *src, int 
> *instance)
>   void __iomem *src_base = IOMEM(MX7_SRC_BASE_ADDR);
>   uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
>   uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
> - int boot_mode;
> -
> - /* BMOD[1:0] */
> - boot_mode = (sbmr2 >> 24) & 0x3;
>  
> - switch (boot_mode) {
> + switch (imx53_get_bmod(sbmr2)) {
>   case 0: /* Fuses, fall through */
>   case 2: /* internal boot */
>   goto internal_boot;
> -- 
> 2.14.3
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 1/2] common: state: Add property to protect existing data

2018-04-16 Thread Sascha Hauer
On Thu, Apr 12, 2018 at 11:13:01AM +0200, Daniel Schultz wrote:
> After an update to a newer barebox version with an enabled state
> framework, existing data in storage memories could be overwritten.
> 
> Add a new property to check in front of every write task, if the meta
> magic field only contains the magic number, zeros or ones.
> 
> Signed-off-by: Daniel Schultz 
> ---
> Changes:
>   v2: Added check for circular backend
>   Improved error message if content was found
> 

Applied, thanks

Sascha

>  .../devicetree/bindings/barebox/barebox,state.rst |  3 +++
>  common/state/backend_bucket_circular.c|  8 +---
>  common/state/backend_bucket_direct.c  |  2 ++
>  common/state/state.c  | 19 
> ++-
>  common/state/state.h  |  2 ++
>  5 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst 
> b/Documentation/devicetree/bindings/barebox/barebox,state.rst
> index 872bac0..2893937 100644
> --- a/Documentation/devicetree/bindings/barebox/barebox,state.rst
> +++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst
> @@ -55,6 +55,9 @@ Optional Properties
>  * ``algo``: A HMAC algorithm used to detect manipulation of the data
>or header, sensible values follow this pattern ``hmac()``,
>e.g. ``hmac(sha256)``. Only available for the ``backend-type`` ``raw``.
> +* ``keep-previous-content``: Check if a the bucket meta magic field contains
> +  other data than the magic value. If so, the backend will not write the 
> state
> +  to prevent unconditionally overwrites of existing data.
>  
>  .. note:: For the ``backend-storage-type`` the keyword ``noncircular`` is 
> still
> supported as a fall back to an old storage format. Recommendation is to 
> not
> diff --git a/common/state/backend_bucket_circular.c 
> b/common/state/backend_bucket_circular.c
> index 2324903..933493e 100644
> --- a/common/state/backend_bucket_circular.c
> +++ b/common/state/backend_bucket_circular.c
> @@ -396,11 +396,13 @@ static int state_backend_bucket_circular_init(
>   meta = (struct 
> state_backend_storage_bucket_circular_meta *)
>   (buf + sub_offset + circ->writesize - 
> sizeof(*meta));
>  
> - if (meta->magic != circular_magic)
> + if (meta->magic != circular_magic) {
>   written_length = 0;
> - else
> + if (meta->magic != ~0 && !!meta->magic)
> + bucket->wrong_magic = 1;
> + } else {
>   written_length = meta->written_length;
> -
> + }
>   break;
>   }
>   }
> diff --git a/common/state/backend_bucket_direct.c 
> b/common/state/backend_bucket_direct.c
> index 958696e..9d6a337 100644
> --- a/common/state/backend_bucket_direct.c
> +++ b/common/state/backend_bucket_direct.c
> @@ -69,6 +69,8 @@ static int state_backend_bucket_direct_read(struct 
> state_backend_storage_bucket
>   if (meta.magic == direct_magic) {
>   read_len = meta.written_length;
>   } else {
> + if (meta.magic != ~0 && !!meta.magic)
> + bucket->wrong_magic = 1;
>   if (!IS_ENABLED(CONFIG_STATE_BACKWARD_COMPATIBLE)) {
>   dev_err(direct->dev, "No meta data header found\n");
>   dev_dbg(direct->dev, "Enable backward compatibility or 
> increase stride size\n");
> diff --git a/common/state/state.c b/common/state/state.c
> index 73dfb58..25d9502 100644
> --- a/common/state/state.c
> +++ b/common/state/state.c
> @@ -44,6 +44,8 @@ int state_save(struct state *state)
>   void *buf;
>   ssize_t len;
>   int ret;
> + struct state_backend_storage_bucket *bucket;
> + struct state_backend_storage *storage;
>  
>   if (!state->dirty)
>   return 0;
> @@ -55,7 +57,19 @@ int state_save(struct state *state)
>   return ret;
>   }
>  
> - ret = state_storage_write(&state->storage, buf, len);
> + storage = &state->storage;
> + if (state->keep_prev_content) {
> + bool has_content = 0;
> + list_for_each_entry(bucket, &storage->buckets, bucket_list)
> + has_content |= bucket->wrong_magic;
> + if (has_content) {
> + dev_err(&state->dev, "Found foreign content on backend, 
> won't overwrite.\n");
> + ret = -EPERM;
> + goto out;
> + }
> + }
> +
> + ret = state_storage_write(storage, buf, len);
>   if (ret) {
>   dev_err(&state->dev, "Failed to write packed state, %d\n", ret);
>   goto out;
> @@ -623,6 +637,9 @@ struct state *state_new_from_node(str

Re: [PATCH 4/4] clk: i.MX6: Fix enfc_sel for i.MX6dqp

2018-04-16 Thread Sascha Hauer
On Wed, Apr 11, 2018 at 03:26:54PM +0200, Sascha Hauer wrote:
> The plus SoC variants have some differences in the clock controller.
> For now fix the NAND controller clock. There are more differences
> that might be relevant, but for now are left for a future excercise.
> 
> Signed-off-by: Sascha Hauer 
> ---
>  drivers/clk/imx/clk-imx6.c | 19 ++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/imx/clk-imx6.c b/drivers/clk/imx/clk-imx6.c
> index c48ab7f76a..7f1af12571 100644
> --- a/drivers/clk/imx/clk-imx6.c
> +++ b/drivers/clk/imx/clk-imx6.c
> @@ -59,6 +59,11 @@
>  static struct clk *clks[IMX6QDL_CLK_END];
>  static struct clk_onecell_data clk_data;
>  
> +static inline int cpu_is_plus(void)
> +{
> + return cpu_is_mx6qp() || cpu_is_mx6dp();
> +}
> +
>  static const char *step_sels[] = {
>   "osc",
>   "pll2_pfd2_396m",
> @@ -109,6 +114,15 @@ static const char *enfc_sels[]   = {
>   "pll2_pfd2_396m",
>  };
>  
> +static const char *enfc_sels_plus[] = {
> + "pll2_pfd0_352m",
> + "pll2_bus",
> + "pll3_usb_otg",
> + "pll2_pfd2_396m",
> + "pll3_pfd3_454m",
> + "dummy",
> +};
> +
>  static const char *eim_sels[] = {
>   "axi",
>   "pll3_usb_otg",
> @@ -404,7 +418,10 @@ static int imx6_ccm_probe(struct device_d *dev)
>   clks[IMX6QDL_CLK_USDHC2_SEL]   = imx_clk_mux("usdhc2_sel",   
> base + 0x1c, 17, 1, usdhc_sels,ARRAY_SIZE(usdhc_sels));
>   clks[IMX6QDL_CLK_USDHC3_SEL]   = imx_clk_mux("usdhc3_sel",   
> base + 0x1c, 18, 1, usdhc_sels,ARRAY_SIZE(usdhc_sels));
>   clks[IMX6QDL_CLK_USDHC4_SEL]   = imx_clk_mux("usdhc4_sel",   
> base + 0x1c, 19, 1, usdhc_sels,ARRAY_SIZE(usdhc_sels));
> - clks[IMX6QDL_CLK_ENFC_SEL] = imx_clk_mux("enfc_sel", 
> base + 0x2c, 16, 2, enfc_sels, ARRAY_SIZE(enfc_sels));
> + if (cpu_is_plus())
> + clks[IMX6QDL_CLK_ENFC_SEL] = imx_clk_mux("enfc_sel",
>  base + 0x2c, 16, 2, enfc_sels, ARRAY_SIZE(enfc_sels));
> + else
> + clks[IMX6QDL_CLK_ENFC_SEL] = imx_clk_mux("enfc_sel",
>  base + 0x2c, 16, 2, enfc_sels_plus,ARRAY_SIZE(enfc_sels_plus));

The enfc_sels for plus and non plus version are swapped here. Fixed.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: Question about barebox*/drivers/mfd/mc34704.c and ACCURATE I²C mode ...

2018-04-16 Thread Baruch Siach
Hi Roland,

On Mon, Apr 16, 2018 at 09:52:14AM +, Mainz, Roland wrote:
> Two small questions about drivers/mfd/mc34704.c in the barebox codebase:
> 1. mc34704 has an ACCURATE bit (I2CSET1, see 
> https://www.nxp.com/docs/en/data-sheet/MC34704.pdf) which requires that all 
> read/write commands are send twice - does the barebox code have any support 
> for that in the current versions ?
> 2. Is this "accurate I²C communication mode" enabled by that bit a 
> vendor-specific protocol extension or is it part of the I²C standard ?

Please send your Barebox related questions to the barebox mailing list. I 
added the list to Cc.

To the best of my knowledge there is no "twice" mode in the I2C standard. The 
mc34704 driver does not seem to support this mode.

baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/2] fs: fix error path in __canonicalize_path()

2018-04-16 Thread Ulrich Ölmann
Report failure in resolving links to the caller and only clean up memory then.

Signed-off-by: Ulrich Ölmann 
---
 fs/fs.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 5135112c8b81..7c818eca024f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -202,8 +202,11 @@ static char *__canonicalize_path(const char *_pathname, 
int level)
continue;
 
ret = readlink(outpath, link, PATH_MAX - 1);
-   if (ret < 0)
+   if (ret < 0) {
+   free(outpath);
+   outpath = ERR_PTR(ret);
goto out;
+   }
 
if (link[0] == '/') {
free(outpath);
@@ -218,14 +221,15 @@ static char *__canonicalize_path(const char *_pathname, 
int level)
if (IS_ERR(outpath))
goto out;
}
-out:
-   free(freep);
 
if (!*outpath) {
free(outpath);
outpath = xstrdup("/");
}
 
+out:
+   free(freep);
+
return outpath;
 }
 
-- 
2.16.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/2] fs: remove shortcut in canonicalizing filenames

2018-04-16 Thread Ulrich Ölmann
Only individually getting the file status for every part of the path tells us if
a symbolic link is involved or not. If this is the case the later call to
readlink will check if the filesystem supports symbolic links or not.

Hence this reverts commit d79a81736f64 ("fs: Don't bother filesystems without
link support with additional stat() calls").

Signed-off-by: Ulrich Ölmann 
---
 fs/fs.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 7c818eca024f..b2da0a62a29d 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -144,7 +144,6 @@ char *normalise_path(const char *pathname)
 EXPORT_SYMBOL(normalise_path);
 
 static int __lstat(const char *filename, struct stat *s);
-static struct fs_device_d *get_fsdevice_by_path(const char *path);
 
 static char *__canonicalize_path(const char *_pathname, int level)
 {
@@ -167,7 +166,6 @@ static char *__canonicalize_path(const char *_pathname, int 
level)
char *p = strsep(&path, "/");
char *tmp;
char link[PATH_MAX] = {};
-   struct fs_device_d *fsdev;
 
if (!p)
break;
@@ -186,14 +184,6 @@ static char *__canonicalize_path(const char *_pathname, 
int level)
free(outpath);
outpath = tmp;
 
-   /*
-* Don't bother filesystems without link support
-* with an additional stat() call.
-*/
-   fsdev = get_fsdevice_by_path(outpath);
-   if (!fsdev || !fsdev->driver->readlink)
-   continue;
-
ret = __lstat(outpath, &s);
if (ret)
goto out;
-- 
2.16.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 08/10] ARM: VFxxx: Add code to detect reset reason

2018-04-16 Thread Andrey Smirnov
On Mon, Apr 16, 2018 at 12:19 AM, Sascha Hauer  wrote:
> On Sat, Apr 14, 2018 at 10:50:22AM -0700, Andrey Smirnov wrote:
>> Signed-off-by: Andrey Smirnov 
>> ---
>>  arch/arm/mach-imx/imx.c   | 78 
>> +--
>>  arch/arm/mach-imx/include/mach/reset-reason.h | 11 
>>  2 files changed, 62 insertions(+), 27 deletions(-)
>>
>> diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
>> index fb1160de9..e84713766 100644
>> --- a/arch/arm/mach-imx/imx.c
>> +++ b/arch/arm/mach-imx/imx.c
>> @@ -158,6 +158,7 @@ void imx_set_reset_reason(void __iomem *srsr)
>>  {
>>   enum reset_src_type type = RESET_UKWN;
>>   const u32 reg = readl(srsr);
>> + const bool is_vf610 = cpu_is_vf610();
>>
>>   /*
>>* SRSR register captures ALL reset event that occured since
>> @@ -166,37 +167,60 @@ void imx_set_reset_reason(void __iomem *srsr)
>>*/
>>   writel(reg, srsr);
>>
>> - switch (reg) {
>> - case IMX_SRC_SRSR_IPP_RESET: /* FALLTHROUGH */
>> - case IMX_SRC_SRSR_IPP_RESET | IMX_SRC_SRSR_WDOG1_RESET:
>> - type = RESET_POR;
>> - break;
>> - case IMX_SRC_SRSR_WDOG3_RESET: /* FALLTHROUGH */
>> - case IMX_SRC_SRSR_WDOG4_RESET: /* FALLTHROUGH */
>> - case IMX_SRC_SRSR_WDOG1_RESET:
>> - type = RESET_WDG;
>> - break;
>> - case IMX_SRC_SRSR_JTAG_RESET: /* FALLTHROUGH */
>> - case IMX_SRC_SRSR_JTAG_SW_RESET:
>> - type = RESET_JTAG;
>> - break;
>> - case IMX_SRC_SRSR_TEMPSENSE_RESET:
>> - type = RESET_THERM;
>> - break;
>> - case IMX_SRC_SRSR_WARM_BOOT:
>> - type = RESET_RST;
>> - break;
>> + if (is_vf610) {
>
> The caller already knows this is a vf610 and the code path for vf610 is
> completely different. Please add a vf610_set_reset_reason() instead of
> clobbering the i.MX function with this.
>

They do share code fore clearing RSRS register, but sure, will do in v2.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 03/10] ARM: i.MX6: Record reset reason as a part of startup

2018-04-16 Thread Andrey Smirnov
On Mon, Apr 16, 2018 at 12:13 AM, Sascha Hauer  wrote:
> Hi Andrey,
>
> On Sat, Apr 14, 2018 at 10:50:17AM -0700, Andrey Smirnov wrote:
>> Signed-off-by: Andrey Smirnov 
>> ---
>>  arch/arm/mach-imx/imx6.c  | 4 +++-
>>  arch/arm/mach-imx/include/mach/reset-reason.h | 2 ++
>>  2 files changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
>> index 14a1cba5a..3d81c2785 100644
>> --- a/arch/arm/mach-imx/imx6.c
>> +++ b/arch/arm/mach-imx/imx6.c
>> @@ -19,6 +19,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -151,6 +152,7 @@ int imx6_init(void)
>>  {
>>   const char *cputypestr;
>>   u32 mx6_silicon_revision;
>> + void __iomem *src = IOMEM(MX6_SRC_BASE_ADDR);
>>
>>   imx6_init_lowlevel();
>>
>> @@ -195,7 +197,7 @@ int imx6_init(void)
>>   }
>>
>>   imx_set_silicon_revision(cputypestr, mx6_silicon_revision);
>> -
>> + imx_set_reset_reason(src + IMX6_SRC_SRSR);
>
> This will get overwritten by the watchdog driver if enabled.
>

I am not sure I see how. Imx_watchdog_detect_reset_source() reports
reset sources with the same priority as this code, so
reset_source_set_priority() should bail out early without changing
anything in that case.

Regardless, even if it were true, I think that behavior is perfectly
OK. First of all, startup log will still be present, which is IMHO
pretty useful. Second, the platforms that doen't use/rely on built-in
watchdog would benefit from this.

Another thing we can do is add code to respect "reset-source-priority"
to imxwd.c, so that people could ajdust what reset source info they
want to see via DT.

Let me know what you think.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value

2018-04-16 Thread Andrey Smirnov
On Mon, Apr 16, 2018 at 12:37 AM, Sascha Hauer  wrote:
> On Sat, Apr 14, 2018 at 10:50:48AM -0700, Andrey Smirnov wrote:
>> The location of BMDO field in SBMR/SBMR2 registers is consistent
>> across all i.MX SoCs starting from i.MX53. Add simple helper function
>> imx53_get_bmod and use it to avoid code duplication.
>>
>> Signed-off-by: Andrey Smirnov 
>> ---
>>  arch/arm/mach-imx/boot.c | 25 ++---
>>  1 file changed, 14 insertions(+), 11 deletions(-)
>>
>> diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
>> index 4657fa017..56f9fb5d4 100644
>> --- a/arch/arm/mach-imx/boot.c
>> +++ b/arch/arm/mach-imx/boot.c
>> @@ -169,12 +169,23 @@ void imx51_get_boot_source(enum bootsource *src, int 
>> *instance)
>>  }
>>
>>  #define IMX53_SRC_SBMR   0x4
>> +
>> +static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
>> +{
>> + return (r & GENMASK(msb, lsb)) >> lsb;
>> +}
>
> If you like GENMASK then maybe the FIELD_GET and FIELD_PREP macros from
> the Linux kernel are for you aswell.
>
> #define SRC_SBMR_BMOD   GENMASK(25, 24)
>

Definetly! I like it a lot! I was hoping that something like that
existed but didn't find anything in barebox's tree. Should've checked
the kernel one instead. Will add and use in v2 of the patch.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 4/4] pci: don't hide hard to understand sanity check in size calculation

2018-04-16 Thread Andrey Smirnov
On Sun, Apr 15, 2018 at 11:27 AM, Uwe Kleine-König
 wrote:
> Hello Andrey,
>
> On Sat, Apr 14, 2018 at 09:25:59AM -0700, Andrey Smirnov wrote:
>> On Fri, Apr 13, 2018 at 4:30 PM, Uwe Kleine-König
>>  wrote:
>> > +   /*
>> > +* if maxbase isn't in the form 0b1...10...0 there is 
>> > something
>> > +* fishy
>> > +*/
>> > +   if ((maxbase | (maxbase - 1)) != (u32)-1 || maxbase == 0) {
>>
>> U32_MAX instead of (u32)-1 ?
>
> I don't feel strong here.

Me neither. I just read (u32)-1 as a shortcut for 0x and we
already have a shortcut for that. But if you want to keep using
(u32)-1, then by all means.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions

2018-04-16 Thread Andrey Smirnov
On Sat, Apr 14, 2018 at 7:24 PM, Marc Reilly  wrote:
> On Sunday, April 15, 2018 3:50:55 AM AEST Andrey Smirnov wrote:
>> Move code to extract appropiate BOOT_CFG bits to decode booutsource on
>
> s/booutsource/bootsource
>

Fixed in v2.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns

2018-04-16 Thread Andrey Smirnov
On Sat, Apr 14, 2018 at 7:22 PM, Marc Reilly  wrote:
> Nitpick: in subject s/retruns/returns
>

 Fixed in v2.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 01/19] ARM: i.MX: boot: Coalesce copy-pasted code

2018-04-16 Thread Andrey Smirnov
All of the instances of imx*_boot_save_loc() do exactly the same thing with
the only difference being SoC-specific imx*_get_boot_source
call. Convert the code into a generic function taking function pointer
+ a macro to take care of the boilerplate.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 85 ++--
 1 file changed, 17 insertions(+), 68 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 72597f5e2..4657fa017 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -89,17 +89,6 @@ void imx25_get_boot_source(enum bootsource *src, int 
*instance)
(val >> MX25_CCM_RCSR_MEM_TYPE_SHIFT) & 
0x3);
 }
 
-void imx25_boot_save_loc(void)
-{
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx25_get_boot_source(&src, &instance);
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
-}
-
 void imx35_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *ccm_base = IOMEM(MX35_CCM_BASE_ADDR);
@@ -110,17 +99,6 @@ void imx35_get_boot_source(enum bootsource *src, int 
*instance)
(val >> MX35_CCM_RCSR_MEM_TYPE_SHIFT) & 
0x3);
 }
 
-void imx35_boot_save_loc(void)
-{
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx35_get_boot_source(&src, &instance);
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
-}
-
 #define IMX27_SYSCTRL_GPCR 0x18
 #define IMX27_GPCR_BOOT_SHIFT  16
 #define IMX27_GPCR_BOOT_MASK   (0xf << IMX27_GPCR_BOOT_SHIFT)
@@ -157,17 +135,6 @@ void imx27_get_boot_source(enum bootsource *src, int 
*instance)
}
 }
 
-void imx27_boot_save_loc(void)
-{
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx27_get_boot_source(&src, &instance);
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
-}
-
 #define IMX51_SRC_SBMR 0x4
 #define IMX51_SBMR_BT_MEM_TYPE_SHIFT   7
 #define IMX51_SBMR_BT_MEM_CTL_SHIFT0
@@ -201,17 +168,6 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance)
}
 }
 
-void imx51_boot_save_loc(void)
-{
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx51_get_boot_source(&src, &instance);
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
-}
-
 #define IMX53_SRC_SBMR 0x4
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
@@ -260,17 +216,6 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
}
 }
 
-void imx53_boot_save_loc(void)
-{
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx53_get_boot_source(&src, &instance);
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
-}
-
 #define IMX6_SRC_SBMR1 0x04
 #define IMX6_SRC_SBMR2 0x1c
 
@@ -337,17 +282,6 @@ internal_boot:
return;
 }
 
-void imx6_boot_save_loc(void)
-{
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx6_get_boot_source(&src, &instance);
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
-}
-
 #define IMX7_SRC_SBMR1 0x58
 #define IMX7_SRC_SBMR2 0x70
 
@@ -406,13 +340,28 @@ internal_boot:
return;
 }
 
-void imx7_boot_save_loc(void)
+static void
+imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
 {
enum bootsource src = BOOTSOURCE_UNKNOWN;
int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
 
-   imx7_get_boot_source(&src, &instance);
+   get_boot_source(&src, &instance);
 
bootsource_set(src);
bootsource_set_instance(instance);
 }
+
+#define IMX_BOOT_SAVE_LOC(soc) \
+   void soc##_boot_save_loc(void)  \
+   {   \
+   imx_boot_save_loc(soc##_get_boot_source);   \
+   }
+
+IMX_BOOT_SAVE_LOC(imx25)
+IMX_BOOT_SAVE_LOC(imx27)
+IMX_BOOT_SAVE_LOC(imx35)
+IMX_BOOT_SAVE_LOC(imx51)
+IMX_BOOT_SAVE_LOC(imx53)
+IMX_BOOT_SAVE_LOC(imx6)
+IMX_BOOT_SAVE_LOC(imx7)
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 00/19] i.MX bootsource bugfixes, refactoring and VFxxx support

2018-04-16 Thread Andrey Smirnov
Everyone:

This patchset is the result of my work on adding support for
bootsource detection of VFxxx as well as fixing a number of
bugs/unsupported corner cases in similar i.MX7 specific code.

NOTE: While VFxxx support is added in this series the code integrating
it into the SoC initalization sequnce is not included. Patch for that
is dependent on recently submitted "i.MX reset reason detection
support" and I didn't want to intertwine two otherwise independent
submissions.

Changes since [v1]:

- Patchset converted to use FIELD_GET macro (which was ported
  from the kernel)

- Spelling fixes

[v1] https://www.spinics.net/lists/u-boot-v2/msg32506.html

Feedback is wellcome!

Thanks,
Andrey Smirnov

Andrey Smirnov (19):
  ARM: i.MX: boot: Coalesce copy-pasted code
  include: Port linux/build_bug.h from Linux kernel
  include: Port linux/bitfield.h from Linux kernel
  ARM: i.MX: Add a function to extract BMOD value
  ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7
  ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7
  ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode
  ARM: i.MX7: boot: Remove incorrect NAND bootsource detection
  ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup
  ARM: i.MX: boot: Remove unnecessary returns
  ARM: i.MX: boot: Move magic values into small functions
  ARM: i.MX: boot: Share code to detect NAND as a boot source
  ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6
  ARM: i.MX53: boot: Move magic numbers info utility functions
  ARM: i.MX6: boot: Move magic numbers into utility functions
  ARM: i.MX7: boot: Move magic numbers into utility functions
  bootsource: Add BOOTSOURCE_CAN
  ARM: VFxxx: Implement code to detect bootsource
  ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI

 arch/arm/boards/datamodul-edm-qmx6/board.c |   2 +-
 arch/arm/boards/dfi-fs700-m60/board.c  |   2 +-
 arch/arm/boards/phytec-som-imx6/board.c|   2 +-
 arch/arm/boards/zii-imx6q-rdu2/lowlevel.c  |   2 +-
 arch/arm/mach-imx/boot.c   | 436 -
 arch/arm/mach-imx/include/mach/generic.h   |   2 +
 arch/arm/mach-imx/xload.c  |   2 +-
 common/bootsource.c|   1 +
 include/bootsource.h   |   1 +
 include/linux/bitfield.h   | 152 ++
 include/linux/bug.h|  25 +-
 include/linux/build_bug.h  |  83 ++
 12 files changed, 550 insertions(+), 160 deletions(-)
 create mode 100644 include/linux/bitfield.h
 create mode 100644 include/linux/build_bug.h

-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 07/19] ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode

2018-04-16 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 7c59c2181..e2696a934 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -303,6 +303,19 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
 #define IMX7_SRC_SBMR1 0x58
 #define IMX7_SRC_SBMR2 0x70
 
+#define IMX_BOOT_SW_INFO_POINTER_ADDR  0x01E8
+#define IMX_BOOT_SW_INFO_BDT_SD0x1
+
+struct imx_boot_sw_info {
+   uint8_t  reserved_1;
+   uint8_t  boot_device_instance;
+   uint8_t  boot_device_type;
+   uint8_t  reserved_2;
+   uint32_t frequency_hz[4]; /* Various frequencies (ARM, AXI,
+  * DDR, etc.). Not used */
+   uint32_t reserved_3[3];
+} __packed;
+
 void imx7_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *src_base = IOMEM(MX7_SRC_BASE_ADDR);
@@ -313,6 +326,33 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
return;
 
if (imx6_bootsource_serial(sbmr2)) {
+   /*
+* On i.MX7 ROM code will try to bood from uSDHC1
+* before entering serial mode. It doesn't seem to be
+* reflected in the contents of SBMR1 in any way when
+* that happens, so we check "Boot_SW_Info" structure
+* (per 6.6.14 Boot information for software) to see
+* if that really happened.
+*
+* FIXME: This behaviour can be inhibited by
+* DISABLE_SDMMC_MFG, but location of that fuse
+* doesn't seem to be documented anywhere. Once that
+* is known it should be taken into account here.
+*/
+   const struct imx_boot_sw_info *info;
+
+   info = (const void *)readl(IMX_BOOT_SW_INFO_POINTER_ADDR);
+
+   if (info->boot_device_type == IMX_BOOT_SW_INFO_BDT_SD) {
+   *src = BOOTSOURCE_MMC;
+   /*
+* We are expecting to only ever boot from
+* uSDHC1 here
+*/
+   WARN_ON(*instance = info->boot_device_instance);
+   return;
+   }
+
*src = BOOTSOURCE_SERIAL;
return;
}
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 02/19] include: Port linux/build_bug.h from Linux kernel

2018-04-16 Thread Andrey Smirnov
Port linux/build_bug.h needed by some of more recent kernel code.

Signed-off-by: Andrey Smirnov 
---
 include/linux/bug.h   | 25 +-
 include/linux/build_bug.h | 83 +++
 2 files changed, 84 insertions(+), 24 deletions(-)
 create mode 100644 include/linux/build_bug.h

diff --git a/include/linux/bug.h b/include/linux/bug.h
index 7295618c9..8367a11ec 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -2,29 +2,6 @@
 #define _LINUX_BUG_H
 
 #include 
-
-#ifdef __CHECKER__
-#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
-#define BUILD_BUG_ON_ZERO(e) (0)
-#define BUILD_BUG_ON_NULL(e) ((void*)0)
-#define BUILD_BUG_ON(condition) (0)
-#else /* __CHECKER__ */
-
-/* Force a compilation error if a constant expression is not a power of 2 */
-#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
-   BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
-
-/* Force a compilation error if condition is true, but also produce a
-   result (of value 0 and type size_t), so the expression can be used
-   e.g. in a structure initializer (or where-ever else comma expressions
-   aren't permitted). */
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
-#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
-
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
-
-#endif
-
+#include 
 
 #endif /* _LINUX_BUG_H */
diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h
new file mode 100644
index 0..43d1fd50d
--- /dev/null
+++ b/include/linux/build_bug.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_BUILD_BUG_H
+#define _LINUX_BUILD_BUG_H
+
+#include 
+
+#ifdef __CHECKER__
+#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
+#define BUILD_BUG_ON_ZERO(e) (0)
+#define BUILD_BUG_ON_INVALID(e) (0)
+#define BUILD_BUG_ON_MSG(cond, msg) (0)
+#define BUILD_BUG_ON(condition) (0)
+#define BUILD_BUG() (0)
+#else /* __CHECKER__ */
+
+/* Force a compilation error if a constant expression is not a power of 2 */
+#define __BUILD_BUG_ON_NOT_POWER_OF_2(n)   \
+   BUILD_BUG_ON(((n) & ((n) - 1)) != 0)
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
+   BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
+
+/*
+ * Force a compilation error if condition is true, but also produce a
+ * result (of value 0 and type size_t), so the expression can be used
+ * e.g. in a structure initializer (or where-ever else comma expressions
+ * aren't permitted).
+ */
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
+
+/*
+ * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
+ * expression but avoids the generation of any code, even if that expression
+ * has side-effects.
+ */
+#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e
+
+/**
+ * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
+ *   error message.
+ * @condition: the condition which the compiler should know is false.
+ *
+ * See BUILD_BUG_ON for description.
+ */
+#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
+
+/**
+ * BUILD_BUG_ON - break compile if a condition is true.
+ * @condition: the condition which the compiler should know is false.
+ *
+ * If you have some code which relies on certain constants being equal, or
+ * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
+ * detect if someone changes it.
+ *
+ * The implementation uses gcc's reluctance to create a negative array, but gcc
+ * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to
+ * inline functions).  Luckily, in 4.3 they added the "error" function
+ * attribute just for this type of case.  Thus, we use a negative sized array
+ * (should always create an error on gcc versions older than 4.4) and then call
+ * an undefined function with the error attribute (should always create an
+ * error on gcc 4.3 and later).  If for some reason, neither creates a
+ * compile-time error, we'll still have a link-time error, which is harder to
+ * track down.
+ */
+#ifndef __OPTIMIZE__
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+#else
+#define BUILD_BUG_ON(condition) \
+   BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
+#endif
+
+/**
+ * BUILD_BUG - break compile if used.
+ *
+ * If you have some code that you expect the compiler to eliminate at
+ * build time, you should use BUILD_BUG to detect if it is
+ * unexpectedly used.
+ */
+#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
+
+#endif /* __CHECKER__ */
+
+#endif /* _LINUX_BUILD_BUG_H */
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 08/19] ARM: i.MX7: boot: Remove incorrect NAND bootsource detection

2018-04-16 Thread Andrey Smirnov
i.MX7 differs from i.MX6 and i.MX53 and bit 7 in SBMR is not used to
signify boot from NAND.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index e2696a934..5484812a6 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -380,10 +380,6 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
break;
}
 
-   /* BOOT_CFG1[7:0] */
-   if (sbmr1 & (1 << 7))
-   *src = BOOTSOURCE_NAND;
-
return;
 }
 
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 09/19] ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup

2018-04-16 Thread Andrey Smirnov
As per "Table 6-33. Boot device selection" from "i.MX 7Dual
Applications Processor Reference Manual, Rev. 1, 01/2018" QSPI is
encoded with 0b0100 and Serial ROM with 0b0110. Fix the original code
to use correct values.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 5484812a6..f9d730f6d 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -366,11 +366,11 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
case 3:
*src = BOOTSOURCE_NAND;
break;
-   case 4:
+   case 6:
*src = BOOTSOURCE_SPI_NOR,
*instance = (sbmr1 >> 9 & 0x7);
break;
-   case 6:
+   case 4:
*src = BOOTSOURCE_SPI; /* Really: qspi */
break;
case 5:
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 04/19] ARM: i.MX: Add a function to extract BMOD value

2018-04-16 Thread Andrey Smirnov
The location of BMDO field in SBMR/SBMR2 registers is consistent
across all i.MX SoCs starting from i.MX53. Add simple helper function
imx53_get_bmod and use it to avoid code duplication.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 4657fa017..9f5ddf629 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -169,12 +170,19 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance)
 }
 
 #define IMX53_SRC_SBMR 0x4
+#define SRC_SBMR_BMOD  GENMASK(25, 24)
+
+static unsigned int imx53_get_bmod(uint32_t r)
+{
+   return FIELD_GET(SRC_SBMR_BMOD, r);
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
 
-   if (((cfg1 >> 24) & 0x3) == 0x3) {
+   if (imx53_get_bmod(cfg1) == 0x3) {
*src = BOOTSOURCE_USB;
*instance = 0;
return;
@@ -225,12 +233,8 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
uint32_t boot_cfg_4_2_0;
-   int boot_mode;
-
-   /* BMOD[1:0] */
-   boot_mode = (sbmr2 >> 24) & 0x3;
 
-   switch (boot_mode) {
+   switch (imx53_get_bmod(sbmr2)) {
case 0: /* Fuses, fall through */
case 2: /* internal boot */
goto internal_boot;
@@ -290,12 +294,8 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
void __iomem *src_base = IOMEM(MX7_SRC_BASE_ADDR);
uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
-   int boot_mode;
-
-   /* BMOD[1:0] */
-   boot_mode = (sbmr2 >> 24) & 0x3;
 
-   switch (boot_mode) {
+   switch (imx53_get_bmod(sbmr2)) {
case 0: /* Fuses, fall through */
case 2: /* internal boot */
goto internal_boot;
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 03/19] include: Port linux/bitfield.h from Linux kernel

2018-04-16 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 include/linux/bitfield.h | 152 +++
 1 file changed, 152 insertions(+)
 create mode 100644 include/linux/bitfield.h

diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
new file mode 100644
index 0..cf2588d81
--- /dev/null
+++ b/include/linux/bitfield.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2014 Felix Fietkau 
+ * Copyright (C) 2004 - 2009 Ivo van Doorn 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _LINUX_BITFIELD_H
+#define _LINUX_BITFIELD_H
+
+#include 
+#include 
+
+/*
+ * Bitfield access macros
+ *
+ * FIELD_{GET,PREP} macros take as first parameter shifted mask
+ * from which they extract the base mask and shift amount.
+ * Mask must be a compilation time constant.
+ *
+ * Example:
+ *
+ *  #define REG_FIELD_A  GENMASK(6, 0)
+ *  #define REG_FIELD_B  BIT(7)
+ *  #define REG_FIELD_C  GENMASK(15, 8)
+ *  #define REG_FIELD_D  GENMASK(31, 16)
+ *
+ * Get:
+ *  a = FIELD_GET(REG_FIELD_A, reg);
+ *  b = FIELD_GET(REG_FIELD_B, reg);
+ *
+ * Set:
+ *  reg = FIELD_PREP(REG_FIELD_A, 1) |
+ *   FIELD_PREP(REG_FIELD_B, 0) |
+ *   FIELD_PREP(REG_FIELD_C, c) |
+ *   FIELD_PREP(REG_FIELD_D, 0x40);
+ *
+ * Modify:
+ *  reg &= ~REG_FIELD_C;
+ *  reg |= FIELD_PREP(REG_FIELD_C, c);
+ */
+
+#define __bf_shf(x) (__builtin_ffsll(x) - 1)
+
+#define __BF_FIELD_CHECK(_mask, _reg, _val, _pfx)  \
+   ({  \
+   BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),  \
+_pfx "mask is not constant");  \
+   BUILD_BUG_ON_MSG(!(_mask), _pfx "mask is zero");\
+   BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?   \
+~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \
+_pfx "value too large for the field"); \
+   BUILD_BUG_ON_MSG((_mask) > (typeof(_reg))~0ull, \
+_pfx "type of reg too small for mask"); \
+   __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \
+ (1ULL << __bf_shf(_mask))); \
+   })
+
+/**
+ * FIELD_FIT() - check if value fits in the field
+ * @_mask: shifted mask defining the field's length and position
+ * @_val:  value to test against the field
+ *
+ * Return: true if @_val can fit inside @_mask, false if @_val is too big.
+ */
+#define FIELD_FIT(_mask, _val) \
+   ({  \
+   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \
+   !typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \
+   })
+
+/**
+ * FIELD_PREP() - prepare a bitfield element
+ * @_mask: shifted mask defining the field's length and position
+ * @_val:  value to put in the field
+ *
+ * FIELD_PREP() masks and shifts up the value.  The result should
+ * be combined with other fields of the bitfield using logical OR.
+ */
+#define FIELD_PREP(_mask, _val)
\
+   ({  \
+   __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");\
+   ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask);   \
+   })
+
+/**
+ * FIELD_GET() - extract a bitfield element
+ * @_mask: shifted mask defining the field's length and position
+ * @_reg:  value of entire bitfield
+ *
+ * FIELD_GET() extracts the field specified by @_mask from the
+ * bitfield passed in as @_reg by masking and shifting it down.
+ */
+#define FIELD_GET(_mask, _reg) \
+   ({  \
+   __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: ");   \
+   (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \
+   })
+
+extern void __compiletime_warning("value doesn't fit into mask")
+__field_overflow(void);
+extern void __compiletime_error("bad bitfield mask")
+__bad_mask(void);
+static __always_inline u64 field_multiplier(u64 field)
+{
+   if ((field | (field - 1)) & ((field | (field - 1)) + 1))
+   __bad_mask();
+   return field & -field;
+}
+static __always_inline u64 field_mask(u64 field)
+{
+   return field / field_multiplier(field);
+}
+#define MAKE_OP(type,base,to,from) \
+static

[PATCH v2 11/19] ARM: i.MX: boot: Move magic values into small functions

2018-04-16 Thread Andrey Smirnov
Move code to extract appropiate BOOT_CFG bits to decode bootsource on
i.MX53, 6, and 7 into small functions for clarity and to allow sharing
the code between i.MX53 and i.MX6.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 44 
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 4bb26d942..61ac8dadf 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -172,11 +172,38 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance)
 #define IMX53_SRC_SBMR 0x4
 #define SRC_SBMR_BMOD  GENMASK(25, 24)
 
+#define __BOOT_CFG(n, m, l)GENMASK((m) + ((n) - 1) * 8, \
+   (l) + ((n) - 1) * 8)
+#define BOOT_CFG1(m, l)__BOOT_CFG(1, m, l)
+
+#define ___BOOT_CFG(n, i)  __BOOT_CFG(n, i, i)
+#define __MAKE_BOOT_CFG_BITS(idx)  \
+   enum {  \
+   BOOT_CFG##idx##_0 = ___BOOT_CFG(idx, 0),\
+   BOOT_CFG##idx##_1 = ___BOOT_CFG(idx, 1),\
+   BOOT_CFG##idx##_2 = ___BOOT_CFG(idx, 2),\
+   BOOT_CFG##idx##_3 = ___BOOT_CFG(idx, 3),\
+   BOOT_CFG##idx##_4 = ___BOOT_CFG(idx, 4),\
+   BOOT_CFG##idx##_5 = ___BOOT_CFG(idx, 5),\
+   BOOT_CFG##idx##_6 = ___BOOT_CFG(idx, 6),\
+   BOOT_CFG##idx##_7 = ___BOOT_CFG(idx, 7),\
+   };
+
+__MAKE_BOOT_CFG_BITS(1)
+#undef __MAKE_BOOT_CFG
+#undef ___BOOT_CFG
+
+
 static unsigned int imx53_get_bmod(uint32_t r)
 {
return FIELD_GET(SRC_SBMR_BMOD, r);
 }
 
+static int imx53_bootsource_internal(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG1(7, 4), r);
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
@@ -188,7 +215,7 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
return;
}
 
-   switch ((cfg1 & 0xff) >> 4) {
+   switch (imx53_bootsource_internal(cfg1)) {
case 2:
*src = BOOTSOURCE_HD;
break;
@@ -263,8 +290,7 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
return;
}
 
-   /* BOOT_CFG1[7:4] */
-   switch ((sbmr1 >> 4) & 0xf) {
+   switch (imx53_bootsource_internal(sbmr1)) {
case 2:
*src = BOOTSOURCE_HD;
break;
@@ -301,9 +327,19 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
 #define IMX7_SRC_SBMR1 0x58
 #define IMX7_SRC_SBMR2 0x70
 
+/*
+ * Re-defined to match the naming in reference manual
+ */
+#define BOOT_CFG(m, l) BOOT_CFG1(m, l)
+
 #define IMX_BOOT_SW_INFO_POINTER_ADDR  0x01E8
 #define IMX_BOOT_SW_INFO_BDT_SD0x1
 
+static unsigned int imx7_bootsource_internal(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG(15, 12), r);
+}
+
 struct imx_boot_sw_info {
uint8_t  reserved_1;
uint8_t  boot_device_instance;
@@ -355,7 +391,7 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
return;
}
 
-   switch ((sbmr1 >> 12) & 0xf) {
+   switch (imx7_bootsource_internal(sbmr1)) {
case 1:
case 2:
*src = BOOTSOURCE_MMC;
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 06/19] ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7

2018-04-16 Thread Andrey Smirnov
On both i.MX6 and i.MX7 (also true for VFxxx) there's an additional
path that leads mask ROM to switch into serial bootloader mode. Add
code to support it.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index dc385ceae..7c59c2181 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -228,6 +228,8 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
 #define IMX6_SRC_SBMR2 0x1c
 #define IMX6_BMOD_SERIAL   0b01
 #define IMX6_BMOD_RESERVED 0b11
+#define IMX6_BMOD_FUSES0b00
+#define BT_FUSE_SELBIT(4)
 
 static bool imx6_bootsource_reserved(uint32_t sbmr2)
 {
@@ -236,7 +238,14 @@ static bool imx6_bootsource_reserved(uint32_t sbmr2)
 
 static bool imx6_bootsource_serial(uint32_t sbmr2)
 {
-   return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL;
+   return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL ||
+   /*
+* If boot from fuses is selected and fuses are not
+* programmed by setting BT_FUSE_SEL, ROM code will
+* fallback to serial mode
+*/
+  (imx53_get_bmod(sbmr2) == IMX6_BMOD_FUSES &&
+   !(sbmr2 & BT_FUSE_SEL));
 }
 
 void imx6_get_boot_source(enum bootsource *src, int *instance)
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 05/19] ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7

2018-04-16 Thread Andrey Smirnov
The algorithm to detect serial mode can be shared between i.M6 and
i.MX7 as wall as simplified a bit by replacing swich goto/break/return
termination logic with more trivial if statements.

This commit also sets the stage for additional improvements in the
commits that follow.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 50 +++-
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 9f5ddf629..dc385ceae 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -226,6 +226,18 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
 
 #define IMX6_SRC_SBMR1 0x04
 #define IMX6_SRC_SBMR2 0x1c
+#define IMX6_BMOD_SERIAL   0b01
+#define IMX6_BMOD_RESERVED 0b11
+
+static bool imx6_bootsource_reserved(uint32_t sbmr2)
+{
+   return imx53_get_bmod(sbmr2) == IMX6_BMOD_RESERVED;
+}
+
+static bool imx6_bootsource_serial(uint32_t sbmr2)
+{
+   return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL;
+}
 
 void imx6_get_boot_source(enum bootsource *src, int *instance)
 {
@@ -234,20 +246,13 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
uint32_t boot_cfg_4_2_0;
 
-   switch (imx53_get_bmod(sbmr2)) {
-   case 0: /* Fuses, fall through */
-   case 2: /* internal boot */
-   goto internal_boot;
-   case 1: /* Serial Downloader */
-   *src = BOOTSOURCE_SERIAL;
-   break;
-   case 3: /* reserved */
-   break;
-   };
-
-   return;
+   if (imx6_bootsource_reserved(sbmr2))
+   return;
 
-internal_boot:
+   if (imx6_bootsource_serial(sbmr2)) {
+   *src = BOOTSOURCE_SERIAL;
+   return;
+   }
 
/* BOOT_CFG1[7:4] */
switch ((sbmr1 >> 4) & 0xf) {
@@ -295,20 +300,13 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
 
-   switch (imx53_get_bmod(sbmr2)) {
-   case 0: /* Fuses, fall through */
-   case 2: /* internal boot */
-   goto internal_boot;
-   case 1: /* Serial Downloader */
-   *src = BOOTSOURCE_SERIAL;
-   break;
-   case 3: /* reserved */
-   break;
-   };
-
-   return;
+   if (imx6_bootsource_reserved(sbmr2))
+   return;
 
-internal_boot:
+   if (imx6_bootsource_serial(sbmr2)) {
+   *src = BOOTSOURCE_SERIAL;
+   return;
+   }
 
switch ((sbmr1 >> 12) & 0xf) {
case 1:
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 12/19] ARM: i.MX: boot: Share code to detect NAND as a boot source

2018-04-16 Thread Andrey Smirnov
Share code to detect NAND as a boot source between i.MX53 and i.MX6
which behave the same in that aspect.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 61ac8dadf..a5dff77df 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -204,6 +204,11 @@ static int imx53_bootsource_internal(uint32_t r)
return FIELD_GET(BOOT_CFG1(7, 4), r);
 }
 
+static bool imx53_bootsource_nand(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG1_7, r);
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
@@ -235,7 +240,7 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
break;
}
 
-   if (cfg1 & (1 << 7))
+   if (imx53_bootsource_nand(cfg1))
*src = BOOTSOURCE_NAND;
 
 
@@ -319,8 +324,7 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
break;
}
 
-   /* BOOT_CFG1[7:0] */
-   if (sbmr1 & (1 << 7))
+   if (imx53_bootsource_nand(sbmr1))
*src = BOOTSOURCE_NAND;
 }
 
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 13/19] ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6

2018-04-16 Thread Andrey Smirnov
We don't need to check if the boot source is NAND in cases when we
already know for a fact that we booted from something else. To avoid
that, move the NAND check to be done inside of default branch of
the preceeding switch statement.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index a5dff77df..f84be5c68 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -237,13 +237,11 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
*src = BOOTSOURCE_MMC;
break;
default:
+   if (imx53_bootsource_nand(cfg1))
+   *src = BOOTSOURCE_NAND;
break;
}
 
-   if (imx53_bootsource_nand(cfg1))
-   *src = BOOTSOURCE_NAND;
-
-
switch (*src) {
case BOOTSOURCE_MMC:
case BOOTSOURCE_SPI:
@@ -321,11 +319,10 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
*instance = (sbmr1 >> 11) & 0x3;
break;
default:
+   if (imx53_bootsource_nand(sbmr1))
+   *src = BOOTSOURCE_NAND;
break;
}
-
-   if (imx53_bootsource_nand(sbmr1))
-   *src = BOOTSOURCE_NAND;
 }
 
 #define IMX7_SRC_SBMR1 0x58
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 14/19] ARM: i.MX53: boot: Move magic numbers info utility functions

2018-04-16 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index f84be5c68..799d5ec93 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -171,10 +171,12 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance)
 
 #define IMX53_SRC_SBMR 0x4
 #define SRC_SBMR_BMOD  GENMASK(25, 24)
+#define IMX53_BMOD_SERIAL  0b11
 
 #define __BOOT_CFG(n, m, l)GENMASK((m) + ((n) - 1) * 8, \
(l) + ((n) - 1) * 8)
 #define BOOT_CFG1(m, l)__BOOT_CFG(1, m, l)
+#define BOOT_CFG3(m, l)__BOOT_CFG(3, m, l)
 
 #define ___BOOT_CFG(n, i)  __BOOT_CFG(n, i, i)
 #define __MAKE_BOOT_CFG_BITS(idx)  \
@@ -204,17 +206,27 @@ static int imx53_bootsource_internal(uint32_t r)
return FIELD_GET(BOOT_CFG1(7, 4), r);
 }
 
+static int imx53_port_select(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG3(5, 4), r);
+}
+
 static bool imx53_bootsource_nand(uint32_t r)
 {
return FIELD_GET(BOOT_CFG1_7, r);
 }
 
+static enum bootsource imx53_bootsource_serial_rom(uint32_t r)
+{
+   return BOOT_CFG1(r, 3) ? BOOTSOURCE_SPI : BOOTSOURCE_I2C;
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
 
-   if (imx53_get_bmod(cfg1) == 0x3) {
+   if (imx53_get_bmod(cfg1) == IMX53_BMOD_SERIAL) {
*src = BOOTSOURCE_USB;
*instance = 0;
return;
@@ -225,10 +237,7 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
*src = BOOTSOURCE_HD;
break;
case 3:
-   if (cfg1 & (1 << 3))
-   *src = BOOTSOURCE_SPI;
-   else
-   *src = BOOTSOURCE_I2C;
+   *src = imx53_bootsource_serial_rom(cfg1);
break;
case 4:
case 5:
@@ -246,7 +255,7 @@ void imx53_get_boot_source(enum bootsource *src, int 
*instance)
case BOOTSOURCE_MMC:
case BOOTSOURCE_SPI:
case BOOTSOURCE_I2C:
-   *instance = (cfg1 >> 20) & 0x3;
+   *instance = imx53_port_select(cfg1);
break;
default:
*instance = 0;
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 10/19] ARM: i.MX: boot: Remove unnecessary returns

2018-04-16 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index f9d730f6d..4bb26d942 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -296,8 +296,6 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
/* BOOT_CFG1[7:0] */
if (sbmr1 & (1 << 7))
*src = BOOTSOURCE_NAND;
-
-   return;
 }
 
 #define IMX7_SRC_SBMR1 0x58
@@ -379,8 +377,6 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
default:
break;
}
-
-   return;
 }
 
 static void
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 16/19] ARM: i.MX7: boot: Move magic numbers into utility functions

2018-04-16 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 60307ffb6..3f67c2510 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -389,6 +389,16 @@ static unsigned int imx7_bootsource_internal(uint32_t r)
return FIELD_GET(BOOT_CFG(15, 12), r);
 }
 
+static int imx7_boot_instance_spi_nor(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG(11, 9), r);
+}
+
+static int imx7_boot_instance_mmc(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG(11, 10), r);
+}
+
 struct imx_boot_sw_info {
uint8_t  reserved_1;
uint8_t  boot_device_instance;
@@ -444,14 +454,14 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
case 1:
case 2:
*src = BOOTSOURCE_MMC;
-   *instance = (sbmr1 >> 10 & 0x3);
+   *instance = imx7_boot_instance_mmc(sbmr1);
break;
case 3:
*src = BOOTSOURCE_NAND;
break;
case 6:
*src = BOOTSOURCE_SPI_NOR,
-   *instance = (sbmr1 >> 9 & 0x7);
+   *instance = imx7_boot_instance_spi_nor(sbmr1);
break;
case 4:
*src = BOOTSOURCE_SPI; /* Really: qspi */
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 19/19] ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI

2018-04-16 Thread Andrey Smirnov
We use BOOTSOURCE_SPI to denote, among other things, QSPI on i.MX7 and
VFxxx, whereas on i.MX6 it is used to mean SPI-NOR. To make functions
like imx_xload() work consistently across various i.MX platforms use
already existent BOOTSOURCE_SPI_NOR constant to mean booting from
SPI-NOR on i.MX6 as well.

Replace all in-tree code that relying on the old value as well.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/boards/datamodul-edm-qmx6/board.c | 2 +-
 arch/arm/boards/dfi-fs700-m60/board.c  | 2 +-
 arch/arm/boards/phytec-som-imx6/board.c| 2 +-
 arch/arm/boards/zii-imx6q-rdu2/lowlevel.c  | 2 +-
 arch/arm/mach-imx/boot.c   | 2 +-
 arch/arm/mach-imx/xload.c  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/datamodul-edm-qmx6/board.c 
b/arch/arm/boards/datamodul-edm-qmx6/board.c
index 043a93461..d93c940e3 100644
--- a/arch/arm/boards/datamodul-edm-qmx6/board.c
+++ b/arch/arm/boards/datamodul-edm-qmx6/board.c
@@ -132,7 +132,7 @@ static int realq7_device_init(void)
}
break;
default:
-   case BOOTSOURCE_SPI:
+   case BOOTSOURCE_SPI_NOR:
of_device_enable_path("/chosen/environment-spi");
break;
}
diff --git a/arch/arm/boards/dfi-fs700-m60/board.c 
b/arch/arm/boards/dfi-fs700-m60/board.c
index bef4612d9..2cb8e3106 100644
--- a/arch/arm/boards/dfi-fs700-m60/board.c
+++ b/arch/arm/boards/dfi-fs700-m60/board.c
@@ -105,7 +105,7 @@ static int dfi_fs700_m60_init(void)
 
phy_register_fixup_for_uid(PHY_ID_AR8031, AR_PHY_ID_MASK, 
ar8031_phy_fixup);
 
-   if (bootsource_get() == BOOTSOURCE_SPI)
+   if (bootsource_get() == BOOTSOURCE_SPI_NOR)
flag_spi |= BBU_HANDLER_FLAG_DEFAULT;
else
flag_mmc |= BBU_HANDLER_FLAG_DEFAULT;
diff --git a/arch/arm/boards/phytec-som-imx6/board.c 
b/arch/arm/boards/phytec-som-imx6/board.c
index 717a22963..ecb22f956 100644
--- a/arch/arm/boards/phytec-som-imx6/board.c
+++ b/arch/arm/boards/phytec-som-imx6/board.c
@@ -152,7 +152,7 @@ static int physom_imx6_devices_init(void)
environment_path = basprintf("/chosen/environment-nand");
envdev = "NAND flash";
break;
-   case BOOTSOURCE_SPI:
+   case BOOTSOURCE_SPI_NOR:
environment_path = basprintf("/chosen/environment-spinor");
envdev = "SPI NOR flash";
break;
diff --git a/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c 
b/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
index 22ffdf85e..3b4dbd212 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
@@ -290,7 +290,7 @@ static noinline void rdu2_sram_setup(void)
write_regs(imx6q_dcd, ARRAY_SIZE(imx6q_dcd));
 
imx6_get_boot_source(&bootsrc, &instance);
-   if (bootsrc == BOOTSOURCE_SPI)
+   if (bootsrc == BOOTSOURCE_SPI_NOR)
imx6_spi_start_image(0);
else
imx6_esdhc_start_image(instance);
diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index f8a04d8f3..bb5318510 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -320,7 +320,7 @@ static enum bootsource imx6_bootsource_serial_rom(uint32_t 
sbmr)
const int source = __imx6_bootsource_serial_rom(sbmr);
 
return source < IMX6_BOOTSOURCE_SERIAL_ROM_I2C1 ?
-   BOOTSOURCE_SPI : BOOTSOURCE_I2C;
+   BOOTSOURCE_SPI_NOR : BOOTSOURCE_I2C;
 }
 
 static int imx6_boot_instance_serial_rom(uint32_t sbmr)
diff --git a/arch/arm/mach-imx/xload.c b/arch/arm/mach-imx/xload.c
index 16d56ab28..921e9ade2 100644
--- a/arch/arm/mach-imx/xload.c
+++ b/arch/arm/mach-imx/xload.c
@@ -24,7 +24,7 @@ static __noreturn int imx_xload(void)
pr_info("booting from MMC\n");
buf = bootstrap_read_disk("disk0.0", "fat");
break;
-   case BOOTSOURCE_SPI:
+   case BOOTSOURCE_SPI_NOR:
pr_info("booting from SPI\n");
buf = bootstrap_read_devfs("dataflash0", false,
   SZ_256K, SZ_1M, SZ_1M);
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 15/19] ARM: i.MX6: boot: Move magic numbers into utility functions

2018-04-16 Thread Andrey Smirnov
Move magic numbers and algorithm for determining Serial ROM bootsource
and boot instance into utility functions. Add a comment on the logic
behing the latter while at it.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 67 ++--
 1 file changed, 53 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 799d5ec93..60307ffb6 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -176,7 +176,9 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance)
 #define __BOOT_CFG(n, m, l)GENMASK((m) + ((n) - 1) * 8, \
(l) + ((n) - 1) * 8)
 #define BOOT_CFG1(m, l)__BOOT_CFG(1, m, l)
+#define BOOT_CFG2(m, l)__BOOT_CFG(2, m, l)
 #define BOOT_CFG3(m, l)__BOOT_CFG(3, m, l)
+#define BOOT_CFG4(m, l)__BOOT_CFG(4, m, l)
 
 #define ___BOOT_CFG(n, i)  __BOOT_CFG(n, i, i)
 #define __MAKE_BOOT_CFG_BITS(idx)  \
@@ -192,6 +194,8 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance)
};
 
 __MAKE_BOOT_CFG_BITS(1)
+__MAKE_BOOT_CFG_BITS(2)
+__MAKE_BOOT_CFG_BITS(4)
 #undef __MAKE_BOOT_CFG
 #undef ___BOOT_CFG
 
@@ -287,12 +291,57 @@ static bool imx6_bootsource_serial(uint32_t sbmr2)
!(sbmr2 & BT_FUSE_SEL));
 }
 
+static int __imx6_bootsource_serial_rom(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG4(2, 0), r);
+}
+
+/*
+ * Serial ROM bootsource on i.MX6 are as follows:
+ *
+ * 000 - ECSPI-1
+ * 001 - ECSPI-2
+ * 010 - ECSPI-3
+ * 011 - ECSPI-4
+ * 100 - ECSPI-5
+ * 101 - I2C1
+ * 110 - I2C2
+ * 111 - I2C3
+ *
+ * There's no single bit that would tell us we are booting from I2C or
+ * SPI, so we just have to compare the "source" agains the value for
+ * I2C1 for both: calculating bootsource and boot instance.
+ */
+#define IMX6_BOOTSOURCE_SERIAL_ROM_I2C10b101
+
+static enum bootsource imx6_bootsource_serial_rom(uint32_t sbmr)
+{
+   const int source = __imx6_bootsource_serial_rom(sbmr);
+
+   return source < IMX6_BOOTSOURCE_SERIAL_ROM_I2C1 ?
+   BOOTSOURCE_SPI : BOOTSOURCE_I2C;
+}
+
+static int imx6_boot_instance_serial_rom(uint32_t sbmr)
+{
+   const int source = __imx6_bootsource_serial_rom(sbmr);
+
+   if (source < IMX6_BOOTSOURCE_SERIAL_ROM_I2C1)
+   return source;
+
+   return source - IMX6_BOOTSOURCE_SERIAL_ROM_I2C1;
+}
+
+static int imx6_boot_instance_mmc(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG2(4, 3), r);
+}
+
 void imx6_get_boot_source(enum bootsource *src, int *instance)
 {
void __iomem *src_base = IOMEM(MX6_SRC_BASE_ADDR);
uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
-   uint32_t boot_cfg_4_2_0;
 
if (imx6_bootsource_reserved(sbmr2))
return;
@@ -307,25 +356,15 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
*src = BOOTSOURCE_HD;
break;
case 3:
-   /* BOOT_CFG4[2:0] */
-   boot_cfg_4_2_0 = (sbmr1 >> 24) & 0x7;
-
-   if (boot_cfg_4_2_0 > 4) {
-   *src = BOOTSOURCE_I2C;
-   *instance = boot_cfg_4_2_0 - 5;
-   } else {
-   *src = BOOTSOURCE_SPI;
-   *instance = boot_cfg_4_2_0;
-   }
+   *src = imx6_bootsource_serial_rom(sbmr1);
+   *instance = imx6_boot_instance_serial_rom(sbmr1);
break;
case 4:
case 5:
case 6:
case 7:
*src = BOOTSOURCE_MMC;
-
-   /* BOOT_CFG2[4:3] */
-   *instance = (sbmr1 >> 11) & 0x3;
+   *instance = imx6_boot_instance_mmc(sbmr1);
break;
default:
if (imx53_bootsource_nand(sbmr1))
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 18/19] ARM: VFxxx: Implement code to detect bootsource

2018-04-16 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/boot.c | 91 
 arch/arm/mach-imx/include/mach/generic.h |  2 +
 2 files changed, 93 insertions(+)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 3f67c2510..f8a04d8f3 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* [CTRL][TYPE] */
 static const enum bootsource locations[4][4] = {
@@ -474,6 +475,95 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
}
 }
 
+static int vf610_boot_instance_spi(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG1_1, r);
+}
+
+static int vf610_boot_instance_nor(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG1_3, r);
+}
+
+/*
+ * Vybrid's Serial ROM boot sources (BOOT_CFG4[2:0]) are as follows:
+ *
+ * 000 - SPI0
+ * 001 - SPI1
+ * 010 - SPI2
+ * 011 - SPI3
+ * 100 - I2C0
+ * 101 - I2C1
+ * 110 - I2C2
+ * 111 - I2C3
+ *
+ * Which we can neatly divide in two halves and use MSb to detect if
+ * bootsource is I2C or SPI EEPROM and 2 LSbs directly as boot
+ * insance.
+ */
+static enum bootsource vf610_bootsource_serial_rom(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG4_2, r) ? BOOTSOURCE_I2C : BOOTSOURCE_SPI_NOR;
+}
+
+static int vf610_boot_instance_serial_rom(uint32_t r)
+{
+   return __imx6_bootsource_serial_rom(r) & 0b11;
+}
+
+static int vf610_boot_instance_can(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG1_0, r);
+}
+
+static int vf610_boot_instance_mmc(uint32_t r)
+{
+   return FIELD_GET(BOOT_CFG2_3, r);
+}
+
+void vf610_get_boot_source(enum bootsource *src, int *instance)
+{
+   void __iomem *src_base = IOMEM(VF610_SRC_BASE_ADDR);
+   uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
+   uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
+
+   if (imx6_bootsource_reserved(sbmr2))
+   return;
+
+   if (imx6_bootsource_serial(sbmr2)) {
+   *src = BOOTSOURCE_SERIAL;
+   return;
+   }
+
+   switch (imx53_bootsource_internal(sbmr1)) {
+   case 0:
+   *src = BOOTSOURCE_SPI; /* Really: qspi */
+   *instance = vf610_boot_instance_spi(sbmr1);
+   break;
+   case 1:
+   *src = BOOTSOURCE_NOR;
+   *instance = vf610_boot_instance_nor(sbmr1);
+   break;
+   case 2:
+   *src = vf610_bootsource_serial_rom(sbmr1);
+   *instance = vf610_boot_instance_serial_rom(sbmr1);
+   break;
+   case 3:
+   *src = BOOTSOURCE_CAN;
+   *instance = vf610_boot_instance_can(sbmr1);
+   break;
+   case 6:
+   case 7:
+   *src = BOOTSOURCE_MMC;
+   *instance = vf610_boot_instance_mmc(sbmr1);
+   break;
+   default:
+   if (imx53_bootsource_nand(sbmr1))
+   *src = BOOTSOURCE_NAND;
+   break;
+   }
+}
+
 static void
 imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
 {
@@ -499,3 +589,4 @@ IMX_BOOT_SAVE_LOC(imx51)
 IMX_BOOT_SAVE_LOC(imx53)
 IMX_BOOT_SAVE_LOC(imx6)
 IMX_BOOT_SAVE_LOC(imx7)
+IMX_BOOT_SAVE_LOC(vf610)
diff --git a/arch/arm/mach-imx/include/mach/generic.h 
b/arch/arm/mach-imx/include/mach/generic.h
index cb5675185..ad9d9cb02 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -15,6 +15,7 @@ void imx51_boot_save_loc(void);
 void imx53_boot_save_loc(void);
 void imx6_boot_save_loc(void);
 void imx7_boot_save_loc(void);
+void vf610_boot_save_loc(void);
 
 void imx25_get_boot_source(enum bootsource *src, int *instance);
 void imx35_get_boot_source(enum bootsource *src, int *instance);
@@ -22,6 +23,7 @@ void imx51_get_boot_source(enum bootsource *src, int 
*instance);
 void imx53_get_boot_source(enum bootsource *src, int *instance);
 void imx6_get_boot_source(enum bootsource *src, int *instance);
 void imx7_get_boot_source(enum bootsource *src, int *instance);
+void vf610_get_boot_source(enum bootsource *src, int *instance);
 
 int imx1_init(void);
 int imx21_init(void);
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 17/19] bootsource: Add BOOTSOURCE_CAN

2018-04-16 Thread Andrey Smirnov
Add BOOTSOURCE_CAN for SoCs that can boot from CAN interface.

Signed-off-by: Andrey Smirnov 
---
 common/bootsource.c  | 1 +
 include/bootsource.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/common/bootsource.c b/common/bootsource.c
index 707b07924..78ecd8267 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -36,6 +36,7 @@ static const char *bootsource_str[] = {
[BOOTSOURCE_HD] = "harddisk",
[BOOTSOURCE_USB] = "usb",
[BOOTSOURCE_NET] = "net",
+   [BOOTSOURCE_CAN] = "can",
 };
 
 static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
diff --git a/include/bootsource.h b/include/bootsource.h
index c6d3b3a98..064f6b9a2 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -16,6 +16,7 @@ enum bootsource {
BOOTSOURCE_HD,
BOOTSOURCE_USB,
BOOTSOURCE_NET,
+   BOOTSOURCE_CAN,
 };
 
 #define BOOTSOURCE_INSTANCE_UNKNOWN-1
-- 
2.14.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] commands: i2c_write: enable reg == 0 too

2018-04-16 Thread Antony Pavlov
This commit fixes the mistake introduced in the commit 34fadb685905
('commands: i2c_write: enable raw write to address').
The intended behaviour for i2c_write command is
"use raw i2c write only if reg address is not defined".
Before the commit 34fadb685905 reg address == 0
was acceptable. After the commit 34fadb685905 reg address == 0
became unacceptable ("undefined") and will lead to raw i2c write.

Signed-off-by: Antony Pavlov 
---
 commands/i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/i2c.c b/commands/i2c.c
index 21c39fe5af..f0d16af0cb 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -131,7 +131,7 @@ static int do_i2c_write(int argc, char *argv[])
for (i = 0; i < count; i++)
*(buf + i) = (char) simple_strtol(argv[optind+i], NULL, 0);
 
-   if (reg > 0) {
+   if (reg >= 0) {
ret = i2c_write_reg(&client, reg | wide, buf, count);
} else {
ret = i2c_master_send(&client, buf, count);
-- 
2.17.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 01/10] Add initial RISC-V architecture support

2018-04-16 Thread Sascha Hauer
Hi Antony,

On Sun, Apr 15, 2018 at 02:28:49PM +0300, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov 
> ---
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> new file mode 100644
> index 00..d65e87acd8
> --- /dev/null
> +++ b/arch/riscv/Kconfig
> @@ -0,0 +1,62 @@
> +config RISCV
> + def_bool y
> + select GENERIC_FIND_NEXT_BIT
> + select HAVE_CONFIGURABLE_MEMORY_LAYOUT
> + select HAVE_CONFIGURABLE_TEXT_BASE
> + select GPIOLIB
> + select OFTREE
> + select COMMON_CLK
> + select COMMON_CLK_OF_PROVIDER
> + select CLKDEV_LOOKUP
> +
> +config ARCH_TEXT_BASE
> + hex
> + default 0x0
> +
> +config GENERIC_LINKER_SCRIPT
> + def_bool y

Do we need this? The linker script should be universal enough to be used
by all boards.

> diff --git a/arch/riscv/dts/skeleton.dtsi b/arch/riscv/dts/skeleton.dtsi
> new file mode 100644
> index 00..38ead821bb
> --- /dev/null
> +++ b/arch/riscv/dts/skeleton.dtsi
> @@ -0,0 +1,13 @@
> +/*
> + * Skeleton device tree; the bare minimum needed to boot; just include and
> + * add a compatible value.  The bootloader will typically populate the memory
> + * node.
> + */
> +
> +/ {
> + #address-cells = <2>;
> + #size-cells = <1>;
> + chosen { };
> + aliases { };
> + memory { device_type = "memory"; reg = <0 0 0>; };
> +};

skeleton.dtsi should no longer be used. For example we should now have
memory@adr {}; instead of memory {};. Since "adr" is board/SoC specific
we can't put it in a generic file.

> diff --git a/arch/riscv/lib/ashldi3.c b/arch/riscv/lib/ashldi3.c
> new file mode 100644
> index 00..cbdbcbb6a9
> --- /dev/null
> +++ b/arch/riscv/lib/ashldi3.c
> @@ -0,0 +1,28 @@
> +#include 
> +
> +#include "libgcc.h"
> +
> +long long __ashldi3(long long u, word_type b)
> +{

Can we have generic C variants for these files? The Kernel has these
symbols in lib/ and they can be selected by "select GENERIC_ASHLDI3"

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 02/10] RISC-V: add Erizo SoC support

2018-04-16 Thread Sascha Hauer
On Sun, Apr 15, 2018 at 02:28:50PM +0300, Antony Pavlov wrote:
> Erizo is an opensource hardware SoC for FPGA.
> 
> Signed-off-by: Antony Pavlov 
> ---
>  arch/riscv/Kconfig | 11 ++
>  arch/riscv/Makefile|  3 ++
>  arch/riscv/boards/erizo-generic/.gitignore |  1 +
>  arch/riscv/boards/erizo-generic/Makefile   |  1 +
>  arch/riscv/boards/erizo-generic/board.c| 28 +
>  arch/riscv/dts/erizo.dtsi  | 46 ++
>  arch/riscv/dts/erizo_generic.dts   | 32 +++
>  arch/riscv/mach-erizo/Kconfig  | 11 ++
>  arch/riscv/mach-erizo/Makefile |  3 ++
>  9 files changed, 136 insertions(+)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index d65e87acd8..fe79cb49b5 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -18,6 +18,15 @@ config GENERIC_LINKER_SCRIPT
>  
>  menu "Machine selection"
>  
> +choice
> + prompt "System type"
> + default MACH_ERIZO
> +
> +config MACH_ERIZO
> + bool "erizo family"
> +
> +endchoice
> +
>  choice
>   prompt "Base ISA"
>   default ARCH_RV32I
> @@ -51,6 +60,8 @@ config BUILTIN_DTB_NAME
>   string "DTB to build into the barebox image"
>   depends on BUILTIN_DTB
>  
> +source arch/riscv/mach-erizo/Kconfig
> +
>  endmenu
>  
>  source common/Kconfig
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index e9c407354c..9a3921065c 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -11,6 +11,9 @@ cflags-y += -Wall -Wmissing-prototypes -Wstrict-prototypes \
>  LDFLAGS += $(ldflags-y)
>  LDFLAGS_barebox += -nostdlib
>  
> +machine-$(CONFIG_MACH_ERIZO) := erizo
> +board-$(CONFIG_BOARD_ERIZO_GENERIC)  := erizo-generic
> +
>  TEXT_BASE = $(CONFIG_TEXT_BASE)
>  CPPFLAGS += -DTEXT_BASE=$(CONFIG_TEXT_BASE)
>  
> diff --git a/arch/riscv/boards/erizo-generic/.gitignore 
> b/arch/riscv/boards/erizo-generic/.gitignore
> new file mode 100644
> index 00..d1165788c9
> --- /dev/null
> +++ b/arch/riscv/boards/erizo-generic/.gitignore
> @@ -0,0 +1 @@
> +barebox.lds
> diff --git a/arch/riscv/boards/erizo-generic/Makefile 
> b/arch/riscv/boards/erizo-generic/Makefile
> new file mode 100644
> index 00..dcfc2937d3
> --- /dev/null
> +++ b/arch/riscv/boards/erizo-generic/Makefile
> @@ -0,0 +1 @@
> +obj-y += board.o
> diff --git a/arch/riscv/boards/erizo-generic/board.c 
> b/arch/riscv/boards/erizo-generic/board.c
> new file mode 100644
> index 00..46c9ca34f0
> --- /dev/null
> +++ b/arch/riscv/boards/erizo-generic/board.c
> @@ -0,0 +1,28 @@
> +/*
> + * Copyright (C) 2017 Antony Pavlov 
> + *
> + * This file is part of barebox.
> + * See file CREDITS for list of people who contributed to this project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +static int hostname_init(void)
> +{
> + barebox_set_hostname("erizo-generic");
> +
> + return 0;
> +}
> +postcore_initcall(hostname_init);
> diff --git a/arch/riscv/dts/erizo.dtsi b/arch/riscv/dts/erizo.dtsi
> new file mode 100644
> index 00..1660ad1040
> --- /dev/null
> +++ b/arch/riscv/dts/erizo.dtsi
> @@ -0,0 +1,46 @@
> +/dts-v1/;
> +
> +#include "skeleton.dtsi"
> +
> +/ {
> + compatible = "miet-riscv-workgroup,erizo";
> +
> + #address-cells = <1>;
> + #size-cells = <1>;
> +
> + clocks {
> + ref_clk: ref_clk {
> + #clock-cells = <0>;
> + compatible = "fixed-clock";
> + clock-frequency = <2400>;
> + };
> + };
> +
> + cpus {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + cpu@0 {
> + device_type = "cpu";
> + compatible = "cliffordwolf,picorv32";
> + clocks = <&ref_clk>;
> + reg = <0>;
> + };
> + };
> +
> + uart0: uart@9000 {
> + compatible = "ns16550a";
> + reg = <0x9000 0x20>;
> + reg-shift = <2>;
> + clocks = <&ref_clk>;
> + };
> +
> + gpio0: gpio@9100 {
> + compatible = "wd,mbl-gpio";
> + reg-names = "dat", "dirout";
> + reg = <0x9100 0x4>,
> + <0x9104 0x4>;
> + #gpio-cells = <2>;
> + gpio-controller;
> + };
> +};
> diff --git a/arch/riscv/dts/erizo_generic.dts 
> b/arch/riscv/dts/erizo_generic.dts
> new file mode 100644
> index 0

Re: [PATCH 07/10] RISC-V: erizo: add nmon image creation

2018-04-16 Thread Sascha Hauer
On Sun, Apr 15, 2018 at 02:28:55PM +0300, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov 
> ---
>  arch/riscv/Makefile  | 11 +++
>  scripts/erizo-nmon-image |  3 +++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index 9a3921065c..c837d4e2e4 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -73,3 +73,14 @@ CFLAGS += $(cflags-y)
>  lds-y:= arch/riscv/lib/barebox.lds
>  
>  CLEAN_FILES += arch/riscv/lib/barebox.lds
> +
> +ifeq ($(CONFIG_MACH_ERIZO),y)
> +KBUILD_IMAGE := barebox.erizo.nmon
> +endif
> +
> +quiet_cmd_erizo_nmon_image = MKIMAGE $@
> +  cmd_erizo_nmon_image = $(srctree)/scripts/erizo-nmon-image $< $@ || \
> + echo "WARNING: Couldn't create erizo nmon image due to previous errors."
> +
> +barebox.erizo.nmon: $(KBUILD_BINARY) FORCE
> + $(call if_changed,erizo_nmon_image)
> diff --git a/scripts/erizo-nmon-image b/scripts/erizo-nmon-image
> new file mode 100755
> index 00..4f0185b6de
> --- /dev/null
> +++ b/scripts/erizo-nmon-image
> @@ -0,0 +1,3 @@
> +#!/bin/sh
> +
> +hexdump -v -e '/4 "%08x\n"' $1 | perl -e '$a = 0x8000; while (<>) { 
> chop; printf("expect \"nmon> \"\n"); printf("send \"w%08x$_\"\n", $a); $a = 
> $a + 4; }' > $2
> -- 

Maybe add some

if [ $# != 2 ]; then echo "usage: ..."; exit 1; fi

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: MIPS parallel build breakage

2018-04-16 Thread Sascha Hauer
On Thu, Mar 01, 2018 at 12:07:29PM +0100, Sascha Hauer wrote:
> Hi Sam and Antony,
> 
> (Antony because you introduced this and Sam because you have intimate
> knowledge with our build system ;)
> 
> I am trying to solve a problem that annoys me for some years now. The
> problem is that the MIPS defconfigs regularly fail in my autobuilder.
> I usually help myself with trying it again and most of the time it
> then works, but doing this for years increases the pressure to do
> something.
> 
> What happens is that the MIPS builds use include/generated/compile.h:
> 
> > arch/mips/include/asm/pbl_macros.h:28:#include 
> 
> This often ends in:
> 
> > In file included from arch/mips/boot/start.S:20:0: 
> > arch/mips/include/asm/pbl_macros.h:28:31:
> > fatal error: generated/compile.h: No such file or directory
> > compilation terminated.
> 
> include/generated/compile.h is generated in common/Makefile:
> 
> > include/generated/compile.h: FORCE
> > @$($(quiet)chk_compile.h)
> > $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
> > "$(UTS_MACHINE)" "$(CC) $(KBUILD_CFLAGS)"
> 
> Other users of this file add an explicit dependency on it:
> 
> > # dependencies on generated files need to be listed explicitly
> > $(obj)/version.o: include/generated/compile.h
> 
> This only seems to work though when the dependent file is in the same
> directory, but not when the file is in arch/mips/boot/.
> 
> I tried doing the include/generated/compile.h in Makefile instead of
> common/Makefile, but then the version counting gets confused and causes
> unnecessary rebuilds.
> 
> Any ideas how to solve this?

We still have no solution for this. I dropped MIPS from my autobuilder,
so we won't catch any build errors on MIPS anymore :(

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: Question about barebox*/drivers/mfd/mc34704.c and ACCURATE I²C mode ...

2018-04-16 Thread Sascha Hauer
Hi Roland,

On Mon, Apr 16, 2018 at 01:19:39PM +0300, Baruch Siach wrote:
> Hi Roland,
> 
> On Mon, Apr 16, 2018 at 09:52:14AM +, Mainz, Roland wrote:
> > Two small questions about drivers/mfd/mc34704.c in the barebox codebase:
> > 1. mc34704 has an ACCURATE bit (I2CSET1, see 
> > https://www.nxp.com/docs/en/data-sheet/MC34704.pdf) which requires that all 
> > read/write commands are send twice - does the barebox code have any support 
> > for that in the current versions ?
> > 2. Is this "accurate I²C communication mode" enabled by that bit a 
> > vendor-specific protocol extension or is it part of the I²C standard ?

I never heard of "accurate I²C", it must be something the chip designers
have invented. Also there is no support for it neither in the mc34704
driver nor in the generic I²C support.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 03/10] ARM: i.MX6: Record reset reason as a part of startup

2018-04-16 Thread Sascha Hauer
On Mon, Apr 16, 2018 at 06:28:11AM -0700, Andrey Smirnov wrote:
> On Mon, Apr 16, 2018 at 12:13 AM, Sascha Hauer  wrote:
> > Hi Andrey,
> >
> > On Sat, Apr 14, 2018 at 10:50:17AM -0700, Andrey Smirnov wrote:
> >> Signed-off-by: Andrey Smirnov 
> >> ---
> >>  arch/arm/mach-imx/imx6.c  | 4 +++-
> >>  arch/arm/mach-imx/include/mach/reset-reason.h | 2 ++
> >>  2 files changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
> >> index 14a1cba5a..3d81c2785 100644
> >> --- a/arch/arm/mach-imx/imx6.c
> >> +++ b/arch/arm/mach-imx/imx6.c
> >> @@ -19,6 +19,7 @@
> >>  #include 
> >>  #include 
> >>  #include 
> >> +#include 
> >>  #include 
> >>  #include 
> >>  #include 
> >> @@ -151,6 +152,7 @@ int imx6_init(void)
> >>  {
> >>   const char *cputypestr;
> >>   u32 mx6_silicon_revision;
> >> + void __iomem *src = IOMEM(MX6_SRC_BASE_ADDR);
> >>
> >>   imx6_init_lowlevel();
> >>
> >> @@ -195,7 +197,7 @@ int imx6_init(void)
> >>   }
> >>
> >>   imx_set_silicon_revision(cputypestr, mx6_silicon_revision);
> >> -
> >> + imx_set_reset_reason(src + IMX6_SRC_SRSR);
> >
> > This will get overwritten by the watchdog driver if enabled.
> >
> 
> I am not sure I see how. Imx_watchdog_detect_reset_source() reports
> reset sources with the same priority as this code, so
> reset_source_set_priority() should bail out early without changing
> anything in that case.

I wasn't aware there is a priority mechanism involved. Indeed the
behaviour seems to be correct. Maybe we should even higher the priority
of imx_set_reset_reason()? This information seems the more accurate one,
so it should be used, and we shouldn't depend on the order of execution.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] ARM: i.MX6: Make cpu_is_mx6xy() greppable

2018-04-16 Thread Sascha Hauer
Grepping for cpu_is_mx6 will not find the definitions of this function
because it is hidden behind a macro. Add a comment containing all
functions defined here to make it greppable.

Signed-off-by: Sascha Hauer 
---
 arch/arm/mach-imx/include/mach/imx6.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/mach-imx/include/mach/imx6.h 
b/arch/arm/mach-imx/include/mach/imx6.h
index e06ca4e235..5701bd480c 100644
--- a/arch/arm/mach-imx/include/mach/imx6.h
+++ b/arch/arm/mach-imx/include/mach/imx6.h
@@ -93,6 +93,13 @@ int imx6_cpu_type(void);
return cpu_mx6_is_##str();  \
}
 
+/*
+ * Below are defined:
+ *
+ * cpu_is_mx6s(), cpu_is_mx6dl(), cpu_is_mx6q(), cpu_is_mx6qp(), cpu_is_mx6d(),
+ * cpu_is_mx6dp(), cpu_is_mx6sx(), cpu_is_mx6sl(), cpu_is_mx6ul(),
+ * cpu_is_mx6ull()
+ */
 DEFINE_MX6_CPU_TYPE(mx6s, IMX6_CPUTYPE_IMX6S);
 DEFINE_MX6_CPU_TYPE(mx6dl, IMX6_CPUTYPE_IMX6DL);
 DEFINE_MX6_CPU_TYPE(mx6q, IMX6_CPUTYPE_IMX6Q);
-- 
2.16.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 01/19] ARM: i.MX: boot: Coalesce copy-pasted code

2018-04-16 Thread Sascha Hauer
On Mon, Apr 16, 2018 at 12:31:39PM -0700, Andrey Smirnov wrote:
> All of the instances of imx*_boot_save_loc() do exactly the same thing with
> the only difference being SoC-specific imx*_get_boot_source
> call. Convert the code into a generic function taking function pointer
> + a macro to take care of the boilerplate.
> 
> Signed-off-by: Andrey Smirnov 
> ---
>  arch/arm/mach-imx/boot.c | 85 
> ++--
>  1 file changed, 17 insertions(+), 68 deletions(-)
> 
> +imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
>  {
>   enum bootsource src = BOOTSOURCE_UNKNOWN;
>   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
>  
> - imx7_get_boot_source(&src, &instance);
> + get_boot_source(&src, &instance);
>  
>   bootsource_set(src);
>   bootsource_set_instance(instance);
>  }
> +
> +#define IMX_BOOT_SAVE_LOC(soc)   \
> + void soc##_boot_save_loc(void)  \
> + {   \
> + imx_boot_save_loc(soc##_get_boot_source);   \
> + }
> +
> +IMX_BOOT_SAVE_LOC(imx25)
> +IMX_BOOT_SAVE_LOC(imx27)
> +IMX_BOOT_SAVE_LOC(imx35)
> +IMX_BOOT_SAVE_LOC(imx51)
> +IMX_BOOT_SAVE_LOC(imx53)
> +IMX_BOOT_SAVE_LOC(imx6)
> +IMX_BOOT_SAVE_LOC(imx7)

I do not really like this patch. Yes, it saves a few lines of code, but
with the cost of making it less readable.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox