[PATCH] ARM: imx_v7_defconfig: Select various missing v7 boards by default

2018-04-20 Thread Andrey Smirnov
Add the following boards:

- ZII RDU2 (all variants)
- ZII Vybrid Dev Board (and its derivatives)
- Freescale/NXP i.MX7D SabreSD
- NXP i.MX6ULL EVK
- element 14 WaRP7

to be selected by default by imx_v7_defconfig.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/configs/imx_v7_defconfig | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/configs/imx_v7_defconfig 
b/arch/arm/configs/imx_v7_defconfig
index 13135f2b3..8aef9d6ef 100644
--- a/arch/arm/configs/imx_v7_defconfig
+++ b/arch/arm/configs/imx_v7_defconfig
@@ -33,10 +33,15 @@ CONFIG_MACH_VARISCITE_MX6=y
 CONFIG_MACH_GW_VENTANA=y
 CONFIG_MACH_CM_FX6=y
 CONFIG_MACH_ADVANTECH_ROM_742X=y
+CONFIG_MACH_WARP7=y
+CONFIG_MACH_VF610_TWR=y
+CONFIG_MACH_ZII_RDU2=y
+CONFIG_MACH_ZII_VF610_DEV=y
 CONFIG_MACH_PHYTEC_PHYCORE_IMX7=y
+CONFIG_MACH_FREESCALE_MX7_SABRESD=y
+CONFIG_MACH_NXP_IMX6ULL_EVK=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
-CONFIG_IMX_OCOTP=y
 CONFIG_THUMB2_BAREBOX=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
-- 
2.14.3


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


[PATCH v3] ARM: i.MX: boot: Coalesce copy-pasted code

2018-04-20 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
to perform SoC specific bits.

Signed-off-by: Andrey Smirnov 
---

Sascha:

This is my second take on the patch we discussed in [thread1]. It
saves a whole bunch of boilerpalte code while keeping all function
names greppable. Hopefully this is good enough to be merged.

Thanks,
Andrey Smirnov

[thread1] http://lists.infradead.org/pipermail/barebox/2018-April/032706.html

 arch/arm/mach-imx/boot.c | 70 +++-
 1 file changed, 21 insertions(+), 49 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index c3e2ec501..22cf08e6a 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -29,6 +29,20 @@
 #include 
 #include 
 
