37 #include <sys/types.h>
47 volatile unsigned int *gpio, *pwm, *clk;
64 mem_fd = open(
"/dev/mem", O_RDWR | O_SYNC);
68 debug(
"[%s] Can't open /dev/mem. Are you root?\n", __func__);
84 static volatile unsigned int*
85 map_register (
int mem_fd,
unsigned int addr)
91 if ( (mem = malloc(BLOCK_SIZE + (PAGE_SIZE - 1))) == NULL )
93 debug(
"[%s] Can't allocate memory.\n", __func__);
98 if ( (
unsigned long) mem % PAGE_SIZE )
100 mem += PAGE_SIZE - ((
unsigned long) mem % PAGE_SIZE);
104 map = (
unsigned char *) mmap ((caddr_t) mem,
105 BLOCK_SIZE, PROT_READ | PROT_WRITE,
106 MAP_SHARED | MAP_FIXED, mem_fd, addr);
108 if ( (
long) map < 0 )
110 debug(
"[%s] Can't mmap memory.\n", __func__);
113 return (
volatile unsigned int*) map;
129 mem_fd = open_memory();
132 debug(
"[%s] Can't open /dev/mem.\n", __func__);
137 gpio = map_register(mem_fd, GPIO_BASE);
138 clk = map_register(mem_fd, CLOCK_BASE);
139 pwm = map_register(mem_fd, PWM_BASE);
149 PWMCLK_DIV = 0x5A000000 | (32 << 12);
150 PWMCLK_CNTL = 0x5A000011;
160 PWM0_RANGE = PWM_MAX;
163 PWM_CONTROL = PWM0_ENABLE;
200 if ( value > PWM_MAX )