Commit 7a475eb4 authored by Qiang Yu's avatar Qiang Yu

drm/lima: separate clk/regulator enable/disable function

For being used by both device init/fini and suspend/resume.
Tested-by: default avatarBhushan Shah <bshah@kde.org>
Reviewed-by: default avatarVasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: default avatarQiang Yu <yuq825@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200421133551.31481-9-yuq825@gmail.com
parent 3446d7e9
...@@ -81,26 +81,10 @@ const char *lima_ip_name(struct lima_ip *ip) ...@@ -81,26 +81,10 @@ const char *lima_ip_name(struct lima_ip *ip)
return lima_ip_desc[ip->id].name; return lima_ip_desc[ip->id].name;
} }
static int lima_clk_init(struct lima_device *dev) static int lima_clk_enable(struct lima_device *dev)
{ {
int err; int err;
dev->clk_bus = devm_clk_get(dev->dev, "bus");
if (IS_ERR(dev->clk_bus)) {
err = PTR_ERR(dev->clk_bus);
if (err != -EPROBE_DEFER)
dev_err(dev->dev, "get bus clk failed %d\n", err);
return err;
}
dev->clk_gpu = devm_clk_get(dev->dev, "core");
if (IS_ERR(dev->clk_gpu)) {
err = PTR_ERR(dev->clk_gpu);
if (err != -EPROBE_DEFER)
dev_err(dev->dev, "get core clk failed %d\n", err);
return err;
}
err = clk_prepare_enable(dev->clk_bus); err = clk_prepare_enable(dev->clk_bus);
if (err) if (err)
return err; return err;
...@@ -109,15 +93,7 @@ static int lima_clk_init(struct lima_device *dev) ...@@ -109,15 +93,7 @@ static int lima_clk_init(struct lima_device *dev)
if (err) if (err)
goto error_out0; goto error_out0;
dev->reset = devm_reset_control_array_get_optional_shared(dev->dev); if (dev->reset) {
if (IS_ERR(dev->reset)) {
err = PTR_ERR(dev->reset);
if (err != -EPROBE_DEFER)
dev_err(dev->dev, "get reset controller failed %d\n",
err);
goto error_out1;
} else if (dev->reset != NULL) {
err = reset_control_deassert(dev->reset); err = reset_control_deassert(dev->reset);
if (err) { if (err) {
dev_err(dev->dev, dev_err(dev->dev,
...@@ -135,14 +111,76 @@ static int lima_clk_init(struct lima_device *dev) ...@@ -135,14 +111,76 @@ static int lima_clk_init(struct lima_device *dev)
return err; return err;
} }
static void lima_clk_fini(struct lima_device *dev) static void lima_clk_disable(struct lima_device *dev)
{ {
if (dev->reset != NULL) if (dev->reset)
reset_control_assert(dev->reset); reset_control_assert(dev->reset);
clk_disable_unprepare(dev->clk_gpu); clk_disable_unprepare(dev->clk_gpu);
clk_disable_unprepare(dev->clk_bus); clk_disable_unprepare(dev->clk_bus);
} }
static int lima_clk_init(struct lima_device *dev)
{
int err;
dev->clk_bus = devm_clk_get(dev->dev, "bus");
if (IS_ERR(dev->clk_bus)) {
err = PTR_ERR(dev->clk_bus);
if (err != -EPROBE_DEFER)
dev_err(dev->dev, "get bus clk failed %d\n", err);
dev->clk_bus = NULL;
return err;
}
dev->clk_gpu = devm_clk_get(dev->dev, "core");
if (IS_ERR(dev->clk_gpu)) {
err = PTR_ERR(dev->clk_gpu);
if (err != -EPROBE_DEFER)
dev_err(dev->dev, "get core clk failed %d\n", err);
dev->clk_gpu = NULL;
return err;
}
dev->reset = devm_reset_control_array_get_optional_shared(dev->dev);
if (IS_ERR(dev->reset)) {
err = PTR_ERR(dev->reset);
if (err != -EPROBE_DEFER)
dev_err(dev->dev, "get reset controller failed %d\n",
err);
dev->reset = NULL;
return err;
}
return lima_clk_enable(dev);
}
static void lima_clk_fini(struct lima_device *dev)
{
lima_clk_disable(dev);
}
static int lima_regulator_enable(struct lima_device *dev)
{
int ret;
if (!dev->regulator)
return 0;
ret = regulator_enable(dev->regulator);
if (ret < 0) {
dev_err(dev->dev, "failed to enable regulator: %d\n", ret);
return ret;
}
return 0;
}
static void lima_regulator_disable(struct lima_device *dev)
{
if (dev->regulator)
regulator_disable(dev->regulator);
}
static int lima_regulator_init(struct lima_device *dev) static int lima_regulator_init(struct lima_device *dev)
{ {
int ret; int ret;
...@@ -158,19 +196,12 @@ static int lima_regulator_init(struct lima_device *dev) ...@@ -158,19 +196,12 @@ static int lima_regulator_init(struct lima_device *dev)
return ret; return ret;
} }
ret = regulator_enable(dev->regulator); return lima_regulator_enable(dev);
if (ret < 0) {
dev_err(dev->dev, "failed to enable regulator: %d\n", ret);
return ret;
}
return 0;
} }
static void lima_regulator_fini(struct lima_device *dev) static void lima_regulator_fini(struct lima_device *dev)
{ {
if (dev->regulator) lima_regulator_disable(dev);
regulator_disable(dev->regulator);
} }
static int lima_init_ip(struct lima_device *dev, int index) static int lima_init_ip(struct lima_device *dev, int index)
......
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