Lines Matching refs:cdev

30 static void cosm_hw_reset(struct cosm_device *cdev, bool force)  in cosm_hw_reset()  argument
35 if (force && cdev->hw_ops->force_reset) in cosm_hw_reset()
36 cdev->hw_ops->force_reset(cdev); in cosm_hw_reset()
38 cdev->hw_ops->reset(cdev); in cosm_hw_reset()
41 if (cdev->hw_ops->ready(cdev)) { in cosm_hw_reset()
42 cosm_set_state(cdev, MIC_READY); in cosm_hw_reset()
52 cosm_set_state(cdev, MIC_RESET_FAILED); in cosm_hw_reset()
62 int cosm_start(struct cosm_device *cdev) in cosm_start() argument
68 mutex_lock(&cdev->cosm_mutex); in cosm_start()
69 if (!cdev->bootmode) { in cosm_start()
70 dev_err(&cdev->dev, "%s %d bootmode not set\n", in cosm_start()
76 if (cdev->state != MIC_READY) { in cosm_start()
77 dev_err(&cdev->dev, "%s %d MIC state not READY\n", in cosm_start()
82 if (!cdev->hw_ops->ready(cdev)) { in cosm_start()
83 cosm_hw_reset(cdev, false); in cosm_start()
97 dev_err(&cdev->dev, "%s %d prepare_creds failed\n", in cosm_start()
105 rc = cdev->hw_ops->start(cdev, cdev->index); in cosm_start()
117 if (!strcmp(cdev->bootmode, "linux")) in cosm_start()
118 cosm_set_state(cdev, MIC_BOOTING); in cosm_start()
120 cosm_set_state(cdev, MIC_ONLINE); in cosm_start()
122 mutex_unlock(&cdev->cosm_mutex); in cosm_start()
124 dev_err(&cdev->dev, "cosm_start failed rc %d\n", rc); in cosm_start()
135 void cosm_stop(struct cosm_device *cdev, bool force) in cosm_stop() argument
137 mutex_lock(&cdev->cosm_mutex); in cosm_stop()
138 if (cdev->state != MIC_READY || force) { in cosm_stop()
144 u8 state = cdev->state == MIC_RESETTING ? in cosm_stop()
145 cdev->prev_state : cdev->state; in cosm_stop()
149 if (cdev->state != MIC_RESETTING) in cosm_stop()
150 cosm_set_state(cdev, MIC_RESETTING); in cosm_stop()
151 cdev->heartbeat_watchdog_enable = false; in cosm_stop()
153 cdev->hw_ops->stop(cdev, force); in cosm_stop()
154 cosm_hw_reset(cdev, force); in cosm_stop()
155 cosm_set_shutdown_status(cdev, MIC_NOP); in cosm_stop()
156 if (call_hw_ops && cdev->hw_ops->post_reset) in cosm_stop()
157 cdev->hw_ops->post_reset(cdev, cdev->state); in cosm_stop()
159 mutex_unlock(&cdev->cosm_mutex); in cosm_stop()
160 flush_work(&cdev->scif_work); in cosm_stop()
171 struct cosm_device *cdev = container_of(work, struct cosm_device, in cosm_reset_trigger_work() local
173 cosm_stop(cdev, false); in cosm_reset_trigger_work()
182 int cosm_reset(struct cosm_device *cdev) in cosm_reset() argument
186 mutex_lock(&cdev->cosm_mutex); in cosm_reset()
187 if (cdev->state != MIC_READY) { in cosm_reset()
188 if (cdev->state != MIC_RESETTING) { in cosm_reset()
189 cdev->prev_state = cdev->state; in cosm_reset()
190 cosm_set_state(cdev, MIC_RESETTING); in cosm_reset()
191 schedule_work(&cdev->reset_trigger_work); in cosm_reset()
194 dev_err(&cdev->dev, "%s %d MIC is READY\n", __func__, __LINE__); in cosm_reset()
197 mutex_unlock(&cdev->cosm_mutex); in cosm_reset()
207 int cosm_shutdown(struct cosm_device *cdev) in cosm_shutdown() argument
212 mutex_lock(&cdev->cosm_mutex); in cosm_shutdown()
213 if (cdev->state != MIC_ONLINE) { in cosm_shutdown()
215 dev_err(&cdev->dev, "%s %d skipping shutdown in state: %s\n", in cosm_shutdown()
216 __func__, __LINE__, cosm_state_string[cdev->state]); in cosm_shutdown()
220 if (!cdev->epd) { in cosm_shutdown()
222 dev_err(&cdev->dev, "%s %d scif endpoint not connected rc %d\n", in cosm_shutdown()
227 rc = scif_send(cdev->epd, &msg, sizeof(msg), SCIF_SEND_BLOCK); in cosm_shutdown()
229 dev_err(&cdev->dev, "%s %d scif_send failed rc %d\n", in cosm_shutdown()
233 cdev->heartbeat_watchdog_enable = false; in cosm_shutdown()
234 cosm_set_state(cdev, MIC_SHUTTING_DOWN); in cosm_shutdown()
237 mutex_unlock(&cdev->cosm_mutex); in cosm_shutdown()
241 static int cosm_driver_probe(struct cosm_device *cdev) in cosm_driver_probe() argument
251 mutex_init(&cdev->cosm_mutex); in cosm_driver_probe()
252 INIT_WORK(&cdev->reset_trigger_work, cosm_reset_trigger_work); in cosm_driver_probe()
253 INIT_WORK(&cdev->scif_work, cosm_scif_work); in cosm_driver_probe()
254 cdev->sysfs_heartbeat_enable = true; in cosm_driver_probe()
255 cosm_sysfs_init(cdev); in cosm_driver_probe()
256 cdev->sdev = device_create_with_groups(g_cosm_class, cdev->dev.parent, in cosm_driver_probe()
257 MKDEV(0, cdev->index), cdev, cdev->attr_group, in cosm_driver_probe()
258 "mic%d", cdev->index); in cosm_driver_probe()
259 if (IS_ERR(cdev->sdev)) { in cosm_driver_probe()
260 rc = PTR_ERR(cdev->sdev); in cosm_driver_probe()
261 dev_err(&cdev->dev, "device_create_with_groups failed rc %d\n", in cosm_driver_probe()
266 cdev->state_sysfs = sysfs_get_dirent(cdev->sdev->kobj.sd, in cosm_driver_probe()
268 if (!cdev->state_sysfs) { in cosm_driver_probe()
270 dev_err(&cdev->dev, "sysfs_get_dirent failed rc %d\n", rc); in cosm_driver_probe()
273 cosm_create_debug_dir(cdev); in cosm_driver_probe()
276 device_destroy(g_cosm_class, MKDEV(0, cdev->index)); in cosm_driver_probe()
283 static void cosm_driver_remove(struct cosm_device *cdev) in cosm_driver_remove() argument
285 cosm_delete_debug_dir(cdev); in cosm_driver_remove()
286 sysfs_put(cdev->state_sysfs); in cosm_driver_remove()
287 device_destroy(g_cosm_class, MKDEV(0, cdev->index)); in cosm_driver_remove()
288 flush_work(&cdev->reset_trigger_work); in cosm_driver_remove()
289 cosm_stop(cdev, false); in cosm_driver_remove()
294 kfree(cdev->cmdline); in cosm_driver_remove()
295 kfree(cdev->firmware); in cosm_driver_remove()
296 kfree(cdev->ramdisk); in cosm_driver_remove()
297 kfree(cdev->bootmode); in cosm_driver_remove()
302 struct cosm_device *cdev = dev_to_cosm(dev); in cosm_suspend() local
304 mutex_lock(&cdev->cosm_mutex); in cosm_suspend()
305 switch (cdev->state) { in cosm_suspend()
315 mutex_unlock(&cdev->cosm_mutex); in cosm_suspend()
316 cosm_stop(cdev, false); in cosm_suspend()
319 mutex_unlock(&cdev->cosm_mutex); in cosm_suspend()