Skip to contentSkip to conversation

drivers/hwmon NTC Thermistor Initial

PATCH Superseded Donggeun Kim 3 participants 4 messages Jun 15, 2011

Subsystems (2)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v9 1/1 drivers/hwmon NTC Thermistor Initial

This patch adds support for NTC Thermistor series. In this release, the following thermistors are supported: NCP15WB473, NCP18WB473, NCP03WB473, and NCP15WL333. This driver is based on the datasheet of MURATA.

The driver in the patch does conversion from the raw ADC value (either voltage or resistence) to temperature. In order to use voltage values as input, the circuit schematics should be provided with the platform data. A compensation table for each type of thermistor is provided for the conversion.

--
Updates
v9
- remove unnecessary variables(mintemp, maxtemp) and checking lines for them v8
- remove compiler warning message
- update Documentation/hwmon/ntc_thermistor
- add EXPERIMENTAL Kconfig dependency
v7
- move header file location
- rename header and driver file
- style fixes
v6
- updated Documentation/hwmon/ntc
- style fixes
v5
- use binary search on sorted table
- removed unnecessary attributes
- style fixes
v4
- put in alphabetic order in Kconfig/Makefile
- handle additional error cases
- remove the exported function
v3
- style fixes
- removed symbol exports
- avoid divide-by-zero
- omitted files added (Kconfig/Makefile)
- removed unnecessary codes
- return error values, not default values for errors.
v2
- added Documentation/hwmon/ntc
- followed hwmon sysfs
- detached the monitoring service
(thank you for the comments, Guenter Roeck)

---
 Documentation/hwmon/ntc_thermistor           |   93 ++++++
 drivers/hwmon/Kconfig                        |   14 +
 drivers/hwmon/Makefile                       |    1 +
 drivers/hwmon/ntc_thermistor.c               |  453 ++++++++++++++++++++++++++
 include/linux/platform_data/ntc_thermistor.h |   53 +++
 5 files changed, 614 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hwmon/ntc_thermistor
 create mode 100644 drivers/hwmon/ntc_thermistor.c
 create mode 100644 include/linux/platform_data/ntc_thermistor.h
Documentation/hwmon/ntc_thermistor new file +92 -0
new file mode 100644
index 0000000..3bfda94
@@ -0,0 +1,93 @@
+Kernel driver ntc_thermistor
+========+
+Supported thermistors:
+* Murata NTC Thermistors NCP15WB473, NCP18WB473, NCP21WB473, NCP03WB473, NCP15WL333
+  Prefixes: 'ncp15wb473', 'ncp18wb473', 'ncp21wb473', 'ncp03wb473', 'ncp15wl333'
+  Datasheet: Publicly available at Murata
+
+Other NTC thermistors can be supported simply by adding compensation
+tables; e.g., NCP15WL333 support is added by the table ncpXXwl333.
+
+Authors:
+	MyungJoo Ham <[email protected]>
+
+Description
+-----------
+
+The NTC thermistor is a simple thermistor that requires users to provide the
+resistance and lookup the corresponding compensation table to get the
+temperature input.
+
+The NTC driver provides lookup tables with a linear approximation function
+and four circuit models with an option not to use any of the four models.
+
+The four circuit models provided are:
+
+	$: resister, [TH]: the thermistor
+
+ 1. connect = NTC_CONNECTED_POSITIVE, pullup_ohm > 0
+
+   [pullup_uV]
+       |    |
+      [TH]  $ (pullup_ohm)
+       |    |
+       +----+-----------------------[read_uV]
+       |
+       $ (pulldown_ohm)
+       |
+      --- (ground)
+
+ 2. connect = NTC_CONNECTED_POSITIVE, pullup_ohm = 0 (not-connected)
+
+   [pullup_uV]
+       |
+      [TH]
+       |
+       +----------------------------[read_uV]
+       |
+       $ (pulldown_ohm)
+       |
+      --- (ground)
+
+ 3. connect = NTC_CONNECTED_GROUND, pulldown_ohm > 0
+
+   [pullup_uV]
+       |
+       $ (pullup_ohm)
+       |
+       +----+-----------------------[read_uV]
+       |    |
+      [TH]  $ (pulldown_ohm)
+       |    |
+      -------- (ground)
+
+ 4. connect = NTC_CONNECTED_GROUND, pulldown_ohm = 0 (not-connected)
+
+   [pullup_uV]
+       |
+       $ (pullup_ohm)
+       |
+       +----------------------------[read_uV]
+       |
+      [TH]
+       |
+      --- (ground)
+
+When one of the four circuit models is used, read_uV, pullup_uV, pullup_ohm,
+pulldown_ohm, and connect should be provided. When none of the four models
+are suitable or the user can get the resistance directly, the user should
+provide read_ohm and _not_ provide the others.
+
+Sysfs Interface
+---------------
+name		the mandatory global attribute, the thermistor name.
+
+temp1_type	always 4 (thermistor)
+		RO
+
+temp1_input	measure the temperature and provide the measured value.
+		(reading this file initiates the reading procedure.)
+		RO
+
+Note that each NTC thermistor has only _one_ thermistor; thus, only temp1 exists.
drivers/hwmon/Kconfig +14 -0
index 16db83c..1e6e8a0 100644
@@ -767,6 +767,20 @@ config SENSORS_MAX6650
 	  This driver can also be built as a module.  If so, the module
 	  will be called max6650.
 
