From: Eduardo Valentin <eduardo.valentin@ti.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devel@driverdev.osuosl.org, linux-pm@vger.kernel.org,
linux-omap@vger.kernel.org, J Keerthy <j-keerthy@ti.com>,
Eduardo Valentin <eduardo.valentin@ti.com>
Subject: [PATCH 10/14] staging: ti-soc-thermal: Modify update_interval r/w functions to incorporate the OMAP5 feature of COUNTER_DELAY.
Date: Mon, 1 Apr 2013 12:04:42 -0400 [thread overview]
Message-ID: <1364832286-17304-11-git-send-email-eduardo.valentin@ti.com> (raw)
In-Reply-To: <1364832286-17304-1-git-send-email-eduardo.valentin@ti.com>
From: J Keerthy <j-keerthy@ti.com>
Update ti_bandgap_write_update_interval and ti_bandgap_read_update_interval
functions to incorporate the OMAP5 feature of COUNTER_DELAY. The way we
program the delay between two successive temperature conversions
is different for OMAP5 as when compared with OMAP4. Incorporating
the changes required to program the delay for OMAP5.
Signed-off-by: J Keerthy <j-keerthy@ti.com>
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>
---
drivers/staging/ti-soc-thermal/ti-bandgap.c | 165 +++++++++++++++++++++++---
1 files changed, 146 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/ti-soc-thermal/ti-bandgap.c b/drivers/staging/ti-soc-thermal/ti-bandgap.c
index 62ffea1..cc0c4ba 100644
--- a/drivers/staging/ti-soc-thermal/ti-bandgap.c
+++ b/drivers/staging/ti-soc-thermal/ti-bandgap.c
@@ -649,6 +649,68 @@ int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val)
}
/**
+ * ti_bandgap_read_counter() - read the sensor counter
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @interval: resulting update interval in miliseconds
+ */
+static void ti_bandgap_read_counter(struct ti_bandgap *bgp, int id,
+ int *interval)
+{
+ struct temp_sensor_registers *tsr;
+ int time;
+
+ tsr = bgp->conf->sensors[id].registers;
+ time = ti_bandgap_readl(bgp, tsr->bgap_counter);
+ time = (time & tsr->counter_mask) >>
+ __ffs(tsr->counter_mask);
+ time = time * 1000 / bgp->clk_rate;
+ *interval = time;
+}
+
+/**
+ * ti_bandgap_read_counter_delay() - read the sensor counter delay
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @interval: resulting update interval in miliseconds
+ */
+static void ti_bandgap_read_counter_delay(struct ti_bandgap *bgp, int id,
+ int *interval)
+{
+ struct temp_sensor_registers *tsr;
+ int reg_val;
+
+ tsr = bgp->conf->sensors[id].registers;
+
+ reg_val = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
+ reg_val = (reg_val & tsr->mask_counter_delay_mask) >>
+ __ffs(tsr->mask_counter_delay_mask);
+ switch (reg_val) {
+ case 0:
+ *interval = 0;
+ break;
+ case 1:
+ *interval = 1;
+ break;
+ case 2:
+ *interval = 10;
+ break;
+ case 3:
+ *interval = 100;
+ break;
+ case 4:
+ *interval = 250;
+ break;
+ case 5:
+ *interval = 500;
+ break;
+ default:
+ dev_warn(bgp->dev, "Wrong counter delay value read from register %X",
+ reg_val);
+ }
+}
+
+/**
* ti_bandgap_read_update_interval() - read the sensor update interval
* @bgp: pointer to bandgap instance
* @id: sensor id
@@ -659,28 +721,88 @@ int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val)
int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id,
int *interval)
{
- struct temp_sensor_registers *tsr;
- u32 time;
- int ret;
+ int ret = 0;
ret = ti_bandgap_validate(bgp, id);
if (ret)
- return ret;
+ goto exit;
- if (!TI_BANDGAP_HAS(bgp, COUNTER))
- return -ENOTSUPP;
+ if (!TI_BANDGAP_HAS(bgp, COUNTER) &&
+ !TI_BANDGAP_HAS(bgp, COUNTER_DELAY)) {
+ ret = -ENOTSUPP;
+ goto exit;
+ }
- tsr = bgp->conf->sensors[id].registers;
- time = ti_bandgap_readl(bgp, tsr->bgap_counter);
- time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask);
- time = time * 1000 / bgp->clk_rate;
+ if (TI_BANDGAP_HAS(bgp, COUNTER)) {
+ ti_bandgap_read_counter(bgp, id, interval);
+ goto exit;
+ }
- *interval = time;
+ ti_bandgap_read_counter_delay(bgp, id, interval);
+exit:
+ return ret;
+}
+
+/**
+ * ti_bandgap_write_counter_delay() - set the counter_delay
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @interval: desired update interval in miliseconds
+ *
+ * Return: 0 on success or the proper error code
+ */
+static int ti_bandgap_write_counter_delay(struct ti_bandgap *bgp, int id,
+ u32 interval)
+{
+ int rval;
+
+ switch (interval) {
+ case 0: /* Immediate conversion */
+ rval = 0x0;
+ break;
+ case 1: /* Conversion after ever 1ms */
+ rval = 0x1;
+ break;
+ case 10: /* Conversion after ever 10ms */
+ rval = 0x2;
+ break;
+ case 100: /* Conversion after ever 100ms */
+ rval = 0x3;
+ break;
+ case 250: /* Conversion after ever 250ms */
+ rval = 0x4;
+ break;
+ case 500: /* Conversion after ever 500ms */
+ rval = 0x5;
+ break;
+ default:
+ dev_warn(bgp->dev, "Delay %d ms is not supported\n", interval);
+ return -EINVAL;
+ }
+
+ spin_lock(&bgp->lock);
+ RMW_BITS(bgp, id, bgap_mask_ctrl, mask_counter_delay_mask, rval);
+ spin_unlock(&bgp->lock);
return 0;
}
/**
+ * ti_bandgap_write_counter() - set the bandgap sensor counter
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @interval: desired update interval in miliseconds
+ */
+static void ti_bandgap_write_counter(struct ti_bandgap *bgp, int id,
+ u32 interval)
+{
+ interval = interval * bgp->clk_rate / 1000;
+ spin_lock(&bgp->lock);
+ RMW_BITS(bgp, id, bgap_counter, counter_mask, interval);
+ spin_unlock(&bgp->lock);
+}
+
+/**
* ti_bandgap_write_update_interval() - set the update interval
* @bgp: pointer to bandgap instance
* @id: sensor id
@@ -693,17 +815,22 @@ int ti_bandgap_write_update_interval(struct ti_bandgap *bgp,
{
int ret = ti_bandgap_validate(bgp, id);
if (ret)
- return ret;
+ goto exit;
- if (!TI_BANDGAP_HAS(bgp, COUNTER))
- return -ENOTSUPP;
+ if (!TI_BANDGAP_HAS(bgp, COUNTER) &&
+ !TI_BANDGAP_HAS(bgp, COUNTER_DELAY)) {
+ ret = -ENOTSUPP;
+ goto exit;
+ }
- interval = interval * bgp->clk_rate / 1000;
- spin_lock(&bgp->lock);
- RMW_BITS(bgp, id, bgap_counter, counter_mask, interval);
- spin_unlock(&bgp->lock);
+ if (TI_BANDGAP_HAS(bgp, COUNTER)) {
+ ti_bandgap_write_counter(bgp, id, interval);
+ goto exit;
+ }
- return 0;
+ ret = ti_bandgap_write_counter_delay(bgp, id, interval);
+exit:
+ return ret;
}
/**
--
1.7.7.1.488.ge8e1c
next prev parent reply other threads:[~2013-04-01 16:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-01 16:04 [PATCH 00/14] staging: ti-soc-thermal: fixes and trending support Eduardo Valentin
2013-04-01 16:04 ` [PATCH 01/14] staging: ti-soc-thermal: return error in case power switch is not supported Eduardo Valentin
2013-04-01 16:04 ` [PATCH 02/14] staging: ti-soc-thermal: remove kernel-doc warnings reported with -v Eduardo Valentin
2013-04-01 16:04 ` [PATCH 03/14] staging: ti-soc-thermal: expose ti_thermal_report_temperature Eduardo Valentin
2013-04-01 16:04 ` [PATCH 04/14] staging: ti-soc-thermal: report alert events on OMAP4 devices Eduardo Valentin
2013-04-01 16:04 ` [PATCH 05/14] staging: ti-soc-thermal: report alert events on OMAP5 devices Eduardo Valentin
2013-04-01 16:04 ` [PATCH 06/14] staging: ti-soc-thermal: Add counter_delay_mask field to temp_sensor_registers struct Eduardo Valentin
2013-04-01 16:04 ` [PATCH 07/14] staging: ti-soc-thermal: Initialise counter_delay field for OMAP5 sensors Eduardo Valentin
2013-04-01 16:04 ` [PATCH 08/14] staging: ti-soc-thermal: Introduce HAS_COUNTER_DELAY feature for bandgap Eduardo Valentin
2013-04-01 16:04 ` [PATCH 09/14] staging: ti-soc-thermal: Enable COUNTER_DELAY feature for OMAP5 Eduardo Valentin
2013-04-01 16:04 ` Eduardo Valentin [this message]
2013-04-01 16:04 ` [PATCH 11/14] staging: ti-soc-thermal: Introduce HAS_HISTORY_BUFFER feature for bandgap Eduardo Valentin
2013-04-01 16:04 ` [PATCH 12/14] staging: ti-soc-thermal: Enable HISTORY_BUFFER Feature for OMAP5 Eduardo Valentin
2013-04-01 16:04 ` [PATCH 13/14] staging: ti-soc-thermal:Introduce ti_bandgap_get_trend function " Eduardo Valentin
2013-04-01 16:04 ` [PATCH 14/14] staging: ti-soc-thermal: Add get_trend support Eduardo Valentin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364832286-17304-11-git-send-email-eduardo.valentin@ti.com \
--to=eduardo.valentin@ti.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=j-keerthy@ti.com \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).