Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
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
Software for White Rabbit PTP Core
Commits
0807aac4
Commit
0807aac4
authored
Nov 06, 2020
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drv: detect endianess
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
348f96f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
white-rabbit.c
driver/white-rabbit.c
+76
-0
No files found.
driver/white-rabbit.c
View file @
0807aac4
...
...
@@ -5,12 +5,88 @@
*/
#include <linux/module.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/version.h>
#include "white-rabbit.h"
#define WR_SIGNATURE 0x0
#define WR_SIGNATURE_OFFSET 0x0
struct
wr_memory_ops
{
u32
(
*
read
)(
void
*
addr
);
void
(
*
write
)(
u32
value
,
void
*
addr
);
};
struct
wr_dev
{
struct
platform_device
*
pdev
;
void
__iomem
*
base
;
struct
wr_memory_ops
memops
;
};
static
int
wr_endianess
(
struct
wr_dev
*
wr
)
{
uint32_t
signature
;
signature
=
ioread32
(
wr
->
base
+
WR_SIGNATURE_OFFSET
);
if
(
signature
==
WR_SIGNATURE
)
return
0
;
signature
=
ioread32be
(
wr
->
base
+
WR_SIGNATURE_OFFSET
);
if
(
signature
==
WR_SIGNATURE
)
return
1
;
return
-
1
;
}
static
int
wr_memops_detect
(
struct
wr_dev
*
wr
)
{
switch
(
wr_endianess
(
wr
))
{
case
0
:
wr
->
memops
.
read
=
ioread32
;
wr
->
memops
.
write
=
iowrite32
;
return
0
;
case
1
:
wr
->
memops
.
read
=
ioread32be
;
wr
->
memops
.
write
=
iowrite32be
;
return
0
;
default:
dev_err
(
&
wr
->
pdev
->
dev
,
"Invalid endianess
\n
"
);
return
-
EINVAL
;
}
}
static
int
wr_probe
(
struct
platform_device
*
pdev
)
{
struct
wr_dev
*
wr
;
struct
resource
*
res
;
int
err
;
wr
=
devm_kzalloc
(
&
pdev
->
dev
,
sizeof
(
*
wr
),
GFP_KERNEL
);
if
(
!
wr
)
return
-
ENOMEM
;
res
=
platform_get_resource
(
pdev
,
IORESOURCE_MEM
,
0
);
#if KERNEL_VERSION(3, 9, 0) > LINUX_VERSION_CODE
wr
->
base
=
devm_request_and_ioremap
(
&
pdev
->
dev
,
res
);
if
(
!
wr
->
base
)
return
-
EADDRNOTAVAIL
;
#else
wr
->
base
=
devm_ioremap_resource
(
&
pdev
->
dev
,
res
);
if
(
IS_ERR
(
wr
->
base
))
return
PTR_ERR
(
wr
->
base
);
#endif
err
=
wr_memops_detect
(
wr
);
if
(
err
)
goto
err_endianess
;
return
0
;
err_endianess:
devm_kfree
(
&
pdev
->
dev
,
wr
);
return
err
;
}
static
int
wr_remove
(
struct
platform_device
*
pdev
)
{
...
...
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