Lines Matching +full:j721s2 +full:- +full:wave521c

1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * Wave5 series multi-standard codec IP - platform driver
5 * Copyright (C) 2021-2023 CHIPS&MEDIA INC
14 #include "wave5-vpu.h"
15 #include "wave5-regdefine.h"
16 #include "wave5-vpuconfig.h"
38 ret = wait_for_completion_timeout(&inst->irq_done, in wave5_vpu_wait_interrupt()
41 return -ETIMEDOUT; in wave5_vpu_wait_interrupt()
43 reinit_completion(&inst->irq_done); in wave5_vpu_wait_interrupt()
60 list_for_each_entry(inst, &dev->instances, list) { in wave5_vpu_handle_irq()
66 if (dev->product_code == WAVE515_CODE && in wave5_vpu_handle_irq()
67 (cmd_done & BIT(inst->id))) { in wave5_vpu_handle_irq()
68 cmd_done &= ~BIT(inst->id); in wave5_vpu_handle_irq()
71 complete(&inst->irq_done); in wave5_vpu_handle_irq()
72 } else if (seq_done & BIT(inst->id)) { in wave5_vpu_handle_irq()
73 seq_done &= ~BIT(inst->id); in wave5_vpu_handle_irq()
76 complete(&inst->irq_done); in wave5_vpu_handle_irq()
82 if (cmd_done & BIT(inst->id)) { in wave5_vpu_handle_irq()
83 cmd_done &= ~BIT(inst->id); in wave5_vpu_handle_irq()
86 inst->ops->finish_process(inst); in wave5_vpu_handle_irq()
117 kthread_queue_work(dev->worker, &dev->work); in wave5_vpu_timer_callback()
136 ret = wave5_vpu_init_with_bitcode(dev, (u8 *)fw->data, fw->size); in wave5_vpu_load_firmware()
163 match_data = device_get_match_data(&pdev->dev); in wave5_vpu_probe()
165 dev_err(&pdev->dev, "missing device match data\n"); in wave5_vpu_probe()
166 return -EINVAL; in wave5_vpu_probe()
170 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); in wave5_vpu_probe()
172 dev_err(&pdev->dev, "Failed to set DMA mask: %d\n", ret); in wave5_vpu_probe()
176 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in wave5_vpu_probe()
178 return -ENOMEM; in wave5_vpu_probe()
180 dev->vdb_register = devm_platform_ioremap_resource(pdev, 0); in wave5_vpu_probe()
181 if (IS_ERR(dev->vdb_register)) in wave5_vpu_probe()
182 return PTR_ERR(dev->vdb_register); in wave5_vpu_probe()
183 ida_init(&dev->inst_ida); in wave5_vpu_probe()
185 mutex_init(&dev->dev_lock); in wave5_vpu_probe()
186 mutex_init(&dev->hw_lock); in wave5_vpu_probe()
187 dev_set_drvdata(&pdev->dev, dev); in wave5_vpu_probe()
188 dev->dev = &pdev->dev; in wave5_vpu_probe()
190 dev->resets = devm_reset_control_array_get_optional_exclusive(&pdev->dev); in wave5_vpu_probe()
191 if (IS_ERR(dev->resets)) { in wave5_vpu_probe()
192 return dev_err_probe(&pdev->dev, PTR_ERR(dev->resets), in wave5_vpu_probe()
196 ret = reset_control_deassert(dev->resets); in wave5_vpu_probe()
198 return dev_err_probe(&pdev->dev, ret, "Failed to deassert resets\n"); in wave5_vpu_probe()
200 ret = devm_clk_bulk_get_all(&pdev->dev, &dev->clks); in wave5_vpu_probe()
204 dev_warn(&pdev->dev, "Getting clocks, fail: %d\n", ret); in wave5_vpu_probe()
207 dev->num_clks = ret; in wave5_vpu_probe()
209 ret = clk_bulk_prepare_enable(dev->num_clks, dev->clks); in wave5_vpu_probe()
211 dev_err(&pdev->dev, "Enabling clocks, fail: %d\n", ret); in wave5_vpu_probe()
215 dev->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0); in wave5_vpu_probe()
216 if (!dev->sram_pool) in wave5_vpu_probe()
217 dev_warn(&pdev->dev, "sram node not found\n"); in wave5_vpu_probe()
219 dev->sram_size = match_data->sram_size; in wave5_vpu_probe()
221 dev->product_code = wave5_vdi_read_register(dev, VPU_PRODUCT_CODE_REGISTER); in wave5_vpu_probe()
222 ret = wave5_vdi_init(&pdev->dev); in wave5_vpu_probe()
224 dev_err(&pdev->dev, "wave5_vdi_init, fail: %d\n", ret); in wave5_vpu_probe()
227 dev->product = wave5_vpu_get_product_id(dev); in wave5_vpu_probe()
229 dev->irq = platform_get_irq(pdev, 0); in wave5_vpu_probe()
230 if (dev->irq < 0) { in wave5_vpu_probe()
231 dev_err(&pdev->dev, "failed to get irq resource, falling back to polling\n"); in wave5_vpu_probe()
232 hrtimer_init(&dev->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); in wave5_vpu_probe()
233 dev->hrtimer.function = &wave5_vpu_timer_callback; in wave5_vpu_probe()
234 dev->worker = kthread_create_worker(0, "vpu_irq_thread"); in wave5_vpu_probe()
235 if (IS_ERR(dev->worker)) { in wave5_vpu_probe()
236 dev_err(&pdev->dev, "failed to create vpu irq worker\n"); in wave5_vpu_probe()
237 ret = PTR_ERR(dev->worker); in wave5_vpu_probe()
240 dev->vpu_poll_interval = vpu_poll_interval; in wave5_vpu_probe()
241 kthread_init_work(&dev->work, wave5_vpu_irq_work_fn); in wave5_vpu_probe()
243 ret = devm_request_threaded_irq(&pdev->dev, dev->irq, NULL, in wave5_vpu_probe()
246 dev_err(&pdev->dev, "Register interrupt handler, fail: %d\n", ret); in wave5_vpu_probe()
251 INIT_LIST_HEAD(&dev->instances); in wave5_vpu_probe()
252 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); in wave5_vpu_probe()
254 dev_err(&pdev->dev, "v4l2_device_register, fail: %d\n", ret); in wave5_vpu_probe()
258 if (match_data->flags & WAVE5_IS_DEC) { in wave5_vpu_probe()
261 dev_err(&pdev->dev, "wave5_vpu_dec_register_device, fail: %d\n", ret); in wave5_vpu_probe()
265 if (match_data->flags & WAVE5_IS_ENC) { in wave5_vpu_probe()
268 dev_err(&pdev->dev, "wave5_vpu_enc_register_device, fail: %d\n", ret); in wave5_vpu_probe()
273 ret = wave5_vpu_load_firmware(&pdev->dev, match_data->fw_name, &fw_revision); in wave5_vpu_probe()
275 dev_err(&pdev->dev, "wave5_vpu_load_firmware, fail: %d\n", ret); in wave5_vpu_probe()
279 dev_info(&pdev->dev, "Added wave5 driver with caps: %s %s\n", in wave5_vpu_probe()
280 (match_data->flags & WAVE5_IS_ENC) ? "'ENCODE'" : "", in wave5_vpu_probe()
281 (match_data->flags & WAVE5_IS_DEC) ? "'DECODE'" : ""); in wave5_vpu_probe()
282 dev_info(&pdev->dev, "Product Code: 0x%x\n", dev->product_code); in wave5_vpu_probe()
283 dev_info(&pdev->dev, "Firmware Revision: %u\n", fw_revision); in wave5_vpu_probe()
287 if (match_data->flags & WAVE5_IS_ENC) in wave5_vpu_probe()
290 if (match_data->flags & WAVE5_IS_DEC) in wave5_vpu_probe()
293 v4l2_device_unregister(&dev->v4l2_dev); in wave5_vpu_probe()
295 wave5_vdi_release(&pdev->dev); in wave5_vpu_probe()
297 clk_bulk_disable_unprepare(dev->num_clks, dev->clks); in wave5_vpu_probe()
299 reset_control_assert(dev->resets); in wave5_vpu_probe()
306 struct vpu_device *dev = dev_get_drvdata(&pdev->dev); in wave5_vpu_remove()
308 if (dev->irq < 0) { in wave5_vpu_remove()
309 kthread_destroy_worker(dev->worker); in wave5_vpu_remove()
310 hrtimer_cancel(&dev->hrtimer); in wave5_vpu_remove()
313 mutex_destroy(&dev->dev_lock); in wave5_vpu_remove()
314 mutex_destroy(&dev->hw_lock); in wave5_vpu_remove()
315 reset_control_assert(dev->resets); in wave5_vpu_remove()
316 clk_bulk_disable_unprepare(dev->num_clks, dev->clks); in wave5_vpu_remove()
319 v4l2_device_unregister(&dev->v4l2_dev); in wave5_vpu_remove()
320 wave5_vdi_release(&pdev->dev); in wave5_vpu_remove()
321 ida_destroy(&dev->inst_ida); in wave5_vpu_remove()
331 { .compatible = "ti,j721s2-wave521c", .data = &ti_wave521c_data },