OSDN Git Service

mmc: sdhci-pci: Let devices define their own private data
authorAdrian Hunter <adrian.hunter@intel.com>
Mon, 20 Mar 2017 17:50:33 +0000 (19:50 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 24 Apr 2017 19:41:27 +0000 (21:41 +0200)
Let devices define their own private data to facilitate device-specific
operations. The size of the private structure is specified in the
sdhci_pci_fixes structure, then sdhci_pci_probe_slot() will allocate extra
space for it, and sdhci_pci_priv() can be used to get a reference to it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Ludovic Desroches <ludovic.desroches@microchip.com>
drivers/mmc/host/sdhci-pci-core.c
drivers/mmc/host/sdhci-pci.h

index b7150e9..84b73cb 100644 (file)
@@ -1830,6 +1830,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
        struct sdhci_pci_slot *slot;
        struct sdhci_host *host;
        int ret, bar = first_bar + slotno;
+       size_t priv_size = chip->fixes ? chip->fixes->priv_size : 0;
 
        if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
                dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
@@ -1851,7 +1852,7 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
                return ERR_PTR(-ENODEV);
        }
 
-       host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
+       host = sdhci_alloc_host(&pdev->dev, sizeof(*slot) + priv_size);
        if (IS_ERR(host)) {
                dev_err(&pdev->dev, "cannot allocate host\n");
                return ERR_CAST(host);
index e6e916b..cfe519c 100644 (file)
@@ -70,6 +70,7 @@ struct sdhci_pci_fixes {
        int                     (*resume) (struct sdhci_pci_chip *);
 
        const struct sdhci_ops  *ops;
+       size_t                  priv_size;
 };
 
 struct sdhci_pci_slot {
@@ -89,6 +90,7 @@ struct sdhci_pci_slot {
                                     struct mmc_card *card,
                                     unsigned int max_dtr, int host_drv,
                                     int card_drv, int *drv_type);
+       unsigned long           private[0] ____cacheline_aligned;
 };
 
 struct sdhci_pci_chip {
@@ -105,4 +107,9 @@ struct sdhci_pci_chip {
        struct sdhci_pci_slot   *slots[MAX_SLOTS]; /* Pointers to host slots */
 };
 
+static inline void *sdhci_pci_priv(struct sdhci_pci_slot *slot)
+{
+       return (void *)slot->private;
+}
+
 #endif /* __SDHCI_PCI_H */