.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges |
---|
3 | 4 | * |
---|
.. | .. |
---|
7 | 8 | * hardcoded in the CS553x specifications. |
---|
8 | 9 | * |
---|
9 | 10 | * 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 | 11 | */ |
---|
24 | 12 | |
---|
25 | 13 | #include <linux/kernel.h> |
---|
.. | .. |
---|
39 | 27 | NR_BARS, |
---|
40 | 28 | }; |
---|
41 | 29 | |
---|
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 | | - |
---|
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 | | - |
---|
74 | 30 | static struct resource cs5535_mfd_resources[NR_BARS]; |
---|
75 | 31 | |
---|
76 | 32 | static struct mfd_cell cs5535_mfd_cells[] = { |
---|
77 | 33 | { |
---|
78 | | - .id = SMB_BAR, |
---|
79 | 34 | .name = "cs5535-smb", |
---|
80 | 35 | .num_resources = 1, |
---|
81 | 36 | .resources = &cs5535_mfd_resources[SMB_BAR], |
---|
82 | 37 | }, |
---|
83 | 38 | { |
---|
84 | | - .id = GPIO_BAR, |
---|
85 | 39 | .name = "cs5535-gpio", |
---|
86 | 40 | .num_resources = 1, |
---|
87 | 41 | .resources = &cs5535_mfd_resources[GPIO_BAR], |
---|
88 | 42 | }, |
---|
89 | 43 | { |
---|
90 | | - .id = MFGPT_BAR, |
---|
91 | 44 | .name = "cs5535-mfgpt", |
---|
92 | 45 | .num_resources = 1, |
---|
93 | 46 | .resources = &cs5535_mfd_resources[MFGPT_BAR], |
---|
94 | 47 | }, |
---|
95 | 48 | { |
---|
96 | | - .id = PMS_BAR, |
---|
97 | 49 | .name = "cs5535-pms", |
---|
98 | 50 | .num_resources = 1, |
---|
99 | 51 | .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 | 52 | }, |
---|
113 | 53 | }; |
---|
114 | 54 | |
---|
115 | | -#ifdef CONFIG_OLPC |
---|
116 | | -static void cs5535_clone_olpc_cells(void) |
---|
117 | | -{ |
---|
118 | | - static const char *acpi_clones[] = { |
---|
119 | | - "olpc-xo1-pm-acpi", |
---|
120 | | - "olpc-xo1-sci-acpi" |
---|
121 | | - }; |
---|
122 | | - |
---|
123 | | - if (!machine_is_olpc()) |
---|
124 | | - return; |
---|
125 | | - |
---|
126 | | - mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones)); |
---|
127 | | -} |
---|
128 | | -#else |
---|
129 | | -static void cs5535_clone_olpc_cells(void) { } |
---|
130 | | -#endif |
---|
| 55 | +static 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 | +}; |
---|
131 | 67 | |
---|
132 | 68 | static int cs5535_mfd_probe(struct pci_dev *pdev, |
---|
133 | 69 | const struct pci_device_id *id) |
---|
134 | 70 | { |
---|
135 | | - int err, i; |
---|
| 71 | + int err, bar; |
---|
136 | 72 | |
---|
137 | 73 | err = pci_enable_device(pdev); |
---|
138 | 74 | if (err) |
---|
139 | 75 | return err; |
---|
140 | 76 | |
---|
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; |
---|
| 77 | + for (bar = 0; bar < NR_BARS; bar++) { |
---|
144 | 78 | struct resource *r = &cs5535_mfd_resources[bar]; |
---|
145 | 79 | |
---|
146 | 80 | r->flags = IORESOURCE_IO; |
---|
147 | 81 | r->start = pci_resource_start(pdev, bar); |
---|
148 | 82 | r->end = pci_resource_end(pdev, bar); |
---|
149 | | - |
---|
150 | | - /* id is used for temporarily storing BAR; unset it now */ |
---|
151 | | - cs5535_mfd_cells[i].id = 0; |
---|
152 | 83 | } |
---|
153 | 84 | |
---|
154 | | - err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells, |
---|
155 | | - ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL); |
---|
| 85 | + err = pci_request_region(pdev, PMS_BAR, DRV_NAME); |
---|
156 | 86 | if (err) { |
---|
157 | | - dev_err(&pdev->dev, "MFD add devices failed: %d\n", err); |
---|
| 87 | + dev_err(&pdev->dev, "Failed to request PMS_BAR's IO region\n"); |
---|
158 | 88 | goto err_disable; |
---|
159 | 89 | } |
---|
160 | | - cs5535_clone_olpc_cells(); |
---|
| 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 | + } |
---|
161 | 118 | |
---|
162 | 119 | dev_info(&pdev->dev, "%zu devices registered.\n", |
---|
163 | 120 | ARRAY_SIZE(cs5535_mfd_cells)); |
---|
164 | 121 | |
---|
165 | 122 | return 0; |
---|
166 | 123 | |
---|
| 124 | +err_release_acpi: |
---|
| 125 | + pci_release_region(pdev, ACPI_BAR); |
---|
| 126 | +err_remove_devices: |
---|
| 127 | + mfd_remove_devices(&pdev->dev); |
---|
| 128 | +err_release_pms: |
---|
| 129 | + pci_release_region(pdev, PMS_BAR); |
---|
167 | 130 | err_disable: |
---|
168 | 131 | pci_disable_device(pdev); |
---|
169 | 132 | return err; |
---|
.. | .. |
---|
172 | 135 | static void cs5535_mfd_remove(struct pci_dev *pdev) |
---|
173 | 136 | { |
---|
174 | 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); |
---|
175 | 143 | pci_disable_device(pdev); |
---|
176 | 144 | } |
---|
177 | 145 | |
---|