diff --git a/cirrus/cp9314/CMakeLists.txt b/cirrus/cp9314/CMakeLists.txt new file mode 100644 index 000000000..611420062 --- /dev/null +++ b/cirrus/cp9314/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(cp9314) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/cirrus/cp9314/boards/nucleo_f401re.overlay b/cirrus/cp9314/boards/nucleo_f401re.overlay new file mode 100644 index 000000000..4d05fa417 --- /dev/null +++ b/cirrus/cp9314/boards/nucleo_f401re.overlay @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Cirrus Logic, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + #include + #include + +&arduino_i2c { + status = "okay"; + clock-frequency = ; + + cp9314: cp9314@72 { + compatible = "cirrus,cp9314"; + reg = <0x72>; + status = "okay"; + + cirrus,initial-switched-capacitor-mode = "2:1"; + + cirrus,en-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>; + }; + + cp9314_dev2: cp9314@73 { + compatible = "cirrus,cp9314"; + reg = <0x73>; + status = "okay"; + + cirrus,initial-switched-capacitor-mode = "2:1"; + + cirrus,en-gpios = <&arduino_header 8 GPIO_ACTIVE_HIGH>; + }; +}; diff --git a/cirrus/cp9314/prj.conf b/cirrus/cp9314/prj.conf new file mode 100644 index 000000000..e99ee86b0 --- /dev/null +++ b/cirrus/cp9314/prj.conf @@ -0,0 +1,5 @@ +CONFIG_I2C=y +CONFIG_LOG=y +CONFIG_REGULATOR=y +CONFIG_REGULATOR_CP9314=y +CONFIG_CBPRINTF_FP_SUPPORT=y \ No newline at end of file diff --git a/cirrus/cp9314/src/main.c b/cirrus/cp9314/src/main.c new file mode 100644 index 000000000..d55058535 --- /dev/null +++ b/cirrus/cp9314/src/main.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 Cirrus Logic, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "zephyr/sys/printk.h" +#include +#include +#include +#include + +int main(void) +{ + const struct device *dev2 = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cp9314_dev2)); + const struct device *host = DEVICE_DT_GET(DT_NODELABEL(cp9314)); + regulator_error_flags_t flags; + int ret; + + if (host == NULL) { + printk("No host CP9314 found...\n"); + return -EIO; + } else if (dev2 == NULL) { + printk("No secondary CP9314 found, assuming standalone operation\n"); + } + + if (!device_is_ready(host)) { + printk("\nError: Device \"%s\" is not ready; " + "check the driver initialization logs for errors.\n", + host->name); + return -EIO; + } + + printk("Found device \"%s\", getting regulator data\n", host->name); + + if (dev2) { + if (!device_is_ready(dev2)) { + printk("\nError: Device \"%s\" is not ready; " + "check the driver initialization logs for errors.\n", + dev2->name); + return -EIO; + } + + printk("Found device \"%s\", getting regulator data\n", dev2->name); + } + + while (1) { + printk("Found device %s\n", host->name); + if (dev2) { + printk("Found device %s\n", dev2->name); + } + + ret = regulator_enable(host); + if (ret == -EINVAL) { + ret = regulator_get_error_flags(host, &flags); + printk("Regulator fault detected: 0x%x\n", flags); + return ret; + } else if (ret < 0) { + printk("I/O Error enabling regulator: %d\n", ret); + return ret; + } + + if (dev2) { + ret = regulator_enable(dev2); + if (ret == -EINVAL) { + ret = regulator_get_error_flags(dev2, &flags); + printk("Regulator fault detected: 0x%x\n", flags); + return ret; + } else if (ret < 0) { + printk("I/O Error enabling regulator: %d\n", ret); + return ret; + } + } + + printk("Converter(s) enabled\n"); + + k_sleep(K_SECONDS(10)); + + if (dev2) { + ret = regulator_disable(dev2); + if (ret < 0) { + printk("Error disabling regulator: %d\n", ret); + return ret; + } + } + + ret = regulator_disable(host); + if (ret < 0) { + printk("Error disabling regulator: %d\n", ret); + return ret; + } + + printk("Converter(s) disabled\n"); + + k_sleep(K_SECONDS(10)); + } + + return 0; +}