power: pmic: rk809: support rk809 pmic
authorJoseph Chen <chenjh@rock-chips.com>
Thu, 26 Sep 2019 07:45:07 +0000 (15:45 +0800)
committerKever Yang <kever.yang@rock-chips.com>
Sun, 10 Nov 2019 12:34:10 +0000 (20:34 +0800)
The RK809 is a Power Management IC (PMIC) for multimedia
and handheld devices. They contains the following components:
    - Regulators(5*BUCKs, 9*LDOs, 2*SWITCHes)
    - RTC
    - Clocking

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
drivers/power/pmic/rk8xx.c
drivers/power/regulator/rk8xx.c
include/power/rk8xx_pmic.h

index df0bf83a054c3ecb7bec37a8493419d5c3b5d751..52e6d9d8c0e88484545d025728f16538ed04558d 100644 (file)
@@ -92,7 +92,8 @@ static int rk8xx_probe(struct udevice *dev)
        u8 value;
 
        /* read Chip variant */
-       if (device_is_compatible(dev, "rockchip,rk817")) {
+       if (device_is_compatible(dev, "rockchip,rk817") ||
+           device_is_compatible(dev, "rockchip,rk809")) {
                id_msb = RK817_ID_MSB;
                id_lsb = RK817_ID_LSB;
        } else {
@@ -119,6 +120,7 @@ static int rk8xx_probe(struct udevice *dev)
                on_source = RK8XX_ON_SOURCE;
                off_source = RK8XX_OFF_SOURCE;
                break;
+       case RK809_ID:
        case RK817_ID:
                on_source = RK817_ON_SOURCE;
                off_source = RK817_OFF_SOURCE;
@@ -173,6 +175,7 @@ static struct dm_pmic_ops rk8xx_ops = {
 static const struct udevice_id rk8xx_ids[] = {
        { .compatible = "rockchip,rk805" },
        { .compatible = "rockchip,rk808" },
+       { .compatible = "rockchip,rk809" },
        { .compatible = "rockchip,rk816" },
        { .compatible = "rockchip,rk817" },
        { .compatible = "rockchip,rk818" },
index a5692edd0023c02da2e5cd9f8543791faae4a207..e99331f6c964bb286862144d8d16ff98954e3e0d 100644 (file)
 #define RK808_BUCK4_VSEL_MASK  0xf
 #define RK808_LDO_VSEL_MASK    0x1f
 
+/* RK809 BUCK5 */
+#define RK809_BUCK5_CONFIG(n)          (0xde + (n) * 1)
+#define RK809_BUCK5_VSEL_MASK          0x07
+
 /* RK817 BUCK */
 #define RK817_BUCK_ON_VSEL(n)          (0xbb + 3 * ((n) - 1))
 #define RK817_BUCK_SLP_VSEL(n)         (0xbc + 3 * ((n) - 1))
@@ -59,6 +63,7 @@
 #define RK805_RAMP_RATE_6MV_PER_US     (1 << RK805_RAMP_RATE_OFFSET)
 #define RK805_RAMP_RATE_12_5MV_PER_US  (2 << RK805_RAMP_RATE_OFFSET)
 #define RK805_RAMP_RATE_25MV_PER_US    (3 << RK805_RAMP_RATE_OFFSET)
+
 #define RK808_RAMP_RATE_OFFSET         3
 #define RK808_RAMP_RATE_MASK           (3 << RK808_RAMP_RATE_OFFSET)
 #define RK808_RAMP_RATE_2MV_PER_US     (0 << RK808_RAMP_RATE_OFFSET)
@@ -105,6 +110,14 @@ static const struct rk8xx_reg_info rk816_buck[] = {
        {  800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, },
 };
 
+static const struct rk8xx_reg_info rk809_buck5[] = {
+       /* buck 5 */
+       { 1500000,      0, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x00, },
+       { 1800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x01, },
+       { 2800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x04, },
+       { 3300000, 300000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x06, },
+};
+
 static const struct rk8xx_reg_info rk817_buck[] = {
        /* buck 1 */
        {  500000,  12500, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x00, },
@@ -223,6 +236,7 @@ static const struct rk8xx_reg_info *get_buck_reg(struct udevice *pmic,
                        return &rk816_buck[num + 4];
                }
 
+       case RK809_ID:
        case RK817_ID:
                switch (num) {
                case 0 ... 2:
@@ -239,6 +253,16 @@ static const struct rk8xx_reg_info *get_buck_reg(struct udevice *pmic,
                                return &rk817_buck[num * 3 + 1];
                        else
                                return &rk817_buck[num * 3 + 2];
+               /* BUCK5 for RK809 */
+               default:
+                       if (uvolt < 1800000)
+                               return &rk809_buck5[0];
+                       else if (uvolt < 2800000)
+                               return &rk809_buck5[1];
+                       else if (uvolt < 3300000)
+                               return &rk809_buck5[2];
+                       else
+                               return &rk809_buck5[3];
                }
        case RK818_ID:
                return &rk818_buck[num];
@@ -308,6 +332,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)
                ret = pmic_clrsetbits(pmic, REG_DCDC_EN, mask,
                                      enable ? mask : 0);
                break;
+       case RK809_ID:
        case RK817_ID:
                if (buck < 4) {
                        if (enable)
@@ -315,6 +340,13 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)
                        else
                                value = ((0 << buck) | (1 << (buck + 4)));
                        ret = pmic_reg_write(pmic, RK817_POWER_EN(0), value);
+               /* BUCK5 for RK809 */
+               } else {
+                       if (enable)
+                               value = ((1 << 1) | (1 << 5));
+                       else
+                               value = ((0 << 1) | (1 << 5));
+                       ret = pmic_reg_write(pmic, RK817_POWER_EN(3), value);
                }
                break;
        default:
@@ -369,10 +401,15 @@ static int _buck_get_enable(struct udevice *pmic, int buck)
                if (ret < 0)
                        return ret;
                break;
+       case RK809_ID:
        case RK817_ID:
                if (buck < 4) {
                        mask = 1 << buck;
                        ret = pmic_reg_read(pmic, RK817_POWER_EN(0));
+               /* BUCK5 for RK809 */
+               } else {
+                       mask = 1 << 1;
+                       ret = pmic_reg_read(pmic, RK817_POWER_EN(3));
                }
                break;
        }
@@ -402,9 +439,12 @@ static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable)
                ret = pmic_clrsetbits(pmic, REG_SLEEP_SET_OFF1, mask,
                                      enable ? 0 : mask);
                break;
+       case RK809_ID:
        case RK817_ID:
                if (buck < 4)
                        mask = 1 << buck;
+               else
+                       mask = 1 << 5;  /* BUCK5 for RK809 */
                ret = pmic_clrsetbits(pmic, RK817_POWER_SLP_EN(0), mask,
                                      enable ? mask : 0);
                break;
@@ -438,9 +478,12 @@ static int _buck_get_suspend_enable(struct udevice *pmic, int buck)
                        return val;
                ret = val & mask ? 0 : 1;
                break;
+       case RK809_ID:
        case RK817_ID:
                if (buck < 4)
                        mask = 1 << buck;
+               else
+                       mask = 1 << 5;  /* BUCK5 for RK809 */
 
                val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(0));
                if (val < 0)
@@ -463,6 +506,7 @@ static const struct rk8xx_reg_info *get_ldo_reg(struct udevice *pmic,
        case RK805_ID:
        case RK816_ID:
                return &rk816_ldo[num];
+       case RK809_ID:
        case RK817_ID:
                if (uvolt < 3400000)
                        return &rk817_ldo[num * 2 + 0];
@@ -499,6 +543,7 @@ static int _ldo_get_enable(struct udevice *pmic, int ldo)
                if (ret < 0)
                        return ret;
                break;
+       case RK809_ID:
        case RK817_ID:
                if (ldo < 4) {
                        mask = 1 << ldo;
@@ -549,6 +594,7 @@ static int _ldo_set_enable(struct udevice *pmic, int ldo, bool enable)
                ret = pmic_clrsetbits(pmic, REG_LDO_EN, mask,
                                       enable ? mask : 0);
                break;
+       case RK809_ID:
        case RK817_ID:
                if (ldo < 4) {
                        en_reg = RK817_POWER_EN(1);
@@ -591,6 +637,7 @@ static int _ldo_set_suspend_enable(struct udevice *pmic, int ldo, bool enable)
                ret = pmic_clrsetbits(pmic, REG_SLEEP_SET_OFF2, mask,
                                      enable ? 0 : mask);
                break;
+       case RK809_ID:
        case RK817_ID:
                if (ldo == 8) {
                        mask = 1 << 4;  /* LDO9 */
@@ -630,6 +677,7 @@ static int _ldo_get_suspend_enable(struct udevice *pmic, int ldo)
                        return val;
                ret = val & mask ? 0 : 1;
                break;
+       case RK809_ID:
        case RK817_ID:
                if (ldo == 8) {
                        mask = 1 << 4;  /* LDO9 */
@@ -849,6 +897,11 @@ static int switch_set_enable(struct udevice *dev, bool enable)
                ret = pmic_clrsetbits(dev->parent, REG_DCDC_EN, mask,
                                      enable ? mask : 0);
                break;
+       case RK809_ID:
+               mask = (1 << (sw + 2)) | (1 << (sw + 6));
+               ret = pmic_clrsetbits(dev->parent, RK817_POWER_EN(3), mask,
+                                     enable ? mask : 0);
+               break;
        case RK818_ID:
                mask = 1 << 6;
                ret = pmic_clrsetbits(dev->parent, REG_DCDC_EN, mask,
@@ -873,6 +926,10 @@ static int switch_get_enable(struct udevice *dev)
                mask = 1 << (sw + 5);
                ret = pmic_reg_read(dev->parent, REG_DCDC_EN);
                break;
+       case RK809_ID:
+               mask = 1 << (sw + 2);
+               ret = pmic_reg_read(dev->parent, RK817_POWER_EN(3));
+               break;
        case RK818_ID:
                mask = 1 << 6;
                ret = pmic_reg_read(dev->parent, REG_DCDC_EN);
@@ -907,6 +964,11 @@ static int switch_set_suspend_enable(struct udevice *dev, bool enable)
                ret = pmic_clrsetbits(dev->parent, REG_SLEEP_SET_OFF1, mask,
                                      enable ? 0 : mask);
                break;
+       case RK809_ID:
+               mask = 1 << (sw + 6);
+               ret = pmic_clrsetbits(dev->parent, RK817_POWER_SLP_EN(0), mask,
+                                     enable ? mask : 0);
+               break;
        case RK818_ID:
                mask = 1 << 6;
                ret = pmic_clrsetbits(dev->parent, REG_SLEEP_SET_OFF1, mask,
@@ -934,6 +996,13 @@ static int switch_get_suspend_enable(struct udevice *dev)
                        return val;
                ret = val & mask ? 0 : 1;
                break;
+       case RK809_ID:
+               mask = 1 << (sw + 6);
+               val = pmic_reg_read(dev->parent, RK817_POWER_SLP_EN(0));
+               if (val < 0)
+                       return val;
+               ret = val & mask ? 1 : 0;
+               break;
        case RK818_ID:
                mask = 1 << 6;
                val = pmic_reg_read(dev->parent, REG_SLEEP_SET_OFF1);
index d93cecedddf724e39ddfbb5e708ea0656056e52b..8ff0af35c57a0ca53b903cada2ef78a5b0dfbdcf 100644 (file)
@@ -185,6 +185,7 @@ enum {
 enum {
        RK805_ID = 0x8050,
        RK808_ID = 0x0000,
+       RK809_ID = 0x8090,
        RK816_ID = 0x8160,
        RK817_ID = 0x8170,
        RK818_ID = 0x8180,