Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3290693imd; Mon, 29 Oct 2018 05:01:41 -0700 (PDT) X-Google-Smtp-Source: AJdET5diIctvHPfrIAbAkRoZKdVyi1QhaSSIGGTX5JUaBvqNiF8BnRBfJ/mBWTk8IUyn8mlE/kQ2 X-Received: by 2002:a17:902:3fe4:: with SMTP id a91-v6mr13880216pld.295.1540814501430; Mon, 29 Oct 2018 05:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540814501; cv=none; d=google.com; s=arc-20160816; b=McWdaG0vzcYDp0Tr21wn1cDye/LCR2ckFtFGaTBNAzWjPsbIJb4ApMmPIdHvItiKWT i2bqb3IUljYS1lgkwiQMFP6iTzQJSJSLOhj2uOvmh368OtZbwdLw9UzWEEw7F1r4JiQz Pv5XmvfhbxGFu72YjuNblX/YAccsC7kn7Hb5zGJaueNHr/i6NjQZNAtv/HfLmHCSSpZ9 BWpG9hWjCUkJg80t+dr6e324IyAmmMfiwObULcUHCQscdnwBuZjD4d1FWn97SkmztglR Oqld5/bVMDp+QbGRrU2G2oq5A/eDDbVHJqCOasuPipq5ZKaQvWH9iOhBmyAXQa5BL2qi KztQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=O2AWIyc7DTaDMorh/hy5SO8y5UGlpcdfK6ps5HwhpSo=; b=0hT0gZw9UkWh8jaR02mMWjBf8HLgBUCHFHpgMSuZeZYuXvwKHmwtIMokANy/UWjAub wouCXIGv/iUZi1EmxkTO2014S/x7g9U+vbN/676a2bJlWG/sZW/f1z50Sp0ySYzR16ze uYg2spclUwT/r+OpyhXIULnaC4qvyWsNnL7yqR4a2Hss/q7FheHbN7h28Y1fMR1eZ/Hm DChJT+BdRwbJjz9lz6P7iOL0HIfVuEdPfMsio4TTmMAZouh6YM57CoCqsSvvGnLBobJo sApMx2uGBPhLh05T5NgGAISMaDNRZaWmP09GByzeY+wGvLxebaWZPWu+Kk5nno3tJj1q AV/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mAa0OUJ1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e127-v6si21774263pfe.8.2018.10.29.05.01.22; Mon, 29 Oct 2018 05:01:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mAa0OUJ1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729170AbeJ2Usi (ORCPT + 99 others); Mon, 29 Oct 2018 16:48:38 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:40090 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729095AbeJ2Ush (ORCPT ); Mon, 29 Oct 2018 16:48:37 -0400 Received: by mail-qt1-f196.google.com with SMTP id k12so2906135qtf.7; Mon, 29 Oct 2018 05:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O2AWIyc7DTaDMorh/hy5SO8y5UGlpcdfK6ps5HwhpSo=; b=mAa0OUJ1y5Dg3locSgocNN/6XAYRE1A726oR3uhWkoeHvm55B2xvtRmIXqAKO14oIf GoxGQTn+ePBBXM4MVwTWBD5O4FbEot1xKeOZrYojJbyEIlGFmeKBe4yTCSTLYw5j18rV dK9ceMI0/3YswHYfQNK4lNYfdHAuW8LmiFIqP5r8XPWFcnGzOhAjPx2p4yyxMgxEB/YS BuzhcHAC4uXHub4q7WENrIjnoSjjwrkwOOhM2PV3em3NAJBSa3GKo49C6hCRdLE9h/VP OtgO0KFKL6aKOH9TQqE50Lr7Tub/b9UdgeYxf/8u1jcynzeEIsXHSq8c2MKs+vbv4ouw a/xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O2AWIyc7DTaDMorh/hy5SO8y5UGlpcdfK6ps5HwhpSo=; b=nbDRPt5SkWhOkg90mangQLXYUmU+ofm3HuBP6OTUs6rEvs8RgFYmYTbwKXZuGkTF34 yzmRdDemnzRYOhlQRFSmABHUMzQhsxBgy0A5ceAZVqomx9xTsDLyEY6EPFxUvc3cr8Vm frIl6qMn4KnfQ2H78rrh0xxevpr5oJKb3erCivMH2ficB3uVqFlqbsj/cit09tNRJQ2m 29gMIzNPaT5q54Tk1YfUvxUg7ZHmDzRbzhGuparcVL4E6O0/pr5NmK7elz3+kr0L43nS vIZlXyzuQLzEaDTtsBAA7wHdJOOBvo8MR3Um7ytoF5lcSj0hSnmhLBYVE1RStzIzSooU twxA== X-Gm-Message-State: AGRZ1gICZfirh2+gRmkXz+vx+qi4qghVwYSjFW0bYddjMaLXon/5AsLw /QFr9YP+e3j9xRhRPQLfw6+MzGxkRolja+jHVsE= X-Received: by 2002:ac8:191a:: with SMTP id t26-v6mr11977000qtj.327.1540814414866; Mon, 29 Oct 2018 05:00:14 -0700 (PDT) MIME-Version: 1.0 References: <20181014175427.22139-1-hdegoede@redhat.com> In-Reply-To: <20181014175427.22139-1-hdegoede@redhat.com> From: Andy Shevchenko Date: Mon, 29 Oct 2018 14:00:03 +0200 Message-ID: Subject: Re: [PATCH v2] platform/x86: Add Intel AtomISP2 dummy / power-management driver To: Hans de Goede Cc: Darren Hart , Andy Shevchenko , Platform Driver , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 14, 2018 at 8:54 PM Hans de Goede wrote: > > The Image Signal Processor found on Cherry Trail devices is brought up in > D0 state on devices which have camera sensors attached to it. The ISP will > not enter D3 state again without some massaging of its registers beforehand > and the ISP not being in D3 state blocks the SoC from entering S0ix modes. > > There was a driver for the ISP in drivers/staging but that got removed > again because it never worked. It does not seem likely that a real > driver for the ISP will be added to the mainline kernel anytime soon. > > This commit adds a dummy driver which contains the necessary magic from > the staging driver to powerdown the ISP, so that Cherry Trail devices where > the ISP is used will properly use S0ix modes when suspended. > > Together with other recent S0ix related fixes this allows S0ix modes to > be entered on e.g. a Chuwi Hi8 Pro and a HP x2 210. > There are might be slight improvements, but in general it's okay. Applied, thanks! P.S. It's possible we need to add Merrifield ID there, I will do it myself along with cosmetic changes as a separate patches later on. > BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=196915 > Signed-off-by: Hans de Goede > --- > Changes in v2: > -Rename the driver and Kconfig option from intel-isp-dummy to intel-atomisp2-pm > --- > MAINTAINERS | 6 ++ > drivers/platform/x86/Kconfig | 12 +++ > drivers/platform/x86/Makefile | 1 + > drivers/platform/x86/intel_atomisp2_pm.c | 119 +++++++++++++++++++++++ > 4 files changed, 138 insertions(+) > create mode 100644 drivers/platform/x86/intel_atomisp2_pm.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index 2c5d5c6859b8..ba9e5da792ea 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -7306,6 +7306,12 @@ L: alsa-devel@alsa-project.org (moderated for non-subscribers) > S: Supported > F: sound/soc/intel/ > > +INTEL ATOMISP2 DUMMY / POWER-MANAGEMENT DRIVER > +M: Hans de Goede > +L: platform-driver-x86@vger.kernel.org > +S: Maintained > +F: drivers/platform/x86/intel_atomisp2_pm.c > + > INTEL C600 SERIES SAS CONTROLLER DRIVER > M: Intel SCU Linux support > M: Artur Paszkiewicz > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig > index 48bec711e5e3..5eedcec0fefe 100644 > --- a/drivers/platform/x86/Kconfig > +++ b/drivers/platform/x86/Kconfig > @@ -1232,6 +1232,18 @@ config I2C_MULTI_INSTANTIATE > To compile this driver as a module, choose M here: the module > will be called i2c-multi-instantiate. > > +config INTEL_ATOMISP2_PM > + tristate "Intel AtomISP2 dummy / power-management driver" > + depends on PCI && IOSF_MBI && PM > + help > + Power-management driver for Intel's Image Signal Processor found on > + Bay and Cherry Trail devices. This dummy driver's sole purpose is to > + turn the ISP off (put it in D3) to save power and to allow entering > + of S0ix modes. > + > + To compile this driver as a module, choose M here: the module > + will be called intel_atomisp2_pm. > + > endif # X86_PLATFORM_DEVICES > > config PMC_ATOM > diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile > index e6d1becf81ce..dc29af4d8e2f 100644 > --- a/drivers/platform/x86/Makefile > +++ b/drivers/platform/x86/Makefile > @@ -92,3 +92,4 @@ obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o > obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o > obj-$(CONFIG_INTEL_CHTDC_TI_PWRBTN) += intel_chtdc_ti_pwrbtn.o > obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o > +obj-$(CONFIG_INTEL_ATOMISP2_PM) += intel_atomisp2_pm.o > diff --git a/drivers/platform/x86/intel_atomisp2_pm.c b/drivers/platform/x86/intel_atomisp2_pm.c > new file mode 100644 > index 000000000000..9371603a0ac9 > --- /dev/null > +++ b/drivers/platform/x86/intel_atomisp2_pm.c > @@ -0,0 +1,119 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Dummy driver for Intel's Image Signal Processor found on Bay and Cherry > + * Trail devices. The sole purpose of this driver is to allow the ISP to > + * be put in D3. > + * > + * Copyright (C) 2018 Hans de Goede > + * > + * Based on various non upstream patches for ISP support: > + * Copyright (C) 2010-2017 Intel Corporation. All rights reserved. > + * Copyright (c) 2010 Silicon Hive www.siliconhive.com. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* PCI configuration regs */ > +#define PCI_INTERRUPT_CTRL 0x9c > + > +#define PCI_CSI_CONTROL 0xe8 > +#define PCI_CSI_CONTROL_PORTS_OFF_MASK 0x7 > + > +/* IOSF BT_MBI_UNIT_PMC regs */ > +#define ISPSSPM0 0x39 > +#define ISPSSPM0_ISPSSC_OFFSET 0 > +#define ISPSSPM0_ISPSSC_MASK 0x00000003 > +#define ISPSSPM0_ISPSSS_OFFSET 24 > +#define ISPSSPM0_ISPSSS_MASK 0x03000000 > +#define ISPSSPM0_IUNIT_POWER_ON 0x0 > +#define ISPSSPM0_IUNIT_POWER_OFF 0x3 > + > +static int isp_probe(struct pci_dev *dev, const struct pci_device_id *id) > +{ > + unsigned long timeout; > + u32 val; > + > + pci_write_config_dword(dev, PCI_INTERRUPT_CTRL, 0); > + > + /* > + * MRFLD IUNIT DPHY is located in an always-power-on island > + * MRFLD HW design need all CSI ports are disabled before > + * powering down the IUNIT. > + */ > + pci_read_config_dword(dev, PCI_CSI_CONTROL, &val); > + val |= PCI_CSI_CONTROL_PORTS_OFF_MASK; > + pci_write_config_dword(dev, PCI_CSI_CONTROL, val); > + > + /* Write 0x3 to ISPSSPM0 bit[1:0] to power off the IUNIT */ > + iosf_mbi_modify(BT_MBI_UNIT_PMC, MBI_REG_READ, ISPSSPM0, > + ISPSSPM0_IUNIT_POWER_OFF, ISPSSPM0_ISPSSC_MASK); > + > + /* > + * There should be no IUNIT access while power-down is > + * in progress HW sighting: 4567865 > + * Wait up to 50 ms for the IUNIT to shut down. > + */ > + timeout = jiffies + msecs_to_jiffies(50); > + while (1) { > + /* Wait until ISPSSPM0 bit[25:24] shows 0x3 */ > + iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, ISPSSPM0, &val); > + val = (val & ISPSSPM0_ISPSSS_MASK) >> ISPSSPM0_ISPSSS_OFFSET; > + if (val == ISPSSPM0_IUNIT_POWER_OFF) > + break; > + > + if (time_after(jiffies, timeout)) { > + dev_err(&dev->dev, "IUNIT power-off timeout.\n"); > + return -EBUSY; > + } > + usleep_range(1000, 2000); > + } > + > + pm_runtime_allow(&dev->dev); > + pm_runtime_put_sync_suspend(&dev->dev); > + > + return 0; > +} > + > +static void isp_remove(struct pci_dev *dev) > +{ > + pm_runtime_get_sync(&dev->dev); > + pm_runtime_forbid(&dev->dev); > +} > + > +static int isp_pci_suspend(struct device *dev) > +{ > + return 0; > +} > + > +static int isp_pci_resume(struct device *dev) > +{ > + return 0; > +} > + > +static UNIVERSAL_DEV_PM_OPS(isp_pm_ops, isp_pci_suspend, > + isp_pci_resume, NULL); > + > +static const struct pci_device_id isp_id_table[] = { > + { PCI_VDEVICE(INTEL, 0x22b8), }, > + { 0, } > +}; > +MODULE_DEVICE_TABLE(pci, isp_id_table); > + > +static struct pci_driver isp_pci_driver = { > + .name = "intel_atomisp2_pm", > + .id_table = isp_id_table, > + .probe = isp_probe, > + .remove = isp_remove, > + .driver.pm = &isp_pm_ops, > +}; > + > +module_pci_driver(isp_pci_driver); > + > +MODULE_DESCRIPTION("Intel AtomISP2 dummy / power-management drv (for suspend)"); > +MODULE_AUTHOR("Hans de Goede "); > +MODULE_LICENSE("GPL v2"); > -- > 2.19.0 > -- With Best Regards, Andy Shevchenko