Lines Matching +full:data +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-only
9 #include <linux/i2c-mux.h>
11 #include <linux/platform_data/i2c-mux-gpio.h>
21 struct i2c_mux_gpio_platform_data data; member
23 struct gpio_desc **gpios; member
32 gpiod_set_array_value_cansleep(mux->ngpios, mux->gpios, NULL, values); in i2c_mux_gpio_set()
48 i2c_mux_gpio_set(mux, mux->data.idle); in i2c_mux_gpio_deselect()
56 struct device *dev = &pdev->dev; in i2c_mux_gpio_probe_fw()
58 struct device_node *np = dev->of_node; in i2c_mux_gpio_probe_fw()
67 return -ENODEV; in i2c_mux_gpio_probe_fw()
69 adapter_np = of_parse_phandle(np, "i2c-parent", 0); in i2c_mux_gpio_probe_fw()
71 dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); in i2c_mux_gpio_probe_fw()
72 return -ENODEV; in i2c_mux_gpio_probe_fw()
82 acpi_handle dev_handle = ACPI_HANDLE(dev->parent); in i2c_mux_gpio_probe_fw()
88 return -EPROBE_DEFER; in i2c_mux_gpio_probe_fw()
90 mux->data.parent = i2c_adapter_id(adapter); in i2c_mux_gpio_probe_fw()
91 put_device(&adapter->dev); in i2c_mux_gpio_probe_fw()
93 mux->data.n_values = device_get_child_node_count(dev); in i2c_mux_gpio_probe_fw()
95 mux->data.n_values, sizeof(*mux->data.values), in i2c_mux_gpio_probe_fw()
99 return -ENOMEM; in i2c_mux_gpio_probe_fw()
114 mux->data.values = values; in i2c_mux_gpio_probe_fw()
116 if (device_property_read_u32(dev, "idle-state", &mux->data.idle)) in i2c_mux_gpio_probe_fw()
117 mux->data.idle = I2C_MUX_GPIO_NO_IDLE; in i2c_mux_gpio_probe_fw()
131 mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); in i2c_mux_gpio_probe()
133 return -ENOMEM; in i2c_mux_gpio_probe()
135 if (!dev_get_platdata(&pdev->dev)) { in i2c_mux_gpio_probe()
140 memcpy(&mux->data, dev_get_platdata(&pdev->dev), in i2c_mux_gpio_probe()
141 sizeof(mux->data)); in i2c_mux_gpio_probe()
144 ngpios = gpiod_count(&pdev->dev, "mux"); in i2c_mux_gpio_probe()
146 dev_err(&pdev->dev, "no valid gpios provided\n"); in i2c_mux_gpio_probe()
147 return ngpios ?: -EINVAL; in i2c_mux_gpio_probe()
149 mux->ngpios = ngpios; in i2c_mux_gpio_probe()
151 parent = i2c_get_adapter(mux->data.parent); in i2c_mux_gpio_probe()
153 return -EPROBE_DEFER; in i2c_mux_gpio_probe()
155 muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, in i2c_mux_gpio_probe()
156 array_size(ngpios, sizeof(*mux->gpios)), 0, in i2c_mux_gpio_probe()
159 ret = -ENOMEM; in i2c_mux_gpio_probe()
162 mux->gpios = muxc->priv; in i2c_mux_gpio_probe()
163 muxc->priv = mux; in i2c_mux_gpio_probe()
167 root = i2c_root_adapter(&parent->dev); in i2c_mux_gpio_probe()
169 muxc->mux_locked = true; in i2c_mux_gpio_probe()
171 if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) { in i2c_mux_gpio_probe()
172 initial_state = mux->data.idle; in i2c_mux_gpio_probe()
173 muxc->deselect = i2c_mux_gpio_deselect; in i2c_mux_gpio_probe()
175 initial_state = mux->data.values[0]; in i2c_mux_gpio_probe()
187 gpiod = devm_gpiod_get_index(&pdev->dev, "mux", i, flag); in i2c_mux_gpio_probe()
193 mux->gpios[i] = gpiod; in i2c_mux_gpio_probe()
195 if (!muxc->mux_locked) in i2c_mux_gpio_probe()
199 gpio_dev = &gpiod->gdev->dev; in i2c_mux_gpio_probe()
200 muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; in i2c_mux_gpio_probe()
203 if (muxc->mux_locked) in i2c_mux_gpio_probe()
204 dev_info(&pdev->dev, "mux-locked i2c mux\n"); in i2c_mux_gpio_probe()
206 for (i = 0; i < mux->data.n_values; i++) { in i2c_mux_gpio_probe()
207 u32 nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; in i2c_mux_gpio_probe()
208 unsigned int class = mux->data.classes ? mux->data.classes[i] : 0; in i2c_mux_gpio_probe()
210 ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class); in i2c_mux_gpio_probe()
215 dev_info(&pdev->dev, "%d port mux on %s adapter\n", in i2c_mux_gpio_probe()
216 mux->data.n_values, parent->name); in i2c_mux_gpio_probe()
233 i2c_put_adapter(muxc->parent); in i2c_mux_gpio_remove()
239 { .compatible = "i2c-mux-gpio", },
248 .name = "i2c-mux-gpio",
255 MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver");
258 MODULE_ALIAS("platform:i2c-mux-gpio");