Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 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/clk.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/err.h> |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 26 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 27 | |
| 28 | #include <plat/display.h> |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 29 | #include <plat/cpu.h> |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 30 | #include "dss.h" |
| 31 | |
| 32 | static struct { |
| 33 | bool skip_init; |
| 34 | bool update_enabled; |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 35 | struct regulator *vdds_sdi_reg; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 36 | } sdi; |
| 37 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 38 | static void sdi_basic_init(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 39 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 40 | { |
| 41 | dispc_set_parallel_interface_mode(dssdev->manager->id, |
| 42 | OMAP_DSS_PARALLELMODE_BYPASS); |
| 43 | |
| 44 | dispc_set_lcd_display_type(dssdev->manager->id, |
| 45 | OMAP_DSS_LCD_DISPLAY_TFT); |
| 46 | |
| 47 | dispc_set_tft_data_lines(dssdev->manager->id, 24); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 48 | dispc_lcd_enable_signal_polarity(1); |
| 49 | } |
| 50 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 51 | int omapdss_sdi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 52 | { |
| 53 | struct omap_video_timings *t = &dssdev->panel.timings; |
| 54 | struct dss_clock_info dss_cinfo; |
| 55 | struct dispc_clock_info dispc_cinfo; |
| 56 | u16 lck_div, pck_div; |
| 57 | unsigned long fck; |
| 58 | unsigned long pck; |
| 59 | int r; |
| 60 | |
| 61 | r = omap_dss_start_device(dssdev); |
| 62 | if (r) { |
| 63 | DSSERR("failed to start device\n"); |
| 64 | goto err0; |
| 65 | } |
| 66 | |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 67 | r = regulator_enable(sdi.vdds_sdi_reg); |
| 68 | if (r) |
| 69 | goto err1; |
| 70 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 71 | /* In case of skip_init sdi_init has already enabled the clocks */ |
| 72 | if (!sdi.skip_init) |
Archit Taneja | 6af9cd1 | 2011-01-31 16:27:44 +0000 | [diff] [blame] | 73 | dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 74 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 75 | sdi_basic_init(dssdev); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 76 | |
| 77 | /* 15.5.9.1.2 */ |
| 78 | dssdev->panel.config |= OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF; |
| 79 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 80 | dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config, |
| 81 | dssdev->panel.acbi, dssdev->panel.acb); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 82 | |
| 83 | if (!sdi.skip_init) { |
| 84 | r = dss_calc_clock_div(1, t->pixel_clock * 1000, |
| 85 | &dss_cinfo, &dispc_cinfo); |
| 86 | } else { |
| 87 | r = dss_get_clock_div(&dss_cinfo); |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 88 | r = dispc_get_clock_div(dssdev->manager->id, &dispc_cinfo); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | if (r) |
| 92 | goto err2; |
| 93 | |
| 94 | fck = dss_cinfo.fck; |
| 95 | lck_div = dispc_cinfo.lck_div; |
| 96 | pck_div = dispc_cinfo.pck_div; |
| 97 | |
| 98 | pck = fck / lck_div / pck_div / 1000; |
| 99 | |
| 100 | if (pck != t->pixel_clock) { |
| 101 | DSSWARN("Could not find exact pixel clock. Requested %d kHz, " |
| 102 | "got %lu kHz\n", |
| 103 | t->pixel_clock, pck); |
| 104 | |
| 105 | t->pixel_clock = pck; |
| 106 | } |
| 107 | |
| 108 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 109 | dispc_set_lcd_timings(dssdev->manager->id, t); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 110 | |
| 111 | r = dss_set_clock_div(&dss_cinfo); |
| 112 | if (r) |
| 113 | goto err2; |
| 114 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 115 | r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 116 | if (r) |
| 117 | goto err2; |
| 118 | |
| 119 | if (!sdi.skip_init) { |
| 120 | dss_sdi_init(dssdev->phy.sdi.datapairs); |
| 121 | r = dss_sdi_enable(); |
| 122 | if (r) |
| 123 | goto err1; |
| 124 | mdelay(2); |
| 125 | } |
| 126 | |
Tomi Valkeinen | a2faee8 | 2010-01-08 17:14:53 +0200 | [diff] [blame] | 127 | dssdev->manager->enable(dssdev->manager); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 128 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 129 | sdi.skip_init = 0; |
| 130 | |
| 131 | return 0; |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 132 | err2: |
Archit Taneja | 6af9cd1 | 2011-01-31 16:27:44 +0000 | [diff] [blame] | 133 | dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK); |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 134 | regulator_disable(sdi.vdds_sdi_reg); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 135 | err1: |
| 136 | omap_dss_stop_device(dssdev); |
| 137 | err0: |
| 138 | return r; |
| 139 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 140 | EXPORT_SYMBOL(omapdss_sdi_display_enable); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 141 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 142 | void omapdss_sdi_display_disable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 143 | { |
Tomi Valkeinen | a2faee8 | 2010-01-08 17:14:53 +0200 | [diff] [blame] | 144 | dssdev->manager->disable(dssdev->manager); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 145 | |
| 146 | dss_sdi_disable(); |
| 147 | |
Archit Taneja | 6af9cd1 | 2011-01-31 16:27:44 +0000 | [diff] [blame] | 148 | dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 149 | |
Roger Quadros | 508886c | 2010-03-17 13:35:21 +0100 | [diff] [blame] | 150 | regulator_disable(sdi.vdds_sdi_reg); |
| 151 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 152 | omap_dss_stop_device(dssdev); |
| 153 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 154 | EXPORT_SYMBOL(omapdss_sdi_display_disable); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 155 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 156 | int sdi_init_display(struct omap_dss_device *dssdev) |
| 157 | { |
| 158 | DSSDBG("SDI init\n"); |
| 159 | |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame^] | 160 | if (sdi.vdds_sdi_reg == NULL) { |
| 161 | struct regulator *vdds_sdi; |
| 162 | |
| 163 | vdds_sdi = dss_get_vdds_sdi(); |
| 164 | |
| 165 | if (IS_ERR(vdds_sdi)) { |
| 166 | DSSERR("can't get VDDS_SDI regulator\n"); |
| 167 | return PTR_ERR(vdds_sdi); |
| 168 | } |
| 169 | |
| 170 | sdi.vdds_sdi_reg = vdds_sdi; |
| 171 | } |
| 172 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int sdi_init(bool skip_init) |
| 177 | { |
| 178 | /* we store this for first display enable, then clear it */ |
| 179 | sdi.skip_init = skip_init; |
| 180 | |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 181 | /* |
| 182 | * Enable clocks already here, otherwise there would be a toggle |
| 183 | * of them until sdi_display_enable is called. |
| 184 | */ |
| 185 | if (skip_init) |
Archit Taneja | 6af9cd1 | 2011-01-31 16:27:44 +0000 | [diff] [blame] | 186 | dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK); |
Tomi Valkeinen | 23c0a7a | 2009-08-05 16:18:44 +0300 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | void sdi_exit(void) |
| 191 | { |
| 192 | } |