diff --git a/Makefile b/Makefile index fb66b0a..13a04c3 100755 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \ # Hardware. OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ bpmp.o ccplex.o clock.o di.o gpio.o i2c.o irq.o mc.o sdram.o \ - pinmux.o se.o smmu.o tsec.o uart.o \ + pinmux.o pmc.o se.o smmu.o tsec.o uart.o \ fuse.o kfuse.o minerva.o \ sdmmc.o sdmmc_driver.o emummc.o nx_emmc.o nx_sd.o \ bq24193.o max17050.o max7762x.o max77620-rtc.o \ diff --git a/bdk/soc/ccplex.c b/bdk/soc/ccplex.c index 785cdc8..2644455 100644 --- a/bdk/soc/ccplex.c +++ b/bdk/soc/ccplex.c @@ -17,11 +17,11 @@ #include #include #include -#include #include #include #include #include +#include void _ccplex_enable_power() { @@ -40,39 +40,6 @@ void _ccplex_enable_power() i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_VOUT_DVS_REG, MAX77621_VOUT_ENABLE | MAX77621_VOUT_0_95V); } -int _ccplex_pmc_enable_partition(u32 part, int enable) -{ - u32 part_mask = 1 << part; - u32 desired_state = enable << part; - - // Check if the partition has the state we want. - if ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) == desired_state) - return 1; - - u32 i = 5001; - while (PMC(APBDEV_PMC_PWRGATE_TOGGLE) & 0x100) - { - usleep(1); - i--; - if (i < 1) - return 0; - } - - // Toggle power gating. - PMC(APBDEV_PMC_PWRGATE_TOGGLE) = part | 0x100; - - i = 5001; - while (i > 0) - { - if ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) == desired_state) - break; - usleep(1); - i--; - } - - return 1; -} - void ccplex_boot_cpu0(u32 entry) { // Set ACTIVE_CLUSER to FAST. @@ -107,11 +74,11 @@ void ccplex_boot_cpu0(u32 entry) CLOCK(CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2) &= 0xFFFFF000; // Enable CPU rail. - _ccplex_pmc_enable_partition(0, 1); - // Enable cluster 0 non-CPU. - _ccplex_pmc_enable_partition(15, 1); - // Enable CE0. - _ccplex_pmc_enable_partition(14, 1); + pmc_enable_partition(0, 1); + // Enable cluster 0 non-CPU rail. + pmc_enable_partition(15, 1); + // Enable CE0 rail. + pmc_enable_partition(14, 1); // Request and wait for RAM repair. FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) = 1; diff --git a/bdk/soc/pmc.c b/bdk/soc/pmc.c new file mode 100644 index 0000000..835c6c8 --- /dev/null +++ b/bdk/soc/pmc.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 CTCaer + * + * 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 . + */ + +#include +#include +#include + +int pmc_enable_partition(u32 part, int enable) +{ + u32 part_mask = 1 << part; + u32 desired_state = enable << part; + + // Check if the partition has the state we want. + if ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) == desired_state) + return 1; + + u32 i = 5001; + while (PMC(APBDEV_PMC_PWRGATE_TOGGLE) & 0x100) + { + usleep(1); + i--; + if (i < 1) + return 0; + } + + // Toggle power gating. + PMC(APBDEV_PMC_PWRGATE_TOGGLE) = part | 0x100; + + i = 5001; + while (i > 0) + { + if ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) == desired_state) + break; + usleep(1); + i--; + } + + return 1; +} diff --git a/bdk/soc/pmc.h b/bdk/soc/pmc.h index 7df7922..a736935 100644 --- a/bdk/soc/pmc.h +++ b/bdk/soc/pmc.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2018 naehrwert * Copyright (c) 2018 st4rk + * Copyright (c) 2018-2020 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -18,6 +19,8 @@ #ifndef _PMC_H_ #define _PMC_H_ +#include + /*! PMC registers. */ #define APBDEV_PMC_CNTRL 0x0 #define PMC_CNTRL_MAIN_RST (1 << 4) @@ -84,4 +87,6 @@ #define APBDEV_PMC_SCRATCH190 0x818 #define APBDEV_PMC_SCRATCH200 0x840 +int pmc_enable_partition(u32 part, int enable); + #endif diff --git a/nyx/Makefile b/nyx/Makefile index c0872b7..1c65a78 100644 --- a/nyx/Makefile +++ b/nyx/Makefile @@ -33,7 +33,7 @@ OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \ # Hardware. OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ - bpmp.o ccplex.o clock.o di.o gpio.o i2c.o irq.o pinmux.o se.o smmu.o tsec.o uart.o \ + bpmp.o ccplex.o clock.o di.o gpio.o i2c.o irq.o pinmux.o pmc.o se.o smmu.o tsec.o uart.o \ fuse.o kfuse.o \ mc.o sdram.o minerva.o ramdisk.o \ sdmmc.o sdmmc_driver.o nx_emmc.o nx_emmc_bis.o nx_sd.o \