Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Synopsys Designware I2C adapter driver (master only). |
| 3 | * |
| 4 | * Based on the TI DAVINCI I2C adapter driver. |
| 5 | * |
| 6 | * Copyright (C) 2006 Texas Instruments. |
| 7 | * Copyright (C) 2007 MontaVista Software Inc. |
| 8 | * Copyright (C) 2009 Provigent Ltd. |
| 9 | * |
| 10 | * ---------------------------------------------------------------------------- |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * ---------------------------------------------------------------------------- |
| 26 | * |
| 27 | */ |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/i2c.h> |
| 32 | #include <linux/clk.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/sched.h> |
| 35 | #include <linux/err.h> |
| 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/platform_device.h> |
| 38 | #include <linux/io.h> |
| 39 | |
| 40 | /* |
| 41 | * Registers offset |
| 42 | */ |
| 43 | #define DW_IC_CON 0x0 |
| 44 | #define DW_IC_TAR 0x4 |
| 45 | #define DW_IC_DATA_CMD 0x10 |
| 46 | #define DW_IC_SS_SCL_HCNT 0x14 |
| 47 | #define DW_IC_SS_SCL_LCNT 0x18 |
| 48 | #define DW_IC_FS_SCL_HCNT 0x1c |
| 49 | #define DW_IC_FS_SCL_LCNT 0x20 |
| 50 | #define DW_IC_INTR_STAT 0x2c |
| 51 | #define DW_IC_INTR_MASK 0x30 |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 52 | #define DW_IC_RAW_INTR_STAT 0x34 |
Shinya Kuribayashi | 4cb6d1d | 2009-11-06 21:48:12 +0900 | [diff] [blame] | 53 | #define DW_IC_RX_TL 0x38 |
| 54 | #define DW_IC_TX_TL 0x3c |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 55 | #define DW_IC_CLR_INTR 0x40 |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 56 | #define DW_IC_CLR_RX_UNDER 0x44 |
| 57 | #define DW_IC_CLR_RX_OVER 0x48 |
| 58 | #define DW_IC_CLR_TX_OVER 0x4c |
| 59 | #define DW_IC_CLR_RD_REQ 0x50 |
| 60 | #define DW_IC_CLR_TX_ABRT 0x54 |
| 61 | #define DW_IC_CLR_RX_DONE 0x58 |
| 62 | #define DW_IC_CLR_ACTIVITY 0x5c |
| 63 | #define DW_IC_CLR_STOP_DET 0x60 |
| 64 | #define DW_IC_CLR_START_DET 0x64 |
| 65 | #define DW_IC_CLR_GEN_CALL 0x68 |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 66 | #define DW_IC_ENABLE 0x6c |
| 67 | #define DW_IC_STATUS 0x70 |
| 68 | #define DW_IC_TXFLR 0x74 |
| 69 | #define DW_IC_RXFLR 0x78 |
| 70 | #define DW_IC_COMP_PARAM_1 0xf4 |
| 71 | #define DW_IC_TX_ABRT_SOURCE 0x80 |
| 72 | |
| 73 | #define DW_IC_CON_MASTER 0x1 |
| 74 | #define DW_IC_CON_SPEED_STD 0x2 |
| 75 | #define DW_IC_CON_SPEED_FAST 0x4 |
| 76 | #define DW_IC_CON_10BITADDR_MASTER 0x10 |
| 77 | #define DW_IC_CON_RESTART_EN 0x20 |
| 78 | #define DW_IC_CON_SLAVE_DISABLE 0x40 |
| 79 | |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 80 | #define DW_IC_INTR_RX_UNDER 0x001 |
| 81 | #define DW_IC_INTR_RX_OVER 0x002 |
| 82 | #define DW_IC_INTR_RX_FULL 0x004 |
| 83 | #define DW_IC_INTR_TX_OVER 0x008 |
| 84 | #define DW_IC_INTR_TX_EMPTY 0x010 |
| 85 | #define DW_IC_INTR_RD_REQ 0x020 |
| 86 | #define DW_IC_INTR_TX_ABRT 0x040 |
| 87 | #define DW_IC_INTR_RX_DONE 0x080 |
| 88 | #define DW_IC_INTR_ACTIVITY 0x100 |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 89 | #define DW_IC_INTR_STOP_DET 0x200 |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 90 | #define DW_IC_INTR_START_DET 0x400 |
| 91 | #define DW_IC_INTR_GEN_CALL 0x800 |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 92 | |
| 93 | #define DW_IC_STATUS_ACTIVITY 0x1 |
| 94 | |
| 95 | #define DW_IC_ERR_TX_ABRT 0x1 |
| 96 | |
| 97 | /* |
| 98 | * status codes |
| 99 | */ |
| 100 | #define STATUS_IDLE 0x0 |
| 101 | #define STATUS_WRITE_IN_PROGRESS 0x1 |
| 102 | #define STATUS_READ_IN_PROGRESS 0x2 |
| 103 | |
| 104 | #define TIMEOUT 20 /* ms */ |
| 105 | |
| 106 | /* |
| 107 | * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register |
| 108 | * |
| 109 | * only expected abort codes are listed here |
| 110 | * refer to the datasheet for the full list |
| 111 | */ |
| 112 | #define ABRT_7B_ADDR_NOACK 0 |
| 113 | #define ABRT_10ADDR1_NOACK 1 |
| 114 | #define ABRT_10ADDR2_NOACK 2 |
| 115 | #define ABRT_TXDATA_NOACK 3 |
| 116 | #define ABRT_GCALL_NOACK 4 |
| 117 | #define ABRT_GCALL_READ 5 |
| 118 | #define ABRT_SBYTE_ACKDET 7 |
| 119 | #define ABRT_SBYTE_NORSTRT 9 |
| 120 | #define ABRT_10B_RD_NORSTRT 10 |
| 121 | #define ARB_MASTER_DIS 11 |
| 122 | #define ARB_LOST 12 |
| 123 | |
| 124 | static char *abort_sources[] = { |
| 125 | [ABRT_7B_ADDR_NOACK] = |
| 126 | "slave address not acknowledged (7bit mode)", |
| 127 | [ABRT_10ADDR1_NOACK] = |
| 128 | "first address byte not acknowledged (10bit mode)", |
| 129 | [ABRT_10ADDR2_NOACK] = |
| 130 | "second address byte not acknowledged (10bit mode)", |
| 131 | [ABRT_TXDATA_NOACK] = |
| 132 | "data not acknowledged", |
| 133 | [ABRT_GCALL_NOACK] = |
| 134 | "no acknowledgement for a general call", |
| 135 | [ABRT_GCALL_READ] = |
| 136 | "read after general call", |
| 137 | [ABRT_SBYTE_ACKDET] = |
| 138 | "start byte acknowledged", |
| 139 | [ABRT_SBYTE_NORSTRT] = |
| 140 | "trying to send start byte when restart is disabled", |
| 141 | [ABRT_10B_RD_NORSTRT] = |
| 142 | "trying to read when restart is disabled (10bit mode)", |
| 143 | [ARB_MASTER_DIS] = |
| 144 | "trying to use disabled adapter", |
| 145 | [ARB_LOST] = |
| 146 | "lost arbitration", |
| 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * struct dw_i2c_dev - private i2c-designware data |
| 151 | * @dev: driver model device node |
| 152 | * @base: IO registers pointer |
| 153 | * @cmd_complete: tx completion indicator |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 154 | * @lock: protect this struct and IO registers |
| 155 | * @clk: input reference clock |
| 156 | * @cmd_err: run time hadware error code |
| 157 | * @msgs: points to an array of messages currently being transfered |
| 158 | * @msgs_num: the number of elements in msgs |
| 159 | * @msg_write_idx: the element index of the current tx message in the msgs |
| 160 | * array |
| 161 | * @tx_buf_len: the length of the current tx buffer |
| 162 | * @tx_buf: the current tx buffer |
| 163 | * @msg_read_idx: the element index of the current rx message in the msgs |
| 164 | * array |
| 165 | * @rx_buf_len: the length of the current rx buffer |
| 166 | * @rx_buf: the current rx buffer |
| 167 | * @msg_err: error status of the current transfer |
| 168 | * @status: i2c master status, one of STATUS_* |
| 169 | * @abort_source: copy of the TX_ABRT_SOURCE register |
| 170 | * @irq: interrupt number for the i2c master |
| 171 | * @adapter: i2c subsystem adapter node |
| 172 | * @tx_fifo_depth: depth of the hardware tx fifo |
| 173 | * @rx_fifo_depth: depth of the hardware rx fifo |
| 174 | */ |
| 175 | struct dw_i2c_dev { |
| 176 | struct device *dev; |
| 177 | void __iomem *base; |
| 178 | struct completion cmd_complete; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 179 | struct mutex lock; |
| 180 | struct clk *clk; |
| 181 | int cmd_err; |
| 182 | struct i2c_msg *msgs; |
| 183 | int msgs_num; |
| 184 | int msg_write_idx; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 185 | u32 tx_buf_len; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 186 | u8 *tx_buf; |
| 187 | int msg_read_idx; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 188 | u32 rx_buf_len; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 189 | u8 *rx_buf; |
| 190 | int msg_err; |
| 191 | unsigned int status; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 192 | u32 abort_source; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 193 | int irq; |
| 194 | struct i2c_adapter adapter; |
| 195 | unsigned int tx_fifo_depth; |
| 196 | unsigned int rx_fifo_depth; |
| 197 | }; |
| 198 | |
Shinya Kuribayashi | d60c7e8 | 2009-11-06 21:47:01 +0900 | [diff] [blame] | 199 | static u32 |
| 200 | i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) |
| 201 | { |
| 202 | /* |
| 203 | * DesignWare I2C core doesn't seem to have solid strategy to meet |
| 204 | * the tHD;STA timing spec. Configuring _HCNT based on tHIGH spec |
| 205 | * will result in violation of the tHD;STA spec. |
| 206 | */ |
| 207 | if (cond) |
| 208 | /* |
| 209 | * Conditional expression: |
| 210 | * |
| 211 | * IC_[FS]S_SCL_HCNT + (1+4+3) >= IC_CLK * tHIGH |
| 212 | * |
| 213 | * This is based on the DW manuals, and represents an ideal |
| 214 | * configuration. The resulting I2C bus speed will be |
| 215 | * faster than any of the others. |
| 216 | * |
| 217 | * If your hardware is free from tHD;STA issue, try this one. |
| 218 | */ |
| 219 | return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset; |
| 220 | else |
| 221 | /* |
| 222 | * Conditional expression: |
| 223 | * |
| 224 | * IC_[FS]S_SCL_HCNT + 3 >= IC_CLK * (tHD;STA + tf) |
| 225 | * |
| 226 | * This is just experimental rule; the tHD;STA period turned |
| 227 | * out to be proportinal to (_HCNT + 3). With this setting, |
| 228 | * we could meet both tHIGH and tHD;STA timing specs. |
| 229 | * |
| 230 | * If unsure, you'd better to take this alternative. |
| 231 | * |
| 232 | * The reason why we need to take into account "tf" here, |
| 233 | * is the same as described in i2c_dw_scl_lcnt(). |
| 234 | */ |
| 235 | return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset; |
| 236 | } |
| 237 | |
| 238 | static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) |
| 239 | { |
| 240 | /* |
| 241 | * Conditional expression: |
| 242 | * |
| 243 | * IC_[FS]S_SCL_LCNT + 1 >= IC_CLK * (tLOW + tf) |
| 244 | * |
| 245 | * DW I2C core starts counting the SCL CNTs for the LOW period |
| 246 | * of the SCL clock (tLOW) as soon as it pulls the SCL line. |
| 247 | * In order to meet the tLOW timing spec, we need to take into |
| 248 | * account the fall time of SCL signal (tf). Default tf value |
| 249 | * should be 0.3 us, for safety. |
| 250 | */ |
| 251 | return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; |
| 252 | } |
| 253 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 254 | /** |
| 255 | * i2c_dw_init() - initialize the designware i2c master hardware |
| 256 | * @dev: device private data |
| 257 | * |
| 258 | * This functions configures and enables the I2C master. |
| 259 | * This function is called during I2C init function, and in case of timeout at |
| 260 | * run time. |
| 261 | */ |
| 262 | static void i2c_dw_init(struct dw_i2c_dev *dev) |
| 263 | { |
| 264 | u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; |
Shinya Kuribayashi | d60c7e8 | 2009-11-06 21:47:01 +0900 | [diff] [blame] | 265 | u32 ic_con, hcnt, lcnt; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 266 | |
| 267 | /* Disable the adapter */ |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 268 | writel(0, dev->base + DW_IC_ENABLE); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 269 | |
| 270 | /* set standard and fast speed deviders for high/low periods */ |
Shinya Kuribayashi | d60c7e8 | 2009-11-06 21:47:01 +0900 | [diff] [blame] | 271 | |
| 272 | /* Standard-mode */ |
| 273 | hcnt = i2c_dw_scl_hcnt(input_clock_khz, |
| 274 | 40, /* tHD;STA = tHIGH = 4.0 us */ |
| 275 | 3, /* tf = 0.3 us */ |
| 276 | 0, /* 0: DW default, 1: Ideal */ |
| 277 | 0); /* No offset */ |
| 278 | lcnt = i2c_dw_scl_lcnt(input_clock_khz, |
| 279 | 47, /* tLOW = 4.7 us */ |
| 280 | 3, /* tf = 0.3 us */ |
| 281 | 0); /* No offset */ |
| 282 | writel(hcnt, dev->base + DW_IC_SS_SCL_HCNT); |
| 283 | writel(lcnt, dev->base + DW_IC_SS_SCL_LCNT); |
| 284 | dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); |
| 285 | |
| 286 | /* Fast-mode */ |
| 287 | hcnt = i2c_dw_scl_hcnt(input_clock_khz, |
| 288 | 6, /* tHD;STA = tHIGH = 0.6 us */ |
| 289 | 3, /* tf = 0.3 us */ |
| 290 | 0, /* 0: DW default, 1: Ideal */ |
| 291 | 0); /* No offset */ |
| 292 | lcnt = i2c_dw_scl_lcnt(input_clock_khz, |
| 293 | 13, /* tLOW = 1.3 us */ |
| 294 | 3, /* tf = 0.3 us */ |
| 295 | 0); /* No offset */ |
| 296 | writel(hcnt, dev->base + DW_IC_FS_SCL_HCNT); |
| 297 | writel(lcnt, dev->base + DW_IC_FS_SCL_LCNT); |
| 298 | dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 299 | |
Shinya Kuribayashi | 4cb6d1d | 2009-11-06 21:48:12 +0900 | [diff] [blame] | 300 | /* Configure Tx/Rx FIFO threshold levels */ |
| 301 | writel(dev->tx_fifo_depth - 1, dev->base + DW_IC_TX_TL); |
| 302 | writel(0, dev->base + DW_IC_RX_TL); |
| 303 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 304 | /* configure the i2c master */ |
| 305 | ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | |
| 306 | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 307 | writel(ic_con, dev->base + DW_IC_CON); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Waiting for bus not busy |
| 312 | */ |
| 313 | static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) |
| 314 | { |
| 315 | int timeout = TIMEOUT; |
| 316 | |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 317 | while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 318 | if (timeout <= 0) { |
| 319 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); |
| 320 | return -ETIMEDOUT; |
| 321 | } |
| 322 | timeout--; |
| 323 | mdelay(1); |
| 324 | } |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Shinya Kuribayashi | 81e798b | 2009-11-06 21:48:55 +0900 | [diff] [blame] | 329 | static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) |
| 330 | { |
| 331 | struct i2c_msg *msgs = dev->msgs; |
| 332 | u32 ic_con; |
| 333 | |
| 334 | /* Disable the adapter */ |
| 335 | writel(0, dev->base + DW_IC_ENABLE); |
| 336 | |
| 337 | /* set the slave (target) address */ |
| 338 | writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR); |
| 339 | |
| 340 | /* if the slave address is ten bit address, enable 10BITADDR */ |
| 341 | ic_con = readl(dev->base + DW_IC_CON); |
| 342 | if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) |
| 343 | ic_con |= DW_IC_CON_10BITADDR_MASTER; |
| 344 | else |
| 345 | ic_con &= ~DW_IC_CON_10BITADDR_MASTER; |
| 346 | writel(ic_con, dev->base + DW_IC_CON); |
| 347 | |
| 348 | /* Enable the adapter */ |
| 349 | writel(1, dev->base + DW_IC_ENABLE); |
| 350 | } |
| 351 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 352 | /* |
| 353 | * Initiate low level master read/write transaction. |
| 354 | * This function is called from i2c_dw_xfer when starting a transfer. |
Shinya Kuribayashi | 0774539 | 2009-11-06 21:47:51 +0900 | [diff] [blame] | 355 | * This function is also called from i2c_dw_isr to continue a transfer |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 356 | * that is longer than the size of the TX FIFO. |
| 357 | */ |
| 358 | static void |
Shinya Kuribayashi | e77cf23 | 2009-11-06 21:46:04 +0900 | [diff] [blame] | 359 | i2c_dw_xfer_msg(struct dw_i2c_dev *dev) |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 360 | { |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 361 | struct i2c_msg *msgs = dev->msgs; |
Shinya Kuribayashi | 81e798b | 2009-11-06 21:48:55 +0900 | [diff] [blame] | 362 | u32 intr_mask; |
Shinya Kuribayashi | ae72222 | 2009-11-06 21:49:39 +0900 | [diff] [blame] | 363 | int tx_limit, rx_limit; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 364 | u32 addr = msgs[dev->msg_write_idx].addr; |
| 365 | u32 buf_len = dev->tx_buf_len; |
Shinya Kuribayashi | 26ea15b | 2009-11-06 21:49:14 +0900 | [diff] [blame] | 366 | u8 *buf = dev->tx_buf;; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 367 | |
Shinya Kuribayashi | 21a89d4 | 2009-11-06 21:48:33 +0900 | [diff] [blame] | 368 | intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT | DW_IC_INTR_RX_FULL; |
Shinya Kuribayashi | c70c5cd | 2009-11-06 21:47:30 +0900 | [diff] [blame] | 369 | |
Shinya Kuribayashi | 6d2ea48 | 2009-11-06 21:46:29 +0900 | [diff] [blame] | 370 | for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) { |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 371 | /* if target address has changed, we need to |
| 372 | * reprogram the target address in the i2c |
| 373 | * adapter when we are done with this transfer |
| 374 | */ |
| 375 | if (msgs[dev->msg_write_idx].addr != addr) |
| 376 | return; |
| 377 | |
| 378 | if (msgs[dev->msg_write_idx].len == 0) { |
| 379 | dev_err(dev->dev, |
| 380 | "%s: invalid message length\n", __func__); |
| 381 | dev->msg_err = -EINVAL; |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { |
| 386 | /* new i2c_msg */ |
Shinya Kuribayashi | 26ea15b | 2009-11-06 21:49:14 +0900 | [diff] [blame] | 387 | buf = msgs[dev->msg_write_idx].buf; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 388 | buf_len = msgs[dev->msg_write_idx].len; |
| 389 | } |
| 390 | |
Shinya Kuribayashi | ae72222 | 2009-11-06 21:49:39 +0900 | [diff] [blame] | 391 | tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR); |
| 392 | rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR); |
| 393 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 394 | while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { |
| 395 | if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 396 | writel(0x100, dev->base + DW_IC_DATA_CMD); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 397 | rx_limit--; |
| 398 | } else |
Shinya Kuribayashi | 26ea15b | 2009-11-06 21:49:14 +0900 | [diff] [blame] | 399 | writel(*buf++, dev->base + DW_IC_DATA_CMD); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 400 | tx_limit--; buf_len--; |
| 401 | } |
Shinya Kuribayashi | c70c5cd | 2009-11-06 21:47:30 +0900 | [diff] [blame] | 402 | |
Shinya Kuribayashi | 26ea15b | 2009-11-06 21:49:14 +0900 | [diff] [blame] | 403 | dev->tx_buf = buf; |
Shinya Kuribayashi | c70c5cd | 2009-11-06 21:47:30 +0900 | [diff] [blame] | 404 | dev->tx_buf_len = buf_len; |
| 405 | |
| 406 | if (buf_len > 0) { |
| 407 | /* more bytes to be written */ |
| 408 | intr_mask |= DW_IC_INTR_TX_EMPTY; |
| 409 | dev->status |= STATUS_WRITE_IN_PROGRESS; |
| 410 | break; |
| 411 | } else |
| 412 | dev->status &= ~STATUS_WRITE_IN_PROGRESS; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 413 | } |
| 414 | |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 415 | writel(intr_mask, dev->base + DW_IC_INTR_MASK); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static void |
Shinya Kuribayashi | 78839bd | 2009-11-06 21:45:39 +0900 | [diff] [blame] | 419 | i2c_dw_read(struct dw_i2c_dev *dev) |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 420 | { |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 421 | struct i2c_msg *msgs = dev->msgs; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 422 | u32 addr = msgs[dev->msg_read_idx].addr; |
Shinya Kuribayashi | ae72222 | 2009-11-06 21:49:39 +0900 | [diff] [blame] | 423 | int rx_valid; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 424 | |
Shinya Kuribayashi | 6d2ea48 | 2009-11-06 21:46:29 +0900 | [diff] [blame] | 425 | for (; dev->msg_read_idx < dev->msgs_num; dev->msg_read_idx++) { |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 426 | u32 len; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 427 | u8 *buf; |
| 428 | |
| 429 | if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) |
| 430 | continue; |
| 431 | |
| 432 | /* different i2c client, reprogram the i2c adapter */ |
| 433 | if (msgs[dev->msg_read_idx].addr != addr) |
| 434 | return; |
| 435 | |
| 436 | if (!(dev->status & STATUS_READ_IN_PROGRESS)) { |
| 437 | len = msgs[dev->msg_read_idx].len; |
| 438 | buf = msgs[dev->msg_read_idx].buf; |
| 439 | } else { |
| 440 | len = dev->rx_buf_len; |
| 441 | buf = dev->rx_buf; |
| 442 | } |
| 443 | |
Shinya Kuribayashi | ae72222 | 2009-11-06 21:49:39 +0900 | [diff] [blame] | 444 | rx_valid = readl(dev->base + DW_IC_RXFLR); |
| 445 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 446 | for (; len > 0 && rx_valid > 0; len--, rx_valid--) |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 447 | *buf++ = readl(dev->base + DW_IC_DATA_CMD); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 448 | |
| 449 | if (len > 0) { |
| 450 | dev->status |= STATUS_READ_IN_PROGRESS; |
| 451 | dev->rx_buf_len = len; |
| 452 | dev->rx_buf = buf; |
| 453 | return; |
| 454 | } else |
| 455 | dev->status &= ~STATUS_READ_IN_PROGRESS; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Prepare controller for a transaction and call i2c_dw_xfer_msg |
| 461 | */ |
| 462 | static int |
| 463 | i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) |
| 464 | { |
| 465 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); |
| 466 | int ret; |
| 467 | |
| 468 | dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); |
| 469 | |
| 470 | mutex_lock(&dev->lock); |
| 471 | |
| 472 | INIT_COMPLETION(dev->cmd_complete); |
| 473 | dev->msgs = msgs; |
| 474 | dev->msgs_num = num; |
| 475 | dev->cmd_err = 0; |
| 476 | dev->msg_write_idx = 0; |
| 477 | dev->msg_read_idx = 0; |
| 478 | dev->msg_err = 0; |
| 479 | dev->status = STATUS_IDLE; |
| 480 | |
| 481 | ret = i2c_dw_wait_bus_not_busy(dev); |
| 482 | if (ret < 0) |
| 483 | goto done; |
| 484 | |
| 485 | /* start the transfers */ |
Shinya Kuribayashi | 81e798b | 2009-11-06 21:48:55 +0900 | [diff] [blame] | 486 | i2c_dw_xfer_init(dev); |
Shinya Kuribayashi | e77cf23 | 2009-11-06 21:46:04 +0900 | [diff] [blame] | 487 | i2c_dw_xfer_msg(dev); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 488 | |
| 489 | /* wait for tx to complete */ |
| 490 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ); |
| 491 | if (ret == 0) { |
| 492 | dev_err(dev->dev, "controller timed out\n"); |
| 493 | i2c_dw_init(dev); |
| 494 | ret = -ETIMEDOUT; |
| 495 | goto done; |
| 496 | } else if (ret < 0) |
| 497 | goto done; |
| 498 | |
| 499 | if (dev->msg_err) { |
| 500 | ret = dev->msg_err; |
| 501 | goto done; |
| 502 | } |
| 503 | |
| 504 | /* no error */ |
| 505 | if (likely(!dev->cmd_err)) { |
Shinya Kuribayashi | 0774539 | 2009-11-06 21:47:51 +0900 | [diff] [blame] | 506 | /* Disable the adapter */ |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 507 | writel(0, dev->base + DW_IC_ENABLE); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 508 | ret = num; |
| 509 | goto done; |
| 510 | } |
| 511 | |
| 512 | /* We have an error */ |
| 513 | if (dev->cmd_err == DW_IC_ERR_TX_ABRT) { |
| 514 | unsigned long abort_source = dev->abort_source; |
| 515 | int i; |
| 516 | |
| 517 | for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) { |
| 518 | dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]); |
| 519 | } |
| 520 | } |
| 521 | ret = -EIO; |
| 522 | |
| 523 | done: |
| 524 | mutex_unlock(&dev->lock); |
| 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
| 529 | static u32 i2c_dw_func(struct i2c_adapter *adap) |
| 530 | { |
Shinya Kuribayashi | 52d7e43 | 2009-11-06 21:50:02 +0900 | [diff] [blame^] | 531 | return I2C_FUNC_I2C | |
| 532 | I2C_FUNC_10BIT_ADDR | |
| 533 | I2C_FUNC_SMBUS_BYTE | |
| 534 | I2C_FUNC_SMBUS_BYTE_DATA | |
| 535 | I2C_FUNC_SMBUS_WORD_DATA | |
| 536 | I2C_FUNC_SMBUS_I2C_BLOCK; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 537 | } |
| 538 | |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 539 | static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) |
| 540 | { |
| 541 | u32 stat; |
| 542 | |
| 543 | /* |
| 544 | * The IC_INTR_STAT register just indicates "enabled" interrupts. |
| 545 | * Ths unmasked raw version of interrupt status bits are available |
| 546 | * in the IC_RAW_INTR_STAT register. |
| 547 | * |
| 548 | * That is, |
| 549 | * stat = readl(IC_INTR_STAT); |
| 550 | * equals to, |
| 551 | * stat = readl(IC_RAW_INTR_STAT) & readl(IC_INTR_MASK); |
| 552 | * |
| 553 | * The raw version might be useful for debugging purposes. |
| 554 | */ |
| 555 | stat = readl(dev->base + DW_IC_INTR_STAT); |
| 556 | |
| 557 | /* |
| 558 | * Do not use the IC_CLR_INTR register to clear interrupts, or |
| 559 | * you'll miss some interrupts, triggered during the period from |
| 560 | * readl(IC_INTR_STAT) to readl(IC_CLR_INTR). |
| 561 | * |
| 562 | * Instead, use the separately-prepared IC_CLR_* registers. |
| 563 | */ |
| 564 | if (stat & DW_IC_INTR_RX_UNDER) |
| 565 | readl(dev->base + DW_IC_CLR_RX_UNDER); |
| 566 | if (stat & DW_IC_INTR_RX_OVER) |
| 567 | readl(dev->base + DW_IC_CLR_RX_OVER); |
| 568 | if (stat & DW_IC_INTR_TX_OVER) |
| 569 | readl(dev->base + DW_IC_CLR_TX_OVER); |
| 570 | if (stat & DW_IC_INTR_RD_REQ) |
| 571 | readl(dev->base + DW_IC_CLR_RD_REQ); |
| 572 | if (stat & DW_IC_INTR_TX_ABRT) { |
| 573 | /* |
| 574 | * The IC_TX_ABRT_SOURCE register is cleared whenever |
| 575 | * the IC_CLR_TX_ABRT is read. Preserve it beforehand. |
| 576 | */ |
| 577 | dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE); |
| 578 | readl(dev->base + DW_IC_CLR_TX_ABRT); |
| 579 | } |
| 580 | if (stat & DW_IC_INTR_RX_DONE) |
| 581 | readl(dev->base + DW_IC_CLR_RX_DONE); |
| 582 | if (stat & DW_IC_INTR_ACTIVITY) |
| 583 | readl(dev->base + DW_IC_CLR_ACTIVITY); |
| 584 | if (stat & DW_IC_INTR_STOP_DET) |
| 585 | readl(dev->base + DW_IC_CLR_STOP_DET); |
| 586 | if (stat & DW_IC_INTR_START_DET) |
| 587 | readl(dev->base + DW_IC_CLR_START_DET); |
| 588 | if (stat & DW_IC_INTR_GEN_CALL) |
| 589 | readl(dev->base + DW_IC_CLR_GEN_CALL); |
| 590 | |
| 591 | return stat; |
| 592 | } |
| 593 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 594 | /* |
| 595 | * Interrupt service routine. This gets called whenever an I2C interrupt |
| 596 | * occurs. |
| 597 | */ |
| 598 | static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) |
| 599 | { |
| 600 | struct dw_i2c_dev *dev = dev_id; |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 601 | u32 stat; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 602 | |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 603 | stat = i2c_dw_read_clear_intrbits(dev); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 604 | dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); |
Shinya Kuribayashi | e28000a | 2009-11-06 21:44:37 +0900 | [diff] [blame] | 605 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 606 | if (stat & DW_IC_INTR_TX_ABRT) { |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 607 | dev->cmd_err |= DW_IC_ERR_TX_ABRT; |
| 608 | dev->status = STATUS_IDLE; |
Shinya Kuribayashi | 0774539 | 2009-11-06 21:47:51 +0900 | [diff] [blame] | 609 | } |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 610 | |
Shinya Kuribayashi | 21a89d4 | 2009-11-06 21:48:33 +0900 | [diff] [blame] | 611 | if (stat & DW_IC_INTR_RX_FULL) |
Shinya Kuribayashi | 0774539 | 2009-11-06 21:47:51 +0900 | [diff] [blame] | 612 | i2c_dw_read(dev); |
Shinya Kuribayashi | 21a89d4 | 2009-11-06 21:48:33 +0900 | [diff] [blame] | 613 | |
| 614 | if (stat & DW_IC_INTR_TX_EMPTY) |
Shinya Kuribayashi | 0774539 | 2009-11-06 21:47:51 +0900 | [diff] [blame] | 615 | i2c_dw_xfer_msg(dev); |
Shinya Kuribayashi | 0774539 | 2009-11-06 21:47:51 +0900 | [diff] [blame] | 616 | |
| 617 | /* |
| 618 | * No need to modify or disable the interrupt mask here. |
| 619 | * i2c_dw_xfer_msg() will take care of it according to |
| 620 | * the current transmit status. |
| 621 | */ |
| 622 | |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 623 | if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) |
| 624 | complete(&dev->cmd_complete); |
| 625 | |
| 626 | return IRQ_HANDLED; |
| 627 | } |
| 628 | |
| 629 | static struct i2c_algorithm i2c_dw_algo = { |
| 630 | .master_xfer = i2c_dw_xfer, |
| 631 | .functionality = i2c_dw_func, |
| 632 | }; |
| 633 | |
| 634 | static int __devinit dw_i2c_probe(struct platform_device *pdev) |
| 635 | { |
| 636 | struct dw_i2c_dev *dev; |
| 637 | struct i2c_adapter *adap; |
Shinya Kuribayashi | 91b52ca | 2009-11-06 21:45:07 +0900 | [diff] [blame] | 638 | struct resource *mem, *ioarea; |
| 639 | int irq, r; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 640 | |
| 641 | /* NOTE: driver uses the static register mapping */ |
| 642 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 643 | if (!mem) { |
| 644 | dev_err(&pdev->dev, "no mem resource?\n"); |
| 645 | return -EINVAL; |
| 646 | } |
| 647 | |
Shinya Kuribayashi | 91b52ca | 2009-11-06 21:45:07 +0900 | [diff] [blame] | 648 | irq = platform_get_irq(pdev, 0); |
| 649 | if (irq < 0) { |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 650 | dev_err(&pdev->dev, "no irq resource?\n"); |
Shinya Kuribayashi | 91b52ca | 2009-11-06 21:45:07 +0900 | [diff] [blame] | 651 | return irq; /* -ENXIO */ |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | ioarea = request_mem_region(mem->start, resource_size(mem), |
| 655 | pdev->name); |
| 656 | if (!ioarea) { |
| 657 | dev_err(&pdev->dev, "I2C region already claimed\n"); |
| 658 | return -EBUSY; |
| 659 | } |
| 660 | |
| 661 | dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); |
| 662 | if (!dev) { |
| 663 | r = -ENOMEM; |
| 664 | goto err_release_region; |
| 665 | } |
| 666 | |
| 667 | init_completion(&dev->cmd_complete); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 668 | mutex_init(&dev->lock); |
| 669 | dev->dev = get_device(&pdev->dev); |
Shinya Kuribayashi | 91b52ca | 2009-11-06 21:45:07 +0900 | [diff] [blame] | 670 | dev->irq = irq; |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 671 | platform_set_drvdata(pdev, dev); |
| 672 | |
| 673 | dev->clk = clk_get(&pdev->dev, NULL); |
| 674 | if (IS_ERR(dev->clk)) { |
| 675 | r = -ENODEV; |
| 676 | goto err_free_mem; |
| 677 | } |
| 678 | clk_enable(dev->clk); |
| 679 | |
| 680 | dev->base = ioremap(mem->start, resource_size(mem)); |
| 681 | if (dev->base == NULL) { |
| 682 | dev_err(&pdev->dev, "failure mapping io resources\n"); |
| 683 | r = -EBUSY; |
| 684 | goto err_unuse_clocks; |
| 685 | } |
| 686 | { |
| 687 | u32 param1 = readl(dev->base + DW_IC_COMP_PARAM_1); |
| 688 | |
| 689 | dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; |
| 690 | dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; |
| 691 | } |
| 692 | i2c_dw_init(dev); |
| 693 | |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 694 | writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 695 | r = request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev); |
| 696 | if (r) { |
| 697 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); |
| 698 | goto err_iounmap; |
| 699 | } |
| 700 | |
| 701 | adap = &dev->adapter; |
| 702 | i2c_set_adapdata(adap, dev); |
| 703 | adap->owner = THIS_MODULE; |
| 704 | adap->class = I2C_CLASS_HWMON; |
| 705 | strlcpy(adap->name, "Synopsys DesignWare I2C adapter", |
| 706 | sizeof(adap->name)); |
| 707 | adap->algo = &i2c_dw_algo; |
| 708 | adap->dev.parent = &pdev->dev; |
| 709 | |
| 710 | adap->nr = pdev->id; |
| 711 | r = i2c_add_numbered_adapter(adap); |
| 712 | if (r) { |
| 713 | dev_err(&pdev->dev, "failure adding adapter\n"); |
| 714 | goto err_free_irq; |
| 715 | } |
| 716 | |
| 717 | return 0; |
| 718 | |
| 719 | err_free_irq: |
| 720 | free_irq(dev->irq, dev); |
| 721 | err_iounmap: |
| 722 | iounmap(dev->base); |
| 723 | err_unuse_clocks: |
| 724 | clk_disable(dev->clk); |
| 725 | clk_put(dev->clk); |
| 726 | dev->clk = NULL; |
| 727 | err_free_mem: |
| 728 | platform_set_drvdata(pdev, NULL); |
| 729 | put_device(&pdev->dev); |
| 730 | kfree(dev); |
| 731 | err_release_region: |
| 732 | release_mem_region(mem->start, resource_size(mem)); |
| 733 | |
| 734 | return r; |
| 735 | } |
| 736 | |
| 737 | static int __devexit dw_i2c_remove(struct platform_device *pdev) |
| 738 | { |
| 739 | struct dw_i2c_dev *dev = platform_get_drvdata(pdev); |
| 740 | struct resource *mem; |
| 741 | |
| 742 | platform_set_drvdata(pdev, NULL); |
| 743 | i2c_del_adapter(&dev->adapter); |
| 744 | put_device(&pdev->dev); |
| 745 | |
| 746 | clk_disable(dev->clk); |
| 747 | clk_put(dev->clk); |
| 748 | dev->clk = NULL; |
| 749 | |
Shinya Kuribayashi | ed5e1dd | 2009-11-06 21:43:52 +0900 | [diff] [blame] | 750 | writel(0, dev->base + DW_IC_ENABLE); |
Baruch Siach | 1ab52cf | 2009-06-22 16:36:29 +0300 | [diff] [blame] | 751 | free_irq(dev->irq, dev); |
| 752 | kfree(dev); |
| 753 | |
| 754 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 755 | release_mem_region(mem->start, resource_size(mem)); |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | /* work with hotplug and coldplug */ |
| 760 | MODULE_ALIAS("platform:i2c_designware"); |
| 761 | |
| 762 | static struct platform_driver dw_i2c_driver = { |
| 763 | .remove = __devexit_p(dw_i2c_remove), |
| 764 | .driver = { |
| 765 | .name = "i2c_designware", |
| 766 | .owner = THIS_MODULE, |
| 767 | }, |
| 768 | }; |
| 769 | |
| 770 | static int __init dw_i2c_init_driver(void) |
| 771 | { |
| 772 | return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe); |
| 773 | } |
| 774 | module_init(dw_i2c_init_driver); |
| 775 | |
| 776 | static void __exit dw_i2c_exit_driver(void) |
| 777 | { |
| 778 | platform_driver_unregister(&dw_i2c_driver); |
| 779 | } |
| 780 | module_exit(dw_i2c_exit_driver); |
| 781 | |
| 782 | MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); |
| 783 | MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter"); |
| 784 | MODULE_LICENSE("GPL"); |