Re: [PATCH] nand-bb: fix writing to the end of a .bb device

2017-03-01 Thread Sascha Hauer
On Wed, Mar 01, 2017 at 04:57:03PM +0100, Uwe Kleine-König wrote:
> As nand_bb_write_buf calls mtd_write(bb->mtd, cur_ofs, now, ...) the
> limit that now should be checked against is bb->mtd->size - cur_ofs.
> 
> Signed-off-by: Uwe Kleine-König 
> ---
>  drivers/mtd/nand/nand-bb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
> index 015f8dc524f3..a1523c3c8992 100644
> --- a/drivers/mtd/nand/nand-bb.c
> +++ b/drivers/mtd/nand/nand-bb.c
> @@ -99,7 +99,7 @@ static int nand_bb_write_buf(struct nand_bb *bb, size_t 
> count)
>   loff_t cur_ofs = bb->offset & ~(BB_WRITEBUF_SIZE - 1);
>  
>   while (count) {
> - loff_t max = bb->mtd->size - bb->offset;
> + loff_t max = bb->mtd->size - cur_ofs;
>  
>   if (max <= 0)
>   return -ENOSPC;
> -- 
> 2.11.0
> 
> 
> ___
> 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] memcmp: fix comparison on short read

2017-03-01 Thread Sascha Hauer
On Wed, Mar 01, 2017 at 03:50:04PM +0100, Uwe Kleine-König wrote:
> read() might return less than $count bytes which is only an upper limit.
> The user is supposed to repeat the command to fill a buffer completely.
> 
> So use the convenience wrapper read_full in memcmp.
> 
> This fixes memcmp on /dev/nand0 on an Armada XP.
> 
> Signed-off-by: Uwe Kleine-König 
> ---
>  commands/memcmp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/commands/memcmp.c b/commands/memcmp.c
> index ce044df0d935..a00fddbc825f 100644
> --- a/commands/memcmp.c
> +++ b/commands/memcmp.c
> @@ -91,13 +91,13 @@ static int do_memcmp(int argc, char *argv[])
>  
>   now = min((loff_t)RW_BUF_SIZE, count);
>  
> - r1 = read(sourcefd, mem_rw_buf,  now);
> + r1 = read_full(sourcefd, mem_rw_buf, now);
>   if (r1 < 0) {
>   perror("read");
>   goto out;
>   }
>  
> - r2 = read(destfd, rw_buf1, now);
> + r2 = read_full(destfd, rw_buf1, now);
>   if (r2 < 0) {
>   perror("read");
>   goto out;
> -- 
> 2.11.0
> 
> 
> ___
> 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] lseek: ensure errno is set on failure and return -1

2017-03-01 Thread Sascha Hauer
On Sat, Feb 25, 2017 at 09:14:34PM +0100, Uwe Kleine-König wrote:
> Hello Sascha,
> 
> On Fri, Feb 24, 2017 at 08:45:13AM +0100, Sascha Hauer wrote:
> > On Thu, Feb 23, 2017 at 10:28:41PM +0100, Uwe Kleine-König wrote:
> > > All error paths before calling the driver's lseek callback return -1 and
> > > set errno. Do the same if the callback returns an error.
> > > 
> > > Signed-off-by: Uwe Kleine-König 
> > > ---
> > >  fs/fs.c | 8 +++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/fs.c b/fs/fs.c
> > > index 2b4659cfbb76..e7b696591433 100644
> > > --- a/fs/fs.c
> > > +++ b/fs/fs.c
> > > @@ -926,7 +926,13 @@ loff_t lseek(int fildes, loff_t offset, int whence)
> > >   goto out;
> > >   }
> > >  
> > > - return fsdrv->lseek(>fsdev->dev, f, pos);
> > > + pos = fsdrv->lseek(>fsdev->dev, f, pos);
> > > + if (pos < 0) {
> > > + errno = -pos;
> > > + return -1;
> > > + }
> > 
> > Before calling into the drivers lseek checks if the position is within
> > the bounds of the file. So when fsdrv->lseek() returns successfully then
> > the position must be the same that was passed in. I think we can just
> > let fsdrv->lseek() return an error code rather than the file position.
> 
> This is a separate and orthogonal change however that doesn't make my
> patch wrong.

Right. Applied.

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 5/8] clocksource: allow to have multiple device from clock source

2017-03-01 Thread Sascha Hauer
On Wed, Mar 01, 2017 at 04:52:05PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> On 08:09 Tue 28 Feb , Sascha Hauer wrote:
> > On Mon, Feb 27, 2017 at 11:19:27AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> > wrote:
> > > use the one with the most priority.
> > > 
> > > We can not select the clocksource at user level.
> > > 
> > > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> > > ---
> > >  common/clock.c  | 11 +++
> > >  include/clock.h |  3 ++-
> > >  2 files changed, 13 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/common/clock.c b/common/clock.c
> > > index 2c5dd91cc..d99d06853 100644
> > > --- a/common/clock.c
> > > +++ b/common/clock.c
> > > @@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
> > >  
> > >  int init_clock(struct clocksource *cs)
> > >  {
> > > + if (current_clock && cs->priority < current_clock->priority)
> > > + return -EBUSY;
> > 
> > You should return successfully here. Otherwise driver probe functions
> > return -EBUSY for something which is not the drivers fault. In fact,
> > it's not an error, it's just that we currently don't have any use for an
> > additional clock.
> my issue is that we will report in barebox that the device is in use but in
> fact is not as we exit the init_clock without doing event the init.

What's the matter? We call init_clock() on a clocksource and barebox
could decide to use it. It just happens that we only use the clocksource
with the highest priority, but this shouldn't interest the driver.

BTW the same as you describe also happens with a low priority
clocksource when it's registered before a high priority clocksource: It
ends up being unused, though registered.

> 
> That's why I choosed to return -EBUSY instead of 0

As a clocksource driver I can only loose in this situation. I haven't
done anything wrong and I can only forward the error, in which case we
see it in the console or I can ignore it in which case I suppress
potential real errors.

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 2/3] ARM: correctly identify ARMv6 K/Z

2017-03-01 Thread Jean-Christophe PLAGNIOL-VILLARD
On 15:26 Wed 01 Mar , Lucas Stach wrote:
> The ARMv6 K/Z derivatives have a v7 compatible MMU, but all other parts
> (including the cache handling) is still at v6. As we don't make use of
> the more advanced features of the v7 MMU in Barebox, it's okay to just
> override this to properly identify the CPU as ARMv6.
evenif we do not use it now I do not liek the idea to report it as ARMv6

It will be better to report it correctly

