Skip to content

Commit c2006b9

Browse files
Yu Qiaoweirkhuangtao
authored andcommitted
video/rockchip: rga2: Support the color palette mode.
1. add support for the BPP8/4/2/1 format used in color palette mode. 2. Add pat support in rga2_get_dma_buf(). 3. Modify the parameters of configuring mmu in color palette mode. Signed-off-by: Yu Qiaowei <cerf.yu@rock-chips.com> Change-Id: I16b498b8d48575688c769486ac7536ddc2d918b4
1 parent a9d5350 commit c2006b9

4 files changed

Lines changed: 111 additions & 21 deletions

File tree

drivers/video/rockchip/rga2/rga2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ enum
116116
RGA2_FORMAT_YCrCb_420_SP_10B = 0x21,
117117
RGA2_FORMAT_YCbCr_422_SP_10B = 0x22,
118118
RGA2_FORMAT_YCrCb_422_SP_10B = 0x23,
119+
120+
RGA2_FORMAT_BPP_1 = 0x24,
121+
RGA2_FORMAT_BPP_2 = 0x25,
122+
RGA2_FORMAT_BPP_4 = 0x26,
123+
RGA2_FORMAT_BPP_8 = 0x27
119124
};
120125

121126
typedef struct mdp_img
@@ -548,6 +553,7 @@ struct rga2_req
548553
struct dma_buf_attachment *attach_src0;
549554
struct dma_buf_attachment *attach_src1;
550555
struct dma_buf_attachment *attach_dst;
556+
struct dma_buf_attachment *attach_els;
551557
};
552558

553559
struct rga2_mmu_buf_t {

drivers/video/rockchip/rga2/rga2_drv.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ static const char *rga2_get_format_name(uint32_t format)
299299
return "YCbCr422SP10B";
300300
case RGA2_FORMAT_YCrCb_422_SP_10B:
301301
return "YCrCb422SP10B";
302+
case RGA2_FORMAT_BPP_1:
303+
return "BPP1";
304+
case RGA2_FORMAT_BPP_2:
305+
return "BPP2";
306+
case RGA2_FORMAT_BPP_4:
307+
return "BPP4";
308+
case RGA2_FORMAT_BPP_8:
309+
return "BPP8";
302310
default:
303311
return "UNF";
304312
}
@@ -1179,6 +1187,7 @@ static int rga2_get_dma_buf(struct rga2_req *req)
11791187
req->attach_src0 = NULL;
11801188
req->attach_dst = NULL;
11811189
req->attach_src1 = NULL;
1190+
req->attach_els = NULL;
11821191
mmu_flag = req->mmu_info.src0_mmu_flag;
11831192
ret = rga2_get_img_info(&req->src, mmu_flag, &req->sg_src0,
11841193
&req->attach_src0);
@@ -1203,8 +1212,24 @@ static int rga2_get_dma_buf(struct rga2_req *req)
12031212
goto err_src1;
12041213
}
12051214

1215+
mmu_flag = req->mmu_info.els_mmu_flag;
1216+
ret = rga2_get_img_info(&req->pat, mmu_flag, &req->sg_els,
1217+
&req->attach_els);
1218+
if (ret) {
1219+
pr_err("els:rga2_get_img_info fail\n");
1220+
goto err_els;
1221+
}
1222+
12061223
return ret;
12071224

