aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2013-03-29 10:54:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-04-02 14:22:16 -0400
commitbeca9e767e27f756d6aed9a62665e3f73546aabb (patch)
treed182af55501a1b53b86fdb4e7d7ccf20acc11076 /drivers/iio
parente748783c55f074046134d2ef15a6e04dd467ecfc (diff)
iio: at91_adc: fix missing Sample and Hold time
On the at91_adc a minimal Sample and Hold Time is necessary for the ADC to guarantee the best converted final value between two channels selection. This time has to be programmed through the bitfield SHTIM in the Mode Register ADC_MR. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/at91_adc.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 7295bc5280bd..e5b88d5d3b59 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -52,6 +52,7 @@ struct at91_adc_state {
52 void __iomem *reg_base; 52 void __iomem *reg_base;
53 struct at91_adc_reg_desc *registers; 53 struct at91_adc_reg_desc *registers;
54 u8 startup_time; 54 u8 startup_time;
55 u8 sample_hold_time;
55 bool sleep_mode; 56 bool sleep_mode;
56 struct iio_trigger **trig; 57 struct iio_trigger **trig;
57 struct at91_adc_trigger *trigger_list; 58 struct at91_adc_trigger *trigger_list;
@@ -465,6 +466,9 @@ static int at91_adc_probe_dt(struct at91_adc_state *st,
465 } 466 }
466 st->startup_time = prop; 467 st->startup_time = prop;
467 468
469 prop = 0;
470 of_property_read_u32(node, "atmel,adc-sample-hold-time", &prop);
471 st->sample_hold_time = prop;
468 472
469 if (of_property_read_u32(node, "atmel,adc-vref", &prop)) { 473 if (of_property_read_u32(node, "atmel,adc-vref", &prop)) {
470 dev_err(&idev->dev, "Missing adc-vref property in the DT.\n"); 474 dev_err(&idev->dev, "Missing adc-vref property in the DT.\n");
@@ -578,7 +582,7 @@ static const struct iio_info at91_adc_info = {
578 582
579static int at91_adc_probe(struct platform_device *pdev) 583static int at91_adc_probe(struct platform_device *pdev)
580{ 584{
581 unsigned int prsc, mstrclk, ticks, adc_clk; 585 unsigned int prsc, mstrclk, ticks, adc_clk, shtim;
582 int ret; 586 int ret;
583 struct iio_dev *idev; 587 struct iio_dev *idev;
584 struct at91_adc_state *st; 588 struct at91_adc_state *st;
@@ -691,12 +695,21 @@ static int at91_adc_probe(struct platform_device *pdev)
691 */ 695 */
692 ticks = round_up((st->startup_time * adc_clk / 696 ticks = round_up((st->startup_time * adc_clk /
693 1000000) - 1, 8) / 8; 697 1000000) - 1, 8) / 8;
698 /*
699 * a minimal Sample and Hold Time is necessary for the ADC to guarantee
700 * the best converted final value between two channels selection
701 * The formula thus is : Sample and Hold Time = (shtim + 1) / ADCClock
702 */
703 shtim = round_up((st->sample_hold_time * adc_clk /
704 1000000) - 1, 1);
705
694 reg = AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL; 706 reg = AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL;
695 reg |= AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP; 707 reg |= AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP;
696 if (st->low_res) 708 if (st->low_res)
697 reg |= AT91_ADC_LOWRES; 709 reg |= AT91_ADC_LOWRES;
698 if (st->sleep_mode) 710 if (st->sleep_mode)
699 reg |= AT91_ADC_SLEEP; 711 reg |= AT91_ADC_SLEEP;
712 reg |= AT91_ADC_SHTIM_(shtim) & AT91_ADC_SHTIM;
700 at91_adc_writel(st, AT91_ADC_MR, reg); 713 at91_adc_writel(st, AT91_ADC_MR, reg);
701 714
702 /* Setup the ADC channels available on the board */ 715 /* Setup the ADC channels available on the board */