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