Lines Matching refs:ec_dev
82 typedef int (*cros_ec_xfer_fn_t) (struct cros_ec_device *ec_dev,
98 struct cros_ec_device *ec_dev; member
117 static int terminate_request(struct cros_ec_device *ec_dev) in terminate_request() argument
119 struct cros_ec_spi *ec_spi = ec_dev->priv; in terminate_request()
139 dev_err(ec_dev->dev, in terminate_request()
156 static int receive_n_bytes(struct cros_ec_device *ec_dev, u8 *buf, int n) in receive_n_bytes() argument
158 struct cros_ec_spi *ec_spi = ec_dev->priv; in receive_n_bytes()
163 if (buf - ec_dev->din + n > ec_dev->din_size) in receive_n_bytes()
175 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); in receive_n_bytes()
192 static int cros_ec_spi_receive_packet(struct cros_ec_device *ec_dev, in cros_ec_spi_receive_packet() argument
201 if (ec_dev->din_size < EC_MSG_PREAMBLE_COUNT) in cros_ec_spi_receive_packet()
209 ret = receive_n_bytes(ec_dev, in cros_ec_spi_receive_packet()
210 ec_dev->din, in cros_ec_spi_receive_packet()
215 ptr = ec_dev->din; in cros_ec_spi_receive_packet()
218 dev_dbg(ec_dev->dev, "msg found at %zd\n", in cros_ec_spi_receive_packet()
219 ptr - ec_dev->din); in cros_ec_spi_receive_packet()
232 dev_warn(ec_dev->dev, "EC failed to respond in time\n"); in cros_ec_spi_receive_packet()
243 memmove(ec_dev->din, ptr, todo); in cros_ec_spi_receive_packet()
244 ptr = ec_dev->din + todo; in cros_ec_spi_receive_packet()
245 dev_dbg(ec_dev->dev, "need %d, got %d bytes from preamble\n", in cros_ec_spi_receive_packet()
251 ret = receive_n_bytes(ec_dev, ptr, sizeof(*response) - todo); in cros_ec_spi_receive_packet()
258 response = (struct ec_host_response *)ec_dev->din; in cros_ec_spi_receive_packet()
261 if (response->data_len > ec_dev->din_size) in cros_ec_spi_receive_packet()
273 dev_dbg(ec_dev->dev, "loop, todo=%d, need_len=%d, ptr=%zd\n", in cros_ec_spi_receive_packet()
274 todo, need_len, ptr - ec_dev->din); in cros_ec_spi_receive_packet()
276 ret = receive_n_bytes(ec_dev, ptr, todo); in cros_ec_spi_receive_packet()
284 dev_dbg(ec_dev->dev, "loop done, ptr=%zd\n", ptr - ec_dev->din); in cros_ec_spi_receive_packet()
301 static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, in cros_ec_spi_receive_response() argument
309 if (ec_dev->din_size < EC_MSG_PREAMBLE_COUNT) in cros_ec_spi_receive_response()
317 ret = receive_n_bytes(ec_dev, in cros_ec_spi_receive_response()
318 ec_dev->din, in cros_ec_spi_receive_response()
323 ptr = ec_dev->din; in cros_ec_spi_receive_response()
326 dev_dbg(ec_dev->dev, "msg found at %zd\n", in cros_ec_spi_receive_response()
327 ptr - ec_dev->din); in cros_ec_spi_receive_response()
340 dev_warn(ec_dev->dev, "EC failed to respond in time\n"); in cros_ec_spi_receive_response()
351 memmove(ec_dev->din, ptr, todo); in cros_ec_spi_receive_response()
352 ptr = ec_dev->din + todo; in cros_ec_spi_receive_response()
353 dev_dbg(ec_dev->dev, "need %d, got %d bytes from preamble\n", in cros_ec_spi_receive_response()
366 dev_dbg(ec_dev->dev, "loop, todo=%d, need_len=%d, ptr=%zd\n", in cros_ec_spi_receive_response()
367 todo, need_len, ptr - ec_dev->din); in cros_ec_spi_receive_response()
369 ret = receive_n_bytes(ec_dev, ptr, todo); in cros_ec_spi_receive_response()
373 debug_packet(ec_dev->dev, "interim", ptr, todo); in cros_ec_spi_receive_response()
378 dev_dbg(ec_dev->dev, "loop done, ptr=%zd\n", ptr - ec_dev->din); in cros_ec_spi_receive_response()
389 static int do_cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, in do_cros_ec_pkt_xfer_spi() argument
393 struct cros_ec_spi *ec_spi = ec_dev->priv; in do_cros_ec_pkt_xfer_spi()
404 len = cros_ec_prepare_tx(ec_dev, ec_msg); in do_cros_ec_pkt_xfer_spi()
407 dev_dbg(ec_dev->dev, "prepared, len=%d\n", len); in do_cros_ec_pkt_xfer_spi()
434 trans.tx_buf = ec_dev->dout; in do_cros_ec_pkt_xfer_spi()
471 ret = cros_ec_spi_receive_packet(ec_dev, in do_cros_ec_pkt_xfer_spi()
474 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); in do_cros_ec_pkt_xfer_spi()
476 final_ret = terminate_request(ec_dev); in do_cros_ec_pkt_xfer_spi()
485 ptr = ec_dev->din; in do_cros_ec_pkt_xfer_spi()
491 ret = cros_ec_check_result(ec_dev, ec_msg); in do_cros_ec_pkt_xfer_spi()
498 dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", in do_cros_ec_pkt_xfer_spi()
513 dev_err(ec_dev->dev, in do_cros_ec_pkt_xfer_spi()
535 static int do_cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, in do_cros_ec_cmd_xfer_spi() argument
538 struct cros_ec_spi *ec_spi = ec_dev->priv; in do_cros_ec_cmd_xfer_spi()
549 len = cros_ec_prepare_tx(ec_dev, ec_msg); in do_cros_ec_cmd_xfer_spi()
552 dev_dbg(ec_dev->dev, "prepared, len=%d\n", len); in do_cros_ec_cmd_xfer_spi()
566 debug_packet(ec_dev->dev, "out", ec_dev->dout, len); in do_cros_ec_cmd_xfer_spi()
568 trans.tx_buf = ec_dev->dout; in do_cros_ec_cmd_xfer_spi()
592 ret = cros_ec_spi_receive_response(ec_dev, in do_cros_ec_cmd_xfer_spi()
595 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); in do_cros_ec_cmd_xfer_spi()
597 final_ret = terminate_request(ec_dev); in do_cros_ec_cmd_xfer_spi()
606 ptr = ec_dev->din; in do_cros_ec_cmd_xfer_spi()
610 ret = cros_ec_check_result(ec_dev, ec_msg); in do_cros_ec_cmd_xfer_spi()
617 dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", in do_cros_ec_cmd_xfer_spi()
631 debug_packet(ec_dev->dev, "in", ptr, len + 3); in do_cros_ec_cmd_xfer_spi()
634 dev_err(ec_dev->dev, in do_cros_ec_cmd_xfer_spi()
655 params->ret = params->fn(params->ec_dev, params->ec_msg); in cros_ec_xfer_high_pri_work()
658 static int cros_ec_xfer_high_pri(struct cros_ec_device *ec_dev, in cros_ec_xfer_high_pri() argument
662 struct cros_ec_spi *ec_spi = ec_dev->priv; in cros_ec_xfer_high_pri()
666 .ec_dev = ec_dev, in cros_ec_xfer_high_pri()
686 static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev, in cros_ec_pkt_xfer_spi() argument
689 return cros_ec_xfer_high_pri(ec_dev, ec_msg, do_cros_ec_pkt_xfer_spi); in cros_ec_pkt_xfer_spi()
692 static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev, in cros_ec_cmd_xfer_spi() argument
695 return cros_ec_xfer_high_pri(ec_dev, ec_msg, do_cros_ec_cmd_xfer_spi); in cros_ec_cmd_xfer_spi()
745 struct cros_ec_device *ec_dev; in cros_ec_spi_probe() local
758 ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); in cros_ec_spi_probe()
759 if (!ec_dev) in cros_ec_spi_probe()
765 spi_set_drvdata(spi, ec_dev); in cros_ec_spi_probe()
766 ec_dev->dev = dev; in cros_ec_spi_probe()
767 ec_dev->priv = ec_spi; in cros_ec_spi_probe()
768 ec_dev->irq = spi->irq; in cros_ec_spi_probe()
769 ec_dev->cmd_xfer = cros_ec_cmd_xfer_spi; in cros_ec_spi_probe()
770 ec_dev->pkt_xfer = cros_ec_pkt_xfer_spi; in cros_ec_spi_probe()
771 ec_dev->phys_name = dev_name(&ec_spi->spi->dev); in cros_ec_spi_probe()
772 ec_dev->din_size = EC_MSG_PREAMBLE_COUNT + in cros_ec_spi_probe()
775 ec_dev->dout_size = sizeof(struct ec_host_request); in cros_ec_spi_probe()
783 err = cros_ec_register(ec_dev); in cros_ec_spi_probe()
796 struct cros_ec_device *ec_dev = spi_get_drvdata(spi); in cros_ec_spi_remove() local
798 cros_ec_unregister(ec_dev); in cros_ec_spi_remove()
804 struct cros_ec_device *ec_dev = dev_get_drvdata(dev); in cros_ec_spi_suspend() local
806 return cros_ec_suspend(ec_dev); in cros_ec_spi_suspend()
811 struct cros_ec_device *ec_dev = dev_get_drvdata(dev); in cros_ec_spi_resume() local
813 return cros_ec_resume(ec_dev); in cros_ec_spi_resume()