Skip to content

Commit 18ccecf

Browse files
Pavan Savoygregkh
authored andcommitted
drivers:misc: ti-st: flush UART upon fw failure
Upon failure to read firmware version from chip or upon failure in responses to firmware download the UART needs to be flushed of its existing buffers so that the UIM can restart UART properly. Signed-off-by: Pavan Savoy <pavan_savoy@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent bfb88d6 commit 18ccecf

1 file changed

Lines changed: 24 additions & 30 deletions

File tree

‎drivers/misc/ti-st/st_kim.c‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -469,37 +469,21 @@ long st_kim_start(void *kim_data)
469469
/* wait for ldisc to be installed */
470470
err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
471471
msecs_to_jiffies(LDISC_TIME));
472-
if (!err) { /* timeout */
473-
pr_err("line disc installation timed out ");
474-
kim_gdata->ldisc_install = 0;
475-
pr_info("ldisc_install = 0");
476-
sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
477-
NULL, "install");
478-
/* the following wait is never going to be completed,
479-
* since the ldisc was never installed, hence serving
480-
* as a mdelay of LDISC_TIME msecs */
481-
err = wait_for_completion_timeout
482-
(&kim_gdata->ldisc_installed,
483-
msecs_to_jiffies(LDISC_TIME));
484-
err = -ETIMEDOUT;
472+
if (!err) {
473+
/* ldisc installation timeout,
474+
* flush uart, power cycle BT_EN */
475+
pr_err("ldisc installation timeout");
476+
err = st_kim_stop(kim_gdata);
485477
continue;
486478
} else {
487479
/* ldisc installed now */
488-
pr_info(" line discipline installed ");
480+
pr_info("line discipline installed");
489481
err = download_firmware(kim_gdata);
490482
if (err != 0) {
483+
/* ldisc installed but fw download failed,
484+
* flush uart & power cycle BT_EN */
491485
pr_err("download firmware failed");
492-
kim_gdata->ldisc_install = 0;
493-
pr_info("ldisc_install = 0");
494-
sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
495-
NULL, "install");
496-
/* this wait might be completed, though in the
497-
* tty_close() since the ldisc is already
498-
* installed */
499-
err = wait_for_completion_timeout
500-
(&kim_gdata->ldisc_installed,
501-
msecs_to_jiffies(LDISC_TIME));
502-
err = -EINVAL;
486+
err = st_kim_stop(kim_gdata);
503487
continue;
504488
} else { /* on success don't retry */
505489
break;
@@ -510,21 +494,31 @@ long st_kim_start(void *kim_data)
510494
}
511495

512496
/**
513-
* st_kim_stop - called from ST Core, on the last un-registration
514-
* toggle low the chip enable gpio
497+
* st_kim_stop - stop communication with chip.
498+
* This can be called from ST Core/KIM, on the-
499+
* (a) last un-register when chip need not be powered there-after,
500+
* (b) upon failure to either install ldisc or download firmware.
501+
* The function is responsible to (a) notify UIM about un-installation,
502+
* (b) flush UART if the ldisc was installed.
503+
* (c) reset BT_EN - pull down nshutdown at the end.
504+
* (d) invoke platform's chip disabling routine.
515505
*/
516506
long st_kim_stop(void *kim_data)
517507
{
518508
long err = 0;
519509
struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
520510
struct ti_st_plat_data *pdata =
521511
kim_gdata->kim_pdev->dev.platform_data;
512+
struct tty_struct *tty = kim_gdata->core_data->tty;
522513

523514
INIT_COMPLETION(kim_gdata->ldisc_installed);
524515

525-
/* Flush any pending characters in the driver and discipline. */
526-
tty_ldisc_flush(kim_gdata->core_data->tty);
527-
tty_driver_flush_buffer(kim_gdata->core_data->tty);
516+
if (tty) { /* can be called before ldisc is installed */
517+
/* Flush any pending characters in the driver and discipline. */
518+
tty_ldisc_flush(tty);
519+
tty_driver_flush_buffer(tty);
520+
tty->ops->flush_buffer(tty);
521+
}
528522

529523
/* send uninstall notification to UIM */
530524
pr_info("ldisc_install = 0");

0 commit comments

Comments
 (0)