Skip to content

Commit 7eb275f

Browse files
author
Jiri Kosina
committed
Merge branch 'for-5.12/intel-ish' into for-linus
- power management improvements for intel-ish driver from Zhang Lixu
2 parents 27b730e + 2f4ec15 commit 7eb275f

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

drivers/hid/intel-ish-hid/ipc/hw-ish.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev);
8282
int ish_hw_start(struct ishtp_device *dev);
8383
void ish_device_disable(struct ishtp_device *dev);
8484
int ish_disable_dma(struct ishtp_device *dev);
85+
void ish_set_host_ready(struct ishtp_device *dev);
8586

8687
#endif /* _ISHTP_HW_ISH_H_ */

drivers/hid/intel-ish-hid/ipc/ipc.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,33 @@ static void ish_clr_host_rdy(struct ishtp_device *dev)
193193
ish_reg_write(dev, IPC_REG_HOST_COMM, host_status);
194194
}
195195

196+
static bool ish_chk_host_rdy(struct ishtp_device *dev)
197+
{
198+
uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM);
199+
200+
return (host_status & IPC_HOSTCOMM_READY_BIT);
201+
}
202+
203+
/**
204+
* ish_set_host_ready() - reconfig ipc host registers
205+
* @dev: ishtp device pointer
206+
*
207+
* Set host to ready state
208+
* This API is called in some case:
209+
* fw is still on, but ipc is powered down.
210+
* such as OOB case.
211+
*
212+
* Return: 0 for success else error fault code
213+
*/
214+
void ish_set_host_ready(struct ishtp_device *dev)
215+
{
216+
if (ish_chk_host_rdy(dev))
217+
return;
218+
219+
ish_set_host_rdy(dev);
220+
set_host_ready(dev);
221+
}
222+
196223
/**
197224
* _ishtp_read_hdr() - Read message header
198225
* @dev: ISHTP device pointer

drivers/hid/intel-ish-hid/ipc/pci-ish.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright (c) 2014-2016, Intel Corporation.
66
*/
77

8+
#include <linux/acpi.h>
89
#include <linux/module.h>
910
#include <linux/moduleparam.h>
1011
#include <linux/kernel.h>
@@ -112,6 +113,42 @@ static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
112113
return !pm_resume_via_firmware() || pdev->device == CHV_DEVICE_ID;
113114
}
114115

116+
static int enable_gpe(struct device *dev)
117+
{
118+
#ifdef CONFIG_ACPI
119+
acpi_status acpi_sts;
120+
struct acpi_device *adev;
121+
struct acpi_device_wakeup *wakeup;
122+
123+
adev = ACPI_COMPANION(dev);
124+
if (!adev) {
125+
dev_err(dev, "get acpi handle failed\n");
126+
return -ENODEV;
127+
}
128+
wakeup = &adev->wakeup;
129+
130+
acpi_sts = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number);
131+
if (ACPI_FAILURE(acpi_sts)) {
132+
dev_err(dev, "enable ose_gpe failed\n");
133+
return -EIO;
134+
}
135+
136+
return 0;
137+
#else
138+
return -ENODEV;
139+
#endif
140+
}
141+
142+
static void enable_pme_wake(struct pci_dev *pdev)
143+
{
144+
if ((pci_pme_capable(pdev, PCI_D0) ||
145+
pci_pme_capable(pdev, PCI_D3hot) ||
146+
pci_pme_capable(pdev, PCI_D3cold)) && !enable_gpe(&pdev->dev)) {
147+
pci_pme_active(pdev, true);
148+
dev_dbg(&pdev->dev, "ish ipc driver pme wake enabled\n");
149+
}
150+
}
151+
115152
/**
116153
* ish_probe() - PCI driver probe callback
117154
* @pdev: pci device
@@ -180,6 +217,10 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
180217
init_waitqueue_head(&ishtp->suspend_wait);
181218
init_waitqueue_head(&ishtp->resume_wait);
182219

220+
/* Enable PME for EHL */
221+
if (pdev->device == EHL_Ax_DEVICE_ID)
222+
enable_pme_wake(pdev);
223+
183224
ret = ish_init(ishtp);
184225
if (ret)
185226
return ret;
@@ -219,11 +260,15 @@ static void __maybe_unused ish_resume_handler(struct work_struct *work)
219260
{
220261
struct pci_dev *pdev = to_pci_dev(ish_resume_device);
221262
struct ishtp_device *dev = pci_get_drvdata(pdev);
263+
uint32_t fwsts = dev->ops->get_fw_status(dev);
222264
int ret;
223265

224-
if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
266+
if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag
267+
&& IPC_IS_ISH_ILUP(fwsts)) {
225268
disable_irq_wake(pdev->irq);
226269

270+
ish_set_host_ready(dev);
271+
227272
ishtp_send_resume(dev);
228273

229274
/* Waiting to get resume response */
@@ -318,6 +363,13 @@ static int __maybe_unused ish_resume(struct device *device)
318363
struct pci_dev *pdev = to_pci_dev(device);
319364
struct ishtp_device *dev = pci_get_drvdata(pdev);
320365

366+
/* add this to finish power flow for EHL */
367+
if (dev->pdev->device == EHL_Ax_DEVICE_ID) {
368+
pci_set_power_state(pdev, PCI_D0);
369+
enable_pme_wake(pdev);
370+
dev_dbg(dev->devc, "set power state to D0 for ehl\n");
371+
}
372+
321373
ish_resume_device = device;
322374
dev->resume_flag = 1;
323375

0 commit comments

Comments
 (0)