182c29810SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f71e1afdSAndres Salomon /*
3f71e1afdSAndres Salomon * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges
4f71e1afdSAndres Salomon *
5f71e1afdSAndres Salomon * The CS5535 and CS5536 has an ISA bridge on the PCI bus that is
6f71e1afdSAndres Salomon * used for accessing GPIOs, MFGPTs, ACPI, etc. Each subdevice has
7f71e1afdSAndres Salomon * an IO range that's specified in a single BAR. The BAR order is
8f71e1afdSAndres Salomon * hardcoded in the CS553x specifications.
9f71e1afdSAndres Salomon *
10f71e1afdSAndres Salomon * Copyright (c) 2010 Andres Salomon <dilinger@queued.net>
11f71e1afdSAndres Salomon */
12f71e1afdSAndres Salomon
13f71e1afdSAndres Salomon #include <linux/kernel.h>
14f71e1afdSAndres Salomon #include <linux/mfd/core.h>
15f71e1afdSAndres Salomon #include <linux/module.h>
16f71e1afdSAndres Salomon #include <linux/pci.h>
17fa1df691SAndres Salomon #include <asm/olpc.h>
18f71e1afdSAndres Salomon
19f71e1afdSAndres Salomon #define DRV_NAME "cs5535-mfd"
20f71e1afdSAndres Salomon
21f71e1afdSAndres Salomon enum cs5535_mfd_bars {
22f71e1afdSAndres Salomon SMB_BAR = 0,
23f71e1afdSAndres Salomon GPIO_BAR = 1,
24f71e1afdSAndres Salomon MFGPT_BAR = 2,
25f71e1afdSAndres Salomon PMS_BAR = 4,
26f71e1afdSAndres Salomon ACPI_BAR = 5,
27f71e1afdSAndres Salomon NR_BARS,
28f71e1afdSAndres Salomon };
29f71e1afdSAndres Salomon
30a9e9ce4cSBill Pemberton static struct resource cs5535_mfd_resources[NR_BARS];
31f71e1afdSAndres Salomon
32a9e9ce4cSBill Pemberton static struct mfd_cell cs5535_mfd_cells[] = {
33f71e1afdSAndres Salomon {
34f71e1afdSAndres Salomon .name = "cs5535-smb",
35f71e1afdSAndres Salomon .num_resources = 1,
36f71e1afdSAndres Salomon .resources = &cs5535_mfd_resources[SMB_BAR],
37f71e1afdSAndres Salomon },
38f71e1afdSAndres Salomon {
39f71e1afdSAndres Salomon .name = "cs5535-gpio",
40f71e1afdSAndres Salomon .num_resources = 1,
41f71e1afdSAndres Salomon .resources = &cs5535_mfd_resources[GPIO_BAR],
42f71e1afdSAndres Salomon },
43f71e1afdSAndres Salomon {
44f71e1afdSAndres Salomon .name = "cs5535-mfgpt",
45f71e1afdSAndres Salomon .num_resources = 1,
46f71e1afdSAndres Salomon .resources = &cs5535_mfd_resources[MFGPT_BAR],
47f71e1afdSAndres Salomon },
48f71e1afdSAndres Salomon {
49f71e1afdSAndres Salomon .name = "cs5535-pms",
50f71e1afdSAndres Salomon .num_resources = 1,
51f71e1afdSAndres Salomon .resources = &cs5535_mfd_resources[PMS_BAR],
52f71e1afdSAndres Salomon },
5399cd1059SLee Jones };
5499cd1059SLee Jones
5599cd1059SLee Jones static struct mfd_cell cs5535_olpc_mfd_cells[] = {
56f71e1afdSAndres Salomon {
5799cd1059SLee Jones .name = "olpc-xo1-pm-acpi",
58f71e1afdSAndres Salomon .num_resources = 1,
59f71e1afdSAndres Salomon .resources = &cs5535_mfd_resources[ACPI_BAR],
60f71e1afdSAndres Salomon },
6199cd1059SLee Jones {
6299cd1059SLee Jones .name = "olpc-xo1-sci-acpi",
6399cd1059SLee Jones .num_resources = 1,
6499cd1059SLee Jones .resources = &cs5535_mfd_resources[ACPI_BAR],
6599cd1059SLee Jones },
66740c1989SLee Jones };
67fa1df691SAndres Salomon
cs5535_mfd_probe(struct pci_dev * pdev,const struct pci_device_id * id)68f791be49SBill Pemberton static int cs5535_mfd_probe(struct pci_dev *pdev,
69f71e1afdSAndres Salomon const struct pci_device_id *id)
70f71e1afdSAndres Salomon {
712129e56eSLee Jones int err, bar;
72f71e1afdSAndres Salomon
73f71e1afdSAndres Salomon err = pci_enable_device(pdev);
74f71e1afdSAndres Salomon if (err)
75f71e1afdSAndres Salomon return err;
76f71e1afdSAndres Salomon
772129e56eSLee Jones for (bar = 0; bar < NR_BARS; bar++) {
78f71e1afdSAndres Salomon struct resource *r = &cs5535_mfd_resources[bar];
79f71e1afdSAndres Salomon
80f71e1afdSAndres Salomon r->flags = IORESOURCE_IO;
81f71e1afdSAndres Salomon r->start = pci_resource_start(pdev, bar);
82f71e1afdSAndres Salomon r->end = pci_resource_end(pdev, bar);
83f71e1afdSAndres Salomon }
84f71e1afdSAndres Salomon
852d4ba917SLee Jones err = pci_request_region(pdev, PMS_BAR, DRV_NAME);
862d4ba917SLee Jones if (err) {
872d4ba917SLee Jones dev_err(&pdev->dev, "Failed to request PMS_BAR's IO region\n");
882d4ba917SLee Jones goto err_disable;
892d4ba917SLee Jones }
902d4ba917SLee Jones
91601e4289SLee Jones err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, cs5535_mfd_cells,
920848c94fSMark Brown ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
93f71e1afdSAndres Salomon if (err) {
94601e4289SLee Jones dev_err(&pdev->dev,
95601e4289SLee Jones "Failed to add CS5535 sub-devices: %d\n", err);
962d4ba917SLee Jones goto err_release_pms;
97f71e1afdSAndres Salomon }
98fd54d65dSLubomir Rintel
992d4ba917SLee Jones if (machine_is_olpc()) {
1002d4ba917SLee Jones err = pci_request_region(pdev, ACPI_BAR, DRV_NAME);
1012d4ba917SLee Jones if (err) {
1022d4ba917SLee Jones dev_err(&pdev->dev,
1032d4ba917SLee Jones "Failed to request ACPI_BAR's IO region\n");
1042d4ba917SLee Jones goto err_remove_devices;
1052d4ba917SLee Jones }
1062d4ba917SLee Jones
10799cd1059SLee Jones err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
10899cd1059SLee Jones cs5535_olpc_mfd_cells,
10999cd1059SLee Jones ARRAY_SIZE(cs5535_olpc_mfd_cells),
11099cd1059SLee Jones NULL, 0, NULL);
1112d4ba917SLee Jones if (err) {
11299cd1059SLee Jones dev_err(&pdev->dev,
11399cd1059SLee Jones "Failed to add CS5535 OLPC sub-devices: %d\n",
11499cd1059SLee Jones err);
1152d4ba917SLee Jones goto err_release_acpi;
1162d4ba917SLee Jones }
1172d4ba917SLee Jones }
118f71e1afdSAndres Salomon
119816b4580SAndres Salomon dev_info(&pdev->dev, "%zu devices registered.\n",
120f71e1afdSAndres Salomon ARRAY_SIZE(cs5535_mfd_cells));
121f71e1afdSAndres Salomon
122f71e1afdSAndres Salomon return 0;
123f71e1afdSAndres Salomon
1242d4ba917SLee Jones err_release_acpi:
1252d4ba917SLee Jones pci_release_region(pdev, ACPI_BAR);
1262d4ba917SLee Jones err_remove_devices:
1272d4ba917SLee Jones mfd_remove_devices(&pdev->dev);
1282d4ba917SLee Jones err_release_pms:
1292d4ba917SLee Jones pci_release_region(pdev, PMS_BAR);
130f71e1afdSAndres Salomon err_disable:
131f71e1afdSAndres Salomon pci_disable_device(pdev);
132f71e1afdSAndres Salomon return err;
133f71e1afdSAndres Salomon }
134f71e1afdSAndres Salomon
cs5535_mfd_remove(struct pci_dev * pdev)1354740f73fSBill Pemberton static void cs5535_mfd_remove(struct pci_dev *pdev)
136f71e1afdSAndres Salomon {
137f71e1afdSAndres Salomon mfd_remove_devices(&pdev->dev);
1382d4ba917SLee Jones
1392d4ba917SLee Jones if (machine_is_olpc())
1402d4ba917SLee Jones pci_release_region(pdev, ACPI_BAR);
1412d4ba917SLee Jones
1422d4ba917SLee Jones pci_release_region(pdev, PMS_BAR);
143f71e1afdSAndres Salomon pci_disable_device(pdev);
144f71e1afdSAndres Salomon }
145f71e1afdSAndres Salomon
14636fcd06cSJingoo Han static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
147f71e1afdSAndres Salomon { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
148f71e1afdSAndres Salomon { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
149f71e1afdSAndres Salomon { 0, }
150f71e1afdSAndres Salomon };
151f71e1afdSAndres Salomon MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
152f71e1afdSAndres Salomon
15397e43c98SChristian Gmeiner static struct pci_driver cs5535_mfd_driver = {
154f71e1afdSAndres Salomon .name = DRV_NAME,
155f71e1afdSAndres Salomon .id_table = cs5535_mfd_pci_tbl,
156f71e1afdSAndres Salomon .probe = cs5535_mfd_probe,
15784449216SBill Pemberton .remove = cs5535_mfd_remove,
158f71e1afdSAndres Salomon };
159f71e1afdSAndres Salomon
16038a36f5aSAxel Lin module_pci_driver(cs5535_mfd_driver);
161f71e1afdSAndres Salomon
162f71e1afdSAndres Salomon MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
163f71e1afdSAndres Salomon MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
164f71e1afdSAndres Salomon MODULE_LICENSE("GPL");
165