1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* pmc - Driver implementation for power management functions 31da177e4SLinus Torvalds * of Power Management Controller (PMC) on SPARCstation-Voyager. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (c) 2002 Eric Brower (ebrower@usa.net) 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds #include <linux/kernel.h> 91da177e4SLinus Torvalds #include <linux/fs.h> 101da177e4SLinus Torvalds #include <linux/errno.h> 111da177e4SLinus Torvalds #include <linux/init.h> 121da177e4SLinus Torvalds #include <linux/pm.h> 13f1b6aa87SDavid S. Miller #include <linux/of.h> 14f1b6aa87SDavid S. Miller #include <linux/of_device.h> 15f060ac54SPaul Gortmaker #include <linux/module.h> 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds #include <asm/io.h> 181da177e4SLinus Torvalds #include <asm/oplib.h> 197c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 201da177e4SLinus Torvalds #include <asm/auxio.h> 21d472ba84SLen Brown #include <asm/processor.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds /* Debug 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * #define PMC_DEBUG_LED 261da177e4SLinus Torvalds * #define PMC_NO_IDLE 271da177e4SLinus Torvalds */ 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #define PMC_OBPNAME "SUNW,pmc" 301da177e4SLinus Torvalds #define PMC_DEVNAME "pmc" 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #define PMC_IDLE_REG 0x00 331da177e4SLinus Torvalds #define PMC_IDLE_ON 0x01 341da177e4SLinus Torvalds 35f1b6aa87SDavid S. Miller static u8 __iomem *regs; 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #define pmc_readb(offs) (sbus_readb(regs+offs)) 381da177e4SLinus Torvalds #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs)) 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds /* 411da177e4SLinus Torvalds * CPU idle callback function 421da177e4SLinus Torvalds * See .../arch/sparc/kernel/process.c 431da177e4SLinus Torvalds */ 4439f6649bSSam Ravnborg static void pmc_swift_idle(void) 451da177e4SLinus Torvalds { 461da177e4SLinus Torvalds #ifdef PMC_DEBUG_LED 471da177e4SLinus Torvalds set_auxio(0x00, AUXIO_LED); 481da177e4SLinus Torvalds #endif 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds pmc_writeb(pmc_readb(PMC_IDLE_REG) | PMC_IDLE_ON, PMC_IDLE_REG); 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #ifdef PMC_DEBUG_LED 531da177e4SLinus Torvalds set_auxio(AUXIO_LED, 0x00); 541da177e4SLinus Torvalds #endif 551da177e4SLinus Torvalds } 561da177e4SLinus Torvalds 577c9503b8SGreg Kroah-Hartman static int pmc_probe(struct platform_device *op) 581da177e4SLinus Torvalds { 59f1b6aa87SDavid S. Miller regs = of_ioremap(&op->resource[0], 0, 60f1b6aa87SDavid S. Miller resource_size(&op->resource[0]), PMC_OBPNAME); 611da177e4SLinus Torvalds if (!regs) { 621da177e4SLinus Torvalds printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME); 631da177e4SLinus Torvalds return -ENODEV; 641da177e4SLinus Torvalds } 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds #ifndef PMC_NO_IDLE 671da177e4SLinus Torvalds /* Assign power management IDLE handler */ 68d472ba84SLen Brown sparc_idle = pmc_swift_idle; 691da177e4SLinus Torvalds #endif 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME); 721da177e4SLinus Torvalds return 0; 731da177e4SLinus Torvalds } 741da177e4SLinus Torvalds 750cd52df8SArvind Yadav static const struct of_device_id pmc_match[] = { 76f1b6aa87SDavid S. Miller { 77f1b6aa87SDavid S. Miller .name = PMC_OBPNAME, 78f1b6aa87SDavid S. Miller }, 79f1b6aa87SDavid S. Miller {}, 80f1b6aa87SDavid S. Miller }; 81f1b6aa87SDavid S. Miller MODULE_DEVICE_TABLE(of, pmc_match); 82f1b6aa87SDavid S. Miller 834ebb24f7SGrant Likely static struct platform_driver pmc_driver = { 844018294bSGrant Likely .driver = { 85f1b6aa87SDavid S. Miller .name = "pmc", 864018294bSGrant Likely .of_match_table = pmc_match, 874018294bSGrant Likely }, 88f1b6aa87SDavid S. Miller .probe = pmc_probe, 89f1b6aa87SDavid S. Miller }; 90f1b6aa87SDavid S. Miller 91f1b6aa87SDavid S. Miller static int __init pmc_init(void) 92f1b6aa87SDavid S. Miller { 934ebb24f7SGrant Likely return platform_driver_register(&pmc_driver); 94f1b6aa87SDavid S. Miller } 95f1b6aa87SDavid S. Miller 961da177e4SLinus Torvalds /* This driver is not critical to the boot process 971da177e4SLinus Torvalds * and is easiest to ioremap when SBus is already 981da177e4SLinus Torvalds * initialized, so we install ourselves thusly: 991da177e4SLinus Torvalds */ 100f1b6aa87SDavid S. Miller __initcall(pmc_init); 101