2019-06-30 01:03:00 +00:00
|
|
|
/*
|
2020-03-14 07:24:24 +00:00
|
|
|
* Copyright (c) 2018-2020 CTCaer
|
2019-06-30 01:03:00 +00: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "hw_init.h"
|
|
|
|
#include "bpmp.h"
|
|
|
|
#include "clock.h"
|
|
|
|
#include "gpio.h"
|
|
|
|
#include "pmc.h"
|
|
|
|
#include "t210.h"
|
|
|
|
#include "../mem/minerva.h"
|
|
|
|
#include "../gfx/di.h"
|
|
|
|
#include "../input/touch.h"
|
2019-12-07 23:41:57 +00:00
|
|
|
#include "../power/regulator_5v.h"
|
2020-04-29 20:20:18 +00:00
|
|
|
#include "../storage/nx_sd.h"
|
2019-06-30 01:03:00 +00:00
|
|
|
#include "../storage/sdmmc.h"
|
2019-12-07 23:41:57 +00:00
|
|
|
#include "../thermal/fan.h"
|
2019-06-30 01:03:00 +00:00
|
|
|
#include "../utils/util.h"
|
|
|
|
|
2020-01-19 13:22:59 +00:00
|
|
|
extern volatile nyx_storage_t *nyx_str;
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
void reconfig_hw_workaround(bool extra_reconfig, u32 magic)
|
|
|
|
{
|
2019-12-07 23:41:57 +00:00
|
|
|
// Disable BPMP max clock.
|
2019-06-30 01:03:00 +00:00
|
|
|
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
|
|
|
|
|
2019-12-07 23:41:57 +00:00
|
|
|
// Deinit touchscreen and 5V regulators.
|
2019-06-30 01:03:00 +00:00
|
|
|
touch_power_off();
|
2019-12-07 23:41:57 +00:00
|
|
|
set_fan_duty(0);
|
|
|
|
regulator_disable_5v(REGULATOR_5V_ALL);
|
|
|
|
|
|
|
|
// Flush/disable MMU cache and set DRAM clock to 204MHz.
|
|
|
|
bpmp_mmu_disable();
|
|
|
|
minerva_change_freq(FREQ_204);
|
2020-01-14 21:41:15 +00:00
|
|
|
nyx_str->mtc_cfg.init_done = 0;
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
// Re-enable clocks to Audio Processing Engine as a workaround to hanging.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= (1 << 10); // Enable AHUB clock.
|
2019-09-12 20:08:38 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= (1 << 6); // Enable APE clock.
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
if (extra_reconfig)
|
|
|
|
{
|
|
|
|
msleep(10);
|
|
|
|
PMC(APBDEV_PMC_PWR_DET_VAL) |= PMC_PWR_DET_SDMMC1_IO_EN;
|
|
|
|
|
|
|
|
clock_disable_cl_dvfs();
|
|
|
|
|
|
|
|
// Disable Joy-con GPIOs.
|
|
|
|
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
|
|
|
|
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
|
|
|
|
gpio_config(GPIO_PORT_E, GPIO_PIN_6, GPIO_MODE_SPIO);
|
|
|
|
gpio_config(GPIO_PORT_H, GPIO_PIN_6, GPIO_MODE_SPIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Power off display.
|
|
|
|
display_end();
|
|
|
|
|
|
|
|
// Enable clock to USBD and init SDMMC1 to avoid hangs with bad hw inits.
|
|
|
|
if (magic == 0xBAADF00D)
|
|
|
|
{
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) |= (1 << 22);
|
2020-04-29 15:53:29 +00:00
|
|
|
sdmmc_init(&sd_sdmmc, SDMMC_1, SDMMC_POWER_3_3, SDMMC_BUS_WIDTH_1, SDHCI_TIMING_SD_ID, 0);
|
2019-06-30 01:03:00 +00:00
|
|
|
clock_disable_cl_dvfs();
|
|
|
|
|
|
|
|
msleep(200);
|
|
|
|
}
|
|
|
|
}
|