smsir.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. struct 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.input_dev, &ev);
  35. }
  36. ir_raw_event_handle(coredev->ir.input_dev);
  37. }
  38. int sms_ir_init(struct smscore_device_t *coredev)
  39. {
  40. struct input_dev *input_dev;
  41. int board_id = smscore_get_board_id(coredev);
  42. sms_log("Allocating input device");
  43. input_dev = input_allocate_device();
  44. if (!input_dev) {
  45. sms_err("Not enough memory");
  46. return -ENOMEM;
  47. }
  48. coredev->ir.input_dev = input_dev;
  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. input_dev->name = coredev->ir.name;
  58. input_dev->phys = coredev->ir.phys;
  59. input_dev->dev.parent = coredev->device;
  60. #if 0
  61. /* TODO: properly initialize the parameters bellow */
  62. input_dev->id.bustype = BUS_USB;
  63. input_dev->id.version = 1;
  64. input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  65. input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  66. #endif
  67. coredev->ir.props.priv = coredev;
  68. coredev->ir.props.driver_type = RC_DRIVER_IR_RAW;
  69. coredev->ir.props.allowed_protos = IR_TYPE_ALL;
  70. sms_log("Input device (IR) %s is set for key events", input_dev->name);
  71. if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes,
  72. &coredev->ir.props, MODULE_NAME)) {
  73. sms_err("Failed to register device");
  74. input_free_device(input_dev);
  75. return -EACCES;
  76. }
  77. return 0;
  78. }
  79. void sms_ir_exit(struct smscore_device_t *coredev)
  80. {
  81. if (coredev->ir.input_dev)
  82. ir_input_unregister(coredev->ir.input_dev);
  83. sms_log("");
  84. }