Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 1 | /**************************************************************** |
| 2 | |
| 3 | Siano Mobile Silicon, Inc. |
| 4 | MDTV receiver kernel modules. |
| 5 | Copyright (C) 2006-2009, Uri Shkolnik |
| 6 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 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 | |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 12 | This program is free software: you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation, either version 2 of the License, or |
| 15 | (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | |
| 25 | ****************************************************************/ |
| 26 | |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/input.h> |
| 30 | |
| 31 | #include "smscoreapi.h" |
| 32 | #include "smsir.h" |
| 33 | #include "sms-cards.h" |
| 34 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 35 | #define MODULE_NAME "smsmdtv" |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 36 | |
| 37 | void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len) |
| 38 | { |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 39 | int i; |
| 40 | const s32 *samples = (const void *)buf; |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 41 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 42 | for (i = 0; i < len >> 2; i++) { |
Maxim Levitsky | dc69798 | 2010-10-24 23:05:29 -0300 | [diff] [blame^] | 43 | DEFINE_IR_RAW_EVENT(ev); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 44 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 45 | ev.duration = abs(samples[i]) * 1000; /* Convert to ns */ |
| 46 | ev.pulse = (samples[i] > 0) ? false : true; |
| 47 | |
| 48 | ir_raw_event_store(coredev->ir.input_dev, &ev); |
| 49 | } |
| 50 | ir_raw_event_handle(coredev->ir.input_dev); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | int sms_ir_init(struct smscore_device_t *coredev) |
| 54 | { |
| 55 | struct input_dev *input_dev; |
Mauro Carvalho Chehab | 1722f3b | 2010-08-01 15:30:50 -0300 | [diff] [blame] | 56 | int board_id = smscore_get_board_id(coredev); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 57 | |
Uri Shkolnik | 90f944a | 2009-05-14 16:32:12 -0300 | [diff] [blame] | 58 | sms_log("Allocating input device"); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 59 | input_dev = input_allocate_device(); |
| 60 | if (!input_dev) { |
| 61 | sms_err("Not enough memory"); |
| 62 | return -ENOMEM; |
| 63 | } |
| 64 | |
| 65 | coredev->ir.input_dev = input_dev; |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 66 | |
| 67 | coredev->ir.controller = 0; /* Todo: vega/nova SPI number */ |
| 68 | coredev->ir.timeout = IR_DEFAULT_TIMEOUT; |
Uri Shkolnik | 90f944a | 2009-05-14 16:32:12 -0300 | [diff] [blame] | 69 | sms_log("IR port %d, timeout %d ms", |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 70 | coredev->ir.controller, coredev->ir.timeout); |
| 71 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 72 | snprintf(coredev->ir.name, sizeof(coredev->ir.name), |
| 73 | "SMS IR (%s)", sms_get_board(board_id)->name); |
Mauro Carvalho Chehab | 1722f3b | 2010-08-01 15:30:50 -0300 | [diff] [blame] | 74 | |
| 75 | strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys)); |
| 76 | strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys)); |
| 77 | |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 78 | input_dev->name = coredev->ir.name; |
Mauro Carvalho Chehab | 1722f3b | 2010-08-01 15:30:50 -0300 | [diff] [blame] | 79 | input_dev->phys = coredev->ir.phys; |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 80 | input_dev->dev.parent = coredev->device; |
| 81 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 82 | #if 0 |
| 83 | /* TODO: properly initialize the parameters bellow */ |
| 84 | input_dev->id.bustype = BUS_USB; |
| 85 | input_dev->id.version = 1; |
| 86 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 87 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 88 | #endif |
| 89 | |
| 90 | coredev->ir.props.priv = coredev; |
| 91 | coredev->ir.props.driver_type = RC_DRIVER_IR_RAW; |
| 92 | coredev->ir.props.allowed_protos = IR_TYPE_ALL; |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 93 | |
Uri Shkolnik | 90f944a | 2009-05-14 16:32:12 -0300 | [diff] [blame] | 94 | sms_log("Input device (IR) %s is set for key events", input_dev->name); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 95 | |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 96 | if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes, |
| 97 | &coredev->ir.props, MODULE_NAME)) { |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 98 | sms_err("Failed to register device"); |
| 99 | input_free_device(input_dev); |
| 100 | return -EACCES; |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | void sms_ir_exit(struct smscore_device_t *coredev) |
| 107 | { |
| 108 | if (coredev->ir.input_dev) |
Mauro Carvalho Chehab | 844a9e9 | 2010-08-01 17:19:29 -0300 | [diff] [blame] | 109 | ir_input_unregister(coredev->ir.input_dev); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 110 | |
Uri Shkolnik | 90f944a | 2009-05-14 16:32:12 -0300 | [diff] [blame] | 111 | sms_log(""); |
Uri Shkolnik | ebb6c22 | 2009-04-05 06:01:37 -0300 | [diff] [blame] | 112 | } |