Revert "i2c: designware: do not disable adapter after transfer"

This reverts commit 0317e6c0f1dc1ba86b8d9dccc010c5e77b8355fa.

Srinivas reported recently touchscreen and touchpad stopped working in
Haswell based machine in Linux 4.9-rc series with timeout errors from
i2c_designware:

[ 16.508013] i2c_designware INT33C3:00: controller timed out
[ 16.508302] i2c_hid i2c-MSFT0001:02: failed to change power setting.
[ 17.532016] i2c_designware INT33C3:00: controller timed out
[ 18.556022] i2c_designware INT33C3:00: controller timed out
[ 18.556315] i2c_hid i2c-ATML1000:00: failed to retrieve report from device.

I managed to reproduce similar errors on another Haswell based machine
where touchscreen initialization fails maybe in every 1/5 - 1/2 boots.
Since root cause for these errors is not clear yet and debugging is
ongoing it's better to revert this commit as we are near to release.

Reported-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by Jarkko Nikula and committed by Wolfram Sang 89119f08 4d6d5f1d

Changed files
+18 -37
drivers
+18 -37
drivers/i2c/busses/i2c-designware-core.c
··· 91 91 DW_IC_INTR_TX_ABRT | \ 92 92 DW_IC_INTR_STOP_DET) 93 93 94 - #define DW_IC_STATUS_ACTIVITY 0x1 95 - #define DW_IC_STATUS_TFE BIT(2) 96 - #define DW_IC_STATUS_MST_ACTIVITY BIT(5) 94 + #define DW_IC_STATUS_ACTIVITY 0x1 97 95 98 96 #define DW_IC_SDA_HOLD_RX_SHIFT 16 99 97 #define DW_IC_SDA_HOLD_RX_MASK GENMASK(23, DW_IC_SDA_HOLD_RX_SHIFT) ··· 476 478 { 477 479 struct i2c_msg *msgs = dev->msgs; 478 480 u32 ic_tar = 0; 479 - bool enabled; 480 481 481 - enabled = dw_readl(dev, DW_IC_ENABLE_STATUS) & 1; 482 - 483 - if (enabled) { 484 - u32 ic_status; 485 - 486 - /* 487 - * Only disable adapter if ic_tar and ic_con can't be 488 - * dynamically updated 489 - */ 490 - ic_status = dw_readl(dev, DW_IC_STATUS); 491 - if (!dev->dynamic_tar_update_enabled || 492 - (ic_status & DW_IC_STATUS_MST_ACTIVITY) || 493 - !(ic_status & DW_IC_STATUS_TFE)) { 494 - __i2c_dw_enable_and_wait(dev, false); 495 - enabled = false; 496 - } 497 - } 482 + /* Disable the adapter */ 483 + __i2c_dw_enable_and_wait(dev, false); 498 484 499 485 /* if the slave address is ten bit address, enable 10BITADDR */ 500 486 if (dev->dynamic_tar_update_enabled) { ··· 508 526 /* enforce disabled interrupts (due to HW issues) */ 509 527 i2c_dw_disable_int(dev); 510 528 511 - if (!enabled) 512 - __i2c_dw_enable(dev, true); 529 + /* Enable the adapter */ 530 + __i2c_dw_enable(dev, true); 513 531 514 532 /* Clear and enable interrupts */ 515 533 dw_readl(dev, DW_IC_CLR_INTR); ··· 690 708 } 691 709 692 710 /* 693 - * Prepare controller for a transaction and start transfer by calling 694 - * i2c_dw_xfer_init() 711 + * Prepare controller for a transaction and call i2c_dw_xfer_msg 695 712 */ 696 713 static int 697 714 i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ··· 732 751 ret = -ETIMEDOUT; 733 752 goto done; 734 753 } 754 + 755 + /* 756 + * We must disable the adapter before returning and signaling the end 757 + * of the current transfer. Otherwise the hardware might continue 758 + * generating interrupts which in turn causes a race condition with 759 + * the following transfer. Needs some more investigation if the 760 + * additional interrupts are a hardware bug or this driver doesn't 761 + * handle them correctly yet. 762 + */ 763 + __i2c_dw_enable(dev, false); 735 764 736 765 if (dev->msg_err) { 737 766 ret = dev->msg_err; ··· 884 893 */ 885 894 886 895 tx_aborted: 887 - if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) 888 - || dev->msg_err) { 889 - /* 890 - * We must disable interruts before returning and signaling 891 - * the end of the current transfer. Otherwise the hardware 892 - * might continue generating interrupts for non-existent 893 - * transfers. 894 - */ 895 - i2c_dw_disable_int(dev); 896 - dw_readl(dev, DW_IC_CLR_INTR); 897 - 896 + if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err) 898 897 complete(&dev->cmd_complete); 899 - } else if (unlikely(dev->accessor_flags & ACCESS_INTR_MASK)) { 898 + else if (unlikely(dev->accessor_flags & ACCESS_INTR_MASK)) { 900 899 /* workaround to trigger pending interrupt */ 901 900 stat = dw_readl(dev, DW_IC_INTR_MASK); 902 901 i2c_dw_disable_int(dev);