blob: 40305ad7841e26971ca8e88035af7385a85ce260 [file] [log] [blame]
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +03001/*
2 * linux/drivers/video/omap2/dss/sdi.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define DSS_SUBSYS_NAME "SDI"
21
22#include <linux/kernel.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030023#include <linux/delay.h>
24#include <linux/err.h>
Roger Quadros508886c2010-03-17 13:35:21 +010025#include <linux/regulator/consumer.h>
Paul Gortmakera8a35932011-07-10 13:20:26 -040026#include <linux/export.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030027
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030028#include <video/omapdss.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030029#include "dss.h"
30
31static struct {
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030032 bool update_enabled;
Roger Quadros508886c2010-03-17 13:35:21 +010033 struct regulator *vdds_sdi_reg;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030034} sdi;
35
Sumit Semwal64ba4f72010-12-02 11:27:10 +000036static void sdi_basic_init(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030037
Sumit Semwal64ba4f72010-12-02 11:27:10 +000038{
Archit Taneja569969d2011-08-22 17:41:57 +053039 dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
40 dispc_mgr_enable_stallmode(dssdev->manager->id, false);
Sumit Semwal64ba4f72010-12-02 11:27:10 +000041
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +030042 dispc_mgr_set_lcd_display_type(dssdev->manager->id,
Sumit Semwal64ba4f72010-12-02 11:27:10 +000043 OMAP_DSS_LCD_DISPLAY_TFT);
44
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +030045 dispc_mgr_set_tft_data_lines(dssdev->manager->id, 24);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030046 dispc_lcd_enable_signal_polarity(1);
47}
48
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +020049int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030050{
51 struct omap_video_timings *t = &dssdev->panel.timings;
52 struct dss_clock_info dss_cinfo;
53 struct dispc_clock_info dispc_cinfo;
54 u16 lck_div, pck_div;
55 unsigned long fck;
56 unsigned long pck;
57 int r;
58
Tomi Valkeinen05e1d602011-06-23 16:38:21 +030059 if (dssdev->manager == NULL) {
60 DSSERR("failed to enable display: no manager\n");
61 return -ENODEV;
62 }
63
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030064 r = omap_dss_start_device(dssdev);
65 if (r) {
66 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030067 goto err_start_dev;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030068 }
69
Roger Quadros508886c2010-03-17 13:35:21 +010070 r = regulator_enable(sdi.vdds_sdi_reg);
71 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030072 goto err_reg_enable;
Roger Quadros508886c2010-03-17 13:35:21 +010073
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030074 r = dss_runtime_get();
75 if (r)
76 goto err_get_dss;
77
78 r = dispc_runtime_get();
79 if (r)
80 goto err_get_dispc;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030081
Sumit Semwal64ba4f72010-12-02 11:27:10 +000082 sdi_basic_init(dssdev);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030083
84 /* 15.5.9.1.2 */
85 dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
86
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +030087 dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000088 dssdev->panel.acbi, dssdev->panel.acb);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030089
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +020090 r = dss_calc_clock_div(1, t->pixel_clock * 1000,
91 &dss_cinfo, &dispc_cinfo);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030092 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030093 goto err_calc_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030094
95 fck = dss_cinfo.fck;
96 lck_div = dispc_cinfo.lck_div;
97 pck_div = dispc_cinfo.pck_div;
98
99 pck = fck / lck_div / pck_div / 1000;
100
101 if (pck != t->pixel_clock) {
102 DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
103 "got %lu kHz\n",
104 t->pixel_clock, pck);
105
106 t->pixel_clock = pck;
107 }
108
109
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300110 dispc_mgr_set_lcd_timings(dssdev->manager->id, t);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300111
112 r = dss_set_clock_div(&dss_cinfo);
113 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300114 goto err_set_dss_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300115
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300116 r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300117 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300118 goto err_set_dispc_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300119
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200120 dss_sdi_init(dssdev->phy.sdi.datapairs);
121 r = dss_sdi_enable();
122 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300123 goto err_sdi_enable;
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200124 mdelay(2);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300125
Tomi Valkeinena2faee82010-01-08 17:14:53 +0200126 dssdev->manager->enable(dssdev->manager);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300127
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300128 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300129
130err_sdi_enable:
131err_set_dispc_clock_div:
132err_set_dss_clock_div:
133err_calc_clock_div:
134 dispc_runtime_put();
135err_get_dispc:
136 dss_runtime_put();
137err_get_dss:
Roger Quadros508886c2010-03-17 13:35:21 +0100138 regulator_disable(sdi.vdds_sdi_reg);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300139err_reg_enable:
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300140 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300141err_start_dev:
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300142 return r;
143}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200144EXPORT_SYMBOL(omapdss_sdi_display_enable);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300145
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200146void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300147{
Tomi Valkeinena2faee82010-01-08 17:14:53 +0200148 dssdev->manager->disable(dssdev->manager);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300149
150 dss_sdi_disable();
151
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300152 dispc_runtime_put();
153 dss_runtime_put();
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300154
Roger Quadros508886c2010-03-17 13:35:21 +0100155 regulator_disable(sdi.vdds_sdi_reg);
156
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300157 omap_dss_stop_device(dssdev);
158}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200159EXPORT_SYMBOL(omapdss_sdi_display_disable);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300160
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300161int sdi_init_display(struct omap_dss_device *dssdev)
162{
163 DSSDBG("SDI init\n");
164
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +0200165 if (sdi.vdds_sdi_reg == NULL) {
166 struct regulator *vdds_sdi;
167
168 vdds_sdi = dss_get_vdds_sdi();
169
170 if (IS_ERR(vdds_sdi)) {
171 DSSERR("can't get VDDS_SDI regulator\n");
172 return PTR_ERR(vdds_sdi);
173 }
174
175 sdi.vdds_sdi_reg = vdds_sdi;
176 }
177
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300178 return 0;
179}
180
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200181int sdi_init(void)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300182{
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300183 return 0;
184}
185
186void sdi_exit(void)
187{
188}