i2c: designware: Add slave support
Subsystems (4)
v3 cover i2c: designware: Add slave support
The purpose of this patch is to enable Linux to be a I2C slave by enabling the slave functionality in the designware I2C controller. The patch refactors the original i2c-designware-core and extracts all master functions to a i2c-designware-master source file as suggested by Andy Shevchenko. It also creates a i2c-designware-slave source file and keeps the common functions in the i2c-designware-src source file. For that changes also had to be made in the Makefile and Kconfig.
The driver instantiates in slave or master mode by checking the compatible string of the device tree (see devicetree/bindings/i2c/i2c-designware.txt). ACPI is not supported.
The functionality was tested using the hardware independent software backend slave-eeprom driver.
Luis Oliveira (5):
i2c: designware: Refactoring of the i2c-designware core and platform
module
i2c: designware: Master mode as separated driver
i2c: designware: Add slave definitions
i2c: designware: Add slave mode as separated driver
i2c: designware: Cleaning and commentary fixes
.../devicetree/bindings/i2c/i2c-designware.txt | 4 +-
drivers/i2c/busses/Kconfig | 1 +
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-designware-core.h | 156 +++++++-
...c-designware-core.c => i2c-designware-master.c} | 391 ++----------------
drivers/i2c/busses/i2c-designware-platdrv.c | 103 ++++-
drivers/i2c/busses/i2c-designware-slave.c | 445 +++++++++++++++++++++
drivers/i2c/busses/i2c-designware-src.c | 258 ++++++++++++
8 files changed, 983 insertions(+), 376 deletions(-)
rename drivers/i2c/busses/{i2c-designware-core.c => i2c-designware-master.c} (64%)
create mode 100644 drivers/i2c/busses/i2c-designware-slave.c
create mode 100644 drivers/i2c/busses/i2c-designware-src.cSignature · 1 line
2.10.2
PATCH v3 1/5 i2c: designware: Refactoring of the i2c-designware core and platform module
- Factor out _master() parts of code to separate functions.
- Standardize all code relatated to I2C master.
---
Changes V2->V3: (Andy Shevchenko)
- indentation and style fix
- nothing else was changed in this patch from v2
drivers/i2c/busses/i2c-designware-core.c | 66 +++++++++++++++++++---------- drivers/i2c/busses/i2c-designware-platdrv.c | 36 ++++++++++------ 2 files changed, 66 insertions(+), 36 deletions(-)
drivers/i2c/busses/i2c-designware-core.c +43 -23
@@ -87,13 +87,13 @@#define DW_IC_INTR_GEN_CALL 0x800#define DW_IC_INTR_DEFAULT_MASK (DW_IC_INTR_RX_FULL | \ - DW_IC_INTR_TX_EMPTY | \ DW_IC_INTR_TX_ABRT | \ DW_IC_INTR_STOP_DET) - +#define DW_IC_INTR_MASTER_MASK (DW_IC_INTR_DEFAULT_MASK | \ + DW_IC_INTR_TX_EMPTY)#define DW_IC_STATUS_ACTIVITY 0x1#define DW_IC_STATUS_TFE BIT(2) -#define DW_IC_STATUS_MST_ACTIVITY BIT(5) +#define DW_IC_STATUS_MASTER_ACTIVITY BIT(5)#define DW_IC_SDA_HOLD_RX_SHIFT 16#define DW_IC_SDA_HOLD_RX_MASK GENMASK(23, DW_IC_SDA_HOLD_RX_SHIFT)
@@ -204,6 +204,17 @@ static void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset) } } +static void i2c_dw_configure_fifo_master (struct dw_i2c_dev *dev) +{ +/* Configure Tx/Rx FIFO threshold levels */ +dw_writel (dev, dev->tx_fifo_depth /2 ,DW_IC_TX_TL ); +dw_writel (dev,0 ,DW_IC_RX_TL ); + +/* configure the i2c master */ +dw_writel (dev, dev->master_cfg,DW_IC_CON ); +dw_writel (dev,DW_IC_INTR_MASTER_MASK ,DW_IC_INTR_MASK ); +} +static u32 i2c_dw_scl_hcnt (u32 ic_clk,u32 tSYMBOL,u32 tf,int cond,int offset) {
@@ -320,10 +331,10 @@ static void i2c_dw_release_lock(struct dw_i2c_dev *dev) }/** -* i2c_dw_init() - initialize the designware i2c master hardware +* i2c_dw_init() - initialize the designware i2c hardware * @dev: device private data * -* This functions configures and enables the I2C master. +* This functions configures and enables the I2C. * This function is called during I2C init function, and in case of timeout at * run time. */
@@ -442,12 +453,9 @@ int i2c_dw_init(struct dw_i2c_dev *dev) "Hardware too old to adjust SDA hold time.\n"); } -/* Configure Tx/Rx FIFO threshold levels */ -dw_writel (dev, dev->tx_fifo_depth /2 ,DW_IC_TX_TL ); -dw_writel (dev,0 ,DW_IC_RX_TL ); - -/* configure the i2c master */ -dw_writel (dev, dev->master_cfg ,DW_IC_CON ); +if ((dev->master_cfg &DW_IC_CON_MASTER ) && + (dev->master_cfg &DW_IC_CON_SLAVE_DISABLE )) +i2c_dw_configure_fifo_master (dev);i2c_dw_release_lock (dev);
@@ -491,7 +499,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)*/ ic_status =dw_readl (dev,DW_IC_STATUS );if (!dev->dynamic_tar_update_enabled || - (ic_status &DW_IC_STATUS_MST_ACTIVITY ) || + (ic_status &DW_IC_STATUS_MASTER_ACTIVITY ) || !(ic_status &DW_IC_STATUS_TFE )) {__i2c_dw_enable_and_wait (dev, false); enabled = false;
@@ -531,7 +539,7 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)/* Clear and enable interrupts */ dw_readl (dev,DW_IC_CLR_INTR ); -dw_writel (dev,DW_IC_INTR_DEFAULT_MASK ,DW_IC_INTR_MASK ); +dw_writel (dev,DW_IC_INTR_MASTER_MASK ,DW_IC_INTR_MASK ); }/*
@@ -551,7 +559,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)u8 *buf = dev->tx_buf;bool need_restart = false; - intr_mask =DW_IC_INTR_DEFAULT_MASK ; + intr_mask =DW_IC_INTR_MASTER_MASK ;for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) {/*
@@ -850,16 +858,9 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)* Interrupt service routine. This gets called whenever an I2C interrupt * occurs. */ -static irqreturn_t i2c_dw_isr (int this_irq,void *dev_id) +static bool i2c_dw_irq_handler_master (struct dw_i2c_dev *dev) { -struct dw_i2c_dev *dev = dev_id; -u32 stat, enabled; - - enabled =dw_readl (dev,DW_IC_ENABLE ); - stat =dw_readl (dev,DW_IC_RAW_INTR_STAT ); -dev_dbg (dev->dev,"%s: enabled=%#x stat=%#x\n" , __func__, enabled, stat); -if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY )) -return IRQ_NONE ; +u32 stat; stat =i2c_dw_read_clear_intrbits (dev);
@@ -906,7 +907,26 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)i2c_dw_disable_int (dev);dw_writel (dev, stat,DW_IC_INTR_MASK ); } +return true; +} + +static irqreturn_t i2c_dw_isr (int this_irq,void *dev_id) +{ +struct dw_i2c_dev *dev = dev_id; +u32 stat, enabled, mode; + + enabled =dw_readl (dev,DW_IC_ENABLE ); + mode =dw_readl (dev,DW_IC_CON ); + stat =dw_readl (dev,DW_IC_RAW_INTR_STAT ); + +dev_dbg (dev->dev,"%s: enabled=%#x stat=%#x\n" , __func__, enabled, stat); +if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY )) +return IRQ_NONE ; + +if (i2c_dw_irq_handler_master (dev)) +return IRQ_HANDLED ; +complete (&dev->cmd_complete);return IRQ_HANDLED ; }
drivers/i2c/busses/i2c-designware-platdrv.c +23 -13
@@ -138,6 +138,28 @@ static inline int dw_i2c_acpi_configure(struct platform_device *pdev) }#endif +static void i2c_dw_configure_master (struct platform_device *pdev) +{ +struct dw_i2c_dev *dev =platform_get_drvdata (pdev); + + dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN ; + + dev->functionality |=I2C_FUNC_10BIT_ADDR ; +dev_info (&pdev->dev,"I am registed as a I2C Master!\n" ); + +switch (dev->clk_freq) { +case 100000 : + dev->master_cfg |=DW_IC_CON_SPEED_STD ; +break ; +case 3400000 : + dev->master_cfg |=DW_IC_CON_SPEED_HIGH ; +break ; +default : + dev->master_cfg |=DW_IC_CON_SPEED_FAST ; + } +} +static int i2c_dw_plat_prepare_clk (struct dw_i2c_dev *i_dev,bool prepare) {if (IS_ERR (i_dev->clk))
@@ -222,19 +244,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; - dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN ; - -switch (dev->clk_freq) { -case 100000 : - dev->master_cfg |=DW_IC_CON_SPEED_STD ; -break ; -case 3400000 : - dev->master_cfg |=DW_IC_CON_SPEED_HIGH ; -break ; -default : - dev->master_cfg |=DW_IC_CON_SPEED_FAST ; - } +i2c_dw_configure_master (pdev); dev->clk =devm_clk_get (&pdev->dev,NULL );if (!i2c_dw_plat_prepare_clk (dev, true)) {
Signature · 1 line
2.10.2
Andy Shevchenko
reviewerRe: [PATCH v3 1/5] i2c: designware: Refactoring of the i2c-designware core and platform module
Quoted 4 lines · Luis Oliveira
- Factor out
_master()parts of code to separate functions.
- Standardize all code relatated to I2C master.
Can you shrink Cc list to people who indeed are involved / concerned?
Quoted 4 lines
---
ChangesV2->V3: (Andy Shevchenko)
- indentation and style fix
- nothing else was changed in this patch from v2
Hmm...
May I add few more comments?
Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +0
-0@@ -87,13 +87,13 @@ #define DW_IC_INTR_GEN_CALL 0x800
#defineDW_IC_INTR_DEFAULT_MASK(DW_IC_INTR_RX_FULL|
\drivers/i2c/busses/i2c-designware-core.c +0
-1- DW_IC_INTR_TX_EMPTY | \DW_IC_INTR_TX_ABRT | \
DW_IC_INTR_STOP_DET)-
Do you need to remove it?
I would leave it...
drivers/i2c/busses/i2c-designware-core.c line 93
Quoted 3 lines
+#define
DW_IC_INTR_MASTER_MASK(DW_IC_INTR_DEFAULT_MAS
K | \drivers/i2c/busses/i2c-designware-core.c +1
-0+ DW_IC_INTR_TX_EMPTY)
...here.
drivers/i2c/busses/i2c-designware-core.c line 96
Quoted 4 lines
#define
DW_IC_STATUS_ACTIVITY0x1
#defineDW_IC_STATUS_TFEBIT(2)drivers/i2c/busses/i2c-designware-core.c +1
-1-#define DW_IC_STATUS_MST_ACTIVITY BIT(5) +#define DW_IC_STATUS_MASTER_ACTIVITY BIT(5)
drivers/i2c/busses/i2c-designware-core.c static void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset) · line 215
Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +9
-0+static void i2c_dw_configure_fifo_master (struct dw_i2c_dev *dev) +{ +/* Configure Tx/Rx FIFO threshold levels */ +dw_writel (dev, dev->tx_fifo_depth /2 ,DW_IC_TX_TL ); +dw_writel (dev,0 ,DW_IC_RX_TL ); + +/* configure the i2c master */ +dw_writel (dev, dev->master_cfg,DW_IC_CON ); +dw_writel (dev,DW_IC_INTR_MASTER_MASK ,DW_IC_INTR_MASK );
So, in the original code there were 3 writes, now 4. Please, put an explanation into commit message.
Quoted 7 lines
(quoted diff) +1
-0+}@@ -442,12 +453,9 @@ int i2c_dw_init(struct dw_i2c_dev *dev)"Hardware too old to adjust SDA hold time.\n");
}
drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev)
Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +2
-6-/* Configure Tx/Rx FIFO threshold levels */ -dw_writel (dev, dev->tx_fifo_depth /2 ,DW_IC_TX_TL ); -dw_writel (dev,0 ,DW_IC_RX_TL ); - -/* configure the i2c master */ -dw_writel (dev, dev->master_cfg ,DW_IC_CON ); +if ((dev->master_cfg &DW_IC_CON_MASTER ) && + (dev->master_cfg &DW_IC_CON_SLAVE_DISABLE ))
Indentation!
drivers/i2c/busses/i2c-designware-core.c int i2c_dw_init(struct dw_i2c_dev *dev)
Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.c +2
-1+i2c_dw_configure_fifo_master (dev); -static irqreturn_t i2c_dw_isr (int this_irq,void *dev_id) +static bool i2c_dw_irq_handler_master (struct dw_i2c_dev *dev)
Perhaps int?
Quoted 15 lines
{
drivers/i2c/busses/i2c-designware-core.c +0
-6-struct dw_i2c_dev *dev = dev_id; -u32 stat, enabled; - - enabled =dw_readl (dev,DW_IC_ENABLE ); - stat =dw_readl (dev,DW_IC_RAW_INTR_STAT ); - dev_dbg(dev->dev, "%s: enabled=%#x stat=%#x\n", __func__,enabled, stat);
drivers/i2c/busses/i2c-designware-core.c +1
-2-if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY )) -return IRQ_NONE ; +u32 stat;
stat =i2c_dw_read_clear_intrbits(dev);
drivers/i2c/busses/i2c-designware-core.c static irqreturn_t i2c_dw_isr(int this_irq, void · line 912
Quoted 6 lines
drivers/i2c/busses/i2c-designware-core.c +1
-0@@ -906,7 +907,26 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) i2c_dw_disable_int(dev); dw_writel(dev, stat, DW_IC_INTR_MASK); } +return true;
Ditto.
And basically I don't see how this would be not true? Are you planning to add something here later in the series? Please, elaborate in the commit message.
Quoted 4 lines
drivers/i2c/busses/i2c-designware-core.c +4
-0+} + +static irqreturn_t i2c_dw_isr (int this_irq,void *dev_id) +{
drivers/i2c/busses/i2c-designware-core.c static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
Quoted 10 lines
drivers/i2c/busses/i2c-designware-core.c +8
-0+struct dw_i2c_dev *dev = dev_id; +u32 stat, enabled, mode; + + enabled =dw_readl (dev,DW_IC_ENABLE ); + mode =dw_readl (dev,DW_IC_CON ); + stat =dw_readl (dev,DW_IC_RAW_INTR_STAT ); + +dev_dbg (dev->dev,"%s: enabled=%#x stat=%#x\n" , __func__, enabled, stat);
For sake of easier review, can we keep same lines same and in the same order?
struct dw_i2c_dev *dev = dev_id; u32 stat, enabled; enabled = dw_readl(dev, DW_IC_ENABLE); stat = dw_readl(dev, DW_IC_RAW_INTR_STAT); dev_dbg(dev->dev, "%s: enabled=%#x stat=%#x\n", __func__, enabled, stat); if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY)) return IRQ_NONE;
Btw, I do not see how mode is used? Do you have a warning? Please, fix.
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +7
-0+if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY )) +return IRQ_NONE ; +static void i2c_dw_configure_master (struct platform_device *pdev) +{ +struct dw_i2c_dev *dev =platform_get_drvdata (pdev); + + dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE |
drivers/i2c/busses/i2c-designware-platdrv.c static inline int dw_i2c_acpi_configure(struct platform_device *pdev) · line 148
Quoted 4 lines
drivers/i2c/busses/i2c-designware-platdrv.c +3
-0+ DW_IC_CON_RESTART_EN; + + dev->functionality |=I2C_FUNC_10BIT_ADDR ;
Where this came from?
Quoted 41 lines
drivers/i2c/busses/i2c-designware-platdrv.c +14
-0+dev_info (&pdev->dev,"I am registed as a I2C Master!\n" ); + +switch (dev->clk_freq) { +case 100000 : + dev->master_cfg |=DW_IC_CON_SPEED_STD ; +break ; +case 3400000 : + dev->master_cfg |=DW_IC_CON_SPEED_HIGH ; +break ; +default : + dev->master_cfg |=DW_IC_CON_SPEED_FAST ; + } +} +static int
i2c_dw_plat_prepare_clk(struct dw_i2c_dev *i_dev, bool prepare)
{
if (IS_ERR(i_dev->clk))(quoted diff) +0
-0@@ -222,19 +244,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
I2C_FUNC_SMBUS_WORD_DATA|
I2C_FUNC_SMBUS_I2C_BLOCK;(quoted diff) +0
-1- dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE|
drivers/i2c/busses/i2c-designware-platdrv.c +1
-12- DW_IC_CON_RESTART_EN; - -switch (dev->clk_freq) { -case 100000 : - dev->master_cfg |=DW_IC_CON_SPEED_STD ; -break ; -case 3400000 : - dev->master_cfg |=DW_IC_CON_SPEED_HIGH ; -break ; -default : - dev->master_cfg |=DW_IC_CON_SPEED_FAST ; - } +i2c_dw_configure_master (pdev);
dev->clk=devm_clk_get(&pdev->dev, NULL); if (!i2c_dw_plat_prepare_clk(dev, true)) {
Signature · 6 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 2/5 i2c: designware: Master mode as separated driver
In reply to Luis Oliveira - The functions related to I2C master mode of operation were transformed in a single driver.
- The name of the i2c-designware-core.c had to be changed to i2c-designware-src.c to for the cmake to be able to correctly compile both modules into one
- Common definitions were moved to i2c-designware-core.h
---
Changes V2->V3: (Andy Shevchenko)
- runtime PM removed
- necessary definitions moved to i2c-designware-core.h (master)
- indentation and style fix
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-designware-core.h | 132 +++++++-
...c-designware-core.c => i2c-designware-master.c} | 341 +--------------------
drivers/i2c/busses/i2c-designware-src.c | 252 +++++++++++++++
4 files changed, 386 insertions(+), 340 deletions(-)
rename drivers/i2c/busses/{i2c-designware-core.c => i2c-designware-master.c} (66%)
create mode 100644 drivers/i2c/busses/i2c-designware-src.cdrivers/i2c/busses/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o obj-$(CONFIG_I2C_CPM) += i2c-cpm.o obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o +i2c-designware-core-objs := i2c-designware-src.o i2c-designware-master.o obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o i2c-designware-platform-objs := i2c-designware-platdrv.o i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-baytrail.o
drivers/i2c/busses/i2c-designware-core.h +130 -2
150 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-master.c renamed from drivers/i2c/busses/i2c-designware-core.c +3 -338
385 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-src.c new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.10.2
Andy Shevchenko
reviewerRe: [PATCH v3 2/5] i2c: designware: Master mode as separated driver
Quoted 9 lines · Luis Oliveira
- The functions related to I2C master mode of operation were transformed in a single driver.
- The name of thei2c-designware-core.chad to be changed to i2c-designware-src.cto for the cmake to be able to correctly compile both modules into one
- Common definitions were moved toi2c-designware-core.hdrivers/i2c/busses/i2c-designware-src.c | 252
+++++++++++++++
Perhaps i2c-designware-common.c ?
drivers/i2c/busses/i2c-designware-core.h line 26
Quoted 7 lines
drivers/i2c/busses/i2c-designware-core.h +0
-3@@ -21,8 +21,6 @@* ------------------------------------------------------------------ ---------- * */ - -
No need to do that in this patch.
drivers/i2c/busses/i2c-designware-core.h line 36
Quoted 11 lines
drivers/i2c/busses/i2c-designware-core.h +0
-0#define DW_IC_CON_MASTER 0x1 #define DW_IC_CON_SPEED_STD 0x2#define
DW_IC_CON_SPEED_FAST0x4drivers/i2c/busses/i2c-designware-core.h +0
-0@@ -32,6 +30,123 @@ #define DW_IC_CON_RESTART_EN 0x20 #define DW_IC_CON_SLAVE_DISABLE 0x40drivers/i2c/busses/i2c-designware-core.h +4
-0+/* +* Registers offset +*/ +#define DW_IC_CON 0x0
Okay, can we split this to move definitions and the rest?
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH v3 3/5 i2c: designware: Add slave definitions
In reply to Luis Oliveira - Add slave defintitions to i2c-designware-core
- Changes in Kconfig to auto-enable I2C_SLAVE when compiling the modules
- Add compatible string to designware-core.txt explaining the devicetree bindings
---
Changes V2->V3: (Andy Shevchenko)
- necessary definitions added to i2c-designware-core.h (slave)
- code will be added in the next patch as suggested
- compatible string for slave enabling as suggested
.../devicetree/bindings/i2c/i2c-designware.txt | 4 +++- drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-designware-core.h | 24 ++++++++++++++++++++++ drivers/i2c/busses/i2c-designware-src.c | 6 ++++++ 4 files changed, 34 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/i2c/i2c-designware.txt +3 -1
@@ -2,7 +2,9 @@ Required properties : - - compatible : should be "snps,designware-i2c" + - compatible : should be: + - "snps,designware-i2c" to setup the hardware block as I2C master. + - "snps,designware-i2c-slave" to setup the hardware block as I2C slave. - reg : Offset and length of the register set for the device - interrupts : <IRQ> where IRQ is the interrupt number.
drivers/i2c/busses/Kconfig +1 -0
@@ -470,6 +470,7 @@ config I2C_DESIGNWARE_CORE config I2C_DESIGNWARE_PLATFORM tristate "Synopsys DesignWare Platform" select I2C_DESIGNWARE_CORE + select I2C_SLAVE depends on (ACPI && COMMON_CLK) || !ACPI help If you say yes to this option, support will be included for the
drivers/i2c/busses/i2c-designware-core.h +24 -0
@@ -26,15 +26,20 @@#define DW_IC_CON_SPEED_FAST 0x4#define DW_IC_CON_SPEED_HIGH 0x6#define DW_IC_CON_SPEED_MASK 0x6 +#define DW_IC_CON_10BITADDR_SLAVE 0x8#define DW_IC_CON_10BITADDR_MASTER 0x10#define DW_IC_CON_RESTART_EN 0x20#define DW_IC_CON_SLAVE_DISABLE 0x40 +#define DW_IC_CON_STOP_DET_IFADDRESSED 0x80 +#define DW_IC_CON_TX_EMPTY_CTRL 0x100 +#define DW_IC_CON_RX_FIFO_FULL_HLD_CTRL 0x200/* * Registers offset */ #define DW_IC_CON 0x0#define DW_IC_TAR 0x4 +#define DW_IC_SAR 0x8#define DW_IC_DATA_CMD 0x10#define DW_IC_SS_SCL_HCNT 0x14#define DW_IC_SS_SCL_LCNT 0x18
@@ -89,9 +94,15 @@ DW_IC_INTR_STOP_DET)#define DW_IC_INTR_MASTER_MASK (DW_IC_INTR_DEFAULT_MASK | \ DW_IC_INTR_TX_EMPTY) +#define DW_IC_INTR_SLAVE_MASK (DW_IC_INTR_DEFAULT_MASK | \ + DW_IC_INTR_RX_DONE | \ + DW_IC_INTR_RX_UNDER | \ + DW_IC_INTR_RD_REQ) +#define DW_IC_STATUS_ACTIVITY 0x1#define DW_IC_STATUS_TFE BIT(2)#define DW_IC_STATUS_MASTER_ACTIVITY BIT(5) +#define DW_IC_STATUS_SLAVE_ACTIVITY BIT(6)#define DW_IC_SDA_HOLD_RX_SHIFT 16#define DW_IC_SDA_HOLD_RX_MASK GENMASK(23, DW_IC_SDA_HOLD_RX_SHIFT)
@@ -129,6 +140,9 @@#define ABRT_10B_RD_NORSTRT 10#define ABRT_MASTER_DIS 11#define ARB_LOST 12 +#define ABRT_SLAVE_FLUSH_TXFIFO 13 +#define ABRT_SLAVE_ARBLOST 14 +#define ABRT_SLAVE_RD_INTX 15#define DW_IC_TX_ABRT_7B_ADDR_NOACK (1UL << ABRT_7B_ADDR_NOACK)#define DW_IC_TX_ABRT_10ADDR1_NOACK (1UL << ABRT_10ADDR1_NOACK)
@@ -141,6 +155,9 @@#define DW_IC_TX_ABRT_10B_RD_NORSTRT (1UL << ABRT_10B_RD_NORSTRT)#define DW_IC_TX_ABRT_MASTER_DIS (1UL << ABRT_MASTER_DIS)#define DW_IC_TX_ARB_LOST (1UL << ARB_LOST) +#define DW_IC_RX_ABRT_SLAVE_RD_INTX (1UL << ABRT_SLAVE_RD_INTX) +#define DW_IC_RX_ABRT_SLAVE_ARBLOST (1UL << ABRT_SLAVE_ARBLOST) +#define DW_IC_RX_ABRT_SLAVE_FLUSH_TXFIFO (1UL << ABRT_SLAVE_FLUSH_TXFIFO)#define DW_IC_TX_ABRT_NOACK (DW_IC_TX_ABRT_7B_ADDR_NOACK | \ DW_IC_TX_ABRT_10ADDR1_NOACK | \
@@ -195,6 +212,7 @@ struct dw_i2c_dev {void __iomem *base;struct completion cmd_complete;struct clk *clk; +struct i2c_client *slave;u32 (*get_clk_rate_khz) (struct dw_i2c_dev *dev);struct dw_pci_controller *controller;int cmd_err;
@@ -214,6 +232,7 @@ struct dw_i2c_dev {struct i2c_adapter adapter;u32 functionality;u32 master_cfg; +u32 slave_cfg;unsigned int tx_fifo_depth;unsigned int rx_fifo_depth;int rx_outstanding;
@@ -257,6 +276,11 @@ extern void i2c_dw_disable(struct dw_i2c_dev *dev);extern void i2c_dw_disable_int (struct dw_i2c_dev *dev);extern u32 i2c_dw_read_comp_param (struct dw_i2c_dev *dev);extern int i2c_dw_probe (struct dw_i2c_dev *dev); +extern int i2c_dw_init_slave (struct dw_i2c_dev *dev); +extern void i2c_dw_disable_slave (struct dw_i2c_dev *dev); +extern void i2c_dw_disable_int_slave (struct dw_i2c_dev *dev); +extern u32 i2c_dw_read_comp_param_slave (struct dw_i2c_dev *dev); +extern int i2c_dw_probe_slave (struct dw_i2c_dev *dev);#if IS_ENABLED (CONFIG_I2C_DESIGNWARE_BAYTRAIL )extern int i2c_dw_eval_lock_support (struct dw_i2c_dev *dev);
drivers/i2c/busses/i2c-designware-src.c +6 -0
@@ -55,6 +55,12 @@ static char *abort_sources[] = { "trying to use disabled adapter", [ARB_LOST ] = "lost arbitration", + [ABRT_SLAVE_FLUSH_TXFIFO ] = + "read command so flush old data in the TX FIFO", + [ABRT_SLAVE_ARBLOST ] = + "slave lost the bus while transmitting data to a remote master", + [ABRT_SLAVE_RD_INTX ] = + "slave request for data to be transmitted and", };u32 dw_readl (struct dw_i2c_dev *dev,int offset)
Signature · 7 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Andy Shevchenko
reviewerRe: [PATCH v3 3/5] i2c: designware: Add slave definitions
Quoted 11 lines · Luis Oliveira
- Add slave defintitions to i2c-designware-core
- Changes inKconfigto auto-enableI2C_SLAVEwhen compiling the modules
- Add compatible string to designware-core.txt explaining the devicetree bindingsDocumentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0@@ -2,7 +2,9 @@
Quoted 8 lines
Required properties :
- - compatible : should be "snps,designware-i2c"
+ - compatible : should be:
+ - "snps,designware-i2c" to setup the hardware block as I2C master. + - "snps,designware-i2c-slave" to setup the hardware block as I2C slave.
Not sure about this one.
Compatible string is more generic than list of modes. Basically you have to add a property which selects mode.
DT people's ACK is a must for this change.
--- a/drivers/i2c/busses/Kconfig
Documentation/devicetree/bindings/i2c/i2c-designware.txt
Quoted 7 lines
+++ b/drivers/i2c/busses/Kconfig
Documentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0@@ -470,6 +470,7 @@ config I2C_DESIGNWARE_COREconfig
I2C_DESIGNWARE_PLATFORM
tristate "Synopsys DesignWare Platform"
selectI2C_DESIGNWARE_COREDocumentation/devicetree/bindings/i2c/i2c-designware.txt +1
-0+ select I2C_SLAVE
Common rule, generic dependencies usually go first
select I2C_SLAVE
select I2C_DESIGNWARE_CORE
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Rob Herring
maintainerRe: [PATCH v3 3/5] i2c: designware: Add slave definitions
Quoted 23 lines · Andy Shevchenko
Quoted 11 lines · Luis Oliveira
- Add slave defintitions to i2c-designware-core
- Changes inKconfigto auto-enableI2C_SLAVEwhen compiling the modules
- Add compatible string to designware-core.txt explaining the devicetree bindingsDocumentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0@@ -2,7 +2,9 @@Quoted 8 lines
Required properties :
- - compatible : should be "snps,designware-i2c"
+ - compatible : should be:
+ - "snps,designware-i2c" to setup the hardware block as I2C master. + - "snps,designware-i2c-slave" to setup the hardware block as I2C slave.Not sure about this one.
Quoted 2 lines
Compatible string is more generic than list of modes. Basically you have to add a property which selects mode.
Yes, agreed. And come up with a common property.
Quoted 14 lines
DT people's ACK is a must for this change.
--- a/drivers/i2c/busses/Kconfig
Documentation/devicetree/bindings/i2c/i2c-designware.txt
Quoted 7 lines
+++ b/drivers/i2c/busses/Kconfig
Documentation/devicetree/bindings/i2c/i2c-designware.txt +0
-0@@ -470,6 +470,7 @@ config I2C_DESIGNWARE_COREconfig
I2C_DESIGNWARE_PLATFORM
tristate "Synopsys DesignWare Platform"
selectI2C_DESIGNWARE_COREDocumentation/devicetree/bindings/i2c/i2c-designware.txt +1
-0+ select I2C_SLAVECommon rule, generic dependencies usually go first
Quoted 6 lines
select
I2C_SLAVE
selectI2C_DESIGNWARE_CORESignature · 2 lines
Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> Intel Finland Oy
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 3/5] i2c: designware: Add slave definitions
OK, I will create a "mode" string property in the devicetree that can be "master" or "slave".
Thank you all,
Luis
Quoted 45 lines · Rob Herring
Quoted 21 lines · Andy Shevchenko
Quoted 17 lines · Luis Oliveira
- Add slave defintitions to i2c-designware-core
- Changes inKconfigto auto-enableI2C_SLAVEwhen compiling the
modules
- Add compatible string to designware-core.txt explaining the
devicetree bindingsDocumentation/devicetree/bindings/i2c/i2c-designware.txt +3
-1@@ -2,7 +2,9 @@ Required properties : - - compatible : should be "snps,designware-i2c" + - compatible : should be: + - "snps,designware-i2c" to setup the hardware block as I2C master. + - "snps,designware-i2c-slave" to setup the hardware block as I2CQuoted 1 line
slave.
Not sure about this one.
Quoted 2 lines
Compatible string is more generic than list of modes. Basically you have to add a property which selects mode.
Yes, agreed. And come up with a common property.
Quoted 19 lines
DT people's ACK is a must for this change.
--- a/drivers/i2c/busses/Kconfig
Documentation/devicetree/bindings/i2c/i2c-designware.txt config I2C_DESIGNWARE_CORE · line 474
Quoted 7 lines
+++ b/drivers/i2c/busses/Kconfig
Documentation/devicetree/bindings/i2c/i2c-designware.txt +1
-0@@ -470,6 +470,7 @@ config I2C_DESIGNWARE_CORE config I2C_DESIGNWARE_PLATFORM tristate "Synopsys DesignWare Platform" select I2C_DESIGNWARE_CORE + select I2C_SLAVECommon rule, generic dependencies usually go first
select
I2C_SLAVE
selectI2C_DESIGNWARE_CORESignature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Signature · 2 lines
Best regards, Luis
PATCH v3 4/5 i2c: designware: Add slave mode as separated driver
In reply to Luis Oliveira - Slave mode selected by compatibility string in platform module
- Changes in Makefile to compile i2c-designware-core with slave functions
---
Changes V2->V3: (Andy Shevchenko)
- slave code in a separated driver as suggested by Wolfram Sang
- changes in Makefile for compilation purposes
drivers/i2c/busses/Makefile | 2 +- drivers/i2c/busses/i2c-designware-platdrv.c | 69 ++++- drivers/i2c/busses/i2c-designware-slave.c | 445 ++++++++++++++++++++++++++++ 3 files changed, 507 insertions(+), 9 deletions(-) create mode 100644 drivers/i2c/busses/i2c-designware-slave.c
drivers/i2c/busses/Makefile +1 -1
@@ -40,7 +40,7 @@ obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o obj-$(CONFIG_I2C_CPM) += i2c-cpm.o obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o obj-$(CONFIG_I2C_DESIGNWARE_CORE) += i2c-designware-core.o -i2c-designware-core-objs := i2c-designware-src.o i2c-designware-master.o +i2c-designware-core-objs := i2c-designware-src.o i2c-designware-slave.o i2c-designware-master.o obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o i2c-designware-platform-objs := i2c-designware-platdrv.o i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-baytrail.o
drivers/i2c/busses/i2c-designware-platdrv.c +61 -8
120 lines not on this page · raw message
drivers/i2c/busses/i2c-designware-slave.c new file +445 -0
445 lines not on this page · raw message
Signature · 7 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Andy Shevchenko
reviewerRe: [PATCH v3 4/5] i2c: designware: Add slave mode as separated driver
Quoted 19 lines · Luis Oliveira
- Slave mode selected by compatibility string in platform module
- Changes inMakefileto compile i2c-designware-core with slave functionsdrivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -160,6 +160,30 @@ static void i2c_dw_configure_master(struct platform_device *pdev) } }drivers/i2c/busses/i2c-designware-platdrv.c +6
-0+static void i2c_dw_configure_slave (struct platform_device *pdev) +{ +struct dw_i2c_dev *dev =platform_get_drvdata (pdev); + + dev->slave_cfg =DW_IC_CON_RX_FIFO_FULL_HLD_CTRL | + DW_IC_CON_RESTART_EN |
DW_IC_CON_STOP_DET_IFADDRESSED|
drivers/i2c/busses/i2c-designware-platdrv.c static void i2c_dw_configure_master(struct platform_device *pdev) · line 173
Quoted 6 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+ DW_IC_CON_SPEED_FAST; + + dev->functionality |=I2C_FUNC_SLAVE ; + dev->functionality &= ~I2C_FUNC_10BIT_ADDR ; +dev_info (&pdev->dev,"I am registed as a I2C Slave!\n" );
Not for production.
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 272
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -244,7 +268,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
I2C_FUNC_SMBUS_WORD_DATA|
I2C_FUNC_SMBUS_I2C_BLOCK;drivers/i2c/busses/i2c-designware-platdrv.c +2
-1-i2c_dw_configure_master (pdev); +if (of_device_is_compatible (pdev->dev.of_node, + "snps,designware-i2c-slave"))
No.
We don't use of_property_*() anymore in general. Instead find appropriate device_property_*() one. Besides, remind about comment regarding to the property itself.
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 275
Quoted 3 lines
drivers/i2c/busses/i2c-designware-platdrv.c +3
-0+i2c_dw_configure_slave (pdev); + else +i2c_dw_configure_master (pdev );
I would go then switch case here, where third variant prints an error that mode X doesn't supported / invalid and bails out.
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev)
Quoted 11 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -257,7 +285,13 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) }
if (!dev->tx_fifo_depth) {drivers/i2c/busses/i2c-designware-platdrv.c +4
-1-u32 param1 =i2c_dw_read_comp_param (dev); +u32 param1; + +if (of_device_is_compatible (pdev->dev.of_node, + "snps,designware-i2c-slave"))
Cache it in local variable if needed.
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 294
Quoted 3 lines
drivers/i2c/busses/i2c-designware-platdrv.c +3
-0+ param1 =i2c_dw_read_comp_param_slave (dev); + else + param1 =i2c_dw_read_comp_param (dev);
Shouldn't it have a _master suffix?
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct · line 320
Quoted 13 lines
dev->tx_fifo_depth= ((param1 >> 16) &0xff) + 1;dev->rx_fifo_depth= ((param1 >> 8) &0xff) + 1;drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -278,8 +312,12 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); } +if (of_device_is_compatible (pdev->dev.of_node, + "snps,designware-i2c-slave")) + r =i2c_dw_probe_slave (dev); +else + r =i2c_dw_probe (dev);
Ditto.
Quoted 7 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -291,10 +329,13 @@ static int dw_i2c_plat_remove(struct platform_device *pdev) struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
pm_runtime_get_sync(&pdev->dev);-
Doesn't belong to the patch.
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_remove(struct platform_device *pdev) · line 338
Quoted 8 lines
i2c_del_adapter(&dev->adapter);drivers/i2c/busses/i2c-designware-platdrv.c +5
-1-i2c_dw_disable (dev); +if (of_device_is_compatible (pdev->dev.of_node, + "snps,designware-i2c-slave")) +i2c_dw_disable_slave (dev); +else +i2c_dw_disable (dev);
_master?
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_remove(struct · line 352
Quoted 9 lines
pm_runtime_dont_use_autosuspend(&pdev->dev);pm_runtime_put_sync(&pdev->dev);drivers/i2c/busses/i2c-designware-platdrv.c +1
-0@@ -307,6 +348,9 @@ static int dw_i2c_plat_remove(struct platform_device *pdev) #ifdef CONFIG_OF static const struct of_device_id dw_i2c_of_match[] = { { .compatible = "snps,designware-i2c", }, +#ifndef CONFIG_ACPI
No, no, no.
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0+ { .compatible = "snps,designware-i2c-slave", }, +#endif {}, };MODULE_DEVICE_TABLE(of,
dw_i2c_of_match);drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -334,7 +378,11 @@ static int dw_i2c_plat_suspend(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_suspend(struct device *dev) · line 385
Quoted 6 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-1-i2c_dw_disable (i_dev); +if (of_device_is_compatible (pdev->dev.of_node, + "snps,designware-i2c-slave")) +i2c_dw_disable_slave (i_dev); +else +i2c_dw_disable (i_dev);
Same comments as above.
Quoted 7 lines
i2c_dw_plat_prepare_clk(i_dev, false);
return 0;drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -347,8 +395,13 @@ static int dw_i2c_plat_resume(struct device *dev)
i2c_dw_plat_prepare_clk(i_dev, true);
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_resume(struct device *dev) · line 403
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +6
-2-if (!i_dev->pm_runtime_disabled) -i2c_dw_init (i_dev); +if (!i_dev->pm_runtime_disabled) { +if (of_device_is_compatible (pdev->dev.of_node, + "snps,designware-i2c-slave")) +i2c_dw_init_slave (i_dev); +else +i2c_dw_init (i_dev);
Ditto.
drivers/i2c/busses/i2c-designware-slave.c
Quoted 2 lines
drivers/i2c/busses/i2c-designware-slave.c new file +0
-0
Slave...
drivers/i2c/busses/i2c-designware-slave.c line 2
Quoted 3 lines
drivers/i2c/busses/i2c-designware-slave.c new file +2
-0@@ -0,0 +1,445 @@ +/* +* Synopsys DesignWare I2C adapter driver (master only).
Master...
drivers/i2c/busses/i2c-designware-slave.c line 5
Quoted 3 lines
drivers/i2c/busses/i2c-designware-slave.c new file +3
-0+* +* Based on the TI DAVINCI I2C adapter driver. +*
+ * Copyright (C) 2006 Texas Instruments.
drivers/i2c/busses/i2c-designware-slave.c line 8
Quoted 2 lines
drivers/i2c/busses/i2c-designware-slave.c new file +2
-0+* Copyright (C) 2007 MontaVista Software Inc. +* Copyright (C) 2009 Provigent Ltd.
Are you sure about these lines?
drivers/i2c/busses/i2c-designware-slave.c line 32
Quoted 9 lines
drivers/i2c/busses/i2c-designware-slave.c new file +9
-0+#include <linux/export.h> +#include <linux/errno.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/pm_runtime.h> +#include <linux/delay.h> +#include <linux/module.h>
+ empty line.
Quoted 13 lines
drivers/i2c/busses/i2c-designware-slave.c new file +8
-0+#include "i2c-designware-core.h" + +/** +* i2c_dw_init_slave() - initialize the designware i2c slave hardware +* @dev: device private data +* +* This functions configures and enables the I2C. +* This function is called during I2C init function, and in case of timeout at
+ * run time.
+ */
drivers/i2c/busses/i2c-designware-slave.c line 58
Quoted 5 lines
drivers/i2c/busses/i2c-designware-slave.c new file +5
-0+int i2c_dw_init_slave (struct dw_i2c_dev *dev) +{ +u32 hcnt, lcnt; +u32 reg, comp_param1; +u32 sda_falling_time, scl_falling_time;
Reversed tree, pls.
Quoted 8 lines
drivers/i2c/busses/i2c-designware-slave.c new file +8
-0+int ret; + + ret =i2c_dw_acquire_lock (dev); +if (ret) +return ret; + + reg =dw_readl (dev,DW_IC_COMP_TYPE ); +if (reg ==___constant_swab32 (DW_IC_COMP_TYPE_VALUE )) {
drivers/i2c/busses/i2c-designware-slave.c line 74
Quoted 10 lines
drivers/i2c/busses/i2c-designware-slave.c new file +8
-0+/* Configure register endianness access */ + dev->accessor_flags |=ACCESS_SWAP ; + }else if (reg == (DW_IC_COMP_TYPE_VALUE &0x0000ffff )) { +/* Configure register access mode 16bit */ + dev->accessor_flags |=ACCESS_16BIT ; + }else if (reg !=DW_IC_COMP_TYPE_VALUE ) { +dev_err (dev->dev,"Unknown Synopsys component type: " +"0x%08x\n" , reg);
Don't break literals.
Choose one that fits.
dev_err(dev->dev, "Unknown Synopsys component type: "0x%08x\n",
reg);
dev_err(dev->dev,
"Unknown Synopsys component type: "0x%08x\n", reg);
dev_err(dev->dev,
"Unknown Synopsys component type: "0x%08x\n",
reg);
drivers/i2c/busses/i2c-designware-slave.c line 81
Quoted 9 lines
drivers/i2c/busses/i2c-designware-slave.c new file +7
-0+i2c_dw_release_lock (dev); +return -ENODEV ; + } + + comp_param1 =dw_readl (dev,DW_IC_COMP_PARAM_1 ); + +/* Disable the adapter */
Useless.
Quoted 4 lines
drivers/i2c/busses/i2c-designware-slave.c new file +3
-0+__i2c_dw_enable_and_wait (dev, false); + +/* set standard and fast speed deviders for high/low periods */
Capital letter!
Quoted 103 lines
drivers/i2c/busses/i2c-designware-slave.c new file +10
-0+ sda_falling_time = dev->sda_falling_time ?:300 ;/* ns */ + scl_falling_time = dev->scl_falling_time ?:300 ;/* ns */ + +/* Set SCL timing parameters for standard-mode */ +if (dev->ss_hcnt && dev->ss_lcnt) { + hcnt = dev->ss_hcnt; + lcnt = dev->ss_lcnt; + }else { + hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), + 4000, /* tHD;STA =tHIGH = 4.0 us */
drivers/i2c/busses/i2c-designware-slave.c new file +2
-0+ sda_falling_time, + 0, /* 0: DW default,1: Ideal */
drivers/i2c/busses/i2c-designware-slave.c new file +3
-0+ 0); /* No offset */ + lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), + 4700, /* tLOW = 4.7 us*/
drivers/i2c/busses/i2c-designware-slave.c new file +6
-0+ scl_falling_time, + 0); /* No offset */ + } +dw_writel (dev, hcnt,DW_IC_SS_SCL_HCNT ); +dw_writel (dev, lcnt,DW_IC_SS_SCL_LCNT ); + dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt,lcnt);
drivers/i2c/busses/i2c-designware-slave.c new file +2
-0+ +/* Set SCL timing parameters for fast-mode or fast-mode plus */
drivers/i2c/busses/i2c-designware-slave.c new file +1
-0+ if ((dev->clk_freq == 1000000) && dev->fp_hcnt && dev-Quoted 1 line
fp_lcnt) {drivers/i2c/busses/i2c-designware-slave.c new file +8
-0+ hcnt = dev->fp_hcnt; + lcnt = dev->fp_lcnt; + }else if (dev->fs_hcnt && dev->fs_lcnt) { + hcnt = dev->fs_hcnt; + lcnt = dev->fs_lcnt; + }else { + hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), + 600, /* tHD;STA =tHIGH = 0.6 us */
drivers/i2c/busses/i2c-designware-slave.c new file +2
-0+ sda_falling_time, + 0, /* 0: DW default,1: Ideal */
drivers/i2c/busses/i2c-designware-slave.c new file +3
-0+ 0); /* No offset */ + lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), + 1300, /* tLOW = 1.3 us*/
drivers/i2c/busses/i2c-designware-slave.c new file +6
-0+ scl_falling_time, + 0); /* No offset */ + } +dw_writel (dev, hcnt,DW_IC_FS_SCL_HCNT ); +dw_writel (dev, lcnt,DW_IC_FS_SCL_LCNT ); + dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt,lcnt);
drivers/i2c/busses/i2c-designware-slave.c new file +4
-0+ +if ((dev->slave_cfg &DW_IC_CON_SPEED_MASK ) == +DW_IC_CON_SPEED_HIGH ) { + if ((comp_param1 &
DW_IC_COMP_PARAM_1_SPEED_MODE_MASK)drivers/i2c/busses/i2c-designware-slave.c new file +2
-0+ != DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH) { + dev_err(dev->dev, "High Speed notsupported!\n");
drivers/i2c/busses/i2c-designware-slave.c new file +8
-0+ dev->slave_cfg &= ~DW_IC_CON_SPEED_MASK ; + dev->slave_cfg |=DW_IC_CON_SPEED_FAST ; + }else if (dev->hs_hcnt && dev->hs_lcnt) { + hcnt = dev->hs_hcnt; + lcnt = dev->hs_lcnt; +dw_writel (dev, hcnt,DW_IC_HS_SCL_HCNT ); +dw_writel (dev, lcnt,DW_IC_HS_SCL_LCNT ); + dev_dbg(dev->dev, "HighSpeed-mode HCNT:LCNT =%d:%d\n",
drivers/i2c/busses/i2c-designware-slave.c new file +10
-0+ hcnt, lcnt); + } + } + +/* Configure SDA Hold Time if required */ + reg =dw_readl (dev,DW_IC_COMP_VERSION ); + reg =dw_readl (dev,DW_IC_COMP_VERSION ); +if (reg >=DW_IC_SDA_HOLD_MIN_VERS ) { +if (!dev->sda_hold_time) { +/* Keep previous hold time setting if no one set it */
drivers/i2c/busses/i2c-designware-slave.c new file +1
-0+ dev->sda_hold_time = dw_readl(dev,
DW_IC_SDA_HOLD);drivers/i2c/busses/i2c-designware-slave.c new file +3
-0+ } +/* +* Workaround for avoiding TX arbitration lost in case I2C
drivers/i2c/busses/i2c-designware-slave.c new file +1
-0+ * slave pulls SDA down "too quickly" after fallingegde of
drivers/i2c/busses/i2c-designware-slave.c new file +1
-0+ * SCL by enabling non-zero SDA RX hold.Specification says it
drivers/i2c/busses/i2c-designware-slave.c new file +1
-0+ * extends incoming SDA low to high transition whileSCL is
drivers/i2c/busses/i2c-designware-slave.c new file +4
-0+* high but it apprears to help also above issue. +*/ +if (!(dev->sda_hold_time &DW_IC_SDA_HOLD_RX_MASK )) + dev->sda_hold_time |= 1 <<
DW_IC_SDA_HOLD_RX_SHIFT;drivers/i2c/busses/i2c-designware-slave.c new file +4
-0+dw_writel (dev, dev->sda_hold_time,DW_IC_SDA_HOLD ); + }else { + dev_warn(dev->dev, + "Hardware too old to adjust SDA holdtime.\n");
drivers/i2c/busses/i2c-designware-slave.c line 174
Quoted 8 lines
drivers/i2c/busses/i2c-designware-slave.c new file +8
-0+ } + +i2c_dw_configure_fifo_slave (dev); +i2c_dw_release_lock (dev); + +return 0 ; +} +EXPORT_SYMBOL_GPL (i2c_dw_init_slave);
So, don't make a noise in exported name space. When we need two sets of functions make an ops structure and assign it where appropriate.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
kbuild test robot
build botRe: [PATCH v3 4/5] i2c: designware: Add slave mode as separated driver
In reply to Luis Oliveiraurl: https://github.com/0day-ci/linux/commits/Luis-Oliveira/i2c-designware-Add-slave-support/20161118-193236 config: x86_64-randconfig-s4-11190538 (attached as .config) compiler: gcc-6 (Debian…
Hi Luis,
[auto build test ERROR on v4.9-rc5]
[also build test ERROR on next-20161117]
[cannot apply to wsa/i2c/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Luis-Oliveira/i2c-designware-Add-slave-support/20161118-193236
config: x86_64-randconfig-s4-11190538 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All error/warnings (new ones prefixed by >>):
drivers/i2c/busses/i2c-designware-slave.c: In function 'i2c_dw_irq_handler_slave':
>> drivers/i2c/busses/i2c-designware-slave.c:295:3: error: implicit declaration of function 'i2c_slave_event' [-Werror=implicit-function-declaration]
i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, &val);
^~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-designware-slave.c:295:31: error: 'I2C_SLAVE_WRITE_REQUESTED' undeclared (first use in this function)
i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, &val);
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/i2c/busses/i2c-designware-slave.c:295:31: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/i2c/busses/i2c-designware-slave.c:302:6: error: 'I2C_SLAVE_WRITE_RECEIVED' undeclared (first use in this function)
I2C_SLAVE_WRITE_RECEIVED, &val)) {
^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-designware-slave.c:314:7: error: 'I2C_SLAVE_READ_REQUESTED' undeclared (first use in this function)
I2C_SLAVE_READ_REQUESTED, &val))
^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-designware-slave.c:320:36: error: 'I2C_SLAVE_READ_PROCESSED' undeclared (first use in this function)
if (!i2c_slave_event(dev->slave, I2C_SLAVE_READ_PROCESSED,
^~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/i2c/busses/i2c-designware-slave.c:324:31: error: 'I2C_SLAVE_STOP' undeclared (first use in this function)
i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
^~~~~~~~~~~~~~
drivers/i2c/busses/i2c-designware-slave.c: At top level:
>> drivers/i2c/busses/i2c-designware-slave.c:370:2: error: unknown field 'reg_slave' specified in initializer
.reg_slave = i2c_dw_reg_slave,
^
>> drivers/i2c/busses/i2c-designware-slave.c:370:15: warning: excess elements in struct initializer
.reg_slave = i2c_dw_reg_slave,
^~~~~~~~~~~~~~~~
drivers/i2c/busses/i2c-designware-slave.c:370:15: note: (near initialization for 'i2c_dw_algo')
>> drivers/i2c/busses/i2c-designware-slave.c:371:2: error: unknown field 'unreg_slave' specified in initializer .unreg_slave = i2c_dw_unreg_slave,
^
drivers/i2c/busses/i2c-designware-slave.c:371:17: warning: excess elements in struct initializer
.unreg_slave = i2c_dw_unreg_slave,
^~~~~~~~~~~~~~~~~~
drivers/i2c/busses/i2c-designware-slave.c:371:17: note: (near initialization for 'i2c_dw_algo')
cc1: some warnings being treated as errors
vim +/i2c_slave_event +295 drivers/i2c/busses/i2c-designware-slave.c
289 dw_readl(dev, DW_IC_CLR_START_DET);
290 if (stat & DW_IC_INTR_ACTIVITY)
291 dw_readl(dev, DW_IC_CLR_ACTIVITY);
292 if (stat & DW_IC_INTR_RX_OVER)
293 dw_readl(dev, DW_IC_CLR_RX_OVER);
294 if ((stat & DW_IC_INTR_RX_FULL) && (stat & DW_IC_INTR_STOP_DET))
> 295 i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, &val);
296
297 if (slave_activity) {
298 if (stat & DW_IC_INTR_RD_REQ) {
299 if (stat & DW_IC_INTR_RX_FULL) {
300 val = dw_readl(dev, DW_IC_DATA_CMD);
301 if (!i2c_slave_event(dev->slave,
> 302 I2C_SLAVE_WRITE_RECEIVED, &val)) {
303 dev_dbg(dev->dev, "Byte %X acked! ",
304 val);
305 }
306 dw_readl(dev, DW_IC_CLR_RD_REQ);
307 stat = i2c_dw_read_clear_intrbits_slave(dev);
308 } else {
309 dw_readl(dev, DW_IC_CLR_RD_REQ);
310 dw_readl(dev, DW_IC_CLR_RX_UNDER);
311 stat = i2c_dw_read_clear_intrbits_slave(dev);
312 }
313 if (!i2c_slave_event(dev->slave,
> 314 I2C_SLAVE_READ_REQUESTED, &val))
315 dw_writel(dev, val, DW_IC_DATA_CMD);
316 }
317 }
318
319 if (stat & DW_IC_INTR_RX_DONE) {
> 320 if (!i2c_slave_event(dev->slave, I2C_SLAVE_READ_PROCESSED,
321 &val))
322 dw_readl(dev, DW_IC_CLR_RX_DONE);
323
> 324 i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
325 stat = i2c_dw_read_clear_intrbits_slave(dev);
326 return true;
327 }
328
329 if (stat & DW_IC_INTR_RX_FULL) {
330 val = dw_readl(dev, DW_IC_DATA_CMD);
331 if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED,
332 &val))
333 dev_dbg(dev->dev, "Byte %X acked! ", val);
334 } else {
335 i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val);
336 stat = i2c_dw_read_clear_intrbits_slave(dev);
337 }
338
339 if (stat & DW_IC_INTR_TX_OVER) {
340 dw_readl(dev, DW_IC_CLR_TX_OVER);
341 return true;
342 }
343 return true;
344 }
345
346 static irqreturn_t i2c_dw_isr_slave(int this_irq, void *dev_id)
347 {
348 struct dw_i2c_dev *dev = dev_id;
349 u32 stat, enabled, mode;
350
351 enabled = dw_readl(dev, DW_IC_ENABLE);
352 mode = dw_readl(dev, DW_IC_CON);
353 stat = dw_readl(dev, DW_IC_RAW_INTR_STAT);
354
355 dev_dbg(dev->dev, "%s: enabled=%#x stat=%#x\n", __func__, enabled,
356 stat);
357 if (!enabled || !(stat & ~DW_IC_INTR_ACTIVITY))
358 return IRQ_NONE;
359
360 stat = i2c_dw_read_clear_intrbits_slave(dev);
361 if (!i2c_dw_irq_handler_slave(dev))
362 return IRQ_NONE;
363
364 complete(&dev->cmd_complete);
365 return IRQ_HANDLED;
366 }
367
368 static struct i2c_algorithm i2c_dw_algo = {
369 .functionality = i2c_dw_func,
> 370 .reg_slave = i2c_dw_reg_slave,
> 371 .unreg_slave = i2c_dw_unreg_slave, 372 };
373
374 void i2c_dw_disable_slave(struct dw_i2c_dev *dev)
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v3 5/5 i2c: designware: Cleaning and commentary fixes
In reply to Luis Oliveira---
Changes V2->V3: (Andy Shevchenko)
- nothing except style issues
drivers/i2c/busses/i2c-designware-slave.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-designware-slave.c +5 -5
@@ -38,7 +38,7 @@ static void i2c_dw_configure_fifo_slave(struct dw_i2c_dev *dev)dw_writel (dev,0 ,DW_IC_TX_TL );dw_writel (dev,0 ,DW_IC_RX_TL ); -/* configure the i2c slave */ +/* configure the I2C slave */ dw_writel (dev, dev->slave_cfg,DW_IC_CON );dw_writel (dev,DW_IC_INTR_SLAVE_MASK ,DW_IC_INTR_MASK ); }
@@ -182,7 +182,7 @@ int i2c_dw_reg_slave(struct i2c_client *slave)if (slave->flags &I2C_CLIENT_TEN )return -EAFNOSUPPORT ;/* set slave address in the IC_SAR register, -* the address to which the DW_apb_i2c responds */ +* the address to which the DW_apb_i2c responds */ __i2c_dw_enable (dev, false);dw_writel (dev, slave->addr,DW_IC_SAR );
@@ -266,7 +266,7 @@ static u32 i2c_dw_read_clear_intrbits_slave(struct dw_i2c_dev *dev) }/* -* Interrupt service routine. This gets called whenever an I2C interrupt +* Interrupt service routine. This gets called whenever an I2C slave interrupt * occurs. */
@@ -300,7 +300,7 @@ static bool i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev) val =dw_readl (dev,DW_IC_DATA_CMD );if (!i2c_slave_event (dev->slave,I2C_SLAVE_WRITE_RECEIVED , &val)) { -dev_dbg (dev->dev,"Byte %X acked! " , +dev_dbg (dev->dev,"Byte %X acked!" , val); }dw_readl (dev,DW_IC_CLR_RD_REQ );
@@ -330,7 +330,7 @@ static bool i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev) val =dw_readl (dev,DW_IC_DATA_CMD );if (!i2c_slave_event (dev->slave,I2C_SLAVE_WRITE_RECEIVED , &val)) -dev_dbg (dev->dev,"Byte %X acked! " , val); +dev_dbg (dev->dev,"Byte %X acked!" , val); }else {i2c_slave_event (dev->slave,I2C_SLAVE_STOP , &val); stat =i2c_dw_read_clear_intrbits_slave (dev);
Signature · 1 line
2.10.2