Beispiel #1
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		opp_set
 * @BRIEF		change OPP of a given voltage domain.
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_NOT_AVAILABLE
 * @param[in]		voltdm: voltage domain name (as defined in voltdm.h)
 * @param[in]		opp: name of OPP to be set (as defined in opp.h)
 * @DESCRIPTION		change OPP of a given voltage domain.
 *//*------------------------------------------------------------------------ */
int opp_set(const char *voltdm, const char *opp)
{
	int vdd_id, opp_id;

	CHECK_NULL_ARG(voltdm, OMAPCONF_ERR_ARG);
	CHECK_NULL_ARG(opp, OMAPCONF_ERR_ARG);

	opp_init();

	vdd_id = voltdm_s2id(voltdm);
	if (vdd_id < 0)
		return OMAPCONF_ERR_ARG;

	opp_id = opp_s2id(opp);
	if (opp_id < 0)
		return OMAPCONF_ERR_ARG;

	if (cpu_is_omap44xx()) {
		return opp44xx_set((voltdm44xx_id) vdd_id, (opp44xx_id) opp_id);
	} else if (cpu_is_omap54xx()) {
		return opp54xx_set((voltdm54xx_id) vdd_id, (opp54xx_id) opp_id);
	} else {
		fprintf(stderr,
			"omapconf: %s(): cpu not supported!!!\n", __func__);
		return OMAPCONF_ERR_CPU;
	}
}
Beispiel #2
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		main_i2c_read
 * @BRIEF		read given data from given address of given device of
 *			given I2C bus
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_NOT_AVAILABLE
 *			OMAPCONF_ERR_REG_ACCESS
 * @param[in]		argc: shell input argument number
 *			argc must be 5
 * @param[in]		argv: shell input argument(s)
 *			argv[2] = i2cbus: I2C bus number
 *			argv[3] = address: I2C device address
 *			argv[4] = daddress: I2C device register address
 * @DESCRIPTION		read given data from given address of given device of
 *			given I2C bus
 *//*------------------------------------------------------------------------ */
static int main_i2c_read(int argc, char *argv[])
{
	unsigned int i2cbus, chip_address, data_address;
	unsigned int data;
	int ret;

	CHECK_NULL_ARG(argv, OMAPCONF_ERR_ARG);

	/* Retrieve arguments */
	if (argc != 5)
		goto main_i2c_read_err;
	ret = sscanf(argv[2], "%u", &i2cbus);
	if (ret != 1)
		goto main_i2c_read_err;
	ret = sscanf(argv[3], "0x%x", &chip_address);
	if (ret != 1)
		goto main_i2c_read_err;
	ret = sscanf(argv[4], "0x%x", &data_address);
	if (ret != 1)
		goto main_i2c_read_err;

	ret = i2cget(i2cbus, chip_address, data_address, &data);
	if (ret == 0)
		printf("0x%02x\n", data);
	return ret;

main_i2c_read_err:
	printf(
		"Usage: omapconf i2c read 'i2cbus' 0x'chip-address' 0x'data-address'\n");
	printf("  'i2cbus' is decimal value.\n");
	printf("  'chip-address' & 'data-address' are hexadecimal values.\n");
	printf("  Warning: prefix '0x' is mandatory.\n");
	return OMAPCONF_ERR_ARG;
}
Beispiel #3
0
/**
 * @brief Reads complete content of a file referenced by the descriptor 'fd' into the memory.
 * Caller is responsible for deallocation of the memory block returned through the output argument 'out'.
 * Returns SR_ERR_OK in case of success, error code otherwise.
 */
static int
srcfg_read_file_content(int fd, char **out)
{
    int rc = SR_ERR_OK;
    size_t size = EXPECTED_MAX_INPUT_FILE_SIZE;
    unsigned cur = 0;
    ssize_t n = 0;
    char *buffer = NULL;

    CHECK_NULL_ARG(out);

    buffer = malloc(size);
    CHECK_NULL_NOMEM_GOTO(buffer, rc, fail);

    do {
        if (size == cur + 1) {
            size <<= 1;
            char *new_buffer = realloc(buffer, size);
            CHECK_NULL_NOMEM_GOTO(new_buffer, rc, fail);
            buffer = new_buffer;
        }
        n = read(fd, buffer + cur, size - cur - 1);
        CHECK_NOT_MINUS1_LOG_GOTO(n, rc, SR_ERR_INTERNAL, fail,
                                  "Read operation failed: %s.", sr_strerror_safe(errno));
        cur += n;
    } while (0 < n);

    buffer[cur] = '\0';
    *out = buffer;
    return rc;

fail:
    free(buffer);
    return rc;
}
Beispiel #4
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		voltdm_s2id
 * @BRIEF		convert voltage domain provided as a string
 *			(as defined in voltdm.h) into a plaftorm-specific
 *			voltage domain ID (integer).
 * @RETURNS		plaftorm-specific voltage domain ID (> 0) if success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 * @param[in]		voltdm: voltage domain name (as defined in voltdm.h)
 * @DESCRIPTION		convert voltage domain provided as a string
 *			(as defined in voltdm.h) into a plaftorm-specific
 *			voltage domain ID (integer).
 *//*------------------------------------------------------------------------ */
int voltdm_s2id(const char *voltdm)
{
	CHECK_NULL_ARG(voltdm, OMAPCONF_ERR_ARG);

	if (cpu_is_omap44xx()) {
		if (strcmp(voltdm, VDD_WKUP) == 0)
			return (int) OMAP4_LDO_WKUP;
		else if (strcmp(voltdm, VDD_MPU) == 0)
			return (int) OMAP4_VDD_MPU;
		else if (strcmp(voltdm, VDD_IVA) == 0)
			return (int) OMAP4_VDD_IVA;
		else if (strcmp(voltdm, VDD_CORE) == 0)
			return (int) OMAP4_VDD_CORE;
		else
			return OMAPCONF_ERR_ARG;
	} else if (cpu_is_omap54xx()) {
		if (strcmp(voltdm, VDD_WKUP) == 0)
			return (int) VDD54XX_WKUP;
		else if (strcmp(voltdm, VDD_MPU) == 0)
			return (int) VDD54XX_MPU;
		else if (strcmp(voltdm, VDD_MM) == 0)
			return (int) VDD54XX_MM;
		else if (strcmp(voltdm, VDD_CORE) == 0)
			return (int) VDD54XX_CORE;
		else
			return OMAPCONF_ERR_ARG;
	} else {
		fprintf(stderr,
			"omapconf: %s(): cpu not supported!!!\n", __func__);
		return OMAPCONF_ERR_CPU;
	}
}
Beispiel #5
0
/**
 * @brief           Measure the current consumption of a given spring.
 * @return          current consumption of a given spring (in microamps)
 * warning          'spring' index starts at 1, not 0.
 * @param[in]       spring: selected spring ([1..SPRING_COUNT])
 * @param[out]      uA: selected spring current measurement, in microamps)
 */
