* [PATCH v2 2/8] clocksource: Add rk3288 timer driver
From: Wadim Egorov @ 2016-08-24 12:49 UTC (permalink / raw)
To: barebox
In-Reply-To: <1472042970-35151-1-git-send-email-w.egorov@phytec.de>
This driver comes from the u-boot (v2016.01).
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
Changes since v1:
- moved rk_timer to drivers/clocksource
- rk_timer now binds against a DT node
---
arch/arm/mach-rockchip/Kconfig | 5 ++
arch/arm/mach-rockchip/include/mach/timer.h | 19 ++++++++
drivers/clocksource/Kconfig | 4 ++
drivers/clocksource/Makefile | 1 +
drivers/clocksource/rk_timer.c | 73 +++++++++++++++++++++++++++++
5 files changed, 102 insertions(+)
create mode 100644 arch/arm/mach-rockchip/include/mach/timer.h
create mode 100644 drivers/clocksource/rk_timer.c
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index e027fae..71fcbe7 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -7,6 +7,10 @@ config ARCH_TEXT_BASE
default 0x68000000 if ARCH_RK3188
default 0x0 if ARCH_RK3288
+config RK_TIMER
+ hex
+ default 1
+
choice
prompt "Select Rockchip SoC"
@@ -15,6 +19,7 @@ config ARCH_RK3188
config ARCH_RK3288
bool "Rockchip RK3288 SoCs"
+ select CLOCKSOURCE_ROCKCHIP
endchoice
comment "select Rockchip boards:"
diff --git a/arch/arm/mach-rockchip/include/mach/timer.h b/arch/arm/mach-rockchip/include/mach/timer.h
new file mode 100644
index 0000000..e6ed0e4
--- /dev/null
+++ b/arch/arm/mach-rockchip/include/mach/timer.h
@@ -0,0 +1,19 @@
+/*
+ * (C) Copyright 2015 Rockchip Electronics Co., Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _ASM_ARCH_TIMER_H
+#define _ASM_ARCH_TIMER_H
+
+struct rk_timer {
+ unsigned int timer_load_count0;
+ unsigned int timer_load_count1;
+ unsigned int timer_curr_value0;
+ unsigned int timer_curr_value1;
+ unsigned int timer_ctrl_reg;
+ unsigned int timer_int_status;
+};
+
+#endif
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 3fb09fb..f1ab554 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -49,3 +49,7 @@ config CLOCKSOURCE_ORION
config CLOCKSOURCE_UEMD
bool
depends on ARCH_UEMD
+
+config CLOCKSOURCE_ROCKCHIP
+ bool
+ depends on ARCH_ROCKCHIP
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 4eb1656..39982ff 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_CLOCKSOURCE_MVEBU) += mvebu.o
obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
obj-$(CONFIG_CLOCKSOURCE_ORION) += orion.o
obj-$(CONFIG_CLOCKSOURCE_UEMD) += uemd.o
+obj-$(CONFIG_CLOCKSOURCE_ROCKCHIP)+= rk_timer.o
diff --git a/drivers/clocksource/rk_timer.c b/drivers/clocksource/rk_timer.c
new file mode 100644
index 0000000..baa517c
--- /dev/null
+++ b/drivers/clocksource/rk_timer.c
@@ -0,0 +1,73 @@
+/*
+ * (C) Copyright 2015 Rockchip Electronics Co., Ltd
+ *
+ * (C) Copyright 2016 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov <w.egorov@phytec.de>
+
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <clock.h>
+#include <init.h>
+#include <io.h>
+#include <mach/timer.h>
+#include <stdio.h>
+#include <mach/hardware.h>
+#include <mach/cru_rk3288.h>
+#include <common.h>
+
+struct rk_timer *timer_ptr;
+
+static uint64_t rockchip_get_ticks(void)
+{
+ uint64_t timebase_h, timebase_l;
+
+ timebase_l = readl(&timer_ptr->timer_curr_value0);
+ timebase_h = readl(&timer_ptr->timer_curr_value1);
+
+ return timebase_h << 32 | timebase_l;
+}
+
+static struct clocksource rkcs = {
+ .read = rockchip_get_ticks,
+ .mask = CLOCKSOURCE_MASK(32),
+ .shift = 10,
+};
+
+static int rockchip_timer_probe(struct device_d *dev)
+{
+ struct resource *iores;
+
+ iores = dev_request_mem_resource(dev, 0);
+ if (IS_ERR(iores))
+ return PTR_ERR(iores);
+ timer_ptr = IOMEM(iores->start) + 0x20 * CONFIG_RK_TIMER;
+
+ rkcs.mult = clocksource_hz2mult(OSC_HZ, rkcs.shift);
+
+ writel(0xffffffff, &timer_ptr->timer_load_count0);
+ writel(0xffffffff, &timer_ptr->timer_load_count1);
+ writel(1, &timer_ptr->timer_ctrl_reg);
+
+ return init_clock(&rkcs);
+}
+
+static __maybe_unused struct of_device_id rktimer_dt_ids[] = {
+ {
+ .compatible = "rockchip,rk3288-timer",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver_d rktimer_driver = {
+ .name = "rockchip-timer",
+ .probe = rockchip_timer_probe,
+ .of_compatible = DRV_OF_COMPAT(rktimer_dt_ids),
+};
+
+static int rktimer_init(void)
+{
+ return platform_driver_register(&rktimer_driver);
+}
+core_initcall(rktimer_init);
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* [PATCH v2 3/8] ARM: rockchip: Add early debug support for RK3288
From: Wadim Egorov @ 2016-08-24 12:49 UTC (permalink / raw)
To: barebox
In-Reply-To: <1472042970-35151-1-git-send-email-w.egorov@phytec.de>
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
Changes since v1:
- use CONFIG_BAUDRATE instead of hard coded value
- use IOMEM macros
---
arch/arm/mach-rockchip/include/mach/debug_ll.h | 73 +++++++++++++++-----------
common/Kconfig | 6 +--
2 files changed, 46 insertions(+), 33 deletions(-)
diff --git a/arch/arm/mach-rockchip/include/mach/debug_ll.h b/arch/arm/mach-rockchip/include/mach/debug_ll.h
index c666b99..9fde297 100644
--- a/arch/arm/mach-rockchip/include/mach/debug_ll.h
+++ b/arch/arm/mach-rockchip/include/mach/debug_ll.h
@@ -1,25 +1,31 @@
#ifndef __MACH_DEBUG_LL_H__
#define __MACH_DEBUG_LL_H__
+#include <common.h>
#include <io.h>
+#include <mach/rk3188-regs.h>
+#include <mach/rk3288-regs.h>
+
+#ifdef CONFIG_ARCH_RK3188
+
+#define UART_CLOCK 100000000
+#define RK_DEBUG_SOC RK3188
+#define serial_out(a, v) writeb(v, a)
+#define serial_in(a) readb(a)
+
+#elif defined CONFIG_ARCH_RK3288
+
+#define UART_CLOCK 24000000
+#define RK_DEBUG_SOC RK3288
+#define serial_out(a, v) writel(v, a)
+#define serial_in(a) readl(a)
-#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 0
-#define UART_BASE 0x10124000
-#endif
-#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 1
-#define UART_BASE 0x10126000
-#endif
-#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 2
-#define UART_BASE 0x20064000
-#endif
-#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 3
-#define UART_BASE 0x20068000
#endif
-#define LSR_THRE 0x20 /* Xmit holding register empty */
-#define LSR (5 << 2)
-#define THR (0 << 2)
+#define __RK_UART_BASE(soc, num) soc##_UART##num##_BASE
+#define RK_UART_BASE(soc, num) __RK_UART_BASE(soc, num)
+#define LSR_THRE 0x20 /* Xmit holding register empty */
#define LCR_BKSE 0x80 /* Bank select enable */
#define LSR (5 << 2)
#define THR (0 << 2)
@@ -33,28 +39,35 @@
static inline void INIT_LL(void)
{
- unsigned int clk = 100000000;
- unsigned int divisor = clk / 16 / 115200;
-
- writeb(0x00, UART_BASE + LCR);
- writeb(0x00, UART_BASE + IER);
- writeb(0x07, UART_BASE + MDR);
- writeb(LCR_BKSE, UART_BASE + LCR);
- writeb(divisor & 0xff, UART_BASE + DLL);
- writeb(divisor >> 8, UART_BASE + DLM);
- writeb(0x03, UART_BASE + LCR);
- writeb(0x03, UART_BASE + MCR);
- writeb(0x07, UART_BASE + FCR);
- writeb(0x00, UART_BASE + MDR);
+ void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
+ CONFIG_DEBUG_ROCKCHIP_UART_PORT));
+ unsigned int divisor = DIV_ROUND_CLOSEST(UART_CLOCK,
+ 16 * CONFIG_BAUDRATE);
+
+ serial_out(base + LCR, 0x00);
+ serial_out(base + IER, 0x00);
+ serial_out(base + MDR, 0x07);
+ serial_out(base + LCR, LCR_BKSE);
+ serial_out(base + DLL, divisor & 0xff);
+ serial_out(base + DLM, divisor >> 8);
+ serial_out(base + LCR, 0x03);
+ serial_out(base + MCR, 0x03);
+ serial_out(base + FCR, 0x07);
+ serial_out(base + MDR, 0x00);
}
static inline void PUTC_LL(char c)
{
+ void __iomem *base = IOMEM(RK_UART_BASE(RK_DEBUG_SOC,
+ CONFIG_DEBUG_ROCKCHIP_UART_PORT));
+
/* Wait until there is space in the FIFO */
- while ((readb(UART_BASE + LSR) & LSR_THRE) == 0);
+ while ((serial_in(base + LSR) & LSR_THRE) == 0)
+ ;
/* Send the character */
- writeb(c, UART_BASE + THR);
+ serial_out(base + THR, c);
/* Wait to make sure it hits the line, in case we die too soon. */
- while ((readb(UART_BASE + LSR) & LSR_THRE) == 0);
+ while ((serial_in(base + LSR) & LSR_THRE) == 0)
+ ;
}
#endif
diff --git a/common/Kconfig b/common/Kconfig
index 679954e..7a51bf0 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1081,11 +1081,11 @@ config DEBUG_AM33XX_UART
on AM33XX.
config DEBUG_ROCKCHIP_UART
- bool "RK31xx Debug UART"
+ bool "RK3xxx Debug UART"
depends on ARCH_ROCKCHIP
help
Say Y here if you want kernel low-level debugging support
- on RK31XX.
+ on RK3XXX.
endchoice
@@ -1120,7 +1120,7 @@ config DEBUG_OMAP_UART_PORT
AM33XX: 0 - 2
config DEBUG_ROCKCHIP_UART_PORT
- int "RK31xx UART debug port" if DEBUG_ROCKCHIP_UART
+ int "RK3xxx UART debug port" if DEBUG_ROCKCHIP_UART
default 2
depends on ARCH_ROCKCHIP
help
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* [PATCH v2 5/8] mci: dw_mmc: Add RK3288 compatible string
From: Wadim Egorov @ 2016-08-24 12:49 UTC (permalink / raw)
To: barebox
In-Reply-To: <1472042970-35151-1-git-send-email-w.egorov@phytec.de>
The SDHC used in the RK2928 and RK3288 are compatible with each other.
Add a compatible string for RK3288's SDHC.
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
drivers/mci/dw_mmc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/mci/dw_mmc.c b/drivers/mci/dw_mmc.c
index 0e004ab..27c36a6 100644
--- a/drivers/mci/dw_mmc.c
+++ b/drivers/mci/dw_mmc.c
@@ -753,6 +753,8 @@ static __maybe_unused struct of_device_id dw_mmc_compatible[] = {
}, {
.compatible = "rockchip,rk2928-dw-mshc",
}, {
+ .compatible = "rockchip,rk3288-dw-mshc",
+ }, {
/* sentinel */
}
};
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* Re: AT91RM9200 hang in atmel_serial_putc
From: Sascha Hauer @ 2016-08-24 12:24 UTC (permalink / raw)
To: Peter Kardos; +Cc: barebox
In-Reply-To: <cacf597f-e684-44e0-84c5-9366481dbed2@gmail.com>
Hi Peter,
On Mon, Aug 22, 2016 at 10:39:24PM +0200, Peter Kardos wrote:
> Hi Sascha,
>
> I've tested your workaround and it seems to work; the board starts and
> attempts
> to boot.
I just sent a proper solution for that problem, you're on Cc. I'm
confident that this solves your problem. Could you give this a test
please?
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* [PATCH] ARM: vector_table: Fix creation of second level page table
From: Sascha Hauer @ 2016-08-24 12:23 UTC (permalink / raw)
To: Barebox List; +Cc: Peter Kardos
The second level page tables can only start at a 1MiB section boundary,
so instead of calling arm_create_pte() with the high vector address
(which is 0xffff0000, not 1MiB aligned) we have to call it with
0xfff00000 to correctly create a second level page table. The vectors
themselves worked as expected with the old value, but the memory around
it did not do a 1:1 mapping anymore. This breaks SoCs which have
peripherals in that area, for example Atmel SoCs like the AT91RM9200.
Fixes: f6b77fe9: ARM: Rework vector table setup
Reported-by: Peter Kardos <kardos.peter.sk@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/cpu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index a31bce4..2b70866 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -307,7 +307,7 @@ static void create_vector_table(unsigned long adr)
vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
pr_debug("Creating vector table, virt = 0x%p, phys = 0x%08lx\n",
vectors, adr);
- exc = arm_create_pte(adr);
+ exc = arm_create_pte(adr & ~(SZ_1M - 1));
idx = (adr & (SZ_1M - 1)) >> PAGE_SHIFT;
exc[idx] = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached;
}
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* Re: [PATCH] arm: Add both .lds files to CLEAN_FILES unconditionally
From: Sascha Hauer @ 2016-08-24 12:02 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
In-Reply-To: <1472003222-9478-1-git-send-email-andrew.smirnov@gmail.com>
On Tue, Aug 23, 2016 at 06:47:02PM -0700, Andrey Smirnov wrote:
> 'clean' target is listed on 'no-dot-config-targets' list in main
> Makefile so that conditional statement would yeild the same result
> every time. Given how CLEAN_FILES are rm'ed with -f there should be no
> harm in specifying them both unconditionally.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> arch/arm/Makefile | 4 ----
> 1 file changed, 4 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 55f7248..96ec588 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -314,9 +314,5 @@ endif
> common- += $(patsubst %,arch/arm/boards/%/,$(board-))
>
> CLEAN_FILES += include/generated/mach-types.h barebox-flash-image
> -
> -ifeq ($(CONFIG_CPU_V8), y)
> CLEAN_FILES += arch/arm/lib64/barebox.lds
> -else
> CLEAN_FILES += arch/arm/lib32/barebox.lds
> -endif
> --
> 2.5.5
>
>
> _______________________________________________
> 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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* [PATCH 3/3] video: tc358767: add eDP video encoder driver
From: Philipp Zabel @ 2016-08-24 10:40 UTC (permalink / raw)
To: barebox; +Cc: Andrey Gusakov
In-Reply-To: <1472035219-23917-1-git-send-email-p.zabel@pengutronix.de>
From: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
This patch adds support for the Toshiba TC358767 eDP bridge,
connected via DPI.
Signed-off-by: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/video/Kconfig | 8 +
drivers/video/Makefile | 1 +
drivers/video/tc358767.c | 1313 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 1322 insertions(+)
create mode 100644 drivers/video/tc358767.c
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7ff67e5..2457bb9 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -127,6 +127,14 @@ config DRIVER_VIDEO_MTL017
The MTL017 is a parallel to lvds video encoder chip found on the
Efika MX Smartbook.
+config DRIVER_VIDEO_TC358767
+ bool "TC358767A Display Port encoder"
+ select VIDEO_VPL
+ depends on I2C
+ depends on OFTREE
+ help
+ The TC358767A is a DSI/DPI to eDP video encoder chip
+
config DRIVER_VIDEO_SIMPLE_PANEL
bool "Simple panel support"
select VIDEO_VPL
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index a64fc5f..1bf2e1f 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_DRIVER_VIDEO_BACKLIGHT_PWM) += backlight-pwm.o
obj-$(CONFIG_FRAMEBUFFER_CONSOLE) += fbconsole.o
obj-$(CONFIG_VIDEO_VPL) += vpl.o
obj-$(CONFIG_DRIVER_VIDEO_MTL017) += mtl017.o
+obj-$(CONFIG_DRIVER_VIDEO_TC358767) += tc358767.o
obj-$(CONFIG_DRIVER_VIDEO_SIMPLE_PANEL) += simple-panel.o
obj-$(CONFIG_DRIVER_VIDEO_ATMEL) += atmel_lcdfb.o atmel_lcdfb_core.o
diff --git a/drivers/video/tc358767.c b/drivers/video/tc358767.c
new file mode 100644
index 0000000..f2ea198
--- /dev/null
+++ b/drivers/video/tc358767.c
@@ -0,0 +1,1313 @@
+/*
+ * tc358767 eDP encoder driver
+ *
+ * Copyright (C) 2016 CogentEmbedded Inc
+ * Author: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
+ *
+ * Copyright (C) 2016 Pengutronix, Philipp Zabel <p.zabel@pengutronix.de>
+ *
+ * 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 <common.h>
+#include <init.h>
+#include <driver.h>
+#include <malloc.h>
+#include <errno.h>
+#include <i2c/i2c.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <gpio.h>
+#include <of_gpio.h>
+#include <video/media-bus-format.h>
+#include <video/vpl.h>
+#include <asm-generic/div64.h>
+
+#define DP_LINK_BW_SET 0x100
+#define DP_TRAINING_PATTERN_SET 0x102
+
+#define DP_DOWNSPREAD_CTRL 0x107
+#define DP_SPREAD_AMP_0_5 (1 << 4)
+
+#define DP_MAIN_LINK_CHANNEL_CODING_SET 0x108
+#define DP_SET_ANSI_8B10B (1 << 0)
+
+#define DP_LANE0_1_STATUS 0x202
+#define DP_LANE2_3_STATUS 0x202
+#define DP_LANE_CR_DONE (1 << 0)
+#define DP_LANE_CHANNEL_EQ_DONE (1 << 1)
+#define DP_LANE_SYMBOL_LOCKED (1 << 2)
+#define DP_CHANNEL_EQ_BITS (DP_LANE_CR_DONE | \
+ DP_LANE_CHANNEL_EQ_DONE | \
+ DP_LANE_SYMBOL_LOCKED)
+
+#define DP_LAINE_ALIGN_STATUS_UPDATED 0x204
+#define DP_INTERLANE_ALIGN_DONE (1 << 0)
+
+#define DP_LINK_SCRAMBLING_DISABLE 0x20
+#define DP_TRAINING_PATTERN_1 1
+#define DP_TRAINING_PATTERN_2 2
+
+#define DP_EDP_CONFIGURATION_SET 0x10a
+#define DP_ALTERNATE_SCRAMBLER_RESET_ENABLE (1 << 0)
+
+/* Registers */
+
+/* Display Parallel Interface */
+#define DPIPXLFMT 0x0440
+#define VS_POL_ACTIVE_LOW (1 << 10)
+#define HS_POL_ACTIVE_LOW (1 << 9)
+#define DE_POL_ACTIVE_HIGH (0 << 8)
+#define SUB_CFG_TYPE_CONFIG1 (0 << 2) /* LSB aligned */
+#define SUB_CFG_TYPE_CONFIG2 (1 << 2) /* Loosely Packed */
+#define SUB_CFG_TYPE_CONFIG3 (2 << 2) /* LSB aligned 8-bit */
+#define DPI_BPP_RGB888 (0 << 0)
+#define DPI_BPP_RGB666 (1 << 0)
+#define DPI_BPP_RGB565 (2 << 0)
+
+/* Video Path */
+#define VPCTRL0 0x0450
+#define OPXLFMT_RGB666 (0 << 8)
+#define OPXLFMT_RGB888 (1 << 8)
+#define FRMSYNC_DISABLED (0 << 4) /* Video Timing Gen Disabled */
+#define FRMSYNC_ENABLED (1 << 4) /* Video Timing Gen Enabled */
+#define MSF_DISABLED (0 << 0) /* Magic Square FRC disabled */
+#define MSF_ENABLED (1 << 0) /* Magic Square FRC enabled */
+#define HTIM01 0x0454
+#define HTIM02 0x0458
+#define VTIM01 0x045c
+#define VTIM02 0x0460
+#define VFUEN0 0x0464
+#define VFUEN BIT(0) /* Video Frame Timing Upload */
+
+/* System */
+#define TC_IDREG 0x0500
+#define SYSCTRL 0x0510
+#define DP0_AUDSRC_NO_INPUT (0 << 3)
+#define DP0_AUDSRC_I2S_RX (1 << 3)
+#define DP0_VIDSRC_NO_INPUT (0 << 0)
+#define DP0_VIDSRC_DSI_RX (1 << 0)
+#define DP0_VIDSRC_DPI_RX (2 << 0)
+#define DP0_VIDSRC_COLOR_BAR (3 << 0)
+
+/* Control */
+#define DP0CTL 0x0600
+#define VID_MN_GEN BIT(6) /* Auto-generate M/N values */
+#define EF_EN BIT(5) /* Enable Enhanced Framing */
+#define VID_EN BIT(1) /* Video transmission enable */
+#define DP_EN BIT(0) /* Enable DPTX function */
+
+/* Clocks */
+#define DP0_VIDMNGEN0 0x0610
+#define DP0_VIDMNGEN1 0x0614
+#define DP0_VMNGENSTATUS 0x0618
+
+/* Main Channel */
+#define DP0_SECSAMPLE 0x0640
+#define DP0_VIDSYNCDELAY 0x0644
+#define DP0_TOTALVAL 0x0648
+#define DP0_STARTVAL 0x064c
+#define DP0_ACTIVEVAL 0x0650
+#define DP0_SYNCVAL 0x0654
+#define DP0_MISC 0x0658
+#define TU_SIZE_RECOMMENDED (0x3f << 16) /* LSCLK cycles per TU */
+#define BPC_6 (0 << 5)
+#define BPC_8 (1 << 5)
+
+/* AUX channel */
+#define DP0_AUXCFG0 0x0660
+#define DP0_AUXCFG1 0x0664
+#define AUX_RX_FILTER_EN BIT(16)
+
+#define DP0_AUXADDR 0x0668
+#define DP0_AUXWDATA(i) (0x066c + (i) * 4)
+#define DP0_AUXRDATA(i) (0x067c + (i) * 4)
+#define DP0_AUXSTATUS 0x068c
+#define AUX_STATUS_MASK 0xf0
+#define AUX_STATUS_SHIFT 4
+#define AUX_TIMEOUT BIT(1)
+#define AUX_BUSY BIT(0)
+#define DP0_AUXI2CADR 0x0698
+
+/* Link Training */
+#define DP0_SRCCTRL 0x06a0
+#define DP0_SRCCTRL_SCRMBLDIS BIT(13)
+#define DP0_SRCCTRL_EN810B BIT(12)
+#define DP0_SRCCTRL_NOTP (0 << 8)
+#define DP0_SRCCTRL_TP1 (1 << 8)
+#define DP0_SRCCTRL_TP2 (2 << 8)
+#define DP0_SRCCTRL_LANESKEW BIT(7)
+#define DP0_SRCCTRL_SSCG BIT(3)
+#define DP0_SRCCTRL_LANES_1 (0 << 2)
+#define DP0_SRCCTRL_LANES_2 (1 << 2)
+#define DP0_SRCCTRL_BW27 (1 << 1)
+#define DP0_SRCCTRL_BW162 (0 << 1)
+#define DP0_SRCCTRL_AUTOCORRECT BIT(0)
+#define DP0_LTSTAT 0x06d0
+#define LT_LOOPDONE BIT(13)
+#define LT_STATUS_MASK (0x1f << 8)
+#define LT_CHANNEL1_EQ_BITS (DP_CHANNEL_EQ_BITS << 4)
+#define LT_INTERLANE_ALIGN_DONE BIT(3)
+#define LT_CHANNEL0_EQ_BITS (DP_CHANNEL_EQ_BITS)
+#define DP0_SNKLTCHGREQ 0x06d4
+#define DP0_LTLOOPCTRL 0x06d8
+#define DP0_SNKLTCTRL 0x06e4
+
+/* PHY */
+#define DP_PHY_CTRL 0x0800
+#define DP_PHY_RST BIT(28) /* DP PHY Global Soft Reset */
+#define BGREN BIT(25) /* AUX PHY BGR Enable */
+#define PWR_SW_EN BIT(24) /* PHY Power Switch Enable */
+#define PHY_M1_RST BIT(12) /* Reset PHY1 Main Channel */
+#define PHY_RDY BIT(16) /* PHY Main Channels Ready */
+#define PHY_M0_RST BIT(8) /* Reset PHY0 Main Channel */
+#define PHY_A0_EN BIT(1) /* PHY Aux Channel0 Enable */
+#define PHY_M0_EN BIT(0) /* PHY Main Channel0 Enable */
+
+/* PLL */
+#define DP0_PLLCTRL 0x0900
+#define DP1_PLLCTRL 0x0904 /* not defined in DS */
+#define PXL_PLLCTRL 0x0908
+#define PLLUPDATE BIT(2)
+#define PLLBYP BIT(1)
+#define PLLEN BIT(0)
+#define PXL_PLLPARAM 0x0914
+#define IN_SEL_REFCLK (0 << 14)
+#define SYS_PLLPARAM 0x0918
+#define REF_FREQ_38M4 (0 << 8) /* 38.4 MHz */
+#define REF_FREQ_19M2 (1 << 8) /* 19.2 MHz */
+#define REF_FREQ_26M (2 << 8) /* 26 MHz */
+#define REF_FREQ_13M (3 << 8) /* 13 MHz */
+#define SYSCLK_SEL_LSCLK (0 << 4)
+#define LSCLK_DIV_1 (0 << 0)
+#define LSCLK_DIV_2 (1 << 0)
+
+/* Test & Debug */
+#define TSTCTL 0x0a00
+#define PLL_DBG 0x0a04
+
+struct tc_edp_link {
+ u8 rate;
+ u8 rev;
+ u8 lanes;
+ u8 enhanced;
+ u8 assr;
+ int scrambler_dis;
+ int spread;
+ int coding8b10b;
+ u8 swing;
+ u8 preemp;
+};
+
+struct tc_data {
+ struct i2c_client *client;
+ struct device_d *dev;
+ /* DP AUX channel */
+ struct i2c_adapter adapter;
+ struct vpl vpl;
+
+ /* link settings */
+ struct tc_edp_link link;
+
+ /* mode */
+ struct fb_videomode *mode;
+
+ u32 rev;
+ u8 assr;
+
+ char *edid;
+
+ int sd_gpio;
+ int sd_active_high;
+ int reset_gpio;
+ int reset_active_high;
+ struct clk *refclk;
+};
+#define to_tc_i2c_struct(a) container_of(a, struct tc_data, adapter)
+
+static int tc_write_reg(struct tc_data *data, u16 reg, u32 value)
+{
+ int ret;
+ u8 buf[4];
+
+ buf[0] = value & 0xff;
+ buf[1] = (value >> 8) & 0xff;
+ buf[2] = (value >> 16) & 0xff;
+ buf[3] = (value >> 24) & 0xff;
+
+ ret = i2c_write_reg(data->client, reg | I2C_ADDR_16_BIT, buf, 4);
+ if (ret != 4) {
+ dev_err(data->dev, "error writing reg 0x%04x: %d\n",
+ reg, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+
+static int tc_read_reg(struct tc_data *data, u16 reg, u32 *value)
+{
+ int ret;
+ u8 buf[4];
+
+ ret = i2c_read_reg(data->client, reg | I2C_ADDR_16_BIT, buf, 4);
+ if (ret != 4) {
+ dev_err(data->dev, "error reading reg 0x%04x: %d\n",
+ reg, ret);
+ return ret;
+ }
+
+ *value = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+
+ return 0;
+}
+
+/* simple macros to avoid error checks */
+#define tc_write(reg, var) do { \
+ ret = tc_write_reg(tc, reg, var); \
+ if (ret) \
+ goto err; \
+ } while (0)
+#define tc_read(reg, var) do { \
+ ret = tc_read_reg(tc, reg, var); \
+ if (ret) \
+ goto err; \
+ } while (0)
+
+static int tc_aux_get_status(struct tc_data *tc)
+{
+ int ret;
+ u32 value;
+
+ tc_read(DP0_AUXSTATUS, &value);
+ if ((value & 0x01) == 0x00) {
+ switch (value & 0xf0) {
+ case 0x00:
+ /* Ack */
+ return 0;
+ case 0x40:
+ /* Nack */
+ return -EIO;
+ case 0x80:
+ dev_err(tc->dev, "i2c defer\n");
+ return -EAGAIN;
+ }
+ return 0;
+ }
+
+ if (value & 0x02) {
+ dev_err(tc->dev, "i2c access timeout!\n");
+ return -ETIME;
+ }
+ return -EBUSY;
+err:
+ return ret;
+}
+
+static int tc_aux_wait_busy(struct tc_data *tc, unsigned int timeout_ms)
+{
+ int ret;
+ u32 value;
+
+ do {
+ tc_read(DP0_AUXSTATUS, &value);
+ if ((value & AUX_BUSY) == 0x00)
+ return 0;
+ mdelay(1);
+ } while (timeout_ms--);
+
+ return -EBUSY;
+err:
+ return ret;
+}
+
+static int tc_aux_read(struct tc_data *tc, int reg, char *data, int size)
+{
+ int i = 0;
+ int ret;
+ u32 tmp;
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ /* store address */
+ tc_write(DP0_AUXADDR, reg);
+ /* start transfer */
+ tc_write(DP0_AUXCFG0, ((size - 1) << 8) | 0x09);
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ ret = tc_aux_get_status(tc);
+ if (ret)
+ goto err;
+
+ /* read data */
+ while (i < size) {
+ if ((i % 4) == 0)
+ tc_read(DP0_AUXRDATA(i >> 2), &tmp);
+ data[i] = tmp & 0xFF;
+ tmp = tmp >> 8;
+ i++;
+ }
+
+ return 0;
+err:
+ dev_err(tc->dev, "tc_aux_read error: %d\n", ret);
+ return ret;
+}
+
+static int tc_aux_write(struct tc_data *tc, int reg, char *data, int size)
+{
+ int i = 0;
+ int ret;
+ u32 tmp = 0;
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ i = 0;
+ /* store data */
+ while (i < size) {
+ tmp = tmp | (data[i] << (8 * (i & 0x03)));
+ i++;
+ if (((i % 4) == 0) ||
+ (i == size)) {
+ tc_write(DP0_AUXWDATA(i >> 2), tmp);
+ tmp = 0;
+ }
+ }
+ /* store address */
+ tc_write(DP0_AUXADDR, reg);
+ /* start transfer */
+ tc_write(DP0_AUXCFG0, ((size - 1) << 8) | 0x08);
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ ret = tc_aux_get_status(tc);
+ if (ret)
+ goto err;
+
+ return 0;
+err:
+ dev_err(tc->dev, "tc_aux_write error: %d\n", ret);
+ return ret;
+}
+
+static int tc_aux_i2c_read(struct tc_data *tc, struct i2c_msg *msg)
+{
+ int i = 0;
+ int ret;
+ u32 tmp;
+
+ if (msg->flags & I2C_M_DATA_ONLY)
+ return -EINVAL;
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ /* store address */
+ tc_write(DP0_AUXADDR, msg->addr);
+
+ /* start transfer */
+ tc_write(DP0_AUXCFG0, ((msg->len - 1) << 8) | 0x01);
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ ret = tc_aux_get_status(tc);
+ if (ret)
+ goto err;
+
+ /* read data */
+ while (i < msg->len) {
+ if ((i % 4) == 0)
+ tc_read(DP0_AUXRDATA(i >> 2), &tmp);
+ msg->buf[i] = tmp & 0xFF;
+ tmp = tmp >> 8;
+ i++;
+ }
+
+ return 0;
+err:
+ return ret;
+}
+
+static int tc_aux_i2c_write(struct tc_data *tc, struct i2c_msg *msg)
+{
+ int i = 0;
+ int ret;
+ u32 tmp = 0;
+
+ if (msg->flags & I2C_M_DATA_ONLY)
+ return -EINVAL;
+
+ if (msg->len > 16) {
+ dev_err(tc->dev, "this bus support max 16 bytes per transfer\n");
+ return -EINVAL;
+ }
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ /* store data */
+ while (i < msg->len) {
+ tmp = (tmp << 8) | msg->buf[i];
+ i++;
+ if (((i % 4) == 0) ||
+ (i == msg->len)) {
+ tc_write(DP0_AUXWDATA(i >> 2), tmp);
+ tmp = 0;
+ }
+ }
+ /* store address */
+ tc_write(DP0_AUXADDR, msg->addr);
+ /* start transfer */
+ tc_write(DP0_AUXCFG0, ((msg->len - 1) << 8) | 0x00);
+
+ ret = tc_aux_wait_busy(tc, 100);
+ if (ret)
+ goto err;
+
+ ret = tc_aux_get_status(tc);
+ if (ret)
+ goto err;
+
+ return 0;
+err:
+ return ret;
+}
+
+static int tc_aux_i2c_xfer(struct i2c_adapter *adapter,
+ struct i2c_msg *msgs, int num)
+{
+ struct tc_data *tc = to_tc_i2c_struct(adapter);
+ unsigned int i;
+ int ret;
+
+ /* check */
+ for (i = 0; i < num; i++) {
+ if (msgs[i].len > 16) {
+ dev_err(tc->dev, "this bus support max 16 bytes per transfer\n");
+ return -EINVAL;
+ }
+ }
+
+ /* read/write data */
+ for (i = 0; i < num; i++) {
+ /* write/read data */
+ if (msgs[i].flags & I2C_M_RD)
+ ret = tc_aux_i2c_read(tc, &msgs[i]);
+ else
+ ret = tc_aux_i2c_write(tc, &msgs[i]);
+ if (ret)
+ goto err;
+ }
+
+err:
+ return (ret < 0) ? ret : num;
+}
+
+static const char * const training_pattern1_errors[] = {
+ "No errors",
+ "Aux write error",
+ "Aux read error",
+ "Max voltage reached error",
+ "Loop counter expired error",
+ "res", "res", "res"
+};
+
+static const char * const training_pattern2_errors[] = {
+ "No errors",
+ "Aux write error",
+ "Aux read error",
+ "Clock recovery failed error",
+ "Loop counter expired error",
+ "res", "res", "res"
+};
+
+static u32 tc_srcctrl(struct tc_data *tc)
+{
+ /*
+ * No training pattern, skew lane 1 data by two LSCLK cycles with
+ * respect to lane 0 data, AutoCorrect Mode = 0
+ */
+ u32 reg = DP0_SRCCTRL_NOTP | DP0_SRCCTRL_LANESKEW;
+
+ if (tc->link.scrambler_dis)
+ reg |= DP0_SRCCTRL_SCRMBLDIS; /* Scrambler Disabled */
+ if (tc->link.coding8b10b)
+ /* Enable 8/10B Encoder (TxData[19:16] not used) */
+ reg |= DP0_SRCCTRL_EN810B;
+ if (tc->link.spread)
+ reg |= DP0_SRCCTRL_SSCG; /* Spread Spectrum Enable */
+ if (tc->link.lanes == 2)
+ reg |= DP0_SRCCTRL_LANES_2; /* Two Main Channel Lanes */
+ if (tc->link.rate != 0x06)
+ reg |= DP0_SRCCTRL_BW27; /* 2.7 Gbps link */
+ return reg;
+}
+
+static void tc_wait_pll_lock(struct tc_data *tc)
+{
+ /* Wait for PLL to lock: up to 2.09 ms, depending on refclk */
+ mdelay(100);
+}
+
+static int tc_stream_clock_calc(struct tc_data *tc)
+{
+ int ret;
+ /*
+ * If the Stream clock and Link Symbol clock are
+ * asynchronous with each other, the value of M changes over
+ * time. This way of generating link clock and stream
+ * clock is called Asynchronous Clock mode. The value M
+ * must change while the value N stays constant. The
+ * value of N in this Asynchronous Clock mode must be set
+ * to 2^15 or 32,768.
+ *
+ * LSCLK = 1/10 of high speed link clock
+ *
+ * f_STRMCLK = M/N * f_LSCLK
+ * M/N = f_STRMCLK / f_LSCLK
+ *
+ */
+ tc_write(DP0_VIDMNGEN1, 32768);
+
+ return 0;
+err:
+ return ret;
+}
+
+static int tc_aux_link_setup(struct tc_data *tc)
+{
+ unsigned long rate;
+ u32 value;
+ int ret;
+ int timeout;
+
+ rate = clk_get_rate(tc->refclk);
+ switch (rate) {
+ case 38400000:
+ value = REF_FREQ_38M4;
+ break;
+ case 26000000:
+ value = REF_FREQ_26M;
+ break;
+ case 19200000:
+ value = REF_FREQ_19M2;
+ break;
+ case 13000000:
+ value = REF_FREQ_13M;
+ break;
+ default:
+ dev_err(tc->dev, "Invalid refclk rate: %lu Hz\n", rate);
+ return -EINVAL;
+ }
+
+ /* Setup DP-PHY / PLL */
+ value |= SYSCLK_SEL_LSCLK | LSCLK_DIV_2;
+ tc_write(SYS_PLLPARAM, value);
+
+ tc_write(DP_PHY_CTRL, BGREN | PWR_SW_EN | BIT(2) | PHY_A0_EN);
+
+ /*
+ * Initially PLLs are in bypass. Force PLL parameter update,
+ * disable PLL bypass, enable PLL
+ */
+ tc_write(DP0_PLLCTRL, PLLUPDATE | PLLEN);
+ tc_wait_pll_lock(tc);
+
+ tc_write(DP1_PLLCTRL, PLLUPDATE | PLLEN);
+ tc_wait_pll_lock(tc);
+
+ timeout = 1000;
+ do {
+ tc_read(DP_PHY_CTRL, &value);
+ udelay(1);
+ } while ((!(value & (1 << 16))) && (--timeout));
+
+ if (timeout == 0) {
+ dev_err(tc->dev, "Timeout waiting for PHY to become ready");
+ return -ETIMEDOUT;
+ }
+
+ /* Setup AUX link */
+ tc_write(DP0_AUXCFG1, AUX_RX_FILTER_EN |
+ (0x06 << 8) | /* Aux Bit Period Calculator Threshold */
+ (0x3f << 0)); /* Aux Response Timeout Timer */
+
+ return 0;
+err:
+ dev_err(tc->dev, "tc_aux_link_setup failed: %d\n", ret);
+ return ret;
+}
+
+static int tc_get_display_props(struct tc_data *tc)
+{
+ int ret;
+ /* temp buffer */
+ u8 tmp[8];
+
+ /* Read DP Rx Link Capability */
+ ret = tc_aux_read(tc, 0x000, tmp, 8);
+ if (ret)
+ goto err_dpcd_read;
+ /* check rev 1.0 or 1.1 */
+ if ((tmp[1] != 0x06) && (tmp[1] != 0x0a))
+ goto err_dpcd_inval;
+
+ tc->assr = !(tc->rev & 0x02);
+ tc->link.rev = tmp[0];
+ tc->link.rate = tmp[1];
+ tc->link.lanes = tmp[2] & 0x0f;
+ tc->link.enhanced = !!(tmp[2] & 0x80);
+ tc->link.spread = tmp[3] & 0x01;
+ tc->link.coding8b10b = tmp[6] & 0x01;
+ tc->link.scrambler_dis = 0;
+ /* read assr */
+ ret = tc_aux_read(tc, DP_EDP_CONFIGURATION_SET, tmp, 1);
+ if (ret)
+ goto err_dpcd_read;
+ tc->link.assr = tmp[0] & DP_ALTERNATE_SCRAMBLER_RESET_ENABLE;
+
+ dev_dbg(tc->dev, "DPCD rev: %d.%d, rate: %s, lanes: %d, framing: %s\n",
+ tc->link.rev >> 4,
+ tc->link.rev & 0x0f,
+ (tc->link.rate == 0x06) ? "1.62Gbps" : "2.7Gbps",
+ tc->link.lanes,
+ tc->link.enhanced ? "enhanced" : "non-enhanced");
+ dev_dbg(tc->dev, "ANSI 8B/10B: %d\n", tc->link.coding8b10b);
+ dev_dbg(tc->dev, "Display ASSR: %d, TC358767 ASSR: %d\n",
+ tc->link.assr, tc->assr);
+
+ return 0;
+
+err_dpcd_read:
+ dev_err(tc->dev, "failed to read DPCD: %d\n", ret);
+ return ret;
+err_dpcd_inval:
+ dev_err(tc->dev, "invalid DPCD\n");
+ return -EINVAL;
+}
+
+static int tc_set_video_mode(struct tc_data *tc, struct fb_videomode *mode)
+{
+ int ret;
+ int htotal;
+ int vtotal;
+ int vid_sync_dly;
+ int max_tu_symbol;
+
+ htotal = mode->hsync_len + mode->left_margin + mode->xres +
+ mode->right_margin;
+ vtotal = mode->vsync_len + mode->upper_margin + mode->yres +
+ mode->lower_margin;
+
+ dev_dbg(tc->dev, "set mode %dx%d\n", mode->xres, mode->yres);
+ dev_dbg(tc->dev, "H margin %d,%d sync %d\n",
+ mode->left_margin, mode->right_margin, mode->hsync_len);
+ dev_dbg(tc->dev, "V margin %d,%d sync %d\n",
+ mode->upper_margin, mode->lower_margin, mode->vsync_len);
+ dev_dbg(tc->dev, "total: %dx%d\n", htotal, vtotal);
+
+
+ /* LCD Ctl Frame Size */
+ tc_write(VPCTRL0, (0x40 << 20) /* VSDELAY */ |
+ OPXLFMT_RGB888 | FRMSYNC_DISABLED | MSF_DISABLED);
+ tc_write(HTIM01, (mode->left_margin << 16) | /* H back porch */
+ (mode->hsync_len << 0)); /* Hsync */
+ tc_write(HTIM02, (mode->right_margin << 16) | /* H front porch */
+ (mode->xres << 0)); /* width */
+ tc_write(VTIM01, (mode->upper_margin << 16) | /* V back porch */
+ (mode->vsync_len << 0)); /* Vsync */
+ tc_write(VTIM02, (mode->lower_margin << 16) | /* V front porch */
+ (mode->yres << 0)); /* height */
+ tc_write(VFUEN0, VFUEN); /* update settings */
+
+ /* Test pattern settings */
+ tc_write(TSTCTL,
+ (120 << 24) | /* Red Color component value */
+ (20 << 16) | /* Green Color component value */
+ (99 << 8) | /* Blue Color component value */
+ (1 << 4) | /* Enable I2C Filter */
+ (2 << 0) | /* Color bar Mode */
+ 0);
+
+ /* DP Main Stream Attributes */
+ vid_sync_dly = mode->hsync_len + mode->left_margin + mode->xres;
+ tc_write(DP0_VIDSYNCDELAY,
+ (0x003e << 16) | /* thresh_dly */
+ (vid_sync_dly << 0));
+
+ tc_write(DP0_TOTALVAL, (vtotal << 16) | (htotal));
+
+ tc_write(DP0_STARTVAL,
+ ((mode->upper_margin + mode->vsync_len) << 16) |
+ ((mode->left_margin + mode->hsync_len) << 0));
+
+ tc_write(DP0_ACTIVEVAL, (mode->yres << 16) | (mode->xres));
+
+ tc_write(DP0_SYNCVAL, (mode->vsync_len << 16) | (mode->hsync_len << 0));
+
+ tc_write(DPIPXLFMT, VS_POL_ACTIVE_LOW | HS_POL_ACTIVE_LOW |
+ DE_POL_ACTIVE_HIGH | SUB_CFG_TYPE_CONFIG1 | DPI_BPP_RGB888);
+
+ /*
+ * Recommended maximum number of symbols transferred in a transfer unit:
+ * DIV_ROUND_UP((input active video bandwidth in bytes) * tu_size,
+ * (output active video bandwidth in bytes))
+ * Must be less than tu_size.
+ */
+ max_tu_symbol = TU_SIZE_RECOMMENDED - 1;
+ tc_write(DP0_MISC, (max_tu_symbol << 23) | TU_SIZE_RECOMMENDED | BPC_8);
+
+ return 0;
+err:
+ return ret;
+}
+
+static int tc_link_training(struct tc_data *tc, int pattern)
+{
+ const char * const *errors;
+ u32 srcctrl = tc_srcctrl(tc) | DP0_SRCCTRL_SCRMBLDIS |
+ DP0_SRCCTRL_AUTOCORRECT;
+ int timeout;
+ int retry;
+ u32 value;
+ int ret;
+
+ if (pattern == DP_TRAINING_PATTERN_1) {
+ srcctrl |= DP0_SRCCTRL_TP1;
+ errors = training_pattern1_errors;
+ } else {
+ srcctrl |= DP0_SRCCTRL_TP2;
+ errors = training_pattern2_errors;
+ }
+
+ /* Set DPCD 0x102 for Training Part 1 or 2 */
+ tc_write(DP0_SNKLTCTRL, DP_LINK_SCRAMBLING_DISABLE | pattern);
+
+ tc_write(DP0_LTLOOPCTRL,
+ (0x0f << 28) | /* Defer Iteration Count */
+ (0x0f << 24) | /* Loop Iteration Count */
+ (0x0d << 0)); /* Loop Timer Delay */
+
+ retry = 5;
+ do {
+ /* Set DP0 Training Pattern */
+ tc_write(DP0_SRCCTRL, srcctrl);
+
+ /* Enable DP0 to start Link Training */
+ tc_write(DP0CTL, DP_EN);
+
+ /* wait */
+ timeout = 1000;
+ do {
+ tc_read(DP0_LTSTAT, &value);
+ udelay(1);
+ } while ((!(value & LT_LOOPDONE)) && (--timeout));
+ if (timeout == 0) {
+ dev_err(tc->dev, "Link training timeout!\n");
+ } else {
+ int pattern = (value >> 11) & 0x3;
+ int error = (value >> 8) & 0x7;
+
+ dev_dbg(tc->dev,
+ "Link training phase %d done after %d uS: %s\n",
+ pattern, 1000 - timeout, errors[error]);
+ if (pattern == DP_TRAINING_PATTERN_1 && error == 0)
+ break;
+ if (pattern == DP_TRAINING_PATTERN_2) {
+ value &= LT_CHANNEL1_EQ_BITS |
+ LT_INTERLANE_ALIGN_DONE |
+ LT_CHANNEL0_EQ_BITS;
+ /* in case of two lanes */
+ if ((tc->link.lanes == 2) &&
+ (value == (LT_CHANNEL1_EQ_BITS |
+ LT_INTERLANE_ALIGN_DONE |
+ LT_CHANNEL0_EQ_BITS)))
+ break;
+ /* in case of one line */
+ if ((tc->link.lanes == 1) &&
+ (value == (LT_INTERLANE_ALIGN_DONE |
+ LT_CHANNEL0_EQ_BITS)))
+ break;
+ }
+ }
+ /* restart */
+ tc_write(DP0CTL, 0);
+ udelay(10);
+ } while (--retry);
+ if (retry == 0) {
+ dev_err(tc->dev, "Failed to finish training phase %d\n",
+ pattern);
+ }
+
+ return 0;
+err:
+ return ret;
+}
+
+static int tc_main_link_setup(struct tc_data *tc)
+{
+ struct device_d *dev = tc->dev;
+ unsigned int rate;
+ u32 dp_phy_ctrl;
+ int timeout;
+ bool aligned;
+ bool ready;
+ u32 value;
+ int ret;
+ u8 tmp[8];
+
+ /* display mode should be set at this point */
+ if (!tc->mode)
+ return -EINVAL;
+
+ /* from excel file - DP0_SrcCtrl */
+ tc_write(DP0_SRCCTRL, DP0_SRCCTRL_SCRMBLDIS | DP0_SRCCTRL_EN810B |
+ DP0_SRCCTRL_LANESKEW | DP0_SRCCTRL_LANES_2 |
+ DP0_SRCCTRL_BW27 | DP0_SRCCTRL_AUTOCORRECT);
+ /* from excel file - DP1_SrcCtrl */
+ tc_write(0x07a0, 0x00003083);
+
+ rate = clk_get_rate(tc->refclk);
+ switch (rate) {
+ case 38400000:
+ value = REF_FREQ_38M4;
+ break;
+ case 26000000:
+ value = REF_FREQ_26M;
+ break;
+ case 19200000:
+ value = REF_FREQ_19M2;
+ break;
+ case 13000000:
+ value = REF_FREQ_13M;
+ break;
+ default:
+ return -EINVAL;
+ }
+ value |= SYSCLK_SEL_LSCLK | LSCLK_DIV_2;
+ tc_write(SYS_PLLPARAM, value);
+ /* Setup Main Link */
+ dp_phy_ctrl = BGREN | PWR_SW_EN | BIT(2) | PHY_A0_EN | PHY_M0_EN;
+ tc_write(DP_PHY_CTRL, dp_phy_ctrl);
+ mdelay(100);
+
+ /* PLL setup */
+ tc_write(DP0_PLLCTRL, PLLUPDATE | PLLEN);
+ tc_wait_pll_lock(tc);
+
+ tc_write(DP1_PLLCTRL, PLLUPDATE | PLLEN);
+ tc_wait_pll_lock(tc);
+
+ /* Reset/Enable Main Links */
+ dp_phy_ctrl |= DP_PHY_RST | PHY_M1_RST | PHY_M0_RST;
+ tc_write(DP_PHY_CTRL, dp_phy_ctrl);
+ udelay(100);
+ dp_phy_ctrl &= ~(DP_PHY_RST | PHY_M1_RST | PHY_M0_RST);
+ tc_write(DP_PHY_CTRL, dp_phy_ctrl);
+
+ timeout = 1000;
+ do {
+ tc_read(DP_PHY_CTRL, &value);
+ udelay(1);
+ } while ((!(value & PHY_RDY)) && (--timeout));
+
+ if (timeout == 0) {
+ dev_err(dev, "timeout waiting for phy become ready");
+ return -ETIMEDOUT;
+ }
+
+ /* Set misc: 8 bits per color */
+ tc_read(DP0_MISC, &value);
+ value |= BPC_8;
+ tc_write(DP0_MISC, value);
+
+ /*
+ * ASSR mode
+ * on TC358767 side ASSR configured through strap pin
+ * seems there is no way to change this setting from SW
+ *
+ * check is tc configured for same mode
+ */
+ if (tc->assr != tc->link.assr) {
+ dev_dbg(dev, "Trying to set display to ASSR: %d\n",
+ tc->assr);
+ /* try to set ASSR on display side */
+ tmp[0] = tc->assr;
+ ret = tc_aux_write(tc, DP_EDP_CONFIGURATION_SET, tmp, 1);
+ if (ret)
+ goto err_dpcd_read;
+ /* read back */
+ ret = tc_aux_read(tc, DP_EDP_CONFIGURATION_SET, tmp, 1);
+ if (ret)
+ goto err_dpcd_read;
+
+ if (tmp[0] != tc->assr) {
+ dev_warn(dev, "Failed to switch display ASSR to %d, falling back to unscrambled mode\n",
+ tc->assr);
+ /* trying with disabled scrambler */
+ tc->link.scrambler_dis = 1;
+ }
+ }
+
+ /* Setup Link & DPRx Config for Training */
+ /* LINK_BW_SET */
+ tmp[0] = tc->link.rate;
+ /* LANE_COUNT_SET */
+ tmp[1] = tc->link.lanes;
+ if (tc->link.enhanced)
+ tmp[1] |= (1 << 7);
+ ret = tc_aux_write(tc, DP_LINK_BW_SET, tmp, 2);
+ if (ret)
+ goto err_dpcd_write;
+
+ /* DOWNSPREAD_CTRL */
+ tmp[0] = tc->link.spread ? DP_SPREAD_AMP_0_5 : 0x00;
+ /* MAIN_LINK_CHANNEL_CODING_SET */
+ tmp[1] = tc->link.coding8b10b ? DP_SET_ANSI_8B10B : 0x00;
+ ret = tc_aux_write(tc, DP_DOWNSPREAD_CTRL, tmp, 2);
+ if (ret)
+ goto err_dpcd_write;
+
+ ret = tc_link_training(tc, DP_TRAINING_PATTERN_1);
+ if (ret)
+ goto err;
+
+ ret = tc_link_training(tc, DP_TRAINING_PATTERN_2);
+ if (ret)
+ goto err;
+
+ /* Clear DPCD 0x102 */
+ /* Note: Can Not use DP0_SNKLTCTRL (0x06E4) short cut */
+ tmp[0] = tc->link.scrambler_dis ? DP_LINK_SCRAMBLING_DISABLE : 0x00;
+ ret = tc_aux_write(tc, DP_TRAINING_PATTERN_SET, tmp, 1);
+ if (ret)
+ goto err_dpcd_write;
+
+ /* Clear Training Pattern, set AutoCorrect Mode = 1 */
+ tc_write(DP0_SRCCTRL, tc_srcctrl(tc) | DP0_SRCCTRL_AUTOCORRECT);
+
+ /* Wait */
+ timeout = 100;
+ do {
+ udelay(1);
+ /* Read DPCD 0x200-0x206 */
+ ret = tc_aux_read(tc, 0x200, tmp, 7);
+ if (ret)
+ goto err_dpcd_read;
+ ready = (tmp[2] == ((DP_CHANNEL_EQ_BITS << 4) | /* Lane1 */
+ DP_CHANNEL_EQ_BITS)); /* Lane0 */
+ aligned = tmp[4] & DP_INTERLANE_ALIGN_DONE;
+ } while ((--timeout) && !(ready && aligned));
+
+ if (timeout == 0) {
+ dev_info(dev, "0x0200 SINK_COUNT: 0x%02x\n", tmp[0]);
+ dev_info(dev, "0x0201 DEVICE_SERVICE_IRQ_VECTOR: 0x%02x\n",
+ tmp[1]);
+ dev_info(dev, "0x0202 LANE0_1_STATUS: 0x%02x\n", tmp[2]);
+ dev_info(dev, "0x0204 LANE_ALIGN_STATUS_UPDATED: 0x%02x\n",
+ tmp[4]);
+ dev_info(dev, "0x0205 SINK_STATUS: 0x%02x\n", tmp[5]);
+ dev_info(dev, "0x0206 ADJUST_REQUEST_LANE0_1: 0x%02x\n",
+ tmp[6]);
+
+ if (!ready)
+ dev_err(dev, "Lane0/1 not ready\n");
+ if (!aligned)
+ dev_err(dev, "Lane0/1 not aligned\n");
+ return -EAGAIN;
+ }
+
+ ret = tc_set_video_mode(tc, tc->mode);
+ if (ret)
+ goto err;
+
+ /* Set M/N */
+ ret = tc_stream_clock_calc(tc);
+ if (ret)
+ goto err;
+
+ return 0;
+err_dpcd_read:
+ dev_err(tc->dev, "Failed to read DPCD: %d\n", ret);
+ return ret;
+err_dpcd_write:
+ dev_err(tc->dev, "Failed to write DPCD: %d\n", ret);
+err:
+ return ret;
+}
+
+static int tc_main_link_stream(struct tc_data *tc, int state)
+{
+ int ret;
+ u32 value;
+
+ dev_dbg(tc->dev, "stream: %d\n", state);
+
+ if (state) {
+ value = VID_MN_GEN | DP_EN;
+ if (tc->link.enhanced)
+ value |= EF_EN;
+ tc_write(DP0CTL, value);
+ /*
+ * VID_EN assertion should be delayed by at least N * LSCLK
+ * cycles from the time VID_MN_GEN is enabled in order to
+ * generate stable values for VID_M. LSCLK is 270 MHz or
+ * 162 MHz, VID_N is set to 32768 in tc_stream_clock_calc(),
+ * so a delay of at least 203 us should suffice.
+ */
+ mdelay(1);
+ value |= VID_EN;
+ tc_write(DP0CTL, value);
+ /* Set input interface, currently DPI only */
+ value = DP0_AUDSRC_NO_INPUT | DP0_VIDSRC_DPI_RX;
+ tc_write(SYSCTRL, value);
+ } else {
+ tc_write(DP0CTL, 0);
+ }
+
+ return 0;
+err:
+ return ret;
+}
+
+#define DDC_BLOCK_READ 5
+#define DDC_SEGMENT_ADDR 0x30
+#define DDC_ADDR 0x50
+#define EDID_LENGTH 0x80
+
+static int tc_read_edid(struct tc_data *tc)
+{
+ int i = 0;
+ int ret;
+ int block;
+ unsigned char start = 0;
+ unsigned char segment = 0;
+
+ struct i2c_msg msgs[] = {
+ {
+ .addr = DDC_SEGMENT_ADDR,
+ .flags = 0,
+ .len = 1,
+ .buf = &segment,
+ }, {
+ .addr = DDC_ADDR,
+ .flags = 0,
+ .len = 1,
+ .buf = &start,
+ }, {
+ .addr = DDC_ADDR,
+ .flags = I2C_M_RD,
+ }
+ };
+ tc->edid = xmalloc(EDID_LENGTH);
+
+ do {
+ block = min(DDC_BLOCK_READ, EDID_LENGTH - i);
+
+ msgs[2].buf = tc->edid + i;
+ msgs[2].len = block;
+
+ ret = i2c_transfer(&tc->adapter, msgs, 3);
+ if (ret < 0)
+ goto err;
+
+ i += DDC_BLOCK_READ;
+ start = i;
+ } while (i < EDID_LENGTH);
+
+#ifdef DEBUG
+ printk(KERN_DEBUG "eDP display EDID:\n");
+ print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, tc->edid,
+ EDID_LENGTH, true);
+#endif
+
+ return 0;
+err:
+ free(tc->edid);
+ tc->edid = NULL;
+ dev_err(tc->dev, "tc_read_edid failed: %d\n", ret);
+ return ret;
+}
+
+static int tc_get_videomodes(struct tc_data *tc, struct display_timings *timings)
+{
+ int ret;
+
+ /* edid_read_i2c does not work due to limitation of eDP i2c */
+ if (!tc->edid) {
+ ret = tc_read_edid(tc);
+ if (ret) {
+ dev_err(tc->dev, "EDID read error: %d\n", ret);
+ return ret;
+ }
+ }
+
+ ret = edid_to_display_timings(timings, tc->edid);
+ if (ret < 0) {
+ dev_err(tc->dev, "Failed to parse EDID: %d\n", ret);
+ return ret;
+ }
+
+ /* hsync, vsync active low */
+ timings->modes->sync &= ~(FB_SYNC_HOR_HIGH_ACT |
+ FB_SYNC_VERT_HIGH_ACT);
+
+ return ret;
+}
+
+static int tc_ioctl(struct vpl *vpl, unsigned int port,
+ unsigned int cmd, void *ptr)
+{
+ struct tc_data *tc = container_of(vpl, struct tc_data, vpl);
+ u32 *bus_format;
+ int ret = 0;
+
+ switch (cmd) {
+ case VPL_PREPARE:
+ tc->mode = ptr;
+ break;
+ case VPL_ENABLE:
+ ret = tc_main_link_setup(tc);
+ if (ret < 0)
+ break;
+
+ ret = tc_main_link_stream(tc, 1);
+ break;
+ case VPL_DISABLE:
+ ret = tc_main_link_stream(tc, 0);
+ break;
+ case VPL_GET_VIDEOMODES:
+ ret = tc_get_videomodes(tc, ptr);
+ break;
+ case VPL_GET_BUS_FORMAT:
+ bus_format = ptr;
+ *bus_format = MEDIA_BUS_FMT_RGB888_1X24;
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+static int tc_probe(struct device_d *dev)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct tc_data *tc;
+ enum of_gpio_flags flags;
+ int ret;
+
+ tc = xzalloc(sizeof(struct tc_data));
+ if (!tc)
+ return -ENOMEM;
+
+ tc->client = client;
+ tc->dev = dev;
+
+ /* Shut down GPIO is optional */
+ tc->sd_gpio = of_get_named_gpio_flags(dev->device_node,
+ "shutdown-gpios", 0, &flags);
+ if (gpio_is_valid(tc->sd_gpio)) {
+ if (!(flags & OF_GPIO_ACTIVE_LOW))
+ tc->sd_active_high = 1;
+ }
+
+ /* Reset GPIO is optional */
+ tc->reset_gpio = of_get_named_gpio_flags(dev->device_node,
+ "reset-gpios", 0, &flags);
+ if (gpio_is_valid(tc->reset_gpio)) {
+ if (!(flags & OF_GPIO_ACTIVE_LOW))
+ tc->reset_active_high = 1;
+ }
+
+ if (gpio_is_valid(tc->sd_gpio)) {
+ ret = gpio_request(tc->sd_gpio, "tc358767");
+ if (ret) {
+ dev_err(tc->dev, "SD (%d) can not be requested\n", tc->sd_gpio);
+ return ret;
+ }
+ gpio_direction_output(tc->sd_gpio, 0);
+ }
+
+ tc->refclk = of_clk_get_by_name(dev->device_node, "ref");
+ if (IS_ERR(tc->refclk)) {
+ ret = PTR_ERR(tc->refclk);
+ dev_err(dev, "Failed to get refclk: %d\n", ret);
+ goto err;
+ }
+
+ ret = tc_read_reg(tc, TC_IDREG, &tc->rev);
+ if (ret) {
+ dev_err(tc->dev, "can not read device ID\n");
+ goto err;
+ }
+
+ if ((tc->rev != 0x6601) && (tc->rev != 0x6603)) {
+ dev_err(tc->dev, "invalid device ID: 0x%08x\n", tc->rev);
+ ret = -EINVAL;
+ goto err;
+ }
+
+ ret = tc_aux_link_setup(tc);
+ if (ret)
+ goto err;
+
+ /* Register DP AUX channel */
+ 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(&tc->adapter);
+ if (ret < 0) {
+ dev_err(tc->dev, "registration failed\n");
+ goto err;
+ }
+
+ ret = tc_get_display_props(tc);
+ if (ret)
+ goto err;
+
+ /* add vlp */
+ tc->vpl.node = dev->device_node;
+ tc->vpl.ioctl = tc_ioctl;
+ return vpl_register(&tc->vpl);
+
+err:
+ free(tc);
+ return ret;
+}
+
+static struct driver_d tc_driver = {
+ .name = "tc358767",
+ .probe = tc_probe,
+};
+
+static int tc_init(void)
+{
+ return i2c_driver_register(&tc_driver);
+}
+device_initcall(tc_init);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* [PATCH 1/3] video: switch to media bus formats
From: Philipp Zabel @ 2016-08-24 10:40 UTC (permalink / raw)
To: barebox
V4L2 pixel formats are supposed to describe video frames in memory. To
describe the pixel format on the hardware bus between display interface
and encoders, use media bus formats, which are more expressive.
This allows to get rid of the custom GBR24 and LVDS666 fourccs.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/video/imx-ipu-v3/imx-hdmi.c | 3 +-
drivers/video/imx-ipu-v3/imx-ipu-v3.h | 4 +-
drivers/video/imx-ipu-v3/imx-ldb.c | 7 +-
drivers/video/imx-ipu-v3/ipu-dc.c | 19 +++--
drivers/video/imx-ipu-v3/ipu-prv.h | 2 -
drivers/video/imx-ipu-v3/ipufb.c | 21 +++--
include/video/fourcc.h | 151 ----------------------------------
include/video/media-bus-format.h | 137 ++++++++++++++++++++++++++++++
8 files changed, 165 insertions(+), 179 deletions(-)
create mode 100644 include/video/media-bus-format.h
diff --git a/drivers/video/imx-ipu-v3/imx-hdmi.c b/drivers/video/imx-ipu-v3/imx-hdmi.c
index 8b251a5..17b6e4c 100644
--- a/drivers/video/imx-ipu-v3/imx-hdmi.c
+++ b/drivers/video/imx-ipu-v3/imx-hdmi.c
@@ -22,6 +22,7 @@
#include <asm-generic/div64.h>
#include <linux/clk.h>
#include <i2c/i2c.h>
+#include <video/media-bus-format.h>
#include <video/vpl.h>
#include <mach/imx6-regs.h>
#include <mach/imx53-regs.h>
@@ -1261,7 +1262,7 @@ static int dw_hdmi_ioctl(struct vpl *vpl, unsigned int port,
mode = data;
mode->di_clkflags = IPU_DI_CLKMODE_EXT | IPU_DI_CLKMODE_SYNC;
- mode->interface_pix_fmt = V4L2_PIX_FMT_RGB24;
+ mode->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
return 0;
}
diff --git a/drivers/video/imx-ipu-v3/imx-ipu-v3.h b/drivers/video/imx-ipu-v3/imx-ipu-v3.h
index fbfec22..cdfff69 100644
--- a/drivers/video/imx-ipu-v3/imx-ipu-v3.h
+++ b/drivers/video/imx-ipu-v3/imx-ipu-v3.h
@@ -116,7 +116,7 @@ struct ipu_di;
struct ipu_dc *ipu_dc_get(struct ipu_soc *ipu, int channel);
void ipu_dc_put(struct ipu_dc *dc);
int ipu_dc_init_sync(struct ipu_dc *dc, struct ipu_di *di, bool interlaced,
- u32 pixel_fmt, u32 width);
+ u32 bus_format, u32 width);
void ipu_dc_enable_channel(struct ipu_dc *dc);
void ipu_dc_disable_channel(struct ipu_dc *dc);
@@ -323,7 +323,7 @@ struct ipu_client_platformdata {
struct ipu_di_mode {
u32 di_clkflags;
- u32 interface_pix_fmt;
+ u32 bus_format;
};
#define IMX_IPU_VPL_DI_MODE 0x12660001
diff --git a/drivers/video/imx-ipu-v3/imx-ldb.c b/drivers/video/imx-ipu-v3/imx-ldb.c
index 17ae894..14a86a4 100644
--- a/drivers/video/imx-ipu-v3/imx-ldb.c
+++ b/drivers/video/imx-ipu-v3/imx-ldb.c
@@ -26,6 +26,7 @@
#include <malloc.h>
#include <errno.h>
#include <init.h>
+#include <video/media-bus-format.h>
#include <video/vpl.h>
#include <mfd/imx6q-iomuxc-gpr.h>
#include <linux/clk.h>
@@ -75,7 +76,7 @@ struct imx_ldb_data {
struct imx_ldb {
struct device_d *dev;
- u32 interface_pix_fmt;
+ u32 bus_format;
int mode_valid;
struct imx_ldb_channel channel[2];
u32 ldb_ctrl;
@@ -273,8 +274,8 @@ static int imx_ldb_ioctl(struct vpl *vpl, unsigned int port,
mode = data;
mode->di_clkflags = IPU_DI_CLKMODE_EXT | IPU_DI_CLKMODE_SYNC;
- mode->interface_pix_fmt = (imx_ldb_ch->datawidth == 24) ?
- V4L2_PIX_FMT_RGB24 : V4L2_PIX_FMT_BGR666;
+ mode->bus_format = (imx_ldb_ch->datawidth == 24) ?
+ MEDIA_BUS_FMT_RGB888_1X24 : MEDIA_BUS_FMT_RGB666_1X18;
return 0;
case VPL_GET_VIDEOMODES:
diff --git a/drivers/video/imx-ipu-v3/ipu-dc.c b/drivers/video/imx-ipu-v3/ipu-dc.c
index 2deb2ae..7b343e8 100644
--- a/drivers/video/imx-ipu-v3/ipu-dc.c
+++ b/drivers/video/imx-ipu-v3/ipu-dc.c
@@ -17,6 +17,7 @@
#include <linux/err.h>
#include <linux/clk.h>
#include <malloc.h>
+#include <video/media-bus-format.h>
#include "imx-ipu-v3.h"
#include "ipu-prv.h"
@@ -138,18 +139,18 @@ static void dc_write_tmpl(struct ipu_dc *dc, int word, u32 opcode, u32 operand,
ipuwritel("dc", reg2, priv->dc_tmpl_reg + word * 8 + 4);
}
-static int ipu_pixfmt_to_map(u32 fmt)
+static int ipu_bus_format_to_map(u32 bus_format)
{
- switch (fmt) {
- case V4L2_PIX_FMT_RGB24:
+ switch (bus_format) {
+ case MEDIA_BUS_FMT_RGB888_1X24:
return IPU_DC_MAP_RGB24;
- case V4L2_PIX_FMT_RGB565:
+ case MEDIA_BUS_FMT_RGB565_1X16:
return IPU_DC_MAP_RGB565;
- case IPU_PIX_FMT_GBR24:
+ case MEDIA_BUS_FMT_GBR888_1X24:
return IPU_DC_MAP_GBR24;
- case V4L2_PIX_FMT_BGR666:
+ case MEDIA_BUS_FMT_RGB666_1X18:
return IPU_DC_MAP_BGR666;
- case V4L2_PIX_FMT_BGR24:
+ case MEDIA_BUS_FMT_BGR888_1X24:
return IPU_DC_MAP_BGR24;
default:
return -EINVAL;
@@ -157,7 +158,7 @@ static int ipu_pixfmt_to_map(u32 fmt)
}
int ipu_dc_init_sync(struct ipu_dc *dc, struct ipu_di *di, bool interlaced,
- u32 pixel_fmt, u32 width)
+ u32 bus_format, u32 width)
{
struct ipu_dc_priv *priv = dc->priv;
u32 reg = 0;
@@ -165,7 +166,7 @@ int ipu_dc_init_sync(struct ipu_dc *dc, struct ipu_di *di, bool interlaced,
dc->di = ipu_di_get_num(di);
- map = ipu_pixfmt_to_map(pixel_fmt);
+ map = ipu_bus_format_to_map(bus_format);
if (map < 0) {
dev_dbg(priv->dev, "IPU_DISP: No MAP\n");
return map;
diff --git a/drivers/video/imx-ipu-v3/ipu-prv.h b/drivers/video/imx-ipu-v3/ipu-prv.h
index 44d7802..4d1c069 100644
--- a/drivers/video/imx-ipu-v3/ipu-prv.h
+++ b/drivers/video/imx-ipu-v3/ipu-prv.h
@@ -19,8 +19,6 @@ struct ipu_soc;
#include "imx-ipu-v3.h"
-#define IPU_PIX_FMT_GBR24 v4l2_fourcc('G', 'B', 'R', '3')
-
#define IPUV3_CHANNEL_CSI0 0
#define IPUV3_CHANNEL_CSI1 1
#define IPUV3_CHANNEL_CSI2 2
diff --git a/drivers/video/imx-ipu-v3/ipufb.c b/drivers/video/imx-ipu-v3/ipufb.c
index 67fec11..cfafa22 100644
--- a/drivers/video/imx-ipu-v3/ipufb.c
+++ b/drivers/video/imx-ipu-v3/ipufb.c
@@ -23,6 +23,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <asm-generic/div64.h>
+#include <video/media-bus-format.h>
#include "imx-ipu-v3.h"
#include "ipuv3-plane.h"
@@ -56,7 +57,7 @@ struct ipufb_info {
void (*enable)(int enable);
unsigned int di_clkflags;
- u32 interface_pix_fmt;
+ u32 bus_format;
struct ipu_dc *dc;
struct ipu_di *di;
@@ -108,7 +109,7 @@ int ipu_crtc_mode_set(struct ipufb_info *fbi,
int ret;
struct ipu_di_signal_cfg sig_cfg = {};
struct ipu_di_mode di_mode = {};
- u32 interface_pix_fmt;
+ u32 bus_format;
dev_info(fbi->dev, "%s: mode->xres: %d\n", __func__,
mode->xres);
@@ -116,8 +117,7 @@ int ipu_crtc_mode_set(struct ipufb_info *fbi,
mode->yres);
vpl_ioctl(&fbi->vpl, 2 + fbi->dino, IMX_IPU_VPL_DI_MODE, &di_mode);
- interface_pix_fmt = di_mode.interface_pix_fmt ?
- di_mode.interface_pix_fmt : fbi->interface_pix_fmt;
+ bus_format = di_mode.bus_format ?: fbi->bus_format;
if (mode->sync & FB_SYNC_HOR_HIGH_ACT)
sig_cfg.Hsync_pol = 1;
@@ -148,8 +148,8 @@ int ipu_crtc_mode_set(struct ipufb_info *fbi,
sig_cfg.hsync_pin = 2;
sig_cfg.vsync_pin = 3;
- ret = ipu_dc_init_sync(fbi->dc, fbi->di, sig_cfg.interlaced,
- interface_pix_fmt, mode->xres);
+ ret = ipu_dc_init_sync(fbi->dc, fbi->di, sig_cfg.interlaced, bus_format,
+ mode->xres);
if (ret) {
dev_err(fbi->dev,
"initializing display controller failed with %d\n",
@@ -318,14 +318,13 @@ static int ipufb_probe(struct device_d *dev)
ret = of_property_read_string(node, "interface-pix-fmt", &fmt);
if (!ret) {
if (!strcmp(fmt, "rgb24"))
- fbi->interface_pix_fmt = V4L2_PIX_FMT_RGB24;
+ fbi->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
else if (!strcmp(fmt, "rgb565"))
- fbi->interface_pix_fmt = V4L2_PIX_FMT_RGB565;
+ fbi->bus_format = MEDIA_BUS_FMT_RGB565_1X16;
else if (!strcmp(fmt, "bgr666"))
- fbi->interface_pix_fmt = V4L2_PIX_FMT_BGR666;
+ fbi->bus_format = MEDIA_BUS_FMT_RGB666_1X18;
else if (!strcmp(fmt, "lvds666"))
- fbi->interface_pix_fmt =
- v4l2_fourcc('L', 'V', 'D', '6');
+ fbi->bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
}
ret = vpl_ioctl(&fbi->vpl, 2 + fbi->dino, VPL_GET_VIDEOMODES, &info->modes);
diff --git a/include/video/fourcc.h b/include/video/fourcc.h
index 322142c..211aabb 100644
--- a/include/video/fourcc.h
+++ b/include/video/fourcc.h
@@ -1,157 +1,6 @@
#ifndef __VIDEO_FOURCC_H
#define __VIDEO_FOURCC_H
-/* Four-character-code (FOURCC) */
-#define v4l2_fourcc(a, b, c, d)\
- ((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
-
-/* Pixel format FOURCC depth Description */
-
-/* RGB formats */
-#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */
-#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */
-#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */
-#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
-#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */
-#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */
-#define V4L2_PIX_FMT_BGR666 v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */
-#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */
-#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */
-#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */
-#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */
-
-/* Grey formats */
-#define V4L2_PIX_FMT_GREY v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */
-#define V4L2_PIX_FMT_Y4 v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */
-#define V4L2_PIX_FMT_Y6 v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */
-#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */
-#define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */
-#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */
-
-/* Grey bit-packed formats */
-#define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */
-
-/* Palette formats */
-#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */
-
-/* Chrominance formats */
-#define V4L2_PIX_FMT_UV8 v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */
-
-/* Luminance+Chrominance formats */
-#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */
-#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */
-#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
-#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */
-#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
-#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */
-#define V4L2_PIX_FMT_VYUY v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */
-#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */
-#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4', '1', '1', 'P') /* 16 YVU411 planar */
-#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */
-#define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */
-#define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */
-#define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */
-#define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */
-#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */
-#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */
-#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* 8 8-bit color */
-#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H', 'M', '1', '2') /* 8 YUV 4:2:0 16x16 macroblocks */
-#define V4L2_PIX_FMT_M420 v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */
-
-/* two planes -- one Y, one Cr + Cb interleaved */
-#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */
-#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */
-#define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */
-#define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */
-#define V4L2_PIX_FMT_NV24 v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */
-#define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */
-
-/* two non contiguous planes - one Y, one Cr + Cb interleaved */
-#define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */
-#define V4L2_PIX_FMT_NV21M v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */
-#define V4L2_PIX_FMT_NV16M v4l2_fourcc('N', 'M', '1', '6') /* 16 Y/CbCr 4:2:2 */
-#define V4L2_PIX_FMT_NV61M v4l2_fourcc('N', 'M', '6', '1') /* 16 Y/CrCb 4:2:2 */
-#define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 macroblocks */
-#define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 macroblocks */
-
-/* three non contiguous planes - Y, Cb, Cr */
-#define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */
-#define V4L2_PIX_FMT_YVU420M v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */
-
-/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
-#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */
-#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
-#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
-#define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
-#define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */
-#define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */
-#define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */
-#define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */
-#define V4L2_PIX_FMT_SBGGR12 v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */
-#define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */
-#define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */
-#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */
- /* 10bit raw bayer a-law compressed to 8 bits */
-#define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8')
-#define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8')
-#define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8')
-#define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8')
- /* 10bit raw bayer DPCM compressed to 8 bits */
-#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8')
-#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8')
-#define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0')
-#define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8')
- /*
- * 10bit raw bayer, expanded to 16 bits
- * xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
- */
-#define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */
-
-/* compressed formats */
-#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
-#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */
-#define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */
-#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */
-#define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
-#define V4L2_PIX_FMT_H264_NO_SC v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */
-#define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */
-#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */
-#define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */
-#define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */
-#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */
-#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */
-#define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
-#define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
-#define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
-
-/* Vendor-specific formats */
-#define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
-#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
-#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */
-#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */
-#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */
-#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */
-#define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */
-#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */
-#define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */
-#define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */
-#define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */
-#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */
-#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */
-#define V4L2_PIX_FMT_JL2005BCD v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */
-#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */
-#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */
-#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */
-#define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
-#define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
-#define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
-#define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
-#define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */
-#define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */
-#define V4L2_PIX_FMT_JPGL v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */
-#define V4L2_PIX_FMT_SE401 v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */
-#define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */
-
#define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
((__u32)(c) << 16) | ((__u32)(d) << 24))
diff --git a/include/video/media-bus-format.h b/include/video/media-bus-format.h
new file mode 100644
index 0000000..190d491
--- /dev/null
+++ b/include/video/media-bus-format.h
@@ -0,0 +1,137 @@
+/*
+ * Media Bus API header
+ *
+ * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_MEDIA_BUS_FORMAT_H
+#define __LINUX_MEDIA_BUS_FORMAT_H
+
+/*
+ * These bus formats uniquely identify data formats on the data bus. Format 0
+ * is reserved, MEDIA_BUS_FMT_FIXED shall be used by host-client pairs, where
+ * the data format is fixed. Additionally, "2X8" means that one pixel is
+ * transferred in two 8-bit samples, "BE" or "LE" specify in which order those
+ * samples are transferred over the bus: "LE" means that the least significant
+ * bits are transferred first, "BE" means that the most significant bits are
+ * transferred first, and "PADHI" and "PADLO" define which bits - low or high,
+ * in the incomplete high byte, are filled with padding bits.
+ *
+ * The bus formats are grouped by type, bus_width, bits per component, samples
+ * per pixel and order of subsamples. Numerical values are sorted using generic
+ * numerical sort order (8 thus comes before 10).
+ *
+ * As their value can't change when a new bus format is inserted in the
+ * enumeration, the bus formats are explicitly given a numerical value. The next
+ * free values for each category are listed below, update them when inserting
+ * new pixel codes.
+ */
+
+#define MEDIA_BUS_FMT_FIXED 0x0001
+
+/* RGB - next is 0x1018 */
+#define MEDIA_BUS_FMT_RGB444_1X12 0x1016
+#define MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE 0x1001
+#define MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE 0x1002
+#define MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE 0x1003
+#define MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE 0x1004
+#define MEDIA_BUS_FMT_RGB565_1X16 0x1017
+#define MEDIA_BUS_FMT_BGR565_2X8_BE 0x1005
+#define MEDIA_BUS_FMT_BGR565_2X8_LE 0x1006
+#define MEDIA_BUS_FMT_RGB565_2X8_BE 0x1007
+#define MEDIA_BUS_FMT_RGB565_2X8_LE 0x1008
+#define MEDIA_BUS_FMT_RGB666_1X18 0x1009
+#define MEDIA_BUS_FMT_RBG888_1X24 0x100e
+#define MEDIA_BUS_FMT_RGB666_1X24_CPADHI 0x1015
+#define MEDIA_BUS_FMT_RGB666_1X7X3_SPWG 0x1010
+#define MEDIA_BUS_FMT_BGR888_1X24 0x1013
+#define MEDIA_BUS_FMT_GBR888_1X24 0x1014
+#define MEDIA_BUS_FMT_RGB888_1X24 0x100a
+#define MEDIA_BUS_FMT_RGB888_2X12_BE 0x100b
+#define MEDIA_BUS_FMT_RGB888_2X12_LE 0x100c
+#define MEDIA_BUS_FMT_RGB888_1X7X4_SPWG 0x1011
+#define MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA 0x1012
+#define MEDIA_BUS_FMT_ARGB8888_1X32 0x100d
+#define MEDIA_BUS_FMT_RGB888_1X32_PADHI 0x100f
+
+/* YUV (including grey) - next is 0x2026 */
+#define MEDIA_BUS_FMT_Y8_1X8 0x2001
+#define MEDIA_BUS_FMT_UV8_1X8 0x2015
+#define MEDIA_BUS_FMT_UYVY8_1_5X8 0x2002
+#define MEDIA_BUS_FMT_VYUY8_1_5X8 0x2003
+#define MEDIA_BUS_FMT_YUYV8_1_5X8 0x2004
+#define MEDIA_BUS_FMT_YVYU8_1_5X8 0x2005
+#define MEDIA_BUS_FMT_UYVY8_2X8 0x2006
+#define MEDIA_BUS_FMT_VYUY8_2X8 0x2007
+#define MEDIA_BUS_FMT_YUYV8_2X8 0x2008
+#define MEDIA_BUS_FMT_YVYU8_2X8 0x2009
+#define MEDIA_BUS_FMT_Y10_1X10 0x200a
+#define MEDIA_BUS_FMT_UYVY10_2X10 0x2018
+#define MEDIA_BUS_FMT_VYUY10_2X10 0x2019
+#define MEDIA_BUS_FMT_YUYV10_2X10 0x200b
+#define MEDIA_BUS_FMT_YVYU10_2X10 0x200c
+#define MEDIA_BUS_FMT_Y12_1X12 0x2013
+#define MEDIA_BUS_FMT_UYVY12_2X12 0x201c
+#define MEDIA_BUS_FMT_VYUY12_2X12 0x201d
+#define MEDIA_BUS_FMT_YUYV12_2X12 0x201e
+#define MEDIA_BUS_FMT_YVYU12_2X12 0x201f
+#define MEDIA_BUS_FMT_UYVY8_1X16 0x200f
+#define MEDIA_BUS_FMT_VYUY8_1X16 0x2010
+#define MEDIA_BUS_FMT_YUYV8_1X16 0x2011
+#define MEDIA_BUS_FMT_YVYU8_1X16 0x2012
+#define MEDIA_BUS_FMT_YDYUYDYV8_1X16 0x2014
+#define MEDIA_BUS_FMT_UYVY10_1X20 0x201a
+#define MEDIA_BUS_FMT_VYUY10_1X20 0x201b
+#define MEDIA_BUS_FMT_YUYV10_1X20 0x200d
+#define MEDIA_BUS_FMT_YVYU10_1X20 0x200e
+#define MEDIA_BUS_FMT_VUY8_1X24 0x2024
+#define MEDIA_BUS_FMT_YUV8_1X24 0x2025
+#define MEDIA_BUS_FMT_UYVY12_1X24 0x2020
+#define MEDIA_BUS_FMT_VYUY12_1X24 0x2021
+#define MEDIA_BUS_FMT_YUYV12_1X24 0x2022
+#define MEDIA_BUS_FMT_YVYU12_1X24 0x2023
+#define MEDIA_BUS_FMT_YUV10_1X30 0x2016
+#define MEDIA_BUS_FMT_AYUV8_1X32 0x2017
+
+/* Bayer - next is 0x3019 */
+#define MEDIA_BUS_FMT_SBGGR8_1X8 0x3001
+#define MEDIA_BUS_FMT_SGBRG8_1X8 0x3013
+#define MEDIA_BUS_FMT_SGRBG8_1X8 0x3002
+#define MEDIA_BUS_FMT_SRGGB8_1X8 0x3014
+#define MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8 0x3015
+#define MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8 0x3016
+#define MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8 0x3017
+#define MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8 0x3018
+#define MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8 0x300b
+#define MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8 0x300c
+#define MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8 0x3009
+#define MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8 0x300d
+#define MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE 0x3003
+#define MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE 0x3004
+#define MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE 0x3005
+#define MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE 0x3006
+#define MEDIA_BUS_FMT_SBGGR10_1X10 0x3007
+#define MEDIA_BUS_FMT_SGBRG10_1X10 0x300e
+#define MEDIA_BUS_FMT_SGRBG10_1X10 0x300a
+#define MEDIA_BUS_FMT_SRGGB10_1X10 0x300f
+#define MEDIA_BUS_FMT_SBGGR12_1X12 0x3008
+#define MEDIA_BUS_FMT_SGBRG12_1X12 0x3010
+#define MEDIA_BUS_FMT_SGRBG12_1X12 0x3011
+#define MEDIA_BUS_FMT_SRGGB12_1X12 0x3012
+
+/* JPEG compressed formats - next is 0x4002 */
+#define MEDIA_BUS_FMT_JPEG_1X8 0x4001
+
+/* Vendor specific formats - next is 0x5002 */
+
+/* S5C73M3 sensor specific interleaved UYVY and JPEG */
+#define MEDIA_BUS_FMT_S5C_UYVY_JPEG_1X8 0x5001
+
+/* HSV - next is 0x6002 */
+#define MEDIA_BUS_FMT_AHSV8888_1X32 0x6001
+
+#endif /* __LINUX_MEDIA_BUS_FORMAT_H */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* [PATCH 2/3] video: add VPL ioctl to get bus format
From: Philipp Zabel @ 2016-08-24 10:40 UTC (permalink / raw)
To: barebox
In-Reply-To: <1472035219-23917-1-git-send-email-p.zabel@pengutronix.de>
The i.MX specific DI_MODE VPL ioctl already allows to query the encoder
input bus format. This patch also allows non-i.MX specific encoder drivers
to report their input bus format.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/video/imx-ipu-v3/ipufb.c | 8 ++++++--
include/video/vpl.h | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/video/imx-ipu-v3/ipufb.c b/drivers/video/imx-ipu-v3/ipufb.c
index cfafa22..63024b5 100644
--- a/drivers/video/imx-ipu-v3/ipufb.c
+++ b/drivers/video/imx-ipu-v3/ipufb.c
@@ -109,7 +109,7 @@ int ipu_crtc_mode_set(struct ipufb_info *fbi,
int ret;
struct ipu_di_signal_cfg sig_cfg = {};
struct ipu_di_mode di_mode = {};
- u32 bus_format;
+ u32 bus_format = 0;
dev_info(fbi->dev, "%s: mode->xres: %d\n", __func__,
mode->xres);
@@ -117,7 +117,11 @@ int ipu_crtc_mode_set(struct ipufb_info *fbi,
mode->yres);
vpl_ioctl(&fbi->vpl, 2 + fbi->dino, IMX_IPU_VPL_DI_MODE, &di_mode);
- bus_format = di_mode.bus_format ?: fbi->bus_format;
+ vpl_ioctl(&fbi->vpl, 2 + fbi->dino, VPL_GET_BUS_FORMAT, &bus_format);
+ if (bus_format)
+ di_mode.di_clkflags = IPU_DI_CLKMODE_NON_FRACTIONAL;
+ else
+ bus_format = di_mode.bus_format ?: fbi->bus_format;
if (mode->sync & FB_SYNC_HOR_HIGH_ACT)
sig_cfg.Hsync_pol = 1;
diff --git a/include/video/vpl.h b/include/video/vpl.h
index 846007f..6ae7b0f 100644
--- a/include/video/vpl.h
+++ b/include/video/vpl.h
@@ -8,6 +8,7 @@
#define VPL_ENABLE 0x67660003
#define VPL_DISABLE 0x67660004
#define VPL_GET_VIDEOMODES 0x67660005
+#define VPL_GET_BUS_FORMAT 0x67660006
struct vpl {
int (*ioctl)(struct vpl *, unsigned int port,
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* Re: [PATCH] Call boot_board from boot, not from init.
From: Sascha Hauer @ 2016-08-24 10:33 UTC (permalink / raw)
To: Guillermo Rodriguez; +Cc: barebox
In-Reply-To: <1471873534-17014-1-git-send-email-guille.rodriguez@gmail.com>
On Mon, Aug 22, 2016 at 03:45:34PM +0200, Guillermo Rodriguez wrote:
> From: grodriguez <guille.rodriguez@gmail.com>
>
> This ensures that any board-specific code that must be run at
> boot time will be run both when autobooting and when manually
> running the 'boot' command from the console.
>
> Signed-off-by: Guillermo Rodriguez <guille.rodriguez@gmail.com>
> ---
> defaultenv/defaultenv-1/bin/boot | 4 ++++
> defaultenv/defaultenv-1/bin/init | 5 ++---
> 2 files changed, 6 insertions(+), 3 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/defaultenv/defaultenv-1/bin/boot b/defaultenv/defaultenv-1/bin/boot
> index c17ccdb..a5d6596 100644
> --- a/defaultenv/defaultenv-1/bin/boot
> +++ b/defaultenv/defaultenv-1/bin/boot
> @@ -2,6 +2,10 @@
>
> . /env/config
>
> +if [ -f /env/bin/boot_board ]; then
> + . /env/bin/boot_board
> +fi
> +
> if [ x$kernel_loc = xnet ]; then
> kernel_loc=tftp
> fi
> diff --git a/defaultenv/defaultenv-1/bin/init b/defaultenv/defaultenv-1/bin/init
> index a55d293..2dcddbe 100644
> --- a/defaultenv/defaultenv-1/bin/init
> +++ b/defaultenv/defaultenv-1/bin/init
> @@ -23,9 +23,8 @@ if [ -f /env/bin/init_board ]; then
> fi
>
> echo -e "\e[?25h"
> -if [ -f /env/bin/boot_board ]; then
> - . /env/bin/boot_board
> -elif [ -n $autoboot_timeout ]; then
> +
> +if [ -n $autoboot_timeout ]; then
> echo -n "Hit any key to stop autoboot: "
> timeout -a $autoboot_timeout
> if [ $? != 0 ]; then
> --
> 1.7.9.5
>
>
> _______________________________________________
> 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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* [PATCH] boot: add framework for redundant boot scenarios
From: Sascha Hauer @ 2016-08-24 10:22 UTC (permalink / raw)
To: Barebox List
From: Marc Kleine-Budde <mkl@pengutronix.de>
There are several use cases where a redundant Linux system is needed. The
barebox bootchooser framework provides the building blocks to model different
use cases without the need to start from the scratch over and over again.
The bootchooser works on abstract boot targets, each with a set of properties
and implements an algorithm which selects the highest priority target to boot.
See the documentation contained in this patch for more information.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Documentation/user/bootchooser.rst | 185 +++++++++
Documentation/user/state.rst | 2 +
Documentation/user/user-manual.rst | 1 +
commands/Kconfig | 5 +
commands/Makefile | 1 +
commands/bootchooser.c | 148 +++++++
common/Kconfig | 6 +
common/Makefile | 1 +
common/boot.c | 7 +
common/bootchooser.c | 784 +++++++++++++++++++++++++++++++++++++
include/bootchooser.h | 37 ++
11 files changed, 1177 insertions(+)
create mode 100644 Documentation/user/bootchooser.rst
create mode 100644 commands/bootchooser.c
create mode 100644 common/bootchooser.c
create mode 100644 include/bootchooser.h
diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
new file mode 100644
index 0000000..5bd8684
--- /dev/null
+++ b/Documentation/user/bootchooser.rst
@@ -0,0 +1,185 @@
+Barebox Bootchooser
+===================
+
+In many cases embedded systems are layed out redundantly with multiple
+kernels and multiple root file systems. The bootchooser framework provides
+the building blocks to model different use cases without the need to start
+from the scratch over and over again.
+
+The bootchooser works on abstract boot targets, each with a set of properties
+and implements an algorithm which selects the highest priority target to boot.
+
+Bootchooser Targets
+-------------------
+
+A bootchooser target represents one target that barebox can boot. It consists
+of a set of variables in the ``global.bootchooser.<targetname>`` namespace. The
+following configuration variables are needed to describe a bootchooser target:
+
++---------------------------------------------+---------+----------------------------+
+| Name | Example | Description |
++---------------------------------------------+---------+----------------------------+
+| global.bootchooser.system0.boot | mmc0 | This controls what |
+| | | barebox actually |
+| | | boots for this target. |
+| | | This string can contain |
+| | | anything that the |
+| | | :ref:`boot <command_boot>` |
+| | | command understands. |
++---------------------------------------------+---------+----------------------------+
+| global.bootchooser.system0.default_attempts | 3 | The default number of |
+| | | attempts that a target |
+| | | shall be tried starting. |
++---------------------------------------------+---------+----------------------------+
+| global.bootchooser.system0.default_priority | 20 | The default priority of |
+| | | a target. |
++---------------------------------------------+---------+----------------------------+
+
+Additionally the following runtime variables are needed. Unlinke the configuration
+variables these are automatically changed by the bootchooser algorithm:
+
++-------------------------------------------------+---------+---------------------------+
+| Name | Example | Description |
++-------------------------------------------------+---------+---------------------------+
+| global.bootchooser.system0.priority | 20 | The current priority |
+| | | of the target. Higher |
+| | | numbers have higher |
+| | | priorities. A priority of |
+| | | 0 means the target is |
+| | | disabled and won't be |
+| | | started. |
++-------------------------------------------------+---------+---------------------------+
+| global.bootchooser.system0.remaining_attempts | 1 | The remaining attempts |
+| | | counter. Only targets |
+| | | with a remaining_attempts |
+| | | counter > 0 are started. |
++-------------------------------------------------+---------+---------------------------+
+
+The bootchooser algorithm generally only starts targets that have a priority
+> 0 and a remaining attempts counter > 0.
+
+The Bootchooser Algorithm
+-------------------------
+
+The bootchooser algorithm always selects the target with the highest priority
+that has a nonzero remaining attempts counter. The remaining attempts counter
+of the target is decremented by one. This means every target remaining attempts
+counter reaches zero sooner or later and the target won't be booted anymore.
+To prevent that the target must be marked good. This can be done either in the
+running system or in barebox.
+
+Marking a System 'Good' in the System Itself
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+In this case barebox will always decrement the remaining attempts counter. In the
+running system it must then be incremented again, which is done usually when the
+application is started successfully. The upside of this mechanism is that a very fine
+grained decision can be made when a target is 'good'. The downside may be that the
+state must be written twice each boot: Once for decrementing the counter in barebox
+and once for incrementing the counters again.
+
+Marking a System 'Good' in Barebox
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+A target can be marked as good in barebox using a bootchooser command or by a
+equivalent C function. Usually a startup script will contain something like:
+
+.. code-block:: sh
+
+ if [ "${global.system.reset}" = "POR" ]; then
+ # Power-on-reset, tell that last boot was successful
+ bootchooser -s
+ fi
+
+In this case the bootchooser will *not* decrement the remaining attempts counter
+of the booted target if it is the same target that was booted last time.
+
+Bootchooser General Options
+---------------------------
+
+Additionally to the target options described above bootchooser has some general
+options not specific to any target.
+
++-------------------------------------+------------+--------------------------------------+
+| Name | Example | Description |
++-------------------------------------+------------+--------------------------------------+
+| global.bootchooser. | 0 | Boolean flag, if 1 bootchooser |
+| deactivate_on_zero_attempts | | deactivates a target (sets priority |
+| | | to 0) whenever the remaining |
+| | | attempts counter reaches 0. |
++-------------------------------------+------------+--------------------------------------+
+| global.bootchooser.default_attempts | 3 | The default number of |
+| | | attempts that a target |
+| | | shall be tried starting, used |
+| | | when not overwritten with |
+| | | the target specific variable |
+| | | of the same name. |
++-------------------------------------+------------+--------------------------------------+
+| global.bootchooser.retry | 1 | If 1, bootchooser retries booting |
+| | | until one succeeds or no more valid |
+| | | targets exist. |
++-------------------------------------+------------+--------------------------------------+
+| global.bootchooser.state_prefix | state.boot | Variable prefix when bootchooser |
+| | | used with state framework as |
+| | | backend for storing runtime data, |
+| | | see below. |
++-------------------------------------+------------+--------------------------------------+
+| global.bootchooser.targets | sys0 sys1 | Space separated list of targets that |
+| | | are used. For each entry in the |
+| | | list a corresponding set of |
+| | | global.bootchooser.<name>. |
+| | | variables must exist. |
++-------------------------------------+------------+--------------------------------------+
+| global.bootchooser.last_chosen | 0 | Set to the target that was chosen on |
+| | | last boot (index) |
++-------------------------------------+------------+--------------------------------------+
+
+Using the State Framework as Backend for Runtime Variable Data
+--------------------------------------------------------------
+
+Normally the data that is modified by the bootchooser during runtime is stored
+in global variables (backed with NV). Alternatively the :ref:`state_framework`
+can be used for this data which allows to store this data redundantely
+and in small EEPROM spaces. See :ref:`state_framework` to setup the state framework.
+During barebox runtime each state instance will create a device
+(usually named 'state' when only one is used) with a set of parameters. Set
+``global.bootchooser.state_prefix`` to the name of the device and optionally the
+namespace inside this device. For example when your state device is called 'state'
+and inside that the 'bootchooser' namespace is used for describing the targets,
+then set ``global.bootchooser.state_prefix`` to ``state.bootchooser``.
+
+Example
+-------
+
+The following initializes two targets, 'system0' and 'system1'. Both boot
+from an UBIFS on nand0, the former has a priority of 21 and boots from
+the volume 'system0' whereas the latter has a priority of 20 and boots from
+the volume 'system1'.
+
+.. code-block:: sh
+
+ # initialize target 'system0'
+ nv bootchooser.system0.boot=nand0.ubi.system0
+ nv bootchooser.system0.remaining_attempts=3
+ nv bootchooser.system0.default_attempts=3
+ nv bootchooser.system0.priority=21
+ nv bootchooser.system0.default_priority=21
+
+ # initialize target 'system1'
+ nv bootchooser.system1.boot=nand0.ubi.system1
+ nv bootchooser.system1.remaining_attempts=3
+ nv bootchooser.system1.default_attempts=3
+ nv bootchooser.system1.priority=20
+ nv bootchooser.system1.default_priority=20
+
+ # make targets known
+ nv bootchooser.targets="system0 system1"
+
+ # retry until one target succeeds
+ nv bootchooser.retry=true
+
+ # First try bootchooser, when no targets remain boot from network
+ nv boot.default="bootchooser net"
+
+Note that this example is for testing, normally the NV variables would be
+initialized directly by files in the default environment, not with a script.
diff --git a/Documentation/user/state.rst b/Documentation/user/state.rst
index c401f10..5dd5c48 100644
--- a/Documentation/user/state.rst
+++ b/Documentation/user/state.rst
@@ -1,3 +1,5 @@
+.. _state_framework:
+
Barebox State Framework
=======================
diff --git a/Documentation/user/user-manual.rst b/Documentation/user/user-manual.rst
index 5841ea6..435649f 100644
--- a/Documentation/user/user-manual.rst
+++ b/Documentation/user/user-manual.rst
@@ -27,6 +27,7 @@ Contents:
usb
ubi
booting-linux
+ bootchooser
remote-control
system-setup
reset-reason
diff --git a/commands/Kconfig b/commands/Kconfig
index decd45d..30bf429 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2097,6 +2097,11 @@ config CMD_STATE
depends on STATE
prompt "state"
+config CMD_BOOTCHOOSER
+ tristate
+ depends on BOOTCHOOSER
+ prompt "bootchooser"
+
config CMD_DHRYSTONE
bool
prompt "dhrystone"
diff --git a/commands/Makefile b/commands/Makefile
index 7abd6dd..601f15f 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -115,6 +115,7 @@ obj-$(CONFIG_CMD_NV) += nv.o
obj-$(CONFIG_CMD_DEFAULTENV) += defaultenv.o
obj-$(CONFIG_CMD_STATE) += state.o
obj-$(CONFIG_CMD_DHCP) += dhcp.o
+obj-$(CONFIG_CMD_BOOTCHOOSER) += bootchooser.o
obj-$(CONFIG_CMD_DHRYSTONE) += dhrystone.o
obj-$(CONFIG_CMD_SPD_DECODE) += spd_decode.o
obj-$(CONFIG_CMD_MMC_EXTCSD) += mmc_extcsd.o
diff --git a/commands/bootchooser.c b/commands/bootchooser.c
new file mode 100644
index 0000000..91938fe
--- /dev/null
+++ b/commands/bootchooser.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2012 Jan Luebbe <j.luebbe@pengutronix.de>
+ * Copyright (C) 2015 Marc Kleine-Budde <mkl@pengutronix.de>
+ *
+ * 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 <bootchooser.h>
+#include <globalvar.h>
+#include <command.h>
+#include <common.h>
+#include <getopt.h>
+#include <malloc.h>
+#include <stdio.h>
+
+#define DONTTOUCH -2
+#define DEFAULT -1
+
+static void target_reset(struct bootchooser_target *target, int priority, int attempts)
+{
+ printf("Resetting target %s to ", bootchooser_target_name(target));
+
+ if (priority >= 0)
+ printf("priority %d", priority);
+ else if (priority == DEFAULT)
+ printf("default priority");
+
+ if (priority > DONTTOUCH && attempts > DONTTOUCH)
+ printf(", ");
+
+ if (attempts >= 0)
+ printf("%d attempts", attempts);
+ else if (attempts == DEFAULT)
+ printf("default attempts");
+
+ printf("\n");
+
+ if (priority > DONTTOUCH)
+ bootchooser_target_set_priority(target, priority);
+ if (attempts > DONTTOUCH)
+ bootchooser_target_set_attempts(target, attempts);
+}
+
+static int do_bootchooser(int argc, char *argv[])
+{
+ int opt, ret = 0, i;
+ struct bootchooser *bootchooser;
+ struct bootchooser_target *target;
+ int attempts = DONTTOUCH;
+ int priority = DONTTOUCH;
+ int info = 0;
+ bool done_something = false;
+ bool last_boot_successful = false;
+
+ while ((opt = getopt(argc, argv, "a:p:is")) > 0) {
+ switch (opt) {
+ case 'a':
+ if (!strcmp(optarg, "default"))
+ attempts = DEFAULT;
+ else
+ attempts = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'p':
+ if (!strcmp(optarg, "default"))
+ priority = DEFAULT;
+ else
+ priority = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'i':
+ info = 1;
+ break;
+ case 's':
+ last_boot_successful = true;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ bootchooser = bootchooser_get();
+ if (IS_ERR(bootchooser)) {
+ printf("No bootchooser found\n");
+ return COMMAND_ERROR;
+ }
+
+ if (last_boot_successful) {
+ bootchooser_last_boot_successful();
+ done_something = true;
+ }
+
+ if (attempts != DONTTOUCH || priority != DONTTOUCH) {
+ if (optind < argc) {
+ for (i = optind; i < argc; i++) {
+ target = bootchooser_target_by_name(bootchooser, argv[i]);
+ if (!target) {
+ printf("No such target: %s\n", argv[i]);
+ ret = COMMAND_ERROR;
+ goto out;
+ }
+
+ target_reset(target, priority, attempts);
+ }
+ } else {
+ bootchooser_for_each_target(bootchooser, target)
+ target_reset(target, priority, attempts);
+ }
+ done_something = true;
+ }
+
+ if (info) {
+ bootchooser_info(bootchooser);
+ done_something = true;
+ }
+
+ if (!done_something) {
+ printf("Nothing to do\n");
+ ret = COMMAND_ERROR_USAGE;
+ }
+out:
+ bootchooser_put(bootchooser);
+
+ return ret;
+}
+
+BAREBOX_CMD_HELP_START(bootchooser)
+BAREBOX_CMD_HELP_TEXT("Control misc behaviour of the bootchooser")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-a <n|default> [TARGETS]", "set priority of given targets to 'n' or the default priority")
+BAREBOX_CMD_HELP_OPT ("-p <n|default> [TARGETS]", "set remaining attempts of given targets to 'n' or the default attempts")
+BAREBOX_CMD_HELP_OPT ("-i", "Show information about the bootchooser")
+BAREBOX_CMD_HELP_OPT ("-s", "Mark the last boot successful")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(bootchooser)
+ .cmd = do_bootchooser,
+ BAREBOX_CMD_DESC("bootchooser control")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_bootchooser_help)
+BAREBOX_CMD_END
diff --git a/common/Kconfig b/common/Kconfig
index 38225eb..262dbf2 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -935,6 +935,12 @@ config STATE_CRYPTO
See Documentation/devicetree/bindings/barebox/barebox,state.rst
for more information.
+config BOOTCHOOSER
+ bool "bootchooser infrastructure"
+ select ENVIRONMENT_VARIABLES
+ select OFTREE
+ select PARAMETER
+
config RESET_SOURCE
bool "detect Reset cause"
depends on GLOBALVAR
diff --git a/common/Makefile b/common/Makefile
index 00bc0e8..a36ae5e 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_SHELL_HUSH) += hush.o
obj-$(CONFIG_SHELL_SIMPLE) += parser.o
obj-$(CONFIG_STATE) += state/
obj-$(CONFIG_RATP) += ratp.o
+obj-$(CONFIG_BOOTCHOOSER) += bootchooser.o
obj-$(CONFIG_UIMAGE) += image.o uimage.o
obj-$(CONFIG_FITIMAGE) += image-fit.o
obj-$(CONFIG_MENUTREE) += menutree.o
diff --git a/common/boot.c b/common/boot.c
index e66bacb..573bebd 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -10,6 +10,7 @@
*/
#include <environment.h>
+#include <bootchooser.h>
#include <globalvar.h>
#include <magicvar.h>
#include <watchdog.h>
@@ -270,6 +271,12 @@ int bootentry_create_from_name(struct bootentries *bootentries,
}
}
+ if (IS_ENABLED(CONFIG_BOOTCHOOSER) && !strcmp(name, "bootchooser")) {
+ ret = bootchooser_create_bootentry(bootentries);
+ if (ret > 0)
+ found += ret;
+ }
+
if (!found) {
char *path;
diff --git a/common/bootchooser.c b/common/bootchooser.c
new file mode 100644
index 0000000..2f087e8
--- /dev/null
+++ b/common/bootchooser.c
@@ -0,0 +1,784 @@
+/*
+ * Copyright (C) 2012 Jan Luebbe <j.luebbe@pengutronix.de>
+ * Copyright (C) 2015 Marc Kleine-Budde <mkl@pengutronix.de>
+ *
+ * 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.
+ */
+#define pr_fmt(fmt) "bootchooser: " fmt
+
+#include <bootchooser.h>
+#include <environment.h>
+#include <globalvar.h>
+#include <magicvar.h>
+#include <command.h>
+#include <libfile.h>
+#include <common.h>
+#include <malloc.h>
+#include <printk.h>
+#include <xfuncs.h>
+#include <envfs.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <ioctl.h>
+#include <libbb.h>
+#include <state.h>
+#include <stdio.h>
+#include <init.h>
+#include <crc.h>
+#include <net.h>
+#include <fs.h>
+
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/err.h>
+
+#define BOOTCHOOSER_PREFIX "global.bootchooser"
+
+static char *available_targets;
+static char *state_prefix;
+static int global_default_attempts = 3;
+static int deactivate_on_zero_attempts;
+static int retry;
+static int last_boot_successful;
+
+struct bootchooser {
+ struct bootentry entry;
+ struct list_head targets;
+ bool dirty;
+ struct bootchooser_target *last_chosen;
+
+ char *state_devname;
+
+ int verbose;
+ int dryrun;
+};
+
+struct bootchooser_target {
+ struct bootchooser *bootchooser;
+ struct list_head list;
+
+ /* state */
+ unsigned int priority;
+ unsigned int remaining_attempts;
+ int id;
+
+ /* spec */
+ char *name;
+ unsigned int default_attempts;
+ unsigned int default_priority;
+
+ char *boot;
+
+ char *prefix;
+ char *state_prefix;
+};
+
+static int bootchooser_target_ok(struct bootchooser_target *target, const char **reason)
+{
+ if (!target->priority) {
+ if (reason)
+ *reason = "Target disabled (priority = 0)";
+ return false;
+ }
+
+ if (!target->remaining_attempts) {
+ if (reason)
+ *reason = "remaining attempts = 0";
+ return false;
+ }
+
+ if (reason)
+ *reason = "target OK";
+
+ return true;
+}
+
+static void pr_target(struct bootchooser_target *target)
+{
+ const char *reason;
+ int ok;
+
+ ok = bootchooser_target_ok(target, &reason);
+
+ printf("%s\n"
+ " id: %u\n"
+ " priority: %u\n"
+ " default_priority: %u\n"
+ " remaining attempts: %u\n"
+ " default attempts: %u\n"
+ " boot: '%s'\n",
+ target->name, target->id, target->priority, target->default_priority,
+ target->remaining_attempts, target->default_attempts,
+ target->boot);
+ if (!ok)
+ printf(" disabled due to %s\n", reason);
+}
+
+static int pr_setenv(struct bootchooser *bc, const char *fmt, ...)
+{
+ va_list ap;
+ int ret = 0;
+ char *str, *val;
+ const char *oldval;
+
+ va_start(ap, fmt);
+ str = bvasprintf(fmt, ap);
+ va_end(ap);
+
+ if (!str)
+ return -ENOMEM;
+
+ val = strchr(str, '=');
+ if (!val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ *val++ = '\0';
+
+ oldval = getenv(str);
+ if (!oldval || strcmp(oldval, val)) {
+ ret = setenv(str, val);
+ bc->dirty = true;
+ }
+
+err:
+ free(str);
+
+ return ret;
+}
+
+static const char *pr_getenv(const char *fmt, ...)
+{
+ va_list ap;
+ char *str;
+ const char *val;
+
+ va_start(ap, fmt);
+ str = bvasprintf(fmt, ap);
+ va_end(ap);
+
+ if (!str)
+ return NULL;
+
+ val = getenv(str);
+
+ free(str);
+
+ return val;
+}
+
+static int pr_getenv_u32(uint32_t *retval, const char *fmt, ...)
+{
+ va_list ap;
+ char *str;
+ const char *val;
+
+ va_start(ap, fmt);
+ str = bvasprintf(fmt, ap);
+ va_end(ap);
+
+ if (!str)
+ return -ENOMEM;
+
+ val = getenv(str);
+
+ free(str);
+
+ if (!val)
+ return -ENOENT;
+
+ *retval = simple_strtoul(val, NULL, 0);
+
+ return 0;
+}
+
+static int bootchooser_target_compare(struct list_head *a, struct list_head *b)
+{
+ struct bootchooser_target *bootchooser_a = list_entry(a, struct bootchooser_target, list);
+ struct bootchooser_target *bootchooser_b = list_entry(b, struct bootchooser_target, list);
+
+ /* order with descending priority */
+ return bootchooser_a->priority >= bootchooser_b->priority ? -1 : 1;
+}
+
+struct target_var {
+ char **prefix;
+ const char *name;
+ uint32_t *ptr;
+};
+
+static struct bootchooser_target *bootchooser_target_new(const char *name)
+{
+ struct bootchooser_target *target = xzalloc(sizeof(*target));
+ int ret, i;
+ const char *val;
+ struct target_var vars[] = {
+ {
+ .prefix = &target->prefix,
+ .name = "default_attempts",
+ .ptr = &target->default_attempts,
+ }, {
+ .prefix = &target->prefix,
+ .name = "default_priority",
+ .ptr = &target->default_priority,
+ }, {
+ .prefix = &target->state_prefix,
+ .name = "priority",
+ .ptr = &target->priority,
+ }, {
+ .prefix = &target->state_prefix,
+ .name = "remaining_attempts",
+ .ptr = &target->remaining_attempts,
+ }
+ };
+
+ target->name = xstrdup(name);
+ target->prefix = basprintf("%s.%s", BOOTCHOOSER_PREFIX, name);
+ target->state_prefix = basprintf("%s.%s", state_prefix, name);
+
+ target->default_attempts = global_default_attempts;
+
+ for (i = 0; i < ARRAY_SIZE(vars); i++) {
+ struct target_var *var = &vars[i];
+ ret = pr_getenv_u32(var->ptr, "%s.%s", *var->prefix, var->name);
+ if (ret) {
+ pr_err("Cannot read %s.%s\n", *var->prefix, var->name);
+ goto err;
+ }
+ }
+
+ val = pr_getenv("%s.boot", target->prefix);
+ if (!val)
+ val = target->name;
+ target->boot = xstrdup(val);
+
+ return target;
+
+err:
+ pr_err("Cannot initialize target '%s'\n", name);
+
+ free(target);
+
+ return ERR_PTR(ret);
+}
+
+static struct bootchooser_target *bootchooser_target_by_id(struct bootchooser *bc,
+ uint32_t id)
+{
+ struct bootchooser_target *target;
+
+ list_for_each_entry(target, &bc->targets, list)
+ if (target->id == id)
+ return target;
+
+ return NULL;
+}
+
+struct bootchooser *bootchooser_get(void)
+{
+ struct bootchooser *bc;
+ char *targets, *str, *freep = NULL, *delim;
+ int ret = -EINVAL, id = 1;
+ uint32_t last_chosen;
+
+ bc = xzalloc(sizeof(*bc));
+
+ delim = strchr(state_prefix, '.');
+ if (!delim) {
+ pr_err("state_prefix '%s' has invalid format\n", state_prefix);
+ goto err;
+ }
+
+ bc->state_devname = xstrndup(state_prefix, delim - state_prefix);
+
+ INIT_LIST_HEAD(&bc->targets);
+
+ freep = targets = xstrdup(available_targets);
+
+ while (1) {
+ struct bootchooser_target *target;
+
+ str = strsep(&targets, " ");
+ if (!str || !*str)
+ break;
+
+ target = bootchooser_target_new(str);
+ if (!IS_ERR(target)) {
+ target->id = id;
+ list_add_sort(&target->list, &bc->targets,
+ bootchooser_target_compare);
+ }
+
+ id++;
+ }
+
+ if (id == 1) {
+ pr_err("Target list $global.bootchooser.targets is empty\n");
+ goto err;
+ }
+
+ if (list_empty(&bc->targets)) {
+ pr_err("No targets could be initialized\n");
+ goto err;
+ }
+
+ free(freep);
+
+ ret = pr_getenv_u32(&last_chosen, "%s.last_chosen", state_prefix);
+ if (!ret && last_chosen > 0) {
+ bc->last_chosen = bootchooser_target_by_id(bc, last_chosen);
+ if (!bc->last_chosen)
+ pr_warn("Last booted target with id %d does not exist\n", last_chosen);
+ }
+
+ if (bc->last_chosen && !bc->last_chosen->remaining_attempts &&
+ deactivate_on_zero_attempts) {
+ bc->last_chosen->priority = 0;
+
+ pr_info("target %s has 0 remaining attempts, disabling\n",
+ bc->last_chosen->name);
+ }
+
+ return bc;
+
+err:
+ free(freep);
+ free(bc);
+
+ return ERR_PTR(ret);
+}
+
+/**
+ * bootchooser_save - save a bootchooser to the backing store
+ * @bc: The bootchooser instance to save
+ *
+ * Return: 0 for success, negative error code otherwise
+ */
+int bootchooser_save(struct bootchooser *bc)
+{
+ struct bootchooser_target *target;
+ int ret;
+ struct state *state;
+
+ if (bc->last_chosen)
+ pr_setenv(bc, "%s.last_chosen=0x%08x", state_prefix,
+ bc->last_chosen->id);
+
+ list_for_each_entry(target, &bc->targets, list) {
+ ret = pr_setenv(bc, "%s.remaining_attempts=%d",
+ target->state_prefix,
+ target->remaining_attempts);
+ if (ret)
+ return ret;
+
+ ret = pr_setenv(bc, "%s.priority=%d",
+ target->state_prefix, target->priority);
+ if (ret)
+ return ret;
+ }
+
+ if (!strcmp(bc->state_devname, "nv")) {
+ ret = nvvar_save();
+ if (ret) {
+ pr_err("Cannot save nv variables: %s\n", strerror(-ret));
+ return ret;
+ }
+ } else {
+ state = state_by_name(bc->state_devname);
+ if (!state) {
+ pr_err("Cannot get state '%s'\n",
+ bc->state_devname);
+ return -ENODEV;
+ }
+
+ ret = state_save(state);
+ if (ret) {
+ pr_err("Cannot save state '%s': %s\n", bc->state_devname, strerror(-ret));
+ return ret;
+ }
+ }
+
+ bc->dirty = 0;
+
+ return 0;
+}
+
+int bootchooser_put(struct bootchooser *bc)
+{
+ struct bootchooser_target *target, *tmp;
+ int ret;
+
+ ret = bootchooser_save(bc);
+ if (ret)
+ pr_err("Failed to save bootchooser state: %s\n", strerror(-ret));
+
+ list_for_each_entry_safe(target, tmp, &bc->targets, list) {
+ free(target->boot);
+ free(target->prefix);
+ free(target->state_prefix);
+ free(target->name);
+ free(target);
+ }
+
+ free(bc);
+
+ return ret;
+}
+
+void bootchooser_info(struct bootchooser *bc)
+{
+ struct bootchooser_target *target;
+ const char *reason;
+ int count = 0;
+
+ printf("Good targets (first will be booted next):\n");
+ list_for_each_entry(target, &bc->targets, list) {
+ if (bootchooser_target_ok(target, NULL)) {
+ count++;
+ pr_target(target);
+ }
+ }
+
+ if (!count)
+ printf("none\n");
+
+ count = 0;
+
+ printf("\nDisabled targets:\n");
+ list_for_each_entry(target, &bc->targets, list) {
+ if (!bootchooser_target_ok(target, &reason)) {
+ count++;
+ pr_target(target);
+ }
+ }
+
+ if (!count)
+ printf("none\n");
+
+ printf("\nlast booted target: %s\n", bc->last_chosen ?
+ bc->last_chosen->name : "unknown");
+}
+
+/**
+ * bootchooser_get_target - get the target that shall be booted next
+ * @bc: The bootchooser
+ *
+ * This is the heart of the bootchooser. This function selects the next
+ * target to boot and returns it. If the remaining_attempts counter
+ * reaches 0 and deactivate_on_zero_attempts is true then the target
+ * will be disabled on the next boot.
+ *
+ * Return: The next target
+ */
+struct bootchooser_target *bootchooser_get_target(struct bootchooser *bc)
+{
+ struct bootchooser_target *target;
+
+ list_for_each_entry(target, &bc->targets, list) {
+ if (bootchooser_target_ok(target, NULL))
+ goto found;
+ }
+
+ pr_err("No valid targets found:\n");
+ list_for_each_entry(target, &bc->targets, list)
+ pr_target(target);
+
+ return ERR_PTR(-ENOENT);
+
+found:
+ if (!last_boot_successful || bc->last_chosen != target) {
+ target->remaining_attempts--;
+
+ if (bc->verbose)
+ pr_info("name=%s decrementing remaining_attempts to %d\n",
+ target->name, target->remaining_attempts);
+ }
+
+ if (bc->verbose)
+ pr_info("selected target '%s', boot '%s'\n", target->name, target->boot);
+
+ bc->last_chosen = target;
+
+ bootchooser_save(bc);
+
+ return target;
+}
+
+/**
+ * bootchooser_target_name - get the name of a target
+ * @target: The target
+ *
+ * Given a bootchooser target this function returns its name.
+ *
+ * Return: The name of the target
+ */
+const char *bootchooser_target_name(struct bootchooser_target *target)
+{
+ return target->name;
+}
+
+/**
+ * bootchooser_target_by_name - get a target from name
+ * @bc: The bootchooser
+ * @name: The name of the target to retrieve
+ *
+ * Given a name this function returns the corresponding target.
+ *
+ * Return: The target if found, NULL otherwise
+ */
+struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bc,
+ const char *name)
+{
+ struct bootchooser_target *target;
+
+ bootchooser_for_each_target(bc, target)
+ if (!strcmp(target->name, name))
+ return target;
+ return NULL;
+}
+
+/**
+ * bootchooser_target_set_attempts - set remaining attempts of a target
+ * @target: The target to change
+ * @attempts: The number of attempts
+ *
+ * This sets the number of remaining attempts for a bootchooser target.
+ * If @attempts is < 0 then the remaining attempts is reset to the default
+ * value.
+ *
+ * Return: 0 for success, negative error code otherwise
+ */
+int bootchooser_target_set_attempts(struct bootchooser_target *target, int attempts)
+{
+ if (attempts >= 0)
+ target->remaining_attempts = attempts;
+ else
+ target->remaining_attempts = target->default_attempts;
+
+ return 0;
+}
+
+/**
+ * bootchooser_target_set_priority - set priority of a target
+ * @target: The target to change
+ * @priority: The priority
+ *
+ * This sets the priority of a bootchooser target. If @priority is < 0
+ * then the priority reset to the default value.
+ *
+ * Return: 0 for success, negative error code otherwise
+ */
+int bootchooser_target_set_priority(struct bootchooser_target *target, int priority)
+{
+ if (priority >= 0)
+ target->priority = priority;
+ else
+ target->priority = target->default_priority;
+
+ return 0;
+}
+
+/**
+ * bootchooser_target_first - get the first target from a bootchooser
+ * @bc: The bootchooser
+ *
+ * Gets the first target from a bootchooser, used for the bootchooser
+ * target iterator.
+ *
+ * Return: The first target or NULL if no target exists
+ */
+struct bootchooser_target *bootchooser_target_first(struct bootchooser *bc)
+{
+ return list_first_entry_or_null(&bc->targets,
+ struct bootchooser_target, list);
+}
+
+/**
+ * bootchooser_target_next - get the next target from a bootchooser
+ * @bc: The bootchooser
+ * @target: The current target
+ *
+ * Gets the next target from a bootchooser, used for the bootchooser
+ * target iterator.
+ *
+ * Return: The first target or NULL if no more targets exist
+ */
+struct bootchooser_target *bootchooser_target_next(struct bootchooser *bc,
+ struct bootchooser_target *target)
+{
+ struct list_head *next = target->list.next;
+
+ if (next == &bc->targets)
+ return NULL;
+
+ return list_entry(next, struct bootchooser_target, list);
+}
+
+/**
+ * bootchooser_last_boot_successful - tell that the last boot was successful
+ *
+ * This tells bootchooser that the last boot was successful. This effectively
+ * means that if the same target is booted again then the remaining_attempts
+ * counter of that target is not decremented.
+ */
+void bootchooser_last_boot_successful(void)
+{
+ last_boot_successful = true;
+}
+
+/**
+ * bootchooser_get_last_chosen - get the target which was chosen last time
+ * @bc: The bootchooser
+ *
+ * Bootchooser stores the id of the target which was last booted in
+ * <state_prefix>.last_chosen. This function returns the target associated
+ * with this id.
+ *
+ * Return: The target which was booted last time
+ */
+struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bc)
+{
+ if (!bc->last_chosen)
+ return ERR_PTR(-ENODEV);
+
+ return bc->last_chosen;
+}
+
+static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
+{
+ char *system;
+ struct bootentries *entries;
+ struct bootentry *entry;
+ struct bootchooser_target *target;
+ int ret = 0;
+
+ entries = bootentries_alloc();
+
+ target = bootchooser_get_target(bc);
+ if (IS_ERR(target)) {
+ ret = PTR_ERR(target);
+ *tryagain = 0;
+ goto out;
+ }
+
+ system = basprintf("bootchooser.active=%s", target->name);
+ globalvar_add_simple("linux.bootargs.bootchooser", system);
+ free(system);
+
+ ret = bootentry_create_from_name(entries, target->boot);
+ if (ret <= 0) {
+ printf("Nothing bootable found on '%s'\n", target->boot);
+ *tryagain = 1;
+ ret = -ENODEV;
+ goto out;
+ }
+
+ last_boot_successful = false;
+
+ ret = -ENOENT;
+
+ bootentries_for_each_entry(entries, entry) {
+ ret = boot_entry(entry, bc->verbose, bc->dryrun);
+ if (!ret) {
+ *tryagain = 0;
+ goto out;
+ }
+ }
+
+ *tryagain = 1;
+out:
+ globalvar_set_match("linux.bootargs.bootchooser", NULL);
+
+ bootentries_free(entries);
+
+ return ret;
+}
+
+static int bootchooser_boot(struct bootentry *entry, int verbose, int dryrun)
+{
+ struct bootchooser *bc = container_of(entry, struct bootchooser,
+ entry);
+ int ret, tryagain;
+
+ bc->verbose = verbose;
+ bc->dryrun = dryrun;
+
+ do {
+ ret = bootchooser_boot_one(bc, &tryagain);
+
+ if (!retry)
+ break;
+ } while (tryagain);
+
+ return ret;
+}
+
+static void bootchooser_release(struct bootentry *entry)
+{
+ struct bootchooser *bc = container_of(entry, struct bootchooser,
+ entry);
+
+ bootchooser_put(bc);
+}
+
+/**
+ * bootchooser_create_bootentry - create a boot entry
+ * @entries: The list of bootentries
+ *
+ * This adds a bootchooser to the list of boot entries. Called
+ * by the 'boot' code.
+ *
+ * Return: The number of entries added to the list
+ */
+int bootchooser_create_bootentry(struct bootentries *entries)
+{
+ struct bootchooser *bc = bootchooser_get();
+
+ if (IS_ERR(bc))
+ return PTR_ERR(bc);
+
+ bc->entry.boot = bootchooser_boot;
+ bc->entry.release = bootchooser_release;
+ bc->entry.title = xstrdup("bootchooser");
+ bc->entry.description = xstrdup("bootchooser");
+
+ bootentries_add_entry(entries, &bc->entry);
+
+ return 1;
+}
+
+static int bootchooser_init(void)
+{
+ state_prefix = xstrdup("nv.bootchooser");
+
+ globalvar_add_simple_bool("bootchooser.deactivate_on_zero_attempts", &deactivate_on_zero_attempts);
+ globalvar_add_simple_bool("bootchooser.retry", &retry);
+ globalvar_add_simple_string("bootchooser.targets", &available_targets);
+ globalvar_add_simple_string("bootchooser.state_prefix", &state_prefix);
+ globalvar_add_simple_int("bootchooser.default_attempts", &global_default_attempts, "%u");
+
+ return 0;
+}
+device_initcall(bootchooser_init);
+
+BAREBOX_MAGICVAR_NAMED(global_bootchooser_deactivate_on_zero_attempts,
+ global.bootchooser.deactivate_on_zero_attempts,
+ "bootchooser: Disable target when remaining attempts counter reaches 0");
+BAREBOX_MAGICVAR_NAMED(global_bootchooser_retry,
+ global.bootchooser.retry,
+ "bootchooser: Try again when booting a target fails");
+BAREBOX_MAGICVAR_NAMED(global_bootchooser_targets,
+ global.bootchooser.targets,
+ "bootchooser: Space separated list of target names");
+BAREBOX_MAGICVAR_NAMED(global_bootchooser_state_prefix,
+ global.bootchooser.state_prefix,
+ "bootchooser: variable namespace prefix for runtime data (default nv.bootchooser)");
diff --git a/include/bootchooser.h b/include/bootchooser.h
new file mode 100644
index 0000000..c948247
--- /dev/null
+++ b/include/bootchooser.h
@@ -0,0 +1,37 @@
+#ifndef __BOOTCHOOSER_H
+#define __BOOTCHOOSER_H
+
+#include <of.h>
+#include <boot.h>
+
+struct bootchooser;
+struct bootchooser_target;
+
+struct bootchooser *bootchooser_get(void);
+int bootchooser_save(struct bootchooser *bootchooser);
+int bootchooser_put(struct bootchooser *bootchooser);
+
+void bootchooser_info(struct bootchooser *bootchooser);
+
+struct bootchooser_target *bootchooser_get_last_chosen(struct bootchooser *bootchooser);
+const char *bootchooser_target_name(struct bootchooser_target *target);
+struct bootchooser_target *bootchooser_target_by_name(struct bootchooser *bootchooser,
+ const char *name);
+void bootchooser_target_force_boot(struct bootchooser_target *target);
+
+int bootchooser_create_bootentry(struct bootentries *entries);
+
+int bootchooser_target_set_attempts(struct bootchooser_target *target, int attempts);
+int bootchooser_target_set_priority(struct bootchooser_target *target, int priority);
+
+void bootchooser_last_boot_successful(void);
+
+struct bootchooser_target *bootchooser_target_first(struct bootchooser *bootchooser);
+struct bootchooser_target *bootchooser_target_next(struct bootchooser *bootchooser,
+ struct bootchooser_target *cur);
+
+#define bootchooser_for_each_target(bootchooser, target) \
+ for (target = bootchooser_target_first(bootchooser); target; \
+ target = bootchooser_target_next(bootchooser, target))
+
+#endif /* __BOOTCHOOSER_H */
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* [PATCH] arm: Add both .lds files to CLEAN_FILES unconditionally
From: Andrey Smirnov @ 2016-08-24 1:47 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
'clean' target is listed on 'no-dot-config-targets' list in main
Makefile so that conditional statement would yeild the same result
every time. Given how CLEAN_FILES are rm'ed with -f there should be no
harm in specifying them both unconditionally.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/Makefile | 4 ----
1 file changed, 4 deletions(-)
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 55f7248..96ec588 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -314,9 +314,5 @@ endif
common- += $(patsubst %,arch/arm/boards/%/,$(board-))
CLEAN_FILES += include/generated/mach-types.h barebox-flash-image
-
-ifeq ($(CONFIG_CPU_V8), y)
CLEAN_FILES += arch/arm/lib64/barebox.lds
-else
CLEAN_FILES += arch/arm/lib32/barebox.lds
-endif
--
2.5.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* Re: barebox remote control
From: Yegor Yefremov @ 2016-08-23 9:24 UTC (permalink / raw)
To: Jan Lübbe; +Cc: barebox
In-Reply-To: <1471943129.32618.2.camel@pengutronix.de>
On Tue, Aug 23, 2016 at 11:05 AM, Jan Lübbe <jlu@pengutronix.de> wrote:
> On Mo, 2016-08-22 at 15:10 +0200, Yegor Yefremov wrote:
>> What is "bbremote listen" for?
>
> It will setup a RATP connection in the 'listen' state. We used it for
> testing during development. Maybe it could be reused for running
> loopback tests locally.
listen mode could be also interesting to really wait for barebox
coming up (i.e. some kind of callback). I can image following
scenario:
/env/bin/init sends ratp ping to bbremote and, if there is no reaction
for n seconds, then it goes further. Otherwise the script exits.
Yegor
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: barebox remote control
From: Jan Lübbe @ 2016-08-23 9:05 UTC (permalink / raw)
To: Yegor Yefremov; +Cc: barebox
In-Reply-To: <CAGm1_kuH3Z=Tev7Ra129C9QFMCM9ryhhTy_KS5Sji2ykabYXiw@mail.gmail.com>
On Mo, 2016-08-22 at 15:10 +0200, Yegor Yefremov wrote:
> What is "bbremote listen" for?
It will setup a RATP connection in the 'listen' state. We used it for
testing during development. Maybe it could be reused for running
loopback tests locally.
Regards,
Jan
--
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: barebox remote control
From: Yegor Yefremov @ 2016-08-23 9:01 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
In-Reply-To: <CAGm1_kuH3Z=Tev7Ra129C9QFMCM9ryhhTy_KS5Sji2ykabYXiw@mail.gmail.com>
On Mon, Aug 22, 2016 at 3:10 PM, Yegor Yefremov
<yegorslists@googlemail.com> wrote:
> Hi Sascha,
>
> On Mon, Aug 22, 2016 at 11:05 AM, Yegor Yefremov
> <yegorslists@googlemail.com> wrote:
>> On Mon, Aug 22, 2016 at 7:28 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>>> Hi Yegor,
>>>
>>> On Fri, Aug 19, 2016 at 03:45:22PM +0200, Yegor Yefremov wrote:
>>>> Hi Sascha,
>>>>
>>>> On Thu, Aug 18, 2016 at 9:48 AM, Yegor Yefremov
>>>> <yegorslists@googlemail.com> wrote:
>>>> > Are you planning to create a standalone PyPI package for bbremote? It
>>>> > would be very handy.
>>>>
>>>> I'll try to create such a package on my GitHub account and then we
>>>> will see how to proceed. Porting to Python 3 is really funny :-) str
>>>> vs. bytearrays ....
>>>>
>>>> > Have you already contacted pyserial maintainers, so that they could
>>>> > provide a configurable option for RFC2217 related timeout
>>>> > (https://github.com/pyserial/pyserial)?
>>>>
>>>> I'll drop own pyserial and rely on upstream.
>>>
>>> Thanks. We haven't done anything in that direction yet.
>>
>> Take a look at this repo: https://github.com/yegorich/bbremote
>>
>> Following commands are already working in both Py2/3:
>>
>> bbremote ping
>> bbremote run "devinfo"
>> bbremote getenv "global.version"
>>
>> So far there was only one place, where I explicitly make distinction
>> between Py2 and 3. Everything else seems to work well with bytearray
>> (http://www.devdungeon.com/content/working-binary-data-python).
>>
>> TODO:
>>
>> 1. bbremote console works only in Py3, in Py2 it seems to freeze
>> 2. add proper dependencies for setup.py (enum, enum34 for Py2 and
>> crcmod and pyserial for all versions). What minial Py3 version should
>> be supported? Perhaps choose 3.4 as is available on current Debian 8
>> 3. licence: should we keep Barebox licence or move to MIT?
>> 4. more tests
>
> What is "bbremote listen" for?
I've started to import remote and use it from a Python file. It would
be good to add a "silent" option, so that only return value says
something about execution state.
What about renaming bbremote "binary" to bbrcli and renaming remote
package to bbremote? "remote" seems to be too common name.
Yegor
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: Fwd: Shouldn't boot_board be called from boot instead of init?
From: Sascha Hauer @ 2016-08-23 8:13 UTC (permalink / raw)
To: Guillermo Rodriguez Garcia; +Cc: barebox
In-Reply-To: <CABDcavb3DN9Hc-Gr-vYG6aPHBgMYhM__4BzxVAjEqp5MdhB6qA@mail.gmail.com>
On Mon, Aug 22, 2016 at 11:12:55AM +0200, Guillermo Rodriguez Garcia wrote:
> >> > However, I would be glad to get rid of defaultenv-1 rather sooner than
> >> > later.
> >>
> >> Uhm. I actually like defaultenv-1 better than defaultenv-2. Why not
> >> keep both? Everyone can then make their choice :)
> >
> > That's interesting. What do you like better about defaultenv-1? This
> > information could help me to improve defaultenv-2.
>
> I guess it is just a matter of personal preference but I find
> defaultenv-1 easier to understand and easier to manage. With
> defaultenv-1 we basically have just one configuration file to edit
> (/env/config) and optionally init_board and/or boot_board (which are
> not needed in a majority of the cases). So everything you need to
> know/edit/tweak is in /env/config.
>
> With defaultenv-2 the "board configuration" is scattered through a
> number of tiny files, some of which contain just a single value (see
> for example nv/autoboot_timeout or nv/user). I find this more
> difficult to manage -- you need to edit a lot of tiny files instead of
> just one. Also I feel that the flow of control is less obvious for the
> same reason.
>
> I'd say defaultenv-1 feels more "imperative" and defaultenv-2 feels
> more "declarative", and I prefer the former. But I am fully aware that
> this is just a matter of personal preference :)
I understand your concerns but do not share them all. Maybe we can find
a way to either make defaultenv-2 more acceptable for you or to make
defaultenv-1 more appealing to me?
About the number of small files that only contain a single value:
defaultenv-1 was the opposite and that was a problem. Whenever a board
wanted to adjust a single value, say the autoboot timeout, it had to
duplicate a big file and very soon we had many nearly identical copies
of that file and nobody knew what the actual change was. With NV
variables this has become better. I never felt the need though to dig
through the individual /env/nv files, here the 'nv' and 'global'
commands or the 'magicvar' command to much better jobs. Normally you
only have to hand edit /env/nv files when you want to change the default
of a variable for a given board.
Another thing that made another approach than with defaultenv-1
necessary was the variables that contain "net", "disk", "nor", "nand".
This did not scale and was not extensible because you could not pass
some arbitrary file and use it as kernel.
I wonder if defaultenv-1 is not customizable enough and on the other
hand your board does only boot from very special locations, do you need
a generic default environment at all or are you better off using your
own special environment?
Finally, could this be a documentation issue? Could you have another
look at defaultenv-2 and see what is not clear or what needs further
convenience to be better usable?
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: AT91RM9200 hang in atmel_serial_putc
From: Peter Kardos @ 2016-08-22 20:39 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
In-Reply-To: <63af30cc-9fd5-3283-a9f2-9e98e507d581@gmail.com>
Hi Sascha,
I've tested your workaround and it seems to work; the board starts and
attempts
to boot.
Peter
On 8/22/2016 11:00 AM, Peter Kardos wrote:
> During the weekend I've played with this some more...
> It seems that the "breakage" was introduced with v2016.05. This version
> introduced the "exception vector remapping to 0xFFFF*".
> Unfortunately AT91RM9200 has peripherals in this region.
>
> I'll test the patch tonight when i get home.
>
> Peter
>
> On 2016-08-22 08:10, Sascha Hauer wrote:
>> On Thu, Aug 18, 2016 at 11:15:33PM +0200, Peter Kardos wrote:
>>> Hi Sascha,
>>>
>>> I may have something. It seems the memory (MMU?) gets "messed" up;
>>>
>>> Reading the debug uart registers (v2015.07) gives reasonable
>>> results, like
>>> (gdb) x/32w 0xfffff200
>>> 0xfffff200: 0x00000000 0x00000800 0x00000000 0x00000000
>>> 0xfffff210: 0x00000000 0x40001a1a 0x00000000 0x00000000
>>> 0xfffff220: 0x00000021 0x00000000 0x00000000 0x00000000
>>> 0xfffff230: 0x00000000 0x00000000 0x00000000 0x00000000
>>> 0xfffff240: 0x09290781 0x00000000 0x00000000 0x00000000
>>>
>>> However the content from v2016.08 gives
>>>
>>> 0xFFFFF200 D78D7E1F F1139ADE 413E0FE5 BBFB6DF2
>>> 0xFFFFF210 7D78666E 79CBDEA6 8FB2CB03 BEF6C2B7
>>> 0xFFFFF220 C9071D17 FA1EFA2D C4BCD95E 27D73C7C
>>> 0xFFFFF230 727C3437 DFBDEBED 69C45C2A 7F5958F6
>>> 0xFFFFF240 834B237E F8B8A211 1AC74D66 FAE06274
>> Uh, this indeed seems to be messed up by the MMU, more specifically
>> during setup of the vector table. Could you try the attached patch?
>> It's not a solution, but is a clear indication that the bug is in this
>> area.
>>
>> Sascha
>>
>> ---------------------------8<--------------------------------
>>
>> From eb66f09db694a0bc1fc88cde8d86e47faf6debf9 Mon Sep 17 00:00:00 2001
>> From: Sascha Hauer <s.hauer@pengutronix.de>
>> Date: Mon, 22 Aug 2016 08:05:38 +0200
>> Subject: [PATCH] ARM: Disable vector table (tmp)
>>
>> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>> ---
>> arch/arm/cpu/mmu.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
>> index a31bce4..fc26077 100644
>> --- a/arch/arm/cpu/mmu.c
>> +++ b/arch/arm/cpu/mmu.c
>> @@ -289,6 +289,8 @@ static void create_vector_table(unsigned long adr)
>> u32 *exc;
>> int idx;
>> + return;
>> +
>> vectors_sdram = request_sdram_region("vector table", adr, SZ_4K);
>> if (vectors_sdram) {
>> /*
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* [PATCH] Call boot_board from boot, not from init.
From: Guillermo Rodriguez @ 2016-08-22 13:45 UTC (permalink / raw)
To: barebox; +Cc: grodriguez
In-Reply-To: <20160822054521.GU20657@pengutronix.de>
From: grodriguez <guille.rodriguez@gmail.com>
This ensures that any board-specific code that must be run at
boot time will be run both when autobooting and when manually
running the 'boot' command from the console.
Signed-off-by: Guillermo Rodriguez <guille.rodriguez@gmail.com>
---
defaultenv/defaultenv-1/bin/boot | 4 ++++
defaultenv/defaultenv-1/bin/init | 5 ++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/defaultenv/defaultenv-1/bin/boot b/defaultenv/defaultenv-1/bin/boot
index c17ccdb..a5d6596 100644
--- a/defaultenv/defaultenv-1/bin/boot
+++ b/defaultenv/defaultenv-1/bin/boot
@@ -2,6 +2,10 @@
. /env/config
+if [ -f /env/bin/boot_board ]; then
+ . /env/bin/boot_board
+fi
+
if [ x$kernel_loc = xnet ]; then
kernel_loc=tftp
fi
diff --git a/defaultenv/defaultenv-1/bin/init b/defaultenv/defaultenv-1/bin/init
index a55d293..2dcddbe 100644
--- a/defaultenv/defaultenv-1/bin/init
+++ b/defaultenv/defaultenv-1/bin/init
@@ -23,9 +23,8 @@ if [ -f /env/bin/init_board ]; then
fi
echo -e "\e[?25h"
-if [ -f /env/bin/boot_board ]; then
- . /env/bin/boot_board
-elif [ -n $autoboot_timeout ]; then
+
+if [ -n $autoboot_timeout ]; then
echo -n "Hit any key to stop autoboot: "
timeout -a $autoboot_timeout
if [ $? != 0 ]; then
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* Re: barebox remote control
From: Yegor Yefremov @ 2016-08-22 13:10 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
In-Reply-To: <CAGm1_ks9wTMiP2EBoO9BKGkckuTRqkinaazxWXTkNrJKSc7b=w@mail.gmail.com>
Hi Sascha,
On Mon, Aug 22, 2016 at 11:05 AM, Yegor Yefremov
<yegorslists@googlemail.com> wrote:
> On Mon, Aug 22, 2016 at 7:28 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> Hi Yegor,
>>
>> On Fri, Aug 19, 2016 at 03:45:22PM +0200, Yegor Yefremov wrote:
>>> Hi Sascha,
>>>
>>> On Thu, Aug 18, 2016 at 9:48 AM, Yegor Yefremov
>>> <yegorslists@googlemail.com> wrote:
>>> > Are you planning to create a standalone PyPI package for bbremote? It
>>> > would be very handy.
>>>
>>> I'll try to create such a package on my GitHub account and then we
>>> will see how to proceed. Porting to Python 3 is really funny :-) str
>>> vs. bytearrays ....
>>>
>>> > Have you already contacted pyserial maintainers, so that they could
>>> > provide a configurable option for RFC2217 related timeout
>>> > (https://github.com/pyserial/pyserial)?
>>>
>>> I'll drop own pyserial and rely on upstream.
>>
>> Thanks. We haven't done anything in that direction yet.
>
> Take a look at this repo: https://github.com/yegorich/bbremote
>
> Following commands are already working in both Py2/3:
>
> bbremote ping
> bbremote run "devinfo"
> bbremote getenv "global.version"
>
> So far there was only one place, where I explicitly make distinction
> between Py2 and 3. Everything else seems to work well with bytearray
> (http://www.devdungeon.com/content/working-binary-data-python).
>
> TODO:
>
> 1. bbremote console works only in Py3, in Py2 it seems to freeze
> 2. add proper dependencies for setup.py (enum, enum34 for Py2 and
> crcmod and pyserial for all versions). What minial Py3 version should
> be supported? Perhaps choose 3.4 as is available on current Debian 8
> 3. licence: should we keep Barebox licence or move to MIT?
> 4. more tests
What is "bbremote listen" for?
Yegor
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: Fwd: Shouldn't boot_board be called from boot instead of init?
From: Holger Schurig @ 2016-08-22 9:46 UTC (permalink / raw)
To: Guillermo Rodriguez Garcia, Sascha Hauer; +Cc: barebox
In-Reply-To: <CABDcavb3DN9Hc-Gr-vYG6aPHBgMYhM__4BzxVAjEqp5MdhB6qA@mail.gmail.com>
Guillermo Rodriguez Garcia <guille.rodriguez@gmail.com> writes:
> With defaultenv-2 the "board configuration" is scattered through a
> number of tiny files, some of which contain just a single value (see
> for example nv/autoboot_timeout or nv/user). I find this more
> difficult to manage -- you need to edit a lot of tiny files instead of
> just one. Also I feel that the flow of control is less obvious for the
> same reason.
Hi,
on my device I use defaultenv-1 for the same reason. Basically I just
have one env/bin/init and one env/config file and that's it. And the
env/config one is even so small that I could fold it into env/bin/init.
This even more so as my device is "set in stone", e.g. there is no SPI
EEPROM or other means (partition) to store an environment. What comes
with the compiled barebox is the environment.
Having things in one place and not scattered around makes things visible
at a glance.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: Fwd: Shouldn't boot_board be called from boot instead of init?
From: Guillermo Rodriguez Garcia @ 2016-08-22 9:12 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
In-Reply-To: <20160822054521.GU20657@pengutronix.de>
Hi Sascha,
2016-08-22 7:45 GMT+02:00 Sascha Hauer <s.hauer@pengutronix.de>:
> On Thu, Aug 18, 2016 at 10:02:48AM +0200, Guillermo Rodriguez Garcia wrote:
>> Hello,
>>
>> 2016-08-18 8:31 GMT+02:00 Sascha Hauer <s.hauer@pengutronix.de>:
>> > Hi,
>> >
>> > On Tue, Aug 16, 2016 at 10:42:32AM +0200, Guillermo Rodriguez Garcia wrote:
>> >> Hello all,
>> >>
>> >> Currently, for defaultenv v1, the /env/bin/boot_board script is called
>> >> from /env/bin/init.
>> >>
>> >> However this means boot_board will not be run if booting manually (by
>> >> running 'boot' from the barebox console).
>> >>
>> >> Shouldn't this script be called from /env/bin/boot instead? If a board
>> >> needs any specific stuff to be done when booting, this probably
>> >> applies both when autobooting and when booting manually (otherwise,
>> >> anything that only applies only when autobooting could also be done
>> >> from init_board instead of boot_board).
>> >
>> > The only boot_board script we have is
>> > arch/arm/boards/at91sam9m10g45ek/env/bin/boot_board. Here a menu is
>> > built which I think makes sense at that stage and not at init_board.
>>
>> The thing is, if boot_board is called from init, then it will not be
>> called if autoboot is interrupted and you later boot manually with the
>> boot command.
>
> I think you are right, just go ahead with the suggested change. With
> that a menu will be shown on the at91sam9m10g45ek when doing a manual
> 'boot' which may even be the desired behaviour.
Perfect. Will do so.
>> > However, I would be glad to get rid of defaultenv-1 rather sooner than
>> > later.
>>
>> Uhm. I actually like defaultenv-1 better than defaultenv-2. Why not
>> keep both? Everyone can then make their choice :)
>
> That's interesting. What do you like better about defaultenv-1? This
> information could help me to improve defaultenv-2.
I guess it is just a matter of personal preference but I find
defaultenv-1 easier to understand and easier to manage. With
defaultenv-1 we basically have just one configuration file to edit
(/env/config) and optionally init_board and/or boot_board (which are
not needed in a majority of the cases). So everything you need to
know/edit/tweak is in /env/config.
With defaultenv-2 the "board configuration" is scattered through a
number of tiny files, some of which contain just a single value (see
for example nv/autoboot_timeout or nv/user). I find this more
difficult to manage -- you need to edit a lot of tiny files instead of
just one. Also I feel that the flow of control is less obvious for the
same reason.
I'd say defaultenv-1 feels more "imperative" and defaultenv-2 feels
more "declarative", and I prefer the former. But I am fully aware that
this is just a matter of personal preference :)
Guillermo
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: barebox remote control
From: Yegor Yefremov @ 2016-08-22 9:05 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
In-Reply-To: <20160822052808.GT20657@pengutronix.de>
On Mon, Aug 22, 2016 at 7:28 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> Hi Yegor,
>
> On Fri, Aug 19, 2016 at 03:45:22PM +0200, Yegor Yefremov wrote:
>> Hi Sascha,
>>
>> On Thu, Aug 18, 2016 at 9:48 AM, Yegor Yefremov
>> <yegorslists@googlemail.com> wrote:
>> > Are you planning to create a standalone PyPI package for bbremote? It
>> > would be very handy.
>>
>> I'll try to create such a package on my GitHub account and then we
>> will see how to proceed. Porting to Python 3 is really funny :-) str
>> vs. bytearrays ....
>>
>> > Have you already contacted pyserial maintainers, so that they could
>> > provide a configurable option for RFC2217 related timeout
>> > (https://github.com/pyserial/pyserial)?
>>
>> I'll drop own pyserial and rely on upstream.
>
> Thanks. We haven't done anything in that direction yet.
Take a look at this repo: https://github.com/yegorich/bbremote
Following commands are already working in both Py2/3:
bbremote ping
bbremote run "devinfo"
bbremote getenv "global.version"
So far there was only one place, where I explicitly make distinction
between Py2 and 3. Everything else seems to work well with bytearray
(http://www.devdungeon.com/content/working-binary-data-python).
TODO:
1. bbremote console works only in Py3, in Py2 it seems to freeze
2. add proper dependencies for setup.py (enum, enum34 for Py2 and
crcmod and pyserial for all versions). What minial Py3 version should
be supported? Perhaps choose 3.4 as is available on current Debian 8
3. licence: should we keep Barebox licence or move to MIT?
4. more tests
Yegor
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: AT91RM9200 hang in atmel_serial_putc
From: Peter Kardos @ 2016-08-22 9:00 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
In-Reply-To: <20160822061049.GC20657@pengutronix.de>
During the weekend I've played with this some more...
It seems that the "breakage" was introduced with v2016.05. This version
introduced the "exception vector remapping to 0xFFFF*".
Unfortunately AT91RM9200 has peripherals in this region.
I'll test the patch tonight when i get home.
Peter
On 2016-08-22 08:10, Sascha Hauer wrote:
> On Thu, Aug 18, 2016 at 11:15:33PM +0200, Peter Kardos wrote:
>> Hi Sascha,
>>
>> I may have something. It seems the memory (MMU?) gets "messed" up;
>>
>> Reading the debug uart registers (v2015.07) gives reasonable results, like
>> (gdb) x/32w 0xfffff200
>> 0xfffff200: 0x00000000 0x00000800 0x00000000 0x00000000
>> 0xfffff210: 0x00000000 0x40001a1a 0x00000000 0x00000000
>> 0xfffff220: 0x00000021 0x00000000 0x00000000 0x00000000
>> 0xfffff230: 0x00000000 0x00000000 0x00000000 0x00000000
>> 0xfffff240: 0x09290781 0x00000000 0x00000000 0x00000000
>>
>> However the content from v2016.08 gives
>>
>> 0xFFFFF200 D78D7E1F F1139ADE 413E0FE5 BBFB6DF2
>> 0xFFFFF210 7D78666E 79CBDEA6 8FB2CB03 BEF6C2B7
>> 0xFFFFF220 C9071D17 FA1EFA2D C4BCD95E 27D73C7C
>> 0xFFFFF230 727C3437 DFBDEBED 69C45C2A 7F5958F6
>> 0xFFFFF240 834B237E F8B8A211 1AC74D66 FAE06274
> Uh, this indeed seems to be messed up by the MMU, more specifically
> during setup of the vector table. Could you try the attached patch?
> It's not a solution, but is a clear indication that the bug is in this
> area.
>
> Sascha
>
> ---------------------------8<--------------------------------
>
> From eb66f09db694a0bc1fc88cde8d86e47faf6debf9 Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Mon, 22 Aug 2016 08:05:38 +0200
> Subject: [PATCH] ARM: Disable vector table (tmp)
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> arch/arm/cpu/mmu.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
> index a31bce4..fc26077 100644
> --- a/arch/arm/cpu/mmu.c
> +++ b/arch/arm/cpu/mmu.c
> @@ -289,6 +289,8 @@ static void create_vector_table(unsigned long adr)
> u32 *exc;
> int idx;
>
> + return;
> +
> vectors_sdram = request_sdram_region("vector table", adr, SZ_4K);
> if (vectors_sdram) {
> /*
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
* Re: AT91RM9200 hang in atmel_serial_putc
From: Sascha Hauer @ 2016-08-22 6:10 UTC (permalink / raw)
To: Peter Kardos; +Cc: barebox
In-Reply-To: <8b40b96f-0414-4566-1215-e1d6bb7abab1@gmail.com>
On Thu, Aug 18, 2016 at 11:15:33PM +0200, Peter Kardos wrote:
> Hi Sascha,
>
> I may have something. It seems the memory (MMU?) gets "messed" up;
>
> Reading the debug uart registers (v2015.07) gives reasonable results, like
> (gdb) x/32w 0xfffff200
> 0xfffff200: 0x00000000 0x00000800 0x00000000 0x00000000
> 0xfffff210: 0x00000000 0x40001a1a 0x00000000 0x00000000
> 0xfffff220: 0x00000021 0x00000000 0x00000000 0x00000000
> 0xfffff230: 0x00000000 0x00000000 0x00000000 0x00000000
> 0xfffff240: 0x09290781 0x00000000 0x00000000 0x00000000
>
> However the content from v2016.08 gives
>
> 0xFFFFF200 D78D7E1F F1139ADE 413E0FE5 BBFB6DF2
> 0xFFFFF210 7D78666E 79CBDEA6 8FB2CB03 BEF6C2B7
> 0xFFFFF220 C9071D17 FA1EFA2D C4BCD95E 27D73C7C
> 0xFFFFF230 727C3437 DFBDEBED 69C45C2A 7F5958F6
> 0xFFFFF240 834B237E F8B8A211 1AC74D66 FAE06274
Uh, this indeed seems to be messed up by the MMU, more specifically
during setup of the vector table. Could you try the attached patch?
It's not a solution, but is a clear indication that the bug is in this
area.
Sascha
---------------------------8<--------------------------------
From eb66f09db694a0bc1fc88cde8d86e47faf6debf9 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Mon, 22 Aug 2016 08:05:38 +0200
Subject: [PATCH] ARM: Disable vector table (tmp)
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/cpu/mmu.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index a31bce4..fc26077 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -289,6 +289,8 @@ static void create_vector_table(unsigned long adr)
u32 *exc;
int idx;
+ return;
+
vectors_sdram = request_sdram_region("vector table", adr, SZ_4K);
if (vectors_sdram) {
/*
--
2.8.1
--
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply related
* Re: [PATCH 1/2] scripts: imx-usb-loader: enable DCD 16-bit write for hdr v1
From: Sascha Hauer @ 2016-08-22 6:02 UTC (permalink / raw)
To: Alexander Kurz; +Cc: barebox
In-Reply-To: <1471810717-1371-1-git-send-email-akurz@blala.de>
On Sun, Aug 21, 2016 at 10:18:36PM +0200, Alexander Kurz wrote:
> Do some cleanup which enables DCDv1 16 bit write access as side effect.
>
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
> scripts/imx/imx-usb-loader.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
> index 1732497..9f25ca6 100644
> --- a/scripts/imx/imx-usb-loader.c
> +++ b/scripts/imx/imx-usb-loader.c
> @@ -889,16 +889,11 @@ static int write_dcd_table_old(const struct imx_flash_header *hdr,
>
> switch (type) {
> case 1:
> - if (verbose > 1)
> - printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
> - err = write_memory(addr, val, 1);
> - if (err < 0)
> - return err;
> - break;
> + case 2:
> case 4:
> if (verbose > 1)
> printf("type=%08x *0x%08x = 0x%08x\n", type, addr, val);
> - err = write_memory(addr, val, 4);
> + err = write_memory(addr, val, type);
> if (err < 0)
> return err;
> break;
> --
> 2.1.4
>
>
> _______________________________________________
> 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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox