Merge branch 'parisc-5.2-3' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux-2.6-block.git] / drivers / mfd / cs5535-mfd.c
CommitLineData
82c29810 1// SPDX-License-Identifier: GPL-2.0-only
f71e1afd
AS
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>
f71e1afd
AS
11 */
12
13#include <linux/kernel.h>
f71e1afd
AS
14#include <linux/mfd/core.h>
15#include <linux/module.h>
16#include <linux/pci.h>
fa1df691 17#include <asm/olpc.h>
f71e1afd
AS
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
1310e6d6
AS
30static int cs5535_mfd_res_enable(struct platform_device *pdev)
31{
32 struct resource *res;
33
34 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
35 if (!res) {
36 dev_err(&pdev->dev, "can't fetch device resource info\n");
37 return -EIO;
38 }
39
40 if (!request_region(res->start, resource_size(res), DRV_NAME)) {
41 dev_err(&pdev->dev, "can't request region\n");
42 return -EIO;
43 }
44
45 return 0;
46}
47
48static int cs5535_mfd_res_disable(struct platform_device *pdev)
49{
50 struct resource *res;
740c1989 51
1310e6d6
AS
52 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
53 if (!res) {
54 dev_err(&pdev->dev, "can't fetch device resource info\n");
55 return -EIO;
56 }
57
58 release_region(res->start, resource_size(res));
59 return 0;
60}
61
a9e9ce4c 62static struct resource cs5535_mfd_resources[NR_BARS];
f71e1afd 63
a9e9ce4c 64static struct mfd_cell cs5535_mfd_cells[] = {
f71e1afd
AS
65 {
66 .id = SMB_BAR,
67 .name = "cs5535-smb",
68 .num_resources = 1,
69 .resources = &cs5535_mfd_resources[SMB_BAR],
70 },
71 {
72 .id = GPIO_BAR,
73 .name = "cs5535-gpio",
74 .num_resources = 1,
75 .resources = &cs5535_mfd_resources[GPIO_BAR],
76 },
77 {
78 .id = MFGPT_BAR,
79 .name = "cs5535-mfgpt",
80 .num_resources = 1,
81 .resources = &cs5535_mfd_resources[MFGPT_BAR],
82 },
83 {
84 .id = PMS_BAR,
85 .name = "cs5535-pms",
86 .num_resources = 1,
87 .resources = &cs5535_mfd_resources[PMS_BAR],
1310e6d6
AS
88
89 .enable = cs5535_mfd_res_enable,
90 .disable = cs5535_mfd_res_disable,
f71e1afd
AS
91 },
92 {
93 .id = ACPI_BAR,
94 .name = "cs5535-acpi",
95 .num_resources = 1,
96 .resources = &cs5535_mfd_resources[ACPI_BAR],
1310e6d6
AS
97
98 .enable = cs5535_mfd_res_enable,
99 .disable = cs5535_mfd_res_disable,
f71e1afd
AS
100 },
101};
102
fa1df691 103#ifdef CONFIG_OLPC
f791be49 104static void cs5535_clone_olpc_cells(void)
fa1df691 105{
740c1989
LJ
106 static const char *acpi_clones[] = {
107 "olpc-xo1-pm-acpi",
108 "olpc-xo1-sci-acpi"
109 };
fa1df691
AS
110
111 if (!machine_is_olpc())
112 return;
113
114 mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones));
fa1df691
AS
115}
116#else
117static void cs5535_clone_olpc_cells(void) { }
118#endif
119
f791be49 120static int cs5535_mfd_probe(struct pci_dev *pdev,
f71e1afd
AS
121 const struct pci_device_id *id)
122{
123 int err, i;
124
125 err = pci_enable_device(pdev);
126 if (err)
127 return err;
128
129 /* fill in IO range for each cell; subdrivers handle the region */
130 for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) {
131 int bar = cs5535_mfd_cells[i].id;
132 struct resource *r = &cs5535_mfd_resources[bar];
133
134 r->flags = IORESOURCE_IO;
135 r->start = pci_resource_start(pdev, bar);
136 r->end = pci_resource_end(pdev, bar);
137
138 /* id is used for temporarily storing BAR; unset it now */
139 cs5535_mfd_cells[i].id = 0;
140 }
141
142 err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
0848c94f 143 ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
f71e1afd
AS
144 if (err) {
145 dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
146 goto err_disable;
147 }
fa1df691 148 cs5535_clone_olpc_cells();
f71e1afd 149
816b4580 150 dev_info(&pdev->dev, "%zu devices registered.\n",
f71e1afd
AS
151 ARRAY_SIZE(cs5535_mfd_cells));
152
153 return 0;
154
155err_disable:
156 pci_disable_device(pdev);
157 return err;
158}
159
4740f73f 160static void cs5535_mfd_remove(struct pci_dev *pdev)
f71e1afd
AS
161{
162 mfd_remove_devices(&pdev->dev);
163 pci_disable_device(pdev);
164}
165
36fcd06c 166static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
f71e1afd
AS
167 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
168 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
169 { 0, }
170};
171MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
172
97e43c98 173static struct pci_driver cs5535_mfd_driver = {
f71e1afd
AS
174 .name = DRV_NAME,
175 .id_table = cs5535_mfd_pci_tbl,
176 .probe = cs5535_mfd_probe,
84449216 177 .remove = cs5535_mfd_remove,
f71e1afd
AS
178};
179
38a36f5a 180module_pci_driver(cs5535_mfd_driver);
f71e1afd
AS
181
182MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
183MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
184MODULE_LICENSE("GPL");