smsir.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Siano Mobile Silicon, Inc.
  4. // MDTV receiver kernel modules.
  5. // Copyright (C) 2006-2009, Uri Shkolnik
  6. //
  7. // Copyright (c) 2010 - Mauro Carvalho Chehab
  8. // - Ported the driver to use rc-core
  9. // - IR raw event decoding is now done at rc-core
  10. // - Code almost re-written
  11. #include "smscoreapi.h"
  12. #include <linux/types.h>
  13. #include <linux/input.h>
  14. #include "smsir.h"
  15. #include "sms-cards.h"
  16. #define MODULE_NAME "smsmdtv"
  17. void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
  18. {
  19. int i;
  20. const s32 *samples = (const void *)buf;
  21. for (i = 0; i < len >> 2; i++) {
  22. DEFINE_IR_RAW_EVENT(ev);
  23. ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
  24. ev.pulse = (samples[i] > 0) ? false : true;
  25. ir_raw_event_store(coredev->ir.dev, &ev);
  26. }
  27. ir_raw_event_handle(coredev->ir.dev);
  28. }
  29. int sms_ir_init(struct smscore_device_t *coredev)
  30. {
  31. int err;
  32. int board_id = smscore_get_board_id(coredev);
  33. struct rc_dev *dev;
  34. pr_debug("Allocating rc device\n");
  35. dev = rc_allocate_device(RC_DRIVER_IR_RAW);
  36. if (!dev)
  37. return -ENOMEM;
  38. coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
  39. coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
  40. pr_debug("IR port %d, timeout %d ms\n",
  41. coredev->ir.controller, coredev->ir.timeout);
  42. snprintf(coredev->ir.name, sizeof(coredev->ir.name),
  43. "SMS IR (%s)", sms_get_board(board_id)->name);
  44. strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
  45. strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
  46. dev->device_name = coredev->ir.name;
  47. dev->input_phys = coredev->ir.phys;
  48. dev->dev.parent = coredev->device;
  49. #if 0
  50. /* TODO: properly initialize the parameters below */
  51. dev->input_id.bustype = BUS_USB;
  52. dev->input_id.version = 1;
  53. dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  54. dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  55. #endif
  56. dev->priv = coredev;
  57. dev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
  58. dev->map_name = sms_get_board(board_id)->rc_codes;
  59. dev->driver_name = MODULE_NAME;
  60. pr_debug("Input device (IR) %s is set for key events\n",
  61. dev->device_name);
  62. err = rc_register_device(dev);
  63. if (err < 0) {
  64. pr_err("Failed to register device\n");
  65. rc_free_device(dev);
  66. return err;
  67. }
  68. coredev->ir.dev = dev;
  69. return 0;
  70. }
  71. void sms_ir_exit(struct smscore_device_t *coredev)
  72. {
  73. rc_unregister_device(coredev->ir.dev);
  74. pr_debug("\n");
  75. }