• Home
  • Raw
  • Download

Lines Matching +full:first +full:- +full:data +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>
33 struct gpio_descs *data; member
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()
100 /* when used as output the default state of the data in ts_nbus_set_direction()
102 gpiod_direction_output(ts_nbus->data->desc[i], 1); in ts_nbus_set_direction()
108 * The data, csn, strobe and ale lines must be zero'ed to let the FPGA knows a
119 gpiod_set_array_value_cansleep(8, ts_nbus->data->desc, values); in ts_nbus_reset_bus()
120 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_reset_bus()
121 gpiod_set_value_cansleep(ts_nbus->strobe, 0); in ts_nbus_reset_bus()
122 gpiod_set_value_cansleep(ts_nbus->ale, 0); in ts_nbus_reset_bus()
130 gpiod_set_value_cansleep(ts_nbus->strobe, 1); in ts_nbus_start_transaction()
134 * read a byte value from the data gpios.
139 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_read_byte() local
144 ret = gpiod_get_value_cansleep(gpios->desc[i]); in ts_nbus_read_byte()
155 * set the data gpios accordingly to the byte value.
159 struct gpio_descs *gpios = ts_nbus->data; in ts_nbus_write_byte() local
169 gpiod_set_array_value_cansleep(8, gpios->desc, values); in ts_nbus_write_byte()
174 * send the data in the data gpios and return the read value.
187 * command (address/value), write the data and notify the FPGA to retrieve the
188 * value in the data gpios.
195 gpiod_set_value_cansleep(ts_nbus->ale, 1); in ts_nbus_write_bus()
211 mutex_lock(&ts_nbus->lock); in ts_nbus_read()
214 gpiod_set_value_cansleep(ts_nbus->txrx, 0); in ts_nbus_read()
219 /* set the data gpios direction as input before reading */ in ts_nbus_read()
222 /* reading value MSB first */ in ts_nbus_read()
226 for (i = 1; i >= 0; i--) { in ts_nbus_read()
235 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_read()
236 ret = gpiod_get_value_cansleep(ts_nbus->rdy); in ts_nbus_read()
240 /* restore the data gpios direction as output after reading */ in ts_nbus_read()
243 mutex_unlock(&ts_nbus->lock); in ts_nbus_read()
257 mutex_lock(&ts_nbus->lock); in ts_nbus_write()
260 gpiod_set_value_cansleep(ts_nbus->txrx, 1); in ts_nbus_write()
265 /* writing value MSB first */ in ts_nbus_write()
266 for (i = 1; i >= 0; i--) in ts_nbus_write()
270 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
271 while (gpiod_get_value_cansleep(ts_nbus->rdy) != 0) { in ts_nbus_write()
272 gpiod_set_value_cansleep(ts_nbus->csn, 0); in ts_nbus_write()
273 gpiod_set_value_cansleep(ts_nbus->csn, 1); in ts_nbus_write()
276 mutex_unlock(&ts_nbus->lock); in ts_nbus_write()
286 struct device *dev = &pdev->dev; in ts_nbus_probe()
292 return -ENOMEM; in ts_nbus_probe()
294 mutex_init(&ts_nbus->lock); in ts_nbus_probe()
303 if (ret != -EPROBE_DEFER) in ts_nbus_probe()
310 dev_err(&pdev->dev, "invalid PWM period\n"); in ts_nbus_probe()
311 return -EINVAL; in ts_nbus_probe()
327 ts_nbus->pwm = pwm; in ts_nbus_probe()
330 * let the child nodes retrieve this instance of the ts-nbus. in ts_nbus_probe()
334 ret = of_platform_populate(dev->of_node, NULL, NULL, dev); in ts_nbus_probe()
345 struct ts_nbus *ts_nbus = dev_get_drvdata(&pdev->dev); in ts_nbus_remove()
348 mutex_lock(&ts_nbus->lock); in ts_nbus_remove()
349 pwm_disable(ts_nbus->pwm); in ts_nbus_remove()
350 mutex_unlock(&ts_nbus->lock); in ts_nbus_remove()
356 { .compatible = "technologic,ts-nbus", },