Loading...
1/*
2 * Driver for the Analog Devices digital potentiometers (I2C bus)
3 *
4 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/i2c.h>
10#include <linux/module.h>
11
12#include "ad525x_dpot.h"
13
14/* ------------------------------------------------------------------------- */
15/* I2C bus functions */
16static int write_d8(void *client, u8 val)
17{
18 return i2c_smbus_write_byte(client, val);
19}
20
21static int write_r8d8(void *client, u8 reg, u8 val)
22{
23 return i2c_smbus_write_byte_data(client, reg, val);
24}
25
26static int write_r8d16(void *client, u8 reg, u16 val)
27{
28 return i2c_smbus_write_word_data(client, reg, val);
29}
30
31static int read_d8(void *client)
32{
33 return i2c_smbus_read_byte(client);
34}
35
36static int read_r8d8(void *client, u8 reg)
37{
38 return i2c_smbus_read_byte_data(client, reg);
39}
40
41static int read_r8d16(void *client, u8 reg)
42{
43 return i2c_smbus_read_word_data(client, reg);
44}
45
46static const struct ad_dpot_bus_ops bops = {
47 .read_d8 = read_d8,
48 .read_r8d8 = read_r8d8,
49 .read_r8d16 = read_r8d16,
50 .write_d8 = write_d8,
51 .write_r8d8 = write_r8d8,
52 .write_r8d16 = write_r8d16,
53};
54
55static int __devinit ad_dpot_i2c_probe(struct i2c_client *client,
56 const struct i2c_device_id *id)
57{
58 struct ad_dpot_bus_data bdata = {
59 .client = client,
60 .bops = &bops,
61 };
62
63 struct ad_dpot_id dpot_id = {
64 .name = (char *) &id->name,
65 .devid = id->driver_data,
66 };
67
68 if (!i2c_check_functionality(client->adapter,
69 I2C_FUNC_SMBUS_WORD_DATA)) {
70 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
71 return -EIO;
72 }
73
74 return ad_dpot_probe(&client->dev, &bdata, &dpot_id);
75}
76
77static int __devexit ad_dpot_i2c_remove(struct i2c_client *client)
78{
79 return ad_dpot_remove(&client->dev);
80}
81
82static const struct i2c_device_id ad_dpot_id[] = {
83 {"ad5258", AD5258_ID},
84 {"ad5259", AD5259_ID},
85 {"ad5251", AD5251_ID},
86 {"ad5252", AD5252_ID},
87 {"ad5253", AD5253_ID},
88 {"ad5254", AD5254_ID},
89 {"ad5255", AD5255_ID},
90 {"ad5241", AD5241_ID},
91 {"ad5242", AD5242_ID},
92 {"ad5243", AD5243_ID},
93 {"ad5245", AD5245_ID},
94 {"ad5246", AD5246_ID},
95 {"ad5247", AD5247_ID},
96 {"ad5248", AD5248_ID},
97 {"ad5280", AD5280_ID},
98 {"ad5282", AD5282_ID},
99 {"adn2860", ADN2860_ID},
100 {"ad5273", AD5273_ID},
101 {"ad5171", AD5171_ID},
102 {"ad5170", AD5170_ID},
103 {"ad5172", AD5172_ID},
104 {"ad5173", AD5173_ID},
105 {"ad5272", AD5272_ID},
106 {"ad5274", AD5274_ID},
107 {}
108};
109MODULE_DEVICE_TABLE(i2c, ad_dpot_id);
110
111static struct i2c_driver ad_dpot_i2c_driver = {
112 .driver = {
113 .name = "ad_dpot",
114 .owner = THIS_MODULE,
115 },
116 .probe = ad_dpot_i2c_probe,
117 .remove = __devexit_p(ad_dpot_i2c_remove),
118 .id_table = ad_dpot_id,
119};
120
121static int __init ad_dpot_i2c_init(void)
122{
123 return i2c_add_driver(&ad_dpot_i2c_driver);
124}
125module_init(ad_dpot_i2c_init);
126
127static void __exit ad_dpot_i2c_exit(void)
128{
129 i2c_del_driver(&ad_dpot_i2c_driver);
130}
131module_exit(ad_dpot_i2c_exit);
132
133MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
134MODULE_DESCRIPTION("digital potentiometer I2C bus driver");
135MODULE_LICENSE("GPL");
136MODULE_ALIAS("i2c:ad_dpot");
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Driver for the Analog Devices digital potentiometers (I2C bus)
4 *
5 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
6 */
7
8#include <linux/i2c.h>
9#include <linux/module.h>
10
11#include "ad525x_dpot.h"
12
13/* I2C bus functions */
14static int write_d8(void *client, u8 val)
15{
16 return i2c_smbus_write_byte(client, val);
17}
18
19static int write_r8d8(void *client, u8 reg, u8 val)
20{
21 return i2c_smbus_write_byte_data(client, reg, val);
22}
23
24static int write_r8d16(void *client, u8 reg, u16 val)
25{
26 return i2c_smbus_write_word_data(client, reg, val);
27}
28
29static int read_d8(void *client)
30{
31 return i2c_smbus_read_byte(client);
32}
33
34static int read_r8d8(void *client, u8 reg)
35{
36 return i2c_smbus_read_byte_data(client, reg);
37}
38
39static int read_r8d16(void *client, u8 reg)
40{
41 return i2c_smbus_read_word_data(client, reg);
42}
43
44static const struct ad_dpot_bus_ops bops = {
45 .read_d8 = read_d8,
46 .read_r8d8 = read_r8d8,
47 .read_r8d16 = read_r8d16,
48 .write_d8 = write_d8,
49 .write_r8d8 = write_r8d8,
50 .write_r8d16 = write_r8d16,
51};
52
53static int ad_dpot_i2c_probe(struct i2c_client *client,
54 const struct i2c_device_id *id)
55{
56 struct ad_dpot_bus_data bdata = {
57 .client = client,
58 .bops = &bops,
59 };
60
61 if (!i2c_check_functionality(client->adapter,
62 I2C_FUNC_SMBUS_WORD_DATA)) {
63 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
64 return -EIO;
65 }
66
67 return ad_dpot_probe(&client->dev, &bdata, id->driver_data, id->name);
68}
69
70static void ad_dpot_i2c_remove(struct i2c_client *client)
71{
72 ad_dpot_remove(&client->dev);
73}
74
75static const struct i2c_device_id ad_dpot_id[] = {
76 {"ad5258", AD5258_ID},
77 {"ad5259", AD5259_ID},
78 {"ad5251", AD5251_ID},
79 {"ad5252", AD5252_ID},
80 {"ad5253", AD5253_ID},
81 {"ad5254", AD5254_ID},
82 {"ad5255", AD5255_ID},
83 {"ad5241", AD5241_ID},
84 {"ad5242", AD5242_ID},
85 {"ad5243", AD5243_ID},
86 {"ad5245", AD5245_ID},
87 {"ad5246", AD5246_ID},
88 {"ad5247", AD5247_ID},
89 {"ad5248", AD5248_ID},
90 {"ad5280", AD5280_ID},
91 {"ad5282", AD5282_ID},
92 {"adn2860", ADN2860_ID},
93 {"ad5273", AD5273_ID},
94 {"ad5161", AD5161_ID},
95 {"ad5171", AD5171_ID},
96 {"ad5170", AD5170_ID},
97 {"ad5172", AD5172_ID},
98 {"ad5173", AD5173_ID},
99 {"ad5272", AD5272_ID},
100 {"ad5274", AD5274_ID},
101 {}
102};
103MODULE_DEVICE_TABLE(i2c, ad_dpot_id);
104
105static struct i2c_driver ad_dpot_i2c_driver = {
106 .driver = {
107 .name = "ad_dpot",
108 },
109 .probe = ad_dpot_i2c_probe,
110 .remove = ad_dpot_i2c_remove,
111 .id_table = ad_dpot_id,
112};
113
114module_i2c_driver(ad_dpot_i2c_driver);
115
116MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
117MODULE_DESCRIPTION("digital potentiometer I2C bus driver");
118MODULE_LICENSE("GPL");