1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 26b6b6042SThierry Reding /* 36b6b6042SThierry Reding * Copyright (C) 2013 NVIDIA Corporation 46b6b6042SThierry Reding */ 56b6b6042SThierry Reding 66b6b6042SThierry Reding #include <linux/clk.h> 7b299221cSThierry Reding #include <linux/clk-provider.h> 8a82752e1SThierry Reding #include <linux/debugfs.h> 96fad8f66SThierry Reding #include <linux/gpio.h> 106b6b6042SThierry Reding #include <linux/io.h> 11eb1df694SSam Ravnborg #include <linux/module.h> 12459cc2c6SThierry Reding #include <linux/of_device.h> 136b6b6042SThierry Reding #include <linux/platform_device.h> 14aaff8bd2SThierry Reding #include <linux/pm_runtime.h> 15459cc2c6SThierry Reding #include <linux/regulator/consumer.h> 166b6b6042SThierry Reding #include <linux/reset.h> 17306a7f91SThierry Reding 187232398aSThierry Reding #include <soc/tegra/pmc.h> 196b6b6042SThierry Reding 204aa3df71SThierry Reding #include <drm/drm_atomic_helper.h> 21eb1df694SSam Ravnborg #include <drm/drm_debugfs.h> 226b6b6042SThierry Reding #include <drm/drm_dp_helper.h> 23eb1df694SSam Ravnborg #include <drm/drm_file.h> 246fad8f66SThierry Reding #include <drm/drm_panel.h> 2536e90221SThierry Reding #include <drm/drm_scdc_helper.h> 266b6b6042SThierry Reding 276b6b6042SThierry Reding #include "dc.h" 289a42c7c6SThierry Reding #include "dp.h" 296b6b6042SThierry Reding #include "drm.h" 30fad7b806SThierry Reding #include "hda.h" 316b6b6042SThierry Reding #include "sor.h" 32932f6529SThierry Reding #include "trace.h" 336b6b6042SThierry Reding 34459cc2c6SThierry Reding #define SOR_REKEY 0x38 35459cc2c6SThierry Reding 36459cc2c6SThierry Reding struct tegra_sor_hdmi_settings { 37459cc2c6SThierry Reding unsigned long frequency; 38459cc2c6SThierry Reding 39459cc2c6SThierry Reding u8 vcocap; 40c57997bcSThierry Reding u8 filter; 41459cc2c6SThierry Reding u8 ichpmp; 42459cc2c6SThierry Reding u8 loadadj; 43c57997bcSThierry Reding u8 tmds_termadj; 44c57997bcSThierry Reding u8 tx_pu_value; 45c57997bcSThierry Reding u8 bg_temp_coef; 46c57997bcSThierry Reding u8 bg_vref_level; 47c57997bcSThierry Reding u8 avdd10_level; 48c57997bcSThierry Reding u8 avdd14_level; 49c57997bcSThierry Reding u8 sparepll; 50459cc2c6SThierry Reding 51459cc2c6SThierry Reding u8 drive_current[4]; 52459cc2c6SThierry Reding u8 preemphasis[4]; 53459cc2c6SThierry Reding }; 54459cc2c6SThierry Reding 55459cc2c6SThierry Reding #if 1 56459cc2c6SThierry Reding static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = { 57459cc2c6SThierry Reding { 58459cc2c6SThierry Reding .frequency = 54000000, 59459cc2c6SThierry Reding .vcocap = 0x0, 60c57997bcSThierry Reding .filter = 0x0, 61459cc2c6SThierry Reding .ichpmp = 0x1, 62459cc2c6SThierry Reding .loadadj = 0x3, 63c57997bcSThierry Reding .tmds_termadj = 0x9, 64c57997bcSThierry Reding .tx_pu_value = 0x10, 65c57997bcSThierry Reding .bg_temp_coef = 0x3, 66c57997bcSThierry Reding .bg_vref_level = 0x8, 67c57997bcSThierry Reding .avdd10_level = 0x4, 68c57997bcSThierry Reding .avdd14_level = 0x4, 69c57997bcSThierry Reding .sparepll = 0x0, 70459cc2c6SThierry Reding .drive_current = { 0x33, 0x3a, 0x3a, 0x3a }, 71459cc2c6SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 72459cc2c6SThierry Reding }, { 73459cc2c6SThierry Reding .frequency = 75000000, 74459cc2c6SThierry Reding .vcocap = 0x3, 75c57997bcSThierry Reding .filter = 0x0, 76459cc2c6SThierry Reding .ichpmp = 0x1, 77459cc2c6SThierry Reding .loadadj = 0x3, 78c57997bcSThierry Reding .tmds_termadj = 0x9, 79c57997bcSThierry Reding .tx_pu_value = 0x40, 80c57997bcSThierry Reding .bg_temp_coef = 0x3, 81c57997bcSThierry Reding .bg_vref_level = 0x8, 82c57997bcSThierry Reding .avdd10_level = 0x4, 83c57997bcSThierry Reding .avdd14_level = 0x4, 84c57997bcSThierry Reding .sparepll = 0x0, 85459cc2c6SThierry Reding .drive_current = { 0x33, 0x3a, 0x3a, 0x3a }, 86459cc2c6SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 87459cc2c6SThierry Reding }, { 88459cc2c6SThierry Reding .frequency = 150000000, 89459cc2c6SThierry Reding .vcocap = 0x3, 90c57997bcSThierry Reding .filter = 0x0, 91459cc2c6SThierry Reding .ichpmp = 0x1, 92459cc2c6SThierry Reding .loadadj = 0x3, 93c57997bcSThierry Reding .tmds_termadj = 0x9, 94c57997bcSThierry Reding .tx_pu_value = 0x66, 95c57997bcSThierry Reding .bg_temp_coef = 0x3, 96c57997bcSThierry Reding .bg_vref_level = 0x8, 97c57997bcSThierry Reding .avdd10_level = 0x4, 98c57997bcSThierry Reding .avdd14_level = 0x4, 99c57997bcSThierry Reding .sparepll = 0x0, 100459cc2c6SThierry Reding .drive_current = { 0x33, 0x3a, 0x3a, 0x3a }, 101459cc2c6SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 102459cc2c6SThierry Reding }, { 103459cc2c6SThierry Reding .frequency = 300000000, 104459cc2c6SThierry Reding .vcocap = 0x3, 105c57997bcSThierry Reding .filter = 0x0, 106459cc2c6SThierry Reding .ichpmp = 0x1, 107459cc2c6SThierry Reding .loadadj = 0x3, 108c57997bcSThierry Reding .tmds_termadj = 0x9, 109c57997bcSThierry Reding .tx_pu_value = 0x66, 110c57997bcSThierry Reding .bg_temp_coef = 0x3, 111c57997bcSThierry Reding .bg_vref_level = 0xa, 112c57997bcSThierry Reding .avdd10_level = 0x4, 113c57997bcSThierry Reding .avdd14_level = 0x4, 114c57997bcSThierry Reding .sparepll = 0x0, 115459cc2c6SThierry Reding .drive_current = { 0x33, 0x3f, 0x3f, 0x3f }, 116459cc2c6SThierry Reding .preemphasis = { 0x00, 0x17, 0x17, 0x17 }, 117459cc2c6SThierry Reding }, { 118459cc2c6SThierry Reding .frequency = 600000000, 119459cc2c6SThierry Reding .vcocap = 0x3, 120c57997bcSThierry Reding .filter = 0x0, 121459cc2c6SThierry Reding .ichpmp = 0x1, 122459cc2c6SThierry Reding .loadadj = 0x3, 123c57997bcSThierry Reding .tmds_termadj = 0x9, 124c57997bcSThierry Reding .tx_pu_value = 0x66, 125c57997bcSThierry Reding .bg_temp_coef = 0x3, 126c57997bcSThierry Reding .bg_vref_level = 0x8, 127c57997bcSThierry Reding .avdd10_level = 0x4, 128c57997bcSThierry Reding .avdd14_level = 0x4, 129c57997bcSThierry Reding .sparepll = 0x0, 130459cc2c6SThierry Reding .drive_current = { 0x33, 0x3f, 0x3f, 0x3f }, 131459cc2c6SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 132459cc2c6SThierry Reding }, 133459cc2c6SThierry Reding }; 134459cc2c6SThierry Reding #else 135459cc2c6SThierry Reding static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = { 136459cc2c6SThierry Reding { 137459cc2c6SThierry Reding .frequency = 75000000, 138459cc2c6SThierry Reding .vcocap = 0x3, 139c57997bcSThierry Reding .filter = 0x0, 140459cc2c6SThierry Reding .ichpmp = 0x1, 141459cc2c6SThierry Reding .loadadj = 0x3, 142c57997bcSThierry Reding .tmds_termadj = 0x9, 143c57997bcSThierry Reding .tx_pu_value = 0x40, 144c57997bcSThierry Reding .bg_temp_coef = 0x3, 145c57997bcSThierry Reding .bg_vref_level = 0x8, 146c57997bcSThierry Reding .avdd10_level = 0x4, 147c57997bcSThierry Reding .avdd14_level = 0x4, 148c57997bcSThierry Reding .sparepll = 0x0, 149459cc2c6SThierry Reding .drive_current = { 0x29, 0x29, 0x29, 0x29 }, 150459cc2c6SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 151459cc2c6SThierry Reding }, { 152459cc2c6SThierry Reding .frequency = 150000000, 153459cc2c6SThierry Reding .vcocap = 0x3, 154c57997bcSThierry Reding .filter = 0x0, 155459cc2c6SThierry Reding .ichpmp = 0x1, 156459cc2c6SThierry Reding .loadadj = 0x3, 157c57997bcSThierry Reding .tmds_termadj = 0x9, 158c57997bcSThierry Reding .tx_pu_value = 0x66, 159c57997bcSThierry Reding .bg_temp_coef = 0x3, 160c57997bcSThierry Reding .bg_vref_level = 0x8, 161c57997bcSThierry Reding .avdd10_level = 0x4, 162c57997bcSThierry Reding .avdd14_level = 0x4, 163c57997bcSThierry Reding .sparepll = 0x0, 164459cc2c6SThierry Reding .drive_current = { 0x30, 0x37, 0x37, 0x37 }, 165459cc2c6SThierry Reding .preemphasis = { 0x01, 0x02, 0x02, 0x02 }, 166459cc2c6SThierry Reding }, { 167459cc2c6SThierry Reding .frequency = 300000000, 168459cc2c6SThierry Reding .vcocap = 0x3, 169c57997bcSThierry Reding .filter = 0x0, 170459cc2c6SThierry Reding .ichpmp = 0x6, 171459cc2c6SThierry Reding .loadadj = 0x3, 172c57997bcSThierry Reding .tmds_termadj = 0x9, 173c57997bcSThierry Reding .tx_pu_value = 0x66, 174c57997bcSThierry Reding .bg_temp_coef = 0x3, 175c57997bcSThierry Reding .bg_vref_level = 0xf, 176c57997bcSThierry Reding .avdd10_level = 0x4, 177c57997bcSThierry Reding .avdd14_level = 0x4, 178c57997bcSThierry Reding .sparepll = 0x0, 179459cc2c6SThierry Reding .drive_current = { 0x30, 0x37, 0x37, 0x37 }, 180459cc2c6SThierry Reding .preemphasis = { 0x10, 0x3e, 0x3e, 0x3e }, 181459cc2c6SThierry Reding }, { 182459cc2c6SThierry Reding .frequency = 600000000, 183459cc2c6SThierry Reding .vcocap = 0x3, 184c57997bcSThierry Reding .filter = 0x0, 185459cc2c6SThierry Reding .ichpmp = 0xa, 186459cc2c6SThierry Reding .loadadj = 0x3, 187c57997bcSThierry Reding .tmds_termadj = 0xb, 188c57997bcSThierry Reding .tx_pu_value = 0x66, 189c57997bcSThierry Reding .bg_temp_coef = 0x3, 190c57997bcSThierry Reding .bg_vref_level = 0xe, 191c57997bcSThierry Reding .avdd10_level = 0x4, 192c57997bcSThierry Reding .avdd14_level = 0x4, 193c57997bcSThierry Reding .sparepll = 0x0, 194459cc2c6SThierry Reding .drive_current = { 0x35, 0x3e, 0x3e, 0x3e }, 195459cc2c6SThierry Reding .preemphasis = { 0x02, 0x3f, 0x3f, 0x3f }, 196459cc2c6SThierry Reding }, 197459cc2c6SThierry Reding }; 198459cc2c6SThierry Reding #endif 199459cc2c6SThierry Reding 200c57997bcSThierry Reding static const struct tegra_sor_hdmi_settings tegra186_sor_hdmi_defaults[] = { 201c57997bcSThierry Reding { 202c57997bcSThierry Reding .frequency = 54000000, 203c57997bcSThierry Reding .vcocap = 0, 204c57997bcSThierry Reding .filter = 5, 205c57997bcSThierry Reding .ichpmp = 5, 206c57997bcSThierry Reding .loadadj = 3, 207c57997bcSThierry Reding .tmds_termadj = 0xf, 208c57997bcSThierry Reding .tx_pu_value = 0, 209c57997bcSThierry Reding .bg_temp_coef = 3, 210c57997bcSThierry Reding .bg_vref_level = 8, 211c57997bcSThierry Reding .avdd10_level = 4, 212c57997bcSThierry Reding .avdd14_level = 4, 213c57997bcSThierry Reding .sparepll = 0x54, 214c57997bcSThierry Reding .drive_current = { 0x3a, 0x3a, 0x3a, 0x33 }, 215c57997bcSThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 216c57997bcSThierry Reding }, { 217c57997bcSThierry Reding .frequency = 75000000, 218c57997bcSThierry Reding .vcocap = 1, 219c57997bcSThierry Reding .filter = 5, 220c57997bcSThierry Reding .ichpmp = 5, 221c57997bcSThierry Reding .loadadj = 3, 222c57997bcSThierry Reding .tmds_termadj = 0xf, 223c57997bcSThierry Reding .tx_pu_value = 0, 224c57997bcSThierry Reding .bg_temp_coef = 3, 225c57997bcSThierry Reding .bg_vref_level = 8, 226c57997bcSThierry Reding .avdd10_level = 4, 227c57997bcSThierry Reding .avdd14_level = 4, 228c57997bcSThierry Reding .sparepll = 0x44, 229c57997bcSThierry Reding .drive_current = { 0x3a, 0x3a, 0x3a, 0x33 }, 230c57997bcSThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 231c57997bcSThierry Reding }, { 232c57997bcSThierry Reding .frequency = 150000000, 233c57997bcSThierry Reding .vcocap = 3, 234c57997bcSThierry Reding .filter = 5, 235c57997bcSThierry Reding .ichpmp = 5, 236c57997bcSThierry Reding .loadadj = 3, 237c57997bcSThierry Reding .tmds_termadj = 15, 238c57997bcSThierry Reding .tx_pu_value = 0x66 /* 0 */, 239c57997bcSThierry Reding .bg_temp_coef = 3, 240c57997bcSThierry Reding .bg_vref_level = 8, 241c57997bcSThierry Reding .avdd10_level = 4, 242c57997bcSThierry Reding .avdd14_level = 4, 243c57997bcSThierry Reding .sparepll = 0x00, /* 0x34 */ 244c57997bcSThierry Reding .drive_current = { 0x3a, 0x3a, 0x3a, 0x37 }, 245c57997bcSThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 246c57997bcSThierry Reding }, { 247c57997bcSThierry Reding .frequency = 300000000, 248c57997bcSThierry Reding .vcocap = 3, 249c57997bcSThierry Reding .filter = 5, 250c57997bcSThierry Reding .ichpmp = 5, 251c57997bcSThierry Reding .loadadj = 3, 252c57997bcSThierry Reding .tmds_termadj = 15, 253c57997bcSThierry Reding .tx_pu_value = 64, 254c57997bcSThierry Reding .bg_temp_coef = 3, 255c57997bcSThierry Reding .bg_vref_level = 8, 256c57997bcSThierry Reding .avdd10_level = 4, 257c57997bcSThierry Reding .avdd14_level = 4, 258c57997bcSThierry Reding .sparepll = 0x34, 259c57997bcSThierry Reding .drive_current = { 0x3d, 0x3d, 0x3d, 0x33 }, 260c57997bcSThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 261c57997bcSThierry Reding }, { 262c57997bcSThierry Reding .frequency = 600000000, 263c57997bcSThierry Reding .vcocap = 3, 264c57997bcSThierry Reding .filter = 5, 265c57997bcSThierry Reding .ichpmp = 5, 266c57997bcSThierry Reding .loadadj = 3, 267c57997bcSThierry Reding .tmds_termadj = 12, 268c57997bcSThierry Reding .tx_pu_value = 96, 269c57997bcSThierry Reding .bg_temp_coef = 3, 270c57997bcSThierry Reding .bg_vref_level = 8, 271c57997bcSThierry Reding .avdd10_level = 4, 272c57997bcSThierry Reding .avdd14_level = 4, 273c57997bcSThierry Reding .sparepll = 0x34, 274c57997bcSThierry Reding .drive_current = { 0x3d, 0x3d, 0x3d, 0x33 }, 275c57997bcSThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 276c57997bcSThierry Reding } 277c57997bcSThierry Reding }; 278c57997bcSThierry Reding 2799b6c14b8SThierry Reding static const struct tegra_sor_hdmi_settings tegra194_sor_hdmi_defaults[] = { 2809b6c14b8SThierry Reding { 2819b6c14b8SThierry Reding .frequency = 54000000, 2829b6c14b8SThierry Reding .vcocap = 0, 2839b6c14b8SThierry Reding .filter = 5, 2849b6c14b8SThierry Reding .ichpmp = 5, 2859b6c14b8SThierry Reding .loadadj = 3, 2869b6c14b8SThierry Reding .tmds_termadj = 0xf, 2879b6c14b8SThierry Reding .tx_pu_value = 0, 2889b6c14b8SThierry Reding .bg_temp_coef = 3, 2899b6c14b8SThierry Reding .bg_vref_level = 8, 2909b6c14b8SThierry Reding .avdd10_level = 4, 2919b6c14b8SThierry Reding .avdd14_level = 4, 2929b6c14b8SThierry Reding .sparepll = 0x54, 2939b6c14b8SThierry Reding .drive_current = { 0x3a, 0x3a, 0x3a, 0x33 }, 2949b6c14b8SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 2959b6c14b8SThierry Reding }, { 2969b6c14b8SThierry Reding .frequency = 75000000, 2979b6c14b8SThierry Reding .vcocap = 1, 2989b6c14b8SThierry Reding .filter = 5, 2999b6c14b8SThierry Reding .ichpmp = 5, 3009b6c14b8SThierry Reding .loadadj = 3, 3019b6c14b8SThierry Reding .tmds_termadj = 0xf, 3029b6c14b8SThierry Reding .tx_pu_value = 0, 3039b6c14b8SThierry Reding .bg_temp_coef = 3, 3049b6c14b8SThierry Reding .bg_vref_level = 8, 3059b6c14b8SThierry Reding .avdd10_level = 4, 3069b6c14b8SThierry Reding .avdd14_level = 4, 3079b6c14b8SThierry Reding .sparepll = 0x44, 3089b6c14b8SThierry Reding .drive_current = { 0x3a, 0x3a, 0x3a, 0x33 }, 3099b6c14b8SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 3109b6c14b8SThierry Reding }, { 3119b6c14b8SThierry Reding .frequency = 150000000, 3129b6c14b8SThierry Reding .vcocap = 3, 3139b6c14b8SThierry Reding .filter = 5, 3149b6c14b8SThierry Reding .ichpmp = 5, 3159b6c14b8SThierry Reding .loadadj = 3, 3169b6c14b8SThierry Reding .tmds_termadj = 15, 3179b6c14b8SThierry Reding .tx_pu_value = 0x66 /* 0 */, 3189b6c14b8SThierry Reding .bg_temp_coef = 3, 3199b6c14b8SThierry Reding .bg_vref_level = 8, 3209b6c14b8SThierry Reding .avdd10_level = 4, 3219b6c14b8SThierry Reding .avdd14_level = 4, 3229b6c14b8SThierry Reding .sparepll = 0x00, /* 0x34 */ 3239b6c14b8SThierry Reding .drive_current = { 0x3a, 0x3a, 0x3a, 0x37 }, 3249b6c14b8SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 3259b6c14b8SThierry Reding }, { 3269b6c14b8SThierry Reding .frequency = 300000000, 3279b6c14b8SThierry Reding .vcocap = 3, 3289b6c14b8SThierry Reding .filter = 5, 3299b6c14b8SThierry Reding .ichpmp = 5, 3309b6c14b8SThierry Reding .loadadj = 3, 3319b6c14b8SThierry Reding .tmds_termadj = 15, 3329b6c14b8SThierry Reding .tx_pu_value = 64, 3339b6c14b8SThierry Reding .bg_temp_coef = 3, 3349b6c14b8SThierry Reding .bg_vref_level = 8, 3359b6c14b8SThierry Reding .avdd10_level = 4, 3369b6c14b8SThierry Reding .avdd14_level = 4, 3379b6c14b8SThierry Reding .sparepll = 0x34, 3389b6c14b8SThierry Reding .drive_current = { 0x3d, 0x3d, 0x3d, 0x33 }, 3399b6c14b8SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 3409b6c14b8SThierry Reding }, { 3419b6c14b8SThierry Reding .frequency = 600000000, 3429b6c14b8SThierry Reding .vcocap = 3, 3439b6c14b8SThierry Reding .filter = 5, 3449b6c14b8SThierry Reding .ichpmp = 5, 3459b6c14b8SThierry Reding .loadadj = 3, 3469b6c14b8SThierry Reding .tmds_termadj = 12, 3479b6c14b8SThierry Reding .tx_pu_value = 96, 3489b6c14b8SThierry Reding .bg_temp_coef = 3, 3499b6c14b8SThierry Reding .bg_vref_level = 8, 3509b6c14b8SThierry Reding .avdd10_level = 4, 3519b6c14b8SThierry Reding .avdd14_level = 4, 3529b6c14b8SThierry Reding .sparepll = 0x34, 3539b6c14b8SThierry Reding .drive_current = { 0x3d, 0x3d, 0x3d, 0x33 }, 3549b6c14b8SThierry Reding .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, 3559b6c14b8SThierry Reding } 3569b6c14b8SThierry Reding }; 3579b6c14b8SThierry Reding 358880cee0bSThierry Reding struct tegra_sor_regs { 359880cee0bSThierry Reding unsigned int head_state0; 360880cee0bSThierry Reding unsigned int head_state1; 361880cee0bSThierry Reding unsigned int head_state2; 362880cee0bSThierry Reding unsigned int head_state3; 363880cee0bSThierry Reding unsigned int head_state4; 364880cee0bSThierry Reding unsigned int head_state5; 365880cee0bSThierry Reding unsigned int pll0; 366880cee0bSThierry Reding unsigned int pll1; 367880cee0bSThierry Reding unsigned int pll2; 368880cee0bSThierry Reding unsigned int pll3; 369880cee0bSThierry Reding unsigned int dp_padctl0; 370880cee0bSThierry Reding unsigned int dp_padctl2; 371880cee0bSThierry Reding }; 372880cee0bSThierry Reding 373459cc2c6SThierry Reding struct tegra_sor_soc { 374459cc2c6SThierry Reding bool supports_lvds; 375459cc2c6SThierry Reding bool supports_hdmi; 376459cc2c6SThierry Reding bool supports_dp; 377d278e4a9SThierry Reding bool supports_audio; 378d278e4a9SThierry Reding bool supports_hdcp; 379459cc2c6SThierry Reding 380880cee0bSThierry Reding const struct tegra_sor_regs *regs; 381c57997bcSThierry Reding bool has_nvdisplay; 382880cee0bSThierry Reding 383459cc2c6SThierry Reding const struct tegra_sor_hdmi_settings *settings; 384459cc2c6SThierry Reding unsigned int num_settings; 38530b49435SThierry Reding 38630b49435SThierry Reding const u8 *xbar_cfg; 387c1763937SThierry Reding const u8 *lane_map; 388c1763937SThierry Reding 389c1763937SThierry Reding const u8 (*voltage_swing)[4][4]; 390c1763937SThierry Reding const u8 (*pre_emphasis)[4][4]; 391c1763937SThierry Reding const u8 (*post_cursor)[4][4]; 392c1763937SThierry Reding const u8 (*tx_pu)[4][4]; 393459cc2c6SThierry Reding }; 394459cc2c6SThierry Reding 395459cc2c6SThierry Reding struct tegra_sor; 396459cc2c6SThierry Reding 397459cc2c6SThierry Reding struct tegra_sor_ops { 398459cc2c6SThierry Reding const char *name; 399459cc2c6SThierry Reding int (*probe)(struct tegra_sor *sor); 400459cc2c6SThierry Reding int (*remove)(struct tegra_sor *sor); 40185d0c4b5SThierry Reding void (*audio_enable)(struct tegra_sor *sor); 40285d0c4b5SThierry Reding void (*audio_disable)(struct tegra_sor *sor); 403459cc2c6SThierry Reding }; 404459cc2c6SThierry Reding 4056b6b6042SThierry Reding struct tegra_sor { 4066b6b6042SThierry Reding struct host1x_client client; 4076b6b6042SThierry Reding struct tegra_output output; 4086b6b6042SThierry Reding struct device *dev; 4096b6b6042SThierry Reding 410459cc2c6SThierry Reding const struct tegra_sor_soc *soc; 4116b6b6042SThierry Reding void __iomem *regs; 412c57997bcSThierry Reding unsigned int index; 4138e2988a7SThierry Reding unsigned int irq; 4146b6b6042SThierry Reding 4156b6b6042SThierry Reding struct reset_control *rst; 4166b6b6042SThierry Reding struct clk *clk_parent; 4176b6b6042SThierry Reding struct clk *clk_safe; 418e1335e2fSThierry Reding struct clk *clk_out; 419e1335e2fSThierry Reding struct clk *clk_pad; 4206b6b6042SThierry Reding struct clk *clk_dp; 4216b6b6042SThierry Reding struct clk *clk; 4226b6b6042SThierry Reding 4236d6c815dSThierry Reding u8 xbar_cfg[5]; 4246d6c815dSThierry Reding 425c1763937SThierry Reding struct drm_dp_link link; 4269542c237SThierry Reding struct drm_dp_aux *aux; 4276b6b6042SThierry Reding 428dab16336SThierry Reding struct drm_info_list *debugfs_files; 429459cc2c6SThierry Reding 430459cc2c6SThierry Reding const struct tegra_sor_ops *ops; 431c57997bcSThierry Reding enum tegra_io_pad pad; 432459cc2c6SThierry Reding 433459cc2c6SThierry Reding /* for HDMI 2.0 */ 434459cc2c6SThierry Reding struct tegra_sor_hdmi_settings *settings; 435459cc2c6SThierry Reding unsigned int num_settings; 436459cc2c6SThierry Reding 437459cc2c6SThierry Reding struct regulator *avdd_io_supply; 438459cc2c6SThierry Reding struct regulator *vdd_pll_supply; 439459cc2c6SThierry Reding struct regulator *hdmi_supply; 44036e90221SThierry Reding 44136e90221SThierry Reding struct delayed_work scdc; 44236e90221SThierry Reding bool scdc_enabled; 4438e2988a7SThierry Reding 444fad7b806SThierry Reding struct tegra_hda_format format; 4456b6b6042SThierry Reding }; 4466b6b6042SThierry Reding 447c31efa7aSThierry Reding struct tegra_sor_state { 448c31efa7aSThierry Reding struct drm_connector_state base; 449c31efa7aSThierry Reding 45036e90221SThierry Reding unsigned int link_speed; 45136e90221SThierry Reding unsigned long pclk; 452c31efa7aSThierry Reding unsigned int bpc; 453c31efa7aSThierry Reding }; 454c31efa7aSThierry Reding 455c31efa7aSThierry Reding static inline struct tegra_sor_state * 456c31efa7aSThierry Reding to_sor_state(struct drm_connector_state *state) 457c31efa7aSThierry Reding { 458c31efa7aSThierry Reding return container_of(state, struct tegra_sor_state, base); 459c31efa7aSThierry Reding } 460c31efa7aSThierry Reding 46134fa183bSThierry Reding struct tegra_sor_config { 46234fa183bSThierry Reding u32 bits_per_pixel; 46334fa183bSThierry Reding 46434fa183bSThierry Reding u32 active_polarity; 46534fa183bSThierry Reding u32 active_count; 46634fa183bSThierry Reding u32 tu_size; 46734fa183bSThierry Reding u32 active_frac; 46834fa183bSThierry Reding u32 watermark; 4697890b576SThierry Reding 4707890b576SThierry Reding u32 hblank_symbols; 4717890b576SThierry Reding u32 vblank_symbols; 47234fa183bSThierry Reding }; 47334fa183bSThierry Reding 4746b6b6042SThierry Reding static inline struct tegra_sor * 4756b6b6042SThierry Reding host1x_client_to_sor(struct host1x_client *client) 4766b6b6042SThierry Reding { 4776b6b6042SThierry Reding return container_of(client, struct tegra_sor, client); 4786b6b6042SThierry Reding } 4796b6b6042SThierry Reding 4806b6b6042SThierry Reding static inline struct tegra_sor *to_sor(struct tegra_output *output) 4816b6b6042SThierry Reding { 4826b6b6042SThierry Reding return container_of(output, struct tegra_sor, output); 4836b6b6042SThierry Reding } 4846b6b6042SThierry Reding 4855c5f1301SThierry Reding static inline u32 tegra_sor_readl(struct tegra_sor *sor, unsigned int offset) 4866b6b6042SThierry Reding { 487932f6529SThierry Reding u32 value = readl(sor->regs + (offset << 2)); 488932f6529SThierry Reding 489932f6529SThierry Reding trace_sor_readl(sor->dev, offset, value); 490932f6529SThierry Reding 491932f6529SThierry Reding return value; 4926b6b6042SThierry Reding } 4936b6b6042SThierry Reding 49428fe2076SThierry Reding static inline void tegra_sor_writel(struct tegra_sor *sor, u32 value, 4955c5f1301SThierry Reding unsigned int offset) 4966b6b6042SThierry Reding { 497932f6529SThierry Reding trace_sor_writel(sor->dev, offset, value); 4986b6b6042SThierry Reding writel(value, sor->regs + (offset << 2)); 4996b6b6042SThierry Reding } 5006b6b6042SThierry Reding 50125bb2cecSThierry Reding static int tegra_sor_set_parent_clock(struct tegra_sor *sor, struct clk *parent) 50225bb2cecSThierry Reding { 50325bb2cecSThierry Reding int err; 50425bb2cecSThierry Reding 50525bb2cecSThierry Reding clk_disable_unprepare(sor->clk); 50625bb2cecSThierry Reding 507e1335e2fSThierry Reding err = clk_set_parent(sor->clk_out, parent); 50825bb2cecSThierry Reding if (err < 0) 50925bb2cecSThierry Reding return err; 51025bb2cecSThierry Reding 51125bb2cecSThierry Reding err = clk_prepare_enable(sor->clk); 51225bb2cecSThierry Reding if (err < 0) 51325bb2cecSThierry Reding return err; 51425bb2cecSThierry Reding 51525bb2cecSThierry Reding return 0; 51625bb2cecSThierry Reding } 51725bb2cecSThierry Reding 518e1335e2fSThierry Reding struct tegra_clk_sor_pad { 519b299221cSThierry Reding struct clk_hw hw; 520b299221cSThierry Reding struct tegra_sor *sor; 521b299221cSThierry Reding }; 522b299221cSThierry Reding 523e1335e2fSThierry Reding static inline struct tegra_clk_sor_pad *to_pad(struct clk_hw *hw) 524b299221cSThierry Reding { 525e1335e2fSThierry Reding return container_of(hw, struct tegra_clk_sor_pad, hw); 526b299221cSThierry Reding } 527b299221cSThierry Reding 5284bdf4710SThierry Reding static const char * const tegra_clk_sor_pad_parents[2][2] = { 5294bdf4710SThierry Reding { "pll_d_out0", "pll_dp" }, 5304bdf4710SThierry Reding { "pll_d2_out0", "pll_dp" }, 531b299221cSThierry Reding }; 532b299221cSThierry Reding 53361417aaaSThierry Reding /* 53461417aaaSThierry Reding * Implementing ->set_parent() here isn't really required because the parent 53561417aaaSThierry Reding * will be explicitly selected in the driver code via the DP_CLK_SEL mux in 53661417aaaSThierry Reding * the SOR_CLK_CNTRL register. This is primarily for compatibility with the 53761417aaaSThierry Reding * Tegra186 and later SoC generations where the BPMP implements this clock 53861417aaaSThierry Reding * and doesn't expose the mux via the common clock framework. 53961417aaaSThierry Reding */ 54061417aaaSThierry Reding 541e1335e2fSThierry Reding static int tegra_clk_sor_pad_set_parent(struct clk_hw *hw, u8 index) 542b299221cSThierry Reding { 543e1335e2fSThierry Reding struct tegra_clk_sor_pad *pad = to_pad(hw); 544e1335e2fSThierry Reding struct tegra_sor *sor = pad->sor; 545b299221cSThierry Reding u32 value; 546b299221cSThierry Reding 547b299221cSThierry Reding value = tegra_sor_readl(sor, SOR_CLK_CNTRL); 548b299221cSThierry Reding value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; 549b299221cSThierry Reding 550b299221cSThierry Reding switch (index) { 551b299221cSThierry Reding case 0: 552b299221cSThierry Reding value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK; 553b299221cSThierry Reding break; 554b299221cSThierry Reding 555b299221cSThierry Reding case 1: 556b299221cSThierry Reding value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK; 557b299221cSThierry Reding break; 558b299221cSThierry Reding } 559b299221cSThierry Reding 560b299221cSThierry Reding tegra_sor_writel(sor, value, SOR_CLK_CNTRL); 561b299221cSThierry Reding 562b299221cSThierry Reding return 0; 563b299221cSThierry Reding } 564b299221cSThierry Reding 565e1335e2fSThierry Reding static u8 tegra_clk_sor_pad_get_parent(struct clk_hw *hw) 566b299221cSThierry Reding { 567e1335e2fSThierry Reding struct tegra_clk_sor_pad *pad = to_pad(hw); 568e1335e2fSThierry Reding struct tegra_sor *sor = pad->sor; 569b299221cSThierry Reding u8 parent = U8_MAX; 570b299221cSThierry Reding u32 value; 571b299221cSThierry Reding 572b299221cSThierry Reding value = tegra_sor_readl(sor, SOR_CLK_CNTRL); 573b299221cSThierry Reding 574b299221cSThierry Reding switch (value & SOR_CLK_CNTRL_DP_CLK_SEL_MASK) { 575b299221cSThierry Reding case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK: 576b299221cSThierry Reding case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_PCLK: 577b299221cSThierry Reding parent = 0; 578b299221cSThierry Reding break; 579b299221cSThierry Reding 580b299221cSThierry Reding case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK: 581b299221cSThierry Reding case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK: 582b299221cSThierry Reding parent = 1; 583b299221cSThierry Reding break; 584b299221cSThierry Reding } 585b299221cSThierry Reding 586b299221cSThierry Reding return parent; 587b299221cSThierry Reding } 588b299221cSThierry Reding 589e1335e2fSThierry Reding static const struct clk_ops tegra_clk_sor_pad_ops = { 590e1335e2fSThierry Reding .set_parent = tegra_clk_sor_pad_set_parent, 591e1335e2fSThierry Reding .get_parent = tegra_clk_sor_pad_get_parent, 592b299221cSThierry Reding }; 593b299221cSThierry Reding 594e1335e2fSThierry Reding static struct clk *tegra_clk_sor_pad_register(struct tegra_sor *sor, 595b299221cSThierry Reding const char *name) 596b299221cSThierry Reding { 597e1335e2fSThierry Reding struct tegra_clk_sor_pad *pad; 598b299221cSThierry Reding struct clk_init_data init; 599b299221cSThierry Reding struct clk *clk; 600b299221cSThierry Reding 601e1335e2fSThierry Reding pad = devm_kzalloc(sor->dev, sizeof(*pad), GFP_KERNEL); 602e1335e2fSThierry Reding if (!pad) 603b299221cSThierry Reding return ERR_PTR(-ENOMEM); 604b299221cSThierry Reding 605e1335e2fSThierry Reding pad->sor = sor; 606b299221cSThierry Reding 607b299221cSThierry Reding init.name = name; 608b299221cSThierry Reding init.flags = 0; 6094bdf4710SThierry Reding init.parent_names = tegra_clk_sor_pad_parents[sor->index]; 6104bdf4710SThierry Reding init.num_parents = ARRAY_SIZE(tegra_clk_sor_pad_parents[sor->index]); 611e1335e2fSThierry Reding init.ops = &tegra_clk_sor_pad_ops; 612b299221cSThierry Reding 613e1335e2fSThierry Reding pad->hw.init = &init; 614b299221cSThierry Reding 615e1335e2fSThierry Reding clk = devm_clk_register(sor->dev, &pad->hw); 616b299221cSThierry Reding 617b299221cSThierry Reding return clk; 618b299221cSThierry Reding } 619b299221cSThierry Reding 620c9533131SThierry Reding static void tegra_sor_filter_rates(struct tegra_sor *sor) 621c9533131SThierry Reding { 622c9533131SThierry Reding struct drm_dp_link *link = &sor->link; 623c9533131SThierry Reding unsigned int i; 624c9533131SThierry Reding 625c9533131SThierry Reding /* Tegra only supports RBR, HBR and HBR2 */ 626c9533131SThierry Reding for (i = 0; i < link->num_rates; i++) { 627c9533131SThierry Reding switch (link->rates[i]) { 628c9533131SThierry Reding case 1620000: 629c9533131SThierry Reding case 2700000: 630c9533131SThierry Reding case 5400000: 631c9533131SThierry Reding break; 632c9533131SThierry Reding 633c9533131SThierry Reding default: 634c9533131SThierry Reding DRM_DEBUG_KMS("link rate %lu kHz not supported\n", 635c9533131SThierry Reding link->rates[i]); 636c9533131SThierry Reding link->rates[i] = 0; 637c9533131SThierry Reding break; 638c9533131SThierry Reding } 639c9533131SThierry Reding } 640c9533131SThierry Reding 641c9533131SThierry Reding drm_dp_link_update_rates(link); 642c9533131SThierry Reding } 643c9533131SThierry Reding 644c1763937SThierry Reding static int tegra_sor_power_up_lanes(struct tegra_sor *sor, unsigned int lanes) 6456b6b6042SThierry Reding { 646c1763937SThierry Reding unsigned long timeout; 64728fe2076SThierry Reding u32 value; 6486b6b6042SThierry Reding 649c1763937SThierry Reding /* 650c1763937SThierry Reding * Clear or set the PD_TXD bit corresponding to each lane, depending 651c1763937SThierry Reding * on whether it is used or not. 652c1763937SThierry Reding */ 653880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 654c1763937SThierry Reding 655c1763937SThierry Reding if (lanes <= 2) 656c1763937SThierry Reding value &= ~(SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[3]) | 657c1763937SThierry Reding SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[2])); 658c1763937SThierry Reding else 659c1763937SThierry Reding value |= SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[3]) | 660c1763937SThierry Reding SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[2]); 661c1763937SThierry Reding 662c1763937SThierry Reding if (lanes <= 1) 663c1763937SThierry Reding value &= ~SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[1]); 664c1763937SThierry Reding else 665c1763937SThierry Reding value |= SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[1]); 666c1763937SThierry Reding 667c1763937SThierry Reding if (lanes == 0) 668c1763937SThierry Reding value &= ~SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[0]); 669c1763937SThierry Reding else 670c1763937SThierry Reding value |= SOR_DP_PADCTL_PD_TXD(sor->soc->lane_map[0]); 671c1763937SThierry Reding 672880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 6736b6b6042SThierry Reding 674c1763937SThierry Reding /* start lane sequencer */ 675c1763937SThierry Reding value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | 676c1763937SThierry Reding SOR_LANE_SEQ_CTL_POWER_STATE_UP; 677c1763937SThierry Reding tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); 678c1763937SThierry Reding 679c1763937SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 680c1763937SThierry Reding 681c1763937SThierry Reding while (time_before(jiffies, timeout)) { 682c1763937SThierry Reding value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); 683c1763937SThierry Reding if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) 684c1763937SThierry Reding break; 685c1763937SThierry Reding 686c1763937SThierry Reding usleep_range(250, 1000); 687c1763937SThierry Reding } 688c1763937SThierry Reding 689c1763937SThierry Reding if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0) 690c1763937SThierry Reding return -ETIMEDOUT; 691c1763937SThierry Reding 692c1763937SThierry Reding return 0; 693c1763937SThierry Reding } 694c1763937SThierry Reding 695c1763937SThierry Reding static int tegra_sor_power_down_lanes(struct tegra_sor *sor) 696c1763937SThierry Reding { 697c1763937SThierry Reding unsigned long timeout; 698c1763937SThierry Reding u32 value; 699c1763937SThierry Reding 700c1763937SThierry Reding /* power down all lanes */ 701880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 702c1763937SThierry Reding value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 | 703c1763937SThierry Reding SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2); 704880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 7056b6b6042SThierry Reding 706c1763937SThierry Reding /* start lane sequencer */ 707c1763937SThierry Reding value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP | 708c1763937SThierry Reding SOR_LANE_SEQ_CTL_POWER_STATE_DOWN; 709c1763937SThierry Reding tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); 710c1763937SThierry Reding 711c1763937SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 712c1763937SThierry Reding 713c1763937SThierry Reding while (time_before(jiffies, timeout)) { 714c1763937SThierry Reding value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); 715c1763937SThierry Reding if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) 716c1763937SThierry Reding break; 717c1763937SThierry Reding 718c1763937SThierry Reding usleep_range(25, 100); 719c1763937SThierry Reding } 720c1763937SThierry Reding 721c1763937SThierry Reding if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0) 722c1763937SThierry Reding return -ETIMEDOUT; 723c1763937SThierry Reding 724c1763937SThierry Reding return 0; 725c1763937SThierry Reding } 726c1763937SThierry Reding 727c1763937SThierry Reding static void tegra_sor_dp_precharge(struct tegra_sor *sor, unsigned int lanes) 728c1763937SThierry Reding { 729c1763937SThierry Reding u32 value; 730c1763937SThierry Reding 731c1763937SThierry Reding /* pre-charge all used lanes */ 732c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 733c1763937SThierry Reding 734c1763937SThierry Reding if (lanes <= 2) 735c1763937SThierry Reding value &= ~(SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[3]) | 736c1763937SThierry Reding SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[2])); 737c1763937SThierry Reding else 738c1763937SThierry Reding value |= SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[3]) | 739c1763937SThierry Reding SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[2]); 740c1763937SThierry Reding 741c1763937SThierry Reding if (lanes <= 1) 742c1763937SThierry Reding value &= ~SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[1]); 743c1763937SThierry Reding else 744c1763937SThierry Reding value |= SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[1]); 745c1763937SThierry Reding 746c1763937SThierry Reding if (lanes == 0) 747c1763937SThierry Reding value &= ~SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[0]); 748c1763937SThierry Reding else 749c1763937SThierry Reding value |= SOR_DP_PADCTL_CM_TXD(sor->soc->lane_map[0]); 750c1763937SThierry Reding 751c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 752c1763937SThierry Reding 753c1763937SThierry Reding usleep_range(15, 100); 7546b6b6042SThierry Reding 755880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 7566b6b6042SThierry Reding value &= ~(SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 | 7576b6b6042SThierry Reding SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0); 758880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 7596b6b6042SThierry Reding } 7606b6b6042SThierry Reding 761c1763937SThierry Reding static void tegra_sor_dp_term_calibrate(struct tegra_sor *sor) 762c1763937SThierry Reding { 763c1763937SThierry Reding u32 mask = 0x08, adj = 0, value; 7646b6b6042SThierry Reding 765c1763937SThierry Reding /* enable pad calibration logic */ 766c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 767c1763937SThierry Reding value &= ~SOR_DP_PADCTL_PAD_CAL_PD; 768c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 7696b6b6042SThierry Reding 770c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll1); 771c1763937SThierry Reding value |= SOR_PLL1_TMDS_TERM; 772c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll1); 7736b6b6042SThierry Reding 774c1763937SThierry Reding while (mask) { 775c1763937SThierry Reding adj |= mask; 7766b6b6042SThierry Reding 777c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll1); 778c1763937SThierry Reding value &= ~SOR_PLL1_TMDS_TERMADJ_MASK; 779c1763937SThierry Reding value |= SOR_PLL1_TMDS_TERMADJ(adj); 780c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll1); 781c1763937SThierry Reding 782c1763937SThierry Reding usleep_range(100, 200); 783c1763937SThierry Reding 784c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll1); 785c1763937SThierry Reding if (value & SOR_PLL1_TERM_COMPOUT) 786c1763937SThierry Reding adj &= ~mask; 787c1763937SThierry Reding 788c1763937SThierry Reding mask >>= 1; 7896b6b6042SThierry Reding } 7906b6b6042SThierry Reding 791c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll1); 792c1763937SThierry Reding value &= ~SOR_PLL1_TMDS_TERMADJ_MASK; 793c1763937SThierry Reding value |= SOR_PLL1_TMDS_TERMADJ(adj); 794c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll1); 7956b6b6042SThierry Reding 796c1763937SThierry Reding /* disable pad calibration logic */ 797c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 798c1763937SThierry Reding value |= SOR_DP_PADCTL_PAD_CAL_PD; 799c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 800c1763937SThierry Reding } 8016b6b6042SThierry Reding 802c1763937SThierry Reding static int tegra_sor_dp_link_apply_training(struct drm_dp_link *link) 803c1763937SThierry Reding { 804c1763937SThierry Reding struct tegra_sor *sor = container_of(link, struct tegra_sor, link); 805c1763937SThierry Reding u32 voltage_swing = 0, pre_emphasis = 0, post_cursor = 0; 806c1763937SThierry Reding const struct tegra_sor_soc *soc = sor->soc; 807c1763937SThierry Reding u32 pattern = 0, tx_pu = 0, value; 808c1763937SThierry Reding unsigned int i; 8096b6b6042SThierry Reding 810c1763937SThierry Reding for (value = 0, i = 0; i < link->lanes; i++) { 811c1763937SThierry Reding u8 vs = link->train.request.voltage_swing[i]; 812c1763937SThierry Reding u8 pe = link->train.request.pre_emphasis[i]; 813c1763937SThierry Reding u8 pc = link->train.request.post_cursor[i]; 814c1763937SThierry Reding u8 shift = sor->soc->lane_map[i] << 3; 815c1763937SThierry Reding 816c1763937SThierry Reding voltage_swing |= soc->voltage_swing[pc][vs][pe] << shift; 817c1763937SThierry Reding pre_emphasis |= soc->pre_emphasis[pc][vs][pe] << shift; 818c1763937SThierry Reding post_cursor |= soc->post_cursor[pc][vs][pe] << shift; 819c1763937SThierry Reding 820c1763937SThierry Reding if (sor->soc->tx_pu[pc][vs][pe] > tx_pu) 821c1763937SThierry Reding tx_pu = sor->soc->tx_pu[pc][vs][pe]; 822c1763937SThierry Reding 823c1763937SThierry Reding switch (link->train.pattern) { 824c1763937SThierry Reding case DP_TRAINING_PATTERN_DISABLE: 825c1763937SThierry Reding value = SOR_DP_TPG_SCRAMBLER_GALIOS | 8266b6b6042SThierry Reding SOR_DP_TPG_PATTERN_NONE; 827c1763937SThierry Reding break; 828c1763937SThierry Reding 829c1763937SThierry Reding case DP_TRAINING_PATTERN_1: 830c1763937SThierry Reding value = SOR_DP_TPG_SCRAMBLER_NONE | 831c1763937SThierry Reding SOR_DP_TPG_PATTERN_TRAIN1; 832c1763937SThierry Reding break; 833c1763937SThierry Reding 834c1763937SThierry Reding case DP_TRAINING_PATTERN_2: 835c1763937SThierry Reding value = SOR_DP_TPG_SCRAMBLER_NONE | 836c1763937SThierry Reding SOR_DP_TPG_PATTERN_TRAIN2; 837c1763937SThierry Reding break; 838c1763937SThierry Reding 839c1763937SThierry Reding case DP_TRAINING_PATTERN_3: 840c1763937SThierry Reding value = SOR_DP_TPG_SCRAMBLER_NONE | 841c1763937SThierry Reding SOR_DP_TPG_PATTERN_TRAIN3; 842c1763937SThierry Reding break; 843c1763937SThierry Reding 844c1763937SThierry Reding default: 845c1763937SThierry Reding return -EINVAL; 8466b6b6042SThierry Reding } 8476b6b6042SThierry Reding 848c1763937SThierry Reding if (link->caps.channel_coding) 849c1763937SThierry Reding value |= SOR_DP_TPG_CHANNEL_CODING; 8506b6b6042SThierry Reding 851c1763937SThierry Reding pattern = pattern << 8 | value; 852c1763937SThierry Reding } 8536b6b6042SThierry Reding 854c1763937SThierry Reding tegra_sor_writel(sor, voltage_swing, SOR_LANE_DRIVE_CURRENT0); 855c1763937SThierry Reding tegra_sor_writel(sor, pre_emphasis, SOR_LANE_PREEMPHASIS0); 856c1763937SThierry Reding 857c1763937SThierry Reding if (link->caps.tps3_supported) 858c1763937SThierry Reding tegra_sor_writel(sor, post_cursor, SOR_LANE_POSTCURSOR0); 859c1763937SThierry Reding 860c1763937SThierry Reding tegra_sor_writel(sor, pattern, SOR_DP_TPG); 861c1763937SThierry Reding 862c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 863c1763937SThierry Reding value &= ~SOR_DP_PADCTL_TX_PU_MASK; 864c1763937SThierry Reding value |= SOR_DP_PADCTL_TX_PU_ENABLE; 865c1763937SThierry Reding value |= SOR_DP_PADCTL_TX_PU(tx_pu); 866c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 867c1763937SThierry Reding 868c1763937SThierry Reding usleep_range(20, 100); 8696b6b6042SThierry Reding 8706b6b6042SThierry Reding return 0; 8716b6b6042SThierry Reding } 8726b6b6042SThierry Reding 873c1763937SThierry Reding static int tegra_sor_dp_link_configure(struct drm_dp_link *link) 874c1763937SThierry Reding { 875c1763937SThierry Reding struct tegra_sor *sor = container_of(link, struct tegra_sor, link); 876c1763937SThierry Reding unsigned int rate, lanes; 877c1763937SThierry Reding u32 value; 878c1763937SThierry Reding int err; 879c1763937SThierry Reding 880c1763937SThierry Reding rate = drm_dp_link_rate_to_bw_code(link->rate); 881c1763937SThierry Reding lanes = link->lanes; 882c1763937SThierry Reding 883c1763937SThierry Reding /* configure link speed and lane count */ 884c1763937SThierry Reding value = tegra_sor_readl(sor, SOR_CLK_CNTRL); 885c1763937SThierry Reding value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; 886c1763937SThierry Reding value |= SOR_CLK_CNTRL_DP_LINK_SPEED(rate); 887c1763937SThierry Reding tegra_sor_writel(sor, value, SOR_CLK_CNTRL); 888c1763937SThierry Reding 889c1763937SThierry Reding value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); 890c1763937SThierry Reding value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK; 891c1763937SThierry Reding value |= SOR_DP_LINKCTL_LANE_COUNT(lanes); 892c1763937SThierry Reding 893c1763937SThierry Reding if (link->caps.enhanced_framing) 894c1763937SThierry Reding value |= SOR_DP_LINKCTL_ENHANCED_FRAME; 895c1763937SThierry Reding 896c1763937SThierry Reding tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); 897c1763937SThierry Reding 898c1763937SThierry Reding usleep_range(400, 1000); 899c1763937SThierry Reding 900c1763937SThierry Reding /* configure load pulse position adjustment */ 901c1763937SThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll1); 902c1763937SThierry Reding value &= ~SOR_PLL1_LOADADJ_MASK; 903c1763937SThierry Reding 904c1763937SThierry Reding switch (rate) { 905c1763937SThierry Reding case DP_LINK_BW_1_62: 906c1763937SThierry Reding value |= SOR_PLL1_LOADADJ(0x3); 907c1763937SThierry Reding break; 908c1763937SThierry Reding 909c1763937SThierry Reding case DP_LINK_BW_2_7: 910c1763937SThierry Reding value |= SOR_PLL1_LOADADJ(0x4); 911c1763937SThierry Reding break; 912c1763937SThierry Reding 913c1763937SThierry Reding case DP_LINK_BW_5_4: 914c1763937SThierry Reding value |= SOR_PLL1_LOADADJ(0x6); 915c1763937SThierry Reding break; 916c1763937SThierry Reding } 917c1763937SThierry Reding 918c1763937SThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll1); 919c1763937SThierry Reding 920c1763937SThierry Reding /* use alternate scrambler reset for eDP */ 921c1763937SThierry Reding value = tegra_sor_readl(sor, SOR_DP_SPARE0); 922c1763937SThierry Reding 923c1763937SThierry Reding if (link->edp == 0) 924c1763937SThierry Reding value &= ~SOR_DP_SPARE_PANEL_INTERNAL; 925c1763937SThierry Reding else 926c1763937SThierry Reding value |= SOR_DP_SPARE_PANEL_INTERNAL; 927c1763937SThierry Reding 928c1763937SThierry Reding tegra_sor_writel(sor, value, SOR_DP_SPARE0); 929c1763937SThierry Reding 930c1763937SThierry Reding err = tegra_sor_power_down_lanes(sor); 931c1763937SThierry Reding if (err < 0) { 932c1763937SThierry Reding dev_err(sor->dev, "failed to power down lanes: %d\n", err); 933c1763937SThierry Reding return err; 934c1763937SThierry Reding } 935c1763937SThierry Reding 936c1763937SThierry Reding /* power up and pre-charge lanes */ 937c1763937SThierry Reding err = tegra_sor_power_up_lanes(sor, lanes); 938c1763937SThierry Reding if (err < 0) { 939c1763937SThierry Reding dev_err(sor->dev, "failed to power up %u lane%s: %d\n", 940c1763937SThierry Reding lanes, (lanes != 1) ? "s" : "", err); 941c1763937SThierry Reding return err; 942c1763937SThierry Reding } 943c1763937SThierry Reding 944c1763937SThierry Reding tegra_sor_dp_precharge(sor, lanes); 945c1763937SThierry Reding 946c1763937SThierry Reding return 0; 947c1763937SThierry Reding } 948c1763937SThierry Reding 949c1763937SThierry Reding static const struct drm_dp_link_ops tegra_sor_dp_link_ops = { 950c1763937SThierry Reding .apply_training = tegra_sor_dp_link_apply_training, 951c1763937SThierry Reding .configure = tegra_sor_dp_link_configure, 952c1763937SThierry Reding }; 953c1763937SThierry Reding 9546b6b6042SThierry Reding static void tegra_sor_super_update(struct tegra_sor *sor) 9556b6b6042SThierry Reding { 956a9a9e4fdSThierry Reding tegra_sor_writel(sor, 0, SOR_SUPER_STATE0); 957a9a9e4fdSThierry Reding tegra_sor_writel(sor, 1, SOR_SUPER_STATE0); 958a9a9e4fdSThierry Reding tegra_sor_writel(sor, 0, SOR_SUPER_STATE0); 9596b6b6042SThierry Reding } 9606b6b6042SThierry Reding 9616b6b6042SThierry Reding static void tegra_sor_update(struct tegra_sor *sor) 9626b6b6042SThierry Reding { 963a9a9e4fdSThierry Reding tegra_sor_writel(sor, 0, SOR_STATE0); 964a9a9e4fdSThierry Reding tegra_sor_writel(sor, 1, SOR_STATE0); 965a9a9e4fdSThierry Reding tegra_sor_writel(sor, 0, SOR_STATE0); 9666b6b6042SThierry Reding } 9676b6b6042SThierry Reding 9686b6b6042SThierry Reding static int tegra_sor_setup_pwm(struct tegra_sor *sor, unsigned long timeout) 9696b6b6042SThierry Reding { 97028fe2076SThierry Reding u32 value; 9716b6b6042SThierry Reding 9726b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_PWM_DIV); 9736b6b6042SThierry Reding value &= ~SOR_PWM_DIV_MASK; 9746b6b6042SThierry Reding value |= 0x400; /* period */ 9756b6b6042SThierry Reding tegra_sor_writel(sor, value, SOR_PWM_DIV); 9766b6b6042SThierry Reding 9776b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_PWM_CTL); 9786b6b6042SThierry Reding value &= ~SOR_PWM_CTL_DUTY_CYCLE_MASK; 9796b6b6042SThierry Reding value |= 0x400; /* duty cycle */ 9806b6b6042SThierry Reding value &= ~SOR_PWM_CTL_CLK_SEL; /* clock source: PCLK */ 9816b6b6042SThierry Reding value |= SOR_PWM_CTL_TRIGGER; 9826b6b6042SThierry Reding tegra_sor_writel(sor, value, SOR_PWM_CTL); 9836b6b6042SThierry Reding 9846b6b6042SThierry Reding timeout = jiffies + msecs_to_jiffies(timeout); 9856b6b6042SThierry Reding 9866b6b6042SThierry Reding while (time_before(jiffies, timeout)) { 9876b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_PWM_CTL); 9886b6b6042SThierry Reding if ((value & SOR_PWM_CTL_TRIGGER) == 0) 9896b6b6042SThierry Reding return 0; 9906b6b6042SThierry Reding 9916b6b6042SThierry Reding usleep_range(25, 100); 9926b6b6042SThierry Reding } 9936b6b6042SThierry Reding 9946b6b6042SThierry Reding return -ETIMEDOUT; 9956b6b6042SThierry Reding } 9966b6b6042SThierry Reding 9976b6b6042SThierry Reding static int tegra_sor_attach(struct tegra_sor *sor) 9986b6b6042SThierry Reding { 9996b6b6042SThierry Reding unsigned long value, timeout; 10006b6b6042SThierry Reding 10016b6b6042SThierry Reding /* wake up in normal mode */ 1002a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_SUPER_STATE1); 10036b6b6042SThierry Reding value |= SOR_SUPER_STATE_HEAD_MODE_AWAKE; 10046b6b6042SThierry Reding value |= SOR_SUPER_STATE_MODE_NORMAL; 1005a9a9e4fdSThierry Reding tegra_sor_writel(sor, value, SOR_SUPER_STATE1); 10066b6b6042SThierry Reding tegra_sor_super_update(sor); 10076b6b6042SThierry Reding 10086b6b6042SThierry Reding /* attach */ 1009a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_SUPER_STATE1); 10106b6b6042SThierry Reding value |= SOR_SUPER_STATE_ATTACHED; 1011a9a9e4fdSThierry Reding tegra_sor_writel(sor, value, SOR_SUPER_STATE1); 10126b6b6042SThierry Reding tegra_sor_super_update(sor); 10136b6b6042SThierry Reding 10146b6b6042SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 10156b6b6042SThierry Reding 10166b6b6042SThierry Reding while (time_before(jiffies, timeout)) { 10176b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_TEST); 10186b6b6042SThierry Reding if ((value & SOR_TEST_ATTACHED) != 0) 10196b6b6042SThierry Reding return 0; 10206b6b6042SThierry Reding 10216b6b6042SThierry Reding usleep_range(25, 100); 10226b6b6042SThierry Reding } 10236b6b6042SThierry Reding 10246b6b6042SThierry Reding return -ETIMEDOUT; 10256b6b6042SThierry Reding } 10266b6b6042SThierry Reding 10276b6b6042SThierry Reding static int tegra_sor_wakeup(struct tegra_sor *sor) 10286b6b6042SThierry Reding { 10296b6b6042SThierry Reding unsigned long value, timeout; 10306b6b6042SThierry Reding 10316b6b6042SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 10326b6b6042SThierry Reding 10336b6b6042SThierry Reding /* wait for head to wake up */ 10346b6b6042SThierry Reding while (time_before(jiffies, timeout)) { 10356b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_TEST); 10366b6b6042SThierry Reding value &= SOR_TEST_HEAD_MODE_MASK; 10376b6b6042SThierry Reding 10386b6b6042SThierry Reding if (value == SOR_TEST_HEAD_MODE_AWAKE) 10396b6b6042SThierry Reding return 0; 10406b6b6042SThierry Reding 10416b6b6042SThierry Reding usleep_range(25, 100); 10426b6b6042SThierry Reding } 10436b6b6042SThierry Reding 10446b6b6042SThierry Reding return -ETIMEDOUT; 10456b6b6042SThierry Reding } 10466b6b6042SThierry Reding 10476b6b6042SThierry Reding static int tegra_sor_power_up(struct tegra_sor *sor, unsigned long timeout) 10486b6b6042SThierry Reding { 104928fe2076SThierry Reding u32 value; 10506b6b6042SThierry Reding 10516b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_PWR); 10526b6b6042SThierry Reding value |= SOR_PWR_TRIGGER | SOR_PWR_NORMAL_STATE_PU; 10536b6b6042SThierry Reding tegra_sor_writel(sor, value, SOR_PWR); 10546b6b6042SThierry Reding 10556b6b6042SThierry Reding timeout = jiffies + msecs_to_jiffies(timeout); 10566b6b6042SThierry Reding 10576b6b6042SThierry Reding while (time_before(jiffies, timeout)) { 10586b6b6042SThierry Reding value = tegra_sor_readl(sor, SOR_PWR); 10596b6b6042SThierry Reding if ((value & SOR_PWR_TRIGGER) == 0) 10606b6b6042SThierry Reding return 0; 10616b6b6042SThierry Reding 10626b6b6042SThierry Reding usleep_range(25, 100); 10636b6b6042SThierry Reding } 10646b6b6042SThierry Reding 10656b6b6042SThierry Reding return -ETIMEDOUT; 10666b6b6042SThierry Reding } 10676b6b6042SThierry Reding 106834fa183bSThierry Reding struct tegra_sor_params { 106934fa183bSThierry Reding /* number of link clocks per line */ 107034fa183bSThierry Reding unsigned int num_clocks; 107134fa183bSThierry Reding /* ratio between input and output */ 107234fa183bSThierry Reding u64 ratio; 107334fa183bSThierry Reding /* precision factor */ 107434fa183bSThierry Reding u64 precision; 107534fa183bSThierry Reding 107634fa183bSThierry Reding unsigned int active_polarity; 107734fa183bSThierry Reding unsigned int active_count; 107834fa183bSThierry Reding unsigned int active_frac; 107934fa183bSThierry Reding unsigned int tu_size; 108034fa183bSThierry Reding unsigned int error; 108134fa183bSThierry Reding }; 108234fa183bSThierry Reding 108334fa183bSThierry Reding static int tegra_sor_compute_params(struct tegra_sor *sor, 108434fa183bSThierry Reding struct tegra_sor_params *params, 108534fa183bSThierry Reding unsigned int tu_size) 108634fa183bSThierry Reding { 108734fa183bSThierry Reding u64 active_sym, active_count, frac, approx; 108834fa183bSThierry Reding u32 active_polarity, active_frac = 0; 108934fa183bSThierry Reding const u64 f = params->precision; 109034fa183bSThierry Reding s64 error; 109134fa183bSThierry Reding 109234fa183bSThierry Reding active_sym = params->ratio * tu_size; 109334fa183bSThierry Reding active_count = div_u64(active_sym, f) * f; 109434fa183bSThierry Reding frac = active_sym - active_count; 109534fa183bSThierry Reding 109634fa183bSThierry Reding /* fraction < 0.5 */ 109734fa183bSThierry Reding if (frac >= (f / 2)) { 109834fa183bSThierry Reding active_polarity = 1; 109934fa183bSThierry Reding frac = f - frac; 110034fa183bSThierry Reding } else { 110134fa183bSThierry Reding active_polarity = 0; 110234fa183bSThierry Reding } 110334fa183bSThierry Reding 110434fa183bSThierry Reding if (frac != 0) { 110534fa183bSThierry Reding frac = div_u64(f * f, frac); /* 1/fraction */ 110634fa183bSThierry Reding if (frac <= (15 * f)) { 110734fa183bSThierry Reding active_frac = div_u64(frac, f); 110834fa183bSThierry Reding 110934fa183bSThierry Reding /* round up */ 111034fa183bSThierry Reding if (active_polarity) 111134fa183bSThierry Reding active_frac++; 111234fa183bSThierry Reding } else { 111334fa183bSThierry Reding active_frac = active_polarity ? 1 : 15; 111434fa183bSThierry Reding } 111534fa183bSThierry Reding } 111634fa183bSThierry Reding 111734fa183bSThierry Reding if (active_frac == 1) 111834fa183bSThierry Reding active_polarity = 0; 111934fa183bSThierry Reding 112034fa183bSThierry Reding if (active_polarity == 1) { 112134fa183bSThierry Reding if (active_frac) { 112234fa183bSThierry Reding approx = active_count + (active_frac * (f - 1)) * f; 112334fa183bSThierry Reding approx = div_u64(approx, active_frac * f); 112434fa183bSThierry Reding } else { 112534fa183bSThierry Reding approx = active_count + f; 112634fa183bSThierry Reding } 112734fa183bSThierry Reding } else { 112834fa183bSThierry Reding if (active_frac) 112934fa183bSThierry Reding approx = active_count + div_u64(f, active_frac); 113034fa183bSThierry Reding else 113134fa183bSThierry Reding approx = active_count; 113234fa183bSThierry Reding } 113334fa183bSThierry Reding 113434fa183bSThierry Reding error = div_s64(active_sym - approx, tu_size); 113534fa183bSThierry Reding error *= params->num_clocks; 113634fa183bSThierry Reding 113779211c8eSAndrew Morton if (error <= 0 && abs(error) < params->error) { 113834fa183bSThierry Reding params->active_count = div_u64(active_count, f); 113934fa183bSThierry Reding params->active_polarity = active_polarity; 114034fa183bSThierry Reding params->active_frac = active_frac; 114179211c8eSAndrew Morton params->error = abs(error); 114234fa183bSThierry Reding params->tu_size = tu_size; 114334fa183bSThierry Reding 114434fa183bSThierry Reding if (error == 0) 114534fa183bSThierry Reding return true; 114634fa183bSThierry Reding } 114734fa183bSThierry Reding 114834fa183bSThierry Reding return false; 114934fa183bSThierry Reding } 115034fa183bSThierry Reding 1151a198359eSThierry Reding static int tegra_sor_compute_config(struct tegra_sor *sor, 115280444495SThierry Reding const struct drm_display_mode *mode, 115334fa183bSThierry Reding struct tegra_sor_config *config, 115434fa183bSThierry Reding struct drm_dp_link *link) 115534fa183bSThierry Reding { 115634fa183bSThierry Reding const u64 f = 100000, link_rate = link->rate * 1000; 115734fa183bSThierry Reding const u64 pclk = mode->clock * 1000; 11587890b576SThierry Reding u64 input, output, watermark, num; 115934fa183bSThierry Reding struct tegra_sor_params params; 116034fa183bSThierry Reding u32 num_syms_per_line; 116134fa183bSThierry Reding unsigned int i; 116234fa183bSThierry Reding 1163c728e2d4SThierry Reding if (!link_rate || !link->lanes || !pclk || !config->bits_per_pixel) 116434fa183bSThierry Reding return -EINVAL; 116534fa183bSThierry Reding 116634fa183bSThierry Reding input = pclk * config->bits_per_pixel; 1167c728e2d4SThierry Reding output = link_rate * 8 * link->lanes; 116834fa183bSThierry Reding 116934fa183bSThierry Reding if (input >= output) 117034fa183bSThierry Reding return -ERANGE; 117134fa183bSThierry Reding 117234fa183bSThierry Reding memset(¶ms, 0, sizeof(params)); 117334fa183bSThierry Reding params.ratio = div64_u64(input * f, output); 117434fa183bSThierry Reding params.num_clocks = div_u64(link_rate * mode->hdisplay, pclk); 117534fa183bSThierry Reding params.precision = f; 117634fa183bSThierry Reding params.error = 64 * f; 117734fa183bSThierry Reding params.tu_size = 64; 117834fa183bSThierry Reding 117934fa183bSThierry Reding for (i = params.tu_size; i >= 32; i--) 118034fa183bSThierry Reding if (tegra_sor_compute_params(sor, ¶ms, i)) 118134fa183bSThierry Reding break; 118234fa183bSThierry Reding 118334fa183bSThierry Reding if (params.active_frac == 0) { 118434fa183bSThierry Reding config->active_polarity = 0; 118534fa183bSThierry Reding config->active_count = params.active_count; 118634fa183bSThierry Reding 118734fa183bSThierry Reding if (!params.active_polarity) 118834fa183bSThierry Reding config->active_count--; 118934fa183bSThierry Reding 119034fa183bSThierry Reding config->tu_size = params.tu_size; 119134fa183bSThierry Reding config->active_frac = 1; 119234fa183bSThierry Reding } else { 119334fa183bSThierry Reding config->active_polarity = params.active_polarity; 119434fa183bSThierry Reding config->active_count = params.active_count; 119534fa183bSThierry Reding config->active_frac = params.active_frac; 119634fa183bSThierry Reding config->tu_size = params.tu_size; 119734fa183bSThierry Reding } 119834fa183bSThierry Reding 119934fa183bSThierry Reding dev_dbg(sor->dev, 120034fa183bSThierry Reding "polarity: %d active count: %d tu size: %d active frac: %d\n", 120134fa183bSThierry Reding config->active_polarity, config->active_count, 120234fa183bSThierry Reding config->tu_size, config->active_frac); 120334fa183bSThierry Reding 120434fa183bSThierry Reding watermark = params.ratio * config->tu_size * (f - params.ratio); 120534fa183bSThierry Reding watermark = div_u64(watermark, f); 120634fa183bSThierry Reding 120734fa183bSThierry Reding watermark = div_u64(watermark + params.error, f); 120834fa183bSThierry Reding config->watermark = watermark + (config->bits_per_pixel / 8) + 2; 120934fa183bSThierry Reding num_syms_per_line = (mode->hdisplay * config->bits_per_pixel) * 1210c728e2d4SThierry Reding (link->lanes * 8); 121134fa183bSThierry Reding 121234fa183bSThierry Reding if (config->watermark > 30) { 121334fa183bSThierry Reding config->watermark = 30; 121434fa183bSThierry Reding dev_err(sor->dev, 121534fa183bSThierry Reding "unable to compute TU size, forcing watermark to %u\n", 121634fa183bSThierry Reding config->watermark); 121734fa183bSThierry Reding } else if (config->watermark > num_syms_per_line) { 121834fa183bSThierry Reding config->watermark = num_syms_per_line; 121934fa183bSThierry Reding dev_err(sor->dev, "watermark too high, forcing to %u\n", 122034fa183bSThierry Reding config->watermark); 122134fa183bSThierry Reding } 122234fa183bSThierry Reding 12237890b576SThierry Reding /* compute the number of symbols per horizontal blanking interval */ 12247890b576SThierry Reding num = ((mode->htotal - mode->hdisplay) - 7) * link_rate; 12257890b576SThierry Reding config->hblank_symbols = div_u64(num, pclk); 12267890b576SThierry Reding 122727ba465cSThierry Reding if (link->caps.enhanced_framing) 12287890b576SThierry Reding config->hblank_symbols -= 3; 12297890b576SThierry Reding 1230c728e2d4SThierry Reding config->hblank_symbols -= 12 / link->lanes; 12317890b576SThierry Reding 12327890b576SThierry Reding /* compute the number of symbols per vertical blanking interval */ 12337890b576SThierry Reding num = (mode->hdisplay - 25) * link_rate; 12347890b576SThierry Reding config->vblank_symbols = div_u64(num, pclk); 1235c728e2d4SThierry Reding config->vblank_symbols -= 36 / link->lanes + 4; 12367890b576SThierry Reding 12377890b576SThierry Reding dev_dbg(sor->dev, "blank symbols: H:%u V:%u\n", config->hblank_symbols, 12387890b576SThierry Reding config->vblank_symbols); 12397890b576SThierry Reding 124034fa183bSThierry Reding return 0; 124134fa183bSThierry Reding } 124234fa183bSThierry Reding 1243402f6bcdSThierry Reding static void tegra_sor_apply_config(struct tegra_sor *sor, 1244402f6bcdSThierry Reding const struct tegra_sor_config *config) 1245402f6bcdSThierry Reding { 1246402f6bcdSThierry Reding u32 value; 1247402f6bcdSThierry Reding 1248402f6bcdSThierry Reding value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); 1249402f6bcdSThierry Reding value &= ~SOR_DP_LINKCTL_TU_SIZE_MASK; 1250402f6bcdSThierry Reding value |= SOR_DP_LINKCTL_TU_SIZE(config->tu_size); 1251402f6bcdSThierry Reding tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); 1252402f6bcdSThierry Reding 1253402f6bcdSThierry Reding value = tegra_sor_readl(sor, SOR_DP_CONFIG0); 1254402f6bcdSThierry Reding value &= ~SOR_DP_CONFIG_WATERMARK_MASK; 1255402f6bcdSThierry Reding value |= SOR_DP_CONFIG_WATERMARK(config->watermark); 1256402f6bcdSThierry Reding 1257402f6bcdSThierry Reding value &= ~SOR_DP_CONFIG_ACTIVE_SYM_COUNT_MASK; 1258402f6bcdSThierry Reding value |= SOR_DP_CONFIG_ACTIVE_SYM_COUNT(config->active_count); 1259402f6bcdSThierry Reding 1260402f6bcdSThierry Reding value &= ~SOR_DP_CONFIG_ACTIVE_SYM_FRAC_MASK; 1261402f6bcdSThierry Reding value |= SOR_DP_CONFIG_ACTIVE_SYM_FRAC(config->active_frac); 1262402f6bcdSThierry Reding 1263402f6bcdSThierry Reding if (config->active_polarity) 1264402f6bcdSThierry Reding value |= SOR_DP_CONFIG_ACTIVE_SYM_POLARITY; 1265402f6bcdSThierry Reding else 1266402f6bcdSThierry Reding value &= ~SOR_DP_CONFIG_ACTIVE_SYM_POLARITY; 1267402f6bcdSThierry Reding 1268402f6bcdSThierry Reding value |= SOR_DP_CONFIG_ACTIVE_SYM_ENABLE; 1269402f6bcdSThierry Reding value |= SOR_DP_CONFIG_DISPARITY_NEGATIVE; 1270402f6bcdSThierry Reding tegra_sor_writel(sor, value, SOR_DP_CONFIG0); 1271402f6bcdSThierry Reding 1272402f6bcdSThierry Reding value = tegra_sor_readl(sor, SOR_DP_AUDIO_HBLANK_SYMBOLS); 1273402f6bcdSThierry Reding value &= ~SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK; 1274402f6bcdSThierry Reding value |= config->hblank_symbols & 0xffff; 1275402f6bcdSThierry Reding tegra_sor_writel(sor, value, SOR_DP_AUDIO_HBLANK_SYMBOLS); 1276402f6bcdSThierry Reding 1277402f6bcdSThierry Reding value = tegra_sor_readl(sor, SOR_DP_AUDIO_VBLANK_SYMBOLS); 1278402f6bcdSThierry Reding value &= ~SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK; 1279402f6bcdSThierry Reding value |= config->vblank_symbols & 0xffff; 1280402f6bcdSThierry Reding tegra_sor_writel(sor, value, SOR_DP_AUDIO_VBLANK_SYMBOLS); 1281402f6bcdSThierry Reding } 1282402f6bcdSThierry Reding 12832bd1dd39SThierry Reding static void tegra_sor_mode_set(struct tegra_sor *sor, 12842bd1dd39SThierry Reding const struct drm_display_mode *mode, 1285c31efa7aSThierry Reding struct tegra_sor_state *state) 12862bd1dd39SThierry Reding { 12872bd1dd39SThierry Reding struct tegra_dc *dc = to_tegra_dc(sor->output.encoder.crtc); 12882bd1dd39SThierry Reding unsigned int vbe, vse, hbe, hse, vbs, hbs; 12892bd1dd39SThierry Reding u32 value; 12902bd1dd39SThierry Reding 12912bd1dd39SThierry Reding value = tegra_sor_readl(sor, SOR_STATE1); 12922bd1dd39SThierry Reding value &= ~SOR_STATE_ASY_PIXELDEPTH_MASK; 12932bd1dd39SThierry Reding value &= ~SOR_STATE_ASY_CRC_MODE_MASK; 12942bd1dd39SThierry Reding value &= ~SOR_STATE_ASY_OWNER_MASK; 12952bd1dd39SThierry Reding 12962bd1dd39SThierry Reding value |= SOR_STATE_ASY_CRC_MODE_COMPLETE | 12972bd1dd39SThierry Reding SOR_STATE_ASY_OWNER(dc->pipe + 1); 12982bd1dd39SThierry Reding 12992bd1dd39SThierry Reding if (mode->flags & DRM_MODE_FLAG_PHSYNC) 13002bd1dd39SThierry Reding value &= ~SOR_STATE_ASY_HSYNCPOL; 13012bd1dd39SThierry Reding 13022bd1dd39SThierry Reding if (mode->flags & DRM_MODE_FLAG_NHSYNC) 13032bd1dd39SThierry Reding value |= SOR_STATE_ASY_HSYNCPOL; 13042bd1dd39SThierry Reding 13052bd1dd39SThierry Reding if (mode->flags & DRM_MODE_FLAG_PVSYNC) 13062bd1dd39SThierry Reding value &= ~SOR_STATE_ASY_VSYNCPOL; 13072bd1dd39SThierry Reding 13082bd1dd39SThierry Reding if (mode->flags & DRM_MODE_FLAG_NVSYNC) 13092bd1dd39SThierry Reding value |= SOR_STATE_ASY_VSYNCPOL; 13102bd1dd39SThierry Reding 1311c31efa7aSThierry Reding switch (state->bpc) { 1312c31efa7aSThierry Reding case 16: 1313c31efa7aSThierry Reding value |= SOR_STATE_ASY_PIXELDEPTH_BPP_48_444; 1314c31efa7aSThierry Reding break; 1315c31efa7aSThierry Reding 1316c31efa7aSThierry Reding case 12: 1317c31efa7aSThierry Reding value |= SOR_STATE_ASY_PIXELDEPTH_BPP_36_444; 1318c31efa7aSThierry Reding break; 1319c31efa7aSThierry Reding 1320c31efa7aSThierry Reding case 10: 1321c31efa7aSThierry Reding value |= SOR_STATE_ASY_PIXELDEPTH_BPP_30_444; 1322c31efa7aSThierry Reding break; 1323c31efa7aSThierry Reding 13242bd1dd39SThierry Reding case 8: 13252bd1dd39SThierry Reding value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444; 13262bd1dd39SThierry Reding break; 13272bd1dd39SThierry Reding 13282bd1dd39SThierry Reding case 6: 13292bd1dd39SThierry Reding value |= SOR_STATE_ASY_PIXELDEPTH_BPP_18_444; 13302bd1dd39SThierry Reding break; 13312bd1dd39SThierry Reding 13322bd1dd39SThierry Reding default: 1333c31efa7aSThierry Reding value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444; 13342bd1dd39SThierry Reding break; 13352bd1dd39SThierry Reding } 13362bd1dd39SThierry Reding 13372bd1dd39SThierry Reding tegra_sor_writel(sor, value, SOR_STATE1); 13382bd1dd39SThierry Reding 13392bd1dd39SThierry Reding /* 13402bd1dd39SThierry Reding * TODO: The video timing programming below doesn't seem to match the 13412bd1dd39SThierry Reding * register definitions. 13422bd1dd39SThierry Reding */ 13432bd1dd39SThierry Reding 13442bd1dd39SThierry Reding value = ((mode->vtotal & 0x7fff) << 16) | (mode->htotal & 0x7fff); 1345880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->head_state1 + dc->pipe); 13462bd1dd39SThierry Reding 13472bd1dd39SThierry Reding /* sync end = sync width - 1 */ 13482bd1dd39SThierry Reding vse = mode->vsync_end - mode->vsync_start - 1; 13492bd1dd39SThierry Reding hse = mode->hsync_end - mode->hsync_start - 1; 13502bd1dd39SThierry Reding 13512bd1dd39SThierry Reding value = ((vse & 0x7fff) << 16) | (hse & 0x7fff); 1352880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->head_state2 + dc->pipe); 13532bd1dd39SThierry Reding 13542bd1dd39SThierry Reding /* blank end = sync end + back porch */ 13552bd1dd39SThierry Reding vbe = vse + (mode->vtotal - mode->vsync_end); 13562bd1dd39SThierry Reding hbe = hse + (mode->htotal - mode->hsync_end); 13572bd1dd39SThierry Reding 13582bd1dd39SThierry Reding value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff); 1359880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->head_state3 + dc->pipe); 13602bd1dd39SThierry Reding 13612bd1dd39SThierry Reding /* blank start = blank end + active */ 13622bd1dd39SThierry Reding vbs = vbe + mode->vdisplay; 13632bd1dd39SThierry Reding hbs = hbe + mode->hdisplay; 13642bd1dd39SThierry Reding 13652bd1dd39SThierry Reding value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff); 1366880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->head_state4 + dc->pipe); 13672bd1dd39SThierry Reding 13682bd1dd39SThierry Reding /* XXX interlacing support */ 1369880cee0bSThierry Reding tegra_sor_writel(sor, 0x001, sor->soc->regs->head_state5 + dc->pipe); 13702bd1dd39SThierry Reding } 13712bd1dd39SThierry Reding 13726fad8f66SThierry Reding static int tegra_sor_detach(struct tegra_sor *sor) 13736b6b6042SThierry Reding { 13746fad8f66SThierry Reding unsigned long value, timeout; 13756fad8f66SThierry Reding 13766fad8f66SThierry Reding /* switch to safe mode */ 1377a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_SUPER_STATE1); 13786fad8f66SThierry Reding value &= ~SOR_SUPER_STATE_MODE_NORMAL; 1379a9a9e4fdSThierry Reding tegra_sor_writel(sor, value, SOR_SUPER_STATE1); 13806fad8f66SThierry Reding tegra_sor_super_update(sor); 13816fad8f66SThierry Reding 13826fad8f66SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 13836fad8f66SThierry Reding 13846fad8f66SThierry Reding while (time_before(jiffies, timeout)) { 13856fad8f66SThierry Reding value = tegra_sor_readl(sor, SOR_PWR); 13866fad8f66SThierry Reding if (value & SOR_PWR_MODE_SAFE) 13876fad8f66SThierry Reding break; 13886fad8f66SThierry Reding } 13896fad8f66SThierry Reding 13906fad8f66SThierry Reding if ((value & SOR_PWR_MODE_SAFE) == 0) 13916fad8f66SThierry Reding return -ETIMEDOUT; 13926fad8f66SThierry Reding 13936fad8f66SThierry Reding /* go to sleep */ 1394a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_SUPER_STATE1); 13956fad8f66SThierry Reding value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK; 1396a9a9e4fdSThierry Reding tegra_sor_writel(sor, value, SOR_SUPER_STATE1); 13976fad8f66SThierry Reding tegra_sor_super_update(sor); 13986fad8f66SThierry Reding 13996fad8f66SThierry Reding /* detach */ 1400a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_SUPER_STATE1); 14016fad8f66SThierry Reding value &= ~SOR_SUPER_STATE_ATTACHED; 1402a9a9e4fdSThierry Reding tegra_sor_writel(sor, value, SOR_SUPER_STATE1); 14036fad8f66SThierry Reding tegra_sor_super_update(sor); 14046fad8f66SThierry Reding 14056fad8f66SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 14066fad8f66SThierry Reding 14076fad8f66SThierry Reding while (time_before(jiffies, timeout)) { 14086fad8f66SThierry Reding value = tegra_sor_readl(sor, SOR_TEST); 14096fad8f66SThierry Reding if ((value & SOR_TEST_ATTACHED) == 0) 14106fad8f66SThierry Reding break; 14116fad8f66SThierry Reding 14126fad8f66SThierry Reding usleep_range(25, 100); 14136fad8f66SThierry Reding } 14146fad8f66SThierry Reding 14156fad8f66SThierry Reding if ((value & SOR_TEST_ATTACHED) != 0) 14166fad8f66SThierry Reding return -ETIMEDOUT; 14176fad8f66SThierry Reding 14186fad8f66SThierry Reding return 0; 14196fad8f66SThierry Reding } 14206fad8f66SThierry Reding 14216fad8f66SThierry Reding static int tegra_sor_power_down(struct tegra_sor *sor) 14226fad8f66SThierry Reding { 14236fad8f66SThierry Reding unsigned long value, timeout; 14246fad8f66SThierry Reding int err; 14256fad8f66SThierry Reding 14266fad8f66SThierry Reding value = tegra_sor_readl(sor, SOR_PWR); 14276fad8f66SThierry Reding value &= ~SOR_PWR_NORMAL_STATE_PU; 14286fad8f66SThierry Reding value |= SOR_PWR_TRIGGER; 14296fad8f66SThierry Reding tegra_sor_writel(sor, value, SOR_PWR); 14306fad8f66SThierry Reding 14316fad8f66SThierry Reding timeout = jiffies + msecs_to_jiffies(250); 14326fad8f66SThierry Reding 14336fad8f66SThierry Reding while (time_before(jiffies, timeout)) { 14346fad8f66SThierry Reding value = tegra_sor_readl(sor, SOR_PWR); 14356fad8f66SThierry Reding if ((value & SOR_PWR_TRIGGER) == 0) 14366fad8f66SThierry Reding return 0; 14376fad8f66SThierry Reding 14386fad8f66SThierry Reding usleep_range(25, 100); 14396fad8f66SThierry Reding } 14406fad8f66SThierry Reding 14416fad8f66SThierry Reding if ((value & SOR_PWR_TRIGGER) != 0) 14426fad8f66SThierry Reding return -ETIMEDOUT; 14436fad8f66SThierry Reding 144425bb2cecSThierry Reding /* switch to safe parent clock */ 144525bb2cecSThierry Reding err = tegra_sor_set_parent_clock(sor, sor->clk_safe); 1446e1335e2fSThierry Reding if (err < 0) { 14476fad8f66SThierry Reding dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); 1448e1335e2fSThierry Reding return err; 1449e1335e2fSThierry Reding } 14506fad8f66SThierry Reding 1451880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 1452a9a9e4fdSThierry Reding value |= SOR_PLL2_PORT_POWERDOWN; 1453880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 14546fad8f66SThierry Reding 14556fad8f66SThierry Reding usleep_range(20, 100); 14566fad8f66SThierry Reding 1457880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll0); 1458a9a9e4fdSThierry Reding value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR; 1459880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll0); 14606fad8f66SThierry Reding 1461880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 1462a9a9e4fdSThierry Reding value |= SOR_PLL2_SEQ_PLLCAPPD; 1463a9a9e4fdSThierry Reding value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; 1464880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 14656fad8f66SThierry Reding 14666fad8f66SThierry Reding usleep_range(20, 100); 14676fad8f66SThierry Reding 14686fad8f66SThierry Reding return 0; 14696fad8f66SThierry Reding } 14706fad8f66SThierry Reding 14716fad8f66SThierry Reding static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout) 14726fad8f66SThierry Reding { 14736fad8f66SThierry Reding u32 value; 14746fad8f66SThierry Reding 14756fad8f66SThierry Reding timeout = jiffies + msecs_to_jiffies(timeout); 14766fad8f66SThierry Reding 14776fad8f66SThierry Reding while (time_before(jiffies, timeout)) { 1478a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_CRCA); 1479a9a9e4fdSThierry Reding if (value & SOR_CRCA_VALID) 14806fad8f66SThierry Reding return 0; 14816fad8f66SThierry Reding 14826fad8f66SThierry Reding usleep_range(100, 200); 14836fad8f66SThierry Reding } 14846fad8f66SThierry Reding 14856fad8f66SThierry Reding return -ETIMEDOUT; 14866fad8f66SThierry Reding } 14876fad8f66SThierry Reding 1488530239a8SThierry Reding static int tegra_sor_show_crc(struct seq_file *s, void *data) 14896fad8f66SThierry Reding { 1490530239a8SThierry Reding struct drm_info_node *node = s->private; 1491530239a8SThierry Reding struct tegra_sor *sor = node->info_ent->data; 1492850bab44SThierry Reding struct drm_crtc *crtc = sor->output.encoder.crtc; 1493850bab44SThierry Reding struct drm_device *drm = node->minor->dev; 1494530239a8SThierry Reding int err = 0; 14956fad8f66SThierry Reding u32 value; 14966fad8f66SThierry Reding 1497850bab44SThierry Reding drm_modeset_lock_all(drm); 14986fad8f66SThierry Reding 1499850bab44SThierry Reding if (!crtc || !crtc->state->active) { 1500850bab44SThierry Reding err = -EBUSY; 15016fad8f66SThierry Reding goto unlock; 15026fad8f66SThierry Reding } 15036fad8f66SThierry Reding 1504a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_STATE1); 15056fad8f66SThierry Reding value &= ~SOR_STATE_ASY_CRC_MODE_MASK; 1506a9a9e4fdSThierry Reding tegra_sor_writel(sor, value, SOR_STATE1); 15076fad8f66SThierry Reding 15086fad8f66SThierry Reding value = tegra_sor_readl(sor, SOR_CRC_CNTRL); 15096fad8f66SThierry Reding value |= SOR_CRC_CNTRL_ENABLE; 15106fad8f66SThierry Reding tegra_sor_writel(sor, value, SOR_CRC_CNTRL); 15116fad8f66SThierry Reding 15126fad8f66SThierry Reding value = tegra_sor_readl(sor, SOR_TEST); 15136fad8f66SThierry Reding value &= ~SOR_TEST_CRC_POST_SERIALIZE; 15146fad8f66SThierry Reding tegra_sor_writel(sor, value, SOR_TEST); 15156fad8f66SThierry Reding 15166fad8f66SThierry Reding err = tegra_sor_crc_wait(sor, 100); 15176fad8f66SThierry Reding if (err < 0) 15186fad8f66SThierry Reding goto unlock; 15196fad8f66SThierry Reding 1520a9a9e4fdSThierry Reding tegra_sor_writel(sor, SOR_CRCA_RESET, SOR_CRCA); 1521a9a9e4fdSThierry Reding value = tegra_sor_readl(sor, SOR_CRCB); 15226fad8f66SThierry Reding 1523530239a8SThierry Reding seq_printf(s, "%08x\n", value); 15246fad8f66SThierry Reding 15256fad8f66SThierry Reding unlock: 1526850bab44SThierry Reding drm_modeset_unlock_all(drm); 15276fad8f66SThierry Reding return err; 15286fad8f66SThierry Reding } 15296fad8f66SThierry Reding 1530062f5b2cSThierry Reding #define DEBUGFS_REG32(_name) { .name = #_name, .offset = _name } 1531062f5b2cSThierry Reding 1532062f5b2cSThierry Reding static const struct debugfs_reg32 tegra_sor_regs[] = { 1533062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CTXSW), 1534062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SUPER_STATE0), 1535062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SUPER_STATE1), 1536062f5b2cSThierry Reding DEBUGFS_REG32(SOR_STATE0), 1537062f5b2cSThierry Reding DEBUGFS_REG32(SOR_STATE1), 1538062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE0(0)), 1539062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE0(1)), 1540062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE1(0)), 1541062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE1(1)), 1542062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE2(0)), 1543062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE2(1)), 1544062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE3(0)), 1545062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE3(1)), 1546062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE4(0)), 1547062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE4(1)), 1548062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE5(0)), 1549062f5b2cSThierry Reding DEBUGFS_REG32(SOR_HEAD_STATE5(1)), 1550062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CRC_CNTRL), 1551062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_DEBUG_MVID), 1552062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CLK_CNTRL), 1553062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CAP), 1554062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PWR), 1555062f5b2cSThierry Reding DEBUGFS_REG32(SOR_TEST), 1556062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PLL0), 1557062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PLL1), 1558062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PLL2), 1559062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PLL3), 1560062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CSTM), 1561062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LVDS), 1562062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CRCA), 1563062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CRCB), 1564062f5b2cSThierry Reding DEBUGFS_REG32(SOR_BLANK), 1565062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_CTL), 1566062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_SEQ_CTL), 1567062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(0)), 1568062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(1)), 1569062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(2)), 1570062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(3)), 1571062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(4)), 1572062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(5)), 1573062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(6)), 1574062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(7)), 1575062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(8)), 1576062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(9)), 1577062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(10)), 1578062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(11)), 1579062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(12)), 1580062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(13)), 1581062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(14)), 1582062f5b2cSThierry Reding DEBUGFS_REG32(SOR_SEQ_INST(15)), 1583062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PWM_DIV), 1584062f5b2cSThierry Reding DEBUGFS_REG32(SOR_PWM_CTL), 1585062f5b2cSThierry Reding DEBUGFS_REG32(SOR_VCRC_A0), 1586062f5b2cSThierry Reding DEBUGFS_REG32(SOR_VCRC_A1), 1587062f5b2cSThierry Reding DEBUGFS_REG32(SOR_VCRC_B0), 1588062f5b2cSThierry Reding DEBUGFS_REG32(SOR_VCRC_B1), 1589062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CCRC_A0), 1590062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CCRC_A1), 1591062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CCRC_B0), 1592062f5b2cSThierry Reding DEBUGFS_REG32(SOR_CCRC_B1), 1593062f5b2cSThierry Reding DEBUGFS_REG32(SOR_EDATA_A0), 1594062f5b2cSThierry Reding DEBUGFS_REG32(SOR_EDATA_A1), 1595062f5b2cSThierry Reding DEBUGFS_REG32(SOR_EDATA_B0), 1596062f5b2cSThierry Reding DEBUGFS_REG32(SOR_EDATA_B1), 1597062f5b2cSThierry Reding DEBUGFS_REG32(SOR_COUNT_A0), 1598062f5b2cSThierry Reding DEBUGFS_REG32(SOR_COUNT_A1), 1599062f5b2cSThierry Reding DEBUGFS_REG32(SOR_COUNT_B0), 1600062f5b2cSThierry Reding DEBUGFS_REG32(SOR_COUNT_B1), 1601062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DEBUG_A0), 1602062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DEBUG_A1), 1603062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DEBUG_B0), 1604062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DEBUG_B1), 1605062f5b2cSThierry Reding DEBUGFS_REG32(SOR_TRIG), 1606062f5b2cSThierry Reding DEBUGFS_REG32(SOR_MSCHECK), 1607062f5b2cSThierry Reding DEBUGFS_REG32(SOR_XBAR_CTRL), 1608062f5b2cSThierry Reding DEBUGFS_REG32(SOR_XBAR_POL), 1609062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_LINKCTL0), 1610062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_LINKCTL1), 1611062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_DRIVE_CURRENT0), 1612062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_DRIVE_CURRENT1), 1613062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE4_DRIVE_CURRENT0), 1614062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE4_DRIVE_CURRENT1), 1615062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_PREEMPHASIS0), 1616062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_PREEMPHASIS1), 1617062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE4_PREEMPHASIS0), 1618062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE4_PREEMPHASIS1), 1619062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_POSTCURSOR0), 1620062f5b2cSThierry Reding DEBUGFS_REG32(SOR_LANE_POSTCURSOR1), 1621062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_CONFIG0), 1622062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_CONFIG1), 1623062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_MN0), 1624062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_MN1), 1625062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_PADCTL0), 1626062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_PADCTL1), 1627c57997bcSThierry Reding DEBUGFS_REG32(SOR_DP_PADCTL2), 1628062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_DEBUG0), 1629062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_DEBUG1), 1630062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_SPARE0), 1631062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_SPARE1), 1632062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_AUDIO_CTRL), 1633062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_AUDIO_HBLANK_SYMBOLS), 1634062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_AUDIO_VBLANK_SYMBOLS), 1635062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_HEADER), 1636062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK0), 1637062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK1), 1638062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK2), 1639062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK3), 1640062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK4), 1641062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK5), 1642062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK6), 1643062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_TPG), 1644062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_TPG_CONFIG), 1645062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_LQ_CSTM0), 1646062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_LQ_CSTM1), 1647062f5b2cSThierry Reding DEBUGFS_REG32(SOR_DP_LQ_CSTM2), 1648062f5b2cSThierry Reding }; 1649062f5b2cSThierry Reding 1650dab16336SThierry Reding static int tegra_sor_show_regs(struct seq_file *s, void *data) 1651dab16336SThierry Reding { 1652dab16336SThierry Reding struct drm_info_node *node = s->private; 1653dab16336SThierry Reding struct tegra_sor *sor = node->info_ent->data; 1654850bab44SThierry Reding struct drm_crtc *crtc = sor->output.encoder.crtc; 1655850bab44SThierry Reding struct drm_device *drm = node->minor->dev; 1656062f5b2cSThierry Reding unsigned int i; 1657850bab44SThierry Reding int err = 0; 1658850bab44SThierry Reding 1659850bab44SThierry Reding drm_modeset_lock_all(drm); 1660850bab44SThierry Reding 1661850bab44SThierry Reding if (!crtc || !crtc->state->active) { 1662850bab44SThierry Reding err = -EBUSY; 1663850bab44SThierry Reding goto unlock; 1664850bab44SThierry Reding } 1665dab16336SThierry Reding 1666062f5b2cSThierry Reding for (i = 0; i < ARRAY_SIZE(tegra_sor_regs); i++) { 1667062f5b2cSThierry Reding unsigned int offset = tegra_sor_regs[i].offset; 1668dab16336SThierry Reding 1669062f5b2cSThierry Reding seq_printf(s, "%-38s %#05x %08x\n", tegra_sor_regs[i].name, 1670062f5b2cSThierry Reding offset, tegra_sor_readl(sor, offset)); 1671062f5b2cSThierry Reding } 1672dab16336SThierry Reding 1673850bab44SThierry Reding unlock: 1674850bab44SThierry Reding drm_modeset_unlock_all(drm); 1675850bab44SThierry Reding return err; 1676dab16336SThierry Reding } 1677dab16336SThierry Reding 1678dab16336SThierry Reding static const struct drm_info_list debugfs_files[] = { 1679530239a8SThierry Reding { "crc", tegra_sor_show_crc, 0, NULL }, 1680dab16336SThierry Reding { "regs", tegra_sor_show_regs, 0, NULL }, 1681dab16336SThierry Reding }; 1682dab16336SThierry Reding 16835b8e043bSThierry Reding static int tegra_sor_late_register(struct drm_connector *connector) 16846fad8f66SThierry Reding { 16855b8e043bSThierry Reding struct tegra_output *output = connector_to_output(connector); 16865b8e043bSThierry Reding unsigned int i, count = ARRAY_SIZE(debugfs_files); 16875b8e043bSThierry Reding struct drm_minor *minor = connector->dev->primary; 16885b8e043bSThierry Reding struct dentry *root = connector->debugfs_entry; 16895b8e043bSThierry Reding struct tegra_sor *sor = to_sor(output); 1690530239a8SThierry Reding int err; 16916fad8f66SThierry Reding 1692dab16336SThierry Reding sor->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), 1693dab16336SThierry Reding GFP_KERNEL); 16945b8e043bSThierry Reding if (!sor->debugfs_files) 16955b8e043bSThierry Reding return -ENOMEM; 16966fad8f66SThierry Reding 16975b8e043bSThierry Reding for (i = 0; i < count; i++) 1698dab16336SThierry Reding sor->debugfs_files[i].data = sor; 1699dab16336SThierry Reding 17005b8e043bSThierry Reding err = drm_debugfs_create_files(sor->debugfs_files, count, root, minor); 1701dab16336SThierry Reding if (err < 0) 1702dab16336SThierry Reding goto free; 1703dab16336SThierry Reding 1704530239a8SThierry Reding return 0; 17056fad8f66SThierry Reding 1706dab16336SThierry Reding free: 1707dab16336SThierry Reding kfree(sor->debugfs_files); 1708dab16336SThierry Reding sor->debugfs_files = NULL; 17095b8e043bSThierry Reding 17106fad8f66SThierry Reding return err; 17116fad8f66SThierry Reding } 17126fad8f66SThierry Reding 17135b8e043bSThierry Reding static void tegra_sor_early_unregister(struct drm_connector *connector) 17146fad8f66SThierry Reding { 17155b8e043bSThierry Reding struct tegra_output *output = connector_to_output(connector); 17165b8e043bSThierry Reding unsigned int count = ARRAY_SIZE(debugfs_files); 17175b8e043bSThierry Reding struct tegra_sor *sor = to_sor(output); 1718d92e6009SThierry Reding 17195b8e043bSThierry Reding drm_debugfs_remove_files(sor->debugfs_files, count, 17205b8e043bSThierry Reding connector->dev->primary); 1721dab16336SThierry Reding kfree(sor->debugfs_files); 1722066d30f8SThierry Reding sor->debugfs_files = NULL; 17236fad8f66SThierry Reding } 17246fad8f66SThierry Reding 1725c31efa7aSThierry Reding static void tegra_sor_connector_reset(struct drm_connector *connector) 1726c31efa7aSThierry Reding { 1727c31efa7aSThierry Reding struct tegra_sor_state *state; 1728c31efa7aSThierry Reding 1729c31efa7aSThierry Reding state = kzalloc(sizeof(*state), GFP_KERNEL); 1730c31efa7aSThierry Reding if (!state) 1731c31efa7aSThierry Reding return; 1732c31efa7aSThierry Reding 1733c31efa7aSThierry Reding if (connector->state) { 1734c31efa7aSThierry Reding __drm_atomic_helper_connector_destroy_state(connector->state); 1735c31efa7aSThierry Reding kfree(connector->state); 1736c31efa7aSThierry Reding } 1737c31efa7aSThierry Reding 1738c31efa7aSThierry Reding __drm_atomic_helper_connector_reset(connector, &state->base); 1739c31efa7aSThierry Reding } 1740c31efa7aSThierry Reding 17416fad8f66SThierry Reding static enum drm_connector_status 17426fad8f66SThierry Reding tegra_sor_connector_detect(struct drm_connector *connector, bool force) 17436fad8f66SThierry Reding { 17446fad8f66SThierry Reding struct tegra_output *output = connector_to_output(connector); 17456fad8f66SThierry Reding struct tegra_sor *sor = to_sor(output); 17466fad8f66SThierry Reding 17479542c237SThierry Reding if (sor->aux) 17489542c237SThierry Reding return drm_dp_aux_detect(sor->aux); 17496fad8f66SThierry Reding 1750459cc2c6SThierry Reding return tegra_output_connector_detect(connector, force); 17516fad8f66SThierry Reding } 17526fad8f66SThierry Reding 1753c31efa7aSThierry Reding static struct drm_connector_state * 1754c31efa7aSThierry Reding tegra_sor_connector_duplicate_state(struct drm_connector *connector) 1755c31efa7aSThierry Reding { 1756c31efa7aSThierry Reding struct tegra_sor_state *state = to_sor_state(connector->state); 1757c31efa7aSThierry Reding struct tegra_sor_state *copy; 1758c31efa7aSThierry Reding 1759c31efa7aSThierry Reding copy = kmemdup(state, sizeof(*state), GFP_KERNEL); 1760c31efa7aSThierry Reding if (!copy) 1761c31efa7aSThierry Reding return NULL; 1762c31efa7aSThierry Reding 1763c31efa7aSThierry Reding __drm_atomic_helper_connector_duplicate_state(connector, ©->base); 1764c31efa7aSThierry Reding 1765c31efa7aSThierry Reding return ©->base; 1766c31efa7aSThierry Reding } 1767c31efa7aSThierry Reding 17686fad8f66SThierry Reding static const struct drm_connector_funcs tegra_sor_connector_funcs = { 1769c31efa7aSThierry Reding .reset = tegra_sor_connector_reset, 17706fad8f66SThierry Reding .detect = tegra_sor_connector_detect, 17716fad8f66SThierry Reding .fill_modes = drm_helper_probe_single_connector_modes, 17726fad8f66SThierry Reding .destroy = tegra_output_connector_destroy, 1773c31efa7aSThierry Reding .atomic_duplicate_state = tegra_sor_connector_duplicate_state, 17744aa3df71SThierry Reding .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 17755b8e043bSThierry Reding .late_register = tegra_sor_late_register, 17765b8e043bSThierry Reding .early_unregister = tegra_sor_early_unregister, 17776fad8f66SThierry Reding }; 17786fad8f66SThierry Reding 17796fad8f66SThierry Reding static int tegra_sor_connector_get_modes(struct drm_connector *connector) 17806fad8f66SThierry Reding { 17816fad8f66SThierry Reding struct tegra_output *output = connector_to_output(connector); 17826fad8f66SThierry Reding struct tegra_sor *sor = to_sor(output); 17836fad8f66SThierry Reding int err; 17846fad8f66SThierry Reding 17859542c237SThierry Reding if (sor->aux) 17869542c237SThierry Reding drm_dp_aux_enable(sor->aux); 17876fad8f66SThierry Reding 17886fad8f66SThierry Reding err = tegra_output_connector_get_modes(connector); 17896fad8f66SThierry Reding 17909542c237SThierry Reding if (sor->aux) 17919542c237SThierry Reding drm_dp_aux_disable(sor->aux); 17926fad8f66SThierry Reding 17936fad8f66SThierry Reding return err; 17946fad8f66SThierry Reding } 17956fad8f66SThierry Reding 17966fad8f66SThierry Reding static enum drm_mode_status 17976fad8f66SThierry Reding tegra_sor_connector_mode_valid(struct drm_connector *connector, 17986fad8f66SThierry Reding struct drm_display_mode *mode) 17996fad8f66SThierry Reding { 18006fad8f66SThierry Reding return MODE_OK; 18016fad8f66SThierry Reding } 18026fad8f66SThierry Reding 18036fad8f66SThierry Reding static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = { 18046fad8f66SThierry Reding .get_modes = tegra_sor_connector_get_modes, 18056fad8f66SThierry Reding .mode_valid = tegra_sor_connector_mode_valid, 18066fad8f66SThierry Reding }; 18076fad8f66SThierry Reding 18086fad8f66SThierry Reding static const struct drm_encoder_funcs tegra_sor_encoder_funcs = { 18096fad8f66SThierry Reding .destroy = tegra_output_encoder_destroy, 18106fad8f66SThierry Reding }; 18116fad8f66SThierry Reding 181282f1511cSThierry Reding static int 181382f1511cSThierry Reding tegra_sor_encoder_atomic_check(struct drm_encoder *encoder, 181482f1511cSThierry Reding struct drm_crtc_state *crtc_state, 181582f1511cSThierry Reding struct drm_connector_state *conn_state) 181682f1511cSThierry Reding { 181782f1511cSThierry Reding struct tegra_output *output = encoder_to_output(encoder); 1818c31efa7aSThierry Reding struct tegra_sor_state *state = to_sor_state(conn_state); 181982f1511cSThierry Reding struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); 182082f1511cSThierry Reding unsigned long pclk = crtc_state->mode.clock * 1000; 182182f1511cSThierry Reding struct tegra_sor *sor = to_sor(output); 1822c31efa7aSThierry Reding struct drm_display_info *info; 182382f1511cSThierry Reding int err; 182482f1511cSThierry Reding 1825c31efa7aSThierry Reding info = &output->connector.display_info; 1826c31efa7aSThierry Reding 182736e90221SThierry Reding /* 182836e90221SThierry Reding * For HBR2 modes, the SOR brick needs to use the x20 multiplier, so 182936e90221SThierry Reding * the pixel clock must be corrected accordingly. 183036e90221SThierry Reding */ 183136e90221SThierry Reding if (pclk >= 340000000) { 183236e90221SThierry Reding state->link_speed = 20; 183336e90221SThierry Reding state->pclk = pclk / 2; 183436e90221SThierry Reding } else { 183536e90221SThierry Reding state->link_speed = 10; 183636e90221SThierry Reding state->pclk = pclk; 183736e90221SThierry Reding } 183836e90221SThierry Reding 183982f1511cSThierry Reding err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent, 184082f1511cSThierry Reding pclk, 0); 184182f1511cSThierry Reding if (err < 0) { 184282f1511cSThierry Reding dev_err(output->dev, "failed to setup CRTC state: %d\n", err); 184382f1511cSThierry Reding return err; 184482f1511cSThierry Reding } 184582f1511cSThierry Reding 1846c31efa7aSThierry Reding switch (info->bpc) { 1847c31efa7aSThierry Reding case 8: 1848c31efa7aSThierry Reding case 6: 1849c31efa7aSThierry Reding state->bpc = info->bpc; 1850c31efa7aSThierry Reding break; 1851c31efa7aSThierry Reding 1852c31efa7aSThierry Reding default: 1853c31efa7aSThierry Reding DRM_DEBUG_KMS("%u bits-per-color not supported\n", info->bpc); 1854c31efa7aSThierry Reding state->bpc = 8; 1855c31efa7aSThierry Reding break; 1856c31efa7aSThierry Reding } 1857c31efa7aSThierry Reding 185882f1511cSThierry Reding return 0; 185982f1511cSThierry Reding } 186082f1511cSThierry Reding 1861459cc2c6SThierry Reding static inline u32 tegra_sor_hdmi_subpack(const u8 *ptr, size_t size) 1862459cc2c6SThierry Reding { 1863459cc2c6SThierry Reding u32 value = 0; 1864459cc2c6SThierry Reding size_t i; 1865459cc2c6SThierry Reding 1866459cc2c6SThierry Reding for (i = size; i > 0; i--) 1867459cc2c6SThierry Reding value = (value << 8) | ptr[i - 1]; 1868459cc2c6SThierry Reding 1869459cc2c6SThierry Reding return value; 1870459cc2c6SThierry Reding } 1871459cc2c6SThierry Reding 1872459cc2c6SThierry Reding static void tegra_sor_hdmi_write_infopack(struct tegra_sor *sor, 1873459cc2c6SThierry Reding const void *data, size_t size) 1874459cc2c6SThierry Reding { 1875459cc2c6SThierry Reding const u8 *ptr = data; 1876459cc2c6SThierry Reding unsigned long offset; 1877459cc2c6SThierry Reding size_t i, j; 1878459cc2c6SThierry Reding u32 value; 1879459cc2c6SThierry Reding 1880459cc2c6SThierry Reding switch (ptr[0]) { 1881459cc2c6SThierry Reding case HDMI_INFOFRAME_TYPE_AVI: 1882459cc2c6SThierry Reding offset = SOR_HDMI_AVI_INFOFRAME_HEADER; 1883459cc2c6SThierry Reding break; 1884459cc2c6SThierry Reding 1885459cc2c6SThierry Reding case HDMI_INFOFRAME_TYPE_AUDIO: 1886459cc2c6SThierry Reding offset = SOR_HDMI_AUDIO_INFOFRAME_HEADER; 1887459cc2c6SThierry Reding break; 1888459cc2c6SThierry Reding 1889459cc2c6SThierry Reding case HDMI_INFOFRAME_TYPE_VENDOR: 1890459cc2c6SThierry Reding offset = SOR_HDMI_VSI_INFOFRAME_HEADER; 1891459cc2c6SThierry Reding break; 1892459cc2c6SThierry Reding 1893459cc2c6SThierry Reding default: 1894459cc2c6SThierry Reding dev_err(sor->dev, "unsupported infoframe type: %02x\n", 1895459cc2c6SThierry Reding ptr[0]); 1896459cc2c6SThierry Reding return; 1897459cc2c6SThierry Reding } 1898459cc2c6SThierry Reding 1899459cc2c6SThierry Reding value = INFOFRAME_HEADER_TYPE(ptr[0]) | 1900459cc2c6SThierry Reding INFOFRAME_HEADER_VERSION(ptr[1]) | 1901459cc2c6SThierry Reding INFOFRAME_HEADER_LEN(ptr[2]); 1902459cc2c6SThierry Reding tegra_sor_writel(sor, value, offset); 1903459cc2c6SThierry Reding offset++; 1904459cc2c6SThierry Reding 1905459cc2c6SThierry Reding /* 1906459cc2c6SThierry Reding * Each subpack contains 7 bytes, divided into: 1907459cc2c6SThierry Reding * - subpack_low: bytes 0 - 3 1908459cc2c6SThierry Reding * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00) 1909459cc2c6SThierry Reding */ 1910459cc2c6SThierry Reding for (i = 3, j = 0; i < size; i += 7, j += 8) { 1911459cc2c6SThierry Reding size_t rem = size - i, num = min_t(size_t, rem, 4); 1912459cc2c6SThierry Reding 1913459cc2c6SThierry Reding value = tegra_sor_hdmi_subpack(&ptr[i], num); 1914459cc2c6SThierry Reding tegra_sor_writel(sor, value, offset++); 1915459cc2c6SThierry Reding 1916459cc2c6SThierry Reding num = min_t(size_t, rem - num, 3); 1917459cc2c6SThierry Reding 1918459cc2c6SThierry Reding value = tegra_sor_hdmi_subpack(&ptr[i + 4], num); 1919459cc2c6SThierry Reding tegra_sor_writel(sor, value, offset++); 1920459cc2c6SThierry Reding } 1921459cc2c6SThierry Reding } 1922459cc2c6SThierry Reding 1923459cc2c6SThierry Reding static int 1924459cc2c6SThierry Reding tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor *sor, 1925459cc2c6SThierry Reding const struct drm_display_mode *mode) 1926459cc2c6SThierry Reding { 1927459cc2c6SThierry Reding u8 buffer[HDMI_INFOFRAME_SIZE(AVI)]; 1928459cc2c6SThierry Reding struct hdmi_avi_infoframe frame; 1929459cc2c6SThierry Reding u32 value; 1930459cc2c6SThierry Reding int err; 1931459cc2c6SThierry Reding 1932459cc2c6SThierry Reding /* disable AVI infoframe */ 1933459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL); 1934459cc2c6SThierry Reding value &= ~INFOFRAME_CTRL_SINGLE; 1935459cc2c6SThierry Reding value &= ~INFOFRAME_CTRL_OTHER; 1936459cc2c6SThierry Reding value &= ~INFOFRAME_CTRL_ENABLE; 1937459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL); 1938459cc2c6SThierry Reding 193913d0add3SVille Syrjälä err = drm_hdmi_avi_infoframe_from_display_mode(&frame, 194013d0add3SVille Syrjälä &sor->output.connector, mode); 1941459cc2c6SThierry Reding if (err < 0) { 1942459cc2c6SThierry Reding dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err); 1943459cc2c6SThierry Reding return err; 1944459cc2c6SThierry Reding } 1945459cc2c6SThierry Reding 1946459cc2c6SThierry Reding err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); 1947459cc2c6SThierry Reding if (err < 0) { 1948459cc2c6SThierry Reding dev_err(sor->dev, "failed to pack AVI infoframe: %d\n", err); 1949459cc2c6SThierry Reding return err; 1950459cc2c6SThierry Reding } 1951459cc2c6SThierry Reding 1952459cc2c6SThierry Reding tegra_sor_hdmi_write_infopack(sor, buffer, err); 1953459cc2c6SThierry Reding 1954459cc2c6SThierry Reding /* enable AVI infoframe */ 1955459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL); 1956459cc2c6SThierry Reding value |= INFOFRAME_CTRL_CHECKSUM_ENABLE; 1957459cc2c6SThierry Reding value |= INFOFRAME_CTRL_ENABLE; 1958459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL); 1959459cc2c6SThierry Reding 1960459cc2c6SThierry Reding return 0; 1961459cc2c6SThierry Reding } 1962459cc2c6SThierry Reding 19638e2988a7SThierry Reding static void tegra_sor_write_eld(struct tegra_sor *sor) 19648e2988a7SThierry Reding { 19658e2988a7SThierry Reding size_t length = drm_eld_size(sor->output.connector.eld), i; 19668e2988a7SThierry Reding 19678e2988a7SThierry Reding for (i = 0; i < length; i++) 19688e2988a7SThierry Reding tegra_sor_writel(sor, i << 8 | sor->output.connector.eld[i], 19698e2988a7SThierry Reding SOR_AUDIO_HDA_ELD_BUFWR); 19708e2988a7SThierry Reding 19718e2988a7SThierry Reding /* 19728e2988a7SThierry Reding * The HDA codec will always report an ELD buffer size of 96 bytes and 19738e2988a7SThierry Reding * the HDA codec driver will check that each byte read from the buffer 19748e2988a7SThierry Reding * is valid. Therefore every byte must be written, even if no 96 bytes 19758e2988a7SThierry Reding * were parsed from EDID. 19768e2988a7SThierry Reding */ 19778e2988a7SThierry Reding for (i = length; i < 96; i++) 19788e2988a7SThierry Reding tegra_sor_writel(sor, i << 8 | 0, SOR_AUDIO_HDA_ELD_BUFWR); 19798e2988a7SThierry Reding } 19808e2988a7SThierry Reding 19818e2988a7SThierry Reding static void tegra_sor_audio_prepare(struct tegra_sor *sor) 19828e2988a7SThierry Reding { 19838e2988a7SThierry Reding u32 value; 19848e2988a7SThierry Reding 1985f1f20eb9SThierry Reding /* 1986f1f20eb9SThierry Reding * Enable and unmask the HDA codec SCRATCH0 register interrupt. This 1987f1f20eb9SThierry Reding * is used for interoperability between the HDA codec driver and the 1988f1f20eb9SThierry Reding * HDMI/DP driver. 1989f1f20eb9SThierry Reding */ 1990f1f20eb9SThierry Reding value = SOR_INT_CODEC_SCRATCH1 | SOR_INT_CODEC_SCRATCH0; 1991f1f20eb9SThierry Reding tegra_sor_writel(sor, value, SOR_INT_ENABLE); 1992f1f20eb9SThierry Reding tegra_sor_writel(sor, value, SOR_INT_MASK); 1993f1f20eb9SThierry Reding 19948e2988a7SThierry Reding tegra_sor_write_eld(sor); 19958e2988a7SThierry Reding 19968e2988a7SThierry Reding value = SOR_AUDIO_HDA_PRESENSE_ELDV | SOR_AUDIO_HDA_PRESENSE_PD; 19978e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_AUDIO_HDA_PRESENSE); 19988e2988a7SThierry Reding } 19998e2988a7SThierry Reding 20008e2988a7SThierry Reding static void tegra_sor_audio_unprepare(struct tegra_sor *sor) 20018e2988a7SThierry Reding { 20028e2988a7SThierry Reding tegra_sor_writel(sor, 0, SOR_AUDIO_HDA_PRESENSE); 2003f1f20eb9SThierry Reding tegra_sor_writel(sor, 0, SOR_INT_MASK); 2004f1f20eb9SThierry Reding tegra_sor_writel(sor, 0, SOR_INT_ENABLE); 20058e2988a7SThierry Reding } 20068e2988a7SThierry Reding 2007a9087cf2SThierry Reding static void tegra_sor_audio_enable(struct tegra_sor *sor) 2008a9087cf2SThierry Reding { 2009a9087cf2SThierry Reding u32 value; 2010a9087cf2SThierry Reding 2011a9087cf2SThierry Reding value = tegra_sor_readl(sor, SOR_AUDIO_CNTRL); 2012a9087cf2SThierry Reding 2013a9087cf2SThierry Reding /* select HDA audio input */ 2014a9087cf2SThierry Reding value &= ~SOR_AUDIO_CNTRL_SOURCE_SELECT(SOURCE_SELECT_MASK); 2015a9087cf2SThierry Reding value |= SOR_AUDIO_CNTRL_SOURCE_SELECT(SOURCE_SELECT_HDA); 2016a9087cf2SThierry Reding 2017a9087cf2SThierry Reding /* inject null samples */ 2018a9087cf2SThierry Reding if (sor->format.channels != 2) 2019a9087cf2SThierry Reding value &= ~SOR_AUDIO_CNTRL_INJECT_NULLSMPL; 2020a9087cf2SThierry Reding else 2021a9087cf2SThierry Reding value |= SOR_AUDIO_CNTRL_INJECT_NULLSMPL; 2022a9087cf2SThierry Reding 2023a9087cf2SThierry Reding value |= SOR_AUDIO_CNTRL_AFIFO_FLUSH; 2024a9087cf2SThierry Reding 2025a9087cf2SThierry Reding tegra_sor_writel(sor, value, SOR_AUDIO_CNTRL); 2026a9087cf2SThierry Reding 2027a9087cf2SThierry Reding /* enable advertising HBR capability */ 2028a9087cf2SThierry Reding tegra_sor_writel(sor, SOR_AUDIO_SPARE_HBR_ENABLE, SOR_AUDIO_SPARE); 2029a9087cf2SThierry Reding } 2030a9087cf2SThierry Reding 20318e2988a7SThierry Reding static int tegra_sor_hdmi_enable_audio_infoframe(struct tegra_sor *sor) 20328e2988a7SThierry Reding { 20338e2988a7SThierry Reding u8 buffer[HDMI_INFOFRAME_SIZE(AUDIO)]; 20348e2988a7SThierry Reding struct hdmi_audio_infoframe frame; 20358e2988a7SThierry Reding u32 value; 20368e2988a7SThierry Reding int err; 20378e2988a7SThierry Reding 20388e2988a7SThierry Reding err = hdmi_audio_infoframe_init(&frame); 20398e2988a7SThierry Reding if (err < 0) { 20408e2988a7SThierry Reding dev_err(sor->dev, "failed to setup audio infoframe: %d\n", err); 20418e2988a7SThierry Reding return err; 20428e2988a7SThierry Reding } 20438e2988a7SThierry Reding 2044fad7b806SThierry Reding frame.channels = sor->format.channels; 20458e2988a7SThierry Reding 20468e2988a7SThierry Reding err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer)); 20478e2988a7SThierry Reding if (err < 0) { 20488e2988a7SThierry Reding dev_err(sor->dev, "failed to pack audio infoframe: %d\n", err); 20498e2988a7SThierry Reding return err; 20508e2988a7SThierry Reding } 20518e2988a7SThierry Reding 20528e2988a7SThierry Reding tegra_sor_hdmi_write_infopack(sor, buffer, err); 20538e2988a7SThierry Reding 20548e2988a7SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL); 20558e2988a7SThierry Reding value |= INFOFRAME_CTRL_CHECKSUM_ENABLE; 20568e2988a7SThierry Reding value |= INFOFRAME_CTRL_ENABLE; 20578e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL); 20588e2988a7SThierry Reding 20598e2988a7SThierry Reding return 0; 20608e2988a7SThierry Reding } 20618e2988a7SThierry Reding 20628e2988a7SThierry Reding static void tegra_sor_hdmi_audio_enable(struct tegra_sor *sor) 20638e2988a7SThierry Reding { 20648e2988a7SThierry Reding u32 value; 20658e2988a7SThierry Reding 2066a9087cf2SThierry Reding tegra_sor_audio_enable(sor); 20678e2988a7SThierry Reding 20688e2988a7SThierry Reding tegra_sor_writel(sor, 0, SOR_HDMI_ACR_CTRL); 20698e2988a7SThierry Reding 20708e2988a7SThierry Reding value = SOR_HDMI_SPARE_ACR_PRIORITY_HIGH | 20718e2988a7SThierry Reding SOR_HDMI_SPARE_CTS_RESET(1) | 20728e2988a7SThierry Reding SOR_HDMI_SPARE_HW_CTS_ENABLE; 20738e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_SPARE); 20748e2988a7SThierry Reding 20758e2988a7SThierry Reding /* enable HW CTS */ 20768e2988a7SThierry Reding value = SOR_HDMI_ACR_SUBPACK_LOW_SB1(0); 20778e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_ACR_0441_SUBPACK_LOW); 20788e2988a7SThierry Reding 20798e2988a7SThierry Reding /* allow packet to be sent */ 20808e2988a7SThierry Reding value = SOR_HDMI_ACR_SUBPACK_HIGH_ENABLE; 20818e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_ACR_0441_SUBPACK_HIGH); 20828e2988a7SThierry Reding 20838e2988a7SThierry Reding /* reset N counter and enable lookup */ 20848e2988a7SThierry Reding value = SOR_HDMI_AUDIO_N_RESET | SOR_HDMI_AUDIO_N_LOOKUP; 20858e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_N); 20868e2988a7SThierry Reding 2087fad7b806SThierry Reding value = (24000 * 4096) / (128 * sor->format.sample_rate / 1000); 20888e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_AUDIO_AVAL_0320); 20898e2988a7SThierry Reding tegra_sor_writel(sor, 4096, SOR_AUDIO_NVAL_0320); 20908e2988a7SThierry Reding 20918e2988a7SThierry Reding tegra_sor_writel(sor, 20000, SOR_AUDIO_AVAL_0441); 20928e2988a7SThierry Reding tegra_sor_writel(sor, 4704, SOR_AUDIO_NVAL_0441); 20938e2988a7SThierry Reding 20948e2988a7SThierry Reding tegra_sor_writel(sor, 20000, SOR_AUDIO_AVAL_0882); 20958e2988a7SThierry Reding tegra_sor_writel(sor, 9408, SOR_AUDIO_NVAL_0882); 20968e2988a7SThierry Reding 20978e2988a7SThierry Reding tegra_sor_writel(sor, 20000, SOR_AUDIO_AVAL_1764); 20988e2988a7SThierry Reding tegra_sor_writel(sor, 18816, SOR_AUDIO_NVAL_1764); 20998e2988a7SThierry Reding 2100fad7b806SThierry Reding value = (24000 * 6144) / (128 * sor->format.sample_rate / 1000); 21018e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_AUDIO_AVAL_0480); 21028e2988a7SThierry Reding tegra_sor_writel(sor, 6144, SOR_AUDIO_NVAL_0480); 21038e2988a7SThierry Reding 2104fad7b806SThierry Reding value = (24000 * 12288) / (128 * sor->format.sample_rate / 1000); 21058e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_AUDIO_AVAL_0960); 21068e2988a7SThierry Reding tegra_sor_writel(sor, 12288, SOR_AUDIO_NVAL_0960); 21078e2988a7SThierry Reding 2108fad7b806SThierry Reding value = (24000 * 24576) / (128 * sor->format.sample_rate / 1000); 21098e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_AUDIO_AVAL_1920); 21108e2988a7SThierry Reding tegra_sor_writel(sor, 24576, SOR_AUDIO_NVAL_1920); 21118e2988a7SThierry Reding 21128e2988a7SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_N); 21138e2988a7SThierry Reding value &= ~SOR_HDMI_AUDIO_N_RESET; 21148e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_N); 21158e2988a7SThierry Reding 21168e2988a7SThierry Reding tegra_sor_hdmi_enable_audio_infoframe(sor); 21178e2988a7SThierry Reding } 21188e2988a7SThierry Reding 2119459cc2c6SThierry Reding static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor *sor) 2120459cc2c6SThierry Reding { 2121459cc2c6SThierry Reding u32 value; 2122459cc2c6SThierry Reding 2123459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL); 2124459cc2c6SThierry Reding value &= ~INFOFRAME_CTRL_ENABLE; 2125459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL); 2126459cc2c6SThierry Reding } 2127459cc2c6SThierry Reding 21288e2988a7SThierry Reding static void tegra_sor_hdmi_audio_disable(struct tegra_sor *sor) 21298e2988a7SThierry Reding { 21308e2988a7SThierry Reding tegra_sor_hdmi_disable_audio_infoframe(sor); 21318e2988a7SThierry Reding } 21328e2988a7SThierry Reding 2133459cc2c6SThierry Reding static struct tegra_sor_hdmi_settings * 2134459cc2c6SThierry Reding tegra_sor_hdmi_find_settings(struct tegra_sor *sor, unsigned long frequency) 2135459cc2c6SThierry Reding { 2136459cc2c6SThierry Reding unsigned int i; 2137459cc2c6SThierry Reding 2138459cc2c6SThierry Reding for (i = 0; i < sor->num_settings; i++) 2139459cc2c6SThierry Reding if (frequency <= sor->settings[i].frequency) 2140459cc2c6SThierry Reding return &sor->settings[i]; 2141459cc2c6SThierry Reding 2142459cc2c6SThierry Reding return NULL; 2143459cc2c6SThierry Reding } 2144459cc2c6SThierry Reding 214536e90221SThierry Reding static void tegra_sor_hdmi_disable_scrambling(struct tegra_sor *sor) 214636e90221SThierry Reding { 214736e90221SThierry Reding u32 value; 214836e90221SThierry Reding 214936e90221SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI2_CTRL); 215036e90221SThierry Reding value &= ~SOR_HDMI2_CTRL_CLOCK_MODE_DIV_BY_4; 215136e90221SThierry Reding value &= ~SOR_HDMI2_CTRL_SCRAMBLE; 215236e90221SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI2_CTRL); 215336e90221SThierry Reding } 215436e90221SThierry Reding 215536e90221SThierry Reding static void tegra_sor_hdmi_scdc_disable(struct tegra_sor *sor) 215636e90221SThierry Reding { 215736e90221SThierry Reding struct i2c_adapter *ddc = sor->output.ddc; 215836e90221SThierry Reding 215936e90221SThierry Reding drm_scdc_set_high_tmds_clock_ratio(ddc, false); 216036e90221SThierry Reding drm_scdc_set_scrambling(ddc, false); 216136e90221SThierry Reding 216236e90221SThierry Reding tegra_sor_hdmi_disable_scrambling(sor); 216336e90221SThierry Reding } 216436e90221SThierry Reding 216536e90221SThierry Reding static void tegra_sor_hdmi_scdc_stop(struct tegra_sor *sor) 216636e90221SThierry Reding { 216736e90221SThierry Reding if (sor->scdc_enabled) { 216836e90221SThierry Reding cancel_delayed_work_sync(&sor->scdc); 216936e90221SThierry Reding tegra_sor_hdmi_scdc_disable(sor); 217036e90221SThierry Reding } 217136e90221SThierry Reding } 217236e90221SThierry Reding 217336e90221SThierry Reding static void tegra_sor_hdmi_enable_scrambling(struct tegra_sor *sor) 217436e90221SThierry Reding { 217536e90221SThierry Reding u32 value; 217636e90221SThierry Reding 217736e90221SThierry Reding value = tegra_sor_readl(sor, SOR_HDMI2_CTRL); 217836e90221SThierry Reding value |= SOR_HDMI2_CTRL_CLOCK_MODE_DIV_BY_4; 217936e90221SThierry Reding value |= SOR_HDMI2_CTRL_SCRAMBLE; 218036e90221SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI2_CTRL); 218136e90221SThierry Reding } 218236e90221SThierry Reding 218336e90221SThierry Reding static void tegra_sor_hdmi_scdc_enable(struct tegra_sor *sor) 218436e90221SThierry Reding { 218536e90221SThierry Reding struct i2c_adapter *ddc = sor->output.ddc; 218636e90221SThierry Reding 218736e90221SThierry Reding drm_scdc_set_high_tmds_clock_ratio(ddc, true); 218836e90221SThierry Reding drm_scdc_set_scrambling(ddc, true); 218936e90221SThierry Reding 219036e90221SThierry Reding tegra_sor_hdmi_enable_scrambling(sor); 219136e90221SThierry Reding } 219236e90221SThierry Reding 219336e90221SThierry Reding static void tegra_sor_hdmi_scdc_work(struct work_struct *work) 219436e90221SThierry Reding { 219536e90221SThierry Reding struct tegra_sor *sor = container_of(work, struct tegra_sor, scdc.work); 219636e90221SThierry Reding struct i2c_adapter *ddc = sor->output.ddc; 219736e90221SThierry Reding 219836e90221SThierry Reding if (!drm_scdc_get_scrambling_status(ddc)) { 219936e90221SThierry Reding DRM_DEBUG_KMS("SCDC not scrambled\n"); 220036e90221SThierry Reding tegra_sor_hdmi_scdc_enable(sor); 220136e90221SThierry Reding } 220236e90221SThierry Reding 220336e90221SThierry Reding schedule_delayed_work(&sor->scdc, msecs_to_jiffies(5000)); 220436e90221SThierry Reding } 220536e90221SThierry Reding 220636e90221SThierry Reding static void tegra_sor_hdmi_scdc_start(struct tegra_sor *sor) 220736e90221SThierry Reding { 220836e90221SThierry Reding struct drm_scdc *scdc = &sor->output.connector.display_info.hdmi.scdc; 220936e90221SThierry Reding struct drm_display_mode *mode; 221036e90221SThierry Reding 221136e90221SThierry Reding mode = &sor->output.encoder.crtc->state->adjusted_mode; 221236e90221SThierry Reding 221336e90221SThierry Reding if (mode->clock >= 340000 && scdc->supported) { 221436e90221SThierry Reding schedule_delayed_work(&sor->scdc, msecs_to_jiffies(5000)); 221536e90221SThierry Reding tegra_sor_hdmi_scdc_enable(sor); 221636e90221SThierry Reding sor->scdc_enabled = true; 221736e90221SThierry Reding } 221836e90221SThierry Reding } 221936e90221SThierry Reding 2220459cc2c6SThierry Reding static void tegra_sor_hdmi_disable(struct drm_encoder *encoder) 2221459cc2c6SThierry Reding { 2222459cc2c6SThierry Reding struct tegra_output *output = encoder_to_output(encoder); 2223459cc2c6SThierry Reding struct tegra_dc *dc = to_tegra_dc(encoder->crtc); 2224459cc2c6SThierry Reding struct tegra_sor *sor = to_sor(output); 2225459cc2c6SThierry Reding u32 value; 2226459cc2c6SThierry Reding int err; 2227459cc2c6SThierry Reding 22288e2988a7SThierry Reding tegra_sor_audio_unprepare(sor); 222936e90221SThierry Reding tegra_sor_hdmi_scdc_stop(sor); 223036e90221SThierry Reding 2231459cc2c6SThierry Reding err = tegra_sor_detach(sor); 2232459cc2c6SThierry Reding if (err < 0) 2233459cc2c6SThierry Reding dev_err(sor->dev, "failed to detach SOR: %d\n", err); 2234459cc2c6SThierry Reding 2235459cc2c6SThierry Reding tegra_sor_writel(sor, 0, SOR_STATE1); 2236459cc2c6SThierry Reding tegra_sor_update(sor); 2237459cc2c6SThierry Reding 2238459cc2c6SThierry Reding /* disable display to SOR clock */ 2239459cc2c6SThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); 2240c57997bcSThierry Reding 2241c57997bcSThierry Reding if (!sor->soc->has_nvdisplay) 2242d278e4a9SThierry Reding value &= ~SOR1_TIMING_CYA; 2243d278e4a9SThierry Reding 2244c57997bcSThierry Reding value &= ~SOR_ENABLE(sor->index); 2245c57997bcSThierry Reding 2246459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); 2247459cc2c6SThierry Reding 2248459cc2c6SThierry Reding tegra_dc_commit(dc); 2249459cc2c6SThierry Reding 2250459cc2c6SThierry Reding err = tegra_sor_power_down(sor); 2251459cc2c6SThierry Reding if (err < 0) 2252459cc2c6SThierry Reding dev_err(sor->dev, "failed to power down SOR: %d\n", err); 2253459cc2c6SThierry Reding 2254c57997bcSThierry Reding err = tegra_io_pad_power_disable(sor->pad); 2255459cc2c6SThierry Reding if (err < 0) 2256c57997bcSThierry Reding dev_err(sor->dev, "failed to power off I/O pad: %d\n", err); 2257459cc2c6SThierry Reding 2258aaff8bd2SThierry Reding pm_runtime_put(sor->dev); 2259459cc2c6SThierry Reding } 2260459cc2c6SThierry Reding 2261459cc2c6SThierry Reding static void tegra_sor_hdmi_enable(struct drm_encoder *encoder) 2262459cc2c6SThierry Reding { 2263459cc2c6SThierry Reding struct tegra_output *output = encoder_to_output(encoder); 2264459cc2c6SThierry Reding unsigned int h_ref_to_sync = 1, pulse_start, max_ac; 2265459cc2c6SThierry Reding struct tegra_dc *dc = to_tegra_dc(encoder->crtc); 2266459cc2c6SThierry Reding struct tegra_sor_hdmi_settings *settings; 2267459cc2c6SThierry Reding struct tegra_sor *sor = to_sor(output); 2268c31efa7aSThierry Reding struct tegra_sor_state *state; 2269459cc2c6SThierry Reding struct drm_display_mode *mode; 227036e90221SThierry Reding unsigned long rate, pclk; 227130b49435SThierry Reding unsigned int div, i; 2272459cc2c6SThierry Reding u32 value; 2273459cc2c6SThierry Reding int err; 2274459cc2c6SThierry Reding 2275c31efa7aSThierry Reding state = to_sor_state(output->connector.state); 2276459cc2c6SThierry Reding mode = &encoder->crtc->state->adjusted_mode; 227736e90221SThierry Reding pclk = mode->clock * 1000; 2278459cc2c6SThierry Reding 2279aaff8bd2SThierry Reding pm_runtime_get_sync(sor->dev); 2280459cc2c6SThierry Reding 228125bb2cecSThierry Reding /* switch to safe parent clock */ 228225bb2cecSThierry Reding err = tegra_sor_set_parent_clock(sor, sor->clk_safe); 2283e1335e2fSThierry Reding if (err < 0) { 2284459cc2c6SThierry Reding dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); 2285e1335e2fSThierry Reding return; 2286e1335e2fSThierry Reding } 2287459cc2c6SThierry Reding 2288459cc2c6SThierry Reding div = clk_get_rate(sor->clk) / 1000000 * 4; 2289459cc2c6SThierry Reding 2290c57997bcSThierry Reding err = tegra_io_pad_power_enable(sor->pad); 2291459cc2c6SThierry Reding if (err < 0) 2292c57997bcSThierry Reding dev_err(sor->dev, "failed to power on I/O pad: %d\n", err); 2293459cc2c6SThierry Reding 2294459cc2c6SThierry Reding usleep_range(20, 100); 2295459cc2c6SThierry Reding 2296880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 2297459cc2c6SThierry Reding value &= ~SOR_PLL2_BANDGAP_POWERDOWN; 2298880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 2299459cc2c6SThierry Reding 2300459cc2c6SThierry Reding usleep_range(20, 100); 2301459cc2c6SThierry Reding 2302880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll3); 2303459cc2c6SThierry Reding value &= ~SOR_PLL3_PLL_VDD_MODE_3V3; 2304880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll3); 2305459cc2c6SThierry Reding 2306880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll0); 2307459cc2c6SThierry Reding value &= ~SOR_PLL0_VCOPD; 2308459cc2c6SThierry Reding value &= ~SOR_PLL0_PWR; 2309880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll0); 2310459cc2c6SThierry Reding 2311880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 2312459cc2c6SThierry Reding value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; 2313880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 2314459cc2c6SThierry Reding 2315459cc2c6SThierry Reding usleep_range(200, 400); 2316459cc2c6SThierry Reding 2317880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 2318459cc2c6SThierry Reding value &= ~SOR_PLL2_POWERDOWN_OVERRIDE; 2319459cc2c6SThierry Reding value &= ~SOR_PLL2_PORT_POWERDOWN; 2320880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 2321459cc2c6SThierry Reding 2322459cc2c6SThierry Reding usleep_range(20, 100); 2323459cc2c6SThierry Reding 2324880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 2325459cc2c6SThierry Reding value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 | 2326459cc2c6SThierry Reding SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2; 2327880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 2328459cc2c6SThierry Reding 2329459cc2c6SThierry Reding while (true) { 2330459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); 2331459cc2c6SThierry Reding if ((value & SOR_LANE_SEQ_CTL_STATE_BUSY) == 0) 2332459cc2c6SThierry Reding break; 2333459cc2c6SThierry Reding 2334459cc2c6SThierry Reding usleep_range(250, 1000); 2335459cc2c6SThierry Reding } 2336459cc2c6SThierry Reding 2337459cc2c6SThierry Reding value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | 2338459cc2c6SThierry Reding SOR_LANE_SEQ_CTL_POWER_STATE_UP | SOR_LANE_SEQ_CTL_DELAY(5); 2339459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); 2340459cc2c6SThierry Reding 2341459cc2c6SThierry Reding while (true) { 2342459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); 2343459cc2c6SThierry Reding if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) 2344459cc2c6SThierry Reding break; 2345459cc2c6SThierry Reding 2346459cc2c6SThierry Reding usleep_range(250, 1000); 2347459cc2c6SThierry Reding } 2348459cc2c6SThierry Reding 2349459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_CLK_CNTRL); 2350459cc2c6SThierry Reding value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; 2351459cc2c6SThierry Reding value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; 2352459cc2c6SThierry Reding 235336e90221SThierry Reding if (mode->clock < 340000) { 235436e90221SThierry Reding DRM_DEBUG_KMS("setting 2.7 GHz link speed\n"); 2355459cc2c6SThierry Reding value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70; 235636e90221SThierry Reding } else { 235736e90221SThierry Reding DRM_DEBUG_KMS("setting 5.4 GHz link speed\n"); 2358459cc2c6SThierry Reding value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40; 235936e90221SThierry Reding } 2360459cc2c6SThierry Reding 2361459cc2c6SThierry Reding value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK; 2362459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_CLK_CNTRL); 2363459cc2c6SThierry Reding 2364c57997bcSThierry Reding /* SOR pad PLL stabilization time */ 2365c57997bcSThierry Reding usleep_range(250, 1000); 2366c57997bcSThierry Reding 2367c57997bcSThierry Reding value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); 2368c57997bcSThierry Reding value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK; 2369c57997bcSThierry Reding value |= SOR_DP_LINKCTL_LANE_COUNT(4); 2370c57997bcSThierry Reding tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); 2371c57997bcSThierry Reding 2372459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_DP_SPARE0); 2373c57997bcSThierry Reding value &= ~SOR_DP_SPARE_DISP_VIDEO_PREAMBLE; 2374459cc2c6SThierry Reding value &= ~SOR_DP_SPARE_PANEL_INTERNAL; 2375c57997bcSThierry Reding value &= ~SOR_DP_SPARE_SEQ_ENABLE; 2376c57997bcSThierry Reding value &= ~SOR_DP_SPARE_MACRO_SOR_CLK; 2377459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_DP_SPARE0); 2378459cc2c6SThierry Reding 2379459cc2c6SThierry Reding value = SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) | 2380459cc2c6SThierry Reding SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8); 2381459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_SEQ_CTL); 2382459cc2c6SThierry Reding 2383459cc2c6SThierry Reding value = SOR_SEQ_INST_DRIVE_PWM_OUT_LO | SOR_SEQ_INST_HALT | 2384459cc2c6SThierry Reding SOR_SEQ_INST_WAIT_VSYNC | SOR_SEQ_INST_WAIT(1); 2385459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_SEQ_INST(0)); 2386459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_SEQ_INST(8)); 2387459cc2c6SThierry Reding 2388c57997bcSThierry Reding if (!sor->soc->has_nvdisplay) { 2389459cc2c6SThierry Reding /* program the reference clock */ 2390459cc2c6SThierry Reding value = SOR_REFCLK_DIV_INT(div) | SOR_REFCLK_DIV_FRAC(div); 2391459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_REFCLK); 2392c57997bcSThierry Reding } 2393459cc2c6SThierry Reding 239430b49435SThierry Reding /* XXX not in TRM */ 239530b49435SThierry Reding for (value = 0, i = 0; i < 5; i++) 23966d6c815dSThierry Reding value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->xbar_cfg[i]) | 239730b49435SThierry Reding SOR_XBAR_CTRL_LINK1_XSEL(i, i); 2398459cc2c6SThierry Reding 2399459cc2c6SThierry Reding tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL); 240030b49435SThierry Reding tegra_sor_writel(sor, value, SOR_XBAR_CTRL); 2401459cc2c6SThierry Reding 240261417aaaSThierry Reding /* 240361417aaaSThierry Reding * Switch the pad clock to the DP clock. Note that we cannot actually 240461417aaaSThierry Reding * do this because Tegra186 and later don't support clk_set_parent() 240561417aaaSThierry Reding * on the sorX_pad_clkout clocks. We already do the equivalent above 240661417aaaSThierry Reding * using the DP_CLK_SEL mux of the SOR_CLK_CNTRL register. 240761417aaaSThierry Reding */ 240861417aaaSThierry Reding #if 0 240961417aaaSThierry Reding err = clk_set_parent(sor->clk_pad, sor->clk_dp); 2410e1335e2fSThierry Reding if (err < 0) { 241161417aaaSThierry Reding dev_err(sor->dev, "failed to select pad parent clock: %d\n", 241261417aaaSThierry Reding err); 241361417aaaSThierry Reding return; 241461417aaaSThierry Reding } 241561417aaaSThierry Reding #endif 241661417aaaSThierry Reding 241761417aaaSThierry Reding /* switch the SOR clock to the pad clock */ 241861417aaaSThierry Reding err = tegra_sor_set_parent_clock(sor, sor->clk_pad); 241961417aaaSThierry Reding if (err < 0) { 242061417aaaSThierry Reding dev_err(sor->dev, "failed to select SOR parent clock: %d\n", 242161417aaaSThierry Reding err); 2422e1335e2fSThierry Reding return; 2423e1335e2fSThierry Reding } 2424e1335e2fSThierry Reding 242561417aaaSThierry Reding /* switch the output clock to the parent pixel clock */ 242661417aaaSThierry Reding err = clk_set_parent(sor->clk, sor->clk_parent); 2427e1335e2fSThierry Reding if (err < 0) { 242861417aaaSThierry Reding dev_err(sor->dev, "failed to select output parent clock: %d\n", 242961417aaaSThierry Reding err); 2430e1335e2fSThierry Reding return; 2431e1335e2fSThierry Reding } 2432459cc2c6SThierry Reding 243336e90221SThierry Reding /* adjust clock rate for HDMI 2.0 modes */ 243436e90221SThierry Reding rate = clk_get_rate(sor->clk_parent); 243536e90221SThierry Reding 243636e90221SThierry Reding if (mode->clock >= 340000) 243736e90221SThierry Reding rate /= 2; 243836e90221SThierry Reding 243936e90221SThierry Reding DRM_DEBUG_KMS("setting clock to %lu Hz, mode: %lu Hz\n", rate, pclk); 244036e90221SThierry Reding 244136e90221SThierry Reding clk_set_rate(sor->clk, rate); 2442c57997bcSThierry Reding 2443c57997bcSThierry Reding if (!sor->soc->has_nvdisplay) { 2444459cc2c6SThierry Reding value = SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc->pipe); 2445459cc2c6SThierry Reding 2446459cc2c6SThierry Reding /* XXX is this the proper check? */ 2447459cc2c6SThierry Reding if (mode->clock < 75000) 2448459cc2c6SThierry Reding value |= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED; 2449459cc2c6SThierry Reding 2450459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_INPUT_CONTROL); 2451c57997bcSThierry Reding } 2452459cc2c6SThierry Reding 2453459cc2c6SThierry Reding max_ac = ((mode->htotal - mode->hdisplay) - SOR_REKEY - 18) / 32; 2454459cc2c6SThierry Reding 2455459cc2c6SThierry Reding value = SOR_HDMI_CTRL_ENABLE | SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac) | 2456459cc2c6SThierry Reding SOR_HDMI_CTRL_AUDIO_LAYOUT | SOR_HDMI_CTRL_REKEY(SOR_REKEY); 2457459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_HDMI_CTRL); 2458459cc2c6SThierry Reding 2459c57997bcSThierry Reding if (!dc->soc->has_nvdisplay) { 2460459cc2c6SThierry Reding /* H_PULSE2 setup */ 2461c57997bcSThierry Reding pulse_start = h_ref_to_sync + 2462c57997bcSThierry Reding (mode->hsync_end - mode->hsync_start) + 2463459cc2c6SThierry Reding (mode->htotal - mode->hsync_end) - 10; 2464459cc2c6SThierry Reding 2465459cc2c6SThierry Reding value = PULSE_LAST_END_A | PULSE_QUAL_VACTIVE | 2466459cc2c6SThierry Reding PULSE_POLARITY_HIGH | PULSE_MODE_NORMAL; 2467459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL); 2468459cc2c6SThierry Reding 2469459cc2c6SThierry Reding value = PULSE_END(pulse_start + 8) | PULSE_START(pulse_start); 2470459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A); 2471459cc2c6SThierry Reding 2472459cc2c6SThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_SIGNAL_OPTIONS0); 2473459cc2c6SThierry Reding value |= H_PULSE2_ENABLE; 2474459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_SIGNAL_OPTIONS0); 2475c57997bcSThierry Reding } 2476459cc2c6SThierry Reding 2477459cc2c6SThierry Reding /* infoframe setup */ 2478459cc2c6SThierry Reding err = tegra_sor_hdmi_setup_avi_infoframe(sor, mode); 2479459cc2c6SThierry Reding if (err < 0) 2480459cc2c6SThierry Reding dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err); 2481459cc2c6SThierry Reding 2482459cc2c6SThierry Reding /* XXX HDMI audio support not implemented yet */ 2483459cc2c6SThierry Reding tegra_sor_hdmi_disable_audio_infoframe(sor); 2484459cc2c6SThierry Reding 2485459cc2c6SThierry Reding /* use single TMDS protocol */ 2486459cc2c6SThierry Reding value = tegra_sor_readl(sor, SOR_STATE1); 2487459cc2c6SThierry Reding value &= ~SOR_STATE_ASY_PROTOCOL_MASK; 2488459cc2c6SThierry Reding value |= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A; 2489459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_STATE1); 2490459cc2c6SThierry Reding 2491459cc2c6SThierry Reding /* power up pad calibration */ 2492880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 2493459cc2c6SThierry Reding value &= ~SOR_DP_PADCTL_PAD_CAL_PD; 2494880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 2495459cc2c6SThierry Reding 2496459cc2c6SThierry Reding /* production settings */ 2497459cc2c6SThierry Reding settings = tegra_sor_hdmi_find_settings(sor, mode->clock * 1000); 2498db8b42fbSDan Carpenter if (!settings) { 2499db8b42fbSDan Carpenter dev_err(sor->dev, "no settings for pixel clock %d Hz\n", 2500db8b42fbSDan Carpenter mode->clock * 1000); 2501459cc2c6SThierry Reding return; 2502459cc2c6SThierry Reding } 2503459cc2c6SThierry Reding 2504880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll0); 2505459cc2c6SThierry Reding value &= ~SOR_PLL0_ICHPMP_MASK; 2506c57997bcSThierry Reding value &= ~SOR_PLL0_FILTER_MASK; 2507459cc2c6SThierry Reding value &= ~SOR_PLL0_VCOCAP_MASK; 2508459cc2c6SThierry Reding value |= SOR_PLL0_ICHPMP(settings->ichpmp); 2509c57997bcSThierry Reding value |= SOR_PLL0_FILTER(settings->filter); 2510459cc2c6SThierry Reding value |= SOR_PLL0_VCOCAP(settings->vcocap); 2511880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll0); 2512459cc2c6SThierry Reding 2513c57997bcSThierry Reding /* XXX not in TRM */ 2514880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll1); 2515459cc2c6SThierry Reding value &= ~SOR_PLL1_LOADADJ_MASK; 2516c57997bcSThierry Reding value &= ~SOR_PLL1_TMDS_TERMADJ_MASK; 2517459cc2c6SThierry Reding value |= SOR_PLL1_LOADADJ(settings->loadadj); 2518c57997bcSThierry Reding value |= SOR_PLL1_TMDS_TERMADJ(settings->tmds_termadj); 2519c57997bcSThierry Reding value |= SOR_PLL1_TMDS_TERM; 2520880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll1); 2521459cc2c6SThierry Reding 2522880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll3); 2523c57997bcSThierry Reding value &= ~SOR_PLL3_BG_TEMP_COEF_MASK; 2524459cc2c6SThierry Reding value &= ~SOR_PLL3_BG_VREF_LEVEL_MASK; 2525c57997bcSThierry Reding value &= ~SOR_PLL3_AVDD10_LEVEL_MASK; 2526c57997bcSThierry Reding value &= ~SOR_PLL3_AVDD14_LEVEL_MASK; 2527c57997bcSThierry Reding value |= SOR_PLL3_BG_TEMP_COEF(settings->bg_temp_coef); 2528c57997bcSThierry Reding value |= SOR_PLL3_BG_VREF_LEVEL(settings->bg_vref_level); 2529c57997bcSThierry Reding value |= SOR_PLL3_AVDD10_LEVEL(settings->avdd10_level); 2530c57997bcSThierry Reding value |= SOR_PLL3_AVDD14_LEVEL(settings->avdd14_level); 2531880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll3); 2532459cc2c6SThierry Reding 2533c57997bcSThierry Reding value = settings->drive_current[3] << 24 | 2534c57997bcSThierry Reding settings->drive_current[2] << 16 | 2535c57997bcSThierry Reding settings->drive_current[1] << 8 | 2536c57997bcSThierry Reding settings->drive_current[0] << 0; 2537459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0); 2538459cc2c6SThierry Reding 2539c57997bcSThierry Reding value = settings->preemphasis[3] << 24 | 2540c57997bcSThierry Reding settings->preemphasis[2] << 16 | 2541c57997bcSThierry Reding settings->preemphasis[1] << 8 | 2542c57997bcSThierry Reding settings->preemphasis[0] << 0; 2543459cc2c6SThierry Reding tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0); 2544459cc2c6SThierry Reding 2545880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 2546459cc2c6SThierry Reding value &= ~SOR_DP_PADCTL_TX_PU_MASK; 2547459cc2c6SThierry Reding value |= SOR_DP_PADCTL_TX_PU_ENABLE; 2548c57997bcSThierry Reding value |= SOR_DP_PADCTL_TX_PU(settings->tx_pu_value); 2549880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 2550459cc2c6SThierry Reding 2551c57997bcSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl2); 2552c57997bcSThierry Reding value &= ~SOR_DP_PADCTL_SPAREPLL_MASK; 2553c57997bcSThierry Reding value |= SOR_DP_PADCTL_SPAREPLL(settings->sparepll); 2554c57997bcSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl2); 2555c57997bcSThierry Reding 2556459cc2c6SThierry Reding /* power down pad calibration */ 2557880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); 2558459cc2c6SThierry Reding value |= SOR_DP_PADCTL_PAD_CAL_PD; 2559880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); 2560459cc2c6SThierry Reding 2561c57997bcSThierry Reding if (!dc->soc->has_nvdisplay) { 2562459cc2c6SThierry Reding /* miscellaneous display controller settings */ 2563459cc2c6SThierry Reding value = VSYNC_H_POSITION(1); 2564459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_TIMING_OPTIONS); 2565c57997bcSThierry Reding } 2566459cc2c6SThierry Reding 2567459cc2c6SThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_COLOR_CONTROL); 2568459cc2c6SThierry Reding value &= ~DITHER_CONTROL_MASK; 2569459cc2c6SThierry Reding value &= ~BASE_COLOR_SIZE_MASK; 2570459cc2c6SThierry Reding 2571c31efa7aSThierry Reding switch (state->bpc) { 2572459cc2c6SThierry Reding case 6: 2573459cc2c6SThierry Reding value |= BASE_COLOR_SIZE_666; 2574459cc2c6SThierry Reding break; 2575459cc2c6SThierry Reding 2576459cc2c6SThierry Reding case 8: 2577459cc2c6SThierry Reding value |= BASE_COLOR_SIZE_888; 2578459cc2c6SThierry Reding break; 2579459cc2c6SThierry Reding 2580c57997bcSThierry Reding case 10: 2581c57997bcSThierry Reding value |= BASE_COLOR_SIZE_101010; 2582c57997bcSThierry Reding break; 2583c57997bcSThierry Reding 2584c57997bcSThierry Reding case 12: 2585c57997bcSThierry Reding value |= BASE_COLOR_SIZE_121212; 2586c57997bcSThierry Reding break; 2587c57997bcSThierry Reding 2588459cc2c6SThierry Reding default: 2589c31efa7aSThierry Reding WARN(1, "%u bits-per-color not supported\n", state->bpc); 2590c31efa7aSThierry Reding value |= BASE_COLOR_SIZE_888; 2591459cc2c6SThierry Reding break; 2592459cc2c6SThierry Reding } 2593459cc2c6SThierry Reding 2594459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_COLOR_CONTROL); 2595459cc2c6SThierry Reding 2596c57997bcSThierry Reding /* XXX set display head owner */ 2597c57997bcSThierry Reding value = tegra_sor_readl(sor, SOR_STATE1); 2598c57997bcSThierry Reding value &= ~SOR_STATE_ASY_OWNER_MASK; 2599c57997bcSThierry Reding value |= SOR_STATE_ASY_OWNER(1 + dc->pipe); 2600c57997bcSThierry Reding tegra_sor_writel(sor, value, SOR_STATE1); 2601c57997bcSThierry Reding 2602459cc2c6SThierry Reding err = tegra_sor_power_up(sor, 250); 2603459cc2c6SThierry Reding if (err < 0) 2604459cc2c6SThierry Reding dev_err(sor->dev, "failed to power up SOR: %d\n", err); 2605459cc2c6SThierry Reding 26062bd1dd39SThierry Reding /* configure dynamic range of output */ 2607880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->head_state0 + dc->pipe); 2608459cc2c6SThierry Reding value &= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK; 2609459cc2c6SThierry Reding value &= ~SOR_HEAD_STATE_DYNRANGE_MASK; 2610880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->head_state0 + dc->pipe); 2611459cc2c6SThierry Reding 26122bd1dd39SThierry Reding /* configure colorspace */ 2613880cee0bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->head_state0 + dc->pipe); 2614459cc2c6SThierry Reding value &= ~SOR_HEAD_STATE_COLORSPACE_MASK; 2615459cc2c6SThierry Reding value |= SOR_HEAD_STATE_COLORSPACE_RGB; 2616880cee0bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->head_state0 + dc->pipe); 2617459cc2c6SThierry Reding 2618c31efa7aSThierry Reding tegra_sor_mode_set(sor, mode, state); 2619459cc2c6SThierry Reding 2620459cc2c6SThierry Reding tegra_sor_update(sor); 2621459cc2c6SThierry Reding 2622c57997bcSThierry Reding /* program preamble timing in SOR (XXX) */ 2623c57997bcSThierry Reding value = tegra_sor_readl(sor, SOR_DP_SPARE0); 2624c57997bcSThierry Reding value &= ~SOR_DP_SPARE_DISP_VIDEO_PREAMBLE; 2625c57997bcSThierry Reding tegra_sor_writel(sor, value, SOR_DP_SPARE0); 2626c57997bcSThierry Reding 2627459cc2c6SThierry Reding err = tegra_sor_attach(sor); 2628459cc2c6SThierry Reding if (err < 0) 2629459cc2c6SThierry Reding dev_err(sor->dev, "failed to attach SOR: %d\n", err); 2630459cc2c6SThierry Reding 2631459cc2c6SThierry Reding /* enable display to SOR clock and generate HDMI preamble */ 2632459cc2c6SThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); 2633c57997bcSThierry Reding 2634c57997bcSThierry Reding if (!sor->soc->has_nvdisplay) 2635d278e4a9SThierry Reding value |= SOR1_TIMING_CYA; 2636d278e4a9SThierry Reding 2637c57997bcSThierry Reding value |= SOR_ENABLE(sor->index); 2638c57997bcSThierry Reding 2639459cc2c6SThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); 2640459cc2c6SThierry Reding 2641c57997bcSThierry Reding if (dc->soc->has_nvdisplay) { 2642c57997bcSThierry Reding value = tegra_dc_readl(dc, DC_DISP_CORE_SOR_SET_CONTROL(sor->index)); 2643c57997bcSThierry Reding value &= ~PROTOCOL_MASK; 2644c57997bcSThierry Reding value |= PROTOCOL_SINGLE_TMDS_A; 2645c57997bcSThierry Reding tegra_dc_writel(dc, value, DC_DISP_CORE_SOR_SET_CONTROL(sor->index)); 2646c57997bcSThierry Reding } 2647c57997bcSThierry Reding 2648459cc2c6SThierry Reding tegra_dc_commit(dc); 2649459cc2c6SThierry Reding 2650459cc2c6SThierry Reding err = tegra_sor_wakeup(sor); 2651459cc2c6SThierry Reding if (err < 0) 2652459cc2c6SThierry Reding dev_err(sor->dev, "failed to wakeup SOR: %d\n", err); 265336e90221SThierry Reding 265436e90221SThierry Reding tegra_sor_hdmi_scdc_start(sor); 26558e2988a7SThierry Reding tegra_sor_audio_prepare(sor); 2656459cc2c6SThierry Reding } 2657459cc2c6SThierry Reding 2658459cc2c6SThierry Reding static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers = { 2659459cc2c6SThierry Reding .disable = tegra_sor_hdmi_disable, 2660459cc2c6SThierry Reding .enable = tegra_sor_hdmi_enable, 2661459cc2c6SThierry Reding .atomic_check = tegra_sor_encoder_atomic_check, 2662459cc2c6SThierry Reding }; 2663459cc2c6SThierry Reding 26640472c21bSThierry Reding static void tegra_sor_dp_disable(struct drm_encoder *encoder) 26650472c21bSThierry Reding { 26660472c21bSThierry Reding struct tegra_output *output = encoder_to_output(encoder); 26670472c21bSThierry Reding struct tegra_dc *dc = to_tegra_dc(encoder->crtc); 26680472c21bSThierry Reding struct tegra_sor *sor = to_sor(output); 26690472c21bSThierry Reding u32 value; 26700472c21bSThierry Reding int err; 26710472c21bSThierry Reding 2672d278e4a9SThierry Reding if (output->panel) 2673d278e4a9SThierry Reding drm_panel_disable(output->panel); 2674d278e4a9SThierry Reding 267568a2ebb5SThierry Reding /* 267668a2ebb5SThierry Reding * Do not attempt to power down a DP link if we're not connected since 267768a2ebb5SThierry Reding * the AUX transactions would just be timing out. 267868a2ebb5SThierry Reding */ 267968a2ebb5SThierry Reding if (output->connector.status != connector_status_disconnected) { 26800472c21bSThierry Reding err = drm_dp_link_power_down(sor->aux, &sor->link); 26810472c21bSThierry Reding if (err < 0) 268268a2ebb5SThierry Reding dev_err(sor->dev, "failed to power down link: %d\n", 268368a2ebb5SThierry Reding err); 268468a2ebb5SThierry Reding } 26850472c21bSThierry Reding 26860472c21bSThierry Reding err = tegra_sor_detach(sor); 26870472c21bSThierry Reding if (err < 0) 26880472c21bSThierry Reding dev_err(sor->dev, "failed to detach SOR: %d\n", err); 26890472c21bSThierry Reding 26900472c21bSThierry Reding tegra_sor_writel(sor, 0, SOR_STATE1); 26910472c21bSThierry Reding tegra_sor_update(sor); 26920472c21bSThierry Reding 26930472c21bSThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); 26940472c21bSThierry Reding value &= ~SOR_ENABLE(sor->index); 26950472c21bSThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); 26960472c21bSThierry Reding tegra_dc_commit(dc); 26970472c21bSThierry Reding 26980472c21bSThierry Reding value = tegra_sor_readl(sor, SOR_STATE1); 26990472c21bSThierry Reding value &= ~SOR_STATE_ASY_PROTOCOL_MASK; 27000472c21bSThierry Reding value &= ~SOR_STATE_ASY_SUBOWNER_MASK; 27010472c21bSThierry Reding value &= ~SOR_STATE_ASY_OWNER_MASK; 27020472c21bSThierry Reding tegra_sor_writel(sor, value, SOR_STATE1); 27030472c21bSThierry Reding tegra_sor_update(sor); 27040472c21bSThierry Reding 27050472c21bSThierry Reding /* switch to safe parent clock */ 27060472c21bSThierry Reding err = tegra_sor_set_parent_clock(sor, sor->clk_safe); 27070472c21bSThierry Reding if (err < 0) 27080472c21bSThierry Reding dev_err(sor->dev, "failed to set safe clock: %d\n", err); 27090472c21bSThierry Reding 27100472c21bSThierry Reding err = tegra_sor_power_down(sor); 27110472c21bSThierry Reding if (err < 0) 27120472c21bSThierry Reding dev_err(sor->dev, "failed to power down SOR: %d\n", err); 27130472c21bSThierry Reding 27140472c21bSThierry Reding err = tegra_io_pad_power_disable(sor->pad); 27150472c21bSThierry Reding if (err < 0) 27160472c21bSThierry Reding dev_err(sor->dev, "failed to power off I/O pad: %d\n", err); 27170472c21bSThierry Reding 27180472c21bSThierry Reding err = drm_dp_aux_disable(sor->aux); 27190472c21bSThierry Reding if (err < 0) 27200472c21bSThierry Reding dev_err(sor->dev, "failed disable DPAUX: %d\n", err); 27210472c21bSThierry Reding 2722d278e4a9SThierry Reding if (output->panel) 2723d278e4a9SThierry Reding drm_panel_unprepare(output->panel); 2724d278e4a9SThierry Reding 27250472c21bSThierry Reding pm_runtime_put(sor->dev); 27260472c21bSThierry Reding } 27270472c21bSThierry Reding 27280472c21bSThierry Reding static void tegra_sor_dp_enable(struct drm_encoder *encoder) 27290472c21bSThierry Reding { 27300472c21bSThierry Reding struct tegra_output *output = encoder_to_output(encoder); 27310472c21bSThierry Reding struct tegra_dc *dc = to_tegra_dc(encoder->crtc); 27320472c21bSThierry Reding struct tegra_sor *sor = to_sor(output); 27330472c21bSThierry Reding struct tegra_sor_config config; 27340472c21bSThierry Reding struct tegra_sor_state *state; 27350472c21bSThierry Reding struct drm_display_mode *mode; 27360472c21bSThierry Reding struct drm_display_info *info; 27370472c21bSThierry Reding unsigned int i; 27380472c21bSThierry Reding u32 value; 27390472c21bSThierry Reding int err; 27400472c21bSThierry Reding 27410472c21bSThierry Reding state = to_sor_state(output->connector.state); 27420472c21bSThierry Reding mode = &encoder->crtc->state->adjusted_mode; 27430472c21bSThierry Reding info = &output->connector.display_info; 27440472c21bSThierry Reding 27450472c21bSThierry Reding pm_runtime_get_sync(sor->dev); 27460472c21bSThierry Reding 27470472c21bSThierry Reding /* switch to safe parent clock */ 27480472c21bSThierry Reding err = tegra_sor_set_parent_clock(sor, sor->clk_safe); 27490472c21bSThierry Reding if (err < 0) 27500472c21bSThierry Reding dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); 27510472c21bSThierry Reding 27520472c21bSThierry Reding err = tegra_io_pad_power_enable(sor->pad); 27530472c21bSThierry Reding if (err < 0) 27540472c21bSThierry Reding dev_err(sor->dev, "failed to power on LVDS rail: %d\n", err); 27550472c21bSThierry Reding 27560472c21bSThierry Reding usleep_range(20, 100); 27570472c21bSThierry Reding 27580472c21bSThierry Reding err = drm_dp_aux_enable(sor->aux); 27590472c21bSThierry Reding if (err < 0) 27600472c21bSThierry Reding dev_err(sor->dev, "failed to enable DPAUX: %d\n", err); 27610472c21bSThierry Reding 27620472c21bSThierry Reding err = drm_dp_link_probe(sor->aux, &sor->link); 27630472c21bSThierry Reding if (err < 0) 27640472c21bSThierry Reding dev_err(sor->dev, "failed to probe DP link: %d\n", err); 27650472c21bSThierry Reding 2766d278e4a9SThierry Reding tegra_sor_filter_rates(sor); 2767d278e4a9SThierry Reding 27680472c21bSThierry Reding err = drm_dp_link_choose(&sor->link, mode, info); 27690472c21bSThierry Reding if (err < 0) 27700472c21bSThierry Reding dev_err(sor->dev, "failed to choose link: %d\n", err); 27710472c21bSThierry Reding 2772d278e4a9SThierry Reding if (output->panel) 2773d278e4a9SThierry Reding drm_panel_prepare(output->panel); 2774d278e4a9SThierry Reding 27750472c21bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 27760472c21bSThierry Reding value &= ~SOR_PLL2_BANDGAP_POWERDOWN; 27770472c21bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 27780472c21bSThierry Reding 27790472c21bSThierry Reding usleep_range(20, 40); 27800472c21bSThierry Reding 27810472c21bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll3); 27820472c21bSThierry Reding value |= SOR_PLL3_PLL_VDD_MODE_3V3; 27830472c21bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll3); 27840472c21bSThierry Reding 27850472c21bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll0); 27860472c21bSThierry Reding value &= ~(SOR_PLL0_VCOPD | SOR_PLL0_PWR); 27870472c21bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll0); 27880472c21bSThierry Reding 27890472c21bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 27900472c21bSThierry Reding value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; 27910472c21bSThierry Reding value |= SOR_PLL2_SEQ_PLLCAPPD; 27920472c21bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 27930472c21bSThierry Reding 27940472c21bSThierry Reding usleep_range(200, 400); 27950472c21bSThierry Reding 27960472c21bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll2); 27970472c21bSThierry Reding value &= ~SOR_PLL2_POWERDOWN_OVERRIDE; 27980472c21bSThierry Reding value &= ~SOR_PLL2_PORT_POWERDOWN; 27990472c21bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll2); 28000472c21bSThierry Reding 28010472c21bSThierry Reding value = tegra_sor_readl(sor, SOR_CLK_CNTRL); 28020472c21bSThierry Reding value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; 2803d278e4a9SThierry Reding 2804d278e4a9SThierry Reding if (output->panel) 2805d278e4a9SThierry Reding value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK; 2806d278e4a9SThierry Reding else 28070472c21bSThierry Reding value |= SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK; 2808d278e4a9SThierry Reding 28090472c21bSThierry Reding tegra_sor_writel(sor, value, SOR_CLK_CNTRL); 28100472c21bSThierry Reding 28110472c21bSThierry Reding usleep_range(200, 400); 28120472c21bSThierry Reding 28130472c21bSThierry Reding value = tegra_sor_readl(sor, SOR_DP_SPARE0); 28140472c21bSThierry Reding /* XXX not in TRM */ 2815d278e4a9SThierry Reding if (output->panel) 2816d278e4a9SThierry Reding value |= SOR_DP_SPARE_PANEL_INTERNAL; 2817d278e4a9SThierry Reding else 28180472c21bSThierry Reding value &= ~SOR_DP_SPARE_PANEL_INTERNAL; 2819d278e4a9SThierry Reding 28200472c21bSThierry Reding value |= SOR_DP_SPARE_SEQ_ENABLE; 28210472c21bSThierry Reding tegra_sor_writel(sor, value, SOR_DP_SPARE0); 28220472c21bSThierry Reding 28230472c21bSThierry Reding /* XXX not in TRM */ 28240472c21bSThierry Reding tegra_sor_writel(sor, 0, SOR_LVDS); 28250472c21bSThierry Reding 28260472c21bSThierry Reding value = tegra_sor_readl(sor, sor->soc->regs->pll0); 28270472c21bSThierry Reding value &= ~SOR_PLL0_ICHPMP_MASK; 28280472c21bSThierry Reding value &= ~SOR_PLL0_VCOCAP_MASK; 28290472c21bSThierry Reding value |= SOR_PLL0_ICHPMP(0x1); 28300472c21bSThierry Reding value |= SOR_PLL0_VCOCAP(0x3); 28310472c21bSThierry Reding value |= SOR_PLL0_RESISTOR_EXT; 28320472c21bSThierry Reding tegra_sor_writel(sor, value, sor->soc->regs->pll0); 28330472c21bSThierry Reding 28340472c21bSThierry Reding /* XXX not in TRM */ 28350472c21bSThierry Reding for (value = 0, i = 0; i < 5; i++) 28360472c21bSThierry Reding value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) | 28370472c21bSThierry Reding SOR_XBAR_CTRL_LINK1_XSEL(i, i); 28380472c21bSThierry Reding 28390472c21bSThierry Reding tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL); 28400472c21bSThierry Reding tegra_sor_writel(sor, value, SOR_XBAR_CTRL); 28410472c21bSThierry Reding 284261417aaaSThierry Reding /* 284361417aaaSThierry Reding * Switch the pad clock to the DP clock. Note that we cannot actually 284461417aaaSThierry Reding * do this because Tegra186 and later don't support clk_set_parent() 284561417aaaSThierry Reding * on the sorX_pad_clkout clocks. We already do the equivalent above 284661417aaaSThierry Reding * using the DP_CLK_SEL mux of the SOR_CLK_CNTRL register. 284761417aaaSThierry Reding */ 284861417aaaSThierry Reding #if 0 284961417aaaSThierry Reding err = clk_set_parent(sor->clk_pad, sor->clk_parent); 285061417aaaSThierry Reding if (err < 0) { 285161417aaaSThierry Reding dev_err(sor->dev, "failed to select pad parent clock: %d\n", 285261417aaaSThierry Reding err); 285361417aaaSThierry Reding return; 285461417aaaSThierry Reding } 285561417aaaSThierry Reding #endif 285661417aaaSThierry Reding 285761417aaaSThierry Reding /* switch the SOR clock to the pad clock */ 28580472c21bSThierry Reding err = tegra_sor_set_parent_clock(sor, sor->clk_pad); 28590472c21bSThierry Reding if (err < 0) { 286061417aaaSThierry Reding dev_err(sor->dev, "failed to select SOR parent clock: %d\n", 286161417aaaSThierry Reding err); 28620472c21bSThierry Reding return; 28630472c21bSThierry Reding } 28640472c21bSThierry Reding 286561417aaaSThierry Reding /* switch the output clock to the parent pixel clock */ 28660472c21bSThierry Reding err = clk_set_parent(sor->clk, sor->clk_parent); 28670472c21bSThierry Reding if (err < 0) { 286861417aaaSThierry Reding dev_err(sor->dev, "failed to select output parent clock: %d\n", 286961417aaaSThierry Reding err); 28700472c21bSThierry Reding return; 28710472c21bSThierry Reding } 28720472c21bSThierry Reding 28730472c21bSThierry Reding /* use DP-A protocol */ 28740472c21bSThierry Reding value = tegra_sor_readl(sor, SOR_STATE1); 28750472c21bSThierry Reding value &= ~SOR_STATE_ASY_PROTOCOL_MASK; 28760472c21bSThierry Reding value |= SOR_STATE_ASY_PROTOCOL_DP_A; 28770472c21bSThierry Reding tegra_sor_writel(sor, value, SOR_STATE1); 28780472c21bSThierry Reding 28790472c21bSThierry Reding /* enable port */ 28800472c21bSThierry Reding value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); 28810472c21bSThierry Reding value |= SOR_DP_LINKCTL_ENABLE; 28820472c21bSThierry Reding tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); 28830472c21bSThierry Reding 28840472c21bSThierry Reding tegra_sor_dp_term_calibrate(sor); 28850472c21bSThierry Reding 28860472c21bSThierry Reding err = drm_dp_link_train(&sor->link); 28870472c21bSThierry Reding if (err < 0) 28880472c21bSThierry Reding dev_err(sor->dev, "link training failed: %d\n", err); 28890472c21bSThierry Reding else 28900472c21bSThierry Reding dev_dbg(sor->dev, "link training succeeded\n"); 28910472c21bSThierry Reding 28920472c21bSThierry Reding err = drm_dp_link_power_up(sor->aux, &sor->link); 28930472c21bSThierry Reding if (err < 0) 28940472c21bSThierry Reding dev_err(sor->dev, "failed to power up DP link: %d\n", err); 28950472c21bSThierry Reding 28960472c21bSThierry Reding /* compute configuration */ 28970472c21bSThierry Reding memset(&config, 0, sizeof(config)); 28980472c21bSThierry Reding config.bits_per_pixel = state->bpc * 3; 28990472c21bSThierry Reding 29000472c21bSThierry Reding err = tegra_sor_compute_config(sor, mode, &config, &sor->link); 29010472c21bSThierry Reding if (err < 0) 29020472c21bSThierry Reding dev_err(sor->dev, "failed to compute configuration: %d\n", err); 29030472c21bSThierry Reding 29040472c21bSThierry Reding tegra_sor_apply_config(sor, &config); 29050472c21bSThierry Reding tegra_sor_mode_set(sor, mode, state); 2906d278e4a9SThierry Reding 2907d278e4a9SThierry Reding if (output->panel) { 2908d278e4a9SThierry Reding /* CSTM (LVDS, link A/B, upper) */ 2909d278e4a9SThierry Reding value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B | 2910d278e4a9SThierry Reding SOR_CSTM_UPPER; 2911d278e4a9SThierry Reding tegra_sor_writel(sor, value, SOR_CSTM); 2912d278e4a9SThierry Reding 2913d278e4a9SThierry Reding /* PWM setup */ 2914d278e4a9SThierry Reding err = tegra_sor_setup_pwm(sor, 250); 2915d278e4a9SThierry Reding if (err < 0) 2916d278e4a9SThierry Reding dev_err(sor->dev, "failed to setup PWM: %d\n", err); 2917d278e4a9SThierry Reding } 2918d278e4a9SThierry Reding 29190472c21bSThierry Reding tegra_sor_update(sor); 29200472c21bSThierry Reding 29210472c21bSThierry Reding err = tegra_sor_power_up(sor, 250); 29220472c21bSThierry Reding if (err < 0) 29230472c21bSThierry Reding dev_err(sor->dev, "failed to power up SOR: %d\n", err); 29240472c21bSThierry Reding 29250472c21bSThierry Reding /* attach and wake up */ 29260472c21bSThierry Reding err = tegra_sor_attach(sor); 29270472c21bSThierry Reding if (err < 0) 29280472c21bSThierry Reding dev_err(sor->dev, "failed to attach SOR: %d\n", err); 29290472c21bSThierry Reding 29300472c21bSThierry Reding value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); 29310472c21bSThierry Reding value |= SOR_ENABLE(sor->index); 29320472c21bSThierry Reding tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); 29330472c21bSThierry Reding 29340472c21bSThierry Reding tegra_dc_commit(dc); 29350472c21bSThierry Reding 29360472c21bSThierry Reding err = tegra_sor_wakeup(sor); 29370472c21bSThierry Reding if (err < 0) 29380472c21bSThierry Reding dev_err(sor->dev, "failed to wakeup SOR: %d\n", err); 2939d278e4a9SThierry Reding 2940d278e4a9SThierry Reding if (output->panel) 2941d278e4a9SThierry Reding drm_panel_enable(output->panel); 29420472c21bSThierry Reding } 29430472c21bSThierry Reding 29440472c21bSThierry Reding static const struct drm_encoder_helper_funcs tegra_sor_dp_helpers = { 29450472c21bSThierry Reding .disable = tegra_sor_dp_disable, 29460472c21bSThierry Reding .enable = tegra_sor_dp_enable, 29470472c21bSThierry Reding .atomic_check = tegra_sor_encoder_atomic_check, 29480472c21bSThierry Reding }; 29490472c21bSThierry Reding 29501c3cc0dfSThierry Reding static int tegra_sor_hdmi_probe(struct tegra_sor *sor) 29511c3cc0dfSThierry Reding { 29521c3cc0dfSThierry Reding int err; 29531c3cc0dfSThierry Reding 29541c3cc0dfSThierry Reding sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io"); 29551c3cc0dfSThierry Reding if (IS_ERR(sor->avdd_io_supply)) { 29561c3cc0dfSThierry Reding dev_err(sor->dev, "cannot get AVDD I/O supply: %ld\n", 29571c3cc0dfSThierry Reding PTR_ERR(sor->avdd_io_supply)); 29581c3cc0dfSThierry Reding return PTR_ERR(sor->avdd_io_supply); 29591c3cc0dfSThierry Reding } 29601c3cc0dfSThierry Reding 29611c3cc0dfSThierry Reding err = regulator_enable(sor->avdd_io_supply); 29621c3cc0dfSThierry Reding if (err < 0) { 29631c3cc0dfSThierry Reding dev_err(sor->dev, "failed to enable AVDD I/O supply: %d\n", 29641c3cc0dfSThierry Reding err); 29651c3cc0dfSThierry Reding return err; 29661c3cc0dfSThierry Reding } 29671c3cc0dfSThierry Reding 29681c3cc0dfSThierry Reding sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-pll"); 29691c3cc0dfSThierry Reding if (IS_ERR(sor->vdd_pll_supply)) { 29701c3cc0dfSThierry Reding dev_err(sor->dev, "cannot get VDD PLL supply: %ld\n", 29711c3cc0dfSThierry Reding PTR_ERR(sor->vdd_pll_supply)); 29721c3cc0dfSThierry Reding return PTR_ERR(sor->vdd_pll_supply); 29731c3cc0dfSThierry Reding } 29741c3cc0dfSThierry Reding 29751c3cc0dfSThierry Reding err = regulator_enable(sor->vdd_pll_supply); 29761c3cc0dfSThierry Reding if (err < 0) { 29771c3cc0dfSThierry Reding dev_err(sor->dev, "failed to enable VDD PLL supply: %d\n", 29781c3cc0dfSThierry Reding err); 29791c3cc0dfSThierry Reding return err; 29801c3cc0dfSThierry Reding } 29811c3cc0dfSThierry Reding 29821c3cc0dfSThierry Reding sor->hdmi_supply = devm_regulator_get(sor->dev, "hdmi"); 29831c3cc0dfSThierry Reding if (IS_ERR(sor->hdmi_supply)) { 29841c3cc0dfSThierry Reding dev_err(sor->dev, "cannot get HDMI supply: %ld\n", 29851c3cc0dfSThierry Reding PTR_ERR(sor->hdmi_supply)); 29861c3cc0dfSThierry Reding return PTR_ERR(sor->hdmi_supply); 29871c3cc0dfSThierry Reding } 29881c3cc0dfSThierry Reding 29891c3cc0dfSThierry Reding err = regulator_enable(sor->hdmi_supply); 29901c3cc0dfSThierry Reding if (err < 0) { 29911c3cc0dfSThierry Reding dev_err(sor->dev, "failed to enable HDMI supply: %d\n", err); 29921c3cc0dfSThierry Reding return err; 29931c3cc0dfSThierry Reding } 29941c3cc0dfSThierry Reding 29951c3cc0dfSThierry Reding INIT_DELAYED_WORK(&sor->scdc, tegra_sor_hdmi_scdc_work); 29961c3cc0dfSThierry Reding 29971c3cc0dfSThierry Reding return 0; 29981c3cc0dfSThierry Reding } 29991c3cc0dfSThierry Reding 30001c3cc0dfSThierry Reding static int tegra_sor_hdmi_remove(struct tegra_sor *sor) 30011c3cc0dfSThierry Reding { 30021c3cc0dfSThierry Reding regulator_disable(sor->hdmi_supply); 30031c3cc0dfSThierry Reding regulator_disable(sor->vdd_pll_supply); 30041c3cc0dfSThierry Reding regulator_disable(sor->avdd_io_supply); 30051c3cc0dfSThierry Reding 30061c3cc0dfSThierry Reding return 0; 30071c3cc0dfSThierry Reding } 30081c3cc0dfSThierry Reding 30091c3cc0dfSThierry Reding static const struct tegra_sor_ops tegra_sor_hdmi_ops = { 30101c3cc0dfSThierry Reding .name = "HDMI", 30111c3cc0dfSThierry Reding .probe = tegra_sor_hdmi_probe, 30121c3cc0dfSThierry Reding .remove = tegra_sor_hdmi_remove, 301385d0c4b5SThierry Reding .audio_enable = tegra_sor_hdmi_audio_enable, 301485d0c4b5SThierry Reding .audio_disable = tegra_sor_hdmi_audio_disable, 30151c3cc0dfSThierry Reding }; 30161c3cc0dfSThierry Reding 30171c3cc0dfSThierry Reding static int tegra_sor_dp_probe(struct tegra_sor *sor) 30181c3cc0dfSThierry Reding { 30191c3cc0dfSThierry Reding int err; 30201c3cc0dfSThierry Reding 30211c3cc0dfSThierry Reding sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io-hdmi-dp"); 30221c3cc0dfSThierry Reding if (IS_ERR(sor->avdd_io_supply)) 30231c3cc0dfSThierry Reding return PTR_ERR(sor->avdd_io_supply); 30241c3cc0dfSThierry Reding 30251c3cc0dfSThierry Reding err = regulator_enable(sor->avdd_io_supply); 30261c3cc0dfSThierry Reding if (err < 0) 30271c3cc0dfSThierry Reding return err; 30281c3cc0dfSThierry Reding 30291c3cc0dfSThierry Reding sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-hdmi-dp-pll"); 30301c3cc0dfSThierry Reding if (IS_ERR(sor->vdd_pll_supply)) 30311c3cc0dfSThierry Reding return PTR_ERR(sor->vdd_pll_supply); 30321c3cc0dfSThierry Reding 30331c3cc0dfSThierry Reding err = regulator_enable(sor->vdd_pll_supply); 30341c3cc0dfSThierry Reding if (err < 0) 30351c3cc0dfSThierry Reding return err; 30361c3cc0dfSThierry Reding 30371c3cc0dfSThierry Reding return 0; 30381c3cc0dfSThierry Reding } 30391c3cc0dfSThierry Reding 30401c3cc0dfSThierry Reding static int tegra_sor_dp_remove(struct tegra_sor *sor) 30411c3cc0dfSThierry Reding { 30421c3cc0dfSThierry Reding regulator_disable(sor->vdd_pll_supply); 30431c3cc0dfSThierry Reding regulator_disable(sor->avdd_io_supply); 30441c3cc0dfSThierry Reding 30451c3cc0dfSThierry Reding return 0; 30461c3cc0dfSThierry Reding } 30471c3cc0dfSThierry Reding 30481c3cc0dfSThierry Reding static const struct tegra_sor_ops tegra_sor_dp_ops = { 30491c3cc0dfSThierry Reding .name = "DP", 30501c3cc0dfSThierry Reding .probe = tegra_sor_dp_probe, 30511c3cc0dfSThierry Reding .remove = tegra_sor_dp_remove, 30521c3cc0dfSThierry Reding }; 30531c3cc0dfSThierry Reding 30546b6b6042SThierry Reding static int tegra_sor_init(struct host1x_client *client) 30556b6b6042SThierry Reding { 30569910f5c4SThierry Reding struct drm_device *drm = dev_get_drvdata(client->parent); 3057459cc2c6SThierry Reding const struct drm_encoder_helper_funcs *helpers = NULL; 30586b6b6042SThierry Reding struct tegra_sor *sor = host1x_client_to_sor(client); 3059459cc2c6SThierry Reding int connector = DRM_MODE_CONNECTOR_Unknown; 3060459cc2c6SThierry Reding int encoder = DRM_MODE_ENCODER_NONE; 30616b6b6042SThierry Reding int err; 30626b6b6042SThierry Reding 30639542c237SThierry Reding if (!sor->aux) { 30641c3cc0dfSThierry Reding if (sor->ops == &tegra_sor_hdmi_ops) { 3065459cc2c6SThierry Reding connector = DRM_MODE_CONNECTOR_HDMIA; 3066459cc2c6SThierry Reding encoder = DRM_MODE_ENCODER_TMDS; 3067459cc2c6SThierry Reding helpers = &tegra_sor_hdmi_helpers; 3068459cc2c6SThierry Reding } else if (sor->soc->supports_lvds) { 3069459cc2c6SThierry Reding connector = DRM_MODE_CONNECTOR_LVDS; 3070459cc2c6SThierry Reding encoder = DRM_MODE_ENCODER_LVDS; 3071459cc2c6SThierry Reding } 3072459cc2c6SThierry Reding } else { 3073d278e4a9SThierry Reding if (sor->output.panel) { 3074459cc2c6SThierry Reding connector = DRM_MODE_CONNECTOR_eDP; 3075459cc2c6SThierry Reding encoder = DRM_MODE_ENCODER_TMDS; 3076d278e4a9SThierry Reding helpers = &tegra_sor_dp_helpers; 30771c3cc0dfSThierry Reding } else { 3078459cc2c6SThierry Reding connector = DRM_MODE_CONNECTOR_DisplayPort; 3079459cc2c6SThierry Reding encoder = DRM_MODE_ENCODER_TMDS; 30800472c21bSThierry Reding helpers = &tegra_sor_dp_helpers; 3081459cc2c6SThierry Reding } 3082c1763937SThierry Reding 3083c1763937SThierry Reding sor->link.ops = &tegra_sor_dp_link_ops; 3084c1763937SThierry Reding sor->link.aux = sor->aux; 3085459cc2c6SThierry Reding } 30866b6b6042SThierry Reding 30876b6b6042SThierry Reding sor->output.dev = sor->dev; 30886b6b6042SThierry Reding 3089*bb9d681bSAndrzej Pietrasiewicz drm_connector_init_with_ddc(drm, &sor->output.connector, 30906fad8f66SThierry Reding &tegra_sor_connector_funcs, 3091*bb9d681bSAndrzej Pietrasiewicz connector, 3092*bb9d681bSAndrzej Pietrasiewicz sor->output.ddc); 30936fad8f66SThierry Reding drm_connector_helper_add(&sor->output.connector, 30946fad8f66SThierry Reding &tegra_sor_connector_helper_funcs); 30956fad8f66SThierry Reding sor->output.connector.dpms = DRM_MODE_DPMS_OFF; 30966fad8f66SThierry Reding 30976fad8f66SThierry Reding drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs, 309813a3d91fSVille Syrjälä encoder, NULL); 3099459cc2c6SThierry Reding drm_encoder_helper_add(&sor->output.encoder, helpers); 31006fad8f66SThierry Reding 3101cde4c44dSDaniel Vetter drm_connector_attach_encoder(&sor->output.connector, 31026fad8f66SThierry Reding &sor->output.encoder); 31036fad8f66SThierry Reding drm_connector_register(&sor->output.connector); 31046fad8f66SThierry Reding 3105ea130b24SThierry Reding err = tegra_output_init(drm, &sor->output); 3106ea130b24SThierry Reding if (err < 0) { 3107ea130b24SThierry Reding dev_err(client->dev, "failed to initialize output: %d\n", err); 3108ea130b24SThierry Reding return err; 3109ea130b24SThierry Reding } 31106fad8f66SThierry Reding 3111c57997bcSThierry Reding tegra_output_find_possible_crtcs(&sor->output, drm); 31126b6b6042SThierry Reding 31139542c237SThierry Reding if (sor->aux) { 31149542c237SThierry Reding err = drm_dp_aux_attach(sor->aux, &sor->output); 31156b6b6042SThierry Reding if (err < 0) { 31166b6b6042SThierry Reding dev_err(sor->dev, "failed to attach DP: %d\n", err); 31176b6b6042SThierry Reding return err; 31186b6b6042SThierry Reding } 31196b6b6042SThierry Reding } 31206b6b6042SThierry Reding 3121535a65dbSTomeu Vizoso /* 3122535a65dbSTomeu Vizoso * XXX: Remove this reset once proper hand-over from firmware to 3123535a65dbSTomeu Vizoso * kernel is possible. 3124535a65dbSTomeu Vizoso */ 3125f8c79120SJon Hunter if (sor->rst) { 312611c632e1SThierry Reding err = reset_control_acquire(sor->rst); 312711c632e1SThierry Reding if (err < 0) { 312811c632e1SThierry Reding dev_err(sor->dev, "failed to acquire SOR reset: %d\n", 312911c632e1SThierry Reding err); 313011c632e1SThierry Reding return err; 313111c632e1SThierry Reding } 313211c632e1SThierry Reding 3133535a65dbSTomeu Vizoso err = reset_control_assert(sor->rst); 3134535a65dbSTomeu Vizoso if (err < 0) { 3135f8c79120SJon Hunter dev_err(sor->dev, "failed to assert SOR reset: %d\n", 3136f8c79120SJon Hunter err); 3137535a65dbSTomeu Vizoso return err; 3138535a65dbSTomeu Vizoso } 3139f8c79120SJon Hunter } 3140535a65dbSTomeu Vizoso 31416fad8f66SThierry Reding err = clk_prepare_enable(sor->clk); 31426fad8f66SThierry Reding if (err < 0) { 31436fad8f66SThierry Reding dev_err(sor->dev, "failed to enable clock: %d\n", err); 31446fad8f66SThierry Reding return err; 31456fad8f66SThierry Reding } 31466fad8f66SThierry Reding 3147535a65dbSTomeu Vizoso usleep_range(1000, 3000); 3148535a65dbSTomeu Vizoso 3149f8c79120SJon Hunter if (sor->rst) { 3150535a65dbSTomeu Vizoso err = reset_control_deassert(sor->rst); 3151535a65dbSTomeu Vizoso if (err < 0) { 3152f8c79120SJon Hunter dev_err(sor->dev, "failed to deassert SOR reset: %d\n", 3153f8c79120SJon Hunter err); 3154535a65dbSTomeu Vizoso return err; 3155535a65dbSTomeu Vizoso } 315611c632e1SThierry Reding 315711c632e1SThierry Reding reset_control_release(sor->rst); 3158f8c79120SJon Hunter } 3159535a65dbSTomeu Vizoso 31606fad8f66SThierry Reding err = clk_prepare_enable(sor->clk_safe); 31616fad8f66SThierry Reding if (err < 0) 31626fad8f66SThierry Reding return err; 31636fad8f66SThierry Reding 31646fad8f66SThierry Reding err = clk_prepare_enable(sor->clk_dp); 31656fad8f66SThierry Reding if (err < 0) 31666fad8f66SThierry Reding return err; 31676fad8f66SThierry Reding 31686b6b6042SThierry Reding return 0; 31696b6b6042SThierry Reding } 31706b6b6042SThierry Reding 31716b6b6042SThierry Reding static int tegra_sor_exit(struct host1x_client *client) 31726b6b6042SThierry Reding { 31736b6b6042SThierry Reding struct tegra_sor *sor = host1x_client_to_sor(client); 31746b6b6042SThierry Reding int err; 31756b6b6042SThierry Reding 3176328ec69eSThierry Reding tegra_output_exit(&sor->output); 3177328ec69eSThierry Reding 31789542c237SThierry Reding if (sor->aux) { 31799542c237SThierry Reding err = drm_dp_aux_detach(sor->aux); 31806b6b6042SThierry Reding if (err < 0) { 31816b6b6042SThierry Reding dev_err(sor->dev, "failed to detach DP: %d\n", err); 31826b6b6042SThierry Reding return err; 31836b6b6042SThierry Reding } 31846b6b6042SThierry Reding } 31856b6b6042SThierry Reding 31866fad8f66SThierry Reding clk_disable_unprepare(sor->clk_safe); 31876fad8f66SThierry Reding clk_disable_unprepare(sor->clk_dp); 31886fad8f66SThierry Reding clk_disable_unprepare(sor->clk); 31896fad8f66SThierry Reding 31906b6b6042SThierry Reding return 0; 31916b6b6042SThierry Reding } 31926b6b6042SThierry Reding 31936b6b6042SThierry Reding static const struct host1x_client_ops sor_client_ops = { 31946b6b6042SThierry Reding .init = tegra_sor_init, 31956b6b6042SThierry Reding .exit = tegra_sor_exit, 31966b6b6042SThierry Reding }; 31976b6b6042SThierry Reding 319830b49435SThierry Reding static const u8 tegra124_sor_xbar_cfg[5] = { 319930b49435SThierry Reding 0, 1, 2, 3, 4 320030b49435SThierry Reding }; 320130b49435SThierry Reding 3202880cee0bSThierry Reding static const struct tegra_sor_regs tegra124_sor_regs = { 3203880cee0bSThierry Reding .head_state0 = 0x05, 3204880cee0bSThierry Reding .head_state1 = 0x07, 3205880cee0bSThierry Reding .head_state2 = 0x09, 3206880cee0bSThierry Reding .head_state3 = 0x0b, 3207880cee0bSThierry Reding .head_state4 = 0x0d, 3208880cee0bSThierry Reding .head_state5 = 0x0f, 3209880cee0bSThierry Reding .pll0 = 0x17, 3210880cee0bSThierry Reding .pll1 = 0x18, 3211880cee0bSThierry Reding .pll2 = 0x19, 3212880cee0bSThierry Reding .pll3 = 0x1a, 3213880cee0bSThierry Reding .dp_padctl0 = 0x5c, 3214880cee0bSThierry Reding .dp_padctl2 = 0x73, 3215880cee0bSThierry Reding }; 3216880cee0bSThierry Reding 3217c1763937SThierry Reding /* Tegra124 and Tegra132 have lanes 0 and 2 swapped. */ 3218c1763937SThierry Reding static const u8 tegra124_sor_lane_map[4] = { 3219c1763937SThierry Reding 2, 1, 0, 3, 3220c1763937SThierry Reding }; 3221c1763937SThierry Reding 3222c1763937SThierry Reding static const u8 tegra124_sor_voltage_swing[4][4][4] = { 3223c1763937SThierry Reding { 3224c1763937SThierry Reding { 0x13, 0x19, 0x1e, 0x28 }, 3225c1763937SThierry Reding { 0x1e, 0x25, 0x2d, }, 3226c1763937SThierry Reding { 0x28, 0x32, }, 3227c1763937SThierry Reding { 0x3c, }, 3228c1763937SThierry Reding }, { 3229c1763937SThierry Reding { 0x12, 0x17, 0x1b, 0x25 }, 3230c1763937SThierry Reding { 0x1c, 0x23, 0x2a, }, 3231c1763937SThierry Reding { 0x25, 0x2f, }, 3232c1763937SThierry Reding { 0x39, } 3233c1763937SThierry Reding }, { 3234c1763937SThierry Reding { 0x12, 0x16, 0x1a, 0x22 }, 3235c1763937SThierry Reding { 0x1b, 0x20, 0x27, }, 3236c1763937SThierry Reding { 0x24, 0x2d, }, 3237c1763937SThierry Reding { 0x36, }, 3238c1763937SThierry Reding }, { 3239c1763937SThierry Reding { 0x11, 0x14, 0x17, 0x1f }, 3240c1763937SThierry Reding { 0x19, 0x1e, 0x24, }, 3241c1763937SThierry Reding { 0x22, 0x2a, }, 3242c1763937SThierry Reding { 0x32, }, 3243c1763937SThierry Reding }, 3244c1763937SThierry Reding }; 3245c1763937SThierry Reding 3246c1763937SThierry Reding static const u8 tegra124_sor_pre_emphasis[4][4][4] = { 3247c1763937SThierry Reding { 3248c1763937SThierry Reding { 0x00, 0x09, 0x13, 0x25 }, 3249c1763937SThierry Reding { 0x00, 0x0f, 0x1e, }, 3250c1763937SThierry Reding { 0x00, 0x14, }, 3251c1763937SThierry Reding { 0x00, }, 3252c1763937SThierry Reding }, { 3253c1763937SThierry Reding { 0x00, 0x0a, 0x14, 0x28 }, 3254c1763937SThierry Reding { 0x00, 0x0f, 0x1e, }, 3255c1763937SThierry Reding { 0x00, 0x14, }, 3256c1763937SThierry Reding { 0x00 }, 3257c1763937SThierry Reding }, { 3258c1763937SThierry Reding { 0x00, 0x0a, 0x14, 0x28 }, 3259c1763937SThierry Reding { 0x00, 0x0f, 0x1e, }, 3260c1763937SThierry Reding { 0x00, 0x14, }, 3261c1763937SThierry Reding { 0x00, }, 3262c1763937SThierry Reding }, { 3263c1763937SThierry Reding { 0x00, 0x0a, 0x14, 0x28 }, 3264c1763937SThierry Reding { 0x00, 0x0f, 0x1e, }, 3265c1763937SThierry Reding { 0x00, 0x14, }, 3266c1763937SThierry Reding { 0x00, }, 3267c1763937SThierry Reding }, 3268c1763937SThierry Reding }; 3269c1763937SThierry Reding 3270c1763937SThierry Reding static const u8 tegra124_sor_post_cursor[4][4][4] = { 3271c1763937SThierry Reding { 3272c1763937SThierry Reding { 0x00, 0x00, 0x00, 0x00 }, 3273c1763937SThierry Reding { 0x00, 0x00, 0x00, }, 3274c1763937SThierry Reding { 0x00, 0x00, }, 3275c1763937SThierry Reding { 0x00, }, 3276c1763937SThierry Reding }, { 3277c1763937SThierry Reding { 0x02, 0x02, 0x04, 0x05 }, 3278c1763937SThierry Reding { 0x02, 0x04, 0x05, }, 3279c1763937SThierry Reding { 0x04, 0x05, }, 3280c1763937SThierry Reding { 0x05, }, 3281c1763937SThierry Reding }, { 3282c1763937SThierry Reding { 0x04, 0x05, 0x08, 0x0b }, 3283c1763937SThierry Reding { 0x05, 0x09, 0x0b, }, 3284c1763937SThierry Reding { 0x08, 0x0a, }, 3285c1763937SThierry Reding { 0x0b, }, 3286c1763937SThierry Reding }, { 3287c1763937SThierry Reding { 0x05, 0x09, 0x0b, 0x12 }, 3288c1763937SThierry Reding { 0x09, 0x0d, 0x12, }, 3289c1763937SThierry Reding { 0x0b, 0x0f, }, 3290c1763937SThierry Reding { 0x12, }, 3291c1763937SThierry Reding }, 3292c1763937SThierry Reding }; 3293c1763937SThierry Reding 3294c1763937SThierry Reding static const u8 tegra124_sor_tx_pu[4][4][4] = { 3295c1763937SThierry Reding { 3296c1763937SThierry Reding { 0x20, 0x30, 0x40, 0x60 }, 3297c1763937SThierry Reding { 0x30, 0x40, 0x60, }, 3298c1763937SThierry Reding { 0x40, 0x60, }, 3299c1763937SThierry Reding { 0x60, }, 3300c1763937SThierry Reding }, { 3301c1763937SThierry Reding { 0x20, 0x20, 0x30, 0x50 }, 3302c1763937SThierry Reding { 0x30, 0x40, 0x50, }, 3303c1763937SThierry Reding { 0x40, 0x50, }, 3304c1763937SThierry Reding { 0x60, }, 3305c1763937SThierry Reding }, { 3306c1763937SThierry Reding { 0x20, 0x20, 0x30, 0x40, }, 3307c1763937SThierry Reding { 0x30, 0x30, 0x40, }, 3308c1763937SThierry Reding { 0x40, 0x50, }, 3309c1763937SThierry Reding { 0x60, }, 3310c1763937SThierry Reding }, { 3311c1763937SThierry Reding { 0x20, 0x20, 0x20, 0x40, }, 3312c1763937SThierry Reding { 0x30, 0x30, 0x40, }, 3313c1763937SThierry Reding { 0x40, 0x40, }, 3314c1763937SThierry Reding { 0x60, }, 3315c1763937SThierry Reding }, 3316c1763937SThierry Reding }; 3317c1763937SThierry Reding 3318459cc2c6SThierry Reding static const struct tegra_sor_soc tegra124_sor = { 3319459cc2c6SThierry Reding .supports_lvds = true, 3320459cc2c6SThierry Reding .supports_hdmi = false, 3321d278e4a9SThierry Reding .supports_dp = true, 3322d278e4a9SThierry Reding .supports_audio = false, 3323d278e4a9SThierry Reding .supports_hdcp = false, 3324880cee0bSThierry Reding .regs = &tegra124_sor_regs, 3325c57997bcSThierry Reding .has_nvdisplay = false, 332630b49435SThierry Reding .xbar_cfg = tegra124_sor_xbar_cfg, 3327c1763937SThierry Reding .lane_map = tegra124_sor_lane_map, 3328c1763937SThierry Reding .voltage_swing = tegra124_sor_voltage_swing, 3329c1763937SThierry Reding .pre_emphasis = tegra124_sor_pre_emphasis, 3330c1763937SThierry Reding .post_cursor = tegra124_sor_post_cursor, 3331c1763937SThierry Reding .tx_pu = tegra124_sor_tx_pu, 3332c1763937SThierry Reding }; 3333c1763937SThierry Reding 3334c1763937SThierry Reding static const u8 tegra132_sor_pre_emphasis[4][4][4] = { 3335c1763937SThierry Reding { 3336c1763937SThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 3337c1763937SThierry Reding { 0x01, 0x0e, 0x1d, }, 3338c1763937SThierry Reding { 0x01, 0x13, }, 3339c1763937SThierry Reding { 0x00, }, 3340c1763937SThierry Reding }, { 3341c1763937SThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 3342c1763937SThierry Reding { 0x00, 0x0e, 0x1d, }, 3343c1763937SThierry Reding { 0x00, 0x13, }, 3344c1763937SThierry Reding { 0x00 }, 3345c1763937SThierry Reding }, { 3346c1763937SThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 3347c1763937SThierry Reding { 0x00, 0x0e, 0x1d, }, 3348c1763937SThierry Reding { 0x00, 0x13, }, 3349c1763937SThierry Reding { 0x00, }, 3350c1763937SThierry Reding }, { 3351c1763937SThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 3352c1763937SThierry Reding { 0x00, 0x0e, 0x1d, }, 3353c1763937SThierry Reding { 0x00, 0x13, }, 3354c1763937SThierry Reding { 0x00, }, 3355c1763937SThierry Reding }, 3356c1763937SThierry Reding }; 3357c1763937SThierry Reding 3358c1763937SThierry Reding static const struct tegra_sor_soc tegra132_sor = { 3359c1763937SThierry Reding .supports_lvds = true, 3360c1763937SThierry Reding .supports_hdmi = false, 3361d278e4a9SThierry Reding .supports_dp = true, 3362d278e4a9SThierry Reding .supports_audio = false, 3363d278e4a9SThierry Reding .supports_hdcp = false, 3364c1763937SThierry Reding .regs = &tegra124_sor_regs, 3365c1763937SThierry Reding .has_nvdisplay = false, 3366c1763937SThierry Reding .xbar_cfg = tegra124_sor_xbar_cfg, 3367c1763937SThierry Reding .lane_map = tegra124_sor_lane_map, 3368c1763937SThierry Reding .voltage_swing = tegra124_sor_voltage_swing, 3369c1763937SThierry Reding .pre_emphasis = tegra132_sor_pre_emphasis, 3370c1763937SThierry Reding .post_cursor = tegra124_sor_post_cursor, 3371c1763937SThierry Reding .tx_pu = tegra124_sor_tx_pu, 3372459cc2c6SThierry Reding }; 3373459cc2c6SThierry Reding 3374880cee0bSThierry Reding static const struct tegra_sor_regs tegra210_sor_regs = { 3375880cee0bSThierry Reding .head_state0 = 0x05, 3376880cee0bSThierry Reding .head_state1 = 0x07, 3377880cee0bSThierry Reding .head_state2 = 0x09, 3378880cee0bSThierry Reding .head_state3 = 0x0b, 3379880cee0bSThierry Reding .head_state4 = 0x0d, 3380880cee0bSThierry Reding .head_state5 = 0x0f, 3381880cee0bSThierry Reding .pll0 = 0x17, 3382880cee0bSThierry Reding .pll1 = 0x18, 3383880cee0bSThierry Reding .pll2 = 0x19, 3384880cee0bSThierry Reding .pll3 = 0x1a, 3385880cee0bSThierry Reding .dp_padctl0 = 0x5c, 3386880cee0bSThierry Reding .dp_padctl2 = 0x73, 3387880cee0bSThierry Reding }; 3388880cee0bSThierry Reding 3389c1763937SThierry Reding static const u8 tegra210_sor_xbar_cfg[5] = { 3390c1763937SThierry Reding 2, 1, 0, 3, 4 3391c1763937SThierry Reding }; 3392c1763937SThierry Reding 33930472c21bSThierry Reding static const u8 tegra210_sor_lane_map[4] = { 33940472c21bSThierry Reding 0, 1, 2, 3, 33950472c21bSThierry Reding }; 33960472c21bSThierry Reding 3397459cc2c6SThierry Reding static const struct tegra_sor_soc tegra210_sor = { 3398459cc2c6SThierry Reding .supports_lvds = false, 3399459cc2c6SThierry Reding .supports_hdmi = false, 3400d278e4a9SThierry Reding .supports_dp = true, 3401d278e4a9SThierry Reding .supports_audio = false, 3402d278e4a9SThierry Reding .supports_hdcp = false, 3403c1763937SThierry Reding 3404880cee0bSThierry Reding .regs = &tegra210_sor_regs, 3405c57997bcSThierry Reding .has_nvdisplay = false, 340630b49435SThierry Reding 3407c1763937SThierry Reding .xbar_cfg = tegra210_sor_xbar_cfg, 34080472c21bSThierry Reding .lane_map = tegra210_sor_lane_map, 34090472c21bSThierry Reding .voltage_swing = tegra124_sor_voltage_swing, 34100472c21bSThierry Reding .pre_emphasis = tegra124_sor_pre_emphasis, 34110472c21bSThierry Reding .post_cursor = tegra124_sor_post_cursor, 34120472c21bSThierry Reding .tx_pu = tegra124_sor_tx_pu, 3413459cc2c6SThierry Reding }; 3414459cc2c6SThierry Reding 3415459cc2c6SThierry Reding static const struct tegra_sor_soc tegra210_sor1 = { 3416459cc2c6SThierry Reding .supports_lvds = false, 3417459cc2c6SThierry Reding .supports_hdmi = true, 3418459cc2c6SThierry Reding .supports_dp = true, 3419d278e4a9SThierry Reding .supports_audio = true, 3420d278e4a9SThierry Reding .supports_hdcp = true, 3421459cc2c6SThierry Reding 3422880cee0bSThierry Reding .regs = &tegra210_sor_regs, 3423c57997bcSThierry Reding .has_nvdisplay = false, 3424880cee0bSThierry Reding 3425459cc2c6SThierry Reding .num_settings = ARRAY_SIZE(tegra210_sor_hdmi_defaults), 3426459cc2c6SThierry Reding .settings = tegra210_sor_hdmi_defaults, 342730b49435SThierry Reding .xbar_cfg = tegra210_sor_xbar_cfg, 34280472c21bSThierry Reding .lane_map = tegra210_sor_lane_map, 34290472c21bSThierry Reding .voltage_swing = tegra124_sor_voltage_swing, 34300472c21bSThierry Reding .pre_emphasis = tegra124_sor_pre_emphasis, 34310472c21bSThierry Reding .post_cursor = tegra124_sor_post_cursor, 34320472c21bSThierry Reding .tx_pu = tegra124_sor_tx_pu, 3433459cc2c6SThierry Reding }; 3434459cc2c6SThierry Reding 3435c57997bcSThierry Reding static const struct tegra_sor_regs tegra186_sor_regs = { 3436c57997bcSThierry Reding .head_state0 = 0x151, 3437c57997bcSThierry Reding .head_state1 = 0x154, 3438c57997bcSThierry Reding .head_state2 = 0x157, 3439c57997bcSThierry Reding .head_state3 = 0x15a, 3440c57997bcSThierry Reding .head_state4 = 0x15d, 3441c57997bcSThierry Reding .head_state5 = 0x160, 3442c57997bcSThierry Reding .pll0 = 0x163, 3443c57997bcSThierry Reding .pll1 = 0x164, 3444c57997bcSThierry Reding .pll2 = 0x165, 3445c57997bcSThierry Reding .pll3 = 0x166, 3446c57997bcSThierry Reding .dp_padctl0 = 0x168, 3447c57997bcSThierry Reding .dp_padctl2 = 0x16a, 3448c57997bcSThierry Reding }; 3449c57997bcSThierry Reding 34500472c21bSThierry Reding static const u8 tegra186_sor_voltage_swing[4][4][4] = { 34510472c21bSThierry Reding { 34520472c21bSThierry Reding { 0x13, 0x19, 0x1e, 0x28 }, 34530472c21bSThierry Reding { 0x1e, 0x25, 0x2d, }, 34540472c21bSThierry Reding { 0x28, 0x32, }, 34550472c21bSThierry Reding { 0x39, }, 34560472c21bSThierry Reding }, { 34570472c21bSThierry Reding { 0x12, 0x16, 0x1b, 0x25 }, 34580472c21bSThierry Reding { 0x1c, 0x23, 0x2a, }, 34590472c21bSThierry Reding { 0x25, 0x2f, }, 34600472c21bSThierry Reding { 0x37, } 34610472c21bSThierry Reding }, { 34620472c21bSThierry Reding { 0x12, 0x16, 0x1a, 0x22 }, 34630472c21bSThierry Reding { 0x1b, 0x20, 0x27, }, 34640472c21bSThierry Reding { 0x24, 0x2d, }, 34650472c21bSThierry Reding { 0x35, }, 34660472c21bSThierry Reding }, { 34670472c21bSThierry Reding { 0x11, 0x14, 0x17, 0x1f }, 34680472c21bSThierry Reding { 0x19, 0x1e, 0x24, }, 34690472c21bSThierry Reding { 0x22, 0x2a, }, 34700472c21bSThierry Reding { 0x32, }, 34710472c21bSThierry Reding }, 34720472c21bSThierry Reding }; 34730472c21bSThierry Reding 34740472c21bSThierry Reding static const u8 tegra186_sor_pre_emphasis[4][4][4] = { 34750472c21bSThierry Reding { 34760472c21bSThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 34770472c21bSThierry Reding { 0x01, 0x0e, 0x1d, }, 34780472c21bSThierry Reding { 0x01, 0x13, }, 34790472c21bSThierry Reding { 0x00, }, 34800472c21bSThierry Reding }, { 34810472c21bSThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 34820472c21bSThierry Reding { 0x00, 0x0e, 0x1d, }, 34830472c21bSThierry Reding { 0x00, 0x13, }, 34840472c21bSThierry Reding { 0x00 }, 34850472c21bSThierry Reding }, { 34860472c21bSThierry Reding { 0x00, 0x08, 0x14, 0x24 }, 34870472c21bSThierry Reding { 0x00, 0x0e, 0x1d, }, 34880472c21bSThierry Reding { 0x00, 0x13, }, 34890472c21bSThierry Reding { 0x00, }, 34900472c21bSThierry Reding }, { 34910472c21bSThierry Reding { 0x00, 0x08, 0x12, 0x24 }, 34920472c21bSThierry Reding { 0x00, 0x0e, 0x1d, }, 34930472c21bSThierry Reding { 0x00, 0x13, }, 34940472c21bSThierry Reding { 0x00, }, 34950472c21bSThierry Reding }, 34960472c21bSThierry Reding }; 34970472c21bSThierry Reding 3498c57997bcSThierry Reding static const struct tegra_sor_soc tegra186_sor = { 3499c57997bcSThierry Reding .supports_lvds = false, 3500c57997bcSThierry Reding .supports_hdmi = true, 3501c57997bcSThierry Reding .supports_dp = true, 3502d278e4a9SThierry Reding .supports_audio = true, 3503d278e4a9SThierry Reding .supports_hdcp = true, 3504c57997bcSThierry Reding 3505c57997bcSThierry Reding .regs = &tegra186_sor_regs, 3506c57997bcSThierry Reding .has_nvdisplay = true, 3507c57997bcSThierry Reding 3508c57997bcSThierry Reding .num_settings = ARRAY_SIZE(tegra186_sor_hdmi_defaults), 3509c57997bcSThierry Reding .settings = tegra186_sor_hdmi_defaults, 3510c57997bcSThierry Reding .xbar_cfg = tegra124_sor_xbar_cfg, 35110472c21bSThierry Reding .lane_map = tegra124_sor_lane_map, 35120472c21bSThierry Reding .voltage_swing = tegra186_sor_voltage_swing, 35130472c21bSThierry Reding .pre_emphasis = tegra186_sor_pre_emphasis, 35140472c21bSThierry Reding .post_cursor = tegra124_sor_post_cursor, 35150472c21bSThierry Reding .tx_pu = tegra124_sor_tx_pu, 3516c57997bcSThierry Reding }; 3517c57997bcSThierry Reding 35189b6c14b8SThierry Reding static const struct tegra_sor_regs tegra194_sor_regs = { 35199b6c14b8SThierry Reding .head_state0 = 0x151, 35209b6c14b8SThierry Reding .head_state1 = 0x155, 35219b6c14b8SThierry Reding .head_state2 = 0x159, 35229b6c14b8SThierry Reding .head_state3 = 0x15d, 35239b6c14b8SThierry Reding .head_state4 = 0x161, 35249b6c14b8SThierry Reding .head_state5 = 0x165, 35259b6c14b8SThierry Reding .pll0 = 0x169, 35269b6c14b8SThierry Reding .pll1 = 0x16a, 35279b6c14b8SThierry Reding .pll2 = 0x16b, 35289b6c14b8SThierry Reding .pll3 = 0x16c, 35299b6c14b8SThierry Reding .dp_padctl0 = 0x16e, 35309b6c14b8SThierry Reding .dp_padctl2 = 0x16f, 35319b6c14b8SThierry Reding }; 35329b6c14b8SThierry Reding 35339b6c14b8SThierry Reding static const struct tegra_sor_soc tegra194_sor = { 35349b6c14b8SThierry Reding .supports_lvds = false, 35359b6c14b8SThierry Reding .supports_hdmi = true, 35369b6c14b8SThierry Reding .supports_dp = true, 3537d278e4a9SThierry Reding .supports_audio = true, 3538d278e4a9SThierry Reding .supports_hdcp = true, 35399b6c14b8SThierry Reding 35409b6c14b8SThierry Reding .regs = &tegra194_sor_regs, 35419b6c14b8SThierry Reding .has_nvdisplay = true, 35429b6c14b8SThierry Reding 35439b6c14b8SThierry Reding .num_settings = ARRAY_SIZE(tegra194_sor_hdmi_defaults), 35449b6c14b8SThierry Reding .settings = tegra194_sor_hdmi_defaults, 35459b6c14b8SThierry Reding 35469b6c14b8SThierry Reding .xbar_cfg = tegra210_sor_xbar_cfg, 3547bae88815SThierry Reding .lane_map = tegra124_sor_lane_map, 3548bae88815SThierry Reding .voltage_swing = tegra186_sor_voltage_swing, 3549bae88815SThierry Reding .pre_emphasis = tegra186_sor_pre_emphasis, 3550bae88815SThierry Reding .post_cursor = tegra124_sor_post_cursor, 3551bae88815SThierry Reding .tx_pu = tegra124_sor_tx_pu, 35529b6c14b8SThierry Reding }; 35539b6c14b8SThierry Reding 3554459cc2c6SThierry Reding static const struct of_device_id tegra_sor_of_match[] = { 35559b6c14b8SThierry Reding { .compatible = "nvidia,tegra194-sor", .data = &tegra194_sor }, 3556c57997bcSThierry Reding { .compatible = "nvidia,tegra186-sor", .data = &tegra186_sor }, 3557459cc2c6SThierry Reding { .compatible = "nvidia,tegra210-sor1", .data = &tegra210_sor1 }, 3558459cc2c6SThierry Reding { .compatible = "nvidia,tegra210-sor", .data = &tegra210_sor }, 3559c1763937SThierry Reding { .compatible = "nvidia,tegra132-sor", .data = &tegra132_sor }, 3560459cc2c6SThierry Reding { .compatible = "nvidia,tegra124-sor", .data = &tegra124_sor }, 3561459cc2c6SThierry Reding { }, 3562459cc2c6SThierry Reding }; 3563459cc2c6SThierry Reding MODULE_DEVICE_TABLE(of, tegra_sor_of_match); 3564459cc2c6SThierry Reding 3565c57997bcSThierry Reding static int tegra_sor_parse_dt(struct tegra_sor *sor) 3566c57997bcSThierry Reding { 3567c57997bcSThierry Reding struct device_node *np = sor->dev->of_node; 35686d6c815dSThierry Reding u32 xbar_cfg[5]; 35696d6c815dSThierry Reding unsigned int i; 3570c57997bcSThierry Reding u32 value; 3571c57997bcSThierry Reding int err; 3572c57997bcSThierry Reding 3573c57997bcSThierry Reding if (sor->soc->has_nvdisplay) { 3574c57997bcSThierry Reding err = of_property_read_u32(np, "nvidia,interface", &value); 3575c57997bcSThierry Reding if (err < 0) 3576c57997bcSThierry Reding return err; 3577c57997bcSThierry Reding 3578c57997bcSThierry Reding sor->index = value; 3579c57997bcSThierry Reding 3580c57997bcSThierry Reding /* 3581c57997bcSThierry Reding * override the default that we already set for Tegra210 and 3582c57997bcSThierry Reding * earlier 3583c57997bcSThierry Reding */ 3584c57997bcSThierry Reding sor->pad = TEGRA_IO_PAD_HDMI_DP0 + sor->index; 358524e64f86SThierry Reding } else { 3586d278e4a9SThierry Reding if (!sor->soc->supports_audio) 358724e64f86SThierry Reding sor->index = 0; 358824e64f86SThierry Reding else 358924e64f86SThierry Reding sor->index = 1; 3590c57997bcSThierry Reding } 3591c57997bcSThierry Reding 35926d6c815dSThierry Reding err = of_property_read_u32_array(np, "nvidia,xbar-cfg", xbar_cfg, 5); 35936d6c815dSThierry Reding if (err < 0) { 35946d6c815dSThierry Reding /* fall back to default per-SoC XBAR configuration */ 35956d6c815dSThierry Reding for (i = 0; i < 5; i++) 35966d6c815dSThierry Reding sor->xbar_cfg[i] = sor->soc->xbar_cfg[i]; 35976d6c815dSThierry Reding } else { 35986d6c815dSThierry Reding /* copy cells to SOR XBAR configuration */ 35996d6c815dSThierry Reding for (i = 0; i < 5; i++) 36006d6c815dSThierry Reding sor->xbar_cfg[i] = xbar_cfg[i]; 3601c57997bcSThierry Reding } 3602c57997bcSThierry Reding 36036b6b6042SThierry Reding return 0; 36048e2988a7SThierry Reding } 36058e2988a7SThierry Reding 36068e2988a7SThierry Reding static irqreturn_t tegra_sor_irq(int irq, void *data) 36078e2988a7SThierry Reding { 36088e2988a7SThierry Reding struct tegra_sor *sor = data; 36098e2988a7SThierry Reding u32 value; 36108e2988a7SThierry Reding 36118e2988a7SThierry Reding value = tegra_sor_readl(sor, SOR_INT_STATUS); 36128e2988a7SThierry Reding tegra_sor_writel(sor, value, SOR_INT_STATUS); 36138e2988a7SThierry Reding 36148e2988a7SThierry Reding if (value & SOR_INT_CODEC_SCRATCH0) { 36158e2988a7SThierry Reding value = tegra_sor_readl(sor, SOR_AUDIO_HDA_CODEC_SCRATCH0); 36168e2988a7SThierry Reding 36178e2988a7SThierry Reding if (value & SOR_AUDIO_HDA_CODEC_SCRATCH0_VALID) { 3618cd54fb96SThierry Reding unsigned int format; 36198e2988a7SThierry Reding 36208e2988a7SThierry Reding format = value & SOR_AUDIO_HDA_CODEC_SCRATCH0_FMT_MASK; 36218e2988a7SThierry Reding 3622fad7b806SThierry Reding tegra_hda_parse_format(format, &sor->format); 36238e2988a7SThierry Reding 362485d0c4b5SThierry Reding if (sor->ops->audio_enable) 362585d0c4b5SThierry Reding sor->ops->audio_enable(sor); 36268e2988a7SThierry Reding } else { 362785d0c4b5SThierry Reding if (sor->ops->audio_disable) 362885d0c4b5SThierry Reding sor->ops->audio_disable(sor); 36298e2988a7SThierry Reding } 36308e2988a7SThierry Reding } 36318e2988a7SThierry Reding 36328e2988a7SThierry Reding return IRQ_HANDLED; 36338e2988a7SThierry Reding } 36348e2988a7SThierry Reding 36356b6b6042SThierry Reding static int tegra_sor_probe(struct platform_device *pdev) 36366b6b6042SThierry Reding { 36376b6b6042SThierry Reding struct device_node *np; 36386b6b6042SThierry Reding struct tegra_sor *sor; 36396b6b6042SThierry Reding struct resource *regs; 36406b6b6042SThierry Reding int err; 36416b6b6042SThierry Reding 36426b6b6042SThierry Reding sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL); 36436b6b6042SThierry Reding if (!sor) 36446b6b6042SThierry Reding return -ENOMEM; 36456b6b6042SThierry Reding 36465faea3d0SThierry Reding sor->soc = of_device_get_match_data(&pdev->dev); 36476b6b6042SThierry Reding sor->output.dev = sor->dev = &pdev->dev; 3648459cc2c6SThierry Reding 3649459cc2c6SThierry Reding sor->settings = devm_kmemdup(&pdev->dev, sor->soc->settings, 3650459cc2c6SThierry Reding sor->soc->num_settings * 3651459cc2c6SThierry Reding sizeof(*sor->settings), 3652459cc2c6SThierry Reding GFP_KERNEL); 3653459cc2c6SThierry Reding if (!sor->settings) 3654459cc2c6SThierry Reding return -ENOMEM; 3655459cc2c6SThierry Reding 3656459cc2c6SThierry Reding sor->num_settings = sor->soc->num_settings; 36576b6b6042SThierry Reding 36586b6b6042SThierry Reding np = of_parse_phandle(pdev->dev.of_node, "nvidia,dpaux", 0); 36596b6b6042SThierry Reding if (np) { 36609542c237SThierry Reding sor->aux = drm_dp_aux_find_by_of_node(np); 36616b6b6042SThierry Reding of_node_put(np); 36626b6b6042SThierry Reding 36639542c237SThierry Reding if (!sor->aux) 36646b6b6042SThierry Reding return -EPROBE_DEFER; 36656f684de5SThierry Reding 36666f684de5SThierry Reding sor->output.ddc = &sor->aux->ddc; 36676b6b6042SThierry Reding } 36686b6b6042SThierry Reding 36699542c237SThierry Reding if (!sor->aux) { 3670459cc2c6SThierry Reding if (sor->soc->supports_hdmi) { 3671459cc2c6SThierry Reding sor->ops = &tegra_sor_hdmi_ops; 3672c57997bcSThierry Reding sor->pad = TEGRA_IO_PAD_HDMI; 3673459cc2c6SThierry Reding } else if (sor->soc->supports_lvds) { 3674459cc2c6SThierry Reding dev_err(&pdev->dev, "LVDS not supported yet\n"); 3675459cc2c6SThierry Reding return -ENODEV; 3676459cc2c6SThierry Reding } else { 3677459cc2c6SThierry Reding dev_err(&pdev->dev, "unknown (non-DP) support\n"); 3678459cc2c6SThierry Reding return -ENODEV; 3679459cc2c6SThierry Reding } 3680459cc2c6SThierry Reding } else { 3681d278e4a9SThierry Reding np = of_parse_phandle(pdev->dev.of_node, "nvidia,panel", 0); 3682d278e4a9SThierry Reding /* 3683d278e4a9SThierry Reding * No need to keep this around since we only use it as a check 3684d278e4a9SThierry Reding * to see if a panel is connected (eDP) or not (DP). 3685d278e4a9SThierry Reding */ 3686d278e4a9SThierry Reding of_node_put(np); 3687d278e4a9SThierry Reding 36880472c21bSThierry Reding sor->ops = &tegra_sor_dp_ops; 3689d23691f6SThierry Reding sor->pad = TEGRA_IO_PAD_LVDS; 3690459cc2c6SThierry Reding } 3691459cc2c6SThierry Reding 3692c57997bcSThierry Reding err = tegra_sor_parse_dt(sor); 3693c57997bcSThierry Reding if (err < 0) 3694c57997bcSThierry Reding return err; 3695c57997bcSThierry Reding 36966b6b6042SThierry Reding err = tegra_output_probe(&sor->output); 36974dbdc740SThierry Reding if (err < 0) { 36984dbdc740SThierry Reding dev_err(&pdev->dev, "failed to probe output: %d\n", err); 36996b6b6042SThierry Reding return err; 37004dbdc740SThierry Reding } 37016b6b6042SThierry Reding 3702459cc2c6SThierry Reding if (sor->ops && sor->ops->probe) { 3703459cc2c6SThierry Reding err = sor->ops->probe(sor); 3704459cc2c6SThierry Reding if (err < 0) { 3705459cc2c6SThierry Reding dev_err(&pdev->dev, "failed to probe %s: %d\n", 3706459cc2c6SThierry Reding sor->ops->name, err); 3707459cc2c6SThierry Reding goto output; 3708459cc2c6SThierry Reding } 3709459cc2c6SThierry Reding } 3710459cc2c6SThierry Reding 37116b6b6042SThierry Reding regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 37126b6b6042SThierry Reding sor->regs = devm_ioremap_resource(&pdev->dev, regs); 3713459cc2c6SThierry Reding if (IS_ERR(sor->regs)) { 3714459cc2c6SThierry Reding err = PTR_ERR(sor->regs); 3715459cc2c6SThierry Reding goto remove; 3716459cc2c6SThierry Reding } 37176b6b6042SThierry Reding 37188e2988a7SThierry Reding err = platform_get_irq(pdev, 0); 37198e2988a7SThierry Reding if (err < 0) { 37208e2988a7SThierry Reding dev_err(&pdev->dev, "failed to get IRQ: %d\n", err); 37218e2988a7SThierry Reding goto remove; 37228e2988a7SThierry Reding } 37238e2988a7SThierry Reding 37248e2988a7SThierry Reding sor->irq = err; 37258e2988a7SThierry Reding 37268e2988a7SThierry Reding err = devm_request_irq(sor->dev, sor->irq, tegra_sor_irq, 0, 37278e2988a7SThierry Reding dev_name(sor->dev), sor); 37288e2988a7SThierry Reding if (err < 0) { 37298e2988a7SThierry Reding dev_err(&pdev->dev, "failed to request IRQ: %d\n", err); 37308e2988a7SThierry Reding goto remove; 37318e2988a7SThierry Reding } 37328e2988a7SThierry Reding 373311c632e1SThierry Reding sor->rst = devm_reset_control_get_exclusive_released(&pdev->dev, "sor"); 37344dbdc740SThierry Reding if (IS_ERR(sor->rst)) { 3735459cc2c6SThierry Reding err = PTR_ERR(sor->rst); 3736180b46ecSThierry Reding 3737180b46ecSThierry Reding if (err != -EBUSY || WARN_ON(!pdev->dev.pm_domain)) { 3738f8c79120SJon Hunter dev_err(&pdev->dev, "failed to get reset control: %d\n", 3739f8c79120SJon Hunter err); 3740459cc2c6SThierry Reding goto remove; 37414dbdc740SThierry Reding } 3742180b46ecSThierry Reding 3743180b46ecSThierry Reding /* 3744180b46ecSThierry Reding * At this point, the reset control is most likely being used 3745180b46ecSThierry Reding * by the generic power domain implementation. With any luck 3746180b46ecSThierry Reding * the power domain will have taken care of resetting the SOR 3747180b46ecSThierry Reding * and we don't have to do anything. 3748180b46ecSThierry Reding */ 3749180b46ecSThierry Reding sor->rst = NULL; 3750f8c79120SJon Hunter } 37516b6b6042SThierry Reding 37526b6b6042SThierry Reding sor->clk = devm_clk_get(&pdev->dev, NULL); 37534dbdc740SThierry Reding if (IS_ERR(sor->clk)) { 3754459cc2c6SThierry Reding err = PTR_ERR(sor->clk); 3755459cc2c6SThierry Reding dev_err(&pdev->dev, "failed to get module clock: %d\n", err); 3756459cc2c6SThierry Reding goto remove; 37574dbdc740SThierry Reding } 37586b6b6042SThierry Reding 3759618dee39SThierry Reding if (sor->soc->supports_hdmi || sor->soc->supports_dp) { 3760e1335e2fSThierry Reding struct device_node *np = pdev->dev.of_node; 3761e1335e2fSThierry Reding const char *name; 3762e1335e2fSThierry Reding 3763e1335e2fSThierry Reding /* 3764e1335e2fSThierry Reding * For backwards compatibility with Tegra210 device trees, 3765e1335e2fSThierry Reding * fall back to the old clock name "source" if the new "out" 3766e1335e2fSThierry Reding * clock is not available. 3767e1335e2fSThierry Reding */ 3768e1335e2fSThierry Reding if (of_property_match_string(np, "clock-names", "out") < 0) 3769e1335e2fSThierry Reding name = "source"; 3770e1335e2fSThierry Reding else 3771e1335e2fSThierry Reding name = "out"; 3772e1335e2fSThierry Reding 3773e1335e2fSThierry Reding sor->clk_out = devm_clk_get(&pdev->dev, name); 3774e1335e2fSThierry Reding if (IS_ERR(sor->clk_out)) { 3775e1335e2fSThierry Reding err = PTR_ERR(sor->clk_out); 3776e1335e2fSThierry Reding dev_err(sor->dev, "failed to get %s clock: %d\n", 3777e1335e2fSThierry Reding name, err); 3778618dee39SThierry Reding goto remove; 3779618dee39SThierry Reding } 37801087fac1SThierry Reding } else { 3781d780537fSThierry Reding /* fall back to the module clock on SOR0 (eDP/LVDS only) */ 37821087fac1SThierry Reding sor->clk_out = sor->clk; 3783618dee39SThierry Reding } 3784618dee39SThierry Reding 37856b6b6042SThierry Reding sor->clk_parent = devm_clk_get(&pdev->dev, "parent"); 37864dbdc740SThierry Reding if (IS_ERR(sor->clk_parent)) { 3787459cc2c6SThierry Reding err = PTR_ERR(sor->clk_parent); 3788459cc2c6SThierry Reding dev_err(&pdev->dev, "failed to get parent clock: %d\n", err); 3789459cc2c6SThierry Reding goto remove; 37904dbdc740SThierry Reding } 37916b6b6042SThierry Reding 37926b6b6042SThierry Reding sor->clk_safe = devm_clk_get(&pdev->dev, "safe"); 37934dbdc740SThierry Reding if (IS_ERR(sor->clk_safe)) { 3794459cc2c6SThierry Reding err = PTR_ERR(sor->clk_safe); 3795459cc2c6SThierry Reding dev_err(&pdev->dev, "failed to get safe clock: %d\n", err); 3796459cc2c6SThierry Reding goto remove; 37974dbdc740SThierry Reding } 37986b6b6042SThierry Reding 37996b6b6042SThierry Reding sor->clk_dp = devm_clk_get(&pdev->dev, "dp"); 38004dbdc740SThierry Reding if (IS_ERR(sor->clk_dp)) { 3801459cc2c6SThierry Reding err = PTR_ERR(sor->clk_dp); 3802459cc2c6SThierry Reding dev_err(&pdev->dev, "failed to get DP clock: %d\n", err); 3803459cc2c6SThierry Reding goto remove; 38044dbdc740SThierry Reding } 38056b6b6042SThierry Reding 3806e1335e2fSThierry Reding /* 3807e1335e2fSThierry Reding * Starting with Tegra186, the BPMP provides an implementation for 3808e1335e2fSThierry Reding * the pad output clock, so we have to look it up from device tree. 3809e1335e2fSThierry Reding */ 3810e1335e2fSThierry Reding sor->clk_pad = devm_clk_get(&pdev->dev, "pad"); 3811e1335e2fSThierry Reding if (IS_ERR(sor->clk_pad)) { 3812e1335e2fSThierry Reding if (sor->clk_pad != ERR_PTR(-ENOENT)) { 3813e1335e2fSThierry Reding err = PTR_ERR(sor->clk_pad); 3814e1335e2fSThierry Reding goto remove; 3815e1335e2fSThierry Reding } 3816e1335e2fSThierry Reding 3817e1335e2fSThierry Reding /* 3818e1335e2fSThierry Reding * If the pad output clock is not available, then we assume 3819e1335e2fSThierry Reding * we're on Tegra210 or earlier and have to provide our own 3820e1335e2fSThierry Reding * implementation. 3821e1335e2fSThierry Reding */ 3822e1335e2fSThierry Reding sor->clk_pad = NULL; 3823e1335e2fSThierry Reding } 3824e1335e2fSThierry Reding 3825e1335e2fSThierry Reding /* 3826e1335e2fSThierry Reding * The bootloader may have set up the SOR such that it's module clock 3827e1335e2fSThierry Reding * is sourced by one of the display PLLs. However, that doesn't work 3828e1335e2fSThierry Reding * without properly having set up other bits of the SOR. 3829e1335e2fSThierry Reding */ 3830e1335e2fSThierry Reding err = clk_set_parent(sor->clk_out, sor->clk_safe); 3831e1335e2fSThierry Reding if (err < 0) { 3832e1335e2fSThierry Reding dev_err(&pdev->dev, "failed to use safe clock: %d\n", err); 3833e1335e2fSThierry Reding goto remove; 3834e1335e2fSThierry Reding } 3835e1335e2fSThierry Reding 3836aaff8bd2SThierry Reding platform_set_drvdata(pdev, sor); 3837aaff8bd2SThierry Reding pm_runtime_enable(&pdev->dev); 3838aaff8bd2SThierry Reding 3839e1335e2fSThierry Reding /* 3840e1335e2fSThierry Reding * On Tegra210 and earlier, provide our own implementation for the 3841e1335e2fSThierry Reding * pad output clock. 3842e1335e2fSThierry Reding */ 3843e1335e2fSThierry Reding if (!sor->clk_pad) { 38444bdf4710SThierry Reding char *name; 38454bdf4710SThierry Reding 3846e1335e2fSThierry Reding err = pm_runtime_get_sync(&pdev->dev); 3847e1335e2fSThierry Reding if (err < 0) { 3848e1335e2fSThierry Reding dev_err(&pdev->dev, "failed to get runtime PM: %d\n", 3849e1335e2fSThierry Reding err); 3850e1335e2fSThierry Reding goto remove; 3851e1335e2fSThierry Reding } 3852b299221cSThierry Reding 38534bdf4710SThierry Reding name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "sor%u_pad_clkout", sor->index); 38544bdf4710SThierry Reding if (!name) { 38554bdf4710SThierry Reding err = -ENOMEM; 38564bdf4710SThierry Reding goto remove; 38574bdf4710SThierry Reding } 38584bdf4710SThierry Reding 38594bdf4710SThierry Reding sor->clk_pad = tegra_clk_sor_pad_register(sor, name); 3860e1335e2fSThierry Reding pm_runtime_put(&pdev->dev); 3861e1335e2fSThierry Reding } 3862e1335e2fSThierry Reding 3863e1335e2fSThierry Reding if (IS_ERR(sor->clk_pad)) { 3864e1335e2fSThierry Reding err = PTR_ERR(sor->clk_pad); 3865e1335e2fSThierry Reding dev_err(&pdev->dev, "failed to register SOR pad clock: %d\n", 3866e1335e2fSThierry Reding err); 3867b299221cSThierry Reding goto remove; 3868b299221cSThierry Reding } 3869b299221cSThierry Reding 38706b6b6042SThierry Reding INIT_LIST_HEAD(&sor->client.list); 38716b6b6042SThierry Reding sor->client.ops = &sor_client_ops; 38726b6b6042SThierry Reding sor->client.dev = &pdev->dev; 38736b6b6042SThierry Reding 38746b6b6042SThierry Reding err = host1x_client_register(&sor->client); 38756b6b6042SThierry Reding if (err < 0) { 38766b6b6042SThierry Reding dev_err(&pdev->dev, "failed to register host1x client: %d\n", 38776b6b6042SThierry Reding err); 3878459cc2c6SThierry Reding goto remove; 38796b6b6042SThierry Reding } 38806b6b6042SThierry Reding 38816b6b6042SThierry Reding return 0; 3882459cc2c6SThierry Reding 3883459cc2c6SThierry Reding remove: 3884459cc2c6SThierry Reding if (sor->ops && sor->ops->remove) 3885459cc2c6SThierry Reding sor->ops->remove(sor); 3886459cc2c6SThierry Reding output: 3887459cc2c6SThierry Reding tegra_output_remove(&sor->output); 3888459cc2c6SThierry Reding return err; 38896b6b6042SThierry Reding } 38906b6b6042SThierry Reding 38916b6b6042SThierry Reding static int tegra_sor_remove(struct platform_device *pdev) 38926b6b6042SThierry Reding { 38936b6b6042SThierry Reding struct tegra_sor *sor = platform_get_drvdata(pdev); 38946b6b6042SThierry Reding int err; 38956b6b6042SThierry Reding 3896aaff8bd2SThierry Reding pm_runtime_disable(&pdev->dev); 3897aaff8bd2SThierry Reding 38986b6b6042SThierry Reding err = host1x_client_unregister(&sor->client); 38996b6b6042SThierry Reding if (err < 0) { 39006b6b6042SThierry Reding dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", 39016b6b6042SThierry Reding err); 39026b6b6042SThierry Reding return err; 39036b6b6042SThierry Reding } 39046b6b6042SThierry Reding 3905459cc2c6SThierry Reding if (sor->ops && sor->ops->remove) { 3906459cc2c6SThierry Reding err = sor->ops->remove(sor); 3907459cc2c6SThierry Reding if (err < 0) 3908459cc2c6SThierry Reding dev_err(&pdev->dev, "failed to remove SOR: %d\n", err); 3909459cc2c6SThierry Reding } 3910459cc2c6SThierry Reding 3911328ec69eSThierry Reding tegra_output_remove(&sor->output); 39126b6b6042SThierry Reding 39136b6b6042SThierry Reding return 0; 39146b6b6042SThierry Reding } 39156b6b6042SThierry Reding 3916be0b23f2SThierry Reding static int tegra_sor_runtime_suspend(struct device *dev) 3917aaff8bd2SThierry Reding { 3918aaff8bd2SThierry Reding struct tegra_sor *sor = dev_get_drvdata(dev); 3919aaff8bd2SThierry Reding int err; 3920aaff8bd2SThierry Reding 3921f8c79120SJon Hunter if (sor->rst) { 3922aaff8bd2SThierry Reding err = reset_control_assert(sor->rst); 3923aaff8bd2SThierry Reding if (err < 0) { 3924aaff8bd2SThierry Reding dev_err(dev, "failed to assert reset: %d\n", err); 3925aaff8bd2SThierry Reding return err; 3926aaff8bd2SThierry Reding } 392711c632e1SThierry Reding 392811c632e1SThierry Reding reset_control_release(sor->rst); 3929f8c79120SJon Hunter } 3930aaff8bd2SThierry Reding 3931aaff8bd2SThierry Reding usleep_range(1000, 2000); 3932aaff8bd2SThierry Reding 3933aaff8bd2SThierry Reding clk_disable_unprepare(sor->clk); 3934aaff8bd2SThierry Reding 3935aaff8bd2SThierry Reding return 0; 3936aaff8bd2SThierry Reding } 3937aaff8bd2SThierry Reding 3938be0b23f2SThierry Reding static int tegra_sor_runtime_resume(struct device *dev) 3939aaff8bd2SThierry Reding { 3940aaff8bd2SThierry Reding struct tegra_sor *sor = dev_get_drvdata(dev); 3941aaff8bd2SThierry Reding int err; 3942aaff8bd2SThierry Reding 3943aaff8bd2SThierry Reding err = clk_prepare_enable(sor->clk); 3944aaff8bd2SThierry Reding if (err < 0) { 3945aaff8bd2SThierry Reding dev_err(dev, "failed to enable clock: %d\n", err); 3946aaff8bd2SThierry Reding return err; 3947aaff8bd2SThierry Reding } 3948aaff8bd2SThierry Reding 3949aaff8bd2SThierry Reding usleep_range(1000, 2000); 3950aaff8bd2SThierry Reding 3951f8c79120SJon Hunter if (sor->rst) { 395211c632e1SThierry Reding err = reset_control_acquire(sor->rst); 395311c632e1SThierry Reding if (err < 0) { 395411c632e1SThierry Reding dev_err(dev, "failed to acquire reset: %d\n", err); 395511c632e1SThierry Reding clk_disable_unprepare(sor->clk); 395611c632e1SThierry Reding return err; 395711c632e1SThierry Reding } 395811c632e1SThierry Reding 3959aaff8bd2SThierry Reding err = reset_control_deassert(sor->rst); 3960aaff8bd2SThierry Reding if (err < 0) { 3961aaff8bd2SThierry Reding dev_err(dev, "failed to deassert reset: %d\n", err); 396211c632e1SThierry Reding reset_control_release(sor->rst); 3963aaff8bd2SThierry Reding clk_disable_unprepare(sor->clk); 3964aaff8bd2SThierry Reding return err; 3965aaff8bd2SThierry Reding } 3966f8c79120SJon Hunter } 3967aaff8bd2SThierry Reding 3968aaff8bd2SThierry Reding return 0; 3969aaff8bd2SThierry Reding } 3970be0b23f2SThierry Reding 3971be0b23f2SThierry Reding static int tegra_sor_suspend(struct device *dev) 3972be0b23f2SThierry Reding { 3973be0b23f2SThierry Reding struct tegra_sor *sor = dev_get_drvdata(dev); 3974b06e145fSThierry Reding int err; 3975be0b23f2SThierry Reding 3976b06e145fSThierry Reding if (sor->hdmi_supply) { 3977b06e145fSThierry Reding err = regulator_disable(sor->hdmi_supply); 3978b06e145fSThierry Reding if (err < 0) 3979b06e145fSThierry Reding return err; 3980b06e145fSThierry Reding } 3981b06e145fSThierry Reding 3982b06e145fSThierry Reding return 0; 3983be0b23f2SThierry Reding } 3984be0b23f2SThierry Reding 3985be0b23f2SThierry Reding static int tegra_sor_resume(struct device *dev) 3986be0b23f2SThierry Reding { 3987be0b23f2SThierry Reding struct tegra_sor *sor = dev_get_drvdata(dev); 3988b06e145fSThierry Reding int err; 3989be0b23f2SThierry Reding 3990b06e145fSThierry Reding if (sor->hdmi_supply) { 3991b06e145fSThierry Reding err = regulator_enable(sor->hdmi_supply); 3992b06e145fSThierry Reding if (err < 0) 3993b06e145fSThierry Reding return err; 3994b06e145fSThierry Reding } 3995b06e145fSThierry Reding 3996b06e145fSThierry Reding return 0; 3997be0b23f2SThierry Reding } 3998aaff8bd2SThierry Reding 3999aaff8bd2SThierry Reding static const struct dev_pm_ops tegra_sor_pm_ops = { 4000be0b23f2SThierry Reding SET_RUNTIME_PM_OPS(tegra_sor_runtime_suspend, tegra_sor_runtime_resume, 4001be0b23f2SThierry Reding NULL) 4002be0b23f2SThierry Reding SET_SYSTEM_SLEEP_PM_OPS(tegra_sor_suspend, tegra_sor_resume) 4003aaff8bd2SThierry Reding }; 4004aaff8bd2SThierry Reding 40056b6b6042SThierry Reding struct platform_driver tegra_sor_driver = { 40066b6b6042SThierry Reding .driver = { 40076b6b6042SThierry Reding .name = "tegra-sor", 40086b6b6042SThierry Reding .of_match_table = tegra_sor_of_match, 4009aaff8bd2SThierry Reding .pm = &tegra_sor_pm_ops, 40106b6b6042SThierry Reding }, 40116b6b6042SThierry Reding .probe = tegra_sor_probe, 40126b6b6042SThierry Reding .remove = tegra_sor_remove, 40136b6b6042SThierry Reding }; 4014