Lines Matching +full:bit +full:- +full:banged
1 // SPDX-License-Identifier: GPL-2.0-only
3 * NBUS driver for TS-4600 based boards
5 * Copyright (c) 2016 - Savoir-faire Linux
8 * This driver implements a GPIOs bit-banged bus, called the NBUS by Technologic
10 * TS-4600 SoM.
21 #include <linux/ts-nbus.h>
45 ts_nbus->data = devm_gpiod_get_array(&pdev->dev, "ts,data", in ts_nbus_init_pdata()
47 if (IS_ERR(ts_nbus->data)) { in ts_nbus_init_pdata()
48 dev_err(&pdev->dev, "failed to retrieve ts,data-gpio from dts\n"); in ts_nbus_init_pdata()
49 return PTR_ERR(ts_nbus->data); in ts_nbus_init_pdata()
52 ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
53 if (IS_ERR(ts_nbus->csn)) { in ts_nbus_init_pdata()
54 dev_err(&pdev->dev, "failed to retrieve ts,csn-gpio from dts\n"); in ts_nbus_init_pdata()
55 return PTR_ERR(ts_nbus->csn); in ts_nbus_init_pdata()
58 ts_nbus->txrx = devm_gpiod_get(&pdev->dev, "ts,txrx", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
59 if (IS_ERR(ts_nbus->txrx)) { in ts_nbus_init_pdata()
60 dev_err(&pdev->dev, "failed to retrieve ts,txrx-gpio from dts\n"); in ts_nbus_init_pdata()
61 return PTR_ERR(ts_nbus->txrx); in ts_nbus_init_pdata()
64 ts_nbus->strobe = devm_gpiod_get(&pdev->dev, "ts,strobe", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
65 if (IS_ERR(ts_nbus->strobe)) { in ts_nbus_init_pdata()
66 dev_err(&pdev->dev, "failed to retrieve ts,strobe-gpio from dts\n"); in ts_nbus_init_pdata()
67 return PTR_ERR(ts_nbus->strobe); in ts_nbus_init_pdata()
70 ts_nbus->ale = devm_gpiod_get(&pdev->dev, "ts,ale", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
71 if (IS_ERR(ts_nbus->ale)) { in ts_nbus_init_pdata()
72 dev_err(&pdev->dev, "failed to retrieve ts,ale-gpio from dts\n"); in ts_nbus_init_pdata()
73 return PTR_ERR(ts_nbus->ale); in ts_nbus_init_pdata()
76 ts_nbus->rdy = devm_gpiod_get(&pdev->dev, "ts,rdy", GPIOD_IN); in ts_nbus_init_pdata()
77 if (IS_ERR(ts_nbus->rdy)) { in ts_nbus_init_pdata()
78 dev_err(&pdev->dev, "failed to retrieve ts,rdy-gpio from dts\n"); in ts_nbus_init_pdata()
79 return PTR_ERR(ts_nbus->rdy); in ts_nbus_init_pdata()
95 gpiod_direction_input(ts_nbus->data->desc[i]); in ts_nbus_set_direction()
99 gpiod_direction_output(ts_nbus->data->desc[i], 1); in ts_nbus_set_direction()
114 gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, in ts_nbus_reset_bus()
115 ts_nbus->data->info, values); in ts_nbus_reset_bus()
116 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_reset_bus()
117 gpiod_set_value_cansleep(ts_nbus->strobe, 0); in ts_nbus_reset_bus()
118 gpiod_set_value_cansleep(ts_nbus->ale, 0); in ts_nbus_reset_bus()
126 gpiod_set_value_cansleep(ts_nbus->strobe, 1); in ts_nbus_start_transaction()
135 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_read_byte()
140 ret = gpiod_get_value_cansleep(gpios->desc[i]); in ts_nbus_read_byte()
144 *val |= BIT(i); in ts_nbus_read_byte()
155 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_write_byte()
160 gpiod_set_array_value_cansleep(8, gpios->desc, gpios->info, values); in ts_nbus_write_byte()
186 gpiod_set_value_cansleep(ts_nbus->ale, 1); in ts_nbus_write_bus()
202 mutex_lock(&ts_nbus->lock); in ts_nbus_read()
205 gpiod_set_value_cansleep(ts_nbus->txrx, 0); in ts_nbus_read()
217 for (i = 1; i >= 0; i--) { in ts_nbus_read()
226 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_read()
227 ret = gpiod_get_value_cansleep(ts_nbus->rdy); in ts_nbus_read()
234 mutex_unlock(&ts_nbus->lock); in ts_nbus_read()
248 mutex_lock(&ts_nbus->lock); in ts_nbus_write()
251 gpiod_set_value_cansleep(ts_nbus->txrx, 1); in ts_nbus_write()
257 for (i = 1; i >= 0; i--) in ts_nbus_write()
261 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
262 while (gpiod_get_value_cansleep(ts_nbus->rdy) != 0) { in ts_nbus_write()
263 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_write()
264 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
267 mutex_unlock(&ts_nbus->lock); in ts_nbus_write()
277 struct device *dev = &pdev->dev; in ts_nbus_probe()
283 return -ENOMEM; in ts_nbus_probe()
285 mutex_init(&ts_nbus->lock); in ts_nbus_probe()
294 if (ret != -EPROBE_DEFER) in ts_nbus_probe()
301 dev_err(&pdev->dev, "invalid PWM period\n"); in ts_nbus_probe()
302 return -EINVAL; in ts_nbus_probe()
318 ts_nbus->pwm = pwm; in ts_nbus_probe()
321 * let the child nodes retrieve this instance of the ts-nbus. in ts_nbus_probe()
325 ret = of_platform_populate(dev->of_node, NULL, NULL, dev); in ts_nbus_probe()
336 struct ts_nbus *ts_nbus = dev_get_drvdata(&pdev->dev); in ts_nbus_remove()
339 mutex_lock(&ts_nbus->lock); in ts_nbus_remove()
340 pwm_disable(ts_nbus->pwm); in ts_nbus_remove()
341 mutex_unlock(&ts_nbus->lock); in ts_nbus_remove()
347 { .compatible = "technologic,ts-nbus", },