From a6d8854499cfab354345b46e5dde086ffeb3bd8b Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 8 Dec 2019 01:36:35 +0200 Subject: [PATCH] power: Add 5V regulator driver --- nyx/Makefile | 2 +- nyx/nyx_gui/power/regulator_5v.c | 67 ++++++++++++++++++++++++++++++++ nyx/nyx_gui/power/regulator_5v.h | 34 ++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 nyx/nyx_gui/power/regulator_5v.c create mode 100644 nyx/nyx_gui/power/regulator_5v.h diff --git a/nyx/Makefile b/nyx/Makefile index 31a58f5..0aff055 100644 --- a/nyx/Makefile +++ b/nyx/Makefile @@ -39,7 +39,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ bpmp.o clock.o cluster.o di.o gpio.o i2c.o mc.o sdram.o pinmux.o se.o smmu.o tsec.o uart.o \ fuse.o kfuse.o minerva.o \ sdmmc.o sdmmc_driver.o \ - bq24193.o max17050.o max7762x.o max77620-rtc.o \ + bq24193.o max17050.o max7762x.o max77620-rtc.o regulator_5v.o \ touch.o tmp451.o fan.o \ hw_init.o \ ) diff --git a/nyx/nyx_gui/power/regulator_5v.c b/nyx/nyx_gui/power/regulator_5v.c new file mode 100644 index 0000000..a65615a --- /dev/null +++ b/nyx/nyx_gui/power/regulator_5v.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2019 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 "../soc/gpio.h" +#include "../soc/pinmux.h" +#include "../soc/t210.h" +#include "../utils/types.h" + +static u8 reg_5v_dev = 0; + +void regulator_enable_5v(u8 dev) +{ + // The power supply selection from battery or USB is automatic. + if (!reg_5v_dev) + { + // Fan and Rail power from internal 5V regulator (battery). + PINMUX_AUX(PINMUX_AUX_SATA_LED_ACTIVE) = 1; + gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_GPIO); + gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_ENABLE); + gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_HIGH); + + // Fan and Rail power from USB 5V VDD. + PINMUX_AUX(PINMUX_AUX_USB_VBUS_EN0) = PINMUX_LPDR | 1; + gpio_config(GPIO_PORT_CC, GPIO_PIN_4, GPIO_MODE_GPIO); + gpio_output_enable(GPIO_PORT_CC, GPIO_PIN_4, GPIO_OUTPUT_ENABLE); + gpio_write(GPIO_PORT_CC, GPIO_PIN_4, GPIO_HIGH); + } + reg_5v_dev |= dev; +} + +void regulator_disable_5v(u8 dev) +{ + reg_5v_dev &= ~dev; + + if (!reg_5v_dev) + { + // Rail power from internal 5V regulator (battery). + gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_LOW); + gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_DISABLE); + gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_SPIO); + PINMUX_AUX(PINMUX_AUX_SATA_LED_ACTIVE) = PINMUX_PARKED | PINMUX_INPUT_ENABLE; + + // Rail power from USB 5V VDD. + gpio_write(GPIO_PORT_CC, GPIO_PIN_4, GPIO_LOW); + gpio_output_enable(GPIO_PORT_CC, GPIO_PIN_4, GPIO_OUTPUT_DISABLE); + gpio_config(GPIO_PORT_CC, GPIO_PIN_4, GPIO_MODE_SPIO); + PINMUX_AUX(PINMUX_AUX_USB_VBUS_EN0) = PINMUX_IO_HV | PINMUX_LPDR | PINMUX_PARKED | PINMUX_INPUT_ENABLE; + } +} + +bool regulator_get_5v_dev_enabled(u8 dev) +{ + return (reg_5v_dev & dev); +} diff --git a/nyx/nyx_gui/power/regulator_5v.h b/nyx/nyx_gui/power/regulator_5v.h new file mode 100644 index 0000000..7608881 --- /dev/null +++ b/nyx/nyx_gui/power/regulator_5v.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 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 . + */ + +#ifndef _REGULATOR_5V_H_ +#define _REGULATOR_5V_H_ + +#include "../utils/types.h" + +enum +{ + REGULATOR_5V_FAN = (1 << 0), + REGULATOR_5V_JC_R = (1 << 1), + REGULATOR_5V_JC_L = (1 << 2), + REGULATOR_5V_ALL = 0xFF +}; + +void regulator_enable_5v(u8 dev); +void regulator_disable_5v(u8 dev); +bool regulator_get_5v_dev_enabled(u8 dev); + +#endif \ No newline at end of file