aboutsummaryrefslogtreecommitdiff
path: root/drivers/power/lp8720.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/lp8720.c')
-rw-r--r--drivers/power/lp8720.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/drivers/power/lp8720.c b/drivers/power/lp8720.c
new file mode 100644
index 00000000000..ac7fc1167e7
--- /dev/null
+++ b/drivers/power/lp8720.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <i2c.h>
+#include <asm/gpio.h>
+#include <lp8720.h>
+
+static struct lp8720_info lp8720_info;
+
+static int lp8720_write(u8 reg, u8 val)
+{
+ return i2c_write(lp8720_info.chip_idsel, reg, 1, &val, 1);
+}
+
+static int lp8720_read(u8 reg, u8 *val)
+{
+ return i2c_read(lp8720_info.chip_idsel, reg, 1, val, 1);
+}
+
+int lp8720_init(int enable_gpio, int chip_idsel)
+{
+ int ret;
+
+ if (enable_gpio) {
+ if (!gpio_is_valid(enable_gpio))
+ return -1;
+
+ ret = gpio_request(enable_gpio, "lp8720_en");
+ if (ret)
+ return ret;
+
+ ret = gpio_direction_output(enable_gpio, 0);
+ if (ret)
+ return ret;
+ }
+
+ lp8720_info.enable_gpio = enable_gpio;
+ lp8720_info.chip_idsel = chip_idsel;
+
+ return 0;
+}
+
+int lp8720_enable(void)
+{
+ int ret;
+
+ if (lp8720_info.enable_gpio) {
+ ret = gpio_set_value(lp8720_info.enable_gpio, 1);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+int lp8720_is_enabled(void)
+{
+ if (lp8720_info.enable_gpio)
+ return gpio_get_value(lp8720_info.enable_gpio);
+
+ /* Assume LP8720 enabled when there is no enable GPIO */
+ return 1;
+}
+
+int lp8720_ldo_enable(u8 ldo_enable)
+{
+ u8 val;
+ int ret;
+
+ ret = lp8720_read(LP8720_ENABLE_BITS, &val);
+ if (ret)
+ return ret;
+
+ val |= ldo_enable;
+
+ ret = lp8720_write(LP8720_ENABLE_BITS, val);
+ if (ret)
+ return ret;
+
+ /* Enable the IC */
+ if (!lp8720_is_enabled())
+ lp8720_enable();
+
+ return 0;
+}
+
+int lp8720_ldo_voltage(u8 ldo_reg, u8 voltage, u8 delay)
+{
+ u8 val;
+ int ret;
+
+ /* Register V field */
+ val = voltage & 0x1F;
+
+ /* Register T field */
+ val |= (delay & 0x07) << 5;
+
+ ret = lp8720_write(ldo_reg, val);
+ if (ret)
+ return ret;
+
+ return 0;
+}