mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/9] ARM: rpi: move model initialisation to rpi-common
Date: Wed,  1 Mar 2017 15:31:29 +0100	[thread overview]
Message-ID: <20170301143137.11570-1-l.stach@pengutronix.de> (raw)

From: Enrico Joerns <ejo@pengutronix.de>

The Raspberry PIs use different versions schemes for the older and newer
variants. The decoding arrays for these schemes were split up in rpi.c
and rpi2.c. This is not required, as the appropriate versioning scheme
can be determined programmatically.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
lst: remove SoC string
---
 arch/arm/boards/raspberry-pi/Makefile     |  2 --
 arch/arm/boards/raspberry-pi/rpi-common.c | 57 ++++++++++++++++++++++++++-----
 arch/arm/boards/raspberry-pi/rpi.c        | 44 ------------------------
 arch/arm/boards/raspberry-pi/rpi.h        |  3 --
 arch/arm/boards/raspberry-pi/rpi2.c       | 21 ------------
 5 files changed, 48 insertions(+), 79 deletions(-)
 delete mode 100644 arch/arm/boards/raspberry-pi/rpi.c
 delete mode 100644 arch/arm/boards/raspberry-pi/rpi2.c

diff --git a/arch/arm/boards/raspberry-pi/Makefile b/arch/arm/boards/raspberry-pi/Makefile
index 7a3d7de241f0..a3e93eb73a32 100644
--- a/arch/arm/boards/raspberry-pi/Makefile
+++ b/arch/arm/boards/raspberry-pi/Makefile
@@ -1,4 +1,2 @@
 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
index 147fce9952ab..7441c06437dd 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -146,6 +146,13 @@ void rpi_add_led(void)
 		led_set_trigger(LED_TRIGGER_HEARTBEAT, &l->led);
 }
 
+void rpi_b_init(void)
+{
+	rpi_leds[0].gpio = 16;
+	rpi_leds[0].active_low = 1;
+	rpi_set_usbethaddr();
+}
+
 void rpi_b_plus_init(void)
 {
 	rpi_leds[0].gpio = 47;
@@ -153,12 +160,39 @@ void rpi_b_plus_init(void)
 	rpi_set_usbethaddr();
 }
 
+/* See comments in mbox.h for data source */
+const struct rpi_model rpi_models_old_scheme[] = {
+	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),
+	RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_4, "Model B", rpi_b_init),
+	RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_5, "Model B", rpi_b_init),
+	RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_6, "Model B", rpi_b_init),
+	RPI_MODEL(BCM2835_BOARD_REV_A_7, "Model A", NULL),
+	RPI_MODEL(BCM2835_BOARD_REV_A_8, "Model A", NULL),
+	RPI_MODEL(BCM2835_BOARD_REV_A_9, "Model A", NULL),
+	RPI_MODEL(BCM2835_BOARD_REV_B_REV2_d, "Model B rev2", rpi_b_init),
+	RPI_MODEL(BCM2835_BOARD_REV_B_REV2_e, "Model B rev2", rpi_b_init),
+	RPI_MODEL(BCM2835_BOARD_REV_B_REV2_f, "Model B rev2", rpi_b_init),
+	RPI_MODEL(BCM2835_BOARD_REV_B_PLUS, "Model B+", rpi_b_plus_init),
+	RPI_MODEL(BCM2835_BOARD_REV_CM, "Compute Module", NULL),
+	RPI_MODEL(BCM2835_BOARD_REV_A_PLUS, "Model A+", NULL),
+};
+
+const struct rpi_model rpi_models_new_scheme[] = {
+	RPI_MODEL(0, "Unknown model", NULL),
+	RPI_MODEL(BCM2836_BOARD_REV_2_B, "2 Model B", rpi_b_plus_init),
+};
+
 static int rpi_board_rev = 0;
+const struct rpi_model *model;
 
 static void rpi_get_board_rev(void)
 {
 	int ret;
 	char *name;
+	const struct rpi_model *rpi_models;
+	size_t rpi_models_size;
 
 	BCM2835_MBOX_STACK_ALIGN(struct msg_get_board_rev, msg);
 	BCM2835_MBOX_INIT_HDR(msg);
@@ -183,10 +217,17 @@ static void rpi_get_board_rev(void)
 	 * 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)
