summaryrefstree
path: root/kernel/include/linux/ccic/max77705_usbc.h
blob: 2b4ba7a7ca53c95725487d0ed34b15057739abbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * Copyrights (C) 2017 Samsung Electronics, Inc.
 * Copyrights (C) 2017 Maxim Integrated Products, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __LINUX_MFD_MAX77705_UIC_H
#define __LINUX_MFD_MAX77705_UIC_H
#include <linux/ccic/max77705.h>
#include <linux/ccic/max77705_pd.h>
#include <linux/ccic/max77705_cc.h>
#include <linux/muic/muic.h>
#include <linux/muic/max77705-muic.h>
#include <linux/battery/battery_notifier.h>
#if defined(CONFIG_TYPEC)
#include <linux/usb/typec.h>
#endif

struct max77705_opcode {
	unsigned char opcode;
	unsigned char data[OPCODE_DATA_LENGTH];
	int read_length;
	int write_length;
};

typedef struct max77705_usbc_command_data {
	u8	opcode;
	u8  prev_opcode;
	u8	response;
	u8	read_data[OPCODE_DATA_LENGTH];
	u8	write_data[OPCODE_DATA_LENGTH];
	int read_length;
	int write_length;
	u8	reg;
	u8	val;
	u8	mask;
	u8  seq;
	int noti_cmd;
	u8	is_uvdm;
} usbc_cmd_data;

typedef struct max77705_usbc_command_node {
	usbc_cmd_data				cmd_data;
	struct max77705_usbc_command_node	*next;
} usbc_cmd_node;

typedef struct max77705_usbc_command_node	*usbc_cmd_node_p;

typedef struct max77705_usbc_command_queue {
	struct mutex			command_mutex;
	usbc_cmd_node			*front;
	usbc_cmd_node			*rear;
	usbc_cmd_node			tmp_cmd_node;
} usbc_cmd_queue_t;

#if defined(CONFIG_SEC_FACTORY)
#define FAC_ABNORMAL_REPEAT_STATE			12
#define FAC_ABNORMAL_REPEAT_RID				5
#define FAC_ABNORMAL_REPEAT_RID0			3
struct AP_REQ_GET_STATUS_Type {
	uint32_t FAC_Abnormal_Repeat_State;
	uint32_t FAC_Abnormal_Repeat_RID;
	uint32_t FAC_Abnormal_RID0;
};
#endif

struct max77705_usbc_platform_data {
	struct max77705_dev *max77705;
	struct device *dev;
	struct i2c_client *i2c; /*0xCC */
	struct i2c_client *muic; /*0x4A */
	struct i2c_client *charger; /*0x2A; Charger */

	int irq_base;

	/* interrupt pin */
	int irq_apcmd;
	int irq_sysmsg;

	/* VDM pin */
	int irq_vdm0;
	int irq_vdm1;
	int irq_vdm2;
	int irq_vdm3;
	int irq_vdm4;
	int irq_vdm5;
	int irq_vdm6;
	int irq_vdm7;

	/* register information */
	u8 usbc_status1;
	u8 usbc_status2;
	u8 bc_status;
	u8 cc_status0;
	u8 cc_status1;
	u8 pd_status0;
	u8 pd_status1;

	int watchdog_count;
	int por_count;

	u8 opcode_res;
	/* USBC System message interrupt */
	u8 sysmsg;
	u8 pd_msg;

	/* F/W state */
	u8 HW_Revision;
	u8 FW_Revision;
	u8 FW_Minor_Revision;
	u8 plug_attach_done;
	int op_code_done;
	enum max77705_connstat prev_connstat;
	enum max77705_connstat current_connstat;

	/* F/W opcode Thread */

	struct work_struct op_wait_work;
	struct work_struct op_send_work;
	struct workqueue_struct	*op_wait_queue;
	struct workqueue_struct	*op_send_queue;
	struct completion op_completion;
	int op_code;
	int is_first_booting;
	usbc_cmd_data last_opcode;
	struct mutex op_lock;

	/* F/W opcode command data */
	usbc_cmd_queue_t usbc_cmd_queue;

	uint32_t alternate_state;
	uint32_t acc_type;
	uint32_t Vendor_ID;
	uint32_t Product_ID;
	uint32_t Device_Version;
	uint32_t SVID_0;
	uint32_t SVID_1;
	struct delayed_work acc_detach_work;
	uint32_t dp_is_connect;
	uint32_t dp_hs_connect;
	uint32_t dp_selected_pin;
	u8 pin_assignment;
	uint32_t is_sent_pin_configuration;
	wait_queue_head_t host_turn_on_wait_q;
	wait_queue_head_t dp_detach_wait_q;
	int host_turn_on_event;
	int host_turn_on_wait_time;
	int is_samsung_accessory_enter_mode;
	u8 sbu[2];
	struct completion ccic_sysfs_completion;
//	u8 selftest;
//	struct completion is_selftest_done;

	struct max77705_muic_data *muic_data;
	struct max77705_pd_data *pd_data;
	struct max77705_cc_data *cc_data;
	struct pdic_notifier_struct *pd_noti;

