1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2019 Google LLC
6 #include <linux/platform_data/wilco-ec.h>
7 #include <linux/string.h>
8 #include <linux/unaligned/le_memmove.h>
10 /* Operation code; what the EC should do with the property */
16 struct ec_property_request {
17 u8 op; /* One of enum ec_property_op */
18 u8 property_id[4]; /* The 32 bit PID is stored Little Endian */
20 u8 data[WILCO_EC_PROPERTY_MAX_SIZE];
23 struct ec_property_response {
25 u8 op; /* One of enum ec_property_op */
26 u8 property_id[4]; /* The 32 bit PID is stored Little Endian */
28 u8 data[WILCO_EC_PROPERTY_MAX_SIZE];
31 static int send_property_msg(struct wilco_ec_device *ec,
32 struct ec_property_request *rq,
33 struct ec_property_response *rs)
35 struct wilco_ec_message ec_msg;
38 memset(&ec_msg, 0, sizeof(ec_msg));
39 ec_msg.type = WILCO_EC_MSG_PROPERTY;
40 ec_msg.request_data = rq;
41 ec_msg.request_size = sizeof(*rq);
42 ec_msg.response_data = rs;
43 ec_msg.response_size = sizeof(*rs);
45 ret = wilco_ec_mailbox(ec, &ec_msg);
50 if (memcmp(rq->property_id, rs->property_id, sizeof(rs->property_id)))
56 int wilco_ec_get_property(struct wilco_ec_device *ec,
57 struct wilco_ec_property_msg *prop_msg)
59 struct ec_property_request rq;
60 struct ec_property_response rs;
63 memset(&rq, 0, sizeof(rq));
65 put_unaligned_le32(prop_msg->property_id, rq.property_id);
67 ret = send_property_msg(ec, &rq, &rs);
71 prop_msg->length = rs.length;
72 memcpy(prop_msg->data, rs.data, rs.length);
76 EXPORT_SYMBOL_GPL(wilco_ec_get_property);
78 int wilco_ec_set_property(struct wilco_ec_device *ec,
79 struct wilco_ec_property_msg *prop_msg)
81 struct ec_property_request rq;
82 struct ec_property_response rs;
85 memset(&rq, 0, sizeof(rq));
87 put_unaligned_le32(prop_msg->property_id, rq.property_id);
88 rq.length = prop_msg->length;
89 memcpy(rq.data, prop_msg->data, prop_msg->length);
91 ret = send_property_msg(ec, &rq, &rs);
94 if (rs.length != prop_msg->length)
99 EXPORT_SYMBOL_GPL(wilco_ec_set_property);
101 int wilco_ec_get_byte_property(struct wilco_ec_device *ec, u32 property_id,
104 struct wilco_ec_property_msg msg;
107 msg.property_id = property_id;
109 ret = wilco_ec_get_property(ec, &msg);
119 EXPORT_SYMBOL_GPL(wilco_ec_get_byte_property);
121 int wilco_ec_set_byte_property(struct wilco_ec_device *ec, u32 property_id,
124 struct wilco_ec_property_msg msg;
126 msg.property_id = property_id;
130 return wilco_ec_set_property(ec, &msg);
132 EXPORT_SYMBOL_GPL(wilco_ec_set_byte_property);