2 * Copyright (C) 2015 - 2016 Xilinx, Inc.
3 * Written by Michal Simek
5 * SPDX-License-Identifier: GPL-2.0+
14 DECLARE_GLOBAL_DATA_PTR;
31 u32 addr; /* I2C mux address */
32 u32 width; /* I2C mux width - number of busses */
35 static const struct chip_desc chips[] = {
38 .muxtype = pca954x_ismux,
42 .muxtype = pca954x_ismux,
46 .muxtype = pca954x_isswi,
50 static int pca954x_deselect(struct udevice *mux, struct udevice *bus,
53 struct pca954x_priv *priv = dev_get_priv(mux);
56 return dm_i2c_write(mux, priv->addr, &byte, 1);
59 static int pca954x_select(struct udevice *mux, struct udevice *bus,
62 struct pca954x_priv *priv = dev_get_priv(mux);
63 const struct chip_desc *chip = &chips[dev_get_driver_data(mux)];
66 if (chip->muxtype == pca954x_ismux)
67 byte = channel | chip->enable;
71 return dm_i2c_write(mux, priv->addr, &byte, 1);
74 static const struct i2c_mux_ops pca954x_ops = {
75 .select = pca954x_select,
76 .deselect = pca954x_deselect,
79 static const struct udevice_id pca954x_ids[] = {
80 { .compatible = "nxp,pca9544", .data = PCA9544 },
81 { .compatible = "nxp,pca9547", .data = PCA9547 },
82 { .compatible = "nxp,pca9548", .data = PCA9548 },
86 static int pca954x_ofdata_to_platdata(struct udevice *dev)
88 struct pca954x_priv *priv = dev_get_priv(dev);
90 priv->addr = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "reg", 0);
92 debug("MUX not found\n");
95 priv->width = dev_get_driver_data(dev);
98 debug("No I2C MUX width specified\n");
102 debug("Device %s at 0x%x with width %d\n",
103 dev->name, priv->addr, priv->width);
108 U_BOOT_DRIVER(pca954x) = {
110 .id = UCLASS_I2C_MUX,
111 .of_match = pca954x_ids,
113 .ofdata_to_platdata = pca954x_ofdata_to_platdata,
114 .priv_auto_alloc_size = sizeof(struct pca954x_priv),