Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2015-01-18 Thread Guenter Roeck

On 01/18/2015 12:33 PM, Pavel Machek wrote:


Pavel,

can you look into the omap4 thermal driver to see if it can be used ?


After some fixes... yes, it seems to be same hardware.


So this should be the way to go, but then we have others claim that
it should not be done because the OMAP3 sensors are too unreliable
to use for thermal decisions. Not really sure where that leaves us.
I am kind of opposed to have similar drivers for similar chips
in two different subsystems.

Is it possible to add the patch below to the omap thermal driver
and not use it for thermal decisions ?


Well... noone forces you to enable the driver, and I don't think it
will do any thermal decisions on N900 as it is ... so we should be ok.

Plus, it seems to work reasonably well (say +- 5 C), so situation does
not seem to be as bad as TI claims.

Nokia was actually using it in production.


Ok, I'll assume that omap3 support will be added to the omap thermal driver.

Thanks,
Guenter

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2015-01-18 Thread Pavel Machek
On Wed 2015-01-07 08:19:44, Guenter Roeck wrote:
 On Sat, Jan 03, 2015 at 10:18:58AM +0100, Pavel Machek wrote:
  On Mon 2014-12-29 11:04:48, Guenter Roeck wrote:
   On Mon, Dec 29, 2014 at 07:15:56PM +0100, Pavel Machek wrote:
On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
 On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas 
 nota...@gmail.com wrote:
  On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel 
  s...@kernel.org wrote:
  OMAP34xx and OMAP36xx processors contain a register in the syscon 
  area,
  which can be used to determine the SoCs temperature. This patch 
  provides
  a DT based driver for the temperature sensor based on an older 
  driver
  written by Peter De Schrijver for the Nokia N900 and N9.
 
  The sensor looks like an earlier iteration of sensors used in newer
  OMAPs, which are already supported by maybe
  drivers/thermal/ti-soc-thermal/ , maybe it would make sense to 
  update
  that driver instead?
 
 Just to be clear - OMAP4 is the first time that the sensors were
 reliable enough to be used.

When testing initial version of the patch, they seem to work very well
in the omap3 case.

   Pavel,
   
   can you look into the omap4 thermal driver to see if it can be used ?
  
  After some fixes... yes, it seems to be same hardware.
  
 So this should be the way to go, but then we have others claim that
 it should not be done because the OMAP3 sensors are too unreliable
 to use for thermal decisions. Not really sure where that leaves us.
 I am kind of opposed to have similar drivers for similar chips
 in two different subsystems.
 
 Is it possible to add the patch below to the omap thermal driver
 and not use it for thermal decisions ?

Well... noone forces you to enable the driver, and I don't think it
will do any thermal decisions on N900 as it is ... so we should be ok.

Plus, it seems to work reasonably well (say +- 5 C), so situation does
not seem to be as bad as TI claims.

Nokia was actually using it in production.

Best regards,
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2015-01-07 Thread Guenter Roeck
On Sat, Jan 03, 2015 at 10:18:58AM +0100, Pavel Machek wrote:
 On Mon 2014-12-29 11:04:48, Guenter Roeck wrote:
  On Mon, Dec 29, 2014 at 07:15:56PM +0100, Pavel Machek wrote:
   On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
wrote:
 On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org 
 wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon 
 area,
 which can be used to determine the SoCs temperature. This patch 
 provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.

 The sensor looks like an earlier iteration of sensors used in newer
 OMAPs, which are already supported by maybe
 drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
 that driver instead?

Just to be clear - OMAP4 is the first time that the sensors were
reliable enough to be used.
   
   When testing initial version of the patch, they seem to work very well
   in the omap3 case.
   
  Pavel,
  
  can you look into the omap4 thermal driver to see if it can be used ?
 
 After some fixes... yes, it seems to be same hardware.
 
So this should be the way to go, but then we have others claim that
it should not be done because the OMAP3 sensors are too unreliable
to use for thermal decisions. Not really sure where that leaves us.
I am kind of opposed to have similar drivers for similar chips
in two different subsystems.

Is it possible to add the patch below to the omap thermal driver
and not use it for thermal decisions ?

