Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2012 Texas Instruments
  4 * Author: Rob Clark <robdclark@gmail.com>
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6
 
 
  7#include <linux/backlight.h>
  8#include <linux/gpio/consumer.h>
  9#include <linux/pinctrl/consumer.h>
 10#include <linux/platform_device.h>
 11
 12#include <video/display_timing.h>
 13#include <video/of_display_timing.h>
 14#include <video/videomode.h>
 15
 16#include <drm/drm_atomic_state_helper.h>
 17#include <drm/drm_connector.h>
 18#include <drm/drm_modeset_helper_vtables.h>
 19#include <drm/drm_probe_helper.h>
 20#include <drm/drm_simple_kms_helper.h>
 21
 22#include "tilcdc_drv.h"
 23#include "tilcdc_panel.h"
 24
 25struct panel_module {
 26	struct tilcdc_module base;
 27	struct tilcdc_panel_info *info;
 28	struct display_timings *timings;
 29	struct backlight_device *backlight;
 30	struct gpio_desc *enable_gpio;
 31};
 32#define to_panel_module(x) container_of(x, struct panel_module, base)
 33
 34
 35/*
 36 * Encoder:
 37 */
 38
 39struct panel_encoder {
 40	struct drm_encoder base;
 41	struct panel_module *mod;
 42};
 43#define to_panel_encoder(x) container_of(x, struct panel_encoder, base)
 44
 45static void panel_encoder_dpms(struct drm_encoder *encoder, int mode)
 46{
 47	struct panel_encoder *panel_encoder = to_panel_encoder(encoder);
 48	struct backlight_device *backlight = panel_encoder->mod->backlight;
 49	struct gpio_desc *gpio = panel_encoder->mod->enable_gpio;
 50
 51	if (backlight) {
 52		backlight->props.power = mode == DRM_MODE_DPMS_ON ?
 53					 FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
 54		backlight_update_status(backlight);
 55	}
 56
 57	if (gpio)
 58		gpiod_set_value_cansleep(gpio,
 59					 mode == DRM_MODE_DPMS_ON ? 1 : 0);
 60}
 61
 62static void panel_encoder_prepare(struct drm_encoder *encoder)
 63{
 64	panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
 65}
 66
 67static void panel_encoder_commit(struct drm_encoder *encoder)
 68{
 69	panel_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
 70}
 71
 72static void panel_encoder_mode_set(struct drm_encoder *encoder,
 73		struct drm_display_mode *mode,
 74		struct drm_display_mode *adjusted_mode)
 75{
 76	/* nothing needed */
 77}
 78
 
 
 
 
 79static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = {
 80		.dpms           = panel_encoder_dpms,
 81		.prepare        = panel_encoder_prepare,
 82		.commit         = panel_encoder_commit,
 83		.mode_set       = panel_encoder_mode_set,
 84};
 85
 86static struct drm_encoder *panel_encoder_create(struct drm_device *dev,
 87		struct panel_module *mod)
 88{
 89	struct panel_encoder *panel_encoder;
 90	struct drm_encoder *encoder;
 91	int ret;
 92
 93	panel_encoder = devm_kzalloc(dev->dev, sizeof(*panel_encoder),
 94				     GFP_KERNEL);
 95	if (!panel_encoder)
 96		return NULL;
 97
 98	panel_encoder->mod = mod;
 99
100	encoder = &panel_encoder->base;
101	encoder->possible_crtcs = 1;
102
103	ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_LVDS);
 
