Lines Matching +full:1 +full:st
53 #define ADRF6780_LO_EN_MSK BIT(1)
67 #define ADRF6780_ADC_EN_MSK BIT(1)
92 static int __adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg, in __adrf6780_spi_read() argument
98 st->data[0] = 0x80 | (reg << 1); in __adrf6780_spi_read()
99 st->data[1] = 0x0; in __adrf6780_spi_read()
100 st->data[2] = 0x0; in __adrf6780_spi_read()
102 t.rx_buf = &st->data[0]; in __adrf6780_spi_read()
103 t.tx_buf = &st->data[0]; in __adrf6780_spi_read()
106 ret = spi_sync_transfer(st->spi, &t, 1); in __adrf6780_spi_read()
110 *val = (get_unaligned_be24(&st->data[0]) >> 1) & GENMASK(15, 0); in __adrf6780_spi_read()
115 static int adrf6780_spi_read(struct adrf6780_state *st, unsigned int reg, in adrf6780_spi_read() argument
120 mutex_lock(&st->lock); in adrf6780_spi_read()
121 ret = __adrf6780_spi_read(st, reg, val); in adrf6780_spi_read()
122 mutex_unlock(&st->lock); in adrf6780_spi_read()
127 static int __adrf6780_spi_write(struct adrf6780_state *st, in __adrf6780_spi_write() argument
131 put_unaligned_be24((val << 1) | (reg << 17), &st->data[0]); in __adrf6780_spi_write()
133 return spi_write(st->spi, &st->data[0], 3); in __adrf6780_spi_write()
136 static int adrf6780_spi_write(struct adrf6780_state *st, unsigned int reg, in adrf6780_spi_write() argument
141 mutex_lock(&st->lock); in adrf6780_spi_write()
142 ret = __adrf6780_spi_write(st, reg, val); in adrf6780_spi_write()
143 mutex_unlock(&st->lock); in adrf6780_spi_write()
148 static int __adrf6780_spi_update_bits(struct adrf6780_state *st, in __adrf6780_spi_update_bits() argument
155 ret = __adrf6780_spi_read(st, reg, &data); in __adrf6780_spi_update_bits()
161 return __adrf6780_spi_write(st, reg, temp); in __adrf6780_spi_update_bits()
164 static int adrf6780_spi_update_bits(struct adrf6780_state *st, unsigned int reg, in adrf6780_spi_update_bits() argument
169 mutex_lock(&st->lock); in adrf6780_spi_update_bits()
170 ret = __adrf6780_spi_update_bits(st, reg, mask, val); in adrf6780_spi_update_bits()
171 mutex_unlock(&st->lock); in adrf6780_spi_update_bits()
176 static int adrf6780_read_adc_raw(struct adrf6780_state *st, unsigned int *read_val) in adrf6780_read_adc_raw() argument
180 mutex_lock(&st->lock); in adrf6780_read_adc_raw()
182 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_ADC_CONTROL, in adrf6780_read_adc_raw()
186 FIELD_PREP(ADRF6780_ADC_EN_MSK, 1) | in adrf6780_read_adc_raw()
187 FIELD_PREP(ADRF6780_ADC_CLOCK_EN_MSK, 1) | in adrf6780_read_adc_raw()
188 FIELD_PREP(ADRF6780_ADC_START_MSK, 1)); in adrf6780_read_adc_raw()
195 ret = __adrf6780_spi_read(st, ADRF6780_REG_ADC_OUTPUT, read_val); in adrf6780_read_adc_raw()
204 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_ADC_CONTROL, in adrf6780_read_adc_raw()
210 ret = __adrf6780_spi_read(st, ADRF6780_REG_ADC_OUTPUT, read_val); in adrf6780_read_adc_raw()
213 mutex_unlock(&st->lock); in adrf6780_read_adc_raw()
270 struct adrf6780_state *st = iio_priv(indio_dev); in adrf6780_write_raw() local
274 return adrf6780_spi_write(st, ADRF6780_REG_LINEARIZE, val); in adrf6780_write_raw()
278 return adrf6780_spi_update_bits(st, in adrf6780_write_raw()
283 return adrf6780_spi_update_bits(st, in adrf6780_write_raw()
300 struct adrf6780_state *st = iio_priv(indio_dev); in adrf6780_reg_access() local
303 return adrf6780_spi_read(st, reg, read_val); in adrf6780_reg_access()
305 return adrf6780_spi_write(st, reg, write_val); in adrf6780_reg_access()
317 .indexed = 1, \
324 .output = 1, \
325 .indexed = 1, \
332 .modified = 1, \
333 .output = 1, \
334 .indexed = 1, \
347 static int adrf6780_reset(struct adrf6780_state *st) in adrf6780_reset() argument
350 struct spi_device *spi = st->spi; in adrf6780_reset()
352 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_CONTROL, in adrf6780_reset()
354 FIELD_PREP(ADRF6780_SOFT_RESET_MSK, 1)); in adrf6780_reset()
360 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_CONTROL, in adrf6780_reset()
371 static int adrf6780_init(struct adrf6780_state *st) in adrf6780_init() argument
375 struct spi_device *spi = st->spi; in adrf6780_init()
378 ret = adrf6780_reset(st); in adrf6780_init()
382 ret = __adrf6780_spi_read(st, ADRF6780_REG_CONTROL, &chip_id); in adrf6780_init()
402 enable_reg = FIELD_PREP(ADRF6780_VGA_BUFFER_EN_MSK, st->vga_buff_en) | in adrf6780_init()
403 FIELD_PREP(ADRF6780_DETECTOR_EN_MSK, 1) | in adrf6780_init()
404 FIELD_PREP(ADRF6780_LO_BUFFER_EN_MSK, st->lo_buff_en) | in adrf6780_init()
405 FIELD_PREP(ADRF6780_IF_MODE_EN_MSK, st->if_mode_en) | in adrf6780_init()
406 FIELD_PREP(ADRF6780_IQ_MODE_EN_MSK, st->iq_mode_en) | in adrf6780_init()
407 FIELD_PREP(ADRF6780_LO_X2_EN_MSK, st->lo_x2_en) | in adrf6780_init()
408 FIELD_PREP(ADRF6780_LO_PPF_EN_MSK, st->lo_ppf_en) | in adrf6780_init()
409 FIELD_PREP(ADRF6780_LO_EN_MSK, st->lo_en) | in adrf6780_init()
410 FIELD_PREP(ADRF6780_UC_BIAS_EN_MSK, st->uc_bias_en); in adrf6780_init()
412 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_ENABLE, in adrf6780_init()
417 ret = __adrf6780_spi_update_bits(st, ADRF6780_REG_LO_PATH, in adrf6780_init()
419 FIELD_PREP(ADRF6780_LO_SIDEBAND_MSK, st->lo_sideband)); in adrf6780_init()
423 return __adrf6780_spi_update_bits(st, ADRF6780_REG_ADC_CONTROL, in adrf6780_init()
425 FIELD_PREP(ADRF6780_VDET_OUTPUT_SELECT_MSK, st->vdet_out_en)); in adrf6780_init()
428 static void adrf6780_properties_parse(struct adrf6780_state *st) in adrf6780_properties_parse() argument
430 struct spi_device *spi = st->spi; in adrf6780_properties_parse()
432 st->vga_buff_en = device_property_read_bool(&spi->dev, "adi,vga-buff-en"); in adrf6780_properties_parse()
433 st->lo_buff_en = device_property_read_bool(&spi->dev, "adi,lo-buff-en"); in adrf6780_properties_parse()
434 st->if_mode_en = device_property_read_bool(&spi->dev, "adi,if-mode-en"); in adrf6780_properties_parse()
435 st->iq_mode_en = device_property_read_bool(&spi->dev, "adi,iq-mode-en"); in adrf6780_properties_parse()
436 st->lo_x2_en = device_property_read_bool(&spi->dev, "adi,lo-x2-en"); in adrf6780_properties_parse()
437 st->lo_ppf_en = device_property_read_bool(&spi->dev, "adi,lo-ppf-en"); in adrf6780_properties_parse()
438 st->lo_en = device_property_read_bool(&spi->dev, "adi,lo-en"); in adrf6780_properties_parse()
439 st->uc_bias_en = device_property_read_bool(&spi->dev, "adi,uc-bias-en"); in adrf6780_properties_parse()
440 st->lo_sideband = device_property_read_bool(&spi->dev, "adi,lo-sideband"); in adrf6780_properties_parse()
441 st->vdet_out_en = device_property_read_bool(&spi->dev, "adi,vdet-out-en"); in adrf6780_properties_parse()
453 struct adrf6780_state *st; in adrf6780_probe() local
456 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adrf6780_probe()
460 st = iio_priv(indio_dev); in adrf6780_probe()
467 st->spi = spi; in adrf6780_probe()
469 adrf6780_properties_parse(st); in adrf6780_probe()
471 st->clkin = devm_clk_get_enabled(&spi->dev, "lo_in"); in adrf6780_probe()
472 if (IS_ERR(st->clkin)) in adrf6780_probe()
473 return dev_err_probe(&spi->dev, PTR_ERR(st->clkin), in adrf6780_probe()
476 mutex_init(&st->lock); in adrf6780_probe()
478 ret = adrf6780_init(st); in adrf6780_probe()
482 ret = devm_add_action_or_reset(&spi->dev, adrf6780_powerdown, st); in adrf6780_probe()