blob: 3be8134ec2d96f86ce408b9d0075290910d4482f [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 Valkeinena57dd4f2012-02-20 16:57:37 +020027#include <linux/platform_device.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030028
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030029#include <video/omapdss.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030030#include "dss.h"
31
32static struct {
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030033 bool update_enabled;
Roger Quadros508886c2010-03-17 13:35:21 +010034 struct regulator *vdds_sdi_reg;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030035} sdi;
36
Sumit Semwal64ba4f72010-12-02 11:27:10 +000037static void sdi_basic_init(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030038
Sumit Semwal64ba4f72010-12-02 11:27:10 +000039{
Archit Taneja569969d2011-08-22 17:41:57 +053040 dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
41 dispc_mgr_enable_stallmode(dssdev->manager->id, false);
Sumit Semwal64ba4f72010-12-02 11:27:10 +000042
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +030043 dispc_mgr_set_lcd_display_type(dssdev->manager->id,
Sumit Semwal64ba4f72010-12-02 11:27:10 +000044 OMAP_DSS_LCD_DISPLAY_TFT);
45
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +030046 dispc_mgr_set_tft_data_lines(dssdev->manager->id, 24);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030047 dispc_lcd_enable_signal_polarity(1);
48}
49
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +020050int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030051{
52 struct omap_video_timings *t = &dssdev->panel.timings;
53 struct dss_clock_info dss_cinfo;
54 struct dispc_clock_info dispc_cinfo;
55 u16 lck_div, pck_div;
56 unsigned long fck;
57 unsigned long pck;
58 int r;
59
Tomi Valkeinen05e1d602011-06-23 16:38:21 +030060 if (dssdev->manager == NULL) {
61 DSSERR("failed to enable display: no manager\n");
62 return -ENODEV;
63 }
64
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030065 r = omap_dss_start_device(dssdev);
66 if (r) {
67 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030068 goto err_start_dev;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030069 }
70
Roger Quadros508886c2010-03-17 13:35:21 +010071 r = regulator_enable(sdi.vdds_sdi_reg);
72 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030073 goto err_reg_enable;
Roger Quadros508886c2010-03-17 13:35:21 +010074
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030075 r = dispc_runtime_get();
76 if (r)
77 goto err_get_dispc;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030078
Sumit Semwal64ba4f72010-12-02 11:27:10 +000079 sdi_basic_init(dssdev);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030080
81 /* 15.5.9.1.2 */
82 dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
83
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +030084 dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000085 dssdev->panel.acbi, dssdev->panel.acb);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030086
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +020087 r = dss_calc_clock_div(1, t->pixel_clock * 1000,
88 &dss_cinfo, &dispc_cinfo);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030089 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030090 goto err_calc_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030091
92 fck = dss_cinfo.fck;
93 lck_div = dispc_cinfo.lck_div;
94 pck_div = dispc_cinfo.pck_div;
95
96 pck = fck / lck_div / pck_div / 1000;
97
98 if (pck != t->pixel_clock) {
99 DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
100 "got %lu kHz\n",
101 t->pixel_clock, pck);
102
103 t->pixel_clock = pck;
104 }
105
106
Archit Taneja41721162012-04-26 20:10:46 +0530107 dss_mgr_set_timings(dssdev->manager, t);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300108
109 r = dss_set_clock_div(&dss_cinfo);
110 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300111 goto err_set_dss_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300112
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +0300113 r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300114 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300115 goto err_set_dispc_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300116
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200117 dss_sdi_init(dssdev->phy.sdi.datapairs);
118 r = dss_sdi_enable();
119 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300120 goto err_sdi_enable;
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200121 mdelay(2);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300122
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200123 r = dss_mgr_enable(dssdev->manager);
124 if (r)
125 goto err_mgr_enable;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300126
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300127 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300128
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200129err_mgr_enable:
130 dss_sdi_disable();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300131err_sdi_enable:
132err_set_dispc_clock_div:
133err_set_dss_clock_div:
134err_calc_clock_div:
135 dispc_runtime_put();
136err_get_dispc:
Roger Quadros508886c2010-03-17 13:35:21 +0100137 regulator_disable(sdi.vdds_sdi_reg);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300138err_reg_enable:
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300139 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300140err_start_dev:
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300141 return r;
142}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200143EXPORT_SYMBOL(omapdss_sdi_display_enable);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300144
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200145void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300146{
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200147 dss_mgr_disable(dssdev->manager);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300148
149 dss_sdi_disable();
150
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300151 dispc_runtime_put();
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300152
Roger Quadros508886c2010-03-17 13:35:21 +0100153 regulator_disable(sdi.vdds_sdi_reg);
154
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300155 omap_dss_stop_device(dssdev);
156}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200157EXPORT_SYMBOL(omapdss_sdi_display_disable);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300158
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300159int sdi_init_display(struct omap_dss_device *dssdev)
160{
161 DSSDBG("SDI init\n");
162
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +0200163 if (sdi.vdds_sdi_reg == NULL) {
164 struct regulator *vdds_sdi;
165
166 vdds_sdi = dss_get_vdds_sdi();
167
168 if (IS_ERR(vdds_sdi)) {
169 DSSERR("can't get VDDS_SDI regulator\n");
170 return PTR_ERR(vdds_sdi);
171 }
172
173 sdi.vdds_sdi_reg = vdds_sdi;
174 }
175
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300176 return 0;
177}
178
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200179static int __init omap_sdi_probe(struct platform_device *pdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300180{
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200181 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
182 int i, r;
183
184 for (i = 0; i < pdata->num_devices; ++i) {
185 struct omap_dss_device *dssdev = pdata->devices[i];
186
187 if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
188 continue;
189
190 r = omap_dss_register_device(dssdev, &pdev->dev, i);
191 if (r)
192 DSSERR("device %s register failed: %d\n",
193 dssdev->name, r);
194 }
195
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300196 return 0;
197}
198
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200199static int __exit omap_sdi_remove(struct platform_device *pdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300200{
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200201 omap_dss_unregister_child_devices(&pdev->dev);
202
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200203 return 0;
204}
205
206static struct platform_driver omap_sdi_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200207 .remove = __exit_p(omap_sdi_remove),
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200208 .driver = {
209 .name = "omapdss_sdi",
210 .owner = THIS_MODULE,
211 },
212};
213
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200214int __init sdi_init_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200215{
Tomi Valkeinen61055d42012-03-07 12:53:38 +0200216 return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200217}
218
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200219void __exit sdi_uninit_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200220{
221 platform_driver_unregister(&omap_sdi_driver);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300222}