Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC DEL 1ns 4cha - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC DEL 1ns 4cha - Software
Commits
58b32625
Commit
58b32625
authored
Apr 17, 2012
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial structure of the code, pll is identified
parent
d61e525c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
416 additions
and
0 deletions
+416
-0
fd-core.c
fd-core.c
+146
-0
fd-spec.c
fd-spec.c
+68
-0
fd-zio.c
fd-zio.c
+37
-0
fine-delay.h
fine-delay.h
+41
-0
pll.c
pll.c
+67
-0
spi.c
spi.c
+57
-0
No files found.
fd-core.c
View file @
58b32625
/*
* core fine-delay driver (i.e., init and exit of the subsystems)
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/io.h>
#include "spec.h"
#include "fine-delay.h"
#include "hw/fd_main_regs.h"
/* The reset function (by Tomasz) */
static
void
fd_do_reset
(
struct
spec_fd
*
fd
,
int
hw_reset
)
{
if
(
hw_reset
)
{
writel
(
FD_RSTR_LOCK_W
(
0xdead
)
|
FD_RSTR_RST_CORE_MASK
,
fd
->
regs
+
FD_REG_RSTR
);
udelay
(
10000
);
writel
(
FD_RSTR_LOCK_W
(
0xdead
)
|
FD_RSTR_RST_CORE_MASK
|
FD_RSTR_RST_FMC_MASK
,
fd
->
regs
+
FD_REG_RSTR
);
/* TPS3307 supervisor needs time to de-assert master reset */
msleep
(
600
);
return
;
}
writel
(
FD_RSTR_LOCK_W
(
0xdead
)
|
FD_RSTR_RST_FMC_MASK
,
fd
->
regs
+
FD_REG_RSTR
);
udelay
(
1000
);
writel
(
FD_RSTR_LOCK_W
(
0xdead
)
|
FD_RSTR_RST_FMC_MASK
|
FD_RSTR_RST_CORE_MASK
,
fd
->
regs
+
FD_REG_RSTR
);
udelay
(
1000
);
}
/* This structure lists the various subsystems */
struct
modlist
{
char
*
name
;
int
(
*
init
)(
struct
spec_fd
*
);
void
(
*
exit
)(
struct
spec_fd
*
);
};
#define M(x) { #x, fd_ ## x ## _init, fd_ ## x ## _exit }
static
struct
modlist
mods
[]
=
{
M
(
spi
),
M
(
pll
),
//M(w1),
//M(i2c),
//M(acam),
//M(zio),
};
#undef M
/* probe and remove are called by fd-spec.c */
int
fd_probe
(
struct
spec_dev
*
dev
)
{
struct
modlist
*
m
;
struct
spec_fd
*
fd
;
int
i
,
ret
;
pr_debug
(
"%s
\n
"
,
__func__
);
fd
=
kzalloc
(
sizeof
(
*
fd
),
GFP_KERNEL
);
if
(
!
fd
)
{
pr_err
(
"%s: can't allocate device
\n
"
,
__func__
);
return
-
ENOMEM
;
}
dev
->
sub_priv
=
fd
;
fd
->
spec
=
dev
;
fd
->
base
=
dev
->
remap
[
0
];
fd
->
regs
=
fd
->
base
+
FD_REGS_OFFSET
;
/* First, hardware reset */
fd_do_reset
(
fd
,
1
);
/* init all subsystems */
for
(
i
=
0
,
m
=
mods
;
i
<
ARRAY_SIZE
(
mods
);
i
++
,
m
++
)
{
ret
=
m
->
init
(
fd
);
if
(
ret
<
0
)
{
pr_err
(
"%s: error initializing %s
\n
"
,
__func__
,
m
->
name
);
goto
err
;
}
}
return
0
;
err:
while
(
--
m
,
--
i
>=
0
)
m
->
exit
(
fd
);
return
ret
;
}
void
fd_remove
(
struct
spec_dev
*
dev
)
{
struct
modlist
*
m
;
int
i
=
ARRAY_SIZE
(
mods
);
pr_debug
(
"%s
\n
"
,
__func__
);
while
(
--
i
>=
0
)
{
m
=
mods
+
i
;
m
->
exit
(
dev
->
sub_priv
);
}
}
static
int
fd_init
(
void
)
{
int
ret
;
pr_debug
(
"%s
\n
"
,
__func__
);
ret
=
fd_zio_register
();
if
(
ret
<
0
)
return
ret
;
ret
=
fd_spec_init
();
if
(
ret
<
0
)
{
fd_zio_unregister
();
return
ret
;
}
return
0
;
}
static
void
fd_exit
(
void
)
{
fd_spec_exit
();
fd_zio_unregister
();
}
module_init
(
fd_init
);
module_exit
(
fd_exit
);
MODULE_LICENSE
(
"GPL and additional rights"
);
/* LGPL */
fd-spec.c
View file @
58b32625
/*
* SPEC interface for the fine-delay driver
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/io.h>
#include "spec.h"
#include "fine-delay.h"
static
int
fd_is_valid
(
int
bus
,
int
devfn
)
{
/* FIXME: restrict to some of the spec devices with moduleparam */
pr_debug
(
"%s: %x %x
\n
"
,
__func__
,
bus
,
devfn
);
return
1
;
}
int
fd_spec_init
(
void
)
{
struct
spec_dev
*
dev
;
int
ret
,
retsave
=
0
,
err
=
0
;
/* Scan the list and see what is there. Take hold of everything */
list_for_each_entry
(
dev
,
&
spec_list
,
list
)
{
if
(
!
fd_is_valid
(
dev
->
pdev
->
bus
->
number
,
dev
->
pdev
->
devfn
))
continue
;
pr_debug
(
"%s: init %04x:%04x (%pR - %p)
\n
"
,
__func__
,
dev
->
pdev
->
bus
->
number
,
dev
->
pdev
->
devfn
,
dev
->
area
[
0
],
dev
->
remap
[
0
]);
ret
=
fd_probe
(
dev
);
if
(
ret
<
0
)
{
retsave
=
ret
;
err
++
;
}
}
if
(
err
)
{
/* FIXME: doesn't undo the other boards */
return
retsave
;
}
return
0
;
}
void
fd_spec_exit
(
void
)
{
struct
spec_dev
*
dev
;
list_for_each_entry
(
dev
,
&
spec_list
,
list
)
{
if
(
!
fd_is_valid
(
dev
->
pdev
->
bus
->
number
,
dev
->
pdev
->
devfn
))
continue
;
pr_debug
(
"%s: release %04x:%04x (%pR - %p)
\n
"
,
__func__
,
dev
->
pdev
->
bus
->
number
,
dev
->
pdev
->
devfn
,
dev
->
area
[
0
],
dev
->
remap
[
0
]);
fd_remove
(
dev
);
}
}
fd-zio.c
View file @
58b32625
/*
* ZIO interface for the fine-delay driver
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/io.h>
#include <linux/zio.h>
#include "fine-delay.h"
/* Register and unregister are used to set up the template driver */
int
fd_zio_register
(
void
)
{
/* FIXME */
return
0
;
}
void
fd_zio_unregister
(
void
)
{
/* FIXME */
}
fine-delay.h
0 → 100644
View file @
58b32625
#ifndef __FINE_DELAY_H__
#define __FINE_DELAY_H__
struct
spec_fd
{
struct
spec_dev
*
spec
;
unsigned
char
__iomem
*
base
;
/* regs files are byte-oriented */
unsigned
char
__iomem
*
regs
;
};
#define FD_REGS_OFFSET 0x84000
/* SPI Bus chip selects */
#define FD_CS_PLL 1
/* AD9516 PLL */
#define FD_CS_GPIO 2
/* MCP23S17 GPIO */
/* Functions exported by fd-core.c */
extern
int
fd_probe
(
struct
spec_dev
*
dev
);
extern
void
fd_remove
(
struct
spec_dev
*
dev
);
/* Functions exported by spi.c */
extern
int
fd_spi_xfer
(
struct
spec_fd
*
fd
,
int
ss
,
int
num_bits
,
uint32_t
in
,
uint32_t
*
out
);
extern
int
fd_spi_init
(
struct
spec_fd
*
fd
);
extern
void
fd_spi_exit
(
struct
spec_fd
*
fd
);
/* Functions exported by pll.c */
extern
int
fd_pll_init
(
struct
spec_fd
*
fd
);
extern
void
fd_pll_exit
(
struct
spec_fd
*
fd
);
/* Functions exported by fd-zio.c */
extern
int
fd_zio_register
(
void
);
extern
void
fd_zio_unregister
(
void
);
extern
int
fd_zio_init
(
struct
spec_fd
*
fd
);
extern
void
fd_zio_exit
(
struct
spec_fd
*
fd
);
/* Functions exported by fd-spec.c */
extern
int
fd_spec_init
(
void
);
extern
void
fd_spec_exit
(
void
);
#endif
/* __FINE_DELAY_H__ */
pll.c
View file @
58b32625
/*
* PLL access (AD9516) for fine-delay card
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <linux/io.h>
#include "fine-delay.h"
static
int
pll_writel
(
struct
spec_fd
*
fd
,
int
val
,
int
reg
)
{
return
fd_spi_xfer
(
fd
,
FD_CS_PLL
,
24
,
(
reg
<<
8
)
|
val
,
NULL
);
}
static
int
pll_readl
(
struct
spec_fd
*
fd
,
int
reg
)
{
uint32_t
ret
;
int
err
;
err
=
fd_spi_xfer
(
fd
,
FD_CS_PLL
,
24
,
(
reg
<<
8
)
|
(
1
<<
23
),
&
ret
);
if
(
err
<
0
)
return
err
;
return
ret
&
0xff
;
}
int
fd_pll_init
(
struct
spec_fd
*
fd
)
{
int
reg
;
pr_debug
(
"%s
\n
"
,
__func__
);
if
(
pll_writel
(
fd
,
0x99
,
0x000
)
<
0
)
goto
out
;
if
(
pll_writel
(
fd
,
0x01
,
0x232
)
<
0
)
goto
out
;
reg
=
pll_readl
(
fd
,
0x003
);
if
(
reg
<
0
)
goto
out
;
if
(
reg
!=
0xc3
)
{
pr_err
(
"%s: Error in PLL communication
\n
"
,
KBUILD_MODNAME
);
pr_err
(
" (got 0x%x, expected 0xc3)
\n
"
,
reg
);
return
-
EIO
;
}
/* FIXME: program the pll */
pr_debug
(
"success!
\n
"
);
return
0
;
out:
pr_err
(
"%s: Error in SPI communication
\n
"
,
KBUILD_MODNAME
);
return
-
EIO
;
}
void
fd_pll_exit
(
struct
spec_fd
*
fd
)
{
/* nothing to do */
}
spi.c
View file @
58b32625
/*
* SPI access to fine-delay internals
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <linux/jiffies.h>
#include <linux/io.h>
#include <linux/delay.h>
#include "fine-delay.h"
#include "hw/fd_main_regs.h"
int
fd_spi_xfer
(
struct
spec_fd
*
fd
,
int
ss
,
int
num_bits
,
uint32_t
in
,
uint32_t
*
out
)
{
uint32_t
scr
=
0
,
r
;
unsigned
long
j
=
jiffies
+
HZ
;
scr
=
FD_SCR_DATA_W
(
in
)
|
FD_SCR_CPOL
;
if
(
ss
==
FD_CS_PLL
)
scr
|=
FD_SCR_SEL_PLL
;
else
if
(
ss
==
FD_CS_GPIO
)
scr
|=
FD_SCR_SEL_GPIO
;
writel
(
scr
,
fd
->
regs
+
FD_REG_SCR
);
writel
(
scr
|
FD_SCR_START
,
fd
->
regs
+
FD_REG_SCR
);
while
(
!
(
readl
(
fd
->
regs
+
FD_REG_SCR
)
&
FD_SCR_READY
))
if
(
jiffies
>
j
)
break
;
if
(
!
(
readl
(
fd
->
regs
+
FD_REG_SCR
)
&
FD_SCR_READY
))
return
-
EIO
;
scr
=
readl
(
fd
->
regs
+
FD_REG_SCR
);
r
=
FD_SCR_DATA_R
(
scr
);
if
(
out
)
*
out
=
r
;
udelay
(
100
);
/* FIXME: check */
return
0
;
}
int
fd_spi_init
(
struct
spec_fd
*
fd
)
{
/* nothing to do */
return
0
;
}
void
fd_spi_exit
(
struct
spec_fd
*
fd
)
{
/* nothing to do */
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment