Lines Matching refs:st

85 	struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));  in nau7802_show_scales()  local
88 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in nau7802_show_scales()
90 st->scale_avail[i]); in nau7802_show_scales()
112 static int nau7802_set_gain(struct nau7802_state *st, int gain) in nau7802_set_gain() argument
116 mutex_lock(&st->lock); in nau7802_set_gain()
117 st->conversion_count = 0; in nau7802_set_gain()
119 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL1); in nau7802_set_gain()
122 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1, in nau7802_set_gain()
127 mutex_unlock(&st->lock); in nau7802_set_gain()
132 static int nau7802_read_conversion(struct nau7802_state *st) in nau7802_read_conversion() argument
136 mutex_lock(&st->data_lock); in nau7802_read_conversion()
137 data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_ADC_B2); in nau7802_read_conversion()
140 st->last_value = data << 16; in nau7802_read_conversion()
142 data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_ADC_B1); in nau7802_read_conversion()
145 st->last_value |= data << 8; in nau7802_read_conversion()
147 data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_ADC_B0); in nau7802_read_conversion()
150 st->last_value |= data; in nau7802_read_conversion()
152 st->last_value = sign_extend32(st->last_value, 23); in nau7802_read_conversion()
155 mutex_unlock(&st->data_lock); in nau7802_read_conversion()
163 static int nau7802_sync(struct nau7802_state *st) in nau7802_sync() argument
167 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_sync()
170 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, in nau7802_sync()
179 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_eoc_trigger() local
182 status = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_eoc_trigger()
189 if (nau7802_read_conversion(st) < 0) in nau7802_eoc_trigger()
197 if (st->conversion_count < NAU7802_MIN_CONVERSIONS) in nau7802_eoc_trigger()
198 st->conversion_count++; in nau7802_eoc_trigger()
199 if (st->conversion_count >= NAU7802_MIN_CONVERSIONS) in nau7802_eoc_trigger()
200 complete(&st->value_ok); in nau7802_eoc_trigger()
209 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_read_irq() local
212 reinit_completion(&st->value_ok); in nau7802_read_irq()
213 enable_irq(st->client->irq); in nau7802_read_irq()
215 nau7802_sync(st); in nau7802_read_irq()
218 ret = nau7802_read_conversion(st); in nau7802_read_irq()
223 ret = wait_for_completion_interruptible_timeout(&st->value_ok, in nau7802_read_irq()
231 disable_irq(st->client->irq); in nau7802_read_irq()
233 *val = st->last_value; in nau7802_read_irq()
238 disable_irq(st->client->irq); in nau7802_read_irq()
247 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_read_poll() local
250 nau7802_sync(st); in nau7802_read_poll()
253 ret = nau7802_read_conversion(st); in nau7802_read_poll()
263 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_read_poll()
268 if (st->sample_rate != NAU7802_SAMP_FREQ_320) in nau7802_read_poll()
272 ret = i2c_smbus_read_byte_data(st->client, in nau7802_read_poll()
278 ret = nau7802_read_conversion(st); in nau7802_read_poll()
281 if (st->conversion_count < NAU7802_MIN_CONVERSIONS) in nau7802_read_poll()
282 st->conversion_count++; in nau7802_read_poll()
283 } while (st->conversion_count < NAU7802_MIN_CONVERSIONS); in nau7802_read_poll()
285 *val = st->last_value; in nau7802_read_poll()
294 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_read_raw() local
299 mutex_lock(&st->lock); in nau7802_read_raw()
305 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL2); in nau7802_read_raw()
307 mutex_unlock(&st->lock); in nau7802_read_raw()
314 st->conversion_count = 0; in nau7802_read_raw()
315 ret = i2c_smbus_write_byte_data(st->client, in nau7802_read_raw()
318 NAU7802_CTRL2_CRS(st->sample_rate)); in nau7802_read_raw()
321 mutex_unlock(&st->lock); in nau7802_read_raw()
326 if (st->client->irq) in nau7802_read_raw()
331 mutex_unlock(&st->lock); in nau7802_read_raw()
335 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL1); in nau7802_read_raw()
343 *val = st->vref_mv; in nau7802_read_raw()
349 *val = nau7802_sample_freq_avail[st->sample_rate]; in nau7802_read_raw()
364 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_write_raw() local
369 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in nau7802_write_raw()
370 if (val2 == st->scale_avail[i]) in nau7802_write_raw()
371 return nau7802_set_gain(st, i); in nau7802_write_raw()
378 mutex_lock(&st->lock); in nau7802_write_raw()
379 st->sample_rate = i; in nau7802_write_raw()
380 st->conversion_count = 0; in nau7802_write_raw()
381 ret = i2c_smbus_write_byte_data(st->client, in nau7802_write_raw()
383 NAU7802_CTRL2_CRS(st->sample_rate)); in nau7802_write_raw()
384 mutex_unlock(&st->lock); in nau7802_write_raw()
414 struct nau7802_state *st; in nau7802_probe() local
419 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); in nau7802_probe()
423 st = iio_priv(indio_dev); in nau7802_probe()
429 st->client = client; in nau7802_probe()
432 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, in nau7802_probe()
438 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, in nau7802_probe()
448 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_probe()
455 st->vref_mv = tmp; in nau7802_probe()
462 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, data); in nau7802_probe()
465 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_ADC_CTRL, 0x30); in nau7802_probe()
471 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1, in nau7802_probe()
478 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in nau7802_probe()
479 st->scale_avail[i] = (((u64)st->vref_mv) * 1000000000ULL) in nau7802_probe()
482 init_completion(&st->value_ok); in nau7802_probe()
517 st->sample_rate = NAU7802_SAMP_FREQ_320; in nau7802_probe()
518 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL2, in nau7802_probe()
519 NAU7802_CTRL2_CRS(st->sample_rate)); in nau7802_probe()
528 mutex_init(&st->lock); in nau7802_probe()
529 mutex_init(&st->data_lock); in nau7802_probe()