int spwrm_get_current(uint8_t spring, int32_t *uA)
{
    int ret;
    uint8_t adc, chan;
    uint32_t spin, uV;

    CHECK_SPRING(spring);
    CHECK_NULL_ARG(uA);

    adc = spwrm_get_adc_device(spring);
    chan = spwrm_get_adc_channel(spring);
    spin = spwrm_get_sign_pin(spring);
    *uA = 0;

    ret = adc_get_data(adc, chan, &uV);
    if (ret) {
        dbg_error("%s(): failed to get %s data! (%d)\n", __func__,
                  spwrm_get_name(spring), ret);
        return ret;
    }
    /* Convert to uV */
    uV = adc_get_uV(uV);
    /* Get data sign */
    if (stm32_gpioread(spin) == 0) {
        dbg_verbose("%s(): pin=0 => sign=-\n", __func__);
        *uA = -((int32_t) max9929f_get_Iload(uV));
    } else {
        dbg_verbose("%s(): pin=1 => sign=+\n", __func__);
        *uA = (int32_t) max9929f_get_Iload(uV);
    }
    dbg_verbose("%s(): measured voltage=%uuV => current=%duA\n",
                __func__, uV, *uA);

    return 0;
}
Beispiel #6
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		voltdm_nominal_voltage_get
 * @BRIEF		return the nominal voltage supplied to a voltage domain.
 * @RETURNS		nominal voltage in micro-volt (> 0) in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 * @param[in]		voltdm: voltage domain name (as defined in voltdm.h)
 * @DESCRIPTION		return the nominal voltage supplied to a voltage domain.
 *			In case SmartReflex AVS Class3 is enabled,
 *			it may differ from the current supplied voltage.
 *//*------------------------------------------------------------------------ */
int voltdm_nominal_voltage_get(const char *voltdm)
{
	int id;
	int uvolt;

	CHECK_NULL_ARG(voltdm, OMAPCONF_ERR_ARG);

	voltdm_init();

	id = voltdm_s2id(voltdm);
	if (id < 0) {
		uvolt = OMAPCONF_ERR_ARG;
	} else if (cpu_is_omap44xx()) {
		uvolt = v2uv(voltdm44xx_nominal_voltage_get(
			(voltdm44xx_id) id));
	} else if (cpu_is_omap54xx()) {
		uvolt = v2uv(voltdm54xx_nominal_voltage_get(
			(voltdm54xx_id) id));
	} else {
		fprintf(stderr,
			"omapconf: %s(): cpu not supported!!!\n", __func__);
		uvolt = OMAPCONF_ERR_CPU;
	}

	dprintf("%s(%s) = %duV\n", __func__, voltdm, uvolt);
	return uvolt;
}
Beispiel #7
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		dpll_lock_freq_calc
 * @BRIEF		compute DPLL lock frequency (in MHz)
 * @RETURNS		lock frequency in case of success (in MHz)
 *			0.0 in case of error.
 * @param[in]		settings: DPLL settings with fields
 *			regm4xen, fref, MN.M, MN.N INITIALIZED
 * @DESCRIPTION		compute DPLL lock frequency (in MHz)
 *//*------------------------------------------------------------------------ */
double dpll_lock_freq_calc(dpll_settings *settings)
{
	CHECK_NULL_ARG(settings, 0.0);

	if (settings->type == DPLL_TYPE_A) {
		if (settings->regm4xen == 0)
			settings->fdpll =
				(settings->fref * 2.0 * (double) (settings->MN).M) /
				((double) (settings->MN).N + 1.0);
		else
			settings->fdpll =
				(settings->fref * 8.0 * (double) (settings->MN).M) /
				((double) (settings->MN).N + 1.0);
		dprintf("%s(%u): type=A regm4xen=%u fref=%lfMHz M=%u N=%u => "
			"fdpll=%lfMHz\n", __func__, settings->id,
			settings->regm4xen, settings->fref, (settings->MN).M,
			(settings->MN).N, settings->fdpll);
	} else {
		settings->fdpll =
			(settings->fref * (double) (settings->MN).M) /
			((double) (settings->MN).N + 1.0);
		dprintf("%s(%u): type=B fref=%lfMHz M=%u N=%u => "
			"fdpll=%lfMHz\n", __func__, settings->id,
			settings->fref, (settings->MN).M,
			(settings->MN).N, settings->fdpll);
	}

	return settings->fdpll;
}
Beispiel #8
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		sr54xx_export
 * @BRIEF		export module register content to file, in XML format.
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_REG_ACCESS
 * @param[in,out]	fp: output file stream (opened for write operations)
 * @param[in]		id: SR module ID
 * @DESCRIPTION		export module register content to file, in XML format.
 *//*------------------------------------------------------------------------ */
