Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / pci / pwrctrl / pci-pwrctrl-pwrseq.c
blob4e664e7b8dd23f592c0392efbf6728fc5bf9093f
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2024 Linaro Ltd.
4 */
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>
16 struct pci_pwrctrl_pwrseq_data {
17 struct pci_pwrctrl ctx;
18 struct pwrseq_desc *pwrseq;
21 struct pci_pwrctrl_pwrseq_pdata {
22 const char *target;
24 * Called before doing anything else to perform device-specific
25 * verification between requesting the power sequencing handle.
27 int (*validate_device)(struct device *dev);
30 static int pci_pwrctrl_pwrseq_qcm_wcn_validate_device(struct device *dev)
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.
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.
41 * Check the existence of the regulator supply that exists on all
42 * WCN models before moving forward.
44 if (!device_property_present(dev, "vddaon-supply"))
45 return -ENODEV;
47 return 0;
50 static const struct pci_pwrctrl_pwrseq_pdata pci_pwrctrl_pwrseq_qcom_wcn_pdata = {
51 .target = "wlan",
52 .validate_device = pci_pwrctrl_pwrseq_qcm_wcn_validate_device,
55 static void devm_pci_pwrctrl_pwrseq_power_off(void *data)
57 struct pwrseq_desc *pwrseq = data;
59 pwrseq_power_off(pwrseq);
62 static int pci_pwrctrl_pwrseq_probe(struct platform_device *pdev)
64 const struct pci_pwrctrl_pwrseq_pdata *pdata;
65 struct pci_pwrctrl_pwrseq_data *data;
66 struct device *dev = &pdev->dev;
67 int ret;
69 pdata = device_get_match_data(dev);
70 if (!pdata || !pdata->target)
71 return -EINVAL;
73 if (pdata->validate_device) {
74 ret = pdata->validate_device(dev);
75 if (ret)
76 return ret;
79 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
80 if (!data)
81 return -ENOMEM;
83 data->pwrseq = devm_pwrseq_get(dev, pdata->target);
84 if (IS_ERR(data->pwrseq))
85 return dev_err_probe(dev, PTR_ERR(data->pwrseq),
86 "Failed to get the power sequencer\n");
88 ret = pwrseq_power_on(data->pwrseq);
89 if (ret)
90 return dev_err_probe(dev, ret,
91 "Failed to power-on the device\n");
93 ret = devm_add_action_or_reset(dev, devm_pci_pwrctrl_pwrseq_power_off,
94 data->pwrseq);
95 if (ret)
96 return ret;
98 pci_pwrctrl_init(&data->ctx, dev);
100 ret = devm_pci_pwrctrl_device_set_ready(dev, &data->ctx);
101 if (ret)
102 return dev_err_probe(dev, ret,
103 "Failed to register the pwrctrl wrapper\n");
105 return 0;
108 static const struct of_device_id pci_pwrctrl_pwrseq_of_match[] = {
110 /* ATH11K in QCA6390 package. */
111 .compatible = "pci17cb,1101",
112 .data = &pci_pwrctrl_pwrseq_qcom_wcn_pdata,
115 /* ATH11K in WCN6855 package. */
116 .compatible = "pci17cb,1103",
117 .data = &pci_pwrctrl_pwrseq_qcom_wcn_pdata,
120 /* ATH12K in WCN7850 package. */
121 .compatible = "pci17cb,1107",
122 .data = &pci_pwrctrl_pwrseq_qcom_wcn_pdata,
126 MODULE_DEVICE_TABLE(of, pci_pwrctrl_pwrseq_of_match);
128 static struct platform_driver pci_pwrctrl_pwrseq_driver = {
129 .driver = {
130 .name = "pci-pwrctrl-pwrseq",
131 .of_match_table = pci_pwrctrl_pwrseq_of_match,
133 .probe = pci_pwrctrl_pwrseq_probe,
135 module_platform_driver(pci_pwrctrl_pwrseq_driver);
137 MODULE_AUTHOR("Bartosz Golaszewski <bartosz.golaszewski@linaro.org>");
138 MODULE_DESCRIPTION("Generic PCI Power Control module for power sequenced devices");
139 MODULE_LICENSE("GPL");