2 * Telecom Clock driver for Intel NetStructure(tm) MPCBL0010
4 * Copyright (C) 2005 Kontron Canada
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Send feedback to <sebastien.bouchard@ca.kontron.com> and the current
24 * Maintainer <mark.gross@intel.com>
26 * Description : This is the TELECOM CLOCK module driver for the ATCA
27 * MPCBL0010 ATCA computer.
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/sched.h>
34 #include <linux/kernel.h> /* printk() */
35 #include <linux/fs.h> /* everything... */
36 #include <linux/errno.h> /* error codes */
37 #include <linux/delay.h> /* udelay */
38 #include <linux/slab.h>
39 #include <linux/ioport.h>
40 #include <linux/interrupt.h>
41 #include <linux/spinlock.h>
42 #include <linux/timer.h>
43 #include <linux/sysfs.h>
44 #include <linux/device.h>
45 #include <linux/miscdevice.h>
46 #include <asm/io.h> /* inb/outb */
47 #include <asm/uaccess.h>
49 MODULE_AUTHOR("Sebastien Bouchard <sebastien.bouchard@ca.kontron.com>");
50 MODULE_LICENSE("GPL");
52 /*Hardware Reset of the PLL */
54 #define RESET_OFF 0x01
57 #define NORMAL_MODE 0x00
58 #define HOLDOVER_MODE 0x10
59 #define FREERUN_MODE 0x20
62 #define FILTER_6HZ 0x04
63 #define FILTER_12HZ 0x00
65 /* SELECT REFERENCE FREQUENCY */
66 #define REF_CLK1_8kHz 0x00
67 #define REF_CLK2_19_44MHz 0x02
69 /* Select primary or secondary redundant clock */
70 #define PRIMARY_CLOCK 0x00
71 #define SECONDARY_CLOCK 0x01
73 /* CLOCK TRANSMISSION DEFINE */
75 #define CLK_16_384MHz 0xfb
77 #define CLK_1_544MHz 0x00
78 #define CLK_2_048MHz 0x01
79 #define CLK_4_096MHz 0x02
80 #define CLK_6_312MHz 0x03
81 #define CLK_8_192MHz 0x04
82 #define CLK_19_440MHz 0x06
84 #define CLK_8_592MHz 0x08
85 #define CLK_11_184MHz 0x09
86 #define CLK_34_368MHz 0x0b
87 #define CLK_44_736MHz 0x0a
89 /* RECEIVED REFERENCE */
93 /* HARDWARE SWITCHING DEFINE */
94 #define HW_ENABLE 0x80
95 #define HW_DISABLE 0x00
97 /* HARDWARE SWITCHING MODE DEFINE */
98 #define PLL_HOLDOVER 0x40
99 #define LOST_CLOCK 0x00
102 #define UNLOCK_MASK 0x10
103 #define HOLDOVER_MASK 0x20
104 #define SEC_LOST_MASK 0x40
105 #define PRI_LOST_MASK 0x80
107 /* INTERRUPT CAUSE DEFINE */
109 #define PRI_LOS_01_MASK 0x01
110 #define PRI_LOS_10_MASK 0x02
112 #define SEC_LOS_01_MASK 0x04
113 #define SEC_LOS_10_MASK 0x08
115 #define HOLDOVER_01_MASK 0x10
116 #define HOLDOVER_10_MASK 0x20
118 #define UNLOCK_01_MASK 0x40
119 #define UNLOCK_10_MASK 0x80
121 struct tlclk_alarms {
123 __u32 lost_primary_clock;
124 __u32 lost_secondary_clock;
125 __u32 primary_clock_back;
126 __u32 secondary_clock_back;
127 __u32 switchover_primary;
128 __u32 switchover_secondary;
130 __u32 pll_end_holdover;
134 /* Telecom clock I/O register definition */
135 #define TLCLK_BASE 0xa08
136 #define TLCLK_REG0 TLCLK_BASE
137 #define TLCLK_REG1 (TLCLK_BASE+1)
138 #define TLCLK_REG2 (TLCLK_BASE+2)
139 #define TLCLK_REG3 (TLCLK_BASE+3)
140 #define TLCLK_REG4 (TLCLK_BASE+4)
141 #define TLCLK_REG5 (TLCLK_BASE+5)
142 #define TLCLK_REG6 (TLCLK_BASE+6)
143 #define TLCLK_REG7 (TLCLK_BASE+7)
145 #define SET_PORT_BITS(port, mask, val) outb(((inb(port) & mask) | val), port)
147 /* 0 = Dynamic allocation of the major device number */
148 #define TLCLK_MAJOR 0
150 /* sysfs interface definition:
151 Upon loading the driver will create a sysfs directory under
152 /sys/devices/platform/telco_clock.
154 This directory exports the following interfaces. There operation is
155 documented in the MCPBL0010 TPS under the Telecom Clock API section, 11.4.
158 enable_clk3a_output :
159 enable_clk3b_output :
160 enable_clka0_output :
161 enable_clka1_output :
162 enable_clkb0_output :
163 enable_clkb1_output :
166 hardware_switching_mode :
171 select_amcb1_transmit_clock :
172 select_amcb2_transmit_clock :
173 select_redundant_clock :
174 select_ref_frequency :
177 All sysfs interfaces are integers in hex format, i.e echo 99 > refalign
178 has the same effect as echo 0x99 > refalign.
181 static unsigned int telclk_interrupt;
183 static int int_events; /* Event that generate a interrupt */
184 static int got_event; /* if events processing have been done */
186 static void switchover_timeout(unsigned long data);
187 static struct timer_list switchover_timer =
188 TIMER_INITIALIZER(switchover_timeout , 0, 0);
190 static struct tlclk_alarms *alarm_events;
192 static DEFINE_SPINLOCK(event_lock);
194 static int tlclk_major = TLCLK_MAJOR;
196 static irqreturn_t tlclk_interrupt(int irq, void *dev_id, struct pt_regs *regs);
198 static DECLARE_WAIT_QUEUE_HEAD(wq);
200 static int tlclk_open(struct inode *inode, struct file *filp)
204 /* Make sure there is no interrupt pending while
205 * initialising interrupt handler */
208 /* This device is wired through the FPGA IO space of the ATCA blade
209 * we can't share this IRQ */
210 result = request_irq(telclk_interrupt, &tlclk_interrupt,
211 SA_INTERRUPT, "telco_clock", tlclk_interrupt);
212 if (result == -EBUSY) {
213 printk(KERN_ERR "telco_clock: Interrupt can't be reserved!\n");
216 inb(TLCLK_REG6); /* Clear interrupt events */
221 static int tlclk_release(struct inode *inode, struct file *filp)
223 free_irq(telclk_interrupt, tlclk_interrupt);
228 ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count,
231 if (count < sizeof(struct tlclk_alarms))
234 wait_event_interruptible(wq, got_event);
235 if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms)))
238 memset(alarm_events, 0, sizeof(struct tlclk_alarms));
241 return sizeof(struct tlclk_alarms);
244 ssize_t tlclk_write(struct file *filp, const char __user *buf, size_t count,
250 static struct file_operations tlclk_fops = {
252 .write = tlclk_write,
254 .release = tlclk_release,
258 static struct miscdevice tlclk_miscdev = {
259 .minor = MISC_DYNAMIC_MINOR,
260 .name = "telco_clock",
264 static ssize_t show_current_ref(struct device *d,
265 struct device_attribute *attr, char *buf)
267 unsigned long ret_val;
270 spin_lock_irqsave(&event_lock, flags);
271 ret_val = ((inb(TLCLK_REG1) & 0x08) >> 3);
272 spin_unlock_irqrestore(&event_lock, flags);
274 return sprintf(buf, "0x%lX\n", ret_val);
277 static DEVICE_ATTR(current_ref, S_IRUGO, show_current_ref, NULL);
280 static ssize_t show_interrupt_switch(struct device *d,
281 struct device_attribute *attr, char *buf)
283 unsigned long ret_val;
286 spin_lock_irqsave(&event_lock, flags);
287 ret_val = inb(TLCLK_REG6);
288 spin_unlock_irqrestore(&event_lock, flags);
290 return sprintf(buf, "0x%lX\n", ret_val);
293 static DEVICE_ATTR(interrupt_switch, S_IRUGO,
294 show_interrupt_switch, NULL);
296 static ssize_t show_alarms(struct device *d,
297 struct device_attribute *attr, char *buf)
299 unsigned long ret_val;
302 spin_lock_irqsave(&event_lock, flags);
303 ret_val = (inb(TLCLK_REG2) & 0xf0);
304 spin_unlock_irqrestore(&event_lock, flags);
306 return sprintf(buf, "0x%lX\n", ret_val);
309 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
311 static ssize_t store_enable_clk3b_output(struct device *d,
312 struct device_attribute *attr, const char *buf, size_t count)
318 sscanf(buf, "%lX", &tmp);
319 dev_dbg(d, ": tmp = 0x%lX\n", tmp);
321 val = (unsigned char)tmp;
322 spin_lock_irqsave(&event_lock, flags);
323 SET_PORT_BITS(TLCLK_REG3, 0x7f, val << 7);
324 spin_unlock_irqrestore(&event_lock, flags);
326 return strnlen(buf, count);
329 static DEVICE_ATTR(enable_clk3b_output, S_IWUGO, NULL,
330 store_enable_clk3b_output);
332 static ssize_t store_enable_clk3a_output(struct device *d,
333 struct device_attribute *attr, const char *buf, size_t count)
339 sscanf(buf, "%lX", &tmp);
340 dev_dbg(d, "tmp = 0x%lX\n", tmp);
342 val = (unsigned char)tmp;
343 spin_lock_irqsave(&event_lock, flags);
344 SET_PORT_BITS(TLCLK_REG3, 0xbf, val << 6);
345 spin_unlock_irqrestore(&event_lock, flags);
347 return strnlen(buf, count);
350 static DEVICE_ATTR(enable_clk3a_output, S_IWUGO, NULL,
351 store_enable_clk3a_output);
353 static ssize_t store_enable_clkb1_output(struct device *d,
354 struct device_attribute *attr, const char *buf, size_t count)
360 sscanf(buf, "%lX", &tmp);
361 dev_dbg(d, "tmp = 0x%lX\n", tmp);
363 val = (unsigned char)tmp;
364 spin_lock_irqsave(&event_lock, flags);
365 SET_PORT_BITS(TLCLK_REG2, 0xf7, val << 3);
366 spin_unlock_irqrestore(&event_lock, flags);
368 return strnlen(buf, count);
371 static DEVICE_ATTR(enable_clkb1_output, S_IWUGO, NULL,
372 store_enable_clkb1_output);
375 static ssize_t store_enable_clka1_output(struct device *d,
376 struct device_attribute *attr, const char *buf, size_t count)
382 sscanf(buf, "%lX", &tmp);
383 dev_dbg(d, "tmp = 0x%lX\n", tmp);
385 val = (unsigned char)tmp;
386 spin_lock_irqsave(&event_lock, flags);
387 SET_PORT_BITS(TLCLK_REG2, 0xfb, val << 2);
388 spin_unlock_irqrestore(&event_lock, flags);
390 return strnlen(buf, count);
393 static DEVICE_ATTR(enable_clka1_output, S_IWUGO, NULL,
394 store_enable_clka1_output);
396 static ssize_t store_enable_clkb0_output(struct device *d,
397 struct device_attribute *attr, const char *buf, size_t count)
403 sscanf(buf, "%lX", &tmp);
404 dev_dbg(d, "tmp = 0x%lX\n", tmp);
406 val = (unsigned char)tmp;
407 spin_lock_irqsave(&event_lock, flags);
408 SET_PORT_BITS(TLCLK_REG2, 0xfd, val << 1);
409 spin_unlock_irqrestore(&event_lock, flags);
411 return strnlen(buf, count);
414 static DEVICE_ATTR(enable_clkb0_output, S_IWUGO, NULL,
415 store_enable_clkb0_output);
417 static ssize_t store_enable_clka0_output(struct device *d,
418 struct device_attribute *attr, const char *buf, size_t count)
424 sscanf(buf, "%lX", &tmp);
425 dev_dbg(d, "tmp = 0x%lX\n", tmp);
427 val = (unsigned char)tmp;
428 spin_lock_irqsave(&event_lock, flags);
429 SET_PORT_BITS(TLCLK_REG2, 0xfe, val);
430 spin_unlock_irqrestore(&event_lock, flags);
432 return strnlen(buf, count);
435 static DEVICE_ATTR(enable_clka0_output, S_IWUGO, NULL,
436 store_enable_clka0_output);
438 static ssize_t store_test_mode(struct device *d,
439 struct device_attribute *attr, const char *buf, size_t count)
445 sscanf(buf, "%lX", &tmp);
446 dev_dbg(d, "tmp = 0x%lX\n", tmp);
448 val = (unsigned char)tmp;
449 spin_lock_irqsave(&event_lock, flags);
450 SET_PORT_BITS(TLCLK_REG4, 0xfd, 2);
451 spin_unlock_irqrestore(&event_lock, flags);
453 return strnlen(buf, count);
456 static DEVICE_ATTR(test_mode, S_IWUGO, NULL, store_test_mode);
458 static ssize_t store_select_amcb2_transmit_clock(struct device *d,
459 struct device_attribute *attr, const char *buf, size_t count)
465 sscanf(buf, "%lX", &tmp);
466 dev_dbg(d, "tmp = 0x%lX\n", tmp);
468 val = (unsigned char)tmp;
469 spin_lock_irqsave(&event_lock, flags);
470 if ((val == CLK_8kHz) || (val == CLK_16_384MHz)) {
471 SET_PORT_BITS(TLCLK_REG3, 0xc7, 0x28);
472 SET_PORT_BITS(TLCLK_REG1, 0xfb, ~val);
473 } else if (val >= CLK_8_592MHz) {
474 SET_PORT_BITS(TLCLK_REG3, 0xc7, 0x38);
477 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
480 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
483 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
486 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
490 SET_PORT_BITS(TLCLK_REG3, 0xc7, val << 3);
492 spin_unlock_irqrestore(&event_lock, flags);
494 return strnlen(buf, count);
497 static DEVICE_ATTR(select_amcb2_transmit_clock, S_IWUGO, NULL,
498 store_select_amcb2_transmit_clock);
500 static ssize_t store_select_amcb1_transmit_clock(struct device *d,
501 struct device_attribute *attr, const char *buf, size_t count)
507 sscanf(buf, "%lX", &tmp);
508 dev_dbg(d, "tmp = 0x%lX\n", tmp);
510 val = (unsigned char)tmp;
511 spin_lock_irqsave(&event_lock, flags);
512 if ((val == CLK_8kHz) || (val == CLK_16_384MHz)) {
513 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x5);
514 SET_PORT_BITS(TLCLK_REG1, 0xfb, ~val);
515 } else if (val >= CLK_8_592MHz) {
516 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7);
519 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
522 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
525 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
528 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
532 SET_PORT_BITS(TLCLK_REG3, 0xf8, val);
533 spin_unlock_irqrestore(&event_lock, flags);
535 return strnlen(buf, count);
538 static DEVICE_ATTR(select_amcb1_transmit_clock, S_IWUGO, NULL,
539 store_select_amcb1_transmit_clock);
541 static ssize_t store_select_redundant_clock(struct device *d,
542 struct device_attribute *attr, const char *buf, size_t count)
548 sscanf(buf, "%lX", &tmp);
549 dev_dbg(d, "tmp = 0x%lX\n", tmp);
551 val = (unsigned char)tmp;
552 spin_lock_irqsave(&event_lock, flags);
553 SET_PORT_BITS(TLCLK_REG1, 0xfe, val);
554 spin_unlock_irqrestore(&event_lock, flags);
556 return strnlen(buf, count);
559 static DEVICE_ATTR(select_redundant_clock, S_IWUGO, NULL,
560 store_select_redundant_clock);
562 static ssize_t store_select_ref_frequency(struct device *d,
563 struct device_attribute *attr, const char *buf, size_t count)
569 sscanf(buf, "%lX", &tmp);
570 dev_dbg(d, "tmp = 0x%lX\n", tmp);
572 val = (unsigned char)tmp;
573 spin_lock_irqsave(&event_lock, flags);
574 SET_PORT_BITS(TLCLK_REG1, 0xfd, val);
575 spin_unlock_irqrestore(&event_lock, flags);
577 return strnlen(buf, count);
580 static DEVICE_ATTR(select_ref_frequency, S_IWUGO, NULL,
581 store_select_ref_frequency);
583 static ssize_t store_filter_select(struct device *d,
584 struct device_attribute *attr, const char *buf, size_t count)
590 sscanf(buf, "%lX", &tmp);
591 dev_dbg(d, "tmp = 0x%lX\n", tmp);
593 val = (unsigned char)tmp;
594 spin_lock_irqsave(&event_lock, flags);
595 SET_PORT_BITS(TLCLK_REG0, 0xfb, val);
596 spin_unlock_irqrestore(&event_lock, flags);
598 return strnlen(buf, count);
601 static DEVICE_ATTR(filter_select, S_IWUGO, NULL, store_filter_select);
603 static ssize_t store_hardware_switching_mode(struct device *d,
604 struct device_attribute *attr, const char *buf, size_t count)
610 sscanf(buf, "%lX", &tmp);
611 dev_dbg(d, "tmp = 0x%lX\n", tmp);
613 val = (unsigned char)tmp;
614 spin_lock_irqsave(&event_lock, flags);
615 SET_PORT_BITS(TLCLK_REG0, 0xbf, val);
616 spin_unlock_irqrestore(&event_lock, flags);
618 return strnlen(buf, count);
621 static DEVICE_ATTR(hardware_switching_mode, S_IWUGO, NULL,
622 store_hardware_switching_mode);
624 static ssize_t store_hardware_switching(struct device *d,
625 struct device_attribute *attr, const char *buf, size_t count)
631 sscanf(buf, "%lX", &tmp);
632 dev_dbg(d, "tmp = 0x%lX\n", tmp);
634 val = (unsigned char)tmp;
635 spin_lock_irqsave(&event_lock, flags);
636 SET_PORT_BITS(TLCLK_REG0, 0x7f, val);
637 spin_unlock_irqrestore(&event_lock, flags);
639 return strnlen(buf, count);
642 static DEVICE_ATTR(hardware_switching, S_IWUGO, NULL,
643 store_hardware_switching);
645 static ssize_t store_refalign (struct device *d,
646 struct device_attribute *attr, const char *buf, size_t count)
651 sscanf(buf, "%lX", &tmp);
652 dev_dbg(d, "tmp = 0x%lX\n", tmp);
653 spin_lock_irqsave(&event_lock, flags);
654 SET_PORT_BITS(TLCLK_REG0, 0xf7, 0);
656 SET_PORT_BITS(TLCLK_REG0, 0xf7, 0x08);
658 SET_PORT_BITS(TLCLK_REG0, 0xf7, 0);
659 spin_unlock_irqrestore(&event_lock, flags);
661 return strnlen(buf, count);
664 static DEVICE_ATTR(refalign, S_IWUGO, NULL, store_refalign);
666 static ssize_t store_mode_select (struct device *d,
667 struct device_attribute *attr, const char *buf, size_t count)
673 sscanf(buf, "%lX", &tmp);
674 dev_dbg(d, "tmp = 0x%lX\n", tmp);
676 val = (unsigned char)tmp;
677 spin_lock_irqsave(&event_lock, flags);
678 SET_PORT_BITS(TLCLK_REG0, 0xcf, val);
679 spin_unlock_irqrestore(&event_lock, flags);
681 return strnlen(buf, count);
684 static DEVICE_ATTR(mode_select, S_IWUGO, NULL, store_mode_select);
686 static ssize_t store_reset (struct device *d,
687 struct device_attribute *attr, const char *buf, size_t count)
693 sscanf(buf, "%lX", &tmp);
694 dev_dbg(d, "tmp = 0x%lX\n", tmp);
696 val = (unsigned char)tmp;
697 spin_lock_irqsave(&event_lock, flags);
698 SET_PORT_BITS(TLCLK_REG4, 0xfd, val);
699 spin_unlock_irqrestore(&event_lock, flags);
701 return strnlen(buf, count);
704 static DEVICE_ATTR(reset, S_IWUGO, NULL, store_reset);
706 static struct attribute *tlclk_sysfs_entries[] = {
707 &dev_attr_current_ref.attr,
708 &dev_attr_interrupt_switch.attr,
709 &dev_attr_alarms.attr,
710 &dev_attr_enable_clk3a_output.attr,
711 &dev_attr_enable_clk3b_output.attr,
712 &dev_attr_enable_clkb1_output.attr,
713 &dev_attr_enable_clka1_output.attr,
714 &dev_attr_enable_clkb0_output.attr,
715 &dev_attr_enable_clka0_output.attr,
716 &dev_attr_test_mode.attr,
717 &dev_attr_select_amcb1_transmit_clock.attr,
718 &dev_attr_select_amcb2_transmit_clock.attr,
719 &dev_attr_select_redundant_clock.attr,
720 &dev_attr_select_ref_frequency.attr,
721 &dev_attr_filter_select.attr,
722 &dev_attr_hardware_switching_mode.attr,
723 &dev_attr_hardware_switching.attr,
724 &dev_attr_refalign.attr,
725 &dev_attr_mode_select.attr,
726 &dev_attr_reset.attr,
730 static struct attribute_group tlclk_attribute_group = {
731 .name = NULL, /* put in device directory */
732 .attrs = tlclk_sysfs_entries,
735 static struct platform_device *tlclk_device;
737 static int __init tlclk_init(void)
741 ret = register_chrdev(tlclk_major, "telco_clock", &tlclk_fops);
743 printk(KERN_ERR "telco_clock: can't get major! %d\n", tlclk_major);
746 alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL);
750 /* Read telecom clock IRQ number (Set by BIOS) */
751 if (!request_region(TLCLK_BASE, 8, "telco_clock")) {
752 printk(KERN_ERR "tlclk: request_region failed! 0x%X\n",
757 telclk_interrupt = (inb(TLCLK_REG7) & 0x0f);
759 if (0x0F == telclk_interrupt ) { /* not MCPBL0010 ? */
760 printk(KERN_ERR "telclk_interrup = 0x%x non-mcpbl0010 hw\n",
766 init_timer(&switchover_timer);
768 ret = misc_register(&tlclk_miscdev);
770 printk(KERN_ERR " misc_register retruns %d\n", ret);
775 tlclk_device = platform_device_register_simple("telco_clock",
778 printk(KERN_ERR " platform_device_register retruns 0x%X\n",
779 (unsigned int) tlclk_device);
784 ret = sysfs_create_group(&tlclk_device->dev.kobj,
785 &tlclk_attribute_group);
787 printk(KERN_ERR "failed to create sysfs device attributes\n");
788 sysfs_remove_group(&tlclk_device->dev.kobj,
789 &tlclk_attribute_group);
795 platform_device_unregister(tlclk_device);
797 misc_deregister(&tlclk_miscdev);
799 release_region(TLCLK_BASE, 8);
803 unregister_chrdev(tlclk_major, "telco_clock");
807 static void __exit tlclk_cleanup(void)
809 sysfs_remove_group(&tlclk_device->dev.kobj, &tlclk_attribute_group);
810 platform_device_unregister(tlclk_device);
811 misc_deregister(&tlclk_miscdev);
812 unregister_chrdev(tlclk_major, "telco_clock");
814 release_region(TLCLK_BASE, 8);
815 del_timer_sync(&switchover_timer);
820 static void switchover_timeout(unsigned long data)
823 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08))
824 alarm_events->switchover_primary++;
826 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08))
827 alarm_events->switchover_secondary++;
830 /* Alarm processing is done, wake up read task */
831 del_timer(&switchover_timer);
836 static irqreturn_t tlclk_interrupt(int irq, void *dev_id, struct pt_regs *regs)
840 spin_lock_irqsave(&event_lock, flags);
841 /* Read and clear interrupt events */
842 int_events = inb(TLCLK_REG6);
844 /* Primary_Los changed from 0 to 1 ? */
845 if (int_events & PRI_LOS_01_MASK) {
846 if (inb(TLCLK_REG2) & SEC_LOST_MASK)
847 alarm_events->lost_clocks++;
849 alarm_events->lost_primary_clock++;
852 /* Primary_Los changed from 1 to 0 ? */
853 if (int_events & PRI_LOS_10_MASK) {
854 alarm_events->primary_clock_back++;
855 SET_PORT_BITS(TLCLK_REG1, 0xFE, 1);
857 /* Secondary_Los changed from 0 to 1 ? */
858 if (int_events & SEC_LOS_01_MASK) {
859 if (inb(TLCLK_REG2) & PRI_LOST_MASK)
860 alarm_events->lost_clocks++;
862 alarm_events->lost_secondary_clock++;
864 /* Secondary_Los changed from 1 to 0 ? */
865 if (int_events & SEC_LOS_10_MASK) {
866 alarm_events->secondary_clock_back++;
867 SET_PORT_BITS(TLCLK_REG1, 0xFE, 0);
869 if (int_events & HOLDOVER_10_MASK)
870 alarm_events->pll_end_holdover++;
872 if (int_events & UNLOCK_01_MASK)
873 alarm_events->pll_lost_sync++;
875 if (int_events & UNLOCK_10_MASK)
876 alarm_events->pll_sync++;
878 /* Holdover changed from 0 to 1 ? */
879 if (int_events & HOLDOVER_01_MASK) {
880 alarm_events->pll_holdover++;
882 /* TIMEOUT in ~10ms */
883 switchover_timer.expires = jiffies + msecs_to_jiffies(10);
884 switchover_timer.data = inb(TLCLK_REG1);
885 add_timer(&switchover_timer);
890 spin_unlock_irqrestore(&event_lock, flags);
895 module_init(tlclk_init);
896 module_exit(tlclk_cleanup);