Lines Matching +full:num +full:- +full:ids

1 // SPDX-License-Identifier: GPL-2.0-only
30 (LJCA_MAX_PACKET_SIZE - sizeof(struct ljca_msg))
78 u8 num; member
79 struct ljca_i2c_ctr_info info[] __counted_by(num);
89 u8 num; member
90 struct ljca_spi_ctr_info info[] __counted_by(num);
108 * struct ljca_adapter - represent a ljca adapter
162 const struct acpi_device_id *ids; member
197 list_for_each_entry(client, &adap->client_list, link) { in ljca_handle_event()
203 if (client->type == header->type) { in ljca_handle_event()
206 spin_lock_irqsave(&client->event_cb_lock, flags); in ljca_handle_event()
207 client->event_cb(client->context, header->cmd, in ljca_handle_event()
208 header->data, header->len); in ljca_handle_event()
209 spin_unlock_irqrestore(&client->event_cb_lock, flags); in ljca_handle_event()
219 struct ljca_msg *tx_header = adap->tx_buf; in ljca_handle_cmd_ack()
224 spin_lock_irqsave(&adap->lock, flags); in ljca_handle_cmd_ack()
226 if (tx_header->type != header->type || tx_header->cmd != header->cmd) { in ljca_handle_cmd_ack()
227 spin_unlock_irqrestore(&adap->lock, flags); in ljca_handle_cmd_ack()
228 dev_err(adap->dev, "cmd ack mismatch error\n"); in ljca_handle_cmd_ack()
232 ibuf_len = adap->ex_buf_len; in ljca_handle_cmd_ack()
233 ibuf = adap->ex_buf; in ljca_handle_cmd_ack()
236 actual_len = min(header->len, ibuf_len); in ljca_handle_cmd_ack()
239 memcpy(ibuf, header->data, actual_len); in ljca_handle_cmd_ack()
242 adap->actual_length = actual_len; in ljca_handle_cmd_ack()
244 spin_unlock_irqrestore(&adap->lock, flags); in ljca_handle_cmd_ack()
246 complete(&adap->cmd_completion); in ljca_handle_cmd_ack()
251 struct ljca_msg *header = urb->transfer_buffer; in ljca_recv()
252 struct ljca_adapter *adap = urb->context; in ljca_recv()
255 switch (urb->status) { in ljca_recv()
259 case -ENOENT: in ljca_recv()
264 if (adap->disconnect) in ljca_recv()
265 complete(&adap->cmd_completion); in ljca_recv()
267 case -ECONNRESET: in ljca_recv()
268 case -ESHUTDOWN: in ljca_recv()
269 case -EPIPE: in ljca_recv()
271 dev_dbg(adap->dev, "rx urb terminated with status: %d\n", in ljca_recv()
272 urb->status); in ljca_recv()
275 dev_dbg(adap->dev, "rx urb error: %d\n", urb->status); in ljca_recv()
279 if (header->len + sizeof(*header) != urb->actual_length) in ljca_recv()
282 if (header->flags & LJCA_ACK_FLAG) in ljca_recv()
289 if (ret && ret != -EPERM) in ljca_recv()
290 dev_err(adap->dev, "resubmit rx urb error %d\n", ret); in ljca_recv()
298 struct ljca_msg *header = adap->tx_buf; in ljca_send()
303 if (adap->disconnect) in ljca_send()
304 return -ENODEV; in ljca_send()
306 if (msg_len > adap->tx_buf_len) in ljca_send()
307 return -EINVAL; in ljca_send()
309 mutex_lock(&adap->mutex); in ljca_send()
311 spin_lock_irqsave(&adap->lock, flags); in ljca_send()
313 header->type = type; in ljca_send()
314 header->cmd = cmd; in ljca_send()
315 header->len = obuf_len; in ljca_send()
317 memcpy(header->data, obuf, obuf_len); in ljca_send()
319 header->flags = LJCA_CMPL_FLAG | (ack ? LJCA_ACK_FLAG : 0); in ljca_send()
321 adap->ex_buf = ibuf; in ljca_send()
322 adap->ex_buf_len = ibuf_len; in ljca_send()
323 adap->actual_length = 0; in ljca_send()
325 spin_unlock_irqrestore(&adap->lock, flags); in ljca_send()
327 reinit_completion(&adap->cmd_completion); in ljca_send()
329 ret = usb_autopm_get_interface(adap->intf); in ljca_send()
333 ret = usb_bulk_msg(adap->usb_dev, adap->tx_pipe, header, in ljca_send()
336 usb_autopm_put_interface(adap->intf); in ljca_send()
341 ret = -EIO; in ljca_send()
346 ret = wait_for_completion_timeout(&adap->cmd_completion, in ljca_send()
349 ret = -ETIMEDOUT; in ljca_send()
353 ret = adap->actual_length; in ljca_send()
356 spin_lock_irqsave(&adap->lock, flags); in ljca_send()
357 adap->ex_buf = NULL; in ljca_send()
358 adap->ex_buf_len = 0; in ljca_send()
361 spin_unlock_irqrestore(&adap->lock, flags); in ljca_send()
363 mutex_unlock(&adap->mutex); in ljca_send()
371 return ljca_send(client->adapter, client->type, cmd, in ljca_transfer()
380 return ljca_send(client->adapter, client->type, cmd, obuf, in ljca_transfer_noack()
391 return -EINVAL; in ljca_register_event_cb()
393 spin_lock_irqsave(&client->event_cb_lock, flags); in ljca_register_event_cb()
395 if (client->event_cb) { in ljca_register_event_cb()
396 spin_unlock_irqrestore(&client->event_cb_lock, flags); in ljca_register_event_cb()
397 return -EALREADY; in ljca_register_event_cb()
400 client->event_cb = event_cb; in ljca_register_event_cb()
401 client->context = context; in ljca_register_event_cb()
403 spin_unlock_irqrestore(&client->event_cb_lock, flags); in ljca_register_event_cb()
413 spin_lock_irqsave(&client->event_cb_lock, flags); in ljca_unregister_event_cb()
415 client->event_cb = NULL; in ljca_unregister_event_cb()
416 client->context = NULL; in ljca_unregister_event_cb()
418 spin_unlock_irqrestore(&client->event_cb_lock, flags); in ljca_unregister_event_cb()
427 if (acpi_match_device_ids(adev, wd->ids)) in ljca_match_device_ids()
430 if (!wd->uid) in ljca_match_device_ids()
444 uid = strchr(uid, wd->uid[0]); in ljca_match_device_ids()
446 if (!uid || strcmp(uid, wd->uid)) in ljca_match_device_ids()
450 wd->adev = adev; in ljca_match_device_ids()
461 struct device *dev = adap->dev; in ljca_auxdev_acpi_bind()
475 wd.ids = ljca_gpio_hids; in ljca_auxdev_acpi_bind()
481 wd.ids = ljca_i2c_hids; in ljca_auxdev_acpi_bind()
485 wd.ids = ljca_spi_hids; in ljca_auxdev_acpi_bind()
494 ACPI_COMPANION_SET(&auxdev->dev, wd.adev); in ljca_auxdev_acpi_bind()
498 parent = ACPI_COMPANION(dev->parent->parent); in ljca_auxdev_acpi_bind()
504 ACPI_COMPANION_SET(&auxdev->dev, wd.adev); in ljca_auxdev_acpi_bind()
511 kfree(auxdev->dev.platform_data); in ljca_auxdev_release()
524 return -ENOMEM; in ljca_new_client_device()
527 client->type = type; in ljca_new_client_device()
528 client->id = id; in ljca_new_client_device()
529 client->adapter = adap; in ljca_new_client_device()
530 spin_lock_init(&client->event_cb_lock); in ljca_new_client_device()
532 auxdev = &client->auxdev; in ljca_new_client_device()
533 auxdev->name = name; in ljca_new_client_device()
534 auxdev->id = id; in ljca_new_client_device()
536 auxdev->dev.parent = adap->dev; in ljca_new_client_device()
537 auxdev->dev.platform_data = data; in ljca_new_client_device()
538 auxdev->dev.release = ljca_auxdev_release; in ljca_new_client_device()
552 list_add_tail(&client->link, &adap->client_list); in ljca_new_client_device()
581 if (ret != struct_size(desc, bank_desc, desc->bank_num)) in ljca_enumerate_gpio()
582 return -EINVAL; in ljca_enumerate_gpio()
584 gpio_num = desc->pins_per_bank * desc->bank_num; in ljca_enumerate_gpio()
586 return -EINVAL; in ljca_enumerate_gpio()
591 return -ENOMEM; in ljca_enumerate_gpio()
592 gpio_info->num = gpio_num; in ljca_enumerate_gpio()
594 for (i = 0; i < desc->bank_num; i++) in ljca_enumerate_gpio()
595 valid_pin[i] = get_unaligned_le32(&desc->bank_desc[i].valid_pins); in ljca_enumerate_gpio()
596 bitmap_from_arr32(gpio_info->valid_pin_map, valid_pin, gpio_num); in ljca_enumerate_gpio()
598 return ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio", in ljca_enumerate_gpio()
617 if (ret != struct_size(desc, info, desc->num)) in ljca_enumerate_i2c()
618 return -EINVAL; in ljca_enumerate_i2c()
620 for (i = 0; i < desc->num; i++) { in ljca_enumerate_i2c()
624 return -ENOMEM; in ljca_enumerate_i2c()
626 i2c_info->id = desc->info[i].id; in ljca_enumerate_i2c()
627 i2c_info->capacity = desc->info[i].capacity; in ljca_enumerate_i2c()
628 i2c_info->intr_pin = desc->info[i].intr_pin; in ljca_enumerate_i2c()
631 "ljca-i2c", i2c_info, in ljca_enumerate_i2c()
652 return (ret == -ETIMEDOUT) ? 0 : ret; in ljca_enumerate_spi()
656 if (ret != struct_size(desc, info, desc->num)) in ljca_enumerate_spi()
657 return -EINVAL; in ljca_enumerate_spi()
659 for (i = 0; i < desc->num; i++) { in ljca_enumerate_spi()
663 return -ENOMEM; in ljca_enumerate_spi()
665 spi_info->id = desc->info[i].id; in ljca_enumerate_spi()
666 spi_info->capacity = desc->info[i].capacity; in ljca_enumerate_spi()
669 "ljca-spi", spi_info, in ljca_enumerate_spi()
680 __le32 reset_id = cpu_to_le32(adap->reset_id); in ljca_reset_handshake()
684 adap->reset_id++; in ljca_reset_handshake()
693 return -EINVAL; in ljca_reset_handshake()
709 dev_err(adap->dev, "enumerate GPIO error\n"); in ljca_enumerate_clients()
715 dev_err(adap->dev, "enumerate I2C error\n"); in ljca_enumerate_clients()
721 dev_err(adap->dev, "enumerate SPI error\n"); in ljca_enumerate_clients()
728 adap->disconnect = true; in ljca_enumerate_clients()
730 usb_kill_urb(adap->rx_urb); in ljca_enumerate_clients()
732 list_for_each_entry_safe_reverse(client, next, &adap->client_list, link) { in ljca_enumerate_clients()
733 auxiliary_device_delete(&client->auxdev); in ljca_enumerate_clients()
734 auxiliary_device_uninit(&client->auxdev); in ljca_enumerate_clients()
736 list_del_init(&client->link); in ljca_enumerate_clients()
747 struct usb_host_interface *alt = interface->cur_altsetting; in ljca_probe()
749 struct device *dev = &interface->dev; in ljca_probe()
755 return -ENOMEM; in ljca_probe()
758 adap->tx_buf = devm_kzalloc(dev, LJCA_MAX_PACKET_SIZE, GFP_KERNEL); in ljca_probe()
759 if (!adap->tx_buf) in ljca_probe()
760 return -ENOMEM; in ljca_probe()
761 adap->tx_buf_len = LJCA_MAX_PACKET_SIZE; in ljca_probe()
763 mutex_init(&adap->mutex); in ljca_probe()
764 spin_lock_init(&adap->lock); in ljca_probe()
765 init_completion(&adap->cmd_completion); in ljca_probe()
766 INIT_LIST_HEAD(&adap->client_list); in ljca_probe()
768 adap->intf = usb_get_intf(interface); in ljca_probe()
769 adap->usb_dev = usb_dev; in ljca_probe()
770 adap->dev = dev; in ljca_probe()
781 adap->rx_pipe = usb_rcvbulkpipe(usb_dev, usb_endpoint_num(ep_in)); in ljca_probe()
782 adap->tx_pipe = usb_sndbulkpipe(usb_dev, usb_endpoint_num(ep_out)); in ljca_probe()
785 adap->rx_len = usb_endpoint_maxp(ep_in); in ljca_probe()
786 adap->rx_buf = devm_kzalloc(dev, adap->rx_len, GFP_KERNEL); in ljca_probe()
787 if (!adap->rx_buf) { in ljca_probe()
788 ret = -ENOMEM; in ljca_probe()
793 adap->rx_urb = usb_alloc_urb(0, GFP_KERNEL); in ljca_probe()
794 if (!adap->rx_urb) { in ljca_probe()
795 ret = -ENOMEM; in ljca_probe()
798 usb_fill_bulk_urb(adap->rx_urb, usb_dev, adap->rx_pipe, in ljca_probe()
799 adap->rx_buf, adap->rx_len, ljca_recv, adap); in ljca_probe()
804 ret = usb_submit_urb(adap->rx_urb, GFP_KERNEL); in ljca_probe()
819 usb_free_urb(adap->rx_urb); in ljca_probe()
822 usb_put_intf(adap->intf); in ljca_probe()
824 mutex_destroy(&adap->mutex); in ljca_probe()
834 adap->disconnect = true; in ljca_disconnect()
836 usb_kill_urb(adap->rx_urb); in ljca_disconnect()
838 list_for_each_entry_safe_reverse(client, next, &adap->client_list, link) { in ljca_disconnect()
839 auxiliary_device_delete(&client->auxdev); in ljca_disconnect()
840 auxiliary_device_uninit(&client->auxdev); in ljca_disconnect()
842 list_del_init(&client->link); in ljca_disconnect()
846 usb_free_urb(adap->rx_urb); in ljca_disconnect()
848 usb_put_intf(adap->intf); in ljca_disconnect()
850 mutex_destroy(&adap->mutex); in ljca_disconnect()
857 usb_kill_urb(adap->rx_urb); in ljca_suspend()
866 return usb_submit_urb(adap->rx_urb, GFP_KERNEL); in ljca_resume()