Lines Matching +full:i2c +full:- +full:mux

1 // SPDX-License-Identifier: GPL-2.0-only
3 * I2C multiplexer using pinctrl API
8 #include <linux/i2c.h>
9 #include <linux/i2c-mux.h>
24 struct i2c_mux_pinctrl *mux = i2c_mux_priv(muxc); in i2c_mux_pinctrl_select() local
26 return pinctrl_select_state(mux->pinctrl, mux->states[chan]); in i2c_mux_pinctrl_select()
31 return i2c_mux_pinctrl_select(muxc, muxc->num_adapters); in i2c_mux_pinctrl_deselect()
41 list_for_each_entry(setting, &state->settings, node) { in i2c_mux_pinctrl_root_adapter()
42 pin_root = i2c_root_adapter(setting->pctldev->dev); in i2c_mux_pinctrl_root_adapter()
56 struct device_node *np = dev->of_node; in i2c_mux_pinctrl_parent_adapter()
60 parent_np = of_parse_phandle(np, "i2c-parent", 0); in i2c_mux_pinctrl_parent_adapter()
62 dev_err(dev, "Cannot parse i2c-parent\n"); in i2c_mux_pinctrl_parent_adapter()
63 return ERR_PTR(-ENODEV); in i2c_mux_pinctrl_parent_adapter()
68 return ERR_PTR(-EPROBE_DEFER); in i2c_mux_pinctrl_parent_adapter()
75 struct device *dev = &pdev->dev; in i2c_mux_pinctrl_probe()
76 struct device_node *np = dev->of_node; in i2c_mux_pinctrl_probe()
78 struct i2c_mux_pinctrl *mux; in i2c_mux_pinctrl_probe() local
84 num_names = of_property_count_strings(np, "pinctrl-names"); in i2c_mux_pinctrl_probe()
86 dev_err(dev, "Cannot parse pinctrl-names: %d\n", in i2c_mux_pinctrl_probe()
96 struct_size(mux, states, num_names), in i2c_mux_pinctrl_probe()
99 ret = -ENOMEM; in i2c_mux_pinctrl_probe()
102 mux = i2c_mux_priv(muxc); in i2c_mux_pinctrl_probe()
106 mux->pinctrl = devm_pinctrl_get(dev); in i2c_mux_pinctrl_probe()
107 if (IS_ERR(mux->pinctrl)) { in i2c_mux_pinctrl_probe()
108 ret = PTR_ERR(mux->pinctrl); in i2c_mux_pinctrl_probe()
114 ret = of_property_read_string_index(np, "pinctrl-names", i, in i2c_mux_pinctrl_probe()
117 dev_err(dev, "Cannot parse pinctrl-names: %d\n", ret); in i2c_mux_pinctrl_probe()
121 mux->states[i] = pinctrl_lookup_state(mux->pinctrl, name); in i2c_mux_pinctrl_probe()
122 if (IS_ERR(mux->states[i])) { in i2c_mux_pinctrl_probe()
123 ret = PTR_ERR(mux->states[i]); in i2c_mux_pinctrl_probe()
132 if (i != num_names - 1) { in i2c_mux_pinctrl_probe()
134 ret = -EINVAL; in i2c_mux_pinctrl_probe()
137 muxc->deselect = i2c_mux_pinctrl_deselect; in i2c_mux_pinctrl_probe()
140 root = i2c_root_adapter(&muxc->parent->dev); in i2c_mux_pinctrl_probe()
142 muxc->mux_locked = true; in i2c_mux_pinctrl_probe()
144 if (root != i2c_mux_pinctrl_root_adapter(mux->states[i])) { in i2c_mux_pinctrl_probe()
145 muxc->mux_locked = false; in i2c_mux_pinctrl_probe()
149 if (muxc->mux_locked) in i2c_mux_pinctrl_probe()
150 dev_info(dev, "mux-locked i2c mux\n"); in i2c_mux_pinctrl_probe()
153 for (i = 0; i < num_names - !!muxc->deselect; i++) { in i2c_mux_pinctrl_probe()
174 i2c_put_adapter(muxc->parent); in i2c_mux_pinctrl_remove()
178 { .compatible = "i2c-mux-pinctrl", },
185 .name = "i2c-mux-pinctrl",
193 MODULE_DESCRIPTION("pinctrl-based I2C multiplexer driver");
196 MODULE_ALIAS("platform:i2c-mux-pinctrl");