Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Simple PCIe FMC carrier SPEC
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
50
Issues
50
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
Simple PCIe FMC carrier SPEC
Commits
0c84cf8d
Commit
0c84cf8d
authored
Jun 26, 2019
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sw:drv: rename spi-gcore to spi-ocores
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
518a7e65
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
151 deletions
+161
-151
Kbuild
software/kernel/Kbuild
+1
-1
spi-ocores.h
software/kernel/platform_data/spi-ocores.h
+3
-3
spi-ocores.c
software/kernel/spi-ocores.c
+157
-147
No files found.
software/kernel/Kbuild
View file @
0c84cf8d
...
...
@@ -30,7 +30,7 @@ KBUILD_EXTRA_SYMBOLS += $(FMC_ABS)/drivers/fmc/Module.symvers
obj-m := spec-fmc-carrier.o
obj-m += gn412x-gpio.o
obj-m += gn412x-fcl.o
obj-m += spi-
gcore
.o
obj-m += spi-
ocores
.o
spec-fmc-carrier-objs := spec-core.o
spec-fmc-carrier-objs += spec-core-fpga.o
...
...
software/kernel/platform_data/spi
_g
cores.h
→
software/kernel/platform_data/spi
-o
cores.h
View file @
0c84cf8d
...
...
@@ -4,10 +4,10 @@
* Author: Federico Vaga <federico.vaga@cern.ch>
*/
#ifndef __
GN412X_GPIO
_H__
#define __
GN412X_GPIO
_H__
#ifndef __
SPI_OCORES_PDATA
_H__
#define __
SPI_OCORES_PDATA
_H__
struct
spi_
g
cores_platform_data
{
struct
spi_
o
cores_platform_data
{
unsigned
int
big_endian
;
unsigned
int
clock_hz
;
};
...
...
software/kernel/spi-
gcore
.c
→
software/kernel/spi-
ocores
.c
View file @
0c84cf8d
...
...
@@ -15,29 +15,31 @@
#include <linux/errno.h>
#include <linux/interrupt.h>
#include "platform_data/spi_gcores.h"
#include "platform_data/spi-ocores.h"
#define SPI_OCORES_BUF_SIZE 4
#define SPI_OCORES_CS_MAX_N 8
#define SPI_GCORES_BUF_SIZE 4
/* SPI register */
#define SPI_
GCORES_RX(x) (x * SPI_G
CORES_BUF_SIZE)
#define SPI_
GCORES_TX(x) (x * SPI_G
CORES_BUF_SIZE)
#define SPI_
G
CORES_CTRL 0x10
#define SPI_
G
CORES_DIV 0x14
#define SPI_
G
CORES_CS 0x18
#define SPI_
OCORES_RX(x) (x * SPI_O
CORES_BUF_SIZE)
#define SPI_
OCORES_TX(x) (x * SPI_O
CORES_BUF_SIZE)
#define SPI_
O
CORES_CTRL 0x10
#define SPI_
O
CORES_DIV 0x14
#define SPI_
O
CORES_CS 0x18
/* SPI control register fields mask */
#define SPI_
G
CORES_CTRL_CHAR_LEN 0x007F
#define SPI_
G
CORES_CTRL_GO 0x0100
/* go/busy */
#define SPI_
G
CORES_CTRL_BUSY 0x0100
/* go/busy */
#define SPI_
G
CORES_CTRL_Rx_NEG 0x0200
#define SPI_
G
CORES_CTRL_Tx_NEG 0x0400
#define SPI_
G
CORES_CTRL_LSB 0x0800
#define SPI_
G
CORES_CTRL_IE 0x1000
#define SPI_
G
CORES_CTRL_ASS 0x2000
#define SPI_
G
CORES_FLAG_POLL BIT(0)
struct
spi_
g
cores
{
#define SPI_
O
CORES_CTRL_CHAR_LEN 0x007F
#define SPI_
O
CORES_CTRL_GO 0x0100
/* go/busy */
#define SPI_
O
CORES_CTRL_BUSY 0x0100
/* go/busy */
#define SPI_
O
CORES_CTRL_Rx_NEG 0x0200
#define SPI_
O
CORES_CTRL_Tx_NEG 0x0400
#define SPI_
O
CORES_CTRL_LSB 0x0800
#define SPI_
O
CORES_CTRL_IE 0x1000
#define SPI_
O
CORES_CTRL_ASS 0x2000
#define SPI_
O
CORES_FLAG_POLL BIT(0)
struct
spi_
o
cores
{
struct
spi_master
*
master
;
unsigned
long
flags
;
void
__iomem
*
mem
;
...
...
@@ -54,39 +56,39 @@ struct spi_gcores {
unsigned
int
cur_rx_len
;
/* Register Access functions */
uint32_t
(
*
read
)(
struct
spi_
g
cores
*
sp
,
unsigned
int
reg
);
void
(
*
write
)(
struct
spi_
g
cores
*
sp
,
unsigned
int
reg
,
uint32_t
val
);
uint32_t
(
*
read
)(
struct
spi_
o
cores
*
sp
,
unsigned
int
reg
);
void
(
*
write
)(
struct
spi_
o
cores
*
sp
,
unsigned
int
reg
,
uint32_t
val
);
};
enum
spi_
g
cores_type
{
TYPE_
G
CORES
=
0
,
enum
spi_
o
cores_type
{
TYPE_
O
CORES
=
0
,
};
static
inline
uint32_t
spi_
gcores_ioread32
(
struct
spi_g
cores
*
sp
,
static
inline
uint32_t
spi_
ocores_ioread32
(
struct
spi_o
cores
*
sp
,
unsigned
int
reg
)
{
return
ioread32
(
sp
->
mem
+
reg
);
}
static
inline
void
spi_
gcores_iowrite32
(
struct
spi_g
cores
*
sp
,
static
inline
void
spi_
ocores_iowrite32
(
struct
spi_o
cores
*
sp
,
unsigned
int
reg
,
uint32_t
val
)
{
iowrite32
(
val
,
sp
->
mem
+
reg
);
}
static
inline
uint32_t
spi_
gcores_ioread32be
(
struct
spi_g
cores
*
sp
,
static
inline
uint32_t
spi_
ocores_ioread32be
(
struct
spi_o
cores
*
sp
,
unsigned
int
reg
)
{
return
ioread32be
(
sp
->
mem
+
reg
);
}
static
inline
void
spi_
gcores_iowrite32be
(
struct
spi_g
cores
*
sp
,
static
inline
void
spi_
ocores_iowrite32be
(
struct
spi_o
cores
*
sp
,
unsigned
int
reg
,
uint32_t
val
)
{
iowrite32be
(
val
,
sp
->
mem
+
reg
);
}
static
inline
struct
spi_
gcores
*
spi_g
coresdev_to_sp
(
struct
spi_device
*
spi
)
static
inline
struct
spi_
ocores
*
spi_o
coresdev_to_sp
(
struct
spi_device
*
spi
)
{
return
spi_master_get_devdata
(
spi
->
master
);
}
...
...
@@ -94,7 +96,7 @@ static inline struct spi_gcores *spi_gcoresdev_to_sp(struct spi_device *spi)
/**
* Configure controller according to SPI device needs
*/
static
int
spi_
g
cores_setup
(
struct
spi_device
*
spi
)
static
int
spi_
o
cores_setup
(
struct
spi_device
*
spi
)
{
return
0
;
}
...
...
@@ -102,74 +104,74 @@ static int spi_gcores_setup(struct spi_device *spi)
/**
* Release resources used by the SPI device
*/
static
void
spi_
g
cores_cleanup
(
struct
spi_device
*
spi
)
static
void
spi_
o
cores_cleanup
(
struct
spi_device
*
spi
)
{
}
/**
* Configure controller
*/
static
void
spi_
gcores_hw_xfer_config
(
struct
spi_g
cores
*
sp
,
static
void
spi_
ocores_hw_xfer_config
(
struct
spi_o
cores
*
sp
,
uint32_t
ctrl
,
uint16_t
divider
)
{
ctrl
&=
~
SPI_
G
CORES_CTRL_GO
;
/* be sure to not start */
sp
->
write
(
sp
,
ctrl
,
SPI_
G
CORES_CTRL
);
sp
->
write
(
sp
,
divider
,
SPI_
G
CORES_DIV
);
ctrl
&=
~
SPI_
O
CORES_CTRL_GO
;
/* be sure to not start */
sp
->
write
(
sp
,
ctrl
,
SPI_
O
CORES_CTRL
);
sp
->
write
(
sp
,
divider
,
SPI_
O
CORES_DIV
);
}
/**
* Transmit data in FIFO
*/
static
void
spi_
gcores_hw_xfer_go
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_go
(
struct
spi_o
cores
*
sp
)
{
uint32_t
ctrl
;
ctrl
=
sp
->
read
(
sp
,
SPI_
G
CORES_CTRL
);
ctrl
|=
SPI_
G
CORES_CTRL_GO
;
sp
->
write
(
sp
,
ctrl
,
SPI_
G
CORES_CTRL
);
ctrl
=
sp
->
read
(
sp
,
SPI_
O
CORES_CTRL
);
ctrl
|=
SPI_
O
CORES_CTRL_GO
;
sp
->
write
(
sp
,
ctrl
,
SPI_
O
CORES_CTRL
);
}
/**
* Slave Select
*/
static
void
spi_
gcores_hw_xfer_cs
(
struct
spi_g
cores
*
sp
,
static
void
spi_
ocores_hw_xfer_cs
(
struct
spi_o
cores
*
sp
,
unsigned
int
cs
,
unsigned
int
val
)
{
uint32_t
ss
;
ss
=
sp
->
read
(
sp
,
SPI_
G
CORES_CS
);
ss
=
sp
->
read
(
sp
,
SPI_
O
CORES_CS
);
if
(
val
)
ss
|=
BIT
(
cs
);
else
ss
&=
~
BIT
(
cs
);
sp
->
write
(
sp
,
ss
,
SPI_
G
CORES_CS
);
sp
->
write
(
sp
,
ss
,
SPI_
O
CORES_CS
);
}
/**
* Write a TX register
*/
static
void
spi_
gcores_tx_set
(
struct
spi_g
cores
*
sp
,
static
void
spi_
ocores_tx_set
(
struct
spi_o
cores
*
sp
,
unsigned
int
idx
,
uint32_t
val
)
{
if
(
WARN
(
idx
>
3
,
"Invalid TX register index %d (min:0, max: 3). Possible data corruption
\n
"
,
idx
))
return
;
sp
->
write
(
sp
,
val
,
SPI_
G
CORES_TX
(
idx
));
sp
->
write
(
sp
,
val
,
SPI_
O
CORES_TX
(
idx
));
}
/**
* Read an RX register
*/
static
uint32_t
spi_
gcores_rx_get
(
struct
spi_g
cores
*
sp
,
unsigned
int
idx
)
static
uint32_t
spi_
ocores_rx_get
(
struct
spi_o
cores
*
sp
,
unsigned
int
idx
)
{
if
(
WARN
(
idx
>
3
,
"Invalid RX register index %d (min:0, max: 3). Possible data corruption
\n
"
,
idx
))
return
0
;
return
sp
->
read
(
sp
,
SPI_
G
CORES_RX
(
idx
));
return
sp
->
read
(
sp
,
SPI_
O
CORES_RX
(
idx
));
}
/**
...
...
@@ -178,7 +180,7 @@ static uint32_t spi_gcores_rx_get(struct spi_gcores *sp, unsigned int idx)
*
* Return: number of bits_per_word
*/
static
uint8_t
spi_
gcores_hw_xfer_bits_per_word
(
struct
spi_g
cores
*
sp
)
static
uint8_t
spi_
ocores_hw_xfer_bits_per_word
(
struct
spi_o
cores
*
sp
)
{
uint8_t
nbits
;
...
...
@@ -189,37 +191,37 @@ static uint8_t spi_gcores_hw_xfer_bits_per_word(struct spi_gcores *sp)
return
nbits
;
}
static
void
spi_
gcores_hw_xfer_tx_push8
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_tx_push8
(
struct
spi_o
cores
*
sp
)
{
uint32_t
data
;
data
=
*
((
uint8_t
*
)
sp
->
cur_tx_buf
);
sp
->
cur_tx_buf
+=
1
;
spi_
g
cores_tx_set
(
sp
,
0
,
data
);
spi_
o
cores_tx_set
(
sp
,
0
,
data
);
sp
->
cur_tx_len
-=
1
;
}
static
void
spi_
gcores_hw_xfer_tx_push16
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_tx_push16
(
struct
spi_o
cores
*
sp
)
{
uint32_t
data
;
data
=
*
((
uint16_t
*
)
sp
->
cur_tx_buf
);
sp
->
cur_tx_buf
+=
2
;
spi_
g
cores_tx_set
(
sp
,
0
,
data
);
spi_
o
cores_tx_set
(
sp
,
0
,
data
);
sp
->
cur_tx_len
-=
2
;
}
static
void
spi_
gcores_hw_xfer_tx_push32
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_tx_push32
(
struct
spi_o
cores
*
sp
)
{
uint32_t
data
;
data
=
*
((
uint32_t
*
)
sp
->
cur_tx_buf
);
sp
->
cur_tx_buf
+=
4
;
spi_
g
cores_tx_set
(
sp
,
0
,
data
);
spi_
o
cores_tx_set
(
sp
,
0
,
data
);
sp
->
cur_tx_len
-=
4
;
}
static
void
spi_
gcores_hw_xfer_tx_push64
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_tx_push64
(
struct
spi_o
cores
*
sp
)
{
int
i
;
...
...
@@ -228,12 +230,12 @@ static void spi_gcores_hw_xfer_tx_push64(struct spi_gcores *sp)
data
=
*
((
uint32_t
*
)
sp
->
cur_tx_buf
);
sp
->
cur_tx_buf
+=
4
;
spi_
g
cores_tx_set
(
sp
,
i
,
data
);
spi_
o
cores_tx_set
(
sp
,
i
,
data
);
sp
->
cur_tx_len
-=
4
;
}
}
static
void
spi_
gcores_hw_xfer_tx_push128
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_tx_push128
(
struct
spi_o
cores
*
sp
)
{
int
i
;
...
...
@@ -242,63 +244,63 @@ static void spi_gcores_hw_xfer_tx_push128(struct spi_gcores *sp)
data
=
*
((
uint32_t
*
)
sp
->
cur_tx_buf
);
sp
->
cur_tx_buf
+=
4
;
spi_
g
cores_tx_set
(
sp
,
i
,
data
);
spi_
o
cores_tx_set
(
sp
,
i
,
data
);
sp
->
cur_tx_len
-=
4
;
}
}
static
void
spi_
gcores_hw_xfer_rx_push8
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_rx_push8
(
struct
spi_o
cores
*
sp
)
{
uint32_t
data
;
data
=
spi_
g
cores_rx_get
(
sp
,
0
)
&
0x000000FF
;
data
=
spi_
o
cores_rx_get
(
sp
,
0
)
&
0x000000FF
;
*
((
uint8_t
*
)
sp
->
cur_rx_buf
)
=
data
;
sp
->
cur_rx_buf
+=
1
;
sp
->
cur_rx_len
-=
1
;
}
static
void
spi_
gcores_hw_xfer_rx_push16
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_rx_push16
(
struct
spi_o
cores
*
sp
)
{
uint32_t
data
;
data
=
spi_
g
cores_rx_get
(
sp
,
0
)
&
0x0000FFFF
;
data
=
spi_
o
cores_rx_get
(
sp
,
0
)
&
0x0000FFFF
;
*
((
uint16_t
*
)
sp
->
cur_rx_buf
)
=
data
;
sp
->
cur_rx_buf
+=
2
;
sp
->
cur_rx_len
-=
2
;
}
static
void
spi_
gcores_hw_xfer_rx_push32
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_rx_push32
(
struct
spi_o
cores
*
sp
)
{
uint32_t
data
;
data
=
spi_
g
cores_rx_get
(
sp
,
0
)
&
0xFFFFFFFF
;
data
=
spi_
o
cores_rx_get
(
sp
,
0
)
&
0xFFFFFFFF
;
*
((
uint32_t
*
)
sp
->
cur_rx_buf
)
=
data
;
sp
->
cur_rx_buf
+=
4
;
sp
->
cur_rx_len
-=
4
;
}
static
void
spi_
gcores_hw_xfer_rx_push64
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_rx_push64
(
struct
spi_o
cores
*
sp
)
{
int
i
;
for
(
i
=
0
;
i
<
2
;
++
i
)
{
uint32_t
data
;
data
=
spi_
g
cores_rx_get
(
sp
,
i
)
&
0xFFFFFFFF
;
data
=
spi_
o
cores_rx_get
(
sp
,
i
)
&
0xFFFFFFFF
;
*
((
uint32_t
*
)
sp
->
cur_rx_buf
)
=
data
;
sp
->
cur_rx_buf
+=
4
;
sp
->
cur_rx_len
-=
4
;
}
}
static
void
spi_
gcores_hw_xfer_rx_push128
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_rx_push128
(
struct
spi_o
cores
*
sp
)
{
int
i
;
for
(
i
=
0
;
i
<
4
;
++
i
)
{
uint32_t
data
;
data
=
spi_
g
cores_rx_get
(
sp
,
i
)
&
0xFFFFFFFF
;
data
=
spi_
o
cores_rx_get
(
sp
,
i
)
&
0xFFFFFFFF
;
*
((
uint32_t
*
)
sp
->
cur_rx_buf
)
=
data
;
sp
->
cur_rx_buf
+=
4
;
sp
->
cur_rx_len
-=
4
;
...
...
@@ -309,21 +311,21 @@ static void spi_gcores_hw_xfer_rx_push128(struct spi_gcores *sp)
* Write pending data in RX registers
* @sp: SPI OCORE controller
*/
static
void
spi_
gcores_hw_xfer_tx_push
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_tx_push
(
struct
spi_o
cores
*
sp
)
{
uint8_t
nbits
;
nbits
=
spi_
g
cores_hw_xfer_bits_per_word
(
sp
);
nbits
=
spi_
o
cores_hw_xfer_bits_per_word
(
sp
);
if
(
nbits
>=
8
)
{
spi_
g
cores_hw_xfer_tx_push8
(
sp
);
spi_
o
cores_hw_xfer_tx_push8
(
sp
);
}
else
if
(
nbits
>=
16
)
{
spi_
g
cores_hw_xfer_tx_push16
(
sp
);
spi_
o
cores_hw_xfer_tx_push16
(
sp
);
}
else
if
(
nbits
>=
32
)
{
spi_
g
cores_hw_xfer_tx_push32
(
sp
);
spi_
o
cores_hw_xfer_tx_push32
(
sp
);
}
else
if
(
nbits
>=
64
)
{
spi_
g
cores_hw_xfer_tx_push64
(
sp
);
spi_
o
cores_hw_xfer_tx_push64
(
sp
);
}
else
if
(
nbits
>=
128
)
{
spi_
g
cores_hw_xfer_tx_push128
(
sp
);
spi_
o
cores_hw_xfer_tx_push128
(
sp
);
}
}
...
...
@@ -331,34 +333,34 @@ static void spi_gcores_hw_xfer_tx_push(struct spi_gcores *sp)
* Read received data from TX registers
* @sp: SPI OCORE controller
*/
static
void
spi_
gcores_hw_xfer_rx_pop
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_rx_pop
(
struct
spi_o
cores
*
sp
)
{
uint8_t
nbits
;
nbits
=
spi_
g
cores_hw_xfer_bits_per_word
(
sp
);
nbits
=
spi_
o
cores_hw_xfer_bits_per_word
(
sp
);
if
(
nbits
>=
8
)
{
spi_
g
cores_hw_xfer_rx_push8
(
sp
);
spi_
o
cores_hw_xfer_rx_push8
(
sp
);
}
else
if
(
nbits
>=
16
)
{
spi_
g
cores_hw_xfer_rx_push16
(
sp
);
spi_
o
cores_hw_xfer_rx_push16
(
sp
);
}
else
if
(
nbits
>=
32
)
{
spi_
g
cores_hw_xfer_rx_push32
(
sp
);
spi_
o
cores_hw_xfer_rx_push32
(
sp
);
}
else
if
(
nbits
>=
64
)
{
spi_
g
cores_hw_xfer_rx_push64
(
sp
);
spi_
o
cores_hw_xfer_rx_push64
(
sp
);
}
else
if
(
nbits
>=
128
)
{
spi_
g
cores_hw_xfer_rx_push128
(
sp
);
spi_
o
cores_hw_xfer_rx_push128
(
sp
);
}
}
static
void
spi_
gcores_hw_xfer_start
(
struct
spi_g
cores
*
sp
)
static
void
spi_
ocores_hw_xfer_start
(
struct
spi_o
cores
*
sp
)
{
unsigned
int
cs
=
sp
->
master
->
cur_msg
->
spi
->
chip_select
;
/* Optimize:
* Probably we can avoid to write CTRL DIVIDER and CS everytime
*/
spi_
g
cores_hw_xfer_config
(
sp
,
sp
->
cur_ctrl
,
sp
->
cur_divider
);
spi_
g
cores_hw_xfer_cs
(
sp
,
cs
,
1
);
spi_
g
cores_hw_xfer_go
(
sp
);
spi_
o
cores_hw_xfer_config
(
sp
,
sp
->
cur_ctrl
,
sp
->
cur_divider
);
spi_
o
cores_hw_xfer_cs
(
sp
,
cs
,
1
);
spi_
o
cores_hw_xfer_go
(
sp
);
}
/**
...
...
@@ -374,7 +376,7 @@ static void spi_gcores_hw_xfer_start(struct spi_gcores *sp)
*
* Return: 0 on success, -ETIMEDOUT on timeout
*/
static
int
spi_
gcores_wait
(
struct
spi_g
cores
*
sp
,
static
int
spi_
ocores_wait
(
struct
spi_o
cores
*
sp
,
int
reg
,
uint32_t
mask
,
uint32_t
val
,
const
unsigned
long
timeout
)
{
...
...
@@ -400,11 +402,11 @@ static int spi_gcores_wait(struct spi_gcores *sp,
*
* return: 0 on success, -ETIMEDOUT on timeout
*/
static
int
spi_
gcores_hw_xfer_wait_complete
(
struct
spi_g
cores
*
sp
,
static
int
spi_
ocores_hw_xfer_wait_complete
(
struct
spi_o
cores
*
sp
,
const
unsigned
long
timeout
)
{
return
spi_
gcores_wait
(
sp
,
SPI_G
CORES_CTRL
,
SPI_
G
CORES_CTRL_BUSY
,
0
,
timeout
);
return
spi_
ocores_wait
(
sp
,
SPI_O
CORES_CTRL
,
SPI_
O
CORES_CTRL_BUSY
,
0
,
timeout
);
}
/**
...
...
@@ -414,7 +416,7 @@ static int spi_gcores_hw_xfer_wait_complete(struct spi_gcores *sp,
*
* Return: 0 on success, otherwise a negative errno
*/
static
int
spi_
gcores_sw_xfer_finish
(
struct
spi_g
cores
*
sp
)
static
int
spi_
ocores_sw_xfer_finish
(
struct
spi_o
cores
*
sp
)
{
if
(
sp
->
cur_xfer
->
delay_usecs
)
udelay
(
sp
->
cur_xfer
->
delay_usecs
);
...
...
@@ -422,10 +424,10 @@ static int spi_gcores_sw_xfer_finish(struct spi_gcores *sp)
unsigned
int
cs
;
cs
=
sp
->
master
->
cur_msg
->
spi
->
chip_select
;
spi_
g
cores_hw_xfer_cs
(
sp
,
cs
,
0
);
spi_
o
cores_hw_xfer_cs
(
sp
,
cs
,
0
);
}
spi_
g
cores_hw_xfer_config
(
sp
,
0
,
0
);
spi_
o
cores_hw_xfer_config
(
sp
,
0
,
0
);
sp
->
cur_xfer
=
NULL
;
sp
->
cur_tx_buf
=
NULL
;
...
...
@@ -444,12 +446,12 @@ static int spi_gcores_sw_xfer_finish(struct spi_gcores *sp)
* -ENODATA when there are no transfers left,
* -EINVAL invalid bit per word
*/
static
int
spi_
gcores_sw_xfer_next_init
(
struct
spi_g
cores
*
sp
)
static
int
spi_
ocores_sw_xfer_next_init
(
struct
spi_o
cores
*
sp
)
{
struct
list_head
*
head
=
&
sp
->
master
->
cur_msg
->
transfers
;
uint32_t
hz
;
if
(
spi_
g
cores_hw_xfer_bits_per_word
(
sp
)
>
128
)
if
(
spi_
o
cores_hw_xfer_bits_per_word
(
sp
)
>
128
)
return
-
EINVAL
;
if
(
!
sp
->
cur_xfer
)
{
...
...
@@ -466,7 +468,7 @@ static int spi_gcores_sw_xfer_next_init(struct spi_gcores *sp)
}
sp
->
cur_ctrl
=
sp
->
ctrl_base
;
sp
->
cur_ctrl
|=
spi_
g
cores_hw_xfer_bits_per_word
(
sp
);
sp
->
cur_ctrl
|=
spi_
o
cores_hw_xfer_bits_per_word
(
sp
);
if
(
sp
->
cur_xfer
->
speed_hz
)
hz
=
sp
->
cur_xfer
->
speed_hz
;
else
...
...
@@ -486,17 +488,17 @@ static int spi_gcores_sw_xfer_next_init(struct spi_gcores *sp)
*
* Return: 0 on success, -ENODEV when missing transfers
*/
static
int
spi_
gcores_sw_xfer_next_start
(
struct
spi_g
cores
*
sp
)
static
int
spi_
ocores_sw_xfer_next_start
(
struct
spi_o
cores
*
sp
)
{
int
err
;
err
=
spi_
g
cores_sw_xfer_next_init
(
sp
);
err
=
spi_
o
cores_sw_xfer_next_init
(
sp
);
if
(
err
)
{
spi_finalize_current_message
(
sp
->
master
);
return
err
;
}
spi_
g
cores_hw_xfer_tx_push
(
sp
);
spi_
g
cores_hw_xfer_start
(
sp
);
spi_
o
cores_hw_xfer_tx_push
(
sp
);
spi_
o
cores_hw_xfer_start
(
sp
);
return
0
;
}
...
...
@@ -506,7 +508,7 @@ static int spi_gcores_sw_xfer_next_start(struct spi_gcores *sp)
* @sp: SPI OCORE controller
* Return: True is there are still pending data in the current transfer
*/
static
bool
spi_
gcores_sw_xfer_tx_pending
(
struct
spi_g
cores
*
sp
)
static
bool
spi_
ocores_sw_xfer_tx_pending
(
struct
spi_o
cores
*
sp
)
{
return
sp
->
cur_tx_len
;
}
...
...
@@ -517,20 +519,20 @@ static bool spi_gcores_sw_xfer_tx_pending(struct spi_gcores *sp)
*
* Return: 0 on success, -ENODATA when there is nothing to process
*/
static
int
spi_
gcores_process
(
struct
spi_g
cores
*
sp
)
static
int
spi_
ocores_process
(
struct
spi_o
cores
*
sp
)
{
uint32_t
ctrl
=
sp
->
read
(
sp
,
SPI_
G
CORES_CTRL
);
uint32_t
ctrl
=
sp
->
read
(
sp
,
SPI_
O
CORES_CTRL
);
if
(
ctrl
&
SPI_
G
CORES_CTRL_BUSY
)
if
(
ctrl
&
SPI_
O
CORES_CTRL_BUSY
)
return
-
ENODATA
;
spi_
g
cores_hw_xfer_rx_pop
(
sp
);
if
(
spi_
g
cores_sw_xfer_tx_pending
(
sp
))
{
spi_
g
cores_hw_xfer_tx_push
(
sp
);
spi_
g
cores_hw_xfer_start
(
sp
);
spi_
o
cores_hw_xfer_rx_pop
(
sp
);
if
(
spi_
o
cores_sw_xfer_tx_pending
(
sp
))
{
spi_
o
cores_hw_xfer_tx_push
(
sp
);
spi_
o
cores_hw_xfer_start
(
sp
);
}
else
{
spi_
g
cores_sw_xfer_finish
(
sp
);
spi_
g
cores_sw_xfer_next_start
(
sp
);
spi_
o
cores_sw_xfer_finish
(
sp
);
spi_
o
cores_sw_xfer_next_start
(
sp
);
}
return
0
;
...
...
@@ -544,25 +546,25 @@ static int spi_gcores_process(struct spi_gcores *sp)
* Return: 0 on success, -ENODATA when there is nothing to process, -ETIMEDOUT
* when is still pending after timeout
*/
static
int
spi_
gcores_process_poll
(
struct
spi_g
cores
*
sp
,
unsigned
int
timeout
)
static
int
spi_
ocores_process_poll
(
struct
spi_o
cores
*
sp
,
unsigned
int
timeout
)
{
int
err
;
err
=
spi_
g
cores_hw_xfer_wait_complete
(
sp
,
msecs_to_jiffies
(
timeout
));
err
=
spi_
o
cores_hw_xfer_wait_complete
(
sp
,
msecs_to_jiffies
(
timeout
));
if
(
err
)
return
err
;
err
=
spi_
g
cores_process
(
sp
);
err
=
spi_
o
cores_process
(
sp
);
if
(
err
)
return
err
;
return
0
;
}
static
irqreturn_t
spi_
g
cores_irq_handler
(
int
irq
,
void
*
arg
)
static
irqreturn_t
spi_
o
cores_irq_handler
(
int
irq
,
void
*
arg
)
{
struct
spi_
g
cores
*
sp
=
arg
;
struct
spi_
o
cores
*
sp
=
arg
;
int
err
;
err
=
spi_
g
cores_process
(
sp
);
err
=
spi_
o
cores_process
(
sp
);
if
(
err
)
return
IRQ_NONE
;
...
...
@@ -572,31 +574,32 @@ static irqreturn_t spi_gcores_irq_handler(int irq, void *arg)
/**
* Transfer one SPI message
*/
static
int
spi_
g
cores_transfer_one_message
(
struct
spi_master
*
master
,
static
int
spi_
o
cores_transfer_one_message
(
struct
spi_master
*
master
,
struct
spi_message
*
mesg
)
{
struct
spi_
g
cores
*
sp
=
spi_master_get_devdata
(
master
);
struct
spi_
o
cores
*
sp
=
spi_master_get_devdata
(
master
);
int
err
=
0
;
err
=
spi_
g
cores_sw_xfer_next_start
(
sp
);
if
(
sp
->
flags
&
SPI_
G
CORES_FLAG_POLL
)
{
err
=
spi_
o
cores_sw_xfer_next_start
(
sp
);
if
(
sp
->
flags
&
SPI_
O
CORES_FLAG_POLL
)
{
do
{
err
=
spi_
g
cores_process_poll
(
sp
,
100
);
err
=
spi_
o
cores_process_poll
(
sp
,
100
);
}
while
(
!
err
);
}
return
0
;
}
static
int
spi_
g
cores_probe
(
struct
platform_device
*
pdev
)
static
int
spi_
o
cores_probe
(
struct
platform_device
*
pdev
)
{
struct
spi_master
*
master
;
struct
spi_
g
cores
*
sp
;
struct
spi_
g
cores_platform_data
*
pdata
;
struct
spi_
o
cores
*
sp
;
struct
spi_
o
cores_platform_data
*
pdata
;
struct
resource
*
r
;
int
err
;
int
irq
;
pr_info
(
"%s:%d
\n
"
,
__func__
,
__LINE__
);
master
=
spi_alloc_master
(
&
pdev
->
dev
,
sizeof
(
*
sp
));
if
(
!
master
)
{
dev_err
(
&
pdev
->
dev
,
"failed to allocate spi master
\n
"
);
...
...
@@ -616,17 +619,17 @@ static int spi_gcores_probe(struct platform_device *pdev)
sp
->
clock_hz
=
pdata
->
clock_hz
;
/* configure SPI master */
master
->
setup
=
spi_
g
cores_setup
;
master
->
cleanup
=
spi_
g
cores_cleanup
;
master
->
transfer_one_message
=
spi_
g
cores_transfer_one_message
;
master
->
num_chipselect
=
pdata
->
num_chipselect
;
master
->
setup
=
spi_
o
cores_setup
;
master
->
cleanup
=
spi_
o
cores_cleanup
;
master
->
transfer_one_message
=
spi_
o
cores_transfer_one_message
;
master
->
num_chipselect
=
SPI_OCORES_CS_MAX_N
;
master
->
bits_per_word_mask
=
BIT
(
32
-
1
);
if
(
pdata
->
big_endian
)
{
sp
->
read
=
spi_
g
cores_ioread32be
;
sp
->
write
=
spi_
g
cores_iowrite32be
;
sp
->
read
=
spi_
o
cores_ioread32be
;
sp
->
write
=
spi_
o
cores_iowrite32be
;
}
else
{
sp
->
read
=
spi_
g
cores_ioread32
;
sp
->
write
=
spi_
g
cores_iowrite32
;
sp
->
read
=
spi_
o
cores_ioread32
;
sp
->
write
=
spi_
o
cores_iowrite32
;
}
/* assign resources */
...
...
@@ -639,7 +642,7 @@ static int spi_gcores_probe(struct platform_device *pdev)
irq
=
platform_get_irq
(
pdev
,
0
);
if
(
irq
==
-
ENXIO
)
{
sp
->
flags
|=
SPI_
G
CORES_FLAG_POLL
;
sp
->
flags
|=
SPI_
O
CORES_FLAG_POLL
;
}
else
{
if
(
irq
<
0
)
{
err
=
irq
;
...
...
@@ -647,9 +650,9 @@ static int spi_gcores_probe(struct platform_device *pdev)
}
}
if
(
!
(
sp
->
flags
&
SPI_
G
CORES_FLAG_POLL
))
{
sp
->
ctrl_base
|=
SPI_
G
CORES_CTRL_IE
;
err
=
request_any_context_irq
(
irq
,
spi_
g
cores_irq_handler
,
if
(
!
(
sp
->
flags
&
SPI_
O
CORES_FLAG_POLL
))
{
sp
->
ctrl_base
|=
SPI_
O
CORES_CTRL_IE
;
err
=
request_any_context_irq
(
irq
,
spi_
o
cores_irq_handler
,
0
,
pdev
->
name
,
sp
);
if
(
err
<
0
)
{
dev_err
(
&
pdev
->
dev
,
"Cannot claim IRQ
\n
"
);
...
...
@@ -664,20 +667,23 @@ static int spi_gcores_probe(struct platform_device *pdev)
return
0
;
err_reg_spi:
if
(
!
(
sp
->
flags
&
SPI_GCORES_FLAG_POLL
))
pr_info
(
"%s:%d
\n
"
,
__func__
,
__LINE__
);
if
(
!
(
sp
->
flags
&
SPI_OCORES_FLAG_POLL
))
free_irq
(
irq
,
sp
);
err_irq:
err_get_irq:
pr_info
(
"%s:%d
\n
"
,
__func__
,
__LINE__
);
devm_iounmap
(
&
pdev
->
dev
,
sp
->
mem
);
err_get_mem:
err_get_pdata:
pr_info
(
"%s:%d
\n
"
,
__func__
,
__LINE__
);
spi_master_put
(
master
);
return
err
;
}
static
int
spi_
g
cores_remove
(
struct
platform_device
*
pdev
)
static
int
spi_
o
cores_remove
(
struct
platform_device
*
pdev
)
{
struct
spi_
g
cores
*
sp
=
platform_get_drvdata
(
pdev
);
struct
spi_
o
cores
*
sp
=
platform_get_drvdata
(
pdev
);
int
irq
=
platform_get_irq
(
pdev
,
0
);
if
(
irq
>
0
)
...
...
@@ -690,27 +696,31 @@ static int spi_gcores_remove(struct platform_device *pdev)
return
0
;
}
static
const
struct
platform_device_id
spi_gcores_id_table
[]
=
{
static
const
struct
platform_device_id
spi_ocores_id_table
[]
=
{
{
.
name
=
"ocores-spi"
,
.
driver_data
=
TYPE_OCORES
,
},
{
.
name
=
"
ocores-i2c
"
,
.
driver_data
=
TYPE_
G
CORES
,
.
name
=
"
spi-ocores
"
,
.
driver_data
=
TYPE_
O
CORES
,
},
{
.
name
=
""
},
/* last */
};
static
struct
platform_driver
spi_
g
cores_driver
=
{
.
probe
=
spi_
g
cores_probe
,
.
remove
=
spi_
g
cores_remove
,
static
struct
platform_driver
spi_
o
cores_driver
=
{
.
probe
=
spi_
o
cores_probe
,
.
remove
=
spi_
o
cores_remove
,
.
driver
=
{
.
name
=
"
spi-gcores
"
,
.
name
=
"
ocores-spi
"
,
.
owner
=
THIS_MODULE
,
},
.
id_table
=
spi_
g
cores_id_table
,
.
id_table
=
spi_
o
cores_id_table
,
};
module_platform_driver
(
spi_
g
cores_driver
);
module_platform_driver
(
spi_
o
cores_driver
);
MODULE_AUTHOR
(
"Federico Vaga <federico.vaga@cern.ch>"
);
MODULE_DESCRIPTION
(
"SPI controller driver for OHWR General-Cores SPI Master"
);
MODULE_LICENSE
(
"GPL"
);
MODULE_VERSION
(
VERSION
);
MODULE_DEVICE_TABLE
(
platform
,
spi_
g
cores_id_table
);
MODULE_DEVICE_TABLE
(
platform
,
spi_
o
cores_id_table
);
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