video: rockchip: mpp: Extract mpp_dev_shutdown for device shutdown

All device have similar function for device shutdown, thus,
extract it for common function.

Change-Id: I365cc10759559c7d7e824a6e4c93df24198d82f9
Signed-off-by: Ding Wei <leo.ding@rock-chips.com>
This commit is contained in:
Ding Wei
2022-01-25 19:58:35 +08:00
committed by Tao Huang
parent c50772fd65
commit 5b7bc45350
12 changed files with 87 additions and 237 deletions

View File

@@ -403,7 +403,7 @@ void mpp_free_task(struct kref *ref)
session->index, task->task_index, task->state,
atomic_read(&task->abort_request));
mpp = mpp_get_task_used_device(task, session);
mpp = session->mpp;
if (!mpp) {
mpp_err("task %d:%d mpp is null.\n",
session->index, task->task_index);
@@ -789,7 +789,6 @@ static int mpp_attach_service(struct mpp_dev *mpp, struct device *dev)
goto err_put_pdev;
}
mpp->pdev_srv = pdev;
mpp->srv = platform_get_drvdata(pdev);
if (!mpp->srv) {
dev_err(&pdev->dev, "failed attach service\n");
@@ -1864,7 +1863,7 @@ int mpp_dev_remove(struct mpp_dev *mpp)
mpp->hw_ops->exit(mpp);
mpp_iommu_remove(mpp->iommu_info);
platform_device_put(mpp->pdev_srv);
platform_device_put(to_platform_device(mpp->dev));
mpp_detach_workqueue(mpp);
device_init_wakeup(mpp->dev, false);
pm_runtime_disable(mpp->dev);
@@ -1872,6 +1871,26 @@ int mpp_dev_remove(struct mpp_dev *mpp)
return 0;
}
void mpp_dev_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total %d running time out\n",
atomic_read(&mpp->task_count));
else
dev_info(dev, "shutdown success\n");
}
int mpp_dev_register_srv(struct mpp_dev *mpp, struct mpp_service *srv)
{
enum MPP_DEVICE_TYPE device_type = mpp->var->device_type;

View File

@@ -22,6 +22,7 @@
#include <linux/reset.h>
#include <linux/irqreturn.h>
#include <linux/poll.h>
#include <linux/platform_device.h>
#include <soc/rockchip/pm_domains.h>
#define MHZ (1000 * 1000)
@@ -321,7 +322,6 @@ struct mpp_dev {
struct mpp_taskqueue *queue;
struct mpp_reset_group *reset_group;
/* point to MPP Service */
struct platform_device *pdev_srv;
struct mpp_service *srv;
/* multi-core data */
@@ -606,6 +606,7 @@ int mpp_session_deinit(struct mpp_session *session);
int mpp_dev_probe(struct mpp_dev *mpp,
struct platform_device *pdev);
int mpp_dev_remove(struct mpp_dev *mpp);
void mpp_dev_shutdown(struct platform_device *pdev);
int mpp_dev_register_srv(struct mpp_dev *mpp, struct mpp_service *srv);
int mpp_power_on(struct mpp_dev *mpp);

View File

@@ -941,7 +941,7 @@ static int iep2_probe(struct platform_device *pdev)
return -ENOMEM;
mpp = &iep->mpp;
platform_set_drvdata(pdev, iep);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_iep2_match, pdev->dev.of_node);
@@ -977,39 +977,22 @@ static int iep2_probe(struct platform_device *pdev)
static int iep2_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct iep2_dev *iep = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
struct iep2_dev *iep = to_iep2_dev(mpp);
dma_free_coherent(dev, iep->roi.size, iep->roi.vaddr, iep->roi.iova);
dev_info(dev, "remove device\n");
mpp_dev_remove(&iep->mpp);
iep2_procfs_remove(&iep->mpp);
mpp_dev_remove(mpp);
iep2_procfs_remove(mpp);
return 0;
}
static void iep2_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct iep2_dev *iep = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &iep->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
struct platform_driver rockchip_iep2_driver = {
.probe = iep2_probe,
.remove = iep2_remove,
.shutdown = iep2_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = IEP2_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_iep2_match),

