FreeBSD/sys/dev/extres/regulator/regulator.c
/*
 * Create and initialize regulator object, but do not register it.
 */
Create and initialize regulator object, but do not register it.
Create and initialize regulator object but do not register it .
struct regnode *
regnode_create(device_t pdev, regnode_class_t regnode_class,
    struct regnode_init_def *def)
{
	struct regnode *regnode;
	KASSERT(def->name != NULL, ("regulator name is NULL"));
	KASSERT(def->name[0] != '\0', ("regulator name is empty"));
	REG_TOPO_SLOCK();
	if (regnode_find_by_name(def->name) != NULL)
		panic("Duplicated regulator registration: %s\n", def->name);
	REG_TOPO_UNLOCK();
	regnode = malloc(sizeof(struct regnode), M_REGULATOR,
	    M_WAITOK | M_ZERO);
	kobj_init((kobj_t)regnode, (kobj_class_t)regnode_class);
	sx_init(&regnode->lock, "Regulator node lock");
	if (regnode_class->size > 0) {
		regnode->softc = malloc(regnode_class->size, M_REGULATOR,
		    M_WAITOK | M_ZERO);
	}
	if (def->flags & REGULATOR_FLAGS_STATIC) {
		regnode->name = def->name;
		regnode->parent_name = def->parent_name;
	} else {
		regnode->name = strdup(def->name, M_REGULATOR);
		if (def->parent_name != NULL)
			regnode->parent_name = strdup(def->parent_name,
			    M_REGULATOR);
	}
	TAILQ_INIT(&regnode->consumers_list);
	regnode->id = def->id;
	regnode->pdev = pdev;
	regnode->flags = def->flags;
	regnode->parent = NULL;
	regnode->std_param = def->std_param;
#ifdef FDT
	regnode->ofw_node = def->ofw_node;
#endif
	return (regnode);
}
struct regnode * regnode_create ( device_t pdev , regnode_class_t regnode_class , struct regnode_init_def * def ) { struct regnode * regnode ; KASSERT ( def -> name != NULL , ( " " ) ) ; KASSERT ( def -> name [ 0 ] != ' \0 ' , ( " " ) ) ; REG_TOPO_SLOCK ( ) ; if ( regnode_find_by_name ( def -> name ) != NULL ) panic ( " \n " , def -> name ) ; REG_TOPO_UNLOCK ( ) ; regnode = malloc ( sizeof ( struct regnode ) , M_REGULATOR , M_WAITOK | M_ZERO ) ; kobj_init ( ( kobj_t ) regnode , ( kobj_class_t ) regnode_class ) ; sx_init ( & regnode -> lock , " " ) ; if ( regnode_class -> size > 0 ) { regnode -> softc = malloc ( regnode_class -> size , M_REGULATOR , M_WAITOK | M_ZERO ) ; } if ( def -> flags & REGULATOR_FLAGS_STATIC ) { regnode -> name = def -> name ; regnode -> parent_name = def -> parent_name ; } else { regnode -> name = strdup ( def -> name , M_REGULATOR ) ; if ( def -> parent_name != NULL ) regnode -> parent_name = strdup ( def -> parent_name , M_REGULATOR ) ; } TAILQ_INIT ( & regnode -> consumers_list ) ; regnode -> id = def -> id ; regnode -> pdev = pdev ; regnode -> flags = def -> flags ; regnode -> parent = NULL ; regnode -> std_param = def -> std_param ; #ifdef FDT regnode -> ofw_node = def -> ofw_node ; #endif return ( regnode ) ; }
Create and initialize regulator object, but do not register it.
Create and initialize regulator object but do not register it .
/* Create object and initialize it. */ /* Allocate softc if required. */ /* Copy all strings unless they're flagged as static. */ /* Rest of init. */