Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.17 224 lines 5.2 kB view raw
1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * Copyright (C) 2018 Oleksij Rempel <linux@rempel-privat.de> 4 * 5 * Driver for Alcor Micro AU6601 and AU6621 controllers 6 */ 7 8#include <linux/delay.h> 9#include <linux/interrupt.h> 10#include <linux/io.h> 11#include <linux/irq.h> 12#include <linux/mfd/core.h> 13#include <linux/module.h> 14#include <linux/pci.h> 15#include <linux/platform_device.h> 16#include <linux/pm.h> 17 18#include <linux/alcor_pci.h> 19 20static DEFINE_IDA(alcor_pci_idr); 21 22static struct mfd_cell alcor_pci_cells[] = { 23 [ALCOR_SD_CARD] = { 24 .name = DRV_NAME_ALCOR_PCI_SDMMC, 25 }, 26 [ALCOR_MS_CARD] = { 27 .name = DRV_NAME_ALCOR_PCI_MS, 28 }, 29}; 30 31static const struct alcor_dev_cfg alcor_cfg = { 32 .dma = 0, 33}; 34 35static const struct alcor_dev_cfg au6621_cfg = { 36 .dma = 1, 37}; 38 39static const struct alcor_dev_cfg au6625_cfg = { 40 .dma = 0, 41}; 42 43static const struct pci_device_id pci_ids[] = { 44 { PCI_DEVICE(PCI_ID_ALCOR_MICRO, PCI_ID_AU6601), 45 .driver_data = (kernel_ulong_t)&alcor_cfg }, 46 { PCI_DEVICE(PCI_ID_ALCOR_MICRO, PCI_ID_AU6621), 47 .driver_data = (kernel_ulong_t)&au6621_cfg }, 48 { PCI_DEVICE(PCI_ID_ALCOR_MICRO, PCI_ID_AU6625), 49 .driver_data = (kernel_ulong_t)&au6625_cfg }, 50 {}, 51}; 52MODULE_DEVICE_TABLE(pci, pci_ids); 53 54void alcor_write8(struct alcor_pci_priv *priv, u8 val, unsigned int addr) 55{ 56 writeb(val, priv->iobase + addr); 57} 58EXPORT_SYMBOL_GPL(alcor_write8); 59 60void alcor_write16(struct alcor_pci_priv *priv, u16 val, unsigned int addr) 61{ 62 writew(val, priv->iobase + addr); 63} 64EXPORT_SYMBOL_GPL(alcor_write16); 65 66void alcor_write32(struct alcor_pci_priv *priv, u32 val, unsigned int addr) 67{ 68 writel(val, priv->iobase + addr); 69} 70EXPORT_SYMBOL_GPL(alcor_write32); 71 72void alcor_write32be(struct alcor_pci_priv *priv, u32 val, unsigned int addr) 73{ 74 iowrite32be(val, priv->iobase + addr); 75} 76EXPORT_SYMBOL_GPL(alcor_write32be); 77 78u8 alcor_read8(struct alcor_pci_priv *priv, unsigned int addr) 79{ 80 return readb(priv->iobase + addr); 81} 82EXPORT_SYMBOL_GPL(alcor_read8); 83 84u32 alcor_read32(struct alcor_pci_priv *priv, unsigned int addr) 85{ 86 return readl(priv->iobase + addr); 87} 88EXPORT_SYMBOL_GPL(alcor_read32); 89 90u32 alcor_read32be(struct alcor_pci_priv *priv, unsigned int addr) 91{ 92 return ioread32be(priv->iobase + addr); 93} 94EXPORT_SYMBOL_GPL(alcor_read32be); 95 96static int alcor_pci_probe(struct pci_dev *pdev, 97 const struct pci_device_id *ent) 98{ 99 struct alcor_dev_cfg *cfg; 100 struct alcor_pci_priv *priv; 101 int ret, i, bar = 0; 102 103 cfg = (void *)ent->driver_data; 104 105 ret = pcim_enable_device(pdev); 106 if (ret) 107 return ret; 108 109 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 110 if (!priv) 111 return -ENOMEM; 112 113 ret = ida_alloc(&alcor_pci_idr, GFP_KERNEL); 114 if (ret < 0) 115 return ret; 116 priv->id = ret; 117 118 priv->pdev = pdev; 119 priv->parent_pdev = pdev->bus->self; 120 priv->dev = &pdev->dev; 121 priv->cfg = cfg; 122 priv->irq = pdev->irq; 123 124 ret = pcim_request_all_regions(pdev, DRV_NAME_ALCOR_PCI); 125 if (ret) { 126 dev_err(&pdev->dev, "Cannot request region\n"); 127 ret = -EBUSY; 128 goto error_free_ida; 129 } 130 131 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { 132 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); 133 ret = -ENODEV; 134 goto error_free_ida; 135 } 136 137 priv->iobase = pcim_iomap(pdev, bar, 0); 138 if (!priv->iobase) { 139 ret = -ENOMEM; 140 goto error_free_ida; 141 } 142 143 /* make sure irqs are disabled */ 144 alcor_write32(priv, 0, AU6601_REG_INT_ENABLE); 145 alcor_write32(priv, 0, AU6601_MS_INT_ENABLE); 146 147 ret = dma_set_mask_and_coherent(priv->dev, AU6601_SDMA_MASK); 148 if (ret) { 149 dev_err(priv->dev, "Failed to set DMA mask\n"); 150 goto error_free_ida; 151 } 152 153 pci_set_master(pdev); 154 pci_set_drvdata(pdev, priv); 155 156 for (i = 0; i < ARRAY_SIZE(alcor_pci_cells); i++) { 157 alcor_pci_cells[i].platform_data = priv; 158 alcor_pci_cells[i].pdata_size = sizeof(*priv); 159 } 160 ret = mfd_add_devices(&pdev->dev, priv->id, alcor_pci_cells, 161 ARRAY_SIZE(alcor_pci_cells), NULL, 0, NULL); 162 if (ret < 0) 163 goto error_clear_drvdata; 164 165 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); 166 167 return 0; 168 169error_clear_drvdata: 170 pci_clear_master(pdev); 171 pci_set_drvdata(pdev, NULL); 172error_free_ida: 173 ida_free(&alcor_pci_idr, priv->id); 174 return ret; 175} 176 177static void alcor_pci_remove(struct pci_dev *pdev) 178{ 179 struct alcor_pci_priv *priv; 180 181 priv = pci_get_drvdata(pdev); 182 183 mfd_remove_devices(&pdev->dev); 184 185 ida_free(&alcor_pci_idr, priv->id); 186 187 pci_clear_master(pdev); 188 pci_set_drvdata(pdev, NULL); 189} 190 191#ifdef CONFIG_PM_SLEEP 192static int alcor_suspend(struct device *dev) 193{ 194 return 0; 195} 196 197static int alcor_resume(struct device *dev) 198{ 199 struct alcor_pci_priv *priv = dev_get_drvdata(dev); 200 201 pci_disable_link_state(priv->pdev, 202 PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); 203 204 return 0; 205} 206#endif /* CONFIG_PM_SLEEP */ 207 208static SIMPLE_DEV_PM_OPS(alcor_pci_pm_ops, alcor_suspend, alcor_resume); 209 210static struct pci_driver alcor_driver = { 211 .name = DRV_NAME_ALCOR_PCI, 212 .id_table = pci_ids, 213 .probe = alcor_pci_probe, 214 .remove = alcor_pci_remove, 215 .driver = { 216 .pm = &alcor_pci_pm_ops 217 }, 218}; 219 220module_pci_driver(alcor_driver); 221 222MODULE_AUTHOR("Oleksij Rempel <linux@rempel-privat.de>"); 223MODULE_DESCRIPTION("PCI driver for Alcor Micro AU6601 Secure Digital Host Controller Interface"); 224MODULE_LICENSE("GPL");