Alexander Goncharov has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/72154 )
Change subject: ni845x_spi: pass global state through func params ......................................................................
ni845x_spi: pass global state through func params
TODO: desc
TOPIC=register_master_api
Change-Id: I5daeb0839a4cc18b82d38cc06eeba88a619bec61 Signed-off-by: Alexander Goncharov chat@joursoir.net --- M ni845x_spi.c 1 file changed, 26 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/54/72154/1
diff --git a/ni845x_spi.c b/ni845x_spi.c index fd5057d..493e8a1 100644 --- a/ni845x_spi.c +++ b/ni845x_spi.c @@ -128,7 +128,8 @@ * @param opened_handle the opened handle from the ni845xOpen * @return the 0 on successful competition, negative error code on failure positive code on warning */ -static int32 ni845x_spi_open_resource(char *resource_handle, uInt32 *opened_handle) +static int32 ni845x_spi_open_resource(char *resource_handle, uInt32 *opened_handle, + enum USB845x_type device_pid) { // NI-845x driver loads the FPGA bitfile at the first time // which can take couple seconds @@ -148,7 +149,8 @@ * @param serial a null terminated string containing the serial number of the specific device or NULL * @return the 0 on successful completion, negative error code on failure */ -static int ni845x_spi_open(const char *serial, uInt32 *return_handle) +static int ni845x_spi_open(const char *serial, uInt32 *return_handle, + enum USB845x_type *device_pid) { char resource_name[256]; NiHandle device_find_handle; @@ -183,7 +185,7 @@ continue; }
- device_pid = pid; + *device_pid = pid;
if (!serial || strtol(serial, NULL, 16) == serial_as_number) break; @@ -198,7 +200,7 @@ }
if (found_devices_count) - ret = ni845x_spi_open_resource(resource_name, return_handle); + ret = ni845x_spi_open_resource(resource_name, return_handle, *device_pid);
_close_ret: tmp = ni845xCloseFindDeviceHandle(device_find_handle); @@ -220,14 +222,15 @@ */ static int usb8452_spi_set_io_voltage(uint16_t requested_io_voltage_mV, uint16_t *set_io_voltage_mV, - enum voltage_coerce_mode coerce_mode) + enum voltage_coerce_mode coerce_mode, + enum USB845x_type device_pid) { int i = 0; uint8_t selected_voltage_100mV = 0; uint8_t requested_io_voltage_100mV = 0;
if (device_pid == USB8451) { - io_voltage_in_mV = 3300; + *set_io_voltage_mV = 3300; msg_pwarn("USB-8451 does not support the changing of the SPI IO voltage\n"); return 0; } @@ -300,7 +303,7 @@ * @param SCK_freq_in_KHz SCK speed in KHz * @return */ -static int ni845x_spi_set_speed(uint16_t SCK_freq_in_KHz) +static int ni845x_spi_set_speed(NiHandle configuration_handle, uint16_t SCK_freq_in_KHz) { int32 i = ni845xSpiConfigurationSetClockRate(configuration_handle, SCK_freq_in_KHz); uInt16 clock_freq_read_KHz; @@ -591,7 +594,7 @@ ignore_io_voltage_limits = true; }
- if (ni845x_spi_open(serial_number, &device_handle)) { + if (ni845x_spi_open(serial_number, &device_handle, &device_pid)) { if (serial_number) { msg_pinfo("Could not find any connected NI USB-8451/8452 with serialnumber: %s!\n", serial_number); @@ -620,7 +623,7 @@ return 1; // no alert here usb8452_spi_set_io_voltage already printed that }
- if (ni845x_spi_set_speed(spi_speed_KHz)) { + if (ni845x_spi_set_speed(configuration_handle, spi_speed_KHz)) { msg_perr("Unable to set SPI speed\n"); ni845x_spi_shutdown(NULL); return 1;