blob: ebc294f8dfdb5c0f9a2ae8fbd51271b2f32c94f8 [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
Archit Taneja630d2d02014-05-30 16:26:22 +053040struct dpi_data {
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;
Archit Taneja630d2d02014-05-30 16:26:22 +053055};
56
Archit Taneja2ac6a1a2014-06-01 12:47:44 +053057static struct dpi_data *dpi_get_data_from_dssdev(struct omap_dss_device *dssdev)
58{
59 return container_of(dssdev, struct dpi_data, output);
60}
61
Archit Taneja80eb6752014-06-02 14:11:51 +053062/* only used in non-DT mode */
Archit Taneja2ac6a1a2014-06-01 12:47:44 +053063static struct dpi_data *dpi_get_data_from_pdev(struct platform_device *pdev)
64{
65 return dev_get_drvdata(&pdev->dev);
66}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030067
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +030068static struct platform_device *dpi_get_dsidev(enum omap_channel channel)
Archit Tanejaa72b64b2011-05-12 17:26:26 +053069{
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020070 /*
71 * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL
72 * would also be used for DISPC fclk. Meaning, when the DPI output is
73 * disabled, DISPC clock will be disabled, and TV out will stop.
74 */
75 switch (omapdss_get_version()) {
76 case OMAPDSS_VER_OMAP24xx:
77 case OMAPDSS_VER_OMAP34xx_ES1:
78 case OMAPDSS_VER_OMAP34xx_ES3:
79 case OMAPDSS_VER_OMAP3630:
80 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +053081 case OMAPDSS_VER_AM43xx:
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020082 return NULL;
Tomi Valkeinenbd0f5cc2012-12-13 14:21:30 +020083
Tomi Valkeinenf8ad9842013-03-11 13:57:38 +020084 case OMAPDSS_VER_OMAP4430_ES1:
85 case OMAPDSS_VER_OMAP4430_ES2:
86 case OMAPDSS_VER_OMAP4:
87 switch (channel) {
88 case OMAP_DSS_CHANNEL_LCD:
89 return dsi_get_dsidev_from_id(0);
90 case OMAP_DSS_CHANNEL_LCD2:
91 return dsi_get_dsidev_from_id(1);
92 default:
93 return NULL;
94 }
95
96 case OMAPDSS_VER_OMAP5:
97 switch (channel) {
98 case OMAP_DSS_CHANNEL_LCD:
99 return dsi_get_dsidev_from_id(0);
100 case OMAP_DSS_CHANNEL_LCD3:
101 return dsi_get_dsidev_from_id(1);
102 default:
103 return NULL;
104 }
105
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300106 default:
107 return NULL;
108 }
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530109}
110
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300111static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel)
Archit Taneja7636b3b2011-04-12 13:52:26 +0530112{
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300113 switch (channel) {
114 case OMAP_DSS_CHANNEL_LCD:
115 return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC;
116 case OMAP_DSS_CHANNEL_LCD2:
117 return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
Tomi Valkeinen35fd32d2014-04-17 13:57:21 +0300118 case OMAP_DSS_CHANNEL_LCD3:
119 return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
Tomi Valkeinen0e8276e2012-10-22 16:12:58 +0300120 default:
121 /* this shouldn't happen */
122 WARN_ON(1);
123 return OMAP_DSS_CLK_SRC_FCK;
124 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530125}
126
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200127struct dpi_clk_calc_ctx {
128 struct platform_device *dsidev;
129
130 /* inputs */
131
132 unsigned long pck_min, pck_max;
133
134 /* outputs */
135
136 struct dsi_clock_info dsi_cinfo;
Tomi Valkeinenc56812f2014-01-28 08:50:47 +0200137 unsigned long fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200138 struct dispc_clock_info dispc_cinfo;
139};
140
141static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
142 unsigned long pck, void *data)
143{
144 struct dpi_clk_calc_ctx *ctx = data;
145
146 /*
147 * Odd dividers give us uneven duty cycle, causing problem when level
148 * shifted. So skip all odd dividers when the pixel clock is on the
149 * higher side.
150 */
Tomi Valkeinen72e55122013-06-12 09:44:52 +0300151 if (ctx->pck_min >= 100000000) {
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200152 if (lckd > 1 && lckd % 2 != 0)
153 return false;
154
155 if (pckd > 1 && pckd % 2 != 0)
156 return false;
157 }
158
159 ctx->dispc_cinfo.lck_div = lckd;
160 ctx->dispc_cinfo.pck_div = pckd;
161 ctx->dispc_cinfo.lck = lck;
162 ctx->dispc_cinfo.pck = pck;
163
164 return true;
165}
166
167
168static bool dpi_calc_hsdiv_cb(int regm_dispc, unsigned long dispc,
169 void *data)
170{
171 struct dpi_clk_calc_ctx *ctx = data;
172
173 /*
174 * Odd dividers give us uneven duty cycle, causing problem when level
175 * shifted. So skip all odd dividers when the pixel clock is on the
176 * higher side.
177 */
Tomi Valkeinen72e55122013-06-12 09:44:52 +0300178 if (regm_dispc > 1 && regm_dispc % 2 != 0 && ctx->pck_min >= 100000000)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200179 return false;
180
181 ctx->dsi_cinfo.regm_dispc = regm_dispc;
182 ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc;
183
184 return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max,
185 dpi_calc_dispc_cb, ctx);
186}
187
188
189static bool dpi_calc_pll_cb(int regn, int regm, unsigned long fint,
190 unsigned long pll,
191 void *data)
192{
193 struct dpi_clk_calc_ctx *ctx = data;
194
195 ctx->dsi_cinfo.regn = regn;
196 ctx->dsi_cinfo.regm = regm;
197 ctx->dsi_cinfo.fint = fint;
198 ctx->dsi_cinfo.clkin4ddr = pll;
199
200 return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->pck_min,
201 dpi_calc_hsdiv_cb, ctx);
202}
203
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200204static bool dpi_calc_dss_cb(unsigned long fck, void *data)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200205{
206 struct dpi_clk_calc_ctx *ctx = data;
207
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200208 ctx->fck = fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200209
210 return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max,
211 dpi_calc_dispc_cb, ctx);
212}
213
Archit Taneja630d2d02014-05-30 16:26:22 +0530214static bool dpi_dsi_clk_calc(struct dpi_data *dpi, unsigned long pck,
215 struct dpi_clk_calc_ctx *ctx)
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200216{
217 unsigned long clkin;
218 unsigned long pll_min, pll_max;
219
Archit Taneja630d2d02014-05-30 16:26:22 +0530220 clkin = dsi_get_pll_clkin(dpi->dsidev);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200221
222 memset(ctx, 0, sizeof(*ctx));
Archit Taneja630d2d02014-05-30 16:26:22 +0530223 ctx->dsidev = dpi->dsidev;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200224 ctx->pck_min = pck - 1000;
225 ctx->pck_max = pck + 1000;
226 ctx->dsi_cinfo.clkin = clkin;
227
228 pll_min = 0;
229 pll_max = 0;
230
Archit Taneja630d2d02014-05-30 16:26:22 +0530231 return dsi_pll_calc(dpi->dsidev, clkin,
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200232 pll_min, pll_max,
233 dpi_calc_pll_cb, ctx);
234}
235
236static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx)
237{
238 int i;
239
240 /*
241 * DSS fck gives us very few possibilities, so finding a good pixel
242 * clock may not be possible. We try multiple times to find the clock,
243 * each time widening the pixel clock range we look for, up to
Tomi Valkeinen2c6360f2013-04-10 14:54:54 +0300244 * +/- ~15MHz.
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200245 */
246
Tomi Valkeinen2c6360f2013-04-10 14:54:54 +0300247 for (i = 0; i < 25; ++i) {
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200248 bool ok;
249
250 memset(ctx, 0, sizeof(*ctx));
251 if (pck > 1000 * i * i * i)
252 ctx->pck_min = max(pck - 1000 * i * i * i, 0lu);
253 else
254 ctx->pck_min = 0;
255 ctx->pck_max = pck + 1000 * i * i * i;
256
Tomi Valkeinen688af022013-10-31 16:41:57 +0200257 ok = dss_div_calc(pck, ctx->pck_min, dpi_calc_dss_cb, ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200258 if (ok)
259 return ok;
260 }
261
262 return false;
263}
264
265
266
Archit Taneja630d2d02014-05-30 16:26:22 +0530267static int dpi_set_dsi_clk(struct dpi_data *dpi, enum omap_channel channel,
Sumit Semwalff1b2cde2010-12-02 11:27:11 +0000268 unsigned long pck_req, unsigned long *fck, int *lck_div,
269 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300270{
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200271 struct dpi_clk_calc_ctx ctx;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300272 int r;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200273 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300274
Archit Taneja630d2d02014-05-30 16:26:22 +0530275 ok = dpi_dsi_clk_calc(dpi, pck_req, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200276 if (!ok)
277 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300278
Archit Taneja630d2d02014-05-30 16:26:22 +0530279 r = dsi_pll_set_clock_div(dpi->dsidev, &ctx.dsi_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300280 if (r)
281 return r;
282
Tomi Valkeinen03a0d1e2012-11-27 16:41:16 +0200283 dss_select_lcd_clk_source(channel,
284 dpi_get_alt_clk_src(channel));
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300285
Archit Taneja630d2d02014-05-30 16:26:22 +0530286 dpi->mgr_config.clock_info = ctx.dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300287
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200288 *fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
289 *lck_div = ctx.dispc_cinfo.lck_div;
290 *pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300291
292 return 0;
293}
Archit Taneja7636b3b2011-04-12 13:52:26 +0530294
Archit Taneja630d2d02014-05-30 16:26:22 +0530295static int dpi_set_dispc_clk(struct dpi_data *dpi, unsigned long pck_req,
296 unsigned long *fck, int *lck_div, int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300297{
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200298 struct dpi_clk_calc_ctx ctx;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300299 int r;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200300 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300301
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200302 ok = dpi_dss_clk_calc(pck_req, &ctx);
303 if (!ok)
304 return -EINVAL;
305
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200306 r = dss_set_fck_rate(ctx.fck);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300307 if (r)
308 return r;
309
Archit Taneja630d2d02014-05-30 16:26:22 +0530310 dpi->mgr_config.clock_info = ctx.dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300311
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200312 *fck = ctx.fck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200313 *lck_div = ctx.dispc_cinfo.lck_div;
314 *pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300315
316 return 0;
317}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300318
Archit Taneja630d2d02014-05-30 16:26:22 +0530319static int dpi_set_mode(struct dpi_data *dpi)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300320{
Archit Taneja630d2d02014-05-30 16:26:22 +0530321 struct omap_dss_device *out = &dpi->output;
322 struct omap_overlay_manager *mgr = out->manager;
323 struct omap_video_timings *t = &dpi->timings;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530324 int lck_div = 0, pck_div = 0;
325 unsigned long fck = 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300326 unsigned long pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300327 int r = 0;
328
Archit Taneja630d2d02014-05-30 16:26:22 +0530329 if (dpi->dsidev)
330 r = dpi_set_dsi_clk(dpi, mgr->id, t->pixelclock, &fck,
Archit Taneja6d523e72012-06-21 09:33:55 +0530331 &lck_div, &pck_div);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530332 else
Archit Taneja630d2d02014-05-30 16:26:22 +0530333 r = dpi_set_dispc_clk(dpi, t->pixelclock, &fck,
Archit Taneja6d523e72012-06-21 09:33:55 +0530334 &lck_div, &pck_div);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300335 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300336 return r;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300337
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300338 pck = fck / lck_div / pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300339
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300340 if (pck != t->pixelclock) {
341 DSSWARN("Could not find exact pixel clock. Requested %d Hz, got %lu Hz\n",
342 t->pixelclock, pck);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300343
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300344 t->pixelclock = pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300345 }
346
Archit Taneja5d512fc2012-09-07 17:53:38 +0530347 dss_mgr_set_timings(mgr, t);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300348
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300349 return 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300350}
351
Archit Taneja630d2d02014-05-30 16:26:22 +0530352static void dpi_config_lcd_manager(struct dpi_data *dpi)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300353{
Archit Taneja630d2d02014-05-30 16:26:22 +0530354 struct omap_dss_device *out = &dpi->output;
355 struct omap_overlay_manager *mgr = out->manager;
Archit Taneja569969d2011-08-22 17:41:57 +0530356
Archit Taneja630d2d02014-05-30 16:26:22 +0530357 dpi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530358
Archit Taneja630d2d02014-05-30 16:26:22 +0530359 dpi->mgr_config.stallmode = false;
360 dpi->mgr_config.fifohandcheck = false;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530361
Archit Taneja630d2d02014-05-30 16:26:22 +0530362 dpi->mgr_config.video_port_width = dpi->data_lines;
Archit Taneja5cf9a262012-06-29 14:19:13 +0530363
Archit Taneja630d2d02014-05-30 16:26:22 +0530364 dpi->mgr_config.lcden_sig_polarity = 0;
365
366 dss_mgr_set_lcd_config(mgr, &dpi->mgr_config);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300367}
368
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300369static int dpi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300370{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530371 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530372 struct omap_dss_device *out = &dpi->output;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300373 int r;
374
Archit Taneja630d2d02014-05-30 16:26:22 +0530375 mutex_lock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530376
Archit Taneja630d2d02014-05-30 16:26:22 +0530377 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi->vdds_dsi_reg) {
Russell King40410712012-02-07 09:44:55 +0000378 DSSERR("no VDSS_DSI regulator\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530379 r = -ENODEV;
380 goto err_no_reg;
Russell King40410712012-02-07 09:44:55 +0000381 }
382
Archit Taneja5d512fc2012-09-07 17:53:38 +0530383 if (out == NULL || out->manager == NULL) {
384 DSSERR("failed to enable display: no output/manager\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530385 r = -ENODEV;
Archit Taneja5d512fc2012-09-07 17:53:38 +0530386 goto err_no_out_mgr;
Tomi Valkeinen05e1d602011-06-23 16:38:21 +0300387 }
388
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530389 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) {
Archit Taneja630d2d02014-05-30 16:26:22 +0530390 r = regulator_enable(dpi->vdds_dsi_reg);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200391 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300392 goto err_reg_enable;
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200393 }
394
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300395 r = dispc_runtime_get();
396 if (r)
397 goto err_get_dispc;
398
Archit Taneja064c2a42014-04-23 18:00:18 +0530399 r = dss_dpi_select_source(out->port_num, out->manager->id);
Tomi Valkeinende09e452012-09-21 12:09:54 +0300400 if (r)
401 goto err_src_sel;
402
Archit Taneja630d2d02014-05-30 16:26:22 +0530403 if (dpi->dsidev) {
404 r = dsi_runtime_get(dpi->dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300405 if (r)
406 goto err_get_dsi;
407
Archit Taneja630d2d02014-05-30 16:26:22 +0530408 r = dsi_pll_init(dpi->dsidev, 0, 1);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530409 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300410 goto err_dsi_pll_init;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530411 }
412
Archit Taneja630d2d02014-05-30 16:26:22 +0530413 r = dpi_set_mode(dpi);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300414 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300415 goto err_set_mode;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300416
Archit Taneja630d2d02014-05-30 16:26:22 +0530417 dpi_config_lcd_manager(dpi);
Archit Taneja5cf9a262012-06-29 14:19:13 +0530418
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300419 mdelay(2);
420
Archit Taneja5d512fc2012-09-07 17:53:38 +0530421 r = dss_mgr_enable(out->manager);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200422 if (r)
423 goto err_mgr_enable;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300424
Archit Taneja630d2d02014-05-30 16:26:22 +0530425 mutex_unlock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530426
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300427 return 0;
428
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200429err_mgr_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300430err_set_mode:
Archit Taneja630d2d02014-05-30 16:26:22 +0530431 if (dpi->dsidev)
432 dsi_pll_uninit(dpi->dsidev, true);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300433err_dsi_pll_init:
Archit Taneja630d2d02014-05-30 16:26:22 +0530434 if (dpi->dsidev)
435 dsi_runtime_put(dpi->dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300436err_get_dsi:
Tomi Valkeinende09e452012-09-21 12:09:54 +0300437err_src_sel:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300438 dispc_runtime_put();
439err_get_dispc:
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530440 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
Archit Taneja630d2d02014-05-30 16:26:22 +0530441 regulator_disable(dpi->vdds_dsi_reg);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300442err_reg_enable:
Archit Taneja5d512fc2012-09-07 17:53:38 +0530443err_no_out_mgr:
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530444err_no_reg:
Archit Taneja630d2d02014-05-30 16:26:22 +0530445 mutex_unlock(&dpi->lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300446 return r;
447}
448
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300449static void dpi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300450{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530451 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530452 struct omap_overlay_manager *mgr = dpi->output.manager;
Archit Taneja5d512fc2012-09-07 17:53:38 +0530453
Archit Taneja630d2d02014-05-30 16:26:22 +0530454 mutex_lock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530455
Archit Taneja5d512fc2012-09-07 17:53:38 +0530456 dss_mgr_disable(mgr);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300457
Archit Taneja630d2d02014-05-30 16:26:22 +0530458 if (dpi->dsidev) {
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300459 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Archit Taneja630d2d02014-05-30 16:26:22 +0530460 dsi_pll_uninit(dpi->dsidev, true);
461 dsi_runtime_put(dpi->dsidev);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530462 }
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300463
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300464 dispc_runtime_put();
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300465
Chandrabhanu Mahapatra195e6722012-08-22 11:44:06 +0530466 if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
Archit Taneja630d2d02014-05-30 16:26:22 +0530467 regulator_disable(dpi->vdds_dsi_reg);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200468
Archit Taneja630d2d02014-05-30 16:26:22 +0530469 mutex_unlock(&dpi->lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300470}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300471
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300472static void dpi_set_timings(struct omap_dss_device *dssdev,
Archit Tanejac4991442012-08-08 14:28:54 +0530473 struct omap_video_timings *timings)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300474{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530475 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530476
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300477 DSSDBG("dpi_set_timings\n");
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530478
Archit Taneja630d2d02014-05-30 16:26:22 +0530479 mutex_lock(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530480
Archit Taneja630d2d02014-05-30 16:26:22 +0530481 dpi->timings = *timings;
Archit Tanejac4991442012-08-08 14:28:54 +0530482
Archit Taneja630d2d02014-05-30 16:26:22 +0530483 mutex_unlock(&dpi->lock);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300484}
485
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300486static void dpi_get_timings(struct omap_dss_device *dssdev,
487 struct omap_video_timings *timings)
488{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530489 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300490
Archit Taneja630d2d02014-05-30 16:26:22 +0530491 mutex_lock(&dpi->lock);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300492
Archit Taneja630d2d02014-05-30 16:26:22 +0530493 *timings = dpi->timings;
494
495 mutex_unlock(&dpi->lock);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300496}
497
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300498static int dpi_check_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300499 struct omap_video_timings *timings)
500{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530501 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530502 struct omap_overlay_manager *mgr = dpi->output.manager;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300503 int lck_div, pck_div;
504 unsigned long fck;
505 unsigned long pck;
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200506 struct dpi_clk_calc_ctx ctx;
507 bool ok;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300508
Tomi Valkeinen8b095512012-10-24 13:27:02 +0300509 if (mgr && !dispc_mgr_timings_ok(mgr->id, timings))
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300510 return -EINVAL;
511
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300512 if (timings->pixelclock == 0)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300513 return -EINVAL;
514
Archit Taneja630d2d02014-05-30 16:26:22 +0530515 if (dpi->dsidev) {
516 ok = dpi_dsi_clk_calc(dpi, timings->pixelclock, &ctx);
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200517 if (!ok)
518 return -EINVAL;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300519
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200520 fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530521 } else {
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300522 ok = dpi_dss_clk_calc(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 Valkeinend0f58bd2013-10-31 14:44:23 +0200526 fck = ctx.fck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300527 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530528
Tomi Valkeinen100c8262013-03-05 17:07:16 +0200529 lck_div = ctx.dispc_cinfo.lck_div;
530 pck_div = ctx.dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300531
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300532 pck = fck / lck_div / pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300533
Tomi Valkeinend8d789412013-04-10 14:12:14 +0300534 timings->pixelclock = pck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300535
536 return 0;
537}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300538
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300539static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
Archit Tanejac6b393d2012-07-06 15:30:52 +0530540{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530541 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530542
Archit Taneja630d2d02014-05-30 16:26:22 +0530543 mutex_lock(&dpi->lock);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530544
Archit Taneja630d2d02014-05-30 16:26:22 +0530545 dpi->data_lines = data_lines;
546
547 mutex_unlock(&dpi->lock);
Archit Tanejac6b393d2012-07-06 15:30:52 +0530548}
Archit Tanejac6b393d2012-07-06 15:30:52 +0530549
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300550static int dpi_verify_dsi_pll(struct platform_device *dsidev)
Tomi Valkeinen60616752012-10-30 12:57:43 +0200551{
552 int r;
553
554 /* do initial setup with the PLL to see if it is operational */
555
556 r = dsi_runtime_get(dsidev);
557 if (r)
558 return r;
559
560 r = dsi_pll_init(dsidev, 0, 1);
561 if (r) {
562 dsi_runtime_put(dsidev);
563 return r;
564 }
565
566 dsi_pll_uninit(dsidev, true);
567 dsi_runtime_put(dsidev);
568
569 return 0;
570}
571
Archit Taneja630d2d02014-05-30 16:26:22 +0530572static int dpi_init_regulator(struct dpi_data *dpi)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300573{
574 struct regulator *vdds_dsi;
575
576 if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
577 return 0;
578
Archit Taneja630d2d02014-05-30 16:26:22 +0530579 if (dpi->vdds_dsi_reg)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300580 return 0;
581
Archit Taneja630d2d02014-05-30 16:26:22 +0530582 vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300583 if (IS_ERR(vdds_dsi)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +0200584 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
585 DSSERR("can't get VDDS_DSI regulator\n");
Tomi Valkeinen4123de22013-08-29 10:06:55 +0300586 return PTR_ERR(vdds_dsi);
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300587 }
588
Archit Taneja630d2d02014-05-30 16:26:22 +0530589 dpi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300590
591 return 0;
592}
593
Archit Taneja630d2d02014-05-30 16:26:22 +0530594static void dpi_init_pll(struct dpi_data *dpi)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300595{
596 struct platform_device *dsidev;
597
Archit Taneja630d2d02014-05-30 16:26:22 +0530598 if (dpi->dsidev)
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300599 return;
600
Archit Taneja630d2d02014-05-30 16:26:22 +0530601 dsidev = dpi_get_dsidev(dpi->output.dispc_channel);
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300602 if (!dsidev)
603 return;
604
605 if (dpi_verify_dsi_pll(dsidev)) {
606 DSSWARN("DSI PLL not operational\n");
607 return;
608 }
609
Archit Taneja630d2d02014-05-30 16:26:22 +0530610 dpi->dsidev = dsidev;
Tomi Valkeinen2795f642013-04-19 16:52:27 +0300611}
612
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200613/*
614 * Return a hardcoded channel for the DPI output. This should work for
615 * current use cases, but this can be later expanded to either resolve
616 * the channel in some more dynamic manner, or get the channel as a user
617 * parameter.
618 */
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530619static enum omap_channel dpi_get_channel(int port_num)
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200620{
621 switch (omapdss_get_version()) {
622 case OMAPDSS_VER_OMAP24xx:
623 case OMAPDSS_VER_OMAP34xx_ES1:
624 case OMAPDSS_VER_OMAP34xx_ES3:
625 case OMAPDSS_VER_OMAP3630:
626 case OMAPDSS_VER_AM35xx:
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +0530627 case OMAPDSS_VER_AM43xx:
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +0200628 return OMAP_DSS_CHANNEL_LCD;
629
630 case OMAPDSS_VER_OMAP4430_ES1:
631 case OMAPDSS_VER_OMAP4430_ES2:
632 case OMAPDSS_VER_OMAP4:
633 return OMAP_DSS_CHANNEL_LCD2;
634
635 case OMAPDSS_VER_OMAP5:
636 return OMAP_DSS_CHANNEL_LCD3;
637
638 default:
639 DSSWARN("unsupported DSS version\n");
640 return OMAP_DSS_CHANNEL_LCD;
641 }
642}
643
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300644static int dpi_connect(struct omap_dss_device *dssdev,
645 struct omap_dss_device *dst)
646{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530647 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300648 struct omap_overlay_manager *mgr;
649 int r;
650
Archit Taneja630d2d02014-05-30 16:26:22 +0530651 r = dpi_init_regulator(dpi);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300652 if (r)
653 return r;
654
Archit Taneja630d2d02014-05-30 16:26:22 +0530655 dpi_init_pll(dpi);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300656
657 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
658 if (!mgr)
659 return -ENODEV;
660
661 r = dss_mgr_connect(mgr, dssdev);
662 if (r)
663 return r;
664
665 r = omapdss_output_set_device(dssdev, dst);
666 if (r) {
667 DSSERR("failed to connect output to new device: %s\n",
668 dst->name);
669 dss_mgr_disconnect(mgr, dssdev);
670 return r;
671 }
672
673 return 0;
674}
675
676static void dpi_disconnect(struct omap_dss_device *dssdev,
677 struct omap_dss_device *dst)
678{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300679 WARN_ON(dst != dssdev->dst);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300680
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300681 if (dst != dssdev->dst)
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300682 return;
683
684 omapdss_output_unset_device(dssdev);
685
686 if (dssdev->manager)
687 dss_mgr_disconnect(dssdev->manager, dssdev);
688}
689
690static const struct omapdss_dpi_ops dpi_ops = {
691 .connect = dpi_connect,
692 .disconnect = dpi_disconnect,
693
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300694 .enable = dpi_display_enable,
695 .disable = dpi_display_disable,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300696
697 .check_timings = dpi_check_timings,
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300698 .set_timings = dpi_set_timings,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300699 .get_timings = dpi_get_timings,
700
Tomi Valkeinen86a3efe2013-05-15 10:40:15 +0300701 .set_data_lines = dpi_set_data_lines,
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300702};
703
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300704static void dpi_init_output(struct platform_device *pdev)
Archit Taneja81b87f52012-09-26 16:30:49 +0530705{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530706 struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530707 struct omap_dss_device *out = &dpi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530708
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300709 out->dev = &pdev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +0530710 out->id = OMAP_DSS_OUTPUT_DPI;
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300711 out->output_type = OMAP_DISPLAY_TYPE_DPI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200712 out->name = "dpi.0";
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530713 out->dispc_channel = dpi_get_channel(0);
Tomi Valkeinen0b24edb2013-05-24 13:18:52 +0300714 out->ops.dpi = &dpi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +0300715 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +0530716
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300717 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530718}
719
720static void __exit dpi_uninit_output(struct platform_device *pdev)
721{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530722 struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
Archit Taneja630d2d02014-05-30 16:26:22 +0530723 struct omap_dss_device *out = &dpi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +0530724
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +0300725 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +0530726}
727
Archit Taneja80eb6752014-06-02 14:11:51 +0530728static void dpi_init_output_port(struct platform_device *pdev,
729 struct device_node *port)
730{
731 struct dpi_data *dpi = port->data;
732 struct omap_dss_device *out = &dpi->output;
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530733 int r;
734 u32 port_num;
735
736 r = of_property_read_u32(port, "reg", &port_num);
737 if (r)
738 port_num = 0;
739
740 switch (port_num) {
741 case 2:
742 out->name = "dpi.2";
743 break;
744 case 1:
745 out->name = "dpi.1";
746 break;
747 case 0:
748 default:
749 out->name = "dpi.0";
750 break;
751 }
Archit Taneja80eb6752014-06-02 14:11:51 +0530752
753 out->dev = &pdev->dev;
754 out->id = OMAP_DSS_OUTPUT_DPI;
755 out->output_type = OMAP_DISPLAY_TYPE_DPI;
Archit Tanejaf7e38fe2014-05-06 17:07:39 +0530756 out->dispc_channel = dpi_get_channel(port_num);
757 out->port_num = port_num;
Archit Taneja80eb6752014-06-02 14:11:51 +0530758 out->ops.dpi = &dpi_ops;
759 out->owner = THIS_MODULE;
760
761 omapdss_register_output(out);
762}
763
764static void __exit dpi_uninit_output_port(struct device_node *port)
765{
766 struct dpi_data *dpi = port->data;
767 struct omap_dss_device *out = &dpi->output;
768
769 omapdss_unregister_output(out);
770}
771
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300772static int omap_dpi_probe(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300773{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530774 struct dpi_data *dpi;
775
776 dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
777 if (!dpi)
778 return -ENOMEM;
Tomi Valkeinen00df43b2013-03-19 11:33:52 +0200779
Archit Taneja630d2d02014-05-30 16:26:22 +0530780 dpi->pdev = pdev;
781
782 dev_set_drvdata(&pdev->dev, dpi);
783
784 mutex_init(&dpi->lock);
Archit Tanejac8a5e4e2012-07-05 12:52:46 +0530785
Archit Taneja81b87f52012-09-26 16:30:49 +0530786 dpi_init_output(pdev);
787
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300788 return 0;
789}
790
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200791static int __exit omap_dpi_remove(struct platform_device *pdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300792{
Archit Taneja81b87f52012-09-26 16:30:49 +0530793 dpi_uninit_output(pdev);
794
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200795 return 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300796}
797
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200798static struct platform_driver omap_dpi_driver = {
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300799 .probe = omap_dpi_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200800 .remove = __exit_p(omap_dpi_remove),
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200801 .driver = {
802 .name = "omapdss_dpi",
803 .owner = THIS_MODULE,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300804 .suppress_bind_attrs = true,
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200805 },
806};
807
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200808int __init dpi_init_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200809{
Tomi Valkeinen94cf3942013-04-26 14:27:44 +0300810 return platform_driver_register(&omap_dpi_driver);
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200811}
812
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200813void __exit dpi_uninit_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200814{
815 platform_driver_unregister(&omap_dpi_driver);
816}
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200817
818int __init dpi_init_port(struct platform_device *pdev, struct device_node *port)
819{
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530820 struct dpi_data *dpi;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200821 struct device_node *ep;
822 u32 datalines;
823 int r;
824
Archit Taneja2ac6a1a2014-06-01 12:47:44 +0530825 dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
826 if (!dpi)
827 return -ENOMEM;
828
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200829 ep = omapdss_of_get_next_endpoint(port, NULL);
830 if (!ep)
831 return 0;
832
833 r = of_property_read_u32(ep, "data-lines", &datalines);
834 if (r) {
835 DSSERR("failed to parse datalines\n");
836 goto err_datalines;
837 }
838
Archit Taneja630d2d02014-05-30 16:26:22 +0530839 dpi->data_lines = datalines;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200840
841 of_node_put(ep);
842
Archit Taneja630d2d02014-05-30 16:26:22 +0530843 dpi->pdev = pdev;
Archit Taneja80eb6752014-06-02 14:11:51 +0530844 port->data = dpi;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200845
Archit Taneja630d2d02014-05-30 16:26:22 +0530846 mutex_init(&dpi->lock);
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200847
Archit Taneja80eb6752014-06-02 14:11:51 +0530848 dpi_init_output_port(pdev, port);
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200849
Archit Taneja630d2d02014-05-30 16:26:22 +0530850 dpi->port_initialized = true;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200851
852 return 0;
853
854err_datalines:
855 of_node_put(ep);
856
857 return r;
858}
859
Archit Taneja80eb6752014-06-02 14:11:51 +0530860void __exit dpi_uninit_port(struct device_node *port)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200861{
Archit Taneja80eb6752014-06-02 14:11:51 +0530862 struct dpi_data *dpi = port->data;
Archit Taneja630d2d02014-05-30 16:26:22 +0530863
864 if (!dpi->port_initialized)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200865 return;
866
Archit Taneja80eb6752014-06-02 14:11:51 +0530867 dpi_uninit_output_port(port);
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200868}