| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include <linux/bitops.h> |
| 14 |
#include <linux/clk.h> |
| 15 |
#include <linux/interrupt.h> |
| 16 |
#include <linux/spinlock.h> |
| 17 |
#include <linux/timer.h> |
| 18 |
#include <media/rc-core.h> |
| 19 |
#include "img-ir.h" |
| 20 |
|
| 21 |
|
| 22 |
static DEFINE_SPINLOCK(img_ir_decoders_lock); |
| 23 |
|
| 24 |
static bool img_ir_decoders_preprocessed; |
| 25 |
static struct img_ir_decoder *img_ir_decoders[] = { |
| 26 |
#ifdef CONFIG_IR_IMG_NEC |
| 27 |
&img_ir_nec, |
| 28 |
#endif |
| 29 |
#ifdef CONFIG_IR_IMG_JVC |
| 30 |
&img_ir_jvc, |
| 31 |
#endif |
| 32 |
#ifdef CONFIG_IR_IMG_SONY |
| 33 |
&img_ir_sony, |
| 34 |
#endif |
| 35 |
#ifdef CONFIG_IR_IMG_SHARP |
| 36 |
&img_ir_sharp, |
| 37 |
#endif |
| 38 |
#ifdef CONFIG_IR_IMG_SANYO |
| 39 |
&img_ir_sanyo, |
| 40 |
#endif |
| 41 |
#ifdef CONFIG_IR_IMG_RC5 |
| 42 |
&img_ir_rc5, |
| 43 |
#endif |
| 44 |
#ifdef CONFIG_IR_IMG_RC6 |
| 45 |
&img_ir_rc6, |
| 46 |
#endif |
| 47 |
NULL |
| 48 |
}; |
| 49 |
|
| 50 |
#define IMG_IR_F_FILTER BIT(RC_FILTER_NORMAL) |
| 51 |
#define IMG_IR_F_WAKE BIT(RC_FILTER_WAKEUP) |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
#define IMG_IR_QUIRK_CODE_BROKEN 0x1 |
| 56 |
#define IMG_IR_QUIRK_CODE_LEN_INCR 0x2 |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#define IMG_IR_QUIRK_CODE_IRQ 0x4 |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
static void img_ir_timing_preprocess(struct img_ir_timing_range *range, |
| 66 |
unsigned int unit) |
| 67 |
{ |
| 68 |
if (range->max < range->min) |
| 69 |
range->max = range->min; |
| 70 |
if (unit) { |
| 71 |
|
| 72 |
range->min = (range->min*unit)/1000; |
| 73 |
range->max = (range->max*unit + 999)/1000; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
static void img_ir_symbol_timing_preprocess(struct img_ir_symbol_timing *timing, |
| 78 |
unsigned int unit) |
| 79 |
{ |
| 80 |
img_ir_timing_preprocess(&timing->pulse, unit); |
| 81 |
img_ir_timing_preprocess(&timing->space, unit); |
| 82 |
} |
| 83 |
|
| 84 |
static void img_ir_timings_preprocess(struct img_ir_timings *timings, |
| 85 |
unsigned int unit) |
| 86 |
{ |
| 87 |
img_ir_symbol_timing_preprocess(&timings->ldr, unit); |
| 88 |
img_ir_symbol_timing_preprocess(&timings->s00, unit); |
| 89 |
img_ir_symbol_timing_preprocess(&timings->s01, unit); |
| 90 |
img_ir_symbol_timing_preprocess(&timings->s10, unit); |
| 91 |
img_ir_symbol_timing_preprocess(&timings->s11, unit); |
| 92 |
|
| 93 |
if (unit) |
| 94 |
|
| 95 |
timings->ft.ft_min = (timings->ft.ft_min*unit + 999)/1000; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
static void img_ir_timing_defaults(struct img_ir_timing_range *range, |
| 101 |
struct img_ir_timing_range *defaults) |
| 102 |
{ |
| 103 |
if (!range->min) |
| 104 |
range->min = defaults->min; |
| 105 |
if (!range->max) |
| 106 |
range->max = defaults->max; |
| 107 |
} |
| 108 |
|
| 109 |
static void img_ir_symbol_timing_defaults(struct img_ir_symbol_timing *timing, |
| 110 |
struct img_ir_symbol_timing *defaults) |
| 111 |
{ |
| 112 |
img_ir_timing_defaults(&timing->pulse, &defaults->pulse); |
| 113 |
img_ir_timing_defaults(&timing->space, &defaults->space); |
| 114 |
} |
| 115 |
|
| 116 |
static void img_ir_timings_defaults(struct img_ir_timings *timings, |
| 117 |
struct img_ir_timings *defaults) |
| 118 |
{ |
| 119 |
img_ir_symbol_timing_defaults(&timings->ldr, &defaults->ldr); |
| 120 |
img_ir_symbol_timing_defaults(&timings->s00, &defaults->s00); |
| 121 |
img_ir_symbol_timing_defaults(&timings->s01, &defaults->s01); |
| 122 |
img_ir_symbol_timing_defaults(&timings->s10, &defaults->s10); |
| 123 |
img_ir_symbol_timing_defaults(&timings->s11, &defaults->s11); |
| 124 |
if (!timings->ft.ft_min) |
| 125 |
timings->ft.ft_min = defaults->ft.ft_min; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
static u32 img_ir_control(const struct img_ir_control *control) |
| 137 |
{ |
| 138 |
u32 ctrl = control->code_type << IMG_IR_CODETYPE_SHIFT; |
| 139 |
if (control->decoden) |
| 140 |
ctrl |= IMG_IR_DECODEN; |
| 141 |
if (control->hdrtog) |
| 142 |
ctrl |= IMG_IR_HDRTOG; |
| 143 |
if (control->ldrdec) |
| 144 |
ctrl |= IMG_IR_LDRDEC; |
| 145 |
if (control->decodinpol) |
| 146 |
ctrl |= IMG_IR_DECODINPOL; |
| 147 |
if (control->bitorien) |
| 148 |
ctrl |= IMG_IR_BITORIEN; |
| 149 |
if (control->d1validsel) |
| 150 |
ctrl |= IMG_IR_D1VALIDSEL; |
| 151 |
if (control->bitinv) |
| 152 |
ctrl |= IMG_IR_BITINV; |
| 153 |
if (control->decodend2) |
| 154 |
ctrl |= IMG_IR_DECODEND2; |
| 155 |
if (control->bitoriend2) |
| 156 |
ctrl |= IMG_IR_BITORIEND2; |
| 157 |
if (control->bitinvd2) |
| 158 |
ctrl |= IMG_IR_BITINVD2; |
| 159 |
return ctrl; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
static void img_ir_timing_range_convert(struct img_ir_timing_range *out, |
| 175 |
const struct img_ir_timing_range *in, |
| 176 |
unsigned int tolerance, |
| 177 |
unsigned long clock_hz, |
| 178 |
unsigned int shift) |
| 179 |
{ |
| 180 |
unsigned int min = in->min; |
| 181 |
unsigned int max = in->max; |
| 182 |
|
| 183 |
min = min - (min*tolerance >> 7); |
| 184 |
max = max + (max*tolerance >> 7); |
| 185 |
|
| 186 |
min = min*clock_hz / 1000000; |
| 187 |
max = (max*clock_hz + 999999) / 1000000; |
| 188 |
|
| 189 |
out->min = min >> shift; |
| 190 |
out->max = (max + ((1 << shift) - 1)) >> shift; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
static u32 img_ir_symbol_timing(const struct img_ir_symbol_timing *timing, |
| 204 |
unsigned int tolerance, |
| 205 |
unsigned long clock_hz, |
| 206 |
unsigned int pd_shift, |
| 207 |
unsigned int w_shift) |
| 208 |
{ |
| 209 |
struct img_ir_timing_range hw_pulse, hw_period; |
| 210 |
|
| 211 |
hw_period.min = timing->pulse.min + timing->space.min; |
| 212 |
hw_period.max = timing->pulse.max + timing->space.max; |
| 213 |
img_ir_timing_range_convert(&hw_period, &hw_period, |
| 214 |
tolerance, clock_hz, pd_shift); |
| 215 |
img_ir_timing_range_convert(&hw_pulse, &timing->pulse, |
| 216 |
tolerance, clock_hz, w_shift); |
| 217 |
|
| 218 |
return (hw_period.max << IMG_IR_PD_MAX_SHIFT) | |
| 219 |
(hw_period.min << IMG_IR_PD_MIN_SHIFT) | |
| 220 |
(hw_pulse.max << IMG_IR_W_MAX_SHIFT) | |
| 221 |
(hw_pulse.min << IMG_IR_W_MIN_SHIFT); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
static u32 img_ir_free_timing(const struct img_ir_free_timing *timing, |
| 232 |
unsigned long clock_hz) |
| 233 |
{ |
| 234 |
unsigned int minlen, maxlen, ft_min; |
| 235 |
|
| 236 |
if (timing->minlen < 30) |
| 237 |
minlen = timing->minlen & -2; |
| 238 |
else |
| 239 |
minlen = 30; |
| 240 |
|
| 241 |
if (timing->maxlen < 48) |
| 242 |
maxlen = (timing->maxlen + 1) & -2; |
| 243 |
else |
| 244 |
maxlen = 48; |
| 245 |
|
| 246 |
ft_min = (timing->ft_min*clock_hz + 999999) / 1000000; |
| 247 |
ft_min = (ft_min + 7) >> 3; |
| 248 |
|
| 249 |
return (maxlen << IMG_IR_MAXLEN_SHIFT) | |
| 250 |
(minlen << IMG_IR_MINLEN_SHIFT) | |
| 251 |
(ft_min << IMG_IR_FT_MIN_SHIFT); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
static u32 img_ir_free_timing_dynamic(u32 st_ft, struct img_ir_filter *filter) |
| 262 |
{ |
| 263 |
unsigned int minlen, maxlen, newminlen, newmaxlen; |
| 264 |
|
| 265 |
|
| 266 |
newminlen = filter->minlen & -2; |
| 267 |
newmaxlen = (filter->maxlen + 1) & -2; |
| 268 |
|
| 269 |
minlen = (st_ft & IMG_IR_MINLEN) >> IMG_IR_MINLEN_SHIFT; |
| 270 |
maxlen = (st_ft & IMG_IR_MAXLEN) >> IMG_IR_MAXLEN_SHIFT; |
| 271 |
|
| 272 |
if (newminlen > minlen) { |
| 273 |
st_ft &= ~IMG_IR_MINLEN; |
| 274 |
st_ft |= newminlen << IMG_IR_MINLEN_SHIFT; |
| 275 |
} |
| 276 |
if (newmaxlen < maxlen) { |
| 277 |
st_ft &= ~IMG_IR_MAXLEN; |
| 278 |
st_ft |= newmaxlen << IMG_IR_MAXLEN_SHIFT; |
| 279 |
} |
| 280 |
return st_ft; |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
static void img_ir_timings_convert(struct img_ir_timing_regvals *regs, |
| 291 |
const struct img_ir_timings *timings, |
| 292 |
unsigned int tolerance, |
| 293 |
unsigned int clock_hz) |
| 294 |
{ |
| 295 |
|
| 296 |
regs->ldr = img_ir_symbol_timing(&timings->ldr, tolerance, clock_hz, |
| 297 |
4, 4); |
| 298 |
|
| 299 |
regs->s00 = img_ir_symbol_timing(&timings->s00, tolerance, clock_hz, |
| 300 |
1, 0); |
| 301 |
regs->s01 = img_ir_symbol_timing(&timings->s01, tolerance, clock_hz, |
| 302 |
1, 0); |
| 303 |
regs->s10 = img_ir_symbol_timing(&timings->s10, tolerance, clock_hz, |
| 304 |
1, 0); |
| 305 |
regs->s11 = img_ir_symbol_timing(&timings->s11, tolerance, clock_hz, |
| 306 |
1, 0); |
| 307 |
regs->ft = img_ir_free_timing(&timings->ft, clock_hz); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
static void img_ir_decoder_preprocess(struct img_ir_decoder *decoder) |
| 318 |
{ |
| 319 |
|
| 320 |
if (!decoder->tolerance) |
| 321 |
decoder->tolerance = 10; |
| 322 |
|
| 323 |
decoder->tolerance = decoder->tolerance * 128 / 100; |
| 324 |
|
| 325 |
|
| 326 |
img_ir_timings_preprocess(&decoder->timings, decoder->unit); |
| 327 |
|
| 328 |
|
| 329 |
if (decoder->repeat) { |
| 330 |
img_ir_timings_preprocess(&decoder->rtimings, decoder->unit); |
| 331 |
img_ir_timings_defaults(&decoder->rtimings, &decoder->timings); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
static void img_ir_decoder_convert(const struct img_ir_decoder *decoder, |
| 345 |
struct img_ir_reg_timings *reg_timings, |
| 346 |
unsigned int clock_hz) |
| 347 |
{ |
| 348 |
|
| 349 |
reg_timings->ctrl = img_ir_control(&decoder->control); |
| 350 |
|
| 351 |
|
| 352 |
img_ir_timings_convert(®_timings->timings, &decoder->timings, |
| 353 |
decoder->tolerance, clock_hz); |
| 354 |
|
| 355 |
|
| 356 |
if (decoder->repeat) |
| 357 |
img_ir_timings_convert(®_timings->rtimings, |
| 358 |
&decoder->rtimings, decoder->tolerance, |
| 359 |
clock_hz); |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
static void img_ir_write_timings(struct img_ir_priv *priv, |
| 373 |
struct img_ir_timing_regvals *regs, |
| 374 |
enum rc_filter_type type) |
| 375 |
{ |
| 376 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 377 |
|
| 378 |
|
| 379 |
u32 ft = regs->ft; |
| 380 |
if (hw->flags & BIT(type)) |
| 381 |
ft = img_ir_free_timing_dynamic(regs->ft, &hw->filters[type]); |
| 382 |
|
| 383 |
img_ir_write(priv, IMG_IR_LEAD_SYMB_TIMING, regs->ldr); |
| 384 |
img_ir_write(priv, IMG_IR_S00_SYMB_TIMING, regs->s00); |
| 385 |
img_ir_write(priv, IMG_IR_S01_SYMB_TIMING, regs->s01); |
| 386 |
img_ir_write(priv, IMG_IR_S10_SYMB_TIMING, regs->s10); |
| 387 |
img_ir_write(priv, IMG_IR_S11_SYMB_TIMING, regs->s11); |
| 388 |
img_ir_write(priv, IMG_IR_FREE_SYMB_TIMING, ft); |
| 389 |
dev_dbg(priv->dev, "timings: ldr=%#x, s=[%#x, %#x, %#x, %#x], ft=%#x\n", |
| 390 |
regs->ldr, regs->s00, regs->s01, regs->s10, regs->s11, ft); |
| 391 |
} |
| 392 |
|
| 393 |
static void img_ir_write_filter(struct img_ir_priv *priv, |
| 394 |
struct img_ir_filter *filter) |
| 395 |
{ |
| 396 |
if (filter) { |
| 397 |
dev_dbg(priv->dev, "IR filter=%016llx & %016llx\n", |
| 398 |
(unsigned long long)filter->data, |
| 399 |
(unsigned long long)filter->mask); |
| 400 |
img_ir_write(priv, IMG_IR_IRQ_MSG_DATA_LW, (u32)filter->data); |
| 401 |
img_ir_write(priv, IMG_IR_IRQ_MSG_DATA_UP, (u32)(filter->data |
| 402 |
>> 32)); |
| 403 |
img_ir_write(priv, IMG_IR_IRQ_MSG_MASK_LW, (u32)filter->mask); |
| 404 |
img_ir_write(priv, IMG_IR_IRQ_MSG_MASK_UP, (u32)(filter->mask |
| 405 |
>> 32)); |
| 406 |
} else { |
| 407 |
dev_dbg(priv->dev, "IR clearing filter\n"); |
| 408 |
img_ir_write(priv, IMG_IR_IRQ_MSG_MASK_LW, 0); |
| 409 |
img_ir_write(priv, IMG_IR_IRQ_MSG_MASK_UP, 0); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
static void _img_ir_set_filter(struct img_ir_priv *priv, |
| 415 |
struct img_ir_filter *filter) |
| 416 |
{ |
| 417 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 418 |
u32 irq_en, irq_on; |
| 419 |
|
| 420 |
irq_en = img_ir_read(priv, IMG_IR_IRQ_ENABLE); |
| 421 |
if (filter) { |
| 422 |
|
| 423 |
hw->filters[RC_FILTER_NORMAL] = *filter; |
| 424 |
hw->flags |= IMG_IR_F_FILTER; |
| 425 |
irq_on = IMG_IR_IRQ_DATA_MATCH; |
| 426 |
irq_en &= ~(IMG_IR_IRQ_DATA_VALID | IMG_IR_IRQ_DATA2_VALID); |
| 427 |
} else { |
| 428 |
|
| 429 |
hw->flags &= ~IMG_IR_F_FILTER; |
| 430 |
irq_en &= ~IMG_IR_IRQ_DATA_MATCH; |
| 431 |
irq_on = IMG_IR_IRQ_DATA_VALID | IMG_IR_IRQ_DATA2_VALID; |
| 432 |
} |
| 433 |
irq_en |= irq_on; |
| 434 |
|
| 435 |
img_ir_write_filter(priv, filter); |
| 436 |
|
| 437 |
img_ir_write(priv, IMG_IR_IRQ_CLEAR, irq_on); |
| 438 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, irq_en); |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
static void _img_ir_set_wake_filter(struct img_ir_priv *priv, |
| 443 |
struct img_ir_filter *filter) |
| 444 |
{ |
| 445 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 446 |
if (filter) { |
| 447 |
|
| 448 |
hw->filters[RC_FILTER_WAKEUP] = *filter; |
| 449 |
hw->flags |= IMG_IR_F_WAKE; |
| 450 |
} else { |
| 451 |
|
| 452 |
hw->flags &= ~IMG_IR_F_WAKE; |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
static int img_ir_set_filter(struct rc_dev *dev, enum rc_filter_type type, |
| 458 |
struct rc_scancode_filter *sc_filter) |
| 459 |
{ |
| 460 |
struct img_ir_priv *priv = dev->priv; |
| 461 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 462 |
struct img_ir_filter filter, *filter_ptr = &filter; |
| 463 |
int ret = 0; |
| 464 |
|
| 465 |
dev_dbg(priv->dev, "IR scancode %sfilter=%08x & %08x\n", |
| 466 |
type == RC_FILTER_WAKEUP ? "wake " : "", |
| 467 |
sc_filter->data, |
| 468 |
sc_filter->mask); |
| 469 |
|
| 470 |
spin_lock_irq(&priv->lock); |
| 471 |
|
| 472 |
|
| 473 |
if (!sc_filter->mask) { |
| 474 |
filter_ptr = NULL; |
| 475 |
goto set_unlock; |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
if (!hw->decoder || !hw->decoder->filter) { |
| 480 |
ret = -EINVAL; |
| 481 |
goto unlock; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
filter.minlen = 0; |
| 486 |
filter.maxlen = ~0; |
| 487 |
if (type == RC_FILTER_NORMAL) { |
| 488 |
|
| 489 |
ret = hw->decoder->filter(sc_filter, &filter, |
| 490 |
dev->enabled_protocols); |
| 491 |
} else { |
| 492 |
|
| 493 |
ret = hw->decoder->filter(sc_filter, &filter, |
| 494 |
1ULL << dev->wakeup_protocol); |
| 495 |
} |
| 496 |
if (ret) |
| 497 |
goto unlock; |
| 498 |
dev_dbg(priv->dev, "IR raw %sfilter=%016llx & %016llx\n", |
| 499 |
type == RC_FILTER_WAKEUP ? "wake " : "", |
| 500 |
(unsigned long long)filter.data, |
| 501 |
(unsigned long long)filter.mask); |
| 502 |
|
| 503 |
set_unlock: |
| 504 |
|
| 505 |
switch (type) { |
| 506 |
case RC_FILTER_NORMAL: |
| 507 |
_img_ir_set_filter(priv, filter_ptr); |
| 508 |
break; |
| 509 |
case RC_FILTER_WAKEUP: |
| 510 |
_img_ir_set_wake_filter(priv, filter_ptr); |
| 511 |
break; |
| 512 |
default: |
| 513 |
ret = -EINVAL; |
| 514 |
} |
| 515 |
|
| 516 |
unlock: |
| 517 |
spin_unlock_irq(&priv->lock); |
| 518 |
return ret; |
| 519 |
} |
| 520 |
|
| 521 |
static int img_ir_set_normal_filter(struct rc_dev *dev, |
| 522 |
struct rc_scancode_filter *sc_filter) |
| 523 |
{ |
| 524 |
return img_ir_set_filter(dev, RC_FILTER_NORMAL, sc_filter); |
| 525 |
} |
| 526 |
|
| 527 |
static int img_ir_set_wakeup_filter(struct rc_dev *dev, |
| 528 |
struct rc_scancode_filter *sc_filter) |
| 529 |
{ |
| 530 |
return img_ir_set_filter(dev, RC_FILTER_WAKEUP, sc_filter); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
static void img_ir_set_decoder(struct img_ir_priv *priv, |
| 540 |
const struct img_ir_decoder *decoder, |
| 541 |
u64 proto) |
| 542 |
{ |
| 543 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 544 |
struct rc_dev *rdev = hw->rdev; |
| 545 |
u32 ir_status, irq_en; |
| 546 |
spin_lock_irq(&priv->lock); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
hw->stopping = true; |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
spin_unlock_irq(&priv->lock); |
| 559 |
timer_delete_sync(&hw->end_timer); |
| 560 |
timer_delete_sync(&hw->suspend_timer); |
| 561 |
spin_lock_irq(&priv->lock); |
| 562 |
|
| 563 |
hw->stopping = false; |
| 564 |
|
| 565 |
|
| 566 |
img_ir_write(priv, IMG_IR_CONTROL, 0); |
| 567 |
irq_en = img_ir_read(priv, IMG_IR_IRQ_ENABLE); |
| 568 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, irq_en & IMG_IR_IRQ_EDGE); |
| 569 |
img_ir_write(priv, IMG_IR_IRQ_CLEAR, IMG_IR_IRQ_ALL & ~IMG_IR_IRQ_EDGE); |
| 570 |
|
| 571 |
|
| 572 |
ir_status = img_ir_read(priv, IMG_IR_STATUS); |
| 573 |
if (ir_status & (IMG_IR_RXDVAL | IMG_IR_RXDVALD2)) { |
| 574 |
ir_status &= ~(IMG_IR_RXDVAL | IMG_IR_RXDVALD2); |
| 575 |
img_ir_write(priv, IMG_IR_STATUS, ir_status); |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
img_ir_read(priv, IMG_IR_DATA_LW); |
| 580 |
img_ir_read(priv, IMG_IR_DATA_UP); |
| 581 |
|
| 582 |
|
| 583 |
hw->mode = IMG_IR_M_NORMAL; |
| 584 |
|
| 585 |
|
| 586 |
rdev->scancode_wakeup_filter.data = 0; |
| 587 |
rdev->scancode_wakeup_filter.mask = 0; |
| 588 |
rdev->wakeup_protocol = RC_PROTO_UNKNOWN; |
| 589 |
|
| 590 |
|
| 591 |
_img_ir_set_filter(priv, NULL); |
| 592 |
_img_ir_set_wake_filter(priv, NULL); |
| 593 |
|
| 594 |
|
| 595 |
hw->enabled_protocols = 0; |
| 596 |
|
| 597 |
|
| 598 |
hw->decoder = decoder; |
| 599 |
if (!decoder) |
| 600 |
goto unlock; |
| 601 |
|
| 602 |
|
| 603 |
if (!proto) |
| 604 |
proto = decoder->type; |
| 605 |
hw->enabled_protocols = proto; |
| 606 |
|
| 607 |
|
| 608 |
img_ir_decoder_convert(decoder, &hw->reg_timings, hw->clk_hz); |
| 609 |
img_ir_write_timings(priv, &hw->reg_timings.timings, RC_FILTER_NORMAL); |
| 610 |
|
| 611 |
|
| 612 |
img_ir_write(priv, IMG_IR_CONTROL, hw->reg_timings.ctrl); |
| 613 |
|
| 614 |
|
| 615 |
unlock: |
| 616 |
spin_unlock_irq(&priv->lock); |
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
static bool img_ir_decoder_compatible(struct img_ir_priv *priv, |
| 627 |
const struct img_ir_decoder *dec) |
| 628 |
{ |
| 629 |
unsigned int ct; |
| 630 |
|
| 631 |
|
| 632 |
ct = dec->control.code_type; |
| 633 |
if (priv->hw.ct_quirks[ct] & IMG_IR_QUIRK_CODE_BROKEN) |
| 634 |
return false; |
| 635 |
|
| 636 |
return true; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
static u64 img_ir_allowed_protos(struct img_ir_priv *priv) |
| 646 |
{ |
| 647 |
u64 protos = 0; |
| 648 |
struct img_ir_decoder **decp; |
| 649 |
|
| 650 |
for (decp = img_ir_decoders; *decp; ++decp) { |
| 651 |
const struct img_ir_decoder *dec = *decp; |
| 652 |
if (img_ir_decoder_compatible(priv, dec)) |
| 653 |
protos |= dec->type; |
| 654 |
} |
| 655 |
return protos; |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
static int img_ir_change_protocol(struct rc_dev *dev, u64 *ir_type) |
| 660 |
{ |
| 661 |
struct img_ir_priv *priv = dev->priv; |
| 662 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 663 |
struct rc_dev *rdev = hw->rdev; |
| 664 |
struct img_ir_decoder **decp; |
| 665 |
u64 wakeup_protocols; |
| 666 |
|
| 667 |
if (!*ir_type) { |
| 668 |
|
| 669 |
img_ir_set_decoder(priv, NULL, 0); |
| 670 |
goto success; |
| 671 |
} |
| 672 |
for (decp = img_ir_decoders; *decp; ++decp) { |
| 673 |
const struct img_ir_decoder *dec = *decp; |
| 674 |
if (!img_ir_decoder_compatible(priv, dec)) |
| 675 |
continue; |
| 676 |
if (*ir_type & dec->type) { |
| 677 |
*ir_type &= dec->type; |
| 678 |
img_ir_set_decoder(priv, dec, *ir_type); |
| 679 |
goto success; |
| 680 |
} |
| 681 |
} |
| 682 |
return -EINVAL; |
| 683 |
|
| 684 |
success: |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
wakeup_protocols = *ir_type; |
| 690 |
if (!hw->decoder || !hw->decoder->filter) |
| 691 |
wakeup_protocols = 0; |
| 692 |
rdev->allowed_wakeup_protocols = wakeup_protocols; |
| 693 |
return 0; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
static void img_ir_set_protocol(struct img_ir_priv *priv, u64 proto) |
| 698 |
{ |
| 699 |
struct rc_dev *rdev = priv->hw.rdev; |
| 700 |
|
| 701 |
mutex_lock(&rdev->lock); |
| 702 |
rdev->enabled_protocols = proto; |
| 703 |
rdev->allowed_wakeup_protocols = proto; |
| 704 |
mutex_unlock(&rdev->lock); |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
static void img_ir_init_decoders(void) |
| 709 |
{ |
| 710 |
struct img_ir_decoder **decp; |
| 711 |
|
| 712 |
spin_lock(&img_ir_decoders_lock); |
| 713 |
if (!img_ir_decoders_preprocessed) { |
| 714 |
for (decp = img_ir_decoders; *decp; ++decp) |
| 715 |
img_ir_decoder_preprocess(*decp); |
| 716 |
img_ir_decoders_preprocessed = true; |
| 717 |
} |
| 718 |
spin_unlock(&img_ir_decoders_lock); |
| 719 |
} |
| 720 |
|
| 721 |
#ifdef CONFIG_PM_SLEEP |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
static int img_ir_enable_wake(struct img_ir_priv *priv) |
| 729 |
{ |
| 730 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 731 |
int ret = 0; |
| 732 |
|
| 733 |
spin_lock_irq(&priv->lock); |
| 734 |
if (hw->flags & IMG_IR_F_WAKE) { |
| 735 |
|
| 736 |
hw->suspend_irqen = img_ir_read(priv, IMG_IR_IRQ_ENABLE); |
| 737 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, IMG_IR_IRQ_DATA_MATCH); |
| 738 |
img_ir_write_filter(priv, &hw->filters[RC_FILTER_WAKEUP]); |
| 739 |
img_ir_write_timings(priv, &hw->reg_timings.timings, |
| 740 |
RC_FILTER_WAKEUP); |
| 741 |
hw->mode = IMG_IR_M_WAKE; |
| 742 |
ret = 1; |
| 743 |
} |
| 744 |
spin_unlock_irq(&priv->lock); |
| 745 |
return ret; |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
static int img_ir_disable_wake(struct img_ir_priv *priv) |
| 756 |
{ |
| 757 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 758 |
int ret = 0; |
| 759 |
|
| 760 |
spin_lock_irq(&priv->lock); |
| 761 |
if (hw->flags & IMG_IR_F_WAKE) { |
| 762 |
|
| 763 |
if (hw->flags & IMG_IR_F_FILTER) { |
| 764 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, |
| 765 |
(hw->suspend_irqen & IMG_IR_IRQ_EDGE) | |
| 766 |
IMG_IR_IRQ_DATA_MATCH); |
| 767 |
img_ir_write_filter(priv, |
| 768 |
&hw->filters[RC_FILTER_NORMAL]); |
| 769 |
} else { |
| 770 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, |
| 771 |
(hw->suspend_irqen & IMG_IR_IRQ_EDGE) | |
| 772 |
IMG_IR_IRQ_DATA_VALID | |
| 773 |
IMG_IR_IRQ_DATA2_VALID); |
| 774 |
img_ir_write_filter(priv, NULL); |
| 775 |
} |
| 776 |
img_ir_write_timings(priv, &hw->reg_timings.timings, |
| 777 |
RC_FILTER_NORMAL); |
| 778 |
hw->mode = IMG_IR_M_NORMAL; |
| 779 |
ret = 1; |
| 780 |
} |
| 781 |
spin_unlock_irq(&priv->lock); |
| 782 |
return ret; |
| 783 |
} |
| 784 |
#endif |
| 785 |
|
| 786 |
|
| 787 |
static void img_ir_begin_repeat(struct img_ir_priv *priv) |
| 788 |
{ |
| 789 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 790 |
if (hw->mode == IMG_IR_M_NORMAL) { |
| 791 |
|
| 792 |
img_ir_write(priv, IMG_IR_CONTROL, 0); |
| 793 |
hw->mode = IMG_IR_M_REPEATING; |
| 794 |
img_ir_write_timings(priv, &hw->reg_timings.rtimings, |
| 795 |
RC_FILTER_NORMAL); |
| 796 |
img_ir_write(priv, IMG_IR_CONTROL, hw->reg_timings.ctrl); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
static void img_ir_end_repeat(struct img_ir_priv *priv) |
| 802 |
{ |
| 803 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 804 |
if (hw->mode == IMG_IR_M_REPEATING) { |
| 805 |
|
| 806 |
img_ir_write(priv, IMG_IR_CONTROL, 0); |
| 807 |
hw->mode = IMG_IR_M_NORMAL; |
| 808 |
img_ir_write_timings(priv, &hw->reg_timings.timings, |
| 809 |
RC_FILTER_NORMAL); |
| 810 |
img_ir_write(priv, IMG_IR_CONTROL, hw->reg_timings.ctrl); |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
static void img_ir_handle_data(struct img_ir_priv *priv, u32 len, u64 raw) |
| 816 |
{ |
| 817 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 818 |
const struct img_ir_decoder *dec = hw->decoder; |
| 819 |
int ret = IMG_IR_SCANCODE; |
| 820 |
struct img_ir_scancode_req request; |
| 821 |
|
| 822 |
request.protocol = RC_PROTO_UNKNOWN; |
| 823 |
request.toggle = 0; |
| 824 |
|
| 825 |
if (dec->scancode) |
| 826 |
ret = dec->scancode(len, raw, hw->enabled_protocols, &request); |
| 827 |
else if (len >= 32) |
| 828 |
request.scancode = (u32)raw; |
| 829 |
else if (len < 32) |
| 830 |
request.scancode = (u32)raw & ((1 << len)-1); |
| 831 |
dev_dbg(priv->dev, "data (%u bits) = %#llx\n", |
| 832 |
len, (unsigned long long)raw); |
| 833 |
if (ret == IMG_IR_SCANCODE) { |
| 834 |
dev_dbg(priv->dev, "decoded scan code %#x, toggle %u\n", |
| 835 |
request.scancode, request.toggle); |
| 836 |
rc_keydown(hw->rdev, request.protocol, request.scancode, |
| 837 |
request.toggle); |
| 838 |
img_ir_end_repeat(priv); |
| 839 |
} else if (ret == IMG_IR_REPEATCODE) { |
| 840 |
if (hw->mode == IMG_IR_M_REPEATING) { |
| 841 |
dev_dbg(priv->dev, "decoded repeat code\n"); |
| 842 |
rc_repeat(hw->rdev); |
| 843 |
} else { |
| 844 |
dev_dbg(priv->dev, "decoded unexpected repeat code, ignoring\n"); |
| 845 |
} |
| 846 |
} else { |
| 847 |
dev_dbg(priv->dev, "decode failed (%d)\n", ret); |
| 848 |
return; |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
if (dec->repeat && !hw->stopping) { |
| 854 |
unsigned long interval; |
| 855 |
|
| 856 |
img_ir_begin_repeat(priv); |
| 857 |
|
| 858 |
|
| 859 |
interval = dec->repeat + (dec->repeat >> 3); |
| 860 |
mod_timer(&hw->end_timer, |
| 861 |
jiffies + msecs_to_jiffies(interval)); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
static void img_ir_end_timer(struct timer_list *t) |
| 867 |
{ |
| 868 |
struct img_ir_priv *priv = timer_container_of(priv, t, hw.end_timer); |
| 869 |
|
| 870 |
spin_lock_irq(&priv->lock); |
| 871 |
img_ir_end_repeat(priv); |
| 872 |
spin_unlock_irq(&priv->lock); |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
static void img_ir_suspend_timer(struct timer_list *t) |
| 881 |
{ |
| 882 |
struct img_ir_priv *priv = timer_container_of(priv, t, |
| 883 |
hw.suspend_timer); |
| 884 |
|
| 885 |
spin_lock_irq(&priv->lock); |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
if ((priv->hw.quirk_suspend_irq & IMG_IR_IRQ_EDGE) == |
| 891 |
img_ir_read(priv, IMG_IR_IRQ_ENABLE)) |
| 892 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, |
| 893 |
priv->hw.quirk_suspend_irq); |
| 894 |
|
| 895 |
img_ir_write(priv, IMG_IR_CONTROL, priv->hw.reg_timings.ctrl); |
| 896 |
spin_unlock_irq(&priv->lock); |
| 897 |
} |
| 898 |
|
| 899 |
#ifdef CONFIG_COMMON_CLK |
| 900 |
static void img_ir_change_frequency(struct img_ir_priv *priv, |
| 901 |
struct clk_notifier_data *change) |
| 902 |
{ |
| 903 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 904 |
|
| 905 |
dev_dbg(priv->dev, "clk changed %lu HZ -> %lu HZ\n", |
| 906 |
change->old_rate, change->new_rate); |
| 907 |
|
| 908 |
spin_lock_irq(&priv->lock); |
| 909 |
if (hw->clk_hz == change->new_rate) |
| 910 |
goto unlock; |
| 911 |
hw->clk_hz = change->new_rate; |
| 912 |
|
| 913 |
if (hw->decoder) { |
| 914 |
img_ir_decoder_convert(hw->decoder, &hw->reg_timings, |
| 915 |
hw->clk_hz); |
| 916 |
switch (hw->mode) { |
| 917 |
case IMG_IR_M_NORMAL: |
| 918 |
img_ir_write_timings(priv, &hw->reg_timings.timings, |
| 919 |
RC_FILTER_NORMAL); |
| 920 |
break; |
| 921 |
case IMG_IR_M_REPEATING: |
| 922 |
img_ir_write_timings(priv, &hw->reg_timings.rtimings, |
| 923 |
RC_FILTER_NORMAL); |
| 924 |
break; |
| 925 |
#ifdef CONFIG_PM_SLEEP |
| 926 |
case IMG_IR_M_WAKE: |
| 927 |
img_ir_write_timings(priv, &hw->reg_timings.timings, |
| 928 |
RC_FILTER_WAKEUP); |
| 929 |
break; |
| 930 |
#endif |
| 931 |
} |
| 932 |
} |
| 933 |
unlock: |
| 934 |
spin_unlock_irq(&priv->lock); |
| 935 |
} |
| 936 |
|
| 937 |
static int img_ir_clk_notify(struct notifier_block *self, unsigned long action, |
| 938 |
void *data) |
| 939 |
{ |
| 940 |
struct img_ir_priv *priv = container_of(self, struct img_ir_priv, |
| 941 |
hw.clk_nb); |
| 942 |
switch (action) { |
| 943 |
case POST_RATE_CHANGE: |
| 944 |
img_ir_change_frequency(priv, data); |
| 945 |
break; |
| 946 |
default: |
| 947 |
break; |
| 948 |
} |
| 949 |
return NOTIFY_OK; |
| 950 |
} |
| 951 |
#endif |
| 952 |
|
| 953 |
|
| 954 |
void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status) |
| 955 |
{ |
| 956 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 957 |
u32 ir_status, len, lw, up; |
| 958 |
unsigned int ct; |
| 959 |
|
| 960 |
|
| 961 |
if (!hw->decoder) |
| 962 |
return; |
| 963 |
|
| 964 |
ct = hw->decoder->control.code_type; |
| 965 |
|
| 966 |
ir_status = img_ir_read(priv, IMG_IR_STATUS); |
| 967 |
if (!(ir_status & (IMG_IR_RXDVAL | IMG_IR_RXDVALD2))) { |
| 968 |
if (!(priv->hw.ct_quirks[ct] & IMG_IR_QUIRK_CODE_IRQ) || |
| 969 |
hw->stopping) |
| 970 |
return; |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
img_ir_write(priv, IMG_IR_CONTROL, 0); |
| 982 |
hw->quirk_suspend_irq = img_ir_read(priv, IMG_IR_IRQ_ENABLE); |
| 983 |
img_ir_write(priv, IMG_IR_IRQ_ENABLE, |
| 984 |
hw->quirk_suspend_irq & IMG_IR_IRQ_EDGE); |
| 985 |
|
| 986 |
|
| 987 |
mod_timer(&hw->suspend_timer, |
| 988 |
jiffies + msecs_to_jiffies(5)); |
| 989 |
return; |
| 990 |
} |
| 991 |
ir_status &= ~(IMG_IR_RXDVAL | IMG_IR_RXDVALD2); |
| 992 |
img_ir_write(priv, IMG_IR_STATUS, ir_status); |
| 993 |
|
| 994 |
len = (ir_status & IMG_IR_RXDLEN) >> IMG_IR_RXDLEN_SHIFT; |
| 995 |
|
| 996 |
if (hw->ct_quirks[ct] & IMG_IR_QUIRK_CODE_LEN_INCR) |
| 997 |
++len; |
| 998 |
|
| 999 |
lw = img_ir_read(priv, IMG_IR_DATA_LW); |
| 1000 |
up = img_ir_read(priv, IMG_IR_DATA_UP); |
| 1001 |
img_ir_handle_data(priv, len, (u64)up << 32 | lw); |
| 1002 |
} |
| 1003 |
|
| 1004 |
void img_ir_setup_hw(struct img_ir_priv *priv) |
| 1005 |
{ |
| 1006 |
struct img_ir_decoder **decp; |
| 1007 |
|
| 1008 |
if (!priv->hw.rdev) |
| 1009 |
return; |
| 1010 |
|
| 1011 |
|
| 1012 |
for (decp = img_ir_decoders; *decp; ++decp) { |
| 1013 |
const struct img_ir_decoder *dec = *decp; |
| 1014 |
if (img_ir_decoder_compatible(priv, dec)) { |
| 1015 |
img_ir_set_protocol(priv, dec->type); |
| 1016 |
img_ir_set_decoder(priv, dec, 0); |
| 1017 |
return; |
| 1018 |
} |
| 1019 |
} |
| 1020 |
img_ir_set_decoder(priv, NULL, 0); |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
static void img_ir_probe_hw_caps(struct img_ir_priv *priv) |
| 1028 |
{ |
| 1029 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
hw->ct_quirks[IMG_IR_CODETYPE_PULSELEN] |
| 1035 |
|= IMG_IR_QUIRK_CODE_LEN_INCR; |
| 1036 |
hw->ct_quirks[IMG_IR_CODETYPE_BIPHASE] |
| 1037 |
|= IMG_IR_QUIRK_CODE_IRQ; |
| 1038 |
hw->ct_quirks[IMG_IR_CODETYPE_2BITPULSEPOS] |
| 1039 |
|= IMG_IR_QUIRK_CODE_BROKEN; |
| 1040 |
} |
| 1041 |
|
| 1042 |
int img_ir_probe_hw(struct img_ir_priv *priv) |
| 1043 |
{ |
| 1044 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 1045 |
struct rc_dev *rdev; |
| 1046 |
int error; |
| 1047 |
|
| 1048 |
|
| 1049 |
img_ir_init_decoders(); |
| 1050 |
|
| 1051 |
|
| 1052 |
img_ir_probe_hw_caps(priv); |
| 1053 |
|
| 1054 |
|
| 1055 |
timer_setup(&hw->end_timer, img_ir_end_timer, 0); |
| 1056 |
timer_setup(&hw->suspend_timer, img_ir_suspend_timer, 0); |
| 1057 |
|
| 1058 |
|
| 1059 |
if (!IS_ERR(priv->clk)) { |
| 1060 |
hw->clk_hz = clk_get_rate(priv->clk); |
| 1061 |
#ifdef CONFIG_COMMON_CLK |
| 1062 |
hw->clk_nb.notifier_call = img_ir_clk_notify; |
| 1063 |
error = clk_notifier_register(priv->clk, &hw->clk_nb); |
| 1064 |
if (error) |
| 1065 |
dev_warn(priv->dev, |
| 1066 |
"failed to register clock notifier\n"); |
| 1067 |
#endif |
| 1068 |
} else { |
| 1069 |
hw->clk_hz = 32768; |
| 1070 |
} |
| 1071 |
|
| 1072 |
|
| 1073 |
hw->rdev = rdev = rc_allocate_device(RC_DRIVER_SCANCODE); |
| 1074 |
if (!rdev) { |
| 1075 |
dev_err(priv->dev, "cannot allocate input device\n"); |
| 1076 |
error = -ENOMEM; |
| 1077 |
goto err_alloc_rc; |
| 1078 |
} |
| 1079 |
rdev->priv = priv; |
| 1080 |
rdev->map_name = RC_MAP_EMPTY; |
| 1081 |
rdev->allowed_protocols = img_ir_allowed_protos(priv); |
| 1082 |
rdev->device_name = "IMG Infrared Decoder"; |
| 1083 |
rdev->s_filter = img_ir_set_normal_filter; |
| 1084 |
rdev->s_wakeup_filter = img_ir_set_wakeup_filter; |
| 1085 |
|
| 1086 |
|
| 1087 |
error = rc_register_device(rdev); |
| 1088 |
if (error) { |
| 1089 |
dev_err(priv->dev, "failed to register IR input device\n"); |
| 1090 |
goto err_register_rc; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
rdev->change_protocol = img_ir_change_protocol; |
| 1098 |
|
| 1099 |
device_init_wakeup(priv->dev, 1); |
| 1100 |
|
| 1101 |
return 0; |
| 1102 |
|
| 1103 |
err_register_rc: |
| 1104 |
img_ir_set_decoder(priv, NULL, 0); |
| 1105 |
hw->rdev = NULL; |
| 1106 |
rc_free_device(rdev); |
| 1107 |
err_alloc_rc: |
| 1108 |
#ifdef CONFIG_COMMON_CLK |
| 1109 |
if (!IS_ERR(priv->clk)) |
| 1110 |
clk_notifier_unregister(priv->clk, &hw->clk_nb); |
| 1111 |
#endif |
| 1112 |
return error; |
| 1113 |
} |
| 1114 |
|
| 1115 |
void img_ir_remove_hw(struct img_ir_priv *priv) |
| 1116 |
{ |
| 1117 |
struct img_ir_priv_hw *hw = &priv->hw; |
| 1118 |
struct rc_dev *rdev = hw->rdev; |
| 1119 |
if (!rdev) |
| 1120 |
return; |
| 1121 |
rc_unregister_device(rdev); |
| 1122 |
img_ir_set_decoder(priv, NULL, 0); |
| 1123 |
hw->rdev = NULL; |
| 1124 |
rc_free_device(rdev); |
| 1125 |
#ifdef CONFIG_COMMON_CLK |
| 1126 |
if (!IS_ERR(priv->clk)) |
| 1127 |
clk_notifier_unregister(priv->clk, &hw->clk_nb); |
| 1128 |
#endif |
| 1129 |
} |
| 1130 |
|
| 1131 |
#ifdef CONFIG_PM_SLEEP |
| 1132 |
int img_ir_suspend(struct device *dev) |
| 1133 |
{ |
| 1134 |
struct img_ir_priv *priv = dev_get_drvdata(dev); |
| 1135 |
|
| 1136 |
if (device_may_wakeup(dev) && img_ir_enable_wake(priv)) |
| 1137 |
enable_irq_wake(priv->irq); |
| 1138 |
return 0; |
| 1139 |
} |
| 1140 |
|
| 1141 |
int img_ir_resume(struct device *dev) |
| 1142 |
{ |
| 1143 |
struct img_ir_priv *priv = dev_get_drvdata(dev); |
| 1144 |
|
| 1145 |
if (device_may_wakeup(dev) && img_ir_disable_wake(priv)) |
| 1146 |
disable_irq_wake(priv->irq); |
| 1147 |
return 0; |
| 1148 |
} |
| 1149 |
#endif |