From: Prashant Malani <pmalani@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: bleung@chromium.org, Prashant Malani <pmalani@chromium.org>,
Stephen Boyd <swboyd@chromium.org>,
chrome-platform@lists.linux.dev (open list:CHROME HARDWARE
PLATFORM SUPPORT), Daisuke Nojiri <dnojiri@chromium.org>,
Enric Balletbo i Serra <enric.balletbo@collabora.com>,
Guenter Roeck <groeck@chromium.org>,
Lee Jones <lee.jones@linaro.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Tzung-Bi Shih <tzungbi@kernel.org>
Subject: [PATCH 1/3] regulator: cros-ec: Use common cros_ec_command()
Date: Mon, 6 Jun 2022 20:18:01 +0000 [thread overview]
Message-ID: <20220606201825.763788-2-pmalani@chromium.org> (raw)
In-Reply-To: <20220606201825.763788-1-pmalani@chromium.org>
Reduce code duplication by using the common cros_ec_command() function
instead of the locally defined variant.
Cc: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
drivers/regulator/cros-ec-regulator.c | 54 ++++++---------------------
1 file changed, 12 insertions(+), 42 deletions(-)
diff --git a/drivers/regulator/cros-ec-regulator.c b/drivers/regulator/cros-ec-regulator.c
index c4754f3cf233..1c5fc74a4776 100644
--- a/drivers/regulator/cros-ec-regulator.c
+++ b/drivers/regulator/cros-ec-regulator.c
@@ -22,36 +22,6 @@ struct cros_ec_regulator_data {
u16 num_voltages;
};
-static int cros_ec_cmd(struct cros_ec_device *ec, u32 version, u32 command,
- void *outdata, u32 outsize, void *indata, u32 insize)
-{
- struct cros_ec_command *msg;
- int ret;
-
- msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
-
- msg->version = version;
- msg->command = command;
- msg->outsize = outsize;
- msg->insize = insize;
-
- if (outdata && outsize > 0)
- memcpy(msg->data, outdata, outsize);
-
- ret = cros_ec_cmd_xfer_status(ec, msg);
- if (ret < 0)
- goto cleanup;
-
- if (insize)
- memcpy(indata, msg->data, insize);
-
-cleanup:
- kfree(msg);
- return ret;
-}
-
static int cros_ec_regulator_enable(struct regulator_dev *dev)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
@@ -60,8 +30,8 @@ static int cros_ec_regulator_enable(struct regulator_dev *dev)
.enable = 1,
};
- return cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_ENABLE, &cmd,
- sizeof(cmd), NULL, 0);
+ return cros_ec_command(data->ec_dev, 0, EC_CMD_REGULATOR_ENABLE, &cmd,
+ sizeof(cmd), NULL, 0);
}
static int cros_ec_regulator_disable(struct regulator_dev *dev)
@@ -72,8 +42,8 @@ static int cros_ec_regulator_disable(struct regulator_dev *dev)
.enable = 0,
};
- return cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_ENABLE, &cmd,
- sizeof(cmd), NULL, 0);
+ return cros_ec_command(data->ec_dev, 0, EC_CMD_REGULATOR_ENABLE, &cmd,
+ sizeof(cmd), NULL, 0);
}
static int cros_ec_regulator_is_enabled(struct regulator_dev *dev)
@@ -85,8 +55,8 @@ static int cros_ec_regulator_is_enabled(struct regulator_dev *dev)
struct ec_response_regulator_is_enabled resp;
int ret;
- ret = cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_IS_ENABLED, &cmd,
- sizeof(cmd), &resp, sizeof(resp));
+ ret = cros_ec_command(data->ec_dev, 0, EC_CMD_REGULATOR_IS_ENABLED, &cmd,
+ sizeof(cmd), &resp, sizeof(resp));
if (ret < 0)
return ret;
return resp.enabled;
@@ -112,8 +82,8 @@ static int cros_ec_regulator_get_voltage(struct regulator_dev *dev)
struct ec_response_regulator_get_voltage resp;
int ret;
- ret = cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_GET_VOLTAGE, &cmd,
- sizeof(cmd), &resp, sizeof(resp));
+ ret = cros_ec_command(data->ec_dev, 0, EC_CMD_REGULATOR_GET_VOLTAGE, &cmd,
+ sizeof(cmd), &resp, sizeof(resp));
if (ret < 0)
return ret;
return resp.voltage_mv * 1000;
@@ -138,8 +108,8 @@ static int cros_ec_regulator_set_voltage(struct regulator_dev *dev, int min_uV,
if (min_mV > max_mV)
return -EINVAL;
- return cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_SET_VOLTAGE, &cmd,
- sizeof(cmd), NULL, 0);
+ return cros_ec_command(data->ec_dev, 0, EC_CMD_REGULATOR_SET_VOLTAGE, &cmd,
+ sizeof(cmd), NULL, 0);
}
static const struct regulator_ops cros_ec_regulator_voltage_ops = {
@@ -160,8 +130,8 @@ static int cros_ec_regulator_init_info(struct device *dev,
struct ec_response_regulator_get_info resp;
int ret;
- ret = cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_GET_INFO, &cmd,
- sizeof(cmd), &resp, sizeof(resp));
+ ret = cros_ec_command(data->ec_dev, 0, EC_CMD_REGULATOR_GET_INFO, &cmd,
+ sizeof(cmd), &resp, sizeof(resp));
if (ret < 0)
return ret;
--
2.36.1.255.ge46751e96f-goog
next prev parent reply other threads:[~2022-06-06 20:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 20:17 [PATCH 0/3] platform/chrome: cros_ec_command() improvements Prashant Malani
2022-06-06 20:18 ` Prashant Malani [this message]
2022-06-06 23:31 ` [PATCH 1/3] regulator: cros-ec: Use common cros_ec_command() Stephen Boyd
2022-06-07 14:37 ` Guenter Roeck
2022-06-07 15:31 ` Mark Brown
2022-06-06 20:18 ` [PATCH 2/3] platform/chrome: cros_ec_proto: Rename cros_ec_command function Prashant Malani
2022-06-06 23:32 ` Stephen Boyd
2022-06-07 14:38 ` Guenter Roeck
2022-06-08 7:44 ` Lee Jones
2022-06-06 20:18 ` [PATCH 3/3] platform/chrome: cros_ec_proto: Update size arg types Prashant Malani
2022-06-06 23:34 ` Stephen Boyd
2022-06-07 14:41 ` Guenter Roeck
2022-06-08 8:20 ` [PATCH 0/3] platform/chrome: cros_ec_command() improvements patchwork-bot+chrome-platform
2022-06-10 2:30 ` patchwork-bot+chrome-platform
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220606201825.763788-2-pmalani@chromium.org \
--to=pmalani@chromium.org \
--cc=bleung@chromium.org \
--cc=broonie@kernel.org \
--cc=chrome-platform@lists.linux.dev \
--cc=dnojiri@chromium.org \
--cc=enric.balletbo@collabora.com \
--cc=groeck@chromium.org \
--cc=lee.jones@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=swboyd@chromium.org \
--cc=tzungbi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®