View File

@@ -572,9 +572,9 @@ static int jpgdec_probe(struct platform_device *pdev)
dec = devm_kzalloc(dev, sizeof(struct jpgdec_dev), GFP_KERNEL);
if (!dec)
return -ENOMEM;
platform_set_drvdata(pdev, dec);
mpp = &dec->mpp;
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_jpgdec_dt_match, pdev->dev.of_node);
if (match)
@@ -609,37 +609,19 @@ static int jpgdec_probe(struct platform_device *pdev)
static int jpgdec_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct jpgdec_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "remove device\n");
mpp_dev_remove(&dec->mpp);
jpgdec_procfs_remove(&dec->mpp);
mpp_dev_remove(mpp);
jpgdec_procfs_remove(mpp);
return 0;
}
static void jpgdec_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct jpgdec_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &dec->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
struct platform_driver rockchip_jpgdec_driver = {
.probe = jpgdec_probe,
.remove = jpgdec_remove,
.shutdown = jpgdec_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = JPGDEC_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_jpgdec_dt_match),

View File

@@ -1873,7 +1873,7 @@ static int rkvdec_probe(struct platform_device *pdev)
return -ENOMEM;
mpp = &dec->mpp;
platform_set_drvdata(pdev, dec);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_rkvdec_dt_match,
@@ -1919,28 +1919,10 @@ static int rkvdec_remove(struct platform_device *pdev)
return 0;
}
static void rkvdec_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct rkvdec_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &dec->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
struct platform_driver rockchip_rkvdec_driver = {
.probe = rkvdec_probe,
.remove = rkvdec_remove,
.shutdown = rkvdec_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = RKVDEC_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_rkvdec_dt_match),

View File

@@ -1077,7 +1077,7 @@ static int rkvdec2_core_probe(struct platform_device *pdev)
return -ENOMEM;
mpp = &dec->mpp;
platform_set_drvdata(pdev, dec);
platform_set_drvdata(pdev, mpp);
if (dev->of_node) {
struct device_node *np = pdev->dev.of_node;
@@ -1141,7 +1141,7 @@ static int rkvdec2_probe_default(struct platform_device *pdev)
return -ENOMEM;
mpp = &dec->mpp;
platform_set_drvdata(pdev, dec);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_rkvdec2_dt_match, pdev->dev.of_node);
@@ -1231,14 +1231,15 @@ static int rkvdec2_remove(struct platform_device *pdev)
dev_info(dev, "remove ccu device\n");
rkvdec2_ccu_remove(dev);
} else {
struct rkvdec2_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
struct rkvdec2_dev *dec = to_rkvdec2_dev(mpp);
dev_info(dev, "remove device\n");
rkvdec2_free_rcbbuf(pdev, dec);
mpp_dev_remove(&dec->mpp);
rkvdec2_procfs_remove(&dec->mpp);
rkvdec2_link_remove(&dec->mpp, dec->link_dec);
mpp_dev_remove(mpp);
rkvdec2_procfs_remove(mpp);
rkvdec2_link_remove(mpp, dec->link_dec);
}
return 0;
@@ -1248,21 +1249,8 @@ static void rkvdec2_shutdown(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
if (!strstr(dev_name(dev), "ccu")) {
int ret;
int val;
struct rkvdec2_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &dec->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
if (!strstr(dev_name(dev), "ccu"))
mpp_dev_shutdown(pdev);
}
struct platform_driver rockchip_rkvdec2_driver = {

View File

@@ -1433,7 +1433,7 @@ static int rkvenc_probe(struct platform_device *pdev)
if (!enc)
return -ENOMEM;
mpp = &enc->mpp;
platform_set_drvdata(pdev, enc);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_rkvenc_dt_match, pdev->dev.of_node);
@@ -1472,39 +1472,19 @@ failed_get_irq:
static int rkvenc_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct rkvenc_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "remove device\n");
mpp_dev_remove(&enc->mpp);
rkvenc_procfs_remove(&enc->mpp);
mpp_dev_remove(mpp);
rkvenc_procfs_remove(mpp);
return 0;
}
static void rkvenc_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct rkvenc_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &enc->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 1000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
dev_info(dev, "shutdown success\n");
}
struct platform_driver rockchip_rkvenc_driver = {
.probe = rkvenc_probe,
.remove = rkvenc_remove,
.shutdown = rkvenc_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = RKVENC_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_rkvenc_dt_match),

View File

@@ -1511,7 +1511,7 @@ static int rkvenc_core_probe(struct platform_device *pdev)
return -ENOMEM;
mpp = &enc->mpp;
platform_set_drvdata(pdev, enc);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
struct device_node *np = pdev->dev.of_node;
@@ -1571,7 +1571,7 @@ static int rkvenc_probe_default(struct platform_device *pdev)
return -ENOMEM;
mpp = &enc->mpp;
platform_set_drvdata(pdev, enc);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_rkvenc_dt_match, pdev->dev.of_node);
@@ -1652,7 +1652,8 @@ static int rkvenc_remove(struct platform_device *pdev)
if (strstr(np->name, "ccu")) {
dev_info(dev, "remove ccu\n");
} else if (strstr(np->name, "core")) {
struct rkvenc_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
struct rkvenc_dev *enc = to_rkvenc_dev(mpp);
dev_info(dev, "remove core\n");
if (enc->ccu) {
@@ -1665,12 +1666,13 @@ static int rkvenc_remove(struct platform_device *pdev)
mpp_dev_remove(&enc->mpp);
rkvenc_procfs_remove(&enc->mpp);
} else {
struct rkvenc_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
struct rkvenc_dev *enc = to_rkvenc_dev(mpp);
dev_info(dev, "remove device\n");
rkvenc2_free_rcbbuf(pdev, enc);
mpp_dev_remove(&enc->mpp);
rkvenc_procfs_remove(&enc->mpp);
mpp_dev_remove(mpp);
rkvenc_procfs_remove(mpp);
}
return 0;
@@ -1680,25 +1682,8 @@ static void rkvenc_shutdown(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
if (!strstr(dev_name(dev), "ccu")) {
int ret;
int val;
struct rkvenc_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &enc->mpp;
dev_info(dev, "shutdown device\n");
if (mpp->srv)
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 1000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
dev_info(dev, "shutdown success\n");
if (!strstr(dev_name(dev), "ccu"))
mpp_dev_shutdown(pdev);
}
struct platform_driver rockchip_rkvenc2_driver = {

View File

@@ -795,9 +795,9 @@ static int vdpu_probe(struct platform_device *pdev)
dec = devm_kzalloc(dev, sizeof(struct vdpu_dev), GFP_KERNEL);
if (!dec)
return -ENOMEM;
platform_set_drvdata(pdev, dec);
mpp = &dec->mpp;
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_vdpu1_dt_match, pdev->dev.of_node);
if (match)
@@ -837,37 +837,19 @@ static int vdpu_probe(struct platform_device *pdev)
static int vdpu_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct vdpu_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "remove device\n");
mpp_dev_remove(&dec->mpp);
vdpu_procfs_remove(&dec->mpp);
mpp_dev_remove(mpp);
vdpu_procfs_remove(mpp);
return 0;
}
static void vdpu_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct vdpu_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &dec->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
struct platform_driver rockchip_vdpu1_driver = {
.probe = vdpu_probe,
.remove = vdpu_remove,
.shutdown = vdpu_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = VDPU1_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_vdpu1_dt_match),

View File

@@ -687,9 +687,8 @@ static int vdpu_probe(struct platform_device *pdev)
dec = devm_kzalloc(dev, sizeof(struct vdpu_dev), GFP_KERNEL);
if (!dec)
return -ENOMEM;
platform_set_drvdata(pdev, dec);
mpp = &dec->mpp;
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_vdpu2_dt_match,
@@ -731,37 +730,19 @@ static int vdpu_probe(struct platform_device *pdev)
static int vdpu_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct vdpu_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "remove device\n");
mpp_dev_remove(&dec->mpp);
vdpu_procfs_remove(&dec->mpp);
mpp_dev_remove(mpp);
vdpu_procfs_remove(mpp);
return 0;
}
static void vdpu_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct vdpu_dev *dec = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &dec->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
struct platform_driver rockchip_vdpu2_driver = {
.probe = vdpu_probe,
.remove = vdpu_remove,
.shutdown = vdpu_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = VDPU2_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_vdpu2_dt_match),

View File

@@ -722,7 +722,7 @@ static int vepu_probe(struct platform_device *pdev)
return -ENOMEM;
mpp = &enc->mpp;
platform_set_drvdata(pdev, enc);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_vepu1_dt_match, pdev->dev.of_node);
@@ -758,37 +758,19 @@ static int vepu_probe(struct platform_device *pdev)
static int vepu_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct vepu_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "remove device\n");
mpp_dev_remove(&enc->mpp);
vepu_procfs_remove(&enc->mpp);
mpp_dev_remove(mpp);
vepu_procfs_remove(mpp);
return 0;
}
static void vepu_shutdown(struct platform_device *pdev)
{
int ret;
int val;
struct device *dev = &pdev->dev;
struct vepu_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &enc->mpp;
dev_info(dev, "shutdown device\n");
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
struct platform_driver rockchip_vepu1_driver = {
.probe = vepu_probe,
.remove = vepu_remove,
.shutdown = vepu_shutdown,
.shutdown = mpp_dev_shutdown,
.driver = {
.name = VEPU1_DRIVER_NAME,
.of_match_table = of_match_ptr(mpp_vepu1_dt_match),

View File

@@ -994,7 +994,7 @@ static int vepu_core_probe(struct platform_device *pdev)
return -ENOMEM;
mpp = &enc->mpp;
platform_set_drvdata(pdev, enc);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_vepu2_dt_match, pdev->dev.of_node);
@@ -1047,7 +1047,7 @@ static int vepu_probe_default(struct platform_device *pdev)
return -ENOMEM;
mpp = &enc->mpp;
platform_set_drvdata(pdev, enc);
platform_set_drvdata(pdev, mpp);
if (pdev->dev.of_node) {
match = of_match_node(mpp_vepu2_dt_match, pdev->dev.of_node);
@@ -1107,7 +1107,8 @@ static int vepu_remove(struct platform_device *pdev)
if (strstr(np->name, "ccu")) {
dev_info(dev, "remove ccu device\n");
} else if (strstr(np->name, "core")) {
struct vepu_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
struct vepu_dev *enc = to_vepu_dev(mpp);
dev_info(dev, "remove core\n");
if (enc->ccu) {
@@ -1119,11 +1120,11 @@ static int vepu_remove(struct platform_device *pdev)
mpp_dev_remove(&enc->mpp);
vepu_procfs_remove(&enc->mpp);
} else {
struct vepu_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = dev_get_drvdata(dev);
dev_info(dev, "remove device\n");
mpp_dev_remove(&enc->mpp);
vepu_procfs_remove(&enc->mpp);
mpp_dev_remove(mpp);
vepu_procfs_remove(mpp);
}
return 0;
@@ -1133,24 +1134,8 @@ static void vepu_shutdown(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
if (!strstr(dev_name(dev), "ccu")) {
int ret;
int val;
struct vepu_dev *enc = platform_get_drvdata(pdev);
struct mpp_dev *mpp = &enc->mpp;
dev_info(dev, "shutdown device\n");
if (mpp->srv)
atomic_inc(&mpp->srv->shutdown_request);
ret = readx_poll_timeout(atomic_read,
&mpp->task_count,
val, val == 0, 20000, 200000);
if (ret == -ETIMEDOUT)
dev_err(dev, "wait total running time out\n");
}
dev_info(dev, "shutdown success\n");
if (!strstr(dev_name(dev), "ccu"))
mpp_dev_shutdown(pdev);
}
struct platform_driver rockchip_vepu2_driver = {