blob: f83e7b030249dd49727e0f081b732cf28a62ee9f [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 Valkeinen2daea7a2014-10-22 14:49:14 +030034#include <linux/clk.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030035
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030036#include <video/omapdss.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030037
38#include "dss.h"
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +053039#include "dss_features.h"
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030040
Tomi Valkeinenacf604b2014-11-07 13:13:24 +020041#define HSDIV_DISPC 0
42
Archit Taneja630d2d02014-05-30 16:26:22 +053043struct dpi_data {
Tomi Valkeinen00df43b2013-03-19 11:33:52 +020044 struct platform_device *pdev;
45
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020046 struct regulator *vdds_dsi_reg;
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +030047 struct dss_pll *pll;
Archit Taneja5cf9a262012-06-29 14:19:13 +053048
Archit Tanejac8a5e4e2012-07-05 12:52:46 +053049 struct mutex lock;
50
Archit Tanejac4991442012-08-08 14:28:54 +053051 struct omap_video_timings timings;
Archit Taneja5cf9a262012-06-29 14:19:13 +053052 struct dss_lcd_mgr_config mgr_config;
Archit Tanejac6b393d2012-07-06 15:30:52 +053053 int data_lines;
Archit Taneja81b87f52012-09-26 16:30:49 +053054
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +030055 struct omap_dss_device output;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +020056
57 bool port_initialized;
Archit Taneja630d2d02014-05-30 16:26:22 +053058};
59
Archit Taneja2ac6a1a2014-06-01 12:47:44 +053060static struct dpi_data *dpi_get_data_from_dssdev(struct omap_dss_device *dssdev)
61{
62 return container_of(dssdev, struct dpi_data, output);
63}
64
Archit Taneja80eb6752014-06-02 14:11:51 +053065/* only used in non-DT mode */
Archit Taneja2ac6a1a2014-06-01 12:47:44 +053066static struct dpi_data *dpi_get_data_from_pdev(struct platform_device *pdev)
67{
68 return dev_get_drvdata(&pdev->dev);
69}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030070
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +030071static struct dss_pll *dpi_get_pll(enum omap_channel channel)
Archit Tanejaa72b64b2011-05-12 17:26:26 +053072{
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020073 /*
74 * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL
75 * would also be used for DISPC fclk. Meaning, when the DPI output is
76 * disabled, DISPC clock will be disabled, and TV out will stop.
77 */
78 switch (omapdss_get_version()) {
79 case OMAPDSS_VER_OMAP24xx:
80 case OMAPDSS_VER_OMAP34xx_ES1:
81 case OMAPDSS_VER_OMAP34xx_ES3:
82 case OMAPDSS_VER_OMAP3630:
83 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +053084 case OMAPDSS_VER_AM43xx:
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020085 return NULL;
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020086
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +020087 case OMAPDSS_VER_OMAP4430_ES1:
88 case OMAPDSS_VER_OMAP4430_ES2:
89 case OMAPDSS_VER_OMAP4:
90 switch (channel) {
91 case OMAP_DSS_CHANNEL_LCD:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +030092 return dss_pll_find("dsi0");
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +020093 case OMAP_DSS_CHANNEL_LCD2:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +030094 return dss_pll_find("dsi1");
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +020095 default:
96 return NULL;
97 }
98
99 case OMAPDSS_VER_OMAP5:
100 switch (channel) {
101 case OMAP_DSS_CHANNEL_LCD:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300102 return dss_pll_find("dsi0");
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +0200103 case OMAP_DSS_CHANNEL_LCD3:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300104 return dss_pll_find("dsi1");
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +0200105 default:
106 return NULL;
107 }
108
Tomi Valkeinena2408152014-12-31 11:26:06 +0200109 case OMAPDSS_VER_DRA7xx:
110 switch (channel) {
111 case OMAP_DSS_CHANNEL_LCD:
112 case OMAP_DSS_CHANNEL_LCD2:
113 return dss_pll_find("video0");
114 case OMAP_DSS_CHANNEL_LCD3:
115 return dss_pll_find("video1");
116 default:
117 return NULL;
118 }
119
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300120 default:
121 return NULL;
122 }
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530123}
124
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300125static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel)
Archit Taneja7636b3b2011-04-12 13:52:26 +0530126{
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300127 switch (channel) {
128 case OMAP_DSS_CHANNEL_LCD:
129 return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC;
130 case OMAP_DSS_CHANNEL_LCD2:
131 return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
Tomi Valkeinen35fd32d2014-04-17 13:57:21 +0300132 case OMAP_DSS_CHANNEL_LCD3:
133 return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300134 default:
135 /* this shouldn't happen */
136 WARN_ON(1);
137 return OMAP_DSS_CLK_SRC_FCK;
138 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530139}
140
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200141struct dpi_clk_calc_ctx {
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300142 struct dss_pll *pll;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200143
144 /* inputs */
145
146 unsigned long pck_min, pck_max;
147
148 /* outputs */
149
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300150 struct dss_pll_clock_info dsi_cinfo;
Tomi Valkeinenc56812f2014-01-28 08:50:47 +0200151 unsigned long fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200152 struct dispc_clock_info dispc_cinfo;
153};
154
155static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
156 unsigned long pck, 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 (ctx->pck_min >= 100000000) {
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200166 if (lckd > 1 && lckd % 2 != 0)
167 return false;
168
169 if (pckd > 1 && pckd % 2 != 0)
170 return false;
171 }
172
173 ctx->dispc_cinfo.lck_div = lckd;
174 ctx->dispc_cinfo.pck_div = pckd;
175 ctx->dispc_cinfo.lck = lck;
176 ctx->dispc_cinfo.pck = pck;
177
178 return true;
179}
180
181
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300182static bool dpi_calc_hsdiv_cb(int m_dispc, unsigned long dispc,
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200183 void *data)
184{
185 struct dpi_clk_calc_ctx *ctx = data;
186
187 /*
188 * Odd dividers give us uneven duty cycle, causing problem when level
189 * shifted. So skip all odd dividers when the pixel clock is on the
190 * higher side.
191 */
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300192 if (m_dispc > 1 && m_dispc % 2 != 0 && ctx->pck_min >= 100000000)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200193 return false;
194
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300195 ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc;
Tomi Valkeinenacf604b2014-11-07 13:13:24 +0200196 ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200197
198 return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max,
199 dpi_calc_dispc_cb, ctx);
200}
201
202
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300203static bool dpi_calc_pll_cb(int n, int m, unsigned long fint,
204 unsigned long clkdco,
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200205 void *data)
206{
207 struct dpi_clk_calc_ctx *ctx = data;
208
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300209 ctx->dsi_cinfo.n = n;
210 ctx->dsi_cinfo.m = m;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200211 ctx->dsi_cinfo.fint = fint;
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300212 ctx->dsi_cinfo.clkdco = clkdco;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200213
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300214 return dss_pll_hsdiv_calc(ctx->pll, clkdco,
215 ctx->pck_min, dss_feat_get_param_max(FEAT_PARAM_DSS_FCK),
216 dpi_calc_hsdiv_cb, ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200217}
218
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200219static bool dpi_calc_dss_cb(unsigned long fck, void *data)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200220{
221 struct dpi_clk_calc_ctx *ctx = data;
222
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200223 ctx->fck = fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200224
225 return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max,
226 dpi_calc_dispc_cb, ctx);
227}
228
Archit Taneja630d2d02014-05-30 16:26:22 +0530229static bool dpi_dsi_clk_calc(struct dpi_data *dpi, unsigned long pck,
230 struct dpi_clk_calc_ctx *ctx)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200231{
232 unsigned long clkin;
233 unsigned long pll_min, pll_max;
234
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200235 memset(ctx, 0, sizeof(*ctx));
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300236 ctx->pll = dpi->pll;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200237 ctx->pck_min = pck - 1000;
238 ctx->pck_max = pck + 1000;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200239
240 pll_min = 0;
241 pll_max = 0;
242
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300243 clkin = clk_get_rate(ctx->pll->clkin);
244
245 return dss_pll_calc(ctx->pll, clkin,
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200246 pll_min, pll_max,
247 dpi_calc_pll_cb, ctx);
248}
249
250static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx)
251{
252 int i;
253
254 /*
255 * DSS fck gives us very few possibilities, so finding a good pixel
256 * clock may not be possible. We try multiple times to find the clock,
257 * each time widening the pixel clock range we look for, up to
Tomi Valkeinen2c6360f2013-04-10 14:54:54 +0300258 * +/- ~15MHz.
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200259 */
260
Tomi Valkeinen2c6360f2013-04-10 14:54:54 +0300261 for (i = 0; i < 25; ++i) {
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200262 bool ok;
263
264 memset(ctx, 0, sizeof(*ctx));
265 if (pck > 1000 * i * i * i)
266 ctx->pck_min = max(pck - 1000 * i * i * i, 0lu);
267 else
268 ctx->pck_min = 0;
269 ctx->pck_max = pck + 1000 * i * i * i;
270
Tomi Valkeinen688af022013-10-31 16:41:57 +0200271 ok = dss_div_calc(pck, ctx->pck_min, dpi_calc_dss_cb, ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200272 if (ok)
273 return ok;
274 }
275
276 return false;
277}
278
279
280
Archit Taneja630d2d02014-05-30 16:26:22 +0530281static int dpi_set_dsi_clk(struct dpi_data *dpi, enum omap_channel channel,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000282 unsigned long pck_req, unsigned long *fck, int *lck_div,
283 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300284{
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200285 struct dpi_clk_calc_ctx ctx;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300286 int r;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200287 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300288
Archit Taneja630d2d02014-05-30 16:26:22 +0530289 ok = dpi_dsi_clk_calc(dpi, pck_req, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200290 if (!ok)
291 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300292
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300293 r = dss_pll_set_config(dpi->pll, &ctx.dsi_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300294 if (r)
295 return r;
296
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200297 dss_select_lcd_clk_source(channel,
298 dpi_get_alt_clk_src(channel));
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300299
Archit Taneja630d2d02014-05-30 16:26:22 +0530300 dpi->mgr_config.clock_info = ctx.dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300301
Tomi Valkeinenacf604b2014-11-07 13:13:24 +0200302 *fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200303 *lck_div = ctx.dispc_cinfo.lck_div;
304 *pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300305
306 return 0;
307}
Archit Taneja7636b3b2011-04-12 13:52:26 +0530308
Archit Taneja630d2d02014-05-30 16:26:22 +0530309static int dpi_set_dispc_clk(struct dpi_data *dpi, unsigned long pck_req,
310 unsigned long *fck, int *lck_div, int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300311{
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200312 struct dpi_clk_calc_ctx ctx;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300313 int r;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200314 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300315
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200316 ok = dpi_dss_clk_calc(pck_req, &ctx);
317 if (!ok)
318 return -EINVAL;
319
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200320 r = dss_set_fck_rate(ctx.fck);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300321 if (r)
322 return r;
323
Archit Taneja630d2d02014-05-30 16:26:22 +0530324 dpi->mgr_config.clock_info = ctx.dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300325
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200326 *fck = ctx.fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200327 *lck_div = ctx.dispc_cinfo.lck_div;
328 *pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300329
330 return 0;
331}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300332
Archit Taneja630d2d02014-05-30 16:26:22 +0530333static int dpi_set_mode(struct dpi_data *dpi)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300334{
Archit Taneja630d2d02014-05-30 16:26:22 +0530335 struct omap_dss_device *out = &dpi->output;
336 struct omap_overlay_manager *mgr = out->manager;
337 struct omap_video_timings *t = &dpi->timings;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530338 int lck_div = 0, pck_div = 0;
339 unsigned long fck = 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300340 unsigned long pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300341 int r = 0;
342
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300343 if (dpi->pll)
Archit Taneja630d2d02014-05-30 16:26:22 +0530344 r = dpi_set_dsi_clk(dpi, mgr->id, t->pixelclock, &fck,
Archit Taneja6d523e72012-06-21 09:33:55 +0530345 &lck_div, &pck_div);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530346 else
Archit Taneja630d2d02014-05-30 16:26:22 +0530347 r = dpi_set_dispc_clk(dpi, t->pixelclock, &fck,
Archit Taneja6d523e72012-06-21 09:33:55 +0530348 &lck_div, &pck_div);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300349 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300350 return r;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300351
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300352 pck = fck / lck_div / pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300353
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300354 if (pck != t->pixelclock) {
355 DSSWARN("Could not find exact pixel clock. Requested %d Hz, got %lu Hz\n",
356 t->pixelclock, pck);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300357
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300358 t->pixelclock = pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300359 }
360
Archit Taneja5d512fc2012-09-07 17:53:38 +0530361 dss_mgr_set_timings(mgr, t);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300362
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300363 return 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300364}
365
Archit Taneja630d2d02014-05-30 16:26:22 +0530366static void dpi_config_lcd_manager(struct dpi_data *dpi)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300367{
Archit Taneja630d2d02014-05-30 16:26:22 +0530368 struct omap_dss_device *out = &dpi->output;
369 struct omap_overlay_manager *mgr = out->manager;
Archit Taneja569969d2011-08-22 17:41:57 +0530370
Archit Taneja630d2d02014-05-30 16:26:22 +0530371 dpi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530372
Archit Taneja630d2d02014-05-30 16:26:22 +0530373 dpi->mgr_config.stallmode = false;
374 dpi->mgr_config.fifohandcheck = false;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530375
Archit Taneja630d2d02014-05-30 16:26:22 +0530376 dpi->mgr_config.video_port_width = dpi->data_lines;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530377
Archit Taneja630d2d02014-05-30 16:26:22 +0530378 dpi->mgr_config.lcden_sig_polarity = 0;
379
380 dss_mgr_set_lcd_config(mgr, &dpi->mgr_config);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300381}
382
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300383static int dpi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300384{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530385 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530386 struct omap_dss_device *out = &dpi->output;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300387 int r;
388
Archit Taneja630d2d02014-05-30 16:26:22 +0530389 mutex_lock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530390
Archit Taneja630d2d02014-05-30 16:26:22 +0530391 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi->vdds_dsi_reg) {
Russell King40410712012-02-07 09:44:55 +0000392 DSSERR("no VDSS_DSI regulator\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530393 r = -ENODEV;
394 goto err_no_reg;
Russell King40410712012-02-07 09:44:55 +0000395 }
396
Archit Taneja5d512fc2012-09-07 17:53:38 +0530397 if (out == NULL || out->manager == NULL) {
398 DSSERR("failed to enable display: no output/manager\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530399 r = -ENODEV;
Archit Taneja5d512fc2012-09-07 17:53:38 +0530400 goto err_no_out_mgr;
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300401 }
402
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530403 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) {
Archit Taneja630d2d02014-05-30 16:26:22 +0530404 r = regulator_enable(dpi->vdds_dsi_reg);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200405 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300406 goto err_reg_enable;
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200407 }
408
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300409 r = dispc_runtime_get();
410 if (r)
411 goto err_get_dispc;
412
Archit Taneja064c2a42014-04-23 18:00:18 +0530413 r = dss_dpi_select_source(out->port_num, out->manager->id);
Tomi Valkeinende09e452012-09-21 12:09:54 +0300414 if (r)
415 goto err_src_sel;
416
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300417 if (dpi->pll) {
418 r = dss_pll_enable(dpi->pll);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530419 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300420 goto err_dsi_pll_init;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530421 }
422
Archit Taneja630d2d02014-05-30 16:26:22 +0530423 r = dpi_set_mode(dpi);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300424 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300425 goto err_set_mode;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300426
Archit Taneja630d2d02014-05-30 16:26:22 +0530427 dpi_config_lcd_manager(dpi);
Archit Taneja5cf9a262012-06-29 14:19:13 +0530428
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300429 mdelay(2);
430
Archit Taneja5d512fc2012-09-07 17:53:38 +0530431 r = dss_mgr_enable(out->manager);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200432 if (r)
433 goto err_mgr_enable;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300434
Archit Taneja630d2d02014-05-30 16:26:22 +0530435 mutex_unlock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530436
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300437 return 0;
438
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200439err_mgr_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300440err_set_mode:
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300441 if (dpi->pll)
442 dss_pll_disable(dpi->pll);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300443err_dsi_pll_init:
Tomi Valkeinende09e452012-09-21 12:09:54 +0300444err_src_sel:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300445 dispc_runtime_put();
446err_get_dispc:
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530447 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
Archit Taneja630d2d02014-05-30 16:26:22 +0530448 regulator_disable(dpi->vdds_dsi_reg);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300449err_reg_enable:
Archit Taneja5d512fc2012-09-07 17:53:38 +0530450err_no_out_mgr:
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530451err_no_reg:
Archit Taneja630d2d02014-05-30 16:26:22 +0530452 mutex_unlock(&dpi->lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300453 return r;
454}
455
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300456static void dpi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300457{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530458 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530459 struct omap_overlay_manager *mgr = dpi->output.manager;
Archit Taneja5d512fc2012-09-07 17:53:38 +0530460
Archit Taneja630d2d02014-05-30 16:26:22 +0530461 mutex_lock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530462
Archit Taneja5d512fc2012-09-07 17:53:38 +0530463 dss_mgr_disable(mgr);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300464
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300465 if (dpi->pll) {
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300466 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300467 dss_pll_disable(dpi->pll);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530468 }
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300469
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300470 dispc_runtime_put();
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300471
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530472 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
Archit Taneja630d2d02014-05-30 16:26:22 +0530473 regulator_disable(dpi->vdds_dsi_reg);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200474
Archit Taneja630d2d02014-05-30 16:26:22 +0530475 mutex_unlock(&dpi->lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300476}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300477
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300478static void dpi_set_timings(struct omap_dss_device *dssdev,
Archit Tanejac4991442012-08-08 14:28:54 +0530479 struct omap_video_timings *timings)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300480{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530481 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530482
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300483 DSSDBG("dpi_set_timings\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530484
Archit Taneja630d2d02014-05-30 16:26:22 +0530485 mutex_lock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530486
Archit Taneja630d2d02014-05-30 16:26:22 +0530487 dpi->timings = *timings;
Archit Tanejac4991442012-08-08 14:28:54 +0530488
Archit Taneja630d2d02014-05-30 16:26:22 +0530489 mutex_unlock(&dpi->lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300490}
491
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300492static void dpi_get_timings(struct omap_dss_device *dssdev,
493 struct omap_video_timings *timings)
494{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530495 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300496
Archit Taneja630d2d02014-05-30 16:26:22 +0530497 mutex_lock(&dpi->lock);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300498
Archit Taneja630d2d02014-05-30 16:26:22 +0530499 *timings = dpi->timings;
500
501 mutex_unlock(&dpi->lock);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300502}
503
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300504static int dpi_check_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300505 struct omap_video_timings *timings)
506{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530507 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530508 struct omap_overlay_manager *mgr = dpi->output.manager;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300509 int lck_div, pck_div;
510 unsigned long fck;
511 unsigned long pck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200512 struct dpi_clk_calc_ctx ctx;
513 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300514
Tomi Valkeinen8b095512012-10-24 13:27:02 +0300515 if (mgr && !dispc_mgr_timings_ok(mgr->id, timings))
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300516 return -EINVAL;
517
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300518 if (timings->pixelclock == 0)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300519 return -EINVAL;
520
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300521 if (dpi->pll) {
Archit Taneja630d2d02014-05-30 16:26:22 +0530522 ok = dpi_dsi_clk_calc(dpi, timings->pixelclock, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200523 if (!ok)
524 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300525
Tomi Valkeinenacf604b2014-11-07 13:13:24 +0200526 fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
Archit Taneja7636b3b2011-04-12 13:52:26 +0530527 } else {
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300528 ok = dpi_dss_clk_calc(timings->pixelclock, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200529 if (!ok)
530 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300531
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200532 fck = ctx.fck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300533 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530534
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200535 lck_div = ctx.dispc_cinfo.lck_div;
536 pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300537
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300538 pck = fck / lck_div / pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300539
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300540 timings->pixelclock = pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300541
542 return 0;
543}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300544
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300545static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
Archit Tanejac6b393d2012-07-06 15:30:52 +0530546{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530547 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530548
Archit Taneja630d2d02014-05-30 16:26:22 +0530549 mutex_lock(&dpi->lock);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530550
Archit Taneja630d2d02014-05-30 16:26:22 +0530551 dpi->data_lines = data_lines;
552
553 mutex_unlock(&dpi->lock);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530554}
Archit Tanejac6b393d2012-07-06 15:30:52 +0530555
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300556static int dpi_verify_dsi_pll(struct dss_pll *pll)
Tomi Valkeinen60616752012-10-30 12:57:43 +0200557{
558 int r;
559
560 /* do initial setup with the PLL to see if it is operational */
561
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300562 r = dss_pll_enable(pll);
Tomi Valkeinen60616752012-10-30 12:57:43 +0200563 if (r)
564 return r;
565
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300566 dss_pll_disable(pll);
Tomi Valkeinen60616752012-10-30 12:57:43 +0200567
568 return 0;
569}
570
Archit Taneja630d2d02014-05-30 16:26:22 +0530571static int dpi_init_regulator(struct dpi_data *dpi)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300572{
573 struct regulator *vdds_dsi;
574
575 if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
576 return 0;
577
Archit Taneja630d2d02014-05-30 16:26:22 +0530578 if (dpi->vdds_dsi_reg)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300579 return 0;
580
Archit Taneja630d2d02014-05-30 16:26:22 +0530581 vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300582 if (IS_ERR(vdds_dsi)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +0200583 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
584 DSSERR("can't get VDDS_DSI regulator\n");
Tomi Valkeinen4123de22013-08-29 10:06:55 +0300585 return PTR_ERR(vdds_dsi);
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300586 }
587
Archit Taneja630d2d02014-05-30 16:26:22 +0530588 dpi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300589
590 return 0;
591}
592
Archit Taneja630d2d02014-05-30 16:26:22 +0530593static void dpi_init_pll(struct dpi_data *dpi)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300594{
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300595 struct dss_pll *pll;
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300596
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300597 if (dpi->pll)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300598 return;
599
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300600 pll = dpi_get_pll(dpi->output.dispc_channel);
601 if (!pll)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300602 return;
603
Tomi Valkeinena2408152014-12-31 11:26:06 +0200604 /* On DRA7 we need to set a mux to use the PLL */
605 if (omapdss_get_version() == OMAPDSS_VER_DRA7xx)
606 dss_ctrl_pll_set_control_mux(pll->id, dpi->output.dispc_channel);
607
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300608 if (dpi_verify_dsi_pll(pll)) {
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300609 DSSWARN("DSI PLL not operational\n");
610 return;
611 }
612
Tomi Valkeinen2daea7a2014-10-22 14:49:14 +0300613 dpi->pll = pll;
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300614}
615
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200616/*
617 * Return a hardcoded channel for the DPI output. This should work for
618 * current use cases, but this can be later expanded to either resolve
619 * the channel in some more dynamic manner, or get the channel as a user
620 * parameter.
621 */
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530622static enum omap_channel dpi_get_channel(int port_num)
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200623{
624 switch (omapdss_get_version()) {
625 case OMAPDSS_VER_OMAP24xx:
626 case OMAPDSS_VER_OMAP34xx_ES1:
627 case OMAPDSS_VER_OMAP34xx_ES3:
628 case OMAPDSS_VER_OMAP3630:
629 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +0530630 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200631 return OMAP_DSS_CHANNEL_LCD;
632
Tomi Valkeinena2408152014-12-31 11:26:06 +0200633 case OMAPDSS_VER_DRA7xx:
634 switch (port_num) {
635 case 2:
636 return OMAP_DSS_CHANNEL_LCD3;
637 case 1:
638 return OMAP_DSS_CHANNEL_LCD2;
639 case 0:
640 default:
641 return OMAP_DSS_CHANNEL_LCD;
642 }
643
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200644 case OMAPDSS_VER_OMAP4430_ES1:
645 case OMAPDSS_VER_OMAP4430_ES2:
646 case OMAPDSS_VER_OMAP4:
647 return OMAP_DSS_CHANNEL_LCD2;
648
649 case OMAPDSS_VER_OMAP5:
650 return OMAP_DSS_CHANNEL_LCD3;
651
652 default:
653 DSSWARN("unsupported DSS version\n");
654 return OMAP_DSS_CHANNEL_LCD;
655 }
656}
657
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300658static int dpi_connect(struct omap_dss_device *dssdev,
659 struct omap_dss_device *dst)
660{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530661 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300662 struct omap_overlay_manager *mgr;
663 int r;
664
Archit Taneja630d2d02014-05-30 16:26:22 +0530665 r = dpi_init_regulator(dpi);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300666 if (r)
667 return r;
668
Archit Taneja630d2d02014-05-30 16:26:22 +0530669 dpi_init_pll(dpi);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300670
671 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
672 if (!mgr)
673 return -ENODEV;
674
675 r = dss_mgr_connect(mgr, dssdev);
676 if (r)
677 return r;
678
679 r = omapdss_output_set_device(dssdev, dst);
680 if (r) {
681 DSSERR("failed to connect output to new device: %s\n",
682 dst->name);
683 dss_mgr_disconnect(mgr, dssdev);
684 return r;
685 }
686
687 return 0;
688}
689
690static void dpi_disconnect(struct omap_dss_device *dssdev,
691 struct omap_dss_device *dst)
692{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300693 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300694
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300695 if (dst != dssdev->dst)
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300696 return;
697
698 omapdss_output_unset_device(dssdev);
699
700 if (dssdev->manager)
701 dss_mgr_disconnect(dssdev->manager, dssdev);
702}
703
704static const struct omapdss_dpi_ops dpi_ops = {
705 .connect = dpi_connect,
706 .disconnect = dpi_disconnect,
707
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300708 .enable = dpi_display_enable,
709 .disable = dpi_display_disable,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300710
711 .check_timings = dpi_check_timings,
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300712 .set_timings = dpi_set_timings,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300713 .get_timings = dpi_get_timings,
714
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300715 .set_data_lines = dpi_set_data_lines,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300716};
717
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300718static void dpi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530719{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530720 struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530721 struct omap_dss_device *out = &dpi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530722
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300723 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530724 out->id = OMAP_DSS_OUTPUT_DPI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300725 out->output_type = OMAP_DISPLAY_TYPE_DPI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200726 out->name = "dpi.0";
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530727 out->dispc_channel = dpi_get_channel(0);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300728 out->ops.dpi = &dpi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300729 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530730
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300731 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530732}
733
734static void __exit dpi_uninit_output(struct platform_device *pdev)
735{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530736 struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530737 struct omap_dss_device *out = &dpi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530738
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300739 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530740}
741
Archit Taneja80eb6752014-06-02 14:11:51 +0530742static void dpi_init_output_port(struct platform_device *pdev,
743 struct device_node *port)
744{
745 struct dpi_data *dpi = port->data;
746 struct omap_dss_device *out = &dpi->output;
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530747 int r;
748 u32 port_num;
749
750 r = of_property_read_u32(port, "reg", &port_num);
751 if (r)
752 port_num = 0;
753
754 switch (port_num) {
755 case 2:
756 out->name = "dpi.2";
757 break;
758 case 1:
759 out->name = "dpi.1";
760 break;
761 case 0:
762 default:
763 out->name = "dpi.0";
764 break;
765 }
Archit Taneja80eb6752014-06-02 14:11:51 +0530766
767 out->dev = &pdev->dev;
768 out->id = OMAP_DSS_OUTPUT_DPI;
769 out->output_type = OMAP_DISPLAY_TYPE_DPI;
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530770 out->dispc_channel = dpi_get_channel(port_num);
771 out->port_num = port_num;
Archit Taneja80eb6752014-06-02 14:11:51 +0530772 out->ops.dpi = &dpi_ops;
773 out->owner = THIS_MODULE;
774
775 omapdss_register_output(out);
776}
777
778static void __exit dpi_uninit_output_port(struct device_node *port)
779{
780 struct dpi_data *dpi = port->data;
781 struct omap_dss_device *out = &dpi->output;
782
783 omapdss_unregister_output(out);
784}
785
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300786static int omap_dpi_probe(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300787{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530788 struct dpi_data *dpi;
789
790 dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
791 if (!dpi)
792 return -ENOMEM;
Tomi Valkeinen00df43b2013-03-19 11:33:52 +0200793
Archit Taneja630d2d02014-05-30 16:26:22 +0530794 dpi->pdev = pdev;
795
796 dev_set_drvdata(&pdev->dev, dpi);
797
798 mutex_init(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530799
Archit Taneja81b87f52012-09-26 16:30:49 +0530800 dpi_init_output(pdev);
801
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300802 return 0;
803}
804
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200805static int __exit omap_dpi_remove(struct platform_device *pdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300806{
Archit Taneja81b87f52012-09-26 16:30:49 +0530807 dpi_uninit_output(pdev);
808
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200809 return 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300810}
811
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200812static struct platform_driver omap_dpi_driver = {
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300813 .probe = omap_dpi_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200814 .remove = __exit_p(omap_dpi_remove),
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200815 .driver = {
816 .name = "omapdss_dpi",
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300817 .suppress_bind_attrs = true,
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200818 },
819};
820
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200821int __init dpi_init_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200822{
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300823 return platform_driver_register(&omap_dpi_driver);
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200824}
825
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200826void __exit dpi_uninit_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200827{
828 platform_driver_unregister(&omap_dpi_driver);
829}
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200830
831int __init dpi_init_port(struct platform_device *pdev, struct device_node *port)
832{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530833 struct dpi_data *dpi;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200834 struct device_node *ep;
835 u32 datalines;
836 int r;
837
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530838 dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
839 if (!dpi)
840 return -ENOMEM;
841
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200842 ep = omapdss_of_get_next_endpoint(port, NULL);
843 if (!ep)
844 return 0;
845
846 r = of_property_read_u32(ep, "data-lines", &datalines);
847 if (r) {
848 DSSERR("failed to parse datalines\n");
849 goto err_datalines;
850 }
851
Archit Taneja630d2d02014-05-30 16:26:22 +0530852 dpi->data_lines = datalines;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200853
854 of_node_put(ep);
855
Archit Taneja630d2d02014-05-30 16:26:22 +0530856 dpi->pdev = pdev;
Archit Taneja80eb6752014-06-02 14:11:51 +0530857 port->data = dpi;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200858
Archit Taneja630d2d02014-05-30 16:26:22 +0530859 mutex_init(&dpi->lock);
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200860
Archit Taneja80eb6752014-06-02 14:11:51 +0530861 dpi_init_output_port(pdev, port);
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200862
Archit Taneja630d2d02014-05-30 16:26:22 +0530863 dpi->port_initialized = true;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200864
865 return 0;
866
867err_datalines:
868 of_node_put(ep);
869
870 return r;
871}
872
Archit Taneja80eb6752014-06-02 14:11:51 +0530873void __exit dpi_uninit_port(struct device_node *port)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200874{
Archit Taneja80eb6752014-06-02 14:11:51 +0530875 struct dpi_data *dpi = port->data;
Archit Taneja630d2d02014-05-30 16:26:22 +0530876
877 if (!dpi->port_initialized)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200878 return;
879
Archit Taneja80eb6752014-06-02 14:11:51 +0530880 dpi_uninit_output_port(port);
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200881}