KVM: x86: update KVM_SAVE_MSRS_BEGIN to correct value
[cascardo/linux.git] / drivers / video / omap2 / dss / sdi.c
1 /*
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>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/regulator/consumer.h>
26 #include <linux/export.h>
27 #include <linux/platform_device.h>
28
29 #include <video/omapdss.h>
30 #include "dss.h"
31
32 static struct {
33         bool update_enabled;
34         struct regulator *vdds_sdi_reg;
35 } sdi;
36
37 static void sdi_basic_init(struct omap_dss_device *dssdev)
38
39 {
40         dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
41         dispc_mgr_enable_stallmode(dssdev->manager->id, false);
42
43         dispc_mgr_set_lcd_display_type(dssdev->manager->id,
44                         OMAP_DSS_LCD_DISPLAY_TFT);
45
46         dispc_mgr_set_tft_data_lines(dssdev->manager->id, 24);
47         dispc_lcd_enable_signal_polarity(1);
48 }
49
50 int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
51 {
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
60         if (dssdev->manager == NULL) {
61                 DSSERR("failed to enable display: no manager\n");
62                 return -ENODEV;
63         }
64
65         r = omap_dss_start_device(dssdev);
66         if (r) {
67                 DSSERR("failed to start device\n");
68                 goto err_start_dev;
69         }
70
71         r = regulator_enable(sdi.vdds_sdi_reg);
72         if (r)
73                 goto err_reg_enable;
74
75         r = dispc_runtime_get();
76         if (r)
77                 goto err_get_dispc;
78
79         sdi_basic_init(dssdev);
80
81         /* 15.5.9.1.2 */
82         dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
83
84         dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
85                         dssdev->panel.acbi, dssdev->panel.acb);
86
87         r = dss_calc_clock_div(1, t->pixel_clock * 1000,
88                         &dss_cinfo, &dispc_cinfo);
89         if (r)
90                 goto err_calc_clock_div;
91
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
107         dss_mgr_set_timings(dssdev->manager, t);
108
109         r = dss_set_clock_div(&dss_cinfo);
110         if (r)
111                 goto err_set_dss_clock_div;
112
113         r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
114         if (r)
115                 goto err_set_dispc_clock_div;
116
117         dss_sdi_init(dssdev->phy.sdi.datapairs);
118         r = dss_sdi_enable();
119         if (r)
120                 goto err_sdi_enable;
121         mdelay(2);
122
123         r = dss_mgr_enable(dssdev->manager);
124         if (r)
125                 goto err_mgr_enable;
126
127         return 0;
128
129 err_mgr_enable:
130         dss_sdi_disable();
131 err_sdi_enable:
132 err_set_dispc_clock_div:
133 err_set_dss_clock_div:
134 err_calc_clock_div:
135         dispc_runtime_put();
136 err_get_dispc:
137         regulator_disable(sdi.vdds_sdi_reg);
138 err_reg_enable:
139         omap_dss_stop_device(dssdev);
140 err_start_dev:
141         return r;
142 }
143 EXPORT_SYMBOL(omapdss_sdi_display_enable);
144
145 void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
146 {
147         dss_mgr_disable(dssdev->manager);
148
149         dss_sdi_disable();
150
151         dispc_runtime_put();
152
153         regulator_disable(sdi.vdds_sdi_reg);
154
155         omap_dss_stop_device(dssdev);
156 }
157 EXPORT_SYMBOL(omapdss_sdi_display_disable);
158
159 static int __init sdi_init_display(struct omap_dss_device *dssdev)
160 {
161         DSSDBG("SDI init\n");
162
163         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
176         return 0;
177 }
178
179 static void __init sdi_probe_pdata(struct platform_device *pdev)
180 {
181         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 = sdi_init_display(dssdev);
191                 if (r) {
192                         DSSERR("device %s init failed: %d\n", dssdev->name, r);
193                         continue;
194                 }
195
196                 r = omap_dss_register_device(dssdev, &pdev->dev, i);
197                 if (r)
198                         DSSERR("device %s register failed: %d\n",
199                                         dssdev->name, r);
200         }
201 }
202
203 static int __init omap_sdi_probe(struct platform_device *pdev)
204 {
205         sdi_probe_pdata(pdev);
206
207         return 0;
208 }
209
210 static int __exit omap_sdi_remove(struct platform_device *pdev)
211 {
212         omap_dss_unregister_child_devices(&pdev->dev);
213
214         return 0;
215 }
216
217 static struct platform_driver omap_sdi_driver = {
218         .remove         = __exit_p(omap_sdi_remove),
219         .driver         = {
220                 .name   = "omapdss_sdi",
221                 .owner  = THIS_MODULE,
222         },
223 };
224
225 int __init sdi_init_platform_driver(void)
226 {
227         return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
228 }
229
230 void __exit sdi_uninit_platform_driver(void)
231 {
232         platform_driver_unregister(&omap_sdi_driver);
233 }