Best Regards,
J.
> 
> Signed-off-by: Lucas Stach 
> ---
>  arch/arm/cpu/cpuinfo.c | 8 
>  arch/arm/include/asm/system_info.h | 8 
>  2 files changed, 16 insertions(+)
> 
> diff --git a/arch/arm/cpu/cpuinfo.c b/arch/arm/cpu/cpuinfo.c
> index 86e19d9780d5..175475b038dc 100644
> --- a/arch/arm/cpu/cpuinfo.c
> +++ b/arch/arm/cpu/cpuinfo.c
> @@ -165,6 +165,14 @@ static int do_cpuinfo(int argc, char *argv[])
>   } else
>   cpu_arch = CPU_ARCH_UNKNOWN;
>  
> + /*
> +  * Special case for ARMv6 (K/Z) (has v7 compatible MMU, but is v6
> +  * otherwise). The below check just matches all ARMv6, as done in the
> +  * Linux kernel.
> +  */
> + if ((mainid & 0x7f000) == 0x7b000)
> + cpu_arch = CPU_ARCH_ARMv6;
> +
>   switch (cpu_arch) {
>   case CPU_ARCH_ARMv3:
>   architecture = "v3";
> diff --git a/arch/arm/include/asm/system_info.h 
> b/arch/arm/include/asm/system_info.h
> index 25fffd268177..a27b79e6dd08 100644
> --- a/arch/arm/include/asm/system_info.h
> +++ b/arch/arm/include/asm/system_info.h
> @@ -188,6 +188,14 @@ static inline int arm_early_get_cpu_architecture(void)
>   cpu_arch = CPU_ARCH_UNKNOWN;
>  #endif
>  
> + /*
> +  * Special case for ARMv6 (K/Z) (has v7 compatible MMU, but is v6
> +  * otherwise). The below check just matches all ARMv6, as done in the
> +  * Linux kernel.
> +  */
> + if ((read_cpuid_id() & 0x7f000) == 0x7b000)
> + cpu_arch = CPU_ARCH_ARMv6;
> +
>   return cpu_arch;
>  }
>  
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

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


Re: Zyxel NAS540 bricked?

2017-03-01 Thread Jean-Christophe PLAGNIOL-VILLARD
On 05:03 Mon 27 Feb , AndrewCz wrote:
> Hello all, hope you are well.
> 
> Recently, I followed a guide[1] to reflash my Zyxel NAS540[2] in order
> to put Debian on it. I'm pretty sure I bricked it and am just looking
> for confirmation.
> 
> I seem to be running into a bootloop where it will restart every two
> minutes or so. At least that is what seems to be indicated based on the
> frequency of the front panel lights lighting up. I reflashed the 'env'
> and 'kernel2' sections of the NOR flash, but neither went the right way.
> I can dive into the specifics if necessary. However, my concern is that
> I was unable to receive any output from the serial connection.
> 
> Given that the barebox 'env' may be corrupt as well as the kernel, is it
> correct to expect that there would be no serial output? Thanks for your
> consideration in this matter.

And evenif we would like to help you zyxel did not provide to source code of
theur barebox they modified. Just the source code of the 2011.06 version.

So you will have to request them and if they refuse we could then force them
to release it as Copyright holder.

Best Regards,
J.
> 
> --Andrew Cz
> 
> [1] https://l.unchti.me/2016/02/12/debian-nas540.html
> [2] http://zyxel.nas-central.org/wiki/Category:NAS540
> 
> -- 
> Only an idiot fights a war on two fronts. Only the heir to the throne
> of the kingdom of idiots would fight a war on twelve fronts.
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

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


[PATCH] nand-bb: fix writing to the end of a .bb device

2017-03-01 Thread Uwe Kleine-König
As nand_bb_write_buf calls mtd_write(bb->mtd, cur_ofs, now, ...) the
limit that now should be checked against is bb->mtd->size - cur_ofs.

Signed-off-by: Uwe Kleine-König 
---
 drivers/mtd/nand/nand-bb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index 015f8dc524f3..a1523c3c8992 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -99,7 +99,7 @@ static int nand_bb_write_buf(struct nand_bb *bb, size_t count)
loff_t cur_ofs = bb->offset & ~(BB_WRITEBUF_SIZE - 1);
 
