19 #include <linux/i2c.h>
22 #include <linux/module.h>
27 #include <linux/slab.h>
47 static int i2c_mux_pinctrl_deselect(
struct i2c_adapter *adap,
void *
data,
60 int num_names,
i,
ret;
70 "Cannot allocate i2c_mux_pinctrl_platform_data\n");
76 dev_err(mux->
dev,
"Cannot parse pinctrl-names: %d\n",
82 sizeof(*mux->
pdata->pinctrl_states) * num_names,
84 if (!mux->
pdata->pinctrl_states) {
85 dev_err(mux->
dev,
"Cannot allocate pinctrl_states\n");
89 for (i = 0; i < num_names; i++) {
91 &mux->
pdata->pinctrl_states[mux->
pdata->bus_count]);
93 dev_err(mux->
dev,
"Cannot parse pinctrl-names: %d\n",
99 if (i != num_names - 1) {
100 dev_err(mux->
dev,
"idle state must be last\n");
103 mux->
pdata->pinctrl_state_idle =
"idle";
105 mux->
pdata->bus_count++;
111 dev_err(mux->
dev,
"Cannot parse i2c-parent\n");
116 dev_err(mux->
dev,
"Cannot find parent bus\n");
119 mux->
pdata->parent_bus_num = i2c_adapter_id(adapter);
125 static inline int i2c_mux_pinctrl_parse_dt(
struct i2c_mux_pinctrl *mux,
140 dev_err(&pdev->
dev,
"Cannot allocate i2c_mux_pinctrl\n");
144 platform_set_drvdata(pdev, mux);
148 mux->
pdata = pdev->
dev.platform_data;
150 ret = i2c_mux_pinctrl_parse_dt(mux, pdev);
155 dev_err(&pdev->
dev,
"Missing platform data\n");
164 dev_err(&pdev->
dev,
"Cannot allocate states\n");
173 dev_err(&pdev->
dev,
"Cannot allocate busses\n");
181 dev_err(&pdev->
dev,
"Cannot get pinctrl: %d\n", ret);
184 for (i = 0; i < mux->
pdata->bus_count; i++) {
186 mux->
pdata->pinctrl_states[i]);
187 if (IS_ERR(mux->
states[i])) {
188 ret = PTR_ERR(mux->
states[i]);
190 "Cannot look up pinctrl state %s: %d\n",
191 mux->
pdata->pinctrl_states[i], ret);
195 if (mux->
pdata->pinctrl_state_idle) {
197 mux->
pdata->pinctrl_state_idle);
201 "Cannot look up pinctrl state %s: %d\n",
202 mux->
pdata->pinctrl_state_idle, ret);
206 deselect = i2c_mux_pinctrl_deselect;
213 dev_err(&pdev->
dev,
"Parent adapter (%d) not found\n",
214 mux->
pdata->parent_bus_num);
219 for (i = 0; i < mux->
pdata->bus_count; i++) {
221 (mux->
pdata->base_bus_num +
i) : 0;
225 i2c_mux_pinctrl_select,
229 dev_err(&pdev->
dev,
"Failed to add adapter %d\n", i);
230 goto err_del_adapter;
249 for (i = 0; i < mux->
pdata->bus_count; i++)
259 { .compatible =
"i2c-mux-pinctrl", },
267 .name =
"i2c-mux-pinctrl",
269 .of_match_table =
of_match_ptr(i2c_mux_pinctrl_of_match),
271 .probe = i2c_mux_pinctrl_probe,