[RK3288][Android6.0] 除錯筆記 --- pmu(rk818)暫存器讀寫
阿新 • • 發佈:2019-01-03
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),
};
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;
}
如果要實現所有暫存器dump,可以新增一個選項,其他pmu模組方法一樣。