Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/i2c/busses/i2c-tegra.c |
| 3 | * |
| 4 | * Copyright (C) 2010 Google, Inc. |
| 5 | * Author: Colin Cross <ccross@android.com> |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/i2c.h> |
| 24 | #include <linux/io.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/slab.h> |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 28 | #include <linux/of_device.h> |
Paul Gortmaker | 93cf5d7 | 2011-07-29 21:14:30 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
Stephen Warren | dda9d6a | 2013-11-06 16:42:05 -0700 | [diff] [blame] | 30 | #include <linux/reset.h> |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 31 | |
| 32 | #include <asm/unaligned.h> |
| 33 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 34 | #define TEGRA_I2C_TIMEOUT (msecs_to_jiffies(1000)) |
| 35 | #define BYTES_PER_FIFO_WORD 4 |
| 36 | |
| 37 | #define I2C_CNFG 0x000 |
Jay Cheng | 40abcf7 | 2011-04-25 15:32:27 -0600 | [diff] [blame] | 38 | #define I2C_CNFG_DEBOUNCE_CNT_SHIFT 12 |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 39 | #define I2C_CNFG_PACKET_MODE_EN (1<<10) |
| 40 | #define I2C_CNFG_NEW_MASTER_FSM (1<<11) |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 41 | #define I2C_STATUS 0x01C |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 42 | #define I2C_SL_CNFG 0x020 |
Stephen Warren | 5afa9d3 | 2011-06-06 11:25:19 -0600 | [diff] [blame] | 43 | #define I2C_SL_CNFG_NACK (1<<1) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 44 | #define I2C_SL_CNFG_NEWSL (1<<2) |
| 45 | #define I2C_SL_ADDR1 0x02c |
Stephen Warren | 5afa9d3 | 2011-06-06 11:25:19 -0600 | [diff] [blame] | 46 | #define I2C_SL_ADDR2 0x030 |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 47 | #define I2C_TX_FIFO 0x050 |
| 48 | #define I2C_RX_FIFO 0x054 |
| 49 | #define I2C_PACKET_TRANSFER_STATUS 0x058 |
| 50 | #define I2C_FIFO_CONTROL 0x05c |
| 51 | #define I2C_FIFO_CONTROL_TX_FLUSH (1<<1) |
| 52 | #define I2C_FIFO_CONTROL_RX_FLUSH (1<<0) |
| 53 | #define I2C_FIFO_CONTROL_TX_TRIG_SHIFT 5 |
| 54 | #define I2C_FIFO_CONTROL_RX_TRIG_SHIFT 2 |
| 55 | #define I2C_FIFO_STATUS 0x060 |
| 56 | #define I2C_FIFO_STATUS_TX_MASK 0xF0 |
| 57 | #define I2C_FIFO_STATUS_TX_SHIFT 4 |
| 58 | #define I2C_FIFO_STATUS_RX_MASK 0x0F |
| 59 | #define I2C_FIFO_STATUS_RX_SHIFT 0 |
| 60 | #define I2C_INT_MASK 0x064 |
| 61 | #define I2C_INT_STATUS 0x068 |
| 62 | #define I2C_INT_PACKET_XFER_COMPLETE (1<<7) |
| 63 | #define I2C_INT_ALL_PACKETS_XFER_COMPLETE (1<<6) |
| 64 | #define I2C_INT_TX_FIFO_OVERFLOW (1<<5) |
| 65 | #define I2C_INT_RX_FIFO_UNDERFLOW (1<<4) |
| 66 | #define I2C_INT_NO_ACK (1<<3) |
| 67 | #define I2C_INT_ARBITRATION_LOST (1<<2) |
| 68 | #define I2C_INT_TX_FIFO_DATA_REQ (1<<1) |
| 69 | #define I2C_INT_RX_FIFO_DATA_REQ (1<<0) |
| 70 | #define I2C_CLK_DIVISOR 0x06c |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 71 | #define I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT 16 |
| 72 | #define I2C_CLK_MULTIPLIER_STD_FAST_MODE 8 |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 73 | |
| 74 | #define DVC_CTRL_REG1 0x000 |
| 75 | #define DVC_CTRL_REG1_INTR_EN (1<<10) |
| 76 | #define DVC_CTRL_REG2 0x004 |
| 77 | #define DVC_CTRL_REG3 0x008 |
| 78 | #define DVC_CTRL_REG3_SW_PROG (1<<26) |
| 79 | #define DVC_CTRL_REG3_I2C_DONE_INTR_EN (1<<30) |
| 80 | #define DVC_STATUS 0x00c |
| 81 | #define DVC_STATUS_I2C_DONE_INTR (1<<30) |
| 82 | |
| 83 | #define I2C_ERR_NONE 0x00 |
| 84 | #define I2C_ERR_NO_ACK 0x01 |
| 85 | #define I2C_ERR_ARBITRATION_LOST 0x02 |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 86 | #define I2C_ERR_UNKNOWN_INTERRUPT 0x04 |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 87 | |
| 88 | #define PACKET_HEADER0_HEADER_SIZE_SHIFT 28 |
| 89 | #define PACKET_HEADER0_PACKET_ID_SHIFT 16 |
| 90 | #define PACKET_HEADER0_CONT_ID_SHIFT 12 |
| 91 | #define PACKET_HEADER0_PROTOCOL_I2C (1<<4) |
| 92 | |
| 93 | #define I2C_HEADER_HIGHSPEED_MODE (1<<22) |
| 94 | #define I2C_HEADER_CONT_ON_NAK (1<<21) |
| 95 | #define I2C_HEADER_SEND_START_BYTE (1<<20) |
| 96 | #define I2C_HEADER_READ (1<<19) |
| 97 | #define I2C_HEADER_10BIT_ADDR (1<<18) |
| 98 | #define I2C_HEADER_IE_ENABLE (1<<17) |
| 99 | #define I2C_HEADER_REPEAT_START (1<<16) |
Laxman Dewangan | c8f5af2 | 2012-06-13 15:42:38 +0530 | [diff] [blame] | 100 | #define I2C_HEADER_CONTINUE_XFER (1<<15) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 101 | #define I2C_HEADER_MASTER_ADDR_SHIFT 12 |
| 102 | #define I2C_HEADER_SLAVE_ADDR_SHIFT 1 |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 103 | |
| 104 | #define I2C_CONFIG_LOAD 0x08C |
| 105 | #define I2C_MSTR_CONFIG_LOAD (1 << 0) |
| 106 | #define I2C_SLV_CONFIG_LOAD (1 << 1) |
| 107 | #define I2C_TIMEOUT_CONFIG_LOAD (1 << 2) |
| 108 | |
Laxman Dewangan | c8f5af2 | 2012-06-13 15:42:38 +0530 | [diff] [blame] | 109 | /* |
| 110 | * msg_end_type: The bus control which need to be send at end of transfer. |
| 111 | * @MSG_END_STOP: Send stop pulse at end of transfer. |
| 112 | * @MSG_END_REPEAT_START: Send repeat start at end of transfer. |
| 113 | * @MSG_END_CONTINUE: The following on message is coming and so do not send |
| 114 | * stop or repeat start. |
| 115 | */ |
| 116 | enum msg_end_type { |
| 117 | MSG_END_STOP, |
| 118 | MSG_END_REPEAT_START, |
| 119 | MSG_END_CONTINUE, |
| 120 | }; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 121 | |
| 122 | /** |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 123 | * struct tegra_i2c_hw_feature : Different HW support on Tegra |
| 124 | * @has_continue_xfer_support: Continue transfer supports. |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 125 | * @has_per_pkt_xfer_complete_irq: Has enable/disable capability for transfer |
| 126 | * complete interrupt per packet basis. |
| 127 | * @has_single_clk_source: The i2c controller has single clock source. Tegra30 |
| 128 | * and earlier Socs has two clock sources i.e. div-clk and |
| 129 | * fast-clk. |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 130 | * @has_config_load_reg: Has the config load register to load the new |
| 131 | * configuration. |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 132 | * @clk_divisor_hs_mode: Clock divisor in HS mode. |
| 133 | * @clk_divisor_std_fast_mode: Clock divisor in standard/fast mode. It is |
| 134 | * applicable if there is no fast clock source i.e. single clock |
| 135 | * source. |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 136 | */ |
| 137 | |
| 138 | struct tegra_i2c_hw_feature { |
| 139 | bool has_continue_xfer_support; |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 140 | bool has_per_pkt_xfer_complete_irq; |
| 141 | bool has_single_clk_source; |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 142 | bool has_config_load_reg; |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 143 | int clk_divisor_hs_mode; |
| 144 | int clk_divisor_std_fast_mode; |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | /** |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 148 | * struct tegra_i2c_dev - per device i2c context |
| 149 | * @dev: device reference for power management |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 150 | * @hw: Tegra i2c hw feature. |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 151 | * @adapter: core i2c layer adapter information |
Laxman Dewangan | 14e92bd | 2012-08-08 13:21:32 +0530 | [diff] [blame] | 152 | * @div_clk: clock reference for div clock of i2c controller. |
| 153 | * @fast_clk: clock reference for fast clock of i2c controller. |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 154 | * @base: ioremapped registers cookie |
| 155 | * @cont_id: i2c controller id, used for for packet header |
| 156 | * @irq: irq number of transfer complete interrupt |
| 157 | * @is_dvc: identifies the DVC i2c controller, has a different register layout |
| 158 | * @msg_complete: transfer completion notifier |
| 159 | * @msg_err: error code for completed message |
| 160 | * @msg_buf: pointer to current message data |
| 161 | * @msg_buf_remaining: size of unsent data in the message buffer |
| 162 | * @msg_read: identifies read transfers |
| 163 | * @bus_clk_rate: current i2c bus clock rate |
| 164 | * @is_suspended: prevents i2c controller accesses after suspend is called |
| 165 | */ |
| 166 | struct tegra_i2c_dev { |
| 167 | struct device *dev; |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 168 | const struct tegra_i2c_hw_feature *hw; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 169 | struct i2c_adapter adapter; |
Laxman Dewangan | 14e92bd | 2012-08-08 13:21:32 +0530 | [diff] [blame] | 170 | struct clk *div_clk; |
| 171 | struct clk *fast_clk; |
Stephen Warren | dda9d6a | 2013-11-06 16:42:05 -0700 | [diff] [blame] | 172 | struct reset_control *rst; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 173 | void __iomem *base; |
| 174 | int cont_id; |
| 175 | int irq; |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 176 | bool irq_disabled; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 177 | int is_dvc; |
| 178 | struct completion msg_complete; |
| 179 | int msg_err; |
| 180 | u8 *msg_buf; |
| 181 | size_t msg_buf_remaining; |
| 182 | int msg_read; |
Stephen Warren | 49a64ac | 2013-03-21 08:08:46 +0000 | [diff] [blame] | 183 | u32 bus_clk_rate; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 184 | bool is_suspended; |
| 185 | }; |
| 186 | |
| 187 | static void dvc_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned long reg) |
| 188 | { |
| 189 | writel(val, i2c_dev->base + reg); |
| 190 | } |
| 191 | |
| 192 | static u32 dvc_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) |
| 193 | { |
| 194 | return readl(i2c_dev->base + reg); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * i2c_writel and i2c_readl will offset the register if necessary to talk |
| 199 | * to the I2C block inside the DVC block |
| 200 | */ |
| 201 | static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev, |
| 202 | unsigned long reg) |
| 203 | { |
| 204 | if (i2c_dev->is_dvc) |
| 205 | reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40; |
| 206 | return reg; |
| 207 | } |
| 208 | |
| 209 | static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, |
| 210 | unsigned long reg) |
| 211 | { |
| 212 | writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); |
Laxman Dewangan | ec7aaca | 2012-06-13 15:42:36 +0530 | [diff] [blame] | 213 | |
| 214 | /* Read back register to make sure that register writes completed */ |
| 215 | if (reg != I2C_TX_FIFO) |
| 216 | readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) |
| 220 | { |
| 221 | return readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); |
| 222 | } |
| 223 | |
| 224 | static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data, |
| 225 | unsigned long reg, int len) |
| 226 | { |
| 227 | writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); |
| 228 | } |
| 229 | |
| 230 | static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data, |
| 231 | unsigned long reg, int len) |
| 232 | { |
| 233 | readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len); |
| 234 | } |
| 235 | |
| 236 | static void tegra_i2c_mask_irq(struct tegra_i2c_dev *i2c_dev, u32 mask) |
| 237 | { |
| 238 | u32 int_mask = i2c_readl(i2c_dev, I2C_INT_MASK); |
| 239 | int_mask &= ~mask; |
| 240 | i2c_writel(i2c_dev, int_mask, I2C_INT_MASK); |
| 241 | } |
| 242 | |
| 243 | static void tegra_i2c_unmask_irq(struct tegra_i2c_dev *i2c_dev, u32 mask) |
| 244 | { |
| 245 | u32 int_mask = i2c_readl(i2c_dev, I2C_INT_MASK); |
| 246 | int_mask |= mask; |
| 247 | i2c_writel(i2c_dev, int_mask, I2C_INT_MASK); |
| 248 | } |
| 249 | |
| 250 | static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) |
| 251 | { |
| 252 | unsigned long timeout = jiffies + HZ; |
| 253 | u32 val = i2c_readl(i2c_dev, I2C_FIFO_CONTROL); |
| 254 | val |= I2C_FIFO_CONTROL_TX_FLUSH | I2C_FIFO_CONTROL_RX_FLUSH; |
| 255 | i2c_writel(i2c_dev, val, I2C_FIFO_CONTROL); |
| 256 | |
| 257 | while (i2c_readl(i2c_dev, I2C_FIFO_CONTROL) & |
| 258 | (I2C_FIFO_CONTROL_TX_FLUSH | I2C_FIFO_CONTROL_RX_FLUSH)) { |
| 259 | if (time_after(jiffies, timeout)) { |
| 260 | dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n"); |
| 261 | return -ETIMEDOUT; |
| 262 | } |
| 263 | msleep(1); |
| 264 | } |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int tegra_i2c_empty_rx_fifo(struct tegra_i2c_dev *i2c_dev) |
| 269 | { |
| 270 | u32 val; |
| 271 | int rx_fifo_avail; |
| 272 | u8 *buf = i2c_dev->msg_buf; |
| 273 | size_t buf_remaining = i2c_dev->msg_buf_remaining; |
| 274 | int words_to_transfer; |
| 275 | |
| 276 | val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); |
| 277 | rx_fifo_avail = (val & I2C_FIFO_STATUS_RX_MASK) >> |
| 278 | I2C_FIFO_STATUS_RX_SHIFT; |
| 279 | |
| 280 | /* Rounds down to not include partial word at the end of buf */ |
| 281 | words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; |
| 282 | if (words_to_transfer > rx_fifo_avail) |
| 283 | words_to_transfer = rx_fifo_avail; |
| 284 | |
| 285 | i2c_readsl(i2c_dev, buf, I2C_RX_FIFO, words_to_transfer); |
| 286 | |
| 287 | buf += words_to_transfer * BYTES_PER_FIFO_WORD; |
| 288 | buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; |
| 289 | rx_fifo_avail -= words_to_transfer; |
| 290 | |
| 291 | /* |
| 292 | * If there is a partial word at the end of buf, handle it manually to |
| 293 | * prevent overwriting past the end of buf |
| 294 | */ |
| 295 | if (rx_fifo_avail > 0 && buf_remaining > 0) { |
| 296 | BUG_ON(buf_remaining > 3); |
| 297 | val = i2c_readl(i2c_dev, I2C_RX_FIFO); |
Dmitry Osipenko | 8c340f6 | 2015-01-26 19:55:02 +0300 | [diff] [blame] | 298 | val = cpu_to_le32(val); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 299 | memcpy(buf, &val, buf_remaining); |
| 300 | buf_remaining = 0; |
| 301 | rx_fifo_avail--; |
| 302 | } |
| 303 | |
| 304 | BUG_ON(rx_fifo_avail > 0 && buf_remaining > 0); |
| 305 | i2c_dev->msg_buf_remaining = buf_remaining; |
| 306 | i2c_dev->msg_buf = buf; |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) |
| 311 | { |
| 312 | u32 val; |
| 313 | int tx_fifo_avail; |
| 314 | u8 *buf = i2c_dev->msg_buf; |
| 315 | size_t buf_remaining = i2c_dev->msg_buf_remaining; |
| 316 | int words_to_transfer; |
| 317 | |
| 318 | val = i2c_readl(i2c_dev, I2C_FIFO_STATUS); |
| 319 | tx_fifo_avail = (val & I2C_FIFO_STATUS_TX_MASK) >> |
| 320 | I2C_FIFO_STATUS_TX_SHIFT; |
| 321 | |
| 322 | /* Rounds down to not include partial word at the end of buf */ |
| 323 | words_to_transfer = buf_remaining / BYTES_PER_FIFO_WORD; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 324 | |
Doug Anderson | 96219c3 | 2011-08-30 11:46:10 -0600 | [diff] [blame] | 325 | /* It's very common to have < 4 bytes, so optimize that case. */ |
| 326 | if (words_to_transfer) { |
| 327 | if (words_to_transfer > tx_fifo_avail) |
| 328 | words_to_transfer = tx_fifo_avail; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 329 | |
Doug Anderson | 96219c3 | 2011-08-30 11:46:10 -0600 | [diff] [blame] | 330 | /* |
| 331 | * Update state before writing to FIFO. If this casues us |
| 332 | * to finish writing all bytes (AKA buf_remaining goes to 0) we |
| 333 | * have a potential for an interrupt (PACKET_XFER_COMPLETE is |
| 334 | * not maskable). We need to make sure that the isr sees |
| 335 | * buf_remaining as 0 and doesn't call us back re-entrantly. |
| 336 | */ |
| 337 | buf_remaining -= words_to_transfer * BYTES_PER_FIFO_WORD; |
| 338 | tx_fifo_avail -= words_to_transfer; |
| 339 | i2c_dev->msg_buf_remaining = buf_remaining; |
| 340 | i2c_dev->msg_buf = buf + |
| 341 | words_to_transfer * BYTES_PER_FIFO_WORD; |
| 342 | barrier(); |
| 343 | |
| 344 | i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer); |
| 345 | |
| 346 | buf += words_to_transfer * BYTES_PER_FIFO_WORD; |
| 347 | } |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 348 | |
| 349 | /* |
| 350 | * If there is a partial word at the end of buf, handle it manually to |
| 351 | * prevent reading past the end of buf, which could cross a page |
| 352 | * boundary and fault. |
| 353 | */ |
| 354 | if (tx_fifo_avail > 0 && buf_remaining > 0) { |
| 355 | BUG_ON(buf_remaining > 3); |
| 356 | memcpy(&val, buf, buf_remaining); |
Dmitry Osipenko | 8c340f6 | 2015-01-26 19:55:02 +0300 | [diff] [blame] | 357 | val = le32_to_cpu(val); |
Doug Anderson | 96219c3 | 2011-08-30 11:46:10 -0600 | [diff] [blame] | 358 | |
| 359 | /* Again update before writing to FIFO to make sure isr sees. */ |
| 360 | i2c_dev->msg_buf_remaining = 0; |
| 361 | i2c_dev->msg_buf = NULL; |
| 362 | barrier(); |
| 363 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 364 | i2c_writel(i2c_dev, val, I2C_TX_FIFO); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * One of the Tegra I2C blocks is inside the DVC (Digital Voltage Controller) |
| 372 | * block. This block is identical to the rest of the I2C blocks, except that |
| 373 | * it only supports master mode, it has registers moved around, and it needs |
| 374 | * some extra init to get it into I2C mode. The register moves are handled |
| 375 | * by i2c_readl and i2c_writel |
| 376 | */ |
| 377 | static void tegra_dvc_init(struct tegra_i2c_dev *i2c_dev) |
| 378 | { |
| 379 | u32 val = 0; |
| 380 | val = dvc_readl(i2c_dev, DVC_CTRL_REG3); |
| 381 | val |= DVC_CTRL_REG3_SW_PROG; |
| 382 | val |= DVC_CTRL_REG3_I2C_DONE_INTR_EN; |
| 383 | dvc_writel(i2c_dev, val, DVC_CTRL_REG3); |
| 384 | |
| 385 | val = dvc_readl(i2c_dev, DVC_CTRL_REG1); |
| 386 | val |= DVC_CTRL_REG1_INTR_EN; |
| 387 | dvc_writel(i2c_dev, val, DVC_CTRL_REG1); |
| 388 | } |
| 389 | |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 390 | static inline int tegra_i2c_clock_enable(struct tegra_i2c_dev *i2c_dev) |
| 391 | { |
| 392 | int ret; |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 393 | if (!i2c_dev->hw->has_single_clk_source) { |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 394 | ret = clk_enable(i2c_dev->fast_clk); |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 395 | if (ret < 0) { |
| 396 | dev_err(i2c_dev->dev, |
| 397 | "Enabling fast clk failed, err %d\n", ret); |
| 398 | return ret; |
| 399 | } |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 400 | } |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 401 | ret = clk_enable(i2c_dev->div_clk); |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 402 | if (ret < 0) { |
| 403 | dev_err(i2c_dev->dev, |
| 404 | "Enabling div clk failed, err %d\n", ret); |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 405 | clk_disable(i2c_dev->fast_clk); |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 406 | } |
| 407 | return ret; |
| 408 | } |
| 409 | |
| 410 | static inline void tegra_i2c_clock_disable(struct tegra_i2c_dev *i2c_dev) |
| 411 | { |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 412 | clk_disable(i2c_dev->div_clk); |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 413 | if (!i2c_dev->hw->has_single_clk_source) |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 414 | clk_disable(i2c_dev->fast_clk); |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 415 | } |
| 416 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 417 | static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev) |
| 418 | { |
| 419 | u32 val; |
| 420 | int err = 0; |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 421 | u32 clk_divisor; |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 422 | unsigned long timeout = jiffies + HZ; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 423 | |
Laxman Dewangan | 132c803 | 2013-03-15 05:34:08 +0000 | [diff] [blame] | 424 | err = tegra_i2c_clock_enable(i2c_dev); |
| 425 | if (err < 0) { |
| 426 | dev_err(i2c_dev->dev, "Clock enable failed %d\n", err); |
| 427 | return err; |
| 428 | } |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 429 | |
Stephen Warren | dda9d6a | 2013-11-06 16:42:05 -0700 | [diff] [blame] | 430 | reset_control_assert(i2c_dev->rst); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 431 | udelay(2); |
Stephen Warren | dda9d6a | 2013-11-06 16:42:05 -0700 | [diff] [blame] | 432 | reset_control_deassert(i2c_dev->rst); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 433 | |
| 434 | if (i2c_dev->is_dvc) |
| 435 | tegra_dvc_init(i2c_dev); |
| 436 | |
Jay Cheng | 40abcf7 | 2011-04-25 15:32:27 -0600 | [diff] [blame] | 437 | val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN | |
| 438 | (0x2 << I2C_CNFG_DEBOUNCE_CNT_SHIFT); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 439 | i2c_writel(i2c_dev, val, I2C_CNFG); |
| 440 | i2c_writel(i2c_dev, 0, I2C_INT_MASK); |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 441 | |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 442 | /* Make sure clock divisor programmed correctly */ |
| 443 | clk_divisor = i2c_dev->hw->clk_divisor_hs_mode; |
| 444 | clk_divisor |= i2c_dev->hw->clk_divisor_std_fast_mode << |
| 445 | I2C_CLK_DIVISOR_STD_FAST_MODE_SHIFT; |
| 446 | i2c_writel(i2c_dev, clk_divisor, I2C_CLK_DIVISOR); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 447 | |
Kenneth Waters | 65a1a0a | 2011-04-25 12:29:54 -0600 | [diff] [blame] | 448 | if (!i2c_dev->is_dvc) { |
| 449 | u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG); |
Stephen Warren | 5afa9d3 | 2011-06-06 11:25:19 -0600 | [diff] [blame] | 450 | sl_cfg |= I2C_SL_CNFG_NACK | I2C_SL_CNFG_NEWSL; |
| 451 | i2c_writel(i2c_dev, sl_cfg, I2C_SL_CNFG); |
| 452 | i2c_writel(i2c_dev, 0xfc, I2C_SL_ADDR1); |
| 453 | i2c_writel(i2c_dev, 0x00, I2C_SL_ADDR2); |
| 454 | |
Kenneth Waters | 65a1a0a | 2011-04-25 12:29:54 -0600 | [diff] [blame] | 455 | } |
| 456 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 457 | val = 7 << I2C_FIFO_CONTROL_TX_TRIG_SHIFT | |
| 458 | 0 << I2C_FIFO_CONTROL_RX_TRIG_SHIFT; |
| 459 | i2c_writel(i2c_dev, val, I2C_FIFO_CONTROL); |
| 460 | |
| 461 | if (tegra_i2c_flush_fifos(i2c_dev)) |
| 462 | err = -ETIMEDOUT; |
| 463 | |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 464 | if (i2c_dev->hw->has_config_load_reg) { |
| 465 | i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD); |
| 466 | while (i2c_readl(i2c_dev, I2C_CONFIG_LOAD) != 0) { |
| 467 | if (time_after(jiffies, timeout)) { |
| 468 | dev_warn(i2c_dev->dev, |
| 469 | "timeout waiting for config load\n"); |
| 470 | return -ETIMEDOUT; |
| 471 | } |
| 472 | msleep(1); |
| 473 | } |
| 474 | } |
| 475 | |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 476 | tegra_i2c_clock_disable(i2c_dev); |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 477 | |
| 478 | if (i2c_dev->irq_disabled) { |
| 479 | i2c_dev->irq_disabled = 0; |
| 480 | enable_irq(i2c_dev->irq); |
| 481 | } |
| 482 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 483 | return err; |
| 484 | } |
| 485 | |
| 486 | static irqreturn_t tegra_i2c_isr(int irq, void *dev_id) |
| 487 | { |
| 488 | u32 status; |
| 489 | const u32 status_err = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; |
| 490 | struct tegra_i2c_dev *i2c_dev = dev_id; |
| 491 | |
| 492 | status = i2c_readl(i2c_dev, I2C_INT_STATUS); |
| 493 | |
| 494 | if (status == 0) { |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 495 | dev_warn(i2c_dev->dev, "irq status 0 %08x %08x %08x\n", |
| 496 | i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS), |
| 497 | i2c_readl(i2c_dev, I2C_STATUS), |
| 498 | i2c_readl(i2c_dev, I2C_CNFG)); |
| 499 | i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT; |
| 500 | |
| 501 | if (!i2c_dev->irq_disabled) { |
| 502 | disable_irq_nosync(i2c_dev->irq); |
| 503 | i2c_dev->irq_disabled = 1; |
| 504 | } |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 505 | goto err; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | if (unlikely(status & status_err)) { |
| 509 | if (status & I2C_INT_NO_ACK) |
| 510 | i2c_dev->msg_err |= I2C_ERR_NO_ACK; |
| 511 | if (status & I2C_INT_ARBITRATION_LOST) |
| 512 | i2c_dev->msg_err |= I2C_ERR_ARBITRATION_LOST; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 513 | goto err; |
| 514 | } |
| 515 | |
| 516 | if (i2c_dev->msg_read && (status & I2C_INT_RX_FIFO_DATA_REQ)) { |
| 517 | if (i2c_dev->msg_buf_remaining) |
| 518 | tegra_i2c_empty_rx_fifo(i2c_dev); |
| 519 | else |
| 520 | BUG(); |
| 521 | } |
| 522 | |
| 523 | if (!i2c_dev->msg_read && (status & I2C_INT_TX_FIFO_DATA_REQ)) { |
| 524 | if (i2c_dev->msg_buf_remaining) |
| 525 | tegra_i2c_fill_tx_fifo(i2c_dev); |
| 526 | else |
| 527 | tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ); |
| 528 | } |
| 529 | |
Laxman Dewangan | c889e91 | 2012-05-07 12:16:19 +0530 | [diff] [blame] | 530 | i2c_writel(i2c_dev, status, I2C_INT_STATUS); |
| 531 | if (i2c_dev->is_dvc) |
| 532 | dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); |
| 533 | |
Doug Anderson | 96219c3 | 2011-08-30 11:46:10 -0600 | [diff] [blame] | 534 | if (status & I2C_INT_PACKET_XFER_COMPLETE) { |
| 535 | BUG_ON(i2c_dev->msg_buf_remaining); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 536 | complete(&i2c_dev->msg_complete); |
Doug Anderson | 96219c3 | 2011-08-30 11:46:10 -0600 | [diff] [blame] | 537 | } |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 538 | return IRQ_HANDLED; |
| 539 | err: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 540 | /* An error occurred, mask all interrupts */ |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 541 | tegra_i2c_mask_irq(i2c_dev, I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST | |
| 542 | I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | |
| 543 | I2C_INT_RX_FIFO_DATA_REQ); |
| 544 | i2c_writel(i2c_dev, status, I2C_INT_STATUS); |
Todd Poynor | cb63c62 | 2011-04-25 15:32:25 -0600 | [diff] [blame] | 545 | if (i2c_dev->is_dvc) |
| 546 | dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); |
Laxman Dewangan | c889e91 | 2012-05-07 12:16:19 +0530 | [diff] [blame] | 547 | |
| 548 | complete(&i2c_dev->msg_complete); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 549 | return IRQ_HANDLED; |
| 550 | } |
| 551 | |
| 552 | static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, |
Laxman Dewangan | c8f5af2 | 2012-06-13 15:42:38 +0530 | [diff] [blame] | 553 | struct i2c_msg *msg, enum msg_end_type end_state) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 554 | { |
| 555 | u32 packet_header; |
| 556 | u32 int_mask; |
Nicholas Mc Guire | 6973a39 | 2015-03-01 09:17:41 -0500 | [diff] [blame] | 557 | unsigned long time_left; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 558 | |
| 559 | tegra_i2c_flush_fifos(i2c_dev); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 560 | |
| 561 | if (msg->len == 0) |
| 562 | return -EINVAL; |
| 563 | |
| 564 | i2c_dev->msg_buf = msg->buf; |
| 565 | i2c_dev->msg_buf_remaining = msg->len; |
| 566 | i2c_dev->msg_err = I2C_ERR_NONE; |
| 567 | i2c_dev->msg_read = (msg->flags & I2C_M_RD); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 568 | reinit_completion(&i2c_dev->msg_complete); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 569 | |
| 570 | packet_header = (0 << PACKET_HEADER0_HEADER_SIZE_SHIFT) | |
| 571 | PACKET_HEADER0_PROTOCOL_I2C | |
| 572 | (i2c_dev->cont_id << PACKET_HEADER0_CONT_ID_SHIFT) | |
| 573 | (1 << PACKET_HEADER0_PACKET_ID_SHIFT); |
| 574 | i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); |
| 575 | |
| 576 | packet_header = msg->len - 1; |
| 577 | i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); |
| 578 | |
Laxman Dewangan | 353f56b | 2012-04-24 12:49:35 +0530 | [diff] [blame] | 579 | packet_header = I2C_HEADER_IE_ENABLE; |
Laxman Dewangan | c8f5af2 | 2012-06-13 15:42:38 +0530 | [diff] [blame] | 580 | if (end_state == MSG_END_CONTINUE) |
| 581 | packet_header |= I2C_HEADER_CONTINUE_XFER; |
| 582 | else if (end_state == MSG_END_REPEAT_START) |
Erik Gilling | 2078cf3 | 2011-04-25 15:32:26 -0600 | [diff] [blame] | 583 | packet_header |= I2C_HEADER_REPEAT_START; |
Laxman Dewangan | 353f56b | 2012-04-24 12:49:35 +0530 | [diff] [blame] | 584 | if (msg->flags & I2C_M_TEN) { |
| 585 | packet_header |= msg->addr; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 586 | packet_header |= I2C_HEADER_10BIT_ADDR; |
Laxman Dewangan | 353f56b | 2012-04-24 12:49:35 +0530 | [diff] [blame] | 587 | } else { |
| 588 | packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; |
| 589 | } |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 590 | if (msg->flags & I2C_M_IGNORE_NAK) |
| 591 | packet_header |= I2C_HEADER_CONT_ON_NAK; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 592 | if (msg->flags & I2C_M_RD) |
| 593 | packet_header |= I2C_HEADER_READ; |
| 594 | i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); |
| 595 | |
| 596 | if (!(msg->flags & I2C_M_RD)) |
| 597 | tegra_i2c_fill_tx_fifo(i2c_dev); |
| 598 | |
| 599 | int_mask = I2C_INT_NO_ACK | I2C_INT_ARBITRATION_LOST; |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 600 | if (i2c_dev->hw->has_per_pkt_xfer_complete_irq) |
| 601 | int_mask |= I2C_INT_PACKET_XFER_COMPLETE; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 602 | if (msg->flags & I2C_M_RD) |
| 603 | int_mask |= I2C_INT_RX_FIFO_DATA_REQ; |
| 604 | else if (i2c_dev->msg_buf_remaining) |
| 605 | int_mask |= I2C_INT_TX_FIFO_DATA_REQ; |
| 606 | tegra_i2c_unmask_irq(i2c_dev, int_mask); |
| 607 | dev_dbg(i2c_dev->dev, "unmasked irq: %02x\n", |
| 608 | i2c_readl(i2c_dev, I2C_INT_MASK)); |
| 609 | |
Nicholas Mc Guire | 6973a39 | 2015-03-01 09:17:41 -0500 | [diff] [blame] | 610 | time_left = wait_for_completion_timeout(&i2c_dev->msg_complete, |
| 611 | TEGRA_I2C_TIMEOUT); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 612 | tegra_i2c_mask_irq(i2c_dev, int_mask); |
| 613 | |
Nicholas Mc Guire | 6973a39 | 2015-03-01 09:17:41 -0500 | [diff] [blame] | 614 | if (time_left == 0) { |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 615 | dev_err(i2c_dev->dev, "i2c transfer timed out\n"); |
| 616 | |
| 617 | tegra_i2c_init(i2c_dev); |
| 618 | return -ETIMEDOUT; |
| 619 | } |
| 620 | |
Nicholas Mc Guire | 6973a39 | 2015-03-01 09:17:41 -0500 | [diff] [blame] | 621 | dev_dbg(i2c_dev->dev, "transfer complete: %lu %d %d\n", |
| 622 | time_left, completion_done(&i2c_dev->msg_complete), |
| 623 | i2c_dev->msg_err); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 624 | |
| 625 | if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) |
| 626 | return 0; |
| 627 | |
Alok Chauhan | f70893d0 | 2012-04-02 11:23:02 +0530 | [diff] [blame] | 628 | /* |
| 629 | * NACK interrupt is generated before the I2C controller generates the |
| 630 | * STOP condition on the bus. So wait for 2 clock periods before resetting |
| 631 | * the controller so that STOP condition has been delivered properly. |
| 632 | */ |
| 633 | if (i2c_dev->msg_err == I2C_ERR_NO_ACK) |
| 634 | udelay(DIV_ROUND_UP(2 * 1000000, i2c_dev->bus_clk_rate)); |
| 635 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 636 | tegra_i2c_init(i2c_dev); |
| 637 | if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { |
| 638 | if (msg->flags & I2C_M_IGNORE_NAK) |
| 639 | return 0; |
| 640 | return -EREMOTEIO; |
| 641 | } |
| 642 | |
| 643 | return -EIO; |
| 644 | } |
| 645 | |
| 646 | static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], |
| 647 | int num) |
| 648 | { |
| 649 | struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); |
| 650 | int i; |
| 651 | int ret = 0; |
| 652 | |
| 653 | if (i2c_dev->is_suspended) |
| 654 | return -EBUSY; |
| 655 | |
Laxman Dewangan | 132c803 | 2013-03-15 05:34:08 +0000 | [diff] [blame] | 656 | ret = tegra_i2c_clock_enable(i2c_dev); |
| 657 | if (ret < 0) { |
| 658 | dev_err(i2c_dev->dev, "Clock enable failed %d\n", ret); |
| 659 | return ret; |
| 660 | } |
| 661 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 662 | for (i = 0; i < num; i++) { |
Laxman Dewangan | c8f5af2 | 2012-06-13 15:42:38 +0530 | [diff] [blame] | 663 | enum msg_end_type end_type = MSG_END_STOP; |
| 664 | if (i < (num - 1)) { |
| 665 | if (msgs[i + 1].flags & I2C_M_NOSTART) |
| 666 | end_type = MSG_END_CONTINUE; |
| 667 | else |
| 668 | end_type = MSG_END_REPEAT_START; |
| 669 | } |
| 670 | ret = tegra_i2c_xfer_msg(i2c_dev, &msgs[i], end_type); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 671 | if (ret) |
| 672 | break; |
| 673 | } |
Laxman Dewangan | fd301cc | 2012-08-19 00:47:47 +0530 | [diff] [blame] | 674 | tegra_i2c_clock_disable(i2c_dev); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 675 | return ret ?: i; |
| 676 | } |
| 677 | |
| 678 | static u32 tegra_i2c_func(struct i2c_adapter *adap) |
| 679 | { |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 680 | struct tegra_i2c_dev *i2c_dev = i2c_get_adapdata(adap); |
Wolfram Sang | 4bb28e3 | 2015-06-16 19:47:21 +0200 | [diff] [blame] | 681 | u32 ret = I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK) | |
| 682 | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 683 | |
| 684 | if (i2c_dev->hw->has_continue_xfer_support) |
| 685 | ret |= I2C_FUNC_NOSTART; |
| 686 | return ret; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static const struct i2c_algorithm tegra_i2c_algo = { |
| 690 | .master_xfer = tegra_i2c_xfer, |
| 691 | .functionality = tegra_i2c_func, |
| 692 | }; |
| 693 | |
Wolfram Sang | 3aaa34b | 2015-06-16 19:57:29 +0200 | [diff] [blame] | 694 | /* payload size is only 12 bit */ |
| 695 | static struct i2c_adapter_quirks tegra_i2c_quirks = { |
| 696 | .max_read_len = 4096, |
| 697 | .max_write_len = 4096, |
| 698 | }; |
| 699 | |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 700 | static const struct tegra_i2c_hw_feature tegra20_i2c_hw = { |
| 701 | .has_continue_xfer_support = false, |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 702 | .has_per_pkt_xfer_complete_irq = false, |
| 703 | .has_single_clk_source = false, |
| 704 | .clk_divisor_hs_mode = 3, |
| 705 | .clk_divisor_std_fast_mode = 0, |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 706 | .has_config_load_reg = false, |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | static const struct tegra_i2c_hw_feature tegra30_i2c_hw = { |
| 710 | .has_continue_xfer_support = true, |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 711 | .has_per_pkt_xfer_complete_irq = false, |
| 712 | .has_single_clk_source = false, |
| 713 | .clk_divisor_hs_mode = 3, |
| 714 | .clk_divisor_std_fast_mode = 0, |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 715 | .has_config_load_reg = false, |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 716 | }; |
| 717 | |
| 718 | static const struct tegra_i2c_hw_feature tegra114_i2c_hw = { |
| 719 | .has_continue_xfer_support = true, |
| 720 | .has_per_pkt_xfer_complete_irq = true, |
| 721 | .has_single_clk_source = true, |
| 722 | .clk_divisor_hs_mode = 1, |
| 723 | .clk_divisor_std_fast_mode = 0x19, |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 724 | .has_config_load_reg = false, |
| 725 | }; |
| 726 | |
| 727 | static const struct tegra_i2c_hw_feature tegra124_i2c_hw = { |
| 728 | .has_continue_xfer_support = true, |
| 729 | .has_per_pkt_xfer_complete_irq = true, |
| 730 | .has_single_clk_source = true, |
| 731 | .clk_divisor_hs_mode = 1, |
| 732 | .clk_divisor_std_fast_mode = 0x19, |
| 733 | .has_config_load_reg = true, |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 734 | }; |
| 735 | |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 736 | /* Match table for of_platform binding */ |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 737 | static const struct of_device_id tegra_i2c_of_match[] = { |
Laxman Dewangan | 6f4664b | 2015-06-30 16:24:26 +0530 | [diff] [blame^] | 738 | { .compatible = "nvidia,tegra124-i2c", .data = &tegra124_i2c_hw, }, |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 739 | { .compatible = "nvidia,tegra114-i2c", .data = &tegra114_i2c_hw, }, |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 740 | { .compatible = "nvidia,tegra30-i2c", .data = &tegra30_i2c_hw, }, |
| 741 | { .compatible = "nvidia,tegra20-i2c", .data = &tegra20_i2c_hw, }, |
| 742 | { .compatible = "nvidia,tegra20-i2c-dvc", .data = &tegra20_i2c_hw, }, |
| 743 | {}, |
| 744 | }; |
| 745 | MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 746 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 747 | static int tegra_i2c_probe(struct platform_device *pdev) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 748 | { |
| 749 | struct tegra_i2c_dev *i2c_dev; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 750 | struct resource *res; |
Laxman Dewangan | 14e92bd | 2012-08-08 13:21:32 +0530 | [diff] [blame] | 751 | struct clk *div_clk; |
| 752 | struct clk *fast_clk; |
Olof Johansson | f533c61 | 2011-10-12 17:33:00 -0700 | [diff] [blame] | 753 | void __iomem *base; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 754 | int irq; |
| 755 | int ret = 0; |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 756 | int clk_multiplier = I2C_CLK_MULTIPLIER_STD_FAST_MODE; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 757 | |
| 758 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 84dbf80 | 2013-01-21 11:09:03 +0100 | [diff] [blame] | 759 | base = devm_ioremap_resource(&pdev->dev, res); |
| 760 | if (IS_ERR(base)) |
| 761 | return PTR_ERR(base); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 762 | |
| 763 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 764 | if (!res) { |
| 765 | dev_err(&pdev->dev, "no irq resource\n"); |
Laxman Dewangan | 9cbb6b2 | 2012-06-13 15:42:39 +0530 | [diff] [blame] | 766 | return -EINVAL; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 767 | } |
| 768 | irq = res->start; |
| 769 | |
Laxman Dewangan | 14e92bd | 2012-08-08 13:21:32 +0530 | [diff] [blame] | 770 | div_clk = devm_clk_get(&pdev->dev, "div-clk"); |
| 771 | if (IS_ERR(div_clk)) { |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 772 | dev_err(&pdev->dev, "missing controller clock"); |
Laxman Dewangan | 14e92bd | 2012-08-08 13:21:32 +0530 | [diff] [blame] | 773 | return PTR_ERR(div_clk); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 774 | } |
| 775 | |
Laxman Dewangan | 9cbb6b2 | 2012-06-13 15:42:39 +0530 | [diff] [blame] | 776 | i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); |
Jingoo Han | 46797a2 | 2014-05-13 10:51:58 +0900 | [diff] [blame] | 777 | if (!i2c_dev) |
Laxman Dewangan | 9cbb6b2 | 2012-06-13 15:42:39 +0530 | [diff] [blame] | 778 | return -ENOMEM; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 779 | |
| 780 | i2c_dev->base = base; |
Laxman Dewangan | 14e92bd | 2012-08-08 13:21:32 +0530 | [diff] [blame] | 781 | i2c_dev->div_clk = div_clk; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 782 | i2c_dev->adapter.algo = &tegra_i2c_algo; |
Wolfram Sang | 3aaa34b | 2015-06-16 19:57:29 +0200 | [diff] [blame] | 783 | i2c_dev->adapter.quirks = &tegra_i2c_quirks; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 784 | i2c_dev->irq = irq; |
| 785 | i2c_dev->cont_id = pdev->id; |
| 786 | i2c_dev->dev = &pdev->dev; |
John Bonesio | 5c470f3 | 2011-06-22 09:16:56 -0700 | [diff] [blame] | 787 | |
Stephen Warren | dda9d6a | 2013-11-06 16:42:05 -0700 | [diff] [blame] | 788 | i2c_dev->rst = devm_reset_control_get(&pdev->dev, "i2c"); |
| 789 | if (IS_ERR(i2c_dev->rst)) { |
| 790 | dev_err(&pdev->dev, "missing controller reset"); |
| 791 | return PTR_ERR(i2c_dev->rst); |
| 792 | } |
| 793 | |
Stephen Warren | 49a64ac | 2013-03-21 08:08:46 +0000 | [diff] [blame] | 794 | ret = of_property_read_u32(i2c_dev->dev->of_node, "clock-frequency", |
| 795 | &i2c_dev->bus_clk_rate); |
| 796 | if (ret) |
| 797 | i2c_dev->bus_clk_rate = 100000; /* default clock rate */ |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 798 | |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 799 | i2c_dev->hw = &tegra20_i2c_hw; |
| 800 | |
| 801 | if (pdev->dev.of_node) { |
| 802 | const struct of_device_id *match; |
Stephen Warren | 49a64ac | 2013-03-21 08:08:46 +0000 | [diff] [blame] | 803 | match = of_match_device(tegra_i2c_of_match, &pdev->dev); |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 804 | i2c_dev->hw = match->data; |
Stephen Warren | 68fb669 | 2011-12-17 23:29:30 -0700 | [diff] [blame] | 805 | i2c_dev->is_dvc = of_device_is_compatible(pdev->dev.of_node, |
| 806 | "nvidia,tegra20-i2c-dvc"); |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 807 | } else if (pdev->id == 3) { |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 808 | i2c_dev->is_dvc = 1; |
Laxman Dewangan | 6ad068e | 2012-08-19 00:47:46 +0530 | [diff] [blame] | 809 | } |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 810 | init_completion(&i2c_dev->msg_complete); |
| 811 | |
Laxman Dewangan | 2a2897b | 2013-01-05 17:34:46 +0530 | [diff] [blame] | 812 | if (!i2c_dev->hw->has_single_clk_source) { |
| 813 | fast_clk = devm_clk_get(&pdev->dev, "fast-clk"); |
| 814 | if (IS_ERR(fast_clk)) { |
| 815 | dev_err(&pdev->dev, "missing fast clock"); |
| 816 | return PTR_ERR(fast_clk); |
| 817 | } |
| 818 | i2c_dev->fast_clk = fast_clk; |
| 819 | } |
| 820 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 821 | platform_set_drvdata(pdev, i2c_dev); |
| 822 | |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 823 | if (!i2c_dev->hw->has_single_clk_source) { |
| 824 | ret = clk_prepare(i2c_dev->fast_clk); |
| 825 | if (ret < 0) { |
| 826 | dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); |
| 827 | return ret; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | clk_multiplier *= (i2c_dev->hw->clk_divisor_std_fast_mode + 1); |
| 832 | ret = clk_set_rate(i2c_dev->div_clk, |
| 833 | i2c_dev->bus_clk_rate * clk_multiplier); |
| 834 | if (ret) { |
| 835 | dev_err(i2c_dev->dev, "Clock rate change failed %d\n", ret); |
| 836 | goto unprepare_fast_clk; |
| 837 | } |
| 838 | |
| 839 | ret = clk_prepare(i2c_dev->div_clk); |
| 840 | if (ret < 0) { |
| 841 | dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret); |
| 842 | goto unprepare_fast_clk; |
| 843 | } |
| 844 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 845 | ret = tegra_i2c_init(i2c_dev); |
| 846 | if (ret) { |
| 847 | dev_err(&pdev->dev, "Failed to initialize i2c controller"); |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 848 | goto unprepare_div_clk; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 849 | } |
| 850 | |
Laxman Dewangan | 9cbb6b2 | 2012-06-13 15:42:39 +0530 | [diff] [blame] | 851 | ret = devm_request_irq(&pdev->dev, i2c_dev->irq, |
Laxman Dewangan | 91b370a | 2012-11-01 22:08:14 +0530 | [diff] [blame] | 852 | tegra_i2c_isr, 0, dev_name(&pdev->dev), i2c_dev); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 853 | if (ret) { |
| 854 | dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 855 | goto unprepare_div_clk; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 858 | i2c_set_adapdata(&i2c_dev->adapter, i2c_dev); |
| 859 | i2c_dev->adapter.owner = THIS_MODULE; |
Wolfram Sang | 6025189 | 2014-07-10 13:46:35 +0200 | [diff] [blame] | 860 | i2c_dev->adapter.class = I2C_CLASS_DEPRECATED; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 861 | strlcpy(i2c_dev->adapter.name, "Tegra I2C adapter", |
| 862 | sizeof(i2c_dev->adapter.name)); |
| 863 | i2c_dev->adapter.algo = &tegra_i2c_algo; |
| 864 | i2c_dev->adapter.dev.parent = &pdev->dev; |
| 865 | i2c_dev->adapter.nr = pdev->id; |
John Bonesio | 5c470f3 | 2011-06-22 09:16:56 -0700 | [diff] [blame] | 866 | i2c_dev->adapter.dev.of_node = pdev->dev.of_node; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 867 | |
| 868 | ret = i2c_add_numbered_adapter(&i2c_dev->adapter); |
| 869 | if (ret) { |
| 870 | dev_err(&pdev->dev, "Failed to add I2C adapter\n"); |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 871 | goto unprepare_div_clk; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 872 | } |
| 873 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 874 | return 0; |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 875 | |
| 876 | unprepare_div_clk: |
| 877 | clk_unprepare(i2c_dev->div_clk); |
| 878 | |
| 879 | unprepare_fast_clk: |
| 880 | if (!i2c_dev->hw->has_single_clk_source) |
| 881 | clk_unprepare(i2c_dev->fast_clk); |
| 882 | |
| 883 | return ret; |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 884 | } |
| 885 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 886 | static int tegra_i2c_remove(struct platform_device *pdev) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 887 | { |
| 888 | struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); |
| 889 | i2c_del_adapter(&i2c_dev->adapter); |
Mikko Perttunen | c9a9ef4 | 2014-09-05 12:28:18 +0300 | [diff] [blame] | 890 | |
| 891 | clk_unprepare(i2c_dev->div_clk); |
| 892 | if (!i2c_dev->hw->has_single_clk_source) |
| 893 | clk_unprepare(i2c_dev->fast_clk); |
| 894 | |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 895 | return 0; |
| 896 | } |
| 897 | |
Laxman Dewangan | 371e67c | 2012-08-18 17:49:58 +0530 | [diff] [blame] | 898 | #ifdef CONFIG_PM_SLEEP |
Wolfram Sang | 5db20c4 | 2012-07-24 17:32:45 +0200 | [diff] [blame] | 899 | static int tegra_i2c_suspend(struct device *dev) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 900 | { |
Rafael J. Wysocki | 6a7b3c3 | 2012-07-11 21:27:30 +0200 | [diff] [blame] | 901 | struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 902 | |
| 903 | i2c_lock_adapter(&i2c_dev->adapter); |
| 904 | i2c_dev->is_suspended = true; |
| 905 | i2c_unlock_adapter(&i2c_dev->adapter); |
| 906 | |
| 907 | return 0; |
| 908 | } |
| 909 | |
Wolfram Sang | 5db20c4 | 2012-07-24 17:32:45 +0200 | [diff] [blame] | 910 | static int tegra_i2c_resume(struct device *dev) |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 911 | { |
Rafael J. Wysocki | 6a7b3c3 | 2012-07-11 21:27:30 +0200 | [diff] [blame] | 912 | struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev); |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 913 | int ret; |
| 914 | |
| 915 | i2c_lock_adapter(&i2c_dev->adapter); |
| 916 | |
| 917 | ret = tegra_i2c_init(i2c_dev); |
| 918 | |
| 919 | if (ret) { |
| 920 | i2c_unlock_adapter(&i2c_dev->adapter); |
| 921 | return ret; |
| 922 | } |
| 923 | |
| 924 | i2c_dev->is_suspended = false; |
| 925 | |
| 926 | i2c_unlock_adapter(&i2c_dev->adapter); |
| 927 | |
| 928 | return 0; |
| 929 | } |
Rafael J. Wysocki | 6a7b3c3 | 2012-07-11 21:27:30 +0200 | [diff] [blame] | 930 | |
Wolfram Sang | 5db20c4 | 2012-07-24 17:32:45 +0200 | [diff] [blame] | 931 | static SIMPLE_DEV_PM_OPS(tegra_i2c_pm, tegra_i2c_suspend, tegra_i2c_resume); |
Rafael J. Wysocki | 6a7b3c3 | 2012-07-11 21:27:30 +0200 | [diff] [blame] | 932 | #define TEGRA_I2C_PM (&tegra_i2c_pm) |
| 933 | #else |
| 934 | #define TEGRA_I2C_PM NULL |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 935 | #endif |
| 936 | |
| 937 | static struct platform_driver tegra_i2c_driver = { |
| 938 | .probe = tegra_i2c_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 939 | .remove = tegra_i2c_remove, |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 940 | .driver = { |
| 941 | .name = "tegra-i2c", |
Stephen Warren | 49a64ac | 2013-03-21 08:08:46 +0000 | [diff] [blame] | 942 | .of_match_table = tegra_i2c_of_match, |
Rafael J. Wysocki | 6a7b3c3 | 2012-07-11 21:27:30 +0200 | [diff] [blame] | 943 | .pm = TEGRA_I2C_PM, |
Colin Cross | db811ca | 2011-02-20 17:14:21 -0800 | [diff] [blame] | 944 | }, |
| 945 | }; |
| 946 | |
| 947 | static int __init tegra_i2c_init_driver(void) |
| 948 | { |
| 949 | return platform_driver_register(&tegra_i2c_driver); |
| 950 | } |
| 951 | |
| 952 | static void __exit tegra_i2c_exit_driver(void) |
| 953 | { |
| 954 | platform_driver_unregister(&tegra_i2c_driver); |
| 955 | } |
| 956 | |
| 957 | subsys_initcall(tegra_i2c_init_driver); |
| 958 | module_exit(tegra_i2c_exit_driver); |
| 959 | |
| 960 | MODULE_DESCRIPTION("nVidia Tegra2 I2C Bus Controller driver"); |
| 961 | MODULE_AUTHOR("Colin Cross"); |
| 962 | MODULE_LICENSE("GPL v2"); |