104	if (ret < 0)
105		goto fail;
106
107	drm_encoder_helper_add(encoder, &panel_encoder_helper_funcs);
108
109	return encoder;
110
111fail:
112	drm_encoder_cleanup(encoder);
113	return NULL;
114}
115
116/*
117 * Connector:
118 */
119
120struct panel_connector {
121	struct drm_connector base;
122
123	struct drm_encoder *encoder;  /* our connected encoder */
124	struct panel_module *mod;
125};
126#define to_panel_connector(x) container_of(x, struct panel_connector, base)
127
128
129static void panel_connector_destroy(struct drm_connector *connector)
130{
131	drm_connector_unregister(connector);
132	drm_connector_cleanup(connector);
133}
134
135static int panel_connector_get_modes(struct drm_connector *connector)
136{
137	struct drm_device *dev = connector->dev;
138	struct panel_connector *panel_connector = to_panel_connector(connector);
139	struct display_timings *timings = panel_connector->mod->timings;
140	int i;
141
142	for (i = 0; i < timings->num_timings; i++) {
143		struct drm_display_mode *mode;
144		struct videomode vm;
145
146		if (videomode_from_timings(timings, &vm, i))
147			break;
148
149		mode = drm_mode_create(dev);
150		if (!mode)
151			break;
152
153		drm_display_mode_from_videomode(&vm, mode);
154
155		mode->type = DRM_MODE_TYPE_DRIVER;
156
157		if (timings->native_mode == i)
158			mode->type |= DRM_MODE_TYPE_PREFERRED;
159
160		drm_mode_set_name(mode);
161		drm_mode_probed_add(connector, mode);
162	}
163
164	return i;
165}
166
 
 
 
 
 
 
 
 
167static struct drm_encoder *panel_connector_best_encoder(
168		struct drm_connector *connector)
169{
170	struct panel_connector *panel_connector = to_panel_connector(connector);
171	return panel_connector->encoder;
172}
173
174static const struct drm_connector_funcs panel_connector_funcs = {
175	.destroy            = panel_connector_destroy,
176	.fill_modes         = drm_helper_probe_single_connector_modes,
177	.reset              = drm_atomic_helper_connector_reset,
178	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
179	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
180};
181
182static const struct drm_connector_helper_funcs panel_connector_helper_funcs = {
183	.get_modes          = panel_connector_get_modes,
 
184	.best_encoder       = panel_connector_best_encoder,
185};
186
187static struct drm_connector *panel_connector_create(struct drm_device *dev,
188		struct panel_module *mod, struct drm_encoder *encoder)
189{
190	struct panel_connector *panel_connector;
191	struct drm_connector *connector;
192	int ret;
193
194	panel_connector = devm_kzalloc(dev->dev, sizeof(*panel_connector),
195				       GFP_KERNEL);
196	if (!panel_connector)
197		return NULL;
198
199	panel_connector->encoder = encoder;
200	panel_connector->mod = mod;
201
202	connector = &panel_connector->base;
203
204	drm_connector_init(dev, connector, &panel_connector_funcs,
205			DRM_MODE_CONNECTOR_LVDS);
206	drm_connector_helper_add(connector, &panel_connector_helper_funcs);
207
208	connector->interlace_allowed = 0;
209	connector->doublescan_allowed = 0;
210
211	ret = drm_connector_attach_encoder(connector, encoder);
212	if (ret)
213		goto fail;
214
215	return connector;
216
217fail:
218	panel_connector_destroy(connector);
219	return NULL;
220}
221
222/*
223 * Module:
224 */
225
226static int panel_modeset_init(struct tilcdc_module *mod, struct drm_device *dev)
227{
228	struct panel_module *panel_mod = to_panel_module(mod);
229	struct tilcdc_drm_private *priv = dev->dev_private;
230	struct drm_encoder *encoder;
231	struct drm_connector *connector;
232
233	encoder = panel_encoder_create(dev, panel_mod);
234	if (!encoder)
235		return -ENOMEM;
236
237	connector = panel_connector_create(dev, panel_mod, encoder);
238	if (!connector)
239		return -ENOMEM;
240
241	priv->encoders[priv->num_encoders++] = encoder;
242	priv->connectors[priv->num_connectors++] = connector;
243
244	tilcdc_crtc_set_panel_info(priv->crtc,
245				   to_panel_encoder(encoder)->mod->info);
246
247	return 0;
248}
249
250static const struct tilcdc_module_ops panel_module_ops = {
251		.modeset_init = panel_modeset_init,
252};
253
254/*
255 * Device:
256 */
257
258/* maybe move this somewhere common if it is needed by other outputs? */
259static struct tilcdc_panel_info *of_get_panel_info(struct device_node *np)
260{
261	struct device_node *info_np;
262	struct tilcdc_panel_info *info;
263	int ret = 0;
264
265	if (!np) {
266		pr_err("%s: no devicenode given\n", __func__);
267		return NULL;
268	}
269
270	info_np = of_get_child_by_name(np, "panel-info");
271	if (!info_np) {
272		pr_err("%s: could not find panel-info node\n", __func__);
273		return NULL;
274	}
275
276	info = kzalloc(sizeof(*info), GFP_KERNEL);
277	if (!info)
278		goto put_node;
279
280	ret |= of_property_read_u32(info_np, "ac-bias", &info->ac_bias);
281	ret |= of_property_read_u32(info_np, "ac-bias-intrpt", &info->ac_bias_intrpt);
282	ret |= of_property_read_u32(info_np, "dma-burst-sz", &info->dma_burst_sz);
283	ret |= of_property_read_u32(info_np, "bpp", &info->bpp);
284	ret |= of_property_read_u32(info_np, "fdd", &info->fdd);
285	ret |= of_property_read_u32(info_np, "sync-edge", &info->sync_edge);
286	ret |= of_property_read_u32(info_np, "sync-ctrl", &info->sync_ctrl);
287	ret |= of_property_read_u32(info_np, "raster-order", &info->raster_order);
288	ret |= of_property_read_u32(info_np, "fifo-th", &info->fifo_th);
289
290	/* optional: */
291	info->tft_alt_mode      = of_property_read_bool(info_np, "tft-alt-mode");
292	info->invert_pxl_clk    = of_property_read_bool(info_np, "invert-pxl-clk");
293
294	if (ret) {
295		pr_err("%s: error reading panel-info properties\n", __func__);
296		kfree(info);
297		info = NULL;
298	}
299
300put_node:
301	of_node_put(info_np);
302	return info;
303}
304
305static int panel_probe(struct platform_device *pdev)
306{
307	struct device_node *node = pdev->dev.of_node;
308	struct backlight_device *backlight;
309	struct panel_module *panel_mod;
310	struct tilcdc_module *mod;
311	struct pinctrl *pinctrl;
312	int ret;
313
314	/* bail out early if no DT data: */
315	if (!node) {
316		dev_err(&pdev->dev, "device-tree data is missing\n");
317		return -ENXIO;
318	}
319
320	panel_mod = devm_kzalloc(&pdev->dev, sizeof(*panel_mod), GFP_KERNEL);
321	if (!panel_mod)
322		return -ENOMEM;
323
324	backlight = devm_of_find_backlight(&pdev->dev);
325	if (IS_ERR(backlight))
326		return PTR_ERR(backlight);
327	panel_mod->backlight = backlight;
 
 
 
 
 
 
328
329	panel_mod->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
330							 GPIOD_OUT_LOW);
331	if (IS_ERR(panel_mod->enable_gpio)) {
332		ret = PTR_ERR(panel_mod->enable_gpio);
333		dev_err(&pdev->dev, "failed to request enable GPIO\n");
334		goto fail_backlight;
335	}
336
337	if (panel_mod->enable_gpio)
338		dev_info(&pdev->dev, "found enable GPIO\n");
339
340	mod = &panel_mod->base;
341	pdev->dev.platform_data = mod;
342
343	tilcdc_module_init(mod, "panel", &panel_module_ops);
344
345	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
346	if (IS_ERR(pinctrl))
347		dev_warn(&pdev->dev, "pins are not configured\n");
348
349	panel_mod->timings = of_get_display_timings(node);
350	if (!panel_mod->timings) {
351		dev_err(&pdev->dev, "could not get panel timings\n");
352		ret = -EINVAL;
353		goto fail_free;
354	}
355
356	panel_mod->info = of_get_panel_info(node);
357	if (!panel_mod->info) {
358		dev_err(&pdev->dev, "could not get panel info\n");
359		ret = -EINVAL;
360		goto fail_timings;
361	}
362
363	return 0;
364
365fail_timings:
366	display_timings_release(panel_mod->timings);
367
368fail_free:
369	tilcdc_module_cleanup(mod);
370
371fail_backlight:
372	if (panel_mod->backlight)
373		put_device(&panel_mod->backlight->dev);
374	return ret;
375}
376
377static void panel_remove(struct platform_device *pdev)
378{
379	struct tilcdc_module *mod = dev_get_platdata(&pdev->dev);
380	struct panel_module *panel_mod = to_panel_module(mod);
381	struct backlight_device *backlight = panel_mod->backlight;
382
383	if (backlight)
384		put_device(&backlight->dev);
385
386	display_timings_release(panel_mod->timings);
387
388	tilcdc_module_cleanup(mod);
389	kfree(panel_mod->info);
 
 
390}
391
392static const struct of_device_id panel_of_match[] = {
393		{ .compatible = "ti,tilcdc,panel", },
394		{ },
395};
396
397static struct platform_driver panel_driver = {
398	.probe = panel_probe,
399	.remove_new = panel_remove,
400	.driver = {
 
401		.name = "tilcdc-panel",
402		.of_match_table = panel_of_match,
403	},
404};
405
406int __init tilcdc_panel_init(void)
407{
408	return platform_driver_register(&panel_driver);
409}
410
411void __exit tilcdc_panel_fini(void)
412{
413	platform_driver_unregister(&panel_driver);
414}
v4.17
 
  1/*
  2 * Copyright (C) 2012 Texas Instruments
  3 * Author: Rob Clark <robdclark@gmail.com>
  4 *
  5 * This program is free software; you can redistribute it and/or modify it
  6 * under the terms of the GNU General Public License version 2 as published by
  7 * the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it will be useful, but WITHOUT
 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 12 * more details.
 13 *
 14 * You should have received a copy of the GNU General Public License along with
 15 * this program.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17
 18#include <linux/pinctrl/pinmux.h>
 19#include <linux/pinctrl/consumer.h>
 20#include <linux/backlight.h>
 21#include <linux/gpio/consumer.h>
 
 
 
 22#include <video/display_timing.h>
 23#include <video/of_display_timing.h>
 24#include <video/videomode.h>
 25#include <drm/drm_atomic_helper.h>
 
 
 
 
 
 26
 27#include "tilcdc_drv.h"
 28#include "tilcdc_panel.h"
 29
 30struct panel_module {
 31	struct tilcdc_module base;
 32	struct tilcdc_panel_info *info;
 33	struct display_timings *timings;
 34	struct backlight_device *backlight;
 35	struct gpio_desc *enable_gpio;
 36};
 37#define to_panel_module(x) container_of(x, struct panel_module, base)
 38
 39
 40/*
 41 * Encoder:
 42 */
 43
 44struct panel_encoder {
 45	struct drm_encoder base;
 46	struct panel_module *mod;
 47};
 48#define to_panel_encoder(x) container_of(x, struct panel_encoder, base)
 49
 50static void panel_encoder_dpms(struct drm_encoder *encoder, int mode)
 51{
 52	struct panel_encoder *panel_encoder = to_panel_encoder(encoder);
 53	struct backlight_device *backlight = panel_encoder->mod->backlight;
 54	struct gpio_desc *gpio = panel_encoder->mod->enable_gpio;
 55
 56	if (backlight) {
 57		backlight->props.power = mode == DRM_MODE_DPMS_ON ?
 58					 FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
 59		backlight_update_status(backlight);
 60	}
 61
 62	if (gpio)
 63		gpiod_set_value_cansleep(gpio,
 64					 mode == DRM_MODE_DPMS_ON ? 1 : 0);
 65}
 66
 67static void panel_encoder_prepare(struct drm_encoder *encoder)
 68{
 69	panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
 70}
 71
 72static void panel_encoder_commit(struct drm_encoder *encoder)
 73{
 74	panel_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
 75}
 76
 77static void panel_encoder_mode_set(struct drm_encoder *encoder,
 78		struct drm_display_mode *mode,
 79		struct drm_display_mode *adjusted_mode)
 80{
 81	/* nothing needed */
 82}
 83
 84static const struct drm_encoder_funcs panel_encoder_funcs = {
 85		.destroy        = drm_encoder_cleanup,
 86};
 87
 88static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = {
 89		.dpms           = panel_encoder_dpms,
 90		.prepare        = panel_encoder_prepare,
 91		.commit         = panel_encoder_commit,
 92		.mode_set       = panel_encoder_mode_set,
 93};
 94
 95static struct drm_encoder *panel_encoder_create(struct drm_device *dev,
 96		struct panel_module *mod)
 97{
 98	struct panel_encoder *panel_encoder;
 99	struct drm_encoder *encoder;
100	int ret;
101
102	panel_encoder = devm_kzalloc(dev->dev, sizeof(*panel_encoder),
103				     GFP_KERNEL);
104	if (!panel_encoder)
105		return NULL;
106
107	panel_encoder->mod = mod;
108
109	encoder = &panel_encoder->base;
110	encoder->possible_crtcs = 1;
111
112	ret = drm_encoder_init(dev, encoder, &panel_encoder_funcs,
113			DRM_MODE_ENCODER_LVDS, NULL);
114	if (ret < 0)
115		goto fail;
116
117	drm_encoder_helper_add(encoder, &panel_encoder_helper_funcs);
118
119	return encoder;
120
121fail:
122	drm_encoder_cleanup(encoder);
123	return NULL;
124}
125
126/*
127 * Connector:
128 */
129
130struct panel_connector {
131	struct drm_connector base;
132
133	struct drm_encoder *encoder;  /* our connected encoder */
134	struct panel_module *mod;
135};
136#define to_panel_connector(x) container_of(x, struct panel_connector, base)
137
138
139static void panel_connector_destroy(struct drm_connector *connector)
140{
141	drm_connector_unregister(connector);
142	drm_connector_cleanup(connector);
143}
144
145static int panel_connector_get_modes(struct drm_connector *connector)
146{
147	struct drm_device *dev = connector->dev;
148	struct panel_connector *panel_connector = to_panel_connector(connector);
149	struct display_timings *timings = panel_connector->mod->timings;
150	int i;
151
152	for (i = 0; i < timings->num_timings; i++) {
153		struct drm_display_mode *mode = drm_mode_create(dev);
154		struct videomode vm;
155
156		if (videomode_from_timings(timings, &vm, i))
157			break;
158
 
 
 
 
159		drm_display_mode_from_videomode(&vm, mode);
160
161		mode->type = DRM_MODE_TYPE_DRIVER;
162
163		if (timings->native_mode == i)
164			mode->type |= DRM_MODE_TYPE_PREFERRED;
165
166		drm_mode_set_name(mode);
167		drm_mode_probed_add(connector, mode);
168	}
169
170	return i;
171}
172
173static int panel_connector_mode_valid(struct drm_connector *connector,
174		  struct drm_display_mode *mode)
175{
176	struct tilcdc_drm_private *priv = connector->dev->dev_private;
177	/* our only constraints are what the crtc can generate: */
178	return tilcdc_crtc_mode_valid(priv->crtc, mode);
179}
180
181static struct drm_encoder *panel_connector_best_encoder(
182		struct drm_connector *connector)
183{
184	struct panel_connector *panel_connector = to_panel_connector(connector);
185	return panel_connector->encoder;
186}
187
188static const struct drm_connector_funcs panel_connector_funcs = {
189	.destroy            = panel_connector_destroy,
190	.fill_modes         = drm_helper_probe_single_connector_modes,
191	.reset              = drm_atomic_helper_connector_reset,
192	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
193	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
194};
195
196static const struct drm_connector_helper_funcs panel_connector_helper_funcs = {
197	.get_modes          = panel_connector_get_modes,
198	.mode_valid         = panel_connector_mode_valid,
199	.best_encoder       = panel_connector_best_encoder,
200};
201
202static struct drm_connector *panel_connector_create(struct drm_device *dev,
203		struct panel_module *mod, struct drm_encoder *encoder)
204{
205	struct panel_connector *panel_connector;
206	struct drm_connector *connector;
207	int ret;
208
209	panel_connector = devm_kzalloc(dev->dev, sizeof(*panel_connector),
210				       GFP_KERNEL);
211	if (!panel_connector)
212		return NULL;
213
214	panel_connector->encoder = encoder;
215	panel_connector->mod = mod;
216
217	connector = &panel_connector->base;
218
219	drm_connector_init(dev, connector, &panel_connector_funcs,
220			DRM_MODE_CONNECTOR_LVDS);
221	drm_connector_helper_add(connector, &panel_connector_helper_funcs);
222
223	connector->interlace_allowed = 0;
224	connector->doublescan_allowed = 0;
225
226	ret = drm_mode_connector_attach_encoder(connector, encoder);
227	if (ret)
228		goto fail;
229
230	return connector;
231
232fail:
233	panel_connector_destroy(connector);
234	return NULL;
235}
236
237/*
238 * Module:
239 */
240
241static int panel_modeset_init(struct tilcdc_module *mod, struct drm_device *dev)
242{
243	struct panel_module *panel_mod = to_panel_module(mod);
244	struct tilcdc_drm_private *priv = dev->dev_private;
245	struct drm_encoder *encoder;
246	struct drm_connector *connector;
247
248	encoder = panel_encoder_create(dev, panel_mod);
249	if (!encoder)
250		return -ENOMEM;
251
252	connector = panel_connector_create(dev, panel_mod, encoder);
253	if (!connector)
254		return -ENOMEM;
255
256	priv->encoders[priv->num_encoders++] = encoder;
257	priv->connectors[priv->num_connectors++] = connector;
258
259	tilcdc_crtc_set_panel_info(priv->crtc,
260				   to_panel_encoder(encoder)->mod->info);
261
262	return 0;
263}
264
265static const struct tilcdc_module_ops panel_module_ops = {
266		.modeset_init = panel_modeset_init,
267};
268
269/*
270 * Device:
271 */
272
273/* maybe move this somewhere common if it is needed by other outputs? */
274static struct tilcdc_panel_info *of_get_panel_info(struct device_node *np)
275{
276	struct device_node *info_np;
277	struct tilcdc_panel_info *info;
278	int ret = 0;
279
280	if (!np) {
281		pr_err("%s: no devicenode given\n", __func__);
282		return NULL;
283	}
284
285	info_np = of_get_child_by_name(np, "panel-info");
286	if (!info_np) {
287		pr_err("%s: could not find panel-info node\n", __func__);
288		return NULL;
289	}
290
291	info = kzalloc(sizeof(*info), GFP_KERNEL);
292	if (!info)
293		goto put_node;
294
295	ret |= of_property_read_u32(info_np, "ac-bias", &info->ac_bias);
296	ret |= of_property_read_u32(info_np, "ac-bias-intrpt", &info->ac_bias_intrpt);
297	ret |= of_property_read_u32(info_np, "dma-burst-sz", &info->dma_burst_sz);
298	ret |= of_property_read_u32(info_np, "bpp", &info->bpp);
299	ret |= of_property_read_u32(info_np, "fdd", &info->fdd);
300	ret |= of_property_read_u32(info_np, "sync-edge", &info->sync_edge);
301	ret |= of_property_read_u32(info_np, "sync-ctrl", &info->sync_ctrl);
302	ret |= of_property_read_u32(info_np, "raster-order", &info->raster_order);
303	ret |= of_property_read_u32(info_np, "fifo-th", &info->fifo_th);
304
305	/* optional: */
306	info->tft_alt_mode      = of_property_read_bool(info_np, "tft-alt-mode");
307	info->invert_pxl_clk    = of_property_read_bool(info_np, "invert-pxl-clk");
308
309	if (ret) {
310		pr_err("%s: error reading panel-info properties\n", __func__);
311		kfree(info);
312		info = NULL;
313	}
314
315put_node:
316	of_node_put(info_np);
317	return info;
318}
319
320static int panel_probe(struct platform_device *pdev)
321{
322	struct device_node *bl_node, *node = pdev->dev.of_node;
 
323	struct panel_module *panel_mod;
324	struct tilcdc_module *mod;
325	struct pinctrl *pinctrl;
326	int ret;
327
328	/* bail out early if no DT data: */
329	if (!node) {
330		dev_err(&pdev->dev, "device-tree data is missing\n");
331		return -ENXIO;
332	}
333
334	panel_mod = devm_kzalloc(&pdev->dev, sizeof(*panel_mod), GFP_KERNEL);
335	if (!panel_mod)
336		return -ENOMEM;
337
338	bl_node = of_parse_phandle(node, "backlight", 0);
339	if (bl_node) {
340		panel_mod->backlight = of_find_backlight_by_node(bl_node);
341		of_node_put(bl_node);
342
343		if (!panel_mod->backlight)
344			return -EPROBE_DEFER;
345
346		dev_info(&pdev->dev, "found backlight\n");
347	}
348
349	panel_mod->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
350							 GPIOD_OUT_LOW);
351	if (IS_ERR(panel_mod->enable_gpio)) {
352		ret = PTR_ERR(panel_mod->enable_gpio);
353		dev_err(&pdev->dev, "failed to request enable GPIO\n");
354		goto fail_backlight;
355	}
356
357	if (panel_mod->enable_gpio)
358		dev_info(&pdev->dev, "found enable GPIO\n");
359
360	mod = &panel_mod->base;
361	pdev->dev.platform_data = mod;
362
363	tilcdc_module_init(mod, "panel", &panel_module_ops);
364
365	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
366	if (IS_ERR(pinctrl))
367		dev_warn(&pdev->dev, "pins are not configured\n");
368
369	panel_mod->timings = of_get_display_timings(node);
370	if (!panel_mod->timings) {
371		dev_err(&pdev->dev, "could not get panel timings\n");
372		ret = -EINVAL;
373		goto fail_free;
374	}
375
376	panel_mod->info = of_get_panel_info(node);
377	if (!panel_mod->info) {
378		dev_err(&pdev->dev, "could not get panel info\n");
379		ret = -EINVAL;
380		goto fail_timings;
381	}
382
383	return 0;
384
385fail_timings:
386	display_timings_release(panel_mod->timings);
387
388fail_free:
389	tilcdc_module_cleanup(mod);
390
391fail_backlight:
392	if (panel_mod->backlight)
393		put_device(&panel_mod->backlight->dev);
394	return ret;
395}
396
397static int panel_remove(struct platform_device *pdev)
398{
399	struct tilcdc_module *mod = dev_get_platdata(&pdev->dev);
400	struct panel_module *panel_mod = to_panel_module(mod);
401	struct backlight_device *backlight = panel_mod->backlight;
402
403	if (backlight)
404		put_device(&backlight->dev);
405
406	display_timings_release(panel_mod->timings);
407
408	tilcdc_module_cleanup(mod);
409	kfree(panel_mod->info);
410
411	return 0;
412}
413
414static const struct of_device_id panel_of_match[] = {
415		{ .compatible = "ti,tilcdc,panel", },
416		{ },
417};
418
419struct platform_driver panel_driver = {
420	.probe = panel_probe,
421	.remove = panel_remove,
422	.driver = {
423		.owner = THIS_MODULE,
424		.name = "tilcdc-panel",
425		.of_match_table = panel_of_match,
426	},
427};
428
429int __init tilcdc_panel_init(void)
430{
431	return platform_driver_register(&panel_driver);
432}
433
434void __exit tilcdc_panel_fini(void)
435{
436	platform_driver_unregister(&panel_driver);
437}