Lines Matching +full:vref +full:- +full:n +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-only
3 * mcp4725.c - Support for Microchip MCP4725/6
9 * driver for the Microchip I2C 12-bit digital-to-analog converter (DAC)
10 * (7-bit I2C slave address 0x60, the three LSBs can be configured in
57 outbuf[0] = (data->powerdown_mode + 1) << 4; in mcp4725_suspend()
59 data->powerdown = true; in mcp4725_suspend()
61 ret = i2c_master_send(data->client, outbuf, 2); in mcp4725_suspend()
65 return -EIO; in mcp4725_suspend()
77 outbuf[0] = (data->dac_value >> 8) & 0xf; in mcp4725_resume()
78 outbuf[1] = data->dac_value & 0xff; in mcp4725_resume()
79 data->powerdown = false; in mcp4725_resume()
81 ret = i2c_master_send(data->client, outbuf, 2); in mcp4725_resume()
85 return -EIO; in mcp4725_resume()
109 inoutbuf[0] |= data->ref_mode << 3; in mcp4725_store_eeprom()
110 inoutbuf[0] |= data->powerdown ? ((data->powerdown_mode + 1) << 1) : 0; in mcp4725_store_eeprom()
111 inoutbuf[1] = data->dac_value >> 4; in mcp4725_store_eeprom()
112 inoutbuf[2] = (data->dac_value & 0xf) << 4; in mcp4725_store_eeprom()
114 ret = i2c_master_send(data->client, inoutbuf, 3); in mcp4725_store_eeprom()
118 return -EIO; in mcp4725_store_eeprom()
121 while (tries--) { in mcp4725_store_eeprom()
123 ret = i2c_master_recv(data->client, inoutbuf, 3); in mcp4725_store_eeprom()
127 return -EIO; in mcp4725_store_eeprom()
134 dev_err(&data->client->dev, in mcp4725_store_eeprom()
135 "mcp4725_store_eeprom() failed, incomplete\n"); in mcp4725_store_eeprom()
136 return -EIO; in mcp4725_store_eeprom()
170 return data->powerdown_mode; in mcp4725_get_powerdown_mode()
178 data->powerdown_mode = mode; in mcp4725_set_powerdown_mode()
188 return sysfs_emit(buf, "%d\n", data->powerdown); in mcp4725_read_powerdown()
204 ret = mcp4725_suspend(&data->client->dev); in mcp4725_write_powerdown()
206 ret = mcp4725_resume(&data->client->dev); in mcp4725_write_powerdown()
289 return -EINVAL; in mcp4725_set_value()
294 ret = i2c_master_send(data->client, outbuf, 2); in mcp4725_set_value()
298 return -EIO; in mcp4725_set_value()
310 outbuf[0] |= data->ref_mode << 3; in mcp4726_set_cfg()
311 if (data->powerdown) in mcp4726_set_cfg()
312 outbuf[0] |= data->powerdown << 1; in mcp4726_set_cfg()
313 outbuf[1] = data->dac_value >> 4; in mcp4726_set_cfg()
314 outbuf[2] = (data->dac_value & 0xf) << 4; in mcp4726_set_cfg()
316 ret = i2c_master_send(data->client, outbuf, 3); in mcp4726_set_cfg()
320 return -EIO; in mcp4726_set_cfg()
334 *val = data->dac_value; in mcp4725_read_raw()
337 if (data->ref_mode == MCP472X_REF_VDD) in mcp4725_read_raw()
338 ret = regulator_get_voltage(data->vdd_reg); in mcp4725_read_raw()
340 ret = regulator_get_voltage(data->vref_reg); in mcp4725_read_raw()
349 return -EINVAL; in mcp4725_read_raw()
362 data->dac_value = val; in mcp4725_write_raw()
365 ret = -EINVAL; in mcp4725_write_raw()
381 /* check if is the vref-supply defined */ in mcp4725_probe_dt()
382 pdata->use_vref = device_property_read_bool(dev, "vref-supply"); in mcp4725_probe_dt()
383 pdata->vref_buffered = in mcp4725_probe_dt()
384 device_property_read_bool(dev, "microchip,vref-buffered"); in mcp4725_probe_dt()
401 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in mcp4725_probe()
403 return -ENOMEM; in mcp4725_probe()
406 data->client = client; in mcp4725_probe()
408 pdata = dev_get_platdata(&client->dev); in mcp4725_probe()
411 err = mcp4725_probe_dt(&client->dev, &pdata_dt); in mcp4725_probe()
413 dev_err(&client->dev, in mcp4725_probe()
420 if (info->use_ext_ref_voltage && pdata->use_vref) { in mcp4725_probe()
421 dev_err(&client->dev, in mcp4725_probe()
423 return -EINVAL; in mcp4725_probe()
426 if (!pdata->use_vref && pdata->vref_buffered) { in mcp4725_probe()
427 dev_err(&client->dev, in mcp4725_probe()
429 return -EINVAL; in mcp4725_probe()
432 if (!pdata->use_vref) in mcp4725_probe()
433 data->ref_mode = MCP472X_REF_VDD; in mcp4725_probe()
435 data->ref_mode = pdata->vref_buffered ? in mcp4725_probe()
439 data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); in mcp4725_probe()
440 if (IS_ERR(data->vdd_reg)) in mcp4725_probe()
441 return PTR_ERR(data->vdd_reg); in mcp4725_probe()
443 err = regulator_enable(data->vdd_reg); in mcp4725_probe()
447 if (pdata->use_vref) { in mcp4725_probe()
448 data->vref_reg = devm_regulator_get(&client->dev, "vref"); in mcp4725_probe()
449 if (IS_ERR(data->vref_reg)) { in mcp4725_probe()
450 err = PTR_ERR(data->vref_reg); in mcp4725_probe()
454 err = regulator_enable(data->vref_reg); in mcp4725_probe()
459 indio_dev->name = id->name; in mcp4725_probe()
460 indio_dev->info = &mcp4725_info; in mcp4725_probe()
461 indio_dev->channels = info->chan_spec; in mcp4725_probe()
462 indio_dev->num_channels = 1; in mcp4725_probe()
463 indio_dev->modes = INDIO_DIRECT_MODE; in mcp4725_probe()
466 err = i2c_master_recv(client, inbuf, info->dac_reg_offset); in mcp4725_probe()
469 dev_err(&client->dev, "failed to read DAC value"); in mcp4725_probe()
473 data->powerdown = pd > 0; in mcp4725_probe()
474 data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */ in mcp4725_probe()
475 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4); in mcp4725_probe()
476 if (!info->use_ext_ref_voltage) in mcp4725_probe()
479 if (!info->use_ext_ref_voltage && ref != data->ref_mode) { in mcp4725_probe()
480 dev_info(&client->dev, in mcp4725_probe()
482 data->ref_mode, ref, data->ref_mode); in mcp4725_probe()
495 if (data->vref_reg) in mcp4725_probe()
496 regulator_disable(data->vref_reg); in mcp4725_probe()
499 regulator_disable(data->vdd_reg); in mcp4725_probe()
511 if (data->vref_reg) in mcp4725_remove()
512 regulator_disable(data->vref_reg); in mcp4725_remove()
513 regulator_disable(data->vdd_reg); in mcp4725_remove()
560 MODULE_DESCRIPTION("MCP4725/6 12-bit DAC");