1a369decad38159dc4ae48c7646e82d4adf02571
[linux-3.10.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_type_tft(dssdev->manager->id);
44
45         dispc_mgr_set_tft_data_lines(dssdev->manager->id, 24);
46         dispc_lcd_enable_signal_polarity(1);
47 }
48
49 int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
50 {
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
59         if (dssdev->manager == NULL) {
60                 DSSERR("failed to enable display: no manager\n");
61                 return -ENODEV;
62         }
63
64         r = omap_dss_start_device(dssdev);
65         if (r) {
66                 DSSERR("failed to start device\n");
67                 goto err_start_dev;
68         }
69
70         r = regulator_enable(sdi.vdds_sdi_reg);
71         if (r)
72                 goto err_reg_enable;
73
74         r = dispc_runtime_get();
75         if (r)
76                 goto err_get_dispc;
77
78         sdi_basic_init(dssdev);
79
80         /* 15.5.9.1.2 */
81         dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
82
83         dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
84                         dssdev->panel.acbi, dssdev->panel.acb);
85
86         r = dss_calc_clock_div(t->pixel_clock * 1000, &dss_cinfo, &dispc_cinfo);
87         if (r)
88                 goto err_calc_clock_div;
89
90         fck = dss_cinfo.fck;
91         lck_div = dispc_cinfo.lck_div;
92         pck_div = dispc_cinfo.pck_div;
93
94         pck = fck / lck_div / pck_div / 1000;
95
96         if (pck != t->pixel_clock) {
97                 DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
98                                 "got %lu kHz\n",
99                                 t->pixel_clock, pck);
100
101                 t->pixel_clock = pck;
102         }
103
104
105         dss_mgr_set_timings(dssdev->manager, t);
106
107         r = dss_set_clock_div(&dss_cinfo);
108         if (r)
109                 goto err_set_dss_clock_div;
110
111         r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
112         if (r)
113                 goto err_set_dispc_clock_div;
114
115         dss_sdi_init(dssdev->phy.sdi.datapairs);
116         r = dss_sdi_enable();
117         if (r)
118                 goto err_sdi_enable;
119         mdelay(2);
120
121         r = dss_mgr_enable(dssdev->manager);
122         if (r)
123                 goto err_mgr_enable;
124
125         return 0;
126
127 err_mgr_enable:
128         dss_sdi_disable();
129 err_sdi_enable:
130 err_set_dispc_clock_div:
131 err_set_dss_clock_div:
132 err_calc_clock_div:
133         dispc_runtime_put();
134 err_get_dispc:
135         regulator_disable(sdi.vdds_sdi_reg);
136 err_reg_enable:
137         omap_dss_stop_device(dssdev);
138 err_start_dev:
139         return r;
140 }
141 EXPORT_SYMBOL(omapdss_sdi_display_enable);
142
143 void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
144 {
145         dss_mgr_disable(dssdev->manager);
146
147         dss_sdi_disable();
148
149         dispc_runtime_put();
150
151         regulator_disable(sdi.vdds_sdi_reg);
152
153         omap_dss_stop_device(dssdev);
154 }
155 EXPORT_SYMBOL(omapdss_sdi_display_disable);
156
157 static int __init sdi_init_display(struct omap_dss_device *dssdev)
158 {
159         DSSDBG("SDI init\n");
160
161         if (sdi.vdds_sdi_reg == NULL) {
162                 struct regulator *vdds_sdi;
163
164                 vdds_sdi = dss_get_vdds_sdi();
165
166                 if (IS_ERR(vdds_sdi)) {
167                         DSSERR("can't get VDDS_SDI regulator\n");
168                         return PTR_ERR(vdds_sdi);
169                 }
170
171                 sdi.vdds_sdi_reg = vdds_sdi;
172         }
173
174         return 0;
175 }
176
177 static void __init sdi_probe_pdata(struct platform_device *pdev)
178 {
179         struct omap_dss_board_info *pdata = pdev->dev.platform_data;
180         int i, r;
181
182         for (i = 0; i < pdata->num_devices; ++i) {
183                 struct omap_dss_device *dssdev = pdata->devices[i];
184
185                 if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
186                         continue;
187
188                 r = sdi_init_display(dssdev);
189                 if (r) {
190                         DSSERR("device %s init failed: %d\n", dssdev->name, r);
191                         continue;
192                 }
193
194                 r = omap_dss_register_device(dssdev, &pdev->dev, i);
195                 if (r)
196                         DSSERR("device %s register failed: %d\n",
197                                         dssdev->name, r);
198         }
199 }
200
201 static int __init omap_sdi_probe(struct platform_device *pdev)
202 {
203         sdi_probe_pdata(pdev);
204
205         return 0;
206 }
207
208 static int __exit omap_sdi_remove(struct platform_device *pdev)
209 {
210         omap_dss_unregister_child_devices(&pdev->dev);
211
212         return 0;
213 }
214
215 static struct platform_driver omap_sdi_driver = {
216         .remove         = __exit_p(omap_sdi_remove),
217         .driver         = {
218                 .name   = "omapdss_sdi",
219                 .owner  = THIS_MODULE,
220         },
221 };
222
223 int __init sdi_init_platform_driver(void)
224 {
225         return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
226 }
227
228 void __exit sdi_uninit_platform_driver(void)
229 {
230         platform_driver_unregister(&omap_sdi_driver);
231 }