Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
fe33bbf7
Commit
fe33bbf7
authored
Nov 21, 2014
by
Jeroen Vreeken
Browse files
Add device tree.
Move /dev/mem code to single file
parent
e6833109
Changes
11
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
fe33bbf7
...
...
@@ -14,6 +14,8 @@
*.dot
*.pdf
*.svg
*.dtb
*.dtbo
.libs
bin
include
build.mk
View file @
fe33bbf7
...
...
@@ -82,3 +82,10 @@ endef
@
echo
" DOT
$<
"
@
dot
$<
-o
$@
-Tpdf
%.dtb
:
%.dts
@
echo
" DTC
$<
"
@
dtc
-I
dts
$<
-O
dtb
-o
$@
%.dtbo
:
%.dts
@
echo
" DTCo
$<
"
@
dtc
-I
dts
$<
-O
dtb
-o
$@
controller/am335x/BB-controller-00A0.dts
0 → 100644
View file @
fe33bbf7
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2014
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/>.
*/
/dts-v1/;
/*/plugin/;*/
/{
compatible = "ti,beaglebone-black";
/* identification */
part-number = "BB-controller";
version = "00A0";
/* resources we use */
exclusive-use =
"P9.39", "P9.40", "P9.37", "P9.38", "P9.33", "P9.36", "P9.35",
"tscadc",
"ehrpwm0a",
"ehrpwm0b",
"ehrpwm1a",
"ehrpwm1b",
"ehrpwm2a",
"ehrpwm2b";
fragment@0 {
target = <0xdeadbeef>;
__overlay__ {
#address-cells = <0x1>;
#size-cells = <0x1>;
tscadc {
compatible = "ti,ti-tscadc";
reg = <0x44e0d000 0x1000>;
ti,hwmods = "adc_tsc";
status = "okay";
adc {
ti,adc-channels = <0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7>;
};
};
};
};
__fixups__ {
ocp = "/fragment@0:target:0";
};
};
controller/am335x/am335x.c
0 → 100644
View file @
fe33bbf7
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2014
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/>.
*/
#include "am335x.h"
#include <log/log.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
struct
map
{
size_t
base
;
size_t
size
;
void
*
map
;
struct
map
*
next
;
};
static
struct
map
*
mapped_list
=
NULL
;
#define AM335X_MIN_SIZE 4096
void
*
am335x_mem
(
size_t
base
,
size_t
size
)
{
int
fd
;
void
*
map
;
struct
map
*
entry
;
size
=
(
size
+
(
AM335X_MIN_SIZE
-
1
))
&
~
(
AM335X_MIN_SIZE
-
1
);
for
(
entry
=
mapped_list
;
entry
;
entry
=
entry
->
next
)
{
if
(
base
>=
entry
->
base
&&
(
base
+
size
)
<=
(
entry
->
base
+
entry
->
size
))
{
char
*
tmp
=
entry
->
map
;
tmp
+=
base
-
entry
->
base
;
return
tmp
;
}
}
entry
=
calloc
(
1
,
sizeof
(
struct
map
));
if
(
!
entry
)
{
log_send
(
LOG_T_ERROR
,
"am335x: calloc() failed"
);
goto
err_calloc
;
}
if
((
fd
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
log_send
(
LOG_T_ERROR
,
"am335x: Error opening /dev/mem"
);
goto
err_open
;
}
map
=
mmap
(
NULL
,
size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
base
);
close
(
fd
);
if
(
!
map
)
{
log_send
(
LOG_T_ERROR
,
"am335x: mmap 0x%zx bytes @ 0x%08zx failed"
,
size
,
base
);
goto
err_mmap
;
}
log_send
(
LOG_T_DEBUG
,
"am335x: 0x%zx bytes mapped @ 0x%08zx"
,
size
,
base
);
entry
->
next
=
mapped_list
;
mapped_list
=
entry
;
return
map
;
err_mmap:
err_open:
free
(
entry
);
err_calloc:
return
NULL
;
}
controller/am335x/am335x.h
View file @
fe33bbf7
...
...
@@ -293,4 +293,8 @@ static inline void am335x_write16(void *base, size_t reg_offset, uint16_t value)
*
reg
=
value
;
}
void
*
am335x_mem
(
size_t
base
,
size_t
size
);
#endif
/* _INCLUDE_AM335X_ */
controller/am335x/block_am335x_adc.c
View file @
fe33bbf7
...
...
@@ -20,10 +20,6 @@
#include <controller/controller_block.h>
#include <log/log.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
struct
controller_block_private
{
...
...
@@ -153,22 +149,12 @@ static void param_set(struct controller_block *adc, int param, va_list val)
struct
controller_block
*
block_am335x_adc_create
(
char
*
name
)
{
struct
controller_block
*
adc
;
int
fd
;
void
*
base
;
uint32_t
reg
;
if
((
fd
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
log_send
(
LOG_T_ERROR
,
"Error opening /dev/mem"
);
close
(
fd
);
return
NULL
;
}
base
=
mmap
(
NULL
,
AM335X_ADC_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
AM335X_ADC_BASE
);
close
(
fd
);
base
=
am335x_mem
(
AM335X_ADC_BASE
,
AM335X_ADC_SIZE
);
if
(
!
base
)
{
log_send
(
LOG_T_ERROR
,
"Mapping ADC failed"
);
log_send
(
LOG_T_ERROR
,
"
%s:
Mapping ADC failed"
,
name
);
return
NULL
;
}
log_send
(
LOG_T_DEBUG
,
"%s: ADC mapped @ %p"
,
name
,
base
);
...
...
@@ -296,6 +282,5 @@ err_outterm:
controller_block_free
(
adc
);
err_alloc:
err_rev:
munmap
(
base
,
AM335X_ADC_SIZE
);
return
NULL
;
}
controller/am335x/block_am335x_gpi.c
View file @
fe33bbf7
...
...
@@ -20,13 +20,6 @@
#include <controller/controller_block.h>
#include <log/log.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>
#include <math.h>
struct
controller_block_private
{
...
...
@@ -60,7 +53,6 @@ static struct controller_block_outterm_list outterms[] = {
struct
controller_block
*
block_am335x_gpi_create
(
char
*
name
,
va_list
ap
)
{
struct
controller_block
*
gpi
;
int
fd
;
void
*
base
;
uint32_t
reg
;
uint32_t
notpin
;
...
...
@@ -96,17 +88,9 @@ struct controller_block * block_am335x_gpi_create(char *name, va_list ap)
return
NULL
;
}
if
((
fd
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
log_send
(
LOG_T_ERROR
,
"%s: Error opening /dev/mem"
,
name
);
close
(
fd
);
return
NULL
;
}
base
=
mmap
(
NULL
,
AM335X_GPIO_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
offset
);
close
(
fd
);
base
=
am335x_mem
(
offset
,
AM335X_GPIO_SIZE
);
if
(
!
base
)
{
log_send
(
LOG_T_ERROR
,
"Mapping GPIO failed"
);
log_send
(
LOG_T_ERROR
,
"
%s:
Mapping GPIO failed"
,
name
);
return
NULL
;
}
log_send
(
LOG_T_DEBUG
,
"%s: GPIO%d (0x%"
PRIx32
") mapped @ %p"
,
name
,
...
...
@@ -157,6 +141,5 @@ err_outterm:
controller_block_free
(
gpi
);
err_alloc:
err_rev:
munmap
(
base
,
AM335X_GPIO_SIZE
);
return
NULL
;
}
controller/am335x/block_am335x_gpo.c
View file @
fe33bbf7
...
...
@@ -20,13 +20,6 @@
#include <controller/controller_block.h>
#include <log/log.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>
#include <math.h>
struct
controller_block_private
{
...
...
@@ -62,7 +55,6 @@ static struct controller_block_interm_list interms[] = {
struct
controller_block
*
block_am335x_gpo_create
(
char
*
name
,
va_list
ap
)
{
struct
controller_block
*
gpo
;
int
fd
;
void
*
base
;
uint32_t
reg
;
uint32_t
notpin
;
...
...
@@ -98,17 +90,9 @@ struct controller_block * block_am335x_gpo_create(char *name, va_list ap)
return
NULL
;
}
if
((
fd
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
log_send
(
LOG_T_ERROR
,
"%s: Error opening /dev/mem"
,
name
);
close
(
fd
);
return
NULL
;
}
base
=
mmap
(
NULL
,
AM335X_GPIO_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
offset
);
close
(
fd
);
base
=
am335x_mem
(
offset
,
AM335X_GPIO_SIZE
);
if
(
!
base
)
{
log_send
(
LOG_T_ERROR
,
"Mapping GPIO failed"
);
log_send
(
LOG_T_ERROR
,
"
%s:
Mapping GPIO failed"
,
name
);
return
NULL
;
}
log_send
(
LOG_T_DEBUG
,
"%s: GPIO%d (0x%"
PRIx32
") mapped @ %p"
,
name
,
...
...
@@ -162,6 +146,5 @@ err_interm:
controller_block_free
(
gpo
);
err_alloc:
err_rev:
munmap
(
base
,
AM335X_GPIO_SIZE
);
return
NULL
;
}
controller/am335x/block_am335x_pwm.c
View file @
fe33bbf7
...
...
@@ -20,19 +20,13 @@
#include <controller/controller_block.h>
#include <log/log.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>
#include <math.h>
struct
controller_block_private
{
float
*
in
;
uint16_
t
tbprd
;
// period
floa
t
tbprd
;
// period
double
freq
;
bool
sym
;
...
...
@@ -156,7 +150,6 @@ static struct controller_block_interm_list interms[] = {
struct
controller_block
*
block_am335x_pwm_create
(
char
*
name
,
va_list
ap
)
{
struct
controller_block
*
pwm
;
int
fd
;
void
*
base
;
uint32_t
reg
;
int
pwm_nr
;
...
...
@@ -179,18 +172,10 @@ struct controller_block * block_am335x_pwm_create(char *name, va_list ap)
offset
=
AM335X_PWMSS2_BASE
;
break
;
}
if
((
fd
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
log_send
(
LOG_T_ERROR
,
"%s: Error opening /dev/mem"
,
name
);
close
(
fd
);
return
NULL
;
}
base
=
mmap
(
NULL
,
AM335X_PWMSS_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
offset
);
close
(
fd
);
base
=
am335x_mem
(
offset
,
AM335X_PWMSS_SIZE
);
if
(
!
base
)
{
log_send
(
LOG_T_ERROR
,
"Mapping PWM failed"
);
log_send
(
LOG_T_ERROR
,
"
%s:
Mapping PWM failed"
,
name
);
return
NULL
;
}
log_send
(
LOG_T_DEBUG
,
"%s: PWM mapped @ %p"
,
name
,
base
);
...
...
@@ -249,6 +234,5 @@ err_interm:
controller_block_free
(
pwm
);
err_alloc:
err_rev:
munmap
(
base
,
AM335X_PWMSS_SIZE
);
return
NULL
;
}
controller/am335x/block_am335x_qed.c
View file @
fe33bbf7
...
...
@@ -20,13 +20,6 @@
#include <controller/controller_block.h>
#include <log/log.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>
#include <math.h>
struct
controller_block_private
{
...
...
@@ -64,7 +57,6 @@ static struct controller_block_outterm_list outterms[] = {
struct
controller_block
*
block_am335x_qed_create
(
char
*
name
,
va_list
ap
)
{
struct
controller_block
*
qed
;
int
fd
;
void
*
base
;
uint32_t
reg
;
int
qed_nr
;
...
...
@@ -88,17 +80,9 @@ struct controller_block * block_am335x_qed_create(char *name, va_list ap)
break
;
}
if
((
fd
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
log_send
(
LOG_T_ERROR
,
"%s: Error opening /dev/mem"
,
name
);
close
(
fd
);
return
NULL
;
}
base
=
mmap
(
NULL
,
AM335X_PWMSS_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fd
,
offset
);
close
(
fd
);
base
=
am335x_mem
(
offset
,
AM335X_PWMSS_SIZE
);
if
(
!
base
)
{
log_send
(
LOG_T_ERROR
,
"Mapping QED failed"
);
log_send
(
LOG_T_ERROR
,
"
%s:
Mapping QED failed"
,
name
);
return
NULL
;
}
log_send
(
LOG_T_DEBUG
,
"%s: QED mapped @ %p"
,
name
,
base
);
...
...
@@ -152,6 +136,5 @@ err_outterm:
controller_block_free
(
qed
);
err_alloc:
err_rev:
munmap
(
base
,
AM335X_PWMSS_SIZE
);
return
NULL
;
}
controller/am335x/build.mk
View file @
fe33bbf7
AM335X_TARGETS
:=
$(LIBDIR)
/libam335x.la
AM335X_TARGETS
:=
$(LIBDIR)
/libam335x.la
$(DIR)
/BB-controller-00A0.dtbo
AM335X_BLOCKS
:=
\
am335x_adc
\
...
...
@@ -9,7 +9,8 @@ AM335X_BLOCKS := \
am335x_gpo
AM335X_SRCS
+=
$(
addsuffix
.c,
$(
addprefix
$(DIR)
/block_,
$(AM335X_BLOCKS)
))
AM335X_SRCS
+=
$(DIR)
/am335x.c
\
$(
addsuffix
.c,
$(
addprefix
$(DIR)
/block_,
$(AM335X_BLOCKS)
))
CTRL_BLOCKS
+=
$(AM335X_BLOCKS)
CTRL_BLOCK_LIBS
+=
libam335x.la
...
...
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