Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ib-drm-gpio-pdx86-rtc-wdt-v5.12-1' into for-next

ib-drm-gpio-pdx86-rtc-wdt for v5.12-1

First part of Intel MID outdated platforms removal.

The following is an automated git shortlog grouped by driver:

drm/gma500:
- Get rid of duplicate NULL checks
- Convert to use new SCU IPC API

gpio:
- msic: Remove driver for deprecated platform
- intel-mid: Remove driver for deprecated platform

intel_mid_powerbtn:
- Remove driver for deprecated platform

intel_mid_thermal:
- Remove driver for deprecated platform

intel_scu_wdt:
- Get rid of custom x86 model comparison
- Drop SCU notification
- Move driver from arch/x86

rtc:
- mrst: Remove driver for deprecated platform

watchdog:
- intel-mid_wdt: Postpone IRQ handler registration till SCU is ready
- intel_scu_watchdog: Remove driver for deprecated platform

+54 -1928
-2
MAINTAINERS
··· 8940 8940 S: Maintained 8941 8941 T: git git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel.git 8942 8942 F: drivers/gpio/gpio-ich.c 8943 - F: drivers/gpio/gpio-intel-mid.c 8944 8943 F: drivers/gpio/gpio-merrifield.c 8945 8944 F: drivers/gpio/gpio-ml-ioh.c 8946 8945 F: drivers/gpio/gpio-pch.c ··· 9098 9099 S: Maintained 9099 9100 T: git git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel.git 9100 9101 F: drivers/gpio/gpio-*cove.c 9101 - F: drivers/gpio/gpio-msic.c 9102 9102 9103 9103 INTEL PMIC MULTIFUNCTION DEVICE DRIVERS 9104 9104 M: Andy Shevchenko <andy@kernel.org>
-1
arch/x86/platform/intel-mid/device_libs/Makefile
··· 30 30 obj-$(subst m,y,$(CONFIG_KEYBOARD_GPIO)) += platform_gpio_keys.o 31 31 obj-$(subst m,y,$(CONFIG_INTEL_MID_POWER_BUTTON)) += platform_mrfld_power_btn.o 32 32 obj-$(subst m,y,$(CONFIG_RTC_DRV_CMOS)) += platform_mrfld_rtc.o 33 - obj-$(subst m,y,$(CONFIG_INTEL_MID_WATCHDOG)) += platform_mrfld_wdt.o
+17 -24
arch/x86/platform/intel-mid/device_libs/platform_mrfld_wdt.c drivers/platform/x86/intel_scu_wdt.c
··· 11 11 #include <linux/platform_device.h> 12 12 #include <linux/platform_data/intel-mid_wdt.h> 13 13 14 + #include <asm/cpu_device_id.h> 15 + #include <asm/intel-family.h> 14 16 #include <asm/intel-mid.h> 15 - #include <asm/intel_scu_ipc.h> 16 17 #include <asm/io_apic.h> 17 18 #include <asm/hw_irq.h> 18 19 ··· 50 49 .probe = tangier_probe, 51 50 }; 52 51 53 - static int wdt_scu_status_change(struct notifier_block *nb, 54 - unsigned long code, void *data) 55 - { 56 - if (code == SCU_DOWN) { 57 - platform_device_unregister(&wdt_dev); 58 - return 0; 59 - } 60 - 61 - return platform_device_register(&wdt_dev); 62 - } 63 - 64 - static struct notifier_block wdt_scu_notifier = { 65 - .notifier_call = wdt_scu_status_change, 52 + static const struct x86_cpu_id intel_mid_cpu_ids[] = { 53 + X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT_MID, &tangier_pdata), 54 + {} 66 55 }; 67 56 68 57 static int __init register_mid_wdt(void) 69 58 { 70 - if (intel_mid_identify_cpu() != INTEL_MID_CPU_CHIP_TANGIER) 59 + const struct x86_cpu_id *id; 60 + 61 + id = x86_match_cpu(intel_mid_cpu_ids); 62 + if (!id) 71 63 return -ENODEV; 72 64 73 - wdt_dev.dev.platform_data = &tangier_pdata; 74 - 75 - /* 76 - * We need to be sure that the SCU IPC is ready before watchdog device 77 - * can be registered: 78 - */ 79 - intel_scu_notifier_add(&wdt_scu_notifier); 80 - 81 - return 0; 65 + wdt_dev.dev.platform_data = (const struct intel_mid_wdt_pdata *)id->driver_data; 66 + return platform_device_register(&wdt_dev); 82 67 } 83 68 arch_initcall(register_mid_wdt); 69 + 70 + static void __exit unregister_mid_wdt(void) 71 + { 72 + platform_device_unregister(&wdt_dev); 73 + } 74 + __exitcall(unregister_mid_wdt);
-14
drivers/gpio/Kconfig
··· 1249 1249 GPIO driver for MAX77650/77651 PMIC from Maxim Semiconductor. 1250 1250 These chips have a single pin that can be configured as GPIO. 1251 1251 1252 - config GPIO_MSIC 1253 - bool "Intel MSIC mixed signal gpio support" 1254 - depends on (X86 || COMPILE_TEST) && MFD_INTEL_MSIC 1255 - help 1256 - Enable support for GPIO on intel MSIC controllers found in 1257 - intel MID devices 1258 - 1259 1252 config GPIO_PALMAS 1260 1253 bool "TI PALMAS series PMICs GPIO" 1261 1254 depends on MFD_PALMAS ··· 1443 1450 Documentation/driver-api/gpio/bt8xxgpio.rst 1444 1451 1445 1452 If unsure, say N. 1446 - 1447 - config GPIO_INTEL_MID 1448 - bool "Intel MID GPIO support" 1449 - depends on X86_INTEL_MID 1450 - select GPIOLIB_IRQCHIP 1451 - help 1452 - Say Y here to support Intel MID GPIO. 1453 1453 1454 1454 config GPIO_MERRIFIELD 1455 1455 tristate "Intel Merrifield GPIO support"
-1
drivers/gpio/Makefile
··· 67 67 obj-$(CONFIG_GPIO_HLWD) += gpio-hlwd.o 68 68 obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o 69 69 obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 70 - obj-$(CONFIG_GPIO_INTEL_MID) += gpio-intel-mid.o 71 70 obj-$(CONFIG_GPIO_IOP) += gpio-iop.o 72 71 obj-$(CONFIG_GPIO_IT87) += gpio-it87.o 73 72 obj-$(CONFIG_GPIO_IXP4XX) += gpio-ixp4xx.o
+1 -1
drivers/gpio/TODO
··· 101 101 102 102 At the same time it makes sense to get rid of code duplication in existing or 103 103 new coming drivers. For example, gpio-ml-ioh should be incorporated into 104 - gpio-pch. In similar way gpio-intel-mid into gpio-pxa. 104 + gpio-pch. 105 105 106 106 107 107 Generic MMIO GPIO
-414
drivers/gpio/gpio-intel-mid.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Intel MID GPIO driver 4 - * 5 - * Copyright (c) 2008-2014,2016 Intel Corporation. 6 - */ 7 - 8 - /* Supports: 9 - * Moorestown platform Langwell chip. 10 - * Medfield platform Penwell chip. 11 - * Clovertrail platform Cloverview chip. 12 - */ 13 - 14 - #include <linux/delay.h> 15 - #include <linux/gpio/driver.h> 16 - #include <linux/init.h> 17 - #include <linux/interrupt.h> 18 - #include <linux/io.h> 19 - #include <linux/kernel.h> 20 - #include <linux/pci.h> 21 - #include <linux/platform_device.h> 22 - #include <linux/pm_runtime.h> 23 - #include <linux/slab.h> 24 - #include <linux/stddef.h> 25 - 26 - #define INTEL_MID_IRQ_TYPE_EDGE (1 << 0) 27 - #define INTEL_MID_IRQ_TYPE_LEVEL (1 << 1) 28 - 29 - /* 30 - * Langwell chip has 64 pins and thus there are 2 32bit registers to control 31 - * each feature, while Penwell chip has 96 pins for each block, and need 3 32bit 32 - * registers to control them, so we only define the order here instead of a 33 - * structure, to get a bit offset for a pin (use GPDR as an example): 34 - * 35 - * nreg = ngpio / 32; 36 - * reg = offset / 32; 37 - * bit = offset % 32; 38 - * reg_addr = reg_base + GPDR * nreg * 4 + reg * 4; 39 - * 40 - * so the bit of reg_addr is to control pin offset's GPDR feature 41 - */ 42 - 43 - enum GPIO_REG { 44 - GPLR = 0, /* pin level read-only */ 45 - GPDR, /* pin direction */ 46 - GPSR, /* pin set */ 47 - GPCR, /* pin clear */ 48 - GRER, /* rising edge detect */ 49 - GFER, /* falling edge detect */ 50 - GEDR, /* edge detect result */ 51 - GAFR, /* alt function */ 52 - }; 53 - 54 - /* intel_mid gpio driver data */ 55 - struct intel_mid_gpio_ddata { 56 - u16 ngpio; /* number of gpio pins */ 57 - u32 chip_irq_type; /* chip interrupt type */ 58 - }; 59 - 60 - struct intel_mid_gpio { 61 - struct gpio_chip chip; 62 - void __iomem *reg_base; 63 - spinlock_t lock; 64 - struct pci_dev *pdev; 65 - }; 66 - 67 - static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, 68 - enum GPIO_REG reg_type) 69 - { 70 - struct intel_mid_gpio *priv = gpiochip_get_data(chip); 71 - unsigned nreg = chip->ngpio / 32; 72 - u8 reg = offset / 32; 73 - 74 - return priv->reg_base + reg_type * nreg * 4 + reg * 4; 75 - } 76 - 77 - static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, 78 - enum GPIO_REG reg_type) 79 - { 80 - struct intel_mid_gpio *priv = gpiochip_get_data(chip); 81 - unsigned nreg = chip->ngpio / 32; 82 - u8 reg = offset / 16; 83 - 84 - return priv->reg_base + reg_type * nreg * 4 + reg * 4; 85 - } 86 - 87 - static int intel_gpio_request(struct gpio_chip *chip, unsigned offset) 88 - { 89 - void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR); 90 - u32 value = readl(gafr); 91 - int shift = (offset % 16) << 1, af = (value >> shift) & 3; 92 - 93 - if (af) { 94 - value &= ~(3 << shift); 95 - writel(value, gafr); 96 - } 97 - return 0; 98 - } 99 - 100 - static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) 101 - { 102 - void __iomem *gplr = gpio_reg(chip, offset, GPLR); 103 - 104 - return !!(readl(gplr) & BIT(offset % 32)); 105 - } 106 - 107 - static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 108 - { 109 - void __iomem *gpsr, *gpcr; 110 - 111 - if (value) { 112 - gpsr = gpio_reg(chip, offset, GPSR); 113 - writel(BIT(offset % 32), gpsr); 114 - } else { 115 - gpcr = gpio_reg(chip, offset, GPCR); 116 - writel(BIT(offset % 32), gpcr); 117 - } 118 - } 119 - 120 - static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 121 - { 122 - struct intel_mid_gpio *priv = gpiochip_get_data(chip); 123 - void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 124 - u32 value; 125 - unsigned long flags; 126 - 127 - if (priv->pdev) 128 - pm_runtime_get(&priv->pdev->dev); 129 - 130 - spin_lock_irqsave(&priv->lock, flags); 131 - value = readl(gpdr); 132 - value &= ~BIT(offset % 32); 133 - writel(value, gpdr); 134 - spin_unlock_irqrestore(&priv->lock, flags); 135 - 136 - if (priv->pdev) 137 - pm_runtime_put(&priv->pdev->dev); 138 - 139 - return 0; 140 - } 141 - 142 - static int intel_gpio_direction_output(struct gpio_chip *chip, 143 - unsigned offset, int value) 144 - { 145 - struct intel_mid_gpio *priv = gpiochip_get_data(chip); 146 - void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 147 - unsigned long flags; 148 - 149 - intel_gpio_set(chip, offset, value); 150 - 151 - if (priv->pdev) 152 - pm_runtime_get(&priv->pdev->dev); 153 - 154 - spin_lock_irqsave(&priv->lock, flags); 155 - value = readl(gpdr); 156 - value |= BIT(offset % 32); 157 - writel(value, gpdr); 158 - spin_unlock_irqrestore(&priv->lock, flags); 159 - 160 - if (priv->pdev) 161 - pm_runtime_put(&priv->pdev->dev); 162 - 163 - return 0; 164 - } 165 - 166 - static int intel_mid_irq_type(struct irq_data *d, unsigned type) 167 - { 168 - struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 169 - struct intel_mid_gpio *priv = gpiochip_get_data(gc); 170 - u32 gpio = irqd_to_hwirq(d); 171 - unsigned long flags; 172 - u32 value; 173 - void __iomem *grer = gpio_reg(&priv->chip, gpio, GRER); 174 - void __iomem *gfer = gpio_reg(&priv->chip, gpio, GFER); 175 - 176 - if (gpio >= priv->chip.ngpio) 177 - return -EINVAL; 178 - 179 - if (priv->pdev) 180 - pm_runtime_get(&priv->pdev->dev); 181 - 182 - spin_lock_irqsave(&priv->lock, flags); 183 - if (type & IRQ_TYPE_EDGE_RISING) 184 - value = readl(grer) | BIT(gpio % 32); 185 - else 186 - value = readl(grer) & (~BIT(gpio % 32)); 187 - writel(value, grer); 188 - 189 - if (type & IRQ_TYPE_EDGE_FALLING) 190 - value = readl(gfer) | BIT(gpio % 32); 191 - else 192 - value = readl(gfer) & (~BIT(gpio % 32)); 193 - writel(value, gfer); 194 - spin_unlock_irqrestore(&priv->lock, flags); 195 - 196 - if (priv->pdev) 197 - pm_runtime_put(&priv->pdev->dev); 198 - 199 - return 0; 200 - } 201 - 202 - static void intel_mid_irq_unmask(struct irq_data *d) 203 - { 204 - } 205 - 206 - static void intel_mid_irq_mask(struct irq_data *d) 207 - { 208 - } 209 - 210 - static struct irq_chip intel_mid_irqchip = { 211 - .name = "INTEL_MID-GPIO", 212 - .irq_mask = intel_mid_irq_mask, 213 - .irq_unmask = intel_mid_irq_unmask, 214 - .irq_set_type = intel_mid_irq_type, 215 - }; 216 - 217 - static const struct intel_mid_gpio_ddata gpio_lincroft = { 218 - .ngpio = 64, 219 - }; 220 - 221 - static const struct intel_mid_gpio_ddata gpio_penwell_aon = { 222 - .ngpio = 96, 223 - .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 224 - }; 225 - 226 - static const struct intel_mid_gpio_ddata gpio_penwell_core = { 227 - .ngpio = 96, 228 - .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 229 - }; 230 - 231 - static const struct intel_mid_gpio_ddata gpio_cloverview_aon = { 232 - .ngpio = 96, 233 - .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE | INTEL_MID_IRQ_TYPE_LEVEL, 234 - }; 235 - 236 - static const struct intel_mid_gpio_ddata gpio_cloverview_core = { 237 - .ngpio = 96, 238 - .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, 239 - }; 240 - 241 - static const struct pci_device_id intel_gpio_ids[] = { 242 - { 243 - /* Lincroft */ 244 - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080f), 245 - .driver_data = (kernel_ulong_t)&gpio_lincroft, 246 - }, 247 - { 248 - /* Penwell AON */ 249 - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081f), 250 - .driver_data = (kernel_ulong_t)&gpio_penwell_aon, 251 - }, 252 - { 253 - /* Penwell Core */ 254 - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081a), 255 - .driver_data = (kernel_ulong_t)&gpio_penwell_core, 256 - }, 257 - { 258 - /* Cloverview Aon */ 259 - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08eb), 260 - .driver_data = (kernel_ulong_t)&gpio_cloverview_aon, 261 - }, 262 - { 263 - /* Cloverview Core */ 264 - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7), 265 - .driver_data = (kernel_ulong_t)&gpio_cloverview_core, 266 - }, 267 - { } 268 - }; 269 - 270 - static void intel_mid_irq_handler(struct irq_desc *desc) 271 - { 272 - struct gpio_chip *gc = irq_desc_get_handler_data(desc); 273 - struct intel_mid_gpio *priv = gpiochip_get_data(gc); 274 - struct irq_data *data = irq_desc_get_irq_data(desc); 275 - struct irq_chip *chip = irq_data_get_irq_chip(data); 276 - u32 base, gpio, mask; 277 - unsigned long pending; 278 - void __iomem *gedr; 279 - 280 - /* check GPIO controller to check which pin triggered the interrupt */ 281 - for (base = 0; base < priv->chip.ngpio; base += 32) { 282 - gedr = gpio_reg(&priv->chip, base, GEDR); 283 - while ((pending = readl(gedr))) { 284 - gpio = __ffs(pending); 285 - mask = BIT(gpio); 286 - /* Clear before handling so we can't lose an edge */ 287 - writel(mask, gedr); 288 - generic_handle_irq(irq_find_mapping(gc->irq.domain, 289 - base + gpio)); 290 - } 291 - } 292 - 293 - chip->irq_eoi(data); 294 - } 295 - 296 - static int intel_mid_irq_init_hw(struct gpio_chip *chip) 297 - { 298 - struct intel_mid_gpio *priv = gpiochip_get_data(chip); 299 - void __iomem *reg; 300 - unsigned base; 301 - 302 - for (base = 0; base < priv->chip.ngpio; base += 32) { 303 - /* Clear the rising-edge detect register */ 304 - reg = gpio_reg(&priv->chip, base, GRER); 305 - writel(0, reg); 306 - /* Clear the falling-edge detect register */ 307 - reg = gpio_reg(&priv->chip, base, GFER); 308 - writel(0, reg); 309 - /* Clear the edge detect status register */ 310 - reg = gpio_reg(&priv->chip, base, GEDR); 311 - writel(~0, reg); 312 - } 313 - 314 - return 0; 315 - } 316 - 317 - static int __maybe_unused intel_gpio_runtime_idle(struct device *dev) 318 - { 319 - int err = pm_schedule_suspend(dev, 500); 320 - return err ?: -EBUSY; 321 - } 322 - 323 - static const struct dev_pm_ops intel_gpio_pm_ops = { 324 - SET_RUNTIME_PM_OPS(NULL, NULL, intel_gpio_runtime_idle) 325 - }; 326 - 327 - static int intel_gpio_probe(struct pci_dev *pdev, 328 - const struct pci_device_id *id) 329 - { 330 - void __iomem *base; 331 - struct intel_mid_gpio *priv; 332 - u32 gpio_base; 333 - u32 irq_base; 334 - int retval; 335 - struct gpio_irq_chip *girq; 336 - struct intel_mid_gpio_ddata *ddata = 337 - (struct intel_mid_gpio_ddata *)id->driver_data; 338 - 339 - retval = pcim_enable_device(pdev); 340 - if (retval) 341 - return retval; 342 - 343 - retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev)); 344 - if (retval) { 345 - dev_err(&pdev->dev, "I/O memory mapping error\n"); 346 - return retval; 347 - } 348 - 349 - base = pcim_iomap_table(pdev)[1]; 350 - 351 - irq_base = readl(base); 352 - gpio_base = readl(sizeof(u32) + base); 353 - 354 - /* release the IO mapping, since we already get the info from bar1 */ 355 - pcim_iounmap_regions(pdev, 1 << 1); 356 - 357 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 358 - if (!priv) 359 - return -ENOMEM; 360 - 361 - priv->reg_base = pcim_iomap_table(pdev)[0]; 362 - priv->chip.label = dev_name(&pdev->dev); 363 - priv->chip.parent = &pdev->dev; 364 - priv->chip.request = intel_gpio_request; 365 - priv->chip.direction_input = intel_gpio_direction_input; 366 - priv->chip.direction_output = intel_gpio_direction_output; 367 - priv->chip.get = intel_gpio_get; 368 - priv->chip.set = intel_gpio_set; 369 - priv->chip.base = gpio_base; 370 - priv->chip.ngpio = ddata->ngpio; 371 - priv->chip.can_sleep = false; 372 - priv->pdev = pdev; 373 - 374 - spin_lock_init(&priv->lock); 375 - 376 - girq = &priv->chip.irq; 377 - girq->chip = &intel_mid_irqchip; 378 - girq->init_hw = intel_mid_irq_init_hw; 379 - girq->parent_handler = intel_mid_irq_handler; 380 - girq->num_parents = 1; 381 - girq->parents = devm_kcalloc(&pdev->dev, girq->num_parents, 382 - sizeof(*girq->parents), 383 - GFP_KERNEL); 384 - if (!girq->parents) 385 - return -ENOMEM; 386 - girq->parents[0] = pdev->irq; 387 - girq->first = irq_base; 388 - girq->default_type = IRQ_TYPE_NONE; 389 - girq->handler = handle_simple_irq; 390 - 391 - pci_set_drvdata(pdev, priv); 392 - 393 - retval = devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv); 394 - if (retval) { 395 - dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); 396 - return retval; 397 - } 398 - 399 - pm_runtime_put_noidle(&pdev->dev); 400 - pm_runtime_allow(&pdev->dev); 401 - 402 - return 0; 403 - } 404 - 405 - static struct pci_driver intel_gpio_driver = { 406 - .name = "intel_mid_gpio", 407 - .id_table = intel_gpio_ids, 408 - .probe = intel_gpio_probe, 409 - .driver = { 410 - .pm = &intel_gpio_pm_ops, 411 - }, 412 - }; 413 - 414 - builtin_pci_driver(intel_gpio_driver);
-314
drivers/gpio/gpio-msic.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Intel Medfield MSIC GPIO driver> 4 - * Copyright (c) 2011, Intel Corporation. 5 - * 6 - * Author: Mathias Nyman <mathias.nyman@linux.intel.com> 7 - * Based on intel_pmic_gpio.c 8 - */ 9 - 10 - #include <linux/gpio/driver.h> 11 - #include <linux/init.h> 12 - #include <linux/interrupt.h> 13 - #include <linux/kernel.h> 14 - #include <linux/mfd/intel_msic.h> 15 - #include <linux/platform_device.h> 16 - #include <linux/slab.h> 17 - 18 - /* the offset for the mapping of global gpio pin to irq */ 19 - #define MSIC_GPIO_IRQ_OFFSET 0x100 20 - 21 - #define MSIC_GPIO_DIR_IN 0 22 - #define MSIC_GPIO_DIR_OUT BIT(5) 23 - #define MSIC_GPIO_TRIG_FALL BIT(1) 24 - #define MSIC_GPIO_TRIG_RISE BIT(2) 25 - 26 - /* masks for msic gpio output GPIOxxxxCTLO registers */ 27 - #define MSIC_GPIO_DIR_MASK BIT(5) 28 - #define MSIC_GPIO_DRV_MASK BIT(4) 29 - #define MSIC_GPIO_REN_MASK BIT(3) 30 - #define MSIC_GPIO_RVAL_MASK (BIT(2) | BIT(1)) 31 - #define MSIC_GPIO_DOUT_MASK BIT(0) 32 - 33 - /* masks for msic gpio input GPIOxxxxCTLI registers */ 34 - #define MSIC_GPIO_GLBYP_MASK BIT(5) 35 - #define MSIC_GPIO_DBNC_MASK (BIT(4) | BIT(3)) 36 - #define MSIC_GPIO_INTCNT_MASK (BIT(2) | BIT(1)) 37 - #define MSIC_GPIO_DIN_MASK BIT(0) 38 - 39 - #define MSIC_NUM_GPIO 24 40 - 41 - struct msic_gpio { 42 - struct platform_device *pdev; 43 - struct mutex buslock; 44 - struct gpio_chip chip; 45 - int irq; 46 - unsigned irq_base; 47 - unsigned long trig_change_mask; 48 - unsigned trig_type; 49 - }; 50 - 51 - /* 52 - * MSIC has 24 gpios, 16 low voltage (1.2-1.8v) and 8 high voltage (3v). 53 - * Both the high and low voltage gpios are divided in two banks. 54 - * GPIOs are numbered with GPIO0LV0 as gpio_base in the following order: 55 - * GPIO0LV0..GPIO0LV7: low voltage, bank 0, gpio_base 56 - * GPIO1LV0..GPIO1LV7: low voltage, bank 1, gpio_base + 8 57 - * GPIO0HV0..GPIO0HV3: high voltage, bank 0, gpio_base + 16 58 - * GPIO1HV0..GPIO1HV3: high voltage, bank 1, gpio_base + 20 59 - */ 60 - 61 - static int msic_gpio_to_ireg(unsigned offset) 62 - { 63 - if (offset >= MSIC_NUM_GPIO) 64 - return -EINVAL; 65 - 66 - if (offset < 8) 67 - return INTEL_MSIC_GPIO0LV0CTLI - offset; 68 - if (offset < 16) 69 - return INTEL_MSIC_GPIO1LV0CTLI - offset + 8; 70 - if (offset < 20) 71 - return INTEL_MSIC_GPIO0HV0CTLI - offset + 16; 72 - 73 - return INTEL_MSIC_GPIO1HV0CTLI - offset + 20; 74 - } 75 - 76 - static int msic_gpio_to_oreg(unsigned offset) 77 - { 78 - if (offset >= MSIC_NUM_GPIO) 79 - return -EINVAL; 80 - 81 - if (offset < 8) 82 - return INTEL_MSIC_GPIO0LV0CTLO - offset; 83 - if (offset < 16) 84 - return INTEL_MSIC_GPIO1LV0CTLO - offset + 8; 85 - if (offset < 20) 86 - return INTEL_MSIC_GPIO0HV0CTLO - offset + 16; 87 - 88 - return INTEL_MSIC_GPIO1HV0CTLO - offset + 20; 89 - } 90 - 91 - static int msic_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 92 - { 93 - int reg; 94 - 95 - reg = msic_gpio_to_oreg(offset); 96 - if (reg < 0) 97 - return reg; 98 - 99 - return intel_msic_reg_update(reg, MSIC_GPIO_DIR_IN, MSIC_GPIO_DIR_MASK); 100 - } 101 - 102 - static int msic_gpio_direction_output(struct gpio_chip *chip, 103 - unsigned offset, int value) 104 - { 105 - int reg; 106 - unsigned mask; 107 - 108 - value = (!!value) | MSIC_GPIO_DIR_OUT; 109 - mask = MSIC_GPIO_DIR_MASK | MSIC_GPIO_DOUT_MASK; 110 - 111 - reg = msic_gpio_to_oreg(offset); 112 - if (reg < 0) 113 - return reg; 114 - 115 - return intel_msic_reg_update(reg, value, mask); 116 - } 117 - 118 - static int msic_gpio_get(struct gpio_chip *chip, unsigned offset) 119 - { 120 - u8 r; 121 - int ret; 122 - int reg; 123 - 124 - reg = msic_gpio_to_ireg(offset); 125 - if (reg < 0) 126 - return reg; 127 - 128 - ret = intel_msic_reg_read(reg, &r); 129 - if (ret < 0) 130 - return ret; 131 - 132 - return !!(r & MSIC_GPIO_DIN_MASK); 133 - } 134 - 135 - static void msic_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 136 - { 137 - int reg; 138 - 139 - reg = msic_gpio_to_oreg(offset); 140 - if (reg < 0) 141 - return; 142 - 143 - intel_msic_reg_update(reg, !!value , MSIC_GPIO_DOUT_MASK); 144 - } 145 - 146 - /* 147 - * This is called from genirq with mg->buslock locked and 148 - * irq_desc->lock held. We can not access the scu bus here, so we 149 - * store the change and update in the bus_sync_unlock() function below 150 - */ 151 - static int msic_irq_type(struct irq_data *data, unsigned type) 152 - { 153 - struct msic_gpio *mg = irq_data_get_irq_chip_data(data); 154 - u32 gpio = data->irq - mg->irq_base; 155 - 156 - if (gpio >= mg->chip.ngpio) 157 - return -EINVAL; 158 - 159 - /* mark for which gpio the trigger changed, protected by buslock */ 160 - mg->trig_change_mask |= (1 << gpio); 161 - mg->trig_type = type; 162 - 163 - return 0; 164 - } 165 - 166 - static int msic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 167 - { 168 - struct msic_gpio *mg = gpiochip_get_data(chip); 169 - return mg->irq_base + offset; 170 - } 171 - 172 - static void msic_bus_lock(struct irq_data *data) 173 - { 174 - struct msic_gpio *mg = irq_data_get_irq_chip_data(data); 175 - mutex_lock(&mg->buslock); 176 - } 177 - 178 - static void msic_bus_sync_unlock(struct irq_data *data) 179 - { 180 - struct msic_gpio *mg = irq_data_get_irq_chip_data(data); 181 - int offset; 182 - int reg; 183 - u8 trig = 0; 184 - 185 - /* We can only get one change at a time as the buslock covers the 186 - entire transaction. The irq_desc->lock is dropped before we are 187 - called but that is fine */ 188 - if (mg->trig_change_mask) { 189 - offset = __ffs(mg->trig_change_mask); 190 - 191 - reg = msic_gpio_to_ireg(offset); 192 - if (reg < 0) 193 - goto out; 194 - 195 - if (mg->trig_type & IRQ_TYPE_EDGE_RISING) 196 - trig |= MSIC_GPIO_TRIG_RISE; 197 - if (mg->trig_type & IRQ_TYPE_EDGE_FALLING) 198 - trig |= MSIC_GPIO_TRIG_FALL; 199 - 200 - intel_msic_reg_update(reg, trig, MSIC_GPIO_INTCNT_MASK); 201 - mg->trig_change_mask = 0; 202 - } 203 - out: 204 - mutex_unlock(&mg->buslock); 205 - } 206 - 207 - /* Firmware does all the masking and unmasking for us, no masking here. */ 208 - static void msic_irq_unmask(struct irq_data *data) { } 209 - 210 - static void msic_irq_mask(struct irq_data *data) { } 211 - 212 - static struct irq_chip msic_irqchip = { 213 - .name = "MSIC-GPIO", 214 - .irq_mask = msic_irq_mask, 215 - .irq_unmask = msic_irq_unmask, 216 - .irq_set_type = msic_irq_type, 217 - .irq_bus_lock = msic_bus_lock, 218 - .irq_bus_sync_unlock = msic_bus_sync_unlock, 219 - }; 220 - 221 - static void msic_gpio_irq_handler(struct irq_desc *desc) 222 - { 223 - struct irq_data *data = irq_desc_get_irq_data(desc); 224 - struct msic_gpio *mg = irq_data_get_irq_handler_data(data); 225 - struct irq_chip *chip = irq_data_get_irq_chip(data); 226 - struct intel_msic *msic = pdev_to_intel_msic(mg->pdev); 227 - unsigned long pending; 228 - int i; 229 - int bitnr; 230 - u8 pin; 231 - 232 - for (i = 0; i < (mg->chip.ngpio / BITS_PER_BYTE); i++) { 233 - intel_msic_irq_read(msic, INTEL_MSIC_GPIO0LVIRQ + i, &pin); 234 - pending = pin; 235 - 236 - for_each_set_bit(bitnr, &pending, BITS_PER_BYTE) 237 - generic_handle_irq(mg->irq_base + i * BITS_PER_BYTE + bitnr); 238 - } 239 - chip->irq_eoi(data); 240 - } 241 - 242 - static int platform_msic_gpio_probe(struct platform_device *pdev) 243 - { 244 - struct device *dev = &pdev->dev; 245 - struct intel_msic_gpio_pdata *pdata = dev_get_platdata(dev); 246 - struct msic_gpio *mg; 247 - int irq = platform_get_irq(pdev, 0); 248 - int retval; 249 - int i; 250 - 251 - if (irq < 0) { 252 - dev_err(dev, "no IRQ line: %d\n", irq); 253 - return irq; 254 - } 255 - 256 - if (!pdata || !pdata->gpio_base) { 257 - dev_err(dev, "incorrect or missing platform data\n"); 258 - return -EINVAL; 259 - } 260 - 261 - mg = kzalloc(sizeof(*mg), GFP_KERNEL); 262 - if (!mg) 263 - return -ENOMEM; 264 - 265 - dev_set_drvdata(dev, mg); 266 - 267 - mg->pdev = pdev; 268 - mg->irq = irq; 269 - mg->irq_base = pdata->gpio_base + MSIC_GPIO_IRQ_OFFSET; 270 - mg->chip.label = "msic_gpio"; 271 - mg->chip.direction_input = msic_gpio_direction_input; 272 - mg->chip.direction_output = msic_gpio_direction_output; 273 - mg->chip.get = msic_gpio_get; 274 - mg->chip.set = msic_gpio_set; 275 - mg->chip.to_irq = msic_gpio_to_irq; 276 - mg->chip.base = pdata->gpio_base; 277 - mg->chip.ngpio = MSIC_NUM_GPIO; 278 - mg->chip.can_sleep = true; 279 - mg->chip.parent = dev; 280 - 281 - mutex_init(&mg->buslock); 282 - 283 - retval = gpiochip_add_data(&mg->chip, mg); 284 - if (retval) { 285 - dev_err(dev, "Adding MSIC gpio chip failed\n"); 286 - goto err; 287 - } 288 - 289 - for (i = 0; i < mg->chip.ngpio; i++) { 290 - irq_set_chip_data(i + mg->irq_base, mg); 291 - irq_set_chip_and_handler(i + mg->irq_base, 292 - &msic_irqchip, 293 - handle_simple_irq); 294 - } 295 - irq_set_chained_handler_and_data(mg->irq, msic_gpio_irq_handler, mg); 296 - 297 - return 0; 298 - err: 299 - kfree(mg); 300 - return retval; 301 - } 302 - 303 - static struct platform_driver platform_msic_gpio_driver = { 304 - .driver = { 305 - .name = "msic_gpio", 306 - }, 307 - .probe = platform_msic_gpio_probe, 308 - }; 309 - 310 - static int __init platform_msic_gpio_init(void) 311 - { 312 - return platform_driver_register(&platform_msic_gpio_driver); 313 - } 314 - subsys_initcall(platform_msic_gpio_init);
+1
drivers/gpu/drm/gma500/Kconfig
··· 30 30 config DRM_MEDFIELD 31 31 bool "Intel Medfield support (Experimental)" 32 32 depends on DRM_GMA500 && X86_INTEL_MID 33 + select INTEL_SCU_IPC 33 34 help 34 35 Say yes to include support for the Intel Medfield platform. 35 36
-2
drivers/gpu/drm/gma500/mdfld_device.c
··· 8 8 #include <linux/delay.h> 9 9 #include <linux/gpio/machine.h> 10 10 11 - #include <asm/intel_scu_ipc.h> 12 - 13 11 #include "mdfld_dsi_output.h" 14 12 #include "mdfld_output.h" 15 13 #include "mid_bios.h"
-2
drivers/gpu/drm/gma500/mdfld_dsi_output.c
··· 30 30 #include <linux/pm_runtime.h> 31 31 #include <linux/gpio/consumer.h> 32 32 33 - #include <asm/intel_scu_ipc.h> 34 - 35 33 #include "mdfld_dsi_dpi.h" 36 34 #include "mdfld_dsi_output.h" 37 35 #include "mdfld_dsi_pkg_sender.h"
+6 -2
drivers/gpu/drm/gma500/mdfld_output.c
··· 25 25 * Scott Rowe <scott.m.rowe@intel.com> 26 26 */ 27 27 28 + #include <asm/intel_scu_ipc.h> 29 + 28 30 #include "mdfld_output.h" 29 31 #include "mdfld_dsi_dpi.h" 30 32 #include "mdfld_dsi_output.h" ··· 60 58 } 61 59 } 62 60 63 - 64 61 int mdfld_output_init(struct drm_device *dev) 65 62 { 66 63 struct drm_psb_private *dev_priv = dev->dev_private; 64 + 65 + dev_priv->scu = devm_intel_scu_ipc_dev_get(&dev->pdev->dev); 66 + if (!dev_priv->scu) 67 + return -EPROBE_DEFER; 67 68 68 69 /* FIXME: hardcoded for now */ 69 70 dev_priv->mdfld_panel_id = TC35876X; ··· 76 71 mdfld_init_panel(dev, 1, HDMI); 77 72 return 0; 78 73 } 79 -
-3
drivers/gpu/drm/gma500/oaktrail_device.c
··· 10 10 #include <linux/dmi.h> 11 11 #include <linux/module.h> 12 12 13 - #include <asm/intel-mid.h> 14 - #include <asm/intel_scu_ipc.h> 15 - 16 13 #include <drm/drm.h> 17 14 18 15 #include "intel_bios.h"
+3
drivers/gpu/drm/gma500/psb_drv.h
··· 428 428 429 429 #define PSB_NUM_PIPE 3 430 430 431 + struct intel_scu_ipc_dev; 432 + 431 433 struct drm_psb_private { 432 434 struct drm_device *dev; 433 435 struct pci_dev *aux_pdev; /* Currently only used by mrst */ ··· 569 567 * Used for modifying backlight from 570 568 * xrandr -- consider removing and using HAL instead 571 569 */ 570 + struct intel_scu_ipc_dev *scu; 572 571 struct backlight_device *backlight_device; 573 572 struct drm_property *backlight_property; 574 573 bool backlight_enabled;
+13 -17
drivers/gpu/drm/gma500/tc35876x-dsi-lvds.c
··· 444 444 445 445 static void tc35876x_brightness_init(struct drm_device *dev) 446 446 { 447 + struct drm_psb_private *dev_priv = dev->dev_private; 447 448 int ret; 448 449 u8 pwmctrl; 449 450 u16 clkdiv; ··· 452 451 /* Make sure the PWM reference is the 19.2 MHz system clock. Read first 453 452 * instead of setting directly to catch potential conflicts between PWM 454 453 * users. */ 455 - ret = intel_scu_ipc_ioread8(GPIOPWMCTRL, &pwmctrl); 454 + ret = intel_scu_ipc_dev_ioread8(dev_priv->scu, GPIOPWMCTRL, &pwmctrl); 456 455 if (ret || pwmctrl != 0x01) { 457 456 if (ret) 458 457 dev_err(&dev->pdev->dev, "GPIOPWMCTRL read failed\n"); 459 458 else 460 459 dev_warn(&dev->pdev->dev, "GPIOPWMCTRL was not set to system clock (pwmctrl = 0x%02x)\n", pwmctrl); 461 460 462 - ret = intel_scu_ipc_iowrite8(GPIOPWMCTRL, 0x01); 461 + ret = intel_scu_ipc_dev_iowrite8(dev_priv->scu, GPIOPWMCTRL, 0x01); 463 462 if (ret) 464 463 dev_err(&dev->pdev->dev, "GPIOPWMCTRL set failed\n"); 465 464 } 466 465 467 466 clkdiv = calc_clkdiv(SYSTEMCLK, PWM_FREQUENCY); 468 467 469 - ret = intel_scu_ipc_iowrite8(PWM0CLKDIV1, (clkdiv >> 8) & 0xff); 468 + ret = intel_scu_ipc_dev_iowrite8(dev_priv->scu, PWM0CLKDIV1, (clkdiv >> 8) & 0xff); 470 469 if (!ret) 471 - ret = intel_scu_ipc_iowrite8(PWM0CLKDIV0, clkdiv & 0xff); 470 + ret = intel_scu_ipc_dev_iowrite8(dev_priv->scu, PWM0CLKDIV0, clkdiv & 0xff); 472 471 473 472 if (ret) 474 473 dev_err(&dev->pdev->dev, "PWM0CLKDIV set failed\n"); ··· 481 480 482 481 void tc35876x_brightness_control(struct drm_device *dev, int level) 483 482 { 483 + struct drm_psb_private *dev_priv = dev->dev_private; 484 484 int ret; 485 485 u8 duty_val; 486 486 u8 panel_duty_val; ··· 497 495 panel_duty_val = (2 * level - 100) * 0xA9 / 498 496 MDFLD_DSI_BRIGHTNESS_MAX_LEVEL + 0x56; 499 497 500 - ret = intel_scu_ipc_iowrite8(PWM0DUTYCYCLE, duty_val); 498 + ret = intel_scu_ipc_dev_iowrite8(dev_priv->scu, PWM0DUTYCYCLE, duty_val); 501 499 if (ret) 502 500 dev_err(&tc35876x_client->dev, "%s: ipc write fail\n", 503 501 __func__); ··· 518 516 519 517 dev_dbg(&tc35876x_client->dev, "%s\n", __func__); 520 518 521 - if (bridge_bl_enable) 522 - gpiod_set_value_cansleep(bridge_bl_enable, 0); 519 + gpiod_set_value_cansleep(bridge_bl_enable, 0); 523 520 524 - if (backlight_voltage) 525 - gpiod_set_value_cansleep(backlight_voltage, 0); 521 + gpiod_set_value_cansleep(backlight_voltage, 0); 526 522 } 527 523 528 524 void tc35876x_toshiba_bridge_panel_on(struct drm_device *dev) ··· 565 565 "i2c write failed (%d)\n", ret); 566 566 } 567 567 568 - if (bridge_bl_enable) 569 - gpiod_set_value_cansleep(bridge_bl_enable, 1); 568 + gpiod_set_value_cansleep(bridge_bl_enable, 1); 570 569 571 570 tc35876x_brightness_control(dev, dev_priv->brightness_adjusted); 572 571 } ··· 639 640 bridge_reset = devm_gpiod_get_optional(&client->dev, "bridge-reset", GPIOD_OUT_LOW); 640 641 if (IS_ERR(bridge_reset)) 641 642 return PTR_ERR(bridge_reset); 642 - if (bridge_reset) 643 - gpiod_set_consumer_name(bridge_reset, "tc35876x bridge reset"); 643 + gpiod_set_consumer_name(bridge_reset, "tc35876x bridge reset"); 644 644 645 645 bridge_bl_enable = devm_gpiod_get_optional(&client->dev, "bl-en", GPIOD_OUT_LOW); 646 646 if (IS_ERR(bridge_bl_enable)) 647 647 return PTR_ERR(bridge_bl_enable); 648 - if (bridge_bl_enable) 649 - gpiod_set_consumer_name(bridge_bl_enable, "tc35876x panel bl en"); 648 + gpiod_set_consumer_name(bridge_bl_enable, "tc35876x panel bl en"); 650 649 651 650 backlight_voltage = devm_gpiod_get_optional(&client->dev, "vadd", GPIOD_OUT_LOW); 652 651 if (IS_ERR(backlight_voltage)) 653 652 return PTR_ERR(backlight_voltage); 654 - if (backlight_voltage) 655 - gpiod_set_consumer_name(backlight_voltage, "tc35876x panel vadd"); 653 + gpiod_set_consumer_name(backlight_voltage, "tc35876x panel vadd"); 656 654 657 655 tc35876x_client = client; 658 656
+8
drivers/platform/x86/Kconfig
··· 1425 1425 and SCU (sometimes called PMC as well). The driver currently 1426 1426 supports Intel Elkhart Lake and compatible platforms. 1427 1427 1428 + config INTEL_SCU_WDT 1429 + bool 1430 + default INTEL_SCU_PCI 1431 + depends on INTEL_MID_WATCHDOG 1432 + help 1433 + This is a specific platform code to instantiate watchdog device 1434 + on ACPI-based Intel MID platforms. 1435 + 1428 1436 config INTEL_SCU_IPC_UTIL 1429 1437 tristate "Intel SCU IPC utility driver" 1430 1438 depends on INTEL_SCU
+1
drivers/platform/x86/Makefile
··· 146 146 obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o 147 147 obj-$(CONFIG_INTEL_SCU_PCI) += intel_scu_pcidrv.o 148 148 obj-$(CONFIG_INTEL_SCU_PLATFORM) += intel_scu_pltdrv.o 149 + obj-$(CONFIG_INTEL_SCU_WDT) += intel_scu_wdt.o 149 150 obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o 150 151 obj-$(CONFIG_INTEL_TELEMETRY) += intel_telemetry_core.o \ 151 152 intel_telemetry_pltdrv.o \
-12
drivers/rtc/Kconfig
··· 973 973 Direct support for the real-time clock found on every Alpha 974 974 system, specifically MC146818 compatibles. If in doubt, say Y. 975 975 976 - config RTC_DRV_VRTC 977 - tristate "Virtual RTC for Intel MID platforms" 978 - depends on X86_INTEL_MID 979 - default y if X86_INTEL_MID 980 - 981 - help 982 - Say "yes" here to get direct support for the real time clock 983 - found on Moorestown platforms. The VRTC is a emulated RTC that 984 - derives its clock source from a real RTC in the PMIC. The MC146818 985 - style programming interface is mostly conserved, but any 986 - updates are done via IPC calls to the system controller FW. 987 - 988 976 config RTC_DRV_DS1216 989 977 tristate "Dallas DS1216" 990 978 depends on SNI_RM
-1
drivers/rtc/Makefile
··· 174 174 obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o 175 175 obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 176 176 obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 177 - obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 178 177 obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o 179 178 obj-$(CONFIG_RTC_DRV_WILCO_EC) += rtc-wilco-ec.o 180 179 obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o
-521
drivers/rtc/rtc-mrst.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * rtc-mrst.c: Driver for Moorestown virtual RTC 4 - * 5 - * (C) Copyright 2009 Intel Corporation 6 - * Author: Jacob Pan (jacob.jun.pan@intel.com) 7 - * Feng Tang (feng.tang@intel.com) 8 - * 9 - * Note: 10 - * VRTC is emulated by system controller firmware, the real HW 11 - * RTC is located in the PMIC device. SCU FW shadows PMIC RTC 12 - * in a memory mapped IO space that is visible to the host IA 13 - * processor. 14 - * 15 - * This driver is based upon drivers/rtc/rtc-cmos.c 16 - */ 17 - 18 - /* 19 - * Note: 20 - * * vRTC only supports binary mode and 24H mode 21 - * * vRTC only support PIE and AIE, no UIE, and its PIE only happens 22 - * at 23:59:59pm everyday, no support for adjustable frequency 23 - * * Alarm function is also limited to hr/min/sec. 24 - */ 25 - 26 - #include <linux/mod_devicetable.h> 27 - #include <linux/platform_device.h> 28 - #include <linux/interrupt.h> 29 - #include <linux/spinlock.h> 30 - #include <linux/kernel.h> 31 - #include <linux/mc146818rtc.h> 32 - #include <linux/module.h> 33 - #include <linux/init.h> 34 - #include <linux/sfi.h> 35 - 36 - #include <asm/intel_scu_ipc.h> 37 - #include <asm/intel-mid.h> 38 - #include <asm/intel_mid_vrtc.h> 39 - 40 - struct mrst_rtc { 41 - struct rtc_device *rtc; 42 - struct device *dev; 43 - int irq; 44 - 45 - u8 enabled_wake; 46 - u8 suspend_ctrl; 47 - }; 48 - 49 - static const char driver_name[] = "rtc_mrst"; 50 - 51 - #define RTC_IRQMASK (RTC_PF | RTC_AF) 52 - 53 - static inline int is_intr(u8 rtc_intr) 54 - { 55 - if (!(rtc_intr & RTC_IRQF)) 56 - return 0; 57 - return rtc_intr & RTC_IRQMASK; 58 - } 59 - 60 - static inline unsigned char vrtc_is_updating(void) 61 - { 62 - unsigned char uip; 63 - unsigned long flags; 64 - 65 - spin_lock_irqsave(&rtc_lock, flags); 66 - uip = (vrtc_cmos_read(RTC_FREQ_SELECT) & RTC_UIP); 67 - spin_unlock_irqrestore(&rtc_lock, flags); 68 - return uip; 69 - } 70 - 71 - /* 72 - * rtc_time's year contains the increment over 1900, but vRTC's YEAR 73 - * register can't be programmed to value larger than 0x64, so vRTC 74 - * driver chose to use 1972 (1970 is UNIX time start point) as the base, 75 - * and does the translation at read/write time. 76 - * 77 - * Why not just use 1970 as the offset? it's because using 1972 will 78 - * make it consistent in leap year setting for both vrtc and low-level 79 - * physical rtc devices. Then why not use 1960 as the offset? If we use 80 - * 1960, for a device's first use, its YEAR register is 0 and the system 81 - * year will be parsed as 1960 which is not a valid UNIX time and will 82 - * cause many applications to fail mysteriously. 83 - */ 84 - static int mrst_read_time(struct device *dev, struct rtc_time *time) 85 - { 86 - unsigned long flags; 87 - 88 - if (vrtc_is_updating()) 89 - msleep(20); 90 - 91 - spin_lock_irqsave(&rtc_lock, flags); 92 - time->tm_sec = vrtc_cmos_read(RTC_SECONDS); 93 - time->tm_min = vrtc_cmos_read(RTC_MINUTES); 94 - time->tm_hour = vrtc_cmos_read(RTC_HOURS); 95 - time->tm_mday = vrtc_cmos_read(RTC_DAY_OF_MONTH); 96 - time->tm_mon = vrtc_cmos_read(RTC_MONTH); 97 - time->tm_year = vrtc_cmos_read(RTC_YEAR); 98 - spin_unlock_irqrestore(&rtc_lock, flags); 99 - 100 - /* Adjust for the 1972/1900 */ 101 - time->tm_year += 72; 102 - time->tm_mon--; 103 - return 0; 104 - } 105 - 106 - static int mrst_set_time(struct device *dev, struct rtc_time *time) 107 - { 108 - int ret; 109 - unsigned long flags; 110 - unsigned char mon, day, hrs, min, sec; 111 - unsigned int yrs; 112 - 113 - yrs = time->tm_year; 114 - mon = time->tm_mon + 1; /* tm_mon starts at zero */ 115 - day = time->tm_mday; 116 - hrs = time->tm_hour; 117 - min = time->tm_min; 118 - sec = time->tm_sec; 119 - 120 - if (yrs < 72 || yrs > 172) 121 - return -EINVAL; 122 - yrs -= 72; 123 - 124 - spin_lock_irqsave(&rtc_lock, flags); 125 - 126 - vrtc_cmos_write(yrs, RTC_YEAR); 127 - vrtc_cmos_write(mon, RTC_MONTH); 128 - vrtc_cmos_write(day, RTC_DAY_OF_MONTH); 129 - vrtc_cmos_write(hrs, RTC_HOURS); 130 - vrtc_cmos_write(min, RTC_MINUTES); 131 - vrtc_cmos_write(sec, RTC_SECONDS); 132 - 133 - spin_unlock_irqrestore(&rtc_lock, flags); 134 - 135 - ret = intel_scu_ipc_simple_command(IPCMSG_VRTC, IPC_CMD_VRTC_SETTIME); 136 - return ret; 137 - } 138 - 139 - static int mrst_read_alarm(struct device *dev, struct rtc_wkalrm *t) 140 - { 141 - struct mrst_rtc *mrst = dev_get_drvdata(dev); 142 - unsigned char rtc_control; 143 - 144 - if (mrst->irq <= 0) 145 - return -EIO; 146 - 147 - /* vRTC only supports binary mode */ 148 - spin_lock_irq(&rtc_lock); 149 - t->time.tm_sec = vrtc_cmos_read(RTC_SECONDS_ALARM); 150 - t->time.tm_min = vrtc_cmos_read(RTC_MINUTES_ALARM); 151 - t->time.tm_hour = vrtc_cmos_read(RTC_HOURS_ALARM); 152 - 153 - rtc_control = vrtc_cmos_read(RTC_CONTROL); 154 - spin_unlock_irq(&rtc_lock); 155 - 156 - t->enabled = !!(rtc_control & RTC_AIE); 157 - t->pending = 0; 158 - 159 - return 0; 160 - } 161 - 162 - static void mrst_checkintr(struct mrst_rtc *mrst, unsigned char rtc_control) 163 - { 164 - unsigned char rtc_intr; 165 - 166 - /* 167 - * NOTE after changing RTC_xIE bits we always read INTR_FLAGS; 168 - * allegedly some older rtcs need that to handle irqs properly 169 - */ 170 - rtc_intr = vrtc_cmos_read(RTC_INTR_FLAGS); 171 - rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; 172 - if (is_intr(rtc_intr)) 173 - rtc_update_irq(mrst->rtc, 1, rtc_intr); 174 - } 175 - 176 - static void mrst_irq_enable(struct mrst_rtc *mrst, unsigned char mask) 177 - { 178 - unsigned char rtc_control; 179 - 180 - /* 181 - * Flush any pending IRQ status, notably for update irqs, 182 - * before we enable new IRQs 183 - */ 184 - rtc_control = vrtc_cmos_read(RTC_CONTROL); 185 - mrst_checkintr(mrst, rtc_control); 186 - 187 - rtc_control |= mask; 188 - vrtc_cmos_write(rtc_control, RTC_CONTROL); 189 - 190 - mrst_checkintr(mrst, rtc_control); 191 - } 192 - 193 - static void mrst_irq_disable(struct mrst_rtc *mrst, unsigned char mask) 194 - { 195 - unsigned char rtc_control; 196 - 197 - rtc_control = vrtc_cmos_read(RTC_CONTROL); 198 - rtc_control &= ~mask; 199 - vrtc_cmos_write(rtc_control, RTC_CONTROL); 200 - mrst_checkintr(mrst, rtc_control); 201 - } 202 - 203 - static int mrst_set_alarm(struct device *dev, struct rtc_wkalrm *t) 204 - { 205 - struct mrst_rtc *mrst = dev_get_drvdata(dev); 206 - unsigned char hrs, min, sec; 207 - int ret = 0; 208 - 209 - if (!mrst->irq) 210 - return -EIO; 211 - 212 - hrs = t->time.tm_hour; 213 - min = t->time.tm_min; 214 - sec = t->time.tm_sec; 215 - 216 - spin_lock_irq(&rtc_lock); 217 - /* Next rtc irq must not be from previous alarm setting */ 218 - mrst_irq_disable(mrst, RTC_AIE); 219 - 220 - /* Update alarm */ 221 - vrtc_cmos_write(hrs, RTC_HOURS_ALARM); 222 - vrtc_cmos_write(min, RTC_MINUTES_ALARM); 223 - vrtc_cmos_write(sec, RTC_SECONDS_ALARM); 224 - 225 - spin_unlock_irq(&rtc_lock); 226 - 227 - ret = intel_scu_ipc_simple_command(IPCMSG_VRTC, IPC_CMD_VRTC_SETALARM); 228 - if (ret) 229 - return ret; 230 - 231 - spin_lock_irq(&rtc_lock); 232 - if (t->enabled) 233 - mrst_irq_enable(mrst, RTC_AIE); 234 - 235 - spin_unlock_irq(&rtc_lock); 236 - 237 - return 0; 238 - } 239 - 240 - /* Currently, the vRTC doesn't support UIE ON/OFF */ 241 - static int mrst_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 242 - { 243 - struct mrst_rtc *mrst = dev_get_drvdata(dev); 244 - unsigned long flags; 245 - 246 - spin_lock_irqsave(&rtc_lock, flags); 247 - if (enabled) 248 - mrst_irq_enable(mrst, RTC_AIE); 249 - else 250 - mrst_irq_disable(mrst, RTC_AIE); 251 - spin_unlock_irqrestore(&rtc_lock, flags); 252 - return 0; 253 - } 254 - 255 - 256 - #if IS_ENABLED(CONFIG_RTC_INTF_PROC) 257 - 258 - static int mrst_procfs(struct device *dev, struct seq_file *seq) 259 - { 260 - unsigned char rtc_control; 261 - 262 - spin_lock_irq(&rtc_lock); 263 - rtc_control = vrtc_cmos_read(RTC_CONTROL); 264 - spin_unlock_irq(&rtc_lock); 265 - 266 - seq_printf(seq, 267 - "periodic_IRQ\t: %s\n" 268 - "alarm\t\t: %s\n" 269 - "BCD\t\t: no\n" 270 - "periodic_freq\t: daily (not adjustable)\n", 271 - (rtc_control & RTC_PIE) ? "on" : "off", 272 - (rtc_control & RTC_AIE) ? "on" : "off"); 273 - 274 - return 0; 275 - } 276 - 277 - #else 278 - #define mrst_procfs NULL 279 - #endif 280 - 281 - static const struct rtc_class_ops mrst_rtc_ops = { 282 - .read_time = mrst_read_time, 283 - .set_time = mrst_set_time, 284 - .read_alarm = mrst_read_alarm, 285 - .set_alarm = mrst_set_alarm, 286 - .proc = mrst_procfs, 287 - .alarm_irq_enable = mrst_rtc_alarm_irq_enable, 288 - }; 289 - 290 - static struct mrst_rtc mrst_rtc; 291 - 292 - /* 293 - * When vRTC IRQ is captured by SCU FW, FW will clear the AIE bit in 294 - * Reg B, so no need for this driver to clear it 295 - */ 296 - static irqreturn_t mrst_rtc_irq(int irq, void *p) 297 - { 298 - u8 irqstat; 299 - 300 - spin_lock(&rtc_lock); 301 - /* This read will clear all IRQ flags inside Reg C */ 302 - irqstat = vrtc_cmos_read(RTC_INTR_FLAGS); 303 - spin_unlock(&rtc_lock); 304 - 305 - irqstat &= RTC_IRQMASK | RTC_IRQF; 306 - if (is_intr(irqstat)) { 307 - rtc_update_irq(p, 1, irqstat); 308 - return IRQ_HANDLED; 309 - } 310 - return IRQ_NONE; 311 - } 312 - 313 - static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, 314 - int rtc_irq) 315 - { 316 - int retval = 0; 317 - unsigned char rtc_control; 318 - 319 - /* There can be only one ... */ 320 - if (mrst_rtc.dev) 321 - return -EBUSY; 322 - 323 - if (!iomem) 324 - return -ENODEV; 325 - 326 - iomem = devm_request_mem_region(dev, iomem->start, resource_size(iomem), 327 - driver_name); 328 - if (!iomem) { 329 - dev_dbg(dev, "i/o mem already in use.\n"); 330 - return -EBUSY; 331 - } 332 - 333 - mrst_rtc.irq = rtc_irq; 334 - mrst_rtc.dev = dev; 335 - dev_set_drvdata(dev, &mrst_rtc); 336 - 337 - mrst_rtc.rtc = devm_rtc_allocate_device(dev); 338 - if (IS_ERR(mrst_rtc.rtc)) 339 - return PTR_ERR(mrst_rtc.rtc); 340 - 341 - mrst_rtc.rtc->ops = &mrst_rtc_ops; 342 - 343 - rename_region(iomem, dev_name(&mrst_rtc.rtc->dev)); 344 - 345 - spin_lock_irq(&rtc_lock); 346 - mrst_irq_disable(&mrst_rtc, RTC_PIE | RTC_AIE); 347 - rtc_control = vrtc_cmos_read(RTC_CONTROL); 348 - spin_unlock_irq(&rtc_lock); 349 - 350 - if (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY))) 351 - dev_dbg(dev, "TODO: support more than 24-hr BCD mode\n"); 352 - 353 - if (rtc_irq) { 354 - retval = devm_request_irq(dev, rtc_irq, mrst_rtc_irq, 355 - 0, dev_name(&mrst_rtc.rtc->dev), 356 - mrst_rtc.rtc); 357 - if (retval < 0) { 358 - dev_dbg(dev, "IRQ %d is already in use, err %d\n", 359 - rtc_irq, retval); 360 - goto cleanup0; 361 - } 362 - } 363 - 364 - retval = devm_rtc_register_device(mrst_rtc.rtc); 365 - if (retval) 366 - goto cleanup0; 367 - 368 - dev_dbg(dev, "initialised\n"); 369 - return 0; 370 - 371 - cleanup0: 372 - mrst_rtc.dev = NULL; 373 - dev_err(dev, "rtc-mrst: unable to initialise\n"); 374 - return retval; 375 - } 376 - 377 - static void rtc_mrst_do_shutdown(void) 378 - { 379 - spin_lock_irq(&rtc_lock); 380 - mrst_irq_disable(&mrst_rtc, RTC_IRQMASK); 381 - spin_unlock_irq(&rtc_lock); 382 - } 383 - 384 - static void rtc_mrst_do_remove(struct device *dev) 385 - { 386 - struct mrst_rtc *mrst = dev_get_drvdata(dev); 387 - 388 - rtc_mrst_do_shutdown(); 389 - 390 - mrst->rtc = NULL; 391 - mrst->dev = NULL; 392 - } 393 - 394 - #ifdef CONFIG_PM_SLEEP 395 - static int mrst_suspend(struct device *dev) 396 - { 397 - struct mrst_rtc *mrst = dev_get_drvdata(dev); 398 - unsigned char tmp; 399 - 400 - /* Only the alarm might be a wakeup event source */ 401 - spin_lock_irq(&rtc_lock); 402 - mrst->suspend_ctrl = tmp = vrtc_cmos_read(RTC_CONTROL); 403 - if (tmp & (RTC_PIE | RTC_AIE)) { 404 - unsigned char mask; 405 - 406 - if (device_may_wakeup(dev)) 407 - mask = RTC_IRQMASK & ~RTC_AIE; 408 - else 409 - mask = RTC_IRQMASK; 410 - tmp &= ~mask; 411 - vrtc_cmos_write(tmp, RTC_CONTROL); 412 - 413 - mrst_checkintr(mrst, tmp); 414 - } 415 - spin_unlock_irq(&rtc_lock); 416 - 417 - if (tmp & RTC_AIE) { 418 - mrst->enabled_wake = 1; 419 - enable_irq_wake(mrst->irq); 420 - } 421 - 422 - dev_dbg(&mrst_rtc.rtc->dev, "suspend%s, ctrl %02x\n", 423 - (tmp & RTC_AIE) ? ", alarm may wake" : "", 424 - tmp); 425 - 426 - return 0; 427 - } 428 - 429 - /* 430 - * We want RTC alarms to wake us from the deep power saving state 431 - */ 432 - static inline int mrst_poweroff(struct device *dev) 433 - { 434 - return mrst_suspend(dev); 435 - } 436 - 437 - static int mrst_resume(struct device *dev) 438 - { 439 - struct mrst_rtc *mrst = dev_get_drvdata(dev); 440 - unsigned char tmp = mrst->suspend_ctrl; 441 - 442 - /* Re-enable any irqs previously active */ 443 - if (tmp & RTC_IRQMASK) { 444 - unsigned char mask; 445 - 446 - if (mrst->enabled_wake) { 447 - disable_irq_wake(mrst->irq); 448 - mrst->enabled_wake = 0; 449 - } 450 - 451 - spin_lock_irq(&rtc_lock); 452 - do { 453 - vrtc_cmos_write(tmp, RTC_CONTROL); 454 - 455 - mask = vrtc_cmos_read(RTC_INTR_FLAGS); 456 - mask &= (tmp & RTC_IRQMASK) | RTC_IRQF; 457 - if (!is_intr(mask)) 458 - break; 459 - 460 - rtc_update_irq(mrst->rtc, 1, mask); 461 - tmp &= ~RTC_AIE; 462 - } while (mask & RTC_AIE); 463 - spin_unlock_irq(&rtc_lock); 464 - } 465 - 466 - dev_dbg(&mrst_rtc.rtc->dev, "resume, ctrl %02x\n", tmp); 467 - 468 - return 0; 469 - } 470 - 471 - static SIMPLE_DEV_PM_OPS(mrst_pm_ops, mrst_suspend, mrst_resume); 472 - #define MRST_PM_OPS (&mrst_pm_ops) 473 - 474 - #else 475 - #define MRST_PM_OPS NULL 476 - 477 - static inline int mrst_poweroff(struct device *dev) 478 - { 479 - return -ENOSYS; 480 - } 481 - 482 - #endif 483 - 484 - static int vrtc_mrst_platform_probe(struct platform_device *pdev) 485 - { 486 - return vrtc_mrst_do_probe(&pdev->dev, 487 - platform_get_resource(pdev, IORESOURCE_MEM, 0), 488 - platform_get_irq(pdev, 0)); 489 - } 490 - 491 - static int vrtc_mrst_platform_remove(struct platform_device *pdev) 492 - { 493 - rtc_mrst_do_remove(&pdev->dev); 494 - return 0; 495 - } 496 - 497 - static void vrtc_mrst_platform_shutdown(struct platform_device *pdev) 498 - { 499 - if (system_state == SYSTEM_POWER_OFF && !mrst_poweroff(&pdev->dev)) 500 - return; 501 - 502 - rtc_mrst_do_shutdown(); 503 - } 504 - 505 - MODULE_ALIAS("platform:vrtc_mrst"); 506 - 507 - static struct platform_driver vrtc_mrst_platform_driver = { 508 - .probe = vrtc_mrst_platform_probe, 509 - .remove = vrtc_mrst_platform_remove, 510 - .shutdown = vrtc_mrst_platform_shutdown, 511 - .driver = { 512 - .name = driver_name, 513 - .pm = MRST_PM_OPS, 514 - } 515 - }; 516 - 517 - module_platform_driver(vrtc_mrst_platform_driver); 518 - 519 - MODULE_AUTHOR("Jacob Pan; Feng Tang"); 520 - MODULE_DESCRIPTION("Driver for Moorestown virtual RTC"); 521 - MODULE_LICENSE("GPL");
-9
drivers/watchdog/Kconfig
··· 1219 1219 To compile this driver as a module, choose M here: the 1220 1220 module will be called ie6xx_wdt. 1221 1221 1222 - config INTEL_SCU_WATCHDOG 1223 - bool "Intel SCU Watchdog for Mobile Platforms" 1224 - depends on X86_INTEL_MID 1225 - help 1226 - Hardware driver for the watchdog time built into the Intel SCU 1227 - for Intel Mobile Platforms. 1228 - 1229 - To compile this driver as a module, choose M here. 1230 - 1231 1222 config INTEL_MID_WATCHDOG 1232 1223 tristate "Intel MID Watchdog Timer" 1233 1224 depends on X86_INTEL_MID
-1
drivers/watchdog/Makefile
··· 140 140 obj-$(CONFIG_W83977F_WDT) += w83977f_wdt.o 141 141 obj-$(CONFIG_MACHZ_WDT) += machzwd.o 142 142 obj-$(CONFIG_SBC_EPX_C3_WATCHDOG) += sbc_epx_c3.o 143 - obj-$(CONFIG_INTEL_SCU_WATCHDOG) += intel_scu_watchdog.o 144 143 obj-$(CONFIG_INTEL_MID_WATCHDOG) += intel-mid_wdt.o 145 144 obj-$(CONFIG_INTEL_MEI_WDT) += mei_wdt.o 146 145 obj-$(CONFIG_NI903X_WDT) += ni903x_wdt.o
+4 -4
drivers/watchdog/intel-mid_wdt.c
··· 154 154 watchdog_set_nowayout(wdt_dev, WATCHDOG_NOWAYOUT); 155 155 watchdog_set_drvdata(wdt_dev, mid); 156 156 157 + mid->scu = devm_intel_scu_ipc_dev_get(dev); 158 + if (!mid->scu) 159 + return -EPROBE_DEFER; 160 + 157 161 ret = devm_request_irq(dev, pdata->irq, mid_wdt_irq, 158 162 IRQF_SHARED | IRQF_NO_SUSPEND, "watchdog", 159 163 wdt_dev); ··· 165 161 dev_err(dev, "error requesting warning irq %d\n", pdata->irq); 166 162 return ret; 167 163 } 168 - 169 - mid->scu = devm_intel_scu_ipc_dev_get(dev); 170 - if (!mid->scu) 171 - return -EPROBE_DEFER; 172 164 173 165 /* 174 166 * The firmware followed by U-Boot leaves the watchdog running
-533
drivers/watchdog/intel_scu_watchdog.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Intel_SCU 0.2: An Intel SCU IOH Based Watchdog Device 4 - * for Intel part #(s): 5 - * - AF82MP20 PCH 6 - * 7 - * Copyright (C) 2009-2010 Intel Corporation. All rights reserved. 8 - */ 9 - 10 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 - 12 - #include <linux/compiler.h> 13 - #include <linux/kernel.h> 14 - #include <linux/moduleparam.h> 15 - #include <linux/types.h> 16 - #include <linux/miscdevice.h> 17 - #include <linux/watchdog.h> 18 - #include <linux/fs.h> 19 - #include <linux/notifier.h> 20 - #include <linux/reboot.h> 21 - #include <linux/init.h> 22 - #include <linux/jiffies.h> 23 - #include <linux/uaccess.h> 24 - #include <linux/slab.h> 25 - #include <linux/io.h> 26 - #include <linux/interrupt.h> 27 - #include <linux/delay.h> 28 - #include <linux/sched.h> 29 - #include <linux/signal.h> 30 - #include <linux/sfi.h> 31 - #include <asm/irq.h> 32 - #include <linux/atomic.h> 33 - #include <asm/intel_scu_ipc.h> 34 - #include <asm/apb_timer.h> 35 - #include <asm/intel-mid.h> 36 - 37 - #include "intel_scu_watchdog.h" 38 - 39 - /* Bounds number of times we will retry loading time count */ 40 - /* This retry is a work around for a silicon bug. */ 41 - #define MAX_RETRY 16 42 - 43 - #define IPC_SET_WATCHDOG_TIMER 0xF8 44 - 45 - static int timer_margin = DEFAULT_SOFT_TO_HARD_MARGIN; 46 - module_param(timer_margin, int, 0); 47 - MODULE_PARM_DESC(timer_margin, 48 - "Watchdog timer margin" 49 - "Time between interrupt and resetting the system" 50 - "The range is from 1 to 160" 51 - "This is the time for all keep alives to arrive"); 52 - 53 - static int timer_set = DEFAULT_TIME; 54 - module_param(timer_set, int, 0); 55 - MODULE_PARM_DESC(timer_set, 56 - "Default Watchdog timer setting" 57 - "Complete cycle time" 58 - "The range is from 1 to 170" 59 - "This is the time for all keep alives to arrive"); 60 - 61 - /* After watchdog device is closed, check force_boot. If: 62 - * force_boot == 0, then force boot on next watchdog interrupt after close, 63 - * force_boot == 1, then force boot immediately when device is closed. 64 - */ 65 - static int force_boot; 66 - module_param(force_boot, int, 0); 67 - MODULE_PARM_DESC(force_boot, 68 - "A value of 1 means that the driver will reboot" 69 - "the system immediately if the /dev/watchdog device is closed" 70 - "A value of 0 means that when /dev/watchdog device is closed" 71 - "the watchdog timer will be refreshed for one more interval" 72 - "of length: timer_set. At the end of this interval, the" 73 - "watchdog timer will reset the system." 74 - ); 75 - 76 - /* there is only one device in the system now; this can be made into 77 - * an array in the future if we have more than one device */ 78 - 79 - static struct intel_scu_watchdog_dev watchdog_device; 80 - 81 - /* Forces restart, if force_reboot is set */ 82 - static void watchdog_fire(void) 83 - { 84 - if (force_boot) { 85 - pr_crit("Initiating system reboot\n"); 86 - emergency_restart(); 87 - pr_crit("Reboot didn't ?????\n"); 88 - } 89 - 90 - else { 91 - pr_crit("Immediate Reboot Disabled\n"); 92 - pr_crit("System will reset when watchdog timer times out!\n"); 93 - } 94 - } 95 - 96 - static int check_timer_margin(int new_margin) 97 - { 98 - if ((new_margin < MIN_TIME_CYCLE) || 99 - (new_margin > MAX_TIME - timer_set)) { 100 - pr_debug("value of new_margin %d is out of the range %d to %d\n", 101 - new_margin, MIN_TIME_CYCLE, MAX_TIME - timer_set); 102 - return -EINVAL; 103 - } 104 - return 0; 105 - } 106 - 107 - /* 108 - * IPC operations 109 - */ 110 - static int watchdog_set_ipc(int soft_threshold, int threshold) 111 - { 112 - u32 *ipc_wbuf; 113 - u8 cbuf[16] = { '\0' }; 114 - int ipc_ret = 0; 115 - 116 - ipc_wbuf = (u32 *)&cbuf; 117 - ipc_wbuf[0] = soft_threshold; 118 - ipc_wbuf[1] = threshold; 119 - 120 - ipc_ret = intel_scu_ipc_command( 121 - IPC_SET_WATCHDOG_TIMER, 122 - 0, 123 - ipc_wbuf, 124 - 2, 125 - NULL, 126 - 0); 127 - 128 - if (ipc_ret != 0) 129 - pr_err("Error setting SCU watchdog timer: %x\n", ipc_ret); 130 - 131 - return ipc_ret; 132 - }; 133 - 134 - /* 135 - * Intel_SCU operations 136 - */ 137 - 138 - /* timer interrupt handler */ 139 - static irqreturn_t watchdog_timer_interrupt(int irq, void *dev_id) 140 - { 141 - int int_status; 142 - int_status = ioread32(watchdog_device.timer_interrupt_status_addr); 143 - 144 - pr_debug("irq, int_status: %x\n", int_status); 145 - 146 - if (int_status != 0) 147 - return IRQ_NONE; 148 - 149 - /* has the timer been started? If not, then this is spurious */ 150 - if (watchdog_device.timer_started == 0) { 151 - pr_debug("spurious interrupt received\n"); 152 - return IRQ_HANDLED; 153 - } 154 - 155 - /* temporarily disable the timer */ 156 - iowrite32(0x00000002, watchdog_device.timer_control_addr); 157 - 158 - /* set the timer to the threshold */ 159 - iowrite32(watchdog_device.threshold, 160 - watchdog_device.timer_load_count_addr); 161 - 162 - /* allow the timer to run */ 163 - iowrite32(0x00000003, watchdog_device.timer_control_addr); 164 - 165 - return IRQ_HANDLED; 166 - } 167 - 168 - static int intel_scu_keepalive(void) 169 - { 170 - 171 - /* read eoi register - clears interrupt */ 172 - ioread32(watchdog_device.timer_clear_interrupt_addr); 173 - 174 - /* temporarily disable the timer */ 175 - iowrite32(0x00000002, watchdog_device.timer_control_addr); 176 - 177 - /* set the timer to the soft_threshold */ 178 - iowrite32(watchdog_device.soft_threshold, 179 - watchdog_device.timer_load_count_addr); 180 - 181 - /* allow the timer to run */ 182 - iowrite32(0x00000003, watchdog_device.timer_control_addr); 183 - 184 - return 0; 185 - } 186 - 187 - static int intel_scu_stop(void) 188 - { 189 - iowrite32(0, watchdog_device.timer_control_addr); 190 - return 0; 191 - } 192 - 193 - static int intel_scu_set_heartbeat(u32 t) 194 - { 195 - int ipc_ret; 196 - int retry_count; 197 - u32 soft_value; 198 - u32 hw_value; 199 - 200 - watchdog_device.timer_set = t; 201 - watchdog_device.threshold = 202 - timer_margin * watchdog_device.timer_tbl_ptr->freq_hz; 203 - watchdog_device.soft_threshold = 204 - (watchdog_device.timer_set - timer_margin) 205 - * watchdog_device.timer_tbl_ptr->freq_hz; 206 - 207 - pr_debug("set_heartbeat: timer freq is %d\n", 208 - watchdog_device.timer_tbl_ptr->freq_hz); 209 - pr_debug("set_heartbeat: timer_set is %x (hex)\n", 210 - watchdog_device.timer_set); 211 - pr_debug("set_heartbeat: timer_margin is %x (hex)\n", timer_margin); 212 - pr_debug("set_heartbeat: threshold is %x (hex)\n", 213 - watchdog_device.threshold); 214 - pr_debug("set_heartbeat: soft_threshold is %x (hex)\n", 215 - watchdog_device.soft_threshold); 216 - 217 - /* Adjust thresholds by FREQ_ADJUSTMENT factor, to make the */ 218 - /* watchdog timing come out right. */ 219 - watchdog_device.threshold = 220 - watchdog_device.threshold / FREQ_ADJUSTMENT; 221 - watchdog_device.soft_threshold = 222 - watchdog_device.soft_threshold / FREQ_ADJUSTMENT; 223 - 224 - /* temporarily disable the timer */ 225 - iowrite32(0x00000002, watchdog_device.timer_control_addr); 226 - 227 - /* send the threshold and soft_threshold via IPC to the processor */ 228 - ipc_ret = watchdog_set_ipc(watchdog_device.soft_threshold, 229 - watchdog_device.threshold); 230 - 231 - if (ipc_ret != 0) { 232 - /* Make sure the watchdog timer is stopped */ 233 - intel_scu_stop(); 234 - return ipc_ret; 235 - } 236 - 237 - /* Soft Threshold set loop. Early versions of silicon did */ 238 - /* not always set this count correctly. This loop checks */ 239 - /* the value and retries if it was not set correctly. */ 240 - 241 - retry_count = 0; 242 - soft_value = watchdog_device.soft_threshold & 0xFFFF0000; 243 - do { 244 - 245 - /* Make sure timer is stopped */ 246 - intel_scu_stop(); 247 - 248 - if (MAX_RETRY < retry_count++) { 249 - /* Unable to set timer value */ 250 - pr_err("Unable to set timer\n"); 251 - return -ENODEV; 252 - } 253 - 254 - /* set the timer to the soft threshold */ 255 - iowrite32(watchdog_device.soft_threshold, 256 - watchdog_device.timer_load_count_addr); 257 - 258 - /* read count value before starting timer */ 259 - ioread32(watchdog_device.timer_load_count_addr); 260 - 261 - /* Start the timer */ 262 - iowrite32(0x00000003, watchdog_device.timer_control_addr); 263 - 264 - /* read the value the time loaded into its count reg */ 265 - hw_value = ioread32(watchdog_device.timer_load_count_addr); 266 - hw_value = hw_value & 0xFFFF0000; 267 - 268 - 269 - } while (soft_value != hw_value); 270 - 271 - watchdog_device.timer_started = 1; 272 - 273 - return 0; 274 - } 275 - 276 - /* 277 - * /dev/watchdog handling 278 - */ 279 - 280 - static int intel_scu_open(struct inode *inode, struct file *file) 281 - { 282 - 283 - /* Set flag to indicate that watchdog device is open */ 284 - if (test_and_set_bit(0, &watchdog_device.driver_open)) 285 - return -EBUSY; 286 - 287 - /* Check for reopen of driver. Reopens are not allowed */ 288 - if (watchdog_device.driver_closed) 289 - return -EPERM; 290 - 291 - return stream_open(inode, file); 292 - } 293 - 294 - static int intel_scu_release(struct inode *inode, struct file *file) 295 - { 296 - /* 297 - * This watchdog should not be closed, after the timer 298 - * is started with the WDIPC_SETTIMEOUT ioctl 299 - * If force_boot is set watchdog_fire() will cause an 300 - * immediate reset. If force_boot is not set, the watchdog 301 - * timer is refreshed for one more interval. At the end 302 - * of that interval, the watchdog timer will reset the system. 303 - */ 304 - 305 - if (!test_and_clear_bit(0, &watchdog_device.driver_open)) { 306 - pr_debug("intel_scu_release, without open\n"); 307 - return -ENOTTY; 308 - } 309 - 310 - if (!watchdog_device.timer_started) { 311 - /* Just close, since timer has not been started */ 312 - pr_debug("closed, without starting timer\n"); 313 - return 0; 314 - } 315 - 316 - pr_crit("Unexpected close of /dev/watchdog!\n"); 317 - 318 - /* Since the timer was started, prevent future reopens */ 319 - watchdog_device.driver_closed = 1; 320 - 321 - /* Refresh the timer for one more interval */ 322 - intel_scu_keepalive(); 323 - 324 - /* Reboot system (if force_boot is set) */ 325 - watchdog_fire(); 326 - 327 - /* We should only reach this point if force_boot is not set */ 328 - return 0; 329 - } 330 - 331 - static ssize_t intel_scu_write(struct file *file, 332 - char const *data, 333 - size_t len, 334 - loff_t *ppos) 335 - { 336 - 337 - if (watchdog_device.timer_started) 338 - /* Watchdog already started, keep it alive */ 339 - intel_scu_keepalive(); 340 - else 341 - /* Start watchdog with timer value set by init */ 342 - intel_scu_set_heartbeat(watchdog_device.timer_set); 343 - 344 - return len; 345 - } 346 - 347 - static long intel_scu_ioctl(struct file *file, 348 - unsigned int cmd, 349 - unsigned long arg) 350 - { 351 - void __user *argp = (void __user *)arg; 352 - u32 __user *p = argp; 353 - u32 new_margin; 354 - 355 - 356 - static const struct watchdog_info ident = { 357 - .options = WDIOF_SETTIMEOUT 358 - | WDIOF_KEEPALIVEPING, 359 - .firmware_version = 0, /* @todo Get from SCU via 360 - ipc_get_scu_fw_version()? */ 361 - .identity = "Intel_SCU IOH Watchdog" /* len < 32 */ 362 - }; 363 - 364 - switch (cmd) { 365 - case WDIOC_GETSUPPORT: 366 - return copy_to_user(argp, 367 - &ident, 368 - sizeof(ident)) ? -EFAULT : 0; 369 - case WDIOC_GETSTATUS: 370 - case WDIOC_GETBOOTSTATUS: 371 - return put_user(0, p); 372 - case WDIOC_KEEPALIVE: 373 - intel_scu_keepalive(); 374 - 375 - return 0; 376 - case WDIOC_SETTIMEOUT: 377 - if (get_user(new_margin, p)) 378 - return -EFAULT; 379 - 380 - if (check_timer_margin(new_margin)) 381 - return -EINVAL; 382 - 383 - if (intel_scu_set_heartbeat(new_margin)) 384 - return -EINVAL; 385 - return 0; 386 - case WDIOC_GETTIMEOUT: 387 - return put_user(watchdog_device.soft_threshold, p); 388 - 389 - default: 390 - return -ENOTTY; 391 - } 392 - } 393 - 394 - /* 395 - * Notifier for system down 396 - */ 397 - static int intel_scu_notify_sys(struct notifier_block *this, 398 - unsigned long code, 399 - void *another_unused) 400 - { 401 - if (code == SYS_DOWN || code == SYS_HALT) 402 - /* Turn off the watchdog timer. */ 403 - intel_scu_stop(); 404 - return NOTIFY_DONE; 405 - } 406 - 407 - /* 408 - * Kernel Interfaces 409 - */ 410 - static const struct file_operations intel_scu_fops = { 411 - .owner = THIS_MODULE, 412 - .llseek = no_llseek, 413 - .write = intel_scu_write, 414 - .unlocked_ioctl = intel_scu_ioctl, 415 - .compat_ioctl = compat_ptr_ioctl, 416 - .open = intel_scu_open, 417 - .release = intel_scu_release, 418 - }; 419 - 420 - static int __init intel_scu_watchdog_init(void) 421 - { 422 - int ret; 423 - u32 __iomem *tmp_addr; 424 - 425 - /* 426 - * We don't really need to check this as the SFI timer get will fail 427 - * but if we do so we can exit with a clearer reason and no noise. 428 - * 429 - * If it isn't an intel MID device then it doesn't have this watchdog 430 - */ 431 - if (!intel_mid_identify_cpu()) 432 - return -ENODEV; 433 - 434 - /* Check boot parameters to verify that their initial values */ 435 - /* are in range. */ 436 - /* Check value of timer_set boot parameter */ 437 - if ((timer_set < MIN_TIME_CYCLE) || 438 - (timer_set > MAX_TIME - MIN_TIME_CYCLE)) { 439 - pr_err("value of timer_set %x (hex) is out of range from %x to %x (hex)\n", 440 - timer_set, MIN_TIME_CYCLE, MAX_TIME - MIN_TIME_CYCLE); 441 - return -EINVAL; 442 - } 443 - 444 - /* Check value of timer_margin boot parameter */ 445 - if (check_timer_margin(timer_margin)) 446 - return -EINVAL; 447 - 448 - watchdog_device.timer_tbl_ptr = sfi_get_mtmr(sfi_mtimer_num-1); 449 - 450 - if (watchdog_device.timer_tbl_ptr == NULL) { 451 - pr_debug("timer is not available\n"); 452 - return -ENODEV; 453 - } 454 - /* make sure the timer exists */ 455 - if (watchdog_device.timer_tbl_ptr->phys_addr == 0) { 456 - pr_debug("timer %d does not have valid physical memory\n", 457 - sfi_mtimer_num); 458 - return -ENODEV; 459 - } 460 - 461 - if (watchdog_device.timer_tbl_ptr->irq == 0) { 462 - pr_debug("timer %d invalid irq\n", sfi_mtimer_num); 463 - return -ENODEV; 464 - } 465 - 466 - tmp_addr = ioremap(watchdog_device.timer_tbl_ptr->phys_addr, 467 - 20); 468 - 469 - if (tmp_addr == NULL) { 470 - pr_debug("timer unable to ioremap\n"); 471 - return -ENOMEM; 472 - } 473 - 474 - watchdog_device.timer_load_count_addr = tmp_addr++; 475 - watchdog_device.timer_current_value_addr = tmp_addr++; 476 - watchdog_device.timer_control_addr = tmp_addr++; 477 - watchdog_device.timer_clear_interrupt_addr = tmp_addr++; 478 - watchdog_device.timer_interrupt_status_addr = tmp_addr++; 479 - 480 - /* Set the default time values in device structure */ 481 - 482 - watchdog_device.timer_set = timer_set; 483 - watchdog_device.threshold = 484 - timer_margin * watchdog_device.timer_tbl_ptr->freq_hz; 485 - watchdog_device.soft_threshold = 486 - (watchdog_device.timer_set - timer_margin) 487 - * watchdog_device.timer_tbl_ptr->freq_hz; 488 - 489 - 490 - watchdog_device.intel_scu_notifier.notifier_call = 491 - intel_scu_notify_sys; 492 - 493 - ret = register_reboot_notifier(&watchdog_device.intel_scu_notifier); 494 - if (ret) { 495 - pr_err("cannot register notifier %d)\n", ret); 496 - goto register_reboot_error; 497 - } 498 - 499 - watchdog_device.miscdev.minor = WATCHDOG_MINOR; 500 - watchdog_device.miscdev.name = "watchdog"; 501 - watchdog_device.miscdev.fops = &intel_scu_fops; 502 - 503 - ret = misc_register(&watchdog_device.miscdev); 504 - if (ret) { 505 - pr_err("cannot register miscdev %d err =%d\n", 506 - WATCHDOG_MINOR, ret); 507 - goto misc_register_error; 508 - } 509 - 510 - ret = request_irq((unsigned int)watchdog_device.timer_tbl_ptr->irq, 511 - watchdog_timer_interrupt, 512 - IRQF_SHARED, "watchdog", 513 - &watchdog_device.timer_load_count_addr); 514 - if (ret) { 515 - pr_err("error requesting irq %d\n", ret); 516 - goto request_irq_error; 517 - } 518 - /* Make sure timer is disabled before returning */ 519 - intel_scu_stop(); 520 - return 0; 521 - 522 - /* error cleanup */ 523 - 524 - request_irq_error: 525 - misc_deregister(&watchdog_device.miscdev); 526 - misc_register_error: 527 - unregister_reboot_notifier(&watchdog_device.intel_scu_notifier); 528 - register_reboot_error: 529 - intel_scu_stop(); 530 - iounmap(watchdog_device.timer_load_count_addr); 531 - return ret; 532 - } 533 - late_initcall(intel_scu_watchdog_init);
-50
drivers/watchdog/intel_scu_watchdog.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Intel_SCU 0.2: An Intel SCU IOH Based Watchdog Device 4 - * for Intel part #(s): 5 - * - AF82MP20 PCH 6 - * 7 - * Copyright (C) 2009-2010 Intel Corporation. All rights reserved. 8 - */ 9 - 10 - #ifndef __INTEL_SCU_WATCHDOG_H 11 - #define __INTEL_SCU_WATCHDOG_H 12 - 13 - #define WDT_VER "0.3" 14 - 15 - /* minimum time between interrupts */ 16 - #define MIN_TIME_CYCLE 1 17 - 18 - /* Time from warning to reboot is 2 seconds */ 19 - #define DEFAULT_SOFT_TO_HARD_MARGIN 2 20 - 21 - #define MAX_TIME 170 22 - 23 - #define DEFAULT_TIME 5 24 - 25 - #define MAX_SOFT_TO_HARD_MARGIN (MAX_TIME-MIN_TIME_CYCLE) 26 - 27 - /* Ajustment to clock tick frequency to make timing come out right */ 28 - #define FREQ_ADJUSTMENT 8 29 - 30 - struct intel_scu_watchdog_dev { 31 - ulong driver_open; 32 - ulong driver_closed; 33 - u32 timer_started; 34 - u32 timer_set; 35 - u32 threshold; 36 - u32 soft_threshold; 37 - u32 __iomem *timer_load_count_addr; 38 - u32 __iomem *timer_current_value_addr; 39 - u32 __iomem *timer_control_addr; 40 - u32 __iomem *timer_clear_interrupt_addr; 41 - u32 __iomem *timer_interrupt_status_addr; 42 - struct sfi_timer_table_entry *timer_tbl_ptr; 43 - struct notifier_block intel_scu_notifier; 44 - struct miscdevice miscdev; 45 - }; 46 - 47 - extern int sfi_mtimer_num; 48 - 49 - /* extern struct sfi_timer_table_entry *sfi_get_mtmr(int hint); */ 50 - #endif /* __INTEL_SCU_WATCHDOG_H */