Пример #1
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 = asprintf(DRIVERNAME "%d",
			cdev_find_free_index(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;
}
Пример #2
0
static int ata_port_init(struct ata_port *port)
{
	int rc;
	struct ata_port_operations *ops = port->ops;
	struct device_d *dev = &port->class_dev;

	if (ops->init) {
		rc = ops->init(port);
		if (rc)
			return rc;
	}

	port->id = dma_alloc(SECTOR_SIZE);

	port->blk.dev = dev;
	port->blk.ops = &ata_ops;

	if (ops->reset) {
		rc = ops->reset(port);
		if (rc) {
			dev_dbg(dev, "Resetting failed\n");
			goto on_error;
		}
	}

	rc = ops->read_id(port, port->id);
	if (rc != 0) {
		dev_dbg(dev, "Reading ID failed\n");
		goto on_error;
	}

	ata_fix_endianess(port->id, SECTOR_SIZE / sizeof(uint16_t));

	rc = ata_id_is_valid(port->id);
	if (rc) {
		dev_err(dev, "ata id invalid\n");
		free(port->id);
		return rc;
	}

#ifdef DEBUG
	ata_dump_id(port->id);
#endif
	rc = cdev_find_free_index("ata");
	if (rc == -1)
		pr_err("Cannot find a free index for the disk node\n");

	port->blk.num_blocks = ata_id_n_sectors(port->id);
	port->blk.cdev.name = asprintf("ata%d", rc);
	port->blk.blockbits = SECTOR_SHIFT;

	rc = blockdevice_register(&port->blk);
	if (rc != 0) {
		dev_err(dev, "Failed to register blockdevice\n");
		goto on_error;
	}

	dev_info(dev, "registered /dev/%s\n", port->blk.cdev.name);

	/* create partitions on demand */
	rc = parse_partition_table(&port->blk);
	if (rc != 0)
		dev_warn(dev, "No partition table found\n");

	return 0;

on_error:
	return rc;
}