Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1 | /* |
| 2 | * hdmi.c |
| 3 | * |
| 4 | * HDMI interface DSS driver setting for TI's OMAP4 family of processor. |
| 5 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * Authors: Yong Zhi |
| 7 | * Mythri pk <mythripk@ti.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as published by |
| 11 | * the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #define DSS_SUBSYS_NAME "HDMI" |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/err.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/mutex.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/string.h> |
Tomi Valkeinen | 24e6289 | 2011-05-23 11:51:18 +0300 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
| 34 | #include <linux/clk.h> |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 35 | #include <video/omapdss.h> |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 36 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 37 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
| 38 | #include <sound/soc.h> |
| 39 | #include <sound/pcm_params.h> |
Mythri P K | 7334167 | 2011-09-08 19:06:24 +0530 | [diff] [blame] | 40 | #include "ti_hdmi_4xxx_ip.h" |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 41 | #endif |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 42 | |
Mythri P K | 94c5298 | 2011-09-08 19:06:21 +0530 | [diff] [blame] | 43 | #include "ti_hdmi.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 44 | #include "dss.h" |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 45 | #include "dss_features.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 46 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 47 | #define HDMI_WP 0x0 |
| 48 | #define HDMI_CORE_SYS 0x400 |
| 49 | #define HDMI_CORE_AV 0x900 |
| 50 | #define HDMI_PLLCTRL 0x200 |
| 51 | #define HDMI_PHY 0x300 |
| 52 | |
Mythri P K | 7c1f1ec | 2011-09-08 19:06:22 +0530 | [diff] [blame] | 53 | /* HDMI EDID Length move this */ |
| 54 | #define HDMI_EDID_MAX_LENGTH 256 |
| 55 | #define EDID_TIMING_DESCRIPTOR_SIZE 0x12 |
| 56 | #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36 |
| 57 | #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80 |
| 58 | #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4 |
| 59 | #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4 |
| 60 | |
| 61 | #define OMAP_HDMI_TIMINGS_NB 34 |
| 62 | |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 63 | #define HDMI_DEFAULT_REGN 16 |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 64 | #define HDMI_DEFAULT_REGM2 1 |
| 65 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 66 | static struct { |
| 67 | struct mutex lock; |
| 68 | struct omap_display_platform_data *pdata; |
| 69 | struct platform_device *pdev; |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 70 | struct hdmi_ip_data ip_data; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 71 | int code; |
| 72 | int mode; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 73 | |
| 74 | struct clk *sys_clk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 75 | } hdmi; |
| 76 | |
| 77 | /* |
| 78 | * Logic for the below structure : |
| 79 | * user enters the CEA or VESA timings by specifying the HDMI/DVI code. |
| 80 | * There is a correspondence between CEA/VESA timing and code, please |
| 81 | * refer to section 6.3 in HDMI 1.3 specification for timing code. |
| 82 | * |
| 83 | * In the below structure, cea_vesa_timings corresponds to all OMAP4 |
| 84 | * supported CEA and VESA timing values.code_cea corresponds to the CEA |
| 85 | * code, It is used to get the timing from cea_vesa_timing array.Similarly |
| 86 | * with code_vesa. Code_index is used for back mapping, that is once EDID |
| 87 | * is read from the TV, EDID is parsed to find the timing values and then |
| 88 | * map it to corresponding CEA or VESA index. |
| 89 | */ |
| 90 | |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame^] | 91 | static const struct hdmi_config cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = { |
| 92 | { {640, 480, 25200, 96, 16, 48, 2, 10, 33, 0, 0, 0}, {1, HDMI_HDMI} }, |
| 93 | { {720, 480, 27027, 62, 16, 60, 6, 9, 30, 0, 0, 0}, {2, HDMI_HDMI} }, |
| 94 | { {1280, 720, 74250, 40, 110, 220, 5, 5, 20, 1, 1, 0}, {4, HDMI_HDMI} }, |
| 95 | { {1920, 540, 74250, 44, 88, 148, 5, 2, 15, 1, 1, 1}, {5, HDMI_HDMI} }, |
| 96 | { {1440, 240, 27027, 124, 38, 114, 3, 4, 15, 0, 0, 1}, {6, HDMI_HDMI} }, |
| 97 | { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36, 1, 1, 0}, {16, HDMI_HDMI} }, |
| 98 | { {720, 576, 27000, 64, 12, 68, 5, 5, 39, 0, 0, 0}, {17, HDMI_HDMI} }, |
| 99 | { {1280, 720, 74250, 40, 440, 220, 5, 5, 20, 1, 1, 0}, {19, HDMI_HDMI} }, |
| 100 | { {1920, 540, 74250, 44, 528, 148, 5, 2, 15, 1, 1, 1}, {20, HDMI_HDMI} }, |
| 101 | { {1440, 288, 27000, 126, 24, 138, 3, 2, 19, 0, 0, 1}, {21, HDMI_HDMI} }, |
| 102 | { {1440, 576, 54000, 128, 24, 136, 5, 5, 39, 0, 0, 0}, {29, HDMI_HDMI} }, |
| 103 | { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36, 1, 1, 0}, {31, HDMI_HDMI} }, |
| 104 | { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36, 1, 1, 0}, {32, HDMI_HDMI} }, |
| 105 | { {2880, 480, 108108, 248, 64, 240, 6, 9, 30, 0, 0, 0}, {35, HDMI_HDMI} }, |
| 106 | { {2880, 576, 108000, 256, 48, 272, 5, 5, 39, 0, 0, 0}, {37, HDMI_HDMI} }, |
| 107 | /* VESA From Here */ |
| 108 | { {640, 480, 25175, 96, 16, 48, 2 , 11, 31, 0, 0, 0}, {4, HDMI_DVI} }, |
| 109 | { {800, 600, 40000, 128, 40, 88, 4 , 1, 23, 1, 1, 0}, {9, HDMI_DVI} }, |
| 110 | { {848, 480, 33750, 112, 16, 112, 8 , 6, 23, 1, 1, 0}, {0xE, HDMI_DVI} }, |
| 111 | { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20, 1, 0, 0}, {0x17, HDMI_DVI} }, |
| 112 | { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22, 1, 0, 0}, {0x1C, HDMI_DVI} }, |
| 113 | { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18, 1, 1, 0}, {0x27, HDMI_DVI} }, |
| 114 | { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36, 1, 1, 0}, {0x20, HDMI_DVI} }, |
| 115 | { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38, 1, 1, 0}, {0x23, HDMI_DVI} }, |
| 116 | { {1024, 768, 65000, 136, 24, 160, 6, 3, 29, 0, 0, 0}, {0x10, HDMI_DVI} }, |
| 117 | { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32, 1, 0, 0}, {0x2A, HDMI_DVI} }, |
| 118 | { {1440, 900, 106500, 152, 80, 232, 6, 3, 25, 1, 0, 0}, {0x2F, HDMI_DVI} }, |
| 119 | { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30, 1, 0, 0}, {0x3A, HDMI_DVI} }, |
| 120 | { {1366, 768, 85500, 143, 70, 213, 3, 3, 24, 1, 1, 0}, {0x51, HDMI_DVI} }, |
| 121 | { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36, 1, 1, 0}, {0x52, HDMI_DVI} }, |
| 122 | { {1280, 768, 68250, 32, 48, 80, 7, 3, 12, 0, 1, 0}, {0x16, HDMI_DVI} }, |
| 123 | { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23, 0, 1, 0}, {0x29, HDMI_DVI} }, |
| 124 | { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21, 0, 1, 0}, {0x39, HDMI_DVI} }, |
| 125 | { {1280, 800, 79500, 32, 48, 80, 6, 3, 14, 0, 1, 0}, {0x1B, HDMI_DVI} }, |
| 126 | { {1280, 720, 74250, 40, 110, 220, 5, 5, 20, 1, 1, 0}, {0x55, HDMI_DVI} } |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * This is a static mapping array which maps the timing values |
| 131 | * with corresponding CEA / VESA code |
| 132 | */ |
| 133 | static const int code_index[OMAP_HDMI_TIMINGS_NB] = { |
| 134 | 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32, |
| 135 | /* <--15 CEA 17--> vesa*/ |
| 136 | 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A, |
| 137 | 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B |
| 138 | }; |
| 139 | |
| 140 | /* |
| 141 | * This is reverse static mapping which maps the CEA / VESA code |
| 142 | * to the corresponding timing values |
| 143 | */ |
| 144 | static const int code_cea[39] = { |
| 145 | -1, 0, 3, 3, 2, 8, 5, 5, -1, -1, |
| 146 | -1, -1, -1, -1, -1, -1, 9, 10, 10, 1, |
| 147 | 7, 6, 6, -1, -1, -1, -1, -1, -1, 11, |
| 148 | 11, 12, 14, -1, -1, 13, 13, 4, 4 |
| 149 | }; |
| 150 | |
| 151 | static const int code_vesa[85] = { |
| 152 | -1, -1, -1, -1, 15, -1, -1, -1, -1, 16, |
| 153 | -1, -1, -1, -1, 17, -1, 23, -1, -1, -1, |
| 154 | -1, -1, 29, 18, -1, -1, -1, 32, 19, -1, |
| 155 | -1, -1, 21, -1, -1, 22, -1, -1, -1, 20, |
| 156 | -1, 30, 24, -1, -1, -1, -1, 25, -1, -1, |
| 157 | -1, -1, -1, -1, -1, -1, -1, 31, 26, -1, |
| 158 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 159 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 160 | -1, 27, 28, -1, 33}; |
| 161 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 162 | static int hdmi_runtime_get(void) |
| 163 | { |
| 164 | int r; |
| 165 | |
| 166 | DSSDBG("hdmi_runtime_get\n"); |
| 167 | |
| 168 | r = pm_runtime_get_sync(&hdmi.pdev->dev); |
| 169 | WARN_ON(r < 0); |
| 170 | return r < 0 ? r : 0; |
| 171 | } |
| 172 | |
| 173 | static void hdmi_runtime_put(void) |
| 174 | { |
| 175 | int r; |
| 176 | |
| 177 | DSSDBG("hdmi_runtime_put\n"); |
| 178 | |
| 179 | r = pm_runtime_put(&hdmi.pdev->dev); |
| 180 | WARN_ON(r < 0); |
| 181 | } |
| 182 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 183 | int hdmi_init_display(struct omap_dss_device *dssdev) |
| 184 | { |
| 185 | DSSDBG("init_display\n"); |
| 186 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 187 | dss_init_hdmi_ip_ops(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 191 | static int get_timings_index(void) |
| 192 | { |
| 193 | int code; |
| 194 | |
| 195 | if (hdmi.mode == 0) |
| 196 | code = code_vesa[hdmi.code]; |
| 197 | else |
| 198 | code = code_cea[hdmi.code]; |
| 199 | |
| 200 | if (code == -1) { |
| 201 | /* HDMI code 4 corresponds to 640 * 480 VGA */ |
| 202 | hdmi.code = 4; |
| 203 | /* DVI mode 1 corresponds to HDMI 0 to DVI */ |
| 204 | hdmi.mode = HDMI_DVI; |
| 205 | |
| 206 | code = code_vesa[hdmi.code]; |
| 207 | } |
| 208 | return code; |
| 209 | } |
| 210 | |
| 211 | static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing) |
| 212 | { |
| 213 | int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0; |
| 214 | int timing_vsync = 0, timing_hsync = 0; |
Mythri P K | 38863b7 | 2011-09-08 19:06:20 +0530 | [diff] [blame] | 215 | struct hdmi_video_timings temp; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 216 | struct hdmi_cm cm = {-1}; |
| 217 | DSSDBG("hdmi_get_code\n"); |
| 218 | |
| 219 | for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) { |
| 220 | temp = cea_vesa_timings[i].timings; |
| 221 | if ((temp.pixel_clock == timing->pixel_clock) && |
| 222 | (temp.x_res == timing->x_res) && |
| 223 | (temp.y_res == timing->y_res)) { |
| 224 | |
| 225 | temp_hsync = temp.hfp + temp.hsw + temp.hbp; |
| 226 | timing_hsync = timing->hfp + timing->hsw + timing->hbp; |
| 227 | temp_vsync = temp.vfp + temp.vsw + temp.vbp; |
| 228 | timing_vsync = timing->vfp + timing->vsw + timing->vbp; |
| 229 | |
| 230 | DSSDBG("temp_hsync = %d , temp_vsync = %d" |
| 231 | "timing_hsync = %d, timing_vsync = %d\n", |
| 232 | temp_hsync, temp_hsync, |
| 233 | timing_hsync, timing_vsync); |
| 234 | |
| 235 | if ((temp_hsync == timing_hsync) && |
| 236 | (temp_vsync == timing_vsync)) { |
| 237 | code = i; |
| 238 | cm.code = code_index[i]; |
| 239 | if (code < 14) |
| 240 | cm.mode = HDMI_HDMI; |
| 241 | else |
| 242 | cm.mode = HDMI_DVI; |
| 243 | DSSDBG("Hdmi_code = %d mode = %d\n", |
| 244 | cm.code, cm.mode); |
| 245 | break; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return cm; |
| 251 | } |
| 252 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 253 | static void update_hdmi_timings(struct hdmi_config *cfg, |
| 254 | struct omap_video_timings *timings, int code) |
| 255 | { |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame^] | 256 | cfg->timings.x_res = timings->x_res; |
| 257 | cfg->timings.y_res = timings->y_res; |
| 258 | cfg->timings.hbp = timings->hbp; |
| 259 | cfg->timings.hfp = timings->hfp; |
| 260 | cfg->timings.hsw = timings->hsw; |
| 261 | cfg->timings.vbp = timings->vbp; |
| 262 | cfg->timings.vfp = timings->vfp; |
| 263 | cfg->timings.vsw = timings->vsw; |
| 264 | cfg->timings.pixel_clock = timings->pixel_clock; |
| 265 | cfg->timings.vsync_pol = cea_vesa_timings[code].timings.vsync_pol; |
| 266 | cfg->timings.hsync_pol = cea_vesa_timings[code].timings.hsync_pol; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 267 | } |
| 268 | |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 269 | unsigned long hdmi_get_pixel_clock(void) |
| 270 | { |
| 271 | /* HDMI Pixel Clock in Mhz */ |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame^] | 272 | return hdmi.ip_data.cfg.timings.pixel_clock * 1000; |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 273 | } |
| 274 | |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 275 | static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy, |
| 276 | struct hdmi_pll_info *pi) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 277 | { |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 278 | unsigned long clkin, refclk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 279 | u32 mf; |
| 280 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 281 | clkin = clk_get_rate(hdmi.sys_clk) / 10000; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 282 | /* |
| 283 | * Input clock is predivided by N + 1 |
| 284 | * out put of which is reference clk |
| 285 | */ |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 286 | if (dssdev->clocks.hdmi.regn == 0) |
| 287 | pi->regn = HDMI_DEFAULT_REGN; |
| 288 | else |
| 289 | pi->regn = dssdev->clocks.hdmi.regn; |
| 290 | |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 291 | refclk = clkin / pi->regn; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * multiplier is pixel_clk/ref_clk |
| 295 | * Multiplying by 100 to avoid fractional part removal |
| 296 | */ |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 297 | pi->regm = (phy * 100 / (refclk)) / 100; |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 298 | |
| 299 | if (dssdev->clocks.hdmi.regm2 == 0) |
| 300 | pi->regm2 = HDMI_DEFAULT_REGM2; |
| 301 | else |
| 302 | pi->regm2 = dssdev->clocks.hdmi.regm2; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * fractional multiplier is remainder of the difference between |
| 306 | * multiplier and actual phy(required pixel clock thus should be |
| 307 | * multiplied by 2^18(262144) divided by the reference clock |
| 308 | */ |
| 309 | mf = (phy - pi->regm * refclk) * 262144; |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 310 | pi->regmf = mf / (refclk); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * Dcofreq should be set to 1 if required pixel clock |
| 314 | * is greater than 1000MHz |
| 315 | */ |
| 316 | pi->dcofreq = phy > 1000 * 100; |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 317 | pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 318 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 319 | /* Set the reference clock to sysclk reference */ |
| 320 | pi->refsel = HDMI_REFSEL_SYSCLK; |
| 321 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 322 | DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf); |
| 323 | DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd); |
| 324 | } |
| 325 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 326 | static int hdmi_power_on(struct omap_dss_device *dssdev) |
| 327 | { |
| 328 | int r, code = 0; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 329 | struct omap_video_timings *p; |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 330 | unsigned long phy; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 331 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 332 | r = hdmi_runtime_get(); |
| 333 | if (r) |
| 334 | return r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 335 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 336 | dss_mgr_disable(dssdev->manager); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 337 | |
| 338 | p = &dssdev->panel.timings; |
| 339 | |
| 340 | DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", |
| 341 | dssdev->panel.timings.x_res, |
| 342 | dssdev->panel.timings.y_res); |
| 343 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 344 | code = get_timings_index(); |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 345 | update_hdmi_timings(&hdmi.ip_data.cfg, p, code); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 346 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 347 | phy = p->pixel_clock; |
| 348 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 349 | hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 350 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 351 | hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 352 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 353 | /* config the PLL and PHY hdmi_set_pll_pwrfirst */ |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 354 | r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 355 | if (r) { |
| 356 | DSSDBG("Failed to lock PLL\n"); |
| 357 | goto err; |
| 358 | } |
| 359 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 360 | r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 361 | if (r) { |
| 362 | DSSDBG("Failed to start PHY\n"); |
| 363 | goto err; |
| 364 | } |
| 365 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 366 | hdmi.ip_data.cfg.cm.mode = hdmi.mode; |
| 367 | hdmi.ip_data.cfg.cm.code = hdmi.code; |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 368 | hdmi.ip_data.ops->video_configure(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 369 | |
| 370 | /* Make selection of HDMI in DSS */ |
| 371 | dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK); |
| 372 | |
| 373 | /* Select the dispc clock source as PRCM clock, to ensure that it is not |
| 374 | * DSI PLL source as the clock selected by DSI PLL might not be |
| 375 | * sufficient for the resolution selected / that can be changed |
| 376 | * dynamically by user. This can be moved to single location , say |
| 377 | * Boardfile. |
| 378 | */ |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 379 | dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 380 | |
| 381 | /* bypass TV gamma table */ |
| 382 | dispc_enable_gamma_table(0); |
| 383 | |
| 384 | /* tv size */ |
| 385 | dispc_set_digit_size(dssdev->panel.timings.x_res, |
| 386 | dssdev->panel.timings.y_res); |
| 387 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 388 | hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 1); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 389 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 390 | r = dss_mgr_enable(dssdev->manager); |
| 391 | if (r) |
| 392 | goto err_mgr_enable; |
Tomi Valkeinen | 3870c90 | 2011-08-31 14:47:11 +0300 | [diff] [blame] | 393 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 394 | return 0; |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 395 | |
| 396 | err_mgr_enable: |
| 397 | hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0); |
| 398 | hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); |
| 399 | hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 400 | err: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 401 | hdmi_runtime_put(); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 402 | return -EIO; |
| 403 | } |
| 404 | |
| 405 | static void hdmi_power_off(struct omap_dss_device *dssdev) |
| 406 | { |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 407 | dss_mgr_disable(dssdev->manager); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 408 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 409 | hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0); |
| 410 | hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); |
| 411 | hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 412 | hdmi_runtime_put(); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev, |
| 416 | struct omap_video_timings *timings) |
| 417 | { |
| 418 | struct hdmi_cm cm; |
| 419 | |
| 420 | cm = hdmi_get_code(timings); |
| 421 | if (cm.code == -1) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 422 | return -EINVAL; |
| 423 | } |
| 424 | |
| 425 | return 0; |
| 426 | |
| 427 | } |
| 428 | |
| 429 | void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev) |
| 430 | { |
| 431 | struct hdmi_cm cm; |
| 432 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 433 | cm = hdmi_get_code(&dssdev->panel.timings); |
| 434 | hdmi.code = cm.code; |
| 435 | hdmi.mode = cm.mode; |
Tomi Valkeinen | fa70dc5 | 2011-08-22 14:57:33 +0300 | [diff] [blame] | 436 | |
| 437 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
| 438 | int r; |
| 439 | |
| 440 | hdmi_power_off(dssdev); |
| 441 | |
| 442 | r = hdmi_power_on(dssdev); |
| 443 | if (r) |
| 444 | DSSERR("failed to power on device\n"); |
| 445 | } |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 446 | } |
| 447 | |
Mythri P K | 162874d | 2011-09-22 13:37:45 +0530 | [diff] [blame] | 448 | void hdmi_dump_regs(struct seq_file *s) |
| 449 | { |
| 450 | mutex_lock(&hdmi.lock); |
| 451 | |
| 452 | if (hdmi_runtime_get()) |
| 453 | return; |
| 454 | |
| 455 | hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s); |
| 456 | hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s); |
| 457 | hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s); |
| 458 | hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s); |
| 459 | |
| 460 | hdmi_runtime_put(); |
| 461 | mutex_unlock(&hdmi.lock); |
| 462 | } |
| 463 | |
Tomi Valkeinen | 4702456 | 2011-08-25 17:12:56 +0300 | [diff] [blame] | 464 | int omapdss_hdmi_read_edid(u8 *buf, int len) |
| 465 | { |
| 466 | int r; |
| 467 | |
| 468 | mutex_lock(&hdmi.lock); |
| 469 | |
| 470 | r = hdmi_runtime_get(); |
| 471 | BUG_ON(r); |
| 472 | |
| 473 | r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len); |
| 474 | |
| 475 | hdmi_runtime_put(); |
| 476 | mutex_unlock(&hdmi.lock); |
| 477 | |
| 478 | return r; |
| 479 | } |
| 480 | |
Tomi Valkeinen | 759593f | 2011-08-29 18:10:20 +0300 | [diff] [blame] | 481 | bool omapdss_hdmi_detect(void) |
| 482 | { |
| 483 | int r; |
| 484 | |
| 485 | mutex_lock(&hdmi.lock); |
| 486 | |
| 487 | r = hdmi_runtime_get(); |
| 488 | BUG_ON(r); |
| 489 | |
| 490 | r = hdmi.ip_data.ops->detect(&hdmi.ip_data); |
| 491 | |
| 492 | hdmi_runtime_put(); |
| 493 | mutex_unlock(&hdmi.lock); |
| 494 | |
| 495 | return r == 1; |
| 496 | } |
| 497 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 498 | int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev) |
| 499 | { |
| 500 | int r = 0; |
| 501 | |
| 502 | DSSDBG("ENTER hdmi_display_enable\n"); |
| 503 | |
| 504 | mutex_lock(&hdmi.lock); |
| 505 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 506 | if (dssdev->manager == NULL) { |
| 507 | DSSERR("failed to enable display: no manager\n"); |
| 508 | r = -ENODEV; |
| 509 | goto err0; |
| 510 | } |
| 511 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 512 | r = omap_dss_start_device(dssdev); |
| 513 | if (r) { |
| 514 | DSSERR("failed to start device\n"); |
| 515 | goto err0; |
| 516 | } |
| 517 | |
| 518 | if (dssdev->platform_enable) { |
| 519 | r = dssdev->platform_enable(dssdev); |
| 520 | if (r) { |
| 521 | DSSERR("failed to enable GPIO's\n"); |
| 522 | goto err1; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | r = hdmi_power_on(dssdev); |
| 527 | if (r) { |
| 528 | DSSERR("failed to power on device\n"); |
| 529 | goto err2; |
| 530 | } |
| 531 | |
| 532 | mutex_unlock(&hdmi.lock); |
| 533 | return 0; |
| 534 | |
| 535 | err2: |
| 536 | if (dssdev->platform_disable) |
| 537 | dssdev->platform_disable(dssdev); |
| 538 | err1: |
| 539 | omap_dss_stop_device(dssdev); |
| 540 | err0: |
| 541 | mutex_unlock(&hdmi.lock); |
| 542 | return r; |
| 543 | } |
| 544 | |
| 545 | void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev) |
| 546 | { |
| 547 | DSSDBG("Enter hdmi_display_disable\n"); |
| 548 | |
| 549 | mutex_lock(&hdmi.lock); |
| 550 | |
| 551 | hdmi_power_off(dssdev); |
| 552 | |
| 553 | if (dssdev->platform_disable) |
| 554 | dssdev->platform_disable(dssdev); |
| 555 | |
| 556 | omap_dss_stop_device(dssdev); |
| 557 | |
| 558 | mutex_unlock(&hdmi.lock); |
| 559 | } |
| 560 | |
Ricardo Neri | 82335c4 | 2011-04-05 16:05:18 -0500 | [diff] [blame] | 561 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 562 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 563 | |
Ricardo Neri | edefcda | 2011-11-27 16:18:01 -0600 | [diff] [blame] | 564 | static int hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd, |
| 565 | struct snd_soc_dai *dai) |
| 566 | { |
| 567 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 568 | struct snd_soc_codec *codec = rtd->codec; |
| 569 | struct platform_device *pdev = to_platform_device(codec->dev); |
| 570 | struct hdmi_ip_data *ip_data = snd_soc_codec_get_drvdata(codec); |
| 571 | int err = 0; |
| 572 | |
| 573 | if (!(ip_data->ops) && !(ip_data->ops->audio_enable)) { |
| 574 | dev_err(&pdev->dev, "Cannot enable/disable audio\n"); |
| 575 | return -ENODEV; |
| 576 | } |
| 577 | |
| 578 | switch (cmd) { |
| 579 | case SNDRV_PCM_TRIGGER_START: |
| 580 | case SNDRV_PCM_TRIGGER_RESUME: |
| 581 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 582 | ip_data->ops->audio_enable(ip_data, true); |
| 583 | break; |
| 584 | case SNDRV_PCM_TRIGGER_STOP: |
| 585 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 586 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 587 | ip_data->ops->audio_enable(ip_data, false); |
| 588 | break; |
| 589 | default: |
| 590 | err = -EINVAL; |
| 591 | } |
| 592 | return err; |
| 593 | } |
| 594 | |
Ricardo Neri | 284cb31 | 2011-11-22 20:50:50 -0600 | [diff] [blame] | 595 | static int hdmi_audio_hw_params(struct snd_pcm_substream *substream, |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 596 | struct snd_pcm_hw_params *params, |
| 597 | struct snd_soc_dai *dai) |
| 598 | { |
Ricardo Neri | 284cb31 | 2011-11-22 20:50:50 -0600 | [diff] [blame] | 599 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 600 | struct snd_soc_codec *codec = rtd->codec; |
| 601 | struct hdmi_ip_data *ip_data = snd_soc_codec_get_drvdata(codec); |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 602 | struct hdmi_audio_format audio_format; |
| 603 | struct hdmi_audio_dma audio_dma; |
| 604 | struct hdmi_core_audio_config core_cfg; |
| 605 | struct hdmi_core_infoframe_audio aud_if_cfg; |
| 606 | int err, n, cts; |
| 607 | enum hdmi_core_audio_sample_freq sample_freq; |
| 608 | |
| 609 | switch (params_format(params)) { |
| 610 | case SNDRV_PCM_FORMAT_S16_LE: |
| 611 | core_cfg.i2s_cfg.word_max_length = |
| 612 | HDMI_AUDIO_I2S_MAX_WORD_20BITS; |
| 613 | core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS; |
| 614 | core_cfg.i2s_cfg.in_length_bits = |
| 615 | HDMI_AUDIO_I2S_INPUT_LENGTH_16; |
| 616 | core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT; |
| 617 | audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES; |
| 618 | audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS; |
| 619 | audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT; |
| 620 | audio_dma.transfer_size = 0x10; |
| 621 | break; |
| 622 | case SNDRV_PCM_FORMAT_S24_LE: |
| 623 | core_cfg.i2s_cfg.word_max_length = |
| 624 | HDMI_AUDIO_I2S_MAX_WORD_24BITS; |
| 625 | core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS; |
| 626 | core_cfg.i2s_cfg.in_length_bits = |
| 627 | HDMI_AUDIO_I2S_INPUT_LENGTH_24; |
| 628 | audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE; |
| 629 | audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS; |
| 630 | audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT; |
| 631 | core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT; |
| 632 | audio_dma.transfer_size = 0x20; |
| 633 | break; |
| 634 | default: |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | |
| 638 | switch (params_rate(params)) { |
| 639 | case 32000: |
| 640 | sample_freq = HDMI_AUDIO_FS_32000; |
| 641 | break; |
| 642 | case 44100: |
| 643 | sample_freq = HDMI_AUDIO_FS_44100; |
| 644 | break; |
| 645 | case 48000: |
| 646 | sample_freq = HDMI_AUDIO_FS_48000; |
| 647 | break; |
| 648 | default: |
| 649 | return -EINVAL; |
| 650 | } |
| 651 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 652 | err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts); |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 653 | if (err < 0) |
| 654 | return err; |
| 655 | |
| 656 | /* Audio wrapper config */ |
| 657 | audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL; |
| 658 | audio_format.active_chnnls_msk = 0x03; |
| 659 | audio_format.type = HDMI_AUDIO_TYPE_LPCM; |
| 660 | audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST; |
| 661 | /* Disable start/stop signals of IEC 60958 blocks */ |
| 662 | audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF; |
| 663 | |
| 664 | audio_dma.block_size = 0xC0; |
| 665 | audio_dma.mode = HDMI_AUDIO_TRANSF_DMA; |
| 666 | audio_dma.fifo_threshold = 0x20; /* in number of samples */ |
| 667 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 668 | hdmi_wp_audio_config_dma(ip_data, &audio_dma); |
| 669 | hdmi_wp_audio_config_format(ip_data, &audio_format); |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 670 | |
| 671 | /* |
| 672 | * I2S config |
| 673 | */ |
| 674 | core_cfg.i2s_cfg.en_high_bitrate_aud = false; |
| 675 | /* Only used with high bitrate audio */ |
| 676 | core_cfg.i2s_cfg.cbit_order = false; |
| 677 | /* Serial data and word select should change on sck rising edge */ |
| 678 | core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING; |
| 679 | core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM; |
| 680 | /* Set I2S word select polarity */ |
| 681 | core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT; |
| 682 | core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST; |
| 683 | /* Set serial data to word select shift. See Phillips spec. */ |
| 684 | core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT; |
| 685 | /* Enable one of the four available serial data channels */ |
| 686 | core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN; |
| 687 | |
| 688 | /* Core audio config */ |
| 689 | core_cfg.freq_sample = sample_freq; |
| 690 | core_cfg.n = n; |
| 691 | core_cfg.cts = cts; |
| 692 | if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) { |
| 693 | core_cfg.aud_par_busclk = 0; |
| 694 | core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW; |
| 695 | core_cfg.use_mclk = false; |
| 696 | } else { |
| 697 | core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8); |
| 698 | core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW; |
| 699 | core_cfg.use_mclk = true; |
| 700 | core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS; |
| 701 | } |
| 702 | core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH; |
| 703 | core_cfg.en_spdif = false; |
| 704 | /* Use sample frequency from channel status word */ |
| 705 | core_cfg.fs_override = true; |
| 706 | /* Enable ACR packets */ |
| 707 | core_cfg.en_acr_pkt = true; |
| 708 | /* Disable direct streaming digital audio */ |
| 709 | core_cfg.en_dsd_audio = false; |
| 710 | /* Use parallel audio interface */ |
| 711 | core_cfg.en_parallel_aud_input = true; |
| 712 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 713 | hdmi_core_audio_config(ip_data, &core_cfg); |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 714 | |
| 715 | /* |
| 716 | * Configure packet |
| 717 | * info frame audio see doc CEA861-D page 74 |
| 718 | */ |
| 719 | aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM; |
| 720 | aud_if_cfg.db1_channel_count = 2; |
| 721 | aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM; |
| 722 | aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM; |
| 723 | aud_if_cfg.db4_channel_alloc = 0x00; |
| 724 | aud_if_cfg.db5_downmix_inh = false; |
| 725 | aud_if_cfg.db5_lsv = 0; |
| 726 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 727 | hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg); |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 731 | static int hdmi_audio_startup(struct snd_pcm_substream *substream, |
| 732 | struct snd_soc_dai *dai) |
| 733 | { |
| 734 | if (!hdmi.mode) { |
| 735 | pr_err("Current video settings do not support audio.\n"); |
| 736 | return -EIO; |
| 737 | } |
| 738 | return 0; |
| 739 | } |
| 740 | |
Ricardo Neri | b17ce11 | 2011-11-22 20:09:41 -0600 | [diff] [blame] | 741 | static int hdmi_audio_codec_probe(struct snd_soc_codec *codec) |
| 742 | { |
| 743 | struct hdmi_ip_data *priv = &hdmi.ip_data; |
| 744 | |
| 745 | snd_soc_codec_set_drvdata(codec, priv); |
| 746 | return 0; |
| 747 | } |
| 748 | |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 749 | static struct snd_soc_codec_driver hdmi_audio_codec_drv = { |
Ricardo Neri | b17ce11 | 2011-11-22 20:09:41 -0600 | [diff] [blame] | 750 | .probe = hdmi_audio_codec_probe, |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 751 | }; |
| 752 | |
| 753 | static struct snd_soc_dai_ops hdmi_audio_codec_ops = { |
| 754 | .hw_params = hdmi_audio_hw_params, |
| 755 | .trigger = hdmi_audio_trigger, |
| 756 | .startup = hdmi_audio_startup, |
| 757 | }; |
| 758 | |
| 759 | static struct snd_soc_dai_driver hdmi_codec_dai_drv = { |
| 760 | .name = "hdmi-audio-codec", |
| 761 | .playback = { |
| 762 | .channels_min = 2, |
| 763 | .channels_max = 2, |
| 764 | .rates = SNDRV_PCM_RATE_32000 | |
| 765 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, |
| 766 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 767 | SNDRV_PCM_FMTBIT_S24_LE, |
| 768 | }, |
| 769 | .ops = &hdmi_audio_codec_ops, |
| 770 | }; |
Ricardo Neri | 82335c4 | 2011-04-05 16:05:18 -0500 | [diff] [blame] | 771 | #endif |
| 772 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 773 | static int hdmi_get_clocks(struct platform_device *pdev) |
| 774 | { |
| 775 | struct clk *clk; |
| 776 | |
| 777 | clk = clk_get(&pdev->dev, "sys_clk"); |
| 778 | if (IS_ERR(clk)) { |
| 779 | DSSERR("can't get sys_clk\n"); |
| 780 | return PTR_ERR(clk); |
| 781 | } |
| 782 | |
| 783 | hdmi.sys_clk = clk; |
| 784 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | static void hdmi_put_clocks(void) |
| 789 | { |
| 790 | if (hdmi.sys_clk) |
| 791 | clk_put(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 792 | } |
| 793 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 794 | /* HDMI HW IP initialisation */ |
| 795 | static int omapdss_hdmihw_probe(struct platform_device *pdev) |
| 796 | { |
| 797 | struct resource *hdmi_mem; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 798 | int r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 799 | |
| 800 | hdmi.pdata = pdev->dev.platform_data; |
| 801 | hdmi.pdev = pdev; |
| 802 | |
| 803 | mutex_init(&hdmi.lock); |
| 804 | |
| 805 | hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0); |
| 806 | if (!hdmi_mem) { |
| 807 | DSSERR("can't get IORESOURCE_MEM HDMI\n"); |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | |
| 811 | /* Base address taken from platform */ |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 812 | hdmi.ip_data.base_wp = ioremap(hdmi_mem->start, |
| 813 | resource_size(hdmi_mem)); |
| 814 | if (!hdmi.ip_data.base_wp) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 815 | DSSERR("can't ioremap WP\n"); |
| 816 | return -ENOMEM; |
| 817 | } |
| 818 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 819 | r = hdmi_get_clocks(pdev); |
| 820 | if (r) { |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 821 | iounmap(hdmi.ip_data.base_wp); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 822 | return r; |
| 823 | } |
| 824 | |
| 825 | pm_runtime_enable(&pdev->dev); |
| 826 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 827 | hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS; |
| 828 | hdmi.ip_data.core_av_offset = HDMI_CORE_AV; |
| 829 | hdmi.ip_data.pll_offset = HDMI_PLLCTRL; |
| 830 | hdmi.ip_data.phy_offset = HDMI_PHY; |
| 831 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 832 | hdmi_panel_init(); |
| 833 | |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 834 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 835 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
| 836 | |
| 837 | /* Register ASoC codec DAI */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 838 | r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv, |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 839 | &hdmi_codec_dai_drv, 1); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 840 | if (r) { |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 841 | DSSERR("can't register ASoC HDMI audio codec\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 842 | return r; |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 843 | } |
| 844 | #endif |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | static int omapdss_hdmihw_remove(struct platform_device *pdev) |
| 849 | { |
| 850 | hdmi_panel_exit(); |
| 851 | |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 852 | #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ |
| 853 | defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) |
| 854 | snd_soc_unregister_codec(&pdev->dev); |
| 855 | #endif |
| 856 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 857 | pm_runtime_disable(&pdev->dev); |
| 858 | |
| 859 | hdmi_put_clocks(); |
| 860 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 861 | iounmap(hdmi.ip_data.base_wp); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 866 | static int hdmi_runtime_suspend(struct device *dev) |
| 867 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 868 | clk_disable(hdmi.sys_clk); |
| 869 | |
| 870 | dispc_runtime_put(); |
| 871 | dss_runtime_put(); |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | static int hdmi_runtime_resume(struct device *dev) |
| 877 | { |
| 878 | int r; |
| 879 | |
| 880 | r = dss_runtime_get(); |
| 881 | if (r < 0) |
| 882 | goto err_get_dss; |
| 883 | |
| 884 | r = dispc_runtime_get(); |
| 885 | if (r < 0) |
| 886 | goto err_get_dispc; |
| 887 | |
| 888 | |
| 889 | clk_enable(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 890 | |
| 891 | return 0; |
| 892 | |
| 893 | err_get_dispc: |
| 894 | dss_runtime_put(); |
| 895 | err_get_dss: |
| 896 | return r; |
| 897 | } |
| 898 | |
| 899 | static const struct dev_pm_ops hdmi_pm_ops = { |
| 900 | .runtime_suspend = hdmi_runtime_suspend, |
| 901 | .runtime_resume = hdmi_runtime_resume, |
| 902 | }; |
| 903 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 904 | static struct platform_driver omapdss_hdmihw_driver = { |
| 905 | .probe = omapdss_hdmihw_probe, |
| 906 | .remove = omapdss_hdmihw_remove, |
| 907 | .driver = { |
| 908 | .name = "omapdss_hdmi", |
| 909 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 910 | .pm = &hdmi_pm_ops, |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 911 | }, |
| 912 | }; |
| 913 | |
| 914 | int hdmi_init_platform_driver(void) |
| 915 | { |
| 916 | return platform_driver_register(&omapdss_hdmihw_driver); |
| 917 | } |
| 918 | |
| 919 | void hdmi_uninit_platform_driver(void) |
| 920 | { |
| 921 | return platform_driver_unregister(&omapdss_hdmihw_driver); |
| 922 | } |