Lines Matching defs:ec_dev

55 static int prepare_tx(struct cros_ec_device *ec_dev,
63 if (msg->outsize + sizeof(*request) > ec_dev->dout_size)
66 out = ec_dev->dout;
88 static int prepare_tx_legacy(struct cros_ec_device *ec_dev,
98 out = ec_dev->dout;
110 static int cros_ec_xfer_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
115 if (ec_dev->proto_version > 2)
116 xfer_fxn = ec_dev->pkt_xfer;
118 xfer_fxn = ec_dev->cmd_xfer;
126 dev_err_once(ec_dev->dev, "missing EC transfer API, cannot send command\n");
131 ret = (*xfer_fxn)(ec_dev, msg);
137 static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result)
156 ret = cros_ec_xfer_command(ec_dev, msg);
181 static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
183 int ret = cros_ec_xfer_command(ec_dev, msg);
186 ret = cros_ec_wait_until_complete(ec_dev, &msg->result);
193 * @ec_dev: Device to register.
201 int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
204 if (ec_dev->proto_version > 2)
205 return prepare_tx(ec_dev, msg);
207 return prepare_tx_legacy(ec_dev, msg);
213 * @ec_dev: EC device.
224 int cros_ec_check_result(struct cros_ec_device *ec_dev,
231 dev_dbg(ec_dev->dev, "command 0x%02x in progress\n",
235 dev_dbg(ec_dev->dev, "command 0x%02x returned %d\n",
247 * @ec_dev: EC device to call
252 * the caller has ec_dev->lock mutex, or the caller knows there is
255 static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev, uint32_t *mask)
268 ret = cros_ec_send_command(ec_dev, msg);
291 static int cros_ec_get_proto_info(struct cros_ec_device *ec_dev, int devidx)
297 ec_dev->proto_version = 3;
299 ec_dev->max_passthru = 0;
308 ret = cros_ec_send_command(ec_dev, msg);
317 ret = cros_ec_send_command(ec_dev, msg);
320 dev_dbg(ec_dev->dev,
341 ec_dev->max_request = info->max_request_packet_size -
343 ec_dev->max_response = info->max_response_packet_size -
345 ec_dev->proto_version = min(EC_HOST_REQUEST_VERSION,
347 ec_dev->din_size = info->max_response_packet_size + EC_MAX_RESPONSE_OVERHEAD;
348 ec_dev->dout_size = info->max_request_packet_size + EC_MAX_REQUEST_OVERHEAD;
350 dev_dbg(ec_dev->dev, "using proto v%u\n", ec_dev->proto_version);
353 ec_dev->max_passthru = info->max_request_packet_size -
356 dev_dbg(ec_dev->dev, "found PD chip\n");
359 dev_dbg(ec_dev->dev, "unknown passthru index: %d\n", devidx);
369 static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev)
376 ec_dev->proto_version = 2;
389 ret = cros_ec_send_command(ec_dev, msg);
391 dev_dbg(ec_dev->dev, "EC failed to respond to v2 hello: %d\n", ret);
398 dev_err(ec_dev->dev, "EC responded to v2 hello with error: %d\n", msg->result);
409 dev_err(ec_dev->dev,
416 ec_dev->max_request = EC_PROTO2_MAX_PARAM_SIZE;
417 ec_dev->max_response = EC_PROTO2_MAX_PARAM_SIZE;
418 ec_dev->max_passthru = 0;
419 ec_dev->pkt_xfer = NULL;
420 ec_dev->din_size = EC_PROTO2_MSG_BYTES;
421 ec_dev->dout_size = EC_PROTO2_MSG_BYTES;
423 dev_dbg(ec_dev->dev, "falling back to proto v2\n");
435 * @ec_dev: EC device to call
443 * the caller has ec_dev->lock mutex or the caller knows there is
446 static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev, u16 cmd, u32 *mask)
466 ret = cros_ec_send_command(ec_dev, msg);
492 * @ec_dev: Device to register.
496 int cros_ec_query_all(struct cros_ec_device *ec_dev)
498 struct device *dev = ec_dev->dev;
503 if (!cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_EC_INDEX)) {
505 cros_ec_get_proto_info(ec_dev, CROS_EC_DEV_PD_INDEX);
508 ret = cros_ec_get_proto_info_legacy(ec_dev);
515 ec_dev->proto_version = EC_PROTO_VERSION_UNKNOWN;
516 dev_dbg(ec_dev->dev, "EC query failed: %d\n", ret);
521 devm_kfree(dev, ec_dev->din);
522 devm_kfree(dev, ec_dev->dout);
524 ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL);
525 if (!ec_dev->din) {
530 ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL);
531 if (!ec_dev->dout) {
532 devm_kfree(dev, ec_dev->din);
538 ret = cros_ec_get_host_command_version_mask(ec_dev, EC_CMD_GET_NEXT_EVENT, &ver_mask);
540 ec_dev->mkbp_event_supported = 0;
542 ec_dev->mkbp_event_supported = fls(ver_mask);
544 dev_dbg(ec_dev->dev, "MKBP support version %u\n", ec_dev->mkbp_event_supported - 1);
548 ret = cros_ec_get_host_command_version_mask(ec_dev, EC_CMD_HOST_SLEEP_EVENT, &ver_mask);
549 ec_dev->host_sleep_v1 = (ret == 0 && (ver_mask & EC_VER_MASK(1)));
552 ret = cros_ec_get_host_event_wake_mask(ec_dev, &ec_dev->host_event_wake_mask);
563 ec_dev->host_event_wake_mask = U32_MAX &
576 dev_err(ec_dev->dev,
589 * @ec_dev: EC device.
607 int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
611 mutex_lock(&ec_dev->lock);
612 if (ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWN) {
613 ret = cros_ec_query_all(ec_dev);
615 dev_err(ec_dev->dev,
617 mutex_unlock(&ec_dev->lock);
622 if (msg->insize > ec_dev->max_response) {
623 dev_dbg(ec_dev->dev, "clamping message receive buffer\n");
624 msg->insize = ec_dev->max_response;
628 if (msg->outsize > ec_dev->max_request) {
629 dev_err(ec_dev->dev,
632 ec_dev->max_request);
633 mutex_unlock(&ec_dev->lock);
637 if (msg->outsize > ec_dev->max_passthru) {
638 dev_err(ec_dev->dev,
641 ec_dev->max_passthru);
642 mutex_unlock(&ec_dev->lock);
647 ret = cros_ec_send_command(ec_dev, msg);
648 mutex_unlock(&ec_dev->lock);
656 * @ec_dev: EC device.
667 int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
672 ret = cros_ec_cmd_xfer(ec_dev, msg);
678 dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n",
687 static int get_next_event_xfer(struct cros_ec_device *ec_dev,
699 ret = cros_ec_cmd_xfer_status(ec_dev, msg);
701 ec_dev->event_size = ret - 1;
702 ec_dev->event_data = *event;
708 static int get_next_event(struct cros_ec_device *ec_dev)
716 const int cmd_version = ec_dev->mkbp_event_supported - 1;
719 if (ec_dev->suspended) {
720 dev_dbg(ec_dev->dev, "Device suspended.\n");
725 return get_next_event_xfer(ec_dev, msg, event, 0,
728 return get_next_event_xfer(ec_dev, msg, event, cmd_version,
732 static int get_keyboard_state_event(struct cros_ec_device *ec_dev)
735 sizeof(ec_dev->event_data.data)];
740 msg->insize = sizeof(ec_dev->event_data.data);
743 ec_dev->event_size = cros_ec_cmd_xfer_status(ec_dev, msg);
744 ec_dev->event_data.event_type = EC_MKBP_EVENT_KEY_MATRIX;
745 memcpy(&ec_dev->event_data.data, msg->data,
746 sizeof(ec_dev->event_data.data));
748 return ec_dev->event_size;
753 * @ec_dev: Device to fetch event from.
767 * written out to @ec_dev->event_data.event_type on success.
769 int cros_ec_get_next_event(struct cros_ec_device *ec_dev,
794 if (!ec_dev->mkbp_event_supported)
795 return get_keyboard_state_event(ec_dev);
797 ret = get_next_event(ec_dev);
806 dev_dbg(ec_dev->dev,
808 ret = cros_ec_get_host_command_version_mask(ec_dev,
821 ec_dev->mkbp_event_supported = fls(ver_mask);
822 dev_dbg(ec_dev->dev, "MKBP support version changed to %u\n",
823 ec_dev->mkbp_event_supported - 1);
826 ret = get_next_event(ec_dev);
833 *has_more_events = ec_dev->event_data.event_type &
835 ec_dev->event_data.event_type &= EC_MKBP_EVENT_TYPE_MASK;
838 event_type = ec_dev->event_data.event_type;
839 host_event = cros_ec_get_host_event(ec_dev);
852 if (!(host_event & ec_dev->host_event_wake_mask))
863 * @ec_dev: Device to fetch event from.
871 u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
875 if (!ec_dev->mkbp_event_supported)
878 if (ec_dev->event_data.event_type != EC_MKBP_EVENT_HOST_EVENT)
881 if (ec_dev->event_size != sizeof(host_event)) {
882 dev_warn(ec_dev->dev, "Invalid host event size\n");
886 host_event = get_unaligned_le32(&ec_dev->event_data.data.host_event);
910 ret = cros_ec_cmd(ec->ec_dev, 0, EC_CMD_GET_FEATURES + ec->cmd_offset,
942 struct cros_ec_device *ec_dev = ec->ec_dev;
958 ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
971 if (sensor_count < 0 && ec->cmd_offset == 0 && ec_dev->cmd_readmem) {
972 ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS,
994 * @ec_dev: EC device
1004 int cros_ec_cmd(struct cros_ec_device *ec_dev,
1027 ret = cros_ec_cmd_xfer_status(ec_dev, msg);