Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Tzachi Perelstein | a083279 | 2007-11-12 19:38:51 +0200 | [diff] [blame] | 2 | * Driver for the i2c controller on the Marvell line of host bridges |
| 3 | * (e.g, gt642[46]0, mv643[46]0, mv644[46]0, and Orion SoC family). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Author: Mark A. Greer <mgreer@mvista.com> |
| 6 | * |
| 7 | * 2005 (c) MontaVista, Software, Inc. This file is licensed under |
| 8 | * the terms of the GNU General Public License version 2. This program |
| 9 | * is licensed "as is" without any warranty of any kind, whether express |
| 10 | * or implied. |
| 11 | */ |
| 12 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/interrupt.h> |
Tzachi Perelstein | a083279 | 2007-11-12 19:38:51 +0200 | [diff] [blame] | 18 | #include <linux/mv643xx_i2c.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
H Hartley Sweeten | 2178218 | 2010-05-21 18:41:01 +0200 | [diff] [blame] | 20 | #include <linux/io.h> |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/of_irq.h> |
| 23 | #include <linux/of_i2c.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | /* Register defines */ |
| 28 | #define MV64XXX_I2C_REG_SLAVE_ADDR 0x00 |
| 29 | #define MV64XXX_I2C_REG_DATA 0x04 |
| 30 | #define MV64XXX_I2C_REG_CONTROL 0x08 |
| 31 | #define MV64XXX_I2C_REG_STATUS 0x0c |
| 32 | #define MV64XXX_I2C_REG_BAUD 0x0c |
| 33 | #define MV64XXX_I2C_REG_EXT_SLAVE_ADDR 0x10 |
| 34 | #define MV64XXX_I2C_REG_SOFT_RESET 0x1c |
| 35 | |
| 36 | #define MV64XXX_I2C_REG_CONTROL_ACK 0x00000004 |
| 37 | #define MV64XXX_I2C_REG_CONTROL_IFLG 0x00000008 |
| 38 | #define MV64XXX_I2C_REG_CONTROL_STOP 0x00000010 |
| 39 | #define MV64XXX_I2C_REG_CONTROL_START 0x00000020 |
| 40 | #define MV64XXX_I2C_REG_CONTROL_TWSIEN 0x00000040 |
| 41 | #define MV64XXX_I2C_REG_CONTROL_INTEN 0x00000080 |
| 42 | |
| 43 | /* Ctlr status values */ |
| 44 | #define MV64XXX_I2C_STATUS_BUS_ERR 0x00 |
| 45 | #define MV64XXX_I2C_STATUS_MAST_START 0x08 |
| 46 | #define MV64XXX_I2C_STATUS_MAST_REPEAT_START 0x10 |
| 47 | #define MV64XXX_I2C_STATUS_MAST_WR_ADDR_ACK 0x18 |
| 48 | #define MV64XXX_I2C_STATUS_MAST_WR_ADDR_NO_ACK 0x20 |
| 49 | #define MV64XXX_I2C_STATUS_MAST_WR_ACK 0x28 |
| 50 | #define MV64XXX_I2C_STATUS_MAST_WR_NO_ACK 0x30 |
| 51 | #define MV64XXX_I2C_STATUS_MAST_LOST_ARB 0x38 |
| 52 | #define MV64XXX_I2C_STATUS_MAST_RD_ADDR_ACK 0x40 |
| 53 | #define MV64XXX_I2C_STATUS_MAST_RD_ADDR_NO_ACK 0x48 |
| 54 | #define MV64XXX_I2C_STATUS_MAST_RD_DATA_ACK 0x50 |
| 55 | #define MV64XXX_I2C_STATUS_MAST_RD_DATA_NO_ACK 0x58 |
| 56 | #define MV64XXX_I2C_STATUS_MAST_WR_ADDR_2_ACK 0xd0 |
| 57 | #define MV64XXX_I2C_STATUS_MAST_WR_ADDR_2_NO_ACK 0xd8 |
| 58 | #define MV64XXX_I2C_STATUS_MAST_RD_ADDR_2_ACK 0xe0 |
| 59 | #define MV64XXX_I2C_STATUS_MAST_RD_ADDR_2_NO_ACK 0xe8 |
| 60 | #define MV64XXX_I2C_STATUS_NO_STATUS 0xf8 |
| 61 | |
| 62 | /* Driver states */ |
| 63 | enum { |
| 64 | MV64XXX_I2C_STATE_INVALID, |
| 65 | MV64XXX_I2C_STATE_IDLE, |
| 66 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND, |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 67 | MV64XXX_I2C_STATE_WAITING_FOR_RESTART, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK, |
| 69 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK, |
| 70 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK, |
| 71 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_DATA, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /* Driver actions */ |
| 75 | enum { |
| 76 | MV64XXX_I2C_ACTION_INVALID, |
| 77 | MV64XXX_I2C_ACTION_CONTINUE, |
| 78 | MV64XXX_I2C_ACTION_SEND_START, |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 79 | MV64XXX_I2C_ACTION_SEND_RESTART, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | MV64XXX_I2C_ACTION_SEND_ADDR_1, |
| 81 | MV64XXX_I2C_ACTION_SEND_ADDR_2, |
| 82 | MV64XXX_I2C_ACTION_SEND_DATA, |
| 83 | MV64XXX_I2C_ACTION_RCV_DATA, |
| 84 | MV64XXX_I2C_ACTION_RCV_DATA_STOP, |
| 85 | MV64XXX_I2C_ACTION_SEND_STOP, |
| 86 | }; |
| 87 | |
| 88 | struct mv64xxx_i2c_data { |
| 89 | int irq; |
| 90 | u32 state; |
| 91 | u32 action; |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 92 | u32 aborting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | u32 cntl_bits; |
| 94 | void __iomem *reg_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | u32 addr1; |
| 96 | u32 addr2; |
| 97 | u32 bytes_left; |
| 98 | u32 byte_posn; |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 99 | u32 send_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | u32 block; |
| 101 | int rc; |
| 102 | u32 freq_m; |
| 103 | u32 freq_n; |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 104 | #if defined(CONFIG_HAVE_CLK) |
| 105 | struct clk *clk; |
| 106 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | wait_queue_head_t waitq; |
| 108 | spinlock_t lock; |
| 109 | struct i2c_msg *msg; |
| 110 | struct i2c_adapter adapter; |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | ***************************************************************************** |
| 115 | * |
| 116 | * Finite State Machine & Interrupt Routines |
| 117 | * |
| 118 | ***************************************************************************** |
| 119 | */ |
Dale Farnsworth | a07ad1c | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 120 | |
| 121 | /* Reset hardware and initialize FSM */ |
| 122 | static void |
| 123 | mv64xxx_i2c_hw_init(struct mv64xxx_i2c_data *drv_data) |
| 124 | { |
| 125 | writel(0, drv_data->reg_base + MV64XXX_I2C_REG_SOFT_RESET); |
| 126 | writel((((drv_data->freq_m & 0xf) << 3) | (drv_data->freq_n & 0x7)), |
| 127 | drv_data->reg_base + MV64XXX_I2C_REG_BAUD); |
| 128 | writel(0, drv_data->reg_base + MV64XXX_I2C_REG_SLAVE_ADDR); |
| 129 | writel(0, drv_data->reg_base + MV64XXX_I2C_REG_EXT_SLAVE_ADDR); |
| 130 | writel(MV64XXX_I2C_REG_CONTROL_TWSIEN | MV64XXX_I2C_REG_CONTROL_STOP, |
| 131 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 132 | drv_data->state = MV64XXX_I2C_STATE_IDLE; |
| 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | static void |
| 136 | mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status) |
| 137 | { |
| 138 | /* |
| 139 | * If state is idle, then this is likely the remnants of an old |
| 140 | * operation that driver has given up on or the user has killed. |
| 141 | * If so, issue the stop condition and go to idle. |
| 142 | */ |
| 143 | if (drv_data->state == MV64XXX_I2C_STATE_IDLE) { |
| 144 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
| 145 | return; |
| 146 | } |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | /* The status from the ctlr [mostly] tells us what to do next */ |
| 149 | switch (status) { |
| 150 | /* Start condition interrupt */ |
| 151 | case MV64XXX_I2C_STATUS_MAST_START: /* 0x08 */ |
| 152 | case MV64XXX_I2C_STATUS_MAST_REPEAT_START: /* 0x10 */ |
| 153 | drv_data->action = MV64XXX_I2C_ACTION_SEND_ADDR_1; |
| 154 | drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK; |
| 155 | break; |
| 156 | |
| 157 | /* Performing a write */ |
| 158 | case MV64XXX_I2C_STATUS_MAST_WR_ADDR_ACK: /* 0x18 */ |
| 159 | if (drv_data->msg->flags & I2C_M_TEN) { |
| 160 | drv_data->action = MV64XXX_I2C_ACTION_SEND_ADDR_2; |
| 161 | drv_data->state = |
| 162 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK; |
| 163 | break; |
| 164 | } |
| 165 | /* FALLTHRU */ |
| 166 | case MV64XXX_I2C_STATUS_MAST_WR_ADDR_2_ACK: /* 0xd0 */ |
| 167 | case MV64XXX_I2C_STATUS_MAST_WR_ACK: /* 0x28 */ |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 168 | if ((drv_data->bytes_left == 0) |
| 169 | || (drv_data->aborting |
| 170 | && (drv_data->byte_posn != 0))) { |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 171 | if (drv_data->send_stop) { |
| 172 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
| 173 | drv_data->state = MV64XXX_I2C_STATE_IDLE; |
| 174 | } else { |
| 175 | drv_data->action = |
| 176 | MV64XXX_I2C_ACTION_SEND_RESTART; |
| 177 | drv_data->state = |
| 178 | MV64XXX_I2C_STATE_WAITING_FOR_RESTART; |
| 179 | } |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 180 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | drv_data->action = MV64XXX_I2C_ACTION_SEND_DATA; |
| 182 | drv_data->state = |
| 183 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK; |
| 184 | drv_data->bytes_left--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | break; |
| 187 | |
| 188 | /* Performing a read */ |
| 189 | case MV64XXX_I2C_STATUS_MAST_RD_ADDR_ACK: /* 40 */ |
| 190 | if (drv_data->msg->flags & I2C_M_TEN) { |
| 191 | drv_data->action = MV64XXX_I2C_ACTION_SEND_ADDR_2; |
| 192 | drv_data->state = |
| 193 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_2_ACK; |
| 194 | break; |
| 195 | } |
| 196 | /* FALLTHRU */ |
| 197 | case MV64XXX_I2C_STATUS_MAST_RD_ADDR_2_ACK: /* 0xe0 */ |
| 198 | if (drv_data->bytes_left == 0) { |
| 199 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
| 200 | drv_data->state = MV64XXX_I2C_STATE_IDLE; |
| 201 | break; |
| 202 | } |
| 203 | /* FALLTHRU */ |
| 204 | case MV64XXX_I2C_STATUS_MAST_RD_DATA_ACK: /* 0x50 */ |
| 205 | if (status != MV64XXX_I2C_STATUS_MAST_RD_DATA_ACK) |
| 206 | drv_data->action = MV64XXX_I2C_ACTION_CONTINUE; |
| 207 | else { |
| 208 | drv_data->action = MV64XXX_I2C_ACTION_RCV_DATA; |
| 209 | drv_data->bytes_left--; |
| 210 | } |
| 211 | drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_DATA; |
| 212 | |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 213 | if ((drv_data->bytes_left == 1) || drv_data->aborting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_ACK; |
| 215 | break; |
| 216 | |
| 217 | case MV64XXX_I2C_STATUS_MAST_RD_DATA_NO_ACK: /* 0x58 */ |
| 218 | drv_data->action = MV64XXX_I2C_ACTION_RCV_DATA_STOP; |
| 219 | drv_data->state = MV64XXX_I2C_STATE_IDLE; |
| 220 | break; |
| 221 | |
| 222 | case MV64XXX_I2C_STATUS_MAST_WR_ADDR_NO_ACK: /* 0x20 */ |
| 223 | case MV64XXX_I2C_STATUS_MAST_WR_NO_ACK: /* 30 */ |
| 224 | case MV64XXX_I2C_STATUS_MAST_RD_ADDR_NO_ACK: /* 48 */ |
| 225 | /* Doesn't seem to be a device at other end */ |
| 226 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
| 227 | drv_data->state = MV64XXX_I2C_STATE_IDLE; |
| 228 | drv_data->rc = -ENODEV; |
| 229 | break; |
| 230 | |
| 231 | default: |
| 232 | dev_err(&drv_data->adapter.dev, |
| 233 | "mv64xxx_i2c_fsm: Ctlr Error -- state: 0x%x, " |
| 234 | "status: 0x%x, addr: 0x%x, flags: 0x%x\n", |
| 235 | drv_data->state, status, drv_data->msg->addr, |
| 236 | drv_data->msg->flags); |
| 237 | drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; |
Dale Farnsworth | a07ad1c | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 238 | mv64xxx_i2c_hw_init(drv_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | drv_data->rc = -EIO; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | static void |
| 244 | mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) |
| 245 | { |
| 246 | switch(drv_data->action) { |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 247 | case MV64XXX_I2C_ACTION_SEND_RESTART: |
| 248 | drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START; |
| 249 | drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN; |
| 250 | writel(drv_data->cntl_bits, |
| 251 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 252 | drv_data->block = 0; |
Russell King | d295a86 | 2013-05-16 10:30:59 +0000 | [diff] [blame] | 253 | wake_up(&drv_data->waitq); |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 254 | break; |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | case MV64XXX_I2C_ACTION_CONTINUE: |
| 257 | writel(drv_data->cntl_bits, |
| 258 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 259 | break; |
| 260 | |
| 261 | case MV64XXX_I2C_ACTION_SEND_START: |
| 262 | writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START, |
| 263 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 264 | break; |
| 265 | |
| 266 | case MV64XXX_I2C_ACTION_SEND_ADDR_1: |
| 267 | writel(drv_data->addr1, |
| 268 | drv_data->reg_base + MV64XXX_I2C_REG_DATA); |
| 269 | writel(drv_data->cntl_bits, |
| 270 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 271 | break; |
| 272 | |
| 273 | case MV64XXX_I2C_ACTION_SEND_ADDR_2: |
| 274 | writel(drv_data->addr2, |
| 275 | drv_data->reg_base + MV64XXX_I2C_REG_DATA); |
| 276 | writel(drv_data->cntl_bits, |
| 277 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 278 | break; |
| 279 | |
| 280 | case MV64XXX_I2C_ACTION_SEND_DATA: |
| 281 | writel(drv_data->msg->buf[drv_data->byte_posn++], |
| 282 | drv_data->reg_base + MV64XXX_I2C_REG_DATA); |
| 283 | writel(drv_data->cntl_bits, |
| 284 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 285 | break; |
| 286 | |
| 287 | case MV64XXX_I2C_ACTION_RCV_DATA: |
| 288 | drv_data->msg->buf[drv_data->byte_posn++] = |
| 289 | readl(drv_data->reg_base + MV64XXX_I2C_REG_DATA); |
| 290 | writel(drv_data->cntl_bits, |
| 291 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 292 | break; |
| 293 | |
| 294 | case MV64XXX_I2C_ACTION_RCV_DATA_STOP: |
| 295 | drv_data->msg->buf[drv_data->byte_posn++] = |
| 296 | readl(drv_data->reg_base + MV64XXX_I2C_REG_DATA); |
| 297 | drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN; |
| 298 | writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_STOP, |
| 299 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 300 | drv_data->block = 0; |
Russell King | d295a86 | 2013-05-16 10:30:59 +0000 | [diff] [blame] | 301 | wake_up(&drv_data->waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | break; |
| 303 | |
| 304 | case MV64XXX_I2C_ACTION_INVALID: |
| 305 | default: |
| 306 | dev_err(&drv_data->adapter.dev, |
| 307 | "mv64xxx_i2c_do_action: Invalid action: %d\n", |
| 308 | drv_data->action); |
| 309 | drv_data->rc = -EIO; |
| 310 | /* FALLTHRU */ |
| 311 | case MV64XXX_I2C_ACTION_SEND_STOP: |
| 312 | drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN; |
| 313 | writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_STOP, |
| 314 | drv_data->reg_base + MV64XXX_I2C_REG_CONTROL); |
| 315 | drv_data->block = 0; |
Russell King | d295a86 | 2013-05-16 10:30:59 +0000 | [diff] [blame] | 316 | wake_up(&drv_data->waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
Mikael Pettersson | b0999cc | 2009-09-07 12:00:13 +0200 | [diff] [blame] | 321 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 322 | mv64xxx_i2c_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
| 324 | struct mv64xxx_i2c_data *drv_data = dev_id; |
| 325 | unsigned long flags; |
| 326 | u32 status; |
Mikael Pettersson | b0999cc | 2009-09-07 12:00:13 +0200 | [diff] [blame] | 327 | irqreturn_t rc = IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | spin_lock_irqsave(&drv_data->lock, flags); |
| 330 | while (readl(drv_data->reg_base + MV64XXX_I2C_REG_CONTROL) & |
| 331 | MV64XXX_I2C_REG_CONTROL_IFLG) { |
| 332 | status = readl(drv_data->reg_base + MV64XXX_I2C_REG_STATUS); |
| 333 | mv64xxx_i2c_fsm(drv_data, status); |
| 334 | mv64xxx_i2c_do_action(drv_data); |
| 335 | rc = IRQ_HANDLED; |
| 336 | } |
| 337 | spin_unlock_irqrestore(&drv_data->lock, flags); |
| 338 | |
| 339 | return rc; |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | ***************************************************************************** |
| 344 | * |
| 345 | * I2C Msg Execution Routines |
| 346 | * |
| 347 | ***************************************************************************** |
| 348 | */ |
| 349 | static void |
| 350 | mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data, |
| 351 | struct i2c_msg *msg) |
| 352 | { |
| 353 | u32 dir = 0; |
| 354 | |
| 355 | drv_data->msg = msg; |
| 356 | drv_data->byte_posn = 0; |
| 357 | drv_data->bytes_left = msg->len; |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 358 | drv_data->aborting = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | drv_data->rc = 0; |
| 360 | drv_data->cntl_bits = MV64XXX_I2C_REG_CONTROL_ACK | |
| 361 | MV64XXX_I2C_REG_CONTROL_INTEN | MV64XXX_I2C_REG_CONTROL_TWSIEN; |
| 362 | |
| 363 | if (msg->flags & I2C_M_RD) |
| 364 | dir = 1; |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (msg->flags & I2C_M_TEN) { |
| 367 | drv_data->addr1 = 0xf0 | (((u32)msg->addr & 0x300) >> 7) | dir; |
| 368 | drv_data->addr2 = (u32)msg->addr & 0xff; |
| 369 | } else { |
| 370 | drv_data->addr1 = ((u32)msg->addr & 0x7f) << 1 | dir; |
| 371 | drv_data->addr2 = 0; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | static void |
| 376 | mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data) |
| 377 | { |
| 378 | long time_left; |
| 379 | unsigned long flags; |
| 380 | char abort = 0; |
| 381 | |
Russell King | d295a86 | 2013-05-16 10:30:59 +0000 | [diff] [blame] | 382 | time_left = wait_event_timeout(drv_data->waitq, |
Jean Delvare | 8a52c6b | 2009-03-28 21:34:43 +0100 | [diff] [blame] | 383 | !drv_data->block, drv_data->adapter.timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
| 385 | spin_lock_irqsave(&drv_data->lock, flags); |
| 386 | if (!time_left) { /* Timed out */ |
| 387 | drv_data->rc = -ETIMEDOUT; |
| 388 | abort = 1; |
| 389 | } else if (time_left < 0) { /* Interrupted/Error */ |
| 390 | drv_data->rc = time_left; /* errno value */ |
| 391 | abort = 1; |
| 392 | } |
| 393 | |
| 394 | if (abort && drv_data->block) { |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 395 | drv_data->aborting = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | spin_unlock_irqrestore(&drv_data->lock, flags); |
| 397 | |
| 398 | time_left = wait_event_timeout(drv_data->waitq, |
Jean Delvare | 8a52c6b | 2009-03-28 21:34:43 +0100 | [diff] [blame] | 399 | !drv_data->block, drv_data->adapter.timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 401 | if ((time_left <= 0) && drv_data->block) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | drv_data->state = MV64XXX_I2C_STATE_IDLE; |
| 403 | dev_err(&drv_data->adapter.dev, |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 404 | "mv64xxx: I2C bus locked, block: %d, " |
| 405 | "time_left: %d\n", drv_data->block, |
| 406 | (int)time_left); |
Dale Farnsworth | a07ad1c | 2007-08-14 18:37:14 +0200 | [diff] [blame] | 407 | mv64xxx_i2c_hw_init(drv_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | } else |
| 410 | spin_unlock_irqrestore(&drv_data->lock, flags); |
| 411 | } |
| 412 | |
| 413 | static int |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 414 | mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg, |
| 415 | int is_first, int is_last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
| 417 | unsigned long flags; |
| 418 | |
| 419 | spin_lock_irqsave(&drv_data->lock, flags); |
| 420 | mv64xxx_i2c_prepare_for_io(drv_data, msg); |
| 421 | |
| 422 | if (unlikely(msg->flags & I2C_M_NOSTART)) { /* Skip start/addr phases */ |
| 423 | if (drv_data->msg->flags & I2C_M_RD) { |
| 424 | /* No action to do, wait for slave to send a byte */ |
| 425 | drv_data->action = MV64XXX_I2C_ACTION_CONTINUE; |
| 426 | drv_data->state = |
| 427 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_DATA; |
| 428 | } else { |
| 429 | drv_data->action = MV64XXX_I2C_ACTION_SEND_DATA; |
| 430 | drv_data->state = |
| 431 | MV64XXX_I2C_STATE_WAITING_FOR_SLAVE_ACK; |
| 432 | drv_data->bytes_left--; |
| 433 | } |
| 434 | } else { |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 435 | if (is_first) { |
| 436 | drv_data->action = MV64XXX_I2C_ACTION_SEND_START; |
| 437 | drv_data->state = |
| 438 | MV64XXX_I2C_STATE_WAITING_FOR_START_COND; |
| 439 | } else { |
| 440 | drv_data->action = MV64XXX_I2C_ACTION_SEND_ADDR_1; |
| 441 | drv_data->state = |
| 442 | MV64XXX_I2C_STATE_WAITING_FOR_ADDR_1_ACK; |
| 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 446 | drv_data->send_stop = is_last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | drv_data->block = 1; |
| 448 | mv64xxx_i2c_do_action(drv_data); |
| 449 | spin_unlock_irqrestore(&drv_data->lock, flags); |
| 450 | |
| 451 | mv64xxx_i2c_wait_for_completion(drv_data); |
| 452 | return drv_data->rc; |
| 453 | } |
| 454 | |
| 455 | /* |
| 456 | ***************************************************************************** |
| 457 | * |
| 458 | * I2C Core Support Routines (Interface to higher level I2C code) |
| 459 | * |
| 460 | ***************************************************************************** |
| 461 | */ |
| 462 | static u32 |
| 463 | mv64xxx_i2c_functionality(struct i2c_adapter *adap) |
| 464 | { |
| 465 | return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SMBUS_EMUL; |
| 466 | } |
| 467 | |
| 468 | static int |
| 469 | mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) |
| 470 | { |
| 471 | struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); |
Jean Delvare | d1b2f0a | 2005-09-02 21:25:47 +0200 | [diff] [blame] | 472 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 474 | for (i = 0; i < num; i++) { |
| 475 | rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i], |
| 476 | i == 0, i + 1 == num); |
| 477 | if (rc < 0) |
Jean Delvare | d1b2f0a | 2005-09-02 21:25:47 +0200 | [diff] [blame] | 478 | return rc; |
Rodolfo Giometti | eda6bee | 2010-11-26 17:06:56 +0100 | [diff] [blame] | 479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Jean Delvare | d1b2f0a | 2005-09-02 21:25:47 +0200 | [diff] [blame] | 481 | return num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Jean Delvare | 8f9082c | 2006-09-03 22:39:46 +0200 | [diff] [blame] | 484 | static const struct i2c_algorithm mv64xxx_i2c_algo = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | .master_xfer = mv64xxx_i2c_xfer, |
| 486 | .functionality = mv64xxx_i2c_functionality, |
| 487 | }; |
| 488 | |
| 489 | /* |
| 490 | ***************************************************************************** |
| 491 | * |
| 492 | * Driver Interface & Early Init Routines |
| 493 | * |
| 494 | ***************************************************************************** |
| 495 | */ |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 496 | #ifdef CONFIG_OF |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 497 | static int |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 498 | mv64xxx_calc_freq(const int tclk, const int n, const int m) |
| 499 | { |
| 500 | return tclk / (10 * (m + 1) * (2 << n)); |
| 501 | } |
| 502 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 503 | static bool |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 504 | mv64xxx_find_baud_factors(const u32 req_freq, const u32 tclk, u32 *best_n, |
| 505 | u32 *best_m) |
| 506 | { |
| 507 | int freq, delta, best_delta = INT_MAX; |
| 508 | int m, n; |
| 509 | |
| 510 | for (n = 0; n <= 7; n++) |
| 511 | for (m = 0; m <= 15; m++) { |
| 512 | freq = mv64xxx_calc_freq(tclk, n, m); |
| 513 | delta = req_freq - freq; |
| 514 | if (delta >= 0 && delta < best_delta) { |
| 515 | *best_m = m; |
| 516 | *best_n = n; |
| 517 | best_delta = delta; |
| 518 | } |
| 519 | if (best_delta == 0) |
| 520 | return true; |
| 521 | } |
| 522 | if (best_delta == INT_MAX) |
| 523 | return false; |
| 524 | return true; |
| 525 | } |
| 526 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 527 | static int |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 528 | mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, |
| 529 | struct device_node *np) |
| 530 | { |
| 531 | u32 bus_freq, tclk; |
| 532 | int rc = 0; |
| 533 | |
| 534 | /* CLK is mandatory when using DT to describe the i2c bus. We |
| 535 | * need to know tclk in order to calculate bus clock |
| 536 | * factors. |
| 537 | */ |
| 538 | #if !defined(CONFIG_HAVE_CLK) |
| 539 | /* Have OF but no CLK */ |
| 540 | return -ENODEV; |
| 541 | #else |
| 542 | if (IS_ERR(drv_data->clk)) { |
| 543 | rc = -ENODEV; |
| 544 | goto out; |
| 545 | } |
| 546 | tclk = clk_get_rate(drv_data->clk); |
| 547 | of_property_read_u32(np, "clock-frequency", &bus_freq); |
| 548 | if (!mv64xxx_find_baud_factors(bus_freq, tclk, |
| 549 | &drv_data->freq_n, &drv_data->freq_m)) { |
| 550 | rc = -EINVAL; |
| 551 | goto out; |
| 552 | } |
| 553 | drv_data->irq = irq_of_parse_and_map(np, 0); |
| 554 | |
| 555 | /* Its not yet defined how timeouts will be specified in device tree. |
| 556 | * So hard code the value to 1 second. |
| 557 | */ |
| 558 | drv_data->adapter.timeout = HZ; |
| 559 | out: |
| 560 | return rc; |
| 561 | #endif |
| 562 | } |
| 563 | #else /* CONFIG_OF */ |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 564 | static int |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 565 | mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data, |
| 566 | struct device_node *np) |
| 567 | { |
| 568 | return -ENODEV; |
| 569 | } |
| 570 | #endif /* CONFIG_OF */ |
| 571 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 572 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 573 | mv64xxx_i2c_probe(struct platform_device *pd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | struct mv64xxx_i2c_data *drv_data; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 576 | struct mv64xxx_i2c_pdata *pdata = pd->dev.platform_data; |
Russell King | 16874b0 | 2013-05-16 21:33:09 +0100 | [diff] [blame] | 577 | struct resource *r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | int rc; |
| 579 | |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 580 | if ((!pdata && !pd->dev.of_node)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | return -ENODEV; |
| 582 | |
Russell King | 2c91110 | 2013-05-16 21:35:10 +0100 | [diff] [blame^] | 583 | drv_data = devm_kzalloc(&pd->dev, sizeof(struct mv64xxx_i2c_data), |
| 584 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (!drv_data) |
| 586 | return -ENOMEM; |
| 587 | |
Russell King | 16874b0 | 2013-05-16 21:33:09 +0100 | [diff] [blame] | 588 | r = platform_get_resource(pd, IORESOURCE_MEM, 0); |
| 589 | drv_data->reg_base = devm_ioremap_resource(&pd->dev, r); |
Russell King | 2c91110 | 2013-05-16 21:35:10 +0100 | [diff] [blame^] | 590 | if (IS_ERR(drv_data->reg_base)) |
| 591 | return PTR_ERR(drv_data->reg_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Mark A. Greer | e91c021 | 2005-12-18 17:22:01 +0100 | [diff] [blame] | 593 | strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter", |
David Brownell | 2096b95 | 2007-05-01 23:26:28 +0200 | [diff] [blame] | 594 | sizeof(drv_data->adapter.name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | init_waitqueue_head(&drv_data->waitq); |
| 597 | spin_lock_init(&drv_data->lock); |
| 598 | |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 599 | #if defined(CONFIG_HAVE_CLK) |
| 600 | /* Not all platforms have a clk */ |
Russell King | 4c5c95f | 2013-05-16 21:34:10 +0100 | [diff] [blame] | 601 | drv_data->clk = devm_clk_get(&pd->dev, NULL); |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 602 | if (!IS_ERR(drv_data->clk)) { |
| 603 | clk_prepare(drv_data->clk); |
| 604 | clk_enable(drv_data->clk); |
| 605 | } |
| 606 | #endif |
| 607 | if (pdata) { |
| 608 | drv_data->freq_m = pdata->freq_m; |
| 609 | drv_data->freq_n = pdata->freq_n; |
| 610 | drv_data->irq = platform_get_irq(pd, 0); |
| 611 | drv_data->adapter.timeout = msecs_to_jiffies(pdata->timeout); |
| 612 | } else if (pd->dev.of_node) { |
| 613 | rc = mv64xxx_of_config(drv_data, pd->dev.of_node); |
| 614 | if (rc) |
Russell King | 2c91110 | 2013-05-16 21:35:10 +0100 | [diff] [blame^] | 615 | goto exit_clk; |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 616 | } |
David Vrabel | 4894473 | 2006-01-19 17:56:29 +0000 | [diff] [blame] | 617 | if (drv_data->irq < 0) { |
| 618 | rc = -ENXIO; |
Russell King | 2c91110 | 2013-05-16 21:35:10 +0100 | [diff] [blame^] | 619 | goto exit_clk; |
David Vrabel | 4894473 | 2006-01-19 17:56:29 +0000 | [diff] [blame] | 620 | } |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 621 | |
Jean Delvare | 12a917f | 2007-02-13 22:09:03 +0100 | [diff] [blame] | 622 | drv_data->adapter.dev.parent = &pd->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | drv_data->adapter.algo = &mv64xxx_i2c_algo; |
| 624 | drv_data->adapter.owner = THIS_MODULE; |
Jean Delvare | 3401b2f | 2008-07-14 22:38:29 +0200 | [diff] [blame] | 625 | drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
Dale Farnsworth | 65b22ad | 2007-07-12 14:12:29 +0200 | [diff] [blame] | 626 | drv_data->adapter.nr = pd->id; |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 627 | drv_data->adapter.dev.of_node = pd->dev.of_node; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 628 | platform_set_drvdata(pd, drv_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | i2c_set_adapdata(&drv_data->adapter, drv_data); |
| 630 | |
Maxime Bizon | 3269bb6 | 2007-01-05 17:54:05 +0100 | [diff] [blame] | 631 | mv64xxx_i2c_hw_init(drv_data); |
| 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | if (request_irq(drv_data->irq, mv64xxx_i2c_intr, 0, |
Mark A. Greer | dfded4a | 2005-12-16 11:08:43 -0800 | [diff] [blame] | 634 | MV64XXX_I2C_CTLR_NAME, drv_data)) { |
| 635 | dev_err(&drv_data->adapter.dev, |
| 636 | "mv64xxx: Can't register intr handler irq: %d\n", |
| 637 | drv_data->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | rc = -EINVAL; |
Russell King | 2c91110 | 2013-05-16 21:35:10 +0100 | [diff] [blame^] | 639 | goto exit_clk; |
Dale Farnsworth | 65b22ad | 2007-07-12 14:12:29 +0200 | [diff] [blame] | 640 | } else if ((rc = i2c_add_numbered_adapter(&drv_data->adapter)) != 0) { |
Mark A. Greer | dfded4a | 2005-12-16 11:08:43 -0800 | [diff] [blame] | 641 | dev_err(&drv_data->adapter.dev, |
| 642 | "mv64xxx: Can't add i2c adapter, rc: %d\n", -rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | goto exit_free_irq; |
| 644 | } |
| 645 | |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 646 | of_i2c_register_devices(&drv_data->adapter); |
| 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | return 0; |
| 649 | |
Russell King | 2c91110 | 2013-05-16 21:35:10 +0100 | [diff] [blame^] | 650 | exit_free_irq: |
| 651 | free_irq(drv_data->irq, drv_data); |
| 652 | exit_clk: |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 653 | #if defined(CONFIG_HAVE_CLK) |
| 654 | /* Not all platforms have a clk */ |
| 655 | if (!IS_ERR(drv_data->clk)) { |
| 656 | clk_disable(drv_data->clk); |
| 657 | clk_unprepare(drv_data->clk); |
| 658 | } |
| 659 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | return rc; |
| 661 | } |
| 662 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 663 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 664 | mv64xxx_i2c_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 666 | struct mv64xxx_i2c_data *drv_data = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 668 | i2c_del_adapter(&drv_data->adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | free_irq(drv_data->irq, drv_data); |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 670 | #if defined(CONFIG_HAVE_CLK) |
| 671 | /* Not all platforms have a clk */ |
| 672 | if (!IS_ERR(drv_data->clk)) { |
| 673 | clk_disable(drv_data->clk); |
| 674 | clk_unprepare(drv_data->clk); |
| 675 | } |
| 676 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 678 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 681 | static const struct of_device_id mv64xxx_i2c_of_match_table[] = { |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 682 | { .compatible = "marvell,mv64xxx-i2c", }, |
| 683 | {} |
| 684 | }; |
| 685 | MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table); |
| 686 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 687 | static struct platform_driver mv64xxx_i2c_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | .probe = mv64xxx_i2c_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 689 | .remove = mv64xxx_i2c_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 690 | .driver = { |
| 691 | .owner = THIS_MODULE, |
| 692 | .name = MV64XXX_I2C_CTLR_NAME, |
Andrew Lunn | b61d157 | 2012-07-22 12:51:35 +0200 | [diff] [blame] | 693 | .of_match_table = of_match_ptr(mv64xxx_i2c_of_match_table), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 694 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | }; |
| 696 | |
Axel Lin | a3664b5 | 2012-01-12 20:32:04 +0100 | [diff] [blame] | 697 | module_platform_driver(mv64xxx_i2c_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | MODULE_AUTHOR("Mark A. Greer <mgreer@mvista.com>"); |
| 700 | MODULE_DESCRIPTION("Marvell mv64xxx host bridge i2c ctlr driver"); |
| 701 | MODULE_LICENSE("GPL"); |