Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 2 | /* |
| 3 | * sp5100_tco : TCO timer driver for sp5100 chipsets |
| 4 | * |
| 5 | * (c) Copyright 2009 Google Inc., All Rights Reserved. |
| 6 | * |
| 7 | * Based on i8xx_tco.c: |
| 8 | * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights |
| 9 | * Reserved. |
Alexander A. Klimov | 2ab77a3 | 2020-07-13 22:58:21 +0200 | [diff] [blame] | 10 | * https://www.kernelconcepts.de |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 11 | * |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 12 | * See AMD Publication 43009 "AMD SB700/710/750 Register Reference Guide", |
| 13 | * AMD Publication 45482 "AMD SB800-Series Southbridges Register |
| 14 | * Reference Guide" |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 15 | * AMD Publication 48751 "BIOS and Kernel Developer’s Guide (BKDG) |
| 16 | * for AMD Family 16h Models 00h-0Fh Processors" |
| 17 | * AMD Publication 51192 "AMD Bolton FCH Register Reference Guide" |
| 18 | * AMD Publication 52740 "BIOS and Kernel Developer’s Guide (BKDG) |
| 19 | * for AMD Family 16h Models 30h-3Fh Processors" |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * Includes, defines, variables, module parameters, ... |
| 24 | */ |
| 25 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 28 | #include <linux/init.h> |
| 29 | #include <linux/io.h> |
| 30 | #include <linux/ioport.h> |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/moduleparam.h> |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 35 | #include <linux/types.h> |
| 36 | #include <linux/watchdog.h> |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 37 | |
| 38 | #include "sp5100_tco.h" |
| 39 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 40 | #define TCO_DRIVER_NAME "sp5100-tco" |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 41 | |
| 42 | /* internal variables */ |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 43 | |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 44 | enum tco_reg_layout { |
| 45 | sp5100, sb800, efch |
| 46 | }; |
| 47 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 48 | struct sp5100_tco { |
| 49 | struct watchdog_device wdd; |
| 50 | void __iomem *tcobase; |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 51 | enum tco_reg_layout tco_reg_layout; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 52 | }; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 53 | |
| 54 | /* the watchdog platform device */ |
| 55 | static struct platform_device *sp5100_tco_platform_device; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 56 | /* the associated PCI device */ |
| 57 | static struct pci_dev *sp5100_tco_pci; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 58 | |
| 59 | /* module parameters */ |
| 60 | |
| 61 | #define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat. */ |
| 62 | static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ |
| 63 | module_param(heartbeat, int, 0); |
| 64 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (default=" |
| 65 | __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); |
| 66 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 67 | static bool nowayout = WATCHDOG_NOWAYOUT; |
| 68 | module_param(nowayout, bool, 0); |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 69 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started." |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 70 | " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 71 | |
| 72 | /* |
| 73 | * Some TCO specific functions |
| 74 | */ |
Lucas Stach | 46856fa | 2016-05-03 19:15:58 +0200 | [diff] [blame] | 75 | |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 76 | static enum tco_reg_layout tco_reg_layout(struct pci_dev *dev) |
Lucas Stach | 46856fa | 2016-05-03 19:15:58 +0200 | [diff] [blame] | 77 | { |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 78 | if (dev->vendor == PCI_VENDOR_ID_ATI && |
| 79 | dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && |
| 80 | dev->revision < 0x40) { |
| 81 | return sp5100; |
| 82 | } else if (dev->vendor == PCI_VENDOR_ID_AMD && |
| 83 | ((dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && |
| 84 | dev->revision >= 0x41) || |
| 85 | (dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && |
| 86 | dev->revision >= 0x49))) { |
| 87 | return efch; |
| 88 | } |
| 89 | return sb800; |
Lucas Stach | 46856fa | 2016-05-03 19:15:58 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 92 | static int tco_timer_start(struct watchdog_device *wdd) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 93 | { |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 94 | struct sp5100_tco *tco = watchdog_get_drvdata(wdd); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 95 | u32 val; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 96 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 97 | val = readl(SP5100_WDT_CONTROL(tco->tcobase)); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 98 | val |= SP5100_WDT_START_STOP_BIT; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 99 | writel(val, SP5100_WDT_CONTROL(tco->tcobase)); |
| 100 | |
| 101 | return 0; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 104 | static int tco_timer_stop(struct watchdog_device *wdd) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 105 | { |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 106 | struct sp5100_tco *tco = watchdog_get_drvdata(wdd); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 107 | u32 val; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 108 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 109 | val = readl(SP5100_WDT_CONTROL(tco->tcobase)); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 110 | val &= ~SP5100_WDT_START_STOP_BIT; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 111 | writel(val, SP5100_WDT_CONTROL(tco->tcobase)); |
| 112 | |
| 113 | return 0; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 116 | static int tco_timer_ping(struct watchdog_device *wdd) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 117 | { |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 118 | struct sp5100_tco *tco = watchdog_get_drvdata(wdd); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 119 | u32 val; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 120 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 121 | val = readl(SP5100_WDT_CONTROL(tco->tcobase)); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 122 | val |= SP5100_WDT_TRIGGER_BIT; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 123 | writel(val, SP5100_WDT_CONTROL(tco->tcobase)); |
| 124 | |
| 125 | return 0; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 128 | static int tco_timer_set_timeout(struct watchdog_device *wdd, |
| 129 | unsigned int t) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 130 | { |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 131 | struct sp5100_tco *tco = watchdog_get_drvdata(wdd); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 132 | |
| 133 | /* Write new heartbeat to watchdog */ |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 134 | writel(t, SP5100_WDT_COUNT(tco->tcobase)); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 135 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 136 | wdd->timeout = t; |
| 137 | |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Guenter Roeck | 2b750cf | 2017-12-24 13:04:06 -0800 | [diff] [blame] | 141 | static u8 sp5100_tco_read_pm_reg8(u8 index) |
| 142 | { |
| 143 | outb(index, SP5100_IO_PM_INDEX_REG); |
| 144 | return inb(SP5100_IO_PM_DATA_REG); |
| 145 | } |
| 146 | |
| 147 | static void sp5100_tco_update_pm_reg8(u8 index, u8 reset, u8 set) |
| 148 | { |
| 149 | u8 val; |
| 150 | |
| 151 | outb(index, SP5100_IO_PM_INDEX_REG); |
| 152 | val = inb(SP5100_IO_PM_DATA_REG); |
| 153 | val &= reset; |
| 154 | val |= set; |
| 155 | outb(val, SP5100_IO_PM_DATA_REG); |
| 156 | } |
| 157 | |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 158 | static void tco_timer_enable(struct sp5100_tco *tco) |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 159 | { |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 160 | u32 val; |
| 161 | |
| 162 | switch (tco->tco_reg_layout) { |
| 163 | case sb800: |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 164 | /* For SB800 or later */ |
| 165 | /* Set the Watchdog timer resolution to 1 sec */ |
Guenter Roeck | 2b750cf | 2017-12-24 13:04:06 -0800 | [diff] [blame] | 166 | sp5100_tco_update_pm_reg8(SB800_PM_WATCHDOG_CONFIG, |
| 167 | 0xff, SB800_PM_WATCHDOG_SECOND_RES); |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 168 | |
| 169 | /* Enable watchdog decode bit and watchdog timer */ |
Guenter Roeck | 2b750cf | 2017-12-24 13:04:06 -0800 | [diff] [blame] | 170 | sp5100_tco_update_pm_reg8(SB800_PM_WATCHDOG_CONTROL, |
| 171 | ~SB800_PM_WATCHDOG_DISABLE, |
| 172 | SB800_PCI_WATCHDOG_DECODE_EN); |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 173 | break; |
| 174 | case sp5100: |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 175 | /* For SP5100 or SB7x0 */ |
| 176 | /* Enable watchdog decode bit */ |
| 177 | pci_read_config_dword(sp5100_tco_pci, |
| 178 | SP5100_PCI_WATCHDOG_MISC_REG, |
| 179 | &val); |
| 180 | |
| 181 | val |= SP5100_PCI_WATCHDOG_DECODE_EN; |
| 182 | |
| 183 | pci_write_config_dword(sp5100_tco_pci, |
| 184 | SP5100_PCI_WATCHDOG_MISC_REG, |
| 185 | val); |
| 186 | |
| 187 | /* Enable Watchdog timer and set the resolution to 1 sec */ |
Guenter Roeck | 2b750cf | 2017-12-24 13:04:06 -0800 | [diff] [blame] | 188 | sp5100_tco_update_pm_reg8(SP5100_PM_WATCHDOG_CONTROL, |
| 189 | ~SP5100_PM_WATCHDOG_DISABLE, |
| 190 | SP5100_PM_WATCHDOG_SECOND_RES); |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 191 | break; |
| 192 | case efch: |
| 193 | /* Set the Watchdog timer resolution to 1 sec and enable */ |
| 194 | sp5100_tco_update_pm_reg8(EFCH_PM_DECODEEN3, |
| 195 | ~EFCH_PM_WATCHDOG_DISABLE, |
| 196 | EFCH_PM_DECODEEN_SECOND_RES); |
| 197 | break; |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 201 | static u32 sp5100_tco_read_pm_reg32(u8 index) |
Guenter Roeck | 2b750cf | 2017-12-24 13:04:06 -0800 | [diff] [blame] | 202 | { |
| 203 | u32 val = 0; |
| 204 | int i; |
| 205 | |
| 206 | for (i = 3; i >= 0; i--) |
| 207 | val = (val << 8) + sp5100_tco_read_pm_reg8(index + i); |
| 208 | |
| 209 | return val; |
| 210 | } |
| 211 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 212 | static int sp5100_tco_setupdevice(struct device *dev, |
| 213 | struct watchdog_device *wdd) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 214 | { |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 215 | struct sp5100_tco *tco = watchdog_get_drvdata(wdd); |
| 216 | const char *dev_name; |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 217 | u32 mmio_addr = 0, val; |
Guenter Roeck | 23dfe14 | 2017-12-24 13:04:09 -0800 | [diff] [blame] | 218 | int ret; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 219 | |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 220 | /* Request the IO ports used by this driver */ |
Guenter Roeck | 16e7730 | 2017-12-24 13:04:08 -0800 | [diff] [blame] | 221 | if (!request_muxed_region(SP5100_IO_PM_INDEX_REG, |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 222 | SP5100_PM_IOPORTS_SIZE, "sp5100_tco")) { |
Guenter Roeck | fd8f909 | 2017-12-24 13:04:12 -0800 | [diff] [blame] | 223 | dev_err(dev, "I/O address 0x%04x already in use\n", |
| 224 | SP5100_IO_PM_INDEX_REG); |
Guenter Roeck | 23dfe14 | 2017-12-24 13:04:09 -0800 | [diff] [blame] | 225 | return -EBUSY; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 228 | /* |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 229 | * Determine type of southbridge chipset. |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 230 | */ |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 231 | switch (tco->tco_reg_layout) { |
| 232 | case sp5100: |
| 233 | dev_name = SP5100_DEVNAME; |
| 234 | mmio_addr = sp5100_tco_read_pm_reg32(SP5100_PM_WATCHDOG_BASE) & |
| 235 | 0xfffffff8; |
| 236 | break; |
| 237 | case sb800: |
| 238 | dev_name = SB800_DEVNAME; |
| 239 | mmio_addr = sp5100_tco_read_pm_reg32(SB800_PM_WATCHDOG_BASE) & |
| 240 | 0xfffffff8; |
| 241 | break; |
| 242 | case efch: |
| 243 | dev_name = SB800_DEVNAME; |
| 244 | val = sp5100_tco_read_pm_reg8(EFCH_PM_DECODEEN); |
| 245 | if (val & EFCH_PM_DECODEEN_WDT_TMREN) |
| 246 | mmio_addr = EFCH_PM_WDT_ADDR; |
| 247 | break; |
| 248 | default: |
| 249 | return -ENODEV; |
| 250 | } |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 251 | |
| 252 | /* Check MMIO address conflict */ |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 253 | if (!mmio_addr || |
| 254 | !devm_request_mem_region(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE, |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 255 | dev_name)) { |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 256 | if (mmio_addr) |
| 257 | dev_dbg(dev, "MMIO address 0x%08x already in use\n", |
| 258 | mmio_addr); |
| 259 | switch (tco->tco_reg_layout) { |
| 260 | case sp5100: |
| 261 | /* |
| 262 | * Secondly, Find the watchdog timer MMIO address |
| 263 | * from SBResource_MMIO register. |
| 264 | */ |
Guenter Roeck | e189410 | 2017-12-24 13:04:10 -0800 | [diff] [blame] | 265 | /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */ |
| 266 | pci_read_config_dword(sp5100_tco_pci, |
| 267 | SP5100_SB_RESOURCE_MMIO_BASE, |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 268 | &mmio_addr); |
| 269 | if ((mmio_addr & (SB800_ACPI_MMIO_DECODE_EN | |
| 270 | SB800_ACPI_MMIO_SEL)) != |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 271 | SB800_ACPI_MMIO_DECODE_EN) { |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 272 | ret = -ENODEV; |
| 273 | goto unreg_region; |
| 274 | } |
| 275 | mmio_addr &= ~0xFFF; |
| 276 | mmio_addr += SB800_PM_WDT_MMIO_OFFSET; |
| 277 | break; |
| 278 | case sb800: |
| 279 | /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */ |
| 280 | mmio_addr = |
| 281 | sp5100_tco_read_pm_reg32(SB800_PM_ACPI_MMIO_EN); |
| 282 | if ((mmio_addr & (SB800_ACPI_MMIO_DECODE_EN | |
| 283 | SB800_ACPI_MMIO_SEL)) != |
| 284 | SB800_ACPI_MMIO_DECODE_EN) { |
| 285 | ret = -ENODEV; |
| 286 | goto unreg_region; |
| 287 | } |
| 288 | mmio_addr &= ~0xFFF; |
| 289 | mmio_addr += SB800_PM_WDT_MMIO_OFFSET; |
| 290 | break; |
| 291 | case efch: |
| 292 | val = sp5100_tco_read_pm_reg8(EFCH_PM_ISACONTROL); |
| 293 | if (!(val & EFCH_PM_ISACONTROL_MMIOEN)) { |
| 294 | ret = -ENODEV; |
| 295 | goto unreg_region; |
| 296 | } |
| 297 | mmio_addr = EFCH_PM_ACPI_MMIO_ADDR + |
| 298 | EFCH_PM_ACPI_MMIO_WDT_OFFSET; |
| 299 | break; |
Guenter Roeck | e189410 | 2017-12-24 13:04:10 -0800 | [diff] [blame] | 300 | } |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 301 | dev_dbg(dev, "Got 0x%08x from SBResource_MMIO register\n", |
| 302 | mmio_addr); |
| 303 | if (!devm_request_mem_region(dev, mmio_addr, |
| 304 | SP5100_WDT_MEM_MAP_SIZE, |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 305 | dev_name)) { |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 306 | dev_dbg(dev, "MMIO address 0x%08x already in use\n", |
| 307 | mmio_addr); |
Guenter Roeck | e189410 | 2017-12-24 13:04:10 -0800 | [diff] [blame] | 308 | ret = -EBUSY; |
| 309 | goto unreg_region; |
| 310 | } |
Guenter Roeck | e189410 | 2017-12-24 13:04:10 -0800 | [diff] [blame] | 311 | } |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 312 | |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 313 | tco->tcobase = devm_ioremap(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE); |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 314 | if (!tco->tcobase) { |
Guenter Roeck | fd8f909 | 2017-12-24 13:04:12 -0800 | [diff] [blame] | 315 | dev_err(dev, "failed to get tcobase address\n"); |
Guenter Roeck | 23dfe14 | 2017-12-24 13:04:09 -0800 | [diff] [blame] | 316 | ret = -ENOMEM; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 317 | goto unreg_region; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 320 | dev_info(dev, "Using 0x%08x for watchdog MMIO address\n", mmio_addr); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 321 | |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 322 | /* Setup the watchdog timer */ |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 323 | tco_timer_enable(tco); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 324 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 325 | val = readl(SP5100_WDT_CONTROL(tco->tcobase)); |
Guenter Roeck | f7781b0 | 2017-12-24 13:04:16 -0800 | [diff] [blame] | 326 | if (val & SP5100_WDT_DISABLED) { |
| 327 | dev_err(dev, "Watchdog hardware is disabled\n"); |
| 328 | ret = -ENODEV; |
| 329 | goto unreg_region; |
| 330 | } |
| 331 | |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 332 | /* |
| 333 | * Save WatchDogFired status, because WatchDogFired flag is |
| 334 | * cleared here. |
| 335 | */ |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 336 | if (val & SP5100_WDT_FIRED) |
| 337 | wdd->bootstatus = WDIOF_CARDRESET; |
Guenter Roeck | f7781b0 | 2017-12-24 13:04:16 -0800 | [diff] [blame] | 338 | /* Set watchdog action to reset the system */ |
Guenter Roeck | 5bbecc5 | 2017-12-24 13:04:13 -0800 | [diff] [blame] | 339 | val &= ~SP5100_WDT_ACTION_RESET; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 340 | writel(val, SP5100_WDT_CONTROL(tco->tcobase)); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 341 | |
| 342 | /* Set a reasonable heartbeat before we stop the timer */ |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 343 | tco_timer_set_timeout(wdd, wdd->timeout); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * Stop the TCO before we change anything so we don't race with |
| 347 | * a zeroed timer. |
| 348 | */ |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 349 | tco_timer_stop(wdd); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 350 | |
Guenter Roeck | 16e7730 | 2017-12-24 13:04:08 -0800 | [diff] [blame] | 351 | release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); |
Guenter Roeck | e189410 | 2017-12-24 13:04:10 -0800 | [diff] [blame] | 352 | |
Guenter Roeck | 23dfe14 | 2017-12-24 13:04:09 -0800 | [diff] [blame] | 353 | return 0; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 354 | |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 355 | unreg_region: |
Guenter Roeck | 2b750cf | 2017-12-24 13:04:06 -0800 | [diff] [blame] | 356 | release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); |
Guenter Roeck | 23dfe14 | 2017-12-24 13:04:09 -0800 | [diff] [blame] | 357 | return ret; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 360 | static struct watchdog_info sp5100_tco_wdt_info = { |
| 361 | .identity = "SP5100 TCO timer", |
| 362 | .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, |
| 363 | }; |
| 364 | |
| 365 | static const struct watchdog_ops sp5100_tco_wdt_ops = { |
| 366 | .owner = THIS_MODULE, |
| 367 | .start = tco_timer_start, |
| 368 | .stop = tco_timer_stop, |
| 369 | .ping = tco_timer_ping, |
| 370 | .set_timeout = tco_timer_set_timeout, |
| 371 | }; |
| 372 | |
Guenter Roeck | 5bbecc5 | 2017-12-24 13:04:13 -0800 | [diff] [blame] | 373 | static int sp5100_tco_probe(struct platform_device *pdev) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 374 | { |
Guenter Roeck | fd8f909 | 2017-12-24 13:04:12 -0800 | [diff] [blame] | 375 | struct device *dev = &pdev->dev; |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 376 | struct watchdog_device *wdd; |
| 377 | struct sp5100_tco *tco; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 378 | int ret; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 379 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 380 | tco = devm_kzalloc(dev, sizeof(*tco), GFP_KERNEL); |
| 381 | if (!tco) |
| 382 | return -ENOMEM; |
| 383 | |
Guenter Roeck | 887d2ec | 2017-12-24 13:04:17 -0800 | [diff] [blame] | 384 | tco->tco_reg_layout = tco_reg_layout(sp5100_tco_pci); |
| 385 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 386 | wdd = &tco->wdd; |
| 387 | wdd->parent = dev; |
| 388 | wdd->info = &sp5100_tco_wdt_info; |
| 389 | wdd->ops = &sp5100_tco_wdt_ops; |
| 390 | wdd->timeout = WATCHDOG_HEARTBEAT; |
| 391 | wdd->min_timeout = 1; |
| 392 | wdd->max_timeout = 0xffff; |
| 393 | |
Wolfram Sang | 2d505e3 | 2019-04-19 20:15:57 +0200 | [diff] [blame] | 394 | watchdog_init_timeout(wdd, heartbeat, NULL); |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 395 | watchdog_set_nowayout(wdd, nowayout); |
| 396 | watchdog_stop_on_reboot(wdd); |
| 397 | watchdog_stop_on_unregister(wdd); |
| 398 | watchdog_set_drvdata(wdd, tco); |
| 399 | |
| 400 | ret = sp5100_tco_setupdevice(dev, wdd); |
Guenter Roeck | 23dfe14 | 2017-12-24 13:04:09 -0800 | [diff] [blame] | 401 | if (ret) |
| 402 | return ret; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 403 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 404 | ret = devm_watchdog_register_device(dev, wdd); |
Wolfram Sang | d41e3f4 | 2019-05-18 23:27:52 +0200 | [diff] [blame] | 405 | if (ret) |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 406 | return ret; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 407 | |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 408 | /* Show module parameters */ |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 409 | dev_info(dev, "initialized. heartbeat=%d sec (nowayout=%d)\n", |
| 410 | wdd->timeout, nowayout); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 411 | |
| 412 | return 0; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static struct platform_driver sp5100_tco_driver = { |
Guenter Roeck | 5bbecc5 | 2017-12-24 13:04:13 -0800 | [diff] [blame] | 416 | .probe = sp5100_tco_probe, |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 417 | .driver = { |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 418 | .name = TCO_DRIVER_NAME, |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 419 | }, |
| 420 | }; |
| 421 | |
Guenter Roeck | a3483443 | 2017-12-24 13:04:11 -0800 | [diff] [blame] | 422 | /* |
| 423 | * Data for PCI driver interface |
| 424 | * |
| 425 | * This data only exists for exporting the supported |
| 426 | * PCI ids via MODULE_DEVICE_TABLE. We do not actually |
| 427 | * register a pci_driver, because someone else might |
| 428 | * want to register another driver on the same PCI id. |
| 429 | */ |
| 430 | static const struct pci_device_id sp5100_tco_pci_tbl[] = { |
| 431 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, PCI_ANY_ID, |
| 432 | PCI_ANY_ID, }, |
| 433 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, PCI_ANY_ID, |
| 434 | PCI_ANY_ID, }, |
| 435 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, PCI_ANY_ID, |
| 436 | PCI_ANY_ID, }, |
| 437 | { 0, }, /* End of list */ |
| 438 | }; |
| 439 | MODULE_DEVICE_TABLE(pci, sp5100_tco_pci_tbl); |
| 440 | |
Guenter Roeck | 5bbecc5 | 2017-12-24 13:04:13 -0800 | [diff] [blame] | 441 | static int __init sp5100_tco_init(void) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 442 | { |
Guenter Roeck | a3483443 | 2017-12-24 13:04:11 -0800 | [diff] [blame] | 443 | struct pci_dev *dev = NULL; |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 444 | int err; |
| 445 | |
Guenter Roeck | a3483443 | 2017-12-24 13:04:11 -0800 | [diff] [blame] | 446 | /* Match the PCI device */ |
| 447 | for_each_pci_dev(dev) { |
| 448 | if (pci_match_id(sp5100_tco_pci_tbl, dev) != NULL) { |
| 449 | sp5100_tco_pci = dev; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if (!sp5100_tco_pci) |
| 455 | return -ENODEV; |
| 456 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 457 | pr_info("SP5100/SB800 TCO WatchDog Timer Driver\n"); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 458 | |
| 459 | err = platform_driver_register(&sp5100_tco_driver); |
| 460 | if (err) |
| 461 | return err; |
| 462 | |
Guenter Roeck | 7cd9d5f | 2017-12-24 13:04:14 -0800 | [diff] [blame] | 463 | sp5100_tco_platform_device = |
| 464 | platform_device_register_simple(TCO_DRIVER_NAME, -1, NULL, 0); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 465 | if (IS_ERR(sp5100_tco_platform_device)) { |
| 466 | err = PTR_ERR(sp5100_tco_platform_device); |
| 467 | goto unreg_platform_driver; |
| 468 | } |
| 469 | |
| 470 | return 0; |
| 471 | |
| 472 | unreg_platform_driver: |
| 473 | platform_driver_unregister(&sp5100_tco_driver); |
| 474 | return err; |
| 475 | } |
| 476 | |
Guenter Roeck | 5bbecc5 | 2017-12-24 13:04:13 -0800 | [diff] [blame] | 477 | static void __exit sp5100_tco_exit(void) |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 478 | { |
| 479 | platform_device_unregister(sp5100_tco_platform_device); |
| 480 | platform_driver_unregister(&sp5100_tco_driver); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Guenter Roeck | 5bbecc5 | 2017-12-24 13:04:13 -0800 | [diff] [blame] | 483 | module_init(sp5100_tco_init); |
| 484 | module_exit(sp5100_tco_exit); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 485 | |
| 486 | MODULE_AUTHOR("Priyanka Gupta"); |
Takahisa Tanaka | 740fbdd | 2012-12-02 14:33:18 +0900 | [diff] [blame] | 487 | MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset"); |
Priyanka Gupta | 15e28bf | 2010-10-25 17:58:04 -0700 | [diff] [blame] | 488 | MODULE_LICENSE("GPL"); |