Lines Matching refs:pcu
183 static void ims_pcu_buttons_report(struct ims_pcu *pcu, u32 data) in ims_pcu_buttons_report() argument
185 struct ims_pcu_buttons *buttons = &pcu->buttons; in ims_pcu_buttons_report()
199 static int ims_pcu_setup_buttons(struct ims_pcu *pcu, in ims_pcu_setup_buttons() argument
203 struct ims_pcu_buttons *buttons = &pcu->buttons; in ims_pcu_setup_buttons()
210 dev_err(pcu->dev, "Not enough memory for input device\n"); in ims_pcu_setup_buttons()
215 "IMS PCU#%d Button Interface", pcu->device_no); in ims_pcu_setup_buttons()
217 usb_make_path(pcu->udev, buttons->phys, sizeof(buttons->phys)); in ims_pcu_setup_buttons()
224 usb_to_input_id(pcu->udev, &input->id); in ims_pcu_setup_buttons()
225 input->dev.parent = &pcu->ctrl_intf->dev; in ims_pcu_setup_buttons()
238 dev_err(pcu->dev, in ims_pcu_setup_buttons()
249 static void ims_pcu_destroy_buttons(struct ims_pcu *pcu) in ims_pcu_destroy_buttons() argument
251 struct ims_pcu_buttons *buttons = &pcu->buttons; in ims_pcu_destroy_buttons()
261 static void ims_pcu_gamepad_report(struct ims_pcu *pcu, u32 data) in ims_pcu_gamepad_report() argument
263 struct ims_pcu_gamepad *gamepad = pcu->gamepad; in ims_pcu_gamepad_report()
283 static int ims_pcu_setup_gamepad(struct ims_pcu *pcu) in ims_pcu_setup_gamepad() argument
292 dev_err(pcu->dev, in ims_pcu_setup_gamepad()
301 "IMS PCU#%d Gamepad Interface", pcu->device_no); in ims_pcu_setup_gamepad()
303 usb_make_path(pcu->udev, gamepad->phys, sizeof(gamepad->phys)); in ims_pcu_setup_gamepad()
308 usb_to_input_id(pcu->udev, &input->id); in ims_pcu_setup_gamepad()
309 input->dev.parent = &pcu->ctrl_intf->dev; in ims_pcu_setup_gamepad()
325 dev_err(pcu->dev, in ims_pcu_setup_gamepad()
331 pcu->gamepad = gamepad; in ims_pcu_setup_gamepad()
340 static void ims_pcu_destroy_gamepad(struct ims_pcu *pcu) in ims_pcu_destroy_gamepad() argument
342 struct ims_pcu_gamepad *gamepad = pcu->gamepad; in ims_pcu_destroy_gamepad()
407 static void ims_pcu_report_events(struct ims_pcu *pcu) in ims_pcu_report_events() argument
409 u32 data = get_unaligned_be32(&pcu->read_buf[3]); in ims_pcu_report_events()
411 ims_pcu_buttons_report(pcu, data & ~IMS_PCU_GAMEPAD_MASK); in ims_pcu_report_events()
412 if (pcu->gamepad) in ims_pcu_report_events()
413 ims_pcu_gamepad_report(pcu, data); in ims_pcu_report_events()
416 static void ims_pcu_handle_response(struct ims_pcu *pcu) in ims_pcu_handle_response() argument
418 switch (pcu->read_buf[0]) { in ims_pcu_handle_response()
420 if (likely(pcu->setup_complete)) in ims_pcu_handle_response()
421 ims_pcu_report_events(pcu); in ims_pcu_handle_response()
430 if (pcu->read_buf[0] == pcu->expected_response && in ims_pcu_handle_response()
431 pcu->read_buf[1] == pcu->ack_id - 1) { in ims_pcu_handle_response()
433 memcpy(pcu->cmd_buf, pcu->read_buf, pcu->read_pos); in ims_pcu_handle_response()
434 pcu->cmd_buf_len = pcu->read_pos; in ims_pcu_handle_response()
435 complete(&pcu->cmd_done); in ims_pcu_handle_response()
441 static void ims_pcu_process_data(struct ims_pcu *pcu, struct urb *urb) in ims_pcu_process_data() argument
446 u8 data = pcu->urb_in_buf[i]; in ims_pcu_process_data()
449 if (!pcu->have_stx && data != IMS_PCU_PROTOCOL_STX) in ims_pcu_process_data()
452 if (pcu->have_dle) { in ims_pcu_process_data()
453 pcu->have_dle = false; in ims_pcu_process_data()
454 pcu->read_buf[pcu->read_pos++] = data; in ims_pcu_process_data()
455 pcu->check_sum += data; in ims_pcu_process_data()
461 if (pcu->have_stx) in ims_pcu_process_data()
462 dev_warn(pcu->dev, in ims_pcu_process_data()
464 pcu->read_pos); in ims_pcu_process_data()
465 pcu->have_stx = true; in ims_pcu_process_data()
466 pcu->have_dle = false; in ims_pcu_process_data()
467 pcu->read_pos = 0; in ims_pcu_process_data()
468 pcu->check_sum = 0; in ims_pcu_process_data()
472 pcu->have_dle = true; in ims_pcu_process_data()
476 if (pcu->read_pos < IMS_PCU_MIN_PACKET_LEN) { in ims_pcu_process_data()
477 dev_warn(pcu->dev, in ims_pcu_process_data()
479 pcu->read_pos); in ims_pcu_process_data()
480 } else if (pcu->check_sum != 0) { in ims_pcu_process_data()
481 dev_warn(pcu->dev, in ims_pcu_process_data()
483 pcu->read_pos); in ims_pcu_process_data()
485 ims_pcu_handle_response(pcu); in ims_pcu_process_data()
488 pcu->have_stx = false; in ims_pcu_process_data()
489 pcu->have_dle = false; in ims_pcu_process_data()
490 pcu->read_pos = 0; in ims_pcu_process_data()
494 pcu->read_buf[pcu->read_pos++] = data; in ims_pcu_process_data()
495 pcu->check_sum += data; in ims_pcu_process_data()
508 static int ims_pcu_send_cmd_chunk(struct ims_pcu *pcu, in ims_pcu_send_cmd_chunk() argument
513 error = usb_bulk_msg(pcu->udev, in ims_pcu_send_cmd_chunk()
514 usb_sndbulkpipe(pcu->udev, in ims_pcu_send_cmd_chunk()
515 pcu->ep_out->bEndpointAddress), in ims_pcu_send_cmd_chunk()
516 pcu->urb_out_buf, len, in ims_pcu_send_cmd_chunk()
519 dev_dbg(pcu->dev, in ims_pcu_send_cmd_chunk()
528 static int ims_pcu_send_command(struct ims_pcu *pcu, in ims_pcu_send_command() argument
539 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_STX; in ims_pcu_send_command()
542 pcu->urb_out_buf[count++] = command; in ims_pcu_send_command()
545 ack_id = pcu->ack_id++; in ims_pcu_send_command()
547 ack_id = pcu->ack_id++; in ims_pcu_send_command()
550 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_DLE; in ims_pcu_send_command()
552 pcu->urb_out_buf[count++] = ack_id; in ims_pcu_send_command()
558 if (count + delta >= pcu->max_out_size) { in ims_pcu_send_command()
559 error = ims_pcu_send_cmd_chunk(pcu, command, in ims_pcu_send_command()
568 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_DLE; in ims_pcu_send_command()
570 pcu->urb_out_buf[count++] = data[i]; in ims_pcu_send_command()
577 if (count + delta >= pcu->max_out_size) { in ims_pcu_send_command()
578 error = ims_pcu_send_cmd_chunk(pcu, command, ++chunk, count); in ims_pcu_send_command()
586 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_DLE; in ims_pcu_send_command()
588 pcu->urb_out_buf[count++] = csum; in ims_pcu_send_command()
589 pcu->urb_out_buf[count++] = IMS_PCU_PROTOCOL_ETX; in ims_pcu_send_command()
591 return ims_pcu_send_cmd_chunk(pcu, command, ++chunk, count); in ims_pcu_send_command()
594 static int __ims_pcu_execute_command(struct ims_pcu *pcu, in __ims_pcu_execute_command() argument
600 pcu->expected_response = expected_response; in __ims_pcu_execute_command()
601 init_completion(&pcu->cmd_done); in __ims_pcu_execute_command()
603 error = ims_pcu_send_command(pcu, command, data, len); in __ims_pcu_execute_command()
608 !wait_for_completion_timeout(&pcu->cmd_done, in __ims_pcu_execute_command()
610 dev_dbg(pcu->dev, "Command 0x%02x timed out\n", command); in __ims_pcu_execute_command()
617 #define ims_pcu_execute_command(pcu, code, data, len) \ argument
618 __ims_pcu_execute_command(pcu, \
623 #define ims_pcu_execute_query(pcu, code) \ argument
624 ims_pcu_execute_command(pcu, code, NULL, 0)
648 static int __ims_pcu_execute_bl_command(struct ims_pcu *pcu, in __ims_pcu_execute_bl_command() argument
654 pcu->cmd_buf[0] = command; in __ims_pcu_execute_bl_command()
656 memcpy(&pcu->cmd_buf[1], data, len); in __ims_pcu_execute_bl_command()
658 error = __ims_pcu_execute_command(pcu, in __ims_pcu_execute_bl_command()
659 IMS_PCU_CMD_BOOTLOADER, pcu->cmd_buf, len + 1, in __ims_pcu_execute_bl_command()
663 dev_err(pcu->dev, in __ims_pcu_execute_bl_command()
665 pcu->cmd_buf[0], error); in __ims_pcu_execute_bl_command()
669 if (expected_response && pcu->cmd_buf[2] != expected_response) { in __ims_pcu_execute_bl_command()
670 dev_err(pcu->dev, in __ims_pcu_execute_bl_command()
672 pcu->cmd_buf[2], expected_response); in __ims_pcu_execute_bl_command()
679 #define ims_pcu_execute_bl_command(pcu, code, data, len, timeout) \ argument
680 __ims_pcu_execute_bl_command(pcu, \
690 static int ims_pcu_get_info(struct ims_pcu *pcu) in ims_pcu_get_info() argument
694 error = ims_pcu_execute_query(pcu, GET_INFO); in ims_pcu_get_info()
696 dev_err(pcu->dev, in ims_pcu_get_info()
701 memcpy(pcu->part_number, in ims_pcu_get_info()
702 &pcu->cmd_buf[IMS_PCU_INFO_PART_OFFSET], in ims_pcu_get_info()
703 sizeof(pcu->part_number)); in ims_pcu_get_info()
704 memcpy(pcu->date_of_manufacturing, in ims_pcu_get_info()
705 &pcu->cmd_buf[IMS_PCU_INFO_DOM_OFFSET], in ims_pcu_get_info()
706 sizeof(pcu->date_of_manufacturing)); in ims_pcu_get_info()
707 memcpy(pcu->serial_number, in ims_pcu_get_info()
708 &pcu->cmd_buf[IMS_PCU_INFO_SERIAL_OFFSET], in ims_pcu_get_info()
709 sizeof(pcu->serial_number)); in ims_pcu_get_info()
714 static int ims_pcu_set_info(struct ims_pcu *pcu) in ims_pcu_set_info() argument
718 memcpy(&pcu->cmd_buf[IMS_PCU_INFO_PART_OFFSET], in ims_pcu_set_info()
719 pcu->part_number, sizeof(pcu->part_number)); in ims_pcu_set_info()
720 memcpy(&pcu->cmd_buf[IMS_PCU_INFO_DOM_OFFSET], in ims_pcu_set_info()
721 pcu->date_of_manufacturing, sizeof(pcu->date_of_manufacturing)); in ims_pcu_set_info()
722 memcpy(&pcu->cmd_buf[IMS_PCU_INFO_SERIAL_OFFSET], in ims_pcu_set_info()
723 pcu->serial_number, sizeof(pcu->serial_number)); in ims_pcu_set_info()
725 error = ims_pcu_execute_command(pcu, SET_INFO, in ims_pcu_set_info()
726 &pcu->cmd_buf[IMS_PCU_DATA_OFFSET], in ims_pcu_set_info()
729 dev_err(pcu->dev, in ims_pcu_set_info()
738 static int ims_pcu_switch_to_bootloader(struct ims_pcu *pcu) in ims_pcu_switch_to_bootloader() argument
743 error = ims_pcu_execute_command(pcu, JUMP_TO_BTLDR, NULL, 0); in ims_pcu_switch_to_bootloader()
745 dev_err(pcu->dev, in ims_pcu_switch_to_bootloader()
779 static int ims_pcu_verify_block(struct ims_pcu *pcu, in ims_pcu_verify_block() argument
785 fragment = (void *)&pcu->cmd_buf[1]; in ims_pcu_verify_block()
789 error = ims_pcu_execute_bl_command(pcu, READ_APP, NULL, 5, in ims_pcu_verify_block()
792 dev_err(pcu->dev, in ims_pcu_verify_block()
798 fragment = (void *)&pcu->cmd_buf[IMS_PCU_BL_DATA_OFFSET]; in ims_pcu_verify_block()
801 dev_err(pcu->dev, in ims_pcu_verify_block()
809 dev_err(pcu->dev, in ims_pcu_verify_block()
818 static int ims_pcu_flash_firmware(struct ims_pcu *pcu, in ims_pcu_flash_firmware() argument
829 error = ims_pcu_execute_bl_command(pcu, ERASE_APP, NULL, 0, 2000); in ims_pcu_flash_firmware()
831 dev_err(pcu->dev, in ims_pcu_flash_firmware()
847 fragment = (void *)&pcu->cmd_buf[1]; in ims_pcu_flash_firmware()
852 error = ims_pcu_execute_bl_command(pcu, PROGRAM_DEVICE, in ims_pcu_flash_firmware()
856 dev_err(pcu->dev, in ims_pcu_flash_firmware()
862 if (addr >= pcu->fw_start_addr && addr < pcu->fw_end_addr) { in ims_pcu_flash_firmware()
863 error = ims_pcu_verify_block(pcu, addr, len, rec->data); in ims_pcu_flash_firmware()
869 pcu->update_firmware_status = (count * 100) / n_fw_records; in ims_pcu_flash_firmware()
874 error = ims_pcu_execute_bl_command(pcu, PROGRAM_COMPLETE, in ims_pcu_flash_firmware()
877 dev_err(pcu->dev, in ims_pcu_flash_firmware()
884 static int ims_pcu_handle_firmware_update(struct ims_pcu *pcu, in ims_pcu_handle_firmware_update() argument
890 dev_info(pcu->dev, "Updating firmware %s, size: %zu\n", in ims_pcu_handle_firmware_update()
895 retval = ims_pcu_flash_firmware(pcu, fw, n_fw_records); in ims_pcu_handle_firmware_update()
899 retval = ims_pcu_execute_bl_command(pcu, LAUNCH_APP, NULL, 0, 0); in ims_pcu_handle_firmware_update()
901 dev_err(pcu->dev, in ims_pcu_handle_firmware_update()
906 pcu->update_firmware_status = retval; in ims_pcu_handle_firmware_update()
907 sysfs_notify(&pcu->dev->kobj, NULL, "update_firmware_status"); in ims_pcu_handle_firmware_update()
914 struct ims_pcu *pcu = context; in ims_pcu_process_async_firmware() local
918 dev_err(pcu->dev, "Failed to get firmware %s\n", in ims_pcu_process_async_firmware()
925 dev_err(pcu->dev, "Firmware %s is invalid\n", in ims_pcu_process_async_firmware()
930 scoped_guard(mutex, &pcu->cmd_mutex) in ims_pcu_process_async_firmware()
931 ims_pcu_handle_firmware_update(pcu, fw); in ims_pcu_process_async_firmware()
936 complete(&pcu->async_firmware_done); in ims_pcu_process_async_firmware()
950 struct ims_pcu *pcu = in ims_pcu_backlight_set_brightness() local
955 guard(mutex)(&pcu->cmd_mutex); in ims_pcu_backlight_set_brightness()
957 error = ims_pcu_execute_command(pcu, SET_BRIGHTNESS, in ims_pcu_backlight_set_brightness()
960 dev_warn(pcu->dev, in ims_pcu_backlight_set_brightness()
972 struct ims_pcu *pcu = in ims_pcu_backlight_get_brightness() local
977 guard(mutex)(&pcu->cmd_mutex); in ims_pcu_backlight_get_brightness()
979 error = ims_pcu_execute_query(pcu, GET_BRIGHTNESS); in ims_pcu_backlight_get_brightness()
981 dev_warn(pcu->dev, in ims_pcu_backlight_get_brightness()
988 get_unaligned_le16(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET]); in ims_pcu_backlight_get_brightness()
994 static int ims_pcu_setup_backlight(struct ims_pcu *pcu) in ims_pcu_setup_backlight() argument
996 struct ims_pcu_backlight *backlight = &pcu->backlight; in ims_pcu_setup_backlight()
1000 "pcu%d::kbd_backlight", pcu->device_no); in ims_pcu_setup_backlight()
1008 error = led_classdev_register(pcu->dev, &backlight->cdev); in ims_pcu_setup_backlight()
1010 dev_err(pcu->dev, in ims_pcu_setup_backlight()
1019 static void ims_pcu_destroy_backlight(struct ims_pcu *pcu) in ims_pcu_destroy_backlight() argument
1021 struct ims_pcu_backlight *backlight = &pcu->backlight; in ims_pcu_destroy_backlight()
1042 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_attribute_show() local
1045 char *field = (char *)pcu + attr->field_offset; in ims_pcu_attribute_show()
1056 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_attribute_store() local
1059 char *field = (char *)pcu + attr->field_offset; in ims_pcu_attribute_store()
1070 scoped_cond_guard(mutex_intr, return -EINTR, &pcu->cmd_mutex) { in ims_pcu_attribute_store()
1074 error = ims_pcu_set_info(pcu); in ims_pcu_attribute_store()
1080 ims_pcu_get_info(pcu); in ims_pcu_attribute_store()
1117 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_reset_device() local
1128 dev_info(pcu->dev, "Attempting to reset device\n"); in ims_pcu_reset_device()
1130 error = ims_pcu_execute_command(pcu, PCU_RESET, &reset_byte, 1); in ims_pcu_reset_device()
1132 dev_info(pcu->dev, in ims_pcu_reset_device()
1148 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_update_firmware_store() local
1160 error = request_ihex_firmware(&fw, IMS_PCU_FIRMWARE_NAME, pcu->dev); in ims_pcu_update_firmware_store()
1162 dev_err(pcu->dev, "Failed to request firmware %s, error: %d\n", in ims_pcu_update_firmware_store()
1167 scoped_cond_guard(mutex_intr, return -EINTR, &pcu->cmd_mutex) { in ims_pcu_update_firmware_store()
1176 if (pcu->bootloader_mode) in ims_pcu_update_firmware_store()
1177 error = ims_pcu_handle_firmware_update(pcu, fw); in ims_pcu_update_firmware_store()
1179 error = ims_pcu_switch_to_bootloader(pcu); in ims_pcu_update_firmware_store()
1197 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_update_firmware_status_show() local
1199 return sysfs_emit(buf, "%d\n", pcu->update_firmware_status); in ims_pcu_update_firmware_status_show()
1223 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_is_attr_visible() local
1226 if (pcu->bootloader_mode) { in ims_pcu_is_attr_visible()
1249 static int ims_pcu_read_ofn_config(struct ims_pcu *pcu, u8 addr, u8 *data) in ims_pcu_read_ofn_config() argument
1254 error = ims_pcu_execute_command(pcu, OFN_GET_CONFIG, in ims_pcu_read_ofn_config()
1259 result = (s16)get_unaligned_le16(pcu->cmd_buf + OFN_REG_RESULT_OFFSET); in ims_pcu_read_ofn_config()
1264 *data = pcu->cmd_buf[OFN_REG_RESULT_OFFSET]; in ims_pcu_read_ofn_config()
1268 static int ims_pcu_write_ofn_config(struct ims_pcu *pcu, u8 addr, u8 data) in ims_pcu_write_ofn_config() argument
1274 error = ims_pcu_execute_command(pcu, OFN_SET_CONFIG, in ims_pcu_write_ofn_config()
1279 result = (s16)get_unaligned_le16(pcu->cmd_buf + OFN_REG_RESULT_OFFSET); in ims_pcu_write_ofn_config()
1291 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_reg_data_show() local
1295 scoped_guard(mutex, &pcu->cmd_mutex) { in ims_pcu_ofn_reg_data_show()
1296 error = ims_pcu_read_ofn_config(pcu, pcu->ofn_reg_addr, &data); in ims_pcu_ofn_reg_data_show()
1309 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_reg_data_store() local
1317 guard(mutex)(&pcu->cmd_mutex); in ims_pcu_ofn_reg_data_store()
1319 error = ims_pcu_write_ofn_config(pcu, pcu->ofn_reg_addr, value); in ims_pcu_ofn_reg_data_store()
1334 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_reg_addr_show() local
1336 guard(mutex)(&pcu->cmd_mutex); in ims_pcu_ofn_reg_addr_show()
1338 return sysfs_emit(buf, "%x\n", pcu->ofn_reg_addr); in ims_pcu_ofn_reg_addr_show()
1346 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_reg_addr_store() local
1354 guard(mutex)(&pcu->cmd_mutex); in ims_pcu_ofn_reg_addr_store()
1356 pcu->ofn_reg_addr = value; in ims_pcu_ofn_reg_addr_store()
1375 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_bit_show() local
1381 scoped_guard(mutex, &pcu->cmd_mutex) { in ims_pcu_ofn_bit_show()
1382 error = ims_pcu_read_ofn_config(pcu, attr->addr, &data); in ims_pcu_ofn_bit_show()
1395 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_bit_store() local
1409 scoped_guard(mutex, &pcu->cmd_mutex) { in ims_pcu_ofn_bit_store()
1410 error = ims_pcu_read_ofn_config(pcu, attr->addr, &data); in ims_pcu_ofn_bit_store()
1419 error = ims_pcu_write_ofn_config(pcu, attr->addr, data); in ims_pcu_ofn_bit_store()
1462 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_ofn_is_attr_visible() local
1468 if (pcu->bootloader_mode || pcu->device_id == IMS_PCU_PCU_B_DEVICE_ID) in ims_pcu_ofn_is_attr_visible()
1482 struct ims_pcu *pcu = urb->context; in ims_pcu_irq() local
1495 dev_dbg(pcu->dev, "%s - urb shutting down with status: %d\n", in ims_pcu_irq()
1499 dev_dbg(pcu->dev, "%s - nonzero urb status received: %d\n", in ims_pcu_irq()
1504 dev_dbg(pcu->dev, "%s: received %d: %*ph\n", __func__, in ims_pcu_irq()
1505 urb->actual_length, urb->actual_length, pcu->urb_in_buf); in ims_pcu_irq()
1507 if (urb == pcu->urb_in) in ims_pcu_irq()
1508 ims_pcu_process_data(pcu, urb); in ims_pcu_irq()
1513 dev_err(pcu->dev, "%s - usb_submit_urb failed with result %d\n", in ims_pcu_irq()
1517 static int ims_pcu_buffers_alloc(struct ims_pcu *pcu) in ims_pcu_buffers_alloc() argument
1521 pcu->urb_in_buf = usb_alloc_coherent(pcu->udev, pcu->max_in_size, in ims_pcu_buffers_alloc()
1522 GFP_KERNEL, &pcu->read_dma); in ims_pcu_buffers_alloc()
1523 if (!pcu->urb_in_buf) { in ims_pcu_buffers_alloc()
1524 dev_err(pcu->dev, in ims_pcu_buffers_alloc()
1529 pcu->urb_in = usb_alloc_urb(0, GFP_KERNEL); in ims_pcu_buffers_alloc()
1530 if (!pcu->urb_in) { in ims_pcu_buffers_alloc()
1531 dev_err(pcu->dev, "Failed to allocate input URB\n"); in ims_pcu_buffers_alloc()
1536 pcu->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in ims_pcu_buffers_alloc()
1537 pcu->urb_in->transfer_dma = pcu->read_dma; in ims_pcu_buffers_alloc()
1539 usb_fill_bulk_urb(pcu->urb_in, pcu->udev, in ims_pcu_buffers_alloc()
1540 usb_rcvbulkpipe(pcu->udev, in ims_pcu_buffers_alloc()
1541 pcu->ep_in->bEndpointAddress), in ims_pcu_buffers_alloc()
1542 pcu->urb_in_buf, pcu->max_in_size, in ims_pcu_buffers_alloc()
1543 ims_pcu_irq, pcu); in ims_pcu_buffers_alloc()
1549 pcu->urb_out_buf = kmalloc(pcu->max_out_size, GFP_KERNEL); in ims_pcu_buffers_alloc()
1550 if (!pcu->urb_out_buf) { in ims_pcu_buffers_alloc()
1551 dev_err(pcu->dev, "Failed to allocate memory for write buffer\n"); in ims_pcu_buffers_alloc()
1556 pcu->urb_ctrl_buf = usb_alloc_coherent(pcu->udev, pcu->max_ctrl_size, in ims_pcu_buffers_alloc()
1557 GFP_KERNEL, &pcu->ctrl_dma); in ims_pcu_buffers_alloc()
1558 if (!pcu->urb_ctrl_buf) { in ims_pcu_buffers_alloc()
1559 dev_err(pcu->dev, in ims_pcu_buffers_alloc()
1565 pcu->urb_ctrl = usb_alloc_urb(0, GFP_KERNEL); in ims_pcu_buffers_alloc()
1566 if (!pcu->urb_ctrl) { in ims_pcu_buffers_alloc()
1567 dev_err(pcu->dev, "Failed to allocate input URB\n"); in ims_pcu_buffers_alloc()
1572 pcu->urb_ctrl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in ims_pcu_buffers_alloc()
1573 pcu->urb_ctrl->transfer_dma = pcu->ctrl_dma; in ims_pcu_buffers_alloc()
1575 usb_fill_int_urb(pcu->urb_ctrl, pcu->udev, in ims_pcu_buffers_alloc()
1576 usb_rcvintpipe(pcu->udev, in ims_pcu_buffers_alloc()
1577 pcu->ep_ctrl->bEndpointAddress), in ims_pcu_buffers_alloc()
1578 pcu->urb_ctrl_buf, pcu->max_ctrl_size, in ims_pcu_buffers_alloc()
1579 ims_pcu_irq, pcu, pcu->ep_ctrl->bInterval); in ims_pcu_buffers_alloc()
1584 usb_free_coherent(pcu->udev, pcu->max_ctrl_size, in ims_pcu_buffers_alloc()
1585 pcu->urb_ctrl_buf, pcu->ctrl_dma); in ims_pcu_buffers_alloc()
1587 kfree(pcu->urb_out_buf); in ims_pcu_buffers_alloc()
1589 usb_free_urb(pcu->urb_in); in ims_pcu_buffers_alloc()
1591 usb_free_coherent(pcu->udev, pcu->max_in_size, in ims_pcu_buffers_alloc()
1592 pcu->urb_in_buf, pcu->read_dma); in ims_pcu_buffers_alloc()
1596 static void ims_pcu_buffers_free(struct ims_pcu *pcu) in ims_pcu_buffers_free() argument
1598 usb_kill_urb(pcu->urb_in); in ims_pcu_buffers_free()
1599 usb_free_urb(pcu->urb_in); in ims_pcu_buffers_free()
1601 usb_free_coherent(pcu->udev, pcu->max_out_size, in ims_pcu_buffers_free()
1602 pcu->urb_in_buf, pcu->read_dma); in ims_pcu_buffers_free()
1604 kfree(pcu->urb_out_buf); in ims_pcu_buffers_free()
1606 usb_kill_urb(pcu->urb_ctrl); in ims_pcu_buffers_free()
1607 usb_free_urb(pcu->urb_ctrl); in ims_pcu_buffers_free()
1609 usb_free_coherent(pcu->udev, pcu->max_ctrl_size, in ims_pcu_buffers_free()
1610 pcu->urb_ctrl_buf, pcu->ctrl_dma); in ims_pcu_buffers_free()
1659 static int ims_pcu_parse_cdc_data(struct usb_interface *intf, struct ims_pcu *pcu) in ims_pcu_parse_cdc_data() argument
1668 pcu->ctrl_intf = usb_ifnum_to_if(pcu->udev, in ims_pcu_parse_cdc_data()
1670 if (!pcu->ctrl_intf) in ims_pcu_parse_cdc_data()
1673 alt = pcu->ctrl_intf->cur_altsetting; in ims_pcu_parse_cdc_data()
1678 pcu->ep_ctrl = &alt->endpoint[0].desc; in ims_pcu_parse_cdc_data()
1679 pcu->max_ctrl_size = usb_endpoint_maxp(pcu->ep_ctrl); in ims_pcu_parse_cdc_data()
1681 pcu->data_intf = usb_ifnum_to_if(pcu->udev, in ims_pcu_parse_cdc_data()
1683 if (!pcu->data_intf) in ims_pcu_parse_cdc_data()
1686 alt = pcu->data_intf->cur_altsetting; in ims_pcu_parse_cdc_data()
1688 dev_err(pcu->dev, in ims_pcu_parse_cdc_data()
1694 pcu->ep_out = &alt->endpoint[0].desc; in ims_pcu_parse_cdc_data()
1695 if (!usb_endpoint_is_bulk_out(pcu->ep_out)) { in ims_pcu_parse_cdc_data()
1696 dev_err(pcu->dev, in ims_pcu_parse_cdc_data()
1701 pcu->max_out_size = usb_endpoint_maxp(pcu->ep_out); in ims_pcu_parse_cdc_data()
1702 if (pcu->max_out_size < 8) { in ims_pcu_parse_cdc_data()
1703 dev_err(pcu->dev, in ims_pcu_parse_cdc_data()
1705 pcu->max_out_size); in ims_pcu_parse_cdc_data()
1709 pcu->ep_in = &alt->endpoint[1].desc; in ims_pcu_parse_cdc_data()
1710 if (!usb_endpoint_is_bulk_in(pcu->ep_in)) { in ims_pcu_parse_cdc_data()
1711 dev_err(pcu->dev, in ims_pcu_parse_cdc_data()
1716 pcu->max_in_size = usb_endpoint_maxp(pcu->ep_in); in ims_pcu_parse_cdc_data()
1717 if (pcu->max_in_size < 8) { in ims_pcu_parse_cdc_data()
1718 dev_err(pcu->dev, in ims_pcu_parse_cdc_data()
1720 pcu->max_in_size); in ims_pcu_parse_cdc_data()
1727 static int ims_pcu_start_io(struct ims_pcu *pcu) in ims_pcu_start_io() argument
1731 error = usb_submit_urb(pcu->urb_ctrl, GFP_KERNEL); in ims_pcu_start_io()
1733 dev_err(pcu->dev, in ims_pcu_start_io()
1739 error = usb_submit_urb(pcu->urb_in, GFP_KERNEL); in ims_pcu_start_io()
1741 dev_err(pcu->dev, in ims_pcu_start_io()
1744 usb_kill_urb(pcu->urb_ctrl); in ims_pcu_start_io()
1751 static void ims_pcu_stop_io(struct ims_pcu *pcu) in ims_pcu_stop_io() argument
1753 usb_kill_urb(pcu->urb_in); in ims_pcu_stop_io()
1754 usb_kill_urb(pcu->urb_ctrl); in ims_pcu_stop_io()
1757 static int ims_pcu_line_setup(struct ims_pcu *pcu) in ims_pcu_line_setup() argument
1759 struct usb_host_interface *interface = pcu->ctrl_intf->cur_altsetting; in ims_pcu_line_setup()
1760 struct usb_cdc_line_coding *line = (void *)pcu->cmd_buf; in ims_pcu_line_setup()
1767 error = usb_control_msg(pcu->udev, usb_sndctrlpipe(pcu->udev, 0), in ims_pcu_line_setup()
1774 dev_err(pcu->dev, "Failed to set line coding, error: %d\n", in ims_pcu_line_setup()
1779 error = usb_control_msg(pcu->udev, usb_sndctrlpipe(pcu->udev, 0), in ims_pcu_line_setup()
1785 dev_err(pcu->dev, "Failed to set line state, error: %d\n", in ims_pcu_line_setup()
1793 static int ims_pcu_get_device_info(struct ims_pcu *pcu) in ims_pcu_get_device_info() argument
1797 error = ims_pcu_get_info(pcu); in ims_pcu_get_device_info()
1801 error = ims_pcu_execute_query(pcu, GET_FW_VERSION); in ims_pcu_get_device_info()
1803 dev_err(pcu->dev, in ims_pcu_get_device_info()
1808 snprintf(pcu->fw_version, sizeof(pcu->fw_version), in ims_pcu_get_device_info()
1810 pcu->cmd_buf[2], pcu->cmd_buf[3], pcu->cmd_buf[4], pcu->cmd_buf[5], in ims_pcu_get_device_info()
1811 pcu->cmd_buf[6], pcu->cmd_buf[7]); in ims_pcu_get_device_info()
1813 error = ims_pcu_execute_query(pcu, GET_BL_VERSION); in ims_pcu_get_device_info()
1815 dev_err(pcu->dev, in ims_pcu_get_device_info()
1820 snprintf(pcu->bl_version, sizeof(pcu->bl_version), in ims_pcu_get_device_info()
1822 pcu->cmd_buf[2], pcu->cmd_buf[3], pcu->cmd_buf[4], pcu->cmd_buf[5], in ims_pcu_get_device_info()
1823 pcu->cmd_buf[6], pcu->cmd_buf[7]); in ims_pcu_get_device_info()
1825 error = ims_pcu_execute_query(pcu, RESET_REASON); in ims_pcu_get_device_info()
1827 dev_err(pcu->dev, in ims_pcu_get_device_info()
1832 snprintf(pcu->reset_reason, sizeof(pcu->reset_reason), in ims_pcu_get_device_info()
1833 "%02x", pcu->cmd_buf[IMS_PCU_DATA_OFFSET]); in ims_pcu_get_device_info()
1835 dev_dbg(pcu->dev, in ims_pcu_get_device_info()
1837 pcu->part_number, in ims_pcu_get_device_info()
1838 pcu->date_of_manufacturing, in ims_pcu_get_device_info()
1839 pcu->serial_number, in ims_pcu_get_device_info()
1840 pcu->fw_version, in ims_pcu_get_device_info()
1841 pcu->bl_version, in ims_pcu_get_device_info()
1842 pcu->reset_reason); in ims_pcu_get_device_info()
1847 static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id) in ims_pcu_identify_type() argument
1851 error = ims_pcu_execute_query(pcu, GET_DEVICE_ID); in ims_pcu_identify_type()
1853 dev_err(pcu->dev, in ims_pcu_identify_type()
1858 *device_id = pcu->cmd_buf[IMS_PCU_DATA_OFFSET]; in ims_pcu_identify_type()
1859 dev_dbg(pcu->dev, "Detected device ID: %d\n", *device_id); in ims_pcu_identify_type()
1864 static int ims_pcu_init_application_mode(struct ims_pcu *pcu) in ims_pcu_init_application_mode() argument
1871 error = ims_pcu_get_device_info(pcu); in ims_pcu_init_application_mode()
1877 error = ims_pcu_identify_type(pcu, &pcu->device_id); in ims_pcu_init_application_mode()
1879 dev_err(pcu->dev, in ims_pcu_init_application_mode()
1889 if (pcu->device_id >= ARRAY_SIZE(ims_pcu_device_info) || in ims_pcu_init_application_mode()
1890 !ims_pcu_device_info[pcu->device_id].keymap) { in ims_pcu_init_application_mode()
1891 dev_err(pcu->dev, "Device ID %d is not valid\n", pcu->device_id); in ims_pcu_init_application_mode()
1897 pcu->device_no = atomic_inc_return(&device_no); in ims_pcu_init_application_mode()
1899 error = ims_pcu_setup_backlight(pcu); in ims_pcu_init_application_mode()
1903 info = &ims_pcu_device_info[pcu->device_id]; in ims_pcu_init_application_mode()
1904 error = ims_pcu_setup_buttons(pcu, info->keymap, info->keymap_len); in ims_pcu_init_application_mode()
1909 error = ims_pcu_setup_gamepad(pcu); in ims_pcu_init_application_mode()
1914 pcu->setup_complete = true; in ims_pcu_init_application_mode()
1919 ims_pcu_destroy_buttons(pcu); in ims_pcu_init_application_mode()
1921 ims_pcu_destroy_backlight(pcu); in ims_pcu_init_application_mode()
1925 static void ims_pcu_destroy_application_mode(struct ims_pcu *pcu) in ims_pcu_destroy_application_mode() argument
1927 if (pcu->setup_complete) { in ims_pcu_destroy_application_mode()
1928 pcu->setup_complete = false; in ims_pcu_destroy_application_mode()
1931 if (pcu->gamepad) in ims_pcu_destroy_application_mode()
1932 ims_pcu_destroy_gamepad(pcu); in ims_pcu_destroy_application_mode()
1933 ims_pcu_destroy_buttons(pcu); in ims_pcu_destroy_application_mode()
1934 ims_pcu_destroy_backlight(pcu); in ims_pcu_destroy_application_mode()
1938 static int ims_pcu_init_bootloader_mode(struct ims_pcu *pcu) in ims_pcu_init_bootloader_mode() argument
1942 error = ims_pcu_execute_bl_command(pcu, QUERY_DEVICE, NULL, 0, in ims_pcu_init_bootloader_mode()
1945 dev_err(pcu->dev, "Bootloader does not respond, aborting\n"); in ims_pcu_init_bootloader_mode()
1949 pcu->fw_start_addr = in ims_pcu_init_bootloader_mode()
1950 get_unaligned_le32(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET + 11]); in ims_pcu_init_bootloader_mode()
1951 pcu->fw_end_addr = in ims_pcu_init_bootloader_mode()
1952 get_unaligned_le32(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET + 15]); in ims_pcu_init_bootloader_mode()
1954 dev_info(pcu->dev, in ims_pcu_init_bootloader_mode()
1956 pcu->fw_start_addr, pcu->fw_end_addr); in ims_pcu_init_bootloader_mode()
1960 pcu->dev, GFP_KERNEL, pcu, in ims_pcu_init_bootloader_mode()
1964 complete(&pcu->async_firmware_done); in ims_pcu_init_bootloader_mode()
1970 static void ims_pcu_destroy_bootloader_mode(struct ims_pcu *pcu) in ims_pcu_destroy_bootloader_mode() argument
1973 wait_for_completion(&pcu->async_firmware_done); in ims_pcu_destroy_bootloader_mode()
1985 struct ims_pcu *pcu; in ims_pcu_probe() local
1988 pcu = kzalloc(sizeof(*pcu), GFP_KERNEL); in ims_pcu_probe()
1989 if (!pcu) in ims_pcu_probe()
1992 pcu->dev = &intf->dev; in ims_pcu_probe()
1993 pcu->udev = udev; in ims_pcu_probe()
1994 pcu->bootloader_mode = id->driver_info == IMS_PCU_BOOTLOADER_MODE; in ims_pcu_probe()
1995 mutex_init(&pcu->cmd_mutex); in ims_pcu_probe()
1996 init_completion(&pcu->cmd_done); in ims_pcu_probe()
1997 init_completion(&pcu->async_firmware_done); in ims_pcu_probe()
1999 error = ims_pcu_parse_cdc_data(intf, pcu); in ims_pcu_probe()
2004 pcu->data_intf, pcu); in ims_pcu_probe()
2012 usb_set_intfdata(pcu->ctrl_intf, pcu); in ims_pcu_probe()
2014 error = ims_pcu_buffers_alloc(pcu); in ims_pcu_probe()
2018 error = ims_pcu_start_io(pcu); in ims_pcu_probe()
2022 error = ims_pcu_line_setup(pcu); in ims_pcu_probe()
2026 error = pcu->bootloader_mode ? in ims_pcu_probe()
2027 ims_pcu_init_bootloader_mode(pcu) : in ims_pcu_probe()
2028 ims_pcu_init_application_mode(pcu); in ims_pcu_probe()
2035 ims_pcu_stop_io(pcu); in ims_pcu_probe()
2037 ims_pcu_buffers_free(pcu); in ims_pcu_probe()
2039 usb_driver_release_interface(&ims_pcu_driver, pcu->data_intf); in ims_pcu_probe()
2041 kfree(pcu); in ims_pcu_probe()
2047 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_disconnect() local
2059 ims_pcu_stop_io(pcu); in ims_pcu_disconnect()
2061 if (pcu->bootloader_mode) in ims_pcu_disconnect()
2062 ims_pcu_destroy_bootloader_mode(pcu); in ims_pcu_disconnect()
2064 ims_pcu_destroy_application_mode(pcu); in ims_pcu_disconnect()
2066 ims_pcu_buffers_free(pcu); in ims_pcu_disconnect()
2067 kfree(pcu); in ims_pcu_disconnect()
2074 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_suspend() local
2078 ims_pcu_stop_io(pcu); in ims_pcu_suspend()
2085 struct ims_pcu *pcu = usb_get_intfdata(intf); in ims_pcu_resume() local
2090 retval = ims_pcu_start_io(pcu); in ims_pcu_resume()
2092 retval = ims_pcu_line_setup(pcu); in ims_pcu_resume()