+
+static void
+imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
+{
+   enum bootsource src = BOOTSOURCE_UNKNOWN;
+   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
+
+   get_boot_source(, );
+
+   bootsource_set(src);
+   bootsource_set_instance(instance);
+}
+
+
 /* [CTRL][TYPE] */
 static const enum bootsource locations[4][4] = {
{ /* CTRL = WEIM */
@@ -93,13 +107,7 @@ void imx25_get_boot_source(enum bootsource *src, int 
*instance)
 
 void imx25_boot_save_loc(void)
 {
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx25_get_boot_source(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(imx25_get_boot_source);
 }
 
 void imx35_get_boot_source(enum bootsource *src, int *instance)
@@ -114,13 +122,7 @@ void imx35_get_boot_source(enum bootsource *src, int 
*instance)
 
 void imx35_boot_save_loc(void)
 {
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx35_get_boot_source(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(imx35_get_boot_source);
 }
 
 #define IMX27_SYSCTRL_GPCR 0x18
@@ -161,13 +163,7 @@ 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(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(imx27_get_boot_source);
 }
 
 #define IMX51_SRC_SBMR 0x4
@@ -205,13 +201,7 @@ 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(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(imx51_get_boot_source);
 }
 
 #define IMX53_SRC_SBMR 0x4
@@ -431,13 +421,7 @@ void imx6_get_boot_source(enum bootsource *src, int 
*instance)
 
 void imx6_boot_save_loc(void)
 {
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx6_get_boot_source(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(imx6_get_boot_source);
 }
 
 #define IMX7_SRC_SBMR1 0x58
@@ -543,13 +527,7 @@ void imx7_get_boot_source(enum bootsource *src, int 
*instance)
 
 void imx7_boot_save_loc(void)
 {
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   imx7_get_boot_source(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(imx7_get_boot_source);
 }
 
 static int vf610_boot_instance_spi(uint32_t r)
@@ -643,11 +621,5 @@ void vf610_get_boot_source(enum bootsource *src, int 
*instance)
 
 void vf610_boot_save_loc(void)
 {
-   enum bootsource src = BOOTSOURCE_UNKNOWN;
-   int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-   vf610_get_boot_source(, );
-
-   bootsource_set(src);
-   bootsource_set_instance(instance);
+   imx_boot_save_loc(vf610_get_boot_source);
 }
-- 
2.14.3


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


[PATCH 2/2] watchdog: Port RAVE SP watchdog driver from Linux kernel

2018-04-20 Thread Andrey Smirnov
Port RAVE SP watchdog driver from Linux kernel

Signed-off-by: Andrey Smirnov 
---
 drivers/watchdog/Kconfig   |   5 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/rave-sp-wdt.c | 426 +
 3 files changed, 432 insertions(+)
 create mode 100644 drivers/watchdog/rave-sp-wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 1d6b15617..27e9f6d8b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -70,4 +70,9 @@ config WATCHDOG_BCM2835
help
  Add support for watchdog on the Broadcom BCM283X SoCs.
 
+config RAVE_SP_WATCHDOG
+   bool "RAVE SP Watchdog timer"
+   depends on RAVE_SP_CORE
+   help
+ Support for the watchdog on RAVE SP device.
 endif
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 237640121..faf06110a 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_WATCHDOG_JZ4740) += jz4740.o
 obj-$(CONFIG_WATCHDOG_IMX_RESET_SOURCE) += imxwd.o
 obj-$(CONFIG_WATCHDOG_ORION) += orion_wdt.o
 obj-$(CONFIG_ARCH_BCM283X) += bcm2835_wdt.o
+obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
diff --git a/drivers/watchdog/rave-sp-wdt.c b/drivers/watchdog/rave-sp-wdt.c
new file mode 100644
index 0..77d0195db
--- /dev/null
+++ b/drivers/watchdog/rave-sp-wdt.c
@@ -0,0 +1,426 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Driver for watchdog aspect of for Zodiac Inflight Innovations RAVE
+ * Supervisory Processor(SP) MCU
+ *
+ * Copyright (C) 2018 Zodiac Inflight Innovation
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+enum {
+   RAVE_SP_RESET_BYTE = 1,
+   RAVE_SP_RESET_REASON_NORMAL = 0,
+   RAVE_SP_RESET_REASON_HW_WATCHDOG= 1,
+   RAVE_SP_RESET_REASON_SW_WATCHDOG= 2,
+   RAVE_SP_RESET_REASON_VOLTAGE= 3,
+   RAVE_SP_RESET_REASON_HOST_REQUEST   = 4,
+   RAVE_SP_RESET_REASON_TEMPERATURE= 5,
+   RAVE_SP_RESET_REASON_BUTTON_PRESS   = 6,
+   RAVE_SP_RESET_REASON_PIC_CM = 7,
+   RAVE_SP_RESET_REASON_PIC_ILL_INST   = 8,
+   RAVE_SP_RESET_REASON_PIC_TRAP   = 9,
+   RAVE_SP_RESET_REASON_UKNOWN_REASON  = 10,
+   RAVE_SP_RESET_REASON_THERMAL_SENSOR = 11,
+   RAVE_SP_RESET_REASON_SW_VOLTAGE = 12,
+   RAVE_SP_RESET_REASON_CP_REQUEST = 13,
+
+   RAVE_SP_RESET_DELAY_MS = 500,
+
+   RAVE_SP_BOOT_SOURCE_GET = 0,
+   RAVE_SP_BOOT_SOURCE_SET = 1,
+};
+
+/**
+ * struct rave_sp_wdt_variant - RAVE SP watchdog variant
+ *
+ * @max_timeout:   Largest possible watchdog timeout setting
+ * @min_timeout:   Smallest possible watchdog timeout setting
+ *
+ * @configure: Function to send configuration command
+ * @restart:   Function to send "restart" command
+ */
+struct rave_sp_wdt_variant {
+   unsigned int max_timeout;
+   unsigned int min_timeout;
+
+   int (*configure)(struct watchdog *, bool);
+   int (*restart)(struct watchdog *);
+   int (*reset_reason)(struct watchdog *);
+};
+
+/**
+ * struct rave_sp_wdt - RAVE SP watchdog
+ *
+ * @wdd:   Underlying watchdog device
+ * @sp:Pointer to parent RAVE SP device
+ * @variant:   Device specific variant information
+ * @reboot_notifier:   Reboot notifier implementing machine reset
+ */
+struct rave_sp_wdt {
+   struct watchdog wdd;
+   struct rave_sp *sp;
+   const struct rave_sp_wdt_variant *variant;
+   struct restart_handler restart;
+   unsigned int timeout;
+   unsigned int boot_source;
+   struct device_d dev;
+};
+
+static struct rave_sp_wdt *to_rave_sp_wdt(struct watchdog *wdd)
+{
+   return container_of(wdd, struct rave_sp_wdt, wdd);
+}
+
+static int rave_sp_wdt_exec(struct watchdog *wdd, void *data,
+   size_t data_size)
+{
+   return rave_sp_exec(to_rave_sp_wdt(wdd)->sp,
+   data, data_size, NULL, 0);
+}
+
+
+static int rave_sp_wdt_access_boot_source(struct rave_sp_wdt *sp_wd, u8 
set_get)
+{
+   u8 cmd[] = {
+   [0] = RAVE_SP_CMD_BOOT_SOURCE,
+   [1] = 0,
+   [2] = set_get,
+   [3] = sp_wd->boot_source,
+   };
+   u8 response;
+   int ret;
+
+   ret = rave_sp_exec(sp_wd->sp, cmd, sizeof(cmd), ,
+  sizeof(response));
+   if (ret)
+   return ret;
+
+   return response;
+}
+
+static int __rave_sp_wdt_rdu_reset_reason(struct watchdog *wdd,
+ uint8_t response[],
+ size_t response_len)
+{
+   u8 cmd[] = {
+   [0] = RAVE_SP_CMD_RESET_REASON,
+   [1] = 0,
+   };
+   int ret;
+
+   ret = rave_sp_exec(to_rave_sp_wdt(wdd)->sp, cmd, sizeof(cmd),
+  response, 

[PATCH 1/2] mfd: Port RAVE SP driver from Linux kernel

2018-04-20 Thread Andrey Smirnov
Port MFD driver for RAVE SP from Linux kernel.

Signed-off-by: Andrey Smirnov 
---
 drivers/mfd/Kconfig |   8 +
 drivers/mfd/Makefile|   1 +
 drivers/mfd/rave-sp.c   | 758 
 include/linux/mfd/rave-sp.h |  78 +
 4 files changed, 845 insertions(+)
 create mode 100644 drivers/mfd/rave-sp.c
 create mode 100644 include/linux/mfd/rave-sp.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 521cf042a..d04431fbc 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -53,4 +53,12 @@ config MFD_TWL6030
select MFD_TWLCORE
bool "TWL6030 driver"
 
+config RAVE_SP_CORE
+   tristate "RAVE SP MCU core driver"
+   depends on SERIAL_DEV_BUS
+   select CRC_CCITT
+   help
+ Select this to get support for the Supervisory Processor
+ device found on several devices in RAVE line of hardware.
+
 endmenu
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 041915a7c..8b23a1023 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_MFD_SYSCON)  += syscon.o
 obj-$(CONFIG_MFD_TWLCORE)  += twl-core.o
 obj-$(CONFIG_MFD_TWL4030)  += twl4030.o
 obj-$(CONFIG_MFD_TWL6030)  += twl6030.o
+obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o
diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
new file mode 100644
index 0..d55e913ff
--- /dev/null
+++ b/drivers/mfd/rave-sp.c
@@ -0,0 +1,758 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Multifunction core driver for Zodiac Inflight Innovations RAVE
+ * Supervisory Processor(SP) MCU that is connected via dedicated UART
+ * port
+ *
+ * Copyright (C) 2017 Zodiac Inflight Innovations
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+#define DUMP_PREFIX_NONE 0
+
+/*
+ * UART protocol using following entities:
+ *  - message to MCU => ACK response
+ *  - event from MCU => event ACK
+ *
+ * Frame structure:
+ *
+ * Where:
+ * - STX - is start of transmission character
+ * - ETX - end of transmission
+ * - DATA - payload
+ * - CHECKSUM - checksum calculated on 
+ *
+ * If  or  contain one of control characters, then it is
+ * escaped using  control code. Added  does not participate in
+ * checksum calculation.
+ */
+#define RAVE_SP_STX0x02
+#define RAVE_SP_ETX0x03
+#define RAVE_SP_DLE0x10
+
+#define RAVE_SP_MAX_DATA_SIZE  64
+#define RAVE_SP_CHECKSUM_SIZE  2  /* Worst case scenario on RDU2 */
+/*
+ * We don't store STX, ETX and unescaped bytes, so Rx is only
+ * DATA + CSUM
+ */
+#define RAVE_SP_RX_BUFFER_SIZE \
+   (RAVE_SP_MAX_DATA_SIZE + RAVE_SP_CHECKSUM_SIZE)
+
+#define RAVE_SP_STX_ETX_SIZE   2
+/*
+ * For Tx we have to have space for everything, STX, EXT and
+ * potentially stuffed DATA + CSUM data + csum
+ */
+#define RAVE_SP_TX_BUFFER_SIZE \
+   (RAVE_SP_STX_ETX_SIZE + 2 * RAVE_SP_RX_BUFFER_SIZE)
+
+#define RAVE_SP_BOOT_SOURCE_GET0
+#define RAVE_SP_BOOT_SOURCE_SET1
+
+#define RAVE_SP_RDU2_BOARD_TYPE_RMB0
+#define RAVE_SP_RDU2_BOARD_TYPE_DEB1
+
+#define RAVE_SP_BOOT_SOURCE_SD 0
+#define RAVE_SP_BOOT_SOURCE_EMMC   1
+#define RAVE_SP_BOOT_SOURCE_NOR2
+
+/**
+ * enum rave_sp_deframer_state - Possible state for de-framer
+ *
+ * @RAVE_SP_EXPECT_SOF: Scanning input for start-of-frame 
marker
+ * @RAVE_SP_EXPECT_DATA:Got start of frame marker, collecting frame
+ * @RAVE_SP_EXPECT_ESCAPED_DATA: Got escape character, collecting escaped byte
+ */
+enum rave_sp_deframer_state {
+   RAVE_SP_EXPECT_SOF,
+   RAVE_SP_EXPECT_DATA,
+   RAVE_SP_EXPECT_ESCAPED_DATA,
+};
+
+/**
+ * struct rave_sp_deframer - Device protocol deframer
+ *
+ * @state:  Current state of the deframer
+ * @data:   Buffer used to collect deframed data
+ * @length: Number of bytes de-framed so far
+ */
+struct rave_sp_deframer {
+   enum rave_sp_deframer_state state;
+   unsigned char data[RAVE_SP_RX_BUFFER_SIZE];
+   size_t length;
+};
+
+/**
+ * struct rave_sp_reply - Reply as per RAVE device protocol
+ *
+ * @length:Expected reply length
+ * @data:  Buffer to store reply payload in
+ * @code:  Expected reply code
+ * @ackid: Expected reply ACK ID
+ * @completion: Successful reply reception completion
+ */
+struct rave_sp_reply {
+   size_t length;
+   void  *data;
+   u8 code;
+   u8 ackid;
+
+   bool   received;
+};
+
+/**
+ * struct rave_sp_checksum - Variant specific checksum implementation details
+ *
+ * @length:Caculated checksum length
+ * @subroutine:Utilized checksum algorithm implementation
+ */
+struct rave_sp_checksum {
+   size_t length;
+   void (*subroutine)(const u8 *, size_t, u8 *);
+};
+
+/**
+ * struct rave_sp_variant_cmds - Variant specific 

[PATCH 0/2] Initial RAVE SP Linux driver port

2018-04-20 Thread Andrey Smirnov
Everyone:

These two patches are first results of an effort to port RAVE SP
(Supervisory Processor) MFD and it's children drivers from Linux
kernel to Barebox. Patch 1/2 brings MFD driver with its core API and
patch 2/2 adds support for watchdog "cell" of the RAVE SP device.

With a very few exceptions, the code of the drivers is identical to
the code of their Linux counterparts.

These drivers are also first users of "serdev" API work that was
recently merged and should server as a reasonable example of its
usage.

Feedback is wellcome!

Thanks,
Andrey Smirnov

Andrey Smirnov (2):
  mfd: Port RAVE SP driver from Linux kernel
  watchdog: Port RAVE SP watchdog driver from Linux kernel

 drivers/mfd/Kconfig|   8 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/rave-sp.c  | 758 +
 drivers/watchdog/Kconfig   |   5 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/rave-sp-wdt.c | 426 +++
 include/linux/mfd/rave-sp.h|  78 +
 7 files changed, 1277 insertions(+)
 create mode 100644 drivers/mfd/rave-sp.c
 create mode 100644 drivers/watchdog/rave-sp-wdt.c
 create mode 100644 include/linux/mfd/rave-sp.h

-- 
2.14.3


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


[PATCH v2 10/10] ARM: VFxxx: Record reset reason as a part of startup

2018-04-20 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/include/mach/reset-reason.h |  9 +
 arch/arm/mach-imx/vf610.c | 12 
 2 files changed, 21 insertions(+)

diff --git a/arch/arm/mach-imx/include/mach/reset-reason.h 
b/arch/arm/mach-imx/include/mach/reset-reason.h
index 96e52486c..4919f68d5 100644
--- a/arch/arm/mach-imx/include/mach/reset-reason.h
+++ b/arch/arm/mach-imx/include/mach/reset-reason.h
@@ -16,6 +16,15 @@
 
 #define IMX6_SRC_SRSR  0x008
 #define IMX7_SRC_SRSR  0x05c
+#define VF610_SRC_SRSR 0x008
+
+
+#define VF610_SRC_SRSR_SW_RST  BIT(18)
+#define VF610_SRC_SRSR_RESETB  BIT(7)
+#define VF610_SRC_SRSR_JTAG_RSTBIT(5)
+#define VF610_SRC_SRSR_WDOG_M4 BIT(4)
+#define VF610_SRC_SRSR_WDOG_A5 BIT(3)
+#define VF610_SRC_SRSR_POR_RST BIT(0)
 
 struct imx_reset_reason {
uint32_t mask;
diff --git a/arch/arm/mach-imx/vf610.c b/arch/arm/mach-imx/vf610.c
index c2d02632f..df8cfcd6b 100644
--- a/arch/arm/mach-imx/vf610.c
+++ b/arch/arm/mach-imx/vf610.c
@@ -18,6 +18,17 @@
 #include 
 #include 
 #include 
+#include 
+
+static const struct imx_reset_reason vf610_reset_reasons[] = {
+   { VF610_SRC_SRSR_POR_RST,   RESET_POR,   0 },
+   { VF610_SRC_SRSR_WDOG_A5,   RESET_WDG,   0 },
+   { VF610_SRC_SRSR_WDOG_M4,   RESET_WDG,   1 },
+   { VF610_SRC_SRSR_JTAG_RST,  RESET_JTAG,  0 },
+   { VF610_SRC_SRSR_RESETB,RESET_EXT,   0 },
+   { VF610_SRC_SRSR_SW_RST,RESET_RST,   0 },
+   { /* sentinel */ }
+};
 
 int vf610_init(void)
 {
@@ -43,5 +54,6 @@ int vf610_init(void)
}
 
imx_set_silicon_revision(cputypestr, vf610_cpu_revision());
+   imx_set_reset_reason(src + VF610_SRC_SRSR, vf610_reset_reasons);
return 0;
 }
-- 
2.14.3


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


[PATCH v2 09/10] ARM: VFxxx: Detect cpu variant on start

2018-04-20 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/Makefile   |  1 +
 arch/arm/mach-imx/imx.c  |  2 +-
 arch/arm/mach-imx/include/mach/generic.h |  1 +
 arch/arm/mach-imx/vf610.c| 47 
 4 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/vf610.c

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 8ec846cce..160ed4b08 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_ARCH_IMX6) += imx6.o usb-imx6.o
 CFLAGS_imx6.o := -march=armv7-a
 lwl-$(CONFIG_ARCH_IMX6) += imx6-mmdc.o
 obj-$(CONFIG_ARCH_IMX7) += imx7.o
+obj-$(CONFIG_ARCH_VF610) += vf610.o
 obj-$(CONFIG_ARCH_IMX_XLOAD) += xload.o
 obj-$(CONFIG_IMX_IIM)  += iim.o
 obj-$(CONFIG_IMX_OCOTP)+= ocotp.o
diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index 32d8e11a7..bf15f0b06 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -119,7 +119,7 @@ static int imx_init(void)
else if (cpu_is_mx7())
ret = imx7_init();
else if (cpu_is_vf610())
-   ret = 0;
+   ret = vf610_init();
else
return -EINVAL;
 
diff --git a/arch/arm/mach-imx/include/mach/generic.h 
b/arch/arm/mach-imx/include/mach/generic.h
index dedb4bbf0..ad9d9cb02 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -36,6 +36,7 @@ int imx51_init(void);
 int imx53_init(void);
 int imx6_init(void);
 int imx7_init(void);
+int vf610_init(void);
 
 int imx1_devices_init(void);
 int imx21_devices_init(void);
diff --git a/arch/arm/mach-imx/vf610.c b/arch/arm/mach-imx/vf610.c
new file mode 100644
index 0..c2d02632f
--- /dev/null
+++ b/arch/arm/mach-imx/vf610.c
@@ -0,0 +1,47 @@
+/*
+ * 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 
+#include 
+#include 
+
+int vf610_init(void)
+{
+   const char *cputypestr;
+   void __iomem *src = IOMEM(VF610_SRC_BASE_ADDR);
+
+   switch (vf610_cpu_type()) {
+   case VF610_CPUTYPE_VF610:
+   cputypestr = "VF610";
+   break;
+   case VF610_CPUTYPE_VF600:
+   cputypestr = "VF600";
+   break;
+   case VF610_CPUTYPE_VF510:
+   cputypestr = "VF510";
+   break;
+   case VF610_CPUTYPE_VF500:
+   cputypestr = "VF500";
+   break;
+   default:
+   cputypestr = "unknown VFxxx";
+   break;
+   }
+
+   imx_set_silicon_revision(cputypestr, vf610_cpu_revision());
+   return 0;
+}
-- 
2.14.3


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


[PATCH v2 08/10] ARM: VFxxx: Add code to detect cpu variant

2018-04-20 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/include/mach/vf610-regs.h |  3 ++
 arch/arm/mach-imx/include/mach/vf610.h  | 51 +
 2 files changed, 54 insertions(+)
 create mode 100644 arch/arm/mach-imx/include/mach/vf610.h

diff --git a/arch/arm/mach-imx/include/mach/vf610-regs.h 
b/arch/arm/mach-imx/include/mach/vf610-regs.h
index 87772ee76..416b457af 100644
--- a/arch/arm/mach-imx/include/mach/vf610-regs.h
+++ b/arch/arm/mach-imx/include/mach/vf610-regs.h
@@ -109,4 +109,7 @@
 #define VF610_MSCM_IRSPRC_CP0_EN   1
 #define VF610_MSCM_IRSPRC_NUM  112
 
+#define VF610_MSCM_CPxCOUNT0x00c
+#define VF610_MSCM_CPxCFG1 0x014
+
 #endif
diff --git a/arch/arm/mach-imx/include/mach/vf610.h 
b/arch/arm/mach-imx/include/mach/vf610.h
new file mode 100644
index 0..6d00d2e45
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/vf610.h
@@ -0,0 +1,51 @@
+#ifndef __MACH_VF610_H
+#define __MACH_VF610_H
+
+#include 
+#include 
+#include 
+#include 
+
+#define VF610_CPUTYPE_VFx100x010
+
+#define VF610_CPUTYPE_VF6100x610
+#define VF610_CPUTYPE_VF6000x600
+#define VF610_CPUTYPE_VF5100x510
+#define VF610_CPUTYPE_VF5000x500
+
+#define VF610_ROM_VERSION_OFFSET   0x80
+
+static inline int __vf610_cpu_type(void)
+{
+   void __iomem *mscm = IOMEM(VF610_MSCM_BASE_ADDR);
+   const u32 cpxcount = readl(mscm + VF610_MSCM_CPxCOUNT);
+   const u32 cpxcfg1  = readl(mscm + VF610_MSCM_CPxCFG1);
+   int cpu_type;
+
+   cpu_type = cpxcount ? VF610_CPUTYPE_VF600 : VF610_CPUTYPE_VF500;
+
+   return cpxcfg1 ? cpu_type | VF610_CPUTYPE_VFx10 : cpu_type;
+}
+
+static inline int vf610_cpu_type(void)
+{
+   if (!cpu_is_vf610())
+   return 0;
+
+   return __vf610_cpu_type();
+}
+
+static inline int vf610_cpu_revision(void)
+{
+   if (!cpu_is_vf610())
+   return IMX_CHIP_REV_UNKNOWN;
+
+   /*
+* There doesn't seem to be a documented way of retreiving
+* silicon revision on VFxxx cpus, so we just report Mask ROM
+* version instead
+*/
+   return readl(VF610_ROM_VERSION_OFFSET) & 0xff;
+}
+
+#endif
-- 
2.14.3


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


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

2018-04-20 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/imx6.c  | 13 -
 arch/arm/mach-imx/include/mach/reset-reason.h |  2 ++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
index 88165adee..49610bf08 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 
@@ -173,10 +174,20 @@ int imx6_cpu_revision(void)
return soc_revision;
 }
 
