/* ------------------------------------------------------------------------*//** * @FUNCTION temp54xx_get * @BRIEF return temperature measured by selected sensor * (in degrees celcius) * @RETURNS measured temperature in case of success * TEMP_ABSOLUTE_ZERO (-273) in case of error * @param[in] id: ADC temperature sensor id * @param[in, out] temp: temperature (Celcius, min) (returned) * @DESCRIPTION return temperature measured by selected sensor * (in degrees celcius) *//*------------------------------------------------------------------------ */ int temp54xx_get(temp54xx_sensor_id id) { int temp, ret; char line[256]; unsigned int i; FILE *fp = NULL; static const char *sensor_filenames1[TEMP54XX_ID_MAX] = { "/sys/kernel/debug/thermal_debug/devices/omap_cpu_sensor/temperature", "/sys/kernel/debug/thermal_debug/devices/omap_cpu_governor/hotspot_temp", "/sys/kernel/debug/thermal_debug/devices/omap_gpu_sensor/temperature", "/sys/kernel/debug/thermal_debug/devices/omap_gpu_governor/hotspot_temp", "/sys/kernel/debug/thermal_debug/devices/omap_core_sensor/temperature", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/kernel/debug/thermal_debug/devices/tmp102_temp_sensor.72/temperature", "/sys/kernel/debug/thermal_debug/devices/tmp006_sensor/temperature", "/sys/kernel/debug/thermal_debug/devices/tmp102_temp_sensor.73/temperature"}; static const char *sensor_filenames2[TEMP54XX_ID_MAX] = { "/sys/devices/platform/omap/omap_temp_sensor.0/temp1_input", "/sys/kernel/debug/thermal_debug/devices/omap_cpu_governor/hotspot_temp", "/sys/devices/platform/omap/omap_temp_sensor.1/temp1_input", "/sys/kernel/debug/thermal_debug/devices/omap_gpu_governor/hotspot_temp", "/sys/devices/platform/omap/omap_temp_sensor.2/temp1_input", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/kernel/debug/thermal_debug/devices/tmp102_temp_sensor.72/temperature", "/sys/kernel/debug/thermal_debug/devices/tmp006_sensor/temperature", "/sys/kernel/debug/thermal_debug/devices/tmp102_temp_sensor.73/temperature"}; static const char *sensor_filenames3[TEMP54XX_ID_MAX] = { "/sys/devices/platform/omap/omap4plus_scm.0/temp_sensor_hwmon.0/temp1_input", "/sys/kernel/debug/thermal_debug/devices/omap_cpu_governor/hotspot_temp", "/sys/devices/platform/omap/omap4plus_scm.0/temp_sensor_hwmon.1/temp1_input", "/sys/kernel/debug/thermal_debug/devices/omap_gpu_governor/hotspot_temp", "/sys/devices/platform/omap/omap4plus_scm.0/temp_sensor_hwmon.2/temp1_input", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/kernel/debug/thermal_debug/devices/tmp102_temp_sensor.72/temperature", "/sys/kernel/debug/thermal_debug/devices/tmp006_sensor/temperature", "/sys/kernel/debug/thermal_debug/devices/tmp102_temp_sensor.73/temperature"}; static const char **sensor_filenames_list[3] = { sensor_filenames1, sensor_filenames2, sensor_filenames3}; CHECK_CPU(54xx, TEMP_ABSOLUTE_ZERO); CHECK_ARG_LESS_THAN(id, TEMP54XX_ID_MAX, TEMP_ABSOLUTE_ZERO); /* Open file exported by temp. sensor driver (if loaded) */ for (i = 0; i < 3; i++) { dprintf("%s(): i=%u id=%u filename=%s\n", __func__, i, id, (char *) sensor_filenames_list[i][id]); fp = fopen((char *) sensor_filenames_list[i][id], "r"); if (fp != NULL) break; } if (fp == NULL) { dprintf("%s(): could not open %s file!\n", __func__, temp54xx_name_get(id)); temp = TEMP_ABSOLUTE_ZERO; goto temp54xx_get_end; } /* Read file */ if (fgets(line, 256, fp) == NULL) { fclose(fp); dprintf("%s(): fgets() returned NULL!\n", __func__); temp = TEMP_ABSOLUTE_ZERO; goto temp54xx_get_end; } fclose(fp); /* Remove endind '\n' */ line[strlen(line) - 1] = '\0'; dprintf("%s(): line=%s len=%u\n", __func__, line, strlen(line)); if ((id != TEMP54XX_EMIF1) && (id != TEMP54XX_EMIF2)) { /* Retrieve temperature, in millidegrees celcius */ ret = sscanf(line, "%d", &temp); if (ret != 1) { dprintf("%s(): sscanf() returned %d!\n", __func__, ret); temp = TEMP_ABSOLUTE_ZERO; goto temp54xx_get_end; } temp = temp / 1000; /* convert to degrees */ } else { /* Retrieve temperature as MR4 code */ ret = sscanf(line, "MR4=%d", &temp); if (ret != 1) { dprintf("%s(): sscanf() returned %d!\n", __func__, ret); temp = TEMP_ABSOLUTE_ZERO; goto temp54xx_get_end; } } temp54xx_get_end: if ((id != TEMP54XX_EMIF1) && (id != TEMP54XX_EMIF2)) { dprintf("%s(%s): temp is %d C\n", __func__, temp54xx_name_get(id), temp); } else { dprintf("%s(%s): temp is %s\n", __func__, temp54xx_name_get(id), emif_mr4_convert(temp, TEMP_CELCIUS_DEGREES)); } return temp; }
/* ------------------------------------------------------------------------*//** * @FUNCTION temp_sensor_show * @BRIEF display all available temperatures formatted in a table. * @RETURNS temperatures formatted in a table * OMAPCONF_ERR_CPU * OMAPCONF_ERR_ARG * OMAPCONF_ERR_INTERNAL * OMAPCONF_ERR_NOT_AVAILABLE * @param[in,out] stream: output file * @param[in,out] sensor: generic temperature sensor name * Use "all" to show all temperatures * @param[in] hw: use s/w (driver based) read or hw_sensor read? * @DESCRIPTION display all available temperatures formatted in a table. * Display both Celcius and Fahrenheit degrees. *//*------------------------------------------------------------------------ */ static int _temp_sensor_show(FILE *stream, const char *sensor, const char hw) { char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN]; unsigned int row = 0; int i, count, temp, temp_f; char temp_s[EMIF_TEMP_MAX_NAME_LENGTH]; const char sensor2[TEMP_SENSOR_MAX_NAME_LENGTH]; const genlist *list; CHECK_NULL_ARG(stream, OMAPCONF_ERR_ARG); CHECK_NULL_ARG(sensor, OMAPCONF_ERR_ARG); if (strcasecmp(sensor, "all") != 0) { if (!temp_sensor_is_available(sensor)) { fprintf(stderr, "omapconf: '%s' temperature sensor is not available!\n", sensor); return OMAPCONF_ERR_NOT_AVAILABLE; } if (hw) temp = hwtemp_sensor_get(sensor); else temp = temp_sensor_get(sensor); if (temp == TEMP_ABSOLUTE_ZERO) { fprintf(stderr, "omapconf: could not retrieve '%s' temperature!\n", sensor); return OMAPCONF_ERR_INTERNAL; } else if ((strcasecmp(sensor, TEMP_SENSOR_MEM1) == 0) || (strcasecmp(sensor, TEMP_SENSOR_MEM2) == 0)) { fprintf(stream, "%s\n", emif_mr4_convert((emif_mr4_code) temp, TEMP_CELCIUS_DEGREES)); return 0; } else { fprintf(stream, "%d\n", temp); return 0; } } /* Retrieve temperature sensor list */ list = temp_sensor_list_get(); if (list == NULL) { fprintf(stderr, "omapconf: CPU not yet supported, sorry...\n"); return OMAPCONF_ERR_INTERNAL; } /* Retrieve temperature sensor list count */ count = temp_sensor_count_get(); if (count <= 0) { fprintf(stderr, "omapconf: could not retrieve sensor count!\n"); return OMAPCONF_ERR_INTERNAL; } dprintf("found %d temperature sensors\n", count); /* Fill table header */ row = 0; autoadjust_table_init(table); autoadjust_table_strncpy(table, row, 0, "Sensor"); autoadjust_table_strncpy(table, row, 1, "Temperature (C)"); autoadjust_table_strncpy(table, row++, 2, "Temperature (F)"); /* Fill table with temperatures */ for (i = 0; i < count; i++) { genlist_get((genlist *) list, i, (char *) &sensor2); if (sensor2 == NULL) { fprintf(stderr, "omapconf: could not retrieve sensor!\n"); return OMAPCONF_ERR_INTERNAL; } autoadjust_table_strncpy(table, row, 0, (char *) sensor2); dprintf("%s(): sensor is %s\n", __func__, sensor2); if (hw) temp = hwtemp_sensor_get(sensor2); else temp = temp_sensor_get(sensor2); if (temp != TEMP_ABSOLUTE_ZERO) { if ((strcasecmp(sensor2, TEMP_SENSOR_MEM1) == 0) || (strcasecmp(sensor2, TEMP_SENSOR_MEM2) == 0)) { sprintf(temp_s, "%s", emif_mr4_convert((emif_mr4_code) temp, TEMP_CELCIUS_DEGREES)); autoadjust_table_strncpy(table, row, 1, temp_s); sprintf(temp_s, "%s", emif_mr4_convert((emif_mr4_code) temp, TEMP_FAHRENHEIT_DEGREES)); autoadjust_table_strncpy(table, row++, 2, temp_s); } else { sprintf(temp_s, "%d", temp); autoadjust_table_strncpy(table, row, 1, temp_s); temp_f = celcius2fahrenheit(temp); sprintf(temp_s, "%d", temp_f); autoadjust_table_strncpy(table, row++, 2, temp_s); } } else { autoadjust_table_strncpy(table, row, 1, "NA"); autoadjust_table_strncpy(table, row++, 2, "NA"); } } /* Display table */ return autoadjust_table_fprint(stream, table, row, 3); }
/* ------------------------------------------------------------------------*//** * @FUNCTION temp44xx_get * @BRIEF return temperature measured by selected sensor * (in degrees celcius) * @RETURNS measured temperature in case of success * TEMP_ABSOLUTE_ZERO (-273) in case of error * @param[in] id: temperature sensor id * @DESCRIPTION return temperature measured by selected sensor * (in degrees celcius) *//*------------------------------------------------------------------------ */ int temp44xx_get(temp44xx_sensor_id id) { int temp, ret; char line[256]; unsigned int i; FILE *fp = NULL; static const char *sensor_filenames1[TEMP44XX_ID_MAX] = { "/sys/devices/platform/omap4plus_scm.0/temp_sensor_hwmon.0/temp1_input", /* GLP */ "/sys/devices/platform/omap/omap_temp_sensor.0/hotspot_temp", "/sys/kernel/debug/emif.1/mr4", /* GLP */ "/sys/kernel/debug/emif.1/mr4", /* GLP */ "/sys/kernel/debug/emif.2/mr4", /* GLP */ "/sys/kernel/debug/emif.2/mr4", /* GLP */ "/sys/devices/platform/i2c_omap.1/i2c-1/1-0049/twl6030_gpadc/in4_input" }; /* 4460 */ static const char *sensor_filenames2[TEMP44XX_ID_MAX] = { "/sys/devices/platform/omap/omap_temp_sensor.0/temp1_input", /* Android */ "/sys/devices/platform/omap/omap_temp_sensor.0/hotspot_temp", "/sys/devices/platform/omap/omap_emif.0/temperature", /* Android */ "/sys/devices/platform/omap/omap_emif.0/temperature", /* Android */ "/sys/devices/platform/omap/omap_emif.1/temperature", /* Android */ "/sys/devices/platform/omap/omap_emif.1/temperature", /* Android */ "/sys/devices/platform/omap/pcb_temp_sensor.0/temp1_input" }; /* 4460 */ static const char *sensor_filenames3[TEMP44XX_ID_MAX] = { "/sys/devices/platform/omap4plus_scm.0/temp_sensor_hwmon.0/temp1_input", "/sys/devices/platform/omap/omap_temp_sensor.0/hotspot_temp", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/devices/platform/i2c_omap.4/i2c-4/4-0048/temp1_input" }; /* 4470 */ static const char *sensor_filenames4[TEMP44XX_ID_MAX] = { "/sys/devices/platform/omap4plus_scm.0/temp_sensor_hwmon.0/temp1_input", "/sys/devices/platform/omap/omap_temp_sensor.0/hotspot_temp", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.1/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/kernel/debug/emif.2/mr4", "/sys/devices/platform/omap/omap_i2c.4/i2c-4/4-0048/temp1_input" }; /* 4470 */ static const char **sensor_filenames_list[4] = { sensor_filenames1, sensor_filenames2, sensor_filenames3, sensor_filenames4 }; CHECK_CPU(44xx, TEMP_ABSOLUTE_ZERO); CHECK_ARG_LESS_THAN(id, TEMP44XX_ID_MAX, TEMP_ABSOLUTE_ZERO); /* Open file exported by temp. sensor driver (if loaded) */ for (i = 0; i < 4; i++) { dprintf("%s(): i=%u id=%u filename=%s\n", __func__, i, id, (char *) sensor_filenames_list[i][id]); fp = fopen((char *) sensor_filenames_list[i][id], "r"); if (fp != NULL) break; } if (fp == NULL) { dprintf("%s(): could not open %s file!\n", __func__, temp44xx_name_get(id)); temp = TEMP_ABSOLUTE_ZERO; goto temp44xx_get_end; } /* Read file */ if (fgets(line, 256, fp) == NULL) { fclose(fp); dprintf("%s(): fgets() returned NULL!\n", __func__); temp = TEMP_ABSOLUTE_ZERO; goto temp44xx_get_end; } fclose(fp); /* Remove endind '\n' */ line[strlen(line) - 1] = '\0'; dprintf("%s(): line=%s len=%u\n", __func__, line, strlen(line)); if ((id != TEMP44XX_DDR1_CS1) && (id != TEMP44XX_DDR1_CS2) && (id != TEMP44XX_DDR2_CS1) && (id != TEMP44XX_DDR2_CS1)) { /* Retrieve temperature, in millidegrees celcius */ ret = sscanf(line, "%d", &temp); if (ret != 1) { dprintf("%s(): sscanf() returned %d!\n", __func__, ret); temp = TEMP_ABSOLUTE_ZERO; goto temp44xx_get_end; } temp = temp / 1000; /* convert to degrees */ } else { /* Retrieve temperature as MR4 code */ ret = sscanf(line, "MR4=%d", &temp); if (ret != 1) { dprintf("%s(): sscanf(\"MR4=%%d\") returned %d!\n", __func__, ret); ret = sscanf(line, "%d", &temp); if (ret != 1) { dprintf("%s(): sscanf(\"%%d\") returned %d!\n", __func__, ret); temp = TEMP_ABSOLUTE_ZERO; goto temp44xx_get_end; } } } temp44xx_get_end: if ((id != TEMP44XX_DDR1_CS1) && (id != TEMP44XX_DDR1_CS2) && (id != TEMP44XX_DDR2_CS1) && (id != TEMP44XX_DDR2_CS1)) { dprintf("%s(%s): temp is %d C\n", __func__, temp44xx_name_get(id), temp); } else { dprintf("%s(%s): temp is %s\n", __func__, temp44xx_name_get(id), emif_mr4_convert(temp, TEMP_CELCIUS_DEGREES)); } return temp; }