kernel: bump 4.9 to 4.9.96
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 950-0048-Add-Chris-Boot-s-i2c-driver.patch
1 From af4e8a3c7b645480f57ec14ded02fba6976ff2d5 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Wed, 17 Jun 2015 15:44:08 +0100
4 Subject: [PATCH] Add Chris Boot's i2c driver
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 i2c-bcm2708: fixed baudrate
10
11 Fixed issue where the wrong CDIV value was set for baudrates below 3815 Hz (for 250MHz bus clock).
12 In that case the computed CDIV value was more than 0xffff. However the CDIV register width is only 16 bits.
13 This resulted in incorrect setting of CDIV and higher baudrate than intended.
14 Example: 3500Hz -> CDIV=0x11704 -> CDIV(16bit)=0x1704 -> 42430Hz
15 After correction: 3500Hz -> CDIV=0x11704 -> CDIV(16bit)=0xffff -> 3815Hz
16 The correct baudrate is shown in the log after the cdiv > 0xffff correction.
17
18 Perform I2C combined transactions when possible
19
20 Perform I2C combined transactions whenever possible, within the
21 restrictions of the Broadcomm Serial Controller.
22
23 Disable DONE interrupt during TA poll
24
25 Prevent interrupt from being triggered if poll is missed and transfer
26 starts and finishes.
27
28 i2c: Make combined transactions optional and disabled by default
29
30 i2c: bcm2708: add device tree support
31
32 Add DT support to driver and add to .dtsi file.
33 Setup pins in .dts file.
34 i2c is disabled by default.
35
36 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
37
38 bcm2708: don't register i2c controllers when using DT
39
40 The devices for the i2c controllers are in the Device Tree.
41 Only register devices when not using DT.
42
43 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
44
45 I2C: Only register the I2C device for the current board revision
46
47 i2c_bcm2708: Fix clock reference counting
48
49 Fix grabbing lock from atomic context in i2c driver
50
51 2 main changes:
52 - check for timeouts in the bcm2708_bsc_setup function as indicated by this comment:
53 /* poll for transfer start bit (should only take 1-20 polls) */
54 This implies that the setup function can now fail so account for this everywhere it's called
55 - Removed the clk_get_rate call from inside the setup function as it locks a mutex and that's not ok since we call it from under a spin lock.
56
57 i2c-bcm2708: When using DT, leave the GPIO setup to pinctrl
58
59 i2c-bcm2708: Increase timeouts to allow larger transfers
60
61 Use the timeout value provided by the I2C_TIMEOUT ioctl when waiting
62 for completion. The default timeout is 1 second.
63
64 See: https://github.com/raspberrypi/linux/issues/260
65
66 i2c-bcm2708/BCM270X_DT: Add support for I2C2
67
68 The third I2C bus (I2C2) is normally reserved for HDMI use. Careless
69 use of this bus can break an attached display - use with caution.
70
71 It is recommended to disable accesses by VideoCore by setting
72 hdmi_ignore_edid=1 or hdmi_edid_file=1 in config.txt.
73
74 The interface is disabled by default - enable using the
75 i2c2_iknowwhatimdoing DT parameter.
76
77 bcm2708-spi: Don't use static pin configuration with DT
78
79 Also remove superfluous error checking - the SPI framework ensures the
80 validity of the chip_select value.
81
82 i2c-bcm2708: Remove non-DT support
83
84 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
85
86 Set the BSC_CLKT clock streching timeout to 35ms as per SMBus specs.
87
88 Fixes i2c_bcm2708: Write to FIFO correctly - v2 (#1574)
89
90 * i2c: fix i2c_bcm2708: Clear FIFO before sending data
91
92 Make sure FIFO gets cleared before trying to send
93 data in case of a repeated start (COMBINED=Y).
94
95 * i2c: fix i2c_bcm2708: Only write to FIFO when not full
96
97 Check if FIFO can accept data before writing.
98 To avoid a peripheral read on the last iteration of a loop,
99 both bcm2708_bsc_fifo_fill and ~drain are changed as well.
100 ---
101 drivers/i2c/busses/Kconfig | 19 ++
102 drivers/i2c/busses/Makefile | 2 +
103 drivers/i2c/busses/i2c-bcm2708.c | 512 +++++++++++++++++++++++++++++++++++++++
104 3 files changed, 533 insertions(+)
105 create mode 100644 drivers/i2c/busses/i2c-bcm2708.c
106
107 --- a/drivers/i2c/busses/Kconfig
108 +++ b/drivers/i2c/busses/Kconfig
109 @@ -8,6 +8,25 @@ menu "I2C Hardware Bus support"
110 comment "PC SMBus host controller drivers"
111 depends on PCI
112
113 +config I2C_BCM2708
114 + tristate "BCM2708 BSC"
115 + depends on ARCH_BCM2835
116 + help
117 + Enabling this option will add BSC (Broadcom Serial Controller)
118 + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
119 + with I2C/TWI/SMBus.
120 +
121 +config I2C_BCM2708_BAUDRATE
122 + prompt "BCM2708 I2C baudrate"
123 + depends on I2C_BCM2708
124 + int
125 + default 100000
126 + help
127 + Set the I2C baudrate. This will alter the default value. A
128 + different baudrate can be set by using a module parameter as well. If
129 + no parameter is provided when loading, this is the value that will be
130 + used.
131 +
132 config I2C_ALI1535
133 tristate "ALI 1535"
134 depends on PCI
135 --- a/drivers/i2c/busses/Makefile
136 +++ b/drivers/i2c/busses/Makefile
137 @@ -2,6 +2,8 @@
138 # Makefile for the i2c bus drivers.
139 #
140
141 +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
142 +
143 # ACPI drivers
144 obj-$(CONFIG_I2C_SCMI) += i2c-scmi.o
145
146 --- /dev/null
147 +++ b/drivers/i2c/busses/i2c-bcm2708.c
148 @@ -0,0 +1,512 @@
149 +/*
150 + * Driver for Broadcom BCM2708 BSC Controllers
151 + *
152 + * Copyright (C) 2012 Chris Boot & Frank Buss
153 + *
154 + * This driver is inspired by:
155 + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
156 + *
157 + * This program is free software; you can redistribute it and/or modify
158 + * it under the terms of the GNU General Public License as published by
159 + * the Free Software Foundation; either version 2 of the License, or
160 + * (at your option) any later version.
161 + *
162 + * This program is distributed in the hope that it will be useful,
163 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
164 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165 + * GNU General Public License for more details.
166 + *
167 + * You should have received a copy of the GNU General Public License
168 + * along with this program; if not, write to the Free Software
169 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
170 + */
171 +
172 +#include <linux/kernel.h>
173 +#include <linux/module.h>
174 +#include <linux/spinlock.h>
175 +#include <linux/clk.h>
176 +#include <linux/err.h>
177 +#include <linux/of.h>
178 +#include <linux/platform_device.h>
179 +#include <linux/io.h>
180 +#include <linux/slab.h>
181 +#include <linux/i2c.h>
182 +#include <linux/interrupt.h>
183 +#include <linux/sched.h>
184 +#include <linux/wait.h>
185 +
186 +/* BSC register offsets */
187 +#define BSC_C 0x00
188 +#define BSC_S 0x04
189 +#define BSC_DLEN 0x08
190 +#define BSC_A 0x0c
191 +#define BSC_FIFO 0x10
192 +#define BSC_DIV 0x14
193 +#define BSC_DEL 0x18
194 +#define BSC_CLKT 0x1c
195 +
196 +/* Bitfields in BSC_C */
197 +#define BSC_C_I2CEN 0x00008000
198 +#define BSC_C_INTR 0x00000400
199 +#define BSC_C_INTT 0x00000200
200 +#define BSC_C_INTD 0x00000100
201 +#define BSC_C_ST 0x00000080
202 +#define BSC_C_CLEAR_1 0x00000020
203 +#define BSC_C_CLEAR_2 0x00000010
204 +#define BSC_C_READ 0x00000001
205 +
206 +/* Bitfields in BSC_S */
207 +#define BSC_S_CLKT 0x00000200
208 +#define BSC_S_ERR 0x00000100
209 +#define BSC_S_RXF 0x00000080
210 +#define BSC_S_TXE 0x00000040
211 +#define BSC_S_RXD 0x00000020
212 +#define BSC_S_TXD 0x00000010
213 +#define BSC_S_RXR 0x00000008
214 +#define BSC_S_TXW 0x00000004
215 +#define BSC_S_DONE 0x00000002
216 +#define BSC_S_TA 0x00000001
217 +
218 +#define I2C_WAIT_LOOP_COUNT 200
219 +
220 +#define DRV_NAME "bcm2708_i2c"
221 +
222 +static unsigned int baudrate;
223 +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
224 +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
225 +
226 +static bool combined = false;
227 +module_param(combined, bool, 0644);
228 +MODULE_PARM_DESC(combined, "Use combined transactions");
229 +
230 +struct bcm2708_i2c {
231 + struct i2c_adapter adapter;
232 +
233 + spinlock_t lock;
234 + void __iomem *base;
235 + int irq;
236 + struct clk *clk;
237 + u32 cdiv;
238 + u32 clk_tout;
239 +
240 + struct completion done;
241 +
242 + struct i2c_msg *msg;
243 + int pos;
244 + int nmsgs;
245 + bool error;
246 +};
247 +
248 +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
249 +{
250 + return readl(bi->base + reg);
251 +}
252 +
253 +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
254 +{
255 + writel(val, bi->base + reg);
256 +}
257 +
258 +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
259 +{
260 + bcm2708_wr(bi, BSC_C, 0);
261 + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
262 +}
263 +
264 +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
265 +{
266 + while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_RXD))
267 + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
268 +}
269 +
270 +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
271 +{
272 + while ((bi->pos < bi->msg->len) && (bcm2708_rd(bi, BSC_S) & BSC_S_TXD))
273 + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
274 +}
275 +
276 +static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
277 +{
278 + u32 cdiv, s, clk_tout;
279 + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
280 + int wait_loops = I2C_WAIT_LOOP_COUNT;
281 +
282 + /* Can't call clk_get_rate as it locks a mutex and here we are spinlocked.
283 + * Use the value that we cached in the probe.
284 + */
285 + cdiv = bi->cdiv;
286 + clk_tout = bi->clk_tout;
287 +
288 + if (bi->msg->flags & I2C_M_RD)
289 + c |= BSC_C_INTR | BSC_C_READ;
290 + else
291 + c |= BSC_C_INTT;
292 +
293 + bcm2708_wr(bi, BSC_CLKT, clk_tout);
294 + bcm2708_wr(bi, BSC_DIV, cdiv);
295 + bcm2708_wr(bi, BSC_A, bi->msg->addr);
296 + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
297 + if (combined)
298 + {
299 + /* Do the next two messages meet combined transaction criteria?
300 + - Current message is a write, next message is a read
301 + - Both messages to same slave address
302 + - Write message can fit inside FIFO (16 bytes or less) */
303 + if ( (bi->nmsgs > 1) &&
304 + !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
305 + (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
306 +
307 + /* Clear FIFO */
308 + bcm2708_wr(bi, BSC_C, BSC_C_CLEAR_1);
309 +
310 + /* Fill FIFO with entire write message (16 byte FIFO) */
311 + while (bi->pos < bi->msg->len) {
312 + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
313 + }
314 + /* Start write transfer (no interrupts, don't clear FIFO) */
315 + bcm2708_wr(bi, BSC_C, BSC_C_I2CEN | BSC_C_ST);
316 +
317 + /* poll for transfer start bit (should only take 1-20 polls) */
318 + do {
319 + s = bcm2708_rd(bi, BSC_S);
320 + } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)) && --wait_loops >= 0);
321 +
322 + /* did we time out or some error occured? */
323 + if (wait_loops < 0 || (s & (BSC_S_ERR | BSC_S_CLKT))) {
324 + return -1;
325 + }
326 +
327 + /* Send next read message before the write transfer finishes. */
328 + bi->nmsgs--;
329 + bi->msg++;
330 + bi->pos = 0;
331 + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
332 + c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_INTR | BSC_C_ST | BSC_C_READ;
333 + }
334 + }
335 + bcm2708_wr(bi, BSC_C, c);
336 +
337 + return 0;
338 +}
339 +
340 +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
341 +{
342 + struct bcm2708_i2c *bi = dev_id;
343 + bool handled = true;
344 + u32 s;
345 + int ret;
346 +
347 + spin_lock(&bi->lock);
348 +
349 + /* we may see camera interrupts on the "other" I2C channel
350 + Just return if we've not sent anything */
351 + if (!bi->nmsgs || !bi->msg) {
352 + goto early_exit;
353 + }
354 +
355 + s = bcm2708_rd(bi, BSC_S);
356 +
357 + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
358 + bcm2708_bsc_reset(bi);
359 + bi->error = true;
360 +
361 + bi->msg = 0; /* to inform the that all work is done */
362 + bi->nmsgs = 0;
363 + /* wake up our bh */
364 + complete(&bi->done);
365 + } else if (s & BSC_S_DONE) {
366 + bi->nmsgs--;
367 +
368 + if (bi->msg->flags & I2C_M_RD) {
369 + bcm2708_bsc_fifo_drain(bi);
370 + }
371 +
372 + bcm2708_bsc_reset(bi);
373 +
374 + if (bi->nmsgs) {
375 + /* advance to next message */
376 + bi->msg++;
377 + bi->pos = 0;
378 + ret = bcm2708_bsc_setup(bi);
379 + if (ret < 0) {
380 + bcm2708_bsc_reset(bi);
381 + bi->error = true;
382 + bi->msg = 0; /* to inform the that all work is done */
383 + bi->nmsgs = 0;
384 + /* wake up our bh */
385 + complete(&bi->done);
386 + goto early_exit;
387 + }
388 + } else {
389 + bi->msg = 0; /* to inform the that all work is done */
390 + bi->nmsgs = 0;
391 + /* wake up our bh */
392 + complete(&bi->done);
393 + }
394 + } else if (s & BSC_S_TXW) {
395 + bcm2708_bsc_fifo_fill(bi);
396 + } else if (s & BSC_S_RXR) {
397 + bcm2708_bsc_fifo_drain(bi);
398 + } else {
399 + handled = false;
400 + }
401 +
402 +early_exit:
403 + spin_unlock(&bi->lock);
404 +
405 + return handled ? IRQ_HANDLED : IRQ_NONE;
406 +}
407 +
408 +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
409 + struct i2c_msg *msgs, int num)
410 +{
411 + struct bcm2708_i2c *bi = adap->algo_data;
412 + unsigned long flags;
413 + int ret;
414 +
415 + spin_lock_irqsave(&bi->lock, flags);
416 +
417 + reinit_completion(&bi->done);
418 + bi->msg = msgs;
419 + bi->pos = 0;
420 + bi->nmsgs = num;
421 + bi->error = false;
422 +
423 + ret = bcm2708_bsc_setup(bi);
424 +
425 + spin_unlock_irqrestore(&bi->lock, flags);
426 +
427 + /* check the result of the setup */
428 + if (ret < 0)
429 + {
430 + dev_err(&adap->dev, "transfer setup timed out\n");
431 + goto error_timeout;
432 + }
433 +
434 + ret = wait_for_completion_timeout(&bi->done, adap->timeout);
435 + if (ret == 0) {
436 + dev_err(&adap->dev, "transfer timed out\n");
437 + goto error_timeout;
438 + }
439 +
440 + ret = bi->error ? -EIO : num;
441 + return ret;
442 +
443 +error_timeout:
444 + spin_lock_irqsave(&bi->lock, flags);
445 + bcm2708_bsc_reset(bi);
446 + bi->msg = 0; /* to inform the interrupt handler that there's nothing else to be done */
447 + bi->nmsgs = 0;
448 + spin_unlock_irqrestore(&bi->lock, flags);
449 + return -ETIMEDOUT;
450 +}
451 +
452 +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
453 +{
454 + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
455 +}
456 +
457 +static struct i2c_algorithm bcm2708_i2c_algorithm = {
458 + .master_xfer = bcm2708_i2c_master_xfer,
459 + .functionality = bcm2708_i2c_functionality,
460 +};
461 +
462 +static int bcm2708_i2c_probe(struct platform_device *pdev)
463 +{
464 + struct resource *regs;
465 + int irq, err = -ENOMEM;
466 + struct clk *clk;
467 + struct bcm2708_i2c *bi;
468 + struct i2c_adapter *adap;
469 + unsigned long bus_hz;
470 + u32 cdiv, clk_tout;
471 + u32 baud;
472 +
473 + baud = CONFIG_I2C_BCM2708_BAUDRATE;
474 +
475 + if (pdev->dev.of_node) {
476 + u32 bus_clk_rate;
477 + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
478 + if (pdev->id < 0) {
479 + dev_err(&pdev->dev, "alias is missing\n");
480 + return -EINVAL;
481 + }
482 + if (!of_property_read_u32(pdev->dev.of_node,
483 + "clock-frequency", &bus_clk_rate))
484 + baud = bus_clk_rate;
485 + else
486 + dev_warn(&pdev->dev,
487 + "Could not read clock-frequency property\n");
488 + }
489 +
490 + if (baudrate)
491 + baud = baudrate;
492 +
493 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
494 + if (!regs) {
495 + dev_err(&pdev->dev, "could not get IO memory\n");
496 + return -ENXIO;
497 + }
498 +
499 + irq = platform_get_irq(pdev, 0);
500 + if (irq < 0) {
501 + dev_err(&pdev->dev, "could not get IRQ\n");
502 + return irq;
503 + }
504 +
505 + clk = clk_get(&pdev->dev, NULL);
506 + if (IS_ERR(clk)) {
507 + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
508 + return PTR_ERR(clk);
509 + }
510 +
511 + err = clk_prepare_enable(clk);
512 + if (err) {
513 + dev_err(&pdev->dev, "could not enable clk: %d\n", err);
514 + goto out_clk_put;
515 + }
516 +
517 + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
518 + if (!bi)
519 + goto out_clk_disable;
520 +
521 + platform_set_drvdata(pdev, bi);
522 +
523 + adap = &bi->adapter;
524 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
525 + adap->algo = &bcm2708_i2c_algorithm;
526 + adap->algo_data = bi;
527 + adap->dev.parent = &pdev->dev;
528 + adap->nr = pdev->id;
529 + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
530 + adap->dev.of_node = pdev->dev.of_node;
531 +
532 + switch (pdev->id) {
533 + case 0:
534 + adap->class = I2C_CLASS_HWMON;
535 + break;
536 + case 1:
537 + adap->class = I2C_CLASS_DDC;
538 + break;
539 + case 2:
540 + adap->class = I2C_CLASS_DDC;
541 + break;
542 + default:
543 + dev_err(&pdev->dev, "can only bind to BSC 0, 1 or 2\n");
544 + err = -ENXIO;
545 + goto out_free_bi;
546 + }
547 +
548 + spin_lock_init(&bi->lock);
549 + init_completion(&bi->done);
550 +
551 + bi->base = ioremap(regs->start, resource_size(regs));
552 + if (!bi->base) {
553 + dev_err(&pdev->dev, "could not remap memory\n");
554 + goto out_free_bi;
555 + }
556 +
557 + bi->irq = irq;
558 + bi->clk = clk;
559 +
560 + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
561 + dev_name(&pdev->dev), bi);
562 + if (err) {
563 + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
564 + goto out_iounmap;
565 + }
566 +
567 + bcm2708_bsc_reset(bi);
568 +
569 + err = i2c_add_numbered_adapter(adap);
570 + if (err < 0) {
571 + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
572 + goto out_free_irq;
573 + }
574 +
575 + bus_hz = clk_get_rate(bi->clk);
576 + cdiv = bus_hz / baud;
577 + if (cdiv > 0xffff) {
578 + cdiv = 0xffff;
579 + baud = bus_hz / cdiv;
580 + }
581 +
582 + clk_tout = 35/1000*baud; //35ms timeout as per SMBus specs.
583 + if (clk_tout > 0xffff)
584 + clk_tout = 0xffff;
585 +
586 + bi->cdiv = cdiv;
587 + bi->clk_tout = clk_tout;
588 +
589 + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
590 + pdev->id, (unsigned long)regs->start, irq, baud);
591 +
592 + return 0;
593 +
594 +out_free_irq:
595 + free_irq(bi->irq, bi);
596 +out_iounmap:
597 + iounmap(bi->base);
598 +out_free_bi:
599 + kfree(bi);
600 +out_clk_disable:
601 + clk_disable_unprepare(clk);
602 +out_clk_put:
603 + clk_put(clk);
604 + return err;
605 +}
606 +
607 +static int bcm2708_i2c_remove(struct platform_device *pdev)
608 +{
609 + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
610 +
611 + platform_set_drvdata(pdev, NULL);
612 +
613 + i2c_del_adapter(&bi->adapter);
614 + free_irq(bi->irq, bi);
615 + iounmap(bi->base);
616 + clk_disable_unprepare(bi->clk);
617 + clk_put(bi->clk);
618 + kfree(bi);
619 +
620 + return 0;
621 +}
622 +
623 +static const struct of_device_id bcm2708_i2c_of_match[] = {
624 + { .compatible = "brcm,bcm2708-i2c" },
625 + {},
626 +};
627 +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
628 +
629 +static struct platform_driver bcm2708_i2c_driver = {
630 + .driver = {
631 + .name = DRV_NAME,
632 + .owner = THIS_MODULE,
633 + .of_match_table = bcm2708_i2c_of_match,
634 + },
635 + .probe = bcm2708_i2c_probe,
636 + .remove = bcm2708_i2c_remove,
637 +};
638 +
639 +// module_platform_driver(bcm2708_i2c_driver);
640 +
641 +
642 +static int __init bcm2708_i2c_init(void)
643 +{
644 + return platform_driver_register(&bcm2708_i2c_driver);
645 +}
646 +
647 +static void __exit bcm2708_i2c_exit(void)
648 +{
649 + platform_driver_unregister(&bcm2708_i2c_driver);
650 +}
651 +
652 +module_init(bcm2708_i2c_init);
653 +module_exit(bcm2708_i2c_exit);
654 +
655 +
656 +
657 +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
658 +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
659 +MODULE_LICENSE("GPL v2");
660 +MODULE_ALIAS("platform:" DRV_NAME);