diff mbox

[U-Boot,v4,2/4] power: regulator: rk8xx: Allow input current/charger shutdown configuration

Message ID 1497868601-30227-2-git-send-email-w.egorov@phytec.de
State Accepted
Delegated to: Philipp Tomsich
Headers show

Commit Message

Wadim Egorov June 19, 2017, 10:36 a.m. UTC
The RK818 PMIC contains a charger. Add very basic charger functionality
to be able to regulate the USB input current and charger shutdown limits.

Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
Changes in v4:
- Added Reviewed-by: Simon Glass <sjg@chromium.org>

 drivers/power/regulator/rk8xx.c | 34 ++++++++++++++++++++++++++++++++++
 include/power/rk8xx_pmic.h      |  2 ++
 2 files changed, 36 insertions(+)

Comments

Philipp Tomsich June 25, 2017, 11:24 p.m. UTC | #1
> The RK818 PMIC contains a charger. Add very basic charger functionality
> to be able to regulate the USB input current and charger shutdown limits.
> 
> Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
> Changes in v4:
> - Added Reviewed-by: Simon Glass <sjg@chromium.org>
> 
>  drivers/power/regulator/rk8xx.c | 34 ++++++++++++++++++++++++++++++++++
>  include/power/rk8xx_pmic.h      |  2 ++
>  2 files changed, 36 insertions(+)
> 

Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Philipp Tomsich June 26, 2017, 3:48 p.m. UTC | #2
> The RK818 PMIC contains a charger. Add very basic charger functionality
> to be able to regulate the USB input current and charger shutdown limits.
> 
> Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> ---
> Changes in v4:
> - Added Reviewed-by: Simon Glass <sjg@chromium.org>
> 
>  drivers/power/regulator/rk8xx.c | 34 ++++++++++++++++++++++++++++++++++
>  include/power/rk8xx_pmic.h      |  2 ++
>  2 files changed, 36 insertions(+)
> 

Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Philipp Tomsich July 4, 2017, 7:56 a.m. UTC | #3
> The RK818 PMIC contains a charger. Add very basic charger functionality
> to be able to regulate the USB input current and charger shutdown limits.
> 
> Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
> ---
> Changes in v4:
> - Added Reviewed-by: Simon Glass <sjg@chromium.org>
> 
>  drivers/power/regulator/rk8xx.c | 34 ++++++++++++++++++++++++++++++++++
>  include/power/rk8xx_pmic.h      |  2 ++
>  2 files changed, 36 insertions(+)
> 

Applied to u-boot-rockchip/next, thanks!
diff mbox

Patch

diff --git a/drivers/power/regulator/rk8xx.c b/drivers/power/regulator/rk8xx.c
index d96a1f8..7c0a3aa 100644
--- a/drivers/power/regulator/rk8xx.c
+++ b/drivers/power/regulator/rk8xx.c
@@ -30,6 +30,9 @@ 
 #define RK818_LDO_VSEL_MASK		0x1f
 #define RK818_LDO3_ON_VSEL_MASK	0xf
 #define RK818_BOOST_ON_VSEL_MASK	0xe0
+#define RK818_USB_ILIM_SEL_MASK		0x0f
+#define RK818_USB_CHG_SD_VSEL_MASK	0x70
+
 
 struct rk8xx_reg_info {
 	uint min_uv;
@@ -76,6 +79,14 @@  static const struct rk8xx_reg_info rk818_ldo[] = {
 };
 #endif
 
+static const u16 rk818_chrg_cur_input_array[] = {
+	450, 800, 850, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000
+};
+
+static const uint rk818_chrg_shutdown_vsel_array[] = {
+	2780000, 2850000, 2920000, 2990000, 3060000, 3130000, 3190000, 3260000
+};
+
 static const struct rk8xx_reg_info *get_buck_reg(struct udevice *pmic,
 					     int num)
 {
@@ -353,3 +364,26 @@  int rk8xx_spl_configure_buck(struct udevice *pmic, int buck, int uvolt)
 
 	return _buck_set_enable(pmic, buck, true);
 }
+
+int rk818_spl_configure_usb_input_current(struct udevice *pmic, int current_ma)
+{
+	uint i;
+
+	for (i = 0; i < ARRAY_SIZE(rk818_chrg_cur_input_array); i++)
+		if (current_ma <= rk818_chrg_cur_input_array[i])
+			break;
+
+	return pmic_clrsetbits(pmic, REG_USB_CTRL, RK818_USB_ILIM_SEL_MASK, i);
+}
+
+int rk818_spl_configure_usb_chrg_shutdown(struct udevice *pmic, int uvolt)
+{
+	uint i;
+
+	for (i = 0; i < ARRAY_SIZE(rk818_chrg_shutdown_vsel_array); i++)
+		if (uvolt <= rk818_chrg_shutdown_vsel_array[i])
+			break;
+
+	return pmic_clrsetbits(pmic, REG_USB_CTRL, RK818_USB_CHG_SD_VSEL_MASK,
+			       i);
+}
diff --git a/include/power/rk8xx_pmic.h b/include/power/rk8xx_pmic.h
index 589f8c4..47a6b36 100644
--- a/include/power/rk8xx_pmic.h
+++ b/include/power/rk8xx_pmic.h
@@ -189,5 +189,7 @@  struct rk8xx_priv {
 };
 
 int rk8xx_spl_configure_buck(struct udevice *pmic, int buck, int uvolt);
+int rk818_spl_configure_usb_input_current(struct udevice *pmic, int current_ma);
+int rk818_spl_configure_usb_chrg_shutdown(struct udevice *pmic, int uvolt);
 
 #endif