| 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> | 
 | 26 | #include <linux/init.h> | 
 | 27 | #include <linux/mfd/core.h> | 
 | 28 | #include <linux/module.h> | 
 | 29 | #include <linux/pci.h> | 
 | 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; | 
 | 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; | 
 | 67 | 	} | 
 | 68 |  | 
 | 69 | 	release_region(res->start, resource_size(res)); | 
 | 70 | 	return 0; | 
 | 71 | } | 
 | 72 |  | 
| Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 73 | static __devinitdata struct resource cs5535_mfd_resources[NR_BARS]; | 
 | 74 |  | 
 | 75 | static __devinitdata struct mfd_cell cs5535_mfd_cells[] = { | 
 | 76 | 	{ | 
 | 77 | 		.id = SMB_BAR, | 
 | 78 | 		.name = "cs5535-smb", | 
 | 79 | 		.num_resources = 1, | 
 | 80 | 		.resources = &cs5535_mfd_resources[SMB_BAR], | 
 | 81 | 	}, | 
 | 82 | 	{ | 
 | 83 | 		.id = GPIO_BAR, | 
 | 84 | 		.name = "cs5535-gpio", | 
 | 85 | 		.num_resources = 1, | 
 | 86 | 		.resources = &cs5535_mfd_resources[GPIO_BAR], | 
 | 87 | 	}, | 
 | 88 | 	{ | 
 | 89 | 		.id = MFGPT_BAR, | 
 | 90 | 		.name = "cs5535-mfgpt", | 
 | 91 | 		.num_resources = 1, | 
 | 92 | 		.resources = &cs5535_mfd_resources[MFGPT_BAR], | 
 | 93 | 	}, | 
 | 94 | 	{ | 
 | 95 | 		.id = PMS_BAR, | 
 | 96 | 		.name = "cs5535-pms", | 
 | 97 | 		.num_resources = 1, | 
 | 98 | 		.resources = &cs5535_mfd_resources[PMS_BAR], | 
| Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame^] | 99 |  | 
 | 100 | 		.enable = cs5535_mfd_res_enable, | 
 | 101 | 		.disable = cs5535_mfd_res_disable, | 
| Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 102 | 	}, | 
 | 103 | 	{ | 
 | 104 | 		.id = ACPI_BAR, | 
 | 105 | 		.name = "cs5535-acpi", | 
 | 106 | 		.num_resources = 1, | 
 | 107 | 		.resources = &cs5535_mfd_resources[ACPI_BAR], | 
| Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame^] | 108 |  | 
 | 109 | 		.enable = cs5535_mfd_res_enable, | 
 | 110 | 		.disable = cs5535_mfd_res_disable, | 
| Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 111 | 	}, | 
 | 112 | }; | 
 | 113 |  | 
 | 114 | static int __devinit cs5535_mfd_probe(struct pci_dev *pdev, | 
 | 115 | 		const struct pci_device_id *id) | 
 | 116 | { | 
 | 117 | 	int err, i; | 
 | 118 |  | 
 | 119 | 	err = pci_enable_device(pdev); | 
 | 120 | 	if (err) | 
 | 121 | 		return err; | 
 | 122 |  | 
 | 123 | 	/* fill in IO range for each cell; subdrivers handle the region */ | 
 | 124 | 	for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) { | 
 | 125 | 		int bar = cs5535_mfd_cells[i].id; | 
 | 126 | 		struct resource *r = &cs5535_mfd_resources[bar]; | 
 | 127 |  | 
 | 128 | 		r->flags = IORESOURCE_IO; | 
 | 129 | 		r->start = pci_resource_start(pdev, bar); | 
 | 130 | 		r->end = pci_resource_end(pdev, bar); | 
 | 131 |  | 
 | 132 | 		/* id is used for temporarily storing BAR; unset it now */ | 
 | 133 | 		cs5535_mfd_cells[i].id = 0; | 
 | 134 | 	} | 
 | 135 |  | 
 | 136 | 	err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells, | 
 | 137 | 			ARRAY_SIZE(cs5535_mfd_cells), NULL, 0); | 
 | 138 | 	if (err) { | 
 | 139 | 		dev_err(&pdev->dev, "MFD add devices failed: %d\n", err); | 
 | 140 | 		goto err_disable; | 
 | 141 | 	} | 
 | 142 |  | 
| Andres Salomon | 816b458 | 2010-11-30 13:54:39 -0800 | [diff] [blame] | 143 | 	dev_info(&pdev->dev, "%zu devices registered.\n", | 
| Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 144 | 			ARRAY_SIZE(cs5535_mfd_cells)); | 
 | 145 |  | 
 | 146 | 	return 0; | 
 | 147 |  | 
 | 148 | err_disable: | 
 | 149 | 	pci_disable_device(pdev); | 
 | 150 | 	return err; | 
 | 151 | } | 
 | 152 |  | 
 | 153 | static void __devexit cs5535_mfd_remove(struct pci_dev *pdev) | 
 | 154 | { | 
 | 155 | 	mfd_remove_devices(&pdev->dev); | 
 | 156 | 	pci_disable_device(pdev); | 
 | 157 | } | 
 | 158 |  | 
 | 159 | static struct pci_device_id cs5535_mfd_pci_tbl[] = { | 
 | 160 | 	{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) }, | 
 | 161 | 	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, | 
 | 162 | 	{ 0, } | 
 | 163 | }; | 
 | 164 | MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl); | 
 | 165 |  | 
 | 166 | static struct pci_driver cs5535_mfd_drv = { | 
 | 167 | 	.name = DRV_NAME, | 
 | 168 | 	.id_table = cs5535_mfd_pci_tbl, | 
 | 169 | 	.probe = cs5535_mfd_probe, | 
 | 170 | 	.remove = __devexit_p(cs5535_mfd_remove), | 
 | 171 | }; | 
 | 172 |  | 
 | 173 | static int __init cs5535_mfd_init(void) | 
 | 174 | { | 
 | 175 | 	return pci_register_driver(&cs5535_mfd_drv); | 
 | 176 | } | 
 | 177 |  | 
 | 178 | static void __exit cs5535_mfd_exit(void) | 
 | 179 | { | 
 | 180 | 	pci_unregister_driver(&cs5535_mfd_drv); | 
 | 181 | } | 
 | 182 |  | 
 | 183 | module_init(cs5535_mfd_init); | 
 | 184 | module_exit(cs5535_mfd_exit); | 
 | 185 |  | 
 | 186 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); | 
 | 187 | MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device"); | 
 | 188 | MODULE_LICENSE("GPL"); |