blob: d77507ba0fb58293bd409410bdf76e6808f6c1c8 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Jarod Wilson1beef3c2010-07-26 20:31:45 -03002/*
Sean Youngfa5dc29c2016-11-21 19:55:53 -02003 * serial_ir.c
Jarod Wilson1beef3c2010-07-26 20:31:45 -03004 *
Sean Youngfa5dc29c2016-11-21 19:55:53 -02005 * serial_ir - Device driver that records pulse- and pause-lengths
Jarod Wilson1beef3c2010-07-26 20:31:45 -03006 * (space-lengths) between DDCD event on a serial port.
7 *
8 * Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
9 * Copyright (C) 1998 Trent Piepho <xyzzy@u.washington.edu>
10 * Copyright (C) 1998 Ben Pfaff <blp@gnu.org>
11 * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
12 * Copyright (C) 2007 Andrei Tanas <andrei@tanas.ca> (suspend/resume support)
Sean Youngb66db532016-11-21 19:55:51 -020013 * Copyright (C) 2016 Sean Young <sean@mess.org> (port to rc-core)
Jarod Wilson1beef3c2010-07-26 20:31:45 -030014 */
15
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -030016#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
Jarod Wilson1beef3c2010-07-26 20:31:45 -030018#include <linux/module.h>
19#include <linux/errno.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030020#include <linux/interrupt.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030021#include <linux/kernel.h>
22#include <linux/serial_reg.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030023#include <linux/types.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030024#include <linux/delay.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030025#include <linux/platform_device.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030026#include <linux/spinlock.h>
Sean Youngb66db532016-11-21 19:55:51 -020027#include <media/rc-core.h>
Jarod Wilson1beef3c2010-07-26 20:31:45 -030028
Sean Youngb66db532016-11-21 19:55:51 -020029struct serial_ir_hw {
Jarod Wilson1beef3c2010-07-26 20:31:45 -030030 int signal_pin;
31 int signal_pin_change;
32 u8 on;
33 u8 off;
Sean Youngb66db532016-11-21 19:55:51 -020034 unsigned set_send_carrier:1;
35 unsigned set_duty_cycle:1;
Sean Young0a847632016-11-21 19:55:52 -020036 void (*send_pulse)(unsigned int length, ktime_t edge);
37 void (*send_space)(void);
Jarod Wilson1beef3c2010-07-26 20:31:45 -030038 spinlock_t lock;
39};
40
Sean Youngb66db532016-11-21 19:55:51 -020041#define IR_HOMEBREW 0
42#define IR_IRDEO 1
43#define IR_IRDEO_REMOTE 2
44#define IR_ANIMAX 3
45#define IR_IGOR 4
Jarod Wilson1beef3c2010-07-26 20:31:45 -030046
Sean Youngb66db532016-11-21 19:55:51 -020047/* module parameters */
Jarod Wilson1beef3c2010-07-26 20:31:45 -030048static int type;
49static int io;
50static int irq;
Sean Young069f3b12017-02-13 20:53:23 -020051static ulong iommap;
Jarod Wilson1beef3c2010-07-26 20:31:45 -030052static int ioshift;
Heba Aamerf3a9d7e2015-01-26 10:21:09 -030053static bool softcarrier = true;
Rusty Russell90ab5ee2012-01-13 09:32:20 +103054static bool share_irq;
Jarod Wilson1beef3c2010-07-26 20:31:45 -030055static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
Rusty Russell90ab5ee2012-01-13 09:32:20 +103056static bool txsense; /* 0 = active high, 1 = active low */
Jarod Wilson1beef3c2010-07-26 20:31:45 -030057
Jarod Wilson1beef3c2010-07-26 20:31:45 -030058/* forward declarations */
Sean Young0a847632016-11-21 19:55:52 -020059static void send_pulse_irdeo(unsigned int length, ktime_t edge);
60static void send_space_irdeo(void);
Sean Youngb66db532016-11-21 19:55:51 -020061#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Sean Young0a847632016-11-21 19:55:52 -020062static void send_pulse_homebrew(unsigned int length, ktime_t edge);
63static void send_space_homebrew(void);
Sean Youngb66db532016-11-21 19:55:51 -020064#endif
Jarod Wilson1beef3c2010-07-26 20:31:45 -030065
Sean Youngb66db532016-11-21 19:55:51 -020066static struct serial_ir_hw hardware[] = {
67 [IR_HOMEBREW] = {
68 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_HOMEBREW].lock),
69 .signal_pin = UART_MSR_DCD,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030070 .signal_pin_change = UART_MSR_DDCD,
71 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
72 .off = (UART_MCR_RTS | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -020073#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Jarod Wilson1beef3c2010-07-26 20:31:45 -030074 .send_pulse = send_pulse_homebrew,
75 .send_space = send_space_homebrew,
Sean Youngb66db532016-11-21 19:55:51 -020076 .set_send_carrier = true,
77 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030078#endif
79 },
80
Sean Youngb66db532016-11-21 19:55:51 -020081 [IR_IRDEO] = {
82 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_IRDEO].lock),
83 .signal_pin = UART_MSR_DSR,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030084 .signal_pin_change = UART_MSR_DDSR,
85 .on = UART_MCR_OUT2,
86 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -020087 .send_pulse = send_pulse_irdeo,
88 .send_space = send_space_irdeo,
89 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030090 },
91
Sean Youngb66db532016-11-21 19:55:51 -020092 [IR_IRDEO_REMOTE] = {
93 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_IRDEO_REMOTE].lock),
94 .signal_pin = UART_MSR_DSR,
Jarod Wilson1beef3c2010-07-26 20:31:45 -030095 .signal_pin_change = UART_MSR_DDSR,
96 .on = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
97 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -020098 .send_pulse = send_pulse_irdeo,
99 .send_space = send_space_irdeo,
100 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300101 },
102
Sean Youngb66db532016-11-21 19:55:51 -0200103 [IR_ANIMAX] = {
104 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_ANIMAX].lock),
105 .signal_pin = UART_MSR_DCD,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300106 .signal_pin_change = UART_MSR_DDCD,
107 .on = 0,
108 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300109 },
110
Sean Youngb66db532016-11-21 19:55:51 -0200111 [IR_IGOR] = {
112 .lock = __SPIN_LOCK_UNLOCKED(hardware[IR_IGOR].lock),
113 .signal_pin = UART_MSR_DSR,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300114 .signal_pin_change = UART_MSR_DDSR,
115 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
116 .off = (UART_MCR_RTS | UART_MCR_OUT2),
Sean Youngb66db532016-11-21 19:55:51 -0200117#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300118 .send_pulse = send_pulse_homebrew,
119 .send_space = send_space_homebrew,
Sean Youngb66db532016-11-21 19:55:51 -0200120 .set_send_carrier = true,
121 .set_duty_cycle = true,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300122#endif
123 },
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300124};
125
126#define RS_ISR_PASS_LIMIT 256
127
Sean Youngb66db532016-11-21 19:55:51 -0200128struct serial_ir {
129 ktime_t lastkt;
130 struct rc_dev *rcdev;
131 struct platform_device *pdev;
Sean Young2940c7e2016-12-02 15:16:11 -0200132 struct timer_list timeout_timer;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300133
Sean Youngfce4b372017-08-23 11:06:04 -0400134 unsigned int carrier;
Sean Youngb66db532016-11-21 19:55:51 -0200135 unsigned int duty_cycle;
Sean Youngb66db532016-11-21 19:55:51 -0200136};
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300137
Sean Youngb66db532016-11-21 19:55:51 -0200138static struct serial_ir serial_ir;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300139
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300140/* fetch serial input packet (1 byte) from register offset */
141static u8 sinp(int offset)
142{
Heba Aamerf3a9d7e2015-01-26 10:21:09 -0300143 if (iommap)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300144 /* the register is memory-mapped */
145 offset <<= ioshift;
146
147 return inb(io + offset);
148}
149
150/* write serial output packet (1 byte) of value to register offset */
151static void soutp(int offset, u8 value)
152{
Heba Aamerf3a9d7e2015-01-26 10:21:09 -0300153 if (iommap)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300154 /* the register is memory-mapped */
155 offset <<= ioshift;
156
157 outb(value, io + offset);
158}
159
160static void on(void)
161{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300162 if (txsense)
163 soutp(UART_MCR, hardware[type].off);
164 else
165 soutp(UART_MCR, hardware[type].on);
166}
167
168static void off(void)
169{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300170 if (txsense)
171 soutp(UART_MCR, hardware[type].on);
172 else
173 soutp(UART_MCR, hardware[type].off);
174}
175
Sean Young0a847632016-11-21 19:55:52 -0200176static void send_pulse_irdeo(unsigned int length, ktime_t target)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300177{
Sean Young0a847632016-11-21 19:55:52 -0200178 long rawbits;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300179 int i;
180 unsigned char output;
181 unsigned char chunk, shifted;
182
183 /* how many bits have to be sent ? */
184 rawbits = length * 1152 / 10000;
Sean Youngb66db532016-11-21 19:55:51 -0200185 if (serial_ir.duty_cycle > 50)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300186 chunk = 3;
187 else
188 chunk = 1;
189 for (i = 0, output = 0x7f; rawbits > 0; rawbits -= 3) {
190 shifted = chunk << (i * 3);
191 shifted >>= 1;
192 output &= (~shifted);
193 i++;
194 if (i == 3) {
195 soutp(UART_TX, output);
196 while (!(sinp(UART_LSR) & UART_LSR_THRE))
197 ;
198 output = 0x7f;
199 i = 0;
200 }
201 }
202 if (i != 0) {
203 soutp(UART_TX, output);
204 while (!(sinp(UART_LSR) & UART_LSR_TEMT))
205 ;
206 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300207}
208
Sean Young0a847632016-11-21 19:55:52 -0200209static void send_space_irdeo(void)
Sean Youngb66db532016-11-21 19:55:51 -0200210{
Sean Youngb66db532016-11-21 19:55:51 -0200211}
212
213#ifdef CONFIG_IR_SERIAL_TRANSMITTER
Sean Young0a847632016-11-21 19:55:52 -0200214static void send_pulse_homebrew_softcarrier(unsigned int length, ktime_t edge)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300215{
Sean Young0a847632016-11-21 19:55:52 -0200216 ktime_t now, target = ktime_add_us(edge, length);
217 /*
218 * delta should never exceed 4 seconds and on m68k
219 * ndelay(s64) does not compile; so use s32 rather than s64.
220 */
221 s32 delta;
Sean Youngfce4b372017-08-23 11:06:04 -0400222 unsigned int pulse, space;
223
224 /* Ensure the dividend fits into 32 bit */
225 pulse = DIV_ROUND_CLOSEST(serial_ir.duty_cycle * (NSEC_PER_SEC / 100),
226 serial_ir.carrier);
227 space = DIV_ROUND_CLOSEST((100 - serial_ir.duty_cycle) *
228 (NSEC_PER_SEC / 100), serial_ir.carrier);
Gulsah Kose5ad6ae12014-09-21 01:20:44 +0300229
Sean Young0a847632016-11-21 19:55:52 -0200230 for (;;) {
231 now = ktime_get();
232 if (ktime_compare(now, target) >= 0)
233 break;
234 on();
Sean Youngfce4b372017-08-23 11:06:04 -0400235 edge = ktime_add_ns(edge, pulse);
Sean Young0a847632016-11-21 19:55:52 -0200236 delta = ktime_to_ns(ktime_sub(edge, now));
237 if (delta > 0)
238 ndelay(delta);
239 now = ktime_get();
240 off();
241 if (ktime_compare(now, target) >= 0)
242 break;
Sean Youngfce4b372017-08-23 11:06:04 -0400243 edge = ktime_add_ns(edge, space);
Sean Young0a847632016-11-21 19:55:52 -0200244 delta = ktime_to_ns(ktime_sub(edge, now));
245 if (delta > 0)
246 ndelay(delta);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300247 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300248}
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300249
Sean Young0a847632016-11-21 19:55:52 -0200250static void send_pulse_homebrew(unsigned int length, ktime_t edge)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300251{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300252 if (softcarrier)
Sean Young0a847632016-11-21 19:55:52 -0200253 send_pulse_homebrew_softcarrier(length, edge);
254 else
255 on();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300256}
257
Sean Young0a847632016-11-21 19:55:52 -0200258static void send_space_homebrew(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300259{
260 off();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300261}
Sean Youngb66db532016-11-21 19:55:51 -0200262#endif
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300263
Sean Youngb66db532016-11-21 19:55:51 -0200264static void frbwrite(unsigned int l, bool is_pulse)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300265{
266 /* simple noise filter */
Sean Youngb66db532016-11-21 19:55:51 -0200267 static unsigned int ptr, pulse, space;
Sean Young183e19f2018-08-21 15:57:52 -0400268 struct ir_raw_event ev = {};
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300269
Sean Youngb66db532016-11-21 19:55:51 -0200270 if (ptr > 0 && is_pulse) {
271 pulse += l;
272 if (pulse > 250000) {
273 ev.duration = space;
274 ev.pulse = false;
275 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
276 ev.duration = pulse;
277 ev.pulse = true;
278 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300279 ptr = 0;
280 pulse = 0;
281 }
282 return;
283 }
Sean Youngb66db532016-11-21 19:55:51 -0200284 if (!is_pulse) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300285 if (ptr == 0) {
Sean Youngb66db532016-11-21 19:55:51 -0200286 if (l > 20000000) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300287 space = l;
288 ptr++;
289 return;
290 }
291 } else {
Sean Youngb66db532016-11-21 19:55:51 -0200292 if (l > 20000000) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300293 space += pulse;
Sean Youngb66db532016-11-21 19:55:51 -0200294 if (space > IR_MAX_DURATION)
295 space = IR_MAX_DURATION;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300296 space += l;
Sean Youngb66db532016-11-21 19:55:51 -0200297 if (space > IR_MAX_DURATION)
298 space = IR_MAX_DURATION;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300299 pulse = 0;
300 return;
301 }
Sean Youngb66db532016-11-21 19:55:51 -0200302
303 ev.duration = space;
304 ev.pulse = false;
305 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
306 ev.duration = pulse;
307 ev.pulse = true;
308 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300309 ptr = 0;
310 pulse = 0;
311 }
312 }
Sean Youngb66db532016-11-21 19:55:51 -0200313
314 ev.duration = l;
315 ev.pulse = is_pulse;
316 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300317}
318
Sean Youngb66db532016-11-21 19:55:51 -0200319static irqreturn_t serial_ir_irq_handler(int i, void *blah)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300320{
Arnd Bergmann84595032015-11-25 13:11:55 -0200321 ktime_t kt;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300322 int counter, dcd;
323 u8 status;
Arnd Bergmann84595032015-11-25 13:11:55 -0200324 ktime_t delkt;
Sean Youngb66db532016-11-21 19:55:51 -0200325 unsigned int data;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300326 static int last_dcd = -1;
327
328 if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
329 /* not our interrupt */
330 return IRQ_NONE;
331 }
332
333 counter = 0;
334 do {
335 counter++;
336 status = sinp(UART_MSR);
337 if (counter > RS_ISR_PASS_LIMIT) {
Sean Youngb66db532016-11-21 19:55:51 -0200338 dev_err(&serial_ir.pdev->dev, "Trapped in interrupt");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300339 break;
340 }
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200341 if ((status & hardware[type].signal_pin_change) &&
342 sense != -1) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300343 /* get current time */
Arnd Bergmann84595032015-11-25 13:11:55 -0200344 kt = ktime_get();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300345
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300346 /*
Sean Youngb66db532016-11-21 19:55:51 -0200347 * The driver needs to know if your receiver is
348 * active high or active low, or the space/pulse
349 * sense could be inverted.
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300350 */
351
Sean Youngb66db532016-11-21 19:55:51 -0200352 /* calc time since last interrupt in nanoseconds */
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300353 dcd = (status & hardware[type].signal_pin) ? 1 : 0;
354
355 if (dcd == last_dcd) {
Bodo Eggerta04930b2019-12-26 22:28:45 +0100356 dev_dbg(&serial_ir.pdev->dev,
Sean Youngb66db532016-11-21 19:55:51 -0200357 "ignoring spike: %d %d %lldns %lldns\n",
358 dcd, sense, ktime_to_ns(kt),
359 ktime_to_ns(serial_ir.lastkt));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300360 continue;
361 }
362
Sean Youngb66db532016-11-21 19:55:51 -0200363 delkt = ktime_sub(kt, serial_ir.lastkt);
Arnd Bergmann84595032015-11-25 13:11:55 -0200364 if (ktime_compare(delkt, ktime_set(15, 0)) > 0) {
Sean Youngb66db532016-11-21 19:55:51 -0200365 data = IR_MAX_DURATION; /* really long time */
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200366 if (!(dcd ^ sense)) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300367 /* sanity check */
Sean Youngb66db532016-11-21 19:55:51 -0200368 dev_err(&serial_ir.pdev->dev,
369 "dcd unexpected: %d %d %lldns %lldns\n",
370 dcd, sense, ktime_to_ns(kt),
371 ktime_to_ns(serial_ir.lastkt));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300372 /*
373 * detecting pulse while this
374 * MUST be a space!
375 */
376 sense = sense ? 0 : 1;
377 }
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200378 } else {
Sean Youngb66db532016-11-21 19:55:51 -0200379 data = ktime_to_ns(delkt);
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200380 }
Sean Youngb66db532016-11-21 19:55:51 -0200381 frbwrite(data, !(dcd ^ sense));
382 serial_ir.lastkt = kt;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300383 last_dcd = dcd;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300384 }
385 } while (!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */
Sean Young2940c7e2016-12-02 15:16:11 -0200386
387 mod_timer(&serial_ir.timeout_timer,
388 jiffies + nsecs_to_jiffies(serial_ir.rcdev->timeout));
389
390 ir_raw_event_handle(serial_ir.rcdev);
391
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300392 return IRQ_HANDLED;
393}
394
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300395static int hardware_init_port(void)
396{
397 u8 scratch, scratch2, scratch3;
398
399 /*
400 * This is a simple port existence test, borrowed from the autoconfig
Mauro Carvalho Chehabc60b4082016-11-22 06:17:44 -0200401 * function in drivers/tty/serial/8250/8250_port.c
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300402 */
403 scratch = sinp(UART_IER);
404 soutp(UART_IER, 0);
405#ifdef __i386__
406 outb(0xff, 0x080);
407#endif
408 scratch2 = sinp(UART_IER) & 0x0f;
409 soutp(UART_IER, 0x0f);
410#ifdef __i386__
411 outb(0x00, 0x080);
412#endif
413 scratch3 = sinp(UART_IER) & 0x0f;
414 soutp(UART_IER, scratch);
415 if (scratch2 != 0 || scratch3 != 0x0f) {
416 /* we fail, there's nothing here */
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300417 pr_err("port existence test failed, cannot continue\n");
Ben Hutchings9b98d602011-11-16 01:53:35 -0300418 return -ENODEV;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300419 }
420
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300421 /* Set DLAB 0. */
422 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
423
424 /* First of all, disable all interrupts */
425 soutp(UART_IER, sinp(UART_IER) &
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200426 (~(UART_IER_MSI | UART_IER_RLSI | UART_IER_THRI | UART_IER_RDI)));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300427
428 /* Clear registers. */
429 sinp(UART_LSR);
430 sinp(UART_RX);
431 sinp(UART_IIR);
432 sinp(UART_MSR);
433
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300434 /* Set line for power source */
435 off();
436
437 /* Clear registers again to be sure. */
438 sinp(UART_LSR);
439 sinp(UART_RX);
440 sinp(UART_IIR);
441 sinp(UART_MSR);
442
443 switch (type) {
Sean Youngb66db532016-11-21 19:55:51 -0200444 case IR_IRDEO:
445 case IR_IRDEO_REMOTE:
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300446 /* setup port to 7N1 @ 115200 Baud */
447 /* 7N1+start = 9 bits at 115200 ~ 3 bits at 38kHz */
448
449 /* Set DLAB 1. */
450 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
451 /* Set divisor to 1 => 115200 Baud */
452 soutp(UART_DLM, 0);
453 soutp(UART_DLL, 1);
454 /* Set DLAB 0 + 7N1 */
455 soutp(UART_LCR, UART_LCR_WLEN7);
456 /* THR interrupt already disabled at this point */
457 break;
458 default:
459 break;
460 }
461
462 return 0;
463}
464
Kees Cook7dc31b82017-10-17 01:10:36 +0200465static void serial_ir_timeout(struct timer_list *unused)
Sean Young2940c7e2016-12-02 15:16:11 -0200466{
Sean Young183e19f2018-08-21 15:57:52 -0400467 struct ir_raw_event ev = {
468 .timeout = true,
469 .duration = serial_ir.rcdev->timeout
470 };
Sean Young2940c7e2016-12-02 15:16:11 -0200471 ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
472 ir_raw_event_handle(serial_ir.rcdev);
473}
474
Sean Young02656342017-02-25 08:28:16 -0300475/* Needed by serial_ir_probe() */
476static int serial_ir_tx(struct rc_dev *dev, unsigned int *txbuf,
477 unsigned int count);
478static int serial_ir_tx_duty_cycle(struct rc_dev *dev, u32 cycle);
479static int serial_ir_tx_carrier(struct rc_dev *dev, u32 carrier);
480static int serial_ir_open(struct rc_dev *rcdev);
481static void serial_ir_close(struct rc_dev *rcdev);
482
Sean Youngb66db532016-11-21 19:55:51 -0200483static int serial_ir_probe(struct platform_device *dev)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300484{
Sean Young02656342017-02-25 08:28:16 -0300485 struct rc_dev *rcdev;
Jarod Wilsonc4b0afe2011-06-13 15:32:26 -0300486 int i, nlow, nhigh, result;
487
Sean Young02656342017-02-25 08:28:16 -0300488 rcdev = devm_rc_allocate_device(&dev->dev, RC_DRIVER_IR_RAW);
489 if (!rcdev)
490 return -ENOMEM;
491
492 if (hardware[type].send_pulse && hardware[type].send_space)
493 rcdev->tx_ir = serial_ir_tx;
494 if (hardware[type].set_send_carrier)
495 rcdev->s_tx_carrier = serial_ir_tx_carrier;
496 if (hardware[type].set_duty_cycle)
497 rcdev->s_tx_duty_cycle = serial_ir_tx_duty_cycle;
498
499 switch (type) {
500 case IR_HOMEBREW:
Sean Young518f4b22017-07-01 12:13:19 -0400501 rcdev->device_name = "Serial IR type home-brew";
Sean Young02656342017-02-25 08:28:16 -0300502 break;
503 case IR_IRDEO:
Sean Young518f4b22017-07-01 12:13:19 -0400504 rcdev->device_name = "Serial IR type IRdeo";
Sean Young02656342017-02-25 08:28:16 -0300505 break;
506 case IR_IRDEO_REMOTE:
Sean Young518f4b22017-07-01 12:13:19 -0400507 rcdev->device_name = "Serial IR type IRdeo remote";
Sean Young02656342017-02-25 08:28:16 -0300508 break;
509 case IR_ANIMAX:
Sean Young518f4b22017-07-01 12:13:19 -0400510 rcdev->device_name = "Serial IR type AnimaX";
Sean Young02656342017-02-25 08:28:16 -0300511 break;
512 case IR_IGOR:
Sean Young518f4b22017-07-01 12:13:19 -0400513 rcdev->device_name = "Serial IR type IgorPlug";
Sean Young02656342017-02-25 08:28:16 -0300514 break;
515 }
516
517 rcdev->input_phys = KBUILD_MODNAME "/input0";
518 rcdev->input_id.bustype = BUS_HOST;
519 rcdev->input_id.vendor = 0x0001;
520 rcdev->input_id.product = 0x0001;
521 rcdev->input_id.version = 0x0100;
522 rcdev->open = serial_ir_open;
523 rcdev->close = serial_ir_close;
524 rcdev->dev.parent = &serial_ir.pdev->dev;
Sean Young6d741bf2017-08-07 16:20:58 -0400525 rcdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
Sean Young02656342017-02-25 08:28:16 -0300526 rcdev->driver_name = KBUILD_MODNAME;
527 rcdev->map_name = RC_MAP_RC6_MCE;
528 rcdev->min_timeout = 1;
529 rcdev->timeout = IR_DEFAULT_TIMEOUT;
530 rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
531 rcdev->rx_resolution = 250000;
532
533 serial_ir.rcdev = rcdev;
534
Kees Cook7dc31b82017-10-17 01:10:36 +0200535 timer_setup(&serial_ir.timeout_timer, serial_ir_timeout, 0);
Sean Young02656342017-02-25 08:28:16 -0300536
Sean Youngb66db532016-11-21 19:55:51 -0200537 result = devm_request_irq(&dev->dev, irq, serial_ir_irq_handler,
538 share_irq ? IRQF_SHARED : 0,
539 KBUILD_MODNAME, &hardware);
Ben Hutchingsaffc9a02011-11-16 01:54:04 -0300540 if (result < 0) {
541 if (result == -EBUSY)
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300542 dev_err(&dev->dev, "IRQ %d busy\n", irq);
Ben Hutchingsaffc9a02011-11-16 01:54:04 -0300543 else if (result == -EINVAL)
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300544 dev_err(&dev->dev, "Bad irq number or handler\n");
Ben Hutchingsaffc9a02011-11-16 01:54:04 -0300545 return result;
546 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300547
548 /* Reserve io region. */
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200549 if ((iommap &&
550 (devm_request_mem_region(&dev->dev, iommap, 8 << ioshift,
551 KBUILD_MODNAME) == NULL)) ||
552 (!iommap && (devm_request_region(&dev->dev, io, 8,
553 KBUILD_MODNAME) == NULL))) {
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300554 dev_err(&dev->dev, "port %04x already in use\n", io);
555 dev_warn(&dev->dev, "use 'setserial /dev/ttySX uart none'\n");
556 dev_warn(&dev->dev,
557 "or compile the serial port driver as module and\n");
558 dev_warn(&dev->dev, "make sure this module is loaded first\n");
Himangi Saraogi56a65a12014-07-03 16:38:40 -0300559 return -EBUSY;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300560 }
561
Ben Hutchings9b98d602011-11-16 01:53:35 -0300562 result = hardware_init_port();
563 if (result < 0)
Himangi Saraogi56a65a12014-07-03 16:38:40 -0300564 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300565
566 /* Initialize pulse/space widths */
Sean Youngfce4b372017-08-23 11:06:04 -0400567 serial_ir.duty_cycle = 50;
568 serial_ir.carrier = 38000;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300569
570 /* If pin is high, then this must be an active low receiver. */
571 if (sense == -1) {
572 /* wait 1/2 sec for the power supply */
573 msleep(500);
574
575 /*
576 * probe 9 times every 0.04s, collect "votes" for
577 * active high/low
578 */
579 nlow = 0;
580 nhigh = 0;
581 for (i = 0; i < 9; i++) {
582 if (sinp(UART_MSR) & hardware[type].signal_pin)
583 nlow++;
584 else
585 nhigh++;
586 msleep(40);
587 }
Haneen Mohammed8126e172015-03-13 20:46:57 +0300588 sense = nlow >= nhigh ? 1 : 0;
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300589 dev_info(&dev->dev, "auto-detected active %s receiver\n",
590 sense ? "low" : "high");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300591 } else
YAMANE Toshiakidf4f07b2012-11-08 15:55:09 -0300592 dev_info(&dev->dev, "Manually using active %s receiver\n",
593 sense ? "low" : "high");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300594
Maciek Borzecki4b4c7a12015-09-04 17:04:05 -0300595 dev_dbg(&dev->dev, "Interrupt %d, port %04x obtained\n", irq, io);
Sean Young02656342017-02-25 08:28:16 -0300596
597 return devm_rc_register_device(&dev->dev, rcdev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300598}
599
Sean Youngb66db532016-11-21 19:55:51 -0200600static int serial_ir_open(struct rc_dev *rcdev)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300601{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300602 unsigned long flags;
603
604 /* initialize timestamp */
Sean Youngb66db532016-11-21 19:55:51 -0200605 serial_ir.lastkt = ktime_get();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300606
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300607 spin_lock_irqsave(&hardware[type].lock, flags);
608
609 /* Set DLAB 0. */
610 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
611
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200612 soutp(UART_IER, sinp(UART_IER) | UART_IER_MSI);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300613
614 spin_unlock_irqrestore(&hardware[type].lock, flags);
615
616 return 0;
617}
618
Sean Youngb66db532016-11-21 19:55:51 -0200619static void serial_ir_close(struct rc_dev *rcdev)
620{
621 unsigned long flags;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300622
623 spin_lock_irqsave(&hardware[type].lock, flags);
624
625 /* Set DLAB 0. */
626 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
627
628 /* First of all, disable all interrupts */
629 soutp(UART_IER, sinp(UART_IER) &
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200630 (~(UART_IER_MSI | UART_IER_RLSI | UART_IER_THRI | UART_IER_RDI)));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300631 spin_unlock_irqrestore(&hardware[type].lock, flags);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300632}
633
Sean Youngb66db532016-11-21 19:55:51 -0200634static int serial_ir_tx(struct rc_dev *dev, unsigned int *txbuf,
635 unsigned int count)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300636{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300637 unsigned long flags;
Sean Young0a847632016-11-21 19:55:52 -0200638 ktime_t edge;
639 s64 delta;
Sean Youngb66db532016-11-21 19:55:51 -0200640 int i;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300641
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300642 spin_lock_irqsave(&hardware[type].lock, flags);
Sean Youngb66db532016-11-21 19:55:51 -0200643 if (type == IR_IRDEO) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300644 /* DTR, RTS down */
645 on();
646 }
Sean Young0a847632016-11-21 19:55:52 -0200647
648 edge = ktime_get();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300649 for (i = 0; i < count; i++) {
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200650 if (i % 2)
Sean Young0a847632016-11-21 19:55:52 -0200651 hardware[type].send_space();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300652 else
Sean Young0a847632016-11-21 19:55:52 -0200653 hardware[type].send_pulse(txbuf[i], edge);
654
655 edge = ktime_add_us(edge, txbuf[i]);
656 delta = ktime_us_delta(edge, ktime_get());
657 if (delta > 25) {
658 spin_unlock_irqrestore(&hardware[type].lock, flags);
659 usleep_range(delta - 25, delta + 25);
660 spin_lock_irqsave(&hardware[type].lock, flags);
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200661 } else if (delta > 0) {
Sean Young0a847632016-11-21 19:55:52 -0200662 udelay(delta);
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200663 }
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300664 }
665 off();
666 spin_unlock_irqrestore(&hardware[type].lock, flags);
Sean Youngb66db532016-11-21 19:55:51 -0200667 return count;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300668}
669
Sean Youngb66db532016-11-21 19:55:51 -0200670static int serial_ir_tx_duty_cycle(struct rc_dev *dev, u32 cycle)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300671{
Sean Youngfce4b372017-08-23 11:06:04 -0400672 serial_ir.duty_cycle = cycle;
Sean Young0a847632016-11-21 19:55:52 -0200673 return 0;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300674}
675
Sean Youngb66db532016-11-21 19:55:51 -0200676static int serial_ir_tx_carrier(struct rc_dev *dev, u32 carrier)
677{
678 if (carrier > 500000 || carrier < 20000)
679 return -EINVAL;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300680
Sean Youngfce4b372017-08-23 11:06:04 -0400681 serial_ir.carrier = carrier;
Sean Young0a847632016-11-21 19:55:52 -0200682 return 0;
Sean Youngb66db532016-11-21 19:55:51 -0200683}
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300684
Sean Youngb66db532016-11-21 19:55:51 -0200685static int serial_ir_suspend(struct platform_device *dev,
686 pm_message_t state)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300687{
688 /* Set DLAB 0. */
689 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
690
691 /* Disable all interrupts */
692 soutp(UART_IER, sinp(UART_IER) &
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200693 (~(UART_IER_MSI | UART_IER_RLSI | UART_IER_THRI | UART_IER_RDI)));
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300694
695 /* Clear registers. */
696 sinp(UART_LSR);
697 sinp(UART_RX);
698 sinp(UART_IIR);
699 sinp(UART_MSR);
700
701 return 0;
702}
703
Sean Youngb66db532016-11-21 19:55:51 -0200704static int serial_ir_resume(struct platform_device *dev)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300705{
706 unsigned long flags;
Ben Hutchings9b98d602011-11-16 01:53:35 -0300707 int result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300708
Ben Hutchings9b98d602011-11-16 01:53:35 -0300709 result = hardware_init_port();
710 if (result < 0)
711 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300712
713 spin_lock_irqsave(&hardware[type].lock, flags);
714 /* Enable Interrupt */
Sean Youngb66db532016-11-21 19:55:51 -0200715 serial_ir.lastkt = ktime_get();
Mauro Carvalho Chehaba6f6ad42016-11-22 05:46:14 -0200716 soutp(UART_IER, sinp(UART_IER) | UART_IER_MSI);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300717 off();
718
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300719 spin_unlock_irqrestore(&hardware[type].lock, flags);
720
721 return 0;
722}
723
Sean Youngb66db532016-11-21 19:55:51 -0200724static struct platform_driver serial_ir_driver = {
725 .probe = serial_ir_probe,
726 .suspend = serial_ir_suspend,
727 .resume = serial_ir_resume,
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300728 .driver = {
Sean Youngb66db532016-11-21 19:55:51 -0200729 .name = "serial_ir",
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300730 },
731};
732
Sean Youngb66db532016-11-21 19:55:51 -0200733static int __init serial_ir_init(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300734{
735 int result;
736
Sean Youngb66db532016-11-21 19:55:51 -0200737 result = platform_driver_register(&serial_ir_driver);
738 if (result)
Ben Hutchings9b98d602011-11-16 01:53:35 -0300739 return result;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300740
Sean Youngb66db532016-11-21 19:55:51 -0200741 serial_ir.pdev = platform_device_alloc("serial_ir", 0);
742 if (!serial_ir.pdev) {
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300743 result = -ENOMEM;
744 goto exit_driver_unregister;
745 }
746
Sean Youngb66db532016-11-21 19:55:51 -0200747 result = platform_device_add(serial_ir.pdev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300748 if (result)
749 goto exit_device_put;
750
751 return 0;
752
753exit_device_put:
Sean Youngb66db532016-11-21 19:55:51 -0200754 platform_device_put(serial_ir.pdev);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300755exit_driver_unregister:
Sean Youngb66db532016-11-21 19:55:51 -0200756 platform_driver_unregister(&serial_ir_driver);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300757 return result;
758}
759
Sean Youngb66db532016-11-21 19:55:51 -0200760static void serial_ir_exit(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300761{
Sean Youngb66db532016-11-21 19:55:51 -0200762 platform_device_unregister(serial_ir.pdev);
763 platform_driver_unregister(&serial_ir_driver);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300764}
765
Sean Youngb66db532016-11-21 19:55:51 -0200766static int __init serial_ir_init_module(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300767{
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300768 switch (type) {
Sean Youngb66db532016-11-21 19:55:51 -0200769 case IR_HOMEBREW:
770 case IR_IRDEO:
771 case IR_IRDEO_REMOTE:
772 case IR_ANIMAX:
773 case IR_IGOR:
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300774 /* if nothing specified, use ttyS0/com1 and irq 4 */
775 io = io ? io : 0x3f8;
776 irq = irq ? irq : 4;
777 break;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300778 default:
Ben Hutchings9105b8b2011-11-16 01:49:41 -0300779 return -EINVAL;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300780 }
781 if (!softcarrier) {
782 switch (type) {
Sean Youngb66db532016-11-21 19:55:51 -0200783 case IR_HOMEBREW:
784 case IR_IGOR:
785 hardware[type].set_send_carrier = false;
786 hardware[type].set_duty_cycle = false;
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300787 break;
788 }
789 }
790
Paul Bolle895507c2012-10-14 15:50:11 -0300791 /* make sure sense is either -1, 0, or 1 */
792 if (sense != -1)
793 sense = !!sense;
794
YueHaibing56cd26b2019-03-05 00:40:26 -0500795 return serial_ir_init();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300796}
797
Sean Youngb66db532016-11-21 19:55:51 -0200798static void __exit serial_ir_exit_module(void)
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300799{
Sean Young2940c7e2016-12-02 15:16:11 -0200800 del_timer_sync(&serial_ir.timeout_timer);
Sean Youngb66db532016-11-21 19:55:51 -0200801 serial_ir_exit();
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300802}
803
Sean Youngb66db532016-11-21 19:55:51 -0200804module_init(serial_ir_init_module);
805module_exit(serial_ir_exit_module);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300806
807MODULE_DESCRIPTION("Infra-red receiver driver for serial ports.");
Sean Youngb66db532016-11-21 19:55:51 -0200808MODULE_AUTHOR("Ralph Metzler, Trent Piepho, Ben Pfaff, Christoph Bartelmus, Andrei Tanas");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300809MODULE_LICENSE("GPL");
810
Sean Youngb66db532016-11-21 19:55:51 -0200811module_param(type, int, 0444);
812MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo, 2 = IRdeo Remote, 3 = AnimaX, 4 = IgorPlug");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300813
David Howells5a8fc6a32017-04-04 16:54:24 +0100814module_param_hw(io, int, ioport, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300815MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
816
817/* some architectures (e.g. intel xscale) have memory mapped registers */
Linus Torvalds291b38a2017-05-10 19:13:03 -0700818module_param_hw(iommap, ulong, other, 0444);
Sean Youngb66db532016-11-21 19:55:51 -0200819MODULE_PARM_DESC(iommap, "physical base for memory mapped I/O (0 = no memory mapped io)");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300820
821/*
822 * some architectures (e.g. intel xscale) align the 8bit serial registers
823 * on 32bit word boundaries.
Justin P. Mattockb47acf22012-03-05 11:49:26 -0300824 * See linux-kernel/drivers/tty/serial/8250/8250.c serial_in()/out()
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300825 */
David Howells5a8fc6a32017-04-04 16:54:24 +0100826module_param_hw(ioshift, int, other, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300827MODULE_PARM_DESC(ioshift, "shift I/O register offset (0 = no shift)");
828
David Howells5a8fc6a32017-04-04 16:54:24 +0100829module_param_hw(irq, int, irq, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300830MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
831
David Howells5a8fc6a32017-04-04 16:54:24 +0100832module_param_hw(share_irq, bool, other, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300833MODULE_PARM_DESC(share_irq, "Share interrupts (0 = off, 1 = on)");
834
Sean Youngb66db532016-11-21 19:55:51 -0200835module_param(sense, int, 0444);
836MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit (0 = active high, 1 = active low )");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300837
Sean Youngb66db532016-11-21 19:55:51 -0200838#ifdef CONFIG_IR_SERIAL_TRANSMITTER
839module_param(txsense, bool, 0444);
840MODULE_PARM_DESC(txsense, "Sense of transmitter circuit (0 = active high, 1 = active low )");
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300841#endif
842
Sean Youngb66db532016-11-21 19:55:51 -0200843module_param(softcarrier, bool, 0444);
Jarod Wilson1beef3c2010-07-26 20:31:45 -0300844MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");