0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __LINUX_MFD_88PM80X_H
0010 #define __LINUX_MFD_88PM80X_H
0011
0012 #include <linux/platform_device.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/regmap.h>
0015 #include <linux/atomic.h>
0016
0017 enum {
0018 CHIP_INVALID = 0,
0019 CHIP_PM800,
0020 CHIP_PM805,
0021 CHIP_PM860,
0022 CHIP_MAX,
0023 };
0024
0025 enum {
0026 PM800_ID_BUCK1 = 0,
0027 PM800_ID_BUCK2,
0028 PM800_ID_BUCK3,
0029 PM800_ID_BUCK4,
0030 PM800_ID_BUCK5,
0031
0032 PM800_ID_LDO1,
0033 PM800_ID_LDO2,
0034 PM800_ID_LDO3,
0035 PM800_ID_LDO4,
0036 PM800_ID_LDO5,
0037 PM800_ID_LDO6,
0038 PM800_ID_LDO7,
0039 PM800_ID_LDO8,
0040 PM800_ID_LDO9,
0041 PM800_ID_LDO10,
0042 PM800_ID_LDO11,
0043 PM800_ID_LDO12,
0044 PM800_ID_LDO13,
0045 PM800_ID_LDO14,
0046 PM800_ID_LDO15,
0047 PM800_ID_LDO16,
0048 PM800_ID_LDO17,
0049 PM800_ID_LDO18,
0050 PM800_ID_LDO19,
0051
0052 PM800_ID_RG_MAX,
0053 };
0054 #define PM800_MAX_REGULATOR PM800_ID_RG_MAX
0055 #define PM800_NUM_BUCK (5)
0056 #define PM800_NUM_LDO (19)
0057
0058
0059
0060 #define PM800_STATUS_1 (0x01)
0061 #define PM800_ONKEY_STS1 BIT(0)
0062 #define PM800_EXTON_STS1 BIT(1)
0063 #define PM800_CHG_STS1 BIT(2)
0064 #define PM800_BAT_STS1 BIT(3)
0065 #define PM800_VBUS_STS1 BIT(4)
0066 #define PM800_LDO_PGOOD_STS1 BIT(5)
0067 #define PM800_BUCK_PGOOD_STS1 BIT(6)
0068
0069 #define PM800_STATUS_2 (0x02)
0070 #define PM800_RTC_ALARM_STS2 BIT(0)
0071
0072
0073 #define PM800_WAKEUP1 (0x0D)
0074
0075 #define PM800_WAKEUP2 (0x0E)
0076 #define PM800_WAKEUP2_INV_INT BIT(0)
0077 #define PM800_WAKEUP2_INT_CLEAR BIT(1)
0078 #define PM800_WAKEUP2_INT_MASK BIT(2)
0079
0080 #define PM800_POWER_UP_LOG (0x10)
0081
0082
0083 #define PM800_LOW_POWER1 (0x20)
0084 #define PM800_LOW_POWER2 (0x21)
0085 #define PM800_LOW_POWER_CONFIG3 (0x22)
0086 #define PM800_LOW_POWER_CONFIG4 (0x23)
0087
0088
0089 #define PM800_GPIO_0_1_CNTRL (0x30)
0090 #define PM800_GPIO0_VAL BIT(0)
0091 #define PM800_GPIO0_GPIO_MODE(x) (x << 1)
0092 #define PM800_GPIO1_VAL BIT(4)
0093 #define PM800_GPIO1_GPIO_MODE(x) (x << 5)
0094
0095 #define PM800_GPIO_2_3_CNTRL (0x31)
0096 #define PM800_GPIO2_VAL BIT(0)
0097 #define PM800_GPIO2_GPIO_MODE(x) (x << 1)
0098 #define PM800_GPIO3_VAL BIT(4)
0099 #define PM800_GPIO3_GPIO_MODE(x) (x << 5)
0100 #define PM800_GPIO3_MODE_MASK 0x1F
0101 #define PM800_GPIO3_HEADSET_MODE PM800_GPIO3_GPIO_MODE(6)
0102
0103 #define PM800_GPIO_4_CNTRL (0x32)
0104 #define PM800_GPIO4_VAL BIT(0)
0105 #define PM800_GPIO4_GPIO_MODE(x) (x << 1)
0106
0107 #define PM800_HEADSET_CNTRL (0x38)
0108 #define PM800_HEADSET_DET_EN BIT(7)
0109 #define PM800_HSDET_SLP BIT(1)
0110
0111 #define PM800_PWM1 (0x40)
0112 #define PM800_PWM2 (0x41)
0113 #define PM800_PWM3 (0x42)
0114 #define PM800_PWM4 (0x43)
0115
0116
0117 #define PM800_RTC_CONTROL (0xD0)
0118 #define PM800_RTC_MISC1 (0xE1)
0119 #define PM800_RTC_MISC2 (0xE2)
0120 #define PM800_RTC_MISC3 (0xE3)
0121 #define PM800_RTC_MISC4 (0xE4)
0122 #define PM800_RTC_MISC5 (0xE7)
0123
0124 #define PM800_ALARM1_EN BIT(0)
0125 #define PM800_ALARM_WAKEUP BIT(4)
0126 #define PM800_ALARM BIT(5)
0127 #define PM800_RTC1_USE_XO BIT(7)
0128
0129
0130
0131
0132 #define PM800_SLEEP_BUCK1 (0x30)
0133
0134
0135 #define PM800_BUCK_SLP1 (0x5A)
0136 #define PM800_BUCK1_SLP1_SHIFT 0
0137 #define PM800_BUCK1_SLP1_MASK (0x3 << PM800_BUCK1_SLP1_SHIFT)
0138
0139
0140 #define PM800_GPADC_MEAS_EN1 (0x01)
0141 #define PM800_MEAS_EN1_VBAT BIT(2)
0142 #define PM800_GPADC_MEAS_EN2 (0x02)
0143 #define PM800_MEAS_EN2_RFTMP BIT(0)
0144 #define PM800_MEAS_GP0_EN BIT(2)
0145 #define PM800_MEAS_GP1_EN BIT(3)
0146 #define PM800_MEAS_GP2_EN BIT(4)
0147 #define PM800_MEAS_GP3_EN BIT(5)
0148 #define PM800_MEAS_GP4_EN BIT(6)
0149
0150 #define PM800_GPADC_MISC_CONFIG1 (0x05)
0151 #define PM800_GPADC_MISC_CONFIG2 (0x06)
0152 #define PM800_GPADC_MISC_GPFSM_EN BIT(0)
0153 #define PM800_GPADC_SLOW_MODE(x) (x << 3)
0154
0155 #define PM800_GPADC_MISC_CONFIG3 (0x09)
0156 #define PM800_GPADC_MISC_CONFIG4 (0x0A)
0157
0158 #define PM800_GPADC_PREBIAS1 (0x0F)
0159 #define PM800_GPADC0_GP_PREBIAS_TIME(x) (x << 0)
0160 #define PM800_GPADC_PREBIAS2 (0x10)
0161
0162 #define PM800_GP_BIAS_ENA1 (0x14)
0163 #define PM800_GPADC_GP_BIAS_EN0 BIT(0)
0164 #define PM800_GPADC_GP_BIAS_EN1 BIT(1)
0165 #define PM800_GPADC_GP_BIAS_EN2 BIT(2)
0166 #define PM800_GPADC_GP_BIAS_EN3 BIT(3)
0167
0168 #define PM800_GP_BIAS_OUT1 (0x15)
0169 #define PM800_BIAS_OUT_GP0 BIT(0)
0170 #define PM800_BIAS_OUT_GP1 BIT(1)
0171 #define PM800_BIAS_OUT_GP2 BIT(2)
0172 #define PM800_BIAS_OUT_GP3 BIT(3)
0173
0174 #define PM800_GPADC0_LOW_TH 0x20
0175 #define PM800_GPADC1_LOW_TH 0x21
0176 #define PM800_GPADC2_LOW_TH 0x22
0177 #define PM800_GPADC3_LOW_TH 0x23
0178 #define PM800_GPADC4_LOW_TH 0x24
0179
0180 #define PM800_GPADC0_UPP_TH 0x30
0181 #define PM800_GPADC1_UPP_TH 0x31
0182 #define PM800_GPADC2_UPP_TH 0x32
0183 #define PM800_GPADC3_UPP_TH 0x33
0184 #define PM800_GPADC4_UPP_TH 0x34
0185
0186 #define PM800_VBBAT_MEAS1 0x40
0187 #define PM800_VBBAT_MEAS2 0x41
0188 #define PM800_VBAT_MEAS1 0x42
0189 #define PM800_VBAT_MEAS2 0x43
0190 #define PM800_VSYS_MEAS1 0x44
0191 #define PM800_VSYS_MEAS2 0x45
0192 #define PM800_VCHG_MEAS1 0x46
0193 #define PM800_VCHG_MEAS2 0x47
0194 #define PM800_TINT_MEAS1 0x50
0195 #define PM800_TINT_MEAS2 0x51
0196 #define PM800_PMOD_MEAS1 0x52
0197 #define PM800_PMOD_MEAS2 0x53
0198
0199 #define PM800_GPADC0_MEAS1 0x54
0200 #define PM800_GPADC0_MEAS2 0x55
0201 #define PM800_GPADC1_MEAS1 0x56
0202 #define PM800_GPADC1_MEAS2 0x57
0203 #define PM800_GPADC2_MEAS1 0x58
0204 #define PM800_GPADC2_MEAS2 0x59
0205 #define PM800_GPADC3_MEAS1 0x5A
0206 #define PM800_GPADC3_MEAS2 0x5B
0207 #define PM800_GPADC4_MEAS1 0x5C
0208 #define PM800_GPADC4_MEAS2 0x5D
0209
0210 #define PM800_GPADC4_AVG1 0xA8
0211 #define PM800_GPADC4_AVG2 0xA9
0212
0213
0214 #define PM805_MAIN_POWERUP (0x01)
0215 #define PM805_INT_STATUS0 (0x02)
0216
0217 #define PM805_STATUS0_INT_CLEAR (1 << 0)
0218 #define PM805_STATUS0_INV_INT (1 << 1)
0219 #define PM800_STATUS0_INT_MASK (1 << 2)
0220
0221 #define PM805_INT_STATUS1 (0x03)
0222
0223 #define PM805_INT1_HP1_SHRT BIT(0)
0224 #define PM805_INT1_HP2_SHRT BIT(1)
0225 #define PM805_INT1_MIC_CONFLICT BIT(2)
0226 #define PM805_INT1_CLIP_FAULT BIT(3)
0227 #define PM805_INT1_LDO_OFF BIT(4)
0228 #define PM805_INT1_SRC_DPLL_LOCK BIT(5)
0229
0230 #define PM805_INT_STATUS2 (0x04)
0231
0232 #define PM805_INT2_MIC_DET BIT(0)
0233 #define PM805_INT2_SHRT_BTN_DET BIT(1)
0234 #define PM805_INT2_VOLM_BTN_DET BIT(2)
0235 #define PM805_INT2_VOLP_BTN_DET BIT(3)
0236 #define PM805_INT2_RAW_PLL_FAULT BIT(4)
0237 #define PM805_INT2_FINE_PLL_FAULT BIT(5)
0238
0239 #define PM805_INT_MASK1 (0x05)
0240 #define PM805_INT_MASK2 (0x06)
0241 #define PM805_SHRT_BTN_DET BIT(1)
0242
0243
0244 #define PM805_INT_REG_NUM (2)
0245
0246 #define PM805_MIC_DET1 (0x07)
0247 #define PM805_MIC_DET_EN_MIC_DET BIT(0)
0248 #define PM805_MIC_DET2 (0x08)
0249 #define PM805_MIC_DET_STATUS1 (0x09)
0250
0251 #define PM805_MIC_DET_STATUS3 (0x0A)
0252 #define PM805_AUTO_SEQ_STATUS1 (0x0B)
0253 #define PM805_AUTO_SEQ_STATUS2 (0x0C)
0254
0255 #define PM805_ADC_SETTING1 (0x10)
0256 #define PM805_ADC_SETTING2 (0x11)
0257 #define PM805_ADC_SETTING3 (0x11)
0258 #define PM805_ADC_GAIN1 (0x12)
0259 #define PM805_ADC_GAIN2 (0x13)
0260 #define PM805_DMIC_SETTING (0x15)
0261 #define PM805_DWS_SETTING (0x16)
0262 #define PM805_MIC_CONFLICT_STS (0x17)
0263
0264 #define PM805_PDM_SETTING1 (0x20)
0265 #define PM805_PDM_SETTING2 (0x21)
0266 #define PM805_PDM_SETTING3 (0x22)
0267 #define PM805_PDM_CONTROL1 (0x23)
0268 #define PM805_PDM_CONTROL2 (0x24)
0269 #define PM805_PDM_CONTROL3 (0x25)
0270
0271 #define PM805_HEADPHONE_SETTING (0x26)
0272 #define PM805_HEADPHONE_GAIN_A2A (0x27)
0273 #define PM805_HEADPHONE_SHORT_STATE (0x28)
0274 #define PM805_EARPHONE_SETTING (0x29)
0275 #define PM805_AUTO_SEQ_SETTING (0x2A)
0276
0277 struct pm80x_rtc_pdata {
0278 int vrtc;
0279 int rtc_wakeup;
0280 };
0281
0282 struct pm80x_subchip {
0283 struct i2c_client *power_page;
0284 struct i2c_client *gpadc_page;
0285 struct regmap *regmap_power;
0286 struct regmap *regmap_gpadc;
0287 unsigned short power_page_addr;
0288 unsigned short gpadc_page_addr;
0289 };
0290
0291 struct pm80x_chip {
0292 struct pm80x_subchip *subchip;
0293 struct device *dev;
0294 struct i2c_client *client;
0295 struct i2c_client *companion;
0296 struct regmap *regmap;
0297 struct regmap_irq_chip *regmap_irq_chip;
0298 struct regmap_irq_chip_data *irq_data;
0299 int type;
0300 int irq;
0301 int irq_mode;
0302 unsigned long wu_flag;
0303 spinlock_t lock;
0304 };
0305
0306 struct pm80x_platform_data {
0307 struct pm80x_rtc_pdata *rtc;
0308
0309
0310
0311
0312
0313
0314 struct regulator_init_data *regulators[PM800_ID_RG_MAX];
0315 unsigned int num_regulators;
0316 int irq_mode;
0317 int batt_det;
0318 int (*plat_config)(struct pm80x_chip *chip,
0319 struct pm80x_platform_data *pdata);
0320 };
0321
0322 extern const struct dev_pm_ops pm80x_pm_ops;
0323 extern const struct regmap_config pm80x_regmap_config;
0324
0325 static inline int pm80x_request_irq(struct pm80x_chip *pm80x, int irq,
0326 irq_handler_t handler, unsigned long flags,
0327 const char *name, void *data)
0328 {
0329 if (!pm80x->irq_data)
0330 return -EINVAL;
0331 return request_threaded_irq(regmap_irq_get_virq(pm80x->irq_data, irq),
0332 NULL, handler, flags, name, data);
0333 }
0334
0335 static inline void pm80x_free_irq(struct pm80x_chip *pm80x, int irq, void *data)
0336 {
0337 if (!pm80x->irq_data)
0338 return;
0339 free_irq(regmap_irq_get_virq(pm80x->irq_data, irq), data);
0340 }
0341
0342 #ifdef CONFIG_PM
0343 static inline int pm80x_dev_suspend(struct device *dev)
0344 {
0345 struct platform_device *pdev = to_platform_device(dev);
0346 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
0347 int irq = platform_get_irq(pdev, 0);
0348
0349 if (device_may_wakeup(dev))
0350 set_bit(irq, &chip->wu_flag);
0351
0352 return 0;
0353 }
0354
0355 static inline int pm80x_dev_resume(struct device *dev)
0356 {
0357 struct platform_device *pdev = to_platform_device(dev);
0358 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
0359 int irq = platform_get_irq(pdev, 0);
0360
0361 if (device_may_wakeup(dev))
0362 clear_bit(irq, &chip->wu_flag);
0363
0364 return 0;
0365 }
0366 #endif
0367
0368 extern int pm80x_init(struct i2c_client *client);
0369 extern int pm80x_deinit(void);
0370 #endif