Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | /* |
| 14 | * Qualcomm PMIC8058 driver header file |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/irq.h> |
| 19 | #include <linux/mfd/core.h> |
| 20 | |
| 21 | #define PM8058_GPIOS 40 |
| 22 | #define PM8058_MPPS 12 |
| 23 | |
| 24 | #define PM8058_IRQ_BLOCK_BIT(block, bit) ((block) * 8 + (bit)) |
| 25 | |
| 26 | /* MPPs and GPIOs [0,N) */ |
| 27 | #define PM8058_MPP_IRQ(base, mpp) ((base) + \ |
| 28 | PM8058_IRQ_BLOCK_BIT(16, (mpp))) |
| 29 | #define PM8058_GPIO_IRQ(base, gpio) ((base) + \ |
| 30 | PM8058_IRQ_BLOCK_BIT(24, (gpio))) |
| 31 | |
| 32 | #define PM8058_KEYPAD_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(9, 2)) |
| 33 | #define PM8058_KEYSTUCK_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(9, 3)) |
| 34 | |
| 35 | #define PM8058_VCP_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 0)) |
| 36 | #define PM8058_CHGILIM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 3)) |
| 37 | #define PM8058_VBATDET_LOW_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 4)) |
| 38 | #define PM8058_BATT_REPLACE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 5)) |
| 39 | #define PM8058_CHGINVAL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 6)) |
| 40 | #define PM8058_CHGVAL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(1, 7)) |
| 41 | #define PM8058_CHG_END_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 0)) |
| 42 | #define PM8058_FASTCHG_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 1)) |
| 43 | #define PM8058_CHGSTATE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 3)) |
| 44 | #define PM8058_AUTO_CHGFAIL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 4)) |
| 45 | #define PM8058_AUTO_CHGDONE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 5)) |
| 46 | #define PM8058_ATCFAIL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 6)) |
| 47 | #define PM8058_ATC_DONE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(2, 7)) |
| 48 | #define PM8058_OVP_OK_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 0)) |
| 49 | #define PM8058_COARSE_DET_OVP_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 1)) |
| 50 | #define PM8058_VCPMAJOR_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 2)) |
| 51 | #define PM8058_CHG_GONE_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 3)) |
| 52 | #define PM8058_CHGTLIMIT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 4)) |
| 53 | #define PM8058_CHGHOT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 5)) |
| 54 | #define PM8058_BATTTEMP_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 6)) |
| 55 | #define PM8058_BATTCONNECT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(3, 7)) |
| 56 | #define PM8058_BATFET_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 4)) |
| 57 | #define PM8058_VBATDET_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 5)) |
| 58 | #define PM8058_VBAT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 6)) |
| 59 | |
| 60 | #define PM8058_CBLPWR_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(4, 3)) |
| 61 | |
| 62 | #define PM8058_PWRKEY_REL_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 2)) |
| 63 | #define PM8058_PWRKEY_PRESS_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 3)) |
| 64 | #define PM8058_SW_0_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 1)) |
| 65 | #define PM8058_IR_0_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 0)) |
| 66 | #define PM8058_SW_1_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 3)) |
| 67 | #define PM8058_IR_1_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 2)) |
| 68 | #define PM8058_SW_2_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 5)) |
| 69 | #define PM8058_IR_2_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(7, 4)) |
| 70 | #define PM8058_RTC_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 5)) |
| 71 | #define PM8058_RTC_ALARM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(4, 7)) |
| 72 | #define PM8058_ADC_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(9, 4)) |
| 73 | #define PM8058_TEMP_ALARM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(6, 7)) |
| 74 | #define PM8058_OSCHALT_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(4, 6)) |
| 75 | #define PM8058_BATT_ALARM_IRQ(base) ((base) + PM8058_IRQ_BLOCK_BIT(5, 6)) |
| 76 | |
| 77 | struct pm8058_chip; |
| 78 | |
| 79 | struct pm8058_platform_data { |
| 80 | /* This table is only needed for misc interrupts. */ |
| 81 | int irq_base; |
| 82 | int (*init)(struct pm8058_chip *pm_chip); |
| 83 | |
| 84 | int num_subdevs; |
| 85 | struct mfd_cell *sub_devices; |
| 86 | int irq_trigger_flags; |
| 87 | struct mfd_cell *charger_sub_device; |
| 88 | }; |
| 89 | |
| 90 | struct pm8058_gpio_platform_data { |
| 91 | int gpio_base; |
| 92 | int irq_base; |
| 93 | int (*init)(void); |
| 94 | }; |
| 95 | |
| 96 | /* GPIO parameters */ |
| 97 | /* direction */ |
| 98 | #define PM_GPIO_DIR_OUT 0x01 |
| 99 | #define PM_GPIO_DIR_IN 0x02 |
| 100 | #define PM_GPIO_DIR_BOTH (PM_GPIO_DIR_OUT | PM_GPIO_DIR_IN) |
| 101 | |
| 102 | /* output_buffer */ |
| 103 | #define PM_GPIO_OUT_BUF_OPEN_DRAIN 1 |
| 104 | #define PM_GPIO_OUT_BUF_CMOS 0 |
| 105 | |
| 106 | /* pull */ |
| 107 | #define PM_GPIO_PULL_UP_30 0 |
| 108 | #define PM_GPIO_PULL_UP_1P5 1 |
| 109 | #define PM_GPIO_PULL_UP_31P5 2 |
| 110 | #define PM_GPIO_PULL_UP_1P5_30 3 |
| 111 | #define PM_GPIO_PULL_DN 4 |
| 112 | #define PM_GPIO_PULL_NO 5 |
| 113 | |
| 114 | /* vin_sel: Voltage Input Select */ |
| 115 | #define PM_GPIO_VIN_VPH 0 |
| 116 | #define PM_GPIO_VIN_BB 1 |
| 117 | #define PM_GPIO_VIN_S3 2 |
| 118 | #define PM_GPIO_VIN_L3 3 |
| 119 | #define PM_GPIO_VIN_L7 4 |
| 120 | #define PM_GPIO_VIN_L6 5 |
| 121 | #define PM_GPIO_VIN_L5 6 |
| 122 | #define PM_GPIO_VIN_L2 7 |
| 123 | |
| 124 | /* out_strength */ |
| 125 | #define PM_GPIO_STRENGTH_NO 0 |
| 126 | #define PM_GPIO_STRENGTH_HIGH 1 |
| 127 | #define PM_GPIO_STRENGTH_MED 2 |
| 128 | #define PM_GPIO_STRENGTH_LOW 3 |
| 129 | |
| 130 | /* function */ |
| 131 | #define PM_GPIO_FUNC_NORMAL 0 |
| 132 | #define PM_GPIO_FUNC_PAIRED 1 |
| 133 | #define PM_GPIO_FUNC_1 2 |
| 134 | #define PM_GPIO_FUNC_2 3 |
| 135 | #define PM_GPIO_DTEST1 4 |
| 136 | #define PM_GPIO_DTEST2 5 |
| 137 | #define PM_GPIO_DTEST3 6 |
| 138 | #define PM_GPIO_DTEST4 7 |
| 139 | |
| 140 | struct pm8058_gpio { |
| 141 | int direction; |
| 142 | int output_buffer; |
| 143 | int output_value; |
| 144 | int pull; |
| 145 | int vin_sel; /* 0..7 */ |
| 146 | int out_strength; |
| 147 | int function; |
| 148 | int inv_int_pol; /* invert interrupt polarity */ |
| 149 | int disable_pin; /* disable pin and tri-state its pad */ |
| 150 | }; |
| 151 | |
| 152 | /* chip revision */ |
| 153 | #define PM_8058_REV_1p0 0xE1 |
| 154 | #define PM_8058_REV_2p0 0xE2 |
| 155 | #define PM_8058_REV_2p1 0xE3 |
| 156 | |
| 157 | /* misc: control mask and flag */ |
| 158 | #define PM8058_UART_MUX_MASK 0x60 |
| 159 | |
| 160 | #define PM8058_UART_MUX_NO 0x0 |
| 161 | #define PM8058_UART_MUX_1 0x20 |
| 162 | #define PM8058_UART_MUX_2 0x40 |
| 163 | #define PM8058_UART_MUX_3 0x60 |
| 164 | |
| 165 | enum pon_config{ |
| 166 | DISABLE_HARD_RESET = 0, |
| 167 | SHUTDOWN_ON_HARD_RESET, |
| 168 | RESTART_ON_HARD_RESET, |
| 169 | MAX_PON_CONFIG, |
| 170 | }; |
| 171 | |
| 172 | enum pm8058_smpl_delay { |
| 173 | PM8058_SMPL_DELAY_0p5, |
| 174 | PM8058_SMPL_DELAY_1p0, |
| 175 | PM8058_SMPL_DELAY_1p5, |
| 176 | PM8058_SMPL_DELAY_2p0, |
| 177 | }; |
| 178 | |
| 179 | /* Note -do not call pm8058_read and pm8058_write in an atomic context */ |
| 180 | int pm8058_read(struct pm8058_chip *pm_chip, u16 addr, u8 *values, |
| 181 | unsigned int len); |
| 182 | int pm8058_write(struct pm8058_chip *pm_chip, u16 addr, u8 *values, |
| 183 | unsigned int len); |
| 184 | |
| 185 | int pm8058_gpio_config(int gpio, struct pm8058_gpio *param); |
| 186 | |
| 187 | int pm8058_rev(struct pm8058_chip *pm_chip); |
| 188 | |
| 189 | int pm8058_irq_get_rt_status(struct pm8058_chip *pm_chip, int irq); |
| 190 | |
| 191 | int pm8058_misc_control(struct pm8058_chip *pm_chip, int mask, int flag); |
| 192 | |
| 193 | #ifdef CONFIG_PMIC8058 |
| 194 | int pm8058_reset_pwr_off(int reset); |
| 195 | #else |
| 196 | static inline int pm8058_reset_pwr_off(int reset) { return 0; } |
| 197 | #endif |
| 198 | |
| 199 | |
| 200 | int pm8058_hard_reset_config(enum pon_config config); |
| 201 | |
| 202 | /** |
| 203 | * pm8058_smpl_control - enables/disables SMPL detection |
| 204 | * @enable: 0 = shutdown PMIC on power loss, 1 = reset PMIC on power loss |
| 205 | * |
| 206 | * This function enables or disables the Sudden Momentary Power Loss detection |
| 207 | * module. If SMPL detection is enabled, then when a sufficiently long power |
| 208 | * loss event occurs, the PMIC will automatically reset itself. If SMPL |
| 209 | * detection is disabled, then the PMIC will shutdown when power loss occurs. |
| 210 | * |
| 211 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 212 | */ |
| 213 | int pm8058_smpl_control(int enable); |
| 214 | |
| 215 | /** |
| 216 | * pm8058_smpl_set_delay - sets the SMPL detection time delay |
| 217 | * @delay: enum value corresponding to delay time |
| 218 | * |
| 219 | * This function sets the time delay of the SMPL detection module. If power |
| 220 | * is reapplied within this interval, then the PMIC reset automatically. The |
| 221 | * SMPL detection module must be enabled for this delay time to take effect. |
| 222 | * |
| 223 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 224 | */ |
| 225 | int pm8058_smpl_set_delay(enum pm8058_smpl_delay delay); |
| 226 | |
| 227 | /** |
| 228 | * pm8058_watchdog_reset_control - enables/disables watchdog reset detection |
| 229 | * @enable: 0 = shutdown when PS_HOLD goes low, 1 = reset when PS_HOLD goes low |
| 230 | * |
| 231 | * This function enables or disables the PMIC watchdog reset detection feature. |
| 232 | * If watchdog reset detection is enabled, then the PMIC will reset itself |
| 233 | * when PS_HOLD goes low. If it is not enabled, then the PMIC will shutdown |
| 234 | * when PS_HOLD goes low. |
| 235 | * |
| 236 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 237 | */ |
| 238 | int pm8058_watchdog_reset_control(int enable); |