blob: 98abd724748c50067b2de0f76d89454c0d11f6f5 [file] [log] [blame]
Srinu Gorlecf8c6752018-01-19 18:36:13 +05301/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#include <linux/slab.h>
14#include "msm_vidc_debug.h"
15#include "vidc_hfi_api.h"
16#include "venus_hfi.h"
17
18struct hfi_device *vidc_hfi_initialize(enum msm_vidc_hfi_type hfi_type,
19 u32 device_id, struct msm_vidc_platform_resources *res,
20 hfi_cmd_response_callback callback)
21{
22 struct hfi_device *hdev = NULL;
23 int rc = 0;
24
25 hdev = (struct hfi_device *)
26 kzalloc(sizeof(struct hfi_device), GFP_KERNEL);
27 if (!hdev) {
28 dprintk(VIDC_ERR, "%s: failed to allocate hdev\n", __func__);
29 return NULL;
30 }
31
32 switch (hfi_type) {
33 case VIDC_HFI_VENUS:
34 rc = venus_hfi_initialize(hdev, device_id, res, callback);
35 break;
36 default:
37 dprintk(VIDC_ERR, "Unsupported host-firmware interface\n");
38 goto err_hfi_init;
39 }
40
41 if (rc) {
42 if (rc != -EPROBE_DEFER)
43 dprintk(VIDC_ERR, "%s device init failed rc = %d",
44 __func__, rc);
45 goto err_hfi_init;
46 }
47
48 return hdev;
49
50err_hfi_init:
51 kfree(hdev);
52 return ERR_PTR(rc);
53}
54
55void vidc_hfi_deinitialize(enum msm_vidc_hfi_type hfi_type,
56 struct hfi_device *hdev)
57{
58 if (!hdev) {
59 dprintk(VIDC_ERR, "%s invalid device %pK", __func__, hdev);
60 return;
61 }
62
63 switch (hfi_type) {
64 case VIDC_HFI_VENUS:
65 venus_hfi_delete_device(hdev->hfi_device_data);
66 break;
67 default:
68 dprintk(VIDC_ERR, "Unsupported host-firmware interface\n");
69 }
70
71 kfree(hdev);
72}
73