Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * i2c Support for Atmel's AT91 Two-Wire Interface (TWI) |
| 3 | * |
| 4 | * Copyright (C) 2011 Weinmann Medical GmbH |
| 5 | * Author: Nikolaus Voss <n.voss@weinmann.de> |
| 6 | * |
| 7 | * Evolved from original work by: |
| 8 | * Copyright (C) 2004 Rick Bronson |
| 9 | * Converted to 2.6 by Andrew Victor <andrew@sanpeople.com> |
| 10 | * |
| 11 | * Borrowed heavily from original work by: |
| 12 | * Copyright (C) 2000 Philip Edelbrock <phil@stimpy.netroedge.com> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/completion.h> |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 22 | #include <linux/dma-mapping.h> |
| 23 | #include <linux/dmaengine.h> |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 24 | #include <linux/err.h> |
| 25 | #include <linux/i2c.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/module.h> |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 29 | #include <linux/of.h> |
| 30 | #include <linux/of_device.h> |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/slab.h> |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 33 | #include <linux/platform_data/dma-atmel.h> |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 34 | #include <linux/pm_runtime.h> |
Wenyou Yang | 62d10c4 | 2014-11-10 09:55:52 +0800 | [diff] [blame] | 35 | #include <linux/pinctrl/consumer.h> |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 36 | |
Marek Roszko | 75b6c4b | 2014-03-11 00:25:38 -0400 | [diff] [blame] | 37 | #define DEFAULT_TWI_CLK_HZ 100000 /* max 400 Kbits/s */ |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 38 | #define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */ |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 39 | #define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */ |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 40 | #define AUTOSUSPEND_TIMEOUT 2000 |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 41 | |
| 42 | /* AT91 TWI register definitions */ |
| 43 | #define AT91_TWI_CR 0x0000 /* Control Register */ |
Cyrille Pitchen | e84cf8f | 2015-06-09 18:22:15 +0200 | [diff] [blame] | 44 | #define AT91_TWI_START BIT(0) /* Send a Start Condition */ |
| 45 | #define AT91_TWI_STOP BIT(1) /* Send a Stop Condition */ |
| 46 | #define AT91_TWI_MSEN BIT(2) /* Master Transfer Enable */ |
| 47 | #define AT91_TWI_MSDIS BIT(3) /* Master Transfer Disable */ |
| 48 | #define AT91_TWI_SVEN BIT(4) /* Slave Transfer Enable */ |
| 49 | #define AT91_TWI_SVDIS BIT(5) /* Slave Transfer Disable */ |
| 50 | #define AT91_TWI_QUICK BIT(6) /* SMBus quick command */ |
| 51 | #define AT91_TWI_SWRST BIT(7) /* Software Reset */ |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 52 | #define AT91_TWI_ACMEN BIT(16) /* Alternative Command Mode Enable */ |
| 53 | #define AT91_TWI_ACMDIS BIT(17) /* Alternative Command Mode Disable */ |
| 54 | #define AT91_TWI_THRCLR BIT(24) /* Transmit Holding Register Clear */ |
| 55 | #define AT91_TWI_RHRCLR BIT(25) /* Receive Holding Register Clear */ |
| 56 | #define AT91_TWI_LOCKCLR BIT(26) /* Lock Clear */ |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 57 | |
| 58 | #define AT91_TWI_MMR 0x0004 /* Master Mode Register */ |
| 59 | #define AT91_TWI_IADRSZ_1 0x0100 /* Internal Device Address Size */ |
Cyrille Pitchen | e84cf8f | 2015-06-09 18:22:15 +0200 | [diff] [blame] | 60 | #define AT91_TWI_MREAD BIT(12) /* Master Read Direction */ |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 61 | |
| 62 | #define AT91_TWI_IADR 0x000c /* Internal Address Register */ |
| 63 | |
| 64 | #define AT91_TWI_CWGR 0x0010 /* Clock Waveform Generator Reg */ |
| 65 | |
| 66 | #define AT91_TWI_SR 0x0020 /* Status Register */ |
Cyrille Pitchen | e84cf8f | 2015-06-09 18:22:15 +0200 | [diff] [blame] | 67 | #define AT91_TWI_TXCOMP BIT(0) /* Transmission Complete */ |
| 68 | #define AT91_TWI_RXRDY BIT(1) /* Receive Holding Register Ready */ |
| 69 | #define AT91_TWI_TXRDY BIT(2) /* Transmit Holding Register Ready */ |
| 70 | #define AT91_TWI_OVRE BIT(6) /* Overrun Error */ |
| 71 | #define AT91_TWI_UNRE BIT(7) /* Underrun Error */ |
| 72 | #define AT91_TWI_NACK BIT(8) /* Not Acknowledged */ |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 73 | #define AT91_TWI_LOCK BIT(23) /* TWI Lock due to Frame Errors */ |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 74 | |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 75 | #define AT91_TWI_INT_MASK \ |
| 76 | (AT91_TWI_TXCOMP | AT91_TWI_RXRDY | AT91_TWI_TXRDY | AT91_TWI_NACK) |
| 77 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 78 | #define AT91_TWI_IER 0x0024 /* Interrupt Enable Register */ |
| 79 | #define AT91_TWI_IDR 0x0028 /* Interrupt Disable Register */ |
| 80 | #define AT91_TWI_IMR 0x002c /* Interrupt Mask Register */ |
| 81 | #define AT91_TWI_RHR 0x0030 /* Receive Holding Register */ |
| 82 | #define AT91_TWI_THR 0x0034 /* Transmit Holding Register */ |
| 83 | |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 84 | #define AT91_TWI_ACR 0x0040 /* Alternative Command Register */ |
| 85 | #define AT91_TWI_ACR_DATAL(len) ((len) & 0xff) |
| 86 | #define AT91_TWI_ACR_DIR BIT(8) |
| 87 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 88 | struct at91_twi_pdata { |
Ludovic Desroches | 5f43381 | 2012-11-23 10:09:03 +0100 | [diff] [blame] | 89 | unsigned clk_max_div; |
| 90 | unsigned clk_offset; |
| 91 | bool has_unre_flag; |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 92 | bool has_alt_cmd; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 93 | struct at_dma_slave dma_slave; |
| 94 | }; |
| 95 | |
| 96 | struct at91_twi_dma { |
| 97 | struct dma_chan *chan_rx; |
| 98 | struct dma_chan *chan_tx; |
| 99 | struct scatterlist sg; |
| 100 | struct dma_async_tx_descriptor *data_desc; |
| 101 | enum dma_data_direction direction; |
| 102 | bool buf_mapped; |
| 103 | bool xfer_in_progress; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct at91_twi_dev { |
Ludovic Desroches | 5f43381 | 2012-11-23 10:09:03 +0100 | [diff] [blame] | 107 | struct device *dev; |
| 108 | void __iomem *base; |
| 109 | struct completion cmd_complete; |
| 110 | struct clk *clk; |
| 111 | u8 *buf; |
| 112 | size_t buf_len; |
| 113 | struct i2c_msg *msg; |
| 114 | int irq; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 115 | unsigned imr; |
Ludovic Desroches | 5f43381 | 2012-11-23 10:09:03 +0100 | [diff] [blame] | 116 | unsigned transfer_status; |
| 117 | struct i2c_adapter adapter; |
| 118 | unsigned twi_cwgr_reg; |
| 119 | struct at91_twi_pdata *pdata; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 120 | bool use_dma; |
Marek Roszko | 75b81f3 | 2014-08-20 21:39:41 -0400 | [diff] [blame] | 121 | bool recv_len_abort; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 122 | struct at91_twi_dma dma; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static unsigned at91_twi_read(struct at91_twi_dev *dev, unsigned reg) |
| 126 | { |
| 127 | return readl_relaxed(dev->base + reg); |
| 128 | } |
| 129 | |
| 130 | static void at91_twi_write(struct at91_twi_dev *dev, unsigned reg, unsigned val) |
| 131 | { |
| 132 | writel_relaxed(val, dev->base + reg); |
| 133 | } |
| 134 | |
| 135 | static void at91_disable_twi_interrupts(struct at91_twi_dev *dev) |
| 136 | { |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 137 | at91_twi_write(dev, AT91_TWI_IDR, AT91_TWI_INT_MASK); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 140 | static void at91_twi_irq_save(struct at91_twi_dev *dev) |
| 141 | { |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 142 | dev->imr = at91_twi_read(dev, AT91_TWI_IMR) & AT91_TWI_INT_MASK; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 143 | at91_disable_twi_interrupts(dev); |
| 144 | } |
| 145 | |
| 146 | static void at91_twi_irq_restore(struct at91_twi_dev *dev) |
| 147 | { |
| 148 | at91_twi_write(dev, AT91_TWI_IER, dev->imr); |
| 149 | } |
| 150 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 151 | static void at91_init_twi_bus(struct at91_twi_dev *dev) |
| 152 | { |
| 153 | at91_disable_twi_interrupts(dev); |
| 154 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_SWRST); |
| 155 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSEN); |
| 156 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_SVDIS); |
| 157 | at91_twi_write(dev, AT91_TWI_CWGR, dev->twi_cwgr_reg); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Calculate symmetric clock as stated in datasheet: |
| 162 | * twi_clk = F_MAIN / (2 * (cdiv * (1 << ckdiv) + offset)) |
| 163 | */ |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 164 | static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk) |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 165 | { |
| 166 | int ckdiv, cdiv, div; |
| 167 | struct at91_twi_pdata *pdata = dev->pdata; |
| 168 | int offset = pdata->clk_offset; |
| 169 | int max_ckdiv = pdata->clk_max_div; |
| 170 | |
| 171 | div = max(0, (int)DIV_ROUND_UP(clk_get_rate(dev->clk), |
| 172 | 2 * twi_clk) - offset); |
| 173 | ckdiv = fls(div >> 8); |
| 174 | cdiv = div >> ckdiv; |
| 175 | |
| 176 | if (ckdiv > max_ckdiv) { |
| 177 | dev_warn(dev->dev, "%d exceeds ckdiv max value which is %d.\n", |
| 178 | ckdiv, max_ckdiv); |
| 179 | ckdiv = max_ckdiv; |
| 180 | cdiv = 255; |
| 181 | } |
| 182 | |
| 183 | dev->twi_cwgr_reg = (ckdiv << 16) | (cdiv << 8) | cdiv; |
| 184 | dev_dbg(dev->dev, "cdiv %d ckdiv %d\n", cdiv, ckdiv); |
| 185 | } |
| 186 | |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 187 | static void at91_twi_dma_cleanup(struct at91_twi_dev *dev) |
| 188 | { |
| 189 | struct at91_twi_dma *dma = &dev->dma; |
| 190 | |
| 191 | at91_twi_irq_save(dev); |
| 192 | |
| 193 | if (dma->xfer_in_progress) { |
| 194 | if (dma->direction == DMA_FROM_DEVICE) |
| 195 | dmaengine_terminate_all(dma->chan_rx); |
| 196 | else |
| 197 | dmaengine_terminate_all(dma->chan_tx); |
| 198 | dma->xfer_in_progress = false; |
| 199 | } |
| 200 | if (dma->buf_mapped) { |
| 201 | dma_unmap_single(dev->dev, sg_dma_address(&dma->sg), |
| 202 | dev->buf_len, dma->direction); |
| 203 | dma->buf_mapped = false; |
| 204 | } |
| 205 | |
| 206 | at91_twi_irq_restore(dev); |
| 207 | } |
| 208 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 209 | static void at91_twi_write_next_byte(struct at91_twi_dev *dev) |
| 210 | { |
| 211 | if (dev->buf_len <= 0) |
| 212 | return; |
| 213 | |
| 214 | at91_twi_write(dev, AT91_TWI_THR, *dev->buf); |
| 215 | |
| 216 | /* send stop when last byte has been written */ |
| 217 | if (--dev->buf_len == 0) |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 218 | if (!dev->pdata->has_alt_cmd) |
| 219 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 220 | |
| 221 | dev_dbg(dev->dev, "wrote 0x%x, to go %d\n", *dev->buf, dev->buf_len); |
| 222 | |
| 223 | ++dev->buf; |
| 224 | } |
| 225 | |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 226 | static void at91_twi_write_data_dma_callback(void *data) |
| 227 | { |
| 228 | struct at91_twi_dev *dev = (struct at91_twi_dev *)data; |
| 229 | |
| 230 | dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg), |
Wolfram Sang | 28772ac | 2014-07-21 11:42:03 +0200 | [diff] [blame] | 231 | dev->buf_len, DMA_TO_DEVICE); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 232 | |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 233 | /* |
| 234 | * When this callback is called, THR/TX FIFO is likely not to be empty |
| 235 | * yet. So we have to wait for TXCOMP or NACK bits to be set into the |
| 236 | * Status Register to be sure that the STOP bit has been sent and the |
| 237 | * transfer is completed. The NACK interrupt has already been enabled, |
| 238 | * we just have to enable TXCOMP one. |
| 239 | */ |
| 240 | at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP); |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 241 | if (!dev->pdata->has_alt_cmd) |
| 242 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static void at91_twi_write_data_dma(struct at91_twi_dev *dev) |
| 246 | { |
| 247 | dma_addr_t dma_addr; |
| 248 | struct dma_async_tx_descriptor *txdesc; |
| 249 | struct at91_twi_dma *dma = &dev->dma; |
| 250 | struct dma_chan *chan_tx = dma->chan_tx; |
| 251 | |
| 252 | if (dev->buf_len <= 0) |
| 253 | return; |
| 254 | |
| 255 | dma->direction = DMA_TO_DEVICE; |
| 256 | |
| 257 | at91_twi_irq_save(dev); |
| 258 | dma_addr = dma_map_single(dev->dev, dev->buf, dev->buf_len, |
| 259 | DMA_TO_DEVICE); |
| 260 | if (dma_mapping_error(dev->dev, dma_addr)) { |
| 261 | dev_err(dev->dev, "dma map failed\n"); |
| 262 | return; |
| 263 | } |
| 264 | dma->buf_mapped = true; |
| 265 | at91_twi_irq_restore(dev); |
| 266 | sg_dma_len(&dma->sg) = dev->buf_len; |
| 267 | sg_dma_address(&dma->sg) = dma_addr; |
| 268 | |
| 269 | txdesc = dmaengine_prep_slave_sg(chan_tx, &dma->sg, 1, DMA_MEM_TO_DEV, |
| 270 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 271 | if (!txdesc) { |
| 272 | dev_err(dev->dev, "dma prep slave sg failed\n"); |
| 273 | goto error; |
| 274 | } |
| 275 | |
| 276 | txdesc->callback = at91_twi_write_data_dma_callback; |
| 277 | txdesc->callback_param = dev; |
| 278 | |
| 279 | dma->xfer_in_progress = true; |
| 280 | dmaengine_submit(txdesc); |
| 281 | dma_async_issue_pending(chan_tx); |
| 282 | |
| 283 | return; |
| 284 | |
| 285 | error: |
| 286 | at91_twi_dma_cleanup(dev); |
| 287 | } |
| 288 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 289 | static void at91_twi_read_next_byte(struct at91_twi_dev *dev) |
| 290 | { |
| 291 | if (dev->buf_len <= 0) |
| 292 | return; |
| 293 | |
| 294 | *dev->buf = at91_twi_read(dev, AT91_TWI_RHR) & 0xff; |
| 295 | --dev->buf_len; |
| 296 | |
Marek Roszko | 75b81f3 | 2014-08-20 21:39:41 -0400 | [diff] [blame] | 297 | /* return if aborting, we only needed to read RHR to clear RXRDY*/ |
| 298 | if (dev->recv_len_abort) |
| 299 | return; |
| 300 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 301 | /* handle I2C_SMBUS_BLOCK_DATA */ |
| 302 | if (unlikely(dev->msg->flags & I2C_M_RECV_LEN)) { |
Marek Roszko | 75b81f3 | 2014-08-20 21:39:41 -0400 | [diff] [blame] | 303 | /* ensure length byte is a valid value */ |
| 304 | if (*dev->buf <= I2C_SMBUS_BLOCK_MAX && *dev->buf > 0) { |
| 305 | dev->msg->flags &= ~I2C_M_RECV_LEN; |
| 306 | dev->buf_len += *dev->buf; |
| 307 | dev->msg->len = dev->buf_len + 1; |
| 308 | dev_dbg(dev->dev, "received block length %d\n", |
| 309 | dev->buf_len); |
| 310 | } else { |
| 311 | /* abort and send the stop by reading one more byte */ |
| 312 | dev->recv_len_abort = true; |
| 313 | dev->buf_len = 1; |
| 314 | } |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* send stop if second but last byte has been read */ |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 318 | if (!dev->pdata->has_alt_cmd && dev->buf_len == 1) |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 319 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP); |
| 320 | |
| 321 | dev_dbg(dev->dev, "read 0x%x, to go %d\n", *dev->buf, dev->buf_len); |
| 322 | |
| 323 | ++dev->buf; |
| 324 | } |
| 325 | |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 326 | static void at91_twi_read_data_dma_callback(void *data) |
| 327 | { |
| 328 | struct at91_twi_dev *dev = (struct at91_twi_dev *)data; |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 329 | unsigned ier = AT91_TWI_TXCOMP; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 330 | |
| 331 | dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg), |
Wolfram Sang | 28772ac | 2014-07-21 11:42:03 +0200 | [diff] [blame] | 332 | dev->buf_len, DMA_FROM_DEVICE); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 333 | |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 334 | if (!dev->pdata->has_alt_cmd) { |
| 335 | /* The last two bytes have to be read without using dma */ |
| 336 | dev->buf += dev->buf_len - 2; |
| 337 | dev->buf_len = 2; |
| 338 | ier |= AT91_TWI_RXRDY; |
| 339 | } |
| 340 | at91_twi_write(dev, AT91_TWI_IER, ier); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static void at91_twi_read_data_dma(struct at91_twi_dev *dev) |
| 344 | { |
| 345 | dma_addr_t dma_addr; |
| 346 | struct dma_async_tx_descriptor *rxdesc; |
| 347 | struct at91_twi_dma *dma = &dev->dma; |
| 348 | struct dma_chan *chan_rx = dma->chan_rx; |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 349 | size_t buf_len; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 350 | |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 351 | buf_len = (dev->pdata->has_alt_cmd) ? dev->buf_len : dev->buf_len - 2; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 352 | dma->direction = DMA_FROM_DEVICE; |
| 353 | |
| 354 | /* Keep in mind that we won't use dma to read the last two bytes */ |
| 355 | at91_twi_irq_save(dev); |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 356 | dma_addr = dma_map_single(dev->dev, dev->buf, buf_len, DMA_FROM_DEVICE); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 357 | if (dma_mapping_error(dev->dev, dma_addr)) { |
| 358 | dev_err(dev->dev, "dma map failed\n"); |
| 359 | return; |
| 360 | } |
| 361 | dma->buf_mapped = true; |
| 362 | at91_twi_irq_restore(dev); |
| 363 | dma->sg.dma_address = dma_addr; |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 364 | sg_dma_len(&dma->sg) = buf_len; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 365 | |
| 366 | rxdesc = dmaengine_prep_slave_sg(chan_rx, &dma->sg, 1, DMA_DEV_TO_MEM, |
| 367 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 368 | if (!rxdesc) { |
| 369 | dev_err(dev->dev, "dma prep slave sg failed\n"); |
| 370 | goto error; |
| 371 | } |
| 372 | |
| 373 | rxdesc->callback = at91_twi_read_data_dma_callback; |
| 374 | rxdesc->callback_param = dev; |
| 375 | |
| 376 | dma->xfer_in_progress = true; |
| 377 | dmaengine_submit(rxdesc); |
| 378 | dma_async_issue_pending(dma->chan_rx); |
| 379 | |
| 380 | return; |
| 381 | |
| 382 | error: |
| 383 | at91_twi_dma_cleanup(dev); |
| 384 | } |
| 385 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 386 | static irqreturn_t atmel_twi_interrupt(int irq, void *dev_id) |
| 387 | { |
| 388 | struct at91_twi_dev *dev = dev_id; |
| 389 | const unsigned status = at91_twi_read(dev, AT91_TWI_SR); |
| 390 | const unsigned irqstatus = status & at91_twi_read(dev, AT91_TWI_IMR); |
| 391 | |
| 392 | if (!irqstatus) |
| 393 | return IRQ_NONE; |
| 394 | else if (irqstatus & AT91_TWI_RXRDY) |
| 395 | at91_twi_read_next_byte(dev); |
| 396 | else if (irqstatus & AT91_TWI_TXRDY) |
| 397 | at91_twi_write_next_byte(dev); |
| 398 | |
| 399 | /* catch error flags */ |
| 400 | dev->transfer_status |= status; |
| 401 | |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 402 | if (irqstatus & (AT91_TWI_TXCOMP | AT91_TWI_NACK)) { |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 403 | at91_disable_twi_interrupts(dev); |
| 404 | complete(&dev->cmd_complete); |
| 405 | } |
| 406 | |
| 407 | return IRQ_HANDLED; |
| 408 | } |
| 409 | |
| 410 | static int at91_do_twi_transfer(struct at91_twi_dev *dev) |
| 411 | { |
| 412 | int ret; |
Nicholas Mc Guire | 1c42aca | 2015-02-08 11:12:07 -0500 | [diff] [blame] | 413 | unsigned long time_left; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 414 | bool has_unre_flag = dev->pdata->has_unre_flag; |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 415 | bool has_alt_cmd = dev->pdata->has_alt_cmd; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 416 | |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 417 | /* |
| 418 | * WARNING: the TXCOMP bit in the Status Register is NOT a clear on |
| 419 | * read flag but shows the state of the transmission at the time the |
| 420 | * Status Register is read. According to the programmer datasheet, |
| 421 | * TXCOMP is set when both holding register and internal shifter are |
| 422 | * empty and STOP condition has been sent. |
| 423 | * Consequently, we should enable NACK interrupt rather than TXCOMP to |
| 424 | * detect transmission failure. |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 425 | * Indeed let's take the case of an i2c write command using DMA. |
| 426 | * Whenever the slave doesn't acknowledge a byte, the LOCK, NACK and |
| 427 | * TXCOMP bits are set together into the Status Register. |
| 428 | * LOCK is a clear on write bit, which is set to prevent the DMA |
| 429 | * controller from sending new data on the i2c bus after a NACK |
| 430 | * condition has happened. Once locked, this i2c peripheral stops |
| 431 | * triggering the DMA controller for new data but it is more than |
| 432 | * likely that a new DMA transaction is already in progress, writing |
| 433 | * into the Transmit Holding Register. Since the peripheral is locked, |
| 434 | * these new data won't be sent to the i2c bus but they will remain |
| 435 | * into the Transmit Holding Register, so TXCOMP bit is cleared. |
| 436 | * Then when the interrupt handler is called, the Status Register is |
| 437 | * read: the TXCOMP bit is clear but NACK bit is still set. The driver |
| 438 | * manage the error properly, without waiting for timeout. |
| 439 | * This case can be reproduced easyly when writing into an at24 eeprom. |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 440 | * |
| 441 | * Besides, the TXCOMP bit is already set before the i2c transaction |
| 442 | * has been started. For read transactions, this bit is cleared when |
| 443 | * writing the START bit into the Control Register. So the |
| 444 | * corresponding interrupt can safely be enabled just after. |
| 445 | * However for write transactions managed by the CPU, we first write |
| 446 | * into THR, so TXCOMP is cleared. Then we can safely enable TXCOMP |
| 447 | * interrupt. If TXCOMP interrupt were enabled before writing into THR, |
| 448 | * the interrupt handler would be called immediately and the i2c command |
| 449 | * would be reported as completed. |
| 450 | * Also when a write transaction is managed by the DMA controller, |
| 451 | * enabling the TXCOMP interrupt in this function may lead to a race |
| 452 | * condition since we don't know whether the TXCOMP interrupt is enabled |
| 453 | * before or after the DMA has started to write into THR. So the TXCOMP |
| 454 | * interrupt is enabled later by at91_twi_write_data_dma_callback(). |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 455 | * Immediately after in that DMA callback, if the alternative command |
| 456 | * mode is not used, we still need to send the STOP condition manually |
| 457 | * writing the corresponding bit into the Control Register. |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 458 | */ |
| 459 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 460 | dev_dbg(dev->dev, "transfer: %s %d bytes.\n", |
| 461 | (dev->msg->flags & I2C_M_RD) ? "read" : "write", dev->buf_len); |
| 462 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 463 | reinit_completion(&dev->cmd_complete); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 464 | dev->transfer_status = 0; |
Ludovic Desroches | 7c3fe64 | 2012-11-13 16:43:21 +0100 | [diff] [blame] | 465 | |
| 466 | if (!dev->buf_len) { |
| 467 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_QUICK); |
| 468 | at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP); |
| 469 | } else if (dev->msg->flags & I2C_M_RD) { |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 470 | unsigned start_flags = AT91_TWI_START; |
| 471 | |
| 472 | if (at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_RXRDY) { |
| 473 | dev_err(dev->dev, "RXRDY still set!"); |
| 474 | at91_twi_read(dev, AT91_TWI_RHR); |
| 475 | } |
| 476 | |
| 477 | /* if only one byte is to be read, immediately stop transfer */ |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 478 | if (!has_alt_cmd && dev->buf_len <= 1 && |
| 479 | !(dev->msg->flags & I2C_M_RECV_LEN)) |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 480 | start_flags |= AT91_TWI_STOP; |
| 481 | at91_twi_write(dev, AT91_TWI_CR, start_flags); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 482 | /* |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 483 | * When using dma without alternative command mode, the last |
| 484 | * byte has to be read manually in order to not send the stop |
| 485 | * command too late and then to receive extra data. |
| 486 | * In practice, there are some issues if you use the dma to |
| 487 | * read n-1 bytes because of latency. |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 488 | * Reading n-2 bytes with dma and the two last ones manually |
| 489 | * seems to be the best solution. |
| 490 | */ |
| 491 | if (dev->use_dma && (dev->buf_len > AT91_I2C_DMA_THRESHOLD)) { |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 492 | at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_NACK); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 493 | at91_twi_read_data_dma(dev); |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 494 | } else { |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 495 | at91_twi_write(dev, AT91_TWI_IER, |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 496 | AT91_TWI_TXCOMP | |
| 497 | AT91_TWI_NACK | |
| 498 | AT91_TWI_RXRDY); |
| 499 | } |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 500 | } else { |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 501 | if (dev->use_dma && (dev->buf_len > AT91_I2C_DMA_THRESHOLD)) { |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 502 | at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_NACK); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 503 | at91_twi_write_data_dma(dev); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 504 | } else { |
| 505 | at91_twi_write_next_byte(dev); |
| 506 | at91_twi_write(dev, AT91_TWI_IER, |
Cyrille Pitchen | 93563a6 | 2015-06-09 18:22:14 +0200 | [diff] [blame] | 507 | AT91_TWI_TXCOMP | |
| 508 | AT91_TWI_NACK | |
| 509 | AT91_TWI_TXRDY); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 510 | } |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 511 | } |
| 512 | |
Nicholas Mc Guire | 1c42aca | 2015-02-08 11:12:07 -0500 | [diff] [blame] | 513 | time_left = wait_for_completion_timeout(&dev->cmd_complete, |
| 514 | dev->adapter.timeout); |
| 515 | if (time_left == 0) { |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 516 | dev->transfer_status |= at91_twi_read(dev, AT91_TWI_SR); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 517 | dev_err(dev->dev, "controller timed out\n"); |
| 518 | at91_init_twi_bus(dev); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 519 | ret = -ETIMEDOUT; |
| 520 | goto error; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 521 | } |
| 522 | if (dev->transfer_status & AT91_TWI_NACK) { |
| 523 | dev_dbg(dev->dev, "received nack\n"); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 524 | ret = -EREMOTEIO; |
| 525 | goto error; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 526 | } |
| 527 | if (dev->transfer_status & AT91_TWI_OVRE) { |
| 528 | dev_err(dev->dev, "overrun while reading\n"); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 529 | ret = -EIO; |
| 530 | goto error; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 531 | } |
| 532 | if (has_unre_flag && dev->transfer_status & AT91_TWI_UNRE) { |
| 533 | dev_err(dev->dev, "underrun while writing\n"); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 534 | ret = -EIO; |
| 535 | goto error; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 536 | } |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 537 | if (has_alt_cmd && (dev->transfer_status & AT91_TWI_LOCK)) { |
| 538 | dev_err(dev->dev, "tx locked\n"); |
| 539 | ret = -EIO; |
| 540 | goto error; |
| 541 | } |
Marek Roszko | 75b81f3 | 2014-08-20 21:39:41 -0400 | [diff] [blame] | 542 | if (dev->recv_len_abort) { |
| 543 | dev_err(dev->dev, "invalid smbus block length recvd\n"); |
| 544 | ret = -EPROTO; |
| 545 | goto error; |
| 546 | } |
| 547 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 548 | dev_dbg(dev->dev, "transfer complete\n"); |
| 549 | |
| 550 | return 0; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 551 | |
| 552 | error: |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 553 | /* first stop DMA transfer if still in progress */ |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 554 | at91_twi_dma_cleanup(dev); |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 555 | /* then flush THR/FIFO and unlock TX if locked */ |
| 556 | if (has_alt_cmd && (dev->transfer_status & AT91_TWI_LOCK)) { |
| 557 | dev_dbg(dev->dev, "unlock tx\n"); |
| 558 | at91_twi_write(dev, AT91_TWI_CR, |
| 559 | AT91_TWI_THRCLR | AT91_TWI_LOCKCLR); |
| 560 | } |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 561 | return ret; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num) |
| 565 | { |
| 566 | struct at91_twi_dev *dev = i2c_get_adapdata(adap); |
| 567 | int ret; |
| 568 | unsigned int_addr_flag = 0; |
| 569 | struct i2c_msg *m_start = msg; |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 570 | bool is_read, use_alt_cmd = false; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 571 | |
| 572 | dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num); |
| 573 | |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 574 | ret = pm_runtime_get_sync(dev->dev); |
| 575 | if (ret < 0) |
| 576 | goto out; |
| 577 | |
Wolfram Sang | a740584 | 2015-01-07 12:24:10 +0100 | [diff] [blame] | 578 | if (num == 2) { |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 579 | int internal_address = 0; |
| 580 | int i; |
| 581 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 582 | /* 1st msg is put into the internal address, start with 2nd */ |
| 583 | m_start = &msg[1]; |
| 584 | for (i = 0; i < msg->len; ++i) { |
| 585 | const unsigned addr = msg->buf[msg->len - 1 - i]; |
| 586 | |
| 587 | internal_address |= addr << (8 * i); |
| 588 | int_addr_flag += AT91_TWI_IADRSZ_1; |
| 589 | } |
| 590 | at91_twi_write(dev, AT91_TWI_IADR, internal_address); |
| 591 | } |
| 592 | |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 593 | is_read = (m_start->flags & I2C_M_RD); |
| 594 | if (dev->pdata->has_alt_cmd) { |
| 595 | if (m_start->len > 0) { |
| 596 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMEN); |
| 597 | at91_twi_write(dev, AT91_TWI_ACR, |
| 598 | AT91_TWI_ACR_DATAL(m_start->len) | |
| 599 | ((is_read) ? AT91_TWI_ACR_DIR : 0)); |
| 600 | use_alt_cmd = true; |
| 601 | } else { |
| 602 | at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_ACMDIS); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | at91_twi_write(dev, AT91_TWI_MMR, |
| 607 | (m_start->addr << 16) | |
| 608 | int_addr_flag | |
| 609 | ((!use_alt_cmd && is_read) ? AT91_TWI_MREAD : 0)); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 610 | |
| 611 | dev->buf_len = m_start->len; |
| 612 | dev->buf = m_start->buf; |
| 613 | dev->msg = m_start; |
Marek Roszko | 75b81f3 | 2014-08-20 21:39:41 -0400 | [diff] [blame] | 614 | dev->recv_len_abort = false; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 615 | |
| 616 | ret = at91_do_twi_transfer(dev); |
| 617 | |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 618 | ret = (ret < 0) ? ret : num; |
| 619 | out: |
| 620 | pm_runtime_mark_last_busy(dev->dev); |
| 621 | pm_runtime_put_autosuspend(dev->dev); |
| 622 | |
| 623 | return ret; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Wolfram Sang | a740584 | 2015-01-07 12:24:10 +0100 | [diff] [blame] | 626 | /* |
| 627 | * The hardware can handle at most two messages concatenated by a |
| 628 | * repeated start via it's internal address feature. |
| 629 | */ |
| 630 | static struct i2c_adapter_quirks at91_twi_quirks = { |
| 631 | .flags = I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | I2C_AQ_COMB_SAME_ADDR, |
| 632 | .max_comb_1st_msg_len = 3, |
| 633 | }; |
| 634 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 635 | static u32 at91_twi_func(struct i2c_adapter *adapter) |
| 636 | { |
| 637 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
| 638 | | I2C_FUNC_SMBUS_READ_BLOCK_DATA; |
| 639 | } |
| 640 | |
| 641 | static struct i2c_algorithm at91_twi_algorithm = { |
| 642 | .master_xfer = at91_twi_xfer, |
| 643 | .functionality = at91_twi_func, |
| 644 | }; |
| 645 | |
| 646 | static struct at91_twi_pdata at91rm9200_config = { |
| 647 | .clk_max_div = 5, |
| 648 | .clk_offset = 3, |
| 649 | .has_unre_flag = true, |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 650 | .has_alt_cmd = false, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 651 | }; |
| 652 | |
| 653 | static struct at91_twi_pdata at91sam9261_config = { |
| 654 | .clk_max_div = 5, |
| 655 | .clk_offset = 4, |
| 656 | .has_unre_flag = false, |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 657 | .has_alt_cmd = false, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | static struct at91_twi_pdata at91sam9260_config = { |
| 661 | .clk_max_div = 7, |
| 662 | .clk_offset = 4, |
| 663 | .has_unre_flag = false, |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 664 | .has_alt_cmd = false, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | static struct at91_twi_pdata at91sam9g20_config = { |
| 668 | .clk_max_div = 7, |
| 669 | .clk_offset = 4, |
| 670 | .has_unre_flag = false, |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 671 | .has_alt_cmd = false, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 672 | }; |
| 673 | |
| 674 | static struct at91_twi_pdata at91sam9g10_config = { |
| 675 | .clk_max_div = 7, |
| 676 | .clk_offset = 4, |
| 677 | .has_unre_flag = false, |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 678 | .has_alt_cmd = false, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | static const struct platform_device_id at91_twi_devtypes[] = { |
| 682 | { |
| 683 | .name = "i2c-at91rm9200", |
| 684 | .driver_data = (unsigned long) &at91rm9200_config, |
| 685 | }, { |
| 686 | .name = "i2c-at91sam9261", |
| 687 | .driver_data = (unsigned long) &at91sam9261_config, |
| 688 | }, { |
| 689 | .name = "i2c-at91sam9260", |
| 690 | .driver_data = (unsigned long) &at91sam9260_config, |
| 691 | }, { |
| 692 | .name = "i2c-at91sam9g20", |
| 693 | .driver_data = (unsigned long) &at91sam9g20_config, |
| 694 | }, { |
| 695 | .name = "i2c-at91sam9g10", |
| 696 | .driver_data = (unsigned long) &at91sam9g10_config, |
| 697 | }, { |
| 698 | /* sentinel */ |
| 699 | } |
| 700 | }; |
| 701 | |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 702 | #if defined(CONFIG_OF) |
Joachim Eastwood | 4182b43 | 2013-02-09 19:14:00 +0100 | [diff] [blame] | 703 | static struct at91_twi_pdata at91sam9x5_config = { |
| 704 | .clk_max_div = 7, |
| 705 | .clk_offset = 4, |
| 706 | .has_unre_flag = false, |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 707 | .has_alt_cmd = false, |
| 708 | }; |
| 709 | |
| 710 | static struct at91_twi_pdata sama5d2_config = { |
| 711 | .clk_max_div = 7, |
| 712 | .clk_offset = 4, |
| 713 | .has_unre_flag = true, |
| 714 | .has_alt_cmd = true, |
Joachim Eastwood | 4182b43 | 2013-02-09 19:14:00 +0100 | [diff] [blame] | 715 | }; |
| 716 | |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 717 | static const struct of_device_id atmel_twi_dt_ids[] = { |
| 718 | { |
Joachim Eastwood | 631056c | 2012-12-05 22:42:12 +0100 | [diff] [blame] | 719 | .compatible = "atmel,at91rm9200-i2c", |
| 720 | .data = &at91rm9200_config, |
| 721 | } , { |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 722 | .compatible = "atmel,at91sam9260-i2c", |
| 723 | .data = &at91sam9260_config, |
| 724 | } , { |
jean-jacques hiblot | d9a3afc | 2014-01-15 14:17:13 +0100 | [diff] [blame] | 725 | .compatible = "atmel,at91sam9261-i2c", |
| 726 | .data = &at91sam9261_config, |
| 727 | } , { |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 728 | .compatible = "atmel,at91sam9g20-i2c", |
| 729 | .data = &at91sam9g20_config, |
| 730 | } , { |
| 731 | .compatible = "atmel,at91sam9g10-i2c", |
| 732 | .data = &at91sam9g10_config, |
| 733 | }, { |
| 734 | .compatible = "atmel,at91sam9x5-i2c", |
| 735 | .data = &at91sam9x5_config, |
| 736 | }, { |
Cyrille Pitchen | 0ef6f32 | 2015-06-09 18:22:17 +0200 | [diff] [blame^] | 737 | .compatible = "atmel,sama5d2-i2c", |
| 738 | .data = &sama5d2_config, |
| 739 | }, { |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 740 | /* sentinel */ |
| 741 | } |
| 742 | }; |
| 743 | MODULE_DEVICE_TABLE(of, atmel_twi_dt_ids); |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 744 | #endif |
| 745 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 746 | static int at91_twi_configure_dma(struct at91_twi_dev *dev, u32 phy_addr) |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 747 | { |
| 748 | int ret = 0; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 749 | struct dma_slave_config slave_config; |
| 750 | struct at91_twi_dma *dma = &dev->dma; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 751 | |
| 752 | memset(&slave_config, 0, sizeof(slave_config)); |
| 753 | slave_config.src_addr = (dma_addr_t)phy_addr + AT91_TWI_RHR; |
| 754 | slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 755 | slave_config.src_maxburst = 1; |
| 756 | slave_config.dst_addr = (dma_addr_t)phy_addr + AT91_TWI_THR; |
| 757 | slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 758 | slave_config.dst_maxburst = 1; |
| 759 | slave_config.device_fc = false; |
| 760 | |
Ludovic Desroches | 727f9c2 | 2014-11-21 14:44:32 +0100 | [diff] [blame] | 761 | dma->chan_tx = dma_request_slave_channel_reason(dev->dev, "tx"); |
| 762 | if (IS_ERR(dma->chan_tx)) { |
| 763 | ret = PTR_ERR(dma->chan_tx); |
| 764 | dma->chan_tx = NULL; |
Ludovic Desroches | d877a72 | 2013-04-15 02:16:56 +0000 | [diff] [blame] | 765 | goto error; |
| 766 | } |
| 767 | |
Ludovic Desroches | 727f9c2 | 2014-11-21 14:44:32 +0100 | [diff] [blame] | 768 | dma->chan_rx = dma_request_slave_channel_reason(dev->dev, "rx"); |
| 769 | if (IS_ERR(dma->chan_rx)) { |
| 770 | ret = PTR_ERR(dma->chan_rx); |
| 771 | dma->chan_rx = NULL; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 772 | goto error; |
| 773 | } |
| 774 | |
| 775 | slave_config.direction = DMA_MEM_TO_DEV; |
| 776 | if (dmaengine_slave_config(dma->chan_tx, &slave_config)) { |
| 777 | dev_err(dev->dev, "failed to configure tx channel\n"); |
| 778 | ret = -EINVAL; |
| 779 | goto error; |
| 780 | } |
| 781 | |
| 782 | slave_config.direction = DMA_DEV_TO_MEM; |
| 783 | if (dmaengine_slave_config(dma->chan_rx, &slave_config)) { |
| 784 | dev_err(dev->dev, "failed to configure rx channel\n"); |
| 785 | ret = -EINVAL; |
| 786 | goto error; |
| 787 | } |
| 788 | |
| 789 | sg_init_table(&dma->sg, 1); |
| 790 | dma->buf_mapped = false; |
| 791 | dma->xfer_in_progress = false; |
Ludovic Desroches | 727f9c2 | 2014-11-21 14:44:32 +0100 | [diff] [blame] | 792 | dev->use_dma = true; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 793 | |
| 794 | dev_info(dev->dev, "using %s (tx) and %s (rx) for DMA transfers\n", |
| 795 | dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); |
| 796 | |
| 797 | return ret; |
| 798 | |
| 799 | error: |
Ludovic Desroches | 727f9c2 | 2014-11-21 14:44:32 +0100 | [diff] [blame] | 800 | if (ret != -EPROBE_DEFER) |
| 801 | dev_info(dev->dev, "can't use DMA, error %d\n", ret); |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 802 | if (dma->chan_rx) |
| 803 | dma_release_channel(dma->chan_rx); |
| 804 | if (dma->chan_tx) |
| 805 | dma_release_channel(dma->chan_tx); |
| 806 | return ret; |
| 807 | } |
| 808 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 809 | static struct at91_twi_pdata *at91_twi_get_driver_data( |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 810 | struct platform_device *pdev) |
| 811 | { |
| 812 | if (pdev->dev.of_node) { |
| 813 | const struct of_device_id *match; |
| 814 | match = of_match_node(atmel_twi_dt_ids, pdev->dev.of_node); |
| 815 | if (!match) |
| 816 | return NULL; |
Ludovic Desroches | cd32e6c | 2012-11-23 17:03:16 +0100 | [diff] [blame] | 817 | return (struct at91_twi_pdata *)match->data; |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 818 | } |
| 819 | return (struct at91_twi_pdata *) platform_get_device_id(pdev)->driver_data; |
| 820 | } |
| 821 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 822 | static int at91_twi_probe(struct platform_device *pdev) |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 823 | { |
| 824 | struct at91_twi_dev *dev; |
| 825 | struct resource *mem; |
| 826 | int rc; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 827 | u32 phy_addr; |
Marek Roszko | 75b6c4b | 2014-03-11 00:25:38 -0400 | [diff] [blame] | 828 | u32 bus_clk_rate; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 829 | |
| 830 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
| 831 | if (!dev) |
| 832 | return -ENOMEM; |
| 833 | init_completion(&dev->cmd_complete); |
| 834 | dev->dev = &pdev->dev; |
| 835 | |
| 836 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 837 | if (!mem) |
| 838 | return -ENODEV; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 839 | phy_addr = mem->start; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 840 | |
| 841 | dev->pdata = at91_twi_get_driver_data(pdev); |
| 842 | if (!dev->pdata) |
| 843 | return -ENODEV; |
| 844 | |
Thierry Reding | 84dbf80 | 2013-01-21 11:09:03 +0100 | [diff] [blame] | 845 | dev->base = devm_ioremap_resource(&pdev->dev, mem); |
| 846 | if (IS_ERR(dev->base)) |
| 847 | return PTR_ERR(dev->base); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 848 | |
| 849 | dev->irq = platform_get_irq(pdev, 0); |
| 850 | if (dev->irq < 0) |
| 851 | return dev->irq; |
| 852 | |
| 853 | rc = devm_request_irq(&pdev->dev, dev->irq, atmel_twi_interrupt, 0, |
| 854 | dev_name(dev->dev), dev); |
| 855 | if (rc) { |
| 856 | dev_err(dev->dev, "Cannot get irq %d: %d\n", dev->irq, rc); |
| 857 | return rc; |
| 858 | } |
| 859 | |
| 860 | platform_set_drvdata(pdev, dev); |
| 861 | |
| 862 | dev->clk = devm_clk_get(dev->dev, NULL); |
| 863 | if (IS_ERR(dev->clk)) { |
| 864 | dev_err(dev->dev, "no clock defined\n"); |
| 865 | return -ENODEV; |
| 866 | } |
| 867 | clk_prepare_enable(dev->clk); |
| 868 | |
Arnd Bergmann | dc6df6e | 2014-11-21 14:44:31 +0100 | [diff] [blame] | 869 | if (dev->dev->of_node) { |
Ludovic Desroches | 727f9c2 | 2014-11-21 14:44:32 +0100 | [diff] [blame] | 870 | rc = at91_twi_configure_dma(dev, phy_addr); |
| 871 | if (rc == -EPROBE_DEFER) |
| 872 | return rc; |
Ludovic Desroches | 60937b2 | 2012-11-23 10:09:04 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Marek Roszko | 75b6c4b | 2014-03-11 00:25:38 -0400 | [diff] [blame] | 875 | rc = of_property_read_u32(dev->dev->of_node, "clock-frequency", |
| 876 | &bus_clk_rate); |
| 877 | if (rc) |
| 878 | bus_clk_rate = DEFAULT_TWI_CLK_HZ; |
| 879 | |
| 880 | at91_calc_twi_clock(dev, bus_clk_rate); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 881 | at91_init_twi_bus(dev); |
| 882 | |
| 883 | snprintf(dev->adapter.name, sizeof(dev->adapter.name), "AT91"); |
| 884 | i2c_set_adapdata(&dev->adapter, dev); |
| 885 | dev->adapter.owner = THIS_MODULE; |
Wolfram Sang | b850579 | 2014-07-10 13:46:22 +0200 | [diff] [blame] | 886 | dev->adapter.class = I2C_CLASS_DEPRECATED; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 887 | dev->adapter.algo = &at91_twi_algorithm; |
Wolfram Sang | a740584 | 2015-01-07 12:24:10 +0100 | [diff] [blame] | 888 | dev->adapter.quirks = &at91_twi_quirks; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 889 | dev->adapter.dev.parent = dev->dev; |
| 890 | dev->adapter.nr = pdev->id; |
| 891 | dev->adapter.timeout = AT91_I2C_TIMEOUT; |
Ludovic Desroches | 70d46a2 | 2012-09-12 08:42:14 +0200 | [diff] [blame] | 892 | dev->adapter.dev.of_node = pdev->dev.of_node; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 893 | |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 894 | pm_runtime_set_autosuspend_delay(dev->dev, AUTOSUSPEND_TIMEOUT); |
| 895 | pm_runtime_use_autosuspend(dev->dev); |
| 896 | pm_runtime_set_active(dev->dev); |
| 897 | pm_runtime_enable(dev->dev); |
| 898 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 899 | rc = i2c_add_numbered_adapter(&dev->adapter); |
| 900 | if (rc) { |
| 901 | dev_err(dev->dev, "Adapter %s registration failed\n", |
| 902 | dev->adapter.name); |
| 903 | clk_disable_unprepare(dev->clk); |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 904 | |
| 905 | pm_runtime_disable(dev->dev); |
| 906 | pm_runtime_set_suspended(dev->dev); |
| 907 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 908 | return rc; |
| 909 | } |
| 910 | |
| 911 | dev_info(dev->dev, "AT91 i2c bus driver.\n"); |
| 912 | return 0; |
| 913 | } |
| 914 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 915 | static int at91_twi_remove(struct platform_device *pdev) |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 916 | { |
| 917 | struct at91_twi_dev *dev = platform_get_drvdata(pdev); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 918 | |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 919 | i2c_del_adapter(&dev->adapter); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 920 | clk_disable_unprepare(dev->clk); |
| 921 | |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 922 | pm_runtime_disable(dev->dev); |
| 923 | pm_runtime_set_suspended(dev->dev); |
| 924 | |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 925 | return 0; |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | #ifdef CONFIG_PM |
| 929 | |
| 930 | static int at91_twi_runtime_suspend(struct device *dev) |
| 931 | { |
| 932 | struct at91_twi_dev *twi_dev = dev_get_drvdata(dev); |
| 933 | |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 934 | clk_disable_unprepare(twi_dev->clk); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 935 | |
Wenyou Yang | 62d10c4 | 2014-11-10 09:55:52 +0800 | [diff] [blame] | 936 | pinctrl_pm_select_sleep_state(dev); |
| 937 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | static int at91_twi_runtime_resume(struct device *dev) |
| 942 | { |
| 943 | struct at91_twi_dev *twi_dev = dev_get_drvdata(dev); |
| 944 | |
Wenyou Yang | 62d10c4 | 2014-11-10 09:55:52 +0800 | [diff] [blame] | 945 | pinctrl_pm_select_default_state(dev); |
| 946 | |
Wenyou Yang | d64a818 | 2014-10-24 14:50:15 +0800 | [diff] [blame] | 947 | return clk_prepare_enable(twi_dev->clk); |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 948 | } |
| 949 | |
Wenyou Yang | 3676529 | 2014-10-24 14:50:16 +0800 | [diff] [blame] | 950 | static int at91_twi_suspend_noirq(struct device *dev) |
| 951 | { |
| 952 | if (!pm_runtime_status_suspended(dev)) |
| 953 | at91_twi_runtime_suspend(dev); |
| 954 | |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | static int at91_twi_resume_noirq(struct device *dev) |
| 959 | { |
| 960 | int ret; |
| 961 | |
| 962 | if (!pm_runtime_status_suspended(dev)) { |
| 963 | ret = at91_twi_runtime_resume(dev); |
| 964 | if (ret) |
| 965 | return ret; |
| 966 | } |
| 967 | |
| 968 | pm_runtime_mark_last_busy(dev); |
| 969 | pm_request_autosuspend(dev); |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 974 | static const struct dev_pm_ops at91_twi_pm = { |
Wenyou Yang | 3676529 | 2014-10-24 14:50:16 +0800 | [diff] [blame] | 975 | .suspend_noirq = at91_twi_suspend_noirq, |
| 976 | .resume_noirq = at91_twi_resume_noirq, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 977 | .runtime_suspend = at91_twi_runtime_suspend, |
| 978 | .runtime_resume = at91_twi_runtime_resume, |
| 979 | }; |
| 980 | |
| 981 | #define at91_twi_pm_ops (&at91_twi_pm) |
| 982 | #else |
| 983 | #define at91_twi_pm_ops NULL |
| 984 | #endif |
| 985 | |
| 986 | static struct platform_driver at91_twi_driver = { |
| 987 | .probe = at91_twi_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 988 | .remove = at91_twi_remove, |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 989 | .id_table = at91_twi_devtypes, |
| 990 | .driver = { |
| 991 | .name = "at91_i2c", |
Sachin Kamat | 600abea | 2013-03-14 00:13:03 +0000 | [diff] [blame] | 992 | .of_match_table = of_match_ptr(atmel_twi_dt_ids), |
Nikolaus Voss | fac368a | 2011-11-08 11:49:46 +0100 | [diff] [blame] | 993 | .pm = at91_twi_pm_ops, |
| 994 | }, |
| 995 | }; |
| 996 | |
| 997 | static int __init at91_twi_init(void) |
| 998 | { |
| 999 | return platform_driver_register(&at91_twi_driver); |
| 1000 | } |
| 1001 | |
| 1002 | static void __exit at91_twi_exit(void) |
| 1003 | { |
| 1004 | platform_driver_unregister(&at91_twi_driver); |
| 1005 | } |
| 1006 | |
| 1007 | subsys_initcall(at91_twi_init); |
| 1008 | module_exit(at91_twi_exit); |
| 1009 | |
| 1010 | MODULE_AUTHOR("Nikolaus Voss <n.voss@weinmann.de>"); |
| 1011 | MODULE_DESCRIPTION("I2C (TWI) driver for Atmel AT91"); |
| 1012 | MODULE_LICENSE("GPL"); |
| 1013 | MODULE_ALIAS("platform:at91_i2c"); |