while (count) {
-   loff_t max = bb->mtd->size - bb->offset;
+   loff_t max = bb->mtd->size - cur_ofs;
 
if (max <= 0)
return -ENOSPC;
-- 
2.11.0


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


Re: [PATCH 5/8] clocksource: allow to have multiple device from clock source

2017-03-01 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:09 Tue 28 Feb , Sascha Hauer wrote:
> On Mon, Feb 27, 2017 at 11:19:27AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > use the one with the most priority.
> > 
> > We can not select the clocksource at user level.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> > ---
> >  common/clock.c  | 11 +++
> >  include/clock.h |  3 ++-
> >  2 files changed, 13 insertions(+), 1 deletion(-)
> > 
> > diff --git a/common/clock.c b/common/clock.c
> > index 2c5dd91cc..d99d06853 100644
> > --- a/common/clock.c
> > +++ b/common/clock.c
> > @@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
> >  
> >  int init_clock(struct clocksource *cs)
> >  {
> > +   if (current_clock && cs->priority < current_clock->priority)
> > +   return -EBUSY;
> 
> You should return successfully here. Otherwise driver probe functions
> return -EBUSY for something which is not the drivers fault. In fact,
> it's not an error, it's just that we currently don't have any use for an
> additional clock.
my issue is that we will report in barebox that the device is in use but in
fact is not as we exit the init_clock without doing event the init.

That's why I choosed to return -EBUSY instead of 0
> Also consider testing for <= current_clock->priority
> instead of <. All current clocks have priority 0 and we want to
> initialize only the first one.
ok

Best Regards,
J.

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


Re: [PATCH v2] arm: boards: phytec-som-am335x: Remove 1GB RAM type

2017-03-01 Thread Sascha Hauer
On Wed, Mar 01, 2017 at 08:50:54AM +0100, Daniel Schultz wrote:
> This machine was a prototype and was never shipped to customers.
> 
> Since it has no dependencies to any image, it can be removed.
> 
> Signed-off-by: Daniel Schultz 
> ---
> Changes:
>   v2: Removed machine in Makefile

Applied, thanks

Sascha

> 
>  arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 -
>  arch/arm/boards/phytec-som-am335x/ram-timings.h | 21 -
>  images/Makefile.am33xx  |  6 --
>  3 files changed, 28 deletions(-)
> 
> diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
> b/arch/arm/boards/phytec-som-am335x/lowlevel.c
> index 33e83c5..03c7e98 100644
> --- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
> +++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
> @@ -122,7 +122,6 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_128mb, 
> am335x_phytec_phycore_s
>  PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_256mb, 
> am335x_phytec_phycore_som_mlo, PHYCORE_MT41J128M16125IT_256MB);
>  PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_512mb, 
> am335x_phytec_phycore_som_mlo, PHYCORE_MT41J256M16HA15EIT_512MB);
>  PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
> am335x_phytec_phycore_som_mlo, PHYCORE_MT41J512M8125IT_2x512MB);
> -PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
> am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
>  PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_512mb, 
> am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K256M16TW107IT_512MB);
>  PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_256mb, 
> am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K128M16JT_256MB);
>  PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_r2_sram_1024mb,  
> am335x_phytec_phycore_som_mlo, PHYCORE_R2_MT41K512M16HA125IT_1024MB);
> diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
> b/arch/arm/boards/phytec-som-am335x/ram-timings.h
> index 4ea654d..d1947b5 100644
> --- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
> +++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
> @@ -29,7 +29,6 @@ enum {
>   PHYCORE_MT41J64M1615IT_128MB,
>   PHYCORE_MT41J256M16HA15EIT_512MB,
>   PHYCORE_MT41J512M8125IT_2x512MB,
> - PHYCORE_IM8G16D3FBBG15EI_1024MB,
>   PHYCORE_R2_MT41K256M16TW107IT_512MB,
>   PHYCORE_R2_MT41K128M16JT_256MB,
>   PHYCORE_R2_MT41K512M16HA125IT_1024MB,
> @@ -162,26 +161,6 @@ struct am335x_sdram_timings physom_timings[] = {
>   },
>   },
>  
> - /* 1024MB */
> - [PHYCORE_IM8G16D3FBBG15EI_1024MB] = {
> - .regs = {
> - .emif_read_latency  = 0x7,
> - .emif_tim1  = 0x0AAAE4DB,
> - .emif_tim2  = 0x268F7FDA,
> - .emif_tim3  = 0x501F88BF,
> - .ocp_config = 0x003d3d3d,
> - .sdram_config   = 0x61C053B2,
> - .zq_config  = 0x50074BE4,
> - .sdram_ref_ctrl = 0x0C30
> - },
> - .data = {
> - .rd_slave_ratio0= 0x33,
> - .wr_dqs_slave_ratio0= 0x4a,
> - .fifo_we_slave_ratio0   = 0xa4,
> - .wr_slave_ratio0= 0x85,
> - },
> - },
> -
>   /* 256MB */
>   [PHYCARD_NT5CB128M16BP_256MB] = {
>   .regs = {
> diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
> index 8168fe4..d1c432e 100644
> --- a/images/Makefile.am33xx
> +++ b/images/Makefile.am33xx
> @@ -77,12 +77,6 @@ FILE_barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img = 
> start_am33xx_phytec_phy
>  am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
> barebox-am33xx-phytec-phycore-mlo-2x512mb.img
>  am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
> barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img
>  
> -pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
> start_am33xx_phytec_phycore_sram_1024mb
> -FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.img = 
> start_am33xx_phytec_phycore_sram_1024mb.pblx.mlo
> -FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img = 
> start_am33xx_phytec_phycore_sram_1024mb.pblx.mlospi
> -am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
> barebox-am33xx-phytec-phycore-mlo-1024mb.img
> -am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
> barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img
> -
>  pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
> start_am33xx_phytec_phycore_r2_sram_1024mb
>  FILE_barebox-am33xx-phytec-phycore-r2-mlo-1024mb.img = 
> start_am33xx_phytec_phycore_r2_sram_1024mb.pblx.mlo
>  FILE_barebox-am33xx-phytec-phycore-r2-mlo-1024mb.spi.img = 
> start_am33xx_phytec_phycore_r2_sram_1024mb.pblx.mlospi
> -- 
> 1.9.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 


[PATCH] memcmp: fix comparison on short read

2017-03-01 Thread Uwe Kleine-König
read() might return less than $count bytes which is only an upper limit.
The user is supposed to repeat the command to fill a buffer completely.

So use the convenience wrapper read_full in memcmp.

This fixes memcmp on /dev/nand0 on an Armada XP.

Signed-off-by: Uwe Kleine-König 
---
 commands/memcmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/memcmp.c b/commands/memcmp.c
index ce044df0d935..a00fddbc825f 100644
--- a/commands/memcmp.c
+++ b/commands/memcmp.c
@@ -91,13 +91,13 @@ static int do_memcmp(int argc, char *argv[])
 
now = min((loff_t)RW_BUF_SIZE, count);
 
-   r1 = read(sourcefd, mem_rw_buf,  now);
+   r1 = read_full(sourcefd, mem_rw_buf, now);
if (r1 < 0) {
perror("read");
goto out;
}
 
-   r2 = read(destfd, rw_buf1, now);
+   r2 = read_full(destfd, rw_buf1, now);
if (r2 < 0) {
perror("read");
goto out;
-- 
2.11.0


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


[PATCH 5/9] clocksource: bcm2835: use clock-frequency property when available

2017-03-01 Thread Lucas Stach
From: Enrico Joerns 

If the clock frequency is given by a DT property, use this and don't
try to use the clock handle.

Signed-off-by: Enrico Joerns 
Signed-off-by: Lucas Stach 
---
lst: reworked to fall back gracefully
---
 drivers/clocksource/bcm2835.c | 35 ++-
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/clocksource/bcm2835.c b/drivers/clocksource/bcm2835.c
index b5831d5f107b..9130a4b14f9a 100644
--- a/drivers/clocksource/bcm2835.c
+++ b/drivers/clocksource/bcm2835.c
@@ -44,24 +44,33 @@ static int bcm2835_cs_probe(struct device_d *dev)
 {
struct resource *iores;
static struct clk *stc_clk;
-   u32 rate;
+   u32 rate = 0;
int ret;
 
-   stc_clk = clk_get(dev, NULL);
-   if (IS_ERR(stc_clk)) {
-   ret = PTR_ERR(stc_clk);
-   dev_err(dev, "clock not found: %d\n", ret);
-   return ret;
-   }
+   /* try to read rate from DT property first */
+   if (IS_ENABLED(CONFIG_OFTREE))
+   of_property_read_u32(dev->device_node, "clock-frequency",
+);
+
+   /* if rate is still empty, try to get rate from clk */
+   if (!rate) {
+   stc_clk = clk_get(dev, NULL);
+   if (IS_ERR(stc_clk)) {
+   ret = PTR_ERR(stc_clk);
+   dev_err(dev, "clock not found: %d\n", ret);
+   return ret;
+   }
+
+   ret = clk_enable(stc_clk);
+   if (ret) {
+   dev_err(dev, "clock failed to enable: %d\n", ret);
+   clk_put(stc_clk);
+   return ret;
+   }
 
-   ret = clk_enable(stc_clk);
-   if (ret) {
-   dev_err(dev, "clock failed to enable: %d\n", ret);
-   clk_put(stc_clk);
-   return ret;
+   rate = clk_get_rate(stc_clk);
}
 
-   rate = clk_get_rate(stc_clk);
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
return PTR_ERR(iores);
-- 
2.11.0


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


[PATCH 1/9] ARM: rpi: move model initialisation to rpi-common

2017-03-01 Thread Lucas Stach
From: Enrico Joerns 

The Raspberry PIs use different versions schemes for the older and newer
variants. The decoding arrays for these schemes were split up in rpi.c
and rpi2.c. This is not required, as the appropriate versioning scheme
can be determined programmatically.

Signed-off-by: Enrico Joerns 
Signed-off-by: Lucas Stach 
---
lst: remove SoC string
---
 arch/arm/boards/raspberry-pi/Makefile |  2 --
 arch/arm/boards/raspberry-pi/rpi-common.c | 57 ++-
 arch/arm/boards/raspberry-pi/rpi.c| 44 
 arch/arm/boards/raspberry-pi/rpi.h|  3 --
 arch/arm/boards/raspberry-pi/rpi2.c   | 21 
 5 files changed, 48 insertions(+), 79 deletions(-)
 delete mode 100644 arch/arm/boards/raspberry-pi/rpi.c
 delete mode 100644 arch/arm/boards/raspberry-pi/rpi2.c

diff --git a/arch/arm/boards/raspberry-pi/Makefile 
b/arch/arm/boards/raspberry-pi/Makefile
index 7a3d7de241f0..a3e93eb73a32 100644
--- a/arch/arm/boards/raspberry-pi/Makefile
+++ b/arch/arm/boards/raspberry-pi/Makefile
@@ -1,4 +1,2 @@
 obj-$(CONFIG_MACH_RPI_COMMON) += rpi-common.o
-obj-$(CONFIG_MACH_RPI) += rpi.o
-obj-$(CONFIG_MACH_RPI2) += rpi2.o
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
b/arch/arm/boards/raspberry-pi/rpi-common.c
index 147fce9952ab..7441c06437dd 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -146,6 +146,13 @@ void rpi_add_led(void)
led_set_trigger(LED_TRIGGER_HEARTBEAT, >led);
 }
 
+void rpi_b_init(void)
+{
+   rpi_leds[0].gpio = 16;
+   rpi_leds[0].active_low = 1;
+   rpi_set_usbethaddr();
+}
+
 void rpi_b_plus_init(void)
 {
rpi_leds[0].gpio = 47;
@@ -153,12 +160,39 @@ void rpi_b_plus_init(void)
rpi_set_usbethaddr();
 }
 
+/* See comments in mbox.h for data source */
+const struct rpi_model rpi_models_old_scheme[] = {
+   RPI_MODEL(0, "Unknown model", NULL),
+   RPI_MODEL(BCM2835_BOARD_REV_B_I2C0_2, "Model B (no P5)", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_I2C0_3, "Model B (no P5)", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_4, "Model B", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_5, "Model B", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_6, "Model B", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_A_7, "Model A", NULL),
+   RPI_MODEL(BCM2835_BOARD_REV_A_8, "Model A", NULL),
+   RPI_MODEL(BCM2835_BOARD_REV_A_9, "Model A", NULL),
+   RPI_MODEL(BCM2835_BOARD_REV_B_REV2_d, "Model B rev2", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_REV2_e, "Model B rev2", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_REV2_f, "Model B rev2", rpi_b_init),
+   RPI_MODEL(BCM2835_BOARD_REV_B_PLUS, "Model B+", rpi_b_plus_init),
+   RPI_MODEL(BCM2835_BOARD_REV_CM, "Compute Module", NULL),
+   RPI_MODEL(BCM2835_BOARD_REV_A_PLUS, "Model A+", NULL),
+};
+
+const struct rpi_model rpi_models_new_scheme[] = {
+   RPI_MODEL(0, "Unknown model", NULL),
+   RPI_MODEL(BCM2836_BOARD_REV_2_B, "2 Model B", rpi_b_plus_init),
+};
+
 static int rpi_board_rev = 0;
+const struct rpi_model *model;
 
 static void rpi_get_board_rev(void)
 {
int ret;
char *name;
+   const struct rpi_model *rpi_models;
+   size_t rpi_models_size;
 
BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_rev, msg);
BCM2835_MBOX_INIT_HDR(msg);
@@ -183,10 +217,17 @@ static void rpi_get_board_rev(void)
 * http://www.raspberrypi.org/forums/viewtopic.php?f=31=20594
 */
rpi_board_rev = msg->get_board_rev.body.resp.rev;
-   if (rpi_board_rev & 0x80)
+   if (rpi_board_rev & 0x80) {
rpi_board_rev = (rpi_board_rev >> 4) & 0xff;
-   else
+   rpi_models = rpi_models_new_scheme;
+   rpi_models_size = ARRAY_SIZE(rpi_models_new_scheme);
+
+   } else {
rpi_board_rev &= 0xff;
+   rpi_models = rpi_models_old_scheme;
+   rpi_models_size = ARRAY_SIZE(rpi_models_old_scheme);
+   }
+
if (rpi_board_rev >= rpi_models_size) {
printf("RPI: Board rev %u outside known range\n",
   rpi_board_rev);
@@ -201,8 +242,8 @@ static void rpi_get_board_rev(void)
if (!rpi_board_rev)
goto unknown_rev;
 
-   name = basprintf("RaspberryPi %s %s",
-  rpi_models[rpi_board_rev].name, rpi_model_string);
+   model = _models[rpi_board_rev];
+   name = basprintf("RaspberryPi %s", model->name);
barebox_set_model(name);
free(name);
 
@@ -210,17 +251,15 @@ static void rpi_get_board_rev(void)
 
 unknown_rev:
rpi_board_rev = 0;
-   name = basprintf("RaspberryPi %s", rpi_model_string);
-   barebox_set_model(name);
-   free(name);
+   barebox_set_model("RaspberryPi (unknown 

[PATCH 9/9] ARM: rpi: switch to DT probe and multi-image build

2017-03-01 Thread Lucas Stach
This commit switches the RaspberryPi arch over to probe Barebox
from the builtin DT and enables multi-image builds.

Signed-off-by: Lucas Stach 
---
 arch/arm/Kconfig  | 30 +--
 arch/arm/boards/raspberry-pi/lowlevel.c   | 20 ++--
 arch/arm/boards/raspberry-pi/rpi-common.c | 30 +--
 arch/arm/configs/rpi2_defconfig   | 72 ---
 arch/arm/configs/rpi_defconfig|  5 +-
 arch/arm/dts/Makefile |  2 +
 arch/arm/dts/bcm2835-rpi.dts  | 11 
 arch/arm/dts/bcm2836-rpi-2.dts| 11 
 arch/arm/mach-bcm283x/Kconfig |  9 ++--
 arch/arm/mach-bcm283x/core.c  | 15 +-
 arch/arm/mach-bcm283x/include/mach/core.h | 18 ---
 arch/arm/mach-bcm283x/include/mach/platform.h | 25 --
 images/Makefile   |  1 +
 images/Makefile.bcm283x   | 11 
 14 files changed, 87 insertions(+), 173 deletions(-)
 delete mode 100644 arch/arm/configs/rpi2_defconfig
 create mode 100644 arch/arm/dts/bcm2835-rpi.dts
 create mode 100644 arch/arm/dts/bcm2836-rpi-2.dts
 create mode 100644 images/Makefile.bcm283x

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 559cac4016bd..6a4cdc12b1ad 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -19,16 +19,6 @@ config ARM_USE_COMPRESSED_DTB
select UNCOMPRESS
select LZO_DECOMPRESS
 
-config ARCH_BCM283X
-   bool
-   select GPIOLIB
-   select CLKDEV_LOOKUP
-   select COMMON_CLK
-   select CLOCKSOURCE_BCM283X
-   select ARM_AMBA
-   select HAS_DEBUG_LL
-   select RELOCATABLE
-
 menu "System Type"
 
 config BUILTIN_DTB
@@ -57,15 +47,19 @@ config ARCH_AT91
select HAVE_CLK
select PINCTRL_AT91
 
-config ARCH_BCM2835
-   bool "Broadcom BCM2835 boards"
-   select ARCH_BCM283X
-   select CPU_ARM1176
 
-config ARCH_BCM2836
-   bool "Broadcom BCM2836 boards"
-   select ARCH_BCM283X
-   select CPU_V7
+config ARCH_BCM283X
+   bool "Broadcom BCM283x based boards"
+   select GPIOLIB
+   select CLKDEV_LOOKUP
+   select COMMON_CLK
+   select CLOCKSOURCE_BCM283X
+   select ARM_AMBA
+   select HAS_DEBUG_LL
+   select RELOCATABLE
+   select OFTREE
+   select OFDEVICE
+   select HAVE_PBL_MULTI_IMAGES
 
 config ARCH_CLPS711X
bool "Cirrus Logic EP711x/EP721x/EP731x"
diff --git a/arch/arm/boards/raspberry-pi/lowlevel.c 
b/arch/arm/boards/raspberry-pi/lowlevel.c
index 485171a11659..4e71e29e0c0b 100644
--- a/arch/arm/boards/raspberry-pi/lowlevel.c
+++ b/arch/arm/boards/raspberry-pi/lowlevel.c
@@ -4,8 +4,22 @@
 #include 
 #include 
 
-void __naked barebox_arm_reset_vector(void)
+extern char __dtb_bcm2835_rpi_start[];
+ENTRY_FUNCTION(start_raspberry_pi1, r0, r1, r2)
 {
-arm_cpu_lowlevel_init();
-   barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_128M, NULL);
+   void *fdt = __dtb_bcm2835_rpi_start - get_runtime_offset();
+
+   arm_cpu_lowlevel_init();
+
+   barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_128M, fdt);
+}
+
+extern char __dtb_bcm2836_rpi_2_start[];
+ENTRY_FUNCTION(start_raspberry_pi2, r0, r1, r2)
+{
+   void *fdt = __dtb_bcm2836_rpi_2_start - get_runtime_offset();
+
+   arm_cpu_lowlevel_init();
+
+   barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_512M, fdt);
 }
diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
b/arch/arm/boards/raspberry-pi/rpi-common.c
index 331e6873bc49..6e375bc984de 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -73,10 +73,9 @@ static int rpi_get_arm_mem(u32 *size)
return 0;
 }
 
-static int rpi_register_clkdev(u32 clock_id, const char *name)
+static struct clk *rpi_register_firmare_clock(u32 clock_id, const char *name)
 {
BCM2835_MBOX_STACK_ALIGN(struct msg_get_clock_rate, msg);
-   struct clk *clk;
int ret;
 
BCM2835_MBOX_INIT_HDR(msg);
@@ -85,16 +84,9 @@ static int rpi_register_clkdev(u32 clock_id, const char 
*name)
 
ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, >hdr);
if (ret)
-   return ret;
+   return ERR_PTR(ret);
 
-   clk = clk_fixed(name, msg->get_clock_rate.body.resp.rate_hz);
-   if (IS_ERR(clk))
-   return PTR_ERR(clk);
-
-   if (!clk_register_clkdev(clk, NULL, name))
-   return -ENODEV;
-
-   return 0;
+   return clk_fixed(name, msg->get_clock_rate.body.resp.rate_hz);
 }
 
 void rpi_set_usbethaddr(void)
@@ -280,19 +272,25 @@ mem_initcall(rpi_mem_init);
 
 static int rpi_postcore_init(void)
 {
-   bcm2835_register_mbox();
-
rpi_get_board_rev();
barebox_set_hostname("rpi");
 
-   bcm2835_register_uart();
return 0;
 }
 postcore_initcall(rpi_postcore_init);
 
 static int rpi_clock_init(void)
 {
-   

[PATCH 2/9] ARM: rpi: move model detection before console init

2017-03-01 Thread Lucas Stach
This way we can print the correct model in the Barebox banner.

Signed-off-by: Lucas Stach 
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
b/arch/arm/boards/raspberry-pi/rpi-common.c
index 7441c06437dd..db9af2be4245 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -278,7 +278,7 @@ static int rpi_mem_init(void)
 }
 mem_initcall(rpi_mem_init);
 
-static int rpi_console_init(void)
+static int rpi_postcore_init(void)
 {
rpi_get_board_rev();
barebox_set_hostname("rpi");
@@ -286,7 +286,7 @@ static int rpi_console_init(void)
bcm2835_register_uart();
return 0;
 }
-console_initcall(rpi_console_init);
+postcore_initcall(rpi_postcore_init);
 
 static int rpi_clock_init(void)
 {
-- 
2.11.0


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


[PATCH 6/9] mci-bcm2835: enable devicetree probing

2017-03-01 Thread Lucas Stach
From: Enrico Joerns 

Signed-off-by: Enrico Joerns 
---
 drivers/mci/mci-bcm2835.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
index c7a8cf972ab3..daf771934a6c 100644
--- a/drivers/mci/mci-bcm2835.c
+++ b/drivers/mci/mci-bcm2835.c
@@ -543,9 +543,18 @@ static int bcm2835_mci_probe(struct device_d *hw_dev)
return mci_register(>mci);
 }
 
+static __maybe_unused struct of_device_id bcm2835_mci_compatible[] = {
+   {
+   .compatible = "brcm,bcm2835-sdhci",
+   }, {
+   /* sentinel */
+   }
+};
+
 static struct driver_d bcm2835_mci_driver = {
.name = "bcm2835_mci",
.probe = bcm2835_mci_probe,
+   .of_compatible = DRV_OF_COMPAT(bcm2835_mci_compatible),
 };
 
 static int bcm2835_mci_add(void)
-- 
2.11.0


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


[PATCH 4/9] ARM: rpi: convert watchdog/reset to regular driver

2017-03-01 Thread Lucas Stach
This way it can be probed from DT later on.

Signed-off-by: Lucas Stach 
---
 arch/arm/boards/raspberry-pi/rpi-common.c |  1 +
 arch/arm/mach-bcm283x/Makefile|  2 +-
 arch/arm/mach-bcm283x/core.c  | 17 ---
 arch/arm/mach-bcm283x/include/mach/core.h |  5 +++
 arch/arm/mach-bcm283x/include/mach/wd.h   |  6 +--
 arch/arm/mach-bcm283x/wd.c| 75 +++
 6 files changed, 85 insertions(+), 21 deletions(-)
 create mode 100644 arch/arm/mach-bcm283x/wd.c

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
b/arch/arm/boards/raspberry-pi/rpi-common.c
index d0f4fcb3bad9..331e6873bc49 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -326,6 +326,7 @@ static int rpi_env_init(void)
 static int rpi_devices_init(void)
 {
rpi_model_init();
+   bcm2835_register_wd();
bcm2835_register_mci();
bcm2835_register_fb();
armlinux_set_architecture(MACH_TYPE_BCM2708);
diff --git a/arch/arm/mach-bcm283x/Makefile b/arch/arm/mach-bcm283x/Makefile
index 940f98cbce76..96ea69365e50 100644
--- a/arch/arm/mach-bcm283x/Makefile
+++ b/arch/arm/mach-bcm283x/Makefile
@@ -1 +1 @@
-obj-y += core.o mbox.o
+obj-y += core.o mbox.o wd.o
diff --git a/arch/arm/mach-bcm283x/core.c b/arch/arm/mach-bcm283x/core.c
index 64f37813883a..3319ad63c3d7 100644
--- a/arch/arm/mach-bcm283x/core.c
+++ b/arch/arm/mach-bcm283x/core.c
@@ -18,7 +18,6 @@
 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -29,7 +28,6 @@
 #include 
 
 #include 
-#include 
 #include 
 #include 
 
@@ -64,25 +62,10 @@ void bcm2835_add_device_sdram(u32 size)
 
arm_add_mem_device("ram0", BCM2835_SDRAM_BASE, size);
 }
-#define RESET_TIMEOUT 10
-
-static void __noreturn bcm2835_restart_soc(struct restart_handler *rst)
-{
-   uint32_t rstc;
-
-   rstc = readl(PM_RSTC);
-   rstc &= ~PM_RSTC_WRCFG_SET;
-   rstc |= PM_RSTC_WRCFG_FULL_RESET;
-   writel(PM_PASSWORD | RESET_TIMEOUT, PM_WDOG);
-   writel(PM_PASSWORD | rstc, PM_RSTC);
-
-   hang();
-}
 
 static int bcm2835_dev_init(void)
 {
add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, 
IORESOURCE_MEM, NULL);
-   restart_handler_register_fn(bcm2835_restart_soc);
return 0;
 }
 coredevice_initcall(bcm2835_dev_init);
