Skip to content

Commit

Permalink
s6sy761: use GFP_DMA memory for touch_i2c_read_block()
Browse files Browse the repository at this point in the history
DMA should be using heap memory allocated with GFP_DMA.
Also, remove unnecessary buffer initializations.

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
  • Loading branch information
arter97 authored and acuicultor committed Sep 15, 2021
1 parent 7b5cb8b commit 1115a18
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
Expand Up @@ -24,6 +24,7 @@

#include "sec_drivers_s6sy761.h"

static struct dma_buf_s6sy761 *dma_buffer;
extern int tp_register_times;
extern struct touchpanel_data *g_tp;
#define PM_QOS_VALUE_TP 200
Expand Down Expand Up @@ -408,7 +409,7 @@ int sec_wait_for_ready(struct chip_data_s6sy761 *chip_info, unsigned int ack)
int rc = -1;
int retry = 0, retry_cnt = 100;
int8_t status = -1;
u8 tBuff[SEC_EVENT_BUFF_SIZE] = {0,};
u8 *tBuff = dma_buffer->tBuff;
int num = 0;

while (touch_i2c_read_block(chip_info->client, SEC_READ_ONE_EVENT, SEC_EVENT_BUFF_SIZE, tBuff) > 0) {
Expand Down Expand Up @@ -438,7 +439,7 @@ int sec_wait_for_ready(struct chip_data_s6sy761 *chip_info, unsigned int ack)
static int sec_enter_fw_mode(struct chip_data_s6sy761 *chip_info)
{
int ret = -1;
u8 device_id[3] = {0};
u8 *device_id = dma_buffer->device_id;
u8 fw_update_mode_passwd[] = {0x55, 0xAC};

ret = touch_i2c_write_block(chip_info->client, SEC_CMD_ENTER_FW_MODE, sizeof(fw_update_mode_passwd), fw_update_mode_passwd);
Expand Down Expand Up @@ -504,7 +505,7 @@ static u8 sec_checksum(u8 *data, int offset, int size)
static int sec_flash_page_erase(struct chip_data_s6sy761 *chip_info, u32 page_idx, u32 page_num)
{
int ret = -1;
u8 tCmd[6] = {0};
u8 tCmd[6];

tCmd[0] = SEC_CMD_FLASH_ERASE;
tCmd[1] = (u8)((page_idx >> 8) & 0xFF);
Expand Down Expand Up @@ -590,7 +591,7 @@ static int sec_flash_write(struct chip_data_s6sy761 *chip_info, u32 mem_addr, u8
int ret = -1;
u32 page_idx = 0, size_copy = 0, flash_page_size = 0;
u32 page_idx_start = 0, page_idx_end = 0, page_num = 0;
u8 page_buf[SEC_FW_BLK_SIZE_MAX] = {0};
u8 page_buf[SEC_FW_BLK_SIZE_MAX];

if (mem_size == 0)
return 0;
Expand Down Expand Up @@ -655,7 +656,6 @@ static int sec_block_read(struct chip_data_s6sy761 *chip_info, u32 mem_addr, int
{
int ret;
u8 cmd[5];
u8 *data;

if (mem_size >= 64 * 1024) {
TPD_INFO("%s: mem size over 64K\n", __func__);
Expand Down Expand Up @@ -687,9 +687,8 @@ static int sec_block_read(struct chip_data_s6sy761 *chip_info, u32 mem_addr, int

udelay(10);
cmd[0] = (u8)SEC_CMD_FLASH_READ_DATA;
data = buf;

ret = touch_i2c_read(chip_info->client, cmd, 1, data, mem_size);
ret = touch_i2c_read(chip_info->client, cmd, 1, buf, mem_size);
if (ret < 0) {
TPD_INFO("%s: memory read failed\n", __func__);
return -EIO;
Expand All @@ -708,7 +707,7 @@ static int sec_memory_read(struct chip_data_s6sy761 *chip_info, u32 mem_addr, u8
int read_left = (int)mem_size;
u8 *tmp_data;

tmp_data = kmalloc(max_size, GFP_KERNEL);
tmp_data = kmalloc(max_size, GFP_KERNEL | GFP_DMA);
if (!tmp_data) {
TPD_INFO("%s: failed to kmalloc\n", __func__);
return -ENOMEM;
Expand Down Expand Up @@ -788,7 +787,7 @@ static int sec_chunk_update(struct chip_data_s6sy761 *chip_info, u32 addr, u32 s
int sec_read_calibration_report(struct chip_data_s6sy761 *chip_info)
{
int ret;
u8 buf[5] = { 0 };
u8 buf[5];

buf[0] = SEC_CMD_READ_CALIBRATION_REPORT;

Expand Down Expand Up @@ -943,7 +942,7 @@ static int sec_power_control(void *chip_data, bool enable)
static fw_check_state sec_fw_check(void *chip_data, struct resolution_info *resolution_info, struct panel_info *panel_data)
{
int ret = 0;
unsigned char data[5] = { 0 };
unsigned char *data = dma_buffer->fw_data;
bool valid_fw_integrity = false;
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;

Expand All @@ -963,6 +962,7 @@ static fw_check_state sec_fw_check(void *chip_data, struct resolution_info *reso
if (ret < 0) {
TPD_INFO("%s: failed to read boot status\n", __func__);
} else {
data[0] = 0;
ret = touch_i2c_read_block(chip_info->client, SEC_READ_TS_STATUS, 4, &data[1]);
if (ret < 0) {
TPD_INFO("%s: failed to read touch status\n", __func__);
Expand All @@ -973,7 +973,7 @@ static fw_check_state sec_fw_check(void *chip_data, struct resolution_info *reso
return FW_ABNORMAL;
}

memset(data, 0, 5);
data[0] = 0;
touch_i2c_read_block(chip_info->client, SEC_READ_IMG_VERSION, 4, data);
panel_data->TP_FW = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
if (panel_data->manufacture_info.version)
Expand All @@ -987,7 +987,7 @@ static fw_check_state sec_fw_check(void *chip_data, struct resolution_info *reso
static fw_update_state sec_fw_update(void *chip_data, const struct firmware *fw, bool force)
{
int i = 0, ret = 0;
u8 buf[4] = {0};
u8 *buf = dma_buffer->fw_buf;
u8 *fd = NULL;
uint8_t cal_status = 0;
sec_fw_chunk *fw_ch = NULL;
Expand All @@ -1010,7 +1010,6 @@ static fw_update_state sec_fw_update(void *chip_data, const struct firmware *fw,
buf[1] = (fw_hd->img_ver >> 8) & 0xff;
buf[0] = (fw_hd->img_ver >> 0) & 0xff;
fw_version_in_bin = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
memset(buf, 0, 4);
touch_i2c_read_block(chip_info->client, SEC_READ_IMG_VERSION, 4, buf);
fw_version_in_ic = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
TPD_INFO("img version in bin is 0x%04x, img version in ic is 0x%04x\n", fw_version_in_bin, fw_version_in_ic);
Expand All @@ -1020,7 +1019,6 @@ static fw_update_state sec_fw_update(void *chip_data, const struct firmware *fw,
buf[1] = (fw_hd->para_ver >> 8) & 0xff;
buf[0] = (fw_hd->para_ver >> 0) & 0xff;
config_version_in_bin = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
memset(buf, 0, 4);
touch_i2c_read_block(chip_info->client, SEC_READ_CONFIG_VERSION, 4, buf);
config_version_in_ic = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
TPD_INFO("config version in bin is 0x%04x, config version in ic is 0x%04x\n", config_version_in_bin, config_version_in_ic);
Expand Down Expand Up @@ -1097,7 +1095,6 @@ static u8 sec_trigger_reason(void *chip_data, int gesture_enable, int is_suspend
struct fp_underscreen_info tp_info;

pm_qos_add_request(&pm_qos_req_stp, PM_QOS_CPU_DMA_LATENCY, PM_QOS_VALUE_TP);
memset(chip_info->first_event, 0, SEC_EVENT_BUFF_SIZE);
ret = touch_i2c_read_block(chip_info->client, SEC_READ_ONE_EVENT, SEC_EVENT_BUFF_SIZE, chip_info->first_event);
if (ret < 0) {
while(ret < 0 && i2c_error_num < 4) {
Expand Down Expand Up @@ -1234,7 +1231,7 @@ static int sec_get_touch_points(void *chip_data, struct point_info *points, int
int left_event = 0;
struct sec_event_coordinate *p_event_coord = NULL;
uint32_t obj_attention = 0;
u8 event_buff[MAX_EVENT_COUNT * SEC_EVENT_BUFF_SIZE];
u8 *event_buff = dma_buffer->event_buff;
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;

p_event_coord = (struct sec_event_coordinate *)chip_info->first_event;
Expand All @@ -1261,8 +1258,7 @@ static int sec_get_touch_points(void *chip_data, struct point_info *points, int
TPD_INFO("%s: read left event beyond max touch points\n", __func__);
left_event = max_num - 1;
}
memset(event_buff, 0, sizeof(event_buff));
ret = touch_i2c_read_block(chip_info->client, SEC_READ_ALL_EVENT, sizeof(u8) * (SEC_EVENT_BUFF_SIZE) * (left_event), &event_buff[0]);
ret = touch_i2c_read_block(chip_info->client, SEC_READ_ALL_EVENT, SEC_EVENT_BUFF_SIZE * left_event, &event_buff[0]);
if (ret < 0) {
TPD_INFO("%s: i2c read all event failed\n", __func__);
pm_qos_remove_request(&pm_qos_req_stp);
Expand Down Expand Up @@ -1293,7 +1289,7 @@ static int sec_get_touch_points(void *chip_data, struct point_info *points, int
static int sec_get_gesture_info(void *chip_data, struct gesture_info * gesture)
{
int i = 0, ret = -1;
uint8_t coord[18] = {0};
uint8_t *coord = dma_buffer->coord;
struct Coordinate limitPoint[4];
struct sec_gesture_status *p_event_gesture = NULL;
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
Expand Down Expand Up @@ -1745,7 +1741,7 @@ static int sec_read_self(struct chip_data_s6sy761 *chip_info, u8 type, char *dat
static int sec_read_mutual(struct chip_data_s6sy761 *chip_info, u8 type, char *data, int len)
{
int ret = 0;
u8 buf[2] = {0};
u8 buf[2];
unsigned int data_len = (chip_info->hw_res->TX_NUM * chip_info->hw_res->RX_NUM) * 2;

if ((len > data_len) || (len % chip_info->hw_res->TX_NUM != 0)) {
Expand Down Expand Up @@ -1792,12 +1788,11 @@ static void sec_delta_read(struct seq_file *s, void *chip_data)
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
int readbytes = chip_info->hw_res->TX_NUM * (chip_info->hw_res->RX_NUM) * 2;

data = kmalloc(readbytes, GFP_KERNEL);
data = kmalloc(readbytes, GFP_KERNEL | GFP_DMA);
if (!data) {
return;
}

memset(data, 0, readbytes);
ret = sec_read_mutual(chip_info, TYPE_SIGNAL_DATA, data, readbytes);
if (ret < 0) {
seq_printf(s, "read delta failed\n");
Expand Down Expand Up @@ -1826,13 +1821,12 @@ static void sec_baseline_read(struct seq_file *s, void *chip_data)
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
int readbytes = (chip_info->hw_res->TX_NUM * chip_info->hw_res->RX_NUM) * 2;

data = kmalloc(readbytes, GFP_KERNEL);
data = kmalloc(readbytes, GFP_KERNEL | GFP_DMA);
if (!data) {
return;
}

//read decoded data
memset(data, 0, readbytes);
ret = sec_read_mutual(chip_info, TYPE_DECODED_DATA, data, readbytes);
if (ret < 0) {
seq_printf(s, "read rawdata failed\n");
Expand All @@ -1851,7 +1845,6 @@ static void sec_baseline_read(struct seq_file *s, void *chip_data)
seq_printf(s, "\n");

//read ambient data
memset(data, 0, readbytes);
ret = sec_read_mutual(chip_info, TYPE_AMBIENT_DATA, data, readbytes);
if (ret < 0) {
seq_printf(s, "read rawdata failed\n");
Expand Down Expand Up @@ -1881,12 +1874,11 @@ static void sec_self_delta_read(struct seq_file *s, void *chip_data)
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
int readbytes = (chip_info->hw_res->TX_NUM + chip_info->hw_res->RX_NUM) * 2;

data = kmalloc(readbytes, GFP_KERNEL);
data = kmalloc(readbytes, GFP_KERNEL | GFP_DMA);
if (!data) {
return;
}

memset(data, 0, readbytes);
ret = sec_read_self(chip_info, TYPE_SIGNAL_DATA, data, readbytes);
if (ret < 0) {
seq_printf(s, "read self delta failed\n");
Expand Down Expand Up @@ -1919,12 +1911,11 @@ static void sec_self_raw_read(struct seq_file *s, void *chip_data)
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
int readbytes = (chip_info->hw_res->TX_NUM + chip_info->hw_res->RX_NUM) * 2;

data = kmalloc(readbytes, GFP_KERNEL);
data = kmalloc(readbytes, GFP_KERNEL| GFP_DMA);
if (!data) {
return;
}

memset(data, 0, readbytes);
ret = sec_read_self(chip_info, TYPE_RAW_DATA, data, readbytes);
if (ret < 0) {
seq_printf(s, "read self rawdata failed\n");
Expand Down Expand Up @@ -1952,7 +1943,7 @@ static void sec_self_raw_read(struct seq_file *s, void *chip_data)

static void sec_main_register_read(struct seq_file *s, void *chip_data)
{
u8 buf[4] = {0};
u8 *buf = dma_buffer->reg_buf;
int state = -1;
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;

Expand All @@ -1965,7 +1956,7 @@ static void sec_main_register_read(struct seq_file *s, void *chip_data)
state = touch_i2c_read_byte(chip_info->client, SET_CMD_SET_CHARGER_MODE);
seq_printf(s, "charger state: 0x%02x\n", state);

memset(buf, 0, 4);
buf[0] = 0;
touch_i2c_read_block(chip_info->client, SEC_READ_ID, 3, buf);
seq_printf(s, "boot state: 0x%02x\n", buf[0]);

Expand All @@ -1978,11 +1969,9 @@ static void sec_main_register_read(struct seq_file *s, void *chip_data)
state = touch_i2c_read_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE);
seq_printf(s, "gesture mode: 0x%04x\n", state);

memset(buf, 0, 4);
touch_i2c_read_block(chip_info->client, SEC_READ_IMG_VERSION, 4, buf);
seq_printf(s, "fw img version: 0x%08x\n", (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);

memset(buf, 0, 4);
touch_i2c_read_block(chip_info->client, SEC_READ_CONFIG_VERSION, 4, buf);
seq_printf(s, "config version: 0x%08x\n", (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);

Expand All @@ -1998,7 +1987,6 @@ static void sec_main_register_read(struct seq_file *s, void *chip_data)
state = touch_i2c_read_word(chip_info->client, SEC_CMD_GRIP_SWITCH);
seq_printf(s, "grip state: 0x%04x(0x0000-off/0x2000-on)\n", state);

memset(buf, 0, 4);
touch_i2c_read_block(chip_info->client, SEC_READ_TS_STATUS, 4, buf);
seq_printf(s, "power mode: 0x%02x[normal-0x02/lpwg-0x05], 0x%02x[indle-0x00/active-0x02]\n", buf[1], buf[3]);
return;
Expand Down Expand Up @@ -2032,9 +2020,9 @@ static struct debug_info_proc_operations debug_info_proc_ops = {
static void sec_earsese_rawdata_read(void *chip_data, char *rawdata, int read_len)
{
int ret = 0;
u8 buf[2] = {0};
u8 buf[2];
int i = 0, j = 0;
int8_t tmp_byte[2] = {0};
int8_t tmp_byte[2];
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
uint8_t len_y = chip_info->hw_res->EARSENSE_RX_NUM;
uint8_t len_x = chip_info->hw_res->EARSENSE_TX_NUM;
Expand Down Expand Up @@ -2079,9 +2067,9 @@ static void sec_earsese_rawdata_read(void *chip_data, char *rawdata, int read_le
static void sec_earsese_delta_read(void *chip_data, char *earsense_delta, int read_len)
{
int ret = 0, hover_status = 0, data_type = 0;
u8 buf[2] = {0};
u8 buf[2];
int i = 0, j = 0;
int8_t tmp_byte[2] = {0};
int8_t tmp_byte[2];
struct chip_data_s6sy761 *chip_info = (struct chip_data_s6sy761 *)chip_data;
uint8_t len_x = chip_info->hw_res->EARSENSE_TX_NUM;
uint8_t len_y = chip_info->hw_res->EARSENSE_RX_NUM;
Expand Down Expand Up @@ -2196,7 +2184,7 @@ static int sec_execute_selftest(struct seq_file *s, struct chip_data_s6sy761 *ch
/* save selftest result in flash */
tpara[0] = 0x21;

rBuff = kzalloc(result_size, GFP_KERNEL);
rBuff = kzalloc(result_size, GFP_KERNEL | GFP_DMA);
if (!rBuff) {
seq_printf(s, "kzalloc space failed\n");
return -ENOMEM;
Expand Down Expand Up @@ -2398,7 +2386,7 @@ static void sec_auto_test(struct seq_file *s, void *chip_data, struct sec_testda
}
}

pRead = kzalloc(readbytes, GFP_KERNEL);
pRead = kzalloc(readbytes, GFP_KERNEL | GFP_DMA);
if (!pRead) {
TPD_INFO("kzalloc space failed\n");
seq_printf(s, "kzalloc space failed\n");
Expand Down Expand Up @@ -2586,7 +2574,6 @@ static void sec_auto_test(struct seq_file *s, void *chip_data, struct sec_testda

sec_mdelay(100);
/* read raw data */
memset(pRead, 0, readbytes); //clear buffer
ret = touch_i2c_read_block(chip_info->client, SEC_READ_TOUCH_SELF_RAWDATA, readselfbytes, pRead);
if (ret < 0) {
err_cnt++;
Expand Down Expand Up @@ -2686,7 +2673,6 @@ static void sec_auto_test(struct seq_file *s, void *chip_data, struct sec_testda

sec_mdelay(100);
/* read raw data */
memset(pRead, 0, readbytes); //clear buffer
ret = touch_i2c_read_block(chip_info->client, SEC_READ_TOUCH_RAWDATA, readbytes, pRead);
if (ret < 0) {
err_cnt++;
Expand Down Expand Up @@ -2729,7 +2715,6 @@ static void sec_auto_test(struct seq_file *s, void *chip_data, struct sec_testda

sec_mdelay(100);
/* read raw data */
memset(pRead, 0, readbytes); //clear buffer
ret = touch_i2c_read_block(chip_info->client, SEC_READ_TOUCH_RAWDATA, readbytes, pRead);
if (ret < 0) {
err_cnt++;
Expand Down Expand Up @@ -3146,7 +3131,7 @@ static int sec_ts_read_frame(struct chip_data_s6sy761 *chip_info, u8 type, short
/* set data length, allocation buffer memory */
readbytes = chip_info->hw_res->TX_NUM * chip_info->hw_res->RX_NUM * 2;

pRead = kzalloc(readbytes, GFP_KERNEL);
pRead = kzalloc(readbytes, GFP_KERNEL | GFP_DMA);
if (!pRead)
return -ENOMEM;

Expand Down Expand Up @@ -3374,21 +3359,26 @@ static int sec_tp_probe(struct i2c_client *client, const struct i2c_device_id *i
return -1;
}
/* 1. alloc chip info */
chip_info = kzalloc(sizeof(struct chip_data_s6sy761), GFP_KERNEL);
chip_info = kzalloc(sizeof(struct chip_data_s6sy761), GFP_KERNEL | GFP_DMA);
if (chip_info == NULL) {
TPD_INFO("chip info kzalloc error\n");
ret = -ENOMEM;
return ret;
}
memset(chip_info, 0, sizeof(*chip_info));

dma_buffer = kmalloc(sizeof(struct dma_buf_s6sy761), GFP_KERNEL | GFP_DMA);
if (dma_buffer == NULL) {
TPD_INFO("dma buffer kzalloc error\n");
ret = -ENOMEM;
return ret;
}

/* 2. Alloc common ts */
ts = common_touch_data_alloc();
if (ts == NULL) {
TPD_INFO("ts kzalloc error\n");
goto ts_malloc_failed;
}
memset(ts, 0, sizeof(*ts));

/* 3. bind client and dev for easy operate */
chip_info->client = client;
Expand Down
Expand Up @@ -280,4 +280,14 @@ struct chip_data_s6sy761 {
bool print_num;
};

struct dma_buf_s6sy761 {
u8 tBuff[SEC_EVENT_BUFF_SIZE];
u8 device_id[3];
unsigned char fw_data[5];
u8 fw_buf[4];
u8 event_buff[MAX_EVENT_COUNT * SEC_EVENT_BUFF_SIZE];
uint8_t coord[18];
u8 reg_buf[4];
};

#endif

0 comments on commit 1115a18

Please sign in to comment.