Lines Matching +full:lock +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0+
45 u8 offset; member
77 …"gpio-a sampling freq in Hz (default is 1000Hz) valid values: 10, 100, 1000, 10000, 100000, 100000…
79 /* ----- begin of gipo a chip -------------------------------------------- */
82 unsigned int offset) in vprbrd_gpioa_get() argument
86 struct vprbrd *vb = gpio->vb; in vprbrd_gpioa_get()
87 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; in vprbrd_gpioa_get()
90 if (gpio->gpioa_out & (1 << offset)) in vprbrd_gpioa_get()
91 return !!(gpio->gpioa_val & (1 << offset)); in vprbrd_gpioa_get()
93 mutex_lock(&vb->lock); in vprbrd_gpioa_get()
95 gamsg->cmd = VPRBRD_GPIOA_CMD_GETIN; in vprbrd_gpioa_get()
96 gamsg->clk = 0x00; in vprbrd_gpioa_get()
97 gamsg->offset = offset; in vprbrd_gpioa_get()
98 gamsg->t1 = 0x00; in vprbrd_gpioa_get()
99 gamsg->t2 = 0x00; in vprbrd_gpioa_get()
100 gamsg->invert = 0x00; in vprbrd_gpioa_get()
101 gamsg->pwmlevel = 0x00; in vprbrd_gpioa_get()
102 gamsg->outval = 0x00; in vprbrd_gpioa_get()
103 gamsg->risefall = 0x00; in vprbrd_gpioa_get()
104 gamsg->answer = 0x00; in vprbrd_gpioa_get()
105 gamsg->__fill = 0x00; in vprbrd_gpioa_get()
107 ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), in vprbrd_gpioa_get()
112 error = -EREMOTEIO; in vprbrd_gpioa_get()
114 ret = usb_control_msg(vb->usb_dev, usb_rcvctrlpipe(vb->usb_dev, 0), in vprbrd_gpioa_get()
118 answer = gamsg->answer & 0x01; in vprbrd_gpioa_get()
120 mutex_unlock(&vb->lock); in vprbrd_gpioa_get()
123 error = -EREMOTEIO; in vprbrd_gpioa_get()
132 unsigned int offset, int value) in vprbrd_gpioa_set() argument
136 struct vprbrd *vb = gpio->vb; in vprbrd_gpioa_set()
137 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; in vprbrd_gpioa_set()
139 if (gpio->gpioa_out & (1 << offset)) { in vprbrd_gpioa_set()
141 gpio->gpioa_val |= (1 << offset); in vprbrd_gpioa_set()
143 gpio->gpioa_val &= ~(1 << offset); in vprbrd_gpioa_set()
145 mutex_lock(&vb->lock); in vprbrd_gpioa_set()
147 gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT; in vprbrd_gpioa_set()
148 gamsg->clk = 0x00; in vprbrd_gpioa_set()
149 gamsg->offset = offset; in vprbrd_gpioa_set()
150 gamsg->t1 = 0x00; in vprbrd_gpioa_set()
151 gamsg->t2 = 0x00; in vprbrd_gpioa_set()
152 gamsg->invert = 0x00; in vprbrd_gpioa_set()
153 gamsg->pwmlevel = 0x00; in vprbrd_gpioa_set()
154 gamsg->outval = value; in vprbrd_gpioa_set()
155 gamsg->risefall = 0x00; in vprbrd_gpioa_set()
156 gamsg->answer = 0x00; in vprbrd_gpioa_set()
157 gamsg->__fill = 0x00; in vprbrd_gpioa_set()
159 ret = usb_control_msg(vb->usb_dev, in vprbrd_gpioa_set()
160 usb_sndctrlpipe(vb->usb_dev, 0), in vprbrd_gpioa_set()
165 mutex_unlock(&vb->lock); in vprbrd_gpioa_set()
168 dev_err(chip->parent, "usb error setting pin value\n"); in vprbrd_gpioa_set()
173 unsigned int offset) in vprbrd_gpioa_direction_input() argument
177 struct vprbrd *vb = gpio->vb; in vprbrd_gpioa_direction_input()
178 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; in vprbrd_gpioa_direction_input()
180 gpio->gpioa_out &= ~(1 << offset); in vprbrd_gpioa_direction_input()
182 mutex_lock(&vb->lock); in vprbrd_gpioa_direction_input()
184 gamsg->cmd = VPRBRD_GPIOA_CMD_SETIN; in vprbrd_gpioa_direction_input()
185 gamsg->clk = gpioa_clk; in vprbrd_gpioa_direction_input()
186 gamsg->offset = offset; in vprbrd_gpioa_direction_input()
187 gamsg->t1 = 0x00; in vprbrd_gpioa_direction_input()
188 gamsg->t2 = 0x00; in vprbrd_gpioa_direction_input()
189 gamsg->invert = 0x00; in vprbrd_gpioa_direction_input()
190 gamsg->pwmlevel = 0x00; in vprbrd_gpioa_direction_input()
191 gamsg->outval = 0x00; in vprbrd_gpioa_direction_input()
192 gamsg->risefall = 0x00; in vprbrd_gpioa_direction_input()
193 gamsg->answer = 0x00; in vprbrd_gpioa_direction_input()
194 gamsg->__fill = 0x00; in vprbrd_gpioa_direction_input()
196 ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), in vprbrd_gpioa_direction_input()
201 mutex_unlock(&vb->lock); in vprbrd_gpioa_direction_input()
204 return -EREMOTEIO; in vprbrd_gpioa_direction_input()
210 unsigned int offset, int value) in vprbrd_gpioa_direction_output() argument
214 struct vprbrd *vb = gpio->vb; in vprbrd_gpioa_direction_output()
215 struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; in vprbrd_gpioa_direction_output()
217 gpio->gpioa_out |= (1 << offset); in vprbrd_gpioa_direction_output()
219 gpio->gpioa_val |= (1 << offset); in vprbrd_gpioa_direction_output()
221 gpio->gpioa_val &= ~(1 << offset); in vprbrd_gpioa_direction_output()
223 mutex_lock(&vb->lock); in vprbrd_gpioa_direction_output()
225 gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT; in vprbrd_gpioa_direction_output()
226 gamsg->clk = 0x00; in vprbrd_gpioa_direction_output()
227 gamsg->offset = offset; in vprbrd_gpioa_direction_output()
228 gamsg->t1 = 0x00; in vprbrd_gpioa_direction_output()
229 gamsg->t2 = 0x00; in vprbrd_gpioa_direction_output()
230 gamsg->invert = 0x00; in vprbrd_gpioa_direction_output()
231 gamsg->pwmlevel = 0x00; in vprbrd_gpioa_direction_output()
232 gamsg->outval = value; in vprbrd_gpioa_direction_output()
233 gamsg->risefall = 0x00; in vprbrd_gpioa_direction_output()
234 gamsg->answer = 0x00; in vprbrd_gpioa_direction_output()
235 gamsg->__fill = 0x00; in vprbrd_gpioa_direction_output()
237 ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), in vprbrd_gpioa_direction_output()
242 mutex_unlock(&vb->lock); in vprbrd_gpioa_direction_output()
245 return -EREMOTEIO; in vprbrd_gpioa_direction_output()
250 /* ----- end of gpio a chip ---------------------------------------------- */
252 /* ----- begin of gipo b chip -------------------------------------------- */
254 static int vprbrd_gpiob_setdir(struct vprbrd *vb, unsigned int offset, in vprbrd_gpiob_setdir() argument
257 struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; in vprbrd_gpiob_setdir()
260 gbmsg->cmd = VPRBRD_GPIOB_CMD_SETDIR; in vprbrd_gpiob_setdir()
261 gbmsg->val = cpu_to_be16(dir << offset); in vprbrd_gpiob_setdir()
262 gbmsg->mask = cpu_to_be16(0x0001 << offset); in vprbrd_gpiob_setdir()
264 ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), in vprbrd_gpiob_setdir()
270 return -EREMOTEIO; in vprbrd_gpiob_setdir()
276 unsigned int offset) in vprbrd_gpiob_get() argument
281 struct vprbrd *vb = gpio->vb; in vprbrd_gpiob_get()
282 struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; in vprbrd_gpiob_get()
285 if (gpio->gpiob_out & (1 << offset)) in vprbrd_gpiob_get()
286 return gpio->gpiob_val & (1 << offset); in vprbrd_gpiob_get()
288 mutex_lock(&vb->lock); in vprbrd_gpiob_get()
290 ret = usb_control_msg(vb->usb_dev, usb_rcvctrlpipe(vb->usb_dev, 0), in vprbrd_gpiob_get()
294 val = gbmsg->val; in vprbrd_gpiob_get()
296 mutex_unlock(&vb->lock); in vprbrd_gpiob_get()
302 gpio->gpiob_val = be16_to_cpu(val); in vprbrd_gpiob_get()
304 return (gpio->gpiob_val >> offset) & 0x1; in vprbrd_gpiob_get()
308 unsigned int offset, int value) in vprbrd_gpiob_set() argument
312 struct vprbrd *vb = gpio->vb; in vprbrd_gpiob_set()
313 struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; in vprbrd_gpiob_set()
315 if (gpio->gpiob_out & (1 << offset)) { in vprbrd_gpiob_set()
317 gpio->gpiob_val |= (1 << offset); in vprbrd_gpiob_set()
319 gpio->gpiob_val &= ~(1 << offset); in vprbrd_gpiob_set()
321 mutex_lock(&vb->lock); in vprbrd_gpiob_set()
323 gbmsg->cmd = VPRBRD_GPIOB_CMD_SETVAL; in vprbrd_gpiob_set()
324 gbmsg->val = cpu_to_be16(value << offset); in vprbrd_gpiob_set()
325 gbmsg->mask = cpu_to_be16(0x0001 << offset); in vprbrd_gpiob_set()
327 ret = usb_control_msg(vb->usb_dev, in vprbrd_gpiob_set()
328 usb_sndctrlpipe(vb->usb_dev, 0), in vprbrd_gpiob_set()
333 mutex_unlock(&vb->lock); in vprbrd_gpiob_set()
336 dev_err(chip->parent, "usb error setting pin value\n"); in vprbrd_gpiob_set()
341 unsigned int offset) in vprbrd_gpiob_direction_input() argument
345 struct vprbrd *vb = gpio->vb; in vprbrd_gpiob_direction_input()
347 gpio->gpiob_out &= ~(1 << offset); in vprbrd_gpiob_direction_input()
349 mutex_lock(&vb->lock); in vprbrd_gpiob_direction_input()
351 ret = vprbrd_gpiob_setdir(vb, offset, 0); in vprbrd_gpiob_direction_input()
353 mutex_unlock(&vb->lock); in vprbrd_gpiob_direction_input()
356 dev_err(chip->parent, "usb error setting pin to input\n"); in vprbrd_gpiob_direction_input()
362 unsigned int offset, int value) in vprbrd_gpiob_direction_output() argument
366 struct vprbrd *vb = gpio->vb; in vprbrd_gpiob_direction_output()
368 gpio->gpiob_out |= (1 << offset); in vprbrd_gpiob_direction_output()
370 mutex_lock(&vb->lock); in vprbrd_gpiob_direction_output()
372 ret = vprbrd_gpiob_setdir(vb, offset, 1); in vprbrd_gpiob_direction_output()
374 dev_err(chip->parent, "usb error setting pin to output\n"); in vprbrd_gpiob_direction_output()
376 mutex_unlock(&vb->lock); in vprbrd_gpiob_direction_output()
378 vprbrd_gpiob_set(chip, offset, value); in vprbrd_gpiob_direction_output()
383 /* ----- end of gpio b chip ---------------------------------------------- */
387 struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent); in vprbrd_gpio_probe()
391 vb_gpio = devm_kzalloc(&pdev->dev, sizeof(*vb_gpio), GFP_KERNEL); in vprbrd_gpio_probe()
393 return -ENOMEM; in vprbrd_gpio_probe()
395 vb_gpio->vb = vb; in vprbrd_gpio_probe()
397 vb_gpio->gpioa.label = "viperboard gpio a"; in vprbrd_gpio_probe()
398 vb_gpio->gpioa.parent = &pdev->dev; in vprbrd_gpio_probe()
399 vb_gpio->gpioa.owner = THIS_MODULE; in vprbrd_gpio_probe()
400 vb_gpio->gpioa.base = -1; in vprbrd_gpio_probe()
401 vb_gpio->gpioa.ngpio = 16; in vprbrd_gpio_probe()
402 vb_gpio->gpioa.can_sleep = true; in vprbrd_gpio_probe()
403 vb_gpio->gpioa.set = vprbrd_gpioa_set; in vprbrd_gpio_probe()
404 vb_gpio->gpioa.get = vprbrd_gpioa_get; in vprbrd_gpio_probe()
405 vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input; in vprbrd_gpio_probe()
406 vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output; in vprbrd_gpio_probe()
408 ret = devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpioa, vb_gpio); in vprbrd_gpio_probe()
413 vb_gpio->gpiob.label = "viperboard gpio b"; in vprbrd_gpio_probe()
414 vb_gpio->gpiob.parent = &pdev->dev; in vprbrd_gpio_probe()
415 vb_gpio->gpiob.owner = THIS_MODULE; in vprbrd_gpio_probe()
416 vb_gpio->gpiob.base = -1; in vprbrd_gpio_probe()
417 vb_gpio->gpiob.ngpio = 16; in vprbrd_gpio_probe()
418 vb_gpio->gpiob.can_sleep = true; in vprbrd_gpio_probe()
419 vb_gpio->gpiob.set = vprbrd_gpiob_set; in vprbrd_gpio_probe()
420 vb_gpio->gpiob.get = vprbrd_gpiob_get; in vprbrd_gpio_probe()
421 vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input; in vprbrd_gpio_probe()
422 vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output; in vprbrd_gpio_probe()
424 return devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpiob, vb_gpio); in vprbrd_gpio_probe()
428 .driver.name = "viperboard-gpio",
471 MODULE_ALIAS("platform:viperboard-gpio");