Skip to content

Commit 16b7856

Browse files
lucaceresolimfischer
authored andcommitted
fpga manager: xilinx-spi: fix write_complete timeout handling
If this routine sleeps because it was scheduled out, it might miss DONE going asserted and consider it a timeout. This would potentially make the code return an error even when programming succeeded. Rewrite the loop to always check DONE after checking if timeout expired so this cannot happen anymore. While there, also add error checking for gpiod_get_value(). Also avoid checking the DONE GPIO in two places, which would make the error-checking code duplicated and more annoying. The new loop it written to still guarantee that we apply 8 extra CCLK cycles after DONE has gone asserted, which is required by the hardware. Reported-by: Tom Rix <trix@redhat.com> Reviewed-by: Tom Rix <trix@redhat.com> Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Moritz Fischer <mdf@kernel.org>
1 parent a44ecdc commit 16b7856

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎drivers/fpga/xilinx-spi.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,29 @@ static int xilinx_spi_write_complete(struct fpga_manager *mgr,
151151
struct fpga_image_info *info)
152152
{
153153
struct xilinx_spi_conf *conf = mgr->priv;
154-
unsigned long timeout;
154+
unsigned long timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us);
155+
bool expired = false;
156+
int done;
155157
int ret;
156158

157-
if (gpiod_get_value(conf->done))
158-
return xilinx_spi_apply_cclk_cycles(conf);
159+
/*
160+
* This loop is carefully written such that if the driver is
161+
* scheduled out for more than 'timeout', we still check for DONE
162+
* before giving up and we apply 8 extra CCLK cycles in all cases.
163+
*/
164+
while (!expired) {
165+
expired = time_after(jiffies, timeout);
159166

160-
timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us);
161-
162-
while (time_before(jiffies, timeout)) {
167+
done = get_done_gpio(mgr);
168+
if (done < 0)
169+
return done;
163170

164171
ret = xilinx_spi_apply_cclk_cycles(conf);
165172
if (ret)
166173
return ret;
167174

168-
if (gpiod_get_value(conf->done))
169-
return xilinx_spi_apply_cclk_cycles(conf);
175+
if (done)
176+
return 0;
170177
}
171178

172179
dev_err(&mgr->dev, "Timeout after config data transfer\n");

0 commit comments

Comments
 (0)