Commit ad98f882e86d3b7231b8c02bbdf8f7eee735aee6

Authored by Wadim Egorov
Committed by Philipp Tomsich
1 parent 8926c2f584

power: regulator: rk8xx: Allow input current/charger shutdown configuration

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>

Showing 2 changed files with 36 additions and 0 deletions Side-by-side Diff

drivers/power/regulator/rk8xx.c
... ... @@ -30,7 +30,10 @@
30 30 #define RK818_LDO_VSEL_MASK 0x1f
31 31 #define RK818_LDO3_ON_VSEL_MASK 0xf
32 32 #define RK818_BOOST_ON_VSEL_MASK 0xe0
  33 +#define RK818_USB_ILIM_SEL_MASK 0x0f
  34 +#define RK818_USB_CHG_SD_VSEL_MASK 0x70
33 35  
  36 +
34 37 struct rk8xx_reg_info {
35 38 uint min_uv;
36 39 uint step_uv;
... ... @@ -76,6 +79,14 @@
76 79 };
77 80 #endif
78 81  
  82 +static const u16 rk818_chrg_cur_input_array[] = {
  83 + 450, 800, 850, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000
  84 +};
  85 +
  86 +static const uint rk818_chrg_shutdown_vsel_array[] = {
  87 + 2780000, 2850000, 2920000, 2990000, 3060000, 3130000, 3190000, 3260000
  88 +};
  89 +
79 90 static const struct rk8xx_reg_info *get_buck_reg(struct udevice *pmic,
80 91 int num)
81 92 {
... ... @@ -352,5 +363,28 @@
352 363 return ret;
353 364  
354 365 return _buck_set_enable(pmic, buck, true);
  366 +}
  367 +
  368 +int rk818_spl_configure_usb_input_current(struct udevice *pmic, int current_ma)
  369 +{
  370 + uint i;
  371 +
  372 + for (i = 0; i < ARRAY_SIZE(rk818_chrg_cur_input_array); i++)
  373 + if (current_ma <= rk818_chrg_cur_input_array[i])
  374 + break;
  375 +
  376 + return pmic_clrsetbits(pmic, REG_USB_CTRL, RK818_USB_ILIM_SEL_MASK, i);
  377 +}
  378 +
  379 +int rk818_spl_configure_usb_chrg_shutdown(struct udevice *pmic, int uvolt)
  380 +{
  381 + uint i;
  382 +
  383 + for (i = 0; i < ARRAY_SIZE(rk818_chrg_shutdown_vsel_array); i++)
  384 + if (uvolt <= rk818_chrg_shutdown_vsel_array[i])
  385 + break;
  386 +
  387 + return pmic_clrsetbits(pmic, REG_USB_CTRL, RK818_USB_CHG_SD_VSEL_MASK,
  388 + i);
355 389 }
include/power/rk8xx_pmic.h
... ... @@ -189,6 +189,8 @@
189 189 };
190 190  
191 191 int rk8xx_spl_configure_buck(struct udevice *pmic, int buck, int uvolt);
  192 +int rk818_spl_configure_usb_input_current(struct udevice *pmic, int current_ma);
  193 +int rk818_spl_configure_usb_chrg_shutdown(struct udevice *pmic, int uvolt);
192 194  
193 195 #endif