blob: 10745261be525fa95dadb870313d12c587f93c6e [file] [log] [blame]
Tomi Valkeinen553c48c2009-08-07 13:15:50 +03001/*
2 * linux/drivers/video/omap2/dss/dpi.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#define DSS_SUBSYS_NAME "DPI"
24
25#include <linux/kernel.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030026#include <linux/delay.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040027#include <linux/export.h>
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020028#include <linux/err.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030029#include <linux/errno.h>
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020030#include <linux/platform_device.h>
31#include <linux/regulator/consumer.h>
Tomi Valkeinen13b1ba72012-09-28 10:03:03 +030032#include <linux/string.h>
Tomi Valkeinen2ecef242013-12-16 15:13:24 +020033#include <linux/of.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030034
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030035#include <video/omapdss.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030036
37#include "dss.h"
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +053038#include "dss_features.h"
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030039
40static struct {
Tomi Valkeinen00df43b2013-03-19 11:33:52 +020041 struct platform_device *pdev;
42
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020043 struct regulator *vdds_dsi_reg;
Archit Tanejaa72b64b2011-05-12 17:26:26 +053044 struct platform_device *dsidev;
Archit Taneja5cf9a262012-06-29 14:19:13 +053045
Archit Tanejac8a5e4e2012-07-05 12:52:46 +053046 struct mutex lock;
47
Archit Tanejac4991442012-08-08 14:28:54 +053048 struct omap_video_timings timings;
Archit Taneja5cf9a262012-06-29 14:19:13 +053049 struct dss_lcd_mgr_config mgr_config;
Archit Tanejac6b393d2012-07-06 15:30:52 +053050 int data_lines;
Archit Taneja81b87f52012-09-26 16:30:49 +053051
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +030052 struct omap_dss_device output;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +020053
54 bool port_initialized;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030055} dpi;
56
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +030057static struct platform_device *dpi_get_dsidev(enum omap_channel channel)
Archit Tanejaa72b64b2011-05-12 17:26:26 +053058{
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020059 /*
60 * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL
61 * would also be used for DISPC fclk. Meaning, when the DPI output is
62 * disabled, DISPC clock will be disabled, and TV out will stop.
63 */
64 switch (omapdss_get_version()) {
65 case OMAPDSS_VER_OMAP24xx:
66 case OMAPDSS_VER_OMAP34xx_ES1:
67 case OMAPDSS_VER_OMAP34xx_ES3:
68 case OMAPDSS_VER_OMAP3630:
69 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +053070 case OMAPDSS_VER_AM43xx:
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020071 return NULL;
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020072
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +020073 case OMAPDSS_VER_OMAP4430_ES1:
74 case OMAPDSS_VER_OMAP4430_ES2:
75 case OMAPDSS_VER_OMAP4:
76 switch (channel) {
77 case OMAP_DSS_CHANNEL_LCD:
78 return dsi_get_dsidev_from_id(0);
79 case OMAP_DSS_CHANNEL_LCD2:
80 return dsi_get_dsidev_from_id(1);
81 default:
82 return NULL;
83 }
84
85 case OMAPDSS_VER_OMAP5:
86 switch (channel) {
87 case OMAP_DSS_CHANNEL_LCD:
88 return dsi_get_dsidev_from_id(0);
89 case OMAP_DSS_CHANNEL_LCD3:
90 return dsi_get_dsidev_from_id(1);
91 default:
92 return NULL;
93 }
94
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +030095 default:
96 return NULL;
97 }
Archit Tanejaa72b64b2011-05-12 17:26:26 +053098}
99
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300100static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel)
Archit Taneja7636b3b2011-04-12 13:52:26 +0530101{
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300102 switch (channel) {
103 case OMAP_DSS_CHANNEL_LCD:
104 return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC;
105 case OMAP_DSS_CHANNEL_LCD2:
106 return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
107 default:
108 /* this shouldn't happen */
109 WARN_ON(1);
110 return OMAP_DSS_CLK_SRC_FCK;
111 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530112}
113
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200114struct dpi_clk_calc_ctx {
115 struct platform_device *dsidev;
116
117 /* inputs */
118
119 unsigned long pck_min, pck_max;
120
121 /* outputs */
122
123 struct dsi_clock_info dsi_cinfo;
Tomi Valkeinenc56812f2014-01-28 08:50:47 +0200124 unsigned long fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200125 struct dispc_clock_info dispc_cinfo;
126};
127
128static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
129 unsigned long pck, void *data)
130{
131 struct dpi_clk_calc_ctx *ctx = data;
132
133 /*
134 * Odd dividers give us uneven duty cycle, causing problem when level
135 * shifted. So skip all odd dividers when the pixel clock is on the
136 * higher side.
137 */
Tomi Valkeinen72e55122013-06-12 09:44:52 +0300138 if (ctx->pck_min >= 100000000) {
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200139 if (lckd > 1 && lckd % 2 != 0)
140 return false;
141
142 if (pckd > 1 && pckd % 2 != 0)
143 return false;
144 }
145
146 ctx->dispc_cinfo.lck_div = lckd;
147 ctx->dispc_cinfo.pck_div = pckd;
148 ctx->dispc_cinfo.lck = lck;
149 ctx->dispc_cinfo.pck = pck;
150
151 return true;
152}
153
154
155static bool dpi_calc_hsdiv_cb(int regm_dispc, unsigned long dispc,
156 void *data)
157{
158 struct dpi_clk_calc_ctx *ctx = data;
159
160 /*
161 * Odd dividers give us uneven duty cycle, causing problem when level
162 * shifted. So skip all odd dividers when the pixel clock is on the
163 * higher side.
164 */
Tomi Valkeinen72e55122013-06-12 09:44:52 +0300165 if (regm_dispc > 1 && regm_dispc % 2 != 0 && ctx->pck_min >= 100000000)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200166 return false;
167
168 ctx->dsi_cinfo.regm_dispc = regm_dispc;
169 ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc;
170
171 return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max,
172 dpi_calc_dispc_cb, ctx);
173}
174
175
176static bool dpi_calc_pll_cb(int regn, int regm, unsigned long fint,
177 unsigned long pll,
178 void *data)
179{
180 struct dpi_clk_calc_ctx *ctx = data;
181
182 ctx->dsi_cinfo.regn = regn;
183 ctx->dsi_cinfo.regm = regm;
184 ctx->dsi_cinfo.fint = fint;
185 ctx->dsi_cinfo.clkin4ddr = pll;
186
187 return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->pck_min,
188 dpi_calc_hsdiv_cb, ctx);
189}
190
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200191static bool dpi_calc_dss_cb(unsigned long fck, void *data)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200192{
193 struct dpi_clk_calc_ctx *ctx = data;
194
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200195 ctx->fck = fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200196
197 return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max,
198 dpi_calc_dispc_cb, ctx);
199}
200
201static bool dpi_dsi_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx)
202{
203 unsigned long clkin;
204 unsigned long pll_min, pll_max;
205
206 clkin = dsi_get_pll_clkin(dpi.dsidev);
207
208 memset(ctx, 0, sizeof(*ctx));
209 ctx->dsidev = dpi.dsidev;
210 ctx->pck_min = pck - 1000;
211 ctx->pck_max = pck + 1000;
212 ctx->dsi_cinfo.clkin = clkin;
213
214 pll_min = 0;
215 pll_max = 0;
216
217 return dsi_pll_calc(dpi.dsidev, clkin,
218 pll_min, pll_max,
219 dpi_calc_pll_cb, ctx);
220}
221
222static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx)
223{
224 int i;
225
226 /*
227 * DSS fck gives us very few possibilities, so finding a good pixel
228 * clock may not be possible. We try multiple times to find the clock,
229 * each time widening the pixel clock range we look for, up to
Tomi Valkeinen2c6360f2013-04-10 14:54:54 +0300230 * +/- ~15MHz.
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200231 */
232
Tomi Valkeinen2c6360f2013-04-10 14:54:54 +0300233 for (i = 0; i < 25; ++i) {
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200234 bool ok;
235
236 memset(ctx, 0, sizeof(*ctx));
237 if (pck > 1000 * i * i * i)
238 ctx->pck_min = max(pck - 1000 * i * i * i, 0lu);
239 else
240 ctx->pck_min = 0;
241 ctx->pck_max = pck + 1000 * i * i * i;
242
Tomi Valkeinen688af022013-10-31 16:41:57 +0200243 ok = dss_div_calc(pck, ctx->pck_min, dpi_calc_dss_cb, ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200244 if (ok)
245 return ok;
246 }
247
248 return false;
249}
250
251
252
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200253static int dpi_set_dsi_clk(enum omap_channel channel,
Sumit Semwalff1b2cde2010-12-02 11:27:11 +0000254 unsigned long pck_req, unsigned long *fck, int *lck_div,
255 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300256{
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200257 struct dpi_clk_calc_ctx ctx;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300258 int r;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200259 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300260
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200261 ok = dpi_dsi_clk_calc(pck_req, &ctx);
262 if (!ok)
263 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300264
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200265 r = dsi_pll_set_clock_div(dpi.dsidev, &ctx.dsi_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300266 if (r)
267 return r;
268
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200269 dss_select_lcd_clk_source(channel,
270 dpi_get_alt_clk_src(channel));
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300271
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200272 dpi.mgr_config.clock_info = ctx.dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300273
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200274 *fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
275 *lck_div = ctx.dispc_cinfo.lck_div;
276 *pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300277
278 return 0;
279}
Archit Taneja7636b3b2011-04-12 13:52:26 +0530280
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200281static int dpi_set_dispc_clk(unsigned long pck_req, unsigned long *fck,
282 int *lck_div, int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300283{
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200284 struct dpi_clk_calc_ctx ctx;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300285 int r;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200286 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300287
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200288 ok = dpi_dss_clk_calc(pck_req, &ctx);
289 if (!ok)
290 return -EINVAL;
291
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200292 r = dss_set_fck_rate(ctx.fck);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300293 if (r)
294 return r;
295
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200296 dpi.mgr_config.clock_info = ctx.dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300297
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200298 *fck = ctx.fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200299 *lck_div = ctx.dispc_cinfo.lck_div;
300 *pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300301
302 return 0;
303}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300304
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200305static int dpi_set_mode(struct omap_overlay_manager *mgr)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300306{
Archit Tanejac4991442012-08-08 14:28:54 +0530307 struct omap_video_timings *t = &dpi.timings;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530308 int lck_div = 0, pck_div = 0;
309 unsigned long fck = 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300310 unsigned long pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300311 int r = 0;
312
Tomi Valkeinen8a3db402012-10-22 16:03:39 +0300313 if (dpi.dsidev)
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300314 r = dpi_set_dsi_clk(mgr->id, t->pixelclock, &fck,
Archit Taneja6d523e72012-06-21 09:33:55 +0530315 &lck_div, &pck_div);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530316 else
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300317 r = dpi_set_dispc_clk(t->pixelclock, &fck,
Archit Taneja6d523e72012-06-21 09:33:55 +0530318 &lck_div, &pck_div);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300319 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300320 return r;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300321
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300322 pck = fck / lck_div / pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300323
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300324 if (pck != t->pixelclock) {
325 DSSWARN("Could not find exact pixel clock. Requested %d Hz, got %lu Hz\n",
326 t->pixelclock, pck);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300327
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300328 t->pixelclock = pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300329 }
330
Archit Taneja5d512fc2012-09-07 17:53:38 +0530331 dss_mgr_set_timings(mgr, t);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300332
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300333 return 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300334}
335
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200336static void dpi_config_lcd_manager(struct omap_overlay_manager *mgr)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300337{
Archit Taneja5cf9a262012-06-29 14:19:13 +0530338 dpi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
Archit Taneja569969d2011-08-22 17:41:57 +0530339
Archit Taneja5cf9a262012-06-29 14:19:13 +0530340 dpi.mgr_config.stallmode = false;
341 dpi.mgr_config.fifohandcheck = false;
342
Archit Tanejac6b393d2012-07-06 15:30:52 +0530343 dpi.mgr_config.video_port_width = dpi.data_lines;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530344
345 dpi.mgr_config.lcden_sig_polarity = 0;
346
Archit Taneja5d512fc2012-09-07 17:53:38 +0530347 dss_mgr_set_lcd_config(mgr, &dpi.mgr_config);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300348}
349
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300350static int dpi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300351{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300352 struct omap_dss_device *out = &dpi.output;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300353 int r;
354
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530355 mutex_lock(&dpi.lock);
356
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530357 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi.vdds_dsi_reg) {
Russell King40410712012-02-07 09:44:55 +0000358 DSSERR("no VDSS_DSI regulator\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530359 r = -ENODEV;
360 goto err_no_reg;
Russell King40410712012-02-07 09:44:55 +0000361 }
362
Archit Taneja5d512fc2012-09-07 17:53:38 +0530363 if (out == NULL || out->manager == NULL) {
364 DSSERR("failed to enable display: no output/manager\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530365 r = -ENODEV;
Archit Taneja5d512fc2012-09-07 17:53:38 +0530366 goto err_no_out_mgr;
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300367 }
368
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530369 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) {
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200370 r = regulator_enable(dpi.vdds_dsi_reg);
371 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300372 goto err_reg_enable;
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200373 }
374
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300375 r = dispc_runtime_get();
376 if (r)
377 goto err_get_dispc;
378
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200379 r = dss_dpi_select_source(out->manager->id);
Tomi Valkeinende09e452012-09-21 12:09:54 +0300380 if (r)
381 goto err_src_sel;
382
Tomi Valkeinen8a3db402012-10-22 16:03:39 +0300383 if (dpi.dsidev) {
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300384 r = dsi_runtime_get(dpi.dsidev);
385 if (r)
386 goto err_get_dsi;
387
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530388 r = dsi_pll_init(dpi.dsidev, 0, 1);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530389 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300390 goto err_dsi_pll_init;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530391 }
392
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200393 r = dpi_set_mode(out->manager);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300394 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300395 goto err_set_mode;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300396
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200397 dpi_config_lcd_manager(out->manager);
Archit Taneja5cf9a262012-06-29 14:19:13 +0530398
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300399 mdelay(2);
400
Archit Taneja5d512fc2012-09-07 17:53:38 +0530401 r = dss_mgr_enable(out->manager);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200402 if (r)
403 goto err_mgr_enable;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300404
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530405 mutex_unlock(&dpi.lock);
406
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300407 return 0;
408
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200409err_mgr_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300410err_set_mode:
Tomi Valkeinen8a3db402012-10-22 16:03:39 +0300411 if (dpi.dsidev)
Tomi Valkeinen19077a72011-05-18 11:33:44 +0300412 dsi_pll_uninit(dpi.dsidev, true);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300413err_dsi_pll_init:
Tomi Valkeinen8a3db402012-10-22 16:03:39 +0300414 if (dpi.dsidev)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300415 dsi_runtime_put(dpi.dsidev);
416err_get_dsi:
Tomi Valkeinende09e452012-09-21 12:09:54 +0300417err_src_sel:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300418 dispc_runtime_put();
419err_get_dispc:
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530420 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200421 regulator_disable(dpi.vdds_dsi_reg);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300422err_reg_enable:
Archit Taneja5d512fc2012-09-07 17:53:38 +0530423err_no_out_mgr:
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530424err_no_reg:
425 mutex_unlock(&dpi.lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300426 return r;
427}
428
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300429static void dpi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300430{
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200431 struct omap_overlay_manager *mgr = dpi.output.manager;
Archit Taneja5d512fc2012-09-07 17:53:38 +0530432
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530433 mutex_lock(&dpi.lock);
434
Archit Taneja5d512fc2012-09-07 17:53:38 +0530435 dss_mgr_disable(mgr);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300436
Tomi Valkeinen8a3db402012-10-22 16:03:39 +0300437 if (dpi.dsidev) {
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300438 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530439 dsi_pll_uninit(dpi.dsidev, true);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300440 dsi_runtime_put(dpi.dsidev);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530441 }
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300442
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300443 dispc_runtime_put();
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300444
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530445 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200446 regulator_disable(dpi.vdds_dsi_reg);
447
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530448 mutex_unlock(&dpi.lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300449}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300450
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300451static void dpi_set_timings(struct omap_dss_device *dssdev,
Archit Tanejac4991442012-08-08 14:28:54 +0530452 struct omap_video_timings *timings)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300453{
454 DSSDBG("dpi_set_timings\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530455
456 mutex_lock(&dpi.lock);
457
Archit Tanejac4991442012-08-08 14:28:54 +0530458 dpi.timings = *timings;
Archit Tanejac4991442012-08-08 14:28:54 +0530459
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530460 mutex_unlock(&dpi.lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300461}
462
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300463static void dpi_get_timings(struct omap_dss_device *dssdev,
464 struct omap_video_timings *timings)
465{
466 mutex_lock(&dpi.lock);
467
468 *timings = dpi.timings;
469
470 mutex_unlock(&dpi.lock);
471}
472
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300473static int dpi_check_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300474 struct omap_video_timings *timings)
475{
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200476 struct omap_overlay_manager *mgr = dpi.output.manager;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300477 int lck_div, pck_div;
478 unsigned long fck;
479 unsigned long pck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200480 struct dpi_clk_calc_ctx ctx;
481 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300482
Tomi Valkeinen8b095512012-10-24 13:27:02 +0300483 if (mgr && !dispc_mgr_timings_ok(mgr->id, timings))
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300484 return -EINVAL;
485
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300486 if (timings->pixelclock == 0)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300487 return -EINVAL;
488
Tomi Valkeinen8a3db402012-10-22 16:03:39 +0300489 if (dpi.dsidev) {
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300490 ok = dpi_dsi_clk_calc(timings->pixelclock, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200491 if (!ok)
492 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300493
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200494 fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530495 } else {
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300496 ok = dpi_dss_clk_calc(timings->pixelclock, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200497 if (!ok)
498 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300499
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200500 fck = ctx.fck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300501 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530502
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200503 lck_div = ctx.dispc_cinfo.lck_div;
504 pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300505
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300506 pck = fck / lck_div / pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300507
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300508 timings->pixelclock = pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300509
510 return 0;
511}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300512
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300513static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
Archit Tanejac6b393d2012-07-06 15:30:52 +0530514{
515 mutex_lock(&dpi.lock);
516
517 dpi.data_lines = data_lines;
518
519 mutex_unlock(&dpi.lock);
520}
Archit Tanejac6b393d2012-07-06 15:30:52 +0530521
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300522static int dpi_verify_dsi_pll(struct platform_device *dsidev)
Tomi Valkeinen60616752012-10-30 12:57:43 +0200523{
524 int r;
525
526 /* do initial setup with the PLL to see if it is operational */
527
528 r = dsi_runtime_get(dsidev);
529 if (r)
530 return r;
531
532 r = dsi_pll_init(dsidev, 0, 1);
533 if (r) {
534 dsi_runtime_put(dsidev);
535 return r;
536 }
537
538 dsi_pll_uninit(dsidev, true);
539 dsi_runtime_put(dsidev);
540
541 return 0;
542}
543
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300544static int dpi_init_regulator(void)
545{
546 struct regulator *vdds_dsi;
547
548 if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
549 return 0;
550
551 if (dpi.vdds_dsi_reg)
552 return 0;
553
Tomi Valkeinen4123de22013-08-29 10:06:55 +0300554 vdds_dsi = devm_regulator_get(&dpi.pdev->dev, "vdds_dsi");
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300555 if (IS_ERR(vdds_dsi)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +0200556 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
557 DSSERR("can't get VDDS_DSI regulator\n");
Tomi Valkeinen4123de22013-08-29 10:06:55 +0300558 return PTR_ERR(vdds_dsi);
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300559 }
560
561 dpi.vdds_dsi_reg = vdds_dsi;
562
563 return 0;
564}
565
566static void dpi_init_pll(void)
567{
568 struct platform_device *dsidev;
569
570 if (dpi.dsidev)
571 return;
572
573 dsidev = dpi_get_dsidev(dpi.output.dispc_channel);
574 if (!dsidev)
575 return;
576
577 if (dpi_verify_dsi_pll(dsidev)) {
578 DSSWARN("DSI PLL not operational\n");
579 return;
580 }
581
582 dpi.dsidev = dsidev;
583}
584
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200585/*
586 * Return a hardcoded channel for the DPI output. This should work for
587 * current use cases, but this can be later expanded to either resolve
588 * the channel in some more dynamic manner, or get the channel as a user
589 * parameter.
590 */
591static enum omap_channel dpi_get_channel(void)
592{
593 switch (omapdss_get_version()) {
594 case OMAPDSS_VER_OMAP24xx:
595 case OMAPDSS_VER_OMAP34xx_ES1:
596 case OMAPDSS_VER_OMAP34xx_ES3:
597 case OMAPDSS_VER_OMAP3630:
598 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +0530599 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200600 return OMAP_DSS_CHANNEL_LCD;
601
602 case OMAPDSS_VER_OMAP4430_ES1:
603 case OMAPDSS_VER_OMAP4430_ES2:
604 case OMAPDSS_VER_OMAP4:
605 return OMAP_DSS_CHANNEL_LCD2;
606
607 case OMAPDSS_VER_OMAP5:
608 return OMAP_DSS_CHANNEL_LCD3;
609
610 default:
611 DSSWARN("unsupported DSS version\n");
612 return OMAP_DSS_CHANNEL_LCD;
613 }
614}
615
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300616static int dpi_connect(struct omap_dss_device *dssdev,
617 struct omap_dss_device *dst)
618{
619 struct omap_overlay_manager *mgr;
620 int r;
621
622 r = dpi_init_regulator();
623 if (r)
624 return r;
625
626 dpi_init_pll();
627
628 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
629 if (!mgr)
630 return -ENODEV;
631
632 r = dss_mgr_connect(mgr, dssdev);
633 if (r)
634 return r;
635
636 r = omapdss_output_set_device(dssdev, dst);
637 if (r) {
638 DSSERR("failed to connect output to new device: %s\n",
639 dst->name);
640 dss_mgr_disconnect(mgr, dssdev);
641 return r;
642 }
643
644 return 0;
645}
646
647static void dpi_disconnect(struct omap_dss_device *dssdev,
648 struct omap_dss_device *dst)
649{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300650 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300651
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300652 if (dst != dssdev->dst)
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300653 return;
654
655 omapdss_output_unset_device(dssdev);
656
657 if (dssdev->manager)
658 dss_mgr_disconnect(dssdev->manager, dssdev);
659}
660
661static const struct omapdss_dpi_ops dpi_ops = {
662 .connect = dpi_connect,
663 .disconnect = dpi_disconnect,
664
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300665 .enable = dpi_display_enable,
666 .disable = dpi_display_disable,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300667
668 .check_timings = dpi_check_timings,
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300669 .set_timings = dpi_set_timings,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300670 .get_timings = dpi_get_timings,
671
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300672 .set_data_lines = dpi_set_data_lines,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300673};
674
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300675static void dpi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530676{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300677 struct omap_dss_device *out = &dpi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530678
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300679 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530680 out->id = OMAP_DSS_OUTPUT_DPI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300681 out->output_type = OMAP_DISPLAY_TYPE_DPI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200682 out->name = "dpi.0";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200683 out->dispc_channel = dpi_get_channel();
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300684 out->ops.dpi = &dpi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300685 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530686
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300687 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530688}
689
690static void __exit dpi_uninit_output(struct platform_device *pdev)
691{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300692 struct omap_dss_device *out = &dpi.output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530693
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300694 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530695}
696
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300697static int omap_dpi_probe(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300698{
Tomi Valkeinen00df43b2013-03-19 11:33:52 +0200699 dpi.pdev = pdev;
700
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530701 mutex_init(&dpi.lock);
702
Archit Taneja81b87f52012-09-26 16:30:49 +0530703 dpi_init_output(pdev);
704
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300705 return 0;
706}
707
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200708static int __exit omap_dpi_remove(struct platform_device *pdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300709{
Archit Taneja81b87f52012-09-26 16:30:49 +0530710 dpi_uninit_output(pdev);
711
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200712 return 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300713}
714
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200715static struct platform_driver omap_dpi_driver = {
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300716 .probe = omap_dpi_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200717 .remove = __exit_p(omap_dpi_remove),
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200718 .driver = {
719 .name = "omapdss_dpi",
720 .owner = THIS_MODULE,
721 },
722};
723
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200724int __init dpi_init_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200725{
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300726 return platform_driver_register(&omap_dpi_driver);
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200727}
728
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200729void __exit dpi_uninit_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200730{
731 platform_driver_unregister(&omap_dpi_driver);
732}
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200733
734int __init dpi_init_port(struct platform_device *pdev, struct device_node *port)
735{
736 struct device_node *ep;
737 u32 datalines;
738 int r;
739
740 ep = omapdss_of_get_next_endpoint(port, NULL);
741 if (!ep)
742 return 0;
743
744 r = of_property_read_u32(ep, "data-lines", &datalines);
745 if (r) {
746 DSSERR("failed to parse datalines\n");
747 goto err_datalines;
748 }
749
750 dpi.data_lines = datalines;
751
752 of_node_put(ep);
753
754 dpi.pdev = pdev;
755
756 mutex_init(&dpi.lock);
757
758 dpi_init_output(pdev);
759
760 dpi.port_initialized = true;
761
762 return 0;
763
764err_datalines:
765 of_node_put(ep);
766
767 return r;
768}
769
770void __exit dpi_uninit_port(void)
771{
772 if (!dpi.port_initialized)
773 return;
774
775 dpi_uninit_output(dpi.pdev);
776}