smsir.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <linux/types.h>
  21. #include <linux/input.h>
  22. #include "smscoreapi.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. sms_log("Allocating rc device");
  44. dev = rc_allocate_device();
  45. if (!dev) {
  46. sms_err("Not enough memory");
  47. return -ENOMEM;
  48. }
  49. coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
  50. coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
  51. sms_log("IR port %d, timeout %d ms",
  52. coredev->ir.controller, coredev->ir.timeout);
  53. snprintf(coredev->ir.name, sizeof(coredev->ir.name),
  54. "SMS IR (%s)", sms_get_board(board_id)->name);
  55. strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
  56. strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
  57. dev->input_name = coredev->ir.name;
  58. dev->input_phys = coredev->ir.phys;
  59. dev->dev.parent = coredev->device;
  60. #if 0
  61. /* TODO: properly initialize the parameters bellow */
  62. dev->input_id.bustype = BUS_USB;
  63. dev->input_id.version = 1;
  64. dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  65. dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  66. #endif
  67. dev->priv = coredev;
  68. dev->driver_type = RC_DRIVER_IR_RAW;
  69. dev->allowed_protos = RC_TYPE_ALL;
  70. dev->map_name = sms_get_board(board_id)->rc_codes;
  71. dev->driver_name = MODULE_NAME;
  72. sms_log("Input device (IR) %s is set for key events", dev->input_name);
  73. err = rc_register_device(dev);
  74. if (err < 0) {
  75. sms_err("Failed to register device");
  76. rc_free_device(dev);
  77. return err;
  78. }
  79. coredev->ir.dev = dev;
  80. return 0;
  81. }
  82. void sms_ir_exit(struct smscore_device_t *coredev)
  83. {
  84. if (coredev->ir.dev)
  85. rc_unregister_device(coredev->ir.dev);
  86. sms_log("");
  87. }