+	if (rpi_board_rev & 0x800000) {
 		rpi_board_rev = (rpi_board_rev >> 4) & 0xff;
-	else
+		rpi_models = rpi_models_new_scheme;
+		rpi_models_size = ARRAY_SIZE(rpi_models_new_scheme);
+
+	} else {
 		rpi_board_rev &= 0xff;
+		rpi_models = rpi_models_old_scheme;
+		rpi_models_size = ARRAY_SIZE(rpi_models_old_scheme);
+	}
+
 	if (rpi_board_rev >= rpi_models_size) {
 		printf("RPI: Board rev %u outside known range\n",
 		       rpi_board_rev);
@@ -201,8 +242,8 @@ static void rpi_get_board_rev(void)
 	if (!rpi_board_rev)
 		goto unknown_rev;
 
-	name = basprintf("RaspberryPi %s %s",
-			   rpi_models[rpi_board_rev].name, rpi_model_string);
+	model = &rpi_models[rpi_board_rev];
+	name = basprintf("RaspberryPi %s", model->name);
 	barebox_set_model(name);
 	free(name);
 
@@ -210,17 +251,15 @@ static void rpi_get_board_rev(void)
 
 unknown_rev:
 	rpi_board_rev = 0;
-	name = basprintf("RaspberryPi %s", rpi_model_string);
-	barebox_set_model(name);
-	free(name);
+	barebox_set_model("RaspberryPi (unknown rev)");
 }
 
 static void rpi_model_init(void)
 {
-	if (!rpi_models[rpi_board_rev].init)
+	if (!model->init)
 		return;
 
-	rpi_models[rpi_board_rev].init();
+	model->init();
 	rpi_add_led();
 }
 
diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
deleted file mode 100644
index dd2ad7f5a519..000000000000
--- a/arch/arm/boards/raspberry-pi/rpi.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2009 Carlo Caione <carlo@carlocaione.org>
- *
- * 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"
-
-static void rpi_b_init(void)
-{
-	rpi_leds[0].gpio = 16;
-	rpi_leds[0].active_low = 1;
-	rpi_set_usbethaddr();
-}
-
-/* See comments in mbox.h for data source */
-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),
-	RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_4, "Model B", rpi_b_init),
-	RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_5, "Model B", rpi_b_init),
-	RPI_MODEL(BCM2835_BOARD_REV_B_I2C1_6, "Model B", rpi_b_init),
-	RPI_MODEL(BCM2835_BOARD_REV_A_7, "Model A", NULL),
-	RPI_MODEL(BCM2835_BOARD_REV_A_8, "Model A", NULL),
-	RPI_MODEL(BCM2835_BOARD_REV_A_9, "Model A", NULL),
-	RPI_MODEL(BCM2835_BOARD_REV_B_REV2_d, "Model B rev2", rpi_b_init),
-	RPI_MODEL(BCM2835_BOARD_REV_B_REV2_e, "Model B rev2", rpi_b_init),
-	RPI_MODEL(BCM2835_BOARD_REV_B_REV2_f, "Model B rev2", rpi_b_init),
-	RPI_MODEL(BCM2835_BOARD_REV_B_PLUS, "Model B+", rpi_b_plus_init),
-	RPI_MODEL(BCM2835_BOARD_REV_CM, "Compute Module", NULL),
-	RPI_MODEL(BCM2835_BOARD_REV_A_PLUS, "Model A+", NULL),
-};
-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
index 739cdee1b3ae..dd32fee80950 100644
--- a/arch/arm/boards/raspberry-pi/rpi.h
+++ b/arch/arm/boards/raspberry-pi/rpi.h
@@ -17,9 +17,6 @@ struct rpi_model {
 	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);
diff --git a/arch/arm/boards/raspberry-pi/rpi2.c b/arch/arm/boards/raspberry-pi/rpi2.c
deleted file mode 100644
index 2cfc06f8a6a9..000000000000
--- a/arch/arm/boards/raspberry-pi/rpi2.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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)";
-- 
2.11.0


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

             reply	other threads:[~2017-03-01 14:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01 14:31 Lucas Stach [this message]
2017-03-01 14:31 ` [PATCH 2/9] ARM: rpi: move model detection before console init Lucas Stach
2017-03-01 14:31 ` [PATCH 3/9] ARM: rpi: convert mailbox interface to regular driver Lucas Stach
2017-03-01 14:31 ` [PATCH 4/9] ARM: rpi: convert watchdog/reset " Lucas Stach
2017-03-01 14:31 ` [PATCH 5/9] clocksource: bcm2835: use clock-frequency property when available Lucas Stach
2017-03-01 14:31 ` [PATCH 6/9] mci-bcm2835: enable devicetree probing Lucas Stach
2017-03-01 14:31 ` [PATCH 7/9] ARM: rpi: always build relocatable image Lucas Stach
2017-03-01 14:31 ` [PATCH 8/9] ARM: rpi: move debug UART base selection to Kconfig Lucas Stach
2017-03-01 14:31 ` [PATCH 9/9] ARM: rpi: switch to DT probe and multi-image build Lucas Stach
2017-03-02  8:11 ` [PATCH 1/9] ARM: rpi: move model initialisation to rpi-common Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170301143137.11570-1-l.stach@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox