tegra-fuse.c
/*
 * tegra_fuse_context_open
 *
 * Set up a context for working with the fuses.
 */
tegra_fuse_context_open
Set up a context for working with the fuses.
tegra_fuse_context_open Set up a context for working with the fuses .
tegra_fusectx_t
tegra_fuse_context_open (const char *basepath)
{
	tegra_fusectx_t ctx;
	const char *path = (basepath == NULL ? fuse_path : basepath);
	ssize_t typelen;
	tegra_soctype_t soc;
	int fd;
	unsigned long chipid;
	char soctype[65];
	fd = open("/sys/module/tegra_fuse/parameters/tegra_chip_id", O_RDONLY);
	if (fd < 0)
		return NULL;
	typelen = read(fd, soctype, sizeof(soctype)-1);
	close(fd);
	if (typelen < 0)
		return NULL;
	while (typelen > 0 && soctype[typelen-1] == '\n') typelen--;
	soctype[typelen] = '\0';
	chipid = strtoul(soctype, NULL, 10);
	switch (chipid) {
	case 0x18:
		soc = TEGRA_SOCTYPE_186;
		break;
	case 0x19:
		soc = TEGRA_SOCTYPE_194;
		break;
	case 0x21:
		soc = TEGRA_SOCTYPE_210;
		break;
	default:
		errno = ENXIO;
		return NULL;
	}
	ctx = malloc(sizeof(struct tegra_fusectx_s));
	if (ctx == NULL)
		return ctx;
	memset(ctx, 0, sizeof(struct tegra_fusectx_s));
	ctx->soc = soc;
	ctx->sysfd = open(path, O_PATH|O_DIRECTORY);
	if (ctx->sysfd < 0) {
		free(ctx);
		return NULL;
	}
	return ctx;
}
tegra_fusectx_t tegra_fuse_context_open ( const char * basepath ) { tegra_fusectx_t ctx ; const char * path = ( basepath == NULL ? fuse_path : basepath ) ; ssize_t typelen ; tegra_soctype_t soc ; int fd ; unsigned long chipid ; char soctype [ 65 ] ; fd = open ( " " , O_RDONLY ) ; if ( fd < 0 ) return NULL ; typelen = read ( fd , soctype , sizeof ( soctype ) - 1 ) ; close ( fd ) ; if ( typelen < 0 ) return NULL ; while ( typelen > 0 && soctype [ typelen - 1 ] == ' \n ' ) typelen -- ; soctype [ typelen ] = ' \0 ' ; chipid = strtoul ( soctype , NULL , 10 ) ; switch ( chipid ) { case 0x18 : soc = TEGRA_SOCTYPE_186 ; break ; case 0x19 : soc = TEGRA_SOCTYPE_194 ; break ; case 0x21 : soc = TEGRA_SOCTYPE_210 ; break ; default : errno = ENXIO ; return NULL ; } ctx = malloc ( sizeof ( struct tegra_fusectx_s ) ) ; if ( ctx == NULL ) return ctx ; memset ( ctx , 0 , sizeof ( struct tegra_fusectx_s ) ) ; ctx -> soc = soc ; ctx -> sysfd = open ( path , O_PATH | O_DIRECTORY ) ; if ( ctx -> sysfd < 0 ) { free ( ctx ) ; return NULL ; } return ctx ; }
tegra_fuse_context_open
 Set up a context for working with the fuses.
tegra_fuse_context_open Set up a context for working with the fuses .