1e3adcf8fSFrançois Tigeot /* 2e3adcf8fSFrançois Tigeot * Copyright 2008 Intel Corporation <hong.liu@intel.com> 3e3adcf8fSFrançois Tigeot * Copyright 2008 Red Hat <mjg@redhat.com> 4e3adcf8fSFrançois Tigeot * 5e3adcf8fSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining 6e3adcf8fSFrançois Tigeot * a copy of this software and associated documentation files (the 7e3adcf8fSFrançois Tigeot * "Software"), to deal in the Software without restriction, including 8e3adcf8fSFrançois Tigeot * without limitation the rights to use, copy, modify, merge, publish, 9e3adcf8fSFrançois Tigeot * distribute, sub license, and/or sell copies of the Software, and to 10e3adcf8fSFrançois Tigeot * permit persons to whom the Software is furnished to do so, subject to 11e3adcf8fSFrançois Tigeot * the following conditions: 12e3adcf8fSFrançois Tigeot * 13e3adcf8fSFrançois Tigeot * The above copyright notice and this permission notice (including the 14e3adcf8fSFrançois Tigeot * next paragraph) shall be included in all copies or substantial 15e3adcf8fSFrançois Tigeot * portions of the Software. 16e3adcf8fSFrançois Tigeot * 17e3adcf8fSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18e3adcf8fSFrançois Tigeot * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19e3adcf8fSFrançois Tigeot * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20e3adcf8fSFrançois Tigeot * NON-INFRINGEMENT. IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE 21e3adcf8fSFrançois Tigeot * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22e3adcf8fSFrançois Tigeot * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23e3adcf8fSFrançois Tigeot * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24e3adcf8fSFrançois Tigeot * SOFTWARE. 25e3adcf8fSFrançois Tigeot * 26e3adcf8fSFrançois Tigeot */ 27e3adcf8fSFrançois Tigeot 2818e26a6dSFrançois Tigeot #include <drm/drmP.h> 295c6c6f23SFrançois Tigeot #include <drm/i915_drm.h> 30e3adcf8fSFrançois Tigeot #include "i915_drv.h" 31e3adcf8fSFrançois Tigeot #include "intel_drv.h" 32a2fdbec6SFrançois Tigeot 3390c722cdSMarkus Pfeiffer #include <contrib/dev/acpica/source/include/acpi.h> 3490c722cdSMarkus Pfeiffer #include <contrib/dev/acpica/source/include/accommon.h> 3590c722cdSMarkus Pfeiffer #include <dev/acpica/acpivar.h> 36e3adcf8fSFrançois Tigeot 37e3adcf8fSFrançois Tigeot #define PCI_ASLE 0xe4 38e3adcf8fSFrançois Tigeot #define PCI_ASLS 0xfc 39e3adcf8fSFrançois Tigeot 40e3adcf8fSFrançois Tigeot #define OPREGION_HEADER_OFFSET 0 41e3adcf8fSFrançois Tigeot #define OPREGION_ACPI_OFFSET 0x100 42e3adcf8fSFrançois Tigeot #define ACPI_CLID 0x01ac /* current lid state indicator */ 43e3adcf8fSFrançois Tigeot #define ACPI_CDCK 0x01b0 /* current docking state indicator */ 44e3adcf8fSFrançois Tigeot #define OPREGION_SWSCI_OFFSET 0x200 45e3adcf8fSFrançois Tigeot #define OPREGION_ASLE_OFFSET 0x300 46e3adcf8fSFrançois Tigeot #define OPREGION_VBT_OFFSET 0x400 47e3adcf8fSFrançois Tigeot 48e3adcf8fSFrançois Tigeot #define OPREGION_SIGNATURE "IntelGraphicsMem" 49e3adcf8fSFrançois Tigeot #define MBOX_ACPI (1<<0) 50e3adcf8fSFrançois Tigeot #define MBOX_SWSCI (1<<1) 51e3adcf8fSFrançois Tigeot #define MBOX_ASLE (1<<2) 52e3adcf8fSFrançois Tigeot 53e3adcf8fSFrançois Tigeot struct opregion_header { 54e3adcf8fSFrançois Tigeot u8 signature[16]; 55e3adcf8fSFrançois Tigeot u32 size; 56e3adcf8fSFrançois Tigeot u32 opregion_ver; 57e3adcf8fSFrançois Tigeot u8 bios_ver[32]; 58e3adcf8fSFrançois Tigeot u8 vbios_ver[16]; 59e3adcf8fSFrançois Tigeot u8 driver_ver[16]; 60e3adcf8fSFrançois Tigeot u32 mboxes; 61e3adcf8fSFrançois Tigeot u8 reserved[164]; 62e3adcf8fSFrançois Tigeot } __attribute__((packed)); 63e3adcf8fSFrançois Tigeot 64e3adcf8fSFrançois Tigeot /* OpRegion mailbox #1: public ACPI methods */ 65e3adcf8fSFrançois Tigeot struct opregion_acpi { 66e3adcf8fSFrançois Tigeot u32 drdy; /* driver readiness */ 67e3adcf8fSFrançois Tigeot u32 csts; /* notification status */ 68e3adcf8fSFrançois Tigeot u32 cevt; /* current event */ 69e3adcf8fSFrançois Tigeot u8 rsvd1[20]; 70e3adcf8fSFrançois Tigeot u32 didl[8]; /* supported display devices ID list */ 71e3adcf8fSFrançois Tigeot u32 cpdl[8]; /* currently presented display list */ 72e3adcf8fSFrançois Tigeot u32 cadl[8]; /* currently active display list */ 73e3adcf8fSFrançois Tigeot u32 nadl[8]; /* next active devices list */ 74e3adcf8fSFrançois Tigeot u32 aslp; /* ASL sleep time-out */ 75e3adcf8fSFrançois Tigeot u32 tidx; /* toggle table index */ 76e3adcf8fSFrançois Tigeot u32 chpd; /* current hotplug enable indicator */ 77e3adcf8fSFrançois Tigeot u32 clid; /* current lid state*/ 78e3adcf8fSFrançois Tigeot u32 cdck; /* current docking state */ 79e3adcf8fSFrançois Tigeot u32 sxsw; /* Sx state resume */ 80e3adcf8fSFrançois Tigeot u32 evts; /* ASL supported events */ 81e3adcf8fSFrançois Tigeot u32 cnot; /* current OS notification */ 82e3adcf8fSFrançois Tigeot u32 nrdy; /* driver status */ 83e3adcf8fSFrançois Tigeot u8 rsvd2[60]; 84e3adcf8fSFrançois Tigeot } __attribute__((packed)); 85e3adcf8fSFrançois Tigeot 86e3adcf8fSFrançois Tigeot /* OpRegion mailbox #2: SWSCI */ 87e3adcf8fSFrançois Tigeot struct opregion_swsci { 88e3adcf8fSFrançois Tigeot u32 scic; /* SWSCI command|status|data */ 89e3adcf8fSFrançois Tigeot u32 parm; /* command parameters */ 90e3adcf8fSFrançois Tigeot u32 dslp; /* driver sleep time-out */ 91e3adcf8fSFrançois Tigeot u8 rsvd[244]; 92e3adcf8fSFrançois Tigeot } __attribute__((packed)); 93e3adcf8fSFrançois Tigeot 94e3adcf8fSFrançois Tigeot /* OpRegion mailbox #3: ASLE */ 95e3adcf8fSFrançois Tigeot struct opregion_asle { 96e3adcf8fSFrançois Tigeot u32 ardy; /* driver readiness */ 97e3adcf8fSFrançois Tigeot u32 aslc; /* ASLE interrupt command */ 98e3adcf8fSFrançois Tigeot u32 tche; /* technology enabled indicator */ 99e3adcf8fSFrançois Tigeot u32 alsi; /* current ALS illuminance reading */ 100e3adcf8fSFrançois Tigeot u32 bclp; /* backlight brightness to set */ 101e3adcf8fSFrançois Tigeot u32 pfit; /* panel fitting state */ 102e3adcf8fSFrançois Tigeot u32 cblv; /* current brightness level */ 103e3adcf8fSFrançois Tigeot u16 bclm[20]; /* backlight level duty cycle mapping table */ 104e3adcf8fSFrançois Tigeot u32 cpfm; /* current panel fitting mode */ 105e3adcf8fSFrançois Tigeot u32 epfm; /* enabled panel fitting modes */ 106e3adcf8fSFrançois Tigeot u8 plut[74]; /* panel LUT and identifier */ 107e3adcf8fSFrançois Tigeot u32 pfmb; /* PWM freq and min brightness */ 108e3adcf8fSFrançois Tigeot u8 rsvd[102]; 109e3adcf8fSFrançois Tigeot } __attribute__((packed)); 110e3adcf8fSFrançois Tigeot 111*5d0b1887SFrançois Tigeot /* Driver readiness indicator */ 112*5d0b1887SFrançois Tigeot #define ASLE_ARDY_READY (1 << 0) 113*5d0b1887SFrançois Tigeot #define ASLE_ARDY_NOT_READY (0 << 0) 114*5d0b1887SFrançois Tigeot 115e3adcf8fSFrançois Tigeot /* ASLE irq request bits */ 116e3adcf8fSFrançois Tigeot #define ASLE_SET_ALS_ILLUM (1 << 0) 117e3adcf8fSFrançois Tigeot #define ASLE_SET_BACKLIGHT (1 << 1) 118e3adcf8fSFrançois Tigeot #define ASLE_SET_PFIT (1 << 2) 119e3adcf8fSFrançois Tigeot #define ASLE_SET_PWM_FREQ (1 << 3) 120e3adcf8fSFrançois Tigeot #define ASLE_REQ_MSK 0xf 121e3adcf8fSFrançois Tigeot 122e3adcf8fSFrançois Tigeot /* response bits of ASLE irq request */ 123e3adcf8fSFrançois Tigeot #define ASLE_ALS_ILLUM_FAILED (1<<10) 124e3adcf8fSFrançois Tigeot #define ASLE_BACKLIGHT_FAILED (1<<12) 125e3adcf8fSFrançois Tigeot #define ASLE_PFIT_FAILED (1<<14) 126e3adcf8fSFrançois Tigeot #define ASLE_PWM_FREQ_FAILED (1<<16) 127e3adcf8fSFrançois Tigeot 128*5d0b1887SFrançois Tigeot /* Technology enabled indicator */ 129*5d0b1887SFrançois Tigeot #define ASLE_TCHE_ALS_EN (1 << 0) 130*5d0b1887SFrançois Tigeot #define ASLE_TCHE_BLC_EN (1 << 1) 131*5d0b1887SFrançois Tigeot #define ASLE_TCHE_PFIT_EN (1 << 2) 132*5d0b1887SFrançois Tigeot #define ASLE_TCHE_PFMB_EN (1 << 3) 133*5d0b1887SFrançois Tigeot 134e3adcf8fSFrançois Tigeot /* ASLE backlight brightness to set */ 135e3adcf8fSFrançois Tigeot #define ASLE_BCLP_VALID (1<<31) 136e3adcf8fSFrançois Tigeot #define ASLE_BCLP_MSK (~(1<<31)) 137e3adcf8fSFrançois Tigeot 138e3adcf8fSFrançois Tigeot /* ASLE panel fitting request */ 139e3adcf8fSFrançois Tigeot #define ASLE_PFIT_VALID (1<<31) 140e3adcf8fSFrançois Tigeot #define ASLE_PFIT_CENTER (1<<0) 141e3adcf8fSFrançois Tigeot #define ASLE_PFIT_STRETCH_TEXT (1<<1) 142e3adcf8fSFrançois Tigeot #define ASLE_PFIT_STRETCH_GFX (1<<2) 143e3adcf8fSFrançois Tigeot 144e3adcf8fSFrançois Tigeot /* PWM frequency and minimum brightness */ 145e3adcf8fSFrançois Tigeot #define ASLE_PFMB_BRIGHTNESS_MASK (0xff) 146e3adcf8fSFrançois Tigeot #define ASLE_PFMB_BRIGHTNESS_VALID (1<<8) 147e3adcf8fSFrançois Tigeot #define ASLE_PFMB_PWM_MASK (0x7ffffe00) 148e3adcf8fSFrançois Tigeot #define ASLE_PFMB_PWM_VALID (1<<31) 149e3adcf8fSFrançois Tigeot 150e3adcf8fSFrançois Tigeot #define ASLE_CBLV_VALID (1<<31) 151e3adcf8fSFrançois Tigeot 152e3adcf8fSFrançois Tigeot #define ACPI_OTHER_OUTPUT (0<<8) 153e3adcf8fSFrançois Tigeot #define ACPI_VGA_OUTPUT (1<<8) 154e3adcf8fSFrançois Tigeot #define ACPI_TV_OUTPUT (2<<8) 155e3adcf8fSFrançois Tigeot #define ACPI_DIGITAL_OUTPUT (3<<8) 156e3adcf8fSFrançois Tigeot #define ACPI_LVDS_OUTPUT (4<<8) 157e3adcf8fSFrançois Tigeot 158e3adcf8fSFrançois Tigeot static u32 asle_set_backlight(struct drm_device *dev, u32 bclp) 159e3adcf8fSFrançois Tigeot { 160e3adcf8fSFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 16100640ec9SFrançois Tigeot struct opregion_asle __iomem *asle = dev_priv->opregion.asle; 162e3adcf8fSFrançois Tigeot 16300640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("bclp = 0x%08x\n", bclp); 16400640ec9SFrançois Tigeot 165e3adcf8fSFrançois Tigeot if (!(bclp & ASLE_BCLP_VALID)) 166e3adcf8fSFrançois Tigeot return ASLE_BACKLIGHT_FAILED; 167e3adcf8fSFrançois Tigeot 168e3adcf8fSFrançois Tigeot bclp &= ASLE_BCLP_MSK; 169e3adcf8fSFrançois Tigeot if (bclp > 255) 170e3adcf8fSFrançois Tigeot return ASLE_BACKLIGHT_FAILED; 171e3adcf8fSFrançois Tigeot 172*5d0b1887SFrançois Tigeot intel_panel_set_backlight(dev, bclp, 255); 17300640ec9SFrançois Tigeot iowrite32((bclp*0x64)/0xff | ASLE_CBLV_VALID, &asle->cblv); 174e3adcf8fSFrançois Tigeot 175e3adcf8fSFrançois Tigeot return 0; 176e3adcf8fSFrançois Tigeot } 177e3adcf8fSFrançois Tigeot 178e3adcf8fSFrançois Tigeot static u32 asle_set_als_illum(struct drm_device *dev, u32 alsi) 179e3adcf8fSFrançois Tigeot { 180e3adcf8fSFrançois Tigeot /* alsi is the current ALS reading in lux. 0 indicates below sensor 181e3adcf8fSFrançois Tigeot range, 0xffff indicates above sensor range. 1-0xfffe are valid */ 182*5d0b1887SFrançois Tigeot DRM_DEBUG_DRIVER("Illum is not supported\n"); 183*5d0b1887SFrançois Tigeot return ASLE_ALS_ILLUM_FAILED; 184e3adcf8fSFrançois Tigeot } 185e3adcf8fSFrançois Tigeot 186e3adcf8fSFrançois Tigeot static u32 asle_set_pwm_freq(struct drm_device *dev, u32 pfmb) 187e3adcf8fSFrançois Tigeot { 188*5d0b1887SFrançois Tigeot DRM_DEBUG_DRIVER("PWM freq is not supported\n"); 189*5d0b1887SFrançois Tigeot return ASLE_PWM_FREQ_FAILED; 190e3adcf8fSFrançois Tigeot } 191e3adcf8fSFrançois Tigeot 192e3adcf8fSFrançois Tigeot static u32 asle_set_pfit(struct drm_device *dev, u32 pfit) 193e3adcf8fSFrançois Tigeot { 194e3adcf8fSFrançois Tigeot /* Panel fitting is currently controlled by the X code, so this is a 195e3adcf8fSFrançois Tigeot noop until modesetting support works fully */ 196*5d0b1887SFrançois Tigeot DRM_DEBUG_DRIVER("Pfit is not supported\n"); 197e3adcf8fSFrançois Tigeot return ASLE_PFIT_FAILED; 198e3adcf8fSFrançois Tigeot } 199e3adcf8fSFrançois Tigeot 200e3adcf8fSFrançois Tigeot void intel_opregion_asle_intr(struct drm_device *dev) 201e3adcf8fSFrançois Tigeot { 202e3adcf8fSFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 20300640ec9SFrançois Tigeot struct opregion_asle __iomem *asle = dev_priv->opregion.asle; 204e3adcf8fSFrançois Tigeot u32 asle_stat = 0; 205e3adcf8fSFrançois Tigeot u32 asle_req; 206e3adcf8fSFrançois Tigeot 207e3adcf8fSFrançois Tigeot if (!asle) 208e3adcf8fSFrançois Tigeot return; 209e3adcf8fSFrançois Tigeot 21000640ec9SFrançois Tigeot asle_req = ioread32(&asle->aslc) & ASLE_REQ_MSK; 211e3adcf8fSFrançois Tigeot 212e3adcf8fSFrançois Tigeot if (!asle_req) { 21300640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("non asle set request??\n"); 214e3adcf8fSFrançois Tigeot return; 215e3adcf8fSFrançois Tigeot } 216e3adcf8fSFrançois Tigeot 217e3adcf8fSFrançois Tigeot if (asle_req & ASLE_SET_ALS_ILLUM) 21800640ec9SFrançois Tigeot asle_stat |= asle_set_als_illum(dev, ioread32(&asle->alsi)); 219e3adcf8fSFrançois Tigeot 220e3adcf8fSFrançois Tigeot if (asle_req & ASLE_SET_BACKLIGHT) 22100640ec9SFrançois Tigeot asle_stat |= asle_set_backlight(dev, ioread32(&asle->bclp)); 222e3adcf8fSFrançois Tigeot 223e3adcf8fSFrançois Tigeot if (asle_req & ASLE_SET_PFIT) 22400640ec9SFrançois Tigeot asle_stat |= asle_set_pfit(dev, ioread32(&asle->pfit)); 225e3adcf8fSFrançois Tigeot 226e3adcf8fSFrançois Tigeot if (asle_req & ASLE_SET_PWM_FREQ) 22700640ec9SFrançois Tigeot asle_stat |= asle_set_pwm_freq(dev, ioread32(&asle->pfmb)); 228e3adcf8fSFrançois Tigeot 22900640ec9SFrançois Tigeot iowrite32(asle_stat, &asle->aslc); 230e3adcf8fSFrançois Tigeot } 231e3adcf8fSFrançois Tigeot 232e3adcf8fSFrançois Tigeot #define ACPI_EV_DISPLAY_SWITCH (1<<0) 233e3adcf8fSFrançois Tigeot #define ACPI_EV_LID (1<<1) 234e3adcf8fSFrançois Tigeot #define ACPI_EV_DOCK (1<<2) 235e3adcf8fSFrançois Tigeot 236e3adcf8fSFrançois Tigeot static struct intel_opregion *system_opregion; 237e3adcf8fSFrançois Tigeot 23890c722cdSMarkus Pfeiffer #if 0 239e3adcf8fSFrançois Tigeot static int intel_opregion_video_event(struct notifier_block *nb, 240e3adcf8fSFrançois Tigeot unsigned long val, void *data) 241e3adcf8fSFrançois Tigeot { 242e3adcf8fSFrançois Tigeot /* The only video events relevant to opregion are 0x80. These indicate 243e3adcf8fSFrançois Tigeot either a docking event, lid switch or display switch request. In 244e3adcf8fSFrançois Tigeot Linux, these are handled by the dock, button and video drivers. 245e3adcf8fSFrançois Tigeot */ 24600640ec9SFrançois Tigeot 24700640ec9SFrançois Tigeot struct opregion_acpi __iomem *acpi; 248e3adcf8fSFrançois Tigeot struct acpi_bus_event *event = data; 249e3adcf8fSFrançois Tigeot int ret = NOTIFY_OK; 250e3adcf8fSFrançois Tigeot 251e3adcf8fSFrançois Tigeot if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0) 252e3adcf8fSFrançois Tigeot return NOTIFY_DONE; 253e3adcf8fSFrançois Tigeot 254e3adcf8fSFrançois Tigeot if (!system_opregion) 255e3adcf8fSFrançois Tigeot return NOTIFY_DONE; 256e3adcf8fSFrançois Tigeot 257e3adcf8fSFrançois Tigeot acpi = system_opregion->acpi; 258e3adcf8fSFrançois Tigeot 25900640ec9SFrançois Tigeot if (event->type == 0x80 && 26000640ec9SFrançois Tigeot (ioread32(&acpi->cevt) & 1) == 0) 261e3adcf8fSFrançois Tigeot ret = NOTIFY_BAD; 262e3adcf8fSFrançois Tigeot 26300640ec9SFrançois Tigeot iowrite32(0, &acpi->csts); 264e3adcf8fSFrançois Tigeot 265e3adcf8fSFrançois Tigeot return ret; 266e3adcf8fSFrançois Tigeot } 267e3adcf8fSFrançois Tigeot 268e3adcf8fSFrançois Tigeot static struct notifier_block intel_opregion_notifier = { 269e3adcf8fSFrançois Tigeot .notifier_call = intel_opregion_video_event, 270e3adcf8fSFrançois Tigeot }; 27190c722cdSMarkus Pfeiffer #endif 27290c722cdSMarkus Pfeiffer 27390c722cdSMarkus Pfeiffer static int acpi_is_video_device(ACPI_HANDLE devh) { 27490c722cdSMarkus Pfeiffer ACPI_HANDLE h; 27590c722cdSMarkus Pfeiffer if (ACPI_FAILURE(AcpiGetHandle(devh, "_DOD", &h)) || 27690c722cdSMarkus Pfeiffer ACPI_FAILURE(AcpiGetHandle(devh, "_DOS", &h))) { 27790c722cdSMarkus Pfeiffer return 0; 27890c722cdSMarkus Pfeiffer } 27990c722cdSMarkus Pfeiffer return 1; 28090c722cdSMarkus Pfeiffer } 281e3adcf8fSFrançois Tigeot 282e3adcf8fSFrançois Tigeot /* 283e3adcf8fSFrançois Tigeot * Initialise the DIDL field in opregion. This passes a list of devices to 284e3adcf8fSFrançois Tigeot * the firmware. Values are defined by section B.4.2 of the ACPI specification 285e3adcf8fSFrançois Tigeot * (version 3) 286e3adcf8fSFrançois Tigeot */ 287e3adcf8fSFrançois Tigeot 288e3adcf8fSFrançois Tigeot static void intel_didl_outputs(struct drm_device *dev) 289e3adcf8fSFrançois Tigeot { 290e3adcf8fSFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 291e3adcf8fSFrançois Tigeot struct intel_opregion *opregion = &dev_priv->opregion; 292e3adcf8fSFrançois Tigeot struct drm_connector *connector; 293a2fdbec6SFrançois Tigeot ACPI_HANDLE handle, acpi_cdev, acpi_video_bus; 29490c722cdSMarkus Pfeiffer u32 device_id; 29590c722cdSMarkus Pfeiffer ACPI_STATUS status; 29600640ec9SFrançois Tigeot u32 temp; 297e3adcf8fSFrançois Tigeot int i = 0; 298e3adcf8fSFrançois Tigeot 29990c722cdSMarkus Pfeiffer handle = acpi_get_handle(dev->dev); 30090c722cdSMarkus Pfeiffer if (!handle) 301e3adcf8fSFrançois Tigeot return; 302e3adcf8fSFrançois Tigeot 30390c722cdSMarkus Pfeiffer if (acpi_is_video_device(handle)) 30490c722cdSMarkus Pfeiffer acpi_video_bus = handle; 305e3adcf8fSFrançois Tigeot else { 30690c722cdSMarkus Pfeiffer acpi_cdev = NULL; 30790c722cdSMarkus Pfeiffer acpi_video_bus = NULL; 30890c722cdSMarkus Pfeiffer while (AcpiGetNextObject(ACPI_TYPE_DEVICE, handle, acpi_cdev, 30990c722cdSMarkus Pfeiffer &acpi_cdev) != AE_NOT_FOUND) { 310e3adcf8fSFrançois Tigeot if (acpi_is_video_device(acpi_cdev)) { 311e3adcf8fSFrançois Tigeot acpi_video_bus = acpi_cdev; 312e3adcf8fSFrançois Tigeot break; 313e3adcf8fSFrançois Tigeot } 314e3adcf8fSFrançois Tigeot } 315e3adcf8fSFrançois Tigeot } 316e3adcf8fSFrançois Tigeot 317e3adcf8fSFrançois Tigeot if (!acpi_video_bus) { 31800640ec9SFrançois Tigeot pr_warn("No ACPI video bus found\n"); 319e3adcf8fSFrançois Tigeot return; 320e3adcf8fSFrançois Tigeot } 321e3adcf8fSFrançois Tigeot 32290c722cdSMarkus Pfeiffer acpi_cdev = NULL; 32390c722cdSMarkus Pfeiffer while (AcpiGetNextObject(ACPI_TYPE_DEVICE, acpi_video_bus, acpi_cdev, 32490c722cdSMarkus Pfeiffer &acpi_cdev) != AE_NOT_FOUND) { 325e3adcf8fSFrançois Tigeot if (i >= 8) { 326a2fdbec6SFrançois Tigeot device_printf(dev->dev, 327*5d0b1887SFrançois Tigeot "More than 8 outputs detected via ACPI\n"); 328e3adcf8fSFrançois Tigeot return; 329e3adcf8fSFrançois Tigeot } 33090c722cdSMarkus Pfeiffer status = acpi_GetInteger(acpi_cdev, "_ADR", &device_id); 331e3adcf8fSFrançois Tigeot if (ACPI_SUCCESS(status)) { 332e3adcf8fSFrançois Tigeot if (!device_id) 333e3adcf8fSFrançois Tigeot goto blind_set; 334a2fdbec6SFrançois Tigeot iowrite32((u32)(device_id & 0x0f0f), 335a2fdbec6SFrançois Tigeot &opregion->acpi->didl[i]); 336e3adcf8fSFrançois Tigeot i++; 337e3adcf8fSFrançois Tigeot } 338e3adcf8fSFrançois Tigeot } 339a2fdbec6SFrançois Tigeot 340e3adcf8fSFrançois Tigeot end: 341e3adcf8fSFrançois Tigeot /* If fewer than 8 outputs, the list must be null terminated */ 342e3adcf8fSFrançois Tigeot if (i < 8) 34300640ec9SFrançois Tigeot iowrite32(0, &opregion->acpi->didl[i]); 344e3adcf8fSFrançois Tigeot return; 345e3adcf8fSFrançois Tigeot 346e3adcf8fSFrançois Tigeot blind_set: 347e3adcf8fSFrançois Tigeot i = 0; 348e3adcf8fSFrançois Tigeot list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 349e3adcf8fSFrançois Tigeot int output_type = ACPI_OTHER_OUTPUT; 350e3adcf8fSFrançois Tigeot if (i >= 8) { 35190c722cdSMarkus Pfeiffer device_printf(dev->dev, 352*5d0b1887SFrançois Tigeot "More than 8 outputs in connector list\n"); 353e3adcf8fSFrançois Tigeot return; 354e3adcf8fSFrançois Tigeot } 355e3adcf8fSFrançois Tigeot switch (connector->connector_type) { 356e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_VGA: 357e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_DVIA: 358e3adcf8fSFrançois Tigeot output_type = ACPI_VGA_OUTPUT; 359e3adcf8fSFrançois Tigeot break; 360e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_Composite: 361e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_SVIDEO: 362e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_Component: 363e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_9PinDIN: 364e3adcf8fSFrançois Tigeot output_type = ACPI_TV_OUTPUT; 365e3adcf8fSFrançois Tigeot break; 366e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_DVII: 367e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_DVID: 368e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_DisplayPort: 369e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_HDMIA: 370e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_HDMIB: 371e3adcf8fSFrançois Tigeot output_type = ACPI_DIGITAL_OUTPUT; 372e3adcf8fSFrançois Tigeot break; 373e3adcf8fSFrançois Tigeot case DRM_MODE_CONNECTOR_LVDS: 374e3adcf8fSFrançois Tigeot output_type = ACPI_LVDS_OUTPUT; 375e3adcf8fSFrançois Tigeot break; 376e3adcf8fSFrançois Tigeot } 37700640ec9SFrançois Tigeot temp = ioread32(&opregion->acpi->didl[i]); 37800640ec9SFrançois Tigeot iowrite32(temp | (1<<31) | output_type | i, 37900640ec9SFrançois Tigeot &opregion->acpi->didl[i]); 380e3adcf8fSFrançois Tigeot i++; 381e3adcf8fSFrançois Tigeot } 382e3adcf8fSFrançois Tigeot goto end; 383e3adcf8fSFrançois Tigeot } 384e3adcf8fSFrançois Tigeot 38500640ec9SFrançois Tigeot static void intel_setup_cadls(struct drm_device *dev) 38600640ec9SFrançois Tigeot { 38700640ec9SFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 38800640ec9SFrançois Tigeot struct intel_opregion *opregion = &dev_priv->opregion; 38900640ec9SFrançois Tigeot int i = 0; 39000640ec9SFrançois Tigeot u32 disp_id; 39100640ec9SFrançois Tigeot 39200640ec9SFrançois Tigeot /* Initialize the CADL field by duplicating the DIDL values. 39300640ec9SFrançois Tigeot * Technically, this is not always correct as display outputs may exist, 39400640ec9SFrançois Tigeot * but not active. This initialization is necessary for some Clevo 39500640ec9SFrançois Tigeot * laptops that check this field before processing the brightness and 39600640ec9SFrançois Tigeot * display switching hotkeys. Just like DIDL, CADL is NULL-terminated if 39700640ec9SFrançois Tigeot * there are less than eight devices. */ 39800640ec9SFrançois Tigeot do { 39900640ec9SFrançois Tigeot disp_id = ioread32(&opregion->acpi->didl[i]); 40000640ec9SFrançois Tigeot iowrite32(disp_id, &opregion->acpi->cadl[i]); 40100640ec9SFrançois Tigeot } while (++i < 8 && disp_id != 0); 40200640ec9SFrançois Tigeot } 40300640ec9SFrançois Tigeot 404e3adcf8fSFrançois Tigeot void intel_opregion_init(struct drm_device *dev) 405e3adcf8fSFrançois Tigeot { 406e3adcf8fSFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 407e3adcf8fSFrançois Tigeot struct intel_opregion *opregion = &dev_priv->opregion; 408e3adcf8fSFrançois Tigeot 409e3adcf8fSFrançois Tigeot if (!opregion->header) 410e3adcf8fSFrançois Tigeot return; 411e3adcf8fSFrançois Tigeot 412e3adcf8fSFrançois Tigeot if (opregion->acpi) { 41300640ec9SFrançois Tigeot if (drm_core_check_feature(dev, DRIVER_MODESET)) { 414e3adcf8fSFrançois Tigeot intel_didl_outputs(dev); 41500640ec9SFrançois Tigeot intel_setup_cadls(dev); 41600640ec9SFrançois Tigeot } 417e3adcf8fSFrançois Tigeot 418e3adcf8fSFrançois Tigeot /* Notify BIOS we are ready to handle ACPI video ext notifs. 419e3adcf8fSFrançois Tigeot * Right now, all the events are handled by the ACPI video module. 420e3adcf8fSFrançois Tigeot * We don't actually need to do anything with them. */ 42100640ec9SFrançois Tigeot iowrite32(0, &opregion->acpi->csts); 42200640ec9SFrançois Tigeot iowrite32(1, &opregion->acpi->drdy); 423e3adcf8fSFrançois Tigeot 424e3adcf8fSFrançois Tigeot system_opregion = opregion; 425e3adcf8fSFrançois Tigeot } 426e3adcf8fSFrançois Tigeot 427*5d0b1887SFrançois Tigeot if (opregion->asle) { 428*5d0b1887SFrançois Tigeot iowrite32(ASLE_TCHE_BLC_EN, &opregion->asle->tche); 429*5d0b1887SFrançois Tigeot iowrite32(ASLE_ARDY_READY, &opregion->asle->ardy); 430*5d0b1887SFrançois Tigeot } 431e3adcf8fSFrançois Tigeot } 432e3adcf8fSFrançois Tigeot 433e3adcf8fSFrançois Tigeot void intel_opregion_fini(struct drm_device *dev) 434e3adcf8fSFrançois Tigeot { 435e3adcf8fSFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 436e3adcf8fSFrançois Tigeot struct intel_opregion *opregion = &dev_priv->opregion; 437e3adcf8fSFrançois Tigeot 438e3adcf8fSFrançois Tigeot if (!opregion->header) 439e3adcf8fSFrançois Tigeot return; 440e3adcf8fSFrançois Tigeot 441*5d0b1887SFrançois Tigeot if (opregion->asle) 442*5d0b1887SFrançois Tigeot iowrite32(ASLE_ARDY_NOT_READY, &opregion->asle->ardy); 443*5d0b1887SFrançois Tigeot 444e3adcf8fSFrançois Tigeot if (opregion->acpi) { 44500640ec9SFrançois Tigeot iowrite32(0, &opregion->acpi->drdy); 446e3adcf8fSFrançois Tigeot 447e3adcf8fSFrançois Tigeot system_opregion = NULL; 448e3adcf8fSFrançois Tigeot } 449e3adcf8fSFrançois Tigeot 450e3adcf8fSFrançois Tigeot /* just clear all opregion memory pointers now */ 45190c722cdSMarkus Pfeiffer pmap_unmapdev((vm_offset_t)opregion->header, OPREGION_SIZE); 452e3adcf8fSFrançois Tigeot opregion->header = NULL; 453e3adcf8fSFrançois Tigeot opregion->acpi = NULL; 454e3adcf8fSFrançois Tigeot opregion->swsci = NULL; 455e3adcf8fSFrançois Tigeot opregion->asle = NULL; 456e3adcf8fSFrançois Tigeot opregion->vbt = NULL; 457e3adcf8fSFrançois Tigeot } 458e3adcf8fSFrançois Tigeot 459e3adcf8fSFrançois Tigeot int intel_opregion_setup(struct drm_device *dev) 460e3adcf8fSFrançois Tigeot { 461e3adcf8fSFrançois Tigeot struct drm_i915_private *dev_priv = dev->dev_private; 462e3adcf8fSFrançois Tigeot struct intel_opregion *opregion = &dev_priv->opregion; 463e3adcf8fSFrançois Tigeot char *base; 464e3adcf8fSFrançois Tigeot u32 asls, mboxes; 46500640ec9SFrançois Tigeot char buf[sizeof(OPREGION_SIGNATURE)]; 466e3adcf8fSFrançois Tigeot int err = 0; 467e3adcf8fSFrançois Tigeot 468f0d07c12SFrançois Tigeot pci_read_config_dword(dev->pdev, PCI_ASLS, &asls); 46900640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("graphic opregion physical addr: 0x%x\n", asls); 470e3adcf8fSFrançois Tigeot if (asls == 0) { 47100640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("ACPI OpRegion not supported!\n"); 472e3adcf8fSFrançois Tigeot return -ENOTSUP; 473e3adcf8fSFrançois Tigeot } 474e3adcf8fSFrançois Tigeot 475e3adcf8fSFrançois Tigeot base = (void *)pmap_mapbios(asls, OPREGION_SIZE); 476e3adcf8fSFrançois Tigeot if (!base) 477e3adcf8fSFrançois Tigeot return -ENOMEM; 478e3adcf8fSFrançois Tigeot 47900640ec9SFrançois Tigeot memcpy_fromio(buf, base, sizeof(buf)); 48000640ec9SFrançois Tigeot 48100640ec9SFrançois Tigeot if (memcmp(buf, OPREGION_SIGNATURE, 16)) { 48200640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("opregion signature mismatch\n"); 483e3adcf8fSFrançois Tigeot err = -EINVAL; 484e3adcf8fSFrançois Tigeot goto err_out; 485e3adcf8fSFrançois Tigeot } 486e3adcf8fSFrançois Tigeot opregion->header = (struct opregion_header *)base; 487e3adcf8fSFrançois Tigeot opregion->vbt = base + OPREGION_VBT_OFFSET; 488e3adcf8fSFrançois Tigeot 489e3adcf8fSFrançois Tigeot opregion->lid_state = (u32 *)(base + ACPI_CLID); 490e3adcf8fSFrançois Tigeot 49100640ec9SFrançois Tigeot mboxes = ioread32(&opregion->header->mboxes); 492e3adcf8fSFrançois Tigeot if (mboxes & MBOX_ACPI) { 49300640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("Public ACPI methods supported\n"); 49400640ec9SFrançois Tigeot opregion->acpi = (struct opregion_acpi *)(base + OPREGION_ACPI_OFFSET); 495e3adcf8fSFrançois Tigeot } 496e3adcf8fSFrançois Tigeot 497e3adcf8fSFrançois Tigeot if (mboxes & MBOX_SWSCI) { 49800640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("SWSCI supported\n"); 49900640ec9SFrançois Tigeot opregion->swsci = (struct opregion_swsci *)(base + OPREGION_SWSCI_OFFSET); 500e3adcf8fSFrançois Tigeot } 501e3adcf8fSFrançois Tigeot if (mboxes & MBOX_ASLE) { 50200640ec9SFrançois Tigeot DRM_DEBUG_DRIVER("ASLE supported\n"); 50300640ec9SFrançois Tigeot opregion->asle = (struct opregion_asle *)(base + OPREGION_ASLE_OFFSET); 504*5d0b1887SFrançois Tigeot 505*5d0b1887SFrançois Tigeot iowrite32(ASLE_ARDY_NOT_READY, &opregion->asle->ardy); 506e3adcf8fSFrançois Tigeot } 507e3adcf8fSFrançois Tigeot 508e3adcf8fSFrançois Tigeot return 0; 509e3adcf8fSFrançois Tigeot 510e3adcf8fSFrançois Tigeot err_out: 511e3adcf8fSFrançois Tigeot pmap_unmapdev((vm_offset_t)base, OPREGION_SIZE); 512e3adcf8fSFrançois Tigeot return err; 513e3adcf8fSFrançois Tigeot } 514