Skip to content

Commit

Permalink
[board] 100ask-ros support pmu and smhc
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Jan 10, 2024
1 parent fd54e52 commit 0916fce
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 7 deletions.
2 changes: 2 additions & 0 deletions board/100ask-ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ set(APP_COMMON_SOURCE
add_subdirectory(hello_world)

add_subdirectory(init_dram)

add_subdirectory(smhc_test)
4 changes: 2 additions & 2 deletions board/100ask-ros/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ sunxi_i2c_t i2c_pmu = {
.base = SUNXI_RTWI_BASE,
.id = SUNXI_R_I2C0,
.speed = 4000000,
.gpio_scl = {GPIO_PIN(GPIO_PORTL, 0), GPIO_PERIPH_MUX3},
.gpio_sda = {GPIO_PIN(GPIO_PORTL, 1), GPIO_PERIPH_MUX3},
.gpio_scl = {GPIO_PIN(GPIO_PORTL, 0), GPIO_PERIPH_MUX2},
.gpio_sda = {GPIO_PIN(GPIO_PORTL, 1), GPIO_PERIPH_MUX2},
};
26 changes: 25 additions & 1 deletion board/100ask-ros/init_dram/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

extern void set_cpu_poweroff(void);
static void set_pmu_fin_voltage(char *power_name, uint32_t voltage) {
int set_vol = voltage;
int temp_vol, src_vol = pmu_axp2202_get_vol(&i2c_pmu, power_name);
if (src_vol > voltage) {
for (temp_vol = src_vol; temp_vol >= voltage; temp_vol -= 50) {
pmu_axp2202_set_vol(&i2c_pmu, power_name, temp_vol, 1);
}
} else if (src_vol < voltage) {
for (temp_vol = src_vol; temp_vol <= voltage; temp_vol += 50) {
pmu_axp2202_set_vol(&i2c_pmu, power_name, temp_vol, 1);
}
}
mdelay(30); /* Delay 300ms for pmu bootup */
}

int main(void) {
sunxi_serial_init(&uart_dbg);
Expand All @@ -29,6 +42,17 @@ int main(void) {

sunxi_clk_dump();

sunxi_i2c_init(&i2c_pmu);

pmu_axp2202_init(&i2c_pmu);

set_pmu_fin_voltage("dcdc1", 1100);
set_pmu_fin_voltage("dcdc3", 1160);

mdelay(30); /* Delay 300ms for pmu bootup */

pmu_axp2202_dump(&i2c_pmu);

printk(LOG_LEVEL_INFO, "DRAM: DRAM Size = %dMB\n", sunxi_dram_init(NULL));

sunxi_clk_dump();
Expand Down
5 changes: 5 additions & 0 deletions board/100ask-ros/smhc_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

add_syterkit_app(smhc_test
main.c
)
80 changes: 80 additions & 0 deletions board/100ask-ros/smhc_test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

#include <log.h>

#include <common.h>

#include <mmu.h>

#include <sys-dram.h>
#include <sys-gpio.h>
#include <sys-i2c.h>
#include <sys-sid.h>
#include <sys-sdcard.h>
#include <sys-spi.h>
#include <sys-uart.h>

extern sunxi_serial_t uart_dbg;

extern sunxi_i2c_t i2c_pmu;

static void set_pmu_fin_voltage(char *power_name, uint32_t voltage) {
int set_vol = voltage;
int temp_vol, src_vol = pmu_axp2202_get_vol(&i2c_pmu, power_name);
if (src_vol > voltage) {
for (temp_vol = src_vol; temp_vol >= voltage; temp_vol -= 50) {
pmu_axp2202_set_vol(&i2c_pmu, power_name, temp_vol, 1);
}
} else if (src_vol < voltage) {
for (temp_vol = src_vol; temp_vol <= voltage; temp_vol += 50) {
pmu_axp2202_set_vol(&i2c_pmu, power_name, temp_vol, 1);
}
}
mdelay(30); /* Delay 300ms for pmu bootup */
}

int main(void) {
sunxi_serial_init(&uart_dbg);

show_banner();

sunxi_clk_init();

sunxi_clk_dump();

sunxi_i2c_init(&i2c_pmu);

pmu_axp2202_init(&i2c_pmu);

set_pmu_fin_voltage("dcdc1", 1100);
set_pmu_fin_voltage("dcdc3", 1100);

pmu_axp2202_dump(&i2c_pmu);

printk(LOG_LEVEL_INFO, "DRAM: DRAM Size = %dMB\n", sunxi_dram_init(NULL));

sunxi_clk_dump();

/* Initialize the SD host controller. */
if (sunxi_sdhci_init(&sdhci0) != 0) {
printk(LOG_LEVEL_ERROR, "SMHC: %s controller init failed\n", sdhci0.name);
} else {
printk(LOG_LEVEL_INFO, "SMHC: %s controller initialized\n", sdhci0.name);
}

/* Initialize the SD card and check if initialization is successful. */
if (sdmmc_init(&card0, &sdhci0) != 0) {
printk(LOG_LEVEL_WARNING, "SMHC: init failed\n");
}

printk(LOG_LEVEL_DEBUG, "Card OK!\n");

abort();

return 0;
}
2 changes: 1 addition & 1 deletion include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum {
};

#ifndef LOG_LEVEL_DEFAULT
#define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
#define LOG_LEVEL_DEFAULT LOG_LEVEL_TRACE
#endif

void set_timer_count();
Expand Down
7 changes: 4 additions & 3 deletions src/drivers/pmu/axp2202.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ int pmu_axp2202_init(sunxi_i2c_t *i2c_dev) {
if (sunxi_i2c_read(i2c_dev, AXP2202_B_RUNTIME_ADDR, AXP2202_CHIP_ID_EXT, &axp_val)) {
/* AXP717B probe fail, Try to probe AXP717C */
if (sunxi_i2c_read(i2c_dev, AXP2202_C_RUNTIME_ADDR, AXP2202_CHIP_ID_EXT, &axp_val)) {
/* AXP717B probe fail */
/* AXP717C probe fail */
printk(LOG_LEVEL_WARNING, "PMU: AXP2202 PMU Read error\n");
return -1;
} else {
AXP2202_RUNTIME_ADDR = AXP2202_C_RUNTIME_ADDR;
Expand All @@ -113,10 +114,10 @@ int pmu_axp2202_init(sunxi_i2c_t *i2c_dev) {
}

if (axp_val != 0x02) {
printk(LOG_LEVEL_INFO, "PMU: AXP PMU Check error\n");
printk(LOG_LEVEL_WARNING, "PMU: AXP PMU Check error\n");
return -1;
} else {
printk(LOG_LEVEL_INFO, "PMU: Found AXP717 PMU\n");
printk(LOG_LEVEL_INFO, "PMU: Found AXP717 PMU, Addr 0x%02x\n", AXP2202_RUNTIME_ADDR);
}

/* limit run current to 2A */
Expand Down

0 comments on commit 0916fce

Please sign in to comment.