diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-24 15:46:24 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-24 15:46:24 -0400 |
| commit | bdaf12b41235b0c59949914de022341e77907461 (patch) | |
| tree | 2473bf0e3a28fdc2285cf830c9a259d9b85a4061 | |
| parent | 7c024e9534f9edd8d052380a1b40d376c8feb11b (diff) | |
| parent | bf5d95c82692ead9ba7876af73dac2edcc8a6191 (diff) | |
Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
i2c-viapro: Don't log nacks
i2c/pca954x: Remove __devinit and __devexit from probe and remove functions
MAINTAINERS: Add maintainer for PCA9541 I2C bus master selector driver
i2c/mux: Driver for PCA9541 I2C Master Selector
i2c: Optimize function i2c_detect()
i2c: Discard warning message on device instantiation from user-space
i2c-amd8111: Add proper error handling
i2c: Change to new flag variable
i2c: Remove unneeded inclusions of <linux/i2c-id.h>
i2c: Let i2c_parent_is_i2c_adapter return the parent adapter
i2c: Simplify i2c_parent_is_i2c_adapter
i2c-pca-platform: Change device name of request_irq
i2c: Fix Kconfig dependencies
26 files changed, 603 insertions, 117 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 9bd4422618e9..0e265fcc103b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -4541,6 +4541,12 @@ S: Maintained | |||
| 4541 | F: drivers/leds/leds-pca9532.c | 4541 | F: drivers/leds/leds-pca9532.c |
| 4542 | F: include/linux/leds-pca9532.h | 4542 | F: include/linux/leds-pca9532.h |
| 4543 | 4543 | ||
| 4544 | PCA9541 I2C BUS MASTER SELECTOR DRIVER | ||
| 4545 | M: Guenter Roeck <guenter.roeck@ericsson.com> | ||
| 4546 | L: linux-i2c@vger.kernel.org | ||
| 4547 | S: Maintained | ||
| 4548 | F: drivers/i2c/muxes/pca9541.c | ||
| 4549 | |||
| 4544 | PCA9564/PCA9665 I2C BUS DRIVER | 4550 | PCA9564/PCA9665 I2C BUS DRIVER |
| 4545 | M: Wolfram Sang <w.sang@pengutronix.de> | 4551 | M: Wolfram Sang <w.sang@pengutronix.de> |
| 4546 | L: linux-i2c@vger.kernel.org | 4552 | L: linux-i2c@vger.kernel.org |
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.h b/drivers/gpu/drm/nouveau/nouveau_i2c.h index f71cb32f7571..cfe7c8426d1d 100644 --- a/drivers/gpu/drm/nouveau/nouveau_i2c.h +++ b/drivers/gpu/drm/nouveau/nouveau_i2c.h | |||
| @@ -24,7 +24,6 @@ | |||
| 24 | #define __NOUVEAU_I2C_H__ | 24 | #define __NOUVEAU_I2C_H__ |
| 25 | 25 | ||
| 26 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
| 27 | #include <linux/i2c-id.h> | ||
| 28 | #include <linux/i2c-algo-bit.h> | 27 | #include <linux/i2c-algo-bit.h> |
| 29 | #include "drm_dp_helper.h" | 28 | #include "drm_dp_helper.h" |
| 30 | 29 | ||
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h index 17a6602b5885..454c1dc7ea45 100644 --- a/drivers/gpu/drm/radeon/radeon_mode.h +++ b/drivers/gpu/drm/radeon/radeon_mode.h | |||
| @@ -36,7 +36,6 @@ | |||
| 36 | #include <drm_dp_helper.h> | 36 | #include <drm_dp_helper.h> |
| 37 | #include <drm_fixed.h> | 37 | #include <drm_fixed.h> |
| 38 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
| 39 | #include <linux/i2c-id.h> | ||
| 40 | #include <linux/i2c-algo-bit.h> | 39 | #include <linux/i2c-algo-bit.h> |
| 41 | 40 | ||
| 42 | struct radeon_bo; | 41 | struct radeon_bo; |
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index 30f06e956bfb..b923074b2cbe 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig | |||
| @@ -75,7 +75,8 @@ config I2C_HELPER_AUTO | |||
| 75 | In doubt, say Y. | 75 | In doubt, say Y. |
| 76 | 76 | ||
| 77 | config I2C_SMBUS | 77 | config I2C_SMBUS |
| 78 | tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO | 78 | tristate |
| 79 | prompt "SMBus-specific protocols" if !I2C_HELPER_AUTO | ||
| 79 | help | 80 | help |
| 80 | Say Y here if you want support for SMBus extensions to the I2C | 81 | Say Y here if you want support for SMBus extensions to the I2C |
| 81 | specification. At the moment, the only supported extension is | 82 | specification. At the moment, the only supported extension is |
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index c00fd66388f5..23ac61e2db39 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile | |||
| @@ -9,6 +9,4 @@ obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o | |||
| 9 | obj-$(CONFIG_I2C_MUX) += i2c-mux.o | 9 | obj-$(CONFIG_I2C_MUX) += i2c-mux.o |
| 10 | obj-y += algos/ busses/ muxes/ | 10 | obj-y += algos/ busses/ muxes/ |
| 11 | 11 | ||
| 12 | ifeq ($(CONFIG_I2C_DEBUG_CORE),y) | 12 | ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG |
| 13 | EXTRA_CFLAGS += -DDEBUG | ||
| 14 | endif | ||
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig index 7b2ce4a08524..3998dd620a03 100644 --- a/drivers/i2c/algos/Kconfig +++ b/drivers/i2c/algos/Kconfig | |||
| @@ -15,3 +15,15 @@ config I2C_ALGOPCA | |||
| 15 | tristate "I2C PCA 9564 interfaces" | 15 | tristate "I2C PCA 9564 interfaces" |
| 16 | 16 | ||
| 17 | endmenu | 17 | endmenu |
| 18 | |||
| 19 | # In automatic configuration mode, we still have to define the | ||
| 20 | # symbols to avoid unmet dependencies. | ||
| 21 | |||
| 22 | if I2C_HELPER_AUTO | ||
| 23 | config I2C_ALGOBIT | ||
| 24 | tristate | ||
| 25 | config I2C_ALGOPCF | ||
| 26 | tristate | ||
| 27 | config I2C_ALGOPCA | ||
| 28 | tristate | ||
| 29 | endif | ||
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/busses/Makefile b/drivers/i2c/busses/Makefile index c3ef49230cba..033ad413f328 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
| @@ -76,6 +76,4 @@ obj-$(CONFIG_I2C_STUB) += i2c-stub.o | |||
| 76 | obj-$(CONFIG_SCx200_ACB) += scx200_acb.o | 76 | obj-$(CONFIG_SCx200_ACB) += scx200_acb.o |
| 77 | obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o | 77 | obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o |
| 78 | 78 | ||
| 79 | ifeq ($(CONFIG_I2C_DEBUG_BUS),y) | 79 | ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG |
| 80 | EXTRA_CFLAGS += -DDEBUG | ||
| 81 | endif | ||
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c index af1e5e254b7b..6b6a6b1d7025 100644 --- a/drivers/i2c/busses/i2c-amd8111.c +++ b/drivers/i2c/busses/i2c-amd8111.c | |||
| @@ -69,7 +69,7 @@ static struct pci_driver amd8111_driver; | |||
| 69 | * ACPI 2.0 chapter 13 access of registers of the EC | 69 | * ACPI 2.0 chapter 13 access of registers of the EC |
| 70 | */ | 70 | */ |
| 71 | 71 | ||
| 72 | static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) | 72 | static int amd_ec_wait_write(struct amd_smbus *smbus) |
| 73 | { | 73 | { |
| 74 | int timeout = 500; | 74 | int timeout = 500; |
| 75 | 75 | ||
| @@ -85,7 +85,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) | |||
| 85 | return 0; | 85 | return 0; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) | 88 | static int amd_ec_wait_read(struct amd_smbus *smbus) |
| 89 | { | 89 | { |
| 90 | int timeout = 500; | 90 | int timeout = 500; |
| 91 | 91 | ||
| @@ -101,7 +101,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) | |||
| 101 | return 0; | 101 | return 0; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | 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, |
| 105 | unsigned char *data) | 105 | unsigned char *data) |
| 106 | { | 106 | { |
| 107 | int status; | 107 | int status; |
| @@ -124,7 +124,7 @@ static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, | |||
| 124 | return 0; | 124 | return 0; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | 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, |
| 128 | unsigned char data) | 128 | unsigned char data) |
| 129 | { | 129 | { |
| 130 | int status; | 130 | int status; |
| @@ -196,7 +196,7 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
| 196 | { | 196 | { |
| 197 | struct amd_smbus *smbus = adap->algo_data; | 197 | struct amd_smbus *smbus = adap->algo_data; |
| 198 | unsigned char protocol, len, pec, temp[2]; | 198 | unsigned char protocol, len, pec, temp[2]; |
| 199 | int i; | 199 | int i, status; |
| 200 | 200 | ||
| 201 | protocol = (read_write == I2C_SMBUS_READ) ? AMD_SMB_PRTCL_READ | 201 | protocol = (read_write == I2C_SMBUS_READ) ? AMD_SMB_PRTCL_READ |
| 202 | : AMD_SMB_PRTCL_WRITE; | 202 | : AMD_SMB_PRTCL_WRITE; |
| @@ -209,38 +209,62 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
| 209 | break; | 209 | break; |
| 210 | 210 | ||
| 211 | case I2C_SMBUS_BYTE: | 211 | case I2C_SMBUS_BYTE: |
| 212 | if (read_write == I2C_SMBUS_WRITE) | 212 | if (read_write == I2C_SMBUS_WRITE) { |
| 213 | 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 | } | ||
| 214 | protocol |= AMD_SMB_PRTCL_BYTE; | 218 | protocol |= AMD_SMB_PRTCL_BYTE; |
| 215 | break; | 219 | break; |
| 216 | 220 | ||
| 217 | case I2C_SMBUS_BYTE_DATA: | 221 | case I2C_SMBUS_BYTE_DATA: |
| 218 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 222 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
| 219 | if (read_write == I2C_SMBUS_WRITE) | 223 | if (status) |
| 220 | 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 | } | ||
| 221 | protocol |= AMD_SMB_PRTCL_BYTE_DATA; | 231 | protocol |= AMD_SMB_PRTCL_BYTE_DATA; |
| 222 | break; | 232 | break; |
| 223 | 233 | ||
| 224 | case I2C_SMBUS_WORD_DATA: | 234 | case I2C_SMBUS_WORD_DATA: |
| 225 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 235 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
| 236 | if (status) | ||
| 237 | return status; | ||
| 226 | if (read_write == I2C_SMBUS_WRITE) { | 238 | if (read_write == I2C_SMBUS_WRITE) { |
| 227 | amd_ec_write(smbus, AMD_SMB_DATA, | 239 | status = amd_ec_write(smbus, AMD_SMB_DATA, |
| 228 | data->word & 0xff); | 240 | data->word & 0xff); |
| 229 | amd_ec_write(smbus, AMD_SMB_DATA + 1, | 241 | if (status) |
| 230 | 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; | ||
| 231 | } | 247 | } |
| 232 | protocol |= AMD_SMB_PRTCL_WORD_DATA | pec; | 248 | protocol |= AMD_SMB_PRTCL_WORD_DATA | pec; |
| 233 | break; | 249 | break; |
| 234 | 250 | ||
| 235 | case I2C_SMBUS_BLOCK_DATA: | 251 | case I2C_SMBUS_BLOCK_DATA: |
| 236 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 252 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
| 253 | if (status) | ||
| 254 | return status; | ||
| 237 | if (read_write == I2C_SMBUS_WRITE) { | 255 | if (read_write == I2C_SMBUS_WRITE) { |
| 238 | len = min_t(u8, data->block[0], | 256 | len = min_t(u8, data->block[0], |
| 239 | I2C_SMBUS_BLOCK_MAX); | 257 | I2C_SMBUS_BLOCK_MAX); |
| 240 | amd_ec_write(smbus, AMD_SMB_BCNT, len); | 258 | status = amd_ec_write(smbus, AMD_SMB_BCNT, len); |
| 241 | for (i = 0; i < len; i++) | 259 | if (status) |
| 242 | amd_ec_write(smbus, AMD_SMB_DATA + i, | 260 | return status; |
| 243 | 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 | } | ||
| 244 | } | 268 | } |
| 245 | protocol |= AMD_SMB_PRTCL_BLOCK_DATA | pec; | 269 | protocol |= AMD_SMB_PRTCL_BLOCK_DATA | pec; |
| 246 | break; | 270 | break; |
| @@ -248,19 +272,35 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
| 248 | case I2C_SMBUS_I2C_BLOCK_DATA: | 272 | case I2C_SMBUS_I2C_BLOCK_DATA: |
| 249 | len = min_t(u8, data->block[0], | 273 | len = min_t(u8, data->block[0], |
| 250 | I2C_SMBUS_BLOCK_MAX); | 274 | I2C_SMBUS_BLOCK_MAX); |
| 251 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 275 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
| 252 | 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; | ||
| 253 | if (read_write == I2C_SMBUS_WRITE) | 281 | if (read_write == I2C_SMBUS_WRITE) |
| 254 | for (i = 0; i < len; i++) | 282 | for (i = 0; i < len; i++) { |
| 255 | amd_ec_write(smbus, AMD_SMB_DATA + i, | 283 | status = |
| 256 | 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 | } | ||
| 257 | protocol |= AMD_SMB_PRTCL_I2C_BLOCK_DATA; | 289 | protocol |= AMD_SMB_PRTCL_I2C_BLOCK_DATA; |
| 258 | break; | 290 | break; |
| 259 | 291 | ||
| 260 | case I2C_SMBUS_PROC_CALL: | 292 | case I2C_SMBUS_PROC_CALL: |
| 261 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 293 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
| 262 | amd_ec_write(smbus, AMD_SMB_DATA, data->word & 0xff); | 294 | if (status) |
| 263 | 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; | ||
| 264 | protocol = AMD_SMB_PRTCL_PROC_CALL | pec; | 304 | protocol = AMD_SMB_PRTCL_PROC_CALL | pec; |
| 265 | read_write = I2C_SMBUS_READ; | 305 | read_write = I2C_SMBUS_READ; |
| 266 | break; | 306 | break; |
| @@ -268,11 +308,18 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
| 268 | case I2C_SMBUS_BLOCK_PROC_CALL: | 308 | case I2C_SMBUS_BLOCK_PROC_CALL: |
| 269 | len = min_t(u8, data->block[0], | 309 | len = min_t(u8, data->block[0], |
| 270 | I2C_SMBUS_BLOCK_MAX - 1); | 310 | I2C_SMBUS_BLOCK_MAX - 1); |
| 271 | amd_ec_write(smbus, AMD_SMB_CMD, command); | 311 | status = amd_ec_write(smbus, AMD_SMB_CMD, command); |
| 272 | amd_ec_write(smbus, AMD_SMB_BCNT, len); | 312 | if (status) |
| 273 | for (i = 0; i < len; i++) | 313 | return status; |
| 274 | amd_ec_write(smbus, AMD_SMB_DATA + i, | 314 | status = amd_ec_write(smbus, AMD_SMB_BCNT, len); |
| 275 | 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 | } | ||
| 276 | protocol = AMD_SMB_PRTCL_BLOCK_PROC_CALL | pec; | 323 | protocol = AMD_SMB_PRTCL_BLOCK_PROC_CALL | pec; |
| 277 | read_write = I2C_SMBUS_READ; | 324 | read_write = I2C_SMBUS_READ; |
| 278 | break; | 325 | break; |
| @@ -282,24 +329,29 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
| 282 | return -EOPNOTSUPP; | 329 | return -EOPNOTSUPP; |
| 283 | } | 330 | } |
| 284 | 331 | ||
| 285 | amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); | 332 | status = amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); |
| 286 | 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; | ||
| 287 | 338 | ||
| 288 | /* FIXME this discards status from ec_read(); so temp[0] will | 339 | status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0); |
| 289 | * hold stack garbage ... the rest of this routine will act | 340 | if (status) |
| 290 | * nonsensically. Ignored ec_write() status might explain | 341 | return status; |
| 291 | * some such failures... | ||
| 292 | */ | ||
| 293 | amd_ec_read(smbus, AMD_SMB_STS, temp + 0); | ||
| 294 | 342 | ||
| 295 | if (~temp[0] & AMD_SMB_STS_DONE) { | 343 | if (~temp[0] & AMD_SMB_STS_DONE) { |
| 296 | udelay(500); | 344 | udelay(500); |
| 297 | 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; | ||
| 298 | } | 348 | } |
| 299 | 349 | ||
| 300 | if (~temp[0] & AMD_SMB_STS_DONE) { | 350 | if (~temp[0] & AMD_SMB_STS_DONE) { |
| 301 | msleep(1); | 351 | msleep(1); |
| 302 | 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; | ||
| 303 | } | 355 | } |
| 304 | 356 | ||
| 305 | 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)) |
| @@ -311,24 +363,35 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, | |||
| 311 | switch (size) { | 363 | switch (size) { |
| 312 | case I2C_SMBUS_BYTE: | 364 | case I2C_SMBUS_BYTE: |
| 313 | case I2C_SMBUS_BYTE_DATA: | 365 | case I2C_SMBUS_BYTE_DATA: |
| 314 | 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; | ||
| 315 | break; | 369 | break; |
| 316 | 370 | ||
| 317 | case I2C_SMBUS_WORD_DATA: | 371 | case I2C_SMBUS_WORD_DATA: |
| 318 | case I2C_SMBUS_PROC_CALL: | 372 | case I2C_SMBUS_PROC_CALL: |
| 319 | amd_ec_read(smbus, AMD_SMB_DATA, temp + 0); | 373 | status = amd_ec_read(smbus, AMD_SMB_DATA, temp + 0); |
| 320 | 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; | ||
| 321 | data->word = (temp[1] << 8) | temp[0]; | 379 | data->word = (temp[1] << 8) | temp[0]; |
| 322 | break; | 380 | break; |
| 323 | 381 | ||
| 324 | case I2C_SMBUS_BLOCK_DATA: | 382 | case I2C_SMBUS_BLOCK_DATA: |
| 325 | case I2C_SMBUS_BLOCK_PROC_CALL: | 383 | case I2C_SMBUS_BLOCK_PROC_CALL: |
| 326 | amd_ec_read(smbus, AMD_SMB_BCNT, &len); | 384 | status = amd_ec_read(smbus, AMD_SMB_BCNT, &len); |
| 385 | if (status) | ||
| 386 | return status; | ||
| 327 | len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX); | 387 | len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX); |
| 328 | case I2C_SMBUS_I2C_BLOCK_DATA: | 388 | case I2C_SMBUS_I2C_BLOCK_DATA: |
| 329 | for (i = 0; i < len; i++) | 389 | for (i = 0; i < len; i++) { |
| 330 | amd_ec_read(smbus, AMD_SMB_DATA + i, | 390 | status = amd_ec_read(smbus, AMD_SMB_DATA + i, |
| 331 | data->block + i + 1); | 391 | data->block + i + 1); |
| 392 | if (status) | ||
| 393 | return status; | ||
| 394 | } | ||
| 332 | data->block[0] = len; | 395 | data->block[0] = len; |
| 333 | break; | 396 | break; |
| 334 | } | 397 | } |
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c index 89eedf45d30e..6e3c38240336 100644 --- a/drivers/i2c/busses/i2c-ibm_iic.c +++ b/drivers/i2c/busses/i2c-ibm_iic.c | |||
| @@ -41,7 +41,6 @@ | |||
| 41 | #include <asm/irq.h> | 41 | #include <asm/irq.h> |
| 42 | #include <linux/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 | ||
diff --git a/drivers/i2c/busses/i2c-nuc900.c b/drivers/i2c/busses/i2c-nuc900.c index 92d770d7bbc2..72434263787b 100644 --- a/drivers/i2c/busses/i2c-nuc900.c +++ b/drivers/i2c/busses/i2c-nuc900.c | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 17 | 17 | ||
| 18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
| 19 | #include <linux/i2c-id.h> | ||
| 20 | #include <linux/init.h> | 19 | #include <linux/init.h> |
| 21 | #include <linux/time.h> | 20 | #include <linux/time.h> |
| 22 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c index 5f6d7f89e225..ace67995d7de 100644 --- a/drivers/i2c/busses/i2c-pca-platform.c +++ b/drivers/i2c/busses/i2c-pca-platform.c | |||
| @@ -224,7 +224,7 @@ static int __devinit i2c_pca_pf_probe(struct platform_device *pdev) | |||
| 224 | 224 | ||
| 225 | if (irq) { | 225 | if (irq) { |
| 226 | ret = request_irq(irq, i2c_pca_pf_handler, | 226 | ret = request_irq(irq, i2c_pca_pf_handler, |
| 227 | IRQF_TRIGGER_FALLING, i2c->adap.name, i2c); | 227 | IRQF_TRIGGER_FALLING, pdev->name, i2c); |
| 228 | if (ret) | 228 | if (ret) |
| 229 | goto e_reqirq; | 229 | goto e_reqirq; |
| 230 | } | 230 | } |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index c94e51b2651e..f4c19a97e0b3 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
| @@ -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> |
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index bf831bf81587..6a292ea5e35c 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> |
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 4c6fff5f330d..0b012f1f8ac5 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c | |||
| @@ -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 */ |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index bea4c5021d26..d231f683f576 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
| @@ -425,14 +425,14 @@ static int __i2c_check_addr_busy(struct device *dev, void *addrp) | |||
| 425 | /* walk up mux tree */ | 425 | /* walk up mux tree */ |
| 426 | static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) | 426 | static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) |
| 427 | { | 427 | { |
| 428 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
| 428 | int result; | 429 | int result; |
| 429 | 430 | ||
| 430 | result = device_for_each_child(&adapter->dev, &addr, | 431 | result = device_for_each_child(&adapter->dev, &addr, |
| 431 | __i2c_check_addr_busy); | 432 | __i2c_check_addr_busy); |
| 432 | 433 | ||
| 433 | if (!result && i2c_parent_is_i2c_adapter(adapter)) | 434 | if (!result && parent) |
| 434 | result = i2c_check_mux_parents( | 435 | result = i2c_check_mux_parents(parent, addr); |
| 435 | to_i2c_adapter(adapter->dev.parent), addr); | ||
| 436 | 436 | ||
| 437 | return result; | 437 | return result; |
| 438 | } | 438 | } |
| @@ -453,11 +453,11 @@ static int i2c_check_mux_children(struct device *dev, void *addrp) | |||
| 453 | 453 | ||
| 454 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) | 454 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) |
| 455 | { | 455 | { |
| 456 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
| 456 | int result = 0; | 457 | int result = 0; |
| 457 | 458 | ||
| 458 | if (i2c_parent_is_i2c_adapter(adapter)) | 459 | if (parent) |
| 459 | result = i2c_check_mux_parents( | 460 | result = i2c_check_mux_parents(parent, addr); |
| 460 | to_i2c_adapter(adapter->dev.parent), addr); | ||
| 461 | 461 | ||
| 462 | if (!result) | 462 | if (!result) |
| 463 | result = device_for_each_child(&adapter->dev, &addr, | 463 | result = device_for_each_child(&adapter->dev, &addr, |
| @@ -472,8 +472,10 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) | |||
| 472 | */ | 472 | */ |
| 473 | void i2c_lock_adapter(struct i2c_adapter *adapter) | 473 | void i2c_lock_adapter(struct i2c_adapter *adapter) |
| 474 | { | 474 | { |
| 475 | if (i2c_parent_is_i2c_adapter(adapter)) | 475 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
| 476 | i2c_lock_adapter(to_i2c_adapter(adapter->dev.parent)); | 476 | |
| 477 | if (parent) | ||
| 478 | i2c_lock_adapter(parent); | ||
| 477 | else | 479 | else |
| 478 | rt_mutex_lock(&adapter->bus_lock); | 480 | rt_mutex_lock(&adapter->bus_lock); |
| 479 | } | 481 | } |
| @@ -485,8 +487,10 @@ EXPORT_SYMBOL_GPL(i2c_lock_adapter); | |||
| 485 | */ | 487 | */ |
| 486 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) | 488 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) |
| 487 | { | 489 | { |
| 488 | if (i2c_parent_is_i2c_adapter(adapter)) | 490 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
| 489 | return i2c_trylock_adapter(to_i2c_adapter(adapter->dev.parent)); | 491 | |
| 492 | if (parent) | ||
| 493 | return i2c_trylock_adapter(parent); | ||
| 490 | else | 494 | else |
| 491 | return rt_mutex_trylock(&adapter->bus_lock); | 495 | return rt_mutex_trylock(&adapter->bus_lock); |
| 492 | } | 496 | } |
| @@ -497,8 +501,10 @@ static int i2c_trylock_adapter(struct i2c_adapter *adapter) | |||
| 497 | */ | 501 | */ |
| 498 | void i2c_unlock_adapter(struct i2c_adapter *adapter) | 502 | void i2c_unlock_adapter(struct i2c_adapter *adapter) |
| 499 | { | 503 | { |
| 500 | if (i2c_parent_is_i2c_adapter(adapter)) | 504 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); |
| 501 | i2c_unlock_adapter(to_i2c_adapter(adapter->dev.parent)); | 505 | |
| 506 | if (parent) | ||
| 507 | i2c_unlock_adapter(parent); | ||
| 502 | else | 508 | else |
| 503 | rt_mutex_unlock(&adapter->bus_lock); | 509 | rt_mutex_unlock(&adapter->bus_lock); |
| 504 | } | 510 | } |
| @@ -677,8 +683,6 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | |||
| 677 | char *blank, end; | 683 | char *blank, end; |
| 678 | int res; | 684 | int res; |
| 679 | 685 | ||
| 680 | dev_warn(dev, "The new_device interface is still experimental " | ||
| 681 | "and may change in a near future\n"); | ||
| 682 | memset(&info, 0, sizeof(struct i2c_board_info)); | 686 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 683 | 687 | ||
| 684 | blank = strchr(buf, ' '); | 688 | blank = strchr(buf, ' '); |
| @@ -1504,26 +1508,25 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) | |||
| 1504 | if (!driver->detect || !address_list) | 1508 | if (!driver->detect || !address_list) |
| 1505 | return 0; | 1509 | return 0; |
| 1506 | 1510 | ||
| 1511 | /* Stop here if the classes do not match */ | ||
| 1512 | if (!(adapter->class & driver->class)) | ||
| 1513 | return 0; | ||
| 1514 | |||
| 1507 | /* Set up a temporary client to help detect callback */ | 1515 | /* Set up a temporary client to help detect callback */ |
| 1508 | temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | 1516 | temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); |
| 1509 | if (!temp_client) | 1517 | if (!temp_client) |
| 1510 | return -ENOMEM; | 1518 | return -ENOMEM; |
| 1511 | temp_client->adapter = adapter; | 1519 | temp_client->adapter = adapter; |
| 1512 | 1520 | ||
| 1513 | /* Stop here if the classes do not match */ | ||
| 1514 | if (!(adapter->class & driver->class)) | ||
| 1515 | goto exit_free; | ||
| 1516 | |||
| 1517 | for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { | 1521 | for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { |
| 1518 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " | 1522 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " |
| 1519 | "addr 0x%02x\n", adap_id, address_list[i]); | 1523 | "addr 0x%02x\n", adap_id, address_list[i]); |
| 1520 | temp_client->addr = address_list[i]; | 1524 | temp_client->addr = address_list[i]; |
| 1521 | err = i2c_detect_address(temp_client, driver); | 1525 | err = i2c_detect_address(temp_client, driver); |
| 1522 | if (err) | 1526 | if (unlikely(err)) |
| 1523 | goto exit_free; | 1527 | break; |
| 1524 | } | 1528 | } |
| 1525 | 1529 | ||
| 1526 | exit_free: | ||
| 1527 | kfree(temp_client); | 1530 | kfree(temp_client); |
| 1528 | return err; | 1531 | return err; |
| 1529 | } | 1532 | } |
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 5f3a52d517c3..cec0f3ba97f8 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
| @@ -192,13 +192,12 @@ static int i2cdev_check(struct device *dev, void *addrp) | |||
| 192 | /* walk up mux tree */ | 192 | /* walk up mux tree */ |
| 193 | static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr) | 193 | static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr) |
| 194 | { | 194 | { |
| 195 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
| 195 | int result; | 196 | int result; |
| 196 | 197 | ||
| 197 | result = device_for_each_child(&adapter->dev, &addr, i2cdev_check); | 198 | result = device_for_each_child(&adapter->dev, &addr, i2cdev_check); |
| 198 | 199 | if (!result && parent) | |
| 199 | if (!result && i2c_parent_is_i2c_adapter(adapter)) | 200 | result = i2cdev_check_mux_parents(parent, addr); |
| 200 | result = i2cdev_check_mux_parents( | ||
| 201 | to_i2c_adapter(adapter->dev.parent), addr); | ||
| 202 | 201 | ||
| 203 | return result; | 202 | return result; |
| 204 | } | 203 | } |
| @@ -222,11 +221,11 @@ static int i2cdev_check_mux_children(struct device *dev, void *addrp) | |||
| 222 | driver bound to it, as NOT busy. */ | 221 | driver bound to it, as NOT busy. */ |
| 223 | 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) |
| 224 | { | 223 | { |
| 224 | struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); | ||
| 225 | int result = 0; | 225 | int result = 0; |
| 226 | 226 | ||
| 227 | if (i2c_parent_is_i2c_adapter(adapter)) | 227 | if (parent) |
| 228 | result = i2cdev_check_mux_parents( | 228 | result = i2cdev_check_mux_parents(parent, addr); |
| 229 | to_i2c_adapter(adapter->dev.parent), addr); | ||
| 230 | 229 | ||
| 231 | if (!result) | 230 | if (!result) |
| 232 | result = device_for_each_child(&adapter->dev, &addr, | 231 | result = device_for_each_child(&adapter->dev, &addr, |
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index 4c9a99c4fcb0..4d91d80bfd23 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig | |||
| @@ -5,6 +5,16 @@ | |||
| 5 | menu "Multiplexer I2C Chip support" | 5 | menu "Multiplexer I2C Chip support" |
| 6 | depends on I2C_MUX | 6 | depends on I2C_MUX |
| 7 | 7 | ||
| 8 | config I2C_MUX_PCA9541 | ||
| 9 | tristate "NXP PCA9541 I2C Master Selector" | ||
| 10 | depends on EXPERIMENTAL | ||
| 11 | help | ||
| 12 | If you say yes here you get support for the NXP PCA9541 | ||
| 13 | I2C Master Selector. | ||
| 14 | |||
| 15 | This driver can also be built as a module. If so, the module | ||
| 16 | will be called pca9541. | ||
| 17 | |||
| 8 | config I2C_MUX_PCA954x | 18 | config I2C_MUX_PCA954x |
| 9 | tristate "Philips PCA954x I2C Mux/switches" | 19 | tristate "Philips PCA954x I2C Mux/switches" |
| 10 | depends on EXPERIMENTAL | 20 | depends on EXPERIMENTAL |
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile index bd83b5274815..d743806d9b42 100644 --- a/drivers/i2c/muxes/Makefile +++ b/drivers/i2c/muxes/Makefile | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | # | 1 | # |
| 2 | # Makefile for multiplexer I2C chip drivers. | 2 | # Makefile for multiplexer I2C chip drivers. |
| 3 | 3 | ||
| 4 | obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o | ||
| 4 | obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o | 5 | obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o |
| 5 | 6 | ||
| 6 | ifeq ($(CONFIG_I2C_DEBUG_BUS),y) | 7 | ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG |
| 7 | EXTRA_CFLAGS += -DDEBUG | ||
| 8 | endif | ||
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 index 6f9accf3189d..54e1ce73534b 100644 --- a/drivers/i2c/muxes/pca954x.c +++ b/drivers/i2c/muxes/pca954x.c | |||
| @@ -181,8 +181,8 @@ static int pca954x_deselect_mux(struct i2c_adapter *adap, | |||
| 181 | /* | 181 | /* |
| 182 | * I2C init/probing/exit functions | 182 | * I2C init/probing/exit functions |
| 183 | */ | 183 | */ |
| 184 | static int __devinit pca954x_probe(struct i2c_client *client, | 184 | static int pca954x_probe(struct i2c_client *client, |
| 185 | const struct i2c_device_id *id) | 185 | const struct i2c_device_id *id) |
| 186 | { | 186 | { |
| 187 | struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); | 187 | struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); |
| 188 | struct pca954x_platform_data *pdata = client->dev.platform_data; | 188 | struct pca954x_platform_data *pdata = client->dev.platform_data; |
| @@ -255,7 +255,7 @@ err: | |||
| 255 | return ret; | 255 | return ret; |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | static int __devexit pca954x_remove(struct i2c_client *client) | 258 | static int pca954x_remove(struct i2c_client *client) |
| 259 | { | 259 | { |
| 260 | struct pca954x *data = i2c_get_clientdata(client); | 260 | struct pca954x *data = i2c_get_clientdata(client); |
| 261 | const struct chip_desc *chip = &chips[data->type]; | 261 | const struct chip_desc *chip = &chips[data->type]; |
| @@ -279,7 +279,7 @@ static struct i2c_driver pca954x_driver = { | |||
| 279 | .owner = THIS_MODULE, | 279 | .owner = THIS_MODULE, |
| 280 | }, | 280 | }, |
| 281 | .probe = pca954x_probe, | 281 | .probe = pca954x_probe, |
| 282 | .remove = __devexit_p(pca954x_remove), | 282 | .remove = pca954x_remove, |
| 283 | .id_table = pca954x_id, | 283 | .id_table = pca954x_id, |
| 284 | }; | 284 | }; |
| 285 | 285 | ||
diff --git a/drivers/video/aty/radeon_i2c.c b/drivers/video/aty/radeon_i2c.c index 359fc64e761a..78d1f4cd1fe0 100644 --- a/drivers/video/aty/radeon_i2c.c +++ b/drivers/video/aty/radeon_i2c.c | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | #include <linux/i2c.h> | 9 | #include <linux/i2c.h> |
| 10 | #include <linux/i2c-id.h> | ||
| 11 | #include <linux/i2c-algo-bit.h> | 10 | #include <linux/i2c-algo-bit.h> |
| 12 | 11 | ||
| 13 | #include <asm/io.h> | 12 | #include <asm/io.h> |
diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h index 328ae6c673ec..f37de60ecc59 100644 --- a/drivers/video/i810/i810.h +++ b/drivers/video/i810/i810.h | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include <linux/agp_backend.h> | 17 | #include <linux/agp_backend.h> |
| 18 | #include <linux/fb.h> | 18 | #include <linux/fb.h> |
| 19 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
| 20 | #include <linux/i2c-id.h> | ||
| 21 | #include <linux/i2c-algo-bit.h> | 20 | #include <linux/i2c-algo-bit.h> |
| 22 | #include <video/vga.h> | 21 | #include <video/vga.h> |
| 23 | 22 | ||
diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c index 487f2be47460..3300bd31d9d7 100644 --- a/drivers/video/intelfb/intelfb_i2c.c +++ b/drivers/video/intelfb/intelfb_i2c.c | |||
| @@ -32,7 +32,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
| 32 | #include <linux/fb.h> | 32 | #include <linux/fb.h> |
| 33 | 33 | ||
| 34 | #include <linux/i2c.h> | 34 | #include <linux/i2c.h> |
| 35 | #include <linux/i2c-id.h> | ||
| 36 | #include <linux/i2c-algo-bit.h> | 35 | #include <linux/i2c-algo-bit.h> |
| 37 | 36 | ||
| 38 | #include <asm/io.h> | 37 | #include <asm/io.h> |
diff --git a/drivers/video/savage/savagefb.h b/drivers/video/savage/savagefb.h index 8bfdfc3c5234..e4c3f214eb8e 100644 --- a/drivers/video/savage/savagefb.h +++ b/drivers/video/savage/savagefb.h | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | #define __SAVAGEFB_H__ | 13 | #define __SAVAGEFB_H__ |
| 14 | 14 | ||
| 15 | #include <linux/i2c.h> | 15 | #include <linux/i2c.h> |
| 16 | #include <linux/i2c-id.h> | ||
| 17 | #include <linux/i2c-algo-bit.h> | 16 | #include <linux/i2c-algo-bit.h> |
| 18 | #include <linux/mutex.h> | 17 | #include <linux/mutex.h> |
| 19 | #include <video/vga.h> | 18 | #include <video/vga.h> |
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 4bae0b72ed3c..1f66fa06a97c 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
| @@ -384,11 +384,15 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data) | |||
| 384 | dev_set_drvdata(&dev->dev, data); | 384 | dev_set_drvdata(&dev->dev, data); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | static inline int i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter) | 387 | static inline struct i2c_adapter * |
| 388 | i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter) | ||
| 388 | { | 389 | { |
| 389 | return adapter->dev.parent != NULL | 390 | struct device *parent = adapter->dev.parent; |
| 390 | && adapter->dev.parent->bus == &i2c_bus_type | 391 | |
| 391 | && adapter->dev.parent->type == &i2c_adapter_type; | 392 | if (parent != NULL && parent->type == &i2c_adapter_type) |
| 393 | return to_i2c_adapter(parent); | ||
| 394 | else | ||
| 395 | return NULL; | ||
| 392 | } | 396 | } |
| 393 | 397 | ||
| 394 | /* Adapter locking functions, exported for shared pin cases */ | 398 | /* Adapter locking functions, exported for shared pin cases */ |
