1717
1818#define AR1021_MAX_X 4095
1919#define AR1021_MAX_Y 4095
20+ #define AR1021_MAX_PRESSURE 255
2021
2122#define AR1021_CMD 0x55
2223
@@ -26,8 +27,29 @@ struct ar1021_i2c {
2627 struct i2c_client * client ;
2728 struct input_dev * input ;
2829 u8 data [AR1021_TOCUH_PKG_SIZE ];
30+ bool invert_x ;
31+ bool invert_y ;
32+ bool swap_xy ;
2933};
3034
35+ static bool ar1021_get_prop_u32 (struct device * dev ,
36+ const char * property ,
37+ unsigned int default_value ,
38+ unsigned int * value )
39+ {
40+ u32 val ;
41+ int error ;
42+
43+ error = device_property_read_u32 (dev , property , & val );
44+ if (error ) {
45+ * value = default_value ;
46+ return false;
47+ }
48+
49+ * value = val ;
50+ return true;
51+ }
52+
3153static irqreturn_t ar1021_i2c_irq (int irq , void * dev_id )
3254{
3355 struct ar1021_i2c * ar1021 = dev_id ;
@@ -49,9 +71,22 @@ static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
4971 x = ((data [2 ] & 0x1f ) << 7 ) | (data [1 ] & 0x7f );
5072 y = ((data [4 ] & 0x1f ) << 7 ) | (data [3 ] & 0x7f );
5173
52- input_report_abs (input , ABS_X , x );
53- input_report_abs (input , ABS_Y , y );
74+ if (ar1021 -> invert_x )
75+ x = AR1021_MAX_X - x ;
76+
77+ if (ar1021 -> invert_y )
78+ y = AR1021_MAX_Y - y ;
79+
80+ if (ar1021 -> swap_xy ) {
81+ input_report_abs (input , ABS_X , y );
82+ input_report_abs (input , ABS_Y , x );
83+ } else {
84+ input_report_abs (input , ABS_X , x );
85+ input_report_abs (input , ABS_Y , y );
86+ }
87+
5488 input_report_key (input , BTN_TOUCH , button );
89+ input_report_abs (input , ABS_PRESSURE , AR1021_MAX_PRESSURE );
5590 input_sync (input );
5691
5792out :
@@ -93,6 +128,8 @@ static int ar1021_i2c_probe(struct i2c_client *client,
93128 struct ar1021_i2c * ar1021 ;
94129 struct input_dev * input ;
95130 int error ;
131+ unsigned int offset_x , offset_y ;
132+ bool data_present ;
96133
97134 if (!i2c_check_functionality (client -> adapter , I2C_FUNC_I2C )) {
98135 dev_err (& client -> dev , "i2c_check_functionality error\n" );
@@ -116,10 +153,44 @@ static int ar1021_i2c_probe(struct i2c_client *client,
116153 input -> open = ar1021_i2c_open ;
117154 input -> close = ar1021_i2c_close ;
118155
156+ ar1021 -> invert_x = device_property_read_bool (& client -> dev , "touchscreen-inverted-x" );
157+ ar1021 -> invert_y = device_property_read_bool (& client -> dev , "touchscreen-inverted-y" );
158+ ar1021 -> swap_xy = device_property_read_bool (& client -> dev , "touchscreen-swapped-x-y" );
159+
160+ data_present = ar1021_get_prop_u32 (& client -> dev ,
161+ "touchscreen-offset-x" ,
162+ 0 ,
163+ & offset_x );
164+
165+ if (data_present )
166+ dev_info (& client -> dev , "touchscreen-offset-x: %d\n" , offset_x );
167+
168+ data_present = ar1021_get_prop_u32 (& client -> dev ,
169+ "touchscreen-offset-y" ,
170+ 0 ,
171+ & offset_y );
172+
173+ if (data_present )
174+ dev_info (& client -> dev , "touchscreen-offset-y: %d\n" , offset_y );
175+
119176 __set_bit (INPUT_PROP_DIRECT , input -> propbit );
120- input_set_capability (input , EV_KEY , BTN_TOUCH );
121- input_set_abs_params (input , ABS_X , 0 , AR1021_MAX_X , 0 , 0 );
122- input_set_abs_params (input , ABS_Y , 0 , AR1021_MAX_Y , 0 , 0 );
177+ //input_set_capability(input, EV_KEY, BTN_TOUCH);
178+
179+ input -> evbit [0 ] = BIT_MASK (EV_KEY ) | BIT_MASK (EV_ABS );
180+ input -> keybit [BIT_WORD (BTN_TOUCH )] = BIT_MASK (BTN_TOUCH );
181+
182+ if (ar1021 -> swap_xy )
183+ {
184+ input_set_abs_params (input , ABS_X , 0 , AR1021_MAX_Y , 0 , 0 );
185+ input_set_abs_params (input , ABS_Y , 0 , AR1021_MAX_X , 0 , 0 );
186+ }
187+ else
188+ {
189+ input_set_abs_params (input , ABS_X , offset_x , AR1021_MAX_X - offset_x , 0 , 0 );
190+ input_set_abs_params (input , ABS_Y , offset_y , AR1021_MAX_Y - offset_y , 0 , 0 );
191+ }
192+
193+ input_set_abs_params (input , ABS_PRESSURE , 0 , AR1021_MAX_PRESSURE , 0 , 0 );
123194
124195 input_set_drvdata (input , ar1021 );
125196
0 commit comments