summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fw/fe310/eos/dev/tps61052.c340
-rw-r--r--fw/fe310/eos/dev/tps61052.h34
2 files changed, 374 insertions, 0 deletions
diff --git a/fw/fe310/eos/dev/tps61052.c b/fw/fe310/eos/dev/tps61052.c
new file mode 100644
index 0000000..d2d431c
--- /dev/null
+++ b/fw/fe310/eos/dev/tps61052.c
@@ -0,0 +1,340 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "eos.h"
+#include "soc/i2c.h"
+
+#include "tps61052.h"
+
+#define TPS61052_ADDR 0x33
+
+static int reg_read(uint8_t reg, uint8_t *data) {
+ int rv;
+
+ rv = eos_i2c_read8(TPS61052_ADDR, reg, data, 1);
+ return rv;
+}
+
+static int reg_write(uint8_t reg, uint8_t data) {
+ int rv;
+
+ rv = eos_i2c_write8(TPS61052_ADDR, reg, &data, 1);
+ return rv;
+}
+
+/* register b00 */
+int eos_tps61052_get_tc(uint8_t *tc) {
+ int rv;
+
+ rv = reg_read(0, tc);
+ if (rv) return rv;
+
+ *tc &= 0x07;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_tc(uint8_t tc) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(0, &data);
+ if (rv) return rv;
+
+ data &= 0xF8;
+ tc &= 0x07;
+
+ rv = reg_write(0, data | tc);
+ return rv;
+}
+
+int eos_tps61052_get_dim(uint8_t *dim) {
+ int rv;
+
+ rv = reg_read(0, dim);
+ if (rv) return rv;
+
+ *dim = *dim >> 3;
+ *dim &= 0x01;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_dim(uint8_t dim) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(0, &data);
+ if (rv) return rv;
+
+ data &= 0xF7;
+ dim &= 0x01;
+ dim = dim << 3;
+
+ rv = reg_write(0, data | dim);
+ return rv;
+}
+
+int eos_tps61052_get_ov(uint8_t *ov) {
+ int rv;
+
+ rv = reg_read(0, ov);
+ if (rv) return rv;
+
+ *ov = *ov >> 4;
+ *ov &= 0x03;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_ov(uint8_t ov) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(0, &data);
+ if (rv) return rv;
+
+ data &= 0xCF;
+ ov &= 0x03;
+ ov = ov << 4;
+
+ rv = reg_write(0, data | ov);
+ return rv;
+}
+
+int eos_tps61052_get_mode0(uint8_t *mode) {
+ int rv;
+
+ rv = reg_read(0, mode);
+ if (rv) return rv;
+
+ *mode = *mode >> 6;
+ *mode &= 0x03;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_mode0(uint8_t mode) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(0, &data);
+ if (rv) return rv;
+
+ data &= 0x3F;
+ mode &= 0x03;
+ mode = mode << 6;
+
+ rv = reg_write(0, data | mode);
+ return rv;
+}
+
+/* register b01 */
+int eos_tps61052_get_fc(uint8_t *fc) {
+ int rv;
+
+ rv = reg_read(1, fc);
+ if (rv) return rv;
+
+ *fc &= 0x07;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_fc(uint8_t fc) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(1, &data);
+ if (rv) return rv;
+
+ data &= 0xF8;
+ fc &= 0x07;
+
+ fc = reg_write(1, data | fc);
+ return rv;
+}
+
+int eos_tps61052_get_sft(uint8_t *sft) {
+ int rv;
+
+ rv = reg_read(1, sft);
+ if (rv) return rv;
+
+ *sft = *sft >> 3;
+ *sft &= 0x01;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_sft(uint8_t sft) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(1, &data);
+ if (rv) return rv;
+
+ data &= 0xF7;
+ sft &= 0x01;
+ sft = sft << 3;
+
+ rv = reg_write(1, data | sft);
+ return rv;
+}
+
+int eos_tps61052_get_stt(uint8_t *stt) {
+ int rv;
+
+ rv = reg_read(1, stt);
+ if (rv) return rv;
+
+ *stt = *stt >> 4;
+ *stt &= 0x01;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_stt(uint8_t stt) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(1, &data);
+ if (rv) return rv;
+
+ data &= 0xEF;
+ stt &= 0x01;
+ stt = stt << 4;
+
+ rv = reg_write(1, data | stt);
+ return rv;
+}
+
+int eos_tps61052_get_to(uint8_t *to) {
+ int rv;
+
+ rv = reg_read(1, to);
+ if (rv) return rv;
+
+ *to = *to >> 5;
+ *to &= 0x01;
+ return EOS_OK;
+}
+
+int eos_tps61052_get_mode1(uint8_t *mode) {
+ int rv;
+
+ rv = reg_read(1, mode);
+ if (rv) return rv;
+
+ *mode = *mode >> 6;
+ *mode &= 0x03;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_mode1(uint8_t mode) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(1, &data);
+ if (rv) return rv;
+
+ data &= 0x3F;
+ mode &= 0x03;
+ mode = mode << 6;
+
+ rv = reg_write(1, data | mode);
+ return rv;
+}
+
+/* register b10 */
+int eos_tps61052_get_adc(uint8_t *adc) {
+ int rv;
+
+ rv = reg_read(2, adc);
+ if (rv) return rv;
+
+ *adc = *adc >> 3;
+ *adc &= 0x07;
+ return EOS_OK;
+}
+
+int eos_tps61052_get_lf(uint8_t *lf) {
+ int rv;
+
+ rv = reg_read(2, lf);
+ if (rv) return rv;
+
+ *lf = *lf >> 6;
+ *lf &= 0x01;
+ return EOS_OK;
+}
+
+int eos_tps61052_get_ot(uint8_t *ot) {
+ int rv;
+
+ rv = reg_read(2, ot);
+ if (rv) return rv;
+
+ *ot = *ot >> 7;
+ *ot &= 0x01;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_ilim(uint8_t ilim) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(2, &data);
+ if (rv) return rv;
+
+ data &= 0x9F;
+ ilim &= 0x03;
+ ilim = ilim << 5;
+
+ rv = reg_write(2, data | ilim);
+ return rv;
+}
+
+/* register b11 */
+int eos_tps61052_get_stim(uint8_t *stim) {
+ int rv;
+
+ rv = reg_read(3, stim);
+ if (rv) return rv;
+
+ *stim &= 0x1F;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_stim(uint8_t stim) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(3, &data);
+ if (rv) return rv;
+
+ data &= 0xE0;
+ stim &= 0x1F;
+
+ stim = reg_write(3, data | stim);
+ return rv;
+}
+
+int eos_tps61052_get_dctim(uint8_t *dctim) {
+ int rv;
+
+ rv = reg_read(3, dctim);
+ if (rv) return rv;
+
+ *dctim = *dctim >> 5;
+ *dctim &= 0x07;
+ return EOS_OK;
+}
+
+int eos_tps61052_set_dctim(uint8_t dctim) {
+ uint8_t data;
+ int rv;
+
+ rv = reg_read(3, &data);
+ if (rv) return rv;
+
+ data &= 0x1F;
+ dctim &= 0x07;
+ dctim = dctim << 5;
+
+ rv = reg_write(3, data | dctim);
+ return rv;
+}
diff --git a/fw/fe310/eos/dev/tps61052.h b/fw/fe310/eos/dev/tps61052.h
new file mode 100644
index 0000000..2711d2b
--- /dev/null
+++ b/fw/fe310/eos/dev/tps61052.h
@@ -0,0 +1,34 @@
+#include <stdint.h>
+
+/* register b00 */
+int eos_tps61052_get_tc(uint8_t *tc);
+int eos_tps61052_set_tc(uint8_t tc);
+int eos_tps61052_get_dim(uint8_t *dim);
+int eos_tps61052_set_dim(uint8_t dim);
+int eos_tps61052_get_ov(uint8_t *ov);
+int eos_tps61052_set_ov(uint8_t ov);
+int eos_tps61052_get_mode0(uint8_t *mode);
+int eos_tps61052_set_mode0(uint8_t mode);
+
+/* register b01 */
+int eos_tps61052_get_fc(uint8_t *fc);
+int eos_tps61052_set_fc(uint8_t fc);
+int eos_tps61052_get_sft(uint8_t *sft);
+int eos_tps61052_set_sft(uint8_t sft);
+int eos_tps61052_get_stt(uint8_t *stt);
+int eos_tps61052_set_stt(uint8_t stt);
+int eos_tps61052_get_to(uint8_t *to);
+int eos_tps61052_get_mode1(uint8_t *mode);
+int eos_tps61052_set_mode1(uint8_t mode);
+
+/* register b10 */
+int eos_tps61052_get_adc(uint8_t *adc);
+int eos_tps61052_get_lf(uint8_t *lf);
+int eos_tps61052_get_ot(uint8_t *ot);
+int eos_tps61052_set_ilim(uint8_t ilim);
+
+/* register b11 */
+int eos_tps61052_get_stim(uint8_t *stim);
+int eos_tps61052_set_stim(uint8_t stim);
+int eos_tps61052_get_dctim(uint8_t *dctim);
+int eos_tps61052_set_dctim(uint8_t dctim);