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>
31 #define DRV_NAME "cs5535-mfd"
33 enum cs5535_mfd_bars
{
42 static int cs5535_mfd_res_enable(struct platform_device
*pdev
)
46 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
48 dev_err(&pdev
->dev
, "can't fetch device resource info\n");
52 if (!request_region(res
->start
, resource_size(res
), DRV_NAME
)) {
53 dev_err(&pdev
->dev
, "can't request region\n");
60 static int cs5535_mfd_res_disable(struct platform_device
*pdev
)
64 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
66 dev_err(&pdev
->dev
, "can't fetch device resource info\n");
70 release_region(res
->start
, resource_size(res
));
74 static struct resource cs5535_mfd_resources
[NR_BARS
];
76 static struct mfd_cell cs5535_mfd_cells
[] = {
81 .resources
= &cs5535_mfd_resources
[SMB_BAR
],
85 .name
= "cs5535-gpio",
87 .resources
= &cs5535_mfd_resources
[GPIO_BAR
],
91 .name
= "cs5535-mfgpt",
93 .resources
= &cs5535_mfd_resources
[MFGPT_BAR
],
99 .resources
= &cs5535_mfd_resources
[PMS_BAR
],
101 .enable
= cs5535_mfd_res_enable
,
102 .disable
= cs5535_mfd_res_disable
,
106 .name
= "cs5535-acpi",
108 .resources
= &cs5535_mfd_resources
[ACPI_BAR
],
110 .enable
= cs5535_mfd_res_enable
,
111 .disable
= cs5535_mfd_res_disable
,
116 static void cs5535_clone_olpc_cells(void)
118 static const char *acpi_clones
[] = {
123 if (!machine_is_olpc())
126 mfd_clone_cell("cs5535-acpi", acpi_clones
, ARRAY_SIZE(acpi_clones
));
129 static void cs5535_clone_olpc_cells(void) { }
132 static int cs5535_mfd_probe(struct pci_dev
*pdev
,
133 const struct pci_device_id
*id
)
137 err
= pci_enable_device(pdev
);
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
];
146 r
->flags
= IORESOURCE_IO
;
147 r
->start
= pci_resource_start(pdev
, bar
);
148 r
->end
= pci_resource_end(pdev
, bar
);
150 /* id is used for temporarily storing BAR; unset it now */
151 cs5535_mfd_cells
[i
].id
= 0;
154 err
= mfd_add_devices(&pdev
->dev
, -1, cs5535_mfd_cells
,
155 ARRAY_SIZE(cs5535_mfd_cells
), NULL
, 0, NULL
);
157 dev_err(&pdev
->dev
, "MFD add devices failed: %d\n", err
);
160 cs5535_clone_olpc_cells();
162 dev_info(&pdev
->dev
, "%zu devices registered.\n",
163 ARRAY_SIZE(cs5535_mfd_cells
));
168 pci_disable_device(pdev
);
172 static void cs5535_mfd_remove(struct pci_dev
*pdev
)
174 mfd_remove_devices(&pdev
->dev
);
175 pci_disable_device(pdev
);
178 static const struct pci_device_id cs5535_mfd_pci_tbl
[] = {
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
) },
183 MODULE_DEVICE_TABLE(pci
, cs5535_mfd_pci_tbl
);
185 static struct pci_driver cs5535_mfd_driver
= {
187 .id_table
= cs5535_mfd_pci_tbl
,
188 .probe
= cs5535_mfd_probe
,
189 .remove
= cs5535_mfd_remove
,
192 module_pci_driver(cs5535_mfd_driver
);
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");