cx231xx-input.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0
  2. // cx231xx IR glue driver
  3. //
  4. // Copyright (c) 2010 Mauro Carvalho Chehab <mchehab@kernel.org>
  5. //
  6. // Polaris (cx231xx) has its support for IR's with a design close to MCE.
  7. // however, a few designs are using an external I2C chip for IR, instead
  8. // of using the one provided by the chip.
  9. // This driver provides support for those extra devices
  10. #include "cx231xx.h"
  11. #include <linux/slab.h>
  12. #include <linux/bitrev.h>
  13. #define MODULE_NAME "cx231xx-input"
  14. static int get_key_isdbt(struct IR_i2c *ir, enum rc_proto *protocol,
  15. u32 *pscancode, u8 *toggle)
  16. {
  17. int rc;
  18. u8 cmd, scancode;
  19. dev_dbg(&ir->rc->dev, "%s\n", __func__);
  20. /* poll IR chip */
  21. rc = i2c_master_recv(ir->c, &cmd, 1);
  22. if (rc < 0)
  23. return rc;
  24. if (rc != 1)
  25. return -EIO;
  26. /* it seems that 0xFE indicates that a button is still hold
  27. down, while 0xff indicates that no button is hold
  28. down. 0xfe sequences are sometimes interrupted by 0xFF */
  29. if (cmd == 0xff)
  30. return 0;
  31. scancode = bitrev8(cmd);
  32. dev_dbg(&ir->rc->dev, "cmd %02x, scan = %02x\n", cmd, scancode);
  33. *protocol = RC_PROTO_OTHER;
  34. *pscancode = scancode;
  35. *toggle = 0;
  36. return 1;
  37. }
  38. int cx231xx_ir_init(struct cx231xx *dev)
  39. {
  40. struct i2c_board_info info;
  41. u8 ir_i2c_bus;
  42. dev_dbg(dev->dev, "%s\n", __func__);
  43. /* Only initialize if a rc keycode map is defined */
  44. if (!cx231xx_boards[dev->model].rc_map_name)
  45. return -ENODEV;
  46. request_module("ir-kbd-i2c");
  47. memset(&info, 0, sizeof(struct i2c_board_info));
  48. memset(&dev->init_data, 0, sizeof(dev->init_data));
  49. dev->init_data.rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
  50. if (!dev->init_data.rc_dev)
  51. return -ENOMEM;
  52. dev->init_data.name = cx231xx_boards[dev->model].name;
  53. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  54. info.platform_data = &dev->init_data;
  55. /*
  56. * Board-dependent values
  57. *
  58. * For now, there's just one type of hardware design using
  59. * an i2c device.
  60. */
  61. dev->init_data.get_key = get_key_isdbt;
  62. dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
  63. /* The i2c micro-controller only outputs the cmd part of NEC protocol */
  64. dev->init_data.rc_dev->scancode_mask = 0xff;
  65. dev->init_data.rc_dev->driver_name = "cx231xx";
  66. dev->init_data.type = RC_PROTO_BIT_NEC;
  67. info.addr = 0x30;
  68. /* Load and bind ir-kbd-i2c */
  69. ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
  70. dev_dbg(dev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
  71. ir_i2c_bus, info.addr);
  72. dev->ir_i2c_client = i2c_new_device(
  73. cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info);
  74. return 0;
  75. }
  76. void cx231xx_ir_exit(struct cx231xx *dev)
  77. {
  78. if (dev->ir_i2c_client)
  79. i2c_unregister_device(dev->ir_i2c_client);
  80. dev->ir_i2c_client = NULL;
  81. }