Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2016 Google Inc. |
Mario Scheithauer | 480eab0 | 2017-02-16 13:39:16 +0100 | [diff] [blame] | 5 | * Copyright (C) 2017 Siemens AG |
Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
Mario Scheithauer | 956a9f6 | 2017-03-29 17:09:37 +0200 | [diff] [blame^] | 17 | #include <device/pci.h> |
Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 18 | #include <device/device.h> |
Mario Scheithauer | 480eab0 | 2017-02-16 13:39:16 +0100 | [diff] [blame] | 19 | #include <console/console.h> |
Mario Scheithauer | 956a9f6 | 2017-03-29 17:09:37 +0200 | [diff] [blame^] | 20 | #include <soc/pci_devs.h> |
Mario Scheithauer | 480eab0 | 2017-02-16 13:39:16 +0100 | [diff] [blame] | 21 | #include <string.h> |
| 22 | #include <hwilib.h> |
| 23 | #include <i210.h> |
Mario Scheithauer | 2d98120 | 2017-03-27 13:25:57 +0200 | [diff] [blame] | 24 | #include "brd_gpio.h" |
Mario Scheithauer | 956a9f6 | 2017-03-29 17:09:37 +0200 | [diff] [blame^] | 25 | #include "ptn3460.h" |
Mario Scheithauer | 480eab0 | 2017-02-16 13:39:16 +0100 | [diff] [blame] | 26 | |
| 27 | #define MAX_PATH_DEPTH 12 |
| 28 | #define MAX_NUM_MAPPINGS 10 |
| 29 | |
| 30 | /** \brief This function can decide if a given MAC address is valid or not. |
| 31 | * Currently, addresses filled with 0xff or 0x00 are not valid. |
| 32 | * @param mac Buffer to the MAC address to check |
| 33 | * @return 0 if address is not valid, otherwise 1 |
| 34 | */ |
| 35 | static uint8_t is_mac_adr_valid(uint8_t mac[6]) |
| 36 | { |
| 37 | uint8_t buf[6]; |
| 38 | |
| 39 | memset(buf, 0, sizeof(buf)); |
| 40 | if (!memcmp(buf, mac, sizeof(buf))) |
| 41 | return 0; |
| 42 | memset(buf, 0xff, sizeof(buf)); |
| 43 | if (!memcmp(buf, mac, sizeof(buf))) |
| 44 | return 0; |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | /** \brief This function will search for a MAC address which can be assigned |
| 49 | * to a MACPHY. |
| 50 | * @param dev pointer to PCI device |
| 51 | * @param mac buffer where to store the MAC address |
| 52 | * @return cb_err CB_ERR or CB_SUCCESS |
| 53 | */ |
| 54 | enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[6]) |
| 55 | { |
| 56 | struct bus *parent = dev->bus; |
| 57 | uint8_t buf[16], mapping[16], i = 0, chain_len = 0; |
| 58 | |
| 59 | memset(buf, 0, sizeof(buf)); |
| 60 | memset(mapping, 0, sizeof(mapping)); |
| 61 | |
| 62 | /* The first entry in the tree is the device itself. */ |
| 63 | buf[0] = dev->path.pci.devfn; |
| 64 | chain_len = 1; |
| 65 | for (i = 1; i < MAX_PATH_DEPTH && parent->dev->bus->subordinate; i++) { |
| 66 | buf[i] = parent->dev->path.pci.devfn; |
| 67 | chain_len++; |
| 68 | parent = parent->dev->bus; |
| 69 | } |
| 70 | if (i == MAX_PATH_DEPTH) { |
| 71 | /* The path is deeper than MAX_PATH_DEPTH devices, error. */ |
| 72 | printk(BIOS_ERR, "Too many bridges for %s\n", dev_path(dev)); |
| 73 | return CB_ERR; |
| 74 | } |
| 75 | /* |
| 76 | * Now construct the mapping based on the device chain starting from |
| 77 | * root bridge device to the device itself. |
| 78 | */ |
| 79 | mapping[0] = 1; |
| 80 | mapping[1] = chain_len; |
| 81 | for (i = 0; i < chain_len; i++) |
| 82 | mapping[i + 4] = buf[chain_len - i - 1]; |
| 83 | |
| 84 | /* Open main hwinfo block */ |
| 85 | if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 86 | return CB_ERR; |
| 87 | /* Now try to find a valid MAC address in hwinfo for this mapping.*/ |
| 88 | for (i = 0; i < MAX_NUM_MAPPINGS; i++) { |
| 89 | if ((hwilib_get_field(XMac1Mapping + i, buf, 16) == 16) && |
| 90 | !(memcmp(buf, mapping, chain_len + 4))) { |
| 91 | /* There is a matching mapping available, get MAC address. */ |
| 92 | if ((hwilib_get_field(XMac1 + i, mac, 6) == 6) && |
| 93 | (is_mac_adr_valid(mac))) { |
| 94 | return CB_SUCCESS; |
| 95 | } else { |
| 96 | return CB_ERR; |
| 97 | } |
| 98 | } else |
| 99 | continue; |
| 100 | } |
| 101 | /* No MAC address found for */ |
| 102 | return CB_ERR; |
| 103 | } |
Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 104 | |
| 105 | static void mainboard_init(void *chip_info) |
| 106 | { |
Mario Scheithauer | 2d98120 | 2017-03-27 13:25:57 +0200 | [diff] [blame] | 107 | const struct pad_config *pads; |
| 108 | size_t num; |
| 109 | |
| 110 | pads = brd_gpio_table(&num); |
| 111 | gpio_configure_pads(pads, num); |
Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Mario Scheithauer | 956a9f6 | 2017-03-29 17:09:37 +0200 | [diff] [blame^] | 114 | static void mainboard_final(void *chip_info) |
| 115 | { |
| 116 | int status; |
| 117 | |
| 118 | /** |
| 119 | * Set up the DP2LVDS converter. |
| 120 | * ptn3460_init() may only be executed after i2c bus init. |
| 121 | */ |
| 122 | status = ptn3460_init("hwinfo.hex"); |
| 123 | if (status) |
| 124 | printk(BIOS_ERR, "LCD: Set up PTN with status 0x%x\n", status); |
| 125 | else |
| 126 | printk(BIOS_INFO, "LCD: Set up PTN was successful.\n"); |
| 127 | } |
| 128 | |
Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 129 | struct chip_operations mainboard_ops = { |
| 130 | .init = mainboard_init, |
Mario Scheithauer | 956a9f6 | 2017-03-29 17:09:37 +0200 | [diff] [blame^] | 131 | .final = mainboard_final, |
Mario Scheithauer | 092db95 | 2017-01-31 15:45:13 +0100 | [diff] [blame] | 132 | }; |