|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | + |
| 3 | +#include <linux/mei_cl_bus.h> |
| 4 | +#include <linux/types.h> |
| 5 | + |
| 6 | +#include "context.h" |
| 7 | +#include "params.h" |
| 8 | +#include "protocol/commands.h" |
| 9 | +#include "protocol/enums.h" |
| 10 | +#include "protocol/events.h" |
| 11 | +#include "protocol/touch.h" |
| 12 | +#include "resources.h" |
| 13 | + |
| 14 | +int ipts_control_send(struct ipts_context *ipts, |
| 15 | + u32 cmd, void *data, u32 size) |
| 16 | +{ |
| 17 | + int ret; |
| 18 | + struct ipts_command msg; |
| 19 | + |
| 20 | + memset(&msg, 0, sizeof(struct ipts_command)); |
| 21 | + msg.code = cmd; |
| 22 | + |
| 23 | + // Copy message payload |
| 24 | + if (data && size > 0) |
| 25 | + memcpy(&msg.data, data, size); |
| 26 | + |
| 27 | + ret = mei_cldev_send(ipts->client_dev, (u8 *)&msg, |
| 28 | + sizeof(msg.code) + size); |
| 29 | + if (ret < 0) { |
| 30 | + dev_err(ipts->dev, "%s: error 0x%X:%d\n", __func__, cmd, ret); |
| 31 | + return ret; |
| 32 | + } |
| 33 | + |
| 34 | + return 0; |
| 35 | +} |
| 36 | + |
| 37 | +int ipts_control_send_feedback(struct ipts_context *ipts, |
| 38 | + u32 buffer, u32 transaction) |
| 39 | +{ |
| 40 | + struct ipts_buffer_info feedback_buffer; |
| 41 | + struct ipts_feedback *feedback; |
| 42 | + struct ipts_feedback_cmd cmd; |
| 43 | + |
| 44 | + feedback_buffer = ipts->feedback[buffer]; |
| 45 | + feedback = (struct ipts_feedback *)feedback_buffer.address; |
| 46 | + |
| 47 | + memset(feedback, 0, sizeof(struct ipts_feedback)); |
| 48 | + memset(&cmd, 0, sizeof(struct ipts_feedback_cmd)); |
| 49 | + |
| 50 | + feedback->type = IPTS_FEEDBACK_TYPE_NONE; |
| 51 | + feedback->transaction = transaction; |
| 52 | + |
| 53 | + cmd.buffer = buffer; |
| 54 | + cmd.transaction = transaction; |
| 55 | + |
| 56 | + return ipts_control_send(ipts, IPTS_CMD(FEEDBACK), |
| 57 | + &cmd, sizeof(struct ipts_feedback_cmd)); |
| 58 | +} |
| 59 | + |
| 60 | +int ipts_control_start(struct ipts_context *ipts) |
| 61 | +{ |
| 62 | + ipts->status = IPTS_HOST_STATUS_INIT; |
| 63 | + |
| 64 | + if (ipts_params.singletouch) |
| 65 | + ipts->mode = IPTS_SENSOR_MODE_SINGLETOUCH; |
| 66 | + else |
| 67 | + ipts->mode = IPTS_SENSOR_MODE_MULTITOUCH; |
| 68 | + |
| 69 | + return ipts_control_send(ipts, IPTS_CMD(NOTIFY_DEV_READY), NULL, 0); |
| 70 | +} |
| 71 | + |
| 72 | +void ipts_control_stop(struct ipts_context *ipts) |
| 73 | +{ |
| 74 | + enum ipts_host_status old_status = ipts->status; |
| 75 | + |
| 76 | + ipts->status = IPTS_HOST_STATUS_STOPPING; |
| 77 | + ipts_control_send(ipts, IPTS_CMD(QUIESCE_IO), NULL, 0); |
| 78 | + ipts_control_send(ipts, IPTS_CMD(CLEAR_MEM_WINDOW), NULL, 0); |
| 79 | + |
| 80 | + if (old_status < IPTS_HOST_STATUS_RESOURCE_READY) |
| 81 | + return; |
| 82 | + |
| 83 | + ipts_resources_free(ipts); |
| 84 | +} |
| 85 | + |
| 86 | +int ipts_control_restart(struct ipts_context *ipts) |
| 87 | +{ |
| 88 | + dev_info(ipts->dev, "Restarting IPTS\n"); |
| 89 | + ipts_control_stop(ipts); |
| 90 | + |
| 91 | + ipts->status = IPTS_HOST_STATUS_RESTARTING; |
| 92 | + return ipts_control_send(ipts, IPTS_CMD(QUIESCE_IO), NULL, 0); |
| 93 | +} |
0 commit comments