sx8654.c (4d6ca227c768b50b05cf183974b40abe444e9d0c) sx8654.c (c3a39380a39df3750149a2f4699c1c241a0e6ea2)
1/*
2 * Driver for Semtech SX8654 I2C touchscreen controller.
3 *
4 * Copyright (c) 2015 Armadeus Systems
5 * Sébastien Szymanski <sebastien.szymanski@armadeus.com>
6 *
7 * Using code from:
8 * - sx865x.c

--- 13 unchanged lines hidden (view full) ---

22 * Copyright (C) 2004 Texas Instruments
23 * Copyright (C) 2005 Dirk Behme
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License version 2 as
27 * published by the Free Software Foundation.
28 */
29
1/*
2 * Driver for Semtech SX8654 I2C touchscreen controller.
3 *
4 * Copyright (c) 2015 Armadeus Systems
5 * Sébastien Szymanski <sebastien.szymanski@armadeus.com>
6 *
7 * Using code from:
8 * - sx865x.c

--- 13 unchanged lines hidden (view full) ---

22 * Copyright (C) 2004 Texas Instruments
23 * Copyright (C) 2005 Dirk Behme
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License version 2 as
27 * published by the Free Software Foundation.
28 */
29
30#include <linux/input.h>
31#include <linux/module.h>
32#include <linux/of.h>
30#include <linux/delay.h>
31#include <linux/gpio/consumer.h>
33#include <linux/i2c.h>
32#include <linux/i2c.h>
33#include <linux/input.h>
34#include <linux/interrupt.h>
35#include <linux/irq.h>
34#include <linux/interrupt.h>
35#include <linux/irq.h>
36#include <linux/module.h>
37#include <linux/of.h>
36
37/* register addresses */
38#define I2C_REG_TOUCH0 0x00
39#define I2C_REG_TOUCH1 0x01
40#define I2C_REG_CHANMASK 0x04
41#define I2C_REG_IRQMASK 0x22
42#define I2C_REG_IRQSRC 0x23
43#define I2C_REG_SOFTRESET 0x3f

--- 25 unchanged lines hidden (view full) ---

