Lines Matching +full:zero +full:- +full:initialised

1 // SPDX-License-Identifier: GPL-2.0
3 * U2F Zero LED and RNG driver
6 * Loosely based on drivers/hid/hid-led.c
23 #include "hid-ids.h"
29 /* We only use broadcast (CID-less) messages */
39 u8 data[HID_REPORT_SIZE - 7];
43 u8 data[HID_REPORT_SIZE - 5];
76 mutex_lock(&dev->lock); in u2fzero_send()
78 memcpy(dev->buf_out, req, sizeof(struct u2f_hid_report)); in u2fzero_send()
80 ret = hid_hw_output_report(dev->hdev, dev->buf_out, in u2fzero_send()
83 mutex_unlock(&dev->lock); in u2fzero_send()
88 return ret == sizeof(struct u2f_hid_msg) ? 0 : -EMSGSIZE; in u2fzero_send()
98 struct u2fzero_transfer_context *ctx = urb->context; in u2fzero_read_callback()
100 ctx->status = urb->status; in u2fzero_read_callback()
101 complete(&ctx->done); in u2fzero_read_callback()
109 struct hid_device *hdev = dev->hdev; in u2fzero_recv()
112 mutex_lock(&dev->lock); in u2fzero_recv()
114 memcpy(dev->buf_out, req, sizeof(struct u2f_hid_report)); in u2fzero_recv()
116 dev->urb->context = &ctx; in u2fzero_recv()
119 ret = usb_submit_urb(dev->urb, GFP_NOIO); in u2fzero_recv()
125 ret = hid_hw_output_report(dev->hdev, dev->buf_out, in u2fzero_recv()
136 usb_kill_urb(dev->urb); in u2fzero_recv()
139 ret = dev->urb->actual_length; in u2fzero_recv()
140 memcpy(resp, dev->buf_in, ret); in u2fzero_recv()
144 mutex_unlock(&dev->lock); in u2fzero_recv()
169 ldev->brightness = LED_OFF; in u2fzero_brightness_set()
195 if (!dev->present) { in u2fzero_rng_read()
196 hid_dbg(dev->hdev, "device not present"); in u2fzero_rng_read()
205 actual_length = min3((size_t)ret - offsetof(struct u2f_hid_msg, in u2fzero_rng_read()
216 dev->led_name = devm_kasprintf(&dev->hdev->dev, GFP_KERNEL, in u2fzero_init_led()
218 if (dev->led_name == NULL) in u2fzero_init_led()
219 return -ENOMEM; in u2fzero_init_led()
221 dev->ldev.name = dev->led_name; in u2fzero_init_led()
222 dev->ldev.max_brightness = LED_ON; in u2fzero_init_led()
223 dev->ldev.flags = LED_HW_PLUGGABLE; in u2fzero_init_led()
224 dev->ldev.brightness_set_blocking = u2fzero_brightness_set; in u2fzero_init_led()
226 return devm_led_classdev_register(&dev->hdev->dev, &dev->ldev); in u2fzero_init_led()
232 dev->rng_name = devm_kasprintf(&dev->hdev->dev, GFP_KERNEL, in u2fzero_init_hwrng()
233 "%s-rng%u", DRIVER_SHORT, minor); in u2fzero_init_hwrng()
234 if (dev->rng_name == NULL) in u2fzero_init_hwrng()
235 return -ENOMEM; in u2fzero_init_hwrng()
237 dev->hwrng.name = dev->rng_name; in u2fzero_init_hwrng()
238 dev->hwrng.read = u2fzero_rng_read; in u2fzero_init_hwrng()
239 dev->hwrng.quality = 1; in u2fzero_init_hwrng()
241 return devm_hwrng_register(&dev->hdev->dev, &dev->hwrng); in u2fzero_init_hwrng()
246 struct hid_device *hdev = dev->hdev; in u2fzero_fill_in_urb()
248 struct usbhid_device *usbhid = hdev->driver_data; in u2fzero_fill_in_urb()
252 if (dev->hdev->bus != BUS_USB) in u2fzero_fill_in_urb()
253 return -EINVAL; in u2fzero_fill_in_urb()
257 if (!usbhid->urbout || !usbhid->urbin) in u2fzero_fill_in_urb()
258 return -ENODEV; in u2fzero_fill_in_urb()
260 ep = usb_pipe_endpoint(udev, usbhid->urbin->pipe); in u2fzero_fill_in_urb()
262 return -ENODEV; in u2fzero_fill_in_urb()
264 dev->urb = usb_alloc_urb(0, GFP_KERNEL); in u2fzero_fill_in_urb()
265 if (!dev->urb) in u2fzero_fill_in_urb()
266 return -ENOMEM; in u2fzero_fill_in_urb()
268 pipe_in = (usbhid->urbin->pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30); in u2fzero_fill_in_urb()
270 usb_fill_int_urb(dev->urb, in u2fzero_fill_in_urb()
273 dev->buf_in, in u2fzero_fill_in_urb()
277 ep->desc.bInterval); in u2fzero_fill_in_urb()
290 return -EINVAL; in u2fzero_probe()
292 dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL); in u2fzero_probe()
294 return -ENOMEM; in u2fzero_probe()
296 dev->buf_out = devm_kmalloc(&hdev->dev, in u2fzero_probe()
298 if (dev->buf_out == NULL) in u2fzero_probe()
299 return -ENOMEM; in u2fzero_probe()
301 dev->buf_in = devm_kmalloc(&hdev->dev, in u2fzero_probe()
303 if (dev->buf_in == NULL) in u2fzero_probe()
304 return -ENOMEM; in u2fzero_probe()
310 dev->hdev = hdev; in u2fzero_probe()
312 mutex_init(&dev->lock); in u2fzero_probe()
320 dev->present = true; in u2fzero_probe()
322 minor = ((struct hidraw *) hdev->hidraw)->minor; in u2fzero_probe()
330 hid_info(hdev, "U2F Zero LED initialised\n"); in u2fzero_probe()
338 hid_info(hdev, "U2F Zero RNG initialised\n"); in u2fzero_probe()
347 mutex_lock(&dev->lock); in u2fzero_remove()
348 dev->present = false; in u2fzero_remove()
349 mutex_unlock(&dev->lock); in u2fzero_remove()
352 usb_poison_urb(dev->urb); in u2fzero_remove()
353 usb_free_urb(dev->urb); in u2fzero_remove()
364 .name = "hid-" DRIVER_SHORT,
374 MODULE_DESCRIPTION("U2F Zero LED and RNG driver");