1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
5 * Samsung MFC (Multi Function Codec - FIMV) driver
6 * This file contains hw related functions.
8 * Kamil Debski, Copyright (c) 2012 Samsung Electronics Co., Ltd.
9 * http://www.samsung.com/
12 #include "s5p_mfc_debug.h"
13 #include "s5p_mfc_opr.h"
14 #include "s5p_mfc_opr_v5.h"
15 #include "s5p_mfc_opr_v6.h"
17 static struct s5p_mfc_hw_ops
*s5p_mfc_ops
;
19 void s5p_mfc_init_hw_ops(struct s5p_mfc_dev
*dev
)
21 if (IS_MFCV6_PLUS(dev
)) {
22 s5p_mfc_ops
= s5p_mfc_init_hw_ops_v6();
23 dev
->warn_start
= S5P_FIMV_ERR_WARNINGS_START_V6
;
25 s5p_mfc_ops
= s5p_mfc_init_hw_ops_v5();
26 dev
->warn_start
= S5P_FIMV_ERR_WARNINGS_START
;
28 dev
->mfc_ops
= s5p_mfc_ops
;
31 void s5p_mfc_init_regs(struct s5p_mfc_dev
*dev
)
33 if (IS_MFCV6_PLUS(dev
))
34 dev
->mfc_regs
= s5p_mfc_init_regs_v6_plus(dev
);
37 int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev
*dev
, unsigned int mem_ctx
,
38 struct s5p_mfc_priv_buf
*b
)
40 unsigned int bits
= dev
->mem_size
>> PAGE_SHIFT
;
41 unsigned int count
= b
->size
>> PAGE_SHIFT
;
42 unsigned int align
= (SZ_64K
>> PAGE_SHIFT
) - 1;
43 unsigned int start
, offset
;
45 mfc_debug(3, "Allocating priv: %zu\n", b
->size
);
48 start
= bitmap_find_next_zero_area(dev
->mem_bitmap
, bits
, 0, count
, align
);
52 bitmap_set(dev
->mem_bitmap
, start
, count
);
53 offset
= start
<< PAGE_SHIFT
;
54 b
->virt
= dev
->mem_virt
+ offset
;
55 b
->dma
= dev
->mem_base
+ offset
;
57 struct device
*mem_dev
= dev
->mem_dev
[mem_ctx
];
58 dma_addr_t base
= dev
->dma_base
[mem_ctx
];
61 b
->virt
= dma_alloc_coherent(mem_dev
, b
->size
, &b
->dma
, GFP_KERNEL
);
65 mfc_err("Invalid memory configuration - buffer (%pad) is below base memory address(%pad)\n",
67 dma_free_coherent(mem_dev
, b
->size
, b
->virt
, b
->dma
);
72 mfc_debug(3, "Allocated addr %p %pad\n", b
->virt
, &b
->dma
);
75 mfc_err("Allocating private buffer of size %zu failed\n", b
->size
);
79 int s5p_mfc_alloc_generic_buf(struct s5p_mfc_dev
*dev
, unsigned int mem_ctx
,
80 struct s5p_mfc_priv_buf
*b
)
82 struct device
*mem_dev
= dev
->mem_dev
[mem_ctx
];
84 mfc_debug(3, "Allocating generic buf: %zu\n", b
->size
);
87 b
->virt
= dma_alloc_coherent(mem_dev
, b
->size
, &b
->dma
, GFP_KERNEL
);
91 mfc_debug(3, "Allocated addr %p %pad\n", b
->virt
, &b
->dma
);
94 mfc_err("Allocating generic buffer of size %zu failed\n", b
->size
);
98 void s5p_mfc_release_priv_buf(struct s5p_mfc_dev
*dev
,
99 struct s5p_mfc_priv_buf
*b
)
102 unsigned int start
= (b
->dma
- dev
->mem_base
) >> PAGE_SHIFT
;
103 unsigned int count
= b
->size
>> PAGE_SHIFT
;
105 bitmap_clear(dev
->mem_bitmap
, start
, count
);
107 struct device
*mem_dev
= dev
->mem_dev
[b
->ctx
];
109 dma_free_coherent(mem_dev
, b
->size
, b
->virt
, b
->dma
);
116 void s5p_mfc_release_generic_buf(struct s5p_mfc_dev
*dev
,
117 struct s5p_mfc_priv_buf
*b
)
119 struct device
*mem_dev
= dev
->mem_dev
[b
->ctx
];
120 dma_free_coherent(mem_dev
, b
->size
, b
->virt
, b
->dma
);