+config SENSORS_NTC_THERMISTOR
+	tristate "NTC thermistor support"
+	depends on EXPERIMENTAL
+	help
+	  This driver supports NTC thermistors sensor reading and its
+	  interpretation. The driver can also monitor the temperature and
+	  send notifications about the temperature.
+
+	  Currently, this driver supports
+	  NCP15WB473, NCP18WB473, NCP21WB473, NCP03WB473, and NCP15WL333.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ntc-thermistor.
+
 config SENSORS_PC87360
 	tristate "National Semiconductor PC87360 family"
 	select HWMON_VID
drivers/hwmon/Makefile +1 -0
index 28061cf..e4ab597 100644
@@ -91,6 +91,7 @@ obj-$(CONFIG_SENSORS_MAX6639)	+= max6639.o
 obj-$(CONFIG_SENSORS_MAX6642)	+= max6642.o
 obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
+obj-$(CONFIG_SENSORS_NTC_THERMISTOR)	+= ntc_thermistor.o
 obj-$(CONFIG_SENSORS_PC87360)	+= pc87360.o
 obj-$(CONFIG_SENSORS_PC87427)	+= pc87427.o
 obj-$(CONFIG_SENSORS_PCF8591)	+= pcf8591.o
drivers/hwmon/ntc_thermistor.c new file +453 -0

453 lines not on this page · raw message

include/linux/platform_data/ntc_thermistor.h new file +53 -0

53 lines not on this page · raw message

Signature · 7 lines
1.7.4.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Hi ,
Not a comment really was a bit curious. Feel free to ignore such comments.

Quoted 63 lines · Donggeun Kim

This patch adds support for NTC Thermistor series. In this release, the following thermistors are supported: NCP15WB473, NCP18WB473, NCP03WB473, and NCP15WL333. This driver is based on the datasheet of MURATA.

The driver in the patch does conversion from the raw ADC value (either voltage or resistence) to temperature. In order to use voltage values as input, the circuit schematics should be provided with the platform data. A compensation table for each type of thermistor is provided for the conversion.

--
Updates
v9
- remove unnecessary variables(mintemp, maxtemp) and checking lines for them
v8
- remove compiler warning message
- update Documentation/hwmon/ntc_thermistor
- add EXPERIMENTAL Kconfig dependency
v7
- move header file location
- rename header and driver file
- style fixes
v6
- updated Documentation/hwmon/ntc
- style fixes
v5
- use binary search on sorted table
- removed unnecessary attributes
- style fixes
v4
- put in alphabetic order in Kconfig/Makefile
- handle additional error cases
- remove the exported function
v3
- style fixes
- removed symbol exports
- avoid divide-by-zero
- omitted files added (Kconfig/Makefile)
- removed unnecessary codes
- return error values, not default values for errors.
v2
- added Documentation/hwmon/ntc
- followed hwmon sysfs
- detached the monitoring service
(thank you for the comments, Guenter Roeck)

---
 Documentation/hwmon/ntc_thermistor           |   93 ++++++
 drivers/hwmon/Kconfig                        |   14 +
 drivers/hwmon/Makefile                       |    1 +
 drivers/hwmon/ntc_thermistor.c               |  453
