-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkbledsoff.c
38 lines (29 loc) · 1006 Bytes
/
kbledsoff.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*****************************************************
* Turn the ZipitZ2 KB LEDS OFF
* simple error checking.
*
* 05/02/10 Russell K. Davis
* (Large) portions ripped from devmem2
*
****************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>
#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE - 1)
#define KBLEDOFF "0x0"
#define GPIO_BASE 0x40C00004 /* PXA270 GPIO Register Base */
int main(int argc, char **argv) {
int fd;
void *map_base, *virt_addr;
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0) exit(255);
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE , MAP_SHARED, fd, GPIO_BASE & ~MAP_MASK);
if(map_base == (void *) -1) exit(255);
virt_addr = map_base + (GPIO_BASE & MAP_MASK);
*((unsigned long *) virt_addr) = strtoul(KBLEDOFF,0,0);
if(munmap(map_base, MAP_SIZE) == -1) exit(255) ;
close(fd);
}