Lines Matching +full:gpio +full:- +full:charger
1 // SPDX-License-Identifier: GPL-2.0-or-later
14 #include <linux/gpio/consumer.h>
26 #define YT2_1380_FC_PDEV_NAME "lenovo-yoga-tab2-pro-1380-fastcharger"
28 #define YT2_1380_FC_SERDEV_NAME "serial0-0"
29 #define YT2_1380_FC_EXTCON_NAME "i2c-lc824206xa"
51 struct pinctrl_state *state = enable ? fc->gpio_state : fc->uart_state; in yt2_1380_fc_set_gpio_mode()
54 ret = pinctrl_select_state(fc->pinctrl, state); in yt2_1380_fc_set_gpio_mode()
56 dev_err(fc->dev, "Error %d setting pinctrl state\n", ret); in yt2_1380_fc_set_gpio_mode()
66 return extcon_get_state(fc->extcon, EXTCON_CHG_USB_DCP) > 0; in yt2_1380_fc_dedicated_charger_connected()
71 return extcon_get_state(fc->extcon, EXTCON_CHG_USB_FAST) > 0; in yt2_1380_fc_fast_charger_connected()
84 /* Set pins to UART mode (for charger disconnect and retries) */ in yt2_1380_fc_worker()
89 /* Only try 12V charging if a dedicated charger is detected */ in yt2_1380_fc_worker()
94 ret = serdev_device_write_buf(to_serdev_device(fc->dev), "SC", strlen("SC")); in yt2_1380_fc_worker()
96 dev_err(fc->dev, "Error %d writing to uart\n", ret); in yt2_1380_fc_worker()
102 /* Re-check a charger is still connected */ in yt2_1380_fc_worker()
107 * Now switch the lines to GPIO (output, high). The charger in yt2_1380_fc_worker()
122 dev_dbg(fc->dev, "Failed to switch to 12V charging (not the original charger?)\n"); in yt2_1380_fc_worker()
132 schedule_work(&fc->work); in yt2_1380_fc_extcon_evt()
142 dev_dbg(&serdev->dev, "recv: %*ph\n", (int)len, data); in yt2_1380_fc_receive()
153 struct device *dev = &serdev->dev; in yt2_1380_fc_serdev_probe()
159 return -ENOMEM; in yt2_1380_fc_serdev_probe()
161 fc->dev = dev; in yt2_1380_fc_serdev_probe()
162 fc->nb.notifier_call = yt2_1380_fc_extcon_evt; in yt2_1380_fc_serdev_probe()
163 INIT_WORK(&fc->work, yt2_1380_fc_worker); in yt2_1380_fc_serdev_probe()
166 * Do this first since it may return -EPROBE_DEFER. in yt2_1380_fc_serdev_probe()
169 fc->extcon = extcon_get_extcon_dev(YT2_1380_FC_EXTCON_NAME); in yt2_1380_fc_serdev_probe()
170 if (IS_ERR(fc->extcon)) in yt2_1380_fc_serdev_probe()
171 return dev_err_probe(dev, PTR_ERR(fc->extcon), "getting extcon\n"); in yt2_1380_fc_serdev_probe()
173 fc->pinctrl = devm_pinctrl_get(dev); in yt2_1380_fc_serdev_probe()
174 if (IS_ERR(fc->pinctrl)) in yt2_1380_fc_serdev_probe()
175 return dev_err_probe(dev, PTR_ERR(fc->pinctrl), "getting pinctrl\n"); in yt2_1380_fc_serdev_probe()
179 * UART and GPIO modes. in yt2_1380_fc_serdev_probe()
181 fc->gpio_state = pinctrl_lookup_state(fc->pinctrl, "uart3_gpio"); in yt2_1380_fc_serdev_probe()
182 fc->uart_state = pinctrl_lookup_state(fc->pinctrl, "uart3_uart"); in yt2_1380_fc_serdev_probe()
183 if (IS_ERR(fc->gpio_state) || IS_ERR(fc->uart_state)) in yt2_1380_fc_serdev_probe()
184 return dev_err_probe(dev, -EINVAL, "getting pinctrl states\n"); in yt2_1380_fc_serdev_probe()
190 fc->uart3_txd = devm_gpiod_get(dev, "uart3_txd", GPIOD_OUT_HIGH); in yt2_1380_fc_serdev_probe()
191 if (IS_ERR(fc->uart3_txd)) in yt2_1380_fc_serdev_probe()
192 return dev_err_probe(dev, PTR_ERR(fc->uart3_txd), "getting uart3_txd gpio\n"); in yt2_1380_fc_serdev_probe()
194 fc->uart3_rxd = devm_gpiod_get(dev, "uart3_rxd", GPIOD_OUT_HIGH); in yt2_1380_fc_serdev_probe()
195 if (IS_ERR(fc->uart3_rxd)) in yt2_1380_fc_serdev_probe()
196 return dev_err_probe(dev, PTR_ERR(fc->uart3_rxd), "getting uart3_rxd gpio\n"); in yt2_1380_fc_serdev_probe()
211 ret = devm_extcon_register_notifier_all(dev, fc->extcon, &fc->nb); in yt2_1380_fc_serdev_probe()
215 /* In case the extcon already has detected a DCP charger */ in yt2_1380_fc_serdev_probe()
216 schedule_work(&fc->work); in yt2_1380_fc_serdev_probe()
232 "INT33FC:00", "uart3_grp_gpio", "gpio"),
247 /* And create the serdev to talk to the charger over the UART3 pins */ in yt2_1380_fc_pdev_probe()
257 ret = -ENOMEM; in yt2_1380_fc_pdev_probe()
263 dev_err_probe(&pdev->dev, ret, "adding serdev\n"); in yt2_1380_fc_pdev_probe()
269 * serdev device <-> driver matching relies on OF or ACPI matches and in yt2_1380_fc_pdev_probe()
272 ret = device_driver_attach(&yt2_1380_fc_serdev_driver.driver, &serdev->dev); in yt2_1380_fc_pdev_probe()
275 ret = (ret == -EAGAIN) ? -EPROBE_DEFER : ret; in yt2_1380_fc_pdev_probe()
276 dev_err_probe(&pdev->dev, ret, "attaching serdev driver\n"); in yt2_1380_fc_pdev_probe()
314 * device_driver_attach() on the serdev, serdev-driver pair. in yt2_1380_fc_module_init()