69/* power delay: lower nibble of CTRL0 register */
70#define POWDLY_1_1MS 0x0b
71
72#define MAX_12BIT ((1 << 12) - 1)
73
74struct sx8654 {
75 struct input_dev *input;
76 struct i2c_client *client;
38
39/* register addresses */
40#define I2C_REG_TOUCH0 0x00
41#define I2C_REG_TOUCH1 0x01
42#define I2C_REG_CHANMASK 0x04
43#define I2C_REG_IRQMASK 0x22
44#define I2C_REG_IRQSRC 0x23
45#define I2C_REG_SOFTRESET 0x3f

--- 25 unchanged lines hidden (view full) ---

71/* power delay: lower nibble of CTRL0 register */
72#define POWDLY_1_1MS 0x0b
73
74#define MAX_12BIT ((1 << 12) - 1)
75
76struct sx8654 {
77 struct input_dev *input;
78 struct i2c_client *client;
79 struct gpio_desc *gpio_reset;
77};
78
79static irqreturn_t sx8654_irq(int irq, void *handle)
80{
81 struct sx8654 *sx8654 = handle;
82 int irqsrc;
83 u8 data[4];
84 unsigned int x, y;

--- 34 unchanged lines hidden (view full) ---

119
120 dev_dbg(&sx8654->client->dev, "point(%4d,%4d)\n", x, y);
121 }
122
123out:
124 return IRQ_HANDLED;
125}
126
80};
81
82static irqreturn_t sx8654_irq(int irq, void *handle)
83{
84 struct sx8654 *sx8654 = handle;
85 int irqsrc;
86 u8 data[4];
87 unsigned int x, y;

--- 34 unchanged lines hidden (view full) ---

122
123 dev_dbg(&sx8654->client->dev, "point(%4d,%4d)\n", x, y);
124 }
125
126out:
127 return IRQ_HANDLED;
128}
129
130static int sx8654_reset(struct sx8654 *ts)
131{
132 int err;
133
134 if (ts->gpio_reset) {
135 gpiod_set_value_cansleep(ts->gpio_reset, 1);
136 udelay(2); /* Tpulse > 1µs */
137 gpiod_set_value_cansleep(ts->gpio_reset, 0);
138 } else {
139 dev_dbg(&ts->client->dev, "NRST unavailable, try softreset\n");
140 err = i2c_smbus_write_byte_data(ts->client, I2C_REG_SOFTRESET,
141 SOFTRESET_VALUE);
142 if (err)
143 return err;
144 }
145
146 return 0;
147}
148
127static int sx8654_open(struct input_dev *dev)
128{
129 struct sx8654 *sx8654 = input_get_drvdata(dev);
130 struct i2c_client *client = sx8654->client;
131 int error;
132
133 /* enable pen trigger mode */
134 error = i2c_smbus_write_byte_data(client, I2C_REG_TOUCH0,

--- 46 unchanged lines hidden (view full) ---

181 if (!i2c_check_functionality(client->adapter,
182 I2C_FUNC_SMBUS_READ_WORD_DATA))
183 return -ENXIO;
184
185 sx8654 = devm_kzalloc(&client->dev, sizeof(*sx8654), GFP_KERNEL);
186 if (!sx8654)
187 return -ENOMEM;
188
149static int sx8654_open(struct input_dev *dev)
150{
151 struct sx8654 *sx8654 = input_get_drvdata(dev);
152 struct i2c_client *client = sx8654->client;
153 int error;
154
155 /* enable pen trigger mode */
156 error = i2c_smbus_write_byte_data(client, I2C_REG_TOUCH0,

--- 46 unchanged lines hidden (view full) ---

203 if (!i2c_check_functionality(client->adapter,
204 I2C_FUNC_SMBUS_READ_WORD_DATA))
205 return -ENXIO;
206
207 sx8654 = devm_kzalloc(&client->dev, sizeof(*sx8654), GFP_KERNEL);
208 if (!sx8654)
209 return -ENOMEM;
210
211 sx8654->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset",
212 GPIOD_OUT_HIGH);
213 if (IS_ERR(sx8654->gpio_reset)) {
214 error = PTR_ERR(sx8654->gpio_reset);
215 if (error != -EPROBE_DEFER)
216 dev_err(&client->dev, "unable to get reset-gpio: %d\n",
217 error);
218 return error;
219 }
220 dev_dbg(&client->dev, "got GPIO reset pin\n");
221
189 input = devm_input_allocate_device(&client->dev);
190 if (!input)
191 return -ENOMEM;
192
193 input->name = "SX8654 I2C Touchscreen";
194 input->id.bustype = BUS_I2C;
195 input->dev.parent = &client->dev;
196 input->open = sx8654_open;

--- 4 unchanged lines hidden (view full) ---

201 input_set_abs_params(input, ABS_X, 0, MAX_12BIT, 0, 0);
202 input_set_abs_params(input, ABS_Y, 0, MAX_12BIT, 0, 0);
203
204 sx8654->client = client;
205 sx8654->input = input;
206
207 input_set_drvdata(sx8654->input, sx8654);
208
222 input = devm_input_allocate_device(&client->dev);
223 if (!input)
224 return -ENOMEM;
225
226 input->name = "SX8654 I2C Touchscreen";
227 input->id.bustype = BUS_I2C;
228 input->dev.parent = &client->dev;
229 input->open = sx8654_open;

--- 4 unchanged lines hidden (view full) ---

234 input_set_abs_params(input, ABS_X, 0, MAX_12BIT, 0, 0);
235 input_set_abs_params(input, ABS_Y, 0, MAX_12BIT, 0, 0);
236
237 sx8654->client = client;
238 sx8654->input = input;
239
240 input_set_drvdata(sx8654->input, sx8654);
241
209 error = i2c_smbus_write_byte_data(client, I2C_REG_SOFTRESET,
210 SOFTRESET_VALUE);
242 error = sx8654_reset(sx8654);
211 if (error) {
243 if (error) {
212 dev_err(&client->dev, "writing softreset value failed");
244 dev_err(&client->dev, "reset failed");
213 return error;
214 }
215
216 error = i2c_smbus_write_byte_data(client, I2C_REG_CHANMASK,
217 CONV_X | CONV_Y);
218 if (error) {
219 dev_err(&client->dev, "writing to I2C_REG_CHANMASK failed");
220 return error;

--- 65 unchanged lines hidden ---
245 return error;
246 }
247
248 error = i2c_smbus_write_byte_data(client, I2C_REG_CHANMASK,
249 CONV_X | CONV_Y);
250 if (error) {
251 dev_err(&client->dev, "writing to I2C_REG_CHANMASK failed");
252 return error;

--- 65 unchanged lines hidden ---