|
15 | 15 | #include <linux/module.h>
|
16 | 16 | #include <linux/pci.h>
|
17 | 17 | #include <linux/ioport.h>
|
| 18 | +#include <linux/iopoll.h> |
18 | 19 | #include <linux/scatterlist.h>
|
19 | 20 |
|
20 | 21 | #include <pcmcia/cistpl.h>
|
@@ -59,7 +60,7 @@ static unsigned int switchlocked;
|
59 | 60 |
|
60 | 61 | /* timeouts */
|
61 | 62 | #define CMD_TIMEOUT 100000
|
62 |
| -#define TRANSFER_TIMEOUT 100000 |
| 63 | +#define SDRICOH_DATA_TIMEOUT_US 1000000 |
63 | 64 |
|
64 | 65 | /* list of supported pcmcia devices */
|
65 | 66 | static const struct pcmcia_device_id pcmcia_ids[] = {
|
@@ -123,21 +124,24 @@ static inline unsigned int sdricoh_readb(struct sdricoh_host *host,
|
123 | 124 | return value;
|
124 | 125 | }
|
125 | 126 |
|
| 127 | +static bool sdricoh_status_ok(struct sdricoh_host *host, unsigned int status, |
| 128 | + unsigned int wanted) |
| 129 | +{ |
| 130 | + sdricoh_writel(host, R2E4_STATUS_RESP, status); |
| 131 | + return status & wanted; |
| 132 | +} |
| 133 | + |
126 | 134 | static int sdricoh_query_status(struct sdricoh_host *host, unsigned int wanted)
|
127 | 135 | {
|
128 |
| - unsigned int loop; |
| 136 | + int ret; |
129 | 137 | unsigned int status = 0;
|
130 |
| - unsigned int timeout = TRANSFER_TIMEOUT; |
131 | 138 | struct device *dev = host->dev;
|
132 | 139 |
|
133 |
| - for (loop = 0; loop < timeout; loop++) { |
134 |
| - status = sdricoh_readl(host, R21C_STATUS); |
135 |
| - sdricoh_writel(host, R2E4_STATUS_RESP, status); |
136 |
| - if (status & wanted) |
137 |
| - break; |
138 |
| - } |
139 |
| - |
140 |
| - if (loop == timeout) { |
| 140 | + ret = read_poll_timeout(sdricoh_readl, status, |
| 141 | + sdricoh_status_ok(host, status, wanted), |
| 142 | + 32, SDRICOH_DATA_TIMEOUT_US, false, |
| 143 | + host, R21C_STATUS); |
| 144 | + if (ret) { |
141 | 145 | dev_err(dev, "query_status: timeout waiting for %x\n", wanted);
|
142 | 146 | return -ETIMEDOUT;
|
143 | 147 | }
|
|
0 commit comments