aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Bresticker <abrestic@chromium.org>2014-09-18 11:18:56 -0400
committerLee Jones <lee.jones@linaro.org>2014-10-06 16:29:07 -0400
commita6551a76fff15056fde2342d0f7de41ee605264e (patch)
tree94ff2a687fc6c8d7ef55a741b2d7db2634eb508d
parent659e142be09482cfd8b9017f616afebc7cf48fa3 (diff)
mfd: cros_ec: stop calling ->cmd_xfer() directly
Instead of having users of the ChromeOS EC call the interface-specific cmd_xfer() callback directly, introduce a central cros_ec_cmd_xfer() to use instead. This will allow us to put all the locking and retry logic in one place instead of duplicating it across the different drivers. Signed-off-by: Andrew Bresticker <abrestic@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk> Reviewed-by: Doug Anderson <dianders@chromium.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
-rw-r--r--drivers/i2c/busses/i2c-cros-ec-tunnel.c2
-rw-r--r--drivers/input/keyboard/cros_ec_keyb.c2
-rw-r--r--drivers/mfd/cros_ec.c7
-rw-r--r--include/linux/mfd/cros_ec.h24
4 files changed, 27 insertions, 8 deletions
diff --git a/drivers/i2c/busses/i2c-cros-ec-tunnel.c b/drivers/i2c/busses/i2c-cros-ec-tunnel.c
index 05e033c98115..43be23dfb115 100644
--- a/drivers/i2c/busses/i2c-cros-ec-tunnel.c
+++ b/drivers/i2c/busses/i2c-cros-ec-tunnel.c
@@ -227,7 +227,7 @@ static int ec_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg i2c_msgs[],
227 msg.indata = response; 227 msg.indata = response;
228 msg.insize = response_len; 228 msg.insize = response_len;
229 229
230 result = bus->ec->cmd_xfer(bus->ec, &msg); 230 result = cros_ec_cmd_xfer(bus->ec, &msg);
231 if (result < 0) 231 if (result < 0)
232 goto exit; 232 goto exit;
233 233
diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index 791781ade4e7..93111d1aa617 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -182,7 +182,7 @@ static int cros_ec_keyb_get_state(struct cros_ec_keyb *ckdev, uint8_t *kb_state)
182 .insize = ckdev->cols, 182 .insize = ckdev->cols,
183 }; 183 };
184 184
185 return ckdev->ec->cmd_xfer(ckdev->ec, &msg); 185 return cros_ec_cmd_xfer(ckdev->ec, &msg);
186} 186}
187 187
188static irqreturn_t cros_ec_keyb_irq(int irq, void *data) 188static irqreturn_t cros_ec_keyb_irq(int irq, void *data)
diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index 4873f9c50452..a9faebdcfa14 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -62,6 +62,13 @@ int cros_ec_check_result(struct cros_ec_device *ec_dev,
62} 62}
63EXPORT_SYMBOL(cros_ec_check_result); 63EXPORT_SYMBOL(cros_ec_check_result);
64 64
65int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
66 struct cros_ec_command *msg)
67{
68 return ec_dev->cmd_xfer(ec_dev, msg);
69}
70EXPORT_SYMBOL(cros_ec_cmd_xfer);
71
65static const struct mfd_cell cros_devs[] = { 72static const struct mfd_cell cros_devs[] = {
66 { 73 {
67 .name = "cros-ec-keyb", 74 .name = "cros-ec-keyb",
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index fcbe9d129a9d..0e166b92f5b4 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -62,10 +62,6 @@ struct cros_ec_command {
62 * @dev: Device pointer 62 * @dev: Device pointer
63 * @was_wake_device: true if this device was set to wake the system from 63 * @was_wake_device: true if this device was set to wake the system from
64 * sleep at the last suspend 64 * sleep at the last suspend
65 * @cmd_xfer: send command to EC and get response
66 * Returns the number of bytes received if the communication succeeded, but
67 * that doesn't mean the EC was happy with the command. The caller
68 * should check msg.result for the EC's result code.
69 * 65 *
70 * @priv: Private data 66 * @priv: Private data
71 * @irq: Interrupt to use 67 * @irq: Interrupt to use
@@ -82,6 +78,10 @@ struct cros_ec_command {
82 * @dout_size: size of dout buffer to allocate (zero to use static dout) 78 * @dout_size: size of dout buffer to allocate (zero to use static dout)
83 * @parent: pointer to parent device (e.g. i2c or spi device) 79 * @parent: pointer to parent device (e.g. i2c or spi device)
84 * @wake_enabled: true if this device can wake the system from sleep 80 * @wake_enabled: true if this device can wake the system from sleep
81 * @cmd_xfer: send command to EC and get response
82 * Returns the number of bytes received if the communication succeeded, but
83 * that doesn't mean the EC was happy with the command. The caller
84 * should check msg.result for the EC's result code.
85 * @lock: one transaction at a time 85 * @lock: one transaction at a time
86 */ 86 */
87struct cros_ec_device { 87struct cros_ec_device {
@@ -92,8 +92,6 @@ struct cros_ec_device {
92 struct device *dev; 92 struct device *dev;
93 bool was_wake_device; 93 bool was_wake_device;
94 struct class *cros_class; 94 struct class *cros_class;
95 int (*cmd_xfer)(struct cros_ec_device *ec,
96 struct cros_ec_command *msg);
97 95
98 /* These are used to implement the platform-specific interface */ 96 /* These are used to implement the platform-specific interface */
99 void *priv; 97 void *priv;
@@ -104,6 +102,8 @@ struct cros_ec_device {
104 int dout_size; 102 int dout_size;
105 struct device *parent; 103 struct device *parent;
106 bool wake_enabled; 104 bool wake_enabled;
105 int (*cmd_xfer)(struct cros_ec_device *ec,
106 struct cros_ec_command *msg);
107 struct mutex lock; 107 struct mutex lock;
108}; 108};
109 109
@@ -153,6 +153,18 @@ int cros_ec_check_result(struct cros_ec_device *ec_dev,
153 struct cros_ec_command *msg); 153 struct cros_ec_command *msg);
154 154
155/** 155/**
156 * cros_ec_cmd_xfer - Send a command to the ChromeOS EC
157 *
158 * Call this to send a command to the ChromeOS EC. This should be used
159 * instead of calling the EC's cmd_xfer() callback directly.
160 *
161 * @ec_dev: EC device
162 * @msg: Message to write
163 */
164int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
165 struct cros_ec_command *msg);
166
167/**
156 * cros_ec_remove - Remove a ChromeOS EC 168 * cros_ec_remove - Remove a ChromeOS EC
157 * 169 *
158 * Call this to deregister a ChromeOS EC, then clean up any private data. 170 * Call this to deregister a ChromeOS EC, then clean up any private data.