From 62ede3c85e9aac5923799f1e3f990265521da8d1 Mon Sep 17 00:00:00 2001 From: Jesse Gilles Date: Mon, 3 Oct 2011 11:01:29 -0500 Subject: add locking on adc read --- io-module/mts_io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 3fc59d9..fe7fcaf 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -1573,6 +1573,8 @@ static ssize_t mts_attr_show_adc(struct device *dev, return -ENOENT; } + mutex_lock(&mts_io_mutex); + // disable all channels and enable the one we want writel(0x0F, adc_base + ADC_CHDR_OFFSET); writel(chan_mask, adc_base + ADC_CHER_OFFSET); @@ -1586,7 +1588,12 @@ static ssize_t mts_attr_show_adc(struct device *dev, log_debug("ADC_SR EOC [%X]", value); } - return sprintf(buf, "%lu\n", (unsigned long) readl(adc_base + offset)); + // read result + value = readl(adc_base + offset); + + mutex_unlock(&mts_io_mutex); + + return sprintf(buf, "%lu\n", (unsigned long) value); } static struct device_attribute dev_attr_adc0 = { -- cgit v1.2.3