• Home
  • Raw
  • Download

Lines Matching refs:st

84 	struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));  in nau7802_show_scales()  local
87 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in nau7802_show_scales()
89 st->scale_avail[i]); in nau7802_show_scales()
111 static int nau7802_set_gain(struct nau7802_state *st, int gain) in nau7802_set_gain() argument
115 mutex_lock(&st->lock); in nau7802_set_gain()
116 st->conversion_count = 0; in nau7802_set_gain()
118 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL1); in nau7802_set_gain()
121 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1, in nau7802_set_gain()
126 mutex_unlock(&st->lock); in nau7802_set_gain()
131 static int nau7802_read_conversion(struct nau7802_state *st) in nau7802_read_conversion() argument
135 mutex_lock(&st->data_lock); in nau7802_read_conversion()
136 data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_ADC_B2); in nau7802_read_conversion()
139 st->last_value = data << 16; in nau7802_read_conversion()
141 data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_ADC_B1); in nau7802_read_conversion()
144 st->last_value |= data << 8; in nau7802_read_conversion()
146 data = i2c_smbus_read_byte_data(st->client, NAU7802_REG_ADC_B0); in nau7802_read_conversion()
149 st->last_value |= data; in nau7802_read_conversion()
151 st->last_value = sign_extend32(st->last_value, 23); in nau7802_read_conversion()
154 mutex_unlock(&st->data_lock); in nau7802_read_conversion()
162 static int nau7802_sync(struct nau7802_state *st) in nau7802_sync() argument
166 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_sync()
169 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, in nau7802_sync()
178 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_eoc_trigger() local
181 status = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_eoc_trigger()
188 if (nau7802_read_conversion(st) < 0) in nau7802_eoc_trigger()
196 if (st->conversion_count < NAU7802_MIN_CONVERSIONS) in nau7802_eoc_trigger()
197 st->conversion_count++; in nau7802_eoc_trigger()
198 if (st->conversion_count >= NAU7802_MIN_CONVERSIONS) in nau7802_eoc_trigger()
199 complete(&st->value_ok); in nau7802_eoc_trigger()
208 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_read_irq() local
211 reinit_completion(&st->value_ok); in nau7802_read_irq()
212 enable_irq(st->client->irq); in nau7802_read_irq()
214 nau7802_sync(st); in nau7802_read_irq()
217 ret = nau7802_read_conversion(st); in nau7802_read_irq()
222 ret = wait_for_completion_interruptible_timeout(&st->value_ok, in nau7802_read_irq()
230 disable_irq(st->client->irq); in nau7802_read_irq()
232 *val = st->last_value; in nau7802_read_irq()
237 disable_irq(st->client->irq); in nau7802_read_irq()
246 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_read_poll() local
249 nau7802_sync(st); in nau7802_read_poll()
252 ret = nau7802_read_conversion(st); in nau7802_read_poll()
262 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_read_poll()
267 if (st->sample_rate != NAU7802_SAMP_FREQ_320) in nau7802_read_poll()
271 ret = i2c_smbus_read_byte_data(st->client, in nau7802_read_poll()
277 ret = nau7802_read_conversion(st); in nau7802_read_poll()
280 if (st->conversion_count < NAU7802_MIN_CONVERSIONS) in nau7802_read_poll()
281 st->conversion_count++; in nau7802_read_poll()
282 } while (st->conversion_count < NAU7802_MIN_CONVERSIONS); in nau7802_read_poll()
284 *val = st->last_value; in nau7802_read_poll()
293 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_read_raw() local
298 mutex_lock(&st->lock); in nau7802_read_raw()
304 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL2); in nau7802_read_raw()
306 mutex_unlock(&st->lock); in nau7802_read_raw()
313 st->conversion_count = 0; in nau7802_read_raw()
314 ret = i2c_smbus_write_byte_data(st->client, in nau7802_read_raw()
317 NAU7802_CTRL2_CRS(st->sample_rate)); in nau7802_read_raw()
320 mutex_unlock(&st->lock); in nau7802_read_raw()
325 if (st->client->irq) in nau7802_read_raw()
330 mutex_unlock(&st->lock); in nau7802_read_raw()
334 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_CTRL1); in nau7802_read_raw()
342 *val = st->vref_mv; in nau7802_read_raw()
348 *val = nau7802_sample_freq_avail[st->sample_rate]; in nau7802_read_raw()
363 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_write_raw() local
368 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in nau7802_write_raw()
369 if (val2 == st->scale_avail[i]) in nau7802_write_raw()
370 return nau7802_set_gain(st, i); in nau7802_write_raw()
377 mutex_lock(&st->lock); in nau7802_write_raw()
378 st->sample_rate = i; in nau7802_write_raw()
379 st->conversion_count = 0; in nau7802_write_raw()
380 ret = i2c_smbus_write_byte_data(st->client, in nau7802_write_raw()
382 NAU7802_CTRL2_CRS(st->sample_rate)); in nau7802_write_raw()
383 mutex_unlock(&st->lock); in nau7802_write_raw()
414 struct nau7802_state *st; in nau7802_probe() local
425 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); in nau7802_probe()
429 st = iio_priv(indio_dev); in nau7802_probe()
437 st->client = client; in nau7802_probe()
440 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, in nau7802_probe()
446 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, in nau7802_probe()
456 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL); in nau7802_probe()
463 st->vref_mv = tmp; in nau7802_probe()
470 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, data); in nau7802_probe()
473 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_ADC_CTRL, 0x30); in nau7802_probe()
479 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1, in nau7802_probe()
486 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in nau7802_probe()
487 st->scale_avail[i] = (((u64)st->vref_mv) * 1000000000ULL) in nau7802_probe()
490 init_completion(&st->value_ok); in nau7802_probe()
525 st->sample_rate = NAU7802_SAMP_FREQ_320; in nau7802_probe()
526 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL2, in nau7802_probe()
527 NAU7802_CTRL2_CRS(st->sample_rate)); in nau7802_probe()
536 mutex_init(&st->lock); in nau7802_probe()
537 mutex_init(&st->data_lock); in nau7802_probe()
548 mutex_destroy(&st->lock); in nau7802_probe()
549 mutex_destroy(&st->data_lock); in nau7802_probe()
560 struct nau7802_state *st = iio_priv(indio_dev); in nau7802_remove() local
563 mutex_destroy(&st->lock); in nau7802_remove()
564 mutex_destroy(&st->data_lock); in nau7802_remove()