blob: d55266c0e02982d3fea4a986dae789a5a27242af [file] [log] [blame]
Tomi Valkeinen559d6702009-11-03 11:23:50 +02001/*
2 * linux/drivers/video/omap2/dss/dss.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 "DSS"
24
25#include <linux/kernel.h>
Tomi Valkeinen2ecef242013-12-16 15:13:24 +020026#include <linux/module.h>
Tomi Valkeinen559d6702009-11-03 11:23:50 +020027#include <linux/io.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040028#include <linux/export.h>
Tomi Valkeinen559d6702009-11-03 11:23:50 +020029#include <linux/err.h>
30#include <linux/delay.h>
Tomi Valkeinen559d6702009-11-03 11:23:50 +020031#include <linux/seq_file.h>
32#include <linux/clk.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030033#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030034#include <linux/pm_runtime.h>
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053035#include <linux/gfp.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030036#include <linux/sizes.h>
Tomi Valkeinen2ecef242013-12-16 15:13:24 +020037#include <linux/of.h>
Tomi Valkeinen559d6702009-11-03 11:23:50 +020038
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030039#include <video/omapdss.h>
Tony Lindgren2c799ce2012-02-24 10:34:35 -080040
Tomi Valkeinen559d6702009-11-03 11:23:50 +020041#include "dss.h"
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +020042#include "dss_features.h"
Tomi Valkeinen559d6702009-11-03 11:23:50 +020043
Tomi Valkeinen559d6702009-11-03 11:23:50 +020044#define DSS_SZ_REGS SZ_512
45
46struct dss_reg {
47 u16 idx;
48};
49
50#define DSS_REG(idx) ((const struct dss_reg) { idx })
51
52#define DSS_REVISION DSS_REG(0x0000)
53#define DSS_SYSCONFIG DSS_REG(0x0010)
54#define DSS_SYSSTATUS DSS_REG(0x0014)
Tomi Valkeinen559d6702009-11-03 11:23:50 +020055#define DSS_CONTROL DSS_REG(0x0040)
56#define DSS_SDI_CONTROL DSS_REG(0x0044)
57#define DSS_PLL_CONTROL DSS_REG(0x0048)
58#define DSS_SDI_STATUS DSS_REG(0x005C)
59
60#define REG_GET(idx, start, end) \
61 FLD_GET(dss_read_reg(idx), start, end)
62
63#define REG_FLD_MOD(idx, val, start, end) \
64 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
65
Tomi Valkeinen852f0832012-02-17 17:58:04 +020066static int dss_runtime_get(void);
67static void dss_runtime_put(void);
68
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053069struct dss_features {
70 u8 fck_div_max;
71 u8 dss_fck_multiplier;
Tomi Valkeinen64ad8462013-11-01 11:38:04 +020072 const char *parent_clk_name;
Tomi Valkeinende09e452012-09-21 12:09:54 +030073 int (*dpi_select_source)(enum omap_channel channel);
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053074};
75
Tomi Valkeinen559d6702009-11-03 11:23:50 +020076static struct {
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +000077 struct platform_device *pdev;
Tomi Valkeinen559d6702009-11-03 11:23:50 +020078 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030079
Tomi Valkeinen64ad8462013-11-01 11:38:04 +020080 struct clk *parent_clk;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030081 struct clk *dss_clk;
Tomi Valkeinen5aaee692012-12-12 10:37:03 +020082 unsigned long dss_clk_rate;
Tomi Valkeinen559d6702009-11-03 11:23:50 +020083
84 unsigned long cache_req_pck;
85 unsigned long cache_prate;
Tomi Valkeinen559d6702009-11-03 11:23:50 +020086 struct dispc_clock_info cache_dispc_cinfo;
87
Archit Taneja5a8b5722011-05-12 17:26:29 +053088 enum omap_dss_clk_source dsi_clk_source[MAX_NUM_DSI];
Archit Taneja89a35e52011-04-12 13:52:23 +053089 enum omap_dss_clk_source dispc_clk_source;
90 enum omap_dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS];
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +020091
Tomi Valkeinen69f06052011-06-01 15:56:39 +030092 bool ctx_valid;
Tomi Valkeinen559d6702009-11-03 11:23:50 +020093 u32 ctx[DSS_SZ_REGS / sizeof(u32)];
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053094
95 const struct dss_features *feat;
Tomi Valkeinen559d6702009-11-03 11:23:50 +020096} dss;
97
Taneja, Archit235e7db2011-03-14 23:28:21 -050098static const char * const dss_generic_clk_source_names[] = {
Archit Taneja89a35e52011-04-12 13:52:23 +053099 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI_PLL_HSDIV_DISPC",
100 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI_PLL_HSDIV_DSI",
101 [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCK",
Tomi Valkeinen901e5fe2011-11-30 17:34:52 +0200102 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC] = "DSI_PLL2_HSDIV_DISPC",
103 [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI] = "DSI_PLL2_HSDIV_DSI",
Archit Taneja067a57e2011-03-02 11:57:25 +0530104};
105
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200106static inline void dss_write_reg(const struct dss_reg idx, u32 val)
107{
108 __raw_writel(val, dss.base + idx.idx);
109}
110
111static inline u32 dss_read_reg(const struct dss_reg idx)
112{
113 return __raw_readl(dss.base + idx.idx);
114}
115
116#define SR(reg) \
117 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
118#define RR(reg) \
119 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
120
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300121static void dss_save_context(void)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200122{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300123 DSSDBG("dss_save_context\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200124
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200125 SR(CONTROL);
126
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200127 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) &
128 OMAP_DISPLAY_TYPE_SDI) {
129 SR(SDI_CONTROL);
130 SR(PLL_CONTROL);
131 }
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300132
133 dss.ctx_valid = true;
134
135 DSSDBG("context saved\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200136}
137
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300138static void dss_restore_context(void)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200139{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300140 DSSDBG("dss_restore_context\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200141
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300142 if (!dss.ctx_valid)
143 return;
144
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200145 RR(CONTROL);
146
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200147 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) &
148 OMAP_DISPLAY_TYPE_SDI) {
149 RR(SDI_CONTROL);
150 RR(PLL_CONTROL);
151 }
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300152
153 DSSDBG("context restored\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200154}
155
156#undef SR
157#undef RR
158
Archit Taneja889b4fd2012-07-20 17:18:49 +0530159void dss_sdi_init(int datapairs)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200160{
161 u32 l;
162
163 BUG_ON(datapairs > 3 || datapairs < 1);
164
165 l = dss_read_reg(DSS_SDI_CONTROL);
166 l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */
167 l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */
168 l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */
169 dss_write_reg(DSS_SDI_CONTROL, l);
170
171 l = dss_read_reg(DSS_PLL_CONTROL);
172 l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
173 l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */
174 l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */
175 dss_write_reg(DSS_PLL_CONTROL, l);
176}
177
178int dss_sdi_enable(void)
179{
180 unsigned long timeout;
181
182 dispc_pck_free_enable(1);
183
184 /* Reset SDI PLL */
185 REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */
186 udelay(1); /* wait 2x PCLK */
187
188 /* Lock SDI PLL */
189 REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */
190
191 /* Waiting for PLL lock request to complete */
192 timeout = jiffies + msecs_to_jiffies(500);
193 while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) {
194 if (time_after_eq(jiffies, timeout)) {
195 DSSERR("PLL lock request timed out\n");
196 goto err1;
197 }
198 }
199
200 /* Clearing PLL_GO bit */
201 REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28);
202
203 /* Waiting for PLL to lock */
204 timeout = jiffies + msecs_to_jiffies(500);
205 while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) {
206 if (time_after_eq(jiffies, timeout)) {
207 DSSERR("PLL lock timed out\n");
208 goto err1;
209 }
210 }
211
212 dispc_lcd_enable_signal(1);
213
214 /* Waiting for SDI reset to complete */
215 timeout = jiffies + msecs_to_jiffies(500);
216 while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) {
217 if (time_after_eq(jiffies, timeout)) {
218 DSSERR("SDI reset timed out\n");
219 goto err2;
220 }
221 }
222
223 return 0;
224
225 err2:
226 dispc_lcd_enable_signal(0);
227 err1:
228 /* Reset SDI PLL */
229 REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
230
231 dispc_pck_free_enable(0);
232
233 return -ETIMEDOUT;
234}
235
236void dss_sdi_disable(void)
237{
238 dispc_lcd_enable_signal(0);
239
240 dispc_pck_free_enable(0);
241
242 /* Reset SDI PLL */
243 REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
244}
245
Archit Taneja89a35e52011-04-12 13:52:23 +0530246const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src)
Archit Taneja067a57e2011-03-02 11:57:25 +0530247{
Taneja, Archit235e7db2011-03-14 23:28:21 -0500248 return dss_generic_clk_source_names[clk_src];
Archit Taneja067a57e2011-03-02 11:57:25 +0530249}
250
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200251void dss_dump_clocks(struct seq_file *s)
252{
Tomi Valkeinen0acf6592011-03-14 07:28:57 -0500253 const char *fclk_name, *fclk_real_name;
254 unsigned long fclk_rate;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200255
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300256 if (dss_runtime_get())
257 return;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200258
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200259 seq_printf(s, "- DSS -\n");
260
Archit Taneja89a35e52011-04-12 13:52:23 +0530261 fclk_name = dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK);
262 fclk_real_name = dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300263 fclk_rate = clk_get_rate(dss.dss_clk);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200264
Tomi Valkeinen9c15d762013-11-01 11:36:10 +0200265 seq_printf(s, "%s (%s) = %lu\n",
266 fclk_name, fclk_real_name,
267 fclk_rate);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200268
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300269 dss_runtime_put();
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200270}
271
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200272static void dss_dump_regs(struct seq_file *s)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200273{
274#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
275
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300276 if (dss_runtime_get())
277 return;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200278
279 DUMPREG(DSS_REVISION);
280 DUMPREG(DSS_SYSCONFIG);
281 DUMPREG(DSS_SYSSTATUS);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200282 DUMPREG(DSS_CONTROL);
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200283
284 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) &
285 OMAP_DISPLAY_TYPE_SDI) {
286 DUMPREG(DSS_SDI_CONTROL);
287 DUMPREG(DSS_PLL_CONTROL);
288 DUMPREG(DSS_SDI_STATUS);
289 }
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200290
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300291 dss_runtime_put();
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200292#undef DUMPREG
293}
294
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300295static void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200296{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530297 struct platform_device *dsidev;
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200298 int b;
Taneja, Architea751592011-03-08 05:50:35 -0600299 u8 start, end;
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200300
Taneja, Archit66534e82011-03-08 05:50:34 -0600301 switch (clk_src) {
Archit Taneja89a35e52011-04-12 13:52:23 +0530302 case OMAP_DSS_CLK_SRC_FCK:
Taneja, Archit66534e82011-03-08 05:50:34 -0600303 b = 0;
304 break;
Archit Taneja89a35e52011-04-12 13:52:23 +0530305 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Taneja, Archit66534e82011-03-08 05:50:34 -0600306 b = 1;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530307 dsidev = dsi_get_dsidev_from_id(0);
308 dsi_wait_pll_hsdiv_dispc_active(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -0600309 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +0530310 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
311 b = 2;
312 dsidev = dsi_get_dsidev_from_id(1);
313 dsi_wait_pll_hsdiv_dispc_active(dsidev);
314 break;
Taneja, Archit66534e82011-03-08 05:50:34 -0600315 default:
316 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300317 return;
Taneja, Archit66534e82011-03-08 05:50:34 -0600318 }
Tomi Valkeinene406f902010-06-09 15:28:12 +0300319
Taneja, Architea751592011-03-08 05:50:35 -0600320 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end);
321
322 REG_FLD_MOD(DSS_CONTROL, b, start, end); /* DISPC_CLK_SWITCH */
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200323
324 dss.dispc_clk_source = clk_src;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200325}
326
Archit Taneja5a8b5722011-05-12 17:26:29 +0530327void dss_select_dsi_clk_source(int dsi_module,
328 enum omap_dss_clk_source clk_src)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200329{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530330 struct platform_device *dsidev;
Archit Tanejaa2e5d822012-05-07 16:51:35 +0530331 int b, pos;
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200332
Taneja, Archit66534e82011-03-08 05:50:34 -0600333 switch (clk_src) {
Archit Taneja89a35e52011-04-12 13:52:23 +0530334 case OMAP_DSS_CLK_SRC_FCK:
Taneja, Archit66534e82011-03-08 05:50:34 -0600335 b = 0;
336 break;
Archit Taneja89a35e52011-04-12 13:52:23 +0530337 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI:
Archit Taneja5a8b5722011-05-12 17:26:29 +0530338 BUG_ON(dsi_module != 0);
Taneja, Archit66534e82011-03-08 05:50:34 -0600339 b = 1;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530340 dsidev = dsi_get_dsidev_from_id(0);
341 dsi_wait_pll_hsdiv_dsi_active(dsidev);
Taneja, Archit66534e82011-03-08 05:50:34 -0600342 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +0530343 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI:
344 BUG_ON(dsi_module != 1);
345 b = 1;
346 dsidev = dsi_get_dsidev_from_id(1);
347 dsi_wait_pll_hsdiv_dsi_active(dsidev);
348 break;
Taneja, Archit66534e82011-03-08 05:50:34 -0600349 default:
350 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300351 return;
Taneja, Archit66534e82011-03-08 05:50:34 -0600352 }
Tomi Valkeinene406f902010-06-09 15:28:12 +0300353
Archit Tanejaa2e5d822012-05-07 16:51:35 +0530354 pos = dsi_module == 0 ? 1 : 10;
355 REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200356
Archit Taneja5a8b5722011-05-12 17:26:29 +0530357 dss.dsi_clk_source[dsi_module] = clk_src;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200358}
359
Taneja, Architea751592011-03-08 05:50:35 -0600360void dss_select_lcd_clk_source(enum omap_channel channel,
Archit Taneja89a35e52011-04-12 13:52:23 +0530361 enum omap_dss_clk_source clk_src)
Taneja, Architea751592011-03-08 05:50:35 -0600362{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530363 struct platform_device *dsidev;
Taneja, Architea751592011-03-08 05:50:35 -0600364 int b, ix, pos;
365
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300366 if (!dss_has_feature(FEAT_LCD_CLK_SRC)) {
367 dss_select_dispc_clk_source(clk_src);
Taneja, Architea751592011-03-08 05:50:35 -0600368 return;
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300369 }
Taneja, Architea751592011-03-08 05:50:35 -0600370
371 switch (clk_src) {
Archit Taneja89a35e52011-04-12 13:52:23 +0530372 case OMAP_DSS_CLK_SRC_FCK:
Taneja, Architea751592011-03-08 05:50:35 -0600373 b = 0;
374 break;
Archit Taneja89a35e52011-04-12 13:52:23 +0530375 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
Taneja, Architea751592011-03-08 05:50:35 -0600376 BUG_ON(channel != OMAP_DSS_CHANNEL_LCD);
377 b = 1;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530378 dsidev = dsi_get_dsidev_from_id(0);
379 dsi_wait_pll_hsdiv_dispc_active(dsidev);
Taneja, Architea751592011-03-08 05:50:35 -0600380 break;
Archit Taneja5a8b5722011-05-12 17:26:29 +0530381 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530382 BUG_ON(channel != OMAP_DSS_CHANNEL_LCD2 &&
383 channel != OMAP_DSS_CHANNEL_LCD3);
Archit Taneja5a8b5722011-05-12 17:26:29 +0530384 b = 1;
385 dsidev = dsi_get_dsidev_from_id(1);
386 dsi_wait_pll_hsdiv_dispc_active(dsidev);
387 break;
Taneja, Architea751592011-03-08 05:50:35 -0600388 default:
389 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300390 return;
Taneja, Architea751592011-03-08 05:50:35 -0600391 }
392
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530393 pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 :
394 (channel == OMAP_DSS_CHANNEL_LCD2 ? 12 : 19);
Taneja, Architea751592011-03-08 05:50:35 -0600395 REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* LCDx_CLK_SWITCH */
396
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530397 ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 :
398 (channel == OMAP_DSS_CHANNEL_LCD2 ? 1 : 2);
Taneja, Architea751592011-03-08 05:50:35 -0600399 dss.lcd_clk_source[ix] = clk_src;
400}
401
Archit Taneja89a35e52011-04-12 13:52:23 +0530402enum omap_dss_clk_source dss_get_dispc_clk_source(void)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200403{
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200404 return dss.dispc_clk_source;
405}
406
Archit Taneja5a8b5722011-05-12 17:26:29 +0530407enum omap_dss_clk_source dss_get_dsi_clk_source(int dsi_module)
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200408{
Archit Taneja5a8b5722011-05-12 17:26:29 +0530409 return dss.dsi_clk_source[dsi_module];
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200410}
411
Archit Taneja89a35e52011-04-12 13:52:23 +0530412enum omap_dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel)
Taneja, Architea751592011-03-08 05:50:35 -0600413{
Archit Taneja89976f22011-03-31 13:23:35 +0530414 if (dss_has_feature(FEAT_LCD_CLK_SRC)) {
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +0530415 int ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 :
416 (channel == OMAP_DSS_CHANNEL_LCD2 ? 1 : 2);
Archit Taneja89976f22011-03-31 13:23:35 +0530417 return dss.lcd_clk_source[ix];
418 } else {
419 /* LCD_CLK source is the same as DISPC_FCLK source for
420 * OMAP2 and OMAP3 */
421 return dss.dispc_clk_source;
422 }
Taneja, Architea751592011-03-08 05:50:35 -0600423}
424
Tomi Valkeinen688af022013-10-31 16:41:57 +0200425bool dss_div_calc(unsigned long pck, unsigned long fck_min,
426 dss_div_calc_func func, void *data)
Tomi Valkeinen43417822013-03-05 16:34:05 +0200427{
428 int fckd, fckd_start, fckd_stop;
429 unsigned long fck;
430 unsigned long fck_hw_max;
431 unsigned long fckd_hw_max;
432 unsigned long prate;
Tomi Valkeinen648a55e2013-04-10 14:47:38 +0300433 unsigned m;
Tomi Valkeinen43417822013-03-05 16:34:05 +0200434
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200435 fck_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
436
Tomi Valkeinen64ad8462013-11-01 11:38:04 +0200437 if (dss.parent_clk == NULL) {
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200438 unsigned pckd;
439
440 pckd = fck_hw_max / pck;
441
442 fck = pck * pckd;
443
444 fck = clk_round_rate(dss.dss_clk, fck);
445
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200446 return func(fck, data);
Tomi Valkeinen43417822013-03-05 16:34:05 +0200447 }
448
Tomi Valkeinen43417822013-03-05 16:34:05 +0200449 fckd_hw_max = dss.feat->fck_div_max;
450
Tomi Valkeinen648a55e2013-04-10 14:47:38 +0300451 m = dss.feat->dss_fck_multiplier;
Tomi Valkeinenada94432013-10-31 16:06:38 +0200452 prate = clk_get_rate(dss.parent_clk);
Tomi Valkeinen43417822013-03-05 16:34:05 +0200453
454 fck_min = fck_min ? fck_min : 1;
455
Tomi Valkeinen648a55e2013-04-10 14:47:38 +0300456 fckd_start = min(prate * m / fck_min, fckd_hw_max);
457 fckd_stop = max(DIV_ROUND_UP(prate * m, fck_hw_max), 1ul);
Tomi Valkeinen43417822013-03-05 16:34:05 +0200458
459 for (fckd = fckd_start; fckd >= fckd_stop; --fckd) {
Tomi Valkeinend0e224f2014-02-13 11:36:22 +0200460 fck = DIV_ROUND_UP(prate, fckd) * m;
Tomi Valkeinen43417822013-03-05 16:34:05 +0200461
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200462 if (func(fck, data))
Tomi Valkeinen43417822013-03-05 16:34:05 +0200463 return true;
464 }
465
466 return false;
467}
468
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200469int dss_set_fck_rate(unsigned long rate)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200470{
Tomi Valkeinenada94432013-10-31 16:06:38 +0200471 int r;
472
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200473 DSSDBG("set fck to %lu\n", rate);
474
Tomi Valkeinenada94432013-10-31 16:06:38 +0200475 r = clk_set_rate(dss.dss_clk, rate);
476 if (r)
477 return r;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200478
Tomi Valkeinen5aaee692012-12-12 10:37:03 +0200479 dss.dss_clk_rate = clk_get_rate(dss.dss_clk);
480
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200481 WARN_ONCE(dss.dss_clk_rate != rate,
Tomi Valkeinen648a55e2013-04-10 14:47:38 +0300482 "clk rate mismatch: %lu != %lu", dss.dss_clk_rate,
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200483 rate);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200484
485 return 0;
486}
487
Tomi Valkeinen5aaee692012-12-12 10:37:03 +0200488unsigned long dss_get_dispc_clk_rate(void)
489{
490 return dss.dss_clk_rate;
491}
492
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300493static int dss_setup_default_clock(void)
494{
495 unsigned long max_dss_fck, prate;
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200496 unsigned long fck;
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300497 unsigned fck_div;
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300498 int r;
499
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300500 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
501
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200502 if (dss.parent_clk == NULL) {
503 fck = clk_round_rate(dss.dss_clk, max_dss_fck);
504 } else {
505 prate = clk_get_rate(dss.parent_clk);
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300506
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200507 fck_div = DIV_ROUND_UP(prate * dss.feat->dss_fck_multiplier,
508 max_dss_fck);
Tomi Valkeinend0e224f2014-02-13 11:36:22 +0200509 fck = DIV_ROUND_UP(prate, fck_div) * dss.feat->dss_fck_multiplier;
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200510 }
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300511
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200512 r = dss_set_fck_rate(fck);
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300513 if (r)
514 return r;
515
516 return 0;
517}
518
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200519void dss_set_venc_output(enum omap_dss_venc_type type)
520{
521 int l = 0;
522
523 if (type == OMAP_DSS_VENC_TYPE_COMPOSITE)
524 l = 0;
525 else if (type == OMAP_DSS_VENC_TYPE_SVIDEO)
526 l = 1;
527 else
528 BUG();
529
530 /* venc out selection. 0 = comp, 1 = svideo */
531 REG_FLD_MOD(DSS_CONTROL, l, 6, 6);
532}
533
534void dss_set_dac_pwrdn_bgz(bool enable)
535{
536 REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */
537}
538
Ricardo Neri8aa2eed2012-08-01 07:56:40 -0500539void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src)
Mythri P K7ed024a2011-03-09 16:31:38 +0530540{
Ricardo Neri8aa2eed2012-08-01 07:56:40 -0500541 enum omap_display_type dp;
542 dp = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT);
543
544 /* Complain about invalid selections */
545 WARN_ON((src == DSS_VENC_TV_CLK) && !(dp & OMAP_DISPLAY_TYPE_VENC));
546 WARN_ON((src == DSS_HDMI_M_PCLK) && !(dp & OMAP_DISPLAY_TYPE_HDMI));
547
548 /* Select only if we have options */
549 if ((dp & OMAP_DISPLAY_TYPE_VENC) && (dp & OMAP_DISPLAY_TYPE_HDMI))
550 REG_FLD_MOD(DSS_CONTROL, src, 15, 15); /* VENC_HDMI_SWITCH */
Mythri P K7ed024a2011-03-09 16:31:38 +0530551}
552
Tomi Valkeinen4a61e262011-08-31 14:33:31 +0300553enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void)
554{
555 enum omap_display_type displays;
556
557 displays = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT);
558 if ((displays & OMAP_DISPLAY_TYPE_HDMI) == 0)
559 return DSS_VENC_TV_CLK;
560
Ricardo Neri8aa2eed2012-08-01 07:56:40 -0500561 if ((displays & OMAP_DISPLAY_TYPE_VENC) == 0)
562 return DSS_HDMI_M_PCLK;
563
Tomi Valkeinen4a61e262011-08-31 14:33:31 +0300564 return REG_GET(DSS_CONTROL, 15, 15);
565}
566
Tomi Valkeinende09e452012-09-21 12:09:54 +0300567static int dss_dpi_select_source_omap2_omap3(enum omap_channel channel)
568{
569 if (channel != OMAP_DSS_CHANNEL_LCD)
570 return -EINVAL;
571
572 return 0;
573}
574
575static int dss_dpi_select_source_omap4(enum omap_channel channel)
576{
577 int val;
578
579 switch (channel) {
580 case OMAP_DSS_CHANNEL_LCD2:
581 val = 0;
582 break;
583 case OMAP_DSS_CHANNEL_DIGIT:
584 val = 1;
585 break;
586 default:
587 return -EINVAL;
588 }
589
590 REG_FLD_MOD(DSS_CONTROL, val, 17, 17);
591
592 return 0;
593}
594
595static int dss_dpi_select_source_omap5(enum omap_channel channel)
596{
597 int val;
598
599 switch (channel) {
600 case OMAP_DSS_CHANNEL_LCD:
601 val = 1;
602 break;
603 case OMAP_DSS_CHANNEL_LCD2:
604 val = 2;
605 break;
606 case OMAP_DSS_CHANNEL_LCD3:
607 val = 3;
608 break;
609 case OMAP_DSS_CHANNEL_DIGIT:
610 val = 0;
611 break;
612 default:
613 return -EINVAL;
614 }
615
616 REG_FLD_MOD(DSS_CONTROL, val, 17, 16);
617
618 return 0;
619}
620
621int dss_dpi_select_source(enum omap_channel channel)
622{
623 return dss.feat->dpi_select_source(channel);
624}
625
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000626static int dss_get_clocks(void)
627{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300628 struct clk *clk;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000629
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300630 clk = devm_clk_get(&dss.pdev->dev, "fck");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300631 if (IS_ERR(clk)) {
632 DSSERR("can't get clock fck\n");
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300633 return PTR_ERR(clk);
Semwal, Sumita1a0dcc2011-03-01 02:42:14 -0600634 }
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000635
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300636 dss.dss_clk = clk;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000637
Tomi Valkeinen64ad8462013-11-01 11:38:04 +0200638 if (dss.feat->parent_clk_name) {
639 clk = clk_get(NULL, dss.feat->parent_clk_name);
Aaro Koskinen8ad93752012-11-21 21:48:51 +0200640 if (IS_ERR(clk)) {
Tomi Valkeinen64ad8462013-11-01 11:38:04 +0200641 DSSERR("Failed to get %s\n", dss.feat->parent_clk_name);
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300642 return PTR_ERR(clk);
Aaro Koskinen8ad93752012-11-21 21:48:51 +0200643 }
644 } else {
645 clk = NULL;
Tomi Valkeinen94c042c2011-05-16 13:43:04 +0300646 }
647
Tomi Valkeinen64ad8462013-11-01 11:38:04 +0200648 dss.parent_clk = clk;
Tomi Valkeinen94c042c2011-05-16 13:43:04 +0300649
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000650 return 0;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000651}
652
653static void dss_put_clocks(void)
654{
Tomi Valkeinen64ad8462013-11-01 11:38:04 +0200655 if (dss.parent_clk)
656 clk_put(dss.parent_clk);
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000657}
658
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200659static int dss_runtime_get(void)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000660{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300661 int r;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000662
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300663 DSSDBG("dss_runtime_get\n");
664
665 r = pm_runtime_get_sync(&dss.pdev->dev);
666 WARN_ON(r < 0);
667 return r < 0 ? r : 0;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000668}
669
Tomi Valkeinen852f0832012-02-17 17:58:04 +0200670static void dss_runtime_put(void)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000671{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300672 int r;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000673
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300674 DSSDBG("dss_runtime_put\n");
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000675
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +0200676 r = pm_runtime_put_sync(&dss.pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300677 WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY);
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000678}
679
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000680/* DEBUGFS */
Chandrabhanu Mahapatra1b3bcb32012-09-29 11:25:42 +0530681#if defined(CONFIG_OMAP2_DSS_DEBUGFS)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000682void dss_debug_dump_clocks(struct seq_file *s)
683{
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000684 dss_dump_clocks(s);
685 dispc_dump_clocks(s);
686#ifdef CONFIG_OMAP2_DSS_DSI
687 dsi_dump_clocks(s);
688#endif
689}
690#endif
691
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300692static const struct dss_features omap24xx_dss_feats __initconst = {
Tomi Valkeinen6e555e22013-11-01 11:26:43 +0200693 /*
694 * fck div max is really 16, but the divider range has gaps. The range
695 * from 1 to 6 has no gaps, so let's use that as a max.
696 */
697 .fck_div_max = 6,
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300698 .dss_fck_multiplier = 2,
Tomi Valkeinenada94432013-10-31 16:06:38 +0200699 .parent_clk_name = "core_ck",
Tomi Valkeinende09e452012-09-21 12:09:54 +0300700 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300701};
702
703static const struct dss_features omap34xx_dss_feats __initconst = {
704 .fck_div_max = 16,
705 .dss_fck_multiplier = 2,
Tomi Valkeinenada94432013-10-31 16:06:38 +0200706 .parent_clk_name = "dpll4_ck",
Tomi Valkeinende09e452012-09-21 12:09:54 +0300707 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300708};
709
710static const struct dss_features omap3630_dss_feats __initconst = {
711 .fck_div_max = 32,
712 .dss_fck_multiplier = 1,
Tomi Valkeinenada94432013-10-31 16:06:38 +0200713 .parent_clk_name = "dpll4_ck",
Tomi Valkeinende09e452012-09-21 12:09:54 +0300714 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300715};
716
717static const struct dss_features omap44xx_dss_feats __initconst = {
718 .fck_div_max = 32,
719 .dss_fck_multiplier = 1,
Tomi Valkeinenada94432013-10-31 16:06:38 +0200720 .parent_clk_name = "dpll_per_x2_ck",
Tomi Valkeinende09e452012-09-21 12:09:54 +0300721 .dpi_select_source = &dss_dpi_select_source_omap4,
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300722};
723
724static const struct dss_features omap54xx_dss_feats __initconst = {
725 .fck_div_max = 64,
726 .dss_fck_multiplier = 1,
Tomi Valkeinenada94432013-10-31 16:06:38 +0200727 .parent_clk_name = "dpll_per_x2_ck",
Tomi Valkeinende09e452012-09-21 12:09:54 +0300728 .dpi_select_source = &dss_dpi_select_source_omap5,
Tomi Valkeinen84273a92012-09-21 12:03:31 +0300729};
730
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300731static int __init dss_init_features(struct platform_device *pdev)
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530732{
733 const struct dss_features *src;
734 struct dss_features *dst;
735
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300736 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530737 if (!dst) {
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300738 dev_err(&pdev->dev, "Failed to allocate local DSS Features\n");
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530739 return -ENOMEM;
740 }
741
Tomi Valkeinenb2c7d542012-10-18 13:46:29 +0300742 switch (omapdss_get_version()) {
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300743 case OMAPDSS_VER_OMAP24xx:
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530744 src = &omap24xx_dss_feats;
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300745 break;
746
747 case OMAPDSS_VER_OMAP34xx_ES1:
748 case OMAPDSS_VER_OMAP34xx_ES3:
749 case OMAPDSS_VER_AM35xx:
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530750 src = &omap34xx_dss_feats;
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300751 break;
752
753 case OMAPDSS_VER_OMAP3630:
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530754 src = &omap3630_dss_feats;
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300755 break;
756
757 case OMAPDSS_VER_OMAP4430_ES1:
758 case OMAPDSS_VER_OMAP4430_ES2:
759 case OMAPDSS_VER_OMAP4:
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530760 src = &omap44xx_dss_feats;
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300761 break;
762
763 case OMAPDSS_VER_OMAP5:
Archit Taneja23362832012-04-08 16:47:01 +0530764 src = &omap54xx_dss_feats;
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300765 break;
766
767 default:
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530768 return -ENODEV;
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300769 }
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530770
771 memcpy(dst, src, sizeof(*dst));
772 dss.feat = dst;
773
774 return 0;
775}
776
Tomi Valkeinen5f0bc7a2014-03-20 11:55:02 +0200777static int __init dss_init_ports(struct platform_device *pdev)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200778{
779 struct device_node *parent = pdev->dev.of_node;
780 struct device_node *port;
781 int r;
782
783 if (parent == NULL)
784 return 0;
785
786 port = omapdss_of_get_next_port(parent, NULL);
787 if (!port) {
788#ifdef CONFIG_OMAP2_DSS_DPI
789 dpi_init_port(pdev, parent);
790#endif
791 return 0;
792 }
793
794 do {
795 u32 reg;
796
797 r = of_property_read_u32(port, "reg", &reg);
798 if (r)
799 reg = 0;
800
801#ifdef CONFIG_OMAP2_DSS_DPI
802 if (reg == 0)
803 dpi_init_port(pdev, port);
804#endif
805
806#ifdef CONFIG_OMAP2_DSS_SDI
807 if (reg == 1)
808 sdi_init_port(pdev, port);
809#endif
810
811 } while ((port = omapdss_of_get_next_port(parent, port)) != NULL);
812
813 return 0;
814}
815
816static void dss_uninit_ports(void)
817{
818#ifdef CONFIG_OMAP2_DSS_DPI
819 dpi_uninit_port();
820#endif
821
822#ifdef CONFIG_OMAP2_DSS_SDI
823 sdi_uninit_port();
824#endif
825}
826
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000827/* DSS HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200828static int __init omap_dsshw_probe(struct platform_device *pdev)
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000829{
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300830 struct resource *dss_mem;
831 u32 rev;
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000832 int r;
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000833
834 dss.pdev = pdev;
835
Tomi Valkeinenbd81ed02012-09-28 12:56:00 +0300836 r = dss_init_features(dss.pdev);
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +0530837 if (r)
838 return r;
839
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300840 dss_mem = platform_get_resource(dss.pdev, IORESOURCE_MEM, 0);
841 if (!dss_mem) {
842 DSSERR("can't get IORESOURCE_MEM DSS\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +0200843 return -EINVAL;
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300844 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +0200845
Julia Lawall6e2a14d2012-01-24 14:00:45 +0100846 dss.base = devm_ioremap(&pdev->dev, dss_mem->start,
847 resource_size(dss_mem));
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300848 if (!dss.base) {
849 DSSERR("can't ioremap DSS\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +0200850 return -ENOMEM;
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300851 }
852
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000853 r = dss_get_clocks();
854 if (r)
Tomi Valkeinencd3b3442012-01-25 13:31:04 +0200855 return r;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000856
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300857 r = dss_setup_default_clock();
858 if (r)
859 goto err_setup_clocks;
860
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300861 pm_runtime_enable(&pdev->dev);
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300862
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300863 r = dss_runtime_get();
864 if (r)
865 goto err_runtime_get;
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300866
Tomi Valkeinen5aaee692012-12-12 10:37:03 +0200867 dss.dss_clk_rate = clk_get_rate(dss.dss_clk);
868
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300869 /* Select DPLL */
870 REG_FLD_MOD(DSS_CONTROL, 0, 0, 0);
871
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300872 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
873
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300874#ifdef CONFIG_OMAP2_DSS_VENC
875 REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */
876 REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */
877 REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */
878#endif
879 dss.dsi_clk_source[0] = OMAP_DSS_CLK_SRC_FCK;
880 dss.dsi_clk_source[1] = OMAP_DSS_CLK_SRC_FCK;
881 dss.dispc_clk_source = OMAP_DSS_CLK_SRC_FCK;
882 dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK;
883 dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK;
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000884
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200885 dss_init_ports(pdev);
886
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300887 rev = dss_read_reg(DSS_REVISION);
888 printk(KERN_INFO "OMAP DSS rev %d.%d\n",
889 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
890
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300891 dss_runtime_put();
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300892
Tomi Valkeinene40402c2012-03-02 18:01:07 +0200893 dss_debugfs_create_file("dss", dss_dump_regs);
894
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000895 return 0;
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200896
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300897err_runtime_get:
898 pm_runtime_disable(&pdev->dev);
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300899err_setup_clocks:
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000900 dss_put_clocks();
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000901 return r;
902}
903
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200904static int __exit omap_dsshw_remove(struct platform_device *pdev)
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000905{
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200906 dss_uninit_ports();
907
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300908 pm_runtime_disable(&pdev->dev);
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000909
910 dss_put_clocks();
Tomi Valkeinenb98482e2011-05-16 13:52:51 +0300911
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000912 return 0;
913}
914
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300915static int dss_runtime_suspend(struct device *dev)
916{
917 dss_save_context();
Tomi Valkeinena8081d32012-03-08 12:52:38 +0200918 dss_set_min_bus_tput(dev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300919 return 0;
920}
921
922static int dss_runtime_resume(struct device *dev)
923{
Tomi Valkeinena8081d32012-03-08 12:52:38 +0200924 int r;
925 /*
926 * Set an arbitrarily high tput request to ensure OPP100.
927 * What we should really do is to make a request to stay in OPP100,
928 * without any tput requirements, but that is not currently possible
929 * via the PM layer.
930 */
931
932 r = dss_set_min_bus_tput(dev, 1000000000);
933 if (r)
934 return r;
935
Tomi Valkeinen39020712011-05-26 14:54:05 +0300936 dss_restore_context();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300937 return 0;
938}
939
940static const struct dev_pm_ops dss_pm_ops = {
941 .runtime_suspend = dss_runtime_suspend,
942 .runtime_resume = dss_runtime_resume,
943};
944
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200945static const struct of_device_id dss_of_match[] = {
946 { .compatible = "ti,omap2-dss", },
947 { .compatible = "ti,omap3-dss", },
948 { .compatible = "ti,omap4-dss", },
949 {},
950};
951
952MODULE_DEVICE_TABLE(of, dss_of_match);
953
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000954static struct platform_driver omap_dsshw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200955 .remove = __exit_p(omap_dsshw_remove),
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000956 .driver = {
957 .name = "omapdss_dss",
958 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300959 .pm = &dss_pm_ops,
Tomi Valkeinen2ecef242013-12-16 15:13:24 +0200960 .of_match_table = dss_of_match,
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000961 },
962};
963
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200964int __init dss_init_platform_driver(void)
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000965{
Tomi Valkeinen11436e12012-03-07 12:53:18 +0200966 return platform_driver_probe(&omap_dsshw_driver, omap_dsshw_probe);
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000967}
968
969void dss_uninit_platform_driver(void)
970{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +0200971 platform_driver_unregister(&omap_dsshw_driver);
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +0000972}