17
17
18
18
#define DRV_NAME "cros-ec-typec"
19
19
20
+ /* Per port data. */
21
+ struct cros_typec_port {
22
+ struct typec_port * port ;
23
+ /* Initial capabilities for the port. */
24
+ struct typec_capability caps ;
25
+ };
26
+
20
27
/* Platform-specific data for the Chrome OS EC Type C controller. */
21
28
struct cros_typec_data {
22
29
struct device * dev ;
23
30
struct cros_ec_device * ec ;
24
31
int num_ports ;
25
32
unsigned int cmd_ver ;
26
33
/* Array of ports, indexed by port number. */
27
- struct typec_port * ports [EC_USB_PD_MAX_PORTS ];
28
- /* Initial capabilities for each port. */
29
- struct typec_capability * caps [EC_USB_PD_MAX_PORTS ];
34
+ struct cros_typec_port * ports [EC_USB_PD_MAX_PORTS ];
30
35
struct notifier_block nb ;
31
36
};
32
37
@@ -76,14 +81,25 @@ static int cros_typec_parse_port_props(struct typec_capability *cap,
76
81
return 0 ;
77
82
}
78
83
84
+ static void cros_unregister_ports (struct cros_typec_data * typec )
85
+ {
86
+ int i ;
87
+
88
+ for (i = 0 ; i < typec -> num_ports ; i ++ ) {
89
+ if (!typec -> ports [i ])
90
+ continue ;
91
+ typec_unregister_port (typec -> ports [i ]-> port );
92
+ }
93
+ }
94
+
79
95
static int cros_typec_init_ports (struct cros_typec_data * typec )
80
96
{
81
97
struct device * dev = typec -> dev ;
82
98
struct typec_capability * cap ;
83
99
struct fwnode_handle * fwnode ;
100
+ struct cros_typec_port * cros_port ;
84
101
const char * port_prop ;
85
102
int ret ;
86
- int i ;
87
103
int nports ;
88
104
u32 port_num = 0 ;
89
105
@@ -115,31 +131,31 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
115
131
116
132
dev_dbg (dev , "Registering port %d\n" , port_num );
117
133
118
- cap = devm_kzalloc (dev , sizeof (* cap ), GFP_KERNEL );
119
- if (!cap ) {
134
+ cros_port = devm_kzalloc (dev , sizeof (* cros_port ), GFP_KERNEL );
135
+ if (!cros_port ) {
120
136
ret = - ENOMEM ;
121
137
goto unregister_ports ;
122
138
}
123
139
124
- typec -> caps [port_num ] = cap ;
140
+ typec -> ports [port_num ] = cros_port ;
141
+ cap = & cros_port -> caps ;
125
142
126
143
ret = cros_typec_parse_port_props (cap , fwnode , dev );
127
144
if (ret < 0 )
128
145
goto unregister_ports ;
129
146
130
- typec -> ports [ port_num ] = typec_register_port (dev , cap );
131
- if (IS_ERR (typec -> ports [ port_num ] )) {
147
+ cros_port -> port = typec_register_port (dev , cap );
148
+ if (IS_ERR (cros_port -> port )) {
132
149
dev_err (dev , "Failed to register port %d\n" , port_num );
133
- ret = PTR_ERR (typec -> ports [ port_num ] );
150
+ ret = PTR_ERR (cros_port -> port );
134
151
goto unregister_ports ;
135
152
}
136
153
}
137
154
138
155
return 0 ;
139
156
140
157
unregister_ports :
141
- for (i = 0 ; i < typec -> num_ports ; i ++ )
142
- typec_unregister_port (typec -> ports [i ]);
158
+ cros_unregister_ports (typec );
143
159
return ret ;
144
160
}
145
161
@@ -177,7 +193,7 @@ static int cros_typec_ec_command(struct cros_typec_data *typec,
177
193
static void cros_typec_set_port_params_v0 (struct cros_typec_data * typec ,
178
194
int port_num , struct ec_response_usb_pd_control * resp )
179
195
{
180
- struct typec_port * port = typec -> ports [port_num ];
196
+ struct typec_port * port = typec -> ports [port_num ]-> port ;
181
197
enum typec_orientation polarity ;
182
198
183
199
if (!resp -> enabled )
@@ -194,7 +210,7 @@ static void cros_typec_set_port_params_v0(struct cros_typec_data *typec,
194
210
static void cros_typec_set_port_params_v1 (struct cros_typec_data * typec ,
195
211
int port_num , struct ec_response_usb_pd_control_v1 * resp )
196
212
{
197
- struct typec_port * port = typec -> ports [port_num ];
213
+ struct typec_port * port = typec -> ports [port_num ]-> port ;
198
214
enum typec_orientation polarity ;
199
215
200
216
if (!(resp -> enabled & PD_CTRL_RESP_ENABLED_CONNECTED ))
@@ -358,9 +374,7 @@ static int cros_typec_probe(struct platform_device *pdev)
358
374
return 0 ;
359
375
360
376
unregister_ports :
361
- for (i = 0 ; i < typec -> num_ports ; i ++ )
362
- if (typec -> ports [i ])
363
- typec_unregister_port (typec -> ports [i ]);
377
+ cros_unregister_ports (typec );
364
378
return ret ;
365
379
}
366
380
0 commit comments