Lines Matching +full:event +full:- +full:touch +full:- +full:alt
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2015-2018 Federico Lorenzi
6 * Copyright (c) 2017-2018 Ronald Tschalär
26 * SPI-based Protocol
27 * ------------------
40 * fixed, 256-byte size). In that case it will be split over multiple,
84 ((KBD_BL_LEVEL_MAX - KBD_BL_LEVEL_MIN) * KBD_BL_LEVEL_SCALE / 255U)
101 …emap Fn key ([0] = no-remap; 1 = left-ctrl, 2 = left-shift, 3 = left-alt, 4 = left-meta, 6 = right…
105 MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. ([0] = disabled,…
113 * struct keyboard_protocol - keyboard message.
117 * @modifiers: bit-set of modifier/control keys pressed
119 * @keys_pressed: the (non-modifier) keys currently pressed
134 * struct tp_finger - single trackpad finger structure, le16-aligned
144 * @touch_major: touch area, major axis
145 * @touch_minor: touch area, minor axis
171 * struct touchpad_protocol - touchpad message.
175 * @clicked: 1 if a button-click was detected, 0 otherwise
193 * struct command_protocol_tp_info - get touchpad info.
204 * struct touchpad_info - touchpad info response.
224 * struct command_protocol_mt_init - initialize multitouch.
237 * struct command_protocol_capsl - toggle caps-lock led
252 * struct command_protocol_bl - set keyboard backlight brightness
269 * struct message - a complete spi message.
271 * Each message begins with fixed header, followed by a message-type specific
272 * payload, and ends with a 16-bit crc. Because of the varying lengths of the
286 * structure (after re-assembly in case of being split over
287 * multiple spi-packets), minus the trailing crc. The total size
312 * struct spi_packet - a complete spi packet; always 256 bytes. This carries
333 * covers just this packet, even on multi-packet messages (in
347 u64 spi_cs_delay; /* cs-to-clk delay in us */
348 u64 reset_a2r_usec; /* active-to-receive delay? */
502 .tp_info = { -5087, -182, 5579, 6089 },
506 .tp_info = { -6243, -170, 6749, 7685 },
510 .tp_info = { -7456, -163, 7976, 9283 },
541 struct spi_message *msg = &applespi->rd_m; in applespi_setup_read_txfrs()
542 struct spi_transfer *dl_t = &applespi->dl_t; in applespi_setup_read_txfrs()
543 struct spi_transfer *rd_t = &applespi->rd_t; in applespi_setup_read_txfrs()
548 dl_t->delay_usecs = applespi->spi_settings.spi_cs_delay; in applespi_setup_read_txfrs()
550 rd_t->rx_buf = applespi->rx_buffer; in applespi_setup_read_txfrs()
551 rd_t->len = APPLESPI_PACKET_SIZE; in applespi_setup_read_txfrs()
560 struct spi_message *msg = &applespi->wr_m; in applespi_setup_write_txfrs()
561 struct spi_transfer *wt_t = &applespi->ww_t; in applespi_setup_write_txfrs()
562 struct spi_transfer *dl_t = &applespi->wd_t; in applespi_setup_write_txfrs()
563 struct spi_transfer *wr_t = &applespi->wr_t; in applespi_setup_write_txfrs()
564 struct spi_transfer *st_t = &applespi->st_t; in applespi_setup_write_txfrs()
577 wt_t->delay_usecs = SPI_RW_CHG_DELAY_US; in applespi_setup_write_txfrs()
578 wt_t->cs_change = 1; in applespi_setup_write_txfrs()
580 dl_t->delay_usecs = applespi->spi_settings.spi_cs_delay; in applespi_setup_write_txfrs()
582 wr_t->tx_buf = applespi->tx_buffer; in applespi_setup_write_txfrs()
583 wr_t->len = APPLESPI_PACKET_SIZE; in applespi_setup_write_txfrs()
584 wr_t->delay_usecs = SPI_RW_CHG_DELAY_US; in applespi_setup_write_txfrs()
586 st_t->rx_buf = applespi->tx_status; in applespi_setup_write_txfrs()
587 st_t->len = APPLESPI_STATUS_SIZE; in applespi_setup_write_txfrs()
599 message->complete = complete; in applespi_async()
600 message->context = applespi; in applespi_async()
602 return spi_async(applespi->spi, message); in applespi_async()
611 dev_warn(&applespi->spi->dev, "Error writing to device: %d\n", in applespi_check_write_status()
616 if (memcmp(applespi->tx_status, status_ok, APPLESPI_STATUS_SIZE)) { in applespi_check_write_status()
617 dev_warn(&applespi->spi->dev, "Error writing to device: %*ph\n", in applespi_check_write_status()
618 APPLESPI_STATUS_SIZE, applespi->tx_status); in applespi_check_write_status()
627 struct acpi_device *adev = ACPI_COMPANION(&applespi->spi->dev); in applespi_get_spi_settings()
629 struct spi_settings *settings = &applespi->spi_settings; in applespi_get_spi_settings()
632 settings->spi_cs_delay = *(u64 *)o->buffer.pointer; in applespi_get_spi_settings()
634 dev_warn(&applespi->spi->dev, in applespi_get_spi_settings()
638 settings->reset_a2r_usec = *(u64 *)o->buffer.pointer; in applespi_get_spi_settings()
640 dev_warn(&applespi->spi->dev, in applespi_get_spi_settings()
644 settings->reset_rec_usec = *(u64 *)o->buffer.pointer; in applespi_get_spi_settings()
646 dev_warn(&applespi->spi->dev, in applespi_get_spi_settings()
649 dev_dbg(&applespi->spi->dev, in applespi_get_spi_settings()
651 settings->spi_cs_delay, settings->reset_a2r_usec, in applespi_get_spi_settings()
652 settings->reset_rec_usec); in applespi_get_spi_settings()
665 spin_lock_init(&applespi->cmd_msg_lock); in applespi_setup_spi()
666 init_waitqueue_head(&applespi->drain_complete); in applespi_setup_spi()
677 acpi_sts = acpi_evaluate_integer(applespi->sist, NULL, NULL, in applespi_enable_spi()
683 acpi_sts = acpi_execute_simple_method(applespi->sien, NULL, 1); in applespi_enable_spi()
685 dev_err(&applespi->spi->dev, "SIEN failed: %s\n", in applespi_enable_spi()
687 return -ENODEV; in applespi_enable_spi()
708 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_msg_complete()
711 applespi->read_active = false; in applespi_msg_complete()
713 applespi->write_active = false; in applespi_msg_complete()
715 if (applespi->drain && !applespi->write_active) in applespi_msg_complete()
716 wake_up_all(&applespi->drain_complete); in applespi_msg_complete()
719 applespi->cmd_msg_queued = false; in applespi_msg_complete()
723 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_msg_complete()
729 enum applespi_evt_type evt_type = applespi->cmd_evt_type; in applespi_async_write_complete()
732 applespi->tx_buffer, in applespi_async_write_complete()
735 applespi->tx_status, in applespi_async_write_complete()
738 if (!applespi_check_write_status(applespi, applespi->wr_m.status)) { in applespi_async_write_complete()
751 struct spi_packet *packet = (struct spi_packet *)applespi->tx_buffer; in applespi_send_cmd_msg()
752 struct message *message = (struct message *)packet->data; in applespi_send_cmd_msg()
757 if (applespi->drain) in applespi_send_cmd_msg()
761 if (applespi->cmd_msg_queued) in applespi_send_cmd_msg()
768 if (applespi->want_tp_info_cmd) { in applespi_send_cmd_msg()
769 applespi->want_tp_info_cmd = false; in applespi_send_cmd_msg()
770 applespi->want_mt_init_cmd = true; in applespi_send_cmd_msg()
771 applespi->cmd_evt_type = ET_CMD_TP_INI; in applespi_send_cmd_msg()
776 message->type = cpu_to_le16(0x1020); in applespi_send_cmd_msg()
777 msg_len = sizeof(message->tp_info_command); in applespi_send_cmd_msg()
779 message->zero = 0x02; in applespi_send_cmd_msg()
780 message->rsp_buf_len = cpu_to_le16(0x0200); in applespi_send_cmd_msg()
782 } else if (applespi->want_mt_init_cmd) { in applespi_send_cmd_msg()
783 applespi->want_mt_init_cmd = false; in applespi_send_cmd_msg()
784 applespi->cmd_evt_type = ET_CMD_TP_INI; in applespi_send_cmd_msg()
789 message->type = cpu_to_le16(0x0252); in applespi_send_cmd_msg()
790 msg_len = sizeof(message->init_mt_command); in applespi_send_cmd_msg()
792 message->init_mt_command.cmd = cpu_to_le16(0x0102); in applespi_send_cmd_msg()
794 /* do we need caps-lock command? */ in applespi_send_cmd_msg()
795 } else if (applespi->want_cl_led_on != applespi->have_cl_led_on) { in applespi_send_cmd_msg()
796 applespi->have_cl_led_on = applespi->want_cl_led_on; in applespi_send_cmd_msg()
797 applespi->cmd_evt_type = ET_CMD_CL; in applespi_send_cmd_msg()
802 message->type = cpu_to_le16(0x0151); in applespi_send_cmd_msg()
803 msg_len = sizeof(message->capsl_command); in applespi_send_cmd_msg()
805 message->capsl_command.unknown = 0x01; in applespi_send_cmd_msg()
806 message->capsl_command.led = applespi->have_cl_led_on ? 2 : 0; in applespi_send_cmd_msg()
809 } else if (applespi->want_bl_level != applespi->have_bl_level) { in applespi_send_cmd_msg()
810 applespi->have_bl_level = applespi->want_bl_level; in applespi_send_cmd_msg()
811 applespi->cmd_evt_type = ET_CMD_BL; in applespi_send_cmd_msg()
816 message->type = cpu_to_le16(0xB051); in applespi_send_cmd_msg()
817 msg_len = sizeof(message->bl_command); in applespi_send_cmd_msg()
819 message->bl_command.const1 = cpu_to_le16(0x01B0); in applespi_send_cmd_msg()
820 message->bl_command.level = in applespi_send_cmd_msg()
821 cpu_to_le16(applespi->have_bl_level); in applespi_send_cmd_msg()
823 if (applespi->have_bl_level > 0) in applespi_send_cmd_msg()
824 message->bl_command.const2 = cpu_to_le16(0x01F4); in applespi_send_cmd_msg()
826 message->bl_command.const2 = cpu_to_le16(0x0001); in applespi_send_cmd_msg()
828 /* everything's up-to-date */ in applespi_send_cmd_msg()
834 packet->flags = PACKET_TYPE_WRITE; in applespi_send_cmd_msg()
835 packet->device = device; in applespi_send_cmd_msg()
836 packet->length = cpu_to_le16(MSG_HEADER_SIZE + msg_len); in applespi_send_cmd_msg()
838 message->counter = applespi->cmd_msg_cntr++ % (U8_MAX + 1); in applespi_send_cmd_msg()
840 message->length = cpu_to_le16(msg_len - 2); in applespi_send_cmd_msg()
841 if (!message->rsp_buf_len) in applespi_send_cmd_msg()
842 message->rsp_buf_len = message->length; in applespi_send_cmd_msg()
844 crc = crc16(0, (u8 *)message, le16_to_cpu(packet->length) - 2); in applespi_send_cmd_msg()
845 put_unaligned_le16(crc, &message->data[msg_len - 2]); in applespi_send_cmd_msg()
847 crc = crc16(0, (u8 *)packet, sizeof(*packet) - 2); in applespi_send_cmd_msg()
848 packet->crc16 = cpu_to_le16(crc); in applespi_send_cmd_msg()
851 sts = applespi_async(applespi, &applespi->wr_m, in applespi_send_cmd_msg()
854 dev_warn(&applespi->spi->dev, in applespi_send_cmd_msg()
859 applespi->cmd_msg_queued = true; in applespi_send_cmd_msg()
860 applespi->write_active = true; in applespi_send_cmd_msg()
869 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_init()
872 applespi->want_mt_init_cmd = true; in applespi_init()
874 applespi->want_tp_info_cmd = true; in applespi_init()
877 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_init()
886 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_set_capsl_led()
888 applespi->want_cl_led_on = capslock_on; in applespi_set_capsl_led()
891 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_set_capsl_led()
903 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_set_bl_level()
906 applespi->want_bl_level = value; in applespi_set_bl_level()
913 applespi->want_bl_level = in applespi_set_bl_level()
920 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_set_bl_level()
930 applespi_set_capsl_led(applespi, !!test_bit(LED_CAPSL, dev->led)); in applespi_event()
934 return -EINVAL; in applespi_event()
938 /* convert 16-bit little endian to signed integer */
947 applespi->tp_dim_min_x = min(applespi->tp_dim_min_x, in applespi_debug_update_dimensions()
948 le16_to_int(f->abs_x)); in applespi_debug_update_dimensions()
949 applespi->tp_dim_max_x = max(applespi->tp_dim_max_x, in applespi_debug_update_dimensions()
950 le16_to_int(f->abs_x)); in applespi_debug_update_dimensions()
951 applespi->tp_dim_min_y = min(applespi->tp_dim_min_y, in applespi_debug_update_dimensions()
952 le16_to_int(f->abs_y)); in applespi_debug_update_dimensions()
953 applespi->tp_dim_max_y = max(applespi->tp_dim_max_y, in applespi_debug_update_dimensions()
954 le16_to_int(f->abs_y)); in applespi_debug_update_dimensions()
959 struct applespi_data *applespi = inode->i_private; in applespi_tp_dim_open()
961 file->private_data = applespi; in applespi_tp_dim_open()
963 snprintf(applespi->tp_dim_val, sizeof(applespi->tp_dim_val), in applespi_tp_dim_open()
965 applespi->touchpad_input_dev->id.product, in applespi_tp_dim_open()
966 applespi->tp_dim_min_x, applespi->tp_dim_min_y, in applespi_tp_dim_open()
967 applespi->tp_dim_max_x - applespi->tp_dim_min_x, in applespi_tp_dim_open()
968 applespi->tp_dim_max_y - applespi->tp_dim_min_y); in applespi_tp_dim_open()
976 struct applespi_data *applespi = file->private_data; in applespi_tp_dim_read()
978 return simple_read_from_buffer(buf, len, off, applespi->tp_dim_val, in applespi_tp_dim_read()
979 strlen(applespi->tp_dim_val)); in applespi_tp_dim_read()
997 le16_to_int(f->touch_major) << 1); in report_finger_data()
999 le16_to_int(f->touch_minor) << 1); in report_finger_data()
1001 le16_to_int(f->tool_major) << 1); in report_finger_data()
1003 le16_to_int(f->tool_minor) << 1); in report_finger_data()
1005 MAX_FINGER_ORIENTATION - le16_to_int(f->orientation)); in report_finger_data()
1006 input_report_abs(input, ABS_MT_POSITION_X, pos->x); in report_finger_data()
1007 input_report_abs(input, ABS_MT_POSITION_Y, pos->y); in report_finger_data()
1015 const struct applespi_tp_info *tp_info = &applespi->tp_info; in report_tp_state()
1019 input = smp_load_acquire(&applespi->touchpad_input_dev); in report_tp_state()
1025 for (i = 0; i < t->number_of_fingers; i++) { in report_tp_state()
1026 f = &t->fingers[i]; in report_tp_state()
1027 if (le16_to_int(f->touch_major) == 0) in report_tp_state()
1029 applespi->pos[n].x = le16_to_int(f->abs_x); in report_tp_state()
1030 applespi->pos[n].y = tp_info->y_min + tp_info->y_max - in report_tp_state()
1031 le16_to_int(f->abs_y); in report_tp_state()
1034 if (applespi->debug_tp_dim) in report_tp_state()
1038 input_mt_assign_slots(input, applespi->slots, applespi->pos, n, 0); in report_tp_state()
1041 report_finger_data(input, applespi->slots[i], in report_tp_state()
1042 &applespi->pos[i], &t->fingers[i]); in report_tp_state()
1045 input_report_key(input, BTN_LEFT, t->clicked); in report_tp_state()
1055 for (trans = table; trans->from; trans++) in applespi_find_translation()
1056 if (trans->from == key) in applespi_find_translation()
1069 if (trans->flags & APPLE_FLAG_FKEY) in applespi_translate_fn_key()
1076 key = trans->to; in applespi_translate_fn_key()
1088 key = trans->to; in applespi_translate_iso_layout()
1108 u8 bit = BIT((fnremap - 1) & 0x07); in applespi_remap_fn_key()
1111 !applespi_controlcodes[fnremap - 1]) in applespi_remap_fn_key()
1114 tmp = keyboard_protocol->fn_pressed; in applespi_remap_fn_key()
1115 keyboard_protocol->fn_pressed = !!(keyboard_protocol->modifiers & bit); in applespi_remap_fn_key()
1117 keyboard_protocol->modifiers |= bit; in applespi_remap_fn_key()
1119 keyboard_protocol->modifiers &= ~bit; in applespi_remap_fn_key()
1134 if (!memchr_inv(keyboard_protocol->keys_pressed, 1, MAX_ROLLOVER)) in applespi_handle_keyboard_event()
1142 if (memchr(keyboard_protocol->keys_pressed, in applespi_handle_keyboard_event()
1143 applespi->last_keys_pressed[i], MAX_ROLLOVER)) in applespi_handle_keyboard_event()
1146 key = applespi_code_to_key(applespi->last_keys_pressed[i], in applespi_handle_keyboard_event()
1147 applespi->last_keys_fn_pressed[i]); in applespi_handle_keyboard_event()
1148 input_report_key(applespi->keyboard_input_dev, key, 0); in applespi_handle_keyboard_event()
1149 applespi->last_keys_fn_pressed[i] = 0; in applespi_handle_keyboard_event()
1154 if (keyboard_protocol->keys_pressed[i] < in applespi_handle_keyboard_event()
1156 keyboard_protocol->keys_pressed[i] > 0) { in applespi_handle_keyboard_event()
1158 keyboard_protocol->keys_pressed[i], in applespi_handle_keyboard_event()
1159 keyboard_protocol->fn_pressed); in applespi_handle_keyboard_event()
1160 input_report_key(applespi->keyboard_input_dev, key, 1); in applespi_handle_keyboard_event()
1161 applespi->last_keys_fn_pressed[i] = in applespi_handle_keyboard_event()
1162 keyboard_protocol->fn_pressed; in applespi_handle_keyboard_event()
1168 if (keyboard_protocol->modifiers & BIT(i)) in applespi_handle_keyboard_event()
1169 input_report_key(applespi->keyboard_input_dev, in applespi_handle_keyboard_event()
1172 input_report_key(applespi->keyboard_input_dev, in applespi_handle_keyboard_event()
1177 if (keyboard_protocol->fn_pressed && !applespi->last_fn_pressed) in applespi_handle_keyboard_event()
1178 input_report_key(applespi->keyboard_input_dev, KEY_FN, 1); in applespi_handle_keyboard_event()
1179 else if (!keyboard_protocol->fn_pressed && applespi->last_fn_pressed) in applespi_handle_keyboard_event()
1180 input_report_key(applespi->keyboard_input_dev, KEY_FN, 0); in applespi_handle_keyboard_event()
1181 applespi->last_fn_pressed = keyboard_protocol->fn_pressed; in applespi_handle_keyboard_event()
1184 input_sync(applespi->keyboard_input_dev); in applespi_handle_keyboard_event()
1185 memcpy(&applespi->last_keys_pressed, keyboard_protocol->keys_pressed, in applespi_handle_keyboard_event()
1186 sizeof(applespi->last_keys_pressed)); in applespi_handle_keyboard_event()
1193 for (info = applespi_tp_models; info->model; info++) { in applespi_find_touchpad_info()
1194 if (info->model == model) in applespi_find_touchpad_info()
1195 return &info->tp_info; in applespi_find_touchpad_info()
1210 tp_info = applespi_find_touchpad_info(rcvd_tp_info->model_no); in applespi_register_touchpad_device()
1212 dev_warn(&applespi->spi->dev, in applespi_register_touchpad_device()
1213 "Unknown touchpad model %x - falling back to MB8 touchpad\n", in applespi_register_touchpad_device()
1214 rcvd_tp_info->model_no); in applespi_register_touchpad_device()
1218 applespi->tp_info = *tp_info; in applespi_register_touchpad_device()
1225 dev_info(&applespi->spi->dev, in applespi_register_touchpad_device()
1227 applespi->tp_info.x_min = x; in applespi_register_touchpad_device()
1228 applespi->tp_info.y_min = y; in applespi_register_touchpad_device()
1229 applespi->tp_info.x_max = x + w; in applespi_register_touchpad_device()
1230 applespi->tp_info.y_max = y + h; in applespi_register_touchpad_device()
1232 dev_warn(&applespi->spi->dev, in applespi_register_touchpad_device()
1241 applespi->tp_info.x_min, in applespi_register_touchpad_device()
1242 applespi->tp_info.y_min, in applespi_register_touchpad_device()
1243 applespi->tp_info.x_max - applespi->tp_info.x_min, in applespi_register_touchpad_device()
1244 applespi->tp_info.y_max - applespi->tp_info.y_min); in applespi_register_touchpad_device()
1248 touchpad_input_dev = devm_input_allocate_device(&applespi->spi->dev); in applespi_register_touchpad_device()
1250 dev_err(&applespi->spi->dev, in applespi_register_touchpad_device()
1252 return -ENOMEM; in applespi_register_touchpad_device()
1255 touchpad_input_dev->name = "Apple SPI Touchpad"; in applespi_register_touchpad_device()
1256 touchpad_input_dev->phys = "applespi/input1"; in applespi_register_touchpad_device()
1257 touchpad_input_dev->dev.parent = &applespi->spi->dev; in applespi_register_touchpad_device()
1258 touchpad_input_dev->id.bustype = BUS_SPI; in applespi_register_touchpad_device()
1259 touchpad_input_dev->id.vendor = SYNAPTICS_VENDOR_ID; in applespi_register_touchpad_device()
1260 touchpad_input_dev->id.product = in applespi_register_touchpad_device()
1261 rcvd_tp_info->model_no << 8 | rcvd_tp_info->model_flags; in applespi_register_touchpad_device()
1267 __set_bit(INPUT_PROP_POINTER, touchpad_input_dev->propbit); in applespi_register_touchpad_device()
1268 __set_bit(INPUT_PROP_BUTTONPAD, touchpad_input_dev->propbit); in applespi_register_touchpad_device()
1270 /* finger touch area */ in applespi_register_touchpad_device()
1284 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, in applespi_register_touchpad_device()
1289 applespi->tp_info.x_min, applespi->tp_info.x_max, in applespi_register_touchpad_device()
1292 applespi->tp_info.y_min, applespi->tp_info.y_max, in applespi_register_touchpad_device()
1303 dev_err(&applespi->spi->dev, in applespi_register_touchpad_device()
1311 dev_err(&applespi->spi->dev, in applespi_register_touchpad_device()
1317 smp_store_release(&applespi->touchpad_input_dev, touchpad_input_dev); in applespi_register_touchpad_device()
1327 applespi_register_touchpad_device(applespi, &applespi->rcvd_tp_info); in applespi_worker()
1334 if (packet->device == PACKET_DEV_INFO && in applespi_handle_cmd_response()
1335 le16_to_cpu(message->type) == 0x1020) { in applespi_handle_cmd_response()
1340 applespi->rcvd_tp_info = message->tp_info; in applespi_handle_cmd_response()
1341 schedule_work(&applespi->work); in applespi_handle_cmd_response()
1345 if (le16_to_cpu(message->length) != 0x0000) { in applespi_handle_cmd_response()
1346 dev_warn_ratelimited(&applespi->spi->dev, in applespi_handle_cmd_response()
1348 le16_to_cpu(message->length)); in applespi_handle_cmd_response()
1352 if (packet->device == PACKET_DEV_TPAD && in applespi_handle_cmd_response()
1353 le16_to_cpu(message->type) == 0x0252 && in applespi_handle_cmd_response()
1354 le16_to_cpu(message->rsp_buf_len) == 0x0002) in applespi_handle_cmd_response()
1355 dev_info(&applespi->spi->dev, "modeswitch done.\n"); in applespi_handle_cmd_response()
1365 dev_warn_ratelimited(&applespi->spi->dev, in applespi_verify_crc()
1380 if (packet->flags == PACKET_TYPE_READ && in applespi_debug_print_read_packet()
1381 packet->device == PACKET_DEV_KEYB) in applespi_debug_print_read_packet()
1383 else if (packet->flags == PACKET_TYPE_READ && in applespi_debug_print_read_packet()
1384 packet->device == PACKET_DEV_TPAD) in applespi_debug_print_read_packet()
1386 else if (packet->flags == PACKET_TYPE_WRITE) in applespi_debug_print_read_packet()
1387 evt_type = applespi->cmd_evt_type; in applespi_debug_print_read_packet()
1391 applespi_get_trace_fun(evt_type)(evt_type, PT_READ, applespi->rx_buffer, in applespi_debug_print_read_packet()
1405 if (!applespi_verify_crc(applespi, applespi->rx_buffer, in applespi_got_data()
1409 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_got_data()
1411 if (applespi->drain) { in applespi_got_data()
1412 applespi->read_active = false; in applespi_got_data()
1413 applespi->write_active = false; in applespi_got_data()
1415 wake_up_all(&applespi->drain_complete); in applespi_got_data()
1418 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_got_data()
1423 packet = (struct spi_packet *)applespi->rx_buffer; in applespi_got_data()
1427 off = le16_to_cpu(packet->offset); in applespi_got_data()
1428 rem = le16_to_cpu(packet->remaining); in applespi_got_data()
1429 len = le16_to_cpu(packet->length); in applespi_got_data()
1431 if (len > sizeof(packet->data)) { in applespi_got_data()
1432 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1438 /* handle multi-packet messages */ in applespi_got_data()
1440 if (off != applespi->saved_msg_len) { in applespi_got_data()
1441 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1443 off, applespi->saved_msg_len); in applespi_got_data()
1448 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1455 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1461 memcpy(applespi->msg_buf + off, &packet->data, len); in applespi_got_data()
1462 applespi->saved_msg_len += len; in applespi_got_data()
1467 message = (struct message *)applespi->msg_buf; in applespi_got_data()
1468 msg_len = applespi->saved_msg_len; in applespi_got_data()
1470 message = (struct message *)&packet->data; in applespi_got_data()
1474 /* got complete message - verify */ in applespi_got_data()
1478 if (le16_to_cpu(message->length) != msg_len - MSG_HEADER_SIZE - 2) { in applespi_got_data()
1479 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1480 "Received corrupted packet (invalid message length %u - expected %u)\n", in applespi_got_data()
1481 le16_to_cpu(message->length), in applespi_got_data()
1482 msg_len - MSG_HEADER_SIZE - 2); in applespi_got_data()
1487 if (packet->flags == PACKET_TYPE_READ && in applespi_got_data()
1488 packet->device == PACKET_DEV_KEYB) { in applespi_got_data()
1489 applespi_handle_keyboard_event(applespi, &message->keyboard); in applespi_got_data()
1491 } else if (packet->flags == PACKET_TYPE_READ && in applespi_got_data()
1492 packet->device == PACKET_DEV_TPAD) { in applespi_got_data()
1496 tp = &message->touchpad; in applespi_got_data()
1497 tp_len = struct_size(tp, fingers, tp->number_of_fingers); in applespi_got_data()
1499 if (le16_to_cpu(message->length) + 2 != tp_len) { in applespi_got_data()
1500 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1501 "Received corrupted packet (invalid message length %u - num-fingers %u, tp-len %zu)\n", in applespi_got_data()
1502 le16_to_cpu(message->length), in applespi_got_data()
1503 tp->number_of_fingers, tp_len); in applespi_got_data()
1507 if (tp->number_of_fingers > MAX_FINGERS) { in applespi_got_data()
1508 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1510 tp->number_of_fingers, in applespi_got_data()
1512 tp->number_of_fingers = MAX_FINGERS; in applespi_got_data()
1517 } else if (packet->flags == PACKET_TYPE_WRITE) { in applespi_got_data()
1522 applespi->saved_msg_len = 0; in applespi_got_data()
1524 applespi_msg_complete(applespi, packet->flags == PACKET_TYPE_WRITE, in applespi_got_data()
1532 if (applespi->rd_m.status < 0) { in applespi_async_read_complete()
1533 dev_warn(&applespi->spi->dev, "Error reading from device: %d\n", in applespi_async_read_complete()
1534 applespi->rd_m.status); in applespi_async_read_complete()
1545 acpi_finish_gpe(NULL, applespi->gpe); in applespi_async_read_complete()
1556 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_notify()
1558 if (!applespi->suspended) { in applespi_notify()
1559 sts = applespi_async(applespi, &applespi->rd_m, in applespi_notify()
1562 dev_warn(&applespi->spi->dev, in applespi_notify()
1566 applespi->read_active = true; in applespi_notify()
1569 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_notify()
1583 return -ENOMEM; in applespi_get_saved_bl_level()
1585 memcpy(efivar_entry->var.VariableName, EFI_BL_LEVEL_NAME, in applespi_get_saved_bl_level()
1587 efivar_entry->var.VendorGuid = EFI_BL_LEVEL_GUID; in applespi_get_saved_bl_level()
1591 if (sts && sts != -ENOENT) in applespi_get_saved_bl_level()
1592 dev_warn(&applespi->spi->dev, in applespi_get_saved_bl_level()
1620 dev_warn(&applespi->spi->dev, in applespi_save_bl_level()
1627 acpi_handle spi_handle = ACPI_HANDLE(&spi->dev); in applespi_probe()
1636 dev_info(&spi->dev, "USB interface already enabled\n"); in applespi_probe()
1637 return -ENODEV; in applespi_probe()
1641 applespi = devm_kzalloc(&spi->dev, sizeof(*applespi), GFP_KERNEL); in applespi_probe()
1643 return -ENOMEM; in applespi_probe()
1645 applespi->spi = spi; in applespi_probe()
1647 INIT_WORK(&applespi->work, applespi_worker); in applespi_probe()
1653 applespi->tx_buffer = devm_kmalloc(&spi->dev, APPLESPI_PACKET_SIZE, in applespi_probe()
1655 applespi->tx_status = devm_kmalloc(&spi->dev, APPLESPI_STATUS_SIZE, in applespi_probe()
1657 applespi->rx_buffer = devm_kmalloc(&spi->dev, APPLESPI_PACKET_SIZE, in applespi_probe()
1659 applespi->msg_buf = devm_kmalloc_array(&spi->dev, MAX_PKTS_PER_MSG, in applespi_probe()
1663 if (!applespi->tx_buffer || !applespi->tx_status || in applespi_probe()
1664 !applespi->rx_buffer || !applespi->msg_buf) in applespi_probe()
1665 return -ENOMEM; in applespi_probe()
1672 acpi_sts = acpi_get_handle(spi_handle, "SIEN", &applespi->sien); in applespi_probe()
1674 dev_err(&applespi->spi->dev, in applespi_probe()
1677 return -ENODEV; in applespi_probe()
1680 acpi_sts = acpi_get_handle(spi_handle, "SIST", &applespi->sist); in applespi_probe()
1682 dev_err(&applespi->spi->dev, in applespi_probe()
1685 return -ENODEV; in applespi_probe()
1698 applespi->keyboard_input_dev = devm_input_allocate_device(&spi->dev); in applespi_probe()
1700 if (!applespi->keyboard_input_dev) in applespi_probe()
1701 return -ENOMEM; in applespi_probe()
1703 applespi->keyboard_input_dev->name = "Apple SPI Keyboard"; in applespi_probe()
1704 applespi->keyboard_input_dev->phys = "applespi/input0"; in applespi_probe()
1705 applespi->keyboard_input_dev->dev.parent = &spi->dev; in applespi_probe()
1706 applespi->keyboard_input_dev->id.bustype = BUS_SPI; in applespi_probe()
1708 applespi->keyboard_input_dev->evbit[0] = in applespi_probe()
1710 applespi->keyboard_input_dev->ledbit[0] = BIT_MASK(LED_CAPSL); in applespi_probe()
1712 input_set_drvdata(applespi->keyboard_input_dev, applespi); in applespi_probe()
1713 applespi->keyboard_input_dev->event = applespi_event; in applespi_probe()
1717 input_set_capability(applespi->keyboard_input_dev, in applespi_probe()
1722 input_set_capability(applespi->keyboard_input_dev, in applespi_probe()
1727 input_set_capability(applespi->keyboard_input_dev, in applespi_probe()
1730 input_set_capability(applespi->keyboard_input_dev, EV_KEY, KEY_FN); in applespi_probe()
1732 sts = input_register_device(applespi->keyboard_input_dev); in applespi_probe()
1734 dev_err(&applespi->spi->dev, in applespi_probe()
1736 return -ENODEV; in applespi_probe()
1745 dev_err(&applespi->spi->dev, in applespi_probe()
1748 return -ENODEV; in applespi_probe()
1750 applespi->gpe = (int)gpe; in applespi_probe()
1752 acpi_sts = acpi_install_gpe_handler(NULL, applespi->gpe, in applespi_probe()
1756 dev_err(&applespi->spi->dev, in applespi_probe()
1758 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_probe()
1759 return -ENODEV; in applespi_probe()
1762 applespi->suspended = false; in applespi_probe()
1764 acpi_sts = acpi_enable_gpe(NULL, applespi->gpe); in applespi_probe()
1766 dev_err(&applespi->spi->dev, in applespi_probe()
1768 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_probe()
1769 acpi_remove_gpe_handler(NULL, applespi->gpe, applespi_notify); in applespi_probe()
1770 return -ENODEV; in applespi_probe()
1781 device_wakeup_enable(&spi->dev); in applespi_probe()
1783 /* set up keyboard-backlight */ in applespi_probe()
1786 applespi_set_bl_level(&applespi->backlight_info, sts); in applespi_probe()
1788 applespi->backlight_info.name = "spi::kbd_backlight"; in applespi_probe()
1789 applespi->backlight_info.default_trigger = "kbd-backlight"; in applespi_probe()
1790 applespi->backlight_info.brightness_set = applespi_set_bl_level; in applespi_probe()
1792 sts = devm_led_classdev_register(&spi->dev, &applespi->backlight_info); in applespi_probe()
1794 dev_warn(&applespi->spi->dev, in applespi_probe()
1799 applespi->debugfs_root = debugfs_create_dir("applespi", NULL); in applespi_probe()
1801 debugfs_create_bool("enable_tp_dim", 0600, applespi->debugfs_root, in applespi_probe()
1802 &applespi->debug_tp_dim); in applespi_probe()
1804 debugfs_create_file("tp_dim", 0400, applespi->debugfs_root, applespi, in applespi_probe()
1814 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_drain_writes()
1816 applespi->drain = true; in applespi_drain_writes()
1817 wait_event_lock_irq(applespi->drain_complete, !applespi->write_active, in applespi_drain_writes()
1818 applespi->cmd_msg_lock); in applespi_drain_writes()
1820 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_drain_writes()
1827 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_drain_reads()
1829 wait_event_lock_irq(applespi->drain_complete, !applespi->read_active, in applespi_drain_reads()
1830 applespi->cmd_msg_lock); in applespi_drain_reads()
1832 applespi->suspended = true; in applespi_drain_reads()
1834 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_drain_reads()
1843 acpi_disable_gpe(NULL, applespi->gpe); in applespi_remove()
1844 acpi_remove_gpe_handler(NULL, applespi->gpe, applespi_notify); in applespi_remove()
1845 device_wakeup_disable(&spi->dev); in applespi_remove()
1849 debugfs_remove_recursive(applespi->debugfs_root); in applespi_remove()
1858 applespi_save_bl_level(applespi, applespi->have_bl_level); in applespi_shutdown()
1866 applespi_save_bl_level(applespi, applespi->have_bl_level); in applespi_poweroff_late()
1878 /* turn off caps-lock - it'll stay on otherwise */ in applespi_suspend()
1881 dev_warn(&applespi->spi->dev, in applespi_suspend()
1882 "Failed to turn off caps-lock led (%d)\n", sts); in applespi_suspend()
1887 acpi_sts = acpi_disable_gpe(NULL, applespi->gpe); in applespi_suspend()
1889 dev_err(&applespi->spi->dev, in applespi_suspend()
1891 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_suspend()
1906 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_resume()
1908 applespi->drain = false; in applespi_resume()
1909 applespi->have_cl_led_on = false; in applespi_resume()
1910 applespi->have_bl_level = 0; in applespi_resume()
1911 applespi->cmd_msg_queued = false; in applespi_resume()
1912 applespi->read_active = false; in applespi_resume()
1913 applespi->write_active = false; in applespi_resume()
1915 applespi->suspended = false; in applespi_resume()
1917 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_resume()
1922 /* re-enable the interrupt */ in applespi_resume()
1923 acpi_sts = acpi_enable_gpe(NULL, applespi->gpe); in applespi_resume()
1925 dev_err(&applespi->spi->dev, in applespi_resume()
1926 "Failed to re-enable GPE handler for GPE %d: %s\n", in applespi_resume()
1927 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_resume()