2019-04-29 17:43:48 +01:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-04-29 17:43:48 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-05-11 23:02:10 +01:00
|
|
|
#include <stratosphere.hpp>
|
2019-06-22 19:34:18 +01:00
|
|
|
#include "gpio_initial_configuration.hpp"
|
|
|
|
#include "gpio_utils.hpp"
|
2019-04-29 17:43:48 +01:00
|
|
|
|
2020-10-30 18:54:30 +00:00
|
|
|
namespace ams::boot::gpio {
|
2019-04-29 17:43:48 +01:00
|
|
|
|
2019-06-22 08:10:21 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct InitialConfig {
|
|
|
|
u32 pad_name;
|
|
|
|
GpioDirection direction;
|
|
|
|
GpioValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Include all initial configuration definitions. */
|
2019-06-22 19:34:18 +01: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"
|
2019-06-22 08:10:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetInitialConfiguration() {
|
|
|
|
const InitialConfig *configs = nullptr;
|
|
|
|
size_t num_configs = 0;
|
2019-06-22 19:34:18 +01:00
|
|
|
const auto hw_type = spl::GetHardwareType();
|
2019-10-16 22:28:19 +01:00
|
|
|
const auto hos_ver = hos::GetVersion();
|
2019-06-22 08:10:21 +01:00
|
|
|
|
|
|
|
/* Choose GPIO map. */
|
2020-04-14 06:19:44 +01:00
|
|
|
if (hos_ver >= hos::Version_2_0_0) {
|
2019-06-22 08:10:21 +01:00
|
|
|
switch (hw_type) {
|
|
|
|
case spl::HardwareType::Icosa:
|
|
|
|
{
|
2020-04-14 06:19:44 +01:00
|
|
|
if (hos_ver >= hos::Version_4_0_0) {
|
2020-02-24 16:21:31 +00:00
|
|
|
configs = InitialConfigsIcosa4x;
|
2019-06-22 08:10:21 +01:00
|
|
|
num_configs = NumInitialConfigsIcosa4x;
|
|
|
|
} else {
|
2020-02-24 16:21:31 +00:00
|
|
|
configs = InitialConfigsIcosa;
|
2019-06-22 08:10:21 +01:00
|
|
|
num_configs = NumInitialConfigsIcosa;
|
|
|
|
}
|
2019-04-29 17:43:48 +01:00
|
|
|
}
|
2019-06-22 08:10:21 +01:00
|
|
|
break;
|
|
|
|
case spl::HardwareType::Copper:
|
2020-02-24 16:21:31 +00:00
|
|
|
configs = InitialConfigsCopper;
|
2019-06-22 08:10:21 +01:00
|
|
|
num_configs = NumInitialConfigsCopper;
|
|
|
|
break;
|
|
|
|
case spl::HardwareType::Hoag:
|
2020-02-24 16:21:31 +00:00
|
|
|
configs = InitialConfigsHoag;
|
2019-06-22 08:10:21 +01:00
|
|
|
num_configs = NumInitialConfigsHoag;
|
|
|
|
break;
|
|
|
|
case spl::HardwareType::Iowa:
|
2020-02-24 16:21:31 +00:00
|
|
|
configs = InitialConfigsIowa;
|
2019-06-22 08:10:21 +01:00
|
|
|
num_configs = NumInitialConfigsIowa;
|
2020-02-24 17:45:40 +00:00
|
|
|
break;
|
2020-02-24 16:21:31 +00:00
|
|
|
case spl::HardwareType::Calcio:
|
|
|
|
configs = InitialConfigsCalcio;
|
|
|
|
num_configs = NumInitialConfigsCalcio;
|
2019-06-22 08:10:21 +01:00
|
|
|
break;
|
2019-09-28 23:13:20 +01:00
|
|
|
/* Unknown hardware type, we can't proceed. */
|
2019-10-24 10:30:10 +01:00
|
|
|
AMS_UNREACHABLE_DEFAULT_CASE();
|
2019-06-22 08:10:21 +01:00
|
|
|
}
|
|
|
|
} 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;
|
2019-06-22 08:10:21 +01:00
|
|
|
num_configs = NumInitialConfigsIcosa;
|
2019-04-29 17:43:48 +01:00
|
|
|
}
|
|
|
|
|
2019-06-22 08:10:21 +01:00
|
|
|
/* Ensure we found an appropriate config. */
|
2020-02-23 07:05:14 +00:00
|
|
|
AMS_ABORT_UNLESS(configs != nullptr);
|
2019-04-29 17:43:48 +01:00
|
|
|
|
2019-06-22 08:10:21 +01:00
|
|
|
for (size_t i = 0; i < num_configs; i++) {
|
|
|
|
/* Configure the GPIO. */
|
|
|
|
Configure(configs[i].pad_name);
|
2019-04-29 17:43:48 +01:00
|
|
|
|
2019-06-22 08:10:21 +01:00
|
|
|
/* Set the GPIO's direction. */
|
|
|
|
SetDirection(configs[i].pad_name, configs[i].direction);
|
2019-04-29 17:43:48 +01:00
|
|
|
|
2019-06-22 08:10:21 +01:00
|
|
|
if (configs[i].direction == GpioDirection_Output) {
|
|
|
|
/* Set the GPIO's value. */
|
|
|
|
SetValue(configs[i].pad_name, configs[i].value);
|
|
|
|
}
|
2019-05-12 11:49:16 +01:00
|
|
|
}
|
2019-04-29 17:43:48 +01:00
|
|
|
}
|
2019-06-22 08:10:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|