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
51 outbuf[0] = (data->powerdown_mode + 1) << 4; in mcp4725_suspend()
53 data->powerdown = true; in mcp4725_suspend()
55 return i2c_master_send(data->client, outbuf, 2); in mcp4725_suspend()
65 outbuf[0] = (data->dac_value >> 8) & 0xf; in mcp4725_resume()
66 outbuf[1] = data->dac_value & 0xff; in mcp4725_resume()
67 data->powerdown = false; in mcp4725_resume()
69 return i2c_master_send(data->client, outbuf, 2); in mcp4725_resume()
92 inoutbuf[0] |= data->ref_mode << 3; in mcp4725_store_eeprom()
93 inoutbuf[0] |= data->powerdown ? ((data->powerdown_mode + 1) << 1) : 0; in mcp4725_store_eeprom()
94 inoutbuf[1] = data->dac_value >> 4; in mcp4725_store_eeprom()
95 inoutbuf[2] = (data->dac_value & 0xf) << 4; in mcp4725_store_eeprom()
97 ret = i2c_master_send(data->client, inoutbuf, 3); in mcp4725_store_eeprom()
101 return -EIO; in mcp4725_store_eeprom()
104 while (tries--) { in mcp4725_store_eeprom()
106 ret = i2c_master_recv(data->client, inoutbuf, 3); in mcp4725_store_eeprom()
110 return -EIO; in mcp4725_store_eeprom()
117 dev_err(&data->client->dev, in mcp4725_store_eeprom()
118 "mcp4725_store_eeprom() failed, incomplete\n"); in mcp4725_store_eeprom()
119 return -EIO; in mcp4725_store_eeprom()
153 return data->powerdown_mode; in mcp4725_get_powerdown_mode()
161 data->powerdown_mode = mode; in mcp4725_set_powerdown_mode()
171 return sysfs_emit(buf, "%d\n", data->powerdown); in mcp4725_read_powerdown()
187 ret = mcp4725_suspend(&data->client->dev); in mcp4725_write_powerdown()
189 ret = mcp4725_resume(&data->client->dev); in mcp4725_write_powerdown()
272 return -EINVAL; in mcp4725_set_value()
277 ret = i2c_master_send(data->client, outbuf, 2); in mcp4725_set_value()
281 return -EIO; in mcp4725_set_value()
293 outbuf[0] |= data->ref_mode << 3; in mcp4726_set_cfg()
294 if (data->powerdown) in mcp4726_set_cfg()
295 outbuf[0] |= data->powerdown << 1; in mcp4726_set_cfg()
296 outbuf[1] = data->dac_value >> 4; in mcp4726_set_cfg()
297 outbuf[2] = (data->dac_value & 0xf) << 4; in mcp4726_set_cfg()
299 ret = i2c_master_send(data->client, outbuf, 3); in mcp4726_set_cfg()
303 return -EIO; in mcp4726_set_cfg()
317 *val = data->dac_value; in mcp4725_read_raw()
320 if (data->ref_mode == MCP472X_REF_VDD) in mcp4725_read_raw()
321 ret = regulator_get_voltage(data->vdd_reg); in mcp4725_read_raw()
323 ret = regulator_get_voltage(data->vref_reg); in mcp4725_read_raw()
332 return -EINVAL; in mcp4725_read_raw()
345 data->dac_value = val; in mcp4725_write_raw()
348 ret = -EINVAL; in mcp4725_write_raw()
364 /* check if is the vref-supply defined */ in mcp4725_probe_dt()
365 pdata->use_vref = device_property_read_bool(dev, "vref-supply"); in mcp4725_probe_dt()
366 pdata->vref_buffered = in mcp4725_probe_dt()
367 device_property_read_bool(dev, "microchip,vref-buffered"); in mcp4725_probe_dt()
383 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in mcp4725_probe()
385 return -ENOMEM; in mcp4725_probe()
388 data->client = client; in mcp4725_probe()
389 if (dev_fwnode(&client->dev)) in mcp4725_probe()
390 data->id = (uintptr_t)device_get_match_data(&client->dev); in mcp4725_probe()
392 data->id = id->driver_data; in mcp4725_probe()
393 pdata = dev_get_platdata(&client->dev); in mcp4725_probe()
396 err = mcp4725_probe_dt(&client->dev, &pdata_dt); in mcp4725_probe()
398 dev_err(&client->dev, in mcp4725_probe()
405 if (data->id == MCP4725 && pdata->use_vref) { in mcp4725_probe()
406 dev_err(&client->dev, in mcp4725_probe()
408 return -EINVAL; in mcp4725_probe()
411 if (!pdata->use_vref && pdata->vref_buffered) { in mcp4725_probe()
412 dev_err(&client->dev, in mcp4725_probe()
414 return -EINVAL; in mcp4725_probe()
417 if (!pdata->use_vref) in mcp4725_probe()
418 data->ref_mode = MCP472X_REF_VDD; in mcp4725_probe()
420 data->ref_mode = pdata->vref_buffered ? in mcp4725_probe()
424 data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); in mcp4725_probe()
425 if (IS_ERR(data->vdd_reg)) in mcp4725_probe()
426 return PTR_ERR(data->vdd_reg); in mcp4725_probe()
428 err = regulator_enable(data->vdd_reg); in mcp4725_probe()
432 if (pdata->use_vref) { in mcp4725_probe()
433 data->vref_reg = devm_regulator_get(&client->dev, "vref"); in mcp4725_probe()
434 if (IS_ERR(data->vref_reg)) { in mcp4725_probe()
435 err = PTR_ERR(data->vref_reg); in mcp4725_probe()
439 err = regulator_enable(data->vref_reg); in mcp4725_probe()
444 indio_dev->name = id->name; in mcp4725_probe()
445 indio_dev->info = &mcp4725_info; in mcp4725_probe()
446 indio_dev->channels = &mcp472x_channel[id->driver_data]; in mcp4725_probe()
447 indio_dev->num_channels = 1; in mcp4725_probe()
448 indio_dev->modes = INDIO_DIRECT_MODE; in mcp4725_probe()
451 err = i2c_master_recv(client, inbuf, data->id == MCP4725 ? 3 : 4); in mcp4725_probe()
454 dev_err(&client->dev, "failed to read DAC value"); in mcp4725_probe()
458 data->powerdown = pd > 0; in mcp4725_probe()
459 data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */ in mcp4725_probe()
460 data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4); in mcp4725_probe()
461 if (data->id == MCP4726) in mcp4725_probe()
464 if (data->id == MCP4726 && ref != data->ref_mode) { in mcp4725_probe()
465 dev_info(&client->dev, in mcp4725_probe()
467 data->ref_mode, ref, data->ref_mode); in mcp4725_probe()
480 if (data->vref_reg) in mcp4725_probe()
481 regulator_disable(data->vref_reg); in mcp4725_probe()
484 regulator_disable(data->vdd_reg); in mcp4725_probe()
496 if (data->vref_reg) in mcp4725_remove()
497 regulator_disable(data->vref_reg); in mcp4725_remove()
498 regulator_disable(data->vdd_reg); in mcp4725_remove()
534 MODULE_DESCRIPTION("MCP4725/6 12-bit DAC");