diff mbox

[U-Boot,v4,4/7] drivers/i2c/muxes/pca954x: Add pca9547 I2C mux support

Message ID 20170609172845.10238-5-marek.behun@nic.cz
State Awaiting Upstream
Delegated to: Stefan Roese
Headers show

Commit Message

Marek BehĂșn June 9, 2017, 5:28 p.m. UTC
This I2C mux is found, for example, on the Turris Omnia board.

Signed-off-by: Marek Behun <marek.behun@nic.cz>
Reviewed-by: Heiko Schocher <hs@denx.de>

Comments

Chris Packham Sept. 28, 2017, 9:27 p.m. UTC | #1
Hi All,

On Sat, Jun 10, 2017 at 5:28 AM, Marek BehĂșn <marek.behun@nic.cz> wrote:
> This I2C mux is found, for example, on the Turris Omnia board.
>
> Signed-off-by: Marek Behun <marek.behun@nic.cz>
> Reviewed-by: Heiko Schocher <hs@denx.de>
>
> diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c
> index 1a6761858c..383f72f552 100644
> --- a/drivers/i2c/muxes/pca954x.c
> +++ b/drivers/i2c/muxes/pca954x.c
> @@ -13,11 +13,40 @@
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> +enum pca_type {
> +       PCA9544,
> +       PCA9547,
> +       PCA9548
> +};
> +
> +struct chip_desc {
> +       u8 enable;
> +       enum muxtype {
> +               pca954x_ismux = 0,
> +               pca954x_isswi,
> +       } muxtype;
> +};
> +
>  struct pca954x_priv {
>         u32 addr; /* I2C mux address */
>         u32 width; /* I2C mux width - number of busses */
>  };
>
> +static const struct chip_desc chips[] = {
> +       [PCA9544] = {
> +               .enable = 0x4,
> +               .muxtype = pca954x_ismux,
> +       },
> +       [PCA9547] = {
> +               .enable = 0x8,
> +               .muxtype = pca954x_ismux,
> +       },
> +       [PCA9548] = {
> +               .enable = 0x8,
> +               .muxtype = pca954x_isswi,
> +       },
> +};
> +
>  static int pca954x_deselect(struct udevice *mux, struct udevice *bus,
>                             uint channel)
>  {
> @@ -31,7 +60,13 @@ static int pca954x_select(struct udevice *mux, struct udevice *bus,
>                           uint channel)
>  {
>         struct pca954x_priv *priv = dev_get_priv(mux);
> -       uchar byte = 1 << channel;
> +       const struct chip_desc *chip = &chips[dev_get_driver_data(mux)];
> +       uchar byte;
> +
> +       if (chip->muxtype == pca954x_ismux)
> +               byte = channel | chip->enable;
> +       else
> +               byte = 1 << channel;
>
>         return dm_i2c_write(mux, priv->addr, &byte, 1);
>  }
> @@ -42,8 +77,9 @@ static const struct i2c_mux_ops pca954x_ops = {
>  };
>
>  static const struct udevice_id pca954x_ids[] = {
> -       { .compatible = "nxp,pca9548", .data = (ulong)8 },
> -       { .compatible = "nxp,pca9544", .data = (ulong)4 },
> +       { .compatible = "nxp,pca9544", .data = PCA9544 },
> +       { .compatible = "nxp,pca9547", .data = PCA9547 },
> +       { .compatible = "nxp,pca9548", .data = PCA9548 },
>         { }
>  };
>

I think this actually breaks this driver. The problem is in
pca954x_ofdata_to_platdata() where it does

    priv->width = dev_get_driver_data(dev);

Which is now not the width but one of the enum values. It would work
for 9457 or 9548 but I happen to be using a9544 which is 0 in the
enum. I'll post a patch shortly to fix this.
diff mbox

Patch

diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c
index 1a6761858c..383f72f552 100644
--- a/drivers/i2c/muxes/pca954x.c
+++ b/drivers/i2c/muxes/pca954x.c
@@ -13,11 +13,40 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
+enum pca_type {
+	PCA9544,
+	PCA9547,
+	PCA9548
+};
+
+struct chip_desc {
+	u8 enable;
+	enum muxtype {
+		pca954x_ismux = 0,
+		pca954x_isswi,
+	} muxtype;
+};
+
 struct pca954x_priv {
 	u32 addr; /* I2C mux address */
 	u32 width; /* I2C mux width - number of busses */
 };
 
+static const struct chip_desc chips[] = {
+	[PCA9544] = {
+		.enable = 0x4,
+		.muxtype = pca954x_ismux,
+	},
+	[PCA9547] = {
+		.enable = 0x8,
+		.muxtype = pca954x_ismux,
+	},
+	[PCA9548] = {
+		.enable = 0x8,
+		.muxtype = pca954x_isswi,
+	},
+};
+
 static int pca954x_deselect(struct udevice *mux, struct udevice *bus,
 			    uint channel)
 {
@@ -31,7 +60,13 @@  static int pca954x_select(struct udevice *mux, struct udevice *bus,
 			  uint channel)
 {
 	struct pca954x_priv *priv = dev_get_priv(mux);
-	uchar byte = 1 << channel;
+	const struct chip_desc *chip = &chips[dev_get_driver_data(mux)];
+	uchar byte;
+
+	if (chip->muxtype == pca954x_ismux)
+		byte = channel | chip->enable;
+	else
+		byte = 1 << channel;
 
 	return dm_i2c_write(mux, priv->addr, &byte, 1);
 }
@@ -42,8 +77,9 @@  static const struct i2c_mux_ops pca954x_ops = {
 };
 
 static const struct udevice_id pca954x_ids[] = {
-	{ .compatible = "nxp,pca9548", .data = (ulong)8 },
-	{ .compatible = "nxp,pca9544", .data = (ulong)4 },
+	{ .compatible = "nxp,pca9544", .data = PCA9544 },
+	{ .compatible = "nxp,pca9547", .data = PCA9547 },
+	{ .compatible = "nxp,pca9548", .data = PCA9548 },
 	{ }
 };