Loading...
1/*
2 * AD714X CapTouch Programmable Controller driver (I2C bus)
3 *
4 * Copyright 2009-2011 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/input.h> /* BUS_I2C */
10#include <linux/i2c.h>
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/pm.h>
14#include "ad714x.h"
15
16#ifdef CONFIG_PM_SLEEP
17static int ad714x_i2c_suspend(struct device *dev)
18{
19 return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev)));
20}
21
22static int ad714x_i2c_resume(struct device *dev)
23{
24 return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev)));
25}
26#endif
27
28static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
29
30static int ad714x_i2c_write(struct ad714x_chip *chip,
31 unsigned short reg, unsigned short data)
32{
33 struct i2c_client *client = to_i2c_client(chip->dev);
34 int error;
35
36 chip->xfer_buf[0] = cpu_to_be16(reg);
37 chip->xfer_buf[1] = cpu_to_be16(data);
38
39 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
40 2 * sizeof(*chip->xfer_buf));
41 if (unlikely(error < 0)) {
42 dev_err(&client->dev, "I2C write error: %d\n", error);
43 return error;
44 }
45
46 return 0;
47}
48
49static int ad714x_i2c_read(struct ad714x_chip *chip,
50 unsigned short reg, unsigned short *data, size_t len)
51{
52 struct i2c_client *client = to_i2c_client(chip->dev);
53 int i;
54 int error;
55
56 chip->xfer_buf[0] = cpu_to_be16(reg);
57
58 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
59 sizeof(*chip->xfer_buf));
60 if (error >= 0)
61 error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
62 len * sizeof(*chip->xfer_buf));
63
64 if (unlikely(error < 0)) {
65 dev_err(&client->dev, "I2C read error: %d\n", error);
66 return error;
67 }
68
69 for (i = 0; i < len; i++)
70 data[i] = be16_to_cpu(chip->xfer_buf[i]);
71
72 return 0;
73}
74
75static int ad714x_i2c_probe(struct i2c_client *client,
76 const struct i2c_device_id *id)
77{
78 struct ad714x_chip *chip;
79
80 chip = ad714x_probe(&client->dev, BUS_I2C, client->irq,
81 ad714x_i2c_read, ad714x_i2c_write);
82 if (IS_ERR(chip))
83 return PTR_ERR(chip);
84
85 i2c_set_clientdata(client, chip);
86
87 return 0;
88}
89
90static int ad714x_i2c_remove(struct i2c_client *client)
91{
92 struct ad714x_chip *chip = i2c_get_clientdata(client);
93
94 ad714x_remove(chip);
95
96 return 0;
97}
98
99static const struct i2c_device_id ad714x_id[] = {
100 { "ad7142_captouch", 0 },
101 { "ad7143_captouch", 0 },
102 { "ad7147_captouch", 0 },
103 { "ad7147a_captouch", 0 },
104 { "ad7148_captouch", 0 },
105 { }
106};
107MODULE_DEVICE_TABLE(i2c, ad714x_id);
108
109static struct i2c_driver ad714x_i2c_driver = {
110 .driver = {
111 .name = "ad714x_captouch",
112 .pm = &ad714x_i2c_pm,
113 },
114 .probe = ad714x_i2c_probe,
115 .remove = ad714x_i2c_remove,
116 .id_table = ad714x_id,
117};
118
119module_i2c_driver(ad714x_i2c_driver);
120
121MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor I2C Bus Driver");
122MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
123MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * AD714X CapTouch Programmable Controller driver (I2C bus)
4 *
5 * Copyright 2009-2011 Analog Devices Inc.
6 */
7
8#include <linux/input.h> /* BUS_I2C */
9#include <linux/i2c.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/pm.h>
13#include "ad714x.h"
14
15static int __maybe_unused ad714x_i2c_suspend(struct device *dev)
16{
17 return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev)));
18}
19
20static int __maybe_unused ad714x_i2c_resume(struct device *dev)
21{
22 return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev)));
23}
24
25static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
26
27static int ad714x_i2c_write(struct ad714x_chip *chip,
28 unsigned short reg, unsigned short data)
29{
30 struct i2c_client *client = to_i2c_client(chip->dev);
31 int error;
32
33 chip->xfer_buf[0] = cpu_to_be16(reg);
34 chip->xfer_buf[1] = cpu_to_be16(data);
35
36 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
37 2 * sizeof(*chip->xfer_buf));
38 if (unlikely(error < 0)) {
39 dev_err(&client->dev, "I2C write error: %d\n", error);
40 return error;
41 }
42
43 return 0;
44}
45
46static int ad714x_i2c_read(struct ad714x_chip *chip,
47 unsigned short reg, unsigned short *data, size_t len)
48{
49 struct i2c_client *client = to_i2c_client(chip->dev);
50 int i;
51 int error;
52
53 chip->xfer_buf[0] = cpu_to_be16(reg);
54
55 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
56 sizeof(*chip->xfer_buf));
57 if (error >= 0)
58 error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
59 len * sizeof(*chip->xfer_buf));
60
61 if (unlikely(error < 0)) {
62 dev_err(&client->dev, "I2C read error: %d\n", error);
63 return error;
64 }
65
66 for (i = 0; i < len; i++)
67 data[i] = be16_to_cpu(chip->xfer_buf[i]);
68
69 return 0;
70}
71
72static int ad714x_i2c_probe(struct i2c_client *client,
73 const struct i2c_device_id *id)
74{
75 struct ad714x_chip *chip;
76
77 chip = ad714x_probe(&client->dev, BUS_I2C, client->irq,
78 ad714x_i2c_read, ad714x_i2c_write);
79 if (IS_ERR(chip))
80 return PTR_ERR(chip);
81
82 i2c_set_clientdata(client, chip);
83
84 return 0;
85}
86
87static const struct i2c_device_id ad714x_id[] = {
88 { "ad7142_captouch", 0 },
89 { "ad7143_captouch", 0 },
90 { "ad7147_captouch", 0 },
91 { "ad7147a_captouch", 0 },
92 { "ad7148_captouch", 0 },
93 { }
94};
95MODULE_DEVICE_TABLE(i2c, ad714x_id);
96
97static struct i2c_driver ad714x_i2c_driver = {
98 .driver = {
99 .name = "ad714x_captouch",
100 .pm = &ad714x_i2c_pm,
101 },
102 .probe = ad714x_i2c_probe,
103 .id_table = ad714x_id,
104};
105
106module_i2c_driver(ad714x_i2c_driver);
107
108MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor I2C Bus Driver");
109MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
110MODULE_LICENSE("GPL");