blob: b908b1462ad51c5badb52189a8051592a4232ea3 [file] [log] [blame]
Umang Agrawal89f6dcb2018-01-03 19:07:47 +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_H_
30#define _PM8x41_H_
31
Channagoud Kadabi0e60b7d2012-11-01 22:56:08 +053032#include <sys/types.h>
33
Deepa Dinamani9a612932012-08-14 16:15:03 -070034#define PM_GPIO_DIR_OUT 0x01
35#define PM_GPIO_DIR_IN 0x00
36#define PM_GPIO_DIR_BOTH 0x02
37
38#define PM_GPIO_PULL_UP_30 0
39#define PM_GPIO_PULL_UP_1_5 1
40#define PM_GPIO_PULL_UP_31_5 2
41/* 1.5uA + 30uA boost */
42#define PM_GPIO_PULL_UP_1_5_30 3
Kuogee Hsieh11835112013-10-04 15:50:36 -070043#define PM_GPIO_PULLDOWN_10 4
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +053044#define PM_GPIO_NO_PULL 5
Deepa Dinamani9a612932012-08-14 16:15:03 -070045
Siddhartha Agrawald61f81e2012-12-17 19:20:35 -080046
47#define PM_GPIO_OUT_CMOS 0x00
48#define PM_GPIO_OUT_DRAIN_NMOS 0x01
49#define PM_GPIO_OUT_DRAIN_PMOS 0x02
50
51#define PM_GPIO_OUT_DRIVE_LOW 0x01
52#define PM_GPIO_OUT_DRIVE_MED 0x02
53#define PM_GPIO_OUT_DRIVE_HIGH 0x03
54
Siddhartha Agrawald61f81e2012-12-17 19:20:35 -080055#define PM_GPIO_FUNC_LOW 0x00
56#define PM_GPIO_FUNC_HIGH 0x01
Kuogee Hsieh11835112013-10-04 15:50:36 -070057#define PM_GPIO_FUNC_2 0x06
Dhaval Patel171f0e42013-10-18 18:56:23 -070058#define PM_GPIO_FUNC_1 0x04
Siddhartha Agrawald61f81e2012-12-17 19:20:35 -080059
60#define PM_GPIO_MODE_MASK 0x70
61#define PM_GPIO_OUTPUT_MASK 0x0F
62
Neeti Desai120b55d2012-08-20 17:15:56 -070063#define PON_PSHOLD_WARM_RESET 0x1
Deepa Dinamani3c9865d2013-03-08 14:03:19 -080064#define PON_PSHOLD_SHUTDOWN 0x4
Sundarajan Srinivasanefc61b62013-07-19 12:08:07 -070065#define PON_PSHOLD_HARD_RESET 0x7
Neeti Desai120b55d2012-08-20 17:15:56 -070066
Ashish Garg44992472017-08-07 14:36:59 +053067#define PM_GPIO_NO_INVERT 0x00
68#define PM_GPIO_INVERT 0x01
69
Channagoud Kadabi36c19ea2013-07-05 16:28:44 -070070enum PM8X41_VERSIONS
71{
72 PM8X41_VERSION_V1 = 0,
73 PM8X41_VERSION_V2 = 1,
74};
75
Deepa Dinamani7564f2a2013-02-05 17:55:51 -080076
sundarajan srinivasand0f59e82013-02-12 19:17:02 -080077/*Target power on reasons*/
Ameya Thakurca145d72013-07-17 16:52:02 -070078#define HARD_RST 1
sundarajan srinivasand0f59e82013-02-12 19:17:02 -080079#define DC_CHG 8
80#define USB_CHG 16
81#define PON1 32
82#define CBLPWR_N 64
83#define KPDPWR_N 128
84
Matthew Qin5e90d832014-07-11 11:15:22 +080085/*Target power off reasons*/
86#define KPDPWR_AND_RESIN 32
87#define STAGE3 128
Umang Agrawale82646d2019-05-23 16:25:45 +053088#define PM660_STAGE3 32
Matthew Qin5e90d832014-07-11 11:15:22 +080089
Deepa Dinamani9a612932012-08-14 16:15:03 -070090struct pm8x41_gpio {
91 int direction;
92 int output_buffer;
93 int output_value;
94 int pull;
95 int vin_sel;
96 int out_strength;
97 int function;
98 int inv_int_pol;
99 int disable_pin;
100};
101
Deepa Dinamanie69ba612013-06-03 16:10:09 -0700102struct pm8x41_ldo {
103 uint8_t type;
104 uint32_t base;
105};
106
107/* LDO base addresses. */
108#define PM8x41_LDO2 0x14100
109#define PM8x41_LDO4 0x14300
Ray Zhang898675f2013-05-25 23:13:40 +0800110#define PM8x41_LDO8 0x14700
Deepa Dinamanie69ba612013-06-03 16:10:09 -0700111#define PM8x41_LDO12 0x14B00
112#define PM8x41_LDO14 0x14D00
Ray Zhang898675f2013-05-25 23:13:40 +0800113#define PM8x41_LDO15 0x14E00
Deepa Dinamanie69ba612013-06-03 16:10:09 -0700114#define PM8x41_LDO19 0x15200
115#define PM8x41_LDO22 0x15500
116
117/* LDO voltage ranges */
118#define NLDO_UV_MIN 375000
119#define NLDO_UV_MAX 1537500
120#define NLDO_UV_STEP 12500
121#define NLDO_UV_VMIN_LOW 750000
122
123#define PLDO_UV_VMIN_LOW 750000
124#define PLDO_UV_VMIN_MID 1500000
125#define PLDO_UV_VMIN_HIGH 1750000
126
127#define PLDO_UV_MIN 1537500
128#define PDLO_UV_MID 3075000
129#define PLDO_UV_MAX 4900000
130#define PLDO_UV_STEP_LOW 12500
131#define PLDO_UV_STEP_MID 25000
132#define PLDO_UV_STEP_HIGH 50000
133
134#define LDO_RANGE_SEL_BIT 0
135#define LDO_VSET_SEL_BIT 0
136#define LDO_VREG_ENABLE_BIT 7
137#define LDO_NORMAL_PWR_BIT 7
138
139#define PLDO_TYPE 0
140#define NLDO_TYPE 1
141
142#define LDO(_base, _type) \
143{ \
144 .type = _type, \
145 .base = _base, \
146}
147
Deepa Dinamanic342f122013-06-12 15:41:31 -0700148enum mpp_vin_select
149{
150 MPP_VIN0,
151 MPP_VIN1,
152 MPP_VIN2,
153 MPP_VIN3,
154};
155
156enum mpp_mode_en_source_select
157{
158 MPP_LOW,
159 MPP_HIGH,
160 MPP_PAIRED_MPP,
161 MPP_NOT_PAIRED_MPP,
162 MPP_DTEST1 = 8,
163 MPP_NOT_DTEST1,
164 MPP_DTEST2,
165 MPP_NOT_DTEST2,
166 MPP_DTEST3,
167 MPP_NOT_DTEST3,
168 MPP_DTEST4,
169 MPP_NOT_DTEST4,
170};
171
172enum mpp_en_ctl
173{
174 MPP_DISABLE,
175 MPP_ENABLE,
176};
177
Ajay Singh Parmar502ed712014-07-23 22:58:43 -0700178enum mvs_en_ctl
179{
180 MVS_DISABLE,
181 MVS_ENABLE,
182};
183
Deepa Dinamanic342f122013-06-12 15:41:31 -0700184enum mpp_mode
185{
186 MPP_DIGITAL_INPUT,
187 MPP_DIGITAL_OUTPUT,
188 MPP_DIGITAL_IN_AND_OUT,
189 MPP_BIDIRECTIONAL,
190 MPP_ANALOG_INPUT,
191 MPP_ANALOG_OUTPUT,
192 MPP_CURRENT_SINK,
193 MPP_RESERVED,
194};
195
196struct pm8x41_mpp
197{
198 uint32_t base;
199 enum mpp_vin_select vin;
200 enum mpp_mode_en_source_select mode;
201};
202
Ajay Singh Parmar502ed712014-07-23 22:58:43 -0700203struct pm8x41_mvs
204{
205 uint32_t base;
206};
207
Kuogee Hsieh383a5ae2014-09-02 16:31:39 -0700208#define PM8x41_MMP1_BASE 0xA000
Sundarajan Srinivasan971b0d72013-12-10 17:56:22 -0800209#define PM8x41_MMP2_BASE 0xA100
Deepa Dinamanic342f122013-06-12 15:41:31 -0700210#define PM8x41_MMP3_BASE 0xA200
Aparna Mallavarapu09c53df2014-03-28 17:47:43 +0530211#define PM8x41_MMP4_BASE 0xA300
Ajay Singh Parmar502ed712014-07-23 22:58:43 -0700212#define PM8x41_MVS1_BASE 0x18400
Deepa Dinamanic342f122013-06-12 15:41:31 -0700213
Kuogee Hsieh11835112013-10-04 15:50:36 -0700214void pm8x41_lpg_write(uint8_t chan, uint8_t off, uint8_t val);
Kuogee Hsieh383a5ae2014-09-02 16:31:39 -0700215void pm8x41_lpg_write_sid(uint8_t sid, uint8_t chan, uint8_t off, uint8_t val);
Deepa Dinamani9a612932012-08-14 16:15:03 -0700216int pm8x41_gpio_get(uint8_t gpio, uint8_t *status);
Kuogee Hsieh383a5ae2014-09-02 16:31:39 -0700217int pm8x41_gpio_get_sid(uint8_t sid, uint8_t gpio, uint8_t *status);
Siddhartha Agrawald61f81e2012-12-17 19:20:35 -0800218int pm8x41_gpio_set(uint8_t gpio, uint8_t value);
Kuogee Hsieh383a5ae2014-09-02 16:31:39 -0700219int pm8x41_gpio_set_sid(uint8_t sid, uint8_t gpio, uint8_t value);
Deepa Dinamani9a612932012-08-14 16:15:03 -0700220int pm8x41_gpio_config(uint8_t gpio, struct pm8x41_gpio *config);
Kuogee Hsieh383a5ae2014-09-02 16:31:39 -0700221int pm8x41_gpio_config_sid(uint8_t sid, uint8_t gpio, struct pm8x41_gpio *config);
Deepa Dinamani22799652012-07-21 12:26:22 -0700222void pm8x41_set_boot_done();
Channagoud Kadabi36c19ea2013-07-05 16:28:44 -0700223uint32_t pm8x41_v2_resin_status();
Deepa Dinamanic7f87582013-02-01 15:24:49 -0800224uint32_t pm8x41_resin_status();
Neeti Desai120b55d2012-08-20 17:15:56 -0700225void pm8x41_reset_configure(uint8_t);
Channagoud Kadabi1312b5d2015-01-28 23:28:47 -0800226void pm8994_reset_configure(uint8_t);
Vamshi Krishna B V82af8482018-03-09 21:02:42 +0530227void pm8996_reset_configure(uint8_t, uint8_t);
Umang Agrawal89f6dcb2018-01-03 19:07:47 +0530228void pmi632_reset_configure(uint8_t);
Deepa Dinamani3c9865d2013-03-08 14:03:19 -0800229void pm8x41_v2_reset_configure(uint8_t);
Parth Dixit1a963d72015-10-20 01:08:57 +0530230uint8_t pmi8950_get_pmi_subtype();
Deepa Dinamanie69ba612013-06-03 16:10:09 -0700231int pm8x41_ldo_set_voltage(struct pm8x41_ldo *ldo, uint32_t voltage);
232int pm8x41_ldo_control(struct pm8x41_ldo *ldo, uint8_t enable);
Deepa Dinamani7564f2a2013-02-05 17:55:51 -0800233uint8_t pm8x41_get_pmic_rev();
sundarajan srinivasand0f59e82013-02-12 19:17:02 -0800234uint8_t pm8x41_get_pon_reason();
Mayank Grover8bf68ac2017-12-05 10:27:36 +0530235uint8_t pm660_get_pon_reason();
Parth Dixitc2e6dfe2015-06-19 15:57:47 +0530236uint8_t pm8950_get_pon_reason();
Umang Agrawalfa38b2e2018-02-19 15:32:46 +0530237uint8_t pmi632_get_pon_reason();
Umang Agrawale82646d2019-05-23 16:25:45 +0530238uint8_t pm660_get_pon_poff_reason1();
239uint8_t pm660_get_pon_poff_reason2();
Matthew Qin5e90d832014-07-11 11:15:22 +0800240uint8_t pm8x41_get_pon_poff_reason1();
241uint8_t pm8x41_get_pon_poff_reason2();
Matthew Qin3aa87052014-02-21 10:32:34 +0800242uint32_t pm8x41_get_pwrkey_is_pressed();
Deepa Dinamanic342f122013-06-12 15:41:31 -0700243void pm8x41_config_output_mpp(struct pm8x41_mpp *mpp);
244void pm8x41_enable_mpp(struct pm8x41_mpp *mpp, enum mpp_en_ctl enable);
Ajay Singh Parmar502ed712014-07-23 22:58:43 -0700245void pm8x41_enable_mvs(struct pm8x41_mvs *mvs, enum mvs_en_ctl enable);
Ameya Thakurb0a62ab2013-06-25 13:43:10 -0700246uint8_t pm8x41_get_is_cold_boot();
Mayank Grover8bf68ac2017-12-05 10:27:36 +0530247uint8_t pm660_get_is_cold_boot();
Amol Jadic3231ff2013-07-23 14:35:31 -0700248void pm8x41_diff_clock_ctrl(uint8_t enable);
Xiaocheng Li73c57122013-09-14 17:32:00 +0800249void pm8x41_clear_pmic_watchdog(void);
Channagoud Kadabi7ec7a082014-02-04 15:47:13 -0800250void pm8x41_lnbb_clock_ctrl(uint8_t enable);
Veera Sundaram Sankarand3227762014-12-09 11:45:29 -0800251void pmi8994_config_mpp_slave_id(uint8_t slave_id);
252void pm_pwm_enable(bool enable);
253int pm_pwm_config(unsigned int duty_us, unsigned int period_us);
Channagoud Kadabi56a6b522015-04-24 17:23:27 -0700254uint32_t spmi_reg_read(uint32_t slave_id, uint16_t addr, uint8_t *data, uint8_t priority);
255uint32_t spmi_reg_write(uint32_t slave_id, uint16_t addr, uint8_t *data, uint8_t priority);
Kiran Gunda11938522018-10-16 17:54:00 +0530256void pm8x41_vib_turn_on(void);
257void pm8x41_vib_turn_off(void);
Deepa Dinamani22799652012-07-21 12:26:22 -0700258#endif