Lines Matching +full:cmd +full:- +full:gpios
2 * NBUS driver for TS-4600 based boards
4 * Copyright (c) 2016 - Savoir-faire Linux
11 * This driver implements a GPIOs bit-banged bus, called the NBUS by Technologic
13 * TS-4600 SoM.
24 #include <linux/ts-nbus.h>
43 * request all gpios required by the bus.
48 ts_nbus->data = devm_gpiod_get_array(&pdev->dev, "ts,data", in ts_nbus_init_pdata()
50 if (IS_ERR(ts_nbus->data)) { in ts_nbus_init_pdata()
51 dev_err(&pdev->dev, "failed to retrieve ts,data-gpio from dts\n"); in ts_nbus_init_pdata()
52 return PTR_ERR(ts_nbus->data); in ts_nbus_init_pdata()
55 ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
56 if (IS_ERR(ts_nbus->csn)) { in ts_nbus_init_pdata()
57 dev_err(&pdev->dev, "failed to retrieve ts,csn-gpio from dts\n"); in ts_nbus_init_pdata()
58 return PTR_ERR(ts_nbus->csn); in ts_nbus_init_pdata()
61 ts_nbus->txrx = devm_gpiod_get(&pdev->dev, "ts,txrx", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
62 if (IS_ERR(ts_nbus->txrx)) { in ts_nbus_init_pdata()
63 dev_err(&pdev->dev, "failed to retrieve ts,txrx-gpio from dts\n"); in ts_nbus_init_pdata()
64 return PTR_ERR(ts_nbus->txrx); in ts_nbus_init_pdata()
67 ts_nbus->strobe = devm_gpiod_get(&pdev->dev, "ts,strobe", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
68 if (IS_ERR(ts_nbus->strobe)) { in ts_nbus_init_pdata()
69 dev_err(&pdev->dev, "failed to retrieve ts,strobe-gpio from dts\n"); in ts_nbus_init_pdata()
70 return PTR_ERR(ts_nbus->strobe); in ts_nbus_init_pdata()
73 ts_nbus->ale = devm_gpiod_get(&pdev->dev, "ts,ale", GPIOD_OUT_HIGH); in ts_nbus_init_pdata()
74 if (IS_ERR(ts_nbus->ale)) { in ts_nbus_init_pdata()
75 dev_err(&pdev->dev, "failed to retrieve ts,ale-gpio from dts\n"); in ts_nbus_init_pdata()
76 return PTR_ERR(ts_nbus->ale); in ts_nbus_init_pdata()
79 ts_nbus->rdy = devm_gpiod_get(&pdev->dev, "ts,rdy", GPIOD_IN); in ts_nbus_init_pdata()
80 if (IS_ERR(ts_nbus->rdy)) { in ts_nbus_init_pdata()
81 dev_err(&pdev->dev, "failed to retrieve ts,rdy-gpio from dts\n"); in ts_nbus_init_pdata()
82 return PTR_ERR(ts_nbus->rdy); in ts_nbus_init_pdata()
89 * the data gpios are used for reading and writing values, their directions
98 gpiod_direction_input(ts_nbus->data->desc[i]); in ts_nbus_set_direction()
102 gpiod_direction_output(ts_nbus->data->desc[i], 1); in ts_nbus_set_direction()
117 gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, in ts_nbus_reset_bus()
118 ts_nbus->data->info, values); in ts_nbus_reset_bus()
119 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_reset_bus()
120 gpiod_set_value_cansleep(ts_nbus->strobe, 0); in ts_nbus_reset_bus()
121 gpiod_set_value_cansleep(ts_nbus->ale, 0); in ts_nbus_reset_bus()
129 gpiod_set_value_cansleep(ts_nbus->strobe, 1); in ts_nbus_start_transaction()
133 * read a byte value from the data gpios.
138 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_read_byte() local
143 ret = gpiod_get_value_cansleep(gpios->desc[i]); in ts_nbus_read_byte()
154 * set the data gpios accordingly to the byte value.
158 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_write_byte() local
163 gpiod_set_array_value_cansleep(8, gpios->desc, gpios->info, values); in ts_nbus_write_byte()
168 * send the data in the data gpios and return the read value.
182 * value in the data gpios.
184 static void ts_nbus_write_bus(struct ts_nbus *ts_nbus, int cmd, u8 val) in ts_nbus_write_bus() argument
188 if (cmd == TS_NBUS_WRITE_ADR) in ts_nbus_write_bus()
189 gpiod_set_value_cansleep(ts_nbus->ale, 1); in ts_nbus_write_bus()
205 mutex_lock(&ts_nbus->lock); in ts_nbus_read()
208 gpiod_set_value_cansleep(ts_nbus->txrx, 0); in ts_nbus_read()
213 /* set the data gpios direction as input before reading */ in ts_nbus_read()
220 for (i = 1; i >= 0; i--) { in ts_nbus_read()
229 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_read()
230 ret = gpiod_get_value_cansleep(ts_nbus->rdy); in ts_nbus_read()
234 /* restore the data gpios direction as output after reading */ in ts_nbus_read()
237 mutex_unlock(&ts_nbus->lock); in ts_nbus_read()
251 mutex_lock(&ts_nbus->lock); in ts_nbus_write()
254 gpiod_set_value_cansleep(ts_nbus->txrx, 1); in ts_nbus_write()
260 for (i = 1; i >= 0; i--) in ts_nbus_write()
264 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
265 while (gpiod_get_value_cansleep(ts_nbus->rdy) != 0) { in ts_nbus_write()
266 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_write()
267 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
270 mutex_unlock(&ts_nbus->lock); in ts_nbus_write()
280 struct device *dev = &pdev->dev; in ts_nbus_probe()
286 return -ENOMEM; in ts_nbus_probe()
288 mutex_init(&ts_nbus->lock); in ts_nbus_probe()
297 if (ret != -EPROBE_DEFER) in ts_nbus_probe()
304 dev_err(&pdev->dev, "invalid PWM period\n"); in ts_nbus_probe()
305 return -EINVAL; in ts_nbus_probe()
321 ts_nbus->pwm = pwm; in ts_nbus_probe()
324 * let the child nodes retrieve this instance of the ts-nbus. in ts_nbus_probe()
328 ret = of_platform_populate(dev->of_node, NULL, NULL, dev); in ts_nbus_probe()
339 struct ts_nbus *ts_nbus = dev_get_drvdata(&pdev->dev); in ts_nbus_remove()
342 mutex_lock(&ts_nbus->lock); in ts_nbus_remove()
343 pwm_disable(ts_nbus->pwm); in ts_nbus_remove()
344 mutex_unlock(&ts_nbus->lock); in ts_nbus_remove()
350 { .compatible = "technologic,ts-nbus", },