Skip to content

Commit

Permalink
touchscreen: 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

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
Change-Id: Ifdfc51890ce669e20de9b1ffcb487f28a9b7ef10
  • Loading branch information
arter97 authored and acuicultor committed Oct 25, 2020
1 parent 8955abf commit 27789b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
10 changes: 6 additions & 4 deletions drivers/oneplus/input/touchscreen/touchpanel_common_driver.c
Expand Up @@ -2350,7 +2350,7 @@ static ssize_t proc_register_info_read(struct file *file, char __user *user_buf,
TPD_INFO("ts->reg_info.reg_length error!\n");
return count;
}
ts->reg_info.reg_result = kzalloc(ts->reg_info.reg_length * (sizeof(uint16_t)), GFP_KERNEL);
ts->reg_info.reg_result = kzalloc(ts->reg_info.reg_length * (sizeof(uint16_t)), GFP_KERNEL | GFP_DMA);
if (!ts->reg_info.reg_result) {
TPD_INFO("ts->reg_info.reg_result kzalloc error\n");
return count;
Expand Down Expand Up @@ -3206,7 +3206,7 @@ static ssize_t proc_earsense_rawdata_read(struct file *file, char __user *user_b
return 0;
}
if (ts->delta_state == TYPE_DELTA_IDLE) {
tmp_data = kzalloc(read_len ,GFP_KERNEL);
tmp_data = kzalloc(read_len ,GFP_KERNEL | GFP_DMA);
ts->earsense_ops->rawdata_read(ts->chip_data, tmp_data, read_len);
mutex_unlock(&ts->mutex);
ret = copy_to_user(user_buf, tmp_data, read_len);
Expand Down Expand Up @@ -3292,7 +3292,7 @@ static ssize_t proc_earsense_selfdata_read(struct file *file, char __user *user_
return 0;
}
if (ts->delta_state == TYPE_DELTA_IDLE) {
tmp_data = kzalloc(data_len ,GFP_KERNEL);
tmp_data = kzalloc(data_len ,GFP_KERNEL | GFP_DMA);
ts->earsense_ops->self_data_read(ts->chip_data, tmp_data, data_len);
mutex_unlock(&ts->mutex);
ret = copy_to_user(user_buf, tmp_data, data_len);
Expand Down Expand Up @@ -5119,7 +5119,7 @@ int register_common_touch_device(struct touchpanel_data *pdata)
mutex_init(&ts->mutex_earsense); // init earsense operate mutex

//malloc space for storing earsense delta
ts->earsense_delta = kzalloc(2 * ts->hw_res.EARSENSE_TX_NUM * ts->hw_res.EARSENSE_RX_NUM, GFP_KERNEL);
ts->earsense_delta = kzalloc(2 * ts->hw_res.EARSENSE_TX_NUM * ts->hw_res.EARSENSE_RX_NUM, GFP_KERNEL | GFP_DMA);
if (ts->earsense_delta == NULL) {
ret = -ENOMEM;
TPD_INFO("earsense_delta kzalloc error\n");
Expand Down Expand Up @@ -5709,12 +5709,14 @@ void tp_i2c_resume(struct touchpanel_data *ts)
}
#endif

extern void touch_alloc_dma_buf(void);
struct touchpanel_data *common_touch_data_alloc(void)
{
if (g_tp) {
TPD_INFO("%s:common panel struct has alloc already!\n", __func__);
return NULL;
}
touch_alloc_dma_buf();
return kzalloc(sizeof(struct touchpanel_data), GFP_KERNEL);
}

Expand Down
34 changes: 21 additions & 13 deletions drivers/oneplus/input/touchscreen/util_interface/touch_interfaces.c
Expand Up @@ -16,6 +16,8 @@
#define TPD_DEVICE "touch_interface"
#define TPD_INFO(a, arg...) pr_err("[TP]"TPD_DEVICE ": " a, ##arg)

static struct touch_dma_buf *dma_buffer;

/**
* touch_i2c_continue_read - Using for "read sequence bytes" through IIC
* @client: Handle to slave device
Expand Down Expand Up @@ -63,13 +65,12 @@ int touch_i2c_read_block(struct i2c_client* client, u16 addr, unsigned short len
{
int retval;
unsigned char retry;
unsigned char buffer;
struct i2c_msg msg[2];

msg[0].addr = client->addr;
msg[0].flags = 0;
msg[0].len = 1;
msg[0].buf = &buffer;
msg[0].buf = dma_buffer->read_buf;
msg[0].buf[0] = addr & 0xff;

msg[1].addr = client->addr;
Expand Down Expand Up @@ -169,14 +170,14 @@ int touch_i2c_write_block(struct i2c_client* client, u16 addr, unsigned short le
int touch_i2c_read_byte(struct i2c_client* client, unsigned short addr)
{
int retval = 0;
unsigned char buf[2] = {0};
unsigned char *buf = dma_buffer->read_byte_buf;

if (unlikely(!client)) {
dump_stack();
return -1;
}
retval = touch_i2c_read_block(client, addr, 1, buf);
if (retval >= 0)
if (likely(retval == 1))
retval = buf[0] & 0xff;

return retval;
Expand All @@ -195,15 +196,14 @@ int touch_i2c_read_byte(struct i2c_client* client, unsigned short addr)
int touch_i2c_write_byte(struct i2c_client* client, unsigned short addr, unsigned char data)
{
int retval;
int length_trans = 1;
unsigned char data_send = data;

if (unlikely(!client)) {
dump_stack();
return -EINVAL;
}
retval = touch_i2c_write_block(client, addr, length_trans, &data_send);
if (retval == length_trans)
retval = touch_i2c_write_block(client, addr, 1, &data_send);
if (likely(retval == 1))
retval = 0;

return retval;
Expand All @@ -221,14 +221,14 @@ int touch_i2c_write_byte(struct i2c_client* client, unsigned short addr, unsigne
int touch_i2c_read_word(struct i2c_client* client, unsigned short addr)
{
int retval;
unsigned char buf[2] = {0};
unsigned char *buf = dma_buffer->read_word_buf;

if (unlikely(!client)) {
dump_stack();
return -EINVAL;
}
retval = touch_i2c_read_block(client, addr, 2, buf);
if (retval >= 0)
if (likely(retval >= 0))
retval = buf[1] << 8 | buf[0];

return retval;
Expand All @@ -246,16 +246,18 @@ int touch_i2c_read_word(struct i2c_client* client, unsigned short addr)
int touch_i2c_write_word(struct i2c_client* client, unsigned short addr, unsigned short data)
{
int retval;
int length_trans = 2;
unsigned char buf[2] = {data & 0xff, (data >> 8) & 0xff};
unsigned char buf[2];

if (unlikely(!client)) {
dump_stack();
return -EINVAL;
}

retval = touch_i2c_write_block(client, addr, length_trans, buf);
if (retval == length_trans)
buf[0] = data & 0xff;
buf[1] = (data >> 8) & 0xff;

retval = touch_i2c_write_block(client, addr, 2, buf);
if (likely(retval == 2))
retval = 0;

return retval;
Expand Down Expand Up @@ -466,3 +468,9 @@ int32_t CTP_SPI_WRITE(struct spi_device *client, uint8_t *buf, uint16_t len)
return ret;
}

void touch_alloc_dma_buf(void)
{
// DMA shouldn't be made with stack memory
dma_buffer = kmalloc(sizeof(struct touch_dma_buf), GFP_KERNEL | GFP_DMA);
}

Expand Up @@ -25,6 +25,12 @@ typedef enum {
SPIREAD = 2
} SPI_RW;

struct touch_dma_buf {
unsigned char read_buf[1];
unsigned char read_byte_buf[2];
unsigned char read_word_buf[2];
};

int touch_i2c_read_byte(struct i2c_client* client, u16 addr);
int touch_i2c_write_byte(struct i2c_client* client, u16 addr, unsigned char data);

Expand Down

0 comments on commit 27789b4

Please sign in to comment.