static s32_t devfs_lookup(struct vnode * dnode, char * name, struct vnode * node) { struct device * dev; struct chrdev * chr; struct blkdev * blk; dev = search_device(name); if(dev == NULL) return -1; if(dev->type == CHAR_DEVICE) { chr = (struct chrdev *)(dev->priv); node->v_type = VCHR; node->v_size = 0; } else if(dev->type == BLOCK_DEVICE) { blk = (struct blkdev *)(dev->priv); node->v_type = VBLK; node->v_size = get_blkdev_total_size(blk); } else { return -1; } node->v_data = (void *)dev; node->v_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; return 0; }
/* Called after the relocation - use desired console functions */ int console_init_r (void) { device_t *inputdev = NULL, *outputdev = NULL; int i; struct list_head *list = device_get_list(); struct list_head *pos; device_t *dev; serial_dev = search_device (DEV_FLAGS_OUTPUT, "serial"); #ifdef CONFIG_SPLASH_SCREEN /* suppress all output if splash screen is enabled and we have a bmp to display */ if (getenv("splashimage") != NULL) gd->flags |= GD_FLG_SILENT; #endif /* Scan devices looking for input and output devices */ list_for_each(pos, list) { dev = list_entry(pos, device_t, list); if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; } if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } if(inputdev && outputdev) break; }
/* Called after the relocation - use desired console functions */ int console_init_r(void) { struct stdio_dev *inputdev = NULL, *outputdev = NULL; int i; struct list_head *list = stdio_get_list(); struct list_head *pos; struct stdio_dev *dev; #ifdef CONFIG_SPLASH_SCREEN /* * suppress all output if splash screen is enabled and we have * a bmp to display. We redirect the output from frame buffer * console to serial console in this case or suppress it if * "silent" mode was requested. */ if (getenv("splashimage") != NULL) { if (!(gd->flags & GD_FLG_SILENT)) outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); } #endif /* Scan devices looking for input and output devices */ list_for_each(pos, list) { dev = list_entry(pos, struct stdio_dev, list); if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; } if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } if(inputdev && outputdev) break; }
int console_assign(int file, const char *devname) { int flag; struct stdio_dev *dev; /* Check for valid file */ switch (file) { case stdin: flag = DEV_FLAGS_INPUT; break; case stdout: case stderr: flag = DEV_FLAGS_OUTPUT; break; default: return -1; } /* Check for valid device name */ dev = search_device(flag, devname); if (dev) return console_setfile(file, dev); return -1; }
/* * register a device into device_list */ bool_t register_device(struct device * dev) { struct device_list * list; list = malloc(sizeof(struct device_list)); if(!list || !dev) { free(list); return FALSE; } if(!dev->name || search_device(dev->name)) { free(list); return FALSE; } if((dev->type != CHAR_DEVICE) && (dev->type != BLOCK_DEVICE) && (dev->type != NET_DEVICE)) { free(list); return FALSE; } if(!dev->priv) { free(list); return FALSE; } list->device = dev; list_add(&list->entry, &device_list->entry); 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 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; }
struct light_t * search_light(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_LIGHT); if(!dev) return NULL; return (struct light_t *)dev->priv; }
struct clocksource_t * search_clocksource(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_CLOCKSOURCE); if(!dev) return NULL; return (struct clocksource_t *)dev->priv; }
struct console_t * search_console(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_CONSOLE); if(!dev) return NULL; return (struct console_t *)dev->priv; }
struct clk_t * search_clk(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_CLK); if(!dev) return NULL; return (struct clk_t *)dev->priv; }
struct dac_t * search_dac(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_DAC); if(!dev) return NULL; return (struct dac_t *)dev->priv; }
struct input_t * search_input(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_INPUT); if(!dev) return NULL; return (struct input_t *)dev->priv; }
struct stepper_t * search_stepper(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_STEPPER); if(!dev) return NULL; return (struct stepper_t *)dev->priv; }
struct block_t * search_block(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_BLOCK); if(!dev) return NULL; return (struct block_t *)dev->priv; }
struct buzzer_t * search_buzzer(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_BUZZER); if(!dev) return NULL; return (struct buzzer_t *)dev->priv; }
struct led_t * search_led(const char * name) { struct device_t * dev; dev = search_device(name, DEVICE_TYPE_LED); if(!dev) return NULL; return (struct led_t *)dev->priv; }
static int init(void) { const char* device; snd_hwdep_info_t* info; struct pollfd pollfd; int err; device = drv.device; if (!device || !*device) { device = search_device(); if (!device) { logprintf(LIRC_ERROR, "device not found"); return 0; } } err = snd_hwdep_open(&hwdep, device, SND_HWDEP_OPEN_READ); if (err < 0) { logprintf(LIRC_ERROR, "cannot open %s: %s", device, snd_strerror(err)); return 0; } snd_hwdep_info_alloca(&info); err = snd_hwdep_info(hwdep, info); if (err < 0) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "cannot get hwdep info: %s", snd_strerror(err)); return 0; } if (snd_hwdep_info_get_iface(info) != SND_HWDEP_IFACE_SB_RC) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "%s is not a Sound Blaster remote control device", device); return 0; } err = snd_hwdep_poll_descriptors(hwdep, &pollfd, 1); if (err < 0) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "cannot get file descriptor: %s", snd_strerror(err)); return 0; } if (err != 1) { snd_hwdep_close(hwdep); logprintf(LIRC_ERROR, "invalid number of file descriptors (%d): %s", err, snd_strerror(err)); return 0; } drv.fd = pollfd.fd; return 1; }
/* * vnode operations */ static s32_t devfs_open(struct vnode * node, s32_t flag) { struct device * dev; struct chrdev * chr; struct blkdev * blk; s8_t * path; path = (s8_t *)node->v_path; if(!strcmp((const char *)path, (const char *)"/")) return 0; if(*path == '/') path++; dev = search_device((const char *)path); if(dev == NULL) return -1; if(dev->type == CHAR_DEVICE) { chr = (struct chrdev *)(dev->priv); if(chr->open(chr) != 0) return -1; } else if(dev->type == BLOCK_DEVICE) { blk = (struct blkdev *)(dev->priv); if(blk->open(blk) != 0) return -1; } else { return -1; } /* * store private data */ node->v_data = (void *)dev; return 0; }
int main(int argc, char **argv) { //parse the input parameters to get the bus number and device number int l_busNum, l_devNum; int l_ret; printf("program started!\n"); if (argc < 3) { printf("not enough arguments!\n"); printf("usage: ./usbreset <bus number> <dev number>\n"); return 0; } printf("bus number: %s\n", argv[1]); printf("dev number: %s\n", argv[2]); l_busNum = atoi(argv[1]); l_devNum = atoi(argv[2]); printf("bus number: %d; dev number: %d\n", l_busNum, l_devNum); l_ret = libusb_init(NULL); if (l_ret < 0) { return l_ret; } l_ret = libusb_get_device_list(NULL, &devs); if (l_ret < 0) { return (int) l_ret; } dev = search_device(l_busNum, l_devNum); if (dev == NULL) { printf("device not found\n"); return 0; } l_ret = libusb_open(dev, &devh); if (l_ret == 0) { printf("got the usb handle successfully.\n"); } else { printf("error getting usb handle.\n"); } //reset the usb device resetUSB(); //free the device list libusb_free_device_list(devs, 1); libusb_exit(NULL); return 0; }
/* * unregister char device from chrdev_list */ bool_t unregister_chrdev(const char * name) { struct device * device; if(!name) return FALSE; device = search_device(name); if(!device && device->type == CHAR_DEVICE) return FALSE; if(unregister_device(device)) { free(device); return TRUE; } return FALSE; }
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_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_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_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_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_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; }
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_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; }