8233-i2c-pca954x-Add-option-to-skip-disabling-PCA954x-Mux.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From a4be9046c3a3fc39a06089553df8cc19a2abd814 Mon Sep 17 00:00:00 2001
  2. From: Priyanka Jain <Priyanka.Jain@freescale.com>
  3. Date: Tue, 3 Nov 2015 11:25:24 +0530
  4. Subject: [PATCH 233/238] i2c: pca954x: Add option to skip disabling PCA954x
  5. Mux device
  6. On some Layerscape boards like LS2085ARDB/LS2080ARDB,
  7. input pull-up resistors on PCA954x Mux device are
  8. missing on board. So, if mux are disabled after powered-on,
  9. input lines will float leading to incorrect functionality.
  10. Hence, PCA954x Mux device should never be turned-off after
  11. power-on.
  12. Add option to skip disabling PCA954x Mux device
  13. if device tree contians "i2c-mux-never-disable" property
  14. for pca954x device node.
  15. Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com>
  16. ---
  17. drivers/i2c/muxes/i2c-mux-pca954x.c | 38 +++++++++++++++++++++++++++++++++++
  18. 1 file changed, 38 insertions(+)
  19. --- a/drivers/i2c/muxes/i2c-mux-pca954x.c
  20. +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
  21. @@ -63,6 +63,7 @@ struct pca954x {
  22. struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS];
  23. u8 last_chan; /* last register value */
  24. + u8 disable_mux; /* do not disable mux if val not 0 */
  25. };
  26. struct chip_desc {
  27. @@ -174,6 +175,13 @@ static int pca954x_deselect_mux(struct i
  28. {
  29. struct pca954x *data = i2c_get_clientdata(client);
  30. +#ifdef CONFIG_ARCH_LAYERSCAPE
  31. + if (data->disable_mux != 0)
  32. + data->last_chan = chips[data->type].nchans;
  33. + else
  34. + data->last_chan = 0;
  35. + return pca954x_reg_write(adap, client, data->disable_mux);
  36. +#endif
  37. /* Deselect active channel */
  38. data->last_chan = 0;
  39. return pca954x_reg_write(adap, client, data->last_chan);
  40. @@ -201,6 +209,23 @@ static int pca954x_probe(struct i2c_clie
  41. if (!data)
  42. return -ENOMEM;
  43. +#ifdef CONFIG_ARCH_LAYERSCAPE
  44. + /* The point here is that you must not disable a mux if there
  45. + * are no pullups on the input or you mess up the I2C. This
  46. + * needs to be put into the DTS really as the kernel cannot
  47. + * know this otherwise.
  48. + */
  49. + data->type = id->driver_data;
  50. + data->disable_mux = of_node &&
  51. + of_property_read_bool(of_node, "i2c-mux-never-disable") &&
  52. + chips[data->type].muxtype == pca954x_ismux ?
  53. + chips[data->type].enable : 0;
  54. + /* force the first selection */
  55. + if (data->disable_mux != 0)
  56. + data->last_chan = chips[data->type].nchans;
  57. + else
  58. + data->last_chan = 0;
  59. +#endif
  60. i2c_set_clientdata(client, data);
  61. /* Get the mux out of reset if a reset GPIO is specified. */
  62. @@ -212,13 +237,19 @@ static int pca954x_probe(struct i2c_clie
  63. * that the mux is in fact present. This also
  64. * initializes the mux to disconnected state.
  65. */
  66. +#ifdef CONFIG_ARCH_LAYERSCAPE
  67. + if (i2c_smbus_write_byte(client, data->disable_mux) < 0) {
  68. +#else
  69. if (i2c_smbus_write_byte(client, 0) < 0) {
  70. +#endif
  71. dev_warn(&client->dev, "probe failed\n");
  72. return -ENODEV;
  73. }
  74. +#ifndef CONFIG_ARCH_LAYERSCAPE
  75. data->type = id->driver_data;
  76. data->last_chan = 0; /* force the first selection */
  77. +#endif
  78. idle_disconnect_dt = of_node &&
  79. of_property_read_bool(of_node, "i2c-mux-idle-disconnect");
  80. @@ -289,6 +320,13 @@ static int pca954x_resume(struct device
  81. struct i2c_client *client = to_i2c_client(dev);
  82. struct pca954x *data = i2c_get_clientdata(client);
  83. +#ifdef CONFIG_ARCH_LAYERSCAPE
  84. + if (data->disable_mux != 0)
  85. + data->last_chan = chips[data->type].nchans;
  86. + else
  87. + data->last_chan = 0;
  88. + return i2c_smbus_write_byte(client, data->disable_mux);
  89. +#endif
  90. data->last_chan = 0;
  91. return i2c_smbus_write_byte(client, 0);
  92. }