ad7879.c (f26e8817b235d8764363bffcc9cbfc61867371f2) ad7879.c (404a24c35db8c44dce91010023f12b73f2f44441)
1/*
2 * AD7879/AD7889 based touchscreen and GPIO driver
3 *
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 *
8 * History:

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

21 * Copyright (C) 2006-2008 Analog Devices Inc.
22 */
23
24#include <linux/device.h>
25#include <linux/delay.h>
26#include <linux/input.h>
27#include <linux/interrupt.h>
28#include <linux/irq.h>
1/*
2 * AD7879/AD7889 based touchscreen and GPIO driver
3 *
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 *
8 * History:

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

21 * Copyright (C) 2006-2008 Analog Devices Inc.
22 */
23
24#include <linux/device.h>
25#include <linux/delay.h>
26#include <linux/input.h>
27#include <linux/interrupt.h>
28#include <linux/irq.h>
29#include <linux/regmap.h>
29#include <linux/slab.h>
30#include <linux/slab.h>
30#include <linux/spi/spi.h>
31#include <linux/i2c.h>
32#include <linux/gpio.h>
33
34#include <linux/input/touchscreen.h>
35#include <linux/platform_data/ad7879.h>
36#include <linux/module.h>
37#include "ad7879.h"
38
39#define AD7879_REG_ZEROS 0

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

101 AD7879_SEQ_Z2 = 3,
102 AD7879_NR_SENSE = 4,
103};
104
105#define MAX_12BIT ((1<<12)-1)
106#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50)
107
108struct ad7879 {
31#include <linux/gpio.h>
32
33#include <linux/input/touchscreen.h>
34#include <linux/platform_data/ad7879.h>
35#include <linux/module.h>
36#include "ad7879.h"
37
38#define AD7879_REG_ZEROS 0

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

100 AD7879_SEQ_Z2 = 3,
101 AD7879_NR_SENSE = 4,
102};
103
104#define MAX_12BIT ((1<<12)-1)
105#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50)
106
107struct ad7879 {
109 const struct ad7879_bus_ops *bops;
110
108 struct regmap *regmap;
111 struct device *dev;
112 struct input_dev *input;
113 struct timer_list timer;
114#ifdef CONFIG_GPIOLIB
115 struct gpio_chip gc;
116 struct mutex mutex;
117#endif
118 unsigned int irq;

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

132 u16 cmd_crtl3;
133 int x;
134 int y;
135 int Rt;
136};
137
138static int ad7879_read(struct ad7879 *ts, u8 reg)
139{
109 struct device *dev;
110 struct input_dev *input;
111 struct timer_list timer;
112#ifdef CONFIG_GPIOLIB
113 struct gpio_chip gc;
114 struct mutex mutex;
115#endif
116 unsigned int irq;

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

130 u16 cmd_crtl3;
131 int x;
132 int y;
133 int Rt;
134};
135
136static int ad7879_read(struct ad7879 *ts, u8 reg)
137{
140 return ts->bops->read(ts->dev, reg);
141}
138 unsigned int val;
139 int error;
142
140
143static int ad7879_multi_read(struct ad7879 *ts, u8 first_reg, u8 count, u16 *buf)
144{
145 return ts->bops->multi_read(ts->dev, first_reg, count, buf);
141 error = regmap_read(ts->regmap, reg, &val);
142 if (error) {
143 dev_err(ts->dev, "failed to read register %#02x: %d\n",
144 reg, error);
145 return error;
146 }
147
148 return val;
146}
147
148static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val)
149{
149}
150
151static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val)
152{
150 return ts->bops->write(ts->dev, reg, val);
153 int error;
154
155 error = regmap_write(ts->regmap, reg, val);
156 if (error) {
157 dev_err(ts->dev,
158 "failed to write %#04x to register %#02x: %d\n",
159 val, reg, error);
160 return error;
161 }
162
163 return 0;
151}
152
153static int ad7879_report(struct ad7879 *ts)
154{
155 struct input_dev *input_dev = ts->input;
156 unsigned Rt;
157 u16 x, y, z1, z2;
158

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

229
230 ad7879_ts_event_release(ts);
231}
232
233static irqreturn_t ad7879_irq(int irq, void *handle)
234{
235 struct ad7879 *ts = handle;
236
164}
165
166static int ad7879_report(struct ad7879 *ts)
167{
168 struct input_dev *input_dev = ts->input;
169 unsigned Rt;
170 u16 x, y, z1, z2;
171

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

242
243 ad7879_ts_event_release(ts);
244}
245
246static irqreturn_t ad7879_irq(int irq, void *handle)
247{
248 struct ad7879 *ts = handle;
249
237 ad7879_multi_read(ts, AD7879_REG_XPLUS, AD7879_NR_SENSE, ts->conversion_data);
250 regmap_bulk_read(ts->regmap, AD7879_REG_XPLUS,
251 ts->conversion_data, AD7879_NR_SENSE);
238
239 if (!ad7879_report(ts))
240 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
241
242 return IRQ_HANDLED;
243}
244
245static void __ad7879_enable(struct ad7879 *ts)

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

