···1818static void amd_isp_dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *i2c_dev)1919{2020 pm_runtime_disable(i2c_dev->dev);2121-2222- if (i2c_dev->shared_with_punit)2323- pm_runtime_put_noidle(i2c_dev->dev);2421}25222623static inline u32 amd_isp_dw_i2c_get_clk_rate(struct dw_i2c_dev *i2c_dev)···76797780 device_enable_async_suspend(&pdev->dev);78817979- if (isp_i2c_dev->shared_with_punit)8080- pm_runtime_get_noresume(&pdev->dev);8181-8282 pm_runtime_enable(&pdev->dev);8383 pm_runtime_get_sync(&pdev->dev);8484···124130{125131 struct dw_i2c_dev *i_dev = dev_get_drvdata(dev);126132127127- if (i_dev->shared_with_punit)128128- return 0;129129-130133 i2c_dw_disable(i_dev);131134 i2c_dw_prepare_clk(i_dev, false);132135···152161 if (!i_dev)153162 return -ENODEV;154163155155- if (!i_dev->shared_with_punit)156156- i2c_dw_prepare_clk(i_dev, true);157157-164164+ i2c_dw_prepare_clk(i_dev, true);158165 i2c_dw_init(i_dev);159166160167 return 0;
+20
drivers/i2c/busses/i2c-designware-common.c
···492492493493 dev->clk_freq_optimized = device_property_read_bool(device, "snps,clk-freq-optimized");494494495495+ /* Mobileye controllers do not hold the clock on empty FIFO */496496+ if (device_is_compatible(device, "mobileye,eyeq6lplus-i2c"))497497+ dev->emptyfifo_hold_master = false;498498+ else499499+ dev->emptyfifo_hold_master = true;500500+495501 i2c_dw_adjust_bus_speed(dev);496502497503 if (is_of_node(fwnode))···923917 irq_flags = IRQF_NO_SUSPEND;924918 else925919 irq_flags = IRQF_SHARED | IRQF_COND_SUSPEND;920920+921921+ /*922922+ * The first writing to TX FIFO buffer causes transmission start.923923+ * If IC_EMPTYFIFO_HOLD_MASTER_EN is not set, when TX FIFO gets924924+ * empty, I2C controller finishes the transaction. If writing to925925+ * FIFO is interrupted, FIFO can get empty and the transaction will926926+ * be finished prematurely. FIFO buffer is filled in IRQ handler,927927+ * but in PREEMPT_RT kernel IRQ handler by default is executed928928+ * in thread that can be preempted with another higher priority929929+ * thread or an interrupt. So, IRQF_NO_THREAD flag is required in930930+ * order to prevent any preemption when filling the FIFO.931931+ */932932+ if (!dev->emptyfifo_hold_master)933933+ irq_flags |= IRQF_NO_THREAD;926934927935 ret = i2c_dw_acquire_lock(dev);928936 if (ret)
+3
drivers/i2c/busses/i2c-designware-core.h
···260260 * @clk_freq_optimized: if this value is true, it means the hardware reduces261261 * its internal clock frequency by reducing the internal latency required262262 * to generate the high period and low period of SCL line.263263+ * @emptyfifo_hold_master: true if the controller acting as master holds264264+ * the clock when the Tx FIFO is empty instead of emitting a stop.263265 *264266 * HCNT and LCNT parameters can be used if the platform knows more accurate265267 * values than the one computed based only on the input clock frequency.···320318 struct i2c_bus_recovery_info rinfo;321319 u32 bus_capacitance_pF;322320 bool clk_freq_optimized;321321+ bool emptyfifo_hold_master;323322};324323325324#define ACCESS_INTR_MASK BIT(0)
+117-45
drivers/i2c/busses/i2c-designware-master.c
···296296 u8 *tx_buf;297297 unsigned int val;298298299299- ACQUIRE(pm_runtime_active_auto_try, pm)(dev->dev);300300- if (ACQUIRE_ERR(pm_runtime_active_auto_try, &pm))299299+ PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev->dev, pm);300300+ if (PM_RUNTIME_ACQUIRE_ERR(&pm))301301 return -ENXIO;302302303303 /*···377377 struct i2c_msg *msgs = dev->msgs;378378 u32 intr_mask;379379 int tx_limit, rx_limit;380380- u32 addr = msgs[dev->msg_write_idx].addr;381380 u32 buf_len = dev->tx_buf_len;382381 u8 *buf = dev->tx_buf;383382 bool need_restart = false;···386387387388 for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) {388389 u32 flags = msgs[dev->msg_write_idx].flags;389389-390390- /*391391- * If target address has changed, we need to392392- * reprogram the target address in the I2C393393- * adapter when we are done with this transfer.394394- */395395- if (msgs[dev->msg_write_idx].addr != addr) {396396- dev_err(dev->dev,397397- "%s: invalid target address\n", __func__);398398- dev->msg_err = -EINVAL;399399- break;400400- }401390402391 if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {403392 /* new i2c_msg */···652665 if (stat & DW_IC_INTR_TX_EMPTY)653666 i2c_dw_xfer_msg(dev);654667668668+ /* Abort if we detect a STOP in the middle of a read or a write */669669+ if ((stat & DW_IC_INTR_STOP_DET) &&670670+ (dev->status & (STATUS_READ_IN_PROGRESS | STATUS_WRITE_IN_PROGRESS))) {671671+ dev_err(dev->dev, "spurious STOP detected\n");672672+ dev->rx_outstanding = 0;673673+ dev->msg_err = -EIO;674674+ }675675+655676 /*656677 * No need to modify or disable the interrupt mask here.657678 * i2c_dw_xfer_msg() will take care of it according to···741746}742747743748/*744744- * Prepare controller for a transaction and call i2c_dw_xfer_msg.749749+ * Prepare controller for a transaction, start the transfer of the @msgs750750+ * and wait for completion, either a STOP or a error.751751+ * Return: 0 or a negative error code.745752 */746753static int747747-i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)754754+__i2c_dw_xfer_one_part(struct dw_i2c_dev *dev, struct i2c_msg *msgs, size_t num)748755{749756 int ret;750750-751751- dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);752752-753753- pm_runtime_get_sync(dev->dev);754757755758 reinit_completion(&dev->cmd_complete);756759 dev->msgs = msgs;···761768 dev->abort_source = 0;762769 dev->rx_outstanding = 0;763770764764- ret = i2c_dw_acquire_lock(dev);765765- if (ret)766766- goto done_nolock;767767-768771 ret = i2c_dw_wait_bus_not_busy(dev);769772 if (ret < 0)770770- goto done;773773+ return ret;771774772775 /* Start the transfers */773776 i2c_dw_xfer_init(dev);···775786 /* i2c_dw_init() implicitly disables the adapter */776787 i2c_recover_bus(&dev->adapter);777788 i2c_dw_init(dev);778778- goto done;789789+ return ret;779790 }780791781792 /*···798809 */799810 __i2c_dw_disable_nowait(dev);800811801801- if (dev->msg_err) {802802- ret = dev->msg_err;803803- goto done;804804- }812812+ if (dev->msg_err)813813+ return dev->msg_err;805814806815 /* No error */807807- if (likely(!dev->cmd_err && !dev->status)) {808808- ret = num;809809- goto done;810810- }816816+ if (likely(!dev->cmd_err && !dev->status))817817+ return 0;811818812819 /* We have an error */813813- if (dev->cmd_err == DW_IC_ERR_TX_ABRT) {814814- ret = i2c_dw_handle_tx_abort(dev);815815- goto done;816816- }820820+ if (dev->cmd_err == DW_IC_ERR_TX_ABRT)821821+ return i2c_dw_handle_tx_abort(dev);817822818823 if (dev->status)819824 dev_err(dev->dev,820825 "transfer terminated early - interrupt latency too high?\n");821826822822- ret = -EIO;827827+ return -EIO;828828+}823829824824-done:830830+/*831831+ * Verify that the message at index @idx can be processed as part832832+ * of a single transaction. The @msgs array contains the messages833833+ * of the transaction. The message is checked against its predecessor834834+ * to ensure that it respects the limitation of the controller.835835+ * Return: true if the message can be processed, false otherwise.836836+ */837837+static bool838838+i2c_dw_msg_is_valid(struct dw_i2c_dev *dev, const struct i2c_msg *msgs, size_t idx)839839+{840840+ /*841841+ * The first message of a transaction is valid,842842+ * no constraints from a previous message.843843+ */844844+ if (!idx)845845+ return true;846846+847847+ /*848848+ * We cannot change the target address during a transaction, so make849849+ * sure the address is identical to the one of the previous message.850850+ */851851+ if (msgs[idx - 1].addr != msgs[idx].addr) {852852+ dev_err(dev->dev, "invalid target address\n");853853+ return false;854854+ }855855+856856+ /*857857+ * Make sure we don't need explicit RESTART between two messages858858+ * in the same direction for controllers that cannot emit them.859859+ */860860+ if (!dev->emptyfifo_hold_master &&861861+ (msgs[idx - 1].flags & I2C_M_RD) == (msgs[idx].flags & I2C_M_RD)) {862862+ dev_err(dev->dev, "cannot emit RESTART\n");863863+ return false;864864+ }865865+866866+ return true;867867+}868868+869869+static int870870+i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)871871+{872872+ struct i2c_msg *msgs_part;873873+ size_t cnt;874874+ int ret;875875+876876+ dev_dbg(dev->dev, "msgs: %d\n", num);877877+878878+ PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev->dev, pm);879879+ if (PM_RUNTIME_ACQUIRE_ERR(&pm))880880+ return -ENXIO;881881+882882+ ret = i2c_dw_acquire_lock(dev);883883+ if (ret)884884+ return ret;885885+886886+ /*887887+ * If the I2C_M_STOP is present in some the messages,888888+ * we do one transaction for each part up to the STOP.889889+ */890890+ for (msgs_part = msgs; msgs_part < msgs + num; msgs_part += cnt) {891891+ /*892892+ * Count the messages in a transaction, up to a STOP or893893+ * the end of the msgs. The last if below guarantees that894894+ * we check all messages and that msg_parts and cnt are895895+ * in-bounds of msgs and num.896896+ */897897+ for (cnt = 1; ; cnt++) {898898+ if (!i2c_dw_msg_is_valid(dev, msgs_part, cnt - 1)) {899899+ ret = -EINVAL;900900+ break;901901+ }902902+903903+ if ((msgs_part[cnt - 1].flags & I2C_M_STOP) ||904904+ (msgs_part + cnt == msgs + num))905905+ break;906906+ }907907+ if (ret < 0)908908+ break;909909+910910+ /* transfer one part up to a STOP */911911+ ret = __i2c_dw_xfer_one_part(dev, msgs_part, cnt);912912+ if (ret < 0)913913+ break;914914+ }915915+825916 i2c_dw_set_mode(dev, DW_IC_SLAVE);826917827918 i2c_dw_release_lock(dev);828919829829-done_nolock:830830- pm_runtime_put_autosuspend(dev->dev);831831-832832- return ret;920920+ if (ret < 0)921921+ return ret;922922+ return num;833923}834924835925int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)···926858 struct i2c_timings *t = &dev->timings;927859928860 dev->functionality |= I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY;861861+862862+ /* amd_i2c_dw_xfer_quirk() does not implement protocol mangling */863863+ if ((dev->flags & MODEL_MASK) != MODEL_AMD_NAVI_GPU)864864+ dev->functionality |= I2C_FUNC_PROTOCOL_MANGLING;929865930866 dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |931867 DW_IC_CON_RESTART_EN;
+14-28
drivers/i2c/busses/i2c-designware-platdrv.c
···160160 if (ret)161161 return ret;162162163163- dev->rst = devm_reset_control_get_optional_exclusive(device, NULL);163163+ dev->rst = devm_reset_control_get_optional_exclusive_deasserted(device, NULL);164164 if (IS_ERR(dev->rst))165165 return dev_err_probe(device, PTR_ERR(dev->rst), "failed to acquire reset\n");166166167167- reset_control_deassert(dev->rst);168168-169167 ret = i2c_dw_fw_parse_and_configure(dev);170168 if (ret)171171- goto exit_reset;169169+ return ret;172170173171 ret = i2c_dw_probe_lock_support(dev);174174- if (ret) {175175- dev_err_probe(device, ret, "failed to probe lock support\n");176176- goto exit_reset;177177- }172172+ if (ret)173173+ return dev_err_probe(device, ret, "failed to probe lock support\n");178174179175 i2c_dw_configure(dev);180176181177 /* Optional interface clock */182178 dev->pclk = devm_clk_get_optional(device, "pclk");183183- if (IS_ERR(dev->pclk)) {184184- ret = dev_err_probe(device, PTR_ERR(dev->pclk), "failed to acquire pclk\n");185185- goto exit_reset;186186- }179179+ if (IS_ERR(dev->pclk))180180+ return dev_err_probe(device, PTR_ERR(dev->pclk), "failed to acquire pclk\n");187181188182 dev->clk = devm_clk_get_optional(device, NULL);189189- if (IS_ERR(dev->clk)) {190190- ret = dev_err_probe(device, PTR_ERR(dev->clk), "failed to acquire clock\n");191191- goto exit_reset;192192- }183183+ if (IS_ERR(dev->clk))184184+ return dev_err_probe(device, PTR_ERR(dev->clk), "failed to acquire clock\n");193185194186 ret = i2c_dw_prepare_clk(dev, true);195187 if (ret)196196- goto exit_reset;188188+ return ret;197189198190 if (dev->clk) {199191 struct i2c_timings *t = &dev->timings;···225233 pm_runtime_enable(device);226234227235 ret = i2c_dw_probe(dev);228228- if (ret)229229- goto exit_probe;236236+ if (ret) {237237+ dw_i2c_plat_pm_cleanup(dev);238238+ i2c_dw_prepare_clk(dev, false);239239+ }230240231231- return ret;232232-233233-exit_probe:234234- dw_i2c_plat_pm_cleanup(dev);235235- i2c_dw_prepare_clk(dev, false);236236-exit_reset:237237- reset_control_assert(dev->rst);238241 return ret;239242}240243···249262 dw_i2c_plat_pm_cleanup(dev);250263251264 i2c_dw_prepare_clk(dev, false);252252-253253- reset_control_assert(dev->rst);254265}255266256267static const struct of_device_id dw_i2c_of_match[] = {268268+ { .compatible = "mobileye,eyeq6lplus-i2c" },257269 { .compatible = "mscc,ocelot-i2c" },258270 { .compatible = "snps,designware-i2c" },259271 {}