本文转载自:http://blog.csdn.net/kris_fei/article/details/76919134
Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92
rk的pmu模块只提供了每次单个寄存器的读写,驱动提供了这个节点供使用:/sys/rk818/rk818_test
举例:
- 读取:
echo r 0x23 > /sys/rk818/rk818_test: 读取地址 0x23 的值,r 表示读;
- 写入:
echo w 0x23 0x7f > /sys/rk818/rk818_test: 对地址 0x23 赋值为 0x7f, w 表示写。
代码实现部分:
rk818.c
static struct rk818_attribute rk818_attrs[] = {
/* node_name permision show_func store_func */
__ATTR(rk818_test, S_IRUGO | S_IWUSR, rk818_test_show, rk818_test_store),
};
- 1
- 2
- 3
- 4
static ssize_t rk818_test_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
{
u32 getdata[8];
u8 regAddr;
u8 data;
char cmd; const char *buftmp = buf; struct rk818 *rk818 = g_rk818; /** * W Addr(8Bit) regAddr(8Bit) data0(8Bit) data1(8Bit) data2(8Bit) data3(8Bit) * :data can be less than 4 byte * R regAddr(8Bit) * C gpio_name(poweron/powerhold/sleep/boot0/boot1) value(H/L) */ sscanf(buftmp, "%c ", &cmd); printk("------zhangqing: get cmd = %c\n", cmd); switch (cmd) { case 'w': sscanf(buftmp, "%c %x %x ", &cmd, &getdata[0], &getdata[1]); regAddr = (u8)(getdata[0] & 0xff); data = (u8)(getdata[1] & 0xff); printk("get value = %x\n", data); rk818_i2c_write(rk818, regAddr, 1, data); rk818_i2c_read(rk818, regAddr, 1, &data); printk("%x %x\n", getdata[1], data); break; case 'r': sscanf(buftmp, "%c %x ", &cmd, &getdata[0]); printk("CMD : %c %x\n", cmd, getdata[0]); regAddr = (u8)(getdata[0] & 0xff); rk818_i2c_read(rk818, regAddr, 1, &data); printk("%x %x\n", getdata[0], data); break; default: printk("Unknown command\n"); break; } return n; }
- 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
- 38
- 39
- 40
- 41
- 42
- 43
如果要实现所有寄存器dump,可以添加一个选项,其他pmu模块方法一样。