1225+
err_els:
1226+
if (req->sg_src1 && req->attach_src1) {
1227+
dma_buf_unmap_attachment(req->attach_src1,
1228+
req->sg_src1, DMA_BIDIRECTIONAL);
1229+
dma_buf = req->attach_src1->dmabuf;
1230+
dma_buf_detach(dma_buf, req->attach_src1);
1231+
dma_buf_put(dma_buf);
1232+
}
12081233
err_src1:
12091234
if (req->sg_dst && req->attach_dst) {
12101235
dma_buf_unmap_attachment(req->attach_dst,

drivers/video/rockchip/rga2/rga2_mmu_info.c

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ static int rga2_mmu_info_color_palette_mode(struct rga2_reg *reg, struct rga2_re
696696
uint32_t stride;
697697

698698
uint8_t shift;
699-
uint16_t sw, byte_num;
699+
uint32_t sw, byte_num;
700700

701701
shift = 3 - (req->palette_mode & 3);
702702
sw = req->src.vir_w*req->src.vir_h;
@@ -710,6 +710,14 @@ static int rga2_mmu_info_color_palette_mode(struct rga2_reg *reg, struct rga2_re
710710

711711
do {
712712
if (req->mmu_info.src0_mmu_flag) {
713+
if (req->mmu_info.els_mmu_flag & 1) {
714+
req->mmu_info.src0_mmu_flag = 0;
715+
req->mmu_info.src1_mmu_flag = 0;
716+
} else {
717+
req->mmu_info.els_mmu_flag = req->mmu_info.src0_mmu_flag;
718+
req->mmu_info.src0_mmu_flag = 0;
719+
}
720+
713721
SrcMemSize = rga2_mem_size_cal(req->src.yrgb_addr, stride, &SrcStart);
714722
if(SrcMemSize == 0) {
715723
return -EINVAL;
@@ -748,28 +756,49 @@ static int rga2_mmu_info_color_palette_mode(struct rga2_reg *reg, struct rga2_re
748756
mutex_unlock(&rga2_service.lock);
749757

750758
if(SrcMemSize) {
751-
ret = rga2_MapUserMemory(&pages[0], &MMU_Base[0],
752-
SrcStart, SrcMemSize, 0);
759+
if (req->sg_src0) {
760+
ret = rga2_MapION(req->sg_src0,
761+
&MMU_Base[0], SrcMemSize);
762+
} else {
763+
ret = rga2_MapUserMemory(&pages[0], &MMU_Base[0],
764+
SrcStart, SrcMemSize, 0);
765+
#if RGA2_DEBUGFS
766+
if (RGA2_CHECK_MODE)
767+
rga2_UserMemory_cheeck(&pages[0], req->src.vir_w,
768+
req->src.vir_h, req->src.format,
769+
1);
770+
#endif
771+
}
753772
if (ret < 0) {
754773
pr_err("rga2 map src0 memory failed\n");
755774
status = ret;
756775
break;
757776
}
758777

759778
/* change the buf address in req struct */
760-
req->mmu_info.src0_base_addr = (((unsigned long)MMU_Base_phys));
779+
req->mmu_info.els_base_addr = (((unsigned long)MMU_Base_phys));
761780
req->src.yrgb_addr = (req->src.yrgb_addr & (~PAGE_MASK));
762781
}
763782

764783
if(DstMemSize) {
765-
ret = rga2_MapUserMemory(&pages[0], MMU_Base + SrcMemSize,
766-
DstStart, DstMemSize, 1);
784+
if (req->sg_dst) {
785+
ret = rga2_MapION(req->sg_dst,
786+
MMU_Base + SrcMemSize, DstMemSize);
787+
} else {
788+
ret = rga2_MapUserMemory(&pages[0], MMU_Base + SrcMemSize,
789+
DstStart, DstMemSize, 1);
790+
#if RGA2_DEBUGFS
791+
if (RGA2_CHECK_MODE)
792+
rga2_UserMemory_cheeck(&pages[0], req->dst.vir_w,
793+
req->dst.vir_h, req->dst.format,
794+
1);
795+
#endif
796+
}
767797
if (ret < 0) {
768798
pr_err("rga2 map dst memory failed\n");
769799
status = ret;
770800
break;
771801
}
772-
773802
/* change the buf address in req struct */
774803
req->mmu_info.dst_base_addr = ((unsigned long)(MMU_Base_phys + SrcMemSize));
775804
req->dst.yrgb_addr = (req->dst.yrgb_addr & (~PAGE_MASK));
@@ -859,49 +888,69 @@ static int rga2_mmu_info_color_fill_mode(struct rga2_reg *reg, struct rga2_req *
859888

860889
static int rga2_mmu_info_update_palette_table_mode(struct rga2_reg *reg, struct rga2_req *req)
861890
{
862-
int SrcMemSize;
863-
unsigned long SrcStart;
891+
int LutMemSize;
892+
unsigned long LutStart;
864893
struct page **pages = NULL;
865894
uint32_t AllSize;
866895
uint32_t *MMU_Base, *MMU_Base_phys;
867896
int ret, status;
868897

869898
MMU_Base = NULL;
899+
LutMemSize = 0;
900+
LutStart = 0;
870901

871902
do {
872-
/* cal src buf mmu info */
873-
SrcMemSize = rga2_mem_size_cal(req->pat.yrgb_addr, req->pat.vir_w * req->pat.vir_h, &SrcStart);
874-
if(SrcMemSize == 0) {
875-
return -EINVAL;
903+
/* cal lut buf mmu info */
904+
if (req->mmu_info.els_mmu_flag & 1) {
905+
req->mmu_info.src0_mmu_flag = req->mmu_info.src0_mmu_flag == 1 ? 0 : req->mmu_info.src0_mmu_flag;
906+
req->mmu_info.src1_mmu_flag = req->mmu_info.src1_mmu_flag == 1 ? 0 : req->mmu_info.src1_mmu_flag;
907+
req->mmu_info.dst_mmu_flag = req->mmu_info.dst_mmu_flag == 1 ? 0 : req->mmu_info.dst_mmu_flag;
908+
909+
LutMemSize = rga2_buf_size_cal(req->pat.yrgb_addr, req->pat.uv_addr, req->pat.v_addr,
910+
req->pat.format, req->pat.vir_w, req->pat.vir_h,
911+
&LutStart);
912+
if(LutMemSize == 0) {
913+
return -EINVAL;
914+
}
876915
}
877916

878-
SrcMemSize = (SrcMemSize + 15) & (~15);
879-
AllSize = SrcMemSize;
917+
LutMemSize = (LutMemSize + 15) & (~15);
918+
AllSize = LutMemSize;
880919

881920
if (rga2_mmu_buf_get_try(&rga2_mmu_buf, AllSize)) {
882921
pr_err("RGA2 Get MMU mem failed\n");
883922
status = RGA2_MALLOC_ERROR;
884923
break;
885924
}
886925

926+
pages = rga2_mmu_buf.pages;
927+
if (pages == NULL) {
928+
pr_err("RGA MMU malloc pages mem failed\n");
929+
return -EINVAL;
930+
}
931+
887932
mutex_lock(&rga2_service.lock);
888933
MMU_Base = rga2_mmu_buf.buf_virtual + (rga2_mmu_buf.front & (rga2_mmu_buf.size - 1));
889934
MMU_Base_phys = rga2_mmu_buf.buf + (rga2_mmu_buf.front & (rga2_mmu_buf.size - 1));
890935
mutex_unlock(&rga2_service.lock);
891936

892-
pages = kzalloc(AllSize * sizeof(struct page *), GFP_KERNEL);
893-
894-
if(SrcMemSize) {
895-
ret = rga2_MapUserMemory(&pages[0], &MMU_Base[0],
896-
SrcStart, SrcMemSize, 0);
937+
if (LutMemSize) {
938+
if (req->sg_els) {
939+
ret = rga2_MapION(req->sg_els,
940+
&MMU_Base[0], LutMemSize);
941+
} else {
942+
ret = rga2_MapUserMemory(&pages[0], &MMU_Base[0],
943+
LutStart, LutMemSize, 0);
944+
}
897945
if (ret < 0) {
898946
pr_err("rga2 map palette memory failed\n");
899947
status = ret;
900948
break;
901949
}
902950

903951
/* change the buf address in req struct */
904-
req->mmu_info.src0_base_addr = (((unsigned long)MMU_Base_phys));
952+
req->mmu_info.els_base_addr = (((unsigned long)MMU_Base_phys));
953+
905954
req->pat.yrgb_addr = (req->pat.yrgb_addr & (~PAGE_MASK));
906955
}
907956

drivers/video/rockchip/rga2/rga2_reg_info.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ static void format_name_convert(uint32_t *df, uint32_t sf)
962962
RK_FORMAT_YCrCb_420_SP = 0xe,
963963
RK_FORMAT_YCrCb_420_P = 0xf,
964964
965+
RK_FORMAT_BPP1 = 0x10,
966+
RK_FORMAT_BPP2 = 0x11,
967+
RK_FORMAT_BPP4 = 0x12,
968+
RK_FORMAT_BPP8 = 0x13,
969+
965970
RGA2_FORMAT_RGBA_8888 = 0x0,
966971
RGA2_FORMAT_RGBX_8888 = 0x1,
967972
RGA2_FORMAT_RGB_888 = 0x2,
@@ -1002,6 +1007,11 @@ static void format_name_convert(uint32_t *df, uint32_t sf)
10021007
case 0xe: *df = RGA2_FORMAT_YCrCb_420_SP; break;
10031008
case 0xf: *df = RGA2_FORMAT_YCrCb_420_P; break;
10041009

1010+
case 0x10: *df = RGA2_FORMAT_BPP_1; break;
1011+
case 0x11: *df = RGA2_FORMAT_BPP_2; break;
1012+
case 0x12: *df = RGA2_FORMAT_BPP_4; break;
1013+
case 0x13: *df = RGA2_FORMAT_BPP_8; break;
1014+
10051015
case 0x18: *df = RGA2_FORMAT_YVYU_422; break;
10061016
case 0x19: *df = RGA2_FORMAT_YVYU_420; break;
10071017
case 0x1a: *df = RGA2_FORMAT_VYUY_422; break;

0 commit comments

Comments
 (0)