Lines Matching +full:1 +full:st
52 #define ADRF6780_LO_EN_MSK BIT(1)
66 #define ADRF6780_ADC_EN_MSK BIT(1)
91 static int __adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg, in __adrf6780_spi_read() argument
97 st->data[0] = 0x80 | (reg << 1); in __adrf6780_spi_read()
98 st->data[1] = 0x0; in __adrf6780_spi_read()
99 st->data[2] = 0x0; in __adrf6780_spi_read()
101 t.rx_buf = &st->data[0]; in __adrf6780_spi_read()
102 t.tx_buf = &st->data[0]; in __adrf6780_spi_read()
105 ret = spi_sync_transfer(st->spi, &t, 1); in __adrf6780_spi_read()
109 *val = (get_unaligned_be24(&st->data[0]) >> 1) & GENMASK(15, 0); in __adrf6780_spi_read()
114 static int adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg, in adrf6780_spi_read() argument
119 mutex_lock(&st->lock); in adrf6780_spi_read()
120 ret = __adrf6780_spi_read(st, reg, val); in adrf6780_spi_read()
121 mutex_unlock(&st->lock); in adrf6780_spi_read()
126 static int __adrf6780_spi_write(struct adrf6780_state *st, in __adrf6780_spi_write() argument
130 put_unaligned_be24((val << 1) | (reg << 17), &st->data[0]); in __adrf6780_spi_write()
132 return spi_write(st->spi, &st->data[0], 3); in __adrf6780_spi_write()
135 static int adrf6780_spi_write(struct adrf6780_state *st, unsigned int reg, in adrf6780_spi_write() argument
140 mutex_lock(&st->lock); in adrf6780_spi_write()
141 ret = __adrf6780_spi_write(st, reg, val); in adrf6780_spi_write()
142 mutex_unlock(&st->lock); in adrf6780_spi_write()
147 static int __adrf6780_spi_update_bits(struct adrf6780_state *st, in __adrf6780_spi_update_bits() argument
154 ret = __adrf6780_spi_read(st, reg, &data); in __adrf6780_spi_update_bits()
160 return __adrf6780_spi_write(st, reg, temp); in __adrf6780_spi_update_bits()
163 static int adrf6780_spi_update_bits(struct adrf6780_state *st, unsigned int reg, in adrf6780_spi_update_bits() argument
168 mutex_lock(&st->lock); in adrf6780_spi_update_bits()
169 ret = __adrf6780_spi_update_bits(st, reg, mask, val); in adrf6780_spi_update_bits()
170 mutex_unlock(&st->lock); in adrf6780_spi_update_bits()
175 static int adrf6780_read_adc_raw(struct adrf6780_state *st, unsigned int *read_val) in adrf6780_read_adc_raw() argument
179 mutex_lock(&st->lock); in adrf6780_read_adc_raw()
181 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_ADC_CONTROL, in adrf6780_read_adc_raw()
185 FIELD_PREP(ADRF6780_ADC_EN_MSK, 1) | in adrf6780_read_adc_raw()
186 FIELD_PREP(ADRF6780_ADC_CLOCK_EN_MSK, 1) | in adrf6780_read_adc_raw()
187 FIELD_PREP(ADRF6780_ADC_START_MSK, 1)); in adrf6780_read_adc_raw()
194 ret = __adrf6780_spi_read(st, ADRF6780_REG_ADC_OUTPUT, read_val); in adrf6780_read_adc_raw()
203 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_ADC_CONTROL, in adrf6780_read_adc_raw()
209 ret = __adrf6780_spi_read(st, ADRF6780_REG_ADC_OUTPUT, read_val); in adrf6780_read_adc_raw()
212 mutex_unlock(&st->lock); in adrf6780_read_adc_raw()
269 struct adrf6780_state *st = iio_priv(indio_dev); in adrf6780_write_raw() local
273 return adrf6780_spi_write(st, ADRF6780_REG_LINEARIZE, val); in adrf6780_write_raw()
277 return adrf6780_spi_update_bits(st, in adrf6780_write_raw()
282 return adrf6780_spi_update_bits(st, in adrf6780_write_raw()
299 struct adrf6780_state *st = iio_priv(indio_dev); in adrf6780_reg_access() local
302 return adrf6780_spi_read(st, reg, read_val); in adrf6780_reg_access()
304 return adrf6780_spi_write(st, reg, write_val); in adrf6780_reg_access()
316 .indexed = 1, \
323 .output = 1, \
324 .indexed = 1, \
331 .modified = 1, \
332 .output = 1, \
333 .indexed = 1, \
346 static int adrf6780_reset(struct adrf6780_state *st) in adrf6780_reset() argument
349 struct spi_device *spi = st->spi; in adrf6780_reset()
351 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_CONTROL, in adrf6780_reset()
353 FIELD_PREP(ADRF6780_SOFT_RESET_MSK, 1)); in adrf6780_reset()
359 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_CONTROL, in adrf6780_reset()
370 static int adrf6780_init(struct adrf6780_state *st) in adrf6780_init() argument
374 struct spi_device *spi = st->spi; in adrf6780_init()
377 ret = adrf6780_reset(st); in adrf6780_init()
381 ret = __adrf6780_spi_read(st, ADRF6780_REG_CONTROL, &chip_id); in adrf6780_init()
401 enable_reg = FIELD_PREP(ADRF6780_VGA_BUFFER_EN_MSK, st->vga_buff_en) | in adrf6780_init()
402 FIELD_PREP(ADRF6780_DETECTOR_EN_MSK, 1) | in adrf6780_init()
403 FIELD_PREP(ADRF6780_LO_BUFFER_EN_MSK, st->lo_buff_en) | in adrf6780_init()
404 FIELD_PREP(ADRF6780_IF_MODE_EN_MSK, st->if_mode_en) | in adrf6780_init()
405 FIELD_PREP(ADRF6780_IQ_MODE_EN_MSK, st->iq_mode_en) | in adrf6780_init()
406 FIELD_PREP(ADRF6780_LO_X2_EN_MSK, st->lo_x2_en) | in adrf6780_init()
407 FIELD_PREP(ADRF6780_LO_PPF_EN_MSK, st->lo_ppf_en) | in adrf6780_init()
408 FIELD_PREP(ADRF6780_LO_EN_MSK, st->lo_en) | in adrf6780_init()
409 FIELD_PREP(ADRF6780_UC_BIAS_EN_MSK, st->uc_bias_en); in adrf6780_init()
411 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_ENABLE, in adrf6780_init()
416 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_LO_PATH, in adrf6780_init()
418 FIELD_PREP(ADRF6780_LO_SIDEBAND_MSK, st->lo_sideband)); in adrf6780_init()
422 return __adrf6780_spi_update_bits(st, ADRF6780_REG_ADC_CONTROL, in adrf6780_init()
424 FIELD_PREP(ADRF6780_VDET_OUTPUT_SELECT_MSK, st->vdet_out_en)); in adrf6780_init()
427 static void adrf6780_properties_parse(struct adrf6780_state *st) in adrf6780_properties_parse() argument
429 struct spi_device *spi = st->spi; in adrf6780_properties_parse()
431 st->vga_buff_en = device_property_read_bool(&spi->dev, "adi,vga-buff-en"); in adrf6780_properties_parse()
432 st->lo_buff_en = device_property_read_bool(&spi->dev, "adi,lo-buff-en"); in adrf6780_properties_parse()
433 st->if_mode_en = device_property_read_bool(&spi->dev, "adi,if-mode-en"); in adrf6780_properties_parse()
434 st->iq_mode_en = device_property_read_bool(&spi->dev, "adi,iq-mode-en"); in adrf6780_properties_parse()
435 st->lo_x2_en = device_property_read_bool(&spi->dev, "adi,lo-x2-en"); in adrf6780_properties_parse()
436 st->lo_ppf_en = device_property_read_bool(&spi->dev, "adi,lo-ppf-en"); in adrf6780_properties_parse()
437 st->lo_en = device_property_read_bool(&spi->dev, "adi,lo-en"); in adrf6780_properties_parse()
438 st->uc_bias_en = device_property_read_bool(&spi->dev, "adi,uc-bias-en"); in adrf6780_properties_parse()
439 st->lo_sideband = device_property_read_bool(&spi->dev, "adi,lo-sideband"); in adrf6780_properties_parse()
440 st->vdet_out_en = device_property_read_bool(&spi->dev, "adi,vdet-out-en"); in adrf6780_properties_parse()
452 struct adrf6780_state *st; in adrf6780_probe() local
455 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adrf6780_probe()
459 st = iio_priv(indio_dev); in adrf6780_probe()
466 st->spi = spi; in adrf6780_probe()
468 adrf6780_properties_parse(st); in adrf6780_probe()
470 st->clkin = devm_clk_get_enabled(&spi->dev, "lo_in"); in adrf6780_probe()
471 if (IS_ERR(st->clkin)) in adrf6780_probe()
472 return dev_err_probe(&spi->dev, PTR_ERR(st->clkin), in adrf6780_probe()
475 mutex_init(&st->lock); in adrf6780_probe()
477 ret = adrf6780_init(st); in adrf6780_probe()
481 ret = devm_add_action_or_reset(&spi->dev, adrf6780_powerdown, st); in adrf6780_probe()