Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * max14577-private.h - Common API for the Maxim 14577 internal sub chip |
| 3 | * |
| 4 | * Copyright (C) 2013 Samsung Electrnoics |
| 5 | * Chanwoo Choi <cw00.choi@samsung.com> |
| 6 | * Krzysztof Kozlowski <k.kozlowski@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __MAX14577_PRIVATE_H__ |
| 20 | #define __MAX14577_PRIVATE_H__ |
| 21 | |
| 22 | #include <linux/i2c.h> |
| 23 | #include <linux/regmap.h> |
| 24 | |
Krzysztof Kozlowski | eccb80c | 2014-04-14 11:17:14 +0200 | [diff] [blame] | 25 | enum maxim_device_type { |
| 26 | MAXIM_DEVICE_TYPE_UNKNOWN = 0, |
| 27 | MAXIM_DEVICE_TYPE_MAX14577, |
| 28 | |
| 29 | MAXIM_DEVICE_TYPE_NUM, |
| 30 | }; |
| 31 | |
Krzysztof Kozlowski | 575343d | 2014-04-14 11:17:13 +0200 | [diff] [blame] | 32 | /* Slave addr = 0x4A: MUIC and Charger */ |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 33 | enum max14577_reg { |
| 34 | MAX14577_REG_DEVICEID = 0x00, |
| 35 | MAX14577_REG_INT1 = 0x01, |
| 36 | MAX14577_REG_INT2 = 0x02, |
| 37 | MAX14577_REG_INT3 = 0x03, |
| 38 | MAX14577_REG_STATUS1 = 0x04, |
| 39 | MAX14577_REG_STATUS2 = 0x05, |
| 40 | MAX14577_REG_STATUS3 = 0x06, |
| 41 | MAX14577_REG_INTMASK1 = 0x07, |
| 42 | MAX14577_REG_INTMASK2 = 0x08, |
| 43 | MAX14577_REG_INTMASK3 = 0x09, |
| 44 | MAX14577_REG_CDETCTRL1 = 0x0A, |
| 45 | MAX14577_REG_RFU = 0x0B, |
| 46 | MAX14577_REG_CONTROL1 = 0x0C, |
| 47 | MAX14577_REG_CONTROL2 = 0x0D, |
| 48 | MAX14577_REG_CONTROL3 = 0x0E, |
| 49 | MAX14577_REG_CHGCTRL1 = 0x0F, |
| 50 | MAX14577_REG_CHGCTRL2 = 0x10, |
| 51 | MAX14577_REG_CHGCTRL3 = 0x11, |
| 52 | MAX14577_REG_CHGCTRL4 = 0x12, |
| 53 | MAX14577_REG_CHGCTRL5 = 0x13, |
| 54 | MAX14577_REG_CHGCTRL6 = 0x14, |
| 55 | MAX14577_REG_CHGCTRL7 = 0x15, |
| 56 | |
| 57 | MAX14577_REG_END, |
| 58 | }; |
| 59 | |
| 60 | /* Slave addr = 0x4A: MUIC */ |
| 61 | enum max14577_muic_reg { |
| 62 | MAX14577_MUIC_REG_STATUS1 = 0x04, |
| 63 | MAX14577_MUIC_REG_STATUS2 = 0x05, |
| 64 | MAX14577_MUIC_REG_CONTROL1 = 0x0C, |
| 65 | MAX14577_MUIC_REG_CONTROL3 = 0x0E, |
| 66 | |
| 67 | MAX14577_MUIC_REG_END, |
| 68 | }; |
| 69 | |
| 70 | enum max14577_muic_charger_type { |
| 71 | MAX14577_CHARGER_TYPE_NONE = 0, |
| 72 | MAX14577_CHARGER_TYPE_USB, |
| 73 | MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT, |
| 74 | MAX14577_CHARGER_TYPE_DEDICATED_CHG, |
| 75 | MAX14577_CHARGER_TYPE_SPECIAL_500MA, |
| 76 | MAX14577_CHARGER_TYPE_SPECIAL_1A, |
| 77 | MAX14577_CHARGER_TYPE_RESERVED, |
| 78 | MAX14577_CHARGER_TYPE_DEAD_BATTERY = 7, |
| 79 | }; |
| 80 | |
| 81 | /* MAX14577 interrupts */ |
Krzysztof Kozlowski | c784685 | 2014-04-14 11:17:17 +0200 | [diff] [blame^] | 82 | #define MAX14577_INT1_ADC_MASK BIT(0) |
| 83 | #define MAX14577_INT1_ADCLOW_MASK BIT(1) |
| 84 | #define MAX14577_INT1_ADCERR_MASK BIT(2) |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 85 | |
Krzysztof Kozlowski | c784685 | 2014-04-14 11:17:17 +0200 | [diff] [blame^] | 86 | #define MAX14577_INT2_CHGTYP_MASK BIT(0) |
| 87 | #define MAX14577_INT2_CHGDETRUN_MASK BIT(1) |
| 88 | #define MAX14577_INT2_DCDTMR_MASK BIT(2) |
| 89 | #define MAX14577_INT2_DBCHG_MASK BIT(3) |
| 90 | #define MAX14577_INT2_VBVOLT_MASK BIT(4) |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 91 | |
Krzysztof Kozlowski | c784685 | 2014-04-14 11:17:17 +0200 | [diff] [blame^] | 92 | #define MAX14577_INT3_EOC_MASK BIT(0) |
| 93 | #define MAX14577_INT3_CGMBC_MASK BIT(1) |
| 94 | #define MAX14577_INT3_OVP_MASK BIT(2) |
| 95 | #define MAX14577_INT3_MBCCHGERR_MASK BIT(3) |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 96 | |
| 97 | /* MAX14577 DEVICE ID register */ |
| 98 | #define DEVID_VENDORID_SHIFT 0 |
| 99 | #define DEVID_DEVICEID_SHIFT 3 |
| 100 | #define DEVID_VENDORID_MASK (0x07 << DEVID_VENDORID_SHIFT) |
| 101 | #define DEVID_DEVICEID_MASK (0x1f << DEVID_DEVICEID_SHIFT) |
| 102 | |
| 103 | /* MAX14577 STATUS1 register */ |
| 104 | #define STATUS1_ADC_SHIFT 0 |
| 105 | #define STATUS1_ADCLOW_SHIFT 5 |
| 106 | #define STATUS1_ADCERR_SHIFT 6 |
| 107 | #define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT) |
| 108 | #define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT) |
| 109 | #define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT) |
| 110 | |
| 111 | /* MAX14577 STATUS2 register */ |
| 112 | #define STATUS2_CHGTYP_SHIFT 0 |
| 113 | #define STATUS2_CHGDETRUN_SHIFT 3 |
| 114 | #define STATUS2_DCDTMR_SHIFT 4 |
| 115 | #define STATUS2_DBCHG_SHIFT 5 |
| 116 | #define STATUS2_VBVOLT_SHIFT 6 |
| 117 | #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) |
| 118 | #define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT) |
| 119 | #define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT) |
| 120 | #define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT) |
| 121 | #define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT) |
| 122 | |
| 123 | /* MAX14577 CONTROL1 register */ |
| 124 | #define COMN1SW_SHIFT 0 |
| 125 | #define COMP2SW_SHIFT 3 |
| 126 | #define MICEN_SHIFT 6 |
| 127 | #define IDBEN_SHIFT 7 |
| 128 | #define COMN1SW_MASK (0x7 << COMN1SW_SHIFT) |
| 129 | #define COMP2SW_MASK (0x7 << COMP2SW_SHIFT) |
| 130 | #define MICEN_MASK (0x1 << MICEN_SHIFT) |
| 131 | #define IDBEN_MASK (0x1 << IDBEN_SHIFT) |
| 132 | #define CLEAR_IDBEN_MICEN_MASK (COMN1SW_MASK | COMP2SW_MASK) |
| 133 | #define CTRL1_SW_USB ((1 << COMP2SW_SHIFT) \ |
| 134 | | (1 << COMN1SW_SHIFT)) |
| 135 | #define CTRL1_SW_AUDIO ((2 << COMP2SW_SHIFT) \ |
| 136 | | (2 << COMN1SW_SHIFT)) |
| 137 | #define CTRL1_SW_UART ((3 << COMP2SW_SHIFT) \ |
| 138 | | (3 << COMN1SW_SHIFT)) |
| 139 | #define CTRL1_SW_OPEN ((0 << COMP2SW_SHIFT) \ |
| 140 | | (0 << COMN1SW_SHIFT)) |
| 141 | |
| 142 | /* MAX14577 CONTROL2 register */ |
| 143 | #define CTRL2_LOWPWR_SHIFT (0) |
| 144 | #define CTRL2_ADCEN_SHIFT (1) |
| 145 | #define CTRL2_CPEN_SHIFT (2) |
| 146 | #define CTRL2_SFOUTASRT_SHIFT (3) |
| 147 | #define CTRL2_SFOUTORD_SHIFT (4) |
| 148 | #define CTRL2_ACCDET_SHIFT (5) |
| 149 | #define CTRL2_USBCPINT_SHIFT (6) |
| 150 | #define CTRL2_RCPS_SHIFT (7) |
| 151 | #define CTRL2_LOWPWR_MASK (0x1 << CTRL2_LOWPWR_SHIFT) |
| 152 | #define CTRL2_ADCEN_MASK (0x1 << CTRL2_ADCEN_SHIFT) |
| 153 | #define CTRL2_CPEN_MASK (0x1 << CTRL2_CPEN_SHIFT) |
| 154 | #define CTRL2_SFOUTASRT_MASK (0x1 << CTRL2_SFOUTASRT_SHIFT) |
| 155 | #define CTRL2_SFOUTORD_MASK (0x1 << CTRL2_SFOUTORD_SHIFT) |
| 156 | #define CTRL2_ACCDET_MASK (0x1 << CTRL2_ACCDET_SHIFT) |
| 157 | #define CTRL2_USBCPINT_MASK (0x1 << CTRL2_USBCPINT_SHIFT) |
| 158 | #define CTRL2_RCPS_MASK (0x1 << CTR2_RCPS_SHIFT) |
| 159 | |
| 160 | #define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \ |
| 161 | (0 << CTRL2_LOWPWR_SHIFT)) |
| 162 | #define CTRL2_CPEN0_LOWPWR1 ((0 << CTRL2_CPEN_SHIFT) | \ |
| 163 | (1 << CTRL2_LOWPWR_SHIFT)) |
| 164 | |
| 165 | /* MAX14577 CONTROL3 register */ |
| 166 | #define CTRL3_JIGSET_SHIFT 0 |
| 167 | #define CTRL3_BOOTSET_SHIFT 2 |
| 168 | #define CTRL3_ADCDBSET_SHIFT 4 |
| 169 | #define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT) |
| 170 | #define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT) |
| 171 | #define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT) |
| 172 | |
| 173 | /* Slave addr = 0x4A: Charger */ |
| 174 | enum max14577_charger_reg { |
| 175 | MAX14577_CHG_REG_STATUS3 = 0x06, |
| 176 | MAX14577_CHG_REG_CHG_CTRL1 = 0x0F, |
| 177 | MAX14577_CHG_REG_CHG_CTRL2 = 0x10, |
| 178 | MAX14577_CHG_REG_CHG_CTRL3 = 0x11, |
| 179 | MAX14577_CHG_REG_CHG_CTRL4 = 0x12, |
| 180 | MAX14577_CHG_REG_CHG_CTRL5 = 0x13, |
| 181 | MAX14577_CHG_REG_CHG_CTRL6 = 0x14, |
| 182 | MAX14577_CHG_REG_CHG_CTRL7 = 0x15, |
| 183 | |
| 184 | MAX14577_CHG_REG_END, |
| 185 | }; |
| 186 | |
| 187 | /* MAX14577 STATUS3 register */ |
| 188 | #define STATUS3_EOC_SHIFT 0 |
| 189 | #define STATUS3_CGMBC_SHIFT 1 |
| 190 | #define STATUS3_OVP_SHIFT 2 |
| 191 | #define STATUS3_MBCCHGERR_SHIFT 3 |
| 192 | #define STATUS3_EOC_MASK (0x1 << STATUS3_EOC_SHIFT) |
| 193 | #define STATUS3_CGMBC_MASK (0x1 << STATUS3_CGMBC_SHIFT) |
| 194 | #define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT) |
| 195 | #define STATUS3_MBCCHGERR_MASK (0x1 << STATUS3_MBCCHGERR_SHIFT) |
| 196 | |
| 197 | /* MAX14577 CDETCTRL1 register */ |
| 198 | #define CDETCTRL1_CHGDETEN_SHIFT 0 |
| 199 | #define CDETCTRL1_CHGTYPMAN_SHIFT 1 |
| 200 | #define CDETCTRL1_DCDEN_SHIFT 2 |
| 201 | #define CDETCTRL1_DCD2SCT_SHIFT 3 |
| 202 | #define CDETCTRL1_DCHKTM_SHIFT 4 |
| 203 | #define CDETCTRL1_DBEXIT_SHIFT 5 |
| 204 | #define CDETCTRL1_DBIDLE_SHIFT 6 |
| 205 | #define CDETCTRL1_CDPDET_SHIFT 7 |
| 206 | #define CDETCTRL1_CHGDETEN_MASK (0x1 << CDETCTRL1_CHGDETEN_SHIFT) |
| 207 | #define CDETCTRL1_CHGTYPMAN_MASK (0x1 << CDETCTRL1_CHGTYPMAN_SHIFT) |
| 208 | #define CDETCTRL1_DCDEN_MASK (0x1 << CDETCTRL1_DCDEN_SHIFT) |
| 209 | #define CDETCTRL1_DCD2SCT_MASK (0x1 << CDETCTRL1_DCD2SCT_SHIFT) |
| 210 | #define CDETCTRL1_DCHKTM_MASK (0x1 << CDETCTRL1_DCHKTM_SHIFT) |
| 211 | #define CDETCTRL1_DBEXIT_MASK (0x1 << CDETCTRL1_DBEXIT_SHIFT) |
| 212 | #define CDETCTRL1_DBIDLE_MASK (0x1 << CDETCTRL1_DBIDLE_SHIFT) |
| 213 | #define CDETCTRL1_CDPDET_MASK (0x1 << CDETCTRL1_CDPDET_SHIFT) |
| 214 | |
| 215 | /* MAX14577 CHGCTRL1 register */ |
| 216 | #define CHGCTRL1_TCHW_SHIFT 4 |
| 217 | #define CHGCTRL1_TCHW_MASK (0x7 << CHGCTRL1_TCHW_SHIFT) |
| 218 | |
| 219 | /* MAX14577 CHGCTRL2 register */ |
| 220 | #define CHGCTRL2_MBCHOSTEN_SHIFT 6 |
| 221 | #define CHGCTRL2_MBCHOSTEN_MASK (0x1 << CHGCTRL2_MBCHOSTEN_SHIFT) |
| 222 | #define CHGCTRL2_VCHGR_RC_SHIFT 7 |
| 223 | #define CHGCTRL2_VCHGR_RC_MASK (0x1 << CHGCTRL2_VCHGR_RC_SHIFT) |
| 224 | |
| 225 | /* MAX14577 CHGCTRL3 register */ |
| 226 | #define CHGCTRL3_MBCCVWRC_SHIFT 0 |
| 227 | #define CHGCTRL3_MBCCVWRC_MASK (0xf << CHGCTRL3_MBCCVWRC_SHIFT) |
| 228 | |
| 229 | /* MAX14577 CHGCTRL4 register */ |
| 230 | #define CHGCTRL4_MBCICHWRCH_SHIFT 0 |
| 231 | #define CHGCTRL4_MBCICHWRCH_MASK (0xf << CHGCTRL4_MBCICHWRCH_SHIFT) |
| 232 | #define CHGCTRL4_MBCICHWRCL_SHIFT 4 |
| 233 | #define CHGCTRL4_MBCICHWRCL_MASK (0x1 << CHGCTRL4_MBCICHWRCL_SHIFT) |
| 234 | |
| 235 | /* MAX14577 CHGCTRL5 register */ |
| 236 | #define CHGCTRL5_EOCS_SHIFT 0 |
| 237 | #define CHGCTRL5_EOCS_MASK (0xf << CHGCTRL5_EOCS_SHIFT) |
| 238 | |
| 239 | /* MAX14577 CHGCTRL6 register */ |
| 240 | #define CHGCTRL6_AUTOSTOP_SHIFT 5 |
| 241 | #define CHGCTRL6_AUTOSTOP_MASK (0x1 << CHGCTRL6_AUTOSTOP_SHIFT) |
| 242 | |
| 243 | /* MAX14577 CHGCTRL7 register */ |
| 244 | #define CHGCTRL7_OTPCGHCVS_SHIFT 0 |
| 245 | #define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT) |
| 246 | |
| 247 | /* MAX14577 regulator current limits (as in CHGCTRL4 register), uA */ |
| 248 | #define MAX14577_REGULATOR_CURRENT_LIMIT_MIN 90000 |
| 249 | #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START 200000 |
| 250 | #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000 |
| 251 | #define MAX14577_REGULATOR_CURRENT_LIMIT_MAX 950000 |
| 252 | |
| 253 | /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */ |
| 254 | #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000 |
| 255 | |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 256 | enum max14577_irq { |
| 257 | /* INT1 */ |
| 258 | MAX14577_IRQ_INT1_ADC, |
| 259 | MAX14577_IRQ_INT1_ADCLOW, |
| 260 | MAX14577_IRQ_INT1_ADCERR, |
| 261 | |
| 262 | /* INT2 */ |
| 263 | MAX14577_IRQ_INT2_CHGTYP, |
| 264 | MAX14577_IRQ_INT2_CHGDETRUN, |
| 265 | MAX14577_IRQ_INT2_DCDTMR, |
| 266 | MAX14577_IRQ_INT2_DBCHG, |
| 267 | MAX14577_IRQ_INT2_VBVOLT, |
| 268 | |
| 269 | /* INT3 */ |
| 270 | MAX14577_IRQ_INT3_EOC, |
| 271 | MAX14577_IRQ_INT3_CGMBC, |
| 272 | MAX14577_IRQ_INT3_OVP, |
| 273 | MAX14577_IRQ_INT3_MBCCHGERR, |
| 274 | |
| 275 | MAX14577_IRQ_NUM, |
| 276 | }; |
| 277 | |
| 278 | struct max14577 { |
| 279 | struct device *dev; |
| 280 | struct i2c_client *i2c; /* Slave addr = 0x4A */ |
Krzysztof Kozlowski | eccb80c | 2014-04-14 11:17:14 +0200 | [diff] [blame] | 281 | enum maxim_device_type dev_type; |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 282 | |
| 283 | struct regmap *regmap; |
| 284 | |
| 285 | struct regmap_irq_chip_data *irq_data; |
| 286 | int irq; |
Chanwoo Choi | 3008ddb | 2013-11-22 16:51:05 +0100 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | /* MAX14577 shared regmap API function */ |
| 290 | static inline int max14577_read_reg(struct regmap *map, u8 reg, u8 *dest) |
| 291 | { |
| 292 | unsigned int val; |
| 293 | int ret; |
| 294 | |
| 295 | ret = regmap_read(map, reg, &val); |
| 296 | *dest = val; |
| 297 | |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | static inline int max14577_bulk_read(struct regmap *map, u8 reg, u8 *buf, |
| 302 | int count) |
| 303 | { |
| 304 | return regmap_bulk_read(map, reg, buf, count); |
| 305 | } |
| 306 | |
| 307 | static inline int max14577_write_reg(struct regmap *map, u8 reg, u8 value) |
| 308 | { |
| 309 | return regmap_write(map, reg, value); |
| 310 | } |
| 311 | |
| 312 | static inline int max14577_bulk_write(struct regmap *map, u8 reg, u8 *buf, |
| 313 | int count) |
| 314 | { |
| 315 | return regmap_bulk_write(map, reg, buf, count); |
| 316 | } |
| 317 | |
| 318 | static inline int max14577_update_reg(struct regmap *map, u8 reg, u8 mask, |
| 319 | u8 val) |
| 320 | { |
| 321 | return regmap_update_bits(map, reg, mask, val); |
| 322 | } |
| 323 | |
| 324 | #endif /* __MAX14577_PRIVATE_H__ */ |