Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: rc: meson-ir: support rc driver type RC_DRIVER_SCANCODE

Meson IR Controller supports hardware decoder in Meson-S4 and later
SoC. So far, protocol NEC could be decoded by hardware decoder.

Signed-off-by: Zelong Dong <zelong.dong@amlogic.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Zelong Dong and committed by
Hans Verkuil
e798f5b2 5ce19a50

+470 -90
+470 -90
drivers/media/rc/meson-ir.c
··· 20 20 21 21 #define DRIVER_NAME "meson-ir" 22 22 23 - #define IR_DEC_LDR_ACTIVE 0x00 24 - #define IR_DEC_LDR_IDLE 0x04 25 - #define IR_DEC_LDR_REPEAT 0x08 26 - #define IR_DEC_BIT_0 0x0c 27 - #define IR_DEC_REG0 0x10 28 - #define IR_DEC_REG0_BASE_TIME GENMASK(11, 0) 29 - #define IR_DEC_FRAME 0x14 30 - #define IR_DEC_STATUS 0x18 31 - #define IR_DEC_STATUS_PULSE BIT(8) 32 - #define IR_DEC_REG1 0x1c 33 - #define IR_DEC_REG1_TIME_IV GENMASK(28, 16) 34 - #define IR_DEC_REG1_ENABLE BIT(15) 35 - #define IR_DEC_REG1_MODE GENMASK(8, 7) 36 - #define IR_DEC_REG1_IRQSEL GENMASK(3, 2) 37 - #define IR_DEC_REG1_RESET BIT(0) 38 - /* The following regs are only available on Meson 8b and newer */ 39 - #define IR_DEC_REG2 0x20 40 - #define IR_DEC_REG2_MODE GENMASK(3, 0) 23 + #define IR_DEC_LDR_ACTIVE 0x00 24 + #define IR_DEC_LDR_ACTIVE_MAX GENMASK(28, 16) 25 + #define IR_DEC_LDR_ACTIVE_MIN GENMASK(12, 0) 26 + #define IR_DEC_LDR_IDLE 0x04 27 + #define IR_DEC_LDR_IDLE_MAX GENMASK(28, 16) 28 + #define IR_DEC_LDR_IDLE_MIN GENMASK(12, 0) 29 + #define IR_DEC_LDR_REPEAT 0x08 30 + #define IR_DEC_LDR_REPEAT_MAX GENMASK(25, 16) 31 + #define IR_DEC_LDR_REPEAT_MIN GENMASK(9, 0) 32 + #define IR_DEC_BIT_0 0x0c 33 + #define IR_DEC_BIT_0_MAX GENMASK(25, 16) 34 + #define IR_DEC_BIT_0_MIN GENMASK(9, 0) 35 + #define IR_DEC_REG0 0x10 36 + #define IR_DEC_REG0_FILTER GENMASK(30, 28) 37 + #define IR_DEC_REG0_FRAME_TIME_MAX GENMASK(24, 12) 38 + #define IR_DEC_REG0_BASE_TIME GENMASK(11, 0) 39 + #define IR_DEC_FRAME 0x14 40 + #define IR_DEC_STATUS 0x18 41 + #define IR_DEC_STATUS_BIT_1_ENABLE BIT(30) 42 + #define IR_DEC_STATUS_BIT_1_MAX GENMASK(29, 20) 43 + #define IR_DEC_STATUS_BIT_1_MIN GENMASK(19, 10) 44 + #define IR_DEC_STATUS_PULSE BIT(8) 45 + #define IR_DEC_STATUS_BUSY BIT(7) 46 + #define IR_DEC_STATUS_FRAME_STATUS GENMASK(3, 0) 47 + #define IR_DEC_REG1 0x1c 48 + #define IR_DEC_REG1_TIME_IV GENMASK(28, 16) 49 + #define IR_DEC_REG1_FRAME_LEN GENMASK(13, 8) 50 + #define IR_DEC_REG1_ENABLE BIT(15) 51 + #define IR_DEC_REG1_HOLD_CODE BIT(6) 52 + #define IR_DEC_REG1_IRQSEL GENMASK(3, 2) 53 + #define IR_DEC_REG1_RESET BIT(0) 54 + /* Meson 6b uses REG1 to configure IR mode */ 55 + #define IR_DEC_REG1_MODE GENMASK(8, 7) 41 56 42 - #define DEC_MODE_NEC 0x0 43 - #define DEC_MODE_RAW 0x2 57 + /* The following registers are only available on Meson 8b and newer */ 58 + #define IR_DEC_REG2 0x20 59 + #define IR_DEC_REG2_TICK_MODE BIT(15) 60 + #define IR_DEC_REG2_REPEAT_COUNTER BIT(13) 61 + #define IR_DEC_REG2_REPEAT_TIME BIT(12) 62 + #define IR_DEC_REG2_COMPARE_FRAME BIT(11) 63 + #define IR_DEC_REG2_BIT_ORDER BIT(8) 64 + /* Meson 8b / GXBB use REG2 to configure IR mode */ 65 + #define IR_DEC_REG2_MODE GENMASK(3, 0) 66 + #define IR_DEC_DURATN2 0x24 67 + #define IR_DEC_DURATN2_MAX GENMASK(25, 16) 68 + #define IR_DEC_DURATN2_MIN GENMASK(9, 0) 69 + #define IR_DEC_DURATN3 0x28 70 + #define IR_DEC_DURATN3_MAX GENMASK(25, 16) 71 + #define IR_DEC_DURATN3_MIN GENMASK(9, 0) 72 + #define IR_DEC_FRAME1 0x2c 44 73 45 - #define IRQSEL_NEC_MODE 0 46 - #define IRQSEL_RISE_FALL 1 47 - #define IRQSEL_FALL 2 48 - #define IRQSEL_RISE 3 74 + #define FRAME_MSB_FIRST true 75 + #define FRAME_LSB_FIRST false 49 76 50 - #define MESON_RAW_TRATE 10 /* us */ 51 - #define MESON_HW_TRATE 20 /* us */ 77 + #define DEC_MODE_NEC 0x0 78 + #define DEC_MODE_RAW 0x2 79 + #define DEC_MODE_RC6 0x9 80 + #define DEC_MODE_XMP 0xE 81 + #define DEC_MODE_UNKNOW 0xFF 82 + 83 + #define DEC_STATUS_VALID BIT(3) 84 + #define DEC_STATUS_DATA_CODE_ERR BIT(2) 85 + #define DEC_STATUS_CUSTOM_CODE_ERR BIT(1) 86 + #define DEC_STATUS_REPEAT BIT(0) 87 + 88 + #define IRQSEL_DEC_MODE 0 89 + #define IRQSEL_RISE_FALL 1 90 + #define IRQSEL_FALL 2 91 + #define IRQSEL_RISE 3 92 + 93 + #define MESON_RAW_TRATE 10 /* us */ 94 + #define MESON_HW_TRATE 20 /* us */ 95 + 96 + /** 97 + * struct meson_ir_protocol - describe IR Protocol parameter 98 + * 99 + * @hw_protocol: select IR Protocol from IR Controller 100 + * @repeat_counter_enable: enable frame-to-frame time counter, it should work 101 + * with @repeat_compare_enable to detect the repeat frame 102 + * @repeat_check_enable: enable repeat time check for repeat detection 103 + * @repeat_compare_enable: enable to compare frame for repeat frame detection. 104 + * Some IR Protocol send the same data as repeat frame. 105 + * In this case, it should work with 106 + * @repeat_counter_enable to detect the repeat frame. 107 + * @bit_order: bit order, LSB or MSB 108 + * @bit1_match_enable: enable to check bit 1 109 + * @hold_code_enable: hold frame code in register IR_DEC_FRAME1, the new one 110 + * frame code will not be store in IR_DEC_FRAME1. 111 + * until IR_DEC_FRAME1 has been read 112 + * @count_tick_mode: increasing time unit of frame-to-frame time counter. 113 + * 0 = 100us, 1 = 10us 114 + * @code_length: length (N-1) of data frame 115 + * @frame_time_max: max time for whole frame. Unit: MESON_HW_TRATE 116 + * @leader_active_max: max time for NEC/RC6 leader active part. Unit: MESON_HW_TRATE 117 + * @leader_active_min: min time for NEC/RC6 leader active part. Unit: MESON_HW_TRATE 118 + * @leader_idle_max: max time for NEC/RC6 leader idle part. Unit: MESON_HW_TRATE 119 + * @leader_idle_min: min time for NEC/RC6 leader idle part. Unit: MESON_HW_TRATE 120 + * @repeat_leader_max: max time for NEC repeat leader idle part. Unit: MESON_HW_TRATE 121 + * @repeat_leader_min: min time for NEC repeat leader idle part. Unit: MESON_HW_TRATE 122 + * @bit0_max: max time for NEC Logic '0', half of RC6 trailer bit, XMP Logic '00' 123 + * @bit0_min: min time for NEC Logic '0', half of RC6 trailer bit, XMP Logic '00' 124 + * @bit1_max: max time for NEC Logic '1', whole of RC6 trailer bit, XMP Logic '01' 125 + * @bit1_min: min time for NEC Logic '1', whole of RC6 trailer bit, XMP Logic '01' 126 + * @duration2_max: max time for half of RC6 normal bit, XMP Logic '10' 127 + * @duration2_min: min time for half of RC6 normal bit, XMP Logic '10' 128 + * @duration3_max: max time for whole of RC6 normal bit, XMP Logic '11' 129 + * @duration3_min: min time for whole of RC6 normal bit, XMP Logic '11' 130 + */ 131 + 132 + struct meson_ir_protocol { 133 + u8 hw_protocol; 134 + bool repeat_counter_enable; 135 + bool repeat_check_enable; 136 + bool repeat_compare_enable; 137 + bool bit_order; 138 + bool bit1_match_enable; 139 + bool hold_code_enable; 140 + bool count_tick_mode; 141 + u8 code_length; 142 + u16 frame_time_max; 143 + u16 leader_active_max; 144 + u16 leader_active_min; 145 + u16 leader_idle_max; 146 + u16 leader_idle_min; 147 + u16 repeat_leader_max; 148 + u16 repeat_leader_min; 149 + u16 bit0_max; 150 + u16 bit0_min; 151 + u16 bit1_max; 152 + u16 bit1_min; 153 + u16 duration2_max; 154 + u16 duration2_min; 155 + u16 duration3_max; 156 + u16 duration3_min; 157 + }; 158 + 159 + struct meson_ir_param { 160 + bool support_hw_decoder; 161 + unsigned int max_register; 162 + }; 52 163 53 164 struct meson_ir { 165 + const struct meson_ir_param *param; 54 166 struct regmap *reg; 55 167 struct rc_dev *rc; 56 168 spinlock_t lock; 57 169 }; 58 170 59 - static const struct regmap_config meson_ir_regmap_config = { 171 + static struct regmap_config meson_ir_regmap_config = { 60 172 .reg_bits = 32, 61 173 .val_bits = 32, 62 174 .reg_stride = 4, 63 175 }; 176 + 177 + static const struct meson_ir_protocol protocol_timings[] = { 178 + /* protocol, repeat counter, repeat check, repeat compare, order */ 179 + {DEC_MODE_NEC, false, false, false, FRAME_LSB_FIRST, 180 + /* bit 1 match, hold code, count tick, len, frame time */ 181 + true, false, false, 32, 4000, 182 + /* leader active max/min, leader idle max/min, repeat leader max/min */ 183 + 500, 400, 300, 200, 150, 80, 184 + /* bit0 max/min, bit1 max/min, duration2 max/min, duration3 max/min */ 185 + 72, 40, 134, 90, 0, 0, 0, 0} 186 + }; 187 + 188 + static void meson_ir_nec_handler(struct meson_ir *ir) 189 + { 190 + u32 code = 0; 191 + u32 status = 0; 192 + enum rc_proto proto; 193 + 194 + regmap_read(ir->reg, IR_DEC_STATUS, &status); 195 + 196 + if (status & DEC_STATUS_REPEAT) { 197 + rc_repeat(ir->rc); 198 + } else { 199 + regmap_read(ir->reg, IR_DEC_FRAME, &code); 200 + 201 + code = ir_nec_bytes_to_scancode(code, code >> 8, 202 + code >> 16, code >> 24, &proto); 203 + rc_keydown(ir->rc, proto, code, 0); 204 + } 205 + } 206 + 207 + static void meson_ir_hw_handler(struct meson_ir *ir) 208 + { 209 + if (ir->rc->enabled_protocols & RC_PROTO_BIT_NEC) 210 + meson_ir_nec_handler(ir); 211 + } 64 212 65 213 static irqreturn_t meson_ir_irq(int irqno, void *dev_id) 66 214 { ··· 218 70 219 71 spin_lock(&ir->lock); 220 72 221 - regmap_read(ir->reg, IR_DEC_REG1, &duration); 222 - duration = FIELD_GET(IR_DEC_REG1_TIME_IV, duration); 223 - rawir.duration = duration * MESON_RAW_TRATE; 224 - 225 73 regmap_read(ir->reg, IR_DEC_STATUS, &status); 226 - rawir.pulse = !!(status & IR_DEC_STATUS_PULSE); 227 74 228 - ir_raw_event_store_with_timeout(ir->rc, &rawir); 75 + if (ir->rc->driver_type == RC_DRIVER_IR_RAW) { 76 + rawir.pulse = !!(status & IR_DEC_STATUS_PULSE); 77 + 78 + regmap_read(ir->reg, IR_DEC_REG1, &duration); 79 + duration = FIELD_GET(IR_DEC_REG1_TIME_IV, duration); 80 + rawir.duration = duration * MESON_RAW_TRATE; 81 + 82 + ir_raw_event_store_with_timeout(ir->rc, &rawir); 83 + } else if (ir->rc->driver_type == RC_DRIVER_SCANCODE) { 84 + if (status & DEC_STATUS_VALID) 85 + meson_ir_hw_handler(ir); 86 + } 229 87 230 88 spin_unlock(&ir->lock); 231 89 232 90 return IRQ_HANDLED; 233 91 } 234 92 235 - static int meson_ir_probe(struct platform_device *pdev) 93 + static int meson_ir_hw_decoder_init(struct rc_dev *dev, u64 *rc_type) 236 94 { 237 - struct device *dev = &pdev->dev; 238 - struct device_node *node = dev->of_node; 239 - void __iomem *res_start; 240 - const char *map_name; 241 - struct meson_ir *ir; 242 - int irq, ret; 95 + u8 protocol; 96 + u32 regval; 97 + int i; 98 + unsigned long flags; 99 + const struct meson_ir_protocol *timings; 100 + struct meson_ir *ir = dev->priv; 243 101 244 - ir = devm_kzalloc(dev, sizeof(struct meson_ir), GFP_KERNEL); 245 - if (!ir) 246 - return -ENOMEM; 102 + if (*rc_type & RC_PROTO_BIT_NEC) 103 + protocol = DEC_MODE_NEC; 104 + else 105 + return 0; 247 106 248 - res_start = devm_platform_ioremap_resource(pdev, 0); 249 - if (IS_ERR(res_start)) 250 - return PTR_ERR(res_start); 107 + for (i = 0; i < ARRAY_SIZE(protocol_timings); i++) 108 + if (protocol_timings[i].hw_protocol == protocol) 109 + break; 251 110 252 - ir->reg = devm_regmap_init_mmio(&pdev->dev, res_start, 253 - &meson_ir_regmap_config); 254 - if (IS_ERR(ir->reg)) 255 - return PTR_ERR(ir->reg); 256 - 257 - irq = platform_get_irq(pdev, 0); 258 - if (irq < 0) 259 - return irq; 260 - 261 - ir->rc = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW); 262 - if (!ir->rc) { 263 - dev_err(dev, "failed to allocate rc device\n"); 264 - return -ENOMEM; 111 + if (i == ARRAY_SIZE(protocol_timings)) { 112 + dev_err(&dev->dev, "hw protocol isn't supported: %d\n", 113 + protocol); 114 + return -EINVAL; 265 115 } 116 + timings = &protocol_timings[i]; 266 117 267 - ir->rc->priv = ir; 268 - ir->rc->device_name = DRIVER_NAME; 269 - ir->rc->input_phys = DRIVER_NAME "/input0"; 270 - ir->rc->input_id.bustype = BUS_HOST; 271 - map_name = of_get_property(node, "linux,rc-map-name", NULL); 272 - ir->rc->map_name = map_name ? map_name : RC_MAP_EMPTY; 273 - ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; 274 - ir->rc->rx_resolution = MESON_RAW_TRATE; 275 - ir->rc->min_timeout = 1; 276 - ir->rc->timeout = IR_DEFAULT_TIMEOUT; 277 - ir->rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT; 278 - ir->rc->driver_name = DRIVER_NAME; 118 + spin_lock_irqsave(&ir->lock, flags); 279 119 280 - spin_lock_init(&ir->lock); 281 - platform_set_drvdata(pdev, ir); 120 + /* Clear controller status */ 121 + regmap_read(ir->reg, IR_DEC_STATUS, &regval); 122 + regmap_read(ir->reg, IR_DEC_FRAME, &regval); 282 123 283 - ret = devm_rc_register_device(dev, ir->rc); 284 - if (ret) { 285 - dev_err(dev, "failed to register rc device\n"); 286 - return ret; 287 - } 124 + /* Reset ir decoder and disable decoder */ 125 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, 0); 126 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, 127 + IR_DEC_REG1_RESET); 288 128 289 - ret = devm_request_irq(dev, irq, meson_ir_irq, 0, NULL, ir); 290 - if (ret) { 291 - dev_err(dev, "failed to request irq\n"); 292 - return ret; 293 - } 129 + /* Base time resolution, (19+1)*1us=20us */ 130 + regval = FIELD_PREP(IR_DEC_REG0_BASE_TIME, MESON_HW_TRATE - 1); 131 + regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_BASE_TIME, regval); 132 + 133 + /* Monitor timing for input filter */ 134 + regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_FILTER, 135 + FIELD_PREP(IR_DEC_REG0_FILTER, 7)); 136 + 137 + /* HW protocol */ 138 + regval = FIELD_PREP(IR_DEC_REG2_MODE, timings->hw_protocol); 139 + regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_MODE, regval); 140 + 141 + /* Hold frame data until register was read */ 142 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_HOLD_CODE, 143 + timings->hold_code_enable ? 144 + IR_DEC_REG1_HOLD_CODE : 0); 145 + 146 + /* Bit order */ 147 + regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_BIT_ORDER, 148 + timings->bit_order ? IR_DEC_REG2_BIT_ORDER : 0); 149 + 150 + /* Select tick mode */ 151 + regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_TICK_MODE, 152 + timings->count_tick_mode ? 153 + IR_DEC_REG2_TICK_MODE : 0); 154 + 155 + /* 156 + * Some protocols transmit the same data frame as repeat frame 157 + * when the key is pressing. In this case, it could be detected as 158 + * repeat frame if the repeat checker was enabled. 159 + */ 160 + regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_REPEAT_COUNTER, 161 + timings->repeat_counter_enable ? 162 + IR_DEC_REG2_REPEAT_COUNTER : 0); 163 + regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_REPEAT_TIME, 164 + timings->repeat_check_enable ? 165 + IR_DEC_REG2_REPEAT_TIME : 0); 166 + regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_COMPARE_FRAME, 167 + timings->repeat_compare_enable ? 168 + IR_DEC_REG2_COMPARE_FRAME : 0); 169 + 170 + /* 171 + * FRAME_TIME_MAX should be larger than the time between 172 + * data frame and repeat frame 173 + */ 174 + regval = FIELD_PREP(IR_DEC_REG0_FRAME_TIME_MAX, 175 + timings->frame_time_max); 176 + regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_FRAME_TIME_MAX, 177 + regval); 178 + 179 + /* Length(N-1) of data frame */ 180 + regval = FIELD_PREP(IR_DEC_REG1_FRAME_LEN, timings->code_length - 1); 181 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_FRAME_LEN, regval); 182 + 183 + /* Time for leader active part */ 184 + regval = FIELD_PREP(IR_DEC_LDR_ACTIVE_MAX, 185 + timings->leader_active_max) | 186 + FIELD_PREP(IR_DEC_LDR_ACTIVE_MIN, 187 + timings->leader_active_min); 188 + regmap_update_bits(ir->reg, IR_DEC_LDR_ACTIVE, IR_DEC_LDR_ACTIVE_MAX | 189 + IR_DEC_LDR_ACTIVE_MIN, regval); 190 + 191 + /* Time for leader idle part */ 192 + regval = FIELD_PREP(IR_DEC_LDR_IDLE_MAX, timings->leader_idle_max) | 193 + FIELD_PREP(IR_DEC_LDR_IDLE_MIN, timings->leader_idle_min); 194 + regmap_update_bits(ir->reg, IR_DEC_LDR_IDLE, 195 + IR_DEC_LDR_IDLE_MAX | IR_DEC_LDR_IDLE_MIN, regval); 196 + 197 + /* Time for repeat leader idle part */ 198 + regval = FIELD_PREP(IR_DEC_LDR_REPEAT_MAX, timings->repeat_leader_max) | 199 + FIELD_PREP(IR_DEC_LDR_REPEAT_MIN, timings->repeat_leader_min); 200 + regmap_update_bits(ir->reg, IR_DEC_LDR_REPEAT, IR_DEC_LDR_REPEAT_MAX | 201 + IR_DEC_LDR_REPEAT_MIN, regval); 202 + 203 + /* 204 + * NEC: Time for logic '0' 205 + * RC6: Time for half of trailer bit 206 + */ 207 + regval = FIELD_PREP(IR_DEC_BIT_0_MAX, timings->bit0_max) | 208 + FIELD_PREP(IR_DEC_BIT_0_MIN, timings->bit0_min); 209 + regmap_update_bits(ir->reg, IR_DEC_BIT_0, 210 + IR_DEC_BIT_0_MAX | IR_DEC_BIT_0_MIN, regval); 211 + 212 + /* 213 + * NEC: Time for logic '1' 214 + * RC6: Time for whole of trailer bit 215 + */ 216 + regval = FIELD_PREP(IR_DEC_STATUS_BIT_1_MAX, timings->bit1_max) | 217 + FIELD_PREP(IR_DEC_STATUS_BIT_1_MIN, timings->bit1_min); 218 + regmap_update_bits(ir->reg, IR_DEC_STATUS, IR_DEC_STATUS_BIT_1_MAX | 219 + IR_DEC_STATUS_BIT_1_MIN, regval); 220 + 221 + /* Enable to match logic '1' */ 222 + regmap_update_bits(ir->reg, IR_DEC_STATUS, IR_DEC_STATUS_BIT_1_ENABLE, 223 + timings->bit1_match_enable ? 224 + IR_DEC_STATUS_BIT_1_ENABLE : 0); 225 + 226 + /* 227 + * NEC: Unused 228 + * RC6: Time for halt of logic 0/1 229 + */ 230 + regval = FIELD_PREP(IR_DEC_DURATN2_MAX, timings->duration2_max) | 231 + FIELD_PREP(IR_DEC_DURATN2_MIN, timings->duration2_min); 232 + regmap_update_bits(ir->reg, IR_DEC_DURATN2, 233 + IR_DEC_DURATN2_MAX | IR_DEC_DURATN2_MIN, regval); 234 + 235 + /* 236 + * NEC: Unused 237 + * RC6: Time for whole logic 0/1 238 + */ 239 + regval = FIELD_PREP(IR_DEC_DURATN3_MAX, timings->duration3_max) | 240 + FIELD_PREP(IR_DEC_DURATN3_MIN, timings->duration3_min); 241 + regmap_update_bits(ir->reg, IR_DEC_DURATN3, 242 + IR_DEC_DURATN3_MAX | IR_DEC_DURATN3_MIN, regval); 243 + 244 + /* Reset ir decoder and enable decode */ 245 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, 246 + IR_DEC_REG1_RESET); 247 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, 0); 248 + regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, 249 + IR_DEC_REG1_ENABLE); 250 + 251 + spin_unlock_irqrestore(&ir->lock, flags); 252 + 253 + dev_info(&dev->dev, "hw decoder init, protocol: %d\n", protocol); 254 + 255 + return 0; 256 + } 257 + 258 + static void meson_ir_sw_decoder_init(struct rc_dev *dev) 259 + { 260 + unsigned long flags; 261 + struct meson_ir *ir = dev->priv; 262 + 263 + spin_lock_irqsave(&ir->lock, flags); 294 264 295 265 /* Reset the decoder */ 296 266 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, ··· 416 150 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_RESET, 0); 417 151 418 152 /* Set general operation mode (= raw/software decoding) */ 419 - if (of_device_is_compatible(node, "amlogic,meson6-ir")) 153 + if (of_device_is_compatible(dev->dev.of_node, "amlogic,meson6-ir")) 420 154 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_MODE, 421 - FIELD_PREP(IR_DEC_REG1_MODE, DEC_MODE_RAW)); 155 + FIELD_PREP(IR_DEC_REG1_MODE, 156 + DEC_MODE_RAW)); 422 157 else 423 158 regmap_update_bits(ir->reg, IR_DEC_REG2, IR_DEC_REG2_MODE, 424 - FIELD_PREP(IR_DEC_REG2_MODE, DEC_MODE_RAW)); 159 + FIELD_PREP(IR_DEC_REG2_MODE, 160 + DEC_MODE_RAW)); 425 161 426 162 /* Set rate */ 427 163 regmap_update_bits(ir->reg, IR_DEC_REG0, IR_DEC_REG0_BASE_TIME, ··· 435 167 /* Enable the decoder */ 436 168 regmap_update_bits(ir->reg, IR_DEC_REG1, IR_DEC_REG1_ENABLE, 437 169 IR_DEC_REG1_ENABLE); 170 + 171 + spin_unlock_irqrestore(&ir->lock, flags); 172 + 173 + dev_info(&dev->dev, "sw decoder init\n"); 174 + } 175 + 176 + static int meson_ir_probe(struct platform_device *pdev) 177 + { 178 + const struct meson_ir_param *match_data; 179 + struct device *dev = &pdev->dev; 180 + struct device_node *node = dev->of_node; 181 + void __iomem *res_start; 182 + const char *map_name; 183 + struct meson_ir *ir; 184 + int irq, ret; 185 + 186 + ir = devm_kzalloc(dev, sizeof(struct meson_ir), GFP_KERNEL); 187 + if (!ir) 188 + return -ENOMEM; 189 + 190 + match_data = of_device_get_match_data(dev); 191 + if (!match_data) 192 + return dev_err_probe(dev, -ENODEV, "failed to get match data\n"); 193 + 194 + ir->param = match_data; 195 + 196 + res_start = devm_platform_ioremap_resource(pdev, 0); 197 + if (IS_ERR(res_start)) 198 + return PTR_ERR(res_start); 199 + 200 + meson_ir_regmap_config.max_register = ir->param->max_register; 201 + ir->reg = devm_regmap_init_mmio(&pdev->dev, res_start, 202 + &meson_ir_regmap_config); 203 + if (IS_ERR(ir->reg)) 204 + return PTR_ERR(ir->reg); 205 + 206 + irq = platform_get_irq(pdev, 0); 207 + if (irq < 0) 208 + return irq; 209 + 210 + if (ir->param->support_hw_decoder) 211 + ir->rc = devm_rc_allocate_device(&pdev->dev, 212 + RC_DRIVER_SCANCODE); 213 + else 214 + ir->rc = devm_rc_allocate_device(&pdev->dev, RC_DRIVER_IR_RAW); 215 + 216 + if (!ir->rc) { 217 + dev_err(dev, "failed to allocate rc device\n"); 218 + return -ENOMEM; 219 + } 220 + 221 + if (ir->rc->driver_type == RC_DRIVER_IR_RAW) { 222 + ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; 223 + ir->rc->rx_resolution = MESON_RAW_TRATE; 224 + ir->rc->min_timeout = 1; 225 + ir->rc->timeout = IR_DEFAULT_TIMEOUT; 226 + ir->rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT; 227 + } else if (ir->rc->driver_type == RC_DRIVER_SCANCODE) { 228 + ir->rc->allowed_protocols = RC_PROTO_BIT_NEC; 229 + ir->rc->change_protocol = meson_ir_hw_decoder_init; 230 + } 231 + 232 + ir->rc->priv = ir; 233 + ir->rc->device_name = DRIVER_NAME; 234 + ir->rc->input_phys = DRIVER_NAME "/input0"; 235 + ir->rc->input_id.bustype = BUS_HOST; 236 + map_name = of_get_property(node, "linux,rc-map-name", NULL); 237 + ir->rc->map_name = map_name ? map_name : RC_MAP_EMPTY; 238 + ir->rc->driver_name = DRIVER_NAME; 239 + 240 + spin_lock_init(&ir->lock); 241 + platform_set_drvdata(pdev, ir); 242 + 243 + ret = devm_rc_register_device(dev, ir->rc); 244 + if (ret) { 245 + dev_err(dev, "failed to register rc device\n"); 246 + return ret; 247 + } 248 + 249 + if (ir->rc->driver_type == RC_DRIVER_IR_RAW) 250 + meson_ir_sw_decoder_init(ir->rc); 251 + 252 + ret = devm_request_irq(dev, irq, meson_ir_irq, 0, "meson_ir", ir); 253 + if (ret) { 254 + dev_err(dev, "failed to request irq\n"); 255 + return ret; 256 + } 438 257 439 258 dev_info(dev, "receiver initialized\n"); 440 259 ··· 567 212 spin_unlock_irqrestore(&ir->lock, flags); 568 213 } 569 214 215 + static const struct meson_ir_param meson6_ir_param = { 216 + .support_hw_decoder = false, 217 + .max_register = IR_DEC_REG1, 218 + }; 219 + 220 + static const struct meson_ir_param meson8b_ir_param = { 221 + .support_hw_decoder = false, 222 + .max_register = IR_DEC_REG2, 223 + }; 224 + 225 + static const struct meson_ir_param meson_s4_ir_param = { 226 + .support_hw_decoder = true, 227 + .max_register = IR_DEC_FRAME1, 228 + }; 229 + 570 230 static const struct of_device_id meson_ir_match[] = { 571 - { .compatible = "amlogic,meson6-ir" }, 572 - { .compatible = "amlogic,meson8b-ir" }, 573 - { .compatible = "amlogic,meson-gxbb-ir" }, 574 - { }, 231 + { 232 + .compatible = "amlogic,meson6-ir", 233 + .data = &meson6_ir_param, 234 + }, { 235 + .compatible = "amlogic,meson8b-ir", 236 + .data = &meson8b_ir_param, 237 + }, { 238 + .compatible = "amlogic,meson-gxbb-ir", 239 + .data = &meson8b_ir_param, 240 + }, { 241 + .compatible = "amlogic,meson-s4-ir", 242 + .data = &meson_s4_ir_param, 243 + }, 244 + {}, 575 245 }; 576 246 MODULE_DEVICE_TABLE(of, meson_ir_match); 577 247