提交 ebf0bd52 编写于 作者: E Eduardo Valentin 提交者: Greg Kroah-Hartman

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: NEduardo Valentin <eduardo.valentin@ti.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 1b46f2a2
List of TODOs (by Eduardo Valentin) List of TODOs (by Eduardo Valentin)
on omap-bandgap.c: on omap-bandgap.c:
- Rework locking
- Improve driver code by adding usage of regmap-mmio - Improve driver code by adding usage of regmap-mmio
- Test every exposed API to userland - Test every exposed API to userland
- Add support to hwmon - Add support to hwmon
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/mutex.h> #include <linux/spinlock.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
...@@ -170,6 +170,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data) ...@@ -170,6 +170,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)
u32 t_hot = 0, t_cold = 0, ctrl; u32 t_hot = 0, t_cold = 0, ctrl;
int i; int i;
spin_lock(&bg_ptr->lock);
for (i = 0; i < bg_ptr->conf->sensor_count; i++) { for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
tsr = bg_ptr->conf->sensors[i].registers; tsr = bg_ptr->conf->sensors[i].registers;
ctrl = omap_bandgap_readl(bg_ptr, tsr->bgap_status); 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,6 +209,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)
if (bg_ptr->conf->report_temperature) if (bg_ptr->conf->report_temperature)
bg_ptr->conf->report_temperature(bg_ptr, i); bg_ptr->conf->report_temperature(bg_ptr, i);
} }
spin_unlock(&bg_ptr->lock);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val, ...@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val,
if (ret < 0) if (ret < 0)
goto exit; goto exit;
mutex_lock(&bg_ptr->bg_mutex); spin_lock(&bg_ptr->lock);
omap_bandgap_update_alert_threshold(bg_ptr, id, adc_val, hot); omap_bandgap_update_alert_threshold(bg_ptr, id, adc_val, hot);
mutex_unlock(&bg_ptr->bg_mutex); spin_unlock(&bg_ptr->lock);
exit: exit:
return ret; return ret;
...@@ -666,9 +668,9 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr, ...@@ -666,9 +668,9 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr,
return -ENOTSUPP; return -ENOTSUPP;
interval = interval * bg_ptr->clk_rate / 1000; interval = interval * bg_ptr->clk_rate / 1000;
mutex_lock(&bg_ptr->bg_mutex); spin_lock(&bg_ptr->lock);
RMW_BITS(bg_ptr, id, bgap_counter, counter_mask, interval); RMW_BITS(bg_ptr, id, bgap_counter, counter_mask, interval);
mutex_unlock(&bg_ptr->bg_mutex); spin_unlock(&bg_ptr->lock);
return 0; return 0;
} }
...@@ -691,9 +693,9 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id, ...@@ -691,9 +693,9 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,
if (ret) if (ret)
return ret; return ret;
mutex_lock(&bg_ptr->bg_mutex); spin_lock(&bg_ptr->lock);
temp = omap_bandgap_read_temp(bg_ptr, id); temp = omap_bandgap_read_temp(bg_ptr, id);
mutex_unlock(&bg_ptr->bg_mutex); spin_unlock(&bg_ptr->lock);
ret |= omap_bandgap_adc_to_mcelsius(bg_ptr, temp, &temp); ret |= omap_bandgap_adc_to_mcelsius(bg_ptr, temp, &temp);
if (ret) if (ret)
...@@ -1016,7 +1018,7 @@ int omap_bandgap_probe(struct platform_device *pdev) ...@@ -1016,7 +1018,7 @@ int omap_bandgap_probe(struct platform_device *pdev)
clk_prepare_enable(bg_ptr->fclock); clk_prepare_enable(bg_ptr->fclock);
mutex_init(&bg_ptr->bg_mutex); spin_lock_init(&bg_ptr->lock);
bg_ptr->dev = &pdev->dev; bg_ptr->dev = &pdev->dev;
platform_set_drvdata(pdev, bg_ptr); platform_set_drvdata(pdev, bg_ptr);
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#ifndef __OMAP_BANDGAP_H #ifndef __OMAP_BANDGAP_H
#define __OMAP_BANDGAP_H #define __OMAP_BANDGAP_H
#include <linux/mutex.h> #include <linux/spinlock.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -211,7 +211,7 @@ struct omap_bandgap { ...@@ -211,7 +211,7 @@ struct omap_bandgap {
struct omap_bandgap_data *conf; struct omap_bandgap_data *conf;
struct clk *fclock; struct clk *fclock;
struct clk *div_clk; struct clk *div_clk;
struct mutex bg_mutex; /* shields this struct */ spinlock_t lock; /* shields this struct */
int irq; int irq;
int tshut_gpio; int tshut_gpio;
u32 clk_rate; u32 clk_rate;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册