1 From 6437f41dfdf9475178e22ab0dd886af033f90cc2 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 29 Sep 2011 21:10:16 +0200
4 Subject: [PATCH 11/24] MIPS: lantiq: adds falcon I2C
7 arch/mips/lantiq/falcon/devices.c | 21 +
8 arch/mips/lantiq/falcon/devices.h | 1 +
9 drivers/i2c/busses/Kconfig | 4 +
10 drivers/i2c/busses/Makefile | 1 +
11 drivers/i2c/busses/i2c-falcon.c | 815 +++++++++++++++++++++++++++++++++++++
12 5 files changed, 842 insertions(+), 0 deletions(-)
13 create mode 100644 drivers/i2c/busses/i2c-falcon.c
15 --- a/arch/mips/lantiq/falcon/devices.c
16 +++ b/arch/mips/lantiq/falcon/devices.c
17 @@ -126,3 +126,24 @@ falcon_register_gpio_extra(void)
18 ltq_sysctl_activate(SYSCTL_SYS1,
19 ACTS_PADCTRL3 | ACTS_PADCTRL4 | ACTS_P3 | ACTS_P4);
23 +static struct resource falcon_i2c_resources[] = {
24 + MEM_RES("i2c", GPON_I2C_BASE,GPON_I2C_END),
25 + IRQ_RES("i2c_lb", FALCON_IRQ_I2C_LBREQ),
26 + IRQ_RES("i2c_b", FALCON_IRQ_I2C_BREQ),
27 + IRQ_RES("i2c_err", FALCON_IRQ_I2C_I2C_ERR),
28 + IRQ_RES("i2c_p", FALCON_IRQ_I2C_I2C_P),
31 +void __init falcon_register_i2c(void)
33 + platform_device_register_simple("i2c-falcon", 0,
34 + falcon_i2c_resources, ARRAY_SIZE(falcon_i2c_resources));
35 + sys1_hw_activate(ACTS_I2C_ACT);
38 +void __init falcon_register_crypto(void)
40 + platform_device_register_simple("ltq_falcon_deu", 0, NULL, 0);
42 --- a/arch/mips/lantiq/falcon/devices.h
43 +++ b/arch/mips/lantiq/falcon/devices.h
45 extern void falcon_register_nand(void);
46 extern void falcon_register_gpio(void);
47 extern void falcon_register_gpio_extra(void);
48 +extern void falcon_register_i2c(void);
51 --- a/drivers/i2c/busses/Kconfig
52 +++ b/drivers/i2c/busses/Kconfig
53 @@ -284,6 +284,10 @@ config I2C_POWERMAC
55 comment "I2C system bus drivers (mostly embedded / system-on-chip)"
58 + tristate "Falcon I2C interface"
59 +# depends on SOC_FALCON
62 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
63 depends on ARCH_AT91 && EXPERIMENTAL && BROKEN
64 --- a/drivers/i2c/busses/Makefile
65 +++ b/drivers/i2c/busses/Makefile
66 @@ -82,5 +82,6 @@ obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
67 obj-$(CONFIG_I2C_STUB) += i2c-stub.o
68 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
69 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
70 +obj-$(CONFIG_I2C_FALCON) += i2c-falcon.o
72 ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
74 +++ b/drivers/i2c/busses/i2c-falcon.c
77 + * Lantiq FALC(tm) ON - I2C bus adapter
79 + * Parts based on i2c-designware.c and other i2c drivers from Linux 2.6.33
81 + * This program is free software; you can redistribute it and/or modify
82 + * it under the terms of the GNU General Public License as published by
83 + * the Free Software Foundation; either version 2 of the License, or
84 + * (at your option) any later version.
86 + * This program is distributed in the hope that it will be useful,
87 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
88 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 + * GNU General Public License for more details.
91 + * You should have received a copy of the GNU General Public License
92 + * along with this program; if not, write to the Free Software
93 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
98 +#include <linux/kernel.h>
99 +#include <linux/module.h>
100 +#include <linux/delay.h>
101 +#include <linux/slab.h> /* for kzalloc, kfree */
102 +#include <linux/i2c.h>
103 +#include <linux/clk.h>
104 +#include <linux/errno.h>
105 +#include <linux/sched.h>
106 +#include <linux/err.h>
107 +#include <linux/interrupt.h>
108 +#include <linux/platform_device.h>
109 +#include <linux/io.h>
110 +#include <linux/gpio.h>
112 +#include <falcon/lantiq_soc.h>
115 + * - no high speed support
116 + * - supports only master mode
117 + * - ten bit mode is not tested (no slave devices)
120 +/* mapping for access macros */
121 +#define reg_r32(reg) __raw_readl(reg)
122 +#define reg_w32(val, reg) __raw_writel(val, reg)
123 +#define reg_w32_mask(clear, set, reg) \
124 + reg_w32((reg_r32(reg) & ~(clear)) | (set), reg)
125 +#define reg_r32_table(reg, idx) reg_r32(&((uint32_t *)®)[idx])
126 +#define reg_w32_table(val, reg, idx) reg_w32(val, &((uint32_t *)®)[idx])
127 +#define i2c (priv->membase)
128 +#include <falcon/i2c_reg.h>
130 +#define DRV_NAME "i2c-falcon"
131 +#define DRV_VERSION "1.01"
133 +#define FALCON_I2C_BUSY_TIMEOUT 20 /* ms */
136 +#define FALCON_I2C_XFER_TIMEOUT 25*HZ
138 +#define FALCON_I2C_XFER_TIMEOUT HZ
140 +#if defined(DEBUG) && 0
141 +#define PRINTK(arg...) printk(arg)
143 +#define PRINTK(arg...) do {} while (0)
146 +#define FALCON_I2C_IMSC_DEFAULT_MASK (I2C_IMSC_I2C_P_INT_EN | \
147 + I2C_IMSC_I2C_ERR_INT_EN)
149 +#define FALCON_I2C_ARB_LOST (1 << 0)
150 +#define FALCON_I2C_NACK (1 << 1)
151 +#define FALCON_I2C_RX_UFL (1 << 2)
152 +#define FALCON_I2C_RX_OFL (1 << 3)
153 +#define FALCON_I2C_TX_UFL (1 << 4)
154 +#define FALCON_I2C_TX_OFL (1 << 5)
157 + struct mutex mutex;
160 + FALCON_I2C_MODE_100 = 1,
161 + FALCON_I2C_MODE_400 = 2,
162 + FALCON_I2C_MODE_3400 = 3
163 + } mode; /* current speed mode */
165 + struct clk *clk; /* clock input for i2c hardware block */
166 + struct gpon_reg_i2c __iomem *membase; /* base of mapped registers */
167 + int irq_lb, irq_b, irq_err, irq_p; /* last burst, burst, error,
170 + struct i2c_adapter adap;
171 + struct device *dev;
173 + struct completion cmd_complete;
175 + /* message transfer data */
176 + /* current message */
177 + struct i2c_msg *current_msg;
178 + /* number of messages to handle */
180 + /* current buffer */
182 + /* remaining length of current buffer */
184 + /* error status of the current transfer */
187 + /* master status codes */
190 + STATUS_ADDR, /* address phase */
198 +static irqreturn_t falcon_i2c_isr(int irq, void *dev_id);
200 +static inline void enable_burst_irq(struct falcon_i2c *priv)
202 + i2c_w32_mask(0, I2C_IMSC_LBREQ_INT_EN | I2C_IMSC_BREQ_INT_EN, imsc);
204 +static inline void disable_burst_irq(struct falcon_i2c *priv)
206 + i2c_w32_mask(I2C_IMSC_LBREQ_INT_EN | I2C_IMSC_BREQ_INT_EN, 0, imsc);
209 +static void prepare_msg_send_addr(struct falcon_i2c *priv)
211 + struct i2c_msg *msg = priv->current_msg;
212 + int rd = !!(msg->flags & I2C_M_RD); /* extends to 0 or 1 */
213 + u16 addr = msg->addr;
216 + priv->msg_buf = msg->buf;
217 + priv->msg_buf_len = msg->len;
219 + priv->status = STATUS_READ;
221 + priv->status = STATUS_WRITE;
223 + /* send slave address */
224 + if (msg->flags & I2C_M_TEN) {
225 + i2c_w32(0xf0 | ((addr & 0x300) >> 7) | rd, txd);
226 + i2c_w32(addr & 0xff, txd);
228 + i2c_w32((addr & 0x7f) << 1 | rd, txd);
231 +static void set_tx_len(struct falcon_i2c *priv)
233 + struct i2c_msg *msg = priv->current_msg;
234 + int len = (msg->flags & I2C_M_TEN) ? 2 : 1;
236 + PRINTK("set_tx_len %cX\n", (msg->flags & I2C_M_RD)?'R':'T');
238 + priv->status = STATUS_ADDR;
240 + if (!(msg->flags & I2C_M_RD)) {
243 + /* set maximum received packet size (before rx int!) */
244 + i2c_w32(msg->len, mrps_ctrl);
246 + i2c_w32(len, tps_ctrl);
247 + enable_burst_irq(priv);
250 +static int falcon_i2c_hw_init(struct i2c_adapter *adap)
252 + struct falcon_i2c *priv = i2c_get_adapdata(adap);
255 + i2c_w32_mask(I2C_RUN_CTRL_RUN_EN, 0, run_ctrl);
258 + /* set normal operation clock divider */
259 + i2c_w32(1 << I2C_CLC_RMC_OFFSET, clc);
261 + /* for debugging a higher divider value! */
262 + i2c_w32(0xF0 << I2C_CLC_RMC_OFFSET, clc);
265 + /* set frequency */
266 + if (priv->mode == FALCON_I2C_MODE_100) {
267 + dev_dbg(priv->dev, "set standard mode (100 kHz)\n");
268 + i2c_w32(0, fdiv_high_cfg);
269 + i2c_w32((1 << I2C_FDIV_CFG_INC_OFFSET) |
270 + (499 << I2C_FDIV_CFG_DEC_OFFSET),
272 + } else if (priv->mode == FALCON_I2C_MODE_400) {
273 + dev_dbg(priv->dev, "set fast mode (400 kHz)\n");
274 + i2c_w32(0, fdiv_high_cfg);
275 + i2c_w32((1 << I2C_FDIV_CFG_INC_OFFSET) |
276 + (124 << I2C_FDIV_CFG_DEC_OFFSET),
278 + } else if (priv->mode == FALCON_I2C_MODE_3400) {
279 + dev_dbg(priv->dev, "set high mode (3.4 MHz)\n");
280 + i2c_w32(0, fdiv_cfg);
281 + /* TODO recalculate value for 100MHz input */
282 + i2c_w32((41 << I2C_FDIV_HIGH_CFG_INC_OFFSET) |
283 + (152 << I2C_FDIV_HIGH_CFG_DEC_OFFSET),
286 + dev_warn(priv->dev, "unknown mode\n");
290 + /* configure fifo */
291 + i2c_w32(I2C_FIFO_CFG_TXFC | /* tx fifo as flow controller */
292 + I2C_FIFO_CFG_RXFC | /* rx fifo as flow controller */
293 + I2C_FIFO_CFG_TXFA_TXFA2 | /* tx fifo 4-byte aligned */
294 + I2C_FIFO_CFG_RXFA_RXFA2 | /* rx fifo 4-byte aligned */
295 + I2C_FIFO_CFG_TXBS_TXBS0 | /* tx fifo burst size is 1 word */
296 + I2C_FIFO_CFG_RXBS_RXBS0, /* rx fifo burst size is 1 word */
299 + /* configure address */
300 + i2c_w32(I2C_ADDR_CFG_SOPE_EN | /* generate stop when no more data in the
302 + I2C_ADDR_CFG_SONA_EN | /* generate stop when NA received */
303 + I2C_ADDR_CFG_MnS_EN | /* we are master device */
304 + 0, /* our slave address (not used!) */
308 + i2c_w32_mask(0, I2C_RUN_CTRL_RUN_EN, run_ctrl);
313 +static int falcon_i2c_wait_bus_not_busy(struct falcon_i2c *priv)
315 + int timeout = FALCON_I2C_BUSY_TIMEOUT;
317 + while ((i2c_r32(bus_stat) & I2C_BUS_STAT_BS_MASK)
318 + != I2C_BUS_STAT_BS_FREE) {
319 + if (timeout <= 0) {
320 + dev_warn(priv->dev, "timeout waiting for bus ready\n");
330 +static void falcon_i2c_tx(struct falcon_i2c *priv, int last)
332 + if (priv->msg_buf_len && priv->msg_buf) {
333 + i2c_w32(*priv->msg_buf, txd);
335 + if (--priv->msg_buf_len)
338 + priv->msg_buf = NULL;
343 + disable_burst_irq(priv);
347 +static void falcon_i2c_rx(struct falcon_i2c *priv, int last)
349 + u32 fifo_stat,timeout;
350 + if (priv->msg_buf_len && priv->msg_buf) {
353 + fifo_stat = i2c_r32(ffs_stat);
354 + } while (!fifo_stat && --timeout);
357 + PRINTK("\nrx timeout\n");
360 + while (fifo_stat) {
361 + *priv->msg_buf = i2c_r32(rxd);
362 + if (--priv->msg_buf_len)
365 + priv->msg_buf = NULL;
370 + fifo_stat = i2c_r32(ffs_stat);
372 + /* do not read more than burst size, otherwise no "last
373 + burst" is generated and the transaction is blocked! */
382 + disable_burst_irq(priv);
384 + if (priv->status == STATUS_READ_END) {
385 + /* do the STATUS_STOP and complete() here, as sometimes
386 + the tx_end is already seen before this is finished */
387 + priv->status = STATUS_STOP;
388 + complete(&priv->cmd_complete);
390 + i2c_w32(I2C_ENDD_CTRL_SETEND, endd_ctrl);
391 + priv->status = STATUS_READ_END;
396 +static void falcon_i2c_xfer_init(struct falcon_i2c *priv)
398 + /* enable interrupts */
399 + i2c_w32(FALCON_I2C_IMSC_DEFAULT_MASK, imsc);
401 + /* trigger transfer of first msg */
405 +static void dump_msgs(struct i2c_msg msgs[], int num, int rx)
409 + printk("Messages %d %s\n", num, rx ? "out" : "in");
410 + for (i = 0; i < num; i++) {
411 + printk("%2d %cX Msg(%d) addr=0x%X: ", i,
412 + (msgs[i].flags & I2C_M_RD)?'R':'T',
413 + msgs[i].len, msgs[i].addr);
414 + if (!(msgs[i].flags & I2C_M_RD) || rx) {
415 + for (j = 0; j < msgs[i].len; j++)
416 + printk("%02X ", msgs[i].buf[j]);
423 +static void falcon_i2c_release_bus(struct falcon_i2c *priv)
425 + if ((i2c_r32(bus_stat) & I2C_BUS_STAT_BS_MASK) == I2C_BUS_STAT_BS_BM)
426 + i2c_w32(I2C_ENDD_CTRL_SETEND, endd_ctrl);
429 +static int falcon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
432 + struct falcon_i2c *priv = i2c_get_adapdata(adap);
435 + dev_dbg(priv->dev, "xfer %u messages\n", num);
436 + dump_msgs(msgs, num, 0);
438 + mutex_lock(&priv->mutex);
440 + INIT_COMPLETION(priv->cmd_complete);
441 + priv->current_msg = msgs;
442 + priv->msgs_num = num;
444 + priv->status = STATUS_IDLE;
446 + /* wait for the bus to become ready */
447 + ret = falcon_i2c_wait_bus_not_busy(priv);
451 + while (priv->msgs_num) {
452 + /* start the transfers */
453 + falcon_i2c_xfer_init(priv);
455 + /* wait for transfers to complete */
456 + ret = wait_for_completion_interruptible_timeout(
457 + &priv->cmd_complete, FALCON_I2C_XFER_TIMEOUT);
459 + dev_err(priv->dev, "controller timed out\n");
460 + falcon_i2c_hw_init(adap);
463 + } else if (ret < 0)
466 + if (priv->msg_err) {
467 + if (priv->msg_err & FALCON_I2C_NACK)
473 + if (--priv->msgs_num) {
474 + priv->current_msg++;
481 + falcon_i2c_release_bus(priv);
483 + mutex_unlock(&priv->mutex);
486 + dump_msgs(msgs, num, 1);
488 + PRINTK("XFER ret %d\n", ret);
492 +static irqreturn_t falcon_i2c_isr_burst(int irq, void *dev_id)
494 + struct falcon_i2c *priv = dev_id;
495 + struct i2c_msg *msg = priv->current_msg;
496 + int last = (irq == priv->irq_lb);
503 + if (msg->flags & I2C_M_RD) {
504 + switch (priv->status) {
507 + prepare_msg_send_addr(priv);
508 + disable_burst_irq(priv);
511 + case STATUS_READ_END:
513 + falcon_i2c_rx(priv, last);
516 + disable_burst_irq(priv);
517 + printk("Status R %d\n", priv->status);
521 + switch (priv->status) {
524 + prepare_msg_send_addr(priv);
528 + falcon_i2c_tx(priv, last);
531 + disable_burst_irq(priv);
532 + printk("Status W %d\n", priv->status);
537 + i2c_w32(I2C_ICR_BREQ_INT_CLR | I2C_ICR_LBREQ_INT_CLR, icr);
538 + return IRQ_HANDLED;
541 +static void falcon_i2c_isr_prot(struct falcon_i2c *priv)
543 + u32 i_pro = i2c_r32(p_irqss);
547 + /* not acknowledge */
548 + if (i_pro & I2C_P_IRQSS_NACK) {
549 + priv->msg_err |= FALCON_I2C_NACK;
553 + /* arbitration lost */
554 + if (i_pro & I2C_P_IRQSS_AL) {
555 + priv->msg_err |= FALCON_I2C_ARB_LOST;
556 + PRINTK(" arb-lost");
558 + /* tx -> rx switch */
559 + if (i_pro & I2C_P_IRQSS_RX)
563 + if (i_pro & I2C_P_IRQSS_TX_END)
567 + if (!priv->msg_err) {
568 + /* tx -> rx switch */
569 + if (i_pro & I2C_P_IRQSS_RX) {
570 + priv->status = STATUS_READ;
571 + enable_burst_irq(priv);
573 + if (i_pro & I2C_P_IRQSS_TX_END) {
574 + if (priv->status == STATUS_READ)
575 + priv->status = STATUS_READ_END;
577 + disable_burst_irq(priv);
578 + priv->status = STATUS_STOP;
583 + i2c_w32(i_pro, p_irqsc);
586 +static irqreturn_t falcon_i2c_isr(int irq, void *dev_id)
588 + u32 i_raw, i_err=0;
589 + struct falcon_i2c *priv = dev_id;
591 + i_raw = i2c_r32(mis);
592 + PRINTK("i_raw 0x%08X\n", i_raw);
594 + /* error interrupt */
595 + if (i_raw & I2C_RIS_I2C_ERR_INT_INTOCC) {
596 + i_err = i2c_r32(err_irqss);
597 + PRINTK("i_err 0x%08X bus_stat 0x%04X\n",
598 + i_err, i2c_r32(bus_stat));
600 + /* tx fifo overflow (8) */
601 + if (i_err & I2C_ERR_IRQSS_TXF_OFL)
602 + priv->msg_err |= FALCON_I2C_TX_OFL;
604 + /* tx fifo underflow (4) */
605 + if (i_err & I2C_ERR_IRQSS_TXF_UFL)
606 + priv->msg_err |= FALCON_I2C_TX_UFL;
608 + /* rx fifo overflow (2) */
609 + if (i_err & I2C_ERR_IRQSS_RXF_OFL)
610 + priv->msg_err |= FALCON_I2C_RX_OFL;
612 + /* rx fifo underflow (1) */
613 + if (i_err & I2C_ERR_IRQSS_RXF_UFL)
614 + priv->msg_err |= FALCON_I2C_RX_UFL;
616 + i2c_w32(i_err, err_irqsc);
619 + /* protocol interrupt */
620 + if (i_raw & I2C_RIS_I2C_P_INT_INTOCC)
621 + falcon_i2c_isr_prot(priv);
623 + if ((priv->msg_err) || (priv->status == STATUS_STOP))
624 + complete(&priv->cmd_complete);
626 + return IRQ_HANDLED;
629 +static u32 falcon_i2c_functionality(struct i2c_adapter *adap)
631 + return I2C_FUNC_I2C |
632 + I2C_FUNC_10BIT_ADDR |
633 + I2C_FUNC_SMBUS_EMUL;
636 +static struct i2c_algorithm falcon_i2c_algorithm = {
637 + .master_xfer = falcon_i2c_xfer,
638 + .functionality = falcon_i2c_functionality,
641 +static int __devinit falcon_i2c_probe(struct platform_device *pdev)
644 + struct falcon_i2c *priv;
645 + struct i2c_adapter *adap;
646 + struct resource *mmres, *ioarea,
647 + *irqres_lb, *irqres_b, *irqres_err, *irqres_p;
650 + dev_dbg(&pdev->dev, "probing\n");
652 + mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
653 + irqres_lb = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
655 + irqres_b = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "i2c_b");
656 + irqres_err = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
658 + irqres_p = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "i2c_p");
660 + if (!mmres || !irqres_lb || !irqres_b || !irqres_err || !irqres_p) {
661 + dev_err(&pdev->dev, "no resources\n");
665 + clk = clk_get(&pdev->dev, "fpi");
667 + dev_err(&pdev->dev, "failed to get fpi clk\n");
671 + if (clk_get_rate(clk) != 100000000) {
672 + dev_err(&pdev->dev, "input clock is not 100MHz\n");
676 + /* allocate private data */
677 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
679 + dev_err(&pdev->dev, "can't allocate private data\n");
683 + adap = &priv->adap;
684 + i2c_set_adapdata(adap, priv);
685 + adap->owner = THIS_MODULE;
686 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
687 + strlcpy(adap->name, DRV_NAME "-adapter", sizeof(adap->name));
688 + adap->algo = &falcon_i2c_algorithm;
690 + priv->mode = FALCON_I2C_MODE_100;
692 + priv->dev = &pdev->dev;
694 + init_completion(&priv->cmd_complete);
695 + mutex_init(&priv->mutex);
697 + ret = ltq_gpio_request(107, 0, 0, 0, DRV_NAME":sda");
699 + dev_err(&pdev->dev, "I2C gpio 107 (sda) not available\n");
701 + goto err_free_priv;
703 + ret = ltq_gpio_request(108, 0, 0, 0, DRV_NAME":scl");
706 + dev_err(&pdev->dev, "I2C gpio 108 (scl) not available\n");
708 + goto err_free_priv;
711 + ioarea = request_mem_region(mmres->start, resource_size(mmres),
714 + if (ioarea == NULL) {
715 + dev_err(&pdev->dev, "I2C region already claimed\n");
717 + goto err_free_gpio;
721 + priv->membase = ioremap_nocache(mmres->start & ~KSEG1,
722 + resource_size(mmres));
723 + if (priv->membase == NULL) {
725 + goto err_release_region;
728 + priv->irq_lb = irqres_lb->start;
729 + ret = request_irq(priv->irq_lb, falcon_i2c_isr_burst, IRQF_DISABLED,
730 + irqres_lb->name, priv);
732 + dev_err(&pdev->dev, "can't get last burst IRQ %d\n", irqres_lb->start);
734 + goto err_unmap_mem;
737 + priv->irq_b = irqres_b->start;
738 + ret = request_irq(priv->irq_b, falcon_i2c_isr_burst, IRQF_DISABLED,
739 + irqres_b->name, priv);
741 + dev_err(&pdev->dev, "can't get burst IRQ %d\n", irqres_b->start);
743 + goto err_free_lb_irq;
746 + priv->irq_err = irqres_err->start;
747 + ret = request_irq(priv->irq_err, falcon_i2c_isr, IRQF_DISABLED,
748 + irqres_err->name, priv);
750 + dev_err(&pdev->dev, "can't get error IRQ %d\n", irqres_err->start);
752 + goto err_free_b_irq;
755 + priv->irq_p = irqres_p->start;
756 + ret = request_irq(priv->irq_p, falcon_i2c_isr, IRQF_DISABLED,
757 + irqres_p->name, priv);
759 + dev_err(&pdev->dev, "can't get protocol IRQ %d\n", irqres_p->start);
761 + goto err_free_err_irq;
764 + dev_dbg(&pdev->dev, "mapped io-space to %p\n", priv->membase);
765 + dev_dbg(&pdev->dev, "use IRQs %d, %d, %d, %d\n", irqres_lb->start,
766 + irqres_b->start, irqres_err->start, irqres_p->start);
768 + /* add our adapter to the i2c stack */
769 + ret = i2c_add_numbered_adapter(adap);
771 + dev_err(&pdev->dev, "can't register I2C adapter\n");
772 + goto err_free_p_irq;
775 + platform_set_drvdata(pdev, priv);
776 + i2c_set_adapdata(adap, priv);
778 + /* print module version information */
779 + dev_dbg(&pdev->dev, "module id=%u revision=%u\n",
780 + (i2c_r32(id) & I2C_ID_ID_MASK) >> I2C_ID_ID_OFFSET,
781 + (i2c_r32(id) & I2C_ID_REV_MASK) >> I2C_ID_REV_OFFSET);
783 + /* initialize HW */
784 + ret = falcon_i2c_hw_init(adap);
786 + dev_err(&pdev->dev, "can't configure adapter\n");
787 + goto err_remove_adapter;
790 + dev_info(&pdev->dev, "version %s\n", DRV_VERSION);
795 + i2c_del_adapter(adap);
796 + platform_set_drvdata(pdev, NULL);
799 + free_irq(priv->irq_p, priv);
802 + free_irq(priv->irq_err, priv);
805 + free_irq(priv->irq_b, priv);
808 + free_irq(priv->irq_lb, priv);
811 + iounmap(priv->membase);
814 + release_mem_region(mmres->start, resource_size(mmres));
826 +static int __devexit falcon_i2c_remove(struct platform_device *pdev)
828 + struct falcon_i2c *priv = platform_get_drvdata(pdev);
829 + struct resource *mmres;
832 + i2c_w32_mask(I2C_RUN_CTRL_RUN_EN, 0, run_ctrl);
834 + /* remove driver */
835 + platform_set_drvdata(pdev, NULL);
836 + i2c_del_adapter(&priv->adap);
838 + free_irq(priv->irq_lb, priv);
839 + free_irq(priv->irq_b, priv);
840 + free_irq(priv->irq_err, priv);
841 + free_irq(priv->irq_p, priv);
843 + iounmap(priv->membase);
850 + mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
851 + release_mem_region(mmres->start, resource_size(mmres));
853 + dev_dbg(&pdev->dev, "removed\n");
858 +static struct platform_driver falcon_i2c_driver = {
859 + .probe = falcon_i2c_probe,
860 + .remove = __devexit_p(falcon_i2c_remove),
863 + .owner = THIS_MODULE,
867 +static int __init falcon_i2c_init(void)
871 + ret = platform_driver_register(&falcon_i2c_driver);
874 + pr_debug(DRV_NAME ": can't register platform driver\n");
879 +static void __exit falcon_i2c_exit(void)
881 + platform_driver_unregister(&falcon_i2c_driver);
884 +module_init(falcon_i2c_init);
885 +module_exit(falcon_i2c_exit);
887 +MODULE_DESCRIPTION("Lantiq FALC(tm) ON - I2C bus adapter");
888 +MODULE_ALIAS("platform:" DRV_NAME);
889 +MODULE_LICENSE("GPL");
890 +MODULE_VERSION(DRV_VERSION);