diff --git a/arch/arm/mach-bcm283x/include/mach/core.h 
b/arch/arm/mach-bcm283x/include/mach/core.h
index ce54d38707d8..5edd99efa25f 100644
--- a/arch/arm/mach-bcm283x/include/mach/core.h
+++ b/arch/arm/mach-bcm283x/include/mach/core.h
@@ -37,5 +37,10 @@ static void inline bcm2835_register_mbox(void)
add_generic_device("bcm2835_mbox", 0, NULL, BCM2835_MBOX_BASE, 0x40,
   IORESOURCE_MEM, NULL);
 }
+static void inline bcm2835_register_wd(void)
+{
+   add_generic_device("bcm2835_wd", 0, NULL, BCM2835_PM_BASE, 0x28,
+  IORESOURCE_MEM, NULL);
+}
 
 #endif
diff --git a/arch/arm/mach-bcm283x/include/mach/wd.h 
b/arch/arm/mach-bcm283x/include/mach/wd.h
index ad8b762d9631..cdd22d48c07b 100644
--- a/arch/arm/mach-bcm283x/include/mach/wd.h
+++ b/arch/arm/mach-bcm283x/include/mach/wd.h
@@ -21,9 +21,9 @@
 /*
  * Watchdog
  */
-#define PM_RSTC(BCM2835_PM_BASE+0x1c)
-#define PM_RSTS(BCM2835_PM_BASE+0x20)
-#define PM_WDOG(BCM2835_PM_BASE+0x24)
+#define PM_RSTC0x1c
+#define PM_RSTS0x20
+#define PM_WDOG0x24
 
 #define PM_WDOG_RESET  00
 #define PM_PASSWORD0x5a00