int sr54xx_export(FILE *fp, sr54xx_mod_id id)
{
	reg **mod;
	unsigned int i;

	CHECK_CPU(54xx, OMAPCONF_ERR_CPU);
	CHECK_NULL_ARG(fp, OMAPCONF_ERR_ARG);
	CHECK_ARG_LESS_THAN(id, SR54XX_MODS_COUNT, OMAPCONF_ERR_ARG);

	if (!sr54xx_is_enabled(id)) {
		printf("%s export: module not running, skipping "
			"registers export.\n", sr54xx_mod_name_get(id));
		return 0;
	}

	mod = sr54xx_mods[id];

	fprintf(fp, "          <submodule id=\"%u\" name=\"%s\">\n",
		id, sr54xx_mod_name_get(id));

	for (i = 0; i < OMAP5430_SMARTREFLEX_CORE_MOD_REGCOUNT; i++)
		fprintf(fp, "            <register id=\"%u\" name=\"%s\" "
			"addr=\"0x%08X\" data=\"0x%08X\" />\n", i,
			(mod[i])->name, (mod[i])->addr, reg_read(mod[i]));

	fprintf(fp, "          </submodule>\n");

	return 0;
}
Beispiel #9
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		powerdm_has_last_power_state
 * @BRIEF		return 1 if power domain has LASTPOWERSTATEENTERED
 * @RETURNS		1 if power domain has a LASTPOWERSTATEENTERED bitfield.
 *			0 if not available or in case of error.
 * @param[in]		powerdm: power domain name
 * @DESCRIPTION		return 1 if power domain has LASTPOWERSTATEENTERED
 *			in PM_xyz_PWRSTST register (not all power domains
 *			feature it).
 *			Return 0 if not available or in case of error.
 *			Does not make any access to any register.
 *//*------------------------------------------------------------------------ */
unsigned int powerdm_has_last_power_state(const char *powerdm)
{
	int ret;
	powerdm_info data;

	CHECK_NULL_ARG(powerdm, 0);

	ret = _powerdm_info_get(powerdm, &data);
	if (ret != 0) {
		dprintf("%s(%s): could not retrieve powerdm_info struct!\n",
			__func__, powerdm);
		return 0;
	}

	if ((data.properties & PWRDM_HAS_LAST_STATE) != 0) {
		dprintf("%s(%s): HAS LASTPOWERSTATEENTERED bitfield\n",
			__func__, powerdm);
		return 1;
	} else {
		dprintf(
			"%s(%s): does NOT have LASTPOWERSTATEENTERED bitfield\n",
			__func__, powerdm);
		return 0;
	}
}
Beispiel #10
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		voltdm_voltage_get
 * @BRIEF		return the current voltage supplied to a voltage domain.
 * @RETURNS		supplied voltage in micro-volt (> 0) in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_REG_ACCESS
 *			OMAPCONF_ERR_NOT_AVAILABLE
 *			OMAPCONF_ERR_INTERNAL
 * @param[in]		voltdm: voltage domain name (as defined in voltdm.h)
 * @DESCRIPTION		return the current voltage supplied to a voltage domain.
 *//*------------------------------------------------------------------------ */
int voltdm_voltage_get(const char *voltdm)
{
	int id, ret;
	double volt;

	CHECK_NULL_ARG(voltdm, OMAPCONF_ERR_ARG);

	voltdm_init();

	id = voltdm_s2id(voltdm);
	if (id < 0)
		return (double) OMAPCONF_ERR_ARG;

	if (cpu_is_omap44xx()) {
		ret = voltdm44xx_get_voltage((voltdm44xx_id) id, &volt);
		if (ret < 0)
			return (double) ret;
		else
			return v2uv(volt);
	} else if (cpu_is_omap54xx()) {
		return v2uv(voltdm54xx_voltage_get((voltdm54xx_id) id));
	} else {
		fprintf(stderr,
			"omapconf: %s(): cpu not supported!!!\n", __func__);
		return (double) OMAPCONF_ERR_CPU;
	}
}
Beispiel #11
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		powerdm_in_transition
 * @BRIEF		return 1 if a power transition is ongoing
 *			on a given power domain
 * @RETURNS		1 if a power transition is ongoing
 *			0 if NO power transition is ongoing (or error)
 * @param[in]		powerdm: power domain name
 * @DESCRIPTION		return 1 if a power transition is ongoing
 *			on a given power domain
 *//*------------------------------------------------------------------------ */
unsigned int powerdm_in_transition(const char *powerdm)
{
	int in_transition;
	reg *pm_pwrstst;

	CHECK_NULL_ARG(powerdm, 0);

	pm_pwrstst = powerdm_pwrstst_reg_get(powerdm);
	if (pm_pwrstst == NULL) {
		dprintf("%s(%s): PM_PWRSTST==NULL!\n", __func__, powerdm);
		return 0;
	}

	in_transition = pwrdm_in_transition(pm_pwrstst);
	#ifdef PWRDM_DEBUG
	if (in_transition)
		printf("%s(%s): power transition ONGOING.\n",
			__func__, powerdm);
	else
		printf("%s(%s): NO power transition ongoing.\n",
			__func__, powerdm);
	#endif

	return in_transition;
}
Beispiel #12
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		cpu_die_id_get
 * @BRIEF		return OMAP DIE ID (4x 32-bit integers, string).
 * @RETURNS		OMAP DIE ID string (as "DIEID3-DIEID2-DIEID1-DIEID0")
 *			NULL in case of error
 * @param[in,out]	die_id_3: DIE ID (part 3, MSB)
 * @param[in,out]	die_id_2: DIE ID (part 2)
 * @param[in,out]	die_id_1: DIE ID (part 1)
 * @param[in,out]	die_id_0: DIE ID (part 0, LSB)
 * @param[in,out]	die_id: DIE ID string ("DIEID3-DIEID2-DIEID1-DIEID0")
 * @DESCRIPTION		return OMAP DIE ID (4x 32-bit integers, string).
 *//*------------------------------------------------------------------------ */
char *cpu_die_id_get(unsigned int *die_id_3, unsigned int *die_id_2,
	unsigned int *die_id_1, unsigned int *die_id_0,
	char die_id[CPU_DIE_ID_LENGTH])
{
	CHECK_NULL_ARG(die_id, NULL);

	if (mem_read(CONTROL_STD_FUSE_DIE_ID_3, die_id_3) != 0)
		return NULL;
	dprintf("%s(): die_id_3 = 0x%08X\n", __func__, *die_id_3);
	if (mem_read(CONTROL_STD_FUSE_DIE_ID_2, die_id_2) != 0)
		return NULL;
	dprintf("%s(): die_id_2 = 0x%08X\n", __func__, *die_id_2);
	if (mem_read(CONTROL_STD_FUSE_DIE_ID_1, die_id_1) != 0)
		return NULL;
	dprintf("%s(): die_id_1 = 0x%08X\n", __func__, *die_id_1);
	if (mem_read(CONTROL_STD_FUSE_DIE_ID_0, die_id_0) != 0)
		return NULL;
	dprintf("%s(): die_id_0 = 0x%08X\n", __func__, *die_id_0);

	sprintf(die_id, "%08X-%08X-%08X-%08X",
		*die_id_3, *die_id_2, *die_id_1, *die_id_0);
	dprintf("%s(): die_id = %s\n", __func__, die_id);

	return die_id;
}
Beispiel #13
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		prm54xx_import
 * @BRIEF		import OMAP PRM registers from XML file
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_UNEXPECTED
 * @param[in,out]	fp: XML import file descriptor
 * @param[in]		id: CM module ID
 * @DESCRIPTION		import OMAP PRM registers from XML file,
 *			generated with lib54xx_export().
 *//*------------------------------------------------------------------------ */
