Lines Matching defs:z2

30 #define CAL_PROP_NAME                    "apple,z2-cal-blob"
82 static void apple_z2_parse_touches(struct apple_z2 *z2,
96 slot = input_mt_get_slot_by_key(z2->input_dev, fingers[i].finger);
98 dev_warn(&z2->spidev->dev, "unable to get slot for finger\n");
103 input_mt_slot(z2->input_dev, slot);
104 if (!input_mt_report_slot_state(z2->input_dev, MT_TOOL_FINGER, slot_valid))
106 touchscreen_report_pos(z2->input_dev, &z2->props,
110 input_report_abs(z2->input_dev, ABS_MT_WIDTH_MAJOR,
112 input_report_abs(z2->input_dev, ABS_MT_WIDTH_MINOR,
114 input_report_abs(z2->input_dev, ABS_MT_ORIENTATION,
116 input_report_abs(z2->input_dev, ABS_MT_TOUCH_MAJOR,
118 input_report_abs(z2->input_dev, ABS_MT_TOUCH_MINOR,
121 input_mt_sync_frame(z2->input_dev);
122 input_sync(z2->input_dev);
125 static int apple_z2_read_packet(struct apple_z2 *z2)
127 struct apple_z2_read_interrupt_cmd *len_cmd = (void *)z2->tx_buf;
134 len_cmd->counter = z2->index_parity + 1;
137 z2->index_parity = !z2->index_parity;
138 xfer.tx_buf = z2->tx_buf;
139 xfer.rx_buf = z2->rx_buf;
142 error = spi_sync_transfer(z2->spidev, &xfer, 1);
146 if (z2->rx_buf[0] != APPLE_Z2_REPLY_INTERRUPT_DATA)
149 pkt_len = (get_unaligned_le16(z2->rx_buf + 1) + 8) & 0xfffffffc;
151 error = spi_read(z2->spidev, z2->rx_buf, pkt_len);
155 apple_z2_parse_touches(z2, z2->rx_buf + 5, pkt_len - 5);
162 struct apple_z2 *z2 = data;
164 if (unlikely(!z2->booted))
165 complete(&z2->boot_irq);
167 apple_z2_read_packet(z2);
173 static const u8 *apple_z2_build_cal_blob(struct apple_z2 *z2,
185 if (!device_property_present(&z2->spidev->dev, CAL_PROP_NAME))
188 cal_size = device_property_count_u8(&z2->spidev->dev, CAL_PROP_NAME);
208 error = device_property_read_u8_array(&z2->spidev->dev, CAL_PROP_NAME,
222 static int apple_z2_send_firmware_blob(struct apple_z2 *z2, const u8 *data,
229 z2->tx_buf[0] = 0x1a;
230 z2->tx_buf[1] = 0xa1;
241 ack_xfer.tx_buf = z2->tx_buf;
245 reinit_completion(&z2->boot_irq);
246 error = spi_sync(z2->spidev, &msg);
251 wait_for_completion_timeout(&z2->boot_irq, msecs_to_jiffies(20));
256 static int apple_z2_upload_firmware(struct apple_z2 *z2)
267 error = request_firmware(&fw, z2->fw_name, &z2->spidev->dev);
269 dev_err(&z2->spidev->dev, "unable to load firmware\n");
275 dev_err(&z2->spidev->dev, "invalid firmware header\n");
286 dev_err(&z2->spidev->dev, "firmware malformed\n");
296 dev_err(&z2->spidev->dev, "firmware malformed\n");
300 error = apple_z2_send_firmware_blob(z2, fw->data + fw_idx,
310 apple_z2_build_cal_blob(z2, address, &size);
315 error = apple_z2_send_firmware_blob(z2, data, size, false);
320 dev_err(&z2->spidev->dev, "firmware malformed\n");
327 z2->booted = true;
328 apple_z2_read_packet(z2);
332 static int apple_z2_boot(struct apple_z2 *z2)
336 reinit_completion(&z2->boot_irq);
337 enable_irq(z2->spidev->irq);
338 gpiod_set_value(z2->reset_gpio, 0);
339 if (!wait_for_completion_timeout(&z2->boot_irq, msecs_to_jiffies(20)))
342 error = apple_z2_upload_firmware(z2);
344 gpiod_set_value(z2->reset_gpio, 1);
345 disable_irq(z2->spidev->irq);
355 struct apple_z2 *z2;
358 z2 = devm_kzalloc_obj(dev, *z2);
359 if (!z2)
362 z2->tx_buf = devm_kzalloc(dev, sizeof(struct apple_z2_read_interrupt_cmd), GFP_KERNEL);
363 if (!z2->tx_buf)
366 z2->rx_buf = devm_kzalloc(dev, 4000, GFP_KERNEL);
367 if (!z2->rx_buf)
370 z2->spidev = spi;
371 init_completion(&z2->boot_irq);
372 spi_set_drvdata(spi, z2);
375 z2->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
376 if (IS_ERR(z2->reset_gpio))
377 return dev_err_probe(dev, PTR_ERR(z2->reset_gpio), "unable to get reset\n");
379 error = devm_request_threaded_irq(dev, z2->spidev->irq, NULL, apple_z2_irq,
381 "apple-z2-irq", z2);
385 error = device_property_read_string(dev, "firmware-name", &z2->fw_name);
389 z2->input_dev = devm_input_allocate_device(dev);
390 if (!z2->input_dev)
393 z2->input_dev->name = (char *)spi_get_device_id(spi)->driver_data;
394 z2->input_dev->phys = "apple_z2";
395 z2->input_dev->id.bustype = BUS_SPI;
398 input_set_abs_params(z2->input_dev, ABS_MT_POSITION_X, 0, 0, 0, 0);
399 input_set_abs_params(z2->input_dev, ABS_MT_POSITION_Y, 0, 0, 0, 0);
400 touchscreen_parse_properties(z2->input_dev, true, &z2->props);
401 input_abs_set_res(z2->input_dev, ABS_MT_POSITION_X, 100);
402 input_abs_set_res(z2->input_dev, ABS_MT_POSITION_Y, 100);
403 input_set_abs_params(z2->input_dev, ABS_MT_WIDTH_MAJOR, 0, 65535, 0, 0);
404 input_set_abs_params(z2->input_dev, ABS_MT_WIDTH_MINOR, 0, 65535, 0, 0);
405 input_set_abs_params(z2->input_dev, ABS_MT_TOUCH_MAJOR, 0, 65535, 0, 0);
406 input_set_abs_params(z2->input_dev, ABS_MT_TOUCH_MINOR, 0, 65535, 0, 0);
407 input_set_abs_params(z2->input_dev, ABS_MT_ORIENTATION, -32768, 32767, 0, 0);
409 error = input_mt_init_slots(z2->input_dev, 256, INPUT_MT_DIRECT);
413 error = input_register_device(z2->input_dev);
419 error = apple_z2_boot(z2);
428 struct apple_z2 *z2 = spi_get_drvdata(spi);
430 disable_irq(z2->spidev->irq);
431 gpiod_direction_output(z2->reset_gpio, 1);
432 z2->booted = false;
444 struct apple_z2 *z2 = spi_get_drvdata(to_spi_device(dev));
446 return apple_z2_boot(z2);
467 .name = "apple-z2",