srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1 | /* |
Linus Walleij | 1804edd | 2010-09-23 09:03:40 +0200 | [diff] [blame] | 2 | * Copyright (C) 2009 ST-Ericsson SA |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 3 | * Copyright (C) 2009 STMicroelectronics |
| 4 | * |
| 5 | * I2C master mode controller driver, used in Nomadik 8815 |
| 6 | * and Ux500 platforms. |
| 7 | * |
| 8 | * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com> |
| 9 | * Author: Sachin Verma <sachin.verma@st.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2, as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 17 | #include <linux/amba/bus.h> |
| 18 | #include <linux/atomic.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/i2c.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/clk.h> |
| 24 | #include <linux/io.h> |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 25 | #include <linux/regulator/consumer.h> |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
Alessandro Rubini | af97bac | 2012-06-11 22:56:26 +0200 | [diff] [blame] | 27 | #include <linux/platform_data/i2c-nomadik.h> |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 28 | |
| 29 | #define DRIVER_NAME "nmk-i2c" |
| 30 | |
| 31 | /* I2C Controller register offsets */ |
| 32 | #define I2C_CR (0x000) |
| 33 | #define I2C_SCR (0x004) |
| 34 | #define I2C_HSMCR (0x008) |
| 35 | #define I2C_MCR (0x00C) |
| 36 | #define I2C_TFR (0x010) |
| 37 | #define I2C_SR (0x014) |
| 38 | #define I2C_RFR (0x018) |
| 39 | #define I2C_TFTR (0x01C) |
| 40 | #define I2C_RFTR (0x020) |
| 41 | #define I2C_DMAR (0x024) |
| 42 | #define I2C_BRCR (0x028) |
| 43 | #define I2C_IMSCR (0x02C) |
| 44 | #define I2C_RISR (0x030) |
| 45 | #define I2C_MISR (0x034) |
| 46 | #define I2C_ICR (0x038) |
| 47 | |
| 48 | /* Control registers */ |
| 49 | #define I2C_CR_PE (0x1 << 0) /* Peripheral Enable */ |
| 50 | #define I2C_CR_OM (0x3 << 1) /* Operating mode */ |
| 51 | #define I2C_CR_SAM (0x1 << 3) /* Slave addressing mode */ |
| 52 | #define I2C_CR_SM (0x3 << 4) /* Speed mode */ |
| 53 | #define I2C_CR_SGCM (0x1 << 6) /* Slave general call mode */ |
| 54 | #define I2C_CR_FTX (0x1 << 7) /* Flush Transmit */ |
| 55 | #define I2C_CR_FRX (0x1 << 8) /* Flush Receive */ |
| 56 | #define I2C_CR_DMA_TX_EN (0x1 << 9) /* DMA Tx enable */ |
| 57 | #define I2C_CR_DMA_RX_EN (0x1 << 10) /* DMA Rx Enable */ |
| 58 | #define I2C_CR_DMA_SLE (0x1 << 11) /* DMA sync. logic enable */ |
| 59 | #define I2C_CR_LM (0x1 << 12) /* Loopback mode */ |
| 60 | #define I2C_CR_FON (0x3 << 13) /* Filtering on */ |
| 61 | #define I2C_CR_FS (0x3 << 15) /* Force stop enable */ |
| 62 | |
| 63 | /* Master controller (MCR) register */ |
| 64 | #define I2C_MCR_OP (0x1 << 0) /* Operation */ |
| 65 | #define I2C_MCR_A7 (0x7f << 1) /* 7-bit address */ |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 66 | #define I2C_MCR_EA10 (0x7 << 8) /* 10-bit Extended address */ |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 67 | #define I2C_MCR_SB (0x1 << 11) /* Extended address */ |
| 68 | #define I2C_MCR_AM (0x3 << 12) /* Address type */ |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 69 | #define I2C_MCR_STOP (0x1 << 14) /* Stop condition */ |
| 70 | #define I2C_MCR_LENGTH (0x7ff << 15) /* Transaction length */ |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 71 | |
| 72 | /* Status register (SR) */ |
| 73 | #define I2C_SR_OP (0x3 << 0) /* Operation */ |
| 74 | #define I2C_SR_STATUS (0x3 << 2) /* controller status */ |
| 75 | #define I2C_SR_CAUSE (0x7 << 4) /* Abort cause */ |
| 76 | #define I2C_SR_TYPE (0x3 << 7) /* Receive type */ |
| 77 | #define I2C_SR_LENGTH (0x7ff << 9) /* Transfer length */ |
| 78 | |
| 79 | /* Interrupt mask set/clear (IMSCR) bits */ |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 80 | #define I2C_IT_TXFE (0x1 << 0) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 81 | #define I2C_IT_TXFNE (0x1 << 1) |
| 82 | #define I2C_IT_TXFF (0x1 << 2) |
| 83 | #define I2C_IT_TXFOVR (0x1 << 3) |
| 84 | #define I2C_IT_RXFE (0x1 << 4) |
| 85 | #define I2C_IT_RXFNF (0x1 << 5) |
| 86 | #define I2C_IT_RXFF (0x1 << 6) |
| 87 | #define I2C_IT_RFSR (0x1 << 16) |
| 88 | #define I2C_IT_RFSE (0x1 << 17) |
| 89 | #define I2C_IT_WTSR (0x1 << 18) |
| 90 | #define I2C_IT_MTD (0x1 << 19) |
| 91 | #define I2C_IT_STD (0x1 << 20) |
| 92 | #define I2C_IT_MAL (0x1 << 24) |
| 93 | #define I2C_IT_BERR (0x1 << 25) |
| 94 | #define I2C_IT_MTDWS (0x1 << 28) |
| 95 | |
| 96 | #define GEN_MASK(val, mask, sb) (((val) << (sb)) & (mask)) |
| 97 | |
| 98 | /* some bits in ICR are reserved */ |
| 99 | #define I2C_CLEAR_ALL_INTS 0x131f007f |
| 100 | |
| 101 | /* first three msb bits are reserved */ |
| 102 | #define IRQ_MASK(mask) (mask & 0x1fffffff) |
| 103 | |
| 104 | /* maximum threshold value */ |
| 105 | #define MAX_I2C_FIFO_THRESHOLD 15 |
| 106 | |
| 107 | enum i2c_status { |
| 108 | I2C_NOP, |
| 109 | I2C_ON_GOING, |
| 110 | I2C_OK, |
| 111 | I2C_ABORT |
| 112 | }; |
| 113 | |
| 114 | /* operation */ |
| 115 | enum i2c_operation { |
| 116 | I2C_NO_OPERATION = 0xff, |
| 117 | I2C_WRITE = 0x00, |
| 118 | I2C_READ = 0x01 |
| 119 | }; |
| 120 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 121 | /** |
| 122 | * struct i2c_nmk_client - client specific data |
| 123 | * @slave_adr: 7-bit slave address |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 124 | * @count: no. bytes to be transferred |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 125 | * @buffer: client data buffer |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 126 | * @xfer_bytes: bytes transferred till now |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 127 | * @operation: current I2C operation |
| 128 | */ |
| 129 | struct i2c_nmk_client { |
| 130 | unsigned short slave_adr; |
| 131 | unsigned long count; |
| 132 | unsigned char *buffer; |
| 133 | unsigned long xfer_bytes; |
| 134 | enum i2c_operation operation; |
| 135 | }; |
| 136 | |
| 137 | /** |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 138 | * struct nmk_i2c_dev - private data structure of the controller. |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 139 | * @adev: parent amba device. |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 140 | * @adap: corresponding I2C adapter. |
| 141 | * @irq: interrupt line for the controller. |
| 142 | * @virtbase: virtual io memory area. |
| 143 | * @clk: hardware i2c block clock. |
| 144 | * @cfg: machine provided controller configuration. |
| 145 | * @cli: holder of client specific data. |
| 146 | * @stop: stop condition. |
| 147 | * @xfer_complete: acknowledge completion for a I2C message. |
| 148 | * @result: controller propogated result. |
| 149 | * @regulator: pointer to i2c regulator. |
| 150 | * @busy: Busy doing transfer. |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 151 | */ |
| 152 | struct nmk_i2c_dev { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 153 | struct amba_device *adev; |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 154 | struct i2c_adapter adap; |
| 155 | int irq; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 156 | void __iomem *virtbase; |
| 157 | struct clk *clk; |
| 158 | struct nmk_i2c_controller cfg; |
| 159 | struct i2c_nmk_client cli; |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 160 | int stop; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 161 | struct completion xfer_complete; |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 162 | int result; |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 163 | struct regulator *regulator; |
| 164 | bool busy; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | /* controller's abort causes */ |
| 168 | static const char *abort_causes[] = { |
| 169 | "no ack received after address transmission", |
| 170 | "no ack received during data phase", |
| 171 | "ack received after xmission of master code", |
| 172 | "master lost arbitration", |
| 173 | "slave restarts", |
| 174 | "slave reset", |
| 175 | "overflow, maxsize is 2047 bytes", |
| 176 | }; |
| 177 | |
| 178 | static inline void i2c_set_bit(void __iomem *reg, u32 mask) |
| 179 | { |
| 180 | writel(readl(reg) | mask, reg); |
| 181 | } |
| 182 | |
| 183 | static inline void i2c_clr_bit(void __iomem *reg, u32 mask) |
| 184 | { |
| 185 | writel(readl(reg) & ~mask, reg); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * flush_i2c_fifo() - This function flushes the I2C FIFO |
| 190 | * @dev: private data of I2C Driver |
| 191 | * |
| 192 | * This function flushes the I2C Tx and Rx FIFOs. It returns |
| 193 | * 0 on successful flushing of FIFO |
| 194 | */ |
| 195 | static int flush_i2c_fifo(struct nmk_i2c_dev *dev) |
| 196 | { |
| 197 | #define LOOP_ATTEMPTS 10 |
| 198 | int i; |
| 199 | unsigned long timeout; |
| 200 | |
| 201 | /* |
| 202 | * flush the transmit and receive FIFO. The flushing |
| 203 | * operation takes several cycles before to be completed. |
| 204 | * On the completion, the I2C internal logic clears these |
| 205 | * bits, until then no one must access Tx, Rx FIFO and |
| 206 | * should poll on these bits waiting for the completion. |
| 207 | */ |
| 208 | writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR); |
| 209 | |
| 210 | for (i = 0; i < LOOP_ATTEMPTS; i++) { |
Virupax Sadashivpetimath | cd20e4fa | 2011-05-13 12:29:46 +0200 | [diff] [blame] | 211 | timeout = jiffies + dev->adap.timeout; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 212 | |
| 213 | while (!time_after(jiffies, timeout)) { |
| 214 | if ((readl(dev->virtbase + I2C_CR) & |
| 215 | (I2C_CR_FTX | I2C_CR_FRX)) == 0) |
| 216 | return 0; |
| 217 | } |
| 218 | } |
| 219 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 220 | dev_err(&dev->adev->dev, |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 221 | "flushing operation timed out giving up after %d attempts", |
| 222 | LOOP_ATTEMPTS); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 223 | |
| 224 | return -ETIMEDOUT; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * disable_all_interrupts() - Disable all interrupts of this I2c Bus |
| 229 | * @dev: private data of I2C Driver |
| 230 | */ |
| 231 | static void disable_all_interrupts(struct nmk_i2c_dev *dev) |
| 232 | { |
| 233 | u32 mask = IRQ_MASK(0); |
| 234 | writel(mask, dev->virtbase + I2C_IMSCR); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * clear_all_interrupts() - Clear all interrupts of I2C Controller |
| 239 | * @dev: private data of I2C Driver |
| 240 | */ |
| 241 | static void clear_all_interrupts(struct nmk_i2c_dev *dev) |
| 242 | { |
| 243 | u32 mask; |
| 244 | mask = IRQ_MASK(I2C_CLEAR_ALL_INTS); |
| 245 | writel(mask, dev->virtbase + I2C_ICR); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * init_hw() - initialize the I2C hardware |
| 250 | * @dev: private data of I2C Driver |
| 251 | */ |
| 252 | static int init_hw(struct nmk_i2c_dev *dev) |
| 253 | { |
| 254 | int stat; |
| 255 | |
| 256 | stat = flush_i2c_fifo(dev); |
| 257 | if (stat) |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 258 | goto exit; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 259 | |
| 260 | /* disable the controller */ |
| 261 | i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE); |
| 262 | |
| 263 | disable_all_interrupts(dev); |
| 264 | |
| 265 | clear_all_interrupts(dev); |
| 266 | |
| 267 | dev->cli.operation = I2C_NO_OPERATION; |
| 268 | |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 269 | exit: |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 270 | return stat; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* enable peripheral, master mode operation */ |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 274 | #define DEFAULT_I2C_REG_CR ((1 << 1) | I2C_CR_PE) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * load_i2c_mcr_reg() - load the MCR register |
| 278 | * @dev: private data of controller |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 279 | * @flags: message flags |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 280 | */ |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 281 | static u32 load_i2c_mcr_reg(struct nmk_i2c_dev *dev, u16 flags) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 282 | { |
| 283 | u32 mcr = 0; |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 284 | unsigned short slave_adr_3msb_bits; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 285 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 286 | mcr |= GEN_MASK(dev->cli.slave_adr, I2C_MCR_A7, 1); |
| 287 | |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 288 | if (unlikely(flags & I2C_M_TEN)) { |
| 289 | /* 10-bit address transaction */ |
| 290 | mcr |= GEN_MASK(2, I2C_MCR_AM, 12); |
| 291 | /* |
| 292 | * Get the top 3 bits. |
| 293 | * EA10 represents extended address in MCR. This includes |
| 294 | * the extension (MSB bits) of the 7 bit address loaded |
| 295 | * in A7 |
| 296 | */ |
| 297 | slave_adr_3msb_bits = (dev->cli.slave_adr >> 7) & 0x7; |
| 298 | |
| 299 | mcr |= GEN_MASK(slave_adr_3msb_bits, I2C_MCR_EA10, 8); |
| 300 | } else { |
| 301 | /* 7-bit address transaction */ |
| 302 | mcr |= GEN_MASK(1, I2C_MCR_AM, 12); |
| 303 | } |
| 304 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 305 | /* start byte procedure not applied */ |
| 306 | mcr |= GEN_MASK(0, I2C_MCR_SB, 11); |
| 307 | |
| 308 | /* check the operation, master read/write? */ |
| 309 | if (dev->cli.operation == I2C_WRITE) |
| 310 | mcr |= GEN_MASK(I2C_WRITE, I2C_MCR_OP, 0); |
| 311 | else |
| 312 | mcr |= GEN_MASK(I2C_READ, I2C_MCR_OP, 0); |
| 313 | |
| 314 | /* stop or repeated start? */ |
| 315 | if (dev->stop) |
| 316 | mcr |= GEN_MASK(1, I2C_MCR_STOP, 14); |
| 317 | else |
| 318 | mcr &= ~(GEN_MASK(1, I2C_MCR_STOP, 14)); |
| 319 | |
| 320 | mcr |= GEN_MASK(dev->cli.count, I2C_MCR_LENGTH, 15); |
| 321 | |
| 322 | return mcr; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * setup_i2c_controller() - setup the controller |
| 327 | * @dev: private data of controller |
| 328 | */ |
| 329 | static void setup_i2c_controller(struct nmk_i2c_dev *dev) |
| 330 | { |
| 331 | u32 brcr1, brcr2; |
| 332 | u32 i2c_clk, div; |
| 333 | |
| 334 | writel(0x0, dev->virtbase + I2C_CR); |
| 335 | writel(0x0, dev->virtbase + I2C_HSMCR); |
| 336 | writel(0x0, dev->virtbase + I2C_TFTR); |
| 337 | writel(0x0, dev->virtbase + I2C_RFTR); |
| 338 | writel(0x0, dev->virtbase + I2C_DMAR); |
| 339 | |
| 340 | /* |
| 341 | * set the slsu: |
| 342 | * |
| 343 | * slsu defines the data setup time after SCL clock |
| 344 | * stretching in terms of i2c clk cycles. The |
| 345 | * needed setup time for the three modes are 250ns, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 346 | * 100ns, 10ns respectively thus leading to the values |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 347 | * of 14, 6, 2 for a 48 MHz i2c clk. |
| 348 | */ |
| 349 | writel(dev->cfg.slsu << 16, dev->virtbase + I2C_SCR); |
| 350 | |
| 351 | i2c_clk = clk_get_rate(dev->clk); |
| 352 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 353 | /* |
| 354 | * The spec says, in case of std. mode the divider is |
| 355 | * 2 whereas it is 3 for fast and fastplus mode of |
| 356 | * operation. TODO - high speed support. |
| 357 | */ |
| 358 | div = (dev->cfg.clk_freq > 100000) ? 3 : 2; |
| 359 | |
| 360 | /* |
| 361 | * generate the mask for baud rate counters. The controller |
| 362 | * has two baud rate counters. One is used for High speed |
| 363 | * operation, and the other is for std, fast mode, fast mode |
| 364 | * plus operation. Currently we do not supprt high speed mode |
| 365 | * so set brcr1 to 0. |
| 366 | */ |
| 367 | brcr1 = 0 << 16; |
| 368 | brcr2 = (i2c_clk/(dev->cfg.clk_freq * div)) & 0xffff; |
| 369 | |
| 370 | /* set the baud rate counter register */ |
| 371 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); |
| 372 | |
| 373 | /* |
| 374 | * set the speed mode. Currently we support |
| 375 | * only standard and fast mode of operation |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 376 | * TODO - support for fast mode plus (up to 1Mb/s) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 377 | * and high speed (up to 3.4 Mb/s) |
| 378 | */ |
| 379 | if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 380 | dev_err(&dev->adev->dev, |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 381 | "do not support this mode defaulting to std. mode\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 382 | brcr2 = i2c_clk/(100000 * 2) & 0xffff; |
| 383 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); |
| 384 | writel(I2C_FREQ_MODE_STANDARD << 4, |
| 385 | dev->virtbase + I2C_CR); |
| 386 | } |
| 387 | writel(dev->cfg.sm << 4, dev->virtbase + I2C_CR); |
| 388 | |
| 389 | /* set the Tx and Rx FIFO threshold */ |
| 390 | writel(dev->cfg.tft, dev->virtbase + I2C_TFTR); |
| 391 | writel(dev->cfg.rft, dev->virtbase + I2C_RFTR); |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * read_i2c() - Read from I2C client device |
| 396 | * @dev: private data of I2C Driver |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 397 | * @flags: message flags |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 398 | * |
| 399 | * This function reads from i2c client device when controller is in |
| 400 | * master mode. There is a completion timeout. If there is no transfer |
| 401 | * before timeout error is returned. |
| 402 | */ |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 403 | static int read_i2c(struct nmk_i2c_dev *dev, u16 flags) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 404 | { |
| 405 | u32 status = 0; |
| 406 | u32 mcr; |
| 407 | u32 irq_mask = 0; |
| 408 | int timeout; |
| 409 | |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 410 | mcr = load_i2c_mcr_reg(dev, flags); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 411 | writel(mcr, dev->virtbase + I2C_MCR); |
| 412 | |
| 413 | /* load the current CR value */ |
| 414 | writel(readl(dev->virtbase + I2C_CR) | DEFAULT_I2C_REG_CR, |
| 415 | dev->virtbase + I2C_CR); |
| 416 | |
| 417 | /* enable the controller */ |
| 418 | i2c_set_bit(dev->virtbase + I2C_CR, I2C_CR_PE); |
| 419 | |
| 420 | init_completion(&dev->xfer_complete); |
| 421 | |
| 422 | /* enable interrupts by setting the mask */ |
| 423 | irq_mask = (I2C_IT_RXFNF | I2C_IT_RXFF | |
| 424 | I2C_IT_MAL | I2C_IT_BERR); |
| 425 | |
| 426 | if (dev->stop) |
| 427 | irq_mask |= I2C_IT_MTD; |
| 428 | else |
| 429 | irq_mask |= I2C_IT_MTDWS; |
| 430 | |
| 431 | irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask); |
| 432 | |
| 433 | writel(readl(dev->virtbase + I2C_IMSCR) | irq_mask, |
| 434 | dev->virtbase + I2C_IMSCR); |
| 435 | |
srinidhi kasagar | 4b723a4 | 2011-08-09 20:17:22 +0200 | [diff] [blame] | 436 | timeout = wait_for_completion_timeout( |
Virupax Sadashivpetimath | cd20e4fa | 2011-05-13 12:29:46 +0200 | [diff] [blame] | 437 | &dev->xfer_complete, dev->adap.timeout); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 438 | |
| 439 | if (timeout < 0) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 440 | dev_err(&dev->adev->dev, |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 441 | "wait_for_completion_timeout " |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 442 | "returned %d waiting for event\n", timeout); |
| 443 | status = timeout; |
| 444 | } |
| 445 | |
| 446 | if (timeout == 0) { |
Virupax Sadashivpetimath | 0511f64 | 2011-05-13 12:30:53 +0200 | [diff] [blame] | 447 | /* Controller timed out */ |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 448 | dev_err(&dev->adev->dev, "read from slave 0x%x timed out\n", |
Virupax Sadashivpetimath | 4cb3f53 | 2011-05-13 12:29:55 +0200 | [diff] [blame] | 449 | dev->cli.slave_adr); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 450 | status = -ETIMEDOUT; |
| 451 | } |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 452 | return status; |
| 453 | } |
| 454 | |
Virupax Sadashivpetimath | 5535534 | 2011-05-13 12:30:34 +0200 | [diff] [blame] | 455 | static void fill_tx_fifo(struct nmk_i2c_dev *dev, int no_bytes) |
| 456 | { |
| 457 | int count; |
| 458 | |
| 459 | for (count = (no_bytes - 2); |
| 460 | (count > 0) && |
| 461 | (dev->cli.count != 0); |
| 462 | count--) { |
| 463 | /* write to the Tx FIFO */ |
| 464 | writeb(*dev->cli.buffer, |
| 465 | dev->virtbase + I2C_TFR); |
| 466 | dev->cli.buffer++; |
| 467 | dev->cli.count--; |
| 468 | dev->cli.xfer_bytes++; |
| 469 | } |
| 470 | |
| 471 | } |
| 472 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 473 | /** |
| 474 | * write_i2c() - Write data to I2C client. |
| 475 | * @dev: private data of I2C Driver |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 476 | * @flags: message flags |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 477 | * |
| 478 | * This function writes data to I2C client |
| 479 | */ |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 480 | static int write_i2c(struct nmk_i2c_dev *dev, u16 flags) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 481 | { |
| 482 | u32 status = 0; |
| 483 | u32 mcr; |
| 484 | u32 irq_mask = 0; |
| 485 | int timeout; |
| 486 | |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 487 | mcr = load_i2c_mcr_reg(dev, flags); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 488 | |
| 489 | writel(mcr, dev->virtbase + I2C_MCR); |
| 490 | |
| 491 | /* load the current CR value */ |
| 492 | writel(readl(dev->virtbase + I2C_CR) | DEFAULT_I2C_REG_CR, |
| 493 | dev->virtbase + I2C_CR); |
| 494 | |
| 495 | /* enable the controller */ |
| 496 | i2c_set_bit(dev->virtbase + I2C_CR , I2C_CR_PE); |
| 497 | |
| 498 | init_completion(&dev->xfer_complete); |
| 499 | |
| 500 | /* enable interrupts by settings the masks */ |
Virupax Sadashivpetimath | 5535534 | 2011-05-13 12:30:34 +0200 | [diff] [blame] | 501 | irq_mask = (I2C_IT_TXFOVR | I2C_IT_MAL | I2C_IT_BERR); |
| 502 | |
| 503 | /* Fill the TX FIFO with transmit data */ |
| 504 | fill_tx_fifo(dev, MAX_I2C_FIFO_THRESHOLD); |
| 505 | |
| 506 | if (dev->cli.count != 0) |
| 507 | irq_mask |= I2C_IT_TXFNE; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 508 | |
| 509 | /* |
| 510 | * check if we want to transfer a single or multiple bytes, if so |
| 511 | * set the MTDWS bit (Master Transaction Done Without Stop) |
| 512 | * to start repeated start operation |
| 513 | */ |
| 514 | if (dev->stop) |
| 515 | irq_mask |= I2C_IT_MTD; |
| 516 | else |
| 517 | irq_mask |= I2C_IT_MTDWS; |
| 518 | |
| 519 | irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask); |
| 520 | |
| 521 | writel(readl(dev->virtbase + I2C_IMSCR) | irq_mask, |
| 522 | dev->virtbase + I2C_IMSCR); |
| 523 | |
srinidhi kasagar | 4b723a4 | 2011-08-09 20:17:22 +0200 | [diff] [blame] | 524 | timeout = wait_for_completion_timeout( |
Virupax Sadashivpetimath | cd20e4fa | 2011-05-13 12:29:46 +0200 | [diff] [blame] | 525 | &dev->xfer_complete, dev->adap.timeout); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 526 | |
| 527 | if (timeout < 0) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 528 | dev_err(&dev->adev->dev, |
Linus Walleij | c8d47631a | 2011-08-09 20:17:29 +0200 | [diff] [blame] | 529 | "wait_for_completion_timeout " |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 530 | "returned %d waiting for event\n", timeout); |
| 531 | status = timeout; |
| 532 | } |
| 533 | |
| 534 | if (timeout == 0) { |
Virupax Sadashivpetimath | 0511f64 | 2011-05-13 12:30:53 +0200 | [diff] [blame] | 535 | /* Controller timed out */ |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 536 | dev_err(&dev->adev->dev, "write to slave 0x%x timed out\n", |
Virupax Sadashivpetimath | 4cb3f53 | 2011-05-13 12:29:55 +0200 | [diff] [blame] | 537 | dev->cli.slave_adr); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 538 | status = -ETIMEDOUT; |
| 539 | } |
| 540 | |
| 541 | return status; |
| 542 | } |
| 543 | |
| 544 | /** |
Linus Walleij | 82a4413 | 2011-05-13 12:31:01 +0200 | [diff] [blame] | 545 | * nmk_i2c_xfer_one() - transmit a single I2C message |
| 546 | * @dev: device with a message encoded into it |
| 547 | * @flags: message flags |
| 548 | */ |
| 549 | static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) |
| 550 | { |
| 551 | int status; |
| 552 | |
| 553 | if (flags & I2C_M_RD) { |
| 554 | /* read operation */ |
| 555 | dev->cli.operation = I2C_READ; |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 556 | status = read_i2c(dev, flags); |
Linus Walleij | 82a4413 | 2011-05-13 12:31:01 +0200 | [diff] [blame] | 557 | } else { |
| 558 | /* write operation */ |
| 559 | dev->cli.operation = I2C_WRITE; |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 560 | status = write_i2c(dev, flags); |
Linus Walleij | 82a4413 | 2011-05-13 12:31:01 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | if (status || (dev->result)) { |
| 564 | u32 i2c_sr; |
| 565 | u32 cause; |
| 566 | |
| 567 | i2c_sr = readl(dev->virtbase + I2C_SR); |
| 568 | /* |
| 569 | * Check if the controller I2C operation status |
| 570 | * is set to ABORT(11b). |
| 571 | */ |
| 572 | if (((i2c_sr >> 2) & 0x3) == 0x3) { |
| 573 | /* get the abort cause */ |
| 574 | cause = (i2c_sr >> 4) & 0x7; |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 575 | dev_err(&dev->adev->dev, "%s\n", |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 576 | cause >= ARRAY_SIZE(abort_causes) ? |
Linus Walleij | 82a4413 | 2011-05-13 12:31:01 +0200 | [diff] [blame] | 577 | "unknown reason" : |
| 578 | abort_causes[cause]); |
| 579 | } |
| 580 | |
| 581 | (void) init_hw(dev); |
| 582 | |
| 583 | status = status ? status : dev->result; |
| 584 | } |
| 585 | |
| 586 | return status; |
| 587 | } |
| 588 | |
| 589 | /** |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 590 | * nmk_i2c_xfer() - I2C transfer function used by kernel framework |
Linus Walleij | 1804edd | 2010-09-23 09:03:40 +0200 | [diff] [blame] | 591 | * @i2c_adap: Adapter pointer to the controller |
| 592 | * @msgs: Pointer to data to be written. |
| 593 | * @num_msgs: Number of messages to be executed |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 594 | * |
| 595 | * This is the function called by the generic kernel i2c_transfer() |
| 596 | * or i2c_smbus...() API calls. Note that this code is protected by the |
| 597 | * semaphore set in the kernel i2c_transfer() function. |
| 598 | * |
| 599 | * NOTE: |
| 600 | * READ TRANSFER : We impose a restriction of the first message to be the |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 601 | * index message for any read transaction. |
| 602 | * - a no index is coded as '0', |
| 603 | * - 2byte big endian index is coded as '3' |
| 604 | * !!! msg[0].buf holds the actual index. |
| 605 | * This is compatible with generic messages of smbus emulator |
| 606 | * that send a one byte index. |
| 607 | * eg. a I2C transation to read 2 bytes from index 0 |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 608 | * idx = 0; |
| 609 | * msg[0].addr = client->addr; |
| 610 | * msg[0].flags = 0x0; |
| 611 | * msg[0].len = 1; |
| 612 | * msg[0].buf = &idx; |
| 613 | * |
| 614 | * msg[1].addr = client->addr; |
| 615 | * msg[1].flags = I2C_M_RD; |
| 616 | * msg[1].len = 2; |
| 617 | * msg[1].buf = rd_buff |
| 618 | * i2c_transfer(adap, msg, 2); |
| 619 | * |
| 620 | * WRITE TRANSFER : The I2C standard interface interprets all data as payload. |
| 621 | * If you want to emulate an SMBUS write transaction put the |
| 622 | * index as first byte(or first and second) in the payload. |
| 623 | * eg. a I2C transation to write 2 bytes from index 1 |
| 624 | * wr_buff[0] = 0x1; |
| 625 | * wr_buff[1] = 0x23; |
| 626 | * wr_buff[2] = 0x46; |
| 627 | * msg[0].flags = 0x0; |
| 628 | * msg[0].len = 3; |
| 629 | * msg[0].buf = wr_buff; |
| 630 | * i2c_transfer(adap, msg, 1); |
| 631 | * |
| 632 | * To read or write a block of data (multiple bytes) using SMBUS emulation |
| 633 | * please use the i2c_smbus_read_i2c_block_data() |
| 634 | * or i2c_smbus_write_i2c_block_data() API |
| 635 | */ |
| 636 | static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, |
| 637 | struct i2c_msg msgs[], int num_msgs) |
| 638 | { |
| 639 | int status; |
| 640 | int i; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 641 | struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 642 | int j; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 643 | |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 644 | dev->busy = true; |
| 645 | |
| 646 | if (dev->regulator) |
| 647 | regulator_enable(dev->regulator); |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 648 | pm_runtime_get_sync(&dev->adev->dev); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 649 | |
Linus Walleij | 8ef4f4e | 2010-09-23 09:03:55 +0200 | [diff] [blame] | 650 | clk_enable(dev->clk); |
| 651 | |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 652 | status = init_hw(dev); |
| 653 | if (status) |
| 654 | goto out; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 655 | |
Linus Walleij | 82a4413 | 2011-05-13 12:31:01 +0200 | [diff] [blame] | 656 | /* Attempt three times to send the message queue */ |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 657 | for (j = 0; j < 3; j++) { |
| 658 | /* setup the i2c controller */ |
| 659 | setup_i2c_controller(dev); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 660 | |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 661 | for (i = 0; i < num_msgs; i++) { |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 662 | dev->cli.slave_adr = msgs[i].addr; |
| 663 | dev->cli.buffer = msgs[i].buf; |
| 664 | dev->cli.count = msgs[i].len; |
| 665 | dev->stop = (i < (num_msgs - 1)) ? 0 : 1; |
| 666 | dev->result = 0; |
| 667 | |
Linus Walleij | 82a4413 | 2011-05-13 12:31:01 +0200 | [diff] [blame] | 668 | status = nmk_i2c_xfer_one(dev, msgs[i].flags); |
| 669 | if (status != 0) |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 670 | break; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 671 | } |
Virupax Sadashivpetimath | ebd10e0 | 2011-05-13 12:30:23 +0200 | [diff] [blame] | 672 | if (status == 0) |
| 673 | break; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 674 | } |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 675 | |
| 676 | out: |
Linus Walleij | 8ef4f4e | 2010-09-23 09:03:55 +0200 | [diff] [blame] | 677 | clk_disable(dev->clk); |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 678 | pm_runtime_put_sync(&dev->adev->dev); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 679 | if (dev->regulator) |
| 680 | regulator_disable(dev->regulator); |
| 681 | |
| 682 | dev->busy = false; |
Linus Walleij | 8ef4f4e | 2010-09-23 09:03:55 +0200 | [diff] [blame] | 683 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 684 | /* return the no. messages processed */ |
| 685 | if (status) |
| 686 | return status; |
| 687 | else |
| 688 | return num_msgs; |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * disable_interrupts() - disable the interrupts |
| 693 | * @dev: private data of controller |
Linus Walleij | 1804edd | 2010-09-23 09:03:40 +0200 | [diff] [blame] | 694 | * @irq: interrupt number |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 695 | */ |
| 696 | static int disable_interrupts(struct nmk_i2c_dev *dev, u32 irq) |
| 697 | { |
| 698 | irq = IRQ_MASK(irq); |
| 699 | writel(readl(dev->virtbase + I2C_IMSCR) & ~(I2C_CLEAR_ALL_INTS & irq), |
| 700 | dev->virtbase + I2C_IMSCR); |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * i2c_irq_handler() - interrupt routine |
| 706 | * @irq: interrupt number |
| 707 | * @arg: data passed to the handler |
| 708 | * |
| 709 | * This is the interrupt handler for the i2c driver. Currently |
| 710 | * it handles the major interrupts like Rx & Tx FIFO management |
| 711 | * interrupts, master transaction interrupts, arbitration and |
| 712 | * bus error interrupts. The rest of the interrupts are treated as |
| 713 | * unhandled. |
| 714 | */ |
| 715 | static irqreturn_t i2c_irq_handler(int irq, void *arg) |
| 716 | { |
| 717 | struct nmk_i2c_dev *dev = arg; |
| 718 | u32 tft, rft; |
| 719 | u32 count; |
| 720 | u32 misr; |
| 721 | u32 src = 0; |
| 722 | |
| 723 | /* load Tx FIFO and Rx FIFO threshold values */ |
| 724 | tft = readl(dev->virtbase + I2C_TFTR); |
| 725 | rft = readl(dev->virtbase + I2C_RFTR); |
| 726 | |
| 727 | /* read interrupt status register */ |
| 728 | misr = readl(dev->virtbase + I2C_MISR); |
| 729 | |
| 730 | src = __ffs(misr); |
| 731 | switch ((1 << src)) { |
| 732 | |
| 733 | /* Transmit FIFO nearly empty interrupt */ |
| 734 | case I2C_IT_TXFNE: |
| 735 | { |
| 736 | if (dev->cli.operation == I2C_READ) { |
| 737 | /* |
| 738 | * in read operation why do we care for writing? |
| 739 | * so disable the Transmit FIFO interrupt |
| 740 | */ |
| 741 | disable_interrupts(dev, I2C_IT_TXFNE); |
| 742 | } else { |
Virupax Sadashivpetimath | 5535534 | 2011-05-13 12:30:34 +0200 | [diff] [blame] | 743 | fill_tx_fifo(dev, (MAX_I2C_FIFO_THRESHOLD - tft)); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 744 | /* |
| 745 | * if done, close the transfer by disabling the |
| 746 | * corresponding TXFNE interrupt |
| 747 | */ |
| 748 | if (dev->cli.count == 0) |
| 749 | disable_interrupts(dev, I2C_IT_TXFNE); |
| 750 | } |
| 751 | } |
| 752 | break; |
| 753 | |
| 754 | /* |
| 755 | * Rx FIFO nearly full interrupt. |
| 756 | * This is set when the numer of entries in Rx FIFO is |
| 757 | * greater or equal than the threshold value programmed |
| 758 | * in RFT |
| 759 | */ |
| 760 | case I2C_IT_RXFNF: |
| 761 | for (count = rft; count > 0; count--) { |
| 762 | /* Read the Rx FIFO */ |
| 763 | *dev->cli.buffer = readb(dev->virtbase + I2C_RFR); |
| 764 | dev->cli.buffer++; |
| 765 | } |
| 766 | dev->cli.count -= rft; |
| 767 | dev->cli.xfer_bytes += rft; |
| 768 | break; |
| 769 | |
| 770 | /* Rx FIFO full */ |
| 771 | case I2C_IT_RXFF: |
| 772 | for (count = MAX_I2C_FIFO_THRESHOLD; count > 0; count--) { |
| 773 | *dev->cli.buffer = readb(dev->virtbase + I2C_RFR); |
| 774 | dev->cli.buffer++; |
| 775 | } |
| 776 | dev->cli.count -= MAX_I2C_FIFO_THRESHOLD; |
| 777 | dev->cli.xfer_bytes += MAX_I2C_FIFO_THRESHOLD; |
| 778 | break; |
| 779 | |
| 780 | /* Master Transaction Done with/without stop */ |
| 781 | case I2C_IT_MTD: |
| 782 | case I2C_IT_MTDWS: |
| 783 | if (dev->cli.operation == I2C_READ) { |
Rabin Vincent | 1df3ab1 | 2010-04-27 10:31:08 +0530 | [diff] [blame] | 784 | while (!(readl(dev->virtbase + I2C_RISR) |
| 785 | & I2C_IT_RXFE)) { |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 786 | if (dev->cli.count == 0) |
| 787 | break; |
| 788 | *dev->cli.buffer = |
| 789 | readb(dev->virtbase + I2C_RFR); |
| 790 | dev->cli.buffer++; |
| 791 | dev->cli.count--; |
| 792 | dev->cli.xfer_bytes++; |
| 793 | } |
| 794 | } |
| 795 | |
Virupax Sadashivpetimath | b5e890f | 2011-05-13 12:30:42 +0200 | [diff] [blame] | 796 | disable_all_interrupts(dev); |
| 797 | clear_all_interrupts(dev); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 798 | |
| 799 | if (dev->cli.count) { |
Virupax Sadashivpetimath | 99381be | 2011-05-13 12:29:28 +0200 | [diff] [blame] | 800 | dev->result = -EIO; |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 801 | dev_err(&dev->adev->dev, |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 802 | "%lu bytes still remain to be xfered\n", |
| 803 | dev->cli.count); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 804 | (void) init_hw(dev); |
| 805 | } |
| 806 | complete(&dev->xfer_complete); |
| 807 | |
| 808 | break; |
| 809 | |
| 810 | /* Master Arbitration lost interrupt */ |
| 811 | case I2C_IT_MAL: |
Virupax Sadashivpetimath | 99381be | 2011-05-13 12:29:28 +0200 | [diff] [blame] | 812 | dev->result = -EIO; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 813 | (void) init_hw(dev); |
| 814 | |
| 815 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL); |
| 816 | complete(&dev->xfer_complete); |
| 817 | |
| 818 | break; |
| 819 | |
| 820 | /* |
| 821 | * Bus Error interrupt. |
| 822 | * This happens when an unexpected start/stop condition occurs |
| 823 | * during the transaction. |
| 824 | */ |
| 825 | case I2C_IT_BERR: |
Virupax Sadashivpetimath | 99381be | 2011-05-13 12:29:28 +0200 | [diff] [blame] | 826 | dev->result = -EIO; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 827 | /* get the status */ |
| 828 | if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT) |
| 829 | (void) init_hw(dev); |
| 830 | |
| 831 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_BERR); |
| 832 | complete(&dev->xfer_complete); |
| 833 | |
| 834 | break; |
| 835 | |
| 836 | /* |
| 837 | * Tx FIFO overrun interrupt. |
| 838 | * This is set when a write operation in Tx FIFO is performed and |
| 839 | * the Tx FIFO is full. |
| 840 | */ |
| 841 | case I2C_IT_TXFOVR: |
Virupax Sadashivpetimath | 99381be | 2011-05-13 12:29:28 +0200 | [diff] [blame] | 842 | dev->result = -EIO; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 843 | (void) init_hw(dev); |
| 844 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 845 | dev_err(&dev->adev->dev, "Tx Fifo Over run\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 846 | complete(&dev->xfer_complete); |
| 847 | |
| 848 | break; |
| 849 | |
| 850 | /* unhandled interrupts by this driver - TODO*/ |
| 851 | case I2C_IT_TXFE: |
| 852 | case I2C_IT_TXFF: |
| 853 | case I2C_IT_RXFE: |
| 854 | case I2C_IT_RFSR: |
| 855 | case I2C_IT_RFSE: |
| 856 | case I2C_IT_WTSR: |
| 857 | case I2C_IT_STD: |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 858 | dev_err(&dev->adev->dev, "unhandled Interrupt\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 859 | break; |
| 860 | default: |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 861 | dev_err(&dev->adev->dev, "spurious Interrupt..\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 862 | break; |
| 863 | } |
| 864 | |
| 865 | return IRQ_HANDLED; |
| 866 | } |
| 867 | |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 868 | |
| 869 | #ifdef CONFIG_PM |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 870 | static int nmk_i2c_suspend(struct device *dev) |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 871 | { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 872 | struct amba_device *adev = to_amba_device(dev); |
| 873 | struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 874 | |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 875 | if (nmk_i2c->busy) |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 876 | return -EBUSY; |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 877 | |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static int nmk_i2c_resume(struct device *dev) |
| 882 | { |
| 883 | return 0; |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 884 | } |
| 885 | #else |
| 886 | #define nmk_i2c_suspend NULL |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 887 | #define nmk_i2c_resume NULL |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 888 | #endif |
| 889 | |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 890 | /* |
| 891 | * We use noirq so that we suspend late and resume before the wakeup interrupt |
| 892 | * to ensure that we do the !pm_runtime_suspended() check in resume before |
| 893 | * there has been a regular pm runtime resume (via pm_runtime_get_sync()). |
| 894 | */ |
| 895 | static const struct dev_pm_ops nmk_i2c_pm = { |
| 896 | .suspend_noirq = nmk_i2c_suspend, |
| 897 | .resume_noirq = nmk_i2c_resume, |
| 898 | }; |
| 899 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 900 | static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) |
| 901 | { |
Virupax Sadashivpetimath | 51a0c8d | 2012-06-25 17:56:07 +0530 | [diff] [blame] | 902 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static const struct i2c_algorithm nmk_i2c_algo = { |
| 906 | .master_xfer = nmk_i2c_xfer, |
| 907 | .functionality = nmk_i2c_functionality |
| 908 | }; |
| 909 | |
Lee Jones | b007a3e | 2012-08-07 12:27:24 +0100 | [diff] [blame^] | 910 | static struct nmk_i2c_controller u8500_i2c = { |
| 911 | /* |
| 912 | * Slave data setup time; 250ns, 100ns, and 10ns, which |
| 913 | * is 14, 6 and 2 respectively for a 48Mhz i2c clock. |
| 914 | */ |
| 915 | .slsu = 0xe, |
| 916 | .tft = 1, /* Tx FIFO threshold */ |
| 917 | .rft = 8, /* Rx FIFO threshold */ |
| 918 | .clk_freq = 400000, /* fast mode operation */ |
| 919 | .timeout = 200, /* Slave response timeout(ms) */ |
| 920 | .sm = I2C_FREQ_MODE_FAST, |
| 921 | }; |
| 922 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 923 | static atomic_t adapter_id = ATOMIC_INIT(0); |
| 924 | |
| 925 | static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 926 | { |
| 927 | int ret = 0; |
Lee Jones | b007a3e | 2012-08-07 12:27:24 +0100 | [diff] [blame^] | 928 | struct nmk_i2c_controller *pdata = adev->dev.platform_data; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 929 | struct nmk_i2c_dev *dev; |
| 930 | struct i2c_adapter *adap; |
| 931 | |
Lee Jones | b007a3e | 2012-08-07 12:27:24 +0100 | [diff] [blame^] | 932 | if (!pdata) |
| 933 | /* No i2c configuration found, using the default. */ |
| 934 | pdata = &u8500_i2c; |
| 935 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 936 | dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); |
| 937 | if (!dev) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 938 | dev_err(&adev->dev, "cannot allocate memory\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 939 | ret = -ENOMEM; |
| 940 | goto err_no_mem; |
| 941 | } |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 942 | dev->busy = false; |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 943 | dev->adev = adev; |
| 944 | amba_set_drvdata(adev, dev); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 945 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 946 | dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 947 | if (!dev->virtbase) { |
| 948 | ret = -ENOMEM; |
| 949 | goto err_no_ioremap; |
| 950 | } |
| 951 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 952 | dev->irq = adev->irq[0]; |
Yong Zhang | 4311051 | 2011-09-21 17:28:33 +0800 | [diff] [blame] | 953 | ret = request_irq(dev->irq, i2c_irq_handler, 0, |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 954 | DRIVER_NAME, dev); |
| 955 | if (ret) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 956 | dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 957 | goto err_irq; |
| 958 | } |
| 959 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 960 | dev->regulator = regulator_get(&adev->dev, "v-i2c"); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 961 | if (IS_ERR(dev->regulator)) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 962 | dev_warn(&adev->dev, "could not get i2c regulator\n"); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 963 | dev->regulator = NULL; |
| 964 | } |
| 965 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 966 | pm_suspend_ignore_children(&adev->dev, true); |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 967 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 968 | dev->clk = clk_get(&adev->dev, NULL); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 969 | if (IS_ERR(dev->clk)) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 970 | dev_err(&adev->dev, "could not get i2c clock\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 971 | ret = PTR_ERR(dev->clk); |
| 972 | goto err_no_clk; |
| 973 | } |
| 974 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 975 | adap = &dev->adap; |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 976 | adap->dev.parent = &adev->dev; |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 977 | adap->owner = THIS_MODULE; |
| 978 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
| 979 | adap->algo = &nmk_i2c_algo; |
Lee Jones | 98582d9 | 2012-04-17 15:52:26 +0100 | [diff] [blame] | 980 | adap->timeout = msecs_to_jiffies(pdata->timeout); |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 981 | adap->nr = atomic_read(&adapter_id); |
Linus Walleij | 6d779a4 | 2010-11-30 16:59:29 +0100 | [diff] [blame] | 982 | snprintf(adap->name, sizeof(adap->name), |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 983 | "Nomadik I2C%d at %pR", adap->nr, &adev->res); |
| 984 | atomic_inc(&adapter_id); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 985 | |
| 986 | /* fetch the controller configuration from machine */ |
| 987 | dev->cfg.clk_freq = pdata->clk_freq; |
| 988 | dev->cfg.slsu = pdata->slsu; |
| 989 | dev->cfg.tft = pdata->tft; |
| 990 | dev->cfg.rft = pdata->rft; |
| 991 | dev->cfg.sm = pdata->sm; |
| 992 | |
| 993 | i2c_set_adapdata(adap, dev); |
| 994 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 995 | dev_info(&adev->dev, |
Jonas Aaberg | 8abf6fbb | 2011-10-20 18:23:01 +0200 | [diff] [blame] | 996 | "initialize %s on virtual base %p\n", |
| 997 | adap->name, dev->virtbase); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 998 | |
| 999 | ret = i2c_add_numbered_adapter(adap); |
| 1000 | if (ret) { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1001 | dev_err(&adev->dev, "failed to add adapter\n"); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1002 | goto err_add_adap; |
| 1003 | } |
| 1004 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1005 | pm_runtime_put(&adev->dev); |
| 1006 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1007 | return 0; |
| 1008 | |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1009 | err_add_adap: |
| 1010 | clk_put(dev->clk); |
| 1011 | err_no_clk: |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 1012 | if (dev->regulator) |
| 1013 | regulator_put(dev->regulator); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1014 | free_irq(dev->irq, dev); |
| 1015 | err_irq: |
| 1016 | iounmap(dev->virtbase); |
| 1017 | err_no_ioremap: |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1018 | amba_set_drvdata(adev, NULL); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1019 | kfree(dev); |
| 1020 | err_no_mem: |
| 1021 | |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1025 | static int nmk_i2c_remove(struct amba_device *adev) |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1026 | { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1027 | struct resource *res = &adev->res; |
| 1028 | struct nmk_i2c_dev *dev = amba_get_drvdata(adev); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1029 | |
| 1030 | i2c_del_adapter(&dev->adap); |
| 1031 | flush_i2c_fifo(dev); |
| 1032 | disable_all_interrupts(dev); |
| 1033 | clear_all_interrupts(dev); |
| 1034 | /* disable the controller */ |
| 1035 | i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); |
| 1036 | free_irq(dev->irq, dev); |
| 1037 | iounmap(dev->virtbase); |
Rabin Vincent | a1c2767 | 2010-04-27 10:31:07 +0530 | [diff] [blame] | 1038 | if (res) |
| 1039 | release_mem_region(res->start, resource_size(res)); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1040 | clk_put(dev->clk); |
Jonas Aberg | a20d239 | 2011-05-13 12:29:02 +0200 | [diff] [blame] | 1041 | if (dev->regulator) |
| 1042 | regulator_put(dev->regulator); |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1043 | pm_runtime_disable(&adev->dev); |
| 1044 | amba_set_drvdata(adev, NULL); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1045 | kfree(dev); |
| 1046 | |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1050 | static struct amba_id nmk_i2c_ids[] = { |
| 1051 | { |
| 1052 | .id = 0x00180024, |
| 1053 | .mask = 0x00ffffff, |
| 1054 | }, |
| 1055 | { |
| 1056 | .id = 0x00380024, |
| 1057 | .mask = 0x00ffffff, |
| 1058 | }, |
| 1059 | {}, |
| 1060 | }; |
| 1061 | |
| 1062 | MODULE_DEVICE_TABLE(amba, nmk_i2c_ids); |
| 1063 | |
| 1064 | static struct amba_driver nmk_i2c_driver = { |
| 1065 | .drv = { |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1066 | .owner = THIS_MODULE, |
| 1067 | .name = DRIVER_NAME, |
Rabin Vincent | b0e751a | 2011-05-13 12:30:07 +0200 | [diff] [blame] | 1068 | .pm = &nmk_i2c_pm, |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1069 | }, |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1070 | .id_table = nmk_i2c_ids, |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1071 | .probe = nmk_i2c_probe, |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1072 | .remove = nmk_i2c_remove, |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1073 | }; |
| 1074 | |
| 1075 | static int __init nmk_i2c_init(void) |
| 1076 | { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1077 | return amba_driver_register(&nmk_i2c_driver); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | static void __exit nmk_i2c_exit(void) |
| 1081 | { |
Alessandro Rubini | 2356021 | 2012-06-11 22:56:38 +0200 | [diff] [blame] | 1082 | amba_driver_unregister(&nmk_i2c_driver); |
srinidhi kasagar | 3f9900f | 2010-02-01 19:44:54 +0530 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | subsys_initcall(nmk_i2c_init); |
| 1086 | module_exit(nmk_i2c_exit); |
| 1087 | |
| 1088 | MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR"); |
| 1089 | MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver"); |
| 1090 | MODULE_LICENSE("GPL"); |