diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9f4d8e9..71d4336 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -22,6 +22,15 @@ select UNCOMPRESS select LZO_DECOMPRESS +config ARCH_BCM283X + bool + select GPIOLIB + select CLKDEV_LOOKUP + select COMMON_CLK + select CLOCKSOURCE_BCM283X + select ARM_AMBA + select HAS_DEBUG_LL + menu "System Type" config BUILTIN_DTB @@ -52,13 +61,13 @@ config ARCH_BCM2835 bool "Broadcom BCM2835 boards" - select GPIOLIB + select ARCH_BCM283X select CPU_ARM1176 - select CLKDEV_LOOKUP - select COMMON_CLK - select CLOCKSOURCE_BCM2835 - select ARM_AMBA - select HAS_DEBUG_LL + +config ARCH_BCM2836 + bool "Broadcom BCM2836 boards" + select ARCH_BCM283X + select CPU_V7 config ARCH_CLPS711X bool "Cirrus Logic EP711x/EP721x/EP731x" @@ -251,7 +260,7 @@ source arch/arm/cpu/Kconfig source arch/arm/mach-at91/Kconfig -source arch/arm/mach-bcm2835/Kconfig +source arch/arm/mach-bcm283x/Kconfig source arch/arm/mach-clps711x/Kconfig source arch/arm/mach-davinci/Kconfig source arch/arm/mach-digic/Kconfig diff --git a/arch/arm/Makefile b/arch/arm/Makefile index cae05ff..9ce16b9 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -57,7 +57,7 @@ # Machine directory name. This list is sorted alphanumerically # by CONFIG_* macro name. machine-$(CONFIG_ARCH_AT91) := at91 -machine-$(CONFIG_ARCH_BCM2835) := bcm2835 +machine-$(CONFIG_ARCH_BCM283X) := bcm283x machine-$(CONFIG_ARCH_CLPS711X) := clps711x machine-$(CONFIG_ARCH_DAVINCI) := davinci machine-$(CONFIG_ARCH_DIGIC) := digic diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile index 2e58f15..1029e8f 100644 --- a/arch/arm/boards/Makefile +++ b/arch/arm/boards/Makefile @@ -95,7 +95,7 @@ obj-$(CONFIG_MACH_QIL_A9G20) += qil-a926x/ obj-$(CONFIG_MACH_RADXA_ROCK) += radxa-rock/ obj-$(CONFIG_MACH_REALQ7) += datamodul-edm-qmx6/ -obj-$(CONFIG_MACH_RPI) += raspberry-pi/ +obj-$(CONFIG_MACH_RPI_COMMON) += raspberry-pi/ obj-$(CONFIG_MACH_SABRELITE) += freescale-mx6-sabrelite/ obj-$(CONFIG_MACH_SABRESD) += freescale-mx6-sabresd/ obj-$(CONFIG_MACH_FREESCALE_IMX6SX_SABRESDB) += freescale-mx6sx-sabresdb/ diff --git a/arch/arm/boards/raspberry-pi/Makefile b/arch/arm/boards/raspberry-pi/Makefile index 978383a..7a3d7de 100644 --- a/arch/arm/boards/raspberry-pi/Makefile +++ b/arch/arm/boards/raspberry-pi/Makefile @@ -1,2 +1,4 @@ +obj-$(CONFIG_MACH_RPI_COMMON) += rpi-common.o obj-$(CONFIG_MACH_RPI) += rpi.o +obj-$(CONFIG_MACH_RPI2) += rpi2.o lwl-y += lowlevel.o diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c new file mode 100644 index 0000000..0e17587 --- /dev/null +++ b/arch/arm/boards/raspberry-pi/rpi-common.c @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2009 Carlo Caione + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "rpi.h" + +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; +}; + +struct msg_get_board_rev { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_get_board_rev get_board_rev; + u32 end_tag; +}; + +struct msg_get_mac_address { + struct bcm2835_mbox_hdr hdr; + struct bcm2835_mbox_tag_get_mac_address get_mac_address; + 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); + 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; +} + +void rpi_set_usbethaddr(void) +{ + BCM2835_MBOX_STACK_ALIGN(struct msg_get_mac_address, msg); + int ret; + + BCM2835_MBOX_INIT_HDR(msg); + BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); + + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); + if (ret) { + printf("bcm2835: Could not query MAC address\n"); + /* Ignore error; not critical */ + return; + } + + eth_register_ethaddr(0, msg->get_mac_address.body.resp.mac); +} + +struct gpio_led rpi_leds[] = { + { + .gpio = -EINVAL, + .led = { + .name = "ACT", + }, + }, { + .gpio = -EINVAL, + .led = { + .name = "PWR", + }, + }, +}; + +void rpi_add_led(void) +{ + int i; + struct gpio_led *l; + + for (i = 0; i < ARRAY_SIZE(rpi_leds); i++) { + l = &rpi_leds[i]; + + if (gpio_is_valid(l->gpio)) + led_gpio_register(l); + } + + l = &rpi_leds[0]; + if (gpio_is_valid(l->gpio)) + led_set_trigger(LED_TRIGGER_HEARTBEAT, &l->led); +} + +void rpi_b_plus_init(void) +{ + rpi_leds[0].gpio = 47; + rpi_leds[1].gpio = 35; + rpi_set_usbethaddr(); +} + +static int rpi_board_rev = 0; + +static void rpi_get_board_rev(void) +{ + int ret; + char *name; + + BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_rev, msg); + BCM2835_MBOX_INIT_HDR(msg); + BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); + + ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); + if (ret) { + printf("bcm2835: Could not query board revision\n"); + /* Ignore error; not critical */ + return; + } + + /* Comments from u-boot: + * For details of old-vs-new scheme, see: + * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py + * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282 + * (a few posts down) + * + * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the + * lower byte to use as the board rev: + * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250 + * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 + */ + rpi_board_rev = msg->get_board_rev.body.resp.rev; + if (rpi_board_rev & 0x800000) + rpi_board_rev = (rpi_board_rev >> 4) & 0xff; + else + rpi_board_rev &= 0xff; + if (rpi_board_rev >= rpi_models_size) { + printf("RPI: Board rev %u outside known range\n", + rpi_board_rev); + goto unknown_rev; + } + + if (!rpi_models[rpi_board_rev].name) { + printf("RPI: Board rev %u unknown\n", rpi_board_rev); + goto unknown_rev; + } + + if (!rpi_board_rev) + goto unknown_rev; + + name = asprintf("RaspberryPi %s %s", rpi_models[rpi_board_rev].name, + rpi_model_string); + barebox_set_model(name); + free(name); + + return; + +unknown_rev: + rpi_board_rev = 0; + name = asprintf("RaspberryPi %s", rpi_model_string); + barebox_set_model(name); + free(name); +} + +static void rpi_model_init(void) +{ + if (!rpi_models[rpi_board_rev].init) + return; + + rpi_models[rpi_board_rev].init(); + rpi_add_led(); +} + +static int rpi_mem_init(void) +{ + 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); + +static int rpi_console_init(void) +{ + rpi_get_board_rev(); + barebox_set_hostname("rpi"); + + bcm2835_register_uart(); + return 0; +} +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; + 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", NULL); + if (ret) { + printf("failed to mount %s\n", diskdev); + return 0; + } + + default_environment_path_set("/boot/barebox.env"); + + return 0; +} + +static int rpi_devices_init(void) +{ + rpi_model_init(); + bcm2835_register_mci(); + bcm2835_register_fb(); + armlinux_set_architecture(MACH_TYPE_BCM2708); + rpi_env_init(); + return 0; +} +late_initcall(rpi_devices_init); diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c index f9406d4..dd2ad7f 100644 --- a/arch/arm/boards/raspberry-pi/rpi.c +++ b/arch/arm/boards/raspberry-pi/rpi.c @@ -13,161 +13,17 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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; -}; - -struct msg_get_board_rev { - struct bcm2835_mbox_hdr hdr; - struct bcm2835_mbox_tag_get_board_rev get_board_rev; - u32 end_tag; -}; - -struct msg_get_mac_address { - struct bcm2835_mbox_hdr hdr; - struct bcm2835_mbox_tag_get_mac_address get_mac_address; - 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); - 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 void rpi_set_usbethaddr(void) -{ - BCM2835_MBOX_STACK_ALIGN(struct msg_get_mac_address, msg); - int ret; - - BCM2835_MBOX_INIT_HDR(msg); - BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); - - ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); - if (ret) { - printf("bcm2835: Could not query MAC address\n"); - /* Ignore error; not critical */ - return; - } - - eth_register_ethaddr(0, msg->get_mac_address.body.resp.mac); -} - -static struct gpio_led leds[] = { - { - .gpio = -EINVAL, - .led = { - .name = "ACT", - }, - }, { - .gpio = -EINVAL, - .led = { - .name = "PWR", - }, - }, -}; - -static void rpi_add_led(void) -{ - int i; - struct gpio_led *l; - - for (i = 0; i < ARRAY_SIZE(leds); i++) { - l = &leds[i]; - - if (gpio_is_valid(l->gpio)) - led_gpio_register(l); - } - - l = &leds[0]; - if (gpio_is_valid(l->gpio)) - led_set_trigger(LED_TRIGGER_HEARTBEAT, &l->led); -} - -static void rpi_b_plus_init(void) -{ - leds[0].gpio = 47; - leds[1].gpio = 35; - rpi_set_usbethaddr(); -} +#include "rpi.h" static void rpi_b_init(void) { - leds[0].gpio = 16; - leds[0].active_low = 1; + rpi_leds[0].gpio = 16; + rpi_leds[0].active_low = 1; rpi_set_usbethaddr(); } -#define RPI_MODEL(_id, _name, _init) \ - [_id] = { \ - .name = _name,\ - .init = _init,\ - } /* See comments in mbox.h for data source */ -static const struct { - const char *name; - void (*init)(void); -} models[] = { +const struct rpi_model rpi_models[] = { RPI_MODEL(0, "Unknown model", NULL), RPI_MODEL(BCM2835_BOARD_REV_B_I2C0_2, "Model B (no P5)", rpi_b_init), RPI_MODEL(BCM2835_BOARD_REV_B_I2C0_3, "Model B (no P5)", rpi_b_init), @@ -184,126 +40,5 @@ RPI_MODEL(BCM2835_BOARD_REV_CM, "Compute Module", NULL), RPI_MODEL(BCM2835_BOARD_REV_A_PLUS, "Model A+", NULL), }; - -static int rpi_board_rev = 0; - -static void rpi_get_board_rev(void) -{ - int ret; - char *name; - - BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_rev, msg); - BCM2835_MBOX_INIT_HDR(msg); - BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); - - ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); - if (ret) { - printf("bcm2835: Could not query board revision\n"); - /* Ignore error; not critical */ - return; - } - - rpi_board_rev = msg->get_board_rev.body.resp.rev; - if (rpi_board_rev >= ARRAY_SIZE(models)) { - printf("RPI: Board rev %u outside known range\n", - rpi_board_rev); - goto unknown_rev; - } - - if (!models[rpi_board_rev].name) { - printf("RPI: Board rev %u unknown\n", rpi_board_rev); - goto unknown_rev; - } - - if (!rpi_board_rev) - goto unknown_rev; - - name = asprintf("RaspberryPi %s (BCM2835/ARM1176JZF-S)", - models[rpi_board_rev].name); - barebox_set_model(name); - free(name); - - return; - -unknown_rev: - rpi_board_rev = 0; - barebox_set_model("RaspberryPi (BCM2835/ARM1176JZF-S)"); -} - -static void rpi_model_init(void) -{ - if (!models[rpi_board_rev].init) - return; - - models[rpi_board_rev].init(); - rpi_add_led(); -} - -static int rpi_mem_init(void) -{ - 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); - -static int rpi_console_init(void) -{ - rpi_get_board_rev(); - barebox_set_hostname("rpi"); - - bcm2835_register_uart(); - return 0; -} -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; - 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", NULL); - if (ret) { - printf("failed to mount %s\n", diskdev); - return 0; - } - - default_environment_path_set("/boot/barebox.env"); - - return 0; -} - -static int rpi_devices_init(void) -{ - rpi_model_init(); - bcm2835_register_mci(); - bcm2835_register_fb(); - armlinux_set_architecture(MACH_TYPE_BCM2708); - rpi_env_init(); - return 0; -} -late_initcall(rpi_devices_init); +const size_t rpi_models_size = ARRAY_SIZE(rpi_models); +const char *rpi_model_string = "(BCM2835/ARM1176JZF-S)"; diff --git a/arch/arm/boards/raspberry-pi/rpi.h b/arch/arm/boards/raspberry-pi/rpi.h new file mode 100644 index 0000000..739cdee --- /dev/null +++ b/arch/arm/boards/raspberry-pi/rpi.h @@ -0,0 +1,28 @@ +#ifndef __ARCH_ARM_BOARDS_RPI_H__ +#define __ARCH_ARM_BOARDS_RPI_H__ + +#include +#include + +#include + +#define RPI_MODEL(_id, _name, _init) \ + [_id] = { \ + .name = _name,\ + .init = _init,\ + } + +struct rpi_model { + const char *name; + void (*init)(void); +}; + +extern const struct rpi_model rpi_models[]; +extern const size_t rpi_models_size; +extern const char *rpi_model_string; +extern struct gpio_led rpi_leds[]; + +void rpi_b_plus_init(void); +void rpi_set_usbethaddr(void); + +#endif /* __ARCH_ARM_BOARDS_RPI_H__ */ diff --git a/arch/arm/boards/raspberry-pi/rpi2.c b/arch/arm/boards/raspberry-pi/rpi2.c new file mode 100644 index 0000000..2cfc06f --- /dev/null +++ b/arch/arm/boards/raspberry-pi/rpi2.c @@ -0,0 +1,21 @@ +/* + * 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 "rpi.h" + +const struct rpi_model rpi_models[] = { + RPI_MODEL(0, "Unknown model", NULL), + RPI_MODEL(BCM2836_BOARD_REV_2_B, "2 Model B", rpi_b_plus_init), +}; +const size_t rpi_models_size = ARRAY_SIZE(rpi_models); +const char *rpi_model_string = "(BCM2836/CORTEX-A7)"; diff --git a/arch/arm/configs/rpi2_defconfig b/arch/arm/configs/rpi2_defconfig new file mode 100644 index 0000000..81f821a --- /dev/null +++ b/arch/arm/configs/rpi2_defconfig @@ -0,0 +1,72 @@ +CONFIG_ARCH_BCM2836=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_HUSH_FANCY_PROMPT=y +CONFIG_CMDLINE_EDITING=y +CONFIG_AUTO_COMPLETE=y +CONFIG_MENU=y +CONFIG_BLSPEC=y +CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y +CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/raspberry-pi/env" +CONFIG_LONGHELP=y +CONFIG_CMD_IOMEM=y +CONFIG_CMD_MEMINFO=y +CONFIG_CMD_BOOTM_SHOW_TYPE=y +CONFIG_CMD_BOOTM_VERBOSE=y +CONFIG_CMD_BOOTM_INITRD=y +CONFIG_CMD_BOOTM_OFTREE=y +CONFIG_CMD_GO=y +CONFIG_CMD_LOADB=y +CONFIG_CMD_LOADY=y +CONFIG_CMD_RESET=y +CONFIG_CMD_UIMAGE=y +CONFIG_CMD_PARTITION=y +CONFIG_CMD_EXPORT=y +CONFIG_CMD_PRINTENV=y +CONFIG_CMD_MAGICVAR=y +CONFIG_CMD_MAGICVAR_HELP=y +CONFIG_CMD_SAVEENV=y +CONFIG_CMD_FILETYPE=y +CONFIG_CMD_LN=y +CONFIG_CMD_MD5SUM=y +CONFIG_CMD_UNCOMPRESS=y +CONFIG_CMD_LET=y +CONFIG_CMD_MSLEEP=y +CONFIG_CMD_SLEEP=y +CONFIG_CMD_ECHO_E=y +CONFIG_CMD_EDIT=y +CONFIG_CMD_LOGIN=y +CONFIG_CMD_MENU=y +CONFIG_CMD_MENU_MANAGEMENT=y +CONFIG_CMD_PASSWD=y +CONFIG_CMD_READLINE=y +CONFIG_CMD_TIMEOUT=y +CONFIG_CMD_CRC=y +CONFIG_CMD_CRC_CMP=y +CONFIG_CMD_MM=y +CONFIG_CMD_CLK=y +CONFIG_CMD_DETECT=y +CONFIG_CMD_GPIO=y +CONFIG_CMD_OF_NODE=y +CONFIG_CMD_OF_PROPERTY=y +CONFIG_CMD_OFTREE=y +CONFIG_CMD_TIME=y +CONFIG_SERIAL_AMBA_PL011=y +CONFIG_MCI=y +CONFIG_MCI_BCM283X=y +CONFIG_LED=y +CONFIG_LED_GPIO=y +CONFIG_LED_TRIGGERS=y +CONFIG_GPIO_BCM283X=y +CONFIG_REGULATOR=y +CONFIG_FS_EXT4=y +CONFIG_FS_FAT=y +CONFIG_FS_FAT_WRITE=y +CONFIG_FS_FAT_LFN=y +CONFIG_DIGEST_SHA1_GENERIC=y +CONFIG_DIGEST_SHA256_GENERIC=y diff --git a/arch/arm/configs/rpi_defconfig b/arch/arm/configs/rpi_defconfig index 25770a0..f7b5910 100644 --- a/arch/arm/configs/rpi_defconfig +++ b/arch/arm/configs/rpi_defconfig @@ -6,7 +6,6 @@ CONFIG_MALLOC_TLSF=y CONFIG_KALLSYMS=y CONFIG_PROMPT="R-Pi> " -CONFIG_LONGHELP=y CONFIG_HUSH_FANCY_PROMPT=y CONFIG_CMDLINE_EDITING=y CONFIG_AUTO_COMPLETE=y @@ -14,52 +13,57 @@ 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_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_LOGIN=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_LOADY=y -CONFIG_CMD_MEMINFO=y +CONFIG_LONGHELP=y CONFIG_CMD_IOMEM=y -CONFIG_CMD_MM=y -CONFIG_CMD_CRC=y -CONFIG_CMD_CRC_CMP=y -CONFIG_CMD_MD5SUM=y +CONFIG_CMD_MEMINFO=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_GO=y -CONFIG_CMD_OFTREE=y -CONFIG_CMD_OF_PROPERTY=y -CONFIG_CMD_OF_NODE=y -CONFIG_CMD_TIMEOUT=y +CONFIG_CMD_LOADB=y +CONFIG_CMD_LOADY=y +CONFIG_CMD_RESET=y +CONFIG_CMD_UIMAGE=y CONFIG_CMD_PARTITION=y +CONFIG_CMD_EXPORT=y +CONFIG_CMD_PRINTENV=y CONFIG_CMD_MAGICVAR=y CONFIG_CMD_MAGICVAR_HELP=y -CONFIG_CMD_GPIO=y +CONFIG_CMD_SAVEENV=y +CONFIG_CMD_FILETYPE=y +CONFIG_CMD_LN=y +CONFIG_CMD_MD5SUM=y CONFIG_CMD_UNCOMPRESS=y +CONFIG_CMD_LET=y +CONFIG_CMD_MSLEEP=y +CONFIG_CMD_SLEEP=y +CONFIG_CMD_ECHO_E=y +CONFIG_CMD_EDIT=y +CONFIG_CMD_LOGIN=y +CONFIG_CMD_MENU=y +CONFIG_CMD_MENU_MANAGEMENT=y +CONFIG_CMD_PASSWD=y +CONFIG_CMD_READLINE=y +CONFIG_CMD_TIMEOUT=y +CONFIG_CMD_CRC=y +CONFIG_CMD_CRC_CMP=y +CONFIG_CMD_MM=y CONFIG_CMD_CLK=y CONFIG_CMD_DETECT=y +CONFIG_CMD_GPIO=y +CONFIG_CMD_OF_NODE=y +CONFIG_CMD_OF_PROPERTY=y +CONFIG_CMD_OFTREE=y +CONFIG_CMD_TIME=y CONFIG_SERIAL_AMBA_PL011=y CONFIG_MCI=y -CONFIG_MCI_BCM2835=y -CONFIG_GPIO_BCM2835=y +CONFIG_MCI_BCM283X=y +CONFIG_LED=y +CONFIG_LED_GPIO=y +CONFIG_LED_TRIGGERS=y +CONFIG_GPIO_BCM283X=y +CONFIG_REGULATOR=y CONFIG_FS_EXT4=y CONFIG_FS_FAT=y CONFIG_FS_FAT_WRITE=y diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile index 418bcab..854df60e 100644 --- a/arch/arm/cpu/Makefile +++ b/arch/arm/cpu/Makefile @@ -11,6 +11,11 @@ obj-$(CONFIG_OFDEVICE) += dtb.o obj-$(CONFIG_MMU) += mmu.o cache.o mmu-early.o pbl-$(CONFIG_MMU) += mmu-early.o + +ifeq ($(CONFIG_MMU),) +obj-y += no-mmu.o +endif + obj-$(CONFIG_CPU_32v4T) += cache-armv4.o pbl-$(CONFIG_CPU_32v4T) += cache-armv4.o obj-$(CONFIG_CPU_32v5) += cache-armv5.o diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c index 784221c..bc5325f 100644 --- a/arch/arm/cpu/mmu.c +++ b/arch/arm/cpu/mmu.c @@ -302,6 +302,16 @@ * live without being able to catch NULL pointer dereferences */ exc = arm_create_pte(0x0); + + if (cpu_architecture() >= CPU_ARCH_ARMv7) { + /* + * ARMv7 CPUs allow to remap low vectors from + * 0x0 to an arbitrary address using VBAR + * register, so let's make sure we have it + * pointing to the correct address + */ + set_vbar(0x0); + } } arm_fixup_vectors(); diff --git a/arch/arm/cpu/no-mmu.c b/arch/arm/cpu/no-mmu.c new file mode 100644 index 0000000..e227b45 --- /dev/null +++ b/arch/arm/cpu/no-mmu.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015 Zodiac Inflight Innovation + * Author: Andrey Smirnov + * + * 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. + * + * 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) "nommu: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define __exceptions_size (__exceptions_stop - __exceptions_start) + +static int nommu_v7_vectors_init(void) +{ + void *vectors; + u32 cr; + + if (cpu_architecture() < CPU_ARCH_ARMv7) + return 0; + + /* + * High vectors cannot be re-mapped, so we have to use normal + * vectors + */ + cr = get_cr(); + cr &= ~CR_V; + set_cr(cr); + + arm_fixup_vectors(); + + vectors = xmemalign(PAGE_SIZE, PAGE_SIZE); + memset(vectors, 0, PAGE_SIZE); + memcpy(vectors, __exceptions_start, __exceptions_size); + + set_vbar((unsigned int)vectors); + + return 0; +} +mmu_initcall(nommu_v7_vectors_init); diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h index 26fb18c..b118a42 100644 --- a/arch/arm/include/asm/system.h +++ b/arch/arm/include/asm/system.h @@ -71,6 +71,26 @@ isb(); } +#ifdef CONFIG_CPU_32v7 +static inline unsigned int get_vbar(void) +{ + unsigned int vbar; + asm volatile("mrc p15, 0, %0, c12, c0, 0 @ get VBAR" + : "=r" (vbar) : : "cc"); + return vbar; +} + +static inline void set_vbar(unsigned int vbar) +{ + asm volatile("mcr p15, 0, %0, c12, c0, 0 @ set VBAR" + : : "r" (vbar) : "cc"); + isb(); +} +#else +static inline unsigned int get_vbar(void) { return 0; } +static inline void set_vbar(unsigned int vbar) {} +#endif + #endif #endif /* __ASM_ARM_SYSTEM_H */ diff --git a/arch/arm/mach-at91/bootstrap.c b/arch/arm/mach-at91/bootstrap.c index 1baf732..47e7896 100644 --- a/arch/arm/mach-at91/bootstrap.c +++ b/arch/arm/mach-at91/bootstrap.c @@ -51,7 +51,7 @@ static void at91bootstrap_boot_m25p80(bool is_barebox) { char *name = is_barebox_to_str(is_barebox); - int (*func)(void) = NULL; + kernel_entry_func func = NULL; func = bootstrap_board_read_m25p80(); printf("Boot %s from m25p80\n", name); @@ -63,7 +63,7 @@ static void at91bootstrap_boot_dataflash(bool is_barebox) { char *name = is_barebox_to_str(is_barebox); - int (*func)(void) = NULL; + kernel_entry_func func = NULL; printf("Boot %s from dataflash\n", name); func = bootstrap_board_read_dataflash(); @@ -75,7 +75,7 @@ static void at91bootstrap_boot_nand(bool is_barebox) { char *name = is_barebox_to_str(is_barebox); - int (*func)(void) = NULL; + kernel_entry_func func = NULL; printf("Boot %s from nand\n", name); func = bootstrap_read_devfs("nand0", true, SZ_128K, SZ_256K, SZ_1M); @@ -86,7 +86,7 @@ static void at91bootstrap_boot_mmc(void) { - int (*func)(void) = NULL; + kernel_entry_func func = NULL; printf("Boot from mmc\n"); func = bootstrap_read_disk("disk0.0", NULL); diff --git a/arch/arm/mach-bcm2835/Kconfig b/arch/arm/mach-bcm2835/Kconfig deleted file mode 100644 index 134ad9b..0000000 --- a/arch/arm/mach-bcm2835/Kconfig +++ /dev/null @@ -1,15 +0,0 @@ -if ARCH_BCM2835 - -config ARCH_TEXT_BASE - hex - default 0x04000000 if MACH_RPI - -choice - prompt "Broadcom Board type" - -config MACH_RPI - bool "RaspberryPi (BCM2835/ARM1176JZF-S)" - -endchoice - -endif diff --git a/arch/arm/mach-bcm2835/Makefile b/arch/arm/mach-bcm2835/Makefile deleted file mode 100644 index 940f98c..0000000 --- a/arch/arm/mach-bcm2835/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-y += core.o mbox.o diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c deleted file mode 100644 index 64f3781..0000000 --- a/arch/arm/mach-bcm2835/core.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Author: Carlo Caione - * - * Based on mach-nomadik - * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -static int bcm2835_clk_init(void) -{ - struct clk *clk; - - clk = clk_fixed("apb_pclk", 0); - clk_register_clkdev(clk, "apb_pclk", NULL); - - clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000); - clk_register_clkdev(clk, NULL, "uart0-pl0110"); - - 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); - -void bcm2835_register_uart(void) -{ - amba_apb_device_add(NULL, "uart0-pl011", 0, BCM2835_UART0_BASE, 4096, NULL, 0); -} - -void bcm2835_add_device_sdram(u32 size) -{ - if (!size) - size = get_ram_size((ulong *) BCM2835_SDRAM_BASE, SZ_128M); - - arm_add_mem_device("ram0", BCM2835_SDRAM_BASE, size); -} -#define RESET_TIMEOUT 10 - -static void __noreturn bcm2835_restart_soc(struct restart_handler *rst) -{ - uint32_t rstc; - - rstc = readl(PM_RSTC); - rstc &= ~PM_RSTC_WRCFG_SET; - rstc |= PM_RSTC_WRCFG_FULL_RESET; - writel(PM_PASSWORD | RESET_TIMEOUT, PM_WDOG); - writel(PM_PASSWORD | rstc, PM_RSTC); - - hang(); -} - -static int bcm2835_dev_init(void) -{ - add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, IORESOURCE_MEM, NULL); - restart_handler_register_fn(bcm2835_restart_soc); - return 0; -} -coredevice_initcall(bcm2835_dev_init); diff --git a/arch/arm/mach-bcm2835/include/mach/core.h b/arch/arm/mach-bcm2835/include/mach/core.h deleted file mode 100644 index 477ecb9..0000000 --- a/arch/arm/mach-bcm2835/include/mach/core.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2009 Carlo Caione - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#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); -} - -static void inline bcm2835_register_fb(void) -{ - add_generic_device("bcm2835_fb", 0, NULL, 0, 0, 0, NULL); -} - -#endif diff --git a/arch/arm/mach-bcm2835/include/mach/debug_ll.h b/arch/arm/mach-bcm2835/include/mach/debug_ll.h deleted file mode 100644 index be93cd9..0000000 --- a/arch/arm/mach-bcm2835/include/mach/debug_ll.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2014 Antony Pavlov - * - * This file is part of barebox. - * See file CREDITS for list of people who contributed to this project. - * - * 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. - * - * 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. - * - */ - -#ifndef __MACH_BCM2835_DEBUG_LL_H__ -#define __MACH_BCM2835_DEBUG_LL_H__ - -#include - -#define DEBUG_LL_UART_ADDR BCM2835_UART0_BASE - -#include - -#endif /* __MACH_BCM2835_DEBUG_LL_H__ */ diff --git a/arch/arm/mach-bcm2835/include/mach/mbox.h b/arch/arm/mach-bcm2835/include/mach/mbox.h deleted file mode 100644 index 4c3fd77..0000000 --- a/arch/arm/mach-bcm2835/include/mach/mbox.h +++ /dev/null @@ -1,518 +0,0 @@ -/* - * 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_BOARD_REV 0x00010002 - -/* - * 0x2..0xf from: - * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/ - * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733 - * 0x10, 0x11 from swarren's testing - */ -#define BCM2835_BOARD_REV_B_I2C0_2 0x2 -#define BCM2835_BOARD_REV_B_I2C0_3 0x3 -#define BCM2835_BOARD_REV_B_I2C1_4 0x4 -#define BCM2835_BOARD_REV_B_I2C1_5 0x5 -#define BCM2835_BOARD_REV_B_I2C1_6 0x6 -#define BCM2835_BOARD_REV_A_7 0x7 -#define BCM2835_BOARD_REV_A_8 0x8 -#define BCM2835_BOARD_REV_A_9 0x9 -#define BCM2835_BOARD_REV_B_REV2_d 0xd -#define BCM2835_BOARD_REV_B_REV2_e 0xe -#define BCM2835_BOARD_REV_B_REV2_f 0xf -#define BCM2835_BOARD_REV_B_PLUS 0x10 -#define BCM2835_BOARD_REV_CM 0x11 -#define BCM2835_BOARD_REV_A_PLUS 0x12 - -struct bcm2835_mbox_tag_get_board_rev { - struct bcm2835_mbox_tag_hdr tag_hdr; - union { - struct { - } req; - struct { - u32 rev; - } resp; - } body; -}; - -#define BCM2835_MBOX_TAG_GET_MAC_ADDRESS 0x00010003 - -struct bcm2835_mbox_tag_get_mac_address { - struct bcm2835_mbox_tag_hdr tag_hdr; - union { - struct { - } req; - struct { - u8 mac[6]; - u8 pad[2]; - } resp; - } body; -}; - -#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_POWER_DEVID_SDHCI 0 -#define BCM2835_MBOX_POWER_DEVID_UART0 1 -#define BCM2835_MBOX_POWER_DEVID_UART1 2 -#define BCM2835_MBOX_POWER_DEVID_USB_HCD 3 -#define BCM2835_MBOX_POWER_DEVID_I2C0 4 -#define BCM2835_MBOX_POWER_DEVID_I2C1 5 -#define BCM2835_MBOX_POWER_DEVID_I2C2 6 -#define BCM2835_MBOX_POWER_DEVID_SPI 7 -#define BCM2835_MBOX_POWER_DEVID_CCP2TX 8 - -#define BCM2835_MBOX_POWER_STATE_RESP_ON (1 << 0) -/* Device doesn't exist */ -#define BCM2835_MBOX_POWER_STATE_RESP_NODEV (1 << 1) - -#define BCM2835_MBOX_TAG_GET_POWER_STATE 0x00020001 - -struct bcm2835_mbox_tag_get_power_state { - struct bcm2835_mbox_tag_hdr tag_hdr; - union { - struct { - u32 device_id; - } req; - struct { - u32 device_id; - u32 state; - } resp; - } body; -}; - -#define BCM2835_MBOX_TAG_SET_POWER_STATE 0x00028001 - -#define BCM2835_MBOX_SET_POWER_STATE_REQ_OFF (0 << 0) -#define BCM2835_MBOX_SET_POWER_STATE_REQ_ON (1 << 0) -#define BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT (1 << 1) - -struct bcm2835_mbox_tag_set_power_state { - struct bcm2835_mbox_tag_hdr tag_hdr; - union { - struct { - u32 device_id; - u32 state; - } req; - struct { - u32 device_id; - u32 state; - } 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; - u32 right; - } 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/include/mach/platform.h b/arch/arm/mach-bcm2835/include/mach/platform.h deleted file mode 100644 index e55085a..0000000 --- a/arch/arm/mach-bcm2835/include/mach/platform.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Extract from arch/arm/mach-bcm2708/include/mach/platform.h - * - * Copyright (C) 2010 Broadcom - * - * 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. - * - */ - -#ifndef _BCM2835_PLATFORM_H -#define _BCM2835_PLATFORM_H - -/* - * SDRAM - */ -#define BCM2835_SDRAM_BASE 0x00000000 - -/* - * Definitions and addresses for the ARM CONTROL logic - * This file is manually generated. - */ - -#define BCM2835_PERI_BASE 0x20000000 -#define BCM2835_ST_BASE (BCM2835_PERI_BASE + 0x3000) /* System Timer */ -#define BCM2835_DMA_BASE (BCM2835_PERI_BASE + 0x7000) /* DMA controller */ -#define BCM2835_ARM_BASE (BCM2835_PERI_BASE + 0xB000) /* BCM2708 ARM control block */ -#define BCM2835_PM_BASE (BCM2835_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */ -#define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000) /* GPIO */ -#define BCM2835_UART0_BASE (BCM2835_PERI_BASE + 0x201000) /* Uart 0 */ -#define BCM2835_MMCI0_BASE (BCM2835_PERI_BASE + 0x202000) /* MMC interface */ -#define BCM2835_SPI0_BASE (BCM2835_PERI_BASE + 0x204000) /* SPI0 */ -#define BCM2835_BSC0_BASE (BCM2835_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */ -#define BCM2835_UART1_BASE (BCM2835_PERI_BASE + 0x215000) /* Uart 1 */ -#define BCM2835_EMMC_BASE (BCM2835_PERI_BASE + 0x300000) /* eMMC interface */ -#define BCM2835_SMI_BASE (BCM2835_PERI_BASE + 0x600000) /* SMI */ -#define BCM2835_BSC1_BASE (BCM2835_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */ -#define BCM2835_USB_BASE (BCM2835_PERI_BASE + 0x980000) /* DTC_OTG USB controller */ -#define BCM2835_MCORE_BASE (BCM2835_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/ - -#endif - -/* END */ diff --git a/arch/arm/mach-bcm2835/include/mach/wd.h b/arch/arm/mach-bcm2835/include/mach/wd.h deleted file mode 100644 index ad8b762..0000000 --- a/arch/arm/mach-bcm2835/include/mach/wd.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Extract from arch/arm/mach-bcm2708/include/mach/platform.h - * - * Copyright (C) 2010 Broadcom - * - * 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. - * - */ - -#ifndef _WD_H -#define _WD_H - -/* - * Watchdog - */ -#define PM_RSTC (BCM2835_PM_BASE+0x1c) -#define PM_RSTS (BCM2835_PM_BASE+0x20) -#define PM_WDOG (BCM2835_PM_BASE+0x24) - -#define PM_WDOG_RESET 0000000000 -#define PM_PASSWORD 0x5a000000 -#define PM_WDOG_TIME_SET 0x000fffff -#define PM_RSTC_WRCFG_CLR 0xffffffcf -#define PM_RSTC_WRCFG_SET 0x00000030 -#define PM_RSTC_WRCFG_FULL_RESET 0x00000020 -#define PM_RSTC_RESET 0x00000102 - -#define PM_RSTS_HADPOR_SET 0x00001000 -#define PM_RSTS_HADSRH_SET 0x00000400 -#define PM_RSTS_HADSRF_SET 0x00000200 -#define PM_RSTS_HADSRQ_SET 0x00000100 -#define PM_RSTS_HADWRH_SET 0x00000040 -#define PM_RSTS_HADWRF_SET 0x00000020 -#define PM_RSTS_HADWRQ_SET 0x00000010 -#define PM_RSTS_HADDRH_SET 0x00000004 -#define PM_RSTS_HADDRF_SET 0x00000002 -#define PM_RSTS_HADDRQ_SET 0x00000001 - -#endif diff --git a/arch/arm/mach-bcm2835/mbox.c b/arch/arm/mach-bcm2835/mbox.c deleted file mode 100644 index 9d69bc8..0000000 --- a/arch/arm/mach-bcm2835/mbox.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * based on U-Boot code - * - * (C) Copyright 2012 Stephen Warren - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include - -#include - -#define TIMEOUT (MSECOND * 1000) - -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_sync_single_for_device((unsigned long)send, buffer->buf_size, - DMA_BIDIRECTIONAL); - 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_sync_single_for_cpu((unsigned long)send, buffer->buf_size, - DMA_BIDIRECTIONAL); - - /* 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; -} diff --git a/arch/arm/mach-bcm283x/Kconfig b/arch/arm/mach-bcm283x/Kconfig new file mode 100644 index 0000000..e861268 --- /dev/null +++ b/arch/arm/mach-bcm283x/Kconfig @@ -0,0 +1,25 @@ +if ARCH_BCM283X + +config ARCH_TEXT_BASE + hex + default 0x04000000 + +config MACH_RPI_COMMON + bool + +choice + prompt "Broadcom Board type" + +config MACH_RPI + bool "RaspberryPi (BCM2835/ARM1176JZF-S)" + depends on ARCH_BCM2835 + select MACH_RPI_COMMON + +config MACH_RPI2 + bool "RaspberryPi 2 (BCM2836/CORTEX-A7)" + depends on ARCH_BCM2836 + select MACH_RPI_COMMON + +endchoice + +endif diff --git a/arch/arm/mach-bcm283x/Makefile b/arch/arm/mach-bcm283x/Makefile new file mode 100644 index 0000000..940f98c --- /dev/null +++ b/arch/arm/mach-bcm283x/Makefile @@ -0,0 +1 @@ +obj-y += core.o mbox.o diff --git a/arch/arm/mach-bcm283x/core.c b/arch/arm/mach-bcm283x/core.c new file mode 100644 index 0000000..64f3781 --- /dev/null +++ b/arch/arm/mach-bcm283x/core.c @@ -0,0 +1,88 @@ +/* + * Author: Carlo Caione + * + * Based on mach-nomadik + * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +static int bcm2835_clk_init(void) +{ + struct clk *clk; + + clk = clk_fixed("apb_pclk", 0); + clk_register_clkdev(clk, "apb_pclk", NULL); + + clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000); + clk_register_clkdev(clk, NULL, "uart0-pl0110"); + + 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); + +void bcm2835_register_uart(void) +{ + amba_apb_device_add(NULL, "uart0-pl011", 0, BCM2835_UART0_BASE, 4096, NULL, 0); +} + +void bcm2835_add_device_sdram(u32 size) +{ + if (!size) + size = get_ram_size((ulong *) BCM2835_SDRAM_BASE, SZ_128M); + + arm_add_mem_device("ram0", BCM2835_SDRAM_BASE, size); +} +#define RESET_TIMEOUT 10 + +static void __noreturn bcm2835_restart_soc(struct restart_handler *rst) +{ + uint32_t rstc; + + rstc = readl(PM_RSTC); + rstc &= ~PM_RSTC_WRCFG_SET; + rstc |= PM_RSTC_WRCFG_FULL_RESET; + writel(PM_PASSWORD | RESET_TIMEOUT, PM_WDOG); + writel(PM_PASSWORD | rstc, PM_RSTC); + + hang(); +} + +static int bcm2835_dev_init(void) +{ + add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, IORESOURCE_MEM, NULL); + restart_handler_register_fn(bcm2835_restart_soc); + return 0; +} +coredevice_initcall(bcm2835_dev_init); diff --git a/arch/arm/mach-bcm283x/include/mach/core.h b/arch/arm/mach-bcm283x/include/mach/core.h new file mode 100644 index 0000000..b0bed80 --- /dev/null +++ b/arch/arm/mach-bcm283x/include/mach/core.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2009 Carlo Caione + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#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); +} + +static void inline bcm2835_register_fb(void) +{ + add_generic_device("bcm2835_fb", 0, NULL, 0, 0, 0, NULL); +} + +#endif diff --git a/arch/arm/mach-bcm283x/include/mach/debug_ll.h b/arch/arm/mach-bcm283x/include/mach/debug_ll.h new file mode 100644 index 0000000..be93cd9 --- /dev/null +++ b/arch/arm/mach-bcm283x/include/mach/debug_ll.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 Antony Pavlov + * + * This file is part of barebox. + * See file CREDITS for list of people who contributed to this project. + * + * 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. + * + * 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. + * + */ + +#ifndef __MACH_BCM2835_DEBUG_LL_H__ +#define __MACH_BCM2835_DEBUG_LL_H__ + +#include + +#define DEBUG_LL_UART_ADDR BCM2835_UART0_BASE + +#include + +#endif /* __MACH_BCM2835_DEBUG_LL_H__ */ diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h b/arch/arm/mach-bcm283x/include/mach/mbox.h new file mode 100644 index 0000000..cd9ee1f --- /dev/null +++ b/arch/arm/mach-bcm283x/include/mach/mbox.h @@ -0,0 +1,523 @@ +/* + * 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 + +#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 (BCM2835_ARM_BASE + 0x880) + +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_CACHELINE_SIZE) + +#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_BOARD_REV 0x00010002 + +/* RPi 2 */ +#define BCM2836_BOARD_REV_2_B 0x4 + +/* + * 0x2..0xf from: + * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/ + * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733 + * 0x10, 0x11 from swarren's testing + */ +#define BCM2835_BOARD_REV_B_I2C0_2 0x2 +#define BCM2835_BOARD_REV_B_I2C0_3 0x3 +#define BCM2835_BOARD_REV_B_I2C1_4 0x4 +#define BCM2835_BOARD_REV_B_I2C1_5 0x5 +#define BCM2835_BOARD_REV_B_I2C1_6 0x6 +#define BCM2835_BOARD_REV_A_7 0x7 +#define BCM2835_BOARD_REV_A_8 0x8 +#define BCM2835_BOARD_REV_A_9 0x9 +#define BCM2835_BOARD_REV_B_REV2_d 0xd +#define BCM2835_BOARD_REV_B_REV2_e 0xe +#define BCM2835_BOARD_REV_B_REV2_f 0xf +#define BCM2835_BOARD_REV_B_PLUS 0x10 +#define BCM2835_BOARD_REV_CM 0x11 +#define BCM2835_BOARD_REV_A_PLUS 0x12 + +struct bcm2835_mbox_tag_get_board_rev { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + u32 rev; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_GET_MAC_ADDRESS 0x00010003 + +struct bcm2835_mbox_tag_get_mac_address { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + } req; + struct { + u8 mac[6]; + u8 pad[2]; + } resp; + } body; +}; + +#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_POWER_DEVID_SDHCI 0 +#define BCM2835_MBOX_POWER_DEVID_UART0 1 +#define BCM2835_MBOX_POWER_DEVID_UART1 2 +#define BCM2835_MBOX_POWER_DEVID_USB_HCD 3 +#define BCM2835_MBOX_POWER_DEVID_I2C0 4 +#define BCM2835_MBOX_POWER_DEVID_I2C1 5 +#define BCM2835_MBOX_POWER_DEVID_I2C2 6 +#define BCM2835_MBOX_POWER_DEVID_SPI 7 +#define BCM2835_MBOX_POWER_DEVID_CCP2TX 8 + +#define BCM2835_MBOX_POWER_STATE_RESP_ON (1 << 0) +/* Device doesn't exist */ +#define BCM2835_MBOX_POWER_STATE_RESP_NODEV (1 << 1) + +#define BCM2835_MBOX_TAG_GET_POWER_STATE 0x00020001 + +struct bcm2835_mbox_tag_get_power_state { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + u32 device_id; + } req; + struct { + u32 device_id; + u32 state; + } resp; + } body; +}; + +#define BCM2835_MBOX_TAG_SET_POWER_STATE 0x00028001 + +#define BCM2835_MBOX_SET_POWER_STATE_REQ_OFF (0 << 0) +#define BCM2835_MBOX_SET_POWER_STATE_REQ_ON (1 << 0) +#define BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT (1 << 1) + +struct bcm2835_mbox_tag_set_power_state { + struct bcm2835_mbox_tag_hdr tag_hdr; + union { + struct { + u32 device_id; + u32 state; + } req; + struct { + u32 device_id; + u32 state; + } 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; + u32 right; + } 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-bcm283x/include/mach/platform.h b/arch/arm/mach-bcm283x/include/mach/platform.h new file mode 100644 index 0000000..3b73831 --- /dev/null +++ b/arch/arm/mach-bcm283x/include/mach/platform.h @@ -0,0 +1,59 @@ +/* + * Extract from arch/arm/mach-bcm2708/include/mach/platform.h + * + * Copyright (C) 2010 Broadcom + * + * 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. + * + */ + +#ifndef _BCM2835_PLATFORM_H +#define _BCM2835_PLATFORM_H + +/* + * SDRAM + */ +#define BCM2835_SDRAM_BASE 0x00000000 + +/* + * Definitions and addresses for the ARM CONTROL logic + * This file is manually generated. + */ + +#ifdef CONFIG_ARCH_BCM2835 +#define BCM2835_PERI_BASE 0x20000000 +#define BCM2835_CACHELINE_SIZE 32 +#elif defined CONFIG_ARCH_BCM2836 +#define BCM2835_PERI_BASE 0x3f000000 +#define BCM2835_CACHELINE_SIZE 64 +#else +#error "no CONFIG_ARCH_BCM283X defined" +#endif + +#define BCM2835_ST_BASE (BCM2835_PERI_BASE + 0x3000) /* System Timer */ +#define BCM2835_DMA_BASE (BCM2835_PERI_BASE + 0x7000) /* DMA controller */ +#define BCM2835_ARM_BASE (BCM2835_PERI_BASE + 0xB000) /* BCM2708 ARM control block */ +#define BCM2835_PM_BASE (BCM2835_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */ +#define BCM2835_GPIO_BASE (BCM2835_PERI_BASE + 0x200000) /* GPIO */ +#define BCM2835_UART0_BASE (BCM2835_PERI_BASE + 0x201000) /* Uart 0 */ +#define BCM2835_MMCI0_BASE (BCM2835_PERI_BASE + 0x202000) /* MMC interface */ +#define BCM2835_SPI0_BASE (BCM2835_PERI_BASE + 0x204000) /* SPI0 */ +#define BCM2835_BSC0_BASE (BCM2835_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */ +#define BCM2835_UART1_BASE (BCM2835_PERI_BASE + 0x215000) /* Uart 1 */ +#define BCM2835_EMMC_BASE (BCM2835_PERI_BASE + 0x300000) /* eMMC interface */ +#define BCM2835_SMI_BASE (BCM2835_PERI_BASE + 0x600000) /* SMI */ +#define BCM2835_BSC1_BASE (BCM2835_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */ +#define BCM2835_USB_BASE (BCM2835_PERI_BASE + 0x980000) /* DTC_OTG USB controller */ +#define BCM2835_MCORE_BASE (BCM2835_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/ + +#endif + +/* END */ diff --git a/arch/arm/mach-bcm283x/include/mach/wd.h b/arch/arm/mach-bcm283x/include/mach/wd.h new file mode 100644 index 0000000..ad8b762 --- /dev/null +++ b/arch/arm/mach-bcm283x/include/mach/wd.h @@ -0,0 +1,47 @@ +/* + * Extract from arch/arm/mach-bcm2708/include/mach/platform.h + * + * Copyright (C) 2010 Broadcom + * + * 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. + * + */ + +#ifndef _WD_H +#define _WD_H + +/* + * Watchdog + */ +#define PM_RSTC (BCM2835_PM_BASE+0x1c) +#define PM_RSTS (BCM2835_PM_BASE+0x20) +#define PM_WDOG (BCM2835_PM_BASE+0x24) + +#define PM_WDOG_RESET 0000000000 +#define PM_PASSWORD 0x5a000000 +#define PM_WDOG_TIME_SET 0x000fffff +#define PM_RSTC_WRCFG_CLR 0xffffffcf +#define PM_RSTC_WRCFG_SET 0x00000030 +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020 +#define PM_RSTC_RESET 0x00000102 + +#define PM_RSTS_HADPOR_SET 0x00001000 +#define PM_RSTS_HADSRH_SET 0x00000400 +#define PM_RSTS_HADSRF_SET 0x00000200 +#define PM_RSTS_HADSRQ_SET 0x00000100 +#define PM_RSTS_HADWRH_SET 0x00000040 +#define PM_RSTS_HADWRF_SET 0x00000020 +#define PM_RSTS_HADWRQ_SET 0x00000010 +#define PM_RSTS_HADDRH_SET 0x00000004 +#define PM_RSTS_HADDRF_SET 0x00000002 +#define PM_RSTS_HADDRQ_SET 0x00000001 + +#endif diff --git a/arch/arm/mach-bcm283x/mbox.c b/arch/arm/mach-bcm283x/mbox.c new file mode 100644 index 0000000..9d69bc8 --- /dev/null +++ b/arch/arm/mach-bcm283x/mbox.c @@ -0,0 +1,154 @@ +/* + * based on U-Boot code + * + * (C) Copyright 2012 Stephen Warren + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +#include + +#define TIMEOUT (MSECOND * 1000) + +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_sync_single_for_device((unsigned long)send, buffer->buf_size, + DMA_BIDIRECTIONAL); + 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_sync_single_for_cpu((unsigned long)send, buffer->buf_size, + DMA_BIDIRECTIONAL); + + /* 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; +} diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 598edc9..3fb09fb 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -6,9 +6,9 @@ bool depends on ARM && CPU_V7 -config CLOCKSOURCE_BCM2835 +config CLOCKSOURCE_BCM283X bool - depends on ARCH_BCM2835 + depends on ARCH_BCM283X config CLOCKSOURCE_CLPS711X bool diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index f5f5141..4eb1656 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -1,6 +1,6 @@ obj-$(CONFIG_AMBA_SP804) += amba-sp804.o obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o -obj-$(CONFIG_CLOCKSOURCE_BCM2835) += bcm2835.o +obj-$(CONFIG_CLOCKSOURCE_BCM283X) += bcm2835.o obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o obj-$(CONFIG_CLOCKSOURCE_DIGIC) += digic.o obj-$(CONFIG_CLOCKSOURCE_MVEBU) += mvebu.o diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 9cb2261..d839d7a 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -21,9 +21,9 @@ shift registers. This driver can be used to provide access to more gpio outputs. -config GPIO_BCM2835 - bool "GPIO support for BCM2835" - depends on ARCH_BCM2835 +config GPIO_BCM283X + bool "GPIO support for BCM283X" + depends on ARCH_BCM283X config GPIO_CLPS711X bool "GPIO support for CLPS711X" diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index f39e8da..8767eed 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_GPIO_74164) += gpio-74164.o obj-$(CONFIG_MACH_MIPS_ATH79) += gpio-ath79.o -obj-$(CONFIG_GPIO_BCM2835) += gpio-bcm2835.o +obj-$(CONFIG_GPIO_BCM283X) += gpio-bcm2835.o obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o obj-$(CONFIG_GPIO_DIGIC) += gpio-digic.o diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig index ebd8da9..0f3504c 100644 --- a/drivers/mci/Kconfig +++ b/drivers/mci/Kconfig @@ -62,9 +62,9 @@ Enable this entry to add support to read and write SD cards on a Samsung S3C24xx based system. -config MCI_BCM2835 - bool "MCI support for BCM2835" - depends on ARCH_BCM2835 +config MCI_BCM283X + bool "MCI support for BCM283X" + depends on ARCH_BCM283X config MCI_IMX bool "i.MX" diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile index 1e8443c..88ec456 100644 --- a/drivers/mci/Makefile +++ b/drivers/mci/Makefile @@ -1,6 +1,6 @@ obj-$(CONFIG_MCI) += mci-core.o obj-$(CONFIG_MCI_ATMEL) += atmel_mci.o -obj-$(CONFIG_MCI_BCM2835) += mci-bcm2835.o +obj-$(CONFIG_MCI_BCM283X) += mci-bcm2835.o obj-$(CONFIG_MCI_IMX) += imx.o obj-$(CONFIG_MCI_IMX_ESDHC) += imx-esdhc.o obj-$(CONFIG_MCI_MXS) += mxs.o diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 05c3f48..4b41252 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -11,9 +11,9 @@ This enables a simple fixed regulator. It is used for regulators which are not software controllable or controllable via gpio. -config REGULATOR_BCM2835 +config REGULATOR_BCM283X bool - depends on ARCH_BCM2835 + depends on ARCH_BCM283X default y endif diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index d663c16..a8dd9bd 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_REGULATOR) += core.o obj-$(CONFIG_REGULATOR_FIXED) += fixed.o -obj-$(CONFIG_REGULATOR_BCM2835) += bcm2835.o +obj-$(CONFIG_REGULATOR_BCM283X) += bcm2835.o diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index eabd246..7ff67e5 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -82,11 +82,11 @@ Add support for the frame buffer device found on the PXA270 CPU. -config DRIVER_VIDEO_BCM2835 - bool "BCM2835 framebuffer driver" - depends on ARCH_BCM2835 +config DRIVER_VIDEO_BCM283X + bool "BCM283X framebuffer driver" + depends on ARCH_BCM283X help - Add support for the BCM2835/VideoCore frame buffer device. + Add support for the BCM283X/VideoCore frame buffer device. source drivers/video/imx-ipu-v3/Kconfig diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 57e4864..a64fc5f 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -17,6 +17,6 @@ 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_BCM283X) += bcm2835.o obj-$(CONFIG_DRIVER_VIDEO_SIMPLEFB) += simplefb.o obj-$(CONFIG_DRIVER_VIDEO_IMX_IPUV3) += imx-ipu-v3/ diff --git a/include/bootstrap.h b/include/bootstrap.h index 28852c0..9863ff4 100644 --- a/include/bootstrap.h +++ b/include/bootstrap.h @@ -11,7 +11,8 @@ #define bootstrap_err(fmt, arg...) printf(fmt, ##arg) -void bootstrap_boot(int (*func)(void), bool barebox); +typedef void (*kernel_entry_func)(int zero, int arch, void *params); +void bootstrap_boot(kernel_entry_func func, bool barebox); #ifdef CONFIG_BOOTSTRAP_DEVFS void* bootstrap_read_devfs(char *devname, bool use_bb, int offset, diff --git a/include/led.h b/include/led.h index ddf8d90..000267c 100644 --- a/include/led.h +++ b/include/led.h @@ -1,7 +1,10 @@ #ifndef __LED_H #define __LED_H +#include + #include +#include struct led { void (*set)(struct led *, unsigned int value); diff --git a/lib/bootstrap/common.c b/lib/bootstrap/common.c index 38ec272..4a61992 100644 --- a/lib/bootstrap/common.c +++ b/lib/bootstrap/common.c @@ -9,7 +9,7 @@ #include #include -void bootstrap_boot(int (*func)(void), bool barebox) +void bootstrap_boot(kernel_entry_func func, bool barebox) { if (!func) return; @@ -18,7 +18,7 @@ return; shutdown_barebox(); - func(); + func(0, 0, NULL); while (1); }