2018-12-17 14:16:54 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-02-21 01:14:21 +00:00
|
|
|
/*
|
|
|
|
* drivers/i2c/busses/i2c-tegra.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Google, Inc.
|
|
|
|
* Author: Colin Cross <ccross@android.com>
|
|
|
|
*/
|
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
#include <linux/acpi.h>
|
2020-04-01 22:21:28 +00:00
|
|
|
#include <linux/bitfield.h>
|
2011-02-21 01:14:21 +00:00
|
|
|
#include <linux/clk.h>
|
2019-02-12 19:06:42 +00:00
|
|
|
#include <linux/delay.h>
|
2019-02-12 19:06:46 +00:00
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2011-02-21 01:14:21 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/i2c.h>
|
2019-02-12 19:06:42 +00:00
|
|
|
#include <linux/init.h>
|
2011-02-21 01:14:21 +00:00
|
|
|
#include <linux/interrupt.h>
|
2019-02-12 19:06:42 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/iopoll.h>
|
2020-01-14 01:34:37 +00:00
|
|
|
#include <linux/irq.h>
|
2019-02-12 19:06:42 +00:00
|
|
|
#include <linux/kernel.h>
|
2020-01-14 01:34:38 +00:00
|
|
|
#include <linux/ktime.h>
|
2011-07-30 04:14:30 +00:00
|
|
|
#include <linux/module.h>
|
2023-07-14 17:46:16 +00:00
|
|
|
#include <linux/of.h>
|
2016-08-26 13:09:05 +00:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
2019-02-12 19:06:42 +00:00
|
|
|
#include <linux/platform_device.h>
|
2016-08-26 13:09:04 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2019-02-12 19:06:42 +00:00
|
|
|
#include <linux/reset.h>
|
2011-02-21 01:14:21 +00:00
|
|
|
|
|
|
|
#define BYTES_PER_FIFO_WORD 4
|
|
|
|
|
|
|
|
#define I2C_CNFG 0x000
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_CNFG_DEBOUNCE_CNT GENMASK(14, 12)
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_CNFG_PACKET_MODE_EN BIT(10)
|
|
|
|
#define I2C_CNFG_NEW_MASTER_FSM BIT(11)
|
|
|
|
#define I2C_CNFG_MULTI_MASTER_MODE BIT(17)
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_STATUS 0x01c
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_SL_CNFG 0x020
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_SL_CNFG_NACK BIT(1)
|
|
|
|
#define I2C_SL_CNFG_NEWSL BIT(2)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_SL_ADDR1 0x02c
|
i2c: tegra: Assign unused slave address
On Tegra, we should always use the "new" I2C slave controller, to avoid
issues with the old controller. This was implemented in commit 65a1a0a
"i2c: tegra: Enable new slave mode."
There is currently no driver for the Tegra I2C slave controller upstream.
Additionally, the controller cannot be completely disabled. Instead, we
need to:
a) Set I2C_SL_CNFG_NACK to make the controller automatically NACK any
incoming transactions.
b) The controller's definition of NACK isn't identical to the I2C
protocol's definition. Specifically, it will perform a standard NACK, but
*also* continue to hold the clock line low in expectation of receiving
more data. This can hang the bus, or at least cause transaction timeouts,
if something starts a transaction that matches the controller's slave
address. Since the default address is 0x00, the general call address,
this does occur in practice.
To avoid this, we explicitly program a slave address that is reserved for
future expansion. For current boards, this guarantees the address will
never be used. If a future board ever needs to use this address, we can
add platform data to determine a board-specific safe address. 0xfc is
picked by this patch.
This patch is based on a change previously posted by: Wei Ni <wni@nvidia.com>
http://www.spinics.net/lists/linux-i2c/msg05437.html
In turned based on internal changes by: Bharat Nihalani <bnihalani@nvidia.com>
A semantically equivalent change has been contained in the various
ChromeOS kernels for a while.
I tested this change on top of 3.0-rc2 on Harmony, and interacted with
the WM8903 I2C-based audio codec.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
2011-06-06 17:25:19 +00:00
|
|
|
#define I2C_SL_ADDR2 0x030
|
2019-06-07 13:56:23 +00:00
|
|
|
#define I2C_TLOW_SEXT 0x034
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_TX_FIFO 0x050
|
|
|
|
#define I2C_RX_FIFO 0x054
|
|
|
|
#define I2C_PACKET_TRANSFER_STATUS 0x058
|
|
|
|
#define I2C_FIFO_CONTROL 0x05c
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_FIFO_CONTROL_TX_FLUSH BIT(1)
|
|
|
|
#define I2C_FIFO_CONTROL_RX_FLUSH BIT(0)
|
2019-02-12 19:06:46 +00:00
|
|
|
#define I2C_FIFO_CONTROL_TX_TRIG(x) (((x) - 1) << 5)
|
|
|
|
#define I2C_FIFO_CONTROL_RX_TRIG(x) (((x) - 1) << 2)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_FIFO_STATUS 0x060
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_FIFO_STATUS_TX GENMASK(7, 4)
|
|
|
|
#define I2C_FIFO_STATUS_RX GENMASK(3, 0)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_INT_MASK 0x064
|
|
|
|
#define I2C_INT_STATUS 0x068
|
2019-02-12 19:06:43 +00:00
|
|
|
#define I2C_INT_BUS_CLR_DONE BIT(11)
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_INT_PACKET_XFER_COMPLETE BIT(7)
|
|
|
|
#define I2C_INT_NO_ACK BIT(3)
|
|
|
|
#define I2C_INT_ARBITRATION_LOST BIT(2)
|
|
|
|
#define I2C_INT_TX_FIFO_DATA_REQ BIT(1)
|
|
|
|
#define I2C_INT_RX_FIFO_DATA_REQ BIT(0)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_CLK_DIVISOR 0x06c
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_CLK_DIVISOR_STD_FAST_MODE GENMASK(31, 16)
|
|
|
|
#define I2C_CLK_DIVISOR_HSMODE GENMASK(15, 0)
|
2011-02-21 01:14:21 +00:00
|
|
|
|
|
|
|
#define DVC_CTRL_REG1 0x000
|
2016-08-26 13:08:58 +00:00
|
|
|
#define DVC_CTRL_REG1_INTR_EN BIT(10)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define DVC_CTRL_REG3 0x008
|
2016-08-26 13:08:58 +00:00
|
|
|
#define DVC_CTRL_REG3_SW_PROG BIT(26)
|
|
|
|
#define DVC_CTRL_REG3_I2C_DONE_INTR_EN BIT(30)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define DVC_STATUS 0x00c
|
2016-08-26 13:08:58 +00:00
|
|
|
#define DVC_STATUS_I2C_DONE_INTR BIT(30)
|
2011-02-21 01:14:21 +00:00
|
|
|
|
|
|
|
#define I2C_ERR_NONE 0x00
|
2019-06-11 10:51:08 +00:00
|
|
|
#define I2C_ERR_NO_ACK BIT(0)
|
|
|
|
#define I2C_ERR_ARBITRATION_LOST BIT(1)
|
|
|
|
#define I2C_ERR_UNKNOWN_INTERRUPT BIT(2)
|
2019-06-18 11:09:42 +00:00
|
|
|
#define I2C_ERR_RX_BUFFER_OVERFLOW BIT(3)
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-04-01 22:21:28 +00:00
|
|
|
#define PACKET_HEADER0_HEADER_SIZE GENMASK(29, 28)
|
|
|
|
#define PACKET_HEADER0_PACKET_ID GENMASK(23, 16)
|
|
|
|
#define PACKET_HEADER0_CONT_ID GENMASK(15, 12)
|
|
|
|
#define PACKET_HEADER0_PROTOCOL GENMASK(7, 4)
|
|
|
|
#define PACKET_HEADER0_PROTOCOL_I2C 1
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_HEADER_CONT_ON_NAK BIT(21)
|
|
|
|
#define I2C_HEADER_READ BIT(19)
|
|
|
|
#define I2C_HEADER_10BIT_ADDR BIT(18)
|
|
|
|
#define I2C_HEADER_IE_ENABLE BIT(17)
|
|
|
|
#define I2C_HEADER_REPEAT_START BIT(16)
|
|
|
|
#define I2C_HEADER_CONTINUE_XFER BIT(15)
|
2011-02-21 01:14:21 +00:00
|
|
|
#define I2C_HEADER_SLAVE_ADDR_SHIFT 1
|
2015-06-30 10:54:26 +00:00
|
|
|
|
2019-02-12 19:06:43 +00:00
|
|
|
#define I2C_BUS_CLEAR_CNFG 0x084
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_BC_SCLK_THRESHOLD GENMASK(23, 16)
|
2019-02-12 19:06:43 +00:00
|
|
|
#define I2C_BC_STOP_COND BIT(2)
|
|
|
|
#define I2C_BC_TERMINATE BIT(1)
|
|
|
|
#define I2C_BC_ENABLE BIT(0)
|
|
|
|
#define I2C_BUS_CLEAR_STATUS 0x088
|
|
|
|
#define I2C_BC_STATUS BIT(0)
|
|
|
|
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_CONFIG_LOAD 0x08c
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_MSTR_CONFIG_LOAD BIT(0)
|
2015-06-30 10:54:26 +00:00
|
|
|
|
2016-03-14 13:22:18 +00:00
|
|
|
#define I2C_CLKEN_OVERRIDE 0x090
|
2016-08-26 13:08:58 +00:00
|
|
|
#define I2C_MST_CORE_CLKEN_OVR BIT(0)
|
2016-03-14 13:22:18 +00:00
|
|
|
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_INTERFACE_TIMING_0 0x094
|
|
|
|
#define I2C_INTERFACE_TIMING_THIGH GENMASK(13, 8)
|
|
|
|
#define I2C_INTERFACE_TIMING_TLOW GENMASK(5, 0)
|
|
|
|
#define I2C_INTERFACE_TIMING_1 0x098
|
2019-06-07 13:56:23 +00:00
|
|
|
#define I2C_INTERFACE_TIMING_TBUF GENMASK(29, 24)
|
|
|
|
#define I2C_INTERFACE_TIMING_TSU_STO GENMASK(21, 16)
|
|
|
|
#define I2C_INTERFACE_TIMING_THD_STA GENMASK(13, 8)
|
|
|
|
#define I2C_INTERFACE_TIMING_TSU_STA GENMASK(5, 0)
|
|
|
|
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_0 0x09c
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_THIGH GENMASK(13, 8)
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_TLOW GENMASK(5, 0)
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_1 0x0a0
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_TSU_STO GENMASK(21, 16)
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_THD_STA GENMASK(13, 8)
|
|
|
|
#define I2C_HS_INTERFACE_TIMING_TSU_STA GENMASK(5, 0)
|
2016-08-31 13:28:40 +00:00
|
|
|
|
2018-06-19 10:49:42 +00:00
|
|
|
#define I2C_MST_FIFO_CONTROL 0x0b4
|
|
|
|
#define I2C_MST_FIFO_CONTROL_RX_FLUSH BIT(0)
|
|
|
|
#define I2C_MST_FIFO_CONTROL_TX_FLUSH BIT(1)
|
|
|
|
#define I2C_MST_FIFO_CONTROL_RX_TRIG(x) (((x) - 1) << 4)
|
|
|
|
#define I2C_MST_FIFO_CONTROL_TX_TRIG(x) (((x) - 1) << 16)
|
|
|
|
|
|
|
|
#define I2C_MST_FIFO_STATUS 0x0b8
|
2020-04-01 22:21:28 +00:00
|
|
|
#define I2C_MST_FIFO_STATUS_TX GENMASK(23, 16)
|
|
|
|
#define I2C_MST_FIFO_STATUS_RX GENMASK(7, 0)
|
2018-06-19 10:49:42 +00:00
|
|
|
|
2020-04-01 22:21:28 +00:00
|
|
|
/* configuration load timeout in microseconds */
|
|
|
|
#define I2C_CONFIG_LOAD_TIMEOUT 1000000
|
2019-02-12 19:06:48 +00:00
|
|
|
|
2020-09-29 22:19:13 +00:00
|
|
|
/* packet header size in bytes */
|
2019-02-12 19:06:45 +00:00
|
|
|
#define I2C_PACKET_HEADER_SIZE 12
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
/*
|
2020-01-14 01:34:39 +00:00
|
|
|
* I2C Controller will use PIO mode for transfers up to 32 bytes in order to
|
|
|
|
* avoid DMA overhead, otherwise external APB DMA controller will be used.
|
|
|
|
* Note that the actual MAX PIO length is 20 bytes because 32 bytes include
|
|
|
|
* I2C_PACKET_HEADER_SIZE.
|
2019-02-12 19:06:46 +00:00
|
|
|
*/
|
2020-01-14 01:34:39 +00:00
|
|
|
#define I2C_PIO_MODE_PREFERRED_LEN 32
|
2019-02-12 19:06:46 +00:00
|
|
|
|
2012-06-13 10:12:38 +00:00
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* msg_end_type: The bus control which needs to be sent at end of transfer.
|
|
|
|
* @MSG_END_STOP: Send stop pulse.
|
|
|
|
* @MSG_END_REPEAT_START: Send repeat-start.
|
|
|
|
* @MSG_END_CONTINUE: Don't send stop or repeat-start.
|
2012-06-13 10:12:38 +00:00
|
|
|
*/
|
|
|
|
enum msg_end_type {
|
|
|
|
MSG_END_STOP,
|
|
|
|
MSG_END_REPEAT_START,
|
|
|
|
MSG_END_CONTINUE,
|
|
|
|
};
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2012-08-18 19:17:46 +00:00
|
|
|
/**
|
2020-09-29 22:19:13 +00:00
|
|
|
* struct tegra_i2c_hw_feature : per hardware generation features
|
|
|
|
* @has_continue_xfer_support: continue-transfer supported
|
2013-01-05 12:04:46 +00:00
|
|
|
* @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer
|
2020-09-29 22:19:13 +00:00
|
|
|
* completion interrupt on per packet basis.
|
2015-06-30 10:54:26 +00:00
|
|
|
* @has_config_load_reg: Has the config load register to load the new
|
|
|
|
* configuration.
|
2013-01-05 12:04:46 +00:00
|
|
|
* @clk_divisor_hs_mode: Clock divisor in HS mode.
|
2019-02-12 19:06:48 +00:00
|
|
|
* @clk_divisor_std_mode: Clock divisor in standard mode. It is
|
|
|
|
* applicable if there is no fast clock source i.e. single clock
|
|
|
|
* source.
|
|
|
|
* @clk_divisor_fast_mode: Clock divisor in fast mode. It is
|
2013-01-05 12:04:46 +00:00
|
|
|
* applicable if there is no fast clock source i.e. single clock
|
|
|
|
* source.
|
2018-12-17 14:16:53 +00:00
|
|
|
* @clk_divisor_fast_plus_mode: Clock divisor in fast mode plus. It is
|
|
|
|
* applicable if there is no fast clock source (i.e. single
|
|
|
|
* clock source).
|
|
|
|
* @has_multi_master_mode: The I2C controller supports running in single-master
|
|
|
|
* or multi-master mode.
|
|
|
|
* @has_slcg_override_reg: The I2C controller supports a register that
|
|
|
|
* overrides the second level clock gating.
|
|
|
|
* @has_mst_fifo: The I2C controller contains the new MST FIFO interface that
|
|
|
|
* provides additional features and allows for longer messages to
|
|
|
|
* be transferred in one go.
|
2020-09-29 22:19:13 +00:00
|
|
|
* @quirks: I2C adapter quirks for limiting write/read transfer size and not
|
2019-01-08 21:59:10 +00:00
|
|
|
* allowing 0 length transfers.
|
2019-02-12 19:06:43 +00:00
|
|
|
* @supports_bus_clear: Bus Clear support to recover from bus hang during
|
|
|
|
* SDA stuck low from device for some unknown reasons.
|
2019-02-12 19:06:46 +00:00
|
|
|
* @has_apb_dma: Support of APBDMA on corresponding Tegra chip.
|
2019-02-12 19:06:48 +00:00
|
|
|
* @tlow_std_mode: Low period of the clock in standard mode.
|
|
|
|
* @thigh_std_mode: High period of the clock in standard mode.
|
|
|
|
* @tlow_fast_fastplus_mode: Low period of the clock in fast/fast-plus modes.
|
|
|
|
* @thigh_fast_fastplus_mode: High period of the clock in fast/fast-plus modes.
|
|
|
|
* @setup_hold_time_std_mode: Setup and hold time for start and stop conditions
|
|
|
|
* in standard mode.
|
|
|
|
* @setup_hold_time_fast_fast_plus_mode: Setup and hold time for start and stop
|
|
|
|
* conditions in fast/fast-plus modes.
|
|
|
|
* @setup_hold_time_hs_mode: Setup and hold time for start and stop conditions
|
|
|
|
* in HS mode.
|
|
|
|
* @has_interface_timing_reg: Has interface timing register to program the tuned
|
|
|
|
* timing settings.
|
2012-08-18 19:17:46 +00:00
|
|
|
*/
|
|
|
|
struct tegra_i2c_hw_feature {
|
|
|
|
bool has_continue_xfer_support;
|
2013-01-05 12:04:46 +00:00
|
|
|
bool has_per_pkt_xfer_complete_irq;
|
2015-06-30 10:54:26 +00:00
|
|
|
bool has_config_load_reg;
|
2020-09-29 22:18:59 +00:00
|
|
|
u32 clk_divisor_hs_mode;
|
|
|
|
u32 clk_divisor_std_mode;
|
|
|
|
u32 clk_divisor_fast_mode;
|
|
|
|
u32 clk_divisor_fast_plus_mode;
|
2016-03-14 13:22:18 +00:00
|
|
|
bool has_multi_master_mode;
|
|
|
|
bool has_slcg_override_reg;
|
2018-06-19 10:49:42 +00:00
|
|
|
bool has_mst_fifo;
|
2019-01-08 21:59:10 +00:00
|
|
|
const struct i2c_adapter_quirks *quirks;
|
2019-02-12 19:06:43 +00:00
|
|
|
bool supports_bus_clear;
|
2019-02-12 19:06:46 +00:00
|
|
|
bool has_apb_dma;
|
2020-09-29 22:18:59 +00:00
|
|
|
u32 tlow_std_mode;
|
|
|
|
u32 thigh_std_mode;
|
|
|
|
u32 tlow_fast_fastplus_mode;
|
|
|
|
u32 thigh_fast_fastplus_mode;
|
2019-02-12 19:06:48 +00:00
|
|
|
u32 setup_hold_time_std_mode;
|
|
|
|
u32 setup_hold_time_fast_fast_plus_mode;
|
|
|
|
u32 setup_hold_time_hs_mode;
|
|
|
|
bool has_interface_timing_reg;
|
2012-08-18 19:17:46 +00:00
|
|
|
};
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
/**
|
2018-12-17 14:16:52 +00:00
|
|
|
* struct tegra_i2c_dev - per device I2C context
|
2011-02-21 01:14:21 +00:00
|
|
|
* @dev: device reference for power management
|
2018-12-17 14:16:52 +00:00
|
|
|
* @hw: Tegra I2C HW feature
|
|
|
|
* @adapter: core I2C layer adapter information
|
|
|
|
* @div_clk: clock reference for div clock of I2C controller
|
2020-09-29 22:18:55 +00:00
|
|
|
* @clocks: array of I2C controller clocks
|
|
|
|
* @nclocks: number of clocks in the array
|
2018-12-17 14:16:53 +00:00
|
|
|
* @rst: reset control for the I2C controller
|
2011-02-21 01:14:21 +00:00
|
|
|
* @base: ioremapped registers cookie
|
2019-02-12 19:06:46 +00:00
|
|
|
* @base_phys: physical base address of the I2C controller
|
2018-12-17 14:16:52 +00:00
|
|
|
* @cont_id: I2C controller ID, used for packet header
|
|
|
|
* @irq: IRQ number of transfer complete interrupt
|
|
|
|
* @is_dvc: identifies the DVC I2C controller, has a different register layout
|
2019-06-07 13:56:23 +00:00
|
|
|
* @is_vi: identifies the VI I2C controller, has a different register layout
|
2011-02-21 01:14:21 +00:00
|
|
|
* @msg_complete: transfer completion notifier
|
2023-04-27 12:39:14 +00:00
|
|
|
* @msg_buf_remaining: size of unsent data in the message buffer
|
|
|
|
* @msg_len: length of message in current transfer
|
2011-02-21 01:14:21 +00:00
|
|
|
* @msg_err: error code for completed message
|
|
|
|
* @msg_buf: pointer to current message data
|
2020-09-29 22:19:13 +00:00
|
|
|
* @msg_read: indicates that the transfer is a read access
|
2021-12-10 12:15:57 +00:00
|
|
|
* @timings: i2c timings information like bus frequency
|
2020-09-29 22:19:11 +00:00
|
|
|
* @multimaster_mode: indicates that I2C controller is in multi-master mode
|
2023-04-27 12:39:15 +00:00
|
|
|
* @dma_chan: DMA channel
|
2019-02-12 19:06:46 +00:00
|
|
|
* @dma_phys: handle to DMA resources
|
|
|
|
* @dma_buf: pointer to allocated DMA buffer
|
|
|
|
* @dma_buf_size: DMA buffer size
|
2020-09-29 22:19:11 +00:00
|
|
|
* @dma_mode: indicates active DMA transfer
|
2019-02-12 19:06:46 +00:00
|
|
|
* @dma_complete: DMA completion notifier
|
2020-09-29 22:19:11 +00:00
|
|
|
* @atomic_mode: indicates active atomic transfer
|
2011-02-21 01:14:21 +00:00
|
|
|
*/
|
|
|
|
struct tegra_i2c_dev {
|
|
|
|
struct device *dev;
|
|
|
|
struct i2c_adapter adapter;
|
2020-09-29 22:19:10 +00:00
|
|
|
|
|
|
|
const struct tegra_i2c_hw_feature *hw;
|
2013-11-06 23:42:05 +00:00
|
|
|
struct reset_control *rst;
|
2020-09-29 22:18:59 +00:00
|
|
|
unsigned int cont_id;
|
|
|
|
unsigned int irq;
|
2020-09-29 22:19:10 +00:00
|
|
|
|
|
|
|
phys_addr_t base_phys;
|
|
|
|
void __iomem *base;
|
|
|
|
|
|
|
|
struct clk_bulk_data clocks[2];
|
|
|
|
unsigned int nclocks;
|
|
|
|
|
|
|
|
struct clk *div_clk;
|
2021-12-10 12:15:57 +00:00
|
|
|
struct i2c_timings timings;
|
2020-09-29 22:19:10 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
struct completion msg_complete;
|
2020-09-29 22:19:10 +00:00
|
|
|
size_t msg_buf_remaining;
|
2023-04-27 12:39:14 +00:00
|
|
|
unsigned int msg_len;
|
2011-02-21 01:14:21 +00:00
|
|
|
int msg_err;
|
|
|
|
u8 *msg_buf;
|
2020-09-29 22:19:10 +00:00
|
|
|
|
|
|
|
struct completion dma_complete;
|
2023-04-27 12:39:15 +00:00
|
|
|
struct dma_chan *dma_chan;
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned int dma_buf_size;
|
2022-10-20 14:39:33 +00:00
|
|
|
struct device *dma_dev;
|
2019-02-12 19:06:46 +00:00
|
|
|
dma_addr_t dma_phys;
|
2020-09-29 22:19:06 +00:00
|
|
|
void *dma_buf;
|
2020-09-29 22:19:10 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
bool multimaster_mode;
|
|
|
|
bool atomic_mode;
|
|
|
|
bool dma_mode;
|
2020-09-29 22:19:10 +00:00
|
|
|
bool msg_read;
|
|
|
|
bool is_dvc;
|
|
|
|
bool is_vi;
|
2011-02-21 01:14:21 +00:00
|
|
|
};
|
|
|
|
|
2023-05-06 21:19:01 +00:00
|
|
|
#define IS_DVC(dev) (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && (dev)->is_dvc)
|
2023-05-06 21:19:02 +00:00
|
|
|
#define IS_VI(dev) (IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC) && (dev)->is_vi)
|
2023-05-06 21:19:01 +00:00
|
|
|
|
2016-08-26 13:08:57 +00:00
|
|
|
static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned int reg)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2020-01-14 01:34:40 +00:00
|
|
|
writel_relaxed(val, i2c_dev->base + reg);
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:10 +00:00
|
|
|
static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2020-01-14 01:34:40 +00:00
|
|
|
return readl_relaxed(i2c_dev->base + reg);
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* If necessary, i2c_writel() and i2c_readl() will offset the register
|
|
|
|
* in order to talk to the I2C block inside the DVC block.
|
2011-02-21 01:14:21 +00:00
|
|
|
*/
|
2020-09-29 22:19:10 +00:00
|
|
|
static u32 tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2023-05-06 21:19:01 +00:00
|
|
|
if (IS_DVC(i2c_dev))
|
2011-02-21 01:14:21 +00:00
|
|
|
reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40;
|
2023-05-06 21:19:02 +00:00
|
|
|
else if (IS_VI(i2c_dev))
|
2019-06-07 13:56:23 +00:00
|
|
|
reg = 0xc00 + (reg << 2);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:10 +00:00
|
|
|
static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned int reg)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2020-01-14 01:34:40 +00:00
|
|
|
writel_relaxed(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
|
2012-06-13 10:12:36 +00:00
|
|
|
|
2020-09-29 22:19:13 +00:00
|
|
|
/* read back register to make sure that register writes completed */
|
2012-06-13 10:12:36 +00:00
|
|
|
if (reg != I2C_TX_FIFO)
|
2020-01-14 01:34:40 +00:00
|
|
|
readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
|
2023-05-06 21:19:02 +00:00
|
|
|
else if (IS_VI(i2c_dev))
|
2021-01-12 19:02:41 +00:00
|
|
|
readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, I2C_INT_STATUS));
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:10 +00:00
|
|
|
static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2020-01-14 01:34:40 +00:00
|
|
|
return readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned int reg, unsigned int len)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
|
|
|
writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
|
|
|
|
}
|
|
|
|
|
2021-01-12 19:02:41 +00:00
|
|
|
static void i2c_writesl_vi(struct tegra_i2c_dev *i2c_dev, void *data,
|
|
|
|
unsigned int reg, unsigned int len)
|
|
|
|
{
|
|
|
|
u32 *data32 = data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VI I2C controller has known hardware bug where writes get stuck
|
|
|
|
* when immediate multiple writes happen to TX_FIFO register.
|
|
|
|
* Recommended software work around is to read I2C register after
|
|
|
|
* each write to TX_FIFO register to flush out the data.
|
|
|
|
*/
|
|
|
|
while (len--)
|
|
|
|
i2c_writel(i2c_dev, *data32++, reg);
|
|
|
|
}
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned int reg, unsigned int len)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
|
|
|
readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_i2c_mask_irq(struct tegra_i2c_dev *i2c_dev, u32 mask)
|
|
|
|
{
|
2016-08-26 13:08:59 +00:00
|
|
|
u32 int_mask;
|
|
|
|
|
|
|
|
int_mask = i2c_readl(i2c_dev, I2C_INT_MASK) & ~mask;
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_writel(i2c_dev, int_mask, I2C_INT_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_i2c_unmask_irq(struct tegra_i2c_dev *i2c_dev, u32 mask)
|
|
|
|
{
|
2016-08-26 13:08:59 +00:00
|
|
|
u32 int_mask;
|
|
|
|
|
|
|
|
int_mask = i2c_readl(i2c_dev, I2C_INT_MASK) | mask;
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_writel(i2c_dev, int_mask, I2C_INT_MASK);
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
static void tegra_i2c_dma_complete(void *args)
|
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = args;
|
|
|
|
|
|
|
|
complete(&i2c_dev->dma_complete);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_i2c_dma_submit(struct tegra_i2c_dev *i2c_dev, size_t len)
|
|
|
|
{
|
|
|
|
struct dma_async_tx_descriptor *dma_desc;
|
|
|
|
enum dma_transfer_direction dir;
|
|
|
|
|
|
|
|
dev_dbg(i2c_dev->dev, "starting DMA for length: %zu\n", len);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
reinit_completion(&i2c_dev->dma_complete);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
dir = i2c_dev->msg_read ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV;
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2023-04-27 12:39:15 +00:00
|
|
|
dma_desc = dmaengine_prep_slave_single(i2c_dev->dma_chan, i2c_dev->dma_phys,
|
2019-02-12 19:06:46 +00:00
|
|
|
len, dir, DMA_PREP_INTERRUPT |
|
|
|
|
DMA_CTRL_ACK);
|
|
|
|
if (!dma_desc) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_err(i2c_dev->dev, "failed to get %s DMA descriptor\n",
|
|
|
|
i2c_dev->msg_read ? "RX" : "TX");
|
2019-02-12 19:06:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_desc->callback = tegra_i2c_dma_complete;
|
|
|
|
dma_desc->callback_param = i2c_dev;
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
dmaengine_submit(dma_desc);
|
2023-04-27 12:39:15 +00:00
|
|
|
dma_async_issue_pending(i2c_dev->dma_chan);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_i2c_release_dma(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
if (i2c_dev->dma_buf) {
|
2022-10-20 14:39:33 +00:00
|
|
|
dma_free_coherent(i2c_dev->dma_dev, i2c_dev->dma_buf_size,
|
2019-02-12 19:06:46 +00:00
|
|
|
i2c_dev->dma_buf, i2c_dev->dma_phys);
|
|
|
|
i2c_dev->dma_buf = NULL;
|
|
|
|
}
|
|
|
|
|
2023-04-27 12:39:15 +00:00
|
|
|
if (i2c_dev->dma_chan) {
|
|
|
|
dma_release_channel(i2c_dev->dma_chan);
|
|
|
|
i2c_dev->dma_chan = NULL;
|
2019-02-12 19:06:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
dma_addr_t dma_phys;
|
2020-09-29 22:19:10 +00:00
|
|
|
u32 *dma_buf;
|
2019-02-12 19:06:46 +00:00
|
|
|
int err;
|
|
|
|
|
2023-05-06 21:19:02 +00:00
|
|
|
if (IS_VI(i2c_dev))
|
2019-02-21 15:00:38 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-08-08 14:01:06 +00:00
|
|
|
if (i2c_dev->hw->has_apb_dma) {
|
2022-09-06 14:47:14 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_TEGRA20_APB_DMA)) {
|
|
|
|
dev_dbg(i2c_dev->dev, "APB DMA support not enabled\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else if (!IS_ENABLED(CONFIG_TEGRA186_GPC_DMA)) {
|
|
|
|
dev_dbg(i2c_dev->dev, "GPC DMA support not enabled\n");
|
2019-02-21 15:00:38 +00:00
|
|
|
return 0;
|
2019-02-12 19:06:46 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 12:39:15 +00:00
|
|
|
/*
|
|
|
|
* The same channel will be used for both RX and TX.
|
|
|
|
* Keeping the name as "tx" for backward compatibility
|
|
|
|
* with existing devicetrees.
|
|
|
|
*/
|
|
|
|
i2c_dev->dma_chan = dma_request_chan(i2c_dev->dev, "tx");
|
|
|
|
if (IS_ERR(i2c_dev->dma_chan)) {
|
|
|
|
err = PTR_ERR(i2c_dev->dma_chan);
|
2023-07-07 13:26:19 +00:00
|
|
|
i2c_dev->dma_chan = NULL;
|
2019-02-12 19:06:46 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2023-04-27 12:39:15 +00:00
|
|
|
i2c_dev->dma_dev = i2c_dev->dma_chan->device->dev;
|
2020-09-29 22:18:57 +00:00
|
|
|
i2c_dev->dma_buf_size = i2c_dev->hw->quirks->max_write_len +
|
|
|
|
I2C_PACKET_HEADER_SIZE;
|
|
|
|
|
2022-10-20 14:39:33 +00:00
|
|
|
dma_buf = dma_alloc_coherent(i2c_dev->dma_dev, i2c_dev->dma_buf_size,
|
2019-02-12 19:06:46 +00:00
|
|
|
&dma_phys, GFP_KERNEL | __GFP_NOWARN);
|
|
|
|
if (!dma_buf) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_err(i2c_dev->dev, "failed to allocate DMA buffer\n");
|
2019-02-12 19:06:46 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c_dev->dma_buf = dma_buf;
|
|
|
|
i2c_dev->dma_phys = dma_phys;
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
tegra_i2c_release_dma(i2c_dev);
|
|
|
|
if (err != -EPROBE_DEFER) {
|
|
|
|
dev_err(i2c_dev->dev, "cannot use DMA: %d\n", err);
|
2019-02-15 15:31:26 +00:00
|
|
|
dev_err(i2c_dev->dev, "falling back to PIO\n");
|
2019-02-12 19:06:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:18:58 +00:00
|
|
|
/*
|
|
|
|
* One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller)
|
|
|
|
* block. This block is identical to the rest of the I2C blocks, except that
|
|
|
|
* it only supports master mode, it has registers moved around, and it needs
|
|
|
|
* some extra init to get it into I2C mode. The register moves are handled
|
2020-09-29 22:19:13 +00:00
|
|
|
* by i2c_readl() and i2c_writel().
|
2020-09-29 22:18:58 +00:00
|
|
|
*/
|
|
|
|
static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = dvc_readl(i2c_dev, DVC_CTRL_REG3);
|
|
|
|
val |= DVC_CTRL_REG3_SW_PROG;
|
|
|
|
val |= DVC_CTRL_REG3_I2C_DONE_INTR_EN;
|
|
|
|
dvc_writel(i2c_dev, val, DVC_CTRL_REG3);
|
|
|
|
|
|
|
|
val = dvc_readl(i2c_dev, DVC_CTRL_REG1);
|
|
|
|
val |= DVC_CTRL_REG1_INTR_EN;
|
|
|
|
dvc_writel(i2c_dev, val, DVC_CTRL_REG1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_i2c_vi_init(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
|
|
|
|
value = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, 2) |
|
|
|
|
FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, 4);
|
|
|
|
i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_0);
|
|
|
|
|
|
|
|
value = FIELD_PREP(I2C_INTERFACE_TIMING_TBUF, 4) |
|
|
|
|
FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STO, 7) |
|
|
|
|
FIELD_PREP(I2C_INTERFACE_TIMING_THD_STA, 4) |
|
|
|
|
FIELD_PREP(I2C_INTERFACE_TIMING_TSU_STA, 4);
|
|
|
|
i2c_writel(i2c_dev, value, I2C_INTERFACE_TIMING_1);
|
|
|
|
|
|
|
|
value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_THIGH, 3) |
|
|
|
|
FIELD_PREP(I2C_HS_INTERFACE_TIMING_TLOW, 8);
|
|
|
|
i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_0);
|
|
|
|
|
|
|
|
value = FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STO, 11) |
|
|
|
|
FIELD_PREP(I2C_HS_INTERFACE_TIMING_THD_STA, 11) |
|
|
|
|
FIELD_PREP(I2C_HS_INTERFACE_TIMING_TSU_STA, 11);
|
|
|
|
i2c_writel(i2c_dev, value, I2C_HS_INTERFACE_TIMING_1);
|
|
|
|
|
|
|
|
value = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND;
|
|
|
|
i2c_writel(i2c_dev, value, I2C_BUS_CLEAR_CNFG);
|
|
|
|
|
|
|
|
i2c_writel(i2c_dev, 0x0, I2C_TLOW_SEXT);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:07 +00:00
|
|
|
static int tegra_i2c_poll_register(struct tegra_i2c_dev *i2c_dev,
|
|
|
|
u32 reg, u32 mask, u32 delay_us,
|
|
|
|
u32 timeout_us)
|
|
|
|
{
|
|
|
|
void __iomem *addr = i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg);
|
|
|
|
u32 val;
|
|
|
|
|
2021-01-12 13:17:09 +00:00
|
|
|
if (!i2c_dev->atomic_mode)
|
2020-09-29 22:19:07 +00:00
|
|
|
return readl_relaxed_poll_timeout(addr, val, !(val & mask),
|
|
|
|
delay_us, timeout_us);
|
|
|
|
|
|
|
|
return readl_relaxed_poll_timeout_atomic(addr, val, !(val & mask),
|
|
|
|
delay_us, timeout_us);
|
|
|
|
}
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
2020-09-29 22:19:07 +00:00
|
|
|
u32 mask, val, offset;
|
2020-09-29 22:18:44 +00:00
|
|
|
int err;
|
2018-06-19 10:49:42 +00:00
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo) {
|
|
|
|
mask = I2C_MST_FIFO_CONTROL_TX_FLUSH |
|
|
|
|
I2C_MST_FIFO_CONTROL_RX_FLUSH;
|
|
|
|
offset = I2C_MST_FIFO_CONTROL;
|
|
|
|
} else {
|
|
|
|
mask = I2C_FIFO_CONTROL_TX_FLUSH |
|
|
|
|
I2C_FIFO_CONTROL_RX_FLUSH;
|
|
|
|
offset = I2C_FIFO_CONTROL;
|
|
|
|
}
|
2016-08-26 13:08:59 +00:00
|
|
|
|
2018-06-19 10:49:42 +00:00
|
|
|
val = i2c_readl(i2c_dev, offset);
|
|
|
|
val |= mask;
|
|
|
|
i2c_writel(i2c_dev, val, offset);
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:19:07 +00:00
|
|
|
err = tegra_i2c_poll_register(i2c_dev, offset, mask, 1000, 1000000);
|
2020-09-29 22:18:44 +00:00
|
|
|
if (err) {
|
|
|
|
dev_err(i2c_dev->dev, "failed to flush FIFO\n");
|
|
|
|
return err;
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-31 13:28:42 +00:00
|
|
|
static int tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2020-09-29 22:19:07 +00:00
|
|
|
if (!i2c_dev->hw->has_config_load_reg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD);
|
|
|
|
|
|
|
|
err = tegra_i2c_poll_register(i2c_dev, I2C_CONFIG_LOAD, 0xffffffff,
|
|
|
|
1000, I2C_CONFIG_LOAD_TIMEOUT);
|
|
|
|
if (err) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_err(i2c_dev->dev, "failed to load config\n");
|
2020-09-29 22:19:07 +00:00
|
|
|
return err;
|
2016-08-31 13:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:18:48 +00:00
|
|
|
static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2020-09-29 22:19:10 +00:00
|
|
|
u32 val, clk_divisor, clk_multiplier, tsu_thd, tlow, thigh, non_hs_mode;
|
2021-11-25 16:53:44 +00:00
|
|
|
acpi_handle handle = ACPI_HANDLE(i2c_dev->dev);
|
2021-12-10 12:15:57 +00:00
|
|
|
struct i2c_timings *t = &i2c_dev->timings;
|
2016-08-26 13:09:04 +00:00
|
|
|
int err;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:18:52 +00:00
|
|
|
/*
|
|
|
|
* The reset shouldn't ever fail in practice. The failure will be a
|
|
|
|
* sign of a severe problem that needs to be resolved. Still we don't
|
|
|
|
* want to fail the initialization completely because this may break
|
|
|
|
* kernel boot up since voltage regulators use I2C. Hence, we will
|
|
|
|
* emit a noisy warning on error, which won't stay unnoticed and
|
|
|
|
* won't hose machine entirely.
|
|
|
|
*/
|
2021-11-25 16:53:44 +00:00
|
|
|
if (handle)
|
|
|
|
err = acpi_evaluate_object(handle, "_RST", NULL, NULL);
|
|
|
|
else
|
|
|
|
err = reset_control_reset(i2c_dev->rst);
|
|
|
|
|
2020-09-29 22:18:52 +00:00
|
|
|
WARN_ON_ONCE(err);
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2023-05-06 21:19:01 +00:00
|
|
|
if (IS_DVC(i2c_dev))
|
2011-02-21 01:14:21 +00:00
|
|
|
tegra_dvc_init(i2c_dev);
|
|
|
|
|
2011-04-25 21:32:27 +00:00
|
|
|
val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN |
|
2020-04-01 22:21:28 +00:00
|
|
|
FIELD_PREP(I2C_CNFG_DEBOUNCE_CNT, 2);
|
2016-03-14 13:22:18 +00:00
|
|
|
|
|
|
|
if (i2c_dev->hw->has_multi_master_mode)
|
|
|
|
val |= I2C_CNFG_MULTI_MASTER_MODE;
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_writel(i2c_dev, val, I2C_CNFG);
|
|
|
|
i2c_writel(i2c_dev, 0, I2C_INT_MASK);
|
2013-01-05 12:04:46 +00:00
|
|
|
|
2023-05-06 21:19:02 +00:00
|
|
|
if (IS_VI(i2c_dev))
|
2019-06-07 13:56:23 +00:00
|
|
|
tegra_i2c_vi_init(i2c_dev);
|
|
|
|
|
2021-12-10 12:15:57 +00:00
|
|
|
switch (t->bus_freq_hz) {
|
2020-09-29 22:18:49 +00:00
|
|
|
case I2C_MAX_STANDARD_MODE_FREQ + 1 ... I2C_MAX_FAST_MODE_PLUS_FREQ:
|
|
|
|
default:
|
2019-02-12 19:06:48 +00:00
|
|
|
tlow = i2c_dev->hw->tlow_fast_fastplus_mode;
|
|
|
|
thigh = i2c_dev->hw->thigh_fast_fastplus_mode;
|
|
|
|
tsu_thd = i2c_dev->hw->setup_hold_time_fast_fast_plus_mode;
|
2020-09-29 22:18:49 +00:00
|
|
|
|
2021-12-10 12:15:57 +00:00
|
|
|
if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ)
|
2020-09-29 22:18:49 +00:00
|
|
|
non_hs_mode = i2c_dev->hw->clk_divisor_fast_plus_mode;
|
|
|
|
else
|
|
|
|
non_hs_mode = i2c_dev->hw->clk_divisor_fast_mode;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0 ... I2C_MAX_STANDARD_MODE_FREQ:
|
2019-02-12 19:06:48 +00:00
|
|
|
tlow = i2c_dev->hw->tlow_std_mode;
|
|
|
|
thigh = i2c_dev->hw->thigh_std_mode;
|
|
|
|
tsu_thd = i2c_dev->hw->setup_hold_time_std_mode;
|
2020-09-29 22:18:49 +00:00
|
|
|
non_hs_mode = i2c_dev->hw->clk_divisor_std_mode;
|
|
|
|
break;
|
2019-02-12 19:06:48 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:13 +00:00
|
|
|
/* make sure clock divisor programmed correctly */
|
2020-09-29 22:18:49 +00:00
|
|
|
clk_divisor = FIELD_PREP(I2C_CLK_DIVISOR_HSMODE,
|
|
|
|
i2c_dev->hw->clk_divisor_hs_mode) |
|
|
|
|
FIELD_PREP(I2C_CLK_DIVISOR_STD_FAST_MODE, non_hs_mode);
|
|
|
|
i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR);
|
|
|
|
|
2019-02-12 19:06:48 +00:00
|
|
|
if (i2c_dev->hw->has_interface_timing_reg) {
|
2020-04-01 22:21:28 +00:00
|
|
|
val = FIELD_PREP(I2C_INTERFACE_TIMING_THIGH, thigh) |
|
|
|
|
FIELD_PREP(I2C_INTERFACE_TIMING_TLOW, tlow);
|
2019-02-12 19:06:48 +00:00
|
|
|
i2c_writel(i2c_dev, val, I2C_INTERFACE_TIMING_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* Configure setup and hold times only when tsu_thd is non-zero.
|
|
|
|
* Otherwise, preserve the chip default values.
|
2019-02-12 19:06:48 +00:00
|
|
|
*/
|
|
|
|
if (i2c_dev->hw->has_interface_timing_reg && tsu_thd)
|
|
|
|
i2c_writel(i2c_dev, tsu_thd, I2C_INTERFACE_TIMING_1);
|
|
|
|
|
2020-09-29 22:19:14 +00:00
|
|
|
clk_multiplier = (tlow + thigh + 2) * (non_hs_mode + 1);
|
2020-09-29 22:18:48 +00:00
|
|
|
|
|
|
|
err = clk_set_rate(i2c_dev->div_clk,
|
2021-12-10 12:15:57 +00:00
|
|
|
t->bus_freq_hz * clk_multiplier);
|
2020-09-29 22:18:48 +00:00
|
|
|
if (err) {
|
|
|
|
dev_err(i2c_dev->dev, "failed to set div-clk rate: %d\n", err);
|
|
|
|
return err;
|
2019-02-12 19:06:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 21:19:02 +00:00
|
|
|
if (!IS_DVC(i2c_dev) && !IS_VI(i2c_dev)) {
|
2011-04-25 18:29:54 +00:00
|
|
|
u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG);
|
2016-08-26 13:08:59 +00:00
|
|
|
|
i2c: tegra: Assign unused slave address
On Tegra, we should always use the "new" I2C slave controller, to avoid
issues with the old controller. This was implemented in commit 65a1a0a
"i2c: tegra: Enable new slave mode."
There is currently no driver for the Tegra I2C slave controller upstream.
Additionally, the controller cannot be completely disabled. Instead, we
need to:
a) Set I2C_SL_CNFG_NACK to make the controller automatically NACK any
incoming transactions.
b) The controller's definition of NACK isn't identical to the I2C
protocol's definition. Specifically, it will perform a standard NACK, but
*also* continue to hold the clock line low in expectation of receiving
more data. This can hang the bus, or at least cause transaction timeouts,
if something starts a transaction that matches the controller's slave
address. Since the default address is 0x00, the general call address,
this does occur in practice.
To avoid this, we explicitly program a slave address that is reserved for
future expansion. For current boards, this guarantees the address will
never be used. If a future board ever needs to use this address, we can
add platform data to determine a board-specific safe address. 0xfc is
picked by this patch.
This patch is based on a change previously posted by: Wei Ni <wni@nvidia.com>
http://www.spinics.net/lists/linux-i2c/msg05437.html
In turned based on internal changes by: Bharat Nihalani <bnihalani@nvidia.com>
A semantically equivalent change has been contained in the various
ChromeOS kernels for a while.
I tested this change on top of 3.0-rc2 on Harmony, and interacted with
the WM8903 I2C-based audio codec.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
2011-06-06 17:25:19 +00:00
|
|
|
sl_cfg |= I2C_SL_CNFG_NACK | I2C_SL_CNFG_NEWSL;
|
|
|
|
i2c_writel(i2c_dev, sl_cfg, I2C_SL_CNFG);
|
|
|
|
i2c_writel(i2c_dev, 0xfc, I2C_SL_ADDR1);
|
|
|
|
i2c_writel(i2c_dev, 0x00, I2C_SL_ADDR2);
|
2011-04-25 18:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 13:09:04 +00:00
|
|
|
err = tegra_i2c_flush_fifos(i2c_dev);
|
2016-08-31 13:28:41 +00:00
|
|
|
if (err)
|
2019-09-10 09:29:17 +00:00
|
|
|
return err;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->multimaster_mode && i2c_dev->hw->has_slcg_override_reg)
|
2016-03-14 13:22:18 +00:00
|
|
|
i2c_writel(i2c_dev, I2C_MST_CORE_CLKEN_OVR, I2C_CLKEN_OVERRIDE);
|
|
|
|
|
2016-08-31 13:28:42 +00:00
|
|
|
err = tegra_i2c_wait_for_config_load(i2c_dev);
|
|
|
|
if (err)
|
2019-09-10 09:29:17 +00:00
|
|
|
return err;
|
2015-06-30 10:54:26 +00:00
|
|
|
|
2019-09-10 09:29:17 +00:00
|
|
|
return 0;
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 13:28:44 +00:00
|
|
|
static int tegra_i2c_disable_packet_mode(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
u32 cnfg;
|
|
|
|
|
2018-07-03 08:55:43 +00:00
|
|
|
/*
|
|
|
|
* NACK interrupt is generated before the I2C controller generates
|
2020-09-29 22:19:13 +00:00
|
|
|
* the STOP condition on the bus. So, wait for 2 clock periods
|
2018-07-03 08:55:43 +00:00
|
|
|
* before disabling the controller so that the STOP condition has
|
|
|
|
* been delivered properly.
|
|
|
|
*/
|
2021-12-10 12:15:57 +00:00
|
|
|
udelay(DIV_ROUND_UP(2 * 1000000, i2c_dev->timings.bus_freq_hz));
|
2018-07-03 08:55:43 +00:00
|
|
|
|
2016-08-31 13:28:44 +00:00
|
|
|
cnfg = i2c_readl(i2c_dev, I2C_CNFG);
|
|
|
|
if (cnfg & I2C_CNFG_PACKET_MODE_EN)
|
|
|
|
i2c_writel(i2c_dev, cnfg & ~I2C_CNFG_PACKET_MODE_EN, I2C_CNFG);
|
|
|
|
|
|
|
|
return tegra_i2c_wait_for_config_load(i2c_dev);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:18:58 +00:00
|
|
|
static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
size_t buf_remaining = i2c_dev->msg_buf_remaining;
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned int words_to_transfer, rx_fifo_avail;
|
|
|
|
u8 *buf = i2c_dev->msg_buf;
|
|
|
|
u32 val;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* Catch overflow due to message fully sent before the check for
|
|
|
|
* RX FIFO availability.
|
2020-09-29 22:18:58 +00:00
|
|
|
*/
|
|
|
|
if (WARN_ON_ONCE(!(i2c_dev->msg_buf_remaining)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo) {
|
|
|
|
val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS);
|
|
|
|
rx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_RX, val);
|
|
|
|
} else {
|
|
|
|
val = i2c_readl(i2c_dev, I2C_FIFO_STATUS);
|
|
|
|
rx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_RX, val);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:13 +00:00
|
|
|
/* round down to exclude partial word at the end of buffer */
|
2020-09-29 22:18:58 +00:00
|
|
|
words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD;
|
|
|
|
if (words_to_transfer > rx_fifo_avail)
|
|
|
|
words_to_transfer = rx_fifo_avail;
|
|
|
|
|
|
|
|
i2c_readsl(i2c_dev, buf, I2C_RX_FIFO, words_to_transfer);
|
|
|
|
|
|
|
|
buf += words_to_transfer * BYTES_PER_FIFO_WORD;
|
|
|
|
buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD;
|
|
|
|
rx_fifo_avail -= words_to_transfer;
|
|
|
|
|
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* If there is a partial word at the end of buffer, handle it
|
|
|
|
* manually to prevent overwriting past the end of buffer.
|
2020-09-29 22:18:58 +00:00
|
|
|
*/
|
|
|
|
if (rx_fifo_avail > 0 && buf_remaining > 0) {
|
|
|
|
/*
|
|
|
|
* buf_remaining > 3 check not needed as rx_fifo_avail == 0
|
|
|
|
* when (words_to_transfer was > rx_fifo_avail) earlier
|
|
|
|
* in this function.
|
|
|
|
*/
|
|
|
|
val = i2c_readl(i2c_dev, I2C_RX_FIFO);
|
|
|
|
val = cpu_to_le32(val);
|
|
|
|
memcpy(buf, &val, buf_remaining);
|
|
|
|
buf_remaining = 0;
|
|
|
|
rx_fifo_avail--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RX FIFO must be drained, otherwise it's an Overflow case. */
|
|
|
|
if (WARN_ON_ONCE(rx_fifo_avail))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
i2c_dev->msg_buf_remaining = buf_remaining;
|
|
|
|
i2c_dev->msg_buf = buf;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
size_t buf_remaining = i2c_dev->msg_buf_remaining;
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned int words_to_transfer, tx_fifo_avail;
|
|
|
|
u8 *buf = i2c_dev->msg_buf;
|
|
|
|
u32 val;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo) {
|
|
|
|
val = i2c_readl(i2c_dev, I2C_MST_FIFO_STATUS);
|
|
|
|
tx_fifo_avail = FIELD_GET(I2C_MST_FIFO_STATUS_TX, val);
|
|
|
|
} else {
|
|
|
|
val = i2c_readl(i2c_dev, I2C_FIFO_STATUS);
|
|
|
|
tx_fifo_avail = FIELD_GET(I2C_FIFO_STATUS_TX, val);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:13 +00:00
|
|
|
/* round down to exclude partial word at the end of buffer */
|
2020-09-29 22:18:58 +00:00
|
|
|
words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD;
|
|
|
|
|
2020-09-29 22:19:13 +00:00
|
|
|
/*
|
|
|
|
* This hunk pushes 4 bytes at a time into the TX FIFO.
|
|
|
|
*
|
|
|
|
* It's very common to have < 4 bytes, hence there is no word
|
|
|
|
* to push if we have less than 4 bytes to transfer.
|
|
|
|
*/
|
2020-09-29 22:18:58 +00:00
|
|
|
if (words_to_transfer) {
|
|
|
|
if (words_to_transfer > tx_fifo_avail)
|
|
|
|
words_to_transfer = tx_fifo_avail;
|
|
|
|
|
|
|
|
/*
|
2020-09-29 22:19:00 +00:00
|
|
|
* Update state before writing to FIFO. Note that this may
|
|
|
|
* cause us to finish writing all bytes (AKA buf_remaining
|
|
|
|
* goes to 0), hence we have a potential for an interrupt
|
|
|
|
* (PACKET_XFER_COMPLETE is not maskable), but GIC interrupt
|
|
|
|
* is disabled at this point.
|
2020-09-29 22:18:58 +00:00
|
|
|
*/
|
|
|
|
buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD;
|
|
|
|
tx_fifo_avail -= words_to_transfer;
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2020-09-29 22:18:58 +00:00
|
|
|
i2c_dev->msg_buf_remaining = buf_remaining;
|
2020-09-29 22:19:14 +00:00
|
|
|
i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
2023-05-06 21:19:02 +00:00
|
|
|
if (IS_VI(i2c_dev))
|
2021-01-12 19:02:41 +00:00
|
|
|
i2c_writesl_vi(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
|
|
|
|
else
|
|
|
|
i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
|
2020-09-29 22:18:58 +00:00
|
|
|
|
|
|
|
buf += words_to_transfer * BYTES_PER_FIFO_WORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* If there is a partial word at the end of buffer, handle it manually
|
|
|
|
* to prevent reading past the end of buffer, which could cross a page
|
2020-09-29 22:18:58 +00:00
|
|
|
* boundary and fault.
|
|
|
|
*/
|
|
|
|
if (tx_fifo_avail > 0 && buf_remaining > 0) {
|
|
|
|
/*
|
|
|
|
* buf_remaining > 3 check not needed as tx_fifo_avail == 0
|
|
|
|
* when (words_to_transfer was > tx_fifo_avail) earlier
|
|
|
|
* in this function for non-zero words_to_transfer.
|
|
|
|
*/
|
|
|
|
memcpy(&val, buf, buf_remaining);
|
|
|
|
val = le32_to_cpu(val);
|
|
|
|
|
|
|
|
i2c_dev->msg_buf_remaining = 0;
|
|
|
|
i2c_dev->msg_buf = NULL;
|
|
|
|
|
|
|
|
i2c_writel(i2c_dev, val, I2C_TX_FIFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
const u32 status_err = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST;
|
|
|
|
struct tegra_i2c_dev *i2c_dev = dev_id;
|
2020-09-29 22:19:10 +00:00
|
|
|
u32 status;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
|
|
|
status = i2c_readl(i2c_dev, I2C_INT_STATUS);
|
|
|
|
|
|
|
|
if (status == 0) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_warn(i2c_dev->dev, "IRQ status 0 %08x %08x %08x\n",
|
2011-04-25 21:32:25 +00:00
|
|
|
i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS),
|
|
|
|
i2c_readl(i2c_dev, I2C_STATUS),
|
|
|
|
i2c_readl(i2c_dev, I2C_CNFG));
|
|
|
|
i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT;
|
|
|
|
goto err;
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:01 +00:00
|
|
|
if (status & status_err) {
|
2016-08-31 13:28:44 +00:00
|
|
|
tegra_i2c_disable_packet_mode(i2c_dev);
|
2011-02-21 01:14:21 +00:00
|
|
|
if (status & I2C_INT_NO_ACK)
|
|
|
|
i2c_dev->msg_err |= I2C_ERR_NO_ACK;
|
|
|
|
if (status & I2C_INT_ARBITRATION_LOST)
|
|
|
|
i2c_dev->msg_err |= I2C_ERR_ARBITRATION_LOST;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:06:43 +00:00
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* I2C transfer is terminated during the bus clear, so skip
|
2019-02-12 19:06:43 +00:00
|
|
|
* processing the other interrupts.
|
|
|
|
*/
|
|
|
|
if (i2c_dev->hw->supports_bus_clear && (status & I2C_INT_BUS_CLR_DONE))
|
|
|
|
goto err;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (!i2c_dev->dma_mode) {
|
2019-02-12 19:06:46 +00:00
|
|
|
if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) {
|
2019-06-18 11:09:42 +00:00
|
|
|
if (tegra_i2c_empty_rx_fifo(i2c_dev)) {
|
|
|
|
/*
|
|
|
|
* Overflow error condition: message fully sent,
|
|
|
|
* with no XFER_COMPLETE interrupt but hardware
|
|
|
|
* asks to transfer more.
|
|
|
|
*/
|
|
|
|
i2c_dev->msg_err |= I2C_ERR_RX_BUFFER_OVERFLOW;
|
|
|
|
goto err;
|
|
|
|
}
|
2019-02-12 19:06:46 +00:00
|
|
|
}
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) {
|
|
|
|
if (i2c_dev->msg_buf_remaining)
|
|
|
|
tegra_i2c_fill_tx_fifo(i2c_dev);
|
|
|
|
else
|
|
|
|
tegra_i2c_mask_irq(i2c_dev,
|
|
|
|
I2C_INT_TX_FIFO_DATA_REQ);
|
|
|
|
}
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 06:46:19 +00:00
|
|
|
i2c_writel(i2c_dev, status, I2C_INT_STATUS);
|
2023-05-06 21:19:01 +00:00
|
|
|
if (IS_DVC(i2c_dev))
|
2012-05-07 06:46:19 +00:00
|
|
|
dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
/*
|
|
|
|
* During message read XFER_COMPLETE interrupt is triggered prior to
|
|
|
|
* DMA completion and during message write XFER_COMPLETE interrupt is
|
|
|
|
* triggered after DMA completion.
|
2020-09-29 22:19:13 +00:00
|
|
|
*
|
|
|
|
* PACKETS_XFER_COMPLETE indicates completion of all bytes of transfer,
|
2019-02-12 19:06:46 +00:00
|
|
|
* so forcing msg_buf_remaining to 0 in DMA mode.
|
|
|
|
*/
|
2011-08-30 17:46:10 +00:00
|
|
|
if (status & I2C_INT_PACKET_XFER_COMPLETE) {
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode)
|
2019-02-12 19:06:46 +00:00
|
|
|
i2c_dev->msg_buf_remaining = 0;
|
2019-06-18 11:09:42 +00:00
|
|
|
/*
|
|
|
|
* Underflow error condition: XFER_COMPLETE before message
|
|
|
|
* fully sent.
|
|
|
|
*/
|
|
|
|
if (WARN_ON_ONCE(i2c_dev->msg_buf_remaining)) {
|
|
|
|
i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT;
|
|
|
|
goto err;
|
|
|
|
}
|
2011-02-21 01:14:21 +00:00
|
|
|
complete(&i2c_dev->msg_complete);
|
2011-08-30 17:46:10 +00:00
|
|
|
}
|
2016-08-31 13:28:44 +00:00
|
|
|
goto done;
|
2011-02-21 01:14:21 +00:00
|
|
|
err:
|
2020-09-29 22:19:13 +00:00
|
|
|
/* mask all interrupts on error */
|
2020-09-29 22:19:14 +00:00
|
|
|
tegra_i2c_mask_irq(i2c_dev,
|
|
|
|
I2C_INT_NO_ACK |
|
|
|
|
I2C_INT_ARBITRATION_LOST |
|
|
|
|
I2C_INT_PACKET_XFER_COMPLETE |
|
|
|
|
I2C_INT_TX_FIFO_DATA_REQ |
|
|
|
|
I2C_INT_RX_FIFO_DATA_REQ);
|
|
|
|
|
2019-02-12 19:06:43 +00:00
|
|
|
if (i2c_dev->hw->supports_bus_clear)
|
|
|
|
tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_writel(i2c_dev, status, I2C_INT_STATUS);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2023-05-06 21:19:01 +00:00
|
|
|
if (IS_DVC(i2c_dev))
|
2011-04-25 21:32:25 +00:00
|
|
|
dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
|
2012-05-07 06:46:19 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode) {
|
2023-04-27 12:39:15 +00:00
|
|
|
dmaengine_terminate_async(i2c_dev->dma_chan);
|
2019-02-12 19:06:46 +00:00
|
|
|
complete(&i2c_dev->dma_complete);
|
|
|
|
}
|
|
|
|
|
2012-05-07 06:46:19 +00:00
|
|
|
complete(&i2c_dev->msg_complete);
|
2016-08-31 13:28:44 +00:00
|
|
|
done:
|
2011-02-21 01:14:21 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
static void tegra_i2c_config_fifo_trig(struct tegra_i2c_dev *i2c_dev,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
struct dma_slave_config slv_config = {0};
|
2020-09-29 22:19:10 +00:00
|
|
|
u32 val, reg, dma_burst, reg_offset;
|
2020-09-29 22:19:11 +00:00
|
|
|
int err;
|
2019-02-12 19:06:46 +00:00
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo)
|
|
|
|
reg = I2C_MST_FIFO_CONTROL;
|
|
|
|
else
|
|
|
|
reg = I2C_FIFO_CONTROL;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode) {
|
2019-02-12 19:06:46 +00:00
|
|
|
if (len & 0xF)
|
|
|
|
dma_burst = 1;
|
|
|
|
else if (len & 0x10)
|
|
|
|
dma_burst = 4;
|
|
|
|
else
|
|
|
|
dma_burst = 8;
|
|
|
|
|
|
|
|
if (i2c_dev->msg_read) {
|
|
|
|
reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_RX_FIFO);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
slv_config.src_addr = i2c_dev->base_phys + reg_offset;
|
|
|
|
slv_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
|
|
|
|
slv_config.src_maxburst = dma_burst;
|
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo)
|
|
|
|
val = I2C_MST_FIFO_CONTROL_RX_TRIG(dma_burst);
|
|
|
|
else
|
|
|
|
val = I2C_FIFO_CONTROL_RX_TRIG(dma_burst);
|
|
|
|
} else {
|
|
|
|
reg_offset = tegra_i2c_reg_addr(i2c_dev, I2C_TX_FIFO);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
slv_config.dst_addr = i2c_dev->base_phys + reg_offset;
|
|
|
|
slv_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
|
|
|
|
slv_config.dst_maxburst = dma_burst;
|
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo)
|
|
|
|
val = I2C_MST_FIFO_CONTROL_TX_TRIG(dma_burst);
|
|
|
|
else
|
|
|
|
val = I2C_FIFO_CONTROL_TX_TRIG(dma_burst);
|
|
|
|
}
|
|
|
|
|
|
|
|
slv_config.device_fc = true;
|
2023-04-27 12:39:15 +00:00
|
|
|
err = dmaengine_slave_config(i2c_dev->dma_chan, &slv_config);
|
2020-09-29 22:19:11 +00:00
|
|
|
if (err) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_err(i2c_dev->dev, "DMA config failed: %d\n", err);
|
2019-02-15 15:31:26 +00:00
|
|
|
dev_err(i2c_dev->dev, "falling back to PIO\n");
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
tegra_i2c_release_dma(i2c_dev);
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->dma_mode = false;
|
2019-02-12 19:06:46 +00:00
|
|
|
} else {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2c_dev->hw->has_mst_fifo)
|
|
|
|
val = I2C_MST_FIFO_CONTROL_TX_TRIG(8) |
|
|
|
|
I2C_MST_FIFO_CONTROL_RX_TRIG(1);
|
|
|
|
else
|
|
|
|
val = I2C_FIFO_CONTROL_TX_TRIG(8) |
|
|
|
|
I2C_FIFO_CONTROL_RX_TRIG(1);
|
|
|
|
out:
|
|
|
|
i2c_writel(i2c_dev, val, reg);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:04 +00:00
|
|
|
static unsigned long tegra_i2c_poll_completion(struct tegra_i2c_dev *i2c_dev,
|
|
|
|
struct completion *complete,
|
|
|
|
unsigned int timeout_ms)
|
2020-01-14 01:34:38 +00:00
|
|
|
{
|
|
|
|
ktime_t ktime = ktime_get();
|
|
|
|
ktime_t ktimeout = ktime_add_ms(ktime, timeout_ms);
|
|
|
|
|
|
|
|
do {
|
|
|
|
u32 status = i2c_readl(i2c_dev, I2C_INT_STATUS);
|
|
|
|
|
2020-03-24 19:12:16 +00:00
|
|
|
if (status)
|
2020-01-14 01:34:38 +00:00
|
|
|
tegra_i2c_isr(i2c_dev->irq, i2c_dev);
|
|
|
|
|
2020-03-24 19:12:16 +00:00
|
|
|
if (completion_done(complete)) {
|
|
|
|
s64 delta = ktime_ms_delta(ktimeout, ktime);
|
2020-01-14 01:34:38 +00:00
|
|
|
|
2020-03-24 19:12:16 +00:00
|
|
|
return msecs_to_jiffies(delta) ?: 1;
|
2020-01-14 01:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ktime = ktime_get();
|
|
|
|
|
|
|
|
} while (ktime_before(ktime, ktimeout));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:04 +00:00
|
|
|
static unsigned long tegra_i2c_wait_completion(struct tegra_i2c_dev *i2c_dev,
|
|
|
|
struct completion *complete,
|
|
|
|
unsigned int timeout_ms)
|
2020-01-14 01:34:37 +00:00
|
|
|
{
|
|
|
|
unsigned long ret;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->atomic_mode) {
|
2020-09-29 22:19:04 +00:00
|
|
|
ret = tegra_i2c_poll_completion(i2c_dev, complete, timeout_ms);
|
2020-01-14 01:34:38 +00:00
|
|
|
} else {
|
|
|
|
enable_irq(i2c_dev->irq);
|
|
|
|
ret = wait_for_completion_timeout(complete,
|
|
|
|
msecs_to_jiffies(timeout_ms));
|
|
|
|
disable_irq(i2c_dev->irq);
|
2020-01-14 01:34:37 +00:00
|
|
|
|
2020-01-14 01:34:38 +00:00
|
|
|
/*
|
2020-03-24 19:12:16 +00:00
|
|
|
* Under some rare circumstances (like running KASAN +
|
|
|
|
* NFS root) CPU, which handles interrupt, may stuck in
|
|
|
|
* uninterruptible state for a significant time. In this
|
|
|
|
* case we will get timeout if I2C transfer is running on
|
|
|
|
* a sibling CPU, despite of IRQ being raised.
|
|
|
|
*
|
|
|
|
* In order to handle this rare condition, the IRQ status
|
|
|
|
* needs to be checked after timeout.
|
2020-01-14 01:34:38 +00:00
|
|
|
*/
|
2020-03-24 19:12:16 +00:00
|
|
|
if (ret == 0)
|
2020-09-29 22:19:04 +00:00
|
|
|
ret = tegra_i2c_poll_completion(i2c_dev, complete, 0);
|
2020-01-14 01:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-12 19:06:43 +00:00
|
|
|
static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap)
|
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
|
2020-09-29 22:19:11 +00:00
|
|
|
u32 val, time_left;
|
2019-02-12 19:06:43 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
reinit_completion(&i2c_dev->msg_complete);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
val = FIELD_PREP(I2C_BC_SCLK_THRESHOLD, 9) | I2C_BC_STOP_COND |
|
2020-04-01 22:21:28 +00:00
|
|
|
I2C_BC_TERMINATE;
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG);
|
2020-09-29 22:19:02 +00:00
|
|
|
|
|
|
|
err = tegra_i2c_wait_for_config_load(i2c_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2019-02-12 19:06:43 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
val |= I2C_BC_ENABLE;
|
|
|
|
i2c_writel(i2c_dev, val, I2C_BUS_CLEAR_CNFG);
|
2019-02-12 19:06:43 +00:00
|
|
|
tegra_i2c_unmask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE);
|
|
|
|
|
2020-09-29 22:19:04 +00:00
|
|
|
time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete, 50);
|
2020-09-29 22:18:47 +00:00
|
|
|
tegra_i2c_mask_irq(i2c_dev, I2C_INT_BUS_CLR_DONE);
|
|
|
|
|
2019-02-12 19:06:43 +00:00
|
|
|
if (time_left == 0) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_err(i2c_dev->dev, "failed to clear bus\n");
|
2019-02-12 19:06:43 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
val = i2c_readl(i2c_dev, I2C_BUS_CLEAR_STATUS);
|
|
|
|
if (!(val & I2C_BC_STATUS)) {
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_err(i2c_dev->dev, "un-recovered arbitration lost\n");
|
2019-02-12 19:06:43 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:06 +00:00
|
|
|
static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev,
|
|
|
|
struct i2c_msg *msg,
|
|
|
|
enum msg_end_type end_state)
|
|
|
|
{
|
|
|
|
u32 *dma_buf = i2c_dev->dma_buf;
|
|
|
|
u32 packet_header;
|
|
|
|
|
|
|
|
packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) |
|
|
|
|
FIELD_PREP(PACKET_HEADER0_PROTOCOL,
|
|
|
|
PACKET_HEADER0_PROTOCOL_I2C) |
|
|
|
|
FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) |
|
|
|
|
FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1);
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode && !i2c_dev->msg_read)
|
2020-09-29 22:19:06 +00:00
|
|
|
*dma_buf++ = packet_header;
|
|
|
|
else
|
|
|
|
i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
|
|
|
|
|
2023-04-27 12:39:14 +00:00
|
|
|
packet_header = i2c_dev->msg_len - 1;
|
2020-09-29 22:19:06 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode && !i2c_dev->msg_read)
|
2020-09-29 22:19:06 +00:00
|
|
|
*dma_buf++ = packet_header;
|
|
|
|
else
|
|
|
|
i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
|
|
|
|
|
|
|
|
packet_header = I2C_HEADER_IE_ENABLE;
|
|
|
|
|
|
|
|
if (end_state == MSG_END_CONTINUE)
|
|
|
|
packet_header |= I2C_HEADER_CONTINUE_XFER;
|
|
|
|
else if (end_state == MSG_END_REPEAT_START)
|
|
|
|
packet_header |= I2C_HEADER_REPEAT_START;
|
|
|
|
|
|
|
|
if (msg->flags & I2C_M_TEN) {
|
|
|
|
packet_header |= msg->addr;
|
|
|
|
packet_header |= I2C_HEADER_10BIT_ADDR;
|
|
|
|
} else {
|
|
|
|
packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg->flags & I2C_M_IGNORE_NAK)
|
|
|
|
packet_header |= I2C_HEADER_CONT_ON_NAK;
|
|
|
|
|
|
|
|
if (msg->flags & I2C_M_RD)
|
|
|
|
packet_header |= I2C_HEADER_READ;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode && !i2c_dev->msg_read)
|
2020-09-29 22:19:06 +00:00
|
|
|
*dma_buf++ = packet_header;
|
|
|
|
else
|
|
|
|
i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:05 +00:00
|
|
|
static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev,
|
|
|
|
struct i2c_msg *msg)
|
|
|
|
{
|
|
|
|
if (i2c_dev->msg_err == I2C_ERR_NONE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tegra_i2c_init(i2c_dev);
|
|
|
|
|
|
|
|
/* start recovery upon arbitration loss in single master mode */
|
|
|
|
if (i2c_dev->msg_err == I2C_ERR_ARBITRATION_LOST) {
|
2020-09-29 22:19:11 +00:00
|
|
|
if (!i2c_dev->multimaster_mode)
|
2020-09-29 22:19:05 +00:00
|
|
|
return i2c_recover_bus(&i2c_dev->adapter);
|
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2c_dev->msg_err == I2C_ERR_NO_ACK) {
|
|
|
|
if (msg->flags & I2C_M_IGNORE_NAK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
|
2019-06-11 10:51:10 +00:00
|
|
|
struct i2c_msg *msg,
|
|
|
|
enum msg_end_type end_state)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
2020-09-29 22:19:10 +00:00
|
|
|
unsigned long time_left, xfer_time = 100;
|
2019-02-12 19:06:46 +00:00
|
|
|
size_t xfer_size;
|
2020-09-29 22:19:10 +00:00
|
|
|
u32 int_mask;
|
|
|
|
int err;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:18:46 +00:00
|
|
|
err = tegra_i2c_flush_fifos(i2c_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
|
|
|
i2c_dev->msg_buf = msg->buf;
|
2023-04-27 12:39:14 +00:00
|
|
|
i2c_dev->msg_len = msg->len;
|
2022-02-10 15:36:03 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_dev->msg_err = I2C_ERR_NONE;
|
2020-09-29 22:18:59 +00:00
|
|
|
i2c_dev->msg_read = !!(msg->flags & I2C_M_RD);
|
2013-11-14 22:32:02 +00:00
|
|
|
reinit_completion(&i2c_dev->msg_complete);
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2023-04-27 12:39:14 +00:00
|
|
|
/*
|
|
|
|
* For SMBUS block read command, read only 1 byte in the first transfer.
|
|
|
|
* Adjust that 1 byte for the next transfer in the msg buffer and msg
|
|
|
|
* length.
|
|
|
|
*/
|
|
|
|
if (msg->flags & I2C_M_RECV_LEN) {
|
|
|
|
if (end_state == MSG_END_CONTINUE) {
|
|
|
|
i2c_dev->msg_len = 1;
|
|
|
|
} else {
|
|
|
|
i2c_dev->msg_buf += 1;
|
|
|
|
i2c_dev->msg_len -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i2c_dev->msg_buf_remaining = i2c_dev->msg_len;
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
if (i2c_dev->msg_read)
|
2023-04-27 12:39:14 +00:00
|
|
|
xfer_size = i2c_dev->msg_len;
|
2019-02-12 19:06:46 +00:00
|
|
|
else
|
2023-04-27 12:39:14 +00:00
|
|
|
xfer_size = i2c_dev->msg_len + I2C_PACKET_HEADER_SIZE;
|
2019-02-12 19:06:46 +00:00
|
|
|
|
|
|
|
xfer_size = ALIGN(xfer_size, BYTES_PER_FIFO_WORD);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
|
|
|
i2c_dev->dma_mode = xfer_size > I2C_PIO_MODE_PREFERRED_LEN &&
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->dma_buf && !i2c_dev->atomic_mode;
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
tegra_i2c_config_fifo_trig(i2c_dev, xfer_size);
|
2020-09-29 22:19:03 +00:00
|
|
|
|
2019-02-12 19:06:47 +00:00
|
|
|
/*
|
|
|
|
* Transfer time in mSec = Total bits / transfer rate
|
|
|
|
* Total bits = 9 bits per byte (including ACK bit) + Start & stop bits
|
|
|
|
*/
|
|
|
|
xfer_time += DIV_ROUND_CLOSEST(((xfer_size * 9) + 2) * MSEC_PER_SEC,
|
2021-12-10 12:15:57 +00:00
|
|
|
i2c_dev->timings.bus_freq_hz);
|
2016-08-31 13:28:44 +00:00
|
|
|
|
|
|
|
int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST;
|
|
|
|
tegra_i2c_unmask_irq(i2c_dev, int_mask);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode) {
|
2019-02-12 19:06:46 +00:00
|
|
|
if (i2c_dev->msg_read) {
|
2022-10-20 14:39:33 +00:00
|
|
|
dma_sync_single_for_device(i2c_dev->dma_dev,
|
2019-02-12 19:06:46 +00:00
|
|
|
i2c_dev->dma_phys,
|
2020-09-29 22:19:14 +00:00
|
|
|
xfer_size, DMA_FROM_DEVICE);
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
err = tegra_i2c_dma_submit(i2c_dev, xfer_size);
|
2020-09-29 22:19:12 +00:00
|
|
|
if (err)
|
2020-01-14 01:34:37 +00:00
|
|
|
return err;
|
2019-02-12 19:06:46 +00:00
|
|
|
} else {
|
2022-10-20 14:39:33 +00:00
|
|
|
dma_sync_single_for_cpu(i2c_dev->dma_dev,
|
2019-02-12 19:06:46 +00:00
|
|
|
i2c_dev->dma_phys,
|
2020-09-29 22:19:14 +00:00
|
|
|
xfer_size, DMA_TO_DEVICE);
|
2019-02-12 19:06:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 13:28:44 +00:00
|
|
|
|
2020-09-29 22:19:06 +00:00
|
|
|
tegra_i2c_push_packet_header(i2c_dev, msg, end_state);
|
2019-02-12 19:06:46 +00:00
|
|
|
|
|
|
|
if (!i2c_dev->msg_read) {
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode) {
|
2020-09-29 22:19:06 +00:00
|
|
|
memcpy(i2c_dev->dma_buf + I2C_PACKET_HEADER_SIZE,
|
2023-04-27 12:39:14 +00:00
|
|
|
msg->buf, i2c_dev->msg_len);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2022-10-20 14:39:33 +00:00
|
|
|
dma_sync_single_for_device(i2c_dev->dma_dev,
|
2019-02-12 19:06:46 +00:00
|
|
|
i2c_dev->dma_phys,
|
2020-09-29 22:19:14 +00:00
|
|
|
xfer_size, DMA_TO_DEVICE);
|
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
err = tegra_i2c_dma_submit(i2c_dev, xfer_size);
|
2020-09-29 22:19:12 +00:00
|
|
|
if (err)
|
2020-01-14 01:34:37 +00:00
|
|
|
return err;
|
2019-02-12 19:06:46 +00:00
|
|
|
} else {
|
|
|
|
tegra_i2c_fill_tx_fifo(i2c_dev);
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2013-01-05 12:04:46 +00:00
|
|
|
if (i2c_dev->hw->has_per_pkt_xfer_complete_irq)
|
|
|
|
int_mask |= I2C_INT_PACKET_XFER_COMPLETE;
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (!i2c_dev->dma_mode) {
|
2019-02-12 19:06:46 +00:00
|
|
|
if (msg->flags & I2C_M_RD)
|
|
|
|
int_mask |= I2C_INT_RX_FIFO_DATA_REQ;
|
|
|
|
else if (i2c_dev->msg_buf_remaining)
|
|
|
|
int_mask |= I2C_INT_TX_FIFO_DATA_REQ;
|
|
|
|
}
|
2016-08-31 13:28:44 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
tegra_i2c_unmask_irq(i2c_dev, int_mask);
|
2020-09-29 22:19:12 +00:00
|
|
|
dev_dbg(i2c_dev->dev, "unmasked IRQ: %02x\n",
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_readl(i2c_dev, I2C_INT_MASK));
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->dma_mode) {
|
2020-09-29 22:19:04 +00:00
|
|
|
time_left = tegra_i2c_wait_completion(i2c_dev,
|
|
|
|
&i2c_dev->dma_complete,
|
|
|
|
xfer_time);
|
2019-02-12 19:06:46 +00:00
|
|
|
|
2020-03-24 19:12:17 +00:00
|
|
|
/*
|
|
|
|
* Synchronize DMA first, since dmaengine_terminate_sync()
|
|
|
|
* performs synchronization after the transfer's termination
|
|
|
|
* and we want to get a completion if transfer succeeded.
|
|
|
|
*/
|
2023-04-27 12:39:15 +00:00
|
|
|
dmaengine_synchronize(i2c_dev->dma_chan);
|
|
|
|
dmaengine_terminate_sync(i2c_dev->dma_chan);
|
2020-01-14 01:34:41 +00:00
|
|
|
|
2020-01-14 01:34:42 +00:00
|
|
|
if (!time_left && !completion_done(&i2c_dev->dma_complete)) {
|
2020-09-29 22:18:48 +00:00
|
|
|
tegra_i2c_init(i2c_dev);
|
2019-02-12 19:06:46 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i2c_dev->msg_read && i2c_dev->msg_err == I2C_ERR_NONE) {
|
2022-10-20 14:39:33 +00:00
|
|
|
dma_sync_single_for_cpu(i2c_dev->dma_dev,
|
2019-02-12 19:06:46 +00:00
|
|
|
i2c_dev->dma_phys,
|
2020-09-29 22:19:14 +00:00
|
|
|
xfer_size, DMA_FROM_DEVICE);
|
|
|
|
|
2023-04-27 12:39:14 +00:00
|
|
|
memcpy(i2c_dev->msg_buf, i2c_dev->dma_buf, i2c_dev->msg_len);
|
2019-02-12 19:06:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:04 +00:00
|
|
|
time_left = tegra_i2c_wait_completion(i2c_dev, &i2c_dev->msg_complete,
|
|
|
|
xfer_time);
|
2020-01-14 01:34:37 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
tegra_i2c_mask_irq(i2c_dev, int_mask);
|
|
|
|
|
2015-03-01 14:17:41 +00:00
|
|
|
if (time_left == 0) {
|
2020-09-29 22:18:48 +00:00
|
|
|
tegra_i2c_init(i2c_dev);
|
2011-02-21 01:14:21 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2015-03-01 14:17:41 +00:00
|
|
|
dev_dbg(i2c_dev->dev, "transfer complete: %lu %d %d\n",
|
|
|
|
time_left, completion_done(&i2c_dev->msg_complete),
|
|
|
|
i2c_dev->msg_err);
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->dma_mode = false;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:19:05 +00:00
|
|
|
err = tegra_i2c_error_recover(i2c_dev, msg);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:19:05 +00:00
|
|
|
return 0;
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
|
2019-06-11 10:51:10 +00:00
|
|
|
int num)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
|
2020-09-29 22:19:10 +00:00
|
|
|
int i, ret;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2016-08-26 13:09:04 +00:00
|
|
|
ret = pm_runtime_get_sync(i2c_dev->dev);
|
2013-03-15 05:34:08 +00:00
|
|
|
if (ret < 0) {
|
2016-08-26 13:09:04 +00:00
|
|
|
dev_err(i2c_dev->dev, "runtime resume failed %d\n", ret);
|
2020-09-29 22:18:45 +00:00
|
|
|
pm_runtime_put_noidle(i2c_dev->dev);
|
2013-03-15 05:34:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2012-06-13 10:12:38 +00:00
|
|
|
enum msg_end_type end_type = MSG_END_STOP;
|
2016-08-26 13:08:59 +00:00
|
|
|
|
2012-06-13 10:12:38 +00:00
|
|
|
if (i < (num - 1)) {
|
2020-09-29 22:19:13 +00:00
|
|
|
/* check whether follow up message is coming */
|
2012-06-13 10:12:38 +00:00
|
|
|
if (msgs[i + 1].flags & I2C_M_NOSTART)
|
|
|
|
end_type = MSG_END_CONTINUE;
|
|
|
|
else
|
|
|
|
end_type = MSG_END_REPEAT_START;
|
|
|
|
}
|
2022-02-10 15:36:03 +00:00
|
|
|
/* If M_RECV_LEN use ContinueXfer to read the first byte */
|
|
|
|
if (msgs[i].flags & I2C_M_RECV_LEN) {
|
|
|
|
ret = tegra_i2c_xfer_msg(i2c_dev, &msgs[i], MSG_END_CONTINUE);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2023-04-27 12:39:14 +00:00
|
|
|
/* Set the msg length from first byte */
|
|
|
|
msgs[i].len += msgs[i].buf[0];
|
2022-02-10 15:36:03 +00:00
|
|
|
dev_dbg(i2c_dev->dev, "reading %d bytes\n", msgs[i].len);
|
|
|
|
}
|
2012-06-13 10:12:38 +00:00
|
|
|
ret = tegra_i2c_xfer_msg(i2c_dev, &msgs[i], end_type);
|
2011-02-21 01:14:21 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2016-08-26 13:09:04 +00:00
|
|
|
|
|
|
|
pm_runtime_put(i2c_dev->dev);
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
return ret ?: i;
|
|
|
|
}
|
|
|
|
|
2020-01-14 01:34:38 +00:00
|
|
|
static int tegra_i2c_xfer_atomic(struct i2c_adapter *adap,
|
|
|
|
struct i2c_msg msgs[], int num)
|
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
|
|
|
|
int ret;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->atomic_mode = true;
|
2020-01-14 01:34:38 +00:00
|
|
|
ret = tegra_i2c_xfer(adap, msgs, num);
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->atomic_mode = false;
|
2020-01-14 01:34:38 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
static u32 tegra_i2c_func(struct i2c_adapter *adap)
|
|
|
|
{
|
2012-08-18 19:17:46 +00:00
|
|
|
struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
|
2015-06-16 17:47:21 +00:00
|
|
|
u32 ret = I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK) |
|
2022-02-10 15:36:03 +00:00
|
|
|
I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
|
2012-08-18 19:17:46 +00:00
|
|
|
|
|
|
|
if (i2c_dev->hw->has_continue_xfer_support)
|
2022-02-10 15:36:03 +00:00
|
|
|
ret |= I2C_FUNC_NOSTART | I2C_FUNC_SMBUS_READ_BLOCK_DATA;
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2012-08-18 19:17:46 +00:00
|
|
|
return ret;
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_algorithm tegra_i2c_algo = {
|
2020-01-14 01:34:38 +00:00
|
|
|
.master_xfer = tegra_i2c_xfer,
|
|
|
|
.master_xfer_atomic = tegra_i2c_xfer_atomic,
|
|
|
|
.functionality = tegra_i2c_func,
|
2011-02-21 01:14:21 +00:00
|
|
|
};
|
|
|
|
|
2015-06-16 17:57:29 +00:00
|
|
|
/* payload size is only 12 bit */
|
2017-08-21 12:12:04 +00:00
|
|
|
static const struct i2c_adapter_quirks tegra_i2c_quirks = {
|
2018-07-23 20:26:12 +00:00
|
|
|
.flags = I2C_AQ_NO_ZERO_LEN,
|
2019-02-12 19:06:45 +00:00
|
|
|
.max_read_len = SZ_4K,
|
|
|
|
.max_write_len = SZ_4K - I2C_PACKET_HEADER_SIZE,
|
2015-06-16 17:57:29 +00:00
|
|
|
};
|
|
|
|
|
2019-01-08 21:59:10 +00:00
|
|
|
static const struct i2c_adapter_quirks tegra194_i2c_quirks = {
|
|
|
|
.flags = I2C_AQ_NO_ZERO_LEN,
|
2019-02-12 19:06:45 +00:00
|
|
|
.max_write_len = SZ_64K - I2C_PACKET_HEADER_SIZE,
|
2019-01-08 21:59:10 +00:00
|
|
|
};
|
|
|
|
|
2019-02-12 19:06:43 +00:00
|
|
|
static struct i2c_bus_recovery_info tegra_i2c_recovery_info = {
|
|
|
|
.recover_bus = tegra_i2c_issue_bus_clear,
|
|
|
|
};
|
|
|
|
|
2012-08-18 19:17:46 +00:00
|
|
|
static const struct tegra_i2c_hw_feature tegra20_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = false,
|
2013-01-05 12:04:46 +00:00
|
|
|
.has_per_pkt_xfer_complete_irq = false,
|
|
|
|
.clk_divisor_hs_mode = 3,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0,
|
|
|
|
.clk_divisor_fast_mode = 0,
|
2015-06-30 10:54:27 +00:00
|
|
|
.clk_divisor_fast_plus_mode = 0,
|
2015-06-30 10:54:26 +00:00
|
|
|
.has_config_load_reg = false,
|
2016-03-14 13:22:18 +00:00
|
|
|
.has_multi_master_mode = false,
|
|
|
|
.has_slcg_override_reg = false,
|
2018-06-19 10:49:42 +00:00
|
|
|
.has_mst_fifo = false,
|
2019-01-08 21:59:10 +00:00
|
|
|
.quirks = &tegra_i2c_quirks,
|
2019-02-12 19:06:43 +00:00
|
|
|
.supports_bus_clear = false,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_apb_dma = true,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x4,
|
|
|
|
.thigh_std_mode = 0x2,
|
|
|
|
.tlow_fast_fastplus_mode = 0x4,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0x0,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0x0,
|
|
|
|
.setup_hold_time_hs_mode = 0x0,
|
|
|
|
.has_interface_timing_reg = false,
|
2012-08-18 19:17:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tegra_i2c_hw_feature tegra30_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = true,
|
2013-01-05 12:04:46 +00:00
|
|
|
.has_per_pkt_xfer_complete_irq = false,
|
|
|
|
.clk_divisor_hs_mode = 3,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0,
|
|
|
|
.clk_divisor_fast_mode = 0,
|
2015-06-30 10:54:27 +00:00
|
|
|
.clk_divisor_fast_plus_mode = 0,
|
2015-06-30 10:54:26 +00:00
|
|
|
.has_config_load_reg = false,
|
2016-03-14 13:22:18 +00:00
|
|
|
.has_multi_master_mode = false,
|
|
|
|
.has_slcg_override_reg = false,
|
2018-06-19 10:49:42 +00:00
|
|
|
.has_mst_fifo = false,
|
2019-01-08 21:59:10 +00:00
|
|
|
.quirks = &tegra_i2c_quirks,
|
2019-02-12 19:06:43 +00:00
|
|
|
.supports_bus_clear = false,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_apb_dma = true,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x4,
|
|
|
|
.thigh_std_mode = 0x2,
|
|
|
|
.tlow_fast_fastplus_mode = 0x4,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0x0,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0x0,
|
|
|
|
.setup_hold_time_hs_mode = 0x0,
|
|
|
|
.has_interface_timing_reg = false,
|
2013-01-05 12:04:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tegra_i2c_hw_feature tegra114_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = true,
|
|
|
|
.has_per_pkt_xfer_complete_irq = true,
|
|
|
|
.clk_divisor_hs_mode = 1,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0x19,
|
|
|
|
.clk_divisor_fast_mode = 0x19,
|
2015-06-30 10:54:27 +00:00
|
|
|
.clk_divisor_fast_plus_mode = 0x10,
|
2015-06-30 10:54:26 +00:00
|
|
|
.has_config_load_reg = false,
|
2016-03-14 13:22:18 +00:00
|
|
|
.has_multi_master_mode = false,
|
|
|
|
.has_slcg_override_reg = false,
|
2018-06-19 10:49:42 +00:00
|
|
|
.has_mst_fifo = false,
|
2019-01-08 21:59:10 +00:00
|
|
|
.quirks = &tegra_i2c_quirks,
|
2019-02-12 19:06:43 +00:00
|
|
|
.supports_bus_clear = true,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_apb_dma = true,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x4,
|
|
|
|
.thigh_std_mode = 0x2,
|
|
|
|
.tlow_fast_fastplus_mode = 0x4,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0x0,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0x0,
|
|
|
|
.setup_hold_time_hs_mode = 0x0,
|
|
|
|
.has_interface_timing_reg = false,
|
2015-06-30 10:54:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tegra_i2c_hw_feature tegra124_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = true,
|
|
|
|
.has_per_pkt_xfer_complete_irq = true,
|
|
|
|
.clk_divisor_hs_mode = 1,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0x19,
|
|
|
|
.clk_divisor_fast_mode = 0x19,
|
2015-06-30 10:54:27 +00:00
|
|
|
.clk_divisor_fast_plus_mode = 0x10,
|
2015-06-30 10:54:26 +00:00
|
|
|
.has_config_load_reg = true,
|
2016-03-14 13:22:18 +00:00
|
|
|
.has_multi_master_mode = false,
|
|
|
|
.has_slcg_override_reg = true,
|
2018-06-19 10:49:42 +00:00
|
|
|
.has_mst_fifo = false,
|
2019-01-08 21:59:10 +00:00
|
|
|
.quirks = &tegra_i2c_quirks,
|
2019-02-12 19:06:43 +00:00
|
|
|
.supports_bus_clear = true,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_apb_dma = true,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x4,
|
|
|
|
.thigh_std_mode = 0x2,
|
|
|
|
.tlow_fast_fastplus_mode = 0x4,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0x0,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0x0,
|
|
|
|
.setup_hold_time_hs_mode = 0x0,
|
|
|
|
.has_interface_timing_reg = true,
|
2016-03-14 13:22:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tegra_i2c_hw_feature tegra210_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = true,
|
|
|
|
.has_per_pkt_xfer_complete_irq = true,
|
|
|
|
.clk_divisor_hs_mode = 1,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0x19,
|
|
|
|
.clk_divisor_fast_mode = 0x19,
|
2016-03-14 13:22:18 +00:00
|
|
|
.clk_divisor_fast_plus_mode = 0x10,
|
|
|
|
.has_config_load_reg = true,
|
2019-02-19 17:28:52 +00:00
|
|
|
.has_multi_master_mode = false,
|
2016-03-14 13:22:18 +00:00
|
|
|
.has_slcg_override_reg = true,
|
2018-06-19 10:49:42 +00:00
|
|
|
.has_mst_fifo = false,
|
2019-01-08 21:59:10 +00:00
|
|
|
.quirks = &tegra_i2c_quirks,
|
2019-02-12 19:06:43 +00:00
|
|
|
.supports_bus_clear = true,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_apb_dma = true,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x4,
|
|
|
|
.thigh_std_mode = 0x2,
|
|
|
|
.tlow_fast_fastplus_mode = 0x4,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0,
|
|
|
|
.setup_hold_time_hs_mode = 0,
|
|
|
|
.has_interface_timing_reg = true,
|
2019-02-12 19:06:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tegra_i2c_hw_feature tegra186_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = true,
|
|
|
|
.has_per_pkt_xfer_complete_irq = true,
|
|
|
|
.clk_divisor_hs_mode = 1,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0x16,
|
|
|
|
.clk_divisor_fast_mode = 0x19,
|
2019-02-12 19:06:46 +00:00
|
|
|
.clk_divisor_fast_plus_mode = 0x10,
|
|
|
|
.has_config_load_reg = true,
|
2019-02-19 17:28:52 +00:00
|
|
|
.has_multi_master_mode = false,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_slcg_override_reg = true,
|
2019-02-19 17:28:51 +00:00
|
|
|
.has_mst_fifo = false,
|
2019-02-12 19:06:46 +00:00
|
|
|
.quirks = &tegra_i2c_quirks,
|
|
|
|
.supports_bus_clear = true,
|
|
|
|
.has_apb_dma = false,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x4,
|
|
|
|
.thigh_std_mode = 0x3,
|
|
|
|
.tlow_fast_fastplus_mode = 0x4,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0,
|
|
|
|
.setup_hold_time_hs_mode = 0,
|
|
|
|
.has_interface_timing_reg = true,
|
2018-06-19 10:49:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tegra_i2c_hw_feature tegra194_i2c_hw = {
|
|
|
|
.has_continue_xfer_support = true,
|
|
|
|
.has_per_pkt_xfer_complete_irq = true,
|
|
|
|
.clk_divisor_hs_mode = 1,
|
2019-02-12 19:06:48 +00:00
|
|
|
.clk_divisor_std_mode = 0x4f,
|
|
|
|
.clk_divisor_fast_mode = 0x3c,
|
|
|
|
.clk_divisor_fast_plus_mode = 0x16,
|
2018-06-19 10:49:42 +00:00
|
|
|
.has_config_load_reg = true,
|
|
|
|
.has_multi_master_mode = true,
|
|
|
|
.has_slcg_override_reg = true,
|
|
|
|
.has_mst_fifo = true,
|
2019-01-08 21:59:10 +00:00
|
|
|
.quirks = &tegra194_i2c_quirks,
|
2019-02-12 19:06:43 +00:00
|
|
|
.supports_bus_clear = true,
|
2019-02-12 19:06:46 +00:00
|
|
|
.has_apb_dma = false,
|
2019-02-12 19:06:48 +00:00
|
|
|
.tlow_std_mode = 0x8,
|
|
|
|
.thigh_std_mode = 0x7,
|
|
|
|
.tlow_fast_fastplus_mode = 0x2,
|
|
|
|
.thigh_fast_fastplus_mode = 0x2,
|
|
|
|
.setup_hold_time_std_mode = 0x08080808,
|
|
|
|
.setup_hold_time_fast_fast_plus_mode = 0x02020202,
|
|
|
|
.setup_hold_time_hs_mode = 0x090909,
|
|
|
|
.has_interface_timing_reg = true,
|
2012-08-18 19:17:46 +00:00
|
|
|
};
|
|
|
|
|
2012-11-27 20:59:38 +00:00
|
|
|
static const struct of_device_id tegra_i2c_of_match[] = {
|
2018-06-19 10:49:42 +00:00
|
|
|
{ .compatible = "nvidia,tegra194-i2c", .data = &tegra194_i2c_hw, },
|
2019-02-12 19:06:46 +00:00
|
|
|
{ .compatible = "nvidia,tegra186-i2c", .data = &tegra186_i2c_hw, },
|
2023-05-06 21:19:02 +00:00
|
|
|
#if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
|
2019-06-07 13:56:23 +00:00
|
|
|
{ .compatible = "nvidia,tegra210-i2c-vi", .data = &tegra210_i2c_hw, },
|
2023-05-06 21:19:02 +00:00
|
|
|
#endif
|
2016-03-14 13:22:18 +00:00
|
|
|
{ .compatible = "nvidia,tegra210-i2c", .data = &tegra210_i2c_hw, },
|
2015-06-30 10:54:26 +00:00
|
|
|
{ .compatible = "nvidia,tegra124-i2c", .data = &tegra124_i2c_hw, },
|
2013-01-05 12:04:46 +00:00
|
|
|
{ .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, },
|
2012-08-18 19:17:46 +00:00
|
|
|
{ .compatible = "nvidia,tegra30-i2c", .data = &tegra30_i2c_hw, },
|
|
|
|
{ .compatible = "nvidia,tegra20-i2c", .data = &tegra20_i2c_hw, },
|
2023-05-06 21:19:01 +00:00
|
|
|
#if IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC)
|
2012-08-18 19:17:46 +00:00
|
|
|
{ .compatible = "nvidia,tegra20-i2c-dvc", .data = &tegra20_i2c_hw, },
|
2023-05-06 21:19:01 +00:00
|
|
|
#endif
|
2012-08-18 19:17:46 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
|
|
|
|
|
2020-09-29 22:18:58 +00:00
|
|
|
static void tegra_i2c_parse_dt(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
struct device_node *np = i2c_dev->dev->of_node;
|
|
|
|
bool multi_mode;
|
|
|
|
|
2021-12-10 12:15:57 +00:00
|
|
|
i2c_parse_fw_timings(i2c_dev->dev, &i2c_dev->timings, true);
|
2020-09-29 22:18:58 +00:00
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
multi_mode = device_property_read_bool(i2c_dev->dev, "multi-master");
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->multimaster_mode = multi_mode;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
2023-05-06 21:19:01 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) &&
|
|
|
|
of_device_is_compatible(np, "nvidia,tegra20-i2c-dvc"))
|
2020-09-29 22:18:58 +00:00
|
|
|
i2c_dev->is_dvc = true;
|
|
|
|
|
2023-05-06 21:19:02 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC) &&
|
|
|
|
of_device_is_compatible(np, "nvidia,tegra210-i2c-vi"))
|
2020-09-29 22:18:58 +00:00
|
|
|
i2c_dev->is_vi = true;
|
|
|
|
}
|
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
static int tegra_i2c_init_reset(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
if (ACPI_HANDLE(i2c_dev->dev))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i2c_dev->rst = devm_reset_control_get_exclusive(i2c_dev->dev, "i2c");
|
|
|
|
if (IS_ERR(i2c_dev->rst))
|
|
|
|
return dev_err_probe(i2c_dev->dev, PTR_ERR(i2c_dev->rst),
|
|
|
|
"failed to get reset control\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:18:55 +00:00
|
|
|
static int tegra_i2c_init_clocks(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
if (ACPI_HANDLE(i2c_dev->dev))
|
|
|
|
return 0;
|
|
|
|
|
2020-09-29 22:18:55 +00:00
|
|
|
i2c_dev->clocks[i2c_dev->nclocks++].id = "div-clk";
|
|
|
|
|
|
|
|
if (i2c_dev->hw == &tegra20_i2c_hw || i2c_dev->hw == &tegra30_i2c_hw)
|
|
|
|
i2c_dev->clocks[i2c_dev->nclocks++].id = "fast-clk";
|
|
|
|
|
2023-05-06 21:19:02 +00:00
|
|
|
if (IS_VI(i2c_dev))
|
2020-09-29 22:18:55 +00:00
|
|
|
i2c_dev->clocks[i2c_dev->nclocks++].id = "slow";
|
|
|
|
|
|
|
|
err = devm_clk_bulk_get(i2c_dev->dev, i2c_dev->nclocks,
|
|
|
|
i2c_dev->clocks);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = clk_bulk_prepare(i2c_dev->nclocks, i2c_dev->clocks);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
i2c_dev->div_clk = i2c_dev->clocks[0].clk;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (!i2c_dev->multimaster_mode)
|
2020-09-29 22:18:55 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err = clk_enable(i2c_dev->div_clk);
|
|
|
|
if (err) {
|
|
|
|
dev_err(i2c_dev->dev, "failed to enable div-clk: %d\n", err);
|
|
|
|
goto unprepare_clocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unprepare_clocks:
|
|
|
|
clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tegra_i2c_release_clocks(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
2020-09-29 22:19:11 +00:00
|
|
|
if (i2c_dev->multimaster_mode)
|
2020-09-29 22:18:55 +00:00
|
|
|
clk_disable(i2c_dev->div_clk);
|
|
|
|
|
|
|
|
clk_bulk_unprepare(i2c_dev->nclocks, i2c_dev->clocks);
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:19:08 +00:00
|
|
|
static int tegra_i2c_init_hardware(struct tegra_i2c_dev *i2c_dev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(i2c_dev->dev);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(i2c_dev->dev, "runtime resume failed: %d\n", ret);
|
|
|
|
else
|
|
|
|
ret = tegra_i2c_init(i2c_dev);
|
|
|
|
|
2021-10-19 23:29:19 +00:00
|
|
|
pm_runtime_put_sync(i2c_dev->dev);
|
2020-09-29 22:19:08 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-27 20:59:38 +00:00
|
|
|
static int tegra_i2c_probe(struct platform_device *pdev)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev;
|
|
|
|
struct resource *res;
|
2020-09-29 22:19:11 +00:00
|
|
|
int err;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2012-06-13 10:12:39 +00:00
|
|
|
i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
|
2014-05-13 01:51:58 +00:00
|
|
|
if (!i2c_dev)
|
2012-06-13 10:12:39 +00:00
|
|
|
return -ENOMEM;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:18:57 +00:00
|
|
|
platform_set_drvdata(pdev, i2c_dev);
|
|
|
|
|
|
|
|
init_completion(&i2c_dev->msg_complete);
|
|
|
|
init_completion(&i2c_dev->dma_complete);
|
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
i2c_dev->hw = device_get_match_data(&pdev->dev);
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_dev->cont_id = pdev->id;
|
|
|
|
i2c_dev->dev = &pdev->dev;
|
2011-06-22 16:16:56 +00:00
|
|
|
|
2020-09-29 22:18:57 +00:00
|
|
|
i2c_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
|
|
|
|
if (IS_ERR(i2c_dev->base))
|
|
|
|
return PTR_ERR(i2c_dev->base);
|
|
|
|
|
|
|
|
i2c_dev->base_phys = res->start;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = platform_get_irq(pdev, 0);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2020-09-29 22:18:57 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->irq = err;
|
2020-09-29 22:18:57 +00:00
|
|
|
|
|
|
|
/* interrupt will be enabled during of transfer time */
|
|
|
|
irq_set_status_flags(i2c_dev->irq, IRQ_NOAUTOEN);
|
|
|
|
|
2021-01-12 13:17:09 +00:00
|
|
|
err = devm_request_threaded_irq(i2c_dev->dev, i2c_dev->irq,
|
|
|
|
NULL, tegra_i2c_isr,
|
|
|
|
IRQF_NO_SUSPEND | IRQF_ONESHOT,
|
|
|
|
dev_name(i2c_dev->dev), i2c_dev);
|
2020-09-29 22:19:11 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2020-09-29 22:18:57 +00:00
|
|
|
|
2016-03-14 13:22:18 +00:00
|
|
|
tegra_i2c_parse_dt(i2c_dev);
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
err = tegra_i2c_init_reset(i2c_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = tegra_i2c_init_clocks(i2c_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2020-09-29 22:18:55 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = tegra_i2c_init_dma(i2c_dev);
|
|
|
|
if (err)
|
2020-09-29 22:18:57 +00:00
|
|
|
goto release_clocks;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-07-27 20:57:19 +00:00
|
|
|
/*
|
2020-09-29 22:19:13 +00:00
|
|
|
* VI I2C is in VE power domain which is not always ON and not
|
|
|
|
* IRQ-safe. Thus, IRQ-safe device shouldn't be attached to a
|
|
|
|
* non IRQ-safe domain because this prevents powering off the power
|
|
|
|
* domain.
|
|
|
|
*
|
|
|
|
* VI I2C device shouldn't be marked as IRQ-safe because VI I2C won't
|
2024-08-13 16:12:53 +00:00
|
|
|
* be used for atomic transfers. ACPI device is not IRQ safe also.
|
2020-07-27 20:57:19 +00:00
|
|
|
*/
|
2024-08-13 16:12:53 +00:00
|
|
|
if (!IS_VI(i2c_dev) && !has_acpi_companion(i2c_dev->dev))
|
2020-09-29 22:19:11 +00:00
|
|
|
pm_runtime_irq_safe(i2c_dev->dev);
|
2020-09-29 22:19:14 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
pm_runtime_enable(i2c_dev->dev);
|
2016-08-26 13:09:04 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = tegra_i2c_init_hardware(i2c_dev);
|
|
|
|
if (err)
|
2020-09-29 22:19:08 +00:00
|
|
|
goto release_rpm;
|
2011-02-21 01:14:21 +00:00
|
|
|
|
|
|
|
i2c_set_adapdata(&i2c_dev->adapter, i2c_dev);
|
2020-09-29 22:19:11 +00:00
|
|
|
i2c_dev->adapter.dev.of_node = i2c_dev->dev->of_node;
|
|
|
|
i2c_dev->adapter.dev.parent = i2c_dev->dev;
|
2020-09-29 22:18:57 +00:00
|
|
|
i2c_dev->adapter.retries = 1;
|
|
|
|
i2c_dev->adapter.timeout = 6 * HZ;
|
|
|
|
i2c_dev->adapter.quirks = i2c_dev->hw->quirks;
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_dev->adapter.owner = THIS_MODULE;
|
2014-07-10 11:46:35 +00:00
|
|
|
i2c_dev->adapter.class = I2C_CLASS_DEPRECATED;
|
2020-09-29 22:18:57 +00:00
|
|
|
i2c_dev->adapter.algo = &tegra_i2c_algo;
|
|
|
|
i2c_dev->adapter.nr = pdev->id;
|
2022-11-17 10:04:15 +00:00
|
|
|
ACPI_COMPANION_SET(&i2c_dev->adapter.dev, ACPI_COMPANION(&pdev->dev));
|
2020-09-29 22:18:57 +00:00
|
|
|
|
|
|
|
if (i2c_dev->hw->supports_bus_clear)
|
|
|
|
i2c_dev->adapter.bus_recovery_info = &tegra_i2c_recovery_info;
|
|
|
|
|
2022-08-11 07:10:30 +00:00
|
|
|
strscpy(i2c_dev->adapter.name, dev_name(i2c_dev->dev),
|
2011-02-21 01:14:21 +00:00
|
|
|
sizeof(i2c_dev->adapter.name));
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = i2c_add_numbered_adapter(&i2c_dev->adapter);
|
|
|
|
if (err)
|
2020-09-29 22:19:08 +00:00
|
|
|
goto release_rpm;
|
2019-09-10 09:29:17 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
return 0;
|
2014-09-05 09:28:18 +00:00
|
|
|
|
2020-09-29 22:19:08 +00:00
|
|
|
release_rpm:
|
2020-09-29 22:19:11 +00:00
|
|
|
pm_runtime_disable(i2c_dev->dev);
|
2020-09-29 22:18:57 +00:00
|
|
|
|
|
|
|
tegra_i2c_release_dma(i2c_dev);
|
|
|
|
release_clocks:
|
2020-09-29 22:18:55 +00:00
|
|
|
tegra_i2c_release_clocks(i2c_dev);
|
2014-09-05 09:28:18 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
return err;
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-08 20:51:38 +00:00
|
|
|
static void tegra_i2c_remove(struct platform_device *pdev)
|
2011-02-21 01:14:21 +00:00
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
|
2016-08-26 13:08:59 +00:00
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
i2c_del_adapter(&i2c_dev->adapter);
|
2021-10-19 23:29:19 +00:00
|
|
|
pm_runtime_force_suspend(i2c_dev->dev);
|
2016-08-26 13:09:04 +00:00
|
|
|
|
2019-02-12 19:06:46 +00:00
|
|
|
tegra_i2c_release_dma(i2c_dev);
|
2020-09-29 22:18:55 +00:00
|
|
|
tegra_i2c_release_clocks(i2c_dev);
|
2011-02-21 01:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 22:18:58 +00:00
|
|
|
static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
|
2020-09-29 22:19:11 +00:00
|
|
|
int err;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = pinctrl_pm_select_default_state(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
err = clk_bulk_enable(i2c_dev->nclocks, i2c_dev->clocks);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2020-09-29 22:18:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VI I2C device is attached to VE power domain which goes through
|
2020-09-29 22:19:13 +00:00
|
|
|
* power ON/OFF during runtime PM resume/suspend, meaning that
|
|
|
|
* controller needs to be re-initialized after power ON.
|
2020-09-29 22:18:58 +00:00
|
|
|
*/
|
2023-05-06 21:19:02 +00:00
|
|
|
if (IS_VI(i2c_dev)) {
|
2020-09-29 22:19:11 +00:00
|
|
|
err = tegra_i2c_init(i2c_dev);
|
|
|
|
if (err)
|
2020-09-29 22:18:58 +00:00
|
|
|
goto disable_clocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
disable_clocks:
|
|
|
|
clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks);
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
return err;
|
2020-09-29 22:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_bulk_disable(i2c_dev->nclocks, i2c_dev->clocks);
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
return pinctrl_pm_select_idle_state(dev);
|
2020-09-29 22:18:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-07 23:12:34 +00:00
|
|
|
static int __maybe_unused tegra_i2c_suspend(struct device *dev)
|
2019-06-07 05:37:47 +00:00
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
|
2020-09-29 22:19:11 +00:00
|
|
|
int err;
|
2019-06-07 05:37:47 +00:00
|
|
|
|
|
|
|
i2c_mark_adapter_suspended(&i2c_dev->adapter);
|
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
if (!pm_runtime_status_suspended(dev)) {
|
2019-12-13 13:44:17 +00:00
|
|
|
err = tegra_i2c_runtime_suspend(dev);
|
2020-09-29 22:19:11 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
2019-12-13 13:44:17 +00:00
|
|
|
|
2020-09-29 22:19:11 +00:00
|
|
|
return 0;
|
2019-06-07 05:37:47 +00:00
|
|
|
}
|
|
|
|
|
2019-07-07 23:12:34 +00:00
|
|
|
static int __maybe_unused tegra_i2c_resume(struct device *dev)
|
2019-06-07 05:37:47 +00:00
|
|
|
{
|
|
|
|
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
|
|
|
|
int err;
|
|
|
|
|
2019-12-13 13:44:17 +00:00
|
|
|
/*
|
|
|
|
* We need to ensure that clocks are enabled so that registers can be
|
|
|
|
* restored in tegra_i2c_init().
|
|
|
|
*/
|
2019-09-10 09:29:17 +00:00
|
|
|
err = tegra_i2c_runtime_resume(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2020-09-29 22:18:48 +00:00
|
|
|
err = tegra_i2c_init(i2c_dev);
|
2019-06-07 05:37:47 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2019-12-13 13:44:17 +00:00
|
|
|
/*
|
|
|
|
* In case we are runtime suspended, disable clocks again so that we
|
|
|
|
* don't unbalance the clock reference counts during the next runtime
|
|
|
|
* resume transition.
|
|
|
|
*/
|
|
|
|
if (pm_runtime_status_suspended(dev)) {
|
|
|
|
err = tegra_i2c_runtime_suspend(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
2019-09-10 09:29:17 +00:00
|
|
|
|
2019-06-07 05:37:47 +00:00
|
|
|
i2c_mark_adapter_resumed(&i2c_dev->adapter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-26 13:09:04 +00:00
|
|
|
static const struct dev_pm_ops tegra_i2c_pm = {
|
2019-09-10 09:29:17 +00:00
|
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
|
2016-08-26 13:09:04 +00:00
|
|
|
SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,
|
|
|
|
NULL)
|
|
|
|
};
|
2019-06-11 10:51:10 +00:00
|
|
|
|
2021-11-25 16:53:44 +00:00
|
|
|
static const struct acpi_device_id tegra_i2c_acpi_match[] = {
|
|
|
|
{.id = "NVDA0101", .driver_data = (kernel_ulong_t)&tegra210_i2c_hw},
|
|
|
|
{.id = "NVDA0201", .driver_data = (kernel_ulong_t)&tegra186_i2c_hw},
|
|
|
|
{.id = "NVDA0301", .driver_data = (kernel_ulong_t)&tegra194_i2c_hw},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, tegra_i2c_acpi_match);
|
|
|
|
|
2011-02-21 01:14:21 +00:00
|
|
|
static struct platform_driver tegra_i2c_driver = {
|
2020-09-29 22:19:14 +00:00
|
|
|
.probe = tegra_i2c_probe,
|
2023-05-08 20:51:38 +00:00
|
|
|
.remove_new = tegra_i2c_remove,
|
2020-09-29 22:19:14 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "tegra-i2c",
|
2013-03-21 08:08:46 +00:00
|
|
|
.of_match_table = tegra_i2c_of_match,
|
2021-11-25 16:53:44 +00:00
|
|
|
.acpi_match_table = tegra_i2c_acpi_match,
|
2020-09-29 22:19:14 +00:00
|
|
|
.pm = &tegra_i2c_pm,
|
2011-02-21 01:14:21 +00:00
|
|
|
},
|
|
|
|
};
|
2019-02-12 19:06:46 +00:00
|
|
|
module_platform_driver(tegra_i2c_driver);
|
2011-02-21 01:14:21 +00:00
|
|
|
|
2020-09-29 22:19:15 +00:00
|
|
|
MODULE_DESCRIPTION("NVIDIA Tegra I2C Bus Controller driver");
|
2011-02-21 01:14:21 +00:00
|
|
|
MODULE_AUTHOR("Colin Cross");
|
|
|
|
MODULE_LICENSE("GPL v2");
|