+static const struct imx_reset_reason imx6_reset_reasons[] = {
+   { IMX_SRC_SRSR_IPP_RESET, RESET_POR,  0 },
+   { IMX_SRC_SRSR_WDOG1_RESET,   RESET_WDG,  0 },
+   { IMX_SRC_SRSR_JTAG_RESET,RESET_JTAG, 0 },
+   { IMX_SRC_SRSR_JTAG_SW_RESET, RESET_JTAG, 0 },
+   { IMX_SRC_SRSR_WARM_BOOT, RESET_RST,  0 },
+   { /* sentinel */ }
+};
+
 int imx6_init(void)
 {
const char *cputypestr;
u32 mx6_silicon_revision;
+   void __iomem *src = IOMEM(MX6_SRC_BASE_ADDR);
 
imx6_init_lowlevel();
 
@@ -221,7 +232,7 @@ int imx6_init(void)
}
 
imx_set_silicon_revision(cputypestr, mx6_silicon_revision);
-
+   imx_set_reset_reason(src + IMX6_SRC_SRSR, imx6_reset_reasons);
imx6_setup_ipu_qos();
imx6ul_enet_clk_init();
 
diff --git a/arch/arm/mach-imx/include/mach/reset-reason.h 
b/arch/arm/mach-imx/include/mach/reset-reason.h
index 39afc4b28..f2544a303 100644
--- a/arch/arm/mach-imx/include/mach/reset-reason.h
+++ b/arch/arm/mach-imx/include/mach/reset-reason.h
@@ -14,6 +14,8 @@
 #define IMX_SRC_SRSR_TEMPSENSE_RESET   BIT(9)
 #define IMX_SRC_SRSR_WARM_BOOT BIT(16)
 
