Venu Byravarasu | 3c33be06 | 2012-03-16 11:10:19 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Core driver interface for TI TPS65090 PMIC family |
| 3 | * |
| 4 | * Copyright (C) 2012 NVIDIA Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #ifndef __LINUX_MFD_TPS65090_H |
| 23 | #define __LINUX_MFD_TPS65090_H |
| 24 | |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 25 | #include <linux/irq.h> |
Laxman Dewangan | b9c7932 | 2012-11-20 08:44:48 +0530 | [diff] [blame] | 26 | #include <linux/regmap.h> |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 27 | |
Laxman Dewangan | 759f259 | 2012-11-20 08:44:49 +0530 | [diff] [blame] | 28 | /* TPS65090 IRQs */ |
| 29 | enum { |
Rhyland Klein | 751391c | 2013-03-12 18:08:06 -0400 | [diff] [blame] | 30 | TPS65090_IRQ_INTERRUPT, |
Laxman Dewangan | 759f259 | 2012-11-20 08:44:49 +0530 | [diff] [blame] | 31 | TPS65090_IRQ_VAC_STATUS_CHANGE, |
| 32 | TPS65090_IRQ_VSYS_STATUS_CHANGE, |
| 33 | TPS65090_IRQ_BAT_STATUS_CHANGE, |
| 34 | TPS65090_IRQ_CHARGING_STATUS_CHANGE, |
| 35 | TPS65090_IRQ_CHARGING_COMPLETE, |
| 36 | TPS65090_IRQ_OVERLOAD_DCDC1, |
| 37 | TPS65090_IRQ_OVERLOAD_DCDC2, |
| 38 | TPS65090_IRQ_OVERLOAD_DCDC3, |
| 39 | TPS65090_IRQ_OVERLOAD_FET1, |
| 40 | TPS65090_IRQ_OVERLOAD_FET2, |
| 41 | TPS65090_IRQ_OVERLOAD_FET3, |
| 42 | TPS65090_IRQ_OVERLOAD_FET4, |
| 43 | TPS65090_IRQ_OVERLOAD_FET5, |
| 44 | TPS65090_IRQ_OVERLOAD_FET6, |
| 45 | TPS65090_IRQ_OVERLOAD_FET7, |
| 46 | }; |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 47 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 48 | /* TPS65090 Regulator ID */ |
| 49 | enum { |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 50 | TPS65090_REGULATOR_DCDC1, |
| 51 | TPS65090_REGULATOR_DCDC2, |
| 52 | TPS65090_REGULATOR_DCDC3, |
| 53 | TPS65090_REGULATOR_FET1, |
| 54 | TPS65090_REGULATOR_FET2, |
| 55 | TPS65090_REGULATOR_FET3, |
| 56 | TPS65090_REGULATOR_FET4, |
| 57 | TPS65090_REGULATOR_FET5, |
| 58 | TPS65090_REGULATOR_FET6, |
| 59 | TPS65090_REGULATOR_FET7, |
Laxman Dewangan | 3a81ef8 | 2012-10-09 15:19:01 +0530 | [diff] [blame] | 60 | TPS65090_REGULATOR_LDO1, |
| 61 | TPS65090_REGULATOR_LDO2, |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 62 | |
| 63 | /* Last entry for maximum ID */ |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 64 | TPS65090_REGULATOR_MAX, |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 65 | }; |
| 66 | |
Doug Anderson | c42ba72 | 2014-04-16 16:12:27 -0700 | [diff] [blame] | 67 | /* Register addresses */ |
| 68 | #define TPS65090_REG_INTR_STS 0x00 |
| 69 | #define TPS65090_REG_INTR_STS2 0x01 |
| 70 | #define TPS65090_REG_INTR_MASK 0x02 |
| 71 | #define TPS65090_REG_INTR_MASK2 0x03 |
| 72 | #define TPS65090_REG_CG_CTRL0 0x04 |
| 73 | #define TPS65090_REG_CG_CTRL1 0x05 |
| 74 | #define TPS65090_REG_CG_CTRL2 0x06 |
| 75 | #define TPS65090_REG_CG_CTRL3 0x07 |
| 76 | #define TPS65090_REG_CG_CTRL4 0x08 |
| 77 | #define TPS65090_REG_CG_CTRL5 0x09 |
| 78 | #define TPS65090_REG_CG_STATUS1 0x0a |
| 79 | #define TPS65090_REG_CG_STATUS2 0x0b |
Maciej S. Szmigiero | 5c14889 | 2016-01-31 23:00:06 +0100 | [diff] [blame] | 80 | #define TPS65090_REG_AD_OUT1 0x17 |
| 81 | #define TPS65090_REG_AD_OUT2 0x18 |
| 82 | |
| 83 | #define TPS65090_MAX_REG TPS65090_REG_AD_OUT2 |
| 84 | #define TPS65090_NUM_REGS (TPS65090_MAX_REG + 1) |
Doug Anderson | c42ba72 | 2014-04-16 16:12:27 -0700 | [diff] [blame] | 85 | |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 86 | struct tps65090 { |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 87 | struct device *dev; |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 88 | struct regmap *rmap; |
Laxman Dewangan | 759f259 | 2012-11-20 08:44:49 +0530 | [diff] [blame] | 89 | struct regmap_irq_chip_data *irq_data; |
Venu Byravarasu | 3c33be06 | 2012-03-16 11:10:19 +0530 | [diff] [blame] | 90 | }; |
| 91 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 92 | /* |
| 93 | * struct tps65090_regulator_plat_data |
| 94 | * |
| 95 | * @reg_init_data: The regulator init data. |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 96 | * @enable_ext_control: Enable extrenal control or not. Only available for |
| 97 | * DCDC1, DCDC2 and DCDC3. |
| 98 | * @gpio: Gpio number if external control is enabled and controlled through |
| 99 | * gpio. |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame] | 100 | * @overcurrent_wait_valid: True if the overcurrent_wait should be applied. |
| 101 | * @overcurrent_wait: Value to set as the overcurrent wait time. This is the |
| 102 | * actual bitfield value, not a time in ms (valid value are 0 - 3). |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 103 | */ |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 104 | struct tps65090_regulator_plat_data { |
| 105 | struct regulator_init_data *reg_init_data; |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 106 | bool enable_ext_control; |
| 107 | int gpio; |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame] | 108 | bool overcurrent_wait_valid; |
| 109 | int overcurrent_wait; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 110 | }; |
| 111 | |
Venu Byravarasu | 3c33be06 | 2012-03-16 11:10:19 +0530 | [diff] [blame] | 112 | struct tps65090_platform_data { |
| 113 | int irq_base; |
Rhyland Klein | 6f8da5d | 2013-03-12 18:08:09 -0400 | [diff] [blame] | 114 | |
| 115 | char **supplied_to; |
| 116 | size_t num_supplicants; |
| 117 | int enable_low_current_chrg; |
| 118 | |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 119 | struct tps65090_regulator_plat_data *reg_pdata[TPS65090_REGULATOR_MAX]; |
Venu Byravarasu | 3c33be06 | 2012-03-16 11:10:19 +0530 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* |
| 123 | * NOTE: the functions below are not intended for use outside |
| 124 | * of the TPS65090 sub-device drivers |
| 125 | */ |
Laxman Dewangan | b9c7932 | 2012-11-20 08:44:48 +0530 | [diff] [blame] | 126 | static inline int tps65090_write(struct device *dev, int reg, uint8_t val) |
| 127 | { |
| 128 | struct tps65090 *tps = dev_get_drvdata(dev); |
| 129 | |
| 130 | return regmap_write(tps->rmap, reg, val); |
| 131 | } |
| 132 | |
| 133 | static inline int tps65090_read(struct device *dev, int reg, uint8_t *val) |
| 134 | { |
| 135 | struct tps65090 *tps = dev_get_drvdata(dev); |
| 136 | unsigned int temp_val; |
| 137 | int ret; |
| 138 | |
| 139 | ret = regmap_read(tps->rmap, reg, &temp_val); |
| 140 | if (!ret) |
| 141 | *val = temp_val; |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | static inline int tps65090_set_bits(struct device *dev, int reg, |
| 146 | uint8_t bit_num) |
| 147 | { |
| 148 | struct tps65090 *tps = dev_get_drvdata(dev); |
| 149 | |
| 150 | return regmap_update_bits(tps->rmap, reg, BIT(bit_num), ~0u); |
| 151 | } |
| 152 | |
| 153 | static inline int tps65090_clr_bits(struct device *dev, int reg, |
| 154 | uint8_t bit_num) |
| 155 | { |
| 156 | struct tps65090 *tps = dev_get_drvdata(dev); |
| 157 | |
| 158 | return regmap_update_bits(tps->rmap, reg, BIT(bit_num), 0u); |
| 159 | } |
Venu Byravarasu | 3c33be06 | 2012-03-16 11:10:19 +0530 | [diff] [blame] | 160 | |
| 161 | #endif /*__LINUX_MFD_TPS65090_H */ |