Skip to content

Commit 42a244b

Browse files
EvenxfJiri Kosina
authored andcommitted
platform/chrome: cros_ec_ishtp: use helper functions for connection
Use helper functions ishtp_cl_establish_connection() and ishtp_cl_destroy_connection() to establish and destroy connection respectively. These functions are used during initialization, reset and deinitialization flows. No functional changes are expected. Signed-off-by: Even Xu <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Acked-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 09b57d9 commit 42a244b

File tree

1 file changed

+15
-59
lines changed

1 file changed

+15
-59
lines changed

drivers/platform/chrome/cros_ec_ishtp.c

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -367,55 +367,33 @@ static void ish_event_cb(struct ishtp_cl_device *cl_device)
367367
/**
368368
* cros_ish_init() - Init function for ISHTP client
369369
* @cros_ish_cl: ISHTP client instance
370+
* @reset: true if called from reset handler
370371
*
371372
* This function complete the initializtion of the client.
372373
*
373374
* Return: 0 for success, negative error code for failure.
374375
*/
375-
static int cros_ish_init(struct ishtp_cl *cros_ish_cl)
376+
static int cros_ish_init(struct ishtp_cl *cros_ish_cl, bool reset)
376377
{
377378
int rv;
378-
struct ishtp_device *dev;
379-
struct ishtp_fw_client *fw_client;
380379
struct ishtp_cl_data *client_data = ishtp_get_client_data(cros_ish_cl);
381380

382-
rv = ishtp_cl_link(cros_ish_cl);
383-
if (rv) {
384-
dev_err(cl_data_to_dev(client_data),
385-
"ishtp_cl_link failed\n");
386-
return rv;
387-
}
388-
389-
dev = ishtp_get_ishtp_device(cros_ish_cl);
390-
391-
/* Connect to firmware client */
392-
ishtp_set_tx_ring_size(cros_ish_cl, CROS_ISH_CL_TX_RING_SIZE);
393-
ishtp_set_rx_ring_size(cros_ish_cl, CROS_ISH_CL_RX_RING_SIZE);
394-
395-
fw_client = ishtp_fw_cl_get_client(dev, &cros_ec_ishtp_id_table[0].guid);
396-
if (!fw_client) {
397-
dev_err(cl_data_to_dev(client_data),
398-
"ish client uuid not found\n");
399-
rv = -ENOENT;
400-
goto err_cl_unlink;
401-
}
402-
403-
ishtp_cl_set_fw_client_id(cros_ish_cl,
404-
ishtp_get_fw_client_id(fw_client));
405-
ishtp_set_connection_state(cros_ish_cl, ISHTP_CL_CONNECTING);
406-
407-
rv = ishtp_cl_connect(cros_ish_cl);
381+
rv = ishtp_cl_establish_connection(cros_ish_cl,
382+
&cros_ec_ishtp_id_table[0].guid,
383+
CROS_ISH_CL_TX_RING_SIZE,
384+
CROS_ISH_CL_RX_RING_SIZE,
385+
reset);
408386
if (rv) {
409387
dev_err(cl_data_to_dev(client_data),
410388
"client connect fail\n");
411-
goto err_cl_unlink;
389+
goto err_cl_disconnect;
412390
}
413391

414392
ishtp_register_event_cb(client_data->cl_device, ish_event_cb);
415393
return 0;
416394

417-
err_cl_unlink:
418-
ishtp_cl_unlink(cros_ish_cl);
395+
err_cl_disconnect:
396+
ishtp_cl_destroy_connection(cros_ish_cl, reset);
419397
return rv;
420398
}
421399

@@ -427,10 +405,7 @@ static int cros_ish_init(struct ishtp_cl *cros_ish_cl)
427405
*/
428406
static void cros_ish_deinit(struct ishtp_cl *cros_ish_cl)
429407
{
430-
ishtp_set_connection_state(cros_ish_cl, ISHTP_CL_DISCONNECTING);
431-
ishtp_cl_disconnect(cros_ish_cl);
432-
ishtp_cl_unlink(cros_ish_cl);
433-
ishtp_cl_flush_queues(cros_ish_cl);
408+
ishtp_cl_destroy_connection(cros_ish_cl, false);
434409

435410
/* Disband and free all Tx and Rx client-level rings */
436411
ishtp_cl_free(cros_ish_cl);
@@ -592,34 +567,18 @@ static void reset_handler(struct work_struct *work)
592567
int rv;
593568
struct device *dev;
594569
struct ishtp_cl *cros_ish_cl;
595-
struct ishtp_cl_device *cl_device;
596570
struct ishtp_cl_data *client_data =
597571
container_of(work, struct ishtp_cl_data, work_ishtp_reset);
598572

599573
/* Lock for reset to complete */
600574
down_write(&init_lock);
601575

602576
cros_ish_cl = client_data->cros_ish_cl;
603-
cl_device = client_data->cl_device;
604577

605-
/* Unlink, flush queues & start again */
606-
ishtp_cl_unlink(cros_ish_cl);
607-
ishtp_cl_flush_queues(cros_ish_cl);
608-
ishtp_cl_free(cros_ish_cl);
609-
610-
cros_ish_cl = ishtp_cl_allocate(cl_device);
611-
if (!cros_ish_cl) {
612-
up_write(&init_lock);
613-
return;
614-
}
615-
616-
ishtp_set_drvdata(cl_device, cros_ish_cl);
617-
ishtp_set_client_data(cros_ish_cl, client_data);
618-
client_data->cros_ish_cl = cros_ish_cl;
578+
ishtp_cl_destroy_connection(cros_ish_cl, true);
619579

620-
rv = cros_ish_init(cros_ish_cl);
580+
rv = cros_ish_init(cros_ish_cl, true);
621581
if (rv) {
622-
ishtp_cl_free(cros_ish_cl);
623582
dev_err(cl_data_to_dev(client_data), "Reset Failed\n");
624583
up_write(&init_lock);
625584
return;
@@ -672,7 +631,7 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device)
672631
INIT_WORK(&client_data->work_ec_evt,
673632
ish_evt_handler);
674633

675-
rv = cros_ish_init(cros_ish_cl);
634+
rv = cros_ish_init(cros_ish_cl, false);
676635
if (rv)
677636
goto end_ishtp_cl_init_error;
678637

@@ -690,10 +649,7 @@ static int cros_ec_ishtp_probe(struct ishtp_cl_device *cl_device)
690649
return 0;
691650

692651
end_cros_ec_dev_init_error:
693-
ishtp_set_connection_state(cros_ish_cl, ISHTP_CL_DISCONNECTING);
694-
ishtp_cl_disconnect(cros_ish_cl);
695-
ishtp_cl_unlink(cros_ish_cl);
696-
ishtp_cl_flush_queues(cros_ish_cl);
652+
ishtp_cl_destroy_connection(cros_ish_cl, false);
697653
ishtp_put_device(cl_device);
698654
end_ishtp_cl_init_error:
699655
ishtp_cl_free(cros_ish_cl);

0 commit comments

Comments
 (0)