astlpc: Introduce KCS accessors
Introducing mctp_astlpc_kcs_{read,write}() results in a minor reduction
of boilerplate and tidying of formatting.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I416592491197d419b7418f1ad33abbff2697119d
diff --git a/astlpc.c b/astlpc.c
index fe4b84f..320be6a 100644
--- a/astlpc.c
+++ b/astlpc.c
@@ -124,6 +124,20 @@
#define KCS_STATUS_IBF 0x02
#define KCS_STATUS_OBF 0x01
+static inline int mctp_astlpc_kcs_write(struct mctp_binding_astlpc *astlpc,
+ enum mctp_binding_astlpc_kcs_reg reg,
+ uint8_t val)
+{
+ return astlpc->ops.kcs_write(astlpc->ops_data, reg, val);
+}
+
+static inline int mctp_astlpc_kcs_read(struct mctp_binding_astlpc *astlpc,
+ enum mctp_binding_astlpc_kcs_reg reg,
+ uint8_t *val)
+{
+ return astlpc->ops.kcs_read(astlpc->ops_data, reg, val);
+}
+
static inline int mctp_astlpc_lpc_write(struct mctp_binding_astlpc *astlpc,
const void *buf, long offset,
size_t len)
@@ -183,15 +197,13 @@
data = 0xff;
status |= KCS_STATUS_OBF;
- rc = astlpc->ops.kcs_write(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_STATUS,
- status);
+ rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, status);
if (rc) {
astlpc_prwarn(astlpc, "KCS status write failed");
return -1;
}
- rc = astlpc->ops.kcs_write(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_DATA,
- data);
+ rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_DATA, data);
if (rc) {
astlpc_prwarn(astlpc, "KCS dummy data write failed");
return -1;
@@ -247,8 +259,7 @@
uint8_t status;
int rc;
- rc = astlpc->ops.kcs_read(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_STATUS,
- &status);
+ rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, &status);
if (rc) {
mctp_prwarn("KCS status read failed");
return rc;
@@ -275,8 +286,7 @@
sizeof(ver_cur_be));
/* Send channel init command */
- rc = astlpc->ops.kcs_write(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_DATA,
- 0x0);
+ rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_DATA, 0x0);
if (rc) {
astlpc_prwarn(astlpc, "KCS write failed");
}
@@ -325,8 +335,8 @@
int rc;
for (;;) {
- rc = astlpc->ops.kcs_read(astlpc->ops_data,
- MCTP_ASTLPC_KCS_REG_STATUS, &status);
+ rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS,
+ &status);
if (rc) {
astlpc_prwarn(astlpc, "KCS status read failed");
return -1;
@@ -336,8 +346,7 @@
/* todo: timeout */
}
- rc = astlpc->ops.kcs_write(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_DATA,
- data);
+ rc = mctp_astlpc_kcs_write(astlpc, MCTP_ASTLPC_KCS_REG_DATA, data);
if (rc) {
astlpc_prwarn(astlpc, "KCS data write failed");
return -1;
@@ -467,8 +476,7 @@
uint8_t status, data;
int rc;
- rc = astlpc->ops.kcs_read(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_STATUS,
- &status);
+ rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_STATUS, &status);
if (rc) {
astlpc_prwarn(astlpc, "KCS read error");
return -1;
@@ -479,8 +487,7 @@
if (!mctp_astlpc_kcs_read_ready(astlpc, status))
return 0;
- rc = astlpc->ops.kcs_read(astlpc->ops_data, MCTP_ASTLPC_KCS_REG_DATA,
- &data);
+ rc = mctp_astlpc_kcs_read(astlpc, MCTP_ASTLPC_KCS_REG_DATA, &data);
if (rc) {
astlpc_prwarn(astlpc, "KCS data read error");
return -1;