int prm54xx_import(FILE *fp, prm54xx_mod_id id)
{
	reg **mod;
	char line[256], sline[256];
	char *xml_entry;
	int ret, i, n;

	CHECK_NULL_ARG(fp, OMAPCONF_ERR_ARG);
	CHECK_ARG_LESS_THAN(id, PRM54XX_MODS_COUNT, OMAPCONF_ERR_ARG);

	if (cpu_revision_get() == REV_ES1_0)
		mod = prm54xxes1_mods[id];
	else
		mod = prm54xx_mods[id];
	rewind(fp);

	/* Search for the PRM module tag */
	sprintf(sline, "<submodule id=\"%u\" name=\"%s\">",
		id, prm54xx_mod_name_get(id));
	while (fgets(line, sizeof(line), fp) != NULL) {
		if (strstr(line, sline) == NULL)
			continue;
		/* Import register content */
		for (i = 0; mod[i] != NULL; i++) {
			if (fgets(line, sizeof(line), fp) == NULL)
				return OMAPCONF_ERR_UNEXPECTED;
			line[strlen(line) - 1] = '\0'; /* remove ending '\n' */
			xml_entry = strstr(line, "<"); /* remove spaces */

			dprintf("%s(%u (%s)): xml_entry=%s\n", __func__, id,
				prm54xx_mod_name_get(id), xml_entry);

			/* Check register id is correct */
			ret = sscanf(xml_entry, "<register id=\"%u\" %s",
				&n, sline);
			if (ret != 2) {
				dprintf("%s(%u (%s)): could not get id\n",
					__func__, id, prm54xx_mod_name_get(id));
				return OMAPCONF_ERR_UNEXPECTED;
			}
			if (n != i) {
				dprintf(
					"%s(%u (%s)): register id does not match! (n=%u, i=%u)\n",
					__func__, id,
					prm54xx_mod_name_get(id), n, i);
				return OMAPCONF_ERR_UNEXPECTED;
			}

			ret = reg_xml_import(mod[i], xml_entry);
			if (ret != 0)
				return ret;
		}
		dprintf("%s(%u (%s)): all registers imported.\n", __func__, id,
			prm54xx_mod_name_get(id));
		break;
	}

	return 0;
}
Beispiel #14
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		main_dra7xx_show
 * @BRIEF		show some DRA7 information,
 *			which category is found in argv
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG in case of incorrect format
 * @param[in]		argc: shell input argument number
 * @param[in]		argv: shell input argument(s)
 * @DESCRIPTION		show some DRA7 information,
 *			which category is found in argv
 *//*------------------------------------------------------------------------ */
int main_dra7xx_show(int argc, char *argv[])
{
	CHECK_NULL_ARG(argv, OMAPCONF_ERR_ARG);

	if (argc < 1) {
		help(HELP_USAGE);
		return OMAPCONF_ERR_ARG;
	} else if (strcmp(argv[0], "hwtemp") == 0) {
		if (argc == 1) {
			return hwtemp_sensor_show(stdout, "all");
		} else if (argc == 2) {
			if (strcmp(argv[1], "all") == 0)
				return hwtemp_sensor_show(stdout, argv[1]);
			else if (hwtemp_sensor_is_available(argv[1]) != 0)
				return hwtemp_sensor_show(stdout, argv[1]);
			else
				return err_arg_msg_show(HELP_HWTEMPERATURE);
		} else {
			return err_arg_too_many_msg_show(HELP_HWTEMPERATURE);
		}
	} else if (strcmp(argv[0], "temp") == 0) {
		if (argc == 1) {
			return temp_sensor_show(stdout, "all");
		} else if (argc == 2) {
			if (strcmp(argv[1], "all") == 0)
				return temp_sensor_show(stdout, argv[1]);
			else if (hwtemp_sensor_is_available(argv[1]) != 0)
				return temp_sensor_show(stdout, argv[1]);
			else
				return err_arg_msg_show(HELP_TEMPERATURE);
		} else {
			return err_arg_too_many_msg_show(HELP_TEMPERATURE);
		}
	} else if (strcmp(argv[0], "dpll") == 0) {
		if (argc == 1) {
			return dpll_dra7xx_show(stdout);
		} else if (argc == 2) {
			if (strcmp(argv[1], "cfg") == 0)
				return dpll_dra7xx_show(stdout);
			else
				return err_arg_msg_show(HELP_DPLL);
		} else {
			return err_arg_too_many_msg_show(HELP_DPLL);
		}
	} else if (strcmp(argv[0], "opp") == 0) {
		if (argc == 1)
			return opp_show(stdout);
		else
			return err_arg_too_many_msg_show(HELP_SOC_OPP);
	} else if (strncmp(argv[0], "mcasp", 5) == 0) {
		if (argc == 1) {
			return dra7xx_mcasp_show(stdout, argc, argv);
		} else {
			return err_arg_too_many_msg_show(HELP_MCASP);
		}
	} else {
		return err_unknown_argument_msg_show(argv[0]);
	}
}
Beispiel #15
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		cm54xx_export
 * @BRIEF		export module register content to file, in XML format.
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_INTERNAL
 * @param[in,out]	fp: output file stream (opened for write operations)
 * @param[in]		id: CM module ID
 * @DESCRIPTION		export module register content to file, in XML format.
 *//*------------------------------------------------------------------------ */
