hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
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
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Misc utility routines for accessing PMU corerev specific features
 * of the SiliconBackplane-based Broadcom chips.
 *
 * Copyright (C) 1999-2019, Broadcom.
 *
 *      Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2 (the "GPL"),
 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
 * following added to such license:
 *
 *      As a special exception, the copyright holders of this software give you
 * permission to link this software with independent modules, and to copy and
 * distribute the resulting executable under terms of your choice, provided that
 * you also meet, for each linked independent module, the terms and conditions of
 * the license of that module.  An independent module is a module which is not
 * derived from this software.  The special exception does not apply to any
 * modifications of the software.
 *
 *      Notwithstanding the above, under no circumstances may you combine this
 * software in any way with any other Broadcom software provided under a license
 * other than the GPL, without Broadcom's express prior written consent.
 *
 *
 * <<Broadcom-WL-IPTag/Open:>>
 *
 * $Id: hndpmu.c 783841 2018-10-09 06:24:16Z $
 */
 
/**
 * @file
 * Note: this file contains PLL/FLL related functions. A chip can contain multiple PLLs/FLLs.
 * However, in the context of this file the baseband ('BB') PLL/FLL is referred to.
 *
 * Throughout this code, the prefixes 'pmu1_' and 'pmu2_' are used.
 * They refer to different revisions of the PMU (which is at revision 18 @ Apr 25, 2012)
 * pmu1_ marks the transition from PLL to ADFLL (Digital Frequency Locked Loop). It supports
 * fractional frequency generation. pmu2_ does not support fractional frequency generation.
 */
 
#include <bcm_cfg.h>
#include <typedefs.h>
#include <bcmdefs.h>
#include <osl.h>
#include <bcmutils.h>
#include <siutils.h>
#include <bcmdevs.h>
#include <hndsoc.h>
#include <sbchipc.h>
#include <hndchipc.h>
#include <hndpmu.h>
#include <hndlhl.h>
#if defined(BCMULP)
#include <ulp.h>
#endif /* defined(BCMULP) */
#include <sbgci.h>
#ifdef EVENT_LOG_COMPILE
#include <event_log.h>
#endif // endif
#include <sbgci.h>
#include <lpflags.h>
 
#define    PMU_ERROR(args)
 
#define    PMU_MSG(args)
 
/* To check in verbose debugging messages not intended
 * to be on except on private builds.
 */
#define    PMU_NONE(args)
#define flags_shift    14
 
/** contains resource bit positions for a specific chip */
struct rsc_per_chip_s {
   uint8 ht_avail;
   uint8 macphy_clkavail;
   uint8 ht_start;
   uint8 otp_pu;
   uint8 macphy_aux_clkavail;
};
 
typedef struct rsc_per_chip_s rsc_per_chip_t;
 
#if defined(BCMPMU_STATS) && !defined(BCMPMU_STATS_DISABLED)
bool    _pmustatsenab = TRUE;
#else
bool    _pmustatsenab = FALSE;
#endif /* BCMPMU_STATS */
 
/**
 * Balance between stable SDIO operation and power consumption is achieved using this function.
 * Note that each drive strength table is for a specific VDDIO of the SDIO pads, ideally this
 * function should read the VDDIO itself to select the correct table. For now it has been solved
 * with the 'BCM_SDIO_VDDIO' preprocessor constant.
 *
 * 'drivestrength': desired pad drive strength in mA. Drive strength of 0 requests tri-state (if
 *            hardware supports this), if no hw support drive strength is not programmed.
 */
void
si_sdiod_drive_strength_init(si_t *sih, osl_t *osh, uint32 drivestrength)
{
   /*
    * Note:
    * This function used to set the SDIO drive strength via PMU_CHIPCTL1 for the
    * 43143, 4330, 4334, 4336, 43362 chips.  These chips are now no longer supported, so
    * the code has been deleted.
    * Newer chips have the SDIO drive strength setting via a GCI Chip Control register,
    * but the bit definitions are chip-specific.  We are keeping this function available
    * (accessed via DHD 'sdiod_drive' IOVar) in case these newer chips need to provide access.
    */
   UNUSED_PARAMETER(sih);
   UNUSED_PARAMETER(osh);
   UNUSED_PARAMETER(drivestrength);
}
 
