Lines Matching full:ec
3 * huawei-gaokun-ec - An EC driver for HUAWEI Matebook E Go
19 #include <linux/platform_data/huawei-gaokun-ec.h>
118 struct mutex lock; /* EC transaction lock */
125 static int gaokun_ec_request(struct gaokun_ec *ec, const u8 *req, in gaokun_ec_request() argument
128 struct i2c_client *client = ec->client; in gaokun_ec_request()
144 guard(mutex)(&ec->lock); in gaokun_ec_request()
153 dev_err(&client->dev, "EC transaction error %d\n", ret); in gaokun_ec_request()
165 * gaokun_ec_read - Read from EC
166 * @ec: The gaokun_ec structure
171 * This function is used to read data after writing a magic sequence to EC.
172 * All EC operations depend on this function.
182 int gaokun_ec_read(struct gaokun_ec *ec, const u8 *req, in gaokun_ec_read() argument
185 return gaokun_ec_request(ec, req, resp_len, resp); in gaokun_ec_read()
190 * gaokun_ec_write - Write to EC
191 * @ec: The gaokun_ec structure
199 int gaokun_ec_write(struct gaokun_ec *ec, const u8 *req) in gaokun_ec_write() argument
203 return gaokun_ec_request(ec, req, sizeof(ec_resp), ec_resp); in gaokun_ec_write()
207 int gaokun_ec_read_byte(struct gaokun_ec *ec, const u8 *req, u8 *byte) in gaokun_ec_read_byte() argument
212 ret = gaokun_ec_read(ec, req, sizeof(ec_resp), ec_resp); in gaokun_ec_read_byte()
220 * gaokun_ec_register_notify - Register a notifier callback for EC events.
221 * @ec: The gaokun_ec structure
226 int gaokun_ec_register_notify(struct gaokun_ec *ec, struct notifier_block *nb) in gaokun_ec_register_notify() argument
228 return blocking_notifier_chain_register(&ec->notifier_list, nb); in gaokun_ec_register_notify()
233 * gaokun_ec_unregister_notify - Unregister notifier callback for EC events.
234 * @ec: The gaokun_ec structure
240 void gaokun_ec_unregister_notify(struct gaokun_ec *ec, struct notifier_block *nb) in gaokun_ec_unregister_notify() argument
242 blocking_notifier_chain_unregister(&ec->notifier_list, nb); in gaokun_ec_unregister_notify()
251 * @ec: The gaokun_ec structure
258 int gaokun_ec_psy_multi_read(struct gaokun_ec *ec, u8 reg, in gaokun_ec_psy_multi_read() argument
267 ret = gaokun_ec_read(ec, ec_req, sizeof(ec_resp), ec_resp); in gaokun_ec_psy_multi_read()
280 * gaokun_ec_psy_get_smart_charge - Get smart charge data from EC
281 * @ec: The gaokun_ec structure
286 int gaokun_ec_psy_get_smart_charge(struct gaokun_ec *ec, in gaokun_ec_psy_get_smart_charge() argument
294 ret = gaokun_ec_read(ec, ec_req, sizeof(ec_resp), ec_resp); in gaokun_ec_psy_get_smart_charge()
311 * @ec: The gaokun_ec structure
316 int gaokun_ec_psy_set_smart_charge(struct gaokun_ec *ec, in gaokun_ec_psy_set_smart_charge() argument
328 return gaokun_ec_write(ec, ec_req); in gaokun_ec_psy_set_smart_charge()
336 * @ec: The gaokun_ec structure
341 int gaokun_ec_psy_get_smart_charge_enable(struct gaokun_ec *ec, bool *on) in gaokun_ec_psy_get_smart_charge_enable() argument
348 ret = gaokun_ec_read_byte(ec, ec_req, &state); in gaokun_ec_psy_get_smart_charge_enable()
360 * @ec: The gaokun_ec structure
365 int gaokun_ec_psy_set_smart_charge_enable(struct gaokun_ec *ec, bool on) in gaokun_ec_psy_set_smart_charge_enable() argument
370 return gaokun_ec_write(ec, ec_req); in gaokun_ec_psy_set_smart_charge_enable()
378 * gaokun_ec_ucsi_read - Read UCSI data from EC
379 * @ec: The gaokun_ec structure
386 int gaokun_ec_ucsi_read(struct gaokun_ec *ec, in gaokun_ec_ucsi_read() argument
393 ret = gaokun_ec_read(ec, ec_req, sizeof(ec_resp), ec_resp); in gaokun_ec_ucsi_read()
403 * gaokun_ec_ucsi_write - Write UCSI data to EC
404 * @ec: The gaokun_ec structure
411 int gaokun_ec_ucsi_write(struct gaokun_ec *ec, in gaokun_ec_ucsi_write() argument
418 return gaokun_ec_write(ec, ec_req); in gaokun_ec_ucsi_write()
423 * gaokun_ec_ucsi_get_reg - Get UCSI register from EC
424 * @ec: The gaokun_ec structure
431 int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, struct gaokun_ucsi_reg *ureg) in gaokun_ec_ucsi_get_reg() argument
437 ret = gaokun_ec_read(ec, ec_req, sizeof(ec_resp), ec_resp); in gaokun_ec_ucsi_get_reg()
448 * gaokun_ec_ucsi_pan_ack - Ack pin assignment notifications from EC
449 * @ec: The gaokun_ec structure
456 int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id) in gaokun_ec_ucsi_pan_ack() argument
466 return gaokun_ec_write(ec, ec_req); in gaokun_ec_ucsi_pan_ack()
471 /* EC Sysfs */
474 static int gaokun_ec_get_fn_lock(struct gaokun_ec *ec, bool *on) in gaokun_ec_get_fn_lock() argument
481 ret = gaokun_ec_read_byte(ec, ec_req, &state); in gaokun_ec_get_fn_lock()
495 static int gaokun_ec_set_fn_lock(struct gaokun_ec *ec, bool on) in gaokun_ec_set_fn_lock() argument
501 return gaokun_ec_write(ec, ec_req); in gaokun_ec_set_fn_lock()
508 struct gaokun_ec *ec = dev_get_drvdata(dev); in fn_lock_show() local
512 ret = gaokun_ec_get_fn_lock(ec, &on); in fn_lock_show()
523 struct gaokun_ec *ec = dev_get_drvdata(dev); in fn_lock_store() local
530 ret = gaokun_ec_set_fn_lock(ec, on); in fn_lock_store()
555 static int gaokun_ec_get_temp(struct gaokun_ec *ec, u8 idx, long *temp) in gaokun_ec_get_temp() argument
563 ret = gaokun_ec_read(ec, ec_req, sizeof(ec_resp), ec_resp); in gaokun_ec_get_temp()
584 struct gaokun_ec *ec = dev_get_drvdata(dev); in gaokun_ec_hwmon_read() local
587 return gaokun_ec_get_temp(ec, channel, val); in gaokun_ec_hwmon_read()
622 struct gaokun_ec *ec = dev_get_drvdata(dev); in gaokun_ec_suspend() local
626 if (ec->suspended) in gaokun_ec_suspend()
629 ret = gaokun_ec_write(ec, ec_req); in gaokun_ec_suspend()
633 ec->suspended = true; in gaokun_ec_suspend()
640 struct gaokun_ec *ec = dev_get_drvdata(dev); in gaokun_ec_resume() local
645 if (!ec->suspended) in gaokun_ec_resume()
649 ret = gaokun_ec_write(ec, ec_req); in gaokun_ec_resume()
653 msleep(100); /* EC need time to resume */ in gaokun_ec_resume()
656 ec->suspended = false; in gaokun_ec_resume()
677 struct gaokun_ec *ec) in gaokun_aux_init() argument
690 adev->dev.platform_data = ec; in gaokun_aux_init()
710 /* EC */
714 struct gaokun_ec *ec = data; in gaokun_ec_irq_handler() local
719 ret = gaokun_ec_read_byte(ec, ec_req, &id); in gaokun_ec_irq_handler()
728 gaokun_ec_psy_read_byte(ec, EC_LID_STATE, &status); in gaokun_ec_irq_handler()
730 input_report_switch(ec->idev, SW_LID, !status); in gaokun_ec_irq_handler()
731 input_sync(ec->idev); in gaokun_ec_irq_handler()
735 blocking_notifier_call_chain(&ec->notifier_list, id, ec); in gaokun_ec_irq_handler()
744 struct gaokun_ec *ec; in gaokun_ec_probe() local
747 ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); in gaokun_ec_probe()
748 if (!ec) in gaokun_ec_probe()
751 ret = devm_mutex_init(dev, &ec->lock); in gaokun_ec_probe()
755 ec->client = client; in gaokun_ec_probe()
756 i2c_set_clientdata(client, ec); in gaokun_ec_probe()
757 BLOCKING_INIT_NOTIFIER_HEAD(&ec->notifier_list); in gaokun_ec_probe()
760 ec->idev = devm_input_allocate_device(dev); in gaokun_ec_probe()
761 if (!ec->idev) in gaokun_ec_probe()
764 ec->idev->name = "LID"; in gaokun_ec_probe()
765 ec->idev->phys = "gaokun-ec/input0"; in gaokun_ec_probe()
766 input_set_capability(ec->idev, EV_SW, SW_LID); in gaokun_ec_probe()
768 ret = input_register_device(ec->idev); in gaokun_ec_probe()
772 ret = gaokun_aux_init(dev, GAOKUN_DEV_PSY, ec); in gaokun_ec_probe()
776 ret = gaokun_aux_init(dev, GAOKUN_DEV_UCSI, ec); in gaokun_ec_probe()
782 dev_name(dev), ec); in gaokun_ec_probe()
786 ec->hwmon_dev = devm_hwmon_device_register_with_info(dev, "gaokun_ec_hwmon", in gaokun_ec_probe()
787 ec, &gaokun_ec_hwmon_chip_info, NULL); in gaokun_ec_probe()
788 if (IS_ERR(ec->hwmon_dev)) in gaokun_ec_probe()
789 return dev_err_probe(dev, PTR_ERR(ec->hwmon_dev), in gaokun_ec_probe()
796 { "gaokun-ec", },
802 { .compatible = "huawei,gaokun3-ec", },
813 .name = "gaokun-ec",
823 MODULE_DESCRIPTION("HUAWEI Matebook E Go EC driver");