diff --git a/arch/arm/mach-bcm283x/wd.c b/arch/arm/mach-bcm283x/wd.c
new file mode 100644
index ..5a5188fd2e26
--- /dev/null
+++ b/arch/arm/mach-bcm283x/wd.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 Pengutronix, Lucas Stach 
+ *
+ * Based on code from  Carlo Caione 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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 
+#include 
+
+#include 
+
+static void __iomem *wd_base;
+
+#define RESET_TIMEOUT 10
+
+static void __noreturn bcm2835_restart_soc(struct restart_handler *rst)
+{
+   uint32_t rstc;
+
+   rstc = readl(wd_base + PM_RSTC);
+   rstc &= ~PM_RSTC_WRCFG_SET;
+   rstc |= PM_RSTC_WRCFG_FULL_RESET;
+   writel(PM_PASSWORD | RESET_TIMEOUT, wd_base +  PM_WDOG);
+   writel(PM_PASSWORD | rstc, wd_base + PM_RSTC);
+
+   hang();
+}
+

[PATCH 3/9] ARM: rpi: convert mailbox interface to regular driver

2017-03-01 Thread Lucas Stach
In prepareation for devicetree probing.

Signed-off-by: Lucas Stach 
---
 arch/arm/boards/raspberry-pi/rpi-common.c |  2 +
 arch/arm/mach-bcm283x/include/mach/core.h |  6 +++
 arch/arm/mach-bcm283x/include/mach/mbox.h | 19 +
 arch/arm/mach-bcm283x/include/mach/platform.h |  1 +
 arch/arm/mach-bcm283x/mbox.c  | 55 ++-
 5 files changed, 63 insertions(+), 20 deletions(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
b/arch/arm/boards/raspberry-pi/rpi-common.c
index db9af2be4245..d0f4fcb3bad9 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -280,6 +280,8 @@ mem_initcall(rpi_mem_init);
 
 static int rpi_postcore_init(void)
 {
+   bcm2835_register_mbox();
+
rpi_get_board_rev();
barebox_set_hostname("rpi");
 
diff --git a/arch/arm/mach-bcm283x/include/mach/core.h 
b/arch/arm/mach-bcm283x/include/mach/core.h
index b0bed80ea000..ce54d38707d8 100644
--- a/arch/arm/mach-bcm283x/include/mach/core.h
+++ b/arch/arm/mach-bcm283x/include/mach/core.h
@@ -32,4 +32,10 @@ static void inline bcm2835_register_fb(void)
add_generic_device("bcm2835_fb", 0, NULL, 0, 0, 0, NULL);
 }
 
+static void inline bcm2835_register_mbox(void)
+{
+   add_generic_device("bcm2835_mbox", 0, NULL, BCM2835_MBOX_BASE, 0x40,
+  IORESOURCE_MEM, NULL);
+}
+
 #endif
diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h 
b/arch/arm/mach-bcm283x/include/mach/mbox.h
index cd9ee1f43415..2b5aea88ee0a 100644
--- a/arch/arm/mach-bcm283x/include/mach/mbox.h
+++ b/arch/arm/mach-bcm283x/include/mach/mbox.h
@@ -41,16 +41,15 @@
  */
 
 /* Raw mailbox HW */
-
-#define BCM2835_MBOX_PHYSADDR  (BCM2835_ARM_BASE + 0x880)
-
-struct bcm2835_mbox_regs {
-   u32 read;
-   u32 rsvd0[5];
-   u32 status;
-   u32 config;
-   u32 write;
-};
+#define ARM_0_MAIL00x00
+#define ARM_0_MAIL10x20
+
+#define MAIL0_RD   (ARM_0_MAIL0 + 0x00)
+#define MAIL0_POL  (ARM_0_MAIL0 + 0x10)
+#define MAIL0_STA  (ARM_0_MAIL0 + 0x18)
+#define MAIL0_CNF  (ARM_0_MAIL0 + 0x1C)
+#define MAIL1_WRT  (ARM_0_MAIL1 + 0x00)
+#define MAIL1_STA  (ARM_0_MAIL1 + 0x18)
 
 #define BCM2835_MBOX_STATUS_WR_FULL0x8000
 #define BCM2835_MBOX_STATUS_RD_EMPTY   0x4000
diff --git a/arch/arm/mach-bcm283x/include/mach/platform.h 
b/arch/arm/mach-bcm283x/include/mach/platform.h
index 3b73831aa522..09fe78fd41f6 100644
--- a/arch/arm/mach-bcm283x/include/mach/platform.h
+++ b/arch/arm/mach-bcm283x/include/mach/platform.h
@@ -41,6 +41,7 @@
 #define BCM2835_ST_BASE(BCM2835_PERI_BASE + 0x3000)/* 
System Timer */
 #define BCM2835_DMA_BASE   (BCM2835_PERI_BASE + 0x7000)/* DMA 
controller */
 #define BCM2835_ARM_BASE   (BCM2835_PERI_BASE + 0xB000)/* BCM2708 ARM 
control block */
+#define BCM2835_MBOX_BASE  (BCM2835_ARM_BASE + 0x880)  /* BCM2835 
mailbox */
 #define BCM2835_PM_BASE(BCM2835_PERI_BASE + 0x10)  /* 
Power Management, Reset controller and Watchdog registers */
 #define BCM2835_GPIO_BASE  (BCM2835_PERI_BASE + 0x20)  /* GPIO */
 #define BCM2835_UART0_BASE (BCM2835_PERI_BASE + 0x201000)  /* Uart 0 */
diff --git a/arch/arm/mach-bcm283x/mbox.c b/arch/arm/mach-bcm283x/mbox.c
index 9d69bc8ea784..b295993359fa 100644
--- a/arch/arm/mach-bcm283x/mbox.c
+++ b/arch/arm/mach-bcm283x/mbox.c
@@ -6,20 +6,21 @@
  * SPDX-License-Identifier:GPL-2.0+
  */
 
-#include 
-#include 
 #include 
+#include 
 #include 
+#include 
+#include 
 
 #include 
 
 #define TIMEOUT (MSECOND * 1000)
 
+static void __iomem *mbox_base;
+
 static int bcm2835_mbox_call_raw(u32 chan, struct bcm2835_mbox_hdr *buffer,
u32 *recv)
 {
-   struct bcm2835_mbox_regs __iomem *regs =
-   (struct bcm2835_mbox_regs *)BCM2835_MBOX_PHYSADDR;
uint64_t starttime = get_time_ns();
u32 send = virt_to_phys(buffer);
u32 val;
@@ -31,19 +32,19 @@ static int bcm2835_mbox_call_raw(u32 chan, struct 
bcm2835_mbox_hdr *buffer,
 
/* Drain any stale responses */
for (;;) {
-   val = readl(>status);
+   val = readl(mbox_base + MAIL0_STA);
if (val & BCM2835_MBOX_STATUS_RD_EMPTY)
break;
if (is_timeout(starttime, TIMEOUT)) {
printf("mbox: Timeout draining stale responses\n");
return -ETIMEDOUT;
}
-   val = readl(>read);
+   val = readl(mbox_base + MAIL0_RD);
}
 
/* Wait for space to send */
for (;;) {
-   val = readl(>status);
+   val = readl(mbox_base + MAIL0_STA);
if (!(val & BCM2835_MBOX_STATUS_WR_FULL))
break;
if (is_timeout(starttime, TIMEOUT)) {
@@ -57,11 +58,11 @@ static int 

[PATCH 7/9] ARM: rpi: always build relocatable image

2017-03-01 Thread Lucas Stach
Makes more space available for the malloc area and will allow
to switch to multi-image later on.

Signed-off-by: Lucas Stach 
---
 arch/arm/Kconfig  | 1 +
 arch/arm/mach-bcm283x/Kconfig | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e4663ea26872..559cac4016bd 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -27,6 +27,7 @@ config ARCH_BCM283X
select CLOCKSOURCE_BCM283X
select ARM_AMBA
select HAS_DEBUG_LL
+   select RELOCATABLE
 
 menu "System Type"
 
diff --git a/arch/arm/mach-bcm283x/Kconfig b/arch/arm/mach-bcm283x/Kconfig
index e86126862772..d9be1a9b65c1 100644
--- a/arch/arm/mach-bcm283x/Kconfig
+++ b/arch/arm/mach-bcm283x/Kconfig
@@ -2,7 +2,7 @@ if ARCH_BCM283X
 
 config ARCH_TEXT_BASE
hex
-   default 0x0400
+   default 0x0
 
 config MACH_RPI_COMMON
bool
-- 
2.11.0


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


[PATCH 8/9] ARM: rpi: move debug UART base selection to Kconfig

2017-03-01 Thread Lucas Stach
To let the user select the right base, when building multi-image.

Signed-off-by: Lucas Stach 
---
 arch/arm/mach-bcm283x/Kconfig | 20 
 arch/arm/mach-bcm283x/include/mach/debug_ll.h |  6 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-bcm283x/Kconfig b/arch/arm/mach-bcm283x/Kconfig
index d9be1a9b65c1..bb4fe95ab2f1 100644
--- a/arch/arm/mach-bcm283x/Kconfig
+++ b/arch/arm/mach-bcm283x/Kconfig
@@ -22,4 +22,24 @@ config MACH_RPI2
 
 endchoice
 
+config MACH_RPI_DEBUG_UART_BASE
+   hex
+   default 0x20201000 if MACH_RPI_DEBUG_UART_RPI
+   default 0x3f201000 if MACH_RPI_DEBUG_UART_RPI2
+
+if DEBUG_LL
+
+choice
+   prompt "Lowlevel debug UART"
+
+config MACH_RPI_DEBUG_UART_RPI
+   bool "use RaspberryPi 1 compatible base"
+
+config MACH_RPI_DEBUG_UART_RPI2
+   bool "use RaspberryPi 2 and 3 compatible base"
+
+endchoice
+
+endif
+
 endif
diff --git a/arch/arm/mach-bcm283x/include/mach/debug_ll.h 
b/arch/arm/mach-bcm283x/include/mach/debug_ll.h
index be93cd95ad46..a625a8bdb71d 100644
--- a/arch/arm/mach-bcm283x/include/mach/debug_ll.h
+++ b/arch/arm/mach-bcm283x/include/mach/debug_ll.h
@@ -20,7 +20,11 @@
 
 #include 
 
-#define DEBUG_LL_UART_ADDR BCM2835_UART0_BASE
+#ifndef CONFIG_MACH_RPI_DEBUG_UART_BASE
+#define CONFIG_MACH_RPI_DEBUG_UART_BASE 0
+#endif
+
+#define DEBUG_LL_UART_ADDR CONFIG_MACH_RPI_DEBUG_UART_BASE
 
 #include 
 
-- 
2.11.0


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


[PATCH 3/3] ARM: execute DMB before trying to flush cache

2017-03-01 Thread Lucas Stach
The CPU write buffer needs to be coherent with the cache, otherwise
we might flush stale entries with the actual data stuck in the cache.

This is really important on newer CPU core with bigger write buffers.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/cache-armv7.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/cpu/cache-armv7.S b/arch/arm/cpu/cache-armv7.S
index c19618bde182..aaa8bf8c62e1 100644
--- a/arch/arm/cpu/cache-armv7.S
+++ b/arch/arm/cpu/cache-armv7.S
@@ -68,6 +68,7 @@ ENTRY(v7_mmu_cache_flush)
 ENDPROC(v7_mmu_cache_flush)
 
 ENTRY(__v7_mmu_cache_flush_invalidate)
+   mcr p15, 0, r12, c7, c10, 5 @ DMB
mrc p15, 0, r12, c0, c1, 5  @ read ID_MMFR1
tst r12, #0xf << 16 @ hierarchical cache (ARMv7)
mov r12, #0
-- 
2.11.0


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


[PATCH 2/3] ARM: correctly identify ARMv6 K/Z

2017-03-01 Thread Lucas Stach
The ARMv6 K/Z derivatives have a v7 compatible MMU, but all other parts
(including the cache handling) is still at v6. As we don't make use of
the more advanced features of the v7 MMU in Barebox, it's okay to just
override this to properly identify the CPU as ARMv6.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/cpuinfo.c | 8 
 arch/arm/include/asm/system_info.h | 8 
 2 files changed, 16 insertions(+)

diff --git a/arch/arm/cpu/cpuinfo.c b/arch/arm/cpu/cpuinfo.c
index 86e19d9780d5..175475b038dc 100644
--- a/arch/arm/cpu/cpuinfo.c
+++ b/arch/arm/cpu/cpuinfo.c
@@ -165,6 +165,14 @@ static int do_cpuinfo(int argc, char *argv[])
} else
cpu_arch = CPU_ARCH_UNKNOWN;
 
+   /*
+* Special case for ARMv6 (K/Z) (has v7 compatible MMU, but is v6
+* otherwise). The below check just matches all ARMv6, as done in the
+* Linux kernel.
+*/
+   if ((mainid & 0x7f000) == 0x7b000)
+   cpu_arch = CPU_ARCH_ARMv6;
+
switch (cpu_arch) {
case CPU_ARCH_ARMv3:
architecture = "v3";
diff --git a/arch/arm/include/asm/system_info.h 
b/arch/arm/include/asm/system_info.h
index 25fffd268177..a27b79e6dd08 100644
--- a/arch/arm/include/asm/system_info.h
+++ b/arch/arm/include/asm/system_info.h
@@ -188,6 +188,14 @@ static inline int arm_early_get_cpu_architecture(void)
cpu_arch = CPU_ARCH_UNKNOWN;
 #endif
 
+   /*
+* Special case for ARMv6 (K/Z) (has v7 compatible MMU, but is v6
+* otherwise). The below check just matches all ARMv6, as done in the
+* Linux kernel.
+*/
+   if ((read_cpuid_id() & 0x7f000) == 0x7b000)
+   cpu_arch = CPU_ARCH_ARMv6;
+
return cpu_arch;
 }
 
-- 
2.11.0


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


[PATCH 1/3] ARM: align exception vectors to 32 byte

2017-03-01 Thread Lucas Stach
On ARMv7 the exception vectors inside the barebox binary are used directly
by remapping the vectors base through the VBAR register. While VBAR allows
to remap the exception vectors freely, it still imposes a minimum alignment
of 32 byte, as the lower bits are treated as the exception vector offset.
Enforce this alignment inside the barebox binary.

Signed-off-by: Lucas Stach 
---
 arch/arm/lib32/barebox.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index b49c269a4346..e7b87b7cdd18 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -45,7 +45,7 @@ SECTIONS
__bare_init_start = .;
*(.text_bare_init*)
__bare_init_end = .;
-   . = ALIGN(4);
+   . = ALIGN(0x20);
__exceptions_start = .;
KEEP(*(.text_exceptions*))
__exceptions_stop = .;
-- 
2.11.0


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