162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * ImgTec IR Decoder found in PowerDown Controller. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 2010-2014 Imagination Technologies Ltd. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef _IMG_IR_H_ 962306a36Sopenharmony_ci#define _IMG_IR_H_ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/io.h> 1262306a36Sopenharmony_ci#include <linux/spinlock.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include "img-ir-raw.h" 1562306a36Sopenharmony_ci#include "img-ir-hw.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* registers */ 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* relative to the start of the IR block of registers */ 2062306a36Sopenharmony_ci#define IMG_IR_CONTROL 0x00 2162306a36Sopenharmony_ci#define IMG_IR_STATUS 0x04 2262306a36Sopenharmony_ci#define IMG_IR_DATA_LW 0x08 2362306a36Sopenharmony_ci#define IMG_IR_DATA_UP 0x0c 2462306a36Sopenharmony_ci#define IMG_IR_LEAD_SYMB_TIMING 0x10 2562306a36Sopenharmony_ci#define IMG_IR_S00_SYMB_TIMING 0x14 2662306a36Sopenharmony_ci#define IMG_IR_S01_SYMB_TIMING 0x18 2762306a36Sopenharmony_ci#define IMG_IR_S10_SYMB_TIMING 0x1c 2862306a36Sopenharmony_ci#define IMG_IR_S11_SYMB_TIMING 0x20 2962306a36Sopenharmony_ci#define IMG_IR_FREE_SYMB_TIMING 0x24 3062306a36Sopenharmony_ci#define IMG_IR_POW_MOD_PARAMS 0x28 3162306a36Sopenharmony_ci#define IMG_IR_POW_MOD_ENABLE 0x2c 3262306a36Sopenharmony_ci#define IMG_IR_IRQ_MSG_DATA_LW 0x30 3362306a36Sopenharmony_ci#define IMG_IR_IRQ_MSG_DATA_UP 0x34 3462306a36Sopenharmony_ci#define IMG_IR_IRQ_MSG_MASK_LW 0x38 3562306a36Sopenharmony_ci#define IMG_IR_IRQ_MSG_MASK_UP 0x3c 3662306a36Sopenharmony_ci#define IMG_IR_IRQ_ENABLE 0x40 3762306a36Sopenharmony_ci#define IMG_IR_IRQ_STATUS 0x44 3862306a36Sopenharmony_ci#define IMG_IR_IRQ_CLEAR 0x48 3962306a36Sopenharmony_ci#define IMG_IR_IRCORE_ID 0xf0 4062306a36Sopenharmony_ci#define IMG_IR_CORE_REV 0xf4 4162306a36Sopenharmony_ci#define IMG_IR_CORE_DES1 0xf8 4262306a36Sopenharmony_ci#define IMG_IR_CORE_DES2 0xfc 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/* field masks */ 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* IMG_IR_CONTROL */ 4862306a36Sopenharmony_ci#define IMG_IR_DECODEN 0x40000000 4962306a36Sopenharmony_ci#define IMG_IR_CODETYPE 0x30000000 5062306a36Sopenharmony_ci#define IMG_IR_CODETYPE_SHIFT 28 5162306a36Sopenharmony_ci#define IMG_IR_HDRTOG 0x08000000 5262306a36Sopenharmony_ci#define IMG_IR_LDRDEC 0x04000000 5362306a36Sopenharmony_ci#define IMG_IR_DECODINPOL 0x02000000 /* active high */ 5462306a36Sopenharmony_ci#define IMG_IR_BITORIEN 0x01000000 /* MSB first */ 5562306a36Sopenharmony_ci#define IMG_IR_D1VALIDSEL 0x00008000 5662306a36Sopenharmony_ci#define IMG_IR_BITINV 0x00000040 /* don't invert */ 5762306a36Sopenharmony_ci#define IMG_IR_DECODEND2 0x00000010 5862306a36Sopenharmony_ci#define IMG_IR_BITORIEND2 0x00000002 /* MSB first */ 5962306a36Sopenharmony_ci#define IMG_IR_BITINVD2 0x00000001 /* don't invert */ 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci/* IMG_IR_STATUS */ 6262306a36Sopenharmony_ci#define IMG_IR_RXDVALD2 0x00001000 6362306a36Sopenharmony_ci#define IMG_IR_IRRXD 0x00000400 6462306a36Sopenharmony_ci#define IMG_IR_TOGSTATE 0x00000200 6562306a36Sopenharmony_ci#define IMG_IR_RXDVAL 0x00000040 6662306a36Sopenharmony_ci#define IMG_IR_RXDLEN 0x0000003f 6762306a36Sopenharmony_ci#define IMG_IR_RXDLEN_SHIFT 0 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* IMG_IR_LEAD_SYMB_TIMING, IMG_IR_Sxx_SYMB_TIMING */ 7062306a36Sopenharmony_ci#define IMG_IR_PD_MAX 0xff000000 7162306a36Sopenharmony_ci#define IMG_IR_PD_MAX_SHIFT 24 7262306a36Sopenharmony_ci#define IMG_IR_PD_MIN 0x00ff0000 7362306a36Sopenharmony_ci#define IMG_IR_PD_MIN_SHIFT 16 7462306a36Sopenharmony_ci#define IMG_IR_W_MAX 0x0000ff00 7562306a36Sopenharmony_ci#define IMG_IR_W_MAX_SHIFT 8 7662306a36Sopenharmony_ci#define IMG_IR_W_MIN 0x000000ff 7762306a36Sopenharmony_ci#define IMG_IR_W_MIN_SHIFT 0 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/* IMG_IR_FREE_SYMB_TIMING */ 8062306a36Sopenharmony_ci#define IMG_IR_MAXLEN 0x0007e000 8162306a36Sopenharmony_ci#define IMG_IR_MAXLEN_SHIFT 13 8262306a36Sopenharmony_ci#define IMG_IR_MINLEN 0x00001f00 8362306a36Sopenharmony_ci#define IMG_IR_MINLEN_SHIFT 8 8462306a36Sopenharmony_ci#define IMG_IR_FT_MIN 0x000000ff 8562306a36Sopenharmony_ci#define IMG_IR_FT_MIN_SHIFT 0 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* IMG_IR_POW_MOD_PARAMS */ 8862306a36Sopenharmony_ci#define IMG_IR_PERIOD_LEN 0x3f000000 8962306a36Sopenharmony_ci#define IMG_IR_PERIOD_LEN_SHIFT 24 9062306a36Sopenharmony_ci#define IMG_IR_PERIOD_DUTY 0x003f0000 9162306a36Sopenharmony_ci#define IMG_IR_PERIOD_DUTY_SHIFT 16 9262306a36Sopenharmony_ci#define IMG_IR_STABLE_STOP 0x00003f00 9362306a36Sopenharmony_ci#define IMG_IR_STABLE_STOP_SHIFT 8 9462306a36Sopenharmony_ci#define IMG_IR_STABLE_START 0x0000003f 9562306a36Sopenharmony_ci#define IMG_IR_STABLE_START_SHIFT 0 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/* IMG_IR_POW_MOD_ENABLE */ 9862306a36Sopenharmony_ci#define IMG_IR_POWER_OUT_EN 0x00000002 9962306a36Sopenharmony_ci#define IMG_IR_POWER_MOD_EN 0x00000001 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci/* IMG_IR_IRQ_ENABLE, IMG_IR_IRQ_STATUS, IMG_IR_IRQ_CLEAR */ 10262306a36Sopenharmony_ci#define IMG_IR_IRQ_DEC2_ERR 0x00000080 10362306a36Sopenharmony_ci#define IMG_IR_IRQ_DEC_ERR 0x00000040 10462306a36Sopenharmony_ci#define IMG_IR_IRQ_ACT_LEVEL 0x00000020 10562306a36Sopenharmony_ci#define IMG_IR_IRQ_FALL_EDGE 0x00000010 10662306a36Sopenharmony_ci#define IMG_IR_IRQ_RISE_EDGE 0x00000008 10762306a36Sopenharmony_ci#define IMG_IR_IRQ_DATA_MATCH 0x00000004 10862306a36Sopenharmony_ci#define IMG_IR_IRQ_DATA2_VALID 0x00000002 10962306a36Sopenharmony_ci#define IMG_IR_IRQ_DATA_VALID 0x00000001 11062306a36Sopenharmony_ci#define IMG_IR_IRQ_ALL 0x000000ff 11162306a36Sopenharmony_ci#define IMG_IR_IRQ_EDGE (IMG_IR_IRQ_FALL_EDGE | IMG_IR_IRQ_RISE_EDGE) 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/* IMG_IR_CORE_ID */ 11462306a36Sopenharmony_ci#define IMG_IR_CORE_ID 0x00ff0000 11562306a36Sopenharmony_ci#define IMG_IR_CORE_ID_SHIFT 16 11662306a36Sopenharmony_ci#define IMG_IR_CORE_CONFIG 0x0000ffff 11762306a36Sopenharmony_ci#define IMG_IR_CORE_CONFIG_SHIFT 0 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* IMG_IR_CORE_REV */ 12062306a36Sopenharmony_ci#define IMG_IR_DESIGNER 0xff000000 12162306a36Sopenharmony_ci#define IMG_IR_DESIGNER_SHIFT 24 12262306a36Sopenharmony_ci#define IMG_IR_MAJOR_REV 0x00ff0000 12362306a36Sopenharmony_ci#define IMG_IR_MAJOR_REV_SHIFT 16 12462306a36Sopenharmony_ci#define IMG_IR_MINOR_REV 0x0000ff00 12562306a36Sopenharmony_ci#define IMG_IR_MINOR_REV_SHIFT 8 12662306a36Sopenharmony_ci#define IMG_IR_MAINT_REV 0x000000ff 12762306a36Sopenharmony_ci#define IMG_IR_MAINT_REV_SHIFT 0 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_cistruct device; 13062306a36Sopenharmony_cistruct clk; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/** 13362306a36Sopenharmony_ci * struct img_ir_priv - Private driver data. 13462306a36Sopenharmony_ci * @dev: Platform device. 13562306a36Sopenharmony_ci * @irq: IRQ number. 13662306a36Sopenharmony_ci * @clk: Input clock. 13762306a36Sopenharmony_ci * @sys_clk: System clock. 13862306a36Sopenharmony_ci * @reg_base: Iomem base address of IR register block. 13962306a36Sopenharmony_ci * @lock: Protects IR registers and variables in this struct. 14062306a36Sopenharmony_ci * @raw: Driver data for raw decoder. 14162306a36Sopenharmony_ci * @hw: Driver data for hardware decoder. 14262306a36Sopenharmony_ci */ 14362306a36Sopenharmony_cistruct img_ir_priv { 14462306a36Sopenharmony_ci struct device *dev; 14562306a36Sopenharmony_ci int irq; 14662306a36Sopenharmony_ci struct clk *clk; 14762306a36Sopenharmony_ci struct clk *sys_clk; 14862306a36Sopenharmony_ci void __iomem *reg_base; 14962306a36Sopenharmony_ci spinlock_t lock; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci struct img_ir_priv_raw raw; 15262306a36Sopenharmony_ci struct img_ir_priv_hw hw; 15362306a36Sopenharmony_ci}; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci/* Hardware access */ 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_cistatic inline void img_ir_write(struct img_ir_priv *priv, 15862306a36Sopenharmony_ci unsigned int reg_offs, unsigned int data) 15962306a36Sopenharmony_ci{ 16062306a36Sopenharmony_ci iowrite32(data, priv->reg_base + reg_offs); 16162306a36Sopenharmony_ci} 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistatic inline unsigned int img_ir_read(struct img_ir_priv *priv, 16462306a36Sopenharmony_ci unsigned int reg_offs) 16562306a36Sopenharmony_ci{ 16662306a36Sopenharmony_ci return ioread32(priv->reg_base + reg_offs); 16762306a36Sopenharmony_ci} 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci#endif /* _IMG_IR_H_ */ 170