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