[PATCH v2 1/2] platform/chrome: cros_ec_lpc: Add R/W helpers to LPC protocol variants

2016-12-02 Thread Thierry Escande
From: Shawn Nematbakhsh 

Call common functions for read / write to prepare support for future
LPC protocol variants which use different I/O ops than inb / outb.

Signed-off-by: Shawn Nematbakhsh 
Signed-off-by: Thierry Escande 
---
 drivers/platform/chrome/Makefile  |  3 +-
 drivers/platform/chrome/cros_ec_lpc.c | 88 +--
 drivers/platform/chrome/cros_ec_lpc_reg.c | 64 ++
 include/linux/mfd/cros_ec_lpc_reg.h   | 47 +
 4 files changed, 151 insertions(+), 51 deletions(-)
 create mode 100644 drivers/platform/chrome/cros_ec_lpc_reg.c
 create mode 100644 include/linux/mfd/cros_ec_lpc_reg.h

diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
index 4f34627..127fbe8 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_CHROMEOS_PSTORE)   += chromeos_pstore.o
 cros_ec_devs-objs  := cros_ec_dev.o cros_ec_sysfs.o \
   cros_ec_lightbar.o cros_ec_vbc.o
 obj-$(CONFIG_CROS_EC_CHARDEV)  += cros_ec_devs.o
-obj-$(CONFIG_CROS_EC_LPC)  += cros_ec_lpc.o
+cros_ec_lpcs-objs  := cros_ec_lpc.o cros_ec_lpc_reg.o
+obj-$(CONFIG_CROS_EC_LPC)  += cros_ec_lpcs.o
 obj-$(CONFIG_CROS_EC_PROTO)+= cros_ec_proto.o
 obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT)   += cros_kbd_led_backlight.o
diff --git a/drivers/platform/chrome/cros_ec_lpc.c 
b/drivers/platform/chrome/cros_ec_lpc.c
index f9a2454..6a782a6 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -26,19 +26,22 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
-#define DRV_NAME "cros_ec_lpc"
+#define DRV_NAME "cros_ec_lpcs"
 
 static int ec_response_timed_out(void)
 {
unsigned long one_second = jiffies + HZ;
+   u8 data;
 
usleep_range(200, 300);
do {
-   if (!(inb(EC_LPC_ADDR_HOST_CMD) & EC_LPC_STATUS_BUSY_MASK))
+   if (!(cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_CMD, 1, ) &
+   EC_LPC_STATUS_BUSY_MASK))
return 0;
usleep_range(100, 200);
} while (time_before(jiffies, one_second));
@@ -51,21 +54,20 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
 {
struct ec_host_request *request;
struct ec_host_response response;
-   u8 sum = 0;
-   int i;
+   u8 sum;
int ret = 0;
u8 *dout;
 
ret = cros_ec_prepare_tx(ec, msg);
 
/* Write buffer */
-   for (i = 0; i < ret; i++)
-   outb(ec->dout[i], EC_LPC_ADDR_HOST_PACKET + i);
+   cros_ec_lpc_write_bytes(EC_LPC_ADDR_HOST_PACKET, ret, ec->dout);
 
request = (struct ec_host_request *)ec->dout;
 
/* Here we go */
-   outb(EC_COMMAND_PROTOCOL_3, EC_LPC_ADDR_HOST_CMD);
+   sum = EC_COMMAND_PROTOCOL_3;
+   cros_ec_lpc_write_bytes(EC_LPC_ADDR_HOST_CMD, 1, );
 
if (ec_response_timed_out()) {
dev_warn(ec->dev, "EC responsed timed out\n");
@@ -74,17 +76,15 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
}
 
/* Check result */
-   msg->result = inb(EC_LPC_ADDR_HOST_DATA);
+   msg->result = cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_DATA, 1, );
ret = cros_ec_check_result(ec, msg);
if (ret)
goto done;
 
/* Read back response */
dout = (u8 *)
-   for (i = 0; i < sizeof(response); i++) {
-   dout[i] = inb(EC_LPC_ADDR_HOST_PACKET + i);
-   sum += dout[i];
-   }
+   sum = cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_PACKET, sizeof(response),
+dout);
 
msg->result = response.result;
 
@@ -97,11 +97,9 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
}
 
/* Read response and process checksum */
-   for (i = 0; i < response.data_len; i++) {
-   msg->data[i] =
-   inb(EC_LPC_ADDR_HOST_PACKET + sizeof(response) + i);
-   sum += msg->data[i];
-   }
+   sum += cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_PACKET +
+ sizeof(response), response.data_len,
+ msg->data);
 
