Skip to content

Commit 86698b9

Browse files
Eizan Miyamotomchehab
Eizan Miyamoto
authored andcommitted
media: mtk-mdp: convert mtk_mdp_dev.comp array to list
The functions mtk_mdp_register/unregister_component have been created to add / remove items from the list of components. This will eventually enable us to specify a list of components in the device tree instead of hardcoding them into this driver. The list is modified by a single thread at driver probe time, and will not be traversed by another thread until the call to pm_runtime_enable at the end of probing. Signed-off-by: Eizan Miyamoto <[email protected]> Reviewed-by: Enric Balletbo I Serra <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent ee18fc7 commit 86698b9

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

drivers/media/platform/mtk-mdp/mtk_mdp_comp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
103103
return -EINVAL;
104104
}
105105

106+
INIT_LIST_HEAD(&comp->node);
106107
comp->dev_node = of_node_get(node);
107108
comp->id = comp_id;
108109
comp->type = mtk_mdp_matches[comp_id].type;

drivers/media/platform/mtk-mdp/mtk_mdp_comp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ enum mtk_mdp_comp_id {
3636

3737
/**
3838
* struct mtk_mdp_comp - the MDP's function component data
39+
* @node: list node to track sibing MDP components
3940
* @dev_node: component device node
4041
* @clk: clocks required for component
4142
* @larb_dev: SMI device required for component
4243
* @type: component type
4344
* @id: component ID
4445
*/
4546
struct mtk_mdp_comp {
47+
struct list_head node;
4648
struct device_node *dev_node;
4749
struct clk *clk[2];
4850
struct device *larb_dev;

drivers/media/platform/mtk-mdp/mtk_mdp_core.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids);
5555
static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
5656
{
5757
struct device *dev = &mdp->pdev->dev;
58-
int i;
58+
struct mtk_mdp_comp *comp_node;
5959

60-
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
61-
mtk_mdp_comp_clock_on(dev, mdp->comp[i]);
60+
list_for_each_entry(comp_node, &mdp->comp_list, node)
61+
mtk_mdp_comp_clock_on(dev, comp_node);
6262
}
6363

6464
static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
6565
{
6666
struct device *dev = &mdp->pdev->dev;
67-
int i;
67+
struct mtk_mdp_comp *comp_node;
6868

69-
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
70-
mtk_mdp_comp_clock_off(dev, mdp->comp[i]);
69+
list_for_each_entry(comp_node, &mdp->comp_list, node)
70+
mtk_mdp_comp_clock_off(dev, comp_node);
7171
}
7272

7373
static void mtk_mdp_wdt_worker(struct work_struct *work)
@@ -91,19 +91,33 @@ static void mtk_mdp_reset_handler(void *priv)
9191
queue_work(mdp->wdt_wq, &mdp->wdt_work);
9292
}
9393

94+
void mtk_mdp_register_component(struct mtk_mdp_dev *mdp,
95+
struct mtk_mdp_comp *comp)
96+
{
97+
list_add(&mdp->comp_list, &comp->node);
98+
}
99+
100+
void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp,
101+
struct mtk_mdp_comp *comp)
102+
{
103+
list_del(&comp->node);
104+
}
105+
94106
static int mtk_mdp_probe(struct platform_device *pdev)
95107
{
96108
struct mtk_mdp_dev *mdp;
97109
struct device *dev = &pdev->dev;
98110
struct device_node *node, *parent;
99-
int i, ret = 0;
111+
struct mtk_mdp_comp *comp, *comp_temp;
112+
int ret = 0;
100113

101114
mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL);
102115
if (!mdp)
103116
return -ENOMEM;
104117

105118
mdp->id = pdev->id;
106119
mdp->pdev = pdev;
120+
INIT_LIST_HEAD(&mdp->comp_list);
107121
INIT_LIST_HEAD(&mdp->ctx_list);
108122

109123
mutex_init(&mdp->lock);
@@ -124,7 +138,6 @@ static int mtk_mdp_probe(struct platform_device *pdev)
124138
const struct of_device_id *of_id;
125139
enum mtk_mdp_comp_type comp_type;
126140
int comp_id;
127-
struct mtk_mdp_comp *comp;
128141

129142
of_id = of_match_node(mtk_mdp_comp_dt_ids, node);
130143
if (!of_id)
@@ -150,13 +163,14 @@ static int mtk_mdp_probe(struct platform_device *pdev)
150163
of_node_put(node);
151164
goto err_comp;
152165
}
153-
mdp->comp[comp_id] = comp;
154166

155167
ret = mtk_mdp_comp_init(dev, node, comp, comp_id);
156168
if (ret) {
157169
of_node_put(node);
158170
goto err_comp;
159171
}
172+
173+
mtk_mdp_register_component(mdp, comp);
160174
}
161175

162176
mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME);
@@ -220,8 +234,10 @@ static int mtk_mdp_probe(struct platform_device *pdev)
220234
err_alloc_job_wq:
221235

222236
err_comp:
223-
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
224-
mtk_mdp_comp_deinit(dev, mdp->comp[i]);
237+
list_for_each_entry_safe(comp, comp_temp, &mdp->comp_list, node) {
238+
mtk_mdp_unregister_component(mdp, comp);
239+
mtk_mdp_comp_deinit(dev, comp);
240+
}
225241

226242
dev_dbg(dev, "err %d\n", ret);
227243
return ret;
@@ -230,7 +246,7 @@ static int mtk_mdp_probe(struct platform_device *pdev)
230246
static int mtk_mdp_remove(struct platform_device *pdev)
231247
{
232248
struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev);
233-
int i;
249+
struct mtk_mdp_comp *comp, *comp_temp;
234250

235251
pm_runtime_disable(&pdev->dev);
236252
vb2_dma_contig_clear_max_seg_size(&pdev->dev);
@@ -243,8 +259,10 @@ static int mtk_mdp_remove(struct platform_device *pdev)
243259
flush_workqueue(mdp->job_wq);
244260
destroy_workqueue(mdp->job_wq);
245261

246-
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
247-
mtk_mdp_comp_deinit(&pdev->dev, mdp->comp[i]);
262+
list_for_each_entry_safe(comp, comp_temp, &mdp->comp_list, node) {
263+
mtk_mdp_unregister_component(mdp, comp);
264+
mtk_mdp_comp_deinit(&pdev->dev, comp);
265+
}
248266

249267
dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
250268
return 0;

drivers/media/platform/mtk-mdp/mtk_mdp_core.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct mtk_mdp_variant {
136136
* @pdev: pointer to the image processor platform device
137137
* @variant: the IP variant information
138138
* @id: image processor device index (0..MTK_MDP_MAX_DEVS)
139-
* @comp: MDP function components
139+
* @comp_list: list of MDP function components
140140
* @m2m_dev: v4l2 memory-to-memory device data
141141
* @ctx_list: list of struct mtk_mdp_ctx
142142
* @vdev: video device for image processor driver
@@ -154,7 +154,7 @@ struct mtk_mdp_dev {
154154
struct platform_device *pdev;
155155
struct mtk_mdp_variant *variant;
156156
u16 id;
157-
struct mtk_mdp_comp *comp[MTK_MDP_COMP_ID_MAX];
157+
struct list_head comp_list;
158158
struct v4l2_m2m_dev *m2m_dev;
159159
struct list_head ctx_list;
160160
struct video_device *vdev;
@@ -221,6 +221,12 @@ struct mtk_mdp_ctx {
221221

222222
extern int mtk_mdp_dbg_level;
223223

224+
void mtk_mdp_register_component(struct mtk_mdp_dev *mdp,
225+
struct mtk_mdp_comp *comp);
226+
227+
void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp,
228+
struct mtk_mdp_comp *comp);
229+
224230
#if defined(DEBUG)
225231

226232
#define mtk_mdp_dbg(level, fmt, args...) \

0 commit comments

Comments
 (0)