title: work with parallel port interrupt
body: <p>I am working on parallel port driver. Now i had seen the methods to get interrupt from parallel port.</p>
  
  <p>by one of them,</p>
  
  <blockquote>
    <p>First make 4th pin of control reg 1(IRQ).
    then make nACK low.</p>
  </blockquote>
  
  <p>so i make a switch in between data pin 8 and nACK. so, if i write some data which has msb 1 then it will be interrupted, if that switch is on. Now i have a problem. If i disconnected that switch and again connect then it will not give me interrupt.</p>
  
  <p>So, how can i do that thing by which i got interrupt by means of switch is connect or not. </p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/fs.h&gt;
  #include &lt;linux/parport.h&gt;
  #include &lt;asm/uaccess.h&gt;
  #include &lt;linux/platform_device.h&gt;
  #include &lt;linux/interrupt.h&gt;
  #include &lt;asm/io.h&gt;
  #include &lt;linux/errno.h&gt;
  #include &lt;asm/irq.h&gt;
  #include &lt;linux/kthread.h&gt;
  
  #define DEVICE_NAME "parlelport"
  
  struct pardevice *pdev;
  static int dummy;
  int ret;
  
  static irqreturn_t recv_handler(int irq, void *dev_id)
  {
      printk("we inside if isr"); 
  
      return 0;
  }
  
  int led_open(struct inode *inode, struct file *file)
  {
      printk("1\n");
      printk("Device File Opened\n");
  
      char byte1;
      byte1=inb(0x37A);
      printk("%d     \n",byte1);
  
      return 0;
  }
  
  ssize_t led_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
  {
      printk("2\n");
  
      char byte=inb(0x37A);
      printk("%d",byte);
      byte = byte | 0x10;     // 0x10= 00010000, 4th pin of CTRL reg
      outb(byte, 0x37A);      //which enable IRQ
  
      char kbuf;
      copy_from_user(&amp;kbuf, buf, 1);
      parport_claim_or_block(pdev);       /* Claim the port */
      parport_write_data(pdev-&gt;port, kbuf);   /* Write to the device */
      //parport_release (pdev);
  
      return count;
  }
  
  int led_release(struct inode *inode, struct file *file)
  {
      printk("3\n");
      printk("Device File Released\n");
  
      char byte;
      byte=inb(0x37A);
      printk("%d", byte);
      return 0;
  }
  
  static struct file_operations led_fops = {
      .owner = THIS_MODULE,
      .open = led_open,
      .write = led_write,
      .release = led_release,
  };
  
  
  static int led_preempt(void *handle)
  {
      printk("4\n");
      return 1;
  }
  
  static void led_attach(struct parport *port)
  {
      printk("5\n");
      pdev = parport_register_device(port, DEVICE_NAME, led_preempt, NULL, NULL, 0, NULL);
      printk("Port attached\n");
  
      char byte1;
      byte1=inb(0x37A);
      printk("%d \n",byte1);
  }
  
  static void led_detach(struct parport *port)
  {
      printk("6\n");
      parport_unregister_device (pdev);
      printk("Port Deattached\n");
  }
  
  static struct parport_driver led_driver = {
      .name= "led",
      .attach = led_attach,
      .detach = led_detach,
  };
  
  int __init led_init(void)
  {
      printk("7\n");
  
  
      if (register_chrdev(89, DEVICE_NAME, &amp;led_fops)) 
      {
      printk("Can't register device\n");
      return -1;
      }
  
      char byte=inb(0x37A);
      printk("%d",byte);
      byte = byte | 0x10;
      outb(byte, 0x37A);
  
      char byte1;
      byte1=inb(0x37A);
      printk("%d     %d \n",byte,byte1);
  
      parport_register_driver(&amp;led_driver);
  
      ret= request_irq(7, recv_handler, IRQF_SHARED, "parlelport", &amp;dummy);   
      printk("%d",ret);
  
      return 0;
  }
  
  void __exit led_cleanup(void)
  {
      printk("8\n");
      unregister_chrdev(89, DEVICE_NAME);
  
      if(!ret)
      free_irq(7, &amp;dummy);
  
      parport_unregister_driver(&amp;led_driver);
      printk("LED Driver unregistered.\n");
      return;
  }
  
  module_init(led_init);
  module_exit(led_cleanup);
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Vikrant Patel");
  </code></pre>
  
  <p>Test.c file</p>
  
  <pre><code>int main()
  { 
  
  
      int fd=open("/dev/parlelport",O_RDWR);
      char byte;
  
      printf("Enter Value to send on parallel port");
      scanf("%c",&amp;byte);
  
      printf("Byte value is %c\n",byte);
      if(write(fd,&amp;byte,sizeof(char)))
      {
          printf("\nSuccessfully written on port");
      }
  
      getchar();
      getchar();
  
      close(fd);
  }
  </code></pre>