Exemple #1
0
int i2c_dw_initialize(struct device *port)
{
	struct i2c_dw_rom_config const * const rom = port->config->config_info;
	struct i2c_dw_dev_config * const dev = port->driver_data;

	volatile struct i2c_dw_registers *regs;

	if (!i2c_dw_pci_setup(port)) {
		port->driver_api = NULL;
		return -EPERM;
	}

	device_sync_call_init(&dev->sync);

	regs = (struct i2c_dw_registers *) rom->base_address;

	/* verify that we have a valid DesignWare register first */
	if (regs->ic_comp_type != I2C_DW_MAGIC_KEY) {
		port->driver_api = NULL;
		DBG("I2C: DesignWare magic key not found, check base address.");
		DBG(" Stopping initialization\n");
		return -EPERM;
	}

	/*
	 * grab the default value on initialization.  This should be set to the
	 * IC_MAX_SPEED_MODE in the hardware.  If it does support high speed we
	 * can move provide support for it
	 */
	if (regs->ic_con.bits.speed == I2C_DW_SPEED_HIGH) {
		DBG("I2C: high speed supported\n");
		dev->support_hs_mode = true;
	} else {
		DBG("I2C: high speed NOT supported\n");
		dev->support_hs_mode = false;
	}

	rom->config_func(port);

	if (i2c_dw_runtime_configure(port, dev->app_config.raw) != 0) {
		DBG("I2C: Cannot set default configuration 0x%x\n",
		    dev->app_config.raw);
		return -EPERM;
	}

	dev->state = I2C_DW_STATE_READY;

	return 0;
}
Exemple #2
0
static int i2c_dw_initialize(struct device *dev)
{
	const struct i2c_dw_rom_config * const rom = dev->config->config_info;
	struct i2c_dw_dev_config * const dw = dev->driver_data;
	volatile struct i2c_dw_registers *regs;

	if (!i2c_dw_pci_setup(dev)) {
		dev->driver_api = NULL;
		return -EIO;
	}

	k_sem_init(&dw->device_sync_sem, 0, UINT_MAX);

	regs = (struct i2c_dw_registers *) dw->base_address;

	/* verify that we have a valid DesignWare register first */
	if (regs->ic_comp_type != I2C_DW_MAGIC_KEY) {
		dev->driver_api = NULL;
		SYS_LOG_DBG("I2C: DesignWare magic key not found, check base "
			    "address. Stopping initialization");
		return -EIO;
	}

	/*
	 * grab the default value on initialization.  This should be set to the
	 * IC_MAX_SPEED_MODE in the hardware.  If it does support high speed we
	 * can move provide support for it
	 */
	if (regs->ic_con.bits.speed == I2C_DW_SPEED_HIGH) {
		SYS_LOG_DBG("I2C: high speed supported");
		dw->support_hs_mode = true;
	} else {
		SYS_LOG_DBG("I2C: high speed NOT supported");
		dw->support_hs_mode = false;
	}

	rom->config_func(dev);

	dw->app_config = I2C_MODE_MASTER | _i2c_map_dt_bitrate(rom->bitrate);

	if (i2c_dw_runtime_configure(dev, dw->app_config) != 0) {
		SYS_LOG_DBG("I2C: Cannot set default configuration");
		return -EIO;
	}

	dw->state = I2C_DW_STATE_READY;

	return 0;
}