static int mc_probe(struct device_d *dev, enum mc34708_mode mode) { int rev; if (mc_dev) return -EBUSY; mc_dev = xzalloc(sizeof(struct mc34708)); mc_dev->mode = mode; mc_dev->cdev.name = DRIVERNAME; if (mode == MC34708_MODE_I2C) { mc_dev->client = to_i2c_client(dev); } if (mode == MC34708_MODE_SPI) { mc_dev->spi = dev->type_data; mc_dev->spi->mode = SPI_MODE_0 | SPI_CS_HIGH; mc_dev->spi->bits_per_word = 32; } mc_dev->cdev.size = 256; mc_dev->cdev.dev = dev; mc_dev->cdev.ops = &mc_fops; rev = mc34708_query_revision(mc_dev); if (rev < 0) { free(mc_dev); mc_dev = NULL; return -EINVAL; } devfs_create(&mc_dev->cdev); return 0; }
int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol) { struct cdev *cdev = &vol->cdev; struct ubi_volume_cdev_priv *priv; int ret; priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv->vol = vol; priv->ubi = ubi; cdev->ops = &ubi_volume_fops; cdev->name = asprintf("ubi%d.%s", ubi->ubi_num, vol->name); cdev->priv = priv; cdev->size = vol->used_bytes; cdev->dev = &vol->dev; ubi_msg("registering %s as /dev/%s\n", vol->name, cdev->name); ret = devfs_create(cdev); if (ret) { kfree(priv); free(cdev->name); } list_add_tail(&vol->list, &ubi_volumes_list); return 0; }
static int stmpe_probe(struct device_d *dev) { struct stmpe_platform_data *pdata = dev->platform_data; struct stmpe *stmpe_dev; struct stmpe_client_info *i2c_ci; if (!pdata) { dev_dbg(dev, "no platform data\n"); return -ENODEV; } stmpe_dev = xzalloc(sizeof(struct stmpe)); stmpe_dev->cdev.name = DRIVERNAME; stmpe_dev->client = to_i2c_client(dev); stmpe_dev->cdev.size = 191; /* 191 known registers */ stmpe_dev->cdev.dev = dev; stmpe_dev->cdev.ops = &stmpe_fops; stmpe_dev->pdata = pdata; dev->priv = stmpe_dev; i2c_ci = xzalloc(sizeof(struct stmpe_client_info)); i2c_ci->stmpe = stmpe_dev; i2c_ci->read_reg = stmpe_reg_read; i2c_ci->write_reg = stmpe_reg_write; if (pdata->blocks &= STMPE_BLOCK_GPIO) add_generic_device("stmpe-gpio", DEVICE_ID_DYNAMIC, NULL, 0, 0, IORESOURCE_MEM, i2c_ci); devfs_create(&stmpe_dev->cdev); return 0; }
static int mxs_ocotp_probe(struct device_d *dev) { int err; struct ocotp_priv *priv = xzalloc(sizeof (*priv)); priv->base = dev_request_mem_region(dev, 0); if (IS_ERR(priv->base)) return PTR_ERR(priv->base); priv->clk = clk_get(dev, NULL); if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk); priv->cdev.dev = dev; priv->cdev.ops = &mxs_ocotp_ops; priv->cdev.priv = priv; priv->cdev.size = cpu_is_mx23() ? 128 : 160; priv->cdev.name = DRIVERNAME; err = devfs_create(&priv->cdev); if (err < 0) return err; if (IS_ENABLED(CONFIG_MXS_OCOTP_WRITABLE)) { mxs_ocotp_ops.write = mxs_ocotp_cdev_write; dev_add_param_bool(dev, "permanent_write_enable", NULL, NULL, &priv->write_enable, NULL); } return 0; }
int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol) { struct cdev *cdev = &vol->cdev; struct ubi_volume_cdev_priv *priv; int ret; priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv->vol = vol; priv->ubi = ubi; cdev->ops = &ubi_volume_fops; cdev->name = basprintf("%s.%s", ubi->cdev.name, vol->name); cdev->priv = priv; cdev->size = vol->used_bytes; if (vol->vol_type == UBI_STATIC_VOLUME) cdev->flags = DEVFS_IS_CHARACTER_DEV; cdev->dev = &vol->dev; ubi_msg(ubi, "registering %s as /dev/%s", vol->name, cdev->name); ret = devfs_create(cdev); if (ret) { kfree(priv); free(cdev->name); } list_add_tail(&vol->list, &ubi_volumes_list); return 0; }
/** * Add a bad block aware device ontop of another (NAND) device * @param[in] dev The device to add a partition on * @param[in] name Partition name (can be obtained with devinfo command) * @return The device representing the new partition. */ int dev_add_bb_dev(char *path, const char *name) { struct nand_bb *bb; int ret = -ENOMEM; struct stat s; bb = xzalloc(sizeof(*bb)); bb->devname = asprintf("/dev/%s", basename(path)); if (!bb->devname) goto out1; if (name) bb->cdev.name = strdup(name); else bb->cdev.name = asprintf("%s.bb", basename(path)); if (!bb->cdev.name) goto out2; ret = stat(bb->devname, &s); if (ret) goto out3; bb->raw_size = s.st_size; bb->fd = open(bb->devname, O_RDWR); if (bb->fd < 0) { ret = -ENODEV; goto out3; } ret = ioctl(bb->fd, MEMGETINFO, &bb->info); if (ret) goto out4; nand_bb_calc_size(bb); bb->cdev.ops = &nand_bb_ops; bb->cdev.priv = bb; devfs_create(&bb->cdev); return 0; out4: close(bb->fd); out3: free(bb->cdev.name); out2: free(bb->devname); out1: free(bb); return ret; }
static int miiphy_probe(struct device_d *dev) { struct miiphy_device *mdev = dev->priv; mdev->cdev.name = asprintf("phy%d", dev->id); mdev->cdev.size = 32; mdev->cdev.ops = &miiphy_ops; mdev->cdev.priv = mdev; mdev->cdev.dev = dev; devfs_create(&mdev->cdev); return 0; }
static int mdio_bus_probe(struct device_d *_dev) { struct phy_device *dev = to_phy_device(_dev); struct phy_driver *drv = to_phy_driver(_dev->driver); int ret; if (drv->probe) { ret = drv->probe(dev); if (ret) goto err; } if (dev->dev_flags) { if (dev->dev_flags & PHYLIB_FORCE_10) { dev->speed = SPEED_10; dev->duplex = DUPLEX_FULL; dev->autoneg = !AUTONEG_ENABLE; dev->force = 1; dev->link = 1; } else if (dev->dev_flags & PHYLIB_FORCE_100) { dev->speed = SPEED_100; dev->duplex = DUPLEX_FULL; dev->autoneg = !AUTONEG_ENABLE; dev->force = 1; dev->link = 1; } } /* Start out supporting everything. Eventually, * a controller will attach, and may modify one * or both of these values */ dev->supported = drv->features; dev->advertising = drv->features; dev_add_param_int_ro(&dev->dev, "phy_addr", dev->addr, "%d"); dev_add_param_int_ro(&dev->dev, "phy_id", dev->phy_id, "0x%08x"); dev->cdev.name = asprintf("phy%d", _dev->id); dev->cdev.size = 64; dev->cdev.ops = &phydev_ops; dev->cdev.priv = dev; dev->cdev.dev = _dev; devfs_create(&dev->cdev); return 0; err: return ret; }
static int ds2431_probe(struct w1_device *dev) { struct cdev *cdev; cdev = xzalloc(sizeof(*cdev)); cdev->dev = &dev->dev; cdev->priv = dev; cdev->ops = &ds2431_ops; cdev->size = W1_F2D_EEPROM_SIZE; cdev->name = basprintf(DRIVERNAME"%d", ds2431_count++); if (cdev->name == NULL) return -ENOMEM; return devfs_create(cdev); }
static int mem_probe(struct device_d *dev) { struct cdev *cdev; cdev = xzalloc(sizeof (*cdev)); dev->priv = cdev; cdev->name = (char*)dev->resource[0].name; cdev->size = (unsigned long)resource_size(&dev->resource[0]); cdev->ops = &memops; cdev->dev = dev; devfs_create(cdev); return 0; }
static int twl_probe(struct device_d *dev) { if (twl_dev) return -EBUSY; twl_dev = xzalloc(sizeof(struct twl4030)); twl_dev->core.cdev.name = DRIVERNAME; twl_dev->core.client = to_i2c_client(dev); twl_dev->core.cdev.size = 1024; twl_dev->core.cdev.dev = dev; twl_dev->core.cdev.ops = &twl_fops; devfs_create(&(twl_dev->core.cdev)); return 0; }
static int act8846_probe(struct device_d *dev) { if (act8846_dev) return -EBUSY; act8846_dev = xzalloc(sizeof(struct act8846)); act8846_dev->cdev.name = DRIVERNAME; act8846_dev->client = to_i2c_client(dev); act8846_dev->cdev.size = 64; act8846_dev->cdev.dev = dev; act8846_dev->cdev.ops = &act8846_fops; devfs_create(&act8846_dev->cdev); return 0; }
static int mc_probe(struct device_d *dev) { if (mc_dev) return -EBUSY; mc_dev = xzalloc(sizeof(struct mc9sdz60)); mc_dev->cdev.name = DRIVERNAME; mc_dev->client = to_i2c_client(dev); mc_dev->cdev.size = 64; /* 35 known registers */ mc_dev->cdev.dev = dev; mc_dev->cdev.ops = &mc_fops; devfs_create(&mc_dev->cdev); return 0; }
static int mc34704_probe(struct device_d *dev) { if (mc34704_dev) return -EBUSY; mc34704_dev = xzalloc(sizeof(struct mc34704)); mc34704_dev->cdev.name = DRIVERNAME; mc34704_dev->client = to_i2c_client(dev); mc34704_dev->cdev.size = 256; mc34704_dev->cdev.dev = dev; mc34704_dev->cdev.ops = &mc34704_fops; devfs_create(&mc34704_dev->cdev); return 0; }
int ubi_cdev_add(struct ubi_device *ubi) { struct cdev *cdev = &ubi->cdev; int ret; cdev->ops = &ubi_fops; cdev->name = basprintf("%s.ubi", ubi->mtd->cdev.name); cdev->priv = ubi; cdev->size = 0; ubi_msg(ubi, "registering /dev/%s", cdev->name); ret = devfs_create(cdev); if (ret) kfree(cdev->name); return ret; }
static int hf_probe(struct device_d *dev) { struct hf_platform_data *hf = dev->platform_data; struct hf_priv *priv = xzalloc(sizeof(*priv)); priv->pdata = hf; priv->cdev.name = hf->name; priv->cdev.size = hf->size; priv->cdev.ops = &hf_fops; priv->cdev.priv = hf; #ifdef CONFIG_FS_DEVFS devfs_create(&priv->cdev); #endif return 0; }
int ubi_cdev_add(struct ubi_device *ubi) { struct cdev *cdev = &ubi->cdev; int ret; cdev->ops = &ubi_fops; cdev->name = asprintf("ubi%d", ubi->ubi_num); cdev->priv = ubi; cdev->size = 0; printf("registering /dev/%s\n", cdev->name); ret = devfs_create(cdev); if (ret) kfree(cdev->name); return ret; }
int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id) { struct mtddev_hook *hook; if (!devname) devname = "mtd"; strcpy(mtd->class_dev.name, devname); mtd->class_dev.id = device_id; if (mtd->parent) mtd->class_dev.parent = mtd->parent; register_device(&mtd->class_dev); mtd->cdev.ops = &mtd_ops; mtd->cdev.size = mtd->size; if (device_id == DEVICE_ID_SINGLE) mtd->cdev.name = xstrdup(devname); else mtd->cdev.name = asprintf("%s%d", devname, mtd->class_dev.id); mtd->cdev.priv = mtd; mtd->cdev.dev = &mtd->class_dev; mtd->cdev.mtd = mtd; if (IS_ENABLED(CONFIG_PARAMETER)) { dev_add_param_llint_ro(&mtd->class_dev, "size", mtd->size, "%llu"); dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, "%u"); dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->writesize, "%u"); dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u"); } devfs_create(&mtd->cdev); if (mtd_can_have_bb(mtd)) mtd->cdev_bb = mtd_add_bb(mtd, NULL); if (mtd->parent && !mtd->master) of_parse_partitions(&mtd->cdev, mtd->parent->device_node); list_for_each_entry(hook, &mtd_register_hooks, hook) if (hook->add_mtd_device) hook->add_mtd_device(mtd, devname, &hook->priv); return 0; }
static int add_mtdoob_device(struct mtd_info *mtd, char *devname, void **priv) { struct mtdoob *mtdoob; if (mtd->oobsize == 0) return 0; mtdoob = xzalloc(sizeof(*mtdoob)); mtdoob->cdev.ops = &mtd_ops_oob; mtdoob->cdev.size = (mtd->size / mtd->writesize) * mtd->oobsize; mtdoob->cdev.name = asprintf("%s_oob%d", devname, mtd->class_dev.id); mtdoob->cdev.priv = mtdoob; mtdoob->cdev.dev = &mtd->class_dev; mtdoob->mtd = mtd; *priv = mtdoob; devfs_create(&mtdoob->cdev); return 0; }
static int add_mtdraw_device(struct mtd_info *mtd, char *devname, void **priv) { struct mtdraw *mtdraw; mtdraw = xzalloc(sizeof(*mtdraw)); mtdraw->writebuf = xmalloc(RAW_WRITEBUF_SIZE); mtdraw->mtd = mtd; mtdraw->cdev.ops = (struct file_operations *)&mtd_raw_fops; mtdraw->cdev.size = mtd->size / mtd->writesize * (mtd->writesize + mtd->oobsize); mtdraw->cdev.name = asprintf("%sraw%d", devname, mtd->class_dev.id); mtdraw->cdev.priv = mtdraw; mtdraw->cdev.dev = &mtd->class_dev; mtdraw->cdev.mtd = mtd; *priv = mtdraw; devfs_create(&mtdraw->cdev); return 0; }
int blockdevice_register(struct block_device *blk) { size_t size = blk->num_blocks * BLOCKSIZE(blk); int ret; blk->cdev.size = size; blk->cdev.dev = blk->dev; blk->cdev.ops = &block_ops; blk->cdev.priv = blk; blk->rdbufsize = PAGE_SIZE >> blk->blockbits; blk->rdbuf = xmalloc(PAGE_SIZE); blk->rdblock = 1; blk->rdblockend = 0; blk->wrbufsize = PAGE_SIZE >> blk->blockbits; blk->wrbuf = xmalloc(PAGE_SIZE); blk->wrblock = 0; blk->wrbufblocks = 0; ret = devfs_create(&blk->cdev); if (ret) return ret; return 0; }
struct inode *devfs_add(struct inode *q, char *name, mode_t mode, int major, int minor) { struct inode *i = devfs_create(q, name, mode); i->dev = 256 * major + minor; return i; }
static int mdio_bus_probe(struct device_d *_dev) { struct phy_device *dev = to_phy_device(_dev); struct phy_driver *drv = to_phy_driver(_dev->driver); int ret; char str[16]; dev->attached_dev->phydev = dev; if (drv->probe) { ret = drv->probe(dev); if (ret) goto err; } if (dev->dev_flags) { if (dev->dev_flags & PHYLIB_FORCE_10) { dev->speed = SPEED_10; dev->duplex = DUPLEX_FULL; dev->autoneg = !AUTONEG_ENABLE; dev->force = 1; dev->link = 1; } else if (dev->dev_flags & PHYLIB_FORCE_100) { dev->speed = SPEED_100; dev->duplex = DUPLEX_FULL; dev->autoneg = !AUTONEG_ENABLE; dev->force = 1; dev->link = 1; } } /* Start out supporting everything. Eventually, * a controller will attach, and may modify one * or both of these values */ dev->supported = drv->features; dev->advertising = drv->features; ret = phy_init_hw(dev); if (ret) goto err; /* Sanitize settings based on PHY capabilities */ if ((dev->supported & SUPPORTED_Autoneg) == 0) dev->autoneg = AUTONEG_DISABLE; sprintf(str, "%d", dev->addr); dev_add_param_fixed(&dev->dev, "phy_addr", str); sprintf(str, "0x%08x", dev->phy_id); dev_add_param_fixed(&dev->dev, "phy_id", str); dev->cdev.name = asprintf("phy%d", _dev->id); dev->cdev.size = 64; dev->cdev.ops = &phydev_ops; dev->cdev.priv = dev; dev->cdev.dev = _dev; devfs_create(&dev->cdev); return 0; err: dev->attached_dev->phydev = NULL; dev->attached_dev = NULL; return ret; }
int register_framebuffer(struct fb_info *info) { int id = get_free_deviceid("fb"); struct device_d *dev; int ret, num_modes, i; const char **names; dev = &info->dev; /* * If info->mode is set at this point it's the only mode * the fb supports. move it over to the modes list. */ if (info->mode) { info->modes.modes = info->mode; info->modes.num_modes = 1; } if (!info->line_length) info->line_length = info->xres * (info->bits_per_pixel >> 3); info->cdev.ops = &fb_ops; info->cdev.name = basprintf("fb%d", id); info->cdev.size = info->line_length * info->yres; info->cdev.dev = dev; info->cdev.priv = info; dev->resource = xzalloc(sizeof(struct resource)); dev->resource[0].start = (resource_size_t)info->screen_base; dev->resource[0].end = dev->resource[0].start + info->cdev.size - 1; dev->resource[0].flags = IORESOURCE_MEM; dev->num_resources = 1; dev->priv = info; dev->id = id; dev->info = fb_info; dev_set_name(dev, "fb"); ret = register_device(&info->dev); if (ret) goto err_free; dev_add_param_bool(dev, "enable", fb_enable_set, NULL, &info->p_enable, info); if (IS_ENABLED(CONFIG_DRIVER_VIDEO_EDID)) fb_edid_add_modes(info); num_modes = info->modes.num_modes + info->edid_modes.num_modes; names = xzalloc(sizeof(char *) * num_modes); for (i = 0; i < info->modes.num_modes; i++) names[i] = info->modes.modes[i].name; for (i = 0; i < info->edid_modes.num_modes; i++) names[i + info->modes.num_modes] = info->edid_modes.modes[i].name; dev_add_param_enum(dev, "mode_name", fb_set_modename, NULL, &info->current_mode, names, num_modes, info); info->shadowfb = 1; dev_add_param_bool(dev, "shadowfb", fb_set_shadowfb, NULL, &info->shadowfb, info); info->mode = fb_num_to_mode(info, 0); fb_setup_mode(info); ret = devfs_create(&info->cdev); if (ret) goto err_unregister; if (IS_ENABLED(CONFIG_DRIVER_VIDEO_SIMPLEFB)) { ret = fb_register_simplefb(info); if (ret) dev_err(&info->dev, "failed to register simplefb: %s\n", strerror(-ret)); } if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE)) register_fbconsole(info); return 0; err_unregister: unregister_device(&info->dev); err_free: free(dev->resource); return ret; }
static int jtag_probe(struct device_d *pdev) { int i, ret; struct jtag_info *info; struct jtag_platdata *pdata = pdev->platform_data; /* Setup gpio pins */ gpio_direction_output(pdata->gpio_tms, 0); gpio_direction_output(pdata->gpio_tclk, 1); gpio_direction_output(pdata->gpio_tdo, 0); gpio_direction_input(pdata->gpio_tdi); if (pdata->use_gpio_trst) { /* * Keep fixed at 1 because some devices in the chain could * not use it, to reset chain use jtag_reset() */ gpio_direction_output(pdata->gpio_trst, 1); } /* Find how many devices in chain */ jtag_reset(pdata); pulse_tms0(pdata); pulse_tms1(pdata); pulse_tms1(pdata); pulse_tms0(pdata); pulse_tms0(pdata); gpio_set_value(pdata->gpio_tdo, 1); /* Fills all IR with bypass instruction */ for (i = 0; i < 32 * MAX_DEVICES; i++) pulse_tms0(pdata); pulse_tms1(pdata); pulse_tms1(pdata); pulse_tms1(pdata); pulse_tms0(pdata); pulse_tms0(pdata); gpio_set_value(pdata->gpio_tdo, 0); /* Fills all 1-bit bypass register with 0 */ for (i = 0; i < MAX_DEVICES + 2; i++) pulse_tms0(pdata); gpio_set_value(pdata->gpio_tdo, 1); /* Counts chain's bit length */ for (i = 0; i < MAX_DEVICES + 1; i++) { pulse_tms0(pdata); if (gpio_get_value(pdata->gpio_tdi)) break; } dev_notice(pdev, "%d devices found in chain\n", i); /* Allocate structure with chain specific infos */ info = xzalloc(sizeof(struct jtag_info) + sizeof(info->ir_len[0]) * i); info->devices = i; info->pdata = pdata; pdev->priv = info; info->cdev.name = JTAG_NAME; info->cdev.dev = pdev; info->cdev.ops = &jtag_operations; info->cdev.priv = info; ret = devfs_create(&info->cdev); if (ret) goto fail_devfs_create; return 0; fail_devfs_create: pdev->priv = NULL; free(info); return ret; }