Lines Matching refs:dev
30 bool spi_is_bus_shared(struct spi_dev_ctx* dev) { in spi_is_bus_shared() argument
31 return dev->bus->num_devs > 1; in spi_is_bus_shared()
34 static inline bool spi_dev_seq_active(struct spi_dev_ctx* dev) { in spi_dev_seq_active() argument
35 return dev->cmds; in spi_dev_seq_active()
38 static void spi_req_exec_set_clk(struct spi_dev_ctx* dev, void* priv) { in spi_req_exec_set_clk() argument
42 int spi_req_set_clk(struct spi_dev_ctx* dev, uint64_t* clk_hz) { in spi_req_set_clk() argument
43 assert(dev); in spi_req_set_clk()
46 dev->cmds[dev->curr_cmd].exec = spi_req_exec_set_clk; in spi_req_set_clk()
47 dev->curr_cmd++; in spi_req_set_clk()
51 static void spi_req_exec_cs_assert(struct spi_dev_ctx* dev, void* priv) { in spi_req_exec_cs_assert() argument
52 assert(dev->bus->owner == NULL); in spi_req_exec_cs_assert()
54 dev->bus->owner = dev; in spi_req_exec_cs_assert()
57 int spi_req_cs_assert(struct spi_dev_ctx* dev) { in spi_req_cs_assert() argument
58 assert(spi_dev_seq_active(dev)); in spi_req_cs_assert()
59 assert(dev->curr_cmd < dev->num_cmds); in spi_req_cs_assert()
61 dev->cmds[dev->curr_cmd].exec = spi_req_exec_cs_assert; in spi_req_cs_assert()
62 dev->curr_cmd++; in spi_req_cs_assert()
66 static void spi_req_exec_cs_deassert(struct spi_dev_ctx* dev, void* priv) { in spi_req_exec_cs_deassert() argument
67 assert(dev->bus->owner == dev); in spi_req_exec_cs_deassert()
69 dev->bus->owner = NULL; in spi_req_exec_cs_deassert()
72 int spi_req_cs_deassert(struct spi_dev_ctx* dev) { in spi_req_cs_deassert() argument
73 assert(spi_dev_seq_active(dev)); in spi_req_cs_deassert()
74 assert(dev->curr_cmd < dev->num_cmds); in spi_req_cs_deassert()
76 dev->cmds[dev->curr_cmd].exec = spi_req_exec_cs_deassert; in spi_req_cs_deassert()
77 dev->curr_cmd++; in spi_req_cs_deassert()
114 static void spi_req_exec_xfer(struct spi_dev_ctx* dev, void* priv) { in spi_req_exec_xfer() argument
121 if (dev->loopback) { in spi_req_exec_xfer()
141 int spi_req_xfer(struct spi_dev_ctx* dev, void* tx, void* rx, size_t len) { in spi_req_xfer() argument
142 assert(spi_dev_seq_active(dev)); in spi_req_xfer()
143 assert(dev->curr_cmd < dev->num_cmds); in spi_req_xfer()
154 dev->cmds[dev->curr_cmd].exec = spi_req_exec_xfer; in spi_req_xfer()
155 dev->cmds[dev->curr_cmd].priv = args; in spi_req_xfer()
156 dev->curr_cmd++; in spi_req_xfer()
160 static void spi_req_exec_delay(struct spi_dev_ctx* dev, void* priv) { in spi_req_exec_delay() argument
165 int spi_req_delay(struct spi_dev_ctx* dev, uint64_t delay_ns) { in spi_req_delay() argument
166 assert(dev); in spi_req_delay()
175 dev->cmds[dev->curr_cmd].exec = spi_req_exec_delay; in spi_req_delay()
176 dev->cmds[dev->curr_cmd].priv = arg; in spi_req_delay()
177 dev->curr_cmd++; in spi_req_delay()
181 int spi_seq_begin(struct spi_dev_ctx* dev, size_t num_cmds) { in spi_seq_begin() argument
182 assert(!spi_dev_seq_active(dev)); in spi_seq_begin()
185 dev->cmds = calloc(num_cmds, sizeof(struct spi_seq_entry)); in spi_seq_begin()
186 if (!dev->cmds) { in spi_seq_begin()
191 dev->num_cmds = num_cmds; in spi_seq_begin()
195 static void spi_seq_free(struct spi_dev_ctx* dev) { in spi_seq_free() argument
196 for (size_t i = 0; i < dev->num_cmds; i++) { in spi_seq_free()
197 void* priv = dev->cmds[i].priv; in spi_seq_free()
202 free(dev->cmds); in spi_seq_free()
203 dev->cmds = NULL; in spi_seq_free()
204 dev->num_cmds = 0; in spi_seq_free()
205 dev->curr_cmd = 0; in spi_seq_free()
208 int spi_seq_commit(struct spi_dev_ctx* dev) { in spi_seq_commit() argument
212 assert(spi_dev_seq_active(dev)); in spi_seq_commit()
213 assert(dev->curr_cmd == dev->num_cmds); in spi_seq_commit()
216 for (i = 0; i < dev->num_cmds; i++) { in spi_seq_commit()
217 priv = dev->cmds[i].priv; in spi_seq_commit()
218 dev->cmds[i].exec(dev, priv); in spi_seq_commit()
221 spi_seq_free(dev); in spi_seq_commit()
225 void spi_seq_abort(struct spi_dev_ctx* dev) { in spi_seq_abort() argument
226 assert(spi_dev_seq_active(dev)); in spi_seq_abort()
227 spi_seq_free(dev); in spi_seq_abort()