diff options
author | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
commit | f43dc23d5ea91fca257be02138a255f02d98e806 (patch) | |
tree | b29722f6e965316e90ac97abf79923ced250dc21 /drivers/i2c | |
parent | f8e53553f452dcbf67cb89c8cba63a1cd6eb4cc0 (diff) | |
parent | 4162cf64973df51fc885825bc9ca4d055891c49f (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into common/serial-rework
Conflicts:
arch/sh/kernel/cpu/sh2/setup-sh7619.c
arch/sh/kernel/cpu/sh2a/setup-mxg.c
arch/sh/kernel/cpu/sh2a/setup-sh7201.c
arch/sh/kernel/cpu/sh2a/setup-sh7203.c
arch/sh/kernel/cpu/sh2a/setup-sh7206.c
arch/sh/kernel/cpu/sh3/setup-sh7705.c
arch/sh/kernel/cpu/sh3/setup-sh770x.c
arch/sh/kernel/cpu/sh3/setup-sh7710.c
arch/sh/kernel/cpu/sh3/setup-sh7720.c
arch/sh/kernel/cpu/sh4/setup-sh4-202.c
arch/sh/kernel/cpu/sh4/setup-sh7750.c
arch/sh/kernel/cpu/sh4/setup-sh7760.c
arch/sh/kernel/cpu/sh4a/setup-sh7343.c
arch/sh/kernel/cpu/sh4a/setup-sh7366.c
arch/sh/kernel/cpu/sh4a/setup-sh7722.c
arch/sh/kernel/cpu/sh4a/setup-sh7723.c
arch/sh/kernel/cpu/sh4a/setup-sh7724.c
arch/sh/kernel/cpu/sh4a/setup-sh7763.c
arch/sh/kernel/cpu/sh4a/setup-sh7770.c
arch/sh/kernel/cpu/sh4a/setup-sh7780.c
arch/sh/kernel/cpu/sh4a/setup-sh7785.c
arch/sh/kernel/cpu/sh4a/setup-sh7786.c
arch/sh/kernel/cpu/sh4a/setup-shx3.c
arch/sh/kernel/cpu/sh5/setup-sh5.c
drivers/serial/sh-sci.c
drivers/serial/sh-sci.h
include/linux/serial_sci.h
Diffstat (limited to 'drivers/i2c')
87 files changed, 10042 insertions, 3461 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 711ca08ab776..30f06e956bfb 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig | |||
@@ -5,6 +5,7 @@ | |||
5 | menuconfig I2C | 5 | menuconfig I2C |
6 | tristate "I2C support" | 6 | tristate "I2C support" |
7 | depends on HAS_IOMEM | 7 | depends on HAS_IOMEM |
8 | select RT_MUTEXES | ||
8 | ---help--- | 9 | ---help--- |
9 | I2C (pronounce: I-square-C) is a slow serial bus protocol used in | 10 | I2C (pronounce: I-square-C) is a slow serial bus protocol used in |
10 | many micro controller applications and developed by Philips. SMBus, | 11 | many micro controller applications and developed by Philips. SMBus, |
@@ -27,6 +28,14 @@ config I2C_BOARDINFO | |||
27 | boolean | 28 | boolean |
28 | default y | 29 | default y |
29 | 30 | ||
31 | config I2C_COMPAT | ||
32 | boolean "Enable compatibility bits for old user-space" | ||
33 | default y | ||
34 | help | ||
35 | Say Y here if you intend to run lm-sensors 3.1.1 or older, or any | ||
36 | other user-space package which expects i2c adapters to be class | ||
37 | devices. If you don't know, say Y. | ||
38 | |||
30 | config I2C_CHARDEV | 39 | config I2C_CHARDEV |
31 | tristate "I2C device interface" | 40 | tristate "I2C device interface" |
32 | help | 41 | help |
@@ -38,6 +47,19 @@ config I2C_CHARDEV | |||
38 | This support is also available as a module. If so, the module | 47 | This support is also available as a module. If so, the module |
39 | will be called i2c-dev. | 48 | will be called i2c-dev. |
40 | 49 | ||
50 | config I2C_MUX | ||
51 | tristate "I2C bus multiplexing support" | ||
52 | depends on EXPERIMENTAL | ||
53 | help | ||
54 | Say Y here if you want the I2C core to support the ability to | ||
55 | handle multiplexed I2C bus topologies, by presenting each | ||
56 | multiplexed segment as a I2C adapter. | ||
57 | |||
58 | This support is also available as a module. If so, the module | ||
59 | will be called i2c-mux. | ||
60 | |||
61 | source drivers/i2c/muxes/Kconfig | ||
62 | |||
41 | config I2C_HELPER_AUTO | 63 | config I2C_HELPER_AUTO |
42 | bool "Autoselect pertinent helper modules" | 64 | bool "Autoselect pertinent helper modules" |
43 | default y | 65 | default y |
@@ -52,9 +74,18 @@ config I2C_HELPER_AUTO | |||
52 | 74 | ||
53 | In doubt, say Y. | 75 | In doubt, say Y. |
54 | 76 | ||
77 | config I2C_SMBUS | ||
78 | tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO | ||
79 | help | ||
80 | Say Y here if you want support for SMBus extensions to the I2C | ||
81 | specification. At the moment, the only supported extension is | ||
82 | the SMBus alert protocol. | ||
83 | |||
84 | This support is also available as a module. If so, the module | ||
85 | will be called i2c-smbus. | ||
86 | |||
55 | source drivers/i2c/algos/Kconfig | 87 | source drivers/i2c/algos/Kconfig |
56 | source drivers/i2c/busses/Kconfig | 88 | source drivers/i2c/busses/Kconfig |
57 | source drivers/i2c/chips/Kconfig | ||
58 | 89 | ||
59 | config I2C_DEBUG_CORE | 90 | config I2C_DEBUG_CORE |
60 | bool "I2C Core debugging messages" | 91 | bool "I2C Core debugging messages" |
@@ -79,12 +110,4 @@ config I2C_DEBUG_BUS | |||
79 | a problem with I2C support and want to see more of what is going | 110 | a problem with I2C support and want to see more of what is going |
80 | on. | 111 | on. |
81 | 112 | ||
82 | config I2C_DEBUG_CHIP | ||
83 | bool "I2C Chip debugging messages" | ||
84 | help | ||
85 | Say Y here if you want the I2C chip drivers to produce a bunch of | ||
86 | debug messages to the system log. Select this if you are having | ||
87 | a problem with I2C support and want to see more of what is going | ||
88 | on. | ||
89 | |||
90 | endif # I2C | 113 | endif # I2C |
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index ba26e6cbe74e..23ac61e2db39 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile | |||
@@ -4,9 +4,9 @@ | |||
4 | 4 | ||
5 | obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o | 5 | obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o |
6 | obj-$(CONFIG_I2C) += i2c-core.o | 6 | obj-$(CONFIG_I2C) += i2c-core.o |
7 | obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o | ||
7 | obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o | 8 | obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o |
8 | obj-y += busses/ chips/ algos/ | 9 | obj-$(CONFIG_I2C_MUX) += i2c-mux.o |
10 | obj-y += algos/ busses/ muxes/ | ||
9 | 11 | ||
10 | ifeq ($(CONFIG_I2C_DEBUG_CORE),y) | 12 | ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG |
11 | EXTRA_CFLAGS += -DDEBUG | ||
12 | endif | ||
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig index 7b2ce4a08524..f1cfe7e5508b 100644 --- a/drivers/i2c/algos/Kconfig +++ b/drivers/i2c/algos/Kconfig | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | menu "I2C Algorithms" | 5 | menu "I2C Algorithms" |
6 | depends on !I2C_HELPER_AUTO | 6 | visible if !I2C_HELPER_AUTO |
7 | 7 | ||
8 | config I2C_ALGOBIT | 8 | config I2C_ALGOBIT |
9 | tristate "I2C bit-banging interfaces" | 9 | tristate "I2C bit-banging interfaces" |
diff --git a/drivers/i2c/algos/Makefile b/drivers/i2c/algos/Makefile index 18b3e962ec09..215303f60d61 100644 --- a/drivers/i2c/algos/Makefile +++ b/drivers/i2c/algos/Makefile | |||
@@ -6,6 +6,4 @@ obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o | |||
6 | obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o | 6 | obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o |
7 | obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o | 7 | obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o |
8 | 8 | ||
9 | ifeq ($(CONFIG_I2C_DEBUG_ALGO),y) | 9 | ccflags-$(CONFIG_I2C_DEBUG_ALGO) := -DDEBUG |
10 | EXTRA_CFLAGS += -DDEBUG | ||
11 | endif | ||
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index e25e13980af3..38319a69bd0a 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/slab.h> | ||
28 | #include <linux/init.h> | 27 | #include <linux/init.h> |
29 | #include <linux/errno.h> | 28 | #include <linux/errno.h> |
30 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
@@ -522,6 +521,12 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
522 | int i, ret; | 521 | int i, ret; |
523 | unsigned short nak_ok; | 522 | unsigned short nak_ok; |
524 | 523 | ||
524 | if (adap->pre_xfer) { | ||
525 | ret = adap->pre_xfer(i2c_adap); | ||
526 | if (ret < 0) | ||
527 | return ret; | ||
528 | } | ||
529 | |||
525 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | 530 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); |
526 | i2c_start(adap); | 531 | i2c_start(adap); |
527 | for (i = 0; i < num; i++) { | 532 | for (i = 0; i < num; i++) { |
@@ -570,6 +575,9 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
570 | bailout: | 575 | bailout: |
571 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); | 576 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); |
572 | i2c_stop(adap); | 577 | i2c_stop(adap); |
578 | |||
579 | if (adap->post_xfer) | ||
580 | adap->post_xfer(i2c_adap); | ||
573 | return ret; | 581 | return ret; |
574 | } | 582 | } |
575 | 583 | ||
@@ -592,12 +600,14 @@ static const struct i2c_algorithm i2c_bit_algo = { | |||
592 | /* | 600 | /* |
593 | * registering functions to load algorithms at runtime | 601 | * registering functions to load algorithms at runtime |
594 | */ | 602 | */ |
595 | static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | 603 | static int __i2c_bit_add_bus(struct i2c_adapter *adap, |
604 | int (*add_adapter)(struct i2c_adapter *)) | ||
596 | { | 605 | { |
597 | struct i2c_algo_bit_data *bit_adap = adap->algo_data; | 606 | struct i2c_algo_bit_data *bit_adap = adap->algo_data; |
607 | int ret; | ||
598 | 608 | ||
599 | if (bit_test) { | 609 | if (bit_test) { |
600 | int ret = test_bus(bit_adap, adap->name); | 610 | ret = test_bus(bit_adap, adap->name); |
601 | if (ret < 0) | 611 | if (ret < 0) |
602 | return -ENODEV; | 612 | return -ENODEV; |
603 | } | 613 | } |
@@ -606,30 +616,27 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | |||
606 | adap->algo = &i2c_bit_algo; | 616 | adap->algo = &i2c_bit_algo; |
607 | adap->retries = 3; | 617 | adap->retries = 3; |
608 | 618 | ||
619 | ret = add_adapter(adap); | ||
620 | if (ret < 0) | ||
621 | return ret; | ||
622 | |||
623 | /* Complain if SCL can't be read */ | ||
624 | if (bit_adap->getscl == NULL) { | ||
625 | dev_warn(&adap->dev, "Not I2C compliant: can't read SCL\n"); | ||
626 | dev_warn(&adap->dev, "Bus may be unreliable\n"); | ||
627 | } | ||
609 | return 0; | 628 | return 0; |
610 | } | 629 | } |
611 | 630 | ||
612 | int i2c_bit_add_bus(struct i2c_adapter *adap) | 631 | int i2c_bit_add_bus(struct i2c_adapter *adap) |
613 | { | 632 | { |
614 | int err; | 633 | return __i2c_bit_add_bus(adap, i2c_add_adapter); |
615 | |||
616 | err = i2c_bit_prepare_bus(adap); | ||
617 | if (err) | ||
618 | return err; | ||
619 | |||
620 | return i2c_add_adapter(adap); | ||
621 | } | 634 | } |
622 | EXPORT_SYMBOL(i2c_bit_add_bus); | 635 | EXPORT_SYMBOL(i2c_bit_add_bus); |
623 | 636 | ||
624 | int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) | 637 | int i2c_bit_add_numbered_bus(struct i2c_adapter *adap) |
625 | { | 638 | { |
626 | int err; | 639 | return __i2c_bit_add_bus(adap, i2c_add_numbered_adapter); |
627 | |||
628 | err = i2c_bit_prepare_bus(adap); | ||
629 | if (err) | ||
630 | return err; | ||
631 | |||
632 | return i2c_add_numbered_adapter(adap); | ||
633 | } | 640 | } |
634 | EXPORT_SYMBOL(i2c_bit_add_numbered_bus); | 641 | EXPORT_SYMBOL(i2c_bit_add_numbered_bus); |
635 | 642 | ||
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c index 78d42aae0089..2b9a8f54bb2c 100644 --- a/drivers/i2c/algos/i2c-algo-pca.c +++ b/drivers/i2c/algos/i2c-algo-pca.c | |||
@@ -109,13 +109,13 @@ static void pca_stop(struct i2c_algo_pca_data *adap) | |||
109 | * returns after the address has been sent | 109 | * returns after the address has been sent |
110 | */ | 110 | */ |
111 | static int pca_address(struct i2c_algo_pca_data *adap, | 111 | static int pca_address(struct i2c_algo_pca_data *adap, |
112 | struct i2c_msg *msg) | 112 | struct i2c_msg *msg) |
113 | { | 113 | { |
114 | int sta = pca_get_con(adap); | 114 | int sta = pca_get_con(adap); |
115 | int addr; | 115 | int addr; |
116 | 116 | ||
117 | addr = ( (0x7f & msg->addr) << 1 ); | 117 | addr = ((0x7f & msg->addr) << 1); |
118 | if (msg->flags & I2C_M_RD ) | 118 | if (msg->flags & I2C_M_RD) |
119 | addr |= 1; | 119 | addr |= 1; |
120 | DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", | 120 | DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", |
121 | msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); | 121 | msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); |
@@ -134,7 +134,7 @@ static int pca_address(struct i2c_algo_pca_data *adap, | |||
134 | * Returns after the byte has been transmitted | 134 | * Returns after the byte has been transmitted |
135 | */ | 135 | */ |
136 | static int pca_tx_byte(struct i2c_algo_pca_data *adap, | 136 | static int pca_tx_byte(struct i2c_algo_pca_data *adap, |
137 | __u8 b) | 137 | __u8 b) |
138 | { | 138 | { |
139 | int sta = pca_get_con(adap); | 139 | int sta = pca_get_con(adap); |
140 | DEB2("=== WRITE %#04x\n", b); | 140 | DEB2("=== WRITE %#04x\n", b); |
@@ -164,13 +164,13 @@ static void pca_rx_byte(struct i2c_algo_pca_data *adap, | |||
164 | * Returns after next byte has arrived. | 164 | * Returns after next byte has arrived. |
165 | */ | 165 | */ |
166 | static int pca_rx_ack(struct i2c_algo_pca_data *adap, | 166 | static int pca_rx_ack(struct i2c_algo_pca_data *adap, |
167 | int ack) | 167 | int ack) |
168 | { | 168 | { |
169 | int sta = pca_get_con(adap); | 169 | int sta = pca_get_con(adap); |
170 | 170 | ||
171 | sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI|I2C_PCA_CON_AA); | 171 | sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI|I2C_PCA_CON_AA); |
172 | 172 | ||
173 | if ( ack ) | 173 | if (ack) |
174 | sta |= I2C_PCA_CON_AA; | 174 | sta |= I2C_PCA_CON_AA; |
175 | 175 | ||
176 | pca_set_con(adap, sta); | 176 | pca_set_con(adap, sta); |
@@ -178,12 +178,12 @@ static int pca_rx_ack(struct i2c_algo_pca_data *adap, | |||
178 | } | 178 | } |
179 | 179 | ||
180 | static int pca_xfer(struct i2c_adapter *i2c_adap, | 180 | static int pca_xfer(struct i2c_adapter *i2c_adap, |
181 | struct i2c_msg *msgs, | 181 | struct i2c_msg *msgs, |
182 | int num) | 182 | int num) |
183 | { | 183 | { |
184 | struct i2c_algo_pca_data *adap = i2c_adap->algo_data; | 184 | struct i2c_algo_pca_data *adap = i2c_adap->algo_data; |
185 | struct i2c_msg *msg = NULL; | 185 | struct i2c_msg *msg = NULL; |
186 | int curmsg; | 186 | int curmsg; |
187 | int numbytes = 0; | 187 | int numbytes = 0; |
188 | int state; | 188 | int state; |
189 | int ret; | 189 | int ret; |
@@ -202,21 +202,21 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, | |||
202 | 202 | ||
203 | DEB1("{{{ XFER %d messages\n", num); | 203 | DEB1("{{{ XFER %d messages\n", num); |
204 | 204 | ||
205 | if (i2c_debug>=2) { | 205 | if (i2c_debug >= 2) { |
206 | for (curmsg = 0; curmsg < num; curmsg++) { | 206 | for (curmsg = 0; curmsg < num; curmsg++) { |
207 | int addr, i; | 207 | int addr, i; |
208 | msg = &msgs[curmsg]; | 208 | msg = &msgs[curmsg]; |
209 | 209 | ||
210 | addr = (0x7f & msg->addr) ; | 210 | addr = (0x7f & msg->addr) ; |
211 | 211 | ||
212 | if (msg->flags & I2C_M_RD ) | 212 | if (msg->flags & I2C_M_RD) |
213 | printk(KERN_INFO " [%02d] RD %d bytes from %#02x [%#02x, ...]\n", | 213 | printk(KERN_INFO " [%02d] RD %d bytes from %#02x [%#02x, ...]\n", |
214 | curmsg, msg->len, addr, (addr<<1) | 1); | 214 | curmsg, msg->len, addr, (addr << 1) | 1); |
215 | else { | 215 | else { |
216 | printk(KERN_INFO " [%02d] WR %d bytes to %#02x [%#02x%s", | 216 | printk(KERN_INFO " [%02d] WR %d bytes to %#02x [%#02x%s", |
217 | curmsg, msg->len, addr, addr<<1, | 217 | curmsg, msg->len, addr, addr << 1, |
218 | msg->len == 0 ? "" : ", "); | 218 | msg->len == 0 ? "" : ", "); |
219 | for(i=0; i < msg->len; i++) | 219 | for (i = 0; i < msg->len; i++) |
220 | printk("%#04x%s", msg->buf[i], i == msg->len - 1 ? "" : ", "); | 220 | printk("%#04x%s", msg->buf[i], i == msg->len - 1 ? "" : ", "); |
221 | printk("]\n"); | 221 | printk("]\n"); |
222 | } | 222 | } |
@@ -305,7 +305,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, | |||
305 | goto out; | 305 | goto out; |
306 | 306 | ||
307 | case 0x58: /* Data byte has been received; NOT ACK has been returned */ | 307 | case 0x58: /* Data byte has been received; NOT ACK has been returned */ |
308 | if ( numbytes == msg->len - 1 ) { | 308 | if (numbytes == msg->len - 1) { |
309 | pca_rx_byte(adap, &msg->buf[numbytes], 0); | 309 | pca_rx_byte(adap, &msg->buf[numbytes], 0); |
310 | curmsg++; numbytes = 0; | 310 | curmsg++; numbytes = 0; |
311 | if (curmsg == num) | 311 | if (curmsg == num) |
@@ -352,7 +352,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, | |||
352 | 352 | ||
353 | static u32 pca_func(struct i2c_adapter *adap) | 353 | static u32 pca_func(struct i2c_adapter *adap) |
354 | { | 354 | { |
355 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | 355 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
356 | } | 356 | } |
357 | 357 | ||
358 | static const struct i2c_algorithm pca_algo = { | 358 | static const struct i2c_algorithm pca_algo = { |
@@ -453,8 +453,6 @@ static int pca_init(struct i2c_adapter *adap) | |||
453 | */ | 453 | */ |
454 | int raise_fall_time; | 454 | int raise_fall_time; |
455 | 455 | ||
456 | struct i2c_algo_pca_data *pca_data = adap->algo_data; | ||
457 | |||
458 | /* Ignore the reset function from the module, | 456 | /* Ignore the reset function from the module, |
459 | * we can use the parallel bus reset | 457 | * we can use the parallel bus reset |
460 | */ | 458 | */ |
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c index 7ce75775ec73..5eebf562ff31 100644 --- a/drivers/i2c/algos/i2c-algo-pcf.c +++ b/drivers/i2c/algos/i2c-algo-pcf.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/slab.h> | ||
33 | #include <linux/init.h> | 32 | #include <linux/init.h> |
34 | #include <linux/errno.h> | 33 | #include <linux/errno.h> |
35 | #include <linux/i2c.h> | 34 | #include <linux/i2c.h> |
@@ -176,7 +175,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap) | |||
176 | */ | 175 | */ |
177 | if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) { | 176 | if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) { |
178 | DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp)); | 177 | DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp)); |
179 | return -ENXIO; /* definetly not PCF8584 */ | 178 | return -ENXIO; /* definitely not PCF8584 */ |
180 | } | 179 | } |
181 | 180 | ||
182 | /* load own address in S0, effective address is (own << 1) */ | 181 | /* load own address in S0, effective address is (own << 1) */ |
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 3c259ee7ddda..3a6321cb8030 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -77,7 +77,7 @@ config I2C_AMD8111 | |||
77 | will be called i2c-amd8111. | 77 | will be called i2c-amd8111. |
78 | 78 | ||
79 | config I2C_I801 | 79 | config I2C_I801 |
80 | tristate "Intel 82801 (ICH)" | 80 | tristate "Intel 82801 (ICH/PCH)" |
81 | depends on PCI | 81 | depends on PCI |
82 | help | 82 | help |
83 | If you say yes to this option, support will be included for the Intel | 83 | If you say yes to this option, support will be included for the Intel |
@@ -95,9 +95,11 @@ config I2C_I801 | |||
95 | ESB2 | 95 | ESB2 |
96 | ICH8 | 96 | ICH8 |
97 | ICH9 | 97 | ICH9 |
98 | Tolapai | 98 | EP80579 (Tolapai) |
99 | ICH10 | 99 | ICH10 |
100 | PCH | 100 | 5/3400 Series (PCH) |
101 | Cougar Point (PCH) | ||
102 | Patsburg (PCH) | ||
101 | 103 | ||
102 | This driver can also be built as a module. If so, the module | 104 | This driver can also be built as a module. If so, the module |
103 | will be called i2c-i801. | 105 | will be called i2c-i801. |
@@ -105,6 +107,8 @@ config I2C_I801 | |||
105 | config I2C_ISCH | 107 | config I2C_ISCH |
106 | tristate "Intel SCH SMBus 1.0" | 108 | tristate "Intel SCH SMBus 1.0" |
107 | depends on PCI | 109 | depends on PCI |
110 | select MFD_CORE | ||
111 | select LPC_SCH | ||
108 | help | 112 | help |
109 | Say Y here if you want to use SMBus controller on the Intel SCH | 113 | Say Y here if you want to use SMBus controller on the Intel SCH |
110 | based systems. | 114 | based systems. |
@@ -113,7 +117,7 @@ config I2C_ISCH | |||
113 | will be called i2c-isch. | 117 | will be called i2c-isch. |
114 | 118 | ||
115 | config I2C_PIIX4 | 119 | config I2C_PIIX4 |
116 | tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" | 120 | tristate "Intel PIIX4 and compatible (ATI/AMD/Serverworks/Broadcom/SMSC)" |
117 | depends on PCI | 121 | depends on PCI |
118 | help | 122 | help |
119 | If you say yes to this option, support will be included for the Intel | 123 | If you say yes to this option, support will be included for the Intel |
@@ -128,6 +132,7 @@ config I2C_PIIX4 | |||
128 | ATI SB600 | 132 | ATI SB600 |
129 | ATI SB700 | 133 | ATI SB700 |
130 | ATI SB800 | 134 | ATI SB800 |
135 | AMD Hudson-2 | ||
131 | Serverworks OSB4 | 136 | Serverworks OSB4 |
132 | Serverworks CSB5 | 137 | Serverworks CSB5 |
133 | Serverworks CSB6 | 138 | Serverworks CSB6 |
@@ -231,6 +236,22 @@ config I2C_VIAPRO | |||
231 | This driver can also be built as a module. If so, the module | 236 | This driver can also be built as a module. If so, the module |
232 | will be called i2c-viapro. | 237 | will be called i2c-viapro. |
233 | 238 | ||
239 | if ACPI | ||
240 | |||
241 | comment "ACPI drivers" | ||
242 | |||
243 | config I2C_SCMI | ||
244 | tristate "SMBus Control Method Interface" | ||
245 | help | ||
246 | This driver supports the SMBus Control Method Interface. It needs the | ||
247 | BIOS to declare ACPI control methods as described in the SMBus Control | ||
248 | Method Interface specification. | ||
249 | |||
250 | To compile this driver as a module, choose M here: | ||
251 | the module will be called i2c-scmi. | ||
252 | |||
253 | endif # ACPI | ||
254 | |||
234 | comment "Mac SMBus host controller drivers" | 255 | comment "Mac SMBus host controller drivers" |
235 | depends on PPC_CHRP || PPC_PMAC | 256 | depends on PPC_CHRP || PPC_PMAC |
236 | 257 | ||
@@ -326,6 +347,16 @@ config I2C_DAVINCI | |||
326 | devices such as DaVinci NIC. | 347 | devices such as DaVinci NIC. |
327 | For details please see http://www.ti.com/davinci | 348 | For details please see http://www.ti.com/davinci |
328 | 349 | ||
350 | config I2C_DESIGNWARE | ||
351 | tristate "Synopsys DesignWare" | ||
352 | depends on HAVE_CLK | ||
353 | help | ||
354 | If you say yes to this option, support will be included for the | ||
355 | Synopsys DesignWare I2C adapter. Only master mode is supported. | ||
356 | |||
357 | This driver can also be built as a module. If so, the module | ||
358 | will be called i2c-designware. | ||
359 | |||
329 | config I2C_GPIO | 360 | config I2C_GPIO |
330 | tristate "GPIO-based bitbanging I2C" | 361 | tristate "GPIO-based bitbanging I2C" |
331 | depends on GENERIC_GPIO | 362 | depends on GENERIC_GPIO |
@@ -366,6 +397,16 @@ config I2C_IMX | |||
366 | This driver can also be built as a module. If so, the module | 397 | This driver can also be built as a module. If so, the module |
367 | will be called i2c-imx. | 398 | will be called i2c-imx. |
368 | 399 | ||
400 | config I2C_INTEL_MID | ||
401 | tristate "Intel Moorestown/Medfield Platform I2C controller" | ||
402 | depends on PCI | ||
403 | help | ||
404 | Say Y here if you have an Intel Moorestown/Medfield platform I2C | ||
405 | controller. | ||
406 | |||
407 | This support is also available as a module. If so, the module | ||
408 | will be called i2c-intel-mid. | ||
409 | |||
369 | config I2C_IOP3XX | 410 | config I2C_IOP3XX |
370 | tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" | 411 | tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" |
371 | depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX | 412 | depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX |
@@ -391,13 +432,12 @@ config I2C_IXP2000 | |||
391 | instead. | 432 | instead. |
392 | 433 | ||
393 | config I2C_MPC | 434 | config I2C_MPC |
394 | tristate "MPC107/824x/85xx/52xx/86xx" | 435 | tristate "MPC107/824x/85xx/512x/52xx/83xx/86xx" |
395 | depends on PPC32 | 436 | depends on PPC32 |
396 | help | 437 | help |
397 | If you say yes to this option, support will be included for the | 438 | If you say yes to this option, support will be included for the |
398 | built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and | 439 | built-in I2C interface on the MPC107, Tsi107, MPC512x, MPC52xx, |
399 | MPC85xx/MPC8641 family processors. The driver may also work on 52xx | 440 | MPC8240, MPC8245, MPC83xx, MPC85xx and MPC8641 family processors. |
400 | family processors, though interrupts are known not to work. | ||
401 | 441 | ||
402 | This driver can also be built as a module. If so, the module | 442 | This driver can also be built as a module. If so, the module |
403 | will be called i2c-mpc. | 443 | will be called i2c-mpc. |
@@ -412,6 +452,20 @@ config I2C_MV64XXX | |||
412 | This driver can also be built as a module. If so, the module | 452 | This driver can also be built as a module. If so, the module |
413 | will be called i2c-mv64xxx. | 453 | will be called i2c-mv64xxx. |
414 | 454 | ||
455 | config I2C_NOMADIK | ||
456 | tristate "ST-Ericsson Nomadik/Ux500 I2C Controller" | ||
457 | depends on PLAT_NOMADIK | ||
458 | help | ||
459 | If you say yes to this option, support will be included for the | ||
460 | I2C interface from ST-Ericsson's Nomadik and Ux500 architectures. | ||
461 | |||
462 | config I2C_NUC900 | ||
463 | tristate "NUC900 I2C Driver" | ||
464 | depends on ARCH_W90X900 | ||
465 | help | ||
466 | Say Y here to include support for I2C controller in the | ||
467 | Winbond/Nuvoton NUC900 based System-on-Chip devices. | ||
468 | |||
415 | config I2C_OCORES | 469 | config I2C_OCORES |
416 | tristate "OpenCores I2C Controller" | 470 | tristate "OpenCores I2C Controller" |
417 | depends on EXPERIMENTAL | 471 | depends on EXPERIMENTAL |
@@ -439,9 +493,29 @@ config I2C_PASEMI | |||
439 | help | 493 | help |
440 | Supports the PA Semi PWRficient on-chip SMBus interfaces. | 494 | Supports the PA Semi PWRficient on-chip SMBus interfaces. |
441 | 495 | ||
496 | config I2C_PCA_PLATFORM | ||
497 | tristate "PCA9564/PCA9665 as platform device" | ||
498 | select I2C_ALGOPCA | ||
499 | default n | ||
500 | help | ||
501 | This driver supports a memory mapped Philips PCA9564/PCA9665 | ||
502 | parallel bus to I2C bus controller. | ||
503 | |||
504 | This driver can also be built as a module. If so, the module | ||
505 | will be called i2c-pca-platform. | ||
506 | |||
507 | config I2C_PMCMSP | ||
508 | tristate "PMC MSP I2C TWI Controller" | ||
509 | depends on PMC_MSP | ||
510 | help | ||
511 | This driver supports the PMC TWI controller on MSP devices. | ||
512 | |||
513 | This driver can also be built as module. If so, the module | ||
514 | will be called i2c-pmcmsp. | ||
515 | |||
442 | config I2C_PNX | 516 | config I2C_PNX |
443 | tristate "I2C bus support for Philips PNX targets" | 517 | tristate "I2C bus support for Philips PNX and NXP LPC targets" |
444 | depends on ARCH_PNX4008 | 518 | depends on ARCH_PNX4008 || ARCH_LPC32XX |
445 | help | 519 | help |
446 | This driver supports the Philips IP3204 I2C IP block master and/or | 520 | This driver supports the Philips IP3204 I2C IP block master and/or |
447 | slave controller | 521 | slave controller |
@@ -450,8 +524,8 @@ config I2C_PNX | |||
450 | will be called i2c-pnx. | 524 | will be called i2c-pnx. |
451 | 525 | ||
452 | config I2C_PXA | 526 | config I2C_PXA |
453 | tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" | 527 | tristate "Intel PXA2XX I2C adapter" |
454 | depends on EXPERIMENTAL && ARCH_PXA | 528 | depends on ARCH_PXA || ARCH_MMP |
455 | help | 529 | help |
456 | If you have devices in the PXA I2C bus, say yes to this option. | 530 | If you have devices in the PXA I2C bus, say yes to this option. |
457 | This driver can also be built as a module. If so, the module | 531 | This driver can also be built as a module. If so, the module |
@@ -465,12 +539,19 @@ config I2C_PXA_SLAVE | |||
465 | is necessary for systems where the PXA may be a target on the | 539 | is necessary for systems where the PXA may be a target on the |
466 | I2C bus. | 540 | I2C bus. |
467 | 541 | ||
542 | config HAVE_S3C2410_I2C | ||
543 | bool | ||
544 | help | ||
545 | This will include I2C support for Samsung SoCs. If you want to | ||
546 | include I2C support for any machine, kindly select this in the | ||
547 | respective Kconfig file. | ||
548 | |||
468 | config I2C_S3C2410 | 549 | config I2C_S3C2410 |
469 | tristate "S3C2410 I2C Driver" | 550 | tristate "S3C2410 I2C Driver" |
470 | depends on ARCH_S3C2410 || ARCH_S3C64XX | 551 | depends on HAVE_S3C2410_I2C |
471 | help | 552 | help |
472 | Say Y here to include support for I2C controller in the | 553 | Say Y here to include support for I2C controller in the |
473 | Samsung S3C2410 based System-on-Chip devices. | 554 | Samsung SoCs. |
474 | 555 | ||
475 | config I2C_S6000 | 556 | config I2C_S6000 |
476 | tristate "S6000 I2C support" | 557 | tristate "S6000 I2C support" |
@@ -493,7 +574,7 @@ config I2C_SH7760 | |||
493 | 574 | ||
494 | config I2C_SH_MOBILE | 575 | config I2C_SH_MOBILE |
495 | tristate "SuperH Mobile I2C Controller" | 576 | tristate "SuperH Mobile I2C Controller" |
496 | depends on SUPERH | 577 | depends on SUPERH || ARCH_SHMOBILE |
497 | help | 578 | help |
498 | If you say yes to this option, support will be included for the | 579 | If you say yes to this option, support will be included for the |
499 | built-in I2C interface on the Renesas SH-Mobile processor. | 580 | built-in I2C interface on the Renesas SH-Mobile processor. |
@@ -528,7 +609,7 @@ config I2C_STU300 | |||
528 | 609 | ||
529 | config I2C_VERSATILE | 610 | config I2C_VERSATILE |
530 | tristate "ARM Versatile/Realview I2C bus support" | 611 | tristate "ARM Versatile/Realview I2C bus support" |
531 | depends on ARCH_VERSATILE || ARCH_REALVIEW | 612 | depends on ARCH_VERSATILE || ARCH_REALVIEW || ARCH_VEXPRESS |
532 | select I2C_ALGOBIT | 613 | select I2C_ALGOBIT |
533 | help | 614 | help |
534 | Say yes if you want to support the I2C serial bus on ARMs Versatile | 615 | Say yes if you want to support the I2C serial bus on ARMs Versatile |
@@ -537,12 +618,33 @@ config I2C_VERSATILE | |||
537 | This driver can also be built as a module. If so, the module | 618 | This driver can also be built as a module. If so, the module |
538 | will be called i2c-versatile. | 619 | will be called i2c-versatile. |
539 | 620 | ||
621 | config I2C_OCTEON | ||
622 | tristate "Cavium OCTEON I2C bus support" | ||
623 | depends on CPU_CAVIUM_OCTEON | ||
624 | help | ||
625 | Say yes if you want to support the I2C serial bus on Cavium | ||
626 | OCTEON SOC. | ||
627 | |||
628 | This driver can also be built as a module. If so, the module | ||
629 | will be called i2c-octeon. | ||
630 | |||
631 | config I2C_XILINX | ||
632 | tristate "Xilinx I2C Controller" | ||
633 | depends on EXPERIMENTAL && HAS_IOMEM | ||
634 | help | ||
635 | If you say yes to this option, support will be included for the | ||
636 | Xilinx I2C controller. | ||
637 | |||
638 | This driver can also be built as a module. If so, the module | ||
639 | will be called xilinx_i2c. | ||
640 | |||
540 | comment "External I2C/SMBus adapter drivers" | 641 | comment "External I2C/SMBus adapter drivers" |
541 | 642 | ||
542 | config I2C_PARPORT | 643 | config I2C_PARPORT |
543 | tristate "Parallel port adapter" | 644 | tristate "Parallel port adapter" |
544 | depends on PARPORT | 645 | depends on PARPORT |
545 | select I2C_ALGOBIT | 646 | select I2C_ALGOBIT |
647 | select I2C_SMBUS | ||
546 | help | 648 | help |
547 | This supports parallel port I2C adapters such as the ones made by | 649 | This supports parallel port I2C adapters such as the ones made by |
548 | Philips or Velleman, Analog Devices evaluation boards, and more. | 650 | Philips or Velleman, Analog Devices evaluation boards, and more. |
@@ -566,6 +668,7 @@ config I2C_PARPORT | |||
566 | config I2C_PARPORT_LIGHT | 668 | config I2C_PARPORT_LIGHT |
567 | tristate "Parallel port adapter (light)" | 669 | tristate "Parallel port adapter (light)" |
568 | select I2C_ALGOBIT | 670 | select I2C_ALGOBIT |
671 | select I2C_SMBUS | ||
569 | help | 672 | help |
570 | This supports parallel port I2C adapters such as the ones made by | 673 | This supports parallel port I2C adapters such as the ones made by |
571 | Philips or Velleman, Analog Devices evaluation boards, and more. | 674 | Philips or Velleman, Analog Devices evaluation boards, and more. |
@@ -613,22 +716,6 @@ config I2C_TINY_USB | |||
613 | This driver can also be built as a module. If so, the module | 716 | This driver can also be built as a module. If so, the module |
614 | will be called i2c-tiny-usb. | 717 | will be called i2c-tiny-usb. |
615 | 718 | ||
616 | comment "Graphics adapter I2C/DDC channel drivers" | ||
617 | depends on PCI | ||
618 | |||
619 | config I2C_VOODOO3 | ||
620 | tristate "Voodoo 3 (DEPRECATED)" | ||
621 | depends on PCI | ||
622 | select I2C_ALGOBIT | ||
623 | help | ||
624 | If you say yes to this option, support will be included for the | ||
625 | Voodoo 3 I2C interface. This driver is deprecated and you should | ||
626 | use the tdfxfb driver instead, which additionally provides | ||
627 | framebuffer support. | ||
628 | |||
629 | This driver can also be built as a module. If so, the module | ||
630 | will be called i2c-voodoo3. | ||
631 | |||
632 | comment "Other I2C/SMBus bus drivers" | 719 | comment "Other I2C/SMBus bus drivers" |
633 | 720 | ||
634 | config I2C_ACORN | 721 | config I2C_ACORN |
@@ -669,26 +756,6 @@ config I2C_PCA_ISA | |||
669 | delays when I2C/SMBus chip drivers are loaded (e.g. at boot | 756 | delays when I2C/SMBus chip drivers are loaded (e.g. at boot |
670 | time). If unsure, say N. | 757 | time). If unsure, say N. |
671 | 758 | ||
672 | config I2C_PCA_PLATFORM | ||
673 | tristate "PCA9564/PCA9665 as platform device" | ||
674 | select I2C_ALGOPCA | ||
675 | default n | ||
676 | help | ||
677 | This driver supports a memory mapped Philips PCA9564/PCA9665 | ||
678 | parallel bus to I2C bus controller. | ||
679 | |||
680 | This driver can also be built as a module. If so, the module | ||
681 | will be called i2c-pca-platform. | ||
682 | |||
683 | config I2C_PMCMSP | ||
684 | tristate "PMC MSP I2C TWI Controller" | ||
685 | depends on PMC_MSP | ||
686 | help | ||
687 | This driver supports the PMC TWI controller on MSP devices. | ||
688 | |||
689 | This driver can also be built as module. If so, the module | ||
690 | will be called i2c-pmcmsp. | ||
691 | |||
692 | config I2C_SIBYTE | 759 | config I2C_SIBYTE |
693 | tristate "SiByte SMBus interface" | 760 | tristate "SiByte SMBus interface" |
694 | depends on SIBYTE_SB1xxx_SOC | 761 | depends on SIBYTE_SB1xxx_SOC |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index edeabf003106..84cb16ae6f9e 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -2,6 +2,9 @@ | |||
2 | # Makefile for the i2c bus drivers. | 2 | # Makefile for the i2c bus drivers. |
3 | # | 3 | # |
4 | 4 | ||
5 | # ACPI drivers | ||
6 | obj-$(CONFIG_I2C_SCMI) += i2c-scmi.o | ||
7 | |||
5 | # PC SMBus host controller drivers | 8 | # PC SMBus host controller drivers |
6 | obj-$(CONFIG_I2C_ALI1535) += i2c-ali1535.o | 9 | obj-$(CONFIG_I2C_ALI1535) += i2c-ali1535.o |
7 | obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o | 10 | obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o |
@@ -24,23 +27,29 @@ obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o | |||
24 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o | 27 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o |
25 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o | 28 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o |
26 | 29 | ||
27 | # Embebbed system I2C/SMBus host controller drivers | 30 | # Embedded system I2C/SMBus host controller drivers |
28 | obj-$(CONFIG_I2C_AT91) += i2c-at91.o | 31 | obj-$(CONFIG_I2C_AT91) += i2c-at91.o |
29 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o | 32 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o |
30 | obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o | 33 | obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o |
31 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o | 34 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o |
32 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o | 35 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o |
36 | obj-$(CONFIG_I2C_DESIGNWARE) += i2c-designware.o | ||
33 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o | 37 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o |
34 | obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o | 38 | obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o |
35 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o | 39 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o |
36 | obj-$(CONFIG_I2C_IMX) += i2c-imx.o | 40 | obj-$(CONFIG_I2C_IMX) += i2c-imx.o |
41 | obj-$(CONFIG_I2C_INTEL_MID) += i2c-intel-mid.o | ||
37 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o | 42 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o |
38 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o | 43 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o |
39 | obj-$(CONFIG_I2C_MPC) += i2c-mpc.o | 44 | obj-$(CONFIG_I2C_MPC) += i2c-mpc.o |
40 | obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o | 45 | obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o |
46 | obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o | ||
47 | obj-$(CONFIG_I2C_NUC900) += i2c-nuc900.o | ||
41 | obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o | 48 | obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o |
42 | obj-$(CONFIG_I2C_OMAP) += i2c-omap.o | 49 | obj-$(CONFIG_I2C_OMAP) += i2c-omap.o |
43 | obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o | 50 | obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o |
51 | obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o | ||
52 | obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o | ||
44 | obj-$(CONFIG_I2C_PNX) += i2c-pnx.o | 53 | obj-$(CONFIG_I2C_PNX) += i2c-pnx.o |
45 | obj-$(CONFIG_I2C_PXA) += i2c-pxa.o | 54 | obj-$(CONFIG_I2C_PXA) += i2c-pxa.o |
46 | obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o | 55 | obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o |
@@ -50,6 +59,8 @@ obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o | |||
50 | obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o | 59 | obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o |
51 | obj-$(CONFIG_I2C_STU300) += i2c-stu300.o | 60 | obj-$(CONFIG_I2C_STU300) += i2c-stu300.o |
52 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o | 61 | obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o |
62 | obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o | ||
63 | obj-$(CONFIG_I2C_XILINX) += i2c-xiic.o | ||
53 | 64 | ||
54 | # External I2C/SMBus adapter drivers | 65 | # External I2C/SMBus adapter drivers |
55 | obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o | 66 | obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o |
@@ -57,20 +68,13 @@ obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o | |||
57 | obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o | 68 | obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o |
58 | obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o | 69 | obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o |
59 | 70 | ||
60 | # Graphics adapter I2C/DDC channel drivers | ||
61 | obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o | ||
62 | |||
63 | # Other I2C/SMBus bus drivers | 71 | # Other I2C/SMBus bus drivers |
64 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o | 72 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o |
65 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o | 73 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o |
66 | obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o | 74 | obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o |
67 | obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o | ||
68 | obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o | ||
69 | obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o | 75 | obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o |
70 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o | 76 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o |
71 | obj-$(CONFIG_SCx200_ACB) += scx200_acb.o | 77 | obj-$(CONFIG_SCx200_ACB) += scx200_acb.o |
72 | obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o | 78 | obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o |
73 | 79 | ||
74 | ifeq ($(CONFIG_I2C_DEBUG_BUS),y) | 80 | ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG |
75 | EXTRA_CFLAGS += -DDEBUG | ||
76 | endif | ||
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c index d108450df064..906a3ca50db6 100644 --- a/drivers/i2c/busses/i2c-ali1535.c +++ b/drivers/i2c/busses/i2c-ali1535.c | |||
@@ -60,7 +60,7 @@ | |||
60 | #include <linux/i2c.h> | 60 | #include <linux/i2c.h> |
61 | #include <linux/init.h> | 61 | #include <linux/init.h> |
62 | #include <linux/acpi.h> | 62 | #include <linux/acpi.h> |
63 | #include <asm/io.h> | 63 | #include <linux/io.h> |
64 | 64 | ||
65 | 65 | ||
66 | /* ALI1535 SMBus address offsets */ | 66 | /* ALI1535 SMBus address offsets */ |
@@ -138,7 +138,7 @@ static unsigned short ali1535_smba; | |||
138 | Note the differences between kernels with the old PCI BIOS interface and | 138 | Note the differences between kernels with the old PCI BIOS interface and |
139 | newer kernels with the real PCI interface. In compat.h some things are | 139 | newer kernels with the real PCI interface. In compat.h some things are |
140 | defined to make the transition easier. */ | 140 | defined to make the transition easier. */ |
141 | static int ali1535_setup(struct pci_dev *dev) | 141 | static int __devinit ali1535_setup(struct pci_dev *dev) |
142 | { | 142 | { |
143 | int retval = -ENODEV; | 143 | int retval = -ENODEV; |
144 | unsigned char temp; | 144 | unsigned char temp; |
@@ -480,7 +480,7 @@ static struct i2c_adapter ali1535_adapter = { | |||
480 | .algo = &smbus_algorithm, | 480 | .algo = &smbus_algorithm, |
481 | }; | 481 | }; |
482 | 482 | ||
483 | static struct pci_device_id ali1535_ids[] = { | 483 | static const struct pci_device_id ali1535_ids[] = { |
484 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, | 484 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, |
485 | { }, | 485 | { }, |
486 | }; | 486 | }; |
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c index f70f46582c6c..a409cfcf0629 100644 --- a/drivers/i2c/busses/i2c-ali1563.c +++ b/drivers/i2c/busses/i2c-ali1563.c | |||
@@ -87,9 +87,9 @@ static int ali1563_transaction(struct i2c_adapter * a, int size) | |||
87 | outb_p(inb_p(SMB_HST_CNTL2) | HST_CNTL2_START, SMB_HST_CNTL2); | 87 | outb_p(inb_p(SMB_HST_CNTL2) | HST_CNTL2_START, SMB_HST_CNTL2); |
88 | 88 | ||
89 | timeout = ALI1563_MAX_TIMEOUT; | 89 | timeout = ALI1563_MAX_TIMEOUT; |
90 | do | 90 | do { |
91 | msleep(1); | 91 | msleep(1); |
92 | while (((data = inb_p(SMB_HST_STS)) & HST_STS_BUSY) && --timeout); | 92 | } while (((data = inb_p(SMB_HST_STS)) & HST_STS_BUSY) && --timeout); |
93 | 93 | ||
94 | dev_dbg(&a->dev, "Transaction (post): STS=%02x, CNTL1=%02x, " | 94 | dev_dbg(&a->dev, "Transaction (post): STS=%02x, CNTL1=%02x, " |
95 | "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", | 95 | "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", |
@@ -157,9 +157,9 @@ static int ali1563_block_start(struct i2c_adapter * a) | |||
157 | outb_p(inb_p(SMB_HST_CNTL2) | HST_CNTL2_START, SMB_HST_CNTL2); | 157 | outb_p(inb_p(SMB_HST_CNTL2) | HST_CNTL2_START, SMB_HST_CNTL2); |
158 | 158 | ||
159 | timeout = ALI1563_MAX_TIMEOUT; | 159 | timeout = ALI1563_MAX_TIMEOUT; |
160 | do | 160 | do { |
161 | msleep(1); | 161 | msleep(1); |
162 | while (!((data = inb_p(SMB_HST_STS)) & HST_STS_DONE) && --timeout); | 162 | } while (!((data = inb_p(SMB_HST_STS)) & HST_STS_DONE) && --timeout); |
163 | 163 | ||
164 | dev_dbg(&a->dev, "Block (post): STS=%02x, CNTL1=%02x, " | 164 | dev_dbg(&a->dev, "Block (post): STS=%02x, CNTL1=%02x, " |
165 | "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", | 165 | "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", |
@@ -417,7 +417,7 @@ static void __devexit ali1563_remove(struct pci_dev * dev) | |||
417 | ali1563_shutdown(dev); | 417 | ali1563_shutdown(dev); |
418 | } | 418 | } |
419 | 419 | ||
420 | static struct pci_device_id __devinitdata ali1563_id_table[] = { | 420 | static const struct pci_device_id ali1563_id_table[] __devinitconst = { |
421 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) }, | 421 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) }, |
422 | {}, | 422 | {}, |
423 | }; | 423 | }; |
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c index d627fceb790b..b14f6d68221d 100644 --- a/drivers/i2c/busses/i2c-ali15x3.c +++ b/drivers/i2c/busses/i2c-ali15x3.c | |||
@@ -67,7 +67,7 @@ | |||
67 | #include <linux/i2c.h> | 67 | #include <linux/i2c.h> |
68 | #include <linux/init.h> | 68 | #include <linux/init.h> |
69 | #include <linux/acpi.h> | 69 | #include <linux/acpi.h> |
70 | #include <asm/io.h> | 70 | #include <linux/io.h> |
71 | 71 | ||
72 | /* ALI15X3 SMBus address offsets */ | 72 | /* ALI15X3 SMBus address offsets */ |
73 | #define SMBHSTSTS (0 + ali15x3_smba) | 73 | #define SMBHSTSTS (0 + ali15x3_smba) |
@@ -131,7 +131,7 @@ MODULE_PARM_DESC(force_addr, | |||
131 | static struct pci_driver ali15x3_driver; | 131 | static struct pci_driver ali15x3_driver; |
132 | static unsigned short ali15x3_smba; | 132 | static unsigned short ali15x3_smba; |
133 | 133 | ||
134 | static int ali15x3_setup(struct pci_dev *ALI15X3_dev) | 134 | static int __devinit ali15x3_setup(struct pci_dev *ALI15X3_dev) |
135 | { | 135 | { |
136 | u16 a; | 136 | u16 a; |
137 | unsigned char temp; | 137 | unsigned char temp; |
@@ -477,7 +477,7 @@ static struct i2c_adapter ali15x3_adapter = { | |||
477 | .algo = &smbus_algorithm, | 477 | .algo = &smbus_algorithm, |
478 | }; | 478 | }; |
479 | 479 | ||
480 | static struct pci_device_id ali15x3_ids[] = { | 480 | static const struct pci_device_id ali15x3_ids[] = { |
481 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, | 481 | { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, |
482 | { 0, } | 482 | { 0, } |
483 | }; | 483 | }; |
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c index f7d6fe9c49ba..03bcd07c4697 100644 --- a/drivers/i2c/busses/i2c-amd756.c +++ b/drivers/i2c/busses/i2c-amd756.c | |||
@@ -43,7 +43,7 @@ | |||
43 | #include <linux/i2c.h> | 43 | #include <linux/i2c.h> |
44 | #include <linux/init.h> | 44 | #include <linux/init.h> |
45 | #include <linux/acpi.h> | 45 | #include <linux/acpi.h> |
46 | #include <asm/io.h> | 46 | #include <linux/io.h> |
47 | 47 | ||
48 | /* AMD756 SMBus address offsets */ | 48 | /* AMD756 SMBus address offsets */ |
49 | #define SMB_ADDR_OFFSET 0xE0 | 49 | #define SMB_ADDR_OFFSET 0xE0 |
@@ -308,7 +308,7 @@ static const char* chipname[] = { | |||
308 | "nVidia nForce", "AMD8111", | 308 | "nVidia nForce", "AMD8111", |
309 | }; | 309 | }; |
310 | 310 | ||
311 | static struct pci_device_id amd756_ids[] = { | 311 | static const struct pci_device_id amd756_ids[] = { |
312 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B), | 312 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B), |
313 | .driver_data = AMD756 }, | 313 | .driver_data = AMD756 }, |
314 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413), | 314 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413), |
@@ -364,7 +364,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev, | |||
364 | error = acpi_check_region(amd756_ioport, SMB_IOSIZE, | 364 | error = acpi_check_region(amd756_ioport, SMB_IOSIZE, |
365 | amd756_driver.name); | 365 | amd756_driver.name); |
366 | if (error) | 366 | if (error) |
367 | return error; | 367 | return -ENODEV; |
368 | 368 | ||
369 | if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) { | 369 | if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) { |
370 | dev_err(&pdev->dev, "SMB region 0x%x already in use!\n", | 370 | dev_err(&pdev->dev, "SMB region 0x%x already in use!\n", |
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c index a7c59908c457..6b6a6b1d7025 100644 --- a/drivers/i2c/busses/i2c-amd8111.c +++ b/drivers/i2c/busses/i2c-amd8111.c | |||
@@ -17,7 +17,8 @@ | |||
17 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/acpi.h> | 19 | #include <linux/acpi.h> |
20 | #include <asm/io.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/io.h> | ||
21 | 22 | ||
22 | MODULE_LICENSE("GPL"); | 23 | MODULE_LICENSE("GPL"); |
23 | MODULE_AUTHOR ("Vojtech Pavlik <vojtech@suse.cz>"); | 24 | MODULE_AUTHOR ("Vojtech Pavlik <vojtech@suse.cz>"); |
@@ -68,7 +69,7 @@ static struct pci_driver amd8111_driver; | |||
68 | * ACPI 2.0 chapter 13 access of registers of the EC | 69 | * ACPI 2.0 chapter 13 access of registers of the EC |
69 | */ | 70 | */ |
70 | 71 | ||
71 | static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) | 72 | static int amd_ec_wait_write(struct amd_smbus *smbus) |
72 | { | 73 | { |
73 | int timeout = 500; | 74 | int timeout = 500; |
74 | 75 | ||
@@ -84,7 +85,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) | |||
84 | return 0; | 85 | return 0; |
85 | } | 86 | } |
86 | 87 | ||
87 | static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) | 88 | static int amd_ec_wait_read(struct amd_smbus *smbus) |
88 | { | 89 | { |
89 | int timeout = 500; | 90 | int timeout = 500; |
90 | 91 | ||
@@ -100,7 +101,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) | |||
100 | return 0; | 101 | return 0; |
101 | } | 102 | } |
102 | 103 | ||
103 | static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, | 104 | static int amd_ec_read(struct amd_smbus *smbus, unsigned char address, |
104 | unsigned char *data) | 105 | unsigned char *data) |
105 | { | 106 | { |
106 | int status; | 107 | int status; |
@@ -123,7 +124,7 @@ static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, | |||
123 | return 0; | 124 | return 0; |
124 | } | 125 | } |
125 | 126 | ||
126 | static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address, | 127 | static int amd_ec_write(struct amd_smbus *smbus, unsigned char address, |
127 | unsigned char data) | 128 | unsigned char data) |
128 | { | 129 | { |
129 | int status; | 130 | int status; |
@@ -195,7 +196,7 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
195 | { | 196 | { |
196 | struct amd_smbus *smbus = adap->algo_data; | 197 | struct amd_smbus *smbus = adap->algo_data; |
197 | unsigned char protocol, len, pec, temp[2]; | 198 | unsigned char protocol, len, pec, temp[2]; |
198 | int i; | 199 | int i, status; |
199 | 200 | ||
200 | protocol = (read_write == I2C_SMBUS_READ) ? AMD_SMB_PRTCL_READ | 201 | protocol = (read_write == I2C_SMBUS_READ) ? AMD_SMB_PRTCL_READ |
201 | : AMD_SMB_PRTCL_WRITE; | 202 | : AMD_SMB_PRTCL_WRITE; |
@@ -208,38 +209,62 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
208 | break; | 209 | break; |
209 | 210 | ||
210 | case I2C_SMBUS_BYTE: | 211 | case I2C_SMBUS_BYTE: |
211 | if (read_write == I2C_SMBUS_WRITE) | 212 | if (read_write == I2C_SMBUS_WRITE) { |
212 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 213 | status = amd_ec_write(smbus, AMD_SMB_CMD, |
214 | command); | ||
215 | if (status) | ||
216 | return status; | ||
217 | } | ||
213 | protocol |= AMD_SMB_PRTCL_BYTE; | 218 | protocol |= AMD_SMB_PRTCL_BYTE; |
214 | break; | 219 | break; |
215 | 220 | ||
216 | case I2C_SMBUS_BYTE_DATA: | 221 | case I2C_SMBUS_BYTE_DATA: |
217 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 222 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
218 | if (read_write == I2C_SMBUS_WRITE) | 223 | if (status) |
219 | amd_ec_write(smbus, AMD_SMB_DATA, data->byte); | 224 | return status; |
225 | if (read_write == I2C_SMBUS_WRITE) { | ||
226 | status = amd_ec_write(smbus, AMD_SMB_DATA, | ||
227 | data->byte); | ||
228 | if (status) | ||
229 | return status; | ||
230 | } | ||
220 | protocol |= AMD_SMB_PRTCL_BYTE_DATA; | 231 | protocol |= AMD_SMB_PRTCL_BYTE_DATA; |
221 | break; | 232 | break; |
222 | 233 | ||
223 | case I2C_SMBUS_WORD_DATA: | 234 | case I2C_SMBUS_WORD_DATA: |
224 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 235 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
236 | if (status) | ||
237 | return status; | ||
225 | if (read_write == I2C_SMBUS_WRITE) { | 238 | if (read_write == I2C_SMBUS_WRITE) { |
226 | amd_ec_write(smbus, AMD_SMB_DATA, | 239 | status = amd_ec_write(smbus, AMD_SMB_DATA, |
227 | data->word & 0xff); | 240 | data->word & 0xff); |
228 | amd_ec_write(smbus, AMD_SMB_DATA + 1, | 241 | if (status) |
229 | data->word >> 8); | 242 | return status; |
243 | status = amd_ec_write(smbus, AMD_SMB_DATA + 1, | ||
244 | data->word >> 8); | ||
245 | if (status) | ||
246 | return status; | ||
230 | } | 247 | } |
231 | protocol |= AMD_SMB_PRTCL_WORD_DATA | pec; | 248 | protocol |= AMD_SMB_PRTCL_WORD_DATA | pec; |
232 | break; | 249 | break; |
233 | 250 | ||
234 | case I2C_SMBUS_BLOCK_DATA: | 251 | case I2C_SMBUS_BLOCK_DATA: |
235 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 252 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
253 | if (status) | ||
254 | return status; | ||
236 | if (read_write == I2C_SMBUS_WRITE) { | 255 | if (read_write == I2C_SMBUS_WRITE) { |
237 | len = min_t(u8, data->block[0], | 256 | len = min_t(u8, data->block[0], |
238 | I2C_SMBUS_BLOCK_MAX); | 257 | I2C_SMBUS_BLOCK_MAX); |
239 | amd_ec_write(smbus, AMD_SMB_BCNT, len); | 258 | status = amd_ec_write(smbus, AMD_SMB_BCNT, len); |
240 | for (i = 0; i < len; i++) | 259 | if (status) |
241 | amd_ec_write(smbus, AMD_SMB_DATA + i, | 260 | return status; |
242 | data->block[i + 1]); | 261 | for (i = 0; i < len; i++) { |
262 | status = | ||
263 | amd_ec_write(smbus, AMD_SMB_DATA + i, | ||
264 | data->block[i + 1]); | ||
265 | if (status) | ||
266 | return status; | ||
267 | } | ||
243 | } | 268 | } |
244 | protocol |= AMD_SMB_PRTCL_BLOCK_DATA | pec; | 269 | protocol |= AMD_SMB_PRTCL_BLOCK_DATA | pec; |
245 | break; | 270 | break; |
@@ -247,19 +272,35 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
247 | case I2C_SMBUS_I2C_BLOCK_DATA: | 272 | case I2C_SMBUS_I2C_BLOCK_DATA: |
248 | len = min_t(u8, data->block[0], | 273 | len = min_t(u8, data->block[0], |
249 | I2C_SMBUS_BLOCK_MAX); | 274 | I2C_SMBUS_BLOCK_MAX); |
250 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 275 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
251 | amd_ec_write(smbus, AMD_SMB_BCNT, len); | 276 | if (status) |
277 | return status; | ||
278 | status = amd_ec_write(smbus, AMD_SMB_BCNT, len); | ||
279 | if (status) | ||
280 | return status; | ||
252 | if (read_write == I2C_SMBUS_WRITE) | 281 | if (read_write == I2C_SMBUS_WRITE) |
253 | for (i = 0; i < len; i++) | 282 | for (i = 0; i < len; i++) { |
254 | amd_ec_write(smbus, AMD_SMB_DATA + i, | 283 | status = |
255 | data->block[i + 1]); | 284 | amd_ec_write(smbus, AMD_SMB_DATA + i, |
285 | data->block[i + 1]); | ||
286 | if (status) | ||
287 | return status; | ||
288 | } | ||
256 | protocol |= AMD_SMB_PRTCL_I2C_BLOCK_DATA; | 289 | protocol |= AMD_SMB_PRTCL_I2C_BLOCK_DATA; |
257 | break; | 290 | break; |
258 | 291 | ||
259 | case I2C_SMBUS_PROC_CALL: | 292 | case I2C_SMBUS_PROC_CALL: |
260 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 293 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
261 | amd_ec_write(smbus, AMD_SMB_DATA, data->word & 0xff); | 294 | if (status) |
262 | amd_ec_write(smbus, AMD_SMB_DATA + 1, data->word >> 8); | 295 | return status; |
296 | status = amd_ec_write(smbus, AMD_SMB_DATA, | ||
297 | data->word & 0xff); | ||
298 | if (status) | ||
299 | return status; | ||
300 | status = amd_ec_write(smbus, AMD_SMB_DATA + 1, | ||
301 | data->word >> 8); | ||
302 | if (status) | ||
303 | return status; | ||
263 | protocol = AMD_SMB_PRTCL_PROC_CALL | pec; | 304 | protocol = AMD_SMB_PRTCL_PROC_CALL | pec; |
264 | read_write = I2C_SMBUS_READ; | 305 | read_write = I2C_SMBUS_READ; |
265 | break; | 306 | break; |
@@ -267,11 +308,18 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
267 | case I2C_SMBUS_BLOCK_PROC_CALL: | 308 | case I2C_SMBUS_BLOCK_PROC_CALL: |
268 | len = min_t(u8, data->block[0], | 309 | len = min_t(u8, data->block[0], |
269 | I2C_SMBUS_BLOCK_MAX - 1); | 310 | I2C_SMBUS_BLOCK_MAX - 1); |
270 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 311 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
271 | amd_ec_write(smbus, AMD_SMB_BCNT, len); | 312 | if (status) |
272 | for (i = 0; i < len; i++) | 313 | return status; |
273 | amd_ec_write(smbus, AMD_SMB_DATA + i, | 314 | status = amd_ec_write(smbus, AMD_SMB_BCNT, len); |
274 | data->block[i + 1]); | 315 | if (status) |
316 | return status; | ||
317 | for (i = 0; i < len; i++) { | ||
318 | status = amd_ec_write(smbus, AMD_SMB_DATA + i, | ||
319 | data->block[i + 1]); | ||
320 | if (status) | ||
321 | return status; | ||
322 | } | ||
275 | protocol = AMD_SMB_PRTCL_BLOCK_PROC_CALL | pec; | 323 | protocol = AMD_SMB_PRTCL_BLOCK_PROC_CALL | pec; |
276 | read_write = I2C_SMBUS_READ; | 324 | read_write = I2C_SMBUS_READ; |
277 | break; | 325 | break; |
@@ -281,24 +329,29 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
281 | return -EOPNOTSUPP; | 329 | return -EOPNOTSUPP; |
282 | } | 330 | } |
283 | 331 | ||
284 | amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); | 332 | status = amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); |
285 | amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); | 333 | if (status) |
334 | return status; | ||
335 | status = amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); | ||
336 | if (status) | ||
337 | return status; | ||
286 | 338 | ||
287 | /* FIXME this discards status from ec_read(); so temp[0] will | 339 | status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0); |
288 | * hold stack garbage ... the rest of this routine will act | 340 | if (status) |
289 | * nonsensically. Ignored ec_write() status might explain | 341 | return status; |
290 | * some such failures... | ||
291 | */ | ||
292 | amd_ec_read(smbus, AMD_SMB_STS, temp + 0); | ||
293 | 342 | ||
294 | if (~temp[0] & AMD_SMB_STS_DONE) { | 343 | if (~temp[0] & AMD_SMB_STS_DONE) { |
295 | udelay(500); | 344 | udelay(500); |
296 | amd_ec_read(smbus, AMD_SMB_STS, temp + 0); | 345 | status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0); |
346 | if (status) | ||
347 | return status; | ||
297 | } | 348 | } |
298 | 349 | ||
299 | if (~temp[0] & AMD_SMB_STS_DONE) { | 350 | if (~temp[0] & AMD_SMB_STS_DONE) { |
300 | msleep(1); | 351 | msleep(1); |
301 | amd_ec_read(smbus, AMD_SMB_STS, temp + 0); | 352 | status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0); |
353 | if (status) | ||
354 | return status; | ||
302 | } | 355 | } |
303 | 356 | ||
304 | if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) | 357 | if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) |
@@ -310,24 +363,35 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
310 | switch (size) { | 363 | switch (size) { |
311 | case I2C_SMBUS_BYTE: | 364 | case I2C_SMBUS_BYTE: |
312 | case I2C_SMBUS_BYTE_DATA: | 365 | case I2C_SMBUS_BYTE_DATA: |
313 | amd_ec_read(smbus, AMD_SMB_DATA, &data->byte); | 366 | status = amd_ec_read(smbus, AMD_SMB_DATA, &data->byte); |
367 | if (status) | ||
368 | return status; | ||
314 | break; | 369 | break; |
315 | 370 | ||
316 | case I2C_SMBUS_WORD_DATA: | 371 | case I2C_SMBUS_WORD_DATA: |
317 | case I2C_SMBUS_PROC_CALL: | 372 | case I2C_SMBUS_PROC_CALL: |
318 | amd_ec_read(smbus, AMD_SMB_DATA, temp + 0); | 373 | status = amd_ec_read(smbus, AMD_SMB_DATA, temp + 0); |
319 | amd_ec_read(smbus, AMD_SMB_DATA + 1, temp + 1); | 374 | if (status) |
375 | return status; | ||
376 | status = amd_ec_read(smbus, AMD_SMB_DATA + 1, temp + 1); | ||
377 | if (status) | ||
378 | return status; | ||
320 | data->word = (temp[1] << 8) | temp[0]; | 379 | data->word = (temp[1] << 8) | temp[0]; |
321 | break; | 380 | break; |
322 | 381 | ||
323 | case I2C_SMBUS_BLOCK_DATA: | 382 | case I2C_SMBUS_BLOCK_DATA: |
324 | case I2C_SMBUS_BLOCK_PROC_CALL: | 383 | case I2C_SMBUS_BLOCK_PROC_CALL: |
325 | amd_ec_read(smbus, AMD_SMB_BCNT, &len); | 384 | status = amd_ec_read(smbus, AMD_SMB_BCNT, &len); |
385 | if (status) | ||
386 | return status; | ||
326 | len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX); | 387 | len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX); |
327 | case I2C_SMBUS_I2C_BLOCK_DATA: | 388 | case I2C_SMBUS_I2C_BLOCK_DATA: |
328 | for (i = 0; i < len; i++) | 389 | for (i = 0; i < len; i++) { |
329 | amd_ec_read(smbus, AMD_SMB_DATA + i, | 390 | status = amd_ec_read(smbus, AMD_SMB_DATA + i, |
330 | data->block + i + 1); | 391 | data->block + i + 1); |
392 | if (status) | ||
393 | return status; | ||
394 | } | ||
331 | data->block[0] = len; | 395 | data->block[0] = len; |
332 | break; | 396 | break; |
333 | } | 397 | } |
@@ -351,7 +415,7 @@ static const struct i2c_algorithm smbus_algorithm = { | |||
351 | }; | 415 | }; |
352 | 416 | ||
353 | 417 | ||
354 | static struct pci_device_id amd8111_ids[] = { | 418 | static const struct pci_device_id amd8111_ids[] = { |
355 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) }, | 419 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) }, |
356 | { 0, } | 420 | { 0, } |
357 | }; | 421 | }; |
@@ -376,8 +440,10 @@ static int __devinit amd8111_probe(struct pci_dev *dev, | |||
376 | smbus->size = pci_resource_len(dev, 0); | 440 | smbus->size = pci_resource_len(dev, 0); |
377 | 441 | ||
378 | error = acpi_check_resource_conflict(&dev->resource[0]); | 442 | error = acpi_check_resource_conflict(&dev->resource[0]); |
379 | if (error) | 443 | if (error) { |
444 | error = -ENODEV; | ||
380 | goto out_kfree; | 445 | goto out_kfree; |
446 | } | ||
381 | 447 | ||
382 | if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) { | 448 | if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) { |
383 | error = -EBUSY; | 449 | error = -EBUSY; |
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 06e1ecb4919f..305c07504f7e 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c | |||
@@ -23,8 +23,7 @@ | |||
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/clk.h> | 24 | #include <linux/clk.h> |
25 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
26 | 26 | #include <linux/io.h> | |
27 | #include <asm/io.h> | ||
28 | 27 | ||
29 | #include <mach/at91_twi.h> | 28 | #include <mach/at91_twi.h> |
30 | #include <mach/board.h> | 29 | #include <mach/board.h> |
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c index b309ac2c3d5c..fb26e5c67515 100644 --- a/drivers/i2c/busses/i2c-bfin-twi.c +++ b/drivers/i2c/busses/i2c-bfin-twi.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/io.h> | 16 | #include <linux/io.h> |
16 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
17 | #include <linux/timer.h> | 18 | #include <linux/timer.h> |
@@ -24,8 +25,6 @@ | |||
24 | #include <asm/portmux.h> | 25 | #include <asm/portmux.h> |
25 | #include <asm/irq.h> | 26 | #include <asm/irq.h> |
26 | 27 | ||
27 | #define POLL_TIMEOUT (2 * HZ) | ||
28 | |||
29 | /* SMBus mode*/ | 28 | /* SMBus mode*/ |
30 | #define TWI_I2C_MODE_STANDARD 1 | 29 | #define TWI_I2C_MODE_STANDARD 1 |
31 | #define TWI_I2C_MODE_STANDARDSUB 2 | 30 | #define TWI_I2C_MODE_STANDARDSUB 2 |
@@ -43,8 +42,6 @@ struct bfin_twi_iface { | |||
43 | int cur_mode; | 42 | int cur_mode; |
44 | int manual_stop; | 43 | int manual_stop; |
45 | int result; | 44 | int result; |
46 | int timeout_count; | ||
47 | struct timer_list timeout_timer; | ||
48 | struct i2c_adapter adap; | 45 | struct i2c_adapter adap; |
49 | struct completion complete; | 46 | struct completion complete; |
50 | struct i2c_msg *pmsg; | 47 | struct i2c_msg *pmsg; |
@@ -84,14 +81,15 @@ static const u16 pin_req[2][3] = { | |||
84 | {P_TWI1_SCL, P_TWI1_SDA, 0}, | 81 | {P_TWI1_SCL, P_TWI1_SDA, 0}, |
85 | }; | 82 | }; |
86 | 83 | ||
87 | static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | 84 | static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface, |
85 | unsigned short twi_int_status) | ||
88 | { | 86 | { |
89 | unsigned short twi_int_status = read_INT_STAT(iface); | ||
90 | unsigned short mast_stat = read_MASTER_STAT(iface); | 87 | unsigned short mast_stat = read_MASTER_STAT(iface); |
91 | 88 | ||
92 | if (twi_int_status & XMTSERV) { | 89 | if (twi_int_status & XMTSERV) { |
93 | /* Transmit next data */ | 90 | /* Transmit next data */ |
94 | if (iface->writeNum > 0) { | 91 | if (iface->writeNum > 0) { |
92 | SSYNC(); | ||
95 | write_XMT_DATA8(iface, *(iface->transPtr++)); | 93 | write_XMT_DATA8(iface, *(iface->transPtr++)); |
96 | iface->writeNum--; | 94 | iface->writeNum--; |
97 | } | 95 | } |
@@ -113,10 +111,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | |||
113 | write_MASTER_CTL(iface, | 111 | write_MASTER_CTL(iface, |
114 | (read_MASTER_CTL(iface) | RSTART) & ~MDIR); | 112 | (read_MASTER_CTL(iface) | RSTART) & ~MDIR); |
115 | } | 113 | } |
116 | SSYNC(); | ||
117 | /* Clear status */ | ||
118 | write_INT_STAT(iface, XMTSERV); | ||
119 | SSYNC(); | ||
120 | } | 114 | } |
121 | if (twi_int_status & RCVSERV) { | 115 | if (twi_int_status & RCVSERV) { |
122 | if (iface->readNum > 0) { | 116 | if (iface->readNum > 0) { |
@@ -138,7 +132,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | |||
138 | } else if (iface->manual_stop) { | 132 | } else if (iface->manual_stop) { |
139 | write_MASTER_CTL(iface, | 133 | write_MASTER_CTL(iface, |
140 | read_MASTER_CTL(iface) | STOP); | 134 | read_MASTER_CTL(iface) | STOP); |
141 | SSYNC(); | ||
142 | } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && | 135 | } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && |
143 | iface->cur_msg + 1 < iface->msg_num) { | 136 | iface->cur_msg + 1 < iface->msg_num) { |
144 | if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) | 137 | if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) |
@@ -147,44 +140,37 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | |||
147 | else | 140 | else |
148 | write_MASTER_CTL(iface, | 141 | write_MASTER_CTL(iface, |
149 | (read_MASTER_CTL(iface) | RSTART) & ~MDIR); | 142 | (read_MASTER_CTL(iface) | RSTART) & ~MDIR); |
150 | SSYNC(); | ||
151 | } | 143 | } |
152 | /* Clear interrupt source */ | ||
153 | write_INT_STAT(iface, RCVSERV); | ||
154 | SSYNC(); | ||
155 | } | 144 | } |
156 | if (twi_int_status & MERR) { | 145 | if (twi_int_status & MERR) { |
157 | write_INT_STAT(iface, MERR); | ||
158 | write_INT_MASK(iface, 0); | 146 | write_INT_MASK(iface, 0); |
159 | write_MASTER_STAT(iface, 0x3e); | 147 | write_MASTER_STAT(iface, 0x3e); |
160 | write_MASTER_CTL(iface, 0); | 148 | write_MASTER_CTL(iface, 0); |
161 | SSYNC(); | ||
162 | iface->result = -EIO; | 149 | iface->result = -EIO; |
163 | /* if both err and complete int stats are set, return proper | 150 | |
164 | * results. | 151 | if (mast_stat & LOSTARB) |
152 | dev_dbg(&iface->adap.dev, "Lost Arbitration\n"); | ||
153 | if (mast_stat & ANAK) | ||
154 | dev_dbg(&iface->adap.dev, "Address Not Acknowledged\n"); | ||
155 | if (mast_stat & DNAK) | ||
156 | dev_dbg(&iface->adap.dev, "Data Not Acknowledged\n"); | ||
157 | if (mast_stat & BUFRDERR) | ||
158 | dev_dbg(&iface->adap.dev, "Buffer Read Error\n"); | ||
159 | if (mast_stat & BUFWRERR) | ||
160 | dev_dbg(&iface->adap.dev, "Buffer Write Error\n"); | ||
161 | |||
162 | /* If it is a quick transfer, only address without data, | ||
163 | * not an err, return 1. | ||
165 | */ | 164 | */ |
166 | if (twi_int_status & MCOMP) { | 165 | if (iface->cur_mode == TWI_I2C_MODE_STANDARD && |
167 | write_INT_STAT(iface, MCOMP); | 166 | iface->transPtr == NULL && |
168 | write_INT_MASK(iface, 0); | 167 | (twi_int_status & MCOMP) && (mast_stat & DNAK)) |
169 | write_MASTER_CTL(iface, 0); | 168 | iface->result = 1; |
170 | SSYNC(); | 169 | |
171 | /* If it is a quick transfer, only address bug no data, | ||
172 | * not an err, return 1. | ||
173 | */ | ||
174 | if (iface->writeNum == 0 && (mast_stat & BUFRDERR)) | ||
175 | iface->result = 1; | ||
176 | /* If address not acknowledged return -1, | ||
177 | * else return 0. | ||
178 | */ | ||
179 | else if (!(mast_stat & ANAK)) | ||
180 | iface->result = 0; | ||
181 | } | ||
182 | complete(&iface->complete); | 170 | complete(&iface->complete); |
183 | return; | 171 | return; |
184 | } | 172 | } |
185 | if (twi_int_status & MCOMP) { | 173 | if (twi_int_status & MCOMP) { |
186 | write_INT_STAT(iface, MCOMP); | ||
187 | SSYNC(); | ||
188 | if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { | 174 | if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { |
189 | if (iface->readNum == 0) { | 175 | if (iface->readNum == 0) { |
190 | /* set the read number to 1 and ask for manual | 176 | /* set the read number to 1 and ask for manual |
@@ -206,7 +192,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | |||
206 | /* remove restart bit and enable master receive */ | 192 | /* remove restart bit and enable master receive */ |
207 | write_MASTER_CTL(iface, | 193 | write_MASTER_CTL(iface, |
208 | read_MASTER_CTL(iface) & ~RSTART); | 194 | read_MASTER_CTL(iface) & ~RSTART); |
209 | SSYNC(); | ||
210 | } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && | 195 | } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && |
211 | iface->cur_msg+1 < iface->msg_num) { | 196 | iface->cur_msg+1 < iface->msg_num) { |
212 | iface->cur_msg++; | 197 | iface->cur_msg++; |
@@ -225,7 +210,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | |||
225 | write_XMT_DATA8(iface, | 210 | write_XMT_DATA8(iface, |
226 | *(iface->transPtr++)); | 211 | *(iface->transPtr++)); |
227 | iface->writeNum--; | 212 | iface->writeNum--; |
228 | SSYNC(); | ||
229 | } | 213 | } |
230 | } | 214 | } |
231 | 215 | ||
@@ -243,15 +227,13 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) | |||
243 | /* remove restart bit and enable master receive */ | 227 | /* remove restart bit and enable master receive */ |
244 | write_MASTER_CTL(iface, | 228 | write_MASTER_CTL(iface, |
245 | read_MASTER_CTL(iface) & ~RSTART); | 229 | read_MASTER_CTL(iface) & ~RSTART); |
246 | SSYNC(); | ||
247 | } else { | 230 | } else { |
248 | iface->result = 1; | 231 | iface->result = 1; |
249 | write_INT_MASK(iface, 0); | 232 | write_INT_MASK(iface, 0); |
250 | write_MASTER_CTL(iface, 0); | 233 | write_MASTER_CTL(iface, 0); |
251 | SSYNC(); | ||
252 | complete(&iface->complete); | ||
253 | } | 234 | } |
254 | } | 235 | } |
236 | complete(&iface->complete); | ||
255 | } | 237 | } |
256 | 238 | ||
257 | /* Interrupt handler */ | 239 | /* Interrupt handler */ |
@@ -259,38 +241,26 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id) | |||
259 | { | 241 | { |
260 | struct bfin_twi_iface *iface = dev_id; | 242 | struct bfin_twi_iface *iface = dev_id; |
261 | unsigned long flags; | 243 | unsigned long flags; |
244 | unsigned short twi_int_status; | ||
262 | 245 | ||
263 | spin_lock_irqsave(&iface->lock, flags); | 246 | spin_lock_irqsave(&iface->lock, flags); |
264 | del_timer(&iface->timeout_timer); | 247 | while (1) { |
265 | bfin_twi_handle_interrupt(iface); | 248 | twi_int_status = read_INT_STAT(iface); |
266 | spin_unlock_irqrestore(&iface->lock, flags); | 249 | if (!twi_int_status) |
267 | return IRQ_HANDLED; | 250 | break; |
268 | } | 251 | /* Clear interrupt status */ |
269 | 252 | write_INT_STAT(iface, twi_int_status); | |
270 | static void bfin_twi_timeout(unsigned long data) | 253 | bfin_twi_handle_interrupt(iface, twi_int_status); |
271 | { | 254 | SSYNC(); |
272 | struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data; | ||
273 | unsigned long flags; | ||
274 | |||
275 | spin_lock_irqsave(&iface->lock, flags); | ||
276 | bfin_twi_handle_interrupt(iface); | ||
277 | if (iface->result == 0) { | ||
278 | iface->timeout_count--; | ||
279 | if (iface->timeout_count > 0) { | ||
280 | iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; | ||
281 | add_timer(&iface->timeout_timer); | ||
282 | } else { | ||
283 | iface->result = -1; | ||
284 | complete(&iface->complete); | ||
285 | } | ||
286 | } | 255 | } |
287 | spin_unlock_irqrestore(&iface->lock, flags); | 256 | spin_unlock_irqrestore(&iface->lock, flags); |
257 | return IRQ_HANDLED; | ||
288 | } | 258 | } |
289 | 259 | ||
290 | /* | 260 | /* |
291 | * Generic i2c master transfer entrypoint | 261 | * One i2c master transfer |
292 | */ | 262 | */ |
293 | static int bfin_twi_master_xfer(struct i2c_adapter *adap, | 263 | static int bfin_twi_do_master_xfer(struct i2c_adapter *adap, |
294 | struct i2c_msg *msgs, int num) | 264 | struct i2c_msg *msgs, int num) |
295 | { | 265 | { |
296 | struct bfin_twi_iface *iface = adap->algo_data; | 266 | struct bfin_twi_iface *iface = adap->algo_data; |
@@ -318,7 +288,6 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap, | |||
318 | iface->transPtr = pmsg->buf; | 288 | iface->transPtr = pmsg->buf; |
319 | iface->writeNum = iface->readNum = pmsg->len; | 289 | iface->writeNum = iface->readNum = pmsg->len; |
320 | iface->result = 0; | 290 | iface->result = 0; |
321 | iface->timeout_count = 10; | ||
322 | init_completion(&(iface->complete)); | 291 | init_completion(&(iface->complete)); |
323 | /* Set Transmit device address */ | 292 | /* Set Transmit device address */ |
324 | write_MASTER_ADDR(iface, pmsg->addr); | 293 | write_MASTER_ADDR(iface, pmsg->addr); |
@@ -357,30 +326,41 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap, | |||
357 | iface->manual_stop = 1; | 326 | iface->manual_stop = 1; |
358 | } | 327 | } |
359 | 328 | ||
360 | iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; | ||
361 | add_timer(&iface->timeout_timer); | ||
362 | |||
363 | /* Master enable */ | 329 | /* Master enable */ |
364 | write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | | 330 | write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | |
365 | ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | | 331 | ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | |
366 | ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); | 332 | ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); |
367 | SSYNC(); | 333 | SSYNC(); |
368 | 334 | ||
369 | wait_for_completion(&iface->complete); | 335 | while (!iface->result) { |
370 | 336 | if (!wait_for_completion_timeout(&iface->complete, | |
371 | rc = iface->result; | 337 | adap->timeout)) { |
338 | iface->result = -1; | ||
339 | dev_err(&adap->dev, "master transfer timeout\n"); | ||
340 | } | ||
341 | } | ||
372 | 342 | ||
373 | if (rc == 1) | 343 | if (iface->result == 1) |
374 | return num; | 344 | rc = iface->cur_msg + 1; |
375 | else | 345 | else |
376 | return rc; | 346 | rc = iface->result; |
347 | |||
348 | return rc; | ||
377 | } | 349 | } |
378 | 350 | ||
379 | /* | 351 | /* |
380 | * SMBus type transfer entrypoint | 352 | * Generic i2c master transfer entrypoint |
381 | */ | 353 | */ |
354 | static int bfin_twi_master_xfer(struct i2c_adapter *adap, | ||
355 | struct i2c_msg *msgs, int num) | ||
356 | { | ||
357 | return bfin_twi_do_master_xfer(adap, msgs, num); | ||
358 | } | ||
382 | 359 | ||
383 | int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | 360 | /* |
361 | * One I2C SMBus transfer | ||
362 | */ | ||
363 | int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr, | ||
384 | unsigned short flags, char read_write, | 364 | unsigned short flags, char read_write, |
385 | u8 command, int size, union i2c_smbus_data *data) | 365 | u8 command, int size, union i2c_smbus_data *data) |
386 | { | 366 | { |
@@ -468,7 +448,6 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
468 | iface->manual_stop = 0; | 448 | iface->manual_stop = 0; |
469 | iface->read_write = read_write; | 449 | iface->read_write = read_write; |
470 | iface->command = command; | 450 | iface->command = command; |
471 | iface->timeout_count = 10; | ||
472 | init_completion(&(iface->complete)); | 451 | init_completion(&(iface->complete)); |
473 | 452 | ||
474 | /* FIFO Initiation. Data in FIFO should be discarded before | 453 | /* FIFO Initiation. Data in FIFO should be discarded before |
@@ -485,9 +464,6 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
485 | write_MASTER_ADDR(iface, addr); | 464 | write_MASTER_ADDR(iface, addr); |
486 | SSYNC(); | 465 | SSYNC(); |
487 | 466 | ||
488 | iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; | ||
489 | add_timer(&iface->timeout_timer); | ||
490 | |||
491 | switch (iface->cur_mode) { | 467 | switch (iface->cur_mode) { |
492 | case TWI_I2C_MODE_STANDARDSUB: | 468 | case TWI_I2C_MODE_STANDARDSUB: |
493 | write_XMT_DATA8(iface, iface->command); | 469 | write_XMT_DATA8(iface, iface->command); |
@@ -549,10 +525,8 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
549 | else if (iface->readNum > 255) { | 525 | else if (iface->readNum > 255) { |
550 | write_MASTER_CTL(iface, 0xff << 6); | 526 | write_MASTER_CTL(iface, 0xff << 6); |
551 | iface->manual_stop = 1; | 527 | iface->manual_stop = 1; |
552 | } else { | 528 | } else |
553 | del_timer(&iface->timeout_timer); | ||
554 | break; | 529 | break; |
555 | } | ||
556 | } | 530 | } |
557 | } | 531 | } |
558 | write_INT_MASK(iface, MCOMP | MERR | | 532 | write_INT_MASK(iface, MCOMP | MERR | |
@@ -568,7 +542,13 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
568 | } | 542 | } |
569 | SSYNC(); | 543 | SSYNC(); |
570 | 544 | ||
571 | wait_for_completion(&iface->complete); | 545 | while (!iface->result) { |
546 | if (!wait_for_completion_timeout(&iface->complete, | ||
547 | adap->timeout)) { | ||
548 | iface->result = -1; | ||
549 | dev_err(&adap->dev, "smbus transfer timeout\n"); | ||
550 | } | ||
551 | } | ||
572 | 552 | ||
573 | rc = (iface->result >= 0) ? 0 : -1; | 553 | rc = (iface->result >= 0) ? 0 : -1; |
574 | 554 | ||
@@ -576,6 +556,17 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
576 | } | 556 | } |
577 | 557 | ||
578 | /* | 558 | /* |
559 | * Generic I2C SMBus transfer entrypoint | ||
560 | */ | ||
561 | int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr, | ||
562 | unsigned short flags, char read_write, | ||
563 | u8 command, int size, union i2c_smbus_data *data) | ||
564 | { | ||
565 | return bfin_twi_do_smbus_xfer(adap, addr, flags, | ||
566 | read_write, command, size, data); | ||
567 | } | ||
568 | |||
569 | /* | ||
579 | * Return what the adapter supports | 570 | * Return what the adapter supports |
580 | */ | 571 | */ |
581 | static u32 bfin_twi_functionality(struct i2c_adapter *adap) | 572 | static u32 bfin_twi_functionality(struct i2c_adapter *adap) |
@@ -666,10 +657,6 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) | |||
666 | goto out_error_no_irq; | 657 | goto out_error_no_irq; |
667 | } | 658 | } |
668 | 659 | ||
669 | init_timer(&(iface->timeout_timer)); | ||
670 | iface->timeout_timer.function = bfin_twi_timeout; | ||
671 | iface->timeout_timer.data = (unsigned long)iface; | ||
672 | |||
673 | p_adap = &iface->adap; | 660 | p_adap = &iface->adap; |
674 | p_adap->nr = pdev->id; | 661 | p_adap->nr = pdev->id; |
675 | strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name)); | 662 | strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name)); |
@@ -677,6 +664,8 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) | |||
677 | p_adap->algo_data = iface; | 664 | p_adap->algo_data = iface; |
678 | p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 665 | p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
679 | p_adap->dev.parent = &pdev->dev; | 666 | p_adap->dev.parent = &pdev->dev; |
667 | p_adap->timeout = 5 * HZ; | ||
668 | p_adap->retries = 3; | ||
680 | 669 | ||
681 | rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi"); | 670 | rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi"); |
682 | if (rc) { | 671 | if (rc) { |
@@ -693,13 +682,13 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) | |||
693 | } | 682 | } |
694 | 683 | ||
695 | /* Set TWI internal clock as 10MHz */ | 684 | /* Set TWI internal clock as 10MHz */ |
696 | write_CONTROL(iface, ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F); | 685 | write_CONTROL(iface, ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F); |
697 | 686 | ||
698 | /* | 687 | /* |
699 | * We will not end up with a CLKDIV=0 because no one will specify | 688 | * We will not end up with a CLKDIV=0 because no one will specify |
700 | * 20kHz SCL or less in Kconfig now. (5 * 1024 / 20 = 0x100) | 689 | * 20kHz SCL or less in Kconfig now. (5 * 1000 / 20 = 250) |
701 | */ | 690 | */ |
702 | clkhilow = 5 * 1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ; | 691 | clkhilow = ((10 * 1000 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ) + 1) / 2; |
703 | 692 | ||
704 | /* Set Twi interface clock as specified */ | 693 | /* Set Twi interface clock as specified */ |
705 | write_CLKDIV(iface, (clkhilow << 8) | clkhilow); | 694 | write_CLKDIV(iface, (clkhilow << 8) | clkhilow); |
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c index 9c2e10082b79..f2de3be35df3 100644 --- a/drivers/i2c/busses/i2c-cpm.c +++ b/drivers/i2c/busses/i2c-cpm.c | |||
@@ -105,7 +105,7 @@ struct i2c_reg { | |||
105 | 105 | ||
106 | struct cpm_i2c { | 106 | struct cpm_i2c { |
107 | char *base; | 107 | char *base; |
108 | struct of_device *ofdev; | 108 | struct platform_device *ofdev; |
109 | struct i2c_adapter adap; | 109 | struct i2c_adapter adap; |
110 | uint dp_addr; | 110 | uint dp_addr; |
111 | int version; /* CPM1=1, CPM2=2 */ | 111 | int version; /* CPM1=1, CPM2=2 */ |
@@ -428,7 +428,7 @@ static const struct i2c_adapter cpm_ops = { | |||
428 | 428 | ||
429 | static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) | 429 | static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) |
430 | { | 430 | { |
431 | struct of_device *ofdev = cpm->ofdev; | 431 | struct platform_device *ofdev = cpm->ofdev; |
432 | const u32 *data; | 432 | const u32 *data; |
433 | int len, ret, i; | 433 | int len, ret, i; |
434 | void __iomem *i2c_base; | 434 | void __iomem *i2c_base; |
@@ -440,8 +440,8 @@ static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) | |||
440 | 440 | ||
441 | init_waitqueue_head(&cpm->i2c_wait); | 441 | init_waitqueue_head(&cpm->i2c_wait); |
442 | 442 | ||
443 | cpm->irq = of_irq_to_resource(ofdev->node, 0, NULL); | 443 | cpm->irq = of_irq_to_resource(ofdev->dev.of_node, 0, NULL); |
444 | if (cpm->irq == NO_IRQ) | 444 | if (!cpm->irq) |
445 | return -EINVAL; | 445 | return -EINVAL; |
446 | 446 | ||
447 | /* Install interrupt handler. */ | 447 | /* Install interrupt handler. */ |
@@ -451,13 +451,13 @@ static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) | |||
451 | return ret; | 451 | return ret; |
452 | 452 | ||
453 | /* I2C parameter RAM */ | 453 | /* I2C parameter RAM */ |
454 | i2c_base = of_iomap(ofdev->node, 1); | 454 | i2c_base = of_iomap(ofdev->dev.of_node, 1); |
455 | if (i2c_base == NULL) { | 455 | if (i2c_base == NULL) { |
456 | ret = -EINVAL; | 456 | ret = -EINVAL; |
457 | goto out_irq; | 457 | goto out_irq; |
458 | } | 458 | } |
459 | 459 | ||
460 | if (of_device_is_compatible(ofdev->node, "fsl,cpm1-i2c")) { | 460 | if (of_device_is_compatible(ofdev->dev.of_node, "fsl,cpm1-i2c")) { |
461 | 461 | ||
462 | /* Check for and use a microcode relocation patch. */ | 462 | /* Check for and use a microcode relocation patch. */ |
463 | cpm->i2c_ram = i2c_base; | 463 | cpm->i2c_ram = i2c_base; |
@@ -474,7 +474,7 @@ static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) | |||
474 | 474 | ||
475 | cpm->version = 1; | 475 | cpm->version = 1; |
476 | 476 | ||
477 | } else if (of_device_is_compatible(ofdev->node, "fsl,cpm2-i2c")) { | 477 | } else if (of_device_is_compatible(ofdev->dev.of_node, "fsl,cpm2-i2c")) { |
478 | cpm->i2c_addr = cpm_muram_alloc(sizeof(struct i2c_ram), 64); | 478 | cpm->i2c_addr = cpm_muram_alloc(sizeof(struct i2c_ram), 64); |
479 | cpm->i2c_ram = cpm_muram_addr(cpm->i2c_addr); | 479 | cpm->i2c_ram = cpm_muram_addr(cpm->i2c_addr); |
480 | out_be16(i2c_base, cpm->i2c_addr); | 480 | out_be16(i2c_base, cpm->i2c_addr); |
@@ -489,24 +489,24 @@ static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) | |||
489 | } | 489 | } |
490 | 490 | ||
491 | /* I2C control/status registers */ | 491 | /* I2C control/status registers */ |
492 | cpm->i2c_reg = of_iomap(ofdev->node, 0); | 492 | cpm->i2c_reg = of_iomap(ofdev->dev.of_node, 0); |
493 | if (cpm->i2c_reg == NULL) { | 493 | if (cpm->i2c_reg == NULL) { |
494 | ret = -EINVAL; | 494 | ret = -EINVAL; |
495 | goto out_ram; | 495 | goto out_ram; |
496 | } | 496 | } |
497 | 497 | ||
498 | data = of_get_property(ofdev->node, "fsl,cpm-command", &len); | 498 | data = of_get_property(ofdev->dev.of_node, "fsl,cpm-command", &len); |
499 | if (!data || len != 4) { | 499 | if (!data || len != 4) { |
500 | ret = -EINVAL; | 500 | ret = -EINVAL; |
501 | goto out_reg; | 501 | goto out_reg; |
502 | } | 502 | } |
503 | cpm->cp_command = *data; | 503 | cpm->cp_command = *data; |
504 | 504 | ||
505 | data = of_get_property(ofdev->node, "linux,i2c-class", &len); | 505 | data = of_get_property(ofdev->dev.of_node, "linux,i2c-class", &len); |
506 | if (data && len == 4) | 506 | if (data && len == 4) |
507 | cpm->adap.class = *data; | 507 | cpm->adap.class = *data; |
508 | 508 | ||
509 | data = of_get_property(ofdev->node, "clock-frequency", &len); | 509 | data = of_get_property(ofdev->dev.of_node, "clock-frequency", &len); |
510 | if (data && len == 4) | 510 | if (data && len == 4) |
511 | cpm->freq = *data; | 511 | cpm->freq = *data; |
512 | else | 512 | else |
@@ -634,7 +634,7 @@ static void cpm_i2c_shutdown(struct cpm_i2c *cpm) | |||
634 | cpm_muram_free(cpm->i2c_addr); | 634 | cpm_muram_free(cpm->i2c_addr); |
635 | } | 635 | } |
636 | 636 | ||
637 | static int __devinit cpm_i2c_probe(struct of_device *ofdev, | 637 | static int __devinit cpm_i2c_probe(struct platform_device *ofdev, |
638 | const struct of_device_id *match) | 638 | const struct of_device_id *match) |
639 | { | 639 | { |
640 | int result, len; | 640 | int result, len; |
@@ -652,6 +652,7 @@ static int __devinit cpm_i2c_probe(struct of_device *ofdev, | |||
652 | cpm->adap = cpm_ops; | 652 | cpm->adap = cpm_ops; |
653 | i2c_set_adapdata(&cpm->adap, cpm); | 653 | i2c_set_adapdata(&cpm->adap, cpm); |
654 | cpm->adap.dev.parent = &ofdev->dev; | 654 | cpm->adap.dev.parent = &ofdev->dev; |
655 | cpm->adap.dev.of_node = of_node_get(ofdev->dev.of_node); | ||
655 | 656 | ||
656 | result = cpm_i2c_setup(cpm); | 657 | result = cpm_i2c_setup(cpm); |
657 | if (result) { | 658 | if (result) { |
@@ -661,7 +662,7 @@ static int __devinit cpm_i2c_probe(struct of_device *ofdev, | |||
661 | 662 | ||
662 | /* register new adapter to i2c module... */ | 663 | /* register new adapter to i2c module... */ |
663 | 664 | ||
664 | data = of_get_property(ofdev->node, "linux,i2c-index", &len); | 665 | data = of_get_property(ofdev->dev.of_node, "linux,i2c-index", &len); |
665 | if (data && len == 4) { | 666 | if (data && len == 4) { |
666 | cpm->adap.nr = *data; | 667 | cpm->adap.nr = *data; |
667 | result = i2c_add_numbered_adapter(&cpm->adap); | 668 | result = i2c_add_numbered_adapter(&cpm->adap); |
@@ -679,7 +680,7 @@ static int __devinit cpm_i2c_probe(struct of_device *ofdev, | |||
679 | /* | 680 | /* |
680 | * register OF I2C devices | 681 | * register OF I2C devices |
681 | */ | 682 | */ |
682 | of_register_i2c_devices(&cpm->adap, ofdev->node); | 683 | of_i2c_register_devices(&cpm->adap); |
683 | 684 | ||
684 | return 0; | 685 | return 0; |
685 | out_shut: | 686 | out_shut: |
@@ -691,7 +692,7 @@ out_free: | |||
691 | return result; | 692 | return result; |
692 | } | 693 | } |
693 | 694 | ||
694 | static int __devexit cpm_i2c_remove(struct of_device *ofdev) | 695 | static int __devexit cpm_i2c_remove(struct platform_device *ofdev) |
695 | { | 696 | { |
696 | struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev); | 697 | struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev); |
697 | 698 | ||
@@ -718,13 +719,13 @@ static const struct of_device_id cpm_i2c_match[] = { | |||
718 | MODULE_DEVICE_TABLE(of, cpm_i2c_match); | 719 | MODULE_DEVICE_TABLE(of, cpm_i2c_match); |
719 | 720 | ||
720 | static struct of_platform_driver cpm_i2c_driver = { | 721 | static struct of_platform_driver cpm_i2c_driver = { |
721 | .match_table = cpm_i2c_match, | ||
722 | .probe = cpm_i2c_probe, | 722 | .probe = cpm_i2c_probe, |
723 | .remove = __devexit_p(cpm_i2c_remove), | 723 | .remove = __devexit_p(cpm_i2c_remove), |
724 | .driver = { | 724 | .driver = { |
725 | .name = "fsl-i2c-cpm", | 725 | .name = "fsl-i2c-cpm", |
726 | .owner = THIS_MODULE, | 726 | .owner = THIS_MODULE, |
727 | } | 727 | .of_match_table = cpm_i2c_match, |
728 | }, | ||
728 | }; | 729 | }; |
729 | 730 | ||
730 | static int __init cpm_i2c_init(void) | 731 | static int __init cpm_i2c_init(void) |
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 3fae3a91ce5b..5795c8398c7c 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c | |||
@@ -35,14 +35,17 @@ | |||
35 | #include <linux/interrupt.h> | 35 | #include <linux/interrupt.h> |
36 | #include <linux/platform_device.h> | 36 | #include <linux/platform_device.h> |
37 | #include <linux/io.h> | 37 | #include <linux/io.h> |
38 | #include <linux/slab.h> | ||
39 | #include <linux/cpufreq.h> | ||
40 | #include <linux/gpio.h> | ||
38 | 41 | ||
39 | #include <mach/hardware.h> | 42 | #include <mach/hardware.h> |
40 | |||
41 | #include <mach/i2c.h> | 43 | #include <mach/i2c.h> |
42 | 44 | ||
43 | /* ----- global defines ----------------------------------------------- */ | 45 | /* ----- global defines ----------------------------------------------- */ |
44 | 46 | ||
45 | #define DAVINCI_I2C_TIMEOUT (1*HZ) | 47 | #define DAVINCI_I2C_TIMEOUT (1*HZ) |
48 | #define DAVINCI_I2C_MAX_TRIES 2 | ||
46 | #define I2C_DAVINCI_INTR_ALL (DAVINCI_I2C_IMR_AAS | \ | 49 | #define I2C_DAVINCI_INTR_ALL (DAVINCI_I2C_IMR_AAS | \ |
47 | DAVINCI_I2C_IMR_SCD | \ | 50 | DAVINCI_I2C_IMR_SCD | \ |
48 | DAVINCI_I2C_IMR_ARDY | \ | 51 | DAVINCI_I2C_IMR_ARDY | \ |
@@ -71,37 +74,29 @@ | |||
71 | #define DAVINCI_I2C_IVR_NACK 0x02 | 74 | #define DAVINCI_I2C_IVR_NACK 0x02 |
72 | #define DAVINCI_I2C_IVR_AL 0x01 | 75 | #define DAVINCI_I2C_IVR_AL 0x01 |
73 | 76 | ||
74 | #define DAVINCI_I2C_STR_BB (1 << 12) | 77 | #define DAVINCI_I2C_STR_BB BIT(12) |
75 | #define DAVINCI_I2C_STR_RSFULL (1 << 11) | 78 | #define DAVINCI_I2C_STR_RSFULL BIT(11) |
76 | #define DAVINCI_I2C_STR_SCD (1 << 5) | 79 | #define DAVINCI_I2C_STR_SCD BIT(5) |
77 | #define DAVINCI_I2C_STR_ARDY (1 << 2) | 80 | #define DAVINCI_I2C_STR_ARDY BIT(2) |
78 | #define DAVINCI_I2C_STR_NACK (1 << 1) | 81 | #define DAVINCI_I2C_STR_NACK BIT(1) |
79 | #define DAVINCI_I2C_STR_AL (1 << 0) | 82 | #define DAVINCI_I2C_STR_AL BIT(0) |
80 | 83 | ||
81 | #define DAVINCI_I2C_MDR_NACK (1 << 15) | 84 | #define DAVINCI_I2C_MDR_NACK BIT(15) |
82 | #define DAVINCI_I2C_MDR_STT (1 << 13) | 85 | #define DAVINCI_I2C_MDR_STT BIT(13) |
83 | #define DAVINCI_I2C_MDR_STP (1 << 11) | 86 | #define DAVINCI_I2C_MDR_STP BIT(11) |
84 | #define DAVINCI_I2C_MDR_MST (1 << 10) | 87 | #define DAVINCI_I2C_MDR_MST BIT(10) |
85 | #define DAVINCI_I2C_MDR_TRX (1 << 9) | 88 | #define DAVINCI_I2C_MDR_TRX BIT(9) |
86 | #define DAVINCI_I2C_MDR_XA (1 << 8) | 89 | #define DAVINCI_I2C_MDR_XA BIT(8) |
87 | #define DAVINCI_I2C_MDR_RM (1 << 7) | 90 | #define DAVINCI_I2C_MDR_RM BIT(7) |
88 | #define DAVINCI_I2C_MDR_IRS (1 << 5) | 91 | #define DAVINCI_I2C_MDR_IRS BIT(5) |
89 | 92 | ||
90 | #define DAVINCI_I2C_IMR_AAS (1 << 6) | 93 | #define DAVINCI_I2C_IMR_AAS BIT(6) |
91 | #define DAVINCI_I2C_IMR_SCD (1 << 5) | 94 | #define DAVINCI_I2C_IMR_SCD BIT(5) |
92 | #define DAVINCI_I2C_IMR_XRDY (1 << 4) | 95 | #define DAVINCI_I2C_IMR_XRDY BIT(4) |
93 | #define DAVINCI_I2C_IMR_RRDY (1 << 3) | 96 | #define DAVINCI_I2C_IMR_RRDY BIT(3) |
94 | #define DAVINCI_I2C_IMR_ARDY (1 << 2) | 97 | #define DAVINCI_I2C_IMR_ARDY BIT(2) |
95 | #define DAVINCI_I2C_IMR_NACK (1 << 1) | 98 | #define DAVINCI_I2C_IMR_NACK BIT(1) |
96 | #define DAVINCI_I2C_IMR_AL (1 << 0) | 99 | #define DAVINCI_I2C_IMR_AL BIT(0) |
97 | |||
98 | #define MOD_REG_BIT(val, mask, set) do { \ | ||
99 | if (set) { \ | ||
100 | val |= mask; \ | ||
101 | } else { \ | ||
102 | val &= ~mask; \ | ||
103 | } \ | ||
104 | } while (0) | ||
105 | 100 | ||
106 | struct davinci_i2c_dev { | 101 | struct davinci_i2c_dev { |
107 | struct device *dev; | 102 | struct device *dev; |
@@ -112,8 +107,13 @@ struct davinci_i2c_dev { | |||
112 | u8 *buf; | 107 | u8 *buf; |
113 | size_t buf_len; | 108 | size_t buf_len; |
114 | int irq; | 109 | int irq; |
110 | int stop; | ||
115 | u8 terminate; | 111 | u8 terminate; |
116 | struct i2c_adapter adapter; | 112 | struct i2c_adapter adapter; |
113 | #ifdef CONFIG_CPU_FREQ | ||
114 | struct completion xfr_complete; | ||
115 | struct notifier_block freq_transition; | ||
116 | #endif | ||
117 | }; | 117 | }; |
118 | 118 | ||
119 | /* default platform data to use if not supplied in the platform_device */ | 119 | /* default platform data to use if not supplied in the platform_device */ |
@@ -133,12 +133,59 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) | |||
133 | return __raw_readw(i2c_dev->base + reg); | 133 | return __raw_readw(i2c_dev->base + reg); |
134 | } | 134 | } |
135 | 135 | ||
136 | /* | 136 | /* Generate a pulse on the i2c clock pin. */ |
137 | * This functions configures I2C and brings I2C out of reset. | 137 | static void generic_i2c_clock_pulse(unsigned int scl_pin) |
138 | * This function is called during I2C init function. This function | 138 | { |
139 | * also gets called if I2C encounters any errors. | 139 | u16 i; |
140 | |||
141 | if (scl_pin) { | ||
142 | /* Send high and low on the SCL line */ | ||
143 | for (i = 0; i < 9; i++) { | ||
144 | gpio_set_value(scl_pin, 0); | ||
145 | udelay(20); | ||
146 | gpio_set_value(scl_pin, 1); | ||
147 | udelay(20); | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | /* This routine does i2c bus recovery as specified in the | ||
153 | * i2c protocol Rev. 03 section 3.16 titled "Bus clear" | ||
140 | */ | 154 | */ |
141 | static int i2c_davinci_init(struct davinci_i2c_dev *dev) | 155 | static void i2c_recover_bus(struct davinci_i2c_dev *dev) |
156 | { | ||
157 | u32 flag = 0; | ||
158 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | ||
159 | |||
160 | dev_err(dev->dev, "initiating i2c bus recovery\n"); | ||
161 | /* Send NACK to the slave */ | ||
162 | flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | ||
163 | flag |= DAVINCI_I2C_MDR_NACK; | ||
164 | /* write the data into mode register */ | ||
165 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); | ||
166 | if (pdata) | ||
167 | generic_i2c_clock_pulse(pdata->scl_pin); | ||
168 | /* Send STOP */ | ||
169 | flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | ||
170 | flag |= DAVINCI_I2C_MDR_STP; | ||
171 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); | ||
172 | } | ||
173 | |||
174 | static inline void davinci_i2c_reset_ctrl(struct davinci_i2c_dev *i2c_dev, | ||
175 | int val) | ||
176 | { | ||
177 | u16 w; | ||
178 | |||
179 | w = davinci_i2c_read_reg(i2c_dev, DAVINCI_I2C_MDR_REG); | ||
180 | if (!val) /* put I2C into reset */ | ||
181 | w &= ~DAVINCI_I2C_MDR_IRS; | ||
182 | else /* take I2C out of reset */ | ||
183 | w |= DAVINCI_I2C_MDR_IRS; | ||
184 | |||
185 | davinci_i2c_write_reg(i2c_dev, DAVINCI_I2C_MDR_REG, w); | ||
186 | } | ||
187 | |||
188 | static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev) | ||
142 | { | 189 | { |
143 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | 190 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; |
144 | u16 psc; | 191 | u16 psc; |
@@ -147,15 +194,6 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) | |||
147 | u32 clkh; | 194 | u32 clkh; |
148 | u32 clkl; | 195 | u32 clkl; |
149 | u32 input_clock = clk_get_rate(dev->clk); | 196 | u32 input_clock = clk_get_rate(dev->clk); |
150 | u16 w; | ||
151 | |||
152 | if (!pdata) | ||
153 | pdata = &davinci_i2c_platform_data_default; | ||
154 | |||
155 | /* put I2C into reset */ | ||
156 | w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | ||
157 | MOD_REG_BIT(w, DAVINCI_I2C_MDR_IRS, 0); | ||
158 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); | ||
159 | 197 | ||
160 | /* NOTE: I2C Clock divider programming info | 198 | /* NOTE: I2C Clock divider programming info |
161 | * As per I2C specs the following formulas provide prescaler | 199 | * As per I2C specs the following formulas provide prescaler |
@@ -188,6 +226,31 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) | |||
188 | davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl); | 226 | davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl); |
189 | 227 | ||
190 | dev_dbg(dev->dev, "input_clock = %d, CLK = %d\n", input_clock, clk); | 228 | dev_dbg(dev->dev, "input_clock = %d, CLK = %d\n", input_clock, clk); |
229 | } | ||
230 | |||
231 | /* | ||
232 | * This function configures I2C and brings I2C out of reset. | ||
233 | * This function is called during I2C init function. This function | ||
234 | * also gets called if I2C encounters any errors. | ||
235 | */ | ||
236 | static int i2c_davinci_init(struct davinci_i2c_dev *dev) | ||
237 | { | ||
238 | struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; | ||
239 | |||
240 | if (!pdata) | ||
241 | pdata = &davinci_i2c_platform_data_default; | ||
242 | |||
243 | /* put I2C into reset */ | ||
244 | davinci_i2c_reset_ctrl(dev, 0); | ||
245 | |||
246 | /* compute clock dividers */ | ||
247 | i2c_davinci_calc_clk_dividers(dev); | ||
248 | |||
249 | /* Respond at reserved "SMBus Host" slave address" (and zero); | ||
250 | * we seem to have no option to not respond... | ||
251 | */ | ||
252 | davinci_i2c_write_reg(dev, DAVINCI_I2C_OAR_REG, 0x08); | ||
253 | |||
191 | dev_dbg(dev->dev, "PSC = %d\n", | 254 | dev_dbg(dev->dev, "PSC = %d\n", |
192 | davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG)); | 255 | davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG)); |
193 | dev_dbg(dev->dev, "CLKL = %d\n", | 256 | dev_dbg(dev->dev, "CLKL = %d\n", |
@@ -198,9 +261,7 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) | |||
198 | pdata->bus_freq, pdata->bus_delay); | 261 | pdata->bus_freq, pdata->bus_delay); |
199 | 262 | ||
200 | /* Take the I2C module out of reset: */ | 263 | /* Take the I2C module out of reset: */ |
201 | w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | 264 | davinci_i2c_reset_ctrl(dev, 1); |
202 | MOD_REG_BIT(w, DAVINCI_I2C_MDR_IRS, 1); | ||
203 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); | ||
204 | 265 | ||
205 | /* Enable interrupts */ | 266 | /* Enable interrupts */ |
206 | davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, I2C_DAVINCI_INTR_ALL); | 267 | davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, I2C_DAVINCI_INTR_ALL); |
@@ -215,14 +276,22 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, | |||
215 | char allow_sleep) | 276 | char allow_sleep) |
216 | { | 277 | { |
217 | unsigned long timeout; | 278 | unsigned long timeout; |
279 | static u16 to_cnt; | ||
218 | 280 | ||
219 | timeout = jiffies + dev->adapter.timeout; | 281 | timeout = jiffies + dev->adapter.timeout; |
220 | while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) | 282 | while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) |
221 | & DAVINCI_I2C_STR_BB) { | 283 | & DAVINCI_I2C_STR_BB) { |
222 | if (time_after(jiffies, timeout)) { | 284 | if (to_cnt <= DAVINCI_I2C_MAX_TRIES) { |
223 | dev_warn(dev->dev, | 285 | if (time_after(jiffies, timeout)) { |
224 | "timeout waiting for bus ready\n"); | 286 | dev_warn(dev->dev, |
225 | return -ETIMEDOUT; | 287 | "timeout waiting for bus ready\n"); |
288 | to_cnt++; | ||
289 | return -ETIMEDOUT; | ||
290 | } else { | ||
291 | to_cnt = 0; | ||
292 | i2c_recover_bus(dev); | ||
293 | i2c_davinci_init(dev); | ||
294 | } | ||
226 | } | 295 | } |
227 | if (allow_sleep) | 296 | if (allow_sleep) |
228 | schedule_timeout(1); | 297 | schedule_timeout(1); |
@@ -244,9 +313,6 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) | |||
244 | u16 w; | 313 | u16 w; |
245 | int r; | 314 | int r; |
246 | 315 | ||
247 | if (msg->len == 0) | ||
248 | return -EINVAL; | ||
249 | |||
250 | if (!pdata) | 316 | if (!pdata) |
251 | pdata = &davinci_i2c_platform_data_default; | 317 | pdata = &davinci_i2c_platform_data_default; |
252 | /* Introduce a delay, required for some boards (e.g Davinci EVM) */ | 318 | /* Introduce a delay, required for some boards (e.g Davinci EVM) */ |
@@ -258,40 +324,64 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) | |||
258 | 324 | ||
259 | dev->buf = msg->buf; | 325 | dev->buf = msg->buf; |
260 | dev->buf_len = msg->len; | 326 | dev->buf_len = msg->len; |
327 | dev->stop = stop; | ||
261 | 328 | ||
262 | davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); | 329 | davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); |
263 | 330 | ||
264 | INIT_COMPLETION(dev->cmd_complete); | 331 | INIT_COMPLETION(dev->cmd_complete); |
265 | dev->cmd_err = 0; | 332 | dev->cmd_err = 0; |
266 | 333 | ||
267 | /* Take I2C out of reset, configure it as master and set the | 334 | /* Take I2C out of reset and configure it as master */ |
268 | * start bit */ | 335 | flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST; |
269 | flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST | DAVINCI_I2C_MDR_STT; | ||
270 | 336 | ||
271 | /* if the slave address is ten bit address, enable XA bit */ | 337 | /* if the slave address is ten bit address, enable XA bit */ |
272 | if (msg->flags & I2C_M_TEN) | 338 | if (msg->flags & I2C_M_TEN) |
273 | flag |= DAVINCI_I2C_MDR_XA; | 339 | flag |= DAVINCI_I2C_MDR_XA; |
274 | if (!(msg->flags & I2C_M_RD)) | 340 | if (!(msg->flags & I2C_M_RD)) |
275 | flag |= DAVINCI_I2C_MDR_TRX; | 341 | flag |= DAVINCI_I2C_MDR_TRX; |
276 | if (stop) | 342 | if (msg->len == 0) |
277 | flag |= DAVINCI_I2C_MDR_STP; | 343 | flag |= DAVINCI_I2C_MDR_RM; |
278 | 344 | ||
279 | /* Enable receive or transmit interrupts */ | 345 | /* Enable receive or transmit interrupts */ |
280 | w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); | 346 | w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); |
281 | if (msg->flags & I2C_M_RD) | 347 | if (msg->flags & I2C_M_RD) |
282 | MOD_REG_BIT(w, DAVINCI_I2C_IMR_RRDY, 1); | 348 | w |= DAVINCI_I2C_IMR_RRDY; |
283 | else | 349 | else |
284 | MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 1); | 350 | w |= DAVINCI_I2C_IMR_XRDY; |
285 | davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); | 351 | davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); |
286 | 352 | ||
287 | dev->terminate = 0; | 353 | dev->terminate = 0; |
288 | /* write the data into mode register */ | 354 | |
355 | /* | ||
356 | * Write mode register first as needed for correct behaviour | ||
357 | * on OMAP-L138, but don't set STT yet to avoid a race with XRDY | ||
358 | * occuring before we have loaded DXR | ||
359 | */ | ||
360 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); | ||
361 | |||
362 | /* | ||
363 | * First byte should be set here, not after interrupt, | ||
364 | * because transmit-data-ready interrupt can come before | ||
365 | * NACK-interrupt during sending of previous message and | ||
366 | * ICDXR may have wrong data | ||
367 | * It also saves us one interrupt, slightly faster | ||
368 | */ | ||
369 | if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) { | ||
370 | davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++); | ||
371 | dev->buf_len--; | ||
372 | } | ||
373 | |||
374 | /* Set STT to begin transmit now DXR is loaded */ | ||
375 | flag |= DAVINCI_I2C_MDR_STT; | ||
376 | if (stop && msg->len != 0) | ||
377 | flag |= DAVINCI_I2C_MDR_STP; | ||
289 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); | 378 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); |
290 | 379 | ||
291 | r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, | 380 | r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, |
292 | dev->adapter.timeout); | 381 | dev->adapter.timeout); |
293 | if (r == 0) { | 382 | if (r == 0) { |
294 | dev_err(dev->dev, "controller timed out\n"); | 383 | dev_err(dev->dev, "controller timed out\n"); |
384 | i2c_recover_bus(dev); | ||
295 | i2c_davinci_init(dev); | 385 | i2c_davinci_init(dev); |
296 | dev->buf_len = 0; | 386 | dev->buf_len = 0; |
297 | return -ETIMEDOUT; | 387 | return -ETIMEDOUT; |
@@ -328,7 +418,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) | |||
328 | return msg->len; | 418 | return msg->len; |
329 | if (stop) { | 419 | if (stop) { |
330 | w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); | 420 | w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); |
331 | MOD_REG_BIT(w, DAVINCI_I2C_MDR_STP, 1); | 421 | w |= DAVINCI_I2C_MDR_STP; |
332 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); | 422 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); |
333 | } | 423 | } |
334 | return -EREMOTEIO; | 424 | return -EREMOTEIO; |
@@ -361,12 +451,17 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
361 | if (ret < 0) | 451 | if (ret < 0) |
362 | return ret; | 452 | return ret; |
363 | } | 453 | } |
454 | |||
455 | #ifdef CONFIG_CPU_FREQ | ||
456 | complete(&dev->xfr_complete); | ||
457 | #endif | ||
458 | |||
364 | return num; | 459 | return num; |
365 | } | 460 | } |
366 | 461 | ||
367 | static u32 i2c_davinci_func(struct i2c_adapter *adap) | 462 | static u32 i2c_davinci_func(struct i2c_adapter *adap) |
368 | { | 463 | { |
369 | return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); | 464 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
370 | } | 465 | } |
371 | 466 | ||
372 | static void terminate_read(struct davinci_i2c_dev *dev) | 467 | static void terminate_read(struct davinci_i2c_dev *dev) |
@@ -387,7 +482,7 @@ static void terminate_write(struct davinci_i2c_dev *dev) | |||
387 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); | 482 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); |
388 | 483 | ||
389 | if (!dev->terminate) | 484 | if (!dev->terminate) |
390 | dev_err(dev->dev, "TDR IRQ while no data to send\n"); | 485 | dev_dbg(dev->dev, "TDR IRQ while no data to send\n"); |
391 | } | 486 | } |
392 | 487 | ||
393 | /* | 488 | /* |
@@ -425,6 +520,14 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) | |||
425 | case DAVINCI_I2C_IVR_ARDY: | 520 | case DAVINCI_I2C_IVR_ARDY: |
426 | davinci_i2c_write_reg(dev, | 521 | davinci_i2c_write_reg(dev, |
427 | DAVINCI_I2C_STR_REG, DAVINCI_I2C_STR_ARDY); | 522 | DAVINCI_I2C_STR_REG, DAVINCI_I2C_STR_ARDY); |
523 | if (((dev->buf_len == 0) && (dev->stop != 0)) || | ||
524 | (dev->cmd_err & DAVINCI_I2C_STR_NACK)) { | ||
525 | w = davinci_i2c_read_reg(dev, | ||
526 | DAVINCI_I2C_MDR_REG); | ||
527 | w |= DAVINCI_I2C_MDR_STP; | ||
528 | davinci_i2c_write_reg(dev, | ||
529 | DAVINCI_I2C_MDR_REG, w); | ||
530 | } | ||
428 | complete(&dev->cmd_complete); | 531 | complete(&dev->cmd_complete); |
429 | break; | 532 | break; |
430 | 533 | ||
@@ -456,7 +559,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) | |||
456 | 559 | ||
457 | w = davinci_i2c_read_reg(dev, | 560 | w = davinci_i2c_read_reg(dev, |
458 | DAVINCI_I2C_IMR_REG); | 561 | DAVINCI_I2C_IMR_REG); |
459 | MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 0); | 562 | w &= ~DAVINCI_I2C_IMR_XRDY; |
460 | davinci_i2c_write_reg(dev, | 563 | davinci_i2c_write_reg(dev, |
461 | DAVINCI_I2C_IMR_REG, | 564 | DAVINCI_I2C_IMR_REG, |
462 | w); | 565 | w); |
@@ -473,13 +576,60 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) | |||
473 | break; | 576 | break; |
474 | 577 | ||
475 | case DAVINCI_I2C_IVR_AAS: | 578 | case DAVINCI_I2C_IVR_AAS: |
476 | dev_warn(dev->dev, "Address as slave interrupt\n"); | 579 | dev_dbg(dev->dev, "Address as slave interrupt\n"); |
477 | }/* switch */ | 580 | break; |
478 | }/* while */ | 581 | |
582 | default: | ||
583 | dev_warn(dev->dev, "Unrecognized irq stat %d\n", stat); | ||
584 | break; | ||
585 | } | ||
586 | } | ||
479 | 587 | ||
480 | return count ? IRQ_HANDLED : IRQ_NONE; | 588 | return count ? IRQ_HANDLED : IRQ_NONE; |
481 | } | 589 | } |
482 | 590 | ||
591 | #ifdef CONFIG_CPU_FREQ | ||
592 | static int i2c_davinci_cpufreq_transition(struct notifier_block *nb, | ||
593 | unsigned long val, void *data) | ||
594 | { | ||
595 | struct davinci_i2c_dev *dev; | ||
596 | |||
597 | dev = container_of(nb, struct davinci_i2c_dev, freq_transition); | ||
598 | if (val == CPUFREQ_PRECHANGE) { | ||
599 | wait_for_completion(&dev->xfr_complete); | ||
600 | davinci_i2c_reset_ctrl(dev, 0); | ||
601 | } else if (val == CPUFREQ_POSTCHANGE) { | ||
602 | i2c_davinci_calc_clk_dividers(dev); | ||
603 | davinci_i2c_reset_ctrl(dev, 1); | ||
604 | } | ||
605 | |||
606 | return 0; | ||
607 | } | ||
608 | |||
609 | static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev) | ||
610 | { | ||
611 | dev->freq_transition.notifier_call = i2c_davinci_cpufreq_transition; | ||
612 | |||
613 | return cpufreq_register_notifier(&dev->freq_transition, | ||
614 | CPUFREQ_TRANSITION_NOTIFIER); | ||
615 | } | ||
616 | |||
617 | static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev) | ||
618 | { | ||
619 | cpufreq_unregister_notifier(&dev->freq_transition, | ||
620 | CPUFREQ_TRANSITION_NOTIFIER); | ||
621 | } | ||
622 | #else | ||
623 | static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev) | ||
624 | { | ||
625 | return 0; | ||
626 | } | ||
627 | |||
628 | static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev) | ||
629 | { | ||
630 | } | ||
631 | #endif | ||
632 | |||
483 | static struct i2c_algorithm i2c_davinci_algo = { | 633 | static struct i2c_algorithm i2c_davinci_algo = { |
484 | .master_xfer = i2c_davinci_xfer, | 634 | .master_xfer = i2c_davinci_xfer, |
485 | .functionality = i2c_davinci_func, | 635 | .functionality = i2c_davinci_func, |
@@ -505,7 +655,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
505 | return -ENODEV; | 655 | return -ENODEV; |
506 | } | 656 | } |
507 | 657 | ||
508 | ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1, | 658 | ioarea = request_mem_region(mem->start, resource_size(mem), |
509 | pdev->name); | 659 | pdev->name); |
510 | if (!ioarea) { | 660 | if (!ioarea) { |
511 | dev_err(&pdev->dev, "I2C region already claimed\n"); | 661 | dev_err(&pdev->dev, "I2C region already claimed\n"); |
@@ -519,18 +669,26 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
519 | } | 669 | } |
520 | 670 | ||
521 | init_completion(&dev->cmd_complete); | 671 | init_completion(&dev->cmd_complete); |
672 | #ifdef CONFIG_CPU_FREQ | ||
673 | init_completion(&dev->xfr_complete); | ||
674 | #endif | ||
522 | dev->dev = get_device(&pdev->dev); | 675 | dev->dev = get_device(&pdev->dev); |
523 | dev->irq = irq->start; | 676 | dev->irq = irq->start; |
524 | platform_set_drvdata(pdev, dev); | 677 | platform_set_drvdata(pdev, dev); |
525 | 678 | ||
526 | dev->clk = clk_get(&pdev->dev, "I2CCLK"); | 679 | dev->clk = clk_get(&pdev->dev, NULL); |
527 | if (IS_ERR(dev->clk)) { | 680 | if (IS_ERR(dev->clk)) { |
528 | r = -ENODEV; | 681 | r = -ENODEV; |
529 | goto err_free_mem; | 682 | goto err_free_mem; |
530 | } | 683 | } |
531 | clk_enable(dev->clk); | 684 | clk_enable(dev->clk); |
532 | 685 | ||
533 | dev->base = (void __iomem *)IO_ADDRESS(mem->start); | 686 | dev->base = ioremap(mem->start, resource_size(mem)); |
687 | if (!dev->base) { | ||
688 | r = -EBUSY; | ||
689 | goto err_mem_ioremap; | ||
690 | } | ||
691 | |||
534 | i2c_davinci_init(dev); | 692 | i2c_davinci_init(dev); |
535 | 693 | ||
536 | r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev); | 694 | r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev); |
@@ -539,6 +697,12 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
539 | goto err_unuse_clocks; | 697 | goto err_unuse_clocks; |
540 | } | 698 | } |
541 | 699 | ||
700 | r = i2c_davinci_cpufreq_register(dev); | ||
701 | if (r) { | ||
702 | dev_err(&pdev->dev, "failed to register cpufreq\n"); | ||
703 | goto err_free_irq; | ||
704 | } | ||
705 | |||
542 | adap = &dev->adapter; | 706 | adap = &dev->adapter; |
543 | i2c_set_adapdata(adap, dev); | 707 | i2c_set_adapdata(adap, dev); |
544 | adap->owner = THIS_MODULE; | 708 | adap->owner = THIS_MODULE; |
@@ -560,6 +724,8 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
560 | err_free_irq: | 724 | err_free_irq: |
561 | free_irq(dev->irq, dev); | 725 | free_irq(dev->irq, dev); |
562 | err_unuse_clocks: | 726 | err_unuse_clocks: |
727 | iounmap(dev->base); | ||
728 | err_mem_ioremap: | ||
563 | clk_disable(dev->clk); | 729 | clk_disable(dev->clk); |
564 | clk_put(dev->clk); | 730 | clk_put(dev->clk); |
565 | dev->clk = NULL; | 731 | dev->clk = NULL; |
@@ -568,7 +734,7 @@ err_free_mem: | |||
568 | put_device(&pdev->dev); | 734 | put_device(&pdev->dev); |
569 | kfree(dev); | 735 | kfree(dev); |
570 | err_release_region: | 736 | err_release_region: |
571 | release_mem_region(mem->start, (mem->end - mem->start) + 1); | 737 | release_mem_region(mem->start, resource_size(mem)); |
572 | 738 | ||
573 | return r; | 739 | return r; |
574 | } | 740 | } |
@@ -578,6 +744,8 @@ static int davinci_i2c_remove(struct platform_device *pdev) | |||
578 | struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); | 744 | struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); |
579 | struct resource *mem; | 745 | struct resource *mem; |
580 | 746 | ||
747 | i2c_davinci_cpufreq_deregister(dev); | ||
748 | |||
581 | platform_set_drvdata(pdev, NULL); | 749 | platform_set_drvdata(pdev, NULL); |
582 | i2c_del_adapter(&dev->adapter); | 750 | i2c_del_adapter(&dev->adapter); |
583 | put_device(&pdev->dev); | 751 | put_device(&pdev->dev); |
@@ -588,13 +756,49 @@ static int davinci_i2c_remove(struct platform_device *pdev) | |||
588 | 756 | ||
589 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); | 757 | davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); |
590 | free_irq(IRQ_I2C, dev); | 758 | free_irq(IRQ_I2C, dev); |
759 | iounmap(dev->base); | ||
591 | kfree(dev); | 760 | kfree(dev); |
592 | 761 | ||
593 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 762 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
594 | release_mem_region(mem->start, (mem->end - mem->start) + 1); | 763 | release_mem_region(mem->start, resource_size(mem)); |
595 | return 0; | 764 | return 0; |
596 | } | 765 | } |
597 | 766 | ||
767 | #ifdef CONFIG_PM | ||
768 | static int davinci_i2c_suspend(struct device *dev) | ||
769 | { | ||
770 | struct platform_device *pdev = to_platform_device(dev); | ||
771 | struct davinci_i2c_dev *i2c_dev = platform_get_drvdata(pdev); | ||
772 | |||
773 | /* put I2C into reset */ | ||
774 | davinci_i2c_reset_ctrl(i2c_dev, 0); | ||
775 | clk_disable(i2c_dev->clk); | ||
776 | |||
777 | return 0; | ||
778 | } | ||
779 | |||
780 | static int davinci_i2c_resume(struct device *dev) | ||
781 | { | ||
782 | struct platform_device *pdev = to_platform_device(dev); | ||
783 | struct davinci_i2c_dev *i2c_dev = platform_get_drvdata(pdev); | ||
784 | |||
785 | clk_enable(i2c_dev->clk); | ||
786 | /* take I2C out of reset */ | ||
787 | davinci_i2c_reset_ctrl(i2c_dev, 1); | ||
788 | |||
789 | return 0; | ||
790 | } | ||
791 | |||
792 | static const struct dev_pm_ops davinci_i2c_pm = { | ||
793 | .suspend = davinci_i2c_suspend, | ||
794 | .resume = davinci_i2c_resume, | ||
795 | }; | ||
796 | |||
797 | #define davinci_i2c_pm_ops (&davinci_i2c_pm) | ||
798 | #else | ||
799 | #define davinci_i2c_pm_ops NULL | ||
800 | #endif | ||
801 | |||
598 | /* work with hotplug and coldplug */ | 802 | /* work with hotplug and coldplug */ |
599 | MODULE_ALIAS("platform:i2c_davinci"); | 803 | MODULE_ALIAS("platform:i2c_davinci"); |
600 | 804 | ||
@@ -604,6 +808,7 @@ static struct platform_driver davinci_i2c_driver = { | |||
604 | .driver = { | 808 | .driver = { |
605 | .name = "i2c_davinci", | 809 | .name = "i2c_davinci", |
606 | .owner = THIS_MODULE, | 810 | .owner = THIS_MODULE, |
811 | .pm = davinci_i2c_pm_ops, | ||
607 | }, | 812 | }, |
608 | }; | 813 | }; |
609 | 814 | ||
diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c new file mode 100644 index 000000000000..b664ed8bbdb3 --- /dev/null +++ b/drivers/i2c/busses/i2c-designware.c | |||
@@ -0,0 +1,847 @@ | |||
1 | /* | ||
2 | * Synopsys DesignWare I2C adapter driver (master only). | ||
3 | * | ||
4 | * Based on the TI DAVINCI I2C adapter driver. | ||
5 | * | ||
6 | * Copyright (C) 2006 Texas Instruments. | ||
7 | * Copyright (C) 2007 MontaVista Software Inc. | ||
8 | * Copyright (C) 2009 Provigent Ltd. | ||
9 | * | ||
10 | * ---------------------------------------------------------------------------- | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | * ---------------------------------------------------------------------------- | ||
26 | * | ||
27 | */ | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/i2c.h> | ||
32 | #include <linux/clk.h> | ||
33 | #include <linux/errno.h> | ||
34 | #include <linux/sched.h> | ||
35 | #include <linux/err.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/platform_device.h> | ||
38 | #include <linux/io.h> | ||
39 | #include <linux/slab.h> | ||
40 | |||
41 | /* | ||
42 | * Registers offset | ||
43 | */ | ||
44 | #define DW_IC_CON 0x0 | ||
45 | #define DW_IC_TAR 0x4 | ||
46 | #define DW_IC_DATA_CMD 0x10 | ||
47 | #define DW_IC_SS_SCL_HCNT 0x14 | ||
48 | #define DW_IC_SS_SCL_LCNT 0x18 | ||
49 | #define DW_IC_FS_SCL_HCNT 0x1c | ||
50 | #define DW_IC_FS_SCL_LCNT 0x20 | ||
51 | #define DW_IC_INTR_STAT 0x2c | ||
52 | #define DW_IC_INTR_MASK 0x30 | ||
53 | #define DW_IC_RAW_INTR_STAT 0x34 | ||
54 | #define DW_IC_RX_TL 0x38 | ||
55 | #define DW_IC_TX_TL 0x3c | ||
56 | #define DW_IC_CLR_INTR 0x40 | ||
57 | #define DW_IC_CLR_RX_UNDER 0x44 | ||
58 | #define DW_IC_CLR_RX_OVER 0x48 | ||
59 | #define DW_IC_CLR_TX_OVER 0x4c | ||
60 | #define DW_IC_CLR_RD_REQ 0x50 | ||
61 | #define DW_IC_CLR_TX_ABRT 0x54 | ||
62 | #define DW_IC_CLR_RX_DONE 0x58 | ||
63 | #define DW_IC_CLR_ACTIVITY 0x5c | ||
64 | #define DW_IC_CLR_STOP_DET 0x60 | ||
65 | #define DW_IC_CLR_START_DET 0x64 | ||
66 | #define DW_IC_CLR_GEN_CALL 0x68 | ||
67 | #define DW_IC_ENABLE 0x6c | ||
68 | #define DW_IC_STATUS 0x70 | ||
69 | #define DW_IC_TXFLR 0x74 | ||
70 | #define DW_IC_RXFLR 0x78 | ||
71 | #define DW_IC_COMP_PARAM_1 0xf4 | ||
72 | #define DW_IC_TX_ABRT_SOURCE 0x80 | ||
73 | |||
74 | #define DW_IC_CON_MASTER 0x1 | ||
75 | #define DW_IC_CON_SPEED_STD 0x2 | ||
76 | #define DW_IC_CON_SPEED_FAST 0x4 | ||
77 | #define DW_IC_CON_10BITADDR_MASTER 0x10 | ||
78 | #define DW_IC_CON_RESTART_EN 0x20 | ||
79 | #define DW_IC_CON_SLAVE_DISABLE 0x40 | ||
80 | |||
81 | #define DW_IC_INTR_RX_UNDER 0x001 | ||
82 | #define DW_IC_INTR_RX_OVER 0x002 | ||
83 | #define DW_IC_INTR_RX_FULL 0x004 | ||
84 | #define DW_IC_INTR_TX_OVER 0x008 | ||
85 | #define DW_IC_INTR_TX_EMPTY 0x010 | ||
86 | #define DW_IC_INTR_RD_REQ 0x020 | ||
87 | #define DW_IC_INTR_TX_ABRT 0x040 | ||
88 | #define DW_IC_INTR_RX_DONE 0x080 | ||
89 | #define DW_IC_INTR_ACTIVITY 0x100 | ||
90 | #define DW_IC_INTR_STOP_DET 0x200 | ||
91 | #define DW_IC_INTR_START_DET 0x400 | ||
92 | #define DW_IC_INTR_GEN_CALL 0x800 | ||
93 | |||
94 | #define DW_IC_INTR_DEFAULT_MASK (DW_IC_INTR_RX_FULL | \ | ||
95 | DW_IC_INTR_TX_EMPTY | \ | ||
96 | DW_IC_INTR_TX_ABRT | \ | ||
97 | DW_IC_INTR_STOP_DET) | ||
98 | |||
99 | #define DW_IC_STATUS_ACTIVITY 0x1 | ||
100 | |||
101 | #define DW_IC_ERR_TX_ABRT 0x1 | ||
102 | |||
103 | /* | ||
104 | * status codes | ||
105 | */ | ||
106 | #define STATUS_IDLE 0x0 | ||
107 | #define STATUS_WRITE_IN_PROGRESS 0x1 | ||
108 | #define STATUS_READ_IN_PROGRESS 0x2 | ||
109 | |||
110 | #define TIMEOUT 20 /* ms */ | ||
111 | |||
112 | /* | ||
113 | * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register | ||
114 | * | ||
115 | * only expected abort codes are listed here | ||
116 | * refer to the datasheet for the full list | ||
117 | */ | ||
118 | #define ABRT_7B_ADDR_NOACK 0 | ||
119 | #define ABRT_10ADDR1_NOACK 1 | ||
120 | #define ABRT_10ADDR2_NOACK 2 | ||
121 | #define ABRT_TXDATA_NOACK 3 | ||
122 | #define ABRT_GCALL_NOACK 4 | ||
123 | #define ABRT_GCALL_READ 5 | ||
124 | #define ABRT_SBYTE_ACKDET 7 | ||
125 | #define ABRT_SBYTE_NORSTRT 9 | ||
126 | #define ABRT_10B_RD_NORSTRT 10 | ||
127 | #define ABRT_MASTER_DIS 11 | ||
128 | #define ARB_LOST 12 | ||
129 | |||
130 | #define DW_IC_TX_ABRT_7B_ADDR_NOACK (1UL << ABRT_7B_ADDR_NOACK) | ||
131 | #define DW_IC_TX_ABRT_10ADDR1_NOACK (1UL << ABRT_10ADDR1_NOACK) | ||
132 | #define DW_IC_TX_ABRT_10ADDR2_NOACK (1UL << ABRT_10ADDR2_NOACK) | ||
133 | #define DW_IC_TX_ABRT_TXDATA_NOACK (1UL << ABRT_TXDATA_NOACK) | ||
134 | #define DW_IC_TX_ABRT_GCALL_NOACK (1UL << ABRT_GCALL_NOACK) | ||
135 | #define DW_IC_TX_ABRT_GCALL_READ (1UL << ABRT_GCALL_READ) | ||
136 | #define DW_IC_TX_ABRT_SBYTE_ACKDET (1UL << ABRT_SBYTE_ACKDET) | ||
137 | #define DW_IC_TX_ABRT_SBYTE_NORSTRT (1UL << ABRT_SBYTE_NORSTRT) | ||
138 | #define DW_IC_TX_ABRT_10B_RD_NORSTRT (1UL << ABRT_10B_RD_NORSTRT) | ||
139 | #define DW_IC_TX_ABRT_MASTER_DIS (1UL << ABRT_MASTER_DIS) | ||
140 | #define DW_IC_TX_ARB_LOST (1UL << ARB_LOST) | ||
141 | |||
142 | #define DW_IC_TX_ABRT_NOACK (DW_IC_TX_ABRT_7B_ADDR_NOACK | \ | ||
143 | DW_IC_TX_ABRT_10ADDR1_NOACK | \ | ||
144 | DW_IC_TX_ABRT_10ADDR2_NOACK | \ | ||
145 | DW_IC_TX_ABRT_TXDATA_NOACK | \ | ||
146 | DW_IC_TX_ABRT_GCALL_NOACK) | ||
147 | |||
148 | static char *abort_sources[] = { | ||
149 | [ABRT_7B_ADDR_NOACK] = | ||
150 | "slave address not acknowledged (7bit mode)", | ||
151 | [ABRT_10ADDR1_NOACK] = | ||
152 | "first address byte not acknowledged (10bit mode)", | ||
153 | [ABRT_10ADDR2_NOACK] = | ||
154 | "second address byte not acknowledged (10bit mode)", | ||
155 | [ABRT_TXDATA_NOACK] = | ||
156 | "data not acknowledged", | ||
157 | [ABRT_GCALL_NOACK] = | ||
158 | "no acknowledgement for a general call", | ||
159 | [ABRT_GCALL_READ] = | ||
160 | "read after general call", | ||
161 | [ABRT_SBYTE_ACKDET] = | ||
162 | "start byte acknowledged", | ||
163 | [ABRT_SBYTE_NORSTRT] = | ||
164 | "trying to send start byte when restart is disabled", | ||
165 | [ABRT_10B_RD_NORSTRT] = | ||
166 | "trying to read when restart is disabled (10bit mode)", | ||
167 | [ABRT_MASTER_DIS] = | ||
168 | "trying to use disabled adapter", | ||
169 | [ARB_LOST] = | ||
170 | "lost arbitration", | ||
171 | }; | ||
172 | |||
173 | /** | ||
174 | * struct dw_i2c_dev - private i2c-designware data | ||
175 | * @dev: driver model device node | ||
176 | * @base: IO registers pointer | ||
177 | * @cmd_complete: tx completion indicator | ||
178 | * @lock: protect this struct and IO registers | ||
179 | * @clk: input reference clock | ||
180 | * @cmd_err: run time hadware error code | ||
181 | * @msgs: points to an array of messages currently being transfered | ||
182 | * @msgs_num: the number of elements in msgs | ||
183 | * @msg_write_idx: the element index of the current tx message in the msgs | ||
184 | * array | ||
185 | * @tx_buf_len: the length of the current tx buffer | ||
186 | * @tx_buf: the current tx buffer | ||
187 | * @msg_read_idx: the element index of the current rx message in the msgs | ||
188 | * array | ||
189 | * @rx_buf_len: the length of the current rx buffer | ||
190 | * @rx_buf: the current rx buffer | ||
191 | * @msg_err: error status of the current transfer | ||
192 | * @status: i2c master status, one of STATUS_* | ||
193 | * @abort_source: copy of the TX_ABRT_SOURCE register | ||
194 | * @irq: interrupt number for the i2c master | ||
195 | * @adapter: i2c subsystem adapter node | ||
196 | * @tx_fifo_depth: depth of the hardware tx fifo | ||
197 | * @rx_fifo_depth: depth of the hardware rx fifo | ||
198 | */ | ||
199 | struct dw_i2c_dev { | ||
200 | struct device *dev; | ||
201 | void __iomem *base; | ||
202 | struct completion cmd_complete; | ||
203 | struct mutex lock; | ||
204 | struct clk *clk; | ||
205 | int cmd_err; | ||
206 | struct i2c_msg *msgs; | ||
207 | int msgs_num; | ||
208 | int msg_write_idx; | ||
209 | u32 tx_buf_len; | ||
210 | u8 *tx_buf; | ||
211 | int msg_read_idx; | ||
212 | u32 rx_buf_len; | ||
213 | u8 *rx_buf; | ||
214 | int msg_err; | ||
215 | unsigned int status; | ||
216 | u32 abort_source; | ||
217 | int irq; | ||
218 | struct i2c_adapter adapter; | ||
219 | unsigned int tx_fifo_depth; | ||
220 | unsigned int rx_fifo_depth; | ||
221 | }; | ||
222 | |||
223 | static u32 | ||
224 | i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) | ||
225 | { | ||
226 | /* | ||
227 | * DesignWare I2C core doesn't seem to have solid strategy to meet | ||
228 | * the tHD;STA timing spec. Configuring _HCNT based on tHIGH spec | ||
229 | * will result in violation of the tHD;STA spec. | ||
230 | */ | ||
231 | if (cond) | ||
232 | /* | ||
233 | * Conditional expression: | ||
234 | * | ||
235 | * IC_[FS]S_SCL_HCNT + (1+4+3) >= IC_CLK * tHIGH | ||
236 | * | ||
237 | * This is based on the DW manuals, and represents an ideal | ||
238 | * configuration. The resulting I2C bus speed will be | ||
239 | * faster than any of the others. | ||
240 | * | ||
241 | * If your hardware is free from tHD;STA issue, try this one. | ||
242 | */ | ||
243 | return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset; | ||
244 | else | ||
245 | /* | ||
246 | * Conditional expression: | ||
247 | * | ||
248 | * IC_[FS]S_SCL_HCNT + 3 >= IC_CLK * (tHD;STA + tf) | ||
249 | * | ||
250 | * This is just experimental rule; the tHD;STA period turned | ||
251 | * out to be proportinal to (_HCNT + 3). With this setting, | ||
252 | * we could meet both tHIGH and tHD;STA timing specs. | ||
253 | * | ||
254 | * If unsure, you'd better to take this alternative. | ||
255 | * | ||
256 | * The reason why we need to take into account "tf" here, | ||
257 | * is the same as described in i2c_dw_scl_lcnt(). | ||
258 | */ | ||
259 | return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset; | ||
260 | } | ||
261 | |||
262 | static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) | ||
263 | { | ||
264 | /* | ||
265 | * Conditional expression: | ||
266 | * | ||
267 | * IC_[FS]S_SCL_LCNT + 1 >= IC_CLK * (tLOW + tf) | ||
268 | * | ||
269 | * DW I2C core starts counting the SCL CNTs for the LOW period | ||
270 | * of the SCL clock (tLOW) as soon as it pulls the SCL line. | ||
271 | * In order to meet the tLOW timing spec, we need to take into | ||
272 | * account the fall time of SCL signal (tf). Default tf value | ||
273 | * should be 0.3 us, for safety. | ||
274 | */ | ||
275 | return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset; | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * i2c_dw_init() - initialize the designware i2c master hardware | ||
280 | * @dev: device private data | ||
281 | * | ||
282 | * This functions configures and enables the I2C master. | ||
283 | * This function is called during I2C init function, and in case of timeout at | ||
284 | * run time. | ||
285 | */ | ||
286 | static void i2c_dw_init(struct dw_i2c_dev *dev) | ||
287 | { | ||
288 | u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; | ||
289 | u32 ic_con, hcnt, lcnt; | ||
290 | |||
291 | /* Disable the adapter */ | ||
292 | writel(0, dev->base + DW_IC_ENABLE); | ||
293 | |||
294 | /* set standard and fast speed deviders for high/low periods */ | ||
295 | |||
296 | /* Standard-mode */ | ||
297 | hcnt = i2c_dw_scl_hcnt(input_clock_khz, | ||
298 | 40, /* tHD;STA = tHIGH = 4.0 us */ | ||
299 | 3, /* tf = 0.3 us */ | ||
300 | 0, /* 0: DW default, 1: Ideal */ | ||
301 | 0); /* No offset */ | ||
302 | lcnt = i2c_dw_scl_lcnt(input_clock_khz, | ||
303 | 47, /* tLOW = 4.7 us */ | ||
304 | 3, /* tf = 0.3 us */ | ||
305 | 0); /* No offset */ | ||
306 | writel(hcnt, dev->base + DW_IC_SS_SCL_HCNT); | ||
307 | writel(lcnt, dev->base + DW_IC_SS_SCL_LCNT); | ||
308 | dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); | ||
309 | |||
310 | /* Fast-mode */ | ||
311 | hcnt = i2c_dw_scl_hcnt(input_clock_khz, | ||
312 | 6, /* tHD;STA = tHIGH = 0.6 us */ | ||
313 | 3, /* tf = 0.3 us */ | ||
314 | 0, /* 0: DW default, 1: Ideal */ | ||
315 | 0); /* No offset */ | ||
316 | lcnt = i2c_dw_scl_lcnt(input_clock_khz, | ||
317 | 13, /* tLOW = 1.3 us */ | ||
318 | 3, /* tf = 0.3 us */ | ||
319 | 0); /* No offset */ | ||
320 | writel(hcnt, dev->base + DW_IC_FS_SCL_HCNT); | ||
321 | writel(lcnt, dev->base + DW_IC_FS_SCL_LCNT); | ||
322 | dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); | ||
323 | |||
324 | /* Configure Tx/Rx FIFO threshold levels */ | ||
325 | writel(dev->tx_fifo_depth - 1, dev->base + DW_IC_TX_TL); | ||
326 | writel(0, dev->base + DW_IC_RX_TL); | ||
327 | |||
328 | /* configure the i2c master */ | ||
329 | ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | | ||
330 | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; | ||
331 | writel(ic_con, dev->base + DW_IC_CON); | ||
332 | } | ||
333 | |||
334 | /* | ||
335 | * Waiting for bus not busy | ||
336 | */ | ||
337 | static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) | ||
338 | { | ||
339 | int timeout = TIMEOUT; | ||
340 | |||
341 | while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { | ||
342 | if (timeout <= 0) { | ||
343 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); | ||
344 | return -ETIMEDOUT; | ||
345 | } | ||
346 | timeout--; | ||
347 | mdelay(1); | ||
348 | } | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) | ||
354 | { | ||
355 | struct i2c_msg *msgs = dev->msgs; | ||
356 | u32 ic_con; | ||
357 | |||
358 | /* Disable the adapter */ | ||
359 | writel(0, dev->base + DW_IC_ENABLE); | ||
360 | |||
361 | /* set the slave (target) address */ | ||
362 | writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR); | ||
363 | |||
364 | /* if the slave address is ten bit address, enable 10BITADDR */ | ||
365 | ic_con = readl(dev->base + DW_IC_CON); | ||
366 | if (msgs[dev->msg_write_idx].flags & I2C_M_TEN) | ||
367 | ic_con |= DW_IC_CON_10BITADDR_MASTER; | ||
368 | else | ||
369 | ic_con &= ~DW_IC_CON_10BITADDR_MASTER; | ||
370 | writel(ic_con, dev->base + DW_IC_CON); | ||
371 | |||
372 | /* Enable the adapter */ | ||
373 | writel(1, dev->base + DW_IC_ENABLE); | ||
374 | |||
375 | /* Enable interrupts */ | ||
376 | writel(DW_IC_INTR_DEFAULT_MASK, dev->base + DW_IC_INTR_MASK); | ||
377 | } | ||
378 | |||
379 | /* | ||
380 | * Initiate (and continue) low level master read/write transaction. | ||
381 | * This function is only called from i2c_dw_isr, and pumping i2c_msg | ||
382 | * messages into the tx buffer. Even if the size of i2c_msg data is | ||
383 | * longer than the size of the tx buffer, it handles everything. | ||
384 | */ | ||
385 | static void | ||
386 | i2c_dw_xfer_msg(struct dw_i2c_dev *dev) | ||
387 | { | ||
388 | struct i2c_msg *msgs = dev->msgs; | ||
389 | u32 intr_mask; | ||
390 | int tx_limit, rx_limit; | ||
391 | u32 addr = msgs[dev->msg_write_idx].addr; | ||
392 | u32 buf_len = dev->tx_buf_len; | ||
393 | u8 *buf = dev->tx_buf;; | ||
394 | |||
395 | intr_mask = DW_IC_INTR_DEFAULT_MASK; | ||
396 | |||
397 | for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) { | ||
398 | /* | ||
399 | * if target address has changed, we need to | ||
400 | * reprogram the target address in the i2c | ||
401 | * adapter when we are done with this transfer | ||
402 | */ | ||
403 | if (msgs[dev->msg_write_idx].addr != addr) { | ||
404 | dev_err(dev->dev, | ||
405 | "%s: invalid target address\n", __func__); | ||
406 | dev->msg_err = -EINVAL; | ||
407 | break; | ||
408 | } | ||
409 | |||
410 | if (msgs[dev->msg_write_idx].len == 0) { | ||
411 | dev_err(dev->dev, | ||
412 | "%s: invalid message length\n", __func__); | ||
413 | dev->msg_err = -EINVAL; | ||
414 | break; | ||
415 | } | ||
416 | |||
417 | if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { | ||
418 | /* new i2c_msg */ | ||
419 | buf = msgs[dev->msg_write_idx].buf; | ||
420 | buf_len = msgs[dev->msg_write_idx].len; | ||
421 | } | ||
422 | |||
423 | tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR); | ||
424 | rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR); | ||
425 | |||
426 | while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { | ||
427 | if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { | ||
428 | writel(0x100, dev->base + DW_IC_DATA_CMD); | ||
429 | rx_limit--; | ||
430 | } else | ||
431 | writel(*buf++, dev->base + DW_IC_DATA_CMD); | ||
432 | tx_limit--; buf_len--; | ||
433 | } | ||
434 | |||
435 | dev->tx_buf = buf; | ||
436 | dev->tx_buf_len = buf_len; | ||
437 | |||
438 | if (buf_len > 0) { | ||
439 | /* more bytes to be written */ | ||
440 | dev->status |= STATUS_WRITE_IN_PROGRESS; | ||
441 | break; | ||
442 | } else | ||
443 | dev->status &= ~STATUS_WRITE_IN_PROGRESS; | ||
444 | } | ||
445 | |||
446 | /* | ||
447 | * If i2c_msg index search is completed, we don't need TX_EMPTY | ||
448 | * interrupt any more. | ||
449 | */ | ||
450 | if (dev->msg_write_idx == dev->msgs_num) | ||
451 | intr_mask &= ~DW_IC_INTR_TX_EMPTY; | ||
452 | |||
453 | if (dev->msg_err) | ||
454 | intr_mask = 0; | ||
455 | |||
456 | writel(intr_mask, dev->base + DW_IC_INTR_MASK); | ||
457 | } | ||
458 | |||
459 | static void | ||
460 | i2c_dw_read(struct dw_i2c_dev *dev) | ||
461 | { | ||
462 | struct i2c_msg *msgs = dev->msgs; | ||
463 | int rx_valid; | ||
464 | |||
465 | for (; dev->msg_read_idx < dev->msgs_num; dev->msg_read_idx++) { | ||
466 | u32 len; | ||
467 | u8 *buf; | ||
468 | |||
469 | if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) | ||
470 | continue; | ||
471 | |||
472 | if (!(dev->status & STATUS_READ_IN_PROGRESS)) { | ||
473 | len = msgs[dev->msg_read_idx].len; | ||
474 | buf = msgs[dev->msg_read_idx].buf; | ||
475 | } else { | ||
476 | len = dev->rx_buf_len; | ||
477 | buf = dev->rx_buf; | ||
478 | } | ||
479 | |||
480 | rx_valid = readl(dev->base + DW_IC_RXFLR); | ||
481 | |||
482 | for (; len > 0 && rx_valid > 0; len--, rx_valid--) | ||
483 | *buf++ = readl(dev->base + DW_IC_DATA_CMD); | ||
484 | |||
485 | if (len > 0) { | ||
486 | dev->status |= STATUS_READ_IN_PROGRESS; | ||
487 | dev->rx_buf_len = len; | ||
488 | dev->rx_buf = buf; | ||
489 | return; | ||
490 | } else | ||
491 | dev->status &= ~STATUS_READ_IN_PROGRESS; | ||
492 | } | ||
493 | } | ||
494 | |||
495 | static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev) | ||
496 | { | ||
497 | unsigned long abort_source = dev->abort_source; | ||
498 | int i; | ||
499 | |||
500 | if (abort_source & DW_IC_TX_ABRT_NOACK) { | ||
501 | for_each_set_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) | ||
502 | dev_dbg(dev->dev, | ||
503 | "%s: %s\n", __func__, abort_sources[i]); | ||
504 | return -EREMOTEIO; | ||
505 | } | ||
506 | |||
507 | for_each_set_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) | ||
508 | dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]); | ||
509 | |||
510 | if (abort_source & DW_IC_TX_ARB_LOST) | ||
511 | return -EAGAIN; | ||
512 | else if (abort_source & DW_IC_TX_ABRT_GCALL_READ) | ||
513 | return -EINVAL; /* wrong msgs[] data */ | ||
514 | else | ||
515 | return -EIO; | ||
516 | } | ||
517 | |||
518 | /* | ||
519 | * Prepare controller for a transaction and call i2c_dw_xfer_msg | ||
520 | */ | ||
521 | static int | ||
522 | i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | ||
523 | { | ||
524 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); | ||
525 | int ret; | ||
526 | |||
527 | dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num); | ||
528 | |||
529 | mutex_lock(&dev->lock); | ||
530 | |||
531 | INIT_COMPLETION(dev->cmd_complete); | ||
532 | dev->msgs = msgs; | ||
533 | dev->msgs_num = num; | ||
534 | dev->cmd_err = 0; | ||
535 | dev->msg_write_idx = 0; | ||
536 | dev->msg_read_idx = 0; | ||
537 | dev->msg_err = 0; | ||
538 | dev->status = STATUS_IDLE; | ||
539 | dev->abort_source = 0; | ||
540 | |||
541 | ret = i2c_dw_wait_bus_not_busy(dev); | ||
542 | if (ret < 0) | ||
543 | goto done; | ||
544 | |||
545 | /* start the transfers */ | ||
546 | i2c_dw_xfer_init(dev); | ||
547 | |||
548 | /* wait for tx to complete */ | ||
549 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ); | ||
550 | if (ret == 0) { | ||
551 | dev_err(dev->dev, "controller timed out\n"); | ||
552 | i2c_dw_init(dev); | ||
553 | ret = -ETIMEDOUT; | ||
554 | goto done; | ||
555 | } else if (ret < 0) | ||
556 | goto done; | ||
557 | |||
558 | if (dev->msg_err) { | ||
559 | ret = dev->msg_err; | ||
560 | goto done; | ||
561 | } | ||
562 | |||
563 | /* no error */ | ||
564 | if (likely(!dev->cmd_err)) { | ||
565 | /* Disable the adapter */ | ||
566 | writel(0, dev->base + DW_IC_ENABLE); | ||
567 | ret = num; | ||
568 | goto done; | ||
569 | } | ||
570 | |||
571 | /* We have an error */ | ||
572 | if (dev->cmd_err == DW_IC_ERR_TX_ABRT) { | ||
573 | ret = i2c_dw_handle_tx_abort(dev); | ||
574 | goto done; | ||
575 | } | ||
576 | ret = -EIO; | ||
577 | |||
578 | done: | ||
579 | mutex_unlock(&dev->lock); | ||
580 | |||
581 | return ret; | ||
582 | } | ||
583 | |||
584 | static u32 i2c_dw_func(struct i2c_adapter *adap) | ||
585 | { | ||
586 | return I2C_FUNC_I2C | | ||
587 | I2C_FUNC_10BIT_ADDR | | ||
588 | I2C_FUNC_SMBUS_BYTE | | ||
589 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
590 | I2C_FUNC_SMBUS_WORD_DATA | | ||
591 | I2C_FUNC_SMBUS_I2C_BLOCK; | ||
592 | } | ||
593 | |||
594 | static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev) | ||
595 | { | ||
596 | u32 stat; | ||
597 | |||
598 | /* | ||
599 | * The IC_INTR_STAT register just indicates "enabled" interrupts. | ||
600 | * Ths unmasked raw version of interrupt status bits are available | ||
601 | * in the IC_RAW_INTR_STAT register. | ||
602 | * | ||
603 | * That is, | ||
604 | * stat = readl(IC_INTR_STAT); | ||
605 | * equals to, | ||
606 | * stat = readl(IC_RAW_INTR_STAT) & readl(IC_INTR_MASK); | ||
607 | * | ||
608 | * The raw version might be useful for debugging purposes. | ||
609 | */ | ||
610 | stat = readl(dev->base + DW_IC_INTR_STAT); | ||
611 | |||
612 | /* | ||
613 | * Do not use the IC_CLR_INTR register to clear interrupts, or | ||
614 | * you'll miss some interrupts, triggered during the period from | ||
615 | * readl(IC_INTR_STAT) to readl(IC_CLR_INTR). | ||
616 | * | ||
617 | * Instead, use the separately-prepared IC_CLR_* registers. | ||
618 | */ | ||
619 | if (stat & DW_IC_INTR_RX_UNDER) | ||
620 | readl(dev->base + DW_IC_CLR_RX_UNDER); | ||
621 | if (stat & DW_IC_INTR_RX_OVER) | ||
622 | readl(dev->base + DW_IC_CLR_RX_OVER); | ||
623 | if (stat & DW_IC_INTR_TX_OVER) | ||
624 | readl(dev->base + DW_IC_CLR_TX_OVER); | ||
625 | if (stat & DW_IC_INTR_RD_REQ) | ||
626 | readl(dev->base + DW_IC_CLR_RD_REQ); | ||
627 | if (stat & DW_IC_INTR_TX_ABRT) { | ||
628 | /* | ||
629 | * The IC_TX_ABRT_SOURCE register is cleared whenever | ||
630 | * the IC_CLR_TX_ABRT is read. Preserve it beforehand. | ||
631 | */ | ||
632 | dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE); | ||
633 | readl(dev->base + DW_IC_CLR_TX_ABRT); | ||
634 | } | ||
635 | if (stat & DW_IC_INTR_RX_DONE) | ||
636 | readl(dev->base + DW_IC_CLR_RX_DONE); | ||
637 | if (stat & DW_IC_INTR_ACTIVITY) | ||
638 | readl(dev->base + DW_IC_CLR_ACTIVITY); | ||
639 | if (stat & DW_IC_INTR_STOP_DET) | ||
640 | readl(dev->base + DW_IC_CLR_STOP_DET); | ||
641 | if (stat & DW_IC_INTR_START_DET) | ||
642 | readl(dev->base + DW_IC_CLR_START_DET); | ||
643 | if (stat & DW_IC_INTR_GEN_CALL) | ||
644 | readl(dev->base + DW_IC_CLR_GEN_CALL); | ||
645 | |||
646 | return stat; | ||
647 | } | ||
648 | |||
649 | /* | ||
650 | * Interrupt service routine. This gets called whenever an I2C interrupt | ||
651 | * occurs. | ||
652 | */ | ||
653 | static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) | ||
654 | { | ||
655 | struct dw_i2c_dev *dev = dev_id; | ||
656 | u32 stat; | ||
657 | |||
658 | stat = i2c_dw_read_clear_intrbits(dev); | ||
659 | dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); | ||
660 | |||
661 | if (stat & DW_IC_INTR_TX_ABRT) { | ||
662 | dev->cmd_err |= DW_IC_ERR_TX_ABRT; | ||
663 | dev->status = STATUS_IDLE; | ||
664 | |||
665 | /* | ||
666 | * Anytime TX_ABRT is set, the contents of the tx/rx | ||
667 | * buffers are flushed. Make sure to skip them. | ||
668 | */ | ||
669 | writel(0, dev->base + DW_IC_INTR_MASK); | ||
670 | goto tx_aborted; | ||
671 | } | ||
672 | |||
673 | if (stat & DW_IC_INTR_RX_FULL) | ||
674 | i2c_dw_read(dev); | ||
675 | |||
676 | if (stat & DW_IC_INTR_TX_EMPTY) | ||
677 | i2c_dw_xfer_msg(dev); | ||
678 | |||
679 | /* | ||
680 | * No need to modify or disable the interrupt mask here. | ||
681 | * i2c_dw_xfer_msg() will take care of it according to | ||
682 | * the current transmit status. | ||
683 | */ | ||
684 | |||
685 | tx_aborted: | ||
686 | if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err) | ||
687 | complete(&dev->cmd_complete); | ||
688 | |||
689 | return IRQ_HANDLED; | ||
690 | } | ||
691 | |||
692 | static struct i2c_algorithm i2c_dw_algo = { | ||
693 | .master_xfer = i2c_dw_xfer, | ||
694 | .functionality = i2c_dw_func, | ||
695 | }; | ||
696 | |||
697 | static int __devinit dw_i2c_probe(struct platform_device *pdev) | ||
698 | { | ||
699 | struct dw_i2c_dev *dev; | ||
700 | struct i2c_adapter *adap; | ||
701 | struct resource *mem, *ioarea; | ||
702 | int irq, r; | ||
703 | |||
704 | /* NOTE: driver uses the static register mapping */ | ||
705 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
706 | if (!mem) { | ||
707 | dev_err(&pdev->dev, "no mem resource?\n"); | ||
708 | return -EINVAL; | ||
709 | } | ||
710 | |||
711 | irq = platform_get_irq(pdev, 0); | ||
712 | if (irq < 0) { | ||
713 | dev_err(&pdev->dev, "no irq resource?\n"); | ||
714 | return irq; /* -ENXIO */ | ||
715 | } | ||
716 | |||
717 | ioarea = request_mem_region(mem->start, resource_size(mem), | ||
718 | pdev->name); | ||
719 | if (!ioarea) { | ||
720 | dev_err(&pdev->dev, "I2C region already claimed\n"); | ||
721 | return -EBUSY; | ||
722 | } | ||
723 | |||
724 | dev = kzalloc(sizeof(struct dw_i2c_dev), GFP_KERNEL); | ||
725 | if (!dev) { | ||
726 | r = -ENOMEM; | ||
727 | goto err_release_region; | ||
728 | } | ||
729 | |||
730 | init_completion(&dev->cmd_complete); | ||
731 | mutex_init(&dev->lock); | ||
732 | dev->dev = get_device(&pdev->dev); | ||
733 | dev->irq = irq; | ||
734 | platform_set_drvdata(pdev, dev); | ||
735 | |||
736 | dev->clk = clk_get(&pdev->dev, NULL); | ||
737 | if (IS_ERR(dev->clk)) { | ||
738 | r = -ENODEV; | ||
739 | goto err_free_mem; | ||
740 | } | ||
741 | clk_enable(dev->clk); | ||
742 | |||
743 | dev->base = ioremap(mem->start, resource_size(mem)); | ||
744 | if (dev->base == NULL) { | ||
745 | dev_err(&pdev->dev, "failure mapping io resources\n"); | ||
746 | r = -EBUSY; | ||
747 | goto err_unuse_clocks; | ||
748 | } | ||
749 | { | ||
750 | u32 param1 = readl(dev->base + DW_IC_COMP_PARAM_1); | ||
751 | |||
752 | dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; | ||
753 | dev->rx_fifo_depth = ((param1 >> 8) & 0xff) + 1; | ||
754 | } | ||
755 | i2c_dw_init(dev); | ||
756 | |||
757 | writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ | ||
758 | r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev); | ||
759 | if (r) { | ||
760 | dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); | ||
761 | goto err_iounmap; | ||
762 | } | ||
763 | |||
764 | adap = &dev->adapter; | ||
765 | i2c_set_adapdata(adap, dev); | ||
766 | adap->owner = THIS_MODULE; | ||
767 | adap->class = I2C_CLASS_HWMON; | ||
768 | strlcpy(adap->name, "Synopsys DesignWare I2C adapter", | ||
769 | sizeof(adap->name)); | ||
770 | adap->algo = &i2c_dw_algo; | ||
771 | adap->dev.parent = &pdev->dev; | ||
772 | |||
773 | adap->nr = pdev->id; | ||
774 | r = i2c_add_numbered_adapter(adap); | ||
775 | if (r) { | ||
776 | dev_err(&pdev->dev, "failure adding adapter\n"); | ||
777 | goto err_free_irq; | ||
778 | } | ||
779 | |||
780 | return 0; | ||
781 | |||
782 | err_free_irq: | ||
783 | free_irq(dev->irq, dev); | ||
784 | err_iounmap: | ||
785 | iounmap(dev->base); | ||
786 | err_unuse_clocks: | ||
787 | clk_disable(dev->clk); | ||
788 | clk_put(dev->clk); | ||
789 | dev->clk = NULL; | ||
790 | err_free_mem: | ||
791 | platform_set_drvdata(pdev, NULL); | ||
792 | put_device(&pdev->dev); | ||
793 | kfree(dev); | ||
794 | err_release_region: | ||
795 | release_mem_region(mem->start, resource_size(mem)); | ||
796 | |||
797 | return r; | ||
798 | } | ||
799 | |||
800 | static int __devexit dw_i2c_remove(struct platform_device *pdev) | ||
801 | { | ||
802 | struct dw_i2c_dev *dev = platform_get_drvdata(pdev); | ||
803 | struct resource *mem; | ||
804 | |||
805 | platform_set_drvdata(pdev, NULL); | ||
806 | i2c_del_adapter(&dev->adapter); | ||
807 | put_device(&pdev->dev); | ||
808 | |||
809 | clk_disable(dev->clk); | ||
810 | clk_put(dev->clk); | ||
811 | dev->clk = NULL; | ||
812 | |||
813 | writel(0, dev->base + DW_IC_ENABLE); | ||
814 | free_irq(dev->irq, dev); | ||
815 | kfree(dev); | ||
816 | |||
817 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
818 | release_mem_region(mem->start, resource_size(mem)); | ||
819 | return 0; | ||
820 | } | ||
821 | |||
822 | /* work with hotplug and coldplug */ | ||
823 | MODULE_ALIAS("platform:i2c_designware"); | ||
824 | |||
825 | static struct platform_driver dw_i2c_driver = { | ||
826 | .remove = __devexit_p(dw_i2c_remove), | ||
827 | .driver = { | ||
828 | .name = "i2c_designware", | ||
829 | .owner = THIS_MODULE, | ||
830 | }, | ||
831 | }; | ||
832 | |||
833 | static int __init dw_i2c_init_driver(void) | ||
834 | { | ||
835 | return platform_driver_probe(&dw_i2c_driver, dw_i2c_probe); | ||
836 | } | ||
837 | module_init(dw_i2c_init_driver); | ||
838 | |||
839 | static void __exit dw_i2c_exit_driver(void) | ||
840 | { | ||
841 | platform_driver_unregister(&dw_i2c_driver); | ||
842 | } | ||
843 | module_exit(dw_i2c_exit_driver); | ||
844 | |||
845 | MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); | ||
846 | MODULE_DESCRIPTION("Synopsys DesignWare I2C bus adapter"); | ||
847 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c index 448b4bf35eb7..e5b1a3bf5b80 100644 --- a/drivers/i2c/busses/i2c-elektor.c +++ b/drivers/i2c/busses/i2c-elektor.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/ioport.h> | 29 | #include <linux/ioport.h> |
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/slab.h> | ||
33 | #include <linux/init.h> | 32 | #include <linux/init.h> |
34 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
35 | #include <linux/pci.h> | 34 | #include <linux/pci.h> |
@@ -38,8 +37,8 @@ | |||
38 | #include <linux/isa.h> | 37 | #include <linux/isa.h> |
39 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
40 | #include <linux/i2c-algo-pcf.h> | 39 | #include <linux/i2c-algo-pcf.h> |
40 | #include <linux/io.h> | ||
41 | 41 | ||
42 | #include <asm/io.h> | ||
43 | #include <asm/irq.h> | 42 | #include <asm/irq.h> |
44 | 43 | ||
45 | #include "../algos/i2c-algo-pcf.h" | 44 | #include "../algos/i2c-algo-pcf.h" |
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 32104eac8d3d..d9aa9a649e35 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/i2c-gpio.h> | 12 | #include <linux/i2c-gpio.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
16 | 17 | ||
17 | #include <asm/gpio.h> | 18 | #include <asm/gpio.h> |
@@ -210,7 +211,7 @@ static int __init i2c_gpio_init(void) | |||
210 | 211 | ||
211 | return ret; | 212 | return ret; |
212 | } | 213 | } |
213 | module_init(i2c_gpio_init); | 214 | subsys_initcall(i2c_gpio_init); |
214 | 215 | ||
215 | static void __exit i2c_gpio_exit(void) | 216 | static void __exit i2c_gpio_exit(void) |
216 | { | 217 | { |
diff --git a/drivers/i2c/busses/i2c-highlander.c b/drivers/i2c/busses/i2c-highlander.c index 87ecace415da..3df1bc80f37a 100644 --- a/drivers/i2c/busses/i2c-highlander.c +++ b/drivers/i2c/busses/i2c-highlander.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/completion.h> | 19 | #include <linux/completion.h> |
20 | #include <linux/io.h> | 20 | #include <linux/io.h> |
21 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #define SMCR 0x00 | 24 | #define SMCR 0x00 |
24 | #define SMCR_START (1 << 0) | 25 | #define SMCR_START (1 << 0) |
@@ -281,7 +282,6 @@ static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
281 | union i2c_smbus_data *data) | 282 | union i2c_smbus_data *data) |
282 | { | 283 | { |
283 | struct highlander_i2c_dev *dev = i2c_get_adapdata(adap); | 284 | struct highlander_i2c_dev *dev = i2c_get_adapdata(adap); |
284 | int read = read_write & I2C_SMBUS_READ; | ||
285 | u16 tmp; | 285 | u16 tmp; |
286 | 286 | ||
287 | init_completion(&dev->cmd_complete); | 287 | init_completion(&dev->cmd_complete); |
@@ -336,11 +336,11 @@ static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, | |||
336 | highlander_i2c_done(dev); | 336 | highlander_i2c_done(dev); |
337 | 337 | ||
338 | /* Set slave address */ | 338 | /* Set slave address */ |
339 | iowrite16((addr << 1) | read, dev->base + SMSMADR); | 339 | iowrite16((addr << 1) | read_write, dev->base + SMSMADR); |
340 | 340 | ||
341 | highlander_i2c_command(dev, command, dev->buf_len); | 341 | highlander_i2c_command(dev, command, dev->buf_len); |
342 | 342 | ||
343 | if (read) | 343 | if (read_write == I2C_SMBUS_READ) |
344 | return highlander_i2c_read(dev); | 344 | return highlander_i2c_read(dev); |
345 | else | 345 | else |
346 | return highlander_i2c_write(dev); | 346 | return highlander_i2c_write(dev); |
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c index bec9b845dd16..9ff1695d8458 100644 --- a/drivers/i2c/busses/i2c-hydra.c +++ b/drivers/i2c/busses/i2c-hydra.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/i2c-algo-bit.h> | 29 | #include <linux/i2c-algo-bit.h> |
30 | #include <linux/init.h> | 30 | #include <linux/init.h> |
31 | #include <asm/io.h> | 31 | #include <linux/io.h> |
32 | #include <asm/hydra.h> | 32 | #include <asm/hydra.h> |
33 | 33 | ||
34 | 34 | ||
@@ -105,7 +105,7 @@ static struct i2c_adapter hydra_adap = { | |||
105 | .algo_data = &hydra_bit_data, | 105 | .algo_data = &hydra_bit_data, |
106 | }; | 106 | }; |
107 | 107 | ||
108 | static struct pci_device_id hydra_ids[] = { | 108 | static const struct pci_device_id hydra_ids[] = { |
109 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, | 109 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, |
110 | { 0, } | 110 | { 0, } |
111 | }; | 111 | }; |
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 9d2c5adf5d4f..7979aef7ee7b 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c | |||
@@ -3,6 +3,8 @@ | |||
3 | Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker | 3 | Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker |
4 | <mdsxyz123@yahoo.com> | 4 | <mdsxyz123@yahoo.com> |
5 | Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> | 5 | Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> |
6 | Copyright (C) 2010 Intel Corporation, | ||
7 | David Woodhouse <dwmw2@infradead.org> | ||
6 | 8 | ||
7 | This program is free software; you can redistribute it and/or modify | 9 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | 10 | it under the terms of the GNU General Public License as published by |
@@ -38,10 +40,15 @@ | |||
38 | 82801G (ICH7) 0x27da 32 hard yes yes yes | 40 | 82801G (ICH7) 0x27da 32 hard yes yes yes |
39 | 82801H (ICH8) 0x283e 32 hard yes yes yes | 41 | 82801H (ICH8) 0x283e 32 hard yes yes yes |
40 | 82801I (ICH9) 0x2930 32 hard yes yes yes | 42 | 82801I (ICH9) 0x2930 32 hard yes yes yes |
41 | Tolapai 0x5032 32 hard yes yes yes | 43 | EP80579 (Tolapai) 0x5032 32 hard yes yes yes |
42 | ICH10 0x3a30 32 hard yes yes yes | 44 | ICH10 0x3a30 32 hard yes yes yes |
43 | ICH10 0x3a60 32 hard yes yes yes | 45 | ICH10 0x3a60 32 hard yes yes yes |
44 | PCH 0x3b30 32 hard yes yes yes | 46 | 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes |
47 | Cougar Point (PCH) 0x1c22 32 hard yes yes yes | ||
48 | Patsburg (PCH) 0x1d22 32 hard yes yes yes | ||
49 | Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes | ||
50 | Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes | ||
51 | Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes | ||
45 | 52 | ||
46 | Features supported by this driver: | 53 | Features supported by this driver: |
47 | Software PEC no | 54 | Software PEC no |
@@ -49,12 +56,11 @@ | |||
49 | Block buffer yes | 56 | Block buffer yes |
50 | Block process call transaction no | 57 | Block process call transaction no |
51 | I2C block read transaction yes (doesn't use the block buffer) | 58 | I2C block read transaction yes (doesn't use the block buffer) |
59 | Slave mode no | ||
52 | 60 | ||
53 | See the file Documentation/i2c/busses/i2c-i801 for details. | 61 | See the file Documentation/i2c/busses/i2c-i801 for details. |
54 | */ | 62 | */ |
55 | 63 | ||
56 | /* Note: we assume there can only be one I801, with one SMBus interface */ | ||
57 | |||
58 | #include <linux/module.h> | 64 | #include <linux/module.h> |
59 | #include <linux/pci.h> | 65 | #include <linux/pci.h> |
60 | #include <linux/kernel.h> | 66 | #include <linux/kernel.h> |
@@ -66,18 +72,19 @@ | |||
66 | #include <linux/acpi.h> | 72 | #include <linux/acpi.h> |
67 | #include <linux/io.h> | 73 | #include <linux/io.h> |
68 | #include <linux/dmi.h> | 74 | #include <linux/dmi.h> |
75 | #include <linux/slab.h> | ||
69 | 76 | ||
70 | /* I801 SMBus address offsets */ | 77 | /* I801 SMBus address offsets */ |
71 | #define SMBHSTSTS (0 + i801_smba) | 78 | #define SMBHSTSTS(p) (0 + (p)->smba) |
72 | #define SMBHSTCNT (2 + i801_smba) | 79 | #define SMBHSTCNT(p) (2 + (p)->smba) |
73 | #define SMBHSTCMD (3 + i801_smba) | 80 | #define SMBHSTCMD(p) (3 + (p)->smba) |
74 | #define SMBHSTADD (4 + i801_smba) | 81 | #define SMBHSTADD(p) (4 + (p)->smba) |
75 | #define SMBHSTDAT0 (5 + i801_smba) | 82 | #define SMBHSTDAT0(p) (5 + (p)->smba) |
76 | #define SMBHSTDAT1 (6 + i801_smba) | 83 | #define SMBHSTDAT1(p) (6 + (p)->smba) |
77 | #define SMBBLKDAT (7 + i801_smba) | 84 | #define SMBBLKDAT(p) (7 + (p)->smba) |
78 | #define SMBPEC (8 + i801_smba) /* ICH3 and later */ | 85 | #define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */ |
79 | #define SMBAUXSTS (12 + i801_smba) /* ICH4 and later */ | 86 | #define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */ |
80 | #define SMBAUXCTL (13 + i801_smba) /* ICH4 and later */ | 87 | #define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */ |
81 | 88 | ||
82 | /* PCI Address Constants */ | 89 | /* PCI Address Constants */ |
83 | #define SMBBAR 4 | 90 | #define SMBBAR 4 |
@@ -126,37 +133,57 @@ | |||
126 | SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \ | 133 | SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \ |
127 | SMBHSTSTS_INTR) | 134 | SMBHSTSTS_INTR) |
128 | 135 | ||
129 | static unsigned long i801_smba; | 136 | /* Patsburg also has three 'Integrated Device Function' SMBus controllers */ |
130 | static unsigned char i801_original_hstcfg; | 137 | #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70 |
138 | #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71 | ||
139 | #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72 | ||
140 | |||
141 | struct i801_priv { | ||
142 | struct i2c_adapter adapter; | ||
143 | unsigned long smba; | ||
144 | unsigned char original_hstcfg; | ||
145 | struct pci_dev *pci_dev; | ||
146 | unsigned int features; | ||
147 | }; | ||
148 | |||
131 | static struct pci_driver i801_driver; | 149 | static struct pci_driver i801_driver; |
132 | static struct pci_dev *I801_dev; | ||
133 | 150 | ||
134 | #define FEATURE_SMBUS_PEC (1 << 0) | 151 | #define FEATURE_SMBUS_PEC (1 << 0) |
135 | #define FEATURE_BLOCK_BUFFER (1 << 1) | 152 | #define FEATURE_BLOCK_BUFFER (1 << 1) |
136 | #define FEATURE_BLOCK_PROC (1 << 2) | 153 | #define FEATURE_BLOCK_PROC (1 << 2) |
137 | #define FEATURE_I2C_BLOCK_READ (1 << 3) | 154 | #define FEATURE_I2C_BLOCK_READ (1 << 3) |
138 | static unsigned int i801_features; | 155 | |
156 | static const char *i801_feature_names[] = { | ||
157 | "SMBus PEC", | ||
158 | "Block buffer", | ||
159 | "Block process call", | ||
160 | "I2C block read", | ||
161 | }; | ||
162 | |||
163 | static unsigned int disable_features; | ||
164 | module_param(disable_features, uint, S_IRUGO | S_IWUSR); | ||
165 | MODULE_PARM_DESC(disable_features, "Disable selected driver features"); | ||
139 | 166 | ||
140 | /* Make sure the SMBus host is ready to start transmitting. | 167 | /* Make sure the SMBus host is ready to start transmitting. |
141 | Return 0 if it is, -EBUSY if it is not. */ | 168 | Return 0 if it is, -EBUSY if it is not. */ |
142 | static int i801_check_pre(void) | 169 | static int i801_check_pre(struct i801_priv *priv) |
143 | { | 170 | { |
144 | int status; | 171 | int status; |
145 | 172 | ||
146 | status = inb_p(SMBHSTSTS); | 173 | status = inb_p(SMBHSTSTS(priv)); |
147 | if (status & SMBHSTSTS_HOST_BUSY) { | 174 | if (status & SMBHSTSTS_HOST_BUSY) { |
148 | dev_err(&I801_dev->dev, "SMBus is busy, can't use it!\n"); | 175 | dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n"); |
149 | return -EBUSY; | 176 | return -EBUSY; |
150 | } | 177 | } |
151 | 178 | ||
152 | status &= STATUS_FLAGS; | 179 | status &= STATUS_FLAGS; |
153 | if (status) { | 180 | if (status) { |
154 | dev_dbg(&I801_dev->dev, "Clearing status flags (%02x)\n", | 181 | dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n", |
155 | status); | 182 | status); |
156 | outb_p(status, SMBHSTSTS); | 183 | outb_p(status, SMBHSTSTS(priv)); |
157 | status = inb_p(SMBHSTSTS) & STATUS_FLAGS; | 184 | status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS; |
158 | if (status) { | 185 | if (status) { |
159 | dev_err(&I801_dev->dev, | 186 | dev_err(&priv->pci_dev->dev, |
160 | "Failed clearing status flags (%02x)\n", | 187 | "Failed clearing status flags (%02x)\n", |
161 | status); | 188 | status); |
162 | return -EBUSY; | 189 | return -EBUSY; |
@@ -167,48 +194,50 @@ static int i801_check_pre(void) | |||
167 | } | 194 | } |
168 | 195 | ||
169 | /* Convert the status register to an error code, and clear it. */ | 196 | /* Convert the status register to an error code, and clear it. */ |
170 | static int i801_check_post(int status, int timeout) | 197 | static int i801_check_post(struct i801_priv *priv, int status, int timeout) |
171 | { | 198 | { |
172 | int result = 0; | 199 | int result = 0; |
173 | 200 | ||
174 | /* If the SMBus is still busy, we give up */ | 201 | /* If the SMBus is still busy, we give up */ |
175 | if (timeout) { | 202 | if (timeout) { |
176 | dev_err(&I801_dev->dev, "Transaction timeout\n"); | 203 | dev_err(&priv->pci_dev->dev, "Transaction timeout\n"); |
177 | /* try to stop the current command */ | 204 | /* try to stop the current command */ |
178 | dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); | 205 | dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n"); |
179 | outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); | 206 | outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL, |
207 | SMBHSTCNT(priv)); | ||
180 | msleep(1); | 208 | msleep(1); |
181 | outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT); | 209 | outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL), |
210 | SMBHSTCNT(priv)); | ||
182 | 211 | ||
183 | /* Check if it worked */ | 212 | /* Check if it worked */ |
184 | status = inb_p(SMBHSTSTS); | 213 | status = inb_p(SMBHSTSTS(priv)); |
185 | if ((status & SMBHSTSTS_HOST_BUSY) || | 214 | if ((status & SMBHSTSTS_HOST_BUSY) || |
186 | !(status & SMBHSTSTS_FAILED)) | 215 | !(status & SMBHSTSTS_FAILED)) |
187 | dev_err(&I801_dev->dev, | 216 | dev_err(&priv->pci_dev->dev, |
188 | "Failed terminating the transaction\n"); | 217 | "Failed terminating the transaction\n"); |
189 | outb_p(STATUS_FLAGS, SMBHSTSTS); | 218 | outb_p(STATUS_FLAGS, SMBHSTSTS(priv)); |
190 | return -ETIMEDOUT; | 219 | return -ETIMEDOUT; |
191 | } | 220 | } |
192 | 221 | ||
193 | if (status & SMBHSTSTS_FAILED) { | 222 | if (status & SMBHSTSTS_FAILED) { |
194 | result = -EIO; | 223 | result = -EIO; |
195 | dev_err(&I801_dev->dev, "Transaction failed\n"); | 224 | dev_err(&priv->pci_dev->dev, "Transaction failed\n"); |
196 | } | 225 | } |
197 | if (status & SMBHSTSTS_DEV_ERR) { | 226 | if (status & SMBHSTSTS_DEV_ERR) { |
198 | result = -ENXIO; | 227 | result = -ENXIO; |
199 | dev_dbg(&I801_dev->dev, "No response\n"); | 228 | dev_dbg(&priv->pci_dev->dev, "No response\n"); |
200 | } | 229 | } |
201 | if (status & SMBHSTSTS_BUS_ERR) { | 230 | if (status & SMBHSTSTS_BUS_ERR) { |
202 | result = -EAGAIN; | 231 | result = -EAGAIN; |
203 | dev_dbg(&I801_dev->dev, "Lost arbitration\n"); | 232 | dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n"); |
204 | } | 233 | } |
205 | 234 | ||
206 | if (result) { | 235 | if (result) { |
207 | /* Clear error flags */ | 236 | /* Clear error flags */ |
208 | outb_p(status & STATUS_FLAGS, SMBHSTSTS); | 237 | outb_p(status & STATUS_FLAGS, SMBHSTSTS(priv)); |
209 | status = inb_p(SMBHSTSTS) & STATUS_FLAGS; | 238 | status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS; |
210 | if (status) { | 239 | if (status) { |
211 | dev_warn(&I801_dev->dev, "Failed clearing status " | 240 | dev_warn(&priv->pci_dev->dev, "Failed clearing status " |
212 | "flags at end of transaction (%02x)\n", | 241 | "flags at end of transaction (%02x)\n", |
213 | status); | 242 | status); |
214 | } | 243 | } |
@@ -217,86 +246,88 @@ static int i801_check_post(int status, int timeout) | |||
217 | return result; | 246 | return result; |
218 | } | 247 | } |
219 | 248 | ||
220 | static int i801_transaction(int xact) | 249 | static int i801_transaction(struct i801_priv *priv, int xact) |
221 | { | 250 | { |
222 | int status; | 251 | int status; |
223 | int result; | 252 | int result; |
224 | int timeout = 0; | 253 | int timeout = 0; |
225 | 254 | ||
226 | result = i801_check_pre(); | 255 | result = i801_check_pre(priv); |
227 | if (result < 0) | 256 | if (result < 0) |
228 | return result; | 257 | return result; |
229 | 258 | ||
230 | /* the current contents of SMBHSTCNT can be overwritten, since PEC, | 259 | /* the current contents of SMBHSTCNT can be overwritten, since PEC, |
231 | * INTREN, SMBSCMD are passed in xact */ | 260 | * INTREN, SMBSCMD are passed in xact */ |
232 | outb_p(xact | I801_START, SMBHSTCNT); | 261 | outb_p(xact | I801_START, SMBHSTCNT(priv)); |
233 | 262 | ||
234 | /* We will always wait for a fraction of a second! */ | 263 | /* We will always wait for a fraction of a second! */ |
235 | do { | 264 | do { |
236 | msleep(1); | 265 | msleep(1); |
237 | status = inb_p(SMBHSTSTS); | 266 | status = inb_p(SMBHSTSTS(priv)); |
238 | } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT)); | 267 | } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT)); |
239 | 268 | ||
240 | result = i801_check_post(status, timeout > MAX_TIMEOUT); | 269 | result = i801_check_post(priv, status, timeout > MAX_TIMEOUT); |
241 | if (result < 0) | 270 | if (result < 0) |
242 | return result; | 271 | return result; |
243 | 272 | ||
244 | outb_p(SMBHSTSTS_INTR, SMBHSTSTS); | 273 | outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv)); |
245 | return 0; | 274 | return 0; |
246 | } | 275 | } |
247 | 276 | ||
248 | /* wait for INTR bit as advised by Intel */ | 277 | /* wait for INTR bit as advised by Intel */ |
249 | static void i801_wait_hwpec(void) | 278 | static void i801_wait_hwpec(struct i801_priv *priv) |
250 | { | 279 | { |
251 | int timeout = 0; | 280 | int timeout = 0; |
252 | int status; | 281 | int status; |
253 | 282 | ||
254 | do { | 283 | do { |
255 | msleep(1); | 284 | msleep(1); |
256 | status = inb_p(SMBHSTSTS); | 285 | status = inb_p(SMBHSTSTS(priv)); |
257 | } while ((!(status & SMBHSTSTS_INTR)) | 286 | } while ((!(status & SMBHSTSTS_INTR)) |
258 | && (timeout++ < MAX_TIMEOUT)); | 287 | && (timeout++ < MAX_TIMEOUT)); |
259 | 288 | ||
260 | if (timeout > MAX_TIMEOUT) | 289 | if (timeout > MAX_TIMEOUT) |
261 | dev_dbg(&I801_dev->dev, "PEC Timeout!\n"); | 290 | dev_dbg(&priv->pci_dev->dev, "PEC Timeout!\n"); |
262 | 291 | ||
263 | outb_p(status, SMBHSTSTS); | 292 | outb_p(status, SMBHSTSTS(priv)); |
264 | } | 293 | } |
265 | 294 | ||
266 | static int i801_block_transaction_by_block(union i2c_smbus_data *data, | 295 | static int i801_block_transaction_by_block(struct i801_priv *priv, |
296 | union i2c_smbus_data *data, | ||
267 | char read_write, int hwpec) | 297 | char read_write, int hwpec) |
268 | { | 298 | { |
269 | int i, len; | 299 | int i, len; |
270 | int status; | 300 | int status; |
271 | 301 | ||
272 | inb_p(SMBHSTCNT); /* reset the data buffer index */ | 302 | inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */ |
273 | 303 | ||
274 | /* Use 32-byte buffer to process this transaction */ | 304 | /* Use 32-byte buffer to process this transaction */ |
275 | if (read_write == I2C_SMBUS_WRITE) { | 305 | if (read_write == I2C_SMBUS_WRITE) { |
276 | len = data->block[0]; | 306 | len = data->block[0]; |
277 | outb_p(len, SMBHSTDAT0); | 307 | outb_p(len, SMBHSTDAT0(priv)); |
278 | for (i = 0; i < len; i++) | 308 | for (i = 0; i < len; i++) |
279 | outb_p(data->block[i+1], SMBBLKDAT); | 309 | outb_p(data->block[i+1], SMBBLKDAT(priv)); |
280 | } | 310 | } |
281 | 311 | ||
282 | status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | | 312 | status = i801_transaction(priv, I801_BLOCK_DATA | ENABLE_INT9 | |
283 | I801_PEC_EN * hwpec); | 313 | I801_PEC_EN * hwpec); |
284 | if (status) | 314 | if (status) |
285 | return status; | 315 | return status; |
286 | 316 | ||
287 | if (read_write == I2C_SMBUS_READ) { | 317 | if (read_write == I2C_SMBUS_READ) { |
288 | len = inb_p(SMBHSTDAT0); | 318 | len = inb_p(SMBHSTDAT0(priv)); |
289 | if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) | 319 | if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) |
290 | return -EPROTO; | 320 | return -EPROTO; |
291 | 321 | ||
292 | data->block[0] = len; | 322 | data->block[0] = len; |
293 | for (i = 0; i < len; i++) | 323 | for (i = 0; i < len; i++) |
294 | data->block[i + 1] = inb_p(SMBBLKDAT); | 324 | data->block[i + 1] = inb_p(SMBBLKDAT(priv)); |
295 | } | 325 | } |
296 | return 0; | 326 | return 0; |
297 | } | 327 | } |
298 | 328 | ||
299 | static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, | 329 | static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, |
330 | union i2c_smbus_data *data, | ||
300 | char read_write, int command, | 331 | char read_write, int command, |
301 | int hwpec) | 332 | int hwpec) |
302 | { | 333 | { |
@@ -306,15 +337,15 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, | |||
306 | int result; | 337 | int result; |
307 | int timeout; | 338 | int timeout; |
308 | 339 | ||
309 | result = i801_check_pre(); | 340 | result = i801_check_pre(priv); |
310 | if (result < 0) | 341 | if (result < 0) |
311 | return result; | 342 | return result; |
312 | 343 | ||
313 | len = data->block[0]; | 344 | len = data->block[0]; |
314 | 345 | ||
315 | if (read_write == I2C_SMBUS_WRITE) { | 346 | if (read_write == I2C_SMBUS_WRITE) { |
316 | outb_p(len, SMBHSTDAT0); | 347 | outb_p(len, SMBHSTDAT0(priv)); |
317 | outb_p(data->block[1], SMBBLKDAT); | 348 | outb_p(data->block[1], SMBBLKDAT(priv)); |
318 | } | 349 | } |
319 | 350 | ||
320 | for (i = 1; i <= len; i++) { | 351 | for (i = 1; i <= len; i++) { |
@@ -330,35 +361,37 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, | |||
330 | else | 361 | else |
331 | smbcmd = I801_BLOCK_DATA; | 362 | smbcmd = I801_BLOCK_DATA; |
332 | } | 363 | } |
333 | outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); | 364 | outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT(priv)); |
334 | 365 | ||
335 | if (i == 1) | 366 | if (i == 1) |
336 | outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); | 367 | outb_p(inb(SMBHSTCNT(priv)) | I801_START, |
368 | SMBHSTCNT(priv)); | ||
337 | 369 | ||
338 | /* We will always wait for a fraction of a second! */ | 370 | /* We will always wait for a fraction of a second! */ |
339 | timeout = 0; | 371 | timeout = 0; |
340 | do { | 372 | do { |
341 | msleep(1); | 373 | msleep(1); |
342 | status = inb_p(SMBHSTSTS); | 374 | status = inb_p(SMBHSTSTS(priv)); |
343 | } | 375 | } while ((!(status & SMBHSTSTS_BYTE_DONE)) |
344 | while ((!(status & SMBHSTSTS_BYTE_DONE)) | 376 | && (timeout++ < MAX_TIMEOUT)); |
345 | && (timeout++ < MAX_TIMEOUT)); | ||
346 | 377 | ||
347 | result = i801_check_post(status, timeout > MAX_TIMEOUT); | 378 | result = i801_check_post(priv, status, timeout > MAX_TIMEOUT); |
348 | if (result < 0) | 379 | if (result < 0) |
349 | return result; | 380 | return result; |
350 | 381 | ||
351 | if (i == 1 && read_write == I2C_SMBUS_READ | 382 | if (i == 1 && read_write == I2C_SMBUS_READ |
352 | && command != I2C_SMBUS_I2C_BLOCK_DATA) { | 383 | && command != I2C_SMBUS_I2C_BLOCK_DATA) { |
353 | len = inb_p(SMBHSTDAT0); | 384 | len = inb_p(SMBHSTDAT0(priv)); |
354 | if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { | 385 | if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) { |
355 | dev_err(&I801_dev->dev, | 386 | dev_err(&priv->pci_dev->dev, |
356 | "Illegal SMBus block read size %d\n", | 387 | "Illegal SMBus block read size %d\n", |
357 | len); | 388 | len); |
358 | /* Recover */ | 389 | /* Recover */ |
359 | while (inb_p(SMBHSTSTS) & SMBHSTSTS_HOST_BUSY) | 390 | while (inb_p(SMBHSTSTS(priv)) & |
360 | outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS); | 391 | SMBHSTSTS_HOST_BUSY) |
361 | outb_p(SMBHSTSTS_INTR, SMBHSTSTS); | 392 | outb_p(SMBHSTSTS_BYTE_DONE, |
393 | SMBHSTSTS(priv)); | ||
394 | outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv)); | ||
362 | return -EPROTO; | 395 | return -EPROTO; |
363 | } | 396 | } |
364 | data->block[0] = len; | 397 | data->block[0] = len; |
@@ -366,27 +399,28 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, | |||
366 | 399 | ||
367 | /* Retrieve/store value in SMBBLKDAT */ | 400 | /* Retrieve/store value in SMBBLKDAT */ |
368 | if (read_write == I2C_SMBUS_READ) | 401 | if (read_write == I2C_SMBUS_READ) |
369 | data->block[i] = inb_p(SMBBLKDAT); | 402 | data->block[i] = inb_p(SMBBLKDAT(priv)); |
370 | if (read_write == I2C_SMBUS_WRITE && i+1 <= len) | 403 | if (read_write == I2C_SMBUS_WRITE && i+1 <= len) |
371 | outb_p(data->block[i+1], SMBBLKDAT); | 404 | outb_p(data->block[i+1], SMBBLKDAT(priv)); |
372 | 405 | ||
373 | /* signals SMBBLKDAT ready */ | 406 | /* signals SMBBLKDAT ready */ |
374 | outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS); | 407 | outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS(priv)); |
375 | } | 408 | } |
376 | 409 | ||
377 | return 0; | 410 | return 0; |
378 | } | 411 | } |
379 | 412 | ||
380 | static int i801_set_block_buffer_mode(void) | 413 | static int i801_set_block_buffer_mode(struct i801_priv *priv) |
381 | { | 414 | { |
382 | outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); | 415 | outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv)); |
383 | if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) | 416 | if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0) |
384 | return -EIO; | 417 | return -EIO; |
385 | return 0; | 418 | return 0; |
386 | } | 419 | } |
387 | 420 | ||
388 | /* Block transaction function */ | 421 | /* Block transaction function */ |
389 | static int i801_block_transaction(union i2c_smbus_data *data, char read_write, | 422 | static int i801_block_transaction(struct i801_priv *priv, |
423 | union i2c_smbus_data *data, char read_write, | ||
390 | int command, int hwpec) | 424 | int command, int hwpec) |
391 | { | 425 | { |
392 | int result = 0; | 426 | int result = 0; |
@@ -395,11 +429,11 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write, | |||
395 | if (command == I2C_SMBUS_I2C_BLOCK_DATA) { | 429 | if (command == I2C_SMBUS_I2C_BLOCK_DATA) { |
396 | if (read_write == I2C_SMBUS_WRITE) { | 430 | if (read_write == I2C_SMBUS_WRITE) { |
397 | /* set I2C_EN bit in configuration register */ | 431 | /* set I2C_EN bit in configuration register */ |
398 | pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc); | 432 | pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc); |
399 | pci_write_config_byte(I801_dev, SMBHSTCFG, | 433 | pci_write_config_byte(priv->pci_dev, SMBHSTCFG, |
400 | hostc | SMBHSTCFG_I2C_EN); | 434 | hostc | SMBHSTCFG_I2C_EN); |
401 | } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { | 435 | } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) { |
402 | dev_err(&I801_dev->dev, | 436 | dev_err(&priv->pci_dev->dev, |
403 | "I2C block read is unsupported!\n"); | 437 | "I2C block read is unsupported!\n"); |
404 | return -EOPNOTSUPP; | 438 | return -EOPNOTSUPP; |
405 | } | 439 | } |
@@ -415,114 +449,121 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write, | |||
415 | data->block[0] = 32; /* max for SMBus block reads */ | 449 | data->block[0] = 32; /* max for SMBus block reads */ |
416 | } | 450 | } |
417 | 451 | ||
418 | if ((i801_features & FEATURE_BLOCK_BUFFER) | 452 | /* Experience has shown that the block buffer can only be used for |
419 | && !(command == I2C_SMBUS_I2C_BLOCK_DATA | 453 | SMBus (not I2C) block transactions, even though the datasheet |
420 | && read_write == I2C_SMBUS_READ) | 454 | doesn't mention this limitation. */ |
421 | && i801_set_block_buffer_mode() == 0) | 455 | if ((priv->features & FEATURE_BLOCK_BUFFER) |
422 | result = i801_block_transaction_by_block(data, read_write, | 456 | && command != I2C_SMBUS_I2C_BLOCK_DATA |
423 | hwpec); | 457 | && i801_set_block_buffer_mode(priv) == 0) |
458 | result = i801_block_transaction_by_block(priv, data, | ||
459 | read_write, hwpec); | ||
424 | else | 460 | else |
425 | result = i801_block_transaction_byte_by_byte(data, read_write, | 461 | result = i801_block_transaction_byte_by_byte(priv, data, |
462 | read_write, | ||
426 | command, hwpec); | 463 | command, hwpec); |
427 | 464 | ||
428 | if (result == 0 && hwpec) | 465 | if (result == 0 && hwpec) |
429 | i801_wait_hwpec(); | 466 | i801_wait_hwpec(priv); |
430 | 467 | ||
431 | if (command == I2C_SMBUS_I2C_BLOCK_DATA | 468 | if (command == I2C_SMBUS_I2C_BLOCK_DATA |
432 | && read_write == I2C_SMBUS_WRITE) { | 469 | && read_write == I2C_SMBUS_WRITE) { |
433 | /* restore saved configuration register value */ | 470 | /* restore saved configuration register value */ |
434 | pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); | 471 | pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc); |
435 | } | 472 | } |
436 | return result; | 473 | return result; |
437 | } | 474 | } |
438 | 475 | ||
439 | /* Return negative errno on error. */ | 476 | /* Return negative errno on error. */ |
440 | static s32 i801_access(struct i2c_adapter * adap, u16 addr, | 477 | static s32 i801_access(struct i2c_adapter *adap, u16 addr, |
441 | unsigned short flags, char read_write, u8 command, | 478 | unsigned short flags, char read_write, u8 command, |
442 | int size, union i2c_smbus_data * data) | 479 | int size, union i2c_smbus_data *data) |
443 | { | 480 | { |
444 | int hwpec; | 481 | int hwpec; |
445 | int block = 0; | 482 | int block = 0; |
446 | int ret, xact = 0; | 483 | int ret, xact = 0; |
484 | struct i801_priv *priv = i2c_get_adapdata(adap); | ||
447 | 485 | ||
448 | hwpec = (i801_features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) | 486 | hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) |
449 | && size != I2C_SMBUS_QUICK | 487 | && size != I2C_SMBUS_QUICK |
450 | && size != I2C_SMBUS_I2C_BLOCK_DATA; | 488 | && size != I2C_SMBUS_I2C_BLOCK_DATA; |
451 | 489 | ||
452 | switch (size) { | 490 | switch (size) { |
453 | case I2C_SMBUS_QUICK: | 491 | case I2C_SMBUS_QUICK: |
454 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 492 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
455 | SMBHSTADD); | 493 | SMBHSTADD(priv)); |
456 | xact = I801_QUICK; | 494 | xact = I801_QUICK; |
457 | break; | 495 | break; |
458 | case I2C_SMBUS_BYTE: | 496 | case I2C_SMBUS_BYTE: |
459 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 497 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
460 | SMBHSTADD); | 498 | SMBHSTADD(priv)); |
461 | if (read_write == I2C_SMBUS_WRITE) | 499 | if (read_write == I2C_SMBUS_WRITE) |
462 | outb_p(command, SMBHSTCMD); | 500 | outb_p(command, SMBHSTCMD(priv)); |
463 | xact = I801_BYTE; | 501 | xact = I801_BYTE; |
464 | break; | 502 | break; |
465 | case I2C_SMBUS_BYTE_DATA: | 503 | case I2C_SMBUS_BYTE_DATA: |
466 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 504 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
467 | SMBHSTADD); | 505 | SMBHSTADD(priv)); |
468 | outb_p(command, SMBHSTCMD); | 506 | outb_p(command, SMBHSTCMD(priv)); |
469 | if (read_write == I2C_SMBUS_WRITE) | 507 | if (read_write == I2C_SMBUS_WRITE) |
470 | outb_p(data->byte, SMBHSTDAT0); | 508 | outb_p(data->byte, SMBHSTDAT0(priv)); |
471 | xact = I801_BYTE_DATA; | 509 | xact = I801_BYTE_DATA; |
472 | break; | 510 | break; |
473 | case I2C_SMBUS_WORD_DATA: | 511 | case I2C_SMBUS_WORD_DATA: |
474 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 512 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
475 | SMBHSTADD); | 513 | SMBHSTADD(priv)); |
476 | outb_p(command, SMBHSTCMD); | 514 | outb_p(command, SMBHSTCMD(priv)); |
477 | if (read_write == I2C_SMBUS_WRITE) { | 515 | if (read_write == I2C_SMBUS_WRITE) { |
478 | outb_p(data->word & 0xff, SMBHSTDAT0); | 516 | outb_p(data->word & 0xff, SMBHSTDAT0(priv)); |
479 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); | 517 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv)); |
480 | } | 518 | } |
481 | xact = I801_WORD_DATA; | 519 | xact = I801_WORD_DATA; |
482 | break; | 520 | break; |
483 | case I2C_SMBUS_BLOCK_DATA: | 521 | case I2C_SMBUS_BLOCK_DATA: |
484 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), | 522 | outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), |
485 | SMBHSTADD); | 523 | SMBHSTADD(priv)); |
486 | outb_p(command, SMBHSTCMD); | 524 | outb_p(command, SMBHSTCMD(priv)); |
487 | block = 1; | 525 | block = 1; |
488 | break; | 526 | break; |
489 | case I2C_SMBUS_I2C_BLOCK_DATA: | 527 | case I2C_SMBUS_I2C_BLOCK_DATA: |
490 | /* NB: page 240 of ICH5 datasheet shows that the R/#W | 528 | /* NB: page 240 of ICH5 datasheet shows that the R/#W |
491 | * bit should be cleared here, even when reading */ | 529 | * bit should be cleared here, even when reading */ |
492 | outb_p((addr & 0x7f) << 1, SMBHSTADD); | 530 | outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); |
493 | if (read_write == I2C_SMBUS_READ) { | 531 | if (read_write == I2C_SMBUS_READ) { |
494 | /* NB: page 240 of ICH5 datasheet also shows | 532 | /* NB: page 240 of ICH5 datasheet also shows |
495 | * that DATA1 is the cmd field when reading */ | 533 | * that DATA1 is the cmd field when reading */ |
496 | outb_p(command, SMBHSTDAT1); | 534 | outb_p(command, SMBHSTDAT1(priv)); |
497 | } else | 535 | } else |
498 | outb_p(command, SMBHSTCMD); | 536 | outb_p(command, SMBHSTCMD(priv)); |
499 | block = 1; | 537 | block = 1; |
500 | break; | 538 | break; |
501 | default: | 539 | default: |
502 | dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); | 540 | dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n", |
541 | size); | ||
503 | return -EOPNOTSUPP; | 542 | return -EOPNOTSUPP; |
504 | } | 543 | } |
505 | 544 | ||
506 | if (hwpec) /* enable/disable hardware PEC */ | 545 | if (hwpec) /* enable/disable hardware PEC */ |
507 | outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_CRC, SMBAUXCTL); | 546 | outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv)); |
508 | else | 547 | else |
509 | outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL); | 548 | outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), |
549 | SMBAUXCTL(priv)); | ||
510 | 550 | ||
511 | if(block) | 551 | if (block) |
512 | ret = i801_block_transaction(data, read_write, size, hwpec); | 552 | ret = i801_block_transaction(priv, data, read_write, size, |
553 | hwpec); | ||
513 | else | 554 | else |
514 | ret = i801_transaction(xact | ENABLE_INT9); | 555 | ret = i801_transaction(priv, xact | ENABLE_INT9); |
515 | 556 | ||
516 | /* Some BIOSes don't like it when PEC is enabled at reboot or resume | 557 | /* Some BIOSes don't like it when PEC is enabled at reboot or resume |
517 | time, so we forcibly disable it after every transaction. Turn off | 558 | time, so we forcibly disable it after every transaction. Turn off |
518 | E32B for the same reason. */ | 559 | E32B for the same reason. */ |
519 | if (hwpec || block) | 560 | if (hwpec || block) |
520 | outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), | 561 | outb_p(inb_p(SMBAUXCTL(priv)) & |
521 | SMBAUXCTL); | 562 | ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); |
522 | 563 | ||
523 | if(block) | 564 | if (block) |
524 | return ret; | 565 | return ret; |
525 | if(ret) | 566 | if (ret) |
526 | return ret; | 567 | return ret; |
527 | if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) | 568 | if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) |
528 | return 0; | 569 | return 0; |
@@ -530,10 +571,11 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr, | |||
530 | switch (xact & 0x7f) { | 571 | switch (xact & 0x7f) { |
531 | case I801_BYTE: /* Result put in SMBHSTDAT0 */ | 572 | case I801_BYTE: /* Result put in SMBHSTDAT0 */ |
532 | case I801_BYTE_DATA: | 573 | case I801_BYTE_DATA: |
533 | data->byte = inb_p(SMBHSTDAT0); | 574 | data->byte = inb_p(SMBHSTDAT0(priv)); |
534 | break; | 575 | break; |
535 | case I801_WORD_DATA: | 576 | case I801_WORD_DATA: |
536 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); | 577 | data->word = inb_p(SMBHSTDAT0(priv)) + |
578 | (inb_p(SMBHSTDAT1(priv)) << 8); | ||
537 | break; | 579 | break; |
538 | } | 580 | } |
539 | return 0; | 581 | return 0; |
@@ -542,11 +584,13 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr, | |||
542 | 584 | ||
543 | static u32 i801_func(struct i2c_adapter *adapter) | 585 | static u32 i801_func(struct i2c_adapter *adapter) |
544 | { | 586 | { |
587 | struct i801_priv *priv = i2c_get_adapdata(adapter); | ||
588 | |||
545 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 589 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
546 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | 590 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | |
547 | I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK | | 591 | I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK | |
548 | ((i801_features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | | 592 | ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) | |
549 | ((i801_features & FEATURE_I2C_BLOCK_READ) ? | 593 | ((priv->features & FEATURE_I2C_BLOCK_READ) ? |
550 | I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0); | 594 | I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0); |
551 | } | 595 | } |
552 | 596 | ||
@@ -555,13 +599,7 @@ static const struct i2c_algorithm smbus_algorithm = { | |||
555 | .functionality = i801_func, | 599 | .functionality = i801_func, |
556 | }; | 600 | }; |
557 | 601 | ||
558 | static struct i2c_adapter i801_adapter = { | 602 | static const struct pci_device_id i801_ids[] = { |
559 | .owner = THIS_MODULE, | ||
560 | .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, | ||
561 | .algo = &smbus_algorithm, | ||
562 | }; | ||
563 | |||
564 | static struct pci_device_id i801_ids[] = { | ||
565 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, | 603 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, |
566 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, | 604 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, |
567 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) }, | 605 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) }, |
@@ -574,14 +612,19 @@ static struct pci_device_id i801_ids[] = { | |||
574 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) }, | 612 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) }, |
575 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) }, | 613 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) }, |
576 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) }, | 614 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) }, |
577 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) }, | 615 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) }, |
578 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) }, | 616 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) }, |
579 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) }, | 617 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) }, |
580 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PCH_SMBUS) }, | 618 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) }, |
619 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) }, | ||
620 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) }, | ||
621 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) }, | ||
622 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) }, | ||
623 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) }, | ||
581 | { 0, } | 624 | { 0, } |
582 | }; | 625 | }; |
583 | 626 | ||
584 | MODULE_DEVICE_TABLE (pci, i801_ids); | 627 | MODULE_DEVICE_TABLE(pci, i801_ids); |
585 | 628 | ||
586 | #if defined CONFIG_INPUT_APANEL || defined CONFIG_INPUT_APANEL_MODULE | 629 | #if defined CONFIG_INPUT_APANEL || defined CONFIG_INPUT_APANEL_MODULE |
587 | static unsigned char apanel_addr; | 630 | static unsigned char apanel_addr; |
@@ -641,7 +684,7 @@ static void __devinit dmi_check_onboard_device(u8 type, const char *name, | |||
641 | /* & ~0x80, ignore enabled/disabled bit */ | 684 | /* & ~0x80, ignore enabled/disabled bit */ |
642 | if ((type & ~0x80) != dmi_devices[i].type) | 685 | if ((type & ~0x80) != dmi_devices[i].type) |
643 | continue; | 686 | continue; |
644 | if (strcmp(name, dmi_devices[i].name)) | 687 | if (strcasecmp(name, dmi_devices[i].name)) |
645 | continue; | 688 | continue; |
646 | 689 | ||
647 | memset(&info, 0, sizeof(struct i2c_board_info)); | 690 | memset(&info, 0, sizeof(struct i2c_board_info)); |
@@ -685,36 +728,46 @@ static void __devinit dmi_check_onboard_devices(const struct dmi_header *dm, | |||
685 | } | 728 | } |
686 | #endif | 729 | #endif |
687 | 730 | ||
688 | static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id) | 731 | static int __devinit i801_probe(struct pci_dev *dev, |
732 | const struct pci_device_id *id) | ||
689 | { | 733 | { |
690 | unsigned char temp; | 734 | unsigned char temp; |
691 | int err; | 735 | int err, i; |
692 | #if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE | 736 | struct i801_priv *priv; |
693 | const char *vendor; | ||
694 | #endif | ||
695 | 737 | ||
696 | I801_dev = dev; | 738 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
697 | i801_features = 0; | 739 | if (!priv) |
740 | return -ENOMEM; | ||
741 | |||
742 | i2c_set_adapdata(&priv->adapter, priv); | ||
743 | priv->adapter.owner = THIS_MODULE; | ||
744 | priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | ||
745 | priv->adapter.algo = &smbus_algorithm; | ||
746 | |||
747 | priv->pci_dev = dev; | ||
698 | switch (dev->device) { | 748 | switch (dev->device) { |
699 | case PCI_DEVICE_ID_INTEL_82801EB_3: | 749 | default: |
700 | case PCI_DEVICE_ID_INTEL_ESB_4: | 750 | priv->features |= FEATURE_I2C_BLOCK_READ; |
701 | case PCI_DEVICE_ID_INTEL_ICH6_16: | ||
702 | case PCI_DEVICE_ID_INTEL_ICH7_17: | ||
703 | case PCI_DEVICE_ID_INTEL_ESB2_17: | ||
704 | case PCI_DEVICE_ID_INTEL_ICH8_5: | ||
705 | case PCI_DEVICE_ID_INTEL_ICH9_6: | ||
706 | case PCI_DEVICE_ID_INTEL_TOLAPAI_1: | ||
707 | case PCI_DEVICE_ID_INTEL_ICH10_4: | ||
708 | case PCI_DEVICE_ID_INTEL_ICH10_5: | ||
709 | case PCI_DEVICE_ID_INTEL_PCH_SMBUS: | ||
710 | i801_features |= FEATURE_I2C_BLOCK_READ; | ||
711 | /* fall through */ | 751 | /* fall through */ |
712 | case PCI_DEVICE_ID_INTEL_82801DB_3: | 752 | case PCI_DEVICE_ID_INTEL_82801DB_3: |
713 | i801_features |= FEATURE_SMBUS_PEC; | 753 | priv->features |= FEATURE_SMBUS_PEC; |
714 | i801_features |= FEATURE_BLOCK_BUFFER; | 754 | priv->features |= FEATURE_BLOCK_BUFFER; |
755 | /* fall through */ | ||
756 | case PCI_DEVICE_ID_INTEL_82801CA_3: | ||
757 | case PCI_DEVICE_ID_INTEL_82801BA_2: | ||
758 | case PCI_DEVICE_ID_INTEL_82801AB_3: | ||
759 | case PCI_DEVICE_ID_INTEL_82801AA_3: | ||
715 | break; | 760 | break; |
716 | } | 761 | } |
717 | 762 | ||
763 | /* Disable features on user request */ | ||
764 | for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) { | ||
765 | if (priv->features & disable_features & (1 << i)) | ||
766 | dev_notice(&dev->dev, "%s disabled by user\n", | ||
767 | i801_feature_names[i]); | ||
768 | } | ||
769 | priv->features &= ~disable_features; | ||
770 | |||
718 | err = pci_enable_device(dev); | 771 | err = pci_enable_device(dev); |
719 | if (err) { | 772 | if (err) { |
720 | dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", | 773 | dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n", |
@@ -723,8 +776,8 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id | |||
723 | } | 776 | } |
724 | 777 | ||
725 | /* Determine the address of the SMBus area */ | 778 | /* Determine the address of the SMBus area */ |
726 | i801_smba = pci_resource_start(dev, SMBBAR); | 779 | priv->smba = pci_resource_start(dev, SMBBAR); |
727 | if (!i801_smba) { | 780 | if (!priv->smba) { |
728 | dev_err(&dev->dev, "SMBus base address uninitialized, " | 781 | dev_err(&dev->dev, "SMBus base address uninitialized, " |
729 | "upgrade BIOS\n"); | 782 | "upgrade BIOS\n"); |
730 | err = -ENODEV; | 783 | err = -ENODEV; |
@@ -732,25 +785,27 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id | |||
732 | } | 785 | } |
733 | 786 | ||
734 | err = acpi_check_resource_conflict(&dev->resource[SMBBAR]); | 787 | err = acpi_check_resource_conflict(&dev->resource[SMBBAR]); |
735 | if (err) | 788 | if (err) { |
789 | err = -ENODEV; | ||
736 | goto exit; | 790 | goto exit; |
791 | } | ||
737 | 792 | ||
738 | err = pci_request_region(dev, SMBBAR, i801_driver.name); | 793 | err = pci_request_region(dev, SMBBAR, i801_driver.name); |
739 | if (err) { | 794 | if (err) { |
740 | dev_err(&dev->dev, "Failed to request SMBus region " | 795 | dev_err(&dev->dev, "Failed to request SMBus region " |
741 | "0x%lx-0x%Lx\n", i801_smba, | 796 | "0x%lx-0x%Lx\n", priv->smba, |
742 | (unsigned long long)pci_resource_end(dev, SMBBAR)); | 797 | (unsigned long long)pci_resource_end(dev, SMBBAR)); |
743 | goto exit; | 798 | goto exit; |
744 | } | 799 | } |
745 | 800 | ||
746 | pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); | 801 | pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp); |
747 | i801_original_hstcfg = temp; | 802 | priv->original_hstcfg = temp; |
748 | temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ | 803 | temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */ |
749 | if (!(temp & SMBHSTCFG_HST_EN)) { | 804 | if (!(temp & SMBHSTCFG_HST_EN)) { |
750 | dev_info(&dev->dev, "Enabling SMBus device\n"); | 805 | dev_info(&dev->dev, "Enabling SMBus device\n"); |
751 | temp |= SMBHSTCFG_HST_EN; | 806 | temp |= SMBHSTCFG_HST_EN; |
752 | } | 807 | } |
753 | pci_write_config_byte(I801_dev, SMBHSTCFG, temp); | 808 | pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp); |
754 | 809 | ||
755 | if (temp & SMBHSTCFG_SMB_SMI_EN) | 810 | if (temp & SMBHSTCFG_SMB_SMI_EN) |
756 | dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n"); | 811 | dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n"); |
@@ -758,16 +813,19 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id | |||
758 | dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); | 813 | dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); |
759 | 814 | ||
760 | /* Clear special mode bits */ | 815 | /* Clear special mode bits */ |
761 | if (i801_features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) | 816 | if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) |
762 | outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), | 817 | outb_p(inb_p(SMBAUXCTL(priv)) & |
763 | SMBAUXCTL); | 818 | ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv)); |
764 | 819 | ||
765 | /* set up the sysfs linkage to our parent device */ | 820 | /* set up the sysfs linkage to our parent device */ |
766 | i801_adapter.dev.parent = &dev->dev; | 821 | priv->adapter.dev.parent = &dev->dev; |
767 | 822 | ||
768 | snprintf(i801_adapter.name, sizeof(i801_adapter.name), | 823 | /* Retry up to 3 times on lost arbitration */ |
769 | "SMBus I801 adapter at %04lx", i801_smba); | 824 | priv->adapter.retries = 3; |
770 | err = i2c_add_adapter(&i801_adapter); | 825 | |
826 | snprintf(priv->adapter.name, sizeof(priv->adapter.name), | ||
827 | "SMBus I801 adapter at %04lx", priv->smba); | ||
828 | err = i2c_add_adapter(&priv->adapter); | ||
771 | if (err) { | 829 | if (err) { |
772 | dev_err(&dev->dev, "Failed to add SMBus adapter\n"); | 830 | dev_err(&dev->dev, "Failed to add SMBus adapter\n"); |
773 | goto exit_release; | 831 | goto exit_release; |
@@ -781,28 +839,33 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id | |||
781 | memset(&info, 0, sizeof(struct i2c_board_info)); | 839 | memset(&info, 0, sizeof(struct i2c_board_info)); |
782 | info.addr = apanel_addr; | 840 | info.addr = apanel_addr; |
783 | strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE); | 841 | strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE); |
784 | i2c_new_device(&i801_adapter, &info); | 842 | i2c_new_device(&priv->adapter, &info); |
785 | } | 843 | } |
786 | #endif | 844 | #endif |
787 | #if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE | 845 | #if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE |
788 | vendor = dmi_get_system_info(DMI_BOARD_VENDOR); | 846 | if (dmi_name_in_vendors("FUJITSU")) |
789 | if (vendor && !strcmp(vendor, "FUJITSU SIEMENS")) | 847 | dmi_walk(dmi_check_onboard_devices, &priv->adapter); |
790 | dmi_walk(dmi_check_onboard_devices, &i801_adapter); | ||
791 | #endif | 848 | #endif |
792 | 849 | ||
850 | pci_set_drvdata(dev, priv); | ||
793 | return 0; | 851 | return 0; |
794 | 852 | ||
795 | exit_release: | 853 | exit_release: |
796 | pci_release_region(dev, SMBBAR); | 854 | pci_release_region(dev, SMBBAR); |
797 | exit: | 855 | exit: |
856 | kfree(priv); | ||
798 | return err; | 857 | return err; |
799 | } | 858 | } |
800 | 859 | ||
801 | static void __devexit i801_remove(struct pci_dev *dev) | 860 | static void __devexit i801_remove(struct pci_dev *dev) |
802 | { | 861 | { |
803 | i2c_del_adapter(&i801_adapter); | 862 | struct i801_priv *priv = pci_get_drvdata(dev); |
804 | pci_write_config_byte(I801_dev, SMBHSTCFG, i801_original_hstcfg); | 863 | |
864 | i2c_del_adapter(&priv->adapter); | ||
865 | pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); | ||
805 | pci_release_region(dev, SMBBAR); | 866 | pci_release_region(dev, SMBBAR); |
867 | pci_set_drvdata(dev, NULL); | ||
868 | kfree(priv); | ||
806 | /* | 869 | /* |
807 | * do not call pci_disable_device(dev) since it can cause hard hangs on | 870 | * do not call pci_disable_device(dev) since it can cause hard hangs on |
808 | * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010) | 871 | * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010) |
@@ -812,8 +875,10 @@ static void __devexit i801_remove(struct pci_dev *dev) | |||
812 | #ifdef CONFIG_PM | 875 | #ifdef CONFIG_PM |
813 | static int i801_suspend(struct pci_dev *dev, pm_message_t mesg) | 876 | static int i801_suspend(struct pci_dev *dev, pm_message_t mesg) |
814 | { | 877 | { |
878 | struct i801_priv *priv = pci_get_drvdata(dev); | ||
879 | |||
815 | pci_save_state(dev); | 880 | pci_save_state(dev); |
816 | pci_write_config_byte(dev, SMBHSTCFG, i801_original_hstcfg); | 881 | pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg); |
817 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); | 882 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); |
818 | return 0; | 883 | return 0; |
819 | } | 884 | } |
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c index e4476743f203..6e3c38240336 100644 --- a/drivers/i2c/busses/i2c-ibm_iic.c +++ b/drivers/i2c/busses/i2c-ibm_iic.c | |||
@@ -39,9 +39,8 @@ | |||
39 | #include <linux/init.h> | 39 | #include <linux/init.h> |
40 | #include <linux/interrupt.h> | 40 | #include <linux/interrupt.h> |
41 | #include <asm/irq.h> | 41 | #include <asm/irq.h> |
42 | #include <asm/io.h> | 42 | #include <linux/io.h> |
43 | #include <linux/i2c.h> | 43 | #include <linux/i2c.h> |
44 | #include <linux/i2c-id.h> | ||
45 | #include <linux/of_platform.h> | 44 | #include <linux/of_platform.h> |
46 | #include <linux/of_i2c.h> | 45 | #include <linux/of_i2c.h> |
47 | 46 | ||
@@ -85,10 +84,11 @@ static void dump_iic_regs(const char* header, struct ibm_iic_private* dev) | |||
85 | { | 84 | { |
86 | volatile struct iic_regs __iomem *iic = dev->vaddr; | 85 | volatile struct iic_regs __iomem *iic = dev->vaddr; |
87 | printk(KERN_DEBUG "ibm-iic%d: %s\n", dev->idx, header); | 86 | printk(KERN_DEBUG "ibm-iic%d: %s\n", dev->idx, header); |
88 | printk(KERN_DEBUG " cntl = 0x%02x, mdcntl = 0x%02x\n" | 87 | printk(KERN_DEBUG |
89 | KERN_DEBUG " sts = 0x%02x, extsts = 0x%02x\n" | 88 | " cntl = 0x%02x, mdcntl = 0x%02x\n" |
90 | KERN_DEBUG " clkdiv = 0x%02x, xfrcnt = 0x%02x\n" | 89 | " sts = 0x%02x, extsts = 0x%02x\n" |
91 | KERN_DEBUG " xtcntlss = 0x%02x, directcntl = 0x%02x\n", | 90 | " clkdiv = 0x%02x, xfrcnt = 0x%02x\n" |
91 | " xtcntlss = 0x%02x, directcntl = 0x%02x\n", | ||
92 | in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts), | 92 | in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts), |
93 | in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt), | 93 | in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt), |
94 | in_8(&iic->xtcntlss), in_8(&iic->directcntl)); | 94 | in_8(&iic->xtcntlss), in_8(&iic->directcntl)); |
@@ -660,19 +660,19 @@ static inline u8 iic_clckdiv(unsigned int opb) | |||
660 | return (u8)((opb + 9) / 10 - 1); | 660 | return (u8)((opb + 9) / 10 - 1); |
661 | } | 661 | } |
662 | 662 | ||
663 | static int __devinit iic_request_irq(struct of_device *ofdev, | 663 | static int __devinit iic_request_irq(struct platform_device *ofdev, |
664 | struct ibm_iic_private *dev) | 664 | struct ibm_iic_private *dev) |
665 | { | 665 | { |
666 | struct device_node *np = ofdev->node; | 666 | struct device_node *np = ofdev->dev.of_node; |
667 | int irq; | 667 | int irq; |
668 | 668 | ||
669 | if (iic_force_poll) | 669 | if (iic_force_poll) |
670 | return NO_IRQ; | 670 | return 0; |
671 | 671 | ||
672 | irq = irq_of_parse_and_map(np, 0); | 672 | irq = irq_of_parse_and_map(np, 0); |
673 | if (irq == NO_IRQ) { | 673 | if (!irq) { |
674 | dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n"); | 674 | dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n"); |
675 | return NO_IRQ; | 675 | return 0; |
676 | } | 676 | } |
677 | 677 | ||
678 | /* Disable interrupts until we finish initialization, assumes | 678 | /* Disable interrupts until we finish initialization, assumes |
@@ -682,7 +682,7 @@ static int __devinit iic_request_irq(struct of_device *ofdev, | |||
682 | if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) { | 682 | if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) { |
683 | dev_err(&ofdev->dev, "request_irq %d failed\n", irq); | 683 | dev_err(&ofdev->dev, "request_irq %d failed\n", irq); |
684 | /* Fallback to the polling mode */ | 684 | /* Fallback to the polling mode */ |
685 | return NO_IRQ; | 685 | return 0; |
686 | } | 686 | } |
687 | 687 | ||
688 | return irq; | 688 | return irq; |
@@ -691,10 +691,10 @@ static int __devinit iic_request_irq(struct of_device *ofdev, | |||
691 | /* | 691 | /* |
692 | * Register single IIC interface | 692 | * Register single IIC interface |
693 | */ | 693 | */ |
694 | static int __devinit iic_probe(struct of_device *ofdev, | 694 | static int __devinit iic_probe(struct platform_device *ofdev, |
695 | const struct of_device_id *match) | 695 | const struct of_device_id *match) |
696 | { | 696 | { |
697 | struct device_node *np = ofdev->node; | 697 | struct device_node *np = ofdev->dev.of_node; |
698 | struct ibm_iic_private *dev; | 698 | struct ibm_iic_private *dev; |
699 | struct i2c_adapter *adap; | 699 | struct i2c_adapter *adap; |
700 | const u32 *freq; | 700 | const u32 *freq; |
@@ -718,7 +718,7 @@ static int __devinit iic_probe(struct of_device *ofdev, | |||
718 | init_waitqueue_head(&dev->wq); | 718 | init_waitqueue_head(&dev->wq); |
719 | 719 | ||
720 | dev->irq = iic_request_irq(ofdev, dev); | 720 | dev->irq = iic_request_irq(ofdev, dev); |
721 | if (dev->irq == NO_IRQ) | 721 | if (!dev->irq) |
722 | dev_warn(&ofdev->dev, "using polling mode\n"); | 722 | dev_warn(&ofdev->dev, "using polling mode\n"); |
723 | 723 | ||
724 | /* Board specific settings */ | 724 | /* Board specific settings */ |
@@ -744,6 +744,7 @@ static int __devinit iic_probe(struct of_device *ofdev, | |||
744 | /* Register it with i2c layer */ | 744 | /* Register it with i2c layer */ |
745 | adap = &dev->adap; | 745 | adap = &dev->adap; |
746 | adap->dev.parent = &ofdev->dev; | 746 | adap->dev.parent = &ofdev->dev; |
747 | adap->dev.of_node = of_node_get(np); | ||
747 | strlcpy(adap->name, "IBM IIC", sizeof(adap->name)); | 748 | strlcpy(adap->name, "IBM IIC", sizeof(adap->name)); |
748 | i2c_set_adapdata(adap, dev); | 749 | i2c_set_adapdata(adap, dev); |
749 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 750 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
@@ -760,12 +761,12 @@ static int __devinit iic_probe(struct of_device *ofdev, | |||
760 | dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); | 761 | dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); |
761 | 762 | ||
762 | /* Now register all the child nodes */ | 763 | /* Now register all the child nodes */ |
763 | of_register_i2c_devices(adap, np); | 764 | of_i2c_register_devices(adap); |
764 | 765 | ||
765 | return 0; | 766 | return 0; |
766 | 767 | ||
767 | error_cleanup: | 768 | error_cleanup: |
768 | if (dev->irq != NO_IRQ) { | 769 | if (dev->irq) { |
769 | iic_interrupt_mode(dev, 0); | 770 | iic_interrupt_mode(dev, 0); |
770 | free_irq(dev->irq, dev); | 771 | free_irq(dev->irq, dev); |
771 | } | 772 | } |
@@ -781,7 +782,7 @@ error_cleanup: | |||
781 | /* | 782 | /* |
782 | * Cleanup initialized IIC interface | 783 | * Cleanup initialized IIC interface |
783 | */ | 784 | */ |
784 | static int __devexit iic_remove(struct of_device *ofdev) | 785 | static int __devexit iic_remove(struct platform_device *ofdev) |
785 | { | 786 | { |
786 | struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev); | 787 | struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev); |
787 | 788 | ||
@@ -789,7 +790,7 @@ static int __devexit iic_remove(struct of_device *ofdev) | |||
789 | 790 | ||
790 | i2c_del_adapter(&dev->adap); | 791 | i2c_del_adapter(&dev->adap); |
791 | 792 | ||
792 | if (dev->irq != NO_IRQ) { | 793 | if (dev->irq) { |
793 | iic_interrupt_mode(dev, 0); | 794 | iic_interrupt_mode(dev, 0); |
794 | free_irq(dev->irq, dev); | 795 | free_irq(dev->irq, dev); |
795 | } | 796 | } |
@@ -806,8 +807,11 @@ static const struct of_device_id ibm_iic_match[] = { | |||
806 | }; | 807 | }; |
807 | 808 | ||
808 | static struct of_platform_driver ibm_iic_driver = { | 809 | static struct of_platform_driver ibm_iic_driver = { |
809 | .name = "ibm-iic", | 810 | .driver = { |
810 | .match_table = ibm_iic_match, | 811 | .name = "ibm-iic", |
812 | .owner = THIS_MODULE, | ||
813 | .of_match_table = ibm_iic_match, | ||
814 | }, | ||
811 | .probe = iic_probe, | 815 | .probe = iic_probe, |
812 | .remove = __devexit_p(iic_remove), | 816 | .remove = __devexit_p(iic_remove), |
813 | }; | 817 | }; |
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 0b486a63460d..4c2a62b75b5c 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/sched.h> | 47 | #include <linux/sched.h> |
48 | #include <linux/platform_device.h> | 48 | #include <linux/platform_device.h> |
49 | #include <linux/clk.h> | 49 | #include <linux/clk.h> |
50 | #include <linux/slab.h> | ||
50 | 51 | ||
51 | #include <mach/irqs.h> | 52 | #include <mach/irqs.h> |
52 | #include <mach/hardware.h> | 53 | #include <mach/hardware.h> |
@@ -120,28 +121,35 @@ struct imx_i2c_struct { | |||
120 | wait_queue_head_t queue; | 121 | wait_queue_head_t queue; |
121 | unsigned long i2csr; | 122 | unsigned long i2csr; |
122 | unsigned int disable_delay; | 123 | unsigned int disable_delay; |
124 | int stopped; | ||
125 | unsigned int ifdr; /* IMX_I2C_IFDR */ | ||
123 | }; | 126 | }; |
124 | 127 | ||
125 | /** Functions for IMX I2C adapter driver *************************************** | 128 | /** Functions for IMX I2C adapter driver *************************************** |
126 | *******************************************************************************/ | 129 | *******************************************************************************/ |
127 | 130 | ||
128 | static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx) | 131 | static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy) |
129 | { | 132 | { |
130 | unsigned long orig_jiffies = jiffies; | 133 | unsigned long orig_jiffies = jiffies; |
134 | unsigned int temp; | ||
131 | 135 | ||
132 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); | 136 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); |
133 | 137 | ||
134 | /* wait for bus not busy */ | 138 | while (1) { |
135 | while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) { | 139 | temp = readb(i2c_imx->base + IMX_I2C_I2SR); |
140 | if (for_busy && (temp & I2SR_IBB)) | ||
141 | break; | ||
142 | if (!for_busy && !(temp & I2SR_IBB)) | ||
143 | break; | ||
136 | if (signal_pending(current)) { | 144 | if (signal_pending(current)) { |
137 | dev_dbg(&i2c_imx->adapter.dev, | 145 | dev_dbg(&i2c_imx->adapter.dev, |
138 | "<%s> I2C Interrupted\n", __func__); | 146 | "<%s> I2C Interrupted\n", __func__); |
139 | return -EINTR; | 147 | return -EINTR; |
140 | } | 148 | } |
141 | if (time_after(jiffies, orig_jiffies + HZ / 1000)) { | 149 | if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { |
142 | dev_dbg(&i2c_imx->adapter.dev, | 150 | dev_dbg(&i2c_imx->adapter.dev, |
143 | "<%s> I2C bus is busy\n", __func__); | 151 | "<%s> I2C bus is busy\n", __func__); |
144 | return -EIO; | 152 | return -ETIMEDOUT; |
145 | } | 153 | } |
146 | schedule(); | 154 | schedule(); |
147 | } | 155 | } |
@@ -151,15 +159,9 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx) | |||
151 | 159 | ||
152 | static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx) | 160 | static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx) |
153 | { | 161 | { |
154 | int result; | 162 | wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10); |
155 | |||
156 | result = wait_event_interruptible_timeout(i2c_imx->queue, | ||
157 | i2c_imx->i2csr & I2SR_IIF, HZ / 10); | ||
158 | 163 | ||
159 | if (unlikely(result < 0)) { | 164 | if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) { |
160 | dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__); | ||
161 | return result; | ||
162 | } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) { | ||
163 | dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__); | 165 | dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__); |
164 | return -ETIMEDOUT; | 166 | return -ETIMEDOUT; |
165 | } | 167 | } |
@@ -179,41 +181,63 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx) | |||
179 | return 0; | 181 | return 0; |
180 | } | 182 | } |
181 | 183 | ||
182 | static void i2c_imx_start(struct imx_i2c_struct *i2c_imx) | 184 | static int i2c_imx_start(struct imx_i2c_struct *i2c_imx) |
183 | { | 185 | { |
184 | unsigned int temp = 0; | 186 | unsigned int temp = 0; |
187 | int result; | ||
185 | 188 | ||
186 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); | 189 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); |
187 | 190 | ||
191 | clk_enable(i2c_imx->clk); | ||
192 | writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR); | ||
188 | /* Enable I2C controller */ | 193 | /* Enable I2C controller */ |
194 | writeb(0, i2c_imx->base + IMX_I2C_I2SR); | ||
189 | writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR); | 195 | writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR); |
196 | |||
197 | /* Wait controller to be stable */ | ||
198 | udelay(50); | ||
199 | |||
190 | /* Start I2C transaction */ | 200 | /* Start I2C transaction */ |
191 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); | 201 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); |
192 | temp |= I2CR_MSTA; | 202 | temp |= I2CR_MSTA; |
193 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); | 203 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); |
204 | result = i2c_imx_bus_busy(i2c_imx, 1); | ||
205 | if (result) | ||
206 | return result; | ||
207 | i2c_imx->stopped = 0; | ||
208 | |||
194 | temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK; | 209 | temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK; |
195 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); | 210 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); |
211 | return result; | ||
196 | } | 212 | } |
197 | 213 | ||
198 | static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx) | 214 | static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx) |
199 | { | 215 | { |
200 | unsigned int temp = 0; | 216 | unsigned int temp = 0; |
201 | 217 | ||
202 | /* Stop I2C transaction */ | 218 | if (!i2c_imx->stopped) { |
203 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); | 219 | /* Stop I2C transaction */ |
204 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); | 220 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); |
205 | temp &= ~I2CR_MSTA; | 221 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); |
206 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); | 222 | temp &= ~(I2CR_MSTA | I2CR_MTX); |
207 | /* setup chip registers to defaults */ | 223 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); |
208 | writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR); | 224 | } |
209 | writeb(0, i2c_imx->base + IMX_I2C_I2SR); | 225 | if (cpu_is_mx1()) { |
210 | /* | 226 | /* |
211 | * This delay caused by an i.MXL hardware bug. | 227 | * This delay caused by an i.MXL hardware bug. |
212 | * If no (or too short) delay, no "STOP" bit will be generated. | 228 | * If no (or too short) delay, no "STOP" bit will be generated. |
213 | */ | 229 | */ |
214 | udelay(i2c_imx->disable_delay); | 230 | udelay(i2c_imx->disable_delay); |
231 | } | ||
232 | |||
233 | if (!i2c_imx->stopped) { | ||
234 | i2c_imx_bus_busy(i2c_imx, 0); | ||
235 | i2c_imx->stopped = 1; | ||
236 | } | ||
237 | |||
215 | /* Disable I2C controller */ | 238 | /* Disable I2C controller */ |
216 | writeb(0, i2c_imx->base + IMX_I2C_I2CR); | 239 | writeb(0, i2c_imx->base + IMX_I2C_I2CR); |
240 | clk_disable(i2c_imx->clk); | ||
217 | } | 241 | } |
218 | 242 | ||
219 | static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, | 243 | static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, |
@@ -233,8 +257,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, | |||
233 | else | 257 | else |
234 | for (i = 0; i2c_clk_div[i][0] < div; i++); | 258 | for (i = 0; i2c_clk_div[i][0] < div; i++); |
235 | 259 | ||
236 | /* Write divider value to register */ | 260 | /* Store divider value */ |
237 | writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR); | 261 | i2c_imx->ifdr = i2c_clk_div[i][1]; |
238 | 262 | ||
239 | /* | 263 | /* |
240 | * There dummy delay is calculated. | 264 | * There dummy delay is calculated. |
@@ -265,7 +289,7 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id) | |||
265 | i2c_imx->i2csr = temp; | 289 | i2c_imx->i2csr = temp; |
266 | temp &= ~I2SR_IIF; | 290 | temp &= ~I2SR_IIF; |
267 | writeb(temp, i2c_imx->base + IMX_I2C_I2SR); | 291 | writeb(temp, i2c_imx->base + IMX_I2C_I2SR); |
268 | wake_up_interruptible(&i2c_imx->queue); | 292 | wake_up(&i2c_imx->queue); |
269 | return IRQ_HANDLED; | 293 | return IRQ_HANDLED; |
270 | } | 294 | } |
271 | 295 | ||
@@ -341,11 +365,15 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs) | |||
341 | if (result) | 365 | if (result) |
342 | return result; | 366 | return result; |
343 | if (i == (msgs->len - 1)) { | 367 | if (i == (msgs->len - 1)) { |
368 | /* It must generate STOP before read I2DR to prevent | ||
369 | controller from generating another clock cycle */ | ||
344 | dev_dbg(&i2c_imx->adapter.dev, | 370 | dev_dbg(&i2c_imx->adapter.dev, |
345 | "<%s> clear MSTA\n", __func__); | 371 | "<%s> clear MSTA\n", __func__); |
346 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); | 372 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); |
347 | temp &= ~I2CR_MSTA; | 373 | temp &= ~(I2CR_MSTA | I2CR_MTX); |
348 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); | 374 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); |
375 | i2c_imx_bus_busy(i2c_imx, 0); | ||
376 | i2c_imx->stopped = 1; | ||
349 | } else if (i == (msgs->len - 2)) { | 377 | } else if (i == (msgs->len - 2)) { |
350 | dev_dbg(&i2c_imx->adapter.dev, | 378 | dev_dbg(&i2c_imx->adapter.dev, |
351 | "<%s> set TXAK\n", __func__); | 379 | "<%s> set TXAK\n", __func__); |
@@ -370,14 +398,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter, | |||
370 | 398 | ||
371 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); | 399 | dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); |
372 | 400 | ||
373 | /* Check if i2c bus is not busy */ | 401 | /* Start I2C transfer */ |
374 | result = i2c_imx_bus_busy(i2c_imx); | 402 | result = i2c_imx_start(i2c_imx); |
375 | if (result) | 403 | if (result) |
376 | goto fail0; | 404 | goto fail0; |
377 | 405 | ||
378 | /* Start I2C transfer */ | ||
379 | i2c_imx_start(i2c_imx); | ||
380 | |||
381 | /* read/write data */ | 406 | /* read/write data */ |
382 | for (i = 0; i < num; i++) { | 407 | for (i = 0; i < num; i++) { |
383 | if (i) { | 408 | if (i) { |
@@ -386,6 +411,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter, | |||
386 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); | 411 | temp = readb(i2c_imx->base + IMX_I2C_I2CR); |
387 | temp |= I2CR_RSTA; | 412 | temp |= I2CR_RSTA; |
388 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); | 413 | writeb(temp, i2c_imx->base + IMX_I2C_I2CR); |
414 | result = i2c_imx_bus_busy(i2c_imx, 1); | ||
415 | if (result) | ||
416 | goto fail0; | ||
389 | } | 417 | } |
390 | dev_dbg(&i2c_imx->adapter.dev, | 418 | dev_dbg(&i2c_imx->adapter.dev, |
391 | "<%s> transfer message: %d\n", __func__, i); | 419 | "<%s> transfer message: %d\n", __func__, i); |
@@ -410,6 +438,8 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter, | |||
410 | result = i2c_imx_read(i2c_imx, &msgs[i]); | 438 | result = i2c_imx_read(i2c_imx, &msgs[i]); |
411 | else | 439 | else |
412 | result = i2c_imx_write(i2c_imx, &msgs[i]); | 440 | result = i2c_imx_write(i2c_imx, &msgs[i]); |
441 | if (result) | ||
442 | goto fail0; | ||
413 | } | 443 | } |
414 | 444 | ||
415 | fail0: | 445 | fail0: |
@@ -464,22 +494,23 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
464 | } | 494 | } |
465 | 495 | ||
466 | res_size = resource_size(res); | 496 | res_size = resource_size(res); |
497 | |||
498 | if (!request_mem_region(res->start, res_size, DRIVER_NAME)) { | ||
499 | ret = -EBUSY; | ||
500 | goto fail0; | ||
501 | } | ||
502 | |||
467 | base = ioremap(res->start, res_size); | 503 | base = ioremap(res->start, res_size); |
468 | if (!base) { | 504 | if (!base) { |
469 | dev_err(&pdev->dev, "ioremap failed\n"); | 505 | dev_err(&pdev->dev, "ioremap failed\n"); |
470 | ret = -EIO; | 506 | ret = -EIO; |
471 | goto fail0; | 507 | goto fail1; |
472 | } | 508 | } |
473 | 509 | ||
474 | i2c_imx = kzalloc(sizeof(struct imx_i2c_struct), GFP_KERNEL); | 510 | i2c_imx = kzalloc(sizeof(struct imx_i2c_struct), GFP_KERNEL); |
475 | if (!i2c_imx) { | 511 | if (!i2c_imx) { |
476 | dev_err(&pdev->dev, "can't allocate interface\n"); | 512 | dev_err(&pdev->dev, "can't allocate interface\n"); |
477 | ret = -ENOMEM; | 513 | ret = -ENOMEM; |
478 | goto fail1; | ||
479 | } | ||
480 | |||
481 | if (!request_mem_region(res->start, res_size, DRIVER_NAME)) { | ||
482 | ret = -EBUSY; | ||
483 | goto fail2; | 514 | goto fail2; |
484 | } | 515 | } |
485 | 516 | ||
@@ -500,7 +531,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
500 | dev_err(&pdev->dev, "can't get I2C clock\n"); | 531 | dev_err(&pdev->dev, "can't get I2C clock\n"); |
501 | goto fail3; | 532 | goto fail3; |
502 | } | 533 | } |
503 | clk_enable(i2c_imx->clk); | ||
504 | 534 | ||
505 | /* Request IRQ */ | 535 | /* Request IRQ */ |
506 | ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx); | 536 | ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx); |
@@ -549,14 +579,13 @@ static int __init i2c_imx_probe(struct platform_device *pdev) | |||
549 | fail5: | 579 | fail5: |
550 | free_irq(i2c_imx->irq, i2c_imx); | 580 | free_irq(i2c_imx->irq, i2c_imx); |
551 | fail4: | 581 | fail4: |
552 | clk_disable(i2c_imx->clk); | ||
553 | clk_put(i2c_imx->clk); | 582 | clk_put(i2c_imx->clk); |
554 | fail3: | 583 | fail3: |
555 | release_mem_region(i2c_imx->res->start, resource_size(res)); | ||
556 | fail2: | ||
557 | kfree(i2c_imx); | 584 | kfree(i2c_imx); |
558 | fail1: | 585 | fail2: |
559 | iounmap(base); | 586 | iounmap(base); |
587 | fail1: | ||
588 | release_mem_region(res->start, resource_size(res)); | ||
560 | fail0: | 589 | fail0: |
561 | if (pdata && pdata->exit) | 590 | if (pdata && pdata->exit) |
562 | pdata->exit(&pdev->dev); | 591 | pdata->exit(&pdev->dev); |
@@ -586,18 +615,15 @@ static int __exit i2c_imx_remove(struct platform_device *pdev) | |||
586 | if (pdata && pdata->exit) | 615 | if (pdata && pdata->exit) |
587 | pdata->exit(&pdev->dev); | 616 | pdata->exit(&pdev->dev); |
588 | 617 | ||
589 | /* Disable I2C clock */ | ||
590 | clk_disable(i2c_imx->clk); | ||
591 | clk_put(i2c_imx->clk); | 618 | clk_put(i2c_imx->clk); |
592 | 619 | ||
593 | release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res)); | ||
594 | iounmap(i2c_imx->base); | 620 | iounmap(i2c_imx->base); |
621 | release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res)); | ||
595 | kfree(i2c_imx); | 622 | kfree(i2c_imx); |
596 | return 0; | 623 | return 0; |
597 | } | 624 | } |
598 | 625 | ||
599 | static struct platform_driver i2c_imx_driver = { | 626 | static struct platform_driver i2c_imx_driver = { |
600 | .probe = i2c_imx_probe, | ||
601 | .remove = __exit_p(i2c_imx_remove), | 627 | .remove = __exit_p(i2c_imx_remove), |
602 | .driver = { | 628 | .driver = { |
603 | .name = DRIVER_NAME, | 629 | .name = DRIVER_NAME, |
@@ -609,13 +635,12 @@ static int __init i2c_adap_imx_init(void) | |||
609 | { | 635 | { |
610 | return platform_driver_probe(&i2c_imx_driver, i2c_imx_probe); | 636 | return platform_driver_probe(&i2c_imx_driver, i2c_imx_probe); |
611 | } | 637 | } |
638 | subsys_initcall(i2c_adap_imx_init); | ||
612 | 639 | ||
613 | static void __exit i2c_adap_imx_exit(void) | 640 | static void __exit i2c_adap_imx_exit(void) |
614 | { | 641 | { |
615 | platform_driver_unregister(&i2c_imx_driver); | 642 | platform_driver_unregister(&i2c_imx_driver); |
616 | } | 643 | } |
617 | |||
618 | module_init(i2c_adap_imx_init); | ||
619 | module_exit(i2c_adap_imx_exit); | 644 | module_exit(i2c_adap_imx_exit); |
620 | 645 | ||
621 | MODULE_LICENSE("GPL"); | 646 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c new file mode 100644 index 000000000000..c71492782bbd --- /dev/null +++ b/drivers/i2c/busses/i2c-intel-mid.c | |||
@@ -0,0 +1,1135 @@ | |||
1 | /* | ||
2 | * Support for Moorestown/Medfield I2C chip | ||
3 | * | ||
4 | * Copyright (c) 2009 Intel Corporation. | ||
5 | * Copyright (c) 2009 Synopsys. Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, version | ||
9 | * 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope it will be useful, but WITHOUT ANY | ||
12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
14 | * details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., 51 | ||
18 | * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/err.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/stat.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/i2c.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/pci.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/pm_runtime.h> | ||
33 | #include <linux/io.h> | ||
34 | |||
35 | #define DRIVER_NAME "i2c-intel-mid" | ||
36 | #define VERSION "Version 0.5ac2" | ||
37 | #define PLATFORM "Moorestown/Medfield" | ||
38 | |||
39 | /* Tables use: 0 Moorestown, 1 Medfield */ | ||
40 | #define NUM_PLATFORMS 2 | ||
41 | enum platform_enum { | ||
42 | MOORESTOWN = 0, | ||
43 | MEDFIELD = 1, | ||
44 | }; | ||
45 | |||
46 | enum mid_i2c_status { | ||
47 | STATUS_IDLE = 0, | ||
48 | STATUS_READ_START, | ||
49 | STATUS_READ_IN_PROGRESS, | ||
50 | STATUS_READ_SUCCESS, | ||
51 | STATUS_WRITE_START, | ||
52 | STATUS_WRITE_SUCCESS, | ||
53 | STATUS_XFER_ABORT, | ||
54 | STATUS_STANDBY | ||
55 | }; | ||
56 | |||
57 | /** | ||
58 | * struct intel_mid_i2c_private - per device I²C context | ||
59 | * @adap: core i2c layer adapter information | ||
60 | * @dev: device reference for power management | ||
61 | * @base: register base | ||
62 | * @speed: speed mode for this port | ||
63 | * @complete: completion object for transaction wait | ||
64 | * @abort: reason for last abort | ||
65 | * @rx_buf: pointer into working receive buffer | ||
66 | * @rx_buf_len: receive buffer length | ||
67 | * @status: adapter state machine | ||
68 | * @msg: the message we are currently processing | ||
69 | * @platform: the MID device type we are part of | ||
70 | * @lock: transaction serialization | ||
71 | * | ||
72 | * We allocate one of these per device we discover, it holds the core | ||
73 | * i2c layer objects and the data we need to track privately. | ||
74 | */ | ||
75 | struct intel_mid_i2c_private { | ||
76 | struct i2c_adapter adap; | ||
77 | struct device *dev; | ||
78 | void __iomem *base; | ||
79 | int speed; | ||
80 | struct completion complete; | ||
81 | int abort; | ||
82 | u8 *rx_buf; | ||
83 | int rx_buf_len; | ||
84 | enum mid_i2c_status status; | ||
85 | struct i2c_msg *msg; | ||
86 | enum platform_enum platform; | ||
87 | struct mutex lock; | ||
88 | }; | ||
89 | |||
90 | #define NUM_SPEEDS 3 | ||
91 | |||
92 | #define ACTIVE 0 | ||
93 | #define STANDBY 1 | ||
94 | |||
95 | |||
96 | /* Control register */ | ||
97 | #define IC_CON 0x00 | ||
98 | #define SLV_DIS (1 << 6) /* Disable slave mode */ | ||
99 | #define RESTART (1 << 5) /* Send a Restart condition */ | ||
100 | #define ADDR_10BIT (1 << 4) /* 10-bit addressing */ | ||
101 | #define STANDARD_MODE (1 << 1) /* standard mode */ | ||
102 | #define FAST_MODE (2 << 1) /* fast mode */ | ||
103 | #define HIGH_MODE (3 << 1) /* high speed mode */ | ||
104 | #define MASTER_EN (1 << 0) /* Master mode */ | ||
105 | |||
106 | /* Target address register */ | ||
107 | #define IC_TAR 0x04 | ||
108 | #define IC_TAR_10BIT_ADDR (1 << 12) /* 10-bit addressing */ | ||
109 | #define IC_TAR_SPECIAL (1 << 11) /* Perform special I2C cmd */ | ||
110 | #define IC_TAR_GC_OR_START (1 << 10) /* 0: Gerneral Call Address */ | ||
111 | /* 1: START BYTE */ | ||
112 | /* Slave Address Register */ | ||
113 | #define IC_SAR 0x08 /* Not used in Master mode */ | ||
114 | |||
115 | /* High Speed Master Mode Code Address Register */ | ||
116 | #define IC_HS_MADDR 0x0c | ||
117 | |||
118 | /* Rx/Tx Data Buffer and Command Register */ | ||
119 | #define IC_DATA_CMD 0x10 | ||
120 | #define IC_RD (1 << 8) /* 1: Read 0: Write */ | ||
121 | |||
122 | /* Standard Speed Clock SCL High Count Register */ | ||
123 | #define IC_SS_SCL_HCNT 0x14 | ||
124 | |||
125 | /* Standard Speed Clock SCL Low Count Register */ | ||
126 | #define IC_SS_SCL_LCNT 0x18 | ||
127 | |||
128 | /* Fast Speed Clock SCL High Count Register */ | ||
129 | #define IC_FS_SCL_HCNT 0x1c | ||
130 | |||
131 | /* Fast Spedd Clock SCL Low Count Register */ | ||
132 | #define IC_FS_SCL_LCNT 0x20 | ||
133 | |||
134 | /* High Speed Clock SCL High Count Register */ | ||
135 | #define IC_HS_SCL_HCNT 0x24 | ||
136 | |||
137 | /* High Speed Clock SCL Low Count Register */ | ||
138 | #define IC_HS_SCL_LCNT 0x28 | ||
139 | |||
140 | /* Interrupt Status Register */ | ||
141 | #define IC_INTR_STAT 0x2c /* Read only */ | ||
142 | #define R_GEN_CALL (1 << 11) | ||
143 | #define R_START_DET (1 << 10) | ||
144 | #define R_STOP_DET (1 << 9) | ||
145 | #define R_ACTIVITY (1 << 8) | ||
146 | #define R_RX_DONE (1 << 7) | ||
147 | #define R_TX_ABRT (1 << 6) | ||
148 | #define R_RD_REQ (1 << 5) | ||
149 | #define R_TX_EMPTY (1 << 4) | ||
150 | #define R_TX_OVER (1 << 3) | ||
151 | #define R_RX_FULL (1 << 2) | ||
152 | #define R_RX_OVER (1 << 1) | ||
153 | #define R_RX_UNDER (1 << 0) | ||
154 | |||
155 | /* Interrupt Mask Register */ | ||
156 | #define IC_INTR_MASK 0x30 /* Read and Write */ | ||
157 | #define M_GEN_CALL (1 << 11) | ||
158 | #define M_START_DET (1 << 10) | ||
159 | #define M_STOP_DET (1 << 9) | ||
160 | #define M_ACTIVITY (1 << 8) | ||
161 | #define M_RX_DONE (1 << 7) | ||
162 | #define M_TX_ABRT (1 << 6) | ||
163 | #define M_RD_REQ (1 << 5) | ||
164 | #define M_TX_EMPTY (1 << 4) | ||
165 | #define M_TX_OVER (1 << 3) | ||
166 | #define M_RX_FULL (1 << 2) | ||
167 | #define M_RX_OVER (1 << 1) | ||
168 | #define M_RX_UNDER (1 << 0) | ||
169 | |||
170 | /* Raw Interrupt Status Register */ | ||
171 | #define IC_RAW_INTR_STAT 0x34 /* Read Only */ | ||
172 | #define GEN_CALL (1 << 11) /* General call */ | ||
173 | #define START_DET (1 << 10) /* (RE)START occured */ | ||
174 | #define STOP_DET (1 << 9) /* STOP occured */ | ||
175 | #define ACTIVITY (1 << 8) /* Bus busy */ | ||
176 | #define RX_DONE (1 << 7) /* Not used in Master mode */ | ||
177 | #define TX_ABRT (1 << 6) /* Transmit Abort */ | ||
178 | #define RD_REQ (1 << 5) /* Not used in Master mode */ | ||
179 | #define TX_EMPTY (1 << 4) /* TX FIFO <= threshold */ | ||
180 | #define TX_OVER (1 << 3) /* TX FIFO overflow */ | ||
181 | #define RX_FULL (1 << 2) /* RX FIFO >= threshold */ | ||
182 | #define RX_OVER (1 << 1) /* RX FIFO overflow */ | ||
183 | #define RX_UNDER (1 << 0) /* RX FIFO empty */ | ||
184 | |||
185 | /* Receive FIFO Threshold Register */ | ||
186 | #define IC_RX_TL 0x38 | ||
187 | |||
188 | /* Transmit FIFO Treshold Register */ | ||
189 | #define IC_TX_TL 0x3c | ||
190 | |||
191 | /* Clear Combined and Individual Interrupt Register */ | ||
192 | #define IC_CLR_INTR 0x40 | ||
193 | #define CLR_INTR (1 << 0) | ||
194 | |||
195 | /* Clear RX_UNDER Interrupt Register */ | ||
196 | #define IC_CLR_RX_UNDER 0x44 | ||
197 | #define CLR_RX_UNDER (1 << 0) | ||
198 | |||
199 | /* Clear RX_OVER Interrupt Register */ | ||
200 | #define IC_CLR_RX_OVER 0x48 | ||
201 | #define CLR_RX_OVER (1 << 0) | ||
202 | |||
203 | /* Clear TX_OVER Interrupt Register */ | ||
204 | #define IC_CLR_TX_OVER 0x4c | ||
205 | #define CLR_TX_OVER (1 << 0) | ||
206 | |||
207 | #define IC_CLR_RD_REQ 0x50 | ||
208 | |||
209 | /* Clear TX_ABRT Interrupt Register */ | ||
210 | #define IC_CLR_TX_ABRT 0x54 | ||
211 | #define CLR_TX_ABRT (1 << 0) | ||
212 | #define IC_CLR_RX_DONE 0x58 | ||
213 | |||
214 | /* Clear ACTIVITY Interrupt Register */ | ||
215 | #define IC_CLR_ACTIVITY 0x5c | ||
216 | #define CLR_ACTIVITY (1 << 0) | ||
217 | |||
218 | /* Clear STOP_DET Interrupt Register */ | ||
219 | #define IC_CLR_STOP_DET 0x60 | ||
220 | #define CLR_STOP_DET (1 << 0) | ||
221 | |||
222 | /* Clear START_DET Interrupt Register */ | ||
223 | #define IC_CLR_START_DET 0x64 | ||
224 | #define CLR_START_DET (1 << 0) | ||
225 | |||
226 | /* Clear GEN_CALL Interrupt Register */ | ||
227 | #define IC_CLR_GEN_CALL 0x68 | ||
228 | #define CLR_GEN_CALL (1 << 0) | ||
229 | |||
230 | /* Enable Register */ | ||
231 | #define IC_ENABLE 0x6c | ||
232 | #define ENABLE (1 << 0) | ||
233 | |||
234 | /* Status Register */ | ||
235 | #define IC_STATUS 0x70 /* Read Only */ | ||
236 | #define STAT_SLV_ACTIVITY (1 << 6) /* Slave not in idle */ | ||
237 | #define STAT_MST_ACTIVITY (1 << 5) /* Master not in idle */ | ||
238 | #define STAT_RFF (1 << 4) /* RX FIFO Full */ | ||
239 | #define STAT_RFNE (1 << 3) /* RX FIFO Not Empty */ | ||
240 | #define STAT_TFE (1 << 2) /* TX FIFO Empty */ | ||
241 | #define STAT_TFNF (1 << 1) /* TX FIFO Not Full */ | ||
242 | #define STAT_ACTIVITY (1 << 0) /* Activity Status */ | ||
243 | |||
244 | /* Transmit FIFO Level Register */ | ||
245 | #define IC_TXFLR 0x74 /* Read Only */ | ||
246 | #define TXFLR (1 << 0) /* TX FIFO level */ | ||
247 | |||
248 | /* Receive FIFO Level Register */ | ||
249 | #define IC_RXFLR 0x78 /* Read Only */ | ||
250 | #define RXFLR (1 << 0) /* RX FIFO level */ | ||
251 | |||
252 | /* Transmit Abort Source Register */ | ||
253 | #define IC_TX_ABRT_SOURCE 0x80 | ||
254 | #define ABRT_SLVRD_INTX (1 << 15) | ||
255 | #define ABRT_SLV_ARBLOST (1 << 14) | ||
256 | #define ABRT_SLVFLUSH_TXFIFO (1 << 13) | ||
257 | #define ARB_LOST (1 << 12) | ||
258 | #define ABRT_MASTER_DIS (1 << 11) | ||
259 | #define ABRT_10B_RD_NORSTRT (1 << 10) | ||
260 | #define ABRT_SBYTE_NORSTRT (1 << 9) | ||
261 | #define ABRT_HS_NORSTRT (1 << 8) | ||
262 | #define ABRT_SBYTE_ACKDET (1 << 7) | ||
263 | #define ABRT_HS_ACKDET (1 << 6) | ||
264 | #define ABRT_GCALL_READ (1 << 5) | ||
265 | #define ABRT_GCALL_NOACK (1 << 4) | ||
266 | #define ABRT_TXDATA_NOACK (1 << 3) | ||
267 | #define ABRT_10ADDR2_NOACK (1 << 2) | ||
268 | #define ABRT_10ADDR1_NOACK (1 << 1) | ||
269 | #define ABRT_7B_ADDR_NOACK (1 << 0) | ||
270 | |||
271 | /* Enable Status Register */ | ||
272 | #define IC_ENABLE_STATUS 0x9c | ||
273 | #define IC_EN (1 << 0) /* I2C in an enabled state */ | ||
274 | |||
275 | /* Component Parameter Register 1*/ | ||
276 | #define IC_COMP_PARAM_1 0xf4 | ||
277 | #define APB_DATA_WIDTH (0x3 << 0) | ||
278 | |||
279 | /* added by xiaolin --begin */ | ||
280 | #define SS_MIN_SCL_HIGH 4000 | ||
281 | #define SS_MIN_SCL_LOW 4700 | ||
282 | #define FS_MIN_SCL_HIGH 600 | ||
283 | #define FS_MIN_SCL_LOW 1300 | ||
284 | #define HS_MIN_SCL_HIGH_100PF 60 | ||
285 | #define HS_MIN_SCL_LOW_100PF 120 | ||
286 | |||
287 | #define STANDARD 0 | ||
288 | #define FAST 1 | ||
289 | #define HIGH 2 | ||
290 | |||
291 | #define NUM_SPEEDS 3 | ||
292 | |||
293 | static int speed_mode[6] = { | ||
294 | FAST, | ||
295 | FAST, | ||
296 | FAST, | ||
297 | STANDARD, | ||
298 | FAST, | ||
299 | FAST | ||
300 | }; | ||
301 | |||
302 | static int ctl_num = 6; | ||
303 | module_param_array(speed_mode, int, &ctl_num, S_IRUGO); | ||
304 | MODULE_PARM_DESC(speed_mode, "Set the speed of the i2c interface (0-2)"); | ||
305 | |||
306 | /** | ||
307 | * intel_mid_i2c_disable - Disable I2C controller | ||
308 | * @adap: struct pointer to i2c_adapter | ||
309 | * | ||
310 | * Return Value: | ||
311 | * 0 success | ||
312 | * -EBUSY if device is busy | ||
313 | * -ETIMEDOUT if i2c cannot be disabled within the given time | ||
314 | * | ||
315 | * I2C bus state should be checked prior to disabling the hardware. If bus is | ||
316 | * not in idle state, an errno is returned. Write "0" to IC_ENABLE to disable | ||
317 | * I2C controller. | ||
318 | */ | ||
319 | static int intel_mid_i2c_disable(struct i2c_adapter *adap) | ||
320 | { | ||
321 | struct intel_mid_i2c_private *i2c = i2c_get_adapdata(adap); | ||
322 | int err = 0; | ||
323 | int count = 0; | ||
324 | int ret1, ret2; | ||
325 | static const u16 delay[NUM_SPEEDS] = {100, 25, 3}; | ||
326 | |||
327 | /* Set IC_ENABLE to 0 */ | ||
328 | writel(0, i2c->base + IC_ENABLE); | ||
329 | |||
330 | /* Check if device is busy */ | ||
331 | dev_dbg(&adap->dev, "mrst i2c disable\n"); | ||
332 | while ((ret1 = readl(i2c->base + IC_ENABLE_STATUS) & 0x1) | ||
333 | || (ret2 = readl(i2c->base + IC_STATUS) & 0x1)) { | ||
334 | udelay(delay[i2c->speed]); | ||
335 | writel(0, i2c->base + IC_ENABLE); | ||
336 | dev_dbg(&adap->dev, "i2c is busy, count is %d speed %d\n", | ||
337 | count, i2c->speed); | ||
338 | if (count++ > 10) { | ||
339 | err = -ETIMEDOUT; | ||
340 | break; | ||
341 | } | ||
342 | } | ||
343 | |||
344 | /* Clear all interrupts */ | ||
345 | readl(i2c->base + IC_CLR_INTR); | ||
346 | readl(i2c->base + IC_CLR_STOP_DET); | ||
347 | readl(i2c->base + IC_CLR_START_DET); | ||
348 | readl(i2c->base + IC_CLR_ACTIVITY); | ||
349 | readl(i2c->base + IC_CLR_TX_ABRT); | ||
350 | readl(i2c->base + IC_CLR_RX_OVER); | ||
351 | readl(i2c->base + IC_CLR_RX_UNDER); | ||
352 | readl(i2c->base + IC_CLR_TX_OVER); | ||
353 | readl(i2c->base + IC_CLR_RX_DONE); | ||
354 | readl(i2c->base + IC_CLR_GEN_CALL); | ||
355 | |||
356 | /* Disable all interupts */ | ||
357 | writel(0x0000, i2c->base + IC_INTR_MASK); | ||
358 | |||
359 | return err; | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * intel_mid_i2c_hwinit - Initialize the I2C hardware registers | ||
364 | * @dev: pci device struct pointer | ||
365 | * | ||
366 | * This function will be called in intel_mid_i2c_probe() before device | ||
367 | * registration. | ||
368 | * | ||
369 | * Return Values: | ||
370 | * 0 success | ||
371 | * -EBUSY i2c cannot be disabled | ||
372 | * -ETIMEDOUT i2c cannot be disabled | ||
373 | * -EFAULT If APB data width is not 32-bit wide | ||
374 | * | ||
375 | * I2C should be disabled prior to other register operation. If failed, an | ||
376 | * errno is returned. Mask and Clear all interrpts, this should be done at | ||
377 | * first. Set common registers which will not be modified during normal | ||
378 | * transfers, including: controll register, FIFO threshold and clock freq. | ||
379 | * Check APB data width at last. | ||
380 | */ | ||
381 | static int intel_mid_i2c_hwinit(struct intel_mid_i2c_private *i2c) | ||
382 | { | ||
383 | int err; | ||
384 | |||
385 | static const u16 hcnt[NUM_PLATFORMS][NUM_SPEEDS] = { | ||
386 | { 0x75, 0x15, 0x07 }, | ||
387 | { 0x04c, 0x10, 0x06 } | ||
388 | }; | ||
389 | static const u16 lcnt[NUM_PLATFORMS][NUM_SPEEDS] = { | ||
390 | { 0x7C, 0x21, 0x0E }, | ||
391 | { 0x053, 0x19, 0x0F } | ||
392 | }; | ||
393 | |||
394 | /* Disable i2c first */ | ||
395 | err = intel_mid_i2c_disable(&i2c->adap); | ||
396 | if (err) | ||
397 | return err; | ||
398 | |||
399 | /* | ||
400 | * Setup clock frequency and speed mode | ||
401 | * Enable restart condition, | ||
402 | * enable master FSM, disable slave FSM, | ||
403 | * use target address when initiating transfer | ||
404 | */ | ||
405 | |||
406 | writel((i2c->speed + 1) << 1 | SLV_DIS | RESTART | MASTER_EN, | ||
407 | i2c->base + IC_CON); | ||
408 | writel(hcnt[i2c->platform][i2c->speed], | ||
409 | i2c->base + (IC_SS_SCL_HCNT + (i2c->speed << 3))); | ||
410 | writel(lcnt[i2c->platform][i2c->speed], | ||
411 | i2c->base + (IC_SS_SCL_LCNT + (i2c->speed << 3))); | ||
412 | |||
413 | /* Set tranmit & receive FIFO threshold to zero */ | ||
414 | writel(0x0, i2c->base + IC_RX_TL); | ||
415 | writel(0x0, i2c->base + IC_TX_TL); | ||
416 | |||
417 | return 0; | ||
418 | } | ||
419 | |||
420 | /** | ||
421 | * intel_mid_i2c_func - Return the supported three I2C operations. | ||
422 | * @adapter: i2c_adapter struct pointer | ||
423 | */ | ||
424 | static u32 intel_mid_i2c_func(struct i2c_adapter *adapter) | ||
425 | { | ||
426 | return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SMBUS_EMUL; | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * intel_mid_i2c_address_neq - To check if the addresses for different i2c messages | ||
431 | * are equal. | ||
432 | * @p1: first i2c_msg | ||
433 | * @p2: second i2c_msg | ||
434 | * | ||
435 | * Return Values: | ||
436 | * 0 if addresses are equal | ||
437 | * 1 if not equal | ||
438 | * | ||
439 | * Within a single transfer, the I2C client may need to send its address more | ||
440 | * than once. So a check if the addresses match is needed. | ||
441 | */ | ||
442 | static inline bool intel_mid_i2c_address_neq(const struct i2c_msg *p1, | ||
443 | const struct i2c_msg *p2) | ||
444 | { | ||
445 | if (p1->addr != p2->addr) | ||
446 | return 1; | ||
447 | if ((p1->flags ^ p2->flags) & I2C_M_TEN) | ||
448 | return 1; | ||
449 | return 0; | ||
450 | } | ||
451 | |||
452 | /** | ||
453 | * intel_mid_i2c_abort - To handle transfer abortions and print error messages. | ||
454 | * @adap: i2c_adapter struct pointer | ||
455 | * | ||
456 | * By reading register IC_TX_ABRT_SOURCE, various transfer errors can be | ||
457 | * distingushed. At present, no circumstances have been found out that | ||
458 | * multiple errors would be occured simutaneously, so we simply use the | ||
459 | * register value directly. | ||
460 | * | ||
461 | * At last the error bits are cleared. (Note clear ABRT_SBYTE_NORSTRT bit need | ||
462 | * a few extra steps) | ||
463 | */ | ||
464 | static void intel_mid_i2c_abort(struct intel_mid_i2c_private *i2c) | ||
465 | { | ||
466 | /* Read about source register */ | ||
467 | int abort = i2c->abort; | ||
468 | struct i2c_adapter *adap = &i2c->adap; | ||
469 | |||
470 | /* Single transfer error check: | ||
471 | * According to databook, TX/RX FIFOs would be flushed when | ||
472 | * the abort interrupt occured. | ||
473 | */ | ||
474 | if (abort & ABRT_MASTER_DIS) | ||
475 | dev_err(&adap->dev, | ||
476 | "initiate master operation with master mode disabled.\n"); | ||
477 | if (abort & ABRT_10B_RD_NORSTRT) | ||
478 | dev_err(&adap->dev, | ||
479 | "RESTART disabled and master sent READ cmd in 10-bit addressing.\n"); | ||
480 | |||
481 | if (abort & ABRT_SBYTE_NORSTRT) { | ||
482 | dev_err(&adap->dev, | ||
483 | "RESTART disabled and user is trying to send START byte.\n"); | ||
484 | writel(~ABRT_SBYTE_NORSTRT, i2c->base + IC_TX_ABRT_SOURCE); | ||
485 | writel(RESTART, i2c->base + IC_CON); | ||
486 | writel(~IC_TAR_SPECIAL, i2c->base + IC_TAR); | ||
487 | } | ||
488 | |||
489 | if (abort & ABRT_SBYTE_ACKDET) | ||
490 | dev_err(&adap->dev, | ||
491 | "START byte was not acknowledged.\n"); | ||
492 | if (abort & ABRT_TXDATA_NOACK) | ||
493 | dev_dbg(&adap->dev, | ||
494 | "No acknowledgement received from slave.\n"); | ||
495 | if (abort & ABRT_10ADDR2_NOACK) | ||
496 | dev_dbg(&adap->dev, | ||
497 | "The 2nd address byte of the 10-bit address was not acknowledged.\n"); | ||
498 | if (abort & ABRT_10ADDR1_NOACK) | ||
499 | dev_dbg(&adap->dev, | ||
500 | "The 1st address byte of 10-bit address was not acknowledged.\n"); | ||
501 | if (abort & ABRT_7B_ADDR_NOACK) | ||
502 | dev_dbg(&adap->dev, | ||
503 | "I2C slave device not acknowledged.\n"); | ||
504 | |||
505 | /* Clear TX_ABRT bit */ | ||
506 | readl(i2c->base + IC_CLR_TX_ABRT); | ||
507 | i2c->status = STATUS_XFER_ABORT; | ||
508 | } | ||
509 | |||
510 | /** | ||
511 | * xfer_read - Internal function to implement master read transfer. | ||
512 | * @adap: i2c_adapter struct pointer | ||
513 | * @buf: buffer in i2c_msg | ||
514 | * @length: number of bytes to be read | ||
515 | * | ||
516 | * Return Values: | ||
517 | * 0 if the read transfer succeeds | ||
518 | * -ETIMEDOUT if cannot read the "raw" interrupt register | ||
519 | * -EINVAL if a transfer abort occurred | ||
520 | * | ||
521 | * For every byte, a "READ" command will be loaded into IC_DATA_CMD prior to | ||
522 | * data transfer. The actual "read" operation will be performed if an RX_FULL | ||
523 | * interrupt occurred. | ||
524 | * | ||
525 | * Note there may be two interrupt signals captured, one should read | ||
526 | * IC_RAW_INTR_STAT to separate between errors and actual data. | ||
527 | */ | ||
528 | static int xfer_read(struct i2c_adapter *adap, unsigned char *buf, int length) | ||
529 | { | ||
530 | struct intel_mid_i2c_private *i2c = i2c_get_adapdata(adap); | ||
531 | int i = length; | ||
532 | int err; | ||
533 | |||
534 | if (length >= 256) { | ||
535 | dev_err(&adap->dev, | ||
536 | "I2C FIFO cannot support larger than 256 bytes\n"); | ||
537 | return -EMSGSIZE; | ||
538 | } | ||
539 | |||
540 | INIT_COMPLETION(i2c->complete); | ||
541 | |||
542 | readl(i2c->base + IC_CLR_INTR); | ||
543 | writel(0x0044, i2c->base + IC_INTR_MASK); | ||
544 | |||
545 | i2c->status = STATUS_READ_START; | ||
546 | |||
547 | while (i--) | ||
548 | writel(IC_RD, i2c->base + IC_DATA_CMD); | ||
549 | |||
550 | i2c->status = STATUS_READ_START; | ||
551 | err = wait_for_completion_interruptible_timeout(&i2c->complete, HZ); | ||
552 | if (!err) { | ||
553 | dev_err(&adap->dev, "Timeout for ACK from I2C slave device\n"); | ||
554 | intel_mid_i2c_hwinit(i2c); | ||
555 | return -ETIMEDOUT; | ||
556 | } | ||
557 | if (i2c->status == STATUS_READ_SUCCESS) | ||
558 | return 0; | ||
559 | else | ||
560 | return -EIO; | ||
561 | } | ||
562 | |||
563 | /** | ||
564 | * xfer_write - Internal function to implement master write transfer. | ||
565 | * @adap: i2c_adapter struct pointer | ||
566 | * @buf: buffer in i2c_msg | ||
567 | * @length: number of bytes to be read | ||
568 | * | ||
569 | * Return Values: | ||
570 | * 0 if the read transfer succeeds | ||
571 | * -ETIMEDOUT if we cannot read the "raw" interrupt register | ||
572 | * -EINVAL if a transfer abort occured | ||
573 | * | ||
574 | * For every byte, a "WRITE" command will be loaded into IC_DATA_CMD prior to | ||
575 | * data transfer. The actual "write" operation will be performed when the | ||
576 | * RX_FULL interrupt signal occurs. | ||
577 | * | ||
578 | * Note there may be two interrupt signals captured, one should read | ||
579 | * IC_RAW_INTR_STAT to separate between errors and actual data. | ||
580 | */ | ||
581 | static int xfer_write(struct i2c_adapter *adap, | ||
582 | unsigned char *buf, int length) | ||
583 | { | ||
584 | struct intel_mid_i2c_private *i2c = i2c_get_adapdata(adap); | ||
585 | int i, err; | ||
586 | |||
587 | if (length >= 256) { | ||
588 | dev_err(&adap->dev, | ||
589 | "I2C FIFO cannot support larger than 256 bytes\n"); | ||
590 | return -EMSGSIZE; | ||
591 | } | ||
592 | |||
593 | INIT_COMPLETION(i2c->complete); | ||
594 | |||
595 | readl(i2c->base + IC_CLR_INTR); | ||
596 | writel(0x0050, i2c->base + IC_INTR_MASK); | ||
597 | |||
598 | i2c->status = STATUS_WRITE_START; | ||
599 | for (i = 0; i < length; i++) | ||
600 | writel((u16)(*(buf + i)), i2c->base + IC_DATA_CMD); | ||
601 | |||
602 | i2c->status = STATUS_WRITE_START; | ||
603 | err = wait_for_completion_interruptible_timeout(&i2c->complete, HZ); | ||
604 | if (!err) { | ||
605 | dev_err(&adap->dev, "Timeout for ACK from I2C slave device\n"); | ||
606 | intel_mid_i2c_hwinit(i2c); | ||
607 | return -ETIMEDOUT; | ||
608 | } else { | ||
609 | if (i2c->status == STATUS_WRITE_SUCCESS) | ||
610 | return 0; | ||
611 | else | ||
612 | return -EIO; | ||
613 | } | ||
614 | } | ||
615 | |||
616 | static int intel_mid_i2c_setup(struct i2c_adapter *adap, struct i2c_msg *pmsg) | ||
617 | { | ||
618 | struct intel_mid_i2c_private *i2c = i2c_get_adapdata(adap); | ||
619 | int err; | ||
620 | u32 reg; | ||
621 | u32 bit_mask; | ||
622 | u32 mode; | ||
623 | |||
624 | /* Disable device first */ | ||
625 | err = intel_mid_i2c_disable(adap); | ||
626 | if (err) { | ||
627 | dev_err(&adap->dev, | ||
628 | "Cannot disable i2c controller, timeout\n"); | ||
629 | return err; | ||
630 | } | ||
631 | |||
632 | mode = (1 + i2c->speed) << 1; | ||
633 | /* set the speed mode */ | ||
634 | reg = readl(i2c->base + IC_CON); | ||
635 | if ((reg & 0x06) != mode) { | ||
636 | dev_dbg(&adap->dev, "set mode %d\n", i2c->speed); | ||
637 | writel((reg & ~0x6) | mode, i2c->base + IC_CON); | ||
638 | } | ||
639 | |||
640 | reg = readl(i2c->base + IC_CON); | ||
641 | /* use 7-bit addressing */ | ||
642 | if (pmsg->flags & I2C_M_TEN) { | ||
643 | if ((reg & ADDR_10BIT) != ADDR_10BIT) { | ||
644 | dev_dbg(&adap->dev, "set i2c 10 bit address mode\n"); | ||
645 | writel(reg | ADDR_10BIT, i2c->base + IC_CON); | ||
646 | } | ||
647 | } else { | ||
648 | if ((reg & ADDR_10BIT) != 0x0) { | ||
649 | dev_dbg(&adap->dev, "set i2c 7 bit address mode\n"); | ||
650 | writel(reg & ~ADDR_10BIT, i2c->base + IC_CON); | ||
651 | } | ||
652 | } | ||
653 | /* enable restart conditions */ | ||
654 | reg = readl(i2c->base + IC_CON); | ||
655 | if ((reg & RESTART) != RESTART) { | ||
656 | dev_dbg(&adap->dev, "enable restart conditions\n"); | ||
657 | writel(reg | RESTART, i2c->base + IC_CON); | ||
658 | } | ||
659 | |||
660 | /* enable master FSM */ | ||
661 | reg = readl(i2c->base + IC_CON); | ||
662 | dev_dbg(&adap->dev, "ic_con reg is 0x%x\n", reg); | ||
663 | writel(reg | MASTER_EN, i2c->base + IC_CON); | ||
664 | if ((reg & SLV_DIS) != SLV_DIS) { | ||
665 | dev_dbg(&adap->dev, "enable master FSM\n"); | ||
666 | writel(reg | SLV_DIS, i2c->base + IC_CON); | ||
667 | dev_dbg(&adap->dev, "ic_con reg is 0x%x\n", reg); | ||
668 | } | ||
669 | |||
670 | /* use target address when initiating transfer */ | ||
671 | reg = readl(i2c->base + IC_TAR); | ||
672 | bit_mask = IC_TAR_SPECIAL | IC_TAR_GC_OR_START; | ||
673 | |||
674 | if ((reg & bit_mask) != 0x0) { | ||
675 | dev_dbg(&adap->dev, | ||
676 | "WR: use target address when intiating transfer, i2c_tx_target\n"); | ||
677 | writel(reg & ~bit_mask, i2c->base + IC_TAR); | ||
678 | } | ||
679 | |||
680 | /* set target address to the I2C slave address */ | ||
681 | dev_dbg(&adap->dev, | ||
682 | "set target address to the I2C slave address, addr is %x\n", | ||
683 | pmsg->addr); | ||
684 | writel(pmsg->addr | (pmsg->flags & I2C_M_TEN ? IC_TAR_10BIT_ADDR : 0), | ||
685 | i2c->base + IC_TAR); | ||
686 | |||
687 | /* Enable I2C controller */ | ||
688 | writel(ENABLE, i2c->base + IC_ENABLE); | ||
689 | |||
690 | return 0; | ||
691 | } | ||
692 | |||
693 | /** | ||
694 | * intel_mid_i2c_xfer - Main master transfer routine. | ||
695 | * @adap: i2c_adapter struct pointer | ||
696 | * @pmsg: i2c_msg struct pointer | ||
697 | * @num: number of i2c_msg | ||
698 | * | ||
699 | * Return Values: | ||
700 | * + number of messages transfered | ||
701 | * -ETIMEDOUT If cannot disable I2C controller or read IC_STATUS | ||
702 | * -EINVAL If the address in i2c_msg is invalid | ||
703 | * | ||
704 | * This function will be registered in i2c-core and exposed to external | ||
705 | * I2C clients. | ||
706 | * 1. Disable I2C controller | ||
707 | * 2. Unmask three interrupts: RX_FULL, TX_EMPTY, TX_ABRT | ||
708 | * 3. Check if address in i2c_msg is valid | ||
709 | * 4. Enable I2C controller | ||
710 | * 5. Perform real transfer (call xfer_read or xfer_write) | ||
711 | * 6. Wait until the current transfer is finished (check bus state) | ||
712 | * 7. Mask and clear all interrupts | ||
713 | */ | ||
714 | static int intel_mid_i2c_xfer(struct i2c_adapter *adap, | ||
715 | struct i2c_msg *pmsg, | ||
716 | int num) | ||
717 | { | ||
718 | struct intel_mid_i2c_private *i2c = i2c_get_adapdata(adap); | ||
719 | int i, err = 0; | ||
720 | |||
721 | /* if number of messages equal 0*/ | ||
722 | if (num == 0) | ||
723 | return 0; | ||
724 | |||
725 | pm_runtime_get(i2c->dev); | ||
726 | |||
727 | mutex_lock(&i2c->lock); | ||
728 | dev_dbg(&adap->dev, "intel_mid_i2c_xfer, process %d msg(s)\n", num); | ||
729 | dev_dbg(&adap->dev, "slave address is %x\n", pmsg->addr); | ||
730 | |||
731 | |||
732 | if (i2c->status != STATUS_IDLE) { | ||
733 | dev_err(&adap->dev, "Adapter %d in transfer/standby\n", | ||
734 | adap->nr); | ||
735 | mutex_unlock(&i2c->lock); | ||
736 | pm_runtime_put(i2c->dev); | ||
737 | return -1; | ||
738 | } | ||
739 | |||
740 | |||
741 | for (i = 1; i < num; i++) { | ||
742 | /* Message address equal? */ | ||
743 | if (unlikely(intel_mid_i2c_address_neq(&pmsg[0], &pmsg[i]))) { | ||
744 | dev_err(&adap->dev, "Invalid address in msg[%d]\n", i); | ||
745 | mutex_unlock(&i2c->lock); | ||
746 | pm_runtime_put(i2c->dev); | ||
747 | return -EINVAL; | ||
748 | } | ||
749 | } | ||
750 | |||
751 | if (intel_mid_i2c_setup(adap, pmsg)) { | ||
752 | mutex_unlock(&i2c->lock); | ||
753 | pm_runtime_put(i2c->dev); | ||
754 | return -EINVAL; | ||
755 | } | ||
756 | |||
757 | for (i = 0; i < num; i++) { | ||
758 | i2c->msg = pmsg; | ||
759 | i2c->status = STATUS_IDLE; | ||
760 | /* Read or Write */ | ||
761 | if (pmsg->flags & I2C_M_RD) { | ||
762 | dev_dbg(&adap->dev, "I2C_M_RD\n"); | ||
763 | err = xfer_read(adap, pmsg->buf, pmsg->len); | ||
764 | } else { | ||
765 | dev_dbg(&adap->dev, "I2C_M_WR\n"); | ||
766 | err = xfer_write(adap, pmsg->buf, pmsg->len); | ||
767 | } | ||
768 | if (err < 0) | ||
769 | break; | ||
770 | dev_dbg(&adap->dev, "msg[%d] transfer complete\n", i); | ||
771 | pmsg++; /* next message */ | ||
772 | } | ||
773 | |||
774 | /* Mask interrupts */ | ||
775 | writel(0x0000, i2c->base + IC_INTR_MASK); | ||
776 | /* Clear all interrupts */ | ||
777 | readl(i2c->base + IC_CLR_INTR); | ||
778 | |||
779 | i2c->status = STATUS_IDLE; | ||
780 | mutex_unlock(&i2c->lock); | ||
781 | pm_runtime_put(i2c->dev); | ||
782 | |||
783 | return err; | ||
784 | } | ||
785 | |||
786 | static int intel_mid_i2c_runtime_suspend(struct device *dev) | ||
787 | { | ||
788 | struct pci_dev *pdev = to_pci_dev(dev); | ||
789 | struct intel_mid_i2c_private *i2c = pci_get_drvdata(pdev); | ||
790 | struct i2c_adapter *adap = to_i2c_adapter(dev); | ||
791 | int err; | ||
792 | |||
793 | if (i2c->status != STATUS_IDLE) | ||
794 | return -1; | ||
795 | |||
796 | intel_mid_i2c_disable(adap); | ||
797 | |||
798 | err = pci_save_state(pdev); | ||
799 | if (err) { | ||
800 | dev_err(dev, "pci_save_state failed\n"); | ||
801 | return err; | ||
802 | } | ||
803 | |||
804 | err = pci_set_power_state(pdev, PCI_D3hot); | ||
805 | if (err) { | ||
806 | dev_err(dev, "pci_set_power_state failed\n"); | ||
807 | return err; | ||
808 | } | ||
809 | i2c->status = STATUS_STANDBY; | ||
810 | |||
811 | return 0; | ||
812 | } | ||
813 | |||
814 | static int intel_mid_i2c_runtime_resume(struct device *dev) | ||
815 | { | ||
816 | struct pci_dev *pdev = to_pci_dev(dev); | ||
817 | struct intel_mid_i2c_private *i2c = pci_get_drvdata(pdev); | ||
818 | int err; | ||
819 | |||
820 | if (i2c->status != STATUS_STANDBY) | ||
821 | return 0; | ||
822 | |||
823 | pci_set_power_state(pdev, PCI_D0); | ||
824 | pci_restore_state(pdev); | ||
825 | err = pci_enable_device(pdev); | ||
826 | if (err) { | ||
827 | dev_err(dev, "pci_enable_device failed\n"); | ||
828 | return err; | ||
829 | } | ||
830 | |||
831 | i2c->status = STATUS_IDLE; | ||
832 | |||
833 | intel_mid_i2c_hwinit(i2c); | ||
834 | return err; | ||
835 | } | ||
836 | |||
837 | static void i2c_isr_read(struct intel_mid_i2c_private *i2c) | ||
838 | { | ||
839 | struct i2c_msg *msg = i2c->msg; | ||
840 | int rx_num; | ||
841 | u32 len; | ||
842 | u8 *buf; | ||
843 | |||
844 | if (!(msg->flags & I2C_M_RD)) | ||
845 | return; | ||
846 | |||
847 | if (i2c->status != STATUS_READ_IN_PROGRESS) { | ||
848 | len = msg->len; | ||
849 | buf = msg->buf; | ||
850 | } else { | ||
851 | len = i2c->rx_buf_len; | ||
852 | buf = i2c->rx_buf; | ||
853 | } | ||
854 | |||
855 | rx_num = readl(i2c->base + IC_RXFLR); | ||
856 | |||
857 | for (; len > 0 && rx_num > 0; len--, rx_num--) | ||
858 | *buf++ = readl(i2c->base + IC_DATA_CMD); | ||
859 | |||
860 | if (len > 0) { | ||
861 | i2c->status = STATUS_READ_IN_PROGRESS; | ||
862 | i2c->rx_buf_len = len; | ||
863 | i2c->rx_buf = buf; | ||
864 | } else | ||
865 | i2c->status = STATUS_READ_SUCCESS; | ||
866 | |||
867 | return; | ||
868 | } | ||
869 | |||
870 | static irqreturn_t intel_mid_i2c_isr(int this_irq, void *dev) | ||
871 | { | ||
872 | struct intel_mid_i2c_private *i2c = dev; | ||
873 | u32 stat = readl(i2c->base + IC_INTR_STAT); | ||
874 | |||
875 | if (!stat) | ||
876 | return IRQ_NONE; | ||
877 | |||
878 | dev_dbg(&i2c->adap.dev, "%s, stat = 0x%x\n", __func__, stat); | ||
879 | stat &= 0x54; | ||
880 | |||
881 | if (i2c->status != STATUS_WRITE_START && | ||
882 | i2c->status != STATUS_READ_START && | ||
883 | i2c->status != STATUS_READ_IN_PROGRESS) | ||
884 | goto err; | ||
885 | |||
886 | if (stat & TX_ABRT) | ||
887 | i2c->abort = readl(i2c->base + IC_TX_ABRT_SOURCE); | ||
888 | |||
889 | readl(i2c->base + IC_CLR_INTR); | ||
890 | |||
891 | if (stat & TX_ABRT) { | ||
892 | intel_mid_i2c_abort(i2c); | ||
893 | goto exit; | ||
894 | } | ||
895 | |||
896 | if (stat & RX_FULL) { | ||
897 | i2c_isr_read(i2c); | ||
898 | goto exit; | ||
899 | } | ||
900 | |||
901 | if (stat & TX_EMPTY) { | ||
902 | if (readl(i2c->base + IC_STATUS) & 0x4) | ||
903 | i2c->status = STATUS_WRITE_SUCCESS; | ||
904 | } | ||
905 | |||
906 | exit: | ||
907 | if (i2c->status == STATUS_READ_SUCCESS || | ||
908 | i2c->status == STATUS_WRITE_SUCCESS || | ||
909 | i2c->status == STATUS_XFER_ABORT) { | ||
910 | /* Clear all interrupts */ | ||
911 | readl(i2c->base + IC_CLR_INTR); | ||
912 | /* Mask interrupts */ | ||
913 | writel(0, i2c->base + IC_INTR_MASK); | ||
914 | complete(&i2c->complete); | ||
915 | } | ||
916 | err: | ||
917 | return IRQ_HANDLED; | ||
918 | } | ||
919 | |||
920 | static struct i2c_algorithm intel_mid_i2c_algorithm = { | ||
921 | .master_xfer = intel_mid_i2c_xfer, | ||
922 | .functionality = intel_mid_i2c_func, | ||
923 | }; | ||
924 | |||
925 | |||
926 | static const struct dev_pm_ops intel_mid_i2c_pm_ops = { | ||
927 | .runtime_suspend = intel_mid_i2c_runtime_suspend, | ||
928 | .runtime_resume = intel_mid_i2c_runtime_resume, | ||
929 | }; | ||
930 | |||
931 | /** | ||
932 | * intel_mid_i2c_probe - I2C controller initialization routine | ||
933 | * @dev: pci device | ||
934 | * @id: device id | ||
935 | * | ||
936 | * Return Values: | ||
937 | * 0 success | ||
938 | * -ENODEV If cannot allocate pci resource | ||
939 | * -ENOMEM If the register base remapping failed, or | ||
940 | * if kzalloc failed | ||
941 | * | ||
942 | * Initialization steps: | ||
943 | * 1. Request for PCI resource | ||
944 | * 2. Remap the start address of PCI resource to register base | ||
945 | * 3. Request for device memory region | ||
946 | * 4. Fill in the struct members of intel_mid_i2c_private | ||
947 | * 5. Call intel_mid_i2c_hwinit() for hardware initialization | ||
948 | * 6. Register I2C adapter in i2c-core | ||
949 | */ | ||
950 | static int __devinit intel_mid_i2c_probe(struct pci_dev *dev, | ||
951 | const struct pci_device_id *id) | ||
952 | { | ||
953 | struct intel_mid_i2c_private *mrst; | ||
954 | unsigned long start, len; | ||
955 | int err, busnum; | ||
956 | void __iomem *base = NULL; | ||
957 | |||
958 | dev_dbg(&dev->dev, "Get into probe function for I2C\n"); | ||
959 | err = pci_enable_device(dev); | ||
960 | if (err) { | ||
961 | dev_err(&dev->dev, "Failed to enable I2C PCI device (%d)\n", | ||
962 | err); | ||
963 | goto exit; | ||
964 | } | ||
965 | |||
966 | /* Determine the address of the I2C area */ | ||
967 | start = pci_resource_start(dev, 0); | ||
968 | len = pci_resource_len(dev, 0); | ||
969 | if (!start || len == 0) { | ||
970 | dev_err(&dev->dev, "base address not set\n"); | ||
971 | err = -ENODEV; | ||
972 | goto exit; | ||
973 | } | ||
974 | dev_dbg(&dev->dev, "%s i2c resource start 0x%lx, len=%ld\n", | ||
975 | PLATFORM, start, len); | ||
976 | |||
977 | err = pci_request_region(dev, 0, DRIVER_NAME); | ||
978 | if (err) { | ||
979 | dev_err(&dev->dev, "failed to request I2C region " | ||
980 | "0x%lx-0x%lx\n", start, | ||
981 | (unsigned long)pci_resource_end(dev, 0)); | ||
982 | goto exit; | ||
983 | } | ||
984 | |||
985 | base = ioremap_nocache(start, len); | ||
986 | if (!base) { | ||
987 | dev_err(&dev->dev, "I/O memory remapping failed\n"); | ||
988 | err = -ENOMEM; | ||
989 | goto fail0; | ||
990 | } | ||
991 | |||
992 | /* Allocate the per-device data structure, intel_mid_i2c_private */ | ||
993 | mrst = kzalloc(sizeof(struct intel_mid_i2c_private), GFP_KERNEL); | ||
994 | if (mrst == NULL) { | ||
995 | dev_err(&dev->dev, "can't allocate interface\n"); | ||
996 | err = -ENOMEM; | ||
997 | goto fail1; | ||
998 | } | ||
999 | |||
1000 | /* Initialize struct members */ | ||
1001 | snprintf(mrst->adap.name, sizeof(mrst->adap.name), | ||
1002 | "Intel MID I2C at %lx", start); | ||
1003 | mrst->adap.owner = THIS_MODULE; | ||
1004 | mrst->adap.algo = &intel_mid_i2c_algorithm; | ||
1005 | mrst->adap.dev.parent = &dev->dev; | ||
1006 | mrst->dev = &dev->dev; | ||
1007 | mrst->base = base; | ||
1008 | mrst->speed = STANDARD; | ||
1009 | mrst->abort = 0; | ||
1010 | mrst->rx_buf_len = 0; | ||
1011 | mrst->status = STATUS_IDLE; | ||
1012 | |||
1013 | pci_set_drvdata(dev, mrst); | ||
1014 | i2c_set_adapdata(&mrst->adap, mrst); | ||
1015 | |||
1016 | mrst->adap.nr = busnum = id->driver_data; | ||
1017 | if (dev->device <= 0x0804) | ||
1018 | mrst->platform = MOORESTOWN; | ||
1019 | else | ||
1020 | mrst->platform = MEDFIELD; | ||
1021 | |||
1022 | dev_dbg(&dev->dev, "I2C%d\n", busnum); | ||
1023 | |||
1024 | if (ctl_num > busnum) { | ||
1025 | if (speed_mode[busnum] < 0 || speed_mode[busnum] >= NUM_SPEEDS) | ||
1026 | dev_warn(&dev->dev, "invalid speed %d ignored.\n", | ||
1027 | speed_mode[busnum]); | ||
1028 | else | ||
1029 | mrst->speed = speed_mode[busnum]; | ||
1030 | } | ||
1031 | |||
1032 | /* Initialize i2c controller */ | ||
1033 | err = intel_mid_i2c_hwinit(mrst); | ||
1034 | if (err < 0) { | ||
1035 | dev_err(&dev->dev, "I2C interface initialization failed\n"); | ||
1036 | goto fail2; | ||
1037 | } | ||
1038 | |||
1039 | mutex_init(&mrst->lock); | ||
1040 | init_completion(&mrst->complete); | ||
1041 | |||
1042 | /* Clear all interrupts */ | ||
1043 | readl(mrst->base + IC_CLR_INTR); | ||
1044 | writel(0x0000, mrst->base + IC_INTR_MASK); | ||
1045 | |||
1046 | err = request_irq(dev->irq, intel_mid_i2c_isr, IRQF_SHARED, | ||
1047 | mrst->adap.name, mrst); | ||
1048 | if (err) { | ||
1049 | dev_err(&dev->dev, "Failed to request IRQ for I2C controller: " | ||
1050 | "%s", mrst->adap.name); | ||
1051 | goto fail2; | ||
1052 | } | ||
1053 | |||
1054 | /* Adapter registration */ | ||
1055 | err = i2c_add_numbered_adapter(&mrst->adap); | ||
1056 | if (err) { | ||
1057 | dev_err(&dev->dev, "Adapter %s registration failed\n", | ||
1058 | mrst->adap.name); | ||
1059 | goto fail3; | ||
1060 | } | ||
1061 | |||
1062 | dev_dbg(&dev->dev, "%s I2C bus %d driver bind success.\n", | ||
1063 | (mrst->platform == MOORESTOWN) ? "Moorestown" : "Medfield", | ||
1064 | busnum); | ||
1065 | |||
1066 | pm_runtime_enable(&dev->dev); | ||
1067 | return 0; | ||
1068 | |||
1069 | fail3: | ||
1070 | free_irq(dev->irq, mrst); | ||
1071 | fail2: | ||
1072 | pci_set_drvdata(dev, NULL); | ||
1073 | kfree(mrst); | ||
1074 | fail1: | ||
1075 | iounmap(base); | ||
1076 | fail0: | ||
1077 | pci_release_region(dev, 0); | ||
1078 | exit: | ||
1079 | return err; | ||
1080 | } | ||
1081 | |||
1082 | static void __devexit intel_mid_i2c_remove(struct pci_dev *dev) | ||
1083 | { | ||
1084 | struct intel_mid_i2c_private *mrst = pci_get_drvdata(dev); | ||
1085 | intel_mid_i2c_disable(&mrst->adap); | ||
1086 | if (i2c_del_adapter(&mrst->adap)) | ||
1087 | dev_err(&dev->dev, "Failed to delete i2c adapter"); | ||
1088 | |||
1089 | free_irq(dev->irq, mrst); | ||
1090 | pci_set_drvdata(dev, NULL); | ||
1091 | iounmap(mrst->base); | ||
1092 | kfree(mrst); | ||
1093 | pci_release_region(dev, 0); | ||
1094 | } | ||
1095 | |||
1096 | static struct pci_device_id intel_mid_i2c_ids[] = { | ||
1097 | /* Moorestown */ | ||
1098 | { PCI_VDEVICE(INTEL, 0x0802), 0 }, | ||
1099 | { PCI_VDEVICE(INTEL, 0x0803), 1 }, | ||
1100 | { PCI_VDEVICE(INTEL, 0x0804), 2 }, | ||
1101 | /* Medfield */ | ||
1102 | { PCI_VDEVICE(INTEL, 0x0817), 3,}, | ||
1103 | { PCI_VDEVICE(INTEL, 0x0818), 4 }, | ||
1104 | { PCI_VDEVICE(INTEL, 0x0819), 5 }, | ||
1105 | { PCI_VDEVICE(INTEL, 0x082C), 0 }, | ||
1106 | { PCI_VDEVICE(INTEL, 0x082D), 1 }, | ||
1107 | { PCI_VDEVICE(INTEL, 0x082E), 2 }, | ||
1108 | { 0,} | ||
1109 | }; | ||
1110 | MODULE_DEVICE_TABLE(pci, intel_mid_i2c_ids); | ||
1111 | |||
1112 | static struct pci_driver intel_mid_i2c_driver = { | ||
1113 | .name = DRIVER_NAME, | ||
1114 | .id_table = intel_mid_i2c_ids, | ||
1115 | .probe = intel_mid_i2c_probe, | ||
1116 | .remove = __devexit_p(intel_mid_i2c_remove), | ||
1117 | }; | ||
1118 | |||
1119 | static int __init intel_mid_i2c_init(void) | ||
1120 | { | ||
1121 | return pci_register_driver(&intel_mid_i2c_driver); | ||
1122 | } | ||
1123 | |||
1124 | static void __exit intel_mid_i2c_exit(void) | ||
1125 | { | ||
1126 | pci_unregister_driver(&intel_mid_i2c_driver); | ||
1127 | } | ||
1128 | |||
1129 | module_init(intel_mid_i2c_init); | ||
1130 | module_exit(intel_mid_i2c_exit); | ||
1131 | |||
1132 | MODULE_AUTHOR("Ba Zheng <zheng.ba@intel.com>"); | ||
1133 | MODULE_DESCRIPTION("I2C driver for Moorestown Platform"); | ||
1134 | MODULE_LICENSE("GPL"); | ||
1135 | MODULE_VERSION(VERSION); | ||
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c index a75c75e77b92..112c61f7b8cd 100644 --- a/drivers/i2c/busses/i2c-iop3xx.c +++ b/drivers/i2c/busses/i2c-iop3xx.c | |||
@@ -38,8 +38,7 @@ | |||
38 | #include <linux/errno.h> | 38 | #include <linux/errno.h> |
39 | #include <linux/platform_device.h> | 39 | #include <linux/platform_device.h> |
40 | #include <linux/i2c.h> | 40 | #include <linux/i2c.h> |
41 | 41 | #include <linux/io.h> | |
42 | #include <asm/io.h> | ||
43 | 42 | ||
44 | #include "i2c-iop3xx.h" | 43 | #include "i2c-iop3xx.h" |
45 | 44 | ||
@@ -56,12 +55,6 @@ iic_cook_addr(struct i2c_msg *msg) | |||
56 | if (msg->flags & I2C_M_RD) | 55 | if (msg->flags & I2C_M_RD) |
57 | addr |= 1; | 56 | addr |= 1; |
58 | 57 | ||
59 | /* | ||
60 | * Read or Write? | ||
61 | */ | ||
62 | if (msg->flags & I2C_M_REV_DIR_ADDR) | ||
63 | addr ^= 1; | ||
64 | |||
65 | return addr; | 58 | return addr; |
66 | } | 59 | } |
67 | 60 | ||
diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c index 9f6b8e0f8632..ddc258edb34f 100644 --- a/drivers/i2c/busses/i2c-isch.c +++ b/drivers/i2c/busses/i2c-isch.c | |||
@@ -27,7 +27,7 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/pci.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
32 | #include <linux/delay.h> | 32 | #include <linux/delay.h> |
33 | #include <linux/stddef.h> | 33 | #include <linux/stddef.h> |
@@ -46,12 +46,6 @@ | |||
46 | #define SMBHSTDAT1 (7 + sch_smba) | 46 | #define SMBHSTDAT1 (7 + sch_smba) |
47 | #define SMBBLKDAT (0x20 + sch_smba) | 47 | #define SMBBLKDAT (0x20 + sch_smba) |
48 | 48 | ||
49 | /* count for request_region */ | ||
50 | #define SMBIOSIZE 64 | ||
51 | |||
52 | /* PCI Address Constants */ | ||
53 | #define SMBBA_SCH 0x40 | ||
54 | |||
55 | /* Other settings */ | 49 | /* Other settings */ |
56 | #define MAX_TIMEOUT 500 | 50 | #define MAX_TIMEOUT 500 |
57 | 51 | ||
@@ -63,7 +57,6 @@ | |||
63 | #define SCH_BLOCK_DATA 0x05 | 57 | #define SCH_BLOCK_DATA 0x05 |
64 | 58 | ||
65 | static unsigned short sch_smba; | 59 | static unsigned short sch_smba; |
66 | static struct pci_driver sch_driver; | ||
67 | static struct i2c_adapter sch_adapter; | 60 | static struct i2c_adapter sch_adapter; |
68 | 61 | ||
69 | /* | 62 | /* |
@@ -256,37 +249,23 @@ static struct i2c_adapter sch_adapter = { | |||
256 | .algo = &smbus_algorithm, | 249 | .algo = &smbus_algorithm, |
257 | }; | 250 | }; |
258 | 251 | ||
259 | static struct pci_device_id sch_ids[] = { | 252 | static int __devinit smbus_sch_probe(struct platform_device *dev) |
260 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC) }, | ||
261 | { 0, } | ||
262 | }; | ||
263 | |||
264 | MODULE_DEVICE_TABLE(pci, sch_ids); | ||
265 | |||
266 | static int __devinit sch_probe(struct pci_dev *dev, | ||
267 | const struct pci_device_id *id) | ||
268 | { | 253 | { |
254 | struct resource *res; | ||
269 | int retval; | 255 | int retval; |
270 | unsigned int smba; | ||
271 | |||
272 | pci_read_config_dword(dev, SMBBA_SCH, &smba); | ||
273 | if (!(smba & (1 << 31))) { | ||
274 | dev_err(&dev->dev, "SMBus I/O space disabled!\n"); | ||
275 | return -ENODEV; | ||
276 | } | ||
277 | 256 | ||
278 | sch_smba = (unsigned short)smba; | 257 | res = platform_get_resource(dev, IORESOURCE_IO, 0); |
279 | if (sch_smba == 0) { | 258 | if (!res) |
280 | dev_err(&dev->dev, "SMBus base address uninitialized!\n"); | ||
281 | return -ENODEV; | ||
282 | } | ||
283 | if (acpi_check_region(sch_smba, SMBIOSIZE, sch_driver.name)) | ||
284 | return -EBUSY; | 259 | return -EBUSY; |
285 | if (!request_region(sch_smba, SMBIOSIZE, sch_driver.name)) { | 260 | |
261 | if (!request_region(res->start, resource_size(res), dev->name)) { | ||
286 | dev_err(&dev->dev, "SMBus region 0x%x already in use!\n", | 262 | dev_err(&dev->dev, "SMBus region 0x%x already in use!\n", |
287 | sch_smba); | 263 | sch_smba); |
288 | return -EBUSY; | 264 | return -EBUSY; |
289 | } | 265 | } |
266 | |||
267 | sch_smba = res->start; | ||
268 | |||
290 | dev_dbg(&dev->dev, "SMBA = 0x%X\n", sch_smba); | 269 | dev_dbg(&dev->dev, "SMBA = 0x%X\n", sch_smba); |
291 | 270 | ||
292 | /* set up the sysfs linkage to our parent device */ | 271 | /* set up the sysfs linkage to our parent device */ |
@@ -298,37 +277,43 @@ static int __devinit sch_probe(struct pci_dev *dev, | |||
298 | retval = i2c_add_adapter(&sch_adapter); | 277 | retval = i2c_add_adapter(&sch_adapter); |
299 | if (retval) { | 278 | if (retval) { |
300 | dev_err(&dev->dev, "Couldn't register adapter!\n"); | 279 | dev_err(&dev->dev, "Couldn't register adapter!\n"); |
301 | release_region(sch_smba, SMBIOSIZE); | 280 | release_region(res->start, resource_size(res)); |
302 | sch_smba = 0; | 281 | sch_smba = 0; |
303 | } | 282 | } |
304 | 283 | ||
305 | return retval; | 284 | return retval; |
306 | } | 285 | } |
307 | 286 | ||
308 | static void __devexit sch_remove(struct pci_dev *dev) | 287 | static int __devexit smbus_sch_remove(struct platform_device *pdev) |
309 | { | 288 | { |
289 | struct resource *res; | ||
310 | if (sch_smba) { | 290 | if (sch_smba) { |
311 | i2c_del_adapter(&sch_adapter); | 291 | i2c_del_adapter(&sch_adapter); |
312 | release_region(sch_smba, SMBIOSIZE); | 292 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
293 | release_region(res->start, resource_size(res)); | ||
313 | sch_smba = 0; | 294 | sch_smba = 0; |
314 | } | 295 | } |
296 | |||
297 | return 0; | ||
315 | } | 298 | } |
316 | 299 | ||
317 | static struct pci_driver sch_driver = { | 300 | static struct platform_driver smbus_sch_driver = { |
318 | .name = "isch_smbus", | 301 | .driver = { |
319 | .id_table = sch_ids, | 302 | .name = "isch_smbus", |
320 | .probe = sch_probe, | 303 | .owner = THIS_MODULE, |
321 | .remove = __devexit_p(sch_remove), | 304 | }, |
305 | .probe = smbus_sch_probe, | ||
306 | .remove = __devexit_p(smbus_sch_remove), | ||
322 | }; | 307 | }; |
323 | 308 | ||
324 | static int __init i2c_sch_init(void) | 309 | static int __init i2c_sch_init(void) |
325 | { | 310 | { |
326 | return pci_register_driver(&sch_driver); | 311 | return platform_driver_register(&smbus_sch_driver); |
327 | } | 312 | } |
328 | 313 | ||
329 | static void __exit i2c_sch_exit(void) | 314 | static void __exit i2c_sch_exit(void) |
330 | { | 315 | { |
331 | pci_unregister_driver(&sch_driver); | 316 | platform_driver_unregister(&smbus_sch_driver); |
332 | } | 317 | } |
333 | 318 | ||
334 | MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@intel.com>"); | 319 | MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@intel.com>"); |
@@ -337,3 +322,4 @@ MODULE_LICENSE("GPL"); | |||
337 | 322 | ||
338 | module_init(i2c_sch_init); | 323 | module_init(i2c_sch_init); |
339 | module_exit(i2c_sch_exit); | 324 | module_exit(i2c_sch_exit); |
325 | MODULE_ALIAS("platform:isch_smbus"); | ||
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c index c016f7a2c5fc..5d8aed5ec21b 100644 --- a/drivers/i2c/busses/i2c-ixp2000.c +++ b/drivers/i2c/busses/i2c-ixp2000.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/i2c.h> | 33 | #include <linux/i2c.h> |
34 | #include <linux/i2c-algo-bit.h> | 34 | #include <linux/i2c-algo-bit.h> |
35 | #include <linux/slab.h> | ||
35 | 36 | ||
36 | #include <mach/hardware.h> /* Pick up IXP2000-specific bits */ | 37 | #include <mach/hardware.h> /* Pick up IXP2000-specific bits */ |
37 | #include <mach/gpio.h> | 38 | #include <mach/gpio.h> |
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index d325e86e3103..b74e6dc6886c 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/of_platform.h> | 20 | #include <linux/of_platform.h> |
21 | #include <linux/of_i2c.h> | 21 | #include <linux/of_i2c.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <linux/io.h> | 24 | #include <linux/io.h> |
24 | #include <linux/fsl_devices.h> | 25 | #include <linux/fsl_devices.h> |
@@ -31,6 +32,9 @@ | |||
31 | 32 | ||
32 | #define DRV_NAME "mpc-i2c" | 33 | #define DRV_NAME "mpc-i2c" |
33 | 34 | ||
35 | #define MPC_I2C_CLOCK_LEGACY 0 | ||
36 | #define MPC_I2C_CLOCK_PRESERVE (~0U) | ||
37 | |||
34 | #define MPC_I2C_FDR 0x04 | 38 | #define MPC_I2C_FDR 0x04 |
35 | #define MPC_I2C_CR 0x08 | 39 | #define MPC_I2C_CR 0x08 |
36 | #define MPC_I2C_SR 0x0c | 40 | #define MPC_I2C_SR 0x0c |
@@ -59,6 +63,7 @@ struct mpc_i2c { | |||
59 | wait_queue_head_t queue; | 63 | wait_queue_head_t queue; |
60 | struct i2c_adapter adap; | 64 | struct i2c_adapter adap; |
61 | int irq; | 65 | int irq; |
66 | u32 real_clk; | ||
62 | }; | 67 | }; |
63 | 68 | ||
64 | struct mpc_i2c_divider { | 69 | struct mpc_i2c_divider { |
@@ -66,10 +71,9 @@ struct mpc_i2c_divider { | |||
66 | u16 fdr; /* including dfsrr */ | 71 | u16 fdr; /* including dfsrr */ |
67 | }; | 72 | }; |
68 | 73 | ||
69 | struct mpc_i2c_match_data { | 74 | struct mpc_i2c_data { |
70 | void (*setclock)(struct device_node *node, | 75 | void (*setup)(struct device_node *node, struct mpc_i2c *i2c, |
71 | struct mpc_i2c *i2c, | 76 | u32 clock, u32 prescaler); |
72 | u32 clock, u32 prescaler); | ||
73 | u32 prescaler; | 77 | u32 prescaler; |
74 | }; | 78 | }; |
75 | 79 | ||
@@ -93,20 +97,23 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id) | |||
93 | /* Sometimes 9th clock pulse isn't generated, and slave doesn't release | 97 | /* Sometimes 9th clock pulse isn't generated, and slave doesn't release |
94 | * the bus, because it wants to send ACK. | 98 | * the bus, because it wants to send ACK. |
95 | * Following sequence of enabling/disabling and sending start/stop generates | 99 | * Following sequence of enabling/disabling and sending start/stop generates |
96 | * the pulse, so it's all OK. | 100 | * the 9 pulses, so it's all OK. |
97 | */ | 101 | */ |
98 | static void mpc_i2c_fixup(struct mpc_i2c *i2c) | 102 | static void mpc_i2c_fixup(struct mpc_i2c *i2c) |
99 | { | 103 | { |
100 | writeccr(i2c, 0); | 104 | int k; |
101 | udelay(30); | 105 | u32 delay_val = 1000000 / i2c->real_clk + 1; |
102 | writeccr(i2c, CCR_MEN); | 106 | |
103 | udelay(30); | 107 | if (delay_val < 2) |
104 | writeccr(i2c, CCR_MSTA | CCR_MTX); | 108 | delay_val = 2; |
105 | udelay(30); | 109 | |
106 | writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN); | 110 | for (k = 9; k; k--) { |
107 | udelay(30); | 111 | writeccr(i2c, 0); |
108 | writeccr(i2c, CCR_MEN); | 112 | writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN); |
109 | udelay(30); | 113 | udelay(delay_val); |
114 | writeccr(i2c, CCR_MEN); | ||
115 | udelay(delay_val << 1); | ||
116 | } | ||
110 | } | 117 | } |
111 | 118 | ||
112 | static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) | 119 | static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) |
@@ -115,7 +122,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) | |||
115 | u32 x; | 122 | u32 x; |
116 | int result = 0; | 123 | int result = 0; |
117 | 124 | ||
118 | if (i2c->irq == NO_IRQ) { | 125 | if (!i2c->irq) { |
119 | while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) { | 126 | while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) { |
120 | schedule(); | 127 | schedule(); |
121 | if (time_after(jiffies, orig_jiffies + timeout)) { | 128 | if (time_after(jiffies, orig_jiffies + timeout)) { |
@@ -164,8 +171,8 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) | |||
164 | return 0; | 171 | return 0; |
165 | } | 172 | } |
166 | 173 | ||
167 | #ifdef CONFIG_PPC_MPC52xx | 174 | #if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_PPC_MPC512x) |
168 | static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { | 175 | static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] __devinitconst = { |
169 | {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, | 176 | {20, 0x20}, {22, 0x21}, {24, 0x22}, {26, 0x23}, |
170 | {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, | 177 | {28, 0x24}, {30, 0x01}, {32, 0x25}, {34, 0x02}, |
171 | {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28}, | 178 | {36, 0x26}, {40, 0x27}, {44, 0x04}, {48, 0x28}, |
@@ -186,15 +193,19 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { | |||
186 | {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f} | 193 | {10240, 0x9d}, {12288, 0x9e}, {15360, 0x9f} |
187 | }; | 194 | }; |
188 | 195 | ||
189 | int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler) | 196 | static int __devinit mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, |
197 | int prescaler, u32 *real_clk) | ||
190 | { | 198 | { |
191 | const struct mpc_i2c_divider *div = NULL; | 199 | const struct mpc_i2c_divider *div = NULL; |
192 | unsigned int pvr = mfspr(SPRN_PVR); | 200 | unsigned int pvr = mfspr(SPRN_PVR); |
193 | u32 divider; | 201 | u32 divider; |
194 | int i; | 202 | int i; |
195 | 203 | ||
196 | if (!clock) | 204 | if (clock == MPC_I2C_CLOCK_LEGACY) { |
205 | /* see below - default fdr = 0x3f -> div = 2048 */ | ||
206 | *real_clk = mpc5xxx_get_bus_frequency(node) / 2048; | ||
197 | return -EINVAL; | 207 | return -EINVAL; |
208 | } | ||
198 | 209 | ||
199 | /* Determine divider value */ | 210 | /* Determine divider value */ |
200 | divider = mpc5xxx_get_bus_frequency(node) / clock; | 211 | divider = mpc5xxx_get_bus_frequency(node) / clock; |
@@ -212,33 +223,77 @@ int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, int prescaler) | |||
212 | break; | 223 | break; |
213 | } | 224 | } |
214 | 225 | ||
215 | return div ? (int)div->fdr : -EINVAL; | 226 | *real_clk = mpc5xxx_get_bus_frequency(node) / div->divider; |
227 | return (int)div->fdr; | ||
216 | } | 228 | } |
217 | 229 | ||
218 | static void mpc_i2c_setclock_52xx(struct device_node *node, | 230 | static void __devinit mpc_i2c_setup_52xx(struct device_node *node, |
219 | struct mpc_i2c *i2c, | 231 | struct mpc_i2c *i2c, |
220 | u32 clock, u32 prescaler) | 232 | u32 clock, u32 prescaler) |
221 | { | 233 | { |
222 | int ret, fdr; | 234 | int ret, fdr; |
223 | 235 | ||
224 | ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler); | 236 | if (clock == MPC_I2C_CLOCK_PRESERVE) { |
237 | dev_dbg(i2c->dev, "using fdr %d\n", | ||
238 | readb(i2c->base + MPC_I2C_FDR)); | ||
239 | return; | ||
240 | } | ||
241 | |||
242 | ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler, &i2c->real_clk); | ||
225 | fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ | 243 | fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ |
226 | 244 | ||
227 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); | 245 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); |
228 | 246 | ||
229 | if (ret >= 0) | 247 | if (ret >= 0) |
230 | dev_info(i2c->dev, "clock %d Hz (fdr=%d)\n", clock, fdr); | 248 | dev_info(i2c->dev, "clock %u Hz (fdr=%d)\n", i2c->real_clk, |
249 | fdr); | ||
250 | } | ||
251 | #else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ | ||
252 | static void __devinit mpc_i2c_setup_52xx(struct device_node *node, | ||
253 | struct mpc_i2c *i2c, | ||
254 | u32 clock, u32 prescaler) | ||
255 | { | ||
231 | } | 256 | } |
232 | #else /* !CONFIG_PPC_MPC52xx */ | 257 | #endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ |
233 | static void mpc_i2c_setclock_52xx(struct device_node *node, | 258 | |
234 | struct mpc_i2c *i2c, | 259 | #ifdef CONFIG_PPC_MPC512x |
235 | u32 clock, u32 prescaler) | 260 | static void __devinit mpc_i2c_setup_512x(struct device_node *node, |
261 | struct mpc_i2c *i2c, | ||
262 | u32 clock, u32 prescaler) | ||
236 | { | 263 | { |
264 | struct device_node *node_ctrl; | ||
265 | void __iomem *ctrl; | ||
266 | const u32 *pval; | ||
267 | u32 idx; | ||
268 | |||
269 | /* Enable I2C interrupts for mpc5121 */ | ||
270 | node_ctrl = of_find_compatible_node(NULL, NULL, | ||
271 | "fsl,mpc5121-i2c-ctrl"); | ||
272 | if (node_ctrl) { | ||
273 | ctrl = of_iomap(node_ctrl, 0); | ||
274 | if (ctrl) { | ||
275 | /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ | ||
276 | pval = of_get_property(node, "reg", NULL); | ||
277 | idx = (*pval & 0xff) / 0x20; | ||
278 | setbits32(ctrl, 1 << (24 + idx * 2)); | ||
279 | iounmap(ctrl); | ||
280 | } | ||
281 | of_node_put(node_ctrl); | ||
282 | } | ||
283 | |||
284 | /* The clock setup for the 52xx works also fine for the 512x */ | ||
285 | mpc_i2c_setup_52xx(node, i2c, clock, prescaler); | ||
237 | } | 286 | } |
238 | #endif /* CONFIG_PPC_MPC52xx*/ | 287 | #else /* CONFIG_PPC_MPC512x */ |
288 | static void __devinit mpc_i2c_setup_512x(struct device_node *node, | ||
289 | struct mpc_i2c *i2c, | ||
290 | u32 clock, u32 prescaler) | ||
291 | { | ||
292 | } | ||
293 | #endif /* CONFIG_PPC_MPC512x */ | ||
239 | 294 | ||
240 | #ifdef CONFIG_FSL_SOC | 295 | #ifdef CONFIG_FSL_SOC |
241 | static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = { | 296 | static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] __devinitconst = { |
242 | {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123}, | 297 | {160, 0x0120}, {192, 0x0121}, {224, 0x0122}, {256, 0x0123}, |
243 | {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102}, | 298 | {288, 0x0100}, {320, 0x0101}, {352, 0x0601}, {384, 0x0102}, |
244 | {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127}, | 299 | {416, 0x0602}, {448, 0x0126}, {480, 0x0103}, {512, 0x0127}, |
@@ -258,7 +313,7 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_8xxx[] = { | |||
258 | {49152, 0x011e}, {61440, 0x011f} | 313 | {49152, 0x011e}, {61440, 0x011f} |
259 | }; | 314 | }; |
260 | 315 | ||
261 | u32 mpc_i2c_get_sec_cfg_8xxx(void) | 316 | static u32 __devinit mpc_i2c_get_sec_cfg_8xxx(void) |
262 | { | 317 | { |
263 | struct device_node *node = NULL; | 318 | struct device_node *node = NULL; |
264 | u32 __iomem *reg; | 319 | u32 __iomem *reg; |
@@ -287,14 +342,18 @@ u32 mpc_i2c_get_sec_cfg_8xxx(void) | |||
287 | return val; | 342 | return val; |
288 | } | 343 | } |
289 | 344 | ||
290 | int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler) | 345 | static int __devinit mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, |
346 | u32 prescaler, u32 *real_clk) | ||
291 | { | 347 | { |
292 | const struct mpc_i2c_divider *div = NULL; | 348 | const struct mpc_i2c_divider *div = NULL; |
293 | u32 divider; | 349 | u32 divider; |
294 | int i; | 350 | int i; |
295 | 351 | ||
296 | if (!clock) | 352 | if (clock == MPC_I2C_CLOCK_LEGACY) { |
353 | /* see below - default fdr = 0x1031 -> div = 16 * 3072 */ | ||
354 | *real_clk = fsl_get_sys_freq() / prescaler / (16 * 3072); | ||
297 | return -EINVAL; | 355 | return -EINVAL; |
356 | } | ||
298 | 357 | ||
299 | /* Determine proper divider value */ | 358 | /* Determine proper divider value */ |
300 | if (of_device_is_compatible(node, "fsl,mpc8544-i2c")) | 359 | if (of_device_is_compatible(node, "fsl,mpc8544-i2c")) |
@@ -317,16 +376,24 @@ int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, u32 prescaler) | |||
317 | break; | 376 | break; |
318 | } | 377 | } |
319 | 378 | ||
379 | *real_clk = fsl_get_sys_freq() / prescaler / div->divider; | ||
320 | return div ? (int)div->fdr : -EINVAL; | 380 | return div ? (int)div->fdr : -EINVAL; |
321 | } | 381 | } |
322 | 382 | ||
323 | static void mpc_i2c_setclock_8xxx(struct device_node *node, | 383 | static void __devinit mpc_i2c_setup_8xxx(struct device_node *node, |
324 | struct mpc_i2c *i2c, | 384 | struct mpc_i2c *i2c, |
325 | u32 clock, u32 prescaler) | 385 | u32 clock, u32 prescaler) |
326 | { | 386 | { |
327 | int ret, fdr; | 387 | int ret, fdr; |
328 | 388 | ||
329 | ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler); | 389 | if (clock == MPC_I2C_CLOCK_PRESERVE) { |
390 | dev_dbg(i2c->dev, "using dfsrr %d, fdr %d\n", | ||
391 | readb(i2c->base + MPC_I2C_DFSRR), | ||
392 | readb(i2c->base + MPC_I2C_FDR)); | ||
393 | return; | ||
394 | } | ||
395 | |||
396 | ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler, &i2c->real_clk); | ||
330 | fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ | 397 | fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ |
331 | 398 | ||
332 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); | 399 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); |
@@ -334,13 +401,13 @@ static void mpc_i2c_setclock_8xxx(struct device_node *node, | |||
334 | 401 | ||
335 | if (ret >= 0) | 402 | if (ret >= 0) |
336 | dev_info(i2c->dev, "clock %d Hz (dfsrr=%d fdr=%d)\n", | 403 | dev_info(i2c->dev, "clock %d Hz (dfsrr=%d fdr=%d)\n", |
337 | clock, fdr >> 8, fdr & 0xff); | 404 | i2c->real_clk, fdr >> 8, fdr & 0xff); |
338 | } | 405 | } |
339 | 406 | ||
340 | #else /* !CONFIG_FSL_SOC */ | 407 | #else /* !CONFIG_FSL_SOC */ |
341 | static void mpc_i2c_setclock_8xxx(struct device_node *node, | 408 | static void __devinit mpc_i2c_setup_8xxx(struct device_node *node, |
342 | struct mpc_i2c *i2c, | 409 | struct mpc_i2c *i2c, |
343 | u32 clock, u32 prescaler) | 410 | u32 clock, u32 prescaler) |
344 | { | 411 | { |
345 | } | 412 | } |
346 | #endif /* CONFIG_FSL_SOC */ | 413 | #endif /* CONFIG_FSL_SOC */ |
@@ -365,9 +432,6 @@ static int mpc_write(struct mpc_i2c *i2c, int target, | |||
365 | unsigned timeout = i2c->adap.timeout; | 432 | unsigned timeout = i2c->adap.timeout; |
366 | u32 flags = restart ? CCR_RSTA : 0; | 433 | u32 flags = restart ? CCR_RSTA : 0; |
367 | 434 | ||
368 | /* Start with MEN */ | ||
369 | if (!restart) | ||
370 | writeccr(i2c, CCR_MEN); | ||
371 | /* Start as master */ | 435 | /* Start as master */ |
372 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags); | 436 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags); |
373 | /* Write target byte */ | 437 | /* Write target byte */ |
@@ -396,9 +460,6 @@ static int mpc_read(struct mpc_i2c *i2c, int target, | |||
396 | int i, result; | 460 | int i, result; |
397 | u32 flags = restart ? CCR_RSTA : 0; | 461 | u32 flags = restart ? CCR_RSTA : 0; |
398 | 462 | ||
399 | /* Start with MEN */ | ||
400 | if (!restart) | ||
401 | writeccr(i2c, CCR_MEN); | ||
402 | /* Switch to read - restart */ | 463 | /* Switch to read - restart */ |
403 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags); | 464 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags); |
404 | /* Write target address byte - this time with the read flag set */ | 465 | /* Write target address byte - this time with the read flag set */ |
@@ -425,9 +486,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target, | |||
425 | /* Generate txack on next to last byte */ | 486 | /* Generate txack on next to last byte */ |
426 | if (i == length - 2) | 487 | if (i == length - 2) |
427 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_TXAK); | 488 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_TXAK); |
428 | /* Generate stop on last byte */ | 489 | /* Do not generate stop on last byte */ |
429 | if (i == length - 1) | 490 | if (i == length - 1) |
430 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_TXAK); | 491 | writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX); |
431 | data[i] = readb(i2c->base + MPC_I2C_DR); | 492 | data[i] = readb(i2c->base + MPC_I2C_DR); |
432 | } | 493 | } |
433 | 494 | ||
@@ -452,10 +513,14 @@ static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
452 | return -EINTR; | 513 | return -EINTR; |
453 | } | 514 | } |
454 | if (time_after(jiffies, orig_jiffies + HZ)) { | 515 | if (time_after(jiffies, orig_jiffies + HZ)) { |
516 | u8 status = readb(i2c->base + MPC_I2C_SR); | ||
517 | |||
455 | dev_dbg(i2c->dev, "timeout\n"); | 518 | dev_dbg(i2c->dev, "timeout\n"); |
456 | if (readb(i2c->base + MPC_I2C_SR) == | 519 | if ((status & (CSR_MCF | CSR_MBB | CSR_RXAK)) != 0) { |
457 | (CSR_MCF | CSR_MBB | CSR_RXAK)) | 520 | writeb(status & ~CSR_MAL, |
521 | i2c->base + MPC_I2C_SR); | ||
458 | mpc_i2c_fixup(i2c); | 522 | mpc_i2c_fixup(i2c); |
523 | } | ||
459 | return -EIO; | 524 | return -EIO; |
460 | } | 525 | } |
461 | schedule(); | 526 | schedule(); |
@@ -495,12 +560,12 @@ static struct i2c_adapter mpc_ops = { | |||
495 | .timeout = HZ, | 560 | .timeout = HZ, |
496 | }; | 561 | }; |
497 | 562 | ||
498 | static int __devinit fsl_i2c_probe(struct of_device *op, | 563 | static int __devinit fsl_i2c_probe(struct platform_device *op, |
499 | const struct of_device_id *match) | 564 | const struct of_device_id *match) |
500 | { | 565 | { |
501 | struct mpc_i2c *i2c; | 566 | struct mpc_i2c *i2c; |
502 | const u32 *prop; | 567 | const u32 *prop; |
503 | u32 clock = 0; | 568 | u32 clock = MPC_I2C_CLOCK_LEGACY; |
504 | int result = 0; | 569 | int result = 0; |
505 | int plen; | 570 | int plen; |
506 | 571 | ||
@@ -512,15 +577,15 @@ static int __devinit fsl_i2c_probe(struct of_device *op, | |||
512 | 577 | ||
513 | init_waitqueue_head(&i2c->queue); | 578 | init_waitqueue_head(&i2c->queue); |
514 | 579 | ||
515 | i2c->base = of_iomap(op->node, 0); | 580 | i2c->base = of_iomap(op->dev.of_node, 0); |
516 | if (!i2c->base) { | 581 | if (!i2c->base) { |
517 | dev_err(i2c->dev, "failed to map controller\n"); | 582 | dev_err(i2c->dev, "failed to map controller\n"); |
518 | result = -ENOMEM; | 583 | result = -ENOMEM; |
519 | goto fail_map; | 584 | goto fail_map; |
520 | } | 585 | } |
521 | 586 | ||
522 | i2c->irq = irq_of_parse_and_map(op->node, 0); | 587 | i2c->irq = irq_of_parse_and_map(op->dev.of_node, 0); |
523 | if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */ | 588 | if (i2c->irq) { /* no i2c->irq implies polling */ |
524 | result = request_irq(i2c->irq, mpc_i2c_isr, | 589 | result = request_irq(i2c->irq, mpc_i2c_isr, |
525 | IRQF_SHARED, "i2c-mpc", i2c); | 590 | IRQF_SHARED, "i2c-mpc", i2c); |
526 | if (result < 0) { | 591 | if (result < 0) { |
@@ -529,35 +594,45 @@ static int __devinit fsl_i2c_probe(struct of_device *op, | |||
529 | } | 594 | } |
530 | } | 595 | } |
531 | 596 | ||
532 | if (!of_get_property(op->node, "fsl,preserve-clocking", NULL)) { | 597 | if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) { |
533 | prop = of_get_property(op->node, "clock-frequency", &plen); | 598 | clock = MPC_I2C_CLOCK_PRESERVE; |
599 | } else { | ||
600 | prop = of_get_property(op->dev.of_node, "clock-frequency", | ||
601 | &plen); | ||
534 | if (prop && plen == sizeof(u32)) | 602 | if (prop && plen == sizeof(u32)) |
535 | clock = *prop; | 603 | clock = *prop; |
604 | } | ||
536 | 605 | ||
537 | if (match->data) { | 606 | if (match->data) { |
538 | struct mpc_i2c_match_data *data = | 607 | struct mpc_i2c_data *data = match->data; |
539 | (struct mpc_i2c_match_data *)match->data; | 608 | data->setup(op->dev.of_node, i2c, clock, data->prescaler); |
540 | data->setclock(op->node, i2c, clock, data->prescaler); | 609 | } else { |
541 | } else { | 610 | /* Backwards compatibility */ |
542 | /* Backwards compatibility */ | 611 | if (of_get_property(op->dev.of_node, "dfsrr", NULL)) |
543 | if (of_get_property(op->node, "dfsrr", NULL)) | 612 | mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock, 0); |
544 | mpc_i2c_setclock_8xxx(op->node, i2c, | ||
545 | clock, 0); | ||
546 | } | ||
547 | } | 613 | } |
548 | 614 | ||
615 | prop = of_get_property(op->dev.of_node, "fsl,timeout", &plen); | ||
616 | if (prop && plen == sizeof(u32)) { | ||
617 | mpc_ops.timeout = *prop * HZ / 1000000; | ||
618 | if (mpc_ops.timeout < 5) | ||
619 | mpc_ops.timeout = 5; | ||
620 | } | ||
621 | dev_info(i2c->dev, "timeout %u us\n", mpc_ops.timeout * 1000000 / HZ); | ||
622 | |||
549 | dev_set_drvdata(&op->dev, i2c); | 623 | dev_set_drvdata(&op->dev, i2c); |
550 | 624 | ||
551 | i2c->adap = mpc_ops; | 625 | i2c->adap = mpc_ops; |
552 | i2c_set_adapdata(&i2c->adap, i2c); | 626 | i2c_set_adapdata(&i2c->adap, i2c); |
553 | i2c->adap.dev.parent = &op->dev; | 627 | i2c->adap.dev.parent = &op->dev; |
628 | i2c->adap.dev.of_node = of_node_get(op->dev.of_node); | ||
554 | 629 | ||
555 | result = i2c_add_adapter(&i2c->adap); | 630 | result = i2c_add_adapter(&i2c->adap); |
556 | if (result < 0) { | 631 | if (result < 0) { |
557 | dev_err(i2c->dev, "failed to add adapter\n"); | 632 | dev_err(i2c->dev, "failed to add adapter\n"); |
558 | goto fail_add; | 633 | goto fail_add; |
559 | } | 634 | } |
560 | of_register_i2c_devices(&i2c->adap, op->node); | 635 | of_i2c_register_devices(&i2c->adap); |
561 | 636 | ||
562 | return result; | 637 | return result; |
563 | 638 | ||
@@ -572,14 +647,14 @@ static int __devinit fsl_i2c_probe(struct of_device *op, | |||
572 | return result; | 647 | return result; |
573 | }; | 648 | }; |
574 | 649 | ||
575 | static int __devexit fsl_i2c_remove(struct of_device *op) | 650 | static int __devexit fsl_i2c_remove(struct platform_device *op) |
576 | { | 651 | { |
577 | struct mpc_i2c *i2c = dev_get_drvdata(&op->dev); | 652 | struct mpc_i2c *i2c = dev_get_drvdata(&op->dev); |
578 | 653 | ||
579 | i2c_del_adapter(&i2c->adap); | 654 | i2c_del_adapter(&i2c->adap); |
580 | dev_set_drvdata(&op->dev, NULL); | 655 | dev_set_drvdata(&op->dev, NULL); |
581 | 656 | ||
582 | if (i2c->irq != NO_IRQ) | 657 | if (i2c->irq) |
583 | free_irq(i2c->irq, i2c); | 658 | free_irq(i2c->irq, i2c); |
584 | 659 | ||
585 | irq_dispose_mapping(i2c->irq); | 660 | irq_dispose_mapping(i2c->irq); |
@@ -588,55 +663,50 @@ static int __devexit fsl_i2c_remove(struct of_device *op) | |||
588 | return 0; | 663 | return 0; |
589 | }; | 664 | }; |
590 | 665 | ||
666 | static struct mpc_i2c_data mpc_i2c_data_512x __devinitdata = { | ||
667 | .setup = mpc_i2c_setup_512x, | ||
668 | }; | ||
669 | |||
670 | static struct mpc_i2c_data mpc_i2c_data_52xx __devinitdata = { | ||
671 | .setup = mpc_i2c_setup_52xx, | ||
672 | }; | ||
673 | |||
674 | static struct mpc_i2c_data mpc_i2c_data_8313 __devinitdata = { | ||
675 | .setup = mpc_i2c_setup_8xxx, | ||
676 | }; | ||
677 | |||
678 | static struct mpc_i2c_data mpc_i2c_data_8543 __devinitdata = { | ||
679 | .setup = mpc_i2c_setup_8xxx, | ||
680 | .prescaler = 2, | ||
681 | }; | ||
682 | |||
683 | static struct mpc_i2c_data mpc_i2c_data_8544 __devinitdata = { | ||
684 | .setup = mpc_i2c_setup_8xxx, | ||
685 | .prescaler = 3, | ||
686 | }; | ||
687 | |||
591 | static const struct of_device_id mpc_i2c_of_match[] = { | 688 | static const struct of_device_id mpc_i2c_of_match[] = { |
592 | {.compatible = "mpc5200-i2c", | 689 | {.compatible = "mpc5200-i2c", .data = &mpc_i2c_data_52xx, }, |
593 | .data = &(struct mpc_i2c_match_data) { | 690 | {.compatible = "fsl,mpc5200b-i2c", .data = &mpc_i2c_data_52xx, }, |
594 | .setclock = mpc_i2c_setclock_52xx, | 691 | {.compatible = "fsl,mpc5200-i2c", .data = &mpc_i2c_data_52xx, }, |
595 | }, | 692 | {.compatible = "fsl,mpc5121-i2c", .data = &mpc_i2c_data_512x, }, |
596 | }, | 693 | {.compatible = "fsl,mpc8313-i2c", .data = &mpc_i2c_data_8313, }, |
597 | {.compatible = "fsl,mpc5200b-i2c", | 694 | {.compatible = "fsl,mpc8543-i2c", .data = &mpc_i2c_data_8543, }, |
598 | .data = &(struct mpc_i2c_match_data) { | 695 | {.compatible = "fsl,mpc8544-i2c", .data = &mpc_i2c_data_8544, }, |
599 | .setclock = mpc_i2c_setclock_52xx, | ||
600 | }, | ||
601 | }, | ||
602 | {.compatible = "fsl,mpc5200-i2c", | ||
603 | .data = &(struct mpc_i2c_match_data) { | ||
604 | .setclock = mpc_i2c_setclock_52xx, | ||
605 | }, | ||
606 | }, | ||
607 | {.compatible = "fsl,mpc8313-i2c", | ||
608 | .data = &(struct mpc_i2c_match_data) { | ||
609 | .setclock = mpc_i2c_setclock_8xxx, | ||
610 | }, | ||
611 | }, | ||
612 | {.compatible = "fsl,mpc8543-i2c", | ||
613 | .data = &(struct mpc_i2c_match_data) { | ||
614 | .setclock = mpc_i2c_setclock_8xxx, | ||
615 | .prescaler = 2, | ||
616 | }, | ||
617 | }, | ||
618 | {.compatible = "fsl,mpc8544-i2c", | ||
619 | .data = &(struct mpc_i2c_match_data) { | ||
620 | .setclock = mpc_i2c_setclock_8xxx, | ||
621 | .prescaler = 3, | ||
622 | }, | ||
623 | /* Backward compatibility */ | 696 | /* Backward compatibility */ |
624 | }, | ||
625 | {.compatible = "fsl-i2c", }, | 697 | {.compatible = "fsl-i2c", }, |
626 | {}, | 698 | {}, |
627 | }; | 699 | }; |
628 | |||
629 | MODULE_DEVICE_TABLE(of, mpc_i2c_of_match); | 700 | MODULE_DEVICE_TABLE(of, mpc_i2c_of_match); |
630 | 701 | ||
631 | |||
632 | /* Structure for a device driver */ | 702 | /* Structure for a device driver */ |
633 | static struct of_platform_driver mpc_i2c_driver = { | 703 | static struct of_platform_driver mpc_i2c_driver = { |
634 | .match_table = mpc_i2c_of_match, | ||
635 | .probe = fsl_i2c_probe, | 704 | .probe = fsl_i2c_probe, |
636 | .remove = __devexit_p(fsl_i2c_remove), | 705 | .remove = __devexit_p(fsl_i2c_remove), |
637 | .driver = { | 706 | .driver = { |
638 | .owner = THIS_MODULE, | 707 | .owner = THIS_MODULE, |
639 | .name = DRV_NAME, | 708 | .name = DRV_NAME, |
709 | .of_match_table = mpc_i2c_of_match, | ||
640 | }, | 710 | }, |
641 | }; | 711 | }; |
642 | 712 | ||
@@ -661,5 +731,5 @@ module_exit(fsl_i2c_exit); | |||
661 | 731 | ||
662 | MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); | 732 | MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); |
663 | MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " | 733 | MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " |
664 | "MPC824x/85xx/52xx processors"); | 734 | "MPC824x/83xx/85xx/86xx/512x/52xx processors"); |
665 | MODULE_LICENSE("GPL"); | 735 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index c3869d94ad42..16242063144f 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
@@ -10,14 +10,14 @@ | |||
10 | * or implied. | 10 | * or implied. |
11 | */ | 11 | */ |
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/module.h> | 14 | #include <linux/module.h> |
14 | #include <linux/spinlock.h> | 15 | #include <linux/spinlock.h> |
15 | #include <linux/i2c.h> | 16 | #include <linux/i2c.h> |
16 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
17 | #include <linux/mv643xx_i2c.h> | 18 | #include <linux/mv643xx_i2c.h> |
18 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
19 | 20 | #include <linux/io.h> | |
20 | #include <asm/io.h> | ||
21 | 21 | ||
22 | /* Register defines */ | 22 | /* Register defines */ |
23 | #define MV64XXX_I2C_REG_SLAVE_ADDR 0x00 | 23 | #define MV64XXX_I2C_REG_SLAVE_ADDR 0x00 |
@@ -293,13 +293,13 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) | |||
293 | } | 293 | } |
294 | } | 294 | } |
295 | 295 | ||
296 | static int | 296 | static irqreturn_t |
297 | mv64xxx_i2c_intr(int irq, void *dev_id) | 297 | mv64xxx_i2c_intr(int irq, void *dev_id) |
298 | { | 298 | { |
299 | struct mv64xxx_i2c_data *drv_data = dev_id; | 299 | struct mv64xxx_i2c_data *drv_data = dev_id; |
300 | unsigned long flags; | 300 | unsigned long flags; |
301 | u32 status; | 301 | u32 status; |
302 | int rc = IRQ_NONE; | 302 | irqreturn_t rc = IRQ_NONE; |
303 | 303 | ||
304 | spin_lock_irqsave(&drv_data->lock, flags); | 304 | spin_lock_irqsave(&drv_data->lock, flags); |
305 | while (readl(drv_data->reg_base + MV64XXX_I2C_REG_CONTROL) & | 305 | while (readl(drv_data->reg_base + MV64XXX_I2C_REG_CONTROL) & |
@@ -338,9 +338,6 @@ mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data, | |||
338 | if (msg->flags & I2C_M_RD) | 338 | if (msg->flags & I2C_M_RD) |
339 | dir = 1; | 339 | dir = 1; |
340 | 340 | ||
341 | if (msg->flags & I2C_M_REV_DIR_ADDR) | ||
342 | dir ^= 1; | ||
343 | |||
344 | if (msg->flags & I2C_M_TEN) { | 341 | if (msg->flags & I2C_M_TEN) { |
345 | drv_data->addr1 = 0xf0 | (((u32)msg->addr & 0x300) >> 7) | dir; | 342 | drv_data->addr1 = 0xf0 | (((u32)msg->addr & 0x300) >> 7) | dir; |
346 | drv_data->addr2 = (u32)msg->addr & 0xff; | 343 | drv_data->addr2 = (u32)msg->addr & 0xff; |
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c index ec11d1c4e77b..ff1e127dfea8 100644 --- a/drivers/i2c/busses/i2c-nforce2.c +++ b/drivers/i2c/busses/i2c-nforce2.c | |||
@@ -56,7 +56,8 @@ | |||
56 | #include <linux/delay.h> | 56 | #include <linux/delay.h> |
57 | #include <linux/dmi.h> | 57 | #include <linux/dmi.h> |
58 | #include <linux/acpi.h> | 58 | #include <linux/acpi.h> |
59 | #include <asm/io.h> | 59 | #include <linux/slab.h> |
60 | #include <linux/io.h> | ||
60 | 61 | ||
61 | MODULE_LICENSE("GPL"); | 62 | MODULE_LICENSE("GPL"); |
62 | MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>"); | 63 | MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>"); |
@@ -308,7 +309,7 @@ static struct i2c_algorithm smbus_algorithm = { | |||
308 | }; | 309 | }; |
309 | 310 | ||
310 | 311 | ||
311 | static struct pci_device_id nforce2_ids[] = { | 312 | static const struct pci_device_id nforce2_ids[] = { |
312 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, | 313 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, |
313 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) }, | 314 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) }, |
314 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) }, | 315 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) }, |
@@ -403,10 +404,9 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_ | |||
403 | 404 | ||
404 | /* SMBus adapter 1 */ | 405 | /* SMBus adapter 1 */ |
405 | res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1"); | 406 | res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1"); |
406 | if (res1 < 0) { | 407 | if (res1 < 0) |
407 | dev_err(&dev->dev, "Error probing SMB1.\n"); | ||
408 | smbuses[0].base = 0; /* to have a check value */ | 408 | smbuses[0].base = 0; /* to have a check value */ |
409 | } | 409 | |
410 | /* SMBus adapter 2 */ | 410 | /* SMBus adapter 2 */ |
411 | if (dmi_check_system(nforce2_dmi_blacklist2)) { | 411 | if (dmi_check_system(nforce2_dmi_blacklist2)) { |
412 | dev_err(&dev->dev, "Disabling SMB2 for safety reasons.\n"); | 412 | dev_err(&dev->dev, "Disabling SMB2 for safety reasons.\n"); |
@@ -415,11 +415,10 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_ | |||
415 | } else { | 415 | } else { |
416 | res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1], | 416 | res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1], |
417 | "SMB2"); | 417 | "SMB2"); |
418 | if (res2 < 0) { | 418 | if (res2 < 0) |
419 | dev_err(&dev->dev, "Error probing SMB2.\n"); | ||
420 | smbuses[1].base = 0; /* to have a check value */ | 419 | smbuses[1].base = 0; /* to have a check value */ |
421 | } | ||
422 | } | 420 | } |
421 | |||
423 | if ((res1 < 0) && (res2 < 0)) { | 422 | if ((res1 < 0) && (res2 < 0)) { |
424 | /* we did not find even one of the SMBuses, so we give up */ | 423 | /* we did not find even one of the SMBuses, so we give up */ |
425 | kfree(smbuses); | 424 | kfree(smbuses); |
@@ -433,7 +432,7 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_ | |||
433 | 432 | ||
434 | static void __devexit nforce2_remove(struct pci_dev *dev) | 433 | static void __devexit nforce2_remove(struct pci_dev *dev) |
435 | { | 434 | { |
436 | struct nforce2_smbus *smbuses = (void*) pci_get_drvdata(dev); | 435 | struct nforce2_smbus *smbuses = pci_get_drvdata(dev); |
437 | 436 | ||
438 | nforce2_set_reference(NULL); | 437 | nforce2_set_reference(NULL); |
439 | if (smbuses[0].base) { | 438 | if (smbuses[0].base) { |
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c new file mode 100644 index 000000000000..c9fffd0389fe --- /dev/null +++ b/drivers/i2c/busses/i2c-nomadik.c | |||
@@ -0,0 +1,970 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009 ST-Ericsson SA | ||
3 | * Copyright (C) 2009 STMicroelectronics | ||
4 | * | ||
5 | * I2C master mode controller driver, used in Nomadik 8815 | ||
6 | * and Ux500 platforms. | ||
7 | * | ||
8 | * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com> | ||
9 | * Author: Sachin Verma <sachin.verma@st.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2, as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/err.h> | ||
23 | #include <linux/clk.h> | ||
24 | #include <linux/io.h> | ||
25 | |||
26 | #include <plat/i2c.h> | ||
27 | |||
28 | #define DRIVER_NAME "nmk-i2c" | ||
29 | |||
30 | /* I2C Controller register offsets */ | ||
31 | #define I2C_CR (0x000) | ||
32 | #define I2C_SCR (0x004) | ||
33 | #define I2C_HSMCR (0x008) | ||
34 | #define I2C_MCR (0x00C) | ||
35 | #define I2C_TFR (0x010) | ||
36 | #define I2C_SR (0x014) | ||
37 | #define I2C_RFR (0x018) | ||
38 | #define I2C_TFTR (0x01C) | ||
39 | #define I2C_RFTR (0x020) | ||
40 | #define I2C_DMAR (0x024) | ||
41 | #define I2C_BRCR (0x028) | ||
42 | #define I2C_IMSCR (0x02C) | ||
43 | #define I2C_RISR (0x030) | ||
44 | #define I2C_MISR (0x034) | ||
45 | #define I2C_ICR (0x038) | ||
46 | |||
47 | /* Control registers */ | ||
48 | #define I2C_CR_PE (0x1 << 0) /* Peripheral Enable */ | ||
49 | #define I2C_CR_OM (0x3 << 1) /* Operating mode */ | ||
50 | #define I2C_CR_SAM (0x1 << 3) /* Slave addressing mode */ | ||
51 | #define I2C_CR_SM (0x3 << 4) /* Speed mode */ | ||
52 | #define I2C_CR_SGCM (0x1 << 6) /* Slave general call mode */ | ||
53 | #define I2C_CR_FTX (0x1 << 7) /* Flush Transmit */ | ||
54 | #define I2C_CR_FRX (0x1 << 8) /* Flush Receive */ | ||
55 | #define I2C_CR_DMA_TX_EN (0x1 << 9) /* DMA Tx enable */ | ||
56 | #define I2C_CR_DMA_RX_EN (0x1 << 10) /* DMA Rx Enable */ | ||
57 | #define I2C_CR_DMA_SLE (0x1 << 11) /* DMA sync. logic enable */ | ||
58 | #define I2C_CR_LM (0x1 << 12) /* Loopback mode */ | ||
59 | #define I2C_CR_FON (0x3 << 13) /* Filtering on */ | ||
60 | #define I2C_CR_FS (0x3 << 15) /* Force stop enable */ | ||
61 | |||
62 | /* Master controller (MCR) register */ | ||
63 | #define I2C_MCR_OP (0x1 << 0) /* Operation */ | ||
64 | #define I2C_MCR_A7 (0x7f << 1) /* 7-bit address */ | ||
65 | #define I2C_MCR_EA10 (0x7 << 8) /* 10-bit Extended address */ | ||
66 | #define I2C_MCR_SB (0x1 << 11) /* Extended address */ | ||
67 | #define I2C_MCR_AM (0x3 << 12) /* Address type */ | ||
68 | #define I2C_MCR_STOP (0x1 << 14) /* Stop condition */ | ||
69 | #define I2C_MCR_LENGTH (0x7ff << 15) /* Transaction length */ | ||
70 | |||
71 | /* Status register (SR) */ | ||
72 | #define I2C_SR_OP (0x3 << 0) /* Operation */ | ||
73 | #define I2C_SR_STATUS (0x3 << 2) /* controller status */ | ||
74 | #define I2C_SR_CAUSE (0x7 << 4) /* Abort cause */ | ||
75 | #define I2C_SR_TYPE (0x3 << 7) /* Receive type */ | ||
76 | #define I2C_SR_LENGTH (0x7ff << 9) /* Transfer length */ | ||
77 | |||
78 | /* Interrupt mask set/clear (IMSCR) bits */ | ||
79 | #define I2C_IT_TXFE (0x1 << 0) | ||
80 | #define I2C_IT_TXFNE (0x1 << 1) | ||
81 | #define I2C_IT_TXFF (0x1 << 2) | ||
82 | #define I2C_IT_TXFOVR (0x1 << 3) | ||
83 | #define I2C_IT_RXFE (0x1 << 4) | ||
84 | #define I2C_IT_RXFNF (0x1 << 5) | ||
85 | #define I2C_IT_RXFF (0x1 << 6) | ||
86 | #define I2C_IT_RFSR (0x1 << 16) | ||
87 | #define I2C_IT_RFSE (0x1 << 17) | ||
88 | #define I2C_IT_WTSR (0x1 << 18) | ||
89 | #define I2C_IT_MTD (0x1 << 19) | ||
90 | #define I2C_IT_STD (0x1 << 20) | ||
91 | #define I2C_IT_MAL (0x1 << 24) | ||
92 | #define I2C_IT_BERR (0x1 << 25) | ||
93 | #define I2C_IT_MTDWS (0x1 << 28) | ||
94 | |||
95 | #define GEN_MASK(val, mask, sb) (((val) << (sb)) & (mask)) | ||
96 | |||
97 | /* some bits in ICR are reserved */ | ||
98 | #define I2C_CLEAR_ALL_INTS 0x131f007f | ||
99 | |||
100 | /* first three msb bits are reserved */ | ||
101 | #define IRQ_MASK(mask) (mask & 0x1fffffff) | ||
102 | |||
103 | /* maximum threshold value */ | ||
104 | #define MAX_I2C_FIFO_THRESHOLD 15 | ||
105 | |||
106 | /* per-transfer delay, required for the hardware to stabilize */ | ||
107 | #define I2C_DELAY 150 | ||
108 | |||
109 | enum i2c_status { | ||
110 | I2C_NOP, | ||
111 | I2C_ON_GOING, | ||
112 | I2C_OK, | ||
113 | I2C_ABORT | ||
114 | }; | ||
115 | |||
116 | /* operation */ | ||
117 | enum i2c_operation { | ||
118 | I2C_NO_OPERATION = 0xff, | ||
119 | I2C_WRITE = 0x00, | ||
120 | I2C_READ = 0x01 | ||
121 | }; | ||
122 | |||
123 | /* controller response timeout in ms */ | ||
124 | #define I2C_TIMEOUT_MS 2000 | ||
125 | |||
126 | /** | ||
127 | * struct i2c_nmk_client - client specific data | ||
128 | * @slave_adr: 7-bit slave address | ||
129 | * @count: no. bytes to be transfered | ||
130 | * @buffer: client data buffer | ||
131 | * @xfer_bytes: bytes transfered till now | ||
132 | * @operation: current I2C operation | ||
133 | */ | ||
134 | struct i2c_nmk_client { | ||
135 | unsigned short slave_adr; | ||
136 | unsigned long count; | ||
137 | unsigned char *buffer; | ||
138 | unsigned long xfer_bytes; | ||
139 | enum i2c_operation operation; | ||
140 | }; | ||
141 | |||
142 | /** | ||
143 | * struct nmk_i2c_dev - private data structure of the controller | ||
144 | * @pdev: parent platform device | ||
145 | * @adap: corresponding I2C adapter | ||
146 | * @irq: interrupt line for the controller | ||
147 | * @virtbase: virtual io memory area | ||
148 | * @clk: hardware i2c block clock | ||
149 | * @cfg: machine provided controller configuration | ||
150 | * @cli: holder of client specific data | ||
151 | * @stop: stop condition | ||
152 | * @xfer_complete: acknowledge completion for a I2C message | ||
153 | * @result: controller propogated result | ||
154 | */ | ||
155 | struct nmk_i2c_dev { | ||
156 | struct platform_device *pdev; | ||
157 | struct i2c_adapter adap; | ||
158 | int irq; | ||
159 | void __iomem *virtbase; | ||
160 | struct clk *clk; | ||
161 | struct nmk_i2c_controller cfg; | ||
162 | struct i2c_nmk_client cli; | ||
163 | int stop; | ||
164 | struct completion xfer_complete; | ||
165 | int result; | ||
166 | }; | ||
167 | |||
168 | /* controller's abort causes */ | ||
169 | static const char *abort_causes[] = { | ||
170 | "no ack received after address transmission", | ||
171 | "no ack received during data phase", | ||
172 | "ack received after xmission of master code", | ||
173 | "master lost arbitration", | ||
174 | "slave restarts", | ||
175 | "slave reset", | ||
176 | "overflow, maxsize is 2047 bytes", | ||
177 | }; | ||
178 | |||
179 | static inline void i2c_set_bit(void __iomem *reg, u32 mask) | ||
180 | { | ||
181 | writel(readl(reg) | mask, reg); | ||
182 | } | ||
183 | |||
184 | static inline void i2c_clr_bit(void __iomem *reg, u32 mask) | ||
185 | { | ||
186 | writel(readl(reg) & ~mask, reg); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * flush_i2c_fifo() - This function flushes the I2C FIFO | ||
191 | * @dev: private data of I2C Driver | ||
192 | * | ||
193 | * This function flushes the I2C Tx and Rx FIFOs. It returns | ||
194 | * 0 on successful flushing of FIFO | ||
195 | */ | ||
196 | static int flush_i2c_fifo(struct nmk_i2c_dev *dev) | ||
197 | { | ||
198 | #define LOOP_ATTEMPTS 10 | ||
199 | int i; | ||
200 | unsigned long timeout; | ||
201 | |||
202 | /* | ||
203 | * flush the transmit and receive FIFO. The flushing | ||
204 | * operation takes several cycles before to be completed. | ||
205 | * On the completion, the I2C internal logic clears these | ||
206 | * bits, until then no one must access Tx, Rx FIFO and | ||
207 | * should poll on these bits waiting for the completion. | ||
208 | */ | ||
209 | writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR); | ||
210 | |||
211 | for (i = 0; i < LOOP_ATTEMPTS; i++) { | ||
212 | timeout = jiffies + msecs_to_jiffies(I2C_TIMEOUT_MS); | ||
213 | |||
214 | while (!time_after(jiffies, timeout)) { | ||
215 | if ((readl(dev->virtbase + I2C_CR) & | ||
216 | (I2C_CR_FTX | I2C_CR_FRX)) == 0) | ||
217 | return 0; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | dev_err(&dev->pdev->dev, "flushing operation timed out " | ||
222 | "giving up after %d attempts", LOOP_ATTEMPTS); | ||
223 | |||
224 | return -ETIMEDOUT; | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * disable_all_interrupts() - Disable all interrupts of this I2c Bus | ||
229 | * @dev: private data of I2C Driver | ||
230 | */ | ||
231 | static void disable_all_interrupts(struct nmk_i2c_dev *dev) | ||
232 | { | ||
233 | u32 mask = IRQ_MASK(0); | ||
234 | writel(mask, dev->virtbase + I2C_IMSCR); | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * clear_all_interrupts() - Clear all interrupts of I2C Controller | ||
239 | * @dev: private data of I2C Driver | ||
240 | */ | ||
241 | static void clear_all_interrupts(struct nmk_i2c_dev *dev) | ||
242 | { | ||
243 | u32 mask; | ||
244 | mask = IRQ_MASK(I2C_CLEAR_ALL_INTS); | ||
245 | writel(mask, dev->virtbase + I2C_ICR); | ||
246 | } | ||
247 | |||
248 | /** | ||
249 | * init_hw() - initialize the I2C hardware | ||
250 | * @dev: private data of I2C Driver | ||
251 | */ | ||
252 | static int init_hw(struct nmk_i2c_dev *dev) | ||
253 | { | ||
254 | int stat; | ||
255 | |||
256 | clk_enable(dev->clk); | ||
257 | |||
258 | stat = flush_i2c_fifo(dev); | ||
259 | if (stat) | ||
260 | return stat; | ||
261 | |||
262 | /* disable the controller */ | ||
263 | i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE); | ||
264 | |||
265 | disable_all_interrupts(dev); | ||
266 | |||
267 | clear_all_interrupts(dev); | ||
268 | |||
269 | dev->cli.operation = I2C_NO_OPERATION; | ||
270 | |||
271 | clk_disable(dev->clk); | ||
272 | |||
273 | udelay(I2C_DELAY); | ||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | /* enable peripheral, master mode operation */ | ||
278 | #define DEFAULT_I2C_REG_CR ((1 << 1) | I2C_CR_PE) | ||
279 | |||
280 | /** | ||
281 | * load_i2c_mcr_reg() - load the MCR register | ||
282 | * @dev: private data of controller | ||
283 | */ | ||
284 | static u32 load_i2c_mcr_reg(struct nmk_i2c_dev *dev) | ||
285 | { | ||
286 | u32 mcr = 0; | ||
287 | |||
288 | /* 7-bit address transaction */ | ||
289 | mcr |= GEN_MASK(1, I2C_MCR_AM, 12); | ||
290 | mcr |= GEN_MASK(dev->cli.slave_adr, I2C_MCR_A7, 1); | ||
291 | |||
292 | /* start byte procedure not applied */ | ||
293 | mcr |= GEN_MASK(0, I2C_MCR_SB, 11); | ||
294 | |||
295 | /* check the operation, master read/write? */ | ||
296 | if (dev->cli.operation == I2C_WRITE) | ||
297 | mcr |= GEN_MASK(I2C_WRITE, I2C_MCR_OP, 0); | ||
298 | else | ||
299 | mcr |= GEN_MASK(I2C_READ, I2C_MCR_OP, 0); | ||
300 | |||
301 | /* stop or repeated start? */ | ||
302 | if (dev->stop) | ||
303 | mcr |= GEN_MASK(1, I2C_MCR_STOP, 14); | ||
304 | else | ||
305 | mcr &= ~(GEN_MASK(1, I2C_MCR_STOP, 14)); | ||
306 | |||
307 | mcr |= GEN_MASK(dev->cli.count, I2C_MCR_LENGTH, 15); | ||
308 | |||
309 | return mcr; | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * setup_i2c_controller() - setup the controller | ||
314 | * @dev: private data of controller | ||
315 | */ | ||
316 | static void setup_i2c_controller(struct nmk_i2c_dev *dev) | ||
317 | { | ||
318 | u32 brcr1, brcr2; | ||
319 | u32 i2c_clk, div; | ||
320 | |||
321 | writel(0x0, dev->virtbase + I2C_CR); | ||
322 | writel(0x0, dev->virtbase + I2C_HSMCR); | ||
323 | writel(0x0, dev->virtbase + I2C_TFTR); | ||
324 | writel(0x0, dev->virtbase + I2C_RFTR); | ||
325 | writel(0x0, dev->virtbase + I2C_DMAR); | ||
326 | |||
327 | /* | ||
328 | * set the slsu: | ||
329 | * | ||
330 | * slsu defines the data setup time after SCL clock | ||
331 | * stretching in terms of i2c clk cycles. The | ||
332 | * needed setup time for the three modes are 250ns, | ||
333 | * 100ns, 10ns repectively thus leading to the values | ||
334 | * of 14, 6, 2 for a 48 MHz i2c clk. | ||
335 | */ | ||
336 | writel(dev->cfg.slsu << 16, dev->virtbase + I2C_SCR); | ||
337 | |||
338 | i2c_clk = clk_get_rate(dev->clk); | ||
339 | |||
340 | /* fallback to std. mode if machine has not provided it */ | ||
341 | if (dev->cfg.clk_freq == 0) | ||
342 | dev->cfg.clk_freq = 100000; | ||
343 | |||
344 | /* | ||
345 | * The spec says, in case of std. mode the divider is | ||
346 | * 2 whereas it is 3 for fast and fastplus mode of | ||
347 | * operation. TODO - high speed support. | ||
348 | */ | ||
349 | div = (dev->cfg.clk_freq > 100000) ? 3 : 2; | ||
350 | |||
351 | /* | ||
352 | * generate the mask for baud rate counters. The controller | ||
353 | * has two baud rate counters. One is used for High speed | ||
354 | * operation, and the other is for std, fast mode, fast mode | ||
355 | * plus operation. Currently we do not supprt high speed mode | ||
356 | * so set brcr1 to 0. | ||
357 | */ | ||
358 | brcr1 = 0 << 16; | ||
359 | brcr2 = (i2c_clk/(dev->cfg.clk_freq * div)) & 0xffff; | ||
360 | |||
361 | /* set the baud rate counter register */ | ||
362 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); | ||
363 | |||
364 | /* | ||
365 | * set the speed mode. Currently we support | ||
366 | * only standard and fast mode of operation | ||
367 | * TODO - support for fast mode plus (upto 1Mb/s) | ||
368 | * and high speed (up to 3.4 Mb/s) | ||
369 | */ | ||
370 | if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { | ||
371 | dev_err(&dev->pdev->dev, "do not support this mode " | ||
372 | "defaulting to std. mode\n"); | ||
373 | brcr2 = i2c_clk/(100000 * 2) & 0xffff; | ||
374 | writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); | ||
375 | writel(I2C_FREQ_MODE_STANDARD << 4, | ||
376 | dev->virtbase + I2C_CR); | ||
377 | } | ||
378 | writel(dev->cfg.sm << 4, dev->virtbase + I2C_CR); | ||
379 | |||
380 | /* set the Tx and Rx FIFO threshold */ | ||
381 | writel(dev->cfg.tft, dev->virtbase + I2C_TFTR); | ||
382 | writel(dev->cfg.rft, dev->virtbase + I2C_RFTR); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * read_i2c() - Read from I2C client device | ||
387 | * @dev: private data of I2C Driver | ||
388 | * | ||
389 | * This function reads from i2c client device when controller is in | ||
390 | * master mode. There is a completion timeout. If there is no transfer | ||
391 | * before timeout error is returned. | ||
392 | */ | ||
393 | static int read_i2c(struct nmk_i2c_dev *dev) | ||
394 | { | ||
395 | u32 status = 0; | ||
396 | u32 mcr; | ||
397 | u32 irq_mask = 0; | ||
398 | int timeout; | ||
399 | |||
400 | mcr = load_i2c_mcr_reg(dev); | ||
401 | writel(mcr, dev->virtbase + I2C_MCR); | ||
402 | |||
403 | /* load the current CR value */ | ||
404 | writel(readl(dev->virtbase + I2C_CR) | DEFAULT_I2C_REG_CR, | ||
405 | dev->virtbase + I2C_CR); | ||
406 | |||
407 | /* enable the controller */ | ||
408 | i2c_set_bit(dev->virtbase + I2C_CR, I2C_CR_PE); | ||
409 | |||
410 | init_completion(&dev->xfer_complete); | ||
411 | |||
412 | /* enable interrupts by setting the mask */ | ||
413 | irq_mask = (I2C_IT_RXFNF | I2C_IT_RXFF | | ||
414 | I2C_IT_MAL | I2C_IT_BERR); | ||
415 | |||
416 | if (dev->stop) | ||
417 | irq_mask |= I2C_IT_MTD; | ||
418 | else | ||
419 | irq_mask |= I2C_IT_MTDWS; | ||
420 | |||
421 | irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask); | ||
422 | |||
423 | writel(readl(dev->virtbase + I2C_IMSCR) | irq_mask, | ||
424 | dev->virtbase + I2C_IMSCR); | ||
425 | |||
426 | timeout = wait_for_completion_interruptible_timeout( | ||
427 | &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); | ||
428 | |||
429 | if (timeout < 0) { | ||
430 | dev_err(&dev->pdev->dev, | ||
431 | "wait_for_completion_interruptible_timeout" | ||
432 | "returned %d waiting for event\n", timeout); | ||
433 | status = timeout; | ||
434 | } | ||
435 | |||
436 | if (timeout == 0) { | ||
437 | /* controler has timedout, re-init the h/w */ | ||
438 | dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); | ||
439 | (void) init_hw(dev); | ||
440 | status = -ETIMEDOUT; | ||
441 | } | ||
442 | return status; | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * write_i2c() - Write data to I2C client. | ||
447 | * @dev: private data of I2C Driver | ||
448 | * | ||
449 | * This function writes data to I2C client | ||
450 | */ | ||
451 | static int write_i2c(struct nmk_i2c_dev *dev) | ||
452 | { | ||
453 | u32 status = 0; | ||
454 | u32 mcr; | ||
455 | u32 irq_mask = 0; | ||
456 | int timeout; | ||
457 | |||
458 | mcr = load_i2c_mcr_reg(dev); | ||
459 | |||
460 | writel(mcr, dev->virtbase + I2C_MCR); | ||
461 | |||
462 | /* load the current CR value */ | ||
463 | writel(readl(dev->virtbase + I2C_CR) | DEFAULT_I2C_REG_CR, | ||
464 | dev->virtbase + I2C_CR); | ||
465 | |||
466 | /* enable the controller */ | ||
467 | i2c_set_bit(dev->virtbase + I2C_CR , I2C_CR_PE); | ||
468 | |||
469 | init_completion(&dev->xfer_complete); | ||
470 | |||
471 | /* enable interrupts by settings the masks */ | ||
472 | irq_mask = (I2C_IT_TXFNE | I2C_IT_TXFOVR | | ||
473 | I2C_IT_MAL | I2C_IT_BERR); | ||
474 | |||
475 | /* | ||
476 | * check if we want to transfer a single or multiple bytes, if so | ||
477 | * set the MTDWS bit (Master Transaction Done Without Stop) | ||
478 | * to start repeated start operation | ||
479 | */ | ||
480 | if (dev->stop) | ||
481 | irq_mask |= I2C_IT_MTD; | ||
482 | else | ||
483 | irq_mask |= I2C_IT_MTDWS; | ||
484 | |||
485 | irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask); | ||
486 | |||
487 | writel(readl(dev->virtbase + I2C_IMSCR) | irq_mask, | ||
488 | dev->virtbase + I2C_IMSCR); | ||
489 | |||
490 | timeout = wait_for_completion_interruptible_timeout( | ||
491 | &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); | ||
492 | |||
493 | if (timeout < 0) { | ||
494 | dev_err(&dev->pdev->dev, | ||
495 | "wait_for_completion_interruptible_timeout" | ||
496 | "returned %d waiting for event\n", timeout); | ||
497 | status = timeout; | ||
498 | } | ||
499 | |||
500 | if (timeout == 0) { | ||
501 | /* controler has timedout, re-init the h/w */ | ||
502 | dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); | ||
503 | (void) init_hw(dev); | ||
504 | status = -ETIMEDOUT; | ||
505 | } | ||
506 | |||
507 | return status; | ||
508 | } | ||
509 | |||
510 | /** | ||
511 | * nmk_i2c_xfer() - I2C transfer function used by kernel framework | ||
512 | * @i2c_adap: Adapter pointer to the controller | ||
513 | * @msgs: Pointer to data to be written. | ||
514 | * @num_msgs: Number of messages to be executed | ||
515 | * | ||
516 | * This is the function called by the generic kernel i2c_transfer() | ||
517 | * or i2c_smbus...() API calls. Note that this code is protected by the | ||
518 | * semaphore set in the kernel i2c_transfer() function. | ||
519 | * | ||
520 | * NOTE: | ||
521 | * READ TRANSFER : We impose a restriction of the first message to be the | ||
522 | * index message for any read transaction. | ||
523 | * - a no index is coded as '0', | ||
524 | * - 2byte big endian index is coded as '3' | ||
525 | * !!! msg[0].buf holds the actual index. | ||
526 | * This is compatible with generic messages of smbus emulator | ||
527 | * that send a one byte index. | ||
528 | * eg. a I2C transation to read 2 bytes from index 0 | ||
529 | * idx = 0; | ||
530 | * msg[0].addr = client->addr; | ||
531 | * msg[0].flags = 0x0; | ||
532 | * msg[0].len = 1; | ||
533 | * msg[0].buf = &idx; | ||
534 | * | ||
535 | * msg[1].addr = client->addr; | ||
536 | * msg[1].flags = I2C_M_RD; | ||
537 | * msg[1].len = 2; | ||
538 | * msg[1].buf = rd_buff | ||
539 | * i2c_transfer(adap, msg, 2); | ||
540 | * | ||
541 | * WRITE TRANSFER : The I2C standard interface interprets all data as payload. | ||
542 | * If you want to emulate an SMBUS write transaction put the | ||
543 | * index as first byte(or first and second) in the payload. | ||
544 | * eg. a I2C transation to write 2 bytes from index 1 | ||
545 | * wr_buff[0] = 0x1; | ||
546 | * wr_buff[1] = 0x23; | ||
547 | * wr_buff[2] = 0x46; | ||
548 | * msg[0].flags = 0x0; | ||
549 | * msg[0].len = 3; | ||
550 | * msg[0].buf = wr_buff; | ||
551 | * i2c_transfer(adap, msg, 1); | ||
552 | * | ||
553 | * To read or write a block of data (multiple bytes) using SMBUS emulation | ||
554 | * please use the i2c_smbus_read_i2c_block_data() | ||
555 | * or i2c_smbus_write_i2c_block_data() API | ||
556 | */ | ||
557 | static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, | ||
558 | struct i2c_msg msgs[], int num_msgs) | ||
559 | { | ||
560 | int status; | ||
561 | int i; | ||
562 | u32 cause; | ||
563 | struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); | ||
564 | |||
565 | status = init_hw(dev); | ||
566 | if (status) | ||
567 | return status; | ||
568 | |||
569 | clk_enable(dev->clk); | ||
570 | |||
571 | /* setup the i2c controller */ | ||
572 | setup_i2c_controller(dev); | ||
573 | |||
574 | for (i = 0; i < num_msgs; i++) { | ||
575 | if (unlikely(msgs[i].flags & I2C_M_TEN)) { | ||
576 | dev_err(&dev->pdev->dev, "10 bit addressing" | ||
577 | "not supported\n"); | ||
578 | return -EINVAL; | ||
579 | } | ||
580 | dev->cli.slave_adr = msgs[i].addr; | ||
581 | dev->cli.buffer = msgs[i].buf; | ||
582 | dev->cli.count = msgs[i].len; | ||
583 | dev->stop = (i < (num_msgs - 1)) ? 0 : 1; | ||
584 | dev->result = 0; | ||
585 | |||
586 | if (msgs[i].flags & I2C_M_RD) { | ||
587 | /* it is a read operation */ | ||
588 | dev->cli.operation = I2C_READ; | ||
589 | status = read_i2c(dev); | ||
590 | } else { | ||
591 | /* write operation */ | ||
592 | dev->cli.operation = I2C_WRITE; | ||
593 | status = write_i2c(dev); | ||
594 | } | ||
595 | if (status || (dev->result)) { | ||
596 | /* get the abort cause */ | ||
597 | cause = (readl(dev->virtbase + I2C_SR) >> 4) & 0x7; | ||
598 | dev_err(&dev->pdev->dev, "error during I2C" | ||
599 | "message xfer: %d\n", cause); | ||
600 | dev_err(&dev->pdev->dev, "%s\n", | ||
601 | cause >= ARRAY_SIZE(abort_causes) | ||
602 | ? "unknown reason" : abort_causes[cause]); | ||
603 | clk_disable(dev->clk); | ||
604 | return status; | ||
605 | } | ||
606 | udelay(I2C_DELAY); | ||
607 | } | ||
608 | clk_disable(dev->clk); | ||
609 | |||
610 | /* return the no. messages processed */ | ||
611 | if (status) | ||
612 | return status; | ||
613 | else | ||
614 | return num_msgs; | ||
615 | } | ||
616 | |||
617 | /** | ||
618 | * disable_interrupts() - disable the interrupts | ||
619 | * @dev: private data of controller | ||
620 | * @irq: interrupt number | ||
621 | */ | ||
622 | static int disable_interrupts(struct nmk_i2c_dev *dev, u32 irq) | ||
623 | { | ||
624 | irq = IRQ_MASK(irq); | ||
625 | writel(readl(dev->virtbase + I2C_IMSCR) & ~(I2C_CLEAR_ALL_INTS & irq), | ||
626 | dev->virtbase + I2C_IMSCR); | ||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * i2c_irq_handler() - interrupt routine | ||
632 | * @irq: interrupt number | ||
633 | * @arg: data passed to the handler | ||
634 | * | ||
635 | * This is the interrupt handler for the i2c driver. Currently | ||
636 | * it handles the major interrupts like Rx & Tx FIFO management | ||
637 | * interrupts, master transaction interrupts, arbitration and | ||
638 | * bus error interrupts. The rest of the interrupts are treated as | ||
639 | * unhandled. | ||
640 | */ | ||
641 | static irqreturn_t i2c_irq_handler(int irq, void *arg) | ||
642 | { | ||
643 | struct nmk_i2c_dev *dev = arg; | ||
644 | u32 tft, rft; | ||
645 | u32 count; | ||
646 | u32 misr; | ||
647 | u32 src = 0; | ||
648 | |||
649 | /* load Tx FIFO and Rx FIFO threshold values */ | ||
650 | tft = readl(dev->virtbase + I2C_TFTR); | ||
651 | rft = readl(dev->virtbase + I2C_RFTR); | ||
652 | |||
653 | /* read interrupt status register */ | ||
654 | misr = readl(dev->virtbase + I2C_MISR); | ||
655 | |||
656 | src = __ffs(misr); | ||
657 | switch ((1 << src)) { | ||
658 | |||
659 | /* Transmit FIFO nearly empty interrupt */ | ||
660 | case I2C_IT_TXFNE: | ||
661 | { | ||
662 | if (dev->cli.operation == I2C_READ) { | ||
663 | /* | ||
664 | * in read operation why do we care for writing? | ||
665 | * so disable the Transmit FIFO interrupt | ||
666 | */ | ||
667 | disable_interrupts(dev, I2C_IT_TXFNE); | ||
668 | } else { | ||
669 | for (count = (MAX_I2C_FIFO_THRESHOLD - tft - 2); | ||
670 | (count > 0) && | ||
671 | (dev->cli.count != 0); | ||
672 | count--) { | ||
673 | /* write to the Tx FIFO */ | ||
674 | writeb(*dev->cli.buffer, | ||
675 | dev->virtbase + I2C_TFR); | ||
676 | dev->cli.buffer++; | ||
677 | dev->cli.count--; | ||
678 | dev->cli.xfer_bytes++; | ||
679 | } | ||
680 | /* | ||
681 | * if done, close the transfer by disabling the | ||
682 | * corresponding TXFNE interrupt | ||
683 | */ | ||
684 | if (dev->cli.count == 0) | ||
685 | disable_interrupts(dev, I2C_IT_TXFNE); | ||
686 | } | ||
687 | } | ||
688 | break; | ||
689 | |||
690 | /* | ||
691 | * Rx FIFO nearly full interrupt. | ||
692 | * This is set when the numer of entries in Rx FIFO is | ||
693 | * greater or equal than the threshold value programmed | ||
694 | * in RFT | ||
695 | */ | ||
696 | case I2C_IT_RXFNF: | ||
697 | for (count = rft; count > 0; count--) { | ||
698 | /* Read the Rx FIFO */ | ||
699 | *dev->cli.buffer = readb(dev->virtbase + I2C_RFR); | ||
700 | dev->cli.buffer++; | ||
701 | } | ||
702 | dev->cli.count -= rft; | ||
703 | dev->cli.xfer_bytes += rft; | ||
704 | break; | ||
705 | |||
706 | /* Rx FIFO full */ | ||
707 | case I2C_IT_RXFF: | ||
708 | for (count = MAX_I2C_FIFO_THRESHOLD; count > 0; count--) { | ||
709 | *dev->cli.buffer = readb(dev->virtbase + I2C_RFR); | ||
710 | dev->cli.buffer++; | ||
711 | } | ||
712 | dev->cli.count -= MAX_I2C_FIFO_THRESHOLD; | ||
713 | dev->cli.xfer_bytes += MAX_I2C_FIFO_THRESHOLD; | ||
714 | break; | ||
715 | |||
716 | /* Master Transaction Done with/without stop */ | ||
717 | case I2C_IT_MTD: | ||
718 | case I2C_IT_MTDWS: | ||
719 | if (dev->cli.operation == I2C_READ) { | ||
720 | while (!(readl(dev->virtbase + I2C_RISR) | ||
721 | & I2C_IT_RXFE)) { | ||
722 | if (dev->cli.count == 0) | ||
723 | break; | ||
724 | *dev->cli.buffer = | ||
725 | readb(dev->virtbase + I2C_RFR); | ||
726 | dev->cli.buffer++; | ||
727 | dev->cli.count--; | ||
728 | dev->cli.xfer_bytes++; | ||
729 | } | ||
730 | } | ||
731 | |||
732 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTD); | ||
733 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTDWS); | ||
734 | |||
735 | disable_interrupts(dev, | ||
736 | (I2C_IT_TXFNE | I2C_IT_TXFE | I2C_IT_TXFF | ||
737 | | I2C_IT_TXFOVR | I2C_IT_RXFNF | ||
738 | | I2C_IT_RXFF | I2C_IT_RXFE)); | ||
739 | |||
740 | if (dev->cli.count) { | ||
741 | dev->result = -1; | ||
742 | dev_err(&dev->pdev->dev, "%lu bytes still remain to be" | ||
743 | "xfered\n", dev->cli.count); | ||
744 | (void) init_hw(dev); | ||
745 | } | ||
746 | complete(&dev->xfer_complete); | ||
747 | |||
748 | break; | ||
749 | |||
750 | /* Master Arbitration lost interrupt */ | ||
751 | case I2C_IT_MAL: | ||
752 | dev->result = -1; | ||
753 | (void) init_hw(dev); | ||
754 | |||
755 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL); | ||
756 | complete(&dev->xfer_complete); | ||
757 | |||
758 | break; | ||
759 | |||
760 | /* | ||
761 | * Bus Error interrupt. | ||
762 | * This happens when an unexpected start/stop condition occurs | ||
763 | * during the transaction. | ||
764 | */ | ||
765 | case I2C_IT_BERR: | ||
766 | dev->result = -1; | ||
767 | /* get the status */ | ||
768 | if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT) | ||
769 | (void) init_hw(dev); | ||
770 | |||
771 | i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_BERR); | ||
772 | complete(&dev->xfer_complete); | ||
773 | |||
774 | break; | ||
775 | |||
776 | /* | ||
777 | * Tx FIFO overrun interrupt. | ||
778 | * This is set when a write operation in Tx FIFO is performed and | ||
779 | * the Tx FIFO is full. | ||
780 | */ | ||
781 | case I2C_IT_TXFOVR: | ||
782 | dev->result = -1; | ||
783 | (void) init_hw(dev); | ||
784 | |||
785 | dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); | ||
786 | complete(&dev->xfer_complete); | ||
787 | |||
788 | break; | ||
789 | |||
790 | /* unhandled interrupts by this driver - TODO*/ | ||
791 | case I2C_IT_TXFE: | ||
792 | case I2C_IT_TXFF: | ||
793 | case I2C_IT_RXFE: | ||
794 | case I2C_IT_RFSR: | ||
795 | case I2C_IT_RFSE: | ||
796 | case I2C_IT_WTSR: | ||
797 | case I2C_IT_STD: | ||
798 | dev_err(&dev->pdev->dev, "unhandled Interrupt\n"); | ||
799 | break; | ||
800 | default: | ||
801 | dev_err(&dev->pdev->dev, "spurious Interrupt..\n"); | ||
802 | break; | ||
803 | } | ||
804 | |||
805 | return IRQ_HANDLED; | ||
806 | } | ||
807 | |||
808 | static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) | ||
809 | { | ||
810 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | ||
811 | } | ||
812 | |||
813 | static const struct i2c_algorithm nmk_i2c_algo = { | ||
814 | .master_xfer = nmk_i2c_xfer, | ||
815 | .functionality = nmk_i2c_functionality | ||
816 | }; | ||
817 | |||
818 | static int __devinit nmk_i2c_probe(struct platform_device *pdev) | ||
819 | { | ||
820 | int ret = 0; | ||
821 | struct resource *res; | ||
822 | struct nmk_i2c_controller *pdata = | ||
823 | pdev->dev.platform_data; | ||
824 | struct nmk_i2c_dev *dev; | ||
825 | struct i2c_adapter *adap; | ||
826 | |||
827 | dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); | ||
828 | if (!dev) { | ||
829 | dev_err(&pdev->dev, "cannot allocate memory\n"); | ||
830 | ret = -ENOMEM; | ||
831 | goto err_no_mem; | ||
832 | } | ||
833 | |||
834 | dev->pdev = pdev; | ||
835 | platform_set_drvdata(pdev, dev); | ||
836 | |||
837 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
838 | if (!res) { | ||
839 | ret = -ENOENT; | ||
840 | goto err_no_resource; | ||
841 | } | ||
842 | |||
843 | if (request_mem_region(res->start, resource_size(res), | ||
844 | DRIVER_NAME "I/O region") == NULL) { | ||
845 | ret = -EBUSY; | ||
846 | goto err_no_region; | ||
847 | } | ||
848 | |||
849 | dev->virtbase = ioremap(res->start, resource_size(res)); | ||
850 | if (!dev->virtbase) { | ||
851 | ret = -ENOMEM; | ||
852 | goto err_no_ioremap; | ||
853 | } | ||
854 | |||
855 | dev->irq = platform_get_irq(pdev, 0); | ||
856 | ret = request_irq(dev->irq, i2c_irq_handler, IRQF_DISABLED, | ||
857 | DRIVER_NAME, dev); | ||
858 | if (ret) { | ||
859 | dev_err(&pdev->dev, "cannot claim the irq %d\n", dev->irq); | ||
860 | goto err_irq; | ||
861 | } | ||
862 | |||
863 | dev->clk = clk_get(&pdev->dev, NULL); | ||
864 | if (IS_ERR(dev->clk)) { | ||
865 | dev_err(&pdev->dev, "could not get i2c clock\n"); | ||
866 | ret = PTR_ERR(dev->clk); | ||
867 | goto err_no_clk; | ||
868 | } | ||
869 | |||
870 | adap = &dev->adap; | ||
871 | adap->dev.parent = &pdev->dev; | ||
872 | adap->owner = THIS_MODULE; | ||
873 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | ||
874 | adap->algo = &nmk_i2c_algo; | ||
875 | |||
876 | /* fetch the controller id */ | ||
877 | adap->nr = pdev->id; | ||
878 | |||
879 | /* fetch the controller configuration from machine */ | ||
880 | dev->cfg.clk_freq = pdata->clk_freq; | ||
881 | dev->cfg.slsu = pdata->slsu; | ||
882 | dev->cfg.tft = pdata->tft; | ||
883 | dev->cfg.rft = pdata->rft; | ||
884 | dev->cfg.sm = pdata->sm; | ||
885 | |||
886 | i2c_set_adapdata(adap, dev); | ||
887 | |||
888 | ret = init_hw(dev); | ||
889 | if (ret != 0) { | ||
890 | dev_err(&pdev->dev, "error in initializing i2c hardware\n"); | ||
891 | goto err_init_hw; | ||
892 | } | ||
893 | |||
894 | dev_dbg(&pdev->dev, "initialize I2C%d bus on virtual " | ||
895 | "base %p\n", pdev->id, dev->virtbase); | ||
896 | |||
897 | ret = i2c_add_numbered_adapter(adap); | ||
898 | if (ret) { | ||
899 | dev_err(&pdev->dev, "failed to add adapter\n"); | ||
900 | goto err_add_adap; | ||
901 | } | ||
902 | |||
903 | return 0; | ||
904 | |||
905 | err_init_hw: | ||
906 | err_add_adap: | ||
907 | clk_put(dev->clk); | ||
908 | err_no_clk: | ||
909 | free_irq(dev->irq, dev); | ||
910 | err_irq: | ||
911 | iounmap(dev->virtbase); | ||
912 | err_no_ioremap: | ||
913 | release_mem_region(res->start, resource_size(res)); | ||
914 | err_no_region: | ||
915 | platform_set_drvdata(pdev, NULL); | ||
916 | err_no_resource: | ||
917 | kfree(dev); | ||
918 | err_no_mem: | ||
919 | |||
920 | return ret; | ||
921 | } | ||
922 | |||
923 | static int __devexit nmk_i2c_remove(struct platform_device *pdev) | ||
924 | { | ||
925 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
926 | struct nmk_i2c_dev *dev = platform_get_drvdata(pdev); | ||
927 | |||
928 | i2c_del_adapter(&dev->adap); | ||
929 | flush_i2c_fifo(dev); | ||
930 | disable_all_interrupts(dev); | ||
931 | clear_all_interrupts(dev); | ||
932 | /* disable the controller */ | ||
933 | i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE); | ||
934 | free_irq(dev->irq, dev); | ||
935 | iounmap(dev->virtbase); | ||
936 | if (res) | ||
937 | release_mem_region(res->start, resource_size(res)); | ||
938 | clk_put(dev->clk); | ||
939 | platform_set_drvdata(pdev, NULL); | ||
940 | kfree(dev); | ||
941 | |||
942 | return 0; | ||
943 | } | ||
944 | |||
945 | static struct platform_driver nmk_i2c_driver = { | ||
946 | .driver = { | ||
947 | .owner = THIS_MODULE, | ||
948 | .name = DRIVER_NAME, | ||
949 | }, | ||
950 | .probe = nmk_i2c_probe, | ||
951 | .remove = __devexit_p(nmk_i2c_remove), | ||
952 | }; | ||
953 | |||
954 | static int __init nmk_i2c_init(void) | ||
955 | { | ||
956 | return platform_driver_register(&nmk_i2c_driver); | ||
957 | } | ||
958 | |||
959 | static void __exit nmk_i2c_exit(void) | ||
960 | { | ||
961 | platform_driver_unregister(&nmk_i2c_driver); | ||
962 | } | ||
963 | |||
964 | subsys_initcall(nmk_i2c_init); | ||
965 | module_exit(nmk_i2c_exit); | ||
966 | |||
967 | MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR"); | ||
968 | MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver"); | ||
969 | MODULE_LICENSE("GPL"); | ||
970 | MODULE_ALIAS("platform:" DRIVER_NAME); | ||
diff --git a/drivers/i2c/busses/i2c-nuc900.c b/drivers/i2c/busses/i2c-nuc900.c new file mode 100644 index 000000000000..72434263787b --- /dev/null +++ b/drivers/i2c/busses/i2c-nuc900.c | |||
@@ -0,0 +1,708 @@ | |||
1 | /* | ||
2 | * linux/drivers/i2c/busses/i2c-nuc900.c | ||
3 | * | ||
4 | * Copyright (c) 2010 Nuvoton technology corporation. | ||
5 | * | ||
6 | * This driver based on S3C2410 I2C driver of Ben Dooks <ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org>. | ||
7 | * Written by Wan ZongShun <mcuos.com-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> | ||
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;version 2 of the License. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | |||
18 | #include <linux/i2c.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/time.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/errno.h> | ||
24 | #include <linux/err.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/clk.h> | ||
27 | #include <linux/cpufreq.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/io.h> | ||
30 | |||
31 | #include <mach/mfp.h> | ||
32 | #include <mach/i2c.h> | ||
33 | |||
34 | /* nuc900 i2c registers offset */ | ||
35 | |||
36 | #define CSR 0x00 | ||
37 | #define DIVIDER 0x04 | ||
38 | #define CMDR 0x08 | ||
39 | #define SWR 0x0C | ||
40 | #define RXR 0x10 | ||
41 | #define TXR 0x14 | ||
42 | |||
43 | /* nuc900 i2c CSR register bits */ | ||
44 | |||
45 | #define IRQEN 0x003 | ||
46 | #define I2CBUSY 0x400 | ||
47 | #define I2CSTART 0x018 | ||
48 | #define IRQFLAG 0x004 | ||
49 | #define ARBIT_LOST 0x200 | ||
50 | #define SLAVE_ACK 0x800 | ||
51 | |||
52 | /* nuc900 i2c CMDR register bits */ | ||
53 | |||
54 | #define I2C_CMD_START 0x10 | ||
55 | #define I2C_CMD_STOP 0x08 | ||
56 | #define I2C_CMD_READ 0x04 | ||
57 | #define I2C_CMD_WRITE 0x02 | ||
58 | #define I2C_CMD_NACK 0x01 | ||
59 | |||
60 | /* i2c controller state */ | ||
61 | |||
62 | enum nuc900_i2c_state { | ||
63 | STATE_IDLE, | ||
64 | STATE_START, | ||
65 | STATE_READ, | ||
66 | STATE_WRITE, | ||
67 | STATE_STOP | ||
68 | }; | ||
69 | |||
70 | /* i2c controller private data */ | ||
71 | |||
72 | struct nuc900_i2c { | ||
73 | spinlock_t lock; | ||
74 | wait_queue_head_t wait; | ||
75 | |||
76 | struct i2c_msg *msg; | ||
77 | unsigned int msg_num; | ||
78 | unsigned int msg_idx; | ||
79 | unsigned int msg_ptr; | ||
80 | unsigned int irq; | ||
81 | |||
82 | enum nuc900_i2c_state state; | ||
83 | |||
84 | void __iomem *regs; | ||
85 | struct clk *clk; | ||
86 | struct device *dev; | ||
87 | struct resource *ioarea; | ||
88 | struct i2c_adapter adap; | ||
89 | }; | ||
90 | |||
91 | /* nuc900_i2c_master_complete | ||
92 | * | ||
93 | * complete the message and wake up the caller, using the given return code, | ||
94 | * or zero to mean ok. | ||
95 | */ | ||
96 | |||
97 | static inline void nuc900_i2c_master_complete(struct nuc900_i2c *i2c, int ret) | ||
98 | { | ||
99 | dev_dbg(i2c->dev, "master_complete %d\n", ret); | ||
100 | |||
101 | i2c->msg_ptr = 0; | ||
102 | i2c->msg = NULL; | ||
103 | i2c->msg_idx++; | ||
104 | i2c->msg_num = 0; | ||
105 | if (ret) | ||
106 | i2c->msg_idx = ret; | ||
107 | |||
108 | wake_up(&i2c->wait); | ||
109 | } | ||
110 | |||
111 | /* irq enable/disable functions */ | ||
112 | |||
113 | static inline void nuc900_i2c_disable_irq(struct nuc900_i2c *i2c) | ||
114 | { | ||
115 | unsigned long tmp; | ||
116 | |||
117 | tmp = readl(i2c->regs + CSR); | ||
118 | writel(tmp & ~IRQEN, i2c->regs + CSR); | ||
119 | } | ||
120 | |||
121 | static inline void nuc900_i2c_enable_irq(struct nuc900_i2c *i2c) | ||
122 | { | ||
123 | unsigned long tmp; | ||
124 | |||
125 | tmp = readl(i2c->regs + CSR); | ||
126 | writel(tmp | IRQEN, i2c->regs + CSR); | ||
127 | } | ||
128 | |||
129 | |||
130 | /* nuc900_i2c_message_start | ||
131 | * | ||
132 | * put the start of a message onto the bus | ||
133 | */ | ||
134 | |||
135 | static void nuc900_i2c_message_start(struct nuc900_i2c *i2c, | ||
136 | struct i2c_msg *msg) | ||
137 | { | ||
138 | unsigned int addr = (msg->addr & 0x7f) << 1; | ||
139 | |||
140 | if (msg->flags & I2C_M_RD) | ||
141 | addr |= 0x1; | ||
142 | writel(addr & 0xff, i2c->regs + TXR); | ||
143 | writel(I2C_CMD_START | I2C_CMD_WRITE, i2c->regs + CMDR); | ||
144 | } | ||
145 | |||
146 | static inline void nuc900_i2c_stop(struct nuc900_i2c *i2c, int ret) | ||
147 | { | ||
148 | |||
149 | dev_dbg(i2c->dev, "STOP\n"); | ||
150 | |||
151 | /* stop the transfer */ | ||
152 | i2c->state = STATE_STOP; | ||
153 | writel(I2C_CMD_STOP, i2c->regs + CMDR); | ||
154 | |||
155 | nuc900_i2c_master_complete(i2c, ret); | ||
156 | nuc900_i2c_disable_irq(i2c); | ||
157 | } | ||
158 | |||
159 | /* helper functions to determine the current state in the set of | ||
160 | * messages we are sending | ||
161 | */ | ||
162 | |||
163 | /* is_lastmsg() | ||
164 | * | ||
165 | * returns TRUE if the current message is the last in the set | ||
166 | */ | ||
167 | |||
168 | static inline int is_lastmsg(struct nuc900_i2c *i2c) | ||
169 | { | ||
170 | return i2c->msg_idx >= (i2c->msg_num - 1); | ||
171 | } | ||
172 | |||
173 | /* is_msglast | ||
174 | * | ||
175 | * returns TRUE if we this is the last byte in the current message | ||
176 | */ | ||
177 | |||
178 | static inline int is_msglast(struct nuc900_i2c *i2c) | ||
179 | { | ||
180 | return i2c->msg_ptr == i2c->msg->len-1; | ||
181 | } | ||
182 | |||
183 | /* is_msgend | ||
184 | * | ||
185 | * returns TRUE if we reached the end of the current message | ||
186 | */ | ||
187 | |||
188 | static inline int is_msgend(struct nuc900_i2c *i2c) | ||
189 | { | ||
190 | return i2c->msg_ptr >= i2c->msg->len; | ||
191 | } | ||
192 | |||
193 | /* i2c_nuc900_irq_nextbyte | ||
194 | * | ||
195 | * process an interrupt and work out what to do | ||
196 | */ | ||
197 | |||
198 | static void i2c_nuc900_irq_nextbyte(struct nuc900_i2c *i2c, | ||
199 | unsigned long iicstat) | ||
200 | { | ||
201 | unsigned char byte; | ||
202 | |||
203 | switch (i2c->state) { | ||
204 | |||
205 | case STATE_IDLE: | ||
206 | dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__); | ||
207 | break; | ||
208 | |||
209 | case STATE_STOP: | ||
210 | dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__); | ||
211 | nuc900_i2c_disable_irq(i2c); | ||
212 | break; | ||
213 | |||
214 | case STATE_START: | ||
215 | /* last thing we did was send a start condition on the | ||
216 | * bus, or started a new i2c message | ||
217 | */ | ||
218 | |||
219 | if (iicstat & SLAVE_ACK && | ||
220 | !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { | ||
221 | /* ack was not received... */ | ||
222 | |||
223 | dev_dbg(i2c->dev, "ack was not received\n"); | ||
224 | nuc900_i2c_stop(i2c, -ENXIO); | ||
225 | break; | ||
226 | } | ||
227 | |||
228 | if (i2c->msg->flags & I2C_M_RD) | ||
229 | i2c->state = STATE_READ; | ||
230 | else | ||
231 | i2c->state = STATE_WRITE; | ||
232 | |||
233 | /* terminate the transfer if there is nothing to do | ||
234 | * as this is used by the i2c probe to find devices. | ||
235 | */ | ||
236 | |||
237 | if (is_lastmsg(i2c) && i2c->msg->len == 0) { | ||
238 | nuc900_i2c_stop(i2c, 0); | ||
239 | break; | ||
240 | } | ||
241 | |||
242 | if (i2c->state == STATE_READ) | ||
243 | goto prepare_read; | ||
244 | |||
245 | /* fall through to the write state, as we will need to | ||
246 | * send a byte as well | ||
247 | */ | ||
248 | |||
249 | case STATE_WRITE: | ||
250 | /* we are writing data to the device... check for the | ||
251 | * end of the message, and if so, work out what to do | ||
252 | */ | ||
253 | |||
254 | if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) { | ||
255 | if (iicstat & SLAVE_ACK) { | ||
256 | dev_dbg(i2c->dev, "WRITE: No Ack\n"); | ||
257 | |||
258 | nuc900_i2c_stop(i2c, -ECONNREFUSED); | ||
259 | break; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | retry_write: | ||
264 | |||
265 | if (!is_msgend(i2c)) { | ||
266 | byte = i2c->msg->buf[i2c->msg_ptr++]; | ||
267 | writeb(byte, i2c->regs + TXR); | ||
268 | writel(I2C_CMD_WRITE, i2c->regs + CMDR); | ||
269 | |||
270 | } else if (!is_lastmsg(i2c)) { | ||
271 | /* we need to go to the next i2c message */ | ||
272 | |||
273 | dev_dbg(i2c->dev, "WRITE: Next Message\n"); | ||
274 | |||
275 | i2c->msg_ptr = 0; | ||
276 | i2c->msg_idx++; | ||
277 | i2c->msg++; | ||
278 | |||
279 | /* check to see if we need to do another message */ | ||
280 | if (i2c->msg->flags & I2C_M_NOSTART) { | ||
281 | |||
282 | if (i2c->msg->flags & I2C_M_RD) { | ||
283 | /* cannot do this, the controller | ||
284 | * forces us to send a new START | ||
285 | * when we change direction | ||
286 | */ | ||
287 | |||
288 | nuc900_i2c_stop(i2c, -EINVAL); | ||
289 | } | ||
290 | |||
291 | goto retry_write; | ||
292 | } else { | ||
293 | /* send the new start */ | ||
294 | nuc900_i2c_message_start(i2c, i2c->msg); | ||
295 | i2c->state = STATE_START; | ||
296 | } | ||
297 | |||
298 | } else { | ||
299 | /* send stop */ | ||
300 | |||
301 | nuc900_i2c_stop(i2c, 0); | ||
302 | } | ||
303 | break; | ||
304 | |||
305 | case STATE_READ: | ||
306 | /* we have a byte of data in the data register, do | ||
307 | * something with it, and then work out wether we are | ||
308 | * going to do any more read/write | ||
309 | */ | ||
310 | |||
311 | byte = readb(i2c->regs + RXR); | ||
312 | i2c->msg->buf[i2c->msg_ptr++] = byte; | ||
313 | |||
314 | prepare_read: | ||
315 | if (is_msglast(i2c)) { | ||
316 | /* last byte of buffer */ | ||
317 | |||
318 | if (is_lastmsg(i2c)) | ||
319 | writel(I2C_CMD_READ | I2C_CMD_NACK, | ||
320 | i2c->regs + CMDR); | ||
321 | |||
322 | } else if (is_msgend(i2c)) { | ||
323 | /* ok, we've read the entire buffer, see if there | ||
324 | * is anything else we need to do | ||
325 | */ | ||
326 | |||
327 | if (is_lastmsg(i2c)) { | ||
328 | /* last message, send stop and complete */ | ||
329 | dev_dbg(i2c->dev, "READ: Send Stop\n"); | ||
330 | |||
331 | nuc900_i2c_stop(i2c, 0); | ||
332 | } else { | ||
333 | /* go to the next transfer */ | ||
334 | dev_dbg(i2c->dev, "READ: Next Transfer\n"); | ||
335 | |||
336 | i2c->msg_ptr = 0; | ||
337 | i2c->msg_idx++; | ||
338 | i2c->msg++; | ||
339 | |||
340 | writel(I2C_CMD_READ, i2c->regs + CMDR); | ||
341 | } | ||
342 | |||
343 | } else { | ||
344 | writel(I2C_CMD_READ, i2c->regs + CMDR); | ||
345 | } | ||
346 | |||
347 | break; | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /* nuc900_i2c_irq | ||
352 | * | ||
353 | * top level IRQ servicing routine | ||
354 | */ | ||
355 | |||
356 | static irqreturn_t nuc900_i2c_irq(int irqno, void *dev_id) | ||
357 | { | ||
358 | struct nuc900_i2c *i2c = dev_id; | ||
359 | unsigned long status; | ||
360 | |||
361 | status = readl(i2c->regs + CSR); | ||
362 | writel(status | IRQFLAG, i2c->regs + CSR); | ||
363 | |||
364 | if (status & ARBIT_LOST) { | ||
365 | /* deal with arbitration loss */ | ||
366 | dev_err(i2c->dev, "deal with arbitration loss\n"); | ||
367 | goto out; | ||
368 | } | ||
369 | |||
370 | if (i2c->state == STATE_IDLE) { | ||
371 | dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n"); | ||
372 | goto out; | ||
373 | } | ||
374 | |||
375 | /* pretty much this leaves us with the fact that we've | ||
376 | * transmitted or received whatever byte we last sent | ||
377 | */ | ||
378 | |||
379 | i2c_nuc900_irq_nextbyte(i2c, status); | ||
380 | |||
381 | out: | ||
382 | return IRQ_HANDLED; | ||
383 | } | ||
384 | |||
385 | |||
386 | /* nuc900_i2c_set_master | ||
387 | * | ||
388 | * get the i2c bus for a master transaction | ||
389 | */ | ||
390 | |||
391 | static int nuc900_i2c_set_master(struct nuc900_i2c *i2c) | ||
392 | { | ||
393 | int timeout = 400; | ||
394 | |||
395 | while (timeout-- > 0) { | ||
396 | if (((readl(i2c->regs + SWR) & I2CSTART) == I2CSTART) && | ||
397 | ((readl(i2c->regs + CSR) & I2CBUSY) == 0)) { | ||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | msleep(1); | ||
402 | } | ||
403 | |||
404 | return -ETIMEDOUT; | ||
405 | } | ||
406 | |||
407 | /* nuc900_i2c_doxfer | ||
408 | * | ||
409 | * this starts an i2c transfer | ||
410 | */ | ||
411 | |||
412 | static int nuc900_i2c_doxfer(struct nuc900_i2c *i2c, | ||
413 | struct i2c_msg *msgs, int num) | ||
414 | { | ||
415 | unsigned long iicstat, timeout; | ||
416 | int spins = 20; | ||
417 | int ret; | ||
418 | |||
419 | ret = nuc900_i2c_set_master(i2c); | ||
420 | if (ret != 0) { | ||
421 | dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); | ||
422 | ret = -EAGAIN; | ||
423 | goto out; | ||
424 | } | ||
425 | |||
426 | spin_lock_irq(&i2c->lock); | ||
427 | |||
428 | i2c->msg = msgs; | ||
429 | i2c->msg_num = num; | ||
430 | i2c->msg_ptr = 0; | ||
431 | i2c->msg_idx = 0; | ||
432 | i2c->state = STATE_START; | ||
433 | |||
434 | nuc900_i2c_message_start(i2c, msgs); | ||
435 | spin_unlock_irq(&i2c->lock); | ||
436 | |||
437 | timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); | ||
438 | |||
439 | ret = i2c->msg_idx; | ||
440 | |||
441 | /* having these next two as dev_err() makes life very | ||
442 | * noisy when doing an i2cdetect | ||
443 | */ | ||
444 | |||
445 | if (timeout == 0) | ||
446 | dev_dbg(i2c->dev, "timeout\n"); | ||
447 | else if (ret != num) | ||
448 | dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret); | ||
449 | |||
450 | /* ensure the stop has been through the bus */ | ||
451 | |||
452 | dev_dbg(i2c->dev, "waiting for bus idle\n"); | ||
453 | |||
454 | /* first, try busy waiting briefly */ | ||
455 | do { | ||
456 | iicstat = readl(i2c->regs + CSR); | ||
457 | } while ((iicstat & I2CBUSY) && --spins); | ||
458 | |||
459 | /* if that timed out sleep */ | ||
460 | if (!spins) { | ||
461 | msleep(1); | ||
462 | iicstat = readl(i2c->regs + CSR); | ||
463 | } | ||
464 | |||
465 | if (iicstat & I2CBUSY) | ||
466 | dev_warn(i2c->dev, "timeout waiting for bus idle\n"); | ||
467 | |||
468 | out: | ||
469 | return ret; | ||
470 | } | ||
471 | |||
472 | /* nuc900_i2c_xfer | ||
473 | * | ||
474 | * first port of call from the i2c bus code when an message needs | ||
475 | * transferring across the i2c bus. | ||
476 | */ | ||
477 | |||
478 | static int nuc900_i2c_xfer(struct i2c_adapter *adap, | ||
479 | struct i2c_msg *msgs, int num) | ||
480 | { | ||
481 | struct nuc900_i2c *i2c = (struct nuc900_i2c *)adap->algo_data; | ||
482 | int retry; | ||
483 | int ret; | ||
484 | |||
485 | nuc900_i2c_enable_irq(i2c); | ||
486 | |||
487 | for (retry = 0; retry < adap->retries; retry++) { | ||
488 | |||
489 | ret = nuc900_i2c_doxfer(i2c, msgs, num); | ||
490 | |||
491 | if (ret != -EAGAIN) | ||
492 | return ret; | ||
493 | |||
494 | dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry); | ||
495 | |||
496 | udelay(100); | ||
497 | } | ||
498 | |||
499 | return -EREMOTEIO; | ||
500 | } | ||
501 | |||
502 | /* declare our i2c functionality */ | ||
503 | static u32 nuc900_i2c_func(struct i2c_adapter *adap) | ||
504 | { | ||
505 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING; | ||
506 | } | ||
507 | |||
508 | /* i2c bus registration info */ | ||
509 | |||
510 | static const struct i2c_algorithm nuc900_i2c_algorithm = { | ||
511 | .master_xfer = nuc900_i2c_xfer, | ||
512 | .functionality = nuc900_i2c_func, | ||
513 | }; | ||
514 | |||
515 | /* nuc900_i2c_probe | ||
516 | * | ||
517 | * called by the bus driver when a suitable device is found | ||
518 | */ | ||
519 | |||
520 | static int __devinit nuc900_i2c_probe(struct platform_device *pdev) | ||
521 | { | ||
522 | struct nuc900_i2c *i2c; | ||
523 | struct nuc900_platform_i2c *pdata; | ||
524 | struct resource *res; | ||
525 | int ret; | ||
526 | |||
527 | pdata = pdev->dev.platform_data; | ||
528 | if (!pdata) { | ||
529 | dev_err(&pdev->dev, "no platform data\n"); | ||
530 | return -EINVAL; | ||
531 | } | ||
532 | |||
533 | i2c = kzalloc(sizeof(struct nuc900_i2c), GFP_KERNEL); | ||
534 | if (!i2c) { | ||
535 | dev_err(&pdev->dev, "no memory for state\n"); | ||
536 | return -ENOMEM; | ||
537 | } | ||
538 | |||
539 | strlcpy(i2c->adap.name, "nuc900-i2c0", sizeof(i2c->adap.name)); | ||
540 | i2c->adap.owner = THIS_MODULE; | ||
541 | i2c->adap.algo = &nuc900_i2c_algorithm; | ||
542 | i2c->adap.retries = 2; | ||
543 | i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | ||
544 | |||
545 | spin_lock_init(&i2c->lock); | ||
546 | init_waitqueue_head(&i2c->wait); | ||
547 | |||
548 | /* find the clock and enable it */ | ||
549 | |||
550 | i2c->dev = &pdev->dev; | ||
551 | i2c->clk = clk_get(&pdev->dev, NULL); | ||
552 | if (IS_ERR(i2c->clk)) { | ||
553 | dev_err(&pdev->dev, "cannot get clock\n"); | ||
554 | ret = -ENOENT; | ||
555 | goto err_noclk; | ||
556 | } | ||
557 | |||
558 | dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); | ||
559 | |||
560 | clk_enable(i2c->clk); | ||
561 | |||
562 | /* map the registers */ | ||
563 | |||
564 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
565 | if (res == NULL) { | ||
566 | dev_err(&pdev->dev, "cannot find IO resource\n"); | ||
567 | ret = -ENOENT; | ||
568 | goto err_clk; | ||
569 | } | ||
570 | |||
571 | i2c->ioarea = request_mem_region(res->start, resource_size(res), | ||
572 | pdev->name); | ||
573 | |||
574 | if (i2c->ioarea == NULL) { | ||
575 | dev_err(&pdev->dev, "cannot request IO\n"); | ||
576 | ret = -ENXIO; | ||
577 | goto err_clk; | ||
578 | } | ||
579 | |||
580 | i2c->regs = ioremap(res->start, resource_size(res)); | ||
581 | |||
582 | if (i2c->regs == NULL) { | ||
583 | dev_err(&pdev->dev, "cannot map IO\n"); | ||
584 | ret = -ENXIO; | ||
585 | goto err_ioarea; | ||
586 | } | ||
587 | |||
588 | dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", | ||
589 | i2c->regs, i2c->ioarea, res); | ||
590 | |||
591 | /* setup info block for the i2c core */ | ||
592 | |||
593 | i2c->adap.algo_data = i2c; | ||
594 | i2c->adap.dev.parent = &pdev->dev; | ||
595 | |||
596 | mfp_set_groupg(&pdev->dev); | ||
597 | |||
598 | clk_get_rate(i2c->clk); | ||
599 | |||
600 | ret = (i2c->clk.apbfreq)/(pdata->bus_freq * 5) - 1; | ||
601 | writel(ret & 0xffff, i2c->regs + DIVIDER); | ||
602 | |||
603 | /* find the IRQ for this unit (note, this relies on the init call to | ||
604 | * ensure no current IRQs pending | ||
605 | */ | ||
606 | |||
607 | i2c->irq = ret = platform_get_irq(pdev, 0); | ||
608 | if (ret <= 0) { | ||
609 | dev_err(&pdev->dev, "cannot find IRQ\n"); | ||
610 | goto err_iomap; | ||
611 | } | ||
612 | |||
613 | ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_DISABLED | IRQF_SHARED, | ||
614 | dev_name(&pdev->dev), i2c); | ||
615 | |||
616 | if (ret != 0) { | ||
617 | dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); | ||
618 | goto err_iomap; | ||
619 | } | ||
620 | |||
621 | /* Note, previous versions of the driver used i2c_add_adapter() | ||
622 | * to add the bus at any number. We now pass the bus number via | ||
623 | * the platform data, so if unset it will now default to always | ||
624 | * being bus 0. | ||
625 | */ | ||
626 | |||
627 | i2c->adap.nr = pdata->bus_num; | ||
628 | |||
629 | ret = i2c_add_numbered_adapter(&i2c->adap); | ||
630 | if (ret < 0) { | ||
631 | dev_err(&pdev->dev, "failed to add bus to i2c core\n"); | ||
632 | goto err_irq; | ||
633 | } | ||
634 | |||
635 | platform_set_drvdata(pdev, i2c); | ||
636 | |||
637 | dev_info(&pdev->dev, "%s: NUC900 I2C adapter\n", | ||
638 | dev_name(&i2c->adap.dev)); | ||
639 | return 0; | ||
640 | |||
641 | err_irq: | ||
642 | free_irq(i2c->irq, i2c); | ||
643 | |||
644 | err_iomap: | ||
645 | iounmap(i2c->regs); | ||
646 | |||
647 | err_ioarea: | ||
648 | release_resource(i2c->ioarea); | ||
649 | kfree(i2c->ioarea); | ||
650 | |||
651 | err_clk: | ||
652 | clk_disable(i2c->clk); | ||
653 | clk_put(i2c->clk); | ||
654 | |||
655 | err_noclk: | ||
656 | kfree(i2c); | ||
657 | return ret; | ||
658 | } | ||
659 | |||
660 | /* nuc900_i2c_remove | ||
661 | * | ||
662 | * called when device is removed from the bus | ||
663 | */ | ||
664 | |||
665 | static int __devexit nuc900_i2c_remove(struct platform_device *pdev) | ||
666 | { | ||
667 | struct nuc900_i2c *i2c = platform_get_drvdata(pdev); | ||
668 | |||
669 | i2c_del_adapter(&i2c->adap); | ||
670 | free_irq(i2c->irq, i2c); | ||
671 | |||
672 | clk_disable(i2c->clk); | ||
673 | clk_put(i2c->clk); | ||
674 | |||
675 | iounmap(i2c->regs); | ||
676 | |||
677 | release_resource(i2c->ioarea); | ||
678 | kfree(i2c->ioarea); | ||
679 | kfree(i2c); | ||
680 | |||
681 | return 0; | ||
682 | } | ||
683 | |||
684 | static struct platform_driver nuc900_i2c_driver = { | ||
685 | .probe = nuc900_i2c_probe, | ||
686 | .remove = __devexit_p(nuc900_i2c_remove), | ||
687 | .driver = { | ||
688 | .owner = THIS_MODULE, | ||
689 | .name = "nuc900-i2c0", | ||
690 | }, | ||
691 | }; | ||
692 | |||
693 | static int __init i2c_adap_nuc900_init(void) | ||
694 | { | ||
695 | return platform_driver_register(&nuc900_i2c_driver); | ||
696 | } | ||
697 | |||
698 | static void __exit i2c_adap_nuc900_exit(void) | ||
699 | { | ||
700 | platform_driver_unregister(&nuc900_i2c_driver); | ||
701 | } | ||
702 | subsys_initcall(i2c_adap_nuc900_init); | ||
703 | module_exit(i2c_adap_nuc900_exit); | ||
704 | |||
705 | MODULE_DESCRIPTION("NUC900 I2C Bus driver"); | ||
706 | MODULE_AUTHOR("Wan ZongShun, <mcuos.com-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>"); | ||
707 | MODULE_LICENSE("GPL"); | ||
708 | MODULE_ALIAS("platform:nuc900-i2c0"); | ||
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c index 0dabe643ec51..0070371b29f3 100644 --- a/drivers/i2c/busses/i2c-ocores.c +++ b/drivers/i2c/busses/i2c-ocores.c | |||
@@ -18,7 +18,8 @@ | |||
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/wait.h> | 19 | #include <linux/wait.h> |
20 | #include <linux/i2c-ocores.h> | 20 | #include <linux/i2c-ocores.h> |
21 | #include <asm/io.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/io.h> | ||
22 | 23 | ||
23 | struct ocores_i2c { | 24 | struct ocores_i2c { |
24 | void __iomem *base; | 25 | void __iomem *base; |
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c new file mode 100644 index 000000000000..56dbe54e8811 --- /dev/null +++ b/drivers/i2c/busses/i2c-octeon.c | |||
@@ -0,0 +1,652 @@ | |||
1 | /* | ||
2 | * (C) Copyright 2009-2010 | ||
3 | * Nokia Siemens Networks, michael.lawnick.ext@nsn.com | ||
4 | * | ||
5 | * Portions Copyright (C) 2010 Cavium Networks, Inc. | ||
6 | * | ||
7 | * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors. | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/init.h> | ||
19 | |||
20 | #include <linux/io.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | |||
26 | #include <asm/octeon/octeon.h> | ||
27 | |||
28 | #define DRV_NAME "i2c-octeon" | ||
29 | |||
30 | /* The previous out-of-tree version was implicitly version 1.0. */ | ||
31 | #define DRV_VERSION "2.0" | ||
32 | |||
33 | /* register offsets */ | ||
34 | #define SW_TWSI 0x00 | ||
35 | #define TWSI_INT 0x10 | ||
36 | |||
37 | /* Controller command patterns */ | ||
38 | #define SW_TWSI_V 0x8000000000000000ull | ||
39 | #define SW_TWSI_EOP_TWSI_DATA 0x0C00000100000000ull | ||
40 | #define SW_TWSI_EOP_TWSI_CTL 0x0C00000200000000ull | ||
41 | #define SW_TWSI_EOP_TWSI_CLKCTL 0x0C00000300000000ull | ||
42 | #define SW_TWSI_EOP_TWSI_STAT 0x0C00000300000000ull | ||
43 | #define SW_TWSI_EOP_TWSI_RST 0x0C00000700000000ull | ||
44 | #define SW_TWSI_OP_TWSI_CLK 0x0800000000000000ull | ||
45 | #define SW_TWSI_R 0x0100000000000000ull | ||
46 | |||
47 | /* Controller command and status bits */ | ||
48 | #define TWSI_CTL_CE 0x80 | ||
49 | #define TWSI_CTL_ENAB 0x40 | ||
50 | #define TWSI_CTL_STA 0x20 | ||
51 | #define TWSI_CTL_STP 0x10 | ||
52 | #define TWSI_CTL_IFLG 0x08 | ||
53 | #define TWSI_CTL_AAK 0x04 | ||
54 | |||
55 | /* Some status values */ | ||
56 | #define STAT_START 0x08 | ||
57 | #define STAT_RSTART 0x10 | ||
58 | #define STAT_TXADDR_ACK 0x18 | ||
59 | #define STAT_TXDATA_ACK 0x28 | ||
60 | #define STAT_RXADDR_ACK 0x40 | ||
61 | #define STAT_RXDATA_ACK 0x50 | ||
62 | #define STAT_IDLE 0xF8 | ||
63 | |||
64 | struct octeon_i2c { | ||
65 | wait_queue_head_t queue; | ||
66 | struct i2c_adapter adap; | ||
67 | int irq; | ||
68 | int twsi_freq; | ||
69 | int sys_freq; | ||
70 | resource_size_t twsi_phys; | ||
71 | void __iomem *twsi_base; | ||
72 | resource_size_t regsize; | ||
73 | struct device *dev; | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * octeon_i2c_write_sw - write an I2C core register. | ||
78 | * @i2c: The struct octeon_i2c. | ||
79 | * @eop_reg: Register selector. | ||
80 | * @data: Value to be written. | ||
81 | * | ||
82 | * The I2C core registers are accessed indirectly via the SW_TWSI CSR. | ||
83 | */ | ||
84 | static void octeon_i2c_write_sw(struct octeon_i2c *i2c, | ||
85 | u64 eop_reg, | ||
86 | u8 data) | ||
87 | { | ||
88 | u64 tmp; | ||
89 | |||
90 | __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI); | ||
91 | do { | ||
92 | tmp = __raw_readq(i2c->twsi_base + SW_TWSI); | ||
93 | } while ((tmp & SW_TWSI_V) != 0); | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * octeon_i2c_read_sw - write an I2C core register. | ||
98 | * @i2c: The struct octeon_i2c. | ||
99 | * @eop_reg: Register selector. | ||
100 | * | ||
101 | * Returns the data. | ||
102 | * | ||
103 | * The I2C core registers are accessed indirectly via the SW_TWSI CSR. | ||
104 | */ | ||
105 | static u8 octeon_i2c_read_sw(struct octeon_i2c *i2c, u64 eop_reg) | ||
106 | { | ||
107 | u64 tmp; | ||
108 | |||
109 | __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI); | ||
110 | do { | ||
111 | tmp = __raw_readq(i2c->twsi_base + SW_TWSI); | ||
112 | } while ((tmp & SW_TWSI_V) != 0); | ||
113 | |||
114 | return tmp & 0xFF; | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * octeon_i2c_write_int - write the TWSI_INT register | ||
119 | * @i2c: The struct octeon_i2c. | ||
120 | * @data: Value to be written. | ||
121 | */ | ||
122 | static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data) | ||
123 | { | ||
124 | u64 tmp; | ||
125 | |||
126 | __raw_writeq(data, i2c->twsi_base + TWSI_INT); | ||
127 | tmp = __raw_readq(i2c->twsi_base + TWSI_INT); | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * octeon_i2c_int_enable - enable the TS interrupt. | ||
132 | * @i2c: The struct octeon_i2c. | ||
133 | * | ||
134 | * The interrupt will be asserted when there is non-STAT_IDLE state in | ||
135 | * the SW_TWSI_EOP_TWSI_STAT register. | ||
136 | */ | ||
137 | static void octeon_i2c_int_enable(struct octeon_i2c *i2c) | ||
138 | { | ||
139 | octeon_i2c_write_int(i2c, 0x40); | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * octeon_i2c_int_disable - disable the TS interrupt. | ||
144 | * @i2c: The struct octeon_i2c. | ||
145 | */ | ||
146 | static void octeon_i2c_int_disable(struct octeon_i2c *i2c) | ||
147 | { | ||
148 | octeon_i2c_write_int(i2c, 0); | ||
149 | } | ||
150 | |||
151 | /** | ||
152 | * octeon_i2c_unblock - unblock the bus. | ||
153 | * @i2c: The struct octeon_i2c. | ||
154 | * | ||
155 | * If there was a reset while a device was driving 0 to bus, | ||
156 | * bus is blocked. We toggle it free manually by some clock | ||
157 | * cycles and send a stop. | ||
158 | */ | ||
159 | static void octeon_i2c_unblock(struct octeon_i2c *i2c) | ||
160 | { | ||
161 | int i; | ||
162 | |||
163 | dev_dbg(i2c->dev, "%s\n", __func__); | ||
164 | for (i = 0; i < 9; i++) { | ||
165 | octeon_i2c_write_int(i2c, 0x0); | ||
166 | udelay(5); | ||
167 | octeon_i2c_write_int(i2c, 0x200); | ||
168 | udelay(5); | ||
169 | } | ||
170 | octeon_i2c_write_int(i2c, 0x300); | ||
171 | udelay(5); | ||
172 | octeon_i2c_write_int(i2c, 0x100); | ||
173 | udelay(5); | ||
174 | octeon_i2c_write_int(i2c, 0x0); | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * octeon_i2c_isr - the interrupt service routine. | ||
179 | * @int: The irq, unused. | ||
180 | * @dev_id: Our struct octeon_i2c. | ||
181 | */ | ||
182 | static irqreturn_t octeon_i2c_isr(int irq, void *dev_id) | ||
183 | { | ||
184 | struct octeon_i2c *i2c = dev_id; | ||
185 | |||
186 | octeon_i2c_int_disable(i2c); | ||
187 | wake_up_interruptible(&i2c->queue); | ||
188 | |||
189 | return IRQ_HANDLED; | ||
190 | } | ||
191 | |||
192 | |||
193 | static int octeon_i2c_test_iflg(struct octeon_i2c *i2c) | ||
194 | { | ||
195 | return (octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_CTL) & TWSI_CTL_IFLG) != 0; | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * octeon_i2c_wait - wait for the IFLG to be set. | ||
200 | * @i2c: The struct octeon_i2c. | ||
201 | * | ||
202 | * Returns 0 on success, otherwise a negative errno. | ||
203 | */ | ||
204 | static int octeon_i2c_wait(struct octeon_i2c *i2c) | ||
205 | { | ||
206 | int result; | ||
207 | |||
208 | octeon_i2c_int_enable(i2c); | ||
209 | |||
210 | result = wait_event_interruptible_timeout(i2c->queue, | ||
211 | octeon_i2c_test_iflg(i2c), | ||
212 | i2c->adap.timeout); | ||
213 | |||
214 | octeon_i2c_int_disable(i2c); | ||
215 | |||
216 | if (result < 0) { | ||
217 | dev_dbg(i2c->dev, "%s: wait interrupted\n", __func__); | ||
218 | return result; | ||
219 | } else if (result == 0) { | ||
220 | dev_dbg(i2c->dev, "%s: timeout\n", __func__); | ||
221 | return -ETIMEDOUT; | ||
222 | } | ||
223 | |||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * octeon_i2c_start - send START to the bus. | ||
229 | * @i2c: The struct octeon_i2c. | ||
230 | * | ||
231 | * Returns 0 on success, otherwise a negative errno. | ||
232 | */ | ||
233 | static int octeon_i2c_start(struct octeon_i2c *i2c) | ||
234 | { | ||
235 | u8 data; | ||
236 | int result; | ||
237 | |||
238 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, | ||
239 | TWSI_CTL_ENAB | TWSI_CTL_STA); | ||
240 | |||
241 | result = octeon_i2c_wait(i2c); | ||
242 | if (result) { | ||
243 | if (octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT) == STAT_IDLE) { | ||
244 | /* | ||
245 | * Controller refused to send start flag May | ||
246 | * be a client is holding SDA low - let's try | ||
247 | * to free it. | ||
248 | */ | ||
249 | octeon_i2c_unblock(i2c); | ||
250 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, | ||
251 | TWSI_CTL_ENAB | TWSI_CTL_STA); | ||
252 | |||
253 | result = octeon_i2c_wait(i2c); | ||
254 | } | ||
255 | if (result) | ||
256 | return result; | ||
257 | } | ||
258 | |||
259 | data = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT); | ||
260 | if ((data != STAT_START) && (data != STAT_RSTART)) { | ||
261 | dev_err(i2c->dev, "%s: bad status (0x%x)\n", __func__, data); | ||
262 | return -EIO; | ||
263 | } | ||
264 | |||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * octeon_i2c_stop - send STOP to the bus. | ||
270 | * @i2c: The struct octeon_i2c. | ||
271 | * | ||
272 | * Returns 0 on success, otherwise a negative errno. | ||
273 | */ | ||
274 | static int octeon_i2c_stop(struct octeon_i2c *i2c) | ||
275 | { | ||
276 | u8 data; | ||
277 | |||
278 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, | ||
279 | TWSI_CTL_ENAB | TWSI_CTL_STP); | ||
280 | |||
281 | data = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT); | ||
282 | |||
283 | if (data != STAT_IDLE) { | ||
284 | dev_err(i2c->dev, "%s: bad status(0x%x)\n", __func__, data); | ||
285 | return -EIO; | ||
286 | } | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | /** | ||
291 | * octeon_i2c_write - send data to the bus. | ||
292 | * @i2c: The struct octeon_i2c. | ||
293 | * @target: Target address. | ||
294 | * @data: Pointer to the data to be sent. | ||
295 | * @length: Length of the data. | ||
296 | * | ||
297 | * The address is sent over the bus, then the data. | ||
298 | * | ||
299 | * Returns 0 on success, otherwise a negative errno. | ||
300 | */ | ||
301 | static int octeon_i2c_write(struct octeon_i2c *i2c, int target, | ||
302 | const u8 *data, int length) | ||
303 | { | ||
304 | int i, result; | ||
305 | u8 tmp; | ||
306 | |||
307 | result = octeon_i2c_start(i2c); | ||
308 | if (result) | ||
309 | return result; | ||
310 | |||
311 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, target << 1); | ||
312 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB); | ||
313 | |||
314 | result = octeon_i2c_wait(i2c); | ||
315 | if (result) | ||
316 | return result; | ||
317 | |||
318 | for (i = 0; i < length; i++) { | ||
319 | tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT); | ||
320 | if ((tmp != STAT_TXADDR_ACK) && (tmp != STAT_TXDATA_ACK)) { | ||
321 | dev_err(i2c->dev, | ||
322 | "%s: bad status before write (0x%x)\n", | ||
323 | __func__, tmp); | ||
324 | return -EIO; | ||
325 | } | ||
326 | |||
327 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, data[i]); | ||
328 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB); | ||
329 | |||
330 | result = octeon_i2c_wait(i2c); | ||
331 | if (result) | ||
332 | return result; | ||
333 | } | ||
334 | |||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | /** | ||
339 | * octeon_i2c_read - receive data from the bus. | ||
340 | * @i2c: The struct octeon_i2c. | ||
341 | * @target: Target address. | ||
342 | * @data: Pointer to the location to store the datae . | ||
343 | * @length: Length of the data. | ||
344 | * | ||
345 | * The address is sent over the bus, then the data is read. | ||
346 | * | ||
347 | * Returns 0 on success, otherwise a negative errno. | ||
348 | */ | ||
349 | static int octeon_i2c_read(struct octeon_i2c *i2c, int target, | ||
350 | u8 *data, int length) | ||
351 | { | ||
352 | int i, result; | ||
353 | u8 tmp; | ||
354 | |||
355 | if (length < 1) | ||
356 | return -EINVAL; | ||
357 | |||
358 | result = octeon_i2c_start(i2c); | ||
359 | if (result) | ||
360 | return result; | ||
361 | |||
362 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, (target<<1) | 1); | ||
363 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB); | ||
364 | |||
365 | result = octeon_i2c_wait(i2c); | ||
366 | if (result) | ||
367 | return result; | ||
368 | |||
369 | for (i = 0; i < length; i++) { | ||
370 | tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT); | ||
371 | if ((tmp != STAT_RXDATA_ACK) && (tmp != STAT_RXADDR_ACK)) { | ||
372 | dev_err(i2c->dev, | ||
373 | "%s: bad status before read (0x%x)\n", | ||
374 | __func__, tmp); | ||
375 | return -EIO; | ||
376 | } | ||
377 | |||
378 | if (i+1 < length) | ||
379 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, | ||
380 | TWSI_CTL_ENAB | TWSI_CTL_AAK); | ||
381 | else | ||
382 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, | ||
383 | TWSI_CTL_ENAB); | ||
384 | |||
385 | result = octeon_i2c_wait(i2c); | ||
386 | if (result) | ||
387 | return result; | ||
388 | |||
389 | data[i] = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_DATA); | ||
390 | } | ||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * octeon_i2c_xfer - The driver's master_xfer function. | ||
396 | * @adap: Pointer to the i2c_adapter structure. | ||
397 | * @msgs: Pointer to the messages to be processed. | ||
398 | * @num: Length of the MSGS array. | ||
399 | * | ||
400 | * Returns the number of messages processed, or a negative errno on | ||
401 | * failure. | ||
402 | */ | ||
403 | static int octeon_i2c_xfer(struct i2c_adapter *adap, | ||
404 | struct i2c_msg *msgs, | ||
405 | int num) | ||
406 | { | ||
407 | struct i2c_msg *pmsg; | ||
408 | int i; | ||
409 | int ret = 0; | ||
410 | struct octeon_i2c *i2c = i2c_get_adapdata(adap); | ||
411 | |||
412 | for (i = 0; ret == 0 && i < num; i++) { | ||
413 | pmsg = &msgs[i]; | ||
414 | dev_dbg(i2c->dev, | ||
415 | "Doing %s %d byte(s) to/from 0x%02x - %d of %d messages\n", | ||
416 | pmsg->flags & I2C_M_RD ? "read" : "write", | ||
417 | pmsg->len, pmsg->addr, i + 1, num); | ||
418 | if (pmsg->flags & I2C_M_RD) | ||
419 | ret = octeon_i2c_read(i2c, pmsg->addr, pmsg->buf, | ||
420 | pmsg->len); | ||
421 | else | ||
422 | ret = octeon_i2c_write(i2c, pmsg->addr, pmsg->buf, | ||
423 | pmsg->len); | ||
424 | } | ||
425 | octeon_i2c_stop(i2c); | ||
426 | |||
427 | return (ret != 0) ? ret : num; | ||
428 | } | ||
429 | |||
430 | static u32 octeon_i2c_functionality(struct i2c_adapter *adap) | ||
431 | { | ||
432 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | ||
433 | } | ||
434 | |||
435 | static const struct i2c_algorithm octeon_i2c_algo = { | ||
436 | .master_xfer = octeon_i2c_xfer, | ||
437 | .functionality = octeon_i2c_functionality, | ||
438 | }; | ||
439 | |||
440 | static struct i2c_adapter octeon_i2c_ops = { | ||
441 | .owner = THIS_MODULE, | ||
442 | .name = "OCTEON adapter", | ||
443 | .algo = &octeon_i2c_algo, | ||
444 | .timeout = 2, | ||
445 | }; | ||
446 | |||
447 | /** | ||
448 | * octeon_i2c_setclock - Calculate and set clock divisors. | ||
449 | */ | ||
450 | static int __devinit octeon_i2c_setclock(struct octeon_i2c *i2c) | ||
451 | { | ||
452 | int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff; | ||
453 | int thp = 0x18, mdiv = 2, ndiv = 0, delta_hz = 1000000; | ||
454 | |||
455 | for (ndiv_idx = 0; ndiv_idx < 8 && delta_hz != 0; ndiv_idx++) { | ||
456 | /* | ||
457 | * An mdiv value of less than 2 seems to not work well | ||
458 | * with ds1337 RTCs, so we constrain it to larger | ||
459 | * values. | ||
460 | */ | ||
461 | for (mdiv_idx = 15; mdiv_idx >= 2 && delta_hz != 0; mdiv_idx--) { | ||
462 | /* | ||
463 | * For given ndiv and mdiv values check the | ||
464 | * two closest thp values. | ||
465 | */ | ||
466 | tclk = i2c->twsi_freq * (mdiv_idx + 1) * 10; | ||
467 | tclk *= (1 << ndiv_idx); | ||
468 | thp_base = (i2c->sys_freq / (tclk * 2)) - 1; | ||
469 | for (inc = 0; inc <= 1; inc++) { | ||
470 | thp_idx = thp_base + inc; | ||
471 | if (thp_idx < 5 || thp_idx > 0xff) | ||
472 | continue; | ||
473 | |||
474 | foscl = i2c->sys_freq / (2 * (thp_idx + 1)); | ||
475 | foscl = foscl / (1 << ndiv_idx); | ||
476 | foscl = foscl / (mdiv_idx + 1) / 10; | ||
477 | diff = abs(foscl - i2c->twsi_freq); | ||
478 | if (diff < delta_hz) { | ||
479 | delta_hz = diff; | ||
480 | thp = thp_idx; | ||
481 | mdiv = mdiv_idx; | ||
482 | ndiv = ndiv_idx; | ||
483 | } | ||
484 | } | ||
485 | } | ||
486 | } | ||
487 | octeon_i2c_write_sw(i2c, SW_TWSI_OP_TWSI_CLK, thp); | ||
488 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CLKCTL, (mdiv << 3) | ndiv); | ||
489 | |||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | static int __devinit octeon_i2c_initlowlevel(struct octeon_i2c *i2c) | ||
494 | { | ||
495 | u8 status; | ||
496 | int tries; | ||
497 | |||
498 | /* disable high level controller, enable bus access */ | ||
499 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB); | ||
500 | |||
501 | /* reset controller */ | ||
502 | octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_RST, 0); | ||
503 | |||
504 | for (tries = 10; tries; tries--) { | ||
505 | udelay(1); | ||
506 | status = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT); | ||
507 | if (status == STAT_IDLE) | ||
508 | return 0; | ||
509 | } | ||
510 | dev_err(i2c->dev, "%s: TWSI_RST failed! (0x%x)\n", __func__, status); | ||
511 | return -EIO; | ||
512 | } | ||
513 | |||
514 | static int __devinit octeon_i2c_probe(struct platform_device *pdev) | ||
515 | { | ||
516 | int irq, result = 0; | ||
517 | struct octeon_i2c *i2c; | ||
518 | struct octeon_i2c_data *i2c_data; | ||
519 | struct resource *res_mem; | ||
520 | |||
521 | /* All adaptors have an irq. */ | ||
522 | irq = platform_get_irq(pdev, 0); | ||
523 | if (irq < 0) | ||
524 | return irq; | ||
525 | |||
526 | i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); | ||
527 | if (!i2c) { | ||
528 | dev_err(&pdev->dev, "kzalloc failed\n"); | ||
529 | result = -ENOMEM; | ||
530 | goto out; | ||
531 | } | ||
532 | i2c->dev = &pdev->dev; | ||
533 | i2c_data = pdev->dev.platform_data; | ||
534 | |||
535 | res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
536 | |||
537 | if (res_mem == NULL) { | ||
538 | dev_err(i2c->dev, "found no memory resource\n"); | ||
539 | result = -ENXIO; | ||
540 | goto fail_region; | ||
541 | } | ||
542 | |||
543 | if (i2c_data == NULL) { | ||
544 | dev_err(i2c->dev, "no I2C frequency data\n"); | ||
545 | result = -ENXIO; | ||
546 | goto fail_region; | ||
547 | } | ||
548 | |||
549 | i2c->twsi_phys = res_mem->start; | ||
550 | i2c->regsize = resource_size(res_mem); | ||
551 | i2c->twsi_freq = i2c_data->i2c_freq; | ||
552 | i2c->sys_freq = i2c_data->sys_freq; | ||
553 | |||
554 | if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) { | ||
555 | dev_err(i2c->dev, "request_mem_region failed\n"); | ||
556 | goto fail_region; | ||
557 | } | ||
558 | i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize); | ||
559 | |||
560 | init_waitqueue_head(&i2c->queue); | ||
561 | |||
562 | i2c->irq = irq; | ||
563 | |||
564 | result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c); | ||
565 | if (result < 0) { | ||
566 | dev_err(i2c->dev, "failed to attach interrupt\n"); | ||
567 | goto fail_irq; | ||
568 | } | ||
569 | |||
570 | result = octeon_i2c_initlowlevel(i2c); | ||
571 | if (result) { | ||
572 | dev_err(i2c->dev, "init low level failed\n"); | ||
573 | goto fail_add; | ||
574 | } | ||
575 | |||
576 | result = octeon_i2c_setclock(i2c); | ||
577 | if (result) { | ||
578 | dev_err(i2c->dev, "clock init failed\n"); | ||
579 | goto fail_add; | ||
580 | } | ||
581 | |||
582 | i2c->adap = octeon_i2c_ops; | ||
583 | i2c->adap.dev.parent = &pdev->dev; | ||
584 | i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0; | ||
585 | i2c_set_adapdata(&i2c->adap, i2c); | ||
586 | platform_set_drvdata(pdev, i2c); | ||
587 | |||
588 | result = i2c_add_numbered_adapter(&i2c->adap); | ||
589 | if (result < 0) { | ||
590 | dev_err(i2c->dev, "failed to add adapter\n"); | ||
591 | goto fail_add; | ||
592 | } | ||
593 | |||
594 | dev_info(i2c->dev, "version %s\n", DRV_VERSION); | ||
595 | |||
596 | return result; | ||
597 | |||
598 | fail_add: | ||
599 | platform_set_drvdata(pdev, NULL); | ||
600 | free_irq(i2c->irq, i2c); | ||
601 | fail_irq: | ||
602 | iounmap(i2c->twsi_base); | ||
603 | release_mem_region(i2c->twsi_phys, i2c->regsize); | ||
604 | fail_region: | ||
605 | kfree(i2c); | ||
606 | out: | ||
607 | return result; | ||
608 | }; | ||
609 | |||
610 | static int __devexit octeon_i2c_remove(struct platform_device *pdev) | ||
611 | { | ||
612 | struct octeon_i2c *i2c = platform_get_drvdata(pdev); | ||
613 | |||
614 | i2c_del_adapter(&i2c->adap); | ||
615 | platform_set_drvdata(pdev, NULL); | ||
616 | free_irq(i2c->irq, i2c); | ||
617 | iounmap(i2c->twsi_base); | ||
618 | release_mem_region(i2c->twsi_phys, i2c->regsize); | ||
619 | kfree(i2c); | ||
620 | return 0; | ||
621 | }; | ||
622 | |||
623 | static struct platform_driver octeon_i2c_driver = { | ||
624 | .probe = octeon_i2c_probe, | ||
625 | .remove = __devexit_p(octeon_i2c_remove), | ||
626 | .driver = { | ||
627 | .owner = THIS_MODULE, | ||
628 | .name = DRV_NAME, | ||
629 | }, | ||
630 | }; | ||
631 | |||
632 | static int __init octeon_i2c_init(void) | ||
633 | { | ||
634 | int rv; | ||
635 | |||
636 | rv = platform_driver_register(&octeon_i2c_driver); | ||
637 | return rv; | ||
638 | } | ||
639 | |||
640 | static void __exit octeon_i2c_exit(void) | ||
641 | { | ||
642 | platform_driver_unregister(&octeon_i2c_driver); | ||
643 | } | ||
644 | |||
645 | MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>"); | ||
646 | MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors"); | ||
647 | MODULE_LICENSE("GPL"); | ||
648 | MODULE_VERSION(DRV_VERSION); | ||
649 | MODULE_ALIAS("platform:" DRV_NAME); | ||
650 | |||
651 | module_init(octeon_i2c_init); | ||
652 | module_exit(octeon_i2c_exit); | ||
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index ad8d2010c921..9d090833e245 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
@@ -37,6 +37,9 @@ | |||
37 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
38 | #include <linux/clk.h> | 38 | #include <linux/clk.h> |
39 | #include <linux/io.h> | 39 | #include <linux/io.h> |
40 | #include <linux/slab.h> | ||
41 | #include <linux/i2c-omap.h> | ||
42 | #include <linux/pm_runtime.h> | ||
40 | 43 | ||
41 | /* I2C controller revisions */ | 44 | /* I2C controller revisions */ |
42 | #define OMAP_I2C_REV_2 0x20 | 45 | #define OMAP_I2C_REV_2 0x20 |
@@ -44,29 +47,37 @@ | |||
44 | /* I2C controller revisions present on specific hardware */ | 47 | /* I2C controller revisions present on specific hardware */ |
45 | #define OMAP_I2C_REV_ON_2430 0x36 | 48 | #define OMAP_I2C_REV_ON_2430 0x36 |
46 | #define OMAP_I2C_REV_ON_3430 0x3C | 49 | #define OMAP_I2C_REV_ON_3430 0x3C |
50 | #define OMAP_I2C_REV_ON_4430 0x40 | ||
47 | 51 | ||
48 | /* timeout waiting for the controller to respond */ | 52 | /* timeout waiting for the controller to respond */ |
49 | #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) | 53 | #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) |
50 | 54 | ||
51 | #define OMAP_I2C_REV_REG 0x00 | ||
52 | #define OMAP_I2C_IE_REG 0x04 | ||
53 | #define OMAP_I2C_STAT_REG 0x08 | ||
54 | #define OMAP_I2C_IV_REG 0x0c | ||
55 | /* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */ | 55 | /* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */ |
56 | #define OMAP_I2C_WE_REG 0x0c | 56 | enum { |
57 | #define OMAP_I2C_SYSS_REG 0x10 | 57 | OMAP_I2C_REV_REG = 0, |
58 | #define OMAP_I2C_BUF_REG 0x14 | 58 | OMAP_I2C_IE_REG, |
59 | #define OMAP_I2C_CNT_REG 0x18 | 59 | OMAP_I2C_STAT_REG, |
60 | #define OMAP_I2C_DATA_REG 0x1c | 60 | OMAP_I2C_IV_REG, |
61 | #define OMAP_I2C_SYSC_REG 0x20 | 61 | OMAP_I2C_WE_REG, |
62 | #define OMAP_I2C_CON_REG 0x24 | 62 | OMAP_I2C_SYSS_REG, |
63 | #define OMAP_I2C_OA_REG 0x28 | 63 | OMAP_I2C_BUF_REG, |
64 | #define OMAP_I2C_SA_REG 0x2c | 64 | OMAP_I2C_CNT_REG, |
65 | #define OMAP_I2C_PSC_REG 0x30 | 65 | OMAP_I2C_DATA_REG, |
66 | #define OMAP_I2C_SCLL_REG 0x34 | 66 | OMAP_I2C_SYSC_REG, |
67 | #define OMAP_I2C_SCLH_REG 0x38 | 67 | OMAP_I2C_CON_REG, |
68 | #define OMAP_I2C_SYSTEST_REG 0x3c | 68 | OMAP_I2C_OA_REG, |
69 | #define OMAP_I2C_BUFSTAT_REG 0x40 | 69 | OMAP_I2C_SA_REG, |
70 | OMAP_I2C_PSC_REG, | ||
71 | OMAP_I2C_SCLL_REG, | ||
72 | OMAP_I2C_SCLH_REG, | ||
73 | OMAP_I2C_SYSTEST_REG, | ||
74 | OMAP_I2C_BUFSTAT_REG, | ||
75 | OMAP_I2C_REVNB_LO, | ||
76 | OMAP_I2C_REVNB_HI, | ||
77 | OMAP_I2C_IRQSTATUS_RAW, | ||
78 | OMAP_I2C_IRQENABLE_SET, | ||
79 | OMAP_I2C_IRQENABLE_CLR, | ||
80 | }; | ||
70 | 81 | ||
71 | /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ | 82 | /* I2C Interrupt Enable Register (OMAP_I2C_IE): */ |
72 | #define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */ | 83 | #define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */ |
@@ -156,18 +167,24 @@ | |||
156 | #define SYSC_IDLEMODE_SMART 0x2 | 167 | #define SYSC_IDLEMODE_SMART 0x2 |
157 | #define SYSC_CLOCKACTIVITY_FCLK 0x2 | 168 | #define SYSC_CLOCKACTIVITY_FCLK 0x2 |
158 | 169 | ||
170 | /* Errata definitions */ | ||
171 | #define I2C_OMAP_ERRATA_I207 (1 << 0) | ||
172 | #define I2C_OMAP3_1P153 (1 << 1) | ||
159 | 173 | ||
160 | struct omap_i2c_dev { | 174 | struct omap_i2c_dev { |
161 | struct device *dev; | 175 | struct device *dev; |
162 | void __iomem *base; /* virtual */ | 176 | void __iomem *base; /* virtual */ |
163 | int irq; | 177 | int irq; |
164 | struct clk *iclk; /* Interface clock */ | 178 | int reg_shift; /* bit shift for I2C register addresses */ |
165 | struct clk *fclk; /* Functional clock */ | ||
166 | struct completion cmd_complete; | 179 | struct completion cmd_complete; |
167 | struct resource *ioarea; | 180 | struct resource *ioarea; |
181 | u32 latency; /* maximum mpu wkup latency */ | ||
182 | void (*set_mpu_wkup_lat)(struct device *dev, | ||
183 | long latency); | ||
168 | u32 speed; /* Speed of bus in Khz */ | 184 | u32 speed; /* Speed of bus in Khz */ |
169 | u16 cmd_err; | 185 | u16 cmd_err; |
170 | u8 *buf; | 186 | u8 *buf; |
187 | u8 *regs; | ||
171 | size_t buf_len; | 188 | size_t buf_len; |
172 | struct i2c_adapter adapter; | 189 | struct i2c_adapter adapter; |
173 | u8 fifo_size; /* use as flag and value | 190 | u8 fifo_size; /* use as flag and value |
@@ -178,71 +195,124 @@ struct omap_i2c_dev { | |||
178 | unsigned b_hw:1; /* bad h/w fixes */ | 195 | unsigned b_hw:1; /* bad h/w fixes */ |
179 | unsigned idle:1; | 196 | unsigned idle:1; |
180 | u16 iestate; /* Saved interrupt register */ | 197 | u16 iestate; /* Saved interrupt register */ |
198 | u16 pscstate; | ||
199 | u16 scllstate; | ||
200 | u16 sclhstate; | ||
201 | u16 bufstate; | ||
202 | u16 syscstate; | ||
203 | u16 westate; | ||
204 | u16 errata; | ||
205 | }; | ||
206 | |||
207 | const static u8 reg_map[] = { | ||
208 | [OMAP_I2C_REV_REG] = 0x00, | ||
209 | [OMAP_I2C_IE_REG] = 0x01, | ||
210 | [OMAP_I2C_STAT_REG] = 0x02, | ||
211 | [OMAP_I2C_IV_REG] = 0x03, | ||
212 | [OMAP_I2C_WE_REG] = 0x03, | ||
213 | [OMAP_I2C_SYSS_REG] = 0x04, | ||
214 | [OMAP_I2C_BUF_REG] = 0x05, | ||
215 | [OMAP_I2C_CNT_REG] = 0x06, | ||
216 | [OMAP_I2C_DATA_REG] = 0x07, | ||
217 | [OMAP_I2C_SYSC_REG] = 0x08, | ||
218 | [OMAP_I2C_CON_REG] = 0x09, | ||
219 | [OMAP_I2C_OA_REG] = 0x0a, | ||
220 | [OMAP_I2C_SA_REG] = 0x0b, | ||
221 | [OMAP_I2C_PSC_REG] = 0x0c, | ||
222 | [OMAP_I2C_SCLL_REG] = 0x0d, | ||
223 | [OMAP_I2C_SCLH_REG] = 0x0e, | ||
224 | [OMAP_I2C_SYSTEST_REG] = 0x0f, | ||
225 | [OMAP_I2C_BUFSTAT_REG] = 0x10, | ||
226 | }; | ||
227 | |||
228 | const static u8 omap4_reg_map[] = { | ||
229 | [OMAP_I2C_REV_REG] = 0x04, | ||
230 | [OMAP_I2C_IE_REG] = 0x2c, | ||
231 | [OMAP_I2C_STAT_REG] = 0x28, | ||
232 | [OMAP_I2C_IV_REG] = 0x34, | ||
233 | [OMAP_I2C_WE_REG] = 0x34, | ||
234 | [OMAP_I2C_SYSS_REG] = 0x90, | ||
235 | [OMAP_I2C_BUF_REG] = 0x94, | ||
236 | [OMAP_I2C_CNT_REG] = 0x98, | ||
237 | [OMAP_I2C_DATA_REG] = 0x9c, | ||
238 | [OMAP_I2C_SYSC_REG] = 0x20, | ||
239 | [OMAP_I2C_CON_REG] = 0xa4, | ||
240 | [OMAP_I2C_OA_REG] = 0xa8, | ||
241 | [OMAP_I2C_SA_REG] = 0xac, | ||
242 | [OMAP_I2C_PSC_REG] = 0xb0, | ||
243 | [OMAP_I2C_SCLL_REG] = 0xb4, | ||
244 | [OMAP_I2C_SCLH_REG] = 0xb8, | ||
245 | [OMAP_I2C_SYSTEST_REG] = 0xbC, | ||
246 | [OMAP_I2C_BUFSTAT_REG] = 0xc0, | ||
247 | [OMAP_I2C_REVNB_LO] = 0x00, | ||
248 | [OMAP_I2C_REVNB_HI] = 0x04, | ||
249 | [OMAP_I2C_IRQSTATUS_RAW] = 0x24, | ||
250 | [OMAP_I2C_IRQENABLE_SET] = 0x2c, | ||
251 | [OMAP_I2C_IRQENABLE_CLR] = 0x30, | ||
181 | }; | 252 | }; |
182 | 253 | ||
183 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, | 254 | static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, |
184 | int reg, u16 val) | 255 | int reg, u16 val) |
185 | { | 256 | { |
186 | __raw_writew(val, i2c_dev->base + reg); | 257 | __raw_writew(val, i2c_dev->base + |
258 | (i2c_dev->regs[reg] << i2c_dev->reg_shift)); | ||
187 | } | 259 | } |
188 | 260 | ||
189 | static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) | 261 | static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg) |
190 | { | 262 | { |
191 | return __raw_readw(i2c_dev->base + reg); | 263 | return __raw_readw(i2c_dev->base + |
264 | (i2c_dev->regs[reg] << i2c_dev->reg_shift)); | ||
192 | } | 265 | } |
193 | 266 | ||
194 | static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev) | 267 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) |
195 | { | 268 | { |
196 | int ret; | 269 | struct platform_device *pdev; |
197 | 270 | struct omap_i2c_bus_platform_data *pdata; | |
198 | dev->iclk = clk_get(dev->dev, "ick"); | ||
199 | if (IS_ERR(dev->iclk)) { | ||
200 | ret = PTR_ERR(dev->iclk); | ||
201 | dev->iclk = NULL; | ||
202 | return ret; | ||
203 | } | ||
204 | |||
205 | dev->fclk = clk_get(dev->dev, "fck"); | ||
206 | if (IS_ERR(dev->fclk)) { | ||
207 | ret = PTR_ERR(dev->fclk); | ||
208 | if (dev->iclk != NULL) { | ||
209 | clk_put(dev->iclk); | ||
210 | dev->iclk = NULL; | ||
211 | } | ||
212 | dev->fclk = NULL; | ||
213 | return ret; | ||
214 | } | ||
215 | 271 | ||
216 | return 0; | 272 | WARN_ON(!dev->idle); |
217 | } | ||
218 | 273 | ||
219 | static void omap_i2c_put_clocks(struct omap_i2c_dev *dev) | 274 | pdev = to_platform_device(dev->dev); |
220 | { | 275 | pdata = pdev->dev.platform_data; |
221 | clk_put(dev->fclk); | ||
222 | dev->fclk = NULL; | ||
223 | clk_put(dev->iclk); | ||
224 | dev->iclk = NULL; | ||
225 | } | ||
226 | 276 | ||
227 | static void omap_i2c_unidle(struct omap_i2c_dev *dev) | 277 | pm_runtime_get_sync(&pdev->dev); |
228 | { | ||
229 | WARN_ON(!dev->idle); | ||
230 | 278 | ||
231 | clk_enable(dev->iclk); | 279 | if (cpu_is_omap34xx()) { |
232 | clk_enable(dev->fclk); | 280 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
281 | omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate); | ||
282 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate); | ||
283 | omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, dev->sclhstate); | ||
284 | omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, dev->bufstate); | ||
285 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, dev->syscstate); | ||
286 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate); | ||
287 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); | ||
288 | } | ||
233 | dev->idle = 0; | 289 | dev->idle = 0; |
290 | |||
291 | /* | ||
292 | * Don't write to this register if the IE state is 0 as it can | ||
293 | * cause deadlock. | ||
294 | */ | ||
234 | if (dev->iestate) | 295 | if (dev->iestate) |
235 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); | 296 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); |
236 | } | 297 | } |
237 | 298 | ||
238 | static void omap_i2c_idle(struct omap_i2c_dev *dev) | 299 | static void omap_i2c_idle(struct omap_i2c_dev *dev) |
239 | { | 300 | { |
301 | struct platform_device *pdev; | ||
302 | struct omap_i2c_bus_platform_data *pdata; | ||
240 | u16 iv; | 303 | u16 iv; |
241 | 304 | ||
242 | WARN_ON(dev->idle); | 305 | WARN_ON(dev->idle); |
243 | 306 | ||
307 | pdev = to_platform_device(dev->dev); | ||
308 | pdata = pdev->dev.platform_data; | ||
309 | |||
244 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); | 310 | dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG); |
245 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); | 311 | if (dev->rev >= OMAP_I2C_REV_ON_4430) |
312 | omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1); | ||
313 | else | ||
314 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0); | ||
315 | |||
246 | if (dev->rev < OMAP_I2C_REV_2) { | 316 | if (dev->rev < OMAP_I2C_REV_2) { |
247 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ | 317 | iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */ |
248 | } else { | 318 | } else { |
@@ -252,19 +322,25 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev) | |||
252 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); | 322 | omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); |
253 | } | 323 | } |
254 | dev->idle = 1; | 324 | dev->idle = 1; |
255 | clk_disable(dev->fclk); | 325 | |
256 | clk_disable(dev->iclk); | 326 | pm_runtime_put_sync(&pdev->dev); |
257 | } | 327 | } |
258 | 328 | ||
259 | static int omap_i2c_init(struct omap_i2c_dev *dev) | 329 | static int omap_i2c_init(struct omap_i2c_dev *dev) |
260 | { | 330 | { |
261 | u16 psc = 0, scll = 0, sclh = 0; | 331 | u16 psc = 0, scll = 0, sclh = 0, buf = 0; |
262 | u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; | 332 | u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; |
263 | unsigned long fclk_rate = 12000000; | 333 | unsigned long fclk_rate = 12000000; |
264 | unsigned long timeout; | 334 | unsigned long timeout; |
265 | unsigned long internal_clk = 0; | 335 | unsigned long internal_clk = 0; |
336 | struct clk *fclk; | ||
266 | 337 | ||
267 | if (dev->rev >= OMAP_I2C_REV_2) { | 338 | if (dev->rev >= OMAP_I2C_REV_2) { |
339 | /* Disable I2C controller before soft reset */ | ||
340 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, | ||
341 | omap_i2c_read_reg(dev, OMAP_I2C_CON_REG) & | ||
342 | ~(OMAP_I2C_CON_EN)); | ||
343 | |||
268 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK); | 344 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK); |
269 | /* For some reason we need to set the EN bit before the | 345 | /* For some reason we need to set the EN bit before the |
270 | * reset done bit gets set. */ | 346 | * reset done bit gets set. */ |
@@ -287,24 +363,24 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
287 | SYSC_AUTOIDLE_MASK); | 363 | SYSC_AUTOIDLE_MASK); |
288 | 364 | ||
289 | } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { | 365 | } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { |
290 | u32 v; | 366 | dev->syscstate = SYSC_AUTOIDLE_MASK; |
291 | 367 | dev->syscstate |= SYSC_ENAWAKEUP_MASK; | |
292 | v = SYSC_AUTOIDLE_MASK; | 368 | dev->syscstate |= (SYSC_IDLEMODE_SMART << |
293 | v |= SYSC_ENAWAKEUP_MASK; | ||
294 | v |= (SYSC_IDLEMODE_SMART << | ||
295 | __ffs(SYSC_SIDLEMODE_MASK)); | 369 | __ffs(SYSC_SIDLEMODE_MASK)); |
296 | v |= (SYSC_CLOCKACTIVITY_FCLK << | 370 | dev->syscstate |= (SYSC_CLOCKACTIVITY_FCLK << |
297 | __ffs(SYSC_CLOCKACTIVITY_MASK)); | 371 | __ffs(SYSC_CLOCKACTIVITY_MASK)); |
298 | 372 | ||
299 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, v); | 373 | omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, |
374 | dev->syscstate); | ||
300 | /* | 375 | /* |
301 | * Enabling all wakup sources to stop I2C freezing on | 376 | * Enabling all wakup sources to stop I2C freezing on |
302 | * WFI instruction. | 377 | * WFI instruction. |
303 | * REVISIT: Some wkup sources might not be needed. | 378 | * REVISIT: Some wkup sources might not be needed. |
304 | */ | 379 | */ |
305 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, | 380 | dev->westate = OMAP_I2C_WE_ALL; |
306 | OMAP_I2C_WE_ALL); | 381 | if (dev->rev < OMAP_I2C_REV_ON_4430) |
307 | 382 | omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, | |
383 | dev->westate); | ||
308 | } | 384 | } |
309 | } | 385 | } |
310 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 386 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
@@ -316,7 +392,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
316 | * always returns 12MHz for the functional clock, we can | 392 | * always returns 12MHz for the functional clock, we can |
317 | * do this bit unconditionally. | 393 | * do this bit unconditionally. |
318 | */ | 394 | */ |
319 | fclk_rate = clk_get_rate(dev->fclk); | 395 | fclk = clk_get(dev->dev, "fck"); |
396 | fclk_rate = clk_get_rate(fclk); | ||
397 | clk_put(fclk); | ||
320 | 398 | ||
321 | /* TRM for 5912 says the I2C clock must be prescaled to be | 399 | /* TRM for 5912 says the I2C clock must be prescaled to be |
322 | * between 7 - 12 MHz. The XOR input clock is typically | 400 | * between 7 - 12 MHz. The XOR input clock is typically |
@@ -331,7 +409,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
331 | psc = fclk_rate / 12000000; | 409 | psc = fclk_rate / 12000000; |
332 | } | 410 | } |
333 | 411 | ||
334 | if (cpu_is_omap2430() || cpu_is_omap34xx()) { | 412 | if (!(cpu_class_is_omap1() || cpu_is_omap2420())) { |
335 | 413 | ||
336 | /* | 414 | /* |
337 | * HSI2C controller internal clk rate should be 19.2 Mhz for | 415 | * HSI2C controller internal clk rate should be 19.2 Mhz for |
@@ -345,7 +423,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
345 | internal_clk = 9600; | 423 | internal_clk = 9600; |
346 | else | 424 | else |
347 | internal_clk = 4000; | 425 | internal_clk = 4000; |
348 | fclk_rate = clk_get_rate(dev->fclk) / 1000; | 426 | fclk = clk_get(dev->dev, "fck"); |
427 | fclk_rate = clk_get_rate(fclk) / 1000; | ||
428 | clk_put(fclk); | ||
349 | 429 | ||
350 | /* Compute prescaler divisor */ | 430 | /* Compute prescaler divisor */ |
351 | psc = fclk_rate / internal_clk; | 431 | psc = fclk_rate / internal_clk; |
@@ -394,23 +474,33 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) | |||
394 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); | 474 | omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); |
395 | omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); | 475 | omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); |
396 | 476 | ||
397 | if (dev->fifo_size) | 477 | if (dev->fifo_size) { |
398 | /* Note: setup required fifo size - 1 */ | 478 | /* Note: setup required fifo size - 1. RTRSH and XTRSH */ |
399 | omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, | 479 | buf = (dev->fifo_size - 1) << 8 | OMAP_I2C_BUF_RXFIF_CLR | |
400 | (dev->fifo_size - 1) << 8 | /* RTRSH */ | 480 | (dev->fifo_size - 1) | OMAP_I2C_BUF_TXFIF_CLR; |
401 | OMAP_I2C_BUF_RXFIF_CLR | | 481 | omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, buf); |
402 | (dev->fifo_size - 1) | /* XTRSH */ | 482 | } |
403 | OMAP_I2C_BUF_TXFIF_CLR); | ||
404 | 483 | ||
405 | /* Take the I2C module out of reset: */ | 484 | /* Take the I2C module out of reset: */ |
406 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); | 485 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); |
407 | 486 | ||
487 | dev->errata = 0; | ||
488 | |||
489 | if (cpu_is_omap2430() || cpu_is_omap34xx()) | ||
490 | dev->errata |= I2C_OMAP_ERRATA_I207; | ||
491 | |||
408 | /* Enable interrupts */ | 492 | /* Enable interrupts */ |
409 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, | 493 | dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | |
410 | (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | | ||
411 | OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | | 494 | OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | |
412 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? | 495 | OMAP_I2C_IE_AL) | ((dev->fifo_size) ? |
413 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0)); | 496 | (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0); |
497 | omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate); | ||
498 | if (cpu_is_omap34xx()) { | ||
499 | dev->pscstate = psc; | ||
500 | dev->scllstate = scll; | ||
501 | dev->sclhstate = sclh; | ||
502 | dev->bufstate = buf; | ||
503 | } | ||
414 | return 0; | 504 | return 0; |
415 | } | 505 | } |
416 | 506 | ||
@@ -508,8 +598,12 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap, | |||
508 | * REVISIT: We should abort the transfer on signals, but the bus goes | 598 | * REVISIT: We should abort the transfer on signals, but the bus goes |
509 | * into arbitration and we're currently unable to recover from it. | 599 | * into arbitration and we're currently unable to recover from it. |
510 | */ | 600 | */ |
601 | if (dev->set_mpu_wkup_lat != NULL) | ||
602 | dev->set_mpu_wkup_lat(dev->dev, dev->latency); | ||
511 | r = wait_for_completion_timeout(&dev->cmd_complete, | 603 | r = wait_for_completion_timeout(&dev->cmd_complete, |
512 | OMAP_I2C_TIMEOUT); | 604 | OMAP_I2C_TIMEOUT); |
605 | if (dev->set_mpu_wkup_lat != NULL) | ||
606 | dev->set_mpu_wkup_lat(dev->dev, -1); | ||
513 | dev->buf_len = 0; | 607 | dev->buf_len = 0; |
514 | if (r < 0) | 608 | if (r < 0) |
515 | return r; | 609 | return r; |
@@ -568,6 +662,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
568 | 662 | ||
569 | if (r == 0) | 663 | if (r == 0) |
570 | r = num; | 664 | r = num; |
665 | |||
666 | omap_i2c_wait_for_bb(dev); | ||
571 | out: | 667 | out: |
572 | omap_i2c_idle(dev); | 668 | omap_i2c_idle(dev); |
573 | return r; | 669 | return r; |
@@ -592,6 +688,34 @@ omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat) | |||
592 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); | 688 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); |
593 | } | 689 | } |
594 | 690 | ||
691 | static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat) | ||
692 | { | ||
693 | /* | ||
694 | * I2C Errata(Errata Nos. OMAP2: 1.67, OMAP3: 1.8) | ||
695 | * Not applicable for OMAP4. | ||
696 | * Under certain rare conditions, RDR could be set again | ||
697 | * when the bus is busy, then ignore the interrupt and | ||
698 | * clear the interrupt. | ||
699 | */ | ||
700 | if (stat & OMAP_I2C_STAT_RDR) { | ||
701 | /* Step 1: If RDR is set, clear it */ | ||
702 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); | ||
703 | |||
704 | /* Step 2: */ | ||
705 | if (!(omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) | ||
706 | & OMAP_I2C_STAT_BB)) { | ||
707 | |||
708 | /* Step 3: */ | ||
709 | if (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) | ||
710 | & OMAP_I2C_STAT_RDR) { | ||
711 | omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); | ||
712 | dev_dbg(dev->dev, "RDR when bus is busy.\n"); | ||
713 | } | ||
714 | |||
715 | } | ||
716 | } | ||
717 | } | ||
718 | |||
595 | /* rev1 devices are apparently only on some 15xx */ | 719 | /* rev1 devices are apparently only on some 15xx */ |
596 | #ifdef CONFIG_ARCH_OMAP15XX | 720 | #ifdef CONFIG_ARCH_OMAP15XX |
597 | 721 | ||
@@ -653,6 +777,35 @@ omap_i2c_rev1_isr(int this_irq, void *dev_id) | |||
653 | #define omap_i2c_rev1_isr NULL | 777 | #define omap_i2c_rev1_isr NULL |
654 | #endif | 778 | #endif |
655 | 779 | ||
780 | /* | ||
781 | * OMAP3430 Errata 1.153: When an XRDY/XDR is hit, wait for XUDF before writing | ||
782 | * data to DATA_REG. Otherwise some data bytes can be lost while transferring | ||
783 | * them from the memory to the I2C interface. | ||
784 | */ | ||
785 | static int errata_omap3_1p153(struct omap_i2c_dev *dev, u16 *stat, int *err) | ||
786 | { | ||
787 | unsigned long timeout = 10000; | ||
788 | |||
789 | while (--timeout && !(*stat & OMAP_I2C_STAT_XUDF)) { | ||
790 | if (*stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) { | ||
791 | omap_i2c_ack_stat(dev, *stat & (OMAP_I2C_STAT_XRDY | | ||
792 | OMAP_I2C_STAT_XDR)); | ||
793 | *err |= OMAP_I2C_STAT_XUDF; | ||
794 | return -ETIMEDOUT; | ||
795 | } | ||
796 | |||
797 | cpu_relax(); | ||
798 | *stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG); | ||
799 | } | ||
800 | |||
801 | if (!timeout) { | ||
802 | dev_err(dev->dev, "timeout waiting on XUDF bit\n"); | ||
803 | return 0; | ||
804 | } | ||
805 | |||
806 | return 0; | ||
807 | } | ||
808 | |||
656 | static irqreturn_t | 809 | static irqreturn_t |
657 | omap_i2c_isr(int this_irq, void *dev_id) | 810 | omap_i2c_isr(int this_irq, void *dev_id) |
658 | { | 811 | { |
@@ -672,9 +825,17 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
672 | break; | 825 | break; |
673 | } | 826 | } |
674 | 827 | ||
675 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); | ||
676 | |||
677 | err = 0; | 828 | err = 0; |
829 | complete: | ||
830 | /* | ||
831 | * Ack the stat in one go, but [R/X]DR and [R/X]RDY should be | ||
832 | * acked after the data operation is complete. | ||
833 | * Ref: TRM SWPU114Q Figure 18-31 | ||
834 | */ | ||
835 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat & | ||
836 | ~(OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR | | ||
837 | OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); | ||
838 | |||
678 | if (stat & OMAP_I2C_STAT_NACK) { | 839 | if (stat & OMAP_I2C_STAT_NACK) { |
679 | err |= OMAP_I2C_STAT_NACK; | 840 | err |= OMAP_I2C_STAT_NACK; |
680 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, | 841 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, |
@@ -685,16 +846,26 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
685 | err |= OMAP_I2C_STAT_AL; | 846 | err |= OMAP_I2C_STAT_AL; |
686 | } | 847 | } |
687 | if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK | | 848 | if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK | |
688 | OMAP_I2C_STAT_AL)) | 849 | OMAP_I2C_STAT_AL)) { |
850 | omap_i2c_ack_stat(dev, stat & | ||
851 | (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR | | ||
852 | OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); | ||
689 | omap_i2c_complete_cmd(dev, err); | 853 | omap_i2c_complete_cmd(dev, err); |
854 | return IRQ_HANDLED; | ||
855 | } | ||
690 | if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) { | 856 | if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) { |
691 | u8 num_bytes = 1; | 857 | u8 num_bytes = 1; |
858 | |||
859 | if (dev->errata & I2C_OMAP_ERRATA_I207) | ||
860 | i2c_omap_errata_i207(dev, stat); | ||
861 | |||
692 | if (dev->fifo_size) { | 862 | if (dev->fifo_size) { |
693 | if (stat & OMAP_I2C_STAT_RRDY) | 863 | if (stat & OMAP_I2C_STAT_RRDY) |
694 | num_bytes = dev->fifo_size; | 864 | num_bytes = dev->fifo_size; |
695 | else | 865 | else /* read RXSTAT on RDR interrupt */ |
696 | num_bytes = omap_i2c_read_reg(dev, | 866 | num_bytes = (omap_i2c_read_reg(dev, |
697 | OMAP_I2C_BUFSTAT_REG); | 867 | OMAP_I2C_BUFSTAT_REG) |
868 | >> 8) & 0x3F; | ||
698 | } | 869 | } |
699 | while (num_bytes) { | 870 | while (num_bytes) { |
700 | num_bytes--; | 871 | num_bytes--; |
@@ -702,9 +873,12 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
702 | if (dev->buf_len) { | 873 | if (dev->buf_len) { |
703 | *dev->buf++ = w; | 874 | *dev->buf++ = w; |
704 | dev->buf_len--; | 875 | dev->buf_len--; |
705 | /* Data reg from 2430 is 8 bit wide */ | 876 | /* |
706 | if (!cpu_is_omap2430() && | 877 | * Data reg in 2430, omap3 and |
707 | !cpu_is_omap34xx()) { | 878 | * omap4 is 8 bit wide |
879 | */ | ||
880 | if (cpu_class_is_omap1() || | ||
881 | cpu_is_omap2420()) { | ||
708 | if (dev->buf_len) { | 882 | if (dev->buf_len) { |
709 | *dev->buf++ = w >> 8; | 883 | *dev->buf++ = w >> 8; |
710 | dev->buf_len--; | 884 | dev->buf_len--; |
@@ -731,9 +905,10 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
731 | if (dev->fifo_size) { | 905 | if (dev->fifo_size) { |
732 | if (stat & OMAP_I2C_STAT_XRDY) | 906 | if (stat & OMAP_I2C_STAT_XRDY) |
733 | num_bytes = dev->fifo_size; | 907 | num_bytes = dev->fifo_size; |
734 | else | 908 | else /* read TXSTAT on XDR interrupt */ |
735 | num_bytes = omap_i2c_read_reg(dev, | 909 | num_bytes = omap_i2c_read_reg(dev, |
736 | OMAP_I2C_BUFSTAT_REG); | 910 | OMAP_I2C_BUFSTAT_REG) |
911 | & 0x3F; | ||
737 | } | 912 | } |
738 | while (num_bytes) { | 913 | while (num_bytes) { |
739 | num_bytes--; | 914 | num_bytes--; |
@@ -741,9 +916,12 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
741 | if (dev->buf_len) { | 916 | if (dev->buf_len) { |
742 | w = *dev->buf++; | 917 | w = *dev->buf++; |
743 | dev->buf_len--; | 918 | dev->buf_len--; |
744 | /* Data reg from 2430 is 8 bit wide */ | 919 | /* |
745 | if (!cpu_is_omap2430() && | 920 | * Data reg in 2430, omap3 and |
746 | !cpu_is_omap34xx()) { | 921 | * omap4 is 8 bit wide |
922 | */ | ||
923 | if (cpu_class_is_omap1() || | ||
924 | cpu_is_omap2420()) { | ||
747 | if (dev->buf_len) { | 925 | if (dev->buf_len) { |
748 | w |= *dev->buf++ << 8; | 926 | w |= *dev->buf++ << 8; |
749 | dev->buf_len--; | 927 | dev->buf_len--; |
@@ -760,6 +938,11 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
760 | "data to send\n"); | 938 | "data to send\n"); |
761 | break; | 939 | break; |
762 | } | 940 | } |
941 | |||
942 | if ((dev->errata & I2C_OMAP3_1P153) && | ||
943 | errata_omap3_1p153(dev, &stat, &err)) | ||
944 | goto complete; | ||
945 | |||
763 | omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); | 946 | omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); |
764 | } | 947 | } |
765 | omap_i2c_ack_stat(dev, | 948 | omap_i2c_ack_stat(dev, |
@@ -784,12 +967,13 @@ static const struct i2c_algorithm omap_i2c_algo = { | |||
784 | .functionality = omap_i2c_func, | 967 | .functionality = omap_i2c_func, |
785 | }; | 968 | }; |
786 | 969 | ||
787 | static int __init | 970 | static int __devinit |
788 | omap_i2c_probe(struct platform_device *pdev) | 971 | omap_i2c_probe(struct platform_device *pdev) |
789 | { | 972 | { |
790 | struct omap_i2c_dev *dev; | 973 | struct omap_i2c_dev *dev; |
791 | struct i2c_adapter *adap; | 974 | struct i2c_adapter *adap; |
792 | struct resource *mem, *irq, *ioarea; | 975 | struct resource *mem, *irq, *ioarea; |
976 | struct omap_i2c_bus_platform_data *pdata = pdev->dev.platform_data; | ||
793 | irq_handler_t isr; | 977 | irq_handler_t isr; |
794 | int r; | 978 | int r; |
795 | u32 speed = 0; | 979 | u32 speed = 0; |
@@ -806,7 +990,7 @@ omap_i2c_probe(struct platform_device *pdev) | |||
806 | return -ENODEV; | 990 | return -ENODEV; |
807 | } | 991 | } |
808 | 992 | ||
809 | ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1, | 993 | ioarea = request_mem_region(mem->start, resource_size(mem), |
810 | pdev->name); | 994 | pdev->name); |
811 | if (!ioarea) { | 995 | if (!ioarea) { |
812 | dev_err(&pdev->dev, "I2C region already claimed\n"); | 996 | dev_err(&pdev->dev, "I2C region already claimed\n"); |
@@ -819,10 +1003,13 @@ omap_i2c_probe(struct platform_device *pdev) | |||
819 | goto err_release_region; | 1003 | goto err_release_region; |
820 | } | 1004 | } |
821 | 1005 | ||
822 | if (pdev->dev.platform_data != NULL) | 1006 | if (pdata != NULL) { |
823 | speed = *(u32 *)pdev->dev.platform_data; | 1007 | speed = pdata->clkrate; |
824 | else | 1008 | dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat; |
825 | speed = 100; /* Defualt speed */ | 1009 | } else { |
1010 | speed = 100; /* Default speed */ | ||
1011 | dev->set_mpu_wkup_lat = NULL; | ||
1012 | } | ||
826 | 1013 | ||
827 | dev->speed = speed; | 1014 | dev->speed = speed; |
828 | dev->idle = 1; | 1015 | dev->idle = 1; |
@@ -836,14 +1023,27 @@ omap_i2c_probe(struct platform_device *pdev) | |||
836 | 1023 | ||
837 | platform_set_drvdata(pdev, dev); | 1024 | platform_set_drvdata(pdev, dev); |
838 | 1025 | ||
839 | if ((r = omap_i2c_get_clocks(dev)) != 0) | 1026 | if (cpu_is_omap7xx()) |
840 | goto err_iounmap; | 1027 | dev->reg_shift = 1; |
1028 | else if (cpu_is_omap44xx()) | ||
1029 | dev->reg_shift = 0; | ||
1030 | else | ||
1031 | dev->reg_shift = 2; | ||
1032 | |||
1033 | if (cpu_is_omap44xx()) | ||
1034 | dev->regs = (u8 *) omap4_reg_map; | ||
1035 | else | ||
1036 | dev->regs = (u8 *) reg_map; | ||
841 | 1037 | ||
1038 | pm_runtime_enable(&pdev->dev); | ||
842 | omap_i2c_unidle(dev); | 1039 | omap_i2c_unidle(dev); |
843 | 1040 | ||
844 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; | 1041 | dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; |
845 | 1042 | ||
846 | if (cpu_is_omap2430() || cpu_is_omap34xx()) { | 1043 | if (dev->rev <= OMAP_I2C_REV_ON_3430) |
1044 | dev->errata |= I2C_OMAP3_1P153; | ||
1045 | |||
1046 | if (!(cpu_class_is_omap1() || cpu_is_omap2420())) { | ||
847 | u16 s; | 1047 | u16 s; |
848 | 1048 | ||
849 | /* Set up the fifo size - Get total size */ | 1049 | /* Set up the fifo size - Get total size */ |
@@ -855,8 +1055,17 @@ omap_i2c_probe(struct platform_device *pdev) | |||
855 | * size. This is to ensure that we can handle the status on int | 1055 | * size. This is to ensure that we can handle the status on int |
856 | * call back latencies. | 1056 | * call back latencies. |
857 | */ | 1057 | */ |
858 | dev->fifo_size = (dev->fifo_size / 2); | 1058 | if (dev->rev >= OMAP_I2C_REV_ON_4430) { |
859 | dev->b_hw = 1; /* Enable hardware fixes */ | 1059 | dev->fifo_size = 0; |
1060 | dev->b_hw = 0; /* Disable hardware fixes */ | ||
1061 | } else { | ||
1062 | dev->fifo_size = (dev->fifo_size / 2); | ||
1063 | dev->b_hw = 1; /* Enable hardware fixes */ | ||
1064 | } | ||
1065 | /* calculate wakeup latency constraint for MPU */ | ||
1066 | if (dev->set_mpu_wkup_lat != NULL) | ||
1067 | dev->latency = (1000000 * dev->fifo_size) / | ||
1068 | (1000 * speed / 8); | ||
860 | } | 1069 | } |
861 | 1070 | ||
862 | /* reset ASAP, clearing any IRQs */ | 1071 | /* reset ASAP, clearing any IRQs */ |
@@ -879,7 +1088,7 @@ omap_i2c_probe(struct platform_device *pdev) | |||
879 | i2c_set_adapdata(adap, dev); | 1088 | i2c_set_adapdata(adap, dev); |
880 | adap->owner = THIS_MODULE; | 1089 | adap->owner = THIS_MODULE; |
881 | adap->class = I2C_CLASS_HWMON; | 1090 | adap->class = I2C_CLASS_HWMON; |
882 | strncpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); | 1091 | strlcpy(adap->name, "OMAP I2C adapter", sizeof(adap->name)); |
883 | adap->algo = &omap_i2c_algo; | 1092 | adap->algo = &omap_i2c_algo; |
884 | adap->dev.parent = &pdev->dev; | 1093 | adap->dev.parent = &pdev->dev; |
885 | 1094 | ||
@@ -898,14 +1107,12 @@ err_free_irq: | |||
898 | err_unuse_clocks: | 1107 | err_unuse_clocks: |
899 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1108 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
900 | omap_i2c_idle(dev); | 1109 | omap_i2c_idle(dev); |
901 | omap_i2c_put_clocks(dev); | ||
902 | err_iounmap: | ||
903 | iounmap(dev->base); | 1110 | iounmap(dev->base); |
904 | err_free_mem: | 1111 | err_free_mem: |
905 | platform_set_drvdata(pdev, NULL); | 1112 | platform_set_drvdata(pdev, NULL); |
906 | kfree(dev); | 1113 | kfree(dev); |
907 | err_release_region: | 1114 | err_release_region: |
908 | release_mem_region(mem->start, (mem->end - mem->start) + 1); | 1115 | release_mem_region(mem->start, resource_size(mem)); |
909 | 1116 | ||
910 | return r; | 1117 | return r; |
911 | } | 1118 | } |
@@ -921,11 +1128,10 @@ omap_i2c_remove(struct platform_device *pdev) | |||
921 | free_irq(dev->irq, dev); | 1128 | free_irq(dev->irq, dev); |
922 | i2c_del_adapter(&dev->adapter); | 1129 | i2c_del_adapter(&dev->adapter); |
923 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); | 1130 | omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); |
924 | omap_i2c_put_clocks(dev); | ||
925 | iounmap(dev->base); | 1131 | iounmap(dev->base); |
926 | kfree(dev); | 1132 | kfree(dev); |
927 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1133 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
928 | release_mem_region(mem->start, (mem->end - mem->start) + 1); | 1134 | release_mem_region(mem->start, resource_size(mem)); |
929 | return 0; | 1135 | return 0; |
930 | } | 1136 | } |
931 | 1137 | ||
@@ -933,7 +1139,7 @@ static struct platform_driver omap_i2c_driver = { | |||
933 | .probe = omap_i2c_probe, | 1139 | .probe = omap_i2c_probe, |
934 | .remove = omap_i2c_remove, | 1140 | .remove = omap_i2c_remove, |
935 | .driver = { | 1141 | .driver = { |
936 | .name = "i2c_omap", | 1142 | .name = "omap_i2c", |
937 | .owner = THIS_MODULE, | 1143 | .owner = THIS_MODULE, |
938 | }, | 1144 | }, |
939 | }; | 1145 | }; |
@@ -955,4 +1161,4 @@ module_exit(omap_i2c_exit_driver); | |||
955 | MODULE_AUTHOR("MontaVista Software, Inc. (and others)"); | 1161 | MODULE_AUTHOR("MontaVista Software, Inc. (and others)"); |
956 | MODULE_DESCRIPTION("TI OMAP I2C bus adapter"); | 1162 | MODULE_DESCRIPTION("TI OMAP I2C bus adapter"); |
957 | MODULE_LICENSE("GPL"); | 1163 | MODULE_LICENSE("GPL"); |
958 | MODULE_ALIAS("platform:i2c_omap"); | 1164 | MODULE_ALIAS("platform:omap_i2c"); |
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c index 322c5691e38e..fc5fbd1012c9 100644 --- a/drivers/i2c/busses/i2c-parport-light.c +++ b/drivers/i2c/busses/i2c-parport-light.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ------------------------------------------------------------------------ * | 1 | /* ------------------------------------------------------------------------ * |
2 | * i2c-parport-light.c I2C bus over parallel port * | 2 | * i2c-parport-light.c I2C bus over parallel port * |
3 | * ------------------------------------------------------------------------ * | 3 | * ------------------------------------------------------------------------ * |
4 | Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org> | 4 | Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org> |
5 | 5 | ||
6 | Based on older i2c-velleman.c driver | 6 | Based on older i2c-velleman.c driver |
7 | Copyright (C) 1995-2000 Simon G. Vogl | 7 | Copyright (C) 1995-2000 Simon G. Vogl |
@@ -27,11 +27,13 @@ | |||
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/delay.h> | ||
30 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
31 | #include <linux/ioport.h> | 32 | #include <linux/ioport.h> |
32 | #include <linux/i2c.h> | 33 | #include <linux/i2c.h> |
33 | #include <linux/i2c-algo-bit.h> | 34 | #include <linux/i2c-algo-bit.h> |
34 | #include <asm/io.h> | 35 | #include <linux/i2c-smbus.h> |
36 | #include <linux/io.h> | ||
35 | #include "i2c-parport.h" | 37 | #include "i2c-parport.h" |
36 | 38 | ||
37 | #define DEFAULT_BASE 0x378 | 39 | #define DEFAULT_BASE 0x378 |
@@ -43,6 +45,10 @@ static u16 base; | |||
43 | module_param(base, ushort, 0); | 45 | module_param(base, ushort, 0); |
44 | MODULE_PARM_DESC(base, "Base I/O address"); | 46 | MODULE_PARM_DESC(base, "Base I/O address"); |
45 | 47 | ||
48 | static int irq; | ||
49 | module_param(irq, int, 0); | ||
50 | MODULE_PARM_DESC(irq, "IRQ (optional)"); | ||
51 | |||
46 | /* ----- Low-level parallel port access ----------------------------------- */ | 52 | /* ----- Low-level parallel port access ----------------------------------- */ |
47 | 53 | ||
48 | static inline void port_write(unsigned char p, unsigned char d) | 54 | static inline void port_write(unsigned char p, unsigned char d) |
@@ -119,6 +125,16 @@ static struct i2c_adapter parport_adapter = { | |||
119 | .name = "Parallel port adapter (light)", | 125 | .name = "Parallel port adapter (light)", |
120 | }; | 126 | }; |
121 | 127 | ||
128 | /* SMBus alert support */ | ||
129 | static struct i2c_smbus_alert_setup alert_data = { | ||
130 | .alert_edge_triggered = 1, | ||
131 | }; | ||
132 | static struct i2c_client *ara; | ||
133 | static struct lineop parport_ctrl_irq = { | ||
134 | .val = (1 << 4), | ||
135 | .port = CTRL, | ||
136 | }; | ||
137 | |||
122 | static int __devinit i2c_parport_probe(struct platform_device *pdev) | 138 | static int __devinit i2c_parport_probe(struct platform_device *pdev) |
123 | { | 139 | { |
124 | int err; | 140 | int err; |
@@ -127,18 +143,39 @@ static int __devinit i2c_parport_probe(struct platform_device *pdev) | |||
127 | parport_setsda(NULL, 1); | 143 | parport_setsda(NULL, 1); |
128 | parport_setscl(NULL, 1); | 144 | parport_setscl(NULL, 1); |
129 | /* Other init if needed (power on...) */ | 145 | /* Other init if needed (power on...) */ |
130 | if (adapter_parm[type].init.val) | 146 | if (adapter_parm[type].init.val) { |
131 | line_set(1, &adapter_parm[type].init); | 147 | line_set(1, &adapter_parm[type].init); |
148 | /* Give powered devices some time to settle */ | ||
149 | msleep(100); | ||
150 | } | ||
132 | 151 | ||
133 | parport_adapter.dev.parent = &pdev->dev; | 152 | parport_adapter.dev.parent = &pdev->dev; |
134 | err = i2c_bit_add_bus(&parport_adapter); | 153 | err = i2c_bit_add_bus(&parport_adapter); |
135 | if (err) | 154 | if (err) { |
136 | dev_err(&pdev->dev, "Unable to register with I2C\n"); | 155 | dev_err(&pdev->dev, "Unable to register with I2C\n"); |
137 | return err; | 156 | return err; |
157 | } | ||
158 | |||
159 | /* Setup SMBus alert if supported */ | ||
160 | if (adapter_parm[type].smbus_alert && irq) { | ||
161 | alert_data.irq = irq; | ||
162 | ara = i2c_setup_smbus_alert(&parport_adapter, &alert_data); | ||
163 | if (ara) | ||
164 | line_set(1, &parport_ctrl_irq); | ||
165 | else | ||
166 | dev_warn(&pdev->dev, "Failed to register ARA client\n"); | ||
167 | } | ||
168 | |||
169 | return 0; | ||
138 | } | 170 | } |
139 | 171 | ||
140 | static int __devexit i2c_parport_remove(struct platform_device *pdev) | 172 | static int __devexit i2c_parport_remove(struct platform_device *pdev) |
141 | { | 173 | { |
174 | if (ara) { | ||
175 | line_set(0, &parport_ctrl_irq); | ||
176 | i2c_unregister_device(ara); | ||
177 | ara = NULL; | ||
178 | } | ||
142 | i2c_del_adapter(&parport_adapter); | 179 | i2c_del_adapter(&parport_adapter); |
143 | 180 | ||
144 | /* Un-init if needed (power off...) */ | 181 | /* Un-init if needed (power off...) */ |
@@ -205,6 +242,9 @@ static int __init i2c_parport_init(void) | |||
205 | if (!request_region(base, 3, DRVNAME)) | 242 | if (!request_region(base, 3, DRVNAME)) |
206 | return -EBUSY; | 243 | return -EBUSY; |
207 | 244 | ||
245 | if (irq != 0) | ||
246 | pr_info(DRVNAME ": using irq %d\n", irq); | ||
247 | |||
208 | if (!adapter_parm[type].getscl.val) | 248 | if (!adapter_parm[type].getscl.val) |
209 | parport_algo_data.getscl = NULL; | 249 | parport_algo_data.getscl = NULL; |
210 | 250 | ||
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c index 0d8998610c74..0eb1515541e7 100644 --- a/drivers/i2c/busses/i2c-parport.c +++ b/drivers/i2c/busses/i2c-parport.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ------------------------------------------------------------------------ * | 1 | /* ------------------------------------------------------------------------ * |
2 | * i2c-parport.c I2C bus over parallel port * | 2 | * i2c-parport.c I2C bus over parallel port * |
3 | * ------------------------------------------------------------------------ * | 3 | * ------------------------------------------------------------------------ * |
4 | Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org> | 4 | Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org> |
5 | 5 | ||
6 | Based on older i2c-philips-par.c driver | 6 | Based on older i2c-philips-par.c driver |
7 | Copyright (C) 1995-2000 Simon G. Vogl | 7 | Copyright (C) 1995-2000 Simon G. Vogl |
@@ -27,9 +27,12 @@ | |||
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/delay.h> | ||
30 | #include <linux/parport.h> | 31 | #include <linux/parport.h> |
31 | #include <linux/i2c.h> | 32 | #include <linux/i2c.h> |
32 | #include <linux/i2c-algo-bit.h> | 33 | #include <linux/i2c-algo-bit.h> |
34 | #include <linux/i2c-smbus.h> | ||
35 | #include <linux/slab.h> | ||
33 | #include "i2c-parport.h" | 36 | #include "i2c-parport.h" |
34 | 37 | ||
35 | /* ----- Device list ------------------------------------------------------ */ | 38 | /* ----- Device list ------------------------------------------------------ */ |
@@ -38,6 +41,8 @@ struct i2c_par { | |||
38 | struct pardevice *pdev; | 41 | struct pardevice *pdev; |
39 | struct i2c_adapter adapter; | 42 | struct i2c_adapter adapter; |
40 | struct i2c_algo_bit_data algo_data; | 43 | struct i2c_algo_bit_data algo_data; |
44 | struct i2c_smbus_alert_setup alert_data; | ||
45 | struct i2c_client *ara; | ||
41 | struct i2c_par *next; | 46 | struct i2c_par *next; |
42 | }; | 47 | }; |
43 | 48 | ||
@@ -132,7 +137,7 @@ static int parport_getsda(void *data) | |||
132 | copied. The attaching code will set getscl to NULL for adapters that | 137 | copied. The attaching code will set getscl to NULL for adapters that |
133 | cannot read SCL back, and will also make the data field point to | 138 | cannot read SCL back, and will also make the data field point to |
134 | the parallel port structure. */ | 139 | the parallel port structure. */ |
135 | static struct i2c_algo_bit_data parport_algo_data = { | 140 | static const struct i2c_algo_bit_data parport_algo_data = { |
136 | .setsda = parport_setsda, | 141 | .setsda = parport_setsda, |
137 | .setscl = parport_setscl, | 142 | .setscl = parport_setscl, |
138 | .getsda = parport_getsda, | 143 | .getsda = parport_getsda, |
@@ -143,6 +148,19 @@ static struct i2c_algo_bit_data parport_algo_data = { | |||
143 | 148 | ||
144 | /* ----- I2c and parallel port call-back functions and structures --------- */ | 149 | /* ----- I2c and parallel port call-back functions and structures --------- */ |
145 | 150 | ||
151 | void i2c_parport_irq(void *data) | ||
152 | { | ||
153 | struct i2c_par *adapter = data; | ||
154 | struct i2c_client *ara = adapter->ara; | ||
155 | |||
156 | if (ara) { | ||
157 | dev_dbg(&ara->dev, "SMBus alert received\n"); | ||
158 | i2c_handle_smbus_alert(ara); | ||
159 | } else | ||
160 | dev_dbg(&adapter->adapter.dev, | ||
161 | "SMBus alert received but no ARA client!\n"); | ||
162 | } | ||
163 | |||
146 | static void i2c_parport_attach (struct parport *port) | 164 | static void i2c_parport_attach (struct parport *port) |
147 | { | 165 | { |
148 | struct i2c_par *adapter; | 166 | struct i2c_par *adapter; |
@@ -154,8 +172,9 @@ static void i2c_parport_attach (struct parport *port) | |||
154 | } | 172 | } |
155 | 173 | ||
156 | pr_debug("i2c-parport: attaching to %s\n", port->name); | 174 | pr_debug("i2c-parport: attaching to %s\n", port->name); |
175 | parport_disable_irq(port); | ||
157 | adapter->pdev = parport_register_device(port, "i2c-parport", | 176 | adapter->pdev = parport_register_device(port, "i2c-parport", |
158 | NULL, NULL, NULL, PARPORT_FLAG_EXCL, NULL); | 177 | NULL, NULL, i2c_parport_irq, PARPORT_FLAG_EXCL, adapter); |
159 | if (!adapter->pdev) { | 178 | if (!adapter->pdev) { |
160 | printk(KERN_ERR "i2c-parport: Unable to register with parport\n"); | 179 | printk(KERN_ERR "i2c-parport: Unable to register with parport\n"); |
161 | goto ERROR0; | 180 | goto ERROR0; |
@@ -185,14 +204,29 @@ static void i2c_parport_attach (struct parport *port) | |||
185 | parport_setsda(port, 1); | 204 | parport_setsda(port, 1); |
186 | parport_setscl(port, 1); | 205 | parport_setscl(port, 1); |
187 | /* Other init if needed (power on...) */ | 206 | /* Other init if needed (power on...) */ |
188 | if (adapter_parm[type].init.val) | 207 | if (adapter_parm[type].init.val) { |
189 | line_set(port, 1, &adapter_parm[type].init); | 208 | line_set(port, 1, &adapter_parm[type].init); |
209 | /* Give powered devices some time to settle */ | ||
210 | msleep(100); | ||
211 | } | ||
190 | 212 | ||
191 | if (i2c_bit_add_bus(&adapter->adapter) < 0) { | 213 | if (i2c_bit_add_bus(&adapter->adapter) < 0) { |
192 | printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); | 214 | printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); |
193 | goto ERROR1; | 215 | goto ERROR1; |
194 | } | 216 | } |
195 | 217 | ||
218 | /* Setup SMBus alert if supported */ | ||
219 | if (adapter_parm[type].smbus_alert) { | ||
220 | adapter->alert_data.alert_edge_triggered = 1; | ||
221 | adapter->ara = i2c_setup_smbus_alert(&adapter->adapter, | ||
222 | &adapter->alert_data); | ||
223 | if (adapter->ara) | ||
224 | parport_enable_irq(port); | ||
225 | else | ||
226 | printk(KERN_WARNING "i2c-parport: Failed to register " | ||
227 | "ARA client\n"); | ||
228 | } | ||
229 | |||
196 | /* Add the new adapter to the list */ | 230 | /* Add the new adapter to the list */ |
197 | adapter->next = adapter_list; | 231 | adapter->next = adapter_list; |
198 | adapter_list = adapter; | 232 | adapter_list = adapter; |
@@ -213,6 +247,10 @@ static void i2c_parport_detach (struct parport *port) | |||
213 | for (prev = NULL, adapter = adapter_list; adapter; | 247 | for (prev = NULL, adapter = adapter_list; adapter; |
214 | prev = adapter, adapter = adapter->next) { | 248 | prev = adapter, adapter = adapter->next) { |
215 | if (adapter->pdev->port == port) { | 249 | if (adapter->pdev->port == port) { |
250 | if (adapter->ara) { | ||
251 | parport_disable_irq(port); | ||
252 | i2c_unregister_device(adapter->ara); | ||
253 | } | ||
216 | i2c_del_adapter(&adapter->adapter); | 254 | i2c_del_adapter(&adapter->adapter); |
217 | 255 | ||
218 | /* Un-init if needed (power off...) */ | 256 | /* Un-init if needed (power off...) */ |
diff --git a/drivers/i2c/busses/i2c-parport.h b/drivers/i2c/busses/i2c-parport.h index ed69d846cb95..a9f66816546c 100644 --- a/drivers/i2c/busses/i2c-parport.h +++ b/drivers/i2c/busses/i2c-parport.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ------------------------------------------------------------------------ * | 1 | /* ------------------------------------------------------------------------ * |
2 | * i2c-parport.h I2C bus over parallel port * | 2 | * i2c-parport.h I2C bus over parallel port * |
3 | * ------------------------------------------------------------------------ * | 3 | * ------------------------------------------------------------------------ * |
4 | Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> | 4 | Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -38,6 +38,7 @@ struct adapter_parm { | |||
38 | struct lineop getsda; | 38 | struct lineop getsda; |
39 | struct lineop getscl; | 39 | struct lineop getscl; |
40 | struct lineop init; | 40 | struct lineop init; |
41 | unsigned int smbus_alert:1; | ||
41 | }; | 42 | }; |
42 | 43 | ||
43 | static struct adapter_parm adapter_parm[] = { | 44 | static struct adapter_parm adapter_parm[] = { |
@@ -73,6 +74,7 @@ static struct adapter_parm adapter_parm[] = { | |||
73 | .setscl = { 0x01, DATA, 1 }, | 74 | .setscl = { 0x01, DATA, 1 }, |
74 | .getsda = { 0x10, STAT, 1 }, | 75 | .getsda = { 0x10, STAT, 1 }, |
75 | .init = { 0xf0, DATA, 0 }, | 76 | .init = { 0xf0, DATA, 0 }, |
77 | .smbus_alert = 1, | ||
76 | }, | 78 | }, |
77 | /* type 5: ADM1025, ADM1030 and ADM1031 evaluation boards */ | 79 | /* type 5: ADM1025, ADM1030 and ADM1031 evaluation boards */ |
78 | { | 80 | { |
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c index adf0fbb902f0..837b8c1aa02a 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi.c | |||
@@ -24,7 +24,8 @@ | |||
24 | #include <linux/sched.h> | 24 | #include <linux/sched.h> |
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <asm/io.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/io.h> | ||
28 | 29 | ||
29 | static struct pci_driver pasemi_smb_driver; | 30 | static struct pci_driver pasemi_smb_driver; |
30 | 31 | ||
@@ -87,7 +88,7 @@ static void pasemi_smb_clear(struct pasemi_smbus *smbus) | |||
87 | reg_write(smbus, REG_SMSTA, status); | 88 | reg_write(smbus, REG_SMSTA, status); |
88 | } | 89 | } |
89 | 90 | ||
90 | static unsigned int pasemi_smb_waitready(struct pasemi_smbus *smbus) | 91 | static int pasemi_smb_waitready(struct pasemi_smbus *smbus) |
91 | { | 92 | { |
92 | int timeout = 10; | 93 | int timeout = 10; |
93 | unsigned int status; | 94 | unsigned int status; |
@@ -400,7 +401,7 @@ static void __devexit pasemi_smb_remove(struct pci_dev *dev) | |||
400 | kfree(smbus); | 401 | kfree(smbus); |
401 | } | 402 | } |
402 | 403 | ||
403 | static struct pci_device_id pasemi_smb_ids[] = { | 404 | static const struct pci_device_id pasemi_smb_ids[] = { |
404 | { PCI_DEVICE(0x1959, 0xa003) }, | 405 | { PCI_DEVICE(0x1959, 0xa003) }, |
405 | { 0, } | 406 | { 0, } |
406 | }; | 407 | }; |
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index 0ed68e2ccd22..29933f87d8fa 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
@@ -30,8 +30,8 @@ | |||
30 | #include <linux/isa.h> | 30 | #include <linux/isa.h> |
31 | #include <linux/i2c.h> | 31 | #include <linux/i2c.h> |
32 | #include <linux/i2c-algo-pca.h> | 32 | #include <linux/i2c-algo-pca.h> |
33 | #include <linux/io.h> | ||
33 | 34 | ||
34 | #include <asm/io.h> | ||
35 | #include <asm/irq.h> | 35 | #include <asm/irq.h> |
36 | 36 | ||
37 | #define DRIVER "i2c-pca-isa" | 37 | #define DRIVER "i2c-pca-isa" |
@@ -71,21 +71,25 @@ static int pca_isa_readbyte(void *pd, int reg) | |||
71 | 71 | ||
72 | static int pca_isa_waitforcompletion(void *pd) | 72 | static int pca_isa_waitforcompletion(void *pd) |
73 | { | 73 | { |
74 | long ret = ~0; | ||
75 | unsigned long timeout; | 74 | unsigned long timeout; |
75 | long ret; | ||
76 | 76 | ||
77 | if (irq > -1) { | 77 | if (irq > -1) { |
78 | ret = wait_event_interruptible_timeout(pca_wait, | 78 | ret = wait_event_timeout(pca_wait, |
79 | pca_isa_readbyte(pd, I2C_PCA_CON) | 79 | pca_isa_readbyte(pd, I2C_PCA_CON) |
80 | & I2C_PCA_CON_SI, pca_isa_ops.timeout); | 80 | & I2C_PCA_CON_SI, pca_isa_ops.timeout); |
81 | } else { | 81 | } else { |
82 | /* Do polling */ | 82 | /* Do polling */ |
83 | timeout = jiffies + pca_isa_ops.timeout; | 83 | timeout = jiffies + pca_isa_ops.timeout; |
84 | while (((pca_isa_readbyte(pd, I2C_PCA_CON) | 84 | do { |
85 | & I2C_PCA_CON_SI) == 0) | 85 | ret = time_before(jiffies, timeout); |
86 | && (ret = time_before(jiffies, timeout))) | 86 | if (pca_isa_readbyte(pd, I2C_PCA_CON) |
87 | & I2C_PCA_CON_SI) | ||
88 | break; | ||
87 | udelay(100); | 89 | udelay(100); |
90 | } while (ret); | ||
88 | } | 91 | } |
92 | |||
89 | return ret > 0; | 93 | return ret > 0; |
90 | } | 94 | } |
91 | 95 | ||
@@ -96,7 +100,7 @@ static void pca_isa_resetchip(void *pd) | |||
96 | } | 100 | } |
97 | 101 | ||
98 | static irqreturn_t pca_handler(int this_irq, void *dev_id) { | 102 | static irqreturn_t pca_handler(int this_irq, void *dev_id) { |
99 | wake_up_interruptible(&pca_wait); | 103 | wake_up(&pca_wait); |
100 | return IRQ_HANDLED; | 104 | return IRQ_HANDLED; |
101 | } | 105 | } |
102 | 106 | ||
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c index c4df9d411cd5..ace67995d7de 100644 --- a/drivers/i2c/busses/i2c-pca-platform.c +++ b/drivers/i2c/busses/i2c-pca-platform.c | |||
@@ -23,9 +23,9 @@ | |||
23 | #include <linux/i2c-algo-pca.h> | 23 | #include <linux/i2c-algo-pca.h> |
24 | #include <linux/i2c-pca-platform.h> | 24 | #include <linux/i2c-pca-platform.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/io.h> | ||
26 | 27 | ||
27 | #include <asm/irq.h> | 28 | #include <asm/irq.h> |
28 | #include <asm/io.h> | ||
29 | 29 | ||
30 | struct i2c_pca_pf_data { | 30 | struct i2c_pca_pf_data { |
31 | void __iomem *reg_base; | 31 | void __iomem *reg_base; |
@@ -80,20 +80,23 @@ static void i2c_pca_pf_writebyte32(void *pd, int reg, int val) | |||
80 | static int i2c_pca_pf_waitforcompletion(void *pd) | 80 | static int i2c_pca_pf_waitforcompletion(void *pd) |
81 | { | 81 | { |
82 | struct i2c_pca_pf_data *i2c = pd; | 82 | struct i2c_pca_pf_data *i2c = pd; |
83 | long ret = ~0; | ||
84 | unsigned long timeout; | 83 | unsigned long timeout; |
84 | long ret; | ||
85 | 85 | ||
86 | if (i2c->irq) { | 86 | if (i2c->irq) { |
87 | ret = wait_event_interruptible_timeout(i2c->wait, | 87 | ret = wait_event_timeout(i2c->wait, |
88 | i2c->algo_data.read_byte(i2c, I2C_PCA_CON) | 88 | i2c->algo_data.read_byte(i2c, I2C_PCA_CON) |
89 | & I2C_PCA_CON_SI, i2c->adap.timeout); | 89 | & I2C_PCA_CON_SI, i2c->adap.timeout); |
90 | } else { | 90 | } else { |
91 | /* Do polling */ | 91 | /* Do polling */ |
92 | timeout = jiffies + i2c->adap.timeout; | 92 | timeout = jiffies + i2c->adap.timeout; |
93 | while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) | 93 | do { |
94 | & I2C_PCA_CON_SI) == 0) | 94 | ret = time_before(jiffies, timeout); |
95 | && (ret = time_before(jiffies, timeout))) | 95 | if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON) |
96 | & I2C_PCA_CON_SI) | ||
97 | break; | ||
96 | udelay(100); | 98 | udelay(100); |
99 | } while (ret); | ||
97 | } | 100 | } |
98 | 101 | ||
99 | return ret > 0; | 102 | return ret > 0; |
@@ -122,7 +125,7 @@ static irqreturn_t i2c_pca_pf_handler(int this_irq, void *dev_id) | |||
122 | if ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) | 125 | if ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) |
123 | return IRQ_NONE; | 126 | return IRQ_NONE; |
124 | 127 | ||
125 | wake_up_interruptible(&i2c->wait); | 128 | wake_up(&i2c->wait); |
126 | 129 | ||
127 | return IRQ_HANDLED; | 130 | return IRQ_HANDLED; |
128 | } | 131 | } |
@@ -221,7 +224,7 @@ static int __devinit i2c_pca_pf_probe(struct platform_device *pdev) | |||
221 | 224 | ||
222 | if (irq) { | 225 | if (irq) { |
223 | ret = request_irq(irq, i2c_pca_pf_handler, | 226 | ret = request_irq(irq, i2c_pca_pf_handler, |
224 | IRQF_TRIGGER_FALLING, i2c->adap.name, i2c); | 227 | IRQF_TRIGGER_FALLING, pdev->name, i2c); |
225 | if (ret) | 228 | if (ret) |
226 | goto e_reqirq; | 229 | goto e_reqirq; |
227 | } | 230 | } |
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c index 0249a7d762b9..6d14ac2e3c41 100644 --- a/drivers/i2c/busses/i2c-piix4.c +++ b/drivers/i2c/busses/i2c-piix4.c | |||
@@ -22,6 +22,7 @@ | |||
22 | Intel PIIX4, 440MX | 22 | Intel PIIX4, 440MX |
23 | Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 | 23 | Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 |
24 | ATI IXP200, IXP300, IXP400, SB600, SB700, SB800 | 24 | ATI IXP200, IXP300, IXP400, SB600, SB700, SB800 |
25 | AMD Hudson-2 | ||
25 | SMSC Victory66 | 26 | SMSC Victory66 |
26 | 27 | ||
27 | Note: we assume there can only be one device, with one SMBus interface. | 28 | Note: we assume there can only be one device, with one SMBus interface. |
@@ -38,7 +39,7 @@ | |||
38 | #include <linux/init.h> | 39 | #include <linux/init.h> |
39 | #include <linux/dmi.h> | 40 | #include <linux/dmi.h> |
40 | #include <linux/acpi.h> | 41 | #include <linux/acpi.h> |
41 | #include <asm/io.h> | 42 | #include <linux/io.h> |
42 | 43 | ||
43 | 44 | ||
44 | /* PIIX4 SMBus address offsets */ | 45 | /* PIIX4 SMBus address offsets */ |
@@ -168,7 +169,7 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, | |||
168 | } | 169 | } |
169 | 170 | ||
170 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) | 171 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) |
171 | return -EBUSY; | 172 | return -ENODEV; |
172 | 173 | ||
173 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { | 174 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { |
174 | dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", | 175 | dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", |
@@ -232,9 +233,9 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev, | |||
232 | unsigned short smba_idx = 0xcd6; | 233 | unsigned short smba_idx = 0xcd6; |
233 | u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c; | 234 | u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c; |
234 | 235 | ||
235 | /* SB800 SMBus does not support forcing address */ | 236 | /* SB800 and later SMBus does not support forcing address */ |
236 | if (force || force_addr) { | 237 | if (force || force_addr) { |
237 | dev_err(&PIIX4_dev->dev, "SB800 SMBus does not support " | 238 | dev_err(&PIIX4_dev->dev, "SMBus does not support " |
238 | "forcing address!\n"); | 239 | "forcing address!\n"); |
239 | return -EINVAL; | 240 | return -EINVAL; |
240 | } | 241 | } |
@@ -259,7 +260,7 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev, | |||
259 | 260 | ||
260 | piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0; | 261 | piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0; |
261 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) | 262 | if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) |
262 | return -EBUSY; | 263 | return -ENODEV; |
263 | 264 | ||
264 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { | 265 | if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { |
265 | dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", | 266 | dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", |
@@ -323,12 +324,12 @@ static int piix4_transaction(void) | |||
323 | else | 324 | else |
324 | msleep(1); | 325 | msleep(1); |
325 | 326 | ||
326 | while ((timeout++ < MAX_TIMEOUT) && | 327 | while ((++timeout < MAX_TIMEOUT) && |
327 | ((temp = inb_p(SMBHSTSTS)) & 0x01)) | 328 | ((temp = inb_p(SMBHSTSTS)) & 0x01)) |
328 | msleep(1); | 329 | msleep(1); |
329 | 330 | ||
330 | /* If the SMBus is still busy, we give up */ | 331 | /* If the SMBus is still busy, we give up */ |
331 | if (timeout >= MAX_TIMEOUT) { | 332 | if (timeout == MAX_TIMEOUT) { |
332 | dev_err(&piix4_adapter.dev, "SMBus Timeout!\n"); | 333 | dev_err(&piix4_adapter.dev, "SMBus Timeout!\n"); |
333 | result = -ETIMEDOUT; | 334 | result = -ETIMEDOUT; |
334 | } | 335 | } |
@@ -471,7 +472,7 @@ static struct i2c_adapter piix4_adapter = { | |||
471 | .algo = &smbus_algorithm, | 472 | .algo = &smbus_algorithm, |
472 | }; | 473 | }; |
473 | 474 | ||
474 | static struct pci_device_id piix4_ids[] = { | 475 | static const struct pci_device_id piix4_ids[] = { |
475 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, | 476 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, |
476 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, | 477 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, |
477 | { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, | 478 | { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, |
@@ -479,6 +480,7 @@ static struct pci_device_id piix4_ids[] = { | |||
479 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, | 480 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, |
480 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, | 481 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, |
481 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, | 482 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, |
483 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) }, | ||
482 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, | 484 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
483 | PCI_DEVICE_ID_SERVERWORKS_OSB4) }, | 485 | PCI_DEVICE_ID_SERVERWORKS_OSB4) }, |
484 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, | 486 | { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, |
@@ -499,9 +501,10 @@ static int __devinit piix4_probe(struct pci_dev *dev, | |||
499 | { | 501 | { |
500 | int retval; | 502 | int retval; |
501 | 503 | ||
502 | if ((dev->vendor == PCI_VENDOR_ID_ATI) && | 504 | if ((dev->vendor == PCI_VENDOR_ID_ATI && |
503 | (dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) && | 505 | dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && |
504 | (dev->revision >= 0x40)) | 506 | dev->revision >= 0x40) || |
507 | dev->vendor == PCI_VENDOR_ID_AMD) | ||
505 | /* base address location etc changed in SB800 */ | 508 | /* base address location etc changed in SB800 */ |
506 | retval = piix4_setup_sb800(dev, id); | 509 | retval = piix4_setup_sb800(dev, id); |
507 | else | 510 | else |
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c index 7b57d5f267e1..dfa7ae9c1b8e 100644 --- a/drivers/i2c/busses/i2c-pmcmsp.c +++ b/drivers/i2c/busses/i2c-pmcmsp.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include <linux/completion.h> | 33 | #include <linux/completion.h> |
34 | #include <linux/mutex.h> | 34 | #include <linux/mutex.h> |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <asm/io.h> | 36 | #include <linux/io.h> |
37 | 37 | ||
38 | #define DRV_NAME "pmcmsptwi" | 38 | #define DRV_NAME "pmcmsptwi" |
39 | 39 | ||
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index ec15cff556b9..a97e3fec8148 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c | |||
@@ -19,14 +19,17 @@ | |||
19 | #include <linux/completion.h> | 19 | #include <linux/completion.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/i2c-pnx.h> | 21 | #include <linux/i2c-pnx.h> |
22 | #include <linux/io.h> | ||
23 | #include <linux/err.h> | ||
24 | #include <linux/clk.h> | ||
25 | #include <linux/slab.h> | ||
26 | |||
22 | #include <mach/hardware.h> | 27 | #include <mach/hardware.h> |
23 | #include <asm/irq.h> | 28 | #include <mach/i2c.h> |
24 | #include <asm/uaccess.h> | ||
25 | 29 | ||
26 | #define I2C_PNX_TIMEOUT 10 /* msec */ | 30 | #define I2C_PNX_TIMEOUT 10 /* msec */ |
27 | #define I2C_PNX_SPEED_KHZ 100 | 31 | #define I2C_PNX_SPEED_KHZ 100 |
28 | #define I2C_PNX_REGION_SIZE 0x100 | 32 | #define I2C_PNX_REGION_SIZE 0x100 |
29 | #define PNX_DEFAULT_FREQ 13 /* MHz */ | ||
30 | 33 | ||
31 | static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data) | 34 | static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data) |
32 | { | 35 | { |
@@ -48,19 +51,21 @@ static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data) | |||
48 | return (timeout <= 0); | 51 | return (timeout <= 0); |
49 | } | 52 | } |
50 | 53 | ||
51 | static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap) | 54 | static inline void i2c_pnx_arm_timer(struct i2c_pnx_algo_data *alg_data) |
52 | { | 55 | { |
53 | struct i2c_pnx_algo_data *data = adap->algo_data; | 56 | struct timer_list *timer = &alg_data->mif.timer; |
54 | struct timer_list *timer = &data->mif.timer; | 57 | unsigned long expires = msecs_to_jiffies(I2C_PNX_TIMEOUT); |
55 | int expires = I2C_PNX_TIMEOUT / (1000 / HZ); | 58 | |
59 | if (expires <= 1) | ||
60 | expires = 2; | ||
56 | 61 | ||
57 | del_timer_sync(timer); | 62 | del_timer_sync(timer); |
58 | 63 | ||
59 | dev_dbg(&adap->dev, "Timer armed at %lu plus %u jiffies.\n", | 64 | dev_dbg(&alg_data->adapter.dev, "Timer armed at %lu plus %lu jiffies.\n", |
60 | jiffies, expires); | 65 | jiffies, expires); |
61 | 66 | ||
62 | timer->expires = jiffies + expires; | 67 | timer->expires = jiffies + expires; |
63 | timer->data = (unsigned long)adap; | 68 | timer->data = (unsigned long)&alg_data; |
64 | 69 | ||
65 | add_timer(timer); | 70 | add_timer(timer); |
66 | } | 71 | } |
@@ -72,34 +77,34 @@ static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap) | |||
72 | * | 77 | * |
73 | * Generate a START signal in the desired mode. | 78 | * Generate a START signal in the desired mode. |
74 | */ | 79 | */ |
75 | static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap) | 80 | static int i2c_pnx_start(unsigned char slave_addr, |
81 | struct i2c_pnx_algo_data *alg_data) | ||
76 | { | 82 | { |
77 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | 83 | dev_dbg(&alg_data->adapter.dev, "%s(): addr 0x%x mode %d\n", __func__, |
78 | |||
79 | dev_dbg(&adap->dev, "%s(): addr 0x%x mode %d\n", __func__, | ||
80 | slave_addr, alg_data->mif.mode); | 84 | slave_addr, alg_data->mif.mode); |
81 | 85 | ||
82 | /* Check for 7 bit slave addresses only */ | 86 | /* Check for 7 bit slave addresses only */ |
83 | if (slave_addr & ~0x7f) { | 87 | if (slave_addr & ~0x7f) { |
84 | dev_err(&adap->dev, "%s: Invalid slave address %x. " | 88 | dev_err(&alg_data->adapter.dev, |
85 | "Only 7-bit addresses are supported\n", | 89 | "%s: Invalid slave address %x. Only 7-bit addresses are supported\n", |
86 | adap->name, slave_addr); | 90 | alg_data->adapter.name, slave_addr); |
87 | return -EINVAL; | 91 | return -EINVAL; |
88 | } | 92 | } |
89 | 93 | ||
90 | /* First, make sure bus is idle */ | 94 | /* First, make sure bus is idle */ |
91 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) { | 95 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) { |
92 | /* Somebody else is monopolizing the bus */ | 96 | /* Somebody else is monopolizing the bus */ |
93 | dev_err(&adap->dev, "%s: Bus busy. Slave addr = %02x, " | 97 | dev_err(&alg_data->adapter.dev, |
94 | "cntrl = %x, stat = %x\n", | 98 | "%s: Bus busy. Slave addr = %02x, cntrl = %x, stat = %x\n", |
95 | adap->name, slave_addr, | 99 | alg_data->adapter.name, slave_addr, |
96 | ioread32(I2C_REG_CTL(alg_data)), | 100 | ioread32(I2C_REG_CTL(alg_data)), |
97 | ioread32(I2C_REG_STS(alg_data))); | 101 | ioread32(I2C_REG_STS(alg_data))); |
98 | return -EBUSY; | 102 | return -EBUSY; |
99 | } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) { | 103 | } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) { |
100 | /* Sorry, we lost the bus */ | 104 | /* Sorry, we lost the bus */ |
101 | dev_err(&adap->dev, "%s: Arbitration failure. " | 105 | dev_err(&alg_data->adapter.dev, |
102 | "Slave addr = %02x\n", adap->name, slave_addr); | 106 | "%s: Arbitration failure. Slave addr = %02x\n", |
107 | alg_data->adapter.name, slave_addr); | ||
103 | return -EIO; | 108 | return -EIO; |
104 | } | 109 | } |
105 | 110 | ||
@@ -110,14 +115,14 @@ static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap) | |||
110 | iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi, | 115 | iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi, |
111 | I2C_REG_STS(alg_data)); | 116 | I2C_REG_STS(alg_data)); |
112 | 117 | ||
113 | dev_dbg(&adap->dev, "%s(): sending %#x\n", __func__, | 118 | dev_dbg(&alg_data->adapter.dev, "%s(): sending %#x\n", __func__, |
114 | (slave_addr << 1) | start_bit | alg_data->mif.mode); | 119 | (slave_addr << 1) | start_bit | alg_data->mif.mode); |
115 | 120 | ||
116 | /* Write the slave address, START bit and R/W bit */ | 121 | /* Write the slave address, START bit and R/W bit */ |
117 | iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode, | 122 | iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode, |
118 | I2C_REG_TX(alg_data)); | 123 | I2C_REG_TX(alg_data)); |
119 | 124 | ||
120 | dev_dbg(&adap->dev, "%s(): exit\n", __func__); | 125 | dev_dbg(&alg_data->adapter.dev, "%s(): exit\n", __func__); |
121 | 126 | ||
122 | return 0; | 127 | return 0; |
123 | } | 128 | } |
@@ -128,13 +133,12 @@ static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap) | |||
128 | * | 133 | * |
129 | * Generate a STOP signal to terminate the master transaction. | 134 | * Generate a STOP signal to terminate the master transaction. |
130 | */ | 135 | */ |
131 | static void i2c_pnx_stop(struct i2c_adapter *adap) | 136 | static void i2c_pnx_stop(struct i2c_pnx_algo_data *alg_data) |
132 | { | 137 | { |
133 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
134 | /* Only 1 msec max timeout due to interrupt context */ | 138 | /* Only 1 msec max timeout due to interrupt context */ |
135 | long timeout = 1000; | 139 | long timeout = 1000; |
136 | 140 | ||
137 | dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", | 141 | dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", |
138 | __func__, ioread32(I2C_REG_STS(alg_data))); | 142 | __func__, ioread32(I2C_REG_STS(alg_data))); |
139 | 143 | ||
140 | /* Write a STOP bit to TX FIFO */ | 144 | /* Write a STOP bit to TX FIFO */ |
@@ -148,7 +152,7 @@ static void i2c_pnx_stop(struct i2c_adapter *adap) | |||
148 | timeout--; | 152 | timeout--; |
149 | } | 153 | } |
150 | 154 | ||
151 | dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", | 155 | dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", |
152 | __func__, ioread32(I2C_REG_STS(alg_data))); | 156 | __func__, ioread32(I2C_REG_STS(alg_data))); |
153 | } | 157 | } |
154 | 158 | ||
@@ -158,36 +162,32 @@ static void i2c_pnx_stop(struct i2c_adapter *adap) | |||
158 | * | 162 | * |
159 | * Sends one byte of data to the slave | 163 | * Sends one byte of data to the slave |
160 | */ | 164 | */ |
161 | static int i2c_pnx_master_xmit(struct i2c_adapter *adap) | 165 | static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data) |
162 | { | 166 | { |
163 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
164 | u32 val; | 167 | u32 val; |
165 | 168 | ||
166 | dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", | 169 | dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", |
167 | __func__, ioread32(I2C_REG_STS(alg_data))); | 170 | __func__, ioread32(I2C_REG_STS(alg_data))); |
168 | 171 | ||
169 | if (alg_data->mif.len > 0) { | 172 | if (alg_data->mif.len > 0) { |
170 | /* We still have something to talk about... */ | 173 | /* We still have something to talk about... */ |
171 | val = *alg_data->mif.buf++; | 174 | val = *alg_data->mif.buf++; |
172 | 175 | ||
173 | if (alg_data->mif.len == 1) { | 176 | if (alg_data->mif.len == 1) |
174 | val |= stop_bit; | 177 | val |= stop_bit; |
175 | if (!alg_data->last) | ||
176 | val |= start_bit; | ||
177 | } | ||
178 | 178 | ||
179 | alg_data->mif.len--; | 179 | alg_data->mif.len--; |
180 | iowrite32(val, I2C_REG_TX(alg_data)); | 180 | iowrite32(val, I2C_REG_TX(alg_data)); |
181 | 181 | ||
182 | dev_dbg(&adap->dev, "%s(): xmit %#x [%d]\n", __func__, | 182 | dev_dbg(&alg_data->adapter.dev, "%s(): xmit %#x [%d]\n", |
183 | val, alg_data->mif.len + 1); | 183 | __func__, val, alg_data->mif.len + 1); |
184 | 184 | ||
185 | if (alg_data->mif.len == 0) { | 185 | if (alg_data->mif.len == 0) { |
186 | if (alg_data->last) { | 186 | if (alg_data->last) { |
187 | /* Wait until the STOP is seen. */ | 187 | /* Wait until the STOP is seen. */ |
188 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) | 188 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) |
189 | dev_err(&adap->dev, "The bus is still " | 189 | dev_err(&alg_data->adapter.dev, |
190 | "active after timeout\n"); | 190 | "The bus is still active after timeout\n"); |
191 | } | 191 | } |
192 | /* Disable master interrupts */ | 192 | /* Disable master interrupts */ |
193 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) & | 193 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) & |
@@ -196,14 +196,15 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap) | |||
196 | 196 | ||
197 | del_timer_sync(&alg_data->mif.timer); | 197 | del_timer_sync(&alg_data->mif.timer); |
198 | 198 | ||
199 | dev_dbg(&adap->dev, "%s(): Waking up xfer routine.\n", | 199 | dev_dbg(&alg_data->adapter.dev, |
200 | "%s(): Waking up xfer routine.\n", | ||
200 | __func__); | 201 | __func__); |
201 | 202 | ||
202 | complete(&alg_data->mif.complete); | 203 | complete(&alg_data->mif.complete); |
203 | } | 204 | } |
204 | } else if (alg_data->mif.len == 0) { | 205 | } else if (alg_data->mif.len == 0) { |
205 | /* zero-sized transfer */ | 206 | /* zero-sized transfer */ |
206 | i2c_pnx_stop(adap); | 207 | i2c_pnx_stop(alg_data); |
207 | 208 | ||
208 | /* Disable master interrupts. */ | 209 | /* Disable master interrupts. */ |
209 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) & | 210 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) & |
@@ -212,13 +213,14 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap) | |||
212 | 213 | ||
213 | /* Stop timer. */ | 214 | /* Stop timer. */ |
214 | del_timer_sync(&alg_data->mif.timer); | 215 | del_timer_sync(&alg_data->mif.timer); |
215 | dev_dbg(&adap->dev, "%s(): Waking up xfer routine after " | 216 | dev_dbg(&alg_data->adapter.dev, |
216 | "zero-xfer.\n", __func__); | 217 | "%s(): Waking up xfer routine after zero-xfer.\n", |
218 | __func__); | ||
217 | 219 | ||
218 | complete(&alg_data->mif.complete); | 220 | complete(&alg_data->mif.complete); |
219 | } | 221 | } |
220 | 222 | ||
221 | dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", | 223 | dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", |
222 | __func__, ioread32(I2C_REG_STS(alg_data))); | 224 | __func__, ioread32(I2C_REG_STS(alg_data))); |
223 | 225 | ||
224 | return 0; | 226 | return 0; |
@@ -230,27 +232,25 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap) | |||
230 | * | 232 | * |
231 | * Reads one byte data from the slave | 233 | * Reads one byte data from the slave |
232 | */ | 234 | */ |
233 | static int i2c_pnx_master_rcv(struct i2c_adapter *adap) | 235 | static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data) |
234 | { | 236 | { |
235 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
236 | unsigned int val = 0; | 237 | unsigned int val = 0; |
237 | u32 ctl = 0; | 238 | u32 ctl = 0; |
238 | 239 | ||
239 | dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", | 240 | dev_dbg(&alg_data->adapter.dev, "%s(): entering: stat = %04x.\n", |
240 | __func__, ioread32(I2C_REG_STS(alg_data))); | 241 | __func__, ioread32(I2C_REG_STS(alg_data))); |
241 | 242 | ||
242 | /* Check, whether there is already data, | 243 | /* Check, whether there is already data, |
243 | * or we didn't 'ask' for it yet. | 244 | * or we didn't 'ask' for it yet. |
244 | */ | 245 | */ |
245 | if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { | 246 | if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { |
246 | dev_dbg(&adap->dev, "%s(): Write dummy data to fill " | 247 | dev_dbg(&alg_data->adapter.dev, |
247 | "Rx-fifo...\n", __func__); | 248 | "%s(): Write dummy data to fill Rx-fifo...\n", |
249 | __func__); | ||
248 | 250 | ||
249 | if (alg_data->mif.len == 1) { | 251 | if (alg_data->mif.len == 1) { |
250 | /* Last byte, do not acknowledge next rcv. */ | 252 | /* Last byte, do not acknowledge next rcv. */ |
251 | val |= stop_bit; | 253 | val |= stop_bit; |
252 | if (!alg_data->last) | ||
253 | val |= start_bit; | ||
254 | 254 | ||
255 | /* | 255 | /* |
256 | * Enable interrupt RFDAIE (data in Rx fifo), | 256 | * Enable interrupt RFDAIE (data in Rx fifo), |
@@ -276,16 +276,16 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap) | |||
276 | if (alg_data->mif.len > 0) { | 276 | if (alg_data->mif.len > 0) { |
277 | val = ioread32(I2C_REG_RX(alg_data)); | 277 | val = ioread32(I2C_REG_RX(alg_data)); |
278 | *alg_data->mif.buf++ = (u8) (val & 0xff); | 278 | *alg_data->mif.buf++ = (u8) (val & 0xff); |
279 | dev_dbg(&adap->dev, "%s(): rcv 0x%x [%d]\n", __func__, val, | 279 | dev_dbg(&alg_data->adapter.dev, "%s(): rcv 0x%x [%d]\n", |
280 | alg_data->mif.len); | 280 | __func__, val, alg_data->mif.len); |
281 | 281 | ||
282 | alg_data->mif.len--; | 282 | alg_data->mif.len--; |
283 | if (alg_data->mif.len == 0) { | 283 | if (alg_data->mif.len == 0) { |
284 | if (alg_data->last) | 284 | if (alg_data->last) |
285 | /* Wait until the STOP is seen. */ | 285 | /* Wait until the STOP is seen. */ |
286 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) | 286 | if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) |
287 | dev_err(&adap->dev, "The bus is still " | 287 | dev_err(&alg_data->adapter.dev, |
288 | "active after timeout\n"); | 288 | "The bus is still active after timeout\n"); |
289 | 289 | ||
290 | /* Disable master interrupts */ | 290 | /* Disable master interrupts */ |
291 | ctl = ioread32(I2C_REG_CTL(alg_data)); | 291 | ctl = ioread32(I2C_REG_CTL(alg_data)); |
@@ -299,7 +299,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap) | |||
299 | } | 299 | } |
300 | } | 300 | } |
301 | 301 | ||
302 | dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", | 302 | dev_dbg(&alg_data->adapter.dev, "%s(): exiting: stat = %04x.\n", |
303 | __func__, ioread32(I2C_REG_STS(alg_data))); | 303 | __func__, ioread32(I2C_REG_STS(alg_data))); |
304 | 304 | ||
305 | return 0; | 305 | return 0; |
@@ -307,11 +307,11 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap) | |||
307 | 307 | ||
308 | static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) | 308 | static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) |
309 | { | 309 | { |
310 | struct i2c_pnx_algo_data *alg_data = dev_id; | ||
310 | u32 stat, ctl; | 311 | u32 stat, ctl; |
311 | struct i2c_adapter *adap = dev_id; | ||
312 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
313 | 312 | ||
314 | dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n", | 313 | dev_dbg(&alg_data->adapter.dev, |
314 | "%s(): mstat = %x mctrl = %x, mode = %d\n", | ||
315 | __func__, | 315 | __func__, |
316 | ioread32(I2C_REG_STS(alg_data)), | 316 | ioread32(I2C_REG_STS(alg_data)), |
317 | ioread32(I2C_REG_CTL(alg_data)), | 317 | ioread32(I2C_REG_CTL(alg_data)), |
@@ -334,10 +334,10 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) | |||
334 | complete(&alg_data->mif.complete); | 334 | complete(&alg_data->mif.complete); |
335 | } else if (stat & mstatus_nai) { | 335 | } else if (stat & mstatus_nai) { |
336 | /* Slave did not acknowledge, generate a STOP */ | 336 | /* Slave did not acknowledge, generate a STOP */ |
337 | dev_dbg(&adap->dev, "%s(): " | 337 | dev_dbg(&alg_data->adapter.dev, |
338 | "Slave did not acknowledge, generating a STOP.\n", | 338 | "%s(): Slave did not acknowledge, generating a STOP.\n", |
339 | __func__); | 339 | __func__); |
340 | i2c_pnx_stop(adap); | 340 | i2c_pnx_stop(alg_data); |
341 | 341 | ||
342 | /* Disable master interrupts. */ | 342 | /* Disable master interrupts. */ |
343 | ctl = ioread32(I2C_REG_CTL(alg_data)); | 343 | ctl = ioread32(I2C_REG_CTL(alg_data)); |
@@ -363,9 +363,9 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) | |||
363 | */ | 363 | */ |
364 | if ((stat & mstatus_drmi) || !(stat & mstatus_rfe)) { | 364 | if ((stat & mstatus_drmi) || !(stat & mstatus_rfe)) { |
365 | if (alg_data->mif.mode == I2C_SMBUS_WRITE) { | 365 | if (alg_data->mif.mode == I2C_SMBUS_WRITE) { |
366 | i2c_pnx_master_xmit(adap); | 366 | i2c_pnx_master_xmit(alg_data); |
367 | } else if (alg_data->mif.mode == I2C_SMBUS_READ) { | 367 | } else if (alg_data->mif.mode == I2C_SMBUS_READ) { |
368 | i2c_pnx_master_rcv(adap); | 368 | i2c_pnx_master_rcv(alg_data); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | } | 371 | } |
@@ -374,7 +374,8 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) | |||
374 | stat = ioread32(I2C_REG_STS(alg_data)); | 374 | stat = ioread32(I2C_REG_STS(alg_data)); |
375 | iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data)); | 375 | iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data)); |
376 | 376 | ||
377 | dev_dbg(&adap->dev, "%s(): exiting, stat = %x ctrl = %x.\n", | 377 | dev_dbg(&alg_data->adapter.dev, |
378 | "%s(): exiting, stat = %x ctrl = %x.\n", | ||
378 | __func__, ioread32(I2C_REG_STS(alg_data)), | 379 | __func__, ioread32(I2C_REG_STS(alg_data)), |
379 | ioread32(I2C_REG_CTL(alg_data))); | 380 | ioread32(I2C_REG_CTL(alg_data))); |
380 | 381 | ||
@@ -383,14 +384,13 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id) | |||
383 | 384 | ||
384 | static void i2c_pnx_timeout(unsigned long data) | 385 | static void i2c_pnx_timeout(unsigned long data) |
385 | { | 386 | { |
386 | struct i2c_adapter *adap = (struct i2c_adapter *)data; | 387 | struct i2c_pnx_algo_data *alg_data = (struct i2c_pnx_algo_data *)data; |
387 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
388 | u32 ctl; | 388 | u32 ctl; |
389 | 389 | ||
390 | dev_err(&adap->dev, "Master timed out. stat = %04x, cntrl = %04x. " | 390 | dev_err(&alg_data->adapter.dev, |
391 | "Resetting master...\n", | 391 | "Master timed out. stat = %04x, cntrl = %04x. Resetting master...\n", |
392 | ioread32(I2C_REG_STS(alg_data)), | 392 | ioread32(I2C_REG_STS(alg_data)), |
393 | ioread32(I2C_REG_CTL(alg_data))); | 393 | ioread32(I2C_REG_CTL(alg_data))); |
394 | 394 | ||
395 | /* Reset master and disable interrupts */ | 395 | /* Reset master and disable interrupts */ |
396 | ctl = ioread32(I2C_REG_CTL(alg_data)); | 396 | ctl = ioread32(I2C_REG_CTL(alg_data)); |
@@ -404,15 +404,14 @@ static void i2c_pnx_timeout(unsigned long data) | |||
404 | complete(&alg_data->mif.complete); | 404 | complete(&alg_data->mif.complete); |
405 | } | 405 | } |
406 | 406 | ||
407 | static inline void bus_reset_if_active(struct i2c_adapter *adap) | 407 | static inline void bus_reset_if_active(struct i2c_pnx_algo_data *alg_data) |
408 | { | 408 | { |
409 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | ||
410 | u32 stat; | 409 | u32 stat; |
411 | 410 | ||
412 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) { | 411 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) { |
413 | dev_err(&adap->dev, | 412 | dev_err(&alg_data->adapter.dev, |
414 | "%s: Bus is still active after xfer. Reset it...\n", | 413 | "%s: Bus is still active after xfer. Reset it...\n", |
415 | adap->name); | 414 | alg_data->adapter.name); |
416 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, | 415 | iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, |
417 | I2C_REG_CTL(alg_data)); | 416 | I2C_REG_CTL(alg_data)); |
418 | wait_reset(I2C_PNX_TIMEOUT, alg_data); | 417 | wait_reset(I2C_PNX_TIMEOUT, alg_data); |
@@ -446,10 +445,11 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
446 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | 445 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; |
447 | u32 stat = ioread32(I2C_REG_STS(alg_data)); | 446 | u32 stat = ioread32(I2C_REG_STS(alg_data)); |
448 | 447 | ||
449 | dev_dbg(&adap->dev, "%s(): entering: %d messages, stat = %04x.\n", | 448 | dev_dbg(&alg_data->adapter.dev, |
449 | "%s(): entering: %d messages, stat = %04x.\n", | ||
450 | __func__, num, ioread32(I2C_REG_STS(alg_data))); | 450 | __func__, num, ioread32(I2C_REG_STS(alg_data))); |
451 | 451 | ||
452 | bus_reset_if_active(adap); | 452 | bus_reset_if_active(alg_data); |
453 | 453 | ||
454 | /* Process transactions in a loop. */ | 454 | /* Process transactions in a loop. */ |
455 | for (i = 0; rc >= 0 && i < num; i++) { | 455 | for (i = 0; rc >= 0 && i < num; i++) { |
@@ -459,9 +459,9 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
459 | addr = pmsg->addr; | 459 | addr = pmsg->addr; |
460 | 460 | ||
461 | if (pmsg->flags & I2C_M_TEN) { | 461 | if (pmsg->flags & I2C_M_TEN) { |
462 | dev_err(&adap->dev, | 462 | dev_err(&alg_data->adapter.dev, |
463 | "%s: 10 bits addr not supported!\n", | 463 | "%s: 10 bits addr not supported!\n", |
464 | adap->name); | 464 | alg_data->adapter.name); |
465 | rc = -EINVAL; | 465 | rc = -EINVAL; |
466 | break; | 466 | break; |
467 | } | 467 | } |
@@ -473,11 +473,10 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
473 | alg_data->mif.ret = 0; | 473 | alg_data->mif.ret = 0; |
474 | alg_data->last = (i == num - 1); | 474 | alg_data->last = (i == num - 1); |
475 | 475 | ||
476 | dev_dbg(&adap->dev, "%s(): mode %d, %d bytes\n", __func__, | 476 | dev_dbg(&alg_data->adapter.dev, "%s(): mode %d, %d bytes\n", |
477 | alg_data->mif.mode, | 477 | __func__, alg_data->mif.mode, alg_data->mif.len); |
478 | alg_data->mif.len); | ||
479 | 478 | ||
480 | i2c_pnx_arm_timer(adap); | 479 | i2c_pnx_arm_timer(alg_data); |
481 | 480 | ||
482 | /* initialize the completion var */ | 481 | /* initialize the completion var */ |
483 | init_completion(&alg_data->mif.complete); | 482 | init_completion(&alg_data->mif.complete); |
@@ -488,7 +487,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
488 | I2C_REG_CTL(alg_data)); | 487 | I2C_REG_CTL(alg_data)); |
489 | 488 | ||
490 | /* Put start-code and slave-address on the bus. */ | 489 | /* Put start-code and slave-address on the bus. */ |
491 | rc = i2c_pnx_start(addr, adap); | 490 | rc = i2c_pnx_start(addr, alg_data); |
492 | if (rc < 0) | 491 | if (rc < 0) |
493 | break; | 492 | break; |
494 | 493 | ||
@@ -497,31 +496,32 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
497 | 496 | ||
498 | if (!(rc = alg_data->mif.ret)) | 497 | if (!(rc = alg_data->mif.ret)) |
499 | completed++; | 498 | completed++; |
500 | dev_dbg(&adap->dev, "%s(): Complete, return code = %d.\n", | 499 | dev_dbg(&alg_data->adapter.dev, |
500 | "%s(): Complete, return code = %d.\n", | ||
501 | __func__, rc); | 501 | __func__, rc); |
502 | 502 | ||
503 | /* Clear TDI and AFI bits in case they are set. */ | 503 | /* Clear TDI and AFI bits in case they are set. */ |
504 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) { | 504 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) { |
505 | dev_dbg(&adap->dev, | 505 | dev_dbg(&alg_data->adapter.dev, |
506 | "%s: TDI still set... clearing now.\n", | 506 | "%s: TDI still set... clearing now.\n", |
507 | adap->name); | 507 | alg_data->adapter.name); |
508 | iowrite32(stat, I2C_REG_STS(alg_data)); | 508 | iowrite32(stat, I2C_REG_STS(alg_data)); |
509 | } | 509 | } |
510 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) { | 510 | if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) { |
511 | dev_dbg(&adap->dev, | 511 | dev_dbg(&alg_data->adapter.dev, |
512 | "%s: AFI still set... clearing now.\n", | 512 | "%s: AFI still set... clearing now.\n", |
513 | adap->name); | 513 | alg_data->adapter.name); |
514 | iowrite32(stat, I2C_REG_STS(alg_data)); | 514 | iowrite32(stat, I2C_REG_STS(alg_data)); |
515 | } | 515 | } |
516 | } | 516 | } |
517 | 517 | ||
518 | bus_reset_if_active(adap); | 518 | bus_reset_if_active(alg_data); |
519 | 519 | ||
520 | /* Cleanup to be sure... */ | 520 | /* Cleanup to be sure... */ |
521 | alg_data->mif.buf = NULL; | 521 | alg_data->mif.buf = NULL; |
522 | alg_data->mif.len = 0; | 522 | alg_data->mif.len = 0; |
523 | 523 | ||
524 | dev_dbg(&adap->dev, "%s(): exiting, stat = %x\n", | 524 | dev_dbg(&alg_data->adapter.dev, "%s(): exiting, stat = %x\n", |
525 | __func__, ioread32(I2C_REG_STS(alg_data))); | 525 | __func__, ioread32(I2C_REG_STS(alg_data))); |
526 | 526 | ||
527 | if (completed != num) | 527 | if (completed != num) |
@@ -540,68 +540,92 @@ static struct i2c_algorithm pnx_algorithm = { | |||
540 | .functionality = i2c_pnx_func, | 540 | .functionality = i2c_pnx_func, |
541 | }; | 541 | }; |
542 | 542 | ||
543 | #ifdef CONFIG_PM | ||
543 | static int i2c_pnx_controller_suspend(struct platform_device *pdev, | 544 | static int i2c_pnx_controller_suspend(struct platform_device *pdev, |
544 | pm_message_t state) | 545 | pm_message_t state) |
545 | { | 546 | { |
546 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | 547 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
547 | return i2c_pnx->suspend(pdev, state); | 548 | |
549 | /* FIXME: shouldn't this be clk_disable? */ | ||
550 | clk_enable(alg_data->clk); | ||
551 | |||
552 | return 0; | ||
548 | } | 553 | } |
549 | 554 | ||
550 | static int i2c_pnx_controller_resume(struct platform_device *pdev) | 555 | static int i2c_pnx_controller_resume(struct platform_device *pdev) |
551 | { | 556 | { |
552 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | 557 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
553 | return i2c_pnx->resume(pdev); | 558 | |
559 | return clk_enable(alg_data->clk); | ||
554 | } | 560 | } |
561 | #else | ||
562 | #define i2c_pnx_controller_suspend NULL | ||
563 | #define i2c_pnx_controller_resume NULL | ||
564 | #endif | ||
555 | 565 | ||
556 | static int __devinit i2c_pnx_probe(struct platform_device *pdev) | 566 | static int __devinit i2c_pnx_probe(struct platform_device *pdev) |
557 | { | 567 | { |
558 | unsigned long tmp; | 568 | unsigned long tmp; |
559 | int ret = 0; | 569 | int ret = 0; |
560 | struct i2c_pnx_algo_data *alg_data; | 570 | struct i2c_pnx_algo_data *alg_data; |
561 | int freq_mhz; | 571 | unsigned long freq; |
562 | struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; | 572 | struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; |
563 | 573 | ||
564 | if (!i2c_pnx || !i2c_pnx->adapter) { | 574 | if (!i2c_pnx || !i2c_pnx->name) { |
565 | dev_err(&pdev->dev, "%s: no platform data supplied\n", | 575 | dev_err(&pdev->dev, "%s: no platform data supplied\n", |
566 | __func__); | 576 | __func__); |
567 | ret = -EINVAL; | 577 | ret = -EINVAL; |
568 | goto out; | 578 | goto out; |
569 | } | 579 | } |
570 | 580 | ||
571 | platform_set_drvdata(pdev, i2c_pnx); | 581 | alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL); |
572 | 582 | if (!alg_data) { | |
573 | if (i2c_pnx->calculate_input_freq) | 583 | ret = -ENOMEM; |
574 | freq_mhz = i2c_pnx->calculate_input_freq(pdev); | 584 | goto err_kzalloc; |
575 | else { | ||
576 | freq_mhz = PNX_DEFAULT_FREQ; | ||
577 | dev_info(&pdev->dev, "Setting bus frequency to default value: " | ||
578 | "%d MHz\n", freq_mhz); | ||
579 | } | 585 | } |
580 | 586 | ||
581 | i2c_pnx->adapter->algo = &pnx_algorithm; | 587 | platform_set_drvdata(pdev, alg_data); |
588 | |||
589 | strlcpy(alg_data->adapter.name, i2c_pnx->name, | ||
590 | sizeof(alg_data->adapter.name)); | ||
591 | alg_data->adapter.dev.parent = &pdev->dev; | ||
592 | alg_data->adapter.algo = &pnx_algorithm; | ||
593 | alg_data->adapter.algo_data = alg_data; | ||
594 | alg_data->adapter.nr = pdev->id; | ||
595 | alg_data->i2c_pnx = i2c_pnx; | ||
596 | |||
597 | alg_data->clk = clk_get(&pdev->dev, NULL); | ||
598 | if (IS_ERR(alg_data->clk)) { | ||
599 | ret = PTR_ERR(alg_data->clk); | ||
600 | goto out_drvdata; | ||
601 | } | ||
582 | 602 | ||
583 | alg_data = i2c_pnx->adapter->algo_data; | ||
584 | init_timer(&alg_data->mif.timer); | 603 | init_timer(&alg_data->mif.timer); |
585 | alg_data->mif.timer.function = i2c_pnx_timeout; | 604 | alg_data->mif.timer.function = i2c_pnx_timeout; |
586 | alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter; | 605 | alg_data->mif.timer.data = (unsigned long)alg_data; |
587 | 606 | ||
588 | /* Register I/O resource */ | 607 | /* Register I/O resource */ |
589 | if (!request_region(alg_data->base, I2C_PNX_REGION_SIZE, pdev->name)) { | 608 | if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE, |
609 | pdev->name)) { | ||
590 | dev_err(&pdev->dev, | 610 | dev_err(&pdev->dev, |
591 | "I/O region 0x%08x for I2C already in use.\n", | 611 | "I/O region 0x%08x for I2C already in use.\n", |
592 | alg_data->base); | 612 | i2c_pnx->base); |
593 | ret = -ENODEV; | 613 | ret = -ENODEV; |
594 | goto out_drvdata; | 614 | goto out_clkget; |
595 | } | 615 | } |
596 | 616 | ||
597 | if (!(alg_data->ioaddr = | 617 | alg_data->ioaddr = ioremap(i2c_pnx->base, I2C_PNX_REGION_SIZE); |
598 | (u32)ioremap(alg_data->base, I2C_PNX_REGION_SIZE))) { | 618 | if (!alg_data->ioaddr) { |
599 | dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n"); | 619 | dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n"); |
600 | ret = -ENOMEM; | 620 | ret = -ENOMEM; |
601 | goto out_release; | 621 | goto out_release; |
602 | } | 622 | } |
603 | 623 | ||
604 | i2c_pnx->set_clock_run(pdev); | 624 | ret = clk_enable(alg_data->clk); |
625 | if (ret) | ||
626 | goto out_unmap; | ||
627 | |||
628 | freq = clk_get_rate(alg_data->clk); | ||
605 | 629 | ||
606 | /* | 630 | /* |
607 | * Clock Divisor High This value is the number of system clocks | 631 | * Clock Divisor High This value is the number of system clocks |
@@ -614,44 +638,49 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev) | |||
614 | * the deglitching filter length. | 638 | * the deglitching filter length. |
615 | */ | 639 | */ |
616 | 640 | ||
617 | tmp = ((freq_mhz * 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2; | 641 | tmp = ((freq / 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2; |
642 | if (tmp > 0x3FF) | ||
643 | tmp = 0x3FF; | ||
618 | iowrite32(tmp, I2C_REG_CKH(alg_data)); | 644 | iowrite32(tmp, I2C_REG_CKH(alg_data)); |
619 | iowrite32(tmp, I2C_REG_CKL(alg_data)); | 645 | iowrite32(tmp, I2C_REG_CKL(alg_data)); |
620 | 646 | ||
621 | iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data)); | 647 | iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data)); |
622 | if (wait_reset(I2C_PNX_TIMEOUT, alg_data)) { | 648 | if (wait_reset(I2C_PNX_TIMEOUT, alg_data)) { |
623 | ret = -ENODEV; | 649 | ret = -ENODEV; |
624 | goto out_unmap; | 650 | goto out_clock; |
625 | } | 651 | } |
626 | init_completion(&alg_data->mif.complete); | 652 | init_completion(&alg_data->mif.complete); |
627 | 653 | ||
628 | ret = request_irq(alg_data->irq, i2c_pnx_interrupt, | 654 | ret = request_irq(i2c_pnx->irq, i2c_pnx_interrupt, |
629 | 0, pdev->name, i2c_pnx->adapter); | 655 | 0, pdev->name, alg_data); |
630 | if (ret) | 656 | if (ret) |
631 | goto out_clock; | 657 | goto out_clock; |
632 | 658 | ||
633 | /* Register this adapter with the I2C subsystem */ | 659 | /* Register this adapter with the I2C subsystem */ |
634 | i2c_pnx->adapter->dev.parent = &pdev->dev; | 660 | ret = i2c_add_numbered_adapter(&alg_data->adapter); |
635 | ret = i2c_add_adapter(i2c_pnx->adapter); | ||
636 | if (ret < 0) { | 661 | if (ret < 0) { |
637 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); | 662 | dev_err(&pdev->dev, "I2C: Failed to add bus\n"); |
638 | goto out_irq; | 663 | goto out_irq; |
639 | } | 664 | } |
640 | 665 | ||
641 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", | 666 | dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", |
642 | i2c_pnx->adapter->name, alg_data->base, alg_data->irq); | 667 | alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq); |
643 | 668 | ||
644 | return 0; | 669 | return 0; |
645 | 670 | ||
646 | out_irq: | 671 | out_irq: |
647 | free_irq(alg_data->irq, alg_data); | 672 | free_irq(i2c_pnx->irq, alg_data); |
648 | out_clock: | 673 | out_clock: |
649 | i2c_pnx->set_clock_stop(pdev); | 674 | clk_disable(alg_data->clk); |
650 | out_unmap: | 675 | out_unmap: |
651 | iounmap((void *)alg_data->ioaddr); | 676 | iounmap(alg_data->ioaddr); |
652 | out_release: | 677 | out_release: |
653 | release_region(alg_data->base, I2C_PNX_REGION_SIZE); | 678 | release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); |
679 | out_clkget: | ||
680 | clk_put(alg_data->clk); | ||
654 | out_drvdata: | 681 | out_drvdata: |
682 | kfree(alg_data); | ||
683 | err_kzalloc: | ||
655 | platform_set_drvdata(pdev, NULL); | 684 | platform_set_drvdata(pdev, NULL); |
656 | out: | 685 | out: |
657 | return ret; | 686 | return ret; |
@@ -659,15 +688,16 @@ out: | |||
659 | 688 | ||
660 | static int __devexit i2c_pnx_remove(struct platform_device *pdev) | 689 | static int __devexit i2c_pnx_remove(struct platform_device *pdev) |
661 | { | 690 | { |
662 | struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev); | 691 | struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); |
663 | struct i2c_adapter *adap = i2c_pnx->adapter; | 692 | struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx; |
664 | struct i2c_pnx_algo_data *alg_data = adap->algo_data; | 693 | |
665 | 694 | free_irq(i2c_pnx->irq, alg_data); | |
666 | free_irq(alg_data->irq, alg_data); | 695 | i2c_del_adapter(&alg_data->adapter); |
667 | i2c_del_adapter(adap); | 696 | clk_disable(alg_data->clk); |
668 | i2c_pnx->set_clock_stop(pdev); | 697 | iounmap(alg_data->ioaddr); |
669 | iounmap((void *)alg_data->ioaddr); | 698 | release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); |
670 | release_region(alg_data->base, I2C_PNX_REGION_SIZE); | 699 | clk_put(alg_data->clk); |
700 | kfree(alg_data); | ||
671 | platform_set_drvdata(pdev, NULL); | 701 | platform_set_drvdata(pdev, NULL); |
672 | 702 | ||
673 | return 0; | 703 | return 0; |
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index 3c9d71f60187..b289ec99eeba 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c | |||
@@ -49,48 +49,38 @@ static s32 i2c_powermac_smbus_xfer( struct i2c_adapter* adap, | |||
49 | int rc = 0; | 49 | int rc = 0; |
50 | int read = (read_write == I2C_SMBUS_READ); | 50 | int read = (read_write == I2C_SMBUS_READ); |
51 | int addrdir = (addr << 1) | read; | 51 | int addrdir = (addr << 1) | read; |
52 | int mode, subsize, len; | ||
53 | u32 subaddr; | ||
54 | u8 *buf; | ||
52 | u8 local[2]; | 55 | u8 local[2]; |
53 | 56 | ||
54 | rc = pmac_i2c_open(bus, 0); | 57 | if (size == I2C_SMBUS_QUICK || size == I2C_SMBUS_BYTE) { |
55 | if (rc) | 58 | mode = pmac_i2c_mode_std; |
56 | return rc; | 59 | subsize = 0; |
60 | subaddr = 0; | ||
61 | } else { | ||
62 | mode = read ? pmac_i2c_mode_combined : pmac_i2c_mode_stdsub; | ||
63 | subsize = 1; | ||
64 | subaddr = command; | ||
65 | } | ||
57 | 66 | ||
58 | switch (size) { | 67 | switch (size) { |
59 | case I2C_SMBUS_QUICK: | 68 | case I2C_SMBUS_QUICK: |
60 | rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std); | 69 | buf = NULL; |
61 | if (rc) | 70 | len = 0; |
62 | goto bail; | ||
63 | rc = pmac_i2c_xfer(bus, addrdir, 0, 0, NULL, 0); | ||
64 | break; | 71 | break; |
65 | case I2C_SMBUS_BYTE: | 72 | case I2C_SMBUS_BYTE: |
66 | rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std); | ||
67 | if (rc) | ||
68 | goto bail; | ||
69 | rc = pmac_i2c_xfer(bus, addrdir, 0, 0, &data->byte, 1); | ||
70 | break; | ||
71 | case I2C_SMBUS_BYTE_DATA: | 73 | case I2C_SMBUS_BYTE_DATA: |
72 | rc = pmac_i2c_setmode(bus, read ? | 74 | buf = &data->byte; |
73 | pmac_i2c_mode_combined : | 75 | len = 1; |
74 | pmac_i2c_mode_stdsub); | ||
75 | if (rc) | ||
76 | goto bail; | ||
77 | rc = pmac_i2c_xfer(bus, addrdir, 1, command, &data->byte, 1); | ||
78 | break; | 76 | break; |
79 | case I2C_SMBUS_WORD_DATA: | 77 | case I2C_SMBUS_WORD_DATA: |
80 | rc = pmac_i2c_setmode(bus, read ? | ||
81 | pmac_i2c_mode_combined : | ||
82 | pmac_i2c_mode_stdsub); | ||
83 | if (rc) | ||
84 | goto bail; | ||
85 | if (!read) { | 78 | if (!read) { |
86 | local[0] = data->word & 0xff; | 79 | local[0] = data->word & 0xff; |
87 | local[1] = (data->word >> 8) & 0xff; | 80 | local[1] = (data->word >> 8) & 0xff; |
88 | } | 81 | } |
89 | rc = pmac_i2c_xfer(bus, addrdir, 1, command, local, 2); | 82 | buf = local; |
90 | if (rc == 0 && read) { | 83 | len = 2; |
91 | data->word = ((u16)local[1]) << 8; | ||
92 | data->word |= local[0]; | ||
93 | } | ||
94 | break; | 84 | break; |
95 | 85 | ||
96 | /* Note that these are broken vs. the expected smbus API where | 86 | /* Note that these are broken vs. the expected smbus API where |
@@ -105,28 +95,49 @@ static s32 i2c_powermac_smbus_xfer( struct i2c_adapter* adap, | |||
105 | * a repeat start/addr phase (but not stop in between) | 95 | * a repeat start/addr phase (but not stop in between) |
106 | */ | 96 | */ |
107 | case I2C_SMBUS_BLOCK_DATA: | 97 | case I2C_SMBUS_BLOCK_DATA: |
108 | rc = pmac_i2c_setmode(bus, read ? | 98 | buf = data->block; |
109 | pmac_i2c_mode_combined : | 99 | len = data->block[0] + 1; |
110 | pmac_i2c_mode_stdsub); | ||
111 | if (rc) | ||
112 | goto bail; | ||
113 | rc = pmac_i2c_xfer(bus, addrdir, 1, command, data->block, | ||
114 | data->block[0] + 1); | ||
115 | |||
116 | break; | 100 | break; |
117 | case I2C_SMBUS_I2C_BLOCK_DATA: | 101 | case I2C_SMBUS_I2C_BLOCK_DATA: |
118 | rc = pmac_i2c_setmode(bus, read ? | 102 | buf = &data->block[1]; |
119 | pmac_i2c_mode_combined : | 103 | len = data->block[0]; |
120 | pmac_i2c_mode_stdsub); | ||
121 | if (rc) | ||
122 | goto bail; | ||
123 | rc = pmac_i2c_xfer(bus, addrdir, 1, command, | ||
124 | &data->block[1], data->block[0]); | ||
125 | break; | 104 | break; |
126 | 105 | ||
127 | default: | 106 | default: |
128 | rc = -EINVAL; | 107 | return -EINVAL; |
108 | } | ||
109 | |||
110 | rc = pmac_i2c_open(bus, 0); | ||
111 | if (rc) { | ||
112 | dev_err(&adap->dev, "Failed to open I2C, err %d\n", rc); | ||
113 | return rc; | ||
114 | } | ||
115 | |||
116 | rc = pmac_i2c_setmode(bus, mode); | ||
117 | if (rc) { | ||
118 | dev_err(&adap->dev, "Failed to set I2C mode %d, err %d\n", | ||
119 | mode, rc); | ||
120 | goto bail; | ||
129 | } | 121 | } |
122 | |||
123 | rc = pmac_i2c_xfer(bus, addrdir, subsize, subaddr, buf, len); | ||
124 | if (rc) { | ||
125 | if (rc == -ENXIO) | ||
126 | dev_dbg(&adap->dev, | ||
127 | "I2C transfer at 0x%02x failed, size %d, " | ||
128 | "err %d\n", addrdir >> 1, size, rc); | ||
129 | else | ||
130 | dev_err(&adap->dev, | ||
131 | "I2C transfer at 0x%02x failed, size %d, " | ||
132 | "err %d\n", addrdir >> 1, size, rc); | ||
133 | goto bail; | ||
134 | } | ||
135 | |||
136 | if (size == I2C_SMBUS_WORD_DATA && read) { | ||
137 | data->word = ((u16)local[1]) << 8; | ||
138 | data->word |= local[0]; | ||
139 | } | ||
140 | |||
130 | bail: | 141 | bail: |
131 | pmac_i2c_close(bus); | 142 | pmac_i2c_close(bus); |
132 | return rc; | 143 | return rc; |
@@ -146,20 +157,39 @@ static int i2c_powermac_master_xfer( struct i2c_adapter *adap, | |||
146 | int read; | 157 | int read; |
147 | int addrdir; | 158 | int addrdir; |
148 | 159 | ||
160 | if (num != 1) { | ||
161 | dev_err(&adap->dev, | ||
162 | "Multi-message I2C transactions not supported\n"); | ||
163 | return -EOPNOTSUPP; | ||
164 | } | ||
165 | |||
149 | if (msgs->flags & I2C_M_TEN) | 166 | if (msgs->flags & I2C_M_TEN) |
150 | return -EINVAL; | 167 | return -EINVAL; |
151 | read = (msgs->flags & I2C_M_RD) != 0; | 168 | read = (msgs->flags & I2C_M_RD) != 0; |
152 | addrdir = (msgs->addr << 1) | read; | 169 | addrdir = (msgs->addr << 1) | read; |
153 | if (msgs->flags & I2C_M_REV_DIR_ADDR) | ||
154 | addrdir ^= 1; | ||
155 | 170 | ||
156 | rc = pmac_i2c_open(bus, 0); | 171 | rc = pmac_i2c_open(bus, 0); |
157 | if (rc) | 172 | if (rc) { |
173 | dev_err(&adap->dev, "Failed to open I2C, err %d\n", rc); | ||
158 | return rc; | 174 | return rc; |
175 | } | ||
159 | rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std); | 176 | rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std); |
160 | if (rc) | 177 | if (rc) { |
178 | dev_err(&adap->dev, "Failed to set I2C mode %d, err %d\n", | ||
179 | pmac_i2c_mode_std, rc); | ||
161 | goto bail; | 180 | goto bail; |
181 | } | ||
162 | rc = pmac_i2c_xfer(bus, addrdir, 0, 0, msgs->buf, msgs->len); | 182 | rc = pmac_i2c_xfer(bus, addrdir, 0, 0, msgs->buf, msgs->len); |
183 | if (rc < 0) { | ||
184 | if (rc == -ENXIO) | ||
185 | dev_dbg(&adap->dev, "I2C %s 0x%02x failed, err %d\n", | ||
186 | addrdir & 1 ? "read from" : "write to", | ||
187 | addrdir >> 1, rc); | ||
188 | else | ||
189 | dev_err(&adap->dev, "I2C %s 0x%02x failed, err %d\n", | ||
190 | addrdir & 1 ? "read from" : "write to", | ||
191 | addrdir >> 1, rc); | ||
192 | } | ||
163 | bail: | 193 | bail: |
164 | pmac_i2c_close(bus); | 194 | pmac_i2c_close(bus); |
165 | return rc < 0 ? rc : 1; | 195 | return rc < 0 ? rc : 1; |
@@ -183,19 +213,16 @@ static const struct i2c_algorithm i2c_powermac_algorithm = { | |||
183 | static int __devexit i2c_powermac_remove(struct platform_device *dev) | 213 | static int __devexit i2c_powermac_remove(struct platform_device *dev) |
184 | { | 214 | { |
185 | struct i2c_adapter *adapter = platform_get_drvdata(dev); | 215 | struct i2c_adapter *adapter = platform_get_drvdata(dev); |
186 | struct pmac_i2c_bus *bus = i2c_get_adapdata(adapter); | ||
187 | int rc; | 216 | int rc; |
188 | 217 | ||
189 | rc = i2c_del_adapter(adapter); | 218 | rc = i2c_del_adapter(adapter); |
190 | pmac_i2c_detach_adapter(bus, adapter); | ||
191 | i2c_set_adapdata(adapter, NULL); | ||
192 | /* We aren't that prepared to deal with this... */ | 219 | /* We aren't that prepared to deal with this... */ |
193 | if (rc) | 220 | if (rc) |
194 | printk(KERN_WARNING | 221 | printk(KERN_WARNING |
195 | "i2c-powermac.c: Failed to remove bus %s !\n", | 222 | "i2c-powermac.c: Failed to remove bus %s !\n", |
196 | adapter->name); | 223 | adapter->name); |
197 | platform_set_drvdata(dev, NULL); | 224 | platform_set_drvdata(dev, NULL); |
198 | kfree(adapter); | 225 | memset(adapter, 0, sizeof(*adapter)); |
199 | 226 | ||
200 | return 0; | 227 | return 0; |
201 | } | 228 | } |
@@ -206,12 +233,12 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev) | |||
206 | struct pmac_i2c_bus *bus = dev->dev.platform_data; | 233 | struct pmac_i2c_bus *bus = dev->dev.platform_data; |
207 | struct device_node *parent = NULL; | 234 | struct device_node *parent = NULL; |
208 | struct i2c_adapter *adapter; | 235 | struct i2c_adapter *adapter; |
209 | char name[32]; | ||
210 | const char *basename; | 236 | const char *basename; |
211 | int rc; | 237 | int rc; |
212 | 238 | ||
213 | if (bus == NULL) | 239 | if (bus == NULL) |
214 | return -EINVAL; | 240 | return -EINVAL; |
241 | adapter = pmac_i2c_get_adapter(bus); | ||
215 | 242 | ||
216 | /* Ok, now we need to make up a name for the interface that will | 243 | /* Ok, now we need to make up a name for the interface that will |
217 | * match what we used to do in the past, that is basically the | 244 | * match what we used to do in the past, that is basically the |
@@ -237,29 +264,22 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev) | |||
237 | default: | 264 | default: |
238 | return -EINVAL; | 265 | return -EINVAL; |
239 | } | 266 | } |
240 | snprintf(name, 32, "%s %d", basename, pmac_i2c_get_channel(bus)); | 267 | snprintf(adapter->name, sizeof(adapter->name), "%s %d", basename, |
268 | pmac_i2c_get_channel(bus)); | ||
241 | of_node_put(parent); | 269 | of_node_put(parent); |
242 | 270 | ||
243 | adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); | ||
244 | if (adapter == NULL) { | ||
245 | printk(KERN_ERR "i2c-powermac: can't allocate inteface !\n"); | ||
246 | return -ENOMEM; | ||
247 | } | ||
248 | platform_set_drvdata(dev, adapter); | 271 | platform_set_drvdata(dev, adapter); |
249 | strcpy(adapter->name, name); | ||
250 | adapter->algo = &i2c_powermac_algorithm; | 272 | adapter->algo = &i2c_powermac_algorithm; |
251 | i2c_set_adapdata(adapter, bus); | 273 | i2c_set_adapdata(adapter, bus); |
252 | adapter->dev.parent = &dev->dev; | 274 | adapter->dev.parent = &dev->dev; |
253 | pmac_i2c_attach_adapter(bus, adapter); | ||
254 | rc = i2c_add_adapter(adapter); | 275 | rc = i2c_add_adapter(adapter); |
255 | if (rc) { | 276 | if (rc) { |
256 | printk(KERN_ERR "i2c-powermac: Adapter %s registration " | 277 | printk(KERN_ERR "i2c-powermac: Adapter %s registration " |
257 | "failed\n", name); | 278 | "failed\n", adapter->name); |
258 | i2c_set_adapdata(adapter, NULL); | 279 | memset(adapter, 0, sizeof(*adapter)); |
259 | pmac_i2c_detach_adapter(bus, adapter); | ||
260 | } | 280 | } |
261 | 281 | ||
262 | printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); | 282 | printk(KERN_INFO "PowerMac i2c bus %s registered\n", adapter->name); |
263 | 283 | ||
264 | if (!strncmp(basename, "uni-n", 5)) { | 284 | if (!strncmp(basename, "uni-n", 5)) { |
265 | struct device_node *np; | 285 | struct device_node *np; |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 762e1e530882..f4c19a97e0b3 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -12,7 +12,7 @@ | |||
12 | * | 12 | * |
13 | * History: | 13 | * History: |
14 | * Apr 2002: Initial version [CS] | 14 | * Apr 2002: Initial version [CS] |
15 | * Jun 2002: Properly seperated algo/adap [FB] | 15 | * Jun 2002: Properly separated algo/adap [FB] |
16 | * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem] | 16 | * Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem] |
17 | * Jan 2003: added limited signal handling [Kai-Uwe Bloem] | 17 | * Jan 2003: added limited signal handling [Kai-Uwe Bloem] |
18 | * Sep 2004: Major rework to ensure efficient bus handling [RMK] | 18 | * Sep 2004: Major rework to ensure efficient bus handling [RMK] |
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <linux/i2c-id.h> | ||
26 | #include <linux/init.h> | 25 | #include <linux/init.h> |
27 | #include <linux/time.h> | 26 | #include <linux/time.h> |
28 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
@@ -33,9 +32,10 @@ | |||
33 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
34 | #include <linux/err.h> | 33 | #include <linux/err.h> |
35 | #include <linux/clk.h> | 34 | #include <linux/clk.h> |
35 | #include <linux/slab.h> | ||
36 | #include <linux/io.h> | ||
36 | 37 | ||
37 | #include <asm/irq.h> | 38 | #include <asm/irq.h> |
38 | #include <asm/io.h> | ||
39 | #include <plat/i2c.h> | 39 | #include <plat/i2c.h> |
40 | 40 | ||
41 | /* | 41 | /* |
@@ -208,18 +208,6 @@ static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname) | |||
208 | } | 208 | } |
209 | 209 | ||
210 | #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__) | 210 | #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__) |
211 | #else | ||
212 | #define i2c_debug 0 | ||
213 | |||
214 | #define show_state(i2c) do { } while (0) | ||
215 | #define decode_ISR(val) do { } while (0) | ||
216 | #define decode_ICR(val) do { } while (0) | ||
217 | #endif | ||
218 | |||
219 | #define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0) | ||
220 | |||
221 | static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret); | ||
222 | static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id); | ||
223 | 211 | ||
224 | static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) | 212 | static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) |
225 | { | 213 | { |
@@ -235,6 +223,20 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) | |||
235 | printk("\n"); | 223 | printk("\n"); |
236 | } | 224 | } |
237 | 225 | ||
226 | #else /* ifdef DEBUG */ | ||
227 | |||
228 | #define i2c_debug 0 | ||
229 | |||
230 | #define show_state(i2c) do { } while (0) | ||
231 | #define decode_ISR(val) do { } while (0) | ||
232 | #define decode_ICR(val) do { } while (0) | ||
233 | #define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0) | ||
234 | |||
235 | #endif /* ifdef DEBUG / else */ | ||
236 | |||
237 | static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret); | ||
238 | static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id); | ||
239 | |||
238 | static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) | 240 | static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) |
239 | { | 241 | { |
240 | return !(readl(_ICR(i2c)) & ICR_SCLE); | 242 | return !(readl(_ICR(i2c)) & ICR_SCLE); |
@@ -998,7 +1000,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
998 | struct pxa_i2c *i2c; | 1000 | struct pxa_i2c *i2c; |
999 | struct resource *res; | 1001 | struct resource *res; |
1000 | struct i2c_pxa_platform_data *plat = dev->dev.platform_data; | 1002 | struct i2c_pxa_platform_data *plat = dev->dev.platform_data; |
1001 | struct platform_device_id *id = platform_get_device_id(dev); | 1003 | const struct platform_device_id *id = platform_get_device_id(dev); |
1002 | int ret; | 1004 | int ret; |
1003 | int irq; | 1005 | int irq; |
1004 | 1006 | ||
@@ -1134,35 +1136,44 @@ static int __exit i2c_pxa_remove(struct platform_device *dev) | |||
1134 | } | 1136 | } |
1135 | 1137 | ||
1136 | #ifdef CONFIG_PM | 1138 | #ifdef CONFIG_PM |
1137 | static int i2c_pxa_suspend_late(struct platform_device *dev, pm_message_t state) | 1139 | static int i2c_pxa_suspend_noirq(struct device *dev) |
1138 | { | 1140 | { |
1139 | struct pxa_i2c *i2c = platform_get_drvdata(dev); | 1141 | struct platform_device *pdev = to_platform_device(dev); |
1142 | struct pxa_i2c *i2c = platform_get_drvdata(pdev); | ||
1143 | |||
1140 | clk_disable(i2c->clk); | 1144 | clk_disable(i2c->clk); |
1145 | |||
1141 | return 0; | 1146 | return 0; |
1142 | } | 1147 | } |
1143 | 1148 | ||
1144 | static int i2c_pxa_resume_early(struct platform_device *dev) | 1149 | static int i2c_pxa_resume_noirq(struct device *dev) |
1145 | { | 1150 | { |
1146 | struct pxa_i2c *i2c = platform_get_drvdata(dev); | 1151 | struct platform_device *pdev = to_platform_device(dev); |
1152 | struct pxa_i2c *i2c = platform_get_drvdata(pdev); | ||
1147 | 1153 | ||
1148 | clk_enable(i2c->clk); | 1154 | clk_enable(i2c->clk); |
1149 | i2c_pxa_reset(i2c); | 1155 | i2c_pxa_reset(i2c); |
1150 | 1156 | ||
1151 | return 0; | 1157 | return 0; |
1152 | } | 1158 | } |
1159 | |||
1160 | static const struct dev_pm_ops i2c_pxa_dev_pm_ops = { | ||
1161 | .suspend_noirq = i2c_pxa_suspend_noirq, | ||
1162 | .resume_noirq = i2c_pxa_resume_noirq, | ||
1163 | }; | ||
1164 | |||
1165 | #define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops) | ||
1153 | #else | 1166 | #else |
1154 | #define i2c_pxa_suspend_late NULL | 1167 | #define I2C_PXA_DEV_PM_OPS NULL |
1155 | #define i2c_pxa_resume_early NULL | ||
1156 | #endif | 1168 | #endif |
1157 | 1169 | ||
1158 | static struct platform_driver i2c_pxa_driver = { | 1170 | static struct platform_driver i2c_pxa_driver = { |
1159 | .probe = i2c_pxa_probe, | 1171 | .probe = i2c_pxa_probe, |
1160 | .remove = __exit_p(i2c_pxa_remove), | 1172 | .remove = __exit_p(i2c_pxa_remove), |
1161 | .suspend_late = i2c_pxa_suspend_late, | ||
1162 | .resume_early = i2c_pxa_resume_early, | ||
1163 | .driver = { | 1173 | .driver = { |
1164 | .name = "pxa2xx-i2c", | 1174 | .name = "pxa2xx-i2c", |
1165 | .owner = THIS_MODULE, | 1175 | .owner = THIS_MODULE, |
1176 | .pm = I2C_PXA_DEV_PM_OPS, | ||
1166 | }, | 1177 | }, |
1167 | .id_table = i2c_pxa_id_table, | 1178 | .id_table = i2c_pxa_id_table, |
1168 | }; | 1179 | }; |
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 8f42a4536cdf..6c00c107ebf3 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | 25 | ||
26 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/i2c-id.h> | ||
28 | #include <linux/init.h> | 27 | #include <linux/init.h> |
29 | #include <linux/time.h> | 28 | #include <linux/time.h> |
30 | #include <linux/interrupt.h> | 29 | #include <linux/interrupt.h> |
@@ -34,9 +33,10 @@ | |||
34 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
35 | #include <linux/clk.h> | 34 | #include <linux/clk.h> |
36 | #include <linux/cpufreq.h> | 35 | #include <linux/cpufreq.h> |
36 | #include <linux/slab.h> | ||
37 | #include <linux/io.h> | ||
37 | 38 | ||
38 | #include <asm/irq.h> | 39 | #include <asm/irq.h> |
39 | #include <asm/io.h> | ||
40 | 40 | ||
41 | #include <plat/regs-iic.h> | 41 | #include <plat/regs-iic.h> |
42 | #include <plat/iic.h> | 42 | #include <plat/iic.h> |
@@ -481,7 +481,8 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) | |||
481 | static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, | 481 | static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, |
482 | struct i2c_msg *msgs, int num) | 482 | struct i2c_msg *msgs, int num) |
483 | { | 483 | { |
484 | unsigned long timeout; | 484 | unsigned long iicstat, timeout; |
485 | int spins = 20; | ||
485 | int ret; | 486 | int ret; |
486 | 487 | ||
487 | if (i2c->suspended) | 488 | if (i2c->suspended) |
@@ -520,7 +521,21 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, | |||
520 | 521 | ||
521 | /* ensure the stop has been through the bus */ | 522 | /* ensure the stop has been through the bus */ |
522 | 523 | ||
523 | msleep(1); | 524 | dev_dbg(i2c->dev, "waiting for bus idle\n"); |
525 | |||
526 | /* first, try busy waiting briefly */ | ||
527 | do { | ||
528 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); | ||
529 | } while ((iicstat & S3C2410_IICSTAT_START) && --spins); | ||
530 | |||
531 | /* if that timed out sleep */ | ||
532 | if (!spins) { | ||
533 | msleep(1); | ||
534 | iicstat = readl(i2c->regs + S3C2410_IICSTAT); | ||
535 | } | ||
536 | |||
537 | if (iicstat & S3C2410_IICSTAT_START) | ||
538 | dev_warn(i2c->dev, "timeout waiting for bus idle\n"); | ||
524 | 539 | ||
525 | out: | 540 | out: |
526 | return ret; | 541 | return ret; |
@@ -539,18 +554,23 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap, | |||
539 | int retry; | 554 | int retry; |
540 | int ret; | 555 | int ret; |
541 | 556 | ||
557 | clk_enable(i2c->clk); | ||
558 | |||
542 | for (retry = 0; retry < adap->retries; retry++) { | 559 | for (retry = 0; retry < adap->retries; retry++) { |
543 | 560 | ||
544 | ret = s3c24xx_i2c_doxfer(i2c, msgs, num); | 561 | ret = s3c24xx_i2c_doxfer(i2c, msgs, num); |
545 | 562 | ||
546 | if (ret != -EAGAIN) | 563 | if (ret != -EAGAIN) { |
564 | clk_disable(i2c->clk); | ||
547 | return ret; | 565 | return ret; |
566 | } | ||
548 | 567 | ||
549 | dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry); | 568 | dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry); |
550 | 569 | ||
551 | udelay(100); | 570 | udelay(100); |
552 | } | 571 | } |
553 | 572 | ||
573 | clk_disable(i2c->clk); | ||
554 | return -EREMOTEIO; | 574 | return -EREMOTEIO; |
555 | } | 575 | } |
556 | 576 | ||
@@ -646,8 +666,8 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) | |||
646 | unsigned long sda_delay; | 666 | unsigned long sda_delay; |
647 | 667 | ||
648 | if (pdata->sda_delay) { | 668 | if (pdata->sda_delay) { |
649 | sda_delay = (freq / 1000) * pdata->sda_delay; | 669 | sda_delay = clkin * pdata->sda_delay; |
650 | sda_delay /= 1000000; | 670 | sda_delay = DIV_ROUND_UP(sda_delay, 1000000); |
651 | sda_delay = DIV_ROUND_UP(sda_delay, 5); | 671 | sda_delay = DIV_ROUND_UP(sda_delay, 5); |
652 | if (sda_delay > 3) | 672 | if (sda_delay > 3) |
653 | sda_delay = 3; | 673 | sda_delay = 3; |
@@ -763,11 +783,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c) | |||
763 | dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); | 783 | dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); |
764 | dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); | 784 | dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); |
765 | 785 | ||
766 | /* check for s3c2440 i2c controller */ | ||
767 | |||
768 | if (s3c24xx_i2c_is2440(i2c)) | ||
769 | writel(0x0, i2c->regs + S3C2440_IICLC); | ||
770 | |||
771 | return 0; | 786 | return 0; |
772 | } | 787 | } |
773 | 788 | ||
@@ -900,6 +915,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) | |||
900 | platform_set_drvdata(pdev, i2c); | 915 | platform_set_drvdata(pdev, i2c); |
901 | 916 | ||
902 | dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev)); | 917 | dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev)); |
918 | clk_disable(i2c->clk); | ||
903 | return 0; | 919 | return 0; |
904 | 920 | ||
905 | err_cpufreq: | 921 | err_cpufreq: |
@@ -951,27 +967,37 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) | |||
951 | } | 967 | } |
952 | 968 | ||
953 | #ifdef CONFIG_PM | 969 | #ifdef CONFIG_PM |
954 | static int s3c24xx_i2c_suspend_late(struct platform_device *dev, | 970 | static int s3c24xx_i2c_suspend_noirq(struct device *dev) |
955 | pm_message_t msg) | ||
956 | { | 971 | { |
957 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); | 972 | struct platform_device *pdev = to_platform_device(dev); |
973 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); | ||
974 | |||
958 | i2c->suspended = 1; | 975 | i2c->suspended = 1; |
976 | |||
959 | return 0; | 977 | return 0; |
960 | } | 978 | } |
961 | 979 | ||
962 | static int s3c24xx_i2c_resume(struct platform_device *dev) | 980 | static int s3c24xx_i2c_resume(struct device *dev) |
963 | { | 981 | { |
964 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); | 982 | struct platform_device *pdev = to_platform_device(dev); |
983 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); | ||
965 | 984 | ||
966 | i2c->suspended = 0; | 985 | i2c->suspended = 0; |
986 | clk_enable(i2c->clk); | ||
967 | s3c24xx_i2c_init(i2c); | 987 | s3c24xx_i2c_init(i2c); |
988 | clk_disable(i2c->clk); | ||
968 | 989 | ||
969 | return 0; | 990 | return 0; |
970 | } | 991 | } |
971 | 992 | ||
993 | static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { | ||
994 | .suspend_noirq = s3c24xx_i2c_suspend_noirq, | ||
995 | .resume = s3c24xx_i2c_resume, | ||
996 | }; | ||
997 | |||
998 | #define S3C24XX_DEV_PM_OPS (&s3c24xx_i2c_dev_pm_ops) | ||
972 | #else | 999 | #else |
973 | #define s3c24xx_i2c_suspend_late NULL | 1000 | #define S3C24XX_DEV_PM_OPS NULL |
974 | #define s3c24xx_i2c_resume NULL | ||
975 | #endif | 1001 | #endif |
976 | 1002 | ||
977 | /* device driver for platform bus bits */ | 1003 | /* device driver for platform bus bits */ |
@@ -990,12 +1016,11 @@ MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); | |||
990 | static struct platform_driver s3c24xx_i2c_driver = { | 1016 | static struct platform_driver s3c24xx_i2c_driver = { |
991 | .probe = s3c24xx_i2c_probe, | 1017 | .probe = s3c24xx_i2c_probe, |
992 | .remove = s3c24xx_i2c_remove, | 1018 | .remove = s3c24xx_i2c_remove, |
993 | .suspend_late = s3c24xx_i2c_suspend_late, | ||
994 | .resume = s3c24xx_i2c_resume, | ||
995 | .id_table = s3c24xx_driver_ids, | 1019 | .id_table = s3c24xx_driver_ids, |
996 | .driver = { | 1020 | .driver = { |
997 | .owner = THIS_MODULE, | 1021 | .owner = THIS_MODULE, |
998 | .name = "s3c-i2c", | 1022 | .name = "s3c-i2c", |
1023 | .pm = S3C24XX_DEV_PM_OPS, | ||
999 | }, | 1024 | }, |
1000 | }; | 1025 | }; |
1001 | 1026 | ||
diff --git a/drivers/i2c/busses/i2c-s6000.c b/drivers/i2c/busses/i2c-s6000.c index c91359f4965c..cadc0216e02f 100644 --- a/drivers/i2c/busses/i2c-s6000.c +++ b/drivers/i2c/busses/i2c-s6000.c | |||
@@ -36,8 +36,8 @@ | |||
36 | #include <linux/completion.h> | 36 | #include <linux/completion.h> |
37 | #include <linux/interrupt.h> | 37 | #include <linux/interrupt.h> |
38 | #include <linux/platform_device.h> | 38 | #include <linux/platform_device.h> |
39 | #include <linux/io.h> | ||
39 | 40 | ||
40 | #include <asm/io.h> | ||
41 | #include "i2c-s6000.h" | 41 | #include "i2c-s6000.h" |
42 | 42 | ||
43 | #define DRV_NAME "i2c-s6000" | 43 | #define DRV_NAME "i2c-s6000" |
diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c new file mode 100644 index 000000000000..388cbdc96db7 --- /dev/null +++ b/drivers/i2c/busses/i2c-scmi.c | |||
@@ -0,0 +1,445 @@ | |||
1 | /* | ||
2 | * SMBus driver for ACPI SMBus CMI | ||
3 | * | ||
4 | * Copyright (C) 2009 Crane Cai <crane.cai@amd.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation version 2. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/slab.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/stddef.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/acpi.h> | ||
18 | |||
19 | #define ACPI_SMBUS_HC_CLASS "smbus" | ||
20 | #define ACPI_SMBUS_HC_DEVICE_NAME "cmi" | ||
21 | |||
22 | ACPI_MODULE_NAME("smbus_cmi"); | ||
23 | |||
24 | struct smbus_methods_t { | ||
25 | char *mt_info; | ||
26 | char *mt_sbr; | ||
27 | char *mt_sbw; | ||
28 | }; | ||
29 | |||
30 | struct acpi_smbus_cmi { | ||
31 | acpi_handle handle; | ||
32 | struct i2c_adapter adapter; | ||
33 | u8 cap_info:1; | ||
34 | u8 cap_read:1; | ||
35 | u8 cap_write:1; | ||
36 | struct smbus_methods_t *methods; | ||
37 | }; | ||
38 | |||
39 | static const struct smbus_methods_t smbus_methods = { | ||
40 | .mt_info = "_SBI", | ||
41 | .mt_sbr = "_SBR", | ||
42 | .mt_sbw = "_SBW", | ||
43 | }; | ||
44 | |||
45 | /* Some IBM BIOSes omit the leading underscore */ | ||
46 | static const struct smbus_methods_t ibm_smbus_methods = { | ||
47 | .mt_info = "SBI_", | ||
48 | .mt_sbr = "SBR_", | ||
49 | .mt_sbw = "SBW_", | ||
50 | }; | ||
51 | |||
52 | static const struct acpi_device_id acpi_smbus_cmi_ids[] = { | ||
53 | {"SMBUS01", (kernel_ulong_t)&smbus_methods}, | ||
54 | {ACPI_SMBUS_IBM_HID, (kernel_ulong_t)&ibm_smbus_methods}, | ||
55 | {"", 0} | ||
56 | }; | ||
57 | MODULE_DEVICE_TABLE(acpi, acpi_smbus_cmi_ids); | ||
58 | |||
59 | #define ACPI_SMBUS_STATUS_OK 0x00 | ||
60 | #define ACPI_SMBUS_STATUS_FAIL 0x07 | ||
61 | #define ACPI_SMBUS_STATUS_DNAK 0x10 | ||
62 | #define ACPI_SMBUS_STATUS_DERR 0x11 | ||
63 | #define ACPI_SMBUS_STATUS_CMD_DENY 0x12 | ||
64 | #define ACPI_SMBUS_STATUS_UNKNOWN 0x13 | ||
65 | #define ACPI_SMBUS_STATUS_ACC_DENY 0x17 | ||
66 | #define ACPI_SMBUS_STATUS_TIMEOUT 0x18 | ||
67 | #define ACPI_SMBUS_STATUS_NOTSUP 0x19 | ||
68 | #define ACPI_SMBUS_STATUS_BUSY 0x1a | ||
69 | #define ACPI_SMBUS_STATUS_PEC 0x1f | ||
70 | |||
71 | #define ACPI_SMBUS_PRTCL_WRITE 0x00 | ||
72 | #define ACPI_SMBUS_PRTCL_READ 0x01 | ||
73 | #define ACPI_SMBUS_PRTCL_QUICK 0x02 | ||
74 | #define ACPI_SMBUS_PRTCL_BYTE 0x04 | ||
75 | #define ACPI_SMBUS_PRTCL_BYTE_DATA 0x06 | ||
76 | #define ACPI_SMBUS_PRTCL_WORD_DATA 0x08 | ||
77 | #define ACPI_SMBUS_PRTCL_BLOCK_DATA 0x0a | ||
78 | |||
79 | |||
80 | static int | ||
81 | acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, | ||
82 | char read_write, u8 command, int size, | ||
83 | union i2c_smbus_data *data) | ||
84 | { | ||
85 | int result = 0; | ||
86 | struct acpi_smbus_cmi *smbus_cmi = adap->algo_data; | ||
87 | unsigned char protocol; | ||
88 | acpi_status status = 0; | ||
89 | struct acpi_object_list input; | ||
90 | union acpi_object mt_params[5]; | ||
91 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
92 | union acpi_object *obj; | ||
93 | union acpi_object *pkg; | ||
94 | char *method; | ||
95 | int len = 0; | ||
96 | |||
97 | dev_dbg(&adap->dev, "access size: %d %s\n", size, | ||
98 | (read_write) ? "READ" : "WRITE"); | ||
99 | switch (size) { | ||
100 | case I2C_SMBUS_QUICK: | ||
101 | protocol = ACPI_SMBUS_PRTCL_QUICK; | ||
102 | command = 0; | ||
103 | if (read_write == I2C_SMBUS_WRITE) { | ||
104 | mt_params[3].type = ACPI_TYPE_INTEGER; | ||
105 | mt_params[3].integer.value = 0; | ||
106 | mt_params[4].type = ACPI_TYPE_INTEGER; | ||
107 | mt_params[4].integer.value = 0; | ||
108 | } | ||
109 | break; | ||
110 | |||
111 | case I2C_SMBUS_BYTE: | ||
112 | protocol = ACPI_SMBUS_PRTCL_BYTE; | ||
113 | if (read_write == I2C_SMBUS_WRITE) { | ||
114 | mt_params[3].type = ACPI_TYPE_INTEGER; | ||
115 | mt_params[3].integer.value = 0; | ||
116 | mt_params[4].type = ACPI_TYPE_INTEGER; | ||
117 | mt_params[4].integer.value = 0; | ||
118 | } else { | ||
119 | command = 0; | ||
120 | } | ||
121 | break; | ||
122 | |||
123 | case I2C_SMBUS_BYTE_DATA: | ||
124 | protocol = ACPI_SMBUS_PRTCL_BYTE_DATA; | ||
125 | if (read_write == I2C_SMBUS_WRITE) { | ||
126 | mt_params[3].type = ACPI_TYPE_INTEGER; | ||
127 | mt_params[3].integer.value = 1; | ||
128 | mt_params[4].type = ACPI_TYPE_INTEGER; | ||
129 | mt_params[4].integer.value = data->byte; | ||
130 | } | ||
131 | break; | ||
132 | |||
133 | case I2C_SMBUS_WORD_DATA: | ||
134 | protocol = ACPI_SMBUS_PRTCL_WORD_DATA; | ||
135 | if (read_write == I2C_SMBUS_WRITE) { | ||
136 | mt_params[3].type = ACPI_TYPE_INTEGER; | ||
137 | mt_params[3].integer.value = 2; | ||
138 | mt_params[4].type = ACPI_TYPE_INTEGER; | ||
139 | mt_params[4].integer.value = data->word; | ||
140 | } | ||
141 | break; | ||
142 | |||
143 | case I2C_SMBUS_BLOCK_DATA: | ||
144 | protocol = ACPI_SMBUS_PRTCL_BLOCK_DATA; | ||
145 | if (read_write == I2C_SMBUS_WRITE) { | ||
146 | len = data->block[0]; | ||
147 | if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) | ||
148 | return -EINVAL; | ||
149 | mt_params[3].type = ACPI_TYPE_INTEGER; | ||
150 | mt_params[3].integer.value = len; | ||
151 | mt_params[4].type = ACPI_TYPE_BUFFER; | ||
152 | mt_params[4].buffer.pointer = data->block + 1; | ||
153 | } | ||
154 | break; | ||
155 | |||
156 | default: | ||
157 | dev_warn(&adap->dev, "Unsupported transaction %d\n", size); | ||
158 | return -EOPNOTSUPP; | ||
159 | } | ||
160 | |||
161 | if (read_write == I2C_SMBUS_READ) { | ||
162 | protocol |= ACPI_SMBUS_PRTCL_READ; | ||
163 | method = smbus_cmi->methods->mt_sbr; | ||
164 | input.count = 3; | ||
165 | } else { | ||
166 | protocol |= ACPI_SMBUS_PRTCL_WRITE; | ||
167 | method = smbus_cmi->methods->mt_sbw; | ||
168 | input.count = 5; | ||
169 | } | ||
170 | |||
171 | input.pointer = mt_params; | ||
172 | mt_params[0].type = ACPI_TYPE_INTEGER; | ||
173 | mt_params[0].integer.value = protocol; | ||
174 | mt_params[1].type = ACPI_TYPE_INTEGER; | ||
175 | mt_params[1].integer.value = addr; | ||
176 | mt_params[2].type = ACPI_TYPE_INTEGER; | ||
177 | mt_params[2].integer.value = command; | ||
178 | |||
179 | status = acpi_evaluate_object(smbus_cmi->handle, method, &input, | ||
180 | &buffer); | ||
181 | if (ACPI_FAILURE(status)) { | ||
182 | ACPI_ERROR((AE_INFO, "Evaluating %s: %i", method, status)); | ||
183 | return -EIO; | ||
184 | } | ||
185 | |||
186 | pkg = buffer.pointer; | ||
187 | if (pkg && pkg->type == ACPI_TYPE_PACKAGE) | ||
188 | obj = pkg->package.elements; | ||
189 | else { | ||
190 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
191 | result = -EIO; | ||
192 | goto out; | ||
193 | } | ||
194 | if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) { | ||
195 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
196 | result = -EIO; | ||
197 | goto out; | ||
198 | } | ||
199 | |||
200 | result = obj->integer.value; | ||
201 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s return status: %i\n", | ||
202 | method, result)); | ||
203 | |||
204 | switch (result) { | ||
205 | case ACPI_SMBUS_STATUS_OK: | ||
206 | result = 0; | ||
207 | break; | ||
208 | case ACPI_SMBUS_STATUS_BUSY: | ||
209 | result = -EBUSY; | ||
210 | goto out; | ||
211 | case ACPI_SMBUS_STATUS_TIMEOUT: | ||
212 | result = -ETIMEDOUT; | ||
213 | goto out; | ||
214 | case ACPI_SMBUS_STATUS_DNAK: | ||
215 | result = -ENXIO; | ||
216 | goto out; | ||
217 | default: | ||
218 | result = -EIO; | ||
219 | goto out; | ||
220 | } | ||
221 | |||
222 | if (read_write == I2C_SMBUS_WRITE || size == I2C_SMBUS_QUICK) | ||
223 | goto out; | ||
224 | |||
225 | obj = pkg->package.elements + 1; | ||
226 | if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) { | ||
227 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
228 | result = -EIO; | ||
229 | goto out; | ||
230 | } | ||
231 | |||
232 | len = obj->integer.value; | ||
233 | obj = pkg->package.elements + 2; | ||
234 | switch (size) { | ||
235 | case I2C_SMBUS_BYTE: | ||
236 | case I2C_SMBUS_BYTE_DATA: | ||
237 | case I2C_SMBUS_WORD_DATA: | ||
238 | if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) { | ||
239 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
240 | result = -EIO; | ||
241 | goto out; | ||
242 | } | ||
243 | if (len == 2) | ||
244 | data->word = obj->integer.value; | ||
245 | else | ||
246 | data->byte = obj->integer.value; | ||
247 | break; | ||
248 | case I2C_SMBUS_BLOCK_DATA: | ||
249 | if (obj == NULL || obj->type != ACPI_TYPE_BUFFER) { | ||
250 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
251 | result = -EIO; | ||
252 | goto out; | ||
253 | } | ||
254 | if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) | ||
255 | return -EPROTO; | ||
256 | data->block[0] = len; | ||
257 | memcpy(data->block + 1, obj->buffer.pointer, len); | ||
258 | break; | ||
259 | } | ||
260 | |||
261 | out: | ||
262 | kfree(buffer.pointer); | ||
263 | dev_dbg(&adap->dev, "Transaction status: %i\n", result); | ||
264 | return result; | ||
265 | } | ||
266 | |||
267 | static u32 acpi_smbus_cmi_func(struct i2c_adapter *adapter) | ||
268 | { | ||
269 | struct acpi_smbus_cmi *smbus_cmi = adapter->algo_data; | ||
270 | u32 ret; | ||
271 | |||
272 | ret = smbus_cmi->cap_read | smbus_cmi->cap_write ? | ||
273 | I2C_FUNC_SMBUS_QUICK : 0; | ||
274 | |||
275 | ret |= smbus_cmi->cap_read ? | ||
276 | (I2C_FUNC_SMBUS_READ_BYTE | | ||
277 | I2C_FUNC_SMBUS_READ_BYTE_DATA | | ||
278 | I2C_FUNC_SMBUS_READ_WORD_DATA | | ||
279 | I2C_FUNC_SMBUS_READ_BLOCK_DATA) : 0; | ||
280 | |||
281 | ret |= smbus_cmi->cap_write ? | ||
282 | (I2C_FUNC_SMBUS_WRITE_BYTE | | ||
283 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA | | ||
284 | I2C_FUNC_SMBUS_WRITE_WORD_DATA | | ||
285 | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) : 0; | ||
286 | |||
287 | return ret; | ||
288 | } | ||
289 | |||
290 | static const struct i2c_algorithm acpi_smbus_cmi_algorithm = { | ||
291 | .smbus_xfer = acpi_smbus_cmi_access, | ||
292 | .functionality = acpi_smbus_cmi_func, | ||
293 | }; | ||
294 | |||
295 | |||
296 | static int acpi_smbus_cmi_add_cap(struct acpi_smbus_cmi *smbus_cmi, | ||
297 | const char *name) | ||
298 | { | ||
299 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
300 | union acpi_object *obj; | ||
301 | acpi_status status; | ||
302 | |||
303 | if (!strcmp(name, smbus_cmi->methods->mt_info)) { | ||
304 | status = acpi_evaluate_object(smbus_cmi->handle, | ||
305 | smbus_cmi->methods->mt_info, | ||
306 | NULL, &buffer); | ||
307 | if (ACPI_FAILURE(status)) { | ||
308 | ACPI_ERROR((AE_INFO, "Evaluating %s: %i", | ||
309 | smbus_cmi->methods->mt_info, status)); | ||
310 | return -EIO; | ||
311 | } | ||
312 | |||
313 | obj = buffer.pointer; | ||
314 | if (obj && obj->type == ACPI_TYPE_PACKAGE) | ||
315 | obj = obj->package.elements; | ||
316 | else { | ||
317 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
318 | kfree(buffer.pointer); | ||
319 | return -EIO; | ||
320 | } | ||
321 | |||
322 | if (obj->type != ACPI_TYPE_INTEGER) { | ||
323 | ACPI_ERROR((AE_INFO, "Invalid argument type")); | ||
324 | kfree(buffer.pointer); | ||
325 | return -EIO; | ||
326 | } else | ||
327 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SMBus CMI Version %x" | ||
328 | "\n", (int)obj->integer.value)); | ||
329 | |||
330 | kfree(buffer.pointer); | ||
331 | smbus_cmi->cap_info = 1; | ||
332 | } else if (!strcmp(name, smbus_cmi->methods->mt_sbr)) | ||
333 | smbus_cmi->cap_read = 1; | ||
334 | else if (!strcmp(name, smbus_cmi->methods->mt_sbw)) | ||
335 | smbus_cmi->cap_write = 1; | ||
336 | else | ||
337 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unsupported CMI method: %s\n", | ||
338 | name)); | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
343 | static acpi_status acpi_smbus_cmi_query_methods(acpi_handle handle, u32 level, | ||
344 | void *context, void **return_value) | ||
345 | { | ||
346 | char node_name[5]; | ||
347 | struct acpi_buffer buffer = { sizeof(node_name), node_name }; | ||
348 | struct acpi_smbus_cmi *smbus_cmi = context; | ||
349 | acpi_status status; | ||
350 | |||
351 | status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); | ||
352 | |||
353 | if (ACPI_SUCCESS(status)) | ||
354 | acpi_smbus_cmi_add_cap(smbus_cmi, node_name); | ||
355 | |||
356 | return AE_OK; | ||
357 | } | ||
358 | |||
359 | static int acpi_smbus_cmi_add(struct acpi_device *device) | ||
360 | { | ||
361 | struct acpi_smbus_cmi *smbus_cmi; | ||
362 | const struct acpi_device_id *id; | ||
363 | |||
364 | smbus_cmi = kzalloc(sizeof(struct acpi_smbus_cmi), GFP_KERNEL); | ||
365 | if (!smbus_cmi) | ||
366 | return -ENOMEM; | ||
367 | |||
368 | smbus_cmi->handle = device->handle; | ||
369 | strcpy(acpi_device_name(device), ACPI_SMBUS_HC_DEVICE_NAME); | ||
370 | strcpy(acpi_device_class(device), ACPI_SMBUS_HC_CLASS); | ||
371 | device->driver_data = smbus_cmi; | ||
372 | smbus_cmi->cap_info = 0; | ||
373 | smbus_cmi->cap_read = 0; | ||
374 | smbus_cmi->cap_write = 0; | ||
375 | |||
376 | for (id = acpi_smbus_cmi_ids; id->id[0]; id++) | ||
377 | if (!strcmp(id->id, acpi_device_hid(device))) | ||
378 | smbus_cmi->methods = | ||
379 | (struct smbus_methods_t *) id->driver_data; | ||
380 | |||
381 | acpi_walk_namespace(ACPI_TYPE_METHOD, smbus_cmi->handle, 1, | ||
382 | acpi_smbus_cmi_query_methods, NULL, smbus_cmi, NULL); | ||
383 | |||
384 | if (smbus_cmi->cap_info == 0) | ||
385 | goto err; | ||
386 | |||
387 | snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name), | ||
388 | "SMBus CMI adapter %s", | ||
389 | acpi_device_name(device)); | ||
390 | smbus_cmi->adapter.owner = THIS_MODULE; | ||
391 | smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm; | ||
392 | smbus_cmi->adapter.algo_data = smbus_cmi; | ||
393 | smbus_cmi->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | ||
394 | smbus_cmi->adapter.dev.parent = &device->dev; | ||
395 | |||
396 | if (i2c_add_adapter(&smbus_cmi->adapter)) { | ||
397 | dev_err(&device->dev, "Couldn't register adapter!\n"); | ||
398 | goto err; | ||
399 | } | ||
400 | |||
401 | return 0; | ||
402 | |||
403 | err: | ||
404 | kfree(smbus_cmi); | ||
405 | device->driver_data = NULL; | ||
406 | return -EIO; | ||
407 | } | ||
408 | |||
409 | static int acpi_smbus_cmi_remove(struct acpi_device *device, int type) | ||
410 | { | ||
411 | struct acpi_smbus_cmi *smbus_cmi = acpi_driver_data(device); | ||
412 | |||
413 | i2c_del_adapter(&smbus_cmi->adapter); | ||
414 | kfree(smbus_cmi); | ||
415 | device->driver_data = NULL; | ||
416 | |||
417 | return 0; | ||
418 | } | ||
419 | |||
420 | static struct acpi_driver acpi_smbus_cmi_driver = { | ||
421 | .name = ACPI_SMBUS_HC_DEVICE_NAME, | ||
422 | .class = ACPI_SMBUS_HC_CLASS, | ||
423 | .ids = acpi_smbus_cmi_ids, | ||
424 | .ops = { | ||
425 | .add = acpi_smbus_cmi_add, | ||
426 | .remove = acpi_smbus_cmi_remove, | ||
427 | }, | ||
428 | }; | ||
429 | |||
430 | static int __init acpi_smbus_cmi_init(void) | ||
431 | { | ||
432 | return acpi_bus_register_driver(&acpi_smbus_cmi_driver); | ||
433 | } | ||
434 | |||
435 | static void __exit acpi_smbus_cmi_exit(void) | ||
436 | { | ||
437 | acpi_bus_unregister_driver(&acpi_smbus_cmi_driver); | ||
438 | } | ||
439 | |||
440 | module_init(acpi_smbus_cmi_init); | ||
441 | module_exit(acpi_smbus_cmi_exit); | ||
442 | |||
443 | MODULE_LICENSE("GPL"); | ||
444 | MODULE_AUTHOR("Crane Cai <crane.cai@amd.com>"); | ||
445 | MODULE_DESCRIPTION("ACPI SMBus CMI driver"); | ||
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c index b9680f50f541..3cad8fecc3d3 100644 --- a/drivers/i2c/busses/i2c-sh7760.c +++ b/drivers/i2c/busses/i2c-sh7760.c | |||
@@ -16,10 +16,10 @@ | |||
16 | #include <linux/ioport.h> | 16 | #include <linux/ioport.h> |
17 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/io.h> | ||
19 | 20 | ||
20 | #include <asm/clock.h> | 21 | #include <asm/clock.h> |
21 | #include <asm/i2c-sh7760.h> | 22 | #include <asm/i2c-sh7760.h> |
22 | #include <asm/io.h> | ||
23 | 23 | ||
24 | /* register offsets */ | 24 | /* register offsets */ |
25 | #define I2CSCR 0x0 /* slave ctrl */ | 25 | #define I2CSCR 0x0 /* slave ctrl */ |
@@ -101,12 +101,12 @@ struct cami2c { | |||
101 | 101 | ||
102 | static inline void OUT32(struct cami2c *cam, int reg, unsigned long val) | 102 | static inline void OUT32(struct cami2c *cam, int reg, unsigned long val) |
103 | { | 103 | { |
104 | ctrl_outl(val, (unsigned long)cam->iobase + reg); | 104 | __raw_writel(val, (unsigned long)cam->iobase + reg); |
105 | } | 105 | } |
106 | 106 | ||
107 | static inline unsigned long IN32(struct cami2c *cam, int reg) | 107 | static inline unsigned long IN32(struct cami2c *cam, int reg) |
108 | { | 108 | { |
109 | return ctrl_inl((unsigned long)cam->iobase + reg); | 109 | return __raw_readl((unsigned long)cam->iobase + reg); |
110 | } | 110 | } |
111 | 111 | ||
112 | static irqreturn_t sh7760_i2c_irq(int irq, void *ptr) | 112 | static irqreturn_t sh7760_i2c_irq(int irq, void *ptr) |
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index 1c01083b01b5..2707f5e17158 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c | |||
@@ -28,8 +28,10 @@ | |||
28 | #include <linux/interrupt.h> | 28 | #include <linux/interrupt.h> |
29 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
30 | #include <linux/err.h> | 30 | #include <linux/err.h> |
31 | #include <linux/pm_runtime.h> | ||
31 | #include <linux/clk.h> | 32 | #include <linux/clk.h> |
32 | #include <linux/io.h> | 33 | #include <linux/io.h> |
34 | #include <linux/slab.h> | ||
33 | 35 | ||
34 | /* Transmit operation: */ | 36 | /* Transmit operation: */ |
35 | /* */ | 37 | /* */ |
@@ -117,8 +119,10 @@ struct sh_mobile_i2c_data { | |||
117 | struct i2c_adapter adap; | 119 | struct i2c_adapter adap; |
118 | 120 | ||
119 | struct clk *clk; | 121 | struct clk *clk; |
122 | u_int8_t icic; | ||
120 | u_int8_t iccl; | 123 | u_int8_t iccl; |
121 | u_int8_t icch; | 124 | u_int8_t icch; |
125 | u_int8_t flags; | ||
122 | 126 | ||
123 | spinlock_t lock; | 127 | spinlock_t lock; |
124 | wait_queue_head_t wait; | 128 | wait_queue_head_t wait; |
@@ -127,15 +131,17 @@ struct sh_mobile_i2c_data { | |||
127 | int sr; | 131 | int sr; |
128 | }; | 132 | }; |
129 | 133 | ||
134 | #define IIC_FLAG_HAS_ICIC67 (1 << 0) | ||
135 | |||
130 | #define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */ | 136 | #define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */ |
131 | 137 | ||
132 | /* Register offsets */ | 138 | /* Register offsets */ |
133 | #define ICDR(pd) (pd->reg + 0x00) | 139 | #define ICDR 0x00 |
134 | #define ICCR(pd) (pd->reg + 0x04) | 140 | #define ICCR 0x04 |
135 | #define ICSR(pd) (pd->reg + 0x08) | 141 | #define ICSR 0x08 |
136 | #define ICIC(pd) (pd->reg + 0x0c) | 142 | #define ICIC 0x0c |
137 | #define ICCL(pd) (pd->reg + 0x10) | 143 | #define ICCL 0x10 |
138 | #define ICCH(pd) (pd->reg + 0x14) | 144 | #define ICCH 0x14 |
139 | 145 | ||
140 | /* Register bits */ | 146 | /* Register bits */ |
141 | #define ICCR_ICE 0x80 | 147 | #define ICCR_ICE 0x80 |
@@ -153,11 +159,32 @@ struct sh_mobile_i2c_data { | |||
153 | #define ICSR_WAIT 0x02 | 159 | #define ICSR_WAIT 0x02 |
154 | #define ICSR_DTE 0x01 | 160 | #define ICSR_DTE 0x01 |
155 | 161 | ||
162 | #define ICIC_ICCLB8 0x80 | ||
163 | #define ICIC_ICCHB8 0x40 | ||
156 | #define ICIC_ALE 0x08 | 164 | #define ICIC_ALE 0x08 |
157 | #define ICIC_TACKE 0x04 | 165 | #define ICIC_TACKE 0x04 |
158 | #define ICIC_WAITE 0x02 | 166 | #define ICIC_WAITE 0x02 |
159 | #define ICIC_DTEE 0x01 | 167 | #define ICIC_DTEE 0x01 |
160 | 168 | ||
169 | static void iic_wr(struct sh_mobile_i2c_data *pd, int offs, unsigned char data) | ||
170 | { | ||
171 | if (offs == ICIC) | ||
172 | data |= pd->icic; | ||
173 | |||
174 | iowrite8(data, pd->reg + offs); | ||
175 | } | ||
176 | |||
177 | static unsigned char iic_rd(struct sh_mobile_i2c_data *pd, int offs) | ||
178 | { | ||
179 | return ioread8(pd->reg + offs); | ||
180 | } | ||
181 | |||
182 | static void iic_set_clr(struct sh_mobile_i2c_data *pd, int offs, | ||
183 | unsigned char set, unsigned char clr) | ||
184 | { | ||
185 | iic_wr(pd, offs, (iic_rd(pd, offs) | set) & ~clr); | ||
186 | } | ||
187 | |||
161 | static void activate_ch(struct sh_mobile_i2c_data *pd) | 188 | static void activate_ch(struct sh_mobile_i2c_data *pd) |
162 | { | 189 | { |
163 | unsigned long i2c_clk; | 190 | unsigned long i2c_clk; |
@@ -165,7 +192,8 @@ static void activate_ch(struct sh_mobile_i2c_data *pd) | |||
165 | u_int32_t denom; | 192 | u_int32_t denom; |
166 | u_int32_t tmp; | 193 | u_int32_t tmp; |
167 | 194 | ||
168 | /* Make sure the clock is enabled */ | 195 | /* Wake up device and enable clock */ |
196 | pm_runtime_get_sync(pd->dev); | ||
169 | clk_enable(pd->clk); | 197 | clk_enable(pd->clk); |
170 | 198 | ||
171 | /* Get clock rate after clock is enabled */ | 199 | /* Get clock rate after clock is enabled */ |
@@ -184,6 +212,14 @@ static void activate_ch(struct sh_mobile_i2c_data *pd) | |||
184 | else | 212 | else |
185 | pd->iccl = (u_int8_t)(num/denom); | 213 | pd->iccl = (u_int8_t)(num/denom); |
186 | 214 | ||
215 | /* one more bit of ICCL in ICIC */ | ||
216 | if (pd->flags & IIC_FLAG_HAS_ICIC67) { | ||
217 | if ((num/denom) > 0xff) | ||
218 | pd->icic |= ICIC_ICCLB8; | ||
219 | else | ||
220 | pd->icic &= ~ICIC_ICCLB8; | ||
221 | } | ||
222 | |||
187 | /* Calculate the value for icch. From the data sheet: | 223 | /* Calculate the value for icch. From the data sheet: |
188 | icch = (p clock / transfer rate) * (H / (L + H)) */ | 224 | icch = (p clock / transfer rate) * (H / (L + H)) */ |
189 | num = i2c_clk * 4; | 225 | num = i2c_clk * 4; |
@@ -193,28 +229,37 @@ static void activate_ch(struct sh_mobile_i2c_data *pd) | |||
193 | else | 229 | else |
194 | pd->icch = (u_int8_t)(num/denom); | 230 | pd->icch = (u_int8_t)(num/denom); |
195 | 231 | ||
232 | /* one more bit of ICCH in ICIC */ | ||
233 | if (pd->flags & IIC_FLAG_HAS_ICIC67) { | ||
234 | if ((num/denom) > 0xff) | ||
235 | pd->icic |= ICIC_ICCHB8; | ||
236 | else | ||
237 | pd->icic &= ~ICIC_ICCHB8; | ||
238 | } | ||
239 | |||
196 | /* Enable channel and configure rx ack */ | 240 | /* Enable channel and configure rx ack */ |
197 | iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); | 241 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); |
198 | 242 | ||
199 | /* Mask all interrupts */ | 243 | /* Mask all interrupts */ |
200 | iowrite8(0, ICIC(pd)); | 244 | iic_wr(pd, ICIC, 0); |
201 | 245 | ||
202 | /* Set the clock */ | 246 | /* Set the clock */ |
203 | iowrite8(pd->iccl, ICCL(pd)); | 247 | iic_wr(pd, ICCL, pd->iccl); |
204 | iowrite8(pd->icch, ICCH(pd)); | 248 | iic_wr(pd, ICCH, pd->icch); |
205 | } | 249 | } |
206 | 250 | ||
207 | static void deactivate_ch(struct sh_mobile_i2c_data *pd) | 251 | static void deactivate_ch(struct sh_mobile_i2c_data *pd) |
208 | { | 252 | { |
209 | /* Clear/disable interrupts */ | 253 | /* Clear/disable interrupts */ |
210 | iowrite8(0, ICSR(pd)); | 254 | iic_wr(pd, ICSR, 0); |
211 | iowrite8(0, ICIC(pd)); | 255 | iic_wr(pd, ICIC, 0); |
212 | 256 | ||
213 | /* Disable channel */ | 257 | /* Disable channel */ |
214 | iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); | 258 | iic_set_clr(pd, ICCR, 0, ICCR_ICE); |
215 | 259 | ||
216 | /* Disable clock */ | 260 | /* Disable clock and mark device as idle */ |
217 | clk_disable(pd->clk); | 261 | clk_disable(pd->clk); |
262 | pm_runtime_put_sync(pd->dev); | ||
218 | } | 263 | } |
219 | 264 | ||
220 | static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, | 265 | static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, |
@@ -229,35 +274,35 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, | |||
229 | 274 | ||
230 | switch (op) { | 275 | switch (op) { |
231 | case OP_START: /* issue start and trigger DTE interrupt */ | 276 | case OP_START: /* issue start and trigger DTE interrupt */ |
232 | iowrite8(0x94, ICCR(pd)); | 277 | iic_wr(pd, ICCR, 0x94); |
233 | break; | 278 | break; |
234 | case OP_TX_FIRST: /* disable DTE interrupt and write data */ | 279 | case OP_TX_FIRST: /* disable DTE interrupt and write data */ |
235 | iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE, ICIC(pd)); | 280 | iic_wr(pd, ICIC, ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
236 | iowrite8(data, ICDR(pd)); | 281 | iic_wr(pd, ICDR, data); |
237 | break; | 282 | break; |
238 | case OP_TX: /* write data */ | 283 | case OP_TX: /* write data */ |
239 | iowrite8(data, ICDR(pd)); | 284 | iic_wr(pd, ICDR, data); |
240 | break; | 285 | break; |
241 | case OP_TX_STOP: /* write data and issue a stop afterwards */ | 286 | case OP_TX_STOP: /* write data and issue a stop afterwards */ |
242 | iowrite8(data, ICDR(pd)); | 287 | iic_wr(pd, ICDR, data); |
243 | iowrite8(0x90, ICCR(pd)); | 288 | iic_wr(pd, ICCR, 0x90); |
244 | break; | 289 | break; |
245 | case OP_TX_TO_RX: /* select read mode */ | 290 | case OP_TX_TO_RX: /* select read mode */ |
246 | iowrite8(0x81, ICCR(pd)); | 291 | iic_wr(pd, ICCR, 0x81); |
247 | break; | 292 | break; |
248 | case OP_RX: /* just read data */ | 293 | case OP_RX: /* just read data */ |
249 | ret = ioread8(ICDR(pd)); | 294 | ret = iic_rd(pd, ICDR); |
250 | break; | 295 | break; |
251 | case OP_RX_STOP: /* enable DTE interrupt, issue stop */ | 296 | case OP_RX_STOP: /* enable DTE interrupt, issue stop */ |
252 | iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE, | 297 | iic_wr(pd, ICIC, |
253 | ICIC(pd)); | 298 | ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
254 | iowrite8(0xc0, ICCR(pd)); | 299 | iic_wr(pd, ICCR, 0xc0); |
255 | break; | 300 | break; |
256 | case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */ | 301 | case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */ |
257 | iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE, | 302 | iic_wr(pd, ICIC, |
258 | ICIC(pd)); | 303 | ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
259 | ret = ioread8(ICDR(pd)); | 304 | ret = iic_rd(pd, ICDR); |
260 | iowrite8(0xc0, ICCR(pd)); | 305 | iic_wr(pd, ICCR, 0xc0); |
261 | break; | 306 | break; |
262 | } | 307 | } |
263 | 308 | ||
@@ -363,7 +408,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id) | |||
363 | unsigned char sr; | 408 | unsigned char sr; |
364 | int wakeup; | 409 | int wakeup; |
365 | 410 | ||
366 | sr = ioread8(ICSR(pd)); | 411 | sr = iic_rd(pd, ICSR); |
367 | pd->sr |= sr; /* remember state */ | 412 | pd->sr |= sr; /* remember state */ |
368 | 413 | ||
369 | dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, | 414 | dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, |
@@ -372,7 +417,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id) | |||
372 | 417 | ||
373 | if (sr & (ICSR_AL | ICSR_TACK)) { | 418 | if (sr & (ICSR_AL | ICSR_TACK)) { |
374 | /* don't interrupt transaction - continue to issue stop */ | 419 | /* don't interrupt transaction - continue to issue stop */ |
375 | iowrite8(sr & ~(ICSR_AL | ICSR_TACK), ICSR(pd)); | 420 | iic_wr(pd, ICSR, sr & ~(ICSR_AL | ICSR_TACK)); |
376 | wakeup = 0; | 421 | wakeup = 0; |
377 | } else if (pd->msg->flags & I2C_M_RD) | 422 | } else if (pd->msg->flags & I2C_M_RD) |
378 | wakeup = sh_mobile_i2c_isr_rx(pd); | 423 | wakeup = sh_mobile_i2c_isr_rx(pd); |
@@ -380,7 +425,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id) | |||
380 | wakeup = sh_mobile_i2c_isr_tx(pd); | 425 | wakeup = sh_mobile_i2c_isr_tx(pd); |
381 | 426 | ||
382 | if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */ | 427 | if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */ |
383 | iowrite8(sr & ~ICSR_WAIT, ICSR(pd)); | 428 | iic_wr(pd, ICSR, sr & ~ICSR_WAIT); |
384 | 429 | ||
385 | if (wakeup) { | 430 | if (wakeup) { |
386 | pd->sr |= SW_DONE; | 431 | pd->sr |= SW_DONE; |
@@ -398,21 +443,21 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg) | |||
398 | } | 443 | } |
399 | 444 | ||
400 | /* Initialize channel registers */ | 445 | /* Initialize channel registers */ |
401 | iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); | 446 | iic_set_clr(pd, ICCR, 0, ICCR_ICE); |
402 | 447 | ||
403 | /* Enable channel and configure rx ack */ | 448 | /* Enable channel and configure rx ack */ |
404 | iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); | 449 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); |
405 | 450 | ||
406 | /* Set the clock */ | 451 | /* Set the clock */ |
407 | iowrite8(pd->iccl, ICCL(pd)); | 452 | iic_wr(pd, ICCL, pd->iccl); |
408 | iowrite8(pd->icch, ICCH(pd)); | 453 | iic_wr(pd, ICCH, pd->icch); |
409 | 454 | ||
410 | pd->msg = usr_msg; | 455 | pd->msg = usr_msg; |
411 | pd->pos = -1; | 456 | pd->pos = -1; |
412 | pd->sr = 0; | 457 | pd->sr = 0; |
413 | 458 | ||
414 | /* Enable all interrupts to begin with */ | 459 | /* Enable all interrupts to begin with */ |
415 | iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE | ICIC_DTEE, ICIC(pd)); | 460 | iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE); |
416 | return 0; | 461 | return 0; |
417 | } | 462 | } |
418 | 463 | ||
@@ -447,7 +492,7 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, | |||
447 | 492 | ||
448 | retry_count = 1000; | 493 | retry_count = 1000; |
449 | again: | 494 | again: |
450 | val = ioread8(ICSR(pd)); | 495 | val = iic_rd(pd, ICSR); |
451 | 496 | ||
452 | dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); | 497 | dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); |
453 | 498 | ||
@@ -493,15 +538,17 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) | |||
493 | { | 538 | { |
494 | struct resource *res; | 539 | struct resource *res; |
495 | int ret = -ENXIO; | 540 | int ret = -ENXIO; |
496 | int q, m; | 541 | int n, k = 0; |
497 | int k = 0; | ||
498 | int n = 0; | ||
499 | 542 | ||
500 | while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) { | 543 | while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) { |
501 | for (n = res->start; hook && n <= res->end; n++) { | 544 | for (n = res->start; hook && n <= res->end; n++) { |
502 | if (request_irq(n, sh_mobile_i2c_isr, IRQF_DISABLED, | 545 | if (request_irq(n, sh_mobile_i2c_isr, IRQF_DISABLED, |
503 | dev_name(&dev->dev), dev)) | 546 | dev_name(&dev->dev), dev)) { |
547 | for (n--; n >= res->start; n--) | ||
548 | free_irq(n, dev); | ||
549 | |||
504 | goto rollback; | 550 | goto rollback; |
551 | } | ||
505 | } | 552 | } |
506 | k++; | 553 | k++; |
507 | } | 554 | } |
@@ -509,16 +556,17 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) | |||
509 | if (hook) | 556 | if (hook) |
510 | return k > 0 ? 0 : -ENOENT; | 557 | return k > 0 ? 0 : -ENOENT; |
511 | 558 | ||
512 | k--; | ||
513 | ret = 0; | 559 | ret = 0; |
514 | 560 | ||
515 | rollback: | 561 | rollback: |
516 | for (q = k; k >= 0; k--) { | 562 | k--; |
517 | for (m = n; m >= res->start; m--) | ||
518 | free_irq(m, dev); | ||
519 | 563 | ||
520 | res = platform_get_resource(dev, IORESOURCE_IRQ, k - 1); | 564 | while (k >= 0) { |
521 | m = res->end; | 565 | res = platform_get_resource(dev, IORESOURCE_IRQ, k); |
566 | for (n = res->start; n <= res->end; n++) | ||
567 | free_irq(n, dev); | ||
568 | |||
569 | k--; | ||
522 | } | 570 | } |
523 | 571 | ||
524 | return ret; | 572 | return ret; |
@@ -563,7 +611,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
563 | goto err_irq; | 611 | goto err_irq; |
564 | } | 612 | } |
565 | 613 | ||
566 | size = (res->end - res->start) + 1; | 614 | size = resource_size(res); |
567 | 615 | ||
568 | pd->reg = ioremap(res->start, size); | 616 | pd->reg = ioremap(res->start, size); |
569 | if (pd->reg == NULL) { | 617 | if (pd->reg == NULL) { |
@@ -572,6 +620,25 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
572 | goto err_irq; | 620 | goto err_irq; |
573 | } | 621 | } |
574 | 622 | ||
623 | /* The IIC blocks on SH-Mobile ARM processors | ||
624 | * come with two new bits in ICIC. | ||
625 | */ | ||
626 | if (size > 0x17) | ||
627 | pd->flags |= IIC_FLAG_HAS_ICIC67; | ||
628 | |||
629 | /* Enable Runtime PM for this device. | ||
630 | * | ||
631 | * Also tell the Runtime PM core to ignore children | ||
632 | * for this device since it is valid for us to suspend | ||
633 | * this I2C master driver even though the slave devices | ||
634 | * on the I2C bus may not be suspended. | ||
635 | * | ||
636 | * The state of the I2C hardware bus is unaffected by | ||
637 | * the Runtime PM state. | ||
638 | */ | ||
639 | pm_suspend_ignore_children(&dev->dev, true); | ||
640 | pm_runtime_enable(&dev->dev); | ||
641 | |||
575 | /* setup the private data */ | 642 | /* setup the private data */ |
576 | adap = &pd->adap; | 643 | adap = &pd->adap; |
577 | i2c_set_adapdata(adap, pd); | 644 | i2c_set_adapdata(adap, pd); |
@@ -614,14 +681,33 @@ static int sh_mobile_i2c_remove(struct platform_device *dev) | |||
614 | iounmap(pd->reg); | 681 | iounmap(pd->reg); |
615 | sh_mobile_i2c_hook_irqs(dev, 0); | 682 | sh_mobile_i2c_hook_irqs(dev, 0); |
616 | clk_put(pd->clk); | 683 | clk_put(pd->clk); |
684 | pm_runtime_disable(&dev->dev); | ||
617 | kfree(pd); | 685 | kfree(pd); |
618 | return 0; | 686 | return 0; |
619 | } | 687 | } |
620 | 688 | ||
689 | static int sh_mobile_i2c_runtime_nop(struct device *dev) | ||
690 | { | ||
691 | /* Runtime PM callback shared between ->runtime_suspend() | ||
692 | * and ->runtime_resume(). Simply returns success. | ||
693 | * | ||
694 | * This driver re-initializes all registers after | ||
695 | * pm_runtime_get_sync() anyway so there is no need | ||
696 | * to save and restore registers here. | ||
697 | */ | ||
698 | return 0; | ||
699 | } | ||
700 | |||
701 | static const struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = { | ||
702 | .runtime_suspend = sh_mobile_i2c_runtime_nop, | ||
703 | .runtime_resume = sh_mobile_i2c_runtime_nop, | ||
704 | }; | ||
705 | |||
621 | static struct platform_driver sh_mobile_i2c_driver = { | 706 | static struct platform_driver sh_mobile_i2c_driver = { |
622 | .driver = { | 707 | .driver = { |
623 | .name = "i2c-sh_mobile", | 708 | .name = "i2c-sh_mobile", |
624 | .owner = THIS_MODULE, | 709 | .owner = THIS_MODULE, |
710 | .pm = &sh_mobile_i2c_dev_pm_ops, | ||
625 | }, | 711 | }, |
626 | .probe = sh_mobile_i2c_probe, | 712 | .probe = sh_mobile_i2c_probe, |
627 | .remove = sh_mobile_i2c_remove, | 713 | .remove = sh_mobile_i2c_remove, |
@@ -637,7 +723,7 @@ static void __exit sh_mobile_i2c_adap_exit(void) | |||
637 | platform_driver_unregister(&sh_mobile_i2c_driver); | 723 | platform_driver_unregister(&sh_mobile_i2c_driver); |
638 | } | 724 | } |
639 | 725 | ||
640 | module_init(sh_mobile_i2c_adap_init); | 726 | subsys_initcall(sh_mobile_i2c_adap_init); |
641 | module_exit(sh_mobile_i2c_adap_exit); | 727 | module_exit(sh_mobile_i2c_adap_exit); |
642 | 728 | ||
643 | MODULE_DESCRIPTION("SuperH Mobile I2C Bus Controller driver"); | 729 | MODULE_DESCRIPTION("SuperH Mobile I2C Bus Controller driver"); |
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c index 98b1ec489159..0fe505d7abe9 100644 --- a/drivers/i2c/busses/i2c-sibyte.c +++ b/drivers/i2c/busses/i2c-sibyte.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <asm/io.h> | 25 | #include <linux/io.h> |
26 | #include <asm/sibyte/sb1250_regs.h> | 26 | #include <asm/sibyte/sb1250_regs.h> |
27 | #include <asm/sibyte/sb1250_smbus.h> | 27 | #include <asm/sibyte/sb1250_smbus.h> |
28 | 28 | ||
@@ -94,7 +94,7 @@ static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, | |||
94 | } | 94 | } |
95 | break; | 95 | break; |
96 | default: | 96 | default: |
97 | return -1; /* XXXKW better error code? */ | 97 | return -EOPNOTSUPP; |
98 | } | 98 | } |
99 | 99 | ||
100 | while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY) | 100 | while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY) |
@@ -104,7 +104,7 @@ static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, | |||
104 | if (error & M_SMB_ERROR) { | 104 | if (error & M_SMB_ERROR) { |
105 | /* Clear error bit by writing a 1 */ | 105 | /* Clear error bit by writing a 1 */ |
106 | csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS)); | 106 | csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS)); |
107 | return -1; /* XXXKW better error code? */ | 107 | return (error & M_SMB_ERROR_TYPE) ? -EIO : -ENXIO; |
108 | } | 108 | } |
109 | 109 | ||
110 | if (data_bytes == 1) | 110 | if (data_bytes == 1) |
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c index 042fda295f3a..2fc08fbf67a2 100644 --- a/drivers/i2c/busses/i2c-simtec.c +++ b/drivers/i2c/busses/i2c-simtec.c | |||
@@ -23,12 +23,12 @@ | |||
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
25 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
26 | #include <linux/slab.h> | ||
27 | #include <linux/io.h> | ||
26 | 28 | ||
27 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
28 | #include <linux/i2c-algo-bit.h> | 30 | #include <linux/i2c-algo-bit.h> |
29 | 31 | ||
30 | #include <asm/io.h> | ||
31 | |||
32 | struct simtec_i2c_data { | 32 | struct simtec_i2c_data { |
33 | struct resource *ioarea; | 33 | struct resource *ioarea; |
34 | void __iomem *reg; | 34 | void __iomem *reg; |
@@ -92,7 +92,7 @@ static int simtec_i2c_probe(struct platform_device *dev) | |||
92 | goto err; | 92 | goto err; |
93 | } | 93 | } |
94 | 94 | ||
95 | size = (res->end-res->start)+1; | 95 | size = resource_size(res); |
96 | 96 | ||
97 | pd->ioarea = request_mem_region(res->start, size, dev->name); | 97 | pd->ioarea = request_mem_region(res->start, size, dev->name); |
98 | if (pd->ioarea == NULL) { | 98 | if (pd->ioarea == NULL) { |
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c index 139f0c7f12a4..437586611d4a 100644 --- a/drivers/i2c/busses/i2c-sis5595.c +++ b/drivers/i2c/busses/i2c-sis5595.c | |||
@@ -61,7 +61,7 @@ | |||
61 | #include <linux/init.h> | 61 | #include <linux/init.h> |
62 | #include <linux/i2c.h> | 62 | #include <linux/i2c.h> |
63 | #include <linux/acpi.h> | 63 | #include <linux/acpi.h> |
64 | #include <asm/io.h> | 64 | #include <linux/io.h> |
65 | 65 | ||
66 | static int blacklist[] = { | 66 | static int blacklist[] = { |
67 | PCI_DEVICE_ID_SI_540, | 67 | PCI_DEVICE_ID_SI_540, |
@@ -142,7 +142,7 @@ static void sis5595_write(u8 reg, u8 data) | |||
142 | outb(data, sis5595_base + SMB_DAT); | 142 | outb(data, sis5595_base + SMB_DAT); |
143 | } | 143 | } |
144 | 144 | ||
145 | static int sis5595_setup(struct pci_dev *SIS5595_dev) | 145 | static int __devinit sis5595_setup(struct pci_dev *SIS5595_dev) |
146 | { | 146 | { |
147 | u16 a; | 147 | u16 a; |
148 | u8 val; | 148 | u8 val; |
@@ -369,7 +369,7 @@ static struct i2c_adapter sis5595_adapter = { | |||
369 | .algo = &smbus_algorithm, | 369 | .algo = &smbus_algorithm, |
370 | }; | 370 | }; |
371 | 371 | ||
372 | static struct pci_device_id sis5595_ids[] __devinitdata = { | 372 | static const struct pci_device_id sis5595_ids[] __devinitconst = { |
373 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, | 373 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, |
374 | { 0, } | 374 | { 0, } |
375 | }; | 375 | }; |
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c index 70ca41e90e58..e6f539e26f65 100644 --- a/drivers/i2c/busses/i2c-sis630.c +++ b/drivers/i2c/busses/i2c-sis630.c | |||
@@ -53,7 +53,7 @@ | |||
53 | #include <linux/init.h> | 53 | #include <linux/init.h> |
54 | #include <linux/i2c.h> | 54 | #include <linux/i2c.h> |
55 | #include <linux/acpi.h> | 55 | #include <linux/acpi.h> |
56 | #include <asm/io.h> | 56 | #include <linux/io.h> |
57 | 57 | ||
58 | /* SIS630 SMBus registers */ | 58 | /* SIS630 SMBus registers */ |
59 | #define SMB_STS 0x80 /* status */ | 59 | #define SMB_STS 0x80 /* status */ |
@@ -389,7 +389,7 @@ static u32 sis630_func(struct i2c_adapter *adapter) | |||
389 | I2C_FUNC_SMBUS_BLOCK_DATA; | 389 | I2C_FUNC_SMBUS_BLOCK_DATA; |
390 | } | 390 | } |
391 | 391 | ||
392 | static int sis630_setup(struct pci_dev *sis630_dev) | 392 | static int __devinit sis630_setup(struct pci_dev *sis630_dev) |
393 | { | 393 | { |
394 | unsigned char b; | 394 | unsigned char b; |
395 | struct pci_dev *dummy = NULL; | 395 | struct pci_dev *dummy = NULL; |
@@ -468,7 +468,7 @@ static struct i2c_adapter sis630_adapter = { | |||
468 | .algo = &smbus_algorithm, | 468 | .algo = &smbus_algorithm, |
469 | }; | 469 | }; |
470 | 470 | ||
471 | static struct pci_device_id sis630_ids[] __devinitdata = { | 471 | static const struct pci_device_id sis630_ids[] __devinitconst = { |
472 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, | 472 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, |
473 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, | 473 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, |
474 | { 0, } | 474 | { 0, } |
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c index 8295885b2fdb..86837f0c4cb9 100644 --- a/drivers/i2c/busses/i2c-sis96x.c +++ b/drivers/i2c/busses/i2c-sis96x.c | |||
@@ -38,7 +38,7 @@ | |||
38 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
39 | #include <linux/init.h> | 39 | #include <linux/init.h> |
40 | #include <linux/acpi.h> | 40 | #include <linux/acpi.h> |
41 | #include <asm/io.h> | 41 | #include <linux/io.h> |
42 | 42 | ||
43 | /* base address register in PCI config space */ | 43 | /* base address register in PCI config space */ |
44 | #define SIS96x_BAR 0x04 | 44 | #define SIS96x_BAR 0x04 |
@@ -245,7 +245,7 @@ static struct i2c_adapter sis96x_adapter = { | |||
245 | .algo = &smbus_algorithm, | 245 | .algo = &smbus_algorithm, |
246 | }; | 246 | }; |
247 | 247 | ||
248 | static struct pci_device_id sis96x_ids[] = { | 248 | static const struct pci_device_id sis96x_ids[] = { |
249 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) }, | 249 | { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) }, |
250 | { 0, } | 250 | { 0, } |
251 | }; | 251 | }; |
@@ -280,7 +280,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev, | |||
280 | 280 | ||
281 | retval = acpi_check_resource_conflict(&dev->resource[SIS96x_BAR]); | 281 | retval = acpi_check_resource_conflict(&dev->resource[SIS96x_BAR]); |
282 | if (retval) | 282 | if (retval) |
283 | return retval; | 283 | return -ENODEV; |
284 | 284 | ||
285 | /* Everything is happy, let's grab the memory and set things up. */ | 285 | /* Everything is happy, let's grab the memory and set things up. */ |
286 | if (!request_region(sis96x_smbus_base, SMB_IOSIZE, | 286 | if (!request_region(sis96x_smbus_base, SMB_IOSIZE, |
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c index 182e711318ba..495be451d326 100644 --- a/drivers/i2c/busses/i2c-stu300.c +++ b/drivers/i2c/busses/i2c-stu300.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/clk.h> | 17 | #include <linux/clk.h> |
18 | #include <linux/io.h> | 18 | #include <linux/io.h> |
19 | #include <linux/slab.h> | ||
19 | 20 | ||
20 | /* the name of this kernel module */ | 21 | /* the name of this kernel module */ |
21 | #define NAME "stu300" | 22 | #define NAME "stu300" |
@@ -117,7 +118,8 @@ enum stu300_error { | |||
117 | STU300_ERROR_NONE = 0, | 118 | STU300_ERROR_NONE = 0, |
118 | STU300_ERROR_ACKNOWLEDGE_FAILURE, | 119 | STU300_ERROR_ACKNOWLEDGE_FAILURE, |
119 | STU300_ERROR_BUS_ERROR, | 120 | STU300_ERROR_BUS_ERROR, |
120 | STU300_ERROR_ARBITRATION_LOST | 121 | STU300_ERROR_ARBITRATION_LOST, |
122 | STU300_ERROR_UNKNOWN | ||
121 | }; | 123 | }; |
122 | 124 | ||
123 | /* timeout waiting for the controller to respond */ | 125 | /* timeout waiting for the controller to respond */ |
@@ -127,7 +129,7 @@ enum stu300_error { | |||
127 | * The number of address send athemps tried before giving up. | 129 | * The number of address send athemps tried before giving up. |
128 | * If the first one failes it seems like 5 to 8 attempts are required. | 130 | * If the first one failes it seems like 5 to 8 attempts are required. |
129 | */ | 131 | */ |
130 | #define NUM_ADDR_RESEND_ATTEMPTS 10 | 132 | #define NUM_ADDR_RESEND_ATTEMPTS 12 |
131 | 133 | ||
132 | /* I2C clock speed, in Hz 0-400kHz*/ | 134 | /* I2C clock speed, in Hz 0-400kHz*/ |
133 | static unsigned int scl_frequency = 100000; | 135 | static unsigned int scl_frequency = 100000; |
@@ -149,6 +151,7 @@ module_param(scl_frequency, uint, 0644); | |||
149 | * @msg_index: index of current message | 151 | * @msg_index: index of current message |
150 | * @msg_len: length of current message | 152 | * @msg_len: length of current message |
151 | */ | 153 | */ |
154 | |||
152 | struct stu300_dev { | 155 | struct stu300_dev { |
153 | struct platform_device *pdev; | 156 | struct platform_device *pdev; |
154 | struct i2c_adapter adapter; | 157 | struct i2c_adapter adapter; |
@@ -188,6 +191,27 @@ static inline u32 stu300_r8(void __iomem *address) | |||
188 | return readl(address) & 0x000000FFU; | 191 | return readl(address) & 0x000000FFU; |
189 | } | 192 | } |
190 | 193 | ||
194 | static void stu300_irq_enable(struct stu300_dev *dev) | ||
195 | { | ||
196 | u32 val; | ||
197 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
198 | val |= I2C_CR_INTERRUPT_ENABLE; | ||
199 | /* Twice paranoia (possible HW glitch) */ | ||
200 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
201 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
202 | } | ||
203 | |||
204 | static void stu300_irq_disable(struct stu300_dev *dev) | ||
205 | { | ||
206 | u32 val; | ||
207 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
208 | val &= ~I2C_CR_INTERRUPT_ENABLE; | ||
209 | /* Twice paranoia (possible HW glitch) */ | ||
210 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
211 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
212 | } | ||
213 | |||
214 | |||
191 | /* | 215 | /* |
192 | * Tells whether a certain event or events occurred in | 216 | * Tells whether a certain event or events occurred in |
193 | * response to a command. The events represent states in | 217 | * response to a command. The events represent states in |
@@ -196,9 +220,10 @@ static inline u32 stu300_r8(void __iomem *address) | |||
196 | * documentation and can only be treated as abstract state | 220 | * documentation and can only be treated as abstract state |
197 | * machine states. | 221 | * machine states. |
198 | * | 222 | * |
199 | * @ret 0 = event has not occurred, any other value means | 223 | * @ret 0 = event has not occurred or unknown error, any |
200 | * the event occurred. | 224 | * other value means the correct event occurred or an error. |
201 | */ | 225 | */ |
226 | |||
202 | static int stu300_event_occurred(struct stu300_dev *dev, | 227 | static int stu300_event_occurred(struct stu300_dev *dev, |
203 | enum stu300_event mr_event) { | 228 | enum stu300_event mr_event) { |
204 | u32 status1; | 229 | u32 status1; |
@@ -206,11 +231,28 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
206 | 231 | ||
207 | /* What event happened? */ | 232 | /* What event happened? */ |
208 | status1 = stu300_r8(dev->virtbase + I2C_SR1); | 233 | status1 = stu300_r8(dev->virtbase + I2C_SR1); |
234 | |||
209 | if (!(status1 & I2C_SR1_EVF_IND)) | 235 | if (!(status1 & I2C_SR1_EVF_IND)) |
210 | /* No event at all */ | 236 | /* No event at all */ |
211 | return 0; | 237 | return 0; |
238 | |||
212 | status2 = stu300_r8(dev->virtbase + I2C_SR2); | 239 | status2 = stu300_r8(dev->virtbase + I2C_SR2); |
213 | 240 | ||
241 | /* Block any multiple interrupts */ | ||
242 | stu300_irq_disable(dev); | ||
243 | |||
244 | /* Check for errors first */ | ||
245 | if (status2 & I2C_SR2_AF_IND) { | ||
246 | dev->cmd_err = STU300_ERROR_ACKNOWLEDGE_FAILURE; | ||
247 | return 1; | ||
248 | } else if (status2 & I2C_SR2_BERR_IND) { | ||
249 | dev->cmd_err = STU300_ERROR_BUS_ERROR; | ||
250 | return 1; | ||
251 | } else if (status2 & I2C_SR2_ARLO_IND) { | ||
252 | dev->cmd_err = STU300_ERROR_ARBITRATION_LOST; | ||
253 | return 1; | ||
254 | } | ||
255 | |||
214 | switch (mr_event) { | 256 | switch (mr_event) { |
215 | case STU300_EVENT_1: | 257 | case STU300_EVENT_1: |
216 | if (status1 & I2C_SR1_ADSL_IND) | 258 | if (status1 & I2C_SR1_ADSL_IND) |
@@ -221,10 +263,6 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
221 | case STU300_EVENT_7: | 263 | case STU300_EVENT_7: |
222 | case STU300_EVENT_8: | 264 | case STU300_EVENT_8: |
223 | if (status1 & I2C_SR1_BTF_IND) { | 265 | if (status1 & I2C_SR1_BTF_IND) { |
224 | if (status2 & I2C_SR2_AF_IND) | ||
225 | dev->cmd_err = STU300_ERROR_ACKNOWLEDGE_FAILURE; | ||
226 | else if (status2 & I2C_SR2_BERR_IND) | ||
227 | dev->cmd_err = STU300_ERROR_BUS_ERROR; | ||
228 | return 1; | 266 | return 1; |
229 | } | 267 | } |
230 | break; | 268 | break; |
@@ -240,8 +278,6 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
240 | case STU300_EVENT_6: | 278 | case STU300_EVENT_6: |
241 | if (status2 & I2C_SR2_ENDAD_IND) { | 279 | if (status2 & I2C_SR2_ENDAD_IND) { |
242 | /* First check for any errors */ | 280 | /* First check for any errors */ |
243 | if (status2 & I2C_SR2_AF_IND) | ||
244 | dev->cmd_err = STU300_ERROR_ACKNOWLEDGE_FAILURE; | ||
245 | return 1; | 281 | return 1; |
246 | } | 282 | } |
247 | break; | 283 | break; |
@@ -252,8 +288,15 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
252 | default: | 288 | default: |
253 | break; | 289 | break; |
254 | } | 290 | } |
255 | if (status2 & I2C_SR2_ARLO_IND) | 291 | /* If we get here, we're on thin ice. |
256 | dev->cmd_err = STU300_ERROR_ARBITRATION_LOST; | 292 | * Here we are in a status where we have |
293 | * gotten a response that does not match | ||
294 | * what we requested. | ||
295 | */ | ||
296 | dev->cmd_err = STU300_ERROR_UNKNOWN; | ||
297 | dev_err(&dev->pdev->dev, | ||
298 | "Unhandled interrupt! %d sr1: 0x%x sr2: 0x%x\n", | ||
299 | mr_event, status1, status2); | ||
257 | return 0; | 300 | return 0; |
258 | } | 301 | } |
259 | 302 | ||
@@ -262,21 +305,20 @@ static irqreturn_t stu300_irh(int irq, void *data) | |||
262 | struct stu300_dev *dev = data; | 305 | struct stu300_dev *dev = data; |
263 | int res; | 306 | int res; |
264 | 307 | ||
308 | /* Just make sure that the block is clocked */ | ||
309 | clk_enable(dev->clk); | ||
310 | |||
265 | /* See if this was what we were waiting for */ | 311 | /* See if this was what we were waiting for */ |
266 | spin_lock(&dev->cmd_issue_lock); | 312 | spin_lock(&dev->cmd_issue_lock); |
267 | if (dev->cmd_event != STU300_EVENT_NONE) { | 313 | |
268 | res = stu300_event_occurred(dev, dev->cmd_event); | 314 | res = stu300_event_occurred(dev, dev->cmd_event); |
269 | if (res || dev->cmd_err != STU300_ERROR_NONE) { | 315 | if (res || dev->cmd_err != STU300_ERROR_NONE) |
270 | u32 val; | 316 | complete(&dev->cmd_complete); |
271 | 317 | ||
272 | complete(&dev->cmd_complete); | ||
273 | /* Block any multiple interrupts */ | ||
274 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
275 | val &= ~I2C_CR_INTERRUPT_ENABLE; | ||
276 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
277 | } | ||
278 | } | ||
279 | spin_unlock(&dev->cmd_issue_lock); | 318 | spin_unlock(&dev->cmd_issue_lock); |
319 | |||
320 | clk_disable(dev->clk); | ||
321 | |||
280 | return IRQ_HANDLED; | 322 | return IRQ_HANDLED; |
281 | } | 323 | } |
282 | 324 | ||
@@ -308,7 +350,6 @@ static int stu300_start_and_await_event(struct stu300_dev *dev, | |||
308 | stu300_wr8(cr_value, dev->virtbase + I2C_CR); | 350 | stu300_wr8(cr_value, dev->virtbase + I2C_CR); |
309 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, | 351 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, |
310 | STU300_TIMEOUT); | 352 | STU300_TIMEOUT); |
311 | |||
312 | if (ret < 0) { | 353 | if (ret < 0) { |
313 | dev_err(&dev->pdev->dev, | 354 | dev_err(&dev->pdev->dev, |
314 | "wait_for_completion_interruptible_timeout() " | 355 | "wait_for_completion_interruptible_timeout() " |
@@ -342,7 +383,6 @@ static int stu300_await_event(struct stu300_dev *dev, | |||
342 | enum stu300_event mr_event) | 383 | enum stu300_event mr_event) |
343 | { | 384 | { |
344 | int ret; | 385 | int ret; |
345 | u32 val; | ||
346 | 386 | ||
347 | if (unlikely(irqs_disabled())) { | 387 | if (unlikely(irqs_disabled())) { |
348 | /* TODO: implement polling for this case if need be. */ | 388 | /* TODO: implement polling for this case if need be. */ |
@@ -354,36 +394,18 @@ static int stu300_await_event(struct stu300_dev *dev, | |||
354 | /* Is it already here? */ | 394 | /* Is it already here? */ |
355 | spin_lock_irq(&dev->cmd_issue_lock); | 395 | spin_lock_irq(&dev->cmd_issue_lock); |
356 | dev->cmd_err = STU300_ERROR_NONE; | 396 | dev->cmd_err = STU300_ERROR_NONE; |
357 | if (stu300_event_occurred(dev, mr_event)) { | ||
358 | spin_unlock_irq(&dev->cmd_issue_lock); | ||
359 | goto exit_await_check_err; | ||
360 | } | ||
361 | init_completion(&dev->cmd_complete); | ||
362 | dev->cmd_err = STU300_ERROR_NONE; | ||
363 | dev->cmd_event = mr_event; | 397 | dev->cmd_event = mr_event; |
364 | 398 | ||
365 | /* Turn on the I2C interrupt for current operation */ | 399 | init_completion(&dev->cmd_complete); |
366 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
367 | val |= I2C_CR_INTERRUPT_ENABLE; | ||
368 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
369 | |||
370 | /* Twice paranoia (possible HW glitch) */ | ||
371 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
372 | 400 | ||
373 | /* Check again: is it already here? */ | 401 | /* Turn on the I2C interrupt for current operation */ |
374 | if (unlikely(stu300_event_occurred(dev, mr_event))) { | 402 | stu300_irq_enable(dev); |
375 | /* Disable IRQ again. */ | ||
376 | val &= ~I2C_CR_INTERRUPT_ENABLE; | ||
377 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
378 | spin_unlock_irq(&dev->cmd_issue_lock); | ||
379 | goto exit_await_check_err; | ||
380 | } | ||
381 | 403 | ||
382 | /* Unlock the command block and wait for the event to occur */ | 404 | /* Unlock the command block and wait for the event to occur */ |
383 | spin_unlock_irq(&dev->cmd_issue_lock); | 405 | spin_unlock_irq(&dev->cmd_issue_lock); |
406 | |||
384 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, | 407 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, |
385 | STU300_TIMEOUT); | 408 | STU300_TIMEOUT); |
386 | |||
387 | if (ret < 0) { | 409 | if (ret < 0) { |
388 | dev_err(&dev->pdev->dev, | 410 | dev_err(&dev->pdev->dev, |
389 | "wait_for_completion_interruptible_timeout()" | 411 | "wait_for_completion_interruptible_timeout()" |
@@ -401,7 +423,6 @@ static int stu300_await_event(struct stu300_dev *dev, | |||
401 | return -ETIMEDOUT; | 423 | return -ETIMEDOUT; |
402 | } | 424 | } |
403 | 425 | ||
404 | exit_await_check_err: | ||
405 | if (dev->cmd_err != STU300_ERROR_NONE) { | 426 | if (dev->cmd_err != STU300_ERROR_NONE) { |
406 | if (mr_event != STU300_EVENT_6) { | 427 | if (mr_event != STU300_EVENT_6) { |
407 | dev_err(&dev->pdev->dev, "controller " | 428 | dev_err(&dev->pdev->dev, "controller " |
@@ -457,18 +478,19 @@ struct stu300_clkset { | |||
457 | }; | 478 | }; |
458 | 479 | ||
459 | static const struct stu300_clkset stu300_clktable[] = { | 480 | static const struct stu300_clkset stu300_clktable[] = { |
460 | { 0, 0xFFU }, | 481 | { 0, 0xFFU }, |
461 | { 2500000, I2C_OAR2_FR_25_10MHZ }, | 482 | { 2500000, I2C_OAR2_FR_25_10MHZ }, |
462 | { 10000000, I2C_OAR2_FR_10_1667MHZ }, | 483 | { 10000000, I2C_OAR2_FR_10_1667MHZ }, |
463 | { 16670000, I2C_OAR2_FR_1667_2667MHZ }, | 484 | { 16670000, I2C_OAR2_FR_1667_2667MHZ }, |
464 | { 26670000, I2C_OAR2_FR_2667_40MHZ }, | 485 | { 26670000, I2C_OAR2_FR_2667_40MHZ }, |
465 | { 40000000, I2C_OAR2_FR_40_5333MHZ }, | 486 | { 40000000, I2C_OAR2_FR_40_5333MHZ }, |
466 | { 53330000, I2C_OAR2_FR_5333_66MHZ }, | 487 | { 53330000, I2C_OAR2_FR_5333_66MHZ }, |
467 | { 66000000, I2C_OAR2_FR_66_80MHZ }, | 488 | { 66000000, I2C_OAR2_FR_66_80MHZ }, |
468 | { 80000000, I2C_OAR2_FR_80_100MHZ }, | 489 | { 80000000, I2C_OAR2_FR_80_100MHZ }, |
469 | { 100000000, 0xFFU }, | 490 | { 100000000, 0xFFU }, |
470 | }; | 491 | }; |
471 | 492 | ||
493 | |||
472 | static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) | 494 | static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) |
473 | { | 495 | { |
474 | 496 | ||
@@ -476,7 +498,7 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) | |||
476 | int i = 0; | 498 | int i = 0; |
477 | 499 | ||
478 | /* Locate the apropriate clock setting */ | 500 | /* Locate the apropriate clock setting */ |
479 | while (i < ARRAY_SIZE(stu300_clktable) && | 501 | while (i < ARRAY_SIZE(stu300_clktable) - 1 && |
480 | stu300_clktable[i].rate < clkrate) | 502 | stu300_clktable[i].rate < clkrate) |
481 | i++; | 503 | i++; |
482 | 504 | ||
@@ -494,10 +516,10 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) | |||
494 | 516 | ||
495 | if (dev->speed > 100000) | 517 | if (dev->speed > 100000) |
496 | /* Fast Mode I2C */ | 518 | /* Fast Mode I2C */ |
497 | val = ((clkrate/dev->speed)-9)/3; | 519 | val = ((clkrate/dev->speed) - 9)/3 + 1; |
498 | else | 520 | else |
499 | /* Standard Mode I2C */ | 521 | /* Standard Mode I2C */ |
500 | val = ((clkrate/dev->speed)-7)/2; | 522 | val = ((clkrate/dev->speed) - 7)/2 + 1; |
501 | 523 | ||
502 | /* According to spec the divider must be > 2 */ | 524 | /* According to spec the divider must be > 2 */ |
503 | if (val < 0x002) { | 525 | if (val < 0x002) { |
@@ -557,6 +579,7 @@ static int stu300_init_hw(struct stu300_dev *dev) | |||
557 | */ | 579 | */ |
558 | clkrate = clk_get_rate(dev->clk); | 580 | clkrate = clk_get_rate(dev->clk); |
559 | ret = stu300_set_clk(dev, clkrate); | 581 | ret = stu300_set_clk(dev, clkrate); |
582 | |||
560 | if (ret) | 583 | if (ret) |
561 | return ret; | 584 | return ret; |
562 | /* | 585 | /* |
@@ -641,7 +664,6 @@ static int stu300_xfer_msg(struct i2c_adapter *adap, | |||
641 | int attempts = 0; | 664 | int attempts = 0; |
642 | struct stu300_dev *dev = i2c_get_adapdata(adap); | 665 | struct stu300_dev *dev = i2c_get_adapdata(adap); |
643 | 666 | ||
644 | |||
645 | clk_enable(dev->clk); | 667 | clk_enable(dev->clk); |
646 | 668 | ||
647 | /* Remove this if (0) to trace each and every message. */ | 669 | /* Remove this if (0) to trace each and every message. */ |
@@ -715,14 +737,15 @@ static int stu300_xfer_msg(struct i2c_adapter *adap, | |||
715 | 737 | ||
716 | if (attempts < NUM_ADDR_RESEND_ATTEMPTS && attempts > 0) { | 738 | if (attempts < NUM_ADDR_RESEND_ATTEMPTS && attempts > 0) { |
717 | dev_dbg(&dev->pdev->dev, "managed to get address " | 739 | dev_dbg(&dev->pdev->dev, "managed to get address " |
718 | "through after %d attempts\n", attempts); | 740 | "through after %d attempts\n", attempts); |
719 | } else if (attempts == NUM_ADDR_RESEND_ATTEMPTS) { | 741 | } else if (attempts == NUM_ADDR_RESEND_ATTEMPTS) { |
720 | dev_dbg(&dev->pdev->dev, "I give up, tried %d times " | 742 | dev_dbg(&dev->pdev->dev, "I give up, tried %d times " |
721 | "to resend address.\n", | 743 | "to resend address.\n", |
722 | NUM_ADDR_RESEND_ATTEMPTS); | 744 | NUM_ADDR_RESEND_ATTEMPTS); |
723 | goto exit_disable; | 745 | goto exit_disable; |
724 | } | 746 | } |
725 | 747 | ||
748 | |||
726 | if (msg->flags & I2C_M_RD) { | 749 | if (msg->flags & I2C_M_RD) { |
727 | /* READ: we read the actual bytes one at a time */ | 750 | /* READ: we read the actual bytes one at a time */ |
728 | for (i = 0; i < msg->len; i++) { | 751 | for (i = 0; i < msg->len; i++) { |
@@ -804,8 +827,10 @@ static int stu300_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, | |||
804 | { | 827 | { |
805 | int ret = -1; | 828 | int ret = -1; |
806 | int i; | 829 | int i; |
830 | |||
807 | struct stu300_dev *dev = i2c_get_adapdata(adap); | 831 | struct stu300_dev *dev = i2c_get_adapdata(adap); |
808 | dev->msg_len = num; | 832 | dev->msg_len = num; |
833 | |||
809 | for (i = 0; i < num; i++) { | 834 | for (i = 0; i < num; i++) { |
810 | /* | 835 | /* |
811 | * Another driver appears to send stop for each message, | 836 | * Another driver appears to send stop for each message, |
@@ -817,6 +842,7 @@ static int stu300_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, | |||
817 | dev->msg_index = i; | 842 | dev->msg_index = i; |
818 | 843 | ||
819 | ret = stu300_xfer_msg(adap, &msgs[i], (i == (num - 1))); | 844 | ret = stu300_xfer_msg(adap, &msgs[i], (i == (num - 1))); |
845 | |||
820 | if (ret != 0) { | 846 | if (ret != 0) { |
821 | num = ret; | 847 | num = ret; |
822 | break; | 848 | break; |
@@ -845,6 +871,7 @@ stu300_probe(struct platform_device *pdev) | |||
845 | struct resource *res; | 871 | struct resource *res; |
846 | int bus_nr; | 872 | int bus_nr; |
847 | int ret = 0; | 873 | int ret = 0; |
874 | char clk_name[] = "I2C0"; | ||
848 | 875 | ||
849 | dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL); | 876 | dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL); |
850 | if (!dev) { | 877 | if (!dev) { |
@@ -854,7 +881,8 @@ stu300_probe(struct platform_device *pdev) | |||
854 | } | 881 | } |
855 | 882 | ||
856 | bus_nr = pdev->id; | 883 | bus_nr = pdev->id; |
857 | dev->clk = clk_get(&pdev->dev, NULL); | 884 | clk_name[3] += (char)bus_nr; |
885 | dev->clk = clk_get(&pdev->dev, clk_name); | ||
858 | if (IS_ERR(dev->clk)) { | 886 | if (IS_ERR(dev->clk)) { |
859 | ret = PTR_ERR(dev->clk); | 887 | ret = PTR_ERR(dev->clk); |
860 | dev_err(&pdev->dev, "could not retrieve i2c bus clock\n"); | 888 | dev_err(&pdev->dev, "could not retrieve i2c bus clock\n"); |
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c index 1b7b2af94036..b1b3447942c9 100644 --- a/drivers/i2c/busses/i2c-stub.c +++ b/drivers/i2c/busses/i2c-stub.c | |||
@@ -29,12 +29,19 @@ | |||
29 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
30 | 30 | ||
31 | #define MAX_CHIPS 10 | 31 | #define MAX_CHIPS 10 |
32 | #define STUB_FUNC (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | \ | ||
33 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | \ | ||
34 | I2C_FUNC_SMBUS_I2C_BLOCK) | ||
32 | 35 | ||
33 | static unsigned short chip_addr[MAX_CHIPS]; | 36 | static unsigned short chip_addr[MAX_CHIPS]; |
34 | module_param_array(chip_addr, ushort, NULL, S_IRUGO); | 37 | module_param_array(chip_addr, ushort, NULL, S_IRUGO); |
35 | MODULE_PARM_DESC(chip_addr, | 38 | MODULE_PARM_DESC(chip_addr, |
36 | "Chip addresses (up to 10, between 0x03 and 0x77)"); | 39 | "Chip addresses (up to 10, between 0x03 and 0x77)"); |
37 | 40 | ||
41 | static unsigned long functionality = STUB_FUNC; | ||
42 | module_param(functionality, ulong, S_IRUGO | S_IWUSR); | ||
43 | MODULE_PARM_DESC(functionality, "Override functionality bitfield"); | ||
44 | |||
38 | struct stub_chip { | 45 | struct stub_chip { |
39 | u8 pointer; | 46 | u8 pointer; |
40 | u16 words[256]; /* Byte operations use the LSB as per SMBus | 47 | u16 words[256]; /* Byte operations use the LSB as per SMBus |
@@ -48,7 +55,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |||
48 | char read_write, u8 command, int size, union i2c_smbus_data * data) | 55 | char read_write, u8 command, int size, union i2c_smbus_data * data) |
49 | { | 56 | { |
50 | s32 ret; | 57 | s32 ret; |
51 | int i; | 58 | int i, len; |
52 | struct stub_chip *chip = NULL; | 59 | struct stub_chip *chip = NULL; |
53 | 60 | ||
54 | /* Search for the right chip */ | 61 | /* Search for the right chip */ |
@@ -118,6 +125,29 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |||
118 | ret = 0; | 125 | ret = 0; |
119 | break; | 126 | break; |
120 | 127 | ||
128 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
129 | len = data->block[0]; | ||
130 | if (read_write == I2C_SMBUS_WRITE) { | ||
131 | for (i = 0; i < len; i++) { | ||
132 | chip->words[command + i] &= 0xff00; | ||
133 | chip->words[command + i] |= data->block[1 + i]; | ||
134 | } | ||
135 | dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, " | ||
136 | "wrote %d bytes at 0x%02x.\n", | ||
137 | addr, len, command); | ||
138 | } else { | ||
139 | for (i = 0; i < len; i++) { | ||
140 | data->block[1 + i] = | ||
141 | chip->words[command + i] & 0xff; | ||
142 | } | ||
143 | dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, " | ||
144 | "read %d bytes at 0x%02x.\n", | ||
145 | addr, len, command); | ||
146 | } | ||
147 | |||
148 | ret = 0; | ||
149 | break; | ||
150 | |||
121 | default: | 151 | default: |
122 | dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); | 152 | dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); |
123 | ret = -EOPNOTSUPP; | 153 | ret = -EOPNOTSUPP; |
@@ -129,8 +159,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |||
129 | 159 | ||
130 | static u32 stub_func(struct i2c_adapter *adapter) | 160 | static u32 stub_func(struct i2c_adapter *adapter) |
131 | { | 161 | { |
132 | return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 162 | return STUB_FUNC & functionality; |
133 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; | ||
134 | } | 163 | } |
135 | 164 | ||
136 | static const struct i2c_algorithm smbus_algorithm = { | 165 | static const struct i2c_algorithm smbus_algorithm = { |
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c index 224aa12ee7c8..dd39c1eb03ed 100644 --- a/drivers/i2c/busses/i2c-taos-evm.c +++ b/drivers/i2c/busses/i2c-taos-evm.c | |||
@@ -32,10 +32,12 @@ | |||
32 | 32 | ||
33 | #define TAOS_STATE_INIT 0 | 33 | #define TAOS_STATE_INIT 0 |
34 | #define TAOS_STATE_IDLE 1 | 34 | #define TAOS_STATE_IDLE 1 |
35 | #define TAOS_STATE_SEND 2 | 35 | #define TAOS_STATE_EOFF 2 |
36 | #define TAOS_STATE_RECV 3 | 36 | #define TAOS_STATE_RECV 3 |
37 | 37 | ||
38 | #define TAOS_CMD_RESET 0x12 | 38 | #define TAOS_CMD_RESET 0x12 |
39 | #define TAOS_CMD_ECHO_ON '+' | ||
40 | #define TAOS_CMD_ECHO_OFF '-' | ||
39 | 41 | ||
40 | static DECLARE_WAIT_QUEUE_HEAD(wq); | 42 | static DECLARE_WAIT_QUEUE_HEAD(wq); |
41 | 43 | ||
@@ -102,17 +104,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr, | |||
102 | 104 | ||
103 | /* Send the transaction to the TAOS EVM */ | 105 | /* Send the transaction to the TAOS EVM */ |
104 | dev_dbg(&adapter->dev, "Command buffer: %s\n", taos->buffer); | 106 | dev_dbg(&adapter->dev, "Command buffer: %s\n", taos->buffer); |
105 | taos->pos = 0; | 107 | for (p = taos->buffer; *p; p++) |
106 | taos->state = TAOS_STATE_SEND; | 108 | serio_write(serio, *p); |
107 | serio_write(serio, taos->buffer[0]); | 109 | |
108 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, | ||
109 | msecs_to_jiffies(250)); | ||
110 | if (taos->state != TAOS_STATE_IDLE) { | ||
111 | dev_err(&adapter->dev, "Transaction failed " | ||
112 | "(state=%d, pos=%d)\n", taos->state, taos->pos); | ||
113 | taos->addr = 0; | ||
114 | return -EIO; | ||
115 | } | ||
116 | taos->addr = addr; | 110 | taos->addr = addr; |
117 | 111 | ||
118 | /* Start the transaction and read the answer */ | 112 | /* Start the transaction and read the answer */ |
@@ -122,7 +116,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr, | |||
122 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, | 116 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, |
123 | msecs_to_jiffies(150)); | 117 | msecs_to_jiffies(150)); |
124 | if (taos->state != TAOS_STATE_IDLE | 118 | if (taos->state != TAOS_STATE_IDLE |
125 | || taos->pos != 6) { | 119 | || taos->pos != 5) { |
126 | dev_err(&adapter->dev, "Transaction timeout (pos=%d)\n", | 120 | dev_err(&adapter->dev, "Transaction timeout (pos=%d)\n", |
127 | taos->pos); | 121 | taos->pos); |
128 | return -EIO; | 122 | return -EIO; |
@@ -130,7 +124,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr, | |||
130 | dev_dbg(&adapter->dev, "Answer buffer: %s\n", taos->buffer); | 124 | dev_dbg(&adapter->dev, "Answer buffer: %s\n", taos->buffer); |
131 | 125 | ||
132 | /* Interpret the returned string */ | 126 | /* Interpret the returned string */ |
133 | p = taos->buffer + 2; | 127 | p = taos->buffer + 1; |
134 | p[3] = '\0'; | 128 | p[3] = '\0'; |
135 | if (!strcmp(p, "NAK")) | 129 | if (!strcmp(p, "NAK")) |
136 | return -ENODEV; | 130 | return -ENODEV; |
@@ -173,13 +167,9 @@ static irqreturn_t taos_interrupt(struct serio *serio, unsigned char data, | |||
173 | wake_up_interruptible(&wq); | 167 | wake_up_interruptible(&wq); |
174 | } | 168 | } |
175 | break; | 169 | break; |
176 | case TAOS_STATE_SEND: | 170 | case TAOS_STATE_EOFF: |
177 | if (taos->buffer[++taos->pos]) | 171 | taos->state = TAOS_STATE_IDLE; |
178 | serio_write(serio, taos->buffer[taos->pos]); | 172 | wake_up_interruptible(&wq); |
179 | else { | ||
180 | taos->state = TAOS_STATE_IDLE; | ||
181 | wake_up_interruptible(&wq); | ||
182 | } | ||
183 | break; | 173 | break; |
184 | case TAOS_STATE_RECV: | 174 | case TAOS_STATE_RECV: |
185 | taos->buffer[taos->pos++] = data; | 175 | taos->buffer[taos->pos++] = data; |
@@ -257,6 +247,19 @@ static int taos_connect(struct serio *serio, struct serio_driver *drv) | |||
257 | } | 247 | } |
258 | strlcpy(adapter->name, name, sizeof(adapter->name)); | 248 | strlcpy(adapter->name, name, sizeof(adapter->name)); |
259 | 249 | ||
250 | /* Turn echo off for better performance */ | ||
251 | taos->state = TAOS_STATE_EOFF; | ||
252 | serio_write(serio, TAOS_CMD_ECHO_OFF); | ||
253 | |||
254 | wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE, | ||
255 | msecs_to_jiffies(250)); | ||
256 | if (taos->state != TAOS_STATE_IDLE) { | ||
257 | err = -ENODEV; | ||
258 | dev_err(&adapter->dev, "Echo off failed " | ||
259 | "(state=%d)\n", taos->state); | ||
260 | goto exit_close; | ||
261 | } | ||
262 | |||
260 | err = i2c_add_adapter(adapter); | 263 | err = i2c_add_adapter(adapter); |
261 | if (err) | 264 | if (err) |
262 | goto exit_close; | 265 | goto exit_close; |
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c index b1c050ff311d..d03b04002f0d 100644 --- a/drivers/i2c/busses/i2c-tiny-usb.c +++ b/drivers/i2c/busses/i2c-tiny-usb.c | |||
@@ -13,6 +13,8 @@ | |||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/slab.h> | ||
17 | #include <linux/types.h> | ||
16 | 18 | ||
17 | /* include interfaces to usb layer */ | 19 | /* include interfaces to usb layer */ |
18 | #include <linux/usb.h> | 20 | #include <linux/usb.h> |
@@ -30,11 +32,13 @@ | |||
30 | #define CMD_I2C_IO_BEGIN (1<<0) | 32 | #define CMD_I2C_IO_BEGIN (1<<0) |
31 | #define CMD_I2C_IO_END (1<<1) | 33 | #define CMD_I2C_IO_END (1<<1) |
32 | 34 | ||
33 | /* i2c bit delay, default is 10us -> 100kHz */ | 35 | /* i2c bit delay, default is 10us -> 100kHz max |
34 | static int delay = 10; | 36 | (in practice, due to additional delays in the i2c bitbanging |
35 | module_param(delay, int, 0); | 37 | code this results in a i2c clock of about 50kHz) */ |
36 | MODULE_PARM_DESC(delay, "bit delay in microseconds, " | 38 | static unsigned short delay = 10; |
37 | "e.g. 10 for 100kHz (default is 100kHz)"); | 39 | module_param(delay, ushort, 0); |
40 | MODULE_PARM_DESC(delay, "bit delay in microseconds " | ||
41 | "(default is 10us for 100kHz max)"); | ||
38 | 42 | ||
39 | static int usb_read(struct i2c_adapter *adapter, int cmd, | 43 | static int usb_read(struct i2c_adapter *adapter, int cmd, |
40 | int value, int index, void *data, int len); | 44 | int value, int index, void *data, int len); |
@@ -109,7 +113,7 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) | |||
109 | 113 | ||
110 | static u32 usb_func(struct i2c_adapter *adapter) | 114 | static u32 usb_func(struct i2c_adapter *adapter) |
111 | { | 115 | { |
112 | u32 func; | 116 | __le32 func; |
113 | 117 | ||
114 | /* get functionality from adapter */ | 118 | /* get functionality from adapter */ |
115 | if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) != | 119 | if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) != |
@@ -118,7 +122,7 @@ static u32 usb_func(struct i2c_adapter *adapter) | |||
118 | return 0; | 122 | return 0; |
119 | } | 123 | } |
120 | 124 | ||
121 | return func; | 125 | return le32_to_cpu(func); |
122 | } | 126 | } |
123 | 127 | ||
124 | /* This is the actual algorithm we define */ | 128 | /* This is the actual algorithm we define */ |
@@ -136,7 +140,7 @@ static const struct i2c_algorithm usb_algorithm = { | |||
136 | * Future Technology Devices International Ltd., later a pair was | 140 | * Future Technology Devices International Ltd., later a pair was |
137 | * bought from EZPrototypes | 141 | * bought from EZPrototypes |
138 | */ | 142 | */ |
139 | static struct usb_device_id i2c_tiny_usb_table [] = { | 143 | static const struct usb_device_id i2c_tiny_usb_table[] = { |
140 | { USB_DEVICE(0x0403, 0xc631) }, /* FTDI */ | 144 | { USB_DEVICE(0x0403, 0xc631) }, /* FTDI */ |
141 | { USB_DEVICE(0x1c40, 0x0534) }, /* EZPrototypes */ | 145 | { USB_DEVICE(0x1c40, 0x0534) }, /* EZPrototypes */ |
142 | { } /* Terminating entry */ | 146 | { } /* Terminating entry */ |
@@ -216,8 +220,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface, | |||
216 | "i2c-tiny-usb at bus %03d device %03d", | 220 | "i2c-tiny-usb at bus %03d device %03d", |
217 | dev->usb_dev->bus->busnum, dev->usb_dev->devnum); | 221 | dev->usb_dev->bus->busnum, dev->usb_dev->devnum); |
218 | 222 | ||
219 | if (usb_write(&dev->adapter, CMD_SET_DELAY, | 223 | if (usb_write(&dev->adapter, CMD_SET_DELAY, delay, 0, NULL, 0) != 0) { |
220 | cpu_to_le16(delay), 0, NULL, 0) != 0) { | ||
221 | dev_err(&dev->adapter.dev, | 224 | dev_err(&dev->adapter.dev, |
222 | "failure setting delay to %dus\n", delay); | 225 | "failure setting delay to %dus\n", delay); |
223 | retval = -EIO; | 226 | retval = -EIO; |
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c index 70de82163463..60556012312f 100644 --- a/drivers/i2c/busses/i2c-versatile.c +++ b/drivers/i2c/busses/i2c-versatile.c | |||
@@ -14,8 +14,8 @@ | |||
14 | #include <linux/i2c-algo-bit.h> | 14 | #include <linux/i2c-algo-bit.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
17 | 17 | #include <linux/slab.h> | |
18 | #include <asm/io.h> | 18 | #include <linux/io.h> |
19 | 19 | ||
20 | #define I2C_CONTROL 0x00 | 20 | #define I2C_CONTROL 0x00 |
21 | #define I2C_CONTROLS 0x00 | 21 | #define I2C_CONTROLS 0x00 |
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c index 8b24f192103a..7799fe5bda88 100644 --- a/drivers/i2c/busses/i2c-via.c +++ b/drivers/i2c/busses/i2c-via.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/i2c-algo-bit.h> | 27 | #include <linux/i2c-algo-bit.h> |
28 | #include <asm/io.h> | 28 | #include <linux/io.h> |
29 | 29 | ||
30 | /* Power management registers */ | 30 | /* Power management registers */ |
31 | #define PM_CFG_REVID 0x08 /* silicon revision code */ | 31 | #define PM_CFG_REVID 0x08 /* silicon revision code */ |
@@ -89,7 +89,7 @@ static struct i2c_adapter vt586b_adapter = { | |||
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
92 | static struct pci_device_id vt586b_ids[] __devinitdata = { | 92 | static const struct pci_device_id vt586b_ids[] __devinitconst = { |
93 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) }, | 93 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) }, |
94 | { 0, } | 94 | { 0, } |
95 | }; | 95 | }; |
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 54d810a4d00f..0b012f1f8ac5 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c | |||
@@ -51,7 +51,7 @@ | |||
51 | #include <linux/i2c.h> | 51 | #include <linux/i2c.h> |
52 | #include <linux/init.h> | 52 | #include <linux/init.h> |
53 | #include <linux/acpi.h> | 53 | #include <linux/acpi.h> |
54 | #include <asm/io.h> | 54 | #include <linux/io.h> |
55 | 55 | ||
56 | static struct pci_dev *vt596_pdev; | 56 | static struct pci_dev *vt596_pdev; |
57 | 57 | ||
@@ -165,10 +165,10 @@ static int vt596_transaction(u8 size) | |||
165 | do { | 165 | do { |
166 | msleep(1); | 166 | msleep(1); |
167 | temp = inb_p(SMBHSTSTS); | 167 | temp = inb_p(SMBHSTSTS); |
168 | } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); | 168 | } while ((temp & 0x01) && (++timeout < MAX_TIMEOUT)); |
169 | 169 | ||
170 | /* If the SMBus is still busy, we give up */ | 170 | /* If the SMBus is still busy, we give up */ |
171 | if (timeout >= MAX_TIMEOUT) { | 171 | if (timeout == MAX_TIMEOUT) { |
172 | result = -ETIMEDOUT; | 172 | result = -ETIMEDOUT; |
173 | dev_err(&vt596_adapter.dev, "SMBus timeout!\n"); | 173 | dev_err(&vt596_adapter.dev, "SMBus timeout!\n"); |
174 | } | 174 | } |
@@ -185,14 +185,8 @@ static int vt596_transaction(u8 size) | |||
185 | } | 185 | } |
186 | 186 | ||
187 | if (temp & 0x04) { | 187 | if (temp & 0x04) { |
188 | int read = inb_p(SMBHSTADD) & 0x01; | ||
189 | result = -ENXIO; | 188 | result = -ENXIO; |
190 | /* The quick and receive byte commands are used to probe | 189 | dev_dbg(&vt596_adapter.dev, "No response\n"); |
191 | for chips, so errors are expected, and we don't want | ||
192 | to frighten the user. */ | ||
193 | if (!((size == VT596_QUICK && !read) || | ||
194 | (size == VT596_BYTE && read))) | ||
195 | dev_err(&vt596_adapter.dev, "Transaction error!\n"); | ||
196 | } | 190 | } |
197 | 191 | ||
198 | /* Resetting status register */ | 192 | /* Resetting status register */ |
@@ -365,7 +359,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev, | |||
365 | found: | 359 | found: |
366 | error = acpi_check_region(vt596_smba, 8, vt596_driver.name); | 360 | error = acpi_check_region(vt596_smba, 8, vt596_driver.name); |
367 | if (error) | 361 | if (error) |
368 | return error; | 362 | return -ENODEV; |
369 | 363 | ||
370 | if (!request_region(vt596_smba, 8, vt596_driver.name)) { | 364 | if (!request_region(vt596_smba, 8, vt596_driver.name)) { |
371 | dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", | 365 | dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", |
@@ -444,7 +438,7 @@ release_region: | |||
444 | return error; | 438 | return error; |
445 | } | 439 | } |
446 | 440 | ||
447 | static struct pci_device_id vt596_ids[] = { | 441 | static const struct pci_device_id vt596_ids[] = { |
448 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3), | 442 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3), |
449 | .driver_data = SMBBA1 }, | 443 | .driver_data = SMBBA1 }, |
450 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3), | 444 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3), |
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c deleted file mode 100644 index 7663d57833a0..000000000000 --- a/drivers/i2c/busses/i2c-voodoo3.c +++ /dev/null | |||
@@ -1,248 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>, | ||
3 | Philip Edelbrock <phil@netroedge.com>, | ||
4 | Ralph Metzler <rjkm@thp.uni-koeln.de>, and | ||
5 | Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
6 | |||
7 | Based on code written by Ralph Metzler <rjkm@thp.uni-koeln.de> and | ||
8 | Simon Vogl | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | */ | ||
24 | |||
25 | /* This interfaces to the I2C bus of the Voodoo3 to gain access to | ||
26 | the BT869 and possibly other I2C devices. */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/pci.h> | ||
32 | #include <linux/i2c.h> | ||
33 | #include <linux/i2c-algo-bit.h> | ||
34 | #include <asm/io.h> | ||
35 | |||
36 | /* the only registers we use */ | ||
37 | #define REG 0x78 | ||
38 | #define REG2 0x70 | ||
39 | |||
40 | /* bit locations in the register */ | ||
41 | #define DDC_ENAB 0x00040000 | ||
42 | #define DDC_SCL_OUT 0x00080000 | ||
43 | #define DDC_SDA_OUT 0x00100000 | ||
44 | #define DDC_SCL_IN 0x00200000 | ||
45 | #define DDC_SDA_IN 0x00400000 | ||
46 | #define I2C_ENAB 0x00800000 | ||
47 | #define I2C_SCL_OUT 0x01000000 | ||
48 | #define I2C_SDA_OUT 0x02000000 | ||
49 | #define I2C_SCL_IN 0x04000000 | ||
50 | #define I2C_SDA_IN 0x08000000 | ||
51 | |||
52 | /* initialization states */ | ||
53 | #define INIT2 0x2 | ||
54 | #define INIT3 0x4 | ||
55 | |||
56 | /* delays */ | ||
57 | #define CYCLE_DELAY 10 | ||
58 | #define TIMEOUT (HZ / 2) | ||
59 | |||
60 | |||
61 | static void __iomem *ioaddr; | ||
62 | |||
63 | /* The voo GPIO registers don't have individual masks for each bit | ||
64 | so we always have to read before writing. */ | ||
65 | |||
66 | static void bit_vooi2c_setscl(void *data, int val) | ||
67 | { | ||
68 | unsigned int r; | ||
69 | r = readl(ioaddr + REG); | ||
70 | if (val) | ||
71 | r |= I2C_SCL_OUT; | ||
72 | else | ||
73 | r &= ~I2C_SCL_OUT; | ||
74 | writel(r, ioaddr + REG); | ||
75 | readl(ioaddr + REG); /* flush posted write */ | ||
76 | } | ||
77 | |||
78 | static void bit_vooi2c_setsda(void *data, int val) | ||
79 | { | ||
80 | unsigned int r; | ||
81 | r = readl(ioaddr + REG); | ||
82 | if (val) | ||
83 | r |= I2C_SDA_OUT; | ||
84 | else | ||
85 | r &= ~I2C_SDA_OUT; | ||
86 | writel(r, ioaddr + REG); | ||
87 | readl(ioaddr + REG); /* flush posted write */ | ||
88 | } | ||
89 | |||
90 | /* The GPIO pins are open drain, so the pins always remain outputs. | ||
91 | We rely on the i2c-algo-bit routines to set the pins high before | ||
92 | reading the input from other chips. */ | ||
93 | |||
94 | static int bit_vooi2c_getscl(void *data) | ||
95 | { | ||
96 | return (0 != (readl(ioaddr + REG) & I2C_SCL_IN)); | ||
97 | } | ||
98 | |||
99 | static int bit_vooi2c_getsda(void *data) | ||
100 | { | ||
101 | return (0 != (readl(ioaddr + REG) & I2C_SDA_IN)); | ||
102 | } | ||
103 | |||
104 | static void bit_vooddc_setscl(void *data, int val) | ||
105 | { | ||
106 | unsigned int r; | ||
107 | r = readl(ioaddr + REG); | ||
108 | if (val) | ||
109 | r |= DDC_SCL_OUT; | ||
110 | else | ||
111 | r &= ~DDC_SCL_OUT; | ||
112 | writel(r, ioaddr + REG); | ||
113 | readl(ioaddr + REG); /* flush posted write */ | ||
114 | } | ||
115 | |||
116 | static void bit_vooddc_setsda(void *data, int val) | ||
117 | { | ||
118 | unsigned int r; | ||
119 | r = readl(ioaddr + REG); | ||
120 | if (val) | ||
121 | r |= DDC_SDA_OUT; | ||
122 | else | ||
123 | r &= ~DDC_SDA_OUT; | ||
124 | writel(r, ioaddr + REG); | ||
125 | readl(ioaddr + REG); /* flush posted write */ | ||
126 | } | ||
127 | |||
128 | static int bit_vooddc_getscl(void *data) | ||
129 | { | ||
130 | return (0 != (readl(ioaddr + REG) & DDC_SCL_IN)); | ||
131 | } | ||
132 | |||
133 | static int bit_vooddc_getsda(void *data) | ||
134 | { | ||
135 | return (0 != (readl(ioaddr + REG) & DDC_SDA_IN)); | ||
136 | } | ||
137 | |||
138 | static int config_v3(struct pci_dev *dev) | ||
139 | { | ||
140 | unsigned long cadr; | ||
141 | |||
142 | /* map Voodoo3 memory */ | ||
143 | cadr = dev->resource[0].start; | ||
144 | cadr &= PCI_BASE_ADDRESS_MEM_MASK; | ||
145 | ioaddr = ioremap_nocache(cadr, 0x1000); | ||
146 | if (ioaddr) { | ||
147 | writel(0x8160, ioaddr + REG2); | ||
148 | writel(0xcffc0020, ioaddr + REG); | ||
149 | dev_info(&dev->dev, "Using Banshee/Voodoo3 I2C device at %p\n", ioaddr); | ||
150 | return 0; | ||
151 | } | ||
152 | return -ENODEV; | ||
153 | } | ||
154 | |||
155 | static struct i2c_algo_bit_data voo_i2c_bit_data = { | ||
156 | .setsda = bit_vooi2c_setsda, | ||
157 | .setscl = bit_vooi2c_setscl, | ||
158 | .getsda = bit_vooi2c_getsda, | ||
159 | .getscl = bit_vooi2c_getscl, | ||
160 | .udelay = CYCLE_DELAY, | ||
161 | .timeout = TIMEOUT | ||
162 | }; | ||
163 | |||
164 | static struct i2c_adapter voodoo3_i2c_adapter = { | ||
165 | .owner = THIS_MODULE, | ||
166 | .name = "I2C Voodoo3/Banshee adapter", | ||
167 | .algo_data = &voo_i2c_bit_data, | ||
168 | }; | ||
169 | |||
170 | static struct i2c_algo_bit_data voo_ddc_bit_data = { | ||
171 | .setsda = bit_vooddc_setsda, | ||
172 | .setscl = bit_vooddc_setscl, | ||
173 | .getsda = bit_vooddc_getsda, | ||
174 | .getscl = bit_vooddc_getscl, | ||
175 | .udelay = CYCLE_DELAY, | ||
176 | .timeout = TIMEOUT | ||
177 | }; | ||
178 | |||
179 | static struct i2c_adapter voodoo3_ddc_adapter = { | ||
180 | .owner = THIS_MODULE, | ||
181 | .class = I2C_CLASS_DDC, | ||
182 | .name = "DDC Voodoo3/Banshee adapter", | ||
183 | .algo_data = &voo_ddc_bit_data, | ||
184 | }; | ||
185 | |||
186 | static struct pci_device_id voodoo3_ids[] __devinitdata = { | ||
187 | { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3) }, | ||
188 | { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE) }, | ||
189 | { 0, } | ||
190 | }; | ||
191 | |||
192 | MODULE_DEVICE_TABLE (pci, voodoo3_ids); | ||
193 | |||
194 | static int __devinit voodoo3_probe(struct pci_dev *dev, const struct pci_device_id *id) | ||
195 | { | ||
196 | int retval; | ||
197 | |||
198 | retval = config_v3(dev); | ||
199 | if (retval) | ||
200 | return retval; | ||
201 | |||
202 | /* set up the sysfs linkage to our parent device */ | ||
203 | voodoo3_i2c_adapter.dev.parent = &dev->dev; | ||
204 | voodoo3_ddc_adapter.dev.parent = &dev->dev; | ||
205 | |||
206 | retval = i2c_bit_add_bus(&voodoo3_i2c_adapter); | ||
207 | if (retval) | ||
208 | return retval; | ||
209 | retval = i2c_bit_add_bus(&voodoo3_ddc_adapter); | ||
210 | if (retval) | ||
211 | i2c_del_adapter(&voodoo3_i2c_adapter); | ||
212 | return retval; | ||
213 | } | ||
214 | |||
215 | static void __devexit voodoo3_remove(struct pci_dev *dev) | ||
216 | { | ||
217 | i2c_del_adapter(&voodoo3_i2c_adapter); | ||
218 | i2c_del_adapter(&voodoo3_ddc_adapter); | ||
219 | iounmap(ioaddr); | ||
220 | } | ||
221 | |||
222 | static struct pci_driver voodoo3_driver = { | ||
223 | .name = "voodoo3_smbus", | ||
224 | .id_table = voodoo3_ids, | ||
225 | .probe = voodoo3_probe, | ||
226 | .remove = __devexit_p(voodoo3_remove), | ||
227 | }; | ||
228 | |||
229 | static int __init i2c_voodoo3_init(void) | ||
230 | { | ||
231 | return pci_register_driver(&voodoo3_driver); | ||
232 | } | ||
233 | |||
234 | static void __exit i2c_voodoo3_exit(void) | ||
235 | { | ||
236 | pci_unregister_driver(&voodoo3_driver); | ||
237 | } | ||
238 | |||
239 | |||
240 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " | ||
241 | "Philip Edelbrock <phil@netroedge.com>, " | ||
242 | "Ralph Metzler <rjkm@thp.uni-koeln.de>, " | ||
243 | "and Mark D. Studebaker <mdsxyz123@yahoo.com>"); | ||
244 | MODULE_DESCRIPTION("Voodoo3 I2C/SMBus driver"); | ||
245 | MODULE_LICENSE("GPL"); | ||
246 | |||
247 | module_init(i2c_voodoo3_init); | ||
248 | module_exit(i2c_voodoo3_exit); | ||
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c new file mode 100644 index 000000000000..a9c419e075a5 --- /dev/null +++ b/drivers/i2c/busses/i2c-xiic.c | |||
@@ -0,0 +1,826 @@ | |||
1 | /* | ||
2 | * i2c-xiic.c | ||
3 | * Copyright (c) 2002-2007 Xilinx Inc. | ||
4 | * Copyright (c) 2009-2010 Intel Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | * | ||
19 | * | ||
20 | * This code was implemented by Mocean Laboratories AB when porting linux | ||
21 | * to the automotive development board Russellville. The copyright holder | ||
22 | * as seen in the header is Intel corporation. | ||
23 | * Mocean Laboratories forked off the GNU/Linux platform work into a | ||
24 | * separate company called Pelagicore AB, which commited the code to the | ||
25 | * kernel. | ||
26 | */ | ||
27 | |||
28 | /* Supports: | ||
29 | * Xilinx IIC | ||
30 | */ | ||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/init.h> | ||
34 | #include <linux/errno.h> | ||
35 | #include <linux/delay.h> | ||
36 | #include <linux/platform_device.h> | ||
37 | #include <linux/i2c.h> | ||
38 | #include <linux/interrupt.h> | ||
39 | #include <linux/wait.h> | ||
40 | #include <linux/i2c-xiic.h> | ||
41 | #include <linux/io.h> | ||
42 | #include <linux/slab.h> | ||
43 | |||
44 | #define DRIVER_NAME "xiic-i2c" | ||
45 | |||
46 | enum xilinx_i2c_state { | ||
47 | STATE_DONE, | ||
48 | STATE_ERROR, | ||
49 | STATE_START | ||
50 | }; | ||
51 | |||
52 | /** | ||
53 | * struct xiic_i2c - Internal representation of the XIIC I2C bus | ||
54 | * @base: Memory base of the HW registers | ||
55 | * @wait: Wait queue for callers | ||
56 | * @adap: Kernel adapter representation | ||
57 | * @tx_msg: Messages from above to be sent | ||
58 | * @lock: Mutual exclusion | ||
59 | * @tx_pos: Current pos in TX message | ||
60 | * @nmsgs: Number of messages in tx_msg | ||
61 | * @state: See STATE_ | ||
62 | * @rx_msg: Current RX message | ||
63 | * @rx_pos: Position within current RX message | ||
64 | */ | ||
65 | struct xiic_i2c { | ||
66 | void __iomem *base; | ||
67 | wait_queue_head_t wait; | ||
68 | struct i2c_adapter adap; | ||
69 | struct i2c_msg *tx_msg; | ||
70 | spinlock_t lock; | ||
71 | unsigned int tx_pos; | ||
72 | unsigned int nmsgs; | ||
73 | enum xilinx_i2c_state state; | ||
74 | struct i2c_msg *rx_msg; | ||
75 | int rx_pos; | ||
76 | }; | ||
77 | |||
78 | |||
79 | #define XIIC_MSB_OFFSET 0 | ||
80 | #define XIIC_REG_OFFSET (0x100+XIIC_MSB_OFFSET) | ||
81 | |||
82 | /* | ||
83 | * Register offsets in bytes from RegisterBase. Three is added to the | ||
84 | * base offset to access LSB (IBM style) of the word | ||
85 | */ | ||
86 | #define XIIC_CR_REG_OFFSET (0x00+XIIC_REG_OFFSET) /* Control Register */ | ||
87 | #define XIIC_SR_REG_OFFSET (0x04+XIIC_REG_OFFSET) /* Status Register */ | ||
88 | #define XIIC_DTR_REG_OFFSET (0x08+XIIC_REG_OFFSET) /* Data Tx Register */ | ||
89 | #define XIIC_DRR_REG_OFFSET (0x0C+XIIC_REG_OFFSET) /* Data Rx Register */ | ||
90 | #define XIIC_ADR_REG_OFFSET (0x10+XIIC_REG_OFFSET) /* Address Register */ | ||
91 | #define XIIC_TFO_REG_OFFSET (0x14+XIIC_REG_OFFSET) /* Tx FIFO Occupancy */ | ||
92 | #define XIIC_RFO_REG_OFFSET (0x18+XIIC_REG_OFFSET) /* Rx FIFO Occupancy */ | ||
93 | #define XIIC_TBA_REG_OFFSET (0x1C+XIIC_REG_OFFSET) /* 10 Bit Address reg */ | ||
94 | #define XIIC_RFD_REG_OFFSET (0x20+XIIC_REG_OFFSET) /* Rx FIFO Depth reg */ | ||
95 | #define XIIC_GPO_REG_OFFSET (0x24+XIIC_REG_OFFSET) /* Output Register */ | ||
96 | |||
97 | /* Control Register masks */ | ||
98 | #define XIIC_CR_ENABLE_DEVICE_MASK 0x01 /* Device enable = 1 */ | ||
99 | #define XIIC_CR_TX_FIFO_RESET_MASK 0x02 /* Transmit FIFO reset=1 */ | ||
100 | #define XIIC_CR_MSMS_MASK 0x04 /* Master starts Txing=1 */ | ||
101 | #define XIIC_CR_DIR_IS_TX_MASK 0x08 /* Dir of tx. Txing=1 */ | ||
102 | #define XIIC_CR_NO_ACK_MASK 0x10 /* Tx Ack. NO ack = 1 */ | ||
103 | #define XIIC_CR_REPEATED_START_MASK 0x20 /* Repeated start = 1 */ | ||
104 | #define XIIC_CR_GENERAL_CALL_MASK 0x40 /* Gen Call enabled = 1 */ | ||
105 | |||
106 | /* Status Register masks */ | ||
107 | #define XIIC_SR_GEN_CALL_MASK 0x01 /* 1=a mstr issued a GC */ | ||
108 | #define XIIC_SR_ADDR_AS_SLAVE_MASK 0x02 /* 1=when addr as slave */ | ||
109 | #define XIIC_SR_BUS_BUSY_MASK 0x04 /* 1 = bus is busy */ | ||
110 | #define XIIC_SR_MSTR_RDING_SLAVE_MASK 0x08 /* 1=Dir: mstr <-- slave */ | ||
111 | #define XIIC_SR_TX_FIFO_FULL_MASK 0x10 /* 1 = Tx FIFO full */ | ||
112 | #define XIIC_SR_RX_FIFO_FULL_MASK 0x20 /* 1 = Rx FIFO full */ | ||
113 | #define XIIC_SR_RX_FIFO_EMPTY_MASK 0x40 /* 1 = Rx FIFO empty */ | ||
114 | #define XIIC_SR_TX_FIFO_EMPTY_MASK 0x80 /* 1 = Tx FIFO empty */ | ||
115 | |||
116 | /* Interrupt Status Register masks Interrupt occurs when... */ | ||
117 | #define XIIC_INTR_ARB_LOST_MASK 0x01 /* 1 = arbitration lost */ | ||
118 | #define XIIC_INTR_TX_ERROR_MASK 0x02 /* 1=Tx error/msg complete */ | ||
119 | #define XIIC_INTR_TX_EMPTY_MASK 0x04 /* 1 = Tx FIFO/reg empty */ | ||
120 | #define XIIC_INTR_RX_FULL_MASK 0x08 /* 1=Rx FIFO/reg=OCY level */ | ||
121 | #define XIIC_INTR_BNB_MASK 0x10 /* 1 = Bus not busy */ | ||
122 | #define XIIC_INTR_AAS_MASK 0x20 /* 1 = when addr as slave */ | ||
123 | #define XIIC_INTR_NAAS_MASK 0x40 /* 1 = not addr as slave */ | ||
124 | #define XIIC_INTR_TX_HALF_MASK 0x80 /* 1 = TX FIFO half empty */ | ||
125 | |||
126 | /* The following constants specify the depth of the FIFOs */ | ||
127 | #define IIC_RX_FIFO_DEPTH 16 /* Rx fifo capacity */ | ||
128 | #define IIC_TX_FIFO_DEPTH 16 /* Tx fifo capacity */ | ||
129 | |||
130 | /* The following constants specify groups of interrupts that are typically | ||
131 | * enabled or disables at the same time | ||
132 | */ | ||
133 | #define XIIC_TX_INTERRUPTS \ | ||
134 | (XIIC_INTR_TX_ERROR_MASK | XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK) | ||
135 | |||
136 | #define XIIC_TX_RX_INTERRUPTS (XIIC_INTR_RX_FULL_MASK | XIIC_TX_INTERRUPTS) | ||
137 | |||
138 | /* The following constants are used with the following macros to specify the | ||
139 | * operation, a read or write operation. | ||
140 | */ | ||
141 | #define XIIC_READ_OPERATION 1 | ||
142 | #define XIIC_WRITE_OPERATION 0 | ||
143 | |||
144 | /* | ||
145 | * Tx Fifo upper bit masks. | ||
146 | */ | ||
147 | #define XIIC_TX_DYN_START_MASK 0x0100 /* 1 = Set dynamic start */ | ||
148 | #define XIIC_TX_DYN_STOP_MASK 0x0200 /* 1 = Set dynamic stop */ | ||
149 | |||
150 | /* | ||
151 | * The following constants define the register offsets for the Interrupt | ||
152 | * registers. There are some holes in the memory map for reserved addresses | ||
153 | * to allow other registers to be added and still match the memory map of the | ||
154 | * interrupt controller registers | ||
155 | */ | ||
156 | #define XIIC_DGIER_OFFSET 0x1C /* Device Global Interrupt Enable Register */ | ||
157 | #define XIIC_IISR_OFFSET 0x20 /* Interrupt Status Register */ | ||
158 | #define XIIC_IIER_OFFSET 0x28 /* Interrupt Enable Register */ | ||
159 | #define XIIC_RESETR_OFFSET 0x40 /* Reset Register */ | ||
160 | |||
161 | #define XIIC_RESET_MASK 0xAUL | ||
162 | |||
163 | /* | ||
164 | * The following constant is used for the device global interrupt enable | ||
165 | * register, to enable all interrupts for the device, this is the only bit | ||
166 | * in the register | ||
167 | */ | ||
168 | #define XIIC_GINTR_ENABLE_MASK 0x80000000UL | ||
169 | |||
170 | #define xiic_tx_space(i2c) ((i2c)->tx_msg->len - (i2c)->tx_pos) | ||
171 | #define xiic_rx_space(i2c) ((i2c)->rx_msg->len - (i2c)->rx_pos) | ||
172 | |||
173 | static void xiic_start_xfer(struct xiic_i2c *i2c); | ||
174 | static void __xiic_start_xfer(struct xiic_i2c *i2c); | ||
175 | |||
176 | static inline void xiic_setreg8(struct xiic_i2c *i2c, int reg, u8 value) | ||
177 | { | ||
178 | iowrite8(value, i2c->base + reg); | ||
179 | } | ||
180 | |||
181 | static inline u8 xiic_getreg8(struct xiic_i2c *i2c, int reg) | ||
182 | { | ||
183 | return ioread8(i2c->base + reg); | ||
184 | } | ||
185 | |||
186 | static inline void xiic_setreg16(struct xiic_i2c *i2c, int reg, u16 value) | ||
187 | { | ||
188 | iowrite16(value, i2c->base + reg); | ||
189 | } | ||
190 | |||
191 | static inline void xiic_setreg32(struct xiic_i2c *i2c, int reg, int value) | ||
192 | { | ||
193 | iowrite32(value, i2c->base + reg); | ||
194 | } | ||
195 | |||
196 | static inline int xiic_getreg32(struct xiic_i2c *i2c, int reg) | ||
197 | { | ||
198 | return ioread32(i2c->base + reg); | ||
199 | } | ||
200 | |||
201 | static inline void xiic_irq_dis(struct xiic_i2c *i2c, u32 mask) | ||
202 | { | ||
203 | u32 ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); | ||
204 | xiic_setreg32(i2c, XIIC_IIER_OFFSET, ier & ~mask); | ||
205 | } | ||
206 | |||
207 | static inline void xiic_irq_en(struct xiic_i2c *i2c, u32 mask) | ||
208 | { | ||
209 | u32 ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); | ||
210 | xiic_setreg32(i2c, XIIC_IIER_OFFSET, ier | mask); | ||
211 | } | ||
212 | |||
213 | static inline void xiic_irq_clr(struct xiic_i2c *i2c, u32 mask) | ||
214 | { | ||
215 | u32 isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); | ||
216 | xiic_setreg32(i2c, XIIC_IISR_OFFSET, isr & mask); | ||
217 | } | ||
218 | |||
219 | static inline void xiic_irq_clr_en(struct xiic_i2c *i2c, u32 mask) | ||
220 | { | ||
221 | xiic_irq_clr(i2c, mask); | ||
222 | xiic_irq_en(i2c, mask); | ||
223 | } | ||
224 | |||
225 | static void xiic_clear_rx_fifo(struct xiic_i2c *i2c) | ||
226 | { | ||
227 | u8 sr; | ||
228 | for (sr = xiic_getreg8(i2c, XIIC_SR_REG_OFFSET); | ||
229 | !(sr & XIIC_SR_RX_FIFO_EMPTY_MASK); | ||
230 | sr = xiic_getreg8(i2c, XIIC_SR_REG_OFFSET)) | ||
231 | xiic_getreg8(i2c, XIIC_DRR_REG_OFFSET); | ||
232 | } | ||
233 | |||
234 | static void xiic_reinit(struct xiic_i2c *i2c) | ||
235 | { | ||
236 | xiic_setreg32(i2c, XIIC_RESETR_OFFSET, XIIC_RESET_MASK); | ||
237 | |||
238 | /* Set receive Fifo depth to maximum (zero based). */ | ||
239 | xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, IIC_RX_FIFO_DEPTH - 1); | ||
240 | |||
241 | /* Reset Tx Fifo. */ | ||
242 | xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, XIIC_CR_TX_FIFO_RESET_MASK); | ||
243 | |||
244 | /* Enable IIC Device, remove Tx Fifo reset & disable general call. */ | ||
245 | xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, XIIC_CR_ENABLE_DEVICE_MASK); | ||
246 | |||
247 | /* make sure RX fifo is empty */ | ||
248 | xiic_clear_rx_fifo(i2c); | ||
249 | |||
250 | /* Enable interrupts */ | ||
251 | xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); | ||
252 | |||
253 | xiic_irq_clr_en(i2c, XIIC_INTR_AAS_MASK | XIIC_INTR_ARB_LOST_MASK); | ||
254 | } | ||
255 | |||
256 | static void xiic_deinit(struct xiic_i2c *i2c) | ||
257 | { | ||
258 | u8 cr; | ||
259 | |||
260 | xiic_setreg32(i2c, XIIC_RESETR_OFFSET, XIIC_RESET_MASK); | ||
261 | |||
262 | /* Disable IIC Device. */ | ||
263 | cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); | ||
264 | xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & ~XIIC_CR_ENABLE_DEVICE_MASK); | ||
265 | } | ||
266 | |||
267 | static void xiic_read_rx(struct xiic_i2c *i2c) | ||
268 | { | ||
269 | u8 bytes_in_fifo; | ||
270 | int i; | ||
271 | |||
272 | bytes_in_fifo = xiic_getreg8(i2c, XIIC_RFO_REG_OFFSET) + 1; | ||
273 | |||
274 | dev_dbg(i2c->adap.dev.parent, "%s entry, bytes in fifo: %d, msg: %d" | ||
275 | ", SR: 0x%x, CR: 0x%x\n", | ||
276 | __func__, bytes_in_fifo, xiic_rx_space(i2c), | ||
277 | xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), | ||
278 | xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); | ||
279 | |||
280 | if (bytes_in_fifo > xiic_rx_space(i2c)) | ||
281 | bytes_in_fifo = xiic_rx_space(i2c); | ||
282 | |||
283 | for (i = 0; i < bytes_in_fifo; i++) | ||
284 | i2c->rx_msg->buf[i2c->rx_pos++] = | ||
285 | xiic_getreg8(i2c, XIIC_DRR_REG_OFFSET); | ||
286 | |||
287 | xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, | ||
288 | (xiic_rx_space(i2c) > IIC_RX_FIFO_DEPTH) ? | ||
289 | IIC_RX_FIFO_DEPTH - 1 : xiic_rx_space(i2c) - 1); | ||
290 | } | ||
291 | |||
292 | static int xiic_tx_fifo_space(struct xiic_i2c *i2c) | ||
293 | { | ||
294 | /* return the actual space left in the FIFO */ | ||
295 | return IIC_TX_FIFO_DEPTH - xiic_getreg8(i2c, XIIC_TFO_REG_OFFSET) - 1; | ||
296 | } | ||
297 | |||
298 | static void xiic_fill_tx_fifo(struct xiic_i2c *i2c) | ||
299 | { | ||
300 | u8 fifo_space = xiic_tx_fifo_space(i2c); | ||
301 | int len = xiic_tx_space(i2c); | ||
302 | |||
303 | len = (len > fifo_space) ? fifo_space : len; | ||
304 | |||
305 | dev_dbg(i2c->adap.dev.parent, "%s entry, len: %d, fifo space: %d\n", | ||
306 | __func__, len, fifo_space); | ||
307 | |||
308 | while (len--) { | ||
309 | u16 data = i2c->tx_msg->buf[i2c->tx_pos++]; | ||
310 | if ((xiic_tx_space(i2c) == 0) && (i2c->nmsgs == 1)) { | ||
311 | /* last message in transfer -> STOP */ | ||
312 | data |= XIIC_TX_DYN_STOP_MASK; | ||
313 | dev_dbg(i2c->adap.dev.parent, "%s TX STOP\n", __func__); | ||
314 | |||
315 | xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); | ||
316 | } else | ||
317 | xiic_setreg8(i2c, XIIC_DTR_REG_OFFSET, data); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | static void xiic_wakeup(struct xiic_i2c *i2c, int code) | ||
322 | { | ||
323 | i2c->tx_msg = NULL; | ||
324 | i2c->rx_msg = NULL; | ||
325 | i2c->nmsgs = 0; | ||
326 | i2c->state = code; | ||
327 | wake_up(&i2c->wait); | ||
328 | } | ||
329 | |||
330 | static void xiic_process(struct xiic_i2c *i2c) | ||
331 | { | ||
332 | u32 pend, isr, ier; | ||
333 | u32 clr = 0; | ||
334 | |||
335 | /* Get the interrupt Status from the IPIF. There is no clearing of | ||
336 | * interrupts in the IPIF. Interrupts must be cleared at the source. | ||
337 | * To find which interrupts are pending; AND interrupts pending with | ||
338 | * interrupts masked. | ||
339 | */ | ||
340 | isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); | ||
341 | ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); | ||
342 | pend = isr & ier; | ||
343 | |||
344 | dev_dbg(i2c->adap.dev.parent, "%s entry, IER: 0x%x, ISR: 0x%x, " | ||
345 | "pend: 0x%x, SR: 0x%x, msg: %p, nmsgs: %d\n", | ||
346 | __func__, ier, isr, pend, xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), | ||
347 | i2c->tx_msg, i2c->nmsgs); | ||
348 | |||
349 | /* Do not processes a devices interrupts if the device has no | ||
350 | * interrupts pending | ||
351 | */ | ||
352 | if (!pend) | ||
353 | return; | ||
354 | |||
355 | /* Service requesting interrupt */ | ||
356 | if ((pend & XIIC_INTR_ARB_LOST_MASK) || | ||
357 | ((pend & XIIC_INTR_TX_ERROR_MASK) && | ||
358 | !(pend & XIIC_INTR_RX_FULL_MASK))) { | ||
359 | /* bus arbritration lost, or... | ||
360 | * Transmit error _OR_ RX completed | ||
361 | * if this happens when RX_FULL is not set | ||
362 | * this is probably a TX error | ||
363 | */ | ||
364 | |||
365 | dev_dbg(i2c->adap.dev.parent, "%s error\n", __func__); | ||
366 | |||
367 | /* dynamic mode seem to suffer from problems if we just flushes | ||
368 | * fifos and the next message is a TX with len 0 (only addr) | ||
369 | * reset the IP instead of just flush fifos | ||
370 | */ | ||
371 | xiic_reinit(i2c); | ||
372 | |||
373 | if (i2c->tx_msg) | ||
374 | xiic_wakeup(i2c, STATE_ERROR); | ||
375 | |||
376 | } else if (pend & XIIC_INTR_RX_FULL_MASK) { | ||
377 | /* Receive register/FIFO is full */ | ||
378 | |||
379 | clr = XIIC_INTR_RX_FULL_MASK; | ||
380 | if (!i2c->rx_msg) { | ||
381 | dev_dbg(i2c->adap.dev.parent, | ||
382 | "%s unexpexted RX IRQ\n", __func__); | ||
383 | xiic_clear_rx_fifo(i2c); | ||
384 | goto out; | ||
385 | } | ||
386 | |||
387 | xiic_read_rx(i2c); | ||
388 | if (xiic_rx_space(i2c) == 0) { | ||
389 | /* this is the last part of the message */ | ||
390 | i2c->rx_msg = NULL; | ||
391 | |||
392 | /* also clear TX error if there (RX complete) */ | ||
393 | clr |= (isr & XIIC_INTR_TX_ERROR_MASK); | ||
394 | |||
395 | dev_dbg(i2c->adap.dev.parent, | ||
396 | "%s end of message, nmsgs: %d\n", | ||
397 | __func__, i2c->nmsgs); | ||
398 | |||
399 | /* send next message if this wasn't the last, | ||
400 | * otherwise the transfer will be finialise when | ||
401 | * receiving the bus not busy interrupt | ||
402 | */ | ||
403 | if (i2c->nmsgs > 1) { | ||
404 | i2c->nmsgs--; | ||
405 | i2c->tx_msg++; | ||
406 | dev_dbg(i2c->adap.dev.parent, | ||
407 | "%s will start next...\n", __func__); | ||
408 | |||
409 | __xiic_start_xfer(i2c); | ||
410 | } | ||
411 | } | ||
412 | } else if (pend & XIIC_INTR_BNB_MASK) { | ||
413 | /* IIC bus has transitioned to not busy */ | ||
414 | clr = XIIC_INTR_BNB_MASK; | ||
415 | |||
416 | /* The bus is not busy, disable BusNotBusy interrupt */ | ||
417 | xiic_irq_dis(i2c, XIIC_INTR_BNB_MASK); | ||
418 | |||
419 | if (!i2c->tx_msg) | ||
420 | goto out; | ||
421 | |||
422 | if ((i2c->nmsgs == 1) && !i2c->rx_msg && | ||
423 | xiic_tx_space(i2c) == 0) | ||
424 | xiic_wakeup(i2c, STATE_DONE); | ||
425 | else | ||
426 | xiic_wakeup(i2c, STATE_ERROR); | ||
427 | |||
428 | } else if (pend & (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK)) { | ||
429 | /* Transmit register/FIFO is empty or ½ empty */ | ||
430 | |||
431 | clr = pend & | ||
432 | (XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_HALF_MASK); | ||
433 | |||
434 | if (!i2c->tx_msg) { | ||
435 | dev_dbg(i2c->adap.dev.parent, | ||
436 | "%s unexpexted TX IRQ\n", __func__); | ||
437 | goto out; | ||
438 | } | ||
439 | |||
440 | xiic_fill_tx_fifo(i2c); | ||
441 | |||
442 | /* current message sent and there is space in the fifo */ | ||
443 | if (!xiic_tx_space(i2c) && xiic_tx_fifo_space(i2c) >= 2) { | ||
444 | dev_dbg(i2c->adap.dev.parent, | ||
445 | "%s end of message sent, nmsgs: %d\n", | ||
446 | __func__, i2c->nmsgs); | ||
447 | if (i2c->nmsgs > 1) { | ||
448 | i2c->nmsgs--; | ||
449 | i2c->tx_msg++; | ||
450 | __xiic_start_xfer(i2c); | ||
451 | } else { | ||
452 | xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK); | ||
453 | |||
454 | dev_dbg(i2c->adap.dev.parent, | ||
455 | "%s Got TX IRQ but no more to do...\n", | ||
456 | __func__); | ||
457 | } | ||
458 | } else if (!xiic_tx_space(i2c) && (i2c->nmsgs == 1)) | ||
459 | /* current frame is sent and is last, | ||
460 | * make sure to disable tx half | ||
461 | */ | ||
462 | xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK); | ||
463 | } else { | ||
464 | /* got IRQ which is not acked */ | ||
465 | dev_err(i2c->adap.dev.parent, "%s Got unexpected IRQ\n", | ||
466 | __func__); | ||
467 | clr = pend; | ||
468 | } | ||
469 | out: | ||
470 | dev_dbg(i2c->adap.dev.parent, "%s clr: 0x%x\n", __func__, clr); | ||
471 | |||
472 | xiic_setreg32(i2c, XIIC_IISR_OFFSET, clr); | ||
473 | } | ||
474 | |||
475 | static int xiic_bus_busy(struct xiic_i2c *i2c) | ||
476 | { | ||
477 | u8 sr = xiic_getreg8(i2c, XIIC_SR_REG_OFFSET); | ||
478 | |||
479 | return (sr & XIIC_SR_BUS_BUSY_MASK) ? -EBUSY : 0; | ||
480 | } | ||
481 | |||
482 | static int xiic_busy(struct xiic_i2c *i2c) | ||
483 | { | ||
484 | int tries = 3; | ||
485 | int err; | ||
486 | |||
487 | if (i2c->tx_msg) | ||
488 | return -EBUSY; | ||
489 | |||
490 | /* for instance if previous transfer was terminated due to TX error | ||
491 | * it might be that the bus is on it's way to become available | ||
492 | * give it at most 3 ms to wake | ||
493 | */ | ||
494 | err = xiic_bus_busy(i2c); | ||
495 | while (err && tries--) { | ||
496 | mdelay(1); | ||
497 | err = xiic_bus_busy(i2c); | ||
498 | } | ||
499 | |||
500 | return err; | ||
501 | } | ||
502 | |||
503 | static void xiic_start_recv(struct xiic_i2c *i2c) | ||
504 | { | ||
505 | u8 rx_watermark; | ||
506 | struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg; | ||
507 | |||
508 | /* Clear and enable Rx full interrupt. */ | ||
509 | xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | XIIC_INTR_TX_ERROR_MASK); | ||
510 | |||
511 | /* we want to get all but last byte, because the TX_ERROR IRQ is used | ||
512 | * to inidicate error ACK on the address, and negative ack on the last | ||
513 | * received byte, so to not mix them receive all but last. | ||
514 | * In the case where there is only one byte to receive | ||
515 | * we can check if ERROR and RX full is set at the same time | ||
516 | */ | ||
517 | rx_watermark = msg->len; | ||
518 | if (rx_watermark > IIC_RX_FIFO_DEPTH) | ||
519 | rx_watermark = IIC_RX_FIFO_DEPTH; | ||
520 | xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rx_watermark - 1); | ||
521 | |||
522 | if (!(msg->flags & I2C_M_NOSTART)) | ||
523 | /* write the address */ | ||
524 | xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, | ||
525 | (msg->addr << 1) | XIIC_READ_OPERATION | | ||
526 | XIIC_TX_DYN_START_MASK); | ||
527 | |||
528 | xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); | ||
529 | |||
530 | xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, | ||
531 | msg->len | ((i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0)); | ||
532 | if (i2c->nmsgs == 1) | ||
533 | /* very last, enable bus not busy as well */ | ||
534 | xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); | ||
535 | |||
536 | /* the message is tx:ed */ | ||
537 | i2c->tx_pos = msg->len; | ||
538 | } | ||
539 | |||
540 | static void xiic_start_send(struct xiic_i2c *i2c) | ||
541 | { | ||
542 | struct i2c_msg *msg = i2c->tx_msg; | ||
543 | |||
544 | xiic_irq_clr(i2c, XIIC_INTR_TX_ERROR_MASK); | ||
545 | |||
546 | dev_dbg(i2c->adap.dev.parent, "%s entry, msg: %p, len: %d, " | ||
547 | "ISR: 0x%x, CR: 0x%x\n", | ||
548 | __func__, msg, msg->len, xiic_getreg32(i2c, XIIC_IISR_OFFSET), | ||
549 | xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); | ||
550 | |||
551 | if (!(msg->flags & I2C_M_NOSTART)) { | ||
552 | /* write the address */ | ||
553 | u16 data = ((msg->addr << 1) & 0xfe) | XIIC_WRITE_OPERATION | | ||
554 | XIIC_TX_DYN_START_MASK; | ||
555 | if ((i2c->nmsgs == 1) && msg->len == 0) | ||
556 | /* no data and last message -> add STOP */ | ||
557 | data |= XIIC_TX_DYN_STOP_MASK; | ||
558 | |||
559 | xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); | ||
560 | } | ||
561 | |||
562 | xiic_fill_tx_fifo(i2c); | ||
563 | |||
564 | /* Clear any pending Tx empty, Tx Error and then enable them. */ | ||
565 | xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_ERROR_MASK | | ||
566 | XIIC_INTR_BNB_MASK); | ||
567 | } | ||
568 | |||
569 | static irqreturn_t xiic_isr(int irq, void *dev_id) | ||
570 | { | ||
571 | struct xiic_i2c *i2c = dev_id; | ||
572 | |||
573 | spin_lock(&i2c->lock); | ||
574 | /* disable interrupts globally */ | ||
575 | xiic_setreg32(i2c, XIIC_DGIER_OFFSET, 0); | ||
576 | |||
577 | dev_dbg(i2c->adap.dev.parent, "%s entry\n", __func__); | ||
578 | |||
579 | xiic_process(i2c); | ||
580 | |||
581 | xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); | ||
582 | spin_unlock(&i2c->lock); | ||
583 | |||
584 | return IRQ_HANDLED; | ||
585 | } | ||
586 | |||
587 | static void __xiic_start_xfer(struct xiic_i2c *i2c) | ||
588 | { | ||
589 | int first = 1; | ||
590 | int fifo_space = xiic_tx_fifo_space(i2c); | ||
591 | dev_dbg(i2c->adap.dev.parent, "%s entry, msg: %p, fifos space: %d\n", | ||
592 | __func__, i2c->tx_msg, fifo_space); | ||
593 | |||
594 | if (!i2c->tx_msg) | ||
595 | return; | ||
596 | |||
597 | i2c->rx_pos = 0; | ||
598 | i2c->tx_pos = 0; | ||
599 | i2c->state = STATE_START; | ||
600 | while ((fifo_space >= 2) && (first || (i2c->nmsgs > 1))) { | ||
601 | if (!first) { | ||
602 | i2c->nmsgs--; | ||
603 | i2c->tx_msg++; | ||
604 | i2c->tx_pos = 0; | ||
605 | } else | ||
606 | first = 0; | ||
607 | |||
608 | if (i2c->tx_msg->flags & I2C_M_RD) { | ||
609 | /* we dont date putting several reads in the FIFO */ | ||
610 | xiic_start_recv(i2c); | ||
611 | return; | ||
612 | } else { | ||
613 | xiic_start_send(i2c); | ||
614 | if (xiic_tx_space(i2c) != 0) { | ||
615 | /* the message could not be completely sent */ | ||
616 | break; | ||
617 | } | ||
618 | } | ||
619 | |||
620 | fifo_space = xiic_tx_fifo_space(i2c); | ||
621 | } | ||
622 | |||
623 | /* there are more messages or the current one could not be completely | ||
624 | * put into the FIFO, also enable the half empty interrupt | ||
625 | */ | ||
626 | if (i2c->nmsgs > 1 || xiic_tx_space(i2c)) | ||
627 | xiic_irq_clr_en(i2c, XIIC_INTR_TX_HALF_MASK); | ||
628 | |||
629 | } | ||
630 | |||
631 | static void xiic_start_xfer(struct xiic_i2c *i2c) | ||
632 | { | ||
633 | unsigned long flags; | ||
634 | |||
635 | spin_lock_irqsave(&i2c->lock, flags); | ||
636 | xiic_reinit(i2c); | ||
637 | /* disable interrupts globally */ | ||
638 | xiic_setreg32(i2c, XIIC_DGIER_OFFSET, 0); | ||
639 | spin_unlock_irqrestore(&i2c->lock, flags); | ||
640 | |||
641 | __xiic_start_xfer(i2c); | ||
642 | xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); | ||
643 | } | ||
644 | |||
645 | static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | ||
646 | { | ||
647 | struct xiic_i2c *i2c = i2c_get_adapdata(adap); | ||
648 | int err; | ||
649 | |||
650 | dev_dbg(adap->dev.parent, "%s entry SR: 0x%x\n", __func__, | ||
651 | xiic_getreg8(i2c, XIIC_SR_REG_OFFSET)); | ||
652 | |||
653 | err = xiic_busy(i2c); | ||
654 | if (err) | ||
655 | return err; | ||
656 | |||
657 | i2c->tx_msg = msgs; | ||
658 | i2c->nmsgs = num; | ||
659 | |||
660 | xiic_start_xfer(i2c); | ||
661 | |||
662 | if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) || | ||
663 | (i2c->state == STATE_DONE), HZ)) | ||
664 | return (i2c->state == STATE_DONE) ? num : -EIO; | ||
665 | else { | ||
666 | i2c->tx_msg = NULL; | ||
667 | i2c->rx_msg = NULL; | ||
668 | i2c->nmsgs = 0; | ||
669 | return -ETIMEDOUT; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | static u32 xiic_func(struct i2c_adapter *adap) | ||
674 | { | ||
675 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | ||
676 | } | ||
677 | |||
678 | static const struct i2c_algorithm xiic_algorithm = { | ||
679 | .master_xfer = xiic_xfer, | ||
680 | .functionality = xiic_func, | ||
681 | }; | ||
682 | |||
683 | static struct i2c_adapter xiic_adapter = { | ||
684 | .owner = THIS_MODULE, | ||
685 | .name = DRIVER_NAME, | ||
686 | .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, | ||
687 | .algo = &xiic_algorithm, | ||
688 | }; | ||
689 | |||
690 | |||
691 | static int __devinit xiic_i2c_probe(struct platform_device *pdev) | ||
692 | { | ||
693 | struct xiic_i2c *i2c; | ||
694 | struct xiic_i2c_platform_data *pdata; | ||
695 | struct resource *res; | ||
696 | int ret, irq; | ||
697 | u8 i; | ||
698 | |||
699 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
700 | if (!res) | ||
701 | goto resource_missing; | ||
702 | |||
703 | irq = platform_get_irq(pdev, 0); | ||
704 | if (irq < 0) | ||
705 | goto resource_missing; | ||
706 | |||
707 | pdata = (struct xiic_i2c_platform_data *) pdev->dev.platform_data; | ||
708 | if (!pdata) | ||
709 | return -EINVAL; | ||
710 | |||
711 | i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); | ||
712 | if (!i2c) | ||
713 | return -ENOMEM; | ||
714 | |||
715 | if (!request_mem_region(res->start, resource_size(res), pdev->name)) { | ||
716 | dev_err(&pdev->dev, "Memory region busy\n"); | ||
717 | ret = -EBUSY; | ||
718 | goto request_mem_failed; | ||
719 | } | ||
720 | |||
721 | i2c->base = ioremap(res->start, resource_size(res)); | ||
722 | if (!i2c->base) { | ||
723 | dev_err(&pdev->dev, "Unable to map registers\n"); | ||
724 | ret = -EIO; | ||
725 | goto map_failed; | ||
726 | } | ||
727 | |||
728 | /* hook up driver to tree */ | ||
729 | platform_set_drvdata(pdev, i2c); | ||
730 | i2c->adap = xiic_adapter; | ||
731 | i2c_set_adapdata(&i2c->adap, i2c); | ||
732 | i2c->adap.dev.parent = &pdev->dev; | ||
733 | |||
734 | xiic_reinit(i2c); | ||
735 | |||
736 | spin_lock_init(&i2c->lock); | ||
737 | init_waitqueue_head(&i2c->wait); | ||
738 | ret = request_irq(irq, xiic_isr, 0, pdev->name, i2c); | ||
739 | if (ret) { | ||
740 | dev_err(&pdev->dev, "Cannot claim IRQ\n"); | ||
741 | goto request_irq_failed; | ||
742 | } | ||
743 | |||
744 | /* add i2c adapter to i2c tree */ | ||
745 | ret = i2c_add_adapter(&i2c->adap); | ||
746 | if (ret) { | ||
747 | dev_err(&pdev->dev, "Failed to add adapter\n"); | ||
748 | goto add_adapter_failed; | ||
749 | } | ||
750 | |||
751 | /* add in known devices to the bus */ | ||
752 | for (i = 0; i < pdata->num_devices; i++) | ||
753 | i2c_new_device(&i2c->adap, pdata->devices + i); | ||
754 | |||
755 | return 0; | ||
756 | |||
757 | add_adapter_failed: | ||
758 | free_irq(irq, i2c); | ||
759 | request_irq_failed: | ||
760 | xiic_deinit(i2c); | ||
761 | iounmap(i2c->base); | ||
762 | map_failed: | ||
763 | release_mem_region(res->start, resource_size(res)); | ||
764 | request_mem_failed: | ||
765 | kfree(i2c); | ||
766 | |||
767 | return ret; | ||
768 | resource_missing: | ||
769 | dev_err(&pdev->dev, "IRQ or Memory resource is missing\n"); | ||
770 | return -ENOENT; | ||
771 | } | ||
772 | |||
773 | static int __devexit xiic_i2c_remove(struct platform_device* pdev) | ||
774 | { | ||
775 | struct xiic_i2c *i2c = platform_get_drvdata(pdev); | ||
776 | struct resource *res; | ||
777 | |||
778 | /* remove adapter & data */ | ||
779 | i2c_del_adapter(&i2c->adap); | ||
780 | |||
781 | xiic_deinit(i2c); | ||
782 | |||
783 | platform_set_drvdata(pdev, NULL); | ||
784 | |||
785 | free_irq(platform_get_irq(pdev, 0), i2c); | ||
786 | |||
787 | iounmap(i2c->base); | ||
788 | |||
789 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
790 | if (res) | ||
791 | release_mem_region(res->start, resource_size(res)); | ||
792 | |||
793 | kfree(i2c); | ||
794 | |||
795 | return 0; | ||
796 | } | ||
797 | |||
798 | |||
799 | /* work with hotplug and coldplug */ | ||
800 | MODULE_ALIAS("platform:"DRIVER_NAME); | ||
801 | |||
802 | static struct platform_driver xiic_i2c_driver = { | ||
803 | .probe = xiic_i2c_probe, | ||
804 | .remove = __devexit_p(xiic_i2c_remove), | ||
805 | .driver = { | ||
806 | .owner = THIS_MODULE, | ||
807 | .name = DRIVER_NAME, | ||
808 | }, | ||
809 | }; | ||
810 | |||
811 | static int __init xiic_i2c_init(void) | ||
812 | { | ||
813 | return platform_driver_register(&xiic_i2c_driver); | ||
814 | } | ||
815 | |||
816 | static void __exit xiic_i2c_exit(void) | ||
817 | { | ||
818 | platform_driver_unregister(&xiic_i2c_driver); | ||
819 | } | ||
820 | |||
821 | module_init(xiic_i2c_init); | ||
822 | module_exit(xiic_i2c_exit); | ||
823 | |||
824 | MODULE_AUTHOR("info@mocean-labs.com"); | ||
825 | MODULE_DESCRIPTION("Xilinx I2C bus driver"); | ||
826 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c index 648ecc6f60e6..53fab518b3da 100644 --- a/drivers/i2c/busses/scx200_acb.c +++ b/drivers/i2c/busses/scx200_acb.c | |||
@@ -31,7 +31,8 @@ | |||
31 | #include <linux/pci.h> | 31 | #include <linux/pci.h> |
32 | #include <linux/delay.h> | 32 | #include <linux/delay.h> |
33 | #include <linux/mutex.h> | 33 | #include <linux/mutex.h> |
34 | #include <asm/io.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/io.h> | ||
35 | 36 | ||
36 | #include <linux/scx200.h> | 37 | #include <linux/scx200.h> |
37 | 38 | ||
@@ -217,8 +218,10 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status) | |||
217 | return; | 218 | return; |
218 | 219 | ||
219 | error: | 220 | error: |
220 | dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg, | 221 | dev_err(&iface->adapter.dev, |
221 | scx200_acb_state_name[iface->state]); | 222 | "%s in state %s (addr=0x%02x, len=%d, status=0x%02x)\n", errmsg, |
223 | scx200_acb_state_name[iface->state], iface->address_byte, | ||
224 | iface->len, status); | ||
222 | 225 | ||
223 | iface->state = state_idle; | 226 | iface->state = state_idle; |
224 | iface->result = -EIO; | 227 | iface->result = -EIO; |
@@ -549,7 +552,7 @@ static int __init scx200_create_isa(const char *text, unsigned long base, | |||
549 | * the name and the BAR where the I/O address resource is located. ISA | 552 | * the name and the BAR where the I/O address resource is located. ISA |
550 | * devices are flagged with a bar value of -1 */ | 553 | * devices are flagged with a bar value of -1 */ |
551 | 554 | ||
552 | static struct pci_device_id scx200_pci[] = { | 555 | static const struct pci_device_id scx200_pci[] __initconst = { |
553 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE), | 556 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE), |
554 | .driver_data = 0 }, | 557 | .driver_data = 0 }, |
555 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE), | 558 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE), |
@@ -557,7 +560,8 @@ static struct pci_device_id scx200_pci[] = { | |||
557 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA), | 560 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA), |
558 | .driver_data = 1 }, | 561 | .driver_data = 1 }, |
559 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA), | 562 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA), |
560 | .driver_data = 2 } | 563 | .driver_data = 2 }, |
564 | { 0, } | ||
561 | }; | 565 | }; |
562 | 566 | ||
563 | static struct { | 567 | static struct { |
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c index 42df0eca43d5..7ee0d502ceab 100644 --- a/drivers/i2c/busses/scx200_i2c.c +++ b/drivers/i2c/busses/scx200_i2c.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <linux/init.h> | 27 | #include <linux/init.h> |
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/i2c-algo-bit.h> | 29 | #include <linux/i2c-algo-bit.h> |
30 | #include <asm/io.h> | 30 | #include <linux/io.h> |
31 | 31 | ||
32 | #include <linux/scx200_gpio.h> | 32 | #include <linux/scx200_gpio.h> |
33 | 33 | ||
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig deleted file mode 100644 index 02d746c9c474..000000000000 --- a/drivers/i2c/chips/Kconfig +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | # | ||
2 | # Miscellaneous I2C chip drivers configuration | ||
3 | # | ||
4 | # *** DEPRECATED! Do not add new entries! See Makefile *** | ||
5 | # | ||
6 | |||
7 | menu "Miscellaneous I2C Chip support" | ||
8 | |||
9 | config DS1682 | ||
10 | tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm" | ||
11 | depends on EXPERIMENTAL | ||
12 | help | ||
13 | If you say yes here you get support for Dallas Semiconductor | ||
14 | DS1682 Total Elapsed Time Recorder. | ||
15 | |||
16 | This driver can also be built as a module. If so, the module | ||
17 | will be called ds1682. | ||
18 | |||
19 | config SENSORS_PCF8574 | ||
20 | tristate "Philips PCF8574 and PCF8574A (DEPRECATED)" | ||
21 | depends on EXPERIMENTAL && GPIO_PCF857X = "n" | ||
22 | default n | ||
23 | help | ||
24 | If you say yes here you get support for Philips PCF8574 and | ||
25 | PCF8574A chips. These chips are 8-bit I/O expanders for the I2C bus. | ||
26 | |||
27 | This driver can also be built as a module. If so, the module | ||
28 | will be called pcf8574. | ||
29 | |||
30 | This driver is deprecated and will be dropped soon. Use | ||
31 | drivers/gpio/pcf857x.c instead. | ||
32 | |||
33 | These devices are hard to detect and rarely found on mainstream | ||
34 | hardware. If unsure, say N. | ||
35 | |||
36 | config PCF8575 | ||
37 | tristate "Philips PCF8575 (DEPRECATED)" | ||
38 | default n | ||
39 | depends on GPIO_PCF857X = "n" | ||
40 | help | ||
41 | If you say yes here you get support for Philips PCF8575 chip. | ||
42 | This chip is a 16-bit I/O expander for the I2C bus. Several other | ||
43 | chip manufacturers sell equivalent chips, e.g. Texas Instruments. | ||
44 | |||
45 | This driver can also be built as a module. If so, the module | ||
46 | will be called pcf8575. | ||
47 | |||
48 | This driver is deprecated and will be dropped soon. Use | ||
49 | drivers/gpio/pcf857x.c instead. | ||
50 | |||
51 | This device is hard to detect and is rarely found on mainstream | ||
52 | hardware. If unsure, say N. | ||
53 | |||
54 | config SENSORS_PCA9539 | ||
55 | tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)" | ||
56 | depends on EXPERIMENTAL && GPIO_PCA953X = "n" | ||
57 | help | ||
58 | If you say yes here you get support for the Philips PCA9539 | ||
59 | 16-bit I/O port. | ||
60 | |||
61 | This driver can also be built as a module. If so, the module | ||
62 | will be called pca9539. | ||
63 | |||
64 | This driver is deprecated and will be dropped soon. Use | ||
65 | drivers/gpio/pca953x.c instead. | ||
66 | |||
67 | config SENSORS_TSL2550 | ||
68 | tristate "Taos TSL2550 ambient light sensor" | ||
69 | depends on EXPERIMENTAL | ||
70 | help | ||
71 | If you say yes here you get support for the Taos TSL2550 | ||
72 | ambient light sensor. | ||
73 | |||
74 | This driver can also be built as a module. If so, the module | ||
75 | will be called tsl2550. | ||
76 | |||
77 | endmenu | ||
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile deleted file mode 100644 index f4680d16ee34..000000000000 --- a/drivers/i2c/chips/Makefile +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for miscellaneous I2C chip drivers. | ||
3 | # | ||
4 | # Do not add new drivers to this directory! It is DEPRECATED. | ||
5 | # | ||
6 | # Device drivers are better grouped according to the functionality they | ||
7 | # implement rather than to the bus they are connected to. In particular: | ||
8 | # * Hardware monitoring chip drivers go to drivers/hwmon | ||
9 | # * RTC chip drivers go to drivers/rtc | ||
10 | # * I/O expander drivers go to drivers/gpio | ||
11 | # | ||
12 | |||
13 | obj-$(CONFIG_DS1682) += ds1682.o | ||
14 | obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o | ||
15 | obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o | ||
16 | obj-$(CONFIG_PCF8575) += pcf8575.o | ||
17 | obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o | ||
18 | |||
19 | ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) | ||
20 | EXTRA_CFLAGS += -DDEBUG | ||
21 | endif | ||
22 | |||
diff --git a/drivers/i2c/chips/ds1682.c b/drivers/i2c/chips/ds1682.c deleted file mode 100644 index f3ee4a1abb77..000000000000 --- a/drivers/i2c/chips/ds1682.c +++ /dev/null | |||
@@ -1,267 +0,0 @@ | |||
1 | /* | ||
2 | * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver | ||
3 | * | ||
4 | * Written by: Grant Likely <grant.likely@secretlab.ca> | ||
5 | * | ||
6 | * Copyright (C) 2007 Secret Lab Technologies Ltd. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * The DS1682 elapsed timer recorder is a simple device that implements | ||
15 | * one elapsed time counter, one event counter, an alarm signal and 10 | ||
16 | * bytes of general purpose EEPROM. | ||
17 | * | ||
18 | * This driver provides access to the DS1682 counters and user data via | ||
19 | * the sysfs. The following attributes are added to the device node: | ||
20 | * elapsed_time (u32): Total elapsed event time in ms resolution | ||
21 | * alarm_time (u32): When elapsed time exceeds the value in alarm_time, | ||
22 | * then the alarm pin is asserted. | ||
23 | * event_count (u16): number of times the event pin has gone low. | ||
24 | * eeprom (u8[10]): general purpose EEPROM | ||
25 | * | ||
26 | * Counter registers and user data are both read/write unless the device | ||
27 | * has been write protected. This driver does not support turning off write | ||
28 | * protection. Once write protection is turned on, it is impossible to | ||
29 | * turn it off again, so I have left the feature out of this driver to avoid | ||
30 | * accidental enabling, but it is trivial to add write protect support. | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include <linux/module.h> | ||
35 | #include <linux/init.h> | ||
36 | #include <linux/slab.h> | ||
37 | #include <linux/i2c.h> | ||
38 | #include <linux/string.h> | ||
39 | #include <linux/list.h> | ||
40 | #include <linux/sysfs.h> | ||
41 | #include <linux/ctype.h> | ||
42 | #include <linux/hwmon-sysfs.h> | ||
43 | |||
44 | /* Device registers */ | ||
45 | #define DS1682_REG_CONFIG 0x00 | ||
46 | #define DS1682_REG_ALARM 0x01 | ||
47 | #define DS1682_REG_ELAPSED 0x05 | ||
48 | #define DS1682_REG_EVT_CNTR 0x09 | ||
49 | #define DS1682_REG_EEPROM 0x0b | ||
50 | #define DS1682_REG_RESET 0x1d | ||
51 | #define DS1682_REG_WRITE_DISABLE 0x1e | ||
52 | #define DS1682_REG_WRITE_MEM_DISABLE 0x1f | ||
53 | |||
54 | #define DS1682_EEPROM_SIZE 10 | ||
55 | |||
56 | /* | ||
57 | * Generic counter attributes | ||
58 | */ | ||
59 | static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr, | ||
60 | char *buf) | ||
61 | { | ||
62 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); | ||
63 | struct i2c_client *client = to_i2c_client(dev); | ||
64 | __le32 val = 0; | ||
65 | int rc; | ||
66 | |||
67 | dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name); | ||
68 | |||
69 | /* Read the register */ | ||
70 | rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr, | ||
71 | (u8 *) & val); | ||
72 | if (rc < 0) | ||
73 | return -EIO; | ||
74 | |||
75 | /* Special case: the 32 bit regs are time values with 1/4s | ||
76 | * resolution, scale them up to milliseconds */ | ||
77 | if (sattr->nr == 4) | ||
78 | return sprintf(buf, "%llu\n", | ||
79 | ((unsigned long long)le32_to_cpu(val)) * 250); | ||
80 | |||
81 | /* Format the output string and return # of bytes */ | ||
82 | return sprintf(buf, "%li\n", (long)le32_to_cpu(val)); | ||
83 | } | ||
84 | |||
85 | static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr, | ||
86 | const char *buf, size_t count) | ||
87 | { | ||
88 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); | ||
89 | struct i2c_client *client = to_i2c_client(dev); | ||
90 | char *endp; | ||
91 | u64 val; | ||
92 | __le32 val_le; | ||
93 | int rc; | ||
94 | |||
95 | dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name); | ||
96 | |||
97 | /* Decode input */ | ||
98 | val = simple_strtoull(buf, &endp, 0); | ||
99 | if (buf == endp) { | ||
100 | dev_dbg(dev, "input string not a number\n"); | ||
101 | return -EINVAL; | ||
102 | } | ||
103 | |||
104 | /* Special case: the 32 bit regs are time values with 1/4s | ||
105 | * resolution, scale input down to quarter-seconds */ | ||
106 | if (sattr->nr == 4) | ||
107 | do_div(val, 250); | ||
108 | |||
109 | /* write out the value */ | ||
110 | val_le = cpu_to_le32(val); | ||
111 | rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr, | ||
112 | (u8 *) & val_le); | ||
113 | if (rc < 0) { | ||
114 | dev_err(dev, "register write failed; reg=0x%x, size=%i\n", | ||
115 | sattr->index, sattr->nr); | ||
116 | return -EIO; | ||
117 | } | ||
118 | |||
119 | return count; | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * Simple register attributes | ||
124 | */ | ||
125 | static SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, | ||
126 | ds1682_store, 4, DS1682_REG_ELAPSED); | ||
127 | static SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, | ||
128 | ds1682_store, 4, DS1682_REG_ALARM); | ||
129 | static SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show, | ||
130 | ds1682_store, 2, DS1682_REG_EVT_CNTR); | ||
131 | |||
132 | static const struct attribute_group ds1682_group = { | ||
133 | .attrs = (struct attribute *[]) { | ||
134 | &sensor_dev_attr_elapsed_time.dev_attr.attr, | ||
135 | &sensor_dev_attr_alarm_time.dev_attr.attr, | ||
136 | &sensor_dev_attr_event_count.dev_attr.attr, | ||
137 | NULL, | ||
138 | }, | ||
139 | }; | ||
140 | |||
141 | /* | ||
142 | * User data attribute | ||
143 | */ | ||
144 | static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *attr, | ||
145 | char *buf, loff_t off, size_t count) | ||
146 | { | ||
147 | struct i2c_client *client = kobj_to_i2c_client(kobj); | ||
148 | int rc; | ||
149 | |||
150 | dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n", | ||
151 | buf, off, count); | ||
152 | |||
153 | if (off >= DS1682_EEPROM_SIZE) | ||
154 | return 0; | ||
155 | |||
156 | if (off + count > DS1682_EEPROM_SIZE) | ||
157 | count = DS1682_EEPROM_SIZE - off; | ||
158 | |||
159 | rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off, | ||
160 | count, buf); | ||
161 | if (rc < 0) | ||
162 | return -EIO; | ||
163 | |||
164 | return count; | ||
165 | } | ||
166 | |||
167 | static ssize_t ds1682_eeprom_write(struct kobject *kobj, struct bin_attribute *attr, | ||
168 | char *buf, loff_t off, size_t count) | ||
169 | { | ||
170 | struct i2c_client *client = kobj_to_i2c_client(kobj); | ||
171 | |||
172 | dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n", | ||
173 | buf, off, count); | ||
174 | |||
175 | if (off >= DS1682_EEPROM_SIZE) | ||
176 | return -ENOSPC; | ||
177 | |||
178 | if (off + count > DS1682_EEPROM_SIZE) | ||
179 | count = DS1682_EEPROM_SIZE - off; | ||
180 | |||
181 | /* Write out to the device */ | ||
182 | if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off, | ||
183 | count, buf) < 0) | ||
184 | return -EIO; | ||
185 | |||
186 | return count; | ||
187 | } | ||
188 | |||
189 | static struct bin_attribute ds1682_eeprom_attr = { | ||
190 | .attr = { | ||
191 | .name = "eeprom", | ||
192 | .mode = S_IRUGO | S_IWUSR, | ||
193 | }, | ||
194 | .size = DS1682_EEPROM_SIZE, | ||
195 | .read = ds1682_eeprom_read, | ||
196 | .write = ds1682_eeprom_write, | ||
197 | }; | ||
198 | |||
199 | /* | ||
200 | * Called when a ds1682 device is matched with this driver | ||
201 | */ | ||
202 | static int ds1682_probe(struct i2c_client *client, | ||
203 | const struct i2c_device_id *id) | ||
204 | { | ||
205 | int rc; | ||
206 | |||
207 | if (!i2c_check_functionality(client->adapter, | ||
208 | I2C_FUNC_SMBUS_I2C_BLOCK)) { | ||
209 | dev_err(&client->dev, "i2c bus does not support the ds1682\n"); | ||
210 | rc = -ENODEV; | ||
211 | goto exit; | ||
212 | } | ||
213 | |||
214 | rc = sysfs_create_group(&client->dev.kobj, &ds1682_group); | ||
215 | if (rc) | ||
216 | goto exit; | ||
217 | |||
218 | rc = sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr); | ||
219 | if (rc) | ||
220 | goto exit_bin_attr; | ||
221 | |||
222 | return 0; | ||
223 | |||
224 | exit_bin_attr: | ||
225 | sysfs_remove_group(&client->dev.kobj, &ds1682_group); | ||
226 | exit: | ||
227 | return rc; | ||
228 | } | ||
229 | |||
230 | static int ds1682_remove(struct i2c_client *client) | ||
231 | { | ||
232 | sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr); | ||
233 | sysfs_remove_group(&client->dev.kobj, &ds1682_group); | ||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static const struct i2c_device_id ds1682_id[] = { | ||
238 | { "ds1682", 0 }, | ||
239 | { } | ||
240 | }; | ||
241 | MODULE_DEVICE_TABLE(i2c, ds1682_id); | ||
242 | |||
243 | static struct i2c_driver ds1682_driver = { | ||
244 | .driver = { | ||
245 | .name = "ds1682", | ||
246 | }, | ||
247 | .probe = ds1682_probe, | ||
248 | .remove = ds1682_remove, | ||
249 | .id_table = ds1682_id, | ||
250 | }; | ||
251 | |||
252 | static int __init ds1682_init(void) | ||
253 | { | ||
254 | return i2c_add_driver(&ds1682_driver); | ||
255 | } | ||
256 | |||
257 | static void __exit ds1682_exit(void) | ||
258 | { | ||
259 | i2c_del_driver(&ds1682_driver); | ||
260 | } | ||
261 | |||
262 | MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); | ||
263 | MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver"); | ||
264 | MODULE_LICENSE("GPL"); | ||
265 | |||
266 | module_init(ds1682_init); | ||
267 | module_exit(ds1682_exit); | ||
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c deleted file mode 100644 index 270de4e56a81..000000000000 --- a/drivers/i2c/chips/pca9539.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* | ||
2 | pca9539.c - 16-bit I/O port with interrupt and reset | ||
3 | |||
4 | Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; version 2 of the License. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/i2c.h> | ||
15 | #include <linux/hwmon-sysfs.h> | ||
16 | |||
17 | /* Addresses to scan: none, device is not autodetected */ | ||
18 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
19 | |||
20 | /* Insmod parameters */ | ||
21 | I2C_CLIENT_INSMOD_1(pca9539); | ||
22 | |||
23 | enum pca9539_cmd | ||
24 | { | ||
25 | PCA9539_INPUT_0 = 0, | ||
26 | PCA9539_INPUT_1 = 1, | ||
27 | PCA9539_OUTPUT_0 = 2, | ||
28 | PCA9539_OUTPUT_1 = 3, | ||
29 | PCA9539_INVERT_0 = 4, | ||
30 | PCA9539_INVERT_1 = 5, | ||
31 | PCA9539_DIRECTION_0 = 6, | ||
32 | PCA9539_DIRECTION_1 = 7, | ||
33 | }; | ||
34 | |||
35 | /* following are the sysfs callback functions */ | ||
36 | static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, | ||
37 | char *buf) | ||
38 | { | ||
39 | struct sensor_device_attribute *psa = to_sensor_dev_attr(attr); | ||
40 | struct i2c_client *client = to_i2c_client(dev); | ||
41 | return sprintf(buf, "%d\n", i2c_smbus_read_byte_data(client, | ||
42 | psa->index)); | ||
43 | } | ||
44 | |||
45 | static ssize_t pca9539_store(struct device *dev, struct device_attribute *attr, | ||
46 | const char *buf, size_t count) | ||
47 | { | ||
48 | struct sensor_device_attribute *psa = to_sensor_dev_attr(attr); | ||
49 | struct i2c_client *client = to_i2c_client(dev); | ||
50 | unsigned long val = simple_strtoul(buf, NULL, 0); | ||
51 | if (val > 0xff) | ||
52 | return -EINVAL; | ||
53 | i2c_smbus_write_byte_data(client, psa->index, val); | ||
54 | return count; | ||
55 | } | ||
56 | |||
57 | /* Define the device attributes */ | ||
58 | |||
59 | #define PCA9539_ENTRY_RO(name, cmd_idx) \ | ||
60 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, pca9539_show, NULL, cmd_idx) | ||
61 | |||
62 | #define PCA9539_ENTRY_RW(name, cmd_idx) \ | ||
63 | static SENSOR_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, pca9539_show, \ | ||
64 | pca9539_store, cmd_idx) | ||
65 | |||
66 | PCA9539_ENTRY_RO(input0, PCA9539_INPUT_0); | ||
67 | PCA9539_ENTRY_RO(input1, PCA9539_INPUT_1); | ||
68 | PCA9539_ENTRY_RW(output0, PCA9539_OUTPUT_0); | ||
69 | PCA9539_ENTRY_RW(output1, PCA9539_OUTPUT_1); | ||
70 | PCA9539_ENTRY_RW(invert0, PCA9539_INVERT_0); | ||
71 | PCA9539_ENTRY_RW(invert1, PCA9539_INVERT_1); | ||
72 | PCA9539_ENTRY_RW(direction0, PCA9539_DIRECTION_0); | ||
73 | PCA9539_ENTRY_RW(direction1, PCA9539_DIRECTION_1); | ||
74 | |||
75 | static struct attribute *pca9539_attributes[] = { | ||
76 | &sensor_dev_attr_input0.dev_attr.attr, | ||
77 | &sensor_dev_attr_input1.dev_attr.attr, | ||
78 | &sensor_dev_attr_output0.dev_attr.attr, | ||
79 | &sensor_dev_attr_output1.dev_attr.attr, | ||
80 | &sensor_dev_attr_invert0.dev_attr.attr, | ||
81 | &sensor_dev_attr_invert1.dev_attr.attr, | ||
82 | &sensor_dev_attr_direction0.dev_attr.attr, | ||
83 | &sensor_dev_attr_direction1.dev_attr.attr, | ||
84 | NULL | ||
85 | }; | ||
86 | |||
87 | static struct attribute_group pca9539_defattr_group = { | ||
88 | .attrs = pca9539_attributes, | ||
89 | }; | ||
90 | |||
91 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
92 | static int pca9539_detect(struct i2c_client *client, int kind, | ||
93 | struct i2c_board_info *info) | ||
94 | { | ||
95 | struct i2c_adapter *adapter = client->adapter; | ||
96 | |||
97 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
98 | return -ENODEV; | ||
99 | |||
100 | strlcpy(info->type, "pca9539", I2C_NAME_SIZE); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int pca9539_probe(struct i2c_client *client, | ||
106 | const struct i2c_device_id *id) | ||
107 | { | ||
108 | /* Register sysfs hooks */ | ||
109 | return sysfs_create_group(&client->dev.kobj, | ||
110 | &pca9539_defattr_group); | ||
111 | } | ||
112 | |||
113 | static int pca9539_remove(struct i2c_client *client) | ||
114 | { | ||
115 | sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static const struct i2c_device_id pca9539_id[] = { | ||
120 | { "pca9539", 0 }, | ||
121 | { } | ||
122 | }; | ||
123 | |||
124 | static struct i2c_driver pca9539_driver = { | ||
125 | .driver = { | ||
126 | .name = "pca9539", | ||
127 | }, | ||
128 | .probe = pca9539_probe, | ||
129 | .remove = pca9539_remove, | ||
130 | .id_table = pca9539_id, | ||
131 | |||
132 | .detect = pca9539_detect, | ||
133 | .address_data = &addr_data, | ||
134 | }; | ||
135 | |||
136 | static int __init pca9539_init(void) | ||
137 | { | ||
138 | return i2c_add_driver(&pca9539_driver); | ||
139 | } | ||
140 | |||
141 | static void __exit pca9539_exit(void) | ||
142 | { | ||
143 | i2c_del_driver(&pca9539_driver); | ||
144 | } | ||
145 | |||
146 | MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>"); | ||
147 | MODULE_DESCRIPTION("PCA9539 driver"); | ||
148 | MODULE_LICENSE("GPL"); | ||
149 | |||
150 | module_init(pca9539_init); | ||
151 | module_exit(pca9539_exit); | ||
152 | |||
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c deleted file mode 100644 index 6ec309894c88..000000000000 --- a/drivers/i2c/chips/pcf8574.c +++ /dev/null | |||
@@ -1,215 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>, | ||
3 | Philip Edelbrock <phil@netroedge.com>, | ||
4 | Dan Eaton <dan.eaton@rocketlogix.com> | ||
5 | Ported to Linux 2.6 by Aurelien Jarno <aurel32@debian.org> with | ||
6 | the help of Jean Delvare <khali@linux-fr.org> | ||
7 | |||
8 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | /* A few notes about the PCF8574: | ||
24 | |||
25 | * The PCF8574 is an 8-bit I/O expander for the I2C bus produced by | ||
26 | Philips Semiconductors. It is designed to provide a byte I2C | ||
27 | interface to up to 8 separate devices. | ||
28 | |||
29 | * The PCF8574 appears as a very simple SMBus device which can be | ||
30 | read from or written to with SMBUS byte read/write accesses. | ||
31 | |||
32 | --Dan | ||
33 | |||
34 | */ | ||
35 | |||
36 | #include <linux/module.h> | ||
37 | #include <linux/init.h> | ||
38 | #include <linux/slab.h> | ||
39 | #include <linux/i2c.h> | ||
40 | |||
41 | /* Addresses to scan: none, device can't be detected */ | ||
42 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
43 | |||
44 | /* Insmod parameters */ | ||
45 | I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); | ||
46 | |||
47 | /* Each client has this additional data */ | ||
48 | struct pcf8574_data { | ||
49 | int write; /* Remember last written value */ | ||
50 | }; | ||
51 | |||
52 | static void pcf8574_init_client(struct i2c_client *client); | ||
53 | |||
54 | /* following are the sysfs callback functions */ | ||
55 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) | ||
56 | { | ||
57 | struct i2c_client *client = to_i2c_client(dev); | ||
58 | return sprintf(buf, "%u\n", i2c_smbus_read_byte(client)); | ||
59 | } | ||
60 | |||
61 | static DEVICE_ATTR(read, S_IRUGO, show_read, NULL); | ||
62 | |||
63 | static ssize_t show_write(struct device *dev, struct device_attribute *attr, char *buf) | ||
64 | { | ||
65 | struct pcf8574_data *data = i2c_get_clientdata(to_i2c_client(dev)); | ||
66 | |||
67 | if (data->write < 0) | ||
68 | return data->write; | ||
69 | |||
70 | return sprintf(buf, "%d\n", data->write); | ||
71 | } | ||
72 | |||
73 | static ssize_t set_write(struct device *dev, struct device_attribute *attr, const char *buf, | ||
74 | size_t count) | ||
75 | { | ||
76 | struct i2c_client *client = to_i2c_client(dev); | ||
77 | struct pcf8574_data *data = i2c_get_clientdata(client); | ||
78 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
79 | |||
80 | if (val > 0xff) | ||
81 | return -EINVAL; | ||
82 | |||
83 | data->write = val; | ||
84 | i2c_smbus_write_byte(client, data->write); | ||
85 | return count; | ||
86 | } | ||
87 | |||
88 | static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); | ||
89 | |||
90 | static struct attribute *pcf8574_attributes[] = { | ||
91 | &dev_attr_read.attr, | ||
92 | &dev_attr_write.attr, | ||
93 | NULL | ||
94 | }; | ||
95 | |||
96 | static const struct attribute_group pcf8574_attr_group = { | ||
97 | .attrs = pcf8574_attributes, | ||
98 | }; | ||
99 | |||
100 | /* | ||
101 | * Real code | ||
102 | */ | ||
103 | |||
104 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
105 | static int pcf8574_detect(struct i2c_client *client, int kind, | ||
106 | struct i2c_board_info *info) | ||
107 | { | ||
108 | struct i2c_adapter *adapter = client->adapter; | ||
109 | const char *client_name; | ||
110 | |||
111 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | ||
112 | return -ENODEV; | ||
113 | |||
114 | /* Now, we would do the remaining detection. But the PCF8574 is plainly | ||
115 | impossible to detect! Stupid chip. */ | ||
116 | |||
117 | /* Determine the chip type */ | ||
118 | if (kind <= 0) { | ||
119 | if (client->addr >= 0x38 && client->addr <= 0x3f) | ||
120 | kind = pcf8574a; | ||
121 | else | ||
122 | kind = pcf8574; | ||
123 | } | ||
124 | |||
125 | if (kind == pcf8574a) | ||
126 | client_name = "pcf8574a"; | ||
127 | else | ||
128 | client_name = "pcf8574"; | ||
129 | strlcpy(info->type, client_name, I2C_NAME_SIZE); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static int pcf8574_probe(struct i2c_client *client, | ||
135 | const struct i2c_device_id *id) | ||
136 | { | ||
137 | struct pcf8574_data *data; | ||
138 | int err; | ||
139 | |||
140 | data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL); | ||
141 | if (!data) { | ||
142 | err = -ENOMEM; | ||
143 | goto exit; | ||
144 | } | ||
145 | |||
146 | i2c_set_clientdata(client, data); | ||
147 | |||
148 | /* Initialize the PCF8574 chip */ | ||
149 | pcf8574_init_client(client); | ||
150 | |||
151 | /* Register sysfs hooks */ | ||
152 | err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); | ||
153 | if (err) | ||
154 | goto exit_free; | ||
155 | return 0; | ||
156 | |||
157 | exit_free: | ||
158 | kfree(data); | ||
159 | exit: | ||
160 | return err; | ||
161 | } | ||
162 | |||
163 | static int pcf8574_remove(struct i2c_client *client) | ||
164 | { | ||
165 | sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); | ||
166 | kfree(i2c_get_clientdata(client)); | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* Called when we have found a new PCF8574. */ | ||
171 | static void pcf8574_init_client(struct i2c_client *client) | ||
172 | { | ||
173 | struct pcf8574_data *data = i2c_get_clientdata(client); | ||
174 | data->write = -EAGAIN; | ||
175 | } | ||
176 | |||
177 | static const struct i2c_device_id pcf8574_id[] = { | ||
178 | { "pcf8574", 0 }, | ||
179 | { "pcf8574a", 0 }, | ||
180 | { } | ||
181 | }; | ||
182 | |||
183 | static struct i2c_driver pcf8574_driver = { | ||
184 | .driver = { | ||
185 | .name = "pcf8574", | ||
186 | }, | ||
187 | .probe = pcf8574_probe, | ||
188 | .remove = pcf8574_remove, | ||
189 | .id_table = pcf8574_id, | ||
190 | |||
191 | .detect = pcf8574_detect, | ||
192 | .address_data = &addr_data, | ||
193 | }; | ||
194 | |||
195 | static int __init pcf8574_init(void) | ||
196 | { | ||
197 | return i2c_add_driver(&pcf8574_driver); | ||
198 | } | ||
199 | |||
200 | static void __exit pcf8574_exit(void) | ||
201 | { | ||
202 | i2c_del_driver(&pcf8574_driver); | ||
203 | } | ||
204 | |||
205 | |||
206 | MODULE_AUTHOR | ||
207 | ("Frodo Looijaard <frodol@dds.nl>, " | ||
208 | "Philip Edelbrock <phil@netroedge.com>, " | ||
209 | "Dan Eaton <dan.eaton@rocketlogix.com> " | ||
210 | "and Aurelien Jarno <aurelien@aurel32.net>"); | ||
211 | MODULE_DESCRIPTION("PCF8574 driver"); | ||
212 | MODULE_LICENSE("GPL"); | ||
213 | |||
214 | module_init(pcf8574_init); | ||
215 | module_exit(pcf8574_exit); | ||
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c deleted file mode 100644 index 07fd7cb3c57d..000000000000 --- a/drivers/i2c/chips/pcf8575.c +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /* | ||
2 | pcf8575.c | ||
3 | |||
4 | About the PCF8575 chip: the PCF8575 is a 16-bit I/O expander for the I2C bus | ||
5 | produced by a.o. Philips Semiconductors. | ||
6 | |||
7 | Copyright (C) 2006 Michael Hennerich, Analog Devices Inc. | ||
8 | <hennerich@blackfin.uclinux.org> | ||
9 | Based on pcf8574.c. | ||
10 | |||
11 | Copyright (c) 2007 Bart Van Assche <bart.vanassche@gmail.com>. | ||
12 | Ported this driver from ucLinux to the mainstream Linux kernel. | ||
13 | |||
14 | This program is free software; you can redistribute it and/or modify | ||
15 | it under the terms of the GNU General Public License as published by | ||
16 | the Free Software Foundation; either version 2 of the License, or | ||
17 | (at your option) any later version. | ||
18 | |||
19 | This program is distributed in the hope that it will be useful, | ||
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | GNU General Public License for more details. | ||
23 | |||
24 | You should have received a copy of the GNU General Public License | ||
25 | along with this program; if not, write to the Free Software | ||
26 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
27 | */ | ||
28 | |||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/i2c.h> | ||
32 | #include <linux/slab.h> /* kzalloc() */ | ||
33 | #include <linux/sysfs.h> /* sysfs_create_group() */ | ||
34 | |||
35 | /* Addresses to scan: none, device can't be detected */ | ||
36 | static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; | ||
37 | |||
38 | /* Insmod parameters */ | ||
39 | I2C_CLIENT_INSMOD; | ||
40 | |||
41 | |||
42 | /* Each client has this additional data */ | ||
43 | struct pcf8575_data { | ||
44 | int write; /* last written value, or error code */ | ||
45 | }; | ||
46 | |||
47 | /* following are the sysfs callback functions */ | ||
48 | static ssize_t show_read(struct device *dev, struct device_attribute *attr, | ||
49 | char *buf) | ||
50 | { | ||
51 | struct i2c_client *client = to_i2c_client(dev); | ||
52 | u16 val; | ||
53 | u8 iopin_state[2]; | ||
54 | |||
55 | i2c_master_recv(client, iopin_state, 2); | ||
56 | |||
57 | val = iopin_state[0]; | ||
58 | val |= iopin_state[1] << 8; | ||
59 | |||
60 | return sprintf(buf, "%u\n", val); | ||
61 | } | ||
62 | |||
63 | static DEVICE_ATTR(read, S_IRUGO, show_read, NULL); | ||
64 | |||
65 | static ssize_t show_write(struct device *dev, struct device_attribute *attr, | ||
66 | char *buf) | ||
67 | { | ||
68 | struct pcf8575_data *data = dev_get_drvdata(dev); | ||
69 | if (data->write < 0) | ||
70 | return data->write; | ||
71 | return sprintf(buf, "%d\n", data->write); | ||
72 | } | ||
73 | |||
74 | static ssize_t set_write(struct device *dev, struct device_attribute *attr, | ||
75 | const char *buf, size_t count) | ||
76 | { | ||
77 | struct i2c_client *client = to_i2c_client(dev); | ||
78 | struct pcf8575_data *data = i2c_get_clientdata(client); | ||
79 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
80 | u8 iopin_state[2]; | ||
81 | |||
82 | if (val > 0xffff) | ||
83 | return -EINVAL; | ||
84 | |||
85 | data->write = val; | ||
86 | |||
87 | iopin_state[0] = val & 0xFF; | ||
88 | iopin_state[1] = val >> 8; | ||
89 | |||
90 | i2c_master_send(client, iopin_state, 2); | ||
91 | |||
92 | return count; | ||
93 | } | ||
94 | |||
95 | static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write); | ||
96 | |||
97 | static struct attribute *pcf8575_attributes[] = { | ||
98 | &dev_attr_read.attr, | ||
99 | &dev_attr_write.attr, | ||
100 | NULL | ||
101 | }; | ||
102 | |||
103 | static const struct attribute_group pcf8575_attr_group = { | ||
104 | .attrs = pcf8575_attributes, | ||
105 | }; | ||
106 | |||
107 | /* | ||
108 | * Real code | ||
109 | */ | ||
110 | |||
111 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
112 | static int pcf8575_detect(struct i2c_client *client, int kind, | ||
113 | struct i2c_board_info *info) | ||
114 | { | ||
115 | struct i2c_adapter *adapter = client->adapter; | ||
116 | |||
117 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) | ||
118 | return -ENODEV; | ||
119 | |||
120 | /* This is the place to detect whether the chip at the specified | ||
121 | address really is a PCF8575 chip. However, there is no method known | ||
122 | to detect whether an I2C chip is a PCF8575 or any other I2C chip. */ | ||
123 | |||
124 | strlcpy(info->type, "pcf8575", I2C_NAME_SIZE); | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | static int pcf8575_probe(struct i2c_client *client, | ||
130 | const struct i2c_device_id *id) | ||
131 | { | ||
132 | struct pcf8575_data *data; | ||
133 | int err; | ||
134 | |||
135 | data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); | ||
136 | if (!data) { | ||
137 | err = -ENOMEM; | ||
138 | goto exit; | ||
139 | } | ||
140 | |||
141 | i2c_set_clientdata(client, data); | ||
142 | data->write = -EAGAIN; | ||
143 | |||
144 | /* Register sysfs hooks */ | ||
145 | err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); | ||
146 | if (err) | ||
147 | goto exit_free; | ||
148 | |||
149 | return 0; | ||
150 | |||
151 | exit_free: | ||
152 | kfree(data); | ||
153 | exit: | ||
154 | return err; | ||
155 | } | ||
156 | |||
157 | static int pcf8575_remove(struct i2c_client *client) | ||
158 | { | ||
159 | sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); | ||
160 | kfree(i2c_get_clientdata(client)); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static const struct i2c_device_id pcf8575_id[] = { | ||
165 | { "pcf8575", 0 }, | ||
166 | { } | ||
167 | }; | ||
168 | |||
169 | static struct i2c_driver pcf8575_driver = { | ||
170 | .driver = { | ||
171 | .owner = THIS_MODULE, | ||
172 | .name = "pcf8575", | ||
173 | }, | ||
174 | .probe = pcf8575_probe, | ||
175 | .remove = pcf8575_remove, | ||
176 | .id_table = pcf8575_id, | ||
177 | |||
178 | .detect = pcf8575_detect, | ||
179 | .address_data = &addr_data, | ||
180 | }; | ||
181 | |||
182 | static int __init pcf8575_init(void) | ||
183 | { | ||
184 | return i2c_add_driver(&pcf8575_driver); | ||
185 | } | ||
186 | |||
187 | static void __exit pcf8575_exit(void) | ||
188 | { | ||
189 | i2c_del_driver(&pcf8575_driver); | ||
190 | } | ||
191 | |||
192 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>, " | ||
193 | "Bart Van Assche <bart.vanassche@gmail.com>"); | ||
194 | MODULE_DESCRIPTION("pcf8575 driver"); | ||
195 | MODULE_LICENSE("GPL"); | ||
196 | |||
197 | module_init(pcf8575_init); | ||
198 | module_exit(pcf8575_exit); | ||
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c deleted file mode 100644 index 1a9cc135219f..000000000000 --- a/drivers/i2c/chips/tsl2550.c +++ /dev/null | |||
@@ -1,489 +0,0 @@ | |||
1 | /* | ||
2 | * tsl2550.c - Linux kernel modules for ambient light sensor | ||
3 | * | ||
4 | * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it> | ||
5 | * Copyright (C) 2007 Eurotech S.p.A. <info@eurotech.it> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <linux/mutex.h> | ||
27 | #include <linux/delay.h> | ||
28 | |||
29 | #define TSL2550_DRV_NAME "tsl2550" | ||
30 | #define DRIVER_VERSION "1.1.1" | ||
31 | |||
32 | /* | ||
33 | * Defines | ||
34 | */ | ||
35 | |||
36 | #define TSL2550_POWER_DOWN 0x00 | ||
37 | #define TSL2550_POWER_UP 0x03 | ||
38 | #define TSL2550_STANDARD_RANGE 0x18 | ||
39 | #define TSL2550_EXTENDED_RANGE 0x1d | ||
40 | #define TSL2550_READ_ADC0 0x43 | ||
41 | #define TSL2550_READ_ADC1 0x83 | ||
42 | |||
43 | /* | ||
44 | * Structs | ||
45 | */ | ||
46 | |||
47 | struct tsl2550_data { | ||
48 | struct i2c_client *client; | ||
49 | struct mutex update_lock; | ||
50 | |||
51 | unsigned int power_state : 1; | ||
52 | unsigned int operating_mode : 1; | ||
53 | }; | ||
54 | |||
55 | /* | ||
56 | * Global data | ||
57 | */ | ||
58 | |||
59 | static const u8 TSL2550_MODE_RANGE[2] = { | ||
60 | TSL2550_STANDARD_RANGE, TSL2550_EXTENDED_RANGE, | ||
61 | }; | ||
62 | |||
63 | /* | ||
64 | * Management functions | ||
65 | */ | ||
66 | |||
67 | static int tsl2550_set_operating_mode(struct i2c_client *client, int mode) | ||
68 | { | ||
69 | struct tsl2550_data *data = i2c_get_clientdata(client); | ||
70 | |||
71 | int ret = i2c_smbus_write_byte(client, TSL2550_MODE_RANGE[mode]); | ||
72 | |||
73 | data->operating_mode = mode; | ||
74 | |||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | static int tsl2550_set_power_state(struct i2c_client *client, int state) | ||
79 | { | ||
80 | struct tsl2550_data *data = i2c_get_clientdata(client); | ||
81 | int ret; | ||
82 | |||
83 | if (state == 0) | ||
84 | ret = i2c_smbus_write_byte(client, TSL2550_POWER_DOWN); | ||
85 | else { | ||
86 | ret = i2c_smbus_write_byte(client, TSL2550_POWER_UP); | ||
87 | |||
88 | /* On power up we should reset operating mode also... */ | ||
89 | tsl2550_set_operating_mode(client, data->operating_mode); | ||
90 | } | ||
91 | |||
92 | data->power_state = state; | ||
93 | |||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd) | ||
98 | { | ||
99 | unsigned long end; | ||
100 | int loop = 0, ret = 0; | ||
101 | |||
102 | /* | ||
103 | * Read ADC channel waiting at most 400ms (see data sheet for further | ||
104 | * info). | ||
105 | * To avoid long busy wait we spin for few milliseconds then | ||
106 | * start sleeping. | ||
107 | */ | ||
108 | end = jiffies + msecs_to_jiffies(400); | ||
109 | while (time_before(jiffies, end)) { | ||
110 | i2c_smbus_write_byte(client, cmd); | ||
111 | |||
112 | if (loop++ < 5) | ||
113 | mdelay(1); | ||
114 | else | ||
115 | msleep(1); | ||
116 | |||
117 | ret = i2c_smbus_read_byte(client); | ||
118 | if (ret < 0) | ||
119 | return ret; | ||
120 | else if (ret & 0x0080) | ||
121 | break; | ||
122 | } | ||
123 | if (!(ret & 0x80)) | ||
124 | return -EIO; | ||
125 | return ret & 0x7f; /* remove the "valid" bit */ | ||
126 | } | ||
127 | |||
128 | /* | ||
129 | * LUX calculation | ||
130 | */ | ||
131 | |||
132 | #define TSL2550_MAX_LUX 1846 | ||
133 | |||
134 | static const u8 ratio_lut[] = { | ||
135 | 100, 100, 100, 100, 100, 100, 100, 100, | ||
136 | 100, 100, 100, 100, 100, 100, 99, 99, | ||
137 | 99, 99, 99, 99, 99, 99, 99, 99, | ||
138 | 99, 99, 99, 98, 98, 98, 98, 98, | ||
139 | 98, 98, 97, 97, 97, 97, 97, 96, | ||
140 | 96, 96, 96, 95, 95, 95, 94, 94, | ||
141 | 93, 93, 93, 92, 92, 91, 91, 90, | ||
142 | 89, 89, 88, 87, 87, 86, 85, 84, | ||
143 | 83, 82, 81, 80, 79, 78, 77, 75, | ||
144 | 74, 73, 71, 69, 68, 66, 64, 62, | ||
145 | 60, 58, 56, 54, 52, 49, 47, 44, | ||
146 | 42, 41, 40, 40, 39, 39, 38, 38, | ||
147 | 37, 37, 37, 36, 36, 36, 35, 35, | ||
148 | 35, 35, 34, 34, 34, 34, 33, 33, | ||
149 | 33, 33, 32, 32, 32, 32, 32, 31, | ||
150 | 31, 31, 31, 31, 30, 30, 30, 30, | ||
151 | 30, | ||
152 | }; | ||
153 | |||
154 | static const u16 count_lut[] = { | ||
155 | 0, 1, 2, 3, 4, 5, 6, 7, | ||
156 | 8, 9, 10, 11, 12, 13, 14, 15, | ||
157 | 16, 18, 20, 22, 24, 26, 28, 30, | ||
158 | 32, 34, 36, 38, 40, 42, 44, 46, | ||
159 | 49, 53, 57, 61, 65, 69, 73, 77, | ||
160 | 81, 85, 89, 93, 97, 101, 105, 109, | ||
161 | 115, 123, 131, 139, 147, 155, 163, 171, | ||
162 | 179, 187, 195, 203, 211, 219, 227, 235, | ||
163 | 247, 263, 279, 295, 311, 327, 343, 359, | ||
164 | 375, 391, 407, 423, 439, 455, 471, 487, | ||
165 | 511, 543, 575, 607, 639, 671, 703, 735, | ||
166 | 767, 799, 831, 863, 895, 927, 959, 991, | ||
167 | 1039, 1103, 1167, 1231, 1295, 1359, 1423, 1487, | ||
168 | 1551, 1615, 1679, 1743, 1807, 1871, 1935, 1999, | ||
169 | 2095, 2223, 2351, 2479, 2607, 2735, 2863, 2991, | ||
170 | 3119, 3247, 3375, 3503, 3631, 3759, 3887, 4015, | ||
171 | }; | ||
172 | |||
173 | /* | ||
174 | * This function is described into Taos TSL2550 Designer's Notebook | ||
175 | * pages 2, 3. | ||
176 | */ | ||
177 | static int tsl2550_calculate_lux(u8 ch0, u8 ch1) | ||
178 | { | ||
179 | unsigned int lux; | ||
180 | |||
181 | /* Look up count from channel values */ | ||
182 | u16 c0 = count_lut[ch0]; | ||
183 | u16 c1 = count_lut[ch1]; | ||
184 | |||
185 | /* | ||
186 | * Calculate ratio. | ||
187 | * Note: the "128" is a scaling factor | ||
188 | */ | ||
189 | u8 r = 128; | ||
190 | |||
191 | /* Avoid division by 0 and count 1 cannot be greater than count 0 */ | ||
192 | if (c0 && (c1 <= c0)) | ||
193 | r = c1 * 128 / c0; | ||
194 | else | ||
195 | return -1; | ||
196 | |||
197 | /* Calculate LUX */ | ||
198 | lux = ((c0 - c1) * ratio_lut[r]) / 256; | ||
199 | |||
200 | /* LUX range check */ | ||
201 | return lux > TSL2550_MAX_LUX ? TSL2550_MAX_LUX : lux; | ||
202 | } | ||
203 | |||
204 | /* | ||
205 | * SysFS support | ||
206 | */ | ||
207 | |||
208 | static ssize_t tsl2550_show_power_state(struct device *dev, | ||
209 | struct device_attribute *attr, char *buf) | ||
210 | { | ||
211 | struct tsl2550_data *data = i2c_get_clientdata(to_i2c_client(dev)); | ||
212 | |||
213 | return sprintf(buf, "%u\n", data->power_state); | ||
214 | } | ||
215 | |||
216 | static ssize_t tsl2550_store_power_state(struct device *dev, | ||
217 | struct device_attribute *attr, const char *buf, size_t count) | ||
218 | { | ||
219 | struct i2c_client *client = to_i2c_client(dev); | ||
220 | struct tsl2550_data *data = i2c_get_clientdata(client); | ||
221 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
222 | int ret; | ||
223 | |||
224 | if (val < 0 || val > 1) | ||
225 | return -EINVAL; | ||
226 | |||
227 | mutex_lock(&data->update_lock); | ||
228 | ret = tsl2550_set_power_state(client, val); | ||
229 | mutex_unlock(&data->update_lock); | ||
230 | |||
231 | if (ret < 0) | ||
232 | return ret; | ||
233 | |||
234 | return count; | ||
235 | } | ||
236 | |||
237 | static DEVICE_ATTR(power_state, S_IWUSR | S_IRUGO, | ||
238 | tsl2550_show_power_state, tsl2550_store_power_state); | ||
239 | |||
240 | static ssize_t tsl2550_show_operating_mode(struct device *dev, | ||
241 | struct device_attribute *attr, char *buf) | ||
242 | { | ||
243 | struct tsl2550_data *data = i2c_get_clientdata(to_i2c_client(dev)); | ||
244 | |||
245 | return sprintf(buf, "%u\n", data->operating_mode); | ||
246 | } | ||
247 | |||
248 | static ssize_t tsl2550_store_operating_mode(struct device *dev, | ||
249 | struct device_attribute *attr, const char *buf, size_t count) | ||
250 | { | ||
251 | struct i2c_client *client = to_i2c_client(dev); | ||
252 | struct tsl2550_data *data = i2c_get_clientdata(client); | ||
253 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
254 | int ret; | ||
255 | |||
256 | if (val < 0 || val > 1) | ||
257 | return -EINVAL; | ||
258 | |||
259 | if (data->power_state == 0) | ||
260 | return -EBUSY; | ||
261 | |||
262 | mutex_lock(&data->update_lock); | ||
263 | ret = tsl2550_set_operating_mode(client, val); | ||
264 | mutex_unlock(&data->update_lock); | ||
265 | |||
266 | if (ret < 0) | ||
267 | return ret; | ||
268 | |||
269 | return count; | ||
270 | } | ||
271 | |||
272 | static DEVICE_ATTR(operating_mode, S_IWUSR | S_IRUGO, | ||
273 | tsl2550_show_operating_mode, tsl2550_store_operating_mode); | ||
274 | |||
275 | static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf) | ||
276 | { | ||
277 | u8 ch0, ch1; | ||
278 | int ret; | ||
279 | |||
280 | ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC0); | ||
281 | if (ret < 0) | ||
282 | return ret; | ||
283 | ch0 = ret; | ||
284 | |||
285 | mdelay(1); | ||
286 | |||
287 | ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1); | ||
288 | if (ret < 0) | ||
289 | return ret; | ||
290 | ch1 = ret; | ||
291 | |||
292 | /* Do the job */ | ||
293 | ret = tsl2550_calculate_lux(ch0, ch1); | ||
294 | if (ret < 0) | ||
295 | return ret; | ||
296 | |||
297 | return sprintf(buf, "%d\n", ret); | ||
298 | } | ||
299 | |||
300 | static ssize_t tsl2550_show_lux1_input(struct device *dev, | ||
301 | struct device_attribute *attr, char *buf) | ||
302 | { | ||
303 | struct i2c_client *client = to_i2c_client(dev); | ||
304 | struct tsl2550_data *data = i2c_get_clientdata(client); | ||
305 | int ret; | ||
306 | |||
307 | /* No LUX data if not operational */ | ||
308 | if (!data->power_state) | ||
309 | return -EBUSY; | ||
310 | |||
311 | mutex_lock(&data->update_lock); | ||
312 | ret = __tsl2550_show_lux(client, buf); | ||
313 | mutex_unlock(&data->update_lock); | ||
314 | |||
315 | return ret; | ||
316 | } | ||
317 | |||
318 | static DEVICE_ATTR(lux1_input, S_IRUGO, | ||
319 | tsl2550_show_lux1_input, NULL); | ||
320 | |||
321 | static struct attribute *tsl2550_attributes[] = { | ||
322 | &dev_attr_power_state.attr, | ||
323 | &dev_attr_operating_mode.attr, | ||
324 | &dev_attr_lux1_input.attr, | ||
325 | NULL | ||
326 | }; | ||
327 | |||
328 | static const struct attribute_group tsl2550_attr_group = { | ||
329 | .attrs = tsl2550_attributes, | ||
330 | }; | ||
331 | |||
332 | /* | ||
333 | * Initialization function | ||
334 | */ | ||
335 | |||
336 | static int tsl2550_init_client(struct i2c_client *client) | ||
337 | { | ||
338 | struct tsl2550_data *data = i2c_get_clientdata(client); | ||
339 | int err; | ||
340 | |||
341 | /* | ||
342 | * Probe the chip. To do so we try to power up the device and then to | ||
343 | * read back the 0x03 code | ||
344 | */ | ||
345 | err = i2c_smbus_write_byte(client, TSL2550_POWER_UP); | ||
346 | if (err < 0) | ||
347 | return err; | ||
348 | mdelay(1); | ||
349 | if (i2c_smbus_read_byte(client) != TSL2550_POWER_UP) | ||
350 | return -ENODEV; | ||
351 | data->power_state = 1; | ||
352 | |||
353 | /* Set the default operating mode */ | ||
354 | err = i2c_smbus_write_byte(client, | ||
355 | TSL2550_MODE_RANGE[data->operating_mode]); | ||
356 | if (err < 0) | ||
357 | return err; | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | /* | ||
363 | * I2C init/probing/exit functions | ||
364 | */ | ||
365 | |||
366 | static struct i2c_driver tsl2550_driver; | ||
367 | static int __devinit tsl2550_probe(struct i2c_client *client, | ||
368 | const struct i2c_device_id *id) | ||
369 | { | ||
370 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | ||
371 | struct tsl2550_data *data; | ||
372 | int *opmode, err = 0; | ||
373 | |||
374 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) { | ||
375 | err = -EIO; | ||
376 | goto exit; | ||
377 | } | ||
378 | |||
379 | data = kzalloc(sizeof(struct tsl2550_data), GFP_KERNEL); | ||
380 | if (!data) { | ||
381 | err = -ENOMEM; | ||
382 | goto exit; | ||
383 | } | ||
384 | data->client = client; | ||
385 | i2c_set_clientdata(client, data); | ||
386 | |||
387 | /* Check platform data */ | ||
388 | opmode = client->dev.platform_data; | ||
389 | if (opmode) { | ||
390 | if (*opmode < 0 || *opmode > 1) { | ||
391 | dev_err(&client->dev, "invalid operating_mode (%d)\n", | ||
392 | *opmode); | ||
393 | err = -EINVAL; | ||
394 | goto exit_kfree; | ||
395 | } | ||
396 | data->operating_mode = *opmode; | ||
397 | } else | ||
398 | data->operating_mode = 0; /* default mode is standard */ | ||
399 | dev_info(&client->dev, "%s operating mode\n", | ||
400 | data->operating_mode ? "extended" : "standard"); | ||
401 | |||
402 | mutex_init(&data->update_lock); | ||
403 | |||
404 | /* Initialize the TSL2550 chip */ | ||
405 | err = tsl2550_init_client(client); | ||
406 | if (err) | ||
407 | goto exit_kfree; | ||
408 | |||
409 | /* Register sysfs hooks */ | ||
410 | err = sysfs_create_group(&client->dev.kobj, &tsl2550_attr_group); | ||
411 | if (err) | ||
412 | goto exit_kfree; | ||
413 | |||
414 | dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION); | ||
415 | |||
416 | return 0; | ||
417 | |||
418 | exit_kfree: | ||
419 | kfree(data); | ||
420 | exit: | ||
421 | return err; | ||
422 | } | ||
423 | |||
424 | static int __devexit tsl2550_remove(struct i2c_client *client) | ||
425 | { | ||
426 | sysfs_remove_group(&client->dev.kobj, &tsl2550_attr_group); | ||
427 | |||
428 | /* Power down the device */ | ||
429 | tsl2550_set_power_state(client, 0); | ||
430 | |||
431 | kfree(i2c_get_clientdata(client)); | ||
432 | |||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | #ifdef CONFIG_PM | ||
437 | |||
438 | static int tsl2550_suspend(struct i2c_client *client, pm_message_t mesg) | ||
439 | { | ||
440 | return tsl2550_set_power_state(client, 0); | ||
441 | } | ||
442 | |||
443 | static int tsl2550_resume(struct i2c_client *client) | ||
444 | { | ||
445 | return tsl2550_set_power_state(client, 1); | ||
446 | } | ||
447 | |||
448 | #else | ||
449 | |||
450 | #define tsl2550_suspend NULL | ||
451 | #define tsl2550_resume NULL | ||
452 | |||
453 | #endif /* CONFIG_PM */ | ||
454 | |||
455 | static const struct i2c_device_id tsl2550_id[] = { | ||
456 | { "tsl2550", 0 }, | ||
457 | { } | ||
458 | }; | ||
459 | MODULE_DEVICE_TABLE(i2c, tsl2550_id); | ||
460 | |||
461 | static struct i2c_driver tsl2550_driver = { | ||
462 | .driver = { | ||
463 | .name = TSL2550_DRV_NAME, | ||
464 | .owner = THIS_MODULE, | ||
465 | }, | ||
466 | .suspend = tsl2550_suspend, | ||
467 | .resume = tsl2550_resume, | ||
468 | .probe = tsl2550_probe, | ||
469 | .remove = __devexit_p(tsl2550_remove), | ||
470 | .id_table = tsl2550_id, | ||
471 | }; | ||
472 | |||
473 | static int __init tsl2550_init(void) | ||
474 | { | ||
475 | return i2c_add_driver(&tsl2550_driver); | ||
476 | } | ||
477 | |||
478 | static void __exit tsl2550_exit(void) | ||
479 | { | ||
480 | i2c_del_driver(&tsl2550_driver); | ||
481 | } | ||
482 | |||
483 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
484 | MODULE_DESCRIPTION("TSL2550 ambient light sensor driver"); | ||
485 | MODULE_LICENSE("GPL"); | ||
486 | MODULE_VERSION(DRIVER_VERSION); | ||
487 | |||
488 | module_init(tsl2550_init); | ||
489 | module_exit(tsl2550_exit); | ||
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c index a26a34a06641..7e6a63b57165 100644 --- a/drivers/i2c/i2c-boardinfo.c +++ b/drivers/i2c/i2c-boardinfo.c | |||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
21 | #include <linux/slab.h> | ||
21 | #include <linux/rwsem.h> | 22 | #include <linux/rwsem.h> |
22 | 23 | ||
23 | #include "i2c-core.h" | 24 | #include "i2c-core.h" |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 0e45c296d3d2..c7db6980e3a3 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -20,7 +20,9 @@ | |||
20 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. | 20 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. |
21 | All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> | 21 | All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> |
22 | SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and | 22 | SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and |
23 | Jean Delvare <khali@linux-fr.org> */ | 23 | Jean Delvare <khali@linux-fr.org> |
24 | Mux support by Rodolfo Giometti <giometti@enneenne.com> and | ||
25 | Michael Lawnick <michael.lawnick.ext@nsn.com> */ | ||
24 | 26 | ||
25 | #include <linux/module.h> | 27 | #include <linux/module.h> |
26 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
@@ -30,23 +32,24 @@ | |||
30 | #include <linux/init.h> | 32 | #include <linux/init.h> |
31 | #include <linux/idr.h> | 33 | #include <linux/idr.h> |
32 | #include <linux/mutex.h> | 34 | #include <linux/mutex.h> |
35 | #include <linux/of_device.h> | ||
33 | #include <linux/completion.h> | 36 | #include <linux/completion.h> |
34 | #include <linux/hardirq.h> | 37 | #include <linux/hardirq.h> |
35 | #include <linux/irqflags.h> | 38 | #include <linux/irqflags.h> |
36 | #include <linux/rwsem.h> | 39 | #include <linux/rwsem.h> |
40 | #include <linux/pm_runtime.h> | ||
37 | #include <asm/uaccess.h> | 41 | #include <asm/uaccess.h> |
38 | 42 | ||
39 | #include "i2c-core.h" | 43 | #include "i2c-core.h" |
40 | 44 | ||
41 | 45 | ||
42 | /* core_lock protects i2c_adapter_idr, userspace_devices, and guarantees | 46 | /* core_lock protects i2c_adapter_idr, and guarantees |
43 | that device detection, deletion of detected devices, and attach_adapter | 47 | that device detection, deletion of detected devices, and attach_adapter |
44 | and detach_adapter calls are serialized */ | 48 | and detach_adapter calls are serialized */ |
45 | static DEFINE_MUTEX(core_lock); | 49 | static DEFINE_MUTEX(core_lock); |
46 | static DEFINE_IDR(i2c_adapter_idr); | 50 | static DEFINE_IDR(i2c_adapter_idr); |
47 | static LIST_HEAD(userspace_devices); | ||
48 | 51 | ||
49 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr); | 52 | static struct device_type i2c_client_type; |
50 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); | 53 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); |
51 | 54 | ||
52 | /* ------------------------------------------------------------------------- */ | 55 | /* ------------------------------------------------------------------------- */ |
@@ -64,9 +67,17 @@ static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, | |||
64 | 67 | ||
65 | static int i2c_device_match(struct device *dev, struct device_driver *drv) | 68 | static int i2c_device_match(struct device *dev, struct device_driver *drv) |
66 | { | 69 | { |
67 | struct i2c_client *client = to_i2c_client(dev); | 70 | struct i2c_client *client = i2c_verify_client(dev); |
68 | struct i2c_driver *driver = to_i2c_driver(drv); | 71 | struct i2c_driver *driver; |
72 | |||
73 | if (!client) | ||
74 | return 0; | ||
75 | |||
76 | /* Attempt an OF style match */ | ||
77 | if (of_driver_match_device(dev, drv)) | ||
78 | return 1; | ||
69 | 79 | ||
80 | driver = to_i2c_driver(drv); | ||
70 | /* match on an id table if there is one */ | 81 | /* match on an id table if there is one */ |
71 | if (driver->id_table) | 82 | if (driver->id_table) |
72 | return i2c_match_id(driver->id_table, client) != NULL; | 83 | return i2c_match_id(driver->id_table, client) != NULL; |
@@ -94,10 +105,14 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
94 | 105 | ||
95 | static int i2c_device_probe(struct device *dev) | 106 | static int i2c_device_probe(struct device *dev) |
96 | { | 107 | { |
97 | struct i2c_client *client = to_i2c_client(dev); | 108 | struct i2c_client *client = i2c_verify_client(dev); |
98 | struct i2c_driver *driver = to_i2c_driver(dev->driver); | 109 | struct i2c_driver *driver; |
99 | int status; | 110 | int status; |
100 | 111 | ||
112 | if (!client) | ||
113 | return 0; | ||
114 | |||
115 | driver = to_i2c_driver(dev->driver); | ||
101 | if (!driver->probe || !driver->id_table) | 116 | if (!driver->probe || !driver->id_table) |
102 | return -ENODEV; | 117 | return -ENODEV; |
103 | client->driver = driver; | 118 | client->driver = driver; |
@@ -107,18 +122,20 @@ static int i2c_device_probe(struct device *dev) | |||
107 | dev_dbg(dev, "probe\n"); | 122 | dev_dbg(dev, "probe\n"); |
108 | 123 | ||
109 | status = driver->probe(client, i2c_match_id(driver->id_table, client)); | 124 | status = driver->probe(client, i2c_match_id(driver->id_table, client)); |
110 | if (status) | 125 | if (status) { |
111 | client->driver = NULL; | 126 | client->driver = NULL; |
127 | i2c_set_clientdata(client, NULL); | ||
128 | } | ||
112 | return status; | 129 | return status; |
113 | } | 130 | } |
114 | 131 | ||
115 | static int i2c_device_remove(struct device *dev) | 132 | static int i2c_device_remove(struct device *dev) |
116 | { | 133 | { |
117 | struct i2c_client *client = to_i2c_client(dev); | 134 | struct i2c_client *client = i2c_verify_client(dev); |
118 | struct i2c_driver *driver; | 135 | struct i2c_driver *driver; |
119 | int status; | 136 | int status; |
120 | 137 | ||
121 | if (!dev->driver) | 138 | if (!client || !dev->driver) |
122 | return 0; | 139 | return 0; |
123 | 140 | ||
124 | driver = to_i2c_driver(dev->driver); | 141 | driver = to_i2c_driver(dev->driver); |
@@ -129,56 +146,158 @@ static int i2c_device_remove(struct device *dev) | |||
129 | dev->driver = NULL; | 146 | dev->driver = NULL; |
130 | status = 0; | 147 | status = 0; |
131 | } | 148 | } |
132 | if (status == 0) | 149 | if (status == 0) { |
133 | client->driver = NULL; | 150 | client->driver = NULL; |
151 | i2c_set_clientdata(client, NULL); | ||
152 | } | ||
134 | return status; | 153 | return status; |
135 | } | 154 | } |
136 | 155 | ||
137 | static void i2c_device_shutdown(struct device *dev) | 156 | static void i2c_device_shutdown(struct device *dev) |
138 | { | 157 | { |
158 | struct i2c_client *client = i2c_verify_client(dev); | ||
139 | struct i2c_driver *driver; | 159 | struct i2c_driver *driver; |
140 | 160 | ||
141 | if (!dev->driver) | 161 | if (!client || !dev->driver) |
142 | return; | 162 | return; |
143 | driver = to_i2c_driver(dev->driver); | 163 | driver = to_i2c_driver(dev->driver); |
144 | if (driver->shutdown) | 164 | if (driver->shutdown) |
145 | driver->shutdown(to_i2c_client(dev)); | 165 | driver->shutdown(client); |
146 | } | 166 | } |
147 | 167 | ||
148 | static int i2c_device_suspend(struct device *dev, pm_message_t mesg) | 168 | #ifdef CONFIG_PM_SLEEP |
169 | static int i2c_legacy_suspend(struct device *dev, pm_message_t mesg) | ||
149 | { | 170 | { |
171 | struct i2c_client *client = i2c_verify_client(dev); | ||
150 | struct i2c_driver *driver; | 172 | struct i2c_driver *driver; |
151 | 173 | ||
152 | if (!dev->driver) | 174 | if (!client || !dev->driver) |
153 | return 0; | 175 | return 0; |
154 | driver = to_i2c_driver(dev->driver); | 176 | driver = to_i2c_driver(dev->driver); |
155 | if (!driver->suspend) | 177 | if (!driver->suspend) |
156 | return 0; | 178 | return 0; |
157 | return driver->suspend(to_i2c_client(dev), mesg); | 179 | return driver->suspend(client, mesg); |
158 | } | 180 | } |
159 | 181 | ||
160 | static int i2c_device_resume(struct device *dev) | 182 | static int i2c_legacy_resume(struct device *dev) |
161 | { | 183 | { |
184 | struct i2c_client *client = i2c_verify_client(dev); | ||
162 | struct i2c_driver *driver; | 185 | struct i2c_driver *driver; |
163 | 186 | ||
164 | if (!dev->driver) | 187 | if (!client || !dev->driver) |
165 | return 0; | 188 | return 0; |
166 | driver = to_i2c_driver(dev->driver); | 189 | driver = to_i2c_driver(dev->driver); |
167 | if (!driver->resume) | 190 | if (!driver->resume) |
168 | return 0; | 191 | return 0; |
169 | return driver->resume(to_i2c_client(dev)); | 192 | return driver->resume(client); |
193 | } | ||
194 | |||
195 | static int i2c_device_pm_suspend(struct device *dev) | ||
196 | { | ||
197 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
198 | |||
199 | if (pm) { | ||
200 | if (pm_runtime_suspended(dev)) | ||
201 | return 0; | ||
202 | else | ||
203 | return pm->suspend ? pm->suspend(dev) : 0; | ||
204 | } | ||
205 | |||
206 | return i2c_legacy_suspend(dev, PMSG_SUSPEND); | ||
207 | } | ||
208 | |||
209 | static int i2c_device_pm_resume(struct device *dev) | ||
210 | { | ||
211 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
212 | int ret; | ||
213 | |||
214 | if (pm) | ||
215 | ret = pm->resume ? pm->resume(dev) : 0; | ||
216 | else | ||
217 | ret = i2c_legacy_resume(dev); | ||
218 | |||
219 | return ret; | ||
170 | } | 220 | } |
171 | 221 | ||
222 | static int i2c_device_pm_freeze(struct device *dev) | ||
223 | { | ||
224 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
225 | |||
226 | if (pm) { | ||
227 | if (pm_runtime_suspended(dev)) | ||
228 | return 0; | ||
229 | else | ||
230 | return pm->freeze ? pm->freeze(dev) : 0; | ||
231 | } | ||
232 | |||
233 | return i2c_legacy_suspend(dev, PMSG_FREEZE); | ||
234 | } | ||
235 | |||
236 | static int i2c_device_pm_thaw(struct device *dev) | ||
237 | { | ||
238 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
239 | |||
240 | if (pm) { | ||
241 | if (pm_runtime_suspended(dev)) | ||
242 | return 0; | ||
243 | else | ||
244 | return pm->thaw ? pm->thaw(dev) : 0; | ||
245 | } | ||
246 | |||
247 | return i2c_legacy_resume(dev); | ||
248 | } | ||
249 | |||
250 | static int i2c_device_pm_poweroff(struct device *dev) | ||
251 | { | ||
252 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
253 | |||
254 | if (pm) { | ||
255 | if (pm_runtime_suspended(dev)) | ||
256 | return 0; | ||
257 | else | ||
258 | return pm->poweroff ? pm->poweroff(dev) : 0; | ||
259 | } | ||
260 | |||
261 | return i2c_legacy_suspend(dev, PMSG_HIBERNATE); | ||
262 | } | ||
263 | |||
264 | static int i2c_device_pm_restore(struct device *dev) | ||
265 | { | ||
266 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; | ||
267 | int ret; | ||
268 | |||
269 | if (pm) | ||
270 | ret = pm->restore ? pm->restore(dev) : 0; | ||
271 | else | ||
272 | ret = i2c_legacy_resume(dev); | ||
273 | |||
274 | if (!ret) { | ||
275 | pm_runtime_disable(dev); | ||
276 | pm_runtime_set_active(dev); | ||
277 | pm_runtime_enable(dev); | ||
278 | } | ||
279 | |||
280 | return ret; | ||
281 | } | ||
282 | #else /* !CONFIG_PM_SLEEP */ | ||
283 | #define i2c_device_pm_suspend NULL | ||
284 | #define i2c_device_pm_resume NULL | ||
285 | #define i2c_device_pm_freeze NULL | ||
286 | #define i2c_device_pm_thaw NULL | ||
287 | #define i2c_device_pm_poweroff NULL | ||
288 | #define i2c_device_pm_restore NULL | ||
289 | #endif /* !CONFIG_PM_SLEEP */ | ||
290 | |||
172 | static void i2c_client_dev_release(struct device *dev) | 291 | static void i2c_client_dev_release(struct device *dev) |
173 | { | 292 | { |
174 | kfree(to_i2c_client(dev)); | 293 | kfree(to_i2c_client(dev)); |
175 | } | 294 | } |
176 | 295 | ||
177 | static ssize_t | 296 | static ssize_t |
178 | show_client_name(struct device *dev, struct device_attribute *attr, char *buf) | 297 | show_name(struct device *dev, struct device_attribute *attr, char *buf) |
179 | { | 298 | { |
180 | struct i2c_client *client = to_i2c_client(dev); | 299 | return sprintf(buf, "%s\n", dev->type == &i2c_client_type ? |
181 | return sprintf(buf, "%s\n", client->name); | 300 | to_i2c_client(dev)->name : to_i2c_adapter(dev)->name); |
182 | } | 301 | } |
183 | 302 | ||
184 | static ssize_t | 303 | static ssize_t |
@@ -188,26 +307,55 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf) | |||
188 | return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); | 307 | return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); |
189 | } | 308 | } |
190 | 309 | ||
191 | static struct device_attribute i2c_dev_attrs[] = { | 310 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
192 | __ATTR(name, S_IRUGO, show_client_name, NULL), | 311 | static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); |
312 | |||
313 | static struct attribute *i2c_dev_attrs[] = { | ||
314 | &dev_attr_name.attr, | ||
193 | /* modalias helps coldplug: modprobe $(cat .../modalias) */ | 315 | /* modalias helps coldplug: modprobe $(cat .../modalias) */ |
194 | __ATTR(modalias, S_IRUGO, show_modalias, NULL), | 316 | &dev_attr_modalias.attr, |
195 | { }, | 317 | NULL |
318 | }; | ||
319 | |||
320 | static struct attribute_group i2c_dev_attr_group = { | ||
321 | .attrs = i2c_dev_attrs, | ||
322 | }; | ||
323 | |||
324 | static const struct attribute_group *i2c_dev_attr_groups[] = { | ||
325 | &i2c_dev_attr_group, | ||
326 | NULL | ||
327 | }; | ||
328 | |||
329 | static const struct dev_pm_ops i2c_device_pm_ops = { | ||
330 | .suspend = i2c_device_pm_suspend, | ||
331 | .resume = i2c_device_pm_resume, | ||
332 | .freeze = i2c_device_pm_freeze, | ||
333 | .thaw = i2c_device_pm_thaw, | ||
334 | .poweroff = i2c_device_pm_poweroff, | ||
335 | .restore = i2c_device_pm_restore, | ||
336 | SET_RUNTIME_PM_OPS( | ||
337 | pm_generic_runtime_suspend, | ||
338 | pm_generic_runtime_resume, | ||
339 | pm_generic_runtime_idle | ||
340 | ) | ||
196 | }; | 341 | }; |
197 | 342 | ||
198 | struct bus_type i2c_bus_type = { | 343 | struct bus_type i2c_bus_type = { |
199 | .name = "i2c", | 344 | .name = "i2c", |
200 | .dev_attrs = i2c_dev_attrs, | ||
201 | .match = i2c_device_match, | 345 | .match = i2c_device_match, |
202 | .uevent = i2c_device_uevent, | ||
203 | .probe = i2c_device_probe, | 346 | .probe = i2c_device_probe, |
204 | .remove = i2c_device_remove, | 347 | .remove = i2c_device_remove, |
205 | .shutdown = i2c_device_shutdown, | 348 | .shutdown = i2c_device_shutdown, |
206 | .suspend = i2c_device_suspend, | 349 | .pm = &i2c_device_pm_ops, |
207 | .resume = i2c_device_resume, | ||
208 | }; | 350 | }; |
209 | EXPORT_SYMBOL_GPL(i2c_bus_type); | 351 | EXPORT_SYMBOL_GPL(i2c_bus_type); |
210 | 352 | ||
353 | static struct device_type i2c_client_type = { | ||
354 | .groups = i2c_dev_attr_groups, | ||
355 | .uevent = i2c_device_uevent, | ||
356 | .release = i2c_client_dev_release, | ||
357 | }; | ||
358 | |||
211 | 359 | ||
212 | /** | 360 | /** |
213 | * i2c_verify_client - return parameter as i2c_client, or NULL | 361 | * i2c_verify_client - return parameter as i2c_client, or NULL |
@@ -220,13 +368,148 @@ EXPORT_SYMBOL_GPL(i2c_bus_type); | |||
220 | */ | 368 | */ |
221 | struct i2c_client *i2c_verify_client(struct device *dev) | 369 | struct i2c_client *i2c_verify_client(struct device *dev) |
222 | { | 370 | { |
223 | return (dev->bus == &i2c_bus_type) | 371 | return (dev->type == &i2c_client_type) |
224 | ? to_i2c_client(dev) | 372 | ? to_i2c_client(dev) |
225 | : NULL; | 373 | : NULL; |
226 | } | 374 | } |
227 | EXPORT_SYMBOL(i2c_verify_client); | 375 | EXPORT_SYMBOL(i2c_verify_client); |
228 | 376 | ||
229 | 377 | ||
378 | /* This is a permissive address validity check, I2C address map constraints | ||
379 | * are purposedly not enforced, except for the general call address. */ | ||
380 | static int i2c_check_client_addr_validity(const struct i2c_client *client) | ||
381 | { | ||
382 | if (client->flags & I2C_CLIENT_TEN) { | ||
383 | /* 10-bit address, all values are valid */ | ||
384 | if (client->addr > 0x3ff) | ||
385 | return -EINVAL; | ||
386 | } else { | ||
387 | /* 7-bit address, reject the general call address */ | ||
388 | if (client->addr == 0x00 || client->addr > 0x7f) | ||
389 | return -EINVAL; | ||
390 | } | ||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | /* And this is a strict address validity check, used when probing. If a | ||
395 | * device uses a reserved address, then it shouldn't be probed. 7-bit | ||
396 | * addressing is assumed, 10-bit address devices are rare and should be | ||
397 | * explicitly enumerated. */ | ||
398 | static int i2c_check_addr_validity(unsigned short addr) | ||
399 | { | ||
400 | /* | ||
401 | * Reserved addresses per I2C specification: | ||
402 | * 0x00 General call address / START byte | ||
403 | * 0x01 CBUS address | ||
404 | * 0x02 Reserved for different bus format | ||
405 | * 0x03 Reserved for future purposes | ||
406 | * 0x04-0x07 Hs-mode master code | ||
407 | * 0x78-0x7b 10-bit slave addressing | ||
408 | * 0x7c-0x7f Reserved for future purposes | ||
409 | */ | ||
410 | if (addr < 0x08 || addr > 0x77) | ||
411 | return -EINVAL; | ||
412 | return 0; | ||
413 | } | ||
414 | |||
415 | static int __i2c_check_addr_busy(struct device *dev, void *addrp) | ||
416 | { | ||
417 | struct i2c_client *client = i2c_verify_client(dev); | ||
418 | int addr = *(int *)addrp; | ||
419 | |||
420 | if (client && client->addr == addr) | ||
421 | return -EBUSY; | ||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | /* walk up mux tree */ | ||
426 | static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) | ||
427 | { | ||
428 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
429 | int result; | ||
430 | |||
431 | result = device_for_each_child(&adapter->dev, &addr, | ||
432 | __i2c_check_addr_busy); | ||
433 | |||
434 | if (!result && parent) | ||
435 | result = i2c_check_mux_parents(parent, addr); | ||
436 | |||
437 | return result; | ||
438 | } | ||
439 | |||
440 | /* recurse down mux tree */ | ||
441 | static int i2c_check_mux_children(struct device *dev, void *addrp) | ||
442 | { | ||
443 | int result; | ||
444 | |||
445 | if (dev->type == &i2c_adapter_type) | ||
446 | result = device_for_each_child(dev, addrp, | ||
447 | i2c_check_mux_children); | ||
448 | else | ||
449 | result = __i2c_check_addr_busy(dev, addrp); | ||
450 | |||
451 | return result; | ||
452 | } | ||
453 | |||
454 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) | ||
455 | { | ||
456 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
457 | int result = 0; | ||
458 | |||
459 | if (parent) | ||
460 | result = i2c_check_mux_parents(parent, addr); | ||
461 | |||
462 | if (!result) | ||
463 | result = device_for_each_child(&adapter->dev, &addr, | ||
464 | i2c_check_mux_children); | ||
465 | |||
466 | return result; | ||
467 | } | ||
468 | |||
469 | /** | ||
470 | * i2c_lock_adapter - Get exclusive access to an I2C bus segment | ||
471 | * @adapter: Target I2C bus segment | ||
472 | */ | ||
473 | void i2c_lock_adapter(struct i2c_adapter *adapter) | ||
474 | { | ||
475 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
476 | |||
477 | if (parent) | ||
478 | i2c_lock_adapter(parent); | ||
479 | else | ||
480 | rt_mutex_lock(&adapter->bus_lock); | ||
481 | } | ||
482 | EXPORT_SYMBOL_GPL(i2c_lock_adapter); | ||
483 | |||
484 | /** | ||
485 | * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment | ||
486 | * @adapter: Target I2C bus segment | ||
487 | */ | ||
488 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) | ||
489 | { | ||
490 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
491 | |||
492 | if (parent) | ||
493 | return i2c_trylock_adapter(parent); | ||
494 | else | ||
495 | return rt_mutex_trylock(&adapter->bus_lock); | ||
496 | } | ||
497 | |||
498 | /** | ||
499 | * i2c_unlock_adapter - Release exclusive access to an I2C bus segment | ||
500 | * @adapter: Target I2C bus segment | ||
501 | */ | ||
502 | void i2c_unlock_adapter(struct i2c_adapter *adapter) | ||
503 | { | ||
504 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
505 | |||
506 | if (parent) | ||
507 | i2c_unlock_adapter(parent); | ||
508 | else | ||
509 | rt_mutex_unlock(&adapter->bus_lock); | ||
510 | } | ||
511 | EXPORT_SYMBOL_GPL(i2c_unlock_adapter); | ||
512 | |||
230 | /** | 513 | /** |
231 | * i2c_new_device - instantiate an i2c device | 514 | * i2c_new_device - instantiate an i2c device |
232 | * @adap: the adapter managing the device | 515 | * @adap: the adapter managing the device |
@@ -266,14 +549,25 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | |||
266 | 549 | ||
267 | strlcpy(client->name, info->type, sizeof(client->name)); | 550 | strlcpy(client->name, info->type, sizeof(client->name)); |
268 | 551 | ||
552 | /* Check for address validity */ | ||
553 | status = i2c_check_client_addr_validity(client); | ||
554 | if (status) { | ||
555 | dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n", | ||
556 | client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr); | ||
557 | goto out_err_silent; | ||
558 | } | ||
559 | |||
269 | /* Check for address business */ | 560 | /* Check for address business */ |
270 | status = i2c_check_addr(adap, client->addr); | 561 | status = i2c_check_addr_busy(adap, client->addr); |
271 | if (status) | 562 | if (status) |
272 | goto out_err; | 563 | goto out_err; |
273 | 564 | ||
274 | client->dev.parent = &client->adapter->dev; | 565 | client->dev.parent = &client->adapter->dev; |
275 | client->dev.bus = &i2c_bus_type; | 566 | client->dev.bus = &i2c_bus_type; |
276 | client->dev.release = i2c_client_dev_release; | 567 | client->dev.type = &i2c_client_type; |
568 | #ifdef CONFIG_OF | ||
569 | client->dev.of_node = info->of_node; | ||
570 | #endif | ||
277 | 571 | ||
278 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), | 572 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), |
279 | client->addr); | 573 | client->addr); |
@@ -289,6 +583,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | |||
289 | out_err: | 583 | out_err: |
290 | dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x " | 584 | dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x " |
291 | "(%d)\n", client->name, client->addr, status); | 585 | "(%d)\n", client->name, client->addr, status); |
586 | out_err_silent: | ||
292 | kfree(client); | 587 | kfree(client); |
293 | return NULL; | 588 | return NULL; |
294 | } | 589 | } |
@@ -368,13 +663,6 @@ static void i2c_adapter_dev_release(struct device *dev) | |||
368 | complete(&adap->dev_released); | 663 | complete(&adap->dev_released); |
369 | } | 664 | } |
370 | 665 | ||
371 | static ssize_t | ||
372 | show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
373 | { | ||
374 | struct i2c_adapter *adap = to_i2c_adapter(dev); | ||
375 | return sprintf(buf, "%s\n", adap->name); | ||
376 | } | ||
377 | |||
378 | /* | 666 | /* |
379 | * Let users instantiate I2C devices through sysfs. This can be used when | 667 | * Let users instantiate I2C devices through sysfs. This can be used when |
380 | * platform initialization code doesn't contain the proper data for | 668 | * platform initialization code doesn't contain the proper data for |
@@ -395,8 +683,6 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | |||
395 | char *blank, end; | 683 | char *blank, end; |
396 | int res; | 684 | int res; |
397 | 685 | ||
398 | dev_warn(dev, "The new_device interface is still experimental " | ||
399 | "and may change in a near future\n"); | ||
400 | memset(&info, 0, sizeof(struct i2c_board_info)); | 686 | memset(&info, 0, sizeof(struct i2c_board_info)); |
401 | 687 | ||
402 | blank = strchr(buf, ' '); | 688 | blank = strchr(buf, ' '); |
@@ -421,20 +707,14 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | |||
421 | return -EINVAL; | 707 | return -EINVAL; |
422 | } | 708 | } |
423 | 709 | ||
424 | if (info.addr < 0x03 || info.addr > 0x77) { | ||
425 | dev_err(dev, "%s: Invalid I2C address 0x%hx\n", "new_device", | ||
426 | info.addr); | ||
427 | return -EINVAL; | ||
428 | } | ||
429 | |||
430 | client = i2c_new_device(adap, &info); | 710 | client = i2c_new_device(adap, &info); |
431 | if (!client) | 711 | if (!client) |
432 | return -EEXIST; | 712 | return -EINVAL; |
433 | 713 | ||
434 | /* Keep track of the added device */ | 714 | /* Keep track of the added device */ |
435 | mutex_lock(&core_lock); | 715 | mutex_lock(&adap->userspace_clients_lock); |
436 | list_add_tail(&client->detected, &userspace_devices); | 716 | list_add_tail(&client->detected, &adap->userspace_clients); |
437 | mutex_unlock(&core_lock); | 717 | mutex_unlock(&adap->userspace_clients_lock); |
438 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", | 718 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", |
439 | info.type, info.addr); | 719 | info.type, info.addr); |
440 | 720 | ||
@@ -473,9 +753,10 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
473 | 753 | ||
474 | /* Make sure the device was added through sysfs */ | 754 | /* Make sure the device was added through sysfs */ |
475 | res = -ENOENT; | 755 | res = -ENOENT; |
476 | mutex_lock(&core_lock); | 756 | mutex_lock(&adap->userspace_clients_lock); |
477 | list_for_each_entry_safe(client, next, &userspace_devices, detected) { | 757 | list_for_each_entry_safe(client, next, &adap->userspace_clients, |
478 | if (client->addr == addr && client->adapter == adap) { | 758 | detected) { |
759 | if (client->addr == addr) { | ||
479 | dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", | 760 | dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", |
480 | "delete_device", client->name, client->addr); | 761 | "delete_device", client->name, client->addr); |
481 | 762 | ||
@@ -485,7 +766,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
485 | break; | 766 | break; |
486 | } | 767 | } |
487 | } | 768 | } |
488 | mutex_unlock(&core_lock); | 769 | mutex_unlock(&adap->userspace_clients_lock); |
489 | 770 | ||
490 | if (res < 0) | 771 | if (res < 0) |
491 | dev_err(dev, "%s: Can't find device in list\n", | 772 | dev_err(dev, "%s: Can't find device in list\n", |
@@ -493,19 +774,35 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
493 | return res; | 774 | return res; |
494 | } | 775 | } |
495 | 776 | ||
496 | static struct device_attribute i2c_adapter_attrs[] = { | 777 | static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device); |
497 | __ATTR(name, S_IRUGO, show_adapter_name, NULL), | 778 | static DEVICE_ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device); |
498 | __ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device), | 779 | |
499 | __ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device), | 780 | static struct attribute *i2c_adapter_attrs[] = { |
500 | { }, | 781 | &dev_attr_name.attr, |
782 | &dev_attr_new_device.attr, | ||
783 | &dev_attr_delete_device.attr, | ||
784 | NULL | ||
501 | }; | 785 | }; |
502 | 786 | ||
503 | static struct class i2c_adapter_class = { | 787 | static struct attribute_group i2c_adapter_attr_group = { |
504 | .owner = THIS_MODULE, | 788 | .attrs = i2c_adapter_attrs, |
505 | .name = "i2c-adapter", | ||
506 | .dev_attrs = i2c_adapter_attrs, | ||
507 | }; | 789 | }; |
508 | 790 | ||
791 | static const struct attribute_group *i2c_adapter_attr_groups[] = { | ||
792 | &i2c_adapter_attr_group, | ||
793 | NULL | ||
794 | }; | ||
795 | |||
796 | struct device_type i2c_adapter_type = { | ||
797 | .groups = i2c_adapter_attr_groups, | ||
798 | .release = i2c_adapter_dev_release, | ||
799 | }; | ||
800 | EXPORT_SYMBOL_GPL(i2c_adapter_type); | ||
801 | |||
802 | #ifdef CONFIG_I2C_COMPAT | ||
803 | static struct class_compat *i2c_adapter_compat_class; | ||
804 | #endif | ||
805 | |||
509 | static void i2c_scan_static_board_info(struct i2c_adapter *adapter) | 806 | static void i2c_scan_static_board_info(struct i2c_adapter *adapter) |
510 | { | 807 | { |
511 | struct i2c_devinfo *devinfo; | 808 | struct i2c_devinfo *devinfo; |
@@ -522,11 +819,9 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter) | |||
522 | up_read(&__i2c_board_lock); | 819 | up_read(&__i2c_board_lock); |
523 | } | 820 | } |
524 | 821 | ||
525 | static int i2c_do_add_adapter(struct device_driver *d, void *data) | 822 | static int i2c_do_add_adapter(struct i2c_driver *driver, |
823 | struct i2c_adapter *adap) | ||
526 | { | 824 | { |
527 | struct i2c_driver *driver = to_i2c_driver(d); | ||
528 | struct i2c_adapter *adap = data; | ||
529 | |||
530 | /* Detect supported devices on that bus, and instantiate them */ | 825 | /* Detect supported devices on that bus, and instantiate them */ |
531 | i2c_detect(adap, driver); | 826 | i2c_detect(adap, driver); |
532 | 827 | ||
@@ -538,9 +833,14 @@ static int i2c_do_add_adapter(struct device_driver *d, void *data) | |||
538 | return 0; | 833 | return 0; |
539 | } | 834 | } |
540 | 835 | ||
836 | static int __process_new_adapter(struct device_driver *d, void *data) | ||
837 | { | ||
838 | return i2c_do_add_adapter(to_i2c_driver(d), data); | ||
839 | } | ||
840 | |||
541 | static int i2c_register_adapter(struct i2c_adapter *adap) | 841 | static int i2c_register_adapter(struct i2c_adapter *adap) |
542 | { | 842 | { |
543 | int res = 0, dummy; | 843 | int res = 0; |
544 | 844 | ||
545 | /* Can't register until after driver model init */ | 845 | /* Can't register until after driver model init */ |
546 | if (unlikely(WARN_ON(!i2c_bus_type.p))) { | 846 | if (unlikely(WARN_ON(!i2c_bus_type.p))) { |
@@ -548,29 +848,50 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
548 | goto out_list; | 848 | goto out_list; |
549 | } | 849 | } |
550 | 850 | ||
551 | mutex_init(&adap->bus_lock); | 851 | /* Sanity checks */ |
852 | if (unlikely(adap->name[0] == '\0')) { | ||
853 | pr_err("i2c-core: Attempt to register an adapter with " | ||
854 | "no name!\n"); | ||
855 | return -EINVAL; | ||
856 | } | ||
857 | if (unlikely(!adap->algo)) { | ||
858 | pr_err("i2c-core: Attempt to register adapter '%s' with " | ||
859 | "no algo!\n", adap->name); | ||
860 | return -EINVAL; | ||
861 | } | ||
862 | |||
863 | rt_mutex_init(&adap->bus_lock); | ||
864 | mutex_init(&adap->userspace_clients_lock); | ||
865 | INIT_LIST_HEAD(&adap->userspace_clients); | ||
552 | 866 | ||
553 | /* Set default timeout to 1 second if not already set */ | 867 | /* Set default timeout to 1 second if not already set */ |
554 | if (adap->timeout == 0) | 868 | if (adap->timeout == 0) |
555 | adap->timeout = HZ; | 869 | adap->timeout = HZ; |
556 | 870 | ||
557 | dev_set_name(&adap->dev, "i2c-%d", adap->nr); | 871 | dev_set_name(&adap->dev, "i2c-%d", adap->nr); |
558 | adap->dev.release = &i2c_adapter_dev_release; | 872 | adap->dev.bus = &i2c_bus_type; |
559 | adap->dev.class = &i2c_adapter_class; | 873 | adap->dev.type = &i2c_adapter_type; |
560 | res = device_register(&adap->dev); | 874 | res = device_register(&adap->dev); |
561 | if (res) | 875 | if (res) |
562 | goto out_list; | 876 | goto out_list; |
563 | 877 | ||
564 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); | 878 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); |
565 | 879 | ||
880 | #ifdef CONFIG_I2C_COMPAT | ||
881 | res = class_compat_create_link(i2c_adapter_compat_class, &adap->dev, | ||
882 | adap->dev.parent); | ||
883 | if (res) | ||
884 | dev_warn(&adap->dev, | ||
885 | "Failed to create compatibility class link\n"); | ||
886 | #endif | ||
887 | |||
566 | /* create pre-declared device nodes */ | 888 | /* create pre-declared device nodes */ |
567 | if (adap->nr < __i2c_first_dynamic_bus_num) | 889 | if (adap->nr < __i2c_first_dynamic_bus_num) |
568 | i2c_scan_static_board_info(adap); | 890 | i2c_scan_static_board_info(adap); |
569 | 891 | ||
570 | /* Notify drivers */ | 892 | /* Notify drivers */ |
571 | mutex_lock(&core_lock); | 893 | mutex_lock(&core_lock); |
572 | dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, | 894 | bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter); |
573 | i2c_do_add_adapter); | ||
574 | mutex_unlock(&core_lock); | 895 | mutex_unlock(&core_lock); |
575 | 896 | ||
576 | return 0; | 897 | return 0; |
@@ -671,10 +992,9 @@ retry: | |||
671 | } | 992 | } |
672 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); | 993 | EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); |
673 | 994 | ||
674 | static int i2c_do_del_adapter(struct device_driver *d, void *data) | 995 | static int i2c_do_del_adapter(struct i2c_driver *driver, |
996 | struct i2c_adapter *adapter) | ||
675 | { | 997 | { |
676 | struct i2c_driver *driver = to_i2c_driver(d); | ||
677 | struct i2c_adapter *adapter = data; | ||
678 | struct i2c_client *client, *_n; | 998 | struct i2c_client *client, *_n; |
679 | int res; | 999 | int res; |
680 | 1000 | ||
@@ -706,6 +1026,11 @@ static int __unregister_client(struct device *dev, void *dummy) | |||
706 | return 0; | 1026 | return 0; |
707 | } | 1027 | } |
708 | 1028 | ||
1029 | static int __process_removed_adapter(struct device_driver *d, void *data) | ||
1030 | { | ||
1031 | return i2c_do_del_adapter(to_i2c_driver(d), data); | ||
1032 | } | ||
1033 | |||
709 | /** | 1034 | /** |
710 | * i2c_del_adapter - unregister I2C adapter | 1035 | * i2c_del_adapter - unregister I2C adapter |
711 | * @adap: the adapter being unregistered | 1036 | * @adap: the adapter being unregistered |
@@ -718,6 +1043,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
718 | { | 1043 | { |
719 | int res = 0; | 1044 | int res = 0; |
720 | struct i2c_adapter *found; | 1045 | struct i2c_adapter *found; |
1046 | struct i2c_client *client, *next; | ||
721 | 1047 | ||
722 | /* First make sure that this adapter was ever added */ | 1048 | /* First make sure that this adapter was ever added */ |
723 | mutex_lock(&core_lock); | 1049 | mutex_lock(&core_lock); |
@@ -732,15 +1058,34 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
732 | /* Tell drivers about this removal */ | 1058 | /* Tell drivers about this removal */ |
733 | mutex_lock(&core_lock); | 1059 | mutex_lock(&core_lock); |
734 | res = bus_for_each_drv(&i2c_bus_type, NULL, adap, | 1060 | res = bus_for_each_drv(&i2c_bus_type, NULL, adap, |
735 | i2c_do_del_adapter); | 1061 | __process_removed_adapter); |
736 | mutex_unlock(&core_lock); | 1062 | mutex_unlock(&core_lock); |
737 | if (res) | 1063 | if (res) |
738 | return res; | 1064 | return res; |
739 | 1065 | ||
1066 | /* Remove devices instantiated from sysfs */ | ||
1067 | mutex_lock(&adap->userspace_clients_lock); | ||
1068 | list_for_each_entry_safe(client, next, &adap->userspace_clients, | ||
1069 | detected) { | ||
1070 | dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, | ||
1071 | client->addr); | ||
1072 | list_del(&client->detected); | ||
1073 | i2c_unregister_device(client); | ||
1074 | } | ||
1075 | mutex_unlock(&adap->userspace_clients_lock); | ||
1076 | |||
740 | /* Detach any active clients. This can't fail, thus we do not | 1077 | /* Detach any active clients. This can't fail, thus we do not |
741 | checking the returned value. */ | 1078 | checking the returned value. */ |
742 | res = device_for_each_child(&adap->dev, NULL, __unregister_client); | 1079 | res = device_for_each_child(&adap->dev, NULL, __unregister_client); |
743 | 1080 | ||
1081 | #ifdef CONFIG_I2C_COMPAT | ||
1082 | class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, | ||
1083 | adap->dev.parent); | ||
1084 | #endif | ||
1085 | |||
1086 | /* device name is gone after device_unregister */ | ||
1087 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); | ||
1088 | |||
744 | /* clean up the sysfs representation */ | 1089 | /* clean up the sysfs representation */ |
745 | init_completion(&adap->dev_released); | 1090 | init_completion(&adap->dev_released); |
746 | device_unregister(&adap->dev); | 1091 | device_unregister(&adap->dev); |
@@ -753,8 +1098,6 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
753 | idr_remove(&i2c_adapter_idr, adap->nr); | 1098 | idr_remove(&i2c_adapter_idr, adap->nr); |
754 | mutex_unlock(&core_lock); | 1099 | mutex_unlock(&core_lock); |
755 | 1100 | ||
756 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); | ||
757 | |||
758 | /* Clear the device structure in case this adapter is ever going to be | 1101 | /* Clear the device structure in case this adapter is ever going to be |
759 | added again */ | 1102 | added again */ |
760 | memset(&adap->dev, 0, sizeof(adap->dev)); | 1103 | memset(&adap->dev, 0, sizeof(adap->dev)); |
@@ -766,18 +1109,11 @@ EXPORT_SYMBOL(i2c_del_adapter); | |||
766 | 1109 | ||
767 | /* ------------------------------------------------------------------------- */ | 1110 | /* ------------------------------------------------------------------------- */ |
768 | 1111 | ||
769 | static int __attach_adapter(struct device *dev, void *data) | 1112 | static int __process_new_driver(struct device *dev, void *data) |
770 | { | 1113 | { |
771 | struct i2c_adapter *adapter = to_i2c_adapter(dev); | 1114 | if (dev->type != &i2c_adapter_type) |
772 | struct i2c_driver *driver = data; | 1115 | return 0; |
773 | 1116 | return i2c_do_add_adapter(data, to_i2c_adapter(dev)); | |
774 | i2c_detect(adapter, driver); | ||
775 | |||
776 | /* Legacy drivers scan i2c busses directly */ | ||
777 | if (driver->attach_adapter) | ||
778 | driver->attach_adapter(adapter); | ||
779 | |||
780 | return 0; | ||
781 | } | 1117 | } |
782 | 1118 | ||
783 | /* | 1119 | /* |
@@ -809,37 +1145,18 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
809 | INIT_LIST_HEAD(&driver->clients); | 1145 | INIT_LIST_HEAD(&driver->clients); |
810 | /* Walk the adapters that are already present */ | 1146 | /* Walk the adapters that are already present */ |
811 | mutex_lock(&core_lock); | 1147 | mutex_lock(&core_lock); |
812 | class_for_each_device(&i2c_adapter_class, NULL, driver, | 1148 | bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver); |
813 | __attach_adapter); | ||
814 | mutex_unlock(&core_lock); | 1149 | mutex_unlock(&core_lock); |
815 | 1150 | ||
816 | return 0; | 1151 | return 0; |
817 | } | 1152 | } |
818 | EXPORT_SYMBOL(i2c_register_driver); | 1153 | EXPORT_SYMBOL(i2c_register_driver); |
819 | 1154 | ||
820 | static int __detach_adapter(struct device *dev, void *data) | 1155 | static int __process_removed_driver(struct device *dev, void *data) |
821 | { | 1156 | { |
822 | struct i2c_adapter *adapter = to_i2c_adapter(dev); | 1157 | if (dev->type != &i2c_adapter_type) |
823 | struct i2c_driver *driver = data; | 1158 | return 0; |
824 | struct i2c_client *client, *_n; | 1159 | return i2c_do_del_adapter(data, to_i2c_adapter(dev)); |
825 | |||
826 | /* Remove the devices we created ourselves as the result of hardware | ||
827 | * probing (using a driver's detect method) */ | ||
828 | list_for_each_entry_safe(client, _n, &driver->clients, detected) { | ||
829 | dev_dbg(&adapter->dev, "Removing %s at 0x%x\n", | ||
830 | client->name, client->addr); | ||
831 | list_del(&client->detected); | ||
832 | i2c_unregister_device(client); | ||
833 | } | ||
834 | |||
835 | if (driver->detach_adapter) { | ||
836 | if (driver->detach_adapter(adapter)) | ||
837 | dev_err(&adapter->dev, | ||
838 | "detach_adapter failed for driver [%s]\n", | ||
839 | driver->driver.name); | ||
840 | } | ||
841 | |||
842 | return 0; | ||
843 | } | 1160 | } |
844 | 1161 | ||
845 | /** | 1162 | /** |
@@ -850,8 +1167,7 @@ static int __detach_adapter(struct device *dev, void *data) | |||
850 | void i2c_del_driver(struct i2c_driver *driver) | 1167 | void i2c_del_driver(struct i2c_driver *driver) |
851 | { | 1168 | { |
852 | mutex_lock(&core_lock); | 1169 | mutex_lock(&core_lock); |
853 | class_for_each_device(&i2c_adapter_class, NULL, driver, | 1170 | bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_removed_driver); |
854 | __detach_adapter); | ||
855 | mutex_unlock(&core_lock); | 1171 | mutex_unlock(&core_lock); |
856 | 1172 | ||
857 | driver_unregister(&driver->driver); | 1173 | driver_unregister(&driver->driver); |
@@ -861,21 +1177,6 @@ EXPORT_SYMBOL(i2c_del_driver); | |||
861 | 1177 | ||
862 | /* ------------------------------------------------------------------------- */ | 1178 | /* ------------------------------------------------------------------------- */ |
863 | 1179 | ||
864 | static int __i2c_check_addr(struct device *dev, void *addrp) | ||
865 | { | ||
866 | struct i2c_client *client = i2c_verify_client(dev); | ||
867 | int addr = *(int *)addrp; | ||
868 | |||
869 | if (client && client->addr == addr) | ||
870 | return -EBUSY; | ||
871 | return 0; | ||
872 | } | ||
873 | |||
874 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr) | ||
875 | { | ||
876 | return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); | ||
877 | } | ||
878 | |||
879 | /** | 1180 | /** |
880 | * i2c_use_client - increments the reference count of the i2c client structure | 1181 | * i2c_use_client - increments the reference count of the i2c client structure |
881 | * @client: the client being referenced | 1182 | * @client: the client being referenced |
@@ -940,17 +1241,23 @@ static int __init i2c_init(void) | |||
940 | retval = bus_register(&i2c_bus_type); | 1241 | retval = bus_register(&i2c_bus_type); |
941 | if (retval) | 1242 | if (retval) |
942 | return retval; | 1243 | return retval; |
943 | retval = class_register(&i2c_adapter_class); | 1244 | #ifdef CONFIG_I2C_COMPAT |
944 | if (retval) | 1245 | i2c_adapter_compat_class = class_compat_register("i2c-adapter"); |
1246 | if (!i2c_adapter_compat_class) { | ||
1247 | retval = -ENOMEM; | ||
945 | goto bus_err; | 1248 | goto bus_err; |
1249 | } | ||
1250 | #endif | ||
946 | retval = i2c_add_driver(&dummy_driver); | 1251 | retval = i2c_add_driver(&dummy_driver); |
947 | if (retval) | 1252 | if (retval) |
948 | goto class_err; | 1253 | goto class_err; |
949 | return 0; | 1254 | return 0; |
950 | 1255 | ||
951 | class_err: | 1256 | class_err: |
952 | class_unregister(&i2c_adapter_class); | 1257 | #ifdef CONFIG_I2C_COMPAT |
1258 | class_compat_unregister(i2c_adapter_compat_class); | ||
953 | bus_err: | 1259 | bus_err: |
1260 | #endif | ||
954 | bus_unregister(&i2c_bus_type); | 1261 | bus_unregister(&i2c_bus_type); |
955 | return retval; | 1262 | return retval; |
956 | } | 1263 | } |
@@ -958,7 +1265,9 @@ bus_err: | |||
958 | static void __exit i2c_exit(void) | 1265 | static void __exit i2c_exit(void) |
959 | { | 1266 | { |
960 | i2c_del_driver(&dummy_driver); | 1267 | i2c_del_driver(&dummy_driver); |
961 | class_unregister(&i2c_adapter_class); | 1268 | #ifdef CONFIG_I2C_COMPAT |
1269 | class_compat_unregister(i2c_adapter_compat_class); | ||
1270 | #endif | ||
962 | bus_unregister(&i2c_bus_type); | 1271 | bus_unregister(&i2c_bus_type); |
963 | } | 1272 | } |
964 | 1273 | ||
@@ -1018,12 +1327,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
1018 | #endif | 1327 | #endif |
1019 | 1328 | ||
1020 | if (in_atomic() || irqs_disabled()) { | 1329 | if (in_atomic() || irqs_disabled()) { |
1021 | ret = mutex_trylock(&adap->bus_lock); | 1330 | ret = i2c_trylock_adapter(adap); |
1022 | if (!ret) | 1331 | if (!ret) |
1023 | /* I2C activity is ongoing. */ | 1332 | /* I2C activity is ongoing. */ |
1024 | return -EAGAIN; | 1333 | return -EAGAIN; |
1025 | } else { | 1334 | } else { |
1026 | mutex_lock_nested(&adap->bus_lock, adap->level); | 1335 | i2c_lock_adapter(adap); |
1027 | } | 1336 | } |
1028 | 1337 | ||
1029 | /* Retry automatically on arbitration loss */ | 1338 | /* Retry automatically on arbitration loss */ |
@@ -1035,7 +1344,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
1035 | if (time_after(jiffies, orig_jiffies + adap->timeout)) | 1344 | if (time_after(jiffies, orig_jiffies + adap->timeout)) |
1036 | break; | 1345 | break; |
1037 | } | 1346 | } |
1038 | mutex_unlock(&adap->bus_lock); | 1347 | i2c_unlock_adapter(adap); |
1039 | 1348 | ||
1040 | return ret; | 1349 | return ret; |
1041 | } else { | 1350 | } else { |
@@ -1049,14 +1358,14 @@ EXPORT_SYMBOL(i2c_transfer); | |||
1049 | * i2c_master_send - issue a single I2C message in master transmit mode | 1358 | * i2c_master_send - issue a single I2C message in master transmit mode |
1050 | * @client: Handle to slave device | 1359 | * @client: Handle to slave device |
1051 | * @buf: Data that will be written to the slave | 1360 | * @buf: Data that will be written to the slave |
1052 | * @count: How many bytes to write | 1361 | * @count: How many bytes to write, must be less than 64k since msg.len is u16 |
1053 | * | 1362 | * |
1054 | * Returns negative errno, or else the number of bytes written. | 1363 | * Returns negative errno, or else the number of bytes written. |
1055 | */ | 1364 | */ |
1056 | int i2c_master_send(struct i2c_client *client,const char *buf ,int count) | 1365 | int i2c_master_send(const struct i2c_client *client, const char *buf, int count) |
1057 | { | 1366 | { |
1058 | int ret; | 1367 | int ret; |
1059 | struct i2c_adapter *adap=client->adapter; | 1368 | struct i2c_adapter *adap = client->adapter; |
1060 | struct i2c_msg msg; | 1369 | struct i2c_msg msg; |
1061 | 1370 | ||
1062 | msg.addr = client->addr; | 1371 | msg.addr = client->addr; |
@@ -1076,13 +1385,13 @@ EXPORT_SYMBOL(i2c_master_send); | |||
1076 | * i2c_master_recv - issue a single I2C message in master receive mode | 1385 | * i2c_master_recv - issue a single I2C message in master receive mode |
1077 | * @client: Handle to slave device | 1386 | * @client: Handle to slave device |
1078 | * @buf: Where to store data read from slave | 1387 | * @buf: Where to store data read from slave |
1079 | * @count: How many bytes to read | 1388 | * @count: How many bytes to read, must be less than 64k since msg.len is u16 |
1080 | * | 1389 | * |
1081 | * Returns negative errno, or else the number of bytes read. | 1390 | * Returns negative errno, or else the number of bytes read. |
1082 | */ | 1391 | */ |
1083 | int i2c_master_recv(struct i2c_client *client, char *buf ,int count) | 1392 | int i2c_master_recv(const struct i2c_client *client, char *buf, int count) |
1084 | { | 1393 | { |
1085 | struct i2c_adapter *adap=client->adapter; | 1394 | struct i2c_adapter *adap = client->adapter; |
1086 | struct i2c_msg msg; | 1395 | struct i2c_msg msg; |
1087 | int ret; | 1396 | int ret; |
1088 | 1397 | ||
@@ -1106,7 +1415,46 @@ EXPORT_SYMBOL(i2c_master_recv); | |||
1106 | * ---------------------------------------------------- | 1415 | * ---------------------------------------------------- |
1107 | */ | 1416 | */ |
1108 | 1417 | ||
1109 | static int i2c_detect_address(struct i2c_client *temp_client, int kind, | 1418 | /* |
1419 | * Legacy default probe function, mostly relevant for SMBus. The default | ||
1420 | * probe method is a quick write, but it is known to corrupt the 24RF08 | ||
1421 | * EEPROMs due to a state machine bug, and could also irreversibly | ||
1422 | * write-protect some EEPROMs, so for address ranges 0x30-0x37 and 0x50-0x5f, | ||
1423 | * we use a short byte read instead. Also, some bus drivers don't implement | ||
1424 | * quick write, so we fallback to a byte read in that case too. | ||
1425 | * On x86, there is another special case for FSC hardware monitoring chips, | ||
1426 | * which want regular byte reads (address 0x73.) Fortunately, these are the | ||
1427 | * only known chips using this I2C address on PC hardware. | ||
1428 | * Returns 1 if probe succeeded, 0 if not. | ||
1429 | */ | ||
1430 | static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr) | ||
1431 | { | ||
1432 | int err; | ||
1433 | union i2c_smbus_data dummy; | ||
1434 | |||
1435 | #ifdef CONFIG_X86 | ||
1436 | if (addr == 0x73 && (adap->class & I2C_CLASS_HWMON) | ||
1437 | && i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE_DATA)) | ||
1438 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1439 | I2C_SMBUS_BYTE_DATA, &dummy); | ||
1440 | else | ||
1441 | #endif | ||
1442 | if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50) | ||
1443 | && i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) | ||
1444 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, | ||
1445 | I2C_SMBUS_QUICK, NULL); | ||
1446 | else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) | ||
1447 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1448 | I2C_SMBUS_BYTE, &dummy); | ||
1449 | else { | ||
1450 | dev_warn(&adap->dev, "No suitable probing method supported\n"); | ||
1451 | err = -EOPNOTSUPP; | ||
1452 | } | ||
1453 | |||
1454 | return err >= 0; | ||
1455 | } | ||
1456 | |||
1457 | static int i2c_detect_address(struct i2c_client *temp_client, | ||
1110 | struct i2c_driver *driver) | 1458 | struct i2c_driver *driver) |
1111 | { | 1459 | { |
1112 | struct i2c_board_info info; | 1460 | struct i2c_board_info info; |
@@ -1115,32 +1463,25 @@ static int i2c_detect_address(struct i2c_client *temp_client, int kind, | |||
1115 | int err; | 1463 | int err; |
1116 | 1464 | ||
1117 | /* Make sure the address is valid */ | 1465 | /* Make sure the address is valid */ |
1118 | if (addr < 0x03 || addr > 0x77) { | 1466 | err = i2c_check_addr_validity(addr); |
1467 | if (err) { | ||
1119 | dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", | 1468 | dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", |
1120 | addr); | 1469 | addr); |
1121 | return -EINVAL; | 1470 | return err; |
1122 | } | 1471 | } |
1123 | 1472 | ||
1124 | /* Skip if already in use */ | 1473 | /* Skip if already in use */ |
1125 | if (i2c_check_addr(adapter, addr)) | 1474 | if (i2c_check_addr_busy(adapter, addr)) |
1126 | return 0; | 1475 | return 0; |
1127 | 1476 | ||
1128 | /* Make sure there is something at this address, unless forced */ | 1477 | /* Make sure there is something at this address */ |
1129 | if (kind < 0) { | 1478 | if (!i2c_default_probe(adapter, addr)) |
1130 | if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, | 1479 | return 0; |
1131 | I2C_SMBUS_QUICK, NULL) < 0) | ||
1132 | return 0; | ||
1133 | |||
1134 | /* prevent 24RF08 corruption */ | ||
1135 | if ((addr & ~0x0f) == 0x50) | ||
1136 | i2c_smbus_xfer(adapter, addr, 0, 0, 0, | ||
1137 | I2C_SMBUS_QUICK, NULL); | ||
1138 | } | ||
1139 | 1480 | ||
1140 | /* Finally call the custom detection function */ | 1481 | /* Finally call the custom detection function */ |
1141 | memset(&info, 0, sizeof(struct i2c_board_info)); | 1482 | memset(&info, 0, sizeof(struct i2c_board_info)); |
1142 | info.addr = addr; | 1483 | info.addr = addr; |
1143 | err = driver->detect(temp_client, kind, &info); | 1484 | err = driver->detect(temp_client, &info); |
1144 | if (err) { | 1485 | if (err) { |
1145 | /* -ENODEV is returned if the detection fails. We catch it | 1486 | /* -ENODEV is returned if the detection fails. We catch it |
1146 | here as this isn't an error. */ | 1487 | here as this isn't an error. */ |
@@ -1170,13 +1511,17 @@ static int i2c_detect_address(struct i2c_client *temp_client, int kind, | |||
1170 | 1511 | ||
1171 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) | 1512 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) |
1172 | { | 1513 | { |
1173 | const struct i2c_client_address_data *address_data; | 1514 | const unsigned short *address_list; |
1174 | struct i2c_client *temp_client; | 1515 | struct i2c_client *temp_client; |
1175 | int i, err = 0; | 1516 | int i, err = 0; |
1176 | int adap_id = i2c_adapter_id(adapter); | 1517 | int adap_id = i2c_adapter_id(adapter); |
1177 | 1518 | ||
1178 | address_data = driver->address_data; | 1519 | address_list = driver->address_list; |
1179 | if (!driver->detect || !address_data) | 1520 | if (!driver->detect || !address_list) |
1521 | return 0; | ||
1522 | |||
1523 | /* Stop here if the classes do not match */ | ||
1524 | if (!(adapter->class & driver->class)) | ||
1180 | return 0; | 1525 | return 0; |
1181 | 1526 | ||
1182 | /* Set up a temporary client to help detect callback */ | 1527 | /* Set up a temporary client to help detect callback */ |
@@ -1185,150 +1530,55 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) | |||
1185 | return -ENOMEM; | 1530 | return -ENOMEM; |
1186 | temp_client->adapter = adapter; | 1531 | temp_client->adapter = adapter; |
1187 | 1532 | ||
1188 | /* Force entries are done first, and are not affected by ignore | 1533 | for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { |
1189 | entries */ | ||
1190 | if (address_data->forces) { | ||
1191 | const unsigned short * const *forces = address_data->forces; | ||
1192 | int kind; | ||
1193 | |||
1194 | for (kind = 0; forces[kind]; kind++) { | ||
1195 | for (i = 0; forces[kind][i] != I2C_CLIENT_END; | ||
1196 | i += 2) { | ||
1197 | if (forces[kind][i] == adap_id | ||
1198 | || forces[kind][i] == ANY_I2C_BUS) { | ||
1199 | dev_dbg(&adapter->dev, "found force " | ||
1200 | "parameter for adapter %d, " | ||
1201 | "addr 0x%02x, kind %d\n", | ||
1202 | adap_id, forces[kind][i + 1], | ||
1203 | kind); | ||
1204 | temp_client->addr = forces[kind][i + 1]; | ||
1205 | err = i2c_detect_address(temp_client, | ||
1206 | kind, driver); | ||
1207 | if (err) | ||
1208 | goto exit_free; | ||
1209 | } | ||
1210 | } | ||
1211 | } | ||
1212 | } | ||
1213 | |||
1214 | /* Stop here if the classes do not match */ | ||
1215 | if (!(adapter->class & driver->class)) | ||
1216 | goto exit_free; | ||
1217 | |||
1218 | /* Stop here if we can't use SMBUS_QUICK */ | ||
1219 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { | ||
1220 | if (address_data->probe[0] == I2C_CLIENT_END | ||
1221 | && address_data->normal_i2c[0] == I2C_CLIENT_END) | ||
1222 | goto exit_free; | ||
1223 | |||
1224 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " | ||
1225 | "can't probe for chips\n"); | ||
1226 | err = -EOPNOTSUPP; | ||
1227 | goto exit_free; | ||
1228 | } | ||
1229 | |||
1230 | /* Probe entries are done second, and are not affected by ignore | ||
1231 | entries either */ | ||
1232 | for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { | ||
1233 | if (address_data->probe[i] == adap_id | ||
1234 | || address_data->probe[i] == ANY_I2C_BUS) { | ||
1235 | dev_dbg(&adapter->dev, "found probe parameter for " | ||
1236 | "adapter %d, addr 0x%02x\n", adap_id, | ||
1237 | address_data->probe[i + 1]); | ||
1238 | temp_client->addr = address_data->probe[i + 1]; | ||
1239 | err = i2c_detect_address(temp_client, -1, driver); | ||
1240 | if (err) | ||
1241 | goto exit_free; | ||
1242 | } | ||
1243 | } | ||
1244 | |||
1245 | /* Normal entries are done last, unless shadowed by an ignore entry */ | ||
1246 | for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) { | ||
1247 | int j, ignore; | ||
1248 | |||
1249 | ignore = 0; | ||
1250 | for (j = 0; address_data->ignore[j] != I2C_CLIENT_END; | ||
1251 | j += 2) { | ||
1252 | if ((address_data->ignore[j] == adap_id || | ||
1253 | address_data->ignore[j] == ANY_I2C_BUS) | ||
1254 | && address_data->ignore[j + 1] | ||
1255 | == address_data->normal_i2c[i]) { | ||
1256 | dev_dbg(&adapter->dev, "found ignore " | ||
1257 | "parameter for adapter %d, " | ||
1258 | "addr 0x%02x\n", adap_id, | ||
1259 | address_data->ignore[j + 1]); | ||
1260 | ignore = 1; | ||
1261 | break; | ||
1262 | } | ||
1263 | } | ||
1264 | if (ignore) | ||
1265 | continue; | ||
1266 | |||
1267 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " | 1534 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " |
1268 | "addr 0x%02x\n", adap_id, | 1535 | "addr 0x%02x\n", adap_id, address_list[i]); |
1269 | address_data->normal_i2c[i]); | 1536 | temp_client->addr = address_list[i]; |
1270 | temp_client->addr = address_data->normal_i2c[i]; | 1537 | err = i2c_detect_address(temp_client, driver); |
1271 | err = i2c_detect_address(temp_client, -1, driver); | 1538 | if (unlikely(err)) |
1272 | if (err) | 1539 | break; |
1273 | goto exit_free; | ||
1274 | } | 1540 | } |
1275 | 1541 | ||
1276 | exit_free: | ||
1277 | kfree(temp_client); | 1542 | kfree(temp_client); |
1278 | return err; | 1543 | return err; |
1279 | } | 1544 | } |
1280 | 1545 | ||
1546 | int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr) | ||
1547 | { | ||
1548 | return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1549 | I2C_SMBUS_QUICK, NULL) >= 0; | ||
1550 | } | ||
1551 | EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read); | ||
1552 | |||
1281 | struct i2c_client * | 1553 | struct i2c_client * |
1282 | i2c_new_probed_device(struct i2c_adapter *adap, | 1554 | i2c_new_probed_device(struct i2c_adapter *adap, |
1283 | struct i2c_board_info *info, | 1555 | struct i2c_board_info *info, |
1284 | unsigned short const *addr_list) | 1556 | unsigned short const *addr_list, |
1557 | int (*probe)(struct i2c_adapter *, unsigned short addr)) | ||
1285 | { | 1558 | { |
1286 | int i; | 1559 | int i; |
1287 | 1560 | ||
1288 | /* Stop here if the bus doesn't support probing */ | 1561 | if (!probe) |
1289 | if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) { | 1562 | probe = i2c_default_probe; |
1290 | dev_err(&adap->dev, "Probing not supported\n"); | ||
1291 | return NULL; | ||
1292 | } | ||
1293 | 1563 | ||
1294 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { | 1564 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { |
1295 | /* Check address validity */ | 1565 | /* Check address validity */ |
1296 | if (addr_list[i] < 0x03 || addr_list[i] > 0x77) { | 1566 | if (i2c_check_addr_validity(addr_list[i]) < 0) { |
1297 | dev_warn(&adap->dev, "Invalid 7-bit address " | 1567 | dev_warn(&adap->dev, "Invalid 7-bit address " |
1298 | "0x%02x\n", addr_list[i]); | 1568 | "0x%02x\n", addr_list[i]); |
1299 | continue; | 1569 | continue; |
1300 | } | 1570 | } |
1301 | 1571 | ||
1302 | /* Check address availability */ | 1572 | /* Check address availability */ |
1303 | if (i2c_check_addr(adap, addr_list[i])) { | 1573 | if (i2c_check_addr_busy(adap, addr_list[i])) { |
1304 | dev_dbg(&adap->dev, "Address 0x%02x already in " | 1574 | dev_dbg(&adap->dev, "Address 0x%02x already in " |
1305 | "use, not probing\n", addr_list[i]); | 1575 | "use, not probing\n", addr_list[i]); |
1306 | continue; | 1576 | continue; |
1307 | } | 1577 | } |
1308 | 1578 | ||
1309 | /* Test address responsiveness | 1579 | /* Test address responsiveness */ |
1310 | The default probe method is a quick write, but it is known | 1580 | if (probe(adap, addr_list[i])) |
1311 | to corrupt the 24RF08 EEPROMs due to a state machine bug, | 1581 | break; |
1312 | and could also irreversibly write-protect some EEPROMs, so | ||
1313 | for address ranges 0x30-0x37 and 0x50-0x5f, we use a byte | ||
1314 | read instead. Also, some bus drivers don't implement | ||
1315 | quick write, so we fallback to a byte read it that case | ||
1316 | too. */ | ||
1317 | if ((addr_list[i] & ~0x07) == 0x30 | ||
1318 | || (addr_list[i] & ~0x0f) == 0x50 | ||
1319 | || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) { | ||
1320 | union i2c_smbus_data data; | ||
1321 | |||
1322 | if (i2c_smbus_xfer(adap, addr_list[i], 0, | ||
1323 | I2C_SMBUS_READ, 0, | ||
1324 | I2C_SMBUS_BYTE, &data) >= 0) | ||
1325 | break; | ||
1326 | } else { | ||
1327 | if (i2c_smbus_xfer(adap, addr_list[i], 0, | ||
1328 | I2C_SMBUS_WRITE, 0, | ||
1329 | I2C_SMBUS_QUICK, NULL) >= 0) | ||
1330 | break; | ||
1331 | } | ||
1332 | } | 1582 | } |
1333 | 1583 | ||
1334 | if (addr_list[i] == I2C_CLIENT_END) { | 1584 | if (addr_list[i] == I2C_CLIENT_END) { |
@@ -1341,7 +1591,7 @@ i2c_new_probed_device(struct i2c_adapter *adap, | |||
1341 | } | 1591 | } |
1342 | EXPORT_SYMBOL_GPL(i2c_new_probed_device); | 1592 | EXPORT_SYMBOL_GPL(i2c_new_probed_device); |
1343 | 1593 | ||
1344 | struct i2c_adapter* i2c_get_adapter(int id) | 1594 | struct i2c_adapter *i2c_get_adapter(int id) |
1345 | { | 1595 | { |
1346 | struct i2c_adapter *adapter; | 1596 | struct i2c_adapter *adapter; |
1347 | 1597 | ||
@@ -1368,7 +1618,7 @@ static u8 crc8(u16 data) | |||
1368 | { | 1618 | { |
1369 | int i; | 1619 | int i; |
1370 | 1620 | ||
1371 | for(i = 0; i < 8; i++) { | 1621 | for (i = 0; i < 8; i++) { |
1372 | if (data & 0x8000) | 1622 | if (data & 0x8000) |
1373 | data = data ^ POLY; | 1623 | data = data ^ POLY; |
1374 | data = data << 1; | 1624 | data = data << 1; |
@@ -1381,7 +1631,7 @@ static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count) | |||
1381 | { | 1631 | { |
1382 | int i; | 1632 | int i; |
1383 | 1633 | ||
1384 | for(i = 0; i < count; i++) | 1634 | for (i = 0; i < count; i++) |
1385 | crc = crc8((crc ^ p[i]) << 8); | 1635 | crc = crc8((crc ^ p[i]) << 8); |
1386 | return crc; | 1636 | return crc; |
1387 | } | 1637 | } |
@@ -1429,7 +1679,7 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg) | |||
1429 | * This executes the SMBus "receive byte" protocol, returning negative errno | 1679 | * This executes the SMBus "receive byte" protocol, returning negative errno |
1430 | * else the byte received from the device. | 1680 | * else the byte received from the device. |
1431 | */ | 1681 | */ |
1432 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 1682 | s32 i2c_smbus_read_byte(const struct i2c_client *client) |
1433 | { | 1683 | { |
1434 | union i2c_smbus_data data; | 1684 | union i2c_smbus_data data; |
1435 | int status; | 1685 | int status; |
@@ -1449,9 +1699,9 @@ EXPORT_SYMBOL(i2c_smbus_read_byte); | |||
1449 | * This executes the SMBus "send byte" protocol, returning negative errno | 1699 | * This executes the SMBus "send byte" protocol, returning negative errno |
1450 | * else zero on success. | 1700 | * else zero on success. |
1451 | */ | 1701 | */ |
1452 | s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) | 1702 | s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value) |
1453 | { | 1703 | { |
1454 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1704 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1455 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | 1705 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); |
1456 | } | 1706 | } |
1457 | EXPORT_SYMBOL(i2c_smbus_write_byte); | 1707 | EXPORT_SYMBOL(i2c_smbus_write_byte); |
@@ -1464,7 +1714,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte); | |||
1464 | * This executes the SMBus "read byte" protocol, returning negative errno | 1714 | * This executes the SMBus "read byte" protocol, returning negative errno |
1465 | * else a data byte received from the device. | 1715 | * else a data byte received from the device. |
1466 | */ | 1716 | */ |
1467 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) | 1717 | s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command) |
1468 | { | 1718 | { |
1469 | union i2c_smbus_data data; | 1719 | union i2c_smbus_data data; |
1470 | int status; | 1720 | int status; |
@@ -1485,13 +1735,14 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data); | |||
1485 | * This executes the SMBus "write byte" protocol, returning negative errno | 1735 | * This executes the SMBus "write byte" protocol, returning negative errno |
1486 | * else zero on success. | 1736 | * else zero on success. |
1487 | */ | 1737 | */ |
1488 | s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) | 1738 | s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command, |
1739 | u8 value) | ||
1489 | { | 1740 | { |
1490 | union i2c_smbus_data data; | 1741 | union i2c_smbus_data data; |
1491 | data.byte = value; | 1742 | data.byte = value; |
1492 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1743 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1493 | I2C_SMBUS_WRITE,command, | 1744 | I2C_SMBUS_WRITE, command, |
1494 | I2C_SMBUS_BYTE_DATA,&data); | 1745 | I2C_SMBUS_BYTE_DATA, &data); |
1495 | } | 1746 | } |
1496 | EXPORT_SYMBOL(i2c_smbus_write_byte_data); | 1747 | EXPORT_SYMBOL(i2c_smbus_write_byte_data); |
1497 | 1748 | ||
@@ -1503,7 +1754,7 @@ EXPORT_SYMBOL(i2c_smbus_write_byte_data); | |||
1503 | * This executes the SMBus "read word" protocol, returning negative errno | 1754 | * This executes the SMBus "read word" protocol, returning negative errno |
1504 | * else a 16-bit unsigned "word" received from the device. | 1755 | * else a 16-bit unsigned "word" received from the device. |
1505 | */ | 1756 | */ |
1506 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) | 1757 | s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command) |
1507 | { | 1758 | { |
1508 | union i2c_smbus_data data; | 1759 | union i2c_smbus_data data; |
1509 | int status; | 1760 | int status; |
@@ -1524,13 +1775,14 @@ EXPORT_SYMBOL(i2c_smbus_read_word_data); | |||
1524 | * This executes the SMBus "write word" protocol, returning negative errno | 1775 | * This executes the SMBus "write word" protocol, returning negative errno |
1525 | * else zero on success. | 1776 | * else zero on success. |
1526 | */ | 1777 | */ |
1527 | s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | 1778 | s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, |
1779 | u16 value) | ||
1528 | { | 1780 | { |
1529 | union i2c_smbus_data data; | 1781 | union i2c_smbus_data data; |
1530 | data.word = value; | 1782 | data.word = value; |
1531 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1783 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1532 | I2C_SMBUS_WRITE,command, | 1784 | I2C_SMBUS_WRITE, command, |
1533 | I2C_SMBUS_WORD_DATA,&data); | 1785 | I2C_SMBUS_WORD_DATA, &data); |
1534 | } | 1786 | } |
1535 | EXPORT_SYMBOL(i2c_smbus_write_word_data); | 1787 | EXPORT_SYMBOL(i2c_smbus_write_word_data); |
1536 | 1788 | ||
@@ -1543,7 +1795,8 @@ EXPORT_SYMBOL(i2c_smbus_write_word_data); | |||
1543 | * This executes the SMBus "process call" protocol, returning negative errno | 1795 | * This executes the SMBus "process call" protocol, returning negative errno |
1544 | * else a 16-bit unsigned "word" received from the device. | 1796 | * else a 16-bit unsigned "word" received from the device. |
1545 | */ | 1797 | */ |
1546 | s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value) | 1798 | s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command, |
1799 | u16 value) | ||
1547 | { | 1800 | { |
1548 | union i2c_smbus_data data; | 1801 | union i2c_smbus_data data; |
1549 | int status; | 1802 | int status; |
@@ -1571,7 +1824,7 @@ EXPORT_SYMBOL(i2c_smbus_process_call); | |||
1571 | * support this; its emulation through I2C messaging relies on a specific | 1824 | * support this; its emulation through I2C messaging relies on a specific |
1572 | * mechanism (I2C_M_RECV_LEN) which may not be implemented. | 1825 | * mechanism (I2C_M_RECV_LEN) which may not be implemented. |
1573 | */ | 1826 | */ |
1574 | s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, | 1827 | s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command, |
1575 | u8 *values) | 1828 | u8 *values) |
1576 | { | 1829 | { |
1577 | union i2c_smbus_data data; | 1830 | union i2c_smbus_data data; |
@@ -1598,7 +1851,7 @@ EXPORT_SYMBOL(i2c_smbus_read_block_data); | |||
1598 | * This executes the SMBus "block write" protocol, returning negative errno | 1851 | * This executes the SMBus "block write" protocol, returning negative errno |
1599 | * else zero on success. | 1852 | * else zero on success. |
1600 | */ | 1853 | */ |
1601 | s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | 1854 | s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command, |
1602 | u8 length, const u8 *values) | 1855 | u8 length, const u8 *values) |
1603 | { | 1856 | { |
1604 | union i2c_smbus_data data; | 1857 | union i2c_smbus_data data; |
@@ -1607,14 +1860,14 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, | |||
1607 | length = I2C_SMBUS_BLOCK_MAX; | 1860 | length = I2C_SMBUS_BLOCK_MAX; |
1608 | data.block[0] = length; | 1861 | data.block[0] = length; |
1609 | memcpy(&data.block[1], values, length); | 1862 | memcpy(&data.block[1], values, length); |
1610 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1863 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1611 | I2C_SMBUS_WRITE,command, | 1864 | I2C_SMBUS_WRITE, command, |
1612 | I2C_SMBUS_BLOCK_DATA,&data); | 1865 | I2C_SMBUS_BLOCK_DATA, &data); |
1613 | } | 1866 | } |
1614 | EXPORT_SYMBOL(i2c_smbus_write_block_data); | 1867 | EXPORT_SYMBOL(i2c_smbus_write_block_data); |
1615 | 1868 | ||
1616 | /* Returns the number of read bytes */ | 1869 | /* Returns the number of read bytes */ |
1617 | s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, | 1870 | s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command, |
1618 | u8 length, u8 *values) | 1871 | u8 length, u8 *values) |
1619 | { | 1872 | { |
1620 | union i2c_smbus_data data; | 1873 | union i2c_smbus_data data; |
@@ -1634,7 +1887,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, | |||
1634 | } | 1887 | } |
1635 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); | 1888 | EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); |
1636 | 1889 | ||
1637 | s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | 1890 | s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command, |
1638 | u8 length, const u8 *values) | 1891 | u8 length, const u8 *values) |
1639 | { | 1892 | { |
1640 | union i2c_smbus_data data; | 1893 | union i2c_smbus_data data; |
@@ -1651,10 +1904,10 @@ EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); | |||
1651 | 1904 | ||
1652 | /* Simulate a SMBus command using the i2c protocol | 1905 | /* Simulate a SMBus command using the i2c protocol |
1653 | No checking of parameters is done! */ | 1906 | No checking of parameters is done! */ |
1654 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | 1907 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, |
1655 | unsigned short flags, | 1908 | unsigned short flags, |
1656 | char read_write, u8 command, int size, | 1909 | char read_write, u8 command, int size, |
1657 | union i2c_smbus_data * data) | 1910 | union i2c_smbus_data *data) |
1658 | { | 1911 | { |
1659 | /* So we need to generate a series of msgs. In the case of writing, we | 1912 | /* So we need to generate a series of msgs. In the case of writing, we |
1660 | need to use only one message; when reading, we need two. We initialize | 1913 | need to use only one message; when reading, we need two. We initialize |
@@ -1662,7 +1915,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1662 | simpler. */ | 1915 | simpler. */ |
1663 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; | 1916 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; |
1664 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; | 1917 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; |
1665 | int num = read_write == I2C_SMBUS_READ?2:1; | 1918 | int num = read_write == I2C_SMBUS_READ ? 2 : 1; |
1666 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, | 1919 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, |
1667 | { addr, flags | I2C_M_RD, 0, msgbuf1 } | 1920 | { addr, flags | I2C_M_RD, 0, msgbuf1 } |
1668 | }; | 1921 | }; |
@@ -1671,7 +1924,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1671 | int status; | 1924 | int status; |
1672 | 1925 | ||
1673 | msgbuf0[0] = command; | 1926 | msgbuf0[0] = command; |
1674 | switch(size) { | 1927 | switch (size) { |
1675 | case I2C_SMBUS_QUICK: | 1928 | case I2C_SMBUS_QUICK: |
1676 | msg[0].len = 0; | 1929 | msg[0].len = 0; |
1677 | /* Special case: The read/write field is used as data */ | 1930 | /* Special case: The read/write field is used as data */ |
@@ -1698,7 +1951,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1698 | if (read_write == I2C_SMBUS_READ) | 1951 | if (read_write == I2C_SMBUS_READ) |
1699 | msg[1].len = 2; | 1952 | msg[1].len = 2; |
1700 | else { | 1953 | else { |
1701 | msg[0].len=3; | 1954 | msg[0].len = 3; |
1702 | msgbuf0[1] = data->word & 0xff; | 1955 | msgbuf0[1] = data->word & 0xff; |
1703 | msgbuf0[2] = data->word >> 8; | 1956 | msgbuf0[2] = data->word >> 8; |
1704 | } | 1957 | } |
@@ -1791,26 +2044,26 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1791 | } | 2044 | } |
1792 | 2045 | ||
1793 | if (read_write == I2C_SMBUS_READ) | 2046 | if (read_write == I2C_SMBUS_READ) |
1794 | switch(size) { | 2047 | switch (size) { |
1795 | case I2C_SMBUS_BYTE: | 2048 | case I2C_SMBUS_BYTE: |
1796 | data->byte = msgbuf0[0]; | 2049 | data->byte = msgbuf0[0]; |
1797 | break; | 2050 | break; |
1798 | case I2C_SMBUS_BYTE_DATA: | 2051 | case I2C_SMBUS_BYTE_DATA: |
1799 | data->byte = msgbuf1[0]; | 2052 | data->byte = msgbuf1[0]; |
1800 | break; | 2053 | break; |
1801 | case I2C_SMBUS_WORD_DATA: | 2054 | case I2C_SMBUS_WORD_DATA: |
1802 | case I2C_SMBUS_PROC_CALL: | 2055 | case I2C_SMBUS_PROC_CALL: |
1803 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); | 2056 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); |
1804 | break; | 2057 | break; |
1805 | case I2C_SMBUS_I2C_BLOCK_DATA: | 2058 | case I2C_SMBUS_I2C_BLOCK_DATA: |
1806 | for (i = 0; i < data->block[0]; i++) | 2059 | for (i = 0; i < data->block[0]; i++) |
1807 | data->block[i+1] = msgbuf1[i]; | 2060 | data->block[i+1] = msgbuf1[i]; |
1808 | break; | 2061 | break; |
1809 | case I2C_SMBUS_BLOCK_DATA: | 2062 | case I2C_SMBUS_BLOCK_DATA: |
1810 | case I2C_SMBUS_BLOCK_PROC_CALL: | 2063 | case I2C_SMBUS_BLOCK_PROC_CALL: |
1811 | for (i = 0; i < msgbuf1[0] + 1; i++) | 2064 | for (i = 0; i < msgbuf1[0] + 1; i++) |
1812 | data->block[i] = msgbuf1[i]; | 2065 | data->block[i] = msgbuf1[i]; |
1813 | break; | 2066 | break; |
1814 | } | 2067 | } |
1815 | return 0; | 2068 | return 0; |
1816 | } | 2069 | } |
@@ -1839,7 +2092,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
1839 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; | 2092 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; |
1840 | 2093 | ||
1841 | if (adapter->algo->smbus_xfer) { | 2094 | if (adapter->algo->smbus_xfer) { |
1842 | mutex_lock(&adapter->bus_lock); | 2095 | i2c_lock_adapter(adapter); |
1843 | 2096 | ||
1844 | /* Retry automatically on arbitration loss */ | 2097 | /* Retry automatically on arbitration loss */ |
1845 | orig_jiffies = jiffies; | 2098 | orig_jiffies = jiffies; |
@@ -1853,9 +2106,9 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
1853 | orig_jiffies + adapter->timeout)) | 2106 | orig_jiffies + adapter->timeout)) |
1854 | break; | 2107 | break; |
1855 | } | 2108 | } |
1856 | mutex_unlock(&adapter->bus_lock); | 2109 | i2c_unlock_adapter(adapter); |
1857 | } else | 2110 | } else |
1858 | res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, | 2111 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, |
1859 | command, protocol, data); | 2112 | command, protocol, data); |
1860 | 2113 | ||
1861 | return res; | 2114 | return res; |
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 7e13d2df9af3..cec0f3ba97f8 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
@@ -34,9 +34,8 @@ | |||
34 | #include <linux/list.h> | 34 | #include <linux/list.h> |
35 | #include <linux/i2c.h> | 35 | #include <linux/i2c.h> |
36 | #include <linux/i2c-dev.h> | 36 | #include <linux/i2c-dev.h> |
37 | #include <linux/smp_lock.h> | ||
38 | #include <linux/jiffies.h> | 37 | #include <linux/jiffies.h> |
39 | #include <asm/uaccess.h> | 38 | #include <linux/uaccess.h> |
40 | 39 | ||
41 | static struct i2c_driver i2cdev_driver; | 40 | static struct i2c_driver i2cdev_driver; |
42 | 41 | ||
@@ -133,53 +132,49 @@ static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); | |||
133 | * needed by those system calls and by this SMBus interface. | 132 | * needed by those system calls and by this SMBus interface. |
134 | */ | 133 | */ |
135 | 134 | ||
136 | static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count, | 135 | static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count, |
137 | loff_t *offset) | 136 | loff_t *offset) |
138 | { | 137 | { |
139 | char *tmp; | 138 | char *tmp; |
140 | int ret; | 139 | int ret; |
141 | 140 | ||
142 | struct i2c_client *client = (struct i2c_client *)file->private_data; | 141 | struct i2c_client *client = file->private_data; |
143 | 142 | ||
144 | if (count > 8192) | 143 | if (count > 8192) |
145 | count = 8192; | 144 | count = 8192; |
146 | 145 | ||
147 | tmp = kmalloc(count,GFP_KERNEL); | 146 | tmp = kmalloc(count, GFP_KERNEL); |
148 | if (tmp==NULL) | 147 | if (tmp == NULL) |
149 | return -ENOMEM; | 148 | return -ENOMEM; |
150 | 149 | ||
151 | pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n", | 150 | pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n", |
152 | iminor(file->f_path.dentry->d_inode), count); | 151 | iminor(file->f_path.dentry->d_inode), count); |
153 | 152 | ||
154 | ret = i2c_master_recv(client,tmp,count); | 153 | ret = i2c_master_recv(client, tmp, count); |
155 | if (ret >= 0) | 154 | if (ret >= 0) |
156 | ret = copy_to_user(buf,tmp,count)?-EFAULT:ret; | 155 | ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret; |
157 | kfree(tmp); | 156 | kfree(tmp); |
158 | return ret; | 157 | return ret; |
159 | } | 158 | } |
160 | 159 | ||
161 | static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t count, | 160 | static ssize_t i2cdev_write(struct file *file, const char __user *buf, |
162 | loff_t *offset) | 161 | size_t count, loff_t *offset) |
163 | { | 162 | { |
164 | int ret; | 163 | int ret; |
165 | char *tmp; | 164 | char *tmp; |
166 | struct i2c_client *client = (struct i2c_client *)file->private_data; | 165 | struct i2c_client *client = file->private_data; |
167 | 166 | ||
168 | if (count > 8192) | 167 | if (count > 8192) |
169 | count = 8192; | 168 | count = 8192; |
170 | 169 | ||
171 | tmp = kmalloc(count,GFP_KERNEL); | 170 | tmp = memdup_user(buf, count); |
172 | if (tmp==NULL) | 171 | if (IS_ERR(tmp)) |
173 | return -ENOMEM; | 172 | return PTR_ERR(tmp); |
174 | if (copy_from_user(tmp,buf,count)) { | ||
175 | kfree(tmp); | ||
176 | return -EFAULT; | ||
177 | } | ||
178 | 173 | ||
179 | pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", | 174 | pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", |
180 | iminor(file->f_path.dentry->d_inode), count); | 175 | iminor(file->f_path.dentry->d_inode), count); |
181 | 176 | ||
182 | ret = i2c_master_send(client,tmp,count); | 177 | ret = i2c_master_send(client, tmp, count); |
183 | kfree(tmp); | 178 | kfree(tmp); |
184 | return ret; | 179 | return ret; |
185 | } | 180 | } |
@@ -194,12 +189,49 @@ static int i2cdev_check(struct device *dev, void *addrp) | |||
194 | return dev->driver ? -EBUSY : 0; | 189 | return dev->driver ? -EBUSY : 0; |
195 | } | 190 | } |
196 | 191 | ||
192 | /* walk up mux tree */ | ||
193 | static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr) | ||
194 | { | ||
195 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
196 | int result; | ||
197 | |||
198 | result = device_for_each_child(&adapter->dev, &addr, i2cdev_check); | ||
199 | if (!result && parent) | ||
200 | result = i2cdev_check_mux_parents(parent, addr); | ||
201 | |||
202 | return result; | ||
203 | } | ||
204 | |||
205 | /* recurse down mux tree */ | ||
206 | static int i2cdev_check_mux_children(struct device *dev, void *addrp) | ||
207 | { | ||
208 | int result; | ||
209 | |||
210 | if (dev->type == &i2c_adapter_type) | ||
211 | result = device_for_each_child(dev, addrp, | ||
212 | i2cdev_check_mux_children); | ||
213 | else | ||
214 | result = i2cdev_check(dev, addrp); | ||
215 | |||
216 | return result; | ||
217 | } | ||
218 | |||
197 | /* This address checking function differs from the one in i2c-core | 219 | /* This address checking function differs from the one in i2c-core |
198 | in that it considers an address with a registered device, but no | 220 | in that it considers an address with a registered device, but no |
199 | driver bound to it, as NOT busy. */ | 221 | driver bound to it, as NOT busy. */ |
200 | static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) | 222 | static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) |
201 | { | 223 | { |
202 | return device_for_each_child(&adapter->dev, &addr, i2cdev_check); | 224 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
225 | int result = 0; | ||
226 | |||
227 | if (parent) | ||
228 | result = i2cdev_check_mux_parents(parent, addr); | ||
229 | |||
230 | if (!result) | ||
231 | result = device_for_each_child(&adapter->dev, &addr, | ||
232 | i2cdev_check_mux_children); | ||
233 | |||
234 | return result; | ||
203 | } | 235 | } |
204 | 236 | ||
205 | static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, | 237 | static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, |
@@ -220,9 +252,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, | |||
220 | if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) | 252 | if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) |
221 | return -EINVAL; | 253 | return -EINVAL; |
222 | 254 | ||
223 | rdwr_pa = (struct i2c_msg *) | 255 | rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL); |
224 | kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), | ||
225 | GFP_KERNEL); | ||
226 | if (!rdwr_pa) | 256 | if (!rdwr_pa) |
227 | return -ENOMEM; | 257 | return -ENOMEM; |
228 | 258 | ||
@@ -248,15 +278,9 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, | |||
248 | break; | 278 | break; |
249 | } | 279 | } |
250 | data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; | 280 | data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; |
251 | rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL); | 281 | rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len); |
252 | if (rdwr_pa[i].buf == NULL) { | 282 | if (IS_ERR(rdwr_pa[i].buf)) { |
253 | res = -ENOMEM; | 283 | res = PTR_ERR(rdwr_pa[i].buf); |
254 | break; | ||
255 | } | ||
256 | if (copy_from_user(rdwr_pa[i].buf, data_ptrs[i], | ||
257 | rdwr_pa[i].len)) { | ||
258 | ++i; /* Needs to be kfreed too */ | ||
259 | res = -EFAULT; | ||
260 | break; | 284 | break; |
261 | } | 285 | } |
262 | } | 286 | } |
@@ -370,13 +394,13 @@ static noinline int i2cdev_ioctl_smbus(struct i2c_client *client, | |||
370 | 394 | ||
371 | static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 395 | static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
372 | { | 396 | { |
373 | struct i2c_client *client = (struct i2c_client *)file->private_data; | 397 | struct i2c_client *client = file->private_data; |
374 | unsigned long funcs; | 398 | unsigned long funcs; |
375 | 399 | ||
376 | dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", | 400 | dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", |
377 | cmd, arg); | 401 | cmd, arg); |
378 | 402 | ||
379 | switch ( cmd ) { | 403 | switch (cmd) { |
380 | case I2C_SLAVE: | 404 | case I2C_SLAVE: |
381 | case I2C_SLAVE_FORCE: | 405 | case I2C_SLAVE_FORCE: |
382 | /* NOTE: devices set up to work with "new style" drivers | 406 | /* NOTE: devices set up to work with "new style" drivers |
@@ -445,20 +469,14 @@ static int i2cdev_open(struct inode *inode, struct file *file) | |||
445 | struct i2c_client *client; | 469 | struct i2c_client *client; |
446 | struct i2c_adapter *adap; | 470 | struct i2c_adapter *adap; |
447 | struct i2c_dev *i2c_dev; | 471 | struct i2c_dev *i2c_dev; |
448 | int ret = 0; | ||
449 | 472 | ||
450 | lock_kernel(); | ||
451 | i2c_dev = i2c_dev_get_by_minor(minor); | 473 | i2c_dev = i2c_dev_get_by_minor(minor); |
452 | if (!i2c_dev) { | 474 | if (!i2c_dev) |
453 | ret = -ENODEV; | 475 | return -ENODEV; |
454 | goto out; | ||
455 | } | ||
456 | 476 | ||
457 | adap = i2c_get_adapter(i2c_dev->adap->nr); | 477 | adap = i2c_get_adapter(i2c_dev->adap->nr); |
458 | if (!adap) { | 478 | if (!adap) |
459 | ret = -ENODEV; | 479 | return -ENODEV; |
460 | goto out; | ||
461 | } | ||
462 | 480 | ||
463 | /* This creates an anonymous i2c_client, which may later be | 481 | /* This creates an anonymous i2c_client, which may later be |
464 | * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. | 482 | * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. |
@@ -470,8 +488,7 @@ static int i2cdev_open(struct inode *inode, struct file *file) | |||
470 | client = kzalloc(sizeof(*client), GFP_KERNEL); | 488 | client = kzalloc(sizeof(*client), GFP_KERNEL); |
471 | if (!client) { | 489 | if (!client) { |
472 | i2c_put_adapter(adap); | 490 | i2c_put_adapter(adap); |
473 | ret = -ENOMEM; | 491 | return -ENOMEM; |
474 | goto out; | ||
475 | } | 492 | } |
476 | snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); | 493 | snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); |
477 | client->driver = &i2cdev_driver; | 494 | client->driver = &i2cdev_driver; |
@@ -479,9 +496,7 @@ static int i2cdev_open(struct inode *inode, struct file *file) | |||
479 | client->adapter = adap; | 496 | client->adapter = adap; |
480 | file->private_data = client; | 497 | file->private_data = client; |
481 | 498 | ||
482 | out: | 499 | return 0; |
483 | unlock_kernel(); | ||
484 | return ret; | ||
485 | } | 500 | } |
486 | 501 | ||
487 | static int i2cdev_release(struct inode *inode, struct file *file) | 502 | static int i2cdev_release(struct inode *inode, struct file *file) |
@@ -611,7 +626,7 @@ static void __exit i2c_dev_exit(void) | |||
611 | { | 626 | { |
612 | i2c_del_driver(&i2cdev_driver); | 627 | i2c_del_driver(&i2cdev_driver); |
613 | class_destroy(i2c_dev_class); | 628 | class_destroy(i2c_dev_class); |
614 | unregister_chrdev(I2C_MAJOR,"i2c"); | 629 | unregister_chrdev(I2C_MAJOR, "i2c"); |
615 | } | 630 | } |
616 | 631 | ||
617 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " | 632 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " |
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c new file mode 100644 index 000000000000..d7a4833be416 --- /dev/null +++ b/drivers/i2c/i2c-mux.c | |||
@@ -0,0 +1,164 @@ | |||
1 | /* | ||
2 | * Multiplexed I2C bus driver. | ||
3 | * | ||
4 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
5 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
6 | * Copyright (c) 2009-2010 NSN GmbH & Co KG <michael.lawnick.ext@nsn.com> | ||
7 | * | ||
8 | * Simplifies access to complex multiplexed I2C bus topologies, by presenting | ||
9 | * each multiplexed bus segment as an additional I2C adapter. | ||
10 | * Supports multi-level mux'ing (mux behind a mux). | ||
11 | * | ||
12 | * Based on: | ||
13 | * i2c-virt.c from Kumar Gala <galak@kernel.crashing.org> | ||
14 | * i2c-virtual.c from Ken Harrenstien, Copyright (c) 2004 Google, Inc. | ||
15 | * i2c-virtual.c from Brian Kuschak <bkuschak@yahoo.com> | ||
16 | * | ||
17 | * This file is licensed under the terms of the GNU General Public | ||
18 | * License version 2. This program is licensed "as is" without any | ||
19 | * warranty of any kind, whether express or implied. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <linux/i2c-mux.h> | ||
27 | |||
28 | /* multiplexer per channel data */ | ||
29 | struct i2c_mux_priv { | ||
30 | struct i2c_adapter adap; | ||
31 | struct i2c_algorithm algo; | ||
32 | |||
33 | struct i2c_adapter *parent; | ||
34 | void *mux_dev; /* the mux chip/device */ | ||
35 | u32 chan_id; /* the channel id */ | ||
36 | |||
37 | int (*select)(struct i2c_adapter *, void *mux_dev, u32 chan_id); | ||
38 | int (*deselect)(struct i2c_adapter *, void *mux_dev, u32 chan_id); | ||
39 | }; | ||
40 | |||
41 | static int i2c_mux_master_xfer(struct i2c_adapter *adap, | ||
42 | struct i2c_msg msgs[], int num) | ||
43 | { | ||
44 | struct i2c_mux_priv *priv = adap->algo_data; | ||
45 | struct i2c_adapter *parent = priv->parent; | ||
46 | int ret; | ||
47 | |||
48 | /* Switch to the right mux port and perform the transfer. */ | ||
49 | |||
50 | ret = priv->select(parent, priv->mux_dev, priv->chan_id); | ||
51 | if (ret >= 0) | ||
52 | ret = parent->algo->master_xfer(parent, msgs, num); | ||
53 | if (priv->deselect) | ||
54 | priv->deselect(parent, priv->mux_dev, priv->chan_id); | ||
55 | |||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | static int i2c_mux_smbus_xfer(struct i2c_adapter *adap, | ||
60 | u16 addr, unsigned short flags, | ||
61 | char read_write, u8 command, | ||
62 | int size, union i2c_smbus_data *data) | ||
63 | { | ||
64 | struct i2c_mux_priv *priv = adap->algo_data; | ||
65 | struct i2c_adapter *parent = priv->parent; | ||
66 | int ret; | ||
67 | |||
68 | /* Select the right mux port and perform the transfer. */ | ||
69 | |||
70 | ret = priv->select(parent, priv->mux_dev, priv->chan_id); | ||
71 | if (ret >= 0) | ||
72 | ret = parent->algo->smbus_xfer(parent, addr, flags, | ||
73 | read_write, command, size, data); | ||
74 | if (priv->deselect) | ||
75 | priv->deselect(parent, priv->mux_dev, priv->chan_id); | ||
76 | |||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | /* Return the parent's functionality */ | ||
81 | static u32 i2c_mux_functionality(struct i2c_adapter *adap) | ||
82 | { | ||
83 | struct i2c_mux_priv *priv = adap->algo_data; | ||
84 | struct i2c_adapter *parent = priv->parent; | ||
85 | |||
86 | return parent->algo->functionality(parent); | ||
87 | } | ||
88 | |||
89 | struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, | ||
90 | void *mux_dev, u32 force_nr, u32 chan_id, | ||
91 | int (*select) (struct i2c_adapter *, | ||
92 | void *, u32), | ||
93 | int (*deselect) (struct i2c_adapter *, | ||
94 | void *, u32)) | ||
95 | { | ||
96 | struct i2c_mux_priv *priv; | ||
97 | int ret; | ||
98 | |||
99 | priv = kzalloc(sizeof(struct i2c_mux_priv), GFP_KERNEL); | ||
100 | if (!priv) | ||
101 | return NULL; | ||
102 | |||
103 | /* Set up private adapter data */ | ||
104 | priv->parent = parent; | ||
105 | priv->mux_dev = mux_dev; | ||
106 | priv->chan_id = chan_id; | ||
107 | priv->select = select; | ||
108 | priv->deselect = deselect; | ||
109 | |||
110 | /* Need to do algo dynamically because we don't know ahead | ||
111 | * of time what sort of physical adapter we'll be dealing with. | ||
112 | */ | ||
113 | if (parent->algo->master_xfer) | ||
114 | priv->algo.master_xfer = i2c_mux_master_xfer; | ||
115 | if (parent->algo->smbus_xfer) | ||
116 | priv->algo.smbus_xfer = i2c_mux_smbus_xfer; | ||
117 | priv->algo.functionality = i2c_mux_functionality; | ||
118 | |||
119 | /* Now fill out new adapter structure */ | ||
120 | snprintf(priv->adap.name, sizeof(priv->adap.name), | ||
121 | "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id); | ||
122 | priv->adap.owner = THIS_MODULE; | ||
123 | priv->adap.algo = &priv->algo; | ||
124 | priv->adap.algo_data = priv; | ||
125 | priv->adap.dev.parent = &parent->dev; | ||
126 | |||
127 | if (force_nr) { | ||
128 | priv->adap.nr = force_nr; | ||
129 | ret = i2c_add_numbered_adapter(&priv->adap); | ||
130 | } else { | ||
131 | ret = i2c_add_adapter(&priv->adap); | ||
132 | } | ||
133 | if (ret < 0) { | ||
134 | dev_err(&parent->dev, | ||
135 | "failed to add mux-adapter (error=%d)\n", | ||
136 | ret); | ||
137 | kfree(priv); | ||
138 | return NULL; | ||
139 | } | ||
140 | |||
141 | dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", | ||
142 | i2c_adapter_id(&priv->adap)); | ||
143 | |||
144 | return &priv->adap; | ||
145 | } | ||
146 | EXPORT_SYMBOL_GPL(i2c_add_mux_adapter); | ||
147 | |||
148 | int i2c_del_mux_adapter(struct i2c_adapter *adap) | ||
149 | { | ||
150 | struct i2c_mux_priv *priv = adap->algo_data; | ||
151 | int ret; | ||
152 | |||
153 | ret = i2c_del_adapter(adap); | ||
154 | if (ret < 0) | ||
155 | return ret; | ||
156 | kfree(priv); | ||
157 | |||
158 | return 0; | ||
159 | } | ||
160 | EXPORT_SYMBOL_GPL(i2c_del_mux_adapter); | ||
161 | |||
162 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
163 | MODULE_DESCRIPTION("I2C driver for multiplexed I2C busses"); | ||
164 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c new file mode 100644 index 000000000000..f61ccc1e5ea3 --- /dev/null +++ b/drivers/i2c/i2c-smbus.c | |||
@@ -0,0 +1,262 @@ | |||
1 | /* | ||
2 | * i2c-smbus.c - SMBus extensions to the I2C protocol | ||
3 | * | ||
4 | * Copyright (C) 2008 David Brownell | ||
5 | * Copyright (C) 2010 Jean Delvare <khali@linux-fr.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/workqueue.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include <linux/i2c-smbus.h> | ||
29 | #include <linux/slab.h> | ||
30 | |||
31 | struct i2c_smbus_alert { | ||
32 | unsigned int alert_edge_triggered:1; | ||
33 | int irq; | ||
34 | struct work_struct alert; | ||
35 | struct i2c_client *ara; /* Alert response address */ | ||
36 | }; | ||
37 | |||
38 | struct alert_data { | ||
39 | unsigned short addr; | ||
40 | u8 flag:1; | ||
41 | }; | ||
42 | |||
43 | /* If this is the alerting device, notify its driver */ | ||
44 | static int smbus_do_alert(struct device *dev, void *addrp) | ||
45 | { | ||
46 | struct i2c_client *client = i2c_verify_client(dev); | ||
47 | struct alert_data *data = addrp; | ||
48 | |||
49 | if (!client || client->addr != data->addr) | ||
50 | return 0; | ||
51 | if (client->flags & I2C_CLIENT_TEN) | ||
52 | return 0; | ||
53 | |||
54 | /* | ||
55 | * Drivers should either disable alerts, or provide at least | ||
56 | * a minimal handler. Lock so client->driver won't change. | ||
57 | */ | ||
58 | device_lock(dev); | ||
59 | if (client->driver) { | ||
60 | if (client->driver->alert) | ||
61 | client->driver->alert(client, data->flag); | ||
62 | else | ||
63 | dev_warn(&client->dev, "no driver alert()!\n"); | ||
64 | } else | ||
65 | dev_dbg(&client->dev, "alert with no driver\n"); | ||
66 | device_unlock(dev); | ||
67 | |||
68 | /* Stop iterating after we find the device */ | ||
69 | return -EBUSY; | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * The alert IRQ handler needs to hand work off to a task which can issue | ||
74 | * SMBus calls, because those sleeping calls can't be made in IRQ context. | ||
75 | */ | ||
76 | static void smbus_alert(struct work_struct *work) | ||
77 | { | ||
78 | struct i2c_smbus_alert *alert; | ||
79 | struct i2c_client *ara; | ||
80 | unsigned short prev_addr = 0; /* Not a valid address */ | ||
81 | |||
82 | alert = container_of(work, struct i2c_smbus_alert, alert); | ||
83 | ara = alert->ara; | ||
84 | |||
85 | for (;;) { | ||
86 | s32 status; | ||
87 | struct alert_data data; | ||
88 | |||
89 | /* | ||
90 | * Devices with pending alerts reply in address order, low | ||
91 | * to high, because of slave transmit arbitration. After | ||
92 | * responding, an SMBus device stops asserting SMBALERT#. | ||
93 | * | ||
94 | * Note that SMBus 2.0 reserves 10-bit addresess for future | ||
95 | * use. We neither handle them, nor try to use PEC here. | ||
96 | */ | ||
97 | status = i2c_smbus_read_byte(ara); | ||
98 | if (status < 0) | ||
99 | break; | ||
100 | |||
101 | data.flag = status & 1; | ||
102 | data.addr = status >> 1; | ||
103 | |||
104 | if (data.addr == prev_addr) { | ||
105 | dev_warn(&ara->dev, "Duplicate SMBALERT# from dev " | ||
106 | "0x%02x, skipping\n", data.addr); | ||
107 | break; | ||
108 | } | ||
109 | dev_dbg(&ara->dev, "SMBALERT# from dev 0x%02x, flag %d\n", | ||
110 | data.addr, data.flag); | ||
111 | |||
112 | /* Notify driver for the device which issued the alert */ | ||
113 | device_for_each_child(&ara->adapter->dev, &data, | ||
114 | smbus_do_alert); | ||
115 | prev_addr = data.addr; | ||
116 | } | ||
117 | |||
118 | /* We handled all alerts; re-enable level-triggered IRQs */ | ||
119 | if (!alert->alert_edge_triggered) | ||
120 | enable_irq(alert->irq); | ||
121 | } | ||
122 | |||
123 | static irqreturn_t smbalert_irq(int irq, void *d) | ||
124 | { | ||
125 | struct i2c_smbus_alert *alert = d; | ||
126 | |||
127 | /* Disable level-triggered IRQs until we handle them */ | ||
128 | if (!alert->alert_edge_triggered) | ||
129 | disable_irq_nosync(irq); | ||
130 | |||
131 | schedule_work(&alert->alert); | ||
132 | return IRQ_HANDLED; | ||
133 | } | ||
134 | |||
135 | /* Setup SMBALERT# infrastructure */ | ||
136 | static int smbalert_probe(struct i2c_client *ara, | ||
137 | const struct i2c_device_id *id) | ||
138 | { | ||
139 | struct i2c_smbus_alert_setup *setup = ara->dev.platform_data; | ||
140 | struct i2c_smbus_alert *alert; | ||
141 | struct i2c_adapter *adapter = ara->adapter; | ||
142 | int res; | ||
143 | |||
144 | alert = kzalloc(sizeof(struct i2c_smbus_alert), GFP_KERNEL); | ||
145 | if (!alert) | ||
146 | return -ENOMEM; | ||
147 | |||
148 | alert->alert_edge_triggered = setup->alert_edge_triggered; | ||
149 | alert->irq = setup->irq; | ||
150 | INIT_WORK(&alert->alert, smbus_alert); | ||
151 | alert->ara = ara; | ||
152 | |||
153 | if (setup->irq > 0) { | ||
154 | res = devm_request_irq(&ara->dev, setup->irq, smbalert_irq, | ||
155 | 0, "smbus_alert", alert); | ||
156 | if (res) { | ||
157 | kfree(alert); | ||
158 | return res; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | i2c_set_clientdata(ara, alert); | ||
163 | dev_info(&adapter->dev, "supports SMBALERT#, %s trigger\n", | ||
164 | setup->alert_edge_triggered ? "edge" : "level"); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | /* IRQ resource is managed so it is freed automatically */ | ||
170 | static int smbalert_remove(struct i2c_client *ara) | ||
171 | { | ||
172 | struct i2c_smbus_alert *alert = i2c_get_clientdata(ara); | ||
173 | |||
174 | cancel_work_sync(&alert->alert); | ||
175 | |||
176 | kfree(alert); | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static const struct i2c_device_id smbalert_ids[] = { | ||
181 | { "smbus_alert", 0 }, | ||
182 | { /* LIST END */ } | ||
183 | }; | ||
184 | MODULE_DEVICE_TABLE(i2c, smbalert_ids); | ||
185 | |||
186 | static struct i2c_driver smbalert_driver = { | ||
187 | .driver = { | ||
188 | .name = "smbus_alert", | ||
189 | }, | ||
190 | .probe = smbalert_probe, | ||
191 | .remove = smbalert_remove, | ||
192 | .id_table = smbalert_ids, | ||
193 | }; | ||
194 | |||
195 | /** | ||
196 | * i2c_setup_smbus_alert - Setup SMBus alert support | ||
197 | * @adapter: the target adapter | ||
198 | * @setup: setup data for the SMBus alert handler | ||
199 | * Context: can sleep | ||
200 | * | ||
201 | * Setup handling of the SMBus alert protocol on a given I2C bus segment. | ||
202 | * | ||
203 | * Handling can be done either through our IRQ handler, or by the | ||
204 | * adapter (from its handler, periodic polling, or whatever). | ||
205 | * | ||
206 | * NOTE that if we manage the IRQ, we *MUST* know if it's level or | ||
207 | * edge triggered in order to hand it to the workqueue correctly. | ||
208 | * If triggering the alert seems to wedge the system, you probably | ||
209 | * should have said it's level triggered. | ||
210 | * | ||
211 | * This returns the ara client, which should be saved for later use with | ||
212 | * i2c_handle_smbus_alert() and ultimately i2c_unregister_device(); or NULL | ||
213 | * to indicate an error. | ||
214 | */ | ||
215 | struct i2c_client *i2c_setup_smbus_alert(struct i2c_adapter *adapter, | ||
216 | struct i2c_smbus_alert_setup *setup) | ||
217 | { | ||
218 | struct i2c_board_info ara_board_info = { | ||
219 | I2C_BOARD_INFO("smbus_alert", 0x0c), | ||
220 | .platform_data = setup, | ||
221 | }; | ||
222 | |||
223 | return i2c_new_device(adapter, &ara_board_info); | ||
224 | } | ||
225 | EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert); | ||
226 | |||
227 | /** | ||
228 | * i2c_handle_smbus_alert - Handle an SMBus alert | ||
229 | * @ara: the ARA client on the relevant adapter | ||
230 | * Context: can't sleep | ||
231 | * | ||
232 | * Helper function to be called from an I2C bus driver's interrupt | ||
233 | * handler. It will schedule the alert work, in turn calling the | ||
234 | * corresponding I2C device driver's alert function. | ||
235 | * | ||
236 | * It is assumed that ara is a valid i2c client previously returned by | ||
237 | * i2c_setup_smbus_alert(). | ||
238 | */ | ||
239 | int i2c_handle_smbus_alert(struct i2c_client *ara) | ||
240 | { | ||
241 | struct i2c_smbus_alert *alert = i2c_get_clientdata(ara); | ||
242 | |||
243 | return schedule_work(&alert->alert); | ||
244 | } | ||
245 | EXPORT_SYMBOL_GPL(i2c_handle_smbus_alert); | ||
246 | |||
247 | static int __init i2c_smbus_init(void) | ||
248 | { | ||
249 | return i2c_add_driver(&smbalert_driver); | ||
250 | } | ||
251 | |||
252 | static void __exit i2c_smbus_exit(void) | ||
253 | { | ||
254 | i2c_del_driver(&smbalert_driver); | ||
255 | } | ||
256 | |||
257 | module_init(i2c_smbus_init); | ||
258 | module_exit(i2c_smbus_exit); | ||
259 | |||
260 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | ||
261 | MODULE_DESCRIPTION("SMBus protocol extensions support"); | ||
262 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig new file mode 100644 index 000000000000..90b7a0163899 --- /dev/null +++ b/drivers/i2c/muxes/Kconfig | |||
@@ -0,0 +1,40 @@ | |||
1 | # | ||
2 | # Multiplexer I2C chip drivers configuration | ||
3 | # | ||
4 | |||
5 | menu "Multiplexer I2C Chip support" | ||
6 | depends on I2C_MUX | ||
7 | |||
8 | config I2C_MUX_GPIO | ||
9 | tristate "GPIO-based I2C multiplexer" | ||
10 | depends on GENERIC_GPIO | ||
11 | help | ||
12 | If you say yes to this option, support will be included for a | ||
13 | GPIO based I2C multiplexer. This driver provides access to | ||
14 | I2C busses connected through a MUX, which is controlled | ||
15 | through GPIO pins. | ||
16 | |||
17 | This driver can also be built as a module. If so, the module | ||
18 | will be called gpio-i2cmux. | ||
19 | |||
20 | config I2C_MUX_PCA9541 | ||
21 | tristate "NXP PCA9541 I2C Master Selector" | ||
22 | depends on EXPERIMENTAL | ||
23 | help | ||
24 | If you say yes here you get support for the NXP PCA9541 | ||
25 | I2C Master Selector. | ||
26 | |||
27 | This driver can also be built as a module. If so, the module | ||
28 | will be called pca9541. | ||
29 | |||
30 | config I2C_MUX_PCA954x | ||
31 | tristate "Philips PCA954x I2C Mux/switches" | ||
32 | depends on EXPERIMENTAL | ||
33 | help | ||
34 | If you say yes here you get support for the Philips PCA954x | ||
35 | I2C mux/switch devices. | ||
36 | |||
37 | This driver can also be built as a module. If so, the module | ||
38 | will be called pca954x. | ||
39 | |||
40 | endmenu | ||
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile new file mode 100644 index 000000000000..4640436ea61f --- /dev/null +++ b/drivers/i2c/muxes/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # | ||
2 | # Makefile for multiplexer I2C chip drivers. | ||
3 | |||
4 | obj-$(CONFIG_I2C_MUX_GPIO) += gpio-i2cmux.o | ||
5 | obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o | ||
6 | obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o | ||
7 | |||
8 | ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG | ||
diff --git a/drivers/i2c/muxes/gpio-i2cmux.c b/drivers/i2c/muxes/gpio-i2cmux.c new file mode 100644 index 000000000000..7b6ce624cd6e --- /dev/null +++ b/drivers/i2c/muxes/gpio-i2cmux.c | |||
@@ -0,0 +1,184 @@ | |||
1 | /* | ||
2 | * I2C multiplexer using GPIO API | ||
3 | * | ||
4 | * Peter Korsgaard <peter.korsgaard@barco.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <linux/i2c.h> | ||
12 | #include <linux/i2c-mux.h> | ||
13 | #include <linux/gpio-i2cmux.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/gpio.h> | ||
19 | |||
20 | struct gpiomux { | ||
21 | struct i2c_adapter *parent; | ||
22 | struct i2c_adapter **adap; /* child busses */ | ||
23 | struct gpio_i2cmux_platform_data data; | ||
24 | }; | ||
25 | |||
26 | static void gpiomux_set(const struct gpiomux *mux, unsigned val) | ||
27 | { | ||
28 | int i; | ||
29 | |||
30 | for (i = 0; i < mux->data.n_gpios; i++) | ||
31 | gpio_set_value(mux->data.gpios[i], val & (1 << i)); | ||
32 | } | ||
33 | |||
34 | static int gpiomux_select(struct i2c_adapter *adap, void *data, u32 chan) | ||
35 | { | ||
36 | struct gpiomux *mux = data; | ||
37 | |||
38 | gpiomux_set(mux, mux->data.values[chan]); | ||
39 | |||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | static int gpiomux_deselect(struct i2c_adapter *adap, void *data, u32 chan) | ||
44 | { | ||
45 | struct gpiomux *mux = data; | ||
46 | |||
47 | gpiomux_set(mux, mux->data.idle); | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static int __devinit gpiomux_probe(struct platform_device *pdev) | ||
53 | { | ||
54 | struct gpiomux *mux; | ||
55 | struct gpio_i2cmux_platform_data *pdata; | ||
56 | struct i2c_adapter *parent; | ||
57 | int (*deselect) (struct i2c_adapter *, void *, u32); | ||
58 | unsigned initial_state; | ||
59 | int i, ret; | ||
60 | |||
61 | pdata = pdev->dev.platform_data; | ||
62 | if (!pdata) { | ||
63 | dev_err(&pdev->dev, "Missing platform data\n"); | ||
64 | return -ENODEV; | ||
65 | } | ||
66 | |||
67 | parent = i2c_get_adapter(pdata->parent); | ||
68 | if (!parent) { | ||
69 | dev_err(&pdev->dev, "Parent adapter (%d) not found\n", | ||
70 | pdata->parent); | ||
71 | return -ENODEV; | ||
72 | } | ||
73 | |||
74 | mux = kzalloc(sizeof(*mux), GFP_KERNEL); | ||
75 | if (!mux) { | ||
76 | ret = -ENOMEM; | ||
77 | goto alloc_failed; | ||
78 | } | ||
79 | |||
80 | mux->parent = parent; | ||
81 | mux->data = *pdata; | ||
82 | mux->adap = kzalloc(sizeof(struct i2c_adapter *) * pdata->n_values, | ||
83 | GFP_KERNEL); | ||
84 | if (!mux->adap) { | ||
85 | ret = -ENOMEM; | ||
86 | goto alloc_failed2; | ||
87 | } | ||
88 | |||
89 | if (pdata->idle != GPIO_I2CMUX_NO_IDLE) { | ||
90 | initial_state = pdata->idle; | ||
91 | deselect = gpiomux_deselect; | ||
92 | } else { | ||
93 | initial_state = pdata->values[0]; | ||
94 | deselect = NULL; | ||
95 | } | ||
96 | |||
97 | for (i = 0; i < pdata->n_gpios; i++) { | ||
98 | ret = gpio_request(pdata->gpios[i], "gpio-i2cmux"); | ||
99 | if (ret) | ||
100 | goto err_request_gpio; | ||
101 | gpio_direction_output(pdata->gpios[i], | ||
102 | initial_state & (1 << i)); | ||
103 | } | ||
104 | |||
105 | for (i = 0; i < pdata->n_values; i++) { | ||
106 | u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0; | ||
107 | |||
108 | mux->adap[i] = i2c_add_mux_adapter(parent, mux, nr, i, | ||
109 | gpiomux_select, deselect); | ||
110 | if (!mux->adap[i]) { | ||
111 | ret = -ENODEV; | ||
112 | dev_err(&pdev->dev, "Failed to add adapter %d\n", i); | ||
113 | goto add_adapter_failed; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | dev_info(&pdev->dev, "%d port mux on %s adapter\n", | ||
118 | pdata->n_values, parent->name); | ||
119 | |||
120 | platform_set_drvdata(pdev, mux); | ||
121 | |||
122 | return 0; | ||
123 | |||
124 | add_adapter_failed: | ||
125 | for (; i > 0; i--) | ||
126 | i2c_del_mux_adapter(mux->adap[i - 1]); | ||
127 | i = pdata->n_gpios; | ||
128 | err_request_gpio: | ||
129 | for (; i > 0; i--) | ||
130 | gpio_free(pdata->gpios[i - 1]); | ||
131 | kfree(mux->adap); | ||
132 | alloc_failed2: | ||
133 | kfree(mux); | ||
134 | alloc_failed: | ||
135 | i2c_put_adapter(parent); | ||
136 | |||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | static int __devexit gpiomux_remove(struct platform_device *pdev) | ||
141 | { | ||
142 | struct gpiomux *mux = platform_get_drvdata(pdev); | ||
143 | int i; | ||
144 | |||
145 | for (i = 0; i < mux->data.n_values; i++) | ||
146 | i2c_del_mux_adapter(mux->adap[i]); | ||
147 | |||
148 | for (i = 0; i < mux->data.n_gpios; i++) | ||
149 | gpio_free(mux->data.gpios[i]); | ||
150 | |||
151 | platform_set_drvdata(pdev, NULL); | ||
152 | i2c_put_adapter(mux->parent); | ||
153 | kfree(mux->adap); | ||
154 | kfree(mux); | ||
155 | |||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | static struct platform_driver gpiomux_driver = { | ||
160 | .probe = gpiomux_probe, | ||
161 | .remove = __devexit_p(gpiomux_remove), | ||
162 | .driver = { | ||
163 | .owner = THIS_MODULE, | ||
164 | .name = "gpio-i2cmux", | ||
165 | }, | ||
166 | }; | ||
167 | |||
168 | static int __init gpiomux_init(void) | ||
169 | { | ||
170 | return platform_driver_register(&gpiomux_driver); | ||
171 | } | ||
172 | |||
173 | static void __exit gpiomux_exit(void) | ||
174 | { | ||
175 | platform_driver_unregister(&gpiomux_driver); | ||
176 | } | ||
177 | |||
178 | module_init(gpiomux_init); | ||
179 | module_exit(gpiomux_exit); | ||
180 | |||
181 | MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver"); | ||
182 | MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>"); | ||
183 | MODULE_LICENSE("GPL"); | ||
184 | MODULE_ALIAS("platform:gpio-i2cmux"); | ||
diff --git a/drivers/i2c/muxes/pca9541.c b/drivers/i2c/muxes/pca9541.c new file mode 100644 index 000000000000..ed699c5aa79d --- /dev/null +++ b/drivers/i2c/muxes/pca9541.c | |||
@@ -0,0 +1,411 @@ | |||
1 | /* | ||
2 | * I2C multiplexer driver for PCA9541 bus master selector | ||
3 | * | ||
4 | * Copyright (c) 2010 Ericsson AB. | ||
5 | * | ||
6 | * Author: Guenter Roeck <guenter.roeck@ericsson.com> | ||
7 | * | ||
8 | * Derived from: | ||
9 | * pca954x.c | ||
10 | * | ||
11 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
12 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
13 | * | ||
14 | * This file is licensed under the terms of the GNU General Public | ||
15 | * License version 2. This program is licensed "as is" without any | ||
16 | * warranty of any kind, whether express or implied. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/jiffies.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <linux/i2c-mux.h> | ||
27 | |||
28 | #include <linux/i2c/pca954x.h> | ||
29 | |||
30 | /* | ||
31 | * The PCA9541 is a bus master selector. It supports two I2C masters connected | ||
32 | * to a single slave bus. | ||
33 | * | ||
34 | * Before each bus transaction, a master has to acquire bus ownership. After the | ||
35 | * transaction is complete, bus ownership has to be released. This fits well | ||
36 | * into the I2C multiplexer framework, which provides select and release | ||
37 | * functions for this purpose. For this reason, this driver is modeled as | ||
38 | * single-channel I2C bus multiplexer. | ||
39 | * | ||
40 | * This driver assumes that the two bus masters are controlled by two different | ||
41 | * hosts. If a single host controls both masters, platform code has to ensure | ||
42 | * that only one of the masters is instantiated at any given time. | ||
43 | */ | ||
44 | |||
45 | #define PCA9541_CONTROL 0x01 | ||
46 | #define PCA9541_ISTAT 0x02 | ||
47 | |||
48 | #define PCA9541_CTL_MYBUS (1 << 0) | ||
49 | #define PCA9541_CTL_NMYBUS (1 << 1) | ||
50 | #define PCA9541_CTL_BUSON (1 << 2) | ||
51 | #define PCA9541_CTL_NBUSON (1 << 3) | ||
52 | #define PCA9541_CTL_BUSINIT (1 << 4) | ||
53 | #define PCA9541_CTL_TESTON (1 << 6) | ||
54 | #define PCA9541_CTL_NTESTON (1 << 7) | ||
55 | |||
56 | #define PCA9541_ISTAT_INTIN (1 << 0) | ||
57 | #define PCA9541_ISTAT_BUSINIT (1 << 1) | ||
58 | #define PCA9541_ISTAT_BUSOK (1 << 2) | ||
59 | #define PCA9541_ISTAT_BUSLOST (1 << 3) | ||
60 | #define PCA9541_ISTAT_MYTEST (1 << 6) | ||
61 | #define PCA9541_ISTAT_NMYTEST (1 << 7) | ||
62 | |||
63 | #define BUSON (PCA9541_CTL_BUSON | PCA9541_CTL_NBUSON) | ||
64 | #define MYBUS (PCA9541_CTL_MYBUS | PCA9541_CTL_NMYBUS) | ||
65 | #define mybus(x) (!((x) & MYBUS) || ((x) & MYBUS) == MYBUS) | ||
66 | #define busoff(x) (!((x) & BUSON) || ((x) & BUSON) == BUSON) | ||
67 | |||
68 | /* arbitration timeouts, in jiffies */ | ||
69 | #define ARB_TIMEOUT (HZ / 8) /* 125 ms until forcing bus ownership */ | ||
70 | #define ARB2_TIMEOUT (HZ / 4) /* 250 ms until acquisition failure */ | ||
71 | |||
72 | /* arbitration retry delays, in us */ | ||
73 | #define SELECT_DELAY_SHORT 50 | ||
74 | #define SELECT_DELAY_LONG 1000 | ||
75 | |||
76 | struct pca9541 { | ||
77 | struct i2c_adapter *mux_adap; | ||
78 | unsigned long select_timeout; | ||
79 | unsigned long arb_timeout; | ||
80 | }; | ||
81 | |||
82 | static const struct i2c_device_id pca9541_id[] = { | ||
83 | {"pca9541", 0}, | ||
84 | {} | ||
85 | }; | ||
86 | |||
87 | MODULE_DEVICE_TABLE(i2c, pca9541_id); | ||
88 | |||
89 | /* | ||
90 | * Write to chip register. Don't use i2c_transfer()/i2c_smbus_xfer() | ||
91 | * as they will try to lock the adapter a second time. | ||
92 | */ | ||
93 | static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val) | ||
94 | { | ||
95 | struct i2c_adapter *adap = client->adapter; | ||
96 | int ret; | ||
97 | |||
98 | if (adap->algo->master_xfer) { | ||
99 | struct i2c_msg msg; | ||
100 | char buf[2]; | ||
101 | |||
102 | msg.addr = client->addr; | ||
103 | msg.flags = 0; | ||
104 | msg.len = 2; | ||
105 | buf[0] = command; | ||
106 | buf[1] = val; | ||
107 | msg.buf = buf; | ||
108 | ret = adap->algo->master_xfer(adap, &msg, 1); | ||
109 | } else { | ||
110 | union i2c_smbus_data data; | ||
111 | |||
112 | data.byte = val; | ||
113 | ret = adap->algo->smbus_xfer(adap, client->addr, | ||
114 | client->flags, | ||
115 | I2C_SMBUS_WRITE, | ||
116 | command, | ||
117 | I2C_SMBUS_BYTE_DATA, &data); | ||
118 | } | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | * Read from chip register. Don't use i2c_transfer()/i2c_smbus_xfer() | ||
125 | * as they will try to lock adapter a second time. | ||
126 | */ | ||
127 | static int pca9541_reg_read(struct i2c_client *client, u8 command) | ||
128 | { | ||
129 | struct i2c_adapter *adap = client->adapter; | ||
130 | int ret; | ||
131 | u8 val; | ||
132 | |||
133 | if (adap->algo->master_xfer) { | ||
134 | struct i2c_msg msg[2] = { | ||
135 | { | ||
136 | .addr = client->addr, | ||
137 | .flags = 0, | ||
138 | .len = 1, | ||
139 | .buf = &command | ||
140 | }, | ||
141 | { | ||
142 | .addr = client->addr, | ||
143 | .flags = I2C_M_RD, | ||
144 | .len = 1, | ||
145 | .buf = &val | ||
146 | } | ||
147 | }; | ||
148 | ret = adap->algo->master_xfer(adap, msg, 2); | ||
149 | if (ret == 2) | ||
150 | ret = val; | ||
151 | else if (ret >= 0) | ||
152 | ret = -EIO; | ||
153 | } else { | ||
154 | union i2c_smbus_data data; | ||
155 | |||
156 | ret = adap->algo->smbus_xfer(adap, client->addr, | ||
157 | client->flags, | ||
158 | I2C_SMBUS_READ, | ||
159 | command, | ||
160 | I2C_SMBUS_BYTE_DATA, &data); | ||
161 | if (!ret) | ||
162 | ret = data.byte; | ||
163 | } | ||
164 | return ret; | ||
165 | } | ||
166 | |||
167 | /* | ||
168 | * Arbitration management functions | ||
169 | */ | ||
170 | |||
171 | /* Release bus. Also reset NTESTON and BUSINIT if it was set. */ | ||
172 | static void pca9541_release_bus(struct i2c_client *client) | ||
173 | { | ||
174 | int reg; | ||
175 | |||
176 | reg = pca9541_reg_read(client, PCA9541_CONTROL); | ||
177 | if (reg >= 0 && !busoff(reg) && mybus(reg)) | ||
178 | pca9541_reg_write(client, PCA9541_CONTROL, | ||
179 | (reg & PCA9541_CTL_NBUSON) >> 1); | ||
180 | } | ||
181 | |||
182 | /* | ||
183 | * Arbitration is defined as a two-step process. A bus master can only activate | ||
184 | * the slave bus if it owns it; otherwise it has to request ownership first. | ||
185 | * This multi-step process ensures that access contention is resolved | ||
186 | * gracefully. | ||
187 | * | ||
188 | * Bus Ownership Other master Action | ||
189 | * state requested access | ||
190 | * ---------------------------------------------------- | ||
191 | * off - yes wait for arbitration timeout or | ||
192 | * for other master to drop request | ||
193 | * off no no take ownership | ||
194 | * off yes no turn on bus | ||
195 | * on yes - done | ||
196 | * on no - wait for arbitration timeout or | ||
197 | * for other master to release bus | ||
198 | * | ||
199 | * The main contention point occurs if the slave bus is off and both masters | ||
200 | * request ownership at the same time. In this case, one master will turn on | ||
201 | * the slave bus, believing that it owns it. The other master will request | ||
202 | * bus ownership. Result is that the bus is turned on, and master which did | ||
203 | * _not_ own the slave bus before ends up owning it. | ||
204 | */ | ||
205 | |||
206 | /* Control commands per PCA9541 datasheet */ | ||
207 | static const u8 pca9541_control[16] = { | ||
208 | 4, 0, 1, 5, 4, 4, 5, 5, 0, 0, 1, 1, 0, 4, 5, 1 | ||
209 | }; | ||
210 | |||
211 | /* | ||
212 | * Channel arbitration | ||
213 | * | ||
214 | * Return values: | ||
215 | * <0: error | ||
216 | * 0 : bus not acquired | ||
217 | * 1 : bus acquired | ||
218 | */ | ||
219 | static int pca9541_arbitrate(struct i2c_client *client) | ||
220 | { | ||
221 | struct pca9541 *data = i2c_get_clientdata(client); | ||
222 | int reg; | ||
223 | |||
224 | reg = pca9541_reg_read(client, PCA9541_CONTROL); | ||
225 | if (reg < 0) | ||
226 | return reg; | ||
227 | |||
228 | if (busoff(reg)) { | ||
229 | int istat; | ||
230 | /* | ||
231 | * Bus is off. Request ownership or turn it on unless | ||
232 | * other master requested ownership. | ||
233 | */ | ||
234 | istat = pca9541_reg_read(client, PCA9541_ISTAT); | ||
235 | if (!(istat & PCA9541_ISTAT_NMYTEST) | ||
236 | || time_is_before_eq_jiffies(data->arb_timeout)) { | ||
237 | /* | ||
238 | * Other master did not request ownership, | ||
239 | * or arbitration timeout expired. Take the bus. | ||
240 | */ | ||
241 | pca9541_reg_write(client, | ||
242 | PCA9541_CONTROL, | ||
243 | pca9541_control[reg & 0x0f] | ||
244 | | PCA9541_CTL_NTESTON); | ||
245 | data->select_timeout = SELECT_DELAY_SHORT; | ||
246 | } else { | ||
247 | /* | ||
248 | * Other master requested ownership. | ||
249 | * Set extra long timeout to give it time to acquire it. | ||
250 | */ | ||
251 | data->select_timeout = SELECT_DELAY_LONG * 2; | ||
252 | } | ||
253 | } else if (mybus(reg)) { | ||
254 | /* | ||
255 | * Bus is on, and we own it. We are done with acquisition. | ||
256 | * Reset NTESTON and BUSINIT, then return success. | ||
257 | */ | ||
258 | if (reg & (PCA9541_CTL_NTESTON | PCA9541_CTL_BUSINIT)) | ||
259 | pca9541_reg_write(client, | ||
260 | PCA9541_CONTROL, | ||
261 | reg & ~(PCA9541_CTL_NTESTON | ||
262 | | PCA9541_CTL_BUSINIT)); | ||
263 | return 1; | ||
264 | } else { | ||
265 | /* | ||
266 | * Other master owns the bus. | ||
267 | * If arbitration timeout has expired, force ownership. | ||
268 | * Otherwise request it. | ||
269 | */ | ||
270 | data->select_timeout = SELECT_DELAY_LONG; | ||
271 | if (time_is_before_eq_jiffies(data->arb_timeout)) { | ||
272 | /* Time is up, take the bus and reset it. */ | ||
273 | pca9541_reg_write(client, | ||
274 | PCA9541_CONTROL, | ||
275 | pca9541_control[reg & 0x0f] | ||
276 | | PCA9541_CTL_BUSINIT | ||
277 | | PCA9541_CTL_NTESTON); | ||
278 | } else { | ||
279 | /* Request bus ownership if needed */ | ||
280 | if (!(reg & PCA9541_CTL_NTESTON)) | ||
281 | pca9541_reg_write(client, | ||
282 | PCA9541_CONTROL, | ||
283 | reg | PCA9541_CTL_NTESTON); | ||
284 | } | ||
285 | } | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int pca9541_select_chan(struct i2c_adapter *adap, void *client, u32 chan) | ||
290 | { | ||
291 | struct pca9541 *data = i2c_get_clientdata(client); | ||
292 | int ret; | ||
293 | unsigned long timeout = jiffies + ARB2_TIMEOUT; | ||
294 | /* give up after this time */ | ||
295 | |||
296 | data->arb_timeout = jiffies + ARB_TIMEOUT; | ||
297 | /* force bus ownership after this time */ | ||
298 | |||
299 | do { | ||
300 | ret = pca9541_arbitrate(client); | ||
301 | if (ret) | ||
302 | return ret < 0 ? ret : 0; | ||
303 | |||
304 | if (data->select_timeout == SELECT_DELAY_SHORT) | ||
305 | udelay(data->select_timeout); | ||
306 | else | ||
307 | msleep(data->select_timeout / 1000); | ||
308 | } while (time_is_after_eq_jiffies(timeout)); | ||
309 | |||
310 | return -ETIMEDOUT; | ||
311 | } | ||
312 | |||
313 | static int pca9541_release_chan(struct i2c_adapter *adap, | ||
314 | void *client, u32 chan) | ||
315 | { | ||
316 | pca9541_release_bus(client); | ||
317 | return 0; | ||
318 | } | ||
319 | |||
320 | /* | ||
321 | * I2C init/probing/exit functions | ||
322 | */ | ||
323 | static int pca9541_probe(struct i2c_client *client, | ||
324 | const struct i2c_device_id *id) | ||
325 | { | ||
326 | struct i2c_adapter *adap = client->adapter; | ||
327 | struct pca954x_platform_data *pdata = client->dev.platform_data; | ||
328 | struct pca9541 *data; | ||
329 | int force; | ||
330 | int ret = -ENODEV; | ||
331 | |||
332 | if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
333 | goto err; | ||
334 | |||
335 | data = kzalloc(sizeof(struct pca9541), GFP_KERNEL); | ||
336 | if (!data) { | ||
337 | ret = -ENOMEM; | ||
338 | goto err; | ||
339 | } | ||
340 | |||
341 | i2c_set_clientdata(client, data); | ||
342 | |||
343 | /* | ||
344 | * I2C accesses are unprotected here. | ||
345 | * We have to lock the adapter before releasing the bus. | ||
346 | */ | ||
347 | i2c_lock_adapter(adap); | ||
348 | pca9541_release_bus(client); | ||
349 | i2c_unlock_adapter(adap); | ||
350 | |||
351 | /* Create mux adapter */ | ||
352 | |||
353 | force = 0; | ||
354 | if (pdata) | ||
355 | force = pdata->modes[0].adap_id; | ||
356 | data->mux_adap = i2c_add_mux_adapter(adap, client, force, 0, | ||
357 | pca9541_select_chan, | ||
358 | pca9541_release_chan); | ||
359 | |||
360 | if (data->mux_adap == NULL) { | ||
361 | dev_err(&client->dev, "failed to register master selector\n"); | ||
362 | goto exit_free; | ||
363 | } | ||
364 | |||
365 | dev_info(&client->dev, "registered master selector for I2C %s\n", | ||
366 | client->name); | ||
367 | |||
368 | return 0; | ||
369 | |||
370 | exit_free: | ||
371 | kfree(data); | ||
372 | err: | ||
373 | return ret; | ||
374 | } | ||
375 | |||
376 | static int pca9541_remove(struct i2c_client *client) | ||
377 | { | ||
378 | struct pca9541 *data = i2c_get_clientdata(client); | ||
379 | |||
380 | i2c_del_mux_adapter(data->mux_adap); | ||
381 | |||
382 | kfree(data); | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static struct i2c_driver pca9541_driver = { | ||
387 | .driver = { | ||
388 | .name = "pca9541", | ||
389 | .owner = THIS_MODULE, | ||
390 | }, | ||
391 | .probe = pca9541_probe, | ||
392 | .remove = pca9541_remove, | ||
393 | .id_table = pca9541_id, | ||
394 | }; | ||
395 | |||
396 | static int __init pca9541_init(void) | ||
397 | { | ||
398 | return i2c_add_driver(&pca9541_driver); | ||
399 | } | ||
400 | |||
401 | static void __exit pca9541_exit(void) | ||
402 | { | ||
403 | i2c_del_driver(&pca9541_driver); | ||
404 | } | ||
405 | |||
406 | module_init(pca9541_init); | ||
407 | module_exit(pca9541_exit); | ||
408 | |||
409 | MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); | ||
410 | MODULE_DESCRIPTION("PCA9541 I2C master selector driver"); | ||
411 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c new file mode 100644 index 000000000000..54e1ce73534b --- /dev/null +++ b/drivers/i2c/muxes/pca954x.c | |||
@@ -0,0 +1,301 @@ | |||
1 | /* | ||
2 | * I2C multiplexer | ||
3 | * | ||
4 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
5 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
6 | * | ||
7 | * This module supports the PCA954x series of I2C multiplexer/switch chips | ||
8 | * made by Philips Semiconductors. | ||
9 | * This includes the: | ||
10 | * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547 | ||
11 | * and PCA9548. | ||
12 | * | ||
13 | * These chips are all controlled via the I2C bus itself, and all have a | ||
14 | * single 8-bit register. The upstream "parent" bus fans out to two, | ||
15 | * four, or eight downstream busses or channels; which of these | ||
16 | * are selected is determined by the chip type and register contents. A | ||
17 | * mux can select only one sub-bus at a time; a switch can select any | ||
18 | * combination simultaneously. | ||
19 | * | ||
20 | * Based on: | ||
21 | * pca954x.c from Kumar Gala <galak@kernel.crashing.org> | ||
22 | * Copyright (C) 2006 | ||
23 | * | ||
24 | * Based on: | ||
25 | * pca954x.c from Ken Harrenstien | ||
26 | * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) | ||
27 | * | ||
28 | * Based on: | ||
29 | * i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com> | ||
30 | * and | ||
31 | * pca9540.c from Jean Delvare <khali@linux-fr.org>. | ||
32 | * | ||
33 | * This file is licensed under the terms of the GNU General Public | ||
34 | * License version 2. This program is licensed "as is" without any | ||
35 | * warranty of any kind, whether express or implied. | ||
36 | */ | ||
37 | |||
38 | #include <linux/module.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/slab.h> | ||
41 | #include <linux/device.h> | ||
42 | #include <linux/i2c.h> | ||
43 | #include <linux/i2c-mux.h> | ||
44 | |||
45 | #include <linux/i2c/pca954x.h> | ||
46 | |||
47 | #define PCA954X_MAX_NCHANS 8 | ||
48 | |||
49 | enum pca_type { | ||
50 | pca_9540, | ||
51 | pca_9542, | ||
52 | pca_9543, | ||
53 | pca_9544, | ||
54 | pca_9545, | ||
55 | pca_9546, | ||
56 | pca_9547, | ||
57 | pca_9548, | ||
58 | }; | ||
59 | |||
60 | struct pca954x { | ||
61 | enum pca_type type; | ||
62 | struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS]; | ||
63 | |||
64 | u8 last_chan; /* last register value */ | ||
65 | }; | ||
66 | |||
67 | struct chip_desc { | ||
68 | u8 nchans; | ||
69 | u8 enable; /* used for muxes only */ | ||
70 | enum muxtype { | ||
71 | pca954x_ismux = 0, | ||
72 | pca954x_isswi | ||
73 | } muxtype; | ||
74 | }; | ||
75 | |||
76 | /* Provide specs for the PCA954x types we know about */ | ||
77 | static const struct chip_desc chips[] = { | ||
78 | [pca_9540] = { | ||
79 | .nchans = 2, | ||
80 | .enable = 0x4, | ||
81 | .muxtype = pca954x_ismux, | ||
82 | }, | ||
83 | [pca_9543] = { | ||
84 | .nchans = 2, | ||
85 | .muxtype = pca954x_isswi, | ||
86 | }, | ||
87 | [pca_9544] = { | ||
88 | .nchans = 4, | ||
89 | .enable = 0x4, | ||
90 | .muxtype = pca954x_ismux, | ||
91 | }, | ||
92 | [pca_9545] = { | ||
93 | .nchans = 4, | ||
94 | .muxtype = pca954x_isswi, | ||
95 | }, | ||
96 | [pca_9547] = { | ||
97 | .nchans = 8, | ||
98 | .enable = 0x8, | ||
99 | .muxtype = pca954x_ismux, | ||
100 | }, | ||
101 | [pca_9548] = { | ||
102 | .nchans = 8, | ||
103 | .muxtype = pca954x_isswi, | ||
104 | }, | ||
105 | }; | ||
106 | |||
107 | static const struct i2c_device_id pca954x_id[] = { | ||
108 | { "pca9540", pca_9540 }, | ||
109 | { "pca9542", pca_9540 }, | ||
110 | { "pca9543", pca_9543 }, | ||
111 | { "pca9544", pca_9544 }, | ||
112 | { "pca9545", pca_9545 }, | ||
113 | { "pca9546", pca_9545 }, | ||
114 | { "pca9547", pca_9547 }, | ||
115 | { "pca9548", pca_9548 }, | ||
116 | { } | ||
117 | }; | ||
118 | MODULE_DEVICE_TABLE(i2c, pca954x_id); | ||
119 | |||
120 | /* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() | ||
121 | for this as they will try to lock adapter a second time */ | ||
122 | static int pca954x_reg_write(struct i2c_adapter *adap, | ||
123 | struct i2c_client *client, u8 val) | ||
124 | { | ||
125 | int ret = -ENODEV; | ||
126 | |||
127 | if (adap->algo->master_xfer) { | ||
128 | struct i2c_msg msg; | ||
129 | char buf[1]; | ||
130 | |||
131 | msg.addr = client->addr; | ||
132 | msg.flags = 0; | ||
133 | msg.len = 1; | ||
134 | buf[0] = val; | ||
135 | msg.buf = buf; | ||
136 | ret = adap->algo->master_xfer(adap, &msg, 1); | ||
137 | } else { | ||
138 | union i2c_smbus_data data; | ||
139 | ret = adap->algo->smbus_xfer(adap, client->addr, | ||
140 | client->flags, | ||
141 | I2C_SMBUS_WRITE, | ||
142 | val, I2C_SMBUS_BYTE, &data); | ||
143 | } | ||
144 | |||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | static int pca954x_select_chan(struct i2c_adapter *adap, | ||
149 | void *client, u32 chan) | ||
150 | { | ||
151 | struct pca954x *data = i2c_get_clientdata(client); | ||
152 | const struct chip_desc *chip = &chips[data->type]; | ||
153 | u8 regval; | ||
154 | int ret = 0; | ||
155 | |||
156 | /* we make switches look like muxes, not sure how to be smarter */ | ||
157 | if (chip->muxtype == pca954x_ismux) | ||
158 | regval = chan | chip->enable; | ||
159 | else | ||
160 | regval = 1 << chan; | ||
161 | |||
162 | /* Only select the channel if its different from the last channel */ | ||
163 | if (data->last_chan != regval) { | ||
164 | ret = pca954x_reg_write(adap, client, regval); | ||
165 | data->last_chan = regval; | ||
166 | } | ||
167 | |||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | static int pca954x_deselect_mux(struct i2c_adapter *adap, | ||
172 | void *client, u32 chan) | ||
173 | { | ||
174 | struct pca954x *data = i2c_get_clientdata(client); | ||
175 | |||
176 | /* Deselect active channel */ | ||
177 | data->last_chan = 0; | ||
178 | return pca954x_reg_write(adap, client, data->last_chan); | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | * I2C init/probing/exit functions | ||
183 | */ | ||
184 | static int pca954x_probe(struct i2c_client *client, | ||
185 | const struct i2c_device_id *id) | ||
186 | { | ||
187 | struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); | ||
188 | struct pca954x_platform_data *pdata = client->dev.platform_data; | ||
189 | int num, force; | ||
190 | struct pca954x *data; | ||
191 | int ret = -ENODEV; | ||
192 | |||
193 | if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) | ||
194 | goto err; | ||
195 | |||
196 | data = kzalloc(sizeof(struct pca954x), GFP_KERNEL); | ||
197 | if (!data) { | ||
198 | ret = -ENOMEM; | ||
199 | goto err; | ||
200 | } | ||
201 | |||
202 | i2c_set_clientdata(client, data); | ||
203 | |||
204 | /* Read the mux register at addr to verify | ||
205 | * that the mux is in fact present. | ||
206 | */ | ||
207 | if (i2c_smbus_read_byte(client) < 0) { | ||
208 | dev_warn(&client->dev, "probe failed\n"); | ||
209 | goto exit_free; | ||
210 | } | ||
211 | |||
212 | data->type = id->driver_data; | ||
213 | data->last_chan = 0; /* force the first selection */ | ||
214 | |||
215 | /* Now create an adapter for each channel */ | ||
216 | for (num = 0; num < chips[data->type].nchans; num++) { | ||
217 | force = 0; /* dynamic adap number */ | ||
218 | if (pdata) { | ||
219 | if (num < pdata->num_modes) | ||
220 | /* force static number */ | ||
221 | force = pdata->modes[num].adap_id; | ||
222 | else | ||
223 | /* discard unconfigured channels */ | ||
224 | break; | ||
225 | } | ||
226 | |||
227 | data->virt_adaps[num] = | ||
228 | i2c_add_mux_adapter(adap, client, | ||
229 | force, num, pca954x_select_chan, | ||
230 | (pdata && pdata->modes[num].deselect_on_exit) | ||
231 | ? pca954x_deselect_mux : NULL); | ||
232 | |||
233 | if (data->virt_adaps[num] == NULL) { | ||
234 | ret = -ENODEV; | ||
235 | dev_err(&client->dev, | ||
236 | "failed to register multiplexed adapter" | ||
237 | " %d as bus %d\n", num, force); | ||
238 | goto virt_reg_failed; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | dev_info(&client->dev, | ||
243 | "registered %d multiplexed busses for I2C %s %s\n", | ||
244 | num, chips[data->type].muxtype == pca954x_ismux | ||
245 | ? "mux" : "switch", client->name); | ||
246 | |||
247 | return 0; | ||
248 | |||
249 | virt_reg_failed: | ||
250 | for (num--; num >= 0; num--) | ||
251 | i2c_del_mux_adapter(data->virt_adaps[num]); | ||
252 | exit_free: | ||
253 | kfree(data); | ||
254 | err: | ||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | static int pca954x_remove(struct i2c_client *client) | ||
259 | { | ||
260 | struct pca954x *data = i2c_get_clientdata(client); | ||
261 | const struct chip_desc *chip = &chips[data->type]; | ||
262 | int i, err; | ||
263 | |||
264 | for (i = 0; i < chip->nchans; ++i) | ||
265 | if (data->virt_adaps[i]) { | ||
266 | err = i2c_del_mux_adapter(data->virt_adaps[i]); | ||
267 | if (err) | ||
268 | return err; | ||
269 | data->virt_adaps[i] = NULL; | ||
270 | } | ||
271 | |||
272 | kfree(data); | ||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | static struct i2c_driver pca954x_driver = { | ||
277 | .driver = { | ||
278 | .name = "pca954x", | ||
279 | .owner = THIS_MODULE, | ||
280 | }, | ||
281 | .probe = pca954x_probe, | ||
282 | .remove = pca954x_remove, | ||
283 | .id_table = pca954x_id, | ||
284 | }; | ||
285 | |||
286 | static int __init pca954x_init(void) | ||
287 | { | ||
288 | return i2c_add_driver(&pca954x_driver); | ||
289 | } | ||
290 | |||
291 | static void __exit pca954x_exit(void) | ||
292 | { | ||
293 | i2c_del_driver(&pca954x_driver); | ||
294 | } | ||
295 | |||
296 | module_init(pca954x_init); | ||
297 | module_exit(pca954x_exit); | ||
298 | |||
299 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
300 | MODULE_DESCRIPTION("PCA954x I2C mux/switch driver"); | ||
301 | MODULE_LICENSE("GPL v2"); | ||