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 | 13b1ba7 | 2012-09-28 10:03:03 +0300 | [diff] [blame] | 32 | #include <linux/string.h> |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 33 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 34 | #include <video/omapdss.h> |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 35 | |
| 36 | #include "dss.h" |
Chandrabhanu Mahapatra | 195e672 | 2012-08-22 11:44:06 +0530 | [diff] [blame] | 37 | #include "dss_features.h" |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 38 | |
| 39 | static struct { |
Tomi Valkeinen | 00df43b | 2013-03-19 11:33:52 +0200 | [diff] [blame] | 40 | struct platform_device *pdev; |
| 41 | |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 42 | struct regulator *vdds_dsi_reg; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 43 | struct platform_device *dsidev; |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 44 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 45 | struct mutex lock; |
| 46 | |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 47 | struct omap_video_timings timings; |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 48 | struct dss_lcd_mgr_config mgr_config; |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame] | 49 | int data_lines; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 50 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 51 | struct omap_dss_device output; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 52 | } dpi; |
| 53 | |
Tomi Valkeinen | 0e8276e | 2012-10-22 16:12:58 +0300 | [diff] [blame] | 54 | static struct platform_device *dpi_get_dsidev(enum omap_channel channel) |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 55 | { |
Tomi Valkeinen | bd0f5cc | 2012-12-13 14:21:30 +0200 | [diff] [blame] | 56 | /* |
| 57 | * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL |
| 58 | * would also be used for DISPC fclk. Meaning, when the DPI output is |
| 59 | * disabled, DISPC clock will be disabled, and TV out will stop. |
| 60 | */ |
| 61 | switch (omapdss_get_version()) { |
| 62 | case OMAPDSS_VER_OMAP24xx: |
| 63 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 64 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 65 | case OMAPDSS_VER_OMAP3630: |
| 66 | case OMAPDSS_VER_AM35xx: |
| 67 | return NULL; |
Tomi Valkeinen | bd0f5cc | 2012-12-13 14:21:30 +0200 | [diff] [blame] | 68 | |
Tomi Valkeinen | f8ad984 | 2013-03-11 13:57:38 +0200 | [diff] [blame] | 69 | case OMAPDSS_VER_OMAP4430_ES1: |
| 70 | case OMAPDSS_VER_OMAP4430_ES2: |
| 71 | case OMAPDSS_VER_OMAP4: |
| 72 | switch (channel) { |
| 73 | case OMAP_DSS_CHANNEL_LCD: |
| 74 | return dsi_get_dsidev_from_id(0); |
| 75 | case OMAP_DSS_CHANNEL_LCD2: |
| 76 | return dsi_get_dsidev_from_id(1); |
| 77 | default: |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | case OMAPDSS_VER_OMAP5: |
| 82 | switch (channel) { |
| 83 | case OMAP_DSS_CHANNEL_LCD: |
| 84 | return dsi_get_dsidev_from_id(0); |
| 85 | case OMAP_DSS_CHANNEL_LCD3: |
| 86 | return dsi_get_dsidev_from_id(1); |
| 87 | default: |
| 88 | return NULL; |
| 89 | } |
| 90 | |
Tomi Valkeinen | 0e8276e | 2012-10-22 16:12:58 +0300 | [diff] [blame] | 91 | default: |
| 92 | return NULL; |
| 93 | } |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 94 | } |
| 95 | |
Tomi Valkeinen | 0e8276e | 2012-10-22 16:12:58 +0300 | [diff] [blame] | 96 | static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel) |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 97 | { |
Tomi Valkeinen | 0e8276e | 2012-10-22 16:12:58 +0300 | [diff] [blame] | 98 | switch (channel) { |
| 99 | case OMAP_DSS_CHANNEL_LCD: |
| 100 | return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC; |
| 101 | case OMAP_DSS_CHANNEL_LCD2: |
| 102 | return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC; |
| 103 | default: |
| 104 | /* this shouldn't happen */ |
| 105 | WARN_ON(1); |
| 106 | return OMAP_DSS_CLK_SRC_FCK; |
| 107 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 108 | } |
| 109 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 110 | struct dpi_clk_calc_ctx { |
| 111 | struct platform_device *dsidev; |
| 112 | |
| 113 | /* inputs */ |
| 114 | |
| 115 | unsigned long pck_min, pck_max; |
| 116 | |
| 117 | /* outputs */ |
| 118 | |
| 119 | struct dsi_clock_info dsi_cinfo; |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 120 | unsigned long long fck; |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 121 | struct dispc_clock_info dispc_cinfo; |
| 122 | }; |
| 123 | |
| 124 | static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck, |
| 125 | unsigned long pck, void *data) |
| 126 | { |
| 127 | struct dpi_clk_calc_ctx *ctx = data; |
| 128 | |
| 129 | /* |
| 130 | * Odd dividers give us uneven duty cycle, causing problem when level |
| 131 | * shifted. So skip all odd dividers when the pixel clock is on the |
| 132 | * higher side. |
| 133 | */ |
Tomi Valkeinen | 72e5512 | 2013-06-12 09:44:52 +0300 | [diff] [blame] | 134 | if (ctx->pck_min >= 100000000) { |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 135 | if (lckd > 1 && lckd % 2 != 0) |
| 136 | return false; |
| 137 | |
| 138 | if (pckd > 1 && pckd % 2 != 0) |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | ctx->dispc_cinfo.lck_div = lckd; |
| 143 | ctx->dispc_cinfo.pck_div = pckd; |
| 144 | ctx->dispc_cinfo.lck = lck; |
| 145 | ctx->dispc_cinfo.pck = pck; |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | static bool dpi_calc_hsdiv_cb(int regm_dispc, unsigned long dispc, |
| 152 | void *data) |
| 153 | { |
| 154 | struct dpi_clk_calc_ctx *ctx = data; |
| 155 | |
| 156 | /* |
| 157 | * Odd dividers give us uneven duty cycle, causing problem when level |
| 158 | * shifted. So skip all odd dividers when the pixel clock is on the |
| 159 | * higher side. |
| 160 | */ |
Tomi Valkeinen | 72e5512 | 2013-06-12 09:44:52 +0300 | [diff] [blame] | 161 | if (regm_dispc > 1 && regm_dispc % 2 != 0 && ctx->pck_min >= 100000000) |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 162 | return false; |
| 163 | |
| 164 | ctx->dsi_cinfo.regm_dispc = regm_dispc; |
| 165 | ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc; |
| 166 | |
| 167 | return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max, |
| 168 | dpi_calc_dispc_cb, ctx); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | static bool dpi_calc_pll_cb(int regn, int regm, unsigned long fint, |
| 173 | unsigned long pll, |
| 174 | void *data) |
| 175 | { |
| 176 | struct dpi_clk_calc_ctx *ctx = data; |
| 177 | |
| 178 | ctx->dsi_cinfo.regn = regn; |
| 179 | ctx->dsi_cinfo.regm = regm; |
| 180 | ctx->dsi_cinfo.fint = fint; |
| 181 | ctx->dsi_cinfo.clkin4ddr = pll; |
| 182 | |
| 183 | return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->pck_min, |
| 184 | dpi_calc_hsdiv_cb, ctx); |
| 185 | } |
| 186 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 187 | static bool dpi_calc_dss_cb(unsigned long fck, void *data) |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 188 | { |
| 189 | struct dpi_clk_calc_ctx *ctx = data; |
| 190 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 191 | ctx->fck = fck; |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 192 | |
| 193 | return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max, |
| 194 | dpi_calc_dispc_cb, ctx); |
| 195 | } |
| 196 | |
| 197 | static bool dpi_dsi_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx) |
| 198 | { |
| 199 | unsigned long clkin; |
| 200 | unsigned long pll_min, pll_max; |
| 201 | |
| 202 | clkin = dsi_get_pll_clkin(dpi.dsidev); |
| 203 | |
| 204 | memset(ctx, 0, sizeof(*ctx)); |
| 205 | ctx->dsidev = dpi.dsidev; |
| 206 | ctx->pck_min = pck - 1000; |
| 207 | ctx->pck_max = pck + 1000; |
| 208 | ctx->dsi_cinfo.clkin = clkin; |
| 209 | |
| 210 | pll_min = 0; |
| 211 | pll_max = 0; |
| 212 | |
| 213 | return dsi_pll_calc(dpi.dsidev, clkin, |
| 214 | pll_min, pll_max, |
| 215 | dpi_calc_pll_cb, ctx); |
| 216 | } |
| 217 | |
| 218 | static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx) |
| 219 | { |
| 220 | int i; |
| 221 | |
| 222 | /* |
| 223 | * DSS fck gives us very few possibilities, so finding a good pixel |
| 224 | * clock may not be possible. We try multiple times to find the clock, |
| 225 | * each time widening the pixel clock range we look for, up to |
Tomi Valkeinen | 2c6360f | 2013-04-10 14:54:54 +0300 | [diff] [blame] | 226 | * +/- ~15MHz. |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 227 | */ |
| 228 | |
Tomi Valkeinen | 2c6360f | 2013-04-10 14:54:54 +0300 | [diff] [blame] | 229 | for (i = 0; i < 25; ++i) { |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 230 | bool ok; |
| 231 | |
| 232 | memset(ctx, 0, sizeof(*ctx)); |
| 233 | if (pck > 1000 * i * i * i) |
| 234 | ctx->pck_min = max(pck - 1000 * i * i * i, 0lu); |
| 235 | else |
| 236 | ctx->pck_min = 0; |
| 237 | ctx->pck_max = pck + 1000 * i * i * i; |
| 238 | |
Tomi Valkeinen | 688af02 | 2013-10-31 16:41:57 +0200 | [diff] [blame] | 239 | ok = dss_div_calc(pck, ctx->pck_min, dpi_calc_dss_cb, ctx); |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 240 | if (ok) |
| 241 | return ok; |
| 242 | } |
| 243 | |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 249 | static int dpi_set_dsi_clk(enum omap_channel channel, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 250 | unsigned long pck_req, unsigned long *fck, int *lck_div, |
| 251 | int *pck_div) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 252 | { |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 253 | struct dpi_clk_calc_ctx ctx; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 254 | int r; |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 255 | bool ok; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 256 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 257 | ok = dpi_dsi_clk_calc(pck_req, &ctx); |
| 258 | if (!ok) |
| 259 | return -EINVAL; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 260 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 261 | r = dsi_pll_set_clock_div(dpi.dsidev, &ctx.dsi_cinfo); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 262 | if (r) |
| 263 | return r; |
| 264 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 265 | dss_select_lcd_clk_source(channel, |
| 266 | dpi_get_alt_clk_src(channel)); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 267 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 268 | dpi.mgr_config.clock_info = ctx.dispc_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 269 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 270 | *fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
| 271 | *lck_div = ctx.dispc_cinfo.lck_div; |
| 272 | *pck_div = ctx.dispc_cinfo.pck_div; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 276 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 277 | static int dpi_set_dispc_clk(unsigned long pck_req, unsigned long *fck, |
| 278 | int *lck_div, int *pck_div) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 279 | { |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 280 | struct dpi_clk_calc_ctx ctx; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 281 | int r; |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 282 | bool ok; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 283 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 284 | ok = dpi_dss_clk_calc(pck_req, &ctx); |
| 285 | if (!ok) |
| 286 | return -EINVAL; |
| 287 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 288 | r = dss_set_fck_rate(ctx.fck); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 289 | if (r) |
| 290 | return r; |
| 291 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 292 | dpi.mgr_config.clock_info = ctx.dispc_cinfo; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 293 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 294 | *fck = ctx.fck; |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 295 | *lck_div = ctx.dispc_cinfo.lck_div; |
| 296 | *pck_div = ctx.dispc_cinfo.pck_div; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 300 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 301 | static int dpi_set_mode(struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 302 | { |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 303 | struct omap_video_timings *t = &dpi.timings; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 304 | int lck_div = 0, pck_div = 0; |
| 305 | unsigned long fck = 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 306 | unsigned long pck; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 307 | int r = 0; |
| 308 | |
Tomi Valkeinen | 8a3db40 | 2012-10-22 16:03:39 +0300 | [diff] [blame] | 309 | if (dpi.dsidev) |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 310 | r = dpi_set_dsi_clk(mgr->id, t->pixel_clock * 1000, &fck, |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 311 | &lck_div, &pck_div); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 312 | else |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 313 | r = dpi_set_dispc_clk(t->pixel_clock * 1000, &fck, |
Archit Taneja | 6d523e7 | 2012-06-21 09:33:55 +0530 | [diff] [blame] | 314 | &lck_div, &pck_div); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 315 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 316 | return r; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 317 | |
| 318 | pck = fck / lck_div / pck_div / 1000; |
| 319 | |
| 320 | if (pck != t->pixel_clock) { |
| 321 | DSSWARN("Could not find exact pixel clock. " |
| 322 | "Requested %d kHz, got %lu kHz\n", |
| 323 | t->pixel_clock, pck); |
| 324 | |
| 325 | t->pixel_clock = pck; |
| 326 | } |
| 327 | |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 328 | dss_mgr_set_timings(mgr, t); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 329 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 330 | return 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 331 | } |
| 332 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 333 | static void dpi_config_lcd_manager(struct omap_overlay_manager *mgr) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 334 | { |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 335 | dpi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS; |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 336 | |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 337 | dpi.mgr_config.stallmode = false; |
| 338 | dpi.mgr_config.fifohandcheck = false; |
| 339 | |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame] | 340 | dpi.mgr_config.video_port_width = dpi.data_lines; |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 341 | |
| 342 | dpi.mgr_config.lcden_sig_polarity = 0; |
| 343 | |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 344 | dss_mgr_set_lcd_config(mgr, &dpi.mgr_config); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 345 | } |
| 346 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 347 | static int dpi_display_enable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 348 | { |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 349 | struct omap_dss_device *out = &dpi.output; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 350 | int r; |
| 351 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 352 | mutex_lock(&dpi.lock); |
| 353 | |
Chandrabhanu Mahapatra | 195e672 | 2012-08-22 11:44:06 +0530 | [diff] [blame] | 354 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi.vdds_dsi_reg) { |
Russell King | 4041071 | 2012-02-07 09:44:55 +0000 | [diff] [blame] | 355 | DSSERR("no VDSS_DSI regulator\n"); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 356 | r = -ENODEV; |
| 357 | goto err_no_reg; |
Russell King | 4041071 | 2012-02-07 09:44:55 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 360 | if (out == NULL || out->manager == NULL) { |
| 361 | DSSERR("failed to enable display: no output/manager\n"); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 362 | r = -ENODEV; |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 363 | goto err_no_out_mgr; |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 364 | } |
| 365 | |
Chandrabhanu Mahapatra | 195e672 | 2012-08-22 11:44:06 +0530 | [diff] [blame] | 366 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) { |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 367 | r = regulator_enable(dpi.vdds_dsi_reg); |
| 368 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 369 | goto err_reg_enable; |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 372 | r = dispc_runtime_get(); |
| 373 | if (r) |
| 374 | goto err_get_dispc; |
| 375 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 376 | r = dss_dpi_select_source(out->manager->id); |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 377 | if (r) |
| 378 | goto err_src_sel; |
| 379 | |
Tomi Valkeinen | 8a3db40 | 2012-10-22 16:03:39 +0300 | [diff] [blame] | 380 | if (dpi.dsidev) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 381 | r = dsi_runtime_get(dpi.dsidev); |
| 382 | if (r) |
| 383 | goto err_get_dsi; |
| 384 | |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 385 | r = dsi_pll_init(dpi.dsidev, 0, 1); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 386 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 387 | goto err_dsi_pll_init; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 388 | } |
| 389 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 390 | r = dpi_set_mode(out->manager); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 391 | if (r) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 392 | goto err_set_mode; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 393 | |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 394 | dpi_config_lcd_manager(out->manager); |
Archit Taneja | 5cf9a26 | 2012-06-29 14:19:13 +0530 | [diff] [blame] | 395 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 396 | mdelay(2); |
| 397 | |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 398 | r = dss_mgr_enable(out->manager); |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 399 | if (r) |
| 400 | goto err_mgr_enable; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 401 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 402 | mutex_unlock(&dpi.lock); |
| 403 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 404 | return 0; |
| 405 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 406 | err_mgr_enable: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 407 | err_set_mode: |
Tomi Valkeinen | 8a3db40 | 2012-10-22 16:03:39 +0300 | [diff] [blame] | 408 | if (dpi.dsidev) |
Tomi Valkeinen | 19077a7 | 2011-05-18 11:33:44 +0300 | [diff] [blame] | 409 | dsi_pll_uninit(dpi.dsidev, true); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 410 | err_dsi_pll_init: |
Tomi Valkeinen | 8a3db40 | 2012-10-22 16:03:39 +0300 | [diff] [blame] | 411 | if (dpi.dsidev) |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 412 | dsi_runtime_put(dpi.dsidev); |
| 413 | err_get_dsi: |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 414 | err_src_sel: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 415 | dispc_runtime_put(); |
| 416 | err_get_dispc: |
Chandrabhanu Mahapatra | 195e672 | 2012-08-22 11:44:06 +0530 | [diff] [blame] | 417 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 418 | regulator_disable(dpi.vdds_dsi_reg); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 419 | err_reg_enable: |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 420 | err_no_out_mgr: |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 421 | err_no_reg: |
| 422 | mutex_unlock(&dpi.lock); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 423 | return r; |
| 424 | } |
| 425 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 426 | static void dpi_display_disable(struct omap_dss_device *dssdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 427 | { |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 428 | struct omap_overlay_manager *mgr = dpi.output.manager; |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 429 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 430 | mutex_lock(&dpi.lock); |
| 431 | |
Archit Taneja | 5d512fc | 2012-09-07 17:53:38 +0530 | [diff] [blame] | 432 | dss_mgr_disable(mgr); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 433 | |
Tomi Valkeinen | 8a3db40 | 2012-10-22 16:03:39 +0300 | [diff] [blame] | 434 | if (dpi.dsidev) { |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 435 | dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK); |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 436 | dsi_pll_uninit(dpi.dsidev, true); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 437 | dsi_runtime_put(dpi.dsidev); |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 438 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 439 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 440 | dispc_runtime_put(); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 441 | |
Chandrabhanu Mahapatra | 195e672 | 2012-08-22 11:44:06 +0530 | [diff] [blame] | 442 | if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) |
Tomi Valkeinen | 8a2cfea | 2010-02-04 17:03:41 +0200 | [diff] [blame] | 443 | regulator_disable(dpi.vdds_dsi_reg); |
| 444 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 445 | mutex_unlock(&dpi.lock); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 446 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 447 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 448 | static void dpi_set_timings(struct omap_dss_device *dssdev, |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 449 | struct omap_video_timings *timings) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 450 | { |
| 451 | DSSDBG("dpi_set_timings\n"); |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 452 | |
| 453 | mutex_lock(&dpi.lock); |
| 454 | |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 455 | dpi.timings = *timings; |
Archit Taneja | c499144 | 2012-08-08 14:28:54 +0530 | [diff] [blame] | 456 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 457 | mutex_unlock(&dpi.lock); |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 458 | } |
| 459 | |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 460 | static void dpi_get_timings(struct omap_dss_device *dssdev, |
| 461 | struct omap_video_timings *timings) |
| 462 | { |
| 463 | mutex_lock(&dpi.lock); |
| 464 | |
| 465 | *timings = dpi.timings; |
| 466 | |
| 467 | mutex_unlock(&dpi.lock); |
| 468 | } |
| 469 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 470 | static int dpi_check_timings(struct omap_dss_device *dssdev, |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 471 | struct omap_video_timings *timings) |
| 472 | { |
Tomi Valkeinen | 03a0d1e | 2012-11-27 16:41:16 +0200 | [diff] [blame] | 473 | struct omap_overlay_manager *mgr = dpi.output.manager; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 474 | int lck_div, pck_div; |
| 475 | unsigned long fck; |
| 476 | unsigned long pck; |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 477 | struct dpi_clk_calc_ctx ctx; |
| 478 | bool ok; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 479 | |
Tomi Valkeinen | 8b09551 | 2012-10-24 13:27:02 +0300 | [diff] [blame] | 480 | if (mgr && !dispc_mgr_timings_ok(mgr->id, timings)) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 481 | return -EINVAL; |
| 482 | |
| 483 | if (timings->pixel_clock == 0) |
| 484 | return -EINVAL; |
| 485 | |
Tomi Valkeinen | 8a3db40 | 2012-10-22 16:03:39 +0300 | [diff] [blame] | 486 | if (dpi.dsidev) { |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 487 | ok = dpi_dsi_clk_calc(timings->pixel_clock * 1000, &ctx); |
| 488 | if (!ok) |
| 489 | return -EINVAL; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 490 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 491 | fck = ctx.dsi_cinfo.dsi_pll_hsdiv_dispc_clk; |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 492 | } else { |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 493 | ok = dpi_dss_clk_calc(timings->pixel_clock * 1000, &ctx); |
| 494 | if (!ok) |
| 495 | return -EINVAL; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 496 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 497 | fck = ctx.fck; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 498 | } |
Archit Taneja | 7636b3b | 2011-04-12 13:52:26 +0530 | [diff] [blame] | 499 | |
Tomi Valkeinen | 100c826 | 2013-03-05 17:07:16 +0200 | [diff] [blame] | 500 | lck_div = ctx.dispc_cinfo.lck_div; |
| 501 | pck_div = ctx.dispc_cinfo.pck_div; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 502 | |
| 503 | pck = fck / lck_div / pck_div / 1000; |
| 504 | |
| 505 | timings->pixel_clock = pck; |
| 506 | |
| 507 | return 0; |
| 508 | } |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 509 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 510 | static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines) |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame] | 511 | { |
| 512 | mutex_lock(&dpi.lock); |
| 513 | |
| 514 | dpi.data_lines = data_lines; |
| 515 | |
| 516 | mutex_unlock(&dpi.lock); |
| 517 | } |
Archit Taneja | c6b393d | 2012-07-06 15:30:52 +0530 | [diff] [blame] | 518 | |
Tomi Valkeinen | 94cf394 | 2013-04-26 14:27:44 +0300 | [diff] [blame] | 519 | static int dpi_verify_dsi_pll(struct platform_device *dsidev) |
Tomi Valkeinen | 6061675 | 2012-10-30 12:57:43 +0200 | [diff] [blame] | 520 | { |
| 521 | int r; |
| 522 | |
| 523 | /* do initial setup with the PLL to see if it is operational */ |
| 524 | |
| 525 | r = dsi_runtime_get(dsidev); |
| 526 | if (r) |
| 527 | return r; |
| 528 | |
| 529 | r = dsi_pll_init(dsidev, 0, 1); |
| 530 | if (r) { |
| 531 | dsi_runtime_put(dsidev); |
| 532 | return r; |
| 533 | } |
| 534 | |
| 535 | dsi_pll_uninit(dsidev, true); |
| 536 | dsi_runtime_put(dsidev); |
| 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
Tomi Valkeinen | 2795f64 | 2013-04-19 16:52:27 +0300 | [diff] [blame] | 541 | static int dpi_init_regulator(void) |
| 542 | { |
| 543 | struct regulator *vdds_dsi; |
| 544 | |
| 545 | if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) |
| 546 | return 0; |
| 547 | |
| 548 | if (dpi.vdds_dsi_reg) |
| 549 | return 0; |
| 550 | |
Tomi Valkeinen | 4123de2 | 2013-08-29 10:06:55 +0300 | [diff] [blame] | 551 | vdds_dsi = devm_regulator_get(&dpi.pdev->dev, "vdds_dsi"); |
Tomi Valkeinen | 2795f64 | 2013-04-19 16:52:27 +0300 | [diff] [blame] | 552 | if (IS_ERR(vdds_dsi)) { |
Tomi Valkeinen | 40359a9 | 2013-12-19 16:15:34 +0200 | [diff] [blame] | 553 | if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER) |
| 554 | DSSERR("can't get VDDS_DSI regulator\n"); |
Tomi Valkeinen | 4123de2 | 2013-08-29 10:06:55 +0300 | [diff] [blame] | 555 | return PTR_ERR(vdds_dsi); |
Tomi Valkeinen | 2795f64 | 2013-04-19 16:52:27 +0300 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | dpi.vdds_dsi_reg = vdds_dsi; |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static void dpi_init_pll(void) |
| 564 | { |
| 565 | struct platform_device *dsidev; |
| 566 | |
| 567 | if (dpi.dsidev) |
| 568 | return; |
| 569 | |
| 570 | dsidev = dpi_get_dsidev(dpi.output.dispc_channel); |
| 571 | if (!dsidev) |
| 572 | return; |
| 573 | |
| 574 | if (dpi_verify_dsi_pll(dsidev)) { |
| 575 | DSSWARN("DSI PLL not operational\n"); |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | dpi.dsidev = dsidev; |
| 580 | } |
| 581 | |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 582 | /* |
| 583 | * Return a hardcoded channel for the DPI output. This should work for |
| 584 | * current use cases, but this can be later expanded to either resolve |
| 585 | * the channel in some more dynamic manner, or get the channel as a user |
| 586 | * parameter. |
| 587 | */ |
| 588 | static enum omap_channel dpi_get_channel(void) |
| 589 | { |
| 590 | switch (omapdss_get_version()) { |
| 591 | case OMAPDSS_VER_OMAP24xx: |
| 592 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 593 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 594 | case OMAPDSS_VER_OMAP3630: |
| 595 | case OMAPDSS_VER_AM35xx: |
| 596 | return OMAP_DSS_CHANNEL_LCD; |
| 597 | |
| 598 | case OMAPDSS_VER_OMAP4430_ES1: |
| 599 | case OMAPDSS_VER_OMAP4430_ES2: |
| 600 | case OMAPDSS_VER_OMAP4: |
| 601 | return OMAP_DSS_CHANNEL_LCD2; |
| 602 | |
| 603 | case OMAPDSS_VER_OMAP5: |
| 604 | return OMAP_DSS_CHANNEL_LCD3; |
| 605 | |
| 606 | default: |
| 607 | DSSWARN("unsupported DSS version\n"); |
| 608 | return OMAP_DSS_CHANNEL_LCD; |
| 609 | } |
| 610 | } |
| 611 | |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 612 | static int dpi_connect(struct omap_dss_device *dssdev, |
| 613 | struct omap_dss_device *dst) |
| 614 | { |
| 615 | struct omap_overlay_manager *mgr; |
| 616 | int r; |
| 617 | |
| 618 | r = dpi_init_regulator(); |
| 619 | if (r) |
| 620 | return r; |
| 621 | |
| 622 | dpi_init_pll(); |
| 623 | |
| 624 | mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel); |
| 625 | if (!mgr) |
| 626 | return -ENODEV; |
| 627 | |
| 628 | r = dss_mgr_connect(mgr, dssdev); |
| 629 | if (r) |
| 630 | return r; |
| 631 | |
| 632 | r = omapdss_output_set_device(dssdev, dst); |
| 633 | if (r) { |
| 634 | DSSERR("failed to connect output to new device: %s\n", |
| 635 | dst->name); |
| 636 | dss_mgr_disconnect(mgr, dssdev); |
| 637 | return r; |
| 638 | } |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static void dpi_disconnect(struct omap_dss_device *dssdev, |
| 644 | struct omap_dss_device *dst) |
| 645 | { |
Tomi Valkeinen | 9560dc10 | 2013-07-24 13:06:54 +0300 | [diff] [blame] | 646 | WARN_ON(dst != dssdev->dst); |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 647 | |
Tomi Valkeinen | 9560dc10 | 2013-07-24 13:06:54 +0300 | [diff] [blame] | 648 | if (dst != dssdev->dst) |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 649 | return; |
| 650 | |
| 651 | omapdss_output_unset_device(dssdev); |
| 652 | |
| 653 | if (dssdev->manager) |
| 654 | dss_mgr_disconnect(dssdev->manager, dssdev); |
| 655 | } |
| 656 | |
| 657 | static const struct omapdss_dpi_ops dpi_ops = { |
| 658 | .connect = dpi_connect, |
| 659 | .disconnect = dpi_disconnect, |
| 660 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 661 | .enable = dpi_display_enable, |
| 662 | .disable = dpi_display_disable, |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 663 | |
| 664 | .check_timings = dpi_check_timings, |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 665 | .set_timings = dpi_set_timings, |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 666 | .get_timings = dpi_get_timings, |
| 667 | |
Tomi Valkeinen | 86a3efe | 2013-05-15 10:40:15 +0300 | [diff] [blame] | 668 | .set_data_lines = dpi_set_data_lines, |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 669 | }; |
| 670 | |
Tomi Valkeinen | 94cf394 | 2013-04-26 14:27:44 +0300 | [diff] [blame] | 671 | static void dpi_init_output(struct platform_device *pdev) |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 672 | { |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 673 | struct omap_dss_device *out = &dpi.output; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 674 | |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 675 | out->dev = &pdev->dev; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 676 | out->id = OMAP_DSS_OUTPUT_DPI; |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 677 | out->output_type = OMAP_DISPLAY_TYPE_DPI; |
Tomi Valkeinen | 7286a08 | 2013-02-18 13:06:01 +0200 | [diff] [blame] | 678 | out->name = "dpi.0"; |
Tomi Valkeinen | 2eea5ae | 2013-02-13 11:23:54 +0200 | [diff] [blame] | 679 | out->dispc_channel = dpi_get_channel(); |
Tomi Valkeinen | 0b24edb | 2013-05-24 13:18:52 +0300 | [diff] [blame] | 680 | out->ops.dpi = &dpi_ops; |
Tomi Valkeinen | b7328e1 | 2013-05-03 11:42:18 +0300 | [diff] [blame] | 681 | out->owner = THIS_MODULE; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 682 | |
Tomi Valkeinen | 5d47dbc | 2013-04-24 13:32:51 +0300 | [diff] [blame] | 683 | omapdss_register_output(out); |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void __exit dpi_uninit_output(struct platform_device *pdev) |
| 687 | { |
Tomi Valkeinen | 1f68d9c | 2013-04-19 15:09:34 +0300 | [diff] [blame] | 688 | struct omap_dss_device *out = &dpi.output; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 689 | |
Tomi Valkeinen | 5d47dbc | 2013-04-24 13:32:51 +0300 | [diff] [blame] | 690 | omapdss_unregister_output(out); |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 691 | } |
| 692 | |
Tomi Valkeinen | 94cf394 | 2013-04-26 14:27:44 +0300 | [diff] [blame] | 693 | static int omap_dpi_probe(struct platform_device *pdev) |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 694 | { |
Tomi Valkeinen | 00df43b | 2013-03-19 11:33:52 +0200 | [diff] [blame] | 695 | dpi.pdev = pdev; |
| 696 | |
Archit Taneja | c8a5e4e | 2012-07-05 12:52:46 +0530 | [diff] [blame] | 697 | mutex_init(&dpi.lock); |
| 698 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 699 | dpi_init_output(pdev); |
| 700 | |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 704 | static int __exit omap_dpi_remove(struct platform_device *pdev) |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 705 | { |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 706 | dpi_uninit_output(pdev); |
| 707 | |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 708 | return 0; |
Tomi Valkeinen | 553c48c | 2009-08-07 13:15:50 +0300 | [diff] [blame] | 709 | } |
| 710 | |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 711 | static struct platform_driver omap_dpi_driver = { |
Tomi Valkeinen | 94cf394 | 2013-04-26 14:27:44 +0300 | [diff] [blame] | 712 | .probe = omap_dpi_probe, |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 713 | .remove = __exit_p(omap_dpi_remove), |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 714 | .driver = { |
| 715 | .name = "omapdss_dpi", |
| 716 | .owner = THIS_MODULE, |
| 717 | }, |
| 718 | }; |
| 719 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 720 | int __init dpi_init_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 721 | { |
Tomi Valkeinen | 94cf394 | 2013-04-26 14:27:44 +0300 | [diff] [blame] | 722 | return platform_driver_register(&omap_dpi_driver); |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 723 | } |
| 724 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 725 | void __exit dpi_uninit_platform_driver(void) |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 726 | { |
| 727 | platform_driver_unregister(&omap_dpi_driver); |
| 728 | } |