hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
 *
 * SPDX-License-Identifier:     GPL-2.0+
 */
#ifndef __ROCKCHIP_IR_H__
#define __ROCKCHIP_IR_H__
 
#include <linux/bitops.h>
 
/* Registers */
/* High polarity cycles */
#define PWM_HPR_REG    0x04
 
/* Low polarity cycles */
#define PWM_LPR_REG    0x08
 
/* PWM Control */
#define PWM_CTL_REG    0x0c
/* Enable */
#define REG_CTL_EN    BIT(0)
/* capture mode */
#define REG_CTL_MD    BIT(2)
 
/* Interrupt Status */
#define PWM_STA_REG(id)    ((4 - (id)) * 0x10)
#define PWM_CH_POL(id)    BIT(id + 8)
 
/* Interrupt Enable */
#define PWM_INT_REG(id)    ((4 - (id)) * 0x14)
#define PWM_CH_INT(id)    BIT(id)
 
/* NEC IR Pulse/Space protocol */
#define NEC_NBITS        32
#define NEC_UNIT        562500    /* ns */
#define NEC_HEADER_PULSE    (16 * NEC_UNIT)
#define NEC_HEADER_SPACE    (8  * NEC_UNIT)
#define NEC_BIT_PULSE        (1  * NEC_UNIT)
#define NEC_BIT_0_SPACE        (1  * NEC_UNIT)
#define NEC_BIT_1_SPACE        (3  * NEC_UNIT)
 
#define TO_US(duration)        ((duration) / 1000)
#define TO_STR(is_pulse)    ((is_pulse) ? "pulse" : "space")
 
#define MAX_NUM_KEYS    60
 
enum nec_state {
   STATE_INACTIVE,
   STATE_HEADER_SPACE,
   STATE_BIT_PULSE,
   STATE_BIT_SPACE,
};
 
struct rockchip_ir_priv {
   fdt_addr_t base;
   ulong freq;
   ulong period;
   int id;
   int num;
   int keycode;
   int repeat;
};
 
struct ir_raw_event {
   u32 duration;
   unsigned pulse:1;
};
 
struct nec_dec {
   int state;
   unsigned count;
   u32 bits;
};
 
struct rc_map_table {
   u32 scancode;
   u32 keycode;
};
 
struct rc_map {
   u32 usercode;
   u32 nbuttons;
   struct rc_map_table scan[MAX_NUM_KEYS];
};
 
/* macros for IR decoders */
static inline bool eq_margin(unsigned d1, unsigned d2, unsigned margin)
{
   return ((d1 > (d2 - margin)) && (d1 < (d2 + margin)));
}
 
#endif /* __ROCKCHIP_IR_H__ */