2019-05-17 04:04:24 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* This file is a template for cmake and is not meant to be used directly!
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void i2c_config_@NUM@(struct device *port);
|
|
|
|
|
|
|
|
static const struct i2c_dw_rom_config i2c_config_dw_@NUM@ = {
|
|
|
|
.config_func = i2c_config_@NUM@,
|
2019-06-12 03:20:32 +08:00
|
|
|
.bitrate = DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_CLOCK_FREQUENCY,
|
2019-05-17 04:04:24 +08:00
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
#if DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_PCIE
|
2019-05-17 06:33:09 +08:00
|
|
|
.pcie = true,
|
2019-06-12 03:20:32 +08:00
|
|
|
.pcie_bdf = DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_BASE_ADDRESS,
|
|
|
|
.pcie_id = DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_SIZE,
|
2019-05-17 04:04:24 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_dw_dev_config i2c_@NUM@_runtime = {
|
2019-10-02 20:09:12 +08:00
|
|
|
.regs = (struct i2c_dw_registers *)
|
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_BASE_ADDRESS
|
2019-05-17 04:04:24 +08:00
|
|
|
};
|
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
DEVICE_AND_API_INIT(i2c_@NUM@, DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_LABEL,
|
2019-05-17 04:04:24 +08:00
|
|
|
&i2c_dw_initialize,
|
|
|
|
&i2c_@NUM@_runtime, &i2c_config_dw_@NUM@,
|
|
|
|
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY,
|
|
|
|
&funcs);
|
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
#ifndef DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_SENSE
|
|
|
|
#define DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_SENSE 0
|
2019-05-17 04:04:24 +08:00
|
|
|
#endif
|
|
|
|
static void i2c_config_@NUM@(struct device *port)
|
|
|
|
{
|
2019-05-17 06:33:09 +08:00
|
|
|
ARG_UNUSED(port);
|
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
#if DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_PCIE
|
|
|
|
#if DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0 == PCIE_IRQ_DETECT
|
2019-05-17 06:33:09 +08:00
|
|
|
|
|
|
|
/* PCI(e) with auto IRQ detection */
|
|
|
|
|
|
|
|
BUILD_ASSERT_MSG(IS_ENABLED(CONFIG_DYNAMIC_INTERRUPTS),
|
|
|
|
"DW I2C PCI auto-IRQ needs CONFIG_DYNAMIC_INTERRUPTS");
|
|
|
|
|
|
|
|
unsigned int irq;
|
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
irq = pcie_wired_irq(DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_BASE_ADDRESS);
|
2019-05-17 06:33:09 +08:00
|
|
|
|
|
|
|
if (irq == PCIE_CONF_INTR_IRQ_NONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
irq_connect_dynamic(irq,
|
2019-06-12 03:20:32 +08:00
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_PRIORITY,
|
2019-05-17 06:33:09 +08:00
|
|
|
i2c_dw_isr, DEVICE_GET(i2c_@NUM@),
|
2019-06-12 03:20:32 +08:00
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_SENSE);
|
|
|
|
pcie_irq_enable(DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_BASE_ADDRESS, irq);
|
2019-05-17 06:33:09 +08:00
|
|
|
|
2019-05-17 04:04:24 +08:00
|
|
|
#else
|
2019-05-17 06:33:09 +08:00
|
|
|
|
|
|
|
/* PCI(e) with fixed or MSI IRQ */
|
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
IRQ_CONNECT(DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0,
|
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_PRIORITY,
|
2019-05-17 06:33:09 +08:00
|
|
|
i2c_dw_isr, DEVICE_GET(i2c_@NUM@),
|
2019-06-12 03:20:32 +08:00
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_SENSE);
|
|
|
|
pcie_irq_enable(DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_BASE_ADDRESS,
|
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0);
|
2019-05-17 06:33:09 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* not PCI(e) */
|
|
|
|
|
2019-06-12 03:20:32 +08:00
|
|
|
IRQ_CONNECT(DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0,
|
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_PRIORITY,
|
2019-05-17 04:04:24 +08:00
|
|
|
i2c_dw_isr, DEVICE_GET(i2c_@NUM@),
|
2019-06-12 03:20:32 +08:00
|
|
|
DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0_SENSE);
|
|
|
|
irq_enable(DT_INST_@NUM@_SNPS_DESIGNWARE_I2C_IRQ_0);
|
2019-05-17 06:33:09 +08:00
|
|
|
|
2019-05-17 04:04:24 +08:00
|
|
|
#endif
|
|
|
|
}
|