Guenter

 Signed-off-by: Pavel Machek pa...@ucw.cz
 
 diff --git a/drivers/thermal/ti-soc-thermal/Kconfig 
 b/drivers/thermal/ti-soc-thermal/Kconfig
 index bd4c7be..a49495f 100644
 --- a/drivers/thermal/ti-soc-thermal/Kconfig
 +++ b/drivers/thermal/ti-soc-thermal/Kconfig
 @@ -21,6 +21,15 @@ config TI_THERMAL
 This includes trip points definitions, extrapolation rules and
 CPU cooling device bindings.
  
 +config OMAP3_THERMAL
 + bool Texas Instruments OMAP3 thermal support
 + depends on TI_SOC_THERMAL
 + depends on ARCH_OMAP3
 + help
 +   If you say yes here you get thermal support for the Texas Instruments
 +   OMAP3 SoC family. The current chip supported are:
 +- OMAP3430
 +
  config OMAP4_THERMAL
   bool Texas Instruments OMAP4 thermal support
   depends on TI_SOC_THERMAL
 diff --git a/drivers/thermal/ti-soc-thermal/Makefile 
 b/drivers/thermal/ti-soc-thermal/Makefile
 index 1226b24..2b5b220 100644
 --- a/drivers/thermal/ti-soc-thermal/Makefile
 +++ b/drivers/thermal/ti-soc-thermal/Makefile
 @@ -2,5 +2,6 @@ obj-$(CONFIG_TI_SOC_THERMAL)  += ti-soc-thermal.o
  ti-soc-thermal-y := ti-bandgap.o
  ti-soc-thermal-$(CONFIG_TI_THERMAL)  += ti-thermal-common.o
  ti-soc-thermal-$(CONFIG_DRA752_THERMAL)  += dra752-thermal-data.o
 +ti-soc-thermal-$(CONFIG_OMAP3_THERMAL)  += omap3-thermal-data.o
  ti-soc-thermal-$(CONFIG_OMAP4_THERMAL)   += omap4-thermal-data.o
  ti-soc-thermal-$(CONFIG_OMAP5_THERMAL)   += omap5-thermal-data.o
 diff --git a/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c 
 b/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c
 new file mode 100644
 index 000..a79ebf2
 --- /dev/null
 +++ b/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c
 @@ -0,0 +1,99 @@
 +/*
 + * OMAP3 thermal driver.
 + *
 + * Copyright (C) 2011-2012 Texas Instruments Inc.
 + * Copyright (C) 2014 Pavel Machek pa...@ucw.cz
 + *
 + * This software is licensed under the terms of the GNU General Public
 + * License version 2, as published by the Free Software Foundation, and
 + * may be copied, distributed, and modified under those terms.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 + * GNU General Public License for more details.
 + *
 + */
 +
 +#include ti-thermal.h
 +#include ti-bandgap.h
 +
 +/*
 + * OMAP34XX has one instance of thermal sensor for MPU
 + * need to describe the individual bit fields
 + */
 +static struct temp_sensor_registers
 +omap34xx_mpu_temp_sensor_registers = {
 + .temp_sensor_ctrl = 0,
 + .bgap_tempsoff_mask = 0, /* Unused, we don't have POWER_SWITCH */
 + .bgap_soc_mask = BIT(8),
 + .bgap_eocz_mask = BIT(7),
 + .bgap_dtemp_mask = 0x7f,
 +
 + .bgap_mode_ctrl = 0,
 + .mode_ctrl_mask = 0,/* Unused, no MODE_CONFIG */
 +
 + .bgap_efuse = 0,
 +};
 +
 +/* Thresholds and limits for OMAP34XX MPU temperature sensor */
 +static struct temp_sensor_data omap34xx_mpu_temp_sensor_data = {
 + .min_freq = 32768,
 + .max_freq = 32768,
 + .max_temp = -99000,
 + .min_temp = 99000,
 + .hyst_val = 5000,
 +};
 +
 +/*
 + * Temperature values in milli 

Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2015-01-03 Thread Pavel Machek
On Mon 2014-12-29 11:04:48, Guenter Roeck wrote:
 On Mon, Dec 29, 2014 at 07:15:56PM +0100, Pavel Machek wrote:
  On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
   On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
   wrote:
On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org 
wrote:
OMAP34xx and OMAP36xx processors contain a register in the syscon area,
which can be used to determine the SoCs temperature. This patch 
provides
a DT based driver for the temperature sensor based on an older driver
written by Peter De Schrijver for the Nokia N900 and N9.
   
The sensor looks like an earlier iteration of sensors used in newer
OMAPs, which are already supported by maybe
drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
that driver instead?
   
   Just to be clear - OMAP4 is the first time that the sensors were
   reliable enough to be used.
  
  When testing initial version of the patch, they seem to work very well
  in the omap3 case.
  
 Pavel,
 
 can you look into the omap4 thermal driver to see if it can be used ?

After some fixes... yes, it seems to be same hardware.

Signed-off-by: Pavel Machek pa...@ucw.cz

diff --git a/drivers/thermal/ti-soc-thermal/Kconfig 
b/drivers/thermal/ti-soc-thermal/Kconfig
index bd4c7be..a49495f 100644
--- a/drivers/thermal/ti-soc-thermal/Kconfig
+++ b/drivers/thermal/ti-soc-thermal/Kconfig
@@ -21,6 +21,15 @@ config TI_THERMAL
  This includes trip points definitions, extrapolation rules and
  CPU cooling device bindings.
 
+config OMAP3_THERMAL
+   bool Texas Instruments OMAP3 thermal support
+   depends on TI_SOC_THERMAL
+   depends on ARCH_OMAP3
+   help
+ If you say yes here you get thermal support for the Texas Instruments
+ OMAP3 SoC family. The current chip supported are:
+  - OMAP3430
+
 config OMAP4_THERMAL
bool Texas Instruments OMAP4 thermal support
depends on TI_SOC_THERMAL
diff --git a/drivers/thermal/ti-soc-thermal/Makefile 
b/drivers/thermal/ti-soc-thermal/Makefile
index 1226b24..2b5b220 100644
--- a/drivers/thermal/ti-soc-thermal/Makefile
+++ b/drivers/thermal/ti-soc-thermal/Makefile
@@ -2,5 +2,6 @@ obj-$(CONFIG_TI_SOC_THERMAL)+= ti-soc-thermal.o
 ti-soc-thermal-y   := ti-bandgap.o
 ti-soc-thermal-$(CONFIG_TI_THERMAL)+= ti-thermal-common.o
 ti-soc-thermal-$(CONFIG_DRA752_THERMAL)+= dra752-thermal-data.o
+ti-soc-thermal-$(CONFIG_OMAP3_THERMAL)  += omap3-thermal-data.o
 ti-soc-thermal-$(CONFIG_OMAP4_THERMAL) += omap4-thermal-data.o
 ti-soc-thermal-$(CONFIG_OMAP5_THERMAL) += omap5-thermal-data.o
diff --git a/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c 
b/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c
new file mode 100644
index 000..a79ebf2
--- /dev/null
+++ b/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c
@@ -0,0 +1,99 @@
+/*
+ * OMAP3 thermal driver.
+ *
+ * Copyright (C) 2011-2012 Texas Instruments Inc.
+ * Copyright (C) 2014 Pavel Machek pa...@ucw.cz
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include ti-thermal.h
+#include ti-bandgap.h
+
+/*
+ * OMAP34XX has one instance of thermal sensor for MPU
+ * need to describe the individual bit fields
+ */
+static struct temp_sensor_registers
+omap34xx_mpu_temp_sensor_registers = {
+   .temp_sensor_ctrl = 0,
+   .bgap_tempsoff_mask = 0, /* Unused, we don't have POWER_SWITCH */
+   .bgap_soc_mask = BIT(8),
+   .bgap_eocz_mask = BIT(7),
+   .bgap_dtemp_mask = 0x7f,
+
+   .bgap_mode_ctrl = 0,
+   .mode_ctrl_mask = 0,/* Unused, no MODE_CONFIG */
+
+   .bgap_efuse = 0,
+};
+
+/* Thresholds and limits for OMAP34XX MPU temperature sensor */
+static struct temp_sensor_data omap34xx_mpu_temp_sensor_data = {
+   .min_freq = 32768,
+   .max_freq = 32768,
+   .max_temp = -99000,
+   .min_temp = 99000,
+   .hyst_val = 5000,
+};
+
+/*
+ * Temperature values in milli degree celsius
+ * ADC code values from 530 to 923
+ */
+static const int
+omap34xx_adc_to_temp[] = {
+   -4, -4, -4, -4, -4, -39000, -38000, -36000,
+   -34000, -32000, -31000, -29000, -28000, -26000, -25000, -24000,
+   -22000, -21000, -19000, -18000, -17000, -15000, -14000, -12000,
+   -11000, -9000, -8000, -7000, -5000, -4000, -2000, -1000, ,
+   1000, 3000, 4000, 5000, 7000, 8000, 1, 11000, 13000, 14000,
+   15000, 17000, 18000, 2, 21000, 22000, 24000, 25000, 27000,
+   28000, 3, 31000, 

Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2015-01-01 Thread Pavel Machek
On Mon 2014-12-29 11:04:48, Guenter Roeck wrote:
 On Mon, Dec 29, 2014 at 07:15:56PM +0100, Pavel Machek wrote:
  On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
   On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
   wrote:
On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org 
wrote:
OMAP34xx and OMAP36xx processors contain a register in the syscon area,
which can be used to determine the SoCs temperature. This patch 
provides
a DT based driver for the temperature sensor based on an older driver
written by Peter De Schrijver for the Nokia N900 and N9.
   
The sensor looks like an earlier iteration of sensors used in newer
OMAPs, which are already supported by maybe
drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
that driver instead?
   
   Just to be clear - OMAP4 is the first time that the sensors were
   reliable enough to be used.
  
  When testing initial version of the patch, they seem to work very well
  in the omap3 case.
  
 Pavel,
 
 can you look into the omap4 thermal driver to see if it can be used ?

The hardware seems similar, but omap4 has a lot more
features... Here's a test patch. It compiles and boots, but I'm too
far away from my working userland at this moment.

Best regards,
Pavel

commit 116612364f93b165b22166f0043117059eb3118f
Author: Pavel pa...@ucw.cz
Date:   Wed Dec 31 00:36:40 2014 +0100

Configure ti-soc-thermal to handle n900's thermal sensor.

diff --git a/.config b/.config
index b031e7f..4a79672 100644
--- a/.config
+++ b/.config
@@ -1671,7 +1671,23 @@ CONFIG_SENSORS_TWL4030_MADC=y
 # CONFIG_SENSORS_W83L786NG is not set
 # CONFIG_SENSORS_W83627HF is not set
 # CONFIG_SENSORS_W83627EHF is not set
-# CONFIG_THERMAL is not set
+CONFIG_THERMAL=y
+CONFIG_THERMAL_HWMON=y
+CONFIG_THERMAL_OF=y
+CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
+# CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE is not set
+# CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE is not set
+# CONFIG_THERMAL_GOV_FAIR_SHARE is not set
+CONFIG_THERMAL_GOV_STEP_WISE=y
+# CONFIG_THERMAL_GOV_BANG_BANG is not set
+# CONFIG_THERMAL_GOV_USER_SPACE is not set
+# CONFIG_CLOCK_THERMAL is not set
+# CONFIG_THERMAL_EMULATION is not set
+
+#
+# Texas Instruments thermal drivers
+#
+CONFIG_TI_SOC_THERMAL=y
 CONFIG_WATCHDOG=y
 CONFIG_WATCHDOG_CORE=y
 # CONFIG_WATCHDOG_NOWAYOUT is not set
diff --git a/arch/arm/boot/dts/omap3-n900.dts b/arch/arm/boot/dts/omap3-n900.dts
index 55e4928..dcbcaa9 100644
--- a/arch/arm/boot/dts/omap3-n900.dts
+++ b/arch/arm/boot/dts/omap3-n900.dts
@@ -29,6 +29,13 @@
};
};
 
