Thomas Gleixner | 82c2981 | 2019-05-28 09:57:05 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 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> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 14 | #include <linux/mfd/core.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/pci.h> |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 17 | #include <asm/olpc.h> |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 18 | |
| 19 | #define DRV_NAME "cs5535-mfd" |
| 20 | |
| 21 | enum 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 | |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 30 | static 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 | |
| 48 | static int cs5535_mfd_res_disable(struct platform_device *pdev) |
| 49 | { |
| 50 | struct resource *res; |
Lee Jones | 740c1989 | 2015-10-28 16:44:58 +0000 | [diff] [blame] | 51 | |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 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 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 62 | static struct resource cs5535_mfd_resources[NR_BARS]; |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 63 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 64 | static struct mfd_cell cs5535_mfd_cells[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 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], |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 88 | |
| 89 | .enable = cs5535_mfd_res_enable, |
| 90 | .disable = cs5535_mfd_res_disable, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 91 | }, |
| 92 | { |
| 93 | .id = ACPI_BAR, |
| 94 | .name = "cs5535-acpi", |
| 95 | .num_resources = 1, |
| 96 | .resources = &cs5535_mfd_resources[ACPI_BAR], |
Andres Salomon | 1310e6d | 2011-02-17 19:07:36 -0800 | [diff] [blame] | 97 | |
| 98 | .enable = cs5535_mfd_res_enable, |
| 99 | .disable = cs5535_mfd_res_disable, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 100 | }, |
| 101 | }; |
| 102 | |
Lubomir Rintel | fd54d65 | 2019-06-20 13:19:57 +0200 | [diff] [blame] | 103 | static const char *olpc_acpi_clones[] = { |
| 104 | "olpc-xo1-pm-acpi", |
| 105 | "olpc-xo1-sci-acpi" |
| 106 | }; |
Andres Salomon | fa1df69 | 2011-03-21 19:19:35 -0700 | [diff] [blame] | 107 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 108 | static int cs5535_mfd_probe(struct pci_dev *pdev, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 109 | const struct pci_device_id *id) |
| 110 | { |
| 111 | int err, i; |
| 112 | |
| 113 | err = pci_enable_device(pdev); |
| 114 | if (err) |
| 115 | return err; |
| 116 | |
| 117 | /* fill in IO range for each cell; subdrivers handle the region */ |
| 118 | for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) { |
| 119 | int bar = cs5535_mfd_cells[i].id; |
| 120 | struct resource *r = &cs5535_mfd_resources[bar]; |
| 121 | |
| 122 | r->flags = IORESOURCE_IO; |
| 123 | r->start = pci_resource_start(pdev, bar); |
| 124 | r->end = pci_resource_end(pdev, bar); |
| 125 | |
| 126 | /* id is used for temporarily storing BAR; unset it now */ |
| 127 | cs5535_mfd_cells[i].id = 0; |
| 128 | } |
| 129 | |
| 130 | err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 131 | ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 132 | if (err) { |
| 133 | dev_err(&pdev->dev, "MFD add devices failed: %d\n", err); |
| 134 | goto err_disable; |
| 135 | } |
Lubomir Rintel | fd54d65 | 2019-06-20 13:19:57 +0200 | [diff] [blame] | 136 | |
| 137 | if (machine_is_olpc()) |
| 138 | mfd_clone_cell("cs5535-acpi", olpc_acpi_clones, ARRAY_SIZE(olpc_acpi_clones)); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 139 | |
Andres Salomon | 816b458 | 2010-11-30 13:54:39 -0800 | [diff] [blame] | 140 | dev_info(&pdev->dev, "%zu devices registered.\n", |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 141 | ARRAY_SIZE(cs5535_mfd_cells)); |
| 142 | |
| 143 | return 0; |
| 144 | |
| 145 | err_disable: |
| 146 | pci_disable_device(pdev); |
| 147 | return err; |
| 148 | } |
| 149 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 150 | static void cs5535_mfd_remove(struct pci_dev *pdev) |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 151 | { |
| 152 | mfd_remove_devices(&pdev->dev); |
| 153 | pci_disable_device(pdev); |
| 154 | } |
| 155 | |
Jingoo Han | 36fcd06 | 2013-12-03 08:15:39 +0900 | [diff] [blame] | 156 | static const struct pci_device_id cs5535_mfd_pci_tbl[] = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 157 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) }, |
| 158 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, |
| 159 | { 0, } |
| 160 | }; |
| 161 | MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl); |
| 162 | |
Christian Gmeiner | 97e43c9 | 2011-12-13 21:30:04 +0100 | [diff] [blame] | 163 | static struct pci_driver cs5535_mfd_driver = { |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 164 | .name = DRV_NAME, |
| 165 | .id_table = cs5535_mfd_pci_tbl, |
| 166 | .probe = cs5535_mfd_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 167 | .remove = cs5535_mfd_remove, |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 168 | }; |
| 169 | |
Axel Lin | 38a36f5 | 2012-04-03 09:09:19 +0800 | [diff] [blame] | 170 | module_pci_driver(cs5535_mfd_driver); |
Andres Salomon | f71e1af | 2010-11-26 11:52:35 +0100 | [diff] [blame] | 171 | |
| 172 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); |
| 173 | MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device"); |
| 174 | MODULE_LICENSE("GPL"); |