27 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/errno.h>
30 #include <linux/signal.h>
32 #include <linux/kernel.h>
34 #include <linux/time.h>
41 #include <asm/div64.h>
43 #include <linux/poll.h>
44 #include <linux/parport.h>
52 #define LIRC_DRIVER_NAME "lirc_parallel"
58 #define LIRC_PORT 0x378
61 #define LIRC_TIMER 65536
67 static bool check_pselecd;
76 #define RBUF_SIZE (256)
124 static unsigned int lirc_get_timer(
void)
129 static unsigned int lirc_get_signal(
void)
134 static void lirc_on(
void)
139 static void lirc_off(
void)
144 static unsigned int init_lirc_timer(
void)
147 unsigned int level, newlevel, timeelapsed, newtimer;
152 level = lirc_get_timer();
154 newlevel = lirc_get_timer();
155 if (level == 0 && newlevel != 0)
159 }
while (count < 1000 && (now.tv_sec < tv.tv_sec
160 || (now.tv_sec == tv.tv_sec
161 && now.tv_usec < tv.tv_usec)));
163 timeelapsed = ((now.tv_sec + 1 - tv.tv_sec)*1000000
164 + (now.tv_usec - tv.tv_usec));
165 if (count >= 1000 && timeelapsed > 0) {
168 newtimer = (1000000*
count)/timeelapsed;
173 newtimer = (1000000*
count)/timeelapsed;
194 static int lirc_claim(
void)
214 static void rbuf_write(
int signal)
236 unsigned int level, newlevel;
257 signal = tv.tv_sec - lasttv.tv_sec;
262 data = (
int) (signal*1000000 +
263 tv.tv_usec - lasttv.tv_usec +
273 timer = init_lirc_timer();
282 level = lirc_get_timer();
284 newlevel = lirc_get_timer();
285 if (level == 0 && newlevel != 0)
296 }
while (lirc_get_signal());
302 helper = ((
__u64) signal)*1000000;
304 signal = (
long) helper;
328 static loff_t lirc_lseek(
struct file *filep, loff_t offset,
int orig)
333 static ssize_t lirc_read(
struct file *filep,
char *
buf,
size_t n, loff_t *ppos)
352 count +=
sizeof(
int);
368 return count ? count :
result;
371 static ssize_t lirc_write(
struct file *filep,
const char *buf,
size_t n,
376 unsigned int level, newlevel;
385 count = n /
sizeof(
int);
387 if (n %
sizeof(
int) || count % 2 == 0)
392 return PTR_ERR(wbuf);
397 timer = init_lirc_timer();
405 for (i = 0; i <
count; i++) {
410 wbuf[
i] = (
int) helper;
416 level = lirc_get_timer();
420 newlevel = lirc_get_timer();
421 if (level == 0 && newlevel != 0)
430 }
while (counttimer < wbuf[i]);
438 newlevel = lirc_get_timer();
439 if (level == 0 && newlevel != 0)
447 }
while (counttimer < wbuf[i]);
463 poll_wait(file, &lirc_wait, wait);
469 static long lirc_ioctl(
struct file *filep,
unsigned int cmd,
unsigned long arg)
521 static int lirc_open(
struct inode *
node,
struct file *filep)
537 static int lirc_close(
struct inode *node,
struct file *filep)
549 .llseek = lirc_lseek,
553 .unlocked_ioctl = lirc_ioctl,
555 .compat_ioctl = lirc_ioctl,
558 .release = lirc_close
561 static int set_use_inc(
void *data)
566 static void set_use_dec(
void *data)
608 .probe = lirc_parallel_probe,
610 .suspend = lirc_parallel_suspend,
611 .resume = lirc_parallel_resume,
625 static void kf(
void *
handle)
641 static int __init lirc_parallel_init(
void)
648 " returned %d\n", result);
653 if (!lirc_parallel_dev) {
655 goto exit_driver_unregister;
660 goto exit_device_put;
667 goto exit_device_put;
672 if (ppdevice ==
NULL) {
676 goto exit_device_put;
687 timer = init_lirc_timer();
695 goto exit_device_put;
706 driver.
dev = &lirc_parallel_dev->
dev;
708 if (driver.
minor < 0) {
713 goto exit_device_put;
721 exit_driver_unregister:
726 static void __exit lirc_parallel_exit(
void)