blob: 4c90aff0fc2d6bb185866ddc81b0800b2ff98d53 [file] [log] [blame]
Mario Scheithauer092db952017-01-31 15:45:13 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
Mario Scheithauer480eab02017-02-16 13:39:16 +01005 * Copyright (C) 2017 Siemens AG
Mario Scheithauer092db952017-01-31 15:45:13 +01006 *
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
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070017#include <console/console.h>
Mario Scheithauer956a9f62017-03-29 17:09:37 +020018#include <device/pci.h>
Mario Scheithauer092db952017-01-31 15:45:13 +010019#include <device/device.h>
Mario Scheithauer480eab02017-02-16 13:39:16 +010020#include <hwilib.h>
21#include <i210.h>
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070022#include <intelblocks/lpc_lib.h>
23#include <soc/pci_devs.h>
24#include <string.h>
Mario Scheithauer2d981202017-03-27 13:25:57 +020025#include "brd_gpio.h"
Mario Scheithauer956a9f62017-03-29 17:09:37 +020026#include "ptn3460.h"
Mario Scheithauer480eab02017-02-16 13:39:16 +010027
28#define MAX_PATH_DEPTH 12
29#define MAX_NUM_MAPPINGS 10
30
31/** \brief This function can decide if a given MAC address is valid or not.
32 * Currently, addresses filled with 0xff or 0x00 are not valid.
33 * @param mac Buffer to the MAC address to check
34 * @return 0 if address is not valid, otherwise 1
35 */
36static uint8_t is_mac_adr_valid(uint8_t mac[6])
37{
38 uint8_t buf[6];
39
40 memset(buf, 0, sizeof(buf));
41 if (!memcmp(buf, mac, sizeof(buf)))
42 return 0;
43 memset(buf, 0xff, sizeof(buf));
44 if (!memcmp(buf, mac, sizeof(buf)))
45 return 0;
46 return 1;
47}
48
49/** \brief This function will search for a MAC address which can be assigned
50 * to a MACPHY.
51 * @param dev pointer to PCI device
52 * @param mac buffer where to store the MAC address
53 * @return cb_err CB_ERR or CB_SUCCESS
54 */
55enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[6])
56{
57 struct bus *parent = dev->bus;
58 uint8_t buf[16], mapping[16], i = 0, chain_len = 0;
59
60 memset(buf, 0, sizeof(buf));
61 memset(mapping, 0, sizeof(mapping));
62
63 /* The first entry in the tree is the device itself. */
64 buf[0] = dev->path.pci.devfn;
65 chain_len = 1;
66 for (i = 1; i < MAX_PATH_DEPTH && parent->dev->bus->subordinate; i++) {
67 buf[i] = parent->dev->path.pci.devfn;
68 chain_len++;
69 parent = parent->dev->bus;
70 }
71 if (i == MAX_PATH_DEPTH) {
72 /* The path is deeper than MAX_PATH_DEPTH devices, error. */
73 printk(BIOS_ERR, "Too many bridges for %s\n", dev_path(dev));
74 return CB_ERR;
75 }
76 /*
77 * Now construct the mapping based on the device chain starting from
78 * root bridge device to the device itself.
79 */
80 mapping[0] = 1;
81 mapping[1] = chain_len;
82 for (i = 0; i < chain_len; i++)
83 mapping[i + 4] = buf[chain_len - i - 1];
84
85 /* Open main hwinfo block */
86 if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS)
87 return CB_ERR;
88 /* Now try to find a valid MAC address in hwinfo for this mapping.*/
89 for (i = 0; i < MAX_NUM_MAPPINGS; i++) {
90 if ((hwilib_get_field(XMac1Mapping + i, buf, 16) == 16) &&
91 !(memcmp(buf, mapping, chain_len + 4))) {
92 /* There is a matching mapping available, get MAC address. */
93 if ((hwilib_get_field(XMac1 + i, mac, 6) == 6) &&
94 (is_mac_adr_valid(mac))) {
95 return CB_SUCCESS;
96 } else {
97 return CB_ERR;
98 }
99 } else
100 continue;
101 }
102 /* No MAC address found for */
103 return CB_ERR;
104}
Mario Scheithauer092db952017-01-31 15:45:13 +0100105
106static void mainboard_init(void *chip_info)
107{
Mario Scheithauer2d981202017-03-27 13:25:57 +0200108 const struct pad_config *pads;
109 size_t num;
110
111 pads = brd_gpio_table(&num);
112 gpio_configure_pads(pads, num);
Mario Scheithauer092db952017-01-31 15:45:13 +0100113}
114
Mario Scheithauer956a9f62017-03-29 17:09:37 +0200115static void mainboard_final(void *chip_info)
116{
117 int status;
118
119 /**
120 * Set up the DP2LVDS converter.
121 * ptn3460_init() may only be executed after i2c bus init.
122 */
123 status = ptn3460_init("hwinfo.hex");
124 if (status)
125 printk(BIOS_ERR, "LCD: Set up PTN with status 0x%x\n", status);
126 else
127 printk(BIOS_INFO, "LCD: Set up PTN was successful.\n");
Mario Scheithauer71dacac2017-06-21 12:42:10 +0200128
129 /* Enable additional I/O decoding range on LPC for COM 3 */
130 lpc_open_pmio_window(0x3e8, 8);
Mario Scheithauer956a9f62017-03-29 17:09:37 +0200131}
132
Mario Scheithauer092db952017-01-31 15:45:13 +0100133struct chip_operations mainboard_ops = {
134 .init = mainboard_init,
Mario Scheithauer956a9f62017-03-29 17:09:37 +0200135 .final = mainboard_final,
Mario Scheithauer092db952017-01-31 15:45:13 +0100136};