diff options
author | Oliver O'Halloran <oohall@gmail.com> | 2019-03-26 19:18:17 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.ibm.com> | 2019-03-28 15:24:13 +1100 |
commit | d290b244efbc03c9a89e858a57b7a91186dcf364 (patch) | |
tree | 2dc85fee566e99f5e5ab1580e7346cc5e2627f15 /core/i2c.c | |
parent | a31085d7d432c889e2e5ddcef55ea866797dace8 (diff) | |
download | skiboot-d290b244efbc03c9a89e858a57b7a91186dcf364.zip skiboot-d290b244efbc03c9a89e858a57b7a91186dcf364.tar.gz skiboot-d290b244efbc03c9a89e858a57b7a91186dcf364.tar.bz2 |
core/i2c: Poll on request state in i2c_request_send()
Use the new built-in state variable rather than a single-use completion
function. Makes things a bit cleaner.
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
Diffstat (limited to 'core/i2c.c')
-rw-r--r-- | core/i2c.c | 26 |
1 files changed, 4 insertions, 22 deletions
@@ -140,20 +140,6 @@ opal_call(OPAL_I2C_REQUEST, opal_i2c_request, 3); #define MAX_NACK_RETRIES 2 #define REQ_COMPLETE_POLLING 5 /* Check if req is complete in 5ms interval */ - -struct i2c_sync_userdata { - int rc; - bool done; -}; - -static void i2c_sync_request_complete(int rc, struct i2c_request *req) -{ - struct i2c_sync_userdata *ud = req->user_data; - ud->rc = rc; - lwsync(); - ud->done = true; -} - /** * i2c_request_send - send request to i2c bus synchronously * @bus_id: i2c bus id @@ -177,7 +163,6 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, struct i2c_request *req; struct i2c_bus *bus; uint64_t time_to_wait = 0; - struct i2c_sync_userdata ud; uint64_t timer_period = msecs_to_tb(5), timer_count; bus = i2c_find_bus_by_id(bus_id); @@ -210,10 +195,7 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, req->offset_bytes = offset_bytes; req->rw_buf = (void*) buf; req->rw_len = buflen; - req->completion = i2c_sync_request_complete; req->timeout = timeout; - ud.done = false; - req->user_data = &ud; for (retries = 0; retries <= MAX_NACK_RETRIES; retries++) { waited = 0; @@ -240,15 +222,15 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, check_timers(false); timer_count = 0; } - } while (!ud.done); + } while (req->req_state != i2c_req_done); lwsync(); - rc = ud.rc; + rc = req->result; - /* error or success */ + /* retry on NACK, otherwise exit */ if (rc != OPAL_I2C_NACK_RCVD) break; - ud.done = false; + req->req_state = i2c_req_new; } prlog(PR_DEBUG, "I2C: %s req op=%x offset=%x buf=%016llx buflen=%d " |