Linux Audio

Check our new training course

Loading...
v3.1
 
  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#include <asm/olpc.h>
 31
 32#define DRV_NAME "cs5535-mfd"
 33
 34enum cs5535_mfd_bars {
 35	SMB_BAR = 0,
 36	GPIO_BAR = 1,
 37	MFGPT_BAR = 2,
 38	PMS_BAR = 4,
 39	ACPI_BAR = 5,
 40	NR_BARS,
 41};
 42
 43static int cs5535_mfd_res_enable(struct platform_device *pdev)
 44{
 45	struct resource *res;
 46
 47	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
 48	if (!res) {
 49		dev_err(&pdev->dev, "can't fetch device resource info\n");
 50		return -EIO;
 51	}
 52
 53	if (!request_region(res->start, resource_size(res), DRV_NAME)) {
 54		dev_err(&pdev->dev, "can't request region\n");
 55		return -EIO;
 56	}
 57
 58	return 0;
 59}
 60
 61static int cs5535_mfd_res_disable(struct platform_device *pdev)
 62{
 63	struct resource *res;
 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
 74static __devinitdata struct resource cs5535_mfd_resources[NR_BARS];
 75
 76static __devinitdata struct mfd_cell cs5535_mfd_cells[] = {
 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],
 
 
100
101		.enable = cs5535_mfd_res_enable,
102		.disable = cs5535_mfd_res_disable,
 
 
 
103	},
104	{
105		.id = ACPI_BAR,
106		.name = "cs5535-acpi",
107		.num_resources = 1,
108		.resources = &cs5535_mfd_resources[ACPI_BAR],
109
110		.enable = cs5535_mfd_res_enable,
111		.disable = cs5535_mfd_res_disable,
112	},
113};
114
115#ifdef CONFIG_OLPC
116static void __devinit cs5535_clone_olpc_cells(void)
117{
118	const char *acpi_clones[] = { "olpc-xo1-pm-acpi", "olpc-xo1-sci-acpi" };
119
120	if (!machine_is_olpc())
121		return;
122
123	mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones));
124}
125#else
126static void cs5535_clone_olpc_cells(void) { }
127#endif
128
129static int __devinit cs5535_mfd_probe(struct pci_dev *pdev,
130		const struct pci_device_id *id)
131{
132	int err, i;
133
134	err = pci_enable_device(pdev);
135	if (err)
136		return err;
137
138	/* fill in IO range for each cell; subdrivers handle the region */
139	for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) {
140		int bar = cs5535_mfd_cells[i].id;
141		struct resource *r = &cs5535_mfd_resources[bar];
142
143		r->flags = IORESOURCE_IO;
144		r->start = pci_resource_start(pdev, bar);
145		r->end = pci_resource_end(pdev, bar);
146
147		/* id is used for temporarily storing BAR; unset it now */
148		cs5535_mfd_cells[i].id = 0;
149	}
150
151	err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
152			ARRAY_SIZE(cs5535_mfd_cells), NULL, 0);
153	if (err) {
154		dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
155		goto err_disable;
156	}
157	cs5535_clone_olpc_cells();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
159	dev_info(&pdev->dev, "%zu devices registered.\n",
160			ARRAY_SIZE(cs5535_mfd_cells));
161
162	return 0;
163
 
 
 
 
 
 
164err_disable:
165	pci_disable_device(pdev);
166	return err;
167}
168
169static void __devexit cs5535_mfd_remove(struct pci_dev *pdev)
170{
171	mfd_remove_devices(&pdev->dev);
 
 
 
 
 
172	pci_disable_device(pdev);
173}
174
175static struct pci_device_id cs5535_mfd_pci_tbl[] = {
176	{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
177	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
178	{ 0, }
179};
180MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
181
182static struct pci_driver cs5535_mfd_drv = {
183	.name = DRV_NAME,
184	.id_table = cs5535_mfd_pci_tbl,
185	.probe = cs5535_mfd_probe,
186	.remove = __devexit_p(cs5535_mfd_remove),
187};
188
189static int __init cs5535_mfd_init(void)
190{
191	return pci_register_driver(&cs5535_mfd_drv);
192}
193
194static void __exit cs5535_mfd_exit(void)
195{
196	pci_unregister_driver(&cs5535_mfd_drv);
197}
198
199module_init(cs5535_mfd_init);
200module_exit(cs5535_mfd_exit);
201
202MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
203MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
204MODULE_LICENSE("GPL");
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-only
  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>
 
 
 
 
 
 
 
 
 
 
 
 
 
 11 */
 12
 13#include <linux/kernel.h>
 
 14#include <linux/mfd/core.h>
 15#include <linux/module.h>
 16#include <linux/pci.h>
 17#include <asm/olpc.h>
 18
 19#define DRV_NAME "cs5535-mfd"
 20
 21enum 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
 30static struct resource cs5535_mfd_resources[NR_BARS];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 31
 32static struct mfd_cell cs5535_mfd_cells[] = {
 
 
 33	{
 
 34		.name = "cs5535-smb",
 35		.num_resources = 1,
 36		.resources = &cs5535_mfd_resources[SMB_BAR],
 37	},
 38	{
 
 39		.name = "cs5535-gpio",
 40		.num_resources = 1,
 41		.resources = &cs5535_mfd_resources[GPIO_BAR],
 42	},
 43	{
 
 44		.name = "cs5535-mfgpt",
 45		.num_resources = 1,
 46		.resources = &cs5535_mfd_resources[MFGPT_BAR],
 47	},
 48	{
 
 49		.name = "cs5535-pms",
 50		.num_resources = 1,
 51		.resources = &cs5535_mfd_resources[PMS_BAR],
 52	},
 53};
 54
 55static struct mfd_cell cs5535_olpc_mfd_cells[] = {
 56	{
 57		.name = "olpc-xo1-pm-acpi",
 58		.num_resources = 1,
 59		.resources = &cs5535_mfd_resources[ACPI_BAR],
 60	},
 61	{
 62		.name = "olpc-xo1-sci-acpi",
 
 63		.num_resources = 1,
 64		.resources = &cs5535_mfd_resources[ACPI_BAR],
 
 
 
 65	},
 66};
 67
 68static int cs5535_mfd_probe(struct pci_dev *pdev,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 69		const struct pci_device_id *id)
 70{
 71	int err, bar;
 72
 73	err = pci_enable_device(pdev);
 74	if (err)
 75		return err;
 76
 77	for (bar = 0; bar < NR_BARS; bar++) {
 
 
 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);
 
 
 
 83	}
 84
 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
 91	err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, cs5535_mfd_cells,
 92			      ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
 93	if (err) {
 94		dev_err(&pdev->dev,
 95			"Failed to add CS5535 sub-devices: %d\n", err);
 96		goto err_release_pms;
 97	}
 98
 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
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);
111		if (err) {
112			dev_err(&pdev->dev,
113				"Failed to add CS5535 OLPC sub-devices: %d\n",
114				err);
115			goto err_release_acpi;
116		}
117	}
118
119	dev_info(&pdev->dev, "%zu devices registered.\n",
120			ARRAY_SIZE(cs5535_mfd_cells));
121
122	return 0;
123
124err_release_acpi:
125	pci_release_region(pdev, ACPI_BAR);
126err_remove_devices:
127	mfd_remove_devices(&pdev->dev);
128err_release_pms:
129	pci_release_region(pdev, PMS_BAR);
130err_disable:
131	pci_disable_device(pdev);
132	return err;
133}
134
135static void cs5535_mfd_remove(struct pci_dev *pdev)
136{
137	mfd_remove_devices(&pdev->dev);
138
139	if (machine_is_olpc())
140		pci_release_region(pdev, ACPI_BAR);
141
142	pci_release_region(pdev, PMS_BAR);
143	pci_disable_device(pdev);
144}
145
146static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
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};
151MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
152
153static struct pci_driver cs5535_mfd_driver = {
154	.name = DRV_NAME,
155	.id_table = cs5535_mfd_pci_tbl,
156	.probe = cs5535_mfd_probe,
157	.remove = cs5535_mfd_remove,
158};
159
160module_pci_driver(cs5535_mfd_driver);
 
 
 
 
 
 
 
 
 
 
 
161
162MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
163MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
164MODULE_LICENSE("GPL");