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
|
#ifndef __CCLOGIC_COMMON_H
#define __CCLOGIC_COMMON_H
#include <linux/wakelock.h>
#include "cclogic-class.h"
#define DEV_STAGE_DEBUG
#define CCLOGIC_UPDATE_REAL_STATUS
#ifdef DEBUG
#undef pr_debug
#undef pr_info
#define pr_debug(fmt, args...) pr_err(fmt, ##args)
#define pr_info(fmt, args...) pr_err(fmt, ##args)
#endif
#define CCLOGIC_I2C_VTG_MIN_UV 1800000
#define CCLOGIC_I2C_VTG_MAX_UV 1800000
#define CCLOGIC_I2C_LOAD_UA 1800
#define CCLOGIC_MAX_SUPPORT_CHIP 2
/* #define CCLOGIC_MAX_RETRIES 100 */
#define CCLOGIC_MAX_RETRIES 5
struct cclogic_of_chip {
const char *chip_name;
int enb;
int address;
};
#define CCLOGIC_SUPPORT_MODE_DFP (1<<0)
#define CCLOGIC_SUPPORT_MODE_UFP (1<<1)
#define CCLOGIC_SUPPORT_MODE_DUAL ((1<<0)|(1<<1))
#define CCLOGIC_SUPPORT_POWER_SOURCE (1<<2)
#define CCLOGIC_SUPPORT_POWER_SINK (1<<3)
#define CCLOGIC_SUPPORT_POWER_SWAP ((1<<2)|(1<<3))
#define CCLOGIC_SUPPORT_DATA_HOST (1<<4)
#define CCLOGIC_SUPPORT_DATA_DEVICE (1<<5)
#define CCLOGIC_SUPPORT_DATA_SWAP ((1<<4)|(1<<5))
#define CCLOGIC_MODE_NONE 0
#define CCLOGIC_MODE_DFP 1
#define CCLOGIC_MODE_UFP 2
#define CCLOGIC_MODE_DRP 3
#define CCLOGIC_POWER_NONE 0
#define CCLOGIC_POWER_SOURCE 1
#define CCLOGIC_POWER_SINK 2
#define CCLOGIC_DATA_NONE 0
#define CCLOGIC_DATA_HOST 1
#define CCLOGIC_DATA_DEVICE 2
struct cclogic_platform {
unsigned int irq_working_flags;
unsigned int irq_working;
unsigned int irq_plug_flags;
unsigned int irq_plug;
bool i2c_pull_up;
unsigned int function_switch_gpio1;
unsigned int function_switch_gpio10;
unsigned int function_switch_gpio2;
unsigned int usb_ss_gpio;
unsigned int enb_gpio;
unsigned int ccchip_power_gpio;
int chip_num;
struct regulator *vbus_reg;
struct cclogic_of_chip chip[CCLOGIC_MAX_SUPPORT_CHIP];
};
enum cclogic_attached_type {
CCLOGIC_DEVICE_UNKNOWN,
CCLOGIC_NO_DEVICE,
CCLOGIC_USB_DEVICE,
CCLOGIC_USB_HOST,
CCLOGIC_DEBUG_DEVICE,
CCLOGIC_AUDIO_DEVICE,
};
enum cclogic_current_type {
CCLOGIC_CURRENT_NONE,
CCLOGIC_CURRENT_DEFAULT,
CCLOGIC_CURRENT_MEDIUM,
CCLOGIC_CURRENT_ACCESSORY,
CCLOGIC_CURRENT_HIGH,
};
enum cclogic_event_type {
CCLOGIC_EVENT_NONE,
CCLOGIC_EVENT_DETACHED,
CCLOGIC_EVENT_ATTACHED,
};
enum cclogic_cc_type {
CCLOGIC_CC_UNKNOWN,
CCLOGIC_CC1,
CCLOGIC_CC2,
CCLOGIC_CC1_CC2,
};
struct cclogic_state {
bool vbus;
enum cclogic_cc_type cc;
enum cclogic_event_type evt;
enum cclogic_attached_type device;
enum cclogic_current_type charger;
};
struct cclogic_chip;
struct cclogic_dev {
struct device *dev;
struct i2c_client *i2c_client;
unsigned int irq_working;
unsigned int irq_plug;
bool irq_enabled;
struct regulator *vcc_i2c;
bool regulator_en;
struct delayed_work work;
struct delayed_work plug_work;
struct cclogic_platform *platform_data;
struct wake_lock wakelock;
struct wake_lock wakelock_plug;
bool vbus_on;
struct cclogic_chip *ops;
struct cclogic_state state;
struct pinctrl *pin;
struct pinctrl_state *pin_active;
struct pinctrl_state *pin_suspend;
struct cclogic_class_dev cdev;
int enb;
unsigned int typec_version;
};
struct cclogic_chip {
const char *chip_name;
unsigned char addr;
unsigned int typec_version;
unsigned int support;
int (*get_state)(struct i2c_client *client, struct cclogic_state *result);
int (*ack_irq)(struct i2c_client *client);
int (*chip_config)(struct i2c_client *client);
int (*chip_reset)(struct i2c_client *client);
int (*chip_check)(struct i2c_client *client);
int (*chip_trymode)(struct i2c_client *client, int mode);
struct list_head chip_list;
int (*read)(struct i2c_client *client, u8 reg);
int (*write)(struct i2c_client *client, u8 reg, u8 data);
};
enum cclogic_func_type {
CCLOGIC_FUNC_HIZ,
CCLOGIC_FUNC_USB,
CCLOGIC_FUNC_AUDIO,
CCLOGIC_FUNC_UART,
};
extern int cclogic_register(struct cclogic_chip *c);
extern void cclogic_unregister(struct cclogic_chip *c);
extern int cclogic_get_connected_mode(struct cclogic_state *state);
extern int cclogic_set_mode(struct cclogic_dev *pdata, int mode);
extern int cclogic_get_power_role(struct cclogic_state *state);
extern int cclogic_set_power_role(struct cclogic_dev *pdata, int role);
extern int cclogic_get_data_role(struct cclogic_state *state);
extern int cclogic_set_data_role(struct cclogic_dev *pdata, int role);
#endif
|