18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright 2019 NXP. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/clk.h> 78c2ecf20Sopenharmony_ci#include <linux/delay.h> 88c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 98c2ecf20Sopenharmony_ci#include <linux/of.h> 108c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 118c2ecf20Sopenharmony_ci#include <linux/slab.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "dcss-dev.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CONTROL_STATUS 0x00 168c2ecf20Sopenharmony_ci#define CH3_EN BIT(0) 178c2ecf20Sopenharmony_ci#define CH2_EN BIT(1) 188c2ecf20Sopenharmony_ci#define CH1_EN BIT(2) 198c2ecf20Sopenharmony_ci#define OVL_DATA_MODE BIT(3) 208c2ecf20Sopenharmony_ci#define BLENDER_VIDEO_ALPHA_SEL BIT(7) 218c2ecf20Sopenharmony_ci#define DTG_START BIT(8) 228c2ecf20Sopenharmony_ci#define DBY_MODE_EN BIT(9) 238c2ecf20Sopenharmony_ci#define CH1_ALPHA_SEL BIT(10) 248c2ecf20Sopenharmony_ci#define CSS_PIX_COMP_SWAP_POS 12 258c2ecf20Sopenharmony_ci#define CSS_PIX_COMP_SWAP_MASK GENMASK(14, 12) 268c2ecf20Sopenharmony_ci#define DEFAULT_FG_ALPHA_POS 24 278c2ecf20Sopenharmony_ci#define DEFAULT_FG_ALPHA_MASK GENMASK(31, 24) 288c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_DTG 0x04 298c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_DISP_TOP 0x08 308c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_DISP_BOT 0x0C 318c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH1_TOP 0x10 328c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH1_BOT 0x14 338c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH2_TOP 0x18 348c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH2_BOT 0x1C 358c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH3_TOP 0x20 368c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH3_BOT 0x24 378c2ecf20Sopenharmony_ci#define TC_X_POS 0 388c2ecf20Sopenharmony_ci#define TC_X_MASK GENMASK(12, 0) 398c2ecf20Sopenharmony_ci#define TC_Y_POS 16 408c2ecf20Sopenharmony_ci#define TC_Y_MASK GENMASK(28, 16) 418c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CTXLD 0x28 428c2ecf20Sopenharmony_ci#define TC_CTXLD_DB_Y_POS 0 438c2ecf20Sopenharmony_ci#define TC_CTXLD_DB_Y_MASK GENMASK(12, 0) 448c2ecf20Sopenharmony_ci#define TC_CTXLD_SB_Y_POS 16 458c2ecf20Sopenharmony_ci#define TC_CTXLD_SB_Y_MASK GENMASK(28, 16) 468c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH1_BKRND 0x2C 478c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH2_BKRND 0x30 488c2ecf20Sopenharmony_ci#define BKRND_R_Y_COMP_POS 20 498c2ecf20Sopenharmony_ci#define BKRND_R_Y_COMP_MASK GENMASK(29, 20) 508c2ecf20Sopenharmony_ci#define BKRND_G_U_COMP_POS 10 518c2ecf20Sopenharmony_ci#define BKRND_G_U_COMP_MASK GENMASK(19, 10) 528c2ecf20Sopenharmony_ci#define BKRND_B_V_COMP_POS 0 538c2ecf20Sopenharmony_ci#define BKRND_B_V_COMP_MASK GENMASK(9, 0) 548c2ecf20Sopenharmony_ci#define DCSS_DTG_BLENDER_DBY_RANGEINV 0x38 558c2ecf20Sopenharmony_ci#define DCSS_DTG_BLENDER_DBY_RANGEMIN 0x3C 568c2ecf20Sopenharmony_ci#define DCSS_DTG_BLENDER_DBY_BDP 0x40 578c2ecf20Sopenharmony_ci#define DCSS_DTG_BLENDER_BKRND_I 0x44 588c2ecf20Sopenharmony_ci#define DCSS_DTG_BLENDER_BKRND_P 0x48 598c2ecf20Sopenharmony_ci#define DCSS_DTG_BLENDER_BKRND_T 0x4C 608c2ecf20Sopenharmony_ci#define DCSS_DTG_LINE0_INT 0x50 618c2ecf20Sopenharmony_ci#define DCSS_DTG_LINE1_INT 0x54 628c2ecf20Sopenharmony_ci#define DCSS_DTG_BG_ALPHA_DEFAULT 0x58 638c2ecf20Sopenharmony_ci#define DCSS_DTG_INT_STATUS 0x5C 648c2ecf20Sopenharmony_ci#define DCSS_DTG_INT_CONTROL 0x60 658c2ecf20Sopenharmony_ci#define DCSS_DTG_TC_CH3_BKRND 0x64 668c2ecf20Sopenharmony_ci#define DCSS_DTG_INT_MASK 0x68 678c2ecf20Sopenharmony_ci#define LINE0_IRQ BIT(0) 688c2ecf20Sopenharmony_ci#define LINE1_IRQ BIT(1) 698c2ecf20Sopenharmony_ci#define LINE2_IRQ BIT(2) 708c2ecf20Sopenharmony_ci#define LINE3_IRQ BIT(3) 718c2ecf20Sopenharmony_ci#define DCSS_DTG_LINE2_INT 0x6C 728c2ecf20Sopenharmony_ci#define DCSS_DTG_LINE3_INT 0x70 738c2ecf20Sopenharmony_ci#define DCSS_DTG_DBY_OL 0x74 748c2ecf20Sopenharmony_ci#define DCSS_DTG_DBY_BL 0x78 758c2ecf20Sopenharmony_ci#define DCSS_DTG_DBY_EL 0x7C 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct dcss_dtg { 788c2ecf20Sopenharmony_ci struct device *dev; 798c2ecf20Sopenharmony_ci struct dcss_ctxld *ctxld; 808c2ecf20Sopenharmony_ci void __iomem *base_reg; 818c2ecf20Sopenharmony_ci u32 base_ofs; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci u32 ctx_id; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci bool in_use; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci u32 dis_ulc_x; 888c2ecf20Sopenharmony_ci u32 dis_ulc_y; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci u32 control_status; 918c2ecf20Sopenharmony_ci u32 alpha; 928c2ecf20Sopenharmony_ci u32 alpha_cfg; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci int ctxld_kick_irq; 958c2ecf20Sopenharmony_ci bool ctxld_kick_irq_en; 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic void dcss_dtg_write(struct dcss_dtg *dtg, u32 val, u32 ofs) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci if (!dtg->in_use) 1018c2ecf20Sopenharmony_ci dcss_writel(val, dtg->base_reg + ofs); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci dcss_ctxld_write(dtg->ctxld, dtg->ctx_id, 1048c2ecf20Sopenharmony_ci val, dtg->base_ofs + ofs); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic irqreturn_t dcss_dtg_irq_handler(int irq, void *data) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci struct dcss_dtg *dtg = data; 1108c2ecf20Sopenharmony_ci u32 status; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci status = dcss_readl(dtg->base_reg + DCSS_DTG_INT_STATUS); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci if (!(status & LINE0_IRQ)) 1158c2ecf20Sopenharmony_ci return IRQ_NONE; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci dcss_ctxld_kick(dtg->ctxld); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci dcss_writel(status & LINE0_IRQ, dtg->base_reg + DCSS_DTG_INT_CONTROL); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci return IRQ_HANDLED; 1228c2ecf20Sopenharmony_ci} 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic int dcss_dtg_irq_config(struct dcss_dtg *dtg, 1258c2ecf20Sopenharmony_ci struct platform_device *pdev) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci int ret; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci dtg->ctxld_kick_irq = platform_get_irq_byname(pdev, "ctxld_kick"); 1308c2ecf20Sopenharmony_ci if (dtg->ctxld_kick_irq < 0) 1318c2ecf20Sopenharmony_ci return dtg->ctxld_kick_irq; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci dcss_update(0, LINE0_IRQ | LINE1_IRQ, 1348c2ecf20Sopenharmony_ci dtg->base_reg + DCSS_DTG_INT_MASK); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci ret = request_irq(dtg->ctxld_kick_irq, dcss_dtg_irq_handler, 1378c2ecf20Sopenharmony_ci 0, "dcss_ctxld_kick", dtg); 1388c2ecf20Sopenharmony_ci if (ret) { 1398c2ecf20Sopenharmony_ci dev_err(dtg->dev, "dtg: irq request failed.\n"); 1408c2ecf20Sopenharmony_ci return ret; 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci disable_irq(dtg->ctxld_kick_irq); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci dtg->ctxld_kick_irq_en = false; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci return 0; 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ciint dcss_dtg_init(struct dcss_dev *dcss, unsigned long dtg_base) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci int ret = 0; 1538c2ecf20Sopenharmony_ci struct dcss_dtg *dtg; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci dtg = kzalloc(sizeof(*dtg), GFP_KERNEL); 1568c2ecf20Sopenharmony_ci if (!dtg) 1578c2ecf20Sopenharmony_ci return -ENOMEM; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci dcss->dtg = dtg; 1608c2ecf20Sopenharmony_ci dtg->dev = dcss->dev; 1618c2ecf20Sopenharmony_ci dtg->ctxld = dcss->ctxld; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci dtg->base_reg = ioremap(dtg_base, SZ_4K); 1648c2ecf20Sopenharmony_ci if (!dtg->base_reg) { 1658c2ecf20Sopenharmony_ci dev_err(dcss->dev, "dtg: unable to remap dtg base\n"); 1668c2ecf20Sopenharmony_ci ret = -ENOMEM; 1678c2ecf20Sopenharmony_ci goto err_ioremap; 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci dtg->base_ofs = dtg_base; 1718c2ecf20Sopenharmony_ci dtg->ctx_id = CTX_DB; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci dtg->alpha = 255; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci dtg->control_status |= OVL_DATA_MODE | BLENDER_VIDEO_ALPHA_SEL | 1768c2ecf20Sopenharmony_ci ((dtg->alpha << DEFAULT_FG_ALPHA_POS) & DEFAULT_FG_ALPHA_MASK); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci ret = dcss_dtg_irq_config(dtg, to_platform_device(dcss->dev)); 1798c2ecf20Sopenharmony_ci if (ret) 1808c2ecf20Sopenharmony_ci goto err_irq; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci return 0; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cierr_irq: 1858c2ecf20Sopenharmony_ci iounmap(dtg->base_reg); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cierr_ioremap: 1888c2ecf20Sopenharmony_ci kfree(dtg); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci return ret; 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_civoid dcss_dtg_exit(struct dcss_dtg *dtg) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci free_irq(dtg->ctxld_kick_irq, dtg); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (dtg->base_reg) 1988c2ecf20Sopenharmony_ci iounmap(dtg->base_reg); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci kfree(dtg); 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_civoid dcss_dtg_sync_set(struct dcss_dtg *dtg, struct videomode *vm) 2048c2ecf20Sopenharmony_ci{ 2058c2ecf20Sopenharmony_ci struct dcss_dev *dcss = dcss_drv_dev_to_dcss(dtg->dev); 2068c2ecf20Sopenharmony_ci u16 dtg_lrc_x, dtg_lrc_y; 2078c2ecf20Sopenharmony_ci u16 dis_ulc_x, dis_ulc_y; 2088c2ecf20Sopenharmony_ci u16 dis_lrc_x, dis_lrc_y; 2098c2ecf20Sopenharmony_ci u32 sb_ctxld_trig, db_ctxld_trig; 2108c2ecf20Sopenharmony_ci u32 pixclock = vm->pixelclock; 2118c2ecf20Sopenharmony_ci u32 actual_clk; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci dtg_lrc_x = vm->hfront_porch + vm->hback_porch + vm->hsync_len + 2148c2ecf20Sopenharmony_ci vm->hactive - 1; 2158c2ecf20Sopenharmony_ci dtg_lrc_y = vm->vfront_porch + vm->vback_porch + vm->vsync_len + 2168c2ecf20Sopenharmony_ci vm->vactive - 1; 2178c2ecf20Sopenharmony_ci dis_ulc_x = vm->hsync_len + vm->hback_porch - 1; 2188c2ecf20Sopenharmony_ci dis_ulc_y = vm->vsync_len + vm->vfront_porch + vm->vback_porch - 1; 2198c2ecf20Sopenharmony_ci dis_lrc_x = vm->hsync_len + vm->hback_porch + vm->hactive - 1; 2208c2ecf20Sopenharmony_ci dis_lrc_y = vm->vsync_len + vm->vfront_porch + vm->vback_porch + 2218c2ecf20Sopenharmony_ci vm->vactive - 1; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci clk_disable_unprepare(dcss->pix_clk); 2248c2ecf20Sopenharmony_ci clk_set_rate(dcss->pix_clk, vm->pixelclock); 2258c2ecf20Sopenharmony_ci clk_prepare_enable(dcss->pix_clk); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci actual_clk = clk_get_rate(dcss->pix_clk); 2288c2ecf20Sopenharmony_ci if (pixclock != actual_clk) { 2298c2ecf20Sopenharmony_ci dev_info(dtg->dev, 2308c2ecf20Sopenharmony_ci "Pixel clock set to %u kHz instead of %u kHz.\n", 2318c2ecf20Sopenharmony_ci (actual_clk / 1000), (pixclock / 1000)); 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, ((dtg_lrc_y << TC_Y_POS) | dtg_lrc_x), 2358c2ecf20Sopenharmony_ci DCSS_DTG_TC_DTG); 2368c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, ((dis_ulc_y << TC_Y_POS) | dis_ulc_x), 2378c2ecf20Sopenharmony_ci DCSS_DTG_TC_DISP_TOP); 2388c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, ((dis_lrc_y << TC_Y_POS) | dis_lrc_x), 2398c2ecf20Sopenharmony_ci DCSS_DTG_TC_DISP_BOT); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci dtg->dis_ulc_x = dis_ulc_x; 2428c2ecf20Sopenharmony_ci dtg->dis_ulc_y = dis_ulc_y; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci sb_ctxld_trig = ((0 * dis_lrc_y / 100) << TC_CTXLD_SB_Y_POS) & 2458c2ecf20Sopenharmony_ci TC_CTXLD_SB_Y_MASK; 2468c2ecf20Sopenharmony_ci db_ctxld_trig = ((99 * dis_lrc_y / 100) << TC_CTXLD_DB_Y_POS) & 2478c2ecf20Sopenharmony_ci TC_CTXLD_DB_Y_MASK; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, sb_ctxld_trig | db_ctxld_trig, DCSS_DTG_TC_CTXLD); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci /* vblank trigger */ 2528c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, 0, DCSS_DTG_LINE1_INT); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci /* CTXLD trigger */ 2558c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, ((90 * dis_lrc_y) / 100) << 16, DCSS_DTG_LINE0_INT); 2568c2ecf20Sopenharmony_ci} 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_civoid dcss_dtg_plane_pos_set(struct dcss_dtg *dtg, int ch_num, 2598c2ecf20Sopenharmony_ci int px, int py, int pw, int ph) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci u16 p_ulc_x, p_ulc_y; 2628c2ecf20Sopenharmony_ci u16 p_lrc_x, p_lrc_y; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci p_ulc_x = dtg->dis_ulc_x + px; 2658c2ecf20Sopenharmony_ci p_ulc_y = dtg->dis_ulc_y + py; 2668c2ecf20Sopenharmony_ci p_lrc_x = p_ulc_x + pw; 2678c2ecf20Sopenharmony_ci p_lrc_y = p_ulc_y + ph; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci if (!px && !py && !pw && !ph) { 2708c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, 0, DCSS_DTG_TC_CH1_TOP + 0x8 * ch_num); 2718c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, 0, DCSS_DTG_TC_CH1_BOT + 0x8 * ch_num); 2728c2ecf20Sopenharmony_ci } else { 2738c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, ((p_ulc_y << TC_Y_POS) | p_ulc_x), 2748c2ecf20Sopenharmony_ci DCSS_DTG_TC_CH1_TOP + 0x8 * ch_num); 2758c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, ((p_lrc_y << TC_Y_POS) | p_lrc_x), 2768c2ecf20Sopenharmony_ci DCSS_DTG_TC_CH1_BOT + 0x8 * ch_num); 2778c2ecf20Sopenharmony_ci } 2788c2ecf20Sopenharmony_ci} 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_cibool dcss_dtg_global_alpha_changed(struct dcss_dtg *dtg, int ch_num, int alpha) 2818c2ecf20Sopenharmony_ci{ 2828c2ecf20Sopenharmony_ci if (ch_num) 2838c2ecf20Sopenharmony_ci return false; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci return alpha != dtg->alpha; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_civoid dcss_dtg_plane_alpha_set(struct dcss_dtg *dtg, int ch_num, 2898c2ecf20Sopenharmony_ci const struct drm_format_info *format, int alpha) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci /* we care about alpha only when channel 0 is concerned */ 2928c2ecf20Sopenharmony_ci if (ch_num) 2938c2ecf20Sopenharmony_ci return; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci /* 2968c2ecf20Sopenharmony_ci * Use global alpha if pixel format does not have alpha channel or the 2978c2ecf20Sopenharmony_ci * user explicitly chose to use global alpha (i.e. alpha is not OPAQUE). 2988c2ecf20Sopenharmony_ci */ 2998c2ecf20Sopenharmony_ci if (!format->has_alpha || alpha != 255) 3008c2ecf20Sopenharmony_ci dtg->alpha_cfg = (alpha << DEFAULT_FG_ALPHA_POS) & DEFAULT_FG_ALPHA_MASK; 3018c2ecf20Sopenharmony_ci else /* use per-pixel alpha otherwise */ 3028c2ecf20Sopenharmony_ci dtg->alpha_cfg = CH1_ALPHA_SEL; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci dtg->alpha = alpha; 3058c2ecf20Sopenharmony_ci} 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_civoid dcss_dtg_css_set(struct dcss_dtg *dtg) 3088c2ecf20Sopenharmony_ci{ 3098c2ecf20Sopenharmony_ci dtg->control_status |= 3108c2ecf20Sopenharmony_ci (0x5 << CSS_PIX_COMP_SWAP_POS) & CSS_PIX_COMP_SWAP_MASK; 3118c2ecf20Sopenharmony_ci} 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_civoid dcss_dtg_enable(struct dcss_dtg *dtg) 3148c2ecf20Sopenharmony_ci{ 3158c2ecf20Sopenharmony_ci dtg->control_status |= DTG_START; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci dtg->control_status &= ~(CH1_ALPHA_SEL | DEFAULT_FG_ALPHA_MASK); 3188c2ecf20Sopenharmony_ci dtg->control_status |= dtg->alpha_cfg; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, dtg->control_status, DCSS_DTG_TC_CONTROL_STATUS); 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci dtg->in_use = true; 3238c2ecf20Sopenharmony_ci} 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_civoid dcss_dtg_shutoff(struct dcss_dtg *dtg) 3268c2ecf20Sopenharmony_ci{ 3278c2ecf20Sopenharmony_ci dtg->control_status &= ~DTG_START; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci dcss_writel(dtg->control_status, 3308c2ecf20Sopenharmony_ci dtg->base_reg + DCSS_DTG_TC_CONTROL_STATUS); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci dtg->in_use = false; 3338c2ecf20Sopenharmony_ci} 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_cibool dcss_dtg_is_enabled(struct dcss_dtg *dtg) 3368c2ecf20Sopenharmony_ci{ 3378c2ecf20Sopenharmony_ci return dtg->in_use; 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_civoid dcss_dtg_ch_enable(struct dcss_dtg *dtg, int ch_num, bool en) 3418c2ecf20Sopenharmony_ci{ 3428c2ecf20Sopenharmony_ci u32 ch_en_map[] = {CH1_EN, CH2_EN, CH3_EN}; 3438c2ecf20Sopenharmony_ci u32 control_status; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci control_status = dtg->control_status & ~ch_en_map[ch_num]; 3468c2ecf20Sopenharmony_ci control_status |= en ? ch_en_map[ch_num] : 0; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci control_status &= ~(CH1_ALPHA_SEL | DEFAULT_FG_ALPHA_MASK); 3498c2ecf20Sopenharmony_ci control_status |= dtg->alpha_cfg; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci if (dtg->control_status != control_status) 3528c2ecf20Sopenharmony_ci dcss_dtg_write(dtg, control_status, DCSS_DTG_TC_CONTROL_STATUS); 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci dtg->control_status = control_status; 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_civoid dcss_dtg_vblank_irq_enable(struct dcss_dtg *dtg, bool en) 3588c2ecf20Sopenharmony_ci{ 3598c2ecf20Sopenharmony_ci u32 status; 3608c2ecf20Sopenharmony_ci u32 mask = en ? LINE1_IRQ : 0; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci if (en) { 3638c2ecf20Sopenharmony_ci status = dcss_readl(dtg->base_reg + DCSS_DTG_INT_STATUS); 3648c2ecf20Sopenharmony_ci dcss_writel(status & LINE1_IRQ, 3658c2ecf20Sopenharmony_ci dtg->base_reg + DCSS_DTG_INT_CONTROL); 3668c2ecf20Sopenharmony_ci } 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci dcss_update(mask, LINE1_IRQ, dtg->base_reg + DCSS_DTG_INT_MASK); 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_civoid dcss_dtg_ctxld_kick_irq_enable(struct dcss_dtg *dtg, bool en) 3728c2ecf20Sopenharmony_ci{ 3738c2ecf20Sopenharmony_ci u32 status; 3748c2ecf20Sopenharmony_ci u32 mask = en ? LINE0_IRQ : 0; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci if (en) { 3778c2ecf20Sopenharmony_ci status = dcss_readl(dtg->base_reg + DCSS_DTG_INT_STATUS); 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci if (!dtg->ctxld_kick_irq_en) { 3808c2ecf20Sopenharmony_ci dcss_writel(status & LINE0_IRQ, 3818c2ecf20Sopenharmony_ci dtg->base_reg + DCSS_DTG_INT_CONTROL); 3828c2ecf20Sopenharmony_ci enable_irq(dtg->ctxld_kick_irq); 3838c2ecf20Sopenharmony_ci dtg->ctxld_kick_irq_en = true; 3848c2ecf20Sopenharmony_ci dcss_update(mask, LINE0_IRQ, 3858c2ecf20Sopenharmony_ci dtg->base_reg + DCSS_DTG_INT_MASK); 3868c2ecf20Sopenharmony_ci } 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci return; 3898c2ecf20Sopenharmony_ci } 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci if (!dtg->ctxld_kick_irq_en) 3928c2ecf20Sopenharmony_ci return; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci disable_irq_nosync(dtg->ctxld_kick_irq); 3958c2ecf20Sopenharmony_ci dtg->ctxld_kick_irq_en = false; 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci dcss_update(mask, LINE0_IRQ, dtg->base_reg + DCSS_DTG_INT_MASK); 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_civoid dcss_dtg_vblank_irq_clear(struct dcss_dtg *dtg) 4018c2ecf20Sopenharmony_ci{ 4028c2ecf20Sopenharmony_ci dcss_update(LINE1_IRQ, LINE1_IRQ, dtg->base_reg + DCSS_DTG_INT_CONTROL); 4038c2ecf20Sopenharmony_ci} 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_cibool dcss_dtg_vblank_irq_valid(struct dcss_dtg *dtg) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci return !!(dcss_readl(dtg->base_reg + DCSS_DTG_INT_STATUS) & LINE1_IRQ); 4088c2ecf20Sopenharmony_ci} 4098c2ecf20Sopenharmony_ci 410