Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwencai committed May 13, 2015
1 parent 566a4a7 commit 5d29a6a
Show file tree
Hide file tree
Showing 22 changed files with 1,968 additions and 0 deletions.
1 change: 1 addition & 0 deletions .axp209.ko.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmd_/home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209.ko := mipsel-openwrt-linux-ld -r -m elf32ltsmip -T /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/linux-3.10.49/scripts/module-common.lds -s --build-id -o /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209.ko /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209.o /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209.mod.o
419 changes: 419 additions & 0 deletions .axp209.mod.o.cmd

Large diffs are not rendered by default.

700 changes: 700 additions & 0 deletions .axp209.o.cmd

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .tmp_versions/axp209.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209.ko
/home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209.o
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARCH ?=mips
CROSS_COMPILE ?=mipsel-openwrt-linux-
CC=$(CROSS_COMPILE)gcc
obj-m := axp209.o #要生成的模块名
mymodules-objs:= axp209.o #生成这个模块名所需要的目标文件

KDIR :=/home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/linux-3.10.49/

PWD := $(shell pwd)

default:
$(CC) demo.c -o demo
$(CC) axp.c -o axp209 -lm
make -C $(KDIR) M=$(PWD) modules

clean:
rm -rf *.o .* .cmd *.ko *.mod.c .tmp_versions demo axp209
4 changes: 4 additions & 0 deletions Module.symvers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0x00000000 unregister_axp209_notifier /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209 EXPORT_SYMBOL
0x00000000 rgbled_notifier /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/rgbled/rgbled EXPORT_SYMBOL
0x00000000 register_axp209_notifier /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209 EXPORT_SYMBOL
0x00000000 call_axp209_notifiers /home/mrdong/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/driver_dev/axp209_drv/axp209 EXPORT_SYMBOL
91 changes: 91 additions & 0 deletions axp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "axp209.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
void usage() __attribute__ ((noreturn));
void usage()
{
printf("-----------usage----------->\n");
printf("axp209 set reg value\n");
printf("axp209 get reg\n");
exit(-1);
}

int hex2int(char *szhex)
{
int n = 0, len;
int value = 0;
char hs2i[128] ={
['0'] = 0,
['1'] = 1,
['2'] = 2,
['3'] = 3,
['4'] = 4,
['5'] = 5,
['6'] = 6,
['7'] = 7,
['8'] = 8,
['9'] = 9,
['A'] = 10,
['B'] = 11,
['C'] = 12,
['D'] = 13,
['E'] = 14,
['F'] = 15,
['a'] = 10,
['b'] = 11,
['c'] = 12,
['d'] = 13,
['e'] = 14,
['f'] = 15,
};
len = strlen(szhex);
while(len)
{
value += hs2i[szhex[len - 1]] * pow(16, n);
n ++;
len --;
}
return value;
}
int str2int(char *hex)
{
if(hex[1] == 'x' || hex[1] == 'X')
{
return hex2int(&hex[2]);
}
return atoi(hex);
}
int main(int argc, char *argv[])
{
int fd = -1;
unsigned char status = 0xff;
unsigned short context = 0xff;
fd = open("/dev/axp209",O_RDWR, S_IRUSR | S_IWUSR);
ioctl(fd, AXP209_GET_ELEC, &status);
printf("%s\t%d\t%d\n", __func__, __LINE__, status);
if(argc > 2 && (!strcmp("get",argv[1])) )
{
context = (str2int(argv[2]) & 0xff) << 8;
ioctl(fd, AXP209_GET_REG, &context);
printf("%x\t%x\n",context >> 8, context & 0xff);
}
else if(argc > 3 && (!strcmp("set",argv[1])))
{
context = (str2int(argv[2]) & 0xff) << 8;
context |= (str2int(argv[3]) & 0xff);
ioctl(fd, AXP209_SET_REG, &context);
}
else
{
// usage();
ioctl(fd, AXP209_GET_ADDR, 0x00);
}
close(fd);
return 0;
}
Binary file added axp209
Binary file not shown.
Loading

0 comments on commit 5d29a6a

Please sign in to comment.