Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: rt5033: Apply preparatory changes before adding rt5033-charger driver

Order the register blocks to have the masks in descending manner.

Add new defines for constant voltage shift (RT5033_CHGCTRL2_CV_SHIFT),
MIVR mask (RT5033_CHGCTRL4_MIVR_MASK), pre-charge current shift
(RT5033_CHGCTRL4_IPREC_SHIFT), internal timer disable
(RT5033_INT_TIMER_DISABLE), termination disable (RT5033_TE_DISABLE),
CFO disable (RT5033_CFO_DISABLE), UUG disable (RT5033_CHARGER_UUG_DISABLE).

The fast charge timer type needs to be written on mask 0x38
(RT5033_CHGCTRL3_TIMER_MASK). To avoid a bit shift on application, change the
values of the timer types to fit the mask. Added the timout duration as a
comment. And the timer between TIMER8 and TIMER12 is most likely TIMER10, see
e.g. RT5036 [1] page 28 bottom.

Add value options for MIVR (Minimum Input Voltage Regulation).

Move RT5033_TE_ENABLE_MASK to the block "RT5033 CHGCTRL1 register", in order
to have the masks of the register collected there. To fit the naming scheme,
rename it to RT5033_CHGCTRL1_TE_EN_MASK.

Move RT5033_CHG_MAX_CURRENT to the block "RT5033 charger fast-charge current".

Add new defines RT5033_CV_MAX_VOLTAGE and RT5033_CHG_MAX_PRE_CURRENT to the
blocks "RT5033 charger constant charge voltage" and "RT5033 charger pre-charge
current limits".

In include/linux/mfd/rt5033.h, turn power_supply "psy" into a pointer in order
to use it in devm_power_supply_register().

[1] https://media.digikey.com/pdf/Data%20Sheets/Richtek%20PDF/RT5036%20%20Preliminary.pdf

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/31c750ae13a1c1896b51d8f0a0d9869f8b85624f.1684182964.git.jahau@rocketmail.com

authored by

Jakob Hauser and committed by
Lee Jones
3d897612 4f7a2a08

