blob: 14f693ba835117eea9b5022e7f350726f162e407 [file] [log] [blame]
Umang Agrawalfa38b2e2018-02-19 15:32:46 +05301/* Copyright (c) 2012-2015, 2017-2018, The Linux Foundation. All rights reserved.
Deepa Dinamani22799652012-07-21 12:26:22 -07002
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
Parth Dixitc2e6dfe2015-06-19 15:57:47 +053012 * * Neither the name of The Linux Foundation, nor the names of its
Deepa Dinamani22799652012-07-21 12:26:22 -070013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef _PM8x41_HW_H_
30#define _PM8x41_HW_H_
31
Channagoud Kadabi56a6b522015-04-24 17:23:27 -070032#include <stdint.h>
33#include <sys/types.h>
34
35
Deepa Dinamani9a612932012-08-14 16:15:03 -070036/* SMBB Registers */
37#define SMBB_MISC_BOOT_DONE 0x1642
Deepa Dinamani22799652012-07-21 12:26:22 -070038
Deepa Dinamani9a612932012-08-14 16:15:03 -070039/* SMBB bit values */
40#define BOOT_DONE_BIT 7
41
Deepa Dinamani7564f2a2013-02-05 17:55:51 -080042#define REVID_REVISION4 0x103
Parth Dixit1a963d72015-10-20 01:08:57 +053043#define REVID_REV_ID_SPARE_0 0x160
Deepa Dinamani9a612932012-08-14 16:15:03 -070044
Kuogee Hsieh11835112013-10-04 15:50:36 -070045/* LPG Registers */
46#define LPG_SLAVE_ID 0x10000 /* slave_id == 1 */
47#define LPG_PERIPHERAL_BASE (0x0B100 | LPG_SLAVE_ID)
48/* Peripheral base address for LPG channel */
49#define LPG_N_PERIPHERAL_BASE(x) (LPG_PERIPHERAL_BASE + ((x) - 1) * 0x100)
50
Deepa Dinamani9a612932012-08-14 16:15:03 -070051/* GPIO Registers */
52#define GPIO_PERIPHERAL_BASE 0xC000
53/* Peripheral base address for GPIO_X */
54#define GPIO_N_PERIPHERAL_BASE(x) (GPIO_PERIPHERAL_BASE + ((x) - 1) * 0x100)
55
56/* Register offsets within GPIO */
57#define GPIO_STATUS 0x08
58#define GPIO_MODE_CTL 0x40
59#define GPIO_DIG_VIN_CTL 0x41
60#define GPIO_DIG_PULL_CTL 0x42
Ashish Garg44992472017-08-07 14:36:59 +053061#define GPIO_DIG_OUT_SRC_CTL 0x44
Deepa Dinamani9a612932012-08-14 16:15:03 -070062#define GPIO_DIG_OUT_CTL 0x45
63#define GPIO_EN_CTL 0x46
64
65/* GPIO bit values */
66#define PERPH_EN_BIT 7
67#define GPIO_STATUS_VAL_BIT 0
68
69
70/* PON Peripheral registers */
sundarajan srinivasand0f59e82013-02-12 19:17:02 -080071#define PON_PON_REASON1 0x808
Mayank Grover8bf68ac2017-12-05 10:27:36 +053072#define PM660_PON_REASON1 0x8C0
73#define PM660_PON_WARMBOOT_STATUS1 0x8C2
Umang Agrawale82646d2019-05-23 16:25:45 +053074#define PM660_PON_POFF_REASON1 0x8C5
75#define PM660_PON_POFF_REASON2 0x8C7
Ameya Thakurb0a62ab2013-06-25 13:43:10 -070076#define PON_WARMBOOT_STATUS1 0x80A
77#define PON_WARMBOOT_STATUS2 0x80B
Matthew Qin5e90d832014-07-11 11:15:22 +080078#define PON_POFF_REASON1 0x80C
79#define PON_POFF_REASON2 0x80D
Deepa Dinamani9a612932012-08-14 16:15:03 -070080#define PON_INT_RT_STS 0x810
81#define PON_INT_SET_TYPE 0x811
82#define PON_INT_POLARITY_HIGH 0x812
83#define PON_INT_POLARITY_LOW 0x813
84#define PON_INT_LATCHED_CLR 0x814
85#define PON_INT_EN_SET 0x815
86#define PON_INT_LATCHED_STS 0x818
87#define PON_INT_PENDING_STS 0x819
88#define PON_RESIN_N_RESET_S1_TIMER 0x844 /* bits 0:3 : S1_TIMER */
89#define PON_RESIN_N_RESET_S2_TIMER 0x845 /* bits 0:2 : S2_TIMER */
90#define PON_RESIN_N_RESET_S2_CTL 0x846 /* bit 7: S2_RESET_EN, bit 0:3 : RESET_TYPE */
Neeti Desai120b55d2012-08-20 17:15:56 -070091#define PON_PS_HOLD_RESET_CTL 0x85A /* bit 7: S2_RESET_EN, bit 0:3 : RESET_TYPE */
Deepa Dinamani3c9865d2013-03-08 14:03:19 -080092#define PON_PS_HOLD_RESET_CTL2 0x85B
Xiaocheng Li73c57122013-09-14 17:32:00 +080093#define PMIC_WD_RESET_S2_CTL2 0x857
Deepa Dinamani9a612932012-08-14 16:15:03 -070094
95/* PON Peripheral register bit values */
Deepa Dinamanic7f87582013-02-01 15:24:49 -080096#define RESIN_ON_INT_BIT 1
Matthew Qin3aa87052014-02-21 10:32:34 +080097#define KPDPWR_ON_INT_BIT 0
Deepa Dinamani9a612932012-08-14 16:15:03 -070098#define RESIN_BARK_INT_BIT 4
99#define S2_RESET_EN_BIT 7
100
101#define S2_RESET_TYPE_WARM 0x1
102#define PON_RESIN_N_RESET_S2_TIMER_MAX_VALUE 0x7
Deepa Dinamani22799652012-07-21 12:26:22 -0700103
Parth Dixitc2e6dfe2015-06-19 15:57:47 +0530104/* USB Peripheral registers */
105#define SMBCHGL_USB_ICL_STS_2 0x1309
106
Parth Dixit746b6bb2015-07-09 19:29:44 +0530107/* PMI8950 slave id */
108#define PMI8950_SLAVE_ID 0x20000
109
Parth Dixitc2e6dfe2015-06-19 15:57:47 +0530110/* USB Peripheral register bits */
111#define USBIN_ACTIVE_PWR_SRC BIT(0)
112#define DCIN_ACTIVE_PWR_SRC BIT(1)
113
Umang Agrawalfa38b2e2018-02-19 15:32:46 +0530114/* USB Status registers */
115#define SCHG_USB_INT_RT_STS 0x1310
116#define USBIN_PLUGIN_RT_STS BIT(4)
117
Deepa Dinamanic342f122013-06-12 15:41:31 -0700118/* MPP registers */
119#define MPP_DIG_VIN_CTL 0x41
120#define MPP_MODE_CTL 0x40
121#define MPP_EN_CTL 0x46
122
123#define MPP_MODE_CTL_MODE_SHIFT 4
124#define MPP_EN_CTL_ENABLE_SHIFT 7
125
Ajay Singh Parmar502ed712014-07-23 22:58:43 -0700126/* MVS registers */
127#define MVS_EN_CTL 0x46
128#define MVS_EN_CTL_ENABLE_SHIFT 7
129
Channagoud Kadabid091f702013-01-07 16:17:37 -0800130void pm8x41_reg_write(uint32_t addr, uint8_t val);
131uint8_t pm8x41_reg_read(uint32_t addr);
132
133/* SPMI Macros */
134#define REG_READ(_a) pm8x41_reg_read(_a)
135#define REG_WRITE(_a, _v) pm8x41_reg_write(_a, _v)
136
137#define REG_OFFSET(_addr) ((_addr) & 0xFF)
138#define PERIPH_ID(_addr) (((_addr) & 0xFF00) >> 8)
139#define SLAVE_ID(_addr) ((_addr) >> 16)
140
Channagoud Kadabi0e60b7d2012-11-01 22:56:08 +0530141#define LDO_RANGE_CTRL 0x40
142#define LDO_STEP_CTRL 0x41
143#define LDO_POWER_MODE 0x45
144#define LDO_EN_CTL_REG 0x46
145
Amol Jadic3231ff2013-07-23 14:35:31 -0700146/* USB3 phy clock */
147#define DIFF_CLK1_EN_CTL 0x5746
148#define DIFF_CLK1_EN_BIT 7
149
Channagoud Kadabi7ec7a082014-02-04 15:47:13 -0800150#define LNBB_CLK_EN_CTL 0x5246
151#define LNBB_CLK_EN_BIT 7
152
Channagoud Kadabi1372b902013-10-28 16:20:51 -0700153/* SMBB registers */
154#define PM8XXX_IBAT_ATC_A 0x1054
155#define PM8XXX_VBAT_DET 0x105D
156#define PM8XXX_SEC_ACCESS 0x10D0
157#define PM8XXX_COMP_OVR0 0x10ED
158#define PM8XXX_VCP 0x1247
159#define PM8XXX_TRKL_CHG_TEST 0x10E2
160#define PM8XXX_VBAT_IN_TSTS 0x1010
161
162/* Macros for broken battery */
163#define VBAT_DET_LO_4_30V 0x35
164#define SEC_ACCESS 0xa5
165#define OVR0_DIS_VTRKL_FAULT 0x08
166#define CHG_TRICKLE_FORCED_ON 0x01
167#define VBAT_DET_HI_RT_STS 0x02
168#define VCP_ENABLE 0x01
169
Channagoud Kadabi8ceb7382014-11-14 11:25:35 -0800170#define PMI8994_CHGR_CFG2 0x210FC
171#define CURRENT_TERM_EN BIT(3)
172#define PMI8994_FCC_CFG 0x210F2
173#define PMI8994_FV_CFG 0x210F4
174#define PMI8994_INT_RT_STS 0x21010
175#define BAT_TAPER_MODE_CHARGING_RT_STS BIT(6)
176#define PMI8994_CHGR_TRIM_OPTIONS_7_0 0x216F6
177#define INPUT_MISSING_POLLER_EN BIT(3)
178
Channagoud Kadabi1372b902013-10-28 16:20:51 -0700179int pm8xxx_is_battery_broken(void);
Channagoud Kadabi8ceb7382014-11-14 11:25:35 -0800180bool pmi8994_battery_broken(void);
Channagoud Kadabi1372b902013-10-28 16:20:51 -0700181
Deepa Dinamani22799652012-07-21 12:26:22 -0700182#endif