Lines Matching refs:cdev
42 static void cosm_hw_reset(struct cosm_device *cdev, bool force) in cosm_hw_reset() argument
47 if (force && cdev->hw_ops->force_reset) in cosm_hw_reset()
48 cdev->hw_ops->force_reset(cdev); in cosm_hw_reset()
50 cdev->hw_ops->reset(cdev); in cosm_hw_reset()
53 if (cdev->hw_ops->ready(cdev)) { in cosm_hw_reset()
54 cosm_set_state(cdev, MIC_READY); in cosm_hw_reset()
64 cosm_set_state(cdev, MIC_RESET_FAILED); in cosm_hw_reset()
74 int cosm_start(struct cosm_device *cdev) in cosm_start() argument
80 mutex_lock(&cdev->cosm_mutex); in cosm_start()
81 if (!cdev->bootmode) { in cosm_start()
82 dev_err(&cdev->dev, "%s %d bootmode not set\n", in cosm_start()
88 if (cdev->state != MIC_READY) { in cosm_start()
89 dev_err(&cdev->dev, "%s %d MIC state not READY\n", in cosm_start()
94 if (!cdev->hw_ops->ready(cdev)) { in cosm_start()
95 cosm_hw_reset(cdev, false); in cosm_start()
109 dev_err(&cdev->dev, "%s %d prepare_creds failed\n", in cosm_start()
117 rc = cdev->hw_ops->start(cdev, cdev->index); in cosm_start()
129 if (!strcmp(cdev->bootmode, "linux")) in cosm_start()
130 cosm_set_state(cdev, MIC_BOOTING); in cosm_start()
132 cosm_set_state(cdev, MIC_ONLINE); in cosm_start()
134 mutex_unlock(&cdev->cosm_mutex); in cosm_start()
136 dev_err(&cdev->dev, "cosm_start failed rc %d\n", rc); in cosm_start()
147 void cosm_stop(struct cosm_device *cdev, bool force) in cosm_stop() argument
149 mutex_lock(&cdev->cosm_mutex); in cosm_stop()
150 if (cdev->state != MIC_READY || force) { in cosm_stop()
156 bool call_hw_ops = cdev->state != MIC_RESET_FAILED && in cosm_stop()
157 cdev->state != MIC_READY; in cosm_stop()
159 if (cdev->state != MIC_RESETTING) in cosm_stop()
160 cosm_set_state(cdev, MIC_RESETTING); in cosm_stop()
161 cdev->heartbeat_watchdog_enable = false; in cosm_stop()
163 cdev->hw_ops->stop(cdev, force); in cosm_stop()
164 cosm_hw_reset(cdev, force); in cosm_stop()
165 cosm_set_shutdown_status(cdev, MIC_NOP); in cosm_stop()
166 if (call_hw_ops && cdev->hw_ops->post_reset) in cosm_stop()
167 cdev->hw_ops->post_reset(cdev, cdev->state); in cosm_stop()
169 mutex_unlock(&cdev->cosm_mutex); in cosm_stop()
170 flush_work(&cdev->scif_work); in cosm_stop()
181 struct cosm_device *cdev = container_of(work, struct cosm_device, in cosm_reset_trigger_work() local
183 cosm_stop(cdev, false); in cosm_reset_trigger_work()
192 int cosm_reset(struct cosm_device *cdev) in cosm_reset() argument
196 mutex_lock(&cdev->cosm_mutex); in cosm_reset()
197 if (cdev->state != MIC_READY) { in cosm_reset()
198 cosm_set_state(cdev, MIC_RESETTING); in cosm_reset()
199 schedule_work(&cdev->reset_trigger_work); in cosm_reset()
201 dev_err(&cdev->dev, "%s %d MIC is READY\n", __func__, __LINE__); in cosm_reset()
204 mutex_unlock(&cdev->cosm_mutex); in cosm_reset()
214 int cosm_shutdown(struct cosm_device *cdev) in cosm_shutdown() argument
219 mutex_lock(&cdev->cosm_mutex); in cosm_shutdown()
220 if (cdev->state != MIC_ONLINE) { in cosm_shutdown()
222 dev_err(&cdev->dev, "%s %d skipping shutdown in state: %s\n", in cosm_shutdown()
223 __func__, __LINE__, cosm_state_string[cdev->state]); in cosm_shutdown()
227 if (!cdev->epd) { in cosm_shutdown()
229 dev_err(&cdev->dev, "%s %d scif endpoint not connected rc %d\n", in cosm_shutdown()
234 rc = scif_send(cdev->epd, &msg, sizeof(msg), SCIF_SEND_BLOCK); in cosm_shutdown()
236 dev_err(&cdev->dev, "%s %d scif_send failed rc %d\n", in cosm_shutdown()
240 cdev->heartbeat_watchdog_enable = false; in cosm_shutdown()
241 cosm_set_state(cdev, MIC_SHUTTING_DOWN); in cosm_shutdown()
244 mutex_unlock(&cdev->cosm_mutex); in cosm_shutdown()
248 static int cosm_driver_probe(struct cosm_device *cdev) in cosm_driver_probe() argument
258 mutex_init(&cdev->cosm_mutex); in cosm_driver_probe()
259 INIT_WORK(&cdev->reset_trigger_work, cosm_reset_trigger_work); in cosm_driver_probe()
260 INIT_WORK(&cdev->scif_work, cosm_scif_work); in cosm_driver_probe()
261 cdev->sysfs_heartbeat_enable = true; in cosm_driver_probe()
262 cosm_sysfs_init(cdev); in cosm_driver_probe()
263 cdev->sdev = device_create_with_groups(g_cosm_class, cdev->dev.parent, in cosm_driver_probe()
264 MKDEV(0, cdev->index), cdev, cdev->attr_group, in cosm_driver_probe()
265 "mic%d", cdev->index); in cosm_driver_probe()
266 if (IS_ERR(cdev->sdev)) { in cosm_driver_probe()
267 rc = PTR_ERR(cdev->sdev); in cosm_driver_probe()
268 dev_err(&cdev->dev, "device_create_with_groups failed rc %d\n", in cosm_driver_probe()
273 cdev->state_sysfs = sysfs_get_dirent(cdev->sdev->kobj.sd, in cosm_driver_probe()
275 if (!cdev->state_sysfs) { in cosm_driver_probe()
277 dev_err(&cdev->dev, "sysfs_get_dirent failed rc %d\n", rc); in cosm_driver_probe()
280 cosm_create_debug_dir(cdev); in cosm_driver_probe()
283 device_destroy(g_cosm_class, MKDEV(0, cdev->index)); in cosm_driver_probe()
290 static void cosm_driver_remove(struct cosm_device *cdev) in cosm_driver_remove() argument
292 cosm_delete_debug_dir(cdev); in cosm_driver_remove()
293 sysfs_put(cdev->state_sysfs); in cosm_driver_remove()
294 device_destroy(g_cosm_class, MKDEV(0, cdev->index)); in cosm_driver_remove()
295 flush_work(&cdev->reset_trigger_work); in cosm_driver_remove()
296 cosm_stop(cdev, false); in cosm_driver_remove()
301 kfree(cdev->cmdline); in cosm_driver_remove()
302 kfree(cdev->firmware); in cosm_driver_remove()
303 kfree(cdev->ramdisk); in cosm_driver_remove()
304 kfree(cdev->bootmode); in cosm_driver_remove()
309 struct cosm_device *cdev = dev_to_cosm(dev); in cosm_suspend() local
311 mutex_lock(&cdev->cosm_mutex); in cosm_suspend()
312 switch (cdev->state) { in cosm_suspend()
322 mutex_unlock(&cdev->cosm_mutex); in cosm_suspend()
323 cosm_stop(cdev, false); in cosm_suspend()
326 mutex_unlock(&cdev->cosm_mutex); in cosm_suspend()