Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/dss/dpi.c |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * Some code and ideas taken from drivers/video/omap/ driver |
| 8 | * by Imre Deak. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #define DSS_SUBSYS_NAME "DPI" |
| 24 | |
| 25 | #include <linux/kernel.h> |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 26 | #include <linux/delay.h> |
Paul Gortmaker | a8a3593 | 2011-07-10 13:20:26 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 28 | #include <linux/err.h> |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 29 | #include <linux/errno.h> |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
| 31 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 32 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 33 | #include <video/omapdss.h> |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 34 | #include <plat/cpu.h> |
| 35 | |
| 36 | #include "dss.h" |
| 37 | |
| 38 | static struct { |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 39 | struct regulator *vdds_dsi_reg; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 40 | struct platform_device *dsidev; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 41 | } dpi; |
| 42 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 43 | static struct platform_device *dpi_get_dsidev(enum omap_dss_clk_source clk) |
| 44 | { |
| 45 | int dsi_module; |
| 46 | |
| 47 | dsi_module = clk == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ? 0 : 1; |
| 48 | |
| 49 | return dsi_get_dsidev_from_id(dsi_module); |
| 50 | } |
| 51 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 52 | static bool dpi_use_dsi_pll(struct omap_dss_device *dssdev) |
| 53 | { |
| 54 | if (dssdev->clocks.dispc.dispc_fclk_src == |
| 55 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC || |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 56 | dssdev->clocks.dispc.dispc_fclk_src == |
| 57 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC || |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 58 | dssdev->clocks.dispc.channel.lcd_clk_src == |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 59 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC || |
| 60 | dssdev->clocks.dispc.channel.lcd_clk_src == |
| 61 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC) |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 62 | return true; |
| 63 | else |
| 64 | return false; |
| 65 | } |
| 66 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 67 | static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft, |
| 68 | unsigned long pck_req, unsigned long *fck, int *lck_div, |
| 69 | int *pck_div) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 70 | { |
| 71 | struct dsi_clock_info dsi_cinfo; |
| 72 | struct dispc_clock_info dispc_cinfo; |
| 73 | int r; |
| 74 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 75 | r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, pck_req, |
| 76 | &dsi_cinfo, &dispc_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 77 | if (r) |
| 78 | return r; |
| 79 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 80 | r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 81 | if (r) |
| 82 | return r; |
| 83 | |
Archit Taneja | e888166 | 2011-04-12 13:52:24 +0530 | [diff] [blame] | 84 | dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 85 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 86 | r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo); |
Tomi Valkeinen | 5e78509 | 2011-08-10 11:25:36 +0300 | [diff] [blame] | 87 | if (r) { |
| 88 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 89 | return r; |
Tomi Valkeinen | 5e78509 | 2011-08-10 11:25:36 +0300 | [diff] [blame] | 90 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 91 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 92 | *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 93 | *lck_div = dispc_cinfo.lck_div; |
| 94 | *pck_div = dispc_cinfo.pck_div; |
| 95 | |
| 96 | return 0; |
| 97 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 98 | |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 99 | static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft, |
| 100 | unsigned long pck_req, unsigned long *fck, int *lck_div, |
| 101 | int *pck_div) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 102 | { |
| 103 | struct dss_clock_info dss_cinfo; |
| 104 | struct dispc_clock_info dispc_cinfo; |
| 105 | int r; |
| 106 | |
| 107 | r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo); |
| 108 | if (r) |
| 109 | return r; |
| 110 | |
| 111 | r = dss_set_clock_div(&dss_cinfo); |
| 112 | if (r) |
| 113 | return r; |
| 114 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 115 | r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 116 | if (r) |
| 117 | return r; |
| 118 | |
| 119 | *fck = dss_cinfo.fck; |
| 120 | *lck_div = dispc_cinfo.lck_div; |
| 121 | *pck_div = dispc_cinfo.pck_div; |
| 122 | |
| 123 | return 0; |
| 124 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 125 | |
| 126 | static int dpi_set_mode(struct omap_dss_device *dssdev) |
| 127 | { |
| 128 | struct omap_video_timings *t = &dssdev->panel.timings; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 129 | int lck_div = 0, pck_div = 0; |
| 130 | unsigned long fck = 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 131 | unsigned long pck; |
| 132 | bool is_tft; |
| 133 | int r = 0; |
| 134 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 135 | dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 136 | dssdev->panel.acbi, dssdev->panel.acb); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 137 | |
| 138 | is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; |
| 139 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 140 | if (dpi_use_dsi_pll(dssdev)) |
| 141 | r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000, |
| 142 | &fck, &lck_div, &pck_div); |
| 143 | else |
| 144 | r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000, |
| 145 | &fck, &lck_div, &pck_div); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 146 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 147 | return r; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 148 | |
| 149 | pck = fck / lck_div / pck_div / 1000; |
| 150 | |
| 151 | if (pck != t->pixel_clock) { |
| 152 | DSSWARN("Could not find exact pixel clock. " |
| 153 | "Requested %d kHz, got %lu kHz\n", |
| 154 | t->pixel_clock, pck); |
| 155 | |
| 156 | t->pixel_clock = pck; |
| 157 | } |
| 158 | |
Archit Taneja | 4172116 | 2012-04-26 20:10:46 +0530 | [diff] [blame] | 159 | dss_mgr_set_timings(dssdev->manager, t); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 160 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 161 | return 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 162 | } |
| 163 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 164 | static void dpi_basic_init(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 165 | { |
| 166 | bool is_tft; |
| 167 | |
| 168 | is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; |
| 169 | |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 170 | dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS); |
| 171 | dispc_mgr_enable_stallmode(dssdev->manager->id, false); |
| 172 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 173 | dispc_mgr_set_lcd_display_type(dssdev->manager->id, is_tft ? |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 174 | OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN); |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 175 | dispc_mgr_set_tft_data_lines(dssdev->manager->id, |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 176 | dssdev->phy.dpi.data_lines); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 177 | } |
| 178 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 179 | int omapdss_dpi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 180 | { |
| 181 | int r; |
| 182 | |
Russell King | 4041071 | 2012-02-07 09:44:55 +0000 | [diff] [blame] | 183 | if (cpu_is_omap34xx() && !dpi.vdds_dsi_reg) { |
| 184 | DSSERR("no VDSS_DSI regulator\n"); |
| 185 | return -ENODEV; |
| 186 | } |
| 187 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 188 | if (dssdev->manager == NULL) { |
| 189 | DSSERR("failed to enable display: no manager\n"); |
| 190 | return -ENODEV; |
| 191 | } |
| 192 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 193 | r = omap_dss_start_device(dssdev); |
| 194 | if (r) { |
| 195 | DSSERR("failed to start device\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 196 | goto err_start_dev; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 197 | } |
| 198 | |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 199 | if (cpu_is_omap34xx()) { |
| 200 | r = regulator_enable(dpi.vdds_dsi_reg); |
| 201 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 202 | goto err_reg_enable; |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 205 | r = dispc_runtime_get(); |
| 206 | if (r) |
| 207 | goto err_get_dispc; |
| 208 | |
| 209 | dpi_basic_init(dssdev); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 210 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 211 | if (dpi_use_dsi_pll(dssdev)) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 212 | r = dsi_runtime_get(dpi.dsidev); |
| 213 | if (r) |
| 214 | goto err_get_dsi; |
| 215 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 216 | r = dsi_pll_init(dpi.dsidev, 0, 1); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 217 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 218 | goto err_dsi_pll_init; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 219 | } |
| 220 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 221 | r = dpi_set_mode(dssdev); |
| 222 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 223 | goto err_set_mode; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 224 | |
| 225 | mdelay(2); |
| 226 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 227 | r = dss_mgr_enable(dssdev->manager); |
| 228 | if (r) |
| 229 | goto err_mgr_enable; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 230 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 231 | return 0; |
| 232 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 233 | err_mgr_enable: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 234 | err_set_mode: |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 235 | if (dpi_use_dsi_pll(dssdev)) |
Tomi Valkeinen | 19077a7 | 2011-05-18 11:33:44 +0300 | [diff] [blame] | 236 | dsi_pll_uninit(dpi.dsidev, true); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 237 | err_dsi_pll_init: |
| 238 | if (dpi_use_dsi_pll(dssdev)) |
| 239 | dsi_runtime_put(dpi.dsidev); |
| 240 | err_get_dsi: |
| 241 | dispc_runtime_put(); |
| 242 | err_get_dispc: |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 243 | if (cpu_is_omap34xx()) |
| 244 | regulator_disable(dpi.vdds_dsi_reg); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 245 | err_reg_enable: |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 246 | omap_dss_stop_device(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 247 | err_start_dev: |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 248 | return r; |
| 249 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 250 | EXPORT_SYMBOL(omapdss_dpi_display_enable); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 251 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 252 | void omapdss_dpi_display_disable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 253 | { |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 254 | dss_mgr_disable(dssdev->manager); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 255 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 256 | if (dpi_use_dsi_pll(dssdev)) { |
| 257 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 258 | dsi_pll_uninit(dpi.dsidev, true); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 259 | dsi_runtime_put(dpi.dsidev); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 260 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 261 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 262 | dispc_runtime_put(); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 263 | |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 264 | if (cpu_is_omap34xx()) |
| 265 | regulator_disable(dpi.vdds_dsi_reg); |
| 266 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 267 | omap_dss_stop_device(dssdev); |
| 268 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 269 | EXPORT_SYMBOL(omapdss_dpi_display_disable); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 270 | |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 271 | void dpi_set_timings(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 272 | struct omap_video_timings *timings) |
| 273 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 274 | int r; |
| 275 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 276 | DSSDBG("dpi_set_timings\n"); |
| 277 | dssdev->panel.timings = *timings; |
| 278 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 279 | r = dispc_runtime_get(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 280 | if (r) |
| 281 | return; |
| 282 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 283 | dpi_set_mode(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 284 | |
| 285 | dispc_runtime_put(); |
Archit Taneja | fcc3661 | 2012-05-03 20:03:11 +0530 | [diff] [blame] | 286 | } else { |
| 287 | dss_mgr_set_timings(dssdev->manager, timings); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 288 | } |
| 289 | } |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 290 | EXPORT_SYMBOL(dpi_set_timings); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 291 | |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 292 | int dpi_check_timings(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 293 | struct omap_video_timings *timings) |
| 294 | { |
| 295 | bool is_tft; |
| 296 | int r; |
| 297 | int lck_div, pck_div; |
| 298 | unsigned long fck; |
| 299 | unsigned long pck; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 300 | struct dispc_clock_info dispc_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 301 | |
Archit Taneja | b917fa3 | 2012-04-27 01:07:28 +0530 | [diff] [blame] | 302 | if (dss_mgr_check_timings(dssdev->manager, timings)) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 303 | return -EINVAL; |
| 304 | |
| 305 | if (timings->pixel_clock == 0) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0; |
| 309 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 310 | if (dpi_use_dsi_pll(dssdev)) { |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 311 | struct dsi_clock_info dsi_cinfo; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 312 | r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 313 | timings->pixel_clock * 1000, |
| 314 | &dsi_cinfo, &dispc_cinfo); |
| 315 | |
| 316 | if (r) |
| 317 | return r; |
| 318 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 319 | fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 320 | } else { |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 321 | struct dss_clock_info dss_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 322 | r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000, |
| 323 | &dss_cinfo, &dispc_cinfo); |
| 324 | |
| 325 | if (r) |
| 326 | return r; |
| 327 | |
| 328 | fck = dss_cinfo.fck; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 329 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 330 | |
| 331 | lck_div = dispc_cinfo.lck_div; |
| 332 | pck_div = dispc_cinfo.pck_div; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 333 | |
| 334 | pck = fck / lck_div / pck_div / 1000; |
| 335 | |
| 336 | timings->pixel_clock = pck; |
| 337 | |
| 338 | return 0; |
| 339 | } |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 340 | EXPORT_SYMBOL(dpi_check_timings); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 341 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 342 | int dpi_init_display(struct omap_dss_device *dssdev) |
| 343 | { |
| 344 | DSSDBG("init_display\n"); |
| 345 | |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 346 | if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) { |
| 347 | struct regulator *vdds_dsi; |
| 348 | |
| 349 | vdds_dsi = dss_get_vdds_dsi(); |
| 350 | |
| 351 | if (IS_ERR(vdds_dsi)) { |
| 352 | DSSERR("can't get VDDS_DSI regulator\n"); |
| 353 | return PTR_ERR(vdds_dsi); |
| 354 | } |
| 355 | |
| 356 | dpi.vdds_dsi_reg = vdds_dsi; |
| 357 | } |
| 358 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 359 | if (dpi_use_dsi_pll(dssdev)) { |
| 360 | enum omap_dss_clk_source dispc_fclk_src = |
| 361 | dssdev->clocks.dispc.dispc_fclk_src; |
| 362 | dpi.dsidev = dpi_get_dsidev(dispc_fclk_src); |
| 363 | } |
| 364 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame^] | 368 | static int __init omap_dpi_probe(struct platform_device *pdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 369 | { |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame^] | 373 | static int __exit omap_dpi_remove(struct platform_device *pdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 374 | { |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 375 | return 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 376 | } |
| 377 | |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 378 | static struct platform_driver omap_dpi_driver = { |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame^] | 379 | .remove = __exit_p(omap_dpi_remove), |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 380 | .driver = { |
| 381 | .name = "omapdss_dpi", |
| 382 | .owner = THIS_MODULE, |
| 383 | }, |
| 384 | }; |
| 385 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame^] | 386 | int __init dpi_init_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 387 | { |
Tomi Valkeinen | 61055d4 | 2012-03-07 12:53:38 +0200 | [diff] [blame] | 388 | return platform_driver_probe(&omap_dpi_driver, omap_dpi_probe); |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame^] | 391 | void __exit dpi_uninit_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 392 | { |
| 393 | platform_driver_unregister(&omap_dpi_driver); |
| 394 | } |