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
|
/*
* Copyright (C) 2010 Samsung Electronics.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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/gpio.h>
#include <linux/time.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/wakelock.h>
#include <linux/delay.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/vmalloc.h>
#include <linux/platform_device.h>
#include <linux/kallsyms.h>
#include <linux/suspend.h>
#include <plat/gpio-cfg.h>
#include <linux/module.h>
#include <linux/debugfs.h>
#include <linux/mipi-lli.h>
#include "modem_prj.h"
#include "modem_utils.h"
#include "link_device_memory.h"
static int sleep_timeout = 100;
module_param(sleep_timeout, int, S_IRUGO);
MODULE_PARM_DESC(sleep_timeout, "LLI sleep timeout");
static int pm_enable = 1;
module_param(pm_enable, int, S_IRUGO);
MODULE_PARM_DESC(pm_enable, "LLI PM enable");
static inline void send_ap2cp_irq(struct mem_link_device *mld, u16 mask)
{
#ifdef CONFIG_EXYNOS_MIPI_LLI_GPIO_SIDEBAND
int val;
unsigned long flags;
spin_lock_irqsave(&mld->sig_lock, flags);
mipi_lli_send_interrupt(mask);
/* invert previous signal level */
val = gpio_get_value(mld->gpio_ipc_int2cp);
val = 1 - val;
gpio_set_value(mld->gpio_ipc_int2cp, val);
trace_send_sig(mask, val);
spin_unlock_irqrestore(&mld->sig_lock, flags);
#else
mipi_lli_send_interrupt(mask);
#endif
}
#ifdef CONFIG_LINK_POWER_MANAGEMENT
static bool forbid_cp_sleep_wait(struct mem_link_device *mld, int flag)
{
long res;
if (mld->forbid_cp_sleep)
mld->forbid_cp_sleep(mld, flag);
#ifndef CONFIG_SEC_MODEM_XMM7260_CAT6
if (atomic_read(&mld->cp_boot_done)) {
#endif
/* As of now, tx path of iosm message should always guarantee
* process context. We don't have to care rx path because cp
* might try to mount lli i/f before sending data. */
res = wait_event_interruptible_timeout(mld->wq,
mld->link_active(mld), msecs_to_jiffies(5000));
switch (res) {
case 0:
mif_err("timeout for link active event\n");
#ifdef CONFIG_SEC_MODEM_XMM7260_CAT6
modemctl_notify_event(MDM_CRASH_BY_IOSM);
#endif
return false;
case -ERESTARTSYS:
mif_info("woken by a signal\n");
return false;
default:
mif_info("got link active event\n");
}
#ifndef CONFIG_SEC_MODEM_XMM7260_CAT6
}
#endif
return true;
}
#ifdef CONFIG_LINK_POWER_MANAGEMENT_WITH_FSM
/**
@brief forbid CP from going to sleep
Wakes up a CP if it can sleep and increases the "ref_cnt" counter in the
mem_link_device instance.
@param mld the pointer to a mem_link_device instance
@remark CAUTION!!! permit_cp_sleep() MUST be invoked after
forbid_cp_sleep() success to decrease the "ref_cnt" counter.
*/
static void forbid_cp_sleep(struct mem_link_device *mld, int flag)
{
struct modem_link_pm *pm = &mld->link_dev.pm;
atomic_set(&pm->ref_cnt, atomic_read(&pm->ref_cnt) | flag);
mif_debug("ref_cnt %d\n", atomic_read(&pm->ref_cnt));
if (atomic_read(&pm->ref_cnt) > 1)
return;
if (pm->request_hold)
pm->request_hold(pm);
}
/**
@brief permit CP to go sleep
Decreases the "ref_cnt" counter in the mem_link_device instance if it can go
sleep and allows CP to go sleep only if the value of "ref_cnt" counter is less
than or equal to 0.
@param mld the pointer to a mem_link_device instance
@remark MUST be invoked after forbid_cp_sleep() success to decrease the
"ref_cnt" counter.
*/
static void permit_cp_sleep(struct mem_link_device *mld, int flag)
{
struct modem_link_pm *pm = &mld->link_dev.pm;
atomic_set(&pm->ref_cnt, atomic_read(&pm->ref_cnt) & ~flag);
mif_debug("ref_cnt %d\n", atomic_read(&pm->ref_cnt));
if (atomic_read(&pm->ref_cnt) > 0)
return;
if (pm->release_hold)
pm->release_hold(pm);
}
static bool check_link_status(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_ctl *mc = ld->mc;
struct modem_link_pm *pm = &ld->pm;
if (gpio_get_value(mld->gpio_cp_status) == 0)
return false;
if (mipi_lli_get_link_status() != LLI_MOUNTED)
return false;
if (cp_online(mc))
return pm->link_active ? pm->link_active(pm) : true;
return true;
}
static void pm_fail_cb(struct modem_link_pm *pm)
{
mipi_lli_debug_info();
modemctl_notify_event(MDM_CRASH_PM_FAIL);
}
static void pm_cp_fail_cb(struct modem_link_pm *pm)
{
struct link_device *ld = pm_to_link_device(pm);
struct mem_link_device *mld = ld_to_mem_link_device(ld);
struct modem_ctl *mc = ld->mc;
struct io_device *iod = mc->iod;
unsigned long flags;
mipi_lli_debug_info();
spin_lock_irqsave(&mc->lock, flags);
if (cp_online(mc)) {
spin_unlock_irqrestore(&mc->lock, flags);
if (mld->stop_pm)
mld->stop_pm(mld);
modemctl_notify_event(MDM_CRASH_PM_CP_FAIL);
return;
}
if (cp_booting(mc)) {
iod->modem_state_changed(iod, STATE_OFFLINE);
ld->reset(ld);
spin_unlock_irqrestore(&mc->lock, flags);
return;
}
spin_unlock_irqrestore(&mc->lock, flags);
}
static void start_pm(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_link_pm *pm = &ld->pm;
if (!pm->start)
return;
if (pm_enable) {
if (mld->iosm)
#ifdef CONFIG_SEC_MODEM_XMM7260_CAT6
pm->start(pm, PM_EVENT_NO_EVENT);
#else
pm->start(pm, PM_EVENT_CP_BOOTING);
#endif
else
pm->start(pm, PM_EVENT_CP_BOOTING);
} else {
pm->start(pm, PM_EVENT_LOCK_ON);
}
}
static void stop_pm(struct mem_link_device *mld)
{
struct modem_link_pm *pm = &mld->link_dev.pm;
if (pm->stop)
pm->stop(pm);
}
static int init_pm(struct mem_link_device *mld)
{
struct link_device *ld = &mld->link_dev;
struct modem_link_pm *pm = &ld->pm;
struct link_pm_svc *pm_svc;
int ret;
spin_lock_init(&mld->sig_lock);
atomic_set(&pm->ref_cnt, 0);
pm_svc = NULL;
ret = init_link_device_pm(ld, pm, pm_svc, pm_fail_cb, pm_cp_fail_cb);
if (ret < 0)
return ret;
return 0;
}
#else
static inline void change_irq_type(unsigned int irq, unsigned int value)
{
unsigned int type;
type = value ? IRQ_TYPE_LEVEL_LOW : IRQ_TYPE_LEVEL_HIGH;
irq_set_irq_type(irq, type);
}
/**
@brief finalize handling the PHONE_START command from CP
@param mld the pointer to a mem_link_device instance
*/
static void finalize_cp_start(struct mem_link_device *mld)
{
int ap_wakeup = gpio_get_value(mld->gpio_ap_wakeup);
int cp_status = gpio_get_value(mld->gpio_cp_status);
change_irq_type(mld->irq_ap_wakeup.num, ap_wakeup);
change_irq_type(mld->irq_cp_status.num, cp_status);
if (ap_wakeup) {
if (wake_lock_active(&mld->ap_wlock))
wake_lock(&mld->ap_wlock);
} else {
if (wake_lock_active(&mld->ap_wlock))
wake_unlock(&mld->ap_wlock);
}
if (cp_status) {
if (!wake_lock_active(&mld->ap_wlock))
wake_lock(&mld->cp_wlock);
} else {
if (wake_lock_active(&mld->ap_wlock))
wake_unlock(&mld->cp_wlock);
}
print_pm_status(mld);
}
static bool check_link_status(struct mem_link_device *mld)
{
if (mipi_lli_get_link_status() != LLI_MOUNTED)
return false;
if (gpio_get_value(mld->gpio_cp_status) == 0)
return false;
return true;
}
static void release_cp_wakeup(struct work_struct *ws)
{
struct mem_link_device *mld;
int i;
unsigned long flags;
mld = container_of(ws, struct mem_link_device, cp_sleep_dwork.work);
if (work_pending(&mld->cp_sleep_dwork.work))
cancel_delayed_work(&mld->cp_sleep_dwork);
spin_lock_irqsave(&mld->pm_lock, flags);
i = atomic_read(&mld->ref_cnt);
spin_unlock_irqrestore(&mld->pm_lock, flags);
if (i > 0)
goto reschedule;
if (gpio_get_value(mld->gpio_ap_wakeup) == 0) {
gpio_set_value(mld->gpio_cp_wakeup, 0);
gpio_set_value(mld->gpio_ap_status, 0);
}
#if 1
print_pm_status(mld);
#endif
return;
reschedule:
queue_delayed_work(system_nrt_wq, &mld->cp_sleep_dwork,
msecs_to_jiffies(sleep_timeout));
}
/**
@brief forbid CP from going to sleep
Wakes up a CP if it can sleep and increases the "ref_cnt" counter in the
mem_link_device instance.
@param mld the pointer to a mem_link_device instance
@remark CAUTION!!! permit_cp_sleep() MUST be invoked after
forbid_cp_sleep() success to decrease the "ref_cnt" counter.
*/
static void forbid_cp_sleep(struct mem_link_device *mld, int flag)
{
int ref_cnt;
unsigned long flags;
int cp_wakeup;
spin_lock_irqsave(&mld->pm_lock, flags);
if (work_pending(&mld->cp_sleep_dwork.work))
cancel_delayed_work(&mld->cp_sleep_dwork);
ref_cnt = atomic_inc_return(&mld->ref_cnt);
mif_debug("ref_cnt %d\n", ref_cnt);
cp_wakeup = gpio_get_value(mld->gpio_cp_wakeup);
gpio_set_value(mld->gpio_cp_wakeup, 1);
if (cp_wakeup == 0)
print_pm_status(mld);
spin_unlock_irqrestore(&mld->pm_lock, flags);
}
/**
@brief permit CP to go sleep
Decreases the "ref_cnt" counter in the mem_link_device instance if it can go
sleep and allows CP to go sleep only if the value of "ref_cnt" counter is less
than or equal to 0.
@param mld the pointer to a mem_link_device instance
@remark MUST be invoked after forbid_cp_sleep() success to decrease the
"ref_cnt" counter.
*/
static void permit_cp_sleep(struct mem_link_device *mld, int flag)
{
int ref_cnt;
unsigned long flags;
spin_lock_irqsave(&mld->pm_lock, flags);
ref_cnt = atomic_dec_return(&mld->ref_cnt);
if (ref_cnt > 0)
goto exit;
if (ref_cnt < 0) {
mif_info("WARNING! ref_cnt %d < 0\n", ref_cnt);
atomic_set(&mld->ref_cnt, 0);
}
exit:
spin_unlock_irqrestore(&mld->pm_lock, flags);
}
/**
@brief interrupt handler for a wakeup interrupt
1) Reads the interrupt value\n
2) Performs interrupt handling\n
@param irq the IRQ number
@param data the pointer to a data
*/
static irqreturn_t ap_wakeup_interrupt(int irq, void *data)
{
struct mem_link_device *mld = (struct mem_link_device *)data;
int ap_wakeup = gpio_get_value(mld->gpio_ap_wakeup);
int cp_wakeup = gpio_get_value(mld->gpio_cp_wakeup);
int cpu = raw_smp_processor_id();
change_irq_type(irq, ap_wakeup);
if (work_pending(&mld->cp_sleep_dwork.work))
cancel_delayed_work(&mld->cp_sleep_dwork);
if (ap_wakeup) {
mld->last_cp2ap_intr = cpu_clock(cpu);
if (!cp_wakeup)
gpio_set_value(mld->gpio_cp_wakeup, 1);
if (!wake_lock_active(&mld->ap_wlock))
wake_lock(&mld->ap_wlock);
if (mipi_lli_get_link_status() == LLI_UNMOUNTED)
mipi_lli_set_link_status(LLI_WAITFORMOUNT);
if (!mipi_lli_suspended())
gpio_set_value(mld->gpio_ap_status, 1);
} else {
if (wake_lock_active(&mld->ap_wlock))
wake_unlock(&mld->ap_wlock);
if (mipi_lli_get_link_status() & LLI_WAITFORMOUNT)
mipi_lli_set_link_status(LLI_UNMOUNTED);
queue_delayed_work(system_nrt_wq, &mld->cp_sleep_dwork,
msecs_to_jiffies(sleep_timeout));
}
print_pm_status(mld);
return IRQ_HANDLED;
}
static irqreturn_t cp_status_handler(int irq, void *data)
{
struct mem_link_device *mld = (struct mem_link_device *)data;
struct link_device *ld = &mld->link_dev;
struct modem_ctl *mc = ld->mc;
int cp_status = gpio_get_value(mld->gpio_cp_status);
unsigned long flags;
spin_lock_irqsave(&mld->pm_lock, flags);
change_irq_type(irq, cp_status);
if (!cp_online(mc))
goto exit;
if (cp_status) {
if (!wake_lock_active(&mld->cp_wlock))
wake_lock(&mld->cp_wlock);
} else {
gpio_set_value(mld->gpio_ap_status, 0);
if (wake_lock_active(&mld->cp_wlock))
wake_unlock(&mld->cp_wlock);
}
exit:
print_pm_status(mld);
spin_unlock_irqrestore(&mld->pm_lock, flags);
return IRQ_HANDLED;
}
static void start_pm(struct mem_link_device *mld)
{
if (pm_enable) {
int ap_wakeup = gpio_get_value(mld->gpio_ap_wakeup);
int cp_status = gpio_get_value(mld->gpio_cp_status);
print_pm_status(mld);
change_irq_type(mld->irq_ap_wakeup.num, ap_wakeup);
mif_enable_irq(&mld->irq_ap_wakeup);
change_irq_type(mld->irq_cp_status.num, cp_status);
mif_enable_irq(&mld->irq_cp_status);
} else {
wake_lock(&mld->ap_wlock);
}
}
static void stop_pm(struct mem_link_device *mld)
{
print_pm_status(mld);
mif_disable_irq(&mld->irq_ap_wakeup);
mif_disable_irq(&mld->irq_cp_status);
}
static int init_pm(struct mem_link_device *mld)
{
int err;
unsigned int gpio;
unsigned int irq_ap_wakeup;
unsigned int irq_cp_status;
unsigned long flags;
gpio_set_value(mld->gpio_ap_status, 0);
/*
Retrieve GPIO#, IRQ#, and IRQ flags for PM
*/
gpio = mld->gpio_ap_wakeup;
irq_ap_wakeup = gpio_to_irq(gpio);
mif_err("CP2AP_WAKEUP GPIO:%d IRQ:%d\n", gpio, irq_ap_wakeup);
gpio = mld->gpio_cp_wakeup;
mif_err("AP2CP_WAKEUP GPIO:%d\n", gpio);
gpio = mld->gpio_cp_status;
irq_cp_status = gpio_to_irq(gpio);
mif_err("CP2AP_STATUS GPIO:%d IRQ:%d\n", gpio, irq_cp_status);
gpio = mld->gpio_ap_status;
mif_err("AP2CP_STATUS GPIO:%d\n", gpio);
/*
Initialize locks, completions, bottom halves, etc.
*/
wake_lock_init(&mld->ap_wlock, WAKE_LOCK_SUSPEND, "lli_ap_wlock");
wake_lock_init(&mld->cp_wlock, WAKE_LOCK_SUSPEND, "lli_cp_wlock");
INIT_DELAYED_WORK(&mld->cp_sleep_dwork, release_cp_wakeup);
spin_lock_init(&mld->pm_lock);
spin_lock_init(&mld->sig_lock);
atomic_set(&mld->ref_cnt, 0);
/*
Enable IRQs for PM
*/
print_pm_status(mld);
flags = (IRQF_TRIGGER_HIGH | IRQF_ONESHOT);
mif_init_irq(&mld->irq_ap_wakeup, irq_ap_wakeup,
"lli_cp2ap_wakeup", flags);
err = mif_request_irq(&mld->irq_ap_wakeup, ap_wakeup_interrupt, mld);
if (err)
return err;
mif_disable_irq(&mld->irq_ap_wakeup);
mif_init_irq(&mld->irq_cp_status, irq_cp_status,
"lli_cp2ap_status", flags);
err = mif_request_irq(&mld->irq_cp_status, cp_status_handler, mld);
if (err)
return err;
mif_disable_irq(&mld->irq_cp_status);
return 0;
}
#endif
#endif
static void lli_link_reset(struct link_device *ld)
{
mif_err("%s: PM %s <%pf>\n", ld->name, FUNC, CALLER);
mipi_lli_intr_enable();
mipi_lli_reset();
}
static void lli_link_reload(struct link_device *ld)
{
mif_err("%s: PM %s <%pf>\n", ld->name, FUNC, CALLER);
mipi_lli_reload();
}
static void lli_link_off(struct link_device *ld)
{
mif_err("%s: PM %s <%pf>\n", ld->name, FUNC, CALLER);
mipi_lli_intr_disable();
stop_pm(ld_to_mem_link_device(ld));
}
static bool lli_link_unmounted(struct link_device *ld)
{
return (mipi_lli_get_link_status() == LLI_UNMOUNTED);
}
static bool lli_link_suspended(struct link_device *ld)
{
return mipi_lli_suspended() ? true : false;
}
static void lli_disable_irq(struct link_device *ld)
{
mipi_lli_mask_sb_intr(true);
}
static void lli_enable_irq(struct link_device *ld)
{
mipi_lli_mask_sb_intr(false);
}
/**
@brief interrupt handler for a MIPI-LLI IPC interrupt
1) Get a free mst buffer\n
2) Reads the RXQ status and saves the status to the mst buffer\n
3) Saves the interrupt value to the mst buffer\n
4) Invokes mem_irq_handler that is common to all memory-type interfaces\n
@param data the pointer to a mem_link_device instance
@param intr the interrupt value
*/
static void lli_irq_handler(void *data, enum mipi_lli_event event, u32 intr)
{
struct mem_link_device *mld = (struct mem_link_device *)data;
struct mst_buff *msb;
if (event == LLI_EVENT_SIG) {
msb = mem_take_snapshot(mld, RX);
if (!msb)
return;
msb->snapshot.int2ap = (u16)intr;
mem_irq_handler(mld, msb);
#ifdef CONFIG_LINK_POWER_MANAGEMENT_WITH_FSM
} else {
struct link_device *ld = &mld->link_dev;
struct modem_link_pm *pm = &ld->pm;
check_lli_irq(pm, event);
#endif
}
}
static struct mem_link_device *g_mld;
#ifdef DEBUG_MODEM_IF
#define DEBUGFS_BUF_SIZE (SZ_32K - SZ_256)
/*
* Due to the lack of the allocated memory size,
* some hard-coded values are used to limit the size of line and row.
* need to invent more neater and cleaner way.
*/
#if 0
static ssize_t dump_rb_frame(char *buf, size_t size, struct sbd_ring_buffer *rb)
{
int idx;
u32 i, j, nr, nc, len = 0;
nr = min_t(u32, rb->len, sipc_ps_ch(rb->ch) ? 48 : 32);
/* 52 Bytes = ip header(20) + TCP header(32) */
nc = sipc_ps_ch(rb->ch) ? 52 : 16;
/* dumps recent n frames */
for (i = 0; i < nr; i++) {
idx = *rb->wp - i - 1;
if (idx < 0)
idx = rb->len + idx;
/*
len += snprintf((buf + len), (size - len), "rb[%03d] ", idx);
*/
for (j = 0; j < nc; j++)
len += snprintf((buf + len), (size - len),
"%02x", rb->buff[idx][j]);
len += snprintf((buf + len), (size - len), "\n");
}
return len;
}
static ssize_t dbgfs_frame(struct file *file,
char __user *user_buf, size_t count, loff_t *ppos)
{
char *buf;
ssize_t size;
u32 i, dir, len = 0;
struct mem_link_device *mld;
struct sbd_link_device *sl;
mld = file->private_data;
sl = &mld->sbd_link_dev;
if (!mld || !sl)
return 0;
buf = kzalloc(DEBUGFS_BUF_SIZE, GFP_KERNEL);
if (!buf) {
mif_err("not enough memory...\n");
return 0;
}
for (i = 0; i < sl->num_channels; i++)
for (dir = UL; dir <= DL; dir++) {
struct sbd_ring_buffer *rb = sbd_id2rb(sl, i, dir);
if (!rb || !sipc_major_ch(rb->ch))
break;
len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len),
">> ch:%d len:%d size:%d [%s w:%d r:%d]\n",
rb->ch, rb->len, rb->buff_size,
udl_str(rb->dir), *rb->wp, *rb->rp);
len += dump_rb_frame((buf + len),
(DEBUGFS_BUF_SIZE - len), rb);
len += snprintf((buf + len),
(DEBUGFS_BUF_SIZE - len), "\n");
}
len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), "\n");
mif_info("Total output length = %d\n", len);
size = simple_read_from_buffer(user_buf, count, ppos, buf, len);
kfree(buf);
return size;
}
static const struct file_operations dbgfs_frame_fops = {
.open = simple_open,
.read = dbgfs_frame,
.owner = THIS_MODULE
};
#endif
static inline void dev_debugfs_add(struct mem_link_device *mld)
{
mld->dbgfs_dir = debugfs_create_dir("svnet", NULL);
mld->mem_dump_blob.data = mld->base;
mld->mem_dump_blob.size = mld->size;
debugfs_create_blob("mem_dump", S_IRUGO, mld->dbgfs_dir,
&mld->mem_dump_blob);
/* mld->dbgfs_frame = debugfs_create_file("frame", S_IRUGO,
mld->dbgfs_dir, mld, &dbgfs_frame_fops);
*/
}
#else
static inline void dev_debugfs_add(struct mem_link_device *mld) {}
#endif
struct link_device *lli_create_link_device(struct platform_device *pdev)
{
struct modem_data *modem;
struct mem_link_device *mld;
struct link_device *ld;
int err;
unsigned long start;
unsigned long size;
/**
* Get the modem (platform) data
*/
modem = (struct modem_data *)pdev->dev.platform_data;
if (!modem) {
mif_err("ERR! modem == NULL\n");
return NULL;
}
if (!modem->gpio_ap_wakeup) {
mif_err("ERR! no gpio_ap_wakeup\n");
return NULL;
}
if (!modem->gpio_cp_status) {
mif_err("ERR! no gpio_cp_status\n");
return NULL;
}
mif_err("MODEM:%s LINK:%s\n", modem->name, modem->link_name);
/**
* Create a MEMORY link device instance
*/
mld = mem_create_link_device(MEM_LLI_SHMEM, modem);
if (!mld) {
mif_err("%s: ERR! create_link_device fail\n", modem->link_name);
return NULL;
}
g_mld = mld;
ld = &mld->link_dev;
ld->reset = lli_link_reset;
ld->reload = lli_link_reload;
ld->off = lli_link_off;
ld->unmounted = lli_link_unmounted;
ld->suspended = lli_link_suspended;
ld->enable_irq = lli_enable_irq;
ld->disable_irq = lli_disable_irq;
/**
* Link local functions to the corresponding function pointers that are
* mandatory for all memory-type link devices
*/
mld->send_ap2cp_irq = send_ap2cp_irq;
/*
** Link local functions to the corresponding function pointers
*/
#ifndef CONFIG_LINK_POWER_MANAGEMENT_WITH_FSM
mld->finalize_cp_start = finalize_cp_start;
#endif
#ifdef CONFIG_LINK_POWER_MANAGEMENT
mld->start_pm = start_pm;
mld->stop_pm = stop_pm;
mld->forbid_cp_sleep = forbid_cp_sleep;
mld->forbid_cp_sleep_wait = forbid_cp_sleep_wait;
mld->permit_cp_sleep = permit_cp_sleep;
mld->link_active = check_link_status;
#endif
#ifdef DEBUG_MODEM_IF
mld->debug_info = mipi_lli_debug_info;
#endif
/**
* Initialize SHMEM maps for IPC (physical map -> logical map)
*/
start = mipi_lli_get_phys_base();
size = mipi_lli_get_phys_size();
err = mem_register_ipc_rgn(mld, start, size);
if (err < 0) {
mif_err("%s: ERR! register_ipc_rgn fail (%d)\n", ld->name, err);
goto error;
}
err = mem_setup_ipc_map(mld);
if (err < 0) {
mif_err("%s: ERR! setup_ipc_map fail (%d)\n", ld->name, err);
mem_unregister_ipc_rgn(mld);
goto error;
}
#ifdef CONFIG_LINK_DEVICE_WITH_SBD_ARCH
if (ld->sbd_ipc) {
struct sbd_link_device *sld = &mld->sbd_link_dev;
err = create_sbd_link_device(ld, sld, mld->base, mld->size);
if (err < 0)
goto error;
}
#endif
/**
* Register interrupt handlers
*/
err = mipi_lli_register_handler(lli_irq_handler, mld);
if (err) {
mif_err("%s: ERR! register_handler fail (%d)\n", ld->name, err);
goto error;
}
/*
** Retrieve GPIO#, IRQ#, and IRQ flags for PM
*/
mld->gpio_ap_wakeup = modem->gpio_ap_wakeup;
mld->gpio_cp_wakeup = modem->gpio_cp_wakeup;
mld->gpio_cp_status = modem->gpio_cp_status;
mld->gpio_ap_status = modem->gpio_ap_status;
mld->gpio_ipc_int2cp = modem->gpio_ipc_int2cp;
init_waitqueue_head(&mld->wq);
#ifdef CONFIG_LINK_POWER_MANAGEMENT
err = init_pm(mld);
if (err)
goto error;
#endif
#ifdef DEBUG_MODEM_IF
dev_debugfs_add(mld);
#endif
return ld;
error:
kfree(mld);
mif_err("xxx\n");
return NULL;
}
|