From 64bf4200132a538d5598c441fb190a347bc85d0f Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 15 Oct 2013 19:38:22 +0200 Subject: [PATCH 01/23] ARM: rpi: fix tty device name in bootargs-base Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/boards/raspberry-pi/env/init/bootargs-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/boards/raspberry-pi/env/init/bootargs-base b/arch/arm/boards/raspberry-pi/env/init/bootargs-base index d86975406..4dda5501e 100644 --- a/arch/arm/boards/raspberry-pi/env/init/bootargs-base +++ b/arch/arm/boards/raspberry-pi/env/init/bootargs-base @@ -5,4 +5,4 @@ if [ "$1" = menu ]; then exit fi -global.linux.bootargs.base="console=ttymxc0,115200" +global.linux.bootargs.base="console=ttyAMA0,115200" From 43efd0e84f96d321655ccab5d8507479414aa333 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 15 Oct 2013 19:38:23 +0200 Subject: [PATCH 02/23] ARM: rpi: fix reading of the EMMC clock for CONFIG_MMU Add explicit flushing to prevent the 50MHz fallback. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- drivers/mci/mci-bcm2835.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c index abd38a35c..576e8da6f 100644 --- a/drivers/mci/mci-bcm2835.c +++ b/drivers/mci/mci-bcm2835.c @@ -28,6 +28,7 @@ * Author: Wilhelm Lundgren */ +#include #include #include #include @@ -471,7 +472,7 @@ int bcm2835_mci_reset(struct mci_host *mci, struct device_d *mci_dev) static u32 bcm2835_mci_get_emmc_clock(struct msg_get_clock_rate *clk_data) { u32 val; - struct bcm2835_mbox_regs *regs = + struct bcm2835_mbox_regs __iomem *regs = (struct bcm2835_mbox_regs *) BCM2835_MBOX_PHYSADDR; /*Read out old msg*/ @@ -489,6 +490,7 @@ static u32 bcm2835_mci_get_emmc_clock(struct msg_get_clock_rate *clk_data) break; } val = BCM2835_MBOX_PROP_CHAN + ((u32) &clk_data->hdr); + dma_flush_range((u32)clk_data, (u32)clk_data + sizeof(*clk_data)); writel(val, ®s->write); while (true) { @@ -504,6 +506,9 @@ static u32 bcm2835_mci_get_emmc_clock(struct msg_get_clock_rate *clk_data) if ((val & 0x0F) == BCM2835_MBOX_PROP_CHAN) break; } + + dma_inv_range((u32)clk_data, (u32)clk_data + sizeof(*clk_data)); + if ((val & ~0x0F) == ((u32) &clk_data->hdr)) if (clk_data->get_clock_rate.tag_hdr.val_len & BCM2835_MBOX_TAG_VAL_LEN_RESPONSE) From 272516419479e5266d1e3ea14823d35283492efc Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 15 Oct 2013 10:35:42 +0200 Subject: [PATCH 03/23] mci: bcm2835: Add detect callback support for hardware device Signed-off-by: Sascha Hauer --- drivers/mci/mci-bcm2835.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c index 576e8da6f..2ffdeecc0 100644 --- a/drivers/mci/mci-bcm2835.c +++ b/drivers/mci/mci-bcm2835.c @@ -516,6 +516,13 @@ static u32 bcm2835_mci_get_emmc_clock(struct msg_get_clock_rate *clk_data) return 0; } +static int bcm2835_mci_detect(struct device_d *dev) +{ + struct bcm2835_mci_host *host = dev->priv; + + return mci_detect_card(&host->mci); +} + static int bcm2835_mci_probe(struct device_d *hw_dev) { struct bcm2835_mci_host *host; @@ -566,6 +573,9 @@ static int bcm2835_mci_probe(struct device_d *hw_dev) host->mci.f_min = MIN_FREQ; host->mci.f_max = host->max_clock; + hw_dev->priv = host; + hw_dev->detect = bcm2835_mci_detect, + /* * The Arasan has a bugette whereby it may lose the content of * successive writes to registers that are within two SD-card clock From 16dd5e5603e281710f7f5a260bcdd16bd43bb5a8 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 15 Oct 2013 10:36:02 +0200 Subject: [PATCH 04/23] ARM: rpi: Update defconfig Enable MMU, stack dumps and a lot of other features Signed-off-by: Sascha Hauer --- arch/arm/configs/rpi_defconfig | 45 ++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/arch/arm/configs/rpi_defconfig b/arch/arm/configs/rpi_defconfig index 014e28c73..76029d025 100644 --- a/arch/arm/configs/rpi_defconfig +++ b/arch/arm/configs/rpi_defconfig @@ -1,41 +1,66 @@ CONFIG_ARCH_BCM2835=y -CONFIG_GPIO_BCM2835=y +CONFIG_AEABI=y CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y +CONFIG_ARM_UNWIND=y +CONFIG_MMU=y +CONFIG_MALLOC_TLSF=y +CONFIG_KALLSYMS=y CONFIG_PROMPT="R-Pi> " CONFIG_LONGHELP=y -CONFIG_GLOB=y CONFIG_HUSH_FANCY_PROMPT=y CONFIG_CMDLINE_EDITING=y CONFIG_AUTO_COMPLETE=y CONFIG_MENU=y -CONFIG_PARTITION=y +CONFIG_BLSPEC=y CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/raspberry-pi/env" CONFIG_CMD_EDIT=y CONFIG_CMD_SLEEP=y +CONFIG_CMD_MSLEEP=y CONFIG_CMD_SAVEENV=y -CONFIG_CMD_LOADENV=y CONFIG_CMD_EXPORT=y CONFIG_CMD_PRINTENV=y CONFIG_CMD_READLINE=y +CONFIG_CMD_LET=y CONFIG_CMD_MENU=y CONFIG_CMD_MENU_MANAGEMENT=y CONFIG_CMD_PASSWD=y +CONFIG_CMD_TIME=y +CONFIG_CMD_LN=y +CONFIG_CMD_FILETYPE=y CONFIG_CMD_ECHO_E=y CONFIG_CMD_LOADB=y CONFIG_CMD_MEMINFO=y -CONFIG_CMD_MTEST=y -CONFIG_CMD_MTEST_ALTERNATIVE=y -CONFIG_CMD_BOOTM_ZLIB=y -CONFIG_CMD_BOOTM_BZLIB=y +CONFIG_CMD_IOMEM=y +CONFIG_CMD_MM=y +CONFIG_CMD_CRC=y +CONFIG_CMD_CRC_CMP=y +CONFIG_CMD_MD5SUM=y CONFIG_CMD_BOOTM_SHOW_TYPE=y +CONFIG_CMD_BOOTM_VERBOSE=y +CONFIG_CMD_BOOTM_INITRD=y +CONFIG_CMD_BOOTM_OFTREE=y +CONFIG_CMD_UIMAGE=y CONFIG_CMD_RESET=y -CONFIG_CMD_CLK=y CONFIG_CMD_GO=y +CONFIG_CMD_OFTREE=y +CONFIG_CMD_OF_PROPERTY=y +CONFIG_CMD_OF_NODE=y CONFIG_CMD_TIMEOUT=y CONFIG_CMD_PARTITION=y -CONFIG_CMD_UNCOMPRESS=y +CONFIG_CMD_MAGICVAR=y +CONFIG_CMD_MAGICVAR_HELP=y CONFIG_CMD_GPIO=y +CONFIG_CMD_UNCOMPRESS=y +CONFIG_CMD_CLK=y +CONFIG_CMD_DETECT=y CONFIG_SERIAL_AMBA_PL011=y +CONFIG_MCI=y +CONFIG_MCI_BCM2835=y +CONFIG_GPIO_BCM2835=y +CONFIG_FS_EXT4=y +CONFIG_FS_FAT=y +CONFIG_FS_FAT_WRITE=y +CONFIG_FS_FAT_LFN=y CONFIG_SHA1=y CONFIG_SHA256=y From 297661763584f6e22470b9225b0f2494b1abc6c0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 15 Oct 2013 12:48:53 +0200 Subject: [PATCH 05/23] ARM: rpi: add SD card environment support Similar to the OMAP boards mount the SD card to /boot and expect the environment as /boot/barebox.env Signed-off-by: Sascha Hauer --- arch/arm/boards/raspberry-pi/rpi.c | 33 ++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c index d4912ccdc..971a603bf 100644 --- a/arch/arm/boards/raspberry-pi/rpi.c +++ b/arch/arm/boards/raspberry-pi/rpi.c @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include #include @@ -37,11 +40,37 @@ static int rpi_console_init(void) } console_initcall(rpi_console_init); +static int rpi_env_init(void) +{ + struct stat s; + const char *diskdev = "/dev/disk0.0"; + int ret; + + device_detect_by_name("mci0"); + + ret = stat(diskdev, &s); + if (ret) { + printf("no %s. using default env\n", diskdev); + return 0; + } + + mkdir("/boot", 0666); + ret = mount(diskdev, "fat", "/boot"); + if (ret) { + printf("failed to mount %s\n", diskdev); + return 0; + } + + default_environment_path = "/boot/barebox.env"; + + return 0; +} + static int rpi_devices_init(void) { armlinux_set_architecture(MACH_TYPE_BCM2708); armlinux_set_bootparams((void *)(0x00000100)); + rpi_env_init(); return 0; } - -device_initcall(rpi_devices_init); +late_initcall(rpi_devices_init); From 5611ccb0422ba938519c20c4f7ce08c7c940b427 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:18:42 +0200 Subject: [PATCH 06/23] ARM: cache: restore cache functions from the PBL When using CONFIG_MMU_EARLY combined with CONFIG_PBL_IMAGE, the barebox setup reuses the MMU setup from the PBL, but doesn't setup the cache functions. Set these up to guarantee proper early cache handing before mmu_initcall(). Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/cpu/start.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c index f8d343f4e..f0a7df37b 100644 --- a/arch/arm/cpu/start.c +++ b/arch/arm/cpu/start.c @@ -70,7 +70,9 @@ static noinline __noreturn void __start(uint32_t membase, uint32_t memsize, endmem &= ~0x3fff; endmem -= SZ_16K; /* ttb */ - if (!IS_ENABLED(CONFIG_PBL_IMAGE)) { + if (IS_ENABLED(CONFIG_PBL_IMAGE)) { + arm_set_cache_functions(); + } else { arm_early_mmu_cache_invalidate(); mmu_early_enable(membase, memsize, endmem); } From 0fdd91d92b7eac2161dbcec2032d055eb2b90b04 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:47 +0200 Subject: [PATCH 07/23] ARM: cache: do not crash when the MMU isn't yet setup Drivers currently cannot implement explicit cache handling and rely on running the same code before and after mmu_initcall() without crashing. Depending on the chosen config options, the cache functions are not yet setup and using them early on ends in a null pointer dereference. The RPi's mailbox driver is such a case; it requires cache handling once the MMU is fully set up and yet the RPi setup needs to use the driver to get the memory size before mem_initcall() and hence mmu_initcall(). Fix this by checking the cache_fns pointer before dereferencing it. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/cpu/cache.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm/cpu/cache.c b/arch/arm/cpu/cache.c index 7aab55b6b..223e3089b 100644 --- a/arch/arm/cpu/cache.c +++ b/arch/arm/cpu/cache.c @@ -41,32 +41,38 @@ DEFINE_CPU_FNS(v7) void __dma_clean_range(unsigned long start, unsigned long end) { - cache_fns->dma_clean_range(start, end); + if (cache_fns) + cache_fns->dma_clean_range(start, end); } void __dma_flush_range(unsigned long start, unsigned long end) { - cache_fns->dma_flush_range(start, end); + if (cache_fns) + cache_fns->dma_flush_range(start, end); } void __dma_inv_range(unsigned long start, unsigned long end) { - cache_fns->dma_inv_range(start, end); + if (cache_fns) + cache_fns->dma_inv_range(start, end); } void __mmu_cache_on(void) { - cache_fns->mmu_cache_on(); + if (cache_fns) + cache_fns->mmu_cache_on(); } void __mmu_cache_off(void) { - cache_fns->mmu_cache_off(); + if (cache_fns) + cache_fns->mmu_cache_off(); } void __mmu_cache_flush(void) { - cache_fns->mmu_cache_flush(); + if (cache_fns) + cache_fns->mmu_cache_flush(); } int arm_set_cache_functions(void) From 55f6869c33e62f6ba253e4fa6fcb9724288a0deb Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:48 +0200 Subject: [PATCH 08/23] common: add a macro to align an array on the stack The macro can be used for temporary stack buffers which need to meet a minimum alignment requirement. This will be used by bcm2835 mailbox users, where all buffers need to be aligned. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- include/common.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/common.h b/include/common.h index 0f0ba08c4..00f1642cd 100644 --- a/include/common.h +++ b/include/common.h @@ -192,6 +192,17 @@ int run_shell(void); #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x) +/* + * The STACK_ALIGN_ARRAY macro is used to allocate a buffer on the stack that + * meets a minimum alignment requirement. + * + * Note that the size parameter is the number of array elements to allocate, + * not the number of bytes. + */ +#define STACK_ALIGN_ARRAY(type, name, size, align) \ + char __##name[sizeof(type) * (size) + (align) - 1]; \ + type *name = (type *)ALIGN((uintptr_t)__##name, align) + /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. From 4754cc79f619ebb08c7e2a1040539a0732ec2993 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:49 +0200 Subject: [PATCH 09/23] ARM: bcm2835: cleanup clock registering Sync exposed names while at it. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/mach-bcm2835/core.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c index 906e4344d..6835960e8 100644 --- a/arch/arm/mach-bcm2835/core.c +++ b/arch/arm/mach-bcm2835/core.c @@ -32,37 +32,20 @@ #include #include -enum brcm_clks { - dummy, clk_ref_3, clk_ref_1, clks_max -}; - -static struct clk *clks[clks_max]; - static int bcm2835_clk_init(void) { - int ret; + struct clk *clk; - clks[dummy] = clk_fixed("dummy", 0); - clks[clk_ref_3] = clk_fixed("ref3", 3 * 1000 * 1000); - clks[clk_ref_1] = clk_fixed("ref1", 1 * 1000 * 1000); + clk = clk_fixed("apb_pclk", 0); + clk_register_clkdev(clk, "apb_pclk", NULL); - ret = clk_register_clkdev(clks[dummy], "apb_pclk", NULL); - if (ret) - goto clk_err; + clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000); + clk_register_clkdev(clk, NULL, "uart0-pl0110"); - ret = clk_register_clkdev(clks[clk_ref_3], NULL, "uart0-pl0110"); - if (ret) - goto clk_err; - - ret = clk_register_clkdev(clks[clk_ref_1], NULL, "bcm2835-cs"); - if (ret) - goto clk_err; + clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000); + clk_register_clkdev(clk, NULL, "bcm2835-cs"); return 0; - -clk_err: - return ret; - } postcore_initcall(bcm2835_clk_init); From 233718d8c514f0e8cbf3770ee8ad2dbc6f1cba1c Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:50 +0200 Subject: [PATCH 10/23] ARM: bcm2835: register the clocksource driver earlier RPi's mailbox driver is used early and it needs clock functions to handle timeouts. Promote to a core_initcall(). Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- drivers/clocksource/bcm2835.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clocksource/bcm2835.c b/drivers/clocksource/bcm2835.c index d5fe0f03a..d1df3d2b2 100644 --- a/drivers/clocksource/bcm2835.c +++ b/drivers/clocksource/bcm2835.c @@ -87,4 +87,4 @@ static int bcm2835_cs_init(void) { return platform_driver_register(&bcm2835_cs_driver); } -coredevice_initcall(bcm2835_cs_init); +core_initcall(bcm2835_cs_init); From d841f42664c97098509e72043337462aeebe5898 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:51 +0200 Subject: [PATCH 11/23] ARM: bcm2835: register the clocksource device earlier RPi's mailbox driver is used early and it needs clock functions to handle timeouts. Register the driver straight after its clkdev. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/mach-bcm2835/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c index 6835960e8..cba7bf681 100644 --- a/arch/arm/mach-bcm2835/core.c +++ b/arch/arm/mach-bcm2835/core.c @@ -45,6 +45,8 @@ static int bcm2835_clk_init(void) clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000); clk_register_clkdev(clk, NULL, "bcm2835-cs"); + add_generic_device("bcm2835-cs", DEVICE_ID_SINGLE, NULL, BCM2835_ST_BASE, 0x1C, IORESOURCE_MEM, NULL); + return 0; } postcore_initcall(bcm2835_clk_init); @@ -52,7 +54,6 @@ postcore_initcall(bcm2835_clk_init); static int bcm2835_dev_init(void) { add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, IORESOURCE_MEM, NULL); - add_generic_device("bcm2835-cs", DEVICE_ID_SINGLE, NULL, BCM2835_ST_BASE, 0x1C, IORESOURCE_MEM, NULL); add_generic_device("bcm2835_mci", 0, NULL, BCM2835_EMMC_BASE, 0xFC, IORESOURCE_MEM, NULL); return 0; } From 76cb4002af394c9179a0802f4b42edb897f7f793 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:52 +0200 Subject: [PATCH 12/23] ARM: bcm2835: add a mailbox driver for VideoCore This allows exchanging data with the on-SoC GPU. Based on U-Boot code by Stephen Warren. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/mach-bcm2835/Makefile | 2 +- arch/arm/mach-bcm2835/include/mach/mbox.h | 420 ++++++++++++++++++++++ arch/arm/mach-bcm2835/mbox.c | 152 ++++++++ 3 files changed, 573 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-bcm2835/include/mach/mbox.h create mode 100644 arch/arm/mach-bcm2835/mbox.c diff --git a/arch/arm/mach-bcm2835/Makefile b/arch/arm/mach-bcm2835/Makefile index 820eb10ac..940f98cbc 100644 --- a/arch/arm/mach-bcm2835/Makefile +++ b/arch/arm/mach-bcm2835/Makefile @@ -1 +1 @@ -obj-y += core.o +obj-y += core.o mbox.o diff --git a/arch/arm/mach-bcm2835/include/mach/mbox.h b/arch/arm/mach-bcm2835/include/mach/mbox.h new file mode 100644 index 000000000..6c3638953 --- /dev/null +++ b/arch/arm/mach-bcm2835/include/mach/mbox.h @@ -0,0 +1,420 @@ +/* + * based on U-Boot code + * + * (C) Copyright 2012 Stephen Warren + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _BCM2835_MBOX_H +#define _BCM2835_MBOX_H + +#include + +/* + * The BCM2835 SoC contains (at least) two CPUs; the VideoCore (a/k/a "GPU") + * and the ARM CPU. The ARM CPU is often thought of as the main CPU. + * However, the VideoCore actually controls the initial SoC boot, and hides + * much of the hardware behind a protocol. This protocol is transported + * using the SoC's mailbox hardware module. + * + * The mailbox hardware supports passing 32-bit values back and forth. + * Presumably by software convention of the firmware, the bottom 4 bits of the + * value are used to indicate a logical channel, and the upper 28 bits are the + * actual payload. Various channels exist using these simple raw messages. See + * https://github.com/raspberrypi/firmware/wiki/Mailboxes for a list. As an + * example, the messages on the power management channel are a bitmask of + * devices whose power should be enabled. + * + * The property mailbox channel passes messages that contain the (16-byte + * aligned) ARM physical address of a memory buffer. This buffer is passed to + * the VC for processing, is modified in-place by the VC, and the address then + * passed back to the ARM CPU as the response mailbox message to indicate + * request completion. The buffers have a generic and extensible format; each + * buffer contains a standard header, a list of "tags", and a terminating zero + * entry. Each tag contains an ID indicating its type, and length fields for + * generic parsing. With some limitations, an arbitrary set of tags may be + * combined together into a single message buffer. This file defines structs + * representing the header and many individual tag layouts and IDs. + */ + +/* Raw mailbox HW */ + +#define BCM2835_MBOX_PHYSADDR 0x2000b880 + +struct bcm2835_mbox_regs { + u32 read; + u32 rsvd0[5]; + u32 status; + u32 config; + u32 write; +}; + +#define BCM2835_MBOX_STATUS_WR_FULL 0x80000000 +#define BCM2835_MBOX_STATUS_RD_EMPTY 0x40000000 + +/* Lower 4-bits are channel ID */ +#define BCM2835_CHAN_MASK 0xf +#define BCM2835_MBOX_PACK(chan, data) (((data) & (~BCM2835_CHAN_MASK)) | \ + (chan & BCM2835_CHAN_MASK)) +#define BCM2835_MBOX_UNPACK_CHAN(val) ((val) & BCM2835_CHAN_MASK) +#define BCM2835_MBOX_UNPACK_DATA(val) ((val) & (~BCM2835_CHAN_MASK)) + +/* Property mailbox buffer structures */ + +#define BCM2835_MBOX_PROP_CHAN 8 + +/* All message buffers must start with this header */ +struct bcm2835_mbox_hdr { + u32 buf_size; + u32 code; +}; + +#define BCM2835_MBOX_REQ_CODE 0 +#define BCM2835_MBOX_RESP_CODE_SUCCESS 0x80000000 + +#define BCM2835_MBOX_STACK_ALIGN(type, name) \ + STACK_ALIGN_ARRAY(type, name, 1, BCM2835_CHAN_MASK + 1) + +#define BCM2835_MBOX_INIT_HDR(_m_) { \ + memset((_m_), 0, sizeof(*(_m_))); \ + (_m_)->hdr.buf_size = sizeof(*(_m_)); \ + (_m_)->hdr.code = 0; \ + (_m_)->end_tag = 0; \ + } + +/* + * A message buffer contains a list of tags. Each tag must also start with + * a standardized header. + */ +struct bcm2835_mbox_tag_hdr { + u32 tag; + u32 val_buf_size; + u32 val_len; +}; + +#define BCM2835_MBOX_INIT_TAG(_t_, _id_) { \ + (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \ + (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \ + (_t_)->tag_hdr.val_len = sizeof((_t_)->body.req); \ + } + +#define BCM2835_MBOX_INIT_TAG_NO_REQ(_t_, _id_) { \ + (_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \ + (_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \ + (_t_)->tag_hdr.val_len = 0; \ + } + +/* When responding, the VC sets this bit in val_len to indicate a response */ +#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE 0x80000000 + +/* + * Below we define the ID and struct for many possible tags. This header only + * defines individual tag structs, not entire message structs, since in + * general an arbitrary set of tags may be combined into a single message. + * Clients of the mbox API are expected to define their own overall message + * structures by combining the header, a set of tags, and a terminating + * entry. For example, + * + * struct msg { + * struct bcm2835_mbox_hdr hdr; + * struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; + * ... perhaps other tags here ... + * u32 end_tag; + * }; + */ + +#define BCM2835_MBOX_TAG_GET_ARM_MEMORY 0x00010005 + +struct bcm2835_mbox_tag_get_arm_mem { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + u32 mem_base; + u32 mem_size; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_CLOCK_RATE 0x00030002 + +#define BCM2835_MBOX_CLOCK_ID_EMMC 1 +#define BCM2835_MBOX_CLOCK_ID_UART 2 +#define BCM2835_MBOX_CLOCK_ID_ARM 3 +#define BCM2835_MBOX_CLOCK_ID_CORE 4 +#define BCM2835_MBOX_CLOCK_ID_V3D 5 +#define BCM2835_MBOX_CLOCK_ID_H264 6 +#define BCM2835_MBOX_CLOCK_ID_ISP 7 +#define BCM2835_MBOX_CLOCK_ID_SDRAM 8 +#define BCM2835_MBOX_CLOCK_ID_PIXEL 9 +#define BCM2835_MBOX_CLOCK_ID_PWM 10 + +struct bcm2835_mbox_tag_get_clock_rate { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + u32 clock_id; + } req; + struct { + u32 clock_id; + u32 rate_hz; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_ALLOCATE_BUFFER 0x00040001 + +struct bcm2835_mbox_tag_allocate_buffer { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + u32 alignment; + } req; + struct { + u32 fb_address; + u32 fb_size; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_RELEASE_BUFFER 0x00048001 + +struct bcm2835_mbox_tag_release_buffer { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_BLANK_SCREEN 0x00040002 + +struct bcm2835_mbox_tag_blank_screen { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + /* bit 0 means on, other bits reserved */ + u32 state; + } req; + struct { + u32 state; + } resp; + } body; +}; + +/* Physical means output signal */ +#define BCM2835_MBOX_TAG_GET_PHYSICAL_W_H 0x00040003 +#define BCM2835_MBOX_TAG_TEST_PHYSICAL_W_H 0x00044003 +#define BCM2835_MBOX_TAG_SET_PHYSICAL_W_H 0x00048003 + +struct bcm2835_mbox_tag_physical_w_h { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 width; + u32 height; + } req; + struct { + u32 width; + u32 height; + } resp; + } body; +}; + +/* Virtual means display buffer */ +#define BCM2835_MBOX_TAG_GET_VIRTUAL_W_H 0x00040004 +#define BCM2835_MBOX_TAG_TEST_VIRTUAL_W_H 0x00044004 +#define BCM2835_MBOX_TAG_SET_VIRTUAL_W_H 0x00048004 + +struct bcm2835_mbox_tag_virtual_w_h { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 width; + u32 height; + } req; + struct { + u32 width; + u32 height; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_DEPTH 0x00040005 +#define BCM2835_MBOX_TAG_TEST_DEPTH 0x00044005 +#define BCM2835_MBOX_TAG_SET_DEPTH 0x00048005 + +struct bcm2835_mbox_tag_depth { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 bpp; + } req; + struct { + u32 bpp; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_PIXEL_ORDER 0x00040006 +#define BCM2835_MBOX_TAG_TEST_PIXEL_ORDER 0x00044005 +#define BCM2835_MBOX_TAG_SET_PIXEL_ORDER 0x00048006 + +#define BCM2835_MBOX_PIXEL_ORDER_BGR 0 +#define BCM2835_MBOX_PIXEL_ORDER_RGB 1 + +struct bcm2835_mbox_tag_pixel_order { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 order; + } req; + struct { + u32 order; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_ALPHA_MODE 0x00040007 +#define BCM2835_MBOX_TAG_TEST_ALPHA_MODE 0x00044007 +#define BCM2835_MBOX_TAG_SET_ALPHA_MODE 0x00048007 + +#define BCM2835_MBOX_ALPHA_MODE_0_OPAQUE 0 +#define BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT 1 +#define BCM2835_MBOX_ALPHA_MODE_IGNORED 2 + +struct bcm2835_mbox_tag_alpha_mode { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 alpha; + } req; + struct { + u32 alpha; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_PITCH 0x00040008 + +struct bcm2835_mbox_tag_pitch { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + u32 pitch; + } resp; + } body; +}; + +/* Offset of display window within buffer */ +#define BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET 0x00040009 +#define BCM2835_MBOX_TAG_TEST_VIRTUAL_OFFSET 0x00044009 +#define BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET 0x00048009 + +struct bcm2835_mbox_tag_virtual_offset { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 x; + u32 y; + } req; + struct { + u32 x; + u32 y; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_OVERSCAN 0x0004000a +#define BCM2835_MBOX_TAG_TEST_OVERSCAN 0x0004400a +#define BCM2835_MBOX_TAG_SET_OVERSCAN 0x0004800a + +struct bcm2835_mbox_tag_overscan { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + /* req not used for get */ + struct { + u32 top; + u32 bottom; + u32 left; + u32 right; + } req; + struct { + u32 top; + u32 bottom; + u32 left; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_PALETTE 0x0004000b + +struct bcm2835_mbox_tag_get_palette { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + u32 data[1024]; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_TEST_PALETTE 0x0004400b + +struct bcm2835_mbox_tag_test_palette { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + u32 offset; + u32 num_entries; + u32 data[256]; + } req; + struct { + u32 is_invalid; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_SET_PALETTE 0x0004800b + +struct bcm2835_mbox_tag_set_palette { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + u32 offset; + u32 num_entries; + u32 data[256]; + } req; + struct { + u32 is_invalid; + } resp; + } body; +}; + +/* + * Pass a complete property-style buffer to the VC, and wait until it has + * been processed. + * + * This function expects a pointer to the mbox_hdr structure in an attempt + * to ensure some degree of type safety. However, some number of tags and + * a termination value are expected to immediately follow the header in + * memory, as required by the property protocol. + * + * Returns 0 for success, any other value for error. + */ +int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer); + +#endif diff --git a/arch/arm/mach-bcm2835/mbox.c b/arch/arm/mach-bcm2835/mbox.c new file mode 100644 index 000000000..2bca567f3 --- /dev/null +++ b/arch/arm/mach-bcm2835/mbox.c @@ -0,0 +1,152 @@ +/* + * based on U-Boot code + * + * (C) Copyright 2012 Stephen Warren + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +#include + +#define TIMEOUT (MSECOND * 100) /* 100mS */ + +static int bcm2835_mbox_call_raw(u32 chan, struct bcm2835_mbox_hdr *buffer, + u32 *recv) +{ + struct bcm2835_mbox_regs __iomem *regs = + (struct bcm2835_mbox_regs *)BCM2835_MBOX_PHYSADDR; + uint64_t starttime = get_time_ns(); + u32 send = virt_to_phys(buffer); + u32 val; + + if (send & BCM2835_CHAN_MASK) { + printf("mbox: Illegal mbox data 0x%08x\n", send); + return -EINVAL; + } + + /* Drain any stale responses */ + for (;;) { + val = readl(®s->status); + if (val & BCM2835_MBOX_STATUS_RD_EMPTY) + break; + if (is_timeout(starttime, TIMEOUT)) { + printf("mbox: Timeout draining stale responses\n"); + return -ETIMEDOUT; + } + val = readl(®s->read); + } + + /* Wait for space to send */ + for (;;) { + val = readl(®s->status); + if (!(val & BCM2835_MBOX_STATUS_WR_FULL)) + break; + if (is_timeout(starttime, TIMEOUT)) { + printf("mbox: Timeout waiting for send space\n"); + return -ETIMEDOUT; + } + } + + /* Send the request */ + val = BCM2835_MBOX_PACK(chan, send); + debug("mbox: TX raw: 0x%08x\n", val); + dma_flush_range(send, send + buffer->buf_size); + writel(val, ®s->write); + + /* Wait for the response */ + for (;;) { + val = readl(®s->status); + if (!(val & BCM2835_MBOX_STATUS_RD_EMPTY)) + break; + if (is_timeout(starttime, TIMEOUT)) { + printf("mbox: Timeout waiting for response\n"); + return -ETIMEDOUT; + } + } + + /* Read the response */ + val = readl(®s->read); + debug("mbox: RX raw: 0x%08x\n", val); + dma_inv_range(send, send + buffer->buf_size); + + /* Validate the response */ + if (BCM2835_MBOX_UNPACK_CHAN(val) != chan) { + printf("mbox: Response channel mismatch\n"); + return -EIO; + } + + *recv = BCM2835_MBOX_UNPACK_DATA(val); + + return 0; +} + +#ifdef DEBUG +void dump_buf(struct bcm2835_mbox_hdr *buffer) +{ + u32 *p; + u32 words; + int i; + + p = (u32 *)buffer; + words = buffer->buf_size / 4; + for (i = 0; i < words; i++) + printf(" 0x%04x: 0x%08x\n", i * 4, p[i]); +} +#endif + +int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer) +{ + int ret; + u32 rbuffer; + struct bcm2835_mbox_tag_hdr *tag; + int tag_index; + +#ifdef DEBUG + printf("mbox: TX buffer\n"); + dump_buf(buffer); +#endif + + ret = bcm2835_mbox_call_raw(chan, buffer, &rbuffer); + if (ret) + return ret; + if (rbuffer != (u32)buffer) { + printf("mbox: Response buffer mismatch\n"); + return -EIO; + } + +#ifdef DEBUG + printf("mbox: RX buffer\n"); + dump_buf(buffer); +#endif + + /* Validate overall response status */ + if (buffer->code != BCM2835_MBOX_RESP_CODE_SUCCESS) { + printf("mbox: Header response code invalid\n"); + return -EIO; + } + + /* Validate each tag's response status */ + tag = (void *)(buffer + 1); + tag_index = 0; + while (tag->tag) { + if (!(tag->val_len & BCM2835_MBOX_TAG_VAL_LEN_RESPONSE)) { + printf("mbox: Tag %d missing val_len response bit\n", + tag_index); + return -EIO; + } + /* + * Clear the reponse bit so clients can just look right at the + * length field without extra processing + */ + tag->val_len &= ~BCM2835_MBOX_TAG_VAL_LEN_RESPONSE; + tag = (void *)(((u8 *)tag) + sizeof(*tag) + tag->val_buf_size); + tag_index++; + } + + return 0; +} From a476255682c82ce4b9c790605eab75b1b5b9a9d0 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:53 +0200 Subject: [PATCH 13/23] ARM: rpi: register a clkdev for the eMMC clock Use the mailbox driver to query the clock frequency and create a clkdev for the bcm2835_mci driver. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/boards/raspberry-pi/rpi.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c index 971a603bf..d3c6b117d 100644 --- a/arch/arm/boards/raspberry-pi/rpi.c +++ b/arch/arm/boards/raspberry-pi/rpi.c @@ -17,11 +17,44 @@ #include #include #include +#include +#include #include #include #include #include +#include + +struct msg_get_clock_rate { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; + u32 end_tag; +}; + +static int rpi_register_clkdev(u32 clock_id, const char *name) +{ + BCM2835_MBOX_STACK_ALIGN(struct msg_get_clock_rate, msg); + struct clk *clk; + int ret; + + BCM2835_MBOX_INIT_HDR(msg); + BCM2835_MBOX_INIT_TAG(&msg->get_clock_rate, GET_CLOCK_RATE); + msg->get_clock_rate.body.req.clock_id = clock_id; + + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); + if (ret) + return ret; + + clk = clk_fixed(name, msg->get_clock_rate.body.resp.rate_hz); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + if (!clk_register_clkdev(clk, NULL, name)) + return -ENODEV; + + return 0; +} static int rpi_mem_init(void) { @@ -40,6 +73,13 @@ static int rpi_console_init(void) } console_initcall(rpi_console_init); +static int rpi_clock_init(void) +{ + rpi_register_clkdev(BCM2835_MBOX_CLOCK_ID_EMMC, "bcm2835_mci0"); + return 0; +} +postconsole_initcall(rpi_clock_init); + static int rpi_env_init(void) { struct stat s; From db81ebba81409106c411aede9311485d174252cc Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:54 +0200 Subject: [PATCH 14/23] mci: bcm2835: use the registered device clkdev Switch from local mailbox code to using the newly created clock device. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- drivers/mci/mci-bcm2835.c | 93 ++++++++------------------------------- drivers/mci/mci-bcm2835.h | 48 -------------------- 2 files changed, 19 insertions(+), 122 deletions(-) diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c index 2ffdeecc0..7d8997c04 100644 --- a/drivers/mci/mci-bcm2835.c +++ b/drivers/mci/mci-bcm2835.c @@ -28,13 +28,14 @@ * Author: Wilhelm Lundgren */ -#include #include #include #include #include #include #include +#include + #include "mci-bcm2835.h" #include "sdhci.h" @@ -469,53 +470,6 @@ int bcm2835_mci_reset(struct mci_host *mci, struct device_d *mci_dev) return bcm2835_mci_wait_command_done(host); } -static u32 bcm2835_mci_get_emmc_clock(struct msg_get_clock_rate *clk_data) -{ - u32 val; - struct bcm2835_mbox_regs __iomem *regs = - (struct bcm2835_mbox_regs *) BCM2835_MBOX_PHYSADDR; - - /*Read out old msg*/ - while (true) { - val = readl(®s->status); - if (val & BCM2835_MBOX_STATUS_RD_EMPTY) - break; - val = readl(®s->read); - } - - /*Check for ok to write*/ - while (true) { - val = readl(®s->status); - if (!(val & BCM2835_MBOX_STATUS_WR_FULL)) - break; - } - val = BCM2835_MBOX_PROP_CHAN + ((u32) &clk_data->hdr); - dma_flush_range((u32)clk_data, (u32)clk_data + sizeof(*clk_data)); - writel(val, ®s->write); - - while (true) { - /* Wait for the response */ - while (true) { - val = readl(®s->status); - if (!(val & BCM2835_MBOX_STATUS_RD_EMPTY)) - break; - } - - /* Read the response */ - val = readl(®s->read); - if ((val & 0x0F) == BCM2835_MBOX_PROP_CHAN) - break; - } - - dma_inv_range((u32)clk_data, (u32)clk_data + sizeof(*clk_data)); - - if ((val & ~0x0F) == ((u32) &clk_data->hdr)) - if (clk_data->get_clock_rate.tag_hdr.val_len - & BCM2835_MBOX_TAG_VAL_LEN_RESPONSE) - return 1; - return 0; -} - static int bcm2835_mci_detect(struct device_d *dev) { struct bcm2835_mci_host *host = dev->priv; @@ -526,7 +480,22 @@ static int bcm2835_mci_detect(struct device_d *dev) static int bcm2835_mci_probe(struct device_d *hw_dev) { struct bcm2835_mci_host *host; - struct msg_get_clock_rate *clk_data; + static struct clk *clk; + int ret; + + clk = clk_get(hw_dev, NULL); + if (IS_ERR(clk)) { + ret = PTR_ERR(clk); + dev_err(hw_dev, "clock not found: %d\n", ret); + return ret; + } + + ret = clk_enable(clk); + if (ret) { + dev_err(hw_dev, "clock failed to enable: %d\n", ret); + clk_put(clk); + return ret; + } host = xzalloc(sizeof(*host)); host->mci.send_cmd = bcm2835_mci_request; @@ -534,31 +503,7 @@ static int bcm2835_mci_probe(struct device_d *hw_dev) host->mci.init = bcm2835_mci_reset; host->mci.hw_dev = hw_dev; host->hw_dev = hw_dev; - - /* Allocate a buffer thats 16 bytes aligned in memory - * Of the 32 bits address passed into the mbox 28 bits - * are the address of the buffer, lower 4 bits is channel - */ - clk_data = memalign(16, sizeof(struct msg_get_clock_rate)); - memset(clk_data, 0, sizeof(struct msg_get_clock_rate)); - clk_data->hdr.buf_size = sizeof(struct msg_get_clock_rate); - clk_data->get_clock_rate.tag_hdr.tag = BCM2835_MBOX_TAG_GET_CLOCK_RATE; - clk_data->get_clock_rate.tag_hdr.val_buf_size = - sizeof(clk_data->get_clock_rate.body); - clk_data->get_clock_rate.tag_hdr.val_len = - sizeof(clk_data->get_clock_rate.body.req); - clk_data->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC; - - if (!bcm2835_mci_get_emmc_clock(clk_data)) { - dev_warn(host->hw_dev, - "Failed getting emmc clock, lets go anyway with 50MHz\n"); - host->max_clock = 50000000; - } else { - host->max_clock = clk_data->get_clock_rate.body.resp.rate_hz; - dev_info(host->hw_dev, "Got emmc clock at %d Hz\n", - host->max_clock); - } - + host->max_clock = clk_get_rate(clk); host->regs = dev_request_mem_region(hw_dev, 0); if (host->regs == NULL) { dev_err(host->hw_dev, "Failed request mem region, aborting...\n"); diff --git a/drivers/mci/mci-bcm2835.h b/drivers/mci/mci-bcm2835.h index 4158a1806..2c95e03c6 100644 --- a/drivers/mci/mci-bcm2835.h +++ b/drivers/mci/mci-bcm2835.h @@ -23,51 +23,3 @@ #define MAX_CLK_DIVIDER_V3 2046 #define MAX_CLK_DIVIDER_V2 256 - -/*this is only for mbox comms*/ -#define BCM2835_MBOX_PHYSADDR 0x2000b880 -#define BCM2835_MBOX_TAG_GET_CLOCK_RATE 0x00030002 -#define BCM2835_MBOX_CLOCK_ID_EMMC 1 -#define BCM2835_MBOX_STATUS_WR_FULL 0x80000000 -#define BCM2835_MBOX_STATUS_RD_EMPTY 0x40000000 -#define BCM2835_MBOX_PROP_CHAN 8 -#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE 0x80000000 - -struct bcm2835_mbox_regs { - u32 read; - u32 rsvd0[5]; - u32 status; - u32 config; - u32 write; -}; - - -struct bcm2835_mbox_hdr { - u32 buf_size; - u32 code; -}; - -struct bcm2835_mbox_tag_hdr { - u32 tag; - u32 val_buf_size; - u32 val_len; -}; - -struct bcm2835_mbox_tag_get_clock_rate { - struct bcm2835_mbox_tag_hdr tag_hdr; - union { - struct { - u32 clock_id; - } req; - struct { - u32 clock_id; - u32 rate_hz; - } resp; - } body; -}; - -struct msg_get_clock_rate { - struct bcm2835_mbox_hdr hdr; - struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; - u32 end_tag; -}; From 607968f541d4619f6e4b5c518cb50a40bebae046 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:21:26 +0200 Subject: [PATCH 15/23] ARM: rpi: use the proper ARM memory size Use the mailbox driver to query the size. This properly takes the firmware's VideoCore/ARM memory split into account. Linux can now be booted with more than 128 MiB. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/boards/raspberry-pi/rpi.c | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c index d3c6b117d..06c43f3c7 100644 --- a/arch/arm/boards/raspberry-pi/rpi.c +++ b/arch/arm/boards/raspberry-pi/rpi.c @@ -26,12 +26,35 @@ #include #include +struct msg_get_arm_mem { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; + u32 end_tag; +}; + struct msg_get_clock_rate { struct bcm2835_mbox_hdr hdr; struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; u32 end_tag; }; +static int rpi_get_arm_mem(u32 *size) +{ + BCM2835_MBOX_STACK_ALIGN(struct msg_get_arm_mem, msg); + int ret; + + BCM2835_MBOX_INIT_HDR(msg); + BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); + + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); + if (ret) + return ret; + + *size = msg->get_arm_mem.body.resp.mem_size; + + return 0; +} + static int rpi_register_clkdev(u32 clock_id, const char *name) { BCM2835_MBOX_STACK_ALIGN(struct msg_get_clock_rate, msg); @@ -58,8 +81,16 @@ static int rpi_register_clkdev(u32 clock_id, const char *name) static int rpi_mem_init(void) { - bcm2835_add_device_sdram(0); - return 0; + u32 size = 0; + int ret; + + ret = rpi_get_arm_mem(&size); + if (ret) + printf("could not query ARM memory size\n"); + + bcm2835_add_device_sdram(size); + + return ret; } mem_initcall(rpi_mem_init); From 7a305b2d8a92cdf42925c7983b61d4a06fe6a789 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Sun, 3 Nov 2013 08:07:08 +0100 Subject: [PATCH 16/23] bcm2835: move mci register at board level not all board have a SD card. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- arch/arm/boards/raspberry-pi/rpi.c | 1 + arch/arm/mach-bcm2835/core.c | 1 - arch/arm/mach-bcm2835/include/mach/core.h | 8 ++++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c index 06c43f3c7..2717feef1 100644 --- a/arch/arm/boards/raspberry-pi/rpi.c +++ b/arch/arm/boards/raspberry-pi/rpi.c @@ -139,6 +139,7 @@ static int rpi_env_init(void) static int rpi_devices_init(void) { + bcm2835_register_mci(); armlinux_set_architecture(MACH_TYPE_BCM2708); armlinux_set_bootparams((void *)(0x00000100)); rpi_env_init(); diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c index cba7bf681..04bc89751 100644 --- a/arch/arm/mach-bcm2835/core.c +++ b/arch/arm/mach-bcm2835/core.c @@ -54,7 +54,6 @@ postcore_initcall(bcm2835_clk_init); static int bcm2835_dev_init(void) { add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, IORESOURCE_MEM, NULL); - add_generic_device("bcm2835_mci", 0, NULL, BCM2835_EMMC_BASE, 0xFC, IORESOURCE_MEM, NULL); return 0; } coredevice_initcall(bcm2835_dev_init); diff --git a/arch/arm/mach-bcm2835/include/mach/core.h b/arch/arm/mach-bcm2835/include/mach/core.h index 9379af209..a095db863 100644 --- a/arch/arm/mach-bcm2835/include/mach/core.h +++ b/arch/arm/mach-bcm2835/include/mach/core.h @@ -16,7 +16,15 @@ #ifndef __BCM2835_CORE_H__ #define __BCM2835_CORE_H__ +#include + void bcm2835_register_uart(void); void bcm2835_add_device_sdram(u32 size); +static void inline bcm2835_register_mci(void) +{ + add_generic_device("bcm2835_mci", 0, NULL, BCM2835_EMMC_BASE, 0xFC, + IORESOURCE_MEM, NULL); +} + #endif From 485544f0fb173e1fe59b70bca0894898a37e9fb0 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 5 Nov 2013 00:00:59 +0100 Subject: [PATCH 17/23] fb: add a line_length value to struct fb_info Add support for framebuffers with noncontiguous horizontal lines. Video drivers can set this value if the hardware requires it. In case a driver does not set it, the current value of xres * (bpp / 8) is used instead. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- drivers/video/fb.c | 11 +++++++++-- include/fb.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/video/fb.c b/drivers/video/fb.c index 420e4e301..0159994d1 100644 --- a/drivers/video/fb.c +++ b/drivers/video/fb.c @@ -72,12 +72,16 @@ static int fb_setup_mode(struct device_d *dev, struct param_d *param, info->xres = info->mode->xres; info->yres = info->mode->yres; + info->line_length = 0; ret = info->fbops->fb_activate_var(info); + if (!info->line_length) + info->line_length = info->xres * (info->bits_per_pixel >> 3); + if (!ret) { dev->resource[0].start = (resource_size_t)info->screen_base; - info->cdev.size = info->xres * info->yres * (info->bits_per_pixel >> 3); + info->cdev.size = info->line_length * info->yres; dev->resource[0].end = dev->resource[0].start + info->cdev.size - 1; dev_param_set_generic(dev, param, val); } else @@ -122,9 +126,12 @@ int register_framebuffer(struct fb_info *info) dev = &info->dev; + if (!info->line_length) + info->line_length = info->xres * (info->bits_per_pixel >> 3); + info->cdev.ops = &fb_ops; info->cdev.name = asprintf("fb%d", id); - info->cdev.size = info->xres * info->yres * (info->bits_per_pixel >> 3); + info->cdev.size = info->line_length * info->yres; info->cdev.dev = dev; info->cdev.priv = info; dev->resource = xzalloc(sizeof(struct resource)); diff --git a/include/fb.h b/include/fb.h index df4ba8ebe..cf9ffa05d 100644 --- a/include/fb.h +++ b/include/fb.h @@ -94,6 +94,7 @@ struct fb_info { u32 xres; /* visible resolution */ u32 yres; u32 bits_per_pixel; /* guess what */ + u32 line_length; /* length of a line in bytes */ u32 grayscale; /* != 0 Graylevels instead of colors */ From 3ad17654675d1fc71f55dc77e7510d243bdfab38 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 5 Nov 2013 00:01:00 +0100 Subject: [PATCH 18/23] gui: convert graphic utils to respect line_length Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- lib/gui/graphic_utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c index 95687df13..300c525b0 100644 --- a/lib/gui/graphic_utils.c +++ b/lib/gui/graphic_utils.c @@ -167,18 +167,18 @@ void rgba_blend(struct fb_info *info, struct image *img, void* buf, int height, { unsigned char *adr; int x, y; - int xres; + int line_length; int img_byte_per_pixel = 3; void *image; if (is_rgba) img_byte_per_pixel++; - xres = info->xres; + line_length = info->line_length; for (y = 0; y < height; y++) { - adr = buf + ((y + starty) * xres + startx) * - (info->bits_per_pixel >> 3); + adr = buf + (y + starty) * line_length + + startx * (info->bits_per_pixel >> 3); image = img->data + (y * img->width *img_byte_per_pixel); for (x = 0; x < width; x++) { @@ -219,7 +219,7 @@ int fb_open(const char * fbdev, struct screen *sc, bool offscreen) sc->s.y = 0; sc->s.width = sc->info.xres; sc->s.height = sc->info.yres; - sc->fbsize = sc->s.width * sc->s.height * (sc->info.bits_per_pixel >> 3); + sc->fbsize = sc->info.line_length * sc->s.height; if (offscreen) { /* Don't fail if malloc fails, just continue rendering directly From 9617cfecbe7d7f3648be7b2cf435e44eaed3a141 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 5 Nov 2013 00:01:01 +0100 Subject: [PATCH 19/23] gui: convert the bmp renderer to respect line_length Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- lib/gui/bmp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/gui/bmp.c b/lib/gui/bmp.c index 6bf8cd000..dcf30952d 100644 --- a/lib/gui/bmp.c +++ b/lib/gui/bmp.c @@ -78,8 +78,8 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img) image = (char *)bmp + le32_to_cpu(bmp->header.data_offset); image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3); - adr = buf + ((y + starty) * sc->s.width + startx) * - (sc->info.bits_per_pixel >> 3); + adr = buf + (y + starty) * sc->info.line_length + + startx * (sc->info.bits_per_pixel >> 3); for (x = 0; x < width; x++) { int pixel; @@ -100,8 +100,8 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img) image = (char *)bmp + le32_to_cpu(bmp->header.data_offset); image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3); - adr = buf + ((y + starty) * sc->s.width + startx) * - (sc->info.bits_per_pixel >> 3); + adr = buf + (y + starty) * sc->info.line_length + + startx * (sc->info.bits_per_pixel >> 3); for (x = 0; x < width; x++) { char *pixel; From 5e9596f3ad2e1b26ceed368a9b21f84839606617 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 5 Nov 2013 00:01:02 +0100 Subject: [PATCH 20/23] ARM: bcm2835: add missing mbox overscan response field Add the missing "right" field to struct bcm2835_mbox_tag_overscan. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/mach-bcm2835/include/mach/mbox.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/mach-bcm2835/include/mach/mbox.h b/arch/arm/mach-bcm2835/include/mach/mbox.h index 6c3638953..fb8a9bf02 100644 --- a/arch/arm/mach-bcm2835/include/mach/mbox.h +++ b/arch/arm/mach-bcm2835/include/mach/mbox.h @@ -355,6 +355,7 @@ struct bcm2835_mbox_tag_overscan { u32 top; u32 bottom; u32 left; + u32 right; } resp; } body; }; From 91b3761ec87a0194b7cb7a0b5ed983504c876195 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 5 Nov 2013 00:01:03 +0100 Subject: [PATCH 21/23] video: add a BCM2835 framebuffer driver Use the mailbox driver to set up a framebuffer based on the firmware configuration. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- arch/arm/boards/raspberry-pi/rpi.c | 1 + arch/arm/mach-bcm2835/include/mach/core.h | 5 + drivers/video/Kconfig | 6 + drivers/video/Makefile | 1 + drivers/video/bcm2835.c | 136 ++++++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 drivers/video/bcm2835.c diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c index 2717feef1..96025ba9b 100644 --- a/arch/arm/boards/raspberry-pi/rpi.c +++ b/arch/arm/boards/raspberry-pi/rpi.c @@ -140,6 +140,7 @@ static int rpi_env_init(void) static int rpi_devices_init(void) { bcm2835_register_mci(); + bcm2835_register_fb(); armlinux_set_architecture(MACH_TYPE_BCM2708); armlinux_set_bootparams((void *)(0x00000100)); rpi_env_init(); diff --git a/arch/arm/mach-bcm2835/include/mach/core.h b/arch/arm/mach-bcm2835/include/mach/core.h index a095db863..477ecb977 100644 --- a/arch/arm/mach-bcm2835/include/mach/core.h +++ b/arch/arm/mach-bcm2835/include/mach/core.h @@ -27,4 +27,9 @@ static void inline bcm2835_register_mci(void) IORESOURCE_MEM, NULL); } +static void inline bcm2835_register_fb(void) +{ + add_generic_device("bcm2835_fb", 0, NULL, 0, 0, 0, NULL); +} + #endif diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 0639d9ca2..b532e7d58 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -71,4 +71,10 @@ config DRIVER_VIDEO_PXA Add support for the frame buffer device found on the PXA270 CPU. +config DRIVER_VIDEO_BCM2835 + bool "BCM2835 framebuffer driver" + depends on ARCH_BCM2835 + help + Add support for the BCM2835/VideoCore frame buffer device. + endif diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 67169d133..244feab27 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o obj-$(CONFIG_DRIVER_VIDEO_OMAP) += omap.o +obj-$(CONFIG_DRIVER_VIDEO_BCM2835) += bcm2835.o diff --git a/drivers/video/bcm2835.c b/drivers/video/bcm2835.c new file mode 100644 index 000000000..3d52f8b6b --- /dev/null +++ b/drivers/video/bcm2835.c @@ -0,0 +1,136 @@ +/* + * BCM2835 framebuffer driver + * + * Copyright (C) 2013 Andre Heider + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +struct bcm2835fb_info { + struct fb_info fbi; + struct fb_videomode mode; +}; + +struct msg_fb_query { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_physical_w_h physical_w_h; + u32 end_tag; +}; + +struct msg_fb_setup { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_physical_w_h physical_w_h; + struct bcm2835_mbox_tag_virtual_w_h virtual_w_h; + struct bcm2835_mbox_tag_depth depth; + struct bcm2835_mbox_tag_pixel_order pixel_order; + struct bcm2835_mbox_tag_alpha_mode alpha_mode; + struct bcm2835_mbox_tag_virtual_offset virtual_offset; + struct bcm2835_mbox_tag_allocate_buffer allocate_buffer; + struct bcm2835_mbox_tag_pitch pitch; + u32 end_tag; +}; + +static void bcm2835fb_enable(struct fb_info *info) +{ +} + +static void bcm2835fb_disable(struct fb_info *info) +{ +} + +static struct fb_ops bcm2835fb_ops = { + .fb_enable = bcm2835fb_enable, + .fb_disable = bcm2835fb_disable, +}; + +static int bcm2835fb_probe(struct device_d *dev) +{ + BCM2835_MBOX_STACK_ALIGN(struct msg_fb_query, msg_query); + BCM2835_MBOX_STACK_ALIGN(struct msg_fb_setup, msg_setup); + struct bcm2835fb_info *info; + u32 w, h; + int ret; + + BCM2835_MBOX_INIT_HDR(msg_query); + BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h, + GET_PHYSICAL_W_H); + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr); + if (ret) { + dev_err(dev, "could not query display resolution\n"); + return ret; + } + + w = msg_query->physical_w_h.body.resp.width; + h = msg_query->physical_w_h.body.resp.height; + + BCM2835_MBOX_INIT_HDR(msg_setup); + BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H); + msg_setup->physical_w_h.body.req.width = w; + msg_setup->physical_w_h.body.req.height = h; + BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H); + msg_setup->virtual_w_h.body.req.width = w; + msg_setup->virtual_w_h.body.req.height = h; + BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH); + msg_setup->depth.body.req.bpp = 16; + BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER); + msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR; + BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE); + msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED; + BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET); + msg_setup->virtual_offset.body.req.x = 0; + msg_setup->virtual_offset.body.req.y = 0; + BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER); + msg_setup->allocate_buffer.body.req.alignment = 0x100; + BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH); + + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr); + if (ret) { + dev_err(dev, "could not configure display\n"); + return ret; + } + + info = xzalloc(sizeof *info); + info->fbi.fbops = &bcm2835fb_ops; + info->fbi.screen_base = + (void *)msg_setup->allocate_buffer.body.resp.fb_address; + info->fbi.xres = msg_setup->physical_w_h.body.resp.width; + info->fbi.yres = msg_setup->physical_w_h.body.resp.height; + info->fbi.bits_per_pixel = 16; + info->fbi.line_length = msg_setup->pitch.body.resp.pitch; + info->fbi.red.length = 5; + info->fbi.red.offset = 11; + info->fbi.green.length = 6; + info->fbi.green.offset = 5; + info->fbi.blue.length = 5; + info->fbi.blue.offset = 0; + + info->fbi.mode = &info->mode; + info->fbi.mode->xres = info->fbi.xres; + info->fbi.mode->yres = info->fbi.yres; + + ret = register_framebuffer(&info->fbi); + if (ret) { + free(info); + dev_err(dev, "failed to register framebuffer: %d\n", ret); + return ret; + } + + dev_info(dev, "registered\n"); + return 0; +} + +static struct driver_d bcm2835fb_driver = { + .name = "bcm2835_fb", + .probe = bcm2835fb_probe, +}; +device_platform_driver(bcm2835fb_driver); From d7c1612d650e87dbdebf8957bc01bd1db52f0d5b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 16 Jul 2013 11:16:24 +0200 Subject: [PATCH 22/23] of: Add a context pointer to fixup functions If drivers want to fixup their specific instance they need some context to know which instance they have to fixup. Signed-off-by: Sascha Hauer --- arch/arm/boards/at91sam9x5ek/hw_version.c | 4 ++-- arch/arm/boards/highbank/init.c | 4 ++-- arch/ppc/mach-mpc5xxx/cpu.c | 4 ++-- arch/ppc/mach-mpc85xx/fdt.c | 4 ++-- common/memory.c | 4 ++-- common/oftree.c | 12 +++++++----- include/of.h | 2 +- net/eth.c | 4 ++-- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c index 1207a3e49..2da4e5ed8 100644 --- a/arch/arm/boards/at91sam9x5ek/hw_version.c +++ b/arch/arm/boards/at91sam9x5ek/hw_version.c @@ -229,7 +229,7 @@ static void at91sam9x5ek_devices_detect_one(const char *name) #define NODE_NAME_LEN 128 -static int cm_cogent_fixup(struct device_node *root) +static int cm_cogent_fixup(struct device_node *root, void *unused) { int ret; struct device_node *node; @@ -260,5 +260,5 @@ void at91sam9x5ek_devices_detect_hw(void) armlinux_set_serial(sn); if (at91sam9x5ek_cm_is_vendor(VENDOR_COGENT)) - of_register_fixup(cm_cogent_fixup); + of_register_fixup(cm_cogent_fixup, NULL); } diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c index 7b1be046a..8a24b21a7 100644 --- a/arch/arm/boards/highbank/init.c +++ b/arch/arm/boards/highbank/init.c @@ -24,7 +24,7 @@ struct fdt_header *fdt = NULL; -static int hb_fixup(struct device_node *root) +static int hb_fixup(struct device_node *root, void *unused) { struct device_node *node; u32 reg = readl(sregs_base + HB_SREG_A9_PWRDOM_DATA); @@ -108,7 +108,7 @@ mem_initcall(highbank_mem_init); static int highbank_devices_init(void) { - of_register_fixup(hb_fixup); + of_register_fixup(hb_fixup, NULL); if (!fdt) { highbank_register_gpio(0); highbank_register_gpio(1); diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c index 0ece4a9ed..c860e709f 100644 --- a/arch/ppc/mach-mpc5xxx/cpu.c +++ b/arch/ppc/mach-mpc5xxx/cpu.c @@ -77,7 +77,7 @@ void __noreturn reset_cpu (unsigned long addr) /* ------------------------------------------------------------------------- */ #ifdef CONFIG_OFTREE -static int of_mpc5200_fixup(struct device_node *root) +static int of_mpc5200_fixup(struct device_node *root, void *unused) { struct device_node *node; @@ -103,7 +103,7 @@ static int of_mpc5200_fixup(struct device_node *root) static int of_register_mpc5200_fixup(void) { - return of_register_fixup(of_mpc5200_fixup); + return of_register_fixup(of_mpc5200_fixup, NULL); } late_initcall(of_register_mpc5200_fixup); #endif diff --git a/arch/ppc/mach-mpc85xx/fdt.c b/arch/ppc/mach-mpc85xx/fdt.c index 65de6f110..fd919a56e 100644 --- a/arch/ppc/mach-mpc85xx/fdt.c +++ b/arch/ppc/mach-mpc85xx/fdt.c @@ -89,7 +89,7 @@ error: return -ENODEV; } -static int fdt_cpu_setup(struct device_node *blob) +static int fdt_cpu_setup(struct device_node *blob, void *unused) { struct device_node *node; struct sys_info sysinfo; @@ -139,6 +139,6 @@ static int fdt_cpu_setup(struct device_node *blob) static int of_register_mpc85xx_fixup(void) { - return of_register_fixup(fdt_cpu_setup); + return of_register_fixup(fdt_cpu_setup, NULL); } late_initcall(of_register_mpc85xx_fixup); diff --git a/common/memory.c b/common/memory.c index 7ec211b8d..c82bbaaf4 100644 --- a/common/memory.c +++ b/common/memory.c @@ -163,7 +163,7 @@ int release_sdram_region(struct resource *res) #ifdef CONFIG_OFTREE -static int of_memory_fixup(struct device_node *node) +static int of_memory_fixup(struct device_node *node, void *unused) { struct memory_bank *bank; int err; @@ -200,7 +200,7 @@ static int of_memory_fixup(struct device_node *node) static int of_register_memory_fixup(void) { - return of_register_fixup(of_memory_fixup); + return of_register_fixup(of_memory_fixup, NULL); } late_initcall(of_register_memory_fixup); #endif diff --git a/common/oftree.c b/common/oftree.c index f2a31692e..50fc95b58 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -113,7 +113,7 @@ void of_print_cmdline(struct device_node *root) printf("commandline: %s\n", cmdline); } -static int of_fixup_bootargs(struct device_node *root) +static int of_fixup_bootargs(struct device_node *root, void *unused) { struct device_node *node; const char *str; @@ -135,22 +135,24 @@ static int of_fixup_bootargs(struct device_node *root) static int of_register_bootargs_fixup(void) { - return of_register_fixup(of_fixup_bootargs); + return of_register_fixup(of_fixup_bootargs, NULL); } late_initcall(of_register_bootargs_fixup); struct of_fixup { - int (*fixup)(struct device_node *); + int (*fixup)(struct device_node *, void *); + void *context; struct list_head list; }; static LIST_HEAD(of_fixup_list); -int of_register_fixup(int (*fixup)(struct device_node *)) +int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context) { struct of_fixup *of_fixup = xzalloc(sizeof(*of_fixup)); of_fixup->fixup = fixup; + of_fixup->context = context; list_add_tail(&of_fixup->list, &of_fixup_list); @@ -167,7 +169,7 @@ int of_fix_tree(struct device_node *node) int ret; list_for_each_entry(of_fixup, &of_fixup_list, list) { - ret = of_fixup->fixup(node); + ret = of_fixup->fixup(node, of_fixup->context); if (ret) return ret; } diff --git a/include/of.h b/include/of.h index e5cd7506c..cd4cff8ab 100644 --- a/include/of.h +++ b/include/of.h @@ -62,7 +62,7 @@ struct device_d; struct driver_d; int of_fix_tree(struct device_node *); -int of_register_fixup(int (*fixup)(struct device_node *)); +int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context); int of_match(struct device_d *dev, struct driver_d *drv); diff --git a/net/eth.c b/net/eth.c index e5d6a3582..38674533d 100644 --- a/net/eth.c +++ b/net/eth.c @@ -274,7 +274,7 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch } #ifdef CONFIG_OFTREE -static int eth_of_fixup(struct device_node *root) +static int eth_of_fixup(struct device_node *root, void *unused) { struct eth_device *edev; struct device_node *node; @@ -316,7 +316,7 @@ static int eth_of_fixup(struct device_node *root) static int eth_register_of_fixup(void) { - return of_register_fixup(eth_of_fixup); + return of_register_fixup(eth_of_fixup, NULL); } late_initcall(eth_register_of_fixup); #endif From 97607e85cdc44824e9617c74325bc9bc6405c383 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Tue, 5 Nov 2013 00:01:04 +0100 Subject: [PATCH 23/23] video: set up the kernel's simple framebuffer driver Add support to configure the active framebuffer for the kernel through device tree. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- drivers/video/Kconfig | 7 ++ drivers/video/Makefile | 1 + drivers/video/fb.c | 7 ++ drivers/video/simplefb.c | 167 +++++++++++++++++++++++++++++++++++++++ include/fb.h | 7 ++ 5 files changed, 189 insertions(+) create mode 100644 drivers/video/simplefb.c diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index b532e7d58..553926622 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -77,4 +77,11 @@ config DRIVER_VIDEO_BCM2835 help Add support for the BCM2835/VideoCore frame buffer device. +config DRIVER_VIDEO_SIMPLEFB + bool "Simple framebuffer support" + depends on OFTREE + help + Add support for setting up the kernel's simple framebuffer driver + based on the active barebox framebuffer. + endif diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 244feab27..31edfca2b 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o obj-$(CONFIG_DRIVER_VIDEO_OMAP) += omap.o obj-$(CONFIG_DRIVER_VIDEO_BCM2835) += bcm2835.o +obj-$(CONFIG_DRIVER_VIDEO_SIMPLEFB) += simplefb.o diff --git a/drivers/video/fb.c b/drivers/video/fb.c index 0159994d1..4263027bf 100644 --- a/drivers/video/fb.c +++ b/drivers/video/fb.c @@ -163,6 +163,13 @@ int register_framebuffer(struct fb_info *info) if (ret) goto err_unregister; + if (IS_ENABLED(CONFIG_DRIVER_VIDEO_SIMPLEFB)) { + ret = fb_register_simplefb(info); + if (ret) + dev_err(&info->dev, "failed to register simplefb: %s\n", + strerror(-ret)); + } + return 0; err_unregister: diff --git a/drivers/video/simplefb.c b/drivers/video/simplefb.c new file mode 100644 index 000000000..834704b21 --- /dev/null +++ b/drivers/video/simplefb.c @@ -0,0 +1,167 @@ +/* + * SimpleFB driver + * + * Copyright (C) 2013 Andre Heider + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#define pr_fmt(fmt) "simplefb: " fmt + +#include +#include +#include +#include +#include +#include +#include + +struct simplefb_mode { + const char *format; + u32 bpp; + struct fb_bitfield red; + struct fb_bitfield green; + struct fb_bitfield blue; + struct fb_bitfield transp; +}; + +/* + * These values have to match the kernel's simplefb driver. + * See Documentation/devicetree/bindings/video/simple-framebuffer.txt + */ +static const struct simplefb_mode simplefb_modes[] = { + { + .format = "r5g6b5", + .bpp = 16, + .red = { .length = 5, .offset = 11 }, + .green = { .length = 6, .offset = 5 }, + .blue = { .length = 5, .offset = 0 }, + .transp = { .length = 0, .offset = 0 }, + }, +}; + +static bool simplefb_bitfield_cmp(const struct fb_bitfield *a, + const struct fb_bitfield *b) +{ + if (a->offset != b->offset) + return false; + if (a->length != b->length) + return false; + if (a->msb_right != b->msb_right) + return false; + + return true; +} + +static const struct simplefb_mode *simplefb_find_mode(const struct fb_info *fbi) +{ + const struct simplefb_mode *mode; + u32 i; + + for (i = 0; i < ARRAY_SIZE(simplefb_modes); ++i) { + mode = &simplefb_modes[i]; + + if (fbi->bits_per_pixel != mode->bpp) + continue; + if (!simplefb_bitfield_cmp(&fbi->red, &mode->red)) + continue; + if (!simplefb_bitfield_cmp(&fbi->green, &mode->green)) + continue; + if (!simplefb_bitfield_cmp(&fbi->blue, &mode->blue)) + continue; + if (!simplefb_bitfield_cmp(&fbi->transp, &mode->transp)) + continue; + + return mode; + } + + return NULL; +} + +static int simplefb_create_node(struct device_node *root, + const struct fb_info *fbi, const char *format) +{ + const char *compat = "simple-framebuffer"; + const char *disabled = "disabled"; + const char *okay = "okay"; + struct device_node *node; + u32 cells[2]; + int ret; + + node = of_create_node(root, "/framebuffer"); + if (!node) + return -ENOMEM; + + ret = of_set_property(node, "status", disabled, + strlen(disabled) + 1, 1); + if (ret < 0) + return ret; + + ret = of_set_property(node, "compatible", compat, strlen(compat) + 1, 1); + if (ret) + return ret; + + cells[0] = cpu_to_be32((u32)fbi->screen_base); + cells[1] = cpu_to_be32(fbi->line_length * fbi->yres); + ret = of_set_property(node, "reg", cells, sizeof(cells[0]) * 2, 1); + if (ret < 0) + return ret; + + cells[0] = cpu_to_be32(fbi->xres); + ret = of_set_property(node, "width", cells, sizeof(cells[0]), 1); + if (ret < 0) + return ret; + + cells[0] = cpu_to_be32(fbi->yres); + ret = of_set_property(node, "height", cells, sizeof(cells[0]), 1); + if (ret < 0) + return ret; + + cells[0] = cpu_to_be32(fbi->line_length); + ret = of_set_property(node, "stride", cells, sizeof(cells[0]), 1); + if (ret < 0) + return ret; + + ret = of_set_property(node, "format", format, strlen(format) + 1, 1); + if (ret < 0) + return ret; + + return of_set_property(node, "status", okay, strlen(okay) + 1, 1); +} + +static int simplefb_of_fixup(struct device_node *root, void *ctx) +{ + struct fb_info *info = ctx; + const struct simplefb_mode *mode; + int ret; + + /* only create node if we are requested to */ + if (!info->register_simplefb) + return 0; + + /* do not create node for disabled framebuffers */ + if (!info->enabled) + return 0; + + mode = simplefb_find_mode(info); + if (!mode) { + dev_err(&info->dev, "fb format is incompatible with simplefb\n"); + return -EINVAL; + } + + ret = simplefb_create_node(root, info, mode->format); + if (ret) + dev_err(&info->dev, "failed to create node: %d\n", ret); + else + dev_info(&info->dev, "created %s node\n", mode->format); + + return ret; +} + +int fb_register_simplefb(struct fb_info *info) +{ + dev_add_param_bool(&info->dev, "register_simplefb", + NULL, NULL, &info->register_simplefb, NULL); + + return of_register_fixup(simplefb_of_fixup, info); +} diff --git a/include/fb.h b/include/fb.h index cf9ffa05d..98d5a0382 100644 --- a/include/fb.h +++ b/include/fb.h @@ -105,6 +105,9 @@ struct fb_info { int enabled; int p_enable; + int register_simplefb; /* If true a simplefb device node will + * be created. + */ }; int register_framebuffer(struct fb_info *info); @@ -115,5 +118,9 @@ int register_framebuffer(struct fb_info *info); extern struct bus_type fb_bus; +/* fb internal functions */ + +int fb_register_simplefb(struct fb_info *info); + #endif /* __FB_H */