30 #include <linux/module.h>
32 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include <linux/sched.h>
36 #include <linux/slab.h>
43 #include <linux/device.h>
47 #include <asm/uaccess.h>
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
66 #define REF_CLK1_8kHz 0x00
67 #define REF_CLK2_19_44MHz 0x02
70 #define PRIMARY_CLOCK 0x00
71 #define SECONDARY_CLOCK 0x01
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
94 #define HW_ENABLE 0x80
95 #define HW_DISABLE 0x00
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
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
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)
148 #define TLCLK_MAJOR 0
182 static unsigned int telclk_interrupt;
184 static int int_events;
185 static int got_event;
187 static void switchover_timeout(
unsigned long data);
190 static unsigned long tlclk_timer_data;
202 static unsigned long useflags;
224 result =
request_irq(telclk_interrupt, &tlclk_interrupt,
226 if (result == -
EBUSY)
236 static int tlclk_release(
struct inode *inode,
struct file *filp)
238 free_irq(telclk_interrupt, tlclk_interrupt);
269 .release = tlclk_release,
276 .name =
"telco_clock",
283 unsigned long ret_val;
288 spin_unlock_irqrestore(&event_lock, flags);
290 return sprintf(buf,
"0x%lX\n", ret_val);
299 unsigned long ret_val;
304 spin_unlock_irqrestore(&event_lock, flags);
306 return sprintf(buf,
"0x%lX\n", ret_val);
310 show_telclock_version,
NULL);
315 unsigned long ret_val;
320 spin_unlock_irqrestore(&event_lock, flags);
322 return sprintf(buf,
"0x%lX\n", ret_val);
335 dev_dbg(d,
": tmp = 0x%lX\n", tmp);
337 val = (
unsigned char)tmp;
340 spin_unlock_irqrestore(&event_lock, flags);
346 store_received_ref_clk3a);
357 dev_dbg(d,
": tmp = 0x%lX\n", tmp);
359 val = (
unsigned char)tmp;
362 spin_unlock_irqrestore(&event_lock, flags);
368 store_received_ref_clk3b);
379 dev_dbg(d,
": tmp = 0x%lX\n", tmp);
381 val = (
unsigned char)tmp;
384 spin_unlock_irqrestore(&event_lock, flags);
390 store_enable_clk3b_output);
400 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
402 val = (
unsigned char)tmp;
405 spin_unlock_irqrestore(&event_lock, flags);
411 store_enable_clk3a_output);
421 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
423 val = (
unsigned char)tmp;
426 spin_unlock_irqrestore(&event_lock, flags);
432 store_enable_clkb1_output);
443 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
445 val = (
unsigned char)tmp;
448 spin_unlock_irqrestore(&event_lock, flags);
454 store_enable_clka1_output);
464 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
466 val = (
unsigned char)tmp;
469 spin_unlock_irqrestore(&event_lock, flags);
475 store_enable_clkb0_output);
485 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
487 val = (
unsigned char)tmp;
490 spin_unlock_irqrestore(&event_lock, flags);
496 store_enable_clka0_output);
498 static ssize_t store_select_amcb2_transmit_clock(
struct device *
d,
506 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
508 val = (
unsigned char)tmp;
532 spin_unlock_irqrestore(&event_lock, flags);
538 store_select_amcb2_transmit_clock);
540 static ssize_t store_select_amcb1_transmit_clock(
struct device *d,
548 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
550 val = (
unsigned char)tmp;
573 spin_unlock_irqrestore(&event_lock, flags);
579 store_select_amcb1_transmit_clock);
581 static ssize_t store_select_redundant_clock(
struct device *d,
589 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
591 val = (
unsigned char)tmp;
594 spin_unlock_irqrestore(&event_lock, flags);
600 store_select_redundant_clock);
610 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
612 val = (
unsigned char)tmp;
615 spin_unlock_irqrestore(&event_lock, flags);
621 store_select_ref_frequency);
631 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
633 val = (
unsigned char)tmp;
636 spin_unlock_irqrestore(&event_lock, flags);
643 static ssize_t store_hardware_switching_mode(
struct device *d,
651 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
653 val = (
unsigned char)tmp;
656 spin_unlock_irqrestore(&event_lock, flags);
662 store_hardware_switching_mode);
672 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
674 val = (
unsigned char)tmp;
677 spin_unlock_irqrestore(&event_lock, flags);
683 store_hardware_switching);
692 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
697 spin_unlock_irqrestore(&event_lock, flags);
712 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
714 val = (
unsigned char)tmp;
717 spin_unlock_irqrestore(&event_lock, flags);
732 dev_dbg(d,
"tmp = 0x%lX\n", tmp);
734 val = (
unsigned char)tmp;
737 spin_unlock_irqrestore(&event_lock, flags);
744 static struct attribute *tlclk_sysfs_entries[] = {
745 &dev_attr_current_ref.attr,
746 &dev_attr_telclock_version.attr,
747 &dev_attr_alarms.attr,
748 &dev_attr_received_ref_clk3a.attr,
749 &dev_attr_received_ref_clk3b.attr,
750 &dev_attr_enable_clk3a_output.attr,
751 &dev_attr_enable_clk3b_output.attr,
752 &dev_attr_enable_clkb1_output.attr,
753 &dev_attr_enable_clka1_output.attr,
754 &dev_attr_enable_clkb0_output.attr,
755 &dev_attr_enable_clka0_output.attr,
756 &dev_attr_select_amcb1_transmit_clock.attr,
757 &dev_attr_select_amcb2_transmit_clock.attr,
758 &dev_attr_select_redundant_clock.attr,
759 &dev_attr_select_ref_frequency.attr,
760 &dev_attr_filter_select.attr,
761 &dev_attr_hardware_switching_mode.attr,
762 &dev_attr_hardware_switching.attr,
763 &dev_attr_refalign.attr,
764 &dev_attr_mode_select.attr,
765 &dev_attr_reset.attr,
771 .attrs = tlclk_sysfs_entries,
776 static int __init tlclk_init(
void)
780 ret = register_chrdev(tlclk_major,
"telco_clock", &tlclk_fops);
801 if (0x0F == telclk_interrupt ) {
816 tlclk_device = platform_device_register_simple(
"telco_clock",
818 if (IS_ERR(tlclk_device)) {
820 ret = PTR_ERR(tlclk_device);
825 &tlclk_attribute_group);
827 printk(
KERN_ERR "tlclk: failed to create sysfs device attributes.\n");
841 unregister_chrdev(tlclk_major,
"telco_clock");
845 static void __exit tlclk_cleanup(
void)
850 unregister_chrdev(tlclk_major,
"telco_clock");
858 static void switchover_timeout(
unsigned long data)
860 unsigned long flags = *(
unsigned long *) data;
925 switchover_timer.
data = (
unsigned long) &tlclk_timer_data;
931 spin_unlock_irqrestore(&event_lock, flags);