int cm54xx_export(FILE *fp, cm54xx_mod_id id)
{
	reg **mod;
	unsigned int i;

	CHECK_CPU(54xx, OMAPCONF_ERR_CPU);
	CHECK_NULL_ARG(fp, OMAPCONF_ERR_ARG);
	CHECK_ARG_LESS_THAN(id, CM54XX_MODS_COUNT, OMAPCONF_ERR_ARG);

	if ((cpu_revision_get() != REV_ES1_0) &&
		(id == CM54XX_L4PER_CM_CORE)) {
		fprintf(stderr, "omapconf: %s(): L4_PER does not exist!!!\n",
			__func__);
		return OMAPCONF_ERR_ARG;
	}

	dprintf("%s(): exporting CM %s (%u) module ...\n", __func__,
		cm54xx_mod_name_get(id), id);

	if (cpu_revision_get() == REV_ES1_0)
		mod = cm54xxes1_mods[id];
	else
		mod = cm54xx_mods[id];
	if (mod == NULL) {
		fprintf(stderr, "omapconf: %s(): mod == NULL!!!\n", __func__);
		return OMAPCONF_ERR_INTERNAL;
	}

	if ((id == CM54XX_INSTR_CM_CORE) &&
		!cm54xx_is_profiling_running(CM54XX_INSTR_CM_CORE)) {
		dprintf(
			"%s(%s): CM module is not accessible, don't export registers\n",
			__func__, cm54xx_mod_name_get(id));
		return 0;
	} else if ((id == CM54XX_INSTR_CM_CORE_AON) &&
		!cm54xx_is_profiling_running(CM54XX_INSTR_CM_CORE_AON)) {
		dprintf(
			"%s(%s): CM module is not accessible, don't export registers\n",
			__func__, cm54xx_mod_name_get(id));
		return 0;
	}

	fprintf(fp, "          <submodule id=\"%u\" name=\"%s\">\n",
		id, cm54xx_mod_name_get(id));

	for (i = 0; mod[i] != NULL; i++)
		fprintf(fp,
			"            <register id=\"%u\" name=\"%s\" addr=\"0x%08X\" data=\"0x%08X\" />\n",
			i, reg_name_get(mod[i]), reg_addr_get(mod[i]),
			reg_read(mod[i]));

	fprintf(fp, "          </submodule>\n");
	fflush(fp);

	dprintf("%s(): CM %s (%u) module exported.\n", __func__,
		cm54xx_mod_name_get(id), id);
	return 0;
}
Beispiel #16
0
/**
 * @brief Convert data tree difference of type LYD_DIFF_MOVEDAFTER1 or LYD_DIFF_MOVEDAFTER2 to corresponding
 * set of Sysrepo public API calls.
 */
static int
srcfg_convert_lydiff_movedafter(const char *target_xpath, const char *after_xpath)
{
    CHECK_NULL_ARG(target_xpath);
    int rc = sr_move_item(srcfg_session, target_xpath, after_xpath ? SR_MOVE_AFTER : SR_MOVE_FIRST, after_xpath);
    if (SR_ERR_OK != rc) {
        SR_LOG_ERR("Error returned from sr_move_item: %s.", sr_strerror(rc));
    }
    return rc;
}
Beispiel #17
0
/**
 * @brief Convert data tree difference of type LYD_DIFF_DELETED to corresponding set of Sysrepo public API calls.
 */
static int
srcfg_convert_lydiff_deleted(const char *xpath)
{
    CHECK_NULL_ARG(xpath);
    int rc = sr_delete_item(srcfg_session, xpath, SR_EDIT_STRICT);
    if (SR_ERR_OK != rc) {
        SR_LOG_ERR("Error returned from sr_delete_item: %s.", sr_strerror(rc));
    }
    return rc;
}
Beispiel #18
0
int
cl_session_clear_errors(sr_session_ctx_t *session)
{
    CHECK_NULL_ARG(session);

    pthread_mutex_lock(&session->lock);
    session->error_cnt = 0;
    pthread_mutex_unlock(&session->lock);

    return SR_ERR_OK;
}
Beispiel #19
0
sr_error_t
cl_session_return(sr_session_ctx_t *session, sr_error_t error_code)
{
    CHECK_NULL_ARG(session);

    pthread_mutex_lock(&session->lock);
    session->last_error = error_code;
    pthread_mutex_unlock(&session->lock);

    return error_code;
}
Beispiel #20
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		opp_get
 * @BRIEF		return the current voltage domain OPP name
 * @RETURNS		current voltage domain OPP name (as defined in opp.h)
 *			NULL pointer in case of error
 * @param[in]		voltdm: voltage domain name (as defined in voltdm.h)
 * @param[in]		quiet: if == 0, print warning message when OPP
 *			could not be found
 * @DESCRIPTION		return the current voltage domain OPP name. Search it by
 *			voltage first, then if failed search it by rates.
 *//*------------------------------------------------------------------------ */
const char *opp_get(const char *voltdm, unsigned int quiet)
{
	const char *opp = NULL;

	CHECK_NULL_ARG(voltdm, NULL);

	opp_init();

	/*
	 *
	 * Due to Smart-Reflex AVS Class1.5 which dynamically updates nominal
	 * voltages, it is not possible to search OPP using nominal voltages.
	 * Even if SR AVS Class1.5 could be disabled before and
	 * during the search, it is considered too constraining,
	 * as it would reset the voltage and force a new calibration to happen.
	 * Also if it was ever needed to print the current voltage, it would
	 * have to be done before the search, otherwise it may not always show
	 * the converged voltage.
	 *
	 * Another reason to skip it is that we want to be really strict,
	 * then OPP is a strict combination of voltage and frequency.
	 * which means we would have to search by voltage AND by frequency,
	 * and only consider it OK if both are found and are matching.
	 *
	 */
#if 0
	dprintf("%s(%s): searching OPP by voltage first:\n", __func__, voltdm);
	opp = opp_by_voltage_get(voltdm, quiet);
	if (opp != NULL) {
		dprintf("%s(%s): OPP search by voltage succeeded.\n",
			__func__, voltdm);
		goto opp_get_end;
	}
	/*
	 * Could not detect OPP using voltage, try again
	 * using frequencies instead.
	 */
	dprintf("%s(): OPP search by voltage failed, try using rate instead.\n",
		__func__);
#endif
	opp = opp_by_rate_get(voltdm, quiet);

#if 0
opp_get_end:
#endif
	#ifdef OPP_DEBUG
	if (opp != NULL)
		printf("%s(%s): found %s OPP\n", __func__, voltdm, opp);
	else
		printf("%s(%s): OPP not found!\n", __func__, voltdm);
	#endif

	return opp;
}
Beispiel #21
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		_powerdm_info_get
 * @BRIEF		return the saved informations of a given power domain.
 * @RETURNS		0 in case of success
 *			-1 in case of error
 * @param[in]		powerdm: power domain name
 * @param[in,out]	data: power domain details
 * @DESCRIPTION		return the saved informations of a given power domain.
 *//*------------------------------------------------------------------------ */
