18709c939Selly.chiang /*
28709c939Selly.chiang * Copyright (c) 2020, MediaTek Inc. All rights reserved. \
38709c939Selly.chiang *
48709c939Selly.chiang * SPDX-License-Identifier: BSD-3-Clause
58709c939Selly.chiang */
68709c939Selly.chiang
78709c939Selly.chiang #include "mtk_ptp3_common.h"
88709c939Selly.chiang
98709c939Selly.chiang /************************************************
108709c939Selly.chiang * Central control: turn on sysPi protection
118709c939Selly.chiang ************************************************/
128709c939Selly.chiang static unsigned int ptp3_cfg1[NR_PTP3_CFG1_CPU][NR_PTP3_CFG] = {
138709c939Selly.chiang {0x0C530610, 0x110842},
148709c939Selly.chiang {0x0C530E10, 0x110842},
158709c939Selly.chiang {0x0C531610, 0x110842},
168709c939Selly.chiang {0x0C531E10, 0x110842},
178709c939Selly.chiang {0x0C532610, 0x110842},
188709c939Selly.chiang {0x0C532E10, 0x110842},
198709c939Selly.chiang {0x0C533610, 0x110842},
208709c939Selly.chiang {0x0C533E10, 0x110842}
218709c939Selly.chiang };
228709c939Selly.chiang static unsigned int ptp3_cfg2[NR_PTP3_CFG2_CPU][NR_PTP3_CFG] = {
238709c939Selly.chiang {0x0C53B830, 0x68000},
248709c939Selly.chiang {0x0C53BA30, 0x68000},
258709c939Selly.chiang {0x0C53BC30, 0x68000},
268709c939Selly.chiang {0x0C53BE30, 0x68000}
278709c939Selly.chiang };
288709c939Selly.chiang static unsigned int ptp3_cfg3[NR_PTP3_CFG3_CPU][NR_PTP3_CFG] = {
298709c939Selly.chiang {0x0C532480, 0x7C607C6},
308709c939Selly.chiang {0x0C532C80, 0x7C607C6},
318709c939Selly.chiang {0x0C533480, 0x7C607C6},
328709c939Selly.chiang {0x0C533C80, 0x7C607C6}
338709c939Selly.chiang };
348709c939Selly.chiang
358709c939Selly.chiang /************************************************
368709c939Selly.chiang * API
378709c939Selly.chiang ************************************************/
ptp3_init(unsigned int core)388709c939Selly.chiang void ptp3_init(unsigned int core)
398709c939Selly.chiang {
408709c939Selly.chiang unsigned int _core;
418709c939Selly.chiang
42*04589e2bSYidi Lin /* Apply ptp3_cfg1 for core 0 to 7 */
438709c939Selly.chiang if (core < NR_PTP3_CFG1_CPU) {
448709c939Selly.chiang /* update ptp3_cfg1 */
458709c939Selly.chiang ptp3_write(
468709c939Selly.chiang ptp3_cfg1[core][PTP3_CFG_ADDR],
478709c939Selly.chiang ptp3_cfg1[core][PTP3_CFG_VALUE]);
488709c939Selly.chiang }
498709c939Selly.chiang
50*04589e2bSYidi Lin /* Apply ptp3_cfg2 for core 4 to 7 */
518709c939Selly.chiang if (core >= PTP3_CFG2_CPU_START_ID) {
528709c939Selly.chiang _core = core - PTP3_CFG2_CPU_START_ID;
538709c939Selly.chiang
548709c939Selly.chiang if (_core < NR_PTP3_CFG2_CPU) {
558709c939Selly.chiang /* update ptp3_cfg2 */
568709c939Selly.chiang ptp3_write(
578709c939Selly.chiang ptp3_cfg2[_core][PTP3_CFG_ADDR],
588709c939Selly.chiang ptp3_cfg2[_core][PTP3_CFG_VALUE]);
598709c939Selly.chiang }
608709c939Selly.chiang }
618709c939Selly.chiang
62*04589e2bSYidi Lin /* Apply ptp3_cfg3 for core 4 to 7 */
638709c939Selly.chiang if (core >= PTP3_CFG3_CPU_START_ID) {
648709c939Selly.chiang _core = core - PTP3_CFG3_CPU_START_ID;
658709c939Selly.chiang
668709c939Selly.chiang if (_core < NR_PTP3_CFG3_CPU) {
678709c939Selly.chiang /* update ptp3_cfg3 */
688709c939Selly.chiang ptp3_write(
698709c939Selly.chiang ptp3_cfg3[_core][PTP3_CFG_ADDR],
708709c939Selly.chiang ptp3_cfg3[_core][PTP3_CFG_VALUE]);
718709c939Selly.chiang }
728709c939Selly.chiang }
738709c939Selly.chiang }
748709c939Selly.chiang
ptp3_deinit(unsigned int core)758709c939Selly.chiang void ptp3_deinit(unsigned int core)
768709c939Selly.chiang {
778709c939Selly.chiang if (core < NR_PTP3_CFG1_CPU) {
788709c939Selly.chiang /* update ptp3_cfg1 */
798709c939Selly.chiang ptp3_write(
808709c939Selly.chiang ptp3_cfg1[core][PTP3_CFG_ADDR],
818709c939Selly.chiang ptp3_cfg1[core][PTP3_CFG_VALUE] &
828709c939Selly.chiang ~PTP3_CFG1_MASK);
838709c939Selly.chiang }
848709c939Selly.chiang }
85