blob: 786ba2de68a751477aa5d416bffbcebb35543981 [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Subrata Banikcb771a22017-11-28 16:26:08 +05302
Nico Huber1a650172018-12-16 02:39:28 +01003#include <commonlib/helpers.h>
Nico Huber826094f2020-04-26 19:24:00 +02004#include <device/mmio.h>
Paul Menzel270a3232020-07-25 10:49:44 +02005#include <device/pci_rom.h>
Nico Huber1a650172018-12-16 02:39:28 +01006#include <device/resource.h>
Matt DeVillierddb4cf02020-03-27 14:13:07 -05007#include <drivers/intel/gma/i915.h>
Subrata Banikcb771a22017-11-28 16:26:08 +05308#include <drivers/intel/gma/i915_reg.h>
9#include <intelblocks/graphics.h>
Subrata Banikcb771a22017-11-28 16:26:08 +053010#include <soc/ramstage.h>
Paul Menzel270a3232020-07-25 10:49:44 +020011#include <soc/systemagent.h>
Elyes HAOUAS27d02d82019-05-15 21:11:39 +020012#include <types.h>
Subrata Banikcb771a22017-11-28 16:26:08 +053013
Matt DeVillier395ab9d2020-12-23 17:30:27 -060014void graphics_soc_panel_init(struct device *dev)
Nico Huber1a650172018-12-16 02:39:28 +010015{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030016 struct soc_intel_skylake_config *conf = config_of(dev);
Michael Niewöhner97e21d32020-12-28 00:49:33 +010017 const struct i915_gpu_panel_config *panel_cfg;
Nico Huber1a650172018-12-16 02:39:28 +010018 struct resource *mmio_res;
19 uint8_t *base;
20 u32 reg32;
21
22 if (!conf)
23 return;
24
Michael Niewöhner97e21d32020-12-28 00:49:33 +010025 panel_cfg = &conf->panel_cfg;
26
Nico Huber1a650172018-12-16 02:39:28 +010027 mmio_res = find_resource(dev, PCI_BASE_ADDRESS_0);
28 if (!mmio_res || !mmio_res->base)
29 return;
30 base = (void *)(uintptr_t)mmio_res->base;
31
Michael Niewöhner97e21d32020-12-28 00:49:33 +010032 reg32 = ((panel_cfg->up_delay_ms * 10) & 0x1fff) << 16;
33 reg32 |= (panel_cfg->backlight_on_delay_ms * 10) & 0x1fff;
Nico Huber1a650172018-12-16 02:39:28 +010034 write32(base + PCH_PP_ON_DELAYS, reg32);
35
Michael Niewöhner97e21d32020-12-28 00:49:33 +010036 reg32 = ((panel_cfg->down_delay_ms * 10) & 0x1fff) << 16;
37 reg32 |= (panel_cfg->backlight_off_delay_ms * 10) & 0x1fff;
Nico Huber1a650172018-12-16 02:39:28 +010038 write32(base + PCH_PP_OFF_DELAYS, reg32);
39
40 reg32 = read32(base + PCH_PP_DIVISOR);
41 reg32 &= ~0x1f;
Michael Niewöhner97e21d32020-12-28 00:49:33 +010042 reg32 |= (DIV_ROUND_UP(panel_cfg->cycle_delay_ms, 100) + 1) & 0x1f;
Nico Huber1a650172018-12-16 02:39:28 +010043 write32(base + PCH_PP_DIVISOR, reg32);
44
45 /* So far all devices seem to use the PCH PWM function.
46 The CPU PWM registers are all zero after reset. */
Michael Niewöhner97e21d32020-12-28 00:49:33 +010047 if (panel_cfg->backlight_pwm_hz) {
Nico Huber1a650172018-12-16 02:39:28 +010048 /* Reference clock is 24MHz. We can choose either a 16
49 or a 128 step increment. Use 16 if we would have less
50 than 100 steps otherwise. */
51 const unsigned int hz_limit = 24 * 1000 * 1000 / 128 / 100;
52 unsigned int pwm_increment, pwm_period;
53 u32 south_chicken1;
54
55 south_chicken1 = read32(base + SOUTH_CHICKEN1);
Michael Niewöhner97e21d32020-12-28 00:49:33 +010056 if (panel_cfg->backlight_pwm_hz > hz_limit) {
Nico Huber1a650172018-12-16 02:39:28 +010057 pwm_increment = 16;
58 south_chicken1 &= ~1;
59 } else {
60 pwm_increment = 128;
61 south_chicken1 |= 1;
62 }
63 write32(base + SOUTH_CHICKEN1, south_chicken1);
64
Michael Niewöhner97e21d32020-12-28 00:49:33 +010065 pwm_period = 24 * 1000 * 1000 / pwm_increment / panel_cfg->backlight_pwm_hz;
Nico Huber1a650172018-12-16 02:39:28 +010066 /* Start with a 50% duty cycle. */
Michael Niewöhner97e21d32020-12-28 00:49:33 +010067 write32(base + BLC_PWM_PCH_CTL2, pwm_period << 16 | pwm_period / 2);
Nico Huber1a650172018-12-16 02:39:28 +010068
69 write32(base + BLC_PWM_PCH_CTL1,
Michael Niewöhner97e21d32020-12-28 00:49:33 +010070 !!panel_cfg->backlight_polarity << 29 | BLM_PCH_PWM_ENABLE);
Nico Huber1a650172018-12-16 02:39:28 +010071 }
72}
73
Matt DeVillierddb4cf02020-03-27 14:13:07 -050074const struct i915_gpu_controller_info *
Furquan Shaikhec3dafd2020-04-24 21:53:42 -070075intel_igd_get_controller_info(const struct device *device)
Matt DeVillierddb4cf02020-03-27 14:13:07 -050076{
77 struct soc_intel_skylake_config *chip = device->chip_info;
78 return &chip->gfx;
79}
Paul Menzel270a3232020-07-25 10:49:44 +020080
81/*
82 * Some VGA option roms are used for several chipsets but they only have one PCI ID in their
83 * header. If we encounter such an option rom, we need to do the mapping ourselves.
84 */
85u32 map_oprom_vendev(u32 vendev)
86{
87 u32 new_vendev = vendev;
88
89 switch (vendev) {
90 case 0x80865916: /* PCI_DEVICE_ID_INTEL_KBL_GT2_SULTM */
91 case 0x80865917: /* PCI_DEVICE_ID_INTEL_KBL_GT2_SULTMR */
92 new_vendev = SA_IGD_OPROM_VENDEV;
93 break;
94 }
95
96 return new_vendev;
97}