Lines Matching refs:ec_dev

18 static int prepare_packet(struct cros_ec_device *ec_dev,  in prepare_packet()  argument
26 BUG_ON(ec_dev->proto_version != EC_HOST_REQUEST_VERSION); in prepare_packet()
27 BUG_ON(msg->outsize + sizeof(*request) > ec_dev->dout_size); in prepare_packet()
29 out = ec_dev->dout; in prepare_packet()
51 static int send_command(struct cros_ec_device *ec_dev, in send_command() argument
59 if (ec_dev->proto_version > 2) in send_command()
60 xfer_fxn = ec_dev->pkt_xfer; in send_command()
62 xfer_fxn = ec_dev->cmd_xfer; in send_command()
70 dev_err_once(ec_dev->dev, in send_command()
75 ret = (*xfer_fxn)(ec_dev, msg); in send_command()
98 ret = (*xfer_fxn)(ec_dev, status_msg); in send_command()
120 int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, in cros_ec_prepare_tx() argument
127 if (ec_dev->proto_version > 2) in cros_ec_prepare_tx()
128 return prepare_packet(ec_dev, msg); in cros_ec_prepare_tx()
131 out = ec_dev->dout; in cros_ec_prepare_tx()
144 int cros_ec_check_result(struct cros_ec_device *ec_dev, in cros_ec_check_result() argument
151 dev_dbg(ec_dev->dev, "command 0x%02x in progress\n", in cros_ec_check_result()
155 dev_dbg(ec_dev->dev, "command 0x%02x returned %d\n", in cros_ec_check_result()
175 static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev, in cros_ec_get_host_event_wake_mask() argument
187 ret = send_command(ec_dev, msg); in cros_ec_get_host_event_wake_mask()
196 static int cros_ec_host_command_proto_query(struct cros_ec_device *ec_dev, in cros_ec_host_command_proto_query() argument
208 if (!ec_dev->pkt_xfer) in cros_ec_host_command_proto_query()
215 ret = send_command(ec_dev, msg); in cros_ec_host_command_proto_query()
218 dev_dbg(ec_dev->dev, in cros_ec_host_command_proto_query()
232 static int cros_ec_host_command_proto_query_v2(struct cros_ec_device *ec_dev) in cros_ec_host_command_proto_query_v2() argument
253 ret = send_command(ec_dev, msg); in cros_ec_host_command_proto_query_v2()
256 dev_dbg(ec_dev->dev, in cros_ec_host_command_proto_query_v2()
261 dev_err(ec_dev->dev, in cros_ec_host_command_proto_query_v2()
267 dev_err(ec_dev->dev, in cros_ec_host_command_proto_query_v2()
297 static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev, in cros_ec_get_host_command_version_mask() argument
318 ret = send_command(ec_dev, msg); in cros_ec_get_host_command_version_mask()
329 int cros_ec_query_all(struct cros_ec_device *ec_dev) in cros_ec_query_all() argument
331 struct device *dev = ec_dev->dev; in cros_ec_query_all()
343 ec_dev->proto_version = 3; in cros_ec_query_all()
344 ret = cros_ec_host_command_proto_query(ec_dev, 0, proto_msg); in cros_ec_query_all()
349 ec_dev->max_request = proto_info->max_request_packet_size - in cros_ec_query_all()
351 ec_dev->max_response = proto_info->max_response_packet_size - in cros_ec_query_all()
353 ec_dev->proto_version = in cros_ec_query_all()
356 dev_dbg(ec_dev->dev, in cros_ec_query_all()
358 ec_dev->proto_version); in cros_ec_query_all()
360 ec_dev->din_size = ec_dev->max_response + in cros_ec_query_all()
363 ec_dev->dout_size = ec_dev->max_request + in cros_ec_query_all()
370 ret = cros_ec_host_command_proto_query(ec_dev, 1, proto_msg); in cros_ec_query_all()
373 dev_dbg(ec_dev->dev, "no PD chip found: %d\n", ret); in cros_ec_query_all()
374 ec_dev->max_passthru = 0; in cros_ec_query_all()
376 dev_dbg(ec_dev->dev, "found PD chip\n"); in cros_ec_query_all()
377 ec_dev->max_passthru = in cros_ec_query_all()
383 ec_dev->proto_version = 2; in cros_ec_query_all()
384 ret = cros_ec_host_command_proto_query_v2(ec_dev); in cros_ec_query_all()
388 dev_dbg(ec_dev->dev, "falling back to proto v2\n"); in cros_ec_query_all()
390 ec_dev->max_request = EC_PROTO2_MAX_PARAM_SIZE; in cros_ec_query_all()
391 ec_dev->max_response = EC_PROTO2_MAX_PARAM_SIZE; in cros_ec_query_all()
392 ec_dev->max_passthru = 0; in cros_ec_query_all()
393 ec_dev->pkt_xfer = NULL; in cros_ec_query_all()
394 ec_dev->din_size = EC_PROTO2_MSG_BYTES; in cros_ec_query_all()
395 ec_dev->dout_size = EC_PROTO2_MSG_BYTES; in cros_ec_query_all()
402 ec_dev->proto_version = EC_PROTO_VERSION_UNKNOWN; in cros_ec_query_all()
403 dev_dbg(ec_dev->dev, "EC query failed: %d\n", ret); in cros_ec_query_all()
408 devm_kfree(dev, ec_dev->din); in cros_ec_query_all()
409 devm_kfree(dev, ec_dev->dout); in cros_ec_query_all()
411 ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL); in cros_ec_query_all()
412 if (!ec_dev->din) { in cros_ec_query_all()
417 ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL); in cros_ec_query_all()
418 if (!ec_dev->dout) { in cros_ec_query_all()
419 devm_kfree(dev, ec_dev->din); in cros_ec_query_all()
425 ret = cros_ec_get_host_command_version_mask(ec_dev, in cros_ec_query_all()
429 ec_dev->mkbp_event_supported = 0; in cros_ec_query_all()
431 ec_dev->mkbp_event_supported = 1; in cros_ec_query_all()
434 ret = cros_ec_get_host_command_version_mask(ec_dev, in cros_ec_query_all()
437 ec_dev->host_sleep_v1 = (ret >= 0 && (ver_mask & EC_VER_MASK(1))); in cros_ec_query_all()
443 ret = cros_ec_get_host_event_wake_mask(ec_dev, proto_msg, in cros_ec_query_all()
444 &ec_dev->host_event_wake_mask); in cros_ec_query_all()
446 ec_dev->host_event_wake_mask = U32_MAX; in cros_ec_query_all()
456 int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, in cros_ec_cmd_xfer() argument
461 mutex_lock(&ec_dev->lock); in cros_ec_cmd_xfer()
462 if (ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWN) { in cros_ec_cmd_xfer()
463 ret = cros_ec_query_all(ec_dev); in cros_ec_cmd_xfer()
465 dev_err(ec_dev->dev, in cros_ec_cmd_xfer()
467 mutex_unlock(&ec_dev->lock); in cros_ec_cmd_xfer()
472 if (msg->insize > ec_dev->max_response) { in cros_ec_cmd_xfer()
473 dev_dbg(ec_dev->dev, "clamping message receive buffer\n"); in cros_ec_cmd_xfer()
474 msg->insize = ec_dev->max_response; in cros_ec_cmd_xfer()
478 if (msg->outsize > ec_dev->max_request) { in cros_ec_cmd_xfer()
479 dev_err(ec_dev->dev, in cros_ec_cmd_xfer()
482 ec_dev->max_request); in cros_ec_cmd_xfer()
483 mutex_unlock(&ec_dev->lock); in cros_ec_cmd_xfer()
487 if (msg->outsize > ec_dev->max_passthru) { in cros_ec_cmd_xfer()
488 dev_err(ec_dev->dev, in cros_ec_cmd_xfer()
491 ec_dev->max_passthru); in cros_ec_cmd_xfer()
492 mutex_unlock(&ec_dev->lock); in cros_ec_cmd_xfer()
496 ret = send_command(ec_dev, msg); in cros_ec_cmd_xfer()
497 mutex_unlock(&ec_dev->lock); in cros_ec_cmd_xfer()
503 int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, in cros_ec_cmd_xfer_status() argument
508 ret = cros_ec_cmd_xfer(ec_dev, msg); in cros_ec_cmd_xfer_status()
510 dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret); in cros_ec_cmd_xfer_status()
512 dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result); in cros_ec_cmd_xfer_status()
520 static int get_next_event_xfer(struct cros_ec_device *ec_dev, in get_next_event_xfer() argument
531 ret = cros_ec_cmd_xfer(ec_dev, msg); in get_next_event_xfer()
533 ec_dev->event_size = ret - 1; in get_next_event_xfer()
534 memcpy(&ec_dev->event_data, msg->data, ret); in get_next_event_xfer()
540 static int get_next_event(struct cros_ec_device *ec_dev) in get_next_event() argument
542 u8 buffer[sizeof(struct cros_ec_command) + sizeof(ec_dev->event_data)]; in get_next_event()
547 if (ec_dev->suspended) { in get_next_event()
548 dev_dbg(ec_dev->dev, "Device suspended.\n"); in get_next_event()
553 ret = get_next_event_xfer(ec_dev, msg, cmd_version, in get_next_event()
562 ret = get_next_event_xfer(ec_dev, msg, cmd_version, in get_next_event()
568 static int get_keyboard_state_event(struct cros_ec_device *ec_dev) in get_keyboard_state_event() argument
571 sizeof(ec_dev->event_data.data)]; in get_keyboard_state_event()
576 msg->insize = sizeof(ec_dev->event_data.data); in get_keyboard_state_event()
579 ec_dev->event_size = cros_ec_cmd_xfer(ec_dev, msg); in get_keyboard_state_event()
580 ec_dev->event_data.event_type = EC_MKBP_EVENT_KEY_MATRIX; in get_keyboard_state_event()
581 memcpy(&ec_dev->event_data.data, msg->data, in get_keyboard_state_event()
582 sizeof(ec_dev->event_data.data)); in get_keyboard_state_event()
584 return ec_dev->event_size; in get_keyboard_state_event()
587 int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event) in cros_ec_get_next_event() argument
593 if (!ec_dev->mkbp_event_supported) { in cros_ec_get_next_event()
594 ret = get_keyboard_state_event(ec_dev); in cros_ec_get_next_event()
604 ret = get_next_event(ec_dev); in cros_ec_get_next_event()
609 event_type = ec_dev->event_data.event_type; in cros_ec_get_next_event()
610 host_event = cros_ec_get_host_event(ec_dev); in cros_ec_get_next_event()
620 !(host_event & ec_dev->host_event_wake_mask)) in cros_ec_get_next_event()
631 u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev) in cros_ec_get_host_event() argument
635 BUG_ON(!ec_dev->mkbp_event_supported); in cros_ec_get_host_event()
637 if (ec_dev->event_data.event_type != EC_MKBP_EVENT_HOST_EVENT) in cros_ec_get_host_event()
640 if (ec_dev->event_size != sizeof(host_event)) { in cros_ec_get_host_event()
641 dev_warn(ec_dev->dev, "Invalid host event size\n"); in cros_ec_get_host_event()
645 host_event = get_unaligned_le32(&ec_dev->event_data.data.host_event); in cros_ec_get_host_event()