blob: 8b66926bc16a905ca8006dd5cf44cc6d5a0921bd [file] [log] [blame]
Jarod Wilson1beef3c2010-07-26 20:31:45 -03001/*
Sean Youngfa5dc29c2016-11-21 19:55:53 -02002 * serial_ir.c
Jarod Wilson1beef3c2010-07-26 20:31:45 -03003 *
Sean Youngfa5dc29c2016-11-21 19:55:53 -02004 * serial_ir - Device driver that records pulse- and pause-lengths
Jarod Wilson1beef3c2010-07-26 20:31:45 -03005 * (space-lengths) between DDCD event on a serial port.
6 *
7 * Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
8 * Copyright (C) 1998 Trent Piepho <xyzzy@u.washington.edu>
9 * Copyright (C) 1998 Ben Pfaff <blp@gnu.org>
10 * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
11 * Copyright (C) 2007 Andrei Tanas <andrei@tanas.ca> (suspend/resume support)
Sean Youngb66db532016-11-21 19:55:51 -020012 * Copyright (C) 2016 Sean Young <sean@mess.org> (port to rc-core)
Jarod Wilson1beef3c2010-07-26 20:31:45 -030013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
Jarod Wilson1beef3c2010-07-26 20:31:45 -030022 */
23
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -030024#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
Jarod Wilson1beef3c2010-07-26 20:31:45 -030026#include <linux/module.h>
27#include <linux/errno.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030028#include <linux/interrupt.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030029#include <linux/kernel.h>
30#include <linux/serial_reg.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030031#include <linux/types.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030032#include <linux/delay.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030033#include <linux/platform_device.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030034#include <linux/spinlock.h>
Sean Youngb66db532016-11-21 19:55:51 -020035#include <media/rc-core.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030036
Sean Youngb66db532016-11-21 19:55:51 -020037struct serial_ir_hw {
Jarod Wilson1beef3c2010-07-26 20:31:45 -030038 int signal_pin;
39 int signal_pin_change;
40 u8 on;
41 u8 off;
Sean Youngb66db532016-11-21 19:55:51 -020042 unsigned set_send_carrier:1;
43 unsigned set_duty_cycle:1;
Sean Young0a847632016-11-21 19:55:52 -020044 void (*send_pulse)(unsigned int length, ktime_t edge);
45 void (*send_space)(void);
Jarod Wilson1beef3c2010-07-26 20:31:45 -030046 spinlock_t lock;
47};
48
Sean Youngb66db532016-11-21 19:55:51 -020049#define IR_HOMEBREW 0
50#define IR_IRDEO 1
51#define IR_IRDEO_REMOTE 2
52#define IR_ANIMAX 3
53#define IR_IGOR 4
Jarod Wilson1beef3c2010-07-26 20:31:45 -030054
Sean Youngb66db532016-11-21 19:55:51 -020055/* module parameters */
Jarod Wilson1beef3c2010-07-26 20:31:45 -030056static int type;
57static int io;
58static int irq;
Sean Young069f3b12017-02-13 20:53:23 -020059static ulong iommap;
Jarod Wilson1beef3c2010-07-26 20:31:45 -030060static int ioshift;
Heba Aamerf3a9d7e2015-01-26 10:21:09 -030061static bool softcarrier = true;
Rusty Russell90ab5ee2012-01-13 09:32:20 +103062static bool share_irq;
Jarod Wilson1beef3c2010-07-26 20:31:45 -030063static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
Rusty Russell90ab5ee2012-01-13 09:32:20 +103064static bool txsense; /* 0 = active high, 1 = active low */
Jarod Wilson1beef3c2010-07-26 20:31:45 -030065
Jarod Wilson1beef3c2010-07-26 20:31:45 -030066/* forward declarations */
Sean Young0a847632016-11-21 19:55:52 -020067static void send_pulse_irdeo(unsigned int length, ktime_t edge);
68static void send_space_irdeo(void);
Sean Youngb66db532016-11-21 19:55:51 -020069#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Sean Young0a847632016-11-21 19:55:52 -020070static void send_pulse_homebrew(unsigned int length, ktime_t edge);
71static void send_space_homebrew(void);
Sean Youngb66db532016-11-21 19:55:51 -020072#endif
Jarod Wilson1beef3c2010-07-26 20:31:45 -030073
Sean Youngb66db532016-11-21 19:55:51 -020074static struct serial_ir_hw hardware[] = {
75 [IR_HOMEBREW] = {
76 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_HOMEBREW].lock),
77 .signal_pin = UART_MSR_DCD,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030078 .signal_pin_change = UART_MSR_DDCD,
79 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
80 .off = (UART_MCR_RTS | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -020081#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Jarod Wilson1beef3c2010-07-26 20:31:45 -030082 .send_pulse = send_pulse_homebrew,
83 .send_space = send_space_homebrew,
Sean Youngb66db532016-11-21 19:55:51 -020084 .set_send_carrier = true,
85 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030086#endif
87 },
88
Sean Youngb66db532016-11-21 19:55:51 -020089 [IR_IRDEO] = {
90 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_IRDEO].lock),
91 .signal_pin = UART_MSR_DSR,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030092 .signal_pin_change = UART_MSR_DDSR,
93 .on = UART_MCR_OUT2,
94 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -020095 .send_pulse = send_pulse_irdeo,
96 .send_space = send_space_irdeo,
97 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030098 },
99
Sean Youngb66db532016-11-21 19:55:51 -0200100 [IR_IRDEO_REMOTE] = {
101 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_IRDEO_REMOTE].lock),
102 .signal_pin = UART_MSR_DSR,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300103 .signal_pin_change = UART_MSR_DDSR,
104 .on = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
105 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -0200106 .send_pulse = send_pulse_irdeo,
107 .send_space = send_space_irdeo,
108 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300109 },
110
Sean Youngb66db532016-11-21 19:55:51 -0200111 [IR_ANIMAX] = {
112 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_ANIMAX].lock),
113 .signal_pin = UART_MSR_DCD,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300114 .signal_pin_change = UART_MSR_DDCD,
115 .on = 0,
116 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300117 },
118
Sean Youngb66db532016-11-21 19:55:51 -0200119 [IR_IGOR] = {
120 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_IGOR].lock),
121 .signal_pin = UART_MSR_DSR,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300122 .signal_pin_change = UART_MSR_DDSR,
123 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
124 .off = (UART_MCR_RTS | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -0200125#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300126 .send_pulse = send_pulse_homebrew,
127 .send_space = send_space_homebrew,
Sean Youngb66db532016-11-21 19:55:51 -0200128 .set_send_carrier = true,
129 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300130#endif
131 },
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300132};
133
134#define RS_ISR_PASS_LIMIT 256
135
Sean Youngb66db532016-11-21 19:55:51 -0200136struct serial_ir {
137 ktime_t lastkt;
138 struct rc_dev *rcdev;
139 struct platform_device *pdev;
Sean Young2940c7e2016-12-02 15:16:11 -0200140 struct timer_list timeout_timer;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300141
Sean Youngfce4b372017-08-23 11:06:04 -0400142 unsigned int carrier;
Sean Youngb66db532016-11-21 19:55:51 -0200143 unsigned int duty_cycle;
Sean Youngb66db532016-11-21 19:55:51 -0200144};
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300145
Sean Youngb66db532016-11-21 19:55:51 -0200146static struct serial_ir serial_ir;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300147
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300148/* fetch serial input packet (1 byte) from register offset */
149static u8 sinp(int offset)
150{
Heba Aamerf3a9d7e2015-01-26 10:21:09 -0300151 if (iommap)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300152 /* the register is memory-mapped */
153 offset <<= ioshift;
154
155 return inb(io + offset);
156}
157
158/* write serial output packet (1 byte) of value to register offset */
159static void soutp(int offset, u8 value)
160{
Heba Aamerf3a9d7e2015-01-26 10:21:09 -0300161 if (iommap)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300162 /* the register is memory-mapped */
163 offset <<= ioshift;
164
165 outb(value, io + offset);
166}
167
168static void on(void)
169{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300170 if (txsense)
171 soutp(UART_MCR, hardware[type].off);
172 else
173 soutp(UART_MCR, hardware[type].on);
174}
175
176static void off(void)
177{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300178 if (txsense)
179 soutp(UART_MCR, hardware[type].on);
180 else
181 soutp(UART_MCR, hardware[type].off);
182}
183
Sean Young0a847632016-11-21 19:55:52 -0200184static void send_pulse_irdeo(unsigned int length, ktime_t target)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300185{
Sean Young0a847632016-11-21 19:55:52 -0200186 long rawbits;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300187 int i;
188 unsigned char output;
189 unsigned char chunk, shifted;
190
191 /* how many bits have to be sent ? */
192 rawbits = length * 1152 / 10000;
Sean Youngb66db532016-11-21 19:55:51 -0200193 if (serial_ir.duty_cycle > 50)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300194 chunk = 3;
195 else
196 chunk = 1;
197 for (i = 0, output = 0x7f; rawbits > 0; rawbits -= 3) {
198 shifted = chunk << (i * 3);
199 shifted >>= 1;
200 output &= (~shifted);
201 i++;
202 if (i == 3) {
203 soutp(UART_TX, output);
204 while (!(sinp(UART_LSR) & UART_LSR_THRE))
205 ;
206 output = 0x7f;
207 i = 0;
208 }
209 }
210 if (i != 0) {
211 soutp(UART_TX, output);
212 while (!(sinp(UART_LSR) & UART_LSR_TEMT))
213 ;
214 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300215}
216
Sean Young0a847632016-11-21 19:55:52 -0200217static void send_space_irdeo(void)
Sean Youngb66db532016-11-21 19:55:51 -0200218{
Sean Youngb66db532016-11-21 19:55:51 -0200219}
220
221#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Sean Young0a847632016-11-21 19:55:52 -0200222static void send_pulse_homebrew_softcarrier(unsigned int length, ktime_t edge)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300223{
Sean Young0a847632016-11-21 19:55:52 -0200224 ktime_t now, target = ktime_add_us(edge, length);
225 /*
226 * delta should never exceed 4 seconds and on m68k
227 * ndelay(s64) does not compile; so use s32 rather than s64.
228 */
229 s32 delta;
Sean Youngfce4b372017-08-23 11:06:04 -0400230 unsigned int pulse, space;
231
232 /* Ensure the dividend fits into 32 bit */
233 pulse = DIV_ROUND_CLOSEST(serial_ir.duty_cycle * (NSEC_PER_SEC / 100),
234 serial_ir.carrier);
235 space = DIV_ROUND_CLOSEST((100 - serial_ir.duty_cycle) *
236 (NSEC_PER_SEC / 100), serial_ir.carrier);
Gulsah Kose5ad6ae12014-09-21 01:20:44 +0300237
Sean Young0a847632016-11-21 19:55:52 -0200238 for (;;) {
239 now = ktime_get();
240 if (ktime_compare(now, target) >= 0)
241 break;
242 on();
Sean Youngfce4b372017-08-23 11:06:04 -0400243 edge = ktime_add_ns(edge, pulse);
Sean Young0a847632016-11-21 19:55:52 -0200244 delta = ktime_to_ns(ktime_sub(edge, now));
245 if (delta > 0)
246 ndelay(delta);
247 now = ktime_get();
248 off();
249 if (ktime_compare(now, target) >= 0)
250 break;
Sean Youngfce4b372017-08-23 11:06:04 -0400251 edge = ktime_add_ns(edge, space);
Sean Young0a847632016-11-21 19:55:52 -0200252 delta = ktime_to_ns(ktime_sub(edge, now));
253 if (delta > 0)
254 ndelay(delta);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300255 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300256}
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300257
Sean Young0a847632016-11-21 19:55:52 -0200258static void send_pulse_homebrew(unsigned int length, ktime_t edge)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300259{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300260 if (softcarrier)
Sean Young0a847632016-11-21 19:55:52 -0200261 send_pulse_homebrew_softcarrier(length, edge);
262 else
263 on();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300264}
265
Sean Young0a847632016-11-21 19:55:52 -0200266static void send_space_homebrew(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300267{
268 off();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300269}
Sean Youngb66db532016-11-21 19:55:51 -0200270#endif
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300271
Sean Youngb66db532016-11-21 19:55:51 -0200272static void frbwrite(unsigned int l, bool is_pulse)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300273{
274 /* simple noise filter */
Sean Youngb66db532016-11-21 19:55:51 -0200275 static unsigned int ptr, pulse, space;
276 DEFINE_IR_RAW_EVENT(ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300277
Sean Youngb66db532016-11-21 19:55:51 -0200278 if (ptr > 0 && is_pulse) {
279 pulse += l;
280 if (pulse > 250000) {
281 ev.duration = space;
282 ev.pulse = false;
283 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
284 ev.duration = pulse;
285 ev.pulse = true;
286 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300287 ptr = 0;
288 pulse = 0;
289 }
290 return;
291 }
Sean Youngb66db532016-11-21 19:55:51 -0200292 if (!is_pulse) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300293 if (ptr == 0) {
Sean Youngb66db532016-11-21 19:55:51 -0200294 if (l > 20000000) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300295 space = l;
296 ptr++;
297 return;
298 }
299 } else {
Sean Youngb66db532016-11-21 19:55:51 -0200300 if (l > 20000000) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300301 space += pulse;
Sean Youngb66db532016-11-21 19:55:51 -0200302 if (space > IR_MAX_DURATION)
303 space = IR_MAX_DURATION;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300304 space += l;
Sean Youngb66db532016-11-21 19:55:51 -0200305 if (space > IR_MAX_DURATION)
306 space = IR_MAX_DURATION;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300307 pulse = 0;
308 return;
309 }
Sean Youngb66db532016-11-21 19:55:51 -0200310
311 ev.duration = space;
312 ev.pulse = false;
313 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
314 ev.duration = pulse;
315 ev.pulse = true;
316 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300317 ptr = 0;
318 pulse = 0;
319 }
320 }
Sean Youngb66db532016-11-21 19:55:51 -0200321
322 ev.duration = l;
323 ev.pulse = is_pulse;
324 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300325}
326
Sean Youngb66db532016-11-21 19:55:51 -0200327static irqreturn_t serial_ir_irq_handler(int i, void *blah)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300328{
Arnd Bergmann84595032015-11-25 13:11:55 -0200329 ktime_t kt;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300330 int counter, dcd;
331 u8 status;
Arnd Bergmann84595032015-11-25 13:11:55 -0200332 ktime_t delkt;
Sean Youngb66db532016-11-21 19:55:51 -0200333 unsigned int data;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300334 static int last_dcd = -1;
335
336 if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
337 /* not our interrupt */
338 return IRQ_NONE;
339 }
340
341 counter = 0;
342 do {
343 counter++;
344 status = sinp(UART_MSR);
345 if (counter > RS_ISR_PASS_LIMIT) {
Sean Youngb66db532016-11-21 19:55:51 -0200346 dev_err(&serial_ir.pdev->dev, "Trapped in interrupt");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300347 break;
348 }
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200349 if ((status & hardware[type].signal_pin_change) &&
350 sense != -1) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300351 /* get current time */
Arnd Bergmann84595032015-11-25 13:11:55 -0200352 kt = ktime_get();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300353
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300354 /*
Sean Youngb66db532016-11-21 19:55:51 -0200355 * The driver needs to know if your receiver is
356 * active high or active low, or the space/pulse
357 * sense could be inverted.
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300358 */
359
Sean Youngb66db532016-11-21 19:55:51 -0200360 /* calc time since last interrupt in nanoseconds */
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300361 dcd = (status & hardware[type].signal_pin) ? 1 : 0;
362
363 if (dcd == last_dcd) {
Sean Youngb66db532016-11-21 19:55:51 -0200364 dev_err(&serial_ir.pdev->dev,
365 "ignoring spike: %d %d %lldns %lldns\n",
366 dcd, sense, ktime_to_ns(kt),
367 ktime_to_ns(serial_ir.lastkt));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300368 continue;
369 }
370
Sean Youngb66db532016-11-21 19:55:51 -0200371 delkt = ktime_sub(kt, serial_ir.lastkt);
Arnd Bergmann84595032015-11-25 13:11:55 -0200372 if (ktime_compare(delkt, ktime_set(15, 0)) > 0) {
Sean Youngb66db532016-11-21 19:55:51 -0200373 data = IR_MAX_DURATION; /* really long time */
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200374 if (!(dcd ^ sense)) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300375 /* sanity check */
Sean Youngb66db532016-11-21 19:55:51 -0200376 dev_err(&serial_ir.pdev->dev,
377 "dcd unexpected: %d %d %lldns %lldns\n",
378 dcd, sense, ktime_to_ns(kt),
379 ktime_to_ns(serial_ir.lastkt));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300380 /*
381 * detecting pulse while this
382 * MUST be a space!
383 */
384 sense = sense ? 0 : 1;
385 }
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200386 } else {
Sean Youngb66db532016-11-21 19:55:51 -0200387 data = ktime_to_ns(delkt);
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200388 }
Sean Youngb66db532016-11-21 19:55:51 -0200389 frbwrite(data, !(dcd ^ sense));
390 serial_ir.lastkt = kt;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300391 last_dcd = dcd;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300392 }
393 } while (!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */
Sean Young2940c7e2016-12-02 15:16:11 -0200394
395 mod_timer(&serial_ir.timeout_timer,
396 jiffies + nsecs_to_jiffies(serial_ir.rcdev->timeout));
397
398 ir_raw_event_handle(serial_ir.rcdev);
399
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300400 return IRQ_HANDLED;
401}
402
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300403static int hardware_init_port(void)
404{
405 u8 scratch, scratch2, scratch3;
406
407 /*
408 * This is a simple port existence test, borrowed from the autoconfig
Mauro Carvalho Chehabc60b4082016-11-22 06:17:44 -0200409 * function in drivers/tty/serial/8250/8250_port.c
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300410 */
411 scratch = sinp(UART_IER);
412 soutp(UART_IER, 0);
413#ifdef __i386__
414 outb(0xff, 0x080);
415#endif
416 scratch2 = sinp(UART_IER) & 0x0f;
417 soutp(UART_IER, 0x0f);
418#ifdef __i386__
419 outb(0x00, 0x080);
420#endif
421 scratch3 = sinp(UART_IER) & 0x0f;
422 soutp(UART_IER, scratch);
423 if (scratch2 != 0 || scratch3 != 0x0f) {
424 /* we fail, there's nothing here */
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300425 pr_err("port existence test failed, cannot continue\n");
Ben Hutchings9b98d602011-11-16 01:53:35 -0300426 return -ENODEV;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300427 }
428
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300429 /* Set DLAB 0. */
430 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
431
432 /* First of all, disable all interrupts */
433 soutp(UART_IER, sinp(UART_IER) &
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200434 (~(UART_IER_MSI | UART_IER_RLSI | UART_IER_THRI | UART_IER_RDI)));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300435
436 /* Clear registers. */
437 sinp(UART_LSR);
438 sinp(UART_RX);
439 sinp(UART_IIR);
440 sinp(UART_MSR);
441
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300442 /* Set line for power source */
443 off();
444
445 /* Clear registers again to be sure. */
446 sinp(UART_LSR);
447 sinp(UART_RX);
448 sinp(UART_IIR);
449 sinp(UART_MSR);
450
451 switch (type) {
Sean Youngb66db532016-11-21 19:55:51 -0200452 case IR_IRDEO:
453 case IR_IRDEO_REMOTE:
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300454 /* setup port to 7N1 @ 115200 Baud */
455 /* 7N1+start = 9 bits at 115200 ~ 3 bits at 38kHz */
456
457 /* Set DLAB 1. */
458 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
459 /* Set divisor to 1 => 115200 Baud */
460 soutp(UART_DLM, 0);
461 soutp(UART_DLL, 1);
462 /* Set DLAB 0 + 7N1 */
463 soutp(UART_LCR, UART_LCR_WLEN7);
464 /* THR interrupt already disabled at this point */
465 break;
466 default:
467 break;
468 }
469
470 return 0;
471}
472
Sean Young2940c7e2016-12-02 15:16:11 -0200473static void serial_ir_timeout(unsigned long arg)
474{
475 DEFINE_IR_RAW_EVENT(ev);
476
477 ev.timeout = true;
478 ev.duration = serial_ir.rcdev->timeout;
479 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
480 ir_raw_event_handle(serial_ir.rcdev);
481}
482
Sean Young02656342017-02-25 08:28:16 -0300483/* Needed by serial_ir_probe() */
484static int serial_ir_tx(struct rc_dev *dev, unsigned int *txbuf,
485 unsigned int count);
486static int serial_ir_tx_duty_cycle(struct rc_dev *dev, u32 cycle);
487static int serial_ir_tx_carrier(struct rc_dev *dev, u32 carrier);
488static int serial_ir_open(struct rc_dev *rcdev);
489static void serial_ir_close(struct rc_dev *rcdev);
490
Sean Youngb66db532016-11-21 19:55:51 -0200491static int serial_ir_probe(struct platform_device *dev)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300492{
Sean Young02656342017-02-25 08:28:16 -0300493 struct rc_dev *rcdev;
Jarod Wilsonc4b0afe2011-06-13 15:32:26 -0300494 int i, nlow, nhigh, result;
495
Sean Young02656342017-02-25 08:28:16 -0300496 rcdev = devm_rc_allocate_device(&dev->dev, RC_DRIVER_IR_RAW);
497 if (!rcdev)
498 return -ENOMEM;
499
500 if (hardware[type].send_pulse && hardware[type].send_space)
501 rcdev->tx_ir = serial_ir_tx;
502 if (hardware[type].set_send_carrier)
503 rcdev->s_tx_carrier = serial_ir_tx_carrier;
504 if (hardware[type].set_duty_cycle)
505 rcdev->s_tx_duty_cycle = serial_ir_tx_duty_cycle;
506
507 switch (type) {
508 case IR_HOMEBREW:
Sean Young518f4b22017-07-01 12:13:19 -0400509 rcdev->device_name = "Serial IR type home-brew";
Sean Young02656342017-02-25 08:28:16 -0300510 break;
511 case IR_IRDEO:
Sean Young518f4b22017-07-01 12:13:19 -0400512 rcdev->device_name = "Serial IR type IRdeo";
Sean Young02656342017-02-25 08:28:16 -0300513 break;
514 case IR_IRDEO_REMOTE:
Sean Young518f4b22017-07-01 12:13:19 -0400515 rcdev->device_name = "Serial IR type IRdeo remote";
Sean Young02656342017-02-25 08:28:16 -0300516 break;
517 case IR_ANIMAX:
Sean Young518f4b22017-07-01 12:13:19 -0400518 rcdev->device_name = "Serial IR type AnimaX";
Sean Young02656342017-02-25 08:28:16 -0300519 break;
520 case IR_IGOR:
Sean Young518f4b22017-07-01 12:13:19 -0400521 rcdev->device_name = "Serial IR type IgorPlug";
Sean Young02656342017-02-25 08:28:16 -0300522 break;
523 }
524
525 rcdev->input_phys = KBUILD_MODNAME "/input0";
526 rcdev->input_id.bustype = BUS_HOST;
527 rcdev->input_id.vendor = 0x0001;
528 rcdev->input_id.product = 0x0001;
529 rcdev->input_id.version = 0x0100;
530 rcdev->open = serial_ir_open;
531 rcdev->close = serial_ir_close;
532 rcdev->dev.parent = &serial_ir.pdev->dev;
Sean Young6d741bf2017-08-07 16:20:58 -0400533 rcdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
Sean Young02656342017-02-25 08:28:16 -0300534 rcdev->driver_name = KBUILD_MODNAME;
535 rcdev->map_name = RC_MAP_RC6_MCE;
536 rcdev->min_timeout = 1;
537 rcdev->timeout = IR_DEFAULT_TIMEOUT;
538 rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
539 rcdev->rx_resolution = 250000;
540
541 serial_ir.rcdev = rcdev;
542
543 setup_timer(&serial_ir.timeout_timer, serial_ir_timeout,
544 (unsigned long)&serial_ir);
545
Sean Youngb66db532016-11-21 19:55:51 -0200546 result = devm_request_irq(&dev->dev, irq, serial_ir_irq_handler,
547 share_irq ? IRQF_SHARED : 0,
548 KBUILD_MODNAME, &hardware);
Ben Hutchingsaffc9a02011-11-16 01:54:04 -0300549 if (result < 0) {
550 if (result == -EBUSY)
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300551 dev_err(&dev->dev, "IRQ %d busy\n", irq);
Ben Hutchingsaffc9a02011-11-16 01:54:04 -0300552 else if (result == -EINVAL)
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300553 dev_err(&dev->dev, "Bad irq number or handler\n");
Ben Hutchingsaffc9a02011-11-16 01:54:04 -0300554 return result;
555 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300556
557 /* Reserve io region. */
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200558 if ((iommap &&
559 (devm_request_mem_region(&dev->dev, iommap, 8 << ioshift,
560 KBUILD_MODNAME) == NULL)) ||
561 (!iommap && (devm_request_region(&dev->dev, io, 8,
562 KBUILD_MODNAME) == NULL))) {
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300563 dev_err(&dev->dev, "port %04x already in use\n", io);
564 dev_warn(&dev->dev, "use 'setserial /dev/ttySX uart none'\n");
565 dev_warn(&dev->dev,
566 "or compile the serial port driver as module and\n");
567 dev_warn(&dev->dev, "make sure this module is loaded first\n");
Himangi Saraogi56a65a12014-07-03 16:38:40 -0300568 return -EBUSY;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300569 }
570
Ben Hutchings9b98d602011-11-16 01:53:35 -0300571 result = hardware_init_port();
572 if (result < 0)
Himangi Saraogi56a65a12014-07-03 16:38:40 -0300573 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300574
575 /* Initialize pulse/space widths */
Sean Youngfce4b372017-08-23 11:06:04 -0400576 serial_ir.duty_cycle = 50;
577 serial_ir.carrier = 38000;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300578
579 /* If pin is high, then this must be an active low receiver. */
580 if (sense == -1) {
581 /* wait 1/2 sec for the power supply */
582 msleep(500);
583
584 /*
585 * probe 9 times every 0.04s, collect "votes" for
586 * active high/low
587 */
588 nlow = 0;
589 nhigh = 0;
590 for (i = 0; i < 9; i++) {
591 if (sinp(UART_MSR) & hardware[type].signal_pin)
592 nlow++;
593 else
594 nhigh++;
595 msleep(40);
596 }
Haneen Mohammed8126e172015-03-13 20:46:57 +0300597 sense = nlow >= nhigh ? 1 : 0;
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300598 dev_info(&dev->dev, "auto-detected active %s receiver\n",
599 sense ? "low" : "high");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300600 } else
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300601 dev_info(&dev->dev, "Manually using active %s receiver\n",
602 sense ? "low" : "high");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300603
Maciek Borzecki4b4c7a12015-09-04 17:04:05 -0300604 dev_dbg(&dev->dev, "Interrupt %d, port %04x obtained\n", irq, io);
Sean Young02656342017-02-25 08:28:16 -0300605
606 return devm_rc_register_device(&dev->dev, rcdev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300607}
608
Sean Youngb66db532016-11-21 19:55:51 -0200609static int serial_ir_open(struct rc_dev *rcdev)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300610{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300611 unsigned long flags;
612
613 /* initialize timestamp */
Sean Youngb66db532016-11-21 19:55:51 -0200614 serial_ir.lastkt = ktime_get();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300615
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300616 spin_lock_irqsave(&hardware[type].lock, flags);
617
618 /* Set DLAB 0. */
619 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
620
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200621 soutp(UART_IER, sinp(UART_IER) | UART_IER_MSI);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300622
623 spin_unlock_irqrestore(&hardware[type].lock, flags);
624
625 return 0;
626}
627
Sean Youngb66db532016-11-21 19:55:51 -0200628static void serial_ir_close(struct rc_dev *rcdev)
629{
630 unsigned long flags;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300631
632 spin_lock_irqsave(&hardware[type].lock, flags);
633
634 /* Set DLAB 0. */
635 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
636
637 /* First of all, disable all interrupts */
638 soutp(UART_IER, sinp(UART_IER) &
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200639 (~(UART_IER_MSI | UART_IER_RLSI | UART_IER_THRI | UART_IER_RDI)));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300640 spin_unlock_irqrestore(&hardware[type].lock, flags);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300641}
642
Sean Youngb66db532016-11-21 19:55:51 -0200643static int serial_ir_tx(struct rc_dev *dev, unsigned int *txbuf,
644 unsigned int count)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300645{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300646 unsigned long flags;
Sean Young0a847632016-11-21 19:55:52 -0200647 ktime_t edge;
648 s64 delta;
Sean Youngb66db532016-11-21 19:55:51 -0200649 int i;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300650
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300651 spin_lock_irqsave(&hardware[type].lock, flags);
Sean Youngb66db532016-11-21 19:55:51 -0200652 if (type == IR_IRDEO) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300653 /* DTR, RTS down */
654 on();
655 }
Sean Young0a847632016-11-21 19:55:52 -0200656
657 edge = ktime_get();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300658 for (i = 0; i < count; i++) {
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200659 if (i % 2)
Sean Young0a847632016-11-21 19:55:52 -0200660 hardware[type].send_space();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300661 else
Sean Young0a847632016-11-21 19:55:52 -0200662 hardware[type].send_pulse(txbuf[i], edge);
663
664 edge = ktime_add_us(edge, txbuf[i]);
665 delta = ktime_us_delta(edge, ktime_get());
666 if (delta > 25) {
667 spin_unlock_irqrestore(&hardware[type].lock, flags);
668 usleep_range(delta - 25, delta + 25);
669 spin_lock_irqsave(&hardware[type].lock, flags);
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200670 } else if (delta > 0) {
Sean Young0a847632016-11-21 19:55:52 -0200671 udelay(delta);
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200672 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300673 }
674 off();
675 spin_unlock_irqrestore(&hardware[type].lock, flags);
Sean Youngb66db532016-11-21 19:55:51 -0200676 return count;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300677}
678
Sean Youngb66db532016-11-21 19:55:51 -0200679static int serial_ir_tx_duty_cycle(struct rc_dev *dev, u32 cycle)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300680{
Sean Youngfce4b372017-08-23 11:06:04 -0400681 serial_ir.duty_cycle = cycle;
Sean Young0a847632016-11-21 19:55:52 -0200682 return 0;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300683}
684
Sean Youngb66db532016-11-21 19:55:51 -0200685static int serial_ir_tx_carrier(struct rc_dev *dev, u32 carrier)
686{
687 if (carrier > 500000 || carrier < 20000)
688 return -EINVAL;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300689
Sean Youngfce4b372017-08-23 11:06:04 -0400690 serial_ir.carrier = carrier;
Sean Young0a847632016-11-21 19:55:52 -0200691 return 0;
Sean Youngb66db532016-11-21 19:55:51 -0200692}
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300693
Sean Youngb66db532016-11-21 19:55:51 -0200694static int serial_ir_suspend(struct platform_device *dev,
695 pm_message_t state)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300696{
697 /* Set DLAB 0. */
698 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
699
700 /* Disable all interrupts */
701 soutp(UART_IER, sinp(UART_IER) &
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200702 (~(UART_IER_MSI | UART_IER_RLSI | UART_IER_THRI | UART_IER_RDI)));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300703
704 /* Clear registers. */
705 sinp(UART_LSR);
706 sinp(UART_RX);
707 sinp(UART_IIR);
708 sinp(UART_MSR);
709
710 return 0;
711}
712
Sean Youngb66db532016-11-21 19:55:51 -0200713static int serial_ir_resume(struct platform_device *dev)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300714{
715 unsigned long flags;
Ben Hutchings9b98d602011-11-16 01:53:35 -0300716 int result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300717
Ben Hutchings9b98d602011-11-16 01:53:35 -0300718 result = hardware_init_port();
719 if (result < 0)
720 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300721
722 spin_lock_irqsave(&hardware[type].lock, flags);
723 /* Enable Interrupt */
Sean Youngb66db532016-11-21 19:55:51 -0200724 serial_ir.lastkt = ktime_get();
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200725 soutp(UART_IER, sinp(UART_IER) | UART_IER_MSI);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300726 off();
727
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300728 spin_unlock_irqrestore(&hardware[type].lock, flags);
729
730 return 0;
731}
732
Sean Youngb66db532016-11-21 19:55:51 -0200733static struct platform_driver serial_ir_driver = {
734 .probe = serial_ir_probe,
735 .suspend = serial_ir_suspend,
736 .resume = serial_ir_resume,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300737 .driver = {
Sean Youngb66db532016-11-21 19:55:51 -0200738 .name = "serial_ir",
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300739 },
740};
741
Sean Youngb66db532016-11-21 19:55:51 -0200742static int __init serial_ir_init(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300743{
744 int result;
745
Sean Youngb66db532016-11-21 19:55:51 -0200746 result = platform_driver_register(&serial_ir_driver);
747 if (result)
Ben Hutchings9b98d602011-11-16 01:53:35 -0300748 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300749
Sean Youngb66db532016-11-21 19:55:51 -0200750 serial_ir.pdev = platform_device_alloc("serial_ir", 0);
751 if (!serial_ir.pdev) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300752 result = -ENOMEM;
753 goto exit_driver_unregister;
754 }
755
Sean Youngb66db532016-11-21 19:55:51 -0200756 result = platform_device_add(serial_ir.pdev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300757 if (result)
758 goto exit_device_put;
759
760 return 0;
761
762exit_device_put:
Sean Youngb66db532016-11-21 19:55:51 -0200763 platform_device_put(serial_ir.pdev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300764exit_driver_unregister:
Sean Youngb66db532016-11-21 19:55:51 -0200765 platform_driver_unregister(&serial_ir_driver);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300766 return result;
767}
768
Sean Youngb66db532016-11-21 19:55:51 -0200769static void serial_ir_exit(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300770{
Sean Youngb66db532016-11-21 19:55:51 -0200771 platform_device_unregister(serial_ir.pdev);
772 platform_driver_unregister(&serial_ir_driver);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300773}
774
Sean Youngb66db532016-11-21 19:55:51 -0200775static int __init serial_ir_init_module(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300776{
777 int result;
778
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300779 switch (type) {
Sean Youngb66db532016-11-21 19:55:51 -0200780 case IR_HOMEBREW:
781 case IR_IRDEO:
782 case IR_IRDEO_REMOTE:
783 case IR_ANIMAX:
784 case IR_IGOR:
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300785 /* if nothing specified, use ttyS0/com1 and irq 4 */
786 io = io ? io : 0x3f8;
787 irq = irq ? irq : 4;
788 break;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300789 default:
Ben Hutchings9105b8b2011-11-16 01:49:41 -0300790 return -EINVAL;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300791 }
792 if (!softcarrier) {
793 switch (type) {
Sean Youngb66db532016-11-21 19:55:51 -0200794 case IR_HOMEBREW:
795 case IR_IGOR:
796 hardware[type].set_send_carrier = false;
797 hardware[type].set_duty_cycle = false;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300798 break;
799 }
800 }
801
Paul Bolle895507c2012-10-14 15:50:11 -0300802 /* make sure sense is either -1, 0, or 1 */
803 if (sense != -1)
804 sense = !!sense;
805
Sean Youngb66db532016-11-21 19:55:51 -0200806 result = serial_ir_init();
Sean Youngb66db532016-11-21 19:55:51 -0200807 if (!result)
808 return 0;
Sean Young02656342017-02-25 08:28:16 -0300809
Sean Youngb66db532016-11-21 19:55:51 -0200810 serial_ir_exit();
811 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300812}
813
Sean Youngb66db532016-11-21 19:55:51 -0200814static void __exit serial_ir_exit_module(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300815{
Sean Young2940c7e2016-12-02 15:16:11 -0200816 del_timer_sync(&serial_ir.timeout_timer);
Sean Youngb66db532016-11-21 19:55:51 -0200817 serial_ir_exit();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300818}
819
Sean Youngb66db532016-11-21 19:55:51 -0200820module_init(serial_ir_init_module);
821module_exit(serial_ir_exit_module);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300822
823MODULE_DESCRIPTION("Infra-red receiver driver for serial ports.");
Sean Youngb66db532016-11-21 19:55:51 -0200824MODULE_AUTHOR("Ralph Metzler, Trent Piepho, Ben Pfaff, Christoph Bartelmus, Andrei Tanas");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300825MODULE_LICENSE("GPL");
826
Sean Youngb66db532016-11-21 19:55:51 -0200827module_param(type, int, 0444);
828MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo, 2 = IRdeo Remote, 3 = AnimaX, 4 = IgorPlug");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300829
David Howells5a8fc6a32017-04-04 16:54:24 +0100830module_param_hw(io, int, ioport, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300831MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
832
833/* some architectures (e.g. intel xscale) have memory mapped registers */
Linus Torvalds291b38a2017-05-10 19:13:03 -0700834module_param_hw(iommap, ulong, other, 0444);
Sean Youngb66db532016-11-21 19:55:51 -0200835MODULE_PARM_DESC(iommap, "physical base for memory mapped I/O (0 = no memory mapped io)");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300836
837/*
838 * some architectures (e.g. intel xscale) align the 8bit serial registers
839 * on 32bit word boundaries.
Justin P. Mattockb47acf22012-03-05 11:49:26 -0300840 * See linux-kernel/drivers/tty/serial/8250/8250.c serial_in()/out()
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300841 */
David Howells5a8fc6a32017-04-04 16:54:24 +0100842module_param_hw(ioshift, int, other, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300843MODULE_PARM_DESC(ioshift, "shift I/O register offset (0 = no shift)");
844
David Howells5a8fc6a32017-04-04 16:54:24 +0100845module_param_hw(irq, int, irq, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300846MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
847
David Howells5a8fc6a32017-04-04 16:54:24 +0100848module_param_hw(share_irq, bool, other, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300849MODULE_PARM_DESC(share_irq, "Share interrupts (0 = off, 1 = on)");
850
Sean Youngb66db532016-11-21 19:55:51 -0200851module_param(sense, int, 0444);
852MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit (0 = active high, 1 = active low )");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300853
Sean Youngb66db532016-11-21 19:55:51 -0200854#ifdef CONFIG_IR_SERIAL_TRANSMITTER
855module_param(txsense, bool, 0444);
856MODULE_PARM_DESC(txsense, "Sense of transmitter circuit (0 = active high, 1 = active low )");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300857#endif
858
Sean Youngb66db532016-11-21 19:55:51 -0200859module_param(softcarrier, bool, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300860MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");