506 device_property_read_u8(dev, "adi,conversion-interval",
507 &ts->pen_down_acc_interval);
508
509 ts->swap_xy = device_property_read_bool(dev, "touchscreen-swapped-x-y");
510
511 return 0;
512}
513
252
253 if (!ad7879_report(ts))
254 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
255
256 return IRQ_HANDLED;
257}
258
259static void __ad7879_enable(struct ad7879 *ts)

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

520 device_property_read_u8(dev, "adi,conversion-interval",
521 &ts->pen_down_acc_interval);
522
523 ts->swap_xy = device_property_read_bool(dev, "touchscreen-swapped-x-y");
524
525 return 0;
526}
527
514struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq,
515 const struct ad7879_bus_ops *bops)
528struct ad7879 *ad7879_probe(struct device *dev, struct regmap *regmap,
529 int irq, u16 bustype, u8 devid)
516{
517 struct ad7879_platform_data *pdata = dev_get_platdata(dev);
518 struct ad7879 *ts;
519 struct input_dev *input_dev;
520 int err;
521 u16 revid;
522
530{
531 struct ad7879_platform_data *pdata = dev_get_platdata(dev);
532 struct ad7879 *ts;
533 struct input_dev *input_dev;
534 int err;
535 u16 revid;
536
523 if (!irq) {
537 if (irq <= 0) {
524 dev_err(dev, "No IRQ specified\n");
525 return ERR_PTR(-EINVAL);
526 }
527
528 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
529 if (!ts)
530 return ERR_PTR(-ENOMEM);
531

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

548 }
549
550 input_dev = devm_input_allocate_device(dev);
551 if (!input_dev) {
552 dev_err(dev, "Failed to allocate input device\n");
553 return ERR_PTR(-ENOMEM);
554 }
555
538 dev_err(dev, "No IRQ specified\n");
539 return ERR_PTR(-EINVAL);
540 }
541
542 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
543 if (!ts)
544 return ERR_PTR(-ENOMEM);
545

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

562 }
563
564 input_dev = devm_input_allocate_device(dev);
565 if (!input_dev) {
566 dev_err(dev, "Failed to allocate input device\n");
567 return ERR_PTR(-ENOMEM);
568 }
569
556 ts->bops = bops;
557 ts->dev = dev;
558 ts->input = input_dev;
559 ts->irq = irq;
570 ts->dev = dev;
571 ts->input = input_dev;
572 ts->irq = irq;
573 ts->regmap = regmap;
560
561 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts);
562 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev));
563
564 input_dev->name = "AD7879 Touchscreen";
565 input_dev->phys = ts->phys;
566 input_dev->dev.parent = dev;
574
575 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts);
576 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev));
577
578 input_dev->name = "AD7879 Touchscreen";
579 input_dev->phys = ts->phys;
580 input_dev->dev.parent = dev;
567 input_dev->id.bustype = bops->bustype;
581 input_dev->id.bustype = bustype;
568
569 input_dev->open = ad7879_open;
570 input_dev->close = ad7879_close;
571
572 input_set_drvdata(input_dev, ts);
573
574 __set_bit(EV_ABS, input_dev->evbit);
575 __set_bit(ABS_X, input_dev->absbit);

--- 106 unchanged lines hidden ---
582
583 input_dev->open = ad7879_open;
584 input_dev->close = ad7879_close;
585
586 input_set_drvdata(input_dev, ts);
587
588 __set_bit(EV_ABS, input_dev->evbit);
589 __set_bit(ABS_X, input_dev->absbit);

--- 106 unchanged lines hidden ---