blob: ea7b8ed43b4713d334d1fecc9933761ba638f70f [file] [log] [blame]
AleX Pelosi78a4bea2020-09-01 19:02:24 -07001/* SPDX-License-Identifier: GPL-2.0 */
Ken Tsou8acade12020-07-09 03:17:35 +08002/*
AleX Pelosi78a4bea2020-09-01 19:02:24 -07003 * Copyright 2020 Google, LLC
Ken Tsou8acade12020-07-09 03:17:35 +08004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef MAX77759_H_
17#define MAX77759_H_
18
19#include <linux/i2c.h>
AleX Pelosi90528cd2021-04-22 23:58:50 -070020#include <linux/interrupt.h>
Ken Tsou8acade12020-07-09 03:17:35 +080021
22#define SCNPRINTF(...) scnprintf(__VA_ARGS__)
23#include "max77759_regs.h"
24
25#define MAX77759_CHG_INT_COUNT 2
AleX Pelosid6150182021-03-05 18:10:44 -080026
27#define MAX77759_PMIC_REV_A0 0x01
28#define MAX77759_PMIC_REV_A1 0x02
29
Ken Tsou8acade12020-07-09 03:17:35 +080030#define MAX77759_PMIC_PMIC_ID_MW 0x3b
31
AleX Pelosid6150182021-03-05 18:10:44 -080032int max777x9_pmic_get_id(struct i2c_client *client, u8 *id, u8 *rev);
Ken Tsou8acade12020-07-09 03:17:35 +080033int max777x9_pmic_reg_read(struct i2c_client *client,
34 u8 addr, u8 *val, int len);
35int max777x9_pmic_reg_write(struct i2c_client *client,
36 u8 addr, const u8 *val, int len);
37int max777x9_pmic_reg_update(struct i2c_client *client,
38 u8 reg, u8 mask, u8 value);
AleX Pelosi967cd3b2021-03-05 18:29:41 -080039/* write to a register */
40int max77759_chg_reg_write(struct i2c_client *client, u8 reg, u8 value);
George Lee8f1c9052022-01-04 15:08:55 -080041/* read a register */
AleX Pelosi40eab662021-05-18 02:40:28 -070042int max77759_chg_reg_read(struct i2c_client *client, u8 reg, u8 *value);
George Lee8f1c9052022-01-04 15:08:55 -080043/* update a register */
AleX Pelosi967cd3b2021-03-05 18:29:41 -080044int max77759_chg_reg_update(struct i2c_client *client, u8 reg, u8 mask, u8 value);
45/* change the mode register */
46int max77759_chg_mode_write(struct i2c_client *client, enum max77759_charger_modes mode);
AleX Pelosi5d020a82021-03-27 20:29:47 -070047/* change the insel register */
48int max77759_chg_insel_write(struct i2c_client *client, u8 mask, u8 value);
yihsiangpeng6a6bd1d2021-04-01 15:55:09 +080049/* read the insel register */
50int max77759_chg_insel_read(struct i2c_client *client, u8 *value);
AleX Pelosi967cd3b2021-03-05 18:29:41 -080051
AleX Pelosi32892282020-09-11 02:29:20 -070052#if IS_ENABLED(CONFIG_PMIC_MAX77729)
Ted Lin855504f2020-11-23 14:44:12 +080053extern int max77759_read_batt_conn(struct i2c_client *client, int *temp);
AleX Pelosi32892282020-09-11 02:29:20 -070054extern int max77759_read_usb_temp(struct i2c_client *client, int *temp);
55extern int max77759_read_batt_id(struct i2c_client *client, unsigned int *id);
56#else
Ted Lin855504f2020-11-23 14:44:12 +080057static inline int max77759_read_batt_conn(struct i2c_client *client, int *temp)
58{
59 return -ENODEV;
60}
AleX Pelosi32892282020-09-11 02:29:20 -070061static inline int max77759_read_usb_temp(struct i2c_client *client, int *temp)
62{
63 return -ENODEV;
64}
65static inline int max77759_read_batt_id(struct i2c_client *client,
66 unsigned int *id)
67{
68 return -ENODEV;
69}
70#endif
71
AleX Pelosi09a58612021-02-27 00:09:11 -080072/* ----------------------------------------------------------------------------
AleX Pelosi327e6932021-02-03 15:03:00 -080073 * GS101 usecases
AleX Pelosi09a58612021-02-27 00:09:11 -080074 * Platform specific, will need to be moved outside the driver.
75 *
76 * Case USB_chg USB_otg WLC_chg WLC_TX PMIC_Charger Ext_B LSx Name
77 * ----------------------------------------------------------------------------
78 * 1-1 1 0 x 0 IF-PMIC-VBUS 0 0/0 USB_CHG
79 * 1-2 2 0 x 0 DC VBUS 0 0/0 USB_DC
80 * 2-1 1 0 0 1 IF-PMIC-VBUS 2 0/1 USB_CHG_WLC_TX
81 * 2-2 2 0 0 1 DC CHG 2 0/1 USB_DC_WLC_TX
82 * 3-1 0 0 1 0 IF-PMIC-WCIN 0 0/0 WLC_RX
83 * 3-2 0 0 2 0 DC WCIN 0 0/0 WLC_DC
84 * 4-1 0 1 1 0 IF-PMIC-WCIN 1 1/0 USB_OTG_WLC_RX
85 * 4-2 0 1 2 0 DC WCIN 1 1/0 USB_OTG_WLC_DC
86 * 5-1 0 1 0 0 0 1 1/0 USB_OTG
87 * 5-2 0 1 0 0 OTG 5V 0 0/0 USB_OTG_FRS
88 * 6-2 0 0 0 1 0 2 0/1 WLC_TX
89 * 7-2 0 1 0 1 MW OTG 5V 2 0/1 USB_OTG_WLC_TX
90 * 8 0 0 0 0 0 0 0/0 IDLE
91 * ----------------------------------------------------------------------------
92 *
93 * Ext_Boost = 0 off, 1 = OTG 5V, 2 = WTX 7.5
94 * USB_chg = 0 off, 1 = on, 2 = PPS
95 * WLC_chg = 0 off, 1 = on, 2 = PPS
AleX Pelosi327e6932021-02-03 15:03:00 -080096 */
AleX Pelosi327e6932021-02-03 15:03:00 -080097struct max77759_foreach_cb_data {
98 struct gvotable_election *el;
99
100 const char *reason;
101
AleX Pelosi8ccfc502021-05-13 20:04:56 -0700102 int chgr_on; /* CC_MAX != 0 */
AleX Pelosi3e4d1462021-03-22 14:20:54 -0700103 bool stby_on; /* on disconnect, mode=0 */
AleX Pelosiaf596a22021-06-18 17:06:33 -0700104 bool charge_done;
AleX Pelosi327e6932021-02-03 15:03:00 -0800105
AleX Pelosidadc9492021-03-23 13:01:11 -0700106 int chgin_off; /* input_suspend, mode=0 */
107 int wlcin_off; /* input_suspend, mode=0 */
AleX Pelosi960eb0a2021-07-20 20:09:18 -0700108 int usb_wlc; /* input_suspend, mode=0 */
AleX Pelosidadc9492021-03-23 13:01:11 -0700109
110 /* wlc_on is the same as wlc_rx */
AleX Pelosi327e6932021-02-03 15:03:00 -0800111 bool buck_on; /* wired power in (chgin_on) from TCPCI */
112
113 bool otg_on; /* power out, usually external */
AleX Pelosi00cd96d2021-03-25 09:46:50 -0700114 bool frs_on; /* power out, fast role swap (internal) */
AleX Pelosi327e6932021-02-03 15:03:00 -0800115
AleX Pelosi29ca3552021-03-15 23:24:37 -0700116 bool wlc_rx; /* charging wireless */
AleX Pelosi327e6932021-02-03 15:03:00 -0800117 bool wlc_tx; /* battery share */
118
AleX Pelosi00cd96d2021-03-25 09:46:50 -0700119 bool dc_on; /* DC requested - wired or wireless */
AleX Pelosi327e6932021-02-03 15:03:00 -0800120
AleX Pelosi00cd96d2021-03-25 09:46:50 -0700121 bool boost_on; /* Compat: old for WLC program */
122 bool uno_on; /* Compat: old for WLC program */
AleX Pelosi327e6932021-02-03 15:03:00 -0800123
124 u8 raw_value; /* hard override */
125 bool use_raw;
126
Jack Wu15abe932022-11-14 20:11:24 +0800127 bool pogo_vin; /* pogo ovp_en */
Jack Wu71efd602022-07-07 16:22:31 +0800128 bool pogo_vout; /* pogo 5v vout */
129
AleX Pelosi327e6932021-02-03 15:03:00 -0800130 u8 reg;
Wasb Liu198b96d2022-07-28 11:13:15 +0800131
132 struct gvotable_election *dc_avail_votable; /* DC_AVAIL */
AleX Pelosi327e6932021-02-03 15:03:00 -0800133};
134
AleX Pelosi327e6932021-02-03 15:03:00 -0800135/* internal system values */
136enum {
AleX Pelosi00cd96d2021-03-25 09:46:50 -0700137 /* Charging disabled (go to mode 0) */
AleX Pelosi327e6932021-02-03 15:03:00 -0800138 GBMS_CHGR_MODE_STBY_ON = 0x10 + MAX77759_CHGR_MODE_ALL_OFF,
AleX Pelosidadc9492021-03-23 13:01:11 -0700139 /* USB inflow off */
140 GBMS_CHGR_MODE_CHGIN_OFF = 0x11 + MAX77759_CHGR_MODE_ALL_OFF,
141 /* WCIN inflow off */
142 GBMS_CHGR_MODE_WLCIN_OFF = 0x12 + MAX77759_CHGR_MODE_ALL_OFF,
AleX Pelosi960eb0a2021-07-20 20:09:18 -0700143 /* USB + WLC_RX mode */
144 GBMS_CHGR_MODE_USB_WLC_RX = 0x13 + MAX77759_CHGR_MODE_ALL_OFF,
145
AleX Pelosidadc9492021-03-23 13:01:11 -0700146 /* charging enabled (charging current != 0) */
AleX Pelosi327e6932021-02-03 15:03:00 -0800147 GBMS_CHGR_MODE_CHGR_BUCK_ON = 0x10 + MAX77759_CHGR_MODE_CHGR_BUCK_ON,
AleX Pelosidadc9492021-03-23 13:01:11 -0700148 /* Compat: old for programmging */
AleX Pelosi327e6932021-02-03 15:03:00 -0800149 GBMS_CHGR_MODE_BOOST_UNO_ON = 0x10 + MAX77759_CHGR_MODE_BOOST_UNO_ON,
150};
151
152
Badhri Jagan Sridharan991b7b52020-11-10 00:00:35 -0800153#endif