+#define IMX6_SRC_SRSR  0x008
+
 struct imx_reset_reason {
uint32_t mask;
enum reset_src_type type;
-- 
2.14.3


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


[PATCH v2 02/10] ARM: i.MX: Add infrastructure to record SoC reset reason

2018-04-20 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/imx.c   | 33 +++
 arch/arm/mach-imx/include/mach/reset-reason.h | 25 
 2 files changed, 58 insertions(+)
 create mode 100644 arch/arm/mach-imx/include/mach/reset-reason.h

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index 9400105c6..29dad9a41 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -14,8 +14,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 static int __imx_silicon_revision = IMX_CHIP_REV_UNKNOWN;
 
@@ -147,3 +149,34 @@ static int imx_init(void)
return ret;
 }
 postcore_initcall(imx_init);
+
+void imx_set_reset_reason(void __iomem *srsr,
+ const struct imx_reset_reason *reasons)
+{
+   enum reset_src_type type = RESET_UKWN;
+   const u32 reg = readl(srsr);
+   int i, instance = 0;
+
+   /*
+* SRSR register captures ALL reset event that occured since
+* POR, so we need to clear it to make sure we only caputre
+* the latest one.
+*/
+   writel(reg, srsr);
+
+   for (i = 0; reasons[i].mask; i++) {
+   if (reg & reasons[i].mask) {
+   type = reasons[i].type;
+   instance = reasons[i].instance;
+   break;
+   }
+   }
+
+   /*
+* Report this with above default priority in order to make
+* sure we'll always override info from watchdog driver.
+*/
+   reset_source_set_priority(type,
+ RESET_SOURCE_DEFAULT_PRIORITY + 1);
+   reset_source_set_instance(type, instance);
+}
diff --git a/arch/arm/mach-imx/include/mach/reset-reason.h 
b/arch/arm/mach-imx/include/mach/reset-reason.h
new file mode 100644
index 0..39afc4b28
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/reset-reason.h
@@ -0,0 +1,25 @@
+#ifndef __MACH_RESET_REASON_H__
+#define __MACH_RESET_REASON_H__
+
+#include 
+
+#define IMX_SRC_SRSR_IPP_RESET BIT(0)
+#define IMX_SRC_SRSR_CSU_RESET BIT(1)
+#define IMX_SRC_SRSR_IPP_USER_RESETBIT(3)
+#define IMX_SRC_SRSR_WDOG1_RESET   BIT(4)
+#define IMX_SRC_SRSR_JTAG_RESETBIT(5)
+#define IMX_SRC_SRSR_JTAG_SW_RESET BIT(6)
+#define IMX_SRC_SRSR_WDOG3_RESET   BIT(7)
+#define IMX_SRC_SRSR_WDOG4_RESET   BIT(8)
+#define IMX_SRC_SRSR_TEMPSENSE_RESET   BIT(9)
+#define IMX_SRC_SRSR_WARM_BOOT BIT(16)
+
+struct imx_reset_reason {
+   uint32_t mask;
+   enum reset_src_type type;
+   int instance;
+};
+
+void imx_set_reset_reason(void __iomem *, const struct imx_reset_reason *);
+
+#endif /* __MACH_RESET_REASON_H__ */
-- 
2.14.3


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


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

