cx231xx-input.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * cx231xx IR glue driver
  3. *
  4. * Copyright (C) 2010 Mauro Carvalho Chehab
  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. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation version 2.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. */
  20. #include "cx231xx.h"
  21. #include <linux/slab.h>
  22. #include <linux/bitrev.h>
  23. #define MODULE_NAME "cx231xx-input"
  24. static int get_key_isdbt(struct IR_i2c *ir, enum rc_type *protocol,
  25. u32 *pscancode, u8 *toggle)
  26. {
  27. int rc;
  28. u8 cmd, scancode;
  29. dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__);
  30. /* poll IR chip */
  31. rc = i2c_master_recv(ir->c, &cmd, 1);
  32. if (rc < 0)
  33. return rc;
  34. if (rc != 1)
  35. return -EIO;
  36. /* it seems that 0xFE indicates that a button is still hold
  37. down, while 0xff indicates that no button is hold
  38. down. 0xfe sequences are sometimes interrupted by 0xFF */
  39. if (cmd == 0xff)
  40. return 0;
  41. scancode = bitrev8(cmd);
  42. dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n",
  43. cmd, scancode);
  44. *protocol = RC_TYPE_OTHER;
  45. *pscancode = scancode;
  46. *toggle = 0;
  47. return 1;
  48. }
  49. int cx231xx_ir_init(struct cx231xx *dev)
  50. {
  51. struct i2c_board_info info;
  52. u8 ir_i2c_bus;
  53. dev_dbg(dev->dev, "%s\n", __func__);
  54. /* Only initialize if a rc keycode map is defined */
  55. if (!cx231xx_boards[dev->model].rc_map_name)
  56. return -ENODEV;
  57. request_module("ir-kbd-i2c");
  58. memset(&info, 0, sizeof(struct i2c_board_info));
  59. memset(&dev->init_data, 0, sizeof(dev->init_data));
  60. dev->init_data.rc_dev = rc_allocate_device();
  61. if (!dev->init_data.rc_dev)
  62. return -ENOMEM;
  63. dev->init_data.name = cx231xx_boards[dev->model].name;
  64. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  65. info.platform_data = &dev->init_data;
  66. /*
  67. * Board-dependent values
  68. *
  69. * For now, there's just one type of hardware design using
  70. * an i2c device.
  71. */
  72. dev->init_data.get_key = get_key_isdbt;
  73. dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
  74. /* The i2c micro-controller only outputs the cmd part of NEC protocol */
  75. dev->init_data.rc_dev->scancode_mask = 0xff;
  76. dev->init_data.rc_dev->driver_name = "cx231xx";
  77. dev->init_data.type = RC_BIT_NEC;
  78. info.addr = 0x30;
  79. /* Load and bind ir-kbd-i2c */
  80. ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
  81. dev_dbg(dev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
  82. ir_i2c_bus, info.addr);
  83. dev->ir_i2c_client = i2c_new_device(
  84. cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info);
  85. return 0;
  86. }
  87. void cx231xx_ir_exit(struct cx231xx *dev)
  88. {
  89. if (dev->ir_i2c_client)
  90. i2c_unregister_device(dev->ir_i2c_client);
  91. dev->ir_i2c_client = NULL;
  92. }