~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: df95086a5151521f9c65d50fbf42a984921a743c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// SPDX-License-Identifier: GPL-2.0+
/*
 * OMAP panel support
 *
 * Copyright (C) 2020 Dario Binacchi <dariobin@libero.it>
 */

#include <common.h>
#include <backlight.h>
#include <clk.h>
#include <display.h>
#include <dm.h>
#include <dm/device_compat.h>
#include <log.h>
#include <panel.h>
#include <asm/gpio.h>
#include <linux/err.h>
#include "tilcdc.h"

struct tilcdc_panel_priv {
	struct tilcdc_panel_info info;
	struct display_timing timing;
	struct udevice *backlight;
	struct gpio_desc enable;
};

static int tilcdc_panel_enable_backlight(struct udevice *dev)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);

	if (dm_gpio_is_valid(&priv->enable))
		dm_gpio_set_value(&priv->enable, 1);

	if (priv->backlight)
		return backlight_enable(priv->backlight);

	return 0;
}

static int tilcdc_panel_set_backlight(struct udevice *dev, int percent)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);

	if (dm_gpio_is_valid(&priv->enable))
		dm_gpio_set_value(&priv->enable, 1);

	if (priv->backlight)
		return backlight_set_brightness(priv->backlight, percent);

	return 0;
}

int tilcdc_panel_get_display_info(struct udevice *dev,
				  struct tilcdc_panel_info *info)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);

	memcpy(info, &priv->info, sizeof(*info));
	return 0;
}

static int tilcdc_panel_get_display_timing(struct udevice *dev,
					   struct display_timing *timing)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);

	memcpy(timing, &priv->timing, sizeof(*timing));
	return 0;
}

static int tilcdc_panel_remove(struct udevice *dev)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);

	if (dm_gpio_is_valid(&priv->enable))
		dm_gpio_free(dev, &priv->enable);

	return 0;
}

static int tilcdc_panel_probe(struct udevice *dev)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);
	int err;

	err = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
					   "backlight", &priv->backlight);
	if (err)
		dev_warn(dev, "failed to get backlight\n");

	err = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
				   GPIOD_IS_OUT);
	if (err) {
		dev_warn(dev, "failed to get enable GPIO\n");
		if (err != -ENOENT)
			return err;
	}

	return 0;
}

static int tilcdc_panel_of_to_plat(struct udevice *dev)
{
	struct tilcdc_panel_priv *priv = dev_get_priv(dev);
	ofnode node;
	int err;

	err = ofnode_decode_display_timing(dev_ofnode(dev), 0, &priv->timing);
	if (err) {
		dev_err(dev, "failed to get display timing\n");
		return err;
	}

	node = dev_read_subnode(dev, "panel-info");
	if (!ofnode_valid(node)) {
		dev_err(dev, "missing 'panel-info' node\n");
		return -ENXIO;
	}

	err |= ofnode_read_u32(node, "ac-bias", &priv->info.ac_bias);
	err |= ofnode_read_u32(node, "ac-bias-intrpt",
			       &priv->info.ac_bias_intrpt);
	err |= ofnode_read_u32(node, "dma-burst-sz", &priv->info.dma_burst_sz);
	err |= ofnode_read_u32(node, "bpp", &priv->info.bpp);
	err |= ofnode_read_u32(node, "fdd", &priv->info.fdd);
	err |= ofnode_read_u32(node, "sync-edge", &priv->info.sync_edge);
	err |= ofnode_read_u32(node, "sync-ctrl", &priv->info.sync_ctrl);
	err |= ofnode_read_u32(node, "raster-order", &priv->info.raster_order);
	err |= ofnode_read_u32(node, "fifo-th", &priv->info.fifo_th);
	if (err) {
		dev_err(dev, "failed to get panel info\n");
		return err;
	}

	/* optional */
	priv->info.tft_alt_mode = ofnode_read_bool(node, "tft-alt-mode");
	priv->info.invert_pxl_clk = ofnode_read_bool(node, "invert-pxl-clk");

	dev_dbg(dev, "LCD: %dx%d, bpp=%d, clk=%d Hz\n",
		priv->timing.hactive.typ, priv->timing.vactive.typ,
		priv->info.bpp, priv->timing.pixelclock.typ);
	dev_dbg(dev, "     hbp=%d, hfp=%d, hsw=%d\n",
		priv->timing.hback_porch.typ, priv->timing.hfront_porch.typ,
		priv->timing.hsync_len.typ);
	dev_dbg(dev, "     vbp=%d, vfp=%d, vsw=%d\n",
		priv->timing.vback_porch.typ, priv->timing.vfront_porch.typ,
		priv->timing.vsync_len.typ);

	return 0;
}

static const struct panel_ops tilcdc_panel_ops = {
	.enable_backlight = tilcdc_panel_enable_backlight,
	.set_backlight = tilcdc_panel_set_backlight,
	.get_display_timing = tilcdc_panel_get_display_timing,
};

static const struct udevice_id tilcdc_panel_ids[] = {
	{.compatible = "ti,tilcdc,panel"},
	{}
};

U_BOOT_DRIVER(tilcdc_panel) = {
	.name = "tilcdc_panel",
	.id = UCLASS_PANEL,
	.of_match = tilcdc_panel_ids,
	.ops = &tilcdc_panel_ops,
	.of_to_plat = tilcdc_panel_of_to_plat,
	.probe = tilcdc_panel_probe,
	.remove = tilcdc_panel_remove,
	.priv_auto = sizeof(struct tilcdc_panel_priv),
};