Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: mux: pca954x: support property idle-state

This supports property idle-state,if present,
overrides i2c-mux-idle-disconnect.

My use cases:
- Use the property idle-state to fix
an errata on LS2085ARDB and LS2088ARDB.
- Errata id: E-00013(board LS2085ARDB and
LS2088ARDB revision on Rev.B, Rev.C and Rev.D).
- About E-00013:
- Description: I2C1 and I2C3 buses
are missing pull-up.
- Impact: When the PCA954x device is tri-stated, the I2C bus
will float. This makes the I2C bus and its associated
downstream devices inaccessible.
- Hardware fix: Populate resistors R189 and R190 for I2C1
and resistors R228 and R229 for I2C3.
- Software fix: Remove the tri-state option from the PCA954x
driver(PCA954x always on enable status, specify a
channel zero in dts to fix the errata E-00013).

Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: Biwen Li <biwen.li@nxp.com>
Signed-off-by: Peter Rosin <peda@axentia.se>

authored by

Biwen Li and committed by
Peter Rosin
e65e228e 0d1569a7

+46 -23
+46 -23
drivers/i2c/muxes/i2c-mux-pca954x.c
··· 86 86 87 87 u8 last_chan; /* last register value */ 88 88 /* MUX_IDLE_AS_IS, MUX_IDLE_DISCONNECT or >= 0 for channel */ 89 - s8 idle_state; 89 + s32 idle_state; 90 90 91 91 struct i2c_client *client; 92 92 ··· 229 229 I2C_SMBUS_BYTE, &dummy); 230 230 } 231 231 232 + static u8 pca954x_regval(struct pca954x *data, u8 chan) 233 + { 234 + /* We make switches look like muxes, not sure how to be smarter. */ 235 + if (data->chip->muxtype == pca954x_ismux) 236 + return chan | data->chip->enable; 237 + else 238 + return 1 << chan; 239 + } 240 + 232 241 static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan) 233 242 { 234 243 struct pca954x *data = i2c_mux_priv(muxc); 235 244 struct i2c_client *client = data->client; 236 - const struct chip_desc *chip = data->chip; 237 245 u8 regval; 238 246 int ret = 0; 239 247 240 - /* we make switches look like muxes, not sure how to be smarter */ 241 - if (chip->muxtype == pca954x_ismux) 242 - regval = chan | chip->enable; 243 - else 244 - regval = 1 << chan; 245 - 248 + regval = pca954x_regval(data, chan); 246 249 /* Only select the channel if its different from the last channel */ 247 250 if (data->last_chan != regval) { 248 251 ret = pca954x_reg_write(muxc->parent, client, regval); ··· 259 256 { 260 257 struct pca954x *data = i2c_mux_priv(muxc); 261 258 struct i2c_client *client = data->client; 262 - s8 idle_state; 259 + s32 idle_state; 263 260 264 261 idle_state = READ_ONCE(data->idle_state); 265 262 if (idle_state >= 0) ··· 405 402 i2c_mux_del_adapters(muxc); 406 403 } 407 404 405 + static int pca954x_init(struct i2c_client *client, struct pca954x *data) 406 + { 407 + int ret; 408 + 409 + if (data->idle_state >= 0) 410 + data->last_chan = pca954x_regval(data, data->idle_state); 411 + else 412 + data->last_chan = 0; /* Disconnect multiplexer */ 413 + 414 + ret = i2c_smbus_write_byte(client, data->last_chan); 415 + if (ret < 0) 416 + data->last_chan = 0; 417 + 418 + return ret; 419 + } 420 + 408 421 /* 409 422 * I2C init/probing/exit functions 410 423 */ ··· 430 411 struct i2c_adapter *adap = client->adapter; 431 412 struct device *dev = &client->dev; 432 413 struct device_node *np = dev->of_node; 433 - bool idle_disconnect_dt; 434 414 struct gpio_desc *gpio; 435 415 struct i2c_mux_core *muxc; 436 416 struct pca954x *data; ··· 480 462 } 481 463 } 482 464 483 - /* Write the mux register at addr to verify 465 + data->idle_state = MUX_IDLE_AS_IS; 466 + if (of_property_read_u32(np, "idle-state", &data->idle_state)) { 467 + if (np && of_property_read_bool(np, "i2c-mux-idle-disconnect")) 468 + data->idle_state = MUX_IDLE_DISCONNECT; 469 + } 470 + 471 + /* 472 + * Write the mux register at addr to verify 484 473 * that the mux is in fact present. This also 485 - * initializes the mux to disconnected state. 474 + * initializes the mux to a channel 475 + * or disconnected state. 486 476 */ 487 - if (i2c_smbus_write_byte(client, 0) < 0) { 477 + ret = pca954x_init(client, data); 478 + if (ret < 0) { 488 479 dev_warn(dev, "probe failed\n"); 489 480 return -ENODEV; 490 481 } 491 - 492 - data->last_chan = 0; /* force the first selection */ 493 - data->idle_state = MUX_IDLE_AS_IS; 494 - 495 - idle_disconnect_dt = np && 496 - of_property_read_bool(np, "i2c-mux-idle-disconnect"); 497 - if (idle_disconnect_dt) 498 - data->idle_state = MUX_IDLE_DISCONNECT; 499 482 500 483 ret = pca954x_irq_setup(muxc); 501 484 if (ret) ··· 549 530 struct i2c_client *client = to_i2c_client(dev); 550 531 struct i2c_mux_core *muxc = i2c_get_clientdata(client); 551 532 struct pca954x *data = i2c_mux_priv(muxc); 533 + int ret; 552 534 553 - data->last_chan = 0; 554 - return i2c_smbus_write_byte(client, 0); 535 + ret = pca954x_init(client, data); 536 + if (ret < 0) 537 + dev_err(&client->dev, "failed to verify mux presence\n"); 538 + 539 + return ret; 555 540 } 556 541 #endif 557 542