]> git.sur5r.net Git - u-boot/blobdiff - board/raspberrypi/rpi/rpi.c
clk: uniphier: add Media I/O clock driver for UniPhier SoCs
[u-boot] / board / raspberrypi / rpi / rpi.c
index ca8e86dead6c24b737bb1b3508cddf9492a6e5f9..7f4fe64385e4d31419713de109947151aa26759e 100644 (file)
@@ -1,24 +1,16 @@
 /*
- * (C) Copyright 2012-2013 Stephen Warren
+ * (C) Copyright 2012-2013,2015 Stephen Warren
  *
- * 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.
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #include <common.h>
 #include <config.h>
 #include <dm.h>
 #include <fdt_support.h>
+#include <fdt_simplefb.h>
 #include <lcd.h>
+#include <memalign.h>
 #include <mmc.h>
 #include <asm/gpio.h>
 #include <asm/arch/mbox.h>
@@ -38,7 +30,11 @@ U_BOOT_DEVICE(bcm2835_gpios) = {
 };
 
 static const struct pl01x_serial_platdata serial_platdata = {
+#ifdef CONFIG_BCM2836
+       .base = 0x3f201000,
+#else
        .base = 0x20201000,
+#endif
        .type = TYPE_PL011,
        .clock = 3000000,
 };
@@ -78,84 +74,141 @@ struct msg_get_clock_rate {
        u32 end_tag;
 };
 
-/* See comments in mbox.h for data source */
-static const struct {
+/*
+ * 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
+ * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922
+ *
+ * In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html
+ * ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi
+ * Foundation stated that the following source was accurate:
+ * https://github.com/AndrewFromMelbourne/raspberry_pi_revision
+ */
+struct rpi_model {
        const char *name;
        const char *fdtfile;
        bool has_onboard_eth;
-} models[] = {
-       [BCM2835_BOARD_REV_B_I2C0_2] = {
-               "Model B (no P5)",
-               "bcm2835-rpi-b-i2c0.dtb",
+};
+
+static const struct rpi_model rpi_model_unknown = {
+       "Unknown model",
+#ifdef CONFIG_BCM2836
+       "bcm2836-rpi-other.dtb",
+#else
+       "bcm2835-rpi-other.dtb",
+#endif
+       false,
+};
+
+static const struct rpi_model rpi_models_new_scheme[] = {
+       [0x4] = {
+               "2 Model B",
+               "bcm2836-rpi-2-b.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_B_I2C0_3] = {
-               "Model B (no P5)",
-               "bcm2835-rpi-b-i2c0.dtb",
-               true,
+       [0x9] = {
+               "Zero",
+               "bcm2835-rpi-zero.dtb",
+               false,
        },
-       [BCM2835_BOARD_REV_B_I2C1_4] = {
+};
+
+static const struct rpi_model rpi_models_old_scheme[] = {
+       [0x2] = {
                "Model B",
                "bcm2835-rpi-b.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_B_I2C1_5] = {
+       [0x3] = {
                "Model B",
                "bcm2835-rpi-b.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_B_I2C1_6] = {
-               "Model B",
-               "bcm2835-rpi-b.dtb",
+       [0x4] = {
+               "Model B rev2",
+               "bcm2835-rpi-b-rev2.dtb",
+               true,
+       },
+       [0x5] = {
+               "Model B rev2",
+               "bcm2835-rpi-b-rev2.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_A_7] = {
+       [0x6] = {
+               "Model B rev2",
+               "bcm2835-rpi-b-rev2.dtb",
+               true,
+       },
+       [0x7] = {
                "Model A",
                "bcm2835-rpi-a.dtb",
                false,
        },
-       [BCM2835_BOARD_REV_A_8] = {
+       [0x8] = {
                "Model A",
                "bcm2835-rpi-a.dtb",
                false,
        },
-       [BCM2835_BOARD_REV_A_9] = {
+       [0x9] = {
                "Model A",
                "bcm2835-rpi-a.dtb",
                false,
        },
-       [BCM2835_BOARD_REV_B_REV2_d] = {
+       [0xd] = {
                "Model B rev2",
                "bcm2835-rpi-b-rev2.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_B_REV2_e] = {
+       [0xe] = {
                "Model B rev2",
                "bcm2835-rpi-b-rev2.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_B_REV2_f] = {
+       [0xf] = {
                "Model B rev2",
                "bcm2835-rpi-b-rev2.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_B_PLUS] = {
+       [0x10] = {
+               "Model B+",
+               "bcm2835-rpi-b-plus.dtb",
+               true,
+       },
+       [0x11] = {
+               "Compute Module",
+               "bcm2835-rpi-cm.dtb",
+               false,
+       },
+       [0x12] = {
+               "Model A+",
+               "bcm2835-rpi-a-plus.dtb",
+               false,
+       },
+       [0x13] = {
                "Model B+",
                "bcm2835-rpi-b-plus.dtb",
                true,
        },
-       [BCM2835_BOARD_REV_CM] = {
+       [0x14] = {
                "Compute Module",
                "bcm2835-rpi-cm.dtb",
                false,
        },
+       [0x15] = {
+               "Model A+",
+               "bcm2835-rpi-a-plus.dtb",
+               false,
+       },
 };
 
-u32 rpi_board_rev = 0;
+static uint32_t revision;
+static uint32_t rev_scheme;
+static uint32_t rev_type;
+static const struct rpi_model *model;
 
 int dram_init(void)
 {
-       ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
+       ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1);
        int ret;
 
        BCM2835_MBOX_INIT_HDR(msg);
@@ -179,19 +232,16 @@ static void set_fdtfile(void)
        if (getenv("fdtfile"))
                return;
 
-       fdtfile = models[rpi_board_rev].fdtfile;
-       if (!fdtfile)
-               fdtfile = "bcm2835-rpi-other.dtb";
-
+       fdtfile = model->fdtfile;
        setenv("fdtfile", fdtfile);
 }
 
 static void set_usbethaddr(void)
 {
-       ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
+       ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
        int ret;
 
-       if (!models[rpi_board_rev].has_onboard_eth)
+       if (!model->has_onboard_eth)
                return;
 
        if (getenv("usbethaddr"))
@@ -209,19 +259,41 @@ static void set_usbethaddr(void)
 
        eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
 
+       if (!getenv("ethaddr"))
+               setenv("ethaddr", getenv("usbethaddr"));
+
        return;
 }
 
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+static void set_board_info(void)
+{
+       char s[11];
+
+       snprintf(s, sizeof(s), "0x%X", revision);
+       setenv("board_revision", s);
+       snprintf(s, sizeof(s), "%d", rev_scheme);
+       setenv("board_rev_scheme", s);
+       /* Can't rename this to board_rev_type since it's an ABI for scripts */
+       snprintf(s, sizeof(s), "0x%X", rev_type);
+       setenv("board_rev", s);
+       setenv("board_name", model->name);
+}
+#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
+
 int misc_init_r(void)
 {
        set_fdtfile();
        set_usbethaddr();
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+       set_board_info();
+#endif
        return 0;
 }
 
 static int power_on_module(u32 module)
 {
-       ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
+       ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
        int ret;
 
        BCM2835_MBOX_INIT_HDR(msg_pwr);
@@ -245,9 +317,10 @@ static int power_on_module(u32 module)
 
 static void get_board_rev(void)
 {
-       ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16);
+       ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
        int ret;
-       const char *name;
+       const struct rpi_model *models;
+       uint32_t models_count;
 
        BCM2835_MBOX_INIT_HDR(msg);
        BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
@@ -259,14 +332,40 @@ static void get_board_rev(void)
                return;
        }
 
-       rpi_board_rev = msg->get_board_rev.body.resp.rev;
-       if (rpi_board_rev >= ARRAY_SIZE(models))
-               rpi_board_rev = 0;
+       /*
+        * 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
+        */
+       revision = msg->get_board_rev.body.resp.rev;
+       if (revision & 0x800000) {
+               rev_scheme = 1;
+               rev_type = (revision >> 4) & 0xff;
+               models = rpi_models_new_scheme;
+               models_count = ARRAY_SIZE(rpi_models_new_scheme);
+       } else {
+               rev_scheme = 0;
+               rev_type = revision & 0xff;
+               models = rpi_models_old_scheme;
+               models_count = ARRAY_SIZE(rpi_models_old_scheme);
+       }
+       if (rev_type >= models_count) {
+               printf("RPI: Board rev 0x%x outside known range\n", rev_type);
+               model = &rpi_model_unknown;
+       } else if (!models[rev_type].name) {
+               printf("RPI: Board rev 0x%x unknown\n", rev_type);
+               model = &rpi_model_unknown;
+       } else {
+               model = &models[rev_type];
+       }
 
-       name = models[rpi_board_rev].name;
-       if (!name)
-               name = "Unknown model";
-       printf("RPI model: %s\n", name);
+       printf("RPI %s (0x%x)\n", model->name, revision);
 }
 
 int board_init(void)
@@ -280,7 +379,7 @@ int board_init(void)
 
 int board_mmc_init(bd_t *bis)
 {
-       ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
+       ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
        int ret;
 
        power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);