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 diff --git a/arch/mips/lantiq/falcon/devices.c b/arch/mips/lantiq/falcon/devices.c
16 index 4f47b44..a998b6b 100644
17 --- a/arch/mips/lantiq/falcon/devices.c
18 +++ b/arch/mips/lantiq/falcon/devices.c
19 @@ -126,3 +126,24 @@ falcon_register_gpio_extra(void)
20 ltq_sysctl_activate(SYSCTL_SYS1,
21 ACTS_PADCTRL3 | ACTS_PADCTRL4 | ACTS_P3 | ACTS_P4);
25 +static struct resource falcon_i2c_resources[] = {
26 + MEM_RES("i2c", GPON_I2C_BASE,GPON_I2C_END),
27 + IRQ_RES("i2c_lb", FALCON_IRQ_I2C_LBREQ),
28 + IRQ_RES("i2c_b", FALCON_IRQ_I2C_BREQ),
29 + IRQ_RES("i2c_err", FALCON_IRQ_I2C_I2C_ERR),
30 + IRQ_RES("i2c_p", FALCON_IRQ_I2C_I2C_P),
33 +void __init falcon_register_i2c(void)
35 + platform_device_register_simple("i2c-falcon", 0,
36 + falcon_i2c_resources, ARRAY_SIZE(falcon_i2c_resources));
37 + sys1_hw_activate(ACTS_I2C_ACT);
40 +void __init falcon_register_crypto(void)
42 + platform_device_register_simple("ltq_falcon_deu", 0, NULL, 0);
44 diff --git a/arch/mips/lantiq/falcon/devices.h b/arch/mips/lantiq/falcon/devices.h
45 index 18be8b6..2fdcb08 100644
46 --- a/arch/mips/lantiq/falcon/devices.h
47 +++ b/arch/mips/lantiq/falcon/devices.h
49 extern void falcon_register_nand(void);
50 extern void falcon_register_gpio(void);
51 extern void falcon_register_gpio_extra(void);
52 +extern void falcon_register_i2c(void);
55 diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
56 index 646068e..e6c3ab6 100644
57 --- a/drivers/i2c/busses/Kconfig
58 +++ b/drivers/i2c/busses/Kconfig
59 @@ -284,6 +284,10 @@ config I2C_POWERMAC
61 comment "I2C system bus drivers (mostly embedded / system-on-chip)"
64 + tristate "Falcon I2C interface"
65 +# depends on SOC_FALCON
68 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
69 depends on ARCH_AT91 && EXPERIMENTAL && BROKEN
70 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
71 index e6cf294..83e9250 100644
72 --- a/drivers/i2c/busses/Makefile
73 +++ b/drivers/i2c/busses/Makefile
74 @@ -82,5 +82,6 @@ obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
75 obj-$(CONFIG_I2C_STUB) += i2c-stub.o
76 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
77 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
78 +obj-$(CONFIG_I2C_FALCON) += i2c-falcon.o
80 ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
81 diff --git a/drivers/i2c/busses/i2c-falcon.c b/drivers/i2c/busses/i2c-falcon.c
83 index 0000000..7bb1253
85 +++ b/drivers/i2c/busses/i2c-falcon.c
88 + * Lantiq FALC(tm) ON - I2C bus adapter
90 + * Parts based on i2c-designware.c and other i2c drivers from Linux 2.6.33
92 + * This program is free software; you can redistribute it and/or modify
93 + * it under the terms of the GNU General Public License as published by
94 + * the Free Software Foundation; either version 2 of the License, or
95 + * (at your option) any later version.
97 + * This program is distributed in the hope that it will be useful,
98 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
99 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100 + * GNU General Public License for more details.
102 + * You should have received a copy of the GNU General Public License
103 + * along with this program; if not, write to the Free Software
104 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
109 +#include <linux/kernel.h>
110 +#include <linux/module.h>
111 +#include <linux/delay.h>
112 +#include <linux/slab.h> /* for kzalloc, kfree */
113 +#include <linux/i2c.h>
114 +#include <linux/clk.h>
115 +#include <linux/errno.h>
116 +#include <linux/sched.h>
117 +#include <linux/err.h>
118 +#include <linux/interrupt.h>
119 +#include <linux/platform_device.h>
120 +#include <linux/io.h>
121 +#include <linux/gpio.h>
123 +#include <falcon/lantiq_soc.h>
126 + * - no high speed support
127 + * - supports only master mode
128 + * - ten bit mode is not tested (no slave devices)
131 +/* mapping for access macros */
132 +#define reg_r32(reg) __raw_readl(reg)
133 +#define reg_w32(val, reg) __raw_writel(val, reg)
134 +#define reg_w32_mask(clear, set, reg) \
135 + reg_w32((reg_r32(reg) & ~(clear)) | (set), reg)
136 +#define reg_r32_table(reg, idx) reg_r32(&((uint32_t *)®)[idx])
137 +#define reg_w32_table(val, reg, idx) reg_w32(val, &((uint32_t *)®)[idx])
138 +#define i2c (priv->membase)
139 +#include <falcon/i2c_reg.h>
141 +#define DRV_NAME "i2c-falcon"
142 +#define DRV_VERSION "1.01"
144 +#define FALCON_I2C_BUSY_TIMEOUT 20 /* ms */
147 +#define FALCON_I2C_XFER_TIMEOUT 25*HZ
149 +#define FALCON_I2C_XFER_TIMEOUT HZ
151 +#if defined(DEBUG) && 0
152 +#define PRINTK(arg...) printk(arg)
154 +#define PRINTK(arg...) do {} while (0)
157 +#define FALCON_I2C_IMSC_DEFAULT_MASK (I2C_IMSC_I2C_P_INT_EN | \
158 + I2C_IMSC_I2C_ERR_INT_EN)
160 +#define FALCON_I2C_ARB_LOST (1 << 0)
161 +#define FALCON_I2C_NACK (1 << 1)
162 +#define FALCON_I2C_RX_UFL (1 << 2)
163 +#define FALCON_I2C_RX_OFL (1 << 3)
164 +#define FALCON_I2C_TX_UFL (1 << 4)
165 +#define FALCON_I2C_TX_OFL (1 << 5)
168 + struct mutex mutex;
171 + FALCON_I2C_MODE_100 = 1,
172 + FALCON_I2C_MODE_400 = 2,
173 + FALCON_I2C_MODE_3400 = 3
174 + } mode; /* current speed mode */
176 + struct clk *clk; /* clock input for i2c hardware block */
177 + struct gpon_reg_i2c __iomem *membase; /* base of mapped registers */
178 + int irq_lb, irq_b, irq_err, irq_p; /* last burst, burst, error,
181 + struct i2c_adapter adap;
182 + struct device *dev;
184 + struct completion cmd_complete;
186 + /* message transfer data */
187 + /* current message */
188 + struct i2c_msg *current_msg;
189 + /* number of messages to handle */
191 + /* current buffer */
193 + /* remaining length of current buffer */
195 + /* error status of the current transfer */
198 + /* master status codes */
201 + STATUS_ADDR, /* address phase */
209 +static irqreturn_t falcon_i2c_isr(int irq, void *dev_id);
211 +static inline void enable_burst_irq(struct falcon_i2c *priv)
213 + i2c_w32_mask(0, I2C_IMSC_LBREQ_INT_EN | I2C_IMSC_BREQ_INT_EN, imsc);
215 +static inline void disable_burst_irq(struct falcon_i2c *priv)
217 + i2c_w32_mask(I2C_IMSC_LBREQ_INT_EN | I2C_IMSC_BREQ_INT_EN, 0, imsc);
220 +static void prepare_msg_send_addr(struct falcon_i2c *priv)
222 + struct i2c_msg *msg = priv->current_msg;
223 + int rd = !!(msg->flags & I2C_M_RD); /* extends to 0 or 1 */
224 + u16 addr = msg->addr;
227 + priv->msg_buf = msg->buf;
228 + priv->msg_buf_len = msg->len;
230 + priv->status = STATUS_READ;
232 + priv->status = STATUS_WRITE;
234 + /* send slave address */
235 + if (msg->flags & I2C_M_TEN) {
236 + i2c_w32(0xf0 | ((addr & 0x300) >> 7) | rd, txd);
237 + i2c_w32(addr & 0xff, txd);
239 + i2c_w32((addr & 0x7f) << 1 | rd, txd);
242 +static void set_tx_len(struct falcon_i2c *priv)
244 + struct i2c_msg *msg = priv->current_msg;
245 + int len = (msg->flags & I2C_M_TEN) ? 2 : 1;
247 + PRINTK("set_tx_len %cX\n", (msg->flags & I2C_M_RD)?'R':'T');
249 + priv->status = STATUS_ADDR;
251 + if (!(msg->flags & I2C_M_RD)) {
254 + /* set maximum received packet size (before rx int!) */
255 + i2c_w32(msg->len, mrps_ctrl);
257 + i2c_w32(len, tps_ctrl);
258 + enable_burst_irq(priv);
261 +static int falcon_i2c_hw_init(struct i2c_adapter *adap)
263 + struct falcon_i2c *priv = i2c_get_adapdata(adap);
266 + i2c_w32_mask(I2C_RUN_CTRL_RUN_EN, 0, run_ctrl);
269 + /* set normal operation clock divider */
270 + i2c_w32(1 << I2C_CLC_RMC_OFFSET, clc);
272 + /* for debugging a higher divider value! */
273 + i2c_w32(0xF0 << I2C_CLC_RMC_OFFSET, clc);
276 + /* set frequency */
277 + if (priv->mode == FALCON_I2C_MODE_100) {
278 + dev_dbg(priv->dev, "set standard mode (100 kHz)\n");
279 + i2c_w32(0, fdiv_high_cfg);
280 + i2c_w32((1 << I2C_FDIV_CFG_INC_OFFSET) |
281 + (499 << I2C_FDIV_CFG_DEC_OFFSET),
283 + } else if (priv->mode == FALCON_I2C_MODE_400) {
284 + dev_dbg(priv->dev, "set fast mode (400 kHz)\n");
285 + i2c_w32(0, fdiv_high_cfg);
286 + i2c_w32((1 << I2C_FDIV_CFG_INC_OFFSET) |
287 + (124 << I2C_FDIV_CFG_DEC_OFFSET),
289 + } else if (priv->mode == FALCON_I2C_MODE_3400) {
290 + dev_dbg(priv->dev, "set high mode (3.4 MHz)\n");
291 + i2c_w32(0, fdiv_cfg);
292 + /* TODO recalculate value for 100MHz input */
293 + i2c_w32((41 << I2C_FDIV_HIGH_CFG_INC_OFFSET) |
294 + (152 << I2C_FDIV_HIGH_CFG_DEC_OFFSET),
297 + dev_warn(priv->dev, "unknown mode\n");
301 + /* configure fifo */
302 + i2c_w32(I2C_FIFO_CFG_TXFC | /* tx fifo as flow controller */
303 + I2C_FIFO_CFG_RXFC | /* rx fifo as flow controller */
304 + I2C_FIFO_CFG_TXFA_TXFA2 | /* tx fifo 4-byte aligned */
305 + I2C_FIFO_CFG_RXFA_RXFA2 | /* rx fifo 4-byte aligned */
306 + I2C_FIFO_CFG_TXBS_TXBS0 | /* tx fifo burst size is 1 word */
307 + I2C_FIFO_CFG_RXBS_RXBS0, /* rx fifo burst size is 1 word */
310 + /* configure address */
311 + i2c_w32(I2C_ADDR_CFG_SOPE_EN | /* generate stop when no more data in the
313 + I2C_ADDR_CFG_SONA_EN | /* generate stop when NA received */
314 + I2C_ADDR_CFG_MnS_EN | /* we are master device */
315 + 0, /* our slave address (not used!) */
319 + i2c_w32_mask(0, I2C_RUN_CTRL_RUN_EN, run_ctrl);
324 +static int falcon_i2c_wait_bus_not_busy(struct falcon_i2c *priv)
326 + int timeout = FALCON_I2C_BUSY_TIMEOUT;
328 + while ((i2c_r32(bus_stat) & I2C_BUS_STAT_BS_MASK)
329 + != I2C_BUS_STAT_BS_FREE) {
330 + if (timeout <= 0) {
331 + dev_warn(priv->dev, "timeout waiting for bus ready\n");
341 +static void falcon_i2c_tx(struct falcon_i2c *priv, int last)
343 + if (priv->msg_buf_len && priv->msg_buf) {
344 + i2c_w32(*priv->msg_buf, txd);
346 + if (--priv->msg_buf_len)
349 + priv->msg_buf = NULL;
354 + disable_burst_irq(priv);
358 +static void falcon_i2c_rx(struct falcon_i2c *priv, int last)
360 + u32 fifo_stat,timeout;
361 + if (priv->msg_buf_len && priv->msg_buf) {
364 + fifo_stat = i2c_r32(ffs_stat);
365 + } while (!fifo_stat && --timeout);
368 + PRINTK("\nrx timeout\n");
371 + while (fifo_stat) {
372 + *priv->msg_buf = i2c_r32(rxd);
373 + if (--priv->msg_buf_len)
376 + priv->msg_buf = NULL;
381 + fifo_stat = i2c_r32(ffs_stat);
383 + /* do not read more than burst size, otherwise no "last
384 + burst" is generated and the transaction is blocked! */
393 + disable_burst_irq(priv);
395 + if (priv->status == STATUS_READ_END) {
396 + /* do the STATUS_STOP and complete() here, as sometimes
397 + the tx_end is already seen before this is finished */
398 + priv->status = STATUS_STOP;
399 + complete(&priv->cmd_complete);
401 + i2c_w32(I2C_ENDD_CTRL_SETEND, endd_ctrl);
402 + priv->status = STATUS_READ_END;
407 +static void falcon_i2c_xfer_init(struct falcon_i2c *priv)
409 + /* enable interrupts */
410 + i2c_w32(FALCON_I2C_IMSC_DEFAULT_MASK, imsc);
412 + /* trigger transfer of first msg */
416 +static void dump_msgs(struct i2c_msg msgs[], int num, int rx)
420 + printk("Messages %d %s\n", num, rx ? "out" : "in");
421 + for (i = 0; i < num; i++) {
422 + printk("%2d %cX Msg(%d) addr=0x%X: ", i,
423 + (msgs[i].flags & I2C_M_RD)?'R':'T',
424 + msgs[i].len, msgs[i].addr);
425 + if (!(msgs[i].flags & I2C_M_RD) || rx) {
426 + for (j = 0; j < msgs[i].len; j++)
427 + printk("%02X ", msgs[i].buf[j]);
434 +static void falcon_i2c_release_bus(struct falcon_i2c *priv)
436 + if ((i2c_r32(bus_stat) & I2C_BUS_STAT_BS_MASK) == I2C_BUS_STAT_BS_BM)
437 + i2c_w32(I2C_ENDD_CTRL_SETEND, endd_ctrl);
440 +static int falcon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
443 + struct falcon_i2c *priv = i2c_get_adapdata(adap);
446 + dev_dbg(priv->dev, "xfer %u messages\n", num);
447 + dump_msgs(msgs, num, 0);
449 + mutex_lock(&priv->mutex);
451 + INIT_COMPLETION(priv->cmd_complete);
452 + priv->current_msg = msgs;
453 + priv->msgs_num = num;
455 + priv->status = STATUS_IDLE;
457 + /* wait for the bus to become ready */
458 + ret = falcon_i2c_wait_bus_not_busy(priv);
462 + while (priv->msgs_num) {
463 + /* start the transfers */
464 + falcon_i2c_xfer_init(priv);
466 + /* wait for transfers to complete */
467 + ret = wait_for_completion_interruptible_timeout(
468 + &priv->cmd_complete, FALCON_I2C_XFER_TIMEOUT);
470 + dev_err(priv->dev, "controller timed out\n");
471 + falcon_i2c_hw_init(adap);
474 + } else if (ret < 0)
477 + if (priv->msg_err) {
478 + if (priv->msg_err & FALCON_I2C_NACK)
484 + if (--priv->msgs_num) {
485 + priv->current_msg++;
492 + falcon_i2c_release_bus(priv);
494 + mutex_unlock(&priv->mutex);
497 + dump_msgs(msgs, num, 1);
499 + PRINTK("XFER ret %d\n", ret);
503 +static irqreturn_t falcon_i2c_isr_burst(int irq, void *dev_id)
505 + struct falcon_i2c *priv = dev_id;
506 + struct i2c_msg *msg = priv->current_msg;
507 + int last = (irq == priv->irq_lb);
514 + if (msg->flags & I2C_M_RD) {
515 + switch (priv->status) {
518 + prepare_msg_send_addr(priv);
519 + disable_burst_irq(priv);
522 + case STATUS_READ_END:
524 + falcon_i2c_rx(priv, last);
527 + disable_burst_irq(priv);
528 + printk("Status R %d\n", priv->status);
532 + switch (priv->status) {
535 + prepare_msg_send_addr(priv);
539 + falcon_i2c_tx(priv, last);
542 + disable_burst_irq(priv);
543 + printk("Status W %d\n", priv->status);
548 + i2c_w32(I2C_ICR_BREQ_INT_CLR | I2C_ICR_LBREQ_INT_CLR, icr);
549 + return IRQ_HANDLED;
552 +static void falcon_i2c_isr_prot(struct falcon_i2c *priv)
554 + u32 i_pro = i2c_r32(p_irqss);
558 + /* not acknowledge */
559 + if (i_pro & I2C_P_IRQSS_NACK) {
560 + priv->msg_err |= FALCON_I2C_NACK;
564 + /* arbitration lost */
565 + if (i_pro & I2C_P_IRQSS_AL) {
566 + priv->msg_err |= FALCON_I2C_ARB_LOST;
567 + PRINTK(" arb-lost");
569 + /* tx -> rx switch */
570 + if (i_pro & I2C_P_IRQSS_RX)
574 + if (i_pro & I2C_P_IRQSS_TX_END)
578 + if (!priv->msg_err) {
579 + /* tx -> rx switch */
580 + if (i_pro & I2C_P_IRQSS_RX) {
581 + priv->status = STATUS_READ;
582 + enable_burst_irq(priv);
584 + if (i_pro & I2C_P_IRQSS_TX_END) {
585 + if (priv->status == STATUS_READ)
586 + priv->status = STATUS_READ_END;
588 + disable_burst_irq(priv);
589 + priv->status = STATUS_STOP;
594 + i2c_w32(i_pro, p_irqsc);
597 +static irqreturn_t falcon_i2c_isr(int irq, void *dev_id)
599 + u32 i_raw, i_err=0;
600 + struct falcon_i2c *priv = dev_id;
602 + i_raw = i2c_r32(mis);
603 + PRINTK("i_raw 0x%08X\n", i_raw);
605 + /* error interrupt */
606 + if (i_raw & I2C_RIS_I2C_ERR_INT_INTOCC) {
607 + i_err = i2c_r32(err_irqss);
608 + PRINTK("i_err 0x%08X bus_stat 0x%04X\n",
609 + i_err, i2c_r32(bus_stat));
611 + /* tx fifo overflow (8) */
612 + if (i_err & I2C_ERR_IRQSS_TXF_OFL)
613 + priv->msg_err |= FALCON_I2C_TX_OFL;
615 + /* tx fifo underflow (4) */
616 + if (i_err & I2C_ERR_IRQSS_TXF_UFL)
617 + priv->msg_err |= FALCON_I2C_TX_UFL;
619 + /* rx fifo overflow (2) */
620 + if (i_err & I2C_ERR_IRQSS_RXF_OFL)
621 + priv->msg_err |= FALCON_I2C_RX_OFL;
623 + /* rx fifo underflow (1) */
624 + if (i_err & I2C_ERR_IRQSS_RXF_UFL)
625 + priv->msg_err |= FALCON_I2C_RX_UFL;
627 + i2c_w32(i_err, err_irqsc);
630 + /* protocol interrupt */
631 + if (i_raw & I2C_RIS_I2C_P_INT_INTOCC)
632 + falcon_i2c_isr_prot(priv);
634 + if ((priv->msg_err) || (priv->status == STATUS_STOP))
635 + complete(&priv->cmd_complete);
637 + return IRQ_HANDLED;
640 +static u32 falcon_i2c_functionality(struct i2c_adapter *adap)
642 + return I2C_FUNC_I2C |
643 + I2C_FUNC_10BIT_ADDR |
644 + I2C_FUNC_SMBUS_EMUL;
647 +static struct i2c_algorithm falcon_i2c_algorithm = {
648 + .master_xfer = falcon_i2c_xfer,
649 + .functionality = falcon_i2c_functionality,
652 +static int __devinit falcon_i2c_probe(struct platform_device *pdev)
655 + struct falcon_i2c *priv;
656 + struct i2c_adapter *adap;
657 + struct resource *mmres, *ioarea,
658 + *irqres_lb, *irqres_b, *irqres_err, *irqres_p;
661 + dev_dbg(&pdev->dev, "probing\n");
663 + mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
664 + irqres_lb = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
666 + irqres_b = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "i2c_b");
667 + irqres_err = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
669 + irqres_p = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "i2c_p");
671 + if (!mmres || !irqres_lb || !irqres_b || !irqres_err || !irqres_p) {
672 + dev_err(&pdev->dev, "no resources\n");
676 + clk = clk_get(&pdev->dev, "fpi");
678 + dev_err(&pdev->dev, "failed to get fpi clk\n");
682 + if (clk_get_rate(clk) != 100000000) {
683 + dev_err(&pdev->dev, "input clock is not 100MHz\n");
687 + /* allocate private data */
688 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
690 + dev_err(&pdev->dev, "can't allocate private data\n");
694 + adap = &priv->adap;
695 + i2c_set_adapdata(adap, priv);
696 + adap->owner = THIS_MODULE;
697 + adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
698 + strlcpy(adap->name, DRV_NAME "-adapter", sizeof(adap->name));
699 + adap->algo = &falcon_i2c_algorithm;
701 + priv->mode = FALCON_I2C_MODE_100;
703 + priv->dev = &pdev->dev;
705 + init_completion(&priv->cmd_complete);
706 + mutex_init(&priv->mutex);
708 + ret = ltq_gpio_request(107, 0, 0, 0, DRV_NAME":sda");
710 + dev_err(&pdev->dev, "I2C gpio 107 (sda) not available\n");
712 + goto err_free_priv;
714 + ret = ltq_gpio_request(108, 0, 0, 0, DRV_NAME":scl");
717 + dev_err(&pdev->dev, "I2C gpio 108 (scl) not available\n");
719 + goto err_free_priv;
722 + ioarea = request_mem_region(mmres->start, resource_size(mmres),
725 + if (ioarea == NULL) {
726 + dev_err(&pdev->dev, "I2C region already claimed\n");
728 + goto err_free_gpio;
732 + priv->membase = ioremap_nocache(mmres->start & ~KSEG1,
733 + resource_size(mmres));
734 + if (priv->membase == NULL) {
736 + goto err_release_region;
739 + priv->irq_lb = irqres_lb->start;
740 + ret = request_irq(priv->irq_lb, falcon_i2c_isr_burst, IRQF_DISABLED,
741 + irqres_lb->name, priv);
743 + dev_err(&pdev->dev, "can't get last burst IRQ %d\n", irqres_lb->start);
745 + goto err_unmap_mem;
748 + priv->irq_b = irqres_b->start;
749 + ret = request_irq(priv->irq_b, falcon_i2c_isr_burst, IRQF_DISABLED,
750 + irqres_b->name, priv);
752 + dev_err(&pdev->dev, "can't get burst IRQ %d\n", irqres_b->start);
754 + goto err_free_lb_irq;
757 + priv->irq_err = irqres_err->start;
758 + ret = request_irq(priv->irq_err, falcon_i2c_isr, IRQF_DISABLED,
759 + irqres_err->name, priv);
761 + dev_err(&pdev->dev, "can't get error IRQ %d\n", irqres_err->start);
763 + goto err_free_b_irq;
766 + priv->irq_p = irqres_p->start;
767 + ret = request_irq(priv->irq_p, falcon_i2c_isr, IRQF_DISABLED,
768 + irqres_p->name, priv);
770 + dev_err(&pdev->dev, "can't get protocol IRQ %d\n", irqres_p->start);
772 + goto err_free_err_irq;
775 + dev_dbg(&pdev->dev, "mapped io-space to %p\n", priv->membase);
776 + dev_dbg(&pdev->dev, "use IRQs %d, %d, %d, %d\n", irqres_lb->start,
777 + irqres_b->start, irqres_err->start, irqres_p->start);
779 + /* add our adapter to the i2c stack */
780 + ret = i2c_add_numbered_adapter(adap);
782 + dev_err(&pdev->dev, "can't register I2C adapter\n");
783 + goto err_free_p_irq;
786 + platform_set_drvdata(pdev, priv);
787 + i2c_set_adapdata(adap, priv);
789 + /* print module version information */
790 + dev_dbg(&pdev->dev, "module id=%u revision=%u\n",
791 + (i2c_r32(id) & I2C_ID_ID_MASK) >> I2C_ID_ID_OFFSET,
792 + (i2c_r32(id) & I2C_ID_REV_MASK) >> I2C_ID_REV_OFFSET);
794 + /* initialize HW */
795 + ret = falcon_i2c_hw_init(adap);
797 + dev_err(&pdev->dev, "can't configure adapter\n");
798 + goto err_remove_adapter;
801 + dev_info(&pdev->dev, "version %s\n", DRV_VERSION);
806 + i2c_del_adapter(adap);
807 + platform_set_drvdata(pdev, NULL);
810 + free_irq(priv->irq_p, priv);
813 + free_irq(priv->irq_err, priv);
816 + free_irq(priv->irq_b, priv);
819 + free_irq(priv->irq_lb, priv);
822 + iounmap(priv->membase);
825 + release_mem_region(mmres->start, resource_size(mmres));
837 +static int __devexit falcon_i2c_remove(struct platform_device *pdev)
839 + struct falcon_i2c *priv = platform_get_drvdata(pdev);
840 + struct resource *mmres;
843 + i2c_w32_mask(I2C_RUN_CTRL_RUN_EN, 0, run_ctrl);
845 + /* remove driver */
846 + platform_set_drvdata(pdev, NULL);
847 + i2c_del_adapter(&priv->adap);
849 + free_irq(priv->irq_lb, priv);
850 + free_irq(priv->irq_b, priv);
851 + free_irq(priv->irq_err, priv);
852 + free_irq(priv->irq_p, priv);
854 + iounmap(priv->membase);
861 + mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
862 + release_mem_region(mmres->start, resource_size(mmres));
864 + dev_dbg(&pdev->dev, "removed\n");
869 +static struct platform_driver falcon_i2c_driver = {
870 + .probe = falcon_i2c_probe,
871 + .remove = __devexit_p(falcon_i2c_remove),
874 + .owner = THIS_MODULE,
878 +static int __init falcon_i2c_init(void)
882 + ret = platform_driver_register(&falcon_i2c_driver);
885 + pr_debug(DRV_NAME ": can't register platform driver\n");
890 +static void __exit falcon_i2c_exit(void)
892 + platform_driver_unregister(&falcon_i2c_driver);
895 +module_init(falcon_i2c_init);
896 +module_exit(falcon_i2c_exit);
898 +MODULE_DESCRIPTION("Lantiq FALC(tm) ON - I2C bus adapter");
899 +MODULE_ALIAS("platform:" DRV_NAME);
900 +MODULE_LICENSE("GPL");
901 +MODULE_VERSION(DRV_VERSION);