+35 -18
+34 -17
include/linux/mfd/rt5033-private.h
··· 55 55 }; 56 56 57 57 /* RT5033 Charger state register */ 58 + #define RT5033_CHG_STAT_TYPE_MASK 0x60 59 + #define RT5033_CHG_STAT_TYPE_PRE 0x20 60 + #define RT5033_CHG_STAT_TYPE_FAST 0x60 58 61 #define RT5033_CHG_STAT_MASK 0x30 59 62 #define RT5033_CHG_STAT_DISCHARGING 0x00 60 63 #define RT5033_CHG_STAT_FULL 0x10 61 64 #define RT5033_CHG_STAT_CHARGING 0x20 62 65 #define RT5033_CHG_STAT_NOT_CHARGING 0x30 63 - #define RT5033_CHG_STAT_TYPE_MASK 0x60 64 - #define RT5033_CHG_STAT_TYPE_PRE 0x20 65 - #define RT5033_CHG_STAT_TYPE_FAST 0x60 66 66 67 67 /* RT5033 CHGCTRL1 register */ 68 68 #define RT5033_CHGCTRL1_IAICR_MASK 0xe0 69 - #define RT5033_CHGCTRL1_MODE_MASK 0x01 69 + #define RT5033_CHGCTRL1_TE_EN_MASK 0x08 70 70 #define RT5033_CHGCTRL1_HZ_MASK 0x02 71 + #define RT5033_CHGCTRL1_MODE_MASK 0x01 71 72 72 73 /* RT5033 CHGCTRL2 register */ 73 74 #define RT5033_CHGCTRL2_CV_MASK 0xfc 75 + #define RT5033_CHGCTRL2_CV_SHIFT 0x02 74 76 75 77 /* RT5033 DEVICE_ID register */ 76 78 #define RT5033_VENDOR_ID_MASK 0xf0 ··· 84 82 #define RT5033_CHGCTRL3_TIMER_EN_MASK 0x01 85 83 86 84 /* RT5033 CHGCTRL4 register */ 87 - #define RT5033_CHGCTRL4_EOC_MASK 0x07 85 + #define RT5033_CHGCTRL4_MIVR_MASK 0xe0 88 86 #define RT5033_CHGCTRL4_IPREC_MASK 0x18 87 + #define RT5033_CHGCTRL4_IPREC_SHIFT 0x03 88 + #define RT5033_CHGCTRL4_EOC_MASK 0x07 89 89 90 90 /* RT5033 CHGCTRL5 register */ 91 - #define RT5033_CHGCTRL5_VPREC_MASK 0x0f 92 91 #define RT5033_CHGCTRL5_ICHG_MASK 0xf0 93 92 #define RT5033_CHGCTRL5_ICHG_SHIFT 0x04 94 - #define RT5033_CHG_MAX_CURRENT 0x0d 93 + #define RT5033_CHGCTRL5_VPREC_MASK 0x0f 95 94 96 95 /* RT5033 RT CTRL1 register */ 97 96 #define RT5033_RT_CTRL1_UUG_MASK 0x02 ··· 131 128 #define RT5033_AICR_1500_MODE 0xc0 132 129 #define RT5033_AICR_2000_MODE 0xe0 133 130 131 + /* RT5033 charger minimum input voltage regulation */ 132 + #define RT5033_CHARGER_MIVR_DISABLE 0x00 133 + #define RT5033_CHARGER_MIVR_4200MV 0x20 134 + #define RT5033_CHARGER_MIVR_4300MV 0x40 135 + #define RT5033_CHARGER_MIVR_4400MV 0x60 136 + #define RT5033_CHARGER_MIVR_4500MV 0x80 137 + #define RT5033_CHARGER_MIVR_4600MV 0xa0 138 + #define RT5033_CHARGER_MIVR_4700MV 0xc0 139 + #define RT5033_CHARGER_MIVR_4800MV 0xe0 140 + 134 141 /* RT5033 use internal timer need to set time */ 135 - #define RT5033_FAST_CHARGE_TIMER4 0x00 136 - #define RT5033_FAST_CHARGE_TIMER6 0x01 137 - #define RT5033_FAST_CHARGE_TIMER8 0x02 138 - #define RT5033_FAST_CHARGE_TIMER9 0x03 139 - #define RT5033_FAST_CHARGE_TIMER12 0x04 140 - #define RT5033_FAST_CHARGE_TIMER14 0x05 141 - #define RT5033_FAST_CHARGE_TIMER16 0x06 142 + #define RT5033_FAST_CHARGE_TIMER4 0x00 /* 4 hrs */ 143 + #define RT5033_FAST_CHARGE_TIMER6 0x08 /* 6 hrs */ 144 + #define RT5033_FAST_CHARGE_TIMER8 0x10 /* 8 hrs */ 145 + #define RT5033_FAST_CHARGE_TIMER10 0x18 /* 10 hrs */ 146 + #define RT5033_FAST_CHARGE_TIMER12 0x20 /* 12 hrs */ 147 + #define RT5033_FAST_CHARGE_TIMER14 0x28 /* 14 hrs */ 148 + #define RT5033_FAST_CHARGE_TIMER16 0x30 /* 16 hrs */ 142 149 150 + #define RT5033_INT_TIMER_DISABLE 0x00 143 151 #define RT5033_INT_TIMER_ENABLE 0x01 144 - 145 - /* RT5033 charger termination enable mask */ 146 - #define RT5033_TE_ENABLE_MASK 0x08 147 152 148 153 /* 149 154 * RT5033 charger opa mode. RT5033 has two opa modes for OTG: charger mode ··· 161 150 #define RT5033_BOOST_MODE 0x01 162 151 163 152 /* RT5033 charger termination enable */ 153 + #define RT5033_TE_DISABLE 0x00 164 154 #define RT5033_TE_ENABLE 0x08 165 155 166 156 /* RT5033 charger CFO enable */ 157 + #define RT5033_CFO_DISABLE 0x00 167 158 #define RT5033_CFO_ENABLE 0x40 168 159 169 160 /* RT5033 charger constant charge voltage (as in CHGCTRL2 register), uV */ 170 161 #define RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN 3650000U 171 162 #define RT5033_CHARGER_CONST_VOLTAGE_STEP_NUM 25000U 172 163 #define RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MAX 4400000U 164 + #define RT5033_CV_MAX_VOLTAGE 0x1e 173 165 174 166 /* RT5033 charger pre-charge current limits (as in CHGCTRL4 register), uA */ 175 167 #define RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN 350000U 176 168 #define RT5033_CHARGER_PRE_CURRENT_STEP_NUM 100000U 177 169 #define RT5033_CHARGER_PRE_CURRENT_LIMIT_MAX 650000U 170 + #define RT5033_CHG_MAX_PRE_CURRENT 0x03 178 171 179 172 /* RT5033 charger fast-charge current (as in CHGCTRL5 register), uA */ 180 173 #define RT5033_CHARGER_FAST_CURRENT_MIN 700000U 181 174 #define RT5033_CHARGER_FAST_CURRENT_STEP_NUM 100000U 182 175 #define RT5033_CHARGER_FAST_CURRENT_MAX 2000000U 176 + #define RT5033_CHG_MAX_CURRENT 0x0d 183 177 184 178 /* 185 179 * RT5033 charger const-charge end of charger current ( ··· 208 192 * RT5033 charger UUG. It enables MOS auto control by H/W charger 209 193 * circuit. 210 194 */ 195 + #define RT5033_CHARGER_UUG_DISABLE 0x00 211 196 #define RT5033_CHARGER_UUG_ENABLE 0x02 212 197 213 198 /* RT5033 charger high impedance mode */
+1 -1
include/linux/mfd/rt5033.h
··· 51 51 struct rt5033_charger { 52 52 struct device *dev; 53 53 struct rt5033_dev *rt5033; 54 - struct power_supply psy; 54 + struct power_supply *psy; 55 55 struct rt5033_charger_data *chg; 56 56 }; 57 57