Lines Matching +full:1 +full:st

32 #define AD5791_ADDR_DAC0		1
38 #define AD5791_CTRL_RBUF BIT(1)
46 #define AD5791_LINCOMP_10_12 1
56 #define AD5791_SWCTRL_CLR BIT(1)
60 #define AD5791_DAC_PWRDN_3STATE 1
108 static int ad5791_spi_write(struct ad5791_state *st, u8 addr, u32 val) in ad5791_spi_write() argument
110 st->data[0].d32 = cpu_to_be32(AD5791_CMD_WRITE | in ad5791_spi_write()
114 return spi_write(st->spi, &st->data[0].d8[1], 3); in ad5791_spi_write()
117 static int ad5791_spi_read(struct ad5791_state *st, u8 addr, u32 *val) in ad5791_spi_read() argument
122 .tx_buf = &st->data[0].d8[1], in ad5791_spi_read()
125 .cs_change = 1, in ad5791_spi_read()
127 .tx_buf = &st->data[1].d8[1], in ad5791_spi_read()
128 .rx_buf = &st->data[2].d8[1], in ad5791_spi_read()
134 st->data[0].d32 = cpu_to_be32(AD5791_CMD_READ | in ad5791_spi_read()
136 st->data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP)); in ad5791_spi_read()
138 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); in ad5791_spi_read()
140 *val = be32_to_cpu(st->data[2].d32); in ad5791_spi_read()
153 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_get_powerdown_mode() local
155 return st->pwr_down_mode; in ad5791_get_powerdown_mode()
161 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_set_powerdown_mode() local
163 st->pwr_down_mode = mode; in ad5791_set_powerdown_mode()
178 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_read_dac_powerdown() local
180 return sysfs_emit(buf, "%d\n", st->pwr_down); in ad5791_read_dac_powerdown()
189 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_write_dac_powerdown() local
196 st->ctrl &= ~(AD5791_CTRL_OPGND | AD5791_CTRL_DACTRI); in ad5791_write_dac_powerdown()
198 if (st->pwr_down_mode == AD5791_DAC_PWRDN_6K) in ad5791_write_dac_powerdown()
199 st->ctrl |= AD5791_CTRL_OPGND; in ad5791_write_dac_powerdown()
200 else if (st->pwr_down_mode == AD5791_DAC_PWRDN_3STATE) in ad5791_write_dac_powerdown()
201 st->ctrl |= AD5791_CTRL_DACTRI; in ad5791_write_dac_powerdown()
203 st->pwr_down = pwr_down; in ad5791_write_dac_powerdown()
205 ret = ad5791_spi_write(st, AD5791_ADDR_CTRL, st->ctrl); in ad5791_write_dac_powerdown()
252 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_read_raw() local
258 ret = ad5791_spi_read(st, chan->address, val); in ad5791_read_raw()
265 *val = st->vref_mv; in ad5791_read_raw()
266 *val2 = (1 << chan->scan_type.realbits) - 1; in ad5791_read_raw()
269 val64 = (((u64)st->vref_neg_mv) << chan->scan_type.realbits); in ad5791_read_raw()
270 do_div(val64, st->vref_mv); in ad5791_read_raw()
294 .output = 1, \
295 .indexed = 1, \
323 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_write_raw() local
327 val &= GENMASK(chan->scan_type.realbits - 1, 0); in ad5791_write_raw()
330 return ad5791_spi_write(st, chan->address, val); in ad5791_write_raw()
346 struct ad5791_state *st; in ad5791_probe() local
350 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5791_probe()
353 st = iio_priv(indio_dev); in ad5791_probe()
354 st->reg_vdd = devm_regulator_get(&spi->dev, "vdd"); in ad5791_probe()
355 if (!IS_ERR(st->reg_vdd)) { in ad5791_probe()
356 ret = regulator_enable(st->reg_vdd); in ad5791_probe()
360 ret = regulator_get_voltage(st->reg_vdd); in ad5791_probe()
367 st->reg_vss = devm_regulator_get(&spi->dev, "vss"); in ad5791_probe()
368 if (!IS_ERR(st->reg_vss)) { in ad5791_probe()
369 ret = regulator_enable(st->reg_vss); in ad5791_probe()
373 ret = regulator_get_voltage(st->reg_vss); in ad5791_probe()
380 st->pwr_down = true; in ad5791_probe()
381 st->spi = spi; in ad5791_probe()
389 if (!IS_ERR(st->reg_vss) && !IS_ERR(st->reg_vdd)) { in ad5791_probe()
390 st->vref_mv = (pos_voltage_uv + neg_voltage_uv) / 1000; in ad5791_probe()
391 st->vref_neg_mv = neg_voltage_uv / 1000; in ad5791_probe()
393 st->vref_mv = pdata->vref_pos_mv + pdata->vref_neg_mv; in ad5791_probe()
394 st->vref_neg_mv = pdata->vref_neg_mv; in ad5791_probe()
399 ret = ad5791_spi_write(st, AD5791_ADDR_SW_CTRL, AD5791_SWCTRL_RESET); in ad5791_probe()
403 st->chip_info = &ad5791_chip_info_tbl[spi_get_device_id(spi) in ad5791_probe()
407 st->ctrl = AD5761_CTRL_LINCOMP(st->chip_info->get_lin_comp(st->vref_mv)) in ad5791_probe()
411 ret = ad5791_spi_write(st, AD5791_ADDR_CTRL, st->ctrl | in ad5791_probe()
421 indio_dev->num_channels = 1; in ad5791_probe()
422 indio_dev->name = spi_get_device_id(st->spi)->name; in ad5791_probe()
430 if (!IS_ERR(st->reg_vss)) in ad5791_probe()
431 regulator_disable(st->reg_vss); in ad5791_probe()
433 if (!IS_ERR(st->reg_vdd)) in ad5791_probe()
434 regulator_disable(st->reg_vdd); in ad5791_probe()
441 struct ad5791_state *st = iio_priv(indio_dev); in ad5791_remove() local
444 if (!IS_ERR(st->reg_vdd)) in ad5791_remove()
445 regulator_disable(st->reg_vdd); in ad5791_remove()
447 if (!IS_ERR(st->reg_vss)) in ad5791_remove()
448 regulator_disable(st->reg_vss); in ad5791_remove()