-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathslim-msm-ctrl.c
More file actions
1615 lines (1523 loc) · 43 KB
/
slim-msm-ctrl.c
File metadata and controls
1615 lines (1523 loc) · 43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/slimbus/slimbus.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/clk.h>
#include <linux/pm_runtime.h>
#include <linux/of.h>
#include <linux/of_slimbus.h>
#include <linux/msm-sps.h>
#include <linux/qdsp6v2/apr.h>
#include "slim-msm.h"
#define MSM_SLIM_NAME "msm_slim_ctrl"
#define SLIM_ROOT_FREQ 24576000
#define QC_MSM_DEVS 5
/* Manager registers */
enum mgr_reg {
MGR_CFG = 0x200,
MGR_STATUS = 0x204,
MGR_RX_MSGQ_CFG = 0x208,
MGR_INT_EN = 0x210,
MGR_INT_STAT = 0x214,
MGR_INT_CLR = 0x218,
MGR_TX_MSG = 0x230,
MGR_RX_MSG = 0x270,
MGR_IE_STAT = 0x2F0,
MGR_VE_STAT = 0x300,
};
enum msg_cfg {
MGR_CFG_ENABLE = 1,
MGR_CFG_RX_MSGQ_EN = 1 << 1,
MGR_CFG_TX_MSGQ_EN_HIGH = 1 << 2,
MGR_CFG_TX_MSGQ_EN_LOW = 1 << 3,
};
/* Message queue types */
enum msm_slim_msgq_type {
MSGQ_RX = 0,
MSGQ_TX_LOW = 1,
MSGQ_TX_HIGH = 2,
};
/* Framer registers */
enum frm_reg {
FRM_CFG = 0x400,
FRM_STAT = 0x404,
FRM_INT_EN = 0x410,
FRM_INT_STAT = 0x414,
FRM_INT_CLR = 0x418,
FRM_WAKEUP = 0x41C,
FRM_CLKCTL_DONE = 0x420,
FRM_IE_STAT = 0x430,
FRM_VE_STAT = 0x440,
};
/* Interface registers */
enum intf_reg {
INTF_CFG = 0x600,
INTF_STAT = 0x604,
INTF_INT_EN = 0x610,
INTF_INT_STAT = 0x614,
INTF_INT_CLR = 0x618,
INTF_IE_STAT = 0x630,
INTF_VE_STAT = 0x640,
};
enum mgr_intr {
MGR_INT_RECFG_DONE = 1 << 24,
MGR_INT_TX_NACKED_2 = 1 << 25,
MGR_INT_MSG_BUF_CONTE = 1 << 26,
MGR_INT_RX_MSG_RCVD = 1 << 30,
MGR_INT_TX_MSG_SENT = 1 << 31,
};
enum frm_cfg {
FRM_ACTIVE = 1,
CLK_GEAR = 9,
ROOT_FREQ = 19,
REF_CLK_GEAR = 15,
INTR_WAKE = 19,
};
static struct msm_slim_sat *msm_slim_alloc_sat(struct msm_slim_ctrl *dev);
static int msm_sat_enqueue(struct msm_slim_sat *sat, u32 *buf, u8 len)
{
struct msm_slim_ctrl *dev = sat->dev;
unsigned long flags;
spin_lock_irqsave(&sat->lock, flags);
if ((sat->stail + 1) % SAT_CONCUR_MSG == sat->shead) {
spin_unlock_irqrestore(&sat->lock, flags);
dev_err(dev->dev, "SAT QUEUE full!");
return -EXFULL;
}
memcpy(sat->sat_msgs[sat->stail], (u8 *)buf, len);
sat->stail = (sat->stail + 1) % SAT_CONCUR_MSG;
spin_unlock_irqrestore(&sat->lock, flags);
return 0;
}
static int msm_sat_dequeue(struct msm_slim_sat *sat, u8 *buf)
{
unsigned long flags;
spin_lock_irqsave(&sat->lock, flags);
if (sat->stail == sat->shead) {
spin_unlock_irqrestore(&sat->lock, flags);
return -ENODATA;
}
memcpy(buf, sat->sat_msgs[sat->shead], 40);
sat->shead = (sat->shead + 1) % SAT_CONCUR_MSG;
spin_unlock_irqrestore(&sat->lock, flags);
return 0;
}
static void msm_get_eaddr(u8 *e_addr, u32 *buffer)
{
e_addr[0] = (buffer[1] >> 24) & 0xff;
e_addr[1] = (buffer[1] >> 16) & 0xff;
e_addr[2] = (buffer[1] >> 8) & 0xff;
e_addr[3] = buffer[1] & 0xff;
e_addr[4] = (buffer[0] >> 24) & 0xff;
e_addr[5] = (buffer[0] >> 16) & 0xff;
}
static bool msm_is_sat_dev(u8 *e_addr)
{
if (e_addr[5] == QC_MFGID_LSB && e_addr[4] == QC_MFGID_MSB &&
e_addr[2] != QC_CHIPID_SL &&
(e_addr[1] == QC_DEVID_SAT1 || e_addr[1] == QC_DEVID_SAT2))
return true;
return false;
}
static struct msm_slim_sat *addr_to_sat(struct msm_slim_ctrl *dev, u8 laddr)
{
struct msm_slim_sat *sat = NULL;
int i = 0;
while (!sat && i < dev->nsats) {
if (laddr == dev->satd[i]->satcl.laddr)
sat = dev->satd[i];
i++;
}
return sat;
}
static irqreturn_t msm_slim_interrupt(int irq, void *d)
{
struct msm_slim_ctrl *dev = d;
u32 pstat;
u32 stat = readl_relaxed(dev->base + MGR_INT_STAT);
if (stat & MGR_INT_TX_MSG_SENT || stat & MGR_INT_TX_NACKED_2) {
if (stat & MGR_INT_TX_MSG_SENT)
writel_relaxed(MGR_INT_TX_MSG_SENT,
dev->base + MGR_INT_CLR);
else {
u32 mgr_stat = readl_relaxed(dev->base + MGR_STATUS);
u32 mgr_ie_stat = readl_relaxed(dev->base +
MGR_IE_STAT);
u32 frm_stat = readl_relaxed(dev->base + FRM_STAT);
u32 frm_cfg = readl_relaxed(dev->base + FRM_CFG);
u32 frm_intr_stat = readl_relaxed(dev->base +
FRM_INT_STAT);
u32 frm_ie_stat = readl_relaxed(dev->base +
FRM_IE_STAT);
u32 intf_stat = readl_relaxed(dev->base + INTF_STAT);
u32 intf_intr_stat = readl_relaxed(dev->base +
INTF_INT_STAT);
u32 intf_ie_stat = readl_relaxed(dev->base +
INTF_IE_STAT);
writel_relaxed(MGR_INT_TX_NACKED_2,
dev->base + MGR_INT_CLR);
pr_err("TX Nack MGR dump:int_stat:0x%x, mgr_stat:0x%x",
stat, mgr_stat);
pr_err("TX Nack MGR dump:ie_stat:0x%x", mgr_ie_stat);
pr_err("TX Nack FRM dump:int_stat:0x%x, frm_stat:0x%x",
frm_intr_stat, frm_stat);
pr_err("TX Nack FRM dump:frm_cfg:0x%x, ie_stat:0x%x",
frm_cfg, frm_ie_stat);
pr_err("TX Nack INTF dump:intr_st:0x%x, intf_stat:0x%x",
intf_intr_stat, intf_stat);
pr_err("TX Nack INTF dump:ie_stat:0x%x", intf_ie_stat);
dev->err = -EIO;
}
/*
* Guarantee that interrupt clear bit write goes through before
* signalling completion/exiting ISR
*/
mb();
msm_slim_manage_tx_msgq(dev, false, NULL);
}
if (stat & MGR_INT_RX_MSG_RCVD) {
u32 rx_buf[10];
u32 mc, mt;
u8 len, i;
rx_buf[0] = readl_relaxed(dev->base + MGR_RX_MSG);
len = rx_buf[0] & 0x1F;
for (i = 1; i < ((len + 3) >> 2); i++) {
rx_buf[i] = readl_relaxed(dev->base + MGR_RX_MSG +
(4 * i));
dev_dbg(dev->dev, "reading data: %x\n", rx_buf[i]);
}
mt = (rx_buf[0] >> 5) & 0x7;
mc = (rx_buf[0] >> 8) & 0xff;
dev_dbg(dev->dev, "MC: %x, MT: %x\n", mc, mt);
if (mt == SLIM_MSG_MT_DEST_REFERRED_USER ||
mt == SLIM_MSG_MT_SRC_REFERRED_USER) {
u8 laddr = (u8)((rx_buf[0] >> 16) & 0xFF);
struct msm_slim_sat *sat = addr_to_sat(dev, laddr);
if (sat)
msm_sat_enqueue(sat, rx_buf, len);
else
dev_err(dev->dev, "unknown sat:%d message",
laddr);
writel_relaxed(MGR_INT_RX_MSG_RCVD,
dev->base + MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through before
* queuing work
*/
mb();
if (sat)
queue_work(sat->wq, &sat->wd);
} else if (mt == SLIM_MSG_MT_CORE &&
mc == SLIM_MSG_MC_REPORT_PRESENT) {
u8 e_addr[6];
msm_get_eaddr(e_addr, rx_buf);
msm_slim_rx_enqueue(dev, rx_buf, len);
writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base +
MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through
* before signalling completion
*/
mb();
complete(&dev->rx_msgq_notify);
} else if (mt == SLIM_MSG_MT_CORE &&
mc == SLIM_MSG_MC_REPORT_ABSENT) {
writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base +
MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through
* before signalling completion
*/
mb();
complete(&dev->rx_msgq_notify);
} else if (mc == SLIM_MSG_MC_REPLY_INFORMATION ||
mc == SLIM_MSG_MC_REPLY_VALUE) {
msm_slim_rx_enqueue(dev, rx_buf, len);
writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base +
MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through
* before signalling completion
*/
mb();
complete(&dev->rx_msgq_notify);
} else if (mc == SLIM_MSG_MC_REPORT_INFORMATION) {
u8 *buf = (u8 *)rx_buf;
u8 l_addr = buf[2];
u16 ele = (u16)buf[4] << 4;
ele |= ((buf[3] & 0xf0) >> 4);
dev_err(dev->dev, "Slim-dev:%d report inf element:0x%x",
l_addr, ele);
for (i = 0; i < len - 5; i++)
dev_err(dev->dev, "offset:0x%x:bit mask:%x",
i, buf[i+5]);
writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base +
MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through
* before exiting
*/
mb();
} else {
dev_err(dev->dev, "Unexpected MC,%x MT:%x, len:%d",
mc, mt, len);
for (i = 0; i < ((len + 3) >> 2); i++)
dev_err(dev->dev, "error msg: %x", rx_buf[i]);
writel_relaxed(MGR_INT_RX_MSG_RCVD, dev->base +
MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through
* before exiting
*/
mb();
}
}
if (stat & MGR_INT_RECFG_DONE) {
writel_relaxed(MGR_INT_RECFG_DONE, dev->base + MGR_INT_CLR);
/*
* Guarantee that CLR bit write goes through
* before exiting ISR
*/
mb();
complete(&dev->reconf);
}
pstat = readl_relaxed(PGD_THIS_EE(PGD_PORT_INT_ST_EEn, dev->ver));
if (pstat != 0) {
return msm_slim_port_irq_handler(dev, pstat);
}
return IRQ_HANDLED;
}
static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn)
{
DECLARE_COMPLETION_ONSTACK(done);
struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
u32 *pbuf;
u8 *puc;
int timeout;
int msgv = -1;
u8 la = txn->la;
u8 mc = (u8)(txn->mc & 0xFF);
/*
* Voting for runtime PM: Slimbus has 2 possible use cases:
* 1. messaging
* 2. Data channels
* Messaging case goes through messaging slots and data channels
* use their own slots
* This "get" votes for messaging bandwidth
*/
if (!(txn->mc & SLIM_MSG_CLK_PAUSE_SEQ_FLG))
msgv = msm_slim_get_ctrl(dev);
if (msgv >= 0)
dev->state = MSM_CTRL_AWAKE;
mutex_lock(&dev->tx_lock);
if (dev->state == MSM_CTRL_ASLEEP ||
((!(txn->mc & SLIM_MSG_CLK_PAUSE_SEQ_FLG)) &&
dev->state == MSM_CTRL_IDLE)) {
dev_err(dev->dev, "runtime or system PM suspended state");
mutex_unlock(&dev->tx_lock);
if (msgv >= 0)
msm_slim_put_ctrl(dev);
return -EBUSY;
}
if (txn->mt == SLIM_MSG_MT_CORE &&
mc == SLIM_MSG_MC_BEGIN_RECONFIGURATION) {
if (dev->reconf_busy) {
wait_for_completion(&dev->reconf);
dev->reconf_busy = false;
}
/* This "get" votes for data channels */
if (dev->ctrl.sched.usedslots != 0 &&
!dev->chan_active) {
int chv = msm_slim_get_ctrl(dev);
if (chv >= 0)
dev->chan_active = true;
}
}
txn->rl--;
pbuf = msm_get_msg_buf(dev, txn->rl, &done);
dev->err = 0;
if (txn->dt == SLIM_MSG_DEST_ENUMADDR) {
mutex_unlock(&dev->tx_lock);
if (msgv >= 0)
msm_slim_put_ctrl(dev);
return -EPROTONOSUPPORT;
}
if (txn->mt == SLIM_MSG_MT_CORE && txn->la == 0xFF &&
(mc == SLIM_MSG_MC_CONNECT_SOURCE ||
mc == SLIM_MSG_MC_CONNECT_SINK ||
mc == SLIM_MSG_MC_DISCONNECT_PORT))
la = dev->pgdla;
if (txn->dt == SLIM_MSG_DEST_LOGICALADDR)
*pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, mc, 0, la);
else
*pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, mc, 1, la);
if (txn->dt == SLIM_MSG_DEST_LOGICALADDR)
puc = ((u8 *)pbuf) + 3;
else
puc = ((u8 *)pbuf) + 2;
if (txn->rbuf)
*(puc++) = txn->tid;
if ((txn->mt == SLIM_MSG_MT_CORE) &&
((mc >= SLIM_MSG_MC_REQUEST_INFORMATION &&
mc <= SLIM_MSG_MC_REPORT_INFORMATION) ||
(mc >= SLIM_MSG_MC_REQUEST_VALUE &&
mc <= SLIM_MSG_MC_CHANGE_VALUE))) {
*(puc++) = (txn->ec & 0xFF);
*(puc++) = (txn->ec >> 8)&0xFF;
}
if (txn->wbuf)
memcpy(puc, txn->wbuf, txn->len);
if (txn->mt == SLIM_MSG_MT_CORE && txn->la == 0xFF &&
(mc == SLIM_MSG_MC_CONNECT_SOURCE ||
mc == SLIM_MSG_MC_CONNECT_SINK ||
mc == SLIM_MSG_MC_DISCONNECT_PORT)) {
if (mc != SLIM_MSG_MC_DISCONNECT_PORT)
dev->err = msm_slim_connect_pipe_port(dev, *puc);
else {
/*
* Remove channel disconnects master-side ports from
* channel. No need to send that again on the bus
* Only disable port
*/
writel_relaxed(0, PGD_PORT(PGD_PORT_CFGn,
dev->pipes[*puc].port_b, dev->ver));
mutex_unlock(&dev->tx_lock);
if (msgv >= 0)
msm_slim_put_ctrl(dev);
return 0;
}
if (dev->err) {
dev_err(dev->dev, "pipe-port connect err:%d", dev->err);
mutex_unlock(&dev->tx_lock);
if (msgv >= 0)
msm_slim_put_ctrl(dev);
return dev->err;
}
*(puc) = (u8)dev->pipes[*puc].port_b;
}
if (txn->mt == SLIM_MSG_MT_CORE &&
mc == SLIM_MSG_MC_BEGIN_RECONFIGURATION)
dev->reconf_busy = true;
msm_send_msg_buf(dev, pbuf, txn->rl, MGR_TX_MSG);
timeout = wait_for_completion_timeout(&done, HZ);
if (mc == SLIM_MSG_MC_RECONFIGURE_NOW) {
if ((txn->mc == (SLIM_MSG_MC_RECONFIGURE_NOW |
SLIM_MSG_CLK_PAUSE_SEQ_FLG)) &&
timeout) {
timeout = wait_for_completion_timeout(&dev->reconf, HZ);
dev->reconf_busy = false;
if (timeout) {
clk_disable_unprepare(dev->rclk);
disable_irq(dev->irq);
}
}
if ((txn->mc == (SLIM_MSG_MC_RECONFIGURE_NOW |
SLIM_MSG_CLK_PAUSE_SEQ_FLG)) &&
!timeout) {
dev->reconf_busy = false;
dev_err(dev->dev, "clock pause failed");
mutex_unlock(&dev->tx_lock);
return -ETIMEDOUT;
}
if (txn->mt == SLIM_MSG_MT_CORE &&
txn->mc == SLIM_MSG_MC_RECONFIGURE_NOW) {
if (dev->ctrl.sched.usedslots == 0 &&
dev->chan_active) {
dev->chan_active = false;
msm_slim_put_ctrl(dev);
}
}
}
mutex_unlock(&dev->tx_lock);
if (msgv >= 0)
msm_slim_put_ctrl(dev);
if (!timeout)
dev_err(dev->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc,
txn->mt);
return timeout ? dev->err : -ETIMEDOUT;
}
static void msm_slim_wait_retry(struct msm_slim_ctrl *dev)
{
int msec_per_frm = 0;
int sfr_per_sec;
/* Wait for 1 superframe, or default time and then retry */
sfr_per_sec = dev->framer.superfreq /
(1 << (SLIM_MAX_CLK_GEAR - dev->ctrl.clkgear));
if (sfr_per_sec)
msec_per_frm = MSEC_PER_SEC / sfr_per_sec;
if (msec_per_frm < DEF_RETRY_MS)
msec_per_frm = DEF_RETRY_MS;
msleep(msec_per_frm);
}
static int msm_set_laddr(struct slim_controller *ctrl, const u8 *ea,
u8 elen, u8 laddr)
{
struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
struct completion done;
int timeout, ret, retries = 0;
u32 *buf;
retry_laddr:
init_completion(&done);
mutex_lock(&dev->tx_lock);
buf = msm_get_msg_buf(dev, 9, &done);
if (buf == NULL)
return -ENOMEM;
buf[0] = SLIM_MSG_ASM_FIRST_WORD(9, SLIM_MSG_MT_CORE,
SLIM_MSG_MC_ASSIGN_LOGICAL_ADDRESS,
SLIM_MSG_DEST_LOGICALADDR,
ea[5] | ea[4] << 8);
buf[1] = ea[3] | (ea[2] << 8) | (ea[1] << 16) | (ea[0] << 24);
buf[2] = laddr;
ret = msm_send_msg_buf(dev, buf, 9, MGR_TX_MSG);
timeout = wait_for_completion_timeout(&done, HZ);
if (!timeout)
dev->err = -ETIMEDOUT;
if (dev->err) {
ret = dev->err;
dev->err = 0;
}
mutex_unlock(&dev->tx_lock);
if (ret) {
pr_err("set LADDR:0x%x failed:ret:%d, retrying", laddr, ret);
if (retries < INIT_MX_RETRIES) {
msm_slim_wait_retry(dev);
retries++;
goto retry_laddr;
} else {
pr_err("set LADDR failed after retrying:ret:%d", ret);
}
}
return ret;
}
static int msm_clk_pause_wakeup(struct slim_controller *ctrl)
{
struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl);
enable_irq(dev->irq);
clk_prepare_enable(dev->rclk);
writel_relaxed(1, dev->base + FRM_WAKEUP);
/* Make sure framer wakeup write goes through before exiting function */
mb();
/*
* Workaround: Currently, slave is reporting lost-sync messages
* after slimbus comes out of clock pause.
* Transaction with slave fail before slave reports that message
* Give some time for that report to come
* Slimbus wakes up in clock gear 10 at 24.576MHz. With each superframe
* being 250 usecs, we wait for 20 superframes here to ensure
* we get the message
*/
usleep_range(5000, 5000);
return 0;
}
static int msm_sat_define_ch(struct msm_slim_sat *sat, u8 *buf, u8 len, u8 mc)
{
struct msm_slim_ctrl *dev = sat->dev;
enum slim_ch_control oper;
int i;
int ret = 0;
if (mc == SLIM_USR_MC_CHAN_CTRL) {
for (i = 0; i < sat->nsatch; i++) {
if (buf[5] == sat->satch[i].chan)
break;
}
if (i >= sat->nsatch)
return -ENOTCONN;
oper = ((buf[3] & 0xC0) >> 6);
/* part of grp. activating/removing 1 will take care of rest */
ret = slim_control_ch(&sat->satcl, sat->satch[i].chanh, oper,
false);
if (!ret) {
for (i = 5; i < len; i++) {
int j;
for (j = 0; j < sat->nsatch; j++) {
if (buf[i] == sat->satch[j].chan) {
if (oper == SLIM_CH_REMOVE)
sat->satch[j].req_rem++;
else
sat->satch[j].req_def++;
break;
}
}
}
}
} else {
u16 chh[40];
struct slim_ch prop;
u32 exp;
u16 *grph = NULL;
u8 coeff, cc;
u8 prrate = buf[6];
if (len <= 8)
return -EINVAL;
for (i = 8; i < len; i++) {
int j = 0;
for (j = 0; j < sat->nsatch; j++) {
if (sat->satch[j].chan == buf[i]) {
chh[i - 8] = sat->satch[j].chanh;
break;
}
}
if (j < sat->nsatch) {
u16 dummy;
ret = slim_query_ch(&sat->satcl, buf[i],
&dummy);
if (ret)
return ret;
if (mc == SLIM_USR_MC_DEF_ACT_CHAN)
sat->satch[j].req_def++;
/* First channel in group from satellite */
if (i == 8)
grph = &sat->satch[j].chanh;
continue;
}
if (sat->nsatch >= MSM_MAX_SATCH)
return -EXFULL;
ret = slim_query_ch(&sat->satcl, buf[i], &chh[i - 8]);
if (ret)
return ret;
sat->satch[j].chan = buf[i];
sat->satch[j].chanh = chh[i - 8];
if (mc == SLIM_USR_MC_DEF_ACT_CHAN)
sat->satch[j].req_def++;
if (i == 8)
grph = &sat->satch[j].chanh;
sat->nsatch++;
}
prop.dataf = (enum slim_ch_dataf)((buf[3] & 0xE0) >> 5);
prop.auxf = (enum slim_ch_auxf)((buf[4] & 0xC0) >> 5);
prop.baser = SLIM_RATE_4000HZ;
if (prrate & 0x8)
prop.baser = SLIM_RATE_11025HZ;
else
prop.baser = SLIM_RATE_4000HZ;
prop.prot = (enum slim_ch_proto)(buf[5] & 0x0F);
prop.sampleszbits = (buf[4] & 0x1F)*SLIM_CL_PER_SL;
exp = (u32)((buf[5] & 0xF0) >> 4);
coeff = (buf[4] & 0x20) >> 5;
cc = (coeff ? 3 : 1);
prop.ratem = cc * (1 << exp);
if (i > 9)
ret = slim_define_ch(&sat->satcl, &prop, chh, len - 8,
true, &chh[0]);
else
ret = slim_define_ch(&sat->satcl, &prop,
chh, 1, true, &chh[0]);
dev_dbg(dev->dev, "define sat grp returned:%d", ret);
if (ret)
return ret;
else if (grph)
*grph = chh[0];
/* part of group so activating 1 will take care of rest */
if (mc == SLIM_USR_MC_DEF_ACT_CHAN)
ret = slim_control_ch(&sat->satcl,
chh[0],
SLIM_CH_ACTIVATE, false);
}
return ret;
}
static void msm_slim_rxwq(struct msm_slim_ctrl *dev)
{
u8 buf[40];
u8 mc, mt, len;
int i, ret;
if ((msm_slim_rx_dequeue(dev, (u8 *)buf)) != -ENODATA) {
len = buf[0] & 0x1F;
mt = (buf[0] >> 5) & 0x7;
mc = buf[1];
if (mt == SLIM_MSG_MT_CORE &&
mc == SLIM_MSG_MC_REPORT_PRESENT) {
u8 laddr;
u8 e_addr[6];
for (i = 0; i < 6; i++)
e_addr[i] = buf[7-i];
ret = slim_assign_laddr(&dev->ctrl, e_addr, 6, &laddr,
false);
/* Is this Qualcomm ported generic device? */
if (!ret && e_addr[5] == QC_MFGID_LSB &&
e_addr[4] == QC_MFGID_MSB &&
e_addr[1] == QC_DEVID_PGD &&
e_addr[2] != QC_CHIPID_SL)
dev->pgdla = laddr;
if (!ret && !pm_runtime_enabled(dev->dev) &&
laddr == (QC_MSM_DEVS - 1))
pm_runtime_enable(dev->dev);
if (!ret && msm_is_sat_dev(e_addr)) {
struct msm_slim_sat *sat = addr_to_sat(dev,
laddr);
if (!sat)
sat = msm_slim_alloc_sat(dev);
if (!sat)
return;
sat->satcl.laddr = laddr;
msm_sat_enqueue(sat, (u32 *)buf, len);
queue_work(sat->wq, &sat->wd);
}
if (ret)
pr_err("assign laddr failed, error:%d", ret);
} else if (mc == SLIM_MSG_MC_REPLY_INFORMATION ||
mc == SLIM_MSG_MC_REPLY_VALUE) {
u8 tid = buf[3];
dev_dbg(dev->dev, "tid:%d, len:%d\n", tid, len - 4);
slim_msg_response(&dev->ctrl, &buf[4], tid,
len - 4);
pm_runtime_mark_last_busy(dev->dev);
} else if (mc == SLIM_MSG_MC_REPORT_INFORMATION) {
u8 l_addr = buf[2];
u16 ele = (u16)buf[4] << 4;
ele |= ((buf[3] & 0xf0) >> 4);
dev_err(dev->dev, "Slim-dev:%d report inf element:0x%x",
l_addr, ele);
for (i = 0; i < len - 5; i++)
dev_err(dev->dev, "offset:0x%x:bit mask:%x",
i, buf[i+5]);
} else {
dev_err(dev->dev, "unexpected message:mc:%x, mt:%x",
mc, mt);
for (i = 0; i < len; i++)
dev_err(dev->dev, "error msg: %x", buf[i]);
}
} else
dev_err(dev->dev, "rxwq called and no dequeue");
}
static void slim_sat_rxprocess(struct work_struct *work)
{
struct msm_slim_sat *sat = container_of(work, struct msm_slim_sat, wd);
struct msm_slim_ctrl *dev = sat->dev;
u8 buf[40];
while ((msm_sat_dequeue(sat, buf)) != -ENODATA) {
struct slim_msg_txn txn;
u8 len, mc, mt;
u32 bw_sl;
int ret = 0;
int satv = -1;
bool gen_ack = false;
u8 tid;
u8 wbuf[8];
int i, retries = 0;
txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER;
txn.dt = SLIM_MSG_DEST_LOGICALADDR;
txn.ec = 0;
txn.rbuf = NULL;
txn.la = sat->satcl.laddr;
/* satellite handling */
len = buf[0] & 0x1F;
mc = buf[1];
mt = (buf[0] >> 5) & 0x7;
if (mt == SLIM_MSG_MT_CORE &&
mc == SLIM_MSG_MC_REPORT_PRESENT) {
u8 e_addr[6];
for (i = 0; i < 6; i++)
e_addr[i] = buf[7-i];
if (pm_runtime_enabled(dev->dev)) {
satv = msm_slim_get_ctrl(dev);
if (satv >= 0)
sat->pending_capability = true;
}
/*
* Since capability message is already sent, present
* message will indicate subsystem hosting this
* satellite has restarted.
* Remove all active channels of this satellite
* when this is detected
*/
if (sat->sent_capability) {
for (i = 0; i < sat->nsatch; i++) {
if (sat->satch[i].reconf) {
pr_err("SSR, sat:%d, rm ch:%d",
sat->satcl.laddr,
sat->satch[i].chan);
slim_control_ch(&sat->satcl,
sat->satch[i].chanh,
SLIM_CH_REMOVE, true);
slim_dealloc_ch(&sat->satcl,
sat->satch[i].chanh);
sat->satch[i].reconf = false;
}
}
}
} else if (mt != SLIM_MSG_MT_CORE &&
mc != SLIM_MSG_MC_REPORT_PRESENT) {
satv = msm_slim_get_ctrl(dev);
}
switch (mc) {
case SLIM_MSG_MC_REPORT_PRESENT:
/* Remove runtime_pm vote once satellite acks */
if (mt != SLIM_MSG_MT_CORE) {
if (pm_runtime_enabled(dev->dev) &&
sat->pending_capability) {
msm_slim_put_ctrl(dev);
sat->pending_capability = false;
}
continue;
}
/* send a Manager capability msg */
if (sat->sent_capability) {
if (mt == SLIM_MSG_MT_CORE)
goto send_capability;
else
continue;
}
ret = slim_add_device(&dev->ctrl, &sat->satcl);
if (ret) {
dev_err(dev->dev,
"Satellite-init failed");
continue;
}
/* Satellite-channels */
sat->satch = kzalloc(MSM_MAX_SATCH *
sizeof(struct msm_sat_chan),
GFP_KERNEL);
send_capability:
txn.mc = SLIM_USR_MC_MASTER_CAPABILITY;
txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER;
txn.la = sat->satcl.laddr;
txn.rl = 8;
wbuf[0] = SAT_MAGIC_LSB;
wbuf[1] = SAT_MAGIC_MSB;
wbuf[2] = SAT_MSG_VER;
wbuf[3] = SAT_MSG_PROT;
txn.wbuf = wbuf;
txn.len = 4;
ret = msm_xfer_msg(&dev->ctrl, &txn);
if (ret) {
pr_err("capability for:0x%x fail:%d, retry:%d",
sat->satcl.laddr, ret, retries);
if (retries < INIT_MX_RETRIES) {
msm_slim_wait_retry(dev);
retries++;
goto send_capability;
} else {
pr_err("failed after all retries:%d",
ret);
}
} else {
sat->sent_capability = true;
}
break;
case SLIM_USR_MC_ADDR_QUERY:
memcpy(&wbuf[1], &buf[4], 6);
ret = slim_get_logical_addr(&sat->satcl,
&wbuf[1], 6, &wbuf[7]);
if (ret)
memset(&wbuf[1], 0, 6);
wbuf[0] = buf[3];
txn.mc = SLIM_USR_MC_ADDR_REPLY;
txn.rl = 12;
txn.len = 8;
txn.wbuf = wbuf;
msm_xfer_msg(&dev->ctrl, &txn);
break;
case SLIM_USR_MC_DEFINE_CHAN:
case SLIM_USR_MC_DEF_ACT_CHAN:
case SLIM_USR_MC_CHAN_CTRL:
if (mc != SLIM_USR_MC_CHAN_CTRL)
tid = buf[7];
else
tid = buf[4];
gen_ack = true;
ret = msm_sat_define_ch(sat, buf, len, mc);
if (ret) {
dev_err(dev->dev,
"SAT define_ch returned:%d",
ret);
}
if (!sat->pending_reconf) {
int chv = msm_slim_get_ctrl(dev);
if (chv >= 0)
sat->pending_reconf = true;
}
break;
case SLIM_USR_MC_RECONFIG_NOW:
tid = buf[3];
gen_ack = true;
ret = slim_reconfigure_now(&sat->satcl);
for (i = 0; i < sat->nsatch; i++) {
struct msm_sat_chan *sch = &sat->satch[i];
if (sch->req_rem && sch->reconf) {
if (!ret) {
slim_dealloc_ch(&sat->satcl,
sch->chanh);
sch->reconf = false;
}
sch->req_rem--;
} else if (sch->req_def) {
if (ret)
slim_dealloc_ch(&sat->satcl,
sch->chanh);
else
sch->reconf = true;
sch->req_def--;
}
}
if (sat->pending_reconf) {
msm_slim_put_ctrl(dev);
sat->pending_reconf = false;
}
break;
case SLIM_USR_MC_REQ_BW:
/* what we get is in SLOTS */
bw_sl = (u32)buf[4] << 3 |
((buf[3] & 0xE0) >> 5);
sat->satcl.pending_msgsl = bw_sl;
tid = buf[5];
gen_ack = true;
break;
case SLIM_USR_MC_CONNECT_SRC:
case SLIM_USR_MC_CONNECT_SINK:
if (mc == SLIM_USR_MC_CONNECT_SRC)
txn.mc = SLIM_MSG_MC_CONNECT_SOURCE;
else
txn.mc = SLIM_MSG_MC_CONNECT_SINK;
wbuf[0] = buf[4] & 0x1F;
wbuf[1] = buf[5];
tid = buf[6];
txn.la = buf[3];
txn.mt = SLIM_MSG_MT_CORE;
txn.rl = 6;
txn.len = 2;
txn.wbuf = wbuf;
gen_ack = true;
ret = msm_xfer_msg(&dev->ctrl, &txn);
break;
case SLIM_USR_MC_DISCONNECT_PORT:
txn.mc = SLIM_MSG_MC_DISCONNECT_PORT;
wbuf[0] = buf[4] & 0x1F;
tid = buf[5];
txn.la = buf[3];
txn.rl = 5;
txn.len = 1;
txn.mt = SLIM_MSG_MT_CORE;
txn.wbuf = wbuf;
gen_ack = true;
ret = msm_xfer_msg(&dev->ctrl, &txn);
break;
case SLIM_MSG_MC_REPORT_ABSENT:
dev_info(dev->dev, "Received Report Absent Message\n");
break;
default:
break;
}
if (!gen_ack) {
if (mc != SLIM_MSG_MC_REPORT_PRESENT && satv >= 0)
msm_slim_put_ctrl(dev);
continue;
}
wbuf[0] = tid;
if (!ret)
wbuf[1] = MSM_SAT_SUCCSS;
else
wbuf[1] = 0;
txn.mc = SLIM_USR_MC_GENERIC_ACK;
txn.la = sat->satcl.laddr;
txn.rl = 6;
txn.len = 2;
txn.wbuf = wbuf;
txn.mt = SLIM_MSG_MT_SRC_REFERRED_USER;
msm_xfer_msg(&dev->ctrl, &txn);
if (satv >= 0)
msm_slim_put_ctrl(dev);
}
}
static struct msm_slim_sat *msm_slim_alloc_sat(struct msm_slim_ctrl *dev)
{
struct msm_slim_sat *sat;
char *name;
if (dev->nsats >= MSM_MAX_NSATS)
return NULL;
sat = kzalloc(sizeof(struct msm_slim_sat), GFP_KERNEL);
if (!sat) {
dev_err(dev->dev, "no memory for satellite");
return NULL;
}
name = kzalloc(SLIMBUS_NAME_SIZE, GFP_KERNEL);
if (!name) {
dev_err(dev->dev, "no memory for satellite name");
kfree(sat);
return NULL;
}
dev->satd[dev->nsats] = sat;
sat->dev = dev;
snprintf(name, SLIMBUS_NAME_SIZE, "msm_sat%d", dev->nsats);
sat->satcl.name = name;
spin_lock_init(&sat->lock);
INIT_WORK(&sat->wd, slim_sat_rxprocess);