| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* Copyright (C) 2024 Linaro Ltd. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <linux/device.h> |
| 7 |
#include <linux/mod_devicetable.h> |
| 8 |
#include <linux/module.h> |
| 9 |
#include <linux/pci-pwrctrl.h> |
| 10 |
#include <linux/platform_device.h> |
| 11 |
#include <linux/property.h> |
| 12 |
#include <linux/pwrseq/consumer.h> |
| 13 |
#include <linux/slab.h> |
| 14 |
#include <linux/types.h> |
| 15 |
|
| 16 |
struct pwrseq_pwrctrl { |
| 17 |
struct pci_pwrctrl pwrctrl; |
| 18 |
struct pwrseq_desc *pwrseq; |
| 19 |
}; |
| 20 |
|
| 21 |
struct pwrseq_pwrctrl_pdata { |
| 22 |
const char *target; |
| 23 |
/* |
| 24 |
* Called before doing anything else to perform device-specific |
| 25 |
* verification between requesting the power sequencing handle. |
| 26 |
*/ |
| 27 |
int (*validate_device)(struct device *dev); |
| 28 |
}; |
| 29 |
|
| 30 |
static int pwrseq_pwrctrl_qcm_wcn_validate_device(struct device *dev) |
| 31 |
{ |
| 32 |
/* |
| 33 |
* Old device trees for some platforms already define wifi nodes for |
| 34 |
* the WCN family of chips since before power sequencing was added |
| 35 |
* upstream. |
| 36 |
* |
| 37 |
* These nodes don't consume the regulator outputs from the PMU, and |
| 38 |
* if we allow this driver to bind to one of such "incomplete" nodes, |
| 39 |
* we'll see a kernel log error about the indefinite probe deferral. |
| 40 |
* |
| 41 |
* Check the existence of the regulator supply that exists on all |
| 42 |
* WCN models before moving forward. |
| 43 |
*/ |
| 44 |
if (!device_property_present(dev, "vddaon-supply")) |
| 45 |
return -ENODEV; |
| 46 |
|
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
static const struct pwrseq_pwrctrl_pdata pwrseq_pwrctrl_qcom_wcn_pdata = { |
| 51 |
.target = "wlan", |
| 52 |
.validate_device = pwrseq_pwrctrl_qcm_wcn_validate_device, |
| 53 |
}; |
| 54 |
|
| 55 |
static int pwrseq_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl) |
| 56 |
{ |
| 57 |
struct pwrseq_pwrctrl *pwrseq = container_of(pwrctrl, |
| 58 |
struct pwrseq_pwrctrl, pwrctrl); |
| 59 |
|
| 60 |
return pwrseq_power_on(pwrseq->pwrseq); |
| 61 |
} |
| 62 |
|
| 63 |
static int pwrseq_pwrctrl_power_off(struct pci_pwrctrl *pwrctrl) |
| 64 |
{ |
| 65 |
struct pwrseq_pwrctrl *pwrseq = container_of(pwrctrl, |
| 66 |
struct pwrseq_pwrctrl, pwrctrl); |
| 67 |
|
| 68 |
return pwrseq_power_off(pwrseq->pwrseq); |
| 69 |
} |
| 70 |
|
| 71 |
static int pwrseq_pwrctrl_probe(struct platform_device *pdev) |
| 72 |
{ |
| 73 |
const struct pwrseq_pwrctrl_pdata *pdata; |
| 74 |
struct pwrseq_pwrctrl *pwrseq; |
| 75 |
struct device *dev = &pdev->dev; |
| 76 |
int ret; |
| 77 |
|
| 78 |
pdata = device_get_match_data(dev); |
| 79 |
if (!pdata || !pdata->target) |
| 80 |
return -EINVAL; |
| 81 |
|
| 82 |
if (pdata->validate_device) { |
| 83 |
ret = pdata->validate_device(dev); |
| 84 |
if (ret) |
| 85 |
return ret; |
| 86 |
} |
| 87 |
|
| 88 |
pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); |
| 89 |
if (!pwrseq) |
| 90 |
return -ENOMEM; |
| 91 |
|
| 92 |
pwrseq->pwrseq = devm_pwrseq_get(dev, pdata->target); |
| 93 |
if (IS_ERR(pwrseq->pwrseq)) |
| 94 |
return dev_err_probe(dev, PTR_ERR(pwrseq->pwrseq), |
| 95 |
"Failed to get the power sequencer\n"); |
| 96 |
|
| 97 |
pwrseq->pwrctrl.power_on = pwrseq_pwrctrl_power_on; |
| 98 |
pwrseq->pwrctrl.power_off = pwrseq_pwrctrl_power_off; |
| 99 |
|
| 100 |
pci_pwrctrl_init(&pwrseq->pwrctrl, dev); |
| 101 |
|
| 102 |
ret = devm_pci_pwrctrl_device_set_ready(dev, &pwrseq->pwrctrl); |
| 103 |
if (ret) |
| 104 |
return dev_err_probe(dev, ret, |
| 105 |
"Failed to register the pwrctrl wrapper\n"); |
| 106 |
|
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
static const struct of_device_id pwrseq_pwrctrl_of_match[] = { |
| 111 |
{ |
| 112 |
/* ATH11K in QCA6390 package. */ |
| 113 |
.compatible = "pci17cb,1101", |
| 114 |
.data = &pwrseq_pwrctrl_qcom_wcn_pdata, |
| 115 |
}, |
| 116 |
{ |
| 117 |
/* ATH11K in WCN6855 package. */ |
| 118 |
.compatible = "pci17cb,1103", |
| 119 |
.data = &pwrseq_pwrctrl_qcom_wcn_pdata, |
| 120 |
}, |
| 121 |
{ |
| 122 |
/* ATH12K in WCN7850 package. */ |
| 123 |
.compatible = "pci17cb,1107", |
| 124 |
.data = &pwrseq_pwrctrl_qcom_wcn_pdata, |
| 125 |
}, |
| 126 |
{ } |
| 127 |
}; |
| 128 |
MODULE_DEVICE_TABLE(of, pwrseq_pwrctrl_of_match); |
| 129 |
|
| 130 |
static struct platform_driver pwrseq_pwrctrl_driver = { |
| 131 |
.driver = { |
| 132 |
.name = "pci-pwrctrl-pwrseq", |
| 133 |
.of_match_table = pwrseq_pwrctrl_of_match, |
| 134 |
}, |
| 135 |
.probe = pwrseq_pwrctrl_probe, |
| 136 |
}; |
| 137 |
module_platform_driver(pwrseq_pwrctrl_driver); |
| 138 |
|
| 139 |
MODULE_AUTHOR("Bartosz Golaszewski <[email protected]>"); |
| 140 |
MODULE_DESCRIPTION("Generic PCI Power Control module for power sequenced devices"); |
| 141 |
MODULE_LICENSE("GPL"); |