+   bandgap: bandgap {
+   reg = 0x4a002524 0x4;
+   compatible = ti,omap34xx-bandgap;
+
+   #thermal-sensor-cells = 0;
+   };
+
leds {
compatible = gpio-leds;
heartbeat {
diff --git a/drivers/thermal/ti-soc-thermal/Makefile 
b/drivers/thermal/ti-soc-thermal/Makefile
index 1226b24..27ff2ed 100644
--- a/drivers/thermal/ti-soc-thermal/Makefile
+++ b/drivers/thermal/ti-soc-thermal/Makefile
@@ -2,5 +2,6 @@ obj-$(CONFIG_TI_SOC_THERMAL)+= ti-soc-thermal.o
 ti-soc-thermal-y   := ti-bandgap.o
 ti-soc-thermal-$(CONFIG_TI_THERMAL)+= ti-thermal-common.o
 ti-soc-thermal-$(CONFIG_DRA752_THERMAL)+= dra752-thermal-data.o
+ti-soc-thermal-y   += omap3-thermal-data.o
 ti-soc-thermal-$(CONFIG_OMAP4_THERMAL) += omap4-thermal-data.o
 ti-soc-thermal-$(CONFIG_OMAP5_THERMAL) += omap5-thermal-data.o
diff --git a/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c 
b/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c
new file mode 100644
index 000..7e25ccd
--- /dev/null
+++ b/drivers/thermal/ti-soc-thermal/omap3-thermal-data.c
@@ -0,0 +1,94 @@
+/*
+ * OMAP4 thermal driver.
+ *
+ * Copyright (C) 2011-2012 Texas Instruments Inc.
+ * Copyright (C) 2014 Pavel Machek pa...@ucw.cz
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include ti-thermal.h
+#include ti-bandgap.h
+
+/*
+ * OMAP34XX has one instance of thermal sensor for MPU
+ * need to describe the individual bit fields
+ */
+static struct temp_sensor_registers
+omap34xx_mpu_temp_sensor_registers = {
+   .temp_sensor_ctrl = 0,
+   .bgap_tempsoff_mask = 0, /* Unused, we don't have POWER_SWITCH */
+   .bgap_soc_mask = BIT(8),
+   .bgap_eocz_mask = BIT(7),
+   .bgap_dtemp_mask = 0x7f,
+
+   .bgap_mode_ctrl = 0,
+   

Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-30 Thread Pavel Machek
On Mon 2014-12-29 14:35:55, Nishanth Menon wrote:
 On 12/29/2014 12:15 PM, Pavel Machek wrote:
  On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
  On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
  wrote:
  On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org 
  wrote:
  OMAP34xx and OMAP36xx processors contain a register in the syscon area,
  which can be used to determine the SoCs temperature. This patch provides
  a DT based driver for the temperature sensor based on an older driver
  written by Peter De Schrijver for the Nokia N900 and N9.
 
  The sensor looks like an earlier iteration of sensors used in newer
  OMAPs, which are already supported by maybe
  drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
  that driver instead?
 
  Just to be clear - OMAP4 is the first time that the sensors were
  reliable enough to be used.
  
  When testing initial version of the patch, they seem to work very well
  in the omap3 case.
 
 Just be careful when you try to make thermal policy like decisions
 based on this sensor. Placement of the sensor w.r.t the actual logic

I guess we won't do that, certainly not anytime soon.

 Also notice http://www.ti.com/lit/er/sprz278f/sprz278f.pdf Advisory
 3.1.1.186 MMC OCP Clock Not Gated When Thermal Sensor Is Used I think
 there were accuracy issues at certain values etc.. So remember to do a
 off mode type PM tests as well before you consider requesting these to
 be merged.

Thanks a lot for a pointer. 3x 100uA power draw when you enable
temperature sensor, because it also errorneously enables MMC. I wonder
how the solution would look in the device tree...
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-30 Thread Pavel Machek
On Mon 2014-12-29 11:04:48, Guenter Roeck wrote:
 On Mon, Dec 29, 2014 at 07:15:56PM +0100, Pavel Machek wrote:
  On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
   On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
   wrote:
On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org 
wrote:
OMAP34xx and OMAP36xx processors contain a register in the syscon area,
which can be used to determine the SoCs temperature. This patch 
provides
a DT based driver for the temperature sensor based on an older driver
written by Peter De Schrijver for the Nokia N900 and N9.
   
The sensor looks like an earlier iteration of sensors used in newer
OMAPs, which are already supported by maybe
drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
that driver instead?
   
   Just to be clear - OMAP4 is the first time that the sensors were
   reliable enough to be used.
  
  When testing initial version of the patch, they seem to work very well
  in the omap3 case.
  
 Pavel,
 
 can you look into the omap4 thermal driver to see if it can be used ?

The hardware registers are named the same way...

Unfortunately, TI moves registers around with each release, and OMAP4
stuff is _way_ more complex and maze of ifdefs, too.

static struct temp_sensor_data omap4430_mpu_temp_sensor_data = {
.min_freq = OMAP4430_MIN_FREQ,
.max_freq = OMAP4430_MAX_FREQ,
.max_temp = OMAP4430_MAX_TEMP,
.min_temp = OMAP4430_MIN_TEMP,
.hyst_val = OMAP4430_HYST_VAL,
};

and each define used just once. Would be easier to read and modify if
the ifdefs were removed...

Best regards,
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-29 Thread Grazvydas Ignotas
On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.

The sensor looks like an earlier iteration of sensors used in newer
OMAPs, which are already supported by maybe
drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
that driver instead?

--
Grazvydas
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-29 Thread Nishanth Menon
On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com wrote:
 On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.

 The sensor looks like an earlier iteration of sensors used in newer
 OMAPs, which are already supported by maybe
 drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
 that driver instead?

Just to be clear - OMAP4 is the first time that the sensors were
reliable enough to be used.

---
Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-29 Thread Pavel Machek
On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
 On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com wrote:
  On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org wrote:
  OMAP34xx and OMAP36xx processors contain a register in the syscon area,
  which can be used to determine the SoCs temperature. This patch provides
  a DT based driver for the temperature sensor based on an older driver
  written by Peter De Schrijver for the Nokia N900 and N9.
 
  The sensor looks like an earlier iteration of sensors used in newer
  OMAPs, which are already supported by maybe
  drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
  that driver instead?
 
 Just to be clear - OMAP4 is the first time that the sensors were
 reliable enough to be used.

When testing initial version of the patch, they seem to work very well
in the omap3 case.

Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-29 Thread Guenter Roeck
On Mon, Dec 29, 2014 at 07:15:56PM +0100, Pavel Machek wrote:
 On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
  On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
  wrote:
   On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org 
   wrote:
   OMAP34xx and OMAP36xx processors contain a register in the syscon area,
   which can be used to determine the SoCs temperature. This patch provides
   a DT based driver for the temperature sensor based on an older driver
   written by Peter De Schrijver for the Nokia N900 and N9.
  
   The sensor looks like an earlier iteration of sensors used in newer
   OMAPs, which are already supported by maybe
   drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
   that driver instead?
  
  Just to be clear - OMAP4 is the first time that the sensors were
  reliable enough to be used.
 
 When testing initial version of the patch, they seem to work very well
 in the omap3 case.
 
Pavel,

can you look into the omap4 thermal driver to see if it can be used ?

Thanks,
Guenter
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-29 Thread Nishanth Menon
On 12/29/2014 12:15 PM, Pavel Machek wrote:
 On Mon 2014-12-29 12:01:03, Nishanth Menon wrote:
 On Mon, Dec 29, 2014 at 11:52 AM, Grazvydas Ignotas nota...@gmail.com 
 wrote:
 On Fri, Dec 26, 2014 at 2:34 PM, Sebastian Reichel s...@kernel.org wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.

 The sensor looks like an earlier iteration of sensors used in newer
 OMAPs, which are already supported by maybe
 drivers/thermal/ti-soc-thermal/ , maybe it would make sense to update
 that driver instead?

 Just to be clear - OMAP4 is the first time that the sensors were
 reliable enough to be used.
 
 When testing initial version of the patch, they seem to work very well
 in the omap3 case.

Just be careful when you try to make thermal policy like decisions
based on this sensor. Placement of the sensor w.r.t the actual logic
generating heat has to be a factor as well. If you are just looking
for an approximation temperature (thermometerish kind), you might be
ok with this. I am not sure we'd find any TI data around this.. just a
heads up.

Also notice http://www.ti.com/lit/er/sprz278f/sprz278f.pdf Advisory
3.1.1.186 MMC OCP Clock Not Gated When Thermal Sensor Is Used I think
there were accuracy issues at certain values etc.. So remember to do a
off mode type PM tests as well before you consider requesting these to
be merged.

-- 
Regards,
Nishanth Menon
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-28 Thread Guenter Roeck
On Sat, Dec 27, 2014 at 11:35:16PM +0100, Pavel Machek wrote:
 On Sat 2014-12-27 20:58:25, Pavel Machek wrote:
  On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
   OMAP34xx and OMAP36xx processors contain a register in the syscon area,
   which can be used to determine the SoCs temperature. This patch provides
   a DT based driver for the temperature sensor based on an older driver
   written by Peter De Schrijver for the Nokia N900 and N9.
   
   Signed-off-by: Sebastian Reichel s...@kernel.org
   ---
drivers/hwmon/Kconfig  |   8 ++
drivers/hwmon/Makefile |   1 +
drivers/hwmon/omap3-temp.c | 307 
   +
3 files changed, 316 insertions(+)
create mode 100644 drivers/hwmon/omap3-temp.c
  
  When it hangs, it loops here:
  
  do {
  regmap_read(data-syscon, SYSCON_TEMP_REG,temp_sensor_reg);
  if ((temp_sensor_reg  eocz_mask) == level)
 return true;
  printk(=);
  }
  while (ktime_us_delta(expire, ktime_get())  0);
 
 And this fixes the hang, and makes level handling more readable.
 
 Fix the timeout code, now it actually works. Driver still fails after
 a while.
 
 Signed-off-by: Pavel Machek pa...@ucw.cz
 
 diff --git a/drivers/hwmon/omap3-temp.c b/drivers/hwmon/omap3-temp.c
 index 8a69604..1b8c768 100644
 --- a/drivers/hwmon/omap3-temp.c
 +++ b/drivers/hwmon/omap3-temp.c
 @@ -130,9 +130,7 @@ static inline bool wait_for_eocz(struct omap3_temp_data 
 *data,
   ktime_t timeout, expire;
   u32 temp_sensor_reg, eocz_mask;
  
   eocz_mask = BIT(data-hwdata-eocz_bit);
 - level = 1;
 - level *= eocz_mask;
  
   expire = ktime_add_ns(ktime_get(), max_delay);
   timeout = ktime_set(0, min_delay);
 @@ -140,9 +141,9 @@ static inline bool wait_for_eocz(struct omap3_temp_data 
 *data,
   schedule_hrtimeout(timeout, HRTIMER_MODE_REL);
   do {
   regmap_read(data-syscon, SYSCON_TEMP_REG, temp_sensor_reg);
 - if ((temp_sensor_reg  eocz_mask) == level)
 + if (!!(temp_sensor_reg  eocz_mask) == level)
   return true;
 - } while (ktime_us_delta(expire, ktime_get())  0);
 + } while (ktime_after(expire, ktime_get()));
  
Does this have to be a hard loop, without sleep ? I am a bit concerned that it
may loop for more than a ms.

Other than that, I assume we'll see an updated version with the coding style
issues and hang-up problems fixed.

Thanks,
Guenter
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-28 Thread Sebastian Reichel
On Sun, Dec 28, 2014 at 12:24:47AM -0800, Guenter Roeck wrote:
 On Sat, Dec 27, 2014 at 11:35:16PM +0100, Pavel Machek wrote:
  On Sat 2014-12-27 20:58:25, Pavel Machek wrote:
   On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
OMAP34xx and OMAP36xx processors contain a register in the syscon area,
which can be used to determine the SoCs temperature. This patch provides
a DT based driver for the temperature sensor based on an older driver
written by Peter De Schrijver for the Nokia N900 and N9.

Signed-off-by: Sebastian Reichel s...@kernel.org
---
 drivers/hwmon/Kconfig  |   8 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/omap3-temp.c | 307 
+
 3 files changed, 316 insertions(+)
 create mode 100644 drivers/hwmon/omap3-temp.c
   
   When it hangs, it loops here:
   
   do {
   regmap_read(data-syscon, SYSCON_TEMP_REG,temp_sensor_reg);
   if ((temp_sensor_reg  eocz_mask) == level)
  return true;
   printk(=);
   }
   while (ktime_us_delta(expire, ktime_get())  0);
  
  And this fixes the hang, and makes level handling more readable.
  
  Fix the timeout code, now it actually works. Driver still fails after
  a while.
  
  Signed-off-by: Pavel Machek pa...@ucw.cz
  
  diff --git a/drivers/hwmon/omap3-temp.c b/drivers/hwmon/omap3-temp.c
  index 8a69604..1b8c768 100644
  --- a/drivers/hwmon/omap3-temp.c
  +++ b/drivers/hwmon/omap3-temp.c
  @@ -130,9 +130,7 @@ static inline bool wait_for_eocz(struct omap3_temp_data 
  *data,
  ktime_t timeout, expire;
  u32 temp_sensor_reg, eocz_mask;
   
  eocz_mask = BIT(data-hwdata-eocz_bit);
  -   level = 1;
  -   level *= eocz_mask;
   
  expire = ktime_add_ns(ktime_get(), max_delay);
  timeout = ktime_set(0, min_delay);
  @@ -140,9 +141,9 @@ static inline bool wait_for_eocz(struct omap3_temp_data 
  *data,
  schedule_hrtimeout(timeout, HRTIMER_MODE_REL);
  do {
  regmap_read(data-syscon, SYSCON_TEMP_REG, temp_sensor_reg);
  -   if ((temp_sensor_reg  eocz_mask) == level)
  +   if (!!(temp_sensor_reg  eocz_mask) == level)
  return true;
  -   } while (ktime_us_delta(expire, ktime_get())  0);
  +   } while (ktime_after(expire, ktime_get()));
   
 Does this have to be a hard loop, without sleep ? I am a bit concerned that it
 may loop for more than a ms.
 
 Other than that, I assume we'll see an updated version with the coding style
 issues and hang-up problems fixed.

I will send a v2 patchset with Pavels change requests. It may take a
few days though, since I'm currently at a conference (31C3).

-- Sebastian


signature.asc
Description: Digital signature


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-27 Thread Pavel Machek
Hi!


 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.
 
 Signed-off-by: Sebastian Reichel s...@kernel.org

I did clk_enable - clk_prepare_enable conversion, as described in
another email.

I got occasional error reading:

root@n900:~# cat /sys/class/hwmon/hwmon0/device/temp_input
20.0
root@n900:~# cat /sys/class/hwmon/hwmon0/device/temp_input
cat: /sys/class/hwmon/hwmon0/device/temp_input: Input/output error
root@n900:~# cat /sys/class/hwmon/hwmon0/device/temp_input
20.0

Nothing in dmesg. It takes few tries to reproduce..

On other attempt, it hung hard:

root@n900:~# cat /sys/class/hwmon/hwmon0/device/temp_input ; cat
/sys/class/hwmon/hwmon0/device/temp_input  ;cat
/sys/class/hwmon/hwmon0/device/temp_input ; cat
/sys/class/hwmon/hwmon0/device/temp_input
17.0
17.0
^[[A



^Z


^C^C^C

Best regards,
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-27 Thread Pavel Machek
On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.
 
 Signed-off-by: Sebastian Reichel s...@kernel.org

I'd suggest these cleanups... But I don't see why it would fail. (Aha,
and sorry for trailing whitespace, you'll probably need to delete it.)

Signed-off-by: Pavel Machek pa...@ucw.cz

diff --git a/drivers/hwmon/omap3-temp.c b/drivers/hwmon/omap3-temp.c
index afe1b5a..8a69604 100644
--- a/drivers/hwmon/omap3-temp.c
+++ b/drivers/hwmon/omap3-temp.c
@@ -35,21 +35,29 @@
 /* 32.768Khz clock speed in nano seconds */
 #define CLOCK_32K_SPEED_NS 30518
 
-/* minimum delay for EOCZ rise after SOC rise is
- * 11 cycles of the 32.768Khz clock */
+/*
+ * minimum delay for EOCZ rise after SOC rise is
+ * 11 cycles of the 32.768Khz clock
+ */
 #define EOCZ_MIN_RISING_DELAY (11 * CLOCK_32K_SPEED_NS)
 
-/* From docs, maximum delay for EOCZ rise after SOC rise is
+/*
+ * From docs, maximum delay for EOCZ rise after SOC rise is
  * 14 cycles of the 32.768Khz clock. But after some experiments,
- * 24 cycles as maximum is safer. */
+ * 24 cycles as maximum is safer.
+ */
 #define EOCZ_MAX_RISING_DELAY (24 * CLOCK_32K_SPEED_NS)
 
-/* minimum delay for EOCZ falling is
- * 36 cycles of the 32.768Khz clock */
+/*
+ * minimum delay for EOCZ falling is
+ * 36 cycles of the 32.768Khz clock 
+ */
 #define EOCZ_MIN_FALLING_DELAY (36 * CLOCK_32K_SPEED_NS)
 
-/* maximum delay for EOCZ falling is
- * 40 cycles of the 32.768Khz clock */
+/*
+ * maximum delay for EOCZ falling is
+ * 40 cycles of the 32.768Khz clock 
+ */
 #define EOCZ_MAX_FALLING_DELAY (40 * CLOCK_32K_SPEED_NS)
 
 /* temperature register offset in the syscon register area */
@@ -116,8 +124,8 @@ struct omap3_temp_data {
bool valid;
 };
 
-static inline u32 wait_for_eocz(int min_delay, int max_delay, u32 level,
-   struct omap3_temp_data *data)
+static inline bool wait_for_eocz(struct omap3_temp_data *data,
+int min_delay, int max_delay, u32 level)
 {
ktime_t timeout, expire;
u32 temp_sensor_reg, eocz_mask;
@@ -133,10 +141,10 @@ static inline u32 wait_for_eocz(int min_delay, int 
max_delay, u32 level,
do {
regmap_read(data-syscon, SYSCON_TEMP_REG, temp_sensor_reg);
if ((temp_sensor_reg  eocz_mask) == level)
-   break;
+   return true;
} while (ktime_us_delta(expire, ktime_get())  0);
 
-   return (temp_sensor_reg  eocz_mask) == level;
+   return false;
 }
 
 static int omap3_temp_update(struct omap3_temp_data *data)
@@ -153,16 +161,16 @@ static int omap3_temp_update(struct omap3_temp_data *data)
regmap_update_bits(data-syscon, SYSCON_TEMP_REG,
   soc_mask, soc_mask);
 
-   if (!wait_for_eocz(EOCZ_MIN_RISING_DELAY,
-   EOCZ_MAX_RISING_DELAY, 1, data)) {
+   if (!wait_for_eocz(data, EOCZ_MIN_RISING_DELAY,
+   EOCZ_MAX_RISING_DELAY, 1)) {
e = -EIO;
goto err;
}
 
regmap_update_bits(data-syscon, SYSCON_TEMP_REG, soc_mask, 0);
 
-   if (!wait_for_eocz(EOCZ_MIN_FALLING_DELAY,
-   EOCZ_MAX_FALLING_DELAY, 0, data)) {
+   if (!wait_for_eocz(data, EOCZ_MIN_FALLING_DELAY,
+   EOCZ_MAX_FALLING_DELAY, 0)) {
e = -EIO;
goto err;
}


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-27 Thread Pavel Machek
On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.
 
 Signed-off-by: Sebastian Reichel s...@kernel.org

When it hangs, it seems to hang here:

if (!wait_for_eocz(data, EOCZ_MIN_RISING_DELAY,
EOCZ_MAX_RISING_DELAY, 1)) {
e = -EIO;
goto
err;
}

...so wait does not seem to reliably wait.
Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-27 Thread Pavel Machek
On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.
 
 Signed-off-by: Sebastian Reichel s...@kernel.org
 ---
  drivers/hwmon/Kconfig  |   8 ++
  drivers/hwmon/Makefile |   1 +
  drivers/hwmon/omap3-temp.c | 307 
 +
  3 files changed, 316 insertions(+)
  create mode 100644 drivers/hwmon/omap3-temp.c

When it hangs, it loops here:

do {
regmap_read(data-syscon, SYSCON_TEMP_REG,temp_sensor_reg);
if ((temp_sensor_reg  eocz_mask) == level)
   return true;
printk(=);
}
while (ktime_us_delta(expire, ktime_get())  0);

Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-27 Thread Pavel Machek
On Sat 2014-12-27 20:58:25, Pavel Machek wrote:
 On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
  OMAP34xx and OMAP36xx processors contain a register in the syscon area,
  which can be used to determine the SoCs temperature. This patch provides
  a DT based driver for the temperature sensor based on an older driver
  written by Peter De Schrijver for the Nokia N900 and N9.
  
  Signed-off-by: Sebastian Reichel s...@kernel.org
  ---
   drivers/hwmon/Kconfig  |   8 ++
   drivers/hwmon/Makefile |   1 +
   drivers/hwmon/omap3-temp.c | 307 
  +
   3 files changed, 316 insertions(+)
   create mode 100644 drivers/hwmon/omap3-temp.c
 
 When it hangs, it loops here:
 
 do {
 regmap_read(data-syscon, SYSCON_TEMP_REG,temp_sensor_reg);
 if ((temp_sensor_reg  eocz_mask) == level)
return true;
 printk(=);
 }
 while (ktime_us_delta(expire, ktime_get())  0);

And this fixes the hang, and makes level handling more readable.

Fix the timeout code, now it actually works. Driver still fails after
a while.

Signed-off-by: Pavel Machek pa...@ucw.cz

diff --git a/drivers/hwmon/omap3-temp.c b/drivers/hwmon/omap3-temp.c
index 8a69604..1b8c768 100644
--- a/drivers/hwmon/omap3-temp.c
+++ b/drivers/hwmon/omap3-temp.c
@@ -130,9 +130,7 @@ static inline bool wait_for_eocz(struct omap3_temp_data 
*data,
ktime_t timeout, expire;
u32 temp_sensor_reg, eocz_mask;
 
eocz_mask = BIT(data-hwdata-eocz_bit);
-   level = 1;
-   level *= eocz_mask;
 
expire = ktime_add_ns(ktime_get(), max_delay);
timeout = ktime_set(0, min_delay);
@@ -140,9 +141,9 @@ static inline bool wait_for_eocz(struct omap3_temp_data 
*data,
schedule_hrtimeout(timeout, HRTIMER_MODE_REL);
do {
regmap_read(data-syscon, SYSCON_TEMP_REG, temp_sensor_reg);
-   if ((temp_sensor_reg  eocz_mask) == level)
+   if (!!(temp_sensor_reg  eocz_mask) == level)
return true;
-   } while (ktime_us_delta(expire, ktime_get())  0);
+   } while (ktime_after(expire, ktime_get()));
 
return false;
 }

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-27 Thread Pavel Machek
On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.
 
 Signed-off-by: Sebastian Reichel s...@kernel.org

As I mentioned before, this version stops working after a
while. Version I originally posted seems to work ok under same load.

Best regards,
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] hwmon: Driver for OMAP3 temperature sensor

2014-12-26 Thread Pavel Machek
On Fri 2014-12-26 13:34:53, Sebastian Reichel wrote:
 OMAP34xx and OMAP36xx processors contain a register in the syscon area,
 which can be used to determine the SoCs temperature. This patch provides
 a DT based driver for the temperature sensor based on an older driver
 written by Peter De Schrijver for the Nokia N900 and N9.
 
 Signed-off-by: Sebastian Reichel s...@kernel.org

 + if (!data-valid || time_after(jiffies, data-last_updated + HZ)) {
 + clk_enable(data-clk_32k);

This needs to be clk_prepare_enable()

 + regmap_update_bits(data-syscon, SYSCON_TEMP_REG,
 +soc_mask, soc_mask);
 +
 + if (!wait_for_eocz(EOCZ_MIN_RISING_DELAY,
 + EOCZ_MAX_RISING_DELAY, 1, data)) {
 + e = -EIO;
 + goto err;
 + }
 +
 + regmap_update_bits(data-syscon, SYSCON_TEMP_REG, soc_mask, 0);
 +
 + if (!wait_for_eocz(EOCZ_MIN_FALLING_DELAY,
 + EOCZ_MAX_FALLING_DELAY, 0, data)) {
 + e = -EIO;
 + goto err;
 + }
 +
 + regmap_read(data-syscon, SYSCON_TEMP_REG, temp_sensor_reg);
 + data-temperature = temp_sensor_reg  ((17) - 1);
 + data-last_updated = jiffies;
 + data-valid = true;
 +
 +err:
 + clk_disable(data-clk_32k);

And this clk_disable_unprepare().

Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html