Re: [PATCH] of: fix typos

2016-10-17 Thread Sascha Hauer
On Mon, Oct 17, 2016 at 02:57:58PM +0300, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov 
> ---
>  drivers/of/base.c | 2 +-
>  drivers/of/fdt.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

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 v3 1/3] reset: import socfpga-reset driver from linux

2016-10-17 Thread Sascha Hauer
On Mon, Oct 17, 2016 at 09:50:50AM +0200, Steffen Trumtrar wrote:
> Port the linux v4.8-rc1 reset-socfpga driver to barebox.
> 
> Signed-off-by: Steffen Trumtrar 
> ---
>  drivers/reset/Makefile|   1 +
>  drivers/reset/reset-socfpga.c | 124 
> ++
>  2 files changed, 125 insertions(+)
>  create mode 100644 drivers/reset/reset-socfpga.c

Applied, thanks

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: Loading kernel issues

2016-10-17 Thread Sascha Hauer
Hi Javier,

On Sun, Oct 16, 2016 at 11:06:15PM +0200, Javier Fileiv wrote:
> Hi everyone, I've just flashed barebox on my Mini2440. I have 2
> questions/issues now
> 
> 1) When trying to load the kernel from TFTP, everything is ok but when
> it's trying to mount the rootfs something is not working, even though
> I set the rootdelay param to 5 secs.
> 
> 2) I tried also the boot from nand and is working just fine, but there
> no is auto boot when reseting the board... it just give me the barebox
> prompt each time, and if i run from there boot nand it works OK, but
> no automaGically. :)
> 
> Any suggestions? Thank you very much
> 
> 
> LOG FOR TFTP BOOT:
> 
> mini2440:/ boot tftp
> warning: No MAC address set. Using random address A2:50:1F:24:DF:AB
> phy0: Link is up - 100/Full
> T DHCP client bound to address 192.168.0.15
> TFTP from server 192.168.0.10 ('uImage-mini2440' -> '/dev/ram0.kernel')
> #
> #
> #
> #
> #
> 
> booting kernel of type uimage from /dev/ram0.kernel
>Verifying Checksum ... OK
>Image Name:   Linux-3.16.7-ptx-master
>Created:  2016-10-13  20:23:14 UTC
>Image Type:  ()
>Data Size:1910288 Bytes =  1.8 MB
>Load Address: 30008000
>Entry Point:  30008000
> OK
> commandline: console=ttySAC0,115200 mini2440=0tbc rootdelay=5 ip=dhcp
> root=/dev/nfs nfsroot=/path/to/nfs/root,v3,tcp noinitrd

You have to replace nfsroot=/path/to/nfs/root with some valid path.
Since your dhcp server does not pass a root server ip you'll have to add
that aswell, so your nfsroot should look like
nfsroot=192.168.x.y:/path/to/nfsroot. Try 'edit /env/config' to edit
the parameter to your needs. Do not forget saveenv afterwards.

To boot from Nand also edit /env/config and adjust the kernel_loc and
rootfs_loc variables.

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 2/4] cmdlinepart: add option to set DEVFS_PARTITION_IN_PT flag

2016-10-17 Thread Michael Grzeschik
With this option it is possible to flag cdev partitions, which will also
be written to the partition table of its backing device.

Signed-off-by: Michael Grzeschik 
---
 include/cmdlinepart.h | 1 +
 lib/cmdlinepart.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/include/cmdlinepart.h b/include/cmdlinepart.h
index bf8cdfa..3363a74 100644
--- a/include/cmdlinepart.h
+++ b/include/cmdlinepart.h
@@ -2,6 +2,7 @@
 #define __CMD_LINE_PART_H
 
 #define CMDLINEPART_ADD_DEVNAME (1 << 0)
+#define CMDLINEPART_ADD_TO_PT (2 << 0)
 
 int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 const char **endp, loff_t *offset,
diff --git a/lib/cmdlinepart.c b/lib/cmdlinepart.c
index d7d4441..8633e82 100644
--- a/lib/cmdlinepart.c
+++ b/lib/cmdlinepart.c
@@ -81,6 +81,9 @@ int cmdlinepart_do_parse_one(const char *devname, const char 
*partstr,
end = (char *)(partstr + 2);
}
 
