device: Invoke device->close on exit

Allow the control device to implement things such as flushing the
command buffer as part of the close operation. This used to be done to
ensure that any lingering power/usb off requests really where sent to
the device as we closed the control tty.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson
2021-01-25 18:48:04 -06:00
parent 2ab5051cde
commit c43466a98f
5 changed files with 9 additions and 2 deletions

View File

@@ -293,8 +293,10 @@ void *cdb_assist_open(struct device *dev)
return cdb;
}
void cdb_assist_close(struct cdb_assist *cdb)
void cdb_assist_close(struct device *dev)
{
struct cdb_assist *cdb = dev->cdb;
tcflush(cdb->control_tty, TCIFLUSH);
close(cdb->control_tty);

View File

@@ -8,7 +8,7 @@
struct cdb_assist;
void *cdb_assist_open(struct device *dev);
void cdb_assist_close(struct cdb_assist *cdb);
void cdb_assist_close(struct device *dev);
int cdb_assist_power(struct device *dev, bool on);
void cdb_assist_usb(struct device *dev, bool on);

View File

@@ -311,4 +311,7 @@ void device_close(struct device *dev)
{
device_usb(dev, false);
device_power(dev, false);
if (dev->close)
dev->close(dev);
}

View File

@@ -26,6 +26,7 @@ struct device {
void (*boot)(struct device *);
void *(*open)(struct device *dev);
void (*close)(struct device *dev);
int (*power)(struct device *dev, bool on);
void (*usb)(struct device *dev, bool on);
void (*print_status)(struct device *dev);

View File

@@ -99,6 +99,7 @@ static void parse_board(struct device_parser *dp)
dev->control_dev = strdup(value);
dev->open = cdb_assist_open;
dev->close = cdb_assist_close;
dev->power = cdb_assist_power;
dev->print_status = cdb_assist_print_status;
dev->usb = cdb_assist_usb;