in spruh73g.pdf which is the docu of the AM335x
there are 3 scratch register mentioned, in the RTC
I wold like to access these registers,
I have written one mmap verison and one kernel module
but they do not read the same values the other version has written,
so either one, or even both, are wrong,
this is the mmap verison, redutce to the read part
Code:
/*
* spruh73g.pdf
* page 153, memory map
* RTCSS 0x44E3_E000 - 0x44E3_EFFF 4KB RTC Registers
*
* page 3615, 20.3.5 RTC Registers
* 60h RTC_SCRATCH0_REG Scratch 0 Register
* 64h RTC_SCRATCH1_REG Scratch 1 Register
* 68h RTC_SCRATCH2_REG Scratch 2 Register
*
*/
#define MAP_SIZE 4096UL
#define RTCSSMEM 0x44E3E000
typedef struct scratchreg {
int value [ 3 ];
} scratchreg;
int
read_scratchreg( scratchreg* sr )
{
int fd = 0;
void* memmap;
void* scratch_addr;
int offset = 0x60 ;
fd = open("/dev/mem", O_RDWR | O_SYNC) ;
if(fd == -1)
{
return -1;
}
memmap = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, RTCSSMEM );
if(memmap == (void *) -1)
{
close(fd);
return -1;
}
scratch_addr = (unsigned int*)memmap + (offset );
memcpy( &sr->value[0], scratch_addr, sizeof(sr->value));
munmap(memmap, MAP_SIZE) ;
close(fd);
return 0;
}
these are the relevant parts from the module code
Code:
#define RTCSSMEM 0x44E3E000
#define SCRATCHREG_OFFSET 0x60
#define SCRATCHREG_SIZE 12
// in inti this happes ..
//request_mem_region( RTCSSMEM + SCRATCHREG_OFFSET, SCRATCHREG_SIZE, "scratchdev" ) ;
//scratchreg = ioremap_nocache( RTCSSMEM + SCRATCHREG_OFFSET, SCRATCHREG_SIZE) ;
static ssize_t scratchdev_read(struct file *f, char __user *buf, size_t len, loff_t *off)
{
int i;
u8 byte;
if (*off >= SCRATCHREG_SIZE)
{
return 0 ;
}
if (*off + len > SCRATCHREG_SIZE)
{
len = SCRATCHREG_SIZE - *off;
}
for (i = 0; i < len; i++)
{
byte = ioread8((u8 *)scratchreg + i);
if (copy_to_user(buf + i, &byte, 1))
{
return -EFAULT;
}
}
*off += len;
return len;
}
If anyone can help me with this it would be great
eidt:
the mmap method behaves incorrect,
the first 2 integers get truncated after 127, the last after 64
there must be a very obvious reason what I do wrong, but what?
(the mmap write method does exactly the same but has of course the first 2 memcpy args swapped)