Atmosphere/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp

104 lines
3.6 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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/>.
*/
2019-06-22 19:23:46 +00:00
#include <stratosphere/spl.hpp>
2019-06-22 18:34:18 +00:00
#include "gpio_initial_configuration.hpp"
#include "gpio_utils.hpp"
namespace ams::gpio {
namespace {
struct InitialConfig {
u32 pad_name;
GpioDirection direction;
GpioValue value;
};
/* Include all initial configuration definitions. */
2019-06-22 18:34:18 +00:00
#include "gpio_initial_configuration_icosa.inc"
#include "gpio_initial_configuration_copper.inc"
#include "gpio_initial_configuration_hoag.inc"
#include "gpio_initial_configuration_iowa.inc"
2020-02-24 16:21:31 +00:00
#include "gpio_initial_configuration_calcio.inc"
}
void SetInitialConfiguration() {
const InitialConfig *configs = nullptr;
size_t num_configs = 0;
2019-06-22 18:34:18 +00:00
const auto hw_type = spl::GetHardwareType();
2019-10-16 21:28:19 +00:00
const auto hos_ver = hos::GetVersion();
/* Choose GPIO map. */
2019-10-16 21:28:19 +00:00
if (hos_ver >= hos::Version_200) {
switch (hw_type) {
case spl::HardwareType::Icosa:
{
2019-10-16 21:28:19 +00:00
if (hos_ver >= hos::Version_400) {
2020-02-24 16:21:31 +00:00
configs = InitialConfigsIcosa4x;
num_configs = NumInitialConfigsIcosa4x;
} else {
2020-02-24 16:21:31 +00:00
configs = InitialConfigsIcosa;
num_configs = NumInitialConfigsIcosa;
}
}
break;
case spl::HardwareType::Copper:
2020-02-24 16:21:31 +00:00
configs = InitialConfigsCopper;
num_configs = NumInitialConfigsCopper;
break;
case spl::HardwareType::Hoag:
2020-02-24 16:21:31 +00:00
configs = InitialConfigsHoag;
num_configs = NumInitialConfigsHoag;
break;
case spl::HardwareType::Iowa:
2020-02-24 16:21:31 +00:00
configs = InitialConfigsIowa;
num_configs = NumInitialConfigsIowa;
2020-02-24 16:21:31 +00:00
case spl::HardwareType::Calcio:
configs = InitialConfigsCalcio;
num_configs = NumInitialConfigsCalcio;
break;
/* Unknown hardware type, we can't proceed. */
AMS_UNREACHABLE_DEFAULT_CASE();
}
} else {
/* Until 2.0.0, the GPIO map for Icosa was used for all hardware types. */
2020-02-24 16:21:31 +00:00
configs = InitialConfigsIcosa;
num_configs = NumInitialConfigsIcosa;
}
/* Ensure we found an appropriate config. */
2020-02-23 07:05:14 +00:00
AMS_ABORT_UNLESS(configs != nullptr);
for (size_t i = 0; i < num_configs; i++) {
/* Configure the GPIO. */
Configure(configs[i].pad_name);
/* Set the GPIO's direction. */
SetDirection(configs[i].pad_name, configs[i].direction);
if (configs[i].direction == GpioDirection_Output) {
/* Set the GPIO's value. */
SetValue(configs[i].pad_name, configs[i].value);
}
}
}
}