Balázs Vinarz has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30988
Change subject: Little bit more helpful, giving back the lines for each file if any
......................................................................
Little bit more helpful, giving back the lines for each file if any
Change-Id: I8ae13f62c6e2cd87278fefab8de5faf0d1bc0a90
---
M util/lint/lint-stable-003-whitespace
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/88/30988/1
diff --git a/util/lint/lint-stable-003-whitespace b/util/lint/lint-stable-003-whitespace
index f9b7891..b2011e7 100755
--- a/util/lint/lint-stable-003-whitespace
+++ b/util/lint/lint-stable-003-whitespace
@@ -20,7 +20,7 @@
# shellcheck disable=SC2086,SC2046
if uname | grep -qi "linux"; then
- grep -l "[[:space:]][[:space:]]*$" \
+ grep -n -H "[[:space:]][[:space:]]*$" \
$(git ls-files $INCLUDELIST | \
grep -Ev "($EXCLUDELIST)" ) | \
sed -e "s,^.*$,File & has lines ending with whitespace.,"
--
To view, visit https://review.coreboot.org/c/coreboot/+/30988
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I8ae13f62c6e2cd87278fefab8de5faf0d1bc0a90
Gerrit-Change-Number: 30988
Gerrit-PatchSet: 1
Gerrit-Owner: Balázs Vinarz <vinibali1(a)gmail.com>
Gerrit-MessageType: newchange
Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31385
Change subject: util/spdtool: Add tool to extract SPD from BLOBs
......................................................................
util/spdtool: Add tool to extract SPD from BLOBs
Opens a binary file to extract DDR SPDs using known bits.
At the moment only DDR4 SPDs are supported.
Dumps the found SPDs into the current folder, as either
binary or hex encoded file.
Works with python2 and python3.
Change-Id: I26dd73d43b724ea6891bb5b6e96856c42db8577c
Signed-off-by: Patrick Rudolph <patrick.rudolph(a)9elements.com>
---
A util/spdtool/description.md
A util/spdtool/spdtool.py
2 files changed, 221 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/85/31385/1
diff --git a/util/spdtool/description.md b/util/spdtool/description.md
new file mode 100644
index 0000000..39d4a5c
--- /dev/null
+++ b/util/spdtool/description.md
@@ -0,0 +1,3 @@
+Dumps SPD ROMs from a given blob to seperate files using known patterns
+and reserved bits. Useful for analysing firmware that holds SPDs on boards
+that have soldered down DRAM. `python`
diff --git a/util/spdtool/spdtool.py b/util/spdtool/spdtool.py
new file mode 100644
index 0000000..c20ee57
--- /dev/null
+++ b/util/spdtool/spdtool.py
@@ -0,0 +1,218 @@
+#!/usr/bin/env python
+
+# spdtool - Tool for partial deblobbing of Intel ME/TXE firmware images
+# Copyright (C) 2019 9elements Agency GmbH <patrick.rudolph(a)9elements.com>
+#
+# 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 3 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.
+#
+#
+# Parse a BLOB and search for SPD files.
+# First it is searched for a possible SPD header.
+#
+# For each candidate the function verify_match is invoked to check
+# additional fields (known bits, reserved bits, CRC, ...)
+#
+# Dumps the found SPDs into the current folder.
+#
+# Implemented:
+# DDR4 SPDs
+#
+
+import argparse
+import crc16
+import struct
+
+class Parser(object):
+ def __init__(self, blob, verbose=False, ignorecrc=False):
+ self.blob = blob
+ self.ignorecrc = ignorecrc
+ self.verbose = verbose
+ def get_matches(self):
+ """Return the first byte to look for"""
+ raise Exception("Function not implemented")
+ def verify_match(self, header, offset):
+ """Return true if it looks like a SPD"""
+ raise Exception("Function not implemented")
+ def get_len(self, header, offset):
+ """Return the length of the SPD"""
+ raise Exception("Function not implemented")
+ def get_part_number(self, offset):
+ """Return the part number in SPD"""
+ return ""
+ def get_manufacturer_id(self, offset):
+ """Return the manufacturer ID in SPD"""
+ return 0xffff
+ def get_mtransfers(self, offset):
+ """Return the number of MT/s"""
+ return 0
+
+ def get_manufacturer(self, offset):
+ """Return manufacturer as string"""
+ id = self.get_manufacturer_id(offset)
+ if id == 0xffff:
+ return "Unknown"
+ ids = {
+ 0x2c80: "Crucial/Micron",
+ 0x4304: "Ramaxel",
+ 0x4f01: "Transcend",
+ 0x9801: "Kingston",
+ 0x987f: "Hynix",
+ 0x9e02: "Corsair",
+ 0xb004: "OCZ",
+ 0xad80: "Hynix/Hyundai",
+ 0xb502: "SuperTalent",
+ 0xcd04: "GSkill",
+ 0xce80: "Samsung",
+ 0xfe02: "Elpida",
+ 0xff2c: "Micron",
+ }
+ if id in ids:
+ return ids[id]
+ return "Unknown"
+
+ def blob_as_ord(self, offset):
+ """Helper for python2/python3 compability"""
+ return self.blob[offset] if type(self.blob[offset]) is int else ord(self.blob[offset])
+
+ def search(self, start):
+ """Search for SPD at start. Returns -1 on error or offset
+ if found.
+ """
+ for i in self.get_matches():
+ for offset in range(start, len(self.blob)):
+ if self.blob_as_ord(offset) != i:
+ continue
+ if not self.verify_match(i, offset):
+ continue
+ return offset, self.get_len(i, offset)
+ return -1, 0
+
+class SPD4Parser(Parser):
+ def get_matches(self):
+ """Return DDR4 possible header candidates"""
+ ret = []
+ for i in [1, 2, 3, 4]:
+ for j in [1, 2]:
+ ret.append(i + j * 16)
+ return ret
+
+ def verify_match(self, header, offset):
+ """Verify DDR4 specific bit fields."""
+ # offset 0 is a candidate, no need to validate
+ if self.blob_as_ord(offset + 1) == 0xff:
+ return False
+ if self.blob_as_ord(offset + 2) != 0x0c:
+ return False
+ if self.blob_as_ord(offset + 5) & 0xc0 > 0:
+ return False
+ if self.blob_as_ord(offset + 6) & 0xc > 0:
+ return False
+ if self.blob_as_ord(offset + 7) & 0xc0 > 0:
+ return False
+ if self.blob_as_ord(offset + 8) != 0:
+ return False
+ if self.blob_as_ord(offset + 9) & 0xf > 0:
+ return False
+ if self.verbose:
+ print("%x: Looks like DDR4 SPD" % offset)
+
+ crc = crc16.crc16xmodem(self.blob[offset:offset + 0x7d + 1])
+ # Vendors ignore the endianness...
+ crc_spd1 = self.blob_as_ord(offset + 0x7f) | (self.blob_as_ord(offset + 0x7e) << 8)
+ crc_spd2 = self.blob_as_ord(offset + 0x7e) | (self.blob_as_ord(offset + 0x7f) << 8)
+ if crc != crc_spd1 and crc != crc_spd2:
+ if self.verbose:
+ print("%x: CRC16 doesn't match" % offset)
+ if not self.ignorecrc:
+ return False
+
+ return True
+
+ def get_len(self, header, offset):
+ """Return the length of the SPD found."""
+ if (header >> 4) & 7 == 1:
+ return 256
+ if (header >> 4) & 7 == 2:
+ return 512
+ return 0
+
+ def get_part_number(self, offset):
+ """Return part number as string"""
+ if offset + 0x15c > len(self.blob):
+ return ""
+ return self.blob[offset + 0x149:offset + 0x15c + 1].decode('utf-8').rstrip()
+
+ def get_manufacturer_id(self, offset):
+ """Return manufacturer ID"""
+ if offset + 0x141 > len(self.blob):
+ return 0xffff
+ return struct.unpack('H', self.blob[offset + 0x140:offset + 0x141 + 1])[0]
+
+ def get_mtransfers(self, offset):
+ """Return MT/s as specified by MTB and FTB"""
+ if offset + 0x7d > len(self.blob):
+ return 0
+
+ if self.blob_as_ord(offset + 0x11) != 0:
+ return 0
+ mtb = 8.0
+ ftb = 1000.0
+ tckm = struct.unpack('B', self.blob[offset + 0x12:offset + 0x12 + 1])[0]
+ tckf = struct.unpack('b', self.blob[offset + 0x7d:offset + 0x7d + 1])[0]
+ return int(2000 / (tckm / mtb + tckf / ftb))
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='SPD rom dumper')
+ parser.add_argument('--blob', required=True,
+ help='The ROM to search SPDs in.')
+ parser.add_argument('--spd4', action='store_true', default=False,
+ help='Search for DDR4 SPDs.')
+ parser.add_argument('--hex', action='store_true', default=False,
+ help='Store SPD in hex format otherwise binary.')
+ parser.add_argument('-v', '--verbose', help='increase output verbosity',
+ action='store_true')
+ parser.add_argument('--ignorecrc', help='Ignore CRC missmatch',
+ action='store_true', default=False)
+ args = parser.parse_args()
+
+ blob = open(args.blob, "rb").read()
+
+ if args.spd4:
+ p = SPD4Parser(blob, args.verbose, args.ignorecrc)
+ else:
+ raise Exception("Must specify one of the following arguments:\n--spd4")
+
+ offset = 0
+ length = 0
+ cnt = 0
+ while True:
+ offset, length = p.search(offset)
+ if length == 0:
+ break
+ print("Found SPD at 0x%x" % offset)
+ print(" '%s', size %d, manufacturer %s (0x%04x) %d MT/s\n" %
+ (p.get_part_number(offset), length, p.get_manufacturer(offset),
+ p.get_manufacturer_id(offset), p.get_mtransfers(offset)))
+ filename = "spd-%d-%s-%s.bin" % (cnt, p.get_part_number(offset),
+ p.get_manufacturer(offset))
+ filename = filename.replace("/", "_")
+ filename = "".join([c for c in filename if c.isalpha() or c.isdigit() or c=='-' or c=='.' or c=='_']).rstrip()
+ if not args.hex:
+ open(filename, "wb").write(blob[offset:offset + length])
+ else:
+ filename += ".hex"
+ fn = open(filename, "w")
+ j = 0
+ for i in blob[offset:offset + length]:
+ fn.write("%02X%s" % (struct.unpack('B',i)[0], " " if j < 15 else "\n"))
+ j = (j + 1) % 16
+ offset += 1
+ cnt += 1
--
To view, visit https://review.coreboot.org/c/coreboot/+/31385
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I26dd73d43b724ea6891bb5b6e96856c42db8577c
Gerrit-Change-Number: 31385
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph(a)9elements.com>
Gerrit-MessageType: newchange
Patrick Georgi has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30964
Change subject: soc/qualcomm/qcs405: Define a Kconfig variable that the code is missing
......................................................................
soc/qualcomm/qcs405: Define a Kconfig variable that the code is missing
It's used in the code but never defined, which trips up the linter.
We need to sort it out before the patch train gets in, but until then,
the linter is mostly creating noise.
Change-Id: Ib04d5b6d2cb03cc8ee6ef0275e1b201c0fc9eb6d
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
M src/soc/qualcomm/qcs405/Kconfig
1 file changed, 7 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/64/30964/1
diff --git a/src/soc/qualcomm/qcs405/Kconfig b/src/soc/qualcomm/qcs405/Kconfig
index b24dc9e..ea1cee4 100644
--- a/src/soc/qualcomm/qcs405/Kconfig
+++ b/src/soc/qualcomm/qcs405/Kconfig
@@ -21,6 +21,13 @@
select VBOOT_OPROM_MATTERS
select VBOOT_STARTS_IN_BOOTBLOCK
+config QC_SDI_ENABLE
+ bool
+ default n
+ help
+ dummy entry because that variable isn't _really_ used yet.
+ todo(pgeorgi): check if used before merging
+
config QC_SOC_SIMULATE
bool
prompt "Build for Early Simulation Environment"
--
To view, visit https://review.coreboot.org/c/coreboot/+/30964
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ib04d5b6d2cb03cc8ee6ef0275e1b201c0fc9eb6d
Gerrit-Change-Number: 30964
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-MessageType: newchange
Duncan Laurie has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31440
Change subject: soc/intel/common: Add DP AUX channel control register bits
......................................................................
soc/intel/common: Add DP AUX channel control register bits
This change implements the SOC-specific function for providing the
DP AUX channel control register bits.
All of the recent Intel SOCs supported by soc/intel/common use the
same format for this register.
Change-Id: I95b75078f907da7df30bda2b3468668a2f0d7a47
Signed-off-by: Duncan Laurie <dlaurie(a)google.com>
---
M src/drivers/intel/gma/i915_reg.h
M src/soc/intel/common/block/graphics/graphics.c
2 files changed, 14 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/31440/1
diff --git a/src/drivers/intel/gma/i915_reg.h b/src/drivers/intel/gma/i915_reg.h
index e0bf142..f32f0cd 100644
--- a/src/drivers/intel/gma/i915_reg.h
+++ b/src/drivers/intel/gma/i915_reg.h
@@ -2323,6 +2323,10 @@
#define DP_AUX_CH_CTL_BIT_CLOCK_2X_MASK (0x7ff)
#define DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT 0
+/* Used by Sky Lake and later SOC */
+#define DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(c) (((c) - 1) << 5)
+#define DP_AUX_CH_CTL_SYNC_PULSE_SKL(c) ((c) - 1)
+
/*
* Computing GMCH M and N values for the Display Port link
*
diff --git a/src/soc/intel/common/block/graphics/graphics.c b/src/soc/intel/common/block/graphics/graphics.c
index 19a78e7..a8c93ec 100644
--- a/src/soc/intel/common/block/graphics/graphics.c
+++ b/src/soc/intel/common/block/graphics/graphics.c
@@ -20,6 +20,7 @@
#include <device/pci_ids.h>
#include <intelblocks/graphics.h>
#include <soc/pci_devs.h>
+#include <drivers/intel/gma/i915.h>
/* SoC Overrides */
__weak void graphics_soc_init(struct device *dev)
@@ -96,11 +97,20 @@
graphics_gtt_write(reg, val);
}
+/* Return the SOC-specific bits of the AUX channel control register */
+uint32_t intel_dp_aux_ctl_soc(void)
+{
+ /* Currently all SOCs supported here use the gen9+ register format */
+ return DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
+ DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
+}
+
static const struct device_operations graphics_ops = {
.read_resources = pci_dev_read_resources,
.set_resources = pci_dev_set_resources,
.enable_resources = pci_dev_enable_resources,
.init = graphics_soc_init,
+ .ops_i2c_bus = &intel_edp_aux_i2c_bus_ops,
.ops_pci = &pci_dev_ops_pci,
.write_acpi_tables = graphics_soc_write_acpi_opregion,
};
--
To view, visit https://review.coreboot.org/c/coreboot/+/31440
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I95b75078f907da7df30bda2b3468668a2f0d7a47
Gerrit-Change-Number: 31440
Gerrit-PatchSet: 1
Gerrit-Owner: Duncan Laurie <dlaurie(a)chromium.org>
Gerrit-MessageType: newchange
Duncan Laurie has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31439
Change subject: drivers/intel/gma: Add DP AUX interface and I2C bus
......................................................................
drivers/intel/gma: Add DP AUX interface and I2C bus
In order to support reading the EDID of the internal panel this
driver ports the kernel i915 Display Port AUX channel protocol
and provides an I2C bus interface to it.
A helper function is also provided for reading the EDID at the
common I2C slave address.
The bottom word of the AUX channel control register contains
SOC-specific bits which are implemented for soc/intel/common in
a subsequent commit.
Change-Id: I4aa7e687aea397d6d70c0398e0f6958611db6410
Signed-off-by: Duncan Laurie <dlaurie(a)google.com>
---
M src/drivers/intel/gma/Kconfig
M src/drivers/intel/gma/Makefile.inc
M src/drivers/intel/gma/i915.h
A src/drivers/intel/gma/intel_dp_aux.c
4 files changed, 386 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/39/31439/1
diff --git a/src/drivers/intel/gma/Kconfig b/src/drivers/intel/gma/Kconfig
index a5c8495..63ca09f 100644
--- a/src/drivers/intel/gma/Kconfig
+++ b/src/drivers/intel/gma/Kconfig
@@ -32,6 +32,13 @@
bool
default n
+config INTEL_DP_AUX
+ bool
+ default n
+ help
+ Select this option to enable the AUX channel driver which provides
+ an I2C bus for reading the EDID from the eDP port.
+
config INTEL_GMA_SSC_ALTERNATE_REF
bool
default n
diff --git a/src/drivers/intel/gma/Makefile.inc b/src/drivers/intel/gma/Makefile.inc
index 274955a..5a5fb8d 100644
--- a/src/drivers/intel/gma/Makefile.inc
+++ b/src/drivers/intel/gma/Makefile.inc
@@ -13,6 +13,7 @@
## GNU General Public License for more details.
##
+ramstage-$(CONFIG_INTEL_DP_AUX) += intel_dp_aux.c
ramstage-$(CONFIG_INTEL_DDI) += intel_ddi.c
ramstage-$(CONFIG_INTEL_EDID) += edid.c vbt.c
ifeq ($(CONFIG_VGA_ROM_RUN),y)
diff --git a/src/drivers/intel/gma/i915.h b/src/drivers/intel/gma/i915.h
index 0ddb2de..de56076 100644
--- a/src/drivers/intel/gma/i915.h
+++ b/src/drivers/intel/gma/i915.h
@@ -107,4 +107,53 @@
generate_fake_intel_oprom(const struct i915_gpu_controller_info *conf,
struct device *dev, const char *idstr);
+/* intel_dp_aux.c */
+
+/**
+ * enum dp_aux_ch - Available AUX channels.
+ */
+enum dp_aux_ch {
+ AUX_CH_EDP,
+ AUX_CH_DDI1,
+ AUX_CH_DDI2,
+ AUX_CH_DDI3,
+};
+
+/**
+ * intel_dp_aux_ctl_soc() - Retrieve SOC specific bits for AUX control.
+ *
+ * Return: Mask of bits to set in AUX control register.
+ */
+uint32_t intel_dp_aux_ctl_soc(void);
+
+/**
+ * intel_dp_aux_ch() - Execute a DP AUX transaction.
+ * @dev: Graphics device.
+ * @aux_ch: Port for this transaction from %dp_aux_ch.
+ * @send_buf: Transmit data buffer.
+ * @send_bytes: Number of bytes to send.
+ * @recv_buf: Receive data buffer.
+ * @recv_size: Size of receive data buffer.
+ *
+ * Return: number of bytes received, or negative error code.
+ */
+ssize_t intel_dp_aux_ch(struct device *dev, enum dp_aux_ch aux_ch,
+ uint8_t *send_buf, size_t send_bytes,
+ uint8_t *recv_buf, size_t recv_size);
+
+/**
+ * intel_edp_aux_edid() - Read EDID from eDP AUX channel.
+ * @dev: Graphics device.
+ * @buf: Buffer to store EDID.
+ * @len: Size of provided buffer.
+ *
+ * Return: 0 to indicate success, negative error code on failure.
+ */
+int intel_edp_aux_edid(struct device *dev, uint8_t *buf, size_t len);
+
+
+/* I2C controller for eDP AUX channel */
+struct i2c_bus_operations;
+extern const struct i2c_bus_operations intel_edp_aux_i2c_bus_ops;
+
#endif
diff --git a/src/drivers/intel/gma/intel_dp_aux.c b/src/drivers/intel/gma/intel_dp_aux.c
new file mode 100644
index 0000000..906ce0e
--- /dev/null
+++ b/src/drivers/intel/gma/intel_dp_aux.c
@@ -0,0 +1,329 @@
+/*
+ * Copyright 2008 Intel Corporation
+ * Copyright 2019 Google LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Keith Packard <keithp(a)keithp.com>
+ */
+
+/*
+ * This driver implements a Display Port AUX channel interface for the Intel
+ * i915 GPU. This work is based on the kernel i915 driver. There are SOC
+ * specific bits in part of the AUX channel control register, and this driver
+ * expects the SOC to implement a function to fill out those bits properly.
+ *
+ * An I2C controller driver is created that allows tunneling I2C traffic over
+ * the AUX channel for the eDP port. This allows reading the built-in panel
+ * EDID and a helper function is added to do that using the common EDID I2C
+ * slave address.
+ *
+ * The AUX channel interface does require the panel power to be enabled
+ * previously by coreboot or FSP. FSP will turn on the panel power it if
+ * the UPD for PanelPowerEnable is set (which is the default) or if the GOP
+ * driver is executed.
+ */
+
+#include <console/console.h>
+#include <delay.h>
+#include <device/i2c_bus.h>
+#include <device/pci.h>
+#include <device/resource.h>
+#include <drivers/intel/gma/i915.h>
+#include <drivers/intel/gma/i915_reg.h>
+#include <drivers/intel/gma/drm_dp_helper.h>
+#include <stdint.h>
+#include <string.h>
+#include <timer.h>
+
+/**
+ * enum intel_dp_aux_info - Intel DP AUX driver information.
+ * @DP_AUX_RETRY: Number of retry attempts. Minimum in DP spec is 3.
+ * @DP_AUX_HEADER_SIZE: Number of bytes in transaction header.
+ * @DP_AUX_I2C_SLAVE_EDID: Common I2C slave address for EDID.
+ * @DP_AUX_SEND_BUSY_TIMEOUT: Time in milliseconds to wait for completion.
+ * @DP_AUX_DATA_REG_COUNT: Number of data registers in each channel.
+ * @DP_AUX_DATA_REG_SIZE: Total size of data registers including header.
+ * @DP_AUX_DATA_XFER_MAX: Maximum number of data bytes in a transaction.
+ */
+enum intel_dp_aux_info {
+ DP_AUX_RETRY = 5,
+ DP_AUX_HEADER_SIZE = 4,
+ DP_AUX_I2C_SLAVE_EDID = 0x50,
+ DP_AUX_SEND_BUSY_TIMEOUT_MS = 1000,
+ DP_AUX_DATA_REG_COUNT = 5,
+ DP_AUX_DATA_REG_SIZE = DP_AUX_DATA_REG_COUNT * sizeof(uint32_t),
+ DP_AUX_DATA_XFER_MAX = DP_AUX_DATA_REG_SIZE - DP_AUX_HEADER_SIZE,
+};
+
+/**
+ * enum intel_dp_aux_type - AUX channel transaction type.
+ * @AUX_TYPE_I2C_WRITE: I2C write transaction.
+ * @AUX_TYPE_I2C_READ: I2C read transaction.
+ */
+enum intel_dp_aux_type {
+ AUX_TYPE_I2C_WRITE,
+ AUX_TYPE_I2C_READ,
+};
+
+/* Map AUX channel to control register. */
+static uint32_t dp_aux_ch_ctl[] = {
+ [AUX_CH_EDP] = DPA_AUX_CH_CTL,
+ [AUX_CH_DDI1] = DPB_AUX_CH_CTL,
+ [AUX_CH_DDI2] = DPC_AUX_CH_CTL,
+ [AUX_CH_DDI3] = DPD_AUX_CH_CTL,
+};
+
+/* Map AUX channel to data register start. */
+static uint32_t dp_aux_ch_data[] = {
+ [AUX_CH_EDP] = DPA_AUX_CH_DATA1,
+ [AUX_CH_DDI1] = DPB_AUX_CH_DATA1,
+ [AUX_CH_DDI2] = DPC_AUX_CH_DATA1,
+ [AUX_CH_DDI3] = DPD_AUX_CH_DATA1,
+};
+
+/* Store the base address of the GMA region. */
+static uintptr_t base_address;
+
+__weak uint32_t intel_dp_aux_ctl_soc(void)
+{
+ return 0;
+}
+
+static uint32_t i915_read32(uint32_t reg)
+{
+ return read32((void *)(base_address + reg));
+}
+
+static void i915_write32(uint32_t reg, uint32_t val)
+{
+ write32((void *)(base_address + reg), val);
+}
+
+static uint32_t pack_aux(uint8_t *src, size_t src_bytes)
+{
+ uint32_t v = 0;
+ size_t i;
+
+ if (src_bytes > 4)
+ src_bytes = 4;
+ for (i = 0; i < src_bytes; i++)
+ v |= ((uint32_t) src[i]) << ((3 - i) * 8);
+ return v;
+}
+
+static void unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
+{
+ size_t i;
+
+ if (dst_bytes > 4)
+ dst_bytes = 4;
+ for (i = 0; i < dst_bytes; i++)
+ dst[i] = src >> ((3 - i) * 8);
+}
+
+static int intel_dp_wait_busy(enum dp_aux_ch aux_ch)
+{
+ uint32_t status;
+ struct stopwatch sw;
+
+ stopwatch_init_msecs_expire(&sw, DP_AUX_SEND_BUSY_TIMEOUT_MS);
+ do {
+ status = i915_read32(dp_aux_ch_ctl[aux_ch]);
+ if (!(status & DP_AUX_CH_CTL_SEND_BUSY))
+ break;
+ mdelay(1);
+ } while (!stopwatch_expired(&sw));
+
+ return status;
+}
+
+ssize_t intel_dp_aux_ch(struct device *dev, enum dp_aux_ch aux_ch,
+ uint8_t *send_buf, size_t send_bytes,
+ uint8_t *recv_buf, size_t recv_size)
+{
+ size_t recv_bytes, try, i;
+ uint32_t status = 0;
+
+ /* Initialize base address */
+ if (!base_address) {
+ struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ base_address = (uintptr_t)res->base;
+ }
+
+ /* Try to wait for any previous AUX channel activity */
+ for (try = 0; try < DP_AUX_RETRY; try++) {
+ status = intel_dp_wait_busy(aux_ch);
+ if (!(status & DP_AUX_CH_CTL_SEND_BUSY))
+ break;
+ }
+ if (try == DP_AUX_RETRY) {
+ printk(BIOS_DEBUG, "%s: not started status 0x%08x\n",
+ __func__, status);
+ return -1;
+ }
+
+ /* Must try at least 3 times according to DP spec */
+ for (try = 0; try < DP_AUX_RETRY; try++) {
+ /* Load the send data into the aux channel data registers */
+ for (i = 0; i < send_bytes; i += 4)
+ i915_write32(dp_aux_ch_data[aux_ch] + i,
+ pack_aux(send_buf + i, send_bytes - i));
+
+ /* Send the command and wait for it to complete */
+ i915_write32(dp_aux_ch_ctl[aux_ch],
+ intel_dp_aux_ctl_soc() | /* SOC specific bits */
+ DP_AUX_CH_CTL_SEND_BUSY |
+ DP_AUX_CH_CTL_TIME_OUT_1600us |
+ DP_AUX_CH_CTL_DONE |
+ DP_AUX_CH_CTL_TIME_OUT_ERROR |
+ DP_AUX_CH_CTL_RECEIVE_ERROR |
+ (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT));
+
+ status = intel_dp_wait_busy(aux_ch);
+ if (status & DP_AUX_CH_CTL_SEND_BUSY)
+ continue;
+
+ /* Clear done status and any errors */
+ i915_write32(dp_aux_ch_ctl[aux_ch],
+ status |
+ DP_AUX_CH_CTL_DONE |
+ DP_AUX_CH_CTL_TIME_OUT_ERROR |
+ DP_AUX_CH_CTL_RECEIVE_ERROR);
+
+ if (status & DP_AUX_CH_CTL_DONE)
+ break;
+ if (status & DP_AUX_CH_CTL_RECEIVE_ERROR)
+ udelay(500);
+ }
+
+ if ((status & DP_AUX_CH_CTL_DONE) == 0) {
+ printk(BIOS_DEBUG, "%s: not done status 0x%08x\n",
+ __func__, status);
+ return -1;
+ }
+ if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
+ printk(BIOS_DEBUG, "%s: receive error status 0x%08x\n",
+ __func__, status);
+ return -1;
+ }
+ if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
+ printk(BIOS_DEBUG, "%s: timeout status 0x%08x\n",
+ __func__, status);
+ return -1;
+ }
+
+ /* Unload any bytes sent back from the other side */
+ recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
+ DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
+ if (recv_bytes > recv_size)
+ recv_bytes = recv_size;
+
+ for (i = 0; i < recv_bytes; i += 4)
+ unpack_aux(i915_read32(dp_aux_ch_data[aux_ch] + i),
+ recv_buf + i, recv_bytes - i);
+
+ return recv_bytes;
+}
+
+static ssize_t intel_dp_aux_i2c_transfer(struct device *dev,
+ enum dp_aux_ch aux_ch,
+ const struct i2c_msg *msg,
+ size_t offset, size_t len)
+{
+ uint8_t txbuf[DP_AUX_DATA_REG_SIZE] = {};
+ uint8_t rxbuf[DP_AUX_DATA_REG_SIZE] = {};
+ uint8_t type;
+ size_t txsize, rxsize;
+ ssize_t bytes;
+
+ if (!len)
+ return -1;
+
+ if (msg->flags & I2C_M_RD) {
+ type = AUX_TYPE_I2C_READ;
+ txsize = DP_AUX_HEADER_SIZE;
+ rxsize = len + 1;
+ } else {
+ type = AUX_TYPE_I2C_WRITE;
+ txsize = DP_AUX_HEADER_SIZE + len;
+ rxsize = 2;
+ memcpy(txbuf + DP_AUX_HEADER_SIZE, msg->buf + offset, len);
+ }
+
+ /* Fill DP AUX header */
+ txbuf[0] = (type << 4) | ((msg->slave >> 16) & 0xf);
+ txbuf[1] = (msg->slave >> 8) & 0xff;
+ txbuf[2] = msg->slave & 0xff;
+ txbuf[3] = len - 1;
+
+ bytes = intel_dp_aux_ch(dev, aux_ch, txbuf, txsize, rxbuf, rxsize);
+ if (bytes > 0 && msg->flags & I2C_M_RD)
+ memcpy(msg->buf + offset, rxbuf + 1, bytes - 1);
+
+ return bytes;
+}
+
+static int intel_edp_aux_i2c(struct device *dev, const struct i2c_msg *msg,
+ size_t count)
+{
+ /* Split different messages into separate transactions */
+ while (count--) {
+ size_t offset = 0;
+
+ /* Split into chunks to fit in available data registers */
+ while (offset < msg->len) {
+ size_t txlen = MIN(msg->len - offset,
+ DP_AUX_DATA_XFER_MAX);
+
+ if (intel_dp_aux_i2c_transfer(dev, AUX_CH_EDP,
+ msg, offset, txlen) < 0)
+ return -1;
+
+ offset += txlen;
+ }
+ msg++;
+ }
+ return 0;
+}
+
+const struct i2c_bus_operations intel_edp_aux_i2c_bus_ops = {
+ .transfer = intel_edp_aux_i2c
+};
+
+int intel_edp_aux_edid(struct device *dev, uint8_t *buf, size_t len)
+{
+ uint8_t start = 0;
+ struct i2c_msg msgs[] = {
+ {
+ .slave = DP_AUX_I2C_SLAVE_EDID,
+ .len = sizeof(start),
+ .buf = &start
+ }, {
+ .slave = DP_AUX_I2C_SLAVE_EDID,
+ .flags = I2C_M_RD,
+ .len = len,
+ .buf = buf
+ }
+ };
+
+ return intel_edp_aux_i2c(dev, msgs, ARRAY_SIZE(msgs));
+}
--
To view, visit https://review.coreboot.org/c/coreboot/+/31439
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I4aa7e687aea397d6d70c0398e0f6958611db6410
Gerrit-Change-Number: 31439
Gerrit-PatchSet: 1
Gerrit-Owner: Duncan Laurie <dlaurie(a)chromium.org>
Gerrit-MessageType: newchange