Lines Matching +full:2 +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
20 #include <dt-bindings/mfd/qcom-rpm.h>
60 #define RPM_STATUS_REG(rpm, i) ((rpm)->status_regs + (i) * 4)
61 #define RPM_CTRL_REG(rpm, i) ((rpm)->ctrl_regs + (i) * 4)
62 #define RPM_REQ_REG(rpm, i) ((rpm)->req_regs + (i) * 4)
94 [QCOM_RPM_PM8921_SMPS1] = { 116, 31, 30, 2 },
95 [QCOM_RPM_PM8921_SMPS2] = { 118, 33, 31, 2 },
96 [QCOM_RPM_PM8921_SMPS3] = { 120, 35, 32, 2 },
97 [QCOM_RPM_PM8921_SMPS4] = { 122, 37, 33, 2 },
98 [QCOM_RPM_PM8921_SMPS5] = { 124, 39, 34, 2 },
99 [QCOM_RPM_PM8921_SMPS6] = { 126, 41, 35, 2 },
100 [QCOM_RPM_PM8921_SMPS7] = { 128, 43, 36, 2 },
101 [QCOM_RPM_PM8921_SMPS8] = { 130, 45, 37, 2 },
102 [QCOM_RPM_PM8921_LDO1] = { 132, 47, 38, 2 },
103 [QCOM_RPM_PM8921_LDO2] = { 134, 49, 39, 2 },
104 [QCOM_RPM_PM8921_LDO3] = { 136, 51, 40, 2 },
105 [QCOM_RPM_PM8921_LDO4] = { 138, 53, 41, 2 },
106 [QCOM_RPM_PM8921_LDO5] = { 140, 55, 42, 2 },
107 [QCOM_RPM_PM8921_LDO6] = { 142, 57, 43, 2 },
108 [QCOM_RPM_PM8921_LDO7] = { 144, 59, 44, 2 },
109 [QCOM_RPM_PM8921_LDO8] = { 146, 61, 45, 2 },
110 [QCOM_RPM_PM8921_LDO9] = { 148, 63, 46, 2 },
111 [QCOM_RPM_PM8921_LDO10] = { 150, 65, 47, 2 },
112 [QCOM_RPM_PM8921_LDO11] = { 152, 67, 48, 2 },
113 [QCOM_RPM_PM8921_LDO12] = { 154, 69, 49, 2 },
114 [QCOM_RPM_PM8921_LDO13] = { 156, 71, 50, 2 },
115 [QCOM_RPM_PM8921_LDO14] = { 158, 73, 51, 2 },
116 [QCOM_RPM_PM8921_LDO15] = { 160, 75, 52, 2 },
117 [QCOM_RPM_PM8921_LDO16] = { 162, 77, 53, 2 },
118 [QCOM_RPM_PM8921_LDO17] = { 164, 79, 54, 2 },
119 [QCOM_RPM_PM8921_LDO18] = { 166, 81, 55, 2 },
120 [QCOM_RPM_PM8921_LDO19] = { 168, 83, 56, 2 },
121 [QCOM_RPM_PM8921_LDO20] = { 170, 85, 57, 2 },
122 [QCOM_RPM_PM8921_LDO21] = { 172, 87, 58, 2 },
123 [QCOM_RPM_PM8921_LDO22] = { 174, 89, 59, 2 },
124 [QCOM_RPM_PM8921_LDO23] = { 176, 91, 60, 2 },
125 [QCOM_RPM_PM8921_LDO24] = { 178, 93, 61, 2 },
126 [QCOM_RPM_PM8921_LDO25] = { 180, 95, 62, 2 },
127 [QCOM_RPM_PM8921_LDO26] = { 182, 97, 63, 2 },
128 [QCOM_RPM_PM8921_LDO27] = { 184, 99, 64, 2 },
129 [QCOM_RPM_PM8921_LDO28] = { 186, 101, 65, 2 },
130 [QCOM_RPM_PM8921_LDO29] = { 188, 103, 66, 2 },
131 [QCOM_RPM_PM8921_CLK1] = { 190, 105, 67, 2 },
132 [QCOM_RPM_PM8921_CLK2] = { 192, 107, 68, 2 },
140 [QCOM_RPM_PM8821_SMPS1] = { 201, 116, 76, 2 },
141 [QCOM_RPM_PM8821_SMPS2] = { 203, 118, 77, 2 },
142 [QCOM_RPM_PM8821_LDO1] = { 205, 120, 78, 2 },
143 [QCOM_RPM_PM8921_NCP] = { 207, 122, 80, 2 },
147 [QCOM_RPM_DDR_DMM] = { 212, 127, 84, 2 },
178 [QCOM_RPM_APPS_FABRIC_HALT] = { 45, 25, 18, 2 },
181 [QCOM_RPM_SYS_FABRIC_HALT] = { 63, 29, 22, 2 },
184 [QCOM_RPM_MM_FABRIC_HALT] = { 105, 33, 26, 2 },
187 [QCOM_RPM_PM8901_SMPS0] = { 134, 37, 30, 2 },
188 [QCOM_RPM_PM8901_SMPS1] = { 136, 39, 31, 2 },
189 [QCOM_RPM_PM8901_SMPS2] = { 138, 41, 32, 2 },
190 [QCOM_RPM_PM8901_SMPS3] = { 140, 43, 33, 2 },
191 [QCOM_RPM_PM8901_SMPS4] = { 142, 45, 34, 2 },
192 [QCOM_RPM_PM8901_LDO0] = { 144, 47, 35, 2 },
193 [QCOM_RPM_PM8901_LDO1] = { 146, 49, 36, 2 },
194 [QCOM_RPM_PM8901_LDO2] = { 148, 51, 37, 2 },
195 [QCOM_RPM_PM8901_LDO3] = { 150, 53, 38, 2 },
196 [QCOM_RPM_PM8901_LDO4] = { 152, 55, 39, 2 },
197 [QCOM_RPM_PM8901_LDO5] = { 154, 57, 40, 2 },
198 [QCOM_RPM_PM8901_LDO6] = { 156, 59, 41, 2 },
204 [QCOM_RPM_PM8058_SMPS0] = { 163, 66, 47, 2 },
205 [QCOM_RPM_PM8058_SMPS1] = { 165, 68, 48, 2 },
206 [QCOM_RPM_PM8058_SMPS2] = { 167, 70, 49, 2 },
207 [QCOM_RPM_PM8058_SMPS3] = { 169, 72, 50, 2 },
208 [QCOM_RPM_PM8058_SMPS4] = { 171, 74, 51, 2 },
209 [QCOM_RPM_PM8058_LDO0] = { 173, 76, 52, 2 },
210 [QCOM_RPM_PM8058_LDO1] = { 175, 78, 53, 2 },
211 [QCOM_RPM_PM8058_LDO2] = { 177, 80, 54, 2 },
212 [QCOM_RPM_PM8058_LDO3] = { 179, 82, 55, 2 },
213 [QCOM_RPM_PM8058_LDO4] = { 181, 84, 56, 2 },
214 [QCOM_RPM_PM8058_LDO5] = { 183, 86, 57, 2 },
215 [QCOM_RPM_PM8058_LDO6] = { 185, 88, 58, 2 },
216 [QCOM_RPM_PM8058_LDO7] = { 187, 90, 59, 2 },
217 [QCOM_RPM_PM8058_LDO8] = { 189, 92, 60, 2 },
218 [QCOM_RPM_PM8058_LDO9] = { 191, 94, 61, 2 },
219 [QCOM_RPM_PM8058_LDO10] = { 193, 96, 62, 2 },
220 [QCOM_RPM_PM8058_LDO11] = { 195, 98, 63, 2 },
221 [QCOM_RPM_PM8058_LDO12] = { 197, 100, 64, 2 },
222 [QCOM_RPM_PM8058_LDO13] = { 199, 102, 65, 2 },
223 [QCOM_RPM_PM8058_LDO14] = { 201, 104, 66, 2 },
224 [QCOM_RPM_PM8058_LDO15] = { 203, 106, 67, 2 },
225 [QCOM_RPM_PM8058_LDO16] = { 205, 108, 68, 2 },
226 [QCOM_RPM_PM8058_LDO17] = { 207, 110, 69, 2 },
227 [QCOM_RPM_PM8058_LDO18] = { 209, 112, 70, 2 },
228 [QCOM_RPM_PM8058_LDO19] = { 211, 114, 71, 2 },
229 [QCOM_RPM_PM8058_LDO20] = { 213, 116, 72, 2 },
230 [QCOM_RPM_PM8058_LDO21] = { 215, 118, 73, 2 },
231 [QCOM_RPM_PM8058_LDO22] = { 217, 120, 74, 2 },
232 [QCOM_RPM_PM8058_LDO23] = { 219, 122, 75, 2 },
233 [QCOM_RPM_PM8058_LDO24] = { 221, 124, 76, 2 },
234 [QCOM_RPM_PM8058_LDO25] = { 223, 126, 77, 2 },
237 [QCOM_RPM_PM8058_NCP] = { 227, 130, 80, 2 },
242 .version = 2,
276 [QCOM_RPM_PM8921_SMPS1] = { 117, 31, 30, 2 },
277 [QCOM_RPM_PM8921_SMPS2] = { 119, 33, 31, 2 },
278 [QCOM_RPM_PM8921_SMPS3] = { 121, 35, 32, 2 },
279 [QCOM_RPM_PM8921_SMPS4] = { 123, 37, 33, 2 },
280 [QCOM_RPM_PM8921_SMPS5] = { 125, 39, 34, 2 },
281 [QCOM_RPM_PM8921_SMPS6] = { 127, 41, 35, 2 },
282 [QCOM_RPM_PM8921_SMPS7] = { 129, 43, 36, 2 },
283 [QCOM_RPM_PM8921_SMPS8] = { 131, 45, 37, 2 },
284 [QCOM_RPM_PM8921_LDO1] = { 133, 47, 38, 2 },
285 [QCOM_RPM_PM8921_LDO2] = { 135, 49, 39, 2 },
286 [QCOM_RPM_PM8921_LDO3] = { 137, 51, 40, 2 },
287 [QCOM_RPM_PM8921_LDO4] = { 139, 53, 41, 2 },
288 [QCOM_RPM_PM8921_LDO5] = { 141, 55, 42, 2 },
289 [QCOM_RPM_PM8921_LDO6] = { 143, 57, 43, 2 },
290 [QCOM_RPM_PM8921_LDO7] = { 145, 59, 44, 2 },
291 [QCOM_RPM_PM8921_LDO8] = { 147, 61, 45, 2 },
292 [QCOM_RPM_PM8921_LDO9] = { 149, 63, 46, 2 },
293 [QCOM_RPM_PM8921_LDO10] = { 151, 65, 47, 2 },
294 [QCOM_RPM_PM8921_LDO11] = { 153, 67, 48, 2 },
295 [QCOM_RPM_PM8921_LDO12] = { 155, 69, 49, 2 },
296 [QCOM_RPM_PM8921_LDO13] = { 157, 71, 50, 2 },
297 [QCOM_RPM_PM8921_LDO14] = { 159, 73, 51, 2 },
298 [QCOM_RPM_PM8921_LDO15] = { 161, 75, 52, 2 },
299 [QCOM_RPM_PM8921_LDO16] = { 163, 77, 53, 2 },
300 [QCOM_RPM_PM8921_LDO17] = { 165, 79, 54, 2 },
301 [QCOM_RPM_PM8921_LDO18] = { 167, 81, 55, 2 },
302 [QCOM_RPM_PM8921_LDO19] = { 169, 83, 56, 2 },
303 [QCOM_RPM_PM8921_LDO20] = { 171, 85, 57, 2 },
304 [QCOM_RPM_PM8921_LDO21] = { 173, 87, 58, 2 },
305 [QCOM_RPM_PM8921_LDO22] = { 175, 89, 59, 2 },
306 [QCOM_RPM_PM8921_LDO23] = { 177, 91, 60, 2 },
307 [QCOM_RPM_PM8921_LDO24] = { 179, 93, 61, 2 },
308 [QCOM_RPM_PM8921_LDO25] = { 181, 95, 62, 2 },
309 [QCOM_RPM_PM8921_LDO26] = { 183, 97, 63, 2 },
310 [QCOM_RPM_PM8921_LDO27] = { 185, 99, 64, 2 },
311 [QCOM_RPM_PM8921_LDO28] = { 187, 101, 65, 2 },
312 [QCOM_RPM_PM8921_LDO29] = { 189, 103, 66, 2 },
313 [QCOM_RPM_PM8921_CLK1] = { 191, 105, 67, 2 },
314 [QCOM_RPM_PM8921_CLK2] = { 193, 107, 68, 2 },
322 [QCOM_RPM_PM8921_NCP] = { 202, 116, 80, 2 },
326 [QCOM_RPM_DDR_DMM] = { 207, 121, 84, 2 },
352 [QCOM_RPM_APPS_FABRIC_HALT] = { 35, 19, 18, 2 },
356 [QCOM_RPM_SYS_FABRIC_HALT] = { 53, 23, 22, 2 },
360 [QCOM_RPM_MM_FABRIC_HALT] = { 89, 27, 26, 2 },
363 [QCOM_RPM_MM_FABRIC_ARB] = { 95, 30, 29, 2 },
367 [QCOM_RPM_DDR_DMM] = { 212, 36, 34, 2 },
369 [QCOM_RPM_SMB208_S1a] = { 216, 41, 90, 2 },
370 [QCOM_RPM_SMB208_S1b] = { 218, 43, 91, 2 },
371 [QCOM_RPM_SMB208_S2a] = { 220, 45, 92, 2 },
372 [QCOM_RPM_SMB208_S2b] = { 222, 47, 93, 2 },
394 [QCOM_RPM_APPS_FABRIC_HALT] = { 31, 15, 22, 2 },
398 [QCOM_RPM_PM8018_SMPS1] = { 64, 19, 30, 2 },
399 [QCOM_RPM_PM8018_SMPS2] = { 66, 21, 31, 2 },
400 [QCOM_RPM_PM8018_SMPS3] = { 68, 23, 32, 2 },
401 [QCOM_RPM_PM8018_SMPS4] = { 70, 25, 33, 2 },
402 [QCOM_RPM_PM8018_SMPS5] = { 72, 27, 34, 2 },
403 [QCOM_RPM_PM8018_LDO1] = { 74, 29, 35, 2 },
404 [QCOM_RPM_PM8018_LDO2] = { 76, 31, 36, 2 },
405 [QCOM_RPM_PM8018_LDO3] = { 78, 33, 37, 2 },
406 [QCOM_RPM_PM8018_LDO4] = { 80, 35, 38, 2 },
407 [QCOM_RPM_PM8018_LDO5] = { 82, 37, 39, 2 },
408 [QCOM_RPM_PM8018_LDO6] = { 84, 39, 40, 2 },
409 [QCOM_RPM_PM8018_LDO7] = { 86, 41, 41, 2 },
410 [QCOM_RPM_PM8018_LDO8] = { 88, 43, 42, 2 },
411 [QCOM_RPM_PM8018_LDO9] = { 90, 45, 43, 2 },
412 [QCOM_RPM_PM8018_LDO10] = { 92, 47, 44, 2 },
413 [QCOM_RPM_PM8018_LDO11] = { 94, 49, 45, 2 },
414 [QCOM_RPM_PM8018_LDO12] = { 96, 51, 46, 2 },
415 [QCOM_RPM_PM8018_LDO13] = { 98, 53, 47, 2 },
416 [QCOM_RPM_PM8018_LDO14] = { 100, 55, 48, 2 },
418 [QCOM_RPM_PM8018_NCP] = { 103, 58, 80, 2 },
438 { .compatible = "qcom,rpm-apq8064", .data = &apq8064_template },
439 { .compatible = "qcom,rpm-msm8660", .data = &msm8660_template },
440 { .compatible = "qcom,rpm-msm8960", .data = &msm8960_template },
441 { .compatible = "qcom,rpm-ipq8064", .data = &ipq806x_template },
442 { .compatible = "qcom,rpm-mdm9615", .data = &mdm9615_template },
453 const struct qcom_rpm_data *data = rpm->data; in qcom_rpm_write()
459 if (WARN_ON(resource < 0 || resource >= data->n_resources)) in qcom_rpm_write()
460 return -EINVAL; in qcom_rpm_write()
462 res = &data->resource_table[resource]; in qcom_rpm_write()
463 if (WARN_ON(res->size != count)) in qcom_rpm_write()
464 return -EINVAL; in qcom_rpm_write()
466 mutex_lock(&rpm->lock); in qcom_rpm_write()
468 for (i = 0; i < res->size; i++) in qcom_rpm_write()
469 writel_relaxed(buf[i], RPM_REQ_REG(rpm, res->target_id + i)); in qcom_rpm_write()
471 bitmap_set((unsigned long *)sel_mask, res->select_id, 1); in qcom_rpm_write()
472 for (i = 0; i < rpm->data->req_sel_size; i++) { in qcom_rpm_write()
474 RPM_CTRL_REG(rpm, rpm->data->req_sel_off + i)); in qcom_rpm_write()
477 writel_relaxed(BIT(state), RPM_CTRL_REG(rpm, rpm->data->req_ctx_off)); in qcom_rpm_write()
479 reinit_completion(&rpm->ack); in qcom_rpm_write()
480 regmap_write(rpm->ipc_regmap, rpm->ipc_offset, BIT(rpm->ipc_bit)); in qcom_rpm_write()
482 left = wait_for_completion_timeout(&rpm->ack, RPM_REQUEST_TIMEOUT); in qcom_rpm_write()
484 ret = -ETIMEDOUT; in qcom_rpm_write()
485 else if (rpm->ack_status & RPM_REJECTED) in qcom_rpm_write()
486 ret = -EIO; in qcom_rpm_write()
488 mutex_unlock(&rpm->lock); in qcom_rpm_write()
500 ack = readl_relaxed(RPM_CTRL_REG(rpm, rpm->data->ack_ctx_off)); in qcom_rpm_ack_interrupt()
501 for (i = 0; i < rpm->data->ack_sel_size; i++) in qcom_rpm_ack_interrupt()
503 RPM_CTRL_REG(rpm, rpm->data->ack_sel_off + i)); in qcom_rpm_ack_interrupt()
504 writel(0, RPM_CTRL_REG(rpm, rpm->data->ack_ctx_off)); in qcom_rpm_ack_interrupt()
507 dev_warn(rpm->dev, "ignoring notification!\n"); in qcom_rpm_ack_interrupt()
509 rpm->ack_status = ack; in qcom_rpm_ack_interrupt()
510 complete(&rpm->ack); in qcom_rpm_ack_interrupt()
520 regmap_write(rpm->ipc_regmap, rpm->ipc_offset, BIT(rpm->ipc_bit)); in qcom_rpm_err_interrupt()
521 dev_err(rpm->dev, "RPM triggered fatal error\n"); in qcom_rpm_err_interrupt()
541 rpm = devm_kzalloc(&pdev->dev, sizeof(*rpm), GFP_KERNEL); in qcom_rpm_probe()
543 return -ENOMEM; in qcom_rpm_probe()
545 rpm->dev = &pdev->dev; in qcom_rpm_probe()
546 mutex_init(&rpm->lock); in qcom_rpm_probe()
547 init_completion(&rpm->ack); in qcom_rpm_probe()
550 rpm->ramclk = devm_clk_get_enabled(&pdev->dev, "ram"); in qcom_rpm_probe()
551 if (IS_ERR(rpm->ramclk)) { in qcom_rpm_probe()
552 ret = PTR_ERR(rpm->ramclk); in qcom_rpm_probe()
553 if (ret == -EPROBE_DEFER) in qcom_rpm_probe()
559 rpm->ramclk = NULL; in qcom_rpm_probe()
574 rpm->data = device_get_match_data(&pdev->dev); in qcom_rpm_probe()
575 if (!rpm->data) in qcom_rpm_probe()
576 return -ENODEV; in qcom_rpm_probe()
578 rpm->status_regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in qcom_rpm_probe()
579 if (IS_ERR(rpm->status_regs)) in qcom_rpm_probe()
580 return PTR_ERR(rpm->status_regs); in qcom_rpm_probe()
581 rpm->ctrl_regs = rpm->status_regs + 0x400; in qcom_rpm_probe()
582 rpm->req_regs = rpm->status_regs + 0x600; in qcom_rpm_probe()
584 syscon_np = of_parse_phandle(pdev->dev.of_node, "qcom,ipc", 0); in qcom_rpm_probe()
586 dev_err(&pdev->dev, "no qcom,ipc node\n"); in qcom_rpm_probe()
587 return -ENODEV; in qcom_rpm_probe()
590 rpm->ipc_regmap = syscon_node_to_regmap(syscon_np); in qcom_rpm_probe()
592 if (IS_ERR(rpm->ipc_regmap)) in qcom_rpm_probe()
593 return PTR_ERR(rpm->ipc_regmap); in qcom_rpm_probe()
595 ret = of_property_read_u32_index(pdev->dev.of_node, "qcom,ipc", 1, in qcom_rpm_probe()
596 &rpm->ipc_offset); in qcom_rpm_probe()
598 dev_err(&pdev->dev, "no offset in qcom,ipc\n"); in qcom_rpm_probe()
599 return -EINVAL; in qcom_rpm_probe()
602 ret = of_property_read_u32_index(pdev->dev.of_node, "qcom,ipc", 2, in qcom_rpm_probe()
603 &rpm->ipc_bit); in qcom_rpm_probe()
605 dev_err(&pdev->dev, "no bit in qcom,ipc\n"); in qcom_rpm_probe()
606 return -EINVAL; in qcom_rpm_probe()
609 dev_set_drvdata(&pdev->dev, rpm); in qcom_rpm_probe()
613 fw_version[2] = readl(RPM_STATUS_REG(rpm, 2)); in qcom_rpm_probe()
614 if (fw_version[0] != rpm->data->version) { in qcom_rpm_probe()
615 dev_err(&pdev->dev, in qcom_rpm_probe()
619 fw_version[2], in qcom_rpm_probe()
620 rpm->data->version); in qcom_rpm_probe()
621 return -EFAULT; in qcom_rpm_probe()
626 writel(fw_version[2], RPM_CTRL_REG(rpm, 2)); in qcom_rpm_probe()
628 dev_info(&pdev->dev, "RPM firmware %u.%u.%u\n", fw_version[0], in qcom_rpm_probe()
630 fw_version[2]); in qcom_rpm_probe()
632 ret = devm_request_irq(&pdev->dev, in qcom_rpm_probe()
639 dev_err(&pdev->dev, "failed to request ack interrupt\n"); in qcom_rpm_probe()
645 dev_warn(&pdev->dev, "failed to mark ack irq as wakeup\n"); in qcom_rpm_probe()
647 ret = devm_request_irq(&pdev->dev, in qcom_rpm_probe()
654 dev_err(&pdev->dev, "failed to request err interrupt\n"); in qcom_rpm_probe()
658 ret = devm_request_irq(&pdev->dev, in qcom_rpm_probe()
665 dev_err(&pdev->dev, "failed to request wakeup interrupt\n"); in qcom_rpm_probe()
671 dev_warn(&pdev->dev, "failed to mark wakeup irq as wakeup\n"); in qcom_rpm_probe()
673 return devm_of_platform_populate(&pdev->dev); in qcom_rpm_probe()