18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ImgTec IR Decoder found in PowerDown Controller. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2010-2014 Imagination Technologies Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _IMG_IR_H_ 98c2ecf20Sopenharmony_ci#define _IMG_IR_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "img-ir-raw.h" 158c2ecf20Sopenharmony_ci#include "img-ir-hw.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* registers */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* relative to the start of the IR block of registers */ 208c2ecf20Sopenharmony_ci#define IMG_IR_CONTROL 0x00 218c2ecf20Sopenharmony_ci#define IMG_IR_STATUS 0x04 228c2ecf20Sopenharmony_ci#define IMG_IR_DATA_LW 0x08 238c2ecf20Sopenharmony_ci#define IMG_IR_DATA_UP 0x0c 248c2ecf20Sopenharmony_ci#define IMG_IR_LEAD_SYMB_TIMING 0x10 258c2ecf20Sopenharmony_ci#define IMG_IR_S00_SYMB_TIMING 0x14 268c2ecf20Sopenharmony_ci#define IMG_IR_S01_SYMB_TIMING 0x18 278c2ecf20Sopenharmony_ci#define IMG_IR_S10_SYMB_TIMING 0x1c 288c2ecf20Sopenharmony_ci#define IMG_IR_S11_SYMB_TIMING 0x20 298c2ecf20Sopenharmony_ci#define IMG_IR_FREE_SYMB_TIMING 0x24 308c2ecf20Sopenharmony_ci#define IMG_IR_POW_MOD_PARAMS 0x28 318c2ecf20Sopenharmony_ci#define IMG_IR_POW_MOD_ENABLE 0x2c 328c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_MSG_DATA_LW 0x30 338c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_MSG_DATA_UP 0x34 348c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_MSG_MASK_LW 0x38 358c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_MSG_MASK_UP 0x3c 368c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_ENABLE 0x40 378c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_STATUS 0x44 388c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_CLEAR 0x48 398c2ecf20Sopenharmony_ci#define IMG_IR_IRCORE_ID 0xf0 408c2ecf20Sopenharmony_ci#define IMG_IR_CORE_REV 0xf4 418c2ecf20Sopenharmony_ci#define IMG_IR_CORE_DES1 0xf8 428c2ecf20Sopenharmony_ci#define IMG_IR_CORE_DES2 0xfc 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* field masks */ 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* IMG_IR_CONTROL */ 488c2ecf20Sopenharmony_ci#define IMG_IR_DECODEN 0x40000000 498c2ecf20Sopenharmony_ci#define IMG_IR_CODETYPE 0x30000000 508c2ecf20Sopenharmony_ci#define IMG_IR_CODETYPE_SHIFT 28 518c2ecf20Sopenharmony_ci#define IMG_IR_HDRTOG 0x08000000 528c2ecf20Sopenharmony_ci#define IMG_IR_LDRDEC 0x04000000 538c2ecf20Sopenharmony_ci#define IMG_IR_DECODINPOL 0x02000000 /* active high */ 548c2ecf20Sopenharmony_ci#define IMG_IR_BITORIEN 0x01000000 /* MSB first */ 558c2ecf20Sopenharmony_ci#define IMG_IR_D1VALIDSEL 0x00008000 568c2ecf20Sopenharmony_ci#define IMG_IR_BITINV 0x00000040 /* don't invert */ 578c2ecf20Sopenharmony_ci#define IMG_IR_DECODEND2 0x00000010 588c2ecf20Sopenharmony_ci#define IMG_IR_BITORIEND2 0x00000002 /* MSB first */ 598c2ecf20Sopenharmony_ci#define IMG_IR_BITINVD2 0x00000001 /* don't invert */ 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* IMG_IR_STATUS */ 628c2ecf20Sopenharmony_ci#define IMG_IR_RXDVALD2 0x00001000 638c2ecf20Sopenharmony_ci#define IMG_IR_IRRXD 0x00000400 648c2ecf20Sopenharmony_ci#define IMG_IR_TOGSTATE 0x00000200 658c2ecf20Sopenharmony_ci#define IMG_IR_RXDVAL 0x00000040 668c2ecf20Sopenharmony_ci#define IMG_IR_RXDLEN 0x0000003f 678c2ecf20Sopenharmony_ci#define IMG_IR_RXDLEN_SHIFT 0 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* IMG_IR_LEAD_SYMB_TIMING, IMG_IR_Sxx_SYMB_TIMING */ 708c2ecf20Sopenharmony_ci#define IMG_IR_PD_MAX 0xff000000 718c2ecf20Sopenharmony_ci#define IMG_IR_PD_MAX_SHIFT 24 728c2ecf20Sopenharmony_ci#define IMG_IR_PD_MIN 0x00ff0000 738c2ecf20Sopenharmony_ci#define IMG_IR_PD_MIN_SHIFT 16 748c2ecf20Sopenharmony_ci#define IMG_IR_W_MAX 0x0000ff00 758c2ecf20Sopenharmony_ci#define IMG_IR_W_MAX_SHIFT 8 768c2ecf20Sopenharmony_ci#define IMG_IR_W_MIN 0x000000ff 778c2ecf20Sopenharmony_ci#define IMG_IR_W_MIN_SHIFT 0 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* IMG_IR_FREE_SYMB_TIMING */ 808c2ecf20Sopenharmony_ci#define IMG_IR_MAXLEN 0x0007e000 818c2ecf20Sopenharmony_ci#define IMG_IR_MAXLEN_SHIFT 13 828c2ecf20Sopenharmony_ci#define IMG_IR_MINLEN 0x00001f00 838c2ecf20Sopenharmony_ci#define IMG_IR_MINLEN_SHIFT 8 848c2ecf20Sopenharmony_ci#define IMG_IR_FT_MIN 0x000000ff 858c2ecf20Sopenharmony_ci#define IMG_IR_FT_MIN_SHIFT 0 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* IMG_IR_POW_MOD_PARAMS */ 888c2ecf20Sopenharmony_ci#define IMG_IR_PERIOD_LEN 0x3f000000 898c2ecf20Sopenharmony_ci#define IMG_IR_PERIOD_LEN_SHIFT 24 908c2ecf20Sopenharmony_ci#define IMG_IR_PERIOD_DUTY 0x003f0000 918c2ecf20Sopenharmony_ci#define IMG_IR_PERIOD_DUTY_SHIFT 16 928c2ecf20Sopenharmony_ci#define IMG_IR_STABLE_STOP 0x00003f00 938c2ecf20Sopenharmony_ci#define IMG_IR_STABLE_STOP_SHIFT 8 948c2ecf20Sopenharmony_ci#define IMG_IR_STABLE_START 0x0000003f 958c2ecf20Sopenharmony_ci#define IMG_IR_STABLE_START_SHIFT 0 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* IMG_IR_POW_MOD_ENABLE */ 988c2ecf20Sopenharmony_ci#define IMG_IR_POWER_OUT_EN 0x00000002 998c2ecf20Sopenharmony_ci#define IMG_IR_POWER_MOD_EN 0x00000001 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* IMG_IR_IRQ_ENABLE, IMG_IR_IRQ_STATUS, IMG_IR_IRQ_CLEAR */ 1028c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_DEC2_ERR 0x00000080 1038c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_DEC_ERR 0x00000040 1048c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_ACT_LEVEL 0x00000020 1058c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_FALL_EDGE 0x00000010 1068c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_RISE_EDGE 0x00000008 1078c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_DATA_MATCH 0x00000004 1088c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_DATA2_VALID 0x00000002 1098c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_DATA_VALID 0x00000001 1108c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_ALL 0x000000ff 1118c2ecf20Sopenharmony_ci#define IMG_IR_IRQ_EDGE (IMG_IR_IRQ_FALL_EDGE | IMG_IR_IRQ_RISE_EDGE) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* IMG_IR_CORE_ID */ 1148c2ecf20Sopenharmony_ci#define IMG_IR_CORE_ID 0x00ff0000 1158c2ecf20Sopenharmony_ci#define IMG_IR_CORE_ID_SHIFT 16 1168c2ecf20Sopenharmony_ci#define IMG_IR_CORE_CONFIG 0x0000ffff 1178c2ecf20Sopenharmony_ci#define IMG_IR_CORE_CONFIG_SHIFT 0 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/* IMG_IR_CORE_REV */ 1208c2ecf20Sopenharmony_ci#define IMG_IR_DESIGNER 0xff000000 1218c2ecf20Sopenharmony_ci#define IMG_IR_DESIGNER_SHIFT 24 1228c2ecf20Sopenharmony_ci#define IMG_IR_MAJOR_REV 0x00ff0000 1238c2ecf20Sopenharmony_ci#define IMG_IR_MAJOR_REV_SHIFT 16 1248c2ecf20Sopenharmony_ci#define IMG_IR_MINOR_REV 0x0000ff00 1258c2ecf20Sopenharmony_ci#define IMG_IR_MINOR_REV_SHIFT 8 1268c2ecf20Sopenharmony_ci#define IMG_IR_MAINT_REV 0x000000ff 1278c2ecf20Sopenharmony_ci#define IMG_IR_MAINT_REV_SHIFT 0 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistruct device; 1308c2ecf20Sopenharmony_cistruct clk; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/** 1338c2ecf20Sopenharmony_ci * struct img_ir_priv - Private driver data. 1348c2ecf20Sopenharmony_ci * @dev: Platform device. 1358c2ecf20Sopenharmony_ci * @irq: IRQ number. 1368c2ecf20Sopenharmony_ci * @clk: Input clock. 1378c2ecf20Sopenharmony_ci * @sys_clk: System clock. 1388c2ecf20Sopenharmony_ci * @reg_base: Iomem base address of IR register block. 1398c2ecf20Sopenharmony_ci * @lock: Protects IR registers and variables in this struct. 1408c2ecf20Sopenharmony_ci * @raw: Driver data for raw decoder. 1418c2ecf20Sopenharmony_ci * @hw: Driver data for hardware decoder. 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_cistruct img_ir_priv { 1448c2ecf20Sopenharmony_ci struct device *dev; 1458c2ecf20Sopenharmony_ci int irq; 1468c2ecf20Sopenharmony_ci struct clk *clk; 1478c2ecf20Sopenharmony_ci struct clk *sys_clk; 1488c2ecf20Sopenharmony_ci void __iomem *reg_base; 1498c2ecf20Sopenharmony_ci spinlock_t lock; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci struct img_ir_priv_raw raw; 1528c2ecf20Sopenharmony_ci struct img_ir_priv_hw hw; 1538c2ecf20Sopenharmony_ci}; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/* Hardware access */ 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistatic inline void img_ir_write(struct img_ir_priv *priv, 1588c2ecf20Sopenharmony_ci unsigned int reg_offs, unsigned int data) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci iowrite32(data, priv->reg_base + reg_offs); 1618c2ecf20Sopenharmony_ci} 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic inline unsigned int img_ir_read(struct img_ir_priv *priv, 1648c2ecf20Sopenharmony_ci unsigned int reg_offs) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci return ioread32(priv->reg_base + reg_offs); 1678c2ecf20Sopenharmony_ci} 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci#endif /* _IMG_IR_H_ */ 170