1 /*- 2 * Copyright (c) 2016 Emmanuel Vadot <manu@freeebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 * $FreeBSD$ 26 */ 27 28 #ifndef _AXP209REG_H_ 29 #define _AXP209REG_H_ 30 31 /* Power State Register */ 32 #define AXP209_PSR 0x00 33 #define AXP209_PSR_ACIN 0x80 34 #define AXP209_PSR_ACIN_SHIFT 7 35 #define AXP209_PSR_VBUS 0x20 36 #define AXP209_PSR_VBUS_SHIFT 5 37 38 /* Shutdown and battery control */ 39 #define AXP209_SHUTBAT 0x32 40 #define AXP209_SHUTBAT_SHUTDOWN 0x80 41 42 /* Voltage/Current Monitor */ 43 #define AXP209_ACIN_VOLTAGE 0x56 44 #define AXP209_ACIN_CURRENT 0x58 45 #define AXP209_VBUS_VOLTAGE 0x5A 46 #define AXP209_VBUS_CURRENT 0x5C 47 #define AXP209_BAT_VOLTAGE 0x78 48 #define AXP209_BAT_CHARGE_CURRENT 0x7A 49 #define AXP209_BAT_DISCHARGE_CURRENT 0x7C 50 51 #define AXP209_VOLT_STEP 1700 52 #define AXP209_BATVOLT_STEP 1100 53 #define AXP209_ACCURRENT_STEP 625 54 #define AXP209_VBUSCURRENT_STEP 375 55 #define AXP209_BATCURRENT_STEP 500 56 57 /* Temperature monitor */ 58 #define AXP209_TEMPMON 0x5e 59 #define AXP209_TEMPMON_MIN 1447 /* -144.7C */ 60 61 /* Sensors conversion macros */ 62 #define AXP209_SENSOR_H(a) ((a) << 4) 63 #define AXP209_SENSOR_L(a) ((a) & 0xf) 64 #define AXP209_SENSOR_BAT_H(a) ((a) << 5) 65 #define AXP209_SENSOR_BAT_L(a) ((a) & 0x1f) 66 67 #define AXP209_0C_TO_K 2732 68 69 /* ADC Sensors */ 70 #define AXP209_ADC_ENABLE1 0x82 71 #define AXP209_ADC_ENABLE2 0x83 72 73 #define AXP209_ADC1_BATVOLT (1 << 7) 74 #define AXP209_ADC1_BATCURRENT (1 << 6) 75 #define AXP209_ADC1_ACVOLT (1 << 5) 76 #define AXP209_ADC1_ACCURRENT (1 << 4) 77 #define AXP209_ADC1_VBUSVOLT (1 << 3) 78 #define AXP209_ADC1_VBUSCURRENT (1 << 2) 79 80 /* Interrupt related registers */ 81 #define AXP209_IRQ1_ENABLE 0x40 82 #define AXP209_IRQ1_STATUS 0x48 83 #define AXP209_IRQ1_AC_OVERVOLT (1 << 7) 84 #define AXP209_IRQ1_AC_CONN (1 << 6) 85 #define AXP209_IRQ1_AC_DISCONN (1 << 5) 86 #define AXP209_IRQ1_VBUS_OVERVOLT (1 << 4) 87 #define AXP209_IRQ1_VBUS_CONN (1 << 3) 88 #define AXP209_IRQ1_VBUS_DISCONN (1 << 2) 89 #define AXP209_IRQ1_VBUS_LOW (1 << 1) 90 91 #define AXP209_IRQ2_ENABLE 0x41 92 #define AXP209_IRQ2_STATUS 0x49 93 #define AXP209_IRQ2_BATT_CONN (1 << 7) 94 #define AXP209_IRQ2_BATT_DISCONN (1 << 6) 95 #define AXP209_IRQ2_BATT_CHARGE_ACCT_ON (1 << 5) 96 #define AXP209_IRQ2_BATT_CHARGE_ACCT_OFF (1 << 4) 97 #define AXP209_IRQ2_BATT_CHARGING (1 << 3) 98 #define AXP209_IRQ2_BATT_CHARGED (1 << 2) 99 #define AXP209_IRQ2_BATT_TEMP_OVER (1 << 1) 100 #define AXP209_IRQ2_BATT_TEMP_LOW (1 << 0) 101 102 #define AXP209_IRQ3_ENABLE 0x42 103 #define AXP209_IRQ3_STATUS 0x4A 104 #define AXP209_IRQ3_TEMP_OVER (1 << 7) 105 #define AXP209_IRQ3_CHARGE_CURRENT_LOW (1 << 6) 106 #define AXP209_IRQ3_DCDC2_LOW (1 << 4) 107 #define AXP209_IRQ3_DCDC3_LOW (1 << 3) 108 #define AXP209_IRQ3_LDO3_LOW (1 << 2) 109 #define AXP209_IRQ3_PEK_SHORT (1 << 1) 110 #define AXP209_IRQ3_PEK_LONG (1 << 0) 111 112 #define AXP209_IRQ4_ENABLE 0x43 113 #define AXP209_IRQ4_STATUS 0x4B 114 #define AXP209_IRQ4_NOE_START (1 << 7) 115 #define AXP209_IRQ4_NOE_SHUT (1 << 6) 116 #define AXP209_IRQ4_VBUS_VALID (1 << 5) 117 #define AXP209_IRQ4_VBUS_INVALID (1 << 4) 118 #define AXP209_IRQ4_VBUS_SESSION (1 << 3) 119 #define AXP209_IRQ4_VBUS_SESSION_END (1 << 2) 120 #define AXP209_IRQ4_APS_LOW_1 (1 << 1) 121 #define AXP209_IRQ4_APS_LOW_2 (1 << 0) 122 123 #define AXP209_IRQ5_ENABLE 0x44 124 #define AXP209_IRQ5_STATUS 0x4C 125 #define AXP209_IRQ5_TIMER_EXPIRE (1 << 7) 126 #define AXP209_IRQ5_PEK_RISE_EDGE (1 << 6) 127 #define AXP209_IRQ5_PEK_FALL_EDGE (1 << 5) 128 #define AXP209_IRQ5_GPIO3 (1 << 3) 129 #define AXP209_IRQ5_GPIO2 (1 << 2) 130 #define AXP209_IRQ5_GPIO1 (1 << 1) 131 #define AXP209_IRQ5_GPIO0 (1 << 0) 132 133 #define AXP209_IRQ_ACK 0xff 134 135 /* GPIOs registers */ 136 #define AXP209_GPIO_FUNC_MASK 0x7 137 138 #define AXP209_GPIO_FUNC_DRVLO 0x0 139 #define AXP209_GPIO_FUNC_DRVHI 0x1 140 #define AXP209_GPIO_FUNC_INPUT 0x2 141 142 #define AXP209_GPIO0_CTRL 0x90 143 #define AXP209_GPIO1_CTRL 0x92 144 #define AXP209_GPIO2_CTRL 0x93 145 #define AXP209_GPIO_STATUS 0x94 146 147 #define AXP209_GPIO_DATA(x) (1 << (x + 4)) 148 149 /* Regulators registers */ 150 #define AXP209_POWERCTL 0x12 151 #define AXP209_POWERCTL_DCDC3 (1 << 1) 152 #define AXP209_POWERCTL_LDO2 (1 << 2) 153 #define AXP209_POWERCTL_LDO4 (1 << 3) 154 #define AXP209_POWERCTL_DCDC2 (1 << 4) 155 #define AXP209_POWERCTL_LDO3 (1 << 6) 156 157 #define AXP209_REG_DCDC2_VOLTAGE 0x23 158 #define AXP209_REG_DCDC3_VOLTAGE 0x27 159 #define AXP209_REG_LDO24_VOLTAGE 0x28 160 #define AXP209_REG_LDO3_VOLTAGE 0x29 161 162 enum axp209_sensor { 163 AXP209_TEMP, 164 AXP209_ACVOLT, 165 AXP209_ACCURRENT, 166 AXP209_VBUSVOLT, 167 AXP209_VBUSCURRENT, 168 AXP209_BATVOLT, 169 AXP209_BATCHARGECURRENT, 170 AXP209_BATDISCHARGECURRENT, 171 }; 172 173 enum axp209_regulators { 174 AXP209_REG_ID_DCDC2, 175 AXP209_REG_ID_DCDC3, 176 AXP209_REG_ID_LDO1, 177 AXP209_REG_ID_LDO2, 178 AXP209_REG_ID_LDO3, 179 /* LDO4 is weird, need to find a correct way to handle it */ 180 /* AXP209_REG_ID_LDO4, */ 181 AXP209_REG_ID_LDO5, 182 }; 183 184 #endif /* _AXP209REG_H_ */ 185