Lines Matching refs:tu
59 struct testunit_data *tu = i2c_get_clientdata(client); in i2c_slave_testunit_smbalert_cb() local
63 gpiod_set_value(tu->gpio, 0); in i2c_slave_testunit_smbalert_cb()
66 *val = tu->regs[TU_REG_DATAL]; in i2c_slave_testunit_smbalert_cb()
70 complete(&tu->alert_done); in i2c_slave_testunit_smbalert_cb()
84 struct testunit_data *tu = i2c_get_clientdata(client); in i2c_slave_testunit_slave_cb() local
85 bool is_proc_call = tu->reg_idx == 3 && tu->regs[TU_REG_DATAL] == 1 && in i2c_slave_testunit_slave_cb()
86 tu->regs[TU_REG_CMD] == TU_CMD_SMBUS_BLOCK_PROC_CALL; in i2c_slave_testunit_slave_cb()
87 bool is_get_version = tu->reg_idx == 3 && in i2c_slave_testunit_slave_cb()
88 tu->regs[TU_REG_CMD] == TU_CMD_GET_VERSION_WITH_REP_START; in i2c_slave_testunit_slave_cb()
93 if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) in i2c_slave_testunit_slave_cb()
96 memset(tu->regs, 0, TU_NUM_REGS); in i2c_slave_testunit_slave_cb()
97 tu->reg_idx = 0; in i2c_slave_testunit_slave_cb()
98 tu->read_idx = 0; in i2c_slave_testunit_slave_cb()
102 if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags)) in i2c_slave_testunit_slave_cb()
105 if (tu->reg_idx < TU_NUM_REGS) in i2c_slave_testunit_slave_cb()
106 tu->regs[tu->reg_idx] = *val; in i2c_slave_testunit_slave_cb()
110 if (tu->reg_idx <= TU_NUM_REGS) in i2c_slave_testunit_slave_cb()
111 tu->reg_idx++; in i2c_slave_testunit_slave_cb()
114 if (tu->regs[TU_REG_CMD] >= TU_NUM_CMDS) in i2c_slave_testunit_slave_cb()
120 if (tu->reg_idx == TU_NUM_REGS) { in i2c_slave_testunit_slave_cb()
121 set_bit(TU_FLAG_IN_PROCESS, &tu->flags); in i2c_slave_testunit_slave_cb()
122 queue_delayed_work(system_long_wq, &tu->worker, in i2c_slave_testunit_slave_cb()
123 msecs_to_jiffies(10 * tu->regs[TU_REG_DELAY])); in i2c_slave_testunit_slave_cb()
131 tu->reg_idx = 0; in i2c_slave_testunit_slave_cb()
136 if (is_get_version && tu_version_info[tu->read_idx] != 0) in i2c_slave_testunit_slave_cb()
137 tu->read_idx++; in i2c_slave_testunit_slave_cb()
138 else if (is_proc_call && tu->regs[TU_REG_DATAH]) in i2c_slave_testunit_slave_cb()
139 tu->regs[TU_REG_DATAH]--; in i2c_slave_testunit_slave_cb()
145 *val = tu_version_info[tu->read_idx]; in i2c_slave_testunit_slave_cb()
147 *val = tu->regs[TU_REG_DATAH]; in i2c_slave_testunit_slave_cb()
149 *val = test_bit(TU_FLAG_IN_PROCESS, &tu->flags) ? in i2c_slave_testunit_slave_cb()
150 tu->regs[TU_REG_CMD] : 0; in i2c_slave_testunit_slave_cb()
159 struct testunit_data *tu = container_of(work, struct testunit_data, worker.work); in i2c_slave_testunit_work() local
169 switch (tu->regs[TU_REG_CMD]) { in i2c_slave_testunit_work()
171 msg.addr = tu->regs[TU_REG_DATAL]; in i2c_slave_testunit_work()
173 msg.len = tu->regs[TU_REG_DATAH]; in i2c_slave_testunit_work()
180 msgbuf[0] = tu->client->addr; in i2c_slave_testunit_work()
181 msgbuf[1] = tu->regs[TU_REG_DATAL]; in i2c_slave_testunit_work()
182 msgbuf[2] = tu->regs[TU_REG_DATAH]; in i2c_slave_testunit_work()
186 i2c_slave_unregister(tu->client); in i2c_slave_testunit_work()
187 orig_addr = tu->client->addr; in i2c_slave_testunit_work()
188 tu->client->addr = 0x0c; in i2c_slave_testunit_work()
189 ret = i2c_slave_register(tu->client, i2c_slave_testunit_smbalert_cb); in i2c_slave_testunit_work()
193 reinit_completion(&tu->alert_done); in i2c_slave_testunit_work()
194 gpiod_set_value(tu->gpio, 1); in i2c_slave_testunit_work()
195 time_left = wait_for_completion_timeout(&tu->alert_done, HZ); in i2c_slave_testunit_work()
199 i2c_slave_unregister(tu->client); in i2c_slave_testunit_work()
201 tu->client->addr = orig_addr; in i2c_slave_testunit_work()
202 i2c_slave_register(tu->client, i2c_slave_testunit_slave_cb); in i2c_slave_testunit_work()
210 ret = i2c_transfer(tu->client->adapter, &msg, 1); in i2c_slave_testunit_work()
216 dev_err(&tu->client->dev, "CMD%02X failed (%d)\n", tu->regs[TU_REG_CMD], ret); in i2c_slave_testunit_work()
218 clear_bit(TU_FLAG_IN_PROCESS, &tu->flags); in i2c_slave_testunit_work()
223 struct testunit_data *tu; in i2c_slave_testunit_probe() local
225 tu = devm_kzalloc(&client->dev, sizeof(struct testunit_data), GFP_KERNEL); in i2c_slave_testunit_probe()
226 if (!tu) in i2c_slave_testunit_probe()
229 tu->client = client; in i2c_slave_testunit_probe()
230 i2c_set_clientdata(client, tu); in i2c_slave_testunit_probe()
231 init_completion(&tu->alert_done); in i2c_slave_testunit_probe()
232 INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work); in i2c_slave_testunit_probe()
234 tu->gpio = devm_gpiod_get_index_optional(&client->dev, NULL, 0, GPIOD_OUT_LOW); in i2c_slave_testunit_probe()
235 if (gpiod_cansleep(tu->gpio)) { in i2c_slave_testunit_probe()
248 struct testunit_data *tu = i2c_get_clientdata(client); in i2c_slave_testunit_remove() local
250 cancel_delayed_work_sync(&tu->worker); in i2c_slave_testunit_remove()