Lines Matching +full:i3c +full:- +full:hci

1 // SPDX-License-Identifier: BSD-3-Clause
7 * I3C HCI v2.0 Command Descriptor Handling
9 * Note: The I3C HCI v2.0 spec is still in flux. The code here will change.
13 #include <linux/i3c/master.h>
15 #include "hci.h"
66 static unsigned int get_i3c_rate_idx(struct i3c_hci *hci) in get_i3c_rate_idx() argument
68 struct i3c_bus *bus = i3c_master_get_bus(&hci->master); in get_i3c_rate_idx()
70 if (bus->scl_rate.i3c >= 12000000) in get_i3c_rate_idx()
72 if (bus->scl_rate.i3c > 8000000) in get_i3c_rate_idx()
74 if (bus->scl_rate.i3c > 6000000) in get_i3c_rate_idx()
76 if (bus->scl_rate.i3c > 4000000) in get_i3c_rate_idx()
78 if (bus->scl_rate.i3c > 2000000) in get_i3c_rate_idx()
83 static unsigned int get_i2c_rate_idx(struct i3c_hci *hci) in get_i2c_rate_idx() argument
85 struct i3c_bus *bus = i3c_master_get_bus(&hci->master); in get_i2c_rate_idx()
87 if (bus->scl_rate.i2c >= 1000000) in get_i2c_rate_idx()
92 static void hci_cmd_v2_prep_private_xfer(struct i3c_hci *hci, in hci_cmd_v2_prep_private_xfer() argument
97 u8 *data = xfer->data; in hci_cmd_v2_prep_private_xfer()
98 unsigned int data_len = xfer->data_len; in hci_cmd_v2_prep_private_xfer()
99 bool rnw = xfer->rnw; in hci_cmd_v2_prep_private_xfer()
101 xfer->cmd_tid = hci_get_tid(); in hci_cmd_v2_prep_private_xfer()
104 xfer->cmd_desc[0] = in hci_cmd_v2_prep_private_xfer()
106 CMD_U0_TID(xfer->cmd_tid) | in hci_cmd_v2_prep_private_xfer()
111 xfer->cmd_desc[1] = in hci_cmd_v2_prep_private_xfer()
113 xfer->cmd_desc[2] = 0; in hci_cmd_v2_prep_private_xfer()
114 xfer->cmd_desc[3] = 0; in hci_cmd_v2_prep_private_xfer()
117 xfer->cmd_desc[3] |= CMD_U3_IDB4(data[4]); in hci_cmd_v2_prep_private_xfer()
120 xfer->cmd_desc[2] |= CMD_U2_IDB3(data[3]); in hci_cmd_v2_prep_private_xfer()
123 xfer->cmd_desc[2] |= CMD_U2_IDB2(data[2]); in hci_cmd_v2_prep_private_xfer()
126 xfer->cmd_desc[2] |= CMD_U2_IDB1(data[1]); in hci_cmd_v2_prep_private_xfer()
129 xfer->cmd_desc[2] |= CMD_U2_IDB0(data[0]); in hci_cmd_v2_prep_private_xfer()
135 xfer->data = NULL; in hci_cmd_v2_prep_private_xfer()
137 xfer->cmd_desc[0] = in hci_cmd_v2_prep_private_xfer()
139 CMD_U0_TID(xfer->cmd_tid) | in hci_cmd_v2_prep_private_xfer()
144 xfer->cmd_desc[1] = in hci_cmd_v2_prep_private_xfer()
146 xfer->cmd_desc[2] = 0; in hci_cmd_v2_prep_private_xfer()
147 xfer->cmd_desc[3] = 0; in hci_cmd_v2_prep_private_xfer()
151 static int hci_cmd_v2_prep_ccc(struct i3c_hci *hci, struct hci_xfer *xfer, in hci_cmd_v2_prep_ccc() argument
155 unsigned int rate = get_i3c_rate_idx(hci); in hci_cmd_v2_prep_ccc()
156 u8 *data = xfer->data; in hci_cmd_v2_prep_ccc()
157 unsigned int data_len = xfer->data_len; in hci_cmd_v2_prep_ccc()
158 bool rnw = xfer->rnw; in hci_cmd_v2_prep_ccc()
161 hci_cmd_v2_prep_private_xfer(hci, xfer, ccc_addr, mode, rate); in hci_cmd_v2_prep_ccc()
165 xfer->cmd_tid = hci_get_tid(); in hci_cmd_v2_prep_ccc()
168 xfer->cmd_desc[0] = in hci_cmd_v2_prep_ccc()
170 CMD_U0_TID(xfer->cmd_tid) | in hci_cmd_v2_prep_ccc()
175 xfer->cmd_desc[1] = in hci_cmd_v2_prep_ccc()
177 xfer->cmd_desc[2] = in hci_cmd_v2_prep_ccc()
179 xfer->cmd_desc[3] = 0; in hci_cmd_v2_prep_ccc()
182 xfer->cmd_desc[3] |= CMD_U3_IDB4(data[3]); in hci_cmd_v2_prep_ccc()
185 xfer->cmd_desc[2] |= CMD_U2_IDB3(data[2]); in hci_cmd_v2_prep_ccc()
188 xfer->cmd_desc[2] |= CMD_U2_IDB2(data[1]); in hci_cmd_v2_prep_ccc()
191 xfer->cmd_desc[2] |= CMD_U2_IDB1(data[0]); in hci_cmd_v2_prep_ccc()
197 xfer->data = NULL; in hci_cmd_v2_prep_ccc()
199 xfer->cmd_desc[0] = in hci_cmd_v2_prep_ccc()
201 CMD_U0_TID(xfer->cmd_tid) | in hci_cmd_v2_prep_ccc()
207 xfer->cmd_desc[1] = in hci_cmd_v2_prep_ccc()
209 xfer->cmd_desc[2] = in hci_cmd_v2_prep_ccc()
211 xfer->cmd_desc[3] = 0; in hci_cmd_v2_prep_ccc()
217 static void hci_cmd_v2_prep_i3c_xfer(struct i3c_hci *hci, in hci_cmd_v2_prep_i3c_xfer() argument
222 unsigned int rate = get_i3c_rate_idx(hci); in hci_cmd_v2_prep_i3c_xfer()
223 u8 addr = dev->info.dyn_addr; in hci_cmd_v2_prep_i3c_xfer()
225 hci_cmd_v2_prep_private_xfer(hci, xfer, addr, mode, rate); in hci_cmd_v2_prep_i3c_xfer()
228 static void hci_cmd_v2_prep_i2c_xfer(struct i3c_hci *hci, in hci_cmd_v2_prep_i2c_xfer() argument
233 unsigned int rate = get_i2c_rate_idx(hci); in hci_cmd_v2_prep_i2c_xfer()
234 u8 addr = dev->addr; in hci_cmd_v2_prep_i2c_xfer()
236 hci_cmd_v2_prep_private_xfer(hci, xfer, addr, mode, rate); in hci_cmd_v2_prep_i2c_xfer()
239 static int hci_cmd_v2_daa(struct i3c_hci *hci) in hci_cmd_v2_daa() argument
251 return -ENOMEM; in hci_cmd_v2_daa()
260 ret = i3c_master_get_free_addr(&hci->master, next_addr); in hci_cmd_v2_daa()
277 hci->io->queue_xfer(hci, xfer, 2); in hci_cmd_v2_daa()
279 hci->io->dequeue_xfer(hci, xfer, 2)) { in hci_cmd_v2_daa()
280 ret = -ETIME; in hci_cmd_v2_daa()
288 ret = -EIO; in hci_cmd_v2_daa()
302 ret = i3c_master_add_i3c_dev_locked(&hci->master, next_addr); in hci_cmd_v2_daa()