Lines Matching full:gpadc

3  * TWL6030 GPADC module driver
86 * struct twl6030_ideal_code - GPADC calibration parameters
87 * GPADC is calibrated in two points: close to the beginning and
108 * @nchannels: number of GPADC channels
122 int (*calibrate)(struct twl6030_gpadc_data *gpadc);
126 * struct twl6030_gpadc_data - GPADC data
385 struct twl6030_gpadc_data *gpadc = iio_priv(indio_dev); in twl6030_gpadc_irq_handler() local
387 complete(&gpadc->irq_complete); in twl6030_gpadc_irq_handler()
448 static int twl6030_gpadc_make_correction(struct twl6030_gpadc_data *gpadc, in twl6030_gpadc_make_correction() argument
451 const struct twl6030_ideal_code *ideal = gpadc->pdata->ideal; in twl6030_gpadc_make_correction()
455 i = twl6030_gpadc_lookup(ideal, channel, gpadc->pdata->nchannels); in twl6030_gpadc_make_correction()
457 gpadc->twl6030_cal_tbl[i].offset_error) / in twl6030_gpadc_make_correction()
458 gpadc->twl6030_cal_tbl[i].gain_error; in twl6030_gpadc_make_correction()
463 static int twl6030_gpadc_get_raw(struct twl6030_gpadc_data *gpadc, in twl6030_gpadc_get_raw() argument
466 u8 reg = gpadc->pdata->channel_to_reg(channel); in twl6030_gpadc_get_raw()
473 dev_dbg(gpadc->dev, "unable to read register 0x%X\n", reg); in twl6030_gpadc_get_raw()
478 dev_dbg(gpadc->dev, "GPADC raw code: %d", raw_code); in twl6030_gpadc_get_raw()
480 if (twl6030_channel_calibrated(gpadc->pdata, channel)) in twl6030_gpadc_get_raw()
481 *res = twl6030_gpadc_make_correction(gpadc, channel, raw_code); in twl6030_gpadc_get_raw()
488 static int twl6030_gpadc_get_processed(struct twl6030_gpadc_data *gpadc, in twl6030_gpadc_get_processed() argument
491 const struct twl6030_ideal_code *ideal = gpadc->pdata->ideal; in twl6030_gpadc_get_processed()
497 ret = twl6030_gpadc_get_raw(gpadc, channel, &corrected_code); in twl6030_gpadc_get_processed()
501 i = twl6030_gpadc_lookup(ideal, channel, gpadc->pdata->nchannels); in twl6030_gpadc_get_processed()
503 gpadc->twl6030_cal_tbl[i].gain; in twl6030_gpadc_get_processed()
508 dev_dbg(gpadc->dev, "GPADC corrected code: %d", corrected_code); in twl6030_gpadc_get_processed()
509 dev_dbg(gpadc->dev, "GPADC value: %d", channel_value); in twl6030_gpadc_get_processed()
520 struct twl6030_gpadc_data *gpadc = iio_priv(indio_dev); in twl6030_gpadc_read_raw() local
524 mutex_lock(&gpadc->lock); in twl6030_gpadc_read_raw()
526 ret = gpadc->pdata->start_conversion(chan->channel); in twl6030_gpadc_read_raw()
528 dev_err(gpadc->dev, "failed to start conversion\n"); in twl6030_gpadc_read_raw()
533 &gpadc->irq_complete, msecs_to_jiffies(5000)); in twl6030_gpadc_read_raw()
544 ret = twl6030_gpadc_get_raw(gpadc, chan->channel, val); in twl6030_gpadc_read_raw()
549 ret = twl6030_gpadc_get_processed(gpadc, chan->channel, val); in twl6030_gpadc_read_raw()
557 mutex_unlock(&gpadc->lock); in twl6030_gpadc_read_raw()
563 * The GPADC channels are calibrated using a two point calibration method.
573 static void twl6030_calibrate_channel(struct twl6030_gpadc_data *gpadc, in twl6030_calibrate_channel() argument
577 const struct twl6030_ideal_code *ideal = gpadc->pdata->ideal; in twl6030_calibrate_channel()
579 i = twl6030_gpadc_lookup(ideal, channel, gpadc->pdata->nchannels); in twl6030_calibrate_channel()
594 gpadc->twl6030_cal_tbl[i].gain = gain; in twl6030_calibrate_channel()
595 gpadc->twl6030_cal_tbl[i].gain_error = k; in twl6030_calibrate_channel()
596 gpadc->twl6030_cal_tbl[i].offset_error = b; in twl6030_calibrate_channel()
598 dev_dbg(gpadc->dev, "GPADC d1 for Chn: %d = %d\n", channel, d1); in twl6030_calibrate_channel()
599 dev_dbg(gpadc->dev, "GPADC d2 for Chn: %d = %d\n", channel, d2); in twl6030_calibrate_channel()
600 dev_dbg(gpadc->dev, "GPADC x1 for Chn: %d = %d\n", channel, x1); in twl6030_calibrate_channel()
601 dev_dbg(gpadc->dev, "GPADC x2 for Chn: %d = %d\n", channel, x2); in twl6030_calibrate_channel()
602 dev_dbg(gpadc->dev, "GPADC Gain for Chn: %d = %d\n", channel, gain); in twl6030_calibrate_channel()
603 dev_dbg(gpadc->dev, "GPADC k for Chn: %d = %d\n", channel, k); in twl6030_calibrate_channel()
604 dev_dbg(gpadc->dev, "GPADC b for Chn: %d = %d\n", channel, b); in twl6030_calibrate_channel()
621 static int twl6030_calibration(struct twl6030_gpadc_data *gpadc) in twl6030_calibration() argument
638 dev_err(gpadc->dev, "calibration failed\n"); in twl6030_calibration()
688 twl6030_calibrate_channel(gpadc, chn, d1, d2); in twl6030_calibration()
708 static int twl6032_calibration(struct twl6030_gpadc_data *gpadc) in twl6032_calibration() argument
717 dev_err(gpadc->dev, "calibration failed\n"); in twl6032_calibration()
723 * GPADC not values. in twl6032_calibration()
796 twl6030_calibrate_channel(gpadc, chn, d1, d2); in twl6032_calibration()
867 .compatible = "ti,twl6030-gpadc",
871 .compatible = "ti,twl6032-gpadc",
881 struct twl6030_gpadc_data *gpadc; in twl6030_gpadc_probe() local
891 indio_dev = devm_iio_device_alloc(dev, sizeof(*gpadc)); in twl6030_gpadc_probe()
895 gpadc = iio_priv(indio_dev); in twl6030_gpadc_probe()
897 gpadc->twl6030_cal_tbl = devm_kcalloc(dev, in twl6030_gpadc_probe()
899 sizeof(*gpadc->twl6030_cal_tbl), in twl6030_gpadc_probe()
901 if (!gpadc->twl6030_cal_tbl) in twl6030_gpadc_probe()
904 gpadc->dev = dev; in twl6030_gpadc_probe()
905 gpadc->pdata = pdata; in twl6030_gpadc_probe()
908 mutex_init(&gpadc->lock); in twl6030_gpadc_probe()
909 init_completion(&gpadc->irq_complete); in twl6030_gpadc_probe()
911 ret = pdata->calibrate(gpadc); in twl6030_gpadc_probe()
929 dev_err(dev, "failed to enable GPADC interrupt\n"); in twl6030_gpadc_probe()
936 dev_err(dev, "failed to enable GPADC module\n"); in twl6030_gpadc_probe()
984 dev_err(pdev, "error resetting GPADC (%d)!\n", ret); in twl6030_gpadc_suspend()
996 dev_err(pdev, "error setting GPADC (%d)!\n", ret); in twl6030_gpadc_resume()