omap: add kernel 3.14 support
[openwrt/svn-archive/archive.git] / target / linux / omap / patches-3.14 / 0334-video-da8xx-fb-adding-dt-support.patch
1 From 884d3962ef4787c8cf0b8a7a673531c623d1dff8 Mon Sep 17 00:00:00 2001
2 From: Darren Etheridge <detheridge@ti.com>
3 Date: Fri, 2 Aug 2013 15:35:36 -0500
4 Subject: [PATCH 334/752] video: da8xx-fb: adding dt support
5
6 Enhancing driver to enable probe triggered by a corresponding dt entry.
7
8 Add da8xx-fb.txt documentation to devicetree section.
9
10 Obtain fb_videomode details for the connected lcd panel using the
11 display timing details present in DT.
12
13 Ensure that platform data is present before checking whether platform
14 callback is present (the one used to control backlight). So far this
15 was not an issue as driver was purely non-DT triggered, but now DT
16 support has been added this check must be performed.
17
18 v2: squashing multiple commits from Afzal Mohammed (afzal@ti.com)
19 v3: remove superfluous cast
20 v4: expose both ti,am3352-lcdc and ti,da830-lcdc for .compatible
21 as driver can use enhanced features of all version of the
22 silicon block.
23 v5: addressed review comments from Prabhakar Lad
24 v6: Changed the .compatible naming to match the existing drm bindings
25 for am33xx devices
26 v7: clarify which compatible to use in the documentation for DA850
27
28 Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
29 Signed-off-by: Darren Etheridge <detheridge@ti.com>
30 ---
31 .../devicetree/bindings/video/da8xx-fb.txt | 42 +++++++++++++
32 drivers/video/da8xx-fb.c | 66 +++++++++++++++++++-
33 2 files changed, 105 insertions(+), 3 deletions(-)
34 create mode 100644 Documentation/devicetree/bindings/video/da8xx-fb.txt
35
36 --- /dev/null
37 +++ b/Documentation/devicetree/bindings/video/da8xx-fb.txt
38 @@ -0,0 +1,42 @@
39 +TI LCD Controller on DA830/DA850/AM335x SoC's
40 +
41 +Required properties:
42 +- compatible:
43 + DA830, DA850 - "ti,da8xx-tilcdc"
44 + AM335x SoC's - "ti,am33xx-tilcdc"
45 +- reg: Address range of lcdc register set
46 +- interrupts: lcdc interrupt
47 +- display-timings: typical videomode of lcd panel, represented as child.
48 + Refer Documentation/devicetree/bindings/video/display-timing.txt for
49 + display timing binding details. If multiple videomodes are mentioned
50 + in display timings node, typical videomode has to be mentioned as the
51 + native mode or it has to be first child (driver cares only for native
52 + videomode).
53 +
54 +Recommended properties:
55 +- ti,hwmods: Name of the hwmod associated to the LCDC
56 +
57 +Example for am335x SoC's:
58 +
59 +lcdc@4830e000 {
60 + compatible = "ti,am33xx-tilcdc";
61 + reg = <0x4830e000 0x1000>;
62 + interrupts = <36>;
63 + ti,hwmods = "lcdc";
64 + status = "okay";
65 + display-timings {
66 + 800x480p62 {
67 + clock-frequency = <30000000>;
68 + hactive = <800>;
69 + vactive = <480>;
70 + hfront-porch = <39>;
71 + hback-porch = <39>;
72 + hsync-len = <47>;
73 + vback-porch = <29>;
74 + vfront-porch = <13>;
75 + vsync-len = <2>;
76 + hsync-active = <1>;
77 + vsync-active = <1>;
78 + };
79 + };
80 +};
81 --- a/drivers/video/da8xx-fb.c
82 +++ b/drivers/video/da8xx-fb.c
83 @@ -36,6 +36,7 @@
84 #include <linux/slab.h>
85 #include <linux/delay.h>
86 #include <linux/lcm.h>
87 +#include <video/of_display_timing.h>
88 #include <video/da8xx-fb.h>
89 #include <asm/div64.h>
90
91 @@ -1311,12 +1312,54 @@ static struct fb_ops da8xx_fb_ops = {
92 .fb_blank = cfb_blank,
93 };
94
95 +static struct lcd_ctrl_config *da8xx_fb_create_cfg(struct platform_device *dev)
96 +{
97 + struct lcd_ctrl_config *cfg;
98 +
99 + cfg = devm_kzalloc(&dev->dev, sizeof(struct fb_videomode), GFP_KERNEL);
100 + if (!cfg)
101 + return NULL;
102 +
103 + /* default values */
104 +
105 + if (lcd_revision == LCD_VERSION_1)
106 + cfg->bpp = 16;
107 + else
108 + cfg->bpp = 32;
109 +
110 + /*
111 + * For panels so far used with this LCDC, below statement is sufficient.
112 + * For new panels, if required, struct lcd_ctrl_cfg fields to be updated
113 + * with additional/modified values. Those values would have to be then
114 + * obtained from dt(requiring new dt bindings).
115 + */
116 +
117 + cfg->panel_shade = COLOR_ACTIVE;
118 +
119 + return cfg;
120 +}
121 +
122 static struct fb_videomode *da8xx_fb_get_videomode(struct platform_device *dev)
123 {
124 struct da8xx_lcdc_platform_data *fb_pdata = dev_get_platdata(&dev->dev);
125 struct fb_videomode *lcdc_info;
126 + struct device_node *np = dev->dev.of_node;
127 int i;
128
129 + if (np) {
130 + lcdc_info = devm_kzalloc(&dev->dev,
131 + sizeof(struct fb_videomode),
132 + GFP_KERNEL);
133 + if (!lcdc_info)
134 + return NULL;
135 +
136 + if (of_get_fb_videomode(np, lcdc_info, OF_USE_NATIVE_MODE)) {
137 + dev_err(&dev->dev, "timings not available in DT\n");
138 + return NULL;
139 + }
140 + return lcdc_info;
141 + }
142 +
143 for (i = 0, lcdc_info = known_lcd_panels;
144 i < ARRAY_SIZE(known_lcd_panels); i++, lcdc_info++) {
145 if (strcmp(fb_pdata->type, lcdc_info->name) == 0)
146 @@ -1345,7 +1388,7 @@ static int fb_probe(struct platform_devi
147 int ret;
148 unsigned long ulcm;
149
150 - if (fb_pdata == NULL) {
151 + if (fb_pdata == NULL && !device->dev.of_node) {
152 dev_err(&device->dev, "Can not get platform data\n");
153 return -ENOENT;
154 }
155 @@ -1385,7 +1428,10 @@ static int fb_probe(struct platform_devi
156 break;
157 }
158
159 - lcd_cfg = (struct lcd_ctrl_config *)fb_pdata->controller_data;
160 + if (device->dev.of_node)
161 + lcd_cfg = da8xx_fb_create_cfg(device);
162 + else
163 + lcd_cfg = fb_pdata->controller_data;
164
165 if (!lcd_cfg) {
166 ret = -EINVAL;
167 @@ -1404,7 +1450,7 @@ static int fb_probe(struct platform_devi
168 par->dev = &device->dev;
169 par->lcdc_clk = tmp_lcdc_clk;
170 par->lcdc_clk_rate = clk_get_rate(par->lcdc_clk);
171 - if (fb_pdata->panel_power_ctrl) {
172 + if (fb_pdata && fb_pdata->panel_power_ctrl) {
173 par->panel_power_ctrl = fb_pdata->panel_power_ctrl;
174 par->panel_power_ctrl(1);
175 }
176 @@ -1652,6 +1698,19 @@ static int fb_resume(struct platform_dev
177 #define fb_resume NULL
178 #endif
179
180 +#if IS_ENABLED(CONFIG_OF)
181 +static const struct of_device_id da8xx_fb_of_match[] = {
182 + /*
183 + * this driver supports version 1 and version 2 of the
184 + * Texas Instruments lcd controller (lcdc) hardware block
185 + */
186 + {.compatible = "ti,da8xx-tilcdc", },
187 + {.compatible = "ti,am33xx-tilcdc", },
188 + {},
189 +};
190 +MODULE_DEVICE_TABLE(of, da8xx_fb_of_match);
191 +#endif
192 +
193 static struct platform_driver da8xx_fb_driver = {
194 .probe = fb_probe,
195 .remove = fb_remove,
196 @@ -1660,6 +1719,7 @@ static struct platform_driver da8xx_fb_d
197 .driver = {
198 .name = DRIVER_NAME,
199 .owner = THIS_MODULE,
200 + .of_match_table = of_match_ptr(da8xx_fb_of_match),
201 },
202 };
203 module_platform_driver(da8xx_fb_driver);