18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for Renesas R-Car VIN 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2016 Renesas Electronics Corp. 68c2ecf20Sopenharmony_ci * Copyright (C) 2011-2013 Renesas Solutions Corp. 78c2ecf20Sopenharmony_ci * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com> 88c2ecf20Sopenharmony_ci * Copyright (C) 2008 Magnus Damm 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Based on the soc-camera rcar_vin driver 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/delay.h> 148c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 158c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <media/videobuf2-dma-contig.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include "rcar-vin.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 228c2ecf20Sopenharmony_ci * HW Functions 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* Register offsets for R-Car VIN */ 268c2ecf20Sopenharmony_ci#define VNMC_REG 0x00 /* Video n Main Control Register */ 278c2ecf20Sopenharmony_ci#define VNMS_REG 0x04 /* Video n Module Status Register */ 288c2ecf20Sopenharmony_ci#define VNFC_REG 0x08 /* Video n Frame Capture Register */ 298c2ecf20Sopenharmony_ci#define VNSLPRC_REG 0x0C /* Video n Start Line Pre-Clip Register */ 308c2ecf20Sopenharmony_ci#define VNELPRC_REG 0x10 /* Video n End Line Pre-Clip Register */ 318c2ecf20Sopenharmony_ci#define VNSPPRC_REG 0x14 /* Video n Start Pixel Pre-Clip Register */ 328c2ecf20Sopenharmony_ci#define VNEPPRC_REG 0x18 /* Video n End Pixel Pre-Clip Register */ 338c2ecf20Sopenharmony_ci#define VNIS_REG 0x2C /* Video n Image Stride Register */ 348c2ecf20Sopenharmony_ci#define VNMB_REG(m) (0x30 + ((m) << 2)) /* Video n Memory Base m Register */ 358c2ecf20Sopenharmony_ci#define VNIE_REG 0x40 /* Video n Interrupt Enable Register */ 368c2ecf20Sopenharmony_ci#define VNINTS_REG 0x44 /* Video n Interrupt Status Register */ 378c2ecf20Sopenharmony_ci#define VNSI_REG 0x48 /* Video n Scanline Interrupt Register */ 388c2ecf20Sopenharmony_ci#define VNMTC_REG 0x4C /* Video n Memory Transfer Control Register */ 398c2ecf20Sopenharmony_ci#define VNDMR_REG 0x58 /* Video n Data Mode Register */ 408c2ecf20Sopenharmony_ci#define VNDMR2_REG 0x5C /* Video n Data Mode Register 2 */ 418c2ecf20Sopenharmony_ci#define VNUVAOF_REG 0x60 /* Video n UV Address Offset Register */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Register offsets specific for Gen2 */ 448c2ecf20Sopenharmony_ci#define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */ 458c2ecf20Sopenharmony_ci#define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */ 468c2ecf20Sopenharmony_ci#define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */ 478c2ecf20Sopenharmony_ci#define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */ 488c2ecf20Sopenharmony_ci#define VNYS_REG 0x50 /* Video n Y Scale Register */ 498c2ecf20Sopenharmony_ci#define VNXS_REG 0x54 /* Video n X Scale Register */ 508c2ecf20Sopenharmony_ci#define VNC1A_REG 0x80 /* Video n Coefficient Set C1A Register */ 518c2ecf20Sopenharmony_ci#define VNC1B_REG 0x84 /* Video n Coefficient Set C1B Register */ 528c2ecf20Sopenharmony_ci#define VNC1C_REG 0x88 /* Video n Coefficient Set C1C Register */ 538c2ecf20Sopenharmony_ci#define VNC2A_REG 0x90 /* Video n Coefficient Set C2A Register */ 548c2ecf20Sopenharmony_ci#define VNC2B_REG 0x94 /* Video n Coefficient Set C2B Register */ 558c2ecf20Sopenharmony_ci#define VNC2C_REG 0x98 /* Video n Coefficient Set C2C Register */ 568c2ecf20Sopenharmony_ci#define VNC3A_REG 0xA0 /* Video n Coefficient Set C3A Register */ 578c2ecf20Sopenharmony_ci#define VNC3B_REG 0xA4 /* Video n Coefficient Set C3B Register */ 588c2ecf20Sopenharmony_ci#define VNC3C_REG 0xA8 /* Video n Coefficient Set C3C Register */ 598c2ecf20Sopenharmony_ci#define VNC4A_REG 0xB0 /* Video n Coefficient Set C4A Register */ 608c2ecf20Sopenharmony_ci#define VNC4B_REG 0xB4 /* Video n Coefficient Set C4B Register */ 618c2ecf20Sopenharmony_ci#define VNC4C_REG 0xB8 /* Video n Coefficient Set C4C Register */ 628c2ecf20Sopenharmony_ci#define VNC5A_REG 0xC0 /* Video n Coefficient Set C5A Register */ 638c2ecf20Sopenharmony_ci#define VNC5B_REG 0xC4 /* Video n Coefficient Set C5B Register */ 648c2ecf20Sopenharmony_ci#define VNC5C_REG 0xC8 /* Video n Coefficient Set C5C Register */ 658c2ecf20Sopenharmony_ci#define VNC6A_REG 0xD0 /* Video n Coefficient Set C6A Register */ 668c2ecf20Sopenharmony_ci#define VNC6B_REG 0xD4 /* Video n Coefficient Set C6B Register */ 678c2ecf20Sopenharmony_ci#define VNC6C_REG 0xD8 /* Video n Coefficient Set C6C Register */ 688c2ecf20Sopenharmony_ci#define VNC7A_REG 0xE0 /* Video n Coefficient Set C7A Register */ 698c2ecf20Sopenharmony_ci#define VNC7B_REG 0xE4 /* Video n Coefficient Set C7B Register */ 708c2ecf20Sopenharmony_ci#define VNC7C_REG 0xE8 /* Video n Coefficient Set C7C Register */ 718c2ecf20Sopenharmony_ci#define VNC8A_REG 0xF0 /* Video n Coefficient Set C8A Register */ 728c2ecf20Sopenharmony_ci#define VNC8B_REG 0xF4 /* Video n Coefficient Set C8B Register */ 738c2ecf20Sopenharmony_ci#define VNC8C_REG 0xF8 /* Video n Coefficient Set C8C Register */ 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* Register offsets specific for Gen3 */ 768c2ecf20Sopenharmony_ci#define VNCSI_IFMD_REG 0x20 /* Video n CSI2 Interface Mode Register */ 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* Register bit fields for R-Car VIN */ 798c2ecf20Sopenharmony_ci/* Video n Main Control Register bits */ 808c2ecf20Sopenharmony_ci#define VNMC_DPINE (1 << 27) /* Gen3 specific */ 818c2ecf20Sopenharmony_ci#define VNMC_SCLE (1 << 26) /* Gen3 specific */ 828c2ecf20Sopenharmony_ci#define VNMC_FOC (1 << 21) 838c2ecf20Sopenharmony_ci#define VNMC_YCAL (1 << 19) 848c2ecf20Sopenharmony_ci#define VNMC_INF_YUV8_BT656 (0 << 16) 858c2ecf20Sopenharmony_ci#define VNMC_INF_YUV8_BT601 (1 << 16) 868c2ecf20Sopenharmony_ci#define VNMC_INF_YUV10_BT656 (2 << 16) 878c2ecf20Sopenharmony_ci#define VNMC_INF_YUV10_BT601 (3 << 16) 888c2ecf20Sopenharmony_ci#define VNMC_INF_RAW8 (4 << 16) 898c2ecf20Sopenharmony_ci#define VNMC_INF_YUV16 (5 << 16) 908c2ecf20Sopenharmony_ci#define VNMC_INF_RGB888 (6 << 16) 918c2ecf20Sopenharmony_ci#define VNMC_VUP (1 << 10) 928c2ecf20Sopenharmony_ci#define VNMC_IM_ODD (0 << 3) 938c2ecf20Sopenharmony_ci#define VNMC_IM_ODD_EVEN (1 << 3) 948c2ecf20Sopenharmony_ci#define VNMC_IM_EVEN (2 << 3) 958c2ecf20Sopenharmony_ci#define VNMC_IM_FULL (3 << 3) 968c2ecf20Sopenharmony_ci#define VNMC_BPS (1 << 1) 978c2ecf20Sopenharmony_ci#define VNMC_ME (1 << 0) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* Video n Module Status Register bits */ 1008c2ecf20Sopenharmony_ci#define VNMS_FBS_MASK (3 << 3) 1018c2ecf20Sopenharmony_ci#define VNMS_FBS_SHIFT 3 1028c2ecf20Sopenharmony_ci#define VNMS_FS (1 << 2) 1038c2ecf20Sopenharmony_ci#define VNMS_AV (1 << 1) 1048c2ecf20Sopenharmony_ci#define VNMS_CA (1 << 0) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* Video n Frame Capture Register bits */ 1078c2ecf20Sopenharmony_ci#define VNFC_C_FRAME (1 << 1) 1088c2ecf20Sopenharmony_ci#define VNFC_S_FRAME (1 << 0) 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci/* Video n Interrupt Enable Register bits */ 1118c2ecf20Sopenharmony_ci#define VNIE_FIE (1 << 4) 1128c2ecf20Sopenharmony_ci#define VNIE_EFE (1 << 1) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* Video n Data Mode Register bits */ 1158c2ecf20Sopenharmony_ci#define VNDMR_A8BIT(n) (((n) & 0xff) << 24) 1168c2ecf20Sopenharmony_ci#define VNDMR_A8BIT_MASK (0xff << 24) 1178c2ecf20Sopenharmony_ci#define VNDMR_EXRGB (1 << 8) 1188c2ecf20Sopenharmony_ci#define VNDMR_BPSM (1 << 4) 1198c2ecf20Sopenharmony_ci#define VNDMR_ABIT (1 << 2) 1208c2ecf20Sopenharmony_ci#define VNDMR_DTMD_YCSEP (1 << 1) 1218c2ecf20Sopenharmony_ci#define VNDMR_DTMD_ARGB (1 << 0) 1228c2ecf20Sopenharmony_ci#define VNDMR_DTMD_YCSEP_420 (3 << 0) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* Video n Data Mode Register 2 bits */ 1258c2ecf20Sopenharmony_ci#define VNDMR2_VPS (1 << 30) 1268c2ecf20Sopenharmony_ci#define VNDMR2_HPS (1 << 29) 1278c2ecf20Sopenharmony_ci#define VNDMR2_CES (1 << 28) 1288c2ecf20Sopenharmony_ci#define VNDMR2_YDS (1 << 22) 1298c2ecf20Sopenharmony_ci#define VNDMR2_FTEV (1 << 17) 1308c2ecf20Sopenharmony_ci#define VNDMR2_VLV(n) ((n & 0xf) << 12) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/* Video n CSI2 Interface Mode Register (Gen3) */ 1338c2ecf20Sopenharmony_ci#define VNCSI_IFMD_DES1 (1 << 26) 1348c2ecf20Sopenharmony_ci#define VNCSI_IFMD_DES0 (1 << 25) 1358c2ecf20Sopenharmony_ci#define VNCSI_IFMD_CSI_CHSEL(n) (((n) & 0xf) << 0) 1368c2ecf20Sopenharmony_ci#define VNCSI_IFMD_CSI_CHSEL_MASK 0xf 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistruct rvin_buffer { 1398c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer vb; 1408c2ecf20Sopenharmony_ci struct list_head list; 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#define to_buf_list(vb2_buffer) (&container_of(vb2_buffer, \ 1448c2ecf20Sopenharmony_ci struct rvin_buffer, \ 1458c2ecf20Sopenharmony_ci vb)->list) 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic void rvin_write(struct rvin_dev *vin, u32 value, u32 offset) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci iowrite32(value, vin->base + offset); 1508c2ecf20Sopenharmony_ci} 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic u32 rvin_read(struct rvin_dev *vin, u32 offset) 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci return ioread32(vin->base + offset); 1558c2ecf20Sopenharmony_ci} 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 1588c2ecf20Sopenharmony_ci * Crop and Scaling Gen2 1598c2ecf20Sopenharmony_ci */ 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistruct vin_coeff { 1628c2ecf20Sopenharmony_ci unsigned short xs_value; 1638c2ecf20Sopenharmony_ci u32 coeff_set[24]; 1648c2ecf20Sopenharmony_ci}; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistatic const struct vin_coeff vin_coeff_set[] = { 1678c2ecf20Sopenharmony_ci { 0x0000, { 1688c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1698c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1708c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1718c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1728c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1738c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1748c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000, 1758c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00000000 }, 1768c2ecf20Sopenharmony_ci }, 1778c2ecf20Sopenharmony_ci { 0x1000, { 1788c2ecf20Sopenharmony_ci 0x000fa400, 0x000fa400, 0x09625902, 1798c2ecf20Sopenharmony_ci 0x000003f8, 0x00000403, 0x3de0d9f0, 1808c2ecf20Sopenharmony_ci 0x001fffed, 0x00000804, 0x3cc1f9c3, 1818c2ecf20Sopenharmony_ci 0x001003de, 0x00000c01, 0x3cb34d7f, 1828c2ecf20Sopenharmony_ci 0x002003d2, 0x00000c00, 0x3d24a92d, 1838c2ecf20Sopenharmony_ci 0x00200bca, 0x00000bff, 0x3df600d2, 1848c2ecf20Sopenharmony_ci 0x002013cc, 0x000007ff, 0x3ed70c7e, 1858c2ecf20Sopenharmony_ci 0x00100fde, 0x00000000, 0x3f87c036 }, 1868c2ecf20Sopenharmony_ci }, 1878c2ecf20Sopenharmony_ci { 0x1200, { 1888c2ecf20Sopenharmony_ci 0x002ffff1, 0x002ffff1, 0x02a0a9c8, 1898c2ecf20Sopenharmony_ci 0x002003e7, 0x001ffffa, 0x000185bc, 1908c2ecf20Sopenharmony_ci 0x002007dc, 0x000003ff, 0x3e52859c, 1918c2ecf20Sopenharmony_ci 0x00200bd4, 0x00000002, 0x3d53996b, 1928c2ecf20Sopenharmony_ci 0x00100fd0, 0x00000403, 0x3d04ad2d, 1938c2ecf20Sopenharmony_ci 0x00000bd5, 0x00000403, 0x3d35ace7, 1948c2ecf20Sopenharmony_ci 0x3ff003e4, 0x00000801, 0x3dc674a1, 1958c2ecf20Sopenharmony_ci 0x3fffe800, 0x00000800, 0x3e76f461 }, 1968c2ecf20Sopenharmony_ci }, 1978c2ecf20Sopenharmony_ci { 0x1400, { 1988c2ecf20Sopenharmony_ci 0x00100be3, 0x00100be3, 0x04d1359a, 1998c2ecf20Sopenharmony_ci 0x00000fdb, 0x002003ed, 0x0211fd93, 2008c2ecf20Sopenharmony_ci 0x00000fd6, 0x002003f4, 0x0002d97b, 2018c2ecf20Sopenharmony_ci 0x000007d6, 0x002ffffb, 0x3e93b956, 2028c2ecf20Sopenharmony_ci 0x3ff003da, 0x001003ff, 0x3db49926, 2038c2ecf20Sopenharmony_ci 0x3fffefe9, 0x00100001, 0x3d655cee, 2048c2ecf20Sopenharmony_ci 0x3fffd400, 0x00000003, 0x3d65f4b6, 2058c2ecf20Sopenharmony_ci 0x000fb421, 0x00000402, 0x3dc6547e }, 2068c2ecf20Sopenharmony_ci }, 2078c2ecf20Sopenharmony_ci { 0x1600, { 2088c2ecf20Sopenharmony_ci 0x00000bdd, 0x00000bdd, 0x06519578, 2098c2ecf20Sopenharmony_ci 0x3ff007da, 0x00000be3, 0x03c24973, 2108c2ecf20Sopenharmony_ci 0x3ff003d9, 0x00000be9, 0x01b30d5f, 2118c2ecf20Sopenharmony_ci 0x3ffff7df, 0x001003f1, 0x0003c542, 2128c2ecf20Sopenharmony_ci 0x000fdfec, 0x001003f7, 0x3ec4711d, 2138c2ecf20Sopenharmony_ci 0x000fc400, 0x002ffffd, 0x3df504f1, 2148c2ecf20Sopenharmony_ci 0x001fa81a, 0x002ffc00, 0x3d957cc2, 2158c2ecf20Sopenharmony_ci 0x002f8c3c, 0x00100000, 0x3db5c891 }, 2168c2ecf20Sopenharmony_ci }, 2178c2ecf20Sopenharmony_ci { 0x1800, { 2188c2ecf20Sopenharmony_ci 0x3ff003dc, 0x3ff003dc, 0x0791e558, 2198c2ecf20Sopenharmony_ci 0x000ff7dd, 0x3ff007de, 0x05328554, 2208c2ecf20Sopenharmony_ci 0x000fe7e3, 0x3ff00be2, 0x03232546, 2218c2ecf20Sopenharmony_ci 0x000fd7ee, 0x000007e9, 0x0143bd30, 2228c2ecf20Sopenharmony_ci 0x001fb800, 0x000007ee, 0x00044511, 2238c2ecf20Sopenharmony_ci 0x002fa015, 0x000007f4, 0x3ef4bcee, 2248c2ecf20Sopenharmony_ci 0x002f8832, 0x001003f9, 0x3e4514c7, 2258c2ecf20Sopenharmony_ci 0x001f7853, 0x001003fd, 0x3de54c9f }, 2268c2ecf20Sopenharmony_ci }, 2278c2ecf20Sopenharmony_ci { 0x1a00, { 2288c2ecf20Sopenharmony_ci 0x000fefe0, 0x000fefe0, 0x08721d3c, 2298c2ecf20Sopenharmony_ci 0x001fdbe7, 0x000ffbde, 0x0652a139, 2308c2ecf20Sopenharmony_ci 0x001fcbf0, 0x000003df, 0x0463292e, 2318c2ecf20Sopenharmony_ci 0x002fb3ff, 0x3ff007e3, 0x0293a91d, 2328c2ecf20Sopenharmony_ci 0x002f9c12, 0x3ff00be7, 0x01241905, 2338c2ecf20Sopenharmony_ci 0x001f8c29, 0x000007ed, 0x3fe470eb, 2348c2ecf20Sopenharmony_ci 0x000f7c46, 0x000007f2, 0x3f04b8ca, 2358c2ecf20Sopenharmony_ci 0x3fef7865, 0x000007f6, 0x3e74e4a8 }, 2368c2ecf20Sopenharmony_ci }, 2378c2ecf20Sopenharmony_ci { 0x1c00, { 2388c2ecf20Sopenharmony_ci 0x001fd3e9, 0x001fd3e9, 0x08f23d26, 2398c2ecf20Sopenharmony_ci 0x002fbff3, 0x001fe3e4, 0x0712ad23, 2408c2ecf20Sopenharmony_ci 0x002fa800, 0x000ff3e0, 0x05631d1b, 2418c2ecf20Sopenharmony_ci 0x001f9810, 0x000ffbe1, 0x03b3890d, 2428c2ecf20Sopenharmony_ci 0x000f8c23, 0x000003e3, 0x0233e8fa, 2438c2ecf20Sopenharmony_ci 0x3fef843b, 0x000003e7, 0x00f430e4, 2448c2ecf20Sopenharmony_ci 0x3fbf8456, 0x3ff00bea, 0x00046cc8, 2458c2ecf20Sopenharmony_ci 0x3f8f8c72, 0x3ff00bef, 0x3f3490ac }, 2468c2ecf20Sopenharmony_ci }, 2478c2ecf20Sopenharmony_ci { 0x1e00, { 2488c2ecf20Sopenharmony_ci 0x001fbbf4, 0x001fbbf4, 0x09425112, 2498c2ecf20Sopenharmony_ci 0x001fa800, 0x002fc7ed, 0x0792b110, 2508c2ecf20Sopenharmony_ci 0x000f980e, 0x001fdbe6, 0x0613110a, 2518c2ecf20Sopenharmony_ci 0x3fff8c20, 0x001fe7e3, 0x04a368fd, 2528c2ecf20Sopenharmony_ci 0x3fcf8c33, 0x000ff7e2, 0x0343b8ed, 2538c2ecf20Sopenharmony_ci 0x3f9f8c4a, 0x000fffe3, 0x0203f8da, 2548c2ecf20Sopenharmony_ci 0x3f5f9c61, 0x000003e6, 0x00e428c5, 2558c2ecf20Sopenharmony_ci 0x3f1fb07b, 0x000003eb, 0x3fe440af }, 2568c2ecf20Sopenharmony_ci }, 2578c2ecf20Sopenharmony_ci { 0x2000, { 2588c2ecf20Sopenharmony_ci 0x000fa400, 0x000fa400, 0x09625902, 2598c2ecf20Sopenharmony_ci 0x3fff980c, 0x001fb7f5, 0x0812b0ff, 2608c2ecf20Sopenharmony_ci 0x3fdf901c, 0x001fc7ed, 0x06b2fcfa, 2618c2ecf20Sopenharmony_ci 0x3faf902d, 0x001fd3e8, 0x055348f1, 2628c2ecf20Sopenharmony_ci 0x3f7f983f, 0x001fe3e5, 0x04038ce3, 2638c2ecf20Sopenharmony_ci 0x3f3fa454, 0x001fefe3, 0x02e3c8d1, 2648c2ecf20Sopenharmony_ci 0x3f0fb86a, 0x001ff7e4, 0x01c3e8c0, 2658c2ecf20Sopenharmony_ci 0x3ecfd880, 0x000fffe6, 0x00c404ac }, 2668c2ecf20Sopenharmony_ci }, 2678c2ecf20Sopenharmony_ci { 0x2200, { 2688c2ecf20Sopenharmony_ci 0x3fdf9c0b, 0x3fdf9c0b, 0x09725cf4, 2698c2ecf20Sopenharmony_ci 0x3fbf9818, 0x3fffa400, 0x0842a8f1, 2708c2ecf20Sopenharmony_ci 0x3f8f9827, 0x000fb3f7, 0x0702f0ec, 2718c2ecf20Sopenharmony_ci 0x3f5fa037, 0x000fc3ef, 0x05d330e4, 2728c2ecf20Sopenharmony_ci 0x3f2fac49, 0x001fcfea, 0x04a364d9, 2738c2ecf20Sopenharmony_ci 0x3effc05c, 0x001fdbe7, 0x038394ca, 2748c2ecf20Sopenharmony_ci 0x3ecfdc6f, 0x001fe7e6, 0x0273b0bb, 2758c2ecf20Sopenharmony_ci 0x3ea00083, 0x001fefe6, 0x0183c0a9 }, 2768c2ecf20Sopenharmony_ci }, 2778c2ecf20Sopenharmony_ci { 0x2400, { 2788c2ecf20Sopenharmony_ci 0x3f9fa014, 0x3f9fa014, 0x098260e6, 2798c2ecf20Sopenharmony_ci 0x3f7f9c23, 0x3fcf9c0a, 0x08629ce5, 2808c2ecf20Sopenharmony_ci 0x3f4fa431, 0x3fefa400, 0x0742d8e1, 2818c2ecf20Sopenharmony_ci 0x3f1fb440, 0x3fffb3f8, 0x062310d9, 2828c2ecf20Sopenharmony_ci 0x3eefc850, 0x000fbbf2, 0x050340d0, 2838c2ecf20Sopenharmony_ci 0x3ecfe062, 0x000fcbec, 0x041364c2, 2848c2ecf20Sopenharmony_ci 0x3ea00073, 0x001fd3ea, 0x03037cb5, 2858c2ecf20Sopenharmony_ci 0x3e902086, 0x001fdfe8, 0x022388a5 }, 2868c2ecf20Sopenharmony_ci }, 2878c2ecf20Sopenharmony_ci { 0x2600, { 2888c2ecf20Sopenharmony_ci 0x3f5fa81e, 0x3f5fa81e, 0x096258da, 2898c2ecf20Sopenharmony_ci 0x3f3fac2b, 0x3f8fa412, 0x088290d8, 2908c2ecf20Sopenharmony_ci 0x3f0fbc38, 0x3fafa408, 0x0772c8d5, 2918c2ecf20Sopenharmony_ci 0x3eefcc47, 0x3fcfa800, 0x0672f4ce, 2928c2ecf20Sopenharmony_ci 0x3ecfe456, 0x3fefaffa, 0x05531cc6, 2938c2ecf20Sopenharmony_ci 0x3eb00066, 0x3fffbbf3, 0x047334bb, 2948c2ecf20Sopenharmony_ci 0x3ea01c77, 0x000fc7ee, 0x039348ae, 2958c2ecf20Sopenharmony_ci 0x3ea04486, 0x000fd3eb, 0x02b350a1 }, 2968c2ecf20Sopenharmony_ci }, 2978c2ecf20Sopenharmony_ci { 0x2800, { 2988c2ecf20Sopenharmony_ci 0x3f2fb426, 0x3f2fb426, 0x094250ce, 2998c2ecf20Sopenharmony_ci 0x3f0fc032, 0x3f4fac1b, 0x086284cd, 3008c2ecf20Sopenharmony_ci 0x3eefd040, 0x3f7fa811, 0x0782acc9, 3018c2ecf20Sopenharmony_ci 0x3ecfe84c, 0x3f9fa807, 0x06a2d8c4, 3028c2ecf20Sopenharmony_ci 0x3eb0005b, 0x3fbfac00, 0x05b2f4bc, 3038c2ecf20Sopenharmony_ci 0x3eb0186a, 0x3fdfb3fa, 0x04c308b4, 3048c2ecf20Sopenharmony_ci 0x3eb04077, 0x3fefbbf4, 0x03f31ca8, 3058c2ecf20Sopenharmony_ci 0x3ec06884, 0x000fbff2, 0x03031c9e }, 3068c2ecf20Sopenharmony_ci }, 3078c2ecf20Sopenharmony_ci { 0x2a00, { 3088c2ecf20Sopenharmony_ci 0x3f0fc42d, 0x3f0fc42d, 0x090240c4, 3098c2ecf20Sopenharmony_ci 0x3eefd439, 0x3f2fb822, 0x08526cc2, 3108c2ecf20Sopenharmony_ci 0x3edfe845, 0x3f4fb018, 0x078294bf, 3118c2ecf20Sopenharmony_ci 0x3ec00051, 0x3f6fac0f, 0x06b2b4bb, 3128c2ecf20Sopenharmony_ci 0x3ec0185f, 0x3f8fac07, 0x05e2ccb4, 3138c2ecf20Sopenharmony_ci 0x3ec0386b, 0x3fafac00, 0x0502e8ac, 3148c2ecf20Sopenharmony_ci 0x3ed05c77, 0x3fcfb3fb, 0x0432f0a3, 3158c2ecf20Sopenharmony_ci 0x3ef08482, 0x3fdfbbf6, 0x0372f898 }, 3168c2ecf20Sopenharmony_ci }, 3178c2ecf20Sopenharmony_ci { 0x2c00, { 3188c2ecf20Sopenharmony_ci 0x3eefdc31, 0x3eefdc31, 0x08e238b8, 3198c2ecf20Sopenharmony_ci 0x3edfec3d, 0x3f0fc828, 0x082258b9, 3208c2ecf20Sopenharmony_ci 0x3ed00049, 0x3f1fc01e, 0x077278b6, 3218c2ecf20Sopenharmony_ci 0x3ed01455, 0x3f3fb815, 0x06c294b2, 3228c2ecf20Sopenharmony_ci 0x3ed03460, 0x3f5fb40d, 0x0602acac, 3238c2ecf20Sopenharmony_ci 0x3ef0506c, 0x3f7fb006, 0x0542c0a4, 3248c2ecf20Sopenharmony_ci 0x3f107476, 0x3f9fb400, 0x0472c89d, 3258c2ecf20Sopenharmony_ci 0x3f309c80, 0x3fbfb7fc, 0x03b2cc94 }, 3268c2ecf20Sopenharmony_ci }, 3278c2ecf20Sopenharmony_ci { 0x2e00, { 3288c2ecf20Sopenharmony_ci 0x3eefec37, 0x3eefec37, 0x088220b0, 3298c2ecf20Sopenharmony_ci 0x3ee00041, 0x3effdc2d, 0x07f244ae, 3308c2ecf20Sopenharmony_ci 0x3ee0144c, 0x3f0fd023, 0x07625cad, 3318c2ecf20Sopenharmony_ci 0x3ef02c57, 0x3f1fc81a, 0x06c274a9, 3328c2ecf20Sopenharmony_ci 0x3f004861, 0x3f3fbc13, 0x060288a6, 3338c2ecf20Sopenharmony_ci 0x3f20686b, 0x3f5fb80c, 0x05529c9e, 3348c2ecf20Sopenharmony_ci 0x3f408c74, 0x3f6fb805, 0x04b2ac96, 3358c2ecf20Sopenharmony_ci 0x3f80ac7e, 0x3f8fb800, 0x0402ac8e }, 3368c2ecf20Sopenharmony_ci }, 3378c2ecf20Sopenharmony_ci { 0x3000, { 3388c2ecf20Sopenharmony_ci 0x3ef0003a, 0x3ef0003a, 0x084210a6, 3398c2ecf20Sopenharmony_ci 0x3ef01045, 0x3effec32, 0x07b228a7, 3408c2ecf20Sopenharmony_ci 0x3f00284e, 0x3f0fdc29, 0x073244a4, 3418c2ecf20Sopenharmony_ci 0x3f104058, 0x3f0fd420, 0x06a258a2, 3428c2ecf20Sopenharmony_ci 0x3f305c62, 0x3f2fc818, 0x0612689d, 3438c2ecf20Sopenharmony_ci 0x3f508069, 0x3f3fc011, 0x05728496, 3448c2ecf20Sopenharmony_ci 0x3f80a072, 0x3f4fc00a, 0x04d28c90, 3458c2ecf20Sopenharmony_ci 0x3fc0c07b, 0x3f6fbc04, 0x04429088 }, 3468c2ecf20Sopenharmony_ci }, 3478c2ecf20Sopenharmony_ci { 0x3200, { 3488c2ecf20Sopenharmony_ci 0x3f00103e, 0x3f00103e, 0x07f1fc9e, 3498c2ecf20Sopenharmony_ci 0x3f102447, 0x3f000035, 0x0782149d, 3508c2ecf20Sopenharmony_ci 0x3f203c4f, 0x3f0ff02c, 0x07122c9c, 3518c2ecf20Sopenharmony_ci 0x3f405458, 0x3f0fe424, 0x06924099, 3528c2ecf20Sopenharmony_ci 0x3f607061, 0x3f1fd41d, 0x06024c97, 3538c2ecf20Sopenharmony_ci 0x3f909068, 0x3f2fcc16, 0x05726490, 3548c2ecf20Sopenharmony_ci 0x3fc0b070, 0x3f3fc80f, 0x04f26c8a, 3558c2ecf20Sopenharmony_ci 0x0000d077, 0x3f4fc409, 0x04627484 }, 3568c2ecf20Sopenharmony_ci }, 3578c2ecf20Sopenharmony_ci { 0x3400, { 3588c2ecf20Sopenharmony_ci 0x3f202040, 0x3f202040, 0x07a1e898, 3598c2ecf20Sopenharmony_ci 0x3f303449, 0x3f100c38, 0x0741fc98, 3608c2ecf20Sopenharmony_ci 0x3f504c50, 0x3f10002f, 0x06e21495, 3618c2ecf20Sopenharmony_ci 0x3f706459, 0x3f1ff028, 0x06722492, 3628c2ecf20Sopenharmony_ci 0x3fa08060, 0x3f1fe421, 0x05f2348f, 3638c2ecf20Sopenharmony_ci 0x3fd09c67, 0x3f1fdc19, 0x05824c89, 3648c2ecf20Sopenharmony_ci 0x0000bc6e, 0x3f2fd014, 0x04f25086, 3658c2ecf20Sopenharmony_ci 0x0040dc74, 0x3f3fcc0d, 0x04825c7f }, 3668c2ecf20Sopenharmony_ci }, 3678c2ecf20Sopenharmony_ci { 0x3600, { 3688c2ecf20Sopenharmony_ci 0x3f403042, 0x3f403042, 0x0761d890, 3698c2ecf20Sopenharmony_ci 0x3f504848, 0x3f301c3b, 0x0701f090, 3708c2ecf20Sopenharmony_ci 0x3f805c50, 0x3f200c33, 0x06a2008f, 3718c2ecf20Sopenharmony_ci 0x3fa07458, 0x3f10002b, 0x06520c8d, 3728c2ecf20Sopenharmony_ci 0x3fd0905e, 0x3f1ff424, 0x05e22089, 3738c2ecf20Sopenharmony_ci 0x0000ac65, 0x3f1fe81d, 0x05823483, 3748c2ecf20Sopenharmony_ci 0x0030cc6a, 0x3f2fdc18, 0x04f23c81, 3758c2ecf20Sopenharmony_ci 0x0080e871, 0x3f2fd412, 0x0482407c }, 3768c2ecf20Sopenharmony_ci }, 3778c2ecf20Sopenharmony_ci { 0x3800, { 3788c2ecf20Sopenharmony_ci 0x3f604043, 0x3f604043, 0x0721c88a, 3798c2ecf20Sopenharmony_ci 0x3f80544a, 0x3f502c3c, 0x06d1d88a, 3808c2ecf20Sopenharmony_ci 0x3fb06851, 0x3f301c35, 0x0681e889, 3818c2ecf20Sopenharmony_ci 0x3fd08456, 0x3f30082f, 0x0611fc88, 3828c2ecf20Sopenharmony_ci 0x00009c5d, 0x3f200027, 0x05d20884, 3838c2ecf20Sopenharmony_ci 0x0030b863, 0x3f2ff421, 0x05621880, 3848c2ecf20Sopenharmony_ci 0x0070d468, 0x3f2fe81b, 0x0502247c, 3858c2ecf20Sopenharmony_ci 0x00c0ec6f, 0x3f2fe015, 0x04a22877 }, 3868c2ecf20Sopenharmony_ci }, 3878c2ecf20Sopenharmony_ci { 0x3a00, { 3888c2ecf20Sopenharmony_ci 0x3f904c44, 0x3f904c44, 0x06e1b884, 3898c2ecf20Sopenharmony_ci 0x3fb0604a, 0x3f70383e, 0x0691c885, 3908c2ecf20Sopenharmony_ci 0x3fe07451, 0x3f502c36, 0x0661d483, 3918c2ecf20Sopenharmony_ci 0x00009055, 0x3f401831, 0x0601ec81, 3928c2ecf20Sopenharmony_ci 0x0030a85b, 0x3f300c2a, 0x05b1f480, 3938c2ecf20Sopenharmony_ci 0x0070c061, 0x3f300024, 0x0562047a, 3948c2ecf20Sopenharmony_ci 0x00b0d867, 0x3f3ff41e, 0x05020c77, 3958c2ecf20Sopenharmony_ci 0x00f0f46b, 0x3f2fec19, 0x04a21474 }, 3968c2ecf20Sopenharmony_ci }, 3978c2ecf20Sopenharmony_ci { 0x3c00, { 3988c2ecf20Sopenharmony_ci 0x3fb05c43, 0x3fb05c43, 0x06c1b07e, 3998c2ecf20Sopenharmony_ci 0x3fe06c4b, 0x3f902c3f, 0x0681c081, 4008c2ecf20Sopenharmony_ci 0x0000844f, 0x3f703838, 0x0631cc7d, 4018c2ecf20Sopenharmony_ci 0x00309855, 0x3f602433, 0x05d1d47e, 4028c2ecf20Sopenharmony_ci 0x0060b459, 0x3f50142e, 0x0581e47b, 4038c2ecf20Sopenharmony_ci 0x00a0c85f, 0x3f400828, 0x0531f078, 4048c2ecf20Sopenharmony_ci 0x00e0e064, 0x3f300021, 0x0501fc73, 4058c2ecf20Sopenharmony_ci 0x00b0fc6a, 0x3f3ff41d, 0x04a20873 }, 4068c2ecf20Sopenharmony_ci }, 4078c2ecf20Sopenharmony_ci { 0x3e00, { 4088c2ecf20Sopenharmony_ci 0x3fe06444, 0x3fe06444, 0x0681a07a, 4098c2ecf20Sopenharmony_ci 0x00007849, 0x3fc0503f, 0x0641b07a, 4108c2ecf20Sopenharmony_ci 0x0020904d, 0x3fa0403a, 0x05f1c07a, 4118c2ecf20Sopenharmony_ci 0x0060a453, 0x3f803034, 0x05c1c878, 4128c2ecf20Sopenharmony_ci 0x0090b858, 0x3f70202f, 0x0571d477, 4138c2ecf20Sopenharmony_ci 0x00d0d05d, 0x3f501829, 0x0531e073, 4148c2ecf20Sopenharmony_ci 0x0110e462, 0x3f500825, 0x04e1e471, 4158c2ecf20Sopenharmony_ci 0x01510065, 0x3f40001f, 0x04a1f06d }, 4168c2ecf20Sopenharmony_ci }, 4178c2ecf20Sopenharmony_ci { 0x4000, { 4188c2ecf20Sopenharmony_ci 0x00007044, 0x00007044, 0x06519476, 4198c2ecf20Sopenharmony_ci 0x00208448, 0x3fe05c3f, 0x0621a476, 4208c2ecf20Sopenharmony_ci 0x0050984d, 0x3fc04c3a, 0x05e1b075, 4218c2ecf20Sopenharmony_ci 0x0080ac52, 0x3fa03c35, 0x05a1b875, 4228c2ecf20Sopenharmony_ci 0x00c0c056, 0x3f803030, 0x0561c473, 4238c2ecf20Sopenharmony_ci 0x0100d45b, 0x3f70202b, 0x0521d46f, 4248c2ecf20Sopenharmony_ci 0x0140e860, 0x3f601427, 0x04d1d46e, 4258c2ecf20Sopenharmony_ci 0x01810064, 0x3f500822, 0x0491dc6b }, 4268c2ecf20Sopenharmony_ci }, 4278c2ecf20Sopenharmony_ci { 0x5000, { 4288c2ecf20Sopenharmony_ci 0x0110a442, 0x0110a442, 0x0551545e, 4298c2ecf20Sopenharmony_ci 0x0140b045, 0x00e0983f, 0x0531585f, 4308c2ecf20Sopenharmony_ci 0x0160c047, 0x00c08c3c, 0x0511645e, 4318c2ecf20Sopenharmony_ci 0x0190cc4a, 0x00908039, 0x04f1685f, 4328c2ecf20Sopenharmony_ci 0x01c0dc4c, 0x00707436, 0x04d1705e, 4338c2ecf20Sopenharmony_ci 0x0200e850, 0x00506833, 0x04b1785b, 4348c2ecf20Sopenharmony_ci 0x0230f453, 0x00305c30, 0x0491805a, 4358c2ecf20Sopenharmony_ci 0x02710056, 0x0010542d, 0x04718059 }, 4368c2ecf20Sopenharmony_ci }, 4378c2ecf20Sopenharmony_ci { 0x6000, { 4388c2ecf20Sopenharmony_ci 0x01c0bc40, 0x01c0bc40, 0x04c13052, 4398c2ecf20Sopenharmony_ci 0x01e0c841, 0x01a0b43d, 0x04c13851, 4408c2ecf20Sopenharmony_ci 0x0210cc44, 0x0180a83c, 0x04a13453, 4418c2ecf20Sopenharmony_ci 0x0230d845, 0x0160a03a, 0x04913c52, 4428c2ecf20Sopenharmony_ci 0x0260e047, 0x01409838, 0x04714052, 4438c2ecf20Sopenharmony_ci 0x0280ec49, 0x01208c37, 0x04514c50, 4448c2ecf20Sopenharmony_ci 0x02b0f44b, 0x01008435, 0x04414c50, 4458c2ecf20Sopenharmony_ci 0x02d1004c, 0x00e07c33, 0x0431544f }, 4468c2ecf20Sopenharmony_ci }, 4478c2ecf20Sopenharmony_ci { 0x7000, { 4488c2ecf20Sopenharmony_ci 0x0230c83e, 0x0230c83e, 0x04711c4c, 4498c2ecf20Sopenharmony_ci 0x0250d03f, 0x0210c43c, 0x0471204b, 4508c2ecf20Sopenharmony_ci 0x0270d840, 0x0200b83c, 0x0451244b, 4518c2ecf20Sopenharmony_ci 0x0290dc42, 0x01e0b43a, 0x0441244c, 4528c2ecf20Sopenharmony_ci 0x02b0e443, 0x01c0b038, 0x0441284b, 4538c2ecf20Sopenharmony_ci 0x02d0ec44, 0x01b0a438, 0x0421304a, 4548c2ecf20Sopenharmony_ci 0x02f0f445, 0x0190a036, 0x04213449, 4558c2ecf20Sopenharmony_ci 0x0310f847, 0x01709c34, 0x04213848 }, 4568c2ecf20Sopenharmony_ci }, 4578c2ecf20Sopenharmony_ci { 0x8000, { 4588c2ecf20Sopenharmony_ci 0x0280d03d, 0x0280d03d, 0x04310c48, 4598c2ecf20Sopenharmony_ci 0x02a0d43e, 0x0270c83c, 0x04311047, 4608c2ecf20Sopenharmony_ci 0x02b0dc3e, 0x0250c83a, 0x04311447, 4618c2ecf20Sopenharmony_ci 0x02d0e040, 0x0240c03a, 0x04211446, 4628c2ecf20Sopenharmony_ci 0x02e0e840, 0x0220bc39, 0x04111847, 4638c2ecf20Sopenharmony_ci 0x0300e842, 0x0210b438, 0x04012445, 4648c2ecf20Sopenharmony_ci 0x0310f043, 0x0200b037, 0x04012045, 4658c2ecf20Sopenharmony_ci 0x0330f444, 0x01e0ac36, 0x03f12445 }, 4668c2ecf20Sopenharmony_ci }, 4678c2ecf20Sopenharmony_ci { 0xefff, { 4688c2ecf20Sopenharmony_ci 0x0340dc3a, 0x0340dc3a, 0x03b0ec40, 4698c2ecf20Sopenharmony_ci 0x0340e03a, 0x0330e039, 0x03c0f03e, 4708c2ecf20Sopenharmony_ci 0x0350e03b, 0x0330dc39, 0x03c0ec3e, 4718c2ecf20Sopenharmony_ci 0x0350e43a, 0x0320dc38, 0x03c0f43e, 4728c2ecf20Sopenharmony_ci 0x0360e43b, 0x0320d839, 0x03b0f03e, 4738c2ecf20Sopenharmony_ci 0x0360e83b, 0x0310d838, 0x03c0fc3b, 4748c2ecf20Sopenharmony_ci 0x0370e83b, 0x0310d439, 0x03a0f83d, 4758c2ecf20Sopenharmony_ci 0x0370e83c, 0x0300d438, 0x03b0fc3c }, 4768c2ecf20Sopenharmony_ci } 4778c2ecf20Sopenharmony_ci}; 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_cistatic void rvin_set_coeff(struct rvin_dev *vin, unsigned short xs) 4808c2ecf20Sopenharmony_ci{ 4818c2ecf20Sopenharmony_ci int i; 4828c2ecf20Sopenharmony_ci const struct vin_coeff *p_prev_set = NULL; 4838c2ecf20Sopenharmony_ci const struct vin_coeff *p_set = NULL; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci /* Look for suitable coefficient values */ 4868c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(vin_coeff_set); i++) { 4878c2ecf20Sopenharmony_ci p_prev_set = p_set; 4888c2ecf20Sopenharmony_ci p_set = &vin_coeff_set[i]; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci if (xs < p_set->xs_value) 4918c2ecf20Sopenharmony_ci break; 4928c2ecf20Sopenharmony_ci } 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci /* Use previous value if its XS value is closer */ 4958c2ecf20Sopenharmony_ci if (p_prev_set && 4968c2ecf20Sopenharmony_ci xs - p_prev_set->xs_value < p_set->xs_value - xs) 4978c2ecf20Sopenharmony_ci p_set = p_prev_set; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci /* Set coefficient registers */ 5008c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[0], VNC1A_REG); 5018c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[1], VNC1B_REG); 5028c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[2], VNC1C_REG); 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[3], VNC2A_REG); 5058c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[4], VNC2B_REG); 5068c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[5], VNC2C_REG); 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[6], VNC3A_REG); 5098c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[7], VNC3B_REG); 5108c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[8], VNC3C_REG); 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[9], VNC4A_REG); 5138c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[10], VNC4B_REG); 5148c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[11], VNC4C_REG); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[12], VNC5A_REG); 5178c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[13], VNC5B_REG); 5188c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[14], VNC5C_REG); 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[15], VNC6A_REG); 5218c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[16], VNC6B_REG); 5228c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[17], VNC6C_REG); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[18], VNC7A_REG); 5258c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[19], VNC7B_REG); 5268c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[20], VNC7C_REG); 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[21], VNC8A_REG); 5298c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[22], VNC8B_REG); 5308c2ecf20Sopenharmony_ci rvin_write(vin, p_set->coeff_set[23], VNC8C_REG); 5318c2ecf20Sopenharmony_ci} 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_cistatic void rvin_crop_scale_comp_gen2(struct rvin_dev *vin) 5348c2ecf20Sopenharmony_ci{ 5358c2ecf20Sopenharmony_ci unsigned int crop_height; 5368c2ecf20Sopenharmony_ci u32 xs, ys; 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci /* Set scaling coefficient */ 5398c2ecf20Sopenharmony_ci crop_height = vin->crop.height; 5408c2ecf20Sopenharmony_ci if (V4L2_FIELD_HAS_BOTH(vin->format.field)) 5418c2ecf20Sopenharmony_ci crop_height *= 2; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci ys = 0; 5448c2ecf20Sopenharmony_ci if (crop_height != vin->compose.height) 5458c2ecf20Sopenharmony_ci ys = (4096 * crop_height) / vin->compose.height; 5468c2ecf20Sopenharmony_ci rvin_write(vin, ys, VNYS_REG); 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci xs = 0; 5498c2ecf20Sopenharmony_ci if (vin->crop.width != vin->compose.width) 5508c2ecf20Sopenharmony_ci xs = (4096 * vin->crop.width) / vin->compose.width; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci /* Horizontal upscaling is up to double size */ 5538c2ecf20Sopenharmony_ci if (xs > 0 && xs < 2048) 5548c2ecf20Sopenharmony_ci xs = 2048; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci rvin_write(vin, xs, VNXS_REG); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci /* Horizontal upscaling is done out by scaling down from double size */ 5598c2ecf20Sopenharmony_ci if (xs < 4096) 5608c2ecf20Sopenharmony_ci xs *= 2; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci rvin_set_coeff(vin, xs); 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci /* Set Start/End Pixel/Line Post-Clip */ 5658c2ecf20Sopenharmony_ci rvin_write(vin, 0, VNSPPOC_REG); 5668c2ecf20Sopenharmony_ci rvin_write(vin, 0, VNSLPOC_REG); 5678c2ecf20Sopenharmony_ci rvin_write(vin, vin->format.width - 1, VNEPPOC_REG); 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci if (V4L2_FIELD_HAS_BOTH(vin->format.field)) 5708c2ecf20Sopenharmony_ci rvin_write(vin, vin->format.height / 2 - 1, VNELPOC_REG); 5718c2ecf20Sopenharmony_ci else 5728c2ecf20Sopenharmony_ci rvin_write(vin, vin->format.height - 1, VNELPOC_REG); 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci vin_dbg(vin, 5758c2ecf20Sopenharmony_ci "Pre-Clip: %ux%u@%u:%u YS: %d XS: %d Post-Clip: %ux%u@%u:%u\n", 5768c2ecf20Sopenharmony_ci vin->crop.width, vin->crop.height, vin->crop.left, 5778c2ecf20Sopenharmony_ci vin->crop.top, ys, xs, vin->format.width, vin->format.height, 5788c2ecf20Sopenharmony_ci 0, 0); 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_civoid rvin_crop_scale_comp(struct rvin_dev *vin) 5828c2ecf20Sopenharmony_ci{ 5838c2ecf20Sopenharmony_ci const struct rvin_video_format *fmt; 5848c2ecf20Sopenharmony_ci u32 stride; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci /* Set Start/End Pixel/Line Pre-Clip */ 5878c2ecf20Sopenharmony_ci rvin_write(vin, vin->crop.left, VNSPPRC_REG); 5888c2ecf20Sopenharmony_ci rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG); 5898c2ecf20Sopenharmony_ci rvin_write(vin, vin->crop.top, VNSLPRC_REG); 5908c2ecf20Sopenharmony_ci rvin_write(vin, vin->crop.top + vin->crop.height - 1, VNELPRC_REG); 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci /* TODO: Add support for the UDS scaler. */ 5938c2ecf20Sopenharmony_ci if (vin->info->model != RCAR_GEN3) 5948c2ecf20Sopenharmony_ci rvin_crop_scale_comp_gen2(vin); 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci fmt = rvin_format_from_pixel(vin, vin->format.pixelformat); 5978c2ecf20Sopenharmony_ci stride = vin->format.bytesperline / fmt->bpp; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci /* For RAW8 format bpp is 1, but the hardware process RAW8 6008c2ecf20Sopenharmony_ci * format in 2 pixel unit hence configure VNIS_REG as stride / 2. 6018c2ecf20Sopenharmony_ci */ 6028c2ecf20Sopenharmony_ci switch (vin->format.pixelformat) { 6038c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SBGGR8: 6048c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SGBRG8: 6058c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SGRBG8: 6068c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SRGGB8: 6078c2ecf20Sopenharmony_ci stride /= 2; 6088c2ecf20Sopenharmony_ci break; 6098c2ecf20Sopenharmony_ci default: 6108c2ecf20Sopenharmony_ci break; 6118c2ecf20Sopenharmony_ci } 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci rvin_write(vin, stride, VNIS_REG); 6148c2ecf20Sopenharmony_ci} 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 6178c2ecf20Sopenharmony_ci * Hardware setup 6188c2ecf20Sopenharmony_ci */ 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_cistatic int rvin_setup(struct rvin_dev *vin) 6218c2ecf20Sopenharmony_ci{ 6228c2ecf20Sopenharmony_ci u32 vnmc, dmr, dmr2, interrupts; 6238c2ecf20Sopenharmony_ci bool progressive = false, output_is_yuv = false, input_is_yuv = false; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci switch (vin->format.field) { 6268c2ecf20Sopenharmony_ci case V4L2_FIELD_TOP: 6278c2ecf20Sopenharmony_ci vnmc = VNMC_IM_ODD; 6288c2ecf20Sopenharmony_ci break; 6298c2ecf20Sopenharmony_ci case V4L2_FIELD_BOTTOM: 6308c2ecf20Sopenharmony_ci vnmc = VNMC_IM_EVEN; 6318c2ecf20Sopenharmony_ci break; 6328c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED: 6338c2ecf20Sopenharmony_ci /* Default to TB */ 6348c2ecf20Sopenharmony_ci vnmc = VNMC_IM_FULL; 6358c2ecf20Sopenharmony_ci /* Use BT if video standard can be read and is 60 Hz format */ 6368c2ecf20Sopenharmony_ci if (!vin->info->use_mc && vin->std & V4L2_STD_525_60) 6378c2ecf20Sopenharmony_ci vnmc = VNMC_IM_FULL | VNMC_FOC; 6388c2ecf20Sopenharmony_ci break; 6398c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED_TB: 6408c2ecf20Sopenharmony_ci vnmc = VNMC_IM_FULL; 6418c2ecf20Sopenharmony_ci break; 6428c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED_BT: 6438c2ecf20Sopenharmony_ci vnmc = VNMC_IM_FULL | VNMC_FOC; 6448c2ecf20Sopenharmony_ci break; 6458c2ecf20Sopenharmony_ci case V4L2_FIELD_SEQ_TB: 6468c2ecf20Sopenharmony_ci case V4L2_FIELD_SEQ_BT: 6478c2ecf20Sopenharmony_ci case V4L2_FIELD_NONE: 6488c2ecf20Sopenharmony_ci case V4L2_FIELD_ALTERNATE: 6498c2ecf20Sopenharmony_ci vnmc = VNMC_IM_ODD_EVEN; 6508c2ecf20Sopenharmony_ci progressive = true; 6518c2ecf20Sopenharmony_ci break; 6528c2ecf20Sopenharmony_ci default: 6538c2ecf20Sopenharmony_ci vnmc = VNMC_IM_ODD; 6548c2ecf20Sopenharmony_ci break; 6558c2ecf20Sopenharmony_ci } 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci /* 6588c2ecf20Sopenharmony_ci * Input interface 6598c2ecf20Sopenharmony_ci */ 6608c2ecf20Sopenharmony_ci switch (vin->mbus_code) { 6618c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_YUYV8_1X16: 6628c2ecf20Sopenharmony_ci /* BT.601/BT.1358 16bit YCbCr422 */ 6638c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_YUV16; 6648c2ecf20Sopenharmony_ci input_is_yuv = true; 6658c2ecf20Sopenharmony_ci break; 6668c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_1X16: 6678c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_YUV16 | VNMC_YCAL; 6688c2ecf20Sopenharmony_ci input_is_yuv = true; 6698c2ecf20Sopenharmony_ci break; 6708c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_2X8: 6718c2ecf20Sopenharmony_ci /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ 6728c2ecf20Sopenharmony_ci if (!vin->is_csi && 6738c2ecf20Sopenharmony_ci vin->parallel->mbus_type == V4L2_MBUS_BT656) 6748c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_YUV8_BT656; 6758c2ecf20Sopenharmony_ci else 6768c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_YUV8_BT601; 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci input_is_yuv = true; 6798c2ecf20Sopenharmony_ci break; 6808c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_RGB888_1X24: 6818c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_RGB888; 6828c2ecf20Sopenharmony_ci break; 6838c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY10_2X10: 6848c2ecf20Sopenharmony_ci /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ 6858c2ecf20Sopenharmony_ci if (!vin->is_csi && 6868c2ecf20Sopenharmony_ci vin->parallel->mbus_type == V4L2_MBUS_BT656) 6878c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_YUV10_BT656; 6888c2ecf20Sopenharmony_ci else 6898c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_YUV10_BT601; 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci input_is_yuv = true; 6928c2ecf20Sopenharmony_ci break; 6938c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SBGGR8_1X8: 6948c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SGBRG8_1X8: 6958c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SGRBG8_1X8: 6968c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SRGGB8_1X8: 6978c2ecf20Sopenharmony_ci vnmc |= VNMC_INF_RAW8; 6988c2ecf20Sopenharmony_ci break; 6998c2ecf20Sopenharmony_ci default: 7008c2ecf20Sopenharmony_ci break; 7018c2ecf20Sopenharmony_ci } 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci /* Enable VSYNC Field Toggle mode after one VSYNC input */ 7048c2ecf20Sopenharmony_ci if (vin->info->model == RCAR_GEN3) 7058c2ecf20Sopenharmony_ci dmr2 = VNDMR2_FTEV; 7068c2ecf20Sopenharmony_ci else 7078c2ecf20Sopenharmony_ci dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1); 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci if (!vin->is_csi) { 7108c2ecf20Sopenharmony_ci /* Hsync Signal Polarity Select */ 7118c2ecf20Sopenharmony_ci if (!(vin->parallel->bus.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) 7128c2ecf20Sopenharmony_ci dmr2 |= VNDMR2_HPS; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci /* Vsync Signal Polarity Select */ 7158c2ecf20Sopenharmony_ci if (!(vin->parallel->bus.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) 7168c2ecf20Sopenharmony_ci dmr2 |= VNDMR2_VPS; 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci /* Data Enable Polarity Select */ 7198c2ecf20Sopenharmony_ci if (vin->parallel->bus.flags & V4L2_MBUS_DATA_ENABLE_LOW) 7208c2ecf20Sopenharmony_ci dmr2 |= VNDMR2_CES; 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci switch (vin->mbus_code) { 7238c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_2X8: 7248c2ecf20Sopenharmony_ci if (vin->parallel->bus.bus_width == 8 && 7258c2ecf20Sopenharmony_ci vin->parallel->bus.data_shift == 8) 7268c2ecf20Sopenharmony_ci dmr2 |= VNDMR2_YDS; 7278c2ecf20Sopenharmony_ci break; 7288c2ecf20Sopenharmony_ci default: 7298c2ecf20Sopenharmony_ci break; 7308c2ecf20Sopenharmony_ci } 7318c2ecf20Sopenharmony_ci } 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci /* 7348c2ecf20Sopenharmony_ci * Output format 7358c2ecf20Sopenharmony_ci */ 7368c2ecf20Sopenharmony_ci switch (vin->format.pixelformat) { 7378c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV12: 7388c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV16: 7398c2ecf20Sopenharmony_ci rvin_write(vin, 7408c2ecf20Sopenharmony_ci ALIGN(vin->format.bytesperline * vin->format.height, 7418c2ecf20Sopenharmony_ci 0x80), VNUVAOF_REG); 7428c2ecf20Sopenharmony_ci dmr = vin->format.pixelformat == V4L2_PIX_FMT_NV12 ? 7438c2ecf20Sopenharmony_ci VNDMR_DTMD_YCSEP_420 : VNDMR_DTMD_YCSEP; 7448c2ecf20Sopenharmony_ci output_is_yuv = true; 7458c2ecf20Sopenharmony_ci break; 7468c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_YUYV: 7478c2ecf20Sopenharmony_ci dmr = VNDMR_BPSM; 7488c2ecf20Sopenharmony_ci output_is_yuv = true; 7498c2ecf20Sopenharmony_ci break; 7508c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_UYVY: 7518c2ecf20Sopenharmony_ci dmr = 0; 7528c2ecf20Sopenharmony_ci output_is_yuv = true; 7538c2ecf20Sopenharmony_ci break; 7548c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_XRGB555: 7558c2ecf20Sopenharmony_ci dmr = VNDMR_DTMD_ARGB; 7568c2ecf20Sopenharmony_ci break; 7578c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_RGB565: 7588c2ecf20Sopenharmony_ci dmr = 0; 7598c2ecf20Sopenharmony_ci break; 7608c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_XBGR32: 7618c2ecf20Sopenharmony_ci /* Note: not supported on M1 */ 7628c2ecf20Sopenharmony_ci dmr = VNDMR_EXRGB; 7638c2ecf20Sopenharmony_ci break; 7648c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_ARGB555: 7658c2ecf20Sopenharmony_ci dmr = (vin->alpha ? VNDMR_ABIT : 0) | VNDMR_DTMD_ARGB; 7668c2ecf20Sopenharmony_ci break; 7678c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_ABGR32: 7688c2ecf20Sopenharmony_ci dmr = VNDMR_A8BIT(vin->alpha) | VNDMR_EXRGB | VNDMR_DTMD_ARGB; 7698c2ecf20Sopenharmony_ci break; 7708c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SBGGR8: 7718c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SGBRG8: 7728c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SGRBG8: 7738c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_SRGGB8: 7748c2ecf20Sopenharmony_ci dmr = 0; 7758c2ecf20Sopenharmony_ci break; 7768c2ecf20Sopenharmony_ci default: 7778c2ecf20Sopenharmony_ci vin_err(vin, "Invalid pixelformat (0x%x)\n", 7788c2ecf20Sopenharmony_ci vin->format.pixelformat); 7798c2ecf20Sopenharmony_ci return -EINVAL; 7808c2ecf20Sopenharmony_ci } 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci /* Always update on field change */ 7838c2ecf20Sopenharmony_ci vnmc |= VNMC_VUP; 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci /* If input and output use the same colorspace, use bypass mode */ 7868c2ecf20Sopenharmony_ci if (input_is_yuv == output_is_yuv) 7878c2ecf20Sopenharmony_ci vnmc |= VNMC_BPS; 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci if (vin->info->model == RCAR_GEN3) { 7908c2ecf20Sopenharmony_ci /* Select between CSI-2 and parallel input */ 7918c2ecf20Sopenharmony_ci if (vin->is_csi) 7928c2ecf20Sopenharmony_ci vnmc &= ~VNMC_DPINE; 7938c2ecf20Sopenharmony_ci else 7948c2ecf20Sopenharmony_ci vnmc |= VNMC_DPINE; 7958c2ecf20Sopenharmony_ci } 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci /* Progressive or interlaced mode */ 7988c2ecf20Sopenharmony_ci interrupts = progressive ? VNIE_FIE : VNIE_EFE; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci /* Ack interrupts */ 8018c2ecf20Sopenharmony_ci rvin_write(vin, interrupts, VNINTS_REG); 8028c2ecf20Sopenharmony_ci /* Enable interrupts */ 8038c2ecf20Sopenharmony_ci rvin_write(vin, interrupts, VNIE_REG); 8048c2ecf20Sopenharmony_ci /* Start capturing */ 8058c2ecf20Sopenharmony_ci rvin_write(vin, dmr, VNDMR_REG); 8068c2ecf20Sopenharmony_ci rvin_write(vin, dmr2, VNDMR2_REG); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci /* Enable module */ 8098c2ecf20Sopenharmony_ci rvin_write(vin, vnmc | VNMC_ME, VNMC_REG); 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci return 0; 8128c2ecf20Sopenharmony_ci} 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_cistatic void rvin_disable_interrupts(struct rvin_dev *vin) 8158c2ecf20Sopenharmony_ci{ 8168c2ecf20Sopenharmony_ci rvin_write(vin, 0, VNIE_REG); 8178c2ecf20Sopenharmony_ci} 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_cistatic u32 rvin_get_interrupt_status(struct rvin_dev *vin) 8208c2ecf20Sopenharmony_ci{ 8218c2ecf20Sopenharmony_ci return rvin_read(vin, VNINTS_REG); 8228c2ecf20Sopenharmony_ci} 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_cistatic void rvin_ack_interrupt(struct rvin_dev *vin) 8258c2ecf20Sopenharmony_ci{ 8268c2ecf20Sopenharmony_ci rvin_write(vin, rvin_read(vin, VNINTS_REG), VNINTS_REG); 8278c2ecf20Sopenharmony_ci} 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_cistatic bool rvin_capture_active(struct rvin_dev *vin) 8308c2ecf20Sopenharmony_ci{ 8318c2ecf20Sopenharmony_ci return rvin_read(vin, VNMS_REG) & VNMS_CA; 8328c2ecf20Sopenharmony_ci} 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_cistatic enum v4l2_field rvin_get_active_field(struct rvin_dev *vin, u32 vnms) 8358c2ecf20Sopenharmony_ci{ 8368c2ecf20Sopenharmony_ci if (vin->format.field == V4L2_FIELD_ALTERNATE) { 8378c2ecf20Sopenharmony_ci /* If FS is set it is an Even field. */ 8388c2ecf20Sopenharmony_ci if (vnms & VNMS_FS) 8398c2ecf20Sopenharmony_ci return V4L2_FIELD_BOTTOM; 8408c2ecf20Sopenharmony_ci return V4L2_FIELD_TOP; 8418c2ecf20Sopenharmony_ci } 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci return vin->format.field; 8448c2ecf20Sopenharmony_ci} 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_cistatic void rvin_set_slot_addr(struct rvin_dev *vin, int slot, dma_addr_t addr) 8478c2ecf20Sopenharmony_ci{ 8488c2ecf20Sopenharmony_ci const struct rvin_video_format *fmt; 8498c2ecf20Sopenharmony_ci int offsetx, offsety; 8508c2ecf20Sopenharmony_ci dma_addr_t offset; 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci fmt = rvin_format_from_pixel(vin, vin->format.pixelformat); 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_ci /* 8558c2ecf20Sopenharmony_ci * There is no HW support for composition do the beast we can 8568c2ecf20Sopenharmony_ci * by modifying the buffer offset 8578c2ecf20Sopenharmony_ci */ 8588c2ecf20Sopenharmony_ci offsetx = vin->compose.left * fmt->bpp; 8598c2ecf20Sopenharmony_ci offsety = vin->compose.top * vin->format.bytesperline; 8608c2ecf20Sopenharmony_ci offset = addr + offsetx + offsety; 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci /* 8638c2ecf20Sopenharmony_ci * The address needs to be 128 bytes aligned. Driver should never accept 8648c2ecf20Sopenharmony_ci * settings that do not satisfy this in the first place... 8658c2ecf20Sopenharmony_ci */ 8668c2ecf20Sopenharmony_ci if (WARN_ON((offsetx | offsety | offset) & HW_BUFFER_MASK)) 8678c2ecf20Sopenharmony_ci return; 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci rvin_write(vin, offset, VNMB_REG(slot)); 8708c2ecf20Sopenharmony_ci} 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_ci/* 8738c2ecf20Sopenharmony_ci * Moves a buffer from the queue to the HW slot. If no buffer is 8748c2ecf20Sopenharmony_ci * available use the scratch buffer. The scratch buffer is never 8758c2ecf20Sopenharmony_ci * returned to userspace, its only function is to enable the capture 8768c2ecf20Sopenharmony_ci * loop to keep running. 8778c2ecf20Sopenharmony_ci */ 8788c2ecf20Sopenharmony_cistatic void rvin_fill_hw_slot(struct rvin_dev *vin, int slot) 8798c2ecf20Sopenharmony_ci{ 8808c2ecf20Sopenharmony_ci struct rvin_buffer *buf; 8818c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer *vbuf; 8828c2ecf20Sopenharmony_ci dma_addr_t phys_addr; 8838c2ecf20Sopenharmony_ci int prev; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci /* A already populated slot shall never be overwritten. */ 8868c2ecf20Sopenharmony_ci if (WARN_ON(vin->buf_hw[slot].buffer)) 8878c2ecf20Sopenharmony_ci return; 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci prev = (slot == 0 ? HW_BUFFER_NUM : slot) - 1; 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci if (vin->buf_hw[prev].type == HALF_TOP) { 8928c2ecf20Sopenharmony_ci vbuf = vin->buf_hw[prev].buffer; 8938c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer = vbuf; 8948c2ecf20Sopenharmony_ci vin->buf_hw[slot].type = HALF_BOTTOM; 8958c2ecf20Sopenharmony_ci switch (vin->format.pixelformat) { 8968c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV12: 8978c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_NV16: 8988c2ecf20Sopenharmony_ci phys_addr = vin->buf_hw[prev].phys + 8998c2ecf20Sopenharmony_ci vin->format.sizeimage / 4; 9008c2ecf20Sopenharmony_ci break; 9018c2ecf20Sopenharmony_ci default: 9028c2ecf20Sopenharmony_ci phys_addr = vin->buf_hw[prev].phys + 9038c2ecf20Sopenharmony_ci vin->format.sizeimage / 2; 9048c2ecf20Sopenharmony_ci break; 9058c2ecf20Sopenharmony_ci } 9068c2ecf20Sopenharmony_ci } else if (list_empty(&vin->buf_list)) { 9078c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer = NULL; 9088c2ecf20Sopenharmony_ci vin->buf_hw[slot].type = FULL; 9098c2ecf20Sopenharmony_ci phys_addr = vin->scratch_phys; 9108c2ecf20Sopenharmony_ci } else { 9118c2ecf20Sopenharmony_ci /* Keep track of buffer we give to HW */ 9128c2ecf20Sopenharmony_ci buf = list_entry(vin->buf_list.next, struct rvin_buffer, list); 9138c2ecf20Sopenharmony_ci vbuf = &buf->vb; 9148c2ecf20Sopenharmony_ci list_del_init(to_buf_list(vbuf)); 9158c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer = vbuf; 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci vin->buf_hw[slot].type = 9188c2ecf20Sopenharmony_ci V4L2_FIELD_IS_SEQUENTIAL(vin->format.field) ? 9198c2ecf20Sopenharmony_ci HALF_TOP : FULL; 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ci /* Setup DMA */ 9228c2ecf20Sopenharmony_ci phys_addr = vb2_dma_contig_plane_dma_addr(&vbuf->vb2_buf, 0); 9238c2ecf20Sopenharmony_ci } 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci vin_dbg(vin, "Filling HW slot: %d type: %d buffer: %p\n", 9268c2ecf20Sopenharmony_ci slot, vin->buf_hw[slot].type, vin->buf_hw[slot].buffer); 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ci vin->buf_hw[slot].phys = phys_addr; 9298c2ecf20Sopenharmony_ci rvin_set_slot_addr(vin, slot, phys_addr); 9308c2ecf20Sopenharmony_ci} 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_cistatic int rvin_capture_start(struct rvin_dev *vin) 9338c2ecf20Sopenharmony_ci{ 9348c2ecf20Sopenharmony_ci int slot, ret; 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci for (slot = 0; slot < HW_BUFFER_NUM; slot++) { 9378c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer = NULL; 9388c2ecf20Sopenharmony_ci vin->buf_hw[slot].type = FULL; 9398c2ecf20Sopenharmony_ci } 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ci for (slot = 0; slot < HW_BUFFER_NUM; slot++) 9428c2ecf20Sopenharmony_ci rvin_fill_hw_slot(vin, slot); 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci rvin_crop_scale_comp(vin); 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_ci ret = rvin_setup(vin); 9478c2ecf20Sopenharmony_ci if (ret) 9488c2ecf20Sopenharmony_ci return ret; 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci vin_dbg(vin, "Starting to capture\n"); 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci /* Continuous Frame Capture Mode */ 9538c2ecf20Sopenharmony_ci rvin_write(vin, VNFC_C_FRAME, VNFC_REG); 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci vin->state = STARTING; 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci return 0; 9588c2ecf20Sopenharmony_ci} 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_cistatic void rvin_capture_stop(struct rvin_dev *vin) 9618c2ecf20Sopenharmony_ci{ 9628c2ecf20Sopenharmony_ci /* Set continuous & single transfer off */ 9638c2ecf20Sopenharmony_ci rvin_write(vin, 0, VNFC_REG); 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci /* Disable module */ 9668c2ecf20Sopenharmony_ci rvin_write(vin, rvin_read(vin, VNMC_REG) & ~VNMC_ME, VNMC_REG); 9678c2ecf20Sopenharmony_ci} 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 9708c2ecf20Sopenharmony_ci * DMA Functions 9718c2ecf20Sopenharmony_ci */ 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci#define RVIN_TIMEOUT_MS 100 9748c2ecf20Sopenharmony_ci#define RVIN_RETRIES 10 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_cistatic irqreturn_t rvin_irq(int irq, void *data) 9778c2ecf20Sopenharmony_ci{ 9788c2ecf20Sopenharmony_ci struct rvin_dev *vin = data; 9798c2ecf20Sopenharmony_ci u32 int_status, vnms; 9808c2ecf20Sopenharmony_ci int slot; 9818c2ecf20Sopenharmony_ci unsigned int handled = 0; 9828c2ecf20Sopenharmony_ci unsigned long flags; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci int_status = rvin_get_interrupt_status(vin); 9878c2ecf20Sopenharmony_ci if (!int_status) 9888c2ecf20Sopenharmony_ci goto done; 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci rvin_ack_interrupt(vin); 9918c2ecf20Sopenharmony_ci handled = 1; 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_ci /* Nothing to do if capture status is 'STOPPED' */ 9948c2ecf20Sopenharmony_ci if (vin->state == STOPPED) { 9958c2ecf20Sopenharmony_ci vin_dbg(vin, "IRQ while state stopped\n"); 9968c2ecf20Sopenharmony_ci goto done; 9978c2ecf20Sopenharmony_ci } 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_ci /* Nothing to do if capture status is 'STOPPING' */ 10008c2ecf20Sopenharmony_ci if (vin->state == STOPPING) { 10018c2ecf20Sopenharmony_ci vin_dbg(vin, "IRQ while state stopping\n"); 10028c2ecf20Sopenharmony_ci goto done; 10038c2ecf20Sopenharmony_ci } 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci /* Prepare for capture and update state */ 10068c2ecf20Sopenharmony_ci vnms = rvin_read(vin, VNMS_REG); 10078c2ecf20Sopenharmony_ci slot = (vnms & VNMS_FBS_MASK) >> VNMS_FBS_SHIFT; 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci /* 10108c2ecf20Sopenharmony_ci * To hand buffers back in a known order to userspace start 10118c2ecf20Sopenharmony_ci * to capture first from slot 0. 10128c2ecf20Sopenharmony_ci */ 10138c2ecf20Sopenharmony_ci if (vin->state == STARTING) { 10148c2ecf20Sopenharmony_ci if (slot != 0) { 10158c2ecf20Sopenharmony_ci vin_dbg(vin, "Starting sync slot: %d\n", slot); 10168c2ecf20Sopenharmony_ci goto done; 10178c2ecf20Sopenharmony_ci } 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci vin_dbg(vin, "Capture start synced!\n"); 10208c2ecf20Sopenharmony_ci vin->state = RUNNING; 10218c2ecf20Sopenharmony_ci } 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_ci /* Capture frame */ 10248c2ecf20Sopenharmony_ci if (vin->buf_hw[slot].buffer) { 10258c2ecf20Sopenharmony_ci /* 10268c2ecf20Sopenharmony_ci * Nothing to do but refill the hardware slot if 10278c2ecf20Sopenharmony_ci * capture only filled first half of vb2 buffer. 10288c2ecf20Sopenharmony_ci */ 10298c2ecf20Sopenharmony_ci if (vin->buf_hw[slot].type == HALF_TOP) { 10308c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer = NULL; 10318c2ecf20Sopenharmony_ci rvin_fill_hw_slot(vin, slot); 10328c2ecf20Sopenharmony_ci goto done; 10338c2ecf20Sopenharmony_ci } 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer->field = 10368c2ecf20Sopenharmony_ci rvin_get_active_field(vin, vnms); 10378c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer->sequence = vin->sequence; 10388c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer->vb2_buf.timestamp = ktime_get_ns(); 10398c2ecf20Sopenharmony_ci vb2_buffer_done(&vin->buf_hw[slot].buffer->vb2_buf, 10408c2ecf20Sopenharmony_ci VB2_BUF_STATE_DONE); 10418c2ecf20Sopenharmony_ci vin->buf_hw[slot].buffer = NULL; 10428c2ecf20Sopenharmony_ci } else { 10438c2ecf20Sopenharmony_ci /* Scratch buffer was used, dropping frame. */ 10448c2ecf20Sopenharmony_ci vin_dbg(vin, "Dropping frame %u\n", vin->sequence); 10458c2ecf20Sopenharmony_ci } 10468c2ecf20Sopenharmony_ci 10478c2ecf20Sopenharmony_ci vin->sequence++; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci /* Prepare for next frame */ 10508c2ecf20Sopenharmony_ci rvin_fill_hw_slot(vin, slot); 10518c2ecf20Sopenharmony_cidone: 10528c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci return IRQ_RETVAL(handled); 10558c2ecf20Sopenharmony_ci} 10568c2ecf20Sopenharmony_ci 10578c2ecf20Sopenharmony_ci/* Need to hold qlock before calling */ 10588c2ecf20Sopenharmony_cistatic void return_all_buffers(struct rvin_dev *vin, 10598c2ecf20Sopenharmony_ci enum vb2_buffer_state state) 10608c2ecf20Sopenharmony_ci{ 10618c2ecf20Sopenharmony_ci struct rvin_buffer *buf, *node; 10628c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer *freed[HW_BUFFER_NUM]; 10638c2ecf20Sopenharmony_ci unsigned int i, n; 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci for (i = 0; i < HW_BUFFER_NUM; i++) { 10668c2ecf20Sopenharmony_ci freed[i] = vin->buf_hw[i].buffer; 10678c2ecf20Sopenharmony_ci vin->buf_hw[i].buffer = NULL; 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci for (n = 0; n < i; n++) { 10708c2ecf20Sopenharmony_ci if (freed[i] == freed[n]) { 10718c2ecf20Sopenharmony_ci freed[i] = NULL; 10728c2ecf20Sopenharmony_ci break; 10738c2ecf20Sopenharmony_ci } 10748c2ecf20Sopenharmony_ci } 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci if (freed[i]) 10778c2ecf20Sopenharmony_ci vb2_buffer_done(&freed[i]->vb2_buf, state); 10788c2ecf20Sopenharmony_ci } 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci list_for_each_entry_safe(buf, node, &vin->buf_list, list) { 10818c2ecf20Sopenharmony_ci vb2_buffer_done(&buf->vb.vb2_buf, state); 10828c2ecf20Sopenharmony_ci list_del(&buf->list); 10838c2ecf20Sopenharmony_ci } 10848c2ecf20Sopenharmony_ci} 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_cistatic int rvin_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, 10878c2ecf20Sopenharmony_ci unsigned int *nplanes, unsigned int sizes[], 10888c2ecf20Sopenharmony_ci struct device *alloc_devs[]) 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci{ 10918c2ecf20Sopenharmony_ci struct rvin_dev *vin = vb2_get_drv_priv(vq); 10928c2ecf20Sopenharmony_ci 10938c2ecf20Sopenharmony_ci /* Make sure the image size is large enough. */ 10948c2ecf20Sopenharmony_ci if (*nplanes) 10958c2ecf20Sopenharmony_ci return sizes[0] < vin->format.sizeimage ? -EINVAL : 0; 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci *nplanes = 1; 10988c2ecf20Sopenharmony_ci sizes[0] = vin->format.sizeimage; 10998c2ecf20Sopenharmony_ci 11008c2ecf20Sopenharmony_ci return 0; 11018c2ecf20Sopenharmony_ci}; 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_cistatic int rvin_buffer_prepare(struct vb2_buffer *vb) 11048c2ecf20Sopenharmony_ci{ 11058c2ecf20Sopenharmony_ci struct rvin_dev *vin = vb2_get_drv_priv(vb->vb2_queue); 11068c2ecf20Sopenharmony_ci unsigned long size = vin->format.sizeimage; 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci if (vb2_plane_size(vb, 0) < size) { 11098c2ecf20Sopenharmony_ci vin_err(vin, "buffer too small (%lu < %lu)\n", 11108c2ecf20Sopenharmony_ci vb2_plane_size(vb, 0), size); 11118c2ecf20Sopenharmony_ci return -EINVAL; 11128c2ecf20Sopenharmony_ci } 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci vb2_set_plane_payload(vb, 0, size); 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_ci return 0; 11178c2ecf20Sopenharmony_ci} 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_cistatic void rvin_buffer_queue(struct vb2_buffer *vb) 11208c2ecf20Sopenharmony_ci{ 11218c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 11228c2ecf20Sopenharmony_ci struct rvin_dev *vin = vb2_get_drv_priv(vb->vb2_queue); 11238c2ecf20Sopenharmony_ci unsigned long flags; 11248c2ecf20Sopenharmony_ci 11258c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci list_add_tail(to_buf_list(vbuf), &vin->buf_list); 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 11308c2ecf20Sopenharmony_ci} 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_cistatic int rvin_mc_validate_format(struct rvin_dev *vin, struct v4l2_subdev *sd, 11338c2ecf20Sopenharmony_ci struct media_pad *pad) 11348c2ecf20Sopenharmony_ci{ 11358c2ecf20Sopenharmony_ci struct v4l2_subdev_format fmt = { 11368c2ecf20Sopenharmony_ci .which = V4L2_SUBDEV_FORMAT_ACTIVE, 11378c2ecf20Sopenharmony_ci }; 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci fmt.pad = pad->index; 11408c2ecf20Sopenharmony_ci if (v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt)) 11418c2ecf20Sopenharmony_ci return -EPIPE; 11428c2ecf20Sopenharmony_ci 11438c2ecf20Sopenharmony_ci switch (fmt.format.code) { 11448c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_YUYV8_1X16: 11458c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_1X16: 11468c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY8_2X8: 11478c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_UYVY10_2X10: 11488c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_RGB888_1X24: 11498c2ecf20Sopenharmony_ci break; 11508c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SBGGR8_1X8: 11518c2ecf20Sopenharmony_ci if (vin->format.pixelformat != V4L2_PIX_FMT_SBGGR8) 11528c2ecf20Sopenharmony_ci return -EPIPE; 11538c2ecf20Sopenharmony_ci break; 11548c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SGBRG8_1X8: 11558c2ecf20Sopenharmony_ci if (vin->format.pixelformat != V4L2_PIX_FMT_SGBRG8) 11568c2ecf20Sopenharmony_ci return -EPIPE; 11578c2ecf20Sopenharmony_ci break; 11588c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SGRBG8_1X8: 11598c2ecf20Sopenharmony_ci if (vin->format.pixelformat != V4L2_PIX_FMT_SGRBG8) 11608c2ecf20Sopenharmony_ci return -EPIPE; 11618c2ecf20Sopenharmony_ci break; 11628c2ecf20Sopenharmony_ci case MEDIA_BUS_FMT_SRGGB8_1X8: 11638c2ecf20Sopenharmony_ci if (vin->format.pixelformat != V4L2_PIX_FMT_SRGGB8) 11648c2ecf20Sopenharmony_ci return -EPIPE; 11658c2ecf20Sopenharmony_ci break; 11668c2ecf20Sopenharmony_ci default: 11678c2ecf20Sopenharmony_ci return -EPIPE; 11688c2ecf20Sopenharmony_ci } 11698c2ecf20Sopenharmony_ci vin->mbus_code = fmt.format.code; 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci switch (fmt.format.field) { 11728c2ecf20Sopenharmony_ci case V4L2_FIELD_TOP: 11738c2ecf20Sopenharmony_ci case V4L2_FIELD_BOTTOM: 11748c2ecf20Sopenharmony_ci case V4L2_FIELD_NONE: 11758c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED_TB: 11768c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED_BT: 11778c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED: 11788c2ecf20Sopenharmony_ci case V4L2_FIELD_SEQ_TB: 11798c2ecf20Sopenharmony_ci case V4L2_FIELD_SEQ_BT: 11808c2ecf20Sopenharmony_ci /* Supported natively */ 11818c2ecf20Sopenharmony_ci break; 11828c2ecf20Sopenharmony_ci case V4L2_FIELD_ALTERNATE: 11838c2ecf20Sopenharmony_ci switch (vin->format.field) { 11848c2ecf20Sopenharmony_ci case V4L2_FIELD_TOP: 11858c2ecf20Sopenharmony_ci case V4L2_FIELD_BOTTOM: 11868c2ecf20Sopenharmony_ci case V4L2_FIELD_NONE: 11878c2ecf20Sopenharmony_ci case V4L2_FIELD_ALTERNATE: 11888c2ecf20Sopenharmony_ci break; 11898c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED_TB: 11908c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED_BT: 11918c2ecf20Sopenharmony_ci case V4L2_FIELD_INTERLACED: 11928c2ecf20Sopenharmony_ci case V4L2_FIELD_SEQ_TB: 11938c2ecf20Sopenharmony_ci case V4L2_FIELD_SEQ_BT: 11948c2ecf20Sopenharmony_ci /* Use VIN hardware to combine the two fields */ 11958c2ecf20Sopenharmony_ci fmt.format.height *= 2; 11968c2ecf20Sopenharmony_ci break; 11978c2ecf20Sopenharmony_ci default: 11988c2ecf20Sopenharmony_ci return -EPIPE; 11998c2ecf20Sopenharmony_ci } 12008c2ecf20Sopenharmony_ci break; 12018c2ecf20Sopenharmony_ci default: 12028c2ecf20Sopenharmony_ci return -EPIPE; 12038c2ecf20Sopenharmony_ci } 12048c2ecf20Sopenharmony_ci 12058c2ecf20Sopenharmony_ci if (fmt.format.width != vin->format.width || 12068c2ecf20Sopenharmony_ci fmt.format.height != vin->format.height || 12078c2ecf20Sopenharmony_ci fmt.format.code != vin->mbus_code) 12088c2ecf20Sopenharmony_ci return -EPIPE; 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_ci return 0; 12118c2ecf20Sopenharmony_ci} 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_cistatic int rvin_set_stream(struct rvin_dev *vin, int on) 12148c2ecf20Sopenharmony_ci{ 12158c2ecf20Sopenharmony_ci struct media_pipeline *pipe; 12168c2ecf20Sopenharmony_ci struct media_device *mdev; 12178c2ecf20Sopenharmony_ci struct v4l2_subdev *sd; 12188c2ecf20Sopenharmony_ci struct media_pad *pad; 12198c2ecf20Sopenharmony_ci int ret; 12208c2ecf20Sopenharmony_ci 12218c2ecf20Sopenharmony_ci /* No media controller used, simply pass operation to subdevice. */ 12228c2ecf20Sopenharmony_ci if (!vin->info->use_mc) { 12238c2ecf20Sopenharmony_ci ret = v4l2_subdev_call(vin->parallel->subdev, video, s_stream, 12248c2ecf20Sopenharmony_ci on); 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci return ret == -ENOIOCTLCMD ? 0 : ret; 12278c2ecf20Sopenharmony_ci } 12288c2ecf20Sopenharmony_ci 12298c2ecf20Sopenharmony_ci pad = media_entity_remote_pad(&vin->pad); 12308c2ecf20Sopenharmony_ci if (!pad) 12318c2ecf20Sopenharmony_ci return -EPIPE; 12328c2ecf20Sopenharmony_ci 12338c2ecf20Sopenharmony_ci sd = media_entity_to_v4l2_subdev(pad->entity); 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_ci if (!on) { 12368c2ecf20Sopenharmony_ci media_pipeline_stop(&vin->vdev.entity); 12378c2ecf20Sopenharmony_ci return v4l2_subdev_call(sd, video, s_stream, 0); 12388c2ecf20Sopenharmony_ci } 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci ret = rvin_mc_validate_format(vin, sd, pad); 12418c2ecf20Sopenharmony_ci if (ret) 12428c2ecf20Sopenharmony_ci return ret; 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_ci /* 12458c2ecf20Sopenharmony_ci * The graph lock needs to be taken to protect concurrent 12468c2ecf20Sopenharmony_ci * starts of multiple VIN instances as they might share 12478c2ecf20Sopenharmony_ci * a common subdevice down the line and then should use 12488c2ecf20Sopenharmony_ci * the same pipe. 12498c2ecf20Sopenharmony_ci */ 12508c2ecf20Sopenharmony_ci mdev = vin->vdev.entity.graph_obj.mdev; 12518c2ecf20Sopenharmony_ci mutex_lock(&mdev->graph_mutex); 12528c2ecf20Sopenharmony_ci pipe = sd->entity.pipe ? sd->entity.pipe : &vin->vdev.pipe; 12538c2ecf20Sopenharmony_ci ret = __media_pipeline_start(&vin->vdev.entity, pipe); 12548c2ecf20Sopenharmony_ci mutex_unlock(&mdev->graph_mutex); 12558c2ecf20Sopenharmony_ci if (ret) 12568c2ecf20Sopenharmony_ci return ret; 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_ci ret = v4l2_subdev_call(sd, video, s_stream, 1); 12598c2ecf20Sopenharmony_ci if (ret == -ENOIOCTLCMD) 12608c2ecf20Sopenharmony_ci ret = 0; 12618c2ecf20Sopenharmony_ci if (ret) 12628c2ecf20Sopenharmony_ci media_pipeline_stop(&vin->vdev.entity); 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci return ret; 12658c2ecf20Sopenharmony_ci} 12668c2ecf20Sopenharmony_ci 12678c2ecf20Sopenharmony_cistatic int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) 12688c2ecf20Sopenharmony_ci{ 12698c2ecf20Sopenharmony_ci struct rvin_dev *vin = vb2_get_drv_priv(vq); 12708c2ecf20Sopenharmony_ci unsigned long flags; 12718c2ecf20Sopenharmony_ci int ret; 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci /* Allocate scratch buffer. */ 12748c2ecf20Sopenharmony_ci vin->scratch = dma_alloc_coherent(vin->dev, vin->format.sizeimage, 12758c2ecf20Sopenharmony_ci &vin->scratch_phys, GFP_KERNEL); 12768c2ecf20Sopenharmony_ci if (!vin->scratch) { 12778c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 12788c2ecf20Sopenharmony_ci return_all_buffers(vin, VB2_BUF_STATE_QUEUED); 12798c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 12808c2ecf20Sopenharmony_ci vin_err(vin, "Failed to allocate scratch buffer\n"); 12818c2ecf20Sopenharmony_ci return -ENOMEM; 12828c2ecf20Sopenharmony_ci } 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci ret = rvin_set_stream(vin, 1); 12858c2ecf20Sopenharmony_ci if (ret) { 12868c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 12878c2ecf20Sopenharmony_ci return_all_buffers(vin, VB2_BUF_STATE_QUEUED); 12888c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 12898c2ecf20Sopenharmony_ci goto out; 12908c2ecf20Sopenharmony_ci } 12918c2ecf20Sopenharmony_ci 12928c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_ci vin->sequence = 0; 12958c2ecf20Sopenharmony_ci 12968c2ecf20Sopenharmony_ci ret = rvin_capture_start(vin); 12978c2ecf20Sopenharmony_ci if (ret) { 12988c2ecf20Sopenharmony_ci return_all_buffers(vin, VB2_BUF_STATE_QUEUED); 12998c2ecf20Sopenharmony_ci rvin_set_stream(vin, 0); 13008c2ecf20Sopenharmony_ci } 13018c2ecf20Sopenharmony_ci 13028c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 13038c2ecf20Sopenharmony_ciout: 13048c2ecf20Sopenharmony_ci if (ret) 13058c2ecf20Sopenharmony_ci dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, 13068c2ecf20Sopenharmony_ci vin->scratch_phys); 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_ci return ret; 13098c2ecf20Sopenharmony_ci} 13108c2ecf20Sopenharmony_ci 13118c2ecf20Sopenharmony_cistatic void rvin_stop_streaming(struct vb2_queue *vq) 13128c2ecf20Sopenharmony_ci{ 13138c2ecf20Sopenharmony_ci struct rvin_dev *vin = vb2_get_drv_priv(vq); 13148c2ecf20Sopenharmony_ci unsigned long flags; 13158c2ecf20Sopenharmony_ci int retries = 0; 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci vin->state = STOPPING; 13208c2ecf20Sopenharmony_ci 13218c2ecf20Sopenharmony_ci /* Wait for streaming to stop */ 13228c2ecf20Sopenharmony_ci while (retries++ < RVIN_RETRIES) { 13238c2ecf20Sopenharmony_ci 13248c2ecf20Sopenharmony_ci rvin_capture_stop(vin); 13258c2ecf20Sopenharmony_ci 13268c2ecf20Sopenharmony_ci /* Check if HW is stopped */ 13278c2ecf20Sopenharmony_ci if (!rvin_capture_active(vin)) { 13288c2ecf20Sopenharmony_ci vin->state = STOPPED; 13298c2ecf20Sopenharmony_ci break; 13308c2ecf20Sopenharmony_ci } 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 13338c2ecf20Sopenharmony_ci msleep(RVIN_TIMEOUT_MS); 13348c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 13358c2ecf20Sopenharmony_ci } 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci if (vin->state != STOPPED) { 13388c2ecf20Sopenharmony_ci /* 13398c2ecf20Sopenharmony_ci * If this happens something have gone horribly wrong. 13408c2ecf20Sopenharmony_ci * Set state to stopped to prevent the interrupt handler 13418c2ecf20Sopenharmony_ci * to make things worse... 13428c2ecf20Sopenharmony_ci */ 13438c2ecf20Sopenharmony_ci vin_err(vin, "Failed stop HW, something is seriously broken\n"); 13448c2ecf20Sopenharmony_ci vin->state = STOPPED; 13458c2ecf20Sopenharmony_ci } 13468c2ecf20Sopenharmony_ci 13478c2ecf20Sopenharmony_ci /* Release all active buffers */ 13488c2ecf20Sopenharmony_ci return_all_buffers(vin, VB2_BUF_STATE_ERROR); 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci rvin_set_stream(vin, 0); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci /* disable interrupts */ 13558c2ecf20Sopenharmony_ci rvin_disable_interrupts(vin); 13568c2ecf20Sopenharmony_ci 13578c2ecf20Sopenharmony_ci /* Free scratch buffer. */ 13588c2ecf20Sopenharmony_ci dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, 13598c2ecf20Sopenharmony_ci vin->scratch_phys); 13608c2ecf20Sopenharmony_ci} 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_cistatic const struct vb2_ops rvin_qops = { 13638c2ecf20Sopenharmony_ci .queue_setup = rvin_queue_setup, 13648c2ecf20Sopenharmony_ci .buf_prepare = rvin_buffer_prepare, 13658c2ecf20Sopenharmony_ci .buf_queue = rvin_buffer_queue, 13668c2ecf20Sopenharmony_ci .start_streaming = rvin_start_streaming, 13678c2ecf20Sopenharmony_ci .stop_streaming = rvin_stop_streaming, 13688c2ecf20Sopenharmony_ci .wait_prepare = vb2_ops_wait_prepare, 13698c2ecf20Sopenharmony_ci .wait_finish = vb2_ops_wait_finish, 13708c2ecf20Sopenharmony_ci}; 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_civoid rvin_dma_unregister(struct rvin_dev *vin) 13738c2ecf20Sopenharmony_ci{ 13748c2ecf20Sopenharmony_ci mutex_destroy(&vin->lock); 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_ci v4l2_device_unregister(&vin->v4l2_dev); 13778c2ecf20Sopenharmony_ci} 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_ciint rvin_dma_register(struct rvin_dev *vin, int irq) 13808c2ecf20Sopenharmony_ci{ 13818c2ecf20Sopenharmony_ci struct vb2_queue *q = &vin->queue; 13828c2ecf20Sopenharmony_ci int i, ret; 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci /* Initialize the top-level structure */ 13858c2ecf20Sopenharmony_ci ret = v4l2_device_register(vin->dev, &vin->v4l2_dev); 13868c2ecf20Sopenharmony_ci if (ret) 13878c2ecf20Sopenharmony_ci return ret; 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_ci mutex_init(&vin->lock); 13908c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&vin->buf_list); 13918c2ecf20Sopenharmony_ci 13928c2ecf20Sopenharmony_ci spin_lock_init(&vin->qlock); 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_ci vin->state = STOPPED; 13958c2ecf20Sopenharmony_ci 13968c2ecf20Sopenharmony_ci for (i = 0; i < HW_BUFFER_NUM; i++) 13978c2ecf20Sopenharmony_ci vin->buf_hw[i].buffer = NULL; 13988c2ecf20Sopenharmony_ci 13998c2ecf20Sopenharmony_ci /* buffer queue */ 14008c2ecf20Sopenharmony_ci q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 14018c2ecf20Sopenharmony_ci q->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF; 14028c2ecf20Sopenharmony_ci q->lock = &vin->lock; 14038c2ecf20Sopenharmony_ci q->drv_priv = vin; 14048c2ecf20Sopenharmony_ci q->buf_struct_size = sizeof(struct rvin_buffer); 14058c2ecf20Sopenharmony_ci q->ops = &rvin_qops; 14068c2ecf20Sopenharmony_ci q->mem_ops = &vb2_dma_contig_memops; 14078c2ecf20Sopenharmony_ci q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 14088c2ecf20Sopenharmony_ci q->min_buffers_needed = 4; 14098c2ecf20Sopenharmony_ci q->dev = vin->dev; 14108c2ecf20Sopenharmony_ci 14118c2ecf20Sopenharmony_ci ret = vb2_queue_init(q); 14128c2ecf20Sopenharmony_ci if (ret < 0) { 14138c2ecf20Sopenharmony_ci vin_err(vin, "failed to initialize VB2 queue\n"); 14148c2ecf20Sopenharmony_ci goto error; 14158c2ecf20Sopenharmony_ci } 14168c2ecf20Sopenharmony_ci 14178c2ecf20Sopenharmony_ci /* irq */ 14188c2ecf20Sopenharmony_ci ret = devm_request_irq(vin->dev, irq, rvin_irq, IRQF_SHARED, 14198c2ecf20Sopenharmony_ci KBUILD_MODNAME, vin); 14208c2ecf20Sopenharmony_ci if (ret) { 14218c2ecf20Sopenharmony_ci vin_err(vin, "failed to request irq\n"); 14228c2ecf20Sopenharmony_ci goto error; 14238c2ecf20Sopenharmony_ci } 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci return 0; 14268c2ecf20Sopenharmony_cierror: 14278c2ecf20Sopenharmony_ci rvin_dma_unregister(vin); 14288c2ecf20Sopenharmony_ci 14298c2ecf20Sopenharmony_ci return ret; 14308c2ecf20Sopenharmony_ci} 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 14338c2ecf20Sopenharmony_ci * Gen3 CHSEL manipulation 14348c2ecf20Sopenharmony_ci */ 14358c2ecf20Sopenharmony_ci 14368c2ecf20Sopenharmony_ci/* 14378c2ecf20Sopenharmony_ci * There is no need to have locking around changing the routing 14388c2ecf20Sopenharmony_ci * as it's only possible to do so when no VIN in the group is 14398c2ecf20Sopenharmony_ci * streaming so nothing can race with the VNMC register. 14408c2ecf20Sopenharmony_ci */ 14418c2ecf20Sopenharmony_ciint rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel) 14428c2ecf20Sopenharmony_ci{ 14438c2ecf20Sopenharmony_ci u32 ifmd, vnmc; 14448c2ecf20Sopenharmony_ci int ret; 14458c2ecf20Sopenharmony_ci 14468c2ecf20Sopenharmony_ci ret = pm_runtime_get_sync(vin->dev); 14478c2ecf20Sopenharmony_ci if (ret < 0) { 14488c2ecf20Sopenharmony_ci pm_runtime_put_noidle(vin->dev); 14498c2ecf20Sopenharmony_ci return ret; 14508c2ecf20Sopenharmony_ci } 14518c2ecf20Sopenharmony_ci 14528c2ecf20Sopenharmony_ci /* Make register writes take effect immediately. */ 14538c2ecf20Sopenharmony_ci vnmc = rvin_read(vin, VNMC_REG); 14548c2ecf20Sopenharmony_ci rvin_write(vin, vnmc & ~VNMC_VUP, VNMC_REG); 14558c2ecf20Sopenharmony_ci 14568c2ecf20Sopenharmony_ci ifmd = VNCSI_IFMD_DES1 | VNCSI_IFMD_DES0 | VNCSI_IFMD_CSI_CHSEL(chsel); 14578c2ecf20Sopenharmony_ci 14588c2ecf20Sopenharmony_ci rvin_write(vin, ifmd, VNCSI_IFMD_REG); 14598c2ecf20Sopenharmony_ci 14608c2ecf20Sopenharmony_ci vin_dbg(vin, "Set IFMD 0x%x\n", ifmd); 14618c2ecf20Sopenharmony_ci 14628c2ecf20Sopenharmony_ci /* Restore VNMC. */ 14638c2ecf20Sopenharmony_ci rvin_write(vin, vnmc, VNMC_REG); 14648c2ecf20Sopenharmony_ci 14658c2ecf20Sopenharmony_ci pm_runtime_put(vin->dev); 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_ci return 0; 14688c2ecf20Sopenharmony_ci} 14698c2ecf20Sopenharmony_ci 14708c2ecf20Sopenharmony_civoid rvin_set_alpha(struct rvin_dev *vin, unsigned int alpha) 14718c2ecf20Sopenharmony_ci{ 14728c2ecf20Sopenharmony_ci unsigned long flags; 14738c2ecf20Sopenharmony_ci u32 dmr; 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_ci spin_lock_irqsave(&vin->qlock, flags); 14768c2ecf20Sopenharmony_ci 14778c2ecf20Sopenharmony_ci vin->alpha = alpha; 14788c2ecf20Sopenharmony_ci 14798c2ecf20Sopenharmony_ci if (vin->state == STOPPED) 14808c2ecf20Sopenharmony_ci goto out; 14818c2ecf20Sopenharmony_ci 14828c2ecf20Sopenharmony_ci switch (vin->format.pixelformat) { 14838c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_ARGB555: 14848c2ecf20Sopenharmony_ci dmr = rvin_read(vin, VNDMR_REG) & ~VNDMR_ABIT; 14858c2ecf20Sopenharmony_ci if (vin->alpha) 14868c2ecf20Sopenharmony_ci dmr |= VNDMR_ABIT; 14878c2ecf20Sopenharmony_ci break; 14888c2ecf20Sopenharmony_ci case V4L2_PIX_FMT_ABGR32: 14898c2ecf20Sopenharmony_ci dmr = rvin_read(vin, VNDMR_REG) & ~VNDMR_A8BIT_MASK; 14908c2ecf20Sopenharmony_ci dmr |= VNDMR_A8BIT(vin->alpha); 14918c2ecf20Sopenharmony_ci break; 14928c2ecf20Sopenharmony_ci default: 14938c2ecf20Sopenharmony_ci goto out; 14948c2ecf20Sopenharmony_ci } 14958c2ecf20Sopenharmony_ci 14968c2ecf20Sopenharmony_ci rvin_write(vin, dmr, VNDMR_REG); 14978c2ecf20Sopenharmony_ciout: 14988c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vin->qlock, flags); 14998c2ecf20Sopenharmony_ci} 1500