aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/misc/thinkpad_acpi.c79
-rw-r--r--drivers/misc/thinkpad_acpi.h8
2 files changed, 61 insertions, 26 deletions
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index 8829d3c6b444..e9aec87a9f09 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -1818,13 +1818,13 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
1818 1818
1819 ta1 = ta2 = 0; 1819 ta1 = ta2 = 0;
1820 for (i = 0; i < 8; i++) { 1820 for (i = 0; i < 8; i++) {
1821 if (likely(acpi_ec_read(0x78 + i, &t))) { 1821 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
1822 ta1 |= t; 1822 ta1 |= t;
1823 } else { 1823 } else {
1824 ta1 = 0; 1824 ta1 = 0;
1825 break; 1825 break;
1826 } 1826 }
1827 if (likely(acpi_ec_read(0xC0 + i, &t))) { 1827 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
1828 ta2 |= t; 1828 ta2 |= t;
1829 } else { 1829 } else {
1830 ta1 = 0; 1830 ta1 = 0;
@@ -1869,57 +1869,84 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
1869 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1; 1869 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
1870} 1870}
1871 1871
1872static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) 1872/* idx is zero-based */
1873static int thermal_get_sensor(int idx, s32 *value)
1873{ 1874{
1874 int i, t; 1875 int t;
1875 s8 tmp; 1876 s8 tmp;
1876 char tmpi[] = "TMPi"; 1877 char tmpi[5];
1877 1878
1878 if (!s) 1879 t = TP_EC_THERMAL_TMP0;
1879 return -EINVAL;
1880 1880
1881 switch (thermal_read_mode) { 1881 switch (thermal_read_mode) {
1882#if TPACPI_MAX_THERMAL_SENSORS >= 16 1882#if TPACPI_MAX_THERMAL_SENSORS >= 16
1883 case TPACPI_THERMAL_TPEC_16: 1883 case TPACPI_THERMAL_TPEC_16:
1884 for (i = 0; i < 8; i++) { 1884 if (idx >= 8 && idx <= 15) {
1885 if (!acpi_ec_read(0xC0 + i, &tmp)) 1885 t = TP_EC_THERMAL_TMP8;
1886 return -EIO; 1886 idx -= 8;
1887 s->temp[i + 8] = tmp * 1000;
1888 } 1887 }
1889 /* fallthrough */ 1888 /* fallthrough */
1890#endif 1889#endif
1891 case TPACPI_THERMAL_TPEC_8: 1890 case TPACPI_THERMAL_TPEC_8:
1892 for (i = 0; i < 8; i++) { 1891 if (idx <= 7) {
1893 if (!acpi_ec_read(0x78 + i, &tmp)) 1892 if (!acpi_ec_read(t + idx, &tmp))
1894 return -EIO; 1893 return -EIO;
1895 s->temp[i] = tmp * 1000; 1894 *value = tmp * 1000;
1895 return 0;
1896 } 1896 }
1897 return (thermal_read_mode == TPACPI_THERMAL_TPEC_16) ? 16 : 8; 1897 break;
1898 1898
1899 case TPACPI_THERMAL_ACPI_UPDT: 1899 case TPACPI_THERMAL_ACPI_UPDT:
1900 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) 1900 if (idx <= 7) {
1901 return -EIO; 1901 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
1902 for (i = 0; i < 8; i++) { 1902 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1903 tmpi[3] = '0' + i; 1903 return -EIO;
1904 if (!acpi_evalf(ec_handle, &t, tmpi, "d")) 1904 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1905 return -EIO; 1905 return -EIO;
1906 s->temp[i] = (t - 2732) * 100; 1906 *value = (t - 2732) * 100;
1907 return 0;
1907 } 1908 }
1908 return 8; 1909 break;
1909 1910
1910 case TPACPI_THERMAL_ACPI_TMP07: 1911 case TPACPI_THERMAL_ACPI_TMP07:
1911 for (i = 0; i < 8; i++) { 1912 if (idx <= 7) {
1912 tmpi[3] = '0' + i; 1913 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
1913 if (!acpi_evalf(ec_handle, &t, tmpi, "d")) 1914 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1914 return -EIO; 1915 return -EIO;
1915 s->temp[i] = t * 1000; 1916 *value = t * 1000;
1917 return 0;
1916 } 1918 }
1917 return 8; 1919 break;
1918 1920
1919 case TPACPI_THERMAL_NONE: 1921 case TPACPI_THERMAL_NONE:
1920 default: 1922 default:
1921 return 0; 1923 return -ENOSYS;
1922 } 1924 }
1925
1926 return -EINVAL;
1927}
1928
1929static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1930{
1931 int res, i;
1932 int n;
1933
1934 n = 8;
1935 i = 0;
1936
1937 if (!s)
1938 return -EINVAL;
1939
1940 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
1941 n = 16;
1942
1943 for(i = 0 ; i < n; i++) {
1944 res = thermal_get_sensor(i, &s->temp[i]);
1945 if (res)
1946 return res;
1947 }
1948
1949 return n;
1923} 1950}
1924 1951
1925static int thermal_read(char *p) 1952static int thermal_read(char *p)
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
index fb0abb02a016..6432b28339af 100644
--- a/drivers/misc/thinkpad_acpi.h
+++ b/drivers/misc/thinkpad_acpi.h
@@ -427,12 +427,20 @@ enum thermal_access_mode {
427 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */ 427 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
428}; 428};
429 429
430enum { /* TPACPI_THERMAL_TPEC_* */
431 TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
432 TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
433};
434
430#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ 435#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
431struct ibm_thermal_sensors_struct { 436struct ibm_thermal_sensors_struct {
432 s32 temp[TPACPI_MAX_THERMAL_SENSORS]; 437 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
433}; 438};
434 439
440static enum thermal_access_mode thermal_read_mode;
441
435static int thermal_init(struct ibm_init_struct *iibm); 442static int thermal_init(struct ibm_init_struct *iibm);
443static int thermal_get_sensor(int idx, s32 *value);
436static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s); 444static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
437static int thermal_read(char *p); 445static int thermal_read(char *p);
438 446