Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2009 ST-Ericsson AB |
| 3 | * License terms: GNU General Public License (GPL) version 2 |
| 4 | * AB3100 core access functions |
| 5 | * Author: Linus Walleij <linus.walleij@stericsson.com> |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 6 | * |
| 7 | * ABX500 core access functions. |
| 8 | * The abx500 interface is used for the Analog Baseband chip |
Linus Walleij | 8959e74 | 2011-09-26 11:45:30 +0200 | [diff] [blame] | 9 | * ab3100, ab5500, and ab8500. |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 10 | * |
| 11 | * Author: Mattias Wallin <mattias.wallin@stericsson.com> |
| 12 | * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> |
| 13 | * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com> |
| 14 | * Author: Rickard Andersson <rickard.andersson@stericsson.com> |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
Linus Walleij | d619bc1 | 2009-09-09 11:31:00 +0200 | [diff] [blame] | 17 | #include <linux/regulator/machine.h> |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 18 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 19 | struct device; |
| 20 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 21 | #ifndef MFD_ABX500_H |
| 22 | #define MFD_ABX500_H |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 23 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 24 | #define AB3100_P1A 0xc0 |
| 25 | #define AB3100_P1B 0xc1 |
| 26 | #define AB3100_P1C 0xc2 |
| 27 | #define AB3100_P1D 0xc3 |
| 28 | #define AB3100_P1E 0xc4 |
| 29 | #define AB3100_P1F 0xc5 |
| 30 | #define AB3100_P1G 0xc6 |
| 31 | #define AB3100_R2A 0xc7 |
| 32 | #define AB3100_R2B 0xc8 |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 33 | #define AB5500_1_0 0x20 |
Mattias Wallin | 3d5e2ca | 2011-09-22 08:22:18 +0200 | [diff] [blame] | 34 | #define AB5500_1_1 0x21 |
| 35 | #define AB5500_2_0 0x24 |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * AB3100, EVENTA1, A2 and A3 event register flags |
| 39 | * these are catenated into a single 32-bit flag in the code |
| 40 | * for event notification broadcasts. |
| 41 | */ |
| 42 | #define AB3100_EVENTA1_ONSWA (0x01<<16) |
| 43 | #define AB3100_EVENTA1_ONSWB (0x02<<16) |
| 44 | #define AB3100_EVENTA1_ONSWC (0x04<<16) |
| 45 | #define AB3100_EVENTA1_DCIO (0x08<<16) |
| 46 | #define AB3100_EVENTA1_OVER_TEMP (0x10<<16) |
| 47 | #define AB3100_EVENTA1_SIM_OFF (0x20<<16) |
| 48 | #define AB3100_EVENTA1_VBUS (0x40<<16) |
| 49 | #define AB3100_EVENTA1_VSET_USB (0x80<<16) |
| 50 | |
| 51 | #define AB3100_EVENTA2_READY_TX (0x01<<8) |
| 52 | #define AB3100_EVENTA2_READY_RX (0x02<<8) |
| 53 | #define AB3100_EVENTA2_OVERRUN_ERROR (0x04<<8) |
| 54 | #define AB3100_EVENTA2_FRAMING_ERROR (0x08<<8) |
| 55 | #define AB3100_EVENTA2_CHARG_OVERCURRENT (0x10<<8) |
| 56 | #define AB3100_EVENTA2_MIDR (0x20<<8) |
| 57 | #define AB3100_EVENTA2_BATTERY_REM (0x40<<8) |
| 58 | #define AB3100_EVENTA2_ALARM (0x80<<8) |
| 59 | |
| 60 | #define AB3100_EVENTA3_ADC_TRIG5 (0x01) |
| 61 | #define AB3100_EVENTA3_ADC_TRIG4 (0x02) |
| 62 | #define AB3100_EVENTA3_ADC_TRIG3 (0x04) |
| 63 | #define AB3100_EVENTA3_ADC_TRIG2 (0x08) |
| 64 | #define AB3100_EVENTA3_ADC_TRIGVBAT (0x10) |
| 65 | #define AB3100_EVENTA3_ADC_TRIGVTX (0x20) |
| 66 | #define AB3100_EVENTA3_ADC_TRIG1 (0x40) |
| 67 | #define AB3100_EVENTA3_ADC_TRIG0 (0x80) |
| 68 | |
| 69 | /* AB3100, STR register flags */ |
| 70 | #define AB3100_STR_ONSWA (0x01) |
| 71 | #define AB3100_STR_ONSWB (0x02) |
| 72 | #define AB3100_STR_ONSWC (0x04) |
| 73 | #define AB3100_STR_DCIO (0x08) |
| 74 | #define AB3100_STR_BOOT_MODE (0x10) |
| 75 | #define AB3100_STR_SIM_OFF (0x20) |
| 76 | #define AB3100_STR_BATT_REMOVAL (0x40) |
| 77 | #define AB3100_STR_VBUS (0x80) |
| 78 | |
Linus Walleij | d619bc1 | 2009-09-09 11:31:00 +0200 | [diff] [blame] | 79 | /* |
| 80 | * AB3100 contains 8 regulators, one external regulator controller |
| 81 | * and a buck converter, further the LDO E and buck converter can |
| 82 | * have separate settings if they are in sleep mode, this is |
| 83 | * modeled as a separate regulator. |
| 84 | */ |
| 85 | #define AB3100_NUM_REGULATORS 10 |
| 86 | |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 87 | /** |
| 88 | * struct ab3100 |
| 89 | * @access_mutex: lock out concurrent accesses to the AB3100 registers |
| 90 | * @dev: pointer to the containing device |
| 91 | * @i2c_client: I2C client for this chip |
| 92 | * @testreg_client: secondary client for test registers |
| 93 | * @chip_name: name of this chip variant |
| 94 | * @chip_id: 8 bit chip ID for this chip variant |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 95 | * @event_subscribers: event subscribers are listed here |
| 96 | * @startup_events: a copy of the first reading of the event registers |
| 97 | * @startup_events_read: whether the first events have been read |
| 98 | * |
| 99 | * This struct is PRIVATE and devices using it should NOT |
| 100 | * access ANY fields. It is used as a token for calling the |
| 101 | * AB3100 functions. |
| 102 | */ |
| 103 | struct ab3100 { |
| 104 | struct mutex access_mutex; |
| 105 | struct device *dev; |
| 106 | struct i2c_client *i2c_client; |
| 107 | struct i2c_client *testreg_client; |
| 108 | char chip_name[32]; |
| 109 | u8 chip_id; |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 110 | struct blocking_notifier_head event_subscribers; |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 111 | u8 startup_events[3]; |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 112 | bool startup_events_read; |
| 113 | }; |
| 114 | |
Linus Walleij | d619bc1 | 2009-09-09 11:31:00 +0200 | [diff] [blame] | 115 | /** |
| 116 | * struct ab3100_platform_data |
| 117 | * Data supplied to initialize board connections to the AB3100 |
| 118 | * @reg_constraints: regulator constraints for target board |
| 119 | * the order of these constraints are: LDO A, C, D, E, |
| 120 | * F, G, H, K, EXT and BUCK. |
| 121 | * @reg_initvals: initial values for the regulator registers |
| 122 | * plus two sleep settings for LDO E and the BUCK converter. |
| 123 | * exactly AB3100_NUM_REGULATORS+2 values must be sent in. |
| 124 | * Order: LDO A, C, E, E sleep, F, G, H, K, EXT, BUCK, |
| 125 | * BUCK sleep, LDO D. (LDO D need to be initialized last.) |
| 126 | * @external_voltage: voltage level of the external regulator. |
| 127 | */ |
| 128 | struct ab3100_platform_data { |
| 129 | struct regulator_init_data reg_constraints[AB3100_NUM_REGULATORS]; |
| 130 | u8 reg_initvals[AB3100_NUM_REGULATORS+2]; |
| 131 | int external_voltage; |
| 132 | }; |
| 133 | |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 134 | int ab3100_event_register(struct ab3100 *ab3100, |
| 135 | struct notifier_block *nb); |
| 136 | int ab3100_event_unregister(struct ab3100 *ab3100, |
| 137 | struct notifier_block *nb); |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 138 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 139 | /** |
| 140 | * struct abx500_init_setting |
| 141 | * Initial value of the registers for driver to use during setup. |
| 142 | */ |
| 143 | struct abx500_init_settings { |
| 144 | u8 bank; |
| 145 | u8 reg; |
| 146 | u8 setting; |
| 147 | }; |
| 148 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 149 | int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg, |
| 150 | u8 value); |
| 151 | int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg, |
| 152 | u8 *value); |
| 153 | int abx500_get_register_page_interruptible(struct device *dev, u8 bank, |
| 154 | u8 first_reg, u8 *regvals, u8 numregs); |
| 155 | int abx500_set_register_page_interruptible(struct device *dev, u8 bank, |
| 156 | u8 first_reg, u8 *regvals, u8 numregs); |
| 157 | /** |
| 158 | * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a |
| 159 | * target register |
| 160 | * |
| 161 | * @dev: The AB sub device. |
| 162 | * @bank: The i2c bank number. |
| 163 | * @bitmask: The bit mask to use. |
| 164 | * @bitvalues: The new bit values. |
| 165 | * |
| 166 | * Updates the value of an AB register: |
| 167 | * value -> ((value & ~bitmask) | (bitvalues & bitmask)) |
| 168 | */ |
| 169 | int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank, |
| 170 | u8 reg, u8 bitmask, u8 bitvalues); |
| 171 | int abx500_get_chip_id(struct device *dev); |
| 172 | int abx500_event_registers_startup_state_get(struct device *dev, u8 *event); |
| 173 | int abx500_startup_irq_enabled(struct device *dev, unsigned int irq); |
| 174 | |
| 175 | struct abx500_ops { |
| 176 | int (*get_chip_id) (struct device *); |
| 177 | int (*get_register) (struct device *, u8, u8, u8 *); |
| 178 | int (*set_register) (struct device *, u8, u8, u8); |
| 179 | int (*get_register_page) (struct device *, u8, u8, u8 *, u8); |
| 180 | int (*set_register_page) (struct device *, u8, u8, u8 *, u8); |
| 181 | int (*mask_and_set_register) (struct device *, u8, u8, u8, u8); |
| 182 | int (*event_registers_startup_state_get) (struct device *, u8 *); |
| 183 | int (*startup_irq_enabled) (struct device *, unsigned int); |
| 184 | }; |
| 185 | |
| 186 | int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops); |
Mark Brown | c6252e9 | 2010-09-22 14:58:30 +0100 | [diff] [blame] | 187 | void abx500_remove_ops(struct device *dev); |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 188 | #endif |