linux/arch/x86/platform/intel-mid/device_libs/platform_mrfld_power_btn.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * Intel Merrifield power button support
   4 *
   5 * (C) Copyright 2017 Intel Corporation
   6 *
   7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
   8 */
   9
  10#include <linux/init.h>
  11#include <linux/ioport.h>
  12#include <linux/platform_device.h>
  13#include <linux/sfi.h>
  14
  15#include <asm/intel-mid.h>
  16#include <asm/intel_scu_ipc.h>
  17
  18static struct resource mrfld_power_btn_resources[] = {
  19        {
  20                .flags          = IORESOURCE_IRQ,
  21        },
  22};
  23
  24static struct platform_device mrfld_power_btn_dev = {
  25        .name           = "msic_power_btn",
  26        .id             = PLATFORM_DEVID_NONE,
  27        .num_resources  = ARRAY_SIZE(mrfld_power_btn_resources),
  28        .resource       = mrfld_power_btn_resources,
  29};
  30
  31static int mrfld_power_btn_scu_status_change(struct notifier_block *nb,
  32                                             unsigned long code, void *data)
  33{
  34        if (code == SCU_DOWN) {
  35                platform_device_unregister(&mrfld_power_btn_dev);
  36                return 0;
  37        }
  38
  39        return platform_device_register(&mrfld_power_btn_dev);
  40}
  41
  42static struct notifier_block mrfld_power_btn_scu_notifier = {
  43        .notifier_call  = mrfld_power_btn_scu_status_change,
  44};
  45
  46static int __init register_mrfld_power_btn(void)
  47{
  48        if (intel_mid_identify_cpu() != INTEL_MID_CPU_CHIP_TANGIER)
  49                return -ENODEV;
  50
  51        /*
  52         * We need to be sure that the SCU IPC is ready before
  53         * PMIC power button device can be registered:
  54         */
  55        intel_scu_notifier_add(&mrfld_power_btn_scu_notifier);
  56
  57        return 0;
  58}
  59arch_initcall(register_mrfld_power_btn);
  60
  61static void __init *mrfld_power_btn_platform_data(void *info)
  62{
  63        struct resource *res = mrfld_power_btn_resources;
  64        struct sfi_device_table_entry *pentry = info;
  65
  66        res->start = res->end = pentry->irq;
  67        return NULL;
  68}
  69
  70static const struct devs_id mrfld_power_btn_dev_id __initconst = {
  71        .name                   = "bcove_power_btn",
  72        .type                   = SFI_DEV_TYPE_IPC,
  73        .delay                  = 1,
  74        .msic                   = 1,
  75        .get_platform_data      = &mrfld_power_btn_platform_data,
  76};
  77
  78sfi_device(mrfld_power_btn_dev_id);
  79