Thomas Gleixner | 82c2981 | 2019-05-28 09:57:05 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 2 | /* |
| 3 | * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges |
| 4 | * |
| 5 | * The CS5535 and CS5536 has an ISA bridge on the PCI bus that is |
| 6 | * used for accessing GPIOs, MFGPTs, ACPI, etc. Each subdevice has |
| 7 | * an IO range that's specified in a single BAR. The BAR order is |
| 8 | * hardcoded in the CS553x specifications. |
| 9 | * |
| 10 | * Copyright (c) 2010 Andres Salomon <dilinger@queued.net> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 14 | #include <linux/mfd/core.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/pci.h> |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 17 | #include <asm/olpc.h> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 18 | |
| 19 | #define DRV_NAME "cs5535-mfd" |
| 20 | |
| 21 | enum cs5535_mfd_bars { |
| 22 | SMB_BAR = 0, |
| 23 | GPIO_BAR = 1, |
| 24 | MFGPT_BAR = 2, |
| 25 | PMS_BAR = 4, |
| 26 | ACPI_BAR = 5, |
| 27 | NR_BARS, |
| 28 | }; |
| 29 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 30 | static struct resource cs5535_mfd_resources[NR_BARS]; |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 31 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 32 | static struct mfd_cell cs5535_mfd_cells[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 33 | { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 34 | .name = "cs5535-smb", |
| 35 | .num_resources = 1, |
| 36 | .resources = &cs5535_mfd_resources[SMB_BAR], |
| 37 | }, |
| 38 | { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 39 | .name = "cs5535-gpio", |
| 40 | .num_resources = 1, |
| 41 | .resources = &cs5535_mfd_resources[GPIO_BAR], |
| 42 | }, |
| 43 | { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 44 | .name = "cs5535-mfgpt", |
| 45 | .num_resources = 1, |
| 46 | .resources = &cs5535_mfd_resources[MFGPT_BAR], |
| 47 | }, |
| 48 | { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 49 | .name = "cs5535-pms", |
| 50 | .num_resources = 1, |
| 51 | .resources = &cs5535_mfd_resources[PMS_BAR], |
| 52 | }, |
Lee Jones | 99cd105 | 2019-10-18 11:36:44 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | static struct mfd_cell cs5535_olpc_mfd_cells[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 56 | { |
Lee Jones | 99cd105 | 2019-10-18 11:36:44 +0100 | [diff] [blame] | 57 | .name = "olpc-xo1-pm-acpi", |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 58 | .num_resources = 1, |
| 59 | .resources = &cs5535_mfd_resources[ACPI_BAR], |
| 60 | }, |
Lee Jones | 99cd105 | 2019-10-18 11:36:44 +0100 | [diff] [blame] | 61 | { |
| 62 | .name = "olpc-xo1-sci-acpi", |
| 63 | .num_resources = 1, |
| 64 | .resources = &cs5535_mfd_resources[ACPI_BAR], |
| 65 | }, |
Lubomir Rintel | fd54d65 | 2019-06-20 13:19:57 +0200 | [diff] [blame] | 66 | }; |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 67 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 68 | static int cs5535_mfd_probe(struct pci_dev *pdev, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 69 | const struct pci_device_id *id) |
| 70 | { |
Lee Jones | 2129e56 | 2019-10-18 10:23:49 +0100 | [diff] [blame] | 71 | int err, bar; |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 72 | |
| 73 | err = pci_enable_device(pdev); |
| 74 | if (err) |
| 75 | return err; |
| 76 | |
Lee Jones | 2129e56 | 2019-10-18 10:23:49 +0100 | [diff] [blame] | 77 | for (bar = 0; bar < NR_BARS; bar++) { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 78 | struct resource *r = &cs5535_mfd_resources[bar]; |
| 79 | |
| 80 | r->flags = IORESOURCE_IO; |
| 81 | r->start = pci_resource_start(pdev, bar); |
| 82 | r->end = pci_resource_end(pdev, bar); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 85 | err = pci_request_region(pdev, PMS_BAR, DRV_NAME); |
| 86 | if (err) { |
| 87 | dev_err(&pdev->dev, "Failed to request PMS_BAR's IO region\n"); |
| 88 | goto err_disable; |
| 89 | } |
| 90 | |
Lee Jones | 601e428 | 2019-10-18 10:09:24 +0100 | [diff] [blame] | 91 | err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, cs5535_mfd_cells, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 92 | ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 93 | if (err) { |
Lee Jones | 601e428 | 2019-10-18 10:09:24 +0100 | [diff] [blame] | 94 | dev_err(&pdev->dev, |
| 95 | "Failed to add CS5535 sub-devices: %d\n", err); |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 96 | goto err_release_pms; |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 97 | } |
Lubomir Rintel | fd54d65 | 2019-06-20 13:19:57 +0200 | [diff] [blame] | 98 | |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 99 | if (machine_is_olpc()) { |
| 100 | err = pci_request_region(pdev, ACPI_BAR, DRV_NAME); |
| 101 | if (err) { |
| 102 | dev_err(&pdev->dev, |
| 103 | "Failed to request ACPI_BAR's IO region\n"); |
| 104 | goto err_remove_devices; |
| 105 | } |
| 106 | |
Lee Jones | 99cd105 | 2019-10-18 11:36:44 +0100 | [diff] [blame] | 107 | err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, |
| 108 | cs5535_olpc_mfd_cells, |
| 109 | ARRAY_SIZE(cs5535_olpc_mfd_cells), |
| 110 | NULL, 0, NULL); |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 111 | if (err) { |
Lee Jones | 99cd105 | 2019-10-18 11:36:44 +0100 | [diff] [blame] | 112 | dev_err(&pdev->dev, |
| 113 | "Failed to add CS5535 OLPC sub-devices: %d\n", |
| 114 | err); |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 115 | goto err_release_acpi; |
| 116 | } |
| 117 | } |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 118 | |
Andres Salomon | 816b458 | 2010-11-30 13:54:39 -0800 | [diff] [blame] | 119 | dev_info(&pdev->dev, "%zu devices registered.\n", |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 120 | ARRAY_SIZE(cs5535_mfd_cells)); |
| 121 | |
| 122 | return 0; |
| 123 | |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 124 | err_release_acpi: |
| 125 | pci_release_region(pdev, ACPI_BAR); |
| 126 | err_remove_devices: |
| 127 | mfd_remove_devices(&pdev->dev); |
| 128 | err_release_pms: |
| 129 | pci_release_region(pdev, PMS_BAR); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 130 | err_disable: |
| 131 | pci_disable_device(pdev); |
| 132 | return err; |
| 133 | } |
| 134 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 135 | static void cs5535_mfd_remove(struct pci_dev *pdev) |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 136 | { |
| 137 | mfd_remove_devices(&pdev->dev); |
Lee Jones | 2d4ba91 | 2019-10-21 08:49:49 +0100 | [diff] [blame] | 138 | |
| 139 | if (machine_is_olpc()) |
| 140 | pci_release_region(pdev, ACPI_BAR); |
| 141 | |
| 142 | pci_release_region(pdev, PMS_BAR); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 143 | pci_disable_device(pdev); |
| 144 | } |
| 145 | |
Jingoo Han | 36fcd06 | 2013-12-03 08:15:39 +0900 | [diff] [blame] | 146 | static const struct pci_device_id cs5535_mfd_pci_tbl[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 147 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) }, |
| 148 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, |
| 149 | { 0, } |
| 150 | }; |
| 151 | MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl); |
| 152 | |
Christian Gmeiner | 97e43c9 | 2011-12-13 21:30:04 +0100 | [diff] [blame] | 153 | static struct pci_driver cs5535_mfd_driver = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 154 | .name = DRV_NAME, |
| 155 | .id_table = cs5535_mfd_pci_tbl, |
| 156 | .probe = cs5535_mfd_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 157 | .remove = cs5535_mfd_remove, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Axel Lin | 38a36f5 | 2012-04-03 09:09:19 +0800 | [diff] [blame] | 160 | module_pci_driver(cs5535_mfd_driver); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 161 | |
| 162 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); |
| 163 | MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device"); |
| 164 | MODULE_LICENSE("GPL"); |