Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Driver for the Analog Devices digital potentiometers (I2C bus)
0004  *
0005  * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
0006  */
0007 
0008 #include <linux/i2c.h>
0009 #include <linux/module.h>
0010 
0011 #include "ad525x_dpot.h"
0012 
0013 /* I2C bus functions */
0014 static int write_d8(void *client, u8 val)
0015 {
0016     return i2c_smbus_write_byte(client, val);
0017 }
0018 
0019 static int write_r8d8(void *client, u8 reg, u8 val)
0020 {
0021     return i2c_smbus_write_byte_data(client, reg, val);
0022 }
0023 
0024 static int write_r8d16(void *client, u8 reg, u16 val)
0025 {
0026     return i2c_smbus_write_word_data(client, reg, val);
0027 }
0028 
0029 static int read_d8(void *client)
0030 {
0031     return i2c_smbus_read_byte(client);
0032 }
0033 
0034 static int read_r8d8(void *client, u8 reg)
0035 {
0036     return i2c_smbus_read_byte_data(client, reg);
0037 }
0038 
0039 static int read_r8d16(void *client, u8 reg)
0040 {
0041     return i2c_smbus_read_word_data(client, reg);
0042 }
0043 
0044 static const struct ad_dpot_bus_ops bops = {
0045     .read_d8    = read_d8,
0046     .read_r8d8  = read_r8d8,
0047     .read_r8d16 = read_r8d16,
0048     .write_d8   = write_d8,
0049     .write_r8d8 = write_r8d8,
0050     .write_r8d16    = write_r8d16,
0051 };
0052 
0053 static int ad_dpot_i2c_probe(struct i2c_client *client,
0054                       const struct i2c_device_id *id)
0055 {
0056     struct ad_dpot_bus_data bdata = {
0057         .client = client,
0058         .bops = &bops,
0059     };
0060 
0061     if (!i2c_check_functionality(client->adapter,
0062                      I2C_FUNC_SMBUS_WORD_DATA)) {
0063         dev_err(&client->dev, "SMBUS Word Data not Supported\n");
0064         return -EIO;
0065     }
0066 
0067     return ad_dpot_probe(&client->dev, &bdata, id->driver_data, id->name);
0068 }
0069 
0070 static int ad_dpot_i2c_remove(struct i2c_client *client)
0071 {
0072     ad_dpot_remove(&client->dev);
0073     return 0;
0074 }
0075 
0076 static const struct i2c_device_id ad_dpot_id[] = {
0077     {"ad5258", AD5258_ID},
0078     {"ad5259", AD5259_ID},
0079     {"ad5251", AD5251_ID},
0080     {"ad5252", AD5252_ID},
0081     {"ad5253", AD5253_ID},
0082     {"ad5254", AD5254_ID},
0083     {"ad5255", AD5255_ID},
0084     {"ad5241", AD5241_ID},
0085     {"ad5242", AD5242_ID},
0086     {"ad5243", AD5243_ID},
0087     {"ad5245", AD5245_ID},
0088     {"ad5246", AD5246_ID},
0089     {"ad5247", AD5247_ID},
0090     {"ad5248", AD5248_ID},
0091     {"ad5280", AD5280_ID},
0092     {"ad5282", AD5282_ID},
0093     {"adn2860", ADN2860_ID},
0094     {"ad5273", AD5273_ID},
0095     {"ad5161", AD5161_ID},
0096     {"ad5171", AD5171_ID},
0097     {"ad5170", AD5170_ID},
0098     {"ad5172", AD5172_ID},
0099     {"ad5173", AD5173_ID},
0100     {"ad5272", AD5272_ID},
0101     {"ad5274", AD5274_ID},
0102     {}
0103 };
0104 MODULE_DEVICE_TABLE(i2c, ad_dpot_id);
0105 
0106 static struct i2c_driver ad_dpot_i2c_driver = {
0107     .driver = {
0108         .name   = "ad_dpot",
0109     },
0110     .probe      = ad_dpot_i2c_probe,
0111     .remove     = ad_dpot_i2c_remove,
0112     .id_table   = ad_dpot_id,
0113 };
0114 
0115 module_i2c_driver(ad_dpot_i2c_driver);
0116 
0117 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
0118 MODULE_DESCRIPTION("digital potentiometer I2C bus driver");
0119 MODULE_LICENSE("GPL");