Skip to content

Commit e19ceeb

Browse files
author
Tzung-Bi Shih
committed
platform/chrome: Centralize common cros_ec_device initialization
Move the common initialization from protocol device drivers into central cros_ec_device_alloc(). This removes duplicated code from each driver's probe function. The buffer sizes are now calculated once, using the maximum possible overhead required by any of the transport protocols, ensuring the allocated buffers are sufficient for all cases. Link: https://lore.kernel.org/r/20250828083601.856083-3-tzungbi@kernel.org Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
1 parent 9188569 commit e19ceeb

8 files changed

Lines changed: 19 additions & 30 deletions

File tree

drivers/platform/chrome/cros_ec.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ struct cros_ec_device *cros_ec_device_alloc(struct device *dev)
3838
if (!ec_dev)
3939
return NULL;
4040

41+
ec_dev->din_size = sizeof(struct ec_host_response) +
42+
sizeof(struct ec_response_get_protocol_info) +
43+
EC_MAX_RESPONSE_OVERHEAD;
44+
ec_dev->dout_size = sizeof(struct ec_host_request) +
45+
sizeof(struct ec_params_rwsig_action) +
46+
EC_MAX_REQUEST_OVERHEAD;
47+
48+
ec_dev->dev = dev;
49+
4150
return ec_dev;
4251
}
4352
EXPORT_SYMBOL(cros_ec_device_alloc);

drivers/platform/chrome/cros_ec_i2c.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,11 @@ static int cros_ec_i2c_probe(struct i2c_client *client)
297297
return -ENOMEM;
298298

299299
i2c_set_clientdata(client, ec_dev);
300-
ec_dev->dev = dev;
301300
ec_dev->priv = client;
302301
ec_dev->irq = client->irq;
303302
ec_dev->cmd_xfer = cros_ec_cmd_xfer_i2c;
304303
ec_dev->pkt_xfer = cros_ec_pkt_xfer_i2c;
305304
ec_dev->phys_name = client->adapter->name;
306-
ec_dev->din_size = sizeof(struct ec_host_response_i2c) +
307-
sizeof(struct ec_response_get_protocol_info);
308-
ec_dev->dout_size = sizeof(struct ec_host_request_i2c) +
309-
sizeof(struct ec_params_rwsig_action);
310305

311306
err = cros_ec_register(ec_dev);
312307
if (err) {

drivers/platform/chrome/cros_ec_ishtp.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,10 @@ static int cros_ec_dev_init(struct ishtp_cl_data *client_data)
550550
client_data->ec_dev = ec_dev;
551551
dev->driver_data = ec_dev;
552552

553-
ec_dev->dev = dev;
554553
ec_dev->priv = client_data->cros_ish_cl;
555554
ec_dev->cmd_xfer = NULL;
556555
ec_dev->pkt_xfer = cros_ec_pkt_xfer_ish;
557556
ec_dev->phys_name = dev_name(dev);
558-
ec_dev->din_size = sizeof(struct cros_ish_in_msg) +
559-
sizeof(struct ec_response_get_protocol_info);
560-
ec_dev->dout_size = sizeof(struct cros_ish_out_msg) + sizeof(struct ec_params_rwsig_action);
561557

562558
return cros_ec_register(ec_dev);
563559
}

drivers/platform/chrome/cros_ec_lpc.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,10 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
642642
return -ENOMEM;
643643

644644
platform_set_drvdata(pdev, ec_dev);
645-
ec_dev->dev = dev;
646645
ec_dev->phys_name = dev_name(dev);
647646
ec_dev->cmd_xfer = cros_ec_cmd_xfer_lpc;
648647
ec_dev->pkt_xfer = cros_ec_pkt_xfer_lpc;
649648
ec_dev->cmd_readmem = cros_ec_lpc_readmem;
650-
ec_dev->din_size = sizeof(struct ec_host_response) +
651-
sizeof(struct ec_response_get_protocol_info);
652-
ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action);
653649
ec_dev->priv = ec_lpc;
654650

655651
/*

drivers/platform/chrome/cros_ec_rpmsg.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,10 @@ static int cros_ec_rpmsg_probe(struct rpmsg_device *rpdev)
224224
if (!ec_rpmsg)
225225
return -ENOMEM;
226226

227-
ec_dev->dev = dev;
228227
ec_dev->priv = ec_rpmsg;
229228
ec_dev->cmd_xfer = cros_ec_cmd_xfer_rpmsg;
230229
ec_dev->pkt_xfer = cros_ec_pkt_xfer_rpmsg;
231230
ec_dev->phys_name = dev_name(&rpdev->dev);
232-
ec_dev->din_size = sizeof(struct ec_host_response) +
233-
sizeof(struct ec_response_get_protocol_info);
234-
ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action);
235231
dev_set_drvdata(dev, ec_dev);
236232

237233
ec_rpmsg->rpdev = rpdev;

drivers/platform/chrome/cros_ec_spi.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,11 @@ static int cros_ec_spi_probe(struct spi_device *spi)
757757
cros_ec_spi_dt_probe(ec_spi, dev);
758758

759759
spi_set_drvdata(spi, ec_dev);
760-
ec_dev->dev = dev;
761760
ec_dev->priv = ec_spi;
762761
ec_dev->irq = spi->irq;
763762
ec_dev->cmd_xfer = cros_ec_cmd_xfer_spi;
764763
ec_dev->pkt_xfer = cros_ec_pkt_xfer_spi;
765764
ec_dev->phys_name = dev_name(&ec_spi->spi->dev);
766-
ec_dev->din_size = EC_MSG_PREAMBLE_COUNT +
767-
sizeof(struct ec_host_response) +
768-
sizeof(struct ec_response_get_protocol_info);
769-
ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action);
770765

771766
ec_spi->last_transfer_ns = ktime_get_ns();
772767

drivers/platform/chrome/cros_ec_uart.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,10 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
276276

277277
/* Initialize ec_dev for cros_ec */
278278
ec_dev->phys_name = dev_name(dev);
279-
ec_dev->dev = dev;
280279
ec_dev->priv = ec_uart;
281280
ec_dev->irq = ec_uart->irq;
282281
ec_dev->cmd_xfer = NULL;
283282
ec_dev->pkt_xfer = cros_ec_uart_pkt_xfer;
284-
ec_dev->din_size = sizeof(struct ec_host_response) +
285-
sizeof(struct ec_response_get_protocol_info);
286-
ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action);
287283

288284
serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops);
289285

include/linux/platform_data/cros_ec_proto.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@
3333

3434
/*
3535
* Max bus-specific overhead incurred by request/responses.
36-
* I2C requires 1 additional byte for requests.
37-
* I2C requires 2 additional bytes for responses.
38-
* SPI requires up to 32 additional bytes for responses.
36+
*
37+
* Request:
38+
* - I2C requires 1 byte (see struct ec_host_request_i2c).
39+
* - ISHTP requires 4 bytes (see struct cros_ish_out_msg).
40+
*
41+
* Response:
42+
* - I2C requires 2 bytes (see struct ec_host_response_i2c).
43+
* - ISHTP requires 4 bytes (see struct cros_ish_in_msg).
44+
* - SPI requires 32 bytes (see EC_MSG_PREAMBLE_COUNT).
3945
*/
4046
#define EC_PROTO_VERSION_UNKNOWN 0
41-
#define EC_MAX_REQUEST_OVERHEAD 1
47+
#define EC_MAX_REQUEST_OVERHEAD 4
4248
#define EC_MAX_RESPONSE_OVERHEAD 32
4349

4450
/*

0 commit comments

Comments
 (0)