static int _powerdm_info_get(const char *powerdm, powerdm_info *data)
{
	const genlist *pwrdm_list;
	int i, count;

	CHECK_NULL_ARG(powerdm, -1);
	CHECK_NULL_ARG(data, -1);

	pwrdm_list = powerdm_list_get();
	count = genlist_getcount((genlist *) pwrdm_list);
	for (i = 0; i < count; i++) {
		genlist_get((genlist *) pwrdm_list, i, (void *) data);
		if (strcmp(data->name, powerdm) == 0) {
			dprintf("%s(%s): found.\n", __func__, powerdm);
			return 0;
		}
	}

	dprintf("%s(%s): not found!\n", __func__, powerdm);
	return -1;
}
Beispiel #22
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		ctt44xx_rd1_export
 * @BRIEF		export PRCM registers in CTT RD1 format
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_REG_ACCESS
 *			OMAPCONF_ERR_NOT_AVAILABLE
 * @param[in]		filename: output file name
 * @DESCRIPTION		export PRCM registers in CTT RD1 format
 *//*------------------------------------------------------------------------ */
int ctt44xx_rd1_export(char *filename)
{
	unsigned int i = 0;
	unsigned int ret, val = 0;
	int err = 0;
	FILE *fd = NULL;

	CHECK_CPU(44xx, OMAPCONF_ERR_ARG);
	CHECK_NULL_ARG(filename, OMAPCONF_ERR_ARG);

	fd = fopen(filename, "w");
	if (fd == NULL) {
		printf("error: could not create %s file!\n", filename);
		return OMAPCONF_ERR_NOT_AVAILABLE;
	}

	if (cpu_is_omap4430()) {
		fprintf(fd, "DeviceName OMAP4430_ES2.x\n");
	} else if (cpu_is_omap4460()) {
		fprintf(fd, "DeviceName OMAP4460_ES1.x\n");
	} else if (cpu_is_omap4470()) {
		fprintf(fd, "DeviceName OMAP4470_ES1.0\n");
	} else {
		err = OMAPCONF_ERR_CPU;
		goto ctt44xx_rd1_export_end;
	}

	ctt44xx_regtable_init();

	while (prcm_ctt_reg_table[i].addr != 0) {
		/* display register addr & content (hex) */
		ret = mem_read(prcm_ctt_reg_table[i].addr, &val);
		if (ret == 0)
			fprintf(fd, "0x%08X 0x%08X\n",
				prcm_ctt_reg_table[i].addr, val);
		else {
			fprintf(stderr,
				"omapconf: read error! (addr=0x%08X, err=%d)\n",
				prcm_ctt_reg_table[i].addr, ret);
			err = OMAPCONF_ERR_REG_ACCESS;
		}
		i++;
	}

	printf("Output written to file '%s'.\n", filename);
	err = 0;

ctt44xx_rd1_export_end:
	if (fd != NULL)
		fclose(fd);
	return err;
}
Beispiel #23
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		vc44xx_raw_cmd_values_get
 * @BRIEF		return ON/ONLP/RET/OFF command values
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_ARG
 * @param[in]		id: voltage domain ID
 * @param[in,out]	vc_regs: Voltage Controller registers content
 * @param[in,out]	cmd_on: ON command value (RETURNED)
 * @param[in,out]	cmd_onlp: ONLP command value (RETURNED)
 * @param[in,out]	cmd_ret: RET command value (RETURNED)
 * @param[in,out]	cmd_off: OFF command value (RETURNED)
 * @DESCRIPTION		return ON/ONLP/RET/OFF command values
 *			WARNING: DO NOT CONSIDER PMIC-SPECIFIC SIZE OF COMMAND.
 *//*------------------------------------------------------------------------ */
short int vc44xx_raw_cmd_values_get(voltdm44xx_id id, vc44xx_registers *vc_regs,
	unsigned char *cmd_on, unsigned char *cmd_onlp,
	unsigned char *cmd_ret, unsigned char *cmd_off)
{
	unsigned int vc_val_cmd;

	CHECK_NULL_ARG(cmd_on, OMAPCONF_ERR_ARG);
	CHECK_NULL_ARG(cmd_onlp, OMAPCONF_ERR_ARG);
	CHECK_NULL_ARG(cmd_ret, OMAPCONF_ERR_ARG);
	CHECK_NULL_ARG(cmd_off, OMAPCONF_ERR_ARG);

	/* Command Values Set Selection */
	switch (id) {
	case OMAP4_VDD_MPU:
		vc_val_cmd = vc_regs->prm_vc_val_cmd_vdd_mpu_l;
		break;

	case OMAP4_VDD_IVA:
		if (extract_bit(vc_regs->prm_vc_cfg_channel,
			VC_CFG_CHANNEL_CMD_VDD_IVA_L_POS) == 1)
			vc_val_cmd = vc_regs->prm_vc_val_cmd_vdd_iva_l;
		else
			vc_val_cmd = vc_regs->prm_vc_val_cmd_vdd_core_l;
		break;

	case OMAP4_VDD_CORE:
		vc_val_cmd = vc_regs->prm_vc_val_cmd_vdd_core_l;
		break;

	default:
		return OMAPCONF_ERR_ARG;
	}

	/* Retrieve commands from registers */
	vc_cmd_values_get(vc_val_cmd,
		cmd_on, cmd_onlp, cmd_ret, cmd_off);

	return 0;
}
Beispiel #24
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		opp_dra7xx_id_get
 * @BRIEF		convert OPP provided as a string (as defined in opp.h)
 *			into a plaftorm-specific OPP ID (integer).
 * @RETURNS		plaftorm-specific OPP ID (> 0) in case of success
 *			OMAPCONF_ERR_CPU
 * @param[in]		opp: OPP provided as a string (as defined in opp.h)
 * @DESCRIPTION		convert OPP provided as a string (as defined in opp.h)
 *			into a plaftorm-specific OPP ID (integer).
 *//*------------------------------------------------------------------------ */
