Commit 10d0d397 authored by Alex Elder's avatar Alex Elder Committed by Jakub Kicinski

net: ipa: clean up interconnect initialization

Pass an the address of an IPA interconnect structure and its
configuration data to ipa_interconnect_init_one() and have that
function initialize all the structure's fields.  Change the function
to simply return an error code.

Introduce ipa_interconnect_exit_one() to encapsulate the cleanup of
an IPA interconnect structure.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e938d7ef
...@@ -56,17 +56,33 @@ struct ipa_clock { ...@@ -56,17 +56,33 @@ struct ipa_clock {
struct ipa_interconnect interconnect[IPA_INTERCONNECT_COUNT]; struct ipa_interconnect interconnect[IPA_INTERCONNECT_COUNT];
}; };
static struct icc_path * static int ipa_interconnect_init_one(struct device *dev,
ipa_interconnect_init_one(struct device *dev, const char *name) struct ipa_interconnect *interconnect,
const struct ipa_interconnect_data *data)
{ {
struct icc_path *path; struct icc_path *path;
path = of_icc_get(dev, name); path = of_icc_get(dev, data->name);
if (IS_ERR(path)) if (IS_ERR(path)) {
dev_err(dev, "error %d getting %s interconnect\n", int ret = PTR_ERR(path);
(int)PTR_ERR(path), name);
return path; dev_err(dev, "error %d getting %s interconnect\n", ret,
data->name);
return ret;
}
interconnect->path = path;
interconnect->average_bandwidth = data->average_bandwidth;
interconnect->peak_bandwidth = data->peak_bandwidth;
return 0;
}
static void ipa_interconnect_exit_one(struct ipa_interconnect *interconnect)
{
icc_put(interconnect->path);
memset(interconnect, 0, sizeof(*interconnect));
} }
/* Initialize interconnects required for IPA operation */ /* Initialize interconnects required for IPA operation */
...@@ -74,51 +90,46 @@ static int ipa_interconnect_init(struct ipa_clock *clock, struct device *dev, ...@@ -74,51 +90,46 @@ static int ipa_interconnect_init(struct ipa_clock *clock, struct device *dev,
const struct ipa_interconnect_data *data) const struct ipa_interconnect_data *data)
{ {
struct ipa_interconnect *interconnect; struct ipa_interconnect *interconnect;
struct icc_path *path; int ret;
path = ipa_interconnect_init_one(dev, data->name);
if (IS_ERR(path))
goto err_return;
interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY]; interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY];
interconnect->path = path; ret = ipa_interconnect_init_one(dev, interconnect, data++);
interconnect->average_bandwidth = data->average_bandwidth; if (ret)
interconnect->peak_bandwidth = data->peak_bandwidth; return ret;
data++;
path = ipa_interconnect_init_one(dev, data->name);
if (IS_ERR(path))
goto err_memory_path_put;
interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM]; interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM];
interconnect->path = path; ret = ipa_interconnect_init_one(dev, interconnect, data++);
interconnect->average_bandwidth = data->average_bandwidth; if (ret)
interconnect->peak_bandwidth = data->peak_bandwidth; goto err_memory_path_put;
data++;
path = ipa_interconnect_init_one(dev, data->name); interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM];
if (IS_ERR(path)) ret = ipa_interconnect_init_one(dev, interconnect, data++);
if (ret)
goto err_imem_path_put; goto err_imem_path_put;
interconnect = &clock->interconnect[IPA_INTERCONNECT_CONFIG];
interconnect->path = path;
interconnect->average_bandwidth = data->average_bandwidth;
interconnect->peak_bandwidth = data->peak_bandwidth;
data++;
return 0; return 0;
err_imem_path_put: err_imem_path_put:
icc_put(clock->interconnect[IPA_INTERCONNECT_IMEM].path); interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM];
ipa_interconnect_exit_one(interconnect);
err_memory_path_put: err_memory_path_put:
icc_put(clock->interconnect[IPA_INTERCONNECT_MEMORY].path); interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY];
err_return: ipa_interconnect_exit_one(interconnect);
return PTR_ERR(path);
return ret;
} }
/* Inverse of ipa_interconnect_init() */ /* Inverse of ipa_interconnect_init() */
static void ipa_interconnect_exit(struct ipa_clock *clock) static void ipa_interconnect_exit(struct ipa_clock *clock)
{ {
icc_put(clock->interconnect[IPA_INTERCONNECT_CONFIG].path); struct ipa_interconnect *interconnect;
icc_put(clock->interconnect[IPA_INTERCONNECT_IMEM].path);
icc_put(clock->interconnect[IPA_INTERCONNECT_MEMORY].path); interconnect = &clock->interconnect[IPA_INTERCONNECT_CONFIG];
ipa_interconnect_exit_one(interconnect);
interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM];
ipa_interconnect_exit_one(interconnect);
interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY];
ipa_interconnect_exit_one(interconnect);
} }
/* Currently we only use one bandwidth level, so just "enable" interconnects */ /* Currently we only use one bandwidth level, so just "enable" interconnects */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment