blob: c27b58ad8e4d547887ddec169ce5a064e07bc789 [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 Valkeinen13b1ba72012-09-28 10:03:03 +030028#include <linux/string.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030029
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030030#include <video/omapdss.h>
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030031#include "dss.h"
32
33static struct {
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030034 bool update_enabled;
Roger Quadros508886c2010-03-17 13:35:21 +010035 struct regulator *vdds_sdi_reg;
Archit Taneja37a57992012-06-29 14:33:18 +053036
37 struct dss_lcd_mgr_config mgr_config;
Archit Taneja9b4a5712012-08-08 16:56:06 +053038 struct omap_video_timings timings;
Archit Taneja889b4fd2012-07-20 17:18:49 +053039 int datapairs;
Archit Taneja81b87f52012-09-26 16:30:49 +053040
41 struct omap_dss_output output;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030042} sdi;
43
Archit Taneja37a57992012-06-29 14:33:18 +053044static void sdi_config_lcd_manager(struct omap_dss_device *dssdev)
Sumit Semwal64ba4f72010-12-02 11:27:10 +000045{
Archit Taneja7d6069e2012-09-04 11:49:30 +053046 struct omap_overlay_manager *mgr = dssdev->output->manager;
47
Archit Taneja37a57992012-06-29 14:33:18 +053048 sdi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
49
50 sdi.mgr_config.stallmode = false;
51 sdi.mgr_config.fifohandcheck = false;
52
53 sdi.mgr_config.video_port_width = 24;
54 sdi.mgr_config.lcden_sig_polarity = 1;
55
Archit Taneja7d6069e2012-09-04 11:49:30 +053056 dss_mgr_set_lcd_config(mgr, &sdi.mgr_config);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030057}
58
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +020059int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030060{
Archit Taneja7d6069e2012-09-04 11:49:30 +053061 struct omap_dss_output *out = dssdev->output;
Archit Taneja9b4a5712012-08-08 16:56:06 +053062 struct omap_video_timings *t = &sdi.timings;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030063 struct dss_clock_info dss_cinfo;
64 struct dispc_clock_info dispc_cinfo;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030065 unsigned long pck;
66 int r;
67
Archit Taneja7d6069e2012-09-04 11:49:30 +053068 if (out == NULL || out->manager == NULL) {
69 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +030070 return -ENODEV;
71 }
72
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030073 r = omap_dss_start_device(dssdev);
74 if (r) {
75 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030076 goto err_start_dev;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030077 }
78
Roger Quadros508886c2010-03-17 13:35:21 +010079 r = regulator_enable(sdi.vdds_sdi_reg);
80 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030081 goto err_reg_enable;
Roger Quadros508886c2010-03-17 13:35:21 +010082
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030083 r = dispc_runtime_get();
84 if (r)
85 goto err_get_dispc;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030086
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030087 /* 15.5.9.1.2 */
Archit Taneja9b4a5712012-08-08 16:56:06 +053088 t->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
89 t->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
Archit Tanejaa8d5e412012-06-25 12:26:38 +053090
Archit Taneja6d523e72012-06-21 09:33:55 +053091 r = dss_calc_clock_div(t->pixel_clock * 1000, &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
Archit Taneja37a57992012-06-29 14:33:18 +053095 sdi.mgr_config.clock_info = dispc_cinfo;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030096
Archit Taneja37a57992012-06-29 14:33:18 +053097 pck = dss_cinfo.fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div / 1000;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +030098
99 if (pck != t->pixel_clock) {
100 DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
101 "got %lu kHz\n",
102 t->pixel_clock, pck);
103
104 t->pixel_clock = pck;
105 }
106
107
Archit Taneja7d6069e2012-09-04 11:49:30 +0530108 dss_mgr_set_timings(out->manager, t);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300109
110 r = dss_set_clock_div(&dss_cinfo);
111 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300112 goto err_set_dss_clock_div;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300113
Archit Taneja37a57992012-06-29 14:33:18 +0530114 sdi_config_lcd_manager(dssdev);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300115
Tomi Valkeinen35d67862012-08-21 09:09:47 +0300116 /*
117 * LCLK and PCLK divisors are located in shadow registers, and we
118 * normally write them to DISPC registers when enabling the output.
119 * However, SDI uses pck-free as source clock for its PLL, and pck-free
120 * is affected by the divisors. And as we need the PLL before enabling
121 * the output, we need to write the divisors early.
122 *
123 * It seems just writing to the DISPC register is enough, and we don't
124 * need to care about the shadow register mechanism for pck-free. The
125 * exact reason for this is unknown.
126 */
Archit Taneja7d6069e2012-09-04 11:49:30 +0530127 dispc_mgr_set_clock_div(out->manager->id, &sdi.mgr_config.clock_info);
Archit Taneja889b4fd2012-07-20 17:18:49 +0530128
Tomi Valkeinen66591452012-09-11 11:28:59 +0300129 dss_sdi_init(sdi.datapairs);
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200130 r = dss_sdi_enable();
131 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300132 goto err_sdi_enable;
Tomi Valkeinen42c9dee2011-03-02 12:29:27 +0200133 mdelay(2);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300134
Archit Taneja7d6069e2012-09-04 11:49:30 +0530135 r = dss_mgr_enable(out->manager);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200136 if (r)
137 goto err_mgr_enable;
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300138
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300139 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300140
Tomi Valkeinen33ca2372011-11-21 13:42:58 +0200141err_mgr_enable:
142 dss_sdi_disable();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300143err_sdi_enable:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300144err_set_dss_clock_div:
145err_calc_clock_div:
146 dispc_runtime_put();
147err_get_dispc:
Roger Quadros508886c2010-03-17 13:35:21 +0100148 regulator_disable(sdi.vdds_sdi_reg);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300149err_reg_enable:
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300150 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300151err_start_dev:
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300152 return r;
153}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200154EXPORT_SYMBOL(omapdss_sdi_display_enable);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300155
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200156void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300157{
Archit Taneja7d6069e2012-09-04 11:49:30 +0530158 struct omap_overlay_manager *mgr = dssdev->output->manager;
159
160 dss_mgr_disable(mgr);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300161
162 dss_sdi_disable();
163
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300164 dispc_runtime_put();
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300165
Roger Quadros508886c2010-03-17 13:35:21 +0100166 regulator_disable(sdi.vdds_sdi_reg);
167
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300168 omap_dss_stop_device(dssdev);
169}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200170EXPORT_SYMBOL(omapdss_sdi_display_disable);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300171
Archit Tanejac7833f72012-07-05 17:11:12 +0530172void omapdss_sdi_set_timings(struct omap_dss_device *dssdev,
173 struct omap_video_timings *timings)
174{
Archit Taneja9b4a5712012-08-08 16:56:06 +0530175 sdi.timings = *timings;
Archit Tanejac7833f72012-07-05 17:11:12 +0530176}
177EXPORT_SYMBOL(omapdss_sdi_set_timings);
178
Archit Taneja889b4fd2012-07-20 17:18:49 +0530179void omapdss_sdi_set_datapairs(struct omap_dss_device *dssdev, int datapairs)
180{
181 sdi.datapairs = datapairs;
182}
183EXPORT_SYMBOL(omapdss_sdi_set_datapairs);
184
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +0200185static int __init sdi_init_display(struct omap_dss_device *dssdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300186{
187 DSSDBG("SDI init\n");
188
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +0200189 if (sdi.vdds_sdi_reg == NULL) {
190 struct regulator *vdds_sdi;
191
192 vdds_sdi = dss_get_vdds_sdi();
193
194 if (IS_ERR(vdds_sdi)) {
195 DSSERR("can't get VDDS_SDI regulator\n");
196 return PTR_ERR(vdds_sdi);
197 }
198
199 sdi.vdds_sdi_reg = vdds_sdi;
200 }
201
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300202 return 0;
203}
204
Tomi Valkeinen15216532012-09-06 14:29:31 +0300205static struct omap_dss_device * __init sdi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300206{
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200207 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
Tomi Valkeinen2bbcce52012-10-29 12:40:46 +0200208 const char *def_disp_name = omapdss_get_default_display_name();
Tomi Valkeinen15216532012-09-06 14:29:31 +0300209 struct omap_dss_device *def_dssdev;
210 int i;
211
212 def_dssdev = NULL;
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200213
214 for (i = 0; i < pdata->num_devices; ++i) {
215 struct omap_dss_device *dssdev = pdata->devices[i];
216
217 if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
218 continue;
219
Tomi Valkeinen15216532012-09-06 14:29:31 +0300220 if (def_dssdev == NULL)
221 def_dssdev = dssdev;
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +0200222
Tomi Valkeinen15216532012-09-06 14:29:31 +0300223 if (def_disp_name != NULL &&
224 strcmp(dssdev->name, def_disp_name) == 0) {
225 def_dssdev = dssdev;
226 break;
227 }
228 }
229
230 return def_dssdev;
231}
232
Tomi Valkeinen52744842012-09-10 13:58:29 +0300233static void __init sdi_probe_pdata(struct platform_device *sdidev)
Tomi Valkeinen15216532012-09-06 14:29:31 +0300234{
Tomi Valkeinen52744842012-09-10 13:58:29 +0300235 struct omap_dss_device *plat_dssdev;
Tomi Valkeinen15216532012-09-06 14:29:31 +0300236 struct omap_dss_device *dssdev;
237 int r;
238
Tomi Valkeinen52744842012-09-10 13:58:29 +0300239 plat_dssdev = sdi_find_dssdev(sdidev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300240
Tomi Valkeinen52744842012-09-10 13:58:29 +0300241 if (!plat_dssdev)
242 return;
243
244 dssdev = dss_alloc_and_init_device(&sdidev->dev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300245 if (!dssdev)
246 return;
247
Tomi Valkeinen52744842012-09-10 13:58:29 +0300248 dss_copy_device_pdata(dssdev, plat_dssdev);
249
Tomi Valkeinen15216532012-09-06 14:29:31 +0300250 r = sdi_init_display(dssdev);
251 if (r) {
252 DSSERR("device %s init failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +0300253 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300254 return;
255 }
256
Tomi Valkeinen486c0e12012-12-07 12:50:08 +0200257 r = omapdss_output_set_device(&sdi.output, dssdev);
258 if (r) {
259 DSSERR("failed to connect output to new device: %s\n",
260 dssdev->name);
261 dss_put_device(dssdev);
262 return;
263 }
264
Tomi Valkeinen52744842012-09-10 13:58:29 +0300265 r = dss_add_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300266 if (r) {
267 DSSERR("device %s register failed: %d\n", dssdev->name, r);
Tomi Valkeinen486c0e12012-12-07 12:50:08 +0200268 omapdss_output_unset_device(&sdi.output);
Tomi Valkeinen52744842012-09-10 13:58:29 +0300269 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +0300270 return;
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200271 }
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300272}
273
Archit Taneja81b87f52012-09-26 16:30:49 +0530274static void __init sdi_init_output(struct platform_device *pdev)
275{
276 struct omap_dss_output *out = &sdi.output;
277
278 out->pdev = pdev;
279 out->id = OMAP_DSS_OUTPUT_SDI;
280 out->type = OMAP_DISPLAY_TYPE_SDI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +0200281 out->name = "sdi.0";
Archit Taneja81b87f52012-09-26 16:30:49 +0530282
283 dss_register_output(out);
284}
285
286static void __exit sdi_uninit_output(struct platform_device *pdev)
287{
288 struct omap_dss_output *out = &sdi.output;
289
290 dss_unregister_output(out);
291}
292
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300293static int __init omap_sdi_probe(struct platform_device *pdev)
294{
Archit Taneja81b87f52012-09-26 16:30:49 +0530295 sdi_init_output(pdev);
296
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +0300297 sdi_probe_pdata(pdev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200298
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300299 return 0;
300}
301
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200302static int __exit omap_sdi_remove(struct platform_device *pdev)
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300303{
Tomi Valkeinen52744842012-09-10 13:58:29 +0300304 dss_unregister_child_devices(&pdev->dev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +0200305
Archit Taneja81b87f52012-09-26 16:30:49 +0530306 sdi_uninit_output(pdev);
307
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200308 return 0;
309}
310
311static struct platform_driver omap_sdi_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200312 .remove = __exit_p(omap_sdi_remove),
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200313 .driver = {
314 .name = "omapdss_sdi",
315 .owner = THIS_MODULE,
316 },
317};
318
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200319int __init sdi_init_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200320{
Tomi Valkeinen61055d42012-03-07 12:53:38 +0200321 return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200322}
323
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +0200324void __exit sdi_uninit_platform_driver(void)
Tomi Valkeinena57dd4f2012-02-20 16:57:37 +0200325{
326 platform_driver_unregister(&omap_sdi_driver);
Tomi Valkeinen23c0a7a2009-08-05 16:18:44 +0300327}