sta2x11-mfd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Copyright (c) 2009-2011 Wind River Systems, Inc.
  3. * Copyright (c) 2011 ST Microelectronics (Alessandro Rubini, Davide Ciminaghi)
  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. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/errno.h>
  23. #include <linux/device.h>
  24. #include <linux/slab.h>
  25. #include <linux/list.h>
  26. #include <linux/io.h>
  27. #include <linux/ioport.h>
  28. #include <linux/pci.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/mfd/core.h>
  32. #include <linux/mfd/sta2x11-mfd.h>
  33. #include <linux/regmap.h>
  34. #include <asm/sta2x11.h>
  35. static inline int __reg_within_range(unsigned int r,
  36. unsigned int start,
  37. unsigned int end)
  38. {
  39. return ((r >= start) && (r <= end));
  40. }
  41. /* This describes STA2X11 MFD chip for us, we may have several */
  42. struct sta2x11_mfd {
  43. struct sta2x11_instance *instance;
  44. struct regmap *regmap[sta2x11_n_mfd_plat_devs];
  45. spinlock_t lock[sta2x11_n_mfd_plat_devs];
  46. struct list_head list;
  47. void __iomem *regs[sta2x11_n_mfd_plat_devs];
  48. };
  49. static LIST_HEAD(sta2x11_mfd_list);
  50. /* Three functions to act on the list */
  51. static struct sta2x11_mfd *sta2x11_mfd_find(struct pci_dev *pdev)
  52. {
  53. struct sta2x11_instance *instance;
  54. struct sta2x11_mfd *mfd;
  55. if (!pdev && !list_empty(&sta2x11_mfd_list)) {
  56. pr_warning("%s: Unspecified device, "
  57. "using first instance\n", __func__);
  58. return list_entry(sta2x11_mfd_list.next,
  59. struct sta2x11_mfd, list);
  60. }
  61. instance = sta2x11_get_instance(pdev);
  62. if (!instance)
  63. return NULL;
  64. list_for_each_entry(mfd, &sta2x11_mfd_list, list) {
  65. if (mfd->instance == instance)
  66. return mfd;
  67. }
  68. return NULL;
  69. }
  70. static int sta2x11_mfd_add(struct pci_dev *pdev, gfp_t flags)
  71. {
  72. int i;
  73. struct sta2x11_mfd *mfd = sta2x11_mfd_find(pdev);
  74. struct sta2x11_instance *instance;
  75. if (mfd)
  76. return -EBUSY;
  77. instance = sta2x11_get_instance(pdev);
  78. if (!instance)
  79. return -EINVAL;
  80. mfd = kzalloc(sizeof(*mfd), flags);
  81. if (!mfd)
  82. return -ENOMEM;
  83. INIT_LIST_HEAD(&mfd->list);
  84. for (i = 0; i < ARRAY_SIZE(mfd->lock); i++)
  85. spin_lock_init(&mfd->lock[i]);
  86. mfd->instance = instance;
  87. list_add(&mfd->list, &sta2x11_mfd_list);
  88. return 0;
  89. }
  90. /* This function is exported and is not expected to fail */
  91. u32 __sta2x11_mfd_mask(struct pci_dev *pdev, u32 reg, u32 mask, u32 val,
  92. enum sta2x11_mfd_plat_dev index)
  93. {
  94. struct sta2x11_mfd *mfd = sta2x11_mfd_find(pdev);
  95. u32 r;
  96. unsigned long flags;
  97. void __iomem *regs;
  98. if (!mfd) {
  99. dev_warn(&pdev->dev, ": can't access sctl regs\n");
  100. return 0;
  101. }
  102. regs = mfd->regs[index];
  103. if (!regs) {
  104. dev_warn(&pdev->dev, ": system ctl not initialized\n");
  105. return 0;
  106. }
  107. spin_lock_irqsave(&mfd->lock[index], flags);
  108. r = readl(regs + reg);
  109. r &= ~mask;
  110. r |= val;
  111. if (mask)
  112. writel(r, regs + reg);
  113. spin_unlock_irqrestore(&mfd->lock[index], flags);
  114. return r;
  115. }
  116. EXPORT_SYMBOL(__sta2x11_mfd_mask);
  117. int sta2x11_mfd_get_regs_data(struct platform_device *dev,
  118. enum sta2x11_mfd_plat_dev index,
  119. void __iomem **regs,
  120. spinlock_t **lock)
  121. {
  122. struct pci_dev *pdev = *(struct pci_dev **)dev_get_platdata(&dev->dev);
  123. struct sta2x11_mfd *mfd;
  124. if (!pdev)
  125. return -ENODEV;
  126. mfd = sta2x11_mfd_find(pdev);
  127. if (!mfd)
  128. return -ENODEV;
  129. if (index >= sta2x11_n_mfd_plat_devs)
  130. return -ENODEV;
  131. *regs = mfd->regs[index];
  132. *lock = &mfd->lock[index];
  133. pr_debug("%s %d *regs = %p\n", __func__, __LINE__, *regs);
  134. return *regs ? 0 : -ENODEV;
  135. }
  136. EXPORT_SYMBOL(sta2x11_mfd_get_regs_data);
  137. /*
  138. * Special sta2x11-mfd regmap lock/unlock functions
  139. */
  140. static void sta2x11_regmap_lock(void *__lock)
  141. {
  142. spinlock_t *lock = __lock;
  143. spin_lock(lock);
  144. }
  145. static void sta2x11_regmap_unlock(void *__lock)
  146. {
  147. spinlock_t *lock = __lock;
  148. spin_unlock(lock);
  149. }
  150. /* OTP (one time programmable registers do not require locking */
  151. static void sta2x11_regmap_nolock(void *__lock)
  152. {
  153. }
  154. static const char *sta2x11_mfd_names[sta2x11_n_mfd_plat_devs] = {
  155. [sta2x11_sctl] = STA2X11_MFD_SCTL_NAME,
  156. [sta2x11_apbreg] = STA2X11_MFD_APBREG_NAME,
  157. [sta2x11_apb_soc_regs] = STA2X11_MFD_APB_SOC_REGS_NAME,
  158. [sta2x11_scr] = STA2X11_MFD_SCR_NAME,
  159. };
  160. static bool sta2x11_sctl_writeable_reg(struct device *dev, unsigned int reg)
  161. {
  162. return !__reg_within_range(reg, SCTL_SCPCIECSBRST, SCTL_SCRSTSTA);
  163. }
  164. static struct regmap_config sta2x11_sctl_regmap_config = {
  165. .reg_bits = 32,
  166. .reg_stride = 4,
  167. .val_bits = 32,
  168. .lock = sta2x11_regmap_lock,
  169. .unlock = sta2x11_regmap_unlock,
  170. .max_register = SCTL_SCRSTSTA,
  171. .writeable_reg = sta2x11_sctl_writeable_reg,
  172. };
  173. static bool sta2x11_scr_readable_reg(struct device *dev, unsigned int reg)
  174. {
  175. return (reg == STA2X11_SECR_CR) ||
  176. __reg_within_range(reg, STA2X11_SECR_FVR0, STA2X11_SECR_FVR1);
  177. }
  178. static bool sta2x11_scr_writeable_reg(struct device *dev, unsigned int reg)
  179. {
  180. return false;
  181. }
  182. static struct regmap_config sta2x11_scr_regmap_config = {
  183. .reg_bits = 32,
  184. .reg_stride = 4,
  185. .val_bits = 32,
  186. .lock = sta2x11_regmap_nolock,
  187. .unlock = sta2x11_regmap_nolock,
  188. .max_register = STA2X11_SECR_FVR1,
  189. .readable_reg = sta2x11_scr_readable_reg,
  190. .writeable_reg = sta2x11_scr_writeable_reg,
  191. };
  192. static bool sta2x11_apbreg_readable_reg(struct device *dev, unsigned int reg)
  193. {
  194. /* Two blocks (CAN and MLB, SARAC) 0x100 bytes apart */
  195. if (reg >= APBREG_BSR_SARAC)
  196. reg -= APBREG_BSR_SARAC;
  197. switch (reg) {
  198. case APBREG_BSR:
  199. case APBREG_PAER:
  200. case APBREG_PWAC:
  201. case APBREG_PRAC:
  202. case APBREG_PCG:
  203. case APBREG_PUR:
  204. case APBREG_EMU_PCG:
  205. return true;
  206. default:
  207. return false;
  208. }
  209. }
  210. static bool sta2x11_apbreg_writeable_reg(struct device *dev, unsigned int reg)
  211. {
  212. if (reg >= APBREG_BSR_SARAC)
  213. reg -= APBREG_BSR_SARAC;
  214. if (!sta2x11_apbreg_readable_reg(dev, reg))
  215. return false;
  216. return reg != APBREG_PAER;
  217. }
  218. static struct regmap_config sta2x11_apbreg_regmap_config = {
  219. .reg_bits = 32,
  220. .reg_stride = 4,
  221. .val_bits = 32,
  222. .lock = sta2x11_regmap_lock,
  223. .unlock = sta2x11_regmap_unlock,
  224. .max_register = APBREG_EMU_PCG_SARAC,
  225. .readable_reg = sta2x11_apbreg_readable_reg,
  226. .writeable_reg = sta2x11_apbreg_writeable_reg,
  227. };
  228. static bool sta2x11_apb_soc_regs_readable_reg(struct device *dev,
  229. unsigned int reg)
  230. {
  231. return reg <= PCIE_SoC_INT_ROUTER_STATUS3_REG ||
  232. __reg_within_range(reg, DMA_IP_CTRL_REG, SPARE3_RESERVED) ||
  233. __reg_within_range(reg, MASTER_LOCK_REG,
  234. SYSTEM_CONFIG_STATUS_REG) ||
  235. reg == MSP_CLK_CTRL_REG ||
  236. __reg_within_range(reg, COMPENSATION_REG1, TEST_CTL_REG);
  237. }
  238. static bool sta2x11_apb_soc_regs_writeable_reg(struct device *dev,
  239. unsigned int reg)
  240. {
  241. if (!sta2x11_apb_soc_regs_readable_reg(dev, reg))
  242. return false;
  243. switch (reg) {
  244. case PCIE_COMMON_CLOCK_CONFIG_0_4_0:
  245. case SYSTEM_CONFIG_STATUS_REG:
  246. case COMPENSATION_REG1:
  247. case PCIE_SoC_INT_ROUTER_STATUS0_REG...PCIE_SoC_INT_ROUTER_STATUS3_REG:
  248. case PCIE_PM_STATUS_0_PORT_0_4...PCIE_PM_STATUS_7_0_EP4:
  249. return false;
  250. default:
  251. return true;
  252. }
  253. }
  254. static struct regmap_config sta2x11_apb_soc_regs_regmap_config = {
  255. .reg_bits = 32,
  256. .reg_stride = 4,
  257. .val_bits = 32,
  258. .lock = sta2x11_regmap_lock,
  259. .unlock = sta2x11_regmap_unlock,
  260. .max_register = TEST_CTL_REG,
  261. .readable_reg = sta2x11_apb_soc_regs_readable_reg,
  262. .writeable_reg = sta2x11_apb_soc_regs_writeable_reg,
  263. };
  264. static struct regmap_config *
  265. sta2x11_mfd_regmap_configs[sta2x11_n_mfd_plat_devs] = {
  266. [sta2x11_sctl] = &sta2x11_sctl_regmap_config,
  267. [sta2x11_apbreg] = &sta2x11_apbreg_regmap_config,
  268. [sta2x11_apb_soc_regs] = &sta2x11_apb_soc_regs_regmap_config,
  269. [sta2x11_scr] = &sta2x11_scr_regmap_config,
  270. };
  271. /* Probe for the four platform devices */
  272. static int sta2x11_mfd_platform_probe(struct platform_device *dev,
  273. enum sta2x11_mfd_plat_dev index)
  274. {
  275. struct pci_dev **pdev;
  276. struct sta2x11_mfd *mfd;
  277. struct resource *res;
  278. const char *name = sta2x11_mfd_names[index];
  279. struct regmap_config *regmap_config = sta2x11_mfd_regmap_configs[index];
  280. pdev = dev_get_platdata(&dev->dev);
  281. mfd = sta2x11_mfd_find(*pdev);
  282. if (!mfd)
  283. return -ENODEV;
  284. if (!regmap_config)
  285. return -ENODEV;
  286. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  287. if (!res)
  288. return -ENOMEM;
  289. if (!request_mem_region(res->start, resource_size(res), name))
  290. return -EBUSY;
  291. mfd->regs[index] = ioremap(res->start, resource_size(res));
  292. if (!mfd->regs[index]) {
  293. release_mem_region(res->start, resource_size(res));
  294. return -ENOMEM;
  295. }
  296. regmap_config->lock_arg = &mfd->lock;
  297. /*
  298. No caching, registers could be reached both via regmap and via
  299. void __iomem *
  300. */
  301. regmap_config->cache_type = REGCACHE_NONE;
  302. mfd->regmap[index] = devm_regmap_init_mmio(&dev->dev, mfd->regs[index],
  303. regmap_config);
  304. WARN_ON(!mfd->regmap[index]);
  305. return 0;
  306. }
  307. static int sta2x11_sctl_probe(struct platform_device *dev)
  308. {
  309. return sta2x11_mfd_platform_probe(dev, sta2x11_sctl);
  310. }
  311. static int sta2x11_apbreg_probe(struct platform_device *dev)
  312. {
  313. return sta2x11_mfd_platform_probe(dev, sta2x11_apbreg);
  314. }
  315. static int sta2x11_apb_soc_regs_probe(struct platform_device *dev)
  316. {
  317. return sta2x11_mfd_platform_probe(dev, sta2x11_apb_soc_regs);
  318. }
  319. static int sta2x11_scr_probe(struct platform_device *dev)
  320. {
  321. return sta2x11_mfd_platform_probe(dev, sta2x11_scr);
  322. }
  323. /* The three platform drivers */
  324. static struct platform_driver sta2x11_sctl_platform_driver = {
  325. .driver = {
  326. .name = STA2X11_MFD_SCTL_NAME,
  327. .owner = THIS_MODULE,
  328. },
  329. .probe = sta2x11_sctl_probe,
  330. };
  331. static int __init sta2x11_sctl_init(void)
  332. {
  333. pr_info("%s\n", __func__);
  334. return platform_driver_register(&sta2x11_sctl_platform_driver);
  335. }
  336. static struct platform_driver sta2x11_platform_driver = {
  337. .driver = {
  338. .name = STA2X11_MFD_APBREG_NAME,
  339. .owner = THIS_MODULE,
  340. },
  341. .probe = sta2x11_apbreg_probe,
  342. };
  343. static int __init sta2x11_apbreg_init(void)
  344. {
  345. pr_info("%s\n", __func__);
  346. return platform_driver_register(&sta2x11_platform_driver);
  347. }
  348. static struct platform_driver sta2x11_apb_soc_regs_platform_driver = {
  349. .driver = {
  350. .name = STA2X11_MFD_APB_SOC_REGS_NAME,
  351. .owner = THIS_MODULE,
  352. },
  353. .probe = sta2x11_apb_soc_regs_probe,
  354. };
  355. static 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. static struct platform_driver sta2x11_scr_platform_driver = {
  361. .driver = {
  362. .name = STA2X11_MFD_SCR_NAME,
  363. .owner = THIS_MODULE,
  364. },
  365. .probe = sta2x11_scr_probe,
  366. };
  367. static int __init sta2x11_scr_init(void)
  368. {
  369. pr_info("%s\n", __func__);
  370. return platform_driver_register(&sta2x11_scr_platform_driver);
  371. }
  372. /*
  373. * What follows are the PCI devices that host the above pdevs.
  374. * Each logic block is 4kB and they are all consecutive: we use this info.
  375. */
  376. /* Mfd 0 device */
  377. /* Mfd 0, Bar 0 */
  378. enum mfd0_bar0_cells {
  379. STA2X11_GPIO_0 = 0,
  380. STA2X11_GPIO_1,
  381. STA2X11_GPIO_2,
  382. STA2X11_GPIO_3,
  383. STA2X11_SCTL,
  384. STA2X11_SCR,
  385. STA2X11_TIME,
  386. };
  387. /* Mfd 0 , Bar 1 */
  388. enum mfd0_bar1_cells {
  389. STA2X11_APBREG = 0,
  390. };
  391. #define CELL_4K(_name, _cell) { \
  392. .name = _name, \
  393. .start = _cell * 4096, .end = _cell * 4096 + 4095, \
  394. .flags = IORESOURCE_MEM, \
  395. }
  396. static const struct resource gpio_resources[] = {
  397. {
  398. /* 4 consecutive cells, 1 driver */
  399. .name = STA2X11_MFD_GPIO_NAME,
  400. .start = 0,
  401. .end = (4 * 4096) - 1,
  402. .flags = IORESOURCE_MEM,
  403. }
  404. };
  405. static const struct resource sctl_resources[] = {
  406. CELL_4K(STA2X11_MFD_SCTL_NAME, STA2X11_SCTL),
  407. };
  408. static const struct resource scr_resources[] = {
  409. CELL_4K(STA2X11_MFD_SCR_NAME, STA2X11_SCR),
  410. };
  411. static const struct resource time_resources[] = {
  412. CELL_4K(STA2X11_MFD_TIME_NAME, STA2X11_TIME),
  413. };
  414. static const struct resource apbreg_resources[] = {
  415. CELL_4K(STA2X11_MFD_APBREG_NAME, STA2X11_APBREG),
  416. };
  417. #define DEV(_name, _r) \
  418. { .name = _name, .num_resources = ARRAY_SIZE(_r), .resources = _r, }
  419. static struct mfd_cell sta2x11_mfd0_bar0[] = {
  420. /* offset 0: we add pdata later */
  421. DEV(STA2X11_MFD_GPIO_NAME, gpio_resources),
  422. DEV(STA2X11_MFD_SCTL_NAME, sctl_resources),
  423. DEV(STA2X11_MFD_SCR_NAME, scr_resources),
  424. DEV(STA2X11_MFD_TIME_NAME, time_resources),
  425. };
  426. static struct mfd_cell sta2x11_mfd0_bar1[] = {
  427. DEV(STA2X11_MFD_APBREG_NAME, apbreg_resources),
  428. };
  429. /* Mfd 1 devices */
  430. /* Mfd 1, Bar 0 */
  431. enum mfd1_bar0_cells {
  432. STA2X11_VIC = 0,
  433. };
  434. /* Mfd 1, Bar 1 */
  435. enum mfd1_bar1_cells {
  436. STA2X11_APB_SOC_REGS = 0,
  437. };
  438. static const struct resource vic_resources[] = {
  439. CELL_4K(STA2X11_MFD_VIC_NAME, STA2X11_VIC),
  440. };
  441. static const struct resource apb_soc_regs_resources[] = {
  442. CELL_4K(STA2X11_MFD_APB_SOC_REGS_NAME, STA2X11_APB_SOC_REGS),
  443. };
  444. static struct mfd_cell sta2x11_mfd1_bar0[] = {
  445. DEV(STA2X11_MFD_VIC_NAME, vic_resources),
  446. };
  447. static struct mfd_cell sta2x11_mfd1_bar1[] = {
  448. DEV(STA2X11_MFD_APB_SOC_REGS_NAME, apb_soc_regs_resources),
  449. };
  450. static int sta2x11_mfd_suspend(struct pci_dev *pdev, pm_message_t state)
  451. {
  452. pci_save_state(pdev);
  453. pci_disable_device(pdev);
  454. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  455. return 0;
  456. }
  457. static int sta2x11_mfd_resume(struct pci_dev *pdev)
  458. {
  459. int err;
  460. pci_set_power_state(pdev, 0);
  461. err = pci_enable_device(pdev);
  462. if (err)
  463. return err;
  464. pci_restore_state(pdev);
  465. return 0;
  466. }
  467. struct sta2x11_mfd_bar_setup_data {
  468. struct mfd_cell *cells;
  469. int ncells;
  470. };
  471. struct sta2x11_mfd_setup_data {
  472. struct sta2x11_mfd_bar_setup_data bars[2];
  473. };
  474. #define STA2X11_MFD0 0
  475. #define STA2X11_MFD1 1
  476. static struct sta2x11_mfd_setup_data mfd_setup_data[] = {
  477. /* Mfd 0: gpio, sctl, scr, timers / apbregs */
  478. [STA2X11_MFD0] = {
  479. .bars = {
  480. [0] = {
  481. .cells = sta2x11_mfd0_bar0,
  482. .ncells = ARRAY_SIZE(sta2x11_mfd0_bar0),
  483. },
  484. [1] = {
  485. .cells = sta2x11_mfd0_bar1,
  486. .ncells = ARRAY_SIZE(sta2x11_mfd0_bar1),
  487. },
  488. },
  489. },
  490. /* Mfd 1: vic / apb-soc-regs */
  491. [STA2X11_MFD1] = {
  492. .bars = {
  493. [0] = {
  494. .cells = sta2x11_mfd1_bar0,
  495. .ncells = ARRAY_SIZE(sta2x11_mfd1_bar0),
  496. },
  497. [1] = {
  498. .cells = sta2x11_mfd1_bar1,
  499. .ncells = ARRAY_SIZE(sta2x11_mfd1_bar1),
  500. },
  501. },
  502. },
  503. };
  504. static void sta2x11_mfd_setup(struct pci_dev *pdev,
  505. struct sta2x11_mfd_setup_data *sd)
  506. {
  507. int i, j;
  508. for (i = 0; i < ARRAY_SIZE(sd->bars); i++)
  509. for (j = 0; j < sd->bars[i].ncells; j++) {
  510. sd->bars[i].cells[j].pdata_size = sizeof(pdev);
  511. sd->bars[i].cells[j].platform_data = &pdev;
  512. }
  513. }
  514. static int sta2x11_mfd_probe(struct pci_dev *pdev,
  515. const struct pci_device_id *pci_id)
  516. {
  517. int err, i;
  518. struct sta2x11_mfd_setup_data *setup_data;
  519. dev_info(&pdev->dev, "%s\n", __func__);
  520. err = pci_enable_device(pdev);
  521. if (err) {
  522. dev_err(&pdev->dev, "Can't enable device.\n");
  523. return err;
  524. }
  525. err = pci_enable_msi(pdev);
  526. if (err)
  527. dev_info(&pdev->dev, "Enable msi failed\n");
  528. setup_data = pci_id->device == PCI_DEVICE_ID_STMICRO_GPIO ?
  529. &mfd_setup_data[STA2X11_MFD0] :
  530. &mfd_setup_data[STA2X11_MFD1];
  531. /* platform data is the pci device for all of them */
  532. sta2x11_mfd_setup(pdev, setup_data);
  533. /* Record this pdev before mfd_add_devices: their probe looks for it */
  534. if (!sta2x11_mfd_find(pdev))
  535. sta2x11_mfd_add(pdev, GFP_ATOMIC);
  536. /* Just 2 bars for all mfd's at present */
  537. for (i = 0; i < 2; i++) {
  538. err = mfd_add_devices(&pdev->dev, -1,
  539. setup_data->bars[i].cells,
  540. setup_data->bars[i].ncells,
  541. &pdev->resource[i],
  542. 0, NULL);
  543. if (err) {
  544. dev_err(&pdev->dev,
  545. "mfd_add_devices[%d] failed: %d\n", i, err);
  546. goto err_disable;
  547. }
  548. }
  549. return 0;
  550. err_disable:
  551. mfd_remove_devices(&pdev->dev);
  552. pci_disable_device(pdev);
  553. pci_disable_msi(pdev);
  554. return err;
  555. }
  556. static DEFINE_PCI_DEVICE_TABLE(sta2x11_mfd_tbl) = {
  557. {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_GPIO)},
  558. {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIC)},
  559. {0,},
  560. };
  561. static struct pci_driver sta2x11_mfd_driver = {
  562. .name = "sta2x11-mfd",
  563. .id_table = sta2x11_mfd_tbl,
  564. .probe = sta2x11_mfd_probe,
  565. .suspend = sta2x11_mfd_suspend,
  566. .resume = sta2x11_mfd_resume,
  567. };
  568. static int __init sta2x11_mfd_init(void)
  569. {
  570. pr_info("%s\n", __func__);
  571. return pci_register_driver(&sta2x11_mfd_driver);
  572. }
  573. /*
  574. * All of this must be ready before "normal" devices like MMCI appear.
  575. * But MFD (the pci device) can't be too early. The following choice
  576. * prepares platform drivers very early and probe the PCI device later,
  577. * but before other PCI devices.
  578. */
  579. subsys_initcall(sta2x11_apbreg_init);
  580. subsys_initcall(sta2x11_sctl_init);
  581. subsys_initcall(sta2x11_apb_soc_regs_init);
  582. subsys_initcall(sta2x11_scr_init);
  583. rootfs_initcall(sta2x11_mfd_init);
  584. MODULE_LICENSE("GPL v2");
  585. MODULE_AUTHOR("Wind River");
  586. MODULE_DESCRIPTION("STA2x11 mfd for GPIO, SCTL and APBREG");
  587. MODULE_DEVICE_TABLE(pci, sta2x11_mfd_tbl);