int opp_dra7xx_id_get(const char *opp)
{
	CHECK_NULL_ARG(opp, OMAPCONF_ERR_ARG);

	if (strcasecmp(opp, OPP_NOM) == 0)
		return (int) OPP_DRA7XX_NOM;
	else if (strcasecmp(opp, OPP_OD) == 0)
		return (int) OPP_DRA7XX_OD;
	else if (strcasecmp(opp, OPP_HIGH) == 0)
		return (int) OPP_DRA7XX_HIGH;
	else
		return OMAPCONF_ERR_ARG;
}
Beispiel #25
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		temp_sensor_s2id
 * @BRIEF		convert generic temperature sensor name (string)
 *			into platform-specific ID (integer).
 * @RETURNS		>= 0 platform-specific ID
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 * @param[in]		sensor: generic temperature sensor name
 * @DESCRIPTION		convert generic temperature sensor name (string)
 *			into platform-specific ID (integer).
 *			To be used when calling architecture-specific functions.
 *//*------------------------------------------------------------------------ */
int temp_sensor_s2id(const char *sensor)
{
	int id;

	CHECK_NULL_ARG(sensor, OMAPCONF_ERR_ARG);

	if (cpu_is_omap44xx()) {
		if (strcasecmp(sensor, TEMP_SENSOR_BANDGAP) == 0)
			id = (int) TEMP44XX_BANDGAP;
		else if (strcasecmp(sensor, TEMP_SENSOR_HOTSPOT_MPU) == 0)
			id = (int) TEMP44XX_HOTSPOT;
		else if (strcasecmp(sensor, TEMP_SENSOR_MEM1) == 0)
			id = (int) TEMP44XX_DDR1_CS1;
		else if (strcasecmp(sensor, TEMP_SENSOR_MEM2) == 0)
			id = (int) TEMP44XX_DDR2_CS1;
		else if (strcasecmp(sensor, TEMP_SENSOR_PCB) == 0)
			id = (int) TEMP44XX_PCB;
		else
			id = OMAPCONF_ERR_ARG;
	} else if (cpu_is_omap54xx()) {
		if (strcasecmp(sensor, TEMP_SENSOR_MPU) == 0)
			id = (int) TEMP54XX_MPU;
		else if (strcasecmp(sensor, TEMP_SENSOR_HOTSPOT_MPU) == 0)
			id = (int) TEMP54XX_HOTSPOT_MPU;
		else if (strcasecmp(sensor, TEMP_SENSOR_GPU) == 0)
			id = (int) TEMP54XX_GPU;
		else if (strcasecmp(sensor, TEMP_SENSOR_HOTSPOT_GPU) == 0)
			id = (int) TEMP54XX_HOTSPOT_GPU;
		else if (strcasecmp(sensor, TEMP_SENSOR_MEM1) == 0)
			id = (int) TEMP54XX_EMIF1;
		else if (strcasecmp(sensor, TEMP_SENSOR_MEM2) == 0)
			id = (int) TEMP54XX_EMIF2;
		else if (strcasecmp(sensor, TEMP_SENSOR_CORE) == 0)
			id = (int) TEMP54XX_CORE;
		else if (strcasecmp(sensor, TEMP_SENSOR_PCB) == 0)
			id = (int) TEMP54XX_PCB;
		else if (strcasecmp(sensor, TEMP_SENSOR_CASE) == 0)
			id = (int) TEMP54XX_CASE;
		else if (strcasecmp(sensor, TEMP_SENSOR_CHARGER) == 0)
			id = (int) TEMP54XX_CHARGER;
		else
			id = OMAPCONF_ERR_ARG;
	} else {
		fprintf(stderr,
			"omapconf: %s(): cpu not supported!!!\n", __func__);
		id = OMAPCONF_ERR_CPU;
	}

	dprintf("%s(%s) = %d\n", __func__, sensor, id);
	return id;
}
Beispiel #26
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		main_dra7xx_dump
 * @BRIEF		dump some DRA7 registers, which category is found in
 *			argv
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 * @param[in]		argc: number of arguments
 * @param[in]		argv: argument(s)
 * @DESCRIPTION		dump some DRA7 registers, which category is found in
 *			argv
 *//*------------------------------------------------------------------------ */
int main_dra7xx_dump(int argc, char *argv[])
{
	dpll_dra7xx_id dpll_id;
	CHECK_NULL_ARG(argv, OMAPCONF_ERR_ARG);

	if (argc < 1) {
		help(HELP_USAGE);
		return OMAPCONF_ERR_ARG;
	} else if (strcmp(argv[0], "prcm") == 0) {
		if (argc == 1)
			return prcm_dra7xx_dump(NULL);
		else if (argc == 2)
			return prcm_dra7xx_dump(argv[1]);
		else
			return err_arg_too_many_msg_show(HELP_PRCM);
	} else if (strcmp(argv[0], "dpll") == 0) {
		if (argc == 1)
			return dpll_dra7xx_dump(stdout, DPLL_DRA7XX_ID_MAX);
		else if (argc == 2) {
			if (strcmp(argv[1], "all") == 0)
				dpll_id = DPLL_DRA7XX_ID_MAX;
			else {
				dpll_id = dpll_dra7xx_s2id(argv[1]);
				if (dpll_id == DPLL_DRA7XX_ID_MAX)
					return err_arg_msg_show(HELP_DPLL);
			}
			return dpll_dra7xx_dump(stdout, dpll_id);
		}
		else
			return err_arg_too_many_msg_show(HELP_PRCM);
	} else if (strncmp(argv[0], "mcasp", 5) == 0) {
		if (argc == 1) {
			return dra7xx_mcasp_dumpregs(stdout, argc, argv);
		} else {
			return err_arg_too_many_msg_show(HELP_MCASP);
		}
	} else if (strcmp(argv[0], "audioic") == 0) {
		if (argc == 1 || argc == 3)
			return tlv320aic3x_dumpregs(argc, argv);
		else
			return err_arg_too_many_msg_show(HELP_AUDIOIC);
	} else if (!strcmp(argv[0], "crossbar")) {
		if (argc == 1 || argc == 2 || argc == 3) {
			return dra7_crossbar_dump_main(argc - 1, argv + 1);
		} else {
			return err_arg_too_many_msg_show(HELP_CROSSBAR);
		}
	} else {
		return err_unknown_argument_msg_show(argv[0]);
	}
}
Beispiel #27
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		emif54xx_export
 * @BRIEF		export module register content to file, in XML format.
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_REG_ACCESS
 *			OMAPCONF_ERR_INTERNAL
 * @param[in,out]	fp: output file stream (opened for write operations)
 * @param[in]		id: EMIF module ID
 * @DESCRIPTION		export module register content to file, in XML format.
 *//*------------------------------------------------------------------------ */