void
si_switch_pmu_dependency(si_t *sih, uint mode)
{
#ifdef DUAL_PMU_SEQUENCE
   osl_t *osh = si_osh(sih);
   uint32 current_res_state;
   uint32 min_mask, max_mask;
   const pmu_res_depend_t *pmu_res_depend_table = NULL;
   uint pmu_res_depend_table_sz = 0;
   uint origidx;
   pmuregs_t *pmu;
   chipcregs_t *cc;
   BCM_REFERENCE(cc);
 
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
       cc  = si_setcore(sih, CC_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
       cc  = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   current_res_state = R_REG(osh, &pmu->res_state);
   min_mask = R_REG(osh, &pmu->min_res_mask);
   max_mask = R_REG(osh, &pmu->max_res_mask);
   W_REG(osh, &pmu->min_res_mask, (min_mask | current_res_state));
   switch (mode) {
       case PMU_4364_1x1_MODE:
       {
           if (CHIPID(sih->chip) == BCM4364_CHIP_ID) {
                   pmu_res_depend_table = bcm4364a0_res_depend_1x1;
                   pmu_res_depend_table_sz =
                       ARRAYSIZE(bcm4364a0_res_depend_1x1);
           max_mask = PMU_4364_MAX_MASK_1x1;
           W_REG(osh, &pmu->res_table_sel, RES4364_SR_SAVE_RESTORE);
           W_REG(osh, &pmu->res_updn_timer, PMU_4364_SAVE_RESTORE_UPDNTIME_1x1);
#if defined(SAVERESTORE)
               if (SR_ENAB()) {
                   /* Disable 3x3 SR engine */
                   W_REG(osh, &cc->sr1_control0,
                   CC_SR0_4364_SR_ENG_CLK_EN |
                   CC_SR0_4364_SR_RSRC_TRIGGER |
                   CC_SR0_4364_SR_WD_MEM_MIN_DIV |
                   CC_SR0_4364_SR_INVERT_CLK |
                   CC_SR0_4364_SR_ENABLE_HT |
                   CC_SR0_4364_SR_ALLOW_PIC |
                   CC_SR0_4364_SR_PMU_MEM_DISABLE);
               }
#endif /* SAVERESTORE */
           }
           break;
       }
       case PMU_4364_3x3_MODE:
       {
           if (CHIPID(sih->chip) == BCM4364_CHIP_ID) {
               W_REG(osh, &pmu->res_table_sel, RES4364_SR_SAVE_RESTORE);
               W_REG(osh, &pmu->res_updn_timer,
                   PMU_4364_SAVE_RESTORE_UPDNTIME_3x3);
               /* Change the dependency table only if required */
               if ((max_mask != PMU_4364_MAX_MASK_3x3) ||
                   (max_mask != PMU_4364_MAX_MASK_RSDB)) {
                       pmu_res_depend_table = bcm4364a0_res_depend_rsdb;
                       pmu_res_depend_table_sz =
                           ARRAYSIZE(bcm4364a0_res_depend_rsdb);
                       max_mask = PMU_4364_MAX_MASK_3x3;
               }
#if defined(SAVERESTORE)
               if (SR_ENAB()) {
                   /* Enable 3x3 SR engine */
                   W_REG(osh, &cc->sr1_control0,
                   CC_SR0_4364_SR_ENG_CLK_EN |
                   CC_SR0_4364_SR_RSRC_TRIGGER |
                   CC_SR0_4364_SR_WD_MEM_MIN_DIV |
                   CC_SR0_4364_SR_INVERT_CLK |
                   CC_SR0_4364_SR_ENABLE_HT |
                   CC_SR0_4364_SR_ALLOW_PIC |
                   CC_SR0_4364_SR_PMU_MEM_DISABLE |
                   CC_SR0_4364_SR_ENG_EN_MASK);
               }
#endif /* SAVERESTORE */
           }
           break;
       }
       case PMU_4364_RSDB_MODE:
       default:
       {
           if (CHIPID(sih->chip) == BCM4364_CHIP_ID) {
               W_REG(osh, &pmu->res_table_sel, RES4364_SR_SAVE_RESTORE);
               W_REG(osh, &pmu->res_updn_timer,
                   PMU_4364_SAVE_RESTORE_UPDNTIME_3x3);
               /* Change the dependency table only if required */
               if ((max_mask != PMU_4364_MAX_MASK_3x3) ||
                   (max_mask != PMU_4364_MAX_MASK_RSDB)) {
                       pmu_res_depend_table =
                           bcm4364a0_res_depend_rsdb;
                       pmu_res_depend_table_sz =
                           ARRAYSIZE(bcm4364a0_res_depend_rsdb);
                       max_mask = PMU_4364_MAX_MASK_RSDB;
               }
#if defined(SAVERESTORE)
           if (SR_ENAB()) {
                   /* Enable 3x3 SR engine */
                   W_REG(osh, &cc->sr1_control0,
                   CC_SR0_4364_SR_ENG_CLK_EN |
                   CC_SR0_4364_SR_RSRC_TRIGGER |
                   CC_SR0_4364_SR_WD_MEM_MIN_DIV |
                   CC_SR0_4364_SR_INVERT_CLK |
                   CC_SR0_4364_SR_ENABLE_HT |
                   CC_SR0_4364_SR_ALLOW_PIC |
                   CC_SR0_4364_SR_PMU_MEM_DISABLE |
                   CC_SR0_4364_SR_ENG_EN_MASK);
               }
#endif /* SAVERESTORE */
           }
           break;
       }
   }
   si_pmu_resdeptbl_upd(sih, osh, pmu, pmu_res_depend_table, pmu_res_depend_table_sz);
   W_REG(osh, &pmu->max_res_mask, max_mask);
   W_REG(osh, &pmu->min_res_mask, min_mask);
   si_pmu_wait_for_steady_state(sih, osh, pmu);
   /* Add some delay; allow resources to come up and settle. */
   OSL_DELAY(200);
   si_setcoreidx(sih, origidx);
#endif /* DUAL_PMU_SEQUENCE */
}
 
#if defined(BCMULP)
 
int
si_pmu_ulp_register(si_t *sih)
{
   return ulp_p1_module_register(ULP_MODULE_ID_PMU, &ulp_pmu_ctx, (void *)sih);
}
 
static uint
si_pmu_ulp_get_retention_size_cb(void *handle, ulp_ext_info_t *einfo)
{
   ULP_DBG(("%s: sz: %d\n", __FUNCTION__, sizeof(si_pmu_ulp_cr_dat_t)));
   return sizeof(si_pmu_ulp_cr_dat_t);
}
 
static int
si_pmu_ulp_enter_cb(void *handle, ulp_ext_info_t *einfo, uint8 *cache_data)
{
   si_pmu_ulp_cr_dat_t crinfo = {0};
   crinfo.ilpcycles_per_sec = ilpcycles_per_sec;
   ULP_DBG(("%s: ilpcycles_per_sec: %x\n", __FUNCTION__, ilpcycles_per_sec));
   memcpy(cache_data, (void*)&crinfo, sizeof(crinfo));
   return BCME_OK;
}
 
static int
si_pmu_ulp_exit_cb(void *handle, uint8 *cache_data,
   uint8 *p2_cache_data)
{
   si_pmu_ulp_cr_dat_t *crinfo = (si_pmu_ulp_cr_dat_t *)cache_data;
 
   ilpcycles_per_sec = crinfo->ilpcycles_per_sec;
   ULP_DBG(("%s: ilpcycles_per_sec: %x, cache_data: %p\n", __FUNCTION__,
       ilpcycles_per_sec, cache_data));
   return BCME_OK;
}
 
void
si_pmu_ulp_chipconfig(si_t *sih, osl_t *osh)
{
   uint32 reg_val;
 
   BCM_REFERENCE(reg_val);
 
   if (CHIPID(sih->chip) == BCM43012_CHIP_ID) {
       /* DS1 reset and clk enable init value config */
       si_pmu_chipcontrol(sih, PMU_CHIPCTL14, ~0x0,
           (PMUCCTL14_43012_ARMCM3_RESET_INITVAL |
           PMUCCTL14_43012_DOT11MAC_CLKEN_INITVAL |
           PMUCCTL14_43012_SDIOD_RESET_INIVAL |
           PMUCCTL14_43012_SDIO_CLK_DMN_RESET_INITVAL |
           PMUCCTL14_43012_SOCRAM_CLKEN_INITVAL |
           PMUCCTL14_43012_M2MDMA_RESET_INITVAL |
           PMUCCTL14_43012_DOT11MAC_PHY_CLK_EN_INITVAL |
           PMUCCTL14_43012_DOT11MAC_PHY_CNTL_EN_INITVAL));
 
       /* Clear SFlash clock request and enable High Quality clock */
       CHIPC_REG(sih, clk_ctl_st, CCS_SFLASH_CLKREQ | CCS_HQCLKREQ, CCS_HQCLKREQ);
 
       reg_val = PMU_REG(sih, min_res_mask, ~0x0, ULP_MIN_RES_MASK);
       ULP_DBG(("si_pmu_ulp_chipconfig: min_res_mask: 0x%08x\n", reg_val));
 
       /* Force power switch off */
       si_pmu_chipcontrol(sih, PMU_CHIPCTL2,
               (PMUCCTL02_43012_SUBCORE_PWRSW_FORCE_ON |
               PMUCCTL02_43012_PHY_PWRSW_FORCE_ON), 0);
 
   }
}
 
void
si_pmu_ulp_ilp_config(si_t *sih, osl_t *osh, uint32 ilp_period)
{
   pmuregs_t *pmu;
   pmu = si_setcoreidx(sih, si_findcoreidx(sih, PMU_CORE_ID, 0));
   W_REG(osh, &pmu->ILPPeriod, ilp_period);
   si_lhl_ilp_config(sih, osh, ilp_period);
}
 
/** Initialize DS1 PMU hardware resources */
void
si_pmu_ds1_res_init(si_t *sih, osl_t *osh)
{
   pmuregs_t *pmu;
   uint origidx;
   const pmu_res_updown_t *pmu_res_updown_table = NULL;
   uint pmu_res_updown_table_sz = 0;
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   switch (CHIPID(sih->chip)) {
   case BCM43012_CHIP_ID:
       pmu_res_updown_table = bcm43012a0_res_updown_ds1;
       pmu_res_updown_table_sz = ARRAYSIZE(bcm43012a0_res_updown_ds1);
       break;
 
   default:
       break;
   }
 
   /* Program up/down timers */
   while (pmu_res_updown_table_sz--) {
       ASSERT(pmu_res_updown_table != NULL);
       PMU_MSG(("DS1: Changing rsrc %d res_updn_timer to 0x%x\n",
           pmu_res_updown_table[pmu_res_updown_table_sz].resnum,
           pmu_res_updown_table[pmu_res_updown_table_sz].updown));
       W_REG(osh, &pmu->res_table_sel,
           pmu_res_updown_table[pmu_res_updown_table_sz].resnum);
       W_REG(osh, &pmu->res_updn_timer,
           pmu_res_updown_table[pmu_res_updown_table_sz].updown);
   }
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
#endif /* defined(BCMULP) */
 
uint32
si_pmu_wake_bit_offset(si_t *sih)
{
   uint32 wakebit;
 
   switch (CHIPID(sih->chip)) {
   case BCM4347_CHIP_GRPID:
       wakebit = CC2_4347_GCI2WAKE_MASK;
       break;
   default:
       wakebit = 0;
       ASSERT(0);
       break;
   }
 
   return wakebit;
}
 
void si_pmu_set_min_res_mask(si_t *sih, osl_t *osh, uint min_res_mask)
{
   pmuregs_t *pmu;
   uint origidx;
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   }
   else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   W_REG(osh, &pmu->min_res_mask, min_res_mask);
   OSL_DELAY(100);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
bool
si_pmu_cap_fast_lpo(si_t *sih)
{
   return (PMU_REG(sih, core_cap_ext, 0, 0) & PCAP_EXT_USE_MUXED_ILP_CLK_MASK) ? TRUE : FALSE;
}
 
int
si_pmu_fast_lpo_disable(si_t *sih)
{
   if (!si_pmu_cap_fast_lpo(sih)) {
       PMU_ERROR(("%s: No Fast LPO capability\n", __FUNCTION__));
       return BCME_ERROR;
   }
 
   PMU_REG(sih, pmucontrol_ext,
       PCTL_EXT_FASTLPO_ENAB |
       PCTL_EXT_FASTLPO_SWENAB |
       PCTL_EXT_FASTLPO_PCIE_SWENAB,
       0);
   OSL_DELAY(1000);
   return BCME_OK;
}
 
#ifdef BCMPMU_STATS
/*
 * 8 pmu statistics timer default map
 *
 * for CORE_RDY_AUX measure, set as below for timer 6 and 7 instead of CORE_RDY_MAIN.
 *    //core-n active duration : pmu_rsrc_state(CORE_RDY_AUX)
 *    { SRC_CORE_RDY_AUX, FALSE, TRUE, LEVEL_HIGH},
 *    //core-n active duration : pmu_rsrc_state(CORE_RDY_AUX)
 *    { SRC_CORE_RDY_AUX, FALSE, TRUE, EDGE_RISE}
 */
static pmu_stats_timer_t pmustatstimer[] = {
   { SRC_LINK_IN_L12, FALSE, TRUE, PMU_STATS_LEVEL_HIGH},    //link_in_l12
   { SRC_LINK_IN_L23, FALSE, TRUE, PMU_STATS_LEVEL_HIGH},    //link_in_l23
   { SRC_PM_ST_IN_D0, FALSE, TRUE, PMU_STATS_LEVEL_HIGH},    //pm_st_in_d0
   { SRC_PM_ST_IN_D3, FALSE, TRUE, PMU_STATS_LEVEL_HIGH},    //pm_st_in_d3
   //deep-sleep duration : pmu_rsrc_state(XTAL_PU)
   { SRC_XTAL_PU, FALSE, TRUE, PMU_STATS_LEVEL_LOW},
   //deep-sleep entry count : pmu_rsrc_state(XTAL_PU)
   { SRC_XTAL_PU, FALSE, TRUE, PMU_STATS_EDGE_FALL},
   //core-n active duration : pmu_rsrc_state(CORE_RDY_MAIN)
   { SRC_CORE_RDY_MAIN, FALSE, TRUE, PMU_STATS_LEVEL_HIGH},
   //core-n active duration : pmu_rsrc_state(CORE_RDY_MAIN)
   { SRC_CORE_RDY_MAIN, FALSE, TRUE, PMU_STATS_EDGE_RISE}
};
 
static void
si_pmustatstimer_update(osl_t *osh, pmuregs_t *pmu, uint8 timerid)
{
   uint32 stats_timer_ctrl;
 
   W_REG(osh, &pmu->pmu_statstimer_addr, timerid);
   stats_timer_ctrl =
       ((pmustatstimer[timerid].src_num << PMU_ST_SRC_SHIFT) &
           PMU_ST_SRC_MASK) |
       ((pmustatstimer[timerid].cnt_mode << PMU_ST_CNT_MODE_SHIFT) &
           PMU_ST_CNT_MODE_MASK) |
       ((pmustatstimer[timerid].enable << PMU_ST_EN_SHIFT) & PMU_ST_EN_MASK) |
       ((pmustatstimer[timerid].int_enable << PMU_ST_INT_EN_SHIFT) & PMU_ST_INT_EN_MASK);
   W_REG(osh, &pmu->pmu_statstimer_ctrl, stats_timer_ctrl);
   W_REG(osh, &pmu->pmu_statstimer_N, 0);
}
 
void
si_pmustatstimer_int_enable(si_t *sih)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   OR_REG(osh, &pmu->pmuintmask0, PMU_INT_STAT_TIMER_INT_MASK);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_int_disable(si_t *sih)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   AND_REG(osh, &pmu->pmuintmask0, ~PMU_INT_STAT_TIMER_INT_MASK);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_init(si_t *sih)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
   uint32 core_cap_ext;
   uint8 max_stats_timer_num;
   int8 i;
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   core_cap_ext = R_REG(osh, &pmu->core_cap_ext);
 
   max_stats_timer_num = ((core_cap_ext & PCAP_EXT_ST_NUM_MASK) >> PCAP_EXT_ST_NUM_SHIFT) + 1;
 
   for (i = 0; i < max_stats_timer_num; i++) {
       si_pmustatstimer_update(osh, pmu, i);
   }
 
   OR_REG(osh, &pmu->pmuintmask0, PMU_INT_STAT_TIMER_INT_MASK);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_dump(si_t *sih)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
   uint32 core_cap_ext, pmucapabilities, AlpPeriod, ILPPeriod, pmuintmask0, pmuintstatus;
   uint8 max_stats_timer_num, max_stats_timer_src_num;
   uint32 stat_timer_ctrl, stat_timer_N;
   uint8 i;
   uint32 current_time_ms = OSL_SYSUPTIME();
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   pmucapabilities = R_REG(osh, &pmu->pmucapabilities);
   core_cap_ext = R_REG(osh, &pmu->core_cap_ext);
   AlpPeriod = R_REG(osh, &pmu->slowclkperiod);
   ILPPeriod = R_REG(osh, &pmu->ILPPeriod);
 
   max_stats_timer_num = ((core_cap_ext & PCAP_EXT_ST_NUM_MASK) >>
       PCAP_EXT_ST_NUM_SHIFT) + 1;
   max_stats_timer_src_num = ((core_cap_ext & PCAP_EXT_ST_SRC_NUM_MASK) >>
       PCAP_EXT_ST_SRC_NUM_SHIFT) + 1;
 
   pmuintstatus = R_REG(osh, &pmu->pmuintstatus);
   pmuintmask0 = R_REG(osh, &pmu->pmuintmask0);
 
   PMU_ERROR(("%s : TIME %d\n", __FUNCTION__, current_time_ms));
 
   PMU_ERROR(("\tMAX Timer Num %d, MAX Source Num %d\n",
       max_stats_timer_num, max_stats_timer_src_num));
   PMU_ERROR(("\tpmucapabilities 0x%8x, core_cap_ext 0x%8x, AlpPeriod 0x%8x, ILPPeriod 0x%8x, "
       "pmuintmask0 0x%8x, pmuintstatus 0x%8x, pmurev %d\n",
       pmucapabilities, core_cap_ext, AlpPeriod, ILPPeriod,
       pmuintmask0, pmuintstatus, PMUREV(sih->pmurev)));
 
   for (i = 0; i < max_stats_timer_num; i++) {
       W_REG(osh, &pmu->pmu_statstimer_addr, i);
       stat_timer_ctrl = R_REG(osh, &pmu->pmu_statstimer_ctrl);
       stat_timer_N = R_REG(osh, &pmu->pmu_statstimer_N);
       PMU_ERROR(("\t Timer %d : control 0x%8x, %d\n",
           i, stat_timer_ctrl, stat_timer_N));
   }
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_start(si_t *sih, uint8 timerid)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   pmustatstimer[timerid].enable = TRUE;
 
   W_REG(osh, &pmu->pmu_statstimer_addr, timerid);
   OR_REG(osh, &pmu->pmu_statstimer_ctrl, PMU_ST_ENAB << PMU_ST_EN_SHIFT);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_stop(si_t *sih, uint8 timerid)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   pmustatstimer[timerid].enable = FALSE;
 
   W_REG(osh, &pmu->pmu_statstimer_addr, timerid);
   AND_REG(osh, &pmu->pmu_statstimer_ctrl, ~(PMU_ST_ENAB << PMU_ST_EN_SHIFT));
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_clear(si_t *sih, uint8 timerid)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   W_REG(osh, &pmu->pmu_statstimer_addr, timerid);
   W_REG(osh, &pmu->pmu_statstimer_N, 0);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_clear_overflow(si_t *sih)
{
   uint8 i;
   uint32 core_cap_ext;
   uint8 max_stats_timer_num;
   uint32 timerN;
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   core_cap_ext = R_REG(osh, &pmu->core_cap_ext);
   max_stats_timer_num = ((core_cap_ext & PCAP_EXT_ST_NUM_MASK) >> PCAP_EXT_ST_NUM_SHIFT) + 1;
 
   for (i = 0; i < max_stats_timer_num; i++) {
       W_REG(osh, &pmu->pmu_statstimer_addr, i);
       timerN = R_REG(osh, &pmu->pmu_statstimer_N);
       if (timerN == 0xFFFFFFFF) {
           PMU_ERROR(("pmustatstimer overflow clear - timerid : %d\n", i));
           si_pmustatstimer_clear(sih, i);
       }
   }
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
uint32
si_pmustatstimer_read(si_t *sih, uint8 timerid)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
   uint32 stats_timer_N;
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   W_REG(osh, &pmu->pmu_statstimer_addr, timerid);
   stats_timer_N = R_REG(osh, &pmu->pmu_statstimer_N);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
 
   return stats_timer_N;
}
 
void
si_pmustatstimer_cfg_src_num(si_t *sih, uint8 src_num, uint8 timerid)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   pmustatstimer[timerid].src_num = src_num;
   si_pmustatstimer_update(osh, pmu, timerid);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
 
void
si_pmustatstimer_cfg_cnt_mode(si_t *sih, uint8 cnt_mode, uint8 timerid)
{
   pmuregs_t *pmu;
   uint origidx;
   osl_t *osh = si_osh(sih);
 
   /* Remember original core before switch to chipc/pmu */
   origidx = si_coreidx(sih);
   if (AOB_ENAB(sih)) {
       pmu = si_setcore(sih, PMU_CORE_ID, 0);
   } else {
       pmu = si_setcoreidx(sih, SI_CC_IDX);
   }
   ASSERT(pmu != NULL);
 
   pmustatstimer[timerid].cnt_mode = cnt_mode;
   si_pmustatstimer_update(osh, pmu, timerid);
 
   /* Return to original core */
   si_setcoreidx(sih, origidx);
}
#endif /* BCMPMU_STATS */