Skip to content

Commit 59d29c0

Browse files
committed
drm/tegra: Allocate resources at probe time
Since the .init() and .exit() functions are executed whenever the DRM driver is loaded or unloaded, care must be taken not to use them for resource allocation. Otherwise deferred probing cannot be used, since the .init() and .exit() are not run at probe time. Similarly the code that frees resources must be run at .remove() time. If it is run from the .exit() function, it can release resources multiple times. To handle this more consistently, rename the tegra_output_parse_dt() function to tegra_output_probe() and introduce tegra_output_remove() which can be used to free output-related resources. Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent f002abc commit 59d29c0

5 files changed

Lines changed: 56 additions & 27 deletions

File tree

‎drivers/gpu/drm/tegra/dc.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,12 @@ static int tegra_dc_remove(struct platform_device *pdev)
11911191
return err;
11921192
}
11931193

1194+
err = tegra_dc_rgb_remove(dc);
1195+
if (err < 0) {
1196+
dev_err(&pdev->dev, "failed to remove RGB output: %d\n", err);
1197+
return err;
1198+
}
1199+
11941200
clk_disable_unprepare(dc->clk);
11951201

11961202
return 0;

‎drivers/gpu/drm/tegra/drm.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
236236

237237
/* from rgb.c */
238238
extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
239+
extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
239240
extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
240241
extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
241242

242243
/* from output.c */
243-
extern int tegra_output_parse_dt(struct tegra_output *output);
244+
extern int tegra_output_probe(struct tegra_output *output);
245+
extern int tegra_output_remove(struct tegra_output *output);
244246
extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
245247
extern int tegra_output_exit(struct tegra_output *output);
246248

‎drivers/gpu/drm/tegra/hdmi.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ static int tegra_hdmi_probe(struct platform_device *pdev)
12261226

12271227
hdmi->output.dev = &pdev->dev;
12281228

1229-
err = tegra_output_parse_dt(&hdmi->output);
1229+
err = tegra_output_probe(&hdmi->output);
12301230
if (err < 0)
12311231
return err;
12321232

@@ -1272,6 +1272,12 @@ static int tegra_hdmi_remove(struct platform_device *pdev)
12721272
return err;
12731273
}
12741274

1275+
err = tegra_output_remove(&hdmi->output);
1276+
if (err < 0) {
1277+
dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1278+
return err;
1279+
}
1280+
12751281
clk_unprepare(hdmi->clk_parent);
12761282
clk_unprepare(hdmi->clk);
12771283

‎drivers/gpu/drm/tegra/output.c‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static irqreturn_t hpd_irq(int irq, void *data)
161161
return IRQ_HANDLED;
162162
}
163163

164-
int tegra_output_parse_dt(struct tegra_output *output)
164+
int tegra_output_probe(struct tegra_output *output)
165165
{
166166
enum of_gpio_flags flags;
167167
struct device_node *ddc;
@@ -191,14 +191,6 @@ int tegra_output_parse_dt(struct tegra_output *output)
191191
output->hpd_gpio = of_get_named_gpio_flags(output->of_node,
192192
"nvidia,hpd-gpio", 0,
193193
&flags);
194-
195-
return 0;
196-
}
197-
198-
int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
199-
{
200-
int connector, encoder, err;
201-
202194
if (gpio_is_valid(output->hpd_gpio)) {
203195
unsigned long flags;
204196

@@ -212,7 +204,8 @@ int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
212204
err = gpio_to_irq(output->hpd_gpio);
213205
if (err < 0) {
214206
dev_err(output->dev, "gpio_to_irq(): %d\n", err);
215-
goto free_hpd;
207+
gpio_free(output->hpd_gpio);
208+
return err;
216209
}
217210

218211
output->hpd_irq = err;
@@ -225,12 +218,33 @@ int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
225218
if (err < 0) {
226219
dev_err(output->dev, "failed to request IRQ#%u: %d\n",
227220
output->hpd_irq, err);
228-
goto free_hpd;
221+
gpio_free(output->hpd_gpio);
222+
return err;
229223
}
230224

231225
output->connector.polled = DRM_CONNECTOR_POLL_HPD;
232226
}
233227

228+
return 0;
229+
}
230+
231+
int tegra_output_remove(struct tegra_output *output)
232+
{
233+
if (gpio_is_valid(output->hpd_gpio)) {
234+
free_irq(output->hpd_irq, output);
235+
gpio_free(output->hpd_gpio);
236+
}
237+
238+
if (output->ddc)
239+
put_device(&output->ddc->dev);
240+
241+
return 0;
242+
}
243+
244+
int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
245+
{
246+
int connector, encoder;
247+
234248
switch (output->type) {
235249
case TEGRA_OUTPUT_RGB:
236250
connector = DRM_MODE_CONNECTOR_LVDS;
@@ -261,22 +275,9 @@ int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
261275
output->encoder.possible_crtcs = 0x3;
262276

263277
return 0;
264-
265-
free_hpd:
266-
gpio_free(output->hpd_gpio);
267-
268-
return err;
269278
}
270279

271280
int tegra_output_exit(struct tegra_output *output)
272281
{
273-
if (gpio_is_valid(output->hpd_gpio)) {
274-
free_irq(output->hpd_irq, output);
275-
gpio_free(output->hpd_gpio);
276-
}
277-
278-
if (output->ddc)
279-
put_device(&output->ddc->dev);
280-
281282
return 0;
282283
}

‎drivers/gpu/drm/tegra/rgb.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int tegra_dc_rgb_probe(struct tegra_dc *dc)
147147
rgb->output.dev = dc->dev;
148148
rgb->output.of_node = np;
149149

150-
err = tegra_output_parse_dt(&rgb->output);
150+
err = tegra_output_probe(&rgb->output);
151151
if (err < 0)
152152
return err;
153153

@@ -174,6 +174,20 @@ int tegra_dc_rgb_probe(struct tegra_dc *dc)
174174
return 0;
175175
}
176176

177+
int tegra_dc_rgb_remove(struct tegra_dc *dc)
178+
{
179+
int err;
180+
181+
if (!dc->rgb)
182+
return 0;
183+
184+
err = tegra_output_remove(dc->rgb);
185+
if (err < 0)
186+
return err;
187+
188+
return 0;
189+
}
190+
177191
int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc)
178192
{
179193
struct tegra_rgb *rgb = to_rgb(dc->rgb);

0 commit comments

Comments
 (0)