Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* linux/drivers/i2c/busses/i2c-s3c2410.c |
| 2 | * |
Daniel Silverstone | c564e6a | 2009-03-13 13:53:46 +0000 | [diff] [blame] | 3 | * Copyright (C) 2004,2005,2009 Simtec Electronics |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
| 6 | * S3C2410 I2C Controller |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | |
| 26 | #include <linux/i2c.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/init.h> |
| 28 | #include <linux/time.h> |
| 29 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/errno.h> |
| 32 | #include <linux/err.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 34 | #include <linux/clk.h> |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 35 | #include <linux/cpufreq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
H Hartley Sweeten | 2178218 | 2010-05-21 18:41:01 +0200 | [diff] [blame] | 37 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Ben Dooks | 9498cb7 | 2008-10-30 10:14:33 +0000 | [diff] [blame] | 41 | #include <plat/regs-iic.h> |
| 42 | #include <plat/iic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* i2c controller state */ |
| 45 | |
| 46 | enum s3c24xx_i2c_state { |
| 47 | STATE_IDLE, |
| 48 | STATE_START, |
| 49 | STATE_READ, |
| 50 | STATE_WRITE, |
| 51 | STATE_STOP |
| 52 | }; |
| 53 | |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 54 | enum s3c24xx_i2c_type { |
| 55 | TYPE_S3C2410, |
| 56 | TYPE_S3C2440, |
| 57 | }; |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | struct s3c24xx_i2c { |
| 60 | spinlock_t lock; |
| 61 | wait_queue_head_t wait; |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 62 | unsigned int suspended:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | struct i2c_msg *msg; |
| 65 | unsigned int msg_num; |
| 66 | unsigned int msg_idx; |
| 67 | unsigned int msg_ptr; |
| 68 | |
Ben Dooks | e00a8cd | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 69 | unsigned int tx_setup; |
Ben Dooks | e0d1ec9 | 2008-10-31 16:10:30 +0000 | [diff] [blame] | 70 | unsigned int irq; |
Ben Dooks | e00a8cd | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | enum s3c24xx_i2c_state state; |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 73 | unsigned long clkrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | void __iomem *regs; |
| 76 | struct clk *clk; |
| 77 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | struct resource *ioarea; |
| 79 | struct i2c_adapter adap; |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 80 | |
Thomas Abraham | 4fd81eb | 2011-09-13 09:46:04 +0530 | [diff] [blame^] | 81 | struct s3c2410_platform_i2c *pdata; |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_CPU_FREQ |
| 83 | struct notifier_block freq_transition; |
| 84 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Ben Dooks | 6a039ca | 2008-10-31 16:10:27 +0000 | [diff] [blame] | 87 | /* default platform data removed, dev should always carry data. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* s3c24xx_i2c_is2440() |
| 90 | * |
| 91 | * return true is this is an s3c2440 |
| 92 | */ |
| 93 | |
| 94 | static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) |
| 95 | { |
| 96 | struct platform_device *pdev = to_platform_device(i2c->dev); |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 97 | enum s3c24xx_i2c_type type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 99 | type = platform_get_device_id(pdev)->driver_data; |
| 100 | return type == TYPE_S3C2440; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* s3c24xx_i2c_master_complete |
| 104 | * |
| 105 | * complete the message and wake up the caller, using the given return code, |
| 106 | * or zero to mean ok. |
| 107 | */ |
| 108 | |
| 109 | static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret) |
| 110 | { |
| 111 | dev_dbg(i2c->dev, "master_complete %d\n", ret); |
| 112 | |
| 113 | i2c->msg_ptr = 0; |
| 114 | i2c->msg = NULL; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 115 | i2c->msg_idx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | i2c->msg_num = 0; |
| 117 | if (ret) |
| 118 | i2c->msg_idx = ret; |
| 119 | |
| 120 | wake_up(&i2c->wait); |
| 121 | } |
| 122 | |
| 123 | static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) |
| 124 | { |
| 125 | unsigned long tmp; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | tmp = readl(i2c->regs + S3C2410_IICCON); |
| 128 | writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c) |
| 132 | { |
| 133 | unsigned long tmp; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | tmp = readl(i2c->regs + S3C2410_IICCON); |
| 136 | writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* irq enable/disable functions */ |
| 140 | |
| 141 | static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c) |
| 142 | { |
| 143 | unsigned long tmp; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | tmp = readl(i2c->regs + S3C2410_IICCON); |
| 146 | writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); |
| 147 | } |
| 148 | |
| 149 | static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) |
| 150 | { |
| 151 | unsigned long tmp; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | tmp = readl(i2c->regs + S3C2410_IICCON); |
| 154 | writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /* s3c24xx_i2c_message_start |
| 159 | * |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 160 | * put the start of a message onto the bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | */ |
| 162 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 163 | static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct i2c_msg *msg) |
| 165 | { |
| 166 | unsigned int addr = (msg->addr & 0x7f) << 1; |
| 167 | unsigned long stat; |
| 168 | unsigned long iiccon; |
| 169 | |
| 170 | stat = 0; |
| 171 | stat |= S3C2410_IICSTAT_TXRXEN; |
| 172 | |
| 173 | if (msg->flags & I2C_M_RD) { |
| 174 | stat |= S3C2410_IICSTAT_MASTER_RX; |
| 175 | addr |= 1; |
| 176 | } else |
| 177 | stat |= S3C2410_IICSTAT_MASTER_TX; |
| 178 | |
| 179 | if (msg->flags & I2C_M_REV_DIR_ADDR) |
| 180 | addr ^= 1; |
| 181 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 182 | /* todo - check for wether ack wanted or not */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | s3c24xx_i2c_enable_ack(i2c); |
| 184 | |
| 185 | iiccon = readl(i2c->regs + S3C2410_IICCON); |
| 186 | writel(stat, i2c->regs + S3C2410_IICSTAT); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); |
| 189 | writeb(addr, i2c->regs + S3C2410_IICDS); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 190 | |
Ben Dooks | e00a8cd | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 191 | /* delay here to ensure the data byte has gotten onto the bus |
| 192 | * before the transaction is started */ |
| 193 | |
| 194 | ndelay(i2c->tx_setup); |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); |
| 197 | writel(iiccon, i2c->regs + S3C2410_IICCON); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 198 | |
| 199 | stat |= S3C2410_IICSTAT_START; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | writel(stat, i2c->regs + S3C2410_IICSTAT); |
| 201 | } |
| 202 | |
| 203 | static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) |
| 204 | { |
| 205 | unsigned long iicstat = readl(i2c->regs + S3C2410_IICSTAT); |
| 206 | |
| 207 | dev_dbg(i2c->dev, "STOP\n"); |
| 208 | |
| 209 | /* stop the transfer */ |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 210 | iicstat &= ~S3C2410_IICSTAT_START; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | writel(iicstat, i2c->regs + S3C2410_IICSTAT); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | i2c->state = STATE_STOP; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | s3c24xx_i2c_master_complete(i2c, ret); |
| 216 | s3c24xx_i2c_disable_irq(i2c); |
| 217 | } |
| 218 | |
| 219 | /* helper functions to determine the current state in the set of |
| 220 | * messages we are sending */ |
| 221 | |
| 222 | /* is_lastmsg() |
| 223 | * |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 224 | * returns TRUE if the current message is the last in the set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | */ |
| 226 | |
| 227 | static inline int is_lastmsg(struct s3c24xx_i2c *i2c) |
| 228 | { |
| 229 | return i2c->msg_idx >= (i2c->msg_num - 1); |
| 230 | } |
| 231 | |
| 232 | /* is_msglast |
| 233 | * |
| 234 | * returns TRUE if we this is the last byte in the current message |
| 235 | */ |
| 236 | |
| 237 | static inline int is_msglast(struct s3c24xx_i2c *i2c) |
| 238 | { |
| 239 | return i2c->msg_ptr == i2c->msg->len-1; |
| 240 | } |
| 241 | |
| 242 | /* is_msgend |
| 243 | * |
| 244 | * returns TRUE if we reached the end of the current message |
| 245 | */ |
| 246 | |
| 247 | static inline int is_msgend(struct s3c24xx_i2c *i2c) |
| 248 | { |
| 249 | return i2c->msg_ptr >= i2c->msg->len; |
| 250 | } |
| 251 | |
Huisung Kang | 1982051 | 2011-06-23 21:37:33 +0900 | [diff] [blame] | 252 | /* i2c_s3c_irq_nextbyte |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | * |
| 254 | * process an interrupt and work out what to do |
| 255 | */ |
| 256 | |
Huisung Kang | 1982051 | 2011-06-23 21:37:33 +0900 | [diff] [blame] | 257 | static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | unsigned long tmp; |
| 260 | unsigned char byte; |
| 261 | int ret = 0; |
| 262 | |
| 263 | switch (i2c->state) { |
| 264 | |
| 265 | case STATE_IDLE: |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 266 | dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | case STATE_STOP: |
Harvey Harrison | 08882d2 | 2008-04-22 22:16:47 +0200 | [diff] [blame] | 270 | dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 271 | s3c24xx_i2c_disable_irq(i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | goto out_ack; |
| 273 | |
| 274 | case STATE_START: |
| 275 | /* last thing we did was send a start condition on the |
| 276 | * bus, or started a new i2c message |
| 277 | */ |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 278 | |
Ben Dooks | 63f5c28 | 2008-07-01 11:59:42 +0100 | [diff] [blame] | 279 | if (iicstat & S3C2410_IICSTAT_LASTBIT && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { |
| 281 | /* ack was not received... */ |
| 282 | |
| 283 | dev_dbg(i2c->dev, "ack was not received\n"); |
Ben Dooks | 63f5c28 | 2008-07-01 11:59:42 +0100 | [diff] [blame] | 284 | s3c24xx_i2c_stop(i2c, -ENXIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | goto out_ack; |
| 286 | } |
| 287 | |
| 288 | if (i2c->msg->flags & I2C_M_RD) |
| 289 | i2c->state = STATE_READ; |
| 290 | else |
| 291 | i2c->state = STATE_WRITE; |
| 292 | |
| 293 | /* terminate the transfer if there is nothing to do |
Ben Dooks | 63f5c28 | 2008-07-01 11:59:42 +0100 | [diff] [blame] | 294 | * as this is used by the i2c probe to find devices. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | if (is_lastmsg(i2c) && i2c->msg->len == 0) { |
| 297 | s3c24xx_i2c_stop(i2c, 0); |
| 298 | goto out_ack; |
| 299 | } |
| 300 | |
| 301 | if (i2c->state == STATE_READ) |
| 302 | goto prepare_read; |
| 303 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 304 | /* fall through to the write state, as we will need to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | * send a byte as well */ |
| 306 | |
| 307 | case STATE_WRITE: |
| 308 | /* we are writing data to the device... check for the |
| 309 | * end of the message, and if so, work out what to do |
| 310 | */ |
| 311 | |
Ben Dooks | 2709781 | 2008-07-01 11:59:41 +0100 | [diff] [blame] | 312 | if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) { |
| 313 | if (iicstat & S3C2410_IICSTAT_LASTBIT) { |
| 314 | dev_dbg(i2c->dev, "WRITE: No Ack\n"); |
| 315 | |
| 316 | s3c24xx_i2c_stop(i2c, -ECONNREFUSED); |
| 317 | goto out_ack; |
| 318 | } |
| 319 | } |
| 320 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 321 | retry_write: |
Ben Dooks | 2709781 | 2008-07-01 11:59:41 +0100 | [diff] [blame] | 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (!is_msgend(i2c)) { |
| 324 | byte = i2c->msg->buf[i2c->msg_ptr++]; |
| 325 | writeb(byte, i2c->regs + S3C2410_IICDS); |
Ben Dooks | e00a8cd | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 326 | |
| 327 | /* delay after writing the byte to allow the |
| 328 | * data setup time on the bus, as writing the |
| 329 | * data to the register causes the first bit |
| 330 | * to appear on SDA, and SCL will change as |
| 331 | * soon as the interrupt is acknowledged */ |
| 332 | |
| 333 | ndelay(i2c->tx_setup); |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } else if (!is_lastmsg(i2c)) { |
| 336 | /* we need to go to the next i2c message */ |
| 337 | |
| 338 | dev_dbg(i2c->dev, "WRITE: Next Message\n"); |
| 339 | |
| 340 | i2c->msg_ptr = 0; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 341 | i2c->msg_idx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | i2c->msg++; |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | /* check to see if we need to do another message */ |
| 345 | if (i2c->msg->flags & I2C_M_NOSTART) { |
| 346 | |
| 347 | if (i2c->msg->flags & I2C_M_RD) { |
| 348 | /* cannot do this, the controller |
| 349 | * forces us to send a new START |
| 350 | * when we change direction */ |
| 351 | |
| 352 | s3c24xx_i2c_stop(i2c, -EINVAL); |
| 353 | } |
| 354 | |
| 355 | goto retry_write; |
| 356 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* send the new start */ |
| 358 | s3c24xx_i2c_message_start(i2c, i2c->msg); |
| 359 | i2c->state = STATE_START; |
| 360 | } |
| 361 | |
| 362 | } else { |
| 363 | /* send stop */ |
| 364 | |
| 365 | s3c24xx_i2c_stop(i2c, 0); |
| 366 | } |
| 367 | break; |
| 368 | |
| 369 | case STATE_READ: |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 370 | /* we have a byte of data in the data register, do |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | * something with it, and then work out wether we are |
| 372 | * going to do any more read/write |
| 373 | */ |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | byte = readb(i2c->regs + S3C2410_IICDS); |
| 376 | i2c->msg->buf[i2c->msg_ptr++] = byte; |
| 377 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 378 | prepare_read: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (is_msglast(i2c)) { |
| 380 | /* last byte of buffer */ |
| 381 | |
| 382 | if (is_lastmsg(i2c)) |
| 383 | s3c24xx_i2c_disable_ack(i2c); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } else if (is_msgend(i2c)) { |
| 386 | /* ok, we've read the entire buffer, see if there |
| 387 | * is anything else we need to do */ |
| 388 | |
| 389 | if (is_lastmsg(i2c)) { |
| 390 | /* last message, send stop and complete */ |
| 391 | dev_dbg(i2c->dev, "READ: Send Stop\n"); |
| 392 | |
| 393 | s3c24xx_i2c_stop(i2c, 0); |
| 394 | } else { |
| 395 | /* go to the next transfer */ |
| 396 | dev_dbg(i2c->dev, "READ: Next Transfer\n"); |
| 397 | |
| 398 | i2c->msg_ptr = 0; |
| 399 | i2c->msg_idx++; |
| 400 | i2c->msg++; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | break; |
| 405 | } |
| 406 | |
| 407 | /* acknowlegde the IRQ and get back on with the work */ |
| 408 | |
| 409 | out_ack: |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 410 | tmp = readl(i2c->regs + S3C2410_IICCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | tmp &= ~S3C2410_IICCON_IRQPEND; |
| 412 | writel(tmp, i2c->regs + S3C2410_IICCON); |
| 413 | out: |
| 414 | return ret; |
| 415 | } |
| 416 | |
| 417 | /* s3c24xx_i2c_irq |
| 418 | * |
| 419 | * top level IRQ servicing routine |
| 420 | */ |
| 421 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 422 | static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
| 424 | struct s3c24xx_i2c *i2c = dev_id; |
| 425 | unsigned long status; |
| 426 | unsigned long tmp; |
| 427 | |
| 428 | status = readl(i2c->regs + S3C2410_IICSTAT); |
| 429 | |
| 430 | if (status & S3C2410_IICSTAT_ARBITR) { |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 431 | /* deal with arbitration loss */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | dev_err(i2c->dev, "deal with arbitration loss\n"); |
| 433 | } |
| 434 | |
| 435 | if (i2c->state == STATE_IDLE) { |
| 436 | dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); |
| 437 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 438 | tmp = readl(i2c->regs + S3C2410_IICCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | tmp &= ~S3C2410_IICCON_IRQPEND; |
| 440 | writel(tmp, i2c->regs + S3C2410_IICCON); |
| 441 | goto out; |
| 442 | } |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | /* pretty much this leaves us with the fact that we've |
| 445 | * transmitted or received whatever byte we last sent */ |
| 446 | |
Huisung Kang | 1982051 | 2011-06-23 21:37:33 +0900 | [diff] [blame] | 447 | i2c_s3c_irq_nextbyte(i2c, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | out: |
| 450 | return IRQ_HANDLED; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /* s3c24xx_i2c_set_master |
| 455 | * |
| 456 | * get the i2c bus for a master transaction |
| 457 | */ |
| 458 | |
| 459 | static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) |
| 460 | { |
| 461 | unsigned long iicstat; |
| 462 | int timeout = 400; |
| 463 | |
| 464 | while (timeout-- > 0) { |
| 465 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | if (!(iicstat & S3C2410_IICSTAT_BUSBUSY)) |
| 468 | return 0; |
| 469 | |
| 470 | msleep(1); |
| 471 | } |
| 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | return -ETIMEDOUT; |
| 474 | } |
| 475 | |
| 476 | /* s3c24xx_i2c_doxfer |
| 477 | * |
| 478 | * this starts an i2c transfer |
| 479 | */ |
| 480 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 481 | static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, |
| 482 | struct i2c_msg *msgs, int num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Mark Brown | 1bc2962 | 2010-04-02 14:15:09 +0100 | [diff] [blame] | 484 | unsigned long iicstat, timeout; |
| 485 | int spins = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | int ret; |
| 487 | |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 488 | if (i2c->suspended) |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 489 | return -EIO; |
| 490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | ret = s3c24xx_i2c_set_master(i2c); |
| 492 | if (ret != 0) { |
| 493 | dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); |
| 494 | ret = -EAGAIN; |
| 495 | goto out; |
| 496 | } |
| 497 | |
| 498 | spin_lock_irq(&i2c->lock); |
| 499 | |
| 500 | i2c->msg = msgs; |
| 501 | i2c->msg_num = num; |
| 502 | i2c->msg_ptr = 0; |
| 503 | i2c->msg_idx = 0; |
| 504 | i2c->state = STATE_START; |
| 505 | |
| 506 | s3c24xx_i2c_enable_irq(i2c); |
| 507 | s3c24xx_i2c_message_start(i2c, msgs); |
| 508 | spin_unlock_irq(&i2c->lock); |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); |
| 511 | |
| 512 | ret = i2c->msg_idx; |
| 513 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 514 | /* having these next two as dev_err() makes life very |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | * noisy when doing an i2cdetect */ |
| 516 | |
| 517 | if (timeout == 0) |
| 518 | dev_dbg(i2c->dev, "timeout\n"); |
| 519 | else if (ret != num) |
| 520 | dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret); |
| 521 | |
| 522 | /* ensure the stop has been through the bus */ |
| 523 | |
Mark Brown | 1bc2962 | 2010-04-02 14:15:09 +0100 | [diff] [blame] | 524 | dev_dbg(i2c->dev, "waiting for bus idle\n"); |
| 525 | |
| 526 | /* first, try busy waiting briefly */ |
| 527 | do { |
| 528 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); |
| 529 | } while ((iicstat & S3C2410_IICSTAT_START) && --spins); |
| 530 | |
| 531 | /* if that timed out sleep */ |
| 532 | if (!spins) { |
| 533 | msleep(1); |
| 534 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); |
| 535 | } |
| 536 | |
| 537 | if (iicstat & S3C2410_IICSTAT_START) |
| 538 | dev_warn(i2c->dev, "timeout waiting for bus idle\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | out: |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | /* s3c24xx_i2c_xfer |
| 545 | * |
| 546 | * first port of call from the i2c bus code when an message needs |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 547 | * transferring across the i2c bus. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | */ |
| 549 | |
| 550 | static int s3c24xx_i2c_xfer(struct i2c_adapter *adap, |
| 551 | struct i2c_msg *msgs, int num) |
| 552 | { |
| 553 | struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data; |
| 554 | int retry; |
| 555 | int ret; |
| 556 | |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 557 | clk_enable(i2c->clk); |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | for (retry = 0; retry < adap->retries; retry++) { |
| 560 | |
| 561 | ret = s3c24xx_i2c_doxfer(i2c, msgs, num); |
| 562 | |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 563 | if (ret != -EAGAIN) { |
| 564 | clk_disable(i2c->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | return ret; |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry); |
| 569 | |
| 570 | udelay(100); |
| 571 | } |
| 572 | |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 573 | clk_disable(i2c->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | return -EREMOTEIO; |
| 575 | } |
| 576 | |
| 577 | /* declare our i2c functionality */ |
| 578 | static u32 s3c24xx_i2c_func(struct i2c_adapter *adap) |
| 579 | { |
| 580 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING; |
| 581 | } |
| 582 | |
| 583 | /* i2c bus registration info */ |
| 584 | |
Jean Delvare | 8f9082c | 2006-09-03 22:39:46 +0200 | [diff] [blame] | 585 | static const struct i2c_algorithm s3c24xx_i2c_algorithm = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | .master_xfer = s3c24xx_i2c_xfer, |
| 587 | .functionality = s3c24xx_i2c_func, |
| 588 | }; |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | /* s3c24xx_i2c_calcdivisor |
| 591 | * |
| 592 | * return the divisor settings for a given frequency |
| 593 | */ |
| 594 | |
| 595 | static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted, |
| 596 | unsigned int *div1, unsigned int *divs) |
| 597 | { |
| 598 | unsigned int calc_divs = clkin / wanted; |
| 599 | unsigned int calc_div1; |
| 600 | |
| 601 | if (calc_divs > (16*16)) |
| 602 | calc_div1 = 512; |
| 603 | else |
| 604 | calc_div1 = 16; |
| 605 | |
| 606 | calc_divs += calc_div1-1; |
| 607 | calc_divs /= calc_div1; |
| 608 | |
| 609 | if (calc_divs == 0) |
| 610 | calc_divs = 1; |
| 611 | if (calc_divs > 17) |
| 612 | calc_divs = 17; |
| 613 | |
| 614 | *divs = calc_divs; |
| 615 | *div1 = calc_div1; |
| 616 | |
| 617 | return clkin / (calc_divs * calc_div1); |
| 618 | } |
| 619 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 620 | /* s3c24xx_i2c_clockrate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | * |
| 622 | * work out a divisor for the user requested frequency setting, |
| 623 | * either by the requested frequency, or scanning the acceptable |
| 624 | * range of frequencies until something is found |
| 625 | */ |
| 626 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 627 | static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Thomas Abraham | 4fd81eb | 2011-09-13 09:46:04 +0530 | [diff] [blame^] | 629 | struct s3c2410_platform_i2c *pdata = i2c->pdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | unsigned long clkin = clk_get_rate(i2c->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | unsigned int divs, div1; |
Daniel Silverstone | c564e6a | 2009-03-13 13:53:46 +0000 | [diff] [blame] | 632 | unsigned long target_frequency; |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 633 | u32 iiccon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | int freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 636 | i2c->clkrate = clkin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | clkin /= 1000; /* clkin now in KHz */ |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 638 | |
Daniel Silverstone | c564e6a | 2009-03-13 13:53:46 +0000 | [diff] [blame] | 639 | dev_dbg(i2c->dev, "pdata desired frequency %lu\n", pdata->frequency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Daniel Silverstone | c564e6a | 2009-03-13 13:53:46 +0000 | [diff] [blame] | 641 | target_frequency = pdata->frequency ? pdata->frequency : 100000; |
| 642 | |
| 643 | target_frequency /= 1000; /* Target frequency now in KHz */ |
| 644 | |
| 645 | freq = s3c24xx_i2c_calcdivisor(clkin, target_frequency, &div1, &divs); |
| 646 | |
| 647 | if (freq > target_frequency) { |
| 648 | dev_err(i2c->dev, |
| 649 | "Unable to achieve desired frequency %luKHz." \ |
| 650 | " Lowest achievable %dKHz\n", target_frequency, freq); |
| 651 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | *got = freq; |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 655 | |
| 656 | iiccon = readl(i2c->regs + S3C2410_IICCON); |
| 657 | iiccon &= ~(S3C2410_IICCON_SCALEMASK | S3C2410_IICCON_TXDIV_512); |
| 658 | iiccon |= (divs-1); |
| 659 | |
| 660 | if (div1 == 512) |
| 661 | iiccon |= S3C2410_IICCON_TXDIV_512; |
| 662 | |
| 663 | writel(iiccon, i2c->regs + S3C2410_IICCON); |
| 664 | |
Ben Dooks | a192f71 | 2009-03-27 10:52:13 +0000 | [diff] [blame] | 665 | if (s3c24xx_i2c_is2440(i2c)) { |
| 666 | unsigned long sda_delay; |
| 667 | |
| 668 | if (pdata->sda_delay) { |
MyungJoo Ham | 7031307a | 2010-09-30 15:54:46 +0200 | [diff] [blame] | 669 | sda_delay = clkin * pdata->sda_delay; |
| 670 | sda_delay = DIV_ROUND_UP(sda_delay, 1000000); |
Ben Dooks | a192f71 | 2009-03-27 10:52:13 +0000 | [diff] [blame] | 671 | sda_delay = DIV_ROUND_UP(sda_delay, 5); |
| 672 | if (sda_delay > 3) |
| 673 | sda_delay = 3; |
| 674 | sda_delay |= S3C2410_IICLC_FILTER_ON; |
| 675 | } else |
| 676 | sda_delay = 0; |
| 677 | |
| 678 | dev_dbg(i2c->dev, "IICLC=%08lx\n", sda_delay); |
| 679 | writel(sda_delay, i2c->regs + S3C2440_IICLC); |
| 680 | } |
| 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 685 | #ifdef CONFIG_CPU_FREQ |
| 686 | |
| 687 | #define freq_to_i2c(_n) container_of(_n, struct s3c24xx_i2c, freq_transition) |
| 688 | |
| 689 | static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb, |
| 690 | unsigned long val, void *data) |
| 691 | { |
| 692 | struct s3c24xx_i2c *i2c = freq_to_i2c(nb); |
| 693 | unsigned long flags; |
| 694 | unsigned int got; |
| 695 | int delta_f; |
| 696 | int ret; |
| 697 | |
| 698 | delta_f = clk_get_rate(i2c->clk) - i2c->clkrate; |
| 699 | |
| 700 | /* if we're post-change and the input clock has slowed down |
| 701 | * or at pre-change and the clock is about to speed up, then |
| 702 | * adjust our clock rate. <0 is slow, >0 speedup. |
| 703 | */ |
| 704 | |
| 705 | if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) || |
| 706 | (val == CPUFREQ_PRECHANGE && delta_f > 0)) { |
| 707 | spin_lock_irqsave(&i2c->lock, flags); |
| 708 | ret = s3c24xx_i2c_clockrate(i2c, &got); |
| 709 | spin_unlock_irqrestore(&i2c->lock, flags); |
| 710 | |
| 711 | if (ret < 0) |
| 712 | dev_err(i2c->dev, "cannot find frequency\n"); |
| 713 | else |
| 714 | dev_info(i2c->dev, "setting freq %d\n", got); |
| 715 | } |
| 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c) |
| 721 | { |
| 722 | i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition; |
| 723 | |
| 724 | return cpufreq_register_notifier(&i2c->freq_transition, |
| 725 | CPUFREQ_TRANSITION_NOTIFIER); |
| 726 | } |
| 727 | |
| 728 | static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) |
| 729 | { |
| 730 | cpufreq_unregister_notifier(&i2c->freq_transition, |
| 731 | CPUFREQ_TRANSITION_NOTIFIER); |
| 732 | } |
| 733 | |
| 734 | #else |
| 735 | static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c) |
| 736 | { |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) |
| 741 | { |
| 742 | } |
| 743 | #endif |
| 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | /* s3c24xx_i2c_init |
| 746 | * |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 747 | * initialise the controller, set the IO lines and frequency |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | */ |
| 749 | |
| 750 | static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) |
| 751 | { |
| 752 | unsigned long iicon = S3C2410_IICCON_IRQEN | S3C2410_IICCON_ACKEN; |
| 753 | struct s3c2410_platform_i2c *pdata; |
| 754 | unsigned int freq; |
| 755 | |
| 756 | /* get the plafrom data */ |
| 757 | |
Thomas Abraham | 4fd81eb | 2011-09-13 09:46:04 +0530 | [diff] [blame^] | 758 | pdata = i2c->pdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
| 760 | /* inititalise the gpio */ |
| 761 | |
Ben Dooks | 8be310a | 2008-10-31 16:10:25 +0000 | [diff] [blame] | 762 | if (pdata->cfg_gpio) |
| 763 | pdata->cfg_gpio(to_platform_device(i2c->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | /* write slave address */ |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD); |
| 768 | |
| 769 | dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); |
| 770 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 771 | writel(iicon, i2c->regs + S3C2410_IICCON); |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | /* we need to work out the divisors for the clock... */ |
| 774 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 775 | if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) { |
| 776 | writel(0, i2c->regs + S3C2410_IICCON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | dev_err(i2c->dev, "cannot meet bus frequency required\n"); |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | |
| 781 | /* todo - check that the i2c lines aren't being dragged anywhere */ |
| 782 | |
| 783 | dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); |
| 784 | dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return 0; |
| 787 | } |
| 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /* s3c24xx_i2c_probe |
| 790 | * |
| 791 | * called by the bus driver when a suitable device is found |
| 792 | */ |
| 793 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 794 | static int s3c24xx_i2c_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
Ben Dooks | 692acbd | 2008-10-31 16:10:28 +0000 | [diff] [blame] | 796 | struct s3c24xx_i2c *i2c; |
Thomas Abraham | 4fd81eb | 2011-09-13 09:46:04 +0530 | [diff] [blame^] | 797 | struct s3c2410_platform_i2c *pdata = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | struct resource *res; |
| 799 | int ret; |
| 800 | |
Ben Dooks | 6a039ca | 2008-10-31 16:10:27 +0000 | [diff] [blame] | 801 | pdata = pdev->dev.platform_data; |
| 802 | if (!pdata) { |
| 803 | dev_err(&pdev->dev, "no platform data\n"); |
| 804 | return -EINVAL; |
| 805 | } |
Ben Dooks | 399dee2 | 2008-07-28 12:04:06 +0100 | [diff] [blame] | 806 | |
Ben Dooks | 692acbd | 2008-10-31 16:10:28 +0000 | [diff] [blame] | 807 | i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL); |
| 808 | if (!i2c) { |
| 809 | dev_err(&pdev->dev, "no memory for state\n"); |
| 810 | return -ENOMEM; |
| 811 | } |
| 812 | |
Thomas Abraham | 4fd81eb | 2011-09-13 09:46:04 +0530 | [diff] [blame^] | 813 | i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 814 | if (!i2c->pdata) { |
| 815 | ret = -ENOMEM; |
| 816 | goto err_noclk; |
| 817 | } |
| 818 | |
| 819 | if (pdata) |
| 820 | memcpy(i2c->pdata, pdata, sizeof(*pdata)); |
| 821 | |
Ben Dooks | 692acbd | 2008-10-31 16:10:28 +0000 | [diff] [blame] | 822 | strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name)); |
| 823 | i2c->adap.owner = THIS_MODULE; |
| 824 | i2c->adap.algo = &s3c24xx_i2c_algorithm; |
| 825 | i2c->adap.retries = 2; |
| 826 | i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
| 827 | i2c->tx_setup = 50; |
| 828 | |
| 829 | spin_lock_init(&i2c->lock); |
| 830 | init_waitqueue_head(&i2c->wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
| 832 | /* find the clock and enable it */ |
| 833 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 834 | i2c->dev = &pdev->dev; |
| 835 | i2c->clk = clk_get(&pdev->dev, "i2c"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | if (IS_ERR(i2c->clk)) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 837 | dev_err(&pdev->dev, "cannot get clock\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | ret = -ENOENT; |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 839 | goto err_noclk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 842 | dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | clk_enable(i2c->clk); |
| 845 | |
| 846 | /* map the registers */ |
| 847 | |
| 848 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 849 | if (res == NULL) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 850 | dev_err(&pdev->dev, "cannot find IO resource\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | ret = -ENOENT; |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 852 | goto err_clk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Ben Dooks | 933a2ae | 2009-06-14 14:04:20 +0100 | [diff] [blame] | 855 | i2c->ioarea = request_mem_region(res->start, resource_size(res), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | pdev->name); |
| 857 | |
| 858 | if (i2c->ioarea == NULL) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 859 | dev_err(&pdev->dev, "cannot request IO\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | ret = -ENXIO; |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 861 | goto err_clk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Ben Dooks | 933a2ae | 2009-06-14 14:04:20 +0100 | [diff] [blame] | 864 | i2c->regs = ioremap(res->start, resource_size(res)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | if (i2c->regs == NULL) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 867 | dev_err(&pdev->dev, "cannot map IO\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | ret = -ENXIO; |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 869 | goto err_ioarea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 872 | dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", |
| 873 | i2c->regs, i2c->ioarea, res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | /* setup info block for the i2c core */ |
| 876 | |
| 877 | i2c->adap.algo_data = i2c; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 878 | i2c->adap.dev.parent = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
| 880 | /* initialise the i2c controller */ |
| 881 | |
| 882 | ret = s3c24xx_i2c_init(i2c); |
| 883 | if (ret != 0) |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 884 | goto err_iomap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | /* find the IRQ for this unit (note, this relies on the init call to |
Ben Dooks | 3d0911b | 2008-10-31 16:10:24 +0000 | [diff] [blame] | 887 | * ensure no current IRQs pending |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | */ |
| 889 | |
Ben Dooks | e0d1ec9 | 2008-10-31 16:10:30 +0000 | [diff] [blame] | 890 | i2c->irq = ret = platform_get_irq(pdev, 0); |
| 891 | if (ret <= 0) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 892 | dev_err(&pdev->dev, "cannot find IRQ\n"); |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 893 | goto err_iomap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Ben Dooks | e0d1ec9 | 2008-10-31 16:10:30 +0000 | [diff] [blame] | 896 | ret = request_irq(i2c->irq, s3c24xx_i2c_irq, IRQF_DISABLED, |
| 897 | dev_name(&pdev->dev), i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
| 899 | if (ret != 0) { |
Ben Dooks | e0d1ec9 | 2008-10-31 16:10:30 +0000 | [diff] [blame] | 900 | dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 901 | goto err_iomap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 904 | ret = s3c24xx_i2c_register_cpufreq(i2c); |
| 905 | if (ret < 0) { |
| 906 | dev_err(&pdev->dev, "failed to register cpufreq notifier\n"); |
| 907 | goto err_irq; |
| 908 | } |
| 909 | |
Ben Dooks | 399dee2 | 2008-07-28 12:04:06 +0100 | [diff] [blame] | 910 | /* Note, previous versions of the driver used i2c_add_adapter() |
| 911 | * to add the bus at any number. We now pass the bus number via |
| 912 | * the platform data, so if unset it will now default to always |
| 913 | * being bus 0. |
| 914 | */ |
| 915 | |
Thomas Abraham | 4fd81eb | 2011-09-13 09:46:04 +0530 | [diff] [blame^] | 916 | i2c->adap.nr = i2c->pdata->bus_num; |
Ben Dooks | 399dee2 | 2008-07-28 12:04:06 +0100 | [diff] [blame] | 917 | |
| 918 | ret = i2c_add_numbered_adapter(&i2c->adap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | if (ret < 0) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 920 | dev_err(&pdev->dev, "failed to add bus to i2c core\n"); |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 921 | goto err_cpufreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 924 | platform_set_drvdata(pdev, i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Jean Delvare | 22e965c | 2009-01-07 14:29:16 +0100 | [diff] [blame] | 926 | dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev)); |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 927 | clk_disable(i2c->clk); |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 928 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 930 | err_cpufreq: |
| 931 | s3c24xx_i2c_deregister_cpufreq(i2c); |
| 932 | |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 933 | err_irq: |
Ben Dooks | e0d1ec9 | 2008-10-31 16:10:30 +0000 | [diff] [blame] | 934 | free_irq(i2c->irq, i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 936 | err_iomap: |
| 937 | iounmap(i2c->regs); |
| 938 | |
| 939 | err_ioarea: |
| 940 | release_resource(i2c->ioarea); |
| 941 | kfree(i2c->ioarea); |
| 942 | |
| 943 | err_clk: |
| 944 | clk_disable(i2c->clk); |
| 945 | clk_put(i2c->clk); |
| 946 | |
| 947 | err_noclk: |
Ben Dooks | 692acbd | 2008-10-31 16:10:28 +0000 | [diff] [blame] | 948 | kfree(i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | return ret; |
| 950 | } |
| 951 | |
| 952 | /* s3c24xx_i2c_remove |
| 953 | * |
| 954 | * called when device is removed from the bus |
| 955 | */ |
| 956 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 957 | static int s3c24xx_i2c_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 959 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 960 | |
Ben Dooks | 61c7cff | 2008-07-28 12:04:07 +0100 | [diff] [blame] | 961 | s3c24xx_i2c_deregister_cpufreq(i2c); |
| 962 | |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 963 | i2c_del_adapter(&i2c->adap); |
Ben Dooks | e0d1ec9 | 2008-10-31 16:10:30 +0000 | [diff] [blame] | 964 | free_irq(i2c->irq, i2c); |
Ben Dooks | 5b68790 | 2007-05-01 23:26:35 +0200 | [diff] [blame] | 965 | |
| 966 | clk_disable(i2c->clk); |
| 967 | clk_put(i2c->clk); |
| 968 | |
| 969 | iounmap(i2c->regs); |
| 970 | |
| 971 | release_resource(i2c->ioarea); |
| 972 | kfree(i2c->ioarea); |
Ben Dooks | 692acbd | 2008-10-31 16:10:28 +0000 | [diff] [blame] | 973 | kfree(i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | #ifdef CONFIG_PM |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 979 | static int s3c24xx_i2c_suspend_noirq(struct device *dev) |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 980 | { |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 981 | struct platform_device *pdev = to_platform_device(dev); |
| 982 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); |
| 983 | |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 984 | i2c->suspended = 1; |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 985 | |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 986 | return 0; |
| 987 | } |
| 988 | |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 989 | static int s3c24xx_i2c_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 991 | struct platform_device *pdev = to_platform_device(dev); |
| 992 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 993 | |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 994 | i2c->suspended = 0; |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 995 | clk_enable(i2c->clk); |
Ben Dooks | be44f01 | 2008-10-31 16:10:22 +0000 | [diff] [blame] | 996 | s3c24xx_i2c_init(i2c); |
Arnaud Patard (Rtp) | d2360b8 | 2010-07-15 15:06:14 +0200 | [diff] [blame] | 997 | clk_disable(i2c->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1002 | static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 1003 | .suspend_noirq = s3c24xx_i2c_suspend_noirq, |
| 1004 | .resume = s3c24xx_i2c_resume, |
| 1005 | }; |
| 1006 | |
| 1007 | #define S3C24XX_DEV_PM_OPS (&s3c24xx_i2c_dev_pm_ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | #else |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 1009 | #define S3C24XX_DEV_PM_OPS NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | #endif |
| 1011 | |
| 1012 | /* device driver for platform bus bits */ |
| 1013 | |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1014 | static struct platform_device_id s3c24xx_driver_ids[] = { |
| 1015 | { |
| 1016 | .name = "s3c2410-i2c", |
| 1017 | .driver_data = TYPE_S3C2410, |
| 1018 | }, { |
| 1019 | .name = "s3c2440-i2c", |
| 1020 | .driver_data = TYPE_S3C2440, |
| 1021 | }, { }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | }; |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1023 | MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1025 | static struct platform_driver s3c24xx_i2c_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | .probe = s3c24xx_i2c_probe, |
| 1027 | .remove = s3c24xx_i2c_remove, |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1028 | .id_table = s3c24xx_driver_ids, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1029 | .driver = { |
| 1030 | .owner = THIS_MODULE, |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1031 | .name = "s3c-i2c", |
Magnus Damm | 6a6c6189 | 2009-07-08 13:22:47 +0200 | [diff] [blame] | 1032 | .pm = S3C24XX_DEV_PM_OPS, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1033 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | }; |
| 1035 | |
| 1036 | static int __init i2c_adap_s3c_init(void) |
| 1037 | { |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1038 | return platform_driver_register(&s3c24xx_i2c_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | } |
Mark Brown | 18dc83a | 2009-02-26 16:29:22 +0000 | [diff] [blame] | 1040 | subsys_initcall(i2c_adap_s3c_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | static void __exit i2c_adap_s3c_exit(void) |
| 1043 | { |
Ben Dooks | 7d85ccd | 2009-06-12 10:45:29 +0100 | [diff] [blame] | 1044 | platform_driver_unregister(&s3c24xx_i2c_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | module_exit(i2c_adap_s3c_exit); |
| 1047 | |
| 1048 | MODULE_DESCRIPTION("S3C24XX I2C Bus driver"); |
| 1049 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); |
| 1050 | MODULE_LICENSE("GPL"); |