- 论坛徽章:
- 0
|
部分代码:- struct okl_reg_data {
- u8 reg;
- u8 data_high;
- u8 data_low;
- };
- static struct okl3800_data okl_data;
- static struct okl_reg_data okl3800_init_data[20]=
- {
- {0x20, 0xf0, 0x00},
- {0x21, 0x3f, 0xc7},
- {0x22, 0x20, 0x00},
- {0x23, 0x00, 0x20},
- {0x25, 0x03, 0x80},
- {0x27, 0x03, 0x80},
- {0x28, 0x44, 0x02},
- {0x29, 0xe8, 0x00},
- {0x02, 0x66, 0x17},
- {0x04, 0x9c, 0xc9},
- {0x05, 0x66, 0x37},
- {0x07, 0x00, 0x4c},
- {0x08, 0x6c, 0x90},
- {0x09, 0x18, 0x00},
- {0x0b, 0x00, 0x08},
- {0x0d, 0x48, 0xbd},
- {0x16, 0x00, 0xff},
- {0x18, 0x00, 0x67},
- {0x1a, 0x19, 0xe0},
- {0x1b, 0x42, 0x00}
- };
- #ifdef CONFIG_HAS_EARLYSUSPEND
- static void okl3800_early_suspend(struct early_suspend *h);
- static void okl3800_late_resume(struct early_suspend *h);
- #endif
- static int okl3800_i2c_rxdata(char *rxdata, int length)
- {
- struct i2c_msg msgs[] = {
- {
- .addr = okl_data.client->addr,
- .flags = 0,
- .len = 1,
- .buf = rxdata,
- },
- {
- .addr = okl_data.client->addr,
- .flags = I2C_M_RD,
- .len = length,
- .buf = rxdata,
- },
- };
- if (i2c_transfer(okl_data.client->adapter, msgs, 2) > 0) {
- return 0;
- } else {
- printk("...read data err...\n");
- return -EIO;
- }
- }
- static int okl3800_i2c_txdata(char *txdata, int length)
- {
- struct i2c_msg msgs[] = {
- {
- .addr = okl_data.client->addr,
- .flags = 0,
- .len = length,
- .buf = txdata,
- },
- };
- if (i2c_transfer(okl_data.client->adapter, msgs, 1) > 0) {
- return 0;
- } else {
- printk("...write data err...\n");
- return -EIO;
- }
- }
- // chip reg init
- static int okl3800_reg_init(void)
- {
- int i = 0;
- u8 buf[3];
- printk("==========okl3800_reg_init========\n");
-
- for (i = 0; i < 20; i++) {
- buf[0] = okl3800_init_data[i].reg;
- buf[1] = okl3800_init_data[i].data_high;
- buf[2] = okl3800_init_data[i].data_low;
-
- printk("===buf[%d].high=%x,buf[%d].low=%x===\n", i, buf[1], i, buf[2]);
- okl3800_i2c_txdata(buf, 3);
- }
-
- return 0;
- }
- static int okl3800_reg_read_back(void)
- {
- int i = 0;
- u8 buf[2];
- printk("===read back===\n\n");
- for (i = 0; i < 20; i++) {
- buf[0] = okl3800_init_data[i].reg;
- okl3800_i2c_rxdata(buf, 2);
- printk("===buf[%d].high=%x,buf[%d].low=%x===\n", i, buf[0], i, buf[1]);
- }
- return 0;
- }
复制代码 |
|