forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/soc/rockchip/rockchip_amp.c
....@@ -6,6 +6,7 @@
66 * Author: Tony Xie <tony.xie@rock-chips.com>
77 */
88
9
+#include <asm/cputype.h>
910 #include <linux/clk.h>
1011 #include <linux/module.h>
1112 #include <linux/of.h>
....@@ -13,10 +14,19 @@
1314 #include <linux/pm_domain.h>
1415 #include <linux/pm_runtime.h>
1516 #include <linux/rockchip/rockchip_sip.h>
17
+#include <soc/rockchip/rockchip_amp.h>
18
+#include <linux/irqchip/arm-gic-common.h>
1619
1720 #define RK_CPU_STATUS_OFF 0
1821 #define RK_CPU_STATUS_ON 1
1922 #define RK_CPU_STATUS_BUSY -1
23
+#define AMP_AFF_MAX_CLUSTER 4
24
+#define AMP_AFF_MAX_CPU 8
25
+#define GPIO_BANK_NUM 16
26
+#define GPIO_GROUP_PRIO_MAX 3
27
+
28
+#define MAX_GIC_SPI_NUM (1020)
29
+#define AMP_GIC_DBG(fmt, arg...) do { if (0) { pr_warn(fmt, ##arg); } } while (0)
2030
2131 enum amp_cpu_ctrl_status {
2232 AMP_CPU_STATUS_AMP_DIS = 0,
....@@ -43,6 +53,34 @@
4353 u64 entry;
4454 u64 cpu_id;
4555 } cpu_boot_info[CONFIG_NR_CPUS];
56
+
57
+struct amp_gpio_group_s {
58
+ u32 bank_id;
59
+ u32 prio;
60
+ u64 irq_aff[AMP_AFF_MAX_CPU];
61
+ u32 irq_id[AMP_AFF_MAX_CPU];
62
+ u32 en[AMP_AFF_MAX_CPU];
63
+};
64
+
65
+struct amp_irq_cfg_s {
66
+ u64 aff;
67
+ u32 prio;
68
+ u32 cpumask;
69
+ int amp_flag;
70
+} irqs_cfg[MAX_GIC_SPI_NUM];
71
+
72
+static struct amp_gic_ctrl_s {
73
+ enum gic_type gic_version;
74
+ u32 spis_num;
75
+ struct {
76
+ u32 aff;
77
+ u32 cpumask;
78
+ u32 flag;
79
+ } aff_to_cpumask[AMP_AFF_MAX_CLUSTER][AMP_AFF_MAX_CPU];
80
+ struct amp_irq_cfg_s irqs_cfg[MAX_GIC_SPI_NUM];
81
+ struct amp_gpio_group_s gpio_grp[GPIO_BANK_NUM][GPIO_GROUP_PRIO_MAX];
82
+ u32 gpio_banks;
83
+} amp_ctrl;
4684
4785 static int get_cpu_boot_info_idx(unsigned long cpu_id)
4886 {
....@@ -77,29 +115,29 @@
77115 static void cpu_status_print(unsigned long cpu_id, struct arm_smccc_res *res)
78116 {
79117 if (res->a0) {
80
- pr_info("get cpu-0x%lx status(%lx) error!\n", cpu_id, res->a0);
118
+ pr_info("failed to get cpu[%lx] status, ret=%lx!\n", cpu_id, res->a0);
81119 return;
82120 }
83121
84122 if (res->a1 == AMP_CPU_STATUS_AMP_DIS)
85
- pr_info("cpu-0x%lx amp is disable (%ld)\n", cpu_id, res->a1);
123
+ pr_info("cpu[%lx] amp is disabled (%ld)\n", cpu_id, res->a1);
86124 else if (res->a1 == AMP_CPU_STATUS_EN)
87
- pr_info("cpu-0x%lx amp is enable (%ld)\n", cpu_id, res->a1);
125
+ pr_info("cpu[%lx] amp is enabled (%ld)\n", cpu_id, res->a1);
88126 else if (res->a1 == AMP_CPU_STATUS_ON)
89
- pr_info("cpu-0x%lx amp: cpu is on (%ld)\n", cpu_id, res->a1);
127
+ pr_info("cpu[%lx] amp: cpu is on (%ld)\n", cpu_id, res->a1);
90128 else if (res->a1 == AMP_CPU_STATUS_OFF)
91
- pr_info("cpu-0x%lx amp: cpu is off(%ld)\n", cpu_id, res->a1);
129
+ pr_info("cpu[%lx] amp: cpu is off(%ld)\n", cpu_id, res->a1);
92130 else
93
- pr_info("cpu-0x%lx status(%ld) is error\n", cpu_id, res->a1);
131
+ pr_info("cpu[%lx] amp status(%ld) is error\n", cpu_id, res->a1);
94132
95133 if (res->a2 == RK_CPU_STATUS_OFF)
96
- pr_info("cpu-0x%lx status(%ld) is off\n", cpu_id, res->a2);
134
+ pr_info("cpu[%lx] status(%ld) is off\n", cpu_id, res->a2);
97135 else if (res->a2 == RK_CPU_STATUS_ON)
98
- pr_info("cpu-0x%lx status(%ld) is on\n", cpu_id, res->a2);
136
+ pr_info("cpu[%lx] status(%ld) is on\n", cpu_id, res->a2);
99137 else if (res->a2 == RK_CPU_STATUS_BUSY)
100
- pr_info("cpu-0x%lx status(%ld) is busy\n", cpu_id, res->a2);
138
+ pr_info("cpu[%lx] status(%ld) is busy\n", cpu_id, res->a2);
101139 else
102
- pr_info("cpu-0x%lx status(%ld) is error\n", cpu_id, res->a2);
140
+ pr_info("cpu[%lx] status(%ld) is error\n", cpu_id, res->a2);
103141 }
104142
105143 static ssize_t boot_cpu_store(struct device *dev,
....@@ -107,23 +145,23 @@
107145 const char *buf,
108146 size_t count)
109147 {
110
- char cmd[10];
111
- unsigned long cpu_id;
112148 struct arm_smccc_res res = {0};
149
+ unsigned long cpu_id;
150
+ char cmd[10];
113151 int ret, idx;
114152
115153 ret = sscanf(buf, "%s", cmd);
116
- if (ret != 1)
154
+ if (ret != 1) {
155
+ pr_info("Use on/off [cpu id] or status [cpu id]\n");
117156 return -EINVAL;
157
+ }
118158
119159 if (!strncmp(cmd, "status", strlen("status"))) {
120160 ret = sscanf(buf, "%s %lx", cmd, &cpu_id);
121
-
122161 if (ret != 2)
123162 return -EINVAL;
124163
125
- res = sip_smc_get_amp_info(RK_AMP_SUB_FUNC_GET_CPU_STATUS,
126
- cpu_id);
164
+ res = sip_smc_get_amp_info(RK_AMP_SUB_FUNC_GET_CPU_STATUS, cpu_id);
127165 cpu_status_print(cpu_id, &res);
128166 } else if (!strncmp(cmd, "off", strlen("off"))) {
129167 ret = sscanf(buf, "%s %lx", cmd, &cpu_id);
....@@ -131,17 +169,14 @@
131169 return -EINVAL;
132170
133171 idx = get_cpu_boot_info_idx(cpu_id);
134
-
135172 if (idx >= 0 && cpu_boot_info[idx].en) {
136173 ret = sip_smc_amp_config(RK_AMP_SUB_FUNC_REQ_CPU_OFF,
137174 cpu_id, 0, 0);
138175 if (ret)
139
- pr_info("requesting a cpu off is error(%d)!\n",
140
- ret);
176
+ dev_warn(dev, "failed to request cpu[%lx] off, ret=%d!\n", cpu_id, ret);
141177 }
142178 } else if (!strncmp(cmd, "on", strlen("on"))) {
143179 ret = sscanf(buf, "%s %lx", cmd, &cpu_id);
144
-
145180 if (ret != 2)
146181 return -EINVAL;
147182
....@@ -152,11 +187,14 @@
152187 cpu_boot_info[idx].entry,
153188 0);
154189 if (ret)
155
- pr_info("booting up a cpu is error(%d)!\n",
156
- ret);
190
+ dev_warn(dev, "Brought up cpu[%lx] failed, ret=%d\n", cpu_id, ret);
191
+ else
192
+ pr_info("Brought up cpu[%lx] ok.\n", cpu_id);
193
+ } else {
194
+ dev_warn(dev, "cpu[%lx] is unavailable\n", cpu_id);
157195 }
158196 } else {
159
- pr_info("unsupported cmd(%s)\n", cmd);
197
+ dev_warn(dev, "unsupported cmd(%s)\n", cmd);
160198 }
161199
162200 return count;
....@@ -171,31 +209,34 @@
171209 struct device_node *cpu_node, int idx)
172210 {
173211 u64 cpu_entry, cpu_id;
174
- u32 cpu_mode;
212
+ u32 cpu_mode, boot_on;
175213 int ret;
176214
177215 if (idx >= CONFIG_NR_CPUS)
178216 return -1;
179217
218
+ if (of_property_read_u64_array(cpu_node, "id", &cpu_id, 1)) {
219
+ dev_warn(dev, "failed to get 'id'\n");
220
+ return -1;
221
+ }
222
+
180223 if (of_property_read_u64_array(cpu_node, "entry", &cpu_entry, 1)) {
181
- dev_warn(dev, "can not get the entry\n");
224
+ dev_warn(dev, "failed to get cpu[%llx] 'entry'\n", cpu_id);
182225 return -1;
183226 }
184227
185228 if (!cpu_entry) {
186
- dev_warn(dev, "cpu-entry is 0\n");
187
- return -1;
188
- }
189
-
190
- if (of_property_read_u64_array(cpu_node, "id", &cpu_id, 1)) {
191
- dev_warn(dev, "can not get the cpu id\n");
229
+ dev_warn(dev, "invalid cpu[%llx] 'entry': 0\n", cpu_id);
192230 return -1;
193231 }
194232
195233 if (of_property_read_u32_array(cpu_node, "mode", &cpu_mode, 1)) {
196
- dev_warn(dev, "can not get the cpu mode\n");
234
+ dev_warn(dev, "failed to get cpu[%llx] 'mode'\n", cpu_id);
197235 return -1;
198236 }
237
+
238
+ if (of_property_read_u32_array(cpu_node, "boot-on", &boot_on, 1))
239
+ boot_on = 1; /* compatible old action */
199240
200241 cpu_boot_info[idx].entry = cpu_entry;
201242 cpu_boot_info[idx].mode = cpu_mode;
....@@ -203,14 +244,18 @@
203244
204245 ret = sip_smc_amp_config(RK_AMP_SUB_FUNC_CFG_MODE, cpu_id, cpu_mode, 0);
205246 if (ret) {
206
- dev_warn(dev, "setting cpu mode is error(%d)!\n", ret);
247
+ dev_warn(dev, "failed to set cpu mode, ret=%d\n", ret);
207248 return ret;
208249 }
209250
210
- ret = sip_smc_amp_config(RK_AMP_SUB_FUNC_CPU_ON, cpu_id, cpu_entry, 0);
211
- if (ret) {
212
- dev_warn(dev, "booting up a cpu is error(%d)!\n", ret);
213
- return ret;
251
+ if (boot_on) {
252
+ ret = sip_smc_amp_config(RK_AMP_SUB_FUNC_CPU_ON, cpu_id, cpu_entry, 0);
253
+ if (ret) {
254
+ dev_warn(dev, "Brought up cpu[%llx] failed, ret=%d\n", cpu_id, ret);
255
+ return ret;
256
+ } else {
257
+ pr_info("Brought up cpu[%llx] ok.\n", cpu_id);
258
+ }
214259 }
215260
216261 cpu_boot_info[idx].en = 1;
....@@ -218,11 +263,289 @@
218263 return 0;
219264 }
220265
266
+int rockchip_amp_check_amp_irq(u32 irq)
267
+{
268
+ return amp_ctrl.irqs_cfg[irq].amp_flag;
269
+}
270
+
271
+u32 rockchip_amp_get_irq_prio(u32 irq)
272
+{
273
+ return amp_ctrl.irqs_cfg[irq].prio;
274
+}
275
+
276
+u32 rockchip_amp_get_irq_cpumask(u32 irq)
277
+{
278
+ return amp_ctrl.irqs_cfg[irq].cpumask;
279
+}
280
+
281
+int rockchip_amp_need_init_amp_irq(u32 irq)
282
+{
283
+ return amp_ctrl.irqs_cfg[irq].amp_flag;
284
+}
285
+
286
+static u32 amp_get_cpumask_bit(u64 aff)
287
+{
288
+ u32 aff_cluster, aff_cpu;
289
+
290
+ aff_cluster = MPIDR_AFFINITY_LEVEL(aff, 1);
291
+ aff_cpu = MPIDR_AFFINITY_LEVEL(aff, 0);
292
+
293
+ if (aff_cpu >= AMP_AFF_MAX_CPU || aff_cluster >= AMP_AFF_MAX_CLUSTER)
294
+ return 0;
295
+
296
+ AMP_GIC_DBG(" %s: aff:%d-%d: %x\n", __func__, aff_cluster, aff_cpu,
297
+ amp_ctrl.aff_to_cpumask[aff_cluster][aff_cpu].cpumask);
298
+
299
+ return amp_ctrl.aff_to_cpumask[aff_cluster][aff_cpu].cpumask;
300
+}
301
+
302
+u64 rockchip_amp_get_irq_aff(u32 irq)
303
+{
304
+ return amp_ctrl.irqs_cfg[irq].aff;
305
+}
306
+
307
+static int gic_amp_get_gpio_prio_group_info(struct device_node *np,
308
+ struct amp_gic_ctrl_s *amp_ctrl,
309
+ int prio_id)
310
+{
311
+ u32 gpio_bank, prio, irq_id;
312
+ u64 irq_aff;
313
+ int i, count0, count1;
314
+ struct amp_gpio_group_s *gpio_grp;
315
+ struct amp_irq_cfg_s *irqs_cfg;
316
+
317
+ if (prio_id >= GPIO_GROUP_PRIO_MAX)
318
+ return -EINVAL;
319
+
320
+ if (of_property_read_u32_array(np, "gpio-bank", &gpio_bank, 1))
321
+ return -EINVAL;
322
+ if (gpio_bank >= amp_ctrl->gpio_banks)
323
+ return -EINVAL;
324
+
325
+ gpio_grp = &amp_ctrl->gpio_grp[gpio_bank][prio_id];
326
+
327
+ if (of_property_read_u32_array(np, "prio", &prio, 1))
328
+ return -EINVAL;
329
+
330
+ if (gpio_bank >= GPIO_BANK_NUM)
331
+ return -EINVAL;
332
+
333
+ AMP_GIC_DBG("%s: gpio-%d, group prio:%d-%x\n",
334
+ __func__, gpio_bank, prio_id, prio);
335
+
336
+ count0 = of_property_count_u32_elems(np, "girq-id");
337
+ count1 = of_property_count_u64_elems(np, "girq-aff");
338
+
339
+ if (count0 != count1)
340
+ return -EINVAL;
341
+
342
+ gpio_grp->prio = prio;
343
+
344
+ for (i = 0; i < count0; i++) {
345
+ of_property_read_u32_index(np, "girq-id", i, &irq_id);
346
+ gpio_grp->irq_id[i] = irq_id;
347
+ of_property_read_u64_index(np, "girq-aff", i, &irq_aff);
348
+
349
+ gpio_grp->irq_aff[i] = irq_aff;
350
+
351
+ of_property_read_u32_index(np, "girq-en", i, &gpio_grp->en[i]);
352
+
353
+ irqs_cfg = &amp_ctrl->irqs_cfg[irq_id];
354
+
355
+ AMP_GIC_DBG(" %s: group cpu-%d, irq-%d: prio-%x, aff-%llx en-%d\n",
356
+ __func__, i, gpio_grp->irq_id[i], gpio_grp->prio,
357
+ gpio_grp->irq_aff[i], gpio_grp->en[i]);
358
+
359
+ if (gpio_grp->en[i]) {
360
+ irqs_cfg->prio = gpio_grp->prio;
361
+ irqs_cfg->aff = irq_aff;
362
+ if (amp_ctrl->gic_version == GIC_V2) {
363
+ irqs_cfg->cpumask = amp_get_cpumask_bit(irq_aff);
364
+ if (!irqs_cfg->cpumask) {
365
+ pr_err(" %s: get cpumask error\n", __func__);
366
+ return -EINVAL;
367
+ }
368
+ }
369
+ irqs_cfg->amp_flag = 1;
370
+ }
371
+
372
+ AMP_GIC_DBG(" %s: prio-%x aff-%llx cpumaks-%x flag-%d\n",
373
+ __func__, irqs_cfg->prio, irqs_cfg->aff,
374
+ irqs_cfg->cpumask, irqs_cfg->amp_flag);
375
+ }
376
+
377
+ return 0;
378
+}
379
+
380
+static int gic_amp_gpio_group_get_info(struct device_node *group_node,
381
+ struct amp_gic_ctrl_s *amp_ctrl,
382
+ int idx)
383
+{
384
+ int i = 0;
385
+ struct device_node *node;
386
+
387
+ if (group_node) {
388
+ for_each_available_child_of_node(group_node, node) {
389
+ if (i >= GPIO_GROUP_PRIO_MAX)
390
+ break;
391
+ if (!gic_amp_get_gpio_prio_group_info(node, amp_ctrl,
392
+ i)) {
393
+ i++;
394
+ }
395
+ }
396
+ }
397
+ return 0;
398
+}
399
+
400
+static void gic_of_get_gpio_group(struct device_node *np,
401
+ struct amp_gic_ctrl_s *amp_ctrl)
402
+{
403
+ struct device_node *gpio_group_node, *node;
404
+ int i = 0;
405
+
406
+ if (of_property_read_u32_array(np, "gpio-group-banks",
407
+ &amp_ctrl->gpio_banks, 1))
408
+ return;
409
+
410
+ gpio_group_node = of_get_child_by_name(np, "gpio-group");
411
+ if (gpio_group_node) {
412
+ for_each_available_child_of_node(gpio_group_node, node) {
413
+ if (i >= amp_ctrl->gpio_banks)
414
+ break;
415
+ if (!gic_amp_gpio_group_get_info(node, amp_ctrl, i))
416
+ i++;
417
+ }
418
+ }
419
+
420
+ of_node_put(gpio_group_node);
421
+}
422
+
423
+static int amp_gic_get_cpumask(struct device_node *np, struct amp_gic_ctrl_s *amp_ctrl)
424
+{
425
+ const struct property *prop;
426
+ int count, i;
427
+ u32 cluster, aff_cpu;
428
+ u64 aff, cpumask;
429
+
430
+ if (amp_ctrl->gic_version != GIC_V2)
431
+ return 0;
432
+ prop = of_find_property(np, "amp-cpu-aff-maskbits", NULL);
433
+
434
+ if (!prop)
435
+ return -1;
436
+
437
+ if (!prop->value)
438
+ return -1;
439
+
440
+ count = of_property_count_u64_elems(np, "amp-cpu-aff-maskbits");
441
+ if (count % 2)
442
+ return -1;
443
+
444
+ for (i = 0; i < count / 2; i++) {
445
+ of_property_read_u64_index(np, "amp-cpu-aff-maskbits",
446
+ 2 * i, &aff);
447
+ cluster = MPIDR_AFFINITY_LEVEL(aff, 1);
448
+ aff_cpu = MPIDR_AFFINITY_LEVEL(aff, 0);
449
+ amp_ctrl->aff_to_cpumask[cluster][aff_cpu].aff = aff;
450
+
451
+ of_property_read_u64_index(np, "amp-cpu-aff-maskbits",
452
+ 2 * i + 1, &cpumask);
453
+
454
+ amp_ctrl->aff_to_cpumask[cluster][aff_cpu].cpumask = (u32)cpumask;
455
+
456
+ AMP_GIC_DBG("cpumask: %d-%d: aff-%llx cpumask-%d\n",
457
+ cluster, aff_cpu, aff, (u32)cpumask);
458
+
459
+ if (!cpumask)
460
+ return -1;
461
+ }
462
+
463
+ return 0;
464
+}
465
+
466
+static void amp_gic_get_irqs_config(struct device_node *np,
467
+ struct amp_gic_ctrl_s *amp_ctrl)
468
+{
469
+ const struct property *prop;
470
+ u32 irq, i;
471
+ int count;
472
+ u64 aff, val, prio;
473
+
474
+ prop = of_find_property(np, "amp-irqs", NULL);
475
+ if (!prop)
476
+ return;
477
+
478
+ if (!prop->value)
479
+ return;
480
+
481
+ count = of_property_count_u64_elems(np, "amp-irqs");
482
+
483
+ if (count % 3)
484
+ return;
485
+
486
+ for (i = 0; i < count / 3; i++) {
487
+ of_property_read_u64_index(np, "amp-irqs", 3 * i, &val);
488
+ irq = (u32)val;
489
+ if (irq > amp_ctrl->spis_num)
490
+ break;
491
+
492
+ of_property_read_u64_index(np, "amp-irqs", 3 * i + 1, &prio);
493
+ of_property_read_u64_index(np, "amp-irqs", 3 * i + 2, &aff);
494
+
495
+ AMP_GIC_DBG("%s: irq-%d aff-%llx prio-%llx\n",
496
+ __func__, irq, aff, prio);
497
+
498
+ amp_ctrl->irqs_cfg[irq].prio = (u32)prio;
499
+ amp_ctrl->irqs_cfg[irq].aff = aff;
500
+ if (amp_ctrl->gic_version == GIC_V2) {
501
+ amp_ctrl->irqs_cfg[irq].cpumask = amp_get_cpumask_bit(aff);
502
+ if (!amp_ctrl->irqs_cfg[irq].cpumask) {
503
+ pr_err("%s: get cpumask error\n", __func__);
504
+ break;
505
+ }
506
+ }
507
+
508
+ if (!amp_ctrl->irqs_cfg[irq].aff &&
509
+ !amp_ctrl->irqs_cfg[irq].prio)
510
+ break;
511
+
512
+ amp_ctrl->irqs_cfg[irq].amp_flag = 1;
513
+
514
+ AMP_GIC_DBG(" %s: irq-%d aff-%llx cpumask-%x pri-%x\n",
515
+ __func__, irq, amp_ctrl->irqs_cfg[irq].aff,
516
+ amp_ctrl->irqs_cfg[irq].cpumask,
517
+ amp_ctrl->irqs_cfg[irq].prio);
518
+ }
519
+}
520
+
521
+void rockchip_amp_get_gic_info(u32 spis_num, enum gic_type gic_version)
522
+{
523
+ struct device_node *np;
524
+
525
+ amp_ctrl.spis_num = spis_num;
526
+ amp_ctrl.gic_version = gic_version;
527
+
528
+ np = of_find_node_by_name(NULL, "rockchip-amp");
529
+ if (!np)
530
+ return;
531
+
532
+ if (amp_gic_get_cpumask(np, &amp_ctrl)) {
533
+ pr_err("%s: get amp gic cpu mask error\n", __func__);
534
+ goto exit;
535
+ }
536
+
537
+ gic_of_get_gpio_group(np, &amp_ctrl);
538
+ amp_gic_get_irqs_config(np, &amp_ctrl);
539
+
540
+exit:
541
+ of_node_put(np);
542
+}
543
+
221544 static int rockchip_amp_probe(struct platform_device *pdev)
222545 {
223
- struct rkamp_device *rkamp_dev = NULL;
224
- int ret, i, idx = 0;
225546 struct device_node *cpus_node, *cpu_node;
547
+ struct rkamp_device *rkamp_dev;
548
+ int ret, i, idx = 0;
226549
227550 rkamp_dev = devm_kzalloc(&pdev->dev, sizeof(*rkamp_dev), GFP_KERNEL);
228551 if (!rkamp_dev)
....@@ -231,50 +554,46 @@
231554 rkamp_dev->num_clks = devm_clk_bulk_get_all(&pdev->dev, &rkamp_dev->clks);
232555 if (rkamp_dev->num_clks < 0)
233556 return -ENODEV;
557
+
234558 ret = clk_bulk_prepare_enable(rkamp_dev->num_clks, rkamp_dev->clks);
235
- if (ret) {
236
- dev_err(&pdev->dev, "failed to prepare enable clks: %d\n", ret);
237
- return ret;
238
- }
559
+ if (ret)
560
+ return dev_err_probe(&pdev->dev, ret, "failed to prepare enable clks: %d\n", ret);
239561
240562 pm_runtime_enable(&pdev->dev);
241563
242
- rkamp_dev->num_pds = of_count_phandle_with_args(pdev->dev.of_node, "power-domains",
243
- "#power-domain-cells");
244
-
564
+ rkamp_dev->num_pds =
565
+ of_count_phandle_with_args(pdev->dev.of_node, "power-domains",
566
+ "#power-domain-cells");
245567 if (rkamp_dev->num_pds > 0) {
246
- rkamp_dev->pd_dev = devm_kmalloc_array(&pdev->dev, rkamp_dev->num_pds,
247
- sizeof(*rkamp_dev->pd_dev), GFP_KERNEL);
568
+ rkamp_dev->pd_dev =
569
+ devm_kmalloc_array(&pdev->dev, rkamp_dev->num_pds,
570
+ sizeof(*rkamp_dev->pd_dev), GFP_KERNEL);
248571 if (!rkamp_dev->pd_dev)
249572 return -ENOMEM;
250573
251574 if (rkamp_dev->num_pds == 1) {
252
- ret = pm_runtime_get_sync(&pdev->dev);
253
- if (ret < 0) {
254
- dev_err(&pdev->dev, "failed to get power-domain\n");
255
- return ret;
256
- }
575
+ ret = pm_runtime_resume_and_get(&pdev->dev);
576
+ if (ret < 0)
577
+ return dev_err_probe(&pdev->dev, ret,
578
+ "failed to get power-domain\n");
257579 } else {
258580 for (i = 0; i < rkamp_dev->num_pds; i++) {
259581 rkamp_dev->pd_dev[i] = dev_pm_domain_attach_by_id(&pdev->dev, i);
260
- ret = pm_runtime_get_sync(rkamp_dev->pd_dev[i]);
261
- if (ret < 0) {
262
- dev_err(&pdev->dev, "failed to get pd_dev[%d]\n", i);
263
- return ret;
264
- }
582
+ ret = pm_runtime_resume_and_get(rkamp_dev->pd_dev[i]);
583
+ if (ret < 0)
584
+ return dev_err_probe(&pdev->dev, ret,
585
+ "failed to get pd_dev[%d]\n", i);
265586 }
266587 }
267588 }
268589
269590 cpus_node = of_get_child_by_name(pdev->dev.of_node, "amp-cpus");
270
-
271591 if (cpus_node) {
272592 for_each_available_child_of_node(cpus_node, cpu_node) {
273
- if (!rockchip_amp_boot_cpus(&pdev->dev, cpu_node,
274
- idx)) {
593
+ if (!rockchip_amp_boot_cpus(&pdev->dev, cpu_node, idx))
275594 idx++;
276
- }
277595 }
596
+ of_node_put(cpus_node);
278597 }
279598
280599 rk_amp_kobj = kobject_create_and_add("rk_amp", NULL);
....@@ -283,10 +602,8 @@
283602
284603 for (i = 0; i < ARRAY_SIZE(rk_amp_attrs); i++) {
285604 ret = sysfs_create_file(rk_amp_kobj, &rk_amp_attrs[i].attr);
286
- if (ret) {
287
- dev_err(&pdev->dev, "create file index %d error\n", i);
288
- return ret;
289
- }
605
+ if (ret)
606
+ return dev_err_probe(&pdev->dev, ret, "create file index %d error\n", i);
290607 }
291608
292609 return 0;
....@@ -294,8 +611,8 @@
294611
295612 static int rockchip_amp_remove(struct platform_device *pdev)
296613 {
297
- int i;
298614 struct rkamp_device *rkamp_dev = platform_get_drvdata(pdev);
615
+ int i;
299616
300617 clk_bulk_disable_unprepare(rkamp_dev->num_clks, rkamp_dev->clks);
301618
....@@ -320,9 +637,9 @@
320637 }
321638
322639 static const struct of_device_id rockchip_amp_match[] = {
323
- {
324
- .compatible = "rockchip,rk3568-amp",
325
- },
640
+ { .compatible = "rockchip,amp" },
641
+ { .compatible = "rockchip,mcu-amp" },
642
+ { .compatible = "rockchip,rk3568-amp" },
326643 { /* sentinel */ },
327644 };
328645
....@@ -340,4 +657,4 @@
340657
341658 MODULE_DESCRIPTION("Rockchip AMP driver");
342659 MODULE_AUTHOR("Tony xie<tony.xie@rock-chips.com>");
343
-MODULE_LICENSE("GPL v2");
660
+MODULE_LICENSE("GPL");