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 u8 state = cdev->state == MIC_RESETTING ? in cosm_stop()
157 cdev->prev_state : cdev->state; in cosm_stop()
161 if (cdev->state != MIC_RESETTING) in cosm_stop()
162 cosm_set_state(cdev, MIC_RESETTING); in cosm_stop()
163 cdev->heartbeat_watchdog_enable = false; in cosm_stop()
165 cdev->hw_ops->stop(cdev, force); in cosm_stop()
166 cosm_hw_reset(cdev, force); in cosm_stop()
167 cosm_set_shutdown_status(cdev, MIC_NOP); in cosm_stop()
168 if (call_hw_ops && cdev->hw_ops->post_reset) in cosm_stop()
169 cdev->hw_ops->post_reset(cdev, cdev->state); in cosm_stop()
171 mutex_unlock(&cdev->cosm_mutex); in cosm_stop()
172 flush_work(&cdev->scif_work); in cosm_stop()
183 struct cosm_device *cdev = container_of(work, struct cosm_device, in cosm_reset_trigger_work() local
185 cosm_stop(cdev, false); in cosm_reset_trigger_work()
194 int cosm_reset(struct cosm_device *cdev) in cosm_reset() argument
198 mutex_lock(&cdev->cosm_mutex); in cosm_reset()
199 if (cdev->state != MIC_READY) { in cosm_reset()
200 if (cdev->state != MIC_RESETTING) { in cosm_reset()
201 cdev->prev_state = cdev->state; in cosm_reset()
202 cosm_set_state(cdev, MIC_RESETTING); in cosm_reset()
203 schedule_work(&cdev->reset_trigger_work); in cosm_reset()
206 dev_err(&cdev->dev, "%s %d MIC is READY\n", __func__, __LINE__); in cosm_reset()
209 mutex_unlock(&cdev->cosm_mutex); in cosm_reset()
219 int cosm_shutdown(struct cosm_device *cdev) in cosm_shutdown() argument
224 mutex_lock(&cdev->cosm_mutex); in cosm_shutdown()
225 if (cdev->state != MIC_ONLINE) { in cosm_shutdown()
227 dev_err(&cdev->dev, "%s %d skipping shutdown in state: %s\n", in cosm_shutdown()
228 __func__, __LINE__, cosm_state_string[cdev->state]); in cosm_shutdown()
232 if (!cdev->epd) { in cosm_shutdown()
234 dev_err(&cdev->dev, "%s %d scif endpoint not connected rc %d\n", in cosm_shutdown()
239 rc = scif_send(cdev->epd, &msg, sizeof(msg), SCIF_SEND_BLOCK); in cosm_shutdown()
241 dev_err(&cdev->dev, "%s %d scif_send failed rc %d\n", in cosm_shutdown()
245 cdev->heartbeat_watchdog_enable = false; in cosm_shutdown()
246 cosm_set_state(cdev, MIC_SHUTTING_DOWN); in cosm_shutdown()
249 mutex_unlock(&cdev->cosm_mutex); in cosm_shutdown()
253 static int cosm_driver_probe(struct cosm_device *cdev) in cosm_driver_probe() argument
263 mutex_init(&cdev->cosm_mutex); in cosm_driver_probe()
264 INIT_WORK(&cdev->reset_trigger_work, cosm_reset_trigger_work); in cosm_driver_probe()
265 INIT_WORK(&cdev->scif_work, cosm_scif_work); in cosm_driver_probe()
266 cdev->sysfs_heartbeat_enable = true; in cosm_driver_probe()
267 cosm_sysfs_init(cdev); in cosm_driver_probe()
268 cdev->sdev = device_create_with_groups(g_cosm_class, cdev->dev.parent, in cosm_driver_probe()
269 MKDEV(0, cdev->index), cdev, cdev->attr_group, in cosm_driver_probe()
270 "mic%d", cdev->index); in cosm_driver_probe()
271 if (IS_ERR(cdev->sdev)) { in cosm_driver_probe()
272 rc = PTR_ERR(cdev->sdev); in cosm_driver_probe()
273 dev_err(&cdev->dev, "device_create_with_groups failed rc %d\n", in cosm_driver_probe()
278 cdev->state_sysfs = sysfs_get_dirent(cdev->sdev->kobj.sd, in cosm_driver_probe()
280 if (!cdev->state_sysfs) { in cosm_driver_probe()
282 dev_err(&cdev->dev, "sysfs_get_dirent failed rc %d\n", rc); in cosm_driver_probe()
285 cosm_create_debug_dir(cdev); in cosm_driver_probe()
288 device_destroy(g_cosm_class, MKDEV(0, cdev->index)); in cosm_driver_probe()
295 static void cosm_driver_remove(struct cosm_device *cdev) in cosm_driver_remove() argument
297 cosm_delete_debug_dir(cdev); in cosm_driver_remove()
298 sysfs_put(cdev->state_sysfs); in cosm_driver_remove()
299 device_destroy(g_cosm_class, MKDEV(0, cdev->index)); in cosm_driver_remove()
300 flush_work(&cdev->reset_trigger_work); in cosm_driver_remove()
301 cosm_stop(cdev, false); in cosm_driver_remove()
306 kfree(cdev->cmdline); in cosm_driver_remove()
307 kfree(cdev->firmware); in cosm_driver_remove()
308 kfree(cdev->ramdisk); in cosm_driver_remove()
309 kfree(cdev->bootmode); in cosm_driver_remove()
314 struct cosm_device *cdev = dev_to_cosm(dev); in cosm_suspend() local
316 mutex_lock(&cdev->cosm_mutex); in cosm_suspend()
317 switch (cdev->state) { in cosm_suspend()
327 mutex_unlock(&cdev->cosm_mutex); in cosm_suspend()
328 cosm_stop(cdev, false); in cosm_suspend()
331 mutex_unlock(&cdev->cosm_mutex); in cosm_suspend()