blob: 7a5f5f233ad0d6100cf8ee80a15adface623c3f2 [file] [log] [blame]
Tomi Valkeinen559d6702009-11-03 11:23:50 +02001/*
Tomi Valkeinen559d6702009-11-03 11:23:50 +02002 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
4 *
5 * Some code and ideas taken from drivers/video/omap/ driver
6 * by Imre Deak.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#define DSS_SUBSYS_NAME "DSS"
22
Laurent Pinchart11765d12017-08-05 01:44:01 +030023#include <linux/debugfs.h>
Laurent Pincharta921c1a2017-10-13 17:59:01 +030024#include <linux/dma-mapping.h>
Tomi Valkeinen559d6702009-11-03 11:23:50 +020025#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>
Arnd Bergmann2639d6b2016-05-09 23:51:27 +020033#include <linux/pinctrl/consumer.h>
Tomi Valkeinen24e62892011-05-23 11:51:18 +030034#include <linux/platform_device.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030035#include <linux/pm_runtime.h>
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053036#include <linux/gfp.h>
Tomi Valkeinen33366d02012-09-28 13:54:35 +030037#include <linux/sizes.h>
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +053038#include <linux/mfd/syscon.h>
39#include <linux/regmap.h>
Tomi Valkeinen2ecef242013-12-16 15:13:24 +020040#include <linux/of.h>
Laurent Pinchart18daeb82017-08-05 01:43:58 +030041#include <linux/of_device.h>
Rob Herring09bffa62017-03-22 08:26:08 -050042#include <linux/of_graph.h>
Tomi Valkeinen99767542014-07-04 13:38:27 +053043#include <linux/regulator/consumer.h>
Tomi Valkeinencb17a4a2015-02-25 12:08:14 +020044#include <linux/suspend.h>
Tomi Valkeinen736e60d2015-06-04 15:22:23 +030045#include <linux/component.h>
Laurent Pinchart18daeb82017-08-05 01:43:58 +030046#include <linux/sys_soc.h>
Tomi Valkeinen559d6702009-11-03 11:23:50 +020047
Peter Ujfalusi32043da2016-05-27 14:40:49 +030048#include "omapdss.h"
Tomi Valkeinen559d6702009-11-03 11:23:50 +020049#include "dss.h"
50
Tomi Valkeinen559d6702009-11-03 11:23:50 +020051struct dss_reg {
52 u16 idx;
53};
54
55#define DSS_REG(idx) ((const struct dss_reg) { idx })
56
57#define DSS_REVISION DSS_REG(0x0000)
58#define DSS_SYSCONFIG DSS_REG(0x0010)
59#define DSS_SYSSTATUS DSS_REG(0x0014)
Tomi Valkeinen559d6702009-11-03 11:23:50 +020060#define DSS_CONTROL DSS_REG(0x0040)
61#define DSS_SDI_CONTROL DSS_REG(0x0044)
62#define DSS_PLL_CONTROL DSS_REG(0x0048)
63#define DSS_SDI_STATUS DSS_REG(0x005C)
64
Laurent Pinchart360c2152018-02-13 14:00:28 +020065#define REG_GET(dss, idx, start, end) \
66 FLD_GET(dss_read_reg(dss, idx), start, end)
Tomi Valkeinen559d6702009-11-03 11:23:50 +020067
Laurent Pinchart360c2152018-02-13 14:00:28 +020068#define REG_FLD_MOD(dss, idx, val, start, end) \
69 dss_write_reg(dss, idx, \
70 FLD_MOD(dss_read_reg(dss, idx), val, start, end))
Tomi Valkeinen559d6702009-11-03 11:23:50 +020071
Laurent Pinchartfecea252017-08-05 01:43:52 +030072struct dss_ops {
Laurent Pinchart8aea8e62018-02-13 14:00:24 +020073 int (*dpi_select_source)(struct dss_device *dss, int port,
74 enum omap_channel channel);
75 int (*select_lcd_source)(struct dss_device *dss,
76 enum omap_channel channel,
77 enum dss_clk_source clk_src);
Laurent Pinchartfecea252017-08-05 01:43:52 +030078};
79
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053080struct dss_features {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +030081 enum dss_model model;
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053082 u8 fck_div_max;
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +030083 unsigned int fck_freq_max;
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053084 u8 dss_fck_multiplier;
Tomi Valkeinen64ad8462013-11-01 11:38:04 +020085 const char *parent_clk_name;
Tomi Valkeinen234f9a22014-12-11 15:59:31 +020086 const enum omap_display_type *ports;
Archit Taneja387ce9f2014-05-22 17:01:57 +053087 int num_ports;
Laurent Pinchart51919572017-08-05 01:44:18 +030088 const enum omap_dss_output_id *outputs;
Laurent Pinchartfecea252017-08-05 01:43:52 +030089 const struct dss_ops *ops;
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +030090 struct dss_reg_field dispc_clk_switch;
Laurent Pinchart4569ab72017-08-05 01:44:13 +030091 bool has_lcd_clk_src;
Chandrabhanu Mahapatra185bae12012-07-11 18:36:18 +053092};
93
Taneja, Archit235e7db2011-03-14 23:28:21 -050094static const char * const dss_generic_clk_source_names[] = {
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +030095 [DSS_CLK_SRC_FCK] = "FCK",
96 [DSS_CLK_SRC_PLL1_1] = "PLL1:1",
97 [DSS_CLK_SRC_PLL1_2] = "PLL1:2",
Tomi Valkeinenb5d8c752016-05-17 14:12:35 +030098 [DSS_CLK_SRC_PLL1_3] = "PLL1:3",
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +030099 [DSS_CLK_SRC_PLL2_1] = "PLL2:1",
100 [DSS_CLK_SRC_PLL2_2] = "PLL2:2",
Tomi Valkeinenb5d8c752016-05-17 14:12:35 +0300101 [DSS_CLK_SRC_PLL2_3] = "PLL2:3",
102 [DSS_CLK_SRC_HDMI_PLL] = "HDMI PLL",
Archit Taneja067a57e2011-03-02 11:57:25 +0530103};
104
Laurent Pinchart360c2152018-02-13 14:00:28 +0200105static inline void dss_write_reg(struct dss_device *dss,
106 const struct dss_reg idx, u32 val)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200107{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200108 __raw_writel(val, dss->base + idx.idx);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200109}
110
Laurent Pinchart360c2152018-02-13 14:00:28 +0200111static inline u32 dss_read_reg(struct dss_device *dss, const struct dss_reg idx)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200112{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200113 return __raw_readl(dss->base + idx.idx);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200114}
115
Laurent Pinchart360c2152018-02-13 14:00:28 +0200116#define SR(dss, reg) \
117 dss->ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(dss, DSS_##reg)
118#define RR(dss, reg) \
119 dss_write_reg(dss, DSS_##reg, dss->ctx[(DSS_##reg).idx / sizeof(u32)])
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200120
Laurent Pinchart360c2152018-02-13 14:00:28 +0200121static void dss_save_context(struct dss_device *dss)
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
Laurent Pinchart360c2152018-02-13 14:00:28 +0200125 SR(dss, CONTROL);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200126
Laurent Pinchart360c2152018-02-13 14:00:28 +0200127 if (dss->feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
128 SR(dss, SDI_CONTROL);
129 SR(dss, PLL_CONTROL);
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200130 }
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300131
Laurent Pinchart360c2152018-02-13 14:00:28 +0200132 dss->ctx_valid = true;
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300133
134 DSSDBG("context saved\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200135}
136
Laurent Pinchart360c2152018-02-13 14:00:28 +0200137static void dss_restore_context(struct dss_device *dss)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200138{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300139 DSSDBG("dss_restore_context\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200140
Laurent Pinchart360c2152018-02-13 14:00:28 +0200141 if (!dss->ctx_valid)
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300142 return;
143
Laurent Pinchart360c2152018-02-13 14:00:28 +0200144 RR(dss, CONTROL);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200145
Laurent Pinchart360c2152018-02-13 14:00:28 +0200146 if (dss->feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
147 RR(dss, SDI_CONTROL);
148 RR(dss, PLL_CONTROL);
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200149 }
Tomi Valkeinen69f06052011-06-01 15:56:39 +0300150
151 DSSDBG("context restored\n");
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200152}
153
154#undef SR
155#undef RR
156
Laurent Pinchart27260992018-02-13 14:00:22 +0200157void dss_ctrl_pll_enable(struct dss_pll *pll, bool enable)
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530158{
Laurent Pinchartd11e5c82018-02-11 15:07:34 +0200159 unsigned int shift;
160 unsigned int val;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530161
Laurent Pinchart27260992018-02-13 14:00:22 +0200162 if (!pll->dss->syscon_pll_ctrl)
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530163 return;
164
165 val = !enable;
166
Laurent Pinchart27260992018-02-13 14:00:22 +0200167 switch (pll->id) {
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530168 case DSS_PLL_VIDEO1:
169 shift = 0;
170 break;
171 case DSS_PLL_VIDEO2:
172 shift = 1;
173 break;
174 case DSS_PLL_HDMI:
175 shift = 2;
176 break;
177 default:
Laurent Pinchart27260992018-02-13 14:00:22 +0200178 DSSERR("illegal DSS PLL ID %d\n", pll->id);
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530179 return;
180 }
181
Laurent Pinchart27260992018-02-13 14:00:22 +0200182 regmap_update_bits(pll->dss->syscon_pll_ctrl,
183 pll->dss->syscon_pll_ctrl_offset,
184 1 << shift, val << shift);
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530185}
186
Laurent Pinchart360c2152018-02-13 14:00:28 +0200187static int dss_ctrl_pll_set_control_mux(struct dss_device *dss,
188 enum dss_clk_source clk_src,
189 enum omap_channel channel)
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530190{
Laurent Pinchartd11e5c82018-02-11 15:07:34 +0200191 unsigned int shift, val;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530192
Laurent Pinchart360c2152018-02-13 14:00:28 +0200193 if (!dss->syscon_pll_ctrl)
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300194 return -EINVAL;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530195
196 switch (channel) {
197 case OMAP_DSS_CHANNEL_LCD:
198 shift = 3;
199
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300200 switch (clk_src) {
201 case DSS_CLK_SRC_PLL1_1:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530202 val = 0; break;
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300203 case DSS_CLK_SRC_HDMI_PLL:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530204 val = 1; break;
205 default:
206 DSSERR("error in PLL mux config for LCD\n");
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300207 return -EINVAL;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530208 }
209
210 break;
211 case OMAP_DSS_CHANNEL_LCD2:
212 shift = 5;
213
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300214 switch (clk_src) {
215 case DSS_CLK_SRC_PLL1_3:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530216 val = 0; break;
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300217 case DSS_CLK_SRC_PLL2_3:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530218 val = 1; break;
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300219 case DSS_CLK_SRC_HDMI_PLL:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530220 val = 2; break;
221 default:
222 DSSERR("error in PLL mux config for LCD2\n");
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300223 return -EINVAL;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530224 }
225
226 break;
227 case OMAP_DSS_CHANNEL_LCD3:
228 shift = 7;
229
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300230 switch (clk_src) {
231 case DSS_CLK_SRC_PLL2_1:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530232 val = 0; break;
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300233 case DSS_CLK_SRC_PLL1_3:
234 val = 1; break;
235 case DSS_CLK_SRC_HDMI_PLL:
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530236 val = 2; break;
237 default:
238 DSSERR("error in PLL mux config for LCD3\n");
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300239 return -EINVAL;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530240 }
241
242 break;
243 default:
244 DSSERR("error in PLL mux config\n");
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300245 return -EINVAL;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530246 }
247
Laurent Pinchart360c2152018-02-13 14:00:28 +0200248 regmap_update_bits(dss->syscon_pll_ctrl, dss->syscon_pll_ctrl_offset,
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530249 0x3 << shift, val << shift);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300250
251 return 0;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +0530252}
253
Laurent Pinchartd7157df2018-02-13 14:00:23 +0200254void dss_sdi_init(struct dss_device *dss, int datapairs)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200255{
256 u32 l;
257
258 BUG_ON(datapairs > 3 || datapairs < 1);
259
Laurent Pinchart360c2152018-02-13 14:00:28 +0200260 l = dss_read_reg(dss, DSS_SDI_CONTROL);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200261 l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */
262 l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */
263 l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200264 dss_write_reg(dss, DSS_SDI_CONTROL, l);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200265
Laurent Pinchart360c2152018-02-13 14:00:28 +0200266 l = dss_read_reg(dss, DSS_PLL_CONTROL);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200267 l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
268 l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */
269 l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200270 dss_write_reg(dss, DSS_PLL_CONTROL, l);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200271}
272
Laurent Pinchartd7157df2018-02-13 14:00:23 +0200273int dss_sdi_enable(struct dss_device *dss)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200274{
275 unsigned long timeout;
276
277 dispc_pck_free_enable(1);
278
279 /* Reset SDI PLL */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200280 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200281 udelay(1); /* wait 2x PCLK */
282
283 /* Lock SDI PLL */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200284 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200285
286 /* Waiting for PLL lock request to complete */
287 timeout = jiffies + msecs_to_jiffies(500);
Laurent Pinchart360c2152018-02-13 14:00:28 +0200288 while (dss_read_reg(dss, DSS_SDI_STATUS) & (1 << 6)) {
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200289 if (time_after_eq(jiffies, timeout)) {
290 DSSERR("PLL lock request timed out\n");
291 goto err1;
292 }
293 }
294
295 /* Clearing PLL_GO bit */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200296 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 0, 28, 28);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200297
298 /* Waiting for PLL to lock */
299 timeout = jiffies + msecs_to_jiffies(500);
Laurent Pinchart360c2152018-02-13 14:00:28 +0200300 while (!(dss_read_reg(dss, DSS_SDI_STATUS) & (1 << 5))) {
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200301 if (time_after_eq(jiffies, timeout)) {
302 DSSERR("PLL lock timed out\n");
303 goto err1;
304 }
305 }
306
307 dispc_lcd_enable_signal(1);
308
309 /* Waiting for SDI reset to complete */
310 timeout = jiffies + msecs_to_jiffies(500);
Laurent Pinchart360c2152018-02-13 14:00:28 +0200311 while (!(dss_read_reg(dss, DSS_SDI_STATUS) & (1 << 2))) {
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200312 if (time_after_eq(jiffies, timeout)) {
313 DSSERR("SDI reset timed out\n");
314 goto err2;
315 }
316 }
317
318 return 0;
319
320 err2:
321 dispc_lcd_enable_signal(0);
322 err1:
323 /* Reset SDI PLL */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200324 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200325
326 dispc_pck_free_enable(0);
327
328 return -ETIMEDOUT;
329}
330
Laurent Pinchartd7157df2018-02-13 14:00:23 +0200331void dss_sdi_disable(struct dss_device *dss)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200332{
333 dispc_lcd_enable_signal(0);
334
335 dispc_pck_free_enable(0);
336
337 /* Reset SDI PLL */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200338 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200339}
340
Tomi Valkeinen407bd562016-05-17 13:50:55 +0300341const char *dss_get_clk_source_name(enum dss_clk_source clk_src)
Archit Taneja067a57e2011-03-02 11:57:25 +0530342{
Taneja, Archit235e7db2011-03-14 23:28:21 -0500343 return dss_generic_clk_source_names[clk_src];
Archit Taneja067a57e2011-03-02 11:57:25 +0530344}
345
Laurent Pinchart9be9d7e2017-10-13 17:59:02 +0300346#if defined(CONFIG_OMAP2_DSS_DEBUGFS)
Laurent Pinchart360c2152018-02-13 14:00:28 +0200347static void dss_dump_clocks(struct dss_device *dss, struct seq_file *s)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200348{
Tomi Valkeinen557a1542016-05-17 13:49:18 +0300349 const char *fclk_name;
Tomi Valkeinen0acf6592011-03-14 07:28:57 -0500350 unsigned long fclk_rate;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200351
Laurent Pinchart360c2152018-02-13 14:00:28 +0200352 if (dss_runtime_get(dss))
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300353 return;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200354
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200355 seq_printf(s, "- DSS -\n");
356
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300357 fclk_name = dss_get_clk_source_name(DSS_CLK_SRC_FCK);
Laurent Pinchart360c2152018-02-13 14:00:28 +0200358 fclk_rate = clk_get_rate(dss->dss_clk);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200359
Tomi Valkeinen557a1542016-05-17 13:49:18 +0300360 seq_printf(s, "%s = %lu\n",
361 fclk_name,
Tomi Valkeinen9c15d762013-11-01 11:36:10 +0200362 fclk_rate);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200363
Laurent Pinchart360c2152018-02-13 14:00:28 +0200364 dss_runtime_put(dss);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200365}
Laurent Pinchart9be9d7e2017-10-13 17:59:02 +0300366#endif
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200367
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200368static int dss_dump_regs(struct seq_file *s, void *p)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200369{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200370 struct dss_device *dss = s->private;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200371
Laurent Pinchart360c2152018-02-13 14:00:28 +0200372#define DUMPREG(dss, r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(dss, r))
373
374 if (dss_runtime_get(dss))
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200375 return 0;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200376
Laurent Pinchart360c2152018-02-13 14:00:28 +0200377 DUMPREG(dss, DSS_REVISION);
378 DUMPREG(dss, DSS_SYSCONFIG);
379 DUMPREG(dss, DSS_SYSSTATUS);
380 DUMPREG(dss, DSS_CONTROL);
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200381
Laurent Pinchart360c2152018-02-13 14:00:28 +0200382 if (dss->feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
383 DUMPREG(dss, DSS_SDI_CONTROL);
384 DUMPREG(dss, DSS_PLL_CONTROL);
385 DUMPREG(dss, DSS_SDI_STATUS);
Tomi Valkeinen6ec549e2011-02-24 14:18:50 +0200386 }
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200387
Laurent Pinchart360c2152018-02-13 14:00:28 +0200388 dss_runtime_put(dss);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200389#undef DUMPREG
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200390 return 0;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200391}
392
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300393static int dss_get_channel_index(enum omap_channel channel)
394{
395 switch (channel) {
396 case OMAP_DSS_CHANNEL_LCD:
397 return 0;
398 case OMAP_DSS_CHANNEL_LCD2:
399 return 1;
400 case OMAP_DSS_CHANNEL_LCD3:
401 return 2;
402 default:
403 WARN_ON(1);
404 return 0;
405 }
406}
407
Laurent Pinchart360c2152018-02-13 14:00:28 +0200408static void dss_select_dispc_clk_source(struct dss_device *dss,
409 enum dss_clk_source clk_src)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200410{
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200411 int b;
412
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300413 /*
414 * We always use PRCM clock as the DISPC func clock, except on DSS3,
415 * where we don't have separate DISPC and LCD clock sources.
416 */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200417 if (WARN_ON(dss->feat->has_lcd_clk_src && clk_src != DSS_CLK_SRC_FCK))
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300418 return;
419
Taneja, Archit66534e82011-03-08 05:50:34 -0600420 switch (clk_src) {
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300421 case DSS_CLK_SRC_FCK:
Taneja, Archit66534e82011-03-08 05:50:34 -0600422 b = 0;
423 break;
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300424 case DSS_CLK_SRC_PLL1_1:
Taneja, Archit66534e82011-03-08 05:50:34 -0600425 b = 1;
Taneja, Archit66534e82011-03-08 05:50:34 -0600426 break;
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300427 case DSS_CLK_SRC_PLL2_1:
Archit Taneja5a8b5722011-05-12 17:26:29 +0530428 b = 2;
Archit Taneja5a8b5722011-05-12 17:26:29 +0530429 break;
Taneja, Archit66534e82011-03-08 05:50:34 -0600430 default:
431 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300432 return;
Taneja, Archit66534e82011-03-08 05:50:34 -0600433 }
Tomi Valkeinene406f902010-06-09 15:28:12 +0300434
Laurent Pinchart360c2152018-02-13 14:00:28 +0200435 REG_FLD_MOD(dss, DSS_CONTROL, b, /* DISPC_CLK_SWITCH */
436 dss->feat->dispc_clk_switch.start,
437 dss->feat->dispc_clk_switch.end);
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200438
Laurent Pinchart360c2152018-02-13 14:00:28 +0200439 dss->dispc_clk_source = clk_src;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200440}
441
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200442void dss_select_dsi_clk_source(struct dss_device *dss, int dsi_module,
443 enum dss_clk_source clk_src)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200444{
Archit Tanejaa2e5d822012-05-07 16:51:35 +0530445 int b, pos;
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200446
Taneja, Archit66534e82011-03-08 05:50:34 -0600447 switch (clk_src) {
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300448 case DSS_CLK_SRC_FCK:
Taneja, Archit66534e82011-03-08 05:50:34 -0600449 b = 0;
450 break;
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300451 case DSS_CLK_SRC_PLL1_2:
Archit Taneja5a8b5722011-05-12 17:26:29 +0530452 BUG_ON(dsi_module != 0);
Taneja, Archit66534e82011-03-08 05:50:34 -0600453 b = 1;
Taneja, Archit66534e82011-03-08 05:50:34 -0600454 break;
Tomi Valkeinen3b63ca72016-05-17 14:01:10 +0300455 case DSS_CLK_SRC_PLL2_2:
Archit Taneja5a8b5722011-05-12 17:26:29 +0530456 BUG_ON(dsi_module != 1);
457 b = 1;
Archit Taneja5a8b5722011-05-12 17:26:29 +0530458 break;
Taneja, Archit66534e82011-03-08 05:50:34 -0600459 default:
460 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300461 return;
Taneja, Archit66534e82011-03-08 05:50:34 -0600462 }
Tomi Valkeinene406f902010-06-09 15:28:12 +0300463
Archit Tanejaa2e5d822012-05-07 16:51:35 +0530464 pos = dsi_module == 0 ? 1 : 10;
Laurent Pinchart360c2152018-02-13 14:00:28 +0200465 REG_FLD_MOD(dss, DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200466
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200467 dss->dsi_clk_source[dsi_module] = clk_src;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200468}
469
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200470static int dss_lcd_clk_mux_dra7(struct dss_device *dss,
471 enum omap_channel channel,
472 enum dss_clk_source clk_src)
Taneja, Architea751592011-03-08 05:50:35 -0600473{
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300474 const u8 ctrl_bits[] = {
475 [OMAP_DSS_CHANNEL_LCD] = 0,
476 [OMAP_DSS_CHANNEL_LCD2] = 12,
477 [OMAP_DSS_CHANNEL_LCD3] = 19,
478 };
479
480 u8 ctrl_bit = ctrl_bits[channel];
481 int r;
482
483 if (clk_src == DSS_CLK_SRC_FCK) {
484 /* LCDx_CLK_SWITCH */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200485 REG_FLD_MOD(dss, DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300486 return -EINVAL;
487 }
488
Laurent Pinchart360c2152018-02-13 14:00:28 +0200489 r = dss_ctrl_pll_set_control_mux(dss, clk_src, channel);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300490 if (r)
491 return r;
492
Laurent Pinchart360c2152018-02-13 14:00:28 +0200493 REG_FLD_MOD(dss, DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300494
495 return 0;
496}
497
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200498static int dss_lcd_clk_mux_omap5(struct dss_device *dss,
499 enum omap_channel channel,
500 enum dss_clk_source clk_src)
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300501{
502 const u8 ctrl_bits[] = {
503 [OMAP_DSS_CHANNEL_LCD] = 0,
504 [OMAP_DSS_CHANNEL_LCD2] = 12,
505 [OMAP_DSS_CHANNEL_LCD3] = 19,
506 };
507 const enum dss_clk_source allowed_plls[] = {
508 [OMAP_DSS_CHANNEL_LCD] = DSS_CLK_SRC_PLL1_1,
509 [OMAP_DSS_CHANNEL_LCD2] = DSS_CLK_SRC_FCK,
510 [OMAP_DSS_CHANNEL_LCD3] = DSS_CLK_SRC_PLL2_1,
511 };
512
513 u8 ctrl_bit = ctrl_bits[channel];
514
515 if (clk_src == DSS_CLK_SRC_FCK) {
516 /* LCDx_CLK_SWITCH */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200517 REG_FLD_MOD(dss, DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300518 return -EINVAL;
519 }
520
521 if (WARN_ON(allowed_plls[channel] != clk_src))
522 return -EINVAL;
523
Laurent Pinchart360c2152018-02-13 14:00:28 +0200524 REG_FLD_MOD(dss, DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300525
526 return 0;
527}
528
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200529static int dss_lcd_clk_mux_omap4(struct dss_device *dss,
530 enum omap_channel channel,
531 enum dss_clk_source clk_src)
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300532{
533 const u8 ctrl_bits[] = {
534 [OMAP_DSS_CHANNEL_LCD] = 0,
535 [OMAP_DSS_CHANNEL_LCD2] = 12,
536 };
537 const enum dss_clk_source allowed_plls[] = {
538 [OMAP_DSS_CHANNEL_LCD] = DSS_CLK_SRC_PLL1_1,
539 [OMAP_DSS_CHANNEL_LCD2] = DSS_CLK_SRC_PLL2_1,
540 };
541
542 u8 ctrl_bit = ctrl_bits[channel];
543
544 if (clk_src == DSS_CLK_SRC_FCK) {
545 /* LCDx_CLK_SWITCH */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200546 REG_FLD_MOD(dss, DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300547 return 0;
548 }
549
550 if (WARN_ON(allowed_plls[channel] != clk_src))
551 return -EINVAL;
552
Laurent Pinchart360c2152018-02-13 14:00:28 +0200553 REG_FLD_MOD(dss, DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300554
555 return 0;
556}
557
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200558void dss_select_lcd_clk_source(struct dss_device *dss,
559 enum omap_channel channel,
560 enum dss_clk_source clk_src)
Taneja, Architea751592011-03-08 05:50:35 -0600561{
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300562 int idx = dss_get_channel_index(channel);
563 int r;
Taneja, Architea751592011-03-08 05:50:35 -0600564
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200565 if (!dss->feat->has_lcd_clk_src) {
Laurent Pinchart360c2152018-02-13 14:00:28 +0200566 dss_select_dispc_clk_source(dss, clk_src);
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200567 dss->lcd_clk_source[idx] = clk_src;
Taneja, Architea751592011-03-08 05:50:35 -0600568 return;
Tomi Valkeinena5b83992012-10-22 16:58:36 +0300569 }
Taneja, Architea751592011-03-08 05:50:35 -0600570
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200571 r = dss->feat->ops->select_lcd_source(dss, channel, clk_src);
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300572 if (r)
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300573 return;
Taneja, Architea751592011-03-08 05:50:35 -0600574
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200575 dss->lcd_clk_source[idx] = clk_src;
Taneja, Architea751592011-03-08 05:50:35 -0600576}
577
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200578enum dss_clk_source dss_get_dispc_clk_source(struct dss_device *dss)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200579{
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200580 return dss->dispc_clk_source;
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200581}
582
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200583enum dss_clk_source dss_get_dsi_clk_source(struct dss_device *dss,
584 int dsi_module)
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200585{
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200586 return dss->dsi_clk_source[dsi_module];
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200587}
588
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200589enum dss_clk_source dss_get_lcd_clk_source(struct dss_device *dss,
590 enum omap_channel channel)
Taneja, Architea751592011-03-08 05:50:35 -0600591{
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200592 if (dss->feat->has_lcd_clk_src) {
Tomi Valkeinenc63b1ec2016-05-17 15:46:19 +0300593 int idx = dss_get_channel_index(channel);
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200594 return dss->lcd_clk_source[idx];
Archit Taneja89976f22011-03-31 13:23:35 +0530595 } else {
596 /* LCD_CLK source is the same as DISPC_FCLK source for
597 * OMAP2 and OMAP3 */
Laurent Pinchart3cc62aa2018-02-13 14:00:25 +0200598 return dss->dispc_clk_source;
Archit Taneja89976f22011-03-31 13:23:35 +0530599 }
Taneja, Architea751592011-03-08 05:50:35 -0600600}
601
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200602bool dss_div_calc(struct dss_device *dss, unsigned long pck,
603 unsigned long fck_min, dss_div_calc_func func, void *data)
Tomi Valkeinen43417822013-03-05 16:34:05 +0200604{
605 int fckd, fckd_start, fckd_stop;
606 unsigned long fck;
607 unsigned long fck_hw_max;
608 unsigned long fckd_hw_max;
609 unsigned long prate;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +0200610 unsigned int m;
Tomi Valkeinen43417822013-03-05 16:34:05 +0200611
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200612 fck_hw_max = dss->feat->fck_freq_max;
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200613
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200614 if (dss->parent_clk == NULL) {
Laurent Pinchartd11e5c82018-02-11 15:07:34 +0200615 unsigned int pckd;
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200616
617 pckd = fck_hw_max / pck;
618
619 fck = pck * pckd;
620
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200621 fck = clk_round_rate(dss->dss_clk, fck);
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200622
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200623 return func(fck, data);
Tomi Valkeinen43417822013-03-05 16:34:05 +0200624 }
625
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200626 fckd_hw_max = dss->feat->fck_div_max;
Tomi Valkeinen43417822013-03-05 16:34:05 +0200627
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200628 m = dss->feat->dss_fck_multiplier;
629 prate = clk_get_rate(dss->parent_clk);
Tomi Valkeinen43417822013-03-05 16:34:05 +0200630
631 fck_min = fck_min ? fck_min : 1;
632
Tomi Valkeinen648a55e2013-04-10 14:47:38 +0300633 fckd_start = min(prate * m / fck_min, fckd_hw_max);
634 fckd_stop = max(DIV_ROUND_UP(prate * m, fck_hw_max), 1ul);
Tomi Valkeinen43417822013-03-05 16:34:05 +0200635
636 for (fckd = fckd_start; fckd >= fckd_stop; --fckd) {
Tomi Valkeinend0e224f2014-02-13 11:36:22 +0200637 fck = DIV_ROUND_UP(prate, fckd) * m;
Tomi Valkeinen43417822013-03-05 16:34:05 +0200638
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200639 if (func(fck, data))
Tomi Valkeinen43417822013-03-05 16:34:05 +0200640 return true;
641 }
642
643 return false;
644}
645
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200646int dss_set_fck_rate(struct dss_device *dss, unsigned long rate)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200647{
Tomi Valkeinenada94432013-10-31 16:06:38 +0200648 int r;
649
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200650 DSSDBG("set fck to %lu\n", rate);
651
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200652 r = clk_set_rate(dss->dss_clk, rate);
Tomi Valkeinenada94432013-10-31 16:06:38 +0200653 if (r)
654 return r;
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200655
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200656 dss->dss_clk_rate = clk_get_rate(dss->dss_clk);
Tomi Valkeinen5aaee692012-12-12 10:37:03 +0200657
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200658 WARN_ONCE(dss->dss_clk_rate != rate, "clk rate mismatch: %lu != %lu",
659 dss->dss_clk_rate, rate);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200660
661 return 0;
662}
663
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200664unsigned long dss_get_dispc_clk_rate(struct dss_device *dss)
Tomi Valkeinen5aaee692012-12-12 10:37:03 +0200665{
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200666 return dss->dss_clk_rate;
Tomi Valkeinen5aaee692012-12-12 10:37:03 +0200667}
668
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200669unsigned long dss_get_max_fck_rate(struct dss_device *dss)
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +0300670{
Laurent Pinchart60f9c592018-02-13 14:00:26 +0200671 return dss->feat->fck_freq_max;
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +0300672}
673
Laurent Pinchart1ef904e2018-02-13 14:00:27 +0200674enum omap_dss_output_id dss_get_supported_outputs(struct dss_device *dss,
675 enum omap_channel channel)
Laurent Pinchart51919572017-08-05 01:44:18 +0300676{
Laurent Pinchart1ef904e2018-02-13 14:00:27 +0200677 return dss->feat->outputs[channel];
Laurent Pinchart51919572017-08-05 01:44:18 +0300678}
679
Laurent Pinchart360c2152018-02-13 14:00:28 +0200680static int dss_setup_default_clock(struct dss_device *dss)
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300681{
682 unsigned long max_dss_fck, prate;
Tomi Valkeinend0f58bd2013-10-31 14:44:23 +0200683 unsigned long fck;
Laurent Pinchartd11e5c82018-02-11 15:07:34 +0200684 unsigned int fck_div;
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300685 int r;
686
Laurent Pinchart360c2152018-02-13 14:00:28 +0200687 max_dss_fck = dss->feat->fck_freq_max;
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300688
Laurent Pinchart360c2152018-02-13 14:00:28 +0200689 if (dss->parent_clk == NULL) {
690 fck = clk_round_rate(dss->dss_clk, max_dss_fck);
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200691 } else {
Laurent Pinchart360c2152018-02-13 14:00:28 +0200692 prate = clk_get_rate(dss->parent_clk);
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300693
Laurent Pinchart360c2152018-02-13 14:00:28 +0200694 fck_div = DIV_ROUND_UP(prate * dss->feat->dss_fck_multiplier,
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200695 max_dss_fck);
Laurent Pinchart360c2152018-02-13 14:00:28 +0200696 fck = DIV_ROUND_UP(prate, fck_div)
697 * dss->feat->dss_fck_multiplier;
Tomi Valkeinenfc1fe6e2013-10-31 16:42:13 +0200698 }
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300699
Laurent Pinchart360c2152018-02-13 14:00:28 +0200700 r = dss_set_fck_rate(dss, fck);
Tomi Valkeinen13a1a2b2012-10-22 16:35:41 +0300701 if (r)
702 return r;
703
704 return 0;
705}
706
Laurent Pinchart1ef904e2018-02-13 14:00:27 +0200707void dss_set_venc_output(struct dss_device *dss, enum omap_dss_venc_type type)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200708{
709 int l = 0;
710
711 if (type == OMAP_DSS_VENC_TYPE_COMPOSITE)
712 l = 0;
713 else if (type == OMAP_DSS_VENC_TYPE_SVIDEO)
714 l = 1;
715 else
716 BUG();
717
718 /* venc out selection. 0 = comp, 1 = svideo */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200719 REG_FLD_MOD(dss, DSS_CONTROL, l, 6, 6);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200720}
721
Laurent Pinchart1ef904e2018-02-13 14:00:27 +0200722void dss_set_dac_pwrdn_bgz(struct dss_device *dss, bool enable)
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200723{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200724 /* DAC Power-Down Control */
725 REG_FLD_MOD(dss, DSS_CONTROL, enable, 5, 5);
Tomi Valkeinen559d6702009-11-03 11:23:50 +0200726}
727
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200728void dss_select_hdmi_venc_clk_source(struct dss_device *dss,
729 enum dss_hdmi_venc_clk_source_select src)
Mythri P K7ed024a2011-03-09 16:31:38 +0530730{
Laurent Pinchart24ab1df2017-08-05 01:43:59 +0300731 enum omap_dss_output_id outputs;
732
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200733 outputs = dss->feat->outputs[OMAP_DSS_CHANNEL_DIGIT];
Ricardo Neri8aa2eed2012-08-01 07:56:40 -0500734
735 /* Complain about invalid selections */
Laurent Pinchart24ab1df2017-08-05 01:43:59 +0300736 WARN_ON((src == DSS_VENC_TV_CLK) && !(outputs & OMAP_DSS_OUTPUT_VENC));
737 WARN_ON((src == DSS_HDMI_M_PCLK) && !(outputs & OMAP_DSS_OUTPUT_HDMI));
Ricardo Neri8aa2eed2012-08-01 07:56:40 -0500738
739 /* Select only if we have options */
Laurent Pinchart24ab1df2017-08-05 01:43:59 +0300740 if ((outputs & OMAP_DSS_OUTPUT_VENC) &&
741 (outputs & OMAP_DSS_OUTPUT_HDMI))
Laurent Pinchart360c2152018-02-13 14:00:28 +0200742 /* VENC_HDMI_SWITCH */
743 REG_FLD_MOD(dss, DSS_CONTROL, src, 15, 15);
Mythri P K7ed024a2011-03-09 16:31:38 +0530744}
745
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200746static int dss_dpi_select_source_omap2_omap3(struct dss_device *dss, int port,
747 enum omap_channel channel)
Tomi Valkeinende09e452012-09-21 12:09:54 +0300748{
749 if (channel != OMAP_DSS_CHANNEL_LCD)
750 return -EINVAL;
751
752 return 0;
753}
754
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200755static int dss_dpi_select_source_omap4(struct dss_device *dss, int port,
756 enum omap_channel channel)
Tomi Valkeinende09e452012-09-21 12:09:54 +0300757{
758 int val;
759
760 switch (channel) {
761 case OMAP_DSS_CHANNEL_LCD2:
762 val = 0;
763 break;
764 case OMAP_DSS_CHANNEL_DIGIT:
765 val = 1;
766 break;
767 default:
768 return -EINVAL;
769 }
770
Laurent Pinchart360c2152018-02-13 14:00:28 +0200771 REG_FLD_MOD(dss, DSS_CONTROL, val, 17, 17);
Tomi Valkeinende09e452012-09-21 12:09:54 +0300772
773 return 0;
774}
775
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200776static int dss_dpi_select_source_omap5(struct dss_device *dss, int port,
777 enum omap_channel channel)
Tomi Valkeinende09e452012-09-21 12:09:54 +0300778{
779 int val;
780
781 switch (channel) {
782 case OMAP_DSS_CHANNEL_LCD:
783 val = 1;
784 break;
785 case OMAP_DSS_CHANNEL_LCD2:
786 val = 2;
787 break;
788 case OMAP_DSS_CHANNEL_LCD3:
789 val = 3;
790 break;
791 case OMAP_DSS_CHANNEL_DIGIT:
792 val = 0;
793 break;
794 default:
795 return -EINVAL;
796 }
797
Laurent Pinchart360c2152018-02-13 14:00:28 +0200798 REG_FLD_MOD(dss, DSS_CONTROL, val, 17, 16);
Tomi Valkeinende09e452012-09-21 12:09:54 +0300799
800 return 0;
801}
802
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200803static int dss_dpi_select_source_dra7xx(struct dss_device *dss, int port,
804 enum omap_channel channel)
Tomi Valkeinen6d817882014-12-31 11:23:31 +0200805{
806 switch (port) {
807 case 0:
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200808 return dss_dpi_select_source_omap5(dss, port, channel);
Tomi Valkeinen6d817882014-12-31 11:23:31 +0200809 case 1:
810 if (channel != OMAP_DSS_CHANNEL_LCD2)
811 return -EINVAL;
812 break;
813 case 2:
814 if (channel != OMAP_DSS_CHANNEL_LCD3)
815 return -EINVAL;
816 break;
817 default:
818 return -EINVAL;
819 }
820
821 return 0;
822}
823
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200824int dss_dpi_select_source(struct dss_device *dss, int port,
825 enum omap_channel channel)
Tomi Valkeinende09e452012-09-21 12:09:54 +0300826{
Laurent Pinchart8aea8e62018-02-13 14:00:24 +0200827 return dss->feat->ops->dpi_select_source(dss, port, channel);
Tomi Valkeinende09e452012-09-21 12:09:54 +0300828}
829
Laurent Pinchart360c2152018-02-13 14:00:28 +0200830static int dss_get_clocks(struct dss_device *dss)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000831{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300832 struct clk *clk;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000833
Laurent Pinchart360c2152018-02-13 14:00:28 +0200834 clk = devm_clk_get(&dss->pdev->dev, "fck");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300835 if (IS_ERR(clk)) {
836 DSSERR("can't get clock fck\n");
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300837 return PTR_ERR(clk);
Semwal, Sumita1a0dcc2011-03-01 02:42:14 -0600838 }
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000839
Laurent Pinchart360c2152018-02-13 14:00:28 +0200840 dss->dss_clk = clk;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000841
Laurent Pinchart360c2152018-02-13 14:00:28 +0200842 if (dss->feat->parent_clk_name) {
843 clk = clk_get(NULL, dss->feat->parent_clk_name);
Aaro Koskinen8ad93752012-11-21 21:48:51 +0200844 if (IS_ERR(clk)) {
Laurent Pinchart360c2152018-02-13 14:00:28 +0200845 DSSERR("Failed to get %s\n",
846 dss->feat->parent_clk_name);
Archit Tanejab2c9c8e2013-04-08 11:55:00 +0300847 return PTR_ERR(clk);
Aaro Koskinen8ad93752012-11-21 21:48:51 +0200848 }
849 } else {
850 clk = NULL;
Tomi Valkeinen94c042c2011-05-16 13:43:04 +0300851 }
852
Laurent Pinchart360c2152018-02-13 14:00:28 +0200853 dss->parent_clk = clk;
Tomi Valkeinen94c042c2011-05-16 13:43:04 +0300854
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000855 return 0;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000856}
857
Laurent Pinchart360c2152018-02-13 14:00:28 +0200858static void dss_put_clocks(struct dss_device *dss)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000859{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200860 if (dss->parent_clk)
861 clk_put(dss->parent_clk);
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000862}
863
Laurent Pinchart7b295252018-02-13 14:00:21 +0200864int dss_runtime_get(struct dss_device *dss)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000865{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300866 int r;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000867
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300868 DSSDBG("dss_runtime_get\n");
869
Laurent Pinchart7b295252018-02-13 14:00:21 +0200870 r = pm_runtime_get_sync(&dss->pdev->dev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300871 WARN_ON(r < 0);
872 return r < 0 ? r : 0;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000873}
874
Laurent Pinchart7b295252018-02-13 14:00:21 +0200875void dss_runtime_put(struct dss_device *dss)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000876{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300877 int r;
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000878
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300879 DSSDBG("dss_runtime_put\n");
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000880
Laurent Pinchart7b295252018-02-13 14:00:21 +0200881 r = pm_runtime_put_sync(&dss->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +0300882 WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY);
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000883}
884
Laurent Pinchart7b295252018-02-13 14:00:21 +0200885struct dss_device *dss_get_device(struct device *dev)
886{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200887 return dev_get_drvdata(dev);
Laurent Pinchart7b295252018-02-13 14:00:21 +0200888}
889
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000890/* DEBUGFS */
Chandrabhanu Mahapatra1b3bcb32012-09-29 11:25:42 +0530891#if defined(CONFIG_OMAP2_DSS_DEBUGFS)
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200892static int dss_debug_dump_clocks(struct seq_file *s, void *p)
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000893{
Laurent Pinchart360c2152018-02-13 14:00:28 +0200894 struct dss_device *dss = s->private;
895
896 dss_dump_clocks(dss, s);
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +0000897 dispc_dump_clocks(s);
898#ifdef CONFIG_OMAP2_DSS_DSI
899 dsi_dump_clocks(s);
900#endif
Laurent Pinchart11765d12017-08-05 01:44:01 +0300901 return 0;
902}
903
Laurent Pinchart360c2152018-02-13 14:00:28 +0200904static int dss_initialize_debugfs(struct dss_device *dss)
Laurent Pinchart11765d12017-08-05 01:44:01 +0300905{
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200906 struct dentry *dir;
Laurent Pinchart11765d12017-08-05 01:44:01 +0300907
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200908 dir = debugfs_create_dir("omapdss", NULL);
909 if (IS_ERR(dir))
910 return PTR_ERR(dir);
911
912 dss->debugfs.root = dir;
Laurent Pinchart11765d12017-08-05 01:44:01 +0300913
Laurent Pinchart11765d12017-08-05 01:44:01 +0300914 return 0;
915}
916
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200917static void dss_uninitialize_debugfs(struct dss_device *dss)
Laurent Pinchart11765d12017-08-05 01:44:01 +0300918{
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200919 debugfs_remove_recursive(dss->debugfs.root);
Laurent Pinchart11765d12017-08-05 01:44:01 +0300920}
921
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200922struct dss_debugfs_entry {
923 struct dentry *dentry;
924 int (*show_fn)(struct seq_file *s, void *data);
925 void *data;
926};
927
928static int dss_debug_open(struct inode *inode, struct file *file)
Laurent Pinchart11765d12017-08-05 01:44:01 +0300929{
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200930 struct dss_debugfs_entry *entry = inode->i_private;
931
932 return single_open(file, entry->show_fn, entry->data);
933}
934
935static const struct file_operations dss_debug_fops = {
936 .open = dss_debug_open,
937 .read = seq_read,
938 .llseek = seq_lseek,
939 .release = single_release,
940};
941
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200942struct dss_debugfs_entry *
943dss_debugfs_create_file(struct dss_device *dss, const char *name,
944 int (*show_fn)(struct seq_file *s, void *data),
945 void *data)
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200946{
947 struct dss_debugfs_entry *entry;
Laurent Pinchart11765d12017-08-05 01:44:01 +0300948 struct dentry *d;
949
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200950 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
951 if (!entry)
952 return ERR_PTR(-ENOMEM);
Laurent Pinchart11765d12017-08-05 01:44:01 +0300953
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200954 entry->show_fn = show_fn;
955 entry->data = data;
956
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200957 d = debugfs_create_file(name, 0444, dss->debugfs.root, entry,
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200958 &dss_debug_fops);
959 if (IS_ERR(d)) {
960 kfree(entry);
961 return ERR_PTR(PTR_ERR(d));
962 }
963
964 entry->dentry = d;
965 return entry;
Laurent Pinchart11765d12017-08-05 01:44:01 +0300966}
Laurent Pinchartf33656e2018-02-13 14:00:29 +0200967
968void dss_debugfs_remove_file(struct dss_debugfs_entry *entry)
969{
970 if (IS_ERR_OR_NULL(entry))
971 return;
972
973 debugfs_remove(entry->dentry);
974 kfree(entry);
975}
976
Laurent Pinchart11765d12017-08-05 01:44:01 +0300977#else /* CONFIG_OMAP2_DSS_DEBUGFS */
Laurent Pinchart360c2152018-02-13 14:00:28 +0200978static inline int dss_initialize_debugfs(struct dss_device *dss)
Laurent Pinchart11765d12017-08-05 01:44:01 +0300979{
980 return 0;
981}
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +0200982static inline void dss_uninitialize_debugfs(struct dss_device *dss)
Laurent Pinchart11765d12017-08-05 01:44:01 +0300983{
984}
985#endif /* CONFIG_OMAP2_DSS_DEBUGFS */
Archit Taneja387ce9f2014-05-22 17:01:57 +0530986
Laurent Pinchartfecea252017-08-05 01:43:52 +0300987static const struct dss_ops dss_ops_omap2_omap3 = {
988 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
989};
990
991static const struct dss_ops dss_ops_omap4 = {
992 .dpi_select_source = &dss_dpi_select_source_omap4,
993 .select_lcd_source = &dss_lcd_clk_mux_omap4,
994};
995
996static const struct dss_ops dss_ops_omap5 = {
997 .dpi_select_source = &dss_dpi_select_source_omap5,
998 .select_lcd_source = &dss_lcd_clk_mux_omap5,
999};
1000
1001static const struct dss_ops dss_ops_dra7 = {
1002 .dpi_select_source = &dss_dpi_select_source_dra7xx,
1003 .select_lcd_source = &dss_lcd_clk_mux_dra7,
1004};
1005
Tomi Valkeinen234f9a22014-12-11 15:59:31 +02001006static const enum omap_display_type omap2plus_ports[] = {
Archit Taneja387ce9f2014-05-22 17:01:57 +05301007 OMAP_DISPLAY_TYPE_DPI,
1008};
1009
Tomi Valkeinen234f9a22014-12-11 15:59:31 +02001010static const enum omap_display_type omap34xx_ports[] = {
Archit Taneja387ce9f2014-05-22 17:01:57 +05301011 OMAP_DISPLAY_TYPE_DPI,
1012 OMAP_DISPLAY_TYPE_SDI,
1013};
1014
Tomi Valkeinen6d817882014-12-31 11:23:31 +02001015static const enum omap_display_type dra7xx_ports[] = {
1016 OMAP_DISPLAY_TYPE_DPI,
1017 OMAP_DISPLAY_TYPE_DPI,
1018 OMAP_DISPLAY_TYPE_DPI,
1019};
1020
Laurent Pinchart51919572017-08-05 01:44:18 +03001021static const enum omap_dss_output_id omap2_dss_supported_outputs[] = {
1022 /* OMAP_DSS_CHANNEL_LCD */
1023 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI,
1024
1025 /* OMAP_DSS_CHANNEL_DIGIT */
1026 OMAP_DSS_OUTPUT_VENC,
1027};
1028
1029static const enum omap_dss_output_id omap3430_dss_supported_outputs[] = {
1030 /* OMAP_DSS_CHANNEL_LCD */
1031 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1032 OMAP_DSS_OUTPUT_SDI | OMAP_DSS_OUTPUT_DSI1,
1033
1034 /* OMAP_DSS_CHANNEL_DIGIT */
1035 OMAP_DSS_OUTPUT_VENC,
1036};
1037
1038static const enum omap_dss_output_id omap3630_dss_supported_outputs[] = {
1039 /* OMAP_DSS_CHANNEL_LCD */
1040 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1041 OMAP_DSS_OUTPUT_DSI1,
1042
1043 /* OMAP_DSS_CHANNEL_DIGIT */
1044 OMAP_DSS_OUTPUT_VENC,
1045};
1046
1047static const enum omap_dss_output_id am43xx_dss_supported_outputs[] = {
1048 /* OMAP_DSS_CHANNEL_LCD */
1049 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI,
1050};
1051
1052static const enum omap_dss_output_id omap4_dss_supported_outputs[] = {
1053 /* OMAP_DSS_CHANNEL_LCD */
1054 OMAP_DSS_OUTPUT_DBI | OMAP_DSS_OUTPUT_DSI1,
1055
1056 /* OMAP_DSS_CHANNEL_DIGIT */
1057 OMAP_DSS_OUTPUT_VENC | OMAP_DSS_OUTPUT_HDMI,
1058
1059 /* OMAP_DSS_CHANNEL_LCD2 */
1060 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1061 OMAP_DSS_OUTPUT_DSI2,
1062};
1063
1064static const enum omap_dss_output_id omap5_dss_supported_outputs[] = {
1065 /* OMAP_DSS_CHANNEL_LCD */
1066 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1067 OMAP_DSS_OUTPUT_DSI1 | OMAP_DSS_OUTPUT_DSI2,
1068
1069 /* OMAP_DSS_CHANNEL_DIGIT */
1070 OMAP_DSS_OUTPUT_HDMI,
1071
1072 /* OMAP_DSS_CHANNEL_LCD2 */
1073 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1074 OMAP_DSS_OUTPUT_DSI1,
1075
1076 /* OMAP_DSS_CHANNEL_LCD3 */
1077 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1078 OMAP_DSS_OUTPUT_DSI2,
1079};
1080
Tomi Valkeinenede92692015-06-04 14:12:16 +03001081static const struct dss_features omap24xx_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001082 .model = DSS_MODEL_OMAP2,
Tomi Valkeinen6e555e22013-11-01 11:26:43 +02001083 /*
1084 * fck div max is really 16, but the divider range has gaps. The range
1085 * from 1 to 6 has no gaps, so let's use that as a max.
1086 */
1087 .fck_div_max = 6,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001088 .fck_freq_max = 133000000,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001089 .dss_fck_multiplier = 2,
Tomi Valkeinenada94432013-10-31 16:06:38 +02001090 .parent_clk_name = "core_ck",
Archit Taneja387ce9f2014-05-22 17:01:57 +05301091 .ports = omap2plus_ports,
1092 .num_ports = ARRAY_SIZE(omap2plus_ports),
Laurent Pinchart51919572017-08-05 01:44:18 +03001093 .outputs = omap2_dss_supported_outputs,
Laurent Pinchartfecea252017-08-05 01:43:52 +03001094 .ops = &dss_ops_omap2_omap3,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001095 .dispc_clk_switch = { 0, 0 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001096 .has_lcd_clk_src = false,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001097};
1098
Tomi Valkeinenede92692015-06-04 14:12:16 +03001099static const struct dss_features omap34xx_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001100 .model = DSS_MODEL_OMAP3,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001101 .fck_div_max = 16,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001102 .fck_freq_max = 173000000,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001103 .dss_fck_multiplier = 2,
Tomi Valkeinenada94432013-10-31 16:06:38 +02001104 .parent_clk_name = "dpll4_ck",
Archit Taneja387ce9f2014-05-22 17:01:57 +05301105 .ports = omap34xx_ports,
Laurent Pinchart51919572017-08-05 01:44:18 +03001106 .outputs = omap3430_dss_supported_outputs,
Archit Taneja387ce9f2014-05-22 17:01:57 +05301107 .num_ports = ARRAY_SIZE(omap34xx_ports),
Laurent Pinchartfecea252017-08-05 01:43:52 +03001108 .ops = &dss_ops_omap2_omap3,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001109 .dispc_clk_switch = { 0, 0 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001110 .has_lcd_clk_src = false,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001111};
1112
Tomi Valkeinenede92692015-06-04 14:12:16 +03001113static const struct dss_features omap3630_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001114 .model = DSS_MODEL_OMAP3,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001115 .fck_div_max = 32,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001116 .fck_freq_max = 173000000,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001117 .dss_fck_multiplier = 1,
Tomi Valkeinenada94432013-10-31 16:06:38 +02001118 .parent_clk_name = "dpll4_ck",
Archit Taneja387ce9f2014-05-22 17:01:57 +05301119 .ports = omap2plus_ports,
1120 .num_ports = ARRAY_SIZE(omap2plus_ports),
Laurent Pinchart51919572017-08-05 01:44:18 +03001121 .outputs = omap3630_dss_supported_outputs,
Laurent Pinchartfecea252017-08-05 01:43:52 +03001122 .ops = &dss_ops_omap2_omap3,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001123 .dispc_clk_switch = { 0, 0 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001124 .has_lcd_clk_src = false,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001125};
1126
Tomi Valkeinenede92692015-06-04 14:12:16 +03001127static const struct dss_features omap44xx_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001128 .model = DSS_MODEL_OMAP4,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001129 .fck_div_max = 32,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001130 .fck_freq_max = 186000000,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001131 .dss_fck_multiplier = 1,
Tomi Valkeinenada94432013-10-31 16:06:38 +02001132 .parent_clk_name = "dpll_per_x2_ck",
Archit Taneja387ce9f2014-05-22 17:01:57 +05301133 .ports = omap2plus_ports,
1134 .num_ports = ARRAY_SIZE(omap2plus_ports),
Laurent Pinchart51919572017-08-05 01:44:18 +03001135 .outputs = omap4_dss_supported_outputs,
Laurent Pinchartfecea252017-08-05 01:43:52 +03001136 .ops = &dss_ops_omap4,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001137 .dispc_clk_switch = { 9, 8 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001138 .has_lcd_clk_src = true,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001139};
1140
Tomi Valkeinenede92692015-06-04 14:12:16 +03001141static const struct dss_features omap54xx_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001142 .model = DSS_MODEL_OMAP5,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001143 .fck_div_max = 64,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001144 .fck_freq_max = 209250000,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001145 .dss_fck_multiplier = 1,
Tomi Valkeinenada94432013-10-31 16:06:38 +02001146 .parent_clk_name = "dpll_per_x2_ck",
Archit Taneja387ce9f2014-05-22 17:01:57 +05301147 .ports = omap2plus_ports,
1148 .num_ports = ARRAY_SIZE(omap2plus_ports),
Laurent Pinchart51919572017-08-05 01:44:18 +03001149 .outputs = omap5_dss_supported_outputs,
Laurent Pinchartfecea252017-08-05 01:43:52 +03001150 .ops = &dss_ops_omap5,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001151 .dispc_clk_switch = { 9, 7 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001152 .has_lcd_clk_src = true,
Tomi Valkeinen84273a92012-09-21 12:03:31 +03001153};
1154
Tomi Valkeinenede92692015-06-04 14:12:16 +03001155static const struct dss_features am43xx_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001156 .model = DSS_MODEL_OMAP3,
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05301157 .fck_div_max = 0,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001158 .fck_freq_max = 200000000,
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05301159 .dss_fck_multiplier = 0,
1160 .parent_clk_name = NULL,
Archit Taneja387ce9f2014-05-22 17:01:57 +05301161 .ports = omap2plus_ports,
1162 .num_ports = ARRAY_SIZE(omap2plus_ports),
Laurent Pinchart51919572017-08-05 01:44:18 +03001163 .outputs = am43xx_dss_supported_outputs,
Laurent Pinchartfecea252017-08-05 01:43:52 +03001164 .ops = &dss_ops_omap2_omap3,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001165 .dispc_clk_switch = { 0, 0 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001166 .has_lcd_clk_src = true,
Sathya Prakash M Rd6279d42014-03-24 16:31:51 +05301167};
1168
Tomi Valkeinenede92692015-06-04 14:12:16 +03001169static const struct dss_features dra7xx_dss_feats = {
Laurent Pinchartb8dab2b2017-08-05 01:43:56 +03001170 .model = DSS_MODEL_DRA7,
Tomi Valkeinen6d817882014-12-31 11:23:31 +02001171 .fck_div_max = 64,
Laurent Pinchart9f0fbae2017-08-05 01:44:17 +03001172 .fck_freq_max = 209250000,
Tomi Valkeinen6d817882014-12-31 11:23:31 +02001173 .dss_fck_multiplier = 1,
1174 .parent_clk_name = "dpll_per_x2_ck",
Tomi Valkeinen6d817882014-12-31 11:23:31 +02001175 .ports = dra7xx_ports,
1176 .num_ports = ARRAY_SIZE(dra7xx_ports),
Laurent Pinchart51919572017-08-05 01:44:18 +03001177 .outputs = omap5_dss_supported_outputs,
Laurent Pinchartfecea252017-08-05 01:43:52 +03001178 .ops = &dss_ops_dra7,
Laurent Pinchart6d85d4a2017-08-05 01:44:07 +03001179 .dispc_clk_switch = { 9, 7 },
Laurent Pinchart4569ab72017-08-05 01:44:13 +03001180 .has_lcd_clk_src = true,
Tomi Valkeinen6d817882014-12-31 11:23:31 +02001181};
1182
Laurent Pinchart360c2152018-02-13 14:00:28 +02001183static int dss_init_ports(struct dss_device *dss)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001184{
Laurent Pinchart360c2152018-02-13 14:00:28 +02001185 struct platform_device *pdev = dss->pdev;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001186 struct device_node *parent = pdev->dev.of_node;
1187 struct device_node *port;
Rob Herring09bffa62017-03-22 08:26:08 -05001188 int i;
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001189
Laurent Pinchart360c2152018-02-13 14:00:28 +02001190 for (i = 0; i < dss->feat->num_ports; i++) {
Rob Herring09bffa62017-03-22 08:26:08 -05001191 port = of_graph_get_port_by_id(parent, i);
1192 if (!port)
Archit Taneja387ce9f2014-05-22 17:01:57 +05301193 continue;
1194
Laurent Pinchart360c2152018-02-13 14:00:28 +02001195 switch (dss->feat->ports[i]) {
Archit Taneja387ce9f2014-05-22 17:01:57 +05301196 case OMAP_DISPLAY_TYPE_DPI:
Laurent Pinchart360c2152018-02-13 14:00:28 +02001197 dpi_init_port(dss, pdev, port, dss->feat->model);
Archit Taneja387ce9f2014-05-22 17:01:57 +05301198 break;
1199 case OMAP_DISPLAY_TYPE_SDI:
Laurent Pinchart360c2152018-02-13 14:00:28 +02001200 sdi_init_port(dss, pdev, port);
Archit Taneja387ce9f2014-05-22 17:01:57 +05301201 break;
1202 default:
1203 break;
1204 }
Rob Herring09bffa62017-03-22 08:26:08 -05001205 }
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001206
1207 return 0;
1208}
1209
Laurent Pinchart360c2152018-02-13 14:00:28 +02001210static void dss_uninit_ports(struct dss_device *dss)
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001211{
Laurent Pinchart360c2152018-02-13 14:00:28 +02001212 struct platform_device *pdev = dss->pdev;
Archit Taneja80eb6752014-06-02 14:11:51 +05301213 struct device_node *parent = pdev->dev.of_node;
1214 struct device_node *port;
Rob Herring09bffa62017-03-22 08:26:08 -05001215 int i;
Archit Taneja80eb6752014-06-02 14:11:51 +05301216
Laurent Pinchart360c2152018-02-13 14:00:28 +02001217 for (i = 0; i < dss->feat->num_ports; i++) {
Rob Herring09bffa62017-03-22 08:26:08 -05001218 port = of_graph_get_port_by_id(parent, i);
1219 if (!port)
Archit Taneja387ce9f2014-05-22 17:01:57 +05301220 continue;
1221
Laurent Pinchart360c2152018-02-13 14:00:28 +02001222 switch (dss->feat->ports[i]) {
Archit Taneja387ce9f2014-05-22 17:01:57 +05301223 case OMAP_DISPLAY_TYPE_DPI:
1224 dpi_uninit_port(port);
1225 break;
1226 case OMAP_DISPLAY_TYPE_SDI:
1227 sdi_uninit_port(port);
1228 break;
1229 default:
1230 break;
1231 }
Rob Herring09bffa62017-03-22 08:26:08 -05001232 }
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001233}
1234
Laurent Pinchart360c2152018-02-13 14:00:28 +02001235static int dss_video_pll_probe(struct dss_device *dss)
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001236{
Laurent Pinchart360c2152018-02-13 14:00:28 +02001237 struct platform_device *pdev = dss->pdev;
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +05301238 struct device_node *np = pdev->dev.of_node;
Tomi Valkeinen99767542014-07-04 13:38:27 +05301239 struct regulator *pll_regulator;
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001240 int r;
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001241
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001242 if (!np)
1243 return 0;
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001244
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001245 if (of_property_read_bool(np, "syscon-pll-ctrl")) {
Laurent Pinchart360c2152018-02-13 14:00:28 +02001246 dss->syscon_pll_ctrl = syscon_regmap_lookup_by_phandle(np,
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +05301247 "syscon-pll-ctrl");
Laurent Pinchart360c2152018-02-13 14:00:28 +02001248 if (IS_ERR(dss->syscon_pll_ctrl)) {
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +05301249 dev_err(&pdev->dev,
1250 "failed to get syscon-pll-ctrl regmap\n");
Laurent Pinchart360c2152018-02-13 14:00:28 +02001251 return PTR_ERR(dss->syscon_pll_ctrl);
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +05301252 }
1253
1254 if (of_property_read_u32_index(np, "syscon-pll-ctrl", 1,
Laurent Pinchart360c2152018-02-13 14:00:28 +02001255 &dss->syscon_pll_ctrl_offset)) {
Tomi Valkeinenbe40eec2014-07-04 13:37:15 +05301256 dev_err(&pdev->dev,
1257 "failed to get syscon-pll-ctrl offset\n");
1258 return -EINVAL;
1259 }
1260 }
1261
Tomi Valkeinen99767542014-07-04 13:38:27 +05301262 pll_regulator = devm_regulator_get(&pdev->dev, "vdda_video");
1263 if (IS_ERR(pll_regulator)) {
1264 r = PTR_ERR(pll_regulator);
1265
1266 switch (r) {
1267 case -ENOENT:
1268 pll_regulator = NULL;
1269 break;
1270
1271 case -EPROBE_DEFER:
1272 return -EPROBE_DEFER;
1273
1274 default:
1275 DSSERR("can't get DPLL VDDA regulator\n");
1276 return r;
1277 }
1278 }
1279
1280 if (of_property_match_string(np, "reg-names", "pll1") >= 0) {
Laurent Pinchart360c2152018-02-13 14:00:28 +02001281 dss->video1_pll = dss_video_pll_init(dss, pdev, 0,
1282 pll_regulator);
1283 if (IS_ERR(dss->video1_pll))
1284 return PTR_ERR(dss->video1_pll);
Tomi Valkeinen99767542014-07-04 13:38:27 +05301285 }
1286
1287 if (of_property_match_string(np, "reg-names", "pll2") >= 0) {
Laurent Pinchart360c2152018-02-13 14:00:28 +02001288 dss->video2_pll = dss_video_pll_init(dss, pdev, 1,
1289 pll_regulator);
1290 if (IS_ERR(dss->video2_pll)) {
1291 dss_video_pll_uninit(dss->video1_pll);
1292 return PTR_ERR(dss->video2_pll);
Tomi Valkeinen99767542014-07-04 13:38:27 +05301293 }
1294 }
1295
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001296 return 0;
1297}
1298
1299/* DSS HW IP initialisation */
Laurent Pinchart18daeb82017-08-05 01:43:58 +03001300static const struct of_device_id dss_of_match[] = {
1301 { .compatible = "ti,omap2-dss", .data = &omap24xx_dss_feats },
1302 { .compatible = "ti,omap3-dss", .data = &omap3630_dss_feats },
1303 { .compatible = "ti,omap4-dss", .data = &omap44xx_dss_feats },
1304 { .compatible = "ti,omap5-dss", .data = &omap54xx_dss_feats },
1305 { .compatible = "ti,dra7-dss", .data = &dra7xx_dss_feats },
1306 {},
1307};
1308MODULE_DEVICE_TABLE(of, dss_of_match);
1309
1310static const struct soc_device_attribute dss_soc_devices[] = {
1311 { .machine = "OMAP3430/3530", .data = &omap34xx_dss_feats },
1312 { .machine = "AM35??", .data = &omap34xx_dss_feats },
1313 { .family = "AM43xx", .data = &am43xx_dss_feats },
1314 { /* sentinel */ }
1315};
1316
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001317static int dss_bind(struct device *dev)
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001318{
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001319 int r;
1320
Laurent Pinchart215003b2018-02-11 15:07:44 +02001321 r = component_bind_all(dev, NULL);
Tomi Valkeinen7e328f52015-06-04 13:02:52 +03001322 if (r)
1323 return r;
1324
Tomi Valkeinencb17a4a2015-02-25 12:08:14 +02001325 pm_set_vt_switch(0);
1326
Peter Ujfalusi1e08c822016-05-03 22:07:10 +03001327 omapdss_gather_components(dev);
Tomi Valkeinen7c299712015-11-05 17:23:14 +02001328 omapdss_set_is_initialized(true);
Tomi Valkeinenf99467b2015-06-04 12:35:42 +03001329
Senthilvadivu Guruswamy8b9cb3a2011-01-24 06:21:58 +00001330 return 0;
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001331}
1332
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001333static void dss_unbind(struct device *dev)
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001334{
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001335 struct platform_device *pdev = to_platform_device(dev);
1336
Tomi Valkeinen7c299712015-11-05 17:23:14 +02001337 omapdss_set_is_initialized(false);
Tomi Valkeinenf99467b2015-06-04 12:35:42 +03001338
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001339 component_unbind_all(&pdev->dev, NULL);
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001340}
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03001341
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001342static const struct component_master_ops dss_component_ops = {
1343 .bind = dss_bind,
1344 .unbind = dss_unbind,
1345};
1346
1347static int dss_component_compare(struct device *dev, void *data)
1348{
1349 struct device *child = data;
1350 return dev == child;
1351}
1352
1353static int dss_add_child_component(struct device *dev, void *data)
1354{
1355 struct component_match **match = data;
1356
Tomi Valkeinen0438ec92015-06-30 12:23:45 +03001357 /*
1358 * HACK
1359 * We don't have a working driver for rfbi, so skip it here always.
1360 * Otherwise dss will never get probed successfully, as it will wait
1361 * for rfbi to get probed.
1362 */
1363 if (strstr(dev_name(dev), "rfbi"))
1364 return 0;
1365
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001366 component_match_add(dev->parent, match, dss_component_compare, dev);
1367
1368 return 0;
1369}
1370
Laurent Pinchart7b295252018-02-13 14:00:21 +02001371static int dss_probe_hardware(struct dss_device *dss)
Laurent Pinchart215003b2018-02-11 15:07:44 +02001372{
1373 u32 rev;
1374 int r;
1375
Laurent Pinchart7b295252018-02-13 14:00:21 +02001376 r = dss_runtime_get(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001377 if (r)
1378 return r;
1379
Laurent Pinchart7b295252018-02-13 14:00:21 +02001380 dss->dss_clk_rate = clk_get_rate(dss->dss_clk);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001381
1382 /* Select DPLL */
Laurent Pinchart360c2152018-02-13 14:00:28 +02001383 REG_FLD_MOD(dss, DSS_CONTROL, 0, 0, 0);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001384
Laurent Pinchart360c2152018-02-13 14:00:28 +02001385 dss_select_dispc_clk_source(dss, DSS_CLK_SRC_FCK);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001386
1387#ifdef CONFIG_OMAP2_DSS_VENC
Laurent Pinchart360c2152018-02-13 14:00:28 +02001388 REG_FLD_MOD(dss, DSS_CONTROL, 1, 4, 4); /* venc dac demen */
1389 REG_FLD_MOD(dss, DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */
1390 REG_FLD_MOD(dss, DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */
Laurent Pinchart215003b2018-02-11 15:07:44 +02001391#endif
Laurent Pinchart7b295252018-02-13 14:00:21 +02001392 dss->dsi_clk_source[0] = DSS_CLK_SRC_FCK;
1393 dss->dsi_clk_source[1] = DSS_CLK_SRC_FCK;
1394 dss->dispc_clk_source = DSS_CLK_SRC_FCK;
1395 dss->lcd_clk_source[0] = DSS_CLK_SRC_FCK;
1396 dss->lcd_clk_source[1] = DSS_CLK_SRC_FCK;
Laurent Pinchart215003b2018-02-11 15:07:44 +02001397
Laurent Pinchart360c2152018-02-13 14:00:28 +02001398 rev = dss_read_reg(dss, DSS_REVISION);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001399 pr_info("OMAP DSS rev %d.%d\n", FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
1400
Laurent Pinchart7b295252018-02-13 14:00:21 +02001401 dss_runtime_put(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001402
1403 return 0;
1404}
1405
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001406static int dss_probe(struct platform_device *pdev)
1407{
Laurent Pinchart4a9fab32017-08-05 01:44:00 +03001408 const struct soc_device_attribute *soc;
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001409 struct component_match *match = NULL;
Laurent Pinchart215003b2018-02-11 15:07:44 +02001410 struct resource *dss_mem;
Laurent Pinchart360c2152018-02-13 14:00:28 +02001411 struct dss_device *dss;
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001412 int r;
1413
Laurent Pinchart360c2152018-02-13 14:00:28 +02001414 dss = kzalloc(sizeof(*dss), GFP_KERNEL);
1415 if (!dss)
1416 return -ENOMEM;
1417
1418 dss->pdev = pdev;
1419 platform_set_drvdata(pdev, dss);
Laurent Pinchart4a9fab32017-08-05 01:44:00 +03001420
Laurent Pincharta921c1a2017-10-13 17:59:01 +03001421 r = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
1422 if (r) {
1423 dev_err(&pdev->dev, "Failed to set the DMA mask\n");
Laurent Pinchart360c2152018-02-13 14:00:28 +02001424 goto err_free_dss;
Laurent Pincharta921c1a2017-10-13 17:59:01 +03001425 }
1426
Laurent Pinchart4a9fab32017-08-05 01:44:00 +03001427 /*
1428 * The various OMAP3-based SoCs can't be told apart using the compatible
1429 * string, use SoC device matching.
1430 */
1431 soc = soc_device_match(dss_soc_devices);
1432 if (soc)
Laurent Pinchart360c2152018-02-13 14:00:28 +02001433 dss->feat = soc->data;
Laurent Pinchart4a9fab32017-08-05 01:44:00 +03001434 else
Laurent Pinchart360c2152018-02-13 14:00:28 +02001435 dss->feat = of_match_device(dss_of_match, &pdev->dev)->data;
Laurent Pinchart4a9fab32017-08-05 01:44:00 +03001436
Laurent Pinchart215003b2018-02-11 15:07:44 +02001437 /* Map I/O registers, get and setup clocks. */
1438 dss_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Laurent Pinchart360c2152018-02-13 14:00:28 +02001439 dss->base = devm_ioremap_resource(&pdev->dev, dss_mem);
1440 if (IS_ERR(dss->base)) {
1441 r = PTR_ERR(dss->base);
1442 goto err_free_dss;
1443 }
Laurent Pinchart215003b2018-02-11 15:07:44 +02001444
Laurent Pinchart360c2152018-02-13 14:00:28 +02001445 r = dss_get_clocks(dss);
Laurent Pinchart11765d12017-08-05 01:44:01 +03001446 if (r)
Laurent Pinchart360c2152018-02-13 14:00:28 +02001447 goto err_free_dss;
Laurent Pinchart11765d12017-08-05 01:44:01 +03001448
Laurent Pinchart360c2152018-02-13 14:00:28 +02001449 r = dss_setup_default_clock(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001450 if (r)
1451 goto err_put_clocks;
1452
1453 /* Setup the video PLLs and the DPI and SDI ports. */
Laurent Pinchart360c2152018-02-13 14:00:28 +02001454 r = dss_video_pll_probe(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001455 if (r)
1456 goto err_put_clocks;
1457
Laurent Pinchart360c2152018-02-13 14:00:28 +02001458 r = dss_init_ports(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001459 if (r)
1460 goto err_uninit_plls;
1461
1462 /* Enable runtime PM and probe the hardware. */
1463 pm_runtime_enable(&pdev->dev);
1464
Laurent Pinchart360c2152018-02-13 14:00:28 +02001465 r = dss_probe_hardware(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001466 if (r)
1467 goto err_pm_runtime_disable;
1468
1469 /* Initialize debugfs. */
Laurent Pinchart360c2152018-02-13 14:00:28 +02001470 r = dss_initialize_debugfs(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001471 if (r)
1472 goto err_pm_runtime_disable;
1473
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +02001474 dss->debugfs.clk = dss_debugfs_create_file(dss, "clk",
1475 dss_debug_dump_clocks, dss);
1476 dss->debugfs.dss = dss_debugfs_create_file(dss, "dss", dss_dump_regs,
Laurent Pinchartf33656e2018-02-13 14:00:29 +02001477 dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001478
1479 /* Add all the child devices as components. */
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001480 device_for_each_child(&pdev->dev, &match, dss_add_child_component);
1481
1482 r = component_master_add_with_match(&pdev->dev, &dss_component_ops, match);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001483 if (r)
1484 goto err_uninit_debugfs;
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001485
1486 return 0;
Laurent Pinchart215003b2018-02-11 15:07:44 +02001487
1488err_uninit_debugfs:
Laurent Pinchartf33656e2018-02-13 14:00:29 +02001489 dss_debugfs_remove_file(dss->debugfs.clk);
1490 dss_debugfs_remove_file(dss->debugfs.dss);
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +02001491 dss_uninitialize_debugfs(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001492
1493err_pm_runtime_disable:
1494 pm_runtime_disable(&pdev->dev);
Laurent Pinchart360c2152018-02-13 14:00:28 +02001495 dss_uninit_ports(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001496
1497err_uninit_plls:
Laurent Pinchart360c2152018-02-13 14:00:28 +02001498 if (dss->video1_pll)
1499 dss_video_pll_uninit(dss->video1_pll);
1500 if (dss->video2_pll)
1501 dss_video_pll_uninit(dss->video2_pll);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001502
1503err_put_clocks:
Laurent Pinchart360c2152018-02-13 14:00:28 +02001504 dss_put_clocks(dss);
1505
1506err_free_dss:
1507 kfree(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001508
1509 return r;
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001510}
1511
1512static int dss_remove(struct platform_device *pdev)
1513{
Laurent Pinchart360c2152018-02-13 14:00:28 +02001514 struct dss_device *dss = platform_get_drvdata(pdev);
1515
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001516 component_master_del(&pdev->dev, &dss_component_ops);
Laurent Pinchart11765d12017-08-05 01:44:01 +03001517
Laurent Pinchartf33656e2018-02-13 14:00:29 +02001518 dss_debugfs_remove_file(dss->debugfs.clk);
1519 dss_debugfs_remove_file(dss->debugfs.dss);
Laurent Pinchart1c4b92e2018-02-13 14:00:31 +02001520 dss_uninitialize_debugfs(dss);
Laurent Pinchart11765d12017-08-05 01:44:01 +03001521
Laurent Pinchart215003b2018-02-11 15:07:44 +02001522 pm_runtime_disable(&pdev->dev);
1523
Laurent Pinchart360c2152018-02-13 14:00:28 +02001524 dss_uninit_ports(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001525
Laurent Pinchart360c2152018-02-13 14:00:28 +02001526 if (dss->video1_pll)
1527 dss_video_pll_uninit(dss->video1_pll);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001528
Laurent Pinchart360c2152018-02-13 14:00:28 +02001529 if (dss->video2_pll)
1530 dss_video_pll_uninit(dss->video2_pll);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001531
Laurent Pinchart360c2152018-02-13 14:00:28 +02001532 dss_put_clocks(dss);
1533
1534 kfree(dss);
Laurent Pinchart215003b2018-02-11 15:07:44 +02001535
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001536 return 0;
1537}
1538
Laurent Pinchart74592ee2017-08-05 01:44:02 +03001539static void dss_shutdown(struct platform_device *pdev)
1540{
1541 struct omap_dss_device *dssdev = NULL;
1542
1543 DSSDBG("shutdown\n");
1544
1545 for_each_dss_dev(dssdev) {
1546 if (!dssdev->driver)
1547 continue;
1548
1549 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1550 dssdev->driver->disable(dssdev);
1551 }
1552}
1553
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001554static int dss_runtime_suspend(struct device *dev)
1555{
Laurent Pinchart360c2152018-02-13 14:00:28 +02001556 struct dss_device *dss = dev_get_drvdata(dev);
1557
1558 dss_save_context(dss);
Tomi Valkeinena8081d32012-03-08 12:52:38 +02001559 dss_set_min_bus_tput(dev, 0);
Dave Gerlach5038bb82014-10-31 16:28:57 -05001560
1561 pinctrl_pm_select_sleep_state(dev);
1562
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001563 return 0;
1564}
1565
1566static int dss_runtime_resume(struct device *dev)
1567{
Laurent Pinchart360c2152018-02-13 14:00:28 +02001568 struct dss_device *dss = dev_get_drvdata(dev);
Tomi Valkeinena8081d32012-03-08 12:52:38 +02001569 int r;
Dave Gerlach5038bb82014-10-31 16:28:57 -05001570
1571 pinctrl_pm_select_default_state(dev);
1572
Tomi Valkeinena8081d32012-03-08 12:52:38 +02001573 /*
1574 * Set an arbitrarily high tput request to ensure OPP100.
1575 * What we should really do is to make a request to stay in OPP100,
1576 * without any tput requirements, but that is not currently possible
1577 * via the PM layer.
1578 */
1579
1580 r = dss_set_min_bus_tput(dev, 1000000000);
1581 if (r)
1582 return r;
1583
Laurent Pinchart360c2152018-02-13 14:00:28 +02001584 dss_restore_context(dss);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001585 return 0;
1586}
1587
1588static const struct dev_pm_ops dss_pm_ops = {
1589 .runtime_suspend = dss_runtime_suspend,
1590 .runtime_resume = dss_runtime_resume,
1591};
1592
Andrew F. Davisd66c36a2017-12-05 14:29:32 -06001593struct platform_driver omap_dsshw_driver = {
Tomi Valkeinen736e60d2015-06-04 15:22:23 +03001594 .probe = dss_probe,
1595 .remove = dss_remove,
Laurent Pinchart74592ee2017-08-05 01:44:02 +03001596 .shutdown = dss_shutdown,
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001597 .driver = {
1598 .name = "omapdss_dss",
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001599 .pm = &dss_pm_ops,
Tomi Valkeinen2ecef242013-12-16 15:13:24 +02001600 .of_match_table = dss_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +03001601 .suppress_bind_attrs = true,
Senthilvadivu Guruswamy96c401b2011-01-24 06:21:57 +00001602 },
1603};