Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * SuperH Mobile I2C Controller |
| 3 | * |
| 4 | * Copyright (C) 2008 Magnus Damm |
| 5 | * |
| 6 | * Portions of the code based on out-of-tree driver i2c-sh7343.c |
| 7 | * Copyright (c) 2006 Carlos Munoz <carlos@kenati.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License |
| 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 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/i2c.h> |
Magnus Damm | ad33707 | 2012-03-30 17:44:02 +0900 | [diff] [blame] | 30 | #include <linux/of_i2c.h> |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 31 | #include <linux/err.h> |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 33 | #include <linux/clk.h> |
| 34 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Magnus Damm | 81f8115 | 2011-04-28 13:25:36 +0900 | [diff] [blame] | 36 | #include <linux/i2c/i2c-sh_mobile.h> |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 37 | |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 38 | /* Transmit operation: */ |
| 39 | /* */ |
| 40 | /* 0 byte transmit */ |
| 41 | /* BUS: S A8 ACK P */ |
| 42 | /* IRQ: DTE WAIT */ |
| 43 | /* ICIC: */ |
| 44 | /* ICCR: 0x94 0x90 */ |
| 45 | /* ICDR: A8 */ |
| 46 | /* */ |
| 47 | /* 1 byte transmit */ |
| 48 | /* BUS: S A8 ACK D8(1) ACK P */ |
| 49 | /* IRQ: DTE WAIT WAIT */ |
| 50 | /* ICIC: -DTE */ |
| 51 | /* ICCR: 0x94 0x90 */ |
| 52 | /* ICDR: A8 D8(1) */ |
| 53 | /* */ |
| 54 | /* 2 byte transmit */ |
| 55 | /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P */ |
| 56 | /* IRQ: DTE WAIT WAIT WAIT */ |
| 57 | /* ICIC: -DTE */ |
| 58 | /* ICCR: 0x94 0x90 */ |
| 59 | /* ICDR: A8 D8(1) D8(2) */ |
| 60 | /* */ |
| 61 | /* 3 bytes or more, +---------+ gets repeated */ |
| 62 | /* */ |
| 63 | /* */ |
| 64 | /* Receive operation: */ |
| 65 | /* */ |
| 66 | /* 0 byte receive - not supported since slave may hold SDA low */ |
| 67 | /* */ |
| 68 | /* 1 byte receive [TX] | [RX] */ |
| 69 | /* BUS: S A8 ACK | D8(1) ACK P */ |
| 70 | /* IRQ: DTE WAIT | WAIT DTE */ |
| 71 | /* ICIC: -DTE | +DTE */ |
| 72 | /* ICCR: 0x94 0x81 | 0xc0 */ |
| 73 | /* ICDR: A8 | D8(1) */ |
| 74 | /* */ |
| 75 | /* 2 byte receive [TX]| [RX] */ |
| 76 | /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK P */ |
| 77 | /* IRQ: DTE WAIT | WAIT WAIT DTE */ |
| 78 | /* ICIC: -DTE | +DTE */ |
| 79 | /* ICCR: 0x94 0x81 | 0xc0 */ |
| 80 | /* ICDR: A8 | D8(1) D8(2) */ |
| 81 | /* */ |
| 82 | /* 3 byte receive [TX] | [RX] */ |
| 83 | /* BUS: S A8 ACK | D8(1) ACK D8(2) ACK D8(3) ACK P */ |
| 84 | /* IRQ: DTE WAIT | WAIT WAIT WAIT DTE */ |
| 85 | /* ICIC: -DTE | +DTE */ |
| 86 | /* ICCR: 0x94 0x81 | 0xc0 */ |
| 87 | /* ICDR: A8 | D8(1) D8(2) D8(3) */ |
| 88 | /* */ |
| 89 | /* 4 bytes or more, this part is repeated +---------+ */ |
| 90 | /* */ |
| 91 | /* */ |
| 92 | /* Interrupt order and BUSY flag */ |
| 93 | /* ___ _ */ |
| 94 | /* SDA ___\___XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXAAAAAAAAA___/ */ |
| 95 | /* SCL \_/1\_/2\_/3\_/4\_/5\_/6\_/7\_/8\___/9\_____/ */ |
| 96 | /* */ |
| 97 | /* S D7 D6 D5 D4 D3 D2 D1 D0 P */ |
| 98 | /* ___ */ |
| 99 | /* WAIT IRQ ________________________________/ \___________ */ |
| 100 | /* TACK IRQ ____________________________________/ \_______ */ |
| 101 | /* DTE IRQ __________________________________________/ \_ */ |
| 102 | /* AL IRQ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ |
| 103 | /* _______________________________________________ */ |
| 104 | /* BUSY __/ \_ */ |
| 105 | /* */ |
| 106 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 107 | enum sh_mobile_i2c_op { |
| 108 | OP_START = 0, |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 109 | OP_TX_FIRST, |
| 110 | OP_TX, |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 111 | OP_TX_STOP, |
| 112 | OP_TX_TO_RX, |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 113 | OP_RX, |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 114 | OP_RX_STOP, |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 115 | OP_RX_STOP_DATA, |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | struct sh_mobile_i2c_data { |
| 119 | struct device *dev; |
| 120 | void __iomem *reg; |
| 121 | struct i2c_adapter adap; |
Magnus Damm | 81f8115 | 2011-04-28 13:25:36 +0900 | [diff] [blame] | 122 | unsigned long bus_speed; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 123 | struct clk *clk; |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 124 | u_int8_t icic; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 125 | u_int8_t iccl; |
| 126 | u_int8_t icch; |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 127 | u_int8_t flags; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 128 | |
| 129 | spinlock_t lock; |
| 130 | wait_queue_head_t wait; |
| 131 | struct i2c_msg *msg; |
| 132 | int pos; |
| 133 | int sr; |
| 134 | }; |
| 135 | |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 136 | #define IIC_FLAG_HAS_ICIC67 (1 << 0) |
| 137 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 138 | #define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */ |
| 139 | |
| 140 | /* Register offsets */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 141 | #define ICDR 0x00 |
| 142 | #define ICCR 0x04 |
| 143 | #define ICSR 0x08 |
| 144 | #define ICIC 0x0c |
| 145 | #define ICCL 0x10 |
| 146 | #define ICCH 0x14 |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 147 | |
| 148 | /* Register bits */ |
| 149 | #define ICCR_ICE 0x80 |
| 150 | #define ICCR_RACK 0x40 |
| 151 | #define ICCR_TRS 0x10 |
| 152 | #define ICCR_BBSY 0x04 |
| 153 | #define ICCR_SCP 0x01 |
| 154 | |
| 155 | #define ICSR_SCLM 0x80 |
| 156 | #define ICSR_SDAM 0x40 |
| 157 | #define SW_DONE 0x20 |
| 158 | #define ICSR_BUSY 0x10 |
| 159 | #define ICSR_AL 0x08 |
| 160 | #define ICSR_TACK 0x04 |
| 161 | #define ICSR_WAIT 0x02 |
| 162 | #define ICSR_DTE 0x01 |
| 163 | |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 164 | #define ICIC_ICCLB8 0x80 |
| 165 | #define ICIC_ICCHB8 0x40 |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 166 | #define ICIC_ALE 0x08 |
| 167 | #define ICIC_TACKE 0x04 |
| 168 | #define ICIC_WAITE 0x02 |
| 169 | #define ICIC_DTEE 0x01 |
| 170 | |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 171 | static void iic_wr(struct sh_mobile_i2c_data *pd, int offs, unsigned char data) |
| 172 | { |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 173 | if (offs == ICIC) |
| 174 | data |= pd->icic; |
| 175 | |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 176 | iowrite8(data, pd->reg + offs); |
| 177 | } |
| 178 | |
| 179 | static unsigned char iic_rd(struct sh_mobile_i2c_data *pd, int offs) |
| 180 | { |
| 181 | return ioread8(pd->reg + offs); |
| 182 | } |
| 183 | |
| 184 | static void iic_set_clr(struct sh_mobile_i2c_data *pd, int offs, |
| 185 | unsigned char set, unsigned char clr) |
| 186 | { |
| 187 | iic_wr(pd, offs, (iic_rd(pd, offs) | set) & ~clr); |
| 188 | } |
| 189 | |
Shinya Kuribayashi | 7b0e629 | 2012-10-24 19:56:51 +0900 | [diff] [blame^] | 190 | static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 191 | { |
Magnus Damm | a5616bd | 2008-10-31 20:20:55 +0900 | [diff] [blame] | 192 | unsigned long i2c_clk; |
| 193 | u_int32_t num; |
| 194 | u_int32_t denom; |
| 195 | u_int32_t tmp; |
| 196 | |
Magnus Damm | a5616bd | 2008-10-31 20:20:55 +0900 | [diff] [blame] | 197 | /* Get clock rate after clock is enabled */ |
Shinya Kuribayashi | 7b0e629 | 2012-10-24 19:56:51 +0900 | [diff] [blame^] | 198 | clk_enable(pd->clk); |
Magnus Damm | a5616bd | 2008-10-31 20:20:55 +0900 | [diff] [blame] | 199 | i2c_clk = clk_get_rate(pd->clk); |
| 200 | |
| 201 | /* Calculate the value for iccl. From the data sheet: |
| 202 | * iccl = (p clock / transfer rate) * (L / (L + H)) |
| 203 | * where L and H are the SCL low/high ratio (5/4 in this case). |
| 204 | * We also round off the result. |
| 205 | */ |
| 206 | num = i2c_clk * 5; |
Magnus Damm | 81f8115 | 2011-04-28 13:25:36 +0900 | [diff] [blame] | 207 | denom = pd->bus_speed * 9; |
Magnus Damm | a5616bd | 2008-10-31 20:20:55 +0900 | [diff] [blame] | 208 | tmp = num * 10 / denom; |
| 209 | if (tmp % 10 >= 5) |
| 210 | pd->iccl = (u_int8_t)((num/denom) + 1); |
| 211 | else |
| 212 | pd->iccl = (u_int8_t)(num/denom); |
| 213 | |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 214 | /* one more bit of ICCL in ICIC */ |
| 215 | if (pd->flags & IIC_FLAG_HAS_ICIC67) { |
| 216 | if ((num/denom) > 0xff) |
| 217 | pd->icic |= ICIC_ICCLB8; |
| 218 | else |
| 219 | pd->icic &= ~ICIC_ICCLB8; |
| 220 | } |
| 221 | |
Magnus Damm | a5616bd | 2008-10-31 20:20:55 +0900 | [diff] [blame] | 222 | /* Calculate the value for icch. From the data sheet: |
| 223 | icch = (p clock / transfer rate) * (H / (L + H)) */ |
| 224 | num = i2c_clk * 4; |
| 225 | tmp = num * 10 / denom; |
| 226 | if (tmp % 10 >= 5) |
| 227 | pd->icch = (u_int8_t)((num/denom) + 1); |
| 228 | else |
| 229 | pd->icch = (u_int8_t)(num/denom); |
| 230 | |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 231 | /* one more bit of ICCH in ICIC */ |
| 232 | if (pd->flags & IIC_FLAG_HAS_ICIC67) { |
| 233 | if ((num/denom) > 0xff) |
| 234 | pd->icic |= ICIC_ICCHB8; |
| 235 | else |
| 236 | pd->icic &= ~ICIC_ICCHB8; |
| 237 | } |
| 238 | |
Shinya Kuribayashi | 7b0e629 | 2012-10-24 19:56:51 +0900 | [diff] [blame^] | 239 | clk_disable(pd->clk); |
| 240 | } |
| 241 | |
| 242 | static void activate_ch(struct sh_mobile_i2c_data *pd) |
| 243 | { |
| 244 | /* Wake up device and enable clock */ |
| 245 | pm_runtime_get_sync(pd->dev); |
| 246 | clk_enable(pd->clk); |
| 247 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 248 | /* Enable channel and configure rx ack */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 249 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 250 | |
| 251 | /* Mask all interrupts */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 252 | iic_wr(pd, ICIC, 0); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 253 | |
| 254 | /* Set the clock */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 255 | iic_wr(pd, ICCL, pd->iccl); |
| 256 | iic_wr(pd, ICCH, pd->icch); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | static void deactivate_ch(struct sh_mobile_i2c_data *pd) |
| 260 | { |
| 261 | /* Clear/disable interrupts */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 262 | iic_wr(pd, ICSR, 0); |
| 263 | iic_wr(pd, ICIC, 0); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 264 | |
| 265 | /* Disable channel */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 266 | iic_set_clr(pd, ICCR, 0, ICCR_ICE); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 267 | |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 268 | /* Disable clock and mark device as idle */ |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 269 | clk_disable(pd->clk); |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 270 | pm_runtime_put_sync(pd->dev); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, |
| 274 | enum sh_mobile_i2c_op op, unsigned char data) |
| 275 | { |
| 276 | unsigned char ret = 0; |
| 277 | unsigned long flags; |
| 278 | |
| 279 | dev_dbg(pd->dev, "op %d, data in 0x%02x\n", op, data); |
| 280 | |
| 281 | spin_lock_irqsave(&pd->lock, flags); |
| 282 | |
| 283 | switch (op) { |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 284 | case OP_START: /* issue start and trigger DTE interrupt */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 285 | iic_wr(pd, ICCR, 0x94); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 286 | break; |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 287 | case OP_TX_FIRST: /* disable DTE interrupt and write data */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 288 | iic_wr(pd, ICIC, ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
| 289 | iic_wr(pd, ICDR, data); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 290 | break; |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 291 | case OP_TX: /* write data */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 292 | iic_wr(pd, ICDR, data); |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 293 | break; |
| 294 | case OP_TX_STOP: /* write data and issue a stop afterwards */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 295 | iic_wr(pd, ICDR, data); |
| 296 | iic_wr(pd, ICCR, 0x90); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 297 | break; |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 298 | case OP_TX_TO_RX: /* select read mode */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 299 | iic_wr(pd, ICCR, 0x81); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 300 | break; |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 301 | case OP_RX: /* just read data */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 302 | ret = iic_rd(pd, ICDR); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 303 | break; |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 304 | case OP_RX_STOP: /* enable DTE interrupt, issue stop */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 305 | iic_wr(pd, ICIC, |
| 306 | ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
| 307 | iic_wr(pd, ICCR, 0xc0); |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 308 | break; |
| 309 | case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 310 | iic_wr(pd, ICIC, |
| 311 | ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
| 312 | ret = iic_rd(pd, ICDR); |
| 313 | iic_wr(pd, ICCR, 0xc0); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 314 | break; |
| 315 | } |
| 316 | |
| 317 | spin_unlock_irqrestore(&pd->lock, flags); |
| 318 | |
| 319 | dev_dbg(pd->dev, "op %d, data out 0x%02x\n", op, ret); |
| 320 | return ret; |
| 321 | } |
| 322 | |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 323 | static int sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd) |
| 324 | { |
| 325 | if (pd->pos == -1) |
| 326 | return 1; |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd) |
| 332 | { |
| 333 | if (pd->pos == (pd->msg->len - 1)) |
| 334 | return 1; |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd, |
| 340 | unsigned char *buf) |
| 341 | { |
| 342 | switch (pd->pos) { |
| 343 | case -1: |
| 344 | *buf = (pd->msg->addr & 0x7f) << 1; |
| 345 | *buf |= (pd->msg->flags & I2C_M_RD) ? 1 : 0; |
| 346 | break; |
| 347 | default: |
| 348 | *buf = pd->msg->buf[pd->pos]; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | static int sh_mobile_i2c_isr_tx(struct sh_mobile_i2c_data *pd) |
| 353 | { |
| 354 | unsigned char data; |
| 355 | |
| 356 | if (pd->pos == pd->msg->len) |
| 357 | return 1; |
| 358 | |
| 359 | sh_mobile_i2c_get_data(pd, &data); |
| 360 | |
| 361 | if (sh_mobile_i2c_is_last_byte(pd)) |
| 362 | i2c_op(pd, OP_TX_STOP, data); |
| 363 | else if (sh_mobile_i2c_is_first_byte(pd)) |
| 364 | i2c_op(pd, OP_TX_FIRST, data); |
| 365 | else |
| 366 | i2c_op(pd, OP_TX, data); |
| 367 | |
| 368 | pd->pos++; |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int sh_mobile_i2c_isr_rx(struct sh_mobile_i2c_data *pd) |
| 373 | { |
| 374 | unsigned char data; |
| 375 | int real_pos; |
| 376 | |
| 377 | do { |
| 378 | if (pd->pos <= -1) { |
| 379 | sh_mobile_i2c_get_data(pd, &data); |
| 380 | |
| 381 | if (sh_mobile_i2c_is_first_byte(pd)) |
| 382 | i2c_op(pd, OP_TX_FIRST, data); |
| 383 | else |
| 384 | i2c_op(pd, OP_TX, data); |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | if (pd->pos == 0) { |
| 389 | i2c_op(pd, OP_TX_TO_RX, 0); |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | real_pos = pd->pos - 2; |
| 394 | |
| 395 | if (pd->pos == pd->msg->len) { |
| 396 | if (real_pos < 0) { |
| 397 | i2c_op(pd, OP_RX_STOP, 0); |
| 398 | break; |
| 399 | } |
| 400 | data = i2c_op(pd, OP_RX_STOP_DATA, 0); |
| 401 | } else |
| 402 | data = i2c_op(pd, OP_RX, 0); |
| 403 | |
Magnus Damm | bff4056c8 | 2008-11-13 15:28:21 +0900 | [diff] [blame] | 404 | if (real_pos >= 0) |
| 405 | pd->msg->buf[real_pos] = data; |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 406 | } while (0); |
| 407 | |
| 408 | pd->pos++; |
| 409 | return pd->pos == (pd->msg->len + 2); |
| 410 | } |
| 411 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 412 | static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id) |
| 413 | { |
| 414 | struct platform_device *dev = dev_id; |
| 415 | struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 416 | unsigned char sr; |
| 417 | int wakeup; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 418 | |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 419 | sr = iic_rd(pd, ICSR); |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 420 | pd->sr |= sr; /* remember state */ |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 421 | |
| 422 | dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 423 | (pd->msg->flags & I2C_M_RD) ? "read" : "write", |
| 424 | pd->pos, pd->msg->len); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 425 | |
| 426 | if (sr & (ICSR_AL | ICSR_TACK)) { |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 427 | /* don't interrupt transaction - continue to issue stop */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 428 | iic_wr(pd, ICSR, sr & ~(ICSR_AL | ICSR_TACK)); |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 429 | wakeup = 0; |
| 430 | } else if (pd->msg->flags & I2C_M_RD) |
| 431 | wakeup = sh_mobile_i2c_isr_rx(pd); |
| 432 | else |
| 433 | wakeup = sh_mobile_i2c_isr_tx(pd); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 434 | |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 435 | if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 436 | iic_wr(pd, ICSR, sr & ~ICSR_WAIT); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 437 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 438 | if (wakeup) { |
| 439 | pd->sr |= SW_DONE; |
| 440 | wake_up(&pd->wait); |
| 441 | } |
| 442 | |
| 443 | return IRQ_HANDLED; |
| 444 | } |
| 445 | |
| 446 | static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg) |
| 447 | { |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 448 | if (usr_msg->len == 0 && (usr_msg->flags & I2C_M_RD)) { |
| 449 | dev_err(pd->dev, "Unsupported zero length i2c read\n"); |
| 450 | return -EIO; |
| 451 | } |
| 452 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 453 | /* Initialize channel registers */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 454 | iic_set_clr(pd, ICCR, 0, ICCR_ICE); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 455 | |
| 456 | /* Enable channel and configure rx ack */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 457 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 458 | |
| 459 | /* Set the clock */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 460 | iic_wr(pd, ICCL, pd->iccl); |
| 461 | iic_wr(pd, ICCH, pd->icch); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 462 | |
| 463 | pd->msg = usr_msg; |
| 464 | pd->pos = -1; |
| 465 | pd->sr = 0; |
| 466 | |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 467 | /* Enable all interrupts to begin with */ |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 468 | iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, |
| 473 | struct i2c_msg *msgs, |
| 474 | int num) |
| 475 | { |
| 476 | struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter); |
| 477 | struct i2c_msg *msg; |
| 478 | int err = 0; |
| 479 | u_int8_t val; |
| 480 | int i, k, retry_count; |
| 481 | |
| 482 | activate_ch(pd); |
| 483 | |
| 484 | /* Process all messages */ |
| 485 | for (i = 0; i < num; i++) { |
| 486 | msg = &msgs[i]; |
| 487 | |
| 488 | err = start_ch(pd, msg); |
| 489 | if (err) |
| 490 | break; |
| 491 | |
| 492 | i2c_op(pd, OP_START, 0); |
| 493 | |
| 494 | /* The interrupt handler takes care of the rest... */ |
| 495 | k = wait_event_timeout(pd->wait, |
| 496 | pd->sr & (ICSR_TACK | SW_DONE), |
| 497 | 5 * HZ); |
| 498 | if (!k) |
| 499 | dev_err(pd->dev, "Transfer request timed out\n"); |
| 500 | |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 501 | retry_count = 1000; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 502 | again: |
Magnus Damm | 12a55f2 | 2010-03-11 10:05:50 +0000 | [diff] [blame] | 503 | val = iic_rd(pd, ICSR); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 504 | |
| 505 | dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); |
| 506 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 507 | /* the interrupt handler may wake us up before the |
| 508 | * transfer is finished, so poll the hardware |
| 509 | * until we're done. |
| 510 | */ |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 511 | if (val & ICSR_BUSY) { |
| 512 | udelay(10); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 513 | if (retry_count--) |
| 514 | goto again; |
| 515 | |
| 516 | err = -EIO; |
| 517 | dev_err(pd->dev, "Polling timed out\n"); |
| 518 | break; |
| 519 | } |
Magnus Damm | 4eb00c9 | 2008-08-27 18:33:56 +0900 | [diff] [blame] | 520 | |
| 521 | /* handle missing acknowledge and arbitration lost */ |
| 522 | if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) { |
| 523 | err = -EIO; |
| 524 | break; |
| 525 | } |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | deactivate_ch(pd); |
| 529 | |
| 530 | if (!err) |
| 531 | err = num; |
| 532 | return err; |
| 533 | } |
| 534 | |
| 535 | static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter) |
| 536 | { |
| 537 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
| 538 | } |
| 539 | |
| 540 | static struct i2c_algorithm sh_mobile_i2c_algorithm = { |
| 541 | .functionality = sh_mobile_i2c_func, |
| 542 | .master_xfer = sh_mobile_i2c_xfer, |
| 543 | }; |
| 544 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 545 | static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) |
| 546 | { |
| 547 | struct resource *res; |
| 548 | int ret = -ENXIO; |
Magnus Damm | 82b20d8 | 2010-08-02 07:16:37 +0000 | [diff] [blame] | 549 | int n, k = 0; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 550 | |
| 551 | while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) { |
| 552 | for (n = res->start; hook && n <= res->end; n++) { |
Yong Zhang | 4311051 | 2011-09-21 17:28:33 +0800 | [diff] [blame] | 553 | if (request_irq(n, sh_mobile_i2c_isr, 0, |
Magnus Damm | 82b20d8 | 2010-08-02 07:16:37 +0000 | [diff] [blame] | 554 | dev_name(&dev->dev), dev)) { |
| 555 | for (n--; n >= res->start; n--) |
| 556 | free_irq(n, dev); |
| 557 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 558 | goto rollback; |
Magnus Damm | 82b20d8 | 2010-08-02 07:16:37 +0000 | [diff] [blame] | 559 | } |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 560 | } |
| 561 | k++; |
| 562 | } |
| 563 | |
| 564 | if (hook) |
| 565 | return k > 0 ? 0 : -ENOENT; |
| 566 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 567 | ret = 0; |
| 568 | |
| 569 | rollback: |
Magnus Damm | 82b20d8 | 2010-08-02 07:16:37 +0000 | [diff] [blame] | 570 | k--; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 571 | |
Magnus Damm | 82b20d8 | 2010-08-02 07:16:37 +0000 | [diff] [blame] | 572 | while (k >= 0) { |
| 573 | res = platform_get_resource(dev, IORESOURCE_IRQ, k); |
| 574 | for (n = res->start; n <= res->end; n++) |
| 575 | free_irq(n, dev); |
| 576 | |
| 577 | k--; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | return ret; |
| 581 | } |
| 582 | |
| 583 | static int sh_mobile_i2c_probe(struct platform_device *dev) |
| 584 | { |
Magnus Damm | 81f8115 | 2011-04-28 13:25:36 +0900 | [diff] [blame] | 585 | struct i2c_sh_mobile_platform_data *pdata = dev->dev.platform_data; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 586 | struct sh_mobile_i2c_data *pd; |
| 587 | struct i2c_adapter *adap; |
| 588 | struct resource *res; |
| 589 | int size; |
| 590 | int ret; |
| 591 | |
| 592 | pd = kzalloc(sizeof(struct sh_mobile_i2c_data), GFP_KERNEL); |
| 593 | if (pd == NULL) { |
| 594 | dev_err(&dev->dev, "cannot allocate private data\n"); |
| 595 | return -ENOMEM; |
| 596 | } |
| 597 | |
Magnus Damm | 1082d5d | 2011-04-21 22:20:39 +0900 | [diff] [blame] | 598 | pd->clk = clk_get(&dev->dev, NULL); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 599 | if (IS_ERR(pd->clk)) { |
Magnus Damm | 1082d5d | 2011-04-21 22:20:39 +0900 | [diff] [blame] | 600 | dev_err(&dev->dev, "cannot get clock\n"); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 601 | ret = PTR_ERR(pd->clk); |
| 602 | goto err; |
| 603 | } |
| 604 | |
| 605 | ret = sh_mobile_i2c_hook_irqs(dev, 1); |
| 606 | if (ret) { |
| 607 | dev_err(&dev->dev, "cannot request IRQ\n"); |
| 608 | goto err_clk; |
| 609 | } |
| 610 | |
| 611 | pd->dev = &dev->dev; |
| 612 | platform_set_drvdata(dev, pd); |
| 613 | |
| 614 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 615 | if (res == NULL) { |
| 616 | dev_err(&dev->dev, "cannot find IO resource\n"); |
| 617 | ret = -ENOENT; |
| 618 | goto err_irq; |
| 619 | } |
| 620 | |
Julia Lawall | 5933082 | 2009-07-05 08:37:50 +0200 | [diff] [blame] | 621 | size = resource_size(res); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 622 | |
| 623 | pd->reg = ioremap(res->start, size); |
| 624 | if (pd->reg == NULL) { |
| 625 | dev_err(&dev->dev, "cannot map IO\n"); |
| 626 | ret = -ENXIO; |
| 627 | goto err_irq; |
| 628 | } |
| 629 | |
Magnus Damm | 81f8115 | 2011-04-28 13:25:36 +0900 | [diff] [blame] | 630 | /* Use platformd data bus speed or NORMAL_SPEED */ |
| 631 | pd->bus_speed = NORMAL_SPEED; |
| 632 | if (pdata && pdata->bus_speed) |
| 633 | pd->bus_speed = pdata->bus_speed; |
| 634 | |
Magnus Damm | 962b603 | 2010-03-11 10:06:02 +0000 | [diff] [blame] | 635 | /* The IIC blocks on SH-Mobile ARM processors |
| 636 | * come with two new bits in ICIC. |
| 637 | */ |
| 638 | if (size > 0x17) |
| 639 | pd->flags |= IIC_FLAG_HAS_ICIC67; |
| 640 | |
Shinya Kuribayashi | 7b0e629 | 2012-10-24 19:56:51 +0900 | [diff] [blame^] | 641 | sh_mobile_i2c_init(pd); |
| 642 | |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 643 | /* Enable Runtime PM for this device. |
| 644 | * |
| 645 | * Also tell the Runtime PM core to ignore children |
| 646 | * for this device since it is valid for us to suspend |
| 647 | * this I2C master driver even though the slave devices |
| 648 | * on the I2C bus may not be suspended. |
| 649 | * |
| 650 | * The state of the I2C hardware bus is unaffected by |
| 651 | * the Runtime PM state. |
| 652 | */ |
| 653 | pm_suspend_ignore_children(&dev->dev, true); |
| 654 | pm_runtime_enable(&dev->dev); |
| 655 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 656 | /* setup the private data */ |
| 657 | adap = &pd->adap; |
| 658 | i2c_set_adapdata(adap, pd); |
| 659 | |
| 660 | adap->owner = THIS_MODULE; |
| 661 | adap->algo = &sh_mobile_i2c_algorithm; |
| 662 | adap->dev.parent = &dev->dev; |
| 663 | adap->retries = 5; |
| 664 | adap->nr = dev->id; |
Magnus Damm | ad33707 | 2012-03-30 17:44:02 +0900 | [diff] [blame] | 665 | adap->dev.of_node = dev->dev.of_node; |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 666 | |
| 667 | strlcpy(adap->name, dev->name, sizeof(adap->name)); |
| 668 | |
Magnus Damm | a5616bd | 2008-10-31 20:20:55 +0900 | [diff] [blame] | 669 | spin_lock_init(&pd->lock); |
| 670 | init_waitqueue_head(&pd->wait); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 671 | |
| 672 | ret = i2c_add_numbered_adapter(adap); |
| 673 | if (ret < 0) { |
| 674 | dev_err(&dev->dev, "cannot add numbered adapter\n"); |
| 675 | goto err_all; |
| 676 | } |
| 677 | |
Magnus Damm | 81f8115 | 2011-04-28 13:25:36 +0900 | [diff] [blame] | 678 | dev_info(&dev->dev, "I2C adapter %d with bus speed %lu Hz\n", |
| 679 | adap->nr, pd->bus_speed); |
Magnus Damm | ad33707 | 2012-03-30 17:44:02 +0900 | [diff] [blame] | 680 | |
| 681 | of_i2c_register_devices(adap); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 682 | return 0; |
| 683 | |
| 684 | err_all: |
| 685 | iounmap(pd->reg); |
| 686 | err_irq: |
| 687 | sh_mobile_i2c_hook_irqs(dev, 0); |
| 688 | err_clk: |
| 689 | clk_put(pd->clk); |
| 690 | err: |
| 691 | kfree(pd); |
| 692 | return ret; |
| 693 | } |
| 694 | |
| 695 | static int sh_mobile_i2c_remove(struct platform_device *dev) |
| 696 | { |
| 697 | struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); |
| 698 | |
| 699 | i2c_del_adapter(&pd->adap); |
| 700 | iounmap(pd->reg); |
| 701 | sh_mobile_i2c_hook_irqs(dev, 0); |
| 702 | clk_put(pd->clk); |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 703 | pm_runtime_disable(&dev->dev); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 704 | kfree(pd); |
| 705 | return 0; |
| 706 | } |
| 707 | |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 708 | static int sh_mobile_i2c_runtime_nop(struct device *dev) |
| 709 | { |
| 710 | /* Runtime PM callback shared between ->runtime_suspend() |
| 711 | * and ->runtime_resume(). Simply returns success. |
| 712 | * |
| 713 | * This driver re-initializes all registers after |
| 714 | * pm_runtime_get_sync() anyway so there is no need |
| 715 | * to save and restore registers here. |
| 716 | */ |
| 717 | return 0; |
| 718 | } |
| 719 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 720 | static const struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = { |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 721 | .runtime_suspend = sh_mobile_i2c_runtime_nop, |
| 722 | .runtime_resume = sh_mobile_i2c_runtime_nop, |
| 723 | }; |
| 724 | |
Magnus Damm | ad33707 | 2012-03-30 17:44:02 +0900 | [diff] [blame] | 725 | static const struct of_device_id sh_mobile_i2c_dt_ids[] __devinitconst = { |
| 726 | { .compatible = "renesas,rmobile-iic", }, |
| 727 | {}, |
| 728 | }; |
| 729 | MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids); |
| 730 | |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 731 | static struct platform_driver sh_mobile_i2c_driver = { |
| 732 | .driver = { |
| 733 | .name = "i2c-sh_mobile", |
| 734 | .owner = THIS_MODULE, |
Magnus Damm | f1a3b99 | 2009-08-14 10:48:59 +0000 | [diff] [blame] | 735 | .pm = &sh_mobile_i2c_dev_pm_ops, |
Magnus Damm | ad33707 | 2012-03-30 17:44:02 +0900 | [diff] [blame] | 736 | .of_match_table = sh_mobile_i2c_dt_ids, |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 737 | }, |
| 738 | .probe = sh_mobile_i2c_probe, |
| 739 | .remove = sh_mobile_i2c_remove, |
| 740 | }; |
| 741 | |
| 742 | static int __init sh_mobile_i2c_adap_init(void) |
| 743 | { |
| 744 | return platform_driver_register(&sh_mobile_i2c_driver); |
| 745 | } |
| 746 | |
| 747 | static void __exit sh_mobile_i2c_adap_exit(void) |
| 748 | { |
| 749 | platform_driver_unregister(&sh_mobile_i2c_driver); |
| 750 | } |
| 751 | |
Magnus Damm | ccb3bc1 | 2009-07-22 23:58:39 +0900 | [diff] [blame] | 752 | subsys_initcall(sh_mobile_i2c_adap_init); |
Magnus Damm | da67277 | 2008-04-22 22:16:49 +0200 | [diff] [blame] | 753 | module_exit(sh_mobile_i2c_adap_exit); |
| 754 | |
| 755 | MODULE_DESCRIPTION("SuperH Mobile I2C Bus Controller driver"); |
| 756 | MODULE_AUTHOR("Magnus Damm"); |
| 757 | MODULE_LICENSE("GPL v2"); |
Guennadi Liakhovetski | 7ef0c12 | 2011-04-15 20:18:57 +0200 | [diff] [blame] | 758 | MODULE_ALIAS("platform:i2c-sh_mobile"); |