Lines Matching +full:cros +full:- +full:ec +full:- +full:regulator
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ChromeOS EC multi-function device
7 * The ChromeOS EC multi function device is used to mux all the requests
8 * to the EC device for its multiple features: keyboard controller,
9 * battery charging and regulator control, firmware update.
34 * cros_ec_irq_handler() - top half part of the interrupt handler
44 ec_dev->last_event_time = cros_ec_get_time_ns(); in cros_ec_irq_handler()
50 * cros_ec_handle_event() - process and forward pending events on EC
53 * Call this function in a loop when the kernel is notified that the EC has
72 if (wake_event && device_may_wakeup(ec_dev->dev)) in cros_ec_handle_event()
73 pm_wakeup_event(ec_dev->dev, 0); in cros_ec_handle_event()
76 blocking_notifier_call_chain(&ec_dev->event_notifier, in cros_ec_handle_event()
83 * cros_ec_irq_thread() - bottom half part of the interrupt handler
116 if (ec_dev->host_sleep_v1) { in cros_ec_sleep_event()
119 ec_dev->suspend_timeout_ms; in cros_ec_sleep_event()
137 if (ret >= 0 && ec_dev->host_sleep_v1 && in cros_ec_sleep_event()
140 ec_dev->last_resume_result = in cros_ec_sleep_event()
145 "EC detected sleep transition timeout. Total sleep transitions: %d", in cros_ec_sleep_event()
162 mutex_lock(&ec_dev->lock); in cros_ec_ready_event()
164 mutex_unlock(&ec_dev->lock); in cros_ec_ready_event()
172 * cros_ec_register() - Register a new ChromeOS EC, using the provided info.
176 * in all the fields up to the --private-- marker.
182 struct device *dev = ec_dev->dev; in cros_ec_register()
185 BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->event_notifier); in cros_ec_register()
186 BLOCKING_INIT_NOTIFIER_HEAD(&ec_dev->panic_notifier); in cros_ec_register()
188 ec_dev->max_request = sizeof(struct ec_params_hello); in cros_ec_register()
189 ec_dev->max_response = sizeof(struct ec_response_get_protocol_info); in cros_ec_register()
190 ec_dev->max_passthru = 0; in cros_ec_register()
191 ec_dev->ec = NULL; in cros_ec_register()
192 ec_dev->pd = NULL; in cros_ec_register()
193 ec_dev->suspend_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT; in cros_ec_register()
195 ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL); in cros_ec_register()
196 if (!ec_dev->din) in cros_ec_register()
197 return -ENOMEM; in cros_ec_register()
199 ec_dev->dout = devm_kzalloc(dev, ec_dev->dout_size, GFP_KERNEL); in cros_ec_register()
200 if (!ec_dev->dout) in cros_ec_register()
201 return -ENOMEM; in cros_ec_register()
203 lockdep_register_key(&ec_dev->lockdep_key); in cros_ec_register()
204 mutex_init(&ec_dev->lock); in cros_ec_register()
205 lockdep_set_class(&ec_dev->lock, &ec_dev->lockdep_key); in cros_ec_register()
209 dev_err(dev, "Cannot identify the EC: error %d\n", err); in cros_ec_register()
213 if (ec_dev->irq > 0) { in cros_ec_register()
214 err = devm_request_threaded_irq(dev, ec_dev->irq, in cros_ec_register()
218 "chromeos-ec", ec_dev); in cros_ec_register()
221 ec_dev->irq, err); in cros_ec_register()
226 /* Register a platform device for the main EC instance */ in cros_ec_register()
227 ec_dev->ec = platform_device_register_data(ec_dev->dev, "cros-ec-dev", in cros_ec_register()
230 if (IS_ERR(ec_dev->ec)) { in cros_ec_register()
231 dev_err(ec_dev->dev, in cros_ec_register()
232 "Failed to create CrOS EC platform device\n"); in cros_ec_register()
233 err = PTR_ERR(ec_dev->ec); in cros_ec_register()
237 if (ec_dev->max_passthru) { in cros_ec_register()
239 * Register a platform device for the PD behind the main EC. in cros_ec_register()
241 * - behind an EC, we have a pd in cros_ec_register()
242 * - only one device added. in cros_ec_register()
243 * - the EC is responsive at init time (it is not true for a in cros_ec_register()
246 ec_dev->pd = platform_device_register_data(ec_dev->dev, in cros_ec_register()
247 "cros-ec-dev", in cros_ec_register()
250 if (IS_ERR(ec_dev->pd)) { in cros_ec_register()
251 dev_err(ec_dev->dev, in cros_ec_register()
252 "Failed to create CrOS PD platform device\n"); in cros_ec_register()
253 err = PTR_ERR(ec_dev->pd); in cros_ec_register()
258 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in cros_ec_register()
261 dev_err(dev, "Failed to register sub-devices\n"); in cros_ec_register()
267 * Clear sleep event - this will fail harmlessly on platforms that in cros_ec_register()
272 dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec\n", in cros_ec_register()
275 if (ec_dev->mkbp_event_supported) { in cros_ec_register()
280 ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; in cros_ec_register()
281 err = blocking_notifier_chain_register(&ec_dev->event_notifier, in cros_ec_register()
282 &ec_dev->notifier_ready); in cros_ec_register()
287 dev_info(dev, "Chrome EC device registered\n"); in cros_ec_register()
290 * Unlock EC that may be waiting for AP to process MKBP events. in cros_ec_register()
291 * If the AP takes to long to answer, the EC would stop sending events. in cros_ec_register()
293 if (ec_dev->mkbp_event_supported) in cros_ec_register()
298 platform_device_unregister(ec_dev->ec); in cros_ec_register()
299 platform_device_unregister(ec_dev->pd); in cros_ec_register()
300 mutex_destroy(&ec_dev->lock); in cros_ec_register()
301 lockdep_unregister_key(&ec_dev->lockdep_key); in cros_ec_register()
307 * cros_ec_unregister() - Remove a ChromeOS EC.
310 * Call this to deregister a ChromeOS EC, then clean up any private data.
316 platform_device_unregister(ec_dev->pd); in cros_ec_unregister()
317 platform_device_unregister(ec_dev->ec); in cros_ec_unregister()
318 mutex_destroy(&ec_dev->lock); in cros_ec_unregister()
319 lockdep_unregister_key(&ec_dev->lockdep_key); in cros_ec_unregister()
335 dev_dbg(ec_dev->dev, "Error %d sending suspend event to ec\n", in cros_ec_send_suspend_event()
340 * cros_ec_suspend_prepare() - Handle a suspend prepare operation for the ChromeOS EC device.
356 struct device *dev = ec_dev->dev; in cros_ec_disable_irq()
358 ec_dev->wake_enabled = !enable_irq_wake(ec_dev->irq); in cros_ec_disable_irq()
360 ec_dev->wake_enabled = false; in cros_ec_disable_irq()
362 disable_irq(ec_dev->irq); in cros_ec_disable_irq()
363 ec_dev->suspended = true; in cros_ec_disable_irq()
367 * cros_ec_suspend_late() - Handle a suspend late operation for the ChromeOS EC device.
382 * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device.
401 while (ec_dev->mkbp_event_supported && in cros_ec_report_events_during_suspend()
403 blocking_notifier_call_chain(&ec_dev->event_notifier, in cros_ec_report_events_during_suspend()
406 if (wake_event && device_may_wakeup(ec_dev->dev)) in cros_ec_report_events_during_suspend()
407 pm_wakeup_event(ec_dev->dev, 0); in cros_ec_report_events_during_suspend()
422 dev_dbg(ec_dev->dev, "Error %d sending resume event to ec\n", in cros_ec_send_resume_event()
427 * cros_ec_resume_complete() - Handle a resume complete operation for the ChromeOS EC device.
446 ec_dev->suspended = false; in cros_ec_enable_irq()
447 enable_irq(ec_dev->irq); in cros_ec_enable_irq()
449 if (ec_dev->wake_enabled) in cros_ec_enable_irq()
450 disable_irq_wake(ec_dev->irq); in cros_ec_enable_irq()
454 * cros_ec_resume_early() - Handle a resume early operation for the ChromeOS EC device.
469 * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device.
487 MODULE_DESCRIPTION("ChromeOS EC core driver");