+   if (partition_flags & CMDLINEPART_ADD_TO_PT)
+   flags |= DEVFS_PARTITION_IN_PT;
+
if (endp)
*endp = end;
 
-- 
2.9.3


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


[PATCH 0/4] Add support to modify mbr partition layout

2016-10-17 Thread Michael Grzeschik
This patchset adds the param dos_partitions to the mci device
node. By setting this param with the standard cmdlinepart notation,
it is possible to rewrite the MBR partition layout on runtime.

Michael Grzeschik (4):
  partitions: add DEVFS_PARTITION_IN_PT flag
  cmdlinepart: add option to set DEVFS_PARTITION_IN_PT flag
  partitions/dos: add function to write partition table
  mci: add MBR write and read function to block devices

 common/partitions.c |   2 +-
 common/partitions/dos.c |  71 
 drivers/mci/mci-core.c  | 122 
 include/cmdlinepart.h   |   1 +
 include/disks.h |   1 +
 include/driver.h|   1 +
 lib/cmdlinepart.c   |   3 ++
 7 files changed, 200 insertions(+), 1 deletion(-)

-- 
2.9.3


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


[PATCH 4/4] mci: add MBR write and read function to block devices

2016-10-17 Thread Michael Grzeschik
With this patch it is possible to write an mbr partition table to the
mci block device. By setting the device property "dos_partitions" of the
mmc device node, it is possible to write back the new partition layout
in the common cmdlinepart notation. The property can also be read back.

Signed-off-by: Michael Grzeschik 
---
 drivers/mci/mci-core.c | 122 +
 1 file changed, 122 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 4e176f7..c0013a1 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -33,9 +33,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 
 #define MAX_BUFFER_NUMBER 0x
 
@@ -1527,6 +1529,122 @@ static void mci_info(struct device_d *dev)
extract_mtd_year(mci));
 }
 
