Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges
0004  *
0005  * The CS5535 and CS5536 has an ISA bridge on the PCI bus that is
0006  * used for accessing GPIOs, MFGPTs, ACPI, etc.  Each subdevice has
0007  * an IO range that's specified in a single BAR.  The BAR order is
0008  * hardcoded in the CS553x specifications.
0009  *
0010  * Copyright (c) 2010  Andres Salomon <dilinger@queued.net>
0011  */
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/mfd/core.h>
0015 #include <linux/module.h>
0016 #include <linux/pci.h>
0017 #include <asm/olpc.h>
0018 
0019 #define DRV_NAME "cs5535-mfd"
0020 
0021 enum cs5535_mfd_bars {
0022     SMB_BAR = 0,
0023     GPIO_BAR = 1,
0024     MFGPT_BAR = 2,
0025     PMS_BAR = 4,
0026     ACPI_BAR = 5,
0027     NR_BARS,
0028 };
0029 
0030 static struct resource cs5535_mfd_resources[NR_BARS];
0031 
0032 static struct mfd_cell cs5535_mfd_cells[] = {
0033     {
0034         .name = "cs5535-smb",
0035         .num_resources = 1,
0036         .resources = &cs5535_mfd_resources[SMB_BAR],
0037     },
0038     {
0039         .name = "cs5535-gpio",
0040         .num_resources = 1,
0041         .resources = &cs5535_mfd_resources[GPIO_BAR],
0042     },
0043     {
0044         .name = "cs5535-mfgpt",
0045         .num_resources = 1,
0046         .resources = &cs5535_mfd_resources[MFGPT_BAR],
0047     },
0048     {
0049         .name = "cs5535-pms",
0050         .num_resources = 1,
0051         .resources = &cs5535_mfd_resources[PMS_BAR],
0052     },
0053 };
0054 
0055 static struct mfd_cell cs5535_olpc_mfd_cells[] = {
0056     {
0057         .name = "olpc-xo1-pm-acpi",
0058         .num_resources = 1,
0059         .resources = &cs5535_mfd_resources[ACPI_BAR],
0060     },
0061     {
0062         .name = "olpc-xo1-sci-acpi",
0063         .num_resources = 1,
0064         .resources = &cs5535_mfd_resources[ACPI_BAR],
0065     },
0066 };
0067 
0068 static int cs5535_mfd_probe(struct pci_dev *pdev,
0069         const struct pci_device_id *id)
0070 {
0071     int err, bar;
0072 
0073     err = pci_enable_device(pdev);
0074     if (err)
0075         return err;
0076 
0077     for (bar = 0; bar < NR_BARS; bar++) {
0078         struct resource *r = &cs5535_mfd_resources[bar];
0079 
0080         r->flags = IORESOURCE_IO;
0081         r->start = pci_resource_start(pdev, bar);
0082         r->end = pci_resource_end(pdev, bar);
0083     }
0084 
0085     err = pci_request_region(pdev, PMS_BAR, DRV_NAME);
0086     if (err) {
0087         dev_err(&pdev->dev, "Failed to request PMS_BAR's IO region\n");
0088         goto err_disable;
0089     }
0090 
0091     err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, cs5535_mfd_cells,
0092                   ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
0093     if (err) {
0094         dev_err(&pdev->dev,
0095             "Failed to add CS5535 sub-devices: %d\n", err);
0096         goto err_release_pms;
0097     }
0098 
0099     if (machine_is_olpc()) {
0100         err = pci_request_region(pdev, ACPI_BAR, DRV_NAME);
0101         if (err) {
0102             dev_err(&pdev->dev,
0103                 "Failed to request ACPI_BAR's IO region\n");
0104             goto err_remove_devices;
0105         }
0106 
0107         err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
0108                       cs5535_olpc_mfd_cells,
0109                       ARRAY_SIZE(cs5535_olpc_mfd_cells),
0110                       NULL, 0, NULL);
0111         if (err) {
0112             dev_err(&pdev->dev,
0113                 "Failed to add CS5535 OLPC sub-devices: %d\n",
0114                 err);
0115             goto err_release_acpi;
0116         }
0117     }
0118 
0119     dev_info(&pdev->dev, "%zu devices registered.\n",
0120             ARRAY_SIZE(cs5535_mfd_cells));
0121 
0122     return 0;
0123 
0124 err_release_acpi:
0125     pci_release_region(pdev, ACPI_BAR);
0126 err_remove_devices:
0127     mfd_remove_devices(&pdev->dev);
0128 err_release_pms:
0129     pci_release_region(pdev, PMS_BAR);
0130 err_disable:
0131     pci_disable_device(pdev);
0132     return err;
0133 }
0134 
0135 static void cs5535_mfd_remove(struct pci_dev *pdev)
0136 {
0137     mfd_remove_devices(&pdev->dev);
0138 
0139     if (machine_is_olpc())
0140         pci_release_region(pdev, ACPI_BAR);
0141 
0142     pci_release_region(pdev, PMS_BAR);
0143     pci_disable_device(pdev);
0144 }
0145 
0146 static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
0147     { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
0148     { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
0149     { 0, }
0150 };
0151 MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
0152 
0153 static struct pci_driver cs5535_mfd_driver = {
0154     .name = DRV_NAME,
0155     .id_table = cs5535_mfd_pci_tbl,
0156     .probe = cs5535_mfd_probe,
0157     .remove = cs5535_mfd_remove,
0158 };
0159 
0160 module_pci_driver(cs5535_mfd_driver);
0161 
0162 MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
0163 MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
0164 MODULE_LICENSE("GPL");