16011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/* 26011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * SH-Mobile High-Definition Multimedia Interface (HDMI) driver 36011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * for SLISHDMI13T and SLIPHDMIT IP cores 46011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * 56011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de> 66011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * 76011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * This program is free software; you can redistribute it and/or modify 86011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * it under the terms of the GNU General Public License version 2 as 96011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * published by the Free Software Foundation. 106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 116011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 126011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/clk.h> 136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/console.h> 146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/delay.h> 156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/err.h> 166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/init.h> 176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/interrupt.h> 186011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/io.h> 196011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/module.h> 206011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/platform_device.h> 216011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/pm_runtime.h> 226011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/slab.h> 236011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/types.h> 246011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <linux/workqueue.h> 25644a98453d5764f467b73f2e02df0d2688da1873Kuninori Morimoto#include <sound/soc.h> 261d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto#include <sound/soc-dapm.h> 271d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto#include <sound/initval.h> 286011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <video/sh_mobile_hdmi.h> 306011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#include <video/sh_mobile_lcdc.h> 316011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 326de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski#include "sh_mobile_lcdcfb.h" 336de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski 34c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto/* HDMI Core Control Register (HTOP0) */ 356011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SYSTEM_CTRL 0x00 /* System control */ 366011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_L_R_DATA_SWAP_CTRL_RPKT 0x01 /* L/R data swap control, 376011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski bits 19..16 of 20-bit N for Audio Clock Regeneration packet */ 386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_20_BIT_N_FOR_AUDIO_RPKT_15_8 0x02 /* bits 15..8 of 20-bit N for Audio Clock Regeneration packet */ 396011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_20_BIT_N_FOR_AUDIO_RPKT_7_0 0x03 /* bits 7..0 of 20-bit N for Audio Clock Regeneration packet */ 406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SPDIF_AUDIO_SAMP_FREQ_CTS 0x04 /* SPDIF audio sampling frequency, 416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski bits 19..16 of Internal CTS */ 426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERNAL_CTS_15_8 0x05 /* bits 15..8 of Internal CTS */ 436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERNAL_CTS_7_0 0x06 /* bits 7..0 of Internal CTS */ 446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_CTS_19_16 0x07 /* External CTS */ 456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_CTS_15_8 0x08 /* External CTS */ 466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_CTS_7_0 0x09 /* External CTS */ 476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUDIO_SETTING_1 0x0A /* Audio setting.1 */ 486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUDIO_SETTING_2 0x0B /* Audio setting.2 */ 496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_I2S_AUDIO_SET 0x0C /* I2S audio setting */ 506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DSD_AUDIO_SET 0x0D /* DSD audio setting */ 516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DEBUG_MONITOR_1 0x0E /* Debug monitor.1 */ 526011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DEBUG_MONITOR_2 0x0F /* Debug monitor.2 */ 536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_I2S_INPUT_PIN_SWAP 0x10 /* I2S input pin swap */ 546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUDIO_STATUS_BITS_SETTING_1 0x11 /* Audio status bits setting.1 */ 556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUDIO_STATUS_BITS_SETTING_2 0x12 /* Audio status bits setting.2 */ 566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CATEGORY_CODE 0x13 /* Category code */ 576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SOURCE_NUM_AUDIO_WORD_LEN 0x14 /* Source number/Audio word length */ 586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUDIO_VIDEO_SETTING_1 0x15 /* Audio/Video setting.1 */ 596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_VIDEO_SETTING_1 0x16 /* Video setting.1 */ 606011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DEEP_COLOR_MODES 0x17 /* Deep Color Modes */ 616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 626011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/* 12 16- and 10-bit Color space conversion parameters: 0x18..0x2f */ 636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_COLOR_SPACE_CONVERSION_PARAMETERS 0x18 646011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS 0x30 /* External video parameter settings */ 666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_TOTAL_7_0 0x31 /* External horizontal total (LSB) */ 676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_TOTAL_11_8 0x32 /* External horizontal total (MSB) */ 686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_BLANK_7_0 0x33 /* External horizontal blank (LSB) */ 696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_BLANK_9_8 0x34 /* External horizontal blank (MSB) */ 706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_DELAY_7_0 0x35 /* External horizontal delay (LSB) */ 716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_DELAY_9_8 0x36 /* External horizontal delay (MSB) */ 726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_DURATION_7_0 0x37 /* External horizontal duration (LSB) */ 736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_H_DURATION_9_8 0x38 /* External horizontal duration (MSB) */ 746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_V_TOTAL_7_0 0x39 /* External vertical total (LSB) */ 756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_V_TOTAL_9_8 0x3A /* External vertical total (MSB) */ 766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUDIO_VIDEO_SETTING_2 0x3B /* Audio/Video setting.2 */ 776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_V_BLANK 0x3D /* External vertical blank */ 786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_V_DELAY 0x3E /* External vertical delay */ 796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EXTERNAL_V_DURATION 0x3F /* External vertical duration */ 806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_MANUAL_SEND_CONTROL 0x40 /* Control packet manual send control */ 816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_AUTO_SEND 0x41 /* Control packet auto send with VSYNC control */ 826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AUTO_CHECKSUM_OPTION 0x42 /* Auto checksum option */ 836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_VIDEO_SETTING_2 0x45 /* Video setting.2 */ 846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_OUTPUT_OPTION 0x46 /* Output option */ 856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_OPTION 0x51 /* SLIPHDMIT parameter option */ 866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HSYNC_PMENT_AT_EMB_7_0 0x52 /* HSYNC placement at embedded sync (LSB) */ 876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HSYNC_PMENT_AT_EMB_15_8 0x53 /* HSYNC placement at embedded sync (MSB) */ 886011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_VSYNC_PMENT_AT_EMB_7_0 0x54 /* VSYNC placement at embedded sync (LSB) */ 896011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_VSYNC_PMENT_AT_EMB_14_8 0x55 /* VSYNC placement at embedded sync (MSB) */ 906011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_1 0x56 /* SLIPHDMIT parameter settings.1 */ 916011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_2 0x57 /* SLIPHDMIT parameter settings.2 */ 926011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_3 0x58 /* SLIPHDMIT parameter settings.3 */ 936011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_5 0x59 /* SLIPHDMIT parameter settings.5 */ 946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_6 0x5A /* SLIPHDMIT parameter settings.6 */ 956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_7 0x5B /* SLIPHDMIT parameter settings.7 */ 966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_8 0x5C /* SLIPHDMIT parameter settings.8 */ 976011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_9 0x5D /* SLIPHDMIT parameter settings.9 */ 986011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SLIPHDMIT_PARAM_SETTINGS_10 0x5E /* SLIPHDMIT parameter settings.10 */ 996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_INDEX 0x5F /* Control packet buffer index */ 1006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_HB0 0x60 /* Control packet data buffer access window - HB0 */ 1016011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_HB1 0x61 /* Control packet data buffer access window - HB1 */ 1026011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_HB2 0x62 /* Control packet data buffer access window - HB2 */ 1036011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB0 0x63 /* Control packet data buffer access window - PB0 */ 1046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB1 0x64 /* Control packet data buffer access window - PB1 */ 1056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB2 0x65 /* Control packet data buffer access window - PB2 */ 1066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB3 0x66 /* Control packet data buffer access window - PB3 */ 1076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB4 0x67 /* Control packet data buffer access window - PB4 */ 1086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB5 0x68 /* Control packet data buffer access window - PB5 */ 1096011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB6 0x69 /* Control packet data buffer access window - PB6 */ 1106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB7 0x6A /* Control packet data buffer access window - PB7 */ 1116011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB8 0x6B /* Control packet data buffer access window - PB8 */ 1126011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB9 0x6C /* Control packet data buffer access window - PB9 */ 1136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB10 0x6D /* Control packet data buffer access window - PB10 */ 1146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB11 0x6E /* Control packet data buffer access window - PB11 */ 1156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB12 0x6F /* Control packet data buffer access window - PB12 */ 1166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB13 0x70 /* Control packet data buffer access window - PB13 */ 1176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB14 0x71 /* Control packet data buffer access window - PB14 */ 1186011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB15 0x72 /* Control packet data buffer access window - PB15 */ 1196011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB16 0x73 /* Control packet data buffer access window - PB16 */ 1206011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB17 0x74 /* Control packet data buffer access window - PB17 */ 1216011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB18 0x75 /* Control packet data buffer access window - PB18 */ 1226011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB19 0x76 /* Control packet data buffer access window - PB19 */ 1236011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB20 0x77 /* Control packet data buffer access window - PB20 */ 1246011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB21 0x78 /* Control packet data buffer access window - PB21 */ 1256011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB22 0x79 /* Control packet data buffer access window - PB22 */ 1266011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB23 0x7A /* Control packet data buffer access window - PB23 */ 1276011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB24 0x7B /* Control packet data buffer access window - PB24 */ 1286011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB25 0x7C /* Control packet data buffer access window - PB25 */ 1296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB26 0x7D /* Control packet data buffer access window - PB26 */ 1306011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_CTRL_PKT_BUF_ACCESS_PB27 0x7E /* Control packet data buffer access window - PB27 */ 1316011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EDID_KSV_FIFO_ACCESS_WINDOW 0x80 /* EDID/KSV FIFO access window */ 1326011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DDC_BUS_ACCESS_FREQ_CTRL_7_0 0x81 /* DDC bus access frequency control (LSB) */ 1336011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DDC_BUS_ACCESS_FREQ_CTRL_15_8 0x82 /* DDC bus access frequency control (MSB) */ 1346011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_MASK_1 0x92 /* Interrupt mask.1 */ 1356011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_MASK_2 0x93 /* Interrupt mask.2 */ 1366011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_STATUS_1 0x94 /* Interrupt status.1 */ 1376011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_STATUS_2 0x95 /* Interrupt status.2 */ 1386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_MASK_3 0x96 /* Interrupt mask.3 */ 1396011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_MASK_4 0x97 /* Interrupt mask.4 */ 1406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_STATUS_3 0x98 /* Interrupt status.3 */ 1416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_INTERRUPT_STATUS_4 0x99 /* Interrupt status.4 */ 1426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SOFTWARE_HDCP_CONTROL_1 0x9A /* Software HDCP control.1 */ 1436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_FRAME_COUNTER 0x9C /* Frame counter */ 1446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_FRAME_COUNTER_FOR_RI_CHECK 0x9D /* Frame counter for Ri check */ 1456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_CONTROL 0xAF /* HDCP control */ 1466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_RI_FRAME_COUNT_REGISTER 0xB2 /* Ri frame count register */ 1476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_DDC_BUS_CONTROL 0xB7 /* DDC bus control */ 1486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_STATUS 0xB8 /* HDCP status */ 1496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SHA0 0xB9 /* sha0 */ 1506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SHA1 0xBA /* sha1 */ 1516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SHA2 0xBB /* sha2 */ 1526011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SHA3 0xBC /* sha3 */ 1536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SHA4 0xBD /* sha4 */ 1546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BCAPS_READ 0xBE /* BCAPS read / debug */ 1556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AKSV_BKSV_7_0_MONITOR 0xBF /* AKSV/BKSV[7:0] monitor */ 1566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AKSV_BKSV_15_8_MONITOR 0xC0 /* AKSV/BKSV[15:8] monitor */ 1576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AKSV_BKSV_23_16_MONITOR 0xC1 /* AKSV/BKSV[23:16] monitor */ 1586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AKSV_BKSV_31_24_MONITOR 0xC2 /* AKSV/BKSV[31:24] monitor */ 1596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AKSV_BKSV_39_32_MONITOR 0xC3 /* AKSV/BKSV[39:32] monitor */ 1606011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EDID_SEGMENT_POINTER 0xC4 /* EDID segment pointer */ 1616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EDID_WORD_ADDRESS 0xC5 /* EDID word address */ 1626011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_EDID_DATA_FIFO_ADDRESS 0xC6 /* EDID data FIFO address */ 1636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_NUM_OF_HDMI_DEVICES 0xC7 /* Number of HDMI devices */ 1646011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_ERROR_CODE 0xC8 /* HDCP error code */ 1656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_100MS_TIMER_SET 0xC9 /* 100ms timer setting */ 1666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_5SEC_TIMER_SET 0xCA /* 5sec timer setting */ 1676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_RI_READ_COUNT 0xCB /* Ri read count */ 1686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_SEED 0xCC /* An seed */ 1696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_MAX_NUM_OF_RCIVRS_ALLOWED 0xCD /* Maximum number of receivers allowed */ 1706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_MEMORY_ACCESS_CONTROL_1 0xCE /* HDCP memory access control.1 */ 1716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_MEMORY_ACCESS_CONTROL_2 0xCF /* HDCP memory access control.2 */ 1726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_CONTROL_2 0xD0 /* HDCP Control 2 */ 1736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HDCP_KEY_MEMORY_CONTROL 0xD2 /* HDCP Key Memory Control */ 1746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_COLOR_SPACE_CONV_CONFIG_1 0xD3 /* Color space conversion configuration.1 */ 1756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_VIDEO_SETTING_3 0xD4 /* Video setting.3 */ 1766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_RI_7_0 0xD5 /* Ri[7:0] */ 1776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_RI_15_8 0xD6 /* Ri[15:8] */ 1786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_PJ 0xD7 /* Pj */ 1796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_SHA_RD 0xD8 /* sha_rd */ 1806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_RI_7_0_SAVED 0xD9 /* Ri[7:0] saved */ 1816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_RI_15_8_SAVED 0xDA /* Ri[15:8] saved */ 1826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_PJ_SAVED 0xDB /* Pj saved */ 1836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_NUM_OF_DEVICES 0xDC /* Number of devices */ 1846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_HOT_PLUG_MSENS_STATUS 0xDF /* Hot plug/MSENS status */ 1856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BCAPS_WRITE 0xE0 /* bcaps */ 1866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BSTAT_7_0 0xE1 /* bstat[7:0] */ 1876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BSTAT_15_8 0xE2 /* bstat[15:8] */ 1886011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BKSV_7_0 0xE3 /* bksv[7:0] */ 1896011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BKSV_15_8 0xE4 /* bksv[15:8] */ 1906011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BKSV_23_16 0xE5 /* bksv[23:16] */ 1916011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BKSV_31_24 0xE6 /* bksv[31:24] */ 1926011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_BKSV_39_32 0xE7 /* bksv[39:32] */ 1936011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_7_0 0xE8 /* An[7:0] */ 1946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_15_8 0xE9 /* An [15:8] */ 1956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_23_16 0xEA /* An [23:16] */ 1966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_31_24 0xEB /* An [31:24] */ 1976011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_39_32 0xEC /* An [39:32] */ 1986011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_47_40 0xED /* An [47:40] */ 1996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_55_48 0xEE /* An [55:48] */ 2006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_AN_63_56 0xEF /* An [63:56] */ 2016011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_PRODUCT_ID 0xF0 /* Product ID */ 2026011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_REVISION_ID 0xF1 /* Revision ID */ 2036011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#define HDMI_TEST_MODE 0xFE /* Test mode */ 2046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 205c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto/* HDMI Control Register (HTOP1) */ 206c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_TEST_MODE 0x0000 /* Test mode */ 207c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_VIDEO_INPUT 0x0008 /* VideoInput */ 208c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_CORE_RSTN 0x000C /* CoreResetn */ 209c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_PLLBW 0x0018 /* PLLBW */ 210c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_CLK_TO_PHY 0x001C /* Clk to Phy */ 211c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_VIDEO_INPUT2 0x0020 /* VideoInput2 */ 212c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_TISEMP0_1 0x0024 /* tisemp0-1 */ 213c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_TISEMP2_C 0x0028 /* tisemp2-c */ 214c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_TISIDRV 0x002C /* tisidrv */ 215c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_TISEN 0x0034 /* tisen */ 216c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_TISDREN 0x0038 /* tisdren */ 217c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_CISRANGE 0x003C /* cisrange */ 218c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_ENABLE_SELECTOR 0x0040 /* Enable Selector */ 219c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_MACRO_RESET 0x0044 /* Macro reset */ 220c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_PLL_CALIBRATION 0x0048 /* PLL calibration */ 221c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_RE_CALIBRATION 0x004C /* Re-calibration */ 222c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_CURRENT 0x0050 /* Current */ 223c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_PLL_LOCK_DETECT 0x0054 /* PLL lock detect */ 224c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_PHY_TEST_MODE 0x0058 /* PHY Test Mode */ 225c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_CLK_SET 0x0080 /* Clock Set */ 226c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_DDC_FAIL_SAFE 0x0084 /* DDC fail safe */ 227c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_PRBS 0x0088 /* PRBS */ 228c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_EDID_AINC_CONTROL 0x008C /* EDID ainc Control */ 229c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_MODE 0x00FC /* Deep Coloer Mode */ 230c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF0 0x0100 /* Deep Color:FRC COEF0 */ 231c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF1 0x0104 /* Deep Color:FRC COEF1 */ 232c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF2 0x0108 /* Deep Color:FRC COEF2 */ 233c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF3 0x010C /* Deep Color:FRC COEF3 */ 234c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF0_C 0x0110 /* Deep Color:FRC COEF0C */ 235c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF1_C 0x0114 /* Deep Color:FRC COEF1C */ 236c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF2_C 0x0118 /* Deep Color:FRC COEF2C */ 237c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_COEF3_C 0x011C /* Deep Color:FRC COEF3C */ 238c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FRC_MODE 0x0120 /* Deep Color:FRC Mode */ 239c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_START1 0x0124 /* Deep Color:Rect Start1 */ 240c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE1 0x0128 /* Deep Color:Rect Size1 */ 241c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_START2 0x012C /* Deep Color:Rect Start2 */ 242c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE2 0x0130 /* Deep Color:Rect Size2 */ 243c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_START3 0x0134 /* Deep Color:Rect Start3 */ 244c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE3 0x0138 /* Deep Color:Rect Size3 */ 245c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_START4 0x013C /* Deep Color:Rect Start4 */ 246c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE4 0x0140 /* Deep Color:Rect Size4 */ 247c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_1 0x0144 /* Deep Color:Fil Para Y1_1 */ 248c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_2 0x0148 /* Deep Color:Fil Para Y1_2 */ 249c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_1 0x014C /* Deep Color:Fil Para CB1_1 */ 250c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_2 0x0150 /* Deep Color:Fil Para CB1_2 */ 251c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_1 0x0154 /* Deep Color:Fil Para CR1_1 */ 252c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_2 0x0158 /* Deep Color:Fil Para CR1_2 */ 253c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_1 0x015C /* Deep Color:Fil Para Y2_1 */ 254c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_2 0x0160 /* Deep Color:Fil Para Y2_2 */ 255c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_1 0x0164 /* Deep Color:Fil Para CB2_1 */ 256c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_2 0x0168 /* Deep Color:Fil Para CB2_2 */ 257c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_1 0x016C /* Deep Color:Fil Para CR2_1 */ 258c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_2 0x0170 /* Deep Color:Fil Para CR2_2 */ 259c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_COR_PARA_Y1 0x0174 /* Deep Color:Cor Para Y1 */ 260c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CB1 0x0178 /* Deep Color:Cor Para CB1 */ 261c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CR1 0x017C /* Deep Color:Cor Para CR1 */ 262c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_COR_PARA_Y2 0x0180 /* Deep Color:Cor Para Y2 */ 263c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CB2 0x0184 /* Deep Color:Cor Para CB2 */ 264c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CR2 0x0188 /* Deep Color:Cor Para CR2 */ 265c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto#define HDMI_HTOP1_EDID_DATA_READ 0x0200 /* EDID Data Read 128Byte:0x03FC */ 266c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto 2676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskienum hotplug_state { 2686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski HDMI_HOTPLUG_DISCONNECTED, 2696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski HDMI_HOTPLUG_CONNECTED, 2706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski HDMI_HOTPLUG_EDID_DONE, 2716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski}; 2726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 2736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistruct sh_hdmi { 2748511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart struct sh_mobile_lcdc_entity entity; 2758511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart 2766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski void __iomem *base; 277c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto void __iomem *htop1; 2786aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski enum hotplug_state hp_state; /* hot-plug status */ 2790ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski u8 preprogrammed_vic; /* use a pre-programmed VIC or 2800ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski the external mode */ 2814232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski u8 edid_block_addr; 2824232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski u8 edid_segment_nr; 2834232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski u8 edid_blocks; 284a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven int irq; 2856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct clk *hdmi_clk; 2866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct device *dev; 2876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct delayed_work edid_work; 288e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart struct fb_videomode mode; 289afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski struct fb_monspecs monspec; 290db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto 291db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto /* register access functions */ 292db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto void (*write)(struct sh_hdmi *hdmi, u8 data, u8 reg); 293db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto u8 (*read)(struct sh_hdmi *hdmi, u8 reg); 2946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski}; 2956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 2968511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart#define entity_to_sh_hdmi(e) container_of(e, struct sh_hdmi, entity) 29712ee2502c0503c484a7df052d356e39c40b02400Laurent Pinchart 298db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimotostatic void __hdmi_write8(struct sh_hdmi *hdmi, u8 data, u8 reg) 2996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 3006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski iowrite8(data, hdmi->base + reg); 3016011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 3026011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 303db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimotostatic u8 __hdmi_read8(struct sh_hdmi *hdmi, u8 reg) 3046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 3056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return ioread8(hdmi->base + reg); 3066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 3076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 308db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimotostatic void __hdmi_write32(struct sh_hdmi *hdmi, u8 data, u8 reg) 309db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto{ 310db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto iowrite32((u32)data, hdmi->base + (reg * 4)); 311db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto udelay(100); 312db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto} 313db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto 314db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimotostatic u8 __hdmi_read32(struct sh_hdmi *hdmi, u8 reg) 315db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto{ 316db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto return (u8)ioread32(hdmi->base + (reg * 4)); 317db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto} 318db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto 319db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimotostatic void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg) 320db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto{ 321db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto hdmi->write(hdmi, data, reg); 322db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto} 323db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto 324db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimotostatic u8 hdmi_read(struct sh_hdmi *hdmi, u8 reg) 325db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto{ 326db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto return hdmi->read(hdmi, reg); 327db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto} 328db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto 3293f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimotostatic void hdmi_bit_set(struct sh_hdmi *hdmi, u8 mask, u8 data, u8 reg) 3303f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto{ 3313f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto u8 val = hdmi_read(hdmi, reg); 3323f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto 3333f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto val &= ~mask; 3343f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto val |= (data & mask); 3353f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto 3363f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_write(hdmi, val, reg); 3373f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto} 3383f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto 339c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimotostatic void hdmi_htop1_write(struct sh_hdmi *hdmi, u32 data, u32 reg) 340c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto{ 341c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto iowrite32(data, hdmi->htop1 + reg); 342c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto udelay(100); 343c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto} 344c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto 345c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimotostatic u32 hdmi_htop1_read(struct sh_hdmi *hdmi, u32 reg) 346c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto{ 347c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto return ioread32(hdmi->htop1 + reg); 348c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto} 349c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto 350f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto/* 351f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto * HDMI sound 352f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto */ 3531d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimotostatic unsigned int sh_hdmi_snd_read(struct snd_soc_codec *codec, 3541d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto unsigned int reg) 3551d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto{ 3561d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto struct sh_hdmi *hdmi = snd_soc_codec_get_drvdata(codec); 3571d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3581d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto return hdmi_read(hdmi, reg); 3591d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto} 3601d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3611d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimotostatic int sh_hdmi_snd_write(struct snd_soc_codec *codec, 3621d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto unsigned int reg, 3631d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto unsigned int value) 3641d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto{ 3651d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto struct sh_hdmi *hdmi = snd_soc_codec_get_drvdata(codec); 3661d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3671d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto hdmi_write(hdmi, value, reg); 3681d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto return 0; 3691d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto} 3701d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3711d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimotostatic struct snd_soc_dai_driver sh_hdmi_dai = { 3721d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .name = "sh_mobile_hdmi-hifi", 3731d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .playback = { 3741d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .stream_name = "Playback", 37517731f8dffe7dc6fd0eb82018505a74907431699Kuninori Morimoto .channels_min = 2, 37617731f8dffe7dc6fd0eb82018505a74907431699Kuninori Morimoto .channels_max = 8, 37717731f8dffe7dc6fd0eb82018505a74907431699Kuninori Morimoto .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | 37817731f8dffe7dc6fd0eb82018505a74907431699Kuninori Morimoto SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | 37917731f8dffe7dc6fd0eb82018505a74907431699Kuninori Morimoto SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | 38017731f8dffe7dc6fd0eb82018505a74907431699Kuninori Morimoto SNDRV_PCM_RATE_192000, 3811d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, 3821d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto }, 3831d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto}; 3841d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3851d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimotostatic int sh_hdmi_snd_probe(struct snd_soc_codec *codec) 3861d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto{ 3871d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto dev_info(codec->dev, "SH Mobile HDMI Audio Codec"); 3881d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3891d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto return 0; 3901d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto} 3911d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 3921d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimotostatic struct snd_soc_codec_driver soc_codec_dev_sh_hdmi = { 3931d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .probe = sh_hdmi_snd_probe, 3941d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .read = sh_hdmi_snd_read, 3951d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto .write = sh_hdmi_snd_write, 3961d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto}; 3971d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 398f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto/* 399f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto * HDMI video 400f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto */ 4011d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 4026011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/* External video parameter settings */ 4036aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetskistatic void sh_hdmi_external_video_param(struct sh_hdmi *hdmi) 4046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 405e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart struct fb_videomode *mode = &hdmi->mode; 4066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski u16 htotal, hblank, hdelay, vtotal, vblank, vdelay, voffset; 4076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski u8 sync = 0; 4086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 409e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart htotal = mode->xres + mode->right_margin + mode->left_margin 410e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart + mode->hsync_len; 411e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart hdelay = mode->hsync_len + mode->left_margin; 412e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart hblank = mode->right_margin + hdelay; 4136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 4156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * Vertical timing looks a bit different in Figure 18, 4166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * but let's try the same first by setting offset = 0 4176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 418e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart vtotal = mode->yres + mode->upper_margin + mode->lower_margin 419e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart + mode->vsync_len; 420e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart vdelay = mode->vsync_len + mode->upper_margin; 421e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart vblank = mode->lower_margin + vdelay; 422e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart voffset = min(mode->upper_margin / 2, 6U); 4236011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4246011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 4256011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [3]: VSYNC polarity: Positive 4266011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [2]: HSYNC polarity: Positive 4276011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [1]: Interlace/Progressive: Progressive 4286011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [0]: External video settings enable: used. 4296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 430e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart if (mode->sync & FB_SYNC_HOR_HIGH_ACT) 4316011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sync |= 4; 432e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart if (mode->sync & FB_SYNC_VERT_HIGH_ACT) 4336011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sync |= 8; 4346011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4356aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski dev_dbg(hdmi->dev, "H: %u, %u, %u, %u; V: %u, %u, %u, %u; sync 0x%x\n", 436e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart htotal, hblank, hdelay, mode->hsync_len, 437e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart vtotal, vblank, vdelay, mode->vsync_len, sync); 4386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4396011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, sync | (voffset << 4), HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS); 4406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, htotal, HDMI_EXTERNAL_H_TOTAL_7_0); 4426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, htotal >> 8, HDMI_EXTERNAL_H_TOTAL_11_8); 4436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, hblank, HDMI_EXTERNAL_H_BLANK_7_0); 4456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, hblank >> 8, HDMI_EXTERNAL_H_BLANK_9_8); 4466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, hdelay, HDMI_EXTERNAL_H_DELAY_7_0); 4486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, hdelay >> 8, HDMI_EXTERNAL_H_DELAY_9_8); 4496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 450e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart hdmi_write(hdmi, mode->hsync_len, HDMI_EXTERNAL_H_DURATION_7_0); 451e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart hdmi_write(hdmi, mode->hsync_len >> 8, HDMI_EXTERNAL_H_DURATION_9_8); 4526011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, vtotal, HDMI_EXTERNAL_V_TOTAL_7_0); 4546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, vtotal >> 8, HDMI_EXTERNAL_V_TOTAL_9_8); 4556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, vblank, HDMI_EXTERNAL_V_BLANK); 4576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, vdelay, HDMI_EXTERNAL_V_DELAY); 4596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 460e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart hdmi_write(hdmi, mode->vsync_len, HDMI_EXTERNAL_V_DURATION); 4616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 46289712699d7bc9cc93602407e0e9bc2490b771400Guennadi Liakhovetski /* Set bit 0 of HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS here for external mode */ 4630ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski if (!hdmi->preprogrammed_vic) 46489712699d7bc9cc93602407e0e9bc2490b771400Guennadi Liakhovetski hdmi_write(hdmi, sync | 1 | (voffset << 4), 46589712699d7bc9cc93602407e0e9bc2490b771400Guennadi Liakhovetski HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS); 4666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 4676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/** 4696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * sh_hdmi_video_config() 4706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 4716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic void sh_hdmi_video_config(struct sh_hdmi *hdmi) 4726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 4736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 4746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7:4]: Audio sampling frequency: 48kHz 4756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [3:1]: Input video format: RGB and YCbCr 4:4:4 (Y on Green) 4766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [0]: Internal/External DE select: internal 4776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 4786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x20, HDMI_AUDIO_VIDEO_SETTING_1); 4796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 4816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7:6]: Video output format: RGB 4:4:4 4826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [5:4]: Input video data width: 8 bit 4836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [3:1]: EAV/SAV location: channel 1 4846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [0]: Video input color space: RGB 4856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 4866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x34, HDMI_VIDEO_SETTING_1); 4876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4886011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 4896011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7:6]: Together with bit [6] of HDMI_AUDIO_VIDEO_SETTING_2, which is 4906011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * left at 0 by default, this configures 24bpp and sets the Color Depth 4916011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * (CD) field in the General Control Packet 4926011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 4936011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x20, HDMI_DEEP_COLOR_MODES); 4946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 4956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 4966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/** 4976011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * sh_hdmi_audio_config() 4986011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 4996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic void sh_hdmi_audio_config(struct sh_hdmi *hdmi) 5006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 5016d86577124bd674209954517a074a472456c758bKuninori Morimoto u8 data; 502ad86abd81eb92afb978e093940bf731b948d7836Jingoo Han struct sh_mobile_hdmi_info *pdata = dev_get_platdata(hdmi->dev); 5036d86577124bd674209954517a074a472456c758bKuninori Morimoto 5046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 5056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7:4] L/R data swap control 5066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [3:0] appropriate N[19:16] 5076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 5086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_L_R_DATA_SWAP_CTRL_RPKT); 5096011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* appropriate N[15:8] */ 5106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x18, HDMI_20_BIT_N_FOR_AUDIO_RPKT_15_8); 5116011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* appropriate N[7:0] */ 5126011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_20_BIT_N_FOR_AUDIO_RPKT_7_0); 5136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* [7:4] 48 kHz SPDIF not used */ 5156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x20, HDMI_SPDIF_AUDIO_SAMP_FREQ_CTS); 5166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 5186011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [6:5] set required down sampling rate if required 5196011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [4:3] set required audio source 5206011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 521dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto switch (pdata->flags & HDMI_SND_SRC_MASK) { 5226d86577124bd674209954517a074a472456c758bKuninori Morimoto default: 523f4363b7d88e99497e4241397efee09b106d802c4Kuninori Morimoto /* fall through */ 524dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto case HDMI_SND_SRC_I2S: 525dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto data = 0x0 << 3; 5266d86577124bd674209954517a074a472456c758bKuninori Morimoto break; 527dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto case HDMI_SND_SRC_SPDIF: 528dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto data = 0x1 << 3; 5296d86577124bd674209954517a074a472456c758bKuninori Morimoto break; 530dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto case HDMI_SND_SRC_DSD: 531dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto data = 0x2 << 3; 5326d86577124bd674209954517a074a472456c758bKuninori Morimoto break; 533dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto case HDMI_SND_SRC_HBR: 534dec6aa49abf73b061b631163cb1e1d803a614d24Kuninori Morimoto data = 0x3 << 3; 5356d86577124bd674209954517a074a472456c758bKuninori Morimoto break; 5366d86577124bd674209954517a074a472456c758bKuninori Morimoto } 5376d86577124bd674209954517a074a472456c758bKuninori Morimoto hdmi_write(hdmi, data, HDMI_AUDIO_SETTING_1); 5386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5396011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* [3:0] set sending channel number for channel status */ 5406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x40, HDMI_AUDIO_SETTING_2); 5416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 5436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [5:2] set valid I2S source input pin 5446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [1:0] set input I2S source mode 5456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 5466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x04, HDMI_I2S_AUDIO_SET); 5476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* [7:4] set valid DSD source input pin */ 5496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_DSD_AUDIO_SET); 5506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* [7:0] set appropriate I2S input pin swap settings if required */ 5526011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_I2S_INPUT_PIN_SWAP); 5536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 5556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7] set validity bit for channel status 5566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [3:0] set original sample frequency for channel status 5576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 5586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_AUDIO_STATUS_BITS_SETTING_1); 5596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5606011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 5616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7] set value for channel status 5626011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [6] set value for channel status 5636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [5] set copyright bit for channel status 5646011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [4:2] set additional information for channel status 5656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [1:0] set clock accuracy for channel status 5666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 5676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_AUDIO_STATUS_BITS_SETTING_2); 5686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* [7:0] set category code for channel status */ 5706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CATEGORY_CODE); 5716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 5736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [7:4] set source number for channel status 5746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * [3:0] set word length for channel status 5756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 5766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SOURCE_NUM_AUDIO_WORD_LEN); 5776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* [7:4] set sample frequency for channel status */ 5796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x20, HDMI_AUDIO_VIDEO_SETTING_1); 5806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 5816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 5826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/** 5836e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * sh_hdmi_phy_config() - configure the HDMI PHY for the used video mode 5846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 5856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic void sh_hdmi_phy_config(struct sh_hdmi *hdmi) 5866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 587e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart if (hdmi->mode.pixclock < 10000) { 5880ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski /* for 1080p8bit 148MHz */ 5890ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x1d, HDMI_SLIPHDMIT_PARAM_SETTINGS_1); 5900ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_2); 5910ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_3); 5920ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x4c, HDMI_SLIPHDMIT_PARAM_SETTINGS_5); 5930ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x1e, HDMI_SLIPHDMIT_PARAM_SETTINGS_6); 5940ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x48, HDMI_SLIPHDMIT_PARAM_SETTINGS_7); 5950ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x0e, HDMI_SLIPHDMIT_PARAM_SETTINGS_8); 5960ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x25, HDMI_SLIPHDMIT_PARAM_SETTINGS_9); 5970ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi_write(hdmi, 0x04, HDMI_SLIPHDMIT_PARAM_SETTINGS_10); 598e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart } else if (hdmi->mode.pixclock < 30000) { 5996e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* 720p, 8bit, 74.25MHz. Might need to be adjusted for other formats */ 6006e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* 6016e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [1:0] Speed_A 6026e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [3:2] Speed_B 6036e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [4] PLLA_Bypass 6046e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [6] DRV_TEST_EN 6056e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [7] DRV_TEST_IN 6066e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski */ 6079289c475823b6eee1f68af2a71243d0cff126948Guennadi Liakhovetski hdmi_write(hdmi, 0x0f, HDMI_SLIPHDMIT_PARAM_SETTINGS_1); 6086e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* PLLB_CONFIG[17], PLLA_CONFIG[17] - not in PHY datasheet */ 6096e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_2); 6106e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* 6116e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [2:0] BGR_I_OFFSET 6126e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [6:4] BGR_V_OFFSET 6136e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski */ 6146e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_3); 6156e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* PLLA_CONFIG[7:0]: VCO gain, VCO offset, LPF resistance[0] */ 6166e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x44, HDMI_SLIPHDMIT_PARAM_SETTINGS_5); 6176e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* 6186e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * PLLA_CONFIG[15:8]: regulator voltage[0], CP current, 6196e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * LPF capacitance, LPF resistance[1] 6206e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski */ 6216e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x32, HDMI_SLIPHDMIT_PARAM_SETTINGS_6); 6226e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* PLLB_CONFIG[7:0]: LPF resistance[0], VCO offset, VCO gain */ 6236e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x4A, HDMI_SLIPHDMIT_PARAM_SETTINGS_7); 6246e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* 6256e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * PLLB_CONFIG[15:8]: regulator voltage[0], CP current, 6266e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * LPF capacitance, LPF resistance[1] 6276e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski */ 6289289c475823b6eee1f68af2a71243d0cff126948Guennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_8); 6296e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* DRV_CONFIG, PE_CONFIG */ 6306e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x25, HDMI_SLIPHDMIT_PARAM_SETTINGS_9); 6316e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* 6326e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [2:0] AMON_SEL (4 == LPF voltage) 6336e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [4] PLLA_CONFIG[16] 6346e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski * [5] PLLB_CONFIG[16] 6356e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski */ 6366e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x04, HDMI_SLIPHDMIT_PARAM_SETTINGS_10); 6376e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski } else { 6386e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski /* for 480p8bit 27MHz */ 6396e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x19, HDMI_SLIPHDMIT_PARAM_SETTINGS_1); 6406e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_2); 6416e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_3); 6426e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x44, HDMI_SLIPHDMIT_PARAM_SETTINGS_5); 6436e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x32, HDMI_SLIPHDMIT_PARAM_SETTINGS_6); 6446e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x48, HDMI_SLIPHDMIT_PARAM_SETTINGS_7); 6456e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x0F, HDMI_SLIPHDMIT_PARAM_SETTINGS_8); 6466e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x20, HDMI_SLIPHDMIT_PARAM_SETTINGS_9); 6476e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, 0x04, HDMI_SLIPHDMIT_PARAM_SETTINGS_10); 6486e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski } 6496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 6506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/** 6526011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * sh_hdmi_avi_infoframe_setup() - Auxiliary Video Information InfoFrame CONTROL PACKET 6536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 6546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic void sh_hdmi_avi_infoframe_setup(struct sh_hdmi *hdmi) 6556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 6566e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski u8 vic; 6576e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski 6586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* AVI InfoFrame */ 6596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x06, HDMI_CTRL_PKT_BUF_INDEX); 6606011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Packet Type = 0x82 */ 6626011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x82, HDMI_CTRL_PKT_BUF_ACCESS_HB0); 6636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6646011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Version = 0x02 */ 6656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x02, HDMI_CTRL_PKT_BUF_ACCESS_HB1); 6666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Length = 13 (0x0D) */ 6686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x0D, HDMI_CTRL_PKT_BUF_ACCESS_HB2); 6696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* N. A. Checksum */ 6716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0); 6726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 6746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * Y = RGB 6756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * A0 = No Data 6766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * B = Bar Data not valid 6776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * S = No Data 6786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 6796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB1); 6806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 6826aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * [7:6] C = Colorimetry: no data 6836aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * [5:4] M = 2: 16:9, 1: 4:3 Picture Aspect Ratio 6846aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * [3:0] R = 8: Active Frame Aspect Ratio: same as picture aspect ratio 6856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 6866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x28, HDMI_CTRL_PKT_BUF_ACCESS_PB2); 6876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6886011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 6896011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * ITC = No Data 6906011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * EC = xvYCC601 6916011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * Q = Default (depends on video format) 6926011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * SC = No Known non_uniform Scaling 6936011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 6946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB3); 6956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 6966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 6970ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski * VIC should be ignored if external config is used, so, we could just use 0, 6980ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski * but play safe and use a valid value in any case just in case 6996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 7000ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski if (hdmi->preprogrammed_vic) 7010ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski vic = hdmi->preprogrammed_vic; 7026e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski else 7036e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski vic = 4; 7046e45746c36d5ab4c3486760e45a555263a0b9facGuennadi Liakhovetski hdmi_write(hdmi, vic, HDMI_CTRL_PKT_BUF_ACCESS_PB4); 7056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* PR = No Repetition */ 7076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB5); 7086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7096011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Line Number of End of Top Bar (lower 8 bits) */ 7106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB6); 7116011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7126011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Line Number of End of Top Bar (upper 8 bits) */ 7136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB7); 7146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Line Number of Start of Bottom Bar (lower 8 bits) */ 7166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB8); 7176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7186011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Line Number of Start of Bottom Bar (upper 8 bits) */ 7196011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB9); 7206011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7216011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Pixel Number of End of Left Bar (lower 8 bits) */ 7226011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB10); 7236011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7246011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Pixel Number of End of Left Bar (upper 8 bits) */ 7256011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB11); 7266011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7276011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Pixel Number of Start of Right Bar (lower 8 bits) */ 7286011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB12); 7296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7306011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Pixel Number of Start of Right Bar (upper 8 bits) */ 7316011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB13); 7326011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 7336011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7346011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/** 7356011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * sh_hdmi_audio_infoframe_setup() - Audio InfoFrame of CONTROL PACKET 7366011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 7376011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic void sh_hdmi_audio_infoframe_setup(struct sh_hdmi *hdmi) 7386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 7396011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Audio InfoFrame */ 7406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x08, HDMI_CTRL_PKT_BUF_INDEX); 7416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Packet Type = 0x84 */ 7436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x84, HDMI_CTRL_PKT_BUF_ACCESS_HB0); 7446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Version Number = 0x01 */ 7466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x01, HDMI_CTRL_PKT_BUF_ACCESS_HB1); 7476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 0 Length = 10 (0x0A) */ 7496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x0A, HDMI_CTRL_PKT_BUF_ACCESS_HB2); 7506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* n. a. Checksum */ 7526011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0); 7536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Audio Channel Count = Refer to Stream Header */ 7556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB1); 7566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Refer to Stream Header */ 7586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB2); 7596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7606011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Format depends on coding type (i.e. CT0...CT3) */ 7616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB3); 7626011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Speaker Channel Allocation = Front Right + Front Left */ 7646011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB4); 7656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Level Shift Value = 0 dB, Down - mix is permitted or no information */ 7676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB5); 7686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Reserved (0) */ 7706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB6); 7716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB7); 7726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB8); 7736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB9); 7746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB10); 7756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 7766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/** 7786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * sh_hdmi_configure() - Initialise HDMI for output 7796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 7806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic void sh_hdmi_configure(struct sh_hdmi *hdmi) 7816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 7826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Configure video format */ 7836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sh_hdmi_video_config(hdmi); 7846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Configure audio format */ 7866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sh_hdmi_audio_config(hdmi); 7876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7886011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Configure PHY */ 7896011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sh_hdmi_phy_config(hdmi); 7906011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7916011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Auxiliary Video Information (AVI) InfoFrame */ 7926011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sh_hdmi_avi_infoframe_setup(hdmi); 7936011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Audio InfoFrame */ 7956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sh_hdmi_audio_infoframe_setup(hdmi); 7966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 7976011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 7986011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * Control packet auto send with VSYNC control: auto send 7996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski * General control, Gamut metadata, ISRC, and ACP packets 8006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 8016011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x8E, HDMI_CTRL_PKT_AUTO_SEND); 8026011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 8036011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* FIXME */ 8046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski msleep(10); 8056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 8066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* PS mode b->d, reset PLLA and PLLB */ 8073f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_bit_set(hdmi, 0xFC, 0x4C, HDMI_SYSTEM_CTRL); 8086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 8096011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski udelay(10); 8106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 8113f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_bit_set(hdmi, 0xFC, 0x40, HDMI_SYSTEM_CTRL); 8126011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 8136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 814f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetskistatic unsigned long sh_hdmi_rate_error(struct sh_hdmi *hdmi, 815c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski const struct fb_videomode *mode, 816c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski unsigned long *hdmi_rate, unsigned long *parent_rate) 8176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 818c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski unsigned long target = PICOS2KHZ(mode->pixclock) * 1000, rate_error; 819ad86abd81eb92afb978e093940bf731b948d7836Jingoo Han struct sh_mobile_hdmi_info *pdata = dev_get_platdata(hdmi->dev); 820c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 821c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski *hdmi_rate = clk_round_rate(hdmi->hdmi_clk, target); 822c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski if ((long)*hdmi_rate < 0) 823c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski *hdmi_rate = clk_get_rate(hdmi->hdmi_clk); 824c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 825c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski rate_error = (long)*hdmi_rate > 0 ? abs(*hdmi_rate - target) : ULONG_MAX; 826c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski if (rate_error && pdata->clk_optimize_parent) 827c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski rate_error = pdata->clk_optimize_parent(target, hdmi_rate, parent_rate); 828c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski else if (clk_get_parent(hdmi->hdmi_clk)) 829c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski *parent_rate = clk_get_rate(clk_get_parent(hdmi->hdmi_clk)); 830f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 831f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski dev_dbg(hdmi->dev, "%u-%u-%u-%u x %u-%u-%u-%u\n", 832f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski mode->left_margin, mode->xres, 833f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski mode->right_margin, mode->hsync_len, 834f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski mode->upper_margin, mode->yres, 835f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski mode->lower_margin, mode->vsync_len); 836f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 837c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_dbg(hdmi->dev, "\t@%lu(+/-%lu)Hz, e=%lu / 1000, r=%uHz, p=%luHz\n", target, 838c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski rate_error, rate_error ? 10000 / (10 * target / rate_error) : 0, 839c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski mode->refresh, *parent_rate); 840f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 841f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski return rate_error; 842f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski} 843f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 844c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetskistatic int sh_hdmi_read_edid(struct sh_hdmi *hdmi, unsigned long *hdmi_rate, 845c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski unsigned long *parent_rate) 8466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 8477295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart struct sh_mobile_lcdc_chan *ch = hdmi->entity.lcdc; 848afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski const struct fb_videomode *mode, *found = NULL; 849f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski unsigned int f_width = 0, f_height = 0, f_refresh = 0; 850f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski unsigned long found_rate_error = ULONG_MAX; /* silly compiler... */ 851c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski bool scanning = false, preferred_bad = false; 85213f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart bool use_edid_mode = false; 8536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski u8 edid[128]; 854f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski char *forced; 855f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski int i; 8566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 8576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Read EDID */ 8586aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski dev_dbg(hdmi->dev, "Read back EDID code:"); 8596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski for (i = 0; i < 128; i++) { 860c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto edid[i] = (hdmi->htop1) ? 861c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto (u8)hdmi_htop1_read(hdmi, HDMI_HTOP1_EDID_DATA_READ + (i * 4)) : 862c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_read(hdmi, HDMI_EDID_KSV_FIFO_ACCESS_WINDOW); 8636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#ifdef DEBUG 8646011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if ((i % 16) == 0) { 8656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski printk(KERN_CONT "\n"); 8666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski printk(KERN_DEBUG "%02X | %02X", i, edid[i]); 8676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } else { 8686011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski printk(KERN_CONT " %02X", edid[i]); 8696011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 8706011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#endif 8716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 8726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#ifdef DEBUG 8736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski printk(KERN_CONT "\n"); 8746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski#endif 875afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 8764232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski if (!hdmi->edid_blocks) { 8774232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski fb_edid_to_monspecs(edid, &hdmi->monspec); 8784232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_blocks = edid[126] + 1; 8794232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski 8804232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski dev_dbg(hdmi->dev, "%d main modes, %d extension blocks\n", 8814232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->monspec.modedb_len, hdmi->edid_blocks - 1); 8824232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski } else { 8834232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski dev_dbg(hdmi->dev, "Extension %u detected, DTD start %u\n", 8844232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski edid[0], edid[2]); 8854232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski fb_edid_add_monspecs(edid, &hdmi->monspec); 8864232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski } 8874232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski 8884232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski if (hdmi->edid_blocks > hdmi->edid_segment_nr * 2 + 8894232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski (hdmi->edid_block_addr >> 7) + 1) { 8904232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski /* More blocks to read */ 8914232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski if (hdmi->edid_block_addr) { 8924232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_block_addr = 0; 8934232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_segment_nr++; 8944232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski } else { 8954232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_block_addr = 0x80; 8964232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski } 8974232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski /* Set EDID word address */ 8984232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi_write(hdmi, hdmi->edid_block_addr, HDMI_EDID_WORD_ADDRESS); 8994232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski /* Enable EDID interrupt */ 9004232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi_write(hdmi, 0xC6, HDMI_INTERRUPT_MASK_1); 9014232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski /* Set EDID segment pointer - starts reading EDID */ 9024232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi_write(hdmi, hdmi->edid_segment_nr, HDMI_EDID_SEGMENT_POINTER); 9034232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski return -EAGAIN; 9044232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski } 9054232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski 9064232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski /* All E-EDID blocks ready */ 9074232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski dev_dbg(hdmi->dev, "%d main and extended modes\n", hdmi->monspec.modedb_len); 908afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 909f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski fb_get_options("sh_mobile_lcdc", &forced); 910f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski if (forced && *forced) { 911f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski /* Only primitive parsing so far */ 912f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski i = sscanf(forced, "%ux%u@%u", 913f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski &f_width, &f_height, &f_refresh); 914f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski if (i < 2) { 915f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski f_width = 0; 916f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski f_height = 0; 917c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski } else { 918c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski /* The user wants us to use the EDID data */ 919c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski scanning = true; 920f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski } 921f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski dev_dbg(hdmi->dev, "Forced mode %ux%u@%uHz\n", 922f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski f_width, f_height, f_refresh); 923f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski } 924f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 925f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski /* Walk monitor modes to find the best or the exact match */ 926f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski for (i = 0, mode = hdmi->monspec.modedb; 927c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski i < hdmi->monspec.modedb_len && scanning; 928afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski i++, mode++) { 929c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski unsigned long rate_error; 930f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 931c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski if (!f_width && !f_height) { 932c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski /* 933c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * A parameter string "video=sh_mobile_lcdc:0x0" means 934c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * use the preferred EDID mode. If it is rejected by 935c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * .fb_check_var(), keep looking, until an acceptable 936c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * one is found. 937c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski */ 938c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski if ((mode->flag & FB_MODE_IS_FIRST) || preferred_bad) 939c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski scanning = false; 940c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski else 941c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski continue; 942c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski } else if (f_width != mode->xres || f_height != mode->yres) { 943c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski /* No interest in unmatching modes */ 944f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski continue; 945c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski } 946c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 947c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski rate_error = sh_hdmi_rate_error(hdmi, mode, hdmi_rate, parent_rate); 948c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 949c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski if (scanning) { 950c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski if (f_refresh == mode->refresh || (!f_refresh && !rate_error)) 951c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski /* 952c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * Exact match if either the refresh rate 953c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * matches or it hasn't been specified and we've 954c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * found a mode, for which we can configure the 955c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * clock precisely 956c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski */ 957c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski scanning = false; 958c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski else if (found && found_rate_error <= rate_error) 959c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski /* 960c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * We otherwise search for the closest matching 961c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * clock rate - either if no refresh rate has 962c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * been specified or we cannot find an exactly 963c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski * matching one 964c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski */ 965c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski continue; 966c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski } 967f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 968f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski /* Check if supported: sufficient fb memory, supported clock-rate */ 9697295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart if (ch && ch->notify && 970e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart ch->notify(ch, SH_MOBILE_LCDC_EVENT_DISPLAY_MODE, mode, 971e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart NULL)) { 972c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski scanning = true; 973c7321d6f88e1f962d605923a93f9c255e4d0b8c9Guennadi Liakhovetski preferred_bad = true; 974f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski continue; 975afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } 976f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski 977f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski found = mode; 978f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski found_rate_error = rate_error; 97913f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart use_edid_mode = true; 980afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } 981afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 982afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski /* 98313f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart * TODO 1: if no default mode is present, postpone running the config 98413f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart * until after the LCDC channel is initialized. 985f1198d1ea1c1fe7a0d619c5cf7049efe6205e527Guennadi Liakhovetski * TODO 2: consider registering the HDMI platform device from the LCDC 98613f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart * driver. 987afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski */ 98813f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart if (!found && hdmi->entity.def_mode.xres != 0) { 98913f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart found = &hdmi->entity.def_mode; 99013f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart found_rate_error = sh_hdmi_rate_error(hdmi, found, hdmi_rate, 99113f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart parent_rate); 992afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } 993afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 994afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski /* No cookie today */ 995afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski if (!found) 996afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski return -ENXIO; 997afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 9980ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski if (found->xres == 640 && found->yres == 480 && found->refresh == 60) 9990ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 1; 10000ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski else if (found->xres == 720 && found->yres == 480 && found->refresh == 60) 10010ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 2; 10020ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski else if (found->xres == 720 && found->yres == 576 && found->refresh == 50) 10030ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 17; 10040ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski else if (found->xres == 1280 && found->yres == 720 && found->refresh == 60) 10050ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 4; 10060ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski else if (found->xres == 1920 && found->yres == 1080 && found->refresh == 24) 10070ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 32; 10080ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski else if (found->xres == 1920 && found->yres == 1080 && found->refresh == 50) 10090ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 31; 10100ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski else if (found->xres == 1920 && found->yres == 1080 && found->refresh == 60) 10110ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 16; 101289712699d7bc9cc93602407e0e9bc2490b771400Guennadi Liakhovetski else 10130ea2af1c15b730dba9ce741420352d298bcd7862Guennadi Liakhovetski hdmi->preprogrammed_vic = 0; 101489712699d7bc9cc93602407e0e9bc2490b771400Guennadi Liakhovetski 101513f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart dev_dbg(hdmi->dev, "Using %s %s mode %ux%u@%uHz (%luHz), " 101613f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart "clock error %luHz\n", use_edid_mode ? "EDID" : "default", 101713f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart hdmi->preprogrammed_vic ? "VIC" : "external", found->xres, 101813f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart found->yres, found->refresh, PICOS2KHZ(found->pixclock) * 1000, 101913f80eea562be6cd58b5bdefc224c87cc0d9288dLaurent Pinchart found_rate_error); 1020c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 1021e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart hdmi->mode = *found; 10226aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski sh_hdmi_external_video_param(hdmi); 1023afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 1024afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski return 0; 10256011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 10266011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10276011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic irqreturn_t sh_hdmi_hotplug(int irq, void *dev_id) 10286011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 10296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct sh_hdmi *hdmi = dev_id; 10306011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski u8 status1, status2, mask1, mask2; 10316011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10326011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* mode_b and PLLA and PLLB reset */ 10333f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_bit_set(hdmi, 0xFC, 0x2C, HDMI_SYSTEM_CTRL); 10346011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10356011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* How long shall reset be held? */ 10366011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski udelay(10); 10376011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* mode_b and PLLA and PLLB reset release */ 10393f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_bit_set(hdmi, 0xFC, 0x20, HDMI_SYSTEM_CTRL); 10406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski status1 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_1); 10426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski status2 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_2); 10436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski mask1 = hdmi_read(hdmi, HDMI_INTERRUPT_MASK_1); 10456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski mask2 = hdmi_read(hdmi, HDMI_INTERRUPT_MASK_2); 10466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Correct would be to ack only set bits, but the datasheet requires 0xff */ 10486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0xFF, HDMI_INTERRUPT_STATUS_1); 10496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0xFF, HDMI_INTERRUPT_STATUS_2); 10506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (printk_ratelimit()) 10526aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski dev_dbg(hdmi->dev, "IRQ #%d: Status #1: 0x%x & 0x%x, #2: 0x%x & 0x%x\n", 10536aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski irq, status1, mask1, status2, mask2); 10546011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (!((status1 & mask1) | (status2 & mask2))) { 10566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return IRQ_NONE; 10576011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } else if (status1 & 0xc0) { 10586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski u8 msens; 10596011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10606011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Datasheet specifies 10ms... */ 10616011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski udelay(500); 10626011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10636011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski msens = hdmi_read(hdmi, HDMI_HOT_PLUG_MSENS_STATUS); 10646aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski dev_dbg(hdmi->dev, "MSENS 0x%x\n", msens); 10656011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Check, if hot plug & MSENS pin status are both high */ 10666011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if ((msens & 0xC0) == 0xC0) { 10676011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Display plug in */ 10684232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_segment_nr = 0; 10694232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_block_addr = 0; 10704232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->edid_blocks = 0; 10716011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi->hp_state = HDMI_HOTPLUG_CONNECTED; 10726011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Set EDID word address */ 10746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_EDID_WORD_ADDRESS); 10756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Enable EDID interrupt */ 10766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0xC6, HDMI_INTERRUPT_MASK_1); 10774232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski /* Set EDID segment pointer - starts reading EDID */ 10784232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi_write(hdmi, 0x00, HDMI_EDID_SEGMENT_POINTER); 10796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } else if (!(status1 & 0x80)) { 10806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Display unplug, beware multiple interrupts */ 10814232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski if (hdmi->hp_state != HDMI_HOTPLUG_DISCONNECTED) { 10824232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->hp_state = HDMI_HOTPLUG_DISCONNECTED; 10836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski schedule_delayed_work(&hdmi->edid_work, 0); 10844232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski } 10856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* display_off will switch back to mode_a */ 10866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 10876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } else if (status1 & 2) { 10886011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* EDID error interrupt: retry */ 10896011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Set EDID word address */ 10904232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi_write(hdmi, hdmi->edid_block_addr, HDMI_EDID_WORD_ADDRESS); 10916011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Set EDID segment pointer */ 10924232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi_write(hdmi, hdmi->edid_segment_nr, HDMI_EDID_SEGMENT_POINTER); 10936011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } else if (status1 & 4) { 10946011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Disable EDID interrupt */ 10956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi_write(hdmi, 0xC0, HDMI_INTERRUPT_MASK_1); 10966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski schedule_delayed_work(&hdmi->edid_work, msecs_to_jiffies(10)); 10976011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 10986011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 10996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return IRQ_HANDLED; 11006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 11016011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 11025864ace19a2546912308e94432c1cf52d5945afeLaurent Pinchartstatic int sh_hdmi_display_on(struct sh_mobile_lcdc_entity *entity) 11036011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 11048511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart struct sh_hdmi *hdmi = entity_to_sh_hdmi(entity); 11056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1106458981c3886133667e020900f53538f1fbc3ea1dLaurent Pinchart dev_dbg(hdmi->dev, "%s(%p): state %x\n", __func__, hdmi, 1107458981c3886133667e020900f53538f1fbc3ea1dLaurent Pinchart hdmi->hp_state); 11086de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski 11096011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* 11106aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * hp_state can be set to 11116aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * HDMI_HOTPLUG_DISCONNECTED: on monitor unplug 11126aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * HDMI_HOTPLUG_CONNECTED: on monitor plug-in 11136aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski * HDMI_HOTPLUG_EDID_DONE: on EDID read completion 11146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski */ 1115d30555d24e462edf439a1057114e1b0df76c89efLaurent Pinchart if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) { 11166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* PS mode d->e. All functions are active */ 11173f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_bit_set(hdmi, 0xFC, 0x80, HDMI_SYSTEM_CTRL); 11186aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski dev_dbg(hdmi->dev, "HDMI running\n"); 11196011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 11208511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart 1121458981c3886133667e020900f53538f1fbc3ea1dLaurent Pinchart return hdmi->hp_state == HDMI_HOTPLUG_DISCONNECTED 1122458981c3886133667e020900f53538f1fbc3ea1dLaurent Pinchart ? SH_MOBILE_LCDC_DISPLAY_DISCONNECTED 1123458981c3886133667e020900f53538f1fbc3ea1dLaurent Pinchart : SH_MOBILE_LCDC_DISPLAY_CONNECTED; 11248511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart} 11258511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart 1126db85905ad95b090941dc894b7f93f9f3818bdc07Laurent Pinchartstatic void sh_hdmi_display_off(struct sh_mobile_lcdc_entity *entity) 11276011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 11288511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart struct sh_hdmi *hdmi = entity_to_sh_hdmi(entity); 11296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1130134d22eb58b72c4fe5e6ca3ebcaccd4975f06842Laurent Pinchart dev_dbg(hdmi->dev, "%s(%p)\n", __func__, hdmi); 11316011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* PS mode e->a */ 11323f521abd6cf1320d65a49cf9fc327b82168b5ba0Kuninori Morimoto hdmi_bit_set(hdmi, 0xFC, 0x10, HDMI_SYSTEM_CTRL); 11336011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 11346011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 11358511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchartstatic const struct sh_mobile_lcdc_entity_ops sh_hdmi_ops = { 1136db85905ad95b090941dc894b7f93f9f3818bdc07Laurent Pinchart .display_on = sh_hdmi_display_on, 1137db85905ad95b090941dc894b7f93f9f3818bdc07Laurent Pinchart .display_off = sh_hdmi_display_off, 11388511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart}; 11398511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart 1140afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski/** 1141afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski * sh_hdmi_clk_configure() - set HDMI clock frequency and enable the clock 1142c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski * @hdmi: driver context 1143c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski * @hdmi_rate: HDMI clock frequency in Hz 1144c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski * @parent_rate: if != 0 - set parent clock rate for optimal precision 1145c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski * return: configured positive rate if successful 1146c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski * 0 if couldn't set the rate, but managed to enable the 1147c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski * clock, negative error, if couldn't enable the clock 1148afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski */ 1149c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetskistatic long sh_hdmi_clk_configure(struct sh_hdmi *hdmi, unsigned long hdmi_rate, 1150c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski unsigned long parent_rate) 1151afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski{ 1152afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski int ret; 1153afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 1154c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski if (parent_rate && clk_get_parent(hdmi->hdmi_clk)) { 1155c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski ret = clk_set_rate(clk_get_parent(hdmi->hdmi_clk), parent_rate); 1156afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski if (ret < 0) { 1157c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_warn(hdmi->dev, "Cannot set parent rate %ld: %d\n", parent_rate, ret); 1158c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski hdmi_rate = clk_round_rate(hdmi->hdmi_clk, hdmi_rate); 1159afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } else { 1160c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_dbg(hdmi->dev, "HDMI set parent frequency %lu\n", parent_rate); 1161afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } 1162afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } 1163afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 1164c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski ret = clk_set_rate(hdmi->hdmi_clk, hdmi_rate); 1165afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski if (ret < 0) { 1166c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_warn(hdmi->dev, "Cannot set rate %ld: %d\n", hdmi_rate, ret); 1167c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski hdmi_rate = 0; 1168c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski } else { 1169c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_dbg(hdmi->dev, "HDMI set frequency %lu\n", hdmi_rate); 1170afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski } 1171afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 1172c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski return hdmi_rate; 1173afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski} 1174afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 11756011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski/* Hotplug interrupt occurred, read EDID */ 11766aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetskistatic void sh_hdmi_edid_work_fn(struct work_struct *work) 11776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 11786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work); 1179bce95fe838a5ca84e57411338b953be672c2a5ebLaurent Pinchart struct sh_mobile_lcdc_chan *ch = hdmi->entity.lcdc; 1180afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski int ret; 11816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1182134d22eb58b72c4fe5e6ca3ebcaccd4975f06842Laurent Pinchart dev_dbg(hdmi->dev, "%s(%p): begin, hotplug status %d\n", __func__, hdmi, 1183134d22eb58b72c4fe5e6ca3ebcaccd4975f06842Laurent Pinchart hdmi->hp_state); 11846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 11854232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski if (hdmi->hp_state == HDMI_HOTPLUG_CONNECTED) { 1186c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski unsigned long parent_rate = 0, hdmi_rate; 1187c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 1188c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski ret = sh_hdmi_read_edid(hdmi, &hdmi_rate, &parent_rate); 1189d521dd944e461371cb309c7c3568483cd2b6f5f2Guennadi Liakhovetski if (ret < 0) 1190afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski goto out; 1191afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 11924232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski hdmi->hp_state = HDMI_HOTPLUG_EDID_DONE; 11934232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski 1194afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski /* Reconfigure the clock */ 1195c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski ret = sh_hdmi_clk_configure(hdmi, hdmi_rate, parent_rate); 1196d521dd944e461371cb309c7c3568483cd2b6f5f2Guennadi Liakhovetski if (ret < 0) 1197afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski goto out; 1198afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski 11996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski msleep(10); 12006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski sh_hdmi_configure(hdmi); 12016011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski /* Switched to another (d) power-save mode */ 12026011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski msleep(10); 12036011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 12047295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart if (ch && ch->notify) 12057295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart ch->notify(ch, SH_MOBILE_LCDC_EVENT_DISPLAY_CONNECT, 1206e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart &hdmi->mode, &hdmi->monspec); 12076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } else { 120891d63f8a306722dbf1b400d4afb11f69512977adGuennadi Liakhovetski hdmi->monspec.modedb_len = 0; 120991d63f8a306722dbf1b400d4afb11f69512977adGuennadi Liakhovetski fb_destroy_modedb(hdmi->monspec.modedb); 121091d63f8a306722dbf1b400d4afb11f69512977adGuennadi Liakhovetski hdmi->monspec.modedb = NULL; 121191d63f8a306722dbf1b400d4afb11f69512977adGuennadi Liakhovetski 12127295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart if (ch && ch->notify) 12137295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart ch->notify(ch, SH_MOBILE_LCDC_EVENT_DISPLAY_DISCONNECT, 1214e0c8601a18969229eb63065e5c3176319c785288Laurent Pinchart NULL, NULL); 12156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 12167295752fd7ec86feca6e3ccb407c1cbabf59e1d3Laurent Pinchart ret = 0; 12176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 12186011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 12196de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetskiout: 12204232f60791d12a5156c3e1c9b04ae08b873a2920Guennadi Liakhovetski if (ret < 0 && ret != -EAGAIN) 1221afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski hdmi->hp_state = HDMI_HOTPLUG_DISCONNECTED; 12226de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski 1223134d22eb58b72c4fe5e6ca3ebcaccd4975f06842Laurent Pinchart dev_dbg(hdmi->dev, "%s(%p): end\n", __func__, hdmi); 12246011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 12256011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1226c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimotostatic void sh_hdmi_htop1_init(struct sh_hdmi *hdmi) 1227c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto{ 1228c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_MODE); 1229c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x0000000b, 0x0010); 1230c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00006710, HDMI_HTOP1_HTOP_DCL_FRC_MODE); 1231c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_1); 1232c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_2); 1233c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_1); 1234c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_2); 1235c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_1); 1236c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_2); 1237c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_1); 1238c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_2); 1239c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_1); 1240c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_2); 1241c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_1); 1242c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_2); 1243c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_Y1); 1244c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CB1); 1245c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CR1); 1246c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_Y2); 1247c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CB2); 1248c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CR2); 1249c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000008, HDMI_HTOP1_CURRENT); 1250c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_TISEMP0_1); 1251c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_TISEMP2_C); 1252c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_PHY_TEST_MODE); 1253c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000081, HDMI_HTOP1_TISIDRV); 1254c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_PLLBW); 1255c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISEN); 1256c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISDREN); 1257c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000003, HDMI_HTOP1_ENABLE_SELECTOR); 1258c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000001, HDMI_HTOP1_MACRO_RESET); 1259c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000016, HDMI_HTOP1_CISRANGE); 1260c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto msleep(100); 1261c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000001, HDMI_HTOP1_ENABLE_SELECTOR); 1262c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto msleep(100); 1263c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000003, HDMI_HTOP1_ENABLE_SELECTOR); 1264c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000001, HDMI_HTOP1_MACRO_RESET); 1265c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISEN); 1266c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISDREN); 1267c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_VIDEO_INPUT); 1268c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_CLK_TO_PHY); 1269c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_VIDEO_INPUT2); 1270c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi_htop1_write(hdmi, 0x0000000a, HDMI_HTOP1_CLK_SET); 1271c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto} 1272c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto 12736011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic int __init sh_hdmi_probe(struct platform_device *pdev) 12746011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 1275ad86abd81eb92afb978e093940bf731b948d7836Jingoo Han struct sh_mobile_hdmi_info *pdata = dev_get_platdata(&pdev->dev); 12766011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1277c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto struct resource *htop1_res; 12786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski int irq = platform_get_irq(pdev, 0), ret; 12796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct sh_hdmi *hdmi; 12806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski long rate; 12816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 12826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (!res || !pdata || irq < 0) 12836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return -ENODEV; 12846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1285c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto htop1_res = NULL; 1286c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto if (pdata->flags & HDMI_HAS_HTOP1) { 1287c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto htop1_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1288c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto if (!htop1_res) { 1289c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto dev_err(&pdev->dev, "htop1 needs register base\n"); 1290c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto return -EINVAL; 1291c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto } 1292c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto } 1293c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto 12944d26ec5ddf93e7e133e36fd0454b54a3938f7d3cSangjung Woo hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); 12956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (!hdmi) { 12966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski dev_err(&pdev->dev, "Cannot allocate device data\n"); 12976011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return -ENOMEM; 12986011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 12996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13006011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi->dev = &pdev->dev; 13018511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart hdmi->entity.owner = THIS_MODULE; 13028511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart hdmi->entity.ops = &sh_hdmi_ops; 1303a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven hdmi->irq = irq; 13046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi->hdmi_clk = clk_get(&pdev->dev, "ick"); 13066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (IS_ERR(hdmi->hdmi_clk)) { 13076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski ret = PTR_ERR(hdmi->hdmi_clk); 13086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski dev_err(&pdev->dev, "Unable to get clock: %d\n", ret); 13094d26ec5ddf93e7e133e36fd0454b54a3938f7d3cSangjung Woo return ret; 13106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 13116011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1312db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto /* select register access functions */ 1313db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto if (pdata->flags & HDMI_32BIT_REG) { 1314db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto hdmi->write = __hdmi_write32; 1315db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto hdmi->read = __hdmi_read32; 1316db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto } else { 1317db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto hdmi->write = __hdmi_write8; 1318db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto hdmi->read = __hdmi_read8; 1319db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto } 1320db6668d83a265a15ffd79dbc8432598808b34bb4Kuninori Morimoto 1321c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski /* An arbitrary relaxed pixclock just to get things started: from standard 480p */ 1322c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski rate = clk_round_rate(hdmi->hdmi_clk, PICOS2KHZ(37037)); 1323c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski if (rate > 0) 1324c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski rate = sh_hdmi_clk_configure(hdmi, rate, 0); 1325c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 13266011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (rate < 0) { 13276011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski ret = rate; 13286011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski goto erate; 13296011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 13306011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1331d00affb1c6bfa83e216931604f697a38745b4181Laurent Pinchart ret = clk_prepare_enable(hdmi->hdmi_clk); 1332c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski if (ret < 0) { 1333c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_err(hdmi->dev, "Cannot enable clock: %d\n", ret); 1334c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski goto erate; 1335c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski } 1336c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 1337afe417c0355154c8b2547619771d6053b3c0aad7Guennadi Liakhovetski dev_dbg(&pdev->dev, "Enabled HDMI clock at %luHz\n", rate); 13386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13396011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (!request_mem_region(res->start, resource_size(res), dev_name(&pdev->dev))) { 13406011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski dev_err(&pdev->dev, "HDMI register region already claimed\n"); 13416011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski ret = -EBUSY; 13426011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski goto ereqreg; 13436011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 13446011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13456011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski hdmi->base = ioremap(res->start, resource_size(res)); 13466011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (!hdmi->base) { 13476011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski dev_err(&pdev->dev, "HDMI register region already claimed\n"); 13486011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski ret = -ENOMEM; 13496011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski goto emap; 13506011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 13516011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13528511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart platform_set_drvdata(pdev, &hdmi->entity); 13536011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13546aa966e610f918a6732a5acc102cb5e8de616cb3Guennadi Liakhovetski INIT_DELAYED_WORK(&hdmi->edid_work, sh_hdmi_edid_work_fn); 13556011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 13566011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski pm_runtime_enable(&pdev->dev); 1357d521dd944e461371cb309c7c3568483cd2b6f5f2Guennadi Liakhovetski pm_runtime_get_sync(&pdev->dev); 13586011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1359e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto /* init interrupt polarity */ 1360e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto if (pdata->flags & HDMI_OUTPUT_PUSH_PULL) 1361e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto hdmi_bit_set(hdmi, 0x02, 0x02, HDMI_SYSTEM_CTRL); 1362e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto 1363e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto if (pdata->flags & HDMI_OUTPUT_POLARITY_HI) 1364e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto hdmi_bit_set(hdmi, 0x01, 0x01, HDMI_SYSTEM_CTRL); 1365e0defc86423d1b5652826c9317c36dfb6af1cd48Kuninori Morimoto 1366c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto /* enable htop1 register if needed */ 1367c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto if (htop1_res) { 1368c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto hdmi->htop1 = ioremap(htop1_res->start, resource_size(htop1_res)); 1369c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto if (!hdmi->htop1) { 1370c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto dev_err(&pdev->dev, "control register region already claimed\n"); 1371c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto ret = -ENOMEM; 1372c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto goto emap_htop1; 1373c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto } 1374c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto sh_hdmi_htop1_init(hdmi); 1375c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto } 1376c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto 1377c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski /* Product and revision IDs are 0 in sh-mobile version */ 1378c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n", 1379c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID)); 1380c36940e678fc30779c99246c034deca1fed61ae4Guennadi Liakhovetski 13816011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski ret = request_irq(irq, sh_hdmi_hotplug, 0, 13826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski dev_name(&pdev->dev), hdmi); 13836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski if (ret < 0) { 13846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski dev_err(&pdev->dev, "Unable to request irq: %d\n", ret); 13856011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski goto ereqirq; 13866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski } 13876011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1388b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King ret = snd_soc_register_codec(&pdev->dev, 1389b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King &soc_codec_dev_sh_hdmi, &sh_hdmi_dai, 1); 1390b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King if (ret < 0) { 1391b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King dev_err(&pdev->dev, "codec registration failed\n"); 1392b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King goto ecodec; 1393b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King } 1394b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King 13956011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return 0; 13966011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1397b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell Kingecodec: 1398b3773301c4290f054aa2aa5379e59a1bf4f78bdfRussell King free_irq(irq, hdmi); 13996011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskiereqirq: 1400c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto if (hdmi->htop1) 1401c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto iounmap(hdmi->htop1); 1402c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimotoemap_htop1: 1403d521dd944e461371cb309c7c3568483cd2b6f5f2Guennadi Liakhovetski pm_runtime_put(&pdev->dev); 14046011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski pm_runtime_disable(&pdev->dev); 14056011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski iounmap(hdmi->base); 14066011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskiemap: 14076011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski release_mem_region(res->start, resource_size(res)); 14086011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskiereqreg: 1409d00affb1c6bfa83e216931604f697a38745b4181Laurent Pinchart clk_disable_unprepare(hdmi->hdmi_clk); 14106011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskierate: 14116011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski clk_put(hdmi->hdmi_clk); 14126011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 14136011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return ret; 14146011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 14156011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 14166011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic int __exit sh_hdmi_remove(struct platform_device *pdev) 14176011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski{ 14188511ea4ad39e351767167280b0b0ac716a8f2986Laurent Pinchart struct sh_hdmi *hdmi = entity_to_sh_hdmi(platform_get_drvdata(pdev)); 14196011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 14206011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 14211d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto snd_soc_unregister_codec(&pdev->dev); 14221d6be338c11ddc1e58915ab85e19b0f6cbc10782Kuninori Morimoto 14236de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski /* No new work will be scheduled, wait for running ISR */ 1424a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven free_irq(hdmi->irq, hdmi); 14256de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski /* Wait for already scheduled work */ 14266011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski cancel_delayed_work_sync(&hdmi->edid_work); 1427d521dd944e461371cb309c7c3568483cd2b6f5f2Guennadi Liakhovetski pm_runtime_put(&pdev->dev); 14286de9edd5bde0cdfea12e9948690e53ec669c3018Guennadi Liakhovetski pm_runtime_disable(&pdev->dev); 1429d00affb1c6bfa83e216931604f697a38745b4181Laurent Pinchart clk_disable_unprepare(hdmi->hdmi_clk); 14306011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski clk_put(hdmi->hdmi_clk); 1431c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto if (hdmi->htop1) 1432c932b2731116f99a660817e8fa718c9da0798a9cKuninori Morimoto iounmap(hdmi->htop1); 14336011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski iounmap(hdmi->base); 14346011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski release_mem_region(res->start, resource_size(res)); 14356011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 14366011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski return 0; 14376011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski} 14386011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 1439a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoevenstatic int sh_hdmi_suspend(struct device *dev) 1440a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven{ 1441a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven struct platform_device *pdev = to_platform_device(dev); 1442a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven struct sh_hdmi *hdmi = entity_to_sh_hdmi(platform_get_drvdata(pdev)); 1443a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1444a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven disable_irq(hdmi->irq); 1445a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven /* Wait for already scheduled work */ 1446a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven cancel_delayed_work_sync(&hdmi->edid_work); 1447a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven return 0; 1448a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven} 1449a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1450a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoevenstatic int sh_hdmi_resume(struct device *dev) 1451a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven{ 1452a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven struct platform_device *pdev = to_platform_device(dev); 1453a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven struct sh_mobile_hdmi_info *pdata = dev_get_platdata(dev); 1454a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven struct sh_hdmi *hdmi = entity_to_sh_hdmi(platform_get_drvdata(pdev)); 1455a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1456a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven /* Re-init interrupt polarity */ 1457a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven if (pdata->flags & HDMI_OUTPUT_PUSH_PULL) 1458a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven hdmi_bit_set(hdmi, 0x02, 0x02, HDMI_SYSTEM_CTRL); 1459a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1460a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven if (pdata->flags & HDMI_OUTPUT_POLARITY_HI) 1461a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven hdmi_bit_set(hdmi, 0x01, 0x01, HDMI_SYSTEM_CTRL); 1462a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1463a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven /* Re-init htop1 */ 1464a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven if (hdmi->htop1) 1465a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven sh_hdmi_htop1_init(hdmi); 1466a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1467a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven /* Now it's safe to enable interrupts again */ 1468a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven enable_irq(hdmi->irq); 1469a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven return 0; 1470a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven} 1471a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 1472a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoevenstatic const struct dev_pm_ops sh_hdmi_pm_ops = { 1473a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven .suspend = sh_hdmi_suspend, 1474a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven .resume = sh_hdmi_resume, 1475a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven}; 1476a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven 14776011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetskistatic struct platform_driver sh_hdmi_driver = { 14786011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski .remove = __exit_p(sh_hdmi_remove), 14796011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski .driver = { 14806011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski .name = "sh-mobile-hdmi", 1481a00d91ea264f974b3d57babce143ba157921629aGeert Uytterhoeven .pm = &sh_hdmi_pm_ops, 14826011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski }, 14836011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski}; 14846011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 14853ccbf89f4d86cc8f4d6645fa5db0327ef835777bFabio Porceddamodule_platform_driver_probe(sh_hdmi_driver, sh_hdmi_probe); 14866011bdeaa6089d49c02de69f05980da7bad314abGuennadi Liakhovetski 14876011bdeaa6089d49c02de69f05980da7bad314abGuennadi LiakhovetskiMODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>"); 14886011bdeaa6089d49c02de69f05980da7bad314abGuennadi LiakhovetskiMODULE_DESCRIPTION("SuperH / ARM-shmobile HDMI driver"); 14896011bdeaa6089d49c02de69f05980da7bad314abGuennadi LiakhovetskiMODULE_LICENSE("GPL v2"); 1490