+static char *print_size(uint64_t s)
+{
+   if (!(s & ((1 << 20) - 1)))
+   return basprintf("%lldM", s >> 20);
+   if (!(s & ((1 << 10) - 1)))
+   return basprintf("%lldk", s >> 10);
+   return basprintf("0x%lld", s);
+}
+
+static int print_part(char *buf, int bufsize, struct cdev *cdev, int is_last)
+{
+   char *size = print_size(cdev->size);
+   int ret;
+
+   if (!size) {
+   ret = -ENOMEM;
+   goto out;
+   }
+
+   ret = snprintf(buf, bufsize, "%s(%s)%s", size,
+   cdev->partname,
+   is_last ? "" : ",");
+out:
+   free(size);
+
+   return ret;
+}
+
+static int print_parts(char *buf, int bufsize, struct mci *mci)
+{
+   struct cdev *cdev, *ct;
+   int ret = 0;
+
+   list_for_each_entry_safe(cdev, ct, >dev.cdevs, devices_list) {
+   if ((cdev->flags & DEVFS_IS_PARTITION) &&
+   (cdev->flags & DEVFS_PARTITION_IN_PT)) {
+   int now;
+   int is_last = 0;
+   struct list_head *nh = (cdev)->devices_list.next;
+   struct cdev *next = container_of(nh, typeof(*(cdev)), 
devices_list);
+
+   if (list_is_last(>devices_list, >dev.cdevs) 
||
+   !(next->flags & DEVFS_PARTITION_IN_PT))
+   is_last = 1;
+
+   now = print_part(buf, bufsize, cdev, is_last);
+   if (now < 0)
+   return now;
+
+   if (buf && bufsize) {
+   buf += now;
+   bufsize -= now;
+   }
+   ret += now;
+   }
+   }
+
+   return ret;
+}
+
+static const char *mci_partition_get(struct device_d *dev, struct param_d *p)
+{
+   struct mci *mci = container_of(dev, struct mci, dev);
+   int len = 0;
+
+   free(p->value);
+
+   len = print_parts(NULL, 0, mci);
+   p->value = xzalloc(len + 1);
+   print_parts(p->value, len + 1, mci);
+
+   return p->value;
+}
+
+#ifdef CONFIG_BLOCK_WRITE
+static int mci_partition_set(struct device_d *dev, struct param_d *p, const 
char *val)
+{
+   struct mci *mci = container_of(dev, struct mci, dev);
+   struct cdev *cdev, *ct;
+   int ret;
+
+   if (!val)
+   return -EINVAL;
+
+   /* remove all partition cdevs with DEVFS_IS_PARTITION set */
+   list_for_each_entry_safe(cdev, ct, >dev.cdevs, devices_list) {
+   if ((cdev->flags & DEVFS_IS_PARTITION) &&
+   (cdev->flags & DEVFS_PARTITION_IN_PT))
+   ret = devfs_del_partition(cdev->name);
+   if (ret)
+   return ret;
+   }
+
+   /* read back the prepared partition layot from dos_partitions param */
+   ret = cmdlinepart_do_parse(mci->cdevname, val, mci->capacity,
+   CMDLINEPART_ADD_DEVNAME | CMDLINEPART_ADD_TO_PT);
+   if (ret)
+   return ret;
+
+   /* write the MBR partition layout based on cdevs with 
DEVFS_IS_PARTITION set  */
+   for (int i = 0; i < mci->nr_parts; i++) {
+   struct mci_part *part = >part[i];
+   if (part->area_type == MMC_BLK_DATA_AREA_MAIN) {
+   ret = write_dos_partition_table(>blk,
+   >dev.cdevs);
+   if (ret != 0) {
+   dev_warn(>dev, "Could not write partition 
table\n");
+   return ret;
+   }
+   }
+   }
+
+   return ret;
+}
+#endif
+
 /**
  * Check if the MCI card is already probed
  * @param mci MCI device instance
@@ -1786,6 +1904,10 @@ int mci_register(struct mci_host *host)
mci->param_probe = dev_add_param_bool(>dev, "probe",
mci_set_probe, NULL, >probe, mci);
 
+#ifdef CONFIG_BLOCK_WRITE
+   

[PATCH 1/4] partitions: add DEVFS_PARTITION_IN_PT flag

2016-10-17 Thread Michael Grzeschik
This flag is used to represent the current status of the partition. When
it is set, the current partition layout is also available in the
partition table of the device. We use it after the partition table was
parsed.

Signed-off-by: Michael Grzeschik 
---
 common/partitions.c | 2 +-
 include/driver.h| 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/partitions.c b/common/partitions.c
index 69a2b1f..62ffaef 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -57,7 +57,7 @@ static int register_one_partition(struct block_device *blk,
dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
partition_name, blk->cdev.name);
cdev = devfs_add_partition(blk->cdev.name,
-   start, size, 0, partition_name);
+   start, size, DEVFS_PARTITION_IN_PT, 
partition_name);
if (IS_ERR(cdev)) {
ret = PTR_ERR(cdev);
goto out;
diff --git a/include/driver.h b/include/driver.h
index 80aa8d8..4ff2f77 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -482,6 +482,7 @@ int cdev_erase(struct cdev *cdev, loff_t count, loff_t 
offset);
 #define DEVFS_PARTITION_READONLY   (1U << 1)
 #define DEVFS_IS_PARTITION (1 << 2)
 #define DEVFS_IS_CHARACTER_DEV (1 << 3)
+#define DEVFS_PARTITION_IN_PT  (1 << 4)
 
 struct cdev *devfs_add_partition(const char *devname, loff_t offset,
loff_t size, unsigned int flags, const char *name);
-- 
2.9.3


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


[PATCH 3/4] partitions/dos: add function to write partition table

2016-10-17 Thread Michael Grzeschik
The function can be used to write an partition layout to the block device
based on its cdev layout. Only cdevs with flag DEVFS_PARTITION_IN_PT set
get written. The function also adds an static offset of 0x20 to
ensure the mbr and bootloader will not be overwritten.

Signed-off-by: Michael Grzeschik 
---
 common/partitions/dos.c | 71 +
 include/disks.h |  1 +
 2 files changed, 72 insertions(+)

diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 5f08e25..d7fa538 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -256,6 +256,77 @@ static void dos_partition(void *buf, struct block_device 
*blk,
>signature, "%08x", dsp);
 }
 
+static inline void hdimage_setup_chs(unsigned int lba, unsigned char *chs)
+{
+   const unsigned int hpc = 255;
+   const unsigned int spt = 63;
+   unsigned int s, c;
+
+   chs[0] = (lba/spt)%hpc;
+   c = (lba/(spt * hpc));
+   s = (lba > 0) ?(lba%spt + 1) : 0;
+   chs[1] = ((c & 0x300) >> 2) | (s & 0xff);
+   chs[2] = (c & 0xff);
+}
+
+int write_dos_partition_table(struct block_device *blk, struct list_head 
*cdevs)
+{
+   char part_table[6+4*sizeof(struct partition_entry)+2];
+   struct cdev *cdev, *ct;
+   void *buf;
+   int ret;
+   int n = 0;
+   char *ptr;
+
+   /* prepare partition table entry */
+   ptr = part_table;
+   memset(ptr, 0, sizeof(part_table));
+
+   /* skip disk signature */
+   ptr += 6;
+   list_for_each_entry_safe(cdev, ct, cdevs, devices_list) {
+   if ((cdev->flags & DEVFS_IS_PARTITION) &&
+   (cdev->flags & DEVFS_PARTITION_IN_PT)) {
+   struct partition_entry *entry;
+   entry = (struct partition_entry *)
+   (ptr + n * sizeof(struct partition_entry));
+
+   /* add static offset to skip the mbr and bootloader */
+   cdev->offset += 4096 * SECTOR_SIZE;
+
+   entry->type = 0x83;
+   entry->partition_start = cdev->offset / SECTOR_SIZE;
+   entry->partition_size = cdev->size / SECTOR_SIZE;
+
+   hdimage_setup_chs(entry->partition_start,
+   entry->chs_begin);
+   hdimage_setup_chs(entry->partition_start +
+   entry->partition_size - 1,
+   entry->chs_end);
+   n++;
+   }
+   if (n == 4)
+   break;
+   }
+
+   ptr += 4 * sizeof(struct partition_entry);
+   ptr[0] = 0x55;
+   ptr[1] = 0xaa;
+
+   buf = read_mbr(blk);
+   if (!buf)
+   return -EIO;
+
+   /* manipulate block with prepared partition table */
+   memcpy(buf + 440, part_table, sizeof(part_table));
+
+   ret = write_mbr(blk, buf);
+
+   free(buf);
+
+   return ret;
+}
+
 static struct partition_parser dos = {
.parse = dos_partition,
.type = filetype_mbr,
diff --git a/include/disks.h b/include/disks.h
index 9932750..432fb23 100644
--- a/include/disks.h
+++ b/include/disks.h
@@ -37,5 +37,6 @@ struct partition_entry {
 } __attribute__ ((packed));
 
 extern int parse_partition_table(struct block_device*);
+extern int write_dos_partition_table(struct block_device *blk, struct 
list_head *cdevs);
 
 #endif /* DISKS_H */
-- 
2.9.3


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


[PATCH] of: fix typos

2016-10-17 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/of/base.c | 2 +-
 drivers/of/fdt.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1e6c33d..767d4e1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1631,7 +1631,7 @@ struct device_node *of_get_next_available_child(const 
struct device_node *node,
 EXPORT_SYMBOL(of_get_next_available_child);
 
 /**
- * of_get_next_child - Iterate a node childs
+ * of_get_next_child - Iterate a node children
  * @node:  parent node
  * @prev:  previous child of the parent node, or NULL to get first
  *
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index b2253aa..614e136 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -525,7 +525,7 @@ void of_clean_reserve_map(void)
  * fdt_add_reserve_map - Add reserve map entries to a devicetree binary
  * @__fdt: The devicetree blob
  *
- * This adds the reservemap entries previously colllected in
+ * This adds the reservemap entries previously collected in
  * of_add_reserve_entry() to a devicetree binary blob. This also
  * adds the devicetree itself to the reserved list, so after calling
  * this function the tree should not be relocated anymore.
-- 
2.9.3


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


[PATCH v3 2/3] watchdog: add designware driver

2016-10-17 Thread Steffen Trumtrar
Port the linux v4.8-rc1 Synopsys DesignWare watchdog driver to barebox.

Signed-off-by: Steffen Trumtrar 
---
 drivers/watchdog/Kconfig  |   6 ++
 drivers/watchdog/Makefile |   1 +
 drivers/watchdog/dw_wdt.c | 193 ++
 3 files changed, 200 insertions(+)
 create mode 100644 drivers/watchdog/dw_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 60a56bf4b030..63fb1a8c5701 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -16,6 +16,12 @@ config WATCHDOG_DAVINCI
help
  Add support for watchdog on the TI Davinci SoC.
 
+config WATCHDOG_DW
+   bool "Synopsys DesignWare watchdog"
+   select RESET_CONTROLLER
+   help
+ Add support for the Synopsys DesignWare watchdog timer.
+
 config WATCHDOG_MXS28
bool "i.MX28"
depends on ARCH_IMX28
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index e3afe1c27efb..5fca4c368c40 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -2,5 +2,6 @@ obj-$(CONFIG_WATCHDOG) += wd_core.o
 obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
 obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
 obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
+obj-$(CONFIG_WATCHDOG_DW) += dw_wdt.o
 obj-$(CONFIG_WATCHDOG_JZ4740) += jz4740.o
 obj-$(CONFIG_WATCHDOG_IMX_RESET_SOURCE) += imxwd.o
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
new file mode 100644
index ..fa2752896c2f
--- /dev/null
+++ b/drivers/watchdog/dw_wdt.c
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2010-2011 Picochip Ltd., Jamie Iles
+ * http://www.picochip.com
+ *
+ * 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 file implements a driver for the Synopsys DesignWare watchdog device
+ * in the many subsystems. The watchdog has 16 different timeout periods
+ * and these are a function of the input clock frequency.
+ *
+ * The DesignWare watchdog cannot be stopped once it has been started so we
+ * do not implement a stop function. The watchdog core will continue to send
+ * heartbeat requests after the watchdog device has been closed.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define WDOG_CONTROL_REG_OFFSET0x00
+#define WDOG_CONTROL_REG_WDT_EN_MASK   0x01
+#define WDOG_TIMEOUT_RANGE_REG_OFFSET  0x04
+#define WDOG_TIMEOUT_RANGE_TOPINIT_SHIFT4
+#define WDOG_CURRENT_COUNT_REG_OFFSET  0x08
+#define WDOG_COUNTER_RESTART_REG_OFFSET 0x0c
+#define WDOG_COUNTER_RESTART_KICK_VALUE0x76
+
+/* The maximum TOP (timeout period) value that can be set in the watchdog. */
+#define DW_WDT_MAX_TOP 15
+
+#define DW_WDT_DEFAULT_SECONDS 30
+
+struct dw_wdt {
+   void __iomem*regs;
+   struct clk  *clk;
+   struct restart_handler  restart;
+   struct watchdog wdd;
+   struct reset_control*rst;
+};
+
+#define to_dw_wdt(wdd) container_of(wdd, struct dw_wdt, wdd)
+
+static inline int dw_wdt_top_in_seconds(struct dw_wdt *dw_wdt, unsigned top)
+{
+   /*
+* There are 16 possible timeout values in 0..15 where the number of
+* cycles is 2 ^ (16 + i) and the watchdog counts down.
+*/
+   return (1U << (16 + top)) / clk_get_rate(dw_wdt->clk);
+}
+
+static int dw_wdt_start(struct watchdog *wdd)
+{
+   struct dw_wdt *dw_wdt = to_dw_wdt(wdd);
+
+   writel(WDOG_CONTROL_REG_WDT_EN_MASK,
+  dw_wdt->regs + WDOG_CONTROL_REG_OFFSET);
+
+   return 0;
+}
+
+static int dw_wdt_stop(struct watchdog *wdd)
+{
+   struct dw_wdt *dw_wdt = to_dw_wdt(wdd);
+
+   if (IS_ERR(dw_wdt->rst)) {
+   dev_warn(dw_wdt->wdd.dev, "No reset line. Will not stop.\n");
+   return PTR_ERR(dw_wdt->rst);
+   }
+
+   reset_control_assert(dw_wdt->rst);
+   reset_control_deassert(dw_wdt->rst);
+
+   return 0;
+}
+
+static int dw_wdt_set_timeout(struct watchdog *wdd, unsigned int top_s)
+{
+   struct dw_wdt *dw_wdt = to_dw_wdt(wdd);
+   int i, top_val = DW_WDT_MAX_TOP;
+
+   if (top_s == 0)
+   return dw_wdt_stop(wdd);
+
+   /*
+* Iterate over the timeout values until we find the closest match. We
+* always look for >=.
+*/
+   for (i = 0; i <= DW_WDT_MAX_TOP; ++i) {
+   if (dw_wdt_top_in_seconds(dw_wdt, i) >= top_s) {
+   top_val = i;
+   break;
+   }
+   }
+
+   /*
+* Set the new value in the watchdog.  Some versions of dw_wdt
+* have have TOPINIT in the TIMEOUT_RANGE register (as per
+* CP_WDT_DUAL_TOP in WDT_COMP_PARAMS_1).  On those we
+* effectively 

[PATCH v3 3/3] ARM: socfpga: dtsi: add dw-wdt reset lines

2016-10-17 Thread Steffen Trumtrar
Signed-off-by: Steffen Trumtrar 
---
 arch/arm/dts/socfpga.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/dts/socfpga.dtsi b/arch/arm/dts/socfpga.dtsi
index d16758fdab46..66d7f21dc6a3 100644
--- a/arch/arm/dts/socfpga.dtsi
+++ b/arch/arm/dts/socfpga.dtsi
@@ -49,3 +49,13 @@
 _sdram_ref_clk {
clock-frequency = <0>;
 };
+
+ {
+   resets = < L4WD0_RESET>;
+   reset-names = "dw-wdt";
+};
+
+ {
+   resets = < L4WD1_RESET>;
+   reset-names = "dw-wdt";
+};
-- 
2.9.3


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


[PATCH v3 1/3] reset: import socfpga-reset driver from linux

2016-10-17 Thread Steffen Trumtrar
Port the linux v4.8-rc1 reset-socfpga driver to barebox.

Signed-off-by: Steffen Trumtrar 
---
 drivers/reset/Makefile|   1 +
 drivers/reset/reset-socfpga.c | 124 ++
 2 files changed, 125 insertions(+)
 create mode 100644 drivers/reset/reset-socfpga.c

diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 1e2d83f2b995..52b10cd48055 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_RESET_CONTROLLER) += core.o
+obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
diff --git a/drivers/reset/reset-socfpga.c b/drivers/reset/reset-socfpga.c
new file mode 100644
index ..9214197e627d
--- /dev/null
+++ b/drivers/reset/reset-socfpga.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2014 Steffen Trumtrar 
+ *
+ * based on
+ * Allwinner SoCs Reset Controller driver
+ *
+ * Copyright 2013 Maxime Ripard
+ *
+ * Maxime Ripard 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define NR_BANKS   4
+
+struct socfpga_reset_data {
+   spinlock_t  lock;
+   void __iomem*membase;
+   u32 modrst_offset;
+   struct reset_controller_dev rcdev;
+};
+
+static int socfpga_reset_assert(struct reset_controller_dev *rcdev,
+   unsigned long id)
+{
+   struct socfpga_reset_data *data = container_of(rcdev,
+struct socfpga_reset_data,
+rcdev);
+   int bank = id / BITS_PER_LONG;
+   int offset = id % BITS_PER_LONG;
+   unsigned long flags;
+   u32 reg;
+
+   spin_lock_irqsave(>lock, flags);
+
+   reg = readl(data->membase + data->modrst_offset + (bank * NR_BANKS));
+   writel(reg | BIT(offset), data->membase + data->modrst_offset +
+(bank * NR_BANKS));
+   spin_unlock_irqrestore(>lock, flags);
+
+   return 0;
+}
+
+static int socfpga_reset_deassert(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+   struct socfpga_reset_data *data = container_of(rcdev,
+struct socfpga_reset_data,
+rcdev);
+
+   int bank = id / BITS_PER_LONG;
+   int offset = id % BITS_PER_LONG;
+   unsigned long flags;
+   u32 reg;
+
+   spin_lock_irqsave(>lock, flags);
+
+   reg = readl(data->membase + data->modrst_offset + (bank * NR_BANKS));
+   writel(reg & ~BIT(offset), data->membase + data->modrst_offset +
+ (bank * NR_BANKS));
+
+   spin_unlock_irqrestore(>lock, flags);
+
+   return 0;
+}
+
+static struct reset_control_ops socfpga_reset_ops = {
+   .assert = socfpga_reset_assert,
+   .deassert   = socfpga_reset_deassert,
+};
+
+static int socfpga_reset_probe(struct device_d *dev)
+{
+   struct socfpga_reset_data *data;
+   struct resource *res;
+   struct device_node *np = dev->device_node;
+
+   data = xzalloc(sizeof(*data));
+
+   res = dev_request_mem_resource(dev, 0);
+   data->membase = IOMEM(res->start);
+   if (IS_ERR(data->membase))
+   return PTR_ERR(data->membase);
+
+   if (of_property_read_u32(np, "altr,modrst-offset", 
>modrst_offset)) {
+   dev_warn(dev, "missing altr,modrst-offset property, assuming 
0x10!\n");
+   data->modrst_offset = 0x10;
+   }
+
+   spin_lock_init(>lock);
+
+   data->rcdev.nr_resets = NR_BANKS * BITS_PER_LONG;
+   data->rcdev.ops = _reset_ops;
+   data->rcdev.of_node = np;
+
+   return reset_controller_register(>rcdev);
+}
+
+static const struct of_device_id socfpga_reset_dt_ids[] = {
+   { .compatible = "altr,rst-mgr", },
+   { /* sentinel */ },
+};
+
+static struct driver_d socfpga_reset_driver = {
+   .probe  = socfpga_reset_probe,
+   .of_compatible  = DRV_OF_COMPAT(socfpga_reset_dt_ids),
+};
+
+static int socfpga_reset_init(void)
+{
+   return platform_driver_register(_reset_driver);
+}
+postcore_initcall(socfpga_reset_init);
-- 
2.9.3


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


Re: [PATCH v2 2/3] watchdog: add designware driver

2016-10-17 Thread Steffen Trumtrar
On Fri, Oct 14, 2016 at 11:27:14AM +0200, Steffen Trumtrar wrote:
> Port the linux v4.8-rc1 Synopsys DesignWare watchdog driver to barebox.
> 
> Signed-off-by: Steffen Trumtrar 
> ---
> Changes since v1:
>   - change usages of pr_warn in favor of dev_warn
> 
>  drivers/watchdog/Kconfig  |   6 ++
>  drivers/watchdog/Makefile |   1 +
>  drivers/watchdog/dw_wdt.c | 193 
> ++
>  3 files changed, 200 insertions(+)
>  create mode 100644 drivers/watchdog/dw_wdt.c
> 

(...)

> +struct dw_wdt {
> + void __iomem*regs;
> + struct clk  *clk;
> + struct restart_handler  restart;
> + struct watchdog wdd;
> + struct reset_control*rst;
> +};
> +

(...)

> +static int dw_wdt_stop(struct watchdog *wdd)
> +{
> + struct dw_wdt *dw_wdt = to_dw_wdt(wdd);
> +
> + if (IS_ERR(dw_wdt->rst)) {
> + dev_warn(dw_wdt->dev, "No reset line. Will not stop.\n");
 ^^^

Meh, I sent the wrong version :-(
Let's try again.

Regards,
Steffen

-- 
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.MX Freescale Sabrelite: Use correct device tree for dl variant

2016-10-17 Thread Sascha Hauer
The i.MX6dl variant also uses the i.MX6q device tree which is wrong.
Use the correct one.

Signed-off-by: Sascha Hauer 
---
 arch/arm/boards/freescale-mx6-sabrelite/lowlevel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/freescale-mx6-sabrelite/lowlevel.c 
b/arch/arm/boards/freescale-mx6-sabrelite/lowlevel.c
index 3b51e01..c2d7a3c 100644
--- a/arch/arm/boards/freescale-mx6-sabrelite/lowlevel.c
+++ b/arch/arm/boards/freescale-mx6-sabrelite/lowlevel.c
@@ -53,9 +53,9 @@ static noinline void imx6dl_sabrelite_start(void)
imx6_uart_setup(uart);
pbl_set_putc(imx_uart_putc, uart);
 
-   pr_debug("Freescale i.MX6q SabreLite\n");
+   pr_debug("Freescale i.MX6dl SabreLite\n");
 
-   imx6q_barebox_entry(__dtb_imx6q_sabrelite_start);
+   imx6q_barebox_entry(__dtb_imx6dl_sabrelite_start);
 }
 
 ENTRY_FUNCTION(start_imx6dl_sabrelite, r0, r1, r2)
-- 
2.9.3


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