~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/qcom/qdsp6/q6prm.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/qcom/qdsp6/q6prm.c (Version linux-6.11.5) and /sound/soc/qcom/qdsp6/q6prm.c (Version linux-6.4.16)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 // Copyright (c) 2021, Linaro Limited               2 // Copyright (c) 2021, Linaro Limited
  3                                                     3 
  4 #include <linux/slab.h>                             4 #include <linux/slab.h>
  5 #include <linux/wait.h>                             5 #include <linux/wait.h>
  6 #include <linux/kernel.h>                           6 #include <linux/kernel.h>
  7 #include <linux/module.h>                           7 #include <linux/module.h>
  8 #include <linux/of.h>                               8 #include <linux/of.h>
  9 #include <linux/delay.h>                            9 #include <linux/delay.h>
 10 #include <linux/of_platform.h>                     10 #include <linux/of_platform.h>
 11 #include <linux/jiffies.h>                         11 #include <linux/jiffies.h>
 12 #include <linux/soc/qcom/apr.h>                    12 #include <linux/soc/qcom/apr.h>
 13 #include <dt-bindings/soc/qcom,gpr.h>              13 #include <dt-bindings/soc/qcom,gpr.h>
 14 #include <dt-bindings/sound/qcom,q6dsp-lpass-p     14 #include <dt-bindings/sound/qcom,q6dsp-lpass-ports.h>
 15 #include "q6apm.h"                                 15 #include "q6apm.h"
 16 #include "q6prm.h"                                 16 #include "q6prm.h"
 17 #include "audioreach.h"                            17 #include "audioreach.h"
 18                                                    18 
 19 struct q6prm {                                     19 struct q6prm {
 20         struct device *dev;                        20         struct device *dev;
 21         gpr_device_t *gdev;                        21         gpr_device_t *gdev;
 22         wait_queue_head_t wait;                    22         wait_queue_head_t wait;
 23         struct gpr_ibasic_rsp_result_t result;     23         struct gpr_ibasic_rsp_result_t result;
 24         struct mutex lock;                         24         struct mutex lock;
 25 };                                                 25 };
 26                                                    26 
 27 #define PRM_CMD_REQUEST_HW_RSC          0x0100     27 #define PRM_CMD_REQUEST_HW_RSC          0x0100100F
 28 #define PRM_CMD_RSP_REQUEST_HW_RSC      0x0200     28 #define PRM_CMD_RSP_REQUEST_HW_RSC      0x02001002
 29 #define PRM_CMD_RELEASE_HW_RSC          0x0100     29 #define PRM_CMD_RELEASE_HW_RSC          0x01001010
 30 #define PRM_CMD_RSP_RELEASE_HW_RSC      0x0200     30 #define PRM_CMD_RSP_RELEASE_HW_RSC      0x02001003
 31 #define PARAM_ID_RSC_HW_CORE            0x0800     31 #define PARAM_ID_RSC_HW_CORE            0x08001032
 32 #define PARAM_ID_RSC_LPASS_CORE         0x0800     32 #define PARAM_ID_RSC_LPASS_CORE         0x0800102B
 33 #define PARAM_ID_RSC_AUDIO_HW_CLK       0x0800     33 #define PARAM_ID_RSC_AUDIO_HW_CLK       0x0800102C
 34                                                    34 
 35 struct prm_cmd_request_hw_core {                   35 struct prm_cmd_request_hw_core {
 36         struct apm_module_param_data param_dat     36         struct apm_module_param_data param_data;
 37         uint32_t hw_clk_id;                        37         uint32_t hw_clk_id;
 38 } __packed;                                        38 } __packed;
 39                                                    39 
 40 struct prm_cmd_request_rsc {                       40 struct prm_cmd_request_rsc {
 41         struct apm_module_param_data param_dat     41         struct apm_module_param_data param_data;
 42         uint32_t num_clk_id;                       42         uint32_t num_clk_id;
 43         struct audio_hw_clk_cfg clock_id;          43         struct audio_hw_clk_cfg clock_id;
 44 } __packed;                                        44 } __packed;
 45                                                    45 
 46 struct prm_cmd_release_rsc {                       46 struct prm_cmd_release_rsc {
 47         struct apm_module_param_data param_dat     47         struct apm_module_param_data param_data;
 48         uint32_t num_clk_id;                       48         uint32_t num_clk_id;
 49         struct audio_hw_clk_rel_cfg clock_id;      49         struct audio_hw_clk_rel_cfg clock_id;
 50 } __packed;                                        50 } __packed;
 51                                                    51 
 52 static int q6prm_send_cmd_sync(struct q6prm *p     52 static int q6prm_send_cmd_sync(struct q6prm *prm, struct gpr_pkt *pkt, uint32_t rsp_opcode)
 53 {                                                  53 {
 54         return audioreach_send_cmd_sync(prm->d     54         return audioreach_send_cmd_sync(prm->dev, prm->gdev, &prm->result, &prm->lock,
 55                                         NULL,      55                                         NULL, &prm->wait, pkt, rsp_opcode);
 56 }                                                  56 }
 57                                                    57 
 58 static int q6prm_set_hw_core_req(struct device     58 static int q6prm_set_hw_core_req(struct device *dev, uint32_t hw_block_id, bool enable)
 59 {                                                  59 {
 60         struct q6prm *prm = dev_get_drvdata(de     60         struct q6prm *prm = dev_get_drvdata(dev->parent);
 61         struct apm_module_param_data *param_da     61         struct apm_module_param_data *param_data;
 62         struct prm_cmd_request_hw_core *req;       62         struct prm_cmd_request_hw_core *req;
 63         gpr_device_t *gdev = prm->gdev;            63         gpr_device_t *gdev = prm->gdev;
 64         uint32_t opcode, rsp_opcode;               64         uint32_t opcode, rsp_opcode;
 65         struct gpr_pkt *pkt;                       65         struct gpr_pkt *pkt;
 66         int rc;                                    66         int rc;
 67                                                    67 
 68         if (enable) {                              68         if (enable) {
 69                 opcode = PRM_CMD_REQUEST_HW_RS     69                 opcode = PRM_CMD_REQUEST_HW_RSC;
 70                 rsp_opcode = PRM_CMD_RSP_REQUE     70                 rsp_opcode = PRM_CMD_RSP_REQUEST_HW_RSC;
 71         } else {                                   71         } else {
 72                 opcode = PRM_CMD_RELEASE_HW_RS     72                 opcode = PRM_CMD_RELEASE_HW_RSC;
 73                 rsp_opcode = PRM_CMD_RSP_RELEA     73                 rsp_opcode = PRM_CMD_RSP_RELEASE_HW_RSC;
 74         }                                          74         }
 75                                                    75 
 76         pkt = audioreach_alloc_cmd_pkt(sizeof(     76         pkt = audioreach_alloc_cmd_pkt(sizeof(*req), opcode, 0, gdev->svc.id, GPR_PRM_MODULE_IID);
 77         if (IS_ERR(pkt))                           77         if (IS_ERR(pkt))
 78                 return PTR_ERR(pkt);               78                 return PTR_ERR(pkt);
 79                                                    79 
 80         req = (void *)pkt + GPR_HDR_SIZE + APM     80         req = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
 81                                                    81 
 82         param_data = &req->param_data;             82         param_data = &req->param_data;
 83                                                    83 
 84         param_data->module_instance_id = GPR_P     84         param_data->module_instance_id = GPR_PRM_MODULE_IID;
 85         param_data->error_code = 0;                85         param_data->error_code = 0;
 86         param_data->param_id = PARAM_ID_RSC_HW     86         param_data->param_id = PARAM_ID_RSC_HW_CORE;
 87         param_data->param_size = sizeof(*req)      87         param_data->param_size = sizeof(*req) - APM_MODULE_PARAM_DATA_SIZE;
 88                                                    88 
 89         req->hw_clk_id = hw_block_id;              89         req->hw_clk_id = hw_block_id;
 90                                                    90 
 91         rc = q6prm_send_cmd_sync(prm, pkt, rsp     91         rc = q6prm_send_cmd_sync(prm, pkt, rsp_opcode);
 92                                                    92 
 93         kfree(pkt);                                93         kfree(pkt);
 94                                                    94 
 95         return rc;                                 95         return rc;
 96 }                                                  96 }
 97                                                    97 
 98 int q6prm_vote_lpass_core_hw(struct device *de     98 int q6prm_vote_lpass_core_hw(struct device *dev, uint32_t hw_block_id,
 99                              const char *clien     99                              const char *client_name, uint32_t *client_handle)
100 {                                                 100 {
101         return q6prm_set_hw_core_req(dev, hw_b    101         return q6prm_set_hw_core_req(dev, hw_block_id, true);
102                                                   102 
103 }                                                 103 }
104 EXPORT_SYMBOL_GPL(q6prm_vote_lpass_core_hw);      104 EXPORT_SYMBOL_GPL(q6prm_vote_lpass_core_hw);
105                                                   105 
106 int q6prm_unvote_lpass_core_hw(struct device *    106 int q6prm_unvote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, uint32_t client_handle)
107 {                                                 107 {
108         return q6prm_set_hw_core_req(dev, hw_b    108         return q6prm_set_hw_core_req(dev, hw_block_id, false);
109 }                                                 109 }
110 EXPORT_SYMBOL_GPL(q6prm_unvote_lpass_core_hw);    110 EXPORT_SYMBOL_GPL(q6prm_unvote_lpass_core_hw);
111                                                   111 
112 static int q6prm_request_lpass_clock(struct de    112 static int q6prm_request_lpass_clock(struct device *dev, int clk_id, int clk_attr, int clk_root,
113                                      unsigned     113                                      unsigned int freq)
114 {                                                 114 {
115         struct q6prm *prm = dev_get_drvdata(de    115         struct q6prm *prm = dev_get_drvdata(dev->parent);
116         struct apm_module_param_data *param_da    116         struct apm_module_param_data *param_data;
117         struct prm_cmd_request_rsc *req;          117         struct prm_cmd_request_rsc *req;
118         gpr_device_t *gdev = prm->gdev;           118         gpr_device_t *gdev = prm->gdev;
119         struct gpr_pkt *pkt;                      119         struct gpr_pkt *pkt;
120         int rc;                                   120         int rc;
121                                                   121 
122         pkt = audioreach_alloc_cmd_pkt(sizeof(    122         pkt = audioreach_alloc_cmd_pkt(sizeof(*req), PRM_CMD_REQUEST_HW_RSC, 0, gdev->svc.id,
123                                        GPR_PRM    123                                        GPR_PRM_MODULE_IID);
124         if (IS_ERR(pkt))                          124         if (IS_ERR(pkt))
125                 return PTR_ERR(pkt);              125                 return PTR_ERR(pkt);
126                                                   126 
127         req = (void *)pkt + GPR_HDR_SIZE + APM    127         req = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
128                                                   128 
129         param_data = &req->param_data;            129         param_data = &req->param_data;
130                                                   130 
131         param_data->module_instance_id = GPR_P    131         param_data->module_instance_id = GPR_PRM_MODULE_IID;
132         param_data->error_code = 0;               132         param_data->error_code = 0;
133         param_data->param_id = PARAM_ID_RSC_AU    133         param_data->param_id = PARAM_ID_RSC_AUDIO_HW_CLK;
134         param_data->param_size = sizeof(*req)     134         param_data->param_size = sizeof(*req) - APM_MODULE_PARAM_DATA_SIZE;
135                                                   135 
136         req->num_clk_id = 1;                      136         req->num_clk_id = 1;
137         req->clock_id.clock_id = clk_id;          137         req->clock_id.clock_id = clk_id;
138         req->clock_id.clock_freq = freq;          138         req->clock_id.clock_freq = freq;
139         req->clock_id.clock_attri = clk_attr;     139         req->clock_id.clock_attri = clk_attr;
140         req->clock_id.clock_root = clk_root;      140         req->clock_id.clock_root = clk_root;
141                                                   141 
142         rc = q6prm_send_cmd_sync(prm, pkt, PRM    142         rc = q6prm_send_cmd_sync(prm, pkt, PRM_CMD_RSP_REQUEST_HW_RSC);
143                                                   143 
144         kfree(pkt);                               144         kfree(pkt);
145                                                   145 
146         return rc;                                146         return rc;
147 }                                                 147 }
148                                                   148 
149 static int q6prm_release_lpass_clock(struct de    149 static int q6prm_release_lpass_clock(struct device *dev, int clk_id, int clk_attr, int clk_root,
150                           unsigned int freq)      150                           unsigned int freq)
151 {                                                 151 {
152         struct q6prm *prm = dev_get_drvdata(de    152         struct q6prm *prm = dev_get_drvdata(dev->parent);
153         struct apm_module_param_data *param_da    153         struct apm_module_param_data *param_data;
154         struct prm_cmd_release_rsc *rel;          154         struct prm_cmd_release_rsc *rel;
155         gpr_device_t *gdev = prm->gdev;           155         gpr_device_t *gdev = prm->gdev;
156         struct gpr_pkt *pkt;                      156         struct gpr_pkt *pkt;
157         int rc;                                   157         int rc;
158                                                   158 
159         pkt = audioreach_alloc_cmd_pkt(sizeof(    159         pkt = audioreach_alloc_cmd_pkt(sizeof(*rel), PRM_CMD_RELEASE_HW_RSC, 0, gdev->svc.id,
160                                        GPR_PRM    160                                        GPR_PRM_MODULE_IID);
161         if (IS_ERR(pkt))                          161         if (IS_ERR(pkt))
162                 return PTR_ERR(pkt);              162                 return PTR_ERR(pkt);
163                                                   163 
164         rel = (void *)pkt + GPR_HDR_SIZE + APM    164         rel = (void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE;
165                                                   165 
166         param_data = &rel->param_data;            166         param_data = &rel->param_data;
167                                                   167 
168         param_data->module_instance_id = GPR_P    168         param_data->module_instance_id = GPR_PRM_MODULE_IID;
169         param_data->error_code = 0;               169         param_data->error_code = 0;
170         param_data->param_id = PARAM_ID_RSC_AU    170         param_data->param_id = PARAM_ID_RSC_AUDIO_HW_CLK;
171         param_data->param_size = sizeof(*rel)     171         param_data->param_size = sizeof(*rel) - APM_MODULE_PARAM_DATA_SIZE;
172                                                   172 
173         rel->num_clk_id = 1;                      173         rel->num_clk_id = 1;
174         rel->clock_id.clock_id = clk_id;          174         rel->clock_id.clock_id = clk_id;
175                                                   175 
176         rc = q6prm_send_cmd_sync(prm, pkt, PRM    176         rc = q6prm_send_cmd_sync(prm, pkt, PRM_CMD_RSP_RELEASE_HW_RSC);
177                                                   177 
178         kfree(pkt);                               178         kfree(pkt);
179                                                   179 
180         return rc;                                180         return rc;
181 }                                                 181 }
182                                                   182 
183 int q6prm_set_lpass_clock(struct device *dev,     183 int q6prm_set_lpass_clock(struct device *dev, int clk_id, int clk_attr, int clk_root,
184                           unsigned int freq)      184                           unsigned int freq)
185 {                                                 185 {
186         if (freq)                                 186         if (freq)
187                 return q6prm_request_lpass_clo    187                 return q6prm_request_lpass_clock(dev, clk_id, clk_attr, clk_root, freq);
188                                                   188 
189         return q6prm_release_lpass_clock(dev,     189         return q6prm_release_lpass_clock(dev, clk_id, clk_attr, clk_root, freq);
190 }                                                 190 }
191 EXPORT_SYMBOL_GPL(q6prm_set_lpass_clock);         191 EXPORT_SYMBOL_GPL(q6prm_set_lpass_clock);
192                                                   192 
193 static int prm_callback(struct gpr_resp_pkt *d    193 static int prm_callback(struct gpr_resp_pkt *data, void *priv, int op)
194 {                                                 194 {
195         gpr_device_t *gdev = priv;                195         gpr_device_t *gdev = priv;
196         struct q6prm *prm = dev_get_drvdata(&g    196         struct q6prm *prm = dev_get_drvdata(&gdev->dev);
197         struct gpr_ibasic_rsp_result_t *result    197         struct gpr_ibasic_rsp_result_t *result;
198         struct gpr_hdr *hdr = &data->hdr;         198         struct gpr_hdr *hdr = &data->hdr;
199                                                   199 
200         switch (hdr->opcode) {                    200         switch (hdr->opcode) {
201         case PRM_CMD_RSP_REQUEST_HW_RSC:          201         case PRM_CMD_RSP_REQUEST_HW_RSC:
202         case PRM_CMD_RSP_RELEASE_HW_RSC:          202         case PRM_CMD_RSP_RELEASE_HW_RSC:
203                 result = data->payload;           203                 result = data->payload;
204                 prm->result.opcode = hdr->opco    204                 prm->result.opcode = hdr->opcode;
205                 prm->result.status = result->s    205                 prm->result.status = result->status;
206                 wake_up(&prm->wait);              206                 wake_up(&prm->wait);
207                 break;                            207                 break;
208         default:                                  208         default:
209                 break;                            209                 break;
210         }                                         210         }
211                                                   211 
212         return 0;                                 212         return 0;
213 }                                                 213 }
214                                                   214 
215 static int prm_probe(gpr_device_t *gdev)          215 static int prm_probe(gpr_device_t *gdev)
216 {                                                 216 {
217         struct device *dev = &gdev->dev;          217         struct device *dev = &gdev->dev;
218         struct q6prm *cc;                         218         struct q6prm *cc;
219                                                   219 
220         cc = devm_kzalloc(dev, sizeof(*cc), GF    220         cc = devm_kzalloc(dev, sizeof(*cc), GFP_KERNEL);
221         if (!cc)                                  221         if (!cc)
222                 return -ENOMEM;                   222                 return -ENOMEM;
223                                                   223 
224         cc->dev = dev;                            224         cc->dev = dev;
225         cc->gdev = gdev;                          225         cc->gdev = gdev;
226         mutex_init(&cc->lock);                    226         mutex_init(&cc->lock);
227         init_waitqueue_head(&cc->wait);           227         init_waitqueue_head(&cc->wait);
228         dev_set_drvdata(dev, cc);                 228         dev_set_drvdata(dev, cc);
229                                                   229 
230         if (!q6apm_is_adsp_ready())               230         if (!q6apm_is_adsp_ready())
231                 return -EPROBE_DEFER;             231                 return -EPROBE_DEFER;
232                                                   232 
233         return devm_of_platform_populate(dev);    233         return devm_of_platform_populate(dev);
234 }                                                 234 }
235                                                   235 
236 #ifdef CONFIG_OF                                  236 #ifdef CONFIG_OF
237 static const struct of_device_id prm_device_id    237 static const struct of_device_id prm_device_id[]  = {
238         { .compatible = "qcom,q6prm" },           238         { .compatible = "qcom,q6prm" },
239         {},                                       239         {},
240 };                                                240 };
241 MODULE_DEVICE_TABLE(of, prm_device_id);           241 MODULE_DEVICE_TABLE(of, prm_device_id);
242 #endif                                            242 #endif
243                                                   243 
244 static gpr_driver_t prm_driver = {                244 static gpr_driver_t prm_driver = {
245         .probe = prm_probe,                       245         .probe = prm_probe,
246         .gpr_callback = prm_callback,             246         .gpr_callback = prm_callback,
247         .driver = {                               247         .driver = {
248                 .name = "qcom-prm",               248                 .name = "qcom-prm",
249                 .of_match_table = of_match_ptr    249                 .of_match_table = of_match_ptr(prm_device_id),
250         },                                        250         },
251 };                                                251 };
252                                                   252 
253 module_gpr_driver(prm_driver);                    253 module_gpr_driver(prm_driver);
254 MODULE_DESCRIPTION("Q6 Proxy Resource Manager"    254 MODULE_DESCRIPTION("Q6 Proxy Resource Manager");
255 MODULE_LICENSE("GPL");                            255 MODULE_LICENSE("GPL");
256                                                   256 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php