	struct max77705_platform_data *max77705_data;
	struct wake_lock apcmd_wake_lock;
	struct wake_lock sysmsg_wake_lock;
#if defined(CONFIG_CCIC_NOTIFIER)
	struct workqueue_struct *ccic_wq;
	int manual_lpm_mode;
	int fac_water_enable;
	int cur_rid;
	int pd_state;
	u8  vconn_test;
	u8  vconn_en;
	u8  fw_update;
	int is_host;
	int is_client;
	bool auto_vbus_en;
	u8 cc_pin_status;
#endif
#if defined(CONFIG_DUAL_ROLE_USB_INTF)
	struct dual_role_phy_instance *dual_role;
	struct dual_role_phy_desc *desc;
	struct completion reverse_completion;
	int power_role;
	int data_role;
	int try_state_change;
#elif defined(CONFIG_TYPEC)
	struct typec_port *port;
	struct typec_partner *partner;
	struct usb_pd_identity partner_identity;
	struct typec_capability typec_cap;
	struct completion typec_reverse_completion;
	int typec_power_role;
	int typec_data_role;
	int typec_try_state_change;
	int pwr_opmode;
#endif
	bool pd_support;
	struct delayed_work usb_external_notifier_register_work;
	struct notifier_block usb_external_notifier_nb;
	int mpsm_mode;
	int vbus_enable;
	int pd_pr_swap;
	int shut_down;
	struct delayed_work vbus_hard_reset_work;
	uint8_t ReadMSG[32];
	int ram_test_enable;
	int ram_test_retry;
	int ram_test_result;
	struct completion uvdm_longpacket_out_wait;
	struct completion uvdm_longpacket_in_wait;
	int is_in_first_sec_uvdm_req;
	int is_in_sec_uvdm_out;
	u8 uvdm_error;

#if defined(CONFIG_SEC_FACTORY)
	struct AP_REQ_GET_STATUS_Type factory_mode;
	struct delayed_work factory_state_work;
	struct delayed_work factory_rid_work;
#endif
	int detach_done_wait;
	uint32_t dr_swap_cnt;
};

/* Function Status from s2mm005 definition */
typedef enum {
	max77705_State_PE_Initial_detach	= 0,
	max77705_State_PE_SRC_Send_Capabilities = 3,
	max77705_State_PE_SNK_Wait_for_Capabilities = 17,
} max77705_pd_state_t;

typedef enum {
	MPSM_OFF = 0,
	MPSM_ON = 1,
} CCIC_DEVICE_MPSM;

#define DATA_ROLE_SWAP 1
#define POWER_ROLE_SWAP 2
#define VCONN_ROLE_SWAP 3
#define MANUAL_ROLE_SWAP 4

#define ROLE_ACCEPT			0x1
#define ROLE_REJECT			0x2
#define ROLE_BUSY			0x3

#define DP_DETACH_WAIT_TIME		5000

int max77705_pd_init(struct max77705_usbc_platform_data *usbc_data);
int max77705_cc_init(struct max77705_usbc_platform_data *usbc_data);
int max77705_muic_init(struct max77705_usbc_platform_data *usbc_data);
int max77705_i2c_opcode_read(struct max77705_usbc_platform_data *usbc_data,
		u8 opcode, u8 length, u8 *values);

void init_usbc_cmd_data(usbc_cmd_data *cmd_data);
void max77705_usbc_clear_queue(struct max77705_usbc_platform_data *usbc_data);
void max77705_usbc_opcode_rw(struct max77705_usbc_platform_data *usbc_data,
	usbc_cmd_data *opcode_r, usbc_cmd_data *opcode_w);
void max77705_usbc_opcode_write(struct max77705_usbc_platform_data *usbc_data,
	usbc_cmd_data *write_op);
void max77705_usbc_opcode_read(struct max77705_usbc_platform_data *usbc_data,
	usbc_cmd_data *read_op);
void max77705_usbc_opcode_push(struct max77705_usbc_platform_data *usbc_data,
	usbc_cmd_data *read_op);
void max77705_usbc_opcode_update(struct max77705_usbc_platform_data *usbc_data,
	usbc_cmd_data *read_op);

void max77705_ccic_event_work(void *data, int dest, int id,
		int attach, int event, int sub);
void max77705_notify_dr_status(struct max77705_usbc_platform_data *usbpd_data,
		uint8_t attach);
void max77705_pdo_list(struct max77705_usbc_platform_data *usbc_data,
		unsigned char *data);
void max77705_current_pdo(struct max77705_usbc_platform_data *usbc_data,
		unsigned char *data);
void max77705_detach_pd(struct max77705_usbc_platform_data *usbc_data);
void max77705_notify_rp_current_level(struct max77705_usbc_platform_data *usbc_data);
extern void max77705_manual_jig_on(struct max77705_usbc_platform_data *usbpd_data, int mode);
extern void max77705_vbus_turn_on_ctrl(struct max77705_usbc_platform_data *usbc_data, bool enable, bool swaped);
extern void max77705_dp_detach(void *data);
void max77705_usbc_disable_auto_vbus(struct max77705_usbc_platform_data *usbc_data);
extern void max77705_set_host_turn_on_event(int mode);
#if defined(CONFIG_TYPEC)
int max77705_get_pd_support(struct max77705_usbc_platform_data *usbc_data);
#endif

extern const uint8_t BOOT_FLASH_FW_PASS2[];
extern const uint8_t BOOT_FLASH_FW_PASS3[];
extern int dp_use_informed;

#if defined(CONFIG_SEC_FACTORY)
void factory_execute_monitor(int);
#endif

#define DEBUG_MAX77705
#ifdef DEBUG_MAX77705
#define msg_maxim(format, args...) \
		pr_info("max77705: %s: " format "\n", __func__, ## args)
#else
#define msg_maxim(format, args...)
#endif /* DEBUG_MAX77766*/
#endif