Esempio n. 1
0
bool_t register_buzzer(struct device_t ** device, struct buzzer_t * buzzer)
{
	struct device_t * dev;

	if(!buzzer || !buzzer->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(buzzer->name);
	dev->type = DEVICE_TYPE_BUZZER;
	dev->priv = buzzer;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "frequency", buzzer_read_frequency, buzzer_write_frequency, buzzer);
	kobj_add_regular(dev->kobj, "play", NULL, buzzer_write_play, buzzer);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 2
0
bool_t register_ledtrig(struct ledtrig_t * trigger)
{
	struct device_t * dev;

	if(!trigger || !trigger->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(trigger->name);
	dev->type = DEVICE_TYPE_LEDTRIG;
	dev->suspend = ledtrig_suspend;
	dev->resume = ledtrig_resume;
	dev->driver = trigger;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "led", ledtrig_read_bind_led_name, NULL, trigger);
	kobj_add_regular(dev->kobj, "activity", NULL, ledtrig_write_activity, trigger);

	if(trigger->init)
		(trigger->init)(trigger);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	return TRUE;
}
Esempio n. 3
0
bool_t register_bus_uart(struct uart_t * uart)
{
	struct bus_t * bus;

	if(!uart || !uart->name)
		return FALSE;

	bus = malloc(sizeof(struct bus_t));
	if(!bus)
		return FALSE;

	bus->name = strdup(uart->name);
	bus->type = BUS_TYPE_UART;
	bus->driver = uart;
	bus->kobj = kobj_alloc_directory(bus->name);

	if(!register_bus(bus))
	{
		kobj_remove_self(bus->kobj);
		free(bus->name);
		free(bus);
		return FALSE;
	}

	if(uart->init)
		(uart->init)(uart);

	return TRUE;
}
Esempio n. 4
0
File: i2c.c Progetto: IngenicC/xboot
bool_t register_bus_i2c(struct i2c_t * i2c)
{
	struct bus_t * bus;

	if(!i2c || !i2c->name)
		return FALSE;

	bus = malloc(sizeof(struct bus_t));
	if(!bus)
		return FALSE;

	bus->name = strdup(i2c->name);
	bus->type = BUS_TYPE_I2C;
	bus->driver = i2c;
	bus->kobj = kobj_alloc_directory(bus->name);

	if(!register_bus(bus))
	{
		kobj_remove_self(bus->kobj);
		free(bus->name);
		free(bus);
		return FALSE;
	}

	if(i2c->init)
		(i2c->init)(i2c);

	return TRUE;
}
Esempio n. 5
0
bool_t register_i2c(struct device_t ** device, struct i2c_t * i2c)
{
	struct device_t * dev;

	if(!i2c || !i2c->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(i2c->name);
	dev->type = DEVICE_TYPE_I2C;
	dev->priv = i2c;
	dev->kobj = kobj_alloc_directory(dev->name);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 6
0
File: input.c Progetto: xboot/xboot
bool_t register_input(struct device_t ** device, struct input_t * input)
{
	struct device_t * dev;

	if(!input || !input->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(input->name);
	dev->type = DEVICE_TYPE_INPUT;
	dev->driver = NULL;
	dev->priv = input;
	dev->kobj = kobj_alloc_directory(dev->name);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 7
0
bool_t register_rtc(struct device_t ** device, struct rtc_t * rtc)
{
	struct device_t * dev;

	if(!rtc || !rtc->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(rtc->name);
	dev->type = DEVICE_TYPE_RTC;
	dev->priv = rtc;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "time", rtc_time_read, rtc_time_write, rtc);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 8
0
bool_t register_led(struct device_t ** device, struct led_t * led)
{
	struct device_t * dev;

	if(!led || !led->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(led->name);
	dev->type = DEVICE_TYPE_LED;
	dev->priv = led;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "brightness", led_read_brightness, led_write_brightness, led);
	kobj_add_regular(dev->kobj, "max_brightness", led_read_max_brightness, NULL, led);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 9
0
bool_t register_watchdog(struct watchdog_t * watchdog)
{
	struct device_t * dev;

	if(!watchdog || !watchdog->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(watchdog->name);
	dev->type = DEVICE_TYPE_WATCHDOG;
	dev->suspend = watchdog_suspend;
	dev->resume = watchdog_resume;
	dev->driver = watchdog;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "timeout", watchdog_read_timeout, watchdog_write_timeout, watchdog);

	if(watchdog->init)
		(watchdog->init)(watchdog);

	if(watchdog->set)
		(watchdog->set)(watchdog, 0);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	return TRUE;
}
Esempio n. 10
0
bool_t register_ledtrig(struct device_t ** device, struct ledtrig_t * ledtrig)
{
	struct device_t * dev;

	if(!ledtrig || !ledtrig->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(ledtrig->name);
	dev->type = DEVICE_TYPE_LEDTRIG;
	dev->priv = ledtrig;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "activity", NULL, ledtrig_write_activity, ledtrig);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 11
0
bool_t register_stepper(struct device_t ** device, struct stepper_t * m)
{
	struct device_t * dev;

	if(!m || !m->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(m->name);
	dev->type = DEVICE_TYPE_STEPPER;
	dev->driver = NULL;
	dev->priv = m;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "enable", NULL, stepper_write_enable, m);
	kobj_add_regular(dev->kobj, "disable", NULL, stepper_write_disable, m);
	kobj_add_regular(dev->kobj, "move", NULL, stepper_write_move, m);
	kobj_add_regular(dev->kobj, "busying", stepper_read_busying, NULL, m);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 12
0
bool_t register_block(struct device_t ** device, struct block_t * blk)
{
	struct device_t * dev;

	if(!blk || !blk->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(blk->name);
	dev->type = DEVICE_TYPE_BLOCK;
	dev->priv = blk;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "size", block_read_size, NULL, blk);
	kobj_add_regular(dev->kobj, "count", block_read_count, NULL, blk);
	kobj_add_regular(dev->kobj, "capacity", block_read_capacity, NULL, blk);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 13
0
File: light.c Progetto: xboot/xboot
bool_t register_light(struct device_t ** device,struct light_t * light)
{
	struct device_t * dev;

	if(!light || !light->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(light->name);
	dev->type = DEVICE_TYPE_LIGHT;
	dev->driver = NULL;
	dev->priv = light;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "illuminance", light_read_illuminance, NULL, light);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 14
0
bool_t register_clocksource(struct device_t ** device, struct clocksource_t * cs)
{
	struct device_t * dev;
	irq_flags_t flags;

	if(!cs || !cs->name || !cs->read)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	cs->keeper.interval = clocksource_deferment(cs) >> 1;
	cs->keeper.last = clocksource_cycle(cs);
	cs->keeper.nsec = 0;
	seqlock_init(&cs->keeper.lock);
	timer_init(&cs->keeper.timer, clocksource_keeper_timer_function, cs);

	dev->name = strdup(cs->name);
	dev->type = DEVICE_TYPE_CLOCKSOURCE;
	dev->driver = NULL;
	dev->priv = cs;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "mult", clocksource_read_mult, NULL, cs);
	kobj_add_regular(dev->kobj, "shift", clocksource_read_shift, NULL, cs);
	kobj_add_regular(dev->kobj, "period", clocksource_read_period, NULL, cs);
	kobj_add_regular(dev->kobj, "deferment", clocksource_read_deferment, NULL, cs);
	kobj_add_regular(dev->kobj, "cycle", clocksource_read_cycle, NULL, cs);
	kobj_add_regular(dev->kobj, "time", clocksource_read_time, NULL, cs);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(__clocksource == &__cs_dummy)
	{
		spin_lock_irqsave(&__clocksource_lock, flags);
		__clocksource = cs;
		spin_unlock_irqrestore(&__clocksource_lock, flags);
	}
	timer_start_now(&cs->keeper.timer, ns_to_ktime(cs->keeper.interval));

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 15
0
File: dac.c Progetto: xboot/xboot
bool_t register_dac(struct device_t ** device, struct dac_t * dac)
{
	struct device_t * dev;
	char buf[64];
	int i;

	if(!dac || !dac->name || (dac->resolution <= 0) || (dac->nchannel <= 0) || !dac->write)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(dac->name);
	dev->type = DEVICE_TYPE_DAC;
	dev->driver = NULL;
	dev->priv = dac;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "vreference", dac_read_vreference, NULL, dac);
	kobj_add_regular(dev->kobj, "resolution", dac_read_resolution, NULL, dac);
	kobj_add_regular(dev->kobj, "nchannel", dac_read_nchannel, NULL, dac);
	for(i = 0; i< dac->nchannel; i++)
	{
		sprintf(buf, "raw%d", i);
		kobj_add_regular(dev->kobj, buf, NULL, dac_write_raw_channel, dac);
	}
	for(i = 0; i< dac->nchannel; i++)
	{
		sprintf(buf, "voltage%d", i);
		kobj_add_regular(dev->kobj, buf, NULL, dac_write_voltage_channel, dac);
	}

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 16
0
bool_t register_console(struct device_t ** device, struct console_t * console)
{
	struct device_t * dev;
	irq_flags_t flags;

	if(!console || !console->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(console->name);
	dev->type = DEVICE_TYPE_CONSOLE;
	dev->driver = NULL;
	dev->priv = console;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "active", console_read_active, console_write_active, console);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(__console == &__console_dummy)
	{
		spin_lock_irqsave(&__console_lock, flags);
		__console = console;
		spin_unlock_irqrestore(&__console_lock, flags);
	}

	if(device)
		*device = dev;
	return TRUE;
}
Esempio n. 17
0
bool_t register_battery(struct battery_t * bat)
{
	struct device_t * dev;

	if(!bat || !bat->name)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(bat->name);
	dev->type = DEVICE_TYPE_BATTERY;
	dev->suspend = battery_suspend;
	dev->resume = battery_resume;
	dev->driver = bat;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "supply", battery_read_supply, NULL, bat);
	kobj_add_regular(dev->kobj, "status", battery_read_status, NULL, bat);
	kobj_add_regular(dev->kobj, "health", battery_read_health, NULL, bat);
	kobj_add_regular(dev->kobj, "count", battery_read_count, NULL, bat);
	kobj_add_regular(dev->kobj, "capacity", battery_read_capacity, NULL, bat);
	kobj_add_regular(dev->kobj, "voltage", battery_read_voltage, NULL, bat);
	kobj_add_regular(dev->kobj, "current", battery_read_current, NULL, bat);
	kobj_add_regular(dev->kobj, "temperature", battery_read_temperature, NULL, bat);
	kobj_add_regular(dev->kobj, "level", battery_read_level, NULL, bat);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	return TRUE;
}
Esempio n. 18
0
File: clk.c Progetto: xboot/xboot
bool_t register_clk(struct device_t ** device, struct clk_t * clk)
{
	struct device_t * dev;

	if(!clk || !clk->name)
		return FALSE;

	if(search_clk(clk->name))
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	dev->name = strdup(clk->name);
	dev->type = DEVICE_TYPE_CLK;
	dev->driver = NULL;
	dev->priv = clk;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "summary", clk_read_summary, NULL, clk);
	kobj_add_regular(dev->kobj, "parent", clk_read_parent, clk_write_parent, clk);
	kobj_add_regular(dev->kobj, "enable", clk_read_enable, clk_write_enable, clk);
	kobj_add_regular(dev->kobj, "rate", clk_read_rate, clk_write_rate, clk);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(device)
		*device = dev;
	return TRUE;
}