Lines Matching +full:max +full:- +full:fingers

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,
85 ((KBD_BL_LEVEL_MAX - KBD_BL_LEVEL_MIN) * KBD_BL_LEVEL_SCALE / 255U)
102 …emap Fn key ([0] = no-remap; 1 = left-ctrl, 2 = left-shift, 3 = left-alt, 4 = left-meta, 6 = right
106 MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. ([0] = disabled,…
114 * struct keyboard_protocol - keyboard message.
118 * @modifiers: bit-set of modifier/control keys pressed
120 * @keys_pressed: the (non-modifier) keys currently pressed
135 * struct tp_finger - single trackpad finger structure, le16-aligned
149 * @multi: one finger: varies, more fingers: constant
152 * @crc16 field; unknown on all other fingers.
172 * struct touchpad_protocol - touchpad message.
176 * @clicked: 1 if a button-click was detected, 0 otherwise
178 * @number_of_fingers: the number of fingers being reported in @fingers
181 * @fingers: the data for each finger
190 struct tp_finger fingers[]; member
194 * struct command_protocol_tp_info - get touchpad info.
205 * struct touchpad_info_protocol - touchpad info response.
225 * struct command_protocol_mt_init - initialize multitouch.
238 * struct command_protocol_capsl - toggle caps-lock led
253 * struct command_protocol_bl - set keyboard backlight brightness
270 * struct message - a complete spi message.
272 * Each message begins with fixed header, followed by a message-type specific
273 * payload, and ends with a 16-bit crc. Because of the varying lengths of the
287 * structure (after re-assembly in case of being split over
288 * multiple spi-packets), minus the trailing crc. The total size
296 * @capsl_command: Toggle caps-lock LED
322 * struct spi_packet - a complete spi packet; always 256 bytes. This carries
325 * fingers pressed) the message is split over multiple packets (see the
343 * covers just this packet, even on multi-packet messages (in
357 u64 spi_cs_delay; /* cs-to-clk delay in us */
358 u64 reset_a2r_usec; /* active-to-receive delay? */
512 .tp_info = { -5087, -182, 5579, 6089 },
516 .tp_info = { -6243, -170, 6749, 7685 },
520 .tp_info = { -7456, -163, 7976, 9283 },
551 struct spi_message *msg = &applespi->rd_m; in applespi_setup_read_txfrs()
552 struct spi_transfer *dl_t = &applespi->dl_t; in applespi_setup_read_txfrs()
553 struct spi_transfer *rd_t = &applespi->rd_t; in applespi_setup_read_txfrs()
558 dl_t->delay.value = applespi->spi_settings.spi_cs_delay; in applespi_setup_read_txfrs()
559 dl_t->delay.unit = SPI_DELAY_UNIT_USECS; in applespi_setup_read_txfrs()
561 rd_t->rx_buf = applespi->rx_buffer; in applespi_setup_read_txfrs()
562 rd_t->len = APPLESPI_PACKET_SIZE; in applespi_setup_read_txfrs()
571 struct spi_message *msg = &applespi->wr_m; in applespi_setup_write_txfrs()
572 struct spi_transfer *wt_t = &applespi->ww_t; in applespi_setup_write_txfrs()
573 struct spi_transfer *dl_t = &applespi->wd_t; in applespi_setup_write_txfrs()
574 struct spi_transfer *wr_t = &applespi->wr_t; in applespi_setup_write_txfrs()
575 struct spi_transfer *st_t = &applespi->st_t; in applespi_setup_write_txfrs()
588 wt_t->delay.value = SPI_RW_CHG_DELAY_US; in applespi_setup_write_txfrs()
589 wt_t->delay.unit = SPI_DELAY_UNIT_USECS; in applespi_setup_write_txfrs()
590 wt_t->cs_change = 1; in applespi_setup_write_txfrs()
592 dl_t->delay.value = applespi->spi_settings.spi_cs_delay; in applespi_setup_write_txfrs()
593 dl_t->delay.unit = SPI_DELAY_UNIT_USECS; in applespi_setup_write_txfrs()
595 wr_t->tx_buf = applespi->tx_buffer; in applespi_setup_write_txfrs()
596 wr_t->len = APPLESPI_PACKET_SIZE; in applespi_setup_write_txfrs()
597 wr_t->delay.value = SPI_RW_CHG_DELAY_US; in applespi_setup_write_txfrs()
598 wr_t->delay.unit = SPI_DELAY_UNIT_USECS; in applespi_setup_write_txfrs()
600 st_t->rx_buf = applespi->tx_status; in applespi_setup_write_txfrs()
601 st_t->len = APPLESPI_STATUS_SIZE; in applespi_setup_write_txfrs()
613 message->complete = complete; in applespi_async()
614 message->context = applespi; in applespi_async()
616 return spi_async(applespi->spi, message); in applespi_async()
625 dev_warn(&applespi->spi->dev, "Error writing to device: %d\n", in applespi_check_write_status()
630 if (memcmp(applespi->tx_status, status_ok, APPLESPI_STATUS_SIZE)) { in applespi_check_write_status()
631 dev_warn(&applespi->spi->dev, "Error writing to device: %*ph\n", in applespi_check_write_status()
632 APPLESPI_STATUS_SIZE, applespi->tx_status); in applespi_check_write_status()
641 struct acpi_device *adev = ACPI_COMPANION(&applespi->spi->dev); in applespi_get_spi_settings()
643 struct spi_settings *settings = &applespi->spi_settings; in applespi_get_spi_settings()
646 settings->spi_cs_delay = *(u64 *)o->buffer.pointer; in applespi_get_spi_settings()
648 dev_warn(&applespi->spi->dev, in applespi_get_spi_settings()
652 settings->reset_a2r_usec = *(u64 *)o->buffer.pointer; in applespi_get_spi_settings()
654 dev_warn(&applespi->spi->dev, in applespi_get_spi_settings()
658 settings->reset_rec_usec = *(u64 *)o->buffer.pointer; in applespi_get_spi_settings()
660 dev_warn(&applespi->spi->dev, in applespi_get_spi_settings()
663 dev_dbg(&applespi->spi->dev, in applespi_get_spi_settings()
665 settings->spi_cs_delay, settings->reset_a2r_usec, in applespi_get_spi_settings()
666 settings->reset_rec_usec); in applespi_get_spi_settings()
679 spin_lock_init(&applespi->cmd_msg_lock); in applespi_setup_spi()
680 init_waitqueue_head(&applespi->drain_complete); in applespi_setup_spi()
691 acpi_sts = acpi_evaluate_integer(applespi->sist, NULL, NULL, in applespi_enable_spi()
697 acpi_sts = acpi_execute_simple_method(applespi->sien, NULL, 1); in applespi_enable_spi()
699 dev_err(&applespi->spi->dev, "SIEN failed: %s\n", in applespi_enable_spi()
701 return -ENODEV; in applespi_enable_spi()
722 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_msg_complete()
725 applespi->read_active = false; in applespi_msg_complete()
727 applespi->write_active = false; in applespi_msg_complete()
729 if (applespi->drain && !applespi->write_active) in applespi_msg_complete()
730 wake_up_all(&applespi->drain_complete); in applespi_msg_complete()
733 applespi->cmd_msg_queued = 0; in applespi_msg_complete()
737 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_msg_complete()
743 enum applespi_evt_type evt_type = applespi->cmd_evt_type; in applespi_async_write_complete()
746 applespi->tx_buffer, in applespi_async_write_complete()
749 applespi->tx_status, in applespi_async_write_complete()
754 if (!applespi_check_write_status(applespi, applespi->wr_m.status)) { in applespi_async_write_complete()
767 struct spi_packet *packet = (struct spi_packet *)applespi->tx_buffer; in applespi_send_cmd_msg()
768 struct message *message = (struct message *)packet->data; in applespi_send_cmd_msg()
773 if (applespi->drain) in applespi_send_cmd_msg()
777 if (applespi->cmd_msg_queued) { in applespi_send_cmd_msg()
778 if (ktime_ms_delta(ktime_get(), applespi->cmd_msg_queued) < 1000) in applespi_send_cmd_msg()
781 dev_warn(&applespi->spi->dev, "Command %d timed out\n", in applespi_send_cmd_msg()
782 applespi->cmd_evt_type); in applespi_send_cmd_msg()
784 applespi->cmd_msg_queued = 0; in applespi_send_cmd_msg()
785 applespi->write_active = false; in applespi_send_cmd_msg()
792 if (applespi->want_tp_info_cmd) { in applespi_send_cmd_msg()
793 applespi->want_tp_info_cmd = false; in applespi_send_cmd_msg()
794 applespi->want_mt_init_cmd = true; in applespi_send_cmd_msg()
795 applespi->cmd_evt_type = ET_CMD_TP_INI; in applespi_send_cmd_msg()
800 message->type = cpu_to_le16(0x1020); in applespi_send_cmd_msg()
801 msg_len = sizeof(message->tp_info_command); in applespi_send_cmd_msg()
803 message->zero = 0x02; in applespi_send_cmd_msg()
804 message->rsp_buf_len = cpu_to_le16(0x0200); in applespi_send_cmd_msg()
806 } else if (applespi->want_mt_init_cmd) { in applespi_send_cmd_msg()
807 applespi->want_mt_init_cmd = false; in applespi_send_cmd_msg()
808 applespi->cmd_evt_type = ET_CMD_TP_INI; in applespi_send_cmd_msg()
813 message->type = cpu_to_le16(0x0252); in applespi_send_cmd_msg()
814 msg_len = sizeof(message->init_mt_command); in applespi_send_cmd_msg()
816 message->init_mt_command.cmd = cpu_to_le16(0x0102); in applespi_send_cmd_msg()
818 /* do we need caps-lock command? */ in applespi_send_cmd_msg()
819 } else if (applespi->want_cl_led_on != applespi->have_cl_led_on) { in applespi_send_cmd_msg()
820 applespi->have_cl_led_on = applespi->want_cl_led_on; in applespi_send_cmd_msg()
821 applespi->cmd_evt_type = ET_CMD_CL; in applespi_send_cmd_msg()
826 message->type = cpu_to_le16(0x0151); in applespi_send_cmd_msg()
827 msg_len = sizeof(message->capsl_command); in applespi_send_cmd_msg()
829 message->capsl_command.unknown = 0x01; in applespi_send_cmd_msg()
830 message->capsl_command.led = applespi->have_cl_led_on ? 2 : 0; in applespi_send_cmd_msg()
833 } else if (applespi->want_bl_level != applespi->have_bl_level) { in applespi_send_cmd_msg()
834 applespi->have_bl_level = applespi->want_bl_level; in applespi_send_cmd_msg()
835 applespi->cmd_evt_type = ET_CMD_BL; in applespi_send_cmd_msg()
840 message->type = cpu_to_le16(0xB051); in applespi_send_cmd_msg()
841 msg_len = sizeof(message->bl_command); in applespi_send_cmd_msg()
843 message->bl_command.const1 = cpu_to_le16(0x01B0); in applespi_send_cmd_msg()
844 message->bl_command.level = in applespi_send_cmd_msg()
845 cpu_to_le16(applespi->have_bl_level); in applespi_send_cmd_msg()
847 if (applespi->have_bl_level > 0) in applespi_send_cmd_msg()
848 message->bl_command.const2 = cpu_to_le16(0x01F4); in applespi_send_cmd_msg()
850 message->bl_command.const2 = cpu_to_le16(0x0001); in applespi_send_cmd_msg()
852 /* everything's up-to-date */ in applespi_send_cmd_msg()
858 packet->flags = PACKET_TYPE_WRITE; in applespi_send_cmd_msg()
859 packet->device = device; in applespi_send_cmd_msg()
860 packet->length = cpu_to_le16(MSG_HEADER_SIZE + msg_len); in applespi_send_cmd_msg()
862 message->counter = applespi->cmd_msg_cntr++ % (U8_MAX + 1); in applespi_send_cmd_msg()
864 message->length = cpu_to_le16(msg_len - 2); in applespi_send_cmd_msg()
865 if (!message->rsp_buf_len) in applespi_send_cmd_msg()
866 message->rsp_buf_len = message->length; in applespi_send_cmd_msg()
868 crc = crc16(0, (u8 *)message, le16_to_cpu(packet->length) - 2); in applespi_send_cmd_msg()
869 put_unaligned_le16(crc, &message->data[msg_len - 2]); in applespi_send_cmd_msg()
871 crc = crc16(0, (u8 *)packet, sizeof(*packet) - 2); in applespi_send_cmd_msg()
872 packet->crc16 = cpu_to_le16(crc); in applespi_send_cmd_msg()
875 sts = applespi_async(applespi, &applespi->wr_m, in applespi_send_cmd_msg()
878 dev_warn(&applespi->spi->dev, in applespi_send_cmd_msg()
883 applespi->cmd_msg_queued = ktime_get_coarse(); in applespi_send_cmd_msg()
884 applespi->write_active = true; in applespi_send_cmd_msg()
893 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_init()
896 applespi->want_mt_init_cmd = true; in applespi_init()
898 applespi->want_tp_info_cmd = true; in applespi_init()
901 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_init()
910 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_set_capsl_led()
912 applespi->want_cl_led_on = capslock_on; in applespi_set_capsl_led()
915 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_set_capsl_led()
927 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_set_bl_level()
930 applespi->want_bl_level = value; in applespi_set_bl_level()
937 applespi->want_bl_level = in applespi_set_bl_level()
944 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_set_bl_level()
954 applespi_set_capsl_led(applespi, !!test_bit(LED_CAPSL, dev->led)); in applespi_event()
958 return -EINVAL; in applespi_event()
962 /* convert 16-bit little endian to signed integer */
971 applespi->tp_dim_min_x = min(applespi->tp_dim_min_x, in applespi_debug_update_dimensions()
972 le16_to_int(f->abs_x)); in applespi_debug_update_dimensions()
973 applespi->tp_dim_max_x = max(applespi->tp_dim_max_x, in applespi_debug_update_dimensions()
974 le16_to_int(f->abs_x)); in applespi_debug_update_dimensions()
975 applespi->tp_dim_min_y = min(applespi->tp_dim_min_y, in applespi_debug_update_dimensions()
976 le16_to_int(f->abs_y)); in applespi_debug_update_dimensions()
977 applespi->tp_dim_max_y = max(applespi->tp_dim_max_y, in applespi_debug_update_dimensions()
978 le16_to_int(f->abs_y)); in applespi_debug_update_dimensions()
983 struct applespi_data *applespi = inode->i_private; in applespi_tp_dim_open()
985 file->private_data = applespi; in applespi_tp_dim_open()
987 snprintf(applespi->tp_dim_val, sizeof(applespi->tp_dim_val), in applespi_tp_dim_open()
989 applespi->touchpad_input_dev->id.product, in applespi_tp_dim_open()
990 applespi->tp_dim_min_x, applespi->tp_dim_min_y, in applespi_tp_dim_open()
991 applespi->tp_dim_max_x - applespi->tp_dim_min_x, in applespi_tp_dim_open()
992 applespi->tp_dim_max_y - applespi->tp_dim_min_y); in applespi_tp_dim_open()
1000 struct applespi_data *applespi = file->private_data; in applespi_tp_dim_read()
1002 return simple_read_from_buffer(buf, len, off, applespi->tp_dim_val, in applespi_tp_dim_read()
1003 strlen(applespi->tp_dim_val)); in applespi_tp_dim_read()
1020 le16_to_int(f->touch_major) << 1); in report_finger_data()
1022 le16_to_int(f->touch_minor) << 1); in report_finger_data()
1024 le16_to_int(f->tool_major) << 1); in report_finger_data()
1026 le16_to_int(f->tool_minor) << 1); in report_finger_data()
1028 MAX_FINGER_ORIENTATION - le16_to_int(f->orientation)); in report_finger_data()
1029 input_report_abs(input, ABS_MT_POSITION_X, pos->x); in report_finger_data()
1030 input_report_abs(input, ABS_MT_POSITION_Y, pos->y); in report_finger_data()
1038 const struct applespi_tp_info *tp_info = &applespi->tp_info; in report_tp_state()
1042 input = smp_load_acquire(&applespi->touchpad_input_dev); in report_tp_state()
1048 for (i = 0; i < t->number_of_fingers; i++) { in report_tp_state()
1049 f = &t->fingers[i]; in report_tp_state()
1050 if (le16_to_int(f->touch_major) == 0) in report_tp_state()
1052 applespi->pos[n].x = le16_to_int(f->abs_x); in report_tp_state()
1053 applespi->pos[n].y = tp_info->y_min + tp_info->y_max - in report_tp_state()
1054 le16_to_int(f->abs_y); in report_tp_state()
1057 if (applespi->debug_tp_dim) in report_tp_state()
1061 input_mt_assign_slots(input, applespi->slots, applespi->pos, n, 0); in report_tp_state()
1064 report_finger_data(input, applespi->slots[i], in report_tp_state()
1065 &applespi->pos[i], &t->fingers[i]); in report_tp_state()
1068 input_report_key(input, BTN_LEFT, t->clicked); in report_tp_state()
1078 for (trans = table; trans->from; trans++) in applespi_find_translation()
1079 if (trans->from == key) in applespi_find_translation()
1092 if (trans->flags & APPLE_FLAG_FKEY) in applespi_translate_fn_key()
1099 key = trans->to; in applespi_translate_fn_key()
1111 key = trans->to; in applespi_translate_iso_layout()
1131 u8 bit = BIT((fnremap - 1) & 0x07); in applespi_remap_fn_key()
1134 !applespi_controlcodes[fnremap - 1]) in applespi_remap_fn_key()
1137 tmp = keyboard_protocol->fn_pressed; in applespi_remap_fn_key()
1138 keyboard_protocol->fn_pressed = !!(keyboard_protocol->modifiers & bit); in applespi_remap_fn_key()
1140 keyboard_protocol->modifiers |= bit; in applespi_remap_fn_key()
1142 keyboard_protocol->modifiers &= ~bit; in applespi_remap_fn_key()
1157 if (!memchr_inv(keyboard_protocol->keys_pressed, 1, MAX_ROLLOVER)) in applespi_handle_keyboard_event()
1165 if (memchr(keyboard_protocol->keys_pressed, in applespi_handle_keyboard_event()
1166 applespi->last_keys_pressed[i], MAX_ROLLOVER)) in applespi_handle_keyboard_event()
1169 key = applespi_code_to_key(applespi->last_keys_pressed[i], in applespi_handle_keyboard_event()
1170 applespi->last_keys_fn_pressed[i]); in applespi_handle_keyboard_event()
1171 input_report_key(applespi->keyboard_input_dev, key, 0); in applespi_handle_keyboard_event()
1172 applespi->last_keys_fn_pressed[i] = 0; in applespi_handle_keyboard_event()
1177 if (keyboard_protocol->keys_pressed[i] < in applespi_handle_keyboard_event()
1179 keyboard_protocol->keys_pressed[i] > 0) { in applespi_handle_keyboard_event()
1181 keyboard_protocol->keys_pressed[i], in applespi_handle_keyboard_event()
1182 keyboard_protocol->fn_pressed); in applespi_handle_keyboard_event()
1183 input_report_key(applespi->keyboard_input_dev, key, 1); in applespi_handle_keyboard_event()
1184 applespi->last_keys_fn_pressed[i] = in applespi_handle_keyboard_event()
1185 keyboard_protocol->fn_pressed; in applespi_handle_keyboard_event()
1191 if (keyboard_protocol->modifiers & BIT(i)) in applespi_handle_keyboard_event()
1192 input_report_key(applespi->keyboard_input_dev, in applespi_handle_keyboard_event()
1195 input_report_key(applespi->keyboard_input_dev, in applespi_handle_keyboard_event()
1200 if (keyboard_protocol->fn_pressed && !applespi->last_fn_pressed) in applespi_handle_keyboard_event()
1201 input_report_key(applespi->keyboard_input_dev, KEY_FN, 1); in applespi_handle_keyboard_event()
1202 else if (!keyboard_protocol->fn_pressed && applespi->last_fn_pressed) in applespi_handle_keyboard_event()
1203 input_report_key(applespi->keyboard_input_dev, KEY_FN, 0); in applespi_handle_keyboard_event()
1204 applespi->last_fn_pressed = keyboard_protocol->fn_pressed; in applespi_handle_keyboard_event()
1207 input_sync(applespi->keyboard_input_dev); in applespi_handle_keyboard_event()
1208 memcpy(&applespi->last_keys_pressed, keyboard_protocol->keys_pressed, in applespi_handle_keyboard_event()
1209 sizeof(applespi->last_keys_pressed)); in applespi_handle_keyboard_event()
1216 for (info = applespi_tp_models; info->model; info++) { in applespi_find_touchpad_info()
1217 if (info->model == model) in applespi_find_touchpad_info()
1218 return &info->tp_info; in applespi_find_touchpad_info()
1233 tp_info = applespi_find_touchpad_info(rcvd_tp_info->model_no); in applespi_register_touchpad_device()
1235 dev_warn(&applespi->spi->dev, in applespi_register_touchpad_device()
1236 "Unknown touchpad model %x - falling back to MB8 touchpad\n", in applespi_register_touchpad_device()
1237 rcvd_tp_info->model_no); in applespi_register_touchpad_device()
1241 applespi->tp_info = *tp_info; in applespi_register_touchpad_device()
1248 dev_info(&applespi->spi->dev, in applespi_register_touchpad_device()
1250 applespi->tp_info.x_min = x; in applespi_register_touchpad_device()
1251 applespi->tp_info.y_min = y; in applespi_register_touchpad_device()
1252 applespi->tp_info.x_max = x + w; in applespi_register_touchpad_device()
1253 applespi->tp_info.y_max = y + h; in applespi_register_touchpad_device()
1255 dev_warn(&applespi->spi->dev, in applespi_register_touchpad_device()
1264 applespi->tp_info.x_min, in applespi_register_touchpad_device()
1265 applespi->tp_info.y_min, in applespi_register_touchpad_device()
1266 applespi->tp_info.x_max - applespi->tp_info.x_min, in applespi_register_touchpad_device()
1267 applespi->tp_info.y_max - applespi->tp_info.y_min); in applespi_register_touchpad_device()
1271 touchpad_input_dev = devm_input_allocate_device(&applespi->spi->dev); in applespi_register_touchpad_device()
1273 dev_err(&applespi->spi->dev, in applespi_register_touchpad_device()
1275 return -ENOMEM; in applespi_register_touchpad_device()
1278 touchpad_input_dev->name = "Apple SPI Touchpad"; in applespi_register_touchpad_device()
1279 touchpad_input_dev->phys = "applespi/input1"; in applespi_register_touchpad_device()
1280 touchpad_input_dev->dev.parent = &applespi->spi->dev; in applespi_register_touchpad_device()
1281 touchpad_input_dev->id.bustype = BUS_SPI; in applespi_register_touchpad_device()
1282 touchpad_input_dev->id.vendor = SYNAPTICS_VENDOR_ID; in applespi_register_touchpad_device()
1283 touchpad_input_dev->id.product = in applespi_register_touchpad_device()
1284 rcvd_tp_info->model_no << 8 | rcvd_tp_info->model_flags; in applespi_register_touchpad_device()
1290 __set_bit(INPUT_PROP_POINTER, touchpad_input_dev->propbit); in applespi_register_touchpad_device()
1291 __set_bit(INPUT_PROP_BUTTONPAD, touchpad_input_dev->propbit); in applespi_register_touchpad_device()
1307 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, in applespi_register_touchpad_device()
1312 applespi->tp_info.x_min, applespi->tp_info.x_max, in applespi_register_touchpad_device()
1315 applespi->tp_info.y_min, applespi->tp_info.y_max, in applespi_register_touchpad_device()
1326 dev_err(&applespi->spi->dev, in applespi_register_touchpad_device()
1334 dev_err(&applespi->spi->dev, in applespi_register_touchpad_device()
1340 smp_store_release(&applespi->touchpad_input_dev, touchpad_input_dev); in applespi_register_touchpad_device()
1350 applespi_register_touchpad_device(applespi, &applespi->rcvd_tp_info); in applespi_worker()
1357 if (packet->device == PACKET_DEV_INFO && in applespi_handle_cmd_response()
1358 le16_to_cpu(message->type) == 0x1020) { in applespi_handle_cmd_response()
1363 applespi->rcvd_tp_info = message->tp_info; in applespi_handle_cmd_response()
1364 schedule_work(&applespi->work); in applespi_handle_cmd_response()
1368 if (le16_to_cpu(message->length) != 0x0000) { in applespi_handle_cmd_response()
1369 dev_warn_ratelimited(&applespi->spi->dev, in applespi_handle_cmd_response()
1371 le16_to_cpu(message->length)); in applespi_handle_cmd_response()
1375 if (packet->device == PACKET_DEV_TPAD && in applespi_handle_cmd_response()
1376 le16_to_cpu(message->type) == 0x0252 && in applespi_handle_cmd_response()
1377 le16_to_cpu(message->rsp_buf_len) == 0x0002) in applespi_handle_cmd_response()
1378 dev_info(&applespi->spi->dev, "modeswitch done.\n"); in applespi_handle_cmd_response()
1388 dev_warn_ratelimited(&applespi->spi->dev, in applespi_verify_crc()
1403 if (packet->flags == PACKET_TYPE_READ && in applespi_debug_print_read_packet()
1404 packet->device == PACKET_DEV_KEYB) in applespi_debug_print_read_packet()
1406 else if (packet->flags == PACKET_TYPE_READ && in applespi_debug_print_read_packet()
1407 packet->device == PACKET_DEV_TPAD) in applespi_debug_print_read_packet()
1409 else if (packet->flags == PACKET_TYPE_WRITE) in applespi_debug_print_read_packet()
1410 evt_type = applespi->cmd_evt_type; in applespi_debug_print_read_packet()
1414 applespi_get_trace_fun(evt_type)(evt_type, PT_READ, applespi->rx_buffer, in applespi_debug_print_read_packet()
1428 if (!applespi_verify_crc(applespi, applespi->rx_buffer, in applespi_got_data()
1432 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_got_data()
1434 if (applespi->drain) { in applespi_got_data()
1435 applespi->read_active = false; in applespi_got_data()
1436 applespi->write_active = false; in applespi_got_data()
1438 wake_up_all(&applespi->drain_complete); in applespi_got_data()
1441 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_got_data()
1446 packet = (struct spi_packet *)applespi->rx_buffer; in applespi_got_data()
1450 off = le16_to_cpu(packet->offset); in applespi_got_data()
1451 rem = le16_to_cpu(packet->remaining); in applespi_got_data()
1452 len = le16_to_cpu(packet->length); in applespi_got_data()
1454 if (len > sizeof(packet->data)) { in applespi_got_data()
1455 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1461 /* handle multi-packet messages */ in applespi_got_data()
1463 if (off != applespi->saved_msg_len) { in applespi_got_data()
1464 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1466 off, applespi->saved_msg_len); in applespi_got_data()
1471 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1478 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1484 memcpy(applespi->msg_buf + off, &packet->data, len); in applespi_got_data()
1485 applespi->saved_msg_len += len; in applespi_got_data()
1490 message = (struct message *)applespi->msg_buf; in applespi_got_data()
1491 msg_len = applespi->saved_msg_len; in applespi_got_data()
1493 message = (struct message *)&packet->data; in applespi_got_data()
1497 /* got complete message - verify */ in applespi_got_data()
1501 if (le16_to_cpu(message->length) != msg_len - MSG_HEADER_SIZE - 2) { in applespi_got_data()
1502 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1503 "Received corrupted packet (invalid message length %u - expected %u)\n", in applespi_got_data()
1504 le16_to_cpu(message->length), in applespi_got_data()
1505 msg_len - MSG_HEADER_SIZE - 2); in applespi_got_data()
1510 if (packet->flags == PACKET_TYPE_READ && in applespi_got_data()
1511 packet->device == PACKET_DEV_KEYB) { in applespi_got_data()
1512 applespi_handle_keyboard_event(applespi, &message->keyboard); in applespi_got_data()
1514 } else if (packet->flags == PACKET_TYPE_READ && in applespi_got_data()
1515 packet->device == PACKET_DEV_TPAD) { in applespi_got_data()
1519 tp = &message->touchpad; in applespi_got_data()
1520 tp_len = struct_size(tp, fingers, tp->number_of_fingers); in applespi_got_data()
1522 if (le16_to_cpu(message->length) + 2 != tp_len) { in applespi_got_data()
1523 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1524 "Received corrupted packet (invalid message length %u - num-fingers %u, tp-len %zu)\n", in applespi_got_data()
1525 le16_to_cpu(message->length), in applespi_got_data()
1526 tp->number_of_fingers, tp_len); in applespi_got_data()
1530 if (tp->number_of_fingers > MAX_FINGERS) { in applespi_got_data()
1531 dev_warn_ratelimited(&applespi->spi->dev, in applespi_got_data()
1532 "Number of reported fingers (%u) exceeds max (%u))\n", in applespi_got_data()
1533 tp->number_of_fingers, in applespi_got_data()
1535 tp->number_of_fingers = MAX_FINGERS; in applespi_got_data()
1540 } else if (packet->flags == PACKET_TYPE_WRITE) { in applespi_got_data()
1545 applespi->saved_msg_len = 0; in applespi_got_data()
1547 applespi_msg_complete(applespi, packet->flags == PACKET_TYPE_WRITE, in applespi_got_data()
1555 if (applespi->rd_m.status < 0) { in applespi_async_read_complete()
1556 dev_warn(&applespi->spi->dev, "Error reading from device: %d\n", in applespi_async_read_complete()
1557 applespi->rd_m.status); in applespi_async_read_complete()
1568 acpi_finish_gpe(NULL, applespi->gpe); in applespi_async_read_complete()
1579 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_notify()
1581 if (!applespi->suspended) { in applespi_notify()
1582 sts = applespi_async(applespi, &applespi->rd_m, in applespi_notify()
1585 dev_warn(&applespi->spi->dev, in applespi_notify()
1589 applespi->read_active = true; in applespi_notify()
1592 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_notify()
1607 dev_warn(&applespi->spi->dev, in applespi_get_saved_bl_level()
1611 return sts != EFI_SUCCESS ? -ENODEV : efi_data; in applespi_get_saved_bl_level()
1629 dev_warn(&applespi->spi->dev, in applespi_save_bl_level()
1636 acpi_handle spi_handle = ACPI_HANDLE(&spi->dev); in applespi_probe()
1645 dev_info(&spi->dev, "USB interface already enabled\n"); in applespi_probe()
1646 return -ENODEV; in applespi_probe()
1650 applespi = devm_kzalloc(&spi->dev, sizeof(*applespi), GFP_KERNEL); in applespi_probe()
1652 return -ENOMEM; in applespi_probe()
1654 applespi->spi = spi; in applespi_probe()
1656 INIT_WORK(&applespi->work, applespi_worker); in applespi_probe()
1662 applespi->tx_buffer = devm_kmalloc(&spi->dev, APPLESPI_PACKET_SIZE, in applespi_probe()
1664 applespi->tx_status = devm_kmalloc(&spi->dev, APPLESPI_STATUS_SIZE, in applespi_probe()
1666 applespi->rx_buffer = devm_kmalloc(&spi->dev, APPLESPI_PACKET_SIZE, in applespi_probe()
1668 applespi->msg_buf = devm_kmalloc_array(&spi->dev, MAX_PKTS_PER_MSG, in applespi_probe()
1672 if (!applespi->tx_buffer || !applespi->tx_status || in applespi_probe()
1673 !applespi->rx_buffer || !applespi->msg_buf) in applespi_probe()
1674 return -ENOMEM; in applespi_probe()
1681 acpi_sts = acpi_get_handle(spi_handle, "SIEN", &applespi->sien); in applespi_probe()
1683 dev_err(&applespi->spi->dev, in applespi_probe()
1686 return -ENODEV; in applespi_probe()
1689 acpi_sts = acpi_get_handle(spi_handle, "SIST", &applespi->sist); in applespi_probe()
1691 dev_err(&applespi->spi->dev, in applespi_probe()
1694 return -ENODEV; in applespi_probe()
1707 applespi->keyboard_input_dev = devm_input_allocate_device(&spi->dev); in applespi_probe()
1709 if (!applespi->keyboard_input_dev) in applespi_probe()
1710 return -ENOMEM; in applespi_probe()
1712 applespi->keyboard_input_dev->name = "Apple SPI Keyboard"; in applespi_probe()
1713 applespi->keyboard_input_dev->phys = "applespi/input0"; in applespi_probe()
1714 applespi->keyboard_input_dev->dev.parent = &spi->dev; in applespi_probe()
1715 applespi->keyboard_input_dev->id.bustype = BUS_SPI; in applespi_probe()
1717 applespi->keyboard_input_dev->evbit[0] = in applespi_probe()
1719 applespi->keyboard_input_dev->ledbit[0] = BIT_MASK(LED_CAPSL); in applespi_probe()
1721 input_set_drvdata(applespi->keyboard_input_dev, applespi); in applespi_probe()
1722 applespi->keyboard_input_dev->event = applespi_event; in applespi_probe()
1726 input_set_capability(applespi->keyboard_input_dev, in applespi_probe()
1731 input_set_capability(applespi->keyboard_input_dev, in applespi_probe()
1736 input_set_capability(applespi->keyboard_input_dev, in applespi_probe()
1739 input_set_capability(applespi->keyboard_input_dev, EV_KEY, KEY_FN); in applespi_probe()
1741 sts = input_register_device(applespi->keyboard_input_dev); in applespi_probe()
1743 dev_err(&applespi->spi->dev, in applespi_probe()
1745 return -ENODEV; in applespi_probe()
1754 dev_err(&applespi->spi->dev, in applespi_probe()
1757 return -ENODEV; in applespi_probe()
1759 applespi->gpe = (int)gpe; in applespi_probe()
1761 acpi_sts = acpi_install_gpe_handler(NULL, applespi->gpe, in applespi_probe()
1765 dev_err(&applespi->spi->dev, in applespi_probe()
1767 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_probe()
1768 return -ENODEV; in applespi_probe()
1771 applespi->suspended = false; in applespi_probe()
1773 acpi_sts = acpi_enable_gpe(NULL, applespi->gpe); in applespi_probe()
1775 dev_err(&applespi->spi->dev, in applespi_probe()
1777 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_probe()
1778 acpi_remove_gpe_handler(NULL, applespi->gpe, applespi_notify); in applespi_probe()
1779 return -ENODEV; in applespi_probe()
1790 device_wakeup_enable(&spi->dev); in applespi_probe()
1792 /* set up keyboard-backlight */ in applespi_probe()
1795 applespi_set_bl_level(&applespi->backlight_info, sts); in applespi_probe()
1797 applespi->backlight_info.name = "spi::kbd_backlight"; in applespi_probe()
1798 applespi->backlight_info.default_trigger = "kbd-backlight"; in applespi_probe()
1799 applespi->backlight_info.brightness_set = applespi_set_bl_level; in applespi_probe()
1801 sts = devm_led_classdev_register(&spi->dev, &applespi->backlight_info); in applespi_probe()
1803 dev_warn(&applespi->spi->dev, in applespi_probe()
1808 applespi->debugfs_root = debugfs_create_dir("applespi", NULL); in applespi_probe()
1810 debugfs_create_bool("enable_tp_dim", 0600, applespi->debugfs_root, in applespi_probe()
1811 &applespi->debug_tp_dim); in applespi_probe()
1813 debugfs_create_file("tp_dim", 0400, applespi->debugfs_root, applespi, in applespi_probe()
1823 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_drain_writes()
1825 applespi->drain = true; in applespi_drain_writes()
1826 wait_event_lock_irq(applespi->drain_complete, !applespi->write_active, in applespi_drain_writes()
1827 applespi->cmd_msg_lock); in applespi_drain_writes()
1829 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_drain_writes()
1836 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_drain_reads()
1838 wait_event_lock_irq(applespi->drain_complete, !applespi->read_active, in applespi_drain_reads()
1839 applespi->cmd_msg_lock); in applespi_drain_reads()
1841 applespi->suspended = true; in applespi_drain_reads()
1843 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_drain_reads()
1852 acpi_disable_gpe(NULL, applespi->gpe); in applespi_remove()
1853 acpi_remove_gpe_handler(NULL, applespi->gpe, applespi_notify); in applespi_remove()
1854 device_wakeup_disable(&spi->dev); in applespi_remove()
1858 debugfs_remove_recursive(applespi->debugfs_root); in applespi_remove()
1865 applespi_save_bl_level(applespi, applespi->have_bl_level); in applespi_shutdown()
1873 applespi_save_bl_level(applespi, applespi->have_bl_level); in applespi_poweroff_late()
1885 /* turn off caps-lock - it'll stay on otherwise */ in applespi_suspend()
1888 dev_warn(&applespi->spi->dev, in applespi_suspend()
1889 "Failed to turn off caps-lock led (%d)\n", sts); in applespi_suspend()
1894 acpi_sts = acpi_disable_gpe(NULL, applespi->gpe); in applespi_suspend()
1896 dev_err(&applespi->spi->dev, in applespi_suspend()
1898 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_suspend()
1913 spin_lock_irqsave(&applespi->cmd_msg_lock, flags); in applespi_resume()
1915 applespi->drain = false; in applespi_resume()
1916 applespi->have_cl_led_on = false; in applespi_resume()
1917 applespi->have_bl_level = 0; in applespi_resume()
1918 applespi->cmd_msg_queued = 0; in applespi_resume()
1919 applespi->read_active = false; in applespi_resume()
1920 applespi->write_active = false; in applespi_resume()
1922 applespi->suspended = false; in applespi_resume()
1924 spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); in applespi_resume()
1929 /* re-enable the interrupt */ in applespi_resume()
1930 acpi_sts = acpi_enable_gpe(NULL, applespi->gpe); in applespi_resume()
1932 dev_err(&applespi->spi->dev, in applespi_resume()
1933 "Failed to re-enable GPE handler for GPE %d: %s\n", in applespi_resume()
1934 applespi->gpe, acpi_format_exception(acpi_sts)); in applespi_resume()