Lines Matching +full:byte +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0
21 * byte 0 0xda (EC_COMMAND_PROTOCOL_3)
22 * byte 1-8 struct ec_host_request
23 * byte 10- response data
34 * byte 0 result code
35 * byte 1 packet_length
36 * byte 2-9 struct ec_host_response
37 * byte 10- response data
55 struct i2c_client *client = ec_dev->priv; in cros_ec_pkt_xfer_i2c()
56 int ret = -ENOMEM; in cros_ec_pkt_xfer_i2c()
69 i2c_msg[0].addr = client->addr; in cros_ec_pkt_xfer_i2c()
71 i2c_msg[1].addr = client->addr; in cros_ec_pkt_xfer_i2c()
74 packet_len = msg->insize + response_header_size; in cros_ec_pkt_xfer_i2c()
75 if (packet_len > ec_dev->din_size) { in cros_ec_pkt_xfer_i2c()
76 ret = -EINVAL; in cros_ec_pkt_xfer_i2c()
79 in_buf = ec_dev->din; in cros_ec_pkt_xfer_i2c()
80 i2c_msg[1].len = packet_len; in cros_ec_pkt_xfer_i2c()
83 packet_len = msg->outsize + request_header_size; in cros_ec_pkt_xfer_i2c()
84 if (packet_len > ec_dev->dout_size) { in cros_ec_pkt_xfer_i2c()
85 ret = -EINVAL; in cros_ec_pkt_xfer_i2c()
88 out_buf = ec_dev->dout; in cros_ec_pkt_xfer_i2c()
89 i2c_msg[0].len = packet_len; in cros_ec_pkt_xfer_i2c()
94 ec_request_i2c->command_protocol = EC_COMMAND_PROTOCOL_3; in cros_ec_pkt_xfer_i2c()
96 ec_dev->dout++; in cros_ec_pkt_xfer_i2c()
100 ec_dev->dout--; in cros_ec_pkt_xfer_i2c()
103 ret = i2c_transfer(client->adapter, i2c_msg, 2); in cros_ec_pkt_xfer_i2c()
105 dev_dbg(ec_dev->dev, "i2c transfer failed: %d\n", ret); in cros_ec_pkt_xfer_i2c()
108 dev_err(ec_dev->dev, "failed to get response: %d\n", ret); in cros_ec_pkt_xfer_i2c()
109 ret = -EIO; in cros_ec_pkt_xfer_i2c()
114 msg->result = ec_response_i2c->result; in cros_ec_pkt_xfer_i2c()
115 ec_response = &ec_response_i2c->ec_response; in cros_ec_pkt_xfer_i2c()
117 switch (msg->result) { in cros_ec_pkt_xfer_i2c()
121 ret = -EAGAIN; in cros_ec_pkt_xfer_i2c()
122 dev_dbg(ec_dev->dev, "command 0x%02x in progress\n", in cros_ec_pkt_xfer_i2c()
123 msg->command); in cros_ec_pkt_xfer_i2c()
127 dev_dbg(ec_dev->dev, "command 0x%02x returned %d\n", in cros_ec_pkt_xfer_i2c()
128 msg->command, msg->result); in cros_ec_pkt_xfer_i2c()
137 if (ec_response_i2c->result == EC_RES_INVALID_COMMAND && in cros_ec_pkt_xfer_i2c()
138 ec_response_i2c->packet_length == 0) { in cros_ec_pkt_xfer_i2c()
139 ret = -EPROTONOSUPPORT; in cros_ec_pkt_xfer_i2c()
144 if (ec_response_i2c->packet_length < sizeof(struct ec_host_response)) { in cros_ec_pkt_xfer_i2c()
145 dev_err(ec_dev->dev, in cros_ec_pkt_xfer_i2c()
147 ec_response_i2c->packet_length); in cros_ec_pkt_xfer_i2c()
148 ret = -EBADMSG; in cros_ec_pkt_xfer_i2c()
152 if (msg->insize < ec_response->data_len) { in cros_ec_pkt_xfer_i2c()
153 dev_err(ec_dev->dev, in cros_ec_pkt_xfer_i2c()
155 msg->insize, in cros_ec_pkt_xfer_i2c()
156 ec_response->data_len); in cros_ec_pkt_xfer_i2c()
157 ret = -EMSGSIZE; in cros_ec_pkt_xfer_i2c()
166 memcpy(msg->data, in cros_ec_pkt_xfer_i2c()
168 ec_response->data_len); in cros_ec_pkt_xfer_i2c()
169 for (i = 0; i < ec_response->data_len; i++) in cros_ec_pkt_xfer_i2c()
170 sum += msg->data[i]; in cros_ec_pkt_xfer_i2c()
174 dev_err(ec_dev->dev, "bad packet checksum\n"); in cros_ec_pkt_xfer_i2c()
175 ret = -EBADMSG; in cros_ec_pkt_xfer_i2c()
179 ret = ec_response->data_len; in cros_ec_pkt_xfer_i2c()
182 if (msg->command == EC_CMD_REBOOT_EC) in cros_ec_pkt_xfer_i2c()
191 struct i2c_client *client = ec_dev->priv; in cros_ec_cmd_xfer_i2c()
192 int ret = -ENOMEM; in cros_ec_cmd_xfer_i2c()
194 int len; in cros_ec_cmd_xfer_i2c() local
201 i2c_msg[0].addr = client->addr; in cros_ec_cmd_xfer_i2c()
203 i2c_msg[1].addr = client->addr; in cros_ec_cmd_xfer_i2c()
207 * allocate larger packet (one byte for checksum, one byte for in cros_ec_cmd_xfer_i2c()
210 packet_len = msg->insize + 3; in cros_ec_cmd_xfer_i2c()
214 i2c_msg[1].len = packet_len; in cros_ec_cmd_xfer_i2c()
218 * allocate larger packet (one byte for checksum, one for in cros_ec_cmd_xfer_i2c()
221 packet_len = msg->outsize + 4; in cros_ec_cmd_xfer_i2c()
225 i2c_msg[0].len = packet_len; in cros_ec_cmd_xfer_i2c()
228 out_buf[0] = EC_CMD_VERSION0 + msg->version; in cros_ec_cmd_xfer_i2c()
229 out_buf[1] = msg->command; in cros_ec_cmd_xfer_i2c()
230 out_buf[2] = msg->outsize; in cros_ec_cmd_xfer_i2c()
234 for (i = 0; i < msg->outsize; i++) { in cros_ec_cmd_xfer_i2c()
235 out_buf[3 + i] = msg->data[i]; in cros_ec_cmd_xfer_i2c()
238 out_buf[3 + msg->outsize] = sum; in cros_ec_cmd_xfer_i2c()
241 ret = i2c_transfer(client->adapter, i2c_msg, 2); in cros_ec_cmd_xfer_i2c()
243 dev_err(ec_dev->dev, "i2c transfer failed: %d\n", ret); in cros_ec_cmd_xfer_i2c()
246 dev_err(ec_dev->dev, "failed to get response: %d\n", ret); in cros_ec_cmd_xfer_i2c()
247 ret = -EIO; in cros_ec_cmd_xfer_i2c()
252 msg->result = i2c_msg[1].buf[0]; in cros_ec_cmd_xfer_i2c()
257 len = in_buf[1]; in cros_ec_cmd_xfer_i2c()
258 if (len > msg->insize) { in cros_ec_cmd_xfer_i2c()
259 dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", in cros_ec_cmd_xfer_i2c()
260 len, msg->insize); in cros_ec_cmd_xfer_i2c()
261 ret = -ENOSPC; in cros_ec_cmd_xfer_i2c()
267 for (i = 0; i < len; i++) { in cros_ec_cmd_xfer_i2c()
268 msg->data[i] = in_buf[2 + i]; in cros_ec_cmd_xfer_i2c()
271 dev_dbg(ec_dev->dev, "packet: %*ph, sum = %02x\n", in cros_ec_cmd_xfer_i2c()
272 i2c_msg[1].len, in_buf, sum); in cros_ec_cmd_xfer_i2c()
273 if (sum != in_buf[2 + len]) { in cros_ec_cmd_xfer_i2c()
274 dev_err(ec_dev->dev, "bad packet checksum\n"); in cros_ec_cmd_xfer_i2c()
275 ret = -EBADMSG; in cros_ec_cmd_xfer_i2c()
279 ret = len; in cros_ec_cmd_xfer_i2c()
283 if (msg->command == EC_CMD_REBOOT_EC) in cros_ec_cmd_xfer_i2c()
291 struct device *dev = &client->dev; in cros_ec_i2c_probe()
297 return -ENOMEM; in cros_ec_i2c_probe()
300 ec_dev->dev = dev; in cros_ec_i2c_probe()
301 ec_dev->priv = client; in cros_ec_i2c_probe()
302 ec_dev->irq = client->irq; in cros_ec_i2c_probe()
303 ec_dev->cmd_xfer = cros_ec_cmd_xfer_i2c; in cros_ec_i2c_probe()
304 ec_dev->pkt_xfer = cros_ec_pkt_xfer_i2c; in cros_ec_i2c_probe()
305 ec_dev->phys_name = client->adapter->name; in cros_ec_i2c_probe()
306 ec_dev->din_size = sizeof(struct ec_host_response_i2c) + in cros_ec_i2c_probe()
308 ec_dev->dout_size = sizeof(struct ec_host_request_i2c); in cros_ec_i2c_probe()
348 { .compatible = "google,cros-ec-i2c", },
355 { "cros-ec-i2c", 0 },
370 .name = "cros-ec-i2c",