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; }
bool_t unregister_clocksource(struct clocksource_t * cs) { struct device_t * dev; struct clocksource_t * c; irq_flags_t flags; if(!cs || !cs->name || !cs->read) return FALSE; dev = search_device(cs->name, DEVICE_TYPE_CLOCKSOURCE); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; timer_cancel(&cs->keeper.timer); if(__clocksource == cs) { if(!(c = search_first_clocksource())) c = &__cs_dummy; spin_lock_irqsave(&__clocksource_lock, flags); __clocksource = c; spin_unlock_irqrestore(&__clocksource_lock, flags); } kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_console(struct console_t * console) { struct device_t * dev; struct console_t * c; irq_flags_t flags; if(!console || !console->name) return FALSE; dev = search_device(console->name, DEVICE_TYPE_CONSOLE); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; if(__console == console) { if(!(c = search_first_console())) c = &__console_dummy; spin_lock_irqsave(&__console_lock, flags); __console = c; spin_unlock_irqrestore(&__console_lock, flags); } kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
bool_t unregister_bus_uart(struct uart_t * uart) { struct bus_t * bus; struct uart_t * driver; if(!uart || !uart->name) return FALSE; bus = search_bus_with_type(uart->name, BUS_TYPE_UART); if(!bus) return FALSE; driver = (struct uart_t *)(bus->driver); if(driver && driver->exit) (driver->exit)(uart); if(!unregister_bus(bus)) return FALSE; kobj_remove_self(bus->kobj); free(bus->name); free(bus); return TRUE; }
bool_t unregister_bus_i2c(struct i2c_t * i2c) { struct bus_t * bus; struct i2c_t * driver; if(!i2c || !i2c->name) return FALSE; bus = search_bus_with_type(i2c->name, BUS_TYPE_I2C); if(!bus) return FALSE; driver = (struct i2c_t *)(bus->driver); if(driver && driver->exit) (driver->exit)(i2c); if(!unregister_bus(bus)) return FALSE; kobj_remove_self(bus->kobj); free(bus->name); free(bus); return TRUE; }
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; }
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; }
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; }
bool_t unregister_watchdog(struct watchdog_t * watchdog) { struct device_t * dev; struct watchdog_t * driver; if(!watchdog || !watchdog->name) return FALSE; dev = search_device_with_type(watchdog->name, DEVICE_TYPE_WATCHDOG); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; driver = (struct watchdog_t *)(dev->driver); if(driver) { if(driver->set) (driver->set)(driver, 0); if(driver->exit) (driver->exit)(driver); } kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
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; }
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; }
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; }
bool_t unregister_rtc(struct rtc_t * rtc) { struct device_t * dev; if(!rtc || !rtc->name) return FALSE; dev = search_device(rtc->name, DEVICE_TYPE_RTC); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_block(struct block_t * blk) { struct device_t * dev; if(!blk || !blk->name) return FALSE; dev = search_device(blk->name, DEVICE_TYPE_BLOCK); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_light(struct light_t * light) { struct device_t * dev; if(!light || !light->name) return FALSE; dev = search_device(light->name, DEVICE_TYPE_LIGHT); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_stepper(struct stepper_t * m) { struct device_t * dev; if(!m || !m->name) return FALSE; dev = search_device(m->name, DEVICE_TYPE_STEPPER); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_clk(struct clk_t * clk) { struct device_t * dev; if(!clk || !clk->name) return FALSE; dev = search_device(clk->name, DEVICE_TYPE_CLK); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_battery(struct battery_t * bat) { struct device_t * dev; if(!bat || !bat->name) return FALSE; dev = search_device_with_type(bat->name, DEVICE_TYPE_BATTERY); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_input(struct input_t * input) { struct device_t * dev; if(!input || !input->name) return FALSE; dev = search_device(input->name, DEVICE_TYPE_INPUT); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_buzzer(struct buzzer_t * buzzer) { struct device_t * dev; if(!buzzer || !buzzer->name) return FALSE; dev = search_device(buzzer->name, DEVICE_TYPE_BUZZER); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_i2c(struct i2c_t * i2c) { struct device_t * dev; if(!i2c || !i2c->name) return FALSE; dev = search_device(i2c->name, DEVICE_TYPE_I2C); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }
bool_t unregister_led(struct led_t * led) { struct device_t * dev; if(!led || !led->name) return FALSE; dev = search_device(led->name, DEVICE_TYPE_LED); if(!dev) return FALSE; if(!unregister_device(dev)) return FALSE; kobj_remove_self(dev->kobj); free(dev->name); free(dev); return TRUE; }