2016-05-12 01:54:04 +03:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2016 Siarhei Siamashka <siarhei.siamashka@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Partially based on the uart code from ar100-info
|
|
|
|
|
*
|
|
|
|
|
* (C) Copyright 2013 Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Partially based on the sunxi gpio code from U-Boot
|
|
|
|
|
*
|
|
|
|
|
* (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net>
|
|
|
|
|
*
|
|
|
|
|
* Based on earlier arch/arm/cpu/armv7/sunxi/gpio.c:
|
|
|
|
|
*
|
|
|
|
|
* (C) Copyright 2007-2011
|
|
|
|
|
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
|
|
|
|
|
* Tom Cubie <tangliang@allwinnertech.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-16 12:15:52 +02:00
|
|
|
#include "bare-metal.h"
|
2016-05-12 01:54:04 +03:00
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
uart0-helloworld-sdboot: introduce SoC table
At the moment the various SoC specific settings are scattered throughout
the file, using mostly chains of "soc_is_xxx()" macros. While this might
have initially worked with just a few SoCs supported, this is becoming
more and more messy with our currently 22 supported SoCs. Also it is not
easy to support new SoCs, and it looks like some SoCs are already broken
(for instance the A80 is missing the GPIO setup).
The make the code more readable and allow easier addition of future
SoCs, let's add a table, where each entry holds all the various
information we will need to know for each chip: the UART base address,
the clock base address, the clock type, etc. This is conceptually
similar to what sunxi-fel does in soc_info.c.
To make review easier and avoid any regressions, add the table member by
member, and convert the various "subsystems" over one by one.
We start with the most simple table containing the SoC ID and the SoC
name (as a string), and use that already when printing the SoC name.
Since some SoCs share the same SoC ID, add a "flags" member and a in
there a variants bit, and set this accordingly for the four SoCs that
need it.
The soc_detection_init() function gets re-written (and renamed), to
return a pointer into the table, so that the other functions can use the
information there directly.
Signed-off-by: Andre Przywara <osp@andrep.de>
2024-08-23 17:32:55 +01:00
|
|
|
const struct soc_info *soc = sunxi_detect_soc();
|
|
|
|
|
|
|
|
|
|
if (soc == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
uart0-helloworld-sdboot: add GPIO data to the SoC table
To make the UART signal appear on the SoC pins, we have to select two
pins from the supported output pins and set up their pinmux to connect
to the UART peripheral.
As the name suggests, uart0-helloworld-sdboot always uses UART0, which
is used as a debug UART on most boards, and is also available as a
multiplex on the SD card pins, to be used with a breakout board.
At the moment there is a large if/else cascade, with each branch calling
three GPIO setup functions, with the right arguments for each SoC.
While this is easily extendable with copy&paste, it is very repetetive
and duplicates quite some code.
Use our new SoC table to put the pin number for the TX pin and the
required pinmux value in there, alongside the PIO base address. The RX
pin is so far always the pin after the TX pin, so we just need to store
one pin. We also store a flag marking the PIO IP generation for each
SoC, so we can just differentiate this easily in the GPIO setup
functions.
This also uses the opportunity to get rid of the idea to assign some
names to the pinmux values, when they are just seemingly random SoC
specific numbers. Instead just use a macro name with that number in it,
to make it obvious that this is the mux value, but don't try to put some
deeper meaning into them.
On one SoC we decided to use the SD card pinmux, which is always on pins
PF2 and PF4. Add a flag to allow a SoC to default to those pins.
Also remove the unneeded GPIO functions, and mark the rest of them
as static.
Signed-off-by: Andre Przywara <osp@andrep.de>
2024-08-23 20:18:45 +01:00
|
|
|
gpio_init(soc);
|
2024-08-23 19:51:41 +01:00
|
|
|
uart0_init(soc);
|
2016-05-12 01:54:04 +03:00
|
|
|
|
uart0-helloworld-sdboot: introduce SoC table
At the moment the various SoC specific settings are scattered throughout
the file, using mostly chains of "soc_is_xxx()" macros. While this might
have initially worked with just a few SoCs supported, this is becoming
more and more messy with our currently 22 supported SoCs. Also it is not
easy to support new SoCs, and it looks like some SoCs are already broken
(for instance the A80 is missing the GPIO setup).
The make the code more readable and allow easier addition of future
SoCs, let's add a table, where each entry holds all the various
information we will need to know for each chip: the UART base address,
the clock base address, the clock type, etc. This is conceptually
similar to what sunxi-fel does in soc_info.c.
To make review easier and avoid any regressions, add the table member by
member, and convert the various "subsystems" over one by one.
We start with the most simple table containing the SoC ID and the SoC
name (as a string), and use that already when printing the SoC name.
Since some SoCs share the same SoC ID, add a "flags" member and a in
there a variants bit, and set this accordingly for the four SoCs that
need it.
The soc_detection_init() function gets re-written (and renamed), to
return a pointer into the table, so that the other functions can use the
information there directly.
Signed-off-by: Andre Przywara <osp@andrep.de>
2024-08-23 17:32:55 +01:00
|
|
|
uart0_puts("\nHello from Allwinner ");
|
2025-04-16 12:22:49 +02:00
|
|
|
uart0_puts(soc->name);
|
uart0-helloworld-sdboot: introduce SoC table
At the moment the various SoC specific settings are scattered throughout
the file, using mostly chains of "soc_is_xxx()" macros. While this might
have initially worked with just a few SoCs supported, this is becoming
more and more messy with our currently 22 supported SoCs. Also it is not
easy to support new SoCs, and it looks like some SoCs are already broken
(for instance the A80 is missing the GPIO setup).
The make the code more readable and allow easier addition of future
SoCs, let's add a table, where each entry holds all the various
information we will need to know for each chip: the UART base address,
the clock base address, the clock type, etc. This is conceptually
similar to what sunxi-fel does in soc_info.c.
To make review easier and avoid any regressions, add the table member by
member, and convert the various "subsystems" over one by one.
We start with the most simple table containing the SoC ID and the SoC
name (as a string), and use that already when printing the SoC name.
Since some SoCs share the same SoC ID, add a "flags" member and a in
there a variants bit, and set this accordingly for the four SoCs that
need it.
The soc_detection_init() function gets re-written (and renamed), to
return a pointer into the table, so that the other functions can use the
information there directly.
Signed-off-by: Andre Przywara <osp@andrep.de>
2024-08-23 17:32:55 +01:00
|
|
|
uart0_puts("!\n");
|
2016-05-12 01:54:04 +03:00
|
|
|
|
2024-08-23 20:19:20 +01:00
|
|
|
switch (get_boot_device(soc)) {
|
2016-05-12 01:54:04 +03:00
|
|
|
case BOOT_DEVICE_FEL:
|
|
|
|
|
uart0_puts("Returning back to FEL.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
case BOOT_DEVICE_MMC0:
|
|
|
|
|
uart0_puts("Booted from MMC0, entering an infinite loop.\n");
|
|
|
|
|
while (1) {}
|
|
|
|
|
case BOOT_DEVICE_SPI:
|
|
|
|
|
uart0_puts("Booted from SPI0, entering an infinite loop.\n");
|
|
|
|
|
while (1) {}
|
|
|
|
|
default:
|
|
|
|
|
uart0_puts("Booted from unknown media, entering an infinite loop.\n");
|
|
|
|
|
while (1) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|