2018-04-20 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/mach-imx/imx7.c  | 14 ++
 arch/arm/mach-imx/include/mach/reset-reason.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/arch/arm/mach-imx/imx7.c b/arch/arm/mach-imx/imx7.c
index 4eef99c87..5ad91c2d7 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)
@@ -167,10 +168,22 @@ static struct psci_ops imx7_psci_ops = {
.cpu_off = imx7_cpu_off,
 };
 
+static const struct imx_reset_reason imx7_reset_reasons[] = {
+   { IMX_SRC_SRSR_IPP_RESET,   RESET_POR,   0 },
+   { IMX_SRC_SRSR_WDOG1_RESET, RESET_WDG,   0 },
+   { IMX_SRC_SRSR_JTAG_RESET,  RESET_JTAG,  0 },
+   { IMX_SRC_SRSR_JTAG_SW_RESET,   RESET_JTAG,  0 },
+   { IMX_SRC_SRSR_WDOG3_RESET, RESET_WDG,   1 },
+   { IMX_SRC_SRSR_WDOG4_RESET, RESET_WDG,   2 },
+   { IMX_SRC_SRSR_TEMPSENSE_RESET, RESET_THERM, 0 },
+   { /* sentinel */ }
+};
+
 int imx7_init(void)
 {
const char *cputypestr;
u32 imx7_silicon_revision;
+   void __iomem *src = IOMEM(MX7_SRC_BASE_ADDR);
 
imx7_init_lowlevel();
 
@@ -197,6 +210,7 @@ int imx7_init(void)
}
 
