diff options
author | Maxim Levitsky <maximlevitsky@gmail.com> | 2010-07-31 10:59:25 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-08-08 22:43:00 -0400 |
commit | 9ea53b74df9c4681f5bb2da6b2e10e37d87ea6d6 (patch) | |
tree | 7f3dc2e209bdcca8388e0aac88c0b7ea2022c6c8 /drivers | |
parent | ed4d3876d18d95406e0258a6421b1f4eda51d629 (diff) |
V4L/DVB: STAGING: remove lirc_ene0100 driver
Add latest unported version of this driver to media/IR.
Next patch will port it to ir core.
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/IR/ene_ir.c | 1176 | ||||
-rw-r--r-- | drivers/media/IR/ene_ir.h | 240 | ||||
-rw-r--r-- | drivers/staging/lirc/Kconfig | 8 | ||||
-rw-r--r-- | drivers/staging/lirc/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/lirc/lirc_ene0100.c | 646 |
5 files changed, 1416 insertions, 655 deletions
diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c new file mode 100644 index 000000000000..9d11caf55b03 --- /dev/null +++ b/drivers/media/IR/ene_ir.c | |||
@@ -0,0 +1,1176 @@ | |||
1 | /* | ||
2 | * driver for ENE KB3926 B/C/D CIR (also known as ENE0100/ENE0200/ENE0201) | ||
3 | * | ||
4 | * Copyright (C) 2010 Maxim Levitsky <maximlevitsky@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation; either version 2 of the | ||
9 | * License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | * USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/pnp.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include <linux/uaccess.h> | ||
29 | #include "lirc_ene0100.h" | ||
30 | |||
31 | |||
32 | static int sample_period = -1; | ||
33 | static int enable_idle = 1; | ||
34 | static int enable_duty_carrier; | ||
35 | static int input = 1; | ||
36 | static int debug; | ||
37 | static int txsim; | ||
38 | |||
39 | static void ene_rx_set_idle(struct ene_device *dev, int idle); | ||
40 | static int ene_irq_status(struct ene_device *dev); | ||
41 | static void ene_send_sample(struct ene_device *dev, unsigned long sample); | ||
42 | |||
43 | /* read a hardware register */ | ||
44 | static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg) | ||
45 | { | ||
46 | u8 retval; | ||
47 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); | ||
48 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); | ||
49 | retval = inb(dev->hw_io + ENE_IO); | ||
50 | |||
51 | ene_dbg_verbose("reg %04x == %02x", reg, retval); | ||
52 | return retval; | ||
53 | } | ||
54 | |||
55 | /* write a hardware register */ | ||
56 | static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value) | ||
57 | { | ||
58 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); | ||
59 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); | ||
60 | outb(value, dev->hw_io + ENE_IO); | ||
61 | |||
62 | ene_dbg_verbose("reg %04x <- %02x", reg, value); | ||
63 | } | ||
64 | |||
65 | /* change specific bits in hardware register */ | ||
66 | static void ene_hw_write_reg_mask(struct ene_device *dev, | ||
67 | u16 reg, u8 value, u8 mask) | ||
68 | { | ||
69 | u8 regvalue; | ||
70 | |||
71 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); | ||
72 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); | ||
73 | |||
74 | regvalue = inb(dev->hw_io + ENE_IO) & ~mask; | ||
75 | regvalue |= (value & mask); | ||
76 | outb(regvalue, dev->hw_io + ENE_IO); | ||
77 | |||
78 | ene_dbg_verbose("reg %04x <- %02x (mask=%02x)", reg, value, mask); | ||
79 | } | ||
80 | |||
81 | /* detect hardware features */ | ||
82 | static int ene_hw_detect(struct ene_device *dev) | ||
83 | { | ||
84 | u8 chip_major, chip_minor; | ||
85 | u8 hw_revision, old_ver; | ||
86 | u8 tmp; | ||
87 | u8 fw_capabilities; | ||
88 | |||
89 | tmp = ene_hw_read_reg(dev, ENE_HW_UNK); | ||
90 | ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR); | ||
91 | |||
92 | chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR); | ||
93 | chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR); | ||
94 | |||
95 | ene_hw_write_reg(dev, ENE_HW_UNK, tmp); | ||
96 | hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION); | ||
97 | old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD); | ||
98 | |||
99 | if (hw_revision == 0xFF) { | ||
100 | |||
101 | ene_printk(KERN_WARNING, "device seems to be disabled\n"); | ||
102 | ene_printk(KERN_WARNING, | ||
103 | "send a mail to lirc-list@lists.sourceforge.net\n"); | ||
104 | ene_printk(KERN_WARNING, "please attach output of acpidump\n"); | ||
105 | return -ENODEV; | ||
106 | } | ||
107 | |||
108 | if (chip_major == 0x33) { | ||
109 | ene_printk(KERN_WARNING, "chips 0x33xx aren't supported\n"); | ||
110 | return -ENODEV; | ||
111 | } | ||
112 | |||
113 | if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) { | ||
114 | dev->hw_revision = ENE_HW_C; | ||
115 | } else if (old_ver == 0x24 && hw_revision == 0xC0) { | ||
116 | dev->hw_revision = ENE_HW_B; | ||
117 | ene_printk(KERN_NOTICE, "KB3926B detected\n"); | ||
118 | } else { | ||
119 | dev->hw_revision = ENE_HW_D; | ||
120 | ene_printk(KERN_WARNING, | ||
121 | "unknown ENE chip detected, assuming KB3926D\n"); | ||
122 | ene_printk(KERN_WARNING, | ||
123 | "driver support might be not complete"); | ||
124 | |||
125 | } | ||
126 | |||
127 | ene_printk(KERN_DEBUG, | ||
128 | "chip is 0x%02x%02x - kbver = 0x%02x, rev = 0x%02x\n", | ||
129 | chip_major, chip_minor, old_ver, hw_revision); | ||
130 | |||
131 | /* detect features hardware supports */ | ||
132 | if (dev->hw_revision < ENE_HW_C) | ||
133 | return 0; | ||
134 | |||
135 | fw_capabilities = ene_hw_read_reg(dev, ENE_FW2); | ||
136 | ene_dbg("Firmware capabilities: %02x", fw_capabilities); | ||
137 | |||
138 | dev->hw_gpio40_learning = fw_capabilities & ENE_FW2_GP40_AS_LEARN; | ||
139 | dev->hw_learning_and_tx_capable = fw_capabilities & ENE_FW2_LEARNING; | ||
140 | |||
141 | dev->hw_fan_as_normal_input = dev->hw_learning_and_tx_capable && | ||
142 | (fw_capabilities & ENE_FW2_FAN_AS_NRML_IN); | ||
143 | |||
144 | ene_printk(KERN_NOTICE, "hardware features:\n"); | ||
145 | ene_printk(KERN_NOTICE, | ||
146 | "learning and transmit %s, gpio40_learn %s, fan_in %s\n", | ||
147 | dev->hw_learning_and_tx_capable ? "on" : "off", | ||
148 | dev->hw_gpio40_learning ? "on" : "off", | ||
149 | dev->hw_fan_as_normal_input ? "on" : "off"); | ||
150 | |||
151 | if (dev->hw_learning_and_tx_capable) { | ||
152 | ene_printk(KERN_WARNING, | ||
153 | "Device supports transmitting, but that support is\n"); | ||
154 | ene_printk(KERN_WARNING, | ||
155 | "lightly tested. Please test it and mail\n"); | ||
156 | ene_printk(KERN_WARNING, | ||
157 | "lirc-list@lists.sourceforge.net\n"); | ||
158 | } | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | /* this enables/disables IR input via gpio40*/ | ||
163 | static void ene_enable_gpio40_recieve(struct ene_device *dev, int enable) | ||
164 | { | ||
165 | ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, enable ? | ||
166 | 0 : ENE_CIR_CONF2_GPIO40DIS, | ||
167 | ENE_CIR_CONF2_GPIO40DIS); | ||
168 | } | ||
169 | |||
170 | /* this enables/disables IR via standard input */ | ||
171 | static void ene_enable_normal_recieve(struct ene_device *dev, int enable) | ||
172 | { | ||
173 | ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_RX_ON : 0); | ||
174 | } | ||
175 | |||
176 | /* this enables/disables IR input via unused fan tachtometer input */ | ||
177 | static void ene_enable_fan_recieve(struct ene_device *dev, int enable) | ||
178 | { | ||
179 | if (!enable) | ||
180 | ene_hw_write_reg(dev, ENE_FAN_AS_IN1, 0); | ||
181 | else { | ||
182 | ene_hw_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN); | ||
183 | ene_hw_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN); | ||
184 | } | ||
185 | dev->rx_fan_input_inuse = enable; | ||
186 | } | ||
187 | |||
188 | |||
189 | /* Sense current recieved carrier */ | ||
190 | static int ene_rx_sense_carrier(struct ene_device *dev) | ||
191 | { | ||
192 | int period = ene_hw_read_reg(dev, ENE_RX_CARRIER); | ||
193 | int carrier; | ||
194 | ene_dbg("RX: hardware carrier period = %02x", period); | ||
195 | |||
196 | if (!(period & ENE_RX_CARRIER_VALID)) | ||
197 | return 0; | ||
198 | |||
199 | period &= ~ENE_RX_CARRIER_VALID; | ||
200 | |||
201 | if (!period) | ||
202 | return 0; | ||
203 | |||
204 | carrier = 2000000 / period; | ||
205 | ene_dbg("RX: sensed carrier = %d Hz", carrier); | ||
206 | return carrier; | ||
207 | } | ||
208 | |||
209 | /* determine which input to use*/ | ||
210 | static void ene_rx_set_inputs(struct ene_device *dev) | ||
211 | { | ||
212 | int learning_mode = dev->learning_enabled || dev->rx_carrier_sense; | ||
213 | |||
214 | ene_dbg("RX: setup reciever, learning mode = %d", learning_mode); | ||
215 | |||
216 | ene_enable_normal_recieve(dev, 1); | ||
217 | |||
218 | /* old hardware doesn't support learning mode for sure */ | ||
219 | if (dev->hw_revision <= ENE_HW_B) | ||
220 | return; | ||
221 | |||
222 | /* reciever not learning capable, still set gpio40 correctly */ | ||
223 | if (!dev->hw_learning_and_tx_capable) { | ||
224 | ene_enable_gpio40_recieve(dev, !dev->hw_gpio40_learning); | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | /* enable learning mode */ | ||
229 | if (learning_mode) { | ||
230 | ene_enable_gpio40_recieve(dev, dev->hw_gpio40_learning); | ||
231 | |||
232 | /* fan input is not used for learning */ | ||
233 | if (dev->hw_fan_as_normal_input) | ||
234 | ene_enable_fan_recieve(dev, 0); | ||
235 | |||
236 | /* disable learning mode */ | ||
237 | } else { | ||
238 | if (dev->hw_fan_as_normal_input) { | ||
239 | ene_enable_fan_recieve(dev, 1); | ||
240 | ene_enable_normal_recieve(dev, 0); | ||
241 | } else | ||
242 | ene_enable_gpio40_recieve(dev, | ||
243 | !dev->hw_gpio40_learning); | ||
244 | } | ||
245 | |||
246 | /* set few additional settings for this mode */ | ||
247 | ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, learning_mode ? | ||
248 | ENE_CIR_CONF1_LEARN1 : 0, ENE_CIR_CONF1_LEARN1); | ||
249 | |||
250 | ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, learning_mode ? | ||
251 | ENE_CIR_CONF2_LEARN2 : 0, ENE_CIR_CONF2_LEARN2); | ||
252 | } | ||
253 | |||
254 | /* Enable the device for receive */ | ||
255 | static void ene_rx_enable(struct ene_device *dev) | ||
256 | { | ||
257 | u8 reg_value; | ||
258 | |||
259 | if (dev->hw_revision < ENE_HW_C) { | ||
260 | ene_hw_write_reg(dev, ENEB_IRQ, dev->irq << 1); | ||
261 | ene_hw_write_reg(dev, ENEB_IRQ_UNK1, 0x01); | ||
262 | } else { | ||
263 | reg_value = ene_hw_read_reg(dev, ENEC_IRQ) & 0xF0; | ||
264 | reg_value |= ENEC_IRQ_UNK_EN; | ||
265 | reg_value &= ~ENEC_IRQ_STATUS; | ||
266 | reg_value |= (dev->irq & ENEC_IRQ_MASK); | ||
267 | ene_hw_write_reg(dev, ENEC_IRQ, reg_value); | ||
268 | ene_hw_write_reg(dev, ENE_TX_UNK1, 0x63); | ||
269 | } | ||
270 | |||
271 | ene_hw_write_reg(dev, ENE_CIR_CONF2, 0x00); | ||
272 | ene_rx_set_inputs(dev); | ||
273 | |||
274 | /* set sampling period */ | ||
275 | ene_hw_write_reg(dev, ENE_CIR_SAMPLE_PERIOD, sample_period); | ||
276 | |||
277 | /* ack any pending irqs - just in case */ | ||
278 | ene_irq_status(dev); | ||
279 | |||
280 | /* enter idle mode */ | ||
281 | ene_rx_set_idle(dev, 1); | ||
282 | |||
283 | /* enable firmware bits */ | ||
284 | ene_hw_write_reg_mask(dev, ENE_FW1, | ||
285 | ENE_FW1_ENABLE | ENE_FW1_IRQ, | ||
286 | ENE_FW1_ENABLE | ENE_FW1_IRQ); | ||
287 | } | ||
288 | |||
289 | /* Disable the device reciever */ | ||
290 | static void ene_rx_disable(struct ene_device *dev) | ||
291 | { | ||
292 | /* disable inputs */ | ||
293 | ene_enable_normal_recieve(dev, 0); | ||
294 | |||
295 | if (dev->hw_fan_as_normal_input) | ||
296 | ene_enable_fan_recieve(dev, 0); | ||
297 | |||
298 | /* disable hardware IRQ and firmware flag */ | ||
299 | ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_ENABLE | ENE_FW1_IRQ); | ||
300 | |||
301 | ene_rx_set_idle(dev, 1); | ||
302 | } | ||
303 | |||
304 | /* send current sample to the user */ | ||
305 | static void ene_rx_flush(struct ene_device *dev, int timeout) | ||
306 | { | ||
307 | unsigned long value; | ||
308 | |||
309 | value = dev->rx_sample_pulse ? LIRC_PULSE(dev->rx_sample) : | ||
310 | LIRC_SPACE(dev->rx_sample); | ||
311 | ene_send_sample(dev, value); | ||
312 | dev->rx_sample = 0; | ||
313 | dev->rx_sample_pulse = 0; | ||
314 | } | ||
315 | |||
316 | /* recieve new sample and process it */ | ||
317 | static void ene_rx_sample(struct ene_device *dev, int sample, int is_pulse) | ||
318 | { | ||
319 | ene_dbg("RX: sample %8d (%s)", sample, is_pulse ? "pulse" : "space"); | ||
320 | |||
321 | /* ignore spaces in idle mode, can get them on revC */ | ||
322 | /* also ignore a space in front of first pulse */ | ||
323 | if (dev->rx_idle && !is_pulse) | ||
324 | return; | ||
325 | |||
326 | /* get out of idle mode now */ | ||
327 | if (dev->rx_idle) | ||
328 | ene_rx_set_idle(dev, 0); | ||
329 | |||
330 | if (!dev->rx_sample) { | ||
331 | dev->rx_sample = sample; | ||
332 | dev->rx_sample_pulse = is_pulse; | ||
333 | } else if (is_pulse == dev->rx_sample_pulse) | ||
334 | dev->rx_sample += sample; | ||
335 | else { | ||
336 | ene_rx_flush(dev, 0); | ||
337 | dev->rx_sample = sample; | ||
338 | dev->rx_sample_pulse = is_pulse; | ||
339 | } | ||
340 | |||
341 | if (is_pulse) | ||
342 | return; | ||
343 | |||
344 | /* overflow sample from fan input recieved, enable idle mode */ | ||
345 | if (dev->rx_fan_input_inuse && | ||
346 | sample == ENE_FAN_VALUE_MASK * ENE_SAMPLE_PERIOD_FAN) { | ||
347 | ene_rx_set_idle(dev, 1); | ||
348 | return; | ||
349 | } | ||
350 | |||
351 | if (!dev->rx_fan_input_inuse) { | ||
352 | /* Report timeout if enabled */ | ||
353 | if (dev->rx_timeout && dev->rx_send_timeout_packet && | ||
354 | !dev->rx_timeout_sent && | ||
355 | dev->rx_sample > dev->rx_timeout) { | ||
356 | ene_dbg("RX: sending timeout sample"); | ||
357 | ene_send_sample(dev, LIRC_TIMEOUT(dev->rx_sample)); | ||
358 | dev->rx_timeout_sent = 1; | ||
359 | } | ||
360 | |||
361 | /* too large sample accumulated via normal input. | ||
362 | note that on revC, hardware idle mode turns on automaticly, | ||
363 | so max gap should be less that the gap after which | ||
364 | hw stops sending samples */ | ||
365 | if (dev->rx_sample > ENE_MAXGAP) { | ||
366 | ene_rx_set_idle(dev, 1); | ||
367 | return; | ||
368 | } | ||
369 | } | ||
370 | } | ||
371 | |||
372 | /* enable or disable idle mode */ | ||
373 | static void ene_rx_set_idle(struct ene_device *dev, int idle) | ||
374 | { | ||
375 | struct timeval now; | ||
376 | int disable_sampler = 0; | ||
377 | |||
378 | |||
379 | /* Also put hardware sampler in 'idle' mode on revB*/ | ||
380 | /* revC and higher do that automaticly (firmware does?) */ | ||
381 | if ((dev->hw_revision < ENE_HW_C) && enable_idle) | ||
382 | if (idle) | ||
383 | disable_sampler = 1; | ||
384 | |||
385 | ene_hw_write_reg_mask(dev, ENE_CIR_SAMPLE_PERIOD, | ||
386 | disable_sampler ? 0 : ENE_CIR_SAMPLE_OVERFLOW, | ||
387 | ENE_CIR_SAMPLE_OVERFLOW); | ||
388 | dev->rx_idle = idle; | ||
389 | |||
390 | /* remember when we have entered the idle mode */ | ||
391 | if (idle) { | ||
392 | ene_dbg("RX: going into idle mode"); | ||
393 | do_gettimeofday(&dev->rx_gap_start); | ||
394 | return; | ||
395 | } | ||
396 | |||
397 | ene_dbg("RX: back from idle mode"); | ||
398 | |||
399 | /* send the gap between keypresses now */ | ||
400 | do_gettimeofday(&now); | ||
401 | |||
402 | if (dev->rx_sample_pulse) { | ||
403 | ene_dbg("RX: somehow we recieved a pulse before idle mode???"); | ||
404 | return; | ||
405 | } | ||
406 | |||
407 | /* manually calculate and recieve the gap between keypresses */ | ||
408 | if (now.tv_sec - dev->rx_gap_start.tv_sec > 16) | ||
409 | dev->rx_sample = LIRC_SPACE(LIRC_VALUE_MASK); | ||
410 | else | ||
411 | dev->rx_sample += | ||
412 | 1000000ull * (now.tv_sec - dev->rx_gap_start.tv_sec) | ||
413 | + now.tv_usec - dev->rx_gap_start.tv_usec; | ||
414 | |||
415 | if (dev->rx_sample > LIRC_SPACE(LIRC_VALUE_MASK)) | ||
416 | dev->rx_sample = LIRC_SPACE(LIRC_VALUE_MASK); | ||
417 | |||
418 | ene_rx_flush(dev, 0); | ||
419 | dev->rx_timeout_sent = 0; | ||
420 | } | ||
421 | |||
422 | /* prepare transmission */ | ||
423 | static void ene_tx_prepare(struct ene_device *dev) | ||
424 | { | ||
425 | u8 conf1; | ||
426 | |||
427 | conf1 = ene_hw_read_reg(dev, ENE_CIR_CONF1); | ||
428 | dev->saved_conf1 = conf1; | ||
429 | |||
430 | if (dev->hw_revision == ENE_HW_C) | ||
431 | conf1 &= ~ENE_CIR_CONF1_TX_CLEAR; | ||
432 | |||
433 | /* Enable TX engine */ | ||
434 | conf1 |= ENE_CIR_CONF1_TX_ON; | ||
435 | |||
436 | /* Set carrier */ | ||
437 | if (dev->tx_period) { | ||
438 | |||
439 | int tx_period_in500ns = dev->tx_period * 2; | ||
440 | |||
441 | int tx_pulse_width_in_500ns = | ||
442 | tx_period_in500ns / (100 / dev->tx_duty_cycle); | ||
443 | |||
444 | if (!tx_pulse_width_in_500ns) | ||
445 | tx_pulse_width_in_500ns = 1; | ||
446 | |||
447 | ene_dbg("TX: pulse distance = %d * 500 ns", tx_period_in500ns); | ||
448 | ene_dbg("TX: pulse width = %d * 500 ns", | ||
449 | tx_pulse_width_in_500ns); | ||
450 | |||
451 | ene_hw_write_reg(dev, ENE_TX_PERIOD, ENE_TX_PERIOD_UNKBIT | | ||
452 | tx_period_in500ns); | ||
453 | |||
454 | ene_hw_write_reg(dev, ENE_TX_PERIOD_PULSE, | ||
455 | tx_pulse_width_in_500ns); | ||
456 | |||
457 | conf1 |= ENE_CIR_CONF1_TX_CARR; | ||
458 | } else | ||
459 | conf1 &= ~ENE_CIR_CONF1_TX_CARR; | ||
460 | |||
461 | ene_hw_write_reg(dev, ENE_CIR_CONF1, conf1); | ||
462 | dev->tx_underway = 1; | ||
463 | |||
464 | } | ||
465 | |||
466 | /* end transmission */ | ||
467 | static void ene_tx_complete(struct ene_device *dev) | ||
468 | { | ||
469 | ene_hw_write_reg(dev, ENE_CIR_CONF1, dev->saved_conf1); | ||
470 | dev->tx_underway = 0; | ||
471 | } | ||
472 | |||
473 | /* set transmit mask */ | ||
474 | static void ene_tx_set_transmiter_mask(struct ene_device *dev) | ||
475 | { | ||
476 | u8 txport1 = ene_hw_read_reg(dev, ENE_TX_PORT1) & ~ENE_TX_PORT1_EN; | ||
477 | u8 txport2 = ene_hw_read_reg(dev, ENE_TX_PORT2) & ~ENE_TX_PORT2_EN; | ||
478 | |||
479 | if (dev->transmitter_mask & 0x01) | ||
480 | txport1 |= ENE_TX_PORT1_EN; | ||
481 | |||
482 | if (dev->transmitter_mask & 0x02) | ||
483 | txport2 |= ENE_TX_PORT2_EN; | ||
484 | |||
485 | ene_hw_write_reg(dev, ENE_TX_PORT1, txport1); | ||
486 | ene_hw_write_reg(dev, ENE_TX_PORT2, txport2); | ||
487 | } | ||
488 | |||
489 | /* TX one sample - must be called with dev->hw_lock*/ | ||
490 | static void ene_tx_sample(struct ene_device *dev) | ||
491 | { | ||
492 | u8 raw_tx; | ||
493 | u32 sample; | ||
494 | |||
495 | if (!dev->tx_underway) { | ||
496 | ene_dbg("TX: attempt to transmit while hw isn't setup"); | ||
497 | return; | ||
498 | } | ||
499 | |||
500 | /* Grab next TX sample */ | ||
501 | if (!dev->tx_sample) { | ||
502 | again: | ||
503 | if (dev->tx_pos == dev->tx_len + 1) { | ||
504 | if (!dev->tx_done) { | ||
505 | ene_dbg("TX: no more data to send"); | ||
506 | dev->tx_done = 1; | ||
507 | goto exit; | ||
508 | } else { | ||
509 | ene_dbg("TX: last sample sent by hardware"); | ||
510 | ene_tx_complete(dev); | ||
511 | complete(&dev->tx_complete); | ||
512 | return; | ||
513 | } | ||
514 | } | ||
515 | |||
516 | sample = dev->tx_buffer[dev->tx_pos++]; | ||
517 | dev->tx_sample_pulse = !dev->tx_sample_pulse; | ||
518 | |||
519 | ene_dbg("TX: sample %8d (%s)", sample, dev->tx_sample_pulse ? | ||
520 | "pulse" : "space"); | ||
521 | |||
522 | dev->tx_sample = DIV_ROUND_CLOSEST(sample, ENE_TX_SMPL_PERIOD); | ||
523 | |||
524 | /* guard against too short samples */ | ||
525 | if (!dev->tx_sample) | ||
526 | goto again; | ||
527 | } | ||
528 | |||
529 | raw_tx = min(dev->tx_sample , (unsigned int)ENE_TX_SMLP_MASK); | ||
530 | dev->tx_sample -= raw_tx; | ||
531 | |||
532 | if (dev->tx_sample_pulse) | ||
533 | raw_tx |= ENE_TX_PULSE_MASK; | ||
534 | |||
535 | ene_hw_write_reg(dev, ENE_TX_INPUT1 + dev->tx_reg, raw_tx); | ||
536 | dev->tx_reg = !dev->tx_reg; | ||
537 | exit: | ||
538 | /* simulate TX done interrupt */ | ||
539 | if (txsim) | ||
540 | mod_timer(&dev->tx_sim_timer, jiffies + HZ / 500); | ||
541 | } | ||
542 | |||
543 | /* timer to simulate tx done interrupt */ | ||
544 | static void ene_tx_irqsim(unsigned long data) | ||
545 | { | ||
546 | struct ene_device *dev = (struct ene_device *)data; | ||
547 | unsigned long flags; | ||
548 | |||
549 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
550 | ene_tx_sample(dev); | ||
551 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
552 | } | ||
553 | |||
554 | |||
555 | /* read irq status and ack it */ | ||
556 | static int ene_irq_status(struct ene_device *dev) | ||
557 | { | ||
558 | u8 irq_status; | ||
559 | u8 fw_flags1, fw_flags2; | ||
560 | int cur_rx_pointer; | ||
561 | int retval = 0; | ||
562 | |||
563 | fw_flags2 = ene_hw_read_reg(dev, ENE_FW2); | ||
564 | cur_rx_pointer = !!(fw_flags2 & ENE_FW2_BUF_HIGH); | ||
565 | |||
566 | if (dev->hw_revision < ENE_HW_C) { | ||
567 | irq_status = ene_hw_read_reg(dev, ENEB_IRQ_STATUS); | ||
568 | |||
569 | if (!(irq_status & ENEB_IRQ_STATUS_IR)) | ||
570 | return 0; | ||
571 | |||
572 | ene_hw_write_reg(dev, ENEB_IRQ_STATUS, | ||
573 | irq_status & ~ENEB_IRQ_STATUS_IR); | ||
574 | dev->rx_pointer = cur_rx_pointer; | ||
575 | return ENE_IRQ_RX; | ||
576 | } | ||
577 | |||
578 | irq_status = ene_hw_read_reg(dev, ENEC_IRQ); | ||
579 | |||
580 | if (!(irq_status & ENEC_IRQ_STATUS)) | ||
581 | return 0; | ||
582 | |||
583 | /* original driver does that twice - a workaround ? */ | ||
584 | ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS); | ||
585 | ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS); | ||
586 | |||
587 | /* clear unknown flag in F8F9 */ | ||
588 | if (fw_flags2 & ENE_FW2_IRQ_CLR) | ||
589 | ene_hw_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_IRQ_CLR); | ||
590 | |||
591 | /* check if this is a TX interrupt */ | ||
592 | fw_flags1 = ene_hw_read_reg(dev, ENE_FW1); | ||
593 | if (fw_flags1 & ENE_FW1_TXIRQ) { | ||
594 | ene_hw_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ); | ||
595 | retval |= ENE_IRQ_TX; | ||
596 | } | ||
597 | |||
598 | /* Check if this is RX interrupt */ | ||
599 | if (dev->rx_pointer != cur_rx_pointer) { | ||
600 | retval |= ENE_IRQ_RX; | ||
601 | dev->rx_pointer = cur_rx_pointer; | ||
602 | |||
603 | } else if (!(retval & ENE_IRQ_TX)) { | ||
604 | ene_dbg("RX: interrupt without change in RX pointer(%d)", | ||
605 | dev->rx_pointer); | ||
606 | retval |= ENE_IRQ_RX; | ||
607 | } | ||
608 | |||
609 | if ((retval & ENE_IRQ_RX) && (retval & ENE_IRQ_TX)) | ||
610 | ene_dbg("both RX and TX interrupt at same time"); | ||
611 | |||
612 | return retval; | ||
613 | } | ||
614 | |||
615 | /* interrupt handler */ | ||
616 | static irqreturn_t ene_isr(int irq, void *data) | ||
617 | { | ||
618 | u16 hw_value; | ||
619 | int i, hw_sample; | ||
620 | int pulse; | ||
621 | int irq_status; | ||
622 | unsigned long flags; | ||
623 | int carrier = 0; | ||
624 | irqreturn_t retval = IRQ_NONE; | ||
625 | struct ene_device *dev = (struct ene_device *)data; | ||
626 | |||
627 | |||
628 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
629 | irq_status = ene_irq_status(dev); | ||
630 | |||
631 | if (!irq_status) | ||
632 | goto unlock; | ||
633 | |||
634 | retval = IRQ_HANDLED; | ||
635 | |||
636 | if (irq_status & ENE_IRQ_TX) { | ||
637 | |||
638 | if (!dev->hw_learning_and_tx_capable) { | ||
639 | ene_dbg("TX interrupt on unsupported device!"); | ||
640 | goto unlock; | ||
641 | } | ||
642 | ene_tx_sample(dev); | ||
643 | } | ||
644 | |||
645 | if (!(irq_status & ENE_IRQ_RX)) | ||
646 | goto unlock; | ||
647 | |||
648 | |||
649 | if ((debug && dev->learning_enabled) || dev->rx_carrier_sense) | ||
650 | carrier = ene_rx_sense_carrier(dev); | ||
651 | |||
652 | if (dev->rx_carrier_sense && carrier) | ||
653 | ene_send_sample(dev, LIRC_FREQUENCY(carrier)); | ||
654 | |||
655 | |||
656 | for (i = 0; i < ENE_SAMPLES_SIZE; i++) { | ||
657 | hw_value = ene_hw_read_reg(dev, | ||
658 | ENE_SAMPLE_BUFFER + dev->rx_pointer * 4 + i); | ||
659 | |||
660 | if (dev->rx_fan_input_inuse) { | ||
661 | /* read high part of the sample */ | ||
662 | hw_value |= ene_hw_read_reg(dev, | ||
663 | ENE_SAMPLE_BUFFER_FAN + | ||
664 | dev->rx_pointer * 4 + i) << 8; | ||
665 | pulse = hw_value & ENE_FAN_SMPL_PULS_MSK; | ||
666 | |||
667 | /* clear space bit, and other unused bits */ | ||
668 | hw_value &= ENE_FAN_VALUE_MASK; | ||
669 | hw_sample = hw_value * ENE_SAMPLE_PERIOD_FAN; | ||
670 | |||
671 | } else { | ||
672 | pulse = !(hw_value & ENE_SAMPLE_SPC_MASK); | ||
673 | hw_value &= ENE_SAMPLE_VALUE_MASK; | ||
674 | hw_sample = hw_value * sample_period; | ||
675 | } | ||
676 | /* no more data */ | ||
677 | if (!(hw_value)) | ||
678 | break; | ||
679 | |||
680 | ene_rx_sample(dev, hw_sample, pulse); | ||
681 | } | ||
682 | unlock: | ||
683 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
684 | return retval; | ||
685 | } | ||
686 | |||
687 | /* Initialize default settings */ | ||
688 | static void ene_setup_settings(struct ene_device *dev) | ||
689 | { | ||
690 | dev->rx_send_timeout_packet = 0; | ||
691 | dev->rx_timeout = ENE_MAXGAP; | ||
692 | dev->tx_period = 32; | ||
693 | dev->tx_duty_cycle = 25; /*%*/ | ||
694 | dev->transmitter_mask = 3; | ||
695 | |||
696 | /* Force learning mode if (input == 2), otherwise | ||
697 | let user set it with LIRC_SET_REC_CARRIER */ | ||
698 | dev->learning_enabled = | ||
699 | (input == 2 && dev->hw_learning_and_tx_capable); | ||
700 | |||
701 | /* Clear accumulated sample bufer */ | ||
702 | dev->rx_sample = 0; | ||
703 | dev->rx_sample_pulse = 0; | ||
704 | dev->rx_pointer = -1; | ||
705 | dev->rx_carrier_sense = 0; | ||
706 | |||
707 | } | ||
708 | |||
709 | /* outside interface: called on first open*/ | ||
710 | static int ene_open(void *data) | ||
711 | { | ||
712 | struct ene_device *dev = (struct ene_device *)data; | ||
713 | unsigned long flags; | ||
714 | |||
715 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
716 | dev->in_use = 1; | ||
717 | ene_setup_settings(dev); | ||
718 | ene_rx_enable(dev); | ||
719 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
720 | return 0; | ||
721 | } | ||
722 | |||
723 | /* outside interface: called on device close*/ | ||
724 | static void ene_close(void *data) | ||
725 | { | ||
726 | struct ene_device *dev = (struct ene_device *)data; | ||
727 | unsigned long flags; | ||
728 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
729 | |||
730 | ene_rx_disable(dev); | ||
731 | dev->in_use = 0; | ||
732 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
733 | } | ||
734 | |||
735 | /* outside interface for settings */ | ||
736 | static int ene_ioctl(struct inode *node, struct file *file, | ||
737 | unsigned int cmd, unsigned long arg) | ||
738 | { | ||
739 | int lvalue = 0, retval, tmp; | ||
740 | unsigned long flags; | ||
741 | struct ene_device *dev = lirc_get_pdata(file); | ||
742 | |||
743 | |||
744 | switch (cmd) { | ||
745 | case LIRC_SET_SEND_CARRIER: | ||
746 | case LIRC_SET_SEND_DUTY_CYCLE: | ||
747 | case LIRC_SET_TRANSMITTER_MASK: | ||
748 | case LIRC_SET_MEASURE_CARRIER_MODE: | ||
749 | case LIRC_SET_REC_CARRIER: | ||
750 | /* All these aren't possible without this */ | ||
751 | if (!dev->hw_learning_and_tx_capable) | ||
752 | return -ENOSYS; | ||
753 | /* Fall through */ | ||
754 | case LIRC_SET_REC_TIMEOUT: | ||
755 | case LIRC_SET_REC_TIMEOUT_REPORTS: | ||
756 | retval = get_user(lvalue, (unsigned int *) arg); | ||
757 | if (retval) | ||
758 | return retval; | ||
759 | } | ||
760 | |||
761 | switch (cmd) { | ||
762 | case LIRC_SET_SEND_CARRIER: | ||
763 | ene_dbg("TX: attempt to set tx carrier to %d kHz", lvalue); | ||
764 | tmp = 1000000 / lvalue; /* (1 / freq) (* # usec in 1 sec) */ | ||
765 | |||
766 | if (tmp && (tmp > ENE_TX_PERIOD_MAX || | ||
767 | tmp < ENE_TX_PERIOD_MIN)) { | ||
768 | |||
769 | ene_dbg("TX: out of range %d-%d carrier, " | ||
770 | "falling back to 32 kHz", | ||
771 | 1000 / ENE_TX_PERIOD_MIN, | ||
772 | 1000 / ENE_TX_PERIOD_MAX); | ||
773 | |||
774 | tmp = 32; /* this is just a coincidence!!! */ | ||
775 | } | ||
776 | ene_dbg("TX: set carrier to %d kHz", lvalue); | ||
777 | |||
778 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
779 | dev->tx_period = tmp; | ||
780 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
781 | break; | ||
782 | case LIRC_SET_SEND_DUTY_CYCLE: | ||
783 | ene_dbg("TX: attempt to set duty cycle to %d%%", lvalue); | ||
784 | |||
785 | if ((lvalue >= 100) || (lvalue <= 0)) { | ||
786 | retval = -EINVAL; | ||
787 | break; | ||
788 | } | ||
789 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
790 | dev->tx_duty_cycle = lvalue; | ||
791 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
792 | break; | ||
793 | case LIRC_SET_TRANSMITTER_MASK: | ||
794 | ene_dbg("TX: attempt to set transmitter mask %02x", lvalue); | ||
795 | |||
796 | /* invalid txmask */ | ||
797 | if (!lvalue || lvalue & ~0x3) { | ||
798 | ene_dbg("TX: invalid mask"); | ||
799 | /* this supposed to return num of transmitters */ | ||
800 | retval = 2; | ||
801 | break; | ||
802 | } | ||
803 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
804 | dev->transmitter_mask = lvalue; | ||
805 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
806 | break; | ||
807 | case LIRC_SET_REC_CARRIER: | ||
808 | tmp = (lvalue > ENE_NORMAL_RX_HI || lvalue < ENE_NORMAL_RX_LOW); | ||
809 | |||
810 | if (tmp != dev->learning_enabled) { | ||
811 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
812 | dev->learning_enabled = tmp; | ||
813 | ene_rx_set_inputs(dev); | ||
814 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
815 | } | ||
816 | break; | ||
817 | case LIRC_SET_REC_TIMEOUT: | ||
818 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
819 | dev->rx_timeout = lvalue; | ||
820 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
821 | ene_dbg("RX: set rx report timeout to %d", dev->rx_timeout); | ||
822 | break; | ||
823 | case LIRC_SET_REC_TIMEOUT_REPORTS: | ||
824 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
825 | dev->rx_send_timeout_packet = lvalue; | ||
826 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
827 | ene_dbg("RX: %sable timeout reports", | ||
828 | dev->rx_send_timeout_packet ? "en" : "dis"); | ||
829 | break; | ||
830 | case LIRC_SET_MEASURE_CARRIER_MODE: | ||
831 | if (dev->rx_carrier_sense == lvalue) | ||
832 | break; | ||
833 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
834 | dev->rx_carrier_sense = lvalue; | ||
835 | ene_rx_set_inputs(dev); | ||
836 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
837 | break; | ||
838 | case LIRC_GET_REC_RESOLUTION: | ||
839 | tmp = dev->rx_fan_input_inuse ? | ||
840 | ENE_SAMPLE_PERIOD_FAN : sample_period; | ||
841 | retval = put_user(tmp, (unsigned long *) arg); | ||
842 | break; | ||
843 | default: | ||
844 | retval = -ENOIOCTLCMD; | ||
845 | break; | ||
846 | } | ||
847 | |||
848 | return retval; | ||
849 | } | ||
850 | |||
851 | /* outside interface: transmit */ | ||
852 | static ssize_t ene_transmit(struct file *file, const char *buf, | ||
853 | size_t n, loff_t *ppos) | ||
854 | { | ||
855 | struct ene_device *dev = lirc_get_pdata(file); | ||
856 | unsigned long flags; | ||
857 | |||
858 | if (!dev) | ||
859 | return -EFAULT; | ||
860 | |||
861 | if (!dev->hw_learning_and_tx_capable) | ||
862 | return -ENODEV; | ||
863 | |||
864 | if (n % sizeof(int)) | ||
865 | return -EINVAL; | ||
866 | |||
867 | if (n > ENE_TXBUF_SIZE * sizeof(int)) | ||
868 | return -ENOMEM; | ||
869 | |||
870 | if (copy_from_user(dev->tx_buffer, buf, n)) | ||
871 | return -EFAULT; | ||
872 | |||
873 | dev->tx_len = n / sizeof(int); | ||
874 | dev->tx_pos = 0; | ||
875 | dev->tx_reg = 0; | ||
876 | dev->tx_done = 0; | ||
877 | dev->tx_sample = 0; | ||
878 | dev->tx_sample_pulse = 0; | ||
879 | |||
880 | ene_dbg("TX: %d samples", dev->tx_len); | ||
881 | |||
882 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
883 | |||
884 | ene_tx_set_transmiter_mask(dev); | ||
885 | ene_tx_prepare(dev); | ||
886 | |||
887 | /* Transmit first two samples */ | ||
888 | ene_tx_sample(dev); | ||
889 | ene_tx_sample(dev); | ||
890 | |||
891 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
892 | |||
893 | if (wait_for_completion_timeout(&dev->tx_complete, 2 * HZ) == 0) { | ||
894 | ene_dbg("TX: timeout"); | ||
895 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
896 | ene_tx_complete(dev); | ||
897 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
898 | } else | ||
899 | ene_dbg("TX: done"); | ||
900 | |||
901 | return n; | ||
902 | } | ||
903 | |||
904 | /* Sends one sample to the user */ | ||
905 | static void ene_send_sample(struct ene_device *dev, unsigned long sample) | ||
906 | { | ||
907 | if (!lirc_buffer_full(dev->lirc_driver->rbuf)) { | ||
908 | lirc_buffer_write(dev->lirc_driver->rbuf, (void *)&sample); | ||
909 | wake_up(&dev->lirc_driver->rbuf->wait_poll); | ||
910 | } | ||
911 | } | ||
912 | |||
913 | |||
914 | static const struct file_operations ene_fops = { | ||
915 | .owner = THIS_MODULE, | ||
916 | .write = ene_transmit, | ||
917 | .ioctl = ene_ioctl, | ||
918 | }; | ||
919 | |||
920 | /* main load function */ | ||
921 | static int ene_probe(struct pnp_dev *pnp_dev, | ||
922 | const struct pnp_device_id *dev_id) | ||
923 | { | ||
924 | struct ene_device *dev; | ||
925 | struct lirc_driver *lirc_driver; | ||
926 | int error = -ENOMEM; | ||
927 | |||
928 | dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); | ||
929 | |||
930 | if (!dev) | ||
931 | goto err1; | ||
932 | |||
933 | dev->pnp_dev = pnp_dev; | ||
934 | pnp_set_drvdata(pnp_dev, dev); | ||
935 | |||
936 | /* prepare lirc interface */ | ||
937 | error = -ENOMEM; | ||
938 | lirc_driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); | ||
939 | |||
940 | if (!lirc_driver) | ||
941 | goto err2; | ||
942 | |||
943 | dev->lirc_driver = lirc_driver; | ||
944 | |||
945 | strcpy(lirc_driver->name, ENE_DRIVER_NAME); | ||
946 | lirc_driver->minor = -1; | ||
947 | lirc_driver->code_length = sizeof(int) * 8; | ||
948 | lirc_driver->features = LIRC_CAN_REC_MODE2 | | ||
949 | LIRC_CAN_GET_REC_RESOLUTION | | ||
950 | LIRC_CAN_SET_REC_TIMEOUT; | ||
951 | lirc_driver->data = dev; | ||
952 | lirc_driver->set_use_inc = ene_open; | ||
953 | lirc_driver->set_use_dec = ene_close; | ||
954 | lirc_driver->dev = &pnp_dev->dev; | ||
955 | lirc_driver->owner = THIS_MODULE; | ||
956 | lirc_driver->fops = &ene_fops; | ||
957 | lirc_driver->min_timeout = ENE_MINGAP; | ||
958 | lirc_driver->max_timeout = ENE_MAXGAP; | ||
959 | lirc_driver->rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL); | ||
960 | |||
961 | if (!lirc_driver->rbuf) | ||
962 | goto err3; | ||
963 | |||
964 | if (lirc_buffer_init(lirc_driver->rbuf, sizeof(int), sizeof(int) * 512)) | ||
965 | goto err4; | ||
966 | |||
967 | /* validate resources */ | ||
968 | if (!pnp_port_valid(pnp_dev, 0) || | ||
969 | pnp_port_len(pnp_dev, 0) < ENE_MAX_IO) | ||
970 | goto err5; | ||
971 | |||
972 | if (!pnp_irq_valid(pnp_dev, 0)) | ||
973 | goto err5; | ||
974 | |||
975 | dev->hw_io = pnp_port_start(pnp_dev, 0); | ||
976 | dev->irq = pnp_irq(pnp_dev, 0); | ||
977 | spin_lock_init(&dev->hw_lock); | ||
978 | |||
979 | /* claim the resources */ | ||
980 | error = -EBUSY; | ||
981 | if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME)) | ||
982 | goto err5; | ||
983 | |||
984 | if (request_irq(dev->irq, ene_isr, | ||
985 | IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) | ||
986 | goto err6; | ||
987 | |||
988 | /* detect hardware version and features */ | ||
989 | error = ene_hw_detect(dev); | ||
990 | if (error) | ||
991 | goto err7; | ||
992 | |||
993 | ene_setup_settings(dev); | ||
994 | |||
995 | if (!dev->hw_learning_and_tx_capable && txsim) { | ||
996 | dev->hw_learning_and_tx_capable = 1; | ||
997 | setup_timer(&dev->tx_sim_timer, ene_tx_irqsim, | ||
998 | (long unsigned int)dev); | ||
999 | ene_printk(KERN_WARNING, | ||
1000 | "Simulation of TX activated\n"); | ||
1001 | } | ||
1002 | |||
1003 | if (dev->hw_learning_and_tx_capable) { | ||
1004 | lirc_driver->features |= LIRC_CAN_SEND_PULSE | | ||
1005 | LIRC_CAN_SET_SEND_CARRIER | | ||
1006 | LIRC_CAN_SET_TRANSMITTER_MASK; | ||
1007 | |||
1008 | if (enable_duty_carrier) | ||
1009 | lirc_driver->features |= LIRC_CAN_SET_SEND_DUTY_CYCLE; | ||
1010 | |||
1011 | if (input == 0) | ||
1012 | lirc_driver->features |= LIRC_CAN_SET_REC_CARRIER; | ||
1013 | |||
1014 | init_completion(&dev->tx_complete); | ||
1015 | } | ||
1016 | |||
1017 | /* don't allow too short/long sample periods */ | ||
1018 | if (sample_period < 5 || sample_period > 0x7F) | ||
1019 | sample_period = -1; | ||
1020 | |||
1021 | /* choose default sample period */ | ||
1022 | if (sample_period == -1) { | ||
1023 | |||
1024 | sample_period = 50; | ||
1025 | |||
1026 | /* on revB, hardware idle mode eats first sample | ||
1027 | if we set too low sample period */ | ||
1028 | if (dev->hw_revision == ENE_HW_B && enable_idle) | ||
1029 | sample_period = 75; | ||
1030 | } | ||
1031 | |||
1032 | device_set_wakeup_capable(&pnp_dev->dev, 1); | ||
1033 | device_set_wakeup_enable(&pnp_dev->dev, 1); | ||
1034 | |||
1035 | error = -ENODEV; | ||
1036 | if (lirc_register_driver(lirc_driver)) | ||
1037 | goto err7; | ||
1038 | |||
1039 | ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n"); | ||
1040 | return 0; | ||
1041 | |||
1042 | err7: | ||
1043 | free_irq(dev->irq, dev); | ||
1044 | err6: | ||
1045 | release_region(dev->hw_io, ENE_MAX_IO); | ||
1046 | err5: | ||
1047 | lirc_buffer_free(lirc_driver->rbuf); | ||
1048 | err4: | ||
1049 | kfree(lirc_driver->rbuf); | ||
1050 | err3: | ||
1051 | kfree(lirc_driver); | ||
1052 | err2: | ||
1053 | kfree(dev); | ||
1054 | err1: | ||
1055 | return error; | ||
1056 | } | ||
1057 | |||
1058 | /* main unload function */ | ||
1059 | static void ene_remove(struct pnp_dev *pnp_dev) | ||
1060 | { | ||
1061 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
1062 | unsigned long flags; | ||
1063 | |||
1064 | spin_lock_irqsave(&dev->hw_lock, flags); | ||
1065 | ene_rx_disable(dev); | ||
1066 | spin_unlock_irqrestore(&dev->hw_lock, flags); | ||
1067 | |||
1068 | free_irq(dev->irq, dev); | ||
1069 | release_region(dev->hw_io, ENE_MAX_IO); | ||
1070 | lirc_unregister_driver(dev->lirc_driver->minor); | ||
1071 | lirc_buffer_free(dev->lirc_driver->rbuf); | ||
1072 | kfree(dev->lirc_driver); | ||
1073 | kfree(dev); | ||
1074 | } | ||
1075 | |||
1076 | /* enable wake on IR (wakes on specific button on original remote) */ | ||
1077 | static void ene_enable_wake(struct ene_device *dev, int enable) | ||
1078 | { | ||
1079 | enable = enable && device_may_wakeup(&dev->pnp_dev->dev); | ||
1080 | |||
1081 | ene_dbg("wake on IR %s", enable ? "enabled" : "disabled"); | ||
1082 | |||
1083 | ene_hw_write_reg_mask(dev, ENE_FW1, enable ? | ||
1084 | ENE_FW1_WAKE : 0, ENE_FW1_WAKE); | ||
1085 | } | ||
1086 | |||
1087 | #ifdef CONFIG_PM | ||
1088 | static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state) | ||
1089 | { | ||
1090 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
1091 | ene_enable_wake(dev, 1); | ||
1092 | return 0; | ||
1093 | } | ||
1094 | |||
1095 | static int ene_resume(struct pnp_dev *pnp_dev) | ||
1096 | { | ||
1097 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
1098 | if (dev->in_use) | ||
1099 | ene_rx_enable(dev); | ||
1100 | |||
1101 | ene_enable_wake(dev, 0); | ||
1102 | return 0; | ||
1103 | } | ||
1104 | #endif | ||
1105 | |||
1106 | static void ene_shutdown(struct pnp_dev *pnp_dev) | ||
1107 | { | ||
1108 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
1109 | ene_enable_wake(dev, 1); | ||
1110 | } | ||
1111 | |||
1112 | static const struct pnp_device_id ene_ids[] = { | ||
1113 | {.id = "ENE0100",}, | ||
1114 | {.id = "ENE0200",}, | ||
1115 | {.id = "ENE0201",}, | ||
1116 | {}, | ||
1117 | }; | ||
1118 | |||
1119 | static struct pnp_driver ene_driver = { | ||
1120 | .name = ENE_DRIVER_NAME, | ||
1121 | .id_table = ene_ids, | ||
1122 | .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, | ||
1123 | |||
1124 | .probe = ene_probe, | ||
1125 | .remove = __devexit_p(ene_remove), | ||
1126 | #ifdef CONFIG_PM | ||
1127 | .suspend = ene_suspend, | ||
1128 | .resume = ene_resume, | ||
1129 | #endif | ||
1130 | .shutdown = ene_shutdown, | ||
1131 | }; | ||
1132 | |||
1133 | static int __init ene_init(void) | ||
1134 | { | ||
1135 | return pnp_register_driver(&ene_driver); | ||
1136 | } | ||
1137 | |||
1138 | static void ene_exit(void) | ||
1139 | { | ||
1140 | pnp_unregister_driver(&ene_driver); | ||
1141 | } | ||
1142 | |||
1143 | module_param(sample_period, int, S_IRUGO); | ||
1144 | MODULE_PARM_DESC(sample_period, "Hardware sample period (50 us default)"); | ||
1145 | |||
1146 | module_param(enable_idle, bool, S_IRUGO | S_IWUSR); | ||
1147 | MODULE_PARM_DESC(enable_idle, | ||
1148 | "Enables turning off signal sampling after long inactivity time; " | ||
1149 | "if disabled might help detecting input signal (default: enabled)" | ||
1150 | " (KB3926B only)"); | ||
1151 | |||
1152 | module_param(input, bool, S_IRUGO); | ||
1153 | MODULE_PARM_DESC(input, "select which input to use " | ||
1154 | "0 - auto, 1 - standard, 2 - wideband(KB3926C+)"); | ||
1155 | |||
1156 | module_param(debug, int, S_IRUGO | S_IWUSR); | ||
1157 | MODULE_PARM_DESC(debug, "Enable debug (debug=2 verbose debug output)"); | ||
1158 | |||
1159 | module_param(txsim, bool, S_IRUGO); | ||
1160 | MODULE_PARM_DESC(txsim, | ||
1161 | "Simulate TX features on unsupported hardware (dangerous)"); | ||
1162 | |||
1163 | module_param(enable_duty_carrier, bool, S_IRUGO); | ||
1164 | MODULE_PARM_DESC(enable_duty_carrier, | ||
1165 | "Enable a code that might allow to to set TX carrier duty cycle"); | ||
1166 | |||
1167 | MODULE_DEVICE_TABLE(pnp, ene_ids); | ||
1168 | MODULE_DESCRIPTION | ||
1169 | ("LIRC driver for KB3926B/KB3926C/KB3926D " | ||
1170 | "(aka ENE0100/ENE0200/ENE0201) CIR port"); | ||
1171 | |||
1172 | MODULE_AUTHOR("Maxim Levitsky"); | ||
1173 | MODULE_LICENSE("GPL"); | ||
1174 | |||
1175 | module_init(ene_init); | ||
1176 | module_exit(ene_exit); | ||
diff --git a/drivers/media/IR/ene_ir.h b/drivers/media/IR/ene_ir.h new file mode 100644 index 000000000000..b464a680d8ae --- /dev/null +++ b/drivers/media/IR/ene_ir.h | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | * driver for ENE KB3926 B/C/D CIR (also known as ENE0100/ENE0200/ENE0201) | ||
3 | * | ||
4 | * Copyright (C) 2010 Maxim Levitsky <maximlevitsky@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation; either version 2 of the | ||
9 | * License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | * USA | ||
20 | */ | ||
21 | #include <linux/spinlock.h> | ||
22 | #include <media/lirc.h> | ||
23 | #include <media/lirc_dev.h> | ||
24 | |||
25 | /* hardware address */ | ||
26 | #define ENE_STATUS 0 /* hardware status - unused */ | ||
27 | #define ENE_ADDR_HI 1 /* hi byte of register address */ | ||
28 | #define ENE_ADDR_LO 2 /* low byte of register address */ | ||
29 | #define ENE_IO 3 /* read/write window */ | ||
30 | #define ENE_MAX_IO 4 | ||
31 | |||
32 | /* 8 bytes of samples, divided in 2 halfs*/ | ||
33 | #define ENE_SAMPLE_BUFFER 0xF8F0 /* regular sample buffer */ | ||
34 | #define ENE_SAMPLE_SPC_MASK 0x80 /* sample is space */ | ||
35 | #define ENE_SAMPLE_VALUE_MASK 0x7F | ||
36 | #define ENE_SAMPLE_OVERFLOW 0x7F | ||
37 | #define ENE_SAMPLES_SIZE 4 | ||
38 | |||
39 | /* fan input sample buffer */ | ||
40 | #define ENE_SAMPLE_BUFFER_FAN 0xF8FB /* this buffer holds high byte of */ | ||
41 | /* each sample of normal buffer */ | ||
42 | #define ENE_FAN_SMPL_PULS_MSK 0x8000 /* this bit of combined sample */ | ||
43 | /* if set, says that sample is pulse */ | ||
44 | #define ENE_FAN_VALUE_MASK 0x0FFF /* mask for valid bits of the value */ | ||
45 | |||
46 | /* first firmware register */ | ||
47 | #define ENE_FW1 0xF8F8 | ||
48 | #define ENE_FW1_ENABLE 0x01 /* enable fw processing */ | ||
49 | #define ENE_FW1_TXIRQ 0x02 /* TX interrupt pending */ | ||
50 | #define ENE_FW1_WAKE 0x40 /* enable wake from S3 */ | ||
51 | #define ENE_FW1_IRQ 0x80 /* enable interrupt */ | ||
52 | |||
53 | /* second firmware register */ | ||
54 | #define ENE_FW2 0xF8F9 | ||
55 | #define ENE_FW2_BUF_HIGH 0x01 /* which half of the buffer to read */ | ||
56 | #define ENE_FW2_IRQ_CLR 0x04 /* clear this on IRQ */ | ||
57 | #define ENE_FW2_GP40_AS_LEARN 0x08 /* normal input is used as */ | ||
58 | /* learning input */ | ||
59 | #define ENE_FW2_FAN_AS_NRML_IN 0x40 /* fan is used as normal input */ | ||
60 | #define ENE_FW2_LEARNING 0x80 /* hardware supports learning and TX */ | ||
61 | |||
62 | /* transmitter ports */ | ||
63 | #define ENE_TX_PORT2 0xFC01 /* this enables one or both */ | ||
64 | #define ENE_TX_PORT2_EN 0x20 /* TX ports */ | ||
65 | #define ENE_TX_PORT1 0xFC08 | ||
66 | #define ENE_TX_PORT1_EN 0x02 | ||
67 | |||
68 | /* IRQ registers block (for revision B) */ | ||
69 | #define ENEB_IRQ 0xFD09 /* IRQ number */ | ||
70 | #define ENEB_IRQ_UNK1 0xFD17 /* unknown setting = 1 */ | ||
71 | #define ENEB_IRQ_STATUS 0xFD80 /* irq status */ | ||
72 | #define ENEB_IRQ_STATUS_IR 0x20 /* IR irq */ | ||
73 | |||
74 | /* fan as input settings - only if learning capable */ | ||
75 | #define ENE_FAN_AS_IN1 0xFE30 /* fan init reg 1 */ | ||
76 | #define ENE_FAN_AS_IN1_EN 0xCD | ||
77 | #define ENE_FAN_AS_IN2 0xFE31 /* fan init reg 2 */ | ||
78 | #define ENE_FAN_AS_IN2_EN 0x03 | ||
79 | #define ENE_SAMPLE_PERIOD_FAN 61 /* fan input has fixed sample period */ | ||
80 | |||
81 | /* IRQ registers block (for revision C,D) */ | ||
82 | #define ENEC_IRQ 0xFE9B /* new irq settings register */ | ||
83 | #define ENEC_IRQ_MASK 0x0F /* irq number mask */ | ||
84 | #define ENEC_IRQ_UNK_EN 0x10 /* always enabled */ | ||
85 | #define ENEC_IRQ_STATUS 0x20 /* irq status and ACK */ | ||
86 | |||
87 | /* CIR block settings */ | ||
88 | #define ENE_CIR_CONF1 0xFEC0 | ||
89 | #define ENE_CIR_CONF1_TX_CLEAR 0x01 /* clear that on revC */ | ||
90 | /* while transmitting */ | ||
91 | #define ENE_CIR_CONF1_RX_ON 0x07 /* normal reciever enabled */ | ||
92 | #define ENE_CIR_CONF1_LEARN1 0x08 /* enabled on learning mode */ | ||
93 | #define ENE_CIR_CONF1_TX_ON 0x30 /* enabled on transmit */ | ||
94 | #define ENE_CIR_CONF1_TX_CARR 0x80 /* send TX carrier or not */ | ||
95 | |||
96 | #define ENE_CIR_CONF2 0xFEC1 /* unknown setting = 0 */ | ||
97 | #define ENE_CIR_CONF2_LEARN2 0x10 /* set on enable learning */ | ||
98 | #define ENE_CIR_CONF2_GPIO40DIS 0x20 /* disable input via gpio40 */ | ||
99 | |||
100 | #define ENE_CIR_SAMPLE_PERIOD 0xFEC8 /* sample period in us */ | ||
101 | #define ENE_CIR_SAMPLE_OVERFLOW 0x80 /* interrupt on overflows if set */ | ||
102 | |||
103 | |||
104 | /* Two byte tx buffer */ | ||
105 | #define ENE_TX_INPUT1 0xFEC9 | ||
106 | #define ENE_TX_INPUT2 0xFECA | ||
107 | #define ENE_TX_PULSE_MASK 0x80 /* Transmitted sample is pulse */ | ||
108 | #define ENE_TX_SMLP_MASK 0x7F | ||
109 | #define ENE_TX_SMPL_PERIOD 50 /* transmit sample period - fixed */ | ||
110 | |||
111 | |||
112 | /* Unknown TX setting - TX sample period ??? */ | ||
113 | #define ENE_TX_UNK1 0xFECB /* set to 0x63 */ | ||
114 | |||
115 | /* Current recieved carrier period */ | ||
116 | #define ENE_RX_CARRIER 0xFECC /* RX period (500 ns) */ | ||
117 | #define ENE_RX_CARRIER_VALID 0x80 /* Register content valid */ | ||
118 | |||
119 | |||
120 | /* TX period (1/carrier) */ | ||
121 | #define ENE_TX_PERIOD 0xFECE /* TX period (500 ns) */ | ||
122 | #define ENE_TX_PERIOD_UNKBIT 0x80 /* This bit set on transmit*/ | ||
123 | #define ENE_TX_PERIOD_PULSE 0xFECF /* TX pulse period (500 ns)*/ | ||
124 | |||
125 | /* Hardware versions */ | ||
126 | #define ENE_HW_VERSION 0xFF00 /* hardware revision */ | ||
127 | #define ENE_HW_UNK 0xFF1D | ||
128 | #define ENE_HW_UNK_CLR 0x04 | ||
129 | #define ENE_HW_VER_MAJOR 0xFF1E /* chip version */ | ||
130 | #define ENE_HW_VER_MINOR 0xFF1F | ||
131 | #define ENE_HW_VER_OLD 0xFD00 | ||
132 | |||
133 | /* Normal/Learning carrier ranges - only valid if we have learning input*/ | ||
134 | /* TODO: test */ | ||
135 | #define ENE_NORMAL_RX_LOW 34 | ||
136 | #define ENE_NORMAL_RX_HI 38 | ||
137 | |||
138 | /* Tx carrier range */ | ||
139 | /* Hardware might be able to do more, but this range is enough for | ||
140 | all purposes */ | ||
141 | #define ENE_TX_PERIOD_MAX 32 /* corresponds to 29.4 kHz */ | ||
142 | #define ENE_TX_PERIOD_MIN 16 /* corrsponds to 62.5 kHz */ | ||
143 | |||
144 | |||
145 | |||
146 | /* Minimal and maximal gaps */ | ||
147 | |||
148 | /* Normal case: | ||
149 | Minimal gap is 0x7F * sample period | ||
150 | Maximum gap depends on hardware. | ||
151 | For KB3926B, it is unlimited, for newer models its around | ||
152 | 250000, after which HW stops sending samples, and that is | ||
153 | not possible to change */ | ||
154 | |||
155 | /* Fan case: | ||
156 | Both minimal and maximal gaps are same, and equal to 0xFFF * 0x61 | ||
157 | And there is nothing to change this setting | ||
158 | */ | ||
159 | |||
160 | #define ENE_MAXGAP 250000 | ||
161 | #define ENE_MINGAP (127 * sample_period) | ||
162 | |||
163 | /******************************************************************************/ | ||
164 | |||
165 | #define ENE_DRIVER_NAME "enecir" | ||
166 | #define ENE_TXBUF_SIZE (500 * sizeof(int)) /* 500 samples (arbitary) */ | ||
167 | |||
168 | #define ENE_IRQ_RX 1 | ||
169 | #define ENE_IRQ_TX 2 | ||
170 | |||
171 | #define ENE_HW_B 1 /* 3926B */ | ||
172 | #define ENE_HW_C 2 /* 3926C */ | ||
173 | #define ENE_HW_D 3 /* 3926D */ | ||
174 | |||
175 | #define ene_printk(level, text, ...) \ | ||
176 | printk(level ENE_DRIVER_NAME ": " text, ## __VA_ARGS__) | ||
177 | |||
178 | #define ene_dbg(text, ...) \ | ||
179 | if (debug) \ | ||
180 | printk(KERN_DEBUG \ | ||
181 | ENE_DRIVER_NAME ": " text "\n" , ## __VA_ARGS__) | ||
182 | |||
183 | #define ene_dbg_verbose(text, ...) \ | ||
184 | if (debug > 1) \ | ||
185 | printk(KERN_DEBUG \ | ||
186 | ENE_DRIVER_NAME ": " text "\n" , ## __VA_ARGS__) | ||
187 | |||
188 | |||
189 | struct ene_device { | ||
190 | struct pnp_dev *pnp_dev; | ||
191 | struct lirc_driver *lirc_driver; | ||
192 | int in_use; | ||
193 | |||
194 | /* hw IO settings */ | ||
195 | unsigned long hw_io; | ||
196 | int irq; | ||
197 | spinlock_t hw_lock; | ||
198 | |||
199 | /* HW features */ | ||
200 | int hw_revision; /* hardware revision */ | ||
201 | int hw_learning_and_tx_capable; /* learning capable */ | ||
202 | int hw_gpio40_learning; /* gpio40 is learning */ | ||
203 | int hw_fan_as_normal_input; /* fan input is used as */ | ||
204 | /* regular input */ | ||
205 | /* HW state*/ | ||
206 | int rx_pointer; /* hw pointer to rx buffer */ | ||
207 | int rx_fan_input_inuse; /* is fan input in use for rx*/ | ||
208 | int tx_reg; /* current reg used for TX */ | ||
209 | u8 saved_conf1; /* saved FEC0 reg */ | ||
210 | int learning_enabled; /* learning input enabled */ | ||
211 | |||
212 | /* RX sample handling */ | ||
213 | int rx_sample; /* current recieved sample */ | ||
214 | int rx_sample_pulse; /* recieved sample is pulse */ | ||
215 | int rx_idle; /* idle mode for RX activated */ | ||
216 | struct timeval rx_gap_start; /* time of start of idle */ | ||
217 | int rx_timeout; /* time in ms of RX timeout */ | ||
218 | int rx_send_timeout_packet; /* do we send RX timeout */ | ||
219 | int rx_timeout_sent; /* we sent the timeout packet */ | ||
220 | int rx_carrier_sense; /* sense carrier */ | ||
221 | |||
222 | /* TX sample handling */ | ||
223 | unsigned int tx_sample; /* current sample for TX */ | ||
224 | int tx_sample_pulse; /* current sample is pulse */ | ||
225 | |||
226 | /* TX buffer */ | ||
227 | int tx_buffer[ENE_TXBUF_SIZE]; /* input samples buffer*/ | ||
228 | int tx_pos; /* position in that bufer */ | ||
229 | int tx_len; /* current len of tx buffer */ | ||
230 | int tx_underway; /* TX is under way*/ | ||
231 | int tx_done; /* done transmitting */ | ||
232 | /* one more sample pending*/ | ||
233 | struct completion tx_complete; /* TX completion */ | ||
234 | struct timer_list tx_sim_timer; | ||
235 | |||
236 | /*TX settings */ | ||
237 | int tx_period; | ||
238 | int tx_duty_cycle; | ||
239 | int transmitter_mask; | ||
240 | }; | ||
diff --git a/drivers/staging/lirc/Kconfig b/drivers/staging/lirc/Kconfig index 7db8cb68ab5d..100c4d4b8125 100644 --- a/drivers/staging/lirc/Kconfig +++ b/drivers/staging/lirc/Kconfig | |||
@@ -18,14 +18,6 @@ config LIRC_BT829 | |||
18 | help | 18 | help |
19 | Driver for the IR interface on BT829-based hardware | 19 | Driver for the IR interface on BT829-based hardware |
20 | 20 | ||
21 | config LIRC_ENE0100 | ||
22 | tristate "ENE KB3924/ENE0100 CIR Port Reciever" | ||
23 | depends on LIRC_STAGING && PNP | ||
24 | help | ||
25 | This is a driver for CIR port handled by ENE KB3924 embedded | ||
26 | controller found on some notebooks. | ||
27 | It appears on PNP list as ENE0100. | ||
28 | |||
29 | config LIRC_I2C | 21 | config LIRC_I2C |
30 | tristate "I2C Based IR Receivers" | 22 | tristate "I2C Based IR Receivers" |
31 | depends on LIRC_STAGING && I2C | 23 | depends on LIRC_STAGING && I2C |
diff --git a/drivers/staging/lirc/Makefile b/drivers/staging/lirc/Makefile index bd789d8a0177..4da1f3397a16 100644 --- a/drivers/staging/lirc/Makefile +++ b/drivers/staging/lirc/Makefile | |||
@@ -4,7 +4,6 @@ | |||
4 | # Each configuration option enables a list of files. | 4 | # Each configuration option enables a list of files. |
5 | 5 | ||
6 | obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o | 6 | obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o |
7 | obj-$(CONFIG_LIRC_ENE0100) += lirc_ene0100.o | ||
8 | obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o | 7 | obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o |
9 | obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o | 8 | obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o |
10 | obj-$(CONFIG_LIRC_IMON) += lirc_imon.o | 9 | obj-$(CONFIG_LIRC_IMON) += lirc_imon.o |
diff --git a/drivers/staging/lirc/lirc_ene0100.c b/drivers/staging/lirc/lirc_ene0100.c deleted file mode 100644 index a152c52b0745..000000000000 --- a/drivers/staging/lirc/lirc_ene0100.c +++ /dev/null | |||
@@ -1,646 +0,0 @@ | |||
1 | /* | ||
2 | * driver for ENE KB3926 B/C/D CIR (also known as ENE0100) | ||
3 | * | ||
4 | * Copyright (C) 2009 Maxim Levitsky <maximlevitsky@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation; either version 2 of the | ||
9 | * License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | * USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/pnp.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include "lirc_ene0100.h" | ||
29 | |||
30 | static int sample_period = 75; | ||
31 | static int enable_idle = 1; | ||
32 | static int enable_learning; | ||
33 | |||
34 | static void ene_set_idle(struct ene_device *dev, int idle); | ||
35 | static void ene_set_inputs(struct ene_device *dev, int enable); | ||
36 | |||
37 | /* read a hardware register */ | ||
38 | static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg) | ||
39 | { | ||
40 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); | ||
41 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); | ||
42 | return inb(dev->hw_io + ENE_IO); | ||
43 | } | ||
44 | |||
45 | /* write a hardware register */ | ||
46 | static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value) | ||
47 | { | ||
48 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); | ||
49 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); | ||
50 | outb(value, dev->hw_io + ENE_IO); | ||
51 | } | ||
52 | |||
53 | /* change specific bits in hardware register */ | ||
54 | static void ene_hw_write_reg_mask(struct ene_device *dev, | ||
55 | u16 reg, u8 value, u8 mask) | ||
56 | { | ||
57 | u8 regvalue; | ||
58 | |||
59 | outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); | ||
60 | outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); | ||
61 | |||
62 | regvalue = inb(dev->hw_io + ENE_IO) & ~mask; | ||
63 | regvalue |= (value & mask); | ||
64 | outb(regvalue, dev->hw_io + ENE_IO); | ||
65 | } | ||
66 | |||
67 | /* read irq status and ack it */ | ||
68 | static int ene_hw_irq_status(struct ene_device *dev, int *buffer_pointer) | ||
69 | { | ||
70 | u8 irq_status; | ||
71 | u8 fw_flags1, fw_flags2; | ||
72 | |||
73 | fw_flags2 = ene_hw_read_reg(dev, ENE_FW2); | ||
74 | |||
75 | if (buffer_pointer) | ||
76 | *buffer_pointer = 4 * (fw_flags2 & ENE_FW2_BUF_HIGH); | ||
77 | |||
78 | if (dev->hw_revision < ENE_HW_C) { | ||
79 | irq_status = ene_hw_read_reg(dev, ENEB_IRQ_STATUS); | ||
80 | |||
81 | if (!(irq_status & ENEB_IRQ_STATUS_IR)) | ||
82 | return 0; | ||
83 | ene_hw_write_reg(dev, ENEB_IRQ_STATUS, | ||
84 | irq_status & ~ENEB_IRQ_STATUS_IR); | ||
85 | |||
86 | /* rev B support only recieving */ | ||
87 | return ENE_IRQ_RX; | ||
88 | } | ||
89 | |||
90 | irq_status = ene_hw_read_reg(dev, ENEC_IRQ); | ||
91 | |||
92 | if (!(irq_status & ENEC_IRQ_STATUS)) | ||
93 | return 0; | ||
94 | |||
95 | /* original driver does that twice - a workaround ? */ | ||
96 | ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS); | ||
97 | ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS); | ||
98 | |||
99 | /* clear unknown flag in F8F9 */ | ||
100 | if (fw_flags2 & ENE_FW2_IRQ_CLR) | ||
101 | ene_hw_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_IRQ_CLR); | ||
102 | |||
103 | /* check if this is a TX interrupt */ | ||
104 | fw_flags1 = ene_hw_read_reg(dev, ENE_FW1); | ||
105 | |||
106 | if (fw_flags1 & ENE_FW1_TXIRQ) { | ||
107 | ene_hw_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ); | ||
108 | return ENE_IRQ_TX; | ||
109 | } else | ||
110 | return ENE_IRQ_RX; | ||
111 | } | ||
112 | |||
113 | static int ene_hw_detect(struct ene_device *dev) | ||
114 | { | ||
115 | u8 chip_major, chip_minor; | ||
116 | u8 hw_revision, old_ver; | ||
117 | u8 tmp; | ||
118 | u8 fw_capabilities; | ||
119 | |||
120 | tmp = ene_hw_read_reg(dev, ENE_HW_UNK); | ||
121 | ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR); | ||
122 | |||
123 | chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR); | ||
124 | chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR); | ||
125 | |||
126 | ene_hw_write_reg(dev, ENE_HW_UNK, tmp); | ||
127 | hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION); | ||
128 | old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD); | ||
129 | |||
130 | if (hw_revision == 0xFF) { | ||
131 | |||
132 | ene_printk(KERN_WARNING, "device seems to be disabled\n"); | ||
133 | ene_printk(KERN_WARNING, | ||
134 | "send a mail to lirc-list@lists.sourceforge.net\n"); | ||
135 | ene_printk(KERN_WARNING, "please attach output of acpidump\n"); | ||
136 | |||
137 | return -ENODEV; | ||
138 | } | ||
139 | |||
140 | if (chip_major == 0x33) { | ||
141 | ene_printk(KERN_WARNING, "chips 0x33xx aren't supported yet\n"); | ||
142 | return -ENODEV; | ||
143 | } | ||
144 | |||
145 | if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) { | ||
146 | dev->hw_revision = ENE_HW_C; | ||
147 | ene_printk(KERN_WARNING, | ||
148 | "KB3926C detected, driver support is not complete!\n"); | ||
149 | |||
150 | } else if (old_ver == 0x24 && hw_revision == 0xC0) { | ||
151 | dev->hw_revision = ENE_HW_B; | ||
152 | ene_printk(KERN_NOTICE, "KB3926B detected\n"); | ||
153 | } else { | ||
154 | dev->hw_revision = ENE_HW_D; | ||
155 | ene_printk(KERN_WARNING, | ||
156 | "unknown ENE chip detected, assuming KB3926D\n"); | ||
157 | ene_printk(KERN_WARNING, "driver support incomplete"); | ||
158 | |||
159 | } | ||
160 | |||
161 | ene_printk(KERN_DEBUG, "chip is 0x%02x%02x - 0x%02x, 0x%02x\n", | ||
162 | chip_major, chip_minor, old_ver, hw_revision); | ||
163 | |||
164 | |||
165 | /* detect features hardware supports */ | ||
166 | |||
167 | if (dev->hw_revision < ENE_HW_C) | ||
168 | return 0; | ||
169 | |||
170 | fw_capabilities = ene_hw_read_reg(dev, ENE_FW2); | ||
171 | |||
172 | dev->hw_gpio40_learning = fw_capabilities & ENE_FW2_GP40_AS_LEARN; | ||
173 | dev->hw_learning_and_tx_capable = fw_capabilities & ENE_FW2_LEARNING; | ||
174 | |||
175 | dev->hw_fan_as_normal_input = dev->hw_learning_and_tx_capable && | ||
176 | fw_capabilities & ENE_FW2_FAN_AS_NRML_IN; | ||
177 | |||
178 | ene_printk(KERN_NOTICE, "hardware features:\n"); | ||
179 | ene_printk(KERN_NOTICE, | ||
180 | "learning and tx %s, gpio40_learn %s, fan_in %s\n", | ||
181 | dev->hw_learning_and_tx_capable ? "on" : "off", | ||
182 | dev->hw_gpio40_learning ? "on" : "off", | ||
183 | dev->hw_fan_as_normal_input ? "on" : "off"); | ||
184 | |||
185 | if (!dev->hw_learning_and_tx_capable && enable_learning) | ||
186 | enable_learning = 0; | ||
187 | |||
188 | if (dev->hw_learning_and_tx_capable) { | ||
189 | ene_printk(KERN_WARNING, | ||
190 | "Device supports transmitting, but the driver doesn't\n"); | ||
191 | ene_printk(KERN_WARNING, | ||
192 | "due to lack of hardware to test against.\n"); | ||
193 | ene_printk(KERN_WARNING, | ||
194 | "Send a mail to: lirc-list@lists.sourceforge.net\n"); | ||
195 | } | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | /* hardware initialization */ | ||
200 | static int ene_hw_init(void *data) | ||
201 | { | ||
202 | u8 reg_value; | ||
203 | struct ene_device *dev = (struct ene_device *)data; | ||
204 | dev->in_use = 1; | ||
205 | |||
206 | if (dev->hw_revision < ENE_HW_C) { | ||
207 | ene_hw_write_reg(dev, ENEB_IRQ, dev->irq << 1); | ||
208 | ene_hw_write_reg(dev, ENEB_IRQ_UNK1, 0x01); | ||
209 | } else { | ||
210 | reg_value = ene_hw_read_reg(dev, ENEC_IRQ) & 0xF0; | ||
211 | reg_value |= ENEC_IRQ_UNK_EN; | ||
212 | reg_value &= ~ENEC_IRQ_STATUS; | ||
213 | reg_value |= (dev->irq & ENEC_IRQ_MASK); | ||
214 | ene_hw_write_reg(dev, ENEC_IRQ, reg_value); | ||
215 | ene_hw_write_reg(dev, ENE_TX_UNK1, 0x63); | ||
216 | } | ||
217 | |||
218 | ene_hw_write_reg(dev, ENE_CIR_CONF2, 0x00); | ||
219 | ene_set_inputs(dev, enable_learning); | ||
220 | |||
221 | /* set sampling period */ | ||
222 | ene_hw_write_reg(dev, ENE_CIR_SAMPLE_PERIOD, sample_period); | ||
223 | |||
224 | /* ack any pending irqs - just in case */ | ||
225 | ene_hw_irq_status(dev, NULL); | ||
226 | |||
227 | /* enter idle mode */ | ||
228 | ene_set_idle(dev, 1); | ||
229 | |||
230 | /* enable firmware bits */ | ||
231 | ene_hw_write_reg_mask(dev, ENE_FW1, | ||
232 | ENE_FW1_ENABLE | ENE_FW1_IRQ, | ||
233 | ENE_FW1_ENABLE | ENE_FW1_IRQ); | ||
234 | /* clear stats */ | ||
235 | dev->sample = 0; | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | /* this enables gpio40 signal, used if connected to wide band input*/ | ||
240 | static void ene_enable_gpio40(struct ene_device *dev, int enable) | ||
241 | { | ||
242 | ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, enable ? | ||
243 | 0 : ENE_CIR_CONF2_GPIO40DIS, | ||
244 | ENE_CIR_CONF2_GPIO40DIS); | ||
245 | } | ||
246 | |||
247 | /* this enables the classic sampler */ | ||
248 | static void ene_enable_normal_recieve(struct ene_device *dev, int enable) | ||
249 | { | ||
250 | ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_ADC_ON : 0); | ||
251 | } | ||
252 | |||
253 | /* this enables recieve via fan input */ | ||
254 | static void ene_enable_fan_recieve(struct ene_device *dev, int enable) | ||
255 | { | ||
256 | if (!enable) | ||
257 | ene_hw_write_reg(dev, ENE_FAN_AS_IN1, 0); | ||
258 | else { | ||
259 | ene_hw_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN); | ||
260 | ene_hw_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN); | ||
261 | } | ||
262 | dev->fan_input_inuse = enable; | ||
263 | } | ||
264 | |||
265 | /* determine which input to use*/ | ||
266 | static void ene_set_inputs(struct ene_device *dev, int learning_enable) | ||
267 | { | ||
268 | ene_enable_normal_recieve(dev, 1); | ||
269 | |||
270 | /* old hardware doesn't support learning mode for sure */ | ||
271 | if (dev->hw_revision <= ENE_HW_B) | ||
272 | return; | ||
273 | |||
274 | /* reciever not learning capable, still set gpio40 correctly */ | ||
275 | if (!dev->hw_learning_and_tx_capable) { | ||
276 | ene_enable_gpio40(dev, !dev->hw_gpio40_learning); | ||
277 | return; | ||
278 | } | ||
279 | |||
280 | /* enable learning mode */ | ||
281 | if (learning_enable) { | ||
282 | ene_enable_gpio40(dev, dev->hw_gpio40_learning); | ||
283 | |||
284 | /* fan input is not used for learning */ | ||
285 | if (dev->hw_fan_as_normal_input) | ||
286 | ene_enable_fan_recieve(dev, 0); | ||
287 | |||
288 | /* disable learning mode */ | ||
289 | } else { | ||
290 | if (dev->hw_fan_as_normal_input) { | ||
291 | ene_enable_fan_recieve(dev, 1); | ||
292 | ene_enable_normal_recieve(dev, 0); | ||
293 | } else | ||
294 | ene_enable_gpio40(dev, !dev->hw_gpio40_learning); | ||
295 | } | ||
296 | |||
297 | /* set few additional settings for this mode */ | ||
298 | ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, learning_enable ? | ||
299 | ENE_CIR_CONF1_LEARN1 : 0, ENE_CIR_CONF1_LEARN1); | ||
300 | |||
301 | ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, learning_enable ? | ||
302 | ENE_CIR_CONF2_LEARN2 : 0, ENE_CIR_CONF2_LEARN2); | ||
303 | } | ||
304 | |||
305 | /* deinitialization */ | ||
306 | static void ene_hw_deinit(void *data) | ||
307 | { | ||
308 | struct ene_device *dev = (struct ene_device *)data; | ||
309 | |||
310 | /* disable samplers */ | ||
311 | ene_enable_normal_recieve(dev, 0); | ||
312 | |||
313 | if (dev->hw_fan_as_normal_input) | ||
314 | ene_enable_fan_recieve(dev, 0); | ||
315 | |||
316 | /* disable hardware IRQ and firmware flag */ | ||
317 | ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_ENABLE | ENE_FW1_IRQ); | ||
318 | |||
319 | ene_set_idle(dev, 1); | ||
320 | dev->in_use = 0; | ||
321 | } | ||
322 | |||
323 | /* sends current sample to userspace */ | ||
324 | static void send_sample(struct ene_device *dev) | ||
325 | { | ||
326 | int value = abs(dev->sample) & PULSE_MASK; | ||
327 | |||
328 | if (dev->sample > 0) | ||
329 | value |= PULSE_BIT; | ||
330 | |||
331 | if (!lirc_buffer_full(dev->lirc_driver->rbuf)) { | ||
332 | lirc_buffer_write(dev->lirc_driver->rbuf, (void *)&value); | ||
333 | wake_up(&dev->lirc_driver->rbuf->wait_poll); | ||
334 | } | ||
335 | dev->sample = 0; | ||
336 | } | ||
337 | |||
338 | /* this updates current sample */ | ||
339 | static void update_sample(struct ene_device *dev, int sample) | ||
340 | { | ||
341 | if (!dev->sample) | ||
342 | dev->sample = sample; | ||
343 | else if (same_sign(dev->sample, sample)) | ||
344 | dev->sample += sample; | ||
345 | else { | ||
346 | send_sample(dev); | ||
347 | dev->sample = sample; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /* enable or disable idle mode */ | ||
352 | static void ene_set_idle(struct ene_device *dev, int idle) | ||
353 | { | ||
354 | struct timeval now; | ||
355 | int disable = idle && enable_idle && (dev->hw_revision < ENE_HW_C); | ||
356 | |||
357 | ene_hw_write_reg_mask(dev, ENE_CIR_SAMPLE_PERIOD, | ||
358 | disable ? 0 : ENE_CIR_SAMPLE_OVERFLOW, | ||
359 | ENE_CIR_SAMPLE_OVERFLOW); | ||
360 | dev->idle = idle; | ||
361 | |||
362 | /* remember when we have entered the idle mode */ | ||
363 | if (idle) { | ||
364 | do_gettimeofday(&dev->gap_start); | ||
365 | return; | ||
366 | } | ||
367 | |||
368 | /* send the gap between keypresses now */ | ||
369 | do_gettimeofday(&now); | ||
370 | |||
371 | if (now.tv_sec - dev->gap_start.tv_sec > 16) | ||
372 | dev->sample = space(PULSE_MASK); | ||
373 | else | ||
374 | dev->sample = dev->sample + | ||
375 | space(1000000ull * (now.tv_sec - dev->gap_start.tv_sec)) | ||
376 | + space(now.tv_usec - dev->gap_start.tv_usec); | ||
377 | |||
378 | if (abs(dev->sample) > PULSE_MASK) | ||
379 | dev->sample = space(PULSE_MASK); | ||
380 | send_sample(dev); | ||
381 | } | ||
382 | |||
383 | /* interrupt handler */ | ||
384 | static irqreturn_t ene_hw_irq(int irq, void *data) | ||
385 | { | ||
386 | u16 hw_value; | ||
387 | int i, hw_sample; | ||
388 | int space; | ||
389 | int buffer_pointer; | ||
390 | int irq_status; | ||
391 | |||
392 | struct ene_device *dev = (struct ene_device *)data; | ||
393 | irq_status = ene_hw_irq_status(dev, &buffer_pointer); | ||
394 | |||
395 | if (!irq_status) | ||
396 | return IRQ_NONE; | ||
397 | |||
398 | /* TODO: only RX for now */ | ||
399 | if (irq_status == ENE_IRQ_TX) | ||
400 | return IRQ_HANDLED; | ||
401 | |||
402 | for (i = 0; i < ENE_SAMPLES_SIZE; i++) { | ||
403 | |||
404 | hw_value = ene_hw_read_reg(dev, | ||
405 | ENE_SAMPLE_BUFFER + buffer_pointer + i); | ||
406 | |||
407 | if (dev->fan_input_inuse) { | ||
408 | /* read high part of the sample */ | ||
409 | hw_value |= ene_hw_read_reg(dev, | ||
410 | ENE_SAMPLE_BUFFER_FAN + buffer_pointer + i) << 8; | ||
411 | |||
412 | /* test for _space_ bit */ | ||
413 | space = !(hw_value & ENE_FAN_SMPL_PULS_MSK); | ||
414 | |||
415 | /* clear space bit, and other unused bits */ | ||
416 | hw_value &= ENE_FAN_VALUE_MASK; | ||
417 | hw_sample = hw_value * ENE_SAMPLE_PERIOD_FAN; | ||
418 | |||
419 | } else { | ||
420 | space = hw_value & ENE_SAMPLE_SPC_MASK; | ||
421 | hw_value &= ENE_SAMPLE_VALUE_MASK; | ||
422 | hw_sample = hw_value * sample_period; | ||
423 | } | ||
424 | |||
425 | /* no more data */ | ||
426 | if (!(hw_value)) | ||
427 | break; | ||
428 | |||
429 | if (space) | ||
430 | hw_sample *= -1; | ||
431 | |||
432 | /* overflow sample recieved, handle it */ | ||
433 | |||
434 | if (!dev->fan_input_inuse && hw_value == ENE_SAMPLE_OVERFLOW) { | ||
435 | |||
436 | if (dev->idle) | ||
437 | continue; | ||
438 | |||
439 | if (dev->sample > 0 || abs(dev->sample) <= ENE_MAXGAP) | ||
440 | update_sample(dev, hw_sample); | ||
441 | else | ||
442 | ene_set_idle(dev, 1); | ||
443 | |||
444 | continue; | ||
445 | } | ||
446 | |||
447 | /* normal first sample recieved */ | ||
448 | if (!dev->fan_input_inuse && dev->idle) { | ||
449 | ene_set_idle(dev, 0); | ||
450 | |||
451 | /* discard first recieved value, its random | ||
452 | since its the time signal was off before | ||
453 | first pulse if idle mode is enabled, HW | ||
454 | does that for us */ | ||
455 | |||
456 | if (!enable_idle) | ||
457 | continue; | ||
458 | } | ||
459 | update_sample(dev, hw_sample); | ||
460 | send_sample(dev); | ||
461 | } | ||
462 | return IRQ_HANDLED; | ||
463 | } | ||
464 | |||
465 | static int ene_probe(struct pnp_dev *pnp_dev, | ||
466 | const struct pnp_device_id *dev_id) | ||
467 | { | ||
468 | struct ene_device *dev; | ||
469 | struct lirc_driver *lirc_driver; | ||
470 | int error = -ENOMEM; | ||
471 | |||
472 | dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); | ||
473 | |||
474 | if (!dev) | ||
475 | goto err1; | ||
476 | |||
477 | dev->pnp_dev = pnp_dev; | ||
478 | pnp_set_drvdata(pnp_dev, dev); | ||
479 | |||
480 | |||
481 | /* prepare lirc interface */ | ||
482 | error = -ENOMEM; | ||
483 | lirc_driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); | ||
484 | |||
485 | if (!lirc_driver) | ||
486 | goto err2; | ||
487 | |||
488 | dev->lirc_driver = lirc_driver; | ||
489 | |||
490 | strcpy(lirc_driver->name, ENE_DRIVER_NAME); | ||
491 | lirc_driver->minor = -1; | ||
492 | lirc_driver->code_length = sizeof(int) * 8; | ||
493 | lirc_driver->features = LIRC_CAN_REC_MODE2; | ||
494 | lirc_driver->data = dev; | ||
495 | lirc_driver->set_use_inc = ene_hw_init; | ||
496 | lirc_driver->set_use_dec = ene_hw_deinit; | ||
497 | lirc_driver->dev = &pnp_dev->dev; | ||
498 | lirc_driver->owner = THIS_MODULE; | ||
499 | |||
500 | lirc_driver->rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL); | ||
501 | |||
502 | if (!lirc_driver->rbuf) | ||
503 | goto err3; | ||
504 | |||
505 | if (lirc_buffer_init(lirc_driver->rbuf, sizeof(int), sizeof(int) * 256)) | ||
506 | goto err4; | ||
507 | |||
508 | error = -ENODEV; | ||
509 | if (lirc_register_driver(lirc_driver)) | ||
510 | goto err5; | ||
511 | |||
512 | /* validate resources */ | ||
513 | if (!pnp_port_valid(pnp_dev, 0) || | ||
514 | pnp_port_len(pnp_dev, 0) < ENE_MAX_IO) | ||
515 | goto err6; | ||
516 | |||
517 | if (!pnp_irq_valid(pnp_dev, 0)) | ||
518 | goto err6; | ||
519 | |||
520 | dev->hw_io = pnp_port_start(pnp_dev, 0); | ||
521 | dev->irq = pnp_irq(pnp_dev, 0); | ||
522 | |||
523 | /* claim the resources */ | ||
524 | error = -EBUSY; | ||
525 | if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME)) | ||
526 | goto err6; | ||
527 | |||
528 | if (request_irq(dev->irq, ene_hw_irq, | ||
529 | IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) | ||
530 | goto err7; | ||
531 | |||
532 | /* detect hardware version and features */ | ||
533 | error = ene_hw_detect(dev); | ||
534 | if (error) | ||
535 | goto err8; | ||
536 | |||
537 | ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n"); | ||
538 | return 0; | ||
539 | |||
540 | err8: | ||
541 | free_irq(dev->irq, dev); | ||
542 | err7: | ||
543 | release_region(dev->hw_io, ENE_MAX_IO); | ||
544 | err6: | ||
545 | lirc_unregister_driver(lirc_driver->minor); | ||
546 | err5: | ||
547 | lirc_buffer_free(lirc_driver->rbuf); | ||
548 | err4: | ||
549 | kfree(lirc_driver->rbuf); | ||
550 | err3: | ||
551 | kfree(lirc_driver); | ||
552 | err2: | ||
553 | kfree(dev); | ||
554 | err1: | ||
555 | return error; | ||
556 | } | ||
557 | |||
558 | static void ene_remove(struct pnp_dev *pnp_dev) | ||
559 | { | ||
560 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
561 | ene_hw_deinit(dev); | ||
562 | free_irq(dev->irq, dev); | ||
563 | release_region(dev->hw_io, ENE_MAX_IO); | ||
564 | lirc_unregister_driver(dev->lirc_driver->minor); | ||
565 | lirc_buffer_free(dev->lirc_driver->rbuf); | ||
566 | kfree(dev->lirc_driver); | ||
567 | kfree(dev); | ||
568 | } | ||
569 | |||
570 | #ifdef CONFIG_PM | ||
571 | |||
572 | /* TODO: make 'wake on IR' configurable and add .shutdown */ | ||
573 | /* currently impossible due to lack of kernel support */ | ||
574 | |||
575 | static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state) | ||
576 | { | ||
577 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
578 | ene_hw_write_reg_mask(dev, ENE_FW1, ENE_FW1_WAKE, ENE_FW1_WAKE); | ||
579 | return 0; | ||
580 | } | ||
581 | |||
582 | static int ene_resume(struct pnp_dev *pnp_dev) | ||
583 | { | ||
584 | struct ene_device *dev = pnp_get_drvdata(pnp_dev); | ||
585 | if (dev->in_use) | ||
586 | ene_hw_init(dev); | ||
587 | |||
588 | ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_WAKE); | ||
589 | return 0; | ||
590 | } | ||
591 | |||
592 | #endif | ||
593 | |||
594 | static const struct pnp_device_id ene_ids[] = { | ||
595 | {.id = "ENE0100",}, | ||
596 | {}, | ||
597 | }; | ||
598 | |||
599 | static struct pnp_driver ene_driver = { | ||
600 | .name = ENE_DRIVER_NAME, | ||
601 | .id_table = ene_ids, | ||
602 | .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, | ||
603 | |||
604 | .probe = ene_probe, | ||
605 | .remove = __devexit_p(ene_remove), | ||
606 | |||
607 | #ifdef CONFIG_PM | ||
608 | .suspend = ene_suspend, | ||
609 | .resume = ene_resume, | ||
610 | #endif | ||
611 | }; | ||
612 | |||
613 | static int __init ene_init(void) | ||
614 | { | ||
615 | if (sample_period < 5) { | ||
616 | ene_printk(KERN_ERR, "sample period must be at\n"); | ||
617 | ene_printk(KERN_ERR, "least 5 us, (at least 30 recommended)\n"); | ||
618 | return -EINVAL; | ||
619 | } | ||
620 | return pnp_register_driver(&ene_driver); | ||
621 | } | ||
622 | |||
623 | static void ene_exit(void) | ||
624 | { | ||
625 | pnp_unregister_driver(&ene_driver); | ||
626 | } | ||
627 | |||
628 | module_param(sample_period, int, S_IRUGO); | ||
629 | MODULE_PARM_DESC(sample_period, "Hardware sample period (75 us default)"); | ||
630 | |||
631 | module_param(enable_idle, bool, S_IRUGO | S_IWUSR); | ||
632 | MODULE_PARM_DESC(enable_idle, | ||
633 | "Enables turning off signal sampling after long inactivity time; " | ||
634 | "if disabled might help detecting input signal (default: enabled)"); | ||
635 | |||
636 | module_param(enable_learning, bool, S_IRUGO); | ||
637 | MODULE_PARM_DESC(enable_learning, "Use wide band (learning) reciever"); | ||
638 | |||
639 | MODULE_DEVICE_TABLE(pnp, ene_ids); | ||
640 | MODULE_DESCRIPTION | ||
641 | ("LIRC driver for KB3926B/KB3926C/KB3926D (aka ENE0100) CIR port"); | ||
642 | MODULE_AUTHOR("Maxim Levitsky"); | ||
643 | MODULE_LICENSE("GPL"); | ||
644 | |||
645 | module_init(ene_init); | ||
646 | module_exit(ene_exit); | ||