Lines Matching +full:firmware +full:- +full:reset
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * linux/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
11 #include <linux/firmware.h>
22 /* Allocate memory for firmware */
25 struct s5p_mfc_priv_buf *fw_buf = &dev->fw_buf; in s5p_mfc_alloc_firmware()
28 fw_buf->size = dev->variant->buf_size->fw; in s5p_mfc_alloc_firmware()
30 if (fw_buf->virt) { in s5p_mfc_alloc_firmware()
31 mfc_err("Attempting to allocate firmware when it seems that it is already loaded\n"); in s5p_mfc_alloc_firmware()
32 return -ENOMEM; in s5p_mfc_alloc_firmware()
35 err = s5p_mfc_alloc_priv_buf(dev, BANK_L_CTX, &dev->fw_buf); in s5p_mfc_alloc_firmware()
44 /* Load firmware */
47 struct firmware *fw_blob; in s5p_mfc_load_firmware()
48 int i, err = -EINVAL; in s5p_mfc_load_firmware()
50 /* Firmware has to be present as a separate file or compiled in s5p_mfc_load_firmware()
54 if (dev->fw_get_done) in s5p_mfc_load_firmware()
57 for (i = MFC_FW_MAX_VERSIONS - 1; i >= 0; i--) { in s5p_mfc_load_firmware()
58 if (!dev->variant->fw_name[i]) in s5p_mfc_load_firmware()
60 err = request_firmware((const struct firmware **)&fw_blob, in s5p_mfc_load_firmware()
61 dev->variant->fw_name[i], &dev->plat_dev->dev); in s5p_mfc_load_firmware()
63 dev->fw_ver = (enum s5p_mfc_fw_ver) i; in s5p_mfc_load_firmware()
69 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n"); in s5p_mfc_load_firmware()
70 return -EINVAL; in s5p_mfc_load_firmware()
72 if (fw_blob->size > dev->fw_buf.size) { in s5p_mfc_load_firmware()
73 mfc_err("MFC firmware is too big to be loaded\n"); in s5p_mfc_load_firmware()
75 return -ENOMEM; in s5p_mfc_load_firmware()
77 memcpy(dev->fw_buf.virt, fw_blob->data, fw_blob->size); in s5p_mfc_load_firmware()
79 dev->fw_get_done = true; in s5p_mfc_load_firmware()
85 /* Release firmware memory */
90 s5p_mfc_release_priv_buf(dev, &dev->fw_buf); in s5p_mfc_release_firmware()
91 dev->fw_get_done = false; in s5p_mfc_release_firmware()
100 /* Reset */ in s5p_mfc_bus_reset()
107 return -EIO; in s5p_mfc_bus_reset()
114 /* Reset the device */
132 /* check bus reset control before reset */ in s5p_mfc_reset()
133 if (dev->risc_on) in s5p_mfc_reset()
135 return -EIO; in s5p_mfc_reset()
136 /* Reset in s5p_mfc_reset()
138 * V6 needs RISC_ON set to 0 during reset also. in s5p_mfc_reset()
140 if ((!dev->risc_on) || (!IS_MFCV7_PLUS(dev))) in s5p_mfc_reset()
147 /* reset RISC */ in s5p_mfc_reset()
149 /* All reset except for MC */ in s5p_mfc_reset()
158 return -EIO; in s5p_mfc_reset()
176 mfc_write(dev, dev->dma_base[BANK_L_CTX], in s5p_mfc_init_memctrl()
179 &dev->dma_base[BANK_L_CTX]); in s5p_mfc_init_memctrl()
181 mfc_write(dev, dev->dma_base[BANK_L_CTX], in s5p_mfc_init_memctrl()
183 mfc_write(dev, dev->dma_base[BANK_R_CTX], in s5p_mfc_init_memctrl()
186 &dev->dma_base[BANK_L_CTX], in s5p_mfc_init_memctrl()
187 &dev->dma_base[BANK_R_CTX]); in s5p_mfc_init_memctrl()
194 /* Zero initialization should be done before RESET. in s5p_mfc_clear_cmds()
211 if (!dev->fw_buf.virt) { in s5p_mfc_init_hw()
212 mfc_err("Firmware memory is not allocated.\n"); in s5p_mfc_init_hw()
213 return -EINVAL; in s5p_mfc_init_hw()
216 /* 0. MFC reset */ in s5p_mfc_init_hw()
217 mfc_debug(2, "MFC reset..\n"); in s5p_mfc_init_hw()
219 dev->risc_on = 0; in s5p_mfc_init_hw()
222 mfc_err("Failed to reset MFC - timeout\n"); in s5p_mfc_init_hw()
225 mfc_debug(2, "Done MFC reset..\n"); in s5p_mfc_init_hw()
230 /* 3. Release reset signal to the RISC */ in s5p_mfc_init_hw()
233 dev->risc_on = 1; in s5p_mfc_init_hw()
242 mfc_debug(2, "Will now wait for completion of firmware transfer\n"); in s5p_mfc_init_hw()
244 mfc_err("Failed to load firmware\n"); in s5p_mfc_init_hw()
247 return -EIO; in s5p_mfc_init_hw()
250 /* 4. Initialize firmware */ in s5p_mfc_init_hw()
251 ret = s5p_mfc_hw_call(dev->mfc_cmds, sys_init_cmd, dev); in s5p_mfc_init_hw()
253 mfc_err("Failed to send command to MFC - timeout\n"); in s5p_mfc_init_hw()
263 return -EIO; in s5p_mfc_init_hw()
265 dev->int_cond = 0; in s5p_mfc_init_hw()
266 if (dev->int_err != 0 || dev->int_type != in s5p_mfc_init_hw()
269 mfc_err("Failed to init firmware - error: %d int: %d\n", in s5p_mfc_init_hw()
270 dev->int_err, dev->int_type); in s5p_mfc_init_hw()
273 return -EIO; in s5p_mfc_init_hw()
294 s5p_mfc_hw_call(dev->mfc_ops, release_dev_context_buffer, dev); in s5p_mfc_deinit_hw()
306 ret = s5p_mfc_hw_call(dev->mfc_cmds, sleep_cmd, dev); in s5p_mfc_sleep()
308 mfc_err("Failed to send command to MFC - timeout\n"); in s5p_mfc_sleep()
313 return -EIO; in s5p_mfc_sleep()
316 dev->int_cond = 0; in s5p_mfc_sleep()
317 if (dev->int_err != 0 || dev->int_type != in s5p_mfc_sleep()
320 mfc_err("Failed to sleep - error: %d int: %d\n", dev->int_err, in s5p_mfc_sleep()
321 dev->int_type); in s5p_mfc_sleep()
322 return -EIO; in s5p_mfc_sleep()
332 /* Release reset signal to the RISC */ in s5p_mfc_v8_wait_wakeup()
333 dev->risc_on = 1; in s5p_mfc_v8_wait_wakeup()
337 mfc_err("Failed to reset MFCV8\n"); in s5p_mfc_v8_wait_wakeup()
338 return -EIO; in s5p_mfc_v8_wait_wakeup()
341 ret = s5p_mfc_hw_call(dev->mfc_cmds, wakeup_cmd, dev); in s5p_mfc_v8_wait_wakeup()
343 mfc_err("Failed to send command to MFCV8 - timeout\n"); in s5p_mfc_v8_wait_wakeup()
349 return -EIO; in s5p_mfc_v8_wait_wakeup()
359 ret = s5p_mfc_hw_call(dev->mfc_cmds, wakeup_cmd, dev); in s5p_mfc_wait_wakeup()
361 mfc_err("Failed to send command to MFC - timeout\n"); in s5p_mfc_wait_wakeup()
365 /* Release reset signal to the RISC */ in s5p_mfc_wait_wakeup()
367 dev->risc_on = 1; in s5p_mfc_wait_wakeup()
375 return -EIO; in s5p_mfc_wait_wakeup()
385 /* 0. MFC reset */ in s5p_mfc_wakeup()
386 mfc_debug(2, "MFC reset..\n"); in s5p_mfc_wakeup()
388 dev->risc_on = 0; in s5p_mfc_wakeup()
391 mfc_err("Failed to reset MFC - timeout\n"); in s5p_mfc_wakeup()
395 mfc_debug(2, "Done MFC reset..\n"); in s5p_mfc_wakeup()
411 dev->int_cond = 0; in s5p_mfc_wakeup()
412 if (dev->int_err != 0 || dev->int_type != in s5p_mfc_wakeup()
415 mfc_err("Failed to wakeup - error: %d int: %d\n", dev->int_err, in s5p_mfc_wakeup()
416 dev->int_type); in s5p_mfc_wakeup()
417 return -EIO; in s5p_mfc_wakeup()
427 ret = s5p_mfc_hw_call(dev->mfc_ops, alloc_instance_buffer, ctx); in s5p_mfc_open_mfc_inst()
433 if (ctx->type == MFCINST_DECODER) { in s5p_mfc_open_mfc_inst()
434 ret = s5p_mfc_hw_call(dev->mfc_ops, in s5p_mfc_open_mfc_inst()
443 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev); in s5p_mfc_open_mfc_inst()
448 ret = -EIO; in s5p_mfc_open_mfc_inst()
452 mfc_debug(2, "Got instance number: %d\n", ctx->inst_no); in s5p_mfc_open_mfc_inst()
456 if (ctx->type == MFCINST_DECODER) in s5p_mfc_open_mfc_inst()
457 s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx); in s5p_mfc_open_mfc_inst()
459 s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx); in s5p_mfc_open_mfc_inst()
466 ctx->state = MFCINST_RETURN_INST; in s5p_mfc_close_mfc_inst()
468 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev); in s5p_mfc_close_mfc_inst()
475 s5p_mfc_hw_call(dev->mfc_ops, release_codec_buffers, ctx); in s5p_mfc_close_mfc_inst()
476 s5p_mfc_hw_call(dev->mfc_ops, release_instance_buffer, ctx); in s5p_mfc_close_mfc_inst()
477 if (ctx->type == MFCINST_DECODER) in s5p_mfc_close_mfc_inst()
478 s5p_mfc_hw_call(dev->mfc_ops, release_dec_desc_buffer, ctx); in s5p_mfc_close_mfc_inst()
480 ctx->inst_no = MFC_NO_INSTANCE_SET; in s5p_mfc_close_mfc_inst()
481 ctx->state = MFCINST_FREE; in s5p_mfc_close_mfc_inst()