1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 - 2016 Xilinx, Inc.
4 * Copyright (C) 2017 National Instruments Corp
5 * Written by Michal Simek
14 #include <asm/global_data.h>
16 #include <asm-generic/gpio.h>
18 DECLARE_GLOBAL_DATA_PTR;
30 u8 enable; /* Enable mask in ctl register (used for muxes only) */
39 u32 addr; /* I2C mux address */
40 u32 width; /* I2C mux width - number of busses */
41 struct gpio_desc gpio_mux_reset;
44 static const struct chip_desc chips[] = {
46 .muxtype = pca954x_isswi,
51 .muxtype = pca954x_ismux,
55 .muxtype = pca954x_isswi,
60 .muxtype = pca954x_ismux,
64 .muxtype = pca954x_isswi,
68 .muxtype = pca954x_isswi,
73 static int pca954x_deselect(struct udevice *mux, struct udevice *bus,
76 struct pca954x_priv *priv = dev_get_priv(mux);
79 return dm_i2c_write(mux, priv->addr, &byte, 1);
82 static int pca954x_select(struct udevice *mux, struct udevice *bus,
85 struct pca954x_priv *priv = dev_get_priv(mux);
86 const struct chip_desc *chip = &chips[dev_get_driver_data(mux)];
89 if (chip->muxtype == pca954x_ismux)
90 byte = channel | chip->enable;
94 return dm_i2c_write(mux, priv->addr, &byte, 1);
97 static const struct i2c_mux_ops pca954x_ops = {
98 .select = pca954x_select,
99 .deselect = pca954x_deselect,
102 static const struct udevice_id pca954x_ids[] = {
103 { .compatible = "nxp,pca9543", .data = PCA9543 },
104 { .compatible = "nxp,pca9544", .data = PCA9544 },
105 { .compatible = "nxp,pca9546", .data = PCA9546 },
106 { .compatible = "nxp,pca9547", .data = PCA9547 },
107 { .compatible = "nxp,pca9548", .data = PCA9548 },
108 { .compatible = "nxp,pca9646", .data = PCA9646 },
112 static int pca954x_of_to_plat(struct udevice *dev)
114 struct pca954x_priv *priv = dev_get_priv(dev);
115 const struct chip_desc *chip = &chips[dev_get_driver_data(dev)];
117 priv->addr = dev_read_u32_default(dev, "reg", 0);
119 debug("MUX not found\n");
122 priv->width = chip->width;
125 debug("No I2C MUX width specified\n");
129 debug("Device %s at 0x%x with width %d\n",
130 dev->name, priv->addr, priv->width);
135 static int pca954x_probe(struct udevice *dev)
137 if (CONFIG_IS_ENABLED(DM_GPIO)) {
138 struct pca954x_priv *priv = dev_get_priv(dev);
141 err = gpio_request_by_name(dev, "reset-gpios", 0,
142 &priv->gpio_mux_reset, GPIOD_IS_OUT);
144 /* it's optional so only bail if we get a real error */
145 if (err && (err != -ENOENT))
148 /* dm will take care of polarity */
149 if (dm_gpio_is_valid(&priv->gpio_mux_reset))
150 dm_gpio_set_value(&priv->gpio_mux_reset, 0);
156 static int pca954x_remove(struct udevice *dev)
158 if (CONFIG_IS_ENABLED(DM_GPIO)) {
159 struct pca954x_priv *priv = dev_get_priv(dev);
161 if (dm_gpio_is_valid(&priv->gpio_mux_reset))
162 dm_gpio_free(dev, &priv->gpio_mux_reset);
168 U_BOOT_DRIVER(pca954x) = {
170 .id = UCLASS_I2C_MUX,
171 .of_match = pca954x_ids,
172 .probe = pca954x_probe,
173 .remove = pca954x_remove,
175 .of_to_plat = pca954x_of_to_plat,
176 .priv_auto = sizeof(struct pca954x_priv),