Linux 4.1.16
[linux/fpc-iii.git] / drivers / mfd / cs5535-mfd.c
blobbe91cb5d6e7860dc789ceb9cb8037524db0969e1
1 /*
2 * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges
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.
9 * Copyright (c) 2010 Andres Salomon <dilinger@queued.net>
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.
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.
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.
25 #include <linux/kernel.h>
26 #include <linux/mfd/core.h>
27 #include <linux/module.h>
28 #include <linux/pci.h>
29 #include <asm/olpc.h>
31 #define DRV_NAME "cs5535-mfd"
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,
42 static int cs5535_mfd_res_enable(struct platform_device *pdev)
44 struct resource *res;
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;
52 if (!request_region(res->start, resource_size(res), DRV_NAME)) {
53 dev_err(&pdev->dev, "can't request region\n");
54 return -EIO;
57 return 0;
60 static int cs5535_mfd_res_disable(struct platform_device *pdev)
62 struct resource *res;
63 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
64 if (!res) {
65 dev_err(&pdev->dev, "can't fetch device resource info\n");
66 return -EIO;
69 release_region(res->start, resource_size(res));
70 return 0;
73 static struct resource cs5535_mfd_resources[NR_BARS];
75 static struct mfd_cell cs5535_mfd_cells[] = {
77 .id = SMB_BAR,
78 .name = "cs5535-smb",
79 .num_resources = 1,
80 .resources = &cs5535_mfd_resources[SMB_BAR],
83 .id = GPIO_BAR,
84 .name = "cs5535-gpio",
85 .num_resources = 1,
86 .resources = &cs5535_mfd_resources[GPIO_BAR],
89 .id = MFGPT_BAR,
90 .name = "cs5535-mfgpt",
91 .num_resources = 1,
92 .resources = &cs5535_mfd_resources[MFGPT_BAR],
95 .id = PMS_BAR,
96 .name = "cs5535-pms",
97 .num_resources = 1,
98 .resources = &cs5535_mfd_resources[PMS_BAR],
100 .enable = cs5535_mfd_res_enable,
101 .disable = cs5535_mfd_res_disable,
104 .id = ACPI_BAR,
105 .name = "cs5535-acpi",
106 .num_resources = 1,
107 .resources = &cs5535_mfd_resources[ACPI_BAR],
109 .enable = cs5535_mfd_res_enable,
110 .disable = cs5535_mfd_res_disable,
114 #ifdef CONFIG_OLPC
115 static void cs5535_clone_olpc_cells(void)
117 const char *acpi_clones[] = { "olpc-xo1-pm-acpi", "olpc-xo1-sci-acpi" };
119 if (!machine_is_olpc())
120 return;
122 mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones));
124 #else
125 static void cs5535_clone_olpc_cells(void) { }
126 #endif
128 static int cs5535_mfd_probe(struct pci_dev *pdev,
129 const struct pci_device_id *id)
131 int err, i;
133 err = pci_enable_device(pdev);
134 if (err)
135 return err;
137 /* fill in IO range for each cell; subdrivers handle the region */
138 for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) {
139 int bar = cs5535_mfd_cells[i].id;
140 struct resource *r = &cs5535_mfd_resources[bar];
142 r->flags = IORESOURCE_IO;
143 r->start = pci_resource_start(pdev, bar);
144 r->end = pci_resource_end(pdev, bar);
146 /* id is used for temporarily storing BAR; unset it now */
147 cs5535_mfd_cells[i].id = 0;
150 err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
151 ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
152 if (err) {
153 dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
154 goto err_disable;
156 cs5535_clone_olpc_cells();
158 dev_info(&pdev->dev, "%zu devices registered.\n",
159 ARRAY_SIZE(cs5535_mfd_cells));
161 return 0;
163 err_disable:
164 pci_disable_device(pdev);
165 return err;
168 static void cs5535_mfd_remove(struct pci_dev *pdev)
170 mfd_remove_devices(&pdev->dev);
171 pci_disable_device(pdev);
174 static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
175 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
176 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
177 { 0, }
179 MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
181 static struct pci_driver cs5535_mfd_driver = {
182 .name = DRV_NAME,
183 .id_table = cs5535_mfd_pci_tbl,
184 .probe = cs5535_mfd_probe,
185 .remove = cs5535_mfd_remove,
188 module_pci_driver(cs5535_mfd_driver);
190 MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
191 MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
192 MODULE_LICENSE("GPL");