blob: 705b881e186d536ccb2bc97c392d108b3ecf765c [file] [log] [blame]
Michael Hennerich6c536e42010-05-24 14:33:14 -07001/*
2 * Driver for the Analog Devices digital potentiometers (I2C bus)
3 *
Michael Hennerich7f3379d2011-11-18 11:05:11 +01004 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
Michael Hennerich6c536e42010-05-24 14:33:14 -07005 *
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
Michael Hennerich6c536e42010-05-24 14:33:14 -070014/* I2C bus functions */
15static int write_d8(void *client, u8 val)
16{
17 return i2c_smbus_write_byte(client, val);
18}
19
20static int write_r8d8(void *client, u8 reg, u8 val)
21{
22 return i2c_smbus_write_byte_data(client, reg, val);
23}
24
25static int write_r8d16(void *client, u8 reg, u16 val)
26{
27 return i2c_smbus_write_word_data(client, reg, val);
28}
29
30static int read_d8(void *client)
31{
32 return i2c_smbus_read_byte(client);
33}
34
35static int read_r8d8(void *client, u8 reg)
36{
37 return i2c_smbus_read_byte_data(client, reg);
38}
39
40static int read_r8d16(void *client, u8 reg)
41{
42 return i2c_smbus_read_word_data(client, reg);
43}
44
45static const struct ad_dpot_bus_ops bops = {
46 .read_d8 = read_d8,
47 .read_r8d8 = read_r8d8,
48 .read_r8d16 = read_r8d16,
49 .write_d8 = write_d8,
50 .write_r8d8 = write_r8d8,
51 .write_r8d16 = write_r8d16,
52};
53
Bill Pemberton80c8ae22012-11-19 13:23:05 -050054static int ad_dpot_i2c_probe(struct i2c_client *client,
Michael Hennerich6c536e42010-05-24 14:33:14 -070055 const struct i2c_device_id *id)
56{
57 struct ad_dpot_bus_data bdata = {
58 .client = client,
59 .bops = &bops,
60 };
61
Michael Hennerich6c536e42010-05-24 14:33:14 -070062 if (!i2c_check_functionality(client->adapter,
63 I2C_FUNC_SMBUS_WORD_DATA)) {
64 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
65 return -EIO;
66 }
67
Michael Hennerich7f3379d2011-11-18 11:05:11 +010068 return ad_dpot_probe(&client->dev, &bdata, id->driver_data, id->name);
Michael Hennerich6c536e42010-05-24 14:33:14 -070069}
70
Bill Pemberton486a5c22012-11-19 13:26:02 -050071static int ad_dpot_i2c_remove(struct i2c_client *client)
Michael Hennerich6c536e42010-05-24 14:33:14 -070072{
73 return ad_dpot_remove(&client->dev);
74}
75
76static const struct i2c_device_id ad_dpot_id[] = {
77 {"ad5258", AD5258_ID},
78 {"ad5259", AD5259_ID},
79 {"ad5251", AD5251_ID},
80 {"ad5252", AD5252_ID},
81 {"ad5253", AD5253_ID},
82 {"ad5254", AD5254_ID},
83 {"ad5255", AD5255_ID},
Michael Henneriche3ae684762010-05-24 14:33:15 -070084 {"ad5241", AD5241_ID},
85 {"ad5242", AD5242_ID},
86 {"ad5243", AD5243_ID},
87 {"ad5245", AD5245_ID},
88 {"ad5246", AD5246_ID},
89 {"ad5247", AD5247_ID},
90 {"ad5248", AD5248_ID},
Michael Hennerichc74cba62010-05-24 14:33:15 -070091 {"ad5280", AD5280_ID},
92 {"ad5282", AD5282_ID},
93 {"adn2860", ADN2860_ID},
Michael Hennerich59592d02010-05-24 14:33:16 -070094 {"ad5273", AD5273_ID},
Peter Korsgaardaaaa2872011-10-31 17:11:12 -070095 {"ad5161", AD5161_ID},
Michael Hennerich59592d02010-05-24 14:33:16 -070096 {"ad5171", AD5171_ID},
97 {"ad5170", AD5170_ID},
98 {"ad5172", AD5172_ID},
99 {"ad5173", AD5173_ID},
Michael Hennericha4bd3942010-10-26 14:22:36 -0700100 {"ad5272", AD5272_ID},
101 {"ad5274", AD5274_ID},
Michael Hennerich6c536e42010-05-24 14:33:14 -0700102 {}
103};
104MODULE_DEVICE_TABLE(i2c, ad_dpot_id);
105
106static struct i2c_driver ad_dpot_i2c_driver = {
107 .driver = {
108 .name = "ad_dpot",
109 .owner = THIS_MODULE,
110 },
111 .probe = ad_dpot_i2c_probe,
Bill Pemberton2d6bed92012-11-19 13:21:23 -0500112 .remove = ad_dpot_i2c_remove,
Michael Hennerich6c536e42010-05-24 14:33:14 -0700113 .id_table = ad_dpot_id,
114};
115
Axel Lina64fe2e2012-01-22 15:36:45 +0800116module_i2c_driver(ad_dpot_i2c_driver);
Michael Hennerich6c536e42010-05-24 14:33:14 -0700117
118MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
119MODULE_DESCRIPTION("digital potentiometer I2C bus driver");
120MODULE_LICENSE("GPL");
121MODULE_ALIAS("i2c:ad_dpot");