int emif54xx_export(FILE *fp, emif54xx_mod_id id)
{
	reg **mod;
	unsigned int i, accessible;

	CHECK_CPU(54xx, OMAPCONF_ERR_CPU);
	CHECK_NULL_ARG(fp, OMAPCONF_ERR_ARG);
	CHECK_ARG_LESS_THAN(id, EMIF54XX_MODS_COUNT, OMAPCONF_ERR_ARG);

	switch (id) {
	case EMIF54XX_EMIF1:
		accessible = module_is_accessible(MOD_EMIF1);
		break;
	case EMIF54XX_EMIF2:
		accessible = module_is_accessible(MOD_EMIF2);
		break;
	default: /* should not happen as already checked just before ... */
		return OMAPCONF_ERR_INTERNAL;
	}

	if (!accessible) {
		printf("%s export: module not running, skipping "
			"registers export.\n", emif54xx_mod_name_get(id));
		return 0;
	}

	if (cpu_revision_get() == REV_ES1_0)
		mod = emif54xxes1_mods[id];
	else
		mod = emif54xx_mods[id];

	fprintf(fp, "          <submodule id=\"%u\" name=\"%s\">\n",
		id, emif54xx_mod_name_get(id));

	if (cpu_revision_get() == REV_ES1_0) {
		for (i = 0; i < OMAP5430ES1_EMIF1_MOD_REGCOUNT; i++)
			fprintf(fp, "            <register id=\"%u\" name=\"%s\" "
				"addr=\"0x%08X\" data=\"0x%08X\" />\n", i,
				(mod[i])->name, (mod[i])->addr, reg_read(mod[i]));
	} else {
		for (i = 0; i < OMAP5430_EMIF1_MOD_REGCOUNT; i++)
			fprintf(fp, "            <register id=\"%u\" name=\"%s\" "
				"addr=\"0x%08X\" data=\"0x%08X\" />\n", i,
				(mod[i])->name, (mod[i])->addr, reg_read(mod[i]));
	}

	fprintf(fp, "          </submodule>\n");

	return 0;
}
Beispiel #28
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		powerdm_id_get
 * @BRIEF		return the unique ID of a given power domain.
 * @RETURNS		>= 0 power domain ID
 *			-1 in case of error
 * @param[in]		powerdm: power domain name
 * @DESCRIPTION		return the unique ID of a given power domain.
 *//*------------------------------------------------------------------------ */
int powerdm_id_get(const char *powerdm)
{
	int id;
	powerdm_info data;

	CHECK_NULL_ARG(powerdm, -1);

	id = _powerdm_info_get(powerdm, &data);
	if (id == 0)
		id = data.id;

	dprintf("%s(%s) = %d\n", __func__, powerdm, id);
	return id;
}
Beispiel #29
0
int
cl_session_set_error(sr_session_ctx_t *session, const char *error_message, const char *error_path)
{
    CHECK_NULL_ARG(session);

    pthread_mutex_lock(&session->lock);

    if (0 == session->error_info_size) {
        /* need to allocate the space for the error */
        session->error_info = calloc(1, sizeof(*session->error_info));
        if (NULL == session->error_info) {
            SR_LOG_ERR_MSG("Unable to allocate error information.");
            pthread_mutex_unlock(&session->lock);
            return SR_ERR_NOMEM;
        }
        session->error_info_size = 1;
    } else {
        /* space for the error already allocated, release old error data */
        if (NULL != session->error_info[0].message) {
            free((void*)session->error_info[0].message);
            session->error_info[0].message = NULL;
        }
        if (NULL != session->error_info[0].xpath) {
            free((void*)session->error_info[0].xpath);
            session->error_info[0].xpath = NULL;
        }
    }
    if (NULL != error_message) {
        session->error_info[0].message = strdup(error_message);
        if (NULL == session->error_info[0].message) {
            SR_LOG_ERR_MSG("Unable to allocate error message.");
            pthread_mutex_unlock(&session->lock);
            return SR_ERR_NOMEM;
        }
    }
    if (NULL != error_path) {
        session->error_info[0].xpath = strdup(error_path);
        if (NULL == session->error_info[0].xpath) {
            SR_LOG_ERR_MSG("Unable to allocate error xpath.");
            pthread_mutex_unlock(&session->lock);
            return SR_ERR_NOMEM;
        }
    }

    session->error_cnt = 1;
    pthread_mutex_unlock(&session->lock);

    return SR_ERR_OK;
}
Beispiel #30
0
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		temp_sensor_is_available
 * @BRIEF		check if temperature sensor is available.
 * @RETURNS		1 if temperature sensor is available
 *			0 if temperature sensor is NOT available
 * @param[in]		sensor: generic temperature sensor name
 * @DESCRIPTION		check if temperature sensor is available
 *			(platform-dependent).
 *//*------------------------------------------------------------------------ */
int temp_sensor_is_available(const char *sensor)
{
	int id;

	CHECK_NULL_ARG(sensor, 0);

	id = temp_sensor_s2id(sensor);
	if (id >= 0) {
		dprintf("%s(): %s is available.\n", __func__, sensor);
		return 1;
	} else {
		dprintf("%s(): %s is NOT available.\n", __func__, sensor);
		return 0;
	}
}