Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges |
| 3 | * |
| 4 | * The CS5535 and CS5536 has an ISA bridge on the PCI bus that is |
| 5 | * used for accessing GPIOs, MFGPTs, ACPI, etc. Each subdevice has |
| 6 | * an IO range that's specified in a single BAR. The BAR order is |
| 7 | * hardcoded in the CS553x specifications. |
| 8 | * |
| 9 | * Copyright (c) 2010 Andres Salomon <dilinger@queued.net> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 26 | #include <linux/mfd/core.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/pci.h> |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 29 | #include <asm/olpc.h> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 30 | |
| 31 | #define DRV_NAME "cs5535-mfd" |
| 32 | |
| 33 | enum cs5535_mfd_bars { |
| 34 | SMB_BAR = 0, |
| 35 | GPIO_BAR = 1, |
| 36 | MFGPT_BAR = 2, |
| 37 | PMS_BAR = 4, |
| 38 | ACPI_BAR = 5, |
| 39 | NR_BARS, |
| 40 | }; |
| 41 | |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 42 | static int cs5535_mfd_res_enable(struct platform_device *pdev) |
| 43 | { |
| 44 | struct resource *res; |
| 45 | |
| 46 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 47 | if (!res) { |
| 48 | dev_err(&pdev->dev, "can't fetch device resource info\n"); |
| 49 | return -EIO; |
| 50 | } |
| 51 | |
| 52 | if (!request_region(res->start, resource_size(res), DRV_NAME)) { |
| 53 | dev_err(&pdev->dev, "can't request region\n"); |
| 54 | return -EIO; |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int cs5535_mfd_res_disable(struct platform_device *pdev) |
| 61 | { |
| 62 | struct resource *res; |
Lee Jones | 740c1989 | 2015-10-28 16:44:58 +0000 | [diff] [blame] | 63 | |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 64 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 65 | if (!res) { |
| 66 | dev_err(&pdev->dev, "can't fetch device resource info\n"); |
| 67 | return -EIO; |
| 68 | } |
| 69 | |
| 70 | release_region(res->start, resource_size(res)); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 74 | static struct resource cs5535_mfd_resources[NR_BARS]; |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 75 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 76 | static struct mfd_cell cs5535_mfd_cells[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 77 | { |
| 78 | .id = SMB_BAR, |
| 79 | .name = "cs5535-smb", |
| 80 | .num_resources = 1, |
| 81 | .resources = &cs5535_mfd_resources[SMB_BAR], |
| 82 | }, |
| 83 | { |
| 84 | .id = GPIO_BAR, |
| 85 | .name = "cs5535-gpio", |
| 86 | .num_resources = 1, |
| 87 | .resources = &cs5535_mfd_resources[GPIO_BAR], |
| 88 | }, |
| 89 | { |
| 90 | .id = MFGPT_BAR, |
| 91 | .name = "cs5535-mfgpt", |
| 92 | .num_resources = 1, |
| 93 | .resources = &cs5535_mfd_resources[MFGPT_BAR], |
| 94 | }, |
| 95 | { |
| 96 | .id = PMS_BAR, |
| 97 | .name = "cs5535-pms", |
| 98 | .num_resources = 1, |
| 99 | .resources = &cs5535_mfd_resources[PMS_BAR], |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 100 | |
| 101 | .enable = cs5535_mfd_res_enable, |
| 102 | .disable = cs5535_mfd_res_disable, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 103 | }, |
| 104 | { |
| 105 | .id = ACPI_BAR, |
| 106 | .name = "cs5535-acpi", |
| 107 | .num_resources = 1, |
| 108 | .resources = &cs5535_mfd_resources[ACPI_BAR], |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 109 | |
| 110 | .enable = cs5535_mfd_res_enable, |
| 111 | .disable = cs5535_mfd_res_disable, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 112 | }, |
| 113 | }; |
| 114 | |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 115 | #ifdef CONFIG_OLPC |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 116 | static void cs5535_clone_olpc_cells(void) |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 117 | { |
Lee Jones | 740c1989 | 2015-10-28 16:44:58 +0000 | [diff] [blame] | 118 | static const char *acpi_clones[] = { |
| 119 | "olpc-xo1-pm-acpi", |
| 120 | "olpc-xo1-sci-acpi" |
| 121 | }; |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 122 | |
| 123 | if (!machine_is_olpc()) |
| 124 | return; |
| 125 | |
| 126 | mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones)); |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 127 | } |
| 128 | #else |
| 129 | static void cs5535_clone_olpc_cells(void) { } |
| 130 | #endif |
| 131 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 132 | static int cs5535_mfd_probe(struct pci_dev *pdev, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 133 | const struct pci_device_id *id) |
| 134 | { |
| 135 | int err, i; |
| 136 | |
| 137 | err = pci_enable_device(pdev); |
| 138 | if (err) |
| 139 | return err; |
| 140 | |
| 141 | /* fill in IO range for each cell; subdrivers handle the region */ |
| 142 | for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) { |
| 143 | int bar = cs5535_mfd_cells[i].id; |
| 144 | struct resource *r = &cs5535_mfd_resources[bar]; |
| 145 | |
| 146 | r->flags = IORESOURCE_IO; |
| 147 | r->start = pci_resource_start(pdev, bar); |
| 148 | r->end = pci_resource_end(pdev, bar); |
| 149 | |
| 150 | /* id is used for temporarily storing BAR; unset it now */ |
| 151 | cs5535_mfd_cells[i].id = 0; |
| 152 | } |
| 153 | |
| 154 | err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 155 | ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 156 | if (err) { |
| 157 | dev_err(&pdev->dev, "MFD add devices failed: %d\n", err); |
| 158 | goto err_disable; |
| 159 | } |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 160 | cs5535_clone_olpc_cells(); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 161 | |
Andres Salomon | 816b458 | 2010-11-30 13:54:39 -0800 | [diff] [blame] | 162 | dev_info(&pdev->dev, "%zu devices registered.\n", |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 163 | ARRAY_SIZE(cs5535_mfd_cells)); |
| 164 | |
| 165 | return 0; |
| 166 | |
| 167 | err_disable: |
| 168 | pci_disable_device(pdev); |
| 169 | return err; |
| 170 | } |
| 171 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 172 | static void cs5535_mfd_remove(struct pci_dev *pdev) |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 173 | { |
| 174 | mfd_remove_devices(&pdev->dev); |
| 175 | pci_disable_device(pdev); |
| 176 | } |
| 177 | |
Jingoo Han | 36fcd06 | 2013-12-03 08:15:39 +0900 | [diff] [blame] | 178 | static const struct pci_device_id cs5535_mfd_pci_tbl[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 179 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) }, |
| 180 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, |
| 181 | { 0, } |
| 182 | }; |
| 183 | MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl); |
| 184 | |
Christian Gmeiner | 97e43c9 | 2011-12-13 21:30:04 +0100 | [diff] [blame] | 185 | static struct pci_driver cs5535_mfd_driver = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 186 | .name = DRV_NAME, |
| 187 | .id_table = cs5535_mfd_pci_tbl, |
| 188 | .probe = cs5535_mfd_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 189 | .remove = cs5535_mfd_remove, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 190 | }; |
| 191 | |
Axel Lin | 38a36f5 | 2012-04-03 09:09:19 +0800 | [diff] [blame] | 192 | module_pci_driver(cs5535_mfd_driver); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 193 | |
| 194 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); |
| 195 | MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device"); |
| 196 | MODULE_LICENSE("GPL"); |