@@ -812,6 +812,44 @@ static void mxt_free_object_table(struct mxt_data *data)
data->T19_reportid = 0;
}
+static int mxt_calc_resolution(struct mxt_data *data)
+{
+ struct i2c_client *client = data->client;
+ struct mxt_object *T9;
+ u8 orient;
+ __le16 xyrange[2];
+ unsigned int max_x, max_y;
+ int ret;
+
+ T9 = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
+ if (T9 == NULL)
+ return -EINVAL;
+
+ /* Get touchscreen resolution */
+ ret = __mxt_read_reg(client, T9->start_address + MXT_TOUCH_XRANGE_LSB,
+ 4, xyrange);
+ if (ret)
+ return ret;
+
+ ret = __mxt_read_reg(client, T9->start_address + MXT_TOUCH_ORIENT,
+ 1, &orient);
+ if (ret)
+ return ret;
+
+ max_x = le16_to_cpu(xyrange[0]);
+ max_y = le16_to_cpu(xyrange[1]);
+
+ if (orient & MXT_XY_SWITCH) {
+ data->max_x = max_y;
+ data->max_y = max_x;
+ } else {
+ data->max_x = max_x;
+ data->max_y = max_y;
+ }
+
+ return 0;
+}
+
static int mxt_initialize(struct mxt_data *data)
{
struct i2c_client *client = data->client;
@@ -844,14 +882,17 @@ static int mxt_initialize(struct mxt_data *data)
mxt_handle_pdata(data);
/* Backup to memory */
- mxt_write_object(data, MXT_GEN_COMMAND_T6,
- MXT_COMMAND_BACKUPNV,
- MXT_BACKUP_VALUE);
+ error = mxt_write_object(data, MXT_GEN_COMMAND_T6,
+ MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE);
+ if (error)
+ return error;
msleep(MXT_BACKUP_TIME);
/* Soft reset */
- mxt_write_object(data, MXT_GEN_COMMAND_T6,
- MXT_COMMAND_RESET, 1);
+ error = mxt_write_object(data, MXT_GEN_COMMAND_T6,
+ MXT_COMMAND_RESET, 1);
+ if (error)
+ return error;
msleep(MXT_RESET_TIME);
/* Update matrix size at info struct */
@@ -875,6 +916,10 @@ static int mxt_initialize(struct mxt_data *data)
info->matrix_xsize, info->matrix_ysize,
info->object_num);
+ error = mxt_calc_resolution(data);
+ if (error)
+ return error;
+
return 0;
err_free_object_table:
@@ -882,20 +927,6 @@ err_free_object_table:
return error;
}
-static void mxt_calc_resolution(struct mxt_data *data)
-{
- unsigned int max_x = data->pdata->x_size - 1;
- unsigned int max_y = data->pdata->y_size - 1;
-
- if (data->pdata->orient & MXT_XY_SWITCH) {
- data->max_x = max_y;
- data->max_y = max_x;
- } else {
- data->max_x = max_x;
- data->max_y = max_y;
- }
-}
-
/* Firmware Version is returned as Major.Minor.Build */
static ssize_t mxt_fw_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -1166,8 +1197,6 @@ static int mxt_probe(struct i2c_client *client,
data->pdata = pdata;
data->irq = client->irq;
- mxt_calc_resolution(data);
-
error = mxt_initialize(data);
if (error)
goto err_free_mem;