blob: 0cac2013bbf6dcc87b9d5861b972d84863968ec7 [file] [log] [blame]
Alessandro Rubini35bdd292012-04-12 10:48:44 +02001/*
2 * Copyright (c) 2009-2011 Wind River Systems, Inc.
3 * Copyright (c) 2011 ST Microelectronics (Alessandro Rubini)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/spinlock.h>
23#include <linux/errno.h>
24#include <linux/device.h>
25#include <linux/slab.h>
26#include <linux/list.h>
27#include <linux/io.h>
28#include <linux/ioport.h>
29#include <linux/pci.h>
Alessandro Rubini35bdd292012-04-12 10:48:44 +020030#include <linux/seq_file.h>
31#include <linux/platform_device.h>
32#include <linux/mfd/core.h>
33#include <linux/mfd/sta2x11-mfd.h>
Davide Ciminaghid94e2552012-11-09 15:19:53 +010034#include <linux/regmap.h>
Alessandro Rubini35bdd292012-04-12 10:48:44 +020035
36#include <asm/sta2x11.h>
37
Davide Ciminaghid94e2552012-11-09 15:19:53 +010038static inline int __reg_within_range(unsigned int r,
39 unsigned int start,
40 unsigned int end)
41{
42 return ((r >= start) && (r <= end));
43}
44
Alessandro Rubini35bdd292012-04-12 10:48:44 +020045/* This describes STA2X11 MFD chip for us, we may have several */
46struct sta2x11_mfd {
47 struct sta2x11_instance *instance;
Davide Ciminaghid94e2552012-11-09 15:19:53 +010048 struct regmap *regmap[sta2x11_n_mfd_plat_devs];
Alessandro Rubini35bdd292012-04-12 10:48:44 +020049 spinlock_t lock;
50 struct list_head list;
Davide Ciminaghi1950c712012-11-09 15:19:52 +010051 void __iomem *regs[sta2x11_n_mfd_plat_devs];
Alessandro Rubini35bdd292012-04-12 10:48:44 +020052};
53
54static LIST_HEAD(sta2x11_mfd_list);
55
56/* Three functions to act on the list */
57static struct sta2x11_mfd *sta2x11_mfd_find(struct pci_dev *pdev)
58{
59 struct sta2x11_instance *instance;
60 struct sta2x11_mfd *mfd;
61
62 if (!pdev && !list_empty(&sta2x11_mfd_list)) {
63 pr_warning("%s: Unspecified device, "
64 "using first instance\n", __func__);
65 return list_entry(sta2x11_mfd_list.next,
66 struct sta2x11_mfd, list);
67 }
68
69 instance = sta2x11_get_instance(pdev);
70 if (!instance)
71 return NULL;
72 list_for_each_entry(mfd, &sta2x11_mfd_list, list) {
73 if (mfd->instance == instance)
74 return mfd;
75 }
76 return NULL;
77}
78
79static int __devinit sta2x11_mfd_add(struct pci_dev *pdev, gfp_t flags)
80{
81 struct sta2x11_mfd *mfd = sta2x11_mfd_find(pdev);
82 struct sta2x11_instance *instance;
83
84 if (mfd)
85 return -EBUSY;
86 instance = sta2x11_get_instance(pdev);
87 if (!instance)
88 return -EINVAL;
89 mfd = kzalloc(sizeof(*mfd), flags);
90 if (!mfd)
91 return -ENOMEM;
92 INIT_LIST_HEAD(&mfd->list);
93 spin_lock_init(&mfd->lock);
94 mfd->instance = instance;
95 list_add(&mfd->list, &sta2x11_mfd_list);
96 return 0;
97}
98
99static int __devexit mfd_remove(struct pci_dev *pdev)
100{
101 struct sta2x11_mfd *mfd = sta2x11_mfd_find(pdev);
102
103 if (!mfd)
104 return -ENODEV;
105 list_del(&mfd->list);
106 kfree(mfd);
107 return 0;
108}
109
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100110/* This function is exported and is not expected to fail */
111u32 __sta2x11_mfd_mask(struct pci_dev *pdev, u32 reg, u32 mask, u32 val,
112 enum sta2x11_mfd_plat_dev index)
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200113{
114 struct sta2x11_mfd *mfd = sta2x11_mfd_find(pdev);
115 u32 r;
116 unsigned long flags;
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100117 void __iomem *regs = mfd->regs[index];
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200118
119 if (!mfd) {
120 dev_warn(&pdev->dev, ": can't access sctl regs\n");
121 return 0;
122 }
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100123 if (!regs) {
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200124 dev_warn(&pdev->dev, ": system ctl not initialized\n");
125 return 0;
126 }
127 spin_lock_irqsave(&mfd->lock, flags);
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100128 r = readl(regs + reg);
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200129 r &= ~mask;
130 r |= val;
131 if (mask)
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100132 writel(r, regs + reg);
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200133 spin_unlock_irqrestore(&mfd->lock, flags);
134 return r;
135}
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100136EXPORT_SYMBOL(__sta2x11_mfd_mask);
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200137
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100138/*
139 * Special sta2x11-mfd regmap lock/unlock functions
140 */
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200141
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100142static void sta2x11_regmap_lock(void *__lock)
143{
144 spinlock_t *lock = __lock;
145 spin_lock(lock);
146}
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200147
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100148static void sta2x11_regmap_unlock(void *__lock)
149{
150 spinlock_t *lock = __lock;
151 spin_unlock(lock);
152}
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100153
154static const char *sta2x11_mfd_names[sta2x11_n_mfd_plat_devs] = {
155 [sta2x11_sctl] = "sta2x11-sctl",
156 [sta2x11_apbreg] = "sta2x11-apbreg",
157 [sta2x11_apb_soc_regs] = "sta2x11-apb-soc-regs",
158};
159
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100160static bool sta2x11_sctl_writeable_reg(struct device *dev, unsigned int reg)
161{
162 return !__reg_within_range(reg, SCTL_SCPCIECSBRST, SCTL_SCRSTSTA);
163}
164
165static struct regmap_config sta2x11_sctl_regmap_config = {
166 .reg_bits = 32,
167 .reg_stride = 4,
168 .val_bits = 32,
169 .lock = sta2x11_regmap_lock,
170 .unlock = sta2x11_regmap_unlock,
171 .max_register = SCTL_SCRSTSTA,
172 .writeable_reg = sta2x11_sctl_writeable_reg,
173};
174
175static bool sta2x11_apbreg_readable_reg(struct device *dev, unsigned int reg)
176{
177 /* Two blocks (CAN and MLB, SARAC) 0x100 bytes apart */
178 if (reg >= APBREG_BSR_SARAC)
179 reg -= APBREG_BSR_SARAC;
180 switch (reg) {
181 case APBREG_BSR:
182 case APBREG_PAER:
183 case APBREG_PWAC:
184 case APBREG_PRAC:
185 case APBREG_PCG:
186 case APBREG_PUR:
187 case APBREG_EMU_PCG:
188 return true;
189 default:
190 return false;
191 }
192}
193
194static bool sta2x11_apbreg_writeable_reg(struct device *dev, unsigned int reg)
195{
196 if (reg >= APBREG_BSR_SARAC)
197 reg -= APBREG_BSR_SARAC;
198 if (!sta2x11_apbreg_readable_reg(dev, reg))
199 return false;
200 return reg != APBREG_PAER;
201}
202
203static struct regmap_config sta2x11_apbreg_regmap_config = {
204 .reg_bits = 32,
205 .reg_stride = 4,
206 .val_bits = 32,
207 .lock = sta2x11_regmap_lock,
208 .unlock = sta2x11_regmap_unlock,
209 .max_register = APBREG_EMU_PCG_SARAC,
210 .readable_reg = sta2x11_apbreg_readable_reg,
211 .writeable_reg = sta2x11_apbreg_writeable_reg,
212};
213
214static bool sta2x11_apb_soc_regs_readable_reg(struct device *dev,
215 unsigned int reg)
216{
217 return reg <= PCIE_SoC_INT_ROUTER_STATUS3_REG ||
218 __reg_within_range(reg, DMA_IP_CTRL_REG, SPARE3_RESERVED) ||
219 __reg_within_range(reg, MASTER_LOCK_REG,
220 SYSTEM_CONFIG_STATUS_REG) ||
221 reg == MSP_CLK_CTRL_REG ||
222 __reg_within_range(reg, COMPENSATION_REG1, TEST_CTL_REG);
223}
224
225static bool sta2x11_apb_soc_regs_writeable_reg(struct device *dev,
226 unsigned int reg)
227{
228 if (!sta2x11_apb_soc_regs_readable_reg(dev, reg))
229 return false;
230 switch (reg) {
231 case PCIE_COMMON_CLOCK_CONFIG_0_4_0:
232 case SYSTEM_CONFIG_STATUS_REG:
233 case COMPENSATION_REG1:
234 case PCIE_SoC_INT_ROUTER_STATUS0_REG...PCIE_SoC_INT_ROUTER_STATUS3_REG:
235 case PCIE_PM_STATUS_0_PORT_0_4...PCIE_PM_STATUS_7_0_EP4:
236 return false;
237 default:
238 return true;
239 }
240}
241
242static struct regmap_config sta2x11_apb_soc_regs_regmap_config = {
243 .reg_bits = 32,
244 .reg_stride = 4,
245 .val_bits = 32,
246 .lock = sta2x11_regmap_lock,
247 .unlock = sta2x11_regmap_unlock,
248 .max_register = TEST_CTL_REG,
249 .readable_reg = sta2x11_apb_soc_regs_readable_reg,
250 .writeable_reg = sta2x11_apb_soc_regs_writeable_reg,
251};
252
253static struct regmap_config *
254sta2x11_mfd_regmap_configs[sta2x11_n_mfd_plat_devs] = {
255 [sta2x11_sctl] = &sta2x11_sctl_regmap_config,
256 [sta2x11_apbreg] = &sta2x11_apbreg_regmap_config,
257 [sta2x11_apb_soc_regs] = &sta2x11_apb_soc_regs_regmap_config,
258};
259
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100260/* Probe for the three platform devices */
261
262static int sta2x11_mfd_platform_probe(struct platform_device *dev,
263 enum sta2x11_mfd_plat_dev index)
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200264{
265 struct pci_dev **pdev;
266 struct sta2x11_mfd *mfd;
267 struct resource *res;
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100268 const char *name = sta2x11_mfd_names[index];
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100269 struct regmap_config *regmap_config = sta2x11_mfd_regmap_configs[index];
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200270
271 pdev = dev->dev.platform_data;
272 mfd = sta2x11_mfd_find(*pdev);
273 if (!mfd)
274 return -ENODEV;
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100275 if (!regmap_config)
276 return -ENODEV;
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200277
278 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
279 if (!res)
280 return -ENOMEM;
281
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100282 if (!request_mem_region(res->start, resource_size(res), name))
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200283 return -EBUSY;
284
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100285 mfd->regs[index] = ioremap(res->start, resource_size(res));
286 if (!mfd->regs[index]) {
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200287 release_mem_region(res->start, resource_size(res));
288 return -ENOMEM;
289 }
Davide Ciminaghid94e2552012-11-09 15:19:53 +0100290 regmap_config->lock_arg = &mfd->lock;
291 /*
292 No caching, registers could be reached both via regmap and via
293 void __iomem *
294 */
295 regmap_config->cache_type = REGCACHE_NONE;
296 mfd->regmap[index] = devm_regmap_init_mmio(&dev->dev, mfd->regs[index],
297 regmap_config);
298 WARN_ON(!mfd->regmap[index]);
299
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200300 return 0;
301}
302
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100303static int sta2x11_sctl_probe(struct platform_device *dev)
304{
305 return sta2x11_mfd_platform_probe(dev, sta2x11_sctl);
306}
307
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200308static int sta2x11_apbreg_probe(struct platform_device *dev)
309{
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100310 return sta2x11_mfd_platform_probe(dev, sta2x11_apbreg);
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200311}
312
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100313static int sta2x11_apb_soc_regs_probe(struct platform_device *dev)
314{
315 return sta2x11_mfd_platform_probe(dev, sta2x11_apb_soc_regs);
316}
317
318/* The three platform drivers */
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200319static struct platform_driver sta2x11_sctl_platform_driver = {
320 .driver = {
321 .name = "sta2x11-sctl",
322 .owner = THIS_MODULE,
323 },
324 .probe = sta2x11_sctl_probe,
325};
326
327static int __init sta2x11_sctl_init(void)
328{
329 pr_info("%s\n", __func__);
330 return platform_driver_register(&sta2x11_sctl_platform_driver);
331}
332
333static struct platform_driver sta2x11_platform_driver = {
334 .driver = {
335 .name = "sta2x11-apbreg",
336 .owner = THIS_MODULE,
337 },
338 .probe = sta2x11_apbreg_probe,
339};
340
341static int __init sta2x11_apbreg_init(void)
342{
343 pr_info("%s\n", __func__);
344 return platform_driver_register(&sta2x11_platform_driver);
345}
346
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100347static struct platform_driver sta2x11_apb_soc_regs_platform_driver = {
348 .driver = {
349 .name = "sta2x11-apb-soc-regs",
350 .owner = THIS_MODULE,
351 },
352 .probe = sta2x11_apb_soc_regs_probe,
353};
354
355static int __init sta2x11_apb_soc_regs_init(void)
356{
357 pr_info("%s\n", __func__);
358 return platform_driver_register(&sta2x11_apb_soc_regs_platform_driver);
359}
360
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200361/*
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100362 * What follows are the PCI devices that host the above pdevs.
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200363 * Each logic block is 4kB and they are all consecutive: we use this info.
364 */
365
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100366/* Mfd 0 device */
367
368/* Mfd 0, Bar 0 */
369enum mfd0_bar0_cells {
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200370 STA2X11_GPIO_0 = 0,
371 STA2X11_GPIO_1,
372 STA2X11_GPIO_2,
373 STA2X11_GPIO_3,
374 STA2X11_SCTL,
375 STA2X11_SCR,
376 STA2X11_TIME,
377};
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100378/* Mfd 0 , Bar 1 */
379enum mfd0_bar1_cells {
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200380 STA2X11_APBREG = 0,
381};
382#define CELL_4K(_name, _cell) { \
383 .name = _name, \
384 .start = _cell * 4096, .end = _cell * 4096 + 4095, \
385 .flags = IORESOURCE_MEM, \
386 }
387
388static const __devinitconst struct resource gpio_resources[] = {
389 {
390 .name = "sta2x11_gpio", /* 4 consecutive cells, 1 driver */
391 .start = 0,
392 .end = (4 * 4096) - 1,
393 .flags = IORESOURCE_MEM,
394 }
395};
396static const __devinitconst struct resource sctl_resources[] = {
397 CELL_4K("sta2x11-sctl", STA2X11_SCTL),
398};
399static const __devinitconst struct resource scr_resources[] = {
400 CELL_4K("sta2x11-scr", STA2X11_SCR),
401};
402static const __devinitconst struct resource time_resources[] = {
403 CELL_4K("sta2x11-time", STA2X11_TIME),
404};
405
406static const __devinitconst struct resource apbreg_resources[] = {
407 CELL_4K("sta2x11-apbreg", STA2X11_APBREG),
408};
409
410#define DEV(_name, _r) \
411 { .name = _name, .num_resources = ARRAY_SIZE(_r), .resources = _r, }
412
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100413static __devinitdata struct mfd_cell sta2x11_mfd0_bar0[] = {
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200414 DEV("sta2x11-gpio", gpio_resources), /* offset 0: we add pdata later */
415 DEV("sta2x11-sctl", sctl_resources),
416 DEV("sta2x11-scr", scr_resources),
417 DEV("sta2x11-time", time_resources),
418};
419
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100420static __devinitdata struct mfd_cell sta2x11_mfd0_bar1[] = {
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200421 DEV("sta2x11-apbreg", apbreg_resources),
422};
423
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100424/* Mfd 1 devices */
425
426/* Mfd 1, Bar 0 */
427enum mfd1_bar0_cells {
428 STA2X11_VIC = 0,
429};
430
431/* Mfd 1, Bar 1 */
432enum mfd1_bar1_cells {
433 STA2X11_APB_SOC_REGS = 0,
434};
435
436static const __devinitconst struct resource vic_resources[] = {
437 CELL_4K("sta2x11-vic", STA2X11_VIC),
438};
439
440static const __devinitconst struct resource apb_soc_regs_resources[] = {
441 CELL_4K("sta2x11-apb-soc-regs", STA2X11_APB_SOC_REGS),
442};
443
444static __devinitdata struct mfd_cell sta2x11_mfd1_bar0[] = {
445 DEV("sta2x11-vic", vic_resources),
446};
447
448static __devinitdata struct mfd_cell sta2x11_mfd1_bar1[] = {
449 DEV("sta2x11-apb-soc-regs", apb_soc_regs_resources),
450};
451
452
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200453static int sta2x11_mfd_suspend(struct pci_dev *pdev, pm_message_t state)
454{
455 pci_save_state(pdev);
456 pci_disable_device(pdev);
457 pci_set_power_state(pdev, pci_choose_state(pdev, state));
458
459 return 0;
460}
461
462static int sta2x11_mfd_resume(struct pci_dev *pdev)
463{
464 int err;
465
466 pci_set_power_state(pdev, 0);
467 err = pci_enable_device(pdev);
468 if (err)
469 return err;
470 pci_restore_state(pdev);
471
472 return 0;
473}
474
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100475struct sta2x11_mfd_bar_setup_data {
476 struct mfd_cell *cells;
477 int ncells;
478};
479
480struct sta2x11_mfd_setup_data {
481 struct sta2x11_mfd_bar_setup_data bars[2];
482};
483
484#define STA2X11_MFD0 0
485#define STA2X11_MFD1 1
486
487static struct sta2x11_mfd_setup_data mfd_setup_data[] = {
488 /* Mfd 0: gpio, sctl, scr, timers / apbregs */
489 [STA2X11_MFD0] = {
490 .bars = {
491 [0] = {
492 .cells = sta2x11_mfd0_bar0,
493 .ncells = ARRAY_SIZE(sta2x11_mfd0_bar0),
494 },
495 [1] = {
496 .cells = sta2x11_mfd0_bar1,
497 .ncells = ARRAY_SIZE(sta2x11_mfd0_bar1),
498 },
499 },
500 },
501 /* Mfd 1: vic / apb-soc-regs */
502 [STA2X11_MFD1] = {
503 .bars = {
504 [0] = {
505 .cells = sta2x11_mfd1_bar0,
506 .ncells = ARRAY_SIZE(sta2x11_mfd1_bar0),
507 },
508 [1] = {
509 .cells = sta2x11_mfd1_bar1,
510 .ncells = ARRAY_SIZE(sta2x11_mfd1_bar1),
511 },
512 },
513 },
514};
515
516static void __devinit sta2x11_mfd_setup(struct pci_dev *pdev,
517 struct sta2x11_mfd_setup_data *sd)
518{
519 int i, j;
520 for (i = 0; i < ARRAY_SIZE(sd->bars); i++)
521 for (j = 0; j < sd->bars[i].ncells; j++) {
522 sd->bars[i].cells[j].pdata_size = sizeof(pdev);
523 sd->bars[i].cells[j].platform_data = &pdev;
524 }
525}
526
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200527static int __devinit sta2x11_mfd_probe(struct pci_dev *pdev,
528 const struct pci_device_id *pci_id)
529{
530 int err, i;
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100531 struct sta2x11_mfd_setup_data *setup_data;
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200532 struct sta2x11_gpio_pdata *gpio_data;
533
534 dev_info(&pdev->dev, "%s\n", __func__);
535
536 err = pci_enable_device(pdev);
537 if (err) {
538 dev_err(&pdev->dev, "Can't enable device.\n");
539 return err;
540 }
541
542 err = pci_enable_msi(pdev);
543 if (err)
544 dev_info(&pdev->dev, "Enable msi failed\n");
545
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100546 setup_data = pci_id->device == PCI_DEVICE_ID_STMICRO_GPIO ?
547 &mfd_setup_data[STA2X11_MFD0] :
548 &mfd_setup_data[STA2X11_MFD1];
549
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200550 /* Read gpio config data as pci device's platform data */
551 gpio_data = dev_get_platdata(&pdev->dev);
552 if (!gpio_data)
553 dev_warn(&pdev->dev, "no gpio configuration\n");
554
555 dev_dbg(&pdev->dev, "%s, gpio_data = %p (%p)\n", __func__,
556 gpio_data, &gpio_data);
557 dev_dbg(&pdev->dev, "%s, pdev = %p (%p)\n", __func__,
558 pdev, &pdev);
559
560 /* platform data is the pci device for all of them */
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100561 sta2x11_mfd_setup(pdev, setup_data);
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200562
563 /* Record this pdev before mfd_add_devices: their probe looks for it */
564 sta2x11_mfd_add(pdev, GFP_ATOMIC);
565
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100566 /* Just 2 bars for all mfd's at present */
567 for (i = 0; i < 2; i++) {
568 err = mfd_add_devices(&pdev->dev, -1,
569 setup_data->bars[i].cells,
570 setup_data->bars[i].ncells,
571 &pdev->resource[i],
572 0, NULL);
573 if (err) {
574 dev_err(&pdev->dev,
575 "mfd_add_devices[%d] failed: %d\n", i, err);
576 goto err_disable;
577 }
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200578 }
579
580 return 0;
581
582err_disable:
583 mfd_remove_devices(&pdev->dev);
584 pci_disable_device(pdev);
585 pci_disable_msi(pdev);
586 return err;
587}
588
589static DEFINE_PCI_DEVICE_TABLE(sta2x11_mfd_tbl) = {
590 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_GPIO)},
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100591 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIC)},
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200592 {0,},
593};
594
595static struct pci_driver sta2x11_mfd_driver = {
596 .name = "sta2x11-mfd",
597 .id_table = sta2x11_mfd_tbl,
598 .probe = sta2x11_mfd_probe,
599 .suspend = sta2x11_mfd_suspend,
600 .resume = sta2x11_mfd_resume,
601};
602
603static int __init sta2x11_mfd_init(void)
604{
605 pr_info("%s\n", __func__);
606 return pci_register_driver(&sta2x11_mfd_driver);
607}
608
609/*
610 * All of this must be ready before "normal" devices like MMCI appear.
611 * But MFD (the pci device) can't be too early. The following choice
612 * prepares platform drivers very early and probe the PCI device later,
613 * but before other PCI devices.
614 */
615subsys_initcall(sta2x11_apbreg_init);
616subsys_initcall(sta2x11_sctl_init);
Davide Ciminaghi1950c712012-11-09 15:19:52 +0100617subsys_initcall(sta2x11_apb_soc_regs_init);
Alessandro Rubini35bdd292012-04-12 10:48:44 +0200618rootfs_initcall(sta2x11_mfd_init);
619
620MODULE_LICENSE("GPL v2");
621MODULE_AUTHOR("Wind River");
622MODULE_DESCRIPTION("STA2x11 mfd for GPIO, SCTL and APBREG");
623MODULE_DEVICE_TABLE(pci, sta2x11_mfd_tbl);