Lines Matching +full:strobe +full:- +full:gpios
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>
33 struct gpio_desc *strobe; member
40 * request all gpios required by the bus.
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 return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->data), in ts_nbus_init_pdata()
49 "failed to retrieve ts,data-gpio from dts\n"); in ts_nbus_init_pdata()
51 ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
52 if (IS_ERR(ts_nbus->csn)) in ts_nbus_init_pdata()
53 return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->csn), in ts_nbus_init_pdata()
54 "failed to retrieve ts,csn-gpio from dts\n"); in ts_nbus_init_pdata()
56 ts_nbus->txrx = devm_gpiod_get(&pdev->dev, "ts,txrx", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
57 if (IS_ERR(ts_nbus->txrx)) in ts_nbus_init_pdata()
58 return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->txrx), in ts_nbus_init_pdata()
59 "failed to retrieve ts,txrx-gpio from dts\n"); in ts_nbus_init_pdata()
61 ts_nbus->strobe = devm_gpiod_get(&pdev->dev, "ts,strobe", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
62 if (IS_ERR(ts_nbus->strobe)) in ts_nbus_init_pdata()
63 return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->strobe), in ts_nbus_init_pdata()
64 "failed to retrieve ts,strobe-gpio from dts\n"); in ts_nbus_init_pdata()
66 ts_nbus->ale = devm_gpiod_get(&pdev->dev, "ts,ale", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
67 if (IS_ERR(ts_nbus->ale)) in ts_nbus_init_pdata()
68 return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->ale), in ts_nbus_init_pdata()
69 "failed to retrieve ts,ale-gpio from dts\n"); in ts_nbus_init_pdata()
71 ts_nbus->rdy = devm_gpiod_get(&pdev->dev, "ts,rdy", GPIOD_IN); in ts_nbus_init_pdata()
72 if (IS_ERR(ts_nbus->rdy)) in ts_nbus_init_pdata()
73 return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->rdy), in ts_nbus_init_pdata()
74 "failed to retrieve ts,rdy-gpio from dts\n"); in ts_nbus_init_pdata()
80 * the data gpios are used for reading and writing values, their directions
89 gpiod_direction_input(ts_nbus->data->desc[i]); in ts_nbus_set_direction()
93 gpiod_direction_output(ts_nbus->data->desc[i], 1); in ts_nbus_set_direction()
99 * The data, csn, strobe and ale lines must be zero'ed to let the FPGA knows a
108 gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, in ts_nbus_reset_bus()
109 ts_nbus->data->info, values); in ts_nbus_reset_bus()
110 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_reset_bus()
111 gpiod_set_value_cansleep(ts_nbus->strobe, 0); in ts_nbus_reset_bus()
112 gpiod_set_value_cansleep(ts_nbus->ale, 0); in ts_nbus_reset_bus()
120 gpiod_set_value_cansleep(ts_nbus->strobe, 1); in ts_nbus_start_transaction()
124 * read a byte value from the data gpios.
129 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_read_byte() local
134 ret = gpiod_get_value_cansleep(gpios->desc[i]); in ts_nbus_read_byte()
145 * set the data gpios accordingly to the byte value.
149 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_write_byte() local
154 gpiod_set_array_value_cansleep(8, gpios->desc, gpios->info, values); in ts_nbus_write_byte()
159 * send the data in the data gpios and return the read value.
173 * value in the data gpios.
180 gpiod_set_value_cansleep(ts_nbus->ale, 1); in ts_nbus_write_bus()
196 mutex_lock(&ts_nbus->lock); in ts_nbus_read()
199 gpiod_set_value_cansleep(ts_nbus->txrx, 0); in ts_nbus_read()
204 /* set the data gpios direction as input before reading */ in ts_nbus_read()
211 for (i = 1; i >= 0; i--) { in ts_nbus_read()
220 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_read()
221 ret = gpiod_get_value_cansleep(ts_nbus->rdy); in ts_nbus_read()
225 /* restore the data gpios direction as output after reading */ in ts_nbus_read()
228 mutex_unlock(&ts_nbus->lock); in ts_nbus_read()
242 mutex_lock(&ts_nbus->lock); in ts_nbus_write()
245 gpiod_set_value_cansleep(ts_nbus->txrx, 1); in ts_nbus_write()
251 for (i = 1; i >= 0; i--) in ts_nbus_write()
255 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
256 while (gpiod_get_value_cansleep(ts_nbus->rdy) != 0) { in ts_nbus_write()
257 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_write()
258 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
261 mutex_unlock(&ts_nbus->lock); in ts_nbus_write()
271 struct device *dev = &pdev->dev; in ts_nbus_probe()
277 return -ENOMEM; in ts_nbus_probe()
279 mutex_init(&ts_nbus->lock); in ts_nbus_probe()
292 return dev_err_probe(dev, -EINVAL, "invalid PWM period\n"); in ts_nbus_probe()
304 ts_nbus->pwm = pwm; in ts_nbus_probe()
307 * let the child nodes retrieve this instance of the ts-nbus. in ts_nbus_probe()
311 ret = of_platform_populate(dev->of_node, NULL, NULL, dev); in ts_nbus_probe()
323 struct ts_nbus *ts_nbus = dev_get_drvdata(&pdev->dev); in ts_nbus_remove()
326 mutex_lock(&ts_nbus->lock); in ts_nbus_remove()
327 pwm_disable(ts_nbus->pwm); in ts_nbus_remove()
328 mutex_unlock(&ts_nbus->lock); in ts_nbus_remove()
332 { .compatible = "technologic,ts-nbus", },