Lines Matching refs:ihid
64 #define i2c_hid_dbg(ihid, fmt, arg...) \ argument
67 dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \
215 struct i2c_hid *ihid = i2c_get_clientdata(client); in __i2c_hid_command() local
216 union command *cmd = (union command *)ihid->cmdbuf; in __i2c_hid_command()
227 cmd->c.reg = ihid->wHIDDescRegister; in __i2c_hid_command()
229 cmd->data[0] = ihid->hdesc_buffer[registerIndex]; in __i2c_hid_command()
230 cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1]; in __i2c_hid_command()
241 i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data); in __i2c_hid_command()
254 set_bit(I2C_HID_READ_PENDING, &ihid->flags); in __i2c_hid_command()
258 set_bit(I2C_HID_RESET_PENDING, &ihid->flags); in __i2c_hid_command()
263 clear_bit(I2C_HID_READ_PENDING, &ihid->flags); in __i2c_hid_command()
270 if (wait && (ihid->quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET)) { in __i2c_hid_command()
273 i2c_hid_dbg(ihid, "%s: waiting...\n", __func__); in __i2c_hid_command()
274 if (!wait_event_timeout(ihid->wait, in __i2c_hid_command()
275 !test_bit(I2C_HID_RESET_PENDING, &ihid->flags), in __i2c_hid_command()
278 i2c_hid_dbg(ihid, "%s: finished.\n", __func__); in __i2c_hid_command()
295 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_get_report() local
299 u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister); in i2c_hid_get_report()
301 i2c_hid_dbg(ihid, "%s\n", __func__); in i2c_hid_get_report()
334 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_set_or_send_report() local
335 u8 *args = ihid->argsbuf; in i2c_hid_set_or_send_report()
338 u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); in i2c_hid_set_or_send_report()
339 u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); in i2c_hid_set_or_send_report()
340 u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); in i2c_hid_set_or_send_report()
345 i2c_hid_dbg(ihid, "%s\n", __func__); in i2c_hid_set_or_send_report()
347 if (data_len > ihid->bufsize) in i2c_hid_set_or_send_report()
399 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_set_power() local
402 i2c_hid_dbg(ihid, "%s\n", __func__); in i2c_hid_set_power()
410 ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) { in i2c_hid_set_power()
443 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_hwreset() local
446 i2c_hid_dbg(ihid, "%s\n", __func__); in i2c_hid_hwreset()
453 mutex_lock(&ihid->reset_lock); in i2c_hid_hwreset()
459 i2c_hid_dbg(ihid, "resetting...\n"); in i2c_hid_hwreset()
469 if (!(ihid->quirks & I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET)) in i2c_hid_hwreset()
473 mutex_unlock(&ihid->reset_lock); in i2c_hid_hwreset()
477 static void i2c_hid_get_input(struct i2c_hid *ihid) in i2c_hid_get_input() argument
481 int size = le16_to_cpu(ihid->hdesc.wMaxInputLength); in i2c_hid_get_input()
483 if (size > ihid->bufsize) in i2c_hid_get_input()
484 size = ihid->bufsize; in i2c_hid_get_input()
486 ret = i2c_master_recv(ihid->client, ihid->inbuf, size); in i2c_hid_get_input()
491 dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n", in i2c_hid_get_input()
496 ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8; in i2c_hid_get_input()
500 if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags)) in i2c_hid_get_input()
501 wake_up(&ihid->wait); in i2c_hid_get_input()
505 if (ihid->quirks & I2C_HID_QUIRK_BOGUS_IRQ && ret_size == 0xffff) { in i2c_hid_get_input()
506 dev_warn_once(&ihid->client->dev, "%s: IRQ triggered but " in i2c_hid_get_input()
512 if (ihid->quirks & I2C_HID_QUIRK_BAD_INPUT_SIZE) { in i2c_hid_get_input()
513 ihid->inbuf[0] = size & 0xff; in i2c_hid_get_input()
514 ihid->inbuf[1] = size >> 8; in i2c_hid_get_input()
517 dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n", in i2c_hid_get_input()
523 i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf); in i2c_hid_get_input()
525 if (test_bit(I2C_HID_STARTED, &ihid->flags)) in i2c_hid_get_input()
526 hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2, in i2c_hid_get_input()
534 struct i2c_hid *ihid = dev_id; in i2c_hid_irq() local
536 if (test_bit(I2C_HID_READ_PENDING, &ihid->flags)) in i2c_hid_irq()
539 i2c_hid_get_input(ihid); in i2c_hid_irq()
568 static void i2c_hid_free_buffers(struct i2c_hid *ihid) in i2c_hid_free_buffers() argument
570 kfree(ihid->inbuf); in i2c_hid_free_buffers()
571 kfree(ihid->rawbuf); in i2c_hid_free_buffers()
572 kfree(ihid->argsbuf); in i2c_hid_free_buffers()
573 kfree(ihid->cmdbuf); in i2c_hid_free_buffers()
574 ihid->inbuf = NULL; in i2c_hid_free_buffers()
575 ihid->rawbuf = NULL; in i2c_hid_free_buffers()
576 ihid->cmdbuf = NULL; in i2c_hid_free_buffers()
577 ihid->argsbuf = NULL; in i2c_hid_free_buffers()
578 ihid->bufsize = 0; in i2c_hid_free_buffers()
581 static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size) in i2c_hid_alloc_buffers() argument
591 ihid->inbuf = kzalloc(report_size, GFP_KERNEL); in i2c_hid_alloc_buffers()
592 ihid->rawbuf = kzalloc(report_size, GFP_KERNEL); in i2c_hid_alloc_buffers()
593 ihid->argsbuf = kzalloc(args_len, GFP_KERNEL); in i2c_hid_alloc_buffers()
594 ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL); in i2c_hid_alloc_buffers()
596 if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) { in i2c_hid_alloc_buffers()
597 i2c_hid_free_buffers(ihid); in i2c_hid_alloc_buffers()
601 ihid->bufsize = report_size; in i2c_hid_alloc_buffers()
611 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_get_raw_report() local
630 ask_count = min(count + 2, (size_t)ihid->bufsize); in i2c_hid_get_raw_report()
634 report_number, ihid->rawbuf, ask_count); in i2c_hid_get_raw_report()
639 ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8); in i2c_hid_get_raw_report()
648 memcpy(buf, ihid->rawbuf + 2, count); in i2c_hid_get_raw_report()
660 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_output_raw_report() local
667 mutex_lock(&ihid->reset_lock); in i2c_hid_output_raw_report()
683 mutex_unlock(&ihid->reset_lock); in i2c_hid_output_raw_report()
714 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_parse() local
715 struct i2c_hid_desc *hdesc = &ihid->hdesc; in i2c_hid_parse()
722 i2c_hid_dbg(ihid, "entering %s\n", __func__); in i2c_hid_parse()
744 i2c_hid_dbg(ihid, "Using a HID report descriptor override\n"); in i2c_hid_parse()
753 i2c_hid_dbg(ihid, "asking HID report descriptor\n"); in i2c_hid_parse()
764 i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc); in i2c_hid_parse()
781 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_start() local
789 if (bufsize > ihid->bufsize) { in i2c_hid_start()
791 i2c_hid_free_buffers(ihid); in i2c_hid_start()
793 ret = i2c_hid_alloc_buffers(ihid, bufsize); in i2c_hid_start()
811 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_open() local
813 set_bit(I2C_HID_STARTED, &ihid->flags); in i2c_hid_open()
820 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_close() local
822 clear_bit(I2C_HID_STARTED, &ihid->flags); in i2c_hid_close()
838 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_init_irq() local
848 irqflags | IRQF_ONESHOT, client->name, ihid); in i2c_hid_init_irq()
861 static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) in i2c_hid_fetch_hid_descriptor() argument
863 struct i2c_client *client = ihid->client; in i2c_hid_fetch_hid_descriptor()
864 struct i2c_hid_desc *hdesc = &ihid->hdesc; in i2c_hid_fetch_hid_descriptor()
870 i2c_hid_dbg(ihid, "Using a HID descriptor override\n"); in i2c_hid_fetch_hid_descriptor()
871 ihid->hdesc = in i2c_hid_fetch_hid_descriptor()
874 i2c_hid_dbg(ihid, "Fetching the HID descriptor\n"); in i2c_hid_fetch_hid_descriptor()
876 ihid->hdesc_buffer, in i2c_hid_fetch_hid_descriptor()
902 i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer); in i2c_hid_fetch_hid_descriptor()
906 static int i2c_hid_core_power_up(struct i2c_hid *ihid) in i2c_hid_core_power_up() argument
908 if (!ihid->ops->power_up) in i2c_hid_core_power_up()
911 return ihid->ops->power_up(ihid->ops); in i2c_hid_core_power_up()
914 static void i2c_hid_core_power_down(struct i2c_hid *ihid) in i2c_hid_core_power_down() argument
916 if (!ihid->ops->power_down) in i2c_hid_core_power_down()
919 ihid->ops->power_down(ihid->ops); in i2c_hid_core_power_down()
922 static void i2c_hid_core_shutdown_tail(struct i2c_hid *ihid) in i2c_hid_core_shutdown_tail() argument
924 if (!ihid->ops->shutdown_tail) in i2c_hid_core_shutdown_tail()
927 ihid->ops->shutdown_tail(ihid->ops); in i2c_hid_core_shutdown_tail()
934 struct i2c_hid *ihid; in i2c_hid_core_probe() local
952 ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL); in i2c_hid_core_probe()
953 if (!ihid) in i2c_hid_core_probe()
956 ihid->ops = ops; in i2c_hid_core_probe()
958 ret = i2c_hid_core_power_up(ihid); in i2c_hid_core_probe()
962 i2c_set_clientdata(client, ihid); in i2c_hid_core_probe()
964 ihid->client = client; in i2c_hid_core_probe()
966 ihid->wHIDDescRegister = cpu_to_le16(hid_descriptor_address); in i2c_hid_core_probe()
968 init_waitqueue_head(&ihid->wait); in i2c_hid_core_probe()
969 mutex_init(&ihid->reset_lock); in i2c_hid_core_probe()
974 ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE); in i2c_hid_core_probe()
988 ret = i2c_hid_fetch_hid_descriptor(ihid); in i2c_hid_core_probe()
1005 ihid->hid = hid; in i2c_hid_core_probe()
1011 hid->version = le16_to_cpu(ihid->hdesc.bcdVersion); in i2c_hid_core_probe()
1012 hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID); in i2c_hid_core_probe()
1013 hid->product = le16_to_cpu(ihid->hdesc.wProductID); in i2c_hid_core_probe()
1023 ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product); in i2c_hid_core_probe()
1038 free_irq(client->irq, ihid); in i2c_hid_core_probe()
1041 i2c_hid_core_power_down(ihid); in i2c_hid_core_probe()
1042 i2c_hid_free_buffers(ihid); in i2c_hid_core_probe()
1049 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_core_remove() local
1052 hid = ihid->hid; in i2c_hid_core_remove()
1055 free_irq(client->irq, ihid); in i2c_hid_core_remove()
1057 if (ihid->bufsize) in i2c_hid_core_remove()
1058 i2c_hid_free_buffers(ihid); in i2c_hid_core_remove()
1060 i2c_hid_core_power_down(ihid); in i2c_hid_core_remove()
1068 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_core_shutdown() local
1071 free_irq(client->irq, ihid); in i2c_hid_core_shutdown()
1073 i2c_hid_core_shutdown_tail(ihid); in i2c_hid_core_shutdown()
1081 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_core_suspend() local
1082 struct hid_device *hid = ihid->hid; in i2c_hid_core_suspend()
1100 ihid->irq_wake_enabled = true; in i2c_hid_core_suspend()
1105 i2c_hid_core_power_down(ihid); in i2c_hid_core_suspend()
1115 struct i2c_hid *ihid = i2c_get_clientdata(client); in i2c_hid_core_resume() local
1116 struct hid_device *hid = ihid->hid; in i2c_hid_core_resume()
1120 i2c_hid_core_power_up(ihid); in i2c_hid_core_resume()
1121 } else if (ihid->irq_wake_enabled) { in i2c_hid_core_resume()
1124 ihid->irq_wake_enabled = false; in i2c_hid_core_resume()
1140 if (ihid->quirks & I2C_HID_QUIRK_RESET_ON_RESUME) in i2c_hid_core_resume()