Lines Matching full:fc

49 static int yt2_1380_fc_set_gpio_mode(struct yt2_1380_fc *fc, bool enable)  in yt2_1380_fc_set_gpio_mode()  argument
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()
64 static bool yt2_1380_fc_dedicated_charger_connected(struct yt2_1380_fc *fc) in yt2_1380_fc_dedicated_charger_connected() argument
66 return extcon_get_state(fc->extcon, EXTCON_CHG_USB_DCP) > 0; in yt2_1380_fc_dedicated_charger_connected()
69 static bool yt2_1380_fc_fast_charger_connected(struct yt2_1380_fc *fc) in yt2_1380_fc_fast_charger_connected() argument
71 return extcon_get_state(fc->extcon, EXTCON_CHG_USB_FAST) > 0; in yt2_1380_fc_fast_charger_connected()
76 struct yt2_1380_fc *fc = container_of(work, struct yt2_1380_fc, work); in yt2_1380_fc_worker() local
80 if (yt2_1380_fc_fast_charger_connected(fc)) in yt2_1380_fc_worker()
85 ret = yt2_1380_fc_set_gpio_mode(fc, false); in yt2_1380_fc_worker()
90 if (!yt2_1380_fc_dedicated_charger_connected(fc)) 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()
103 if (!yt2_1380_fc_dedicated_charger_connected(fc)) in yt2_1380_fc_worker()
112 ret = yt2_1380_fc_set_gpio_mode(fc, true); in yt2_1380_fc_worker()
118 if (yt2_1380_fc_fast_charger_connected(fc)) 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()
124 yt2_1380_fc_set_gpio_mode(fc, false); in yt2_1380_fc_worker()
130 struct yt2_1380_fc *fc = container_of(nb, struct yt2_1380_fc, nb); in yt2_1380_fc_extcon_evt() local
132 schedule_work(&fc->work); in yt2_1380_fc_extcon_evt()
154 struct yt2_1380_fc *fc; in yt2_1380_fc_serdev_probe() local
157 fc = devm_kzalloc(dev, sizeof(*fc), GFP_KERNEL); in yt2_1380_fc_serdev_probe()
158 if (!fc) 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()
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()
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()
186 ret = yt2_1380_fc_set_gpio_mode(fc, true); 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()
198 ret = yt2_1380_fc_set_gpio_mode(fc, false); in yt2_1380_fc_serdev_probe()
208 serdev_device_set_drvdata(serdev, fc); in yt2_1380_fc_serdev_probe()
211 ret = devm_extcon_register_notifier_all(dev, fc->extcon, &fc->nb); in yt2_1380_fc_serdev_probe()
216 schedule_work(&fc->work); in yt2_1380_fc_serdev_probe()