| /* |
| * Copyright 2016 Google Inc. |
| * |
| * See file CREDITS for list of people who contributed to this |
| * project. |
| * |
| * This program is free software; you can redistribute it and/or |
| * modify it under the terms of the GNU General Public License as |
| * published by the Free Software Foundation; either version 2 of |
| * the License, or (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but without any warranty; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| * MA 02111-1307 USA |
| */ |
| |
| #include "base/io.h" |
| #include "base/container_of.h" |
| #include "base/xalloc.h" |
| #include "drivers/framebuffer/intel_i915.h" |
| |
| enum { |
| BlcPchPwmCtl1Offset = 0xc8250, |
| BlcPchPwmEnable = 1 << 31, |
| }; |
| |
| static int intel_i915_framebuffer_prepare(FrameBufferOps *me, FrameBuffer *buf) |
| { |
| IntelI915Framebuffer *fb = container_of(me, IntelI915Framebuffer, ops); |
| |
| if (!fb->base) |
| fb->base = pci_read_config32(fb->bdf, PciConfBar0) & ~0xf; |
| |
| return framebuffer_read_from_fwdb(buf); |
| } |
| |
| static int intel_i915_framebuffer_backlight_set(GpioOps *me, unsigned enable) |
| { |
| IntelI915Framebuffer *fb = |
| container_of(me, IntelI915Framebuffer, backlight); |
| |
| uint32_t *blc = (uint32_t *)(fb->base + BlcPchPwmCtl1Offset); |
| |
| uint32_t old_val = read32(blc); |
| uint32_t new_val = enable ? (old_val | BlcPchPwmEnable) : |
| (old_val & ~BlcPchPwmEnable); |
| |
| if (old_val != new_val) |
| write32(blc, new_val); |
| |
| return 0; |
| } |
| |
| IntelI915Framebuffer *new_intel_i915_framebuffer(pcidev_t bdf) |
| { |
| IntelI915Framebuffer *fb = xzalloc(sizeof(*fb)); |
| |
| fb->ops.prepare = &intel_i915_framebuffer_prepare; |
| |
| fb->backlight.set = &intel_i915_framebuffer_backlight_set; |
| |
| fb->bdf = bdf; |
| |
| return fb; |
| } |