Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * Copyright 2017 Intel Corporation |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but without any warranty; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <rules.h> |
| 17 | #if ENV_RAMSTAGE |
| 18 | #define __SIMPLE_DEVICE__ 1 |
| 19 | #endif |
| 20 | |
| 21 | #include <assert.h> |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 22 | #include <commonlib/sdhci.h> |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 23 | #include <console/console.h> |
| 24 | #include <device/pci.h> |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 25 | #include "sd_mmc.h" |
| 26 | #include "storage.h" |
| 27 | #include <string.h> |
| 28 | |
| 29 | /* Initialize an SDHCI port */ |
| 30 | int sdhci_controller_init(struct sdhci_ctrlr *sdhci_ctrlr, void *ioaddr) |
| 31 | { |
| 32 | memset(sdhci_ctrlr, 0, sizeof(*sdhci_ctrlr)); |
| 33 | sdhci_ctrlr->ioaddr = ioaddr; |
| 34 | return add_sdhci(sdhci_ctrlr); |
| 35 | } |
| 36 | |
| 37 | struct sd_mmc_ctrlr *new_mem_sdhci_controller(void *ioaddr) |
| 38 | { |
| 39 | struct sdhci_ctrlr *sdhci_ctrlr; |
| 40 | |
| 41 | sdhci_ctrlr = malloc(sizeof(*sdhci_ctrlr)); |
| 42 | if (sdhci_ctrlr == NULL) |
| 43 | return NULL; |
| 44 | |
| 45 | if (sdhci_controller_init(sdhci_ctrlr, ioaddr)) { |
| 46 | free(sdhci_ctrlr); |
| 47 | sdhci_ctrlr = NULL; |
| 48 | } |
| 49 | return &sdhci_ctrlr->sd_mmc_ctrlr; |
| 50 | } |
| 51 | |
| 52 | struct sd_mmc_ctrlr *new_pci_sdhci_controller(uint32_t dev) |
| 53 | { |
| 54 | uint32_t addr; |
| 55 | |
| 56 | addr = pci_read_config32(dev, PCI_BASE_ADDRESS_0); |
| 57 | if (addr == ((uint32_t)~0)) { |
| 58 | sdhc_error("Error: PCI SDHCI not found\n"); |
| 59 | return NULL; |
| 60 | } |
| 61 | |
| 62 | addr &= ~0xf; |
| 63 | return new_mem_sdhci_controller((void *)addr); |
| 64 | } |