From 8bb2021d77c8ee213b53d671687b7a1179335522 Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Tue, 14 Jun 2011 01:35:36 +0000 Subject: Use shutdown callback mechanism to shutdown programmers This patch attempts to resolve some programmer shutdown ordering issues by having the programmer init functions register shutdown callbacks explicitly wherever it makes most sense. Before, assumptions were made that could lead to the internal programmer's state changing before the external programmer could be shut down properly. Now, each programmer cleans up after itself and (hopefully) performs each operation in the correct order. As a side-effect, this patch gives us a better usage model for reverse operations such as rpci_* and rmmio_*. In the long-run, this should make reversing the initialization process easier to understand, less tedious, and less error-prone. In short, this patch does the following: - Registers a shutdown callback during initialization for each programmer. - Kills the .shutdown function pointer from programmer_entry struct. Also, make most shutdown functions static. - Adds a few minor clean-ups and corrections (e.g. missing physunmap() calls). TODO: Remove forward declaration of serprog_shutdown() (added to simplify diff) Corresponding to flashrom svn r1338. Signed-off-by: David Hendricks Acked-by: Carl-Daniel Hailfinger --- dediprog.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'dediprog.c') diff --git a/dediprog.c b/dediprog.c index 1c54c66..1cbde18 100644 --- a/dediprog.c +++ b/dediprog.c @@ -536,6 +536,25 @@ static const struct spi_programmer spi_programmer_dediprog = { .write_256 = dediprog_spi_write_256, }; +static int dediprog_shutdown(void *data) +{ + msg_pspew("%s\n", __func__); + + /* URB 28. Command Set SPI Voltage to 0. */ + if (dediprog_set_spi_voltage(0x0)) + return 1; + + if (usb_release_interface(dediprog_handle, 0)) { + msg_perr("Could not release USB interface!\n"); + return 1; + } + if (usb_close(dediprog_handle)) { + msg_perr("Could not close USB device!\n"); + return 1; + } + return 0; +} + /* URB numbers refer to the first log ever captured. */ int dediprog_init(void) { @@ -587,6 +606,9 @@ int dediprog_init(void) } dediprog_endpoint = 2; + if (register_shutdown(dediprog_shutdown, NULL)) + return 1; + dediprog_set_leds(PASS_ON|BUSY_ON|ERROR_ON); /* URB 6. Command A. */ @@ -681,22 +703,3 @@ static int dediprog_do_stuff(void) return 0; } #endif - -int dediprog_shutdown(void) -{ - msg_pspew("%s\n", __func__); - - /* URB 28. Command Set SPI Voltage to 0. */ - if (dediprog_set_spi_voltage(0x0)) - return 1; - - if (usb_release_interface(dediprog_handle, 0)) { - msg_perr("Could not release USB interface!\n"); - return 1; - } - if (usb_close(dediprog_handle)) { - msg_perr("Could not close USB device!\n"); - return 1; - } - return 0; -} -- cgit v1.1