Thomas Gleixner | 80503b2 | 2019-05-24 12:04:09 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for the Analog Devices digital potentiometers (I2C bus) |
| 4 | * |
Michael Hennerich | 7f3379d | 2011-11-18 11:05:11 +0100 | [diff] [blame] | 5 | * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc. |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/i2c.h> |
| 9 | #include <linux/module.h> |
| 10 | |
| 11 | #include "ad525x_dpot.h" |
| 12 | |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 13 | /* I2C bus functions */ |
| 14 | static int write_d8(void *client, u8 val) |
| 15 | { |
| 16 | return i2c_smbus_write_byte(client, val); |
| 17 | } |
| 18 | |
| 19 | static int write_r8d8(void *client, u8 reg, u8 val) |
| 20 | { |
| 21 | return i2c_smbus_write_byte_data(client, reg, val); |
| 22 | } |
| 23 | |
| 24 | static int write_r8d16(void *client, u8 reg, u16 val) |
| 25 | { |
| 26 | return i2c_smbus_write_word_data(client, reg, val); |
| 27 | } |
| 28 | |
| 29 | static int read_d8(void *client) |
| 30 | { |
| 31 | return i2c_smbus_read_byte(client); |
| 32 | } |
| 33 | |
| 34 | static int read_r8d8(void *client, u8 reg) |
| 35 | { |
| 36 | return i2c_smbus_read_byte_data(client, reg); |
| 37 | } |
| 38 | |
| 39 | static int read_r8d16(void *client, u8 reg) |
| 40 | { |
| 41 | return i2c_smbus_read_word_data(client, reg); |
| 42 | } |
| 43 | |
| 44 | static 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 | |
Bill Pemberton | 80c8ae2 | 2012-11-19 13:23:05 -0500 | [diff] [blame] | 53 | static int ad_dpot_i2c_probe(struct i2c_client *client, |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 54 | const struct i2c_device_id *id) |
| 55 | { |
| 56 | struct ad_dpot_bus_data bdata = { |
| 57 | .client = client, |
| 58 | .bops = &bops, |
| 59 | }; |
| 60 | |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 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 | |
Michael Hennerich | 7f3379d | 2011-11-18 11:05:11 +0100 | [diff] [blame] | 67 | return ad_dpot_probe(&client->dev, &bdata, id->driver_data, id->name); |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Bill Pemberton | 486a5c2 | 2012-11-19 13:26:02 -0500 | [diff] [blame] | 70 | static int ad_dpot_i2c_remove(struct i2c_client *client) |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 71 | { |
| 72 | return ad_dpot_remove(&client->dev); |
| 73 | } |
| 74 | |
| 75 | static 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}, |
Michael Hennerich | e3ae68476 | 2010-05-24 14:33:15 -0700 | [diff] [blame] | 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}, |
Michael Hennerich | c74cba6 | 2010-05-24 14:33:15 -0700 | [diff] [blame] | 90 | {"ad5280", AD5280_ID}, |
| 91 | {"ad5282", AD5282_ID}, |
| 92 | {"adn2860", ADN2860_ID}, |
Michael Hennerich | 59592d0 | 2010-05-24 14:33:16 -0700 | [diff] [blame] | 93 | {"ad5273", AD5273_ID}, |
Peter Korsgaard | aaaa287 | 2011-10-31 17:11:12 -0700 | [diff] [blame] | 94 | {"ad5161", AD5161_ID}, |
Michael Hennerich | 59592d0 | 2010-05-24 14:33:16 -0700 | [diff] [blame] | 95 | {"ad5171", AD5171_ID}, |
| 96 | {"ad5170", AD5170_ID}, |
| 97 | {"ad5172", AD5172_ID}, |
| 98 | {"ad5173", AD5173_ID}, |
Michael Hennerich | a4bd394 | 2010-10-26 14:22:36 -0700 | [diff] [blame] | 99 | {"ad5272", AD5272_ID}, |
| 100 | {"ad5274", AD5274_ID}, |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 101 | {} |
| 102 | }; |
| 103 | MODULE_DEVICE_TABLE(i2c, ad_dpot_id); |
| 104 | |
| 105 | static struct i2c_driver ad_dpot_i2c_driver = { |
| 106 | .driver = { |
| 107 | .name = "ad_dpot", |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 108 | }, |
| 109 | .probe = ad_dpot_i2c_probe, |
Bill Pemberton | 2d6bed9 | 2012-11-19 13:21:23 -0500 | [diff] [blame] | 110 | .remove = ad_dpot_i2c_remove, |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 111 | .id_table = ad_dpot_id, |
| 112 | }; |
| 113 | |
Axel Lin | a64fe2e | 2012-01-22 15:36:45 +0800 | [diff] [blame] | 114 | module_i2c_driver(ad_dpot_i2c_driver); |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 115 | |
Michael Hennerich | dbd7139 | 2018-08-14 13:30:18 +0200 | [diff] [blame] | 116 | MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); |
Michael Hennerich | 6c536e4 | 2010-05-24 14:33:14 -0700 | [diff] [blame] | 117 | MODULE_DESCRIPTION("digital potentiometer I2C bus driver"); |
| 118 | MODULE_LICENSE("GPL"); |