if (sum) {
dev_err(ec->dev,
@@ -121,8 +119,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
struct cros_ec_command *msg)
 {
struct ec_lpc_host_args args;
-   int csum;
-   int i;
+   u8 sum;
int ret = 0;
 
if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE ||
@@ -139,24 +136,20 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
args.data_size = msg->outsize;
 
/* Initialize checksum */
-  

[PATCH v2 1/2] platform/chrome: cros_ec_lpc: Add R/W helpers to LPC protocol variants

2016-12-02 Thread Thierry Escande
From: Shawn Nematbakhsh 

Call common functions for read / write to prepare support for future
LPC protocol variants which use different I/O ops than inb / outb.

Signed-off-by: Shawn Nematbakhsh 
Signed-off-by: Thierry Escande 
---
 drivers/platform/chrome/Makefile  |  3 +-
 drivers/platform/chrome/cros_ec_lpc.c | 88 +--
 drivers/platform/chrome/cros_ec_lpc_reg.c | 64 ++
 include/linux/mfd/cros_ec_lpc_reg.h   | 47 +
 4 files changed, 151 insertions(+), 51 deletions(-)
 create mode 100644 drivers/platform/chrome/cros_ec_lpc_reg.c
 create mode 100644 include/linux/mfd/cros_ec_lpc_reg.h

diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
index 4f34627..127fbe8 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_CHROMEOS_PSTORE)   += chromeos_pstore.o
 cros_ec_devs-objs  := cros_ec_dev.o cros_ec_sysfs.o \
   cros_ec_lightbar.o cros_ec_vbc.o
 obj-$(CONFIG_CROS_EC_CHARDEV)  += cros_ec_devs.o
-obj-$(CONFIG_CROS_EC_LPC)  += cros_ec_lpc.o
+cros_ec_lpcs-objs  := cros_ec_lpc.o cros_ec_lpc_reg.o
+obj-$(CONFIG_CROS_EC_LPC)  += cros_ec_lpcs.o
 obj-$(CONFIG_CROS_EC_PROTO)+= cros_ec_proto.o
 obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT)   += cros_kbd_led_backlight.o
diff --git a/drivers/platform/chrome/cros_ec_lpc.c 
b/drivers/platform/chrome/cros_ec_lpc.c
index f9a2454..6a782a6 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -26,19 +26,22 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
-#define DRV_NAME "cros_ec_lpc"
+#define DRV_NAME "cros_ec_lpcs"
 
 static int ec_response_timed_out(void)
 {
unsigned long one_second = jiffies + HZ;
+   u8 data;
 
usleep_range(200, 300);
do {
-   if (!(inb(EC_LPC_ADDR_HOST_CMD) & EC_LPC_STATUS_BUSY_MASK))
+   if (!(cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_CMD, 1, ) &
+   EC_LPC_STATUS_BUSY_MASK))
return 0;
usleep_range(100, 200);
} while (time_before(jiffies, one_second));
@@ -51,21 +54,20 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
 {
struct ec_host_request *request;
struct ec_host_response response;
-   u8 sum = 0;
-   int i;
+   u8 sum;
int ret = 0;
u8 *dout;
 
ret = cros_ec_prepare_tx(ec, msg);
 
/* Write buffer */
-   for (i = 0; i < ret; i++)
-   outb(ec->dout[i], EC_LPC_ADDR_HOST_PACKET + i);
+   cros_ec_lpc_write_bytes(EC_LPC_ADDR_HOST_PACKET, ret, ec->dout);
 
request = (struct ec_host_request *)ec->dout;
 
/* Here we go */
-   outb(EC_COMMAND_PROTOCOL_3, EC_LPC_ADDR_HOST_CMD);
+   sum = EC_COMMAND_PROTOCOL_3;
+   cros_ec_lpc_write_bytes(EC_LPC_ADDR_HOST_CMD, 1, );
 
if (ec_response_timed_out()) {
dev_warn(ec->dev, "EC responsed timed out\n");
@@ -74,17 +76,15 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
}
 
/* Check result */
-   msg->result = inb(EC_LPC_ADDR_HOST_DATA);
+   msg->result = cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_DATA, 1, );
ret = cros_ec_check_result(ec, msg);
if (ret)
goto done;
 
/* Read back response */
dout = (u8 *)
-   for (i = 0; i < sizeof(response); i++) {
-   dout[i] = inb(EC_LPC_ADDR_HOST_PACKET + i);
-   sum += dout[i];
-   }
+   sum = cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_PACKET, sizeof(response),
+dout);
 
msg->result = response.result;
 
@@ -97,11 +97,9 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
}
 
/* Read response and process checksum */
-   for (i = 0; i < response.data_len; i++) {
-   msg->data[i] =
-   inb(EC_LPC_ADDR_HOST_PACKET + sizeof(response) + i);
-   sum += msg->data[i];
-   }
+   sum += cros_ec_lpc_read_bytes(EC_LPC_ADDR_HOST_PACKET +
+ sizeof(response), response.data_len,
+ msg->data);
 
if (sum) {
dev_err(ec->dev,
@@ -121,8 +119,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
struct cros_ec_command *msg)
 {
struct ec_lpc_host_args args;
-   int csum;
-   int i;
+   u8 sum;
int ret = 0;
 
if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE ||
@@ -139,24 +136,20 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
args.data_size = msg->outsize;
 
/* Initialize checksum */
-   csum = msg->command + args.flags +
-   args.command_version