-/* send a high / low clock impulse of <duration> microseconds high and low */
-static void smartcard_send_clock(int duration)
-{
- int old;
-
- w_dtr(pprt, (old = r_dtr(pprt)) | PNL_SC_CLK);
- udelay(duration);
- w_dtr(pprt, (old & ~PNL_SC_CLK));
- udelay(duration);
-}
-
-static void smartcard_insert(int dummy)
-{
- int ofs;
-
- spin_lock(&pprt_lock);
- w_dtr(pprt, (r_dtr(pprt) & ~PNL_SC_BITS));
- w_ctr(pprt, (r_ctr(pprt) | PNL_SC_ENA));
-
- udelay(30); /* ensure the rst is low at least 30 us */
-
- smartcard_send_clock(100); /* reset address counter */
-
- w_dtr(pprt, r_dtr(pprt) | PNL_SC_RST);
- udelay(30); /* ensure the rst is high at least 30 us */
-
- for (ofs = 0; ofs < SMARTCARD_BYTES; ofs++) {
- int bit, byte;
- byte = 0;
- for (bit = 128; bit > 0; bit >>= 1) {
- if (!(r_str(pprt) & PNL_SC_IOR))
- byte |= bit;
- smartcard_send_clock(15); /* 15 us are enough for data */
- }
- smartcard_data[ofs] = byte;
- }
-
- w_dtr(pprt, (r_dtr(pprt) & ~PNL_SC_BITS));
- w_ctr(pprt, (r_ctr(pprt) & ~PNL_SC_ENA));
-
- spin_unlock(&pprt_lock);
-
- printk(KERN_INFO "Panel: smart card inserted : %02x%02x%02x%02x%1x\n",
- smartcard_data[2], smartcard_data[3], smartcard_data[4],
- smartcard_data[5], smartcard_data[6] >> 4);
- keypad_send_key("CardIn\n", 7);
-}
-
-static void smartcard_remove(int dummy)
-{
- printk(KERN_INFO "Panel: smart card removed : %02x%02x%02x%02x%1x\n",
- smartcard_data[2], smartcard_data[3], smartcard_data[4],
- smartcard_data[5], smartcard_data[6] >> 4);
- memset(smartcard_data, 0, sizeof(smartcard_data));
- keypad_send_key("CardOut\n", 8);
-}
-
-/*
- * These are the file operation function for user access to /dev/smartcard
- */
-
-static ssize_t smartcard_read(struct file *file,
- char *buf, size_t count, loff_t *ppos)
-{
-
- unsigned i = *ppos;
- char *tmp = buf;
-
- for (; count-- > 0 && (smartcard_ptr < 9); ++i, ++tmp, ++smartcard_ptr) {
- if (smartcard_ptr & 1)
- put_user('0' +
- (smartcard_data[2 + (smartcard_ptr >> 1)] &
- 0xF), tmp);
- else
- put_user('0' +
- (smartcard_data[2 + (smartcard_ptr >> 1)] >>
- 4), tmp);
- }
- *ppos = i;
-
- return tmp - buf;
-}
-
-static int smartcard_open(struct inode *inode, struct file *file)
-{
-
- if (smartcard_open_cnt)
- return -EBUSY; /* open only once at a time */
-
- if (file->f_mode & FMODE_WRITE) /* device is read-only */
- return -EPERM;
-
- smartcard_ptr = 0; /* flush the buffer on opening */
- smartcard_open_cnt++;
- return 0;
-}
-
-static int smartcard_release(struct inode *inode, struct file *file)
-{
- smartcard_open_cnt--;
- return 0;
-}
-
-static struct file_operations smartcard_fops = {
- .read = smartcard_read, /* read */
- .open = smartcard_open, /* open */
- .release = smartcard_release, /* close */
-};
-
-static struct miscdevice smartcard_dev = {
- SMARTCARD_MINOR,
- "smartcard",
- &smartcard_fops
-};
-