Lines Matching +full:rmi4 +full:- +full:spi

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2015 Synaptics Incorporated
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-ioctl.h>
15 #include <media/videobuf2-v4l2.h>
16 #include <media/videobuf2-vmalloc.h>
29 * But this should be fine for i2c/spi as well.
43 * enum rmi_f54_report_type - RMI4 F54 report types
47 * @F54_8BIT_IMAGE: Normalized 8-Bit Image Report. The capacitance variance
50 * @F54_16BIT_IMAGE: Normalized 16-Bit Image Report. The capacitance variance
54 * Raw 16-Bit Image Report. The raw capacitance for each
87 [F54_8BIT_IMAGE] = "Normalized 8-Bit Image",
88 [F54_16BIT_IMAGE] = "Normalized 16-Bit Image",
89 [F54_RAW_16BIT_IMAGE] = "Raw 16-Bit Image",
139 return f54->capabilities & F54_CAP_IMAGE8; in is_f54_report_type_valid()
142 return f54->capabilities & F54_CAP_IMAGE16; in is_f54_report_type_valid()
144 return f54->capabilities & F54_CAP_IMAGE16; in is_f54_report_type_valid()
159 return f54->inputs[i]; in rmi_f54_get_reptype()
171 f54->inputs[i++] = reptype; in rmi_f54_create_input_map()
179 struct f54_data *f54 = dev_get_drvdata(&fn->dev); in rmi_f54_request_report()
180 struct rmi_device *rmi_dev = fn->rmi_dev; in rmi_f54_request_report()
184 if (f54->report_type != report_type) { in rmi_f54_request_report()
185 error = rmi_write(rmi_dev, f54->fn->fd.data_base_addr, in rmi_f54_request_report()
189 f54->report_type = report_type; in rmi_f54_request_report()
199 mutex_lock(&f54->data_mutex); in rmi_f54_request_report()
201 error = rmi_write(rmi_dev, fn->fd.command_base_addr, F54_GET_REPORT); in rmi_f54_request_report()
205 init_completion(&f54->cmd_done); in rmi_f54_request_report()
207 f54->is_busy = 1; in rmi_f54_request_report()
208 f54->timeout = jiffies + msecs_to_jiffies(100); in rmi_f54_request_report()
210 queue_delayed_work(f54->workqueue, &f54->work, 0); in rmi_f54_request_report()
213 mutex_unlock(&f54->data_mutex); in rmi_f54_request_report()
220 struct rmi_device *rmi_dev = f54->fn->rmi_dev; in rmi_f54_get_report_size()
221 struct rmi_driver_data *drv_data = dev_get_drvdata(&rmi_dev->dev); in rmi_f54_get_report_size()
222 u8 rx = drv_data->num_rx_electrodes ? : f54->num_rx_electrodes; in rmi_f54_get_report_size()
223 u8 tx = drv_data->num_tx_electrodes ? : f54->num_tx_electrodes; in rmi_f54_get_report_size()
226 switch (rmi_f54_get_reptype(f54, f54->input)) { in rmi_f54_get_report_size()
266 ret = -EINVAL; in rmi_f54_get_pixel_fmt()
287 struct f54_data *f54 = q->drv_priv; in rmi_f54_queue_setup()
290 return sizes[0] < rmi_f54_get_report_size(f54) ? -EINVAL : 0; in rmi_f54_queue_setup()
301 struct f54_data *f54 = vb2_get_drv_priv(vb->vb2_queue); in rmi_f54_buffer_queue()
307 mutex_lock(&f54->status_mutex); in rmi_f54_buffer_queue()
310 reptype = rmi_f54_get_reptype(f54, f54->input); in rmi_f54_buffer_queue()
316 if (f54->is_busy) { in rmi_f54_buffer_queue()
321 ret = rmi_f54_request_report(f54->fn, reptype); in rmi_f54_buffer_queue()
323 dev_err(&f54->fn->dev, "Error requesting F54 report\n"); in rmi_f54_buffer_queue()
329 mutex_lock(&f54->data_mutex); in rmi_f54_buffer_queue()
331 while (f54->is_busy) { in rmi_f54_buffer_queue()
332 mutex_unlock(&f54->data_mutex); in rmi_f54_buffer_queue()
333 if (!wait_for_completion_timeout(&f54->cmd_done, in rmi_f54_buffer_queue()
335 dev_err(&f54->fn->dev, "Timed out\n"); in rmi_f54_buffer_queue()
339 mutex_lock(&f54->data_mutex); in rmi_f54_buffer_queue()
344 dev_err(&f54->fn->dev, "Error acquiring frame ptr\n"); in rmi_f54_buffer_queue()
349 memcpy(ptr, f54->report_data, f54->report_size); in rmi_f54_buffer_queue()
354 mutex_unlock(&f54->data_mutex); in rmi_f54_buffer_queue()
356 vb->timestamp = ktime_get_ns(); in rmi_f54_buffer_queue()
357 vbuf->field = V4L2_FIELD_NONE; in rmi_f54_buffer_queue()
358 vbuf->sequence = f54->sequence++; in rmi_f54_buffer_queue()
360 mutex_unlock(&f54->status_mutex); in rmi_f54_buffer_queue()
367 f54->sequence = 0; in rmi_f54_stop_streaming()
393 strscpy(cap->driver, F54_NAME, sizeof(cap->driver)); in rmi_f54_vidioc_querycap()
394 strscpy(cap->card, SYNAPTICS_INPUT_DEVICE_NAME, sizeof(cap->card)); in rmi_f54_vidioc_querycap()
395 snprintf(cap->bus_info, sizeof(cap->bus_info), in rmi_f54_vidioc_querycap()
396 "rmi4:%s", dev_name(&f54->fn->dev)); in rmi_f54_vidioc_querycap()
407 reptype = rmi_f54_get_reptype(f54, i->index); in rmi_f54_vidioc_enum_input()
409 return -EINVAL; in rmi_f54_vidioc_enum_input()
411 i->type = V4L2_INPUT_TYPE_TOUCH; in rmi_f54_vidioc_enum_input()
413 strscpy(i->name, rmi_f54_report_type_names[reptype], sizeof(i->name)); in rmi_f54_vidioc_enum_input()
419 struct rmi_device *rmi_dev = f54->fn->rmi_dev; in rmi_f54_set_input()
420 struct rmi_driver_data *drv_data = dev_get_drvdata(&rmi_dev->dev); in rmi_f54_set_input()
421 u8 rx = drv_data->num_rx_electrodes ? : f54->num_rx_electrodes; in rmi_f54_set_input()
422 u8 tx = drv_data->num_tx_electrodes ? : f54->num_tx_electrodes; in rmi_f54_set_input()
423 struct v4l2_pix_format *f = &f54->format; in rmi_f54_set_input()
429 return -EINVAL; in rmi_f54_set_input()
431 ret = rmi_f54_get_pixel_fmt(reptype, &f->pixelformat); in rmi_f54_set_input()
435 f54->input = i; in rmi_f54_set_input()
437 f->width = rx; in rmi_f54_set_input()
438 f->height = tx; in rmi_f54_set_input()
439 f->field = V4L2_FIELD_NONE; in rmi_f54_set_input()
440 f->colorspace = V4L2_COLORSPACE_RAW; in rmi_f54_set_input()
441 f->bytesperline = f->width * sizeof(u16); in rmi_f54_set_input()
442 f->sizeimage = f->width * f->height * sizeof(u16); in rmi_f54_set_input()
457 *i = f54->input; in rmi_f54_vidioc_g_input()
467 f->fmt.pix = f54->format; in rmi_f54_vidioc_fmt()
477 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in rmi_f54_vidioc_enum_fmt()
478 return -EINVAL; in rmi_f54_vidioc_enum_fmt()
480 if (fmt->index) in rmi_f54_vidioc_enum_fmt()
481 return -EINVAL; in rmi_f54_vidioc_enum_fmt()
483 fmt->pixelformat = f54->format.pixelformat; in rmi_f54_vidioc_enum_fmt()
491 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in rmi_f54_vidioc_g_parm()
492 return -EINVAL; in rmi_f54_vidioc_g_parm()
494 a->parm.capture.readbuffers = 1; in rmi_f54_vidioc_g_parm()
495 a->parm.capture.timeperframe.numerator = 1; in rmi_f54_vidioc_g_parm()
496 a->parm.capture.timeperframe.denominator = 10; in rmi_f54_vidioc_g_parm()
525 .name = "Synaptics RMI4",
536 struct rmi_function *fn = f54->fn; in rmi_f54_work()
545 dev_err(&fn->dev, "Bad report size, report type=%d\n", in rmi_f54_work()
546 f54->report_type); in rmi_f54_work()
547 error = -EINVAL; in rmi_f54_work()
551 mutex_lock(&f54->data_mutex); in rmi_f54_work()
557 error = rmi_read(fn->rmi_dev, f54->fn->fd.command_base_addr, in rmi_f54_work()
560 dev_err(&fn->dev, "Failed to read back command\n"); in rmi_f54_work()
564 if (time_after(jiffies, f54->timeout)) { in rmi_f54_work()
565 dev_err(&fn->dev, "Get report command timed out\n"); in rmi_f54_work()
566 error = -ETIMEDOUT; in rmi_f54_work()
572 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Get report command completed, reading data\n"); in rmi_f54_work()
575 int size = min(F54_REPORT_DATA_SIZE, report_size - i); in rmi_f54_work()
579 error = rmi_write_block(fn->rmi_dev, in rmi_f54_work()
580 fn->fd.data_base_addr + F54_FIFO_OFFSET, in rmi_f54_work()
583 dev_err(&fn->dev, "Failed to set fifo start offset\n"); in rmi_f54_work()
587 error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr + in rmi_f54_work()
589 f54->report_data + i, size); in rmi_f54_work()
591 dev_err(&fn->dev, "%s: read [%d bytes] returned %d\n", in rmi_f54_work()
598 f54->report_size = error ? 0 : report_size; in rmi_f54_work()
604 queue_delayed_work(f54->workqueue, &f54->work, in rmi_f54_work()
607 f54->is_busy = false; in rmi_f54_work()
608 complete(&f54->cmd_done); in rmi_f54_work()
611 mutex_unlock(&f54->data_mutex); in rmi_f54_work()
616 struct rmi_driver *drv = fn->rmi_dev->driver; in rmi_f54_config()
618 drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask); in rmi_f54_config()
629 f54 = dev_get_drvdata(&fn->dev); in rmi_f54_detect()
631 error = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr, in rmi_f54_detect()
634 dev_err(&fn->dev, "%s: Failed to query F54 properties\n", in rmi_f54_detect()
639 f54->num_rx_electrodes = buf[0]; in rmi_f54_detect()
640 f54->num_tx_electrodes = buf[1]; in rmi_f54_detect()
641 f54->capabilities = buf[2]; in rmi_f54_detect()
642 f54->clock_rate = buf[3] | (buf[4] << 8); in rmi_f54_detect()
643 f54->family = buf[5]; in rmi_f54_detect()
645 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 num_rx_electrodes: %d\n", in rmi_f54_detect()
646 f54->num_rx_electrodes); in rmi_f54_detect()
647 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 num_tx_electrodes: %d\n", in rmi_f54_detect()
648 f54->num_tx_electrodes); in rmi_f54_detect()
649 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 capabilities: 0x%x\n", in rmi_f54_detect()
650 f54->capabilities); in rmi_f54_detect()
651 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 clock rate: 0x%x\n", in rmi_f54_detect()
652 f54->clock_rate); in rmi_f54_detect()
653 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "F54 family: 0x%x\n", in rmi_f54_detect()
654 f54->family); in rmi_f54_detect()
656 f54->is_busy = false; in rmi_f54_detect()
667 f54 = devm_kzalloc(&fn->dev, sizeof(struct f54_data), GFP_KERNEL); in rmi_f54_probe()
669 return -ENOMEM; in rmi_f54_probe()
671 f54->fn = fn; in rmi_f54_probe()
672 dev_set_drvdata(&fn->dev, f54); in rmi_f54_probe()
678 mutex_init(&f54->data_mutex); in rmi_f54_probe()
679 mutex_init(&f54->status_mutex); in rmi_f54_probe()
681 rx = f54->num_rx_electrodes; in rmi_f54_probe()
682 tx = f54->num_tx_electrodes; in rmi_f54_probe()
683 f54->report_data = devm_kzalloc(&fn->dev, in rmi_f54_probe()
686 if (f54->report_data == NULL) in rmi_f54_probe()
687 return -ENOMEM; in rmi_f54_probe()
689 INIT_DELAYED_WORK(&f54->work, rmi_f54_work); in rmi_f54_probe()
691 f54->workqueue = create_singlethread_workqueue("rmi4-poller"); in rmi_f54_probe()
692 if (!f54->workqueue) in rmi_f54_probe()
693 return -ENOMEM; in rmi_f54_probe()
699 strscpy(f54->v4l2.name, F54_NAME, sizeof(f54->v4l2.name)); in rmi_f54_probe()
700 ret = v4l2_device_register(&fn->dev, &f54->v4l2); in rmi_f54_probe()
702 dev_err(&fn->dev, "Unable to register video dev.\n"); in rmi_f54_probe()
707 mutex_init(&f54->lock); in rmi_f54_probe()
708 f54->queue = rmi_f54_queue; in rmi_f54_probe()
709 f54->queue.drv_priv = f54; in rmi_f54_probe()
710 f54->queue.lock = &f54->lock; in rmi_f54_probe()
711 f54->queue.dev = &fn->dev; in rmi_f54_probe()
713 ret = vb2_queue_init(&f54->queue); in rmi_f54_probe()
717 f54->vdev = rmi_f54_video_device; in rmi_f54_probe()
718 f54->vdev.v4l2_dev = &f54->v4l2; in rmi_f54_probe()
719 f54->vdev.lock = &f54->lock; in rmi_f54_probe()
720 f54->vdev.vfl_dir = VFL_DIR_RX; in rmi_f54_probe()
721 f54->vdev.queue = &f54->queue; in rmi_f54_probe()
722 video_set_drvdata(&f54->vdev, f54); in rmi_f54_probe()
724 ret = video_register_device(&f54->vdev, VFL_TYPE_TOUCH, -1); in rmi_f54_probe()
726 dev_err(&fn->dev, "Unable to register video subdevice."); in rmi_f54_probe()
733 v4l2_device_unregister(&f54->v4l2); in rmi_f54_probe()
735 cancel_delayed_work_sync(&f54->work); in rmi_f54_probe()
736 destroy_workqueue(f54->workqueue); in rmi_f54_probe()
742 struct f54_data *f54 = dev_get_drvdata(&fn->dev); in rmi_f54_remove()
744 video_unregister_device(&f54->vdev); in rmi_f54_remove()
745 v4l2_device_unregister(&f54->v4l2); in rmi_f54_remove()
746 destroy_workqueue(f54->workqueue); in rmi_f54_remove()