imx_set_silicon_revision(cputypestr, imx7_silicon_revision);
+   imx_set_reset_reason(src + IMX7_SRC_SRSR, imx7_reset_reasons);
 
return 0;
 }
diff --git a/arch/arm/mach-imx/include/mach/reset-reason.h 
b/arch/arm/mach-imx/include/mach/reset-reason.h
index f2544a303..96e52486c 100644
--- a/arch/arm/mach-imx/include/mach/reset-reason.h
+++ b/arch/arm/mach-imx/include/mach/reset-reason.h
@@ -15,6 +15,7 @@
 #define IMX_SRC_SRSR_WARM_BOOT BIT(16)
 
 #define IMX6_SRC_SRSR  0x008
+#define IMX7_SRC_SRSR  0x05c
 
 struct imx_reset_reason {
uint32_t mask;
-- 
2.14.3


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


[PATCH v2 05/10] common: reset_source: Introduce reset_source_name()

2018-04-20 Thread Andrey Smirnov
Introduce reset_source_name() to get string representation of current
reset source.

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

diff --git a/common/reset_source.c b/common/reset_source.c
index 6a6c4f5da..b2985ee85 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -60,6 +60,12 @@ void reset_source_set_priority(enum reset_src_type st, 
unsigned int priority)
 }
 EXPORT_SYMBOL(reset_source_set_priority);
 
