blob: a730ecbf78cd5d53d3f08bdc919f3abcdec7df88 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Priyanka Gupta15e28bf2010-10-25 17:58:04 -07002/*
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. Klimov2ab77a32020-07-13 22:58:21 +020010 * https://www.kernelconcepts.de
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070011 *
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +090012 * See AMD Publication 43009 "AMD SB700/710/750 Register Reference Guide",
13 * AMD Publication 45482 "AMD SB800-Series Southbridges Register
14 * Reference Guide"
Guenter Roeck887d2ec2017-12-24 13:04:17 -080015 * 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"
Guenter Roeck09da89a2020-09-10 09:31:09 -070020 * AMD Publication 55570-B1-PUB "Processor Programming Reference (PPR)
21 * for AMD Family 17h Model 18h, Revision B1
22 * Processors (PUB)
23 * AMD Publication 55772-A1-PUB "Processor Programming Reference (PPR)
24 * for AMD Family 17h Model 20h, Revision A1
25 * Processors (PUB)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070026 */
27
28/*
29 * Includes, defines, variables, module parameters, ...
30 */
31
Joe Perches27c766a2012-02-15 15:06:19 -080032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080034#include <linux/init.h>
35#include <linux/io.h>
36#include <linux/ioport.h>
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070037#include <linux/module.h>
38#include <linux/moduleparam.h>
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070039#include <linux/pci.h>
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070040#include <linux/platform_device.h>
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080041#include <linux/types.h>
42#include <linux/watchdog.h>
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070043
44#include "sp5100_tco.h"
45
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080046#define TCO_DRIVER_NAME "sp5100-tco"
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070047
48/* internal variables */
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080049
Guenter Roeck887d2ec2017-12-24 13:04:17 -080050enum tco_reg_layout {
51 sp5100, sb800, efch
52};
53
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080054struct sp5100_tco {
55 struct watchdog_device wdd;
56 void __iomem *tcobase;
Guenter Roeck887d2ec2017-12-24 13:04:17 -080057 enum tco_reg_layout tco_reg_layout;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080058};
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070059
60/* the watchdog platform device */
61static struct platform_device *sp5100_tco_platform_device;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080062/* the associated PCI device */
63static struct pci_dev *sp5100_tco_pci;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070064
65/* module parameters */
66
67#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat. */
68static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
69module_param(heartbeat, int, 0);
70MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (default="
71 __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
72
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010073static bool nowayout = WATCHDOG_NOWAYOUT;
74module_param(nowayout, bool, 0);
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +090075MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started."
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070076 " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
77
78/*
79 * Some TCO specific functions
80 */
Lucas Stach46856fa2016-05-03 19:15:58 +020081
Guenter Roeck887d2ec2017-12-24 13:04:17 -080082static enum tco_reg_layout tco_reg_layout(struct pci_dev *dev)
Lucas Stach46856fa2016-05-03 19:15:58 +020083{
Guenter Roeck887d2ec2017-12-24 13:04:17 -080084 if (dev->vendor == PCI_VENDOR_ID_ATI &&
85 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
86 dev->revision < 0x40) {
87 return sp5100;
88 } else if (dev->vendor == PCI_VENDOR_ID_AMD &&
89 ((dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS &&
90 dev->revision >= 0x41) ||
91 (dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS &&
92 dev->revision >= 0x49))) {
93 return efch;
94 }
95 return sb800;
Lucas Stach46856fa2016-05-03 19:15:58 +020096}
97
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -080098static int tco_timer_start(struct watchdog_device *wdd)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -070099{
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800100 struct sp5100_tco *tco = watchdog_get_drvdata(wdd);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700101 u32 val;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700102
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800103 val = readl(SP5100_WDT_CONTROL(tco->tcobase));
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700104 val |= SP5100_WDT_START_STOP_BIT;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800105 writel(val, SP5100_WDT_CONTROL(tco->tcobase));
106
107 return 0;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700108}
109
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800110static int tco_timer_stop(struct watchdog_device *wdd)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700111{
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800112 struct sp5100_tco *tco = watchdog_get_drvdata(wdd);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700113 u32 val;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700114
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800115 val = readl(SP5100_WDT_CONTROL(tco->tcobase));
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700116 val &= ~SP5100_WDT_START_STOP_BIT;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800117 writel(val, SP5100_WDT_CONTROL(tco->tcobase));
118
119 return 0;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700120}
121
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800122static int tco_timer_ping(struct watchdog_device *wdd)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700123{
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800124 struct sp5100_tco *tco = watchdog_get_drvdata(wdd);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700125 u32 val;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700126
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800127 val = readl(SP5100_WDT_CONTROL(tco->tcobase));
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700128 val |= SP5100_WDT_TRIGGER_BIT;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800129 writel(val, SP5100_WDT_CONTROL(tco->tcobase));
130
131 return 0;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700132}
133
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800134static int tco_timer_set_timeout(struct watchdog_device *wdd,
135 unsigned int t)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700136{
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800137 struct sp5100_tco *tco = watchdog_get_drvdata(wdd);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700138
139 /* Write new heartbeat to watchdog */
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800140 writel(t, SP5100_WDT_COUNT(tco->tcobase));
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700141
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800142 wdd->timeout = t;
143
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700144 return 0;
145}
146
Guenter Roeck2b750cf2017-12-24 13:04:06 -0800147static u8 sp5100_tco_read_pm_reg8(u8 index)
148{
149 outb(index, SP5100_IO_PM_INDEX_REG);
150 return inb(SP5100_IO_PM_DATA_REG);
151}
152
153static void sp5100_tco_update_pm_reg8(u8 index, u8 reset, u8 set)
154{
155 u8 val;
156
157 outb(index, SP5100_IO_PM_INDEX_REG);
158 val = inb(SP5100_IO_PM_DATA_REG);
159 val &= reset;
160 val |= set;
161 outb(val, SP5100_IO_PM_DATA_REG);
162}
163
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800164static void tco_timer_enable(struct sp5100_tco *tco)
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900165{
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800166 u32 val;
167
168 switch (tco->tco_reg_layout) {
169 case sb800:
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900170 /* For SB800 or later */
171 /* Set the Watchdog timer resolution to 1 sec */
Guenter Roeck2b750cf2017-12-24 13:04:06 -0800172 sp5100_tco_update_pm_reg8(SB800_PM_WATCHDOG_CONFIG,
173 0xff, SB800_PM_WATCHDOG_SECOND_RES);
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900174
175 /* Enable watchdog decode bit and watchdog timer */
Guenter Roeck2b750cf2017-12-24 13:04:06 -0800176 sp5100_tco_update_pm_reg8(SB800_PM_WATCHDOG_CONTROL,
177 ~SB800_PM_WATCHDOG_DISABLE,
178 SB800_PCI_WATCHDOG_DECODE_EN);
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800179 break;
180 case sp5100:
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900181 /* For SP5100 or SB7x0 */
182 /* Enable watchdog decode bit */
183 pci_read_config_dword(sp5100_tco_pci,
184 SP5100_PCI_WATCHDOG_MISC_REG,
185 &val);
186
187 val |= SP5100_PCI_WATCHDOG_DECODE_EN;
188
189 pci_write_config_dword(sp5100_tco_pci,
190 SP5100_PCI_WATCHDOG_MISC_REG,
191 val);
192
193 /* Enable Watchdog timer and set the resolution to 1 sec */
Guenter Roeck2b750cf2017-12-24 13:04:06 -0800194 sp5100_tco_update_pm_reg8(SP5100_PM_WATCHDOG_CONTROL,
195 ~SP5100_PM_WATCHDOG_DISABLE,
196 SP5100_PM_WATCHDOG_SECOND_RES);
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800197 break;
198 case efch:
199 /* Set the Watchdog timer resolution to 1 sec and enable */
200 sp5100_tco_update_pm_reg8(EFCH_PM_DECODEEN3,
201 ~EFCH_PM_WATCHDOG_DISABLE,
202 EFCH_PM_DECODEEN_SECOND_RES);
203 break;
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900204 }
205}
206
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800207static u32 sp5100_tco_read_pm_reg32(u8 index)
Guenter Roeck2b750cf2017-12-24 13:04:06 -0800208{
209 u32 val = 0;
210 int i;
211
212 for (i = 3; i >= 0; i--)
213 val = (val << 8) + sp5100_tco_read_pm_reg8(index + i);
214
215 return val;
216}
217
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800218static int sp5100_tco_setupdevice(struct device *dev,
219 struct watchdog_device *wdd)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700220{
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800221 struct sp5100_tco *tco = watchdog_get_drvdata(wdd);
222 const char *dev_name;
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800223 u32 mmio_addr = 0, val;
Guenter Roeck23dfe142017-12-24 13:04:09 -0800224 int ret;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700225
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700226 /* Request the IO ports used by this driver */
Guenter Roeck16e77302017-12-24 13:04:08 -0800227 if (!request_muxed_region(SP5100_IO_PM_INDEX_REG,
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800228 SP5100_PM_IOPORTS_SIZE, "sp5100_tco")) {
Guenter Roeckfd8f9092017-12-24 13:04:12 -0800229 dev_err(dev, "I/O address 0x%04x already in use\n",
230 SP5100_IO_PM_INDEX_REG);
Guenter Roeck23dfe142017-12-24 13:04:09 -0800231 return -EBUSY;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700232 }
233
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900234 /*
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800235 * Determine type of southbridge chipset.
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900236 */
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800237 switch (tco->tco_reg_layout) {
238 case sp5100:
239 dev_name = SP5100_DEVNAME;
240 mmio_addr = sp5100_tco_read_pm_reg32(SP5100_PM_WATCHDOG_BASE) &
241 0xfffffff8;
242 break;
243 case sb800:
244 dev_name = SB800_DEVNAME;
245 mmio_addr = sp5100_tco_read_pm_reg32(SB800_PM_WATCHDOG_BASE) &
246 0xfffffff8;
247 break;
248 case efch:
249 dev_name = SB800_DEVNAME;
Guenter Roeck09da89a2020-09-10 09:31:09 -0700250 /*
251 * On Family 17h devices, the EFCH_PM_DECODEEN_WDT_TMREN bit of
252 * EFCH_PM_DECODEEN not only enables the EFCH_PM_WDT_ADDR memory
253 * region, it also enables the watchdog itself.
254 */
255 if (boot_cpu_data.x86 == 0x17) {
256 val = sp5100_tco_read_pm_reg8(EFCH_PM_DECODEEN);
257 if (!(val & EFCH_PM_DECODEEN_WDT_TMREN)) {
258 sp5100_tco_update_pm_reg8(EFCH_PM_DECODEEN, 0xff,
259 EFCH_PM_DECODEEN_WDT_TMREN);
260 }
261 }
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800262 val = sp5100_tco_read_pm_reg8(EFCH_PM_DECODEEN);
263 if (val & EFCH_PM_DECODEEN_WDT_TMREN)
264 mmio_addr = EFCH_PM_WDT_ADDR;
265 break;
266 default:
267 return -ENODEV;
268 }
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900269
270 /* Check MMIO address conflict */
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800271 if (!mmio_addr ||
272 !devm_request_mem_region(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE,
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800273 dev_name)) {
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800274 if (mmio_addr)
275 dev_dbg(dev, "MMIO address 0x%08x already in use\n",
276 mmio_addr);
277 switch (tco->tco_reg_layout) {
278 case sp5100:
279 /*
280 * Secondly, Find the watchdog timer MMIO address
281 * from SBResource_MMIO register.
282 */
Guenter Roecke1894102017-12-24 13:04:10 -0800283 /* Read SBResource_MMIO from PCI config(PCI_Reg: 9Ch) */
284 pci_read_config_dword(sp5100_tco_pci,
285 SP5100_SB_RESOURCE_MMIO_BASE,
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800286 &mmio_addr);
287 if ((mmio_addr & (SB800_ACPI_MMIO_DECODE_EN |
288 SB800_ACPI_MMIO_SEL)) !=
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900289 SB800_ACPI_MMIO_DECODE_EN) {
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800290 ret = -ENODEV;
291 goto unreg_region;
292 }
293 mmio_addr &= ~0xFFF;
294 mmio_addr += SB800_PM_WDT_MMIO_OFFSET;
295 break;
296 case sb800:
297 /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */
298 mmio_addr =
299 sp5100_tco_read_pm_reg32(SB800_PM_ACPI_MMIO_EN);
300 if ((mmio_addr & (SB800_ACPI_MMIO_DECODE_EN |
301 SB800_ACPI_MMIO_SEL)) !=
302 SB800_ACPI_MMIO_DECODE_EN) {
303 ret = -ENODEV;
304 goto unreg_region;
305 }
306 mmio_addr &= ~0xFFF;
307 mmio_addr += SB800_PM_WDT_MMIO_OFFSET;
308 break;
309 case efch:
310 val = sp5100_tco_read_pm_reg8(EFCH_PM_ISACONTROL);
311 if (!(val & EFCH_PM_ISACONTROL_MMIOEN)) {
312 ret = -ENODEV;
313 goto unreg_region;
314 }
315 mmio_addr = EFCH_PM_ACPI_MMIO_ADDR +
316 EFCH_PM_ACPI_MMIO_WDT_OFFSET;
317 break;
Guenter Roecke1894102017-12-24 13:04:10 -0800318 }
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800319 dev_dbg(dev, "Got 0x%08x from SBResource_MMIO register\n",
320 mmio_addr);
321 if (!devm_request_mem_region(dev, mmio_addr,
322 SP5100_WDT_MEM_MAP_SIZE,
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800323 dev_name)) {
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800324 dev_dbg(dev, "MMIO address 0x%08x already in use\n",
325 mmio_addr);
Guenter Roecke1894102017-12-24 13:04:10 -0800326 ret = -EBUSY;
327 goto unreg_region;
328 }
Guenter Roecke1894102017-12-24 13:04:10 -0800329 }
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900330
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800331 tco->tcobase = devm_ioremap(dev, mmio_addr, SP5100_WDT_MEM_MAP_SIZE);
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800332 if (!tco->tcobase) {
Guenter Roeckfd8f9092017-12-24 13:04:12 -0800333 dev_err(dev, "failed to get tcobase address\n");
Guenter Roeck23dfe142017-12-24 13:04:09 -0800334 ret = -ENOMEM;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800335 goto unreg_region;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700336 }
337
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800338 dev_info(dev, "Using 0x%08x for watchdog MMIO address\n", mmio_addr);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700339
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900340 /* Setup the watchdog timer */
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800341 tco_timer_enable(tco);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700342
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800343 val = readl(SP5100_WDT_CONTROL(tco->tcobase));
Guenter Roeckf7781b02017-12-24 13:04:16 -0800344 if (val & SP5100_WDT_DISABLED) {
345 dev_err(dev, "Watchdog hardware is disabled\n");
346 ret = -ENODEV;
347 goto unreg_region;
348 }
349
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900350 /*
351 * Save WatchDogFired status, because WatchDogFired flag is
352 * cleared here.
353 */
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800354 if (val & SP5100_WDT_FIRED)
355 wdd->bootstatus = WDIOF_CARDRESET;
Guenter Roeckf7781b02017-12-24 13:04:16 -0800356 /* Set watchdog action to reset the system */
Guenter Roeck5bbecc52017-12-24 13:04:13 -0800357 val &= ~SP5100_WDT_ACTION_RESET;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800358 writel(val, SP5100_WDT_CONTROL(tco->tcobase));
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700359
360 /* Set a reasonable heartbeat before we stop the timer */
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800361 tco_timer_set_timeout(wdd, wdd->timeout);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700362
363 /*
364 * Stop the TCO before we change anything so we don't race with
365 * a zeroed timer.
366 */
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800367 tco_timer_stop(wdd);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700368
Guenter Roeck16e77302017-12-24 13:04:08 -0800369 release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
Guenter Roecke1894102017-12-24 13:04:10 -0800370
Guenter Roeck23dfe142017-12-24 13:04:09 -0800371 return 0;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700372
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700373unreg_region:
Guenter Roeck2b750cf2017-12-24 13:04:06 -0800374 release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE);
Guenter Roeck23dfe142017-12-24 13:04:09 -0800375 return ret;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700376}
377
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800378static struct watchdog_info sp5100_tco_wdt_info = {
379 .identity = "SP5100 TCO timer",
380 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
381};
382
383static const struct watchdog_ops sp5100_tco_wdt_ops = {
384 .owner = THIS_MODULE,
385 .start = tco_timer_start,
386 .stop = tco_timer_stop,
387 .ping = tco_timer_ping,
388 .set_timeout = tco_timer_set_timeout,
389};
390
Guenter Roeck5bbecc52017-12-24 13:04:13 -0800391static int sp5100_tco_probe(struct platform_device *pdev)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700392{
Guenter Roeckfd8f9092017-12-24 13:04:12 -0800393 struct device *dev = &pdev->dev;
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800394 struct watchdog_device *wdd;
395 struct sp5100_tco *tco;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700396 int ret;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700397
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800398 tco = devm_kzalloc(dev, sizeof(*tco), GFP_KERNEL);
399 if (!tco)
400 return -ENOMEM;
401
Guenter Roeck887d2ec2017-12-24 13:04:17 -0800402 tco->tco_reg_layout = tco_reg_layout(sp5100_tco_pci);
403
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800404 wdd = &tco->wdd;
405 wdd->parent = dev;
406 wdd->info = &sp5100_tco_wdt_info;
407 wdd->ops = &sp5100_tco_wdt_ops;
408 wdd->timeout = WATCHDOG_HEARTBEAT;
409 wdd->min_timeout = 1;
410 wdd->max_timeout = 0xffff;
411
Wolfram Sang2d505e32019-04-19 20:15:57 +0200412 watchdog_init_timeout(wdd, heartbeat, NULL);
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800413 watchdog_set_nowayout(wdd, nowayout);
414 watchdog_stop_on_reboot(wdd);
415 watchdog_stop_on_unregister(wdd);
416 watchdog_set_drvdata(wdd, tco);
417
418 ret = sp5100_tco_setupdevice(dev, wdd);
Guenter Roeck23dfe142017-12-24 13:04:09 -0800419 if (ret)
420 return ret;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700421
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800422 ret = devm_watchdog_register_device(dev, wdd);
Wolfram Sangd41e3f42019-05-18 23:27:52 +0200423 if (ret)
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800424 return ret;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700425
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900426 /* Show module parameters */
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800427 dev_info(dev, "initialized. heartbeat=%d sec (nowayout=%d)\n",
428 wdd->timeout, nowayout);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700429
430 return 0;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700431}
432
433static struct platform_driver sp5100_tco_driver = {
Guenter Roeck5bbecc52017-12-24 13:04:13 -0800434 .probe = sp5100_tco_probe,
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700435 .driver = {
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800436 .name = TCO_DRIVER_NAME,
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700437 },
438};
439
Guenter Roecka34834432017-12-24 13:04:11 -0800440/*
441 * Data for PCI driver interface
442 *
443 * This data only exists for exporting the supported
444 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
445 * register a pci_driver, because someone else might
446 * want to register another driver on the same PCI id.
447 */
448static const struct pci_device_id sp5100_tco_pci_tbl[] = {
449 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, PCI_ANY_ID,
450 PCI_ANY_ID, },
451 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, PCI_ANY_ID,
452 PCI_ANY_ID, },
453 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, PCI_ANY_ID,
454 PCI_ANY_ID, },
455 { 0, }, /* End of list */
456};
457MODULE_DEVICE_TABLE(pci, sp5100_tco_pci_tbl);
458
Guenter Roeck5bbecc52017-12-24 13:04:13 -0800459static int __init sp5100_tco_init(void)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700460{
Guenter Roecka34834432017-12-24 13:04:11 -0800461 struct pci_dev *dev = NULL;
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700462 int err;
463
Guenter Roecka34834432017-12-24 13:04:11 -0800464 /* Match the PCI device */
465 for_each_pci_dev(dev) {
466 if (pci_match_id(sp5100_tco_pci_tbl, dev) != NULL) {
467 sp5100_tco_pci = dev;
468 break;
469 }
470 }
471
472 if (!sp5100_tco_pci)
473 return -ENODEV;
474
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800475 pr_info("SP5100/SB800 TCO WatchDog Timer Driver\n");
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700476
477 err = platform_driver_register(&sp5100_tco_driver);
478 if (err)
479 return err;
480
Guenter Roeck7cd9d5f2017-12-24 13:04:14 -0800481 sp5100_tco_platform_device =
482 platform_device_register_simple(TCO_DRIVER_NAME, -1, NULL, 0);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700483 if (IS_ERR(sp5100_tco_platform_device)) {
484 err = PTR_ERR(sp5100_tco_platform_device);
485 goto unreg_platform_driver;
486 }
487
488 return 0;
489
490unreg_platform_driver:
491 platform_driver_unregister(&sp5100_tco_driver);
492 return err;
493}
494
Guenter Roeck5bbecc52017-12-24 13:04:13 -0800495static void __exit sp5100_tco_exit(void)
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700496{
497 platform_device_unregister(sp5100_tco_platform_device);
498 platform_driver_unregister(&sp5100_tco_driver);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700499}
500
Guenter Roeck5bbecc52017-12-24 13:04:13 -0800501module_init(sp5100_tco_init);
502module_exit(sp5100_tco_exit);
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700503
504MODULE_AUTHOR("Priyanka Gupta");
Takahisa Tanaka740fbdd2012-12-02 14:33:18 +0900505MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset");
Priyanka Gupta15e28bf2010-10-25 17:58:04 -0700506MODULE_LICENSE("GPL");