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