++++++++++++++++++++++++++
 include/linux/platform_data/ntc_thermistor.h |   53 +++
 5 files changed, 614 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hwmon/ntc_thermistor
 create mode 100644 drivers/hwmon/ntc_thermistor.c
 create mode 100644 include/linux/platform_data/ntc_thermistor.h
Quoted 1 line

<snip>

Why have a function starting with a _

drivers/hwmon/ntc_thermistor.c line 254

Quoted 9 lines
drivers/hwmon/ntc_thermistor.c new file +8 -0
+static int _ntc_thermistor_read(struct ntc_data *data, int *temp)
+{
+       int ret;
+       int read_ohm, read_uV;
+       unsigned int ohm = 0;
+
+       if (data->pdata->read_ohm) {
+               read_ohm = data->pdata->read_ohm();

Is the platform function posted? What errors could these functions return ? Should we mask the errors here?

drivers/hwmon/ntc_thermistor.c line 261

Quoted 8 lines
drivers/hwmon/ntc_thermistor.c new file +7 -0
+               if (read_ohm < 0)
+                       return -EINVAL;
+               ohm = (unsigned int)read_ohm;
+       }
+
+       if (data->pdata->read_uV) {
+               read_uV = data->pdata->read_uV();

same here

drivers/hwmon/ntc_thermistor.c line 266

Quoted 6 lines
drivers/hwmon/ntc_thermistor.c new file +5 -0
+               if (read_uV < 0)
+                       return -EINVAL;
+               ohm = get_ohm_of_thermistor(data, (unsigned int)read_uV);
+       }
+

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Donggeun Kim

Hi,

Quoted 75 lines · Shubhrajyoti Datta

Hi ,
Not a comment really was a bit curious. Feel free to ignore such comments.

Quoted 63 lines · Donggeun Kim

This patch adds support for NTC Thermistor series. In this release, the following thermistors are supported: NCP15WB473, NCP18WB473, NCP03WB473, and NCP15WL333. This driver is based on the datasheet of MURATA.

The driver in the patch does conversion from the raw ADC value (either voltage or resistence) to temperature. In order to use voltage values as input, the circuit schematics should be provided with the platform data. A compensation table for each type of thermistor is provided for the conversion.

--
Updates
v9
- remove unnecessary variables(mintemp, maxtemp) and checking lines for them
v8
- remove compiler warning message
- update Documentation/hwmon/ntc_thermistor
- add EXPERIMENTAL Kconfig dependency
v7
- move header file location
- rename header and driver file
- style fixes
v6
- updated Documentation/hwmon/ntc
- style fixes
v5
- use binary search on sorted table
- removed unnecessary attributes
- style fixes
v4
- put in alphabetic order in Kconfig/Makefile
- handle additional error cases
- remove the exported function
v3
- style fixes
- removed symbol exports
- avoid divide-by-zero
- omitted files added (Kconfig/Makefile)
- removed unnecessary codes
- return error values, not default values for errors.
v2
- added Documentation/hwmon/ntc
- followed hwmon sysfs
- detached the monitoring service
(thank you for the comments, Guenter Roeck)

---
 Documentation/hwmon/ntc_thermistor           |   93 ++++++
 drivers/hwmon/Kconfig                        |   14 +
 drivers/hwmon/Makefile                       |    1 +
 drivers/hwmon/ntc_thermistor.c               |  453
++++++++++++++++++++++++++
 include/linux/platform_data/ntc_thermistor.h |   53 +++
 5 files changed, 614 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hwmon/ntc_thermistor
 create mode 100644 drivers/hwmon/ntc_thermistor.c
 create mode 100644 include/linux/platform_data/ntc_thermistor.h
Quoted 1 line

<snip>

Why have a function starting with a _

Quoted 15 lines

drivers/hwmon/ntc_thermistor.c line 254

Quoted 9 lines
drivers/hwmon/ntc_thermistor.c new file +8 -0
+static int _ntc_thermistor_read(struct ntc_data *data, int *temp)
+{
+       int ret;
+       int read_ohm, read_uV;
+       unsigned int ohm = 0;
+
+       if (data->pdata->read_ohm) {
+               read_ohm = data->pdata->read_ohm();

Is the platform function posted? What errors could these functions return ? Should we mask the errors here?

Two platform functions have not posted.
The positive values are returned by read_ohm and read_uV functions, when errors do not occur.
It is assumed that the functions simply return negative value for error cases.
Thus, the driver code checks whether positive or negative value is returned and returns -EINVAL for negative value.

Quoted 8 lines

drivers/hwmon/ntc_thermistor.c line 261

Quoted 8 lines
drivers/hwmon/ntc_thermistor.c new file +7 -0
+               if (read_ohm < 0)
+                       return -EINVAL;
+               ohm = (unsigned int)read_ohm;
+       }
+
+       if (data->pdata->read_uV) {
+               read_uV = data->pdata->read_uV();
Quoted 9 lines

same here

Quoted 6 lines
drivers/hwmon/ntc_thermistor.c new file +5 -0
+               if (read_uV < 0)
+                       return -EINVAL;
+               ohm = get_ohm_of_thermistor(data, (unsigned int)read_uV);
+       }
+

Thanks.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Donggeun Kim
Quoted 87 lines · Shubhrajyoti Datta

Hi ,
Not a comment really was a bit curious.
Feel free to ignore such comments.

On Wed, Jun 15, 2011 at 12:52 PM, Donggeun Kim <[email protected]> wrote:

This patch adds support for NTC Thermistor series. In this release, the following thermistors are supported: NCP15WB473, NCP18WB473, NCP03WB473, and NCP15WL333. This driver is based on the datasheet of MURATA.

The driver in the patch does conversion from the raw ADC value (either voltage or resistence) to temperature. In order to use voltage values as input, the circuit schematics should be provided with the platform data. A compensation table for each type of thermistor is provided for the conversion.

--
Updates
v9
- remove unnecessary variables(mintemp, maxtemp) and checking lines for them
v8
- remove compiler warning message
- update Documentation/hwmon/ntc_thermistor
- add EXPERIMENTAL Kconfig dependency
v7
- move header file location
- rename header and driver file
- style fixes
v6
- updated Documentation/hwmon/ntc
- style fixes
v5
- use binary search on sorted table
- removed unnecessary attributes
- style fixes
v4
- put in alphabetic order in Kconfig/Makefile
- handle additional error cases
- remove the exported function
v3
- style fixes
- removed symbol exports
- avoid divide-by-zero
- omitted files added (Kconfig/Makefile)
- removed unnecessary codes
- return error values, not default values for errors.
v2
- added Documentation/hwmon/ntc
- followed hwmon sysfs
- detached the monitoring service
(thank you for the comments, Guenter Roeck)
---
Documentation/hwmon/ntc_thermistor | 93 ++++++
drivers/hwmon/Kconfig | 14 +
drivers/hwmon/Makefile | 1 +
drivers/hwmon/ntc_thermistor.c | 453
++++++++++++++++++++++++++
include/linux/platform_data/ntc_thermistor.h | 53 +++
5 files changed, 614 insertions(+), 0 deletions(-)
create mode 100644 Documentation/hwmon/ntc_thermistor create mode 100644 drivers/hwmon/ntc_thermistor.c
create mode 100644 include/linux/platform_data/ntc_thermistor.h

<snip>
Why have a function starting with a _

+static int _ntc_thermistor_read(struct ntc_data *data, int *temp) +{
+ int ret;
+ int read_ohm, read_uV;
+ unsigned int ohm = 0;
+
+ if (data->pdata->read_ohm) {
+ read_ohm = data->pdata->read_ohm();

Quoted 1 line

Is the platform function posted?

What do you mean with "posted" ? It would be defined in the instantiating platform code.

Quoted 1 line

What errors could these functions return ?

We neither know nor care. The point is that if an error is returned, it is passed on.

Quoted 2 lines

Should we mask the errors here?

Definitely not. There is no knowledge about the internals of the function. If there is an error, just pass it on to the caller.

Quoted 3 lines

+ if (read_ohm < 0)
+ return -EINVAL;

Actually it should be

				return read_ohm;

We don't want to replace error codes. Sorry I didn't notice this before.

Quoted 10 lines

+ ohm = (unsigned int)read_ohm;
+ }
+
+ if (data->pdata->read_uV) {
+ read_uV = data->pdata->read_uV();

same here

+ if (read_uV < 0)
+ return -EINVAL;

Same here - return read_uV.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors