#include <linux/autoconf.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
#include <asm/arch/hwregs/reg_map.h>
#include <asm/arch/hwregs/reg_rdwr.h>
#include <asm/arch/hwregs/gio_defs.h>
#include <asm/arch/hwregs/intr_vect_defs.h>
#include <asm/arch/hwregs/pinmux_defs.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/irq.h>
#include <asm/delay.h>
#include <asm/uaccess.h>
#include <asm/elphel/driver_numbers.h>
#include <asm/elphel/fpgaconfa.h>
#include <asm/elphel/fpgaclocks.h>
#include "fpgactrl.h"
Include dependency graph for fpgaclocks.c:
Go to the source code of this file.
Data Structures | |
struct | t_pll_params |
Defines | |
#define | D(x) |
#define | D1(x) |
#define | D2(x) |
#define | D3(x) |
#define | D5(x) |
#define | FPGA_CLOCK_DRIVER_NAME "Elphel (R) model 353 system clocks (PLL frequency synth.) driver" |
#define | FPGA_CLOCK_MAXMINOR 10 |
#define | XCLOCK_LOW_TIME 8 |
#define | XCLOCK_HIGH_TIME 8 |
#define | XSTART_CONDITION_HOLD_TIME 8 |
#define | XSTOP_CONDITION_HOLD_TIME 8 |
#define | XENABLE_OUTPUT 0x01 |
#define | XENABLE_INPUT 0x00 |
#define | XI2C_CLOCK_HIGH 1 |
#define | XI2C_CLOCK_LOW 0 |
#define | XI2C_DATA_HIGH 1 |
#define | XI2C_DATA_LOW 0 |
#define | xi2c_delay(usecs) udelay(usecs) |
#define | CY223933_SA 0xd2 |
#define | CY22393_SCALE 100 |
#define | CY22393_PLLMIN (100000000/CY22393_SCALE) |
#define | CY22393_PLLMAX (400000000/CY22393_SCALE) |
#define | CY22393_XTAL ( 12000000/CY22393_SCALE) |
#define | CY22393_OUTMAX (166000000/CY22393_SCALE) |
#define | CY22393_PMIN 16 |
#define | CY22393_PMAX 1600 |
Functions | |
int | xi2c_diagnose (void) |
int | xi2c_start (void) |
void | xi2c_stop (void) |
void | xi2c_nostop (void) |
int | xi2c_outbyte (unsigned char d) |
unsigned char | xi2c_inbyte (void) |
void | xi2c_sendack (void) |
int | fi2c_writeData (unsigned char theSlave, unsigned char *theData, int size, int nostop) |
int | fi2c_readData (unsigned char theSlave, unsigned char *theData, int size) |
int | fi2c_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) |
int | calc_pll_params (unsigned int f, t_pll_params *pars) |
int | setCYField (int addr, int mask, int value) |
int | setClockFreq (int nclock, int freq) |
static int | fpga_clock_open (struct inode *inode, struct file *filp) |
static int | fpga_clock_release (struct inode *inode, struct file *filp) |
static int | fpga_clock_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) |
static int __init | fpga_clock_init (void) |
void | xi2c_disable (void) |
void | xi2c_scl (int x) |
void | xi2c_sda (int x) |
int | xi2c_getbit (void) |
int | xi2c_getscl (void) |
void | initPortB (void) |
int | getClockFreq (int nclock) |
module_init (fpga_clock_init) | |
MODULE_LICENSE ("GPL") | |
MODULE_AUTHOR ("Andrey Filippov <andrey@elphel.com>.") | |
MODULE_DESCRIPTION (FPGA_CLOCK_DRIVER_NAME) | |
Variables | |
static int | clock_frequency [4] |
static const char | fpga_clock_name [] = "fpga_clock_control" |
static int | minors [FPGA_CLOCK_MAXMINOR+1] |
static struct file_operations | fpga_clock_fops |
#define CY223933_SA 0xd2 |
#define CY22393_OUTMAX (166000000/CY22393_SCALE) |
#define CY22393_PLLMAX (400000000/CY22393_SCALE) |
#define CY22393_PLLMIN (100000000/CY22393_SCALE) |
#define CY22393_PMAX 1600 |
#define CY22393_PMIN 16 |
#define CY22393_SCALE 100 |
#define CY22393_XTAL ( 12000000/CY22393_SCALE) |
#define D | ( | x | ) |
*************************************************************************** ! FILE NAME : fpgaclocks353.c ! provides control of the FPGA clocks based on 3-pll generator ! Direct r/w of the CY22393 over the I2C interface (connected to PB.16 and PB.17 of the CPU) ! supports 3 PLLs connected to 3 outputs (clk0, clk1 and clk2) ! clk3 can be only turned on to Xtal frequency (12MHz) or off ! Input parameter specifies frequency in Hz, internally data is rounded to 100Hz ! ! ! Copyright (C) 2002-2006 Elphel, Inc. ! -----------------------------------------------------------------------------** ! ! 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 3 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. 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, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** !
Definition at line 100 of file fpgaclocks.c.
#define D1 | ( | x | ) |
Definition at line 103 of file fpgaclocks.c.
#define D2 | ( | x | ) |
Definition at line 106 of file fpgaclocks.c.
#define D3 | ( | x | ) |
Definition at line 109 of file fpgaclocks.c.
#define D5 | ( | x | ) |
Definition at line 116 of file fpgaclocks.c.
#define FPGA_CLOCK_DRIVER_NAME "Elphel (R) model 353 system clocks (PLL frequency synth.) driver" |
#define FPGA_CLOCK_MAXMINOR 10 |
#define XCLOCK_HIGH_TIME 8 |
Definition at line 128 of file fpgaclocks.c.
Referenced by xi2c_diagnose(), xi2c_inbyte(), xi2c_nostop(), xi2c_outbyte(), xi2c_sendack(), xi2c_start(), and xi2c_stop().
#define XCLOCK_LOW_TIME 8 |
Definition at line 127 of file fpgaclocks.c.
Referenced by xi2c_diagnose(), xi2c_inbyte(), xi2c_nostop(), xi2c_outbyte(), xi2c_sendack(), xi2c_start(), and xi2c_stop().
#define XENABLE_INPUT 0x00 |
Definition at line 132 of file fpgaclocks.c.
#define XENABLE_OUTPUT 0x01 |
Definition at line 131 of file fpgaclocks.c.
#define XI2C_CLOCK_HIGH 1 |
Definition at line 133 of file fpgaclocks.c.
#define XI2C_CLOCK_LOW 0 |
Definition at line 134 of file fpgaclocks.c.
#define XI2C_DATA_HIGH 1 |
Definition at line 135 of file fpgaclocks.c.
#define XI2C_DATA_LOW 0 |
Definition at line 136 of file fpgaclocks.c.
#define xi2c_delay | ( | usecs | ) | udelay(usecs) |
Definition at line 143 of file fpgaclocks.c.
Referenced by xi2c_diagnose(), xi2c_inbyte(), xi2c_nostop(), xi2c_outbyte(), xi2c_sendack(), xi2c_start(), and xi2c_stop().
#define XSTART_CONDITION_HOLD_TIME 8 |
#define XSTOP_CONDITION_HOLD_TIME 8 |
Definition at line 130 of file fpgaclocks.c.
Referenced by xi2c_diagnose(), xi2c_nostop(), xi2c_start(), and xi2c_stop().
int calc_pll_params | ( | unsigned int | f, | |
t_pll_params * | pars | |||
) |
Definition at line 202 of file fpgaclocks.c.
References t_pll_params::corr, CY22393_OUTMAX, CY22393_PLLMAX, CY22393_PLLMIN, CY22393_PMAX, CY22393_PMIN, CY22393_SCALE, CY22393_XTAL, D, D1, t_pll_params::dv, e, t_pll_params::p, printk, t_pll_params::q, and t_pll_params::rslt.
Referenced by setClockFreq().
int fi2c_ioctl | ( | struct inode * | inode, | |
struct file * | file, | |||
unsigned int | cmd, | |||
unsigned long | arg | |||
) |
Definition at line 715 of file fpgaclocks.c.
References D3, data, error(), fi2c_readData(), fi2c_writeData(), FPGA_CLOCK_I2C_READREG, FPGA_CLOCK_I2C_WRITEREG, FPGA_CLOCK_IOCTYPE, I2C_ARGREG, I2C_ARGSLAVE, I2C_ARGVALUE, and printk.
Referenced by fpga_clock_ioctl().
int fi2c_readData | ( | unsigned char | theSlave, | |
unsigned char * | theData, | |||
int | size | |||
) |
Definition at line 689 of file fpgaclocks.c.
References D, D3, ERR_I2C_BSY, error(), printk, xi2c_inbyte(), xi2c_outbyte(), xi2c_sendack(), xi2c_start(), and xi2c_stop().
Referenced by fi2c_ioctl(), and setCYField().
int fi2c_writeData | ( | unsigned char | theSlave, | |
unsigned char * | theData, | |||
int | size, | |||
int | nostop | |||
) |
Definition at line 653 of file fpgaclocks.c.
References D, D3, ERR_I2C_BSY, ERR_I2C_NACK, error(), printk, xi2c_nostop(), xi2c_outbyte(), xi2c_start(), and xi2c_stop().
Referenced by fi2c_ioctl(), and setCYField().
static int __init fpga_clock_init | ( | void | ) | [static] |
Definition at line 926 of file fpgaclocks.c.
References FPGA_CLOCK_DRIVER_NAME, fpga_clock_fops, FPGA_CLOCK_MAJOR, FPGA_CLOCK_MAXMINOR, fpga_clock_name, fpga_state, initPortB(), KERN_ERR, minors, and printk.
static int fpga_clock_ioctl | ( | struct inode * | inode, | |
struct file * | filp, | |||
unsigned int | cmd, | |||
unsigned long | arg | |||
) | [static] |
Definition at line 899 of file fpgaclocks.c.
References D, D5, fi2c_ioctl(), FPGA_CLOCK_IOCTYPE, FPGA_CLOCK_IOCTYPE_RD, FPGA_CLOCK_MINOR_CLOCKS, FPGA_CLOCK_MINOR_I2C, getClockFreq(), printk, and setClockFreq().
static int fpga_clock_open | ( | struct inode * | inode, | |
struct file * | filp | |||
) | [static] |
Definition at line 873 of file fpgaclocks.c.
References D, FPGA_CLOCK_MINOR_CLOCKS, FPGA_CLOCK_MINOR_I2C, minors, and printk.
static int fpga_clock_release | ( | struct inode * | inode, | |
struct file * | filp | |||
) | [static] |
int getClockFreq | ( | int | nclock | ) |
Definition at line 777 of file fpgaclocks.c.
Referenced by fpga_clock_ioctl(), pgm_detectsensor(), and pgm_sensorphase().
void initPortB | ( | void | ) |
MODULE_AUTHOR | ( | "Andrey Filippov <andrey@elphel.com>." | ) |
MODULE_DESCRIPTION | ( | FPGA_CLOCK_DRIVER_NAME | ) |
module_init | ( | fpga_clock_init | ) |
MODULE_LICENSE | ( | "GPL" | ) |
int setClockFreq | ( | int | nclock, | |
int | freq | |||
) |
Definition at line 782 of file fpgaclocks.c.
References calc_pll_params(), clock_frequency, t_pll_params::corr, CY22393_SCALE, CY22393_XTAL, D5, t_pll_params::dv, fpga_state, FPGA_STATE_CLOCKS, t_pll_params::p, printk, t_pll_params::q, and setCYField().
Referenced by fpga_clock_ioctl(), pgm_detectsensor(), and pgm_sensorphase().
int setCYField | ( | int | addr, | |
int | mask, | |||
int | value | |||
) |
Definition at line 764 of file fpgaclocks.c.
References CY223933_SA, data, error(), fi2c_readData(), and fi2c_writeData().
Referenced by setClockFreq().
int xi2c_diagnose | ( | void | ) |
Definition at line 444 of file fpgaclocks.c.
References D, ERR_I2C_NOTDETECTED, ERR_I2C_SCL_NOPULLUP, ERR_I2C_SCL_ST0, ERR_I2C_SDA_NOPULLUP, ERR_I2C_SDA_ST0, ERR_I2C_SHORT, error(), printk, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_disable, xi2c_getbit, xi2c_getscl, xi2c_scl(), xi2c_sda, XSTART_CONDITION_HOLD_TIME, and XSTOP_CONDITION_HOLD_TIME.
Referenced by xi2c_start().
void xi2c_disable | ( | void | ) | [inline] |
int xi2c_getbit | ( | void | ) | [inline] |
int xi2c_getscl | ( | void | ) | [inline] |
unsigned char xi2c_inbyte | ( | void | ) |
Definition at line 604 of file fpgaclocks.c.
References D, printk, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_getbit, xi2c_scl(), and xi2c_sda.
Referenced by fi2c_readData().
void xi2c_nostop | ( | void | ) |
Definition at line 547 of file fpgaclocks.c.
References D, printk, udelay, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_disable, xi2c_scl(), xi2c_sda, and XSTOP_CONDITION_HOLD_TIME.
Referenced by fi2c_writeData().
int xi2c_outbyte | ( | unsigned char | d | ) |
Definition at line 568 of file fpgaclocks.c.
References D, printk, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_getbit, xi2c_scl(), and xi2c_sda.
Referenced by fi2c_readData(), and fi2c_writeData().
void xi2c_scl | ( | int | x | ) | [inline] |
Definition at line 372 of file fpgaclocks.c.
Referenced by xi2c_diagnose(), xi2c_inbyte(), xi2c_nostop(), xi2c_outbyte(), xi2c_sendack(), xi2c_start(), and xi2c_stop().
void xi2c_sda | ( | int | x | ) | [inline] |
void xi2c_sendack | ( | void | ) |
Definition at line 633 of file fpgaclocks.c.
References D, printk, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_scl(), and xi2c_sda.
Referenced by fi2c_readData().
int xi2c_start | ( | void | ) |
Definition at line 486 of file fpgaclocks.c.
References D, printk, udelay, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_diagnose(), xi2c_disable, xi2c_getbit, xi2c_getscl, xi2c_scl(), xi2c_sda, XSTART_CONDITION_HOLD_TIME, and XSTOP_CONDITION_HOLD_TIME.
Referenced by fi2c_readData(), and fi2c_writeData().
void xi2c_stop | ( | void | ) |
Definition at line 529 of file fpgaclocks.c.
References D, printk, udelay, XCLOCK_HIGH_TIME, XCLOCK_LOW_TIME, xi2c_delay, xi2c_scl(), xi2c_sda, and XSTOP_CONDITION_HOLD_TIME.
Referenced by fi2c_readData(), and fi2c_writeData().
int clock_frequency[4] [static] |
struct file_operations fpga_clock_fops [static] |
Initial value:
{ owner: THIS_MODULE, open: fpga_clock_open, release: fpga_clock_release, ioctl: fpga_clock_ioctl, }
Definition at line 180 of file fpgaclocks.c.
Referenced by fpga_clock_init().
const char fpga_clock_name[] = "fpga_clock_control" [static] |
int minors[FPGA_CLOCK_MAXMINOR+1] [static] |
Definition at line 173 of file fpgaclocks.c.
Referenced by fpga_clock_init(), fpga_clock_open(), fpga_clock_release(), fpga_init(), fpga_jtag_init(), fpga_jtag_open(), fpga_jtag_release(), fpga_open(), and fpga_release().