sunxi-tools/uart0-helloworld-sdboot.c

86 lines
2.6 KiB
C
Raw Normal View History

/*
* 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+
*/
#include "bare-metal.h"
int main(void)
{
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);
uart0_init(soc);
uart0_puts("\nHello from Allwinner ");
uart0_puts(soc->name);
uart0_puts("!\n");
switch (get_boot_device(soc)) {
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;
}