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; |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 41 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 42 | struct mutex lock; |
| 43 | |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 44 | struct omap_video_timings timings; |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 45 | struct dss_lcd_mgr_config mgr_config; |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame^] | 46 | int data_lines; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 47 | } dpi; |
| 48 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 49 | static struct platform_device *dpi_get_dsidev(enum omap_dss_clk_source clk) |
| 50 | { |
| 51 | int dsi_module; |
| 52 | |
| 53 | dsi_module = clk == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ? 0 : 1; |
| 54 | |
| 55 | return dsi_get_dsidev_from_id(dsi_module); |
| 56 | } |
| 57 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 58 | static bool dpi_use_dsi_pll(struct omap_dss_device *dssdev) |
| 59 | { |
| 60 | if (dssdev->clocks.dispc.dispc_fclk_src == |
| 61 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC || |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 62 | dssdev->clocks.dispc.dispc_fclk_src == |
| 63 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC || |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 64 | dssdev->clocks.dispc.channel.lcd_clk_src == |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 65 | OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC || |
| 66 | dssdev->clocks.dispc.channel.lcd_clk_src == |
| 67 | OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC) |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 68 | return true; |
| 69 | else |
| 70 | return false; |
| 71 | } |
| 72 | |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 73 | static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 74 | unsigned long pck_req, unsigned long *fck, int *lck_div, |
| 75 | int *pck_div) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 76 | { |
| 77 | struct dsi_clock_info dsi_cinfo; |
| 78 | struct dispc_clock_info dispc_cinfo; |
| 79 | int r; |
| 80 | |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 81 | r = dsi_pll_calc_clock_div_pck(dpi.dsidev, pck_req, &dsi_cinfo, |
| 82 | &dispc_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 83 | if (r) |
| 84 | return r; |
| 85 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 86 | r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 87 | if (r) |
| 88 | return r; |
| 89 | |
Archit Taneja | e888166 | 2011-04-12 13:52:24 +0530 | [diff] [blame] | 90 | dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 91 | |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 92 | dpi.mgr_config.clock_info = dispc_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 93 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 94 | *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 95 | *lck_div = dispc_cinfo.lck_div; |
| 96 | *pck_div = dispc_cinfo.pck_div; |
| 97 | |
| 98 | return 0; |
| 99 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 100 | |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 101 | static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 102 | unsigned long pck_req, unsigned long *fck, int *lck_div, |
| 103 | int *pck_div) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 104 | { |
| 105 | struct dss_clock_info dss_cinfo; |
| 106 | struct dispc_clock_info dispc_cinfo; |
| 107 | int r; |
| 108 | |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 109 | r = dss_calc_clock_div(pck_req, &dss_cinfo, &dispc_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 110 | if (r) |
| 111 | return r; |
| 112 | |
| 113 | r = dss_set_clock_div(&dss_cinfo); |
| 114 | if (r) |
| 115 | return r; |
| 116 | |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 117 | dpi.mgr_config.clock_info = dispc_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 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 | { |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 128 | struct omap_video_timings *t = &dpi.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; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 132 | int r = 0; |
| 133 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 134 | if (dpi_use_dsi_pll(dssdev)) |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 135 | r = dpi_set_dsi_clk(dssdev, t->pixel_clock * 1000, &fck, |
| 136 | &lck_div, &pck_div); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 137 | else |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 138 | r = dpi_set_dispc_clk(dssdev, t->pixel_clock * 1000, &fck, |
| 139 | &lck_div, &pck_div); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 140 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 141 | return r; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 142 | |
| 143 | pck = fck / lck_div / pck_div / 1000; |
| 144 | |
| 145 | if (pck != t->pixel_clock) { |
| 146 | DSSWARN("Could not find exact pixel clock. " |
| 147 | "Requested %d kHz, got %lu kHz\n", |
| 148 | t->pixel_clock, pck); |
| 149 | |
| 150 | t->pixel_clock = pck; |
| 151 | } |
| 152 | |
Archit Taneja | 4172116 | 2012-04-26 20:10:46 +0530 | [diff] [blame] | 153 | dss_mgr_set_timings(dssdev->manager, t); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 154 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 155 | return 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 156 | } |
| 157 | |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 158 | static void dpi_config_lcd_manager(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 159 | { |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 160 | dpi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 161 | |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 162 | dpi.mgr_config.stallmode = false; |
| 163 | dpi.mgr_config.fifohandcheck = false; |
| 164 | |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame^] | 165 | dpi.mgr_config.video_port_width = dpi.data_lines; |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 166 | |
| 167 | dpi.mgr_config.lcden_sig_polarity = 0; |
| 168 | |
Archit Taneja | f476ae9 | 2012-06-29 14:37:03 +0530 | [diff] [blame] | 169 | dss_mgr_set_lcd_config(dssdev->manager, &dpi.mgr_config); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 170 | } |
| 171 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 172 | int omapdss_dpi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 173 | { |
| 174 | int r; |
| 175 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 176 | mutex_lock(&dpi.lock); |
| 177 | |
Russell King | 4041071 | 2012-02-07 09:44:55 +0000 | [diff] [blame] | 178 | if (cpu_is_omap34xx() && !dpi.vdds_dsi_reg) { |
| 179 | DSSERR("no VDSS_DSI regulator\n"); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 180 | r = -ENODEV; |
| 181 | goto err_no_reg; |
Russell King | 4041071 | 2012-02-07 09:44:55 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 184 | if (dssdev->manager == NULL) { |
| 185 | DSSERR("failed to enable display: no manager\n"); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 186 | r = -ENODEV; |
| 187 | goto err_no_mgr; |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 188 | } |
| 189 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 190 | r = omap_dss_start_device(dssdev); |
| 191 | if (r) { |
| 192 | DSSERR("failed to start device\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 193 | goto err_start_dev; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 194 | } |
| 195 | |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 196 | if (cpu_is_omap34xx()) { |
| 197 | r = regulator_enable(dpi.vdds_dsi_reg); |
| 198 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 199 | goto err_reg_enable; |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 202 | r = dispc_runtime_get(); |
| 203 | if (r) |
| 204 | goto err_get_dispc; |
| 205 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 206 | if (dpi_use_dsi_pll(dssdev)) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 207 | r = dsi_runtime_get(dpi.dsidev); |
| 208 | if (r) |
| 209 | goto err_get_dsi; |
| 210 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 211 | r = dsi_pll_init(dpi.dsidev, 0, 1); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 212 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 213 | goto err_dsi_pll_init; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 214 | } |
| 215 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 216 | r = dpi_set_mode(dssdev); |
| 217 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 218 | goto err_set_mode; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 219 | |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 220 | dpi_config_lcd_manager(dssdev); |
| 221 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 222 | mdelay(2); |
| 223 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 224 | r = dss_mgr_enable(dssdev->manager); |
| 225 | if (r) |
| 226 | goto err_mgr_enable; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 227 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 228 | mutex_unlock(&dpi.lock); |
| 229 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 230 | return 0; |
| 231 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 232 | err_mgr_enable: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 233 | err_set_mode: |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 234 | if (dpi_use_dsi_pll(dssdev)) |
Tomi Valkeinen | 19077a7 | 2011-05-18 11:33:44 +0300 | [diff] [blame] | 235 | dsi_pll_uninit(dpi.dsidev, true); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 236 | err_dsi_pll_init: |
| 237 | if (dpi_use_dsi_pll(dssdev)) |
| 238 | dsi_runtime_put(dpi.dsidev); |
| 239 | err_get_dsi: |
| 240 | dispc_runtime_put(); |
| 241 | err_get_dispc: |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 242 | if (cpu_is_omap34xx()) |
| 243 | regulator_disable(dpi.vdds_dsi_reg); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 244 | err_reg_enable: |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 245 | omap_dss_stop_device(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 246 | err_start_dev: |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 247 | err_no_mgr: |
| 248 | err_no_reg: |
| 249 | mutex_unlock(&dpi.lock); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 250 | return r; |
| 251 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 252 | EXPORT_SYMBOL(omapdss_dpi_display_enable); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 253 | |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 254 | void omapdss_dpi_display_disable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 255 | { |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 256 | mutex_lock(&dpi.lock); |
| 257 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 258 | dss_mgr_disable(dssdev->manager); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 259 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 260 | if (dpi_use_dsi_pll(dssdev)) { |
| 261 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 262 | dsi_pll_uninit(dpi.dsidev, true); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 263 | dsi_runtime_put(dpi.dsidev); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 264 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 265 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 266 | dispc_runtime_put(); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 267 | |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 268 | if (cpu_is_omap34xx()) |
| 269 | regulator_disable(dpi.vdds_dsi_reg); |
| 270 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 271 | omap_dss_stop_device(dssdev); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 272 | |
| 273 | mutex_unlock(&dpi.lock); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 274 | } |
Tomi Valkeinen | 37ac60e | 2010-01-12 15:12:07 +0200 | [diff] [blame] | 275 | EXPORT_SYMBOL(omapdss_dpi_display_disable); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 276 | |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 277 | void omapdss_dpi_set_timings(struct omap_dss_device *dssdev, |
| 278 | struct omap_video_timings *timings) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 279 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 280 | int r; |
| 281 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 282 | DSSDBG("dpi_set_timings\n"); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 283 | |
| 284 | mutex_lock(&dpi.lock); |
| 285 | |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 286 | dpi.timings = *timings; |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 287 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 288 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 289 | r = dispc_runtime_get(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 290 | if (r) |
| 291 | return; |
| 292 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 293 | dpi_set_mode(dssdev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 294 | |
| 295 | dispc_runtime_put(); |
Archit Taneja | fcc3661 | 2012-05-03 20:03:11 +0530 | [diff] [blame] | 296 | } else { |
| 297 | dss_mgr_set_timings(dssdev->manager, timings); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 298 | } |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 299 | |
| 300 | mutex_unlock(&dpi.lock); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 301 | } |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 302 | EXPORT_SYMBOL(omapdss_dpi_set_timings); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 303 | |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 304 | int dpi_check_timings(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 305 | struct omap_video_timings *timings) |
| 306 | { |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 307 | int r; |
| 308 | int lck_div, pck_div; |
| 309 | unsigned long fck; |
| 310 | unsigned long pck; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 311 | struct dispc_clock_info dispc_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 312 | |
Archit Taneja | b917fa3 | 2012-04-27 01:07:28 +0530 | [diff] [blame] | 313 | if (dss_mgr_check_timings(dssdev->manager, timings)) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 314 | return -EINVAL; |
| 315 | |
| 316 | if (timings->pixel_clock == 0) |
| 317 | return -EINVAL; |
| 318 | |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 319 | if (dpi_use_dsi_pll(dssdev)) { |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 320 | struct dsi_clock_info dsi_cinfo; |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 321 | r = dsi_pll_calc_clock_div_pck(dpi.dsidev, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 322 | timings->pixel_clock * 1000, |
| 323 | &dsi_cinfo, &dispc_cinfo); |
| 324 | |
| 325 | if (r) |
| 326 | return r; |
| 327 | |
Archit Taneja | 1bb4783 | 2011-02-24 14:17:30 +0530 | [diff] [blame] | 328 | fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 329 | } else { |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 330 | struct dss_clock_info dss_cinfo; |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 331 | r = dss_calc_clock_div(timings->pixel_clock * 1000, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 332 | &dss_cinfo, &dispc_cinfo); |
| 333 | |
| 334 | if (r) |
| 335 | return r; |
| 336 | |
| 337 | fck = dss_cinfo.fck; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 338 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 339 | |
| 340 | lck_div = dispc_cinfo.lck_div; |
| 341 | pck_div = dispc_cinfo.pck_div; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 342 | |
| 343 | pck = fck / lck_div / pck_div / 1000; |
| 344 | |
| 345 | timings->pixel_clock = pck; |
| 346 | |
| 347 | return 0; |
| 348 | } |
Tomi Valkeinen | 69b2048 | 2010-01-20 12:11:25 +0200 | [diff] [blame] | 349 | EXPORT_SYMBOL(dpi_check_timings); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 350 | |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame^] | 351 | void omapdss_dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines) |
| 352 | { |
| 353 | mutex_lock(&dpi.lock); |
| 354 | |
| 355 | dpi.data_lines = data_lines; |
| 356 | |
| 357 | mutex_unlock(&dpi.lock); |
| 358 | } |
| 359 | EXPORT_SYMBOL(omapdss_dpi_set_data_lines); |
| 360 | |
Tomi Valkeinen | 9d8232a | 2012-03-01 16:58:39 +0200 | [diff] [blame] | 361 | static int __init dpi_init_display(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 362 | { |
| 363 | DSSDBG("init_display\n"); |
| 364 | |
Tomi Valkeinen | 5f42f2ce | 2011-02-22 15:53:46 +0200 | [diff] [blame] | 365 | if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) { |
| 366 | struct regulator *vdds_dsi; |
| 367 | |
| 368 | vdds_dsi = dss_get_vdds_dsi(); |
| 369 | |
| 370 | if (IS_ERR(vdds_dsi)) { |
| 371 | DSSERR("can't get VDDS_DSI regulator\n"); |
| 372 | return PTR_ERR(vdds_dsi); |
| 373 | } |
| 374 | |
| 375 | dpi.vdds_dsi_reg = vdds_dsi; |
| 376 | } |
| 377 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 378 | if (dpi_use_dsi_pll(dssdev)) { |
| 379 | enum omap_dss_clk_source dispc_fclk_src = |
| 380 | dssdev->clocks.dispc.dispc_fclk_src; |
| 381 | dpi.dsidev = dpi_get_dsidev(dispc_fclk_src); |
| 382 | } |
| 383 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 387 | static void __init dpi_probe_pdata(struct platform_device *pdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 388 | { |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 389 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
| 390 | int i, r; |
| 391 | |
| 392 | for (i = 0; i < pdata->num_devices; ++i) { |
| 393 | struct omap_dss_device *dssdev = pdata->devices[i]; |
| 394 | |
| 395 | if (dssdev->type != OMAP_DISPLAY_TYPE_DPI) |
| 396 | continue; |
| 397 | |
Tomi Valkeinen | 9d8232a | 2012-03-01 16:58:39 +0200 | [diff] [blame] | 398 | r = dpi_init_display(dssdev); |
| 399 | if (r) { |
| 400 | DSSERR("device %s init failed: %d\n", dssdev->name, r); |
| 401 | continue; |
| 402 | } |
| 403 | |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 404 | r = omap_dss_register_device(dssdev, &pdev->dev, i); |
| 405 | if (r) |
| 406 | DSSERR("device %s register failed: %d\n", |
| 407 | dssdev->name, r); |
| 408 | } |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static int __init omap_dpi_probe(struct platform_device *pdev) |
| 412 | { |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 413 | mutex_init(&dpi.lock); |
| 414 | |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 415 | dpi_probe_pdata(pdev); |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 416 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 420 | static int __exit omap_dpi_remove(struct platform_device *pdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 421 | { |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 422 | omap_dss_unregister_child_devices(&pdev->dev); |
| 423 | |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 424 | return 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 425 | } |
| 426 | |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 427 | static struct platform_driver omap_dpi_driver = { |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 428 | .remove = __exit_p(omap_dpi_remove), |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 429 | .driver = { |
| 430 | .name = "omapdss_dpi", |
| 431 | .owner = THIS_MODULE, |
| 432 | }, |
| 433 | }; |
| 434 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 435 | int __init dpi_init_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 436 | { |
Tomi Valkeinen | 61055d4 | 2012-03-07 12:53:38 +0200 | [diff] [blame] | 437 | return platform_driver_probe(&omap_dpi_driver, omap_dpi_probe); |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 440 | void __exit dpi_uninit_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 441 | { |
| 442 | platform_driver_unregister(&omap_dpi_driver); |
| 443 | } |