On Wed, Apr 11, 2018 at 1:38 PM Tomasz Figa <tfiga@xxxxxxxxxxxx> wrote: [snip] > > +static int dw9807_set_dac(struct i2c_client *client, u16 data) > > +{ > > + const char tx_data[3] = { > > + DW9807_MSB_ADDR, ((data >> 8) & 0x03), (data & 0xff) > > + }; > > + int ret, retry = 0; > > + > > + /* > > + * According to the datasheet, need to check the bus status > before we > > + * write VCM position. This ensure that we really write the value > > + * into the register > > + */ > > + while ((ret = dw9807_i2c_check(client)) != 0) { > > + if (ret < 0) > > + return ret; > > + > > + if (MAX_RETRY == ++retry) { > > + dev_err(&client->dev, > > + "Cannot do the write operation because > VCM is busy\n"); > > + return -EIO; > > + } > > + usleep_range(DW9807_CTRL_DELAY_US, DW9807_CTRL_DELAY_US + > 10); > > + } > One could use readx_poll_timeout() here: > int val; > ret = readx_poll_timeout(dw9807_i2c_check, client, val, !val, Actually, to handle errors, it should be ret = readx_poll_timeout(dw9807_i2c_check, client, val, val <= 0, > DW9807_CTRL_DELAY_US, > MAX_RETRY * DW9807_CTRL_DELAY_US); > if (ret) { if (ret || val < 0) { > dev_err(&client->dev, > "Cannot do the write operation because VCM is busy\n"); > return -EIO; return ret ? ret : val; Sorry for not spotting this earlier. Best regards, Tomasz