1*47298897SPhilippe Reynes /* 2*47298897SPhilippe Reynes * iio/dac/max5821.c 3*47298897SPhilippe Reynes * Copyright (C) 2014 Philippe Reynes 4*47298897SPhilippe Reynes * 5*47298897SPhilippe Reynes * This program is free software; you can redistribute it and/or modify 6*47298897SPhilippe Reynes * it under the terms of the GNU General Public License version 2 as 7*47298897SPhilippe Reynes * published by the Free Software Foundation. 8*47298897SPhilippe Reynes */ 9*47298897SPhilippe Reynes 10*47298897SPhilippe Reynes #include <linux/kernel.h> 11*47298897SPhilippe Reynes #include <linux/module.h> 12*47298897SPhilippe Reynes #include <linux/i2c.h> 13*47298897SPhilippe Reynes #include <linux/iio/iio.h> 14*47298897SPhilippe Reynes #include <linux/regulator/consumer.h> 15*47298897SPhilippe Reynes 16*47298897SPhilippe Reynes #define MAX5821_MAX_DAC_CHANNELS 2 17*47298897SPhilippe Reynes 18*47298897SPhilippe Reynes /* command bytes */ 19*47298897SPhilippe Reynes #define MAX5821_LOAD_DAC_A_IN_REG_B 0x00 20*47298897SPhilippe Reynes #define MAX5821_LOAD_DAC_B_IN_REG_A 0x10 21*47298897SPhilippe Reynes #define MAX5821_EXTENDED_COMMAND_MODE 0xf0 22*47298897SPhilippe Reynes #define MAX5821_READ_DAC_A_COMMAND 0xf1 23*47298897SPhilippe Reynes #define MAX5821_READ_DAC_B_COMMAND 0xf2 24*47298897SPhilippe Reynes 25*47298897SPhilippe Reynes #define MAX5821_EXTENDED_POWER_UP 0x00 26*47298897SPhilippe Reynes #define MAX5821_EXTENDED_POWER_DOWN_MODE0 0x01 27*47298897SPhilippe Reynes #define MAX5821_EXTENDED_POWER_DOWN_MODE1 0x02 28*47298897SPhilippe Reynes #define MAX5821_EXTENDED_POWER_DOWN_MODE2 0x03 29*47298897SPhilippe Reynes #define MAX5821_EXTENDED_DAC_A 0x04 30*47298897SPhilippe Reynes #define MAX5821_EXTENDED_DAC_B 0x08 31*47298897SPhilippe Reynes 32*47298897SPhilippe Reynes enum max5821_device_ids { 33*47298897SPhilippe Reynes ID_MAX5821, 34*47298897SPhilippe Reynes }; 35*47298897SPhilippe Reynes 36*47298897SPhilippe Reynes struct max5821_data { 37*47298897SPhilippe Reynes struct i2c_client *client; 38*47298897SPhilippe Reynes struct regulator *vref_reg; 39*47298897SPhilippe Reynes unsigned short vref_mv; 40*47298897SPhilippe Reynes bool powerdown[MAX5821_MAX_DAC_CHANNELS]; 41*47298897SPhilippe Reynes u8 powerdown_mode[MAX5821_MAX_DAC_CHANNELS]; 42*47298897SPhilippe Reynes struct mutex lock; 43*47298897SPhilippe Reynes }; 44*47298897SPhilippe Reynes 45*47298897SPhilippe Reynes static const char * const max5821_powerdown_modes[] = { 46*47298897SPhilippe Reynes "three_state", 47*47298897SPhilippe Reynes "1kohm_to_gnd", 48*47298897SPhilippe Reynes "100kohm_to_gnd", 49*47298897SPhilippe Reynes }; 50*47298897SPhilippe Reynes 51*47298897SPhilippe Reynes enum { 52*47298897SPhilippe Reynes MAX5821_THREE_STATE, 53*47298897SPhilippe Reynes MAX5821_1KOHM_TO_GND, 54*47298897SPhilippe Reynes MAX5821_100KOHM_TO_GND 55*47298897SPhilippe Reynes }; 56*47298897SPhilippe Reynes 57*47298897SPhilippe Reynes static int max5821_get_powerdown_mode(struct iio_dev *indio_dev, 58*47298897SPhilippe Reynes const struct iio_chan_spec *chan) 59*47298897SPhilippe Reynes { 60*47298897SPhilippe Reynes struct max5821_data *st = iio_priv(indio_dev); 61*47298897SPhilippe Reynes 62*47298897SPhilippe Reynes return st->powerdown_mode[chan->channel]; 63*47298897SPhilippe Reynes } 64*47298897SPhilippe Reynes 65*47298897SPhilippe Reynes static int max5821_set_powerdown_mode(struct iio_dev *indio_dev, 66*47298897SPhilippe Reynes const struct iio_chan_spec *chan, 67*47298897SPhilippe Reynes unsigned int mode) 68*47298897SPhilippe Reynes { 69*47298897SPhilippe Reynes struct max5821_data *st = iio_priv(indio_dev); 70*47298897SPhilippe Reynes 71*47298897SPhilippe Reynes st->powerdown_mode[chan->channel] = mode; 72*47298897SPhilippe Reynes 73*47298897SPhilippe Reynes return 0; 74*47298897SPhilippe Reynes } 75*47298897SPhilippe Reynes 76*47298897SPhilippe Reynes static const struct iio_enum max5821_powerdown_mode_enum = { 77*47298897SPhilippe Reynes .items = max5821_powerdown_modes, 78*47298897SPhilippe Reynes .num_items = ARRAY_SIZE(max5821_powerdown_modes), 79*47298897SPhilippe Reynes .get = max5821_get_powerdown_mode, 80*47298897SPhilippe Reynes .set = max5821_set_powerdown_mode, 81*47298897SPhilippe Reynes }; 82*47298897SPhilippe Reynes 83*47298897SPhilippe Reynes static ssize_t max5821_read_dac_powerdown(struct iio_dev *indio_dev, 84*47298897SPhilippe Reynes uintptr_t private, 85*47298897SPhilippe Reynes const struct iio_chan_spec *chan, 86*47298897SPhilippe Reynes char *buf) 87*47298897SPhilippe Reynes { 88*47298897SPhilippe Reynes struct max5821_data *st = iio_priv(indio_dev); 89*47298897SPhilippe Reynes 90*47298897SPhilippe Reynes return sprintf(buf, "%d\n", st->powerdown[chan->channel]); 91*47298897SPhilippe Reynes } 92*47298897SPhilippe Reynes 93*47298897SPhilippe Reynes static int max5821_sync_powerdown_mode(struct max5821_data *data, 94*47298897SPhilippe Reynes const struct iio_chan_spec *chan) 95*47298897SPhilippe Reynes { 96*47298897SPhilippe Reynes u8 outbuf[2]; 97*47298897SPhilippe Reynes 98*47298897SPhilippe Reynes outbuf[0] = MAX5821_EXTENDED_COMMAND_MODE; 99*47298897SPhilippe Reynes 100*47298897SPhilippe Reynes if (chan->channel == 0) 101*47298897SPhilippe Reynes outbuf[1] = MAX5821_EXTENDED_DAC_A; 102*47298897SPhilippe Reynes else 103*47298897SPhilippe Reynes outbuf[1] = MAX5821_EXTENDED_DAC_B; 104*47298897SPhilippe Reynes 105*47298897SPhilippe Reynes if (data->powerdown[chan->channel]) 106*47298897SPhilippe Reynes outbuf[1] |= data->powerdown_mode[chan->channel] + 1; 107*47298897SPhilippe Reynes else 108*47298897SPhilippe Reynes outbuf[1] |= MAX5821_EXTENDED_POWER_UP; 109*47298897SPhilippe Reynes 110*47298897SPhilippe Reynes return i2c_master_send(data->client, outbuf, 2); 111*47298897SPhilippe Reynes } 112*47298897SPhilippe Reynes 113*47298897SPhilippe Reynes static ssize_t max5821_write_dac_powerdown(struct iio_dev *indio_dev, 114*47298897SPhilippe Reynes uintptr_t private, 115*47298897SPhilippe Reynes const struct iio_chan_spec *chan, 116*47298897SPhilippe Reynes const char *buf, size_t len) 117*47298897SPhilippe Reynes { 118*47298897SPhilippe Reynes struct max5821_data *data = iio_priv(indio_dev); 119*47298897SPhilippe Reynes bool powerdown; 120*47298897SPhilippe Reynes int ret; 121*47298897SPhilippe Reynes 122*47298897SPhilippe Reynes ret = strtobool(buf, &powerdown); 123*47298897SPhilippe Reynes if (ret) 124*47298897SPhilippe Reynes return ret; 125*47298897SPhilippe Reynes 126*47298897SPhilippe Reynes data->powerdown[chan->channel] = powerdown; 127*47298897SPhilippe Reynes 128*47298897SPhilippe Reynes ret = max5821_sync_powerdown_mode(data, chan); 129*47298897SPhilippe Reynes if (ret < 0) 130*47298897SPhilippe Reynes return ret; 131*47298897SPhilippe Reynes 132*47298897SPhilippe Reynes return len; 133*47298897SPhilippe Reynes } 134*47298897SPhilippe Reynes 135*47298897SPhilippe Reynes static const struct iio_chan_spec_ext_info max5821_ext_info[] = { 136*47298897SPhilippe Reynes { 137*47298897SPhilippe Reynes .name = "powerdown", 138*47298897SPhilippe Reynes .read = max5821_read_dac_powerdown, 139*47298897SPhilippe Reynes .write = max5821_write_dac_powerdown, 140*47298897SPhilippe Reynes .shared = IIO_SEPARATE, 141*47298897SPhilippe Reynes }, 142*47298897SPhilippe Reynes IIO_ENUM("powerdown_mode", IIO_SEPARATE, &max5821_powerdown_mode_enum), 143*47298897SPhilippe Reynes IIO_ENUM_AVAILABLE("powerdown_mode", &max5821_powerdown_mode_enum), 144*47298897SPhilippe Reynes { }, 145*47298897SPhilippe Reynes }; 146*47298897SPhilippe Reynes 147*47298897SPhilippe Reynes #define MAX5821_CHANNEL(chan) { \ 148*47298897SPhilippe Reynes .type = IIO_VOLTAGE, \ 149*47298897SPhilippe Reynes .indexed = 1, \ 150*47298897SPhilippe Reynes .output = 1, \ 151*47298897SPhilippe Reynes .channel = (chan), \ 152*47298897SPhilippe Reynes .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 153*47298897SPhilippe Reynes .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE), \ 154*47298897SPhilippe Reynes .ext_info = max5821_ext_info, \ 155*47298897SPhilippe Reynes } 156*47298897SPhilippe Reynes 157*47298897SPhilippe Reynes static const struct iio_chan_spec max5821_channels[] = { 158*47298897SPhilippe Reynes MAX5821_CHANNEL(0), 159*47298897SPhilippe Reynes MAX5821_CHANNEL(1) 160*47298897SPhilippe Reynes }; 161*47298897SPhilippe Reynes 162*47298897SPhilippe Reynes static const u8 max5821_read_dac_command[] = { 163*47298897SPhilippe Reynes MAX5821_READ_DAC_A_COMMAND, 164*47298897SPhilippe Reynes MAX5821_READ_DAC_B_COMMAND 165*47298897SPhilippe Reynes }; 166*47298897SPhilippe Reynes 167*47298897SPhilippe Reynes static const u8 max5821_load_dac_command[] = { 168*47298897SPhilippe Reynes MAX5821_LOAD_DAC_A_IN_REG_B, 169*47298897SPhilippe Reynes MAX5821_LOAD_DAC_B_IN_REG_A 170*47298897SPhilippe Reynes }; 171*47298897SPhilippe Reynes 172*47298897SPhilippe Reynes static int max5821_get_value(struct iio_dev *indio_dev, 173*47298897SPhilippe Reynes int *val, int channel) 174*47298897SPhilippe Reynes { 175*47298897SPhilippe Reynes struct max5821_data *data = iio_priv(indio_dev); 176*47298897SPhilippe Reynes struct i2c_client *client = data->client; 177*47298897SPhilippe Reynes u8 outbuf[1]; 178*47298897SPhilippe Reynes u8 inbuf[2]; 179*47298897SPhilippe Reynes int ret; 180*47298897SPhilippe Reynes 181*47298897SPhilippe Reynes if ((channel != 0) && (channel != 1)) 182*47298897SPhilippe Reynes return -EINVAL; 183*47298897SPhilippe Reynes 184*47298897SPhilippe Reynes outbuf[0] = max5821_read_dac_command[channel]; 185*47298897SPhilippe Reynes 186*47298897SPhilippe Reynes mutex_lock(&data->lock); 187*47298897SPhilippe Reynes 188*47298897SPhilippe Reynes ret = i2c_master_send(client, outbuf, 1); 189*47298897SPhilippe Reynes if (ret < 0) { 190*47298897SPhilippe Reynes mutex_unlock(&data->lock); 191*47298897SPhilippe Reynes return ret; 192*47298897SPhilippe Reynes } else if (ret != 1) { 193*47298897SPhilippe Reynes mutex_unlock(&data->lock); 194*47298897SPhilippe Reynes return -EIO; 195*47298897SPhilippe Reynes } 196*47298897SPhilippe Reynes 197*47298897SPhilippe Reynes ret = i2c_master_recv(client, inbuf, 2); 198*47298897SPhilippe Reynes if (ret < 0) { 199*47298897SPhilippe Reynes mutex_unlock(&data->lock); 200*47298897SPhilippe Reynes return ret; 201*47298897SPhilippe Reynes } else if (ret != 2) { 202*47298897SPhilippe Reynes mutex_unlock(&data->lock); 203*47298897SPhilippe Reynes return -EIO; 204*47298897SPhilippe Reynes } 205*47298897SPhilippe Reynes 206*47298897SPhilippe Reynes mutex_unlock(&data->lock); 207*47298897SPhilippe Reynes 208*47298897SPhilippe Reynes *val = ((inbuf[0] & 0x0f) << 6) | (inbuf[1] >> 2); 209*47298897SPhilippe Reynes 210*47298897SPhilippe Reynes return IIO_VAL_INT; 211*47298897SPhilippe Reynes } 212*47298897SPhilippe Reynes 213*47298897SPhilippe Reynes static int max5821_set_value(struct iio_dev *indio_dev, 214*47298897SPhilippe Reynes int val, int channel) 215*47298897SPhilippe Reynes { 216*47298897SPhilippe Reynes struct max5821_data *data = iio_priv(indio_dev); 217*47298897SPhilippe Reynes struct i2c_client *client = data->client; 218*47298897SPhilippe Reynes u8 outbuf[2]; 219*47298897SPhilippe Reynes int ret; 220*47298897SPhilippe Reynes 221*47298897SPhilippe Reynes if ((val < 0) || (val > 1023)) 222*47298897SPhilippe Reynes return -EINVAL; 223*47298897SPhilippe Reynes 224*47298897SPhilippe Reynes if ((channel != 0) && (channel != 1)) 225*47298897SPhilippe Reynes return -EINVAL; 226*47298897SPhilippe Reynes 227*47298897SPhilippe Reynes outbuf[0] = max5821_load_dac_command[channel]; 228*47298897SPhilippe Reynes outbuf[0] |= val >> 6; 229*47298897SPhilippe Reynes outbuf[1] = (val & 0x3f) << 2; 230*47298897SPhilippe Reynes 231*47298897SPhilippe Reynes ret = i2c_master_send(client, outbuf, 2); 232*47298897SPhilippe Reynes if (ret < 0) 233*47298897SPhilippe Reynes return ret; 234*47298897SPhilippe Reynes else if (ret != 2) 235*47298897SPhilippe Reynes return -EIO; 236*47298897SPhilippe Reynes else 237*47298897SPhilippe Reynes return 0; 238*47298897SPhilippe Reynes } 239*47298897SPhilippe Reynes 240*47298897SPhilippe Reynes static int max5821_read_raw(struct iio_dev *indio_dev, 241*47298897SPhilippe Reynes struct iio_chan_spec const *chan, 242*47298897SPhilippe Reynes int *val, int *val2, long mask) 243*47298897SPhilippe Reynes { 244*47298897SPhilippe Reynes struct max5821_data *data = iio_priv(indio_dev); 245*47298897SPhilippe Reynes 246*47298897SPhilippe Reynes switch (mask) { 247*47298897SPhilippe Reynes case IIO_CHAN_INFO_RAW: 248*47298897SPhilippe Reynes return max5821_get_value(indio_dev, val, chan->channel); 249*47298897SPhilippe Reynes case IIO_CHAN_INFO_SCALE: 250*47298897SPhilippe Reynes *val = data->vref_mv; 251*47298897SPhilippe Reynes *val2 = 10; 252*47298897SPhilippe Reynes return IIO_VAL_FRACTIONAL_LOG2; 253*47298897SPhilippe Reynes default: 254*47298897SPhilippe Reynes return -EINVAL; 255*47298897SPhilippe Reynes } 256*47298897SPhilippe Reynes } 257*47298897SPhilippe Reynes 258*47298897SPhilippe Reynes static int max5821_write_raw(struct iio_dev *indio_dev, 259*47298897SPhilippe Reynes struct iio_chan_spec const *chan, 260*47298897SPhilippe Reynes int val, int val2, long mask) 261*47298897SPhilippe Reynes { 262*47298897SPhilippe Reynes if (val2 != 0) 263*47298897SPhilippe Reynes return -EINVAL; 264*47298897SPhilippe Reynes 265*47298897SPhilippe Reynes switch (mask) { 266*47298897SPhilippe Reynes case IIO_CHAN_INFO_RAW: 267*47298897SPhilippe Reynes return max5821_set_value(indio_dev, val, chan->channel); 268*47298897SPhilippe Reynes default: 269*47298897SPhilippe Reynes return -EINVAL; 270*47298897SPhilippe Reynes } 271*47298897SPhilippe Reynes } 272*47298897SPhilippe Reynes 273*47298897SPhilippe Reynes #ifdef CONFIG_PM_SLEEP 274*47298897SPhilippe Reynes static int max5821_suspend(struct device *dev) 275*47298897SPhilippe Reynes { 276*47298897SPhilippe Reynes u8 outbuf[2] = { MAX5821_EXTENDED_COMMAND_MODE, 277*47298897SPhilippe Reynes MAX5821_EXTENDED_DAC_A | 278*47298897SPhilippe Reynes MAX5821_EXTENDED_DAC_B | 279*47298897SPhilippe Reynes MAX5821_EXTENDED_POWER_DOWN_MODE2 }; 280*47298897SPhilippe Reynes 281*47298897SPhilippe Reynes return i2c_master_send(to_i2c_client(dev), outbuf, 2); 282*47298897SPhilippe Reynes } 283*47298897SPhilippe Reynes 284*47298897SPhilippe Reynes static int max5821_resume(struct device *dev) 285*47298897SPhilippe Reynes { 286*47298897SPhilippe Reynes u8 outbuf[2] = { MAX5821_EXTENDED_COMMAND_MODE, 287*47298897SPhilippe Reynes MAX5821_EXTENDED_DAC_A | 288*47298897SPhilippe Reynes MAX5821_EXTENDED_DAC_B | 289*47298897SPhilippe Reynes MAX5821_EXTENDED_POWER_UP }; 290*47298897SPhilippe Reynes 291*47298897SPhilippe Reynes return i2c_master_send(to_i2c_client(dev), outbuf, 2); 292*47298897SPhilippe Reynes } 293*47298897SPhilippe Reynes 294*47298897SPhilippe Reynes static SIMPLE_DEV_PM_OPS(max5821_pm_ops, max5821_suspend, max5821_resume); 295*47298897SPhilippe Reynes #define MAX5821_PM_OPS (&max5821_pm_ops) 296*47298897SPhilippe Reynes #else 297*47298897SPhilippe Reynes #define MAX5821_PM_OPS NULL 298*47298897SPhilippe Reynes #endif /* CONFIG_PM_SLEEP */ 299*47298897SPhilippe Reynes 300*47298897SPhilippe Reynes static const struct iio_info max5821_info = { 301*47298897SPhilippe Reynes .read_raw = max5821_read_raw, 302*47298897SPhilippe Reynes .write_raw = max5821_write_raw, 303*47298897SPhilippe Reynes .driver_module = THIS_MODULE, 304*47298897SPhilippe Reynes }; 305*47298897SPhilippe Reynes 306*47298897SPhilippe Reynes static int max5821_probe(struct i2c_client *client, 307*47298897SPhilippe Reynes const struct i2c_device_id *id) 308*47298897SPhilippe Reynes { 309*47298897SPhilippe Reynes struct max5821_data *data; 310*47298897SPhilippe Reynes struct iio_dev *indio_dev; 311*47298897SPhilippe Reynes u32 tmp; 312*47298897SPhilippe Reynes int ret; 313*47298897SPhilippe Reynes 314*47298897SPhilippe Reynes indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 315*47298897SPhilippe Reynes if (!indio_dev) 316*47298897SPhilippe Reynes return -ENOMEM; 317*47298897SPhilippe Reynes data = iio_priv(indio_dev); 318*47298897SPhilippe Reynes i2c_set_clientdata(client, indio_dev); 319*47298897SPhilippe Reynes data->client = client; 320*47298897SPhilippe Reynes mutex_init(&data->lock); 321*47298897SPhilippe Reynes 322*47298897SPhilippe Reynes /* max5821 start in powerdown mode 100Kohm to ground */ 323*47298897SPhilippe Reynes for (tmp = 0; tmp < MAX5821_MAX_DAC_CHANNELS; tmp++) { 324*47298897SPhilippe Reynes data->powerdown[tmp] = true; 325*47298897SPhilippe Reynes data->powerdown_mode[tmp] = MAX5821_100KOHM_TO_GND; 326*47298897SPhilippe Reynes } 327*47298897SPhilippe Reynes 328*47298897SPhilippe Reynes data->vref_reg = devm_regulator_get(&client->dev, "vref"); 329*47298897SPhilippe Reynes if (IS_ERR(data->vref_reg)) { 330*47298897SPhilippe Reynes ret = PTR_ERR(data->vref_reg); 331*47298897SPhilippe Reynes dev_err(&client->dev, 332*47298897SPhilippe Reynes "Failed to get vref regulator: %d\n", ret); 333*47298897SPhilippe Reynes goto error_free_reg; 334*47298897SPhilippe Reynes } 335*47298897SPhilippe Reynes 336*47298897SPhilippe Reynes ret = regulator_enable(data->vref_reg); 337*47298897SPhilippe Reynes if (ret) { 338*47298897SPhilippe Reynes dev_err(&client->dev, 339*47298897SPhilippe Reynes "Failed to enable vref regulator: %d\n", ret); 340*47298897SPhilippe Reynes goto error_free_reg; 341*47298897SPhilippe Reynes } 342*47298897SPhilippe Reynes 343*47298897SPhilippe Reynes ret = regulator_get_voltage(data->vref_reg); 344*47298897SPhilippe Reynes if (ret < 0) { 345*47298897SPhilippe Reynes dev_err(&client->dev, 346*47298897SPhilippe Reynes "Failed to get voltage on regulator: %d\n", ret); 347*47298897SPhilippe Reynes goto error_disable_reg; 348*47298897SPhilippe Reynes } 349*47298897SPhilippe Reynes 350*47298897SPhilippe Reynes data->vref_mv = ret / 1000; 351*47298897SPhilippe Reynes 352*47298897SPhilippe Reynes indio_dev->name = id->name; 353*47298897SPhilippe Reynes indio_dev->dev.parent = &client->dev; 354*47298897SPhilippe Reynes indio_dev->num_channels = ARRAY_SIZE(max5821_channels); 355*47298897SPhilippe Reynes indio_dev->channels = max5821_channels; 356*47298897SPhilippe Reynes indio_dev->modes = INDIO_DIRECT_MODE; 357*47298897SPhilippe Reynes indio_dev->info = &max5821_info; 358*47298897SPhilippe Reynes 359*47298897SPhilippe Reynes return iio_device_register(indio_dev); 360*47298897SPhilippe Reynes 361*47298897SPhilippe Reynes error_disable_reg: 362*47298897SPhilippe Reynes regulator_disable(data->vref_reg); 363*47298897SPhilippe Reynes 364*47298897SPhilippe Reynes error_free_reg: 365*47298897SPhilippe Reynes 366*47298897SPhilippe Reynes return ret; 367*47298897SPhilippe Reynes } 368*47298897SPhilippe Reynes 369*47298897SPhilippe Reynes static int max5821_remove(struct i2c_client *client) 370*47298897SPhilippe Reynes { 371*47298897SPhilippe Reynes struct iio_dev *indio_dev = i2c_get_clientdata(client); 372*47298897SPhilippe Reynes struct max5821_data *data = iio_priv(indio_dev); 373*47298897SPhilippe Reynes 374*47298897SPhilippe Reynes iio_device_unregister(indio_dev); 375*47298897SPhilippe Reynes regulator_disable(data->vref_reg); 376*47298897SPhilippe Reynes 377*47298897SPhilippe Reynes return 0; 378*47298897SPhilippe Reynes } 379*47298897SPhilippe Reynes 380*47298897SPhilippe Reynes static const struct i2c_device_id max5821_id[] = { 381*47298897SPhilippe Reynes { "max5821", ID_MAX5821 }, 382*47298897SPhilippe Reynes { } 383*47298897SPhilippe Reynes }; 384*47298897SPhilippe Reynes MODULE_DEVICE_TABLE(i2c, max5821_id); 385*47298897SPhilippe Reynes 386*47298897SPhilippe Reynes static const struct of_device_id max5821_of_match[] = { 387*47298897SPhilippe Reynes { .compatible = "maxim,max5821" }, 388*47298897SPhilippe Reynes { } 389*47298897SPhilippe Reynes }; 390*47298897SPhilippe Reynes 391*47298897SPhilippe Reynes static struct i2c_driver max5821_driver = { 392*47298897SPhilippe Reynes .driver = { 393*47298897SPhilippe Reynes .name = "max5821", 394*47298897SPhilippe Reynes .pm = MAX5821_PM_OPS, 395*47298897SPhilippe Reynes .owner = THIS_MODULE, 396*47298897SPhilippe Reynes }, 397*47298897SPhilippe Reynes .probe = max5821_probe, 398*47298897SPhilippe Reynes .remove = max5821_remove, 399*47298897SPhilippe Reynes .id_table = max5821_id, 400*47298897SPhilippe Reynes }; 401*47298897SPhilippe Reynes module_i2c_driver(max5821_driver); 402*47298897SPhilippe Reynes 403*47298897SPhilippe Reynes MODULE_AUTHOR("Philippe Reynes <tremyfr@yahoo.fr>"); 404*47298897SPhilippe Reynes MODULE_DESCRIPTION("MAX5821 DAC"); 405*47298897SPhilippe Reynes MODULE_LICENSE("GPL v2"); 406