+const char *reset_source_name(void)
+{
+   return reset_src_names[reset_source];
+}
+EXPORT_SYMBOL(reset_source_name)
+
 void reset_source_set_instance(enum reset_src_type type, int instance)
 {
if (reset_source == type)
diff --git a/include/reset_source.h b/include/reset_source.h
index c9911c008..f9aed6a7a 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -30,6 +30,7 @@ enum reset_src_type reset_source_get(void);
 void reset_source_set_instance(enum reset_src_type type, int instance);
 int reset_source_get_instance(void);
 unsigned int of_get_reset_source_priority(struct device_node *node);
+const char *reset_source_name(void);
 #else
 static inline void reset_source_set_priority(enum reset_src_type type,
unsigned int priority)
@@ -54,6 +55,11 @@ static inline unsigned int 
of_get_reset_source_priority(struct device_node *node
 {
return 0;
 }
+
+const char *reset_source_name(void)
+{
+   return "unknown";
+}
 #endif
 
 #define RESET_SOURCE_DEFAULT_PRIORITY 100
-- 
2.14.3


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


[PATCH v2 01/10] common: reset_source: Add the notion of "reset source instance"

2018-04-20 Thread Andrey Smirnov
In order to accomodate SoCs that come with multiple watchdogs (or any
other reset sources of the same kind) add a notion of "reset source
instance", similar to what we already have for bootsource API.

Signed-off-by: Andrey Smirnov 
---
 common/reset_source.c  | 17 +
 include/reset_source.h | 11 +++
 2 files changed, 28 insertions(+)

diff --git a/common/reset_source.c b/common/reset_source.c
index 06e2ca85f..6a6c4f5da 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -32,6 +32,7 @@ static const char * const reset_src_names[] = {
 
 static enum reset_src_type reset_source;
 static unsigned int reset_source_priority;
+static int reset_source_instance;
 
 enum reset_src_type reset_source_get(void)
 {
@@ -39,6 +40,12 @@ enum reset_src_type reset_source_get(void)
 }
 EXPORT_SYMBOL(reset_source_get);
 
+int reset_source_get_instance(void)
+{
+   return reset_source_instance;
+}
+EXPORT_SYMBOL(reset_source_get_instance);
+
 void reset_source_set_priority(enum reset_src_type st, unsigned int priority)
 {
if (priority <= reset_source_priority)
@@ -46,17 +53,27 @@ void reset_source_set_priority(enum reset_src_type st, 
unsigned int priority)
 
reset_source = st;
reset_source_priority = priority;
+   reset_source_instance = 0;
 
pr_debug("Setting reset source to %s with priority %d\n",
reset_src_names[reset_source], priority);
 }
 EXPORT_SYMBOL(reset_source_set_priority);
 
+void reset_source_set_instance(enum reset_src_type type, int instance)
+{
+   if (reset_source == type)
+   reset_source_instance = instance;
+}
+EXPORT_SYMBOL(reset_source_set_instance);
+
 static int reset_source_init(void)
 {
globalvar_add_simple_enum("system.reset", (unsigned int *)_source,
reset_src_names, ARRAY_SIZE(reset_src_names));
 
+   globalvar_add_simple_int("system.reset_instance", 
_source_instance,
+"%d");
return 0;
 }
 
diff --git a/include/reset_source.h b/include/reset_source.h
index 3ff06b70a..c9911c008 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -27,6 +27,8 @@ enum reset_src_type {
 #ifdef CONFIG_RESET_SOURCE
 void reset_source_set_priority(enum reset_src_type, unsigned int priority);
 enum reset_src_type reset_source_get(void);
+void reset_source_set_instance(enum reset_src_type type, int instance);
+int reset_source_get_instance(void);
 unsigned int of_get_reset_source_priority(struct device_node *node);
 #else
 static inline void reset_source_set_priority(enum reset_src_type type,
@@ -34,11 +36,20 @@ static inline void reset_source_set_priority(enum 
reset_src_type type,
 {
 }
 
+static inline void reset_source_set_instance(enum reset_src_type type, int 
instance)
+{
+}
+
 static inline enum reset_src_type reset_source_get(void)
 {
return RESET_UKWN;
 }
 
+static inline int reset_source_get_instance(void)
+{
+   return 0;
+}
+
 static inline unsigned int of_get_reset_source_priority(struct device_node 
*node)
 {
return 0;
-- 
2.14.3


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


[PATCH v2 06/10] ARM: i.MX: Log detected reset reason

2018-04-20 Thread Andrey Smirnov
Log detected reset reason as well as raw value of SRSR for better
clarity.

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

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index 29dad9a41..7dee1433b 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -179,4 +179,7 @@ void imx_set_reset_reason(void __iomem *srsr,
reset_source_set_priority(type,
  RESET_SOURCE_DEFAULT_PRIORITY + 1);
reset_source_set_instance(type, instance);
+
+   pr_info("i.MX reset reason %s (SRSR: 0x%08x)\n",
+   reset_source_name(), reg);
 }
-- 
2.14.3


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


[PATCH v2 00/10] i.MX reset reason detection support

2018-04-20 Thread Andrey Smirnov
Everyone:

This patchset is the result of my work on adding support for detecting
and reporting reset reason as can be obtained from System Reset
Controller (to be more precise via SRSR register) on i.MX family of
SoC.

Currently list of supported SoC is as follows:

  - i.MX6 (tested on i.MX6Q)
  - i.MX7 (tested on i.MX7D)
  - VFxxx (tested on VF610)


Changes since [v1]:

- i.MX reset reason detection code was converted to do detect
  the source with bitmasking as opposed to having a switch
  statement, due to potential problems with the latter as was
  pointed out by Philipp in [thread1]

- Change above also allowed to unify VFxxx and i.MX codepaths
  without the need to introduce a dedicated VFxxx centric
  function

[v1] http://lists.infradead.org/pipermail/barebox/2018-April/032614.html
[thread1] http://lists.infradead.org/pipermail/barebox/2018-April/032708.html

Feedback is wellcome!

Thanks,
Andrey Smirnov

Andrey Smirnov (10):
  common: reset_source: Add the notion of "reset source instance"
  ARM: i.MX: Add infrastructure to record SoC reset reason
  ARM: i.MX6: Record reset reason as a part of startup
  ARM: i.MX7: Record reset reason as a part of startup
  common: reset_source: Introduce reset_source_name()
  ARM: i.MX: Log detected reset reason
  ARM: i.MX: Print "revision unknown" if that is the case
  ARM: VFxxx: Add code to detect cpu variant
  ARM: VFxxx: Detect cpu variant on start
  ARM: VFxxx: Record reset reason as a part of startup

 arch/arm/mach-imx/Makefile|  1 +
 arch/arm/mach-imx/imx.c   | 43 ++-
 arch/arm/mach-imx/imx6.c  | 13 +-
 arch/arm/mach-imx/imx7.c  | 14 +++
 arch/arm/mach-imx/include/mach/generic.h  |  1 +
 arch/arm/mach-imx/include/mach/reset-reason.h | 37 +
 arch/arm/mach-imx/include/mach/vf610-regs.h   |  3 ++
 arch/arm/mach-imx/include/mach/vf610.h| 51 +++
 arch/arm/mach-imx/vf610.c | 59 +++
 common/reset_source.c | 23 +++
 include/reset_source.h| 17 
 11 files changed, 259 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-imx/include/mach/reset-reason.h
 create mode 100644 arch/arm/mach-imx/include/mach/vf610.h
 create mode 100644 arch/arm/mach-imx/vf610.c

-- 
2.14.3


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


[PATCH v2 07/10] ARM: i.MX: Print "revision unknown" if that is the case

2018-04-20 Thread Andrey Smirnov
Printing "revision 16.16" if i.MX SoC's revision is unknown is a bit
confusing so modify the code to actually say "revision unknown" in
such a case.

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

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index 7dee1433b..32d8e11a7 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -30,7 +30,10 @@ void imx_set_silicon_revision(const char *soc, int revision)
 {
__imx_silicon_revision = revision;
 
-   pr_info("detected %s revision %d.%d\n", soc,
+   if (revision == IMX_CHIP_REV_UNKNOWN)
+   pr_info("detected %s revision unknown\n", soc);
+   else
+   pr_info("detected %s revision %d.%d\n", soc,
(revision >> 4) & 0xf,
revision & 0xf);
 }
-- 
2.14.3


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


[PATCH] commands: of_display_timings: Add simple-panel support

2018-04-20 Thread Stefan Riedmueller
Display timings can now be set with simple-panel method which selects
the required timings by the compatible of the simple panel devicetree
node.

This patch adds an option to set simple panel timings with the
of_display_timings command by setting the compatible of the display node.
The options -P and -c were implemented. The -P option requires the display
node path as argument and the -c option requires the compatible to set.

This has one downside. The available simple panel timings cannot be
listed since the timings are defined in the kernel. Account for this in the
help text.

Signed-off-by: Stefan Riedmueller 
---
 commands/of_display_timings.c | 65 ---
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index ccf2db0..ca8275f 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -28,6 +28,39 @@
 #include 
 #include 
 
+struct panel_info {
+   char *displaypath;
+   char *compatible;
+};
+
+static int of_panel_timing(struct device_node *root, void *context)
+{
+   int ret = 0;
+   struct panel_info *panel = (struct panel_info*)context;
+   struct device_node *display;
+
+   display = of_find_node_by_path_from(root, panel->displaypath);
+   if (!display) {
+   pr_err("Path to display node is not vaild.\n");
+   ret = -EINVAL;
+   goto out;
+   }
+
+   ret = of_set_property(display, "compatible",
+ panel->compatible,
+ strlen(panel->compatible) + 1, 1);
+
+   if (ret < 0) {
+   pr_err("Could not update compatible property\n");
+   goto out;
+   }
+
+   ret = of_device_enable(display);
+
+out:
+   return ret;
+}
+
 static int of_display_timing(struct device_node *root, void *timingpath)
 {
int ret = 0;
@@ -55,10 +88,12 @@ static int do_of_display_timings(int argc, char *argv[])
struct device_node *root = NULL;
struct device_node *display = NULL;
struct device_node *timings = NULL;
+   struct panel_info *panel = NULL;
char *timingpath = NULL;
char *dtbfile = NULL;
+   char *compatible = NULL;
 
-   while ((opt = getopt(argc, argv, "sS:lf:")) > 0) {
+   while ((opt = getopt(argc, argv, "sS:lf:c:P:")) > 0) {
switch (opt) {
case 'l':
list = 1;
@@ -69,10 +104,18 @@ static int do_of_display_timings(int argc, char *argv[])
case 's':
selected = 1;
break;
+   case 'c':
+   compatible = optarg;
+   break;
case 'S':
timingpath = xzalloc(strlen(optarg) + 1);
strcpy(timingpath, optarg);
break;
+   case 'P':
+   panel = xzalloc(sizeof(struct panel_info));
+   panel->displaypath = xzalloc(strlen(optarg) + 1);
+   strcpy(panel->displaypath, optarg);
+   break;
default:
return COMMAND_ERROR_USAGE;
}
@@ -140,6 +183,18 @@ static int do_of_display_timings(int argc, char *argv[])
printf("No selected display-timings found.\n");
}
 
+   if (panel) {
+   if (!compatible) {
+   pr_err("No compatible argument. -P option requires 
compatible with -c option\n");
+   return -EINVAL;
+   } else {
+   panel->compatible = xzalloc(strlen(compatible) + 1);
+   strcpy(panel->compatible, compatible);
+   }
+
+   of_register_fixup(of_panel_timing, panel);
+   }
+
if (timingpath)
of_register_fixup(of_display_timing, timingpath);
 
@@ -148,16 +203,18 @@ static int do_of_display_timings(int argc, char *argv[])
 
 BAREBOX_CMD_HELP_START(of_display_timings)
 BAREBOX_CMD_HELP_TEXT("Options:")
-BAREBOX_CMD_HELP_OPT("-l",  "list path of all available display-timings\n")
-BAREBOX_CMD_HELP_OPT("-s",  "list path of all selected display-timings\n")
+BAREBOX_CMD_HELP_OPT("-l",  "list path of all available 
display-timings\n\t\tNOTE: simple-panel timings cannot be listed\n")
+BAREBOX_CMD_HELP_OPT("-s",  "list path of all selected 
display-timings\n\t\tNOTE: simple-panel timings cannot be listed\n")
+BAREBOX_CMD_HELP_OPT("-c",  "display compatible to enable with -P option. Has 
no effect on -S option\n")
 BAREBOX_CMD_HELP_OPT("-S path",  "select display-timings and register oftree 
fixup\n")
+BAREBOX_CMD_HELP_OPT("-P path",  "select simple-panel node and register oftree 
fixup with -c compatible\n")
 BAREBOX_CMD_HELP_OPT("-f dtb",  "work on dtb. Has no effect on -s 

[PATCH] video: tc358767: don't link AUX i2c adapter to parent OF node

2018-04-20 Thread Lucas Stach
Otherwise the i2c core will try to populate the TC358767 child nodes
as i2c devices, which is wrong.

Signed-off-by: Lucas Stach 
---
 drivers/video/tc358767.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/tc358767.c b/drivers/video/tc358767.c
index d4749b15c7a1..125e8236c153 100644
--- a/drivers/video/tc358767.c
+++ b/drivers/video/tc358767.c
@@ -1413,7 +1413,6 @@ static int tc_probe(struct device_d *dev)
tc->adapter.master_xfer = tc_aux_i2c_xfer;
tc->adapter.nr = -1; /* any free */
tc->adapter.dev.parent = dev;
-   tc->adapter.dev.device_node = dev->device_node;
/* Add I2C adapter */
ret = i2c_add_numbered_adapter(>adapter);
if (ret < 0) {
-- 
2.16.3


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


[PATCH v1] Crypt and decrypt files using password in keystore.

2018-04-20 Thread Gerd Pauli
Adds ccryptlib library in crypto which implements a
stream cipher based on the block cipher Rijndael,
the candidate for the AES standard.
Compatible with the ccrypt tool in linux
from Peter Selinger.

Usage: ccrypt [-e|-d] -k KEYNAME_IN_KEYSTORE SRC DST

Signed-off-by: Gerd Pauli 
---
 commands/Kconfig|   17 +
 commands/Makefile   |1 +
 commands/ccrypt.c   |  249 +
 crypto/Kconfig  |7 +
 crypto/Makefile |1 +
 crypto/ccryptlib.c  | 1467 +++
 include/ccryptlib.h |  102 
 7 files changed, 1844 insertions(+)
 create mode 100644 commands/ccrypt.c
 create mode 100644 crypto/ccryptlib.c
 create mode 100644 include/ccryptlib.h

diff --git a/commands/Kconfig b/commands/Kconfig
index 951a86963..b6911246a 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2137,6 +2137,23 @@ config CMD_SEED
help
  Seed the pseudo random number generator (PRNG)
 
+config CMD_CCRYPT
+tristate
+prompt "ccrypt"
+select CRYPTO_CCRYPTLIB
+select CRYPTO_KEYSTORE
+help
+  encrypting/decrypting a character stream
+  ccrypt implements a stream cipher based on the block cipher
+  Rijndael.
+
+  Usage: ccrypt [-ed] [-K name] srcfile dstfile
+
+  Options:
+-eencrypt srcfile to dstfile
+-ddecrypt srcfile to dstfile
+-k name   use key with name from keystore
+
 # end Miscellaneous commands
 endmenu
 
diff --git a/commands/Makefile b/commands/Makefile
index eb4796389..3693bf553 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -123,3 +123,4 @@ obj-$(CONFIG_CMD_MMC_EXTCSD)+= mmc_extcsd.o
 obj-$(CONFIG_CMD_NAND_BITFLIP) += nand-bitflip.o
 obj-$(CONFIG_CMD_SEED) += seed.o
 obj-$(CONFIG_CMD_IP_ROUTE_GET)  += ip-route-get.o
+obj-$(CONFIG_CMD_CCRYPT)+= ccrypt.o
diff --git a/commands/ccrypt.c b/commands/ccrypt.c
new file mode 100644
index 0..1b0ee9f1a
--- /dev/null
+++ b/commands/ccrypt.c
@@ -0,0 +1,249 @@
+/* -*- Mode:C; c-file-style:"linux"; -*- */
+
+/* Copyright (C) 2018 Gerd Pauli  0) {
+   switch(opt) {
+   case 'e':
+   encrypt=1;
+   break;
+   case 'd':
+   decrypt=1;
+   break;
+