aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo Valentin <eduardo.valentin@ti.com>2013-03-15 09:00:35 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-03-15 12:02:24 -0400
commitebf0bd52e657b41341bbfb0cbaabc308bf1c58e9 (patch)
tree59d0f6108e99b9ee416cefe869fa13fc55684cf4
parent1b46f2a239bfa3452179c8f1783f41ad1ff1833c (diff)
staging: omap-thermal: switch mutex to spinlock inside omap-bandgap
Because there is a need to lock inside IRQ handler, this patch changes the locking mechanism inside the omap-bandgap.[c,h] to spinlocks. Now this lock is used to protect omap_bandgap struct during APIs exposed (possibly used in sysfs handling functions) and inside the ALERT IRQ handler. Because there are registers shared among the sensors, this lock is global, not per sensor. Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/omap-thermal/TODO1
-rw-r--r--drivers/staging/omap-thermal/omap-bandgap.c18
-rw-r--r--drivers/staging/omap-thermal/omap-bandgap.h4
3 files changed, 12 insertions, 11 deletions
diff --git a/drivers/staging/omap-thermal/TODO b/drivers/staging/omap-thermal/TODO
index 77b761befe92..0f24e9b7555b 100644
--- a/drivers/staging/omap-thermal/TODO
+++ b/drivers/staging/omap-thermal/TODO
@@ -1,7 +1,6 @@
1List of TODOs (by Eduardo Valentin) 1List of TODOs (by Eduardo Valentin)
2 2
3on omap-bandgap.c: 3on omap-bandgap.c:
4- Rework locking
5- Improve driver code by adding usage of regmap-mmio 4- Improve driver code by adding usage of regmap-mmio
6- Test every exposed API to userland 5- Test every exposed API to userland
7- Add support to hwmon 6- Add support to hwmon
diff --git a/drivers/staging/omap-thermal/omap-bandgap.c b/drivers/staging/omap-thermal/omap-bandgap.c
index 4b631fd20e3a..846ced66d10c 100644
--- a/drivers/staging/omap-thermal/omap-bandgap.c
+++ b/drivers/staging/omap-thermal/omap-bandgap.c
@@ -33,7 +33,7 @@
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/types.h> 35#include <linux/types.h>
36#include <linux/mutex.h> 36#include <linux/spinlock.h>
37#include <linux/reboot.h> 37#include <linux/reboot.h>
38#include <linux/of_device.h> 38#include <linux/of_device.h>
39#include <linux/of_platform.h> 39#include <linux/of_platform.h>
@@ -170,6 +170,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)
170 u32 t_hot = 0, t_cold = 0, ctrl; 170 u32 t_hot = 0, t_cold = 0, ctrl;
171 int i; 171 int i;
172 172
173 spin_lock(&bg_ptr->lock);
173 for (i = 0; i < bg_ptr->conf->sensor_count; i++) { 174 for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
174 tsr = bg_ptr->conf->sensors[i].registers; 175 tsr = bg_ptr->conf->sensors[i].registers;
175 ctrl = omap_bandgap_readl(bg_ptr, tsr->bgap_status); 176 ctrl = omap_bandgap_readl(bg_ptr, tsr->bgap_status);
@@ -208,6 +209,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)
208 if (bg_ptr->conf->report_temperature) 209 if (bg_ptr->conf->report_temperature)
209 bg_ptr->conf->report_temperature(bg_ptr, i); 210 bg_ptr->conf->report_temperature(bg_ptr, i);
210 } 211 }
212 spin_unlock(&bg_ptr->lock);
211 213
212 return IRQ_HANDLED; 214 return IRQ_HANDLED;
213} 215}
@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val,
502 if (ret < 0) 504 if (ret < 0)
503 goto exit; 505 goto exit;
504 506
505 mutex_lock(&bg_ptr->bg_mutex); 507 spin_lock(&bg_ptr->lock);
506 omap_bandgap_update_alert_threshold(bg_ptr, id, adc_val, hot); 508 omap_bandgap_update_alert_threshold(bg_ptr, id, adc_val, hot);
507 mutex_unlock(&bg_ptr->bg_mutex); 509 spin_unlock(&bg_ptr->lock);
508 510
509exit: 511exit:
510 return ret; 512 return ret;
@@ -666,9 +668,9 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr,
666 return -ENOTSUPP; 668 return -ENOTSUPP;
667 669
668 interval = interval * bg_ptr->clk_rate / 1000; 670 interval = interval * bg_ptr->clk_rate / 1000;
669 mutex_lock(&bg_ptr->bg_mutex); 671 spin_lock(&bg_ptr->lock);
670 RMW_BITS(bg_ptr, id, bgap_counter, counter_mask, interval); 672 RMW_BITS(bg_ptr, id, bgap_counter, counter_mask, interval);
671 mutex_unlock(&bg_ptr->bg_mutex); 673 spin_unlock(&bg_ptr->lock);
672 674
673 return 0; 675 return 0;
674} 676}
@@ -691,9 +693,9 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,
691 if (ret) 693 if (ret)
692 return ret; 694 return ret;
693 695
694 mutex_lock(&bg_ptr->bg_mutex); 696 spin_lock(&bg_ptr->lock);
695 temp = omap_bandgap_read_temp(bg_ptr, id); 697 temp = omap_bandgap_read_temp(bg_ptr, id);
696 mutex_unlock(&bg_ptr->bg_mutex); 698 spin_unlock(&bg_ptr->lock);
697 699
698 ret |= omap_bandgap_adc_to_mcelsius(bg_ptr, temp, &temp); 700 ret |= omap_bandgap_adc_to_mcelsius(bg_ptr, temp, &temp);
699 if (ret) 701 if (ret)
@@ -1016,7 +1018,7 @@ int omap_bandgap_probe(struct platform_device *pdev)
1016 clk_prepare_enable(bg_ptr->fclock); 1018 clk_prepare_enable(bg_ptr->fclock);
1017 1019
1018 1020
1019 mutex_init(&bg_ptr->bg_mutex); 1021 spin_lock_init(&bg_ptr->lock);
1020 bg_ptr->dev = &pdev->dev; 1022 bg_ptr->dev = &pdev->dev;
1021 platform_set_drvdata(pdev, bg_ptr); 1023 platform_set_drvdata(pdev, bg_ptr);
1022 1024
diff --git a/drivers/staging/omap-thermal/omap-bandgap.h b/drivers/staging/omap-thermal/omap-bandgap.h
index edcc9652d53f..57005862d4f9 100644
--- a/drivers/staging/omap-thermal/omap-bandgap.h
+++ b/drivers/staging/omap-thermal/omap-bandgap.h
@@ -23,7 +23,7 @@
23#ifndef __OMAP_BANDGAP_H 23#ifndef __OMAP_BANDGAP_H
24#define __OMAP_BANDGAP_H 24#define __OMAP_BANDGAP_H
25 25
26#include <linux/mutex.h> 26#include <linux/spinlock.h>
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/err.h> 28#include <linux/err.h>
29 29
@@ -211,7 +211,7 @@ struct omap_bandgap {
211 struct omap_bandgap_data *conf; 211 struct omap_bandgap_data *conf;
212 struct clk *fclock; 212 struct clk *fclock;
213 struct clk *div_clk; 213 struct clk *div_clk;
214 struct mutex bg_mutex; /* shields this struct */ 214 spinlock_t lock; /* shields this struct */
215 int irq; 215 int irq;
216 int tshut_gpio; 216 int tshut_gpio;
217 u32 clk_rate; 217 u32 clk_rate;