static int get_emmc0_cid(void) { struct device *emmc_disk; /* * Automation people are needing proper serial number for ADB * lets derivate from the serial number of the emmc card. */ emmc_disk = class_find_device(&block_class, NULL, NULL, mmcblk0_match); if (emmc_disk) { struct gendisk *disk = dev_to_disk(emmc_disk); struct mmc_card *card = mmc_dev_to_card(disk->driverfs_dev); if (card) { cid_legacy.manfid = card->cid.manfid; cid_legacy.prod_name[0] = card->cid.prod_name[0]; cid_legacy.prod_name[1] = card->cid.prod_name[1]; cid_legacy.prod_name[2] = card->cid.prod_name[2]; cid_legacy.prod_name[3] = card->cid.prod_name[3]; cid_legacy.prod_name[4] = card->cid.prod_name[4]; cid_legacy.prod_name[5] = card->cid.prod_name[5]; cid_legacy.prod_name[6] = card->cid.prod_name[6]; cid_legacy.prod_name[7] = card->cid.prod_name[7]; cid_legacy.serial = card->cid.serial; cid_legacy.oemid = card->cid.oemid; cid_legacy.year = card->cid.year; cid_legacy.hwrev = card->cid.hwrev; cid_legacy.fwrev = card->cid.fwrev; cid_legacy.month = card->cid.month; snprintf(emmc0_id, sizeof(emmc0_id), "Medfield%08X", jhash(&cid_legacy, sizeof(cid_legacy), 0)); return 1; } } return 0; }
static int __init test_suspend(void) { static char warn_no_rtc[] __initdata = KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n"; char *pony = NULL; struct rtc_device *rtc = NULL; if (test_state == PM_SUSPEND_ON) goto done; if (!valid_state(test_state)) { printk(warn_bad_state, pm_states[test_state]); goto done; } class_find_device(rtc_class, NULL, &pony, has_wakealarm); if (pony) rtc = rtc_class_open(pony); if (!rtc) { printk(warn_no_rtc); goto done; } test_wakealarm(rtc, test_state); rtc_class_close(rtc); done: return 0; }
struct power_supply *power_supply_get_by_name(char *name) { struct device *dev = class_find_device(power_supply_class, NULL, name, power_supply_match_device_by_name); return dev ? dev_get_drvdata(dev) : NULL; }
static int __init test_suspend(void) { static char warn_no_rtc[] __initdata = KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n"; char *pony = NULL; struct rtc_device *rtc = NULL; /* PM is initialized by now; is that state testable? */ if (test_state == PM_SUSPEND_ON) goto done; if (!valid_state(test_state)) { printk(warn_bad_state, pm_states[test_state]); goto done; } /* RTCs have initialized by now too ... can we use one? */ class_find_device(rtc_class, NULL, &pony, has_wakealarm); if (pony) rtc = rtc_class_open(pony); if (!rtc) { printk(warn_no_rtc); goto done; } /* go for it */ test_wakealarm(rtc, test_state); rtc_class_close(rtc); done: return 0; }
static struct block_device *get_emmc_bdev(void) { struct block_device *bdev; struct device *emmc_disk; emmc_disk = class_find_device(&block_class, NULL, NULL, mmcblk0boot0_match); if (emmc_disk == 0) { pr_err("emmc not found!\n"); return NULL; } /* partition 0 means raw disk */ bdev = bdget_disk(dev_to_disk(emmc_disk), 0); if (bdev == NULL) { dev_err(emmc_disk, "unable to get disk\n"); return NULL; } /* Note: this bdev ref will be freed after first * bdev_get/bdev_put cycle */ return bdev; }
/** * alarmtimer_get_rtcdev - Return selected rtcdevice * * This function returns the rtc device to use for wakealarms. * If one has not already been chosen, it checks to see if a * functional rtc device is available. */ static struct rtc_device *alarmtimer_get_rtcdev(void) { struct device *dev; char *str; unsigned long flags; struct rtc_device *ret; spin_lock_irqsave(&rtcdev_lock, flags); if (!rtcdev) { /* Find an rtc device and init the rtc_timer */ dev = class_find_device(rtc_class, NULL, &str, has_wakealarm); /* If we have a device then str is valid. See has_wakealarm() */ if (dev) { rtcdev = rtc_class_open(str); /* * Drop the reference we got in class_find_device, * rtc_open takes its own. */ put_device(dev); rtc_timer_init(&rtctimer, NULL, NULL); } } ret = rtcdev; spin_unlock_irqrestore(&rtcdev_lock, flags); return ret; }
/** * devt_from_partuuid - looks up the dev_t of a partition by its UUID * @uuid: min 36 byte char array containing a hex ascii UUID * * The function will return the first partition which contains a matching * UUID value in its partition_meta_info struct. This does not search * by filesystem UUIDs. * * If @uuid is followed by a "/PARTNROFF=%d", then the number will be * extracted and used as an offset from the partition identified by the UUID. * * Returns the matching dev_t on success or 0 on failure. */ static dev_t devt_from_partuuid(char *uuid_str) { dev_t res = 0; struct device *dev = NULL; u8 uuid[16]; struct gendisk *disk; struct hd_struct *part; int offset = 0; if (strlen(uuid_str) < 36) goto done; /* Check for optional partition number offset attributes. */ if (uuid_str[36]) { char c = 0; /* Explicitly fail on poor PARTUUID syntax. */ if (sscanf(&uuid_str[36], "/PARTNROFF=%d%c", &offset, &c) != 1) { printk(KERN_ERR "VFS: PARTUUID= is invalid.\n" "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n"); if (root_wait) printk(KERN_ERR "Disabling rootwait; root= is invalid.\n"); root_wait = 0; goto done; } } /* Pack the requested UUID in the expected format. */ part_pack_uuid(uuid_str, uuid); dev = class_find_device(&block_class, NULL, uuid, &match_dev_by_uuid); if (!dev) goto done; res = dev->devt; /* Attempt to find the partition by offset. */ if (!offset) goto no_offset; res = 0; disk = part_to_disk(dev_to_part(dev)); part = disk_get_part(disk, dev_to_part(dev)->partno + offset); if (part) { res = part_devt(part); put_device(part_to_dev(part)); } no_offset: put_device(dev); done: return res; }
/** * tegra_get_linear_age - helper function to return linear age * from Jan 2012. * * @return * 1 - Jan 2012, * 2 - Feb 2012, * ..... * 13 - Jan 2013 */ int tegra_get_linear_age(void) { struct rtc_time tm; int year, month, linear_age; struct rtc_device *rtc_dev = NULL; const char *name = NULL; int ret; struct device *dev = NULL; linear_age = -1; year = month = 0; dev = class_find_device(rtc_class, NULL, &name, has_readtime); if (!dev) { pr_err("DVFS: No device with readtime capability\n"); goto done; } name = dev_name(dev); pr_info("DVFS: Got RTC device name:%s\n", name); if (name) rtc_dev = rtc_class_open((char *)name); if (!rtc_dev) { pr_err("DVFS: No RTC device\n"); goto error_dev; } ret = rtc_read_time(rtc_dev, &tm); if (ret < 0) { pr_err("DVFS: Can't read RTC time\n"); goto error_rtc; } year = tm.tm_year; /*Normalize it to 2012*/ year -= 112; month = tm.tm_mon + 1; if (year >= 0) linear_age = year * 12 + month; error_rtc: rtc_class_close(rtc_dev); error_dev: put_device(dev); done: return linear_age; }
struct wpan_phy *wpan_phy_find(const char *str) { struct device *dev; if (WARN_ON(!str)) return NULL; dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match); if (!dev) return NULL; return container_of(dev, struct wpan_phy, dev); }
static struct device *get_fb_dev(void) { struct device *fbdev = NULL; /* get the first framebuffer device */ /* [TODO] Handle properly when there are more than one framebuffer */ fbdev = class_find_device(fb_class, NULL, NULL, is_device_ok); if (NULL == fbdev) { pr_debug("ERROR cannot get framebuffer device\n"); return NULL; } return fbdev; }
/** * alarmpwr_get_rtcdev - Return power up rtcdevice * * This function returns the rtc device to power up for wakealarms. * If one has not already been chosen, it checks to see if a * functional rtc device is available. */ struct rtc_device *alarmpwr_get_rtcdev(void) { struct rtc_device *ret; struct device *dev; dev = class_find_device(rtc_class, NULL, NULL, rtc_match); if (dev == NULL) return NULL; ret = to_rtc_device(dev); return ret; }
int pwm_register_byname(struct pwm_device *p, struct device *parent, const char *name) { struct device *d; int ret; if (!p->ops || !p->ops->config) return -EINVAL; mutex_lock(&device_list_mutex); d = class_find_device(&pwm_class, NULL, (char *)name, pwm_match_name); if (d) { ret = -EEXIST; goto err_found_device; } p->dev = device_create(&pwm_class, parent, MKDEV(0, 0), NULL, name); if (IS_ERR(p->dev)) { ret = PTR_ERR(p->dev); goto err_device_create; } ret = sysfs_create_group(&p->dev->kobj, &pwm_device_attr_group); if (ret) goto err_create_group; dev_set_drvdata(p->dev, p); p->flags = BIT(FLAG_REGISTERED); ret = pwm_cpufreq_notifier_register(p); if (ret < 0) printk(KERN_ERR "Failed to add cpufreq notifier\n"); spin_lock_init(&p->pwm_lock); goto done; err_create_group: device_unregister(p->dev); p->flags = 0; err_device_create: err_found_device: done: mutex_unlock(&device_list_mutex); return ret; }
static int led_classdev_next_name(const char *init_name, char *name, size_t len) { unsigned int i = 0; int ret = 0; strlcpy(name, init_name, len); while (class_find_device(leds_class, NULL, name, match_name) && (ret < len)) ret = snprintf(name, len, "%s_%u", init_name, ++i); if (ret >= len) return -ENOMEM; return i; }
struct rtc_device *rtc_class_open(const char *name) { struct device *dev; struct rtc_device *rtc = NULL; dev = class_find_device(rtc_class, NULL, name, __rtc_match); if (dev) rtc = to_rtc_device(dev); if (rtc) { if (!try_module_get(rtc->owner)) { put_device(dev); rtc = NULL; } } return rtc; }
static int __devinit suspend_autotest_probe(struct platform_device *pdev) { int err; char *pony = NULL; pwr_dev = input_allocate_device(); if (!pwr_dev) { pr_err("Can't allocate suspend autotest power button\n"); err = -ENOMEM; goto err_alloc_dev; } input_set_capability(pwr_dev, EV_KEY, KEY_POWER); pwr_dev->name = "suspend_autotest_pwrkey"; pwr_dev->phys = "suspend_autotest_pwrkey/input0"; err = input_register_device(pwr_dev); if (err) { pr_err("%s: input_register_device err=%d\n", __func__, err); goto err_input_dev; } /* RTCs have initialized by now too ... can we use one? */ class_find_device(rtc_class, NULL, &pony, has_wakealarm); if (pony) rtc = rtc_class_open(pony); if (!rtc) { pr_info("%s: rtc class fail\n",__func__); goto err_input_dev; } wake_lock_init(&test_wake_lock, WAKE_LOCK_SUSPEND, "suspend_autotest"); register_early_suspend(&suspend_autotest_earlysuspend); test_mode = NONE; return 0; err_input_dev: input_free_device(pwr_dev); err_alloc_dev: return err; }
/** * devt_from_partuuid - looks up the dev_t of a partition by its UUID * @uuid: 36 byte char array containing a hex ascii UUID * * The function will return the first partition which contains a matching * UUID value in its partition_meta_info struct. This does not search * by filesystem UUIDs. * * Returns the matching dev_t on success or 0 on failure. */ static dev_t devt_from_partuuid(char *uuid_str) { dev_t res = 0; struct device *dev = NULL; u8 uuid[16]; /* Pack the requested UUID in the expected format. */ part_pack_uuid(uuid_str, uuid); dev = class_find_device(&block_class, NULL, uuid, &match_dev_by_uuid); if (!dev) goto done; res = dev->devt; put_device(dev); done: return res; }
static struct pwm_device *__pwm_request_byname(const char *name, const char *label) { struct device *d; struct pwm_device *p; d = class_find_device(&pwm_class, NULL, (char *)name, pwm_match_name); if (!d) { p = ERR_PTR(-EINVAL); goto done; } if (IS_ERR(d)) { p = (struct pwm_device *)d; goto done; } p = __pwm_request(dev_get_drvdata(d), label); done: return p; }
static int __init test_suspend(void) { static char warn_no_rtc[] __initdata = KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n"; struct rtc_device *rtc = NULL; struct device *dev; suspend_state_t test_state; /* PM is initialized by now; is that state testable? */ if (!test_state_label) return 0; for (test_state = PM_SUSPEND_MIN; test_state < PM_SUSPEND_MAX; test_state++) { const char *state_label = pm_states[test_state]; if (state_label && !strcmp(test_state_label, state_label)) break; } if (test_state == PM_SUSPEND_MAX) { printk(warn_bad_state, test_state_label); return 0; } /* RTCs have initialized by now too ... can we use one? */ dev = class_find_device(rtc_class, NULL, NULL, has_wakealarm); if (dev) { rtc = rtc_class_open(dev_name(dev)); put_device(dev); } if (!rtc) { printk(warn_no_rtc); return 0; } /* go for it */ test_wakealarm(rtc, test_state); rtc_class_close(rtc); return 0; }
static int sony_ric_bdev_mount(const char *dev_name, struct path *path, struct inode *inode, unsigned long flags) { struct device *dev; struct hd_struct *part; int ret = 0; dev = class_find_device(&block_class, NULL, &inode->i_rdev, &match_device_by_devt); if (!dev) return ret; part = dev_to_part(dev); if (!part->info) { pr_debug("RIC: No partition info for %s\n", dev_name); goto done; } ret = sony_ric_bdev_mount_perm(part->info->volname, path, flags); done: put_device(dev); return ret; }
/** * of_fpga_bridge_get - get an exclusive reference to a fpga bridge * * @np: node pointer of a FPGA bridge * @info: fpga image specific information * * Return fpga_bridge struct if successful. * Return -EBUSY if someone already has a reference to the bridge. * Return -ENODEV if @np is not a FPGA Bridge. */ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np, struct fpga_image_info *info) { struct device *dev; struct fpga_bridge *bridge; int ret = -ENODEV; dev = class_find_device(fpga_bridge_class, NULL, np, fpga_bridge_of_node_match); if (!dev) goto err_dev; bridge = to_fpga_bridge(dev); if (!bridge) goto err_dev; bridge->info = info; if (!mutex_trylock(&bridge->mutex)) { ret = -EBUSY; goto err_dev; } if (!try_module_get(dev->parent->driver->owner)) goto err_ll_mod; dev_dbg(&bridge->dev, "get\n"); return bridge; err_ll_mod: mutex_unlock(&bridge->mutex); err_dev: put_device(dev); return ERR_PTR(ret); }
dev_t name_to_dev_t(char *name) { char s[32]; char *p; dev_t res = 0; struct device *dev = NULL; int part; #ifdef CONFIG_BLOCK if (strncmp(name, "PARTUUID=", 9) == 0) { name += 9; res = devt_from_partuuid(name); if (!res) goto fail; goto done; } #endif if (strncmp(name, "/dev/", 5) != 0) { unsigned maj, min; if (sscanf(name, "%u:%u", &maj, &min) == 2) { res = MKDEV(maj, min); if (maj != MAJOR(res) || min != MINOR(res)) goto fail; } else { res = new_decode_dev(simple_strtoul(name, &p, 16)); if (*p) goto fail; } goto done; } name += 5; res = Root_NFS; if (strcmp(name, "nfs") == 0) goto done; res = Root_RAM0; if (strcmp(name, "ram") == 0) goto done; if (strlen(name) > 31) goto fail; strcpy(s, name); for (p = s; *p; p++) if (*p == '/') *p = '!'; res = blk_lookup_devt(s, 0); if (res) goto done; dev = class_find_device(&block_class, NULL, name, &match_dev_by_name); if (dev) { res = dev->devt; goto done; } /* * try non-existent, but valid partition, which may only exist * after revalidating the disk, like partitioned md devices */ while (p > s && isdigit(p[-1])) p--; if (p == s || !*p || *p == '0') goto fail; /* try disk name without <part number> */ part = simple_strtoul(p, NULL, 10); *p = '\0'; res = blk_lookup_devt(s, part); if (res) goto done; /* try disk name without p<part number> */ if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p') goto fail; p[-1] = '\0'; res = blk_lookup_devt(s, part); if (res) goto done; fail: return 0; done: return res; }
/** * devt_from_partuuid - looks up the dev_t of a partition by its UUID * @uuid: char array containing ascii UUID * * The function will return the first partition which contains a matching * UUID value in its partition_meta_info struct. This does not search * by filesystem UUIDs. * * If @uuid is followed by a "/PARTNROFF=%d", then the number will be * extracted and used as an offset from the partition identified by the UUID. * * Returns the matching dev_t on success or 0 on failure. */ static dev_t devt_from_partuuid(const char *uuid_str) { dev_t res = 0; struct uuidcmp cmp; struct device *dev = NULL; struct gendisk *disk; struct hd_struct *part; int offset = 0; bool clear_root_wait = false; char *slash; cmp.uuid = uuid_str; slash = strchr(uuid_str, '/'); /* Check for optional partition number offset attributes. */ if (slash) { char c = 0; /* Explicitly fail on poor PARTUUID syntax. */ if (sscanf(slash + 1, "PARTNROFF=%d%c", &offset, &c) != 1) { clear_root_wait = true; goto done; } cmp.len = slash - uuid_str; } else { cmp.len = strlen(uuid_str); } if (!cmp.len) { clear_root_wait = true; goto done; } dev = class_find_device(&block_class, NULL, &cmp, &match_dev_by_uuid); if (!dev) goto done; res = dev->devt; /* Attempt to find the partition by offset. */ if (!offset) goto no_offset; res = 0; disk = part_to_disk(dev_to_part(dev)); part = disk_get_part(disk, dev_to_part(dev)->partno + offset); if (part) { res = part_devt(part); put_device(part_to_dev(part)); } no_offset: put_device(dev); done: if (clear_root_wait) { pr_err("VFS: PARTUUID= is invalid.\n" "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n"); if (root_wait) pr_err("Disabling rootwait; root= is invalid.\n"); root_wait = 0; } return res; }
static int ev3_uart_open(struct tty_struct *tty) { struct ktermios old_termios = tty->termios; struct ev3_uart_port_data *port; struct device *in_port_dev; port = kzalloc(sizeof(struct ev3_uart_port_data), GFP_KERNEL); if (!port) return -ENOMEM; port->tty = tty; port->new_baud_rate = EV3_UART_SPEED_MIN; port->type_id = EV3_UART_TYPE_UNKNOWN; port->sensor.name = port->device_name; /* * This is a special case for the input ports on the EV3 brick. * We use the name of the input port instead of the tty to make * it easier to know which sensor is which. */ in_port_dev = class_find_device(&lego_port_class, NULL, port->tty->name, ev3_uart_match_input_port); if (in_port_dev) { port->in_port = to_lego_port_device(in_port_dev); port->sensor.address = port->in_port->address; } else { port->sensor.address = port->tty->name; } port->sensor.mode_info = port->mode_info; port->sensor.set_mode = ev3_uart_set_mode; port->sensor.direct_write = ev3_uart_direct_write; port->circ_buf.buf = port->buffer; INIT_WORK(&port->rx_data_work, ev3_uart_handle_rx_data); INIT_DELAYED_WORK(&port->send_ack_work, ev3_uart_send_ack); INIT_WORK(&port->change_bitrate_work, ev3_uart_change_bitrate); hrtimer_init(&port->keep_alive_timer, HRTIMER_BASE_MONOTONIC, HRTIMER_MODE_REL); port->keep_alive_timer.function = ev3_uart_keep_alive_timer_callback; tasklet_init(&port->keep_alive_tasklet, ev3_uart_send_keep_alive, (unsigned long)tty); init_completion(&port->set_mode_completion); tty->disc_data = port; /* set baud rate and other port settings */ down_write(&tty->termios_rwsem); tty->termios.c_iflag &= ~(IGNBRK /* disable ignore break */ | BRKINT /* disable break causes interrupt */ | PARMRK /* disable mark parity errors */ | ISTRIP /* disable clear high bit of input characters */ | INLCR /* disable translate NL to CR */ | IGNCR /* disable ignore CR */ | ICRNL /* disable translate CR to NL */ | IXON); /* disable enable XON/XOFF flow control */ /* disable postprocess output characters */ tty->termios.c_oflag &= ~OPOST; tty->termios.c_lflag &= ~(ECHO /* disable echo input characters */ | ECHONL /* disable echo new line */ | ICANON /* disable erase, kill, werase, and rprnt special characters */ | ISIG /* disable interrupt, quit, and suspend special characters */ | IEXTEN); /* disable non-POSIX special characters */ /* 2400 baud, 8bits, no parity, 1 stop */ tty->termios.c_cflag = B2400 | CS8 | CREAD | HUPCL | CLOCAL; tty->ops->set_termios(tty, &old_termios); up_write(&tty->termios_rwsem); tty->ops->tiocmset(tty, 0, ~0); /* clear all */ tty->receive_room = 65536; tty->port->low_latency = 1; // does not do anything since kernel 3.12 /* flush any existing data in the buffer */ if (tty->ldisc->ops->flush_buffer) tty->ldisc->ops->flush_buffer(tty); tty_driver_flush_buffer(tty); return 0; }
}; static struct class flashlight_class = { .name = FLASHLIGHT_CLASS_NAME, .class_attrs = flashlight_class_attrs, .owner = THIS_MODULE, }; static int flashlight_device_match(struct device *dev, void *data) { return (!strcmp(dev->kobj.name,(const char*)data)); } struct device *flashlight_class_to_device(struct class *cla) { struct device *dev; dev = class_find_device(cla, NULL, (void*)cla->name,flashlight_device_match); if (!dev) printk("%s:%s no matched device found!\n",FLASHLIGHT_MODULE_NAME,__FUNCTION__); return dev; } static ssize_t flashlight_ctrl(struct class *cla, struct class_attribute *attr, const char *buf, size_t count) { aml_plat_flashlight_data_t *pdata = NULL; struct device *dev = NULL; dev = flashlight_class_to_device(cla); pdata = (aml_plat_flashlight_data_t *)dev->platform_data; if(pdata == NULL){ printk("%s platform data is required!\n",__FUNCTION__); return -1; }