summaryrefslogtreecommitdiffhomepage
path: root/source/pwr_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/pwr_driver.c')
-rw-r--r--source/pwr_driver.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/source/pwr_driver.c b/source/pwr_driver.c
new file mode 100644
index 0000000..37abbd4
--- /dev/null
+++ b/source/pwr_driver.c
@@ -0,0 +1,113 @@
+/*
+ * pwr_driver.c
+ *
+ * Copyright (C) 2018, 2019 Mind Chasers Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "board.h"
+#include "pmic.h"
+#include "fsl_debug_console.h"
+#include "fsl_common.h"
+#include "fsl_i2c.h"
+#include "fsl_gpio.h"
+#include "main.h"
+
+int power_init(i2c_master_transfer_t* pXfer, uint8_t* pBuff) {
+
+ bool repeat = false;
+ uint8_t addr,data;
+ uint8_t buf[2]; // write address followed by data
+_loop:
+
+ PRINTF("Power Init\r\n");
+
+ // Read version
+ addr=PMIC_VERSION;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("Version: 0x%2x\r\n", *pBuff);
+
+ // Read PGOODZ
+ addr=PMIC_PGOODZ;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("PGOODZ: 0x%2x\r\n", *pBuff);
+
+ // Read MASK
+ addr=PMIC_MASK;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("MASK: 0x%2x\r\n", *pBuff);
+
+ // Read REG_CTRL
+ addr=PMIC_REG_CTRL;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("REG_CTRL: 0x%2x\r\n", *pBuff);
+
+ // Read CON_CTRL
+ addr=PMIC_CON_CTRL;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ // PRINTF("CON_CTRL: 0x%2x\r\n", *pBuff);
+
+ // Read CON_CTRL2
+ addr=PMIC_CON_CTRL2;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("CON_CTRL2: 0x%2x\r\n", *pBuff);
+
+ // Read DEFCORE
+ // We want 1.1V: 0xc
+ addr=PMIC_DEFCORE;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("DEFSLEW: 0x%2x\r\n", *pBuff);
+
+ // Read DEFSLEW
+ addr=PMIC_DEFSLEW;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("DEFSLEW: 0x%2x\r\n", *pBuff);
+
+ // Read LDO_CTRL
+ addr=PMIC_LDO_CTRL;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("LDO_CTRL: 0x%2x\r\n", *pBuff);
+
+ // Write LDO_CTRL
+ addr=PMIC_LDO_CTRL;
+ data=LDO2_2_5V<<4|LDO1_1_1V;
+ buf[0]=addr;
+ buf[1]=data;
+ i2c_write(pXfer, I2C_PMIC_ADDR, buf, 2);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("LDO_CTRL: 0x%2x\r\n", *pBuff);
+
+ GPIO_WritePinOutput(GPIOA, 19, 1);
+
+ // Read PGOODZ
+ addr=PMIC_PGOODZ;
+ i2c_write(pXfer, I2C_PMIC_ADDR, &addr, 1);
+ i2c_read(pXfer, I2C_PMIC_ADDR, (uint8_t*) pBuff, 1);
+ //PRINTF("PGOODZ: 0x%2x\r\n", *pBuff);
+
+
+ if (repeat) goto _loop;
+
+ return 0;
+}



X-ray Engineering Services