2005-10-31 07:02:55 +08:00
|
|
|
/*
|
|
|
|
* Telecom Clock driver for Intel NetStructure(tm) MPCBL0010
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Kontron Canada
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* Send feedback to <sebastien.bouchard@ca.kontron.com> and the current
|
|
|
|
* Maintainer <mark.gross@intel.com>
|
|
|
|
*
|
|
|
|
* Description : This is the TELECOM CLOCK module driver for the ATCA
|
|
|
|
* MPCBL0010 ATCA computer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h> /* printk() */
|
|
|
|
#include <linux/fs.h> /* everything... */
|
|
|
|
#include <linux/errno.h> /* error codes */
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2005-10-31 07:02:55 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/spinlock.h>
|
2010-09-12 01:31:43 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-10-31 07:02:55 +08:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/miscdevice.h>
|
2005-11-01 15:44:30 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-10-31 07:02:55 +08:00
|
|
|
#include <asm/io.h> /* inb/outb */
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Sebastien Bouchard <sebastien.bouchard@ca.kontron.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/*Hardware Reset of the PLL */
|
|
|
|
#define RESET_ON 0x00
|
|
|
|
#define RESET_OFF 0x01
|
|
|
|
|
|
|
|
/* MODE SELECT */
|
|
|
|
#define NORMAL_MODE 0x00
|
|
|
|
#define HOLDOVER_MODE 0x10
|
|
|
|
#define FREERUN_MODE 0x20
|
|
|
|
|
|
|
|
/* FILTER SELECT */
|
|
|
|
#define FILTER_6HZ 0x04
|
|
|
|
#define FILTER_12HZ 0x00
|
|
|
|
|
|
|
|
/* SELECT REFERENCE FREQUENCY */
|
|
|
|
#define REF_CLK1_8kHz 0x00
|
|
|
|
#define REF_CLK2_19_44MHz 0x02
|
|
|
|
|
|
|
|
/* Select primary or secondary redundant clock */
|
|
|
|
#define PRIMARY_CLOCK 0x00
|
|
|
|
#define SECONDARY_CLOCK 0x01
|
|
|
|
|
|
|
|
/* CLOCK TRANSMISSION DEFINE */
|
|
|
|
#define CLK_8kHz 0xff
|
|
|
|
#define CLK_16_384MHz 0xfb
|
|
|
|
|
|
|
|
#define CLK_1_544MHz 0x00
|
|
|
|
#define CLK_2_048MHz 0x01
|
|
|
|
#define CLK_4_096MHz 0x02
|
|
|
|
#define CLK_6_312MHz 0x03
|
|
|
|
#define CLK_8_192MHz 0x04
|
|
|
|
#define CLK_19_440MHz 0x06
|
|
|
|
|
|
|
|
#define CLK_8_592MHz 0x08
|
|
|
|
#define CLK_11_184MHz 0x09
|
|
|
|
#define CLK_34_368MHz 0x0b
|
|
|
|
#define CLK_44_736MHz 0x0a
|
|
|
|
|
|
|
|
/* RECEIVED REFERENCE */
|
|
|
|
#define AMC_B1 0
|
|
|
|
#define AMC_B2 1
|
|
|
|
|
|
|
|
/* HARDWARE SWITCHING DEFINE */
|
|
|
|
#define HW_ENABLE 0x80
|
|
|
|
#define HW_DISABLE 0x00
|
|
|
|
|
|
|
|
/* HARDWARE SWITCHING MODE DEFINE */
|
|
|
|
#define PLL_HOLDOVER 0x40
|
|
|
|
#define LOST_CLOCK 0x00
|
|
|
|
|
|
|
|
/* ALARMS DEFINE */
|
|
|
|
#define UNLOCK_MASK 0x10
|
|
|
|
#define HOLDOVER_MASK 0x20
|
|
|
|
#define SEC_LOST_MASK 0x40
|
|
|
|
#define PRI_LOST_MASK 0x80
|
|
|
|
|
|
|
|
/* INTERRUPT CAUSE DEFINE */
|
|
|
|
|
|
|
|
#define PRI_LOS_01_MASK 0x01
|
|
|
|
#define PRI_LOS_10_MASK 0x02
|
|
|
|
|
|
|
|
#define SEC_LOS_01_MASK 0x04
|
|
|
|
#define SEC_LOS_10_MASK 0x08
|
|
|
|
|
|
|
|
#define HOLDOVER_01_MASK 0x10
|
|
|
|
#define HOLDOVER_10_MASK 0x20
|
|
|
|
|
|
|
|
#define UNLOCK_01_MASK 0x40
|
|
|
|
#define UNLOCK_10_MASK 0x80
|
|
|
|
|
|
|
|
struct tlclk_alarms {
|
|
|
|
__u32 lost_clocks;
|
|
|
|
__u32 lost_primary_clock;
|
|
|
|
__u32 lost_secondary_clock;
|
|
|
|
__u32 primary_clock_back;
|
|
|
|
__u32 secondary_clock_back;
|
|
|
|
__u32 switchover_primary;
|
|
|
|
__u32 switchover_secondary;
|
|
|
|
__u32 pll_holdover;
|
|
|
|
__u32 pll_end_holdover;
|
|
|
|
__u32 pll_lost_sync;
|
|
|
|
__u32 pll_sync;
|
|
|
|
};
|
|
|
|
/* Telecom clock I/O register definition */
|
|
|
|
#define TLCLK_BASE 0xa08
|
|
|
|
#define TLCLK_REG0 TLCLK_BASE
|
|
|
|
#define TLCLK_REG1 (TLCLK_BASE+1)
|
|
|
|
#define TLCLK_REG2 (TLCLK_BASE+2)
|
|
|
|
#define TLCLK_REG3 (TLCLK_BASE+3)
|
|
|
|
#define TLCLK_REG4 (TLCLK_BASE+4)
|
|
|
|
#define TLCLK_REG5 (TLCLK_BASE+5)
|
|
|
|
#define TLCLK_REG6 (TLCLK_BASE+6)
|
|
|
|
#define TLCLK_REG7 (TLCLK_BASE+7)
|
|
|
|
|
|
|
|
#define SET_PORT_BITS(port, mask, val) outb(((inb(port) & mask) | val), port)
|
|
|
|
|
|
|
|
/* 0 = Dynamic allocation of the major device number */
|
|
|
|
#define TLCLK_MAJOR 0
|
|
|
|
|
|
|
|
/* sysfs interface definition:
|
|
|
|
Upon loading the driver will create a sysfs directory under
|
|
|
|
/sys/devices/platform/telco_clock.
|
|
|
|
|
|
|
|
This directory exports the following interfaces. There operation is
|
|
|
|
documented in the MCPBL0010 TPS under the Telecom Clock API section, 11.4.
|
|
|
|
alarms :
|
|
|
|
current_ref :
|
2006-01-16 09:37:30 +08:00
|
|
|
received_ref_clk3a :
|
|
|
|
received_ref_clk3b :
|
2005-10-31 07:02:55 +08:00
|
|
|
enable_clk3a_output :
|
|
|
|
enable_clk3b_output :
|
|
|
|
enable_clka0_output :
|
|
|
|
enable_clka1_output :
|
|
|
|
enable_clkb0_output :
|
|
|
|
enable_clkb1_output :
|
|
|
|
filter_select :
|
|
|
|
hardware_switching :
|
|
|
|
hardware_switching_mode :
|
2006-01-16 09:37:30 +08:00
|
|
|
telclock_version :
|
2005-10-31 07:02:55 +08:00
|
|
|
mode_select :
|
|
|
|
refalign :
|
|
|
|
reset :
|
|
|
|
select_amcb1_transmit_clock :
|
|
|
|
select_amcb2_transmit_clock :
|
|
|
|
select_redundant_clock :
|
|
|
|
select_ref_frequency :
|
|
|
|
|
|
|
|
All sysfs interfaces are integers in hex format, i.e echo 99 > refalign
|
|
|
|
has the same effect as echo 0x99 > refalign.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned int telclk_interrupt;
|
|
|
|
|
|
|
|
static int int_events; /* Event that generate a interrupt */
|
|
|
|
static int got_event; /* if events processing have been done */
|
|
|
|
|
2017-10-05 07:27:01 +08:00
|
|
|
static void switchover_timeout(struct timer_list *t);
|
|
|
|
static struct timer_list switchover_timer;
|
2007-01-23 12:40:44 +08:00
|
|
|
static unsigned long tlclk_timer_data;
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static struct tlclk_alarms *alarm_events;
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(event_lock);
|
|
|
|
|
|
|
|
static int tlclk_major = TLCLK_MAJOR;
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t tlclk_interrupt(int irq, void *dev_id);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(wq);
|
|
|
|
|
2007-01-23 12:40:44 +08:00
|
|
|
static unsigned long useflags;
|
|
|
|
static DEFINE_MUTEX(tlclk_mutex);
|
|
|
|
|
2005-10-31 07:02:55 +08:00
|
|
|
static int tlclk_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2010-09-12 01:31:43 +08:00
|
|
|
mutex_lock(&tlclk_mutex);
|
2008-05-17 03:53:00 +08:00
|
|
|
if (test_and_set_bit(0, &useflags)) {
|
|
|
|
result = -EBUSY;
|
2007-01-23 12:40:44 +08:00
|
|
|
/* this legacy device is always one per system and it doesn't
|
|
|
|
* know how to handle multiple concurrent clients.
|
|
|
|
*/
|
2008-05-17 03:53:00 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2007-01-23 12:40:44 +08:00
|
|
|
|
2005-10-31 07:02:55 +08:00
|
|
|
/* Make sure there is no interrupt pending while
|
|
|
|
* initialising interrupt handler */
|
|
|
|
inb(TLCLK_REG6);
|
|
|
|
|
|
|
|
/* This device is wired through the FPGA IO space of the ATCA blade
|
|
|
|
* we can't share this IRQ */
|
|
|
|
result = request_irq(telclk_interrupt, &tlclk_interrupt,
|
2013-10-13 12:17:25 +08:00
|
|
|
0, "telco_clock", tlclk_interrupt);
|
2008-05-17 03:53:00 +08:00
|
|
|
if (result == -EBUSY)
|
2006-01-12 04:17:33 +08:00
|
|
|
printk(KERN_ERR "tlclk: Interrupt can't be reserved.\n");
|
2008-05-17 03:53:00 +08:00
|
|
|
else
|
|
|
|
inb(TLCLK_REG6); /* Clear interrupt events */
|
2005-10-31 07:02:55 +08:00
|
|
|
|
2008-05-17 03:53:00 +08:00
|
|
|
out:
|
2010-09-12 01:31:43 +08:00
|
|
|
mutex_unlock(&tlclk_mutex);
|
2008-05-17 03:53:00 +08:00
|
|
|
return result;
|
2005-10-31 07:02:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tlclk_release(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
free_irq(telclk_interrupt, tlclk_interrupt);
|
2007-01-23 12:40:44 +08:00
|
|
|
clear_bit(0, &useflags);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-16 09:37:30 +08:00
|
|
|
static ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count,
|
2005-10-31 07:02:55 +08:00
|
|
|
loff_t *f_pos)
|
|
|
|
{
|
|
|
|
if (count < sizeof(struct tlclk_alarms))
|
|
|
|
return -EIO;
|
2007-01-23 12:40:44 +08:00
|
|
|
if (mutex_lock_interruptible(&tlclk_mutex))
|
|
|
|
return -EINTR;
|
|
|
|
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
wait_event_interruptible(wq, got_event);
|
2007-01-23 12:40:44 +08:00
|
|
|
if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms))) {
|
|
|
|
mutex_unlock(&tlclk_mutex);
|
2005-10-31 07:02:55 +08:00
|
|
|
return -EFAULT;
|
2007-01-23 12:40:44 +08:00
|
|
|
}
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
memset(alarm_events, 0, sizeof(struct tlclk_alarms));
|
|
|
|
got_event = 0;
|
|
|
|
|
2007-01-23 12:40:44 +08:00
|
|
|
mutex_unlock(&tlclk_mutex);
|
2005-10-31 07:02:55 +08:00
|
|
|
return sizeof(struct tlclk_alarms);
|
|
|
|
}
|
|
|
|
|
2006-07-03 15:24:21 +08:00
|
|
|
static const struct file_operations tlclk_fops = {
|
2005-10-31 07:02:55 +08:00
|
|
|
.read = tlclk_read,
|
|
|
|
.open = tlclk_open,
|
|
|
|
.release = tlclk_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = noop_llseek,
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice tlclk_miscdev = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "telco_clock",
|
|
|
|
.fops = &tlclk_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t show_current_ref(struct device *d,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned long ret_val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
ret_val = ((inb(TLCLK_REG1) & 0x08) >> 3);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return sprintf(buf, "0x%lX\n", ret_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(current_ref, S_IRUGO, show_current_ref, NULL);
|
|
|
|
|
|
|
|
|
2006-01-16 09:37:30 +08:00
|
|
|
static ssize_t show_telclock_version(struct device *d,
|
2005-10-31 07:02:55 +08:00
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned long ret_val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
2006-01-16 09:37:30 +08:00
|
|
|
ret_val = inb(TLCLK_REG5);
|
2005-10-31 07:02:55 +08:00
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return sprintf(buf, "0x%lX\n", ret_val);
|
|
|
|
}
|
|
|
|
|
2006-01-16 09:37:30 +08:00
|
|
|
static DEVICE_ATTR(telclock_version, S_IRUGO,
|
|
|
|
show_telclock_version, NULL);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static ssize_t show_alarms(struct device *d,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
unsigned long ret_val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
ret_val = (inb(TLCLK_REG2) & 0xf0);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return sprintf(buf, "0x%lX\n", ret_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
|
|
|
|
|
2006-01-16 09:37:30 +08:00
|
|
|
static ssize_t store_received_ref_clk3a(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, ": tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xef, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(received_ref_clk3a, (S_IWUSR|S_IWGRP), NULL,
|
2006-01-16 09:37:30 +08:00
|
|
|
store_received_ref_clk3a);
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t store_received_ref_clk3b(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, ": tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
2006-06-24 06:13:07 +08:00
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xdf, val << 1);
|
2006-01-16 09:37:30 +08:00
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(received_ref_clk3b, (S_IWUSR|S_IWGRP), NULL,
|
2006-01-16 09:37:30 +08:00
|
|
|
store_received_ref_clk3b);
|
|
|
|
|
|
|
|
|
2005-10-31 07:02:55 +08:00
|
|
|
static ssize_t store_enable_clk3b_output(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, ": tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0x7f, val << 7);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(enable_clk3b_output, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_enable_clk3b_output);
|
|
|
|
|
|
|
|
static ssize_t store_enable_clk3a_output(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xbf, val << 6);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(enable_clk3a_output, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_enable_clk3a_output);
|
|
|
|
|
|
|
|
static ssize_t store_enable_clkb1_output(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG2, 0xf7, val << 3);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(enable_clkb1_output, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_enable_clkb1_output);
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t store_enable_clka1_output(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG2, 0xfb, val << 2);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(enable_clka1_output, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_enable_clka1_output);
|
|
|
|
|
|
|
|
static ssize_t store_enable_clkb0_output(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG2, 0xfd, val << 1);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(enable_clkb0_output, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_enable_clkb0_output);
|
|
|
|
|
|
|
|
static ssize_t store_enable_clka0_output(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG2, 0xfe, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(enable_clka0_output, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_enable_clka0_output);
|
|
|
|
|
|
|
|
static ssize_t store_select_amcb2_transmit_clock(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
if ((val == CLK_8kHz) || (val == CLK_16_384MHz)) {
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xc7, 0x28);
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xfb, ~val);
|
|
|
|
} else if (val >= CLK_8_592MHz) {
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xc7, 0x38);
|
|
|
|
switch (val) {
|
|
|
|
case CLK_8_592MHz:
|
2006-01-16 09:37:30 +08:00
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
|
2005-10-31 07:02:55 +08:00
|
|
|
break;
|
|
|
|
case CLK_11_184MHz:
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
|
|
|
|
break;
|
|
|
|
case CLK_34_368MHz:
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
|
|
|
|
break;
|
|
|
|
case CLK_44_736MHz:
|
2006-01-16 09:37:30 +08:00
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
|
2005-10-31 07:02:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xc7, val << 3);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(select_amcb2_transmit_clock, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_select_amcb2_transmit_clock);
|
|
|
|
|
|
|
|
static ssize_t store_select_amcb1_transmit_clock(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
if ((val == CLK_8kHz) || (val == CLK_16_384MHz)) {
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x5);
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xfb, ~val);
|
|
|
|
} else if (val >= CLK_8_592MHz) {
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7);
|
|
|
|
switch (val) {
|
|
|
|
case CLK_8_592MHz:
|
2007-01-23 12:40:44 +08:00
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
|
2005-10-31 07:02:55 +08:00
|
|
|
break;
|
|
|
|
case CLK_11_184MHz:
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
|
|
|
|
break;
|
|
|
|
case CLK_34_368MHz:
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
|
|
|
|
break;
|
|
|
|
case CLK_44_736MHz:
|
2007-01-23 12:40:44 +08:00
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
|
2005-10-31 07:02:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
SET_PORT_BITS(TLCLK_REG3, 0xf8, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(select_amcb1_transmit_clock, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_select_amcb1_transmit_clock);
|
|
|
|
|
|
|
|
static ssize_t store_select_redundant_clock(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xfe, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(select_redundant_clock, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_select_redundant_clock);
|
|
|
|
|
|
|
|
static ssize_t store_select_ref_frequency(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xfd, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(select_ref_frequency, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_select_ref_frequency);
|
|
|
|
|
|
|
|
static ssize_t store_filter_select(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xfb, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(filter_select, (S_IWUSR|S_IWGRP), NULL, store_filter_select);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static ssize_t store_hardware_switching_mode(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xbf, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(hardware_switching_mode, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_hardware_switching_mode);
|
|
|
|
|
|
|
|
static ssize_t store_hardware_switching(struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0x7f, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(hardware_switching, (S_IWUSR|S_IWGRP), NULL,
|
2005-10-31 07:02:55 +08:00
|
|
|
store_hardware_switching);
|
|
|
|
|
|
|
|
static ssize_t store_refalign (struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xf7, 0);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xf7, 0x08);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xf7, 0);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(refalign, (S_IWUSR|S_IWGRP), NULL, store_refalign);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static ssize_t store_mode_select (struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG0, 0xcf, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(mode_select, (S_IWUSR|S_IWGRP), NULL, store_mode_select);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static ssize_t store_reset (struct device *d,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
sscanf(buf, "%lX", &tmp);
|
|
|
|
dev_dbg(d, "tmp = 0x%lX\n", tmp);
|
|
|
|
|
|
|
|
val = (unsigned char)tmp;
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
SET_PORT_BITS(TLCLK_REG4, 0xfd, val);
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return strnlen(buf, count);
|
|
|
|
}
|
|
|
|
|
2006-04-11 13:54:20 +08:00
|
|
|
static DEVICE_ATTR(reset, (S_IWUSR|S_IWGRP), NULL, store_reset);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
static struct attribute *tlclk_sysfs_entries[] = {
|
|
|
|
&dev_attr_current_ref.attr,
|
2006-01-16 09:37:30 +08:00
|
|
|
&dev_attr_telclock_version.attr,
|
2005-10-31 07:02:55 +08:00
|
|
|
&dev_attr_alarms.attr,
|
2006-01-16 09:37:30 +08:00
|
|
|
&dev_attr_received_ref_clk3a.attr,
|
|
|
|
&dev_attr_received_ref_clk3b.attr,
|
2005-10-31 07:02:55 +08:00
|
|
|
&dev_attr_enable_clk3a_output.attr,
|
|
|
|
&dev_attr_enable_clk3b_output.attr,
|
|
|
|
&dev_attr_enable_clkb1_output.attr,
|
|
|
|
&dev_attr_enable_clka1_output.attr,
|
|
|
|
&dev_attr_enable_clkb0_output.attr,
|
|
|
|
&dev_attr_enable_clka0_output.attr,
|
|
|
|
&dev_attr_select_amcb1_transmit_clock.attr,
|
|
|
|
&dev_attr_select_amcb2_transmit_clock.attr,
|
|
|
|
&dev_attr_select_redundant_clock.attr,
|
|
|
|
&dev_attr_select_ref_frequency.attr,
|
|
|
|
&dev_attr_filter_select.attr,
|
|
|
|
&dev_attr_hardware_switching_mode.attr,
|
|
|
|
&dev_attr_hardware_switching.attr,
|
|
|
|
&dev_attr_refalign.attr,
|
|
|
|
&dev_attr_mode_select.attr,
|
|
|
|
&dev_attr_reset.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2017-08-02 19:19:05 +08:00
|
|
|
static const struct attribute_group tlclk_attribute_group = {
|
2005-10-31 07:02:55 +08:00
|
|
|
.name = NULL, /* put in device directory */
|
|
|
|
.attrs = tlclk_sysfs_entries,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *tlclk_device;
|
|
|
|
|
|
|
|
static int __init tlclk_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = register_chrdev(tlclk_major, "telco_clock", &tlclk_fops);
|
|
|
|
if (ret < 0) {
|
2006-01-12 04:17:33 +08:00
|
|
|
printk(KERN_ERR "tlclk: can't get major %d.\n", tlclk_major);
|
2005-10-31 07:02:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2006-03-26 17:37:31 +08:00
|
|
|
tlclk_major = ret;
|
2005-10-31 07:02:55 +08:00
|
|
|
alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL);
|
2012-08-05 17:52:35 +08:00
|
|
|
if (!alarm_events) {
|
|
|
|
ret = -ENOMEM;
|
2005-10-31 07:02:55 +08:00
|
|
|
goto out1;
|
2012-08-05 17:52:35 +08:00
|
|
|
}
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
/* Read telecom clock IRQ number (Set by BIOS) */
|
|
|
|
if (!request_region(TLCLK_BASE, 8, "telco_clock")) {
|
2006-01-12 04:17:33 +08:00
|
|
|
printk(KERN_ERR "tlclk: request_region 0x%X failed.\n",
|
2005-10-31 07:02:55 +08:00
|
|
|
TLCLK_BASE);
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
telclk_interrupt = (inb(TLCLK_REG7) & 0x0f);
|
|
|
|
|
|
|
|
if (0x0F == telclk_interrupt ) { /* not MCPBL0010 ? */
|
2012-02-07 22:55:52 +08:00
|
|
|
printk(KERN_ERR "telclk_interrupt = 0x%x non-mcpbl0010 hw.\n",
|
2005-10-31 07:02:55 +08:00
|
|
|
telclk_interrupt);
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
2017-10-05 07:27:01 +08:00
|
|
|
timer_setup(&switchover_timer, switchover_timeout, 0);
|
2005-10-31 07:02:55 +08:00
|
|
|
|
|
|
|
ret = misc_register(&tlclk_miscdev);
|
|
|
|
if (ret < 0) {
|
2006-01-12 04:17:33 +08:00
|
|
|
printk(KERN_ERR "tlclk: misc_register returns %d.\n", ret);
|
2005-10-31 07:02:55 +08:00
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
tlclk_device = platform_device_register_simple("telco_clock",
|
|
|
|
-1, NULL, 0);
|
2006-11-26 03:09:35 +08:00
|
|
|
if (IS_ERR(tlclk_device)) {
|
2006-01-12 04:17:33 +08:00
|
|
|
printk(KERN_ERR "tlclk: platform_device_register failed.\n");
|
2006-11-26 03:09:35 +08:00
|
|
|
ret = PTR_ERR(tlclk_device);
|
2005-10-31 07:02:55 +08:00
|
|
|
goto out4;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sysfs_create_group(&tlclk_device->dev.kobj,
|
|
|
|
&tlclk_attribute_group);
|
|
|
|
if (ret) {
|
2006-01-12 04:17:33 +08:00
|
|
|
printk(KERN_ERR "tlclk: failed to create sysfs device attributes.\n");
|
2005-10-31 07:02:55 +08:00
|
|
|
goto out5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out5:
|
|
|
|
platform_device_unregister(tlclk_device);
|
|
|
|
out4:
|
|
|
|
misc_deregister(&tlclk_miscdev);
|
|
|
|
out3:
|
|
|
|
release_region(TLCLK_BASE, 8);
|
|
|
|
out2:
|
|
|
|
kfree(alarm_events);
|
|
|
|
out1:
|
|
|
|
unregister_chrdev(tlclk_major, "telco_clock");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit tlclk_cleanup(void)
|
|
|
|
{
|
|
|
|
sysfs_remove_group(&tlclk_device->dev.kobj, &tlclk_attribute_group);
|
|
|
|
platform_device_unregister(tlclk_device);
|
|
|
|
misc_deregister(&tlclk_miscdev);
|
|
|
|
unregister_chrdev(tlclk_major, "telco_clock");
|
|
|
|
|
|
|
|
release_region(TLCLK_BASE, 8);
|
|
|
|
del_timer_sync(&switchover_timer);
|
|
|
|
kfree(alarm_events);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-05 07:27:01 +08:00
|
|
|
static void switchover_timeout(struct timer_list *unused)
|
2005-10-31 07:02:55 +08:00
|
|
|
{
|
2017-10-05 07:27:01 +08:00
|
|
|
unsigned long flags = tlclk_timer_data;
|
2007-01-23 12:40:44 +08:00
|
|
|
|
|
|
|
if ((flags & 1)) {
|
|
|
|
if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
|
2005-10-31 07:02:55 +08:00
|
|
|
alarm_events->switchover_primary++;
|
|
|
|
} else {
|
2007-01-23 12:40:44 +08:00
|
|
|
if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
|
2005-10-31 07:02:55 +08:00
|
|
|
alarm_events->switchover_secondary++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Alarm processing is done, wake up read task */
|
|
|
|
del_timer(&switchover_timer);
|
|
|
|
got_event = 1;
|
|
|
|
wake_up(&wq);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t tlclk_interrupt(int irq, void *dev_id)
|
2005-10-31 07:02:55 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&event_lock, flags);
|
|
|
|
/* Read and clear interrupt events */
|
|
|
|
int_events = inb(TLCLK_REG6);
|
|
|
|
|
|
|
|
/* Primary_Los changed from 0 to 1 ? */
|
|
|
|
if (int_events & PRI_LOS_01_MASK) {
|
|
|
|
if (inb(TLCLK_REG2) & SEC_LOST_MASK)
|
|
|
|
alarm_events->lost_clocks++;
|
|
|
|
else
|
|
|
|
alarm_events->lost_primary_clock++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Primary_Los changed from 1 to 0 ? */
|
|
|
|
if (int_events & PRI_LOS_10_MASK) {
|
|
|
|
alarm_events->primary_clock_back++;
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xFE, 1);
|
|
|
|
}
|
|
|
|
/* Secondary_Los changed from 0 to 1 ? */
|
|
|
|
if (int_events & SEC_LOS_01_MASK) {
|
|
|
|
if (inb(TLCLK_REG2) & PRI_LOST_MASK)
|
|
|
|
alarm_events->lost_clocks++;
|
|
|
|
else
|
|
|
|
alarm_events->lost_secondary_clock++;
|
|
|
|
}
|
|
|
|
/* Secondary_Los changed from 1 to 0 ? */
|
|
|
|
if (int_events & SEC_LOS_10_MASK) {
|
|
|
|
alarm_events->secondary_clock_back++;
|
|
|
|
SET_PORT_BITS(TLCLK_REG1, 0xFE, 0);
|
|
|
|
}
|
|
|
|
if (int_events & HOLDOVER_10_MASK)
|
|
|
|
alarm_events->pll_end_holdover++;
|
|
|
|
|
|
|
|
if (int_events & UNLOCK_01_MASK)
|
|
|
|
alarm_events->pll_lost_sync++;
|
|
|
|
|
|
|
|
if (int_events & UNLOCK_10_MASK)
|
|
|
|
alarm_events->pll_sync++;
|
|
|
|
|
|
|
|
/* Holdover changed from 0 to 1 ? */
|
|
|
|
if (int_events & HOLDOVER_01_MASK) {
|
|
|
|
alarm_events->pll_holdover++;
|
|
|
|
|
|
|
|
/* TIMEOUT in ~10ms */
|
|
|
|
switchover_timer.expires = jiffies + msecs_to_jiffies(10);
|
2007-01-23 12:40:44 +08:00
|
|
|
tlclk_timer_data = inb(TLCLK_REG1);
|
|
|
|
mod_timer(&switchover_timer, switchover_timer.expires);
|
2005-10-31 07:02:55 +08:00
|
|
|
} else {
|
|
|
|
got_event = 1;
|
|
|
|
wake_up(&wq);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&event_lock, flags);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(tlclk_init);
|
|
|
|
module_exit(tlclk_cleanup);
|