Skip to content

Commit 5851721

Browse files
gwendalcrTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_lpc: Merge lpc_driver_ops into ec private structure
Remove cros_ec_lpc_ops global variable, since EC specific info can be stored in the device private structure, introduced in commit e4dbf9d ("platform/chrome: cros_ec_lpc: add a "quirks" system"). Add ec_lpc pointer to read/write function to be able to access ec specific data. Signed-off-by: Gwendal Grignou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent df78050 commit 5851721

File tree

1 file changed

+41
-45
lines changed

1 file changed

+41
-45
lines changed

drivers/platform/chrome/cros_ec_lpc.c

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,26 @@ struct lpc_driver_data {
7070
/**
7171
* struct cros_ec_lpc - LPC device-specific data
7272
* @mmio_memory_base: The first I/O port addressing EC mapped memory.
73-
*/
74-
struct cros_ec_lpc {
75-
u16 mmio_memory_base;
76-
};
77-
78-
/**
79-
* struct lpc_driver_ops - LPC driver operations
8073
* @read: Copy length bytes from EC address offset into buffer dest.
8174
* Returns a negative error code on error, or the 8-bit checksum
8275
* of all bytes read.
8376
* @write: Copy length bytes from buffer msg into EC address offset.
8477
* Returns a negative error code on error, or the 8-bit checksum
8578
* of all bytes written.
8679
*/
87-
struct lpc_driver_ops {
88-
int (*read)(unsigned int offset, unsigned int length, u8 *dest);
89-
int (*write)(unsigned int offset, unsigned int length, const u8 *msg);
80+
struct cros_ec_lpc {
81+
u16 mmio_memory_base;
82+
int (*read)(struct cros_ec_lpc *ec_lpc, unsigned int offset,
83+
unsigned int length, u8 *dest);
84+
int (*write)(struct cros_ec_lpc *ec_lpc, unsigned int offset,
85+
unsigned int length, const u8 *msg);
9086
};
9187

92-
static struct lpc_driver_ops cros_ec_lpc_ops = { };
93-
9488
/*
9589
* A generic instance of the read function of struct lpc_driver_ops, used for
9690
* the LPC EC.
9791
*/
98-
static int cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length,
92+
static int cros_ec_lpc_read_bytes(struct cros_ec_lpc *_, unsigned int offset, unsigned int length,
9993
u8 *dest)
10094
{
10195
u8 sum = 0;
@@ -114,7 +108,7 @@ static int cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length,
114108
* A generic instance of the write function of struct lpc_driver_ops, used for
115109
* the LPC EC.
116110
*/
117-
static int cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length,
111+
static int cros_ec_lpc_write_bytes(struct cros_ec_lpc *_, unsigned int offset, unsigned int length,
118112
const u8 *msg)
119113
{
120114
u8 sum = 0;
@@ -133,8 +127,8 @@ static int cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length,
133127
* An instance of the read function of struct lpc_driver_ops, used for the
134128
* MEC variant of LPC EC.
135129
*/
136-
static int cros_ec_lpc_mec_read_bytes(unsigned int offset, unsigned int length,
137-
u8 *dest)
130+
static int cros_ec_lpc_mec_read_bytes(struct cros_ec_lpc *ec_lpc, unsigned int offset,
131+
unsigned int length, u8 *dest)
138132
{
139133
int in_range = cros_ec_lpc_mec_in_range(offset, length);
140134

@@ -145,15 +139,15 @@ static int cros_ec_lpc_mec_read_bytes(unsigned int offset, unsigned int length,
145139
cros_ec_lpc_io_bytes_mec(MEC_IO_READ,
146140
offset - EC_HOST_CMD_REGION0,
147141
length, dest) :
148-
cros_ec_lpc_read_bytes(offset, length, dest);
142+
cros_ec_lpc_read_bytes(ec_lpc, offset, length, dest);
149143
}
150144

151145
/*
152146
* An instance of the write function of struct lpc_driver_ops, used for the
153147
* MEC variant of LPC EC.
154148
*/
155-
static int cros_ec_lpc_mec_write_bytes(unsigned int offset, unsigned int length,
156-
const u8 *msg)
149+
static int cros_ec_lpc_mec_write_bytes(struct cros_ec_lpc *ec_lpc, unsigned int offset,
150+
unsigned int length, const u8 *msg)
157151
{
158152
int in_range = cros_ec_lpc_mec_in_range(offset, length);
159153

@@ -164,18 +158,19 @@ static int cros_ec_lpc_mec_write_bytes(unsigned int offset, unsigned int length,
164158
cros_ec_lpc_io_bytes_mec(MEC_IO_WRITE,
165159
offset - EC_HOST_CMD_REGION0,
166160
length, (u8 *)msg) :
167-
cros_ec_lpc_write_bytes(offset, length, msg);
161+
cros_ec_lpc_write_bytes(ec_lpc, offset, length, msg);
162+
}
168163
}
169164

170-
static int ec_response_timed_out(void)
165+
static int ec_response_timed_out(struct cros_ec_lpc *ec_lpc)
171166
{
172167
unsigned long one_second = jiffies + HZ;
173168
u8 data;
174169
int ret;
175170

176171
usleep_range(200, 300);
177172
do {
178-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_CMD, 1, &data);
173+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_CMD, 1, &data);
179174
if (ret < 0)
180175
return ret;
181176
if (!(data & EC_LPC_STATUS_BUSY_MASK))
@@ -189,6 +184,7 @@ static int ec_response_timed_out(void)
189184
static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
190185
struct cros_ec_command *msg)
191186
{
187+
struct cros_ec_lpc *ec_lpc = ec->priv;
192188
struct ec_host_response response;
193189
u8 sum;
194190
int ret = 0;
@@ -199,17 +195,17 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
199195
goto done;
200196

201197
/* Write buffer */
202-
ret = cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_PACKET, ret, ec->dout);
198+
ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_PACKET, ret, ec->dout);
203199
if (ret < 0)
204200
goto done;
205201

206202
/* Here we go */
207203
sum = EC_COMMAND_PROTOCOL_3;
208-
ret = cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_CMD, 1, &sum);
204+
ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_CMD, 1, &sum);
209205
if (ret < 0)
210206
goto done;
211207

212-
ret = ec_response_timed_out();
208+
ret = ec_response_timed_out(ec_lpc);
213209
if (ret < 0)
214210
goto done;
215211
if (ret) {
@@ -219,7 +215,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
219215
}
220216

221217
/* Check result */
222-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_DATA, 1, &sum);
218+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_DATA, 1, &sum);
223219
if (ret < 0)
224220
goto done;
225221
msg->result = ret;
@@ -229,7 +225,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
229225

230226
/* Read back response */
231227
dout = (u8 *)&response;
232-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_PACKET, sizeof(response),
228+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_PACKET, sizeof(response),
233229
dout);
234230
if (ret < 0)
235231
goto done;
@@ -246,7 +242,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
246242
}
247243

248244
/* Read response and process checksum */
249-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_PACKET +
245+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_PACKET +
250246
sizeof(response), response.data_len,
251247
msg->data);
252248
if (ret < 0)
@@ -270,6 +266,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
270266
static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
271267
struct cros_ec_command *msg)
272268
{
269+
struct cros_ec_lpc *ec_lpc = ec->priv;
273270
struct ec_lpc_host_args args;
274271
u8 sum;
275272
int ret = 0;
@@ -291,26 +288,26 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
291288
sum = msg->command + args.flags + args.command_version + args.data_size;
292289

293290
/* Copy data and update checksum */
294-
ret = cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_PARAM, msg->outsize,
291+
ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_PARAM, msg->outsize,
295292
msg->data);
296293
if (ret < 0)
297294
goto done;
298295
sum += ret;
299296

300297
/* Finalize checksum and write args */
301298
args.checksum = sum;
302-
ret = cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_ARGS, sizeof(args),
299+
ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_ARGS, sizeof(args),
303300
(u8 *)&args);
304301
if (ret < 0)
305302
goto done;
306303

307304
/* Here we go */
308305
sum = msg->command;
309-
ret = cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_CMD, 1, &sum);
306+
ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_CMD, 1, &sum);
310307
if (ret < 0)
311308
goto done;
312309

313-
ret = ec_response_timed_out();
310+
ret = ec_response_timed_out(ec_lpc);
314311
if (ret < 0)
315312
goto done;
316313
if (ret) {
@@ -320,7 +317,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
320317
}
321318

322319
/* Check result */
323-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_DATA, 1, &sum);
320+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_DATA, 1, &sum);
324321
if (ret < 0)
325322
goto done;
326323
msg->result = ret;
@@ -329,7 +326,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
329326
goto done;
330327

331328
/* Read back args */
332-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8 *)&args);
329+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8 *)&args);
333330
if (ret < 0)
334331
goto done;
335332

@@ -345,7 +342,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
345342
sum = msg->command + args.flags + args.command_version + args.data_size;
346343

347344
/* Read response and update checksum */
348-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_HOST_PARAM, args.data_size,
345+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_PARAM, args.data_size,
349346
msg->data);
350347
if (ret < 0)
351348
goto done;
@@ -381,15 +378,15 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
381378

382379
/* fixed length */
383380
if (bytes) {
384-
ret = cros_ec_lpc_ops.read(ec_lpc->mmio_memory_base + offset, bytes, s);
381+
ret = ec_lpc->read(ec_lpc, ec_lpc->mmio_memory_base + offset, bytes, s);
385382
if (ret < 0)
386383
return ret;
387384
return bytes;
388385
}
389386

390387
/* string */
391388
for (; i < EC_MEMMAP_SIZE; i++, s++) {
392-
ret = cros_ec_lpc_ops.read(ec_lpc->mmio_memory_base + i, 1, s);
389+
ret = ec_lpc->read(ec_lpc, ec_lpc->mmio_memory_base + i, 1, s);
393390
if (ret < 0)
394391
return ret;
395392
cnt++;
@@ -492,8 +489,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
492489
}
493490

494491
if (quirks & CROS_EC_LPC_QUIRK_AML_MUTEX) {
495-
const char *name
496-
= driver_data->quirk_aml_mutex_name;
492+
const char *name = driver_data->quirk_aml_mutex_name;
497493
ret = cros_ec_lpc_mec_acpi_mutex(ACPI_COMPANION(dev), name);
498494
if (ret) {
499495
dev_err(dev, "failed to get AML mutex '%s'", name);
@@ -523,9 +519,9 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
523519
* protocol fails, fallback to the non MEC variant and try to
524520
* read again the ID.
525521
*/
526-
cros_ec_lpc_ops.read = cros_ec_lpc_mec_read_bytes;
527-
cros_ec_lpc_ops.write = cros_ec_lpc_mec_write_bytes;
528-
ret = cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, buf);
522+
ec_lpc->read = cros_ec_lpc_mec_read_bytes;
523+
ec_lpc->write = cros_ec_lpc_mec_write_bytes;
524+
ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, buf);
529525
if (ret < 0)
530526
return ret;
531527
if (buf[0] != 'E' || buf[1] != 'C') {
@@ -536,9 +532,9 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
536532
}
537533

538534
/* Re-assign read/write operations for the non MEC variant */
539-
cros_ec_lpc_ops.read = cros_ec_lpc_read_bytes;
540-
cros_ec_lpc_ops.write = cros_ec_lpc_write_bytes;
541-
ret = cros_ec_lpc_ops.read(ec_lpc->mmio_memory_base + EC_MEMMAP_ID, 2,
535+
ec_lpc->read = cros_ec_lpc_read_bytes;
536+
ec_lpc->write = cros_ec_lpc_write_bytes;
537+
ret = ec_lpc->read(ec_lpc, ec_lpc->mmio_memory_base + EC_MEMMAP_ID, 2,
542538
buf);
543539
if (ret < 0)
544540
return ret;

0 commit comments

Comments
 (0)