Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 1 | /* |
| 2 | * HDMI wrapper |
| 3 | * |
| 4 | * Copyright (C) 2013 Texas Instruments Incorporated |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
| 9 | */ |
| 10 | |
Tomi Valkeinen | ac9f242 | 2013-11-14 13:46:32 +0200 | [diff] [blame^] | 11 | #define DSS_SUBSYS_NAME "HDMIWP" |
| 12 | |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 14 | #include <linux/err.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <video/omapdss.h> |
| 18 | |
| 19 | #include "dss.h" |
Archit Taneja | ef26958 | 2013-09-12 17:45:57 +0530 | [diff] [blame] | 20 | #include "hdmi.h" |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 21 | |
| 22 | void hdmi_wp_dump(struct hdmi_wp_data *wp, struct seq_file *s) |
| 23 | { |
| 24 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, hdmi_read_reg(wp->base, r)) |
| 25 | |
| 26 | DUMPREG(HDMI_WP_REVISION); |
| 27 | DUMPREG(HDMI_WP_SYSCONFIG); |
| 28 | DUMPREG(HDMI_WP_IRQSTATUS_RAW); |
| 29 | DUMPREG(HDMI_WP_IRQSTATUS); |
| 30 | DUMPREG(HDMI_WP_IRQENABLE_SET); |
| 31 | DUMPREG(HDMI_WP_IRQENABLE_CLR); |
| 32 | DUMPREG(HDMI_WP_IRQWAKEEN); |
| 33 | DUMPREG(HDMI_WP_PWR_CTRL); |
| 34 | DUMPREG(HDMI_WP_DEBOUNCE); |
| 35 | DUMPREG(HDMI_WP_VIDEO_CFG); |
| 36 | DUMPREG(HDMI_WP_VIDEO_SIZE); |
| 37 | DUMPREG(HDMI_WP_VIDEO_TIMING_H); |
| 38 | DUMPREG(HDMI_WP_VIDEO_TIMING_V); |
| 39 | DUMPREG(HDMI_WP_WP_CLK); |
| 40 | DUMPREG(HDMI_WP_AUDIO_CFG); |
| 41 | DUMPREG(HDMI_WP_AUDIO_CFG2); |
| 42 | DUMPREG(HDMI_WP_AUDIO_CTRL); |
| 43 | DUMPREG(HDMI_WP_AUDIO_DATA); |
| 44 | } |
| 45 | |
| 46 | u32 hdmi_wp_get_irqstatus(struct hdmi_wp_data *wp) |
| 47 | { |
| 48 | return hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS); |
| 49 | } |
| 50 | |
| 51 | void hdmi_wp_set_irqstatus(struct hdmi_wp_data *wp, u32 irqstatus) |
| 52 | { |
| 53 | hdmi_write_reg(wp->base, HDMI_WP_IRQSTATUS, irqstatus); |
| 54 | /* flush posted write */ |
| 55 | hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS); |
| 56 | } |
| 57 | |
| 58 | void hdmi_wp_set_irqenable(struct hdmi_wp_data *wp, u32 mask) |
| 59 | { |
| 60 | hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_SET, mask); |
| 61 | } |
| 62 | |
| 63 | void hdmi_wp_clear_irqenable(struct hdmi_wp_data *wp, u32 mask) |
| 64 | { |
| 65 | hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_CLR, mask); |
| 66 | } |
| 67 | |
| 68 | /* PHY_PWR_CMD */ |
| 69 | int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val) |
| 70 | { |
| 71 | /* Return if already the state */ |
| 72 | if (REG_GET(wp->base, HDMI_WP_PWR_CTRL, 5, 4) == val) |
| 73 | return 0; |
| 74 | |
| 75 | /* Command for power control of HDMI PHY */ |
| 76 | REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 7, 6); |
| 77 | |
| 78 | /* Status of the power control of HDMI PHY */ |
| 79 | if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 5, 4, val) |
| 80 | != val) { |
Tomi Valkeinen | ac9f242 | 2013-11-14 13:46:32 +0200 | [diff] [blame^] | 81 | DSSERR("Failed to set PHY power mode to %d\n", val); |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 82 | return -ETIMEDOUT; |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /* PLL_PWR_CMD */ |
| 89 | int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val) |
| 90 | { |
| 91 | /* Command for power control of HDMI PLL */ |
| 92 | REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 3, 2); |
| 93 | |
| 94 | /* wait till PHY_PWR_STATUS is set */ |
| 95 | if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 1, 0, val) |
| 96 | != val) { |
Tomi Valkeinen | ac9f242 | 2013-11-14 13:46:32 +0200 | [diff] [blame^] | 97 | DSSERR("Failed to set PLL_PWR_STATUS\n"); |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 98 | return -ETIMEDOUT; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | int hdmi_wp_video_start(struct hdmi_wp_data *wp) |
| 105 | { |
| 106 | REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, true, 31, 31); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | void hdmi_wp_video_stop(struct hdmi_wp_data *wp) |
| 112 | { |
| 113 | REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, false, 31, 31); |
| 114 | } |
| 115 | |
| 116 | void hdmi_wp_video_config_format(struct hdmi_wp_data *wp, |
| 117 | struct hdmi_video_format *video_fmt) |
| 118 | { |
| 119 | u32 l = 0; |
| 120 | |
| 121 | REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, video_fmt->packing_mode, |
| 122 | 10, 8); |
| 123 | |
| 124 | l |= FLD_VAL(video_fmt->y_res, 31, 16); |
| 125 | l |= FLD_VAL(video_fmt->x_res, 15, 0); |
| 126 | hdmi_write_reg(wp->base, HDMI_WP_VIDEO_SIZE, l); |
| 127 | } |
| 128 | |
| 129 | void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp, |
| 130 | struct omap_video_timings *timings) |
| 131 | { |
| 132 | u32 r; |
| 133 | bool vsync_pol, hsync_pol; |
Tomi Valkeinen | ac9f242 | 2013-11-14 13:46:32 +0200 | [diff] [blame^] | 134 | DSSDBG("Enter hdmi_wp_video_config_interface\n"); |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 135 | |
| 136 | vsync_pol = timings->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH; |
| 137 | hsync_pol = timings->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH; |
| 138 | |
| 139 | r = hdmi_read_reg(wp->base, HDMI_WP_VIDEO_CFG); |
| 140 | r = FLD_MOD(r, vsync_pol, 7, 7); |
| 141 | r = FLD_MOD(r, hsync_pol, 6, 6); |
| 142 | r = FLD_MOD(r, timings->interlace, 3, 3); |
| 143 | r = FLD_MOD(r, 1, 1, 0); /* HDMI_TIMING_MASTER_24BIT */ |
| 144 | hdmi_write_reg(wp->base, HDMI_WP_VIDEO_CFG, r); |
| 145 | } |
| 146 | |
| 147 | void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp, |
| 148 | struct omap_video_timings *timings) |
| 149 | { |
| 150 | u32 timing_h = 0; |
| 151 | u32 timing_v = 0; |
| 152 | |
Tomi Valkeinen | ac9f242 | 2013-11-14 13:46:32 +0200 | [diff] [blame^] | 153 | DSSDBG("Enter hdmi_wp_video_config_timing\n"); |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 154 | |
| 155 | timing_h |= FLD_VAL(timings->hbp, 31, 20); |
| 156 | timing_h |= FLD_VAL(timings->hfp, 19, 8); |
| 157 | timing_h |= FLD_VAL(timings->hsw, 7, 0); |
| 158 | hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_H, timing_h); |
| 159 | |
| 160 | timing_v |= FLD_VAL(timings->vbp, 31, 20); |
| 161 | timing_v |= FLD_VAL(timings->vfp, 19, 8); |
| 162 | timing_v |= FLD_VAL(timings->vsw, 7, 0); |
| 163 | hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_V, timing_v); |
| 164 | } |
| 165 | |
| 166 | void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt, |
| 167 | struct omap_video_timings *timings, struct hdmi_config *param) |
| 168 | { |
Tomi Valkeinen | ac9f242 | 2013-11-14 13:46:32 +0200 | [diff] [blame^] | 169 | DSSDBG("Enter hdmi_wp_video_init_format\n"); |
Archit Taneja | f382d9e | 2013-08-06 14:56:55 +0530 | [diff] [blame] | 170 | |
| 171 | video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444; |
| 172 | video_fmt->y_res = param->timings.y_res; |
| 173 | video_fmt->x_res = param->timings.x_res; |
| 174 | |
| 175 | timings->hbp = param->timings.hbp; |
| 176 | timings->hfp = param->timings.hfp; |
| 177 | timings->hsw = param->timings.hsw; |
| 178 | timings->vbp = param->timings.vbp; |
| 179 | timings->vfp = param->timings.vfp; |
| 180 | timings->vsw = param->timings.vsw; |
| 181 | timings->vsync_level = param->timings.vsync_level; |
| 182 | timings->hsync_level = param->timings.hsync_level; |
| 183 | timings->interlace = param->timings.interlace; |
| 184 | } |
| 185 | |
| 186 | #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) |
| 187 | void hdmi_wp_audio_config_format(struct hdmi_wp_data *wp, |
| 188 | struct hdmi_audio_format *aud_fmt) |
| 189 | { |
| 190 | u32 r; |
| 191 | |
| 192 | DSSDBG("Enter hdmi_wp_audio_config_format\n"); |
| 193 | |
| 194 | r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG); |
| 195 | r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24); |
| 196 | r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16); |
| 197 | r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5); |
| 198 | r = FLD_MOD(r, aud_fmt->type, 4, 4); |
| 199 | r = FLD_MOD(r, aud_fmt->justification, 3, 3); |
| 200 | r = FLD_MOD(r, aud_fmt->sample_order, 2, 2); |
| 201 | r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1); |
| 202 | r = FLD_MOD(r, aud_fmt->sample_size, 0, 0); |
| 203 | hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG, r); |
| 204 | } |
| 205 | |
| 206 | void hdmi_wp_audio_config_dma(struct hdmi_wp_data *wp, |
| 207 | struct hdmi_audio_dma *aud_dma) |
| 208 | { |
| 209 | u32 r; |
| 210 | |
| 211 | DSSDBG("Enter hdmi_wp_audio_config_dma\n"); |
| 212 | |
| 213 | r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG2); |
| 214 | r = FLD_MOD(r, aud_dma->transfer_size, 15, 8); |
| 215 | r = FLD_MOD(r, aud_dma->block_size, 7, 0); |
| 216 | hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG2, r); |
| 217 | |
| 218 | r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CTRL); |
| 219 | r = FLD_MOD(r, aud_dma->mode, 9, 9); |
| 220 | r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0); |
| 221 | hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CTRL, r); |
| 222 | } |
| 223 | |
| 224 | int hdmi_wp_audio_enable(struct hdmi_wp_data *wp, bool enable) |
| 225 | { |
| 226 | REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 31, 31); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | int hdmi_wp_audio_core_req_enable(struct hdmi_wp_data *wp, bool enable) |
| 232 | { |
| 233 | REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 30, 30); |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | #endif |
| 238 | |
| 239 | #define WP_SIZE 0x200 |
| 240 | |
| 241 | int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp) |
| 242 | { |
| 243 | struct resource *res; |
| 244 | struct resource temp_res; |
| 245 | |
| 246 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hdmi_wp"); |
| 247 | if (!res) { |
| 248 | DSSDBG("can't get WP mem resource by name\n"); |
| 249 | /* |
| 250 | * if hwmod/DT doesn't have the memory resource information |
| 251 | * split into HDMI sub blocks by name, we try again by getting |
| 252 | * the platform's first resource. this code will be removed when |
| 253 | * the driver can get the mem resources by name |
| 254 | */ |
| 255 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 256 | if (!res) { |
| 257 | DSSERR("can't get WP mem resource\n"); |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
| 261 | temp_res.start = res->start; |
| 262 | temp_res.end = temp_res.start + WP_SIZE - 1; |
| 263 | res = &temp_res; |
| 264 | } |
| 265 | |
| 266 | wp->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 267 | if (!wp->base) { |
| 268 | DSSERR("can't ioremap HDMI WP\n"); |
| 269 | return -ENOMEM; |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | } |