smsir.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /****************************************************************
  2. Siano Mobile Silicon, Inc.
  3. MDTV receiver kernel modules.
  4. Copyright (C) 2006-2009, Uri Shkolnik
  5. Copyright (c) 2010 - Mauro Carvalho Chehab
  6. - Ported the driver to use rc-core
  7. - IR raw event decoding is now done at rc-core
  8. - Code almost re-written
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. ****************************************************************/
  20. #include "smscoreapi.h"
  21. #include <linux/types.h>
  22. #include <linux/input.h>
  23. #include "smsir.h"
  24. #include "sms-cards.h"
  25. #define MODULE_NAME "smsmdtv"
  26. void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
  27. {
  28. int i;
  29. const s32 *samples = (const void *)buf;
  30. for (i = 0; i < len >> 2; i++) {
  31. DEFINE_IR_RAW_EVENT(ev);
  32. ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
  33. ev.pulse = (samples[i] > 0) ? false : true;
  34. ir_raw_event_store(coredev->ir.dev, &ev);
  35. }
  36. ir_raw_event_handle(coredev->ir.dev);
  37. }
  38. int sms_ir_init(struct smscore_device_t *coredev)
  39. {
  40. int err;
  41. int board_id = smscore_get_board_id(coredev);
  42. struct rc_dev *dev;
  43. pr_debug("Allocating rc device\n");
  44. dev = rc_allocate_device();
  45. if (!dev)
  46. return -ENOMEM;
  47. coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
  48. coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
  49. pr_debug("IR port %d, timeout %d ms\n",
  50. coredev->ir.controller, coredev->ir.timeout);
  51. snprintf(coredev->ir.name, sizeof(coredev->ir.name),
  52. "SMS IR (%s)", sms_get_board(board_id)->name);
  53. strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
  54. strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
  55. dev->input_name = coredev->ir.name;
  56. dev->input_phys = coredev->ir.phys;
  57. dev->dev.parent = coredev->device;
  58. #if 0
  59. /* TODO: properly initialize the parameters below */
  60. dev->input_id.bustype = BUS_USB;
  61. dev->input_id.version = 1;
  62. dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  63. dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  64. #endif
  65. dev->priv = coredev;
  66. dev->driver_type = RC_DRIVER_IR_RAW;
  67. dev->allowed_protocols = RC_BIT_ALL;
  68. dev->map_name = sms_get_board(board_id)->rc_codes;
  69. dev->driver_name = MODULE_NAME;
  70. pr_debug("Input device (IR) %s is set for key events\n",
  71. dev->input_name);
  72. err = rc_register_device(dev);
  73. if (err < 0) {
  74. pr_err("Failed to register device\n");
  75. rc_free_device(dev);
  76. return err;
  77. }
  78. coredev->ir.dev = dev;
  79. return 0;
  80. }
  81. void sms_ir_exit(struct smscore_device_t *coredev)
  82. {
  83. rc_unregister_device(coredev->ir.dev);
  84. pr_debug("\n");
  85. }