18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Joshua Henderson <joshua.henderson@microchip.com> 48c2ecf20Sopenharmony_ci * Copyright (C) 2015 Microchip Technology Inc. All rights reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#include <asm/io.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "early_pin.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define PPS_BASE 0x1f800000 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* Input PPS Registers */ 138c2ecf20Sopenharmony_ci#define INT1R 0x1404 148c2ecf20Sopenharmony_ci#define INT2R 0x1408 158c2ecf20Sopenharmony_ci#define INT3R 0x140C 168c2ecf20Sopenharmony_ci#define INT4R 0x1410 178c2ecf20Sopenharmony_ci#define T2CKR 0x1418 188c2ecf20Sopenharmony_ci#define T3CKR 0x141C 198c2ecf20Sopenharmony_ci#define T4CKR 0x1420 208c2ecf20Sopenharmony_ci#define T5CKR 0x1424 218c2ecf20Sopenharmony_ci#define T6CKR 0x1428 228c2ecf20Sopenharmony_ci#define T7CKR 0x142C 238c2ecf20Sopenharmony_ci#define T8CKR 0x1430 248c2ecf20Sopenharmony_ci#define T9CKR 0x1434 258c2ecf20Sopenharmony_ci#define IC1R 0x1438 268c2ecf20Sopenharmony_ci#define IC2R 0x143C 278c2ecf20Sopenharmony_ci#define IC3R 0x1440 288c2ecf20Sopenharmony_ci#define IC4R 0x1444 298c2ecf20Sopenharmony_ci#define IC5R 0x1448 308c2ecf20Sopenharmony_ci#define IC6R 0x144C 318c2ecf20Sopenharmony_ci#define IC7R 0x1450 328c2ecf20Sopenharmony_ci#define IC8R 0x1454 338c2ecf20Sopenharmony_ci#define IC9R 0x1458 348c2ecf20Sopenharmony_ci#define OCFAR 0x1460 358c2ecf20Sopenharmony_ci#define U1RXR 0x1468 368c2ecf20Sopenharmony_ci#define U1CTSR 0x146C 378c2ecf20Sopenharmony_ci#define U2RXR 0x1470 388c2ecf20Sopenharmony_ci#define U2CTSR 0x1474 398c2ecf20Sopenharmony_ci#define U3RXR 0x1478 408c2ecf20Sopenharmony_ci#define U3CTSR 0x147C 418c2ecf20Sopenharmony_ci#define U4RXR 0x1480 428c2ecf20Sopenharmony_ci#define U4CTSR 0x1484 438c2ecf20Sopenharmony_ci#define U5RXR 0x1488 448c2ecf20Sopenharmony_ci#define U5CTSR 0x148C 458c2ecf20Sopenharmony_ci#define U6RXR 0x1490 468c2ecf20Sopenharmony_ci#define U6CTSR 0x1494 478c2ecf20Sopenharmony_ci#define SDI1R 0x149C 488c2ecf20Sopenharmony_ci#define SS1R 0x14A0 498c2ecf20Sopenharmony_ci#define SDI2R 0x14A8 508c2ecf20Sopenharmony_ci#define SS2R 0x14AC 518c2ecf20Sopenharmony_ci#define SDI3R 0x14B4 528c2ecf20Sopenharmony_ci#define SS3R 0x14B8 538c2ecf20Sopenharmony_ci#define SDI4R 0x14C0 548c2ecf20Sopenharmony_ci#define SS4R 0x14C4 558c2ecf20Sopenharmony_ci#define SDI5R 0x14CC 568c2ecf20Sopenharmony_ci#define SS5R 0x14D0 578c2ecf20Sopenharmony_ci#define SDI6R 0x14D8 588c2ecf20Sopenharmony_ci#define SS6R 0x14DC 598c2ecf20Sopenharmony_ci#define C1RXR 0x14E0 608c2ecf20Sopenharmony_ci#define C2RXR 0x14E4 618c2ecf20Sopenharmony_ci#define REFCLKI1R 0x14E8 628c2ecf20Sopenharmony_ci#define REFCLKI3R 0x14F0 638c2ecf20Sopenharmony_ci#define REFCLKI4R 0x14F4 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic const struct 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci int function; 688c2ecf20Sopenharmony_ci int reg; 698c2ecf20Sopenharmony_ci} input_pin_reg[] = { 708c2ecf20Sopenharmony_ci { IN_FUNC_INT3, INT3R }, 718c2ecf20Sopenharmony_ci { IN_FUNC_T2CK, T2CKR }, 728c2ecf20Sopenharmony_ci { IN_FUNC_T6CK, T6CKR }, 738c2ecf20Sopenharmony_ci { IN_FUNC_IC3, IC3R }, 748c2ecf20Sopenharmony_ci { IN_FUNC_IC7, IC7R }, 758c2ecf20Sopenharmony_ci { IN_FUNC_U1RX, U1RXR }, 768c2ecf20Sopenharmony_ci { IN_FUNC_U2CTS, U2CTSR }, 778c2ecf20Sopenharmony_ci { IN_FUNC_U5RX, U5RXR }, 788c2ecf20Sopenharmony_ci { IN_FUNC_U6CTS, U6CTSR }, 798c2ecf20Sopenharmony_ci { IN_FUNC_SDI1, SDI1R }, 808c2ecf20Sopenharmony_ci { IN_FUNC_SDI3, SDI3R }, 818c2ecf20Sopenharmony_ci { IN_FUNC_SDI5, SDI5R }, 828c2ecf20Sopenharmony_ci { IN_FUNC_SS6, SS6R }, 838c2ecf20Sopenharmony_ci { IN_FUNC_REFCLKI1, REFCLKI1R }, 848c2ecf20Sopenharmony_ci { IN_FUNC_INT4, INT4R }, 858c2ecf20Sopenharmony_ci { IN_FUNC_T5CK, T5CKR }, 868c2ecf20Sopenharmony_ci { IN_FUNC_T7CK, T7CKR }, 878c2ecf20Sopenharmony_ci { IN_FUNC_IC4, IC4R }, 888c2ecf20Sopenharmony_ci { IN_FUNC_IC8, IC8R }, 898c2ecf20Sopenharmony_ci { IN_FUNC_U3RX, U3RXR }, 908c2ecf20Sopenharmony_ci { IN_FUNC_U4CTS, U4CTSR }, 918c2ecf20Sopenharmony_ci { IN_FUNC_SDI2, SDI2R }, 928c2ecf20Sopenharmony_ci { IN_FUNC_SDI4, SDI4R }, 938c2ecf20Sopenharmony_ci { IN_FUNC_C1RX, C1RXR }, 948c2ecf20Sopenharmony_ci { IN_FUNC_REFCLKI4, REFCLKI4R }, 958c2ecf20Sopenharmony_ci { IN_FUNC_INT2, INT2R }, 968c2ecf20Sopenharmony_ci { IN_FUNC_T3CK, T3CKR }, 978c2ecf20Sopenharmony_ci { IN_FUNC_T8CK, T8CKR }, 988c2ecf20Sopenharmony_ci { IN_FUNC_IC2, IC2R }, 998c2ecf20Sopenharmony_ci { IN_FUNC_IC5, IC5R }, 1008c2ecf20Sopenharmony_ci { IN_FUNC_IC9, IC9R }, 1018c2ecf20Sopenharmony_ci { IN_FUNC_U1CTS, U1CTSR }, 1028c2ecf20Sopenharmony_ci { IN_FUNC_U2RX, U2RXR }, 1038c2ecf20Sopenharmony_ci { IN_FUNC_U5CTS, U5CTSR }, 1048c2ecf20Sopenharmony_ci { IN_FUNC_SS1, SS1R }, 1058c2ecf20Sopenharmony_ci { IN_FUNC_SS3, SS3R }, 1068c2ecf20Sopenharmony_ci { IN_FUNC_SS4, SS4R }, 1078c2ecf20Sopenharmony_ci { IN_FUNC_SS5, SS5R }, 1088c2ecf20Sopenharmony_ci { IN_FUNC_C2RX, C2RXR }, 1098c2ecf20Sopenharmony_ci { IN_FUNC_INT1, INT1R }, 1108c2ecf20Sopenharmony_ci { IN_FUNC_T4CK, T4CKR }, 1118c2ecf20Sopenharmony_ci { IN_FUNC_T9CK, T9CKR }, 1128c2ecf20Sopenharmony_ci { IN_FUNC_IC1, IC1R }, 1138c2ecf20Sopenharmony_ci { IN_FUNC_IC6, IC6R }, 1148c2ecf20Sopenharmony_ci { IN_FUNC_U3CTS, U3CTSR }, 1158c2ecf20Sopenharmony_ci { IN_FUNC_U4RX, U4RXR }, 1168c2ecf20Sopenharmony_ci { IN_FUNC_U6RX, U6RXR }, 1178c2ecf20Sopenharmony_ci { IN_FUNC_SS2, SS2R }, 1188c2ecf20Sopenharmony_ci { IN_FUNC_SDI6, SDI6R }, 1198c2ecf20Sopenharmony_ci { IN_FUNC_OCFA, OCFAR }, 1208c2ecf20Sopenharmony_ci { IN_FUNC_REFCLKI3, REFCLKI3R }, 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_civoid pic32_pps_input(int function, int pin) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci void __iomem *pps_base = ioremap(PPS_BASE, 0xF4); 1268c2ecf20Sopenharmony_ci int i; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(input_pin_reg); i++) { 1298c2ecf20Sopenharmony_ci if (input_pin_reg[i].function == function) { 1308c2ecf20Sopenharmony_ci __raw_writel(pin, pps_base + input_pin_reg[i].reg); 1318c2ecf20Sopenharmony_ci return; 1328c2ecf20Sopenharmony_ci } 1338c2ecf20Sopenharmony_ci } 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci iounmap(pps_base); 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* Output PPS Registers */ 1398c2ecf20Sopenharmony_ci#define RPA14R 0x1538 1408c2ecf20Sopenharmony_ci#define RPA15R 0x153C 1418c2ecf20Sopenharmony_ci#define RPB0R 0x1540 1428c2ecf20Sopenharmony_ci#define RPB1R 0x1544 1438c2ecf20Sopenharmony_ci#define RPB2R 0x1548 1448c2ecf20Sopenharmony_ci#define RPB3R 0x154C 1458c2ecf20Sopenharmony_ci#define RPB5R 0x1554 1468c2ecf20Sopenharmony_ci#define RPB6R 0x1558 1478c2ecf20Sopenharmony_ci#define RPB7R 0x155C 1488c2ecf20Sopenharmony_ci#define RPB8R 0x1560 1498c2ecf20Sopenharmony_ci#define RPB9R 0x1564 1508c2ecf20Sopenharmony_ci#define RPB10R 0x1568 1518c2ecf20Sopenharmony_ci#define RPB14R 0x1578 1528c2ecf20Sopenharmony_ci#define RPB15R 0x157C 1538c2ecf20Sopenharmony_ci#define RPC1R 0x1584 1548c2ecf20Sopenharmony_ci#define RPC2R 0x1588 1558c2ecf20Sopenharmony_ci#define RPC3R 0x158C 1568c2ecf20Sopenharmony_ci#define RPC4R 0x1590 1578c2ecf20Sopenharmony_ci#define RPC13R 0x15B4 1588c2ecf20Sopenharmony_ci#define RPC14R 0x15B8 1598c2ecf20Sopenharmony_ci#define RPD0R 0x15C0 1608c2ecf20Sopenharmony_ci#define RPD1R 0x15C4 1618c2ecf20Sopenharmony_ci#define RPD2R 0x15C8 1628c2ecf20Sopenharmony_ci#define RPD3R 0x15CC 1638c2ecf20Sopenharmony_ci#define RPD4R 0x15D0 1648c2ecf20Sopenharmony_ci#define RPD5R 0x15D4 1658c2ecf20Sopenharmony_ci#define RPD6R 0x15D8 1668c2ecf20Sopenharmony_ci#define RPD7R 0x15DC 1678c2ecf20Sopenharmony_ci#define RPD9R 0x15E4 1688c2ecf20Sopenharmony_ci#define RPD10R 0x15E8 1698c2ecf20Sopenharmony_ci#define RPD11R 0x15EC 1708c2ecf20Sopenharmony_ci#define RPD12R 0x15F0 1718c2ecf20Sopenharmony_ci#define RPD14R 0x15F8 1728c2ecf20Sopenharmony_ci#define RPD15R 0x15FC 1738c2ecf20Sopenharmony_ci#define RPE3R 0x160C 1748c2ecf20Sopenharmony_ci#define RPE5R 0x1614 1758c2ecf20Sopenharmony_ci#define RPE8R 0x1620 1768c2ecf20Sopenharmony_ci#define RPE9R 0x1624 1778c2ecf20Sopenharmony_ci#define RPF0R 0x1640 1788c2ecf20Sopenharmony_ci#define RPF1R 0x1644 1798c2ecf20Sopenharmony_ci#define RPF2R 0x1648 1808c2ecf20Sopenharmony_ci#define RPF3R 0x164C 1818c2ecf20Sopenharmony_ci#define RPF4R 0x1650 1828c2ecf20Sopenharmony_ci#define RPF5R 0x1654 1838c2ecf20Sopenharmony_ci#define RPF8R 0x1660 1848c2ecf20Sopenharmony_ci#define RPF12R 0x1670 1858c2ecf20Sopenharmony_ci#define RPF13R 0x1674 1868c2ecf20Sopenharmony_ci#define RPG0R 0x1680 1878c2ecf20Sopenharmony_ci#define RPG1R 0x1684 1888c2ecf20Sopenharmony_ci#define RPG6R 0x1698 1898c2ecf20Sopenharmony_ci#define RPG7R 0x169C 1908c2ecf20Sopenharmony_ci#define RPG8R 0x16A0 1918c2ecf20Sopenharmony_ci#define RPG9R 0x16A4 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic const struct 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci int pin; 1968c2ecf20Sopenharmony_ci int reg; 1978c2ecf20Sopenharmony_ci} output_pin_reg[] = { 1988c2ecf20Sopenharmony_ci { OUT_RPD2, RPD2R }, 1998c2ecf20Sopenharmony_ci { OUT_RPG8, RPG8R }, 2008c2ecf20Sopenharmony_ci { OUT_RPF4, RPF4R }, 2018c2ecf20Sopenharmony_ci { OUT_RPD10, RPD10R }, 2028c2ecf20Sopenharmony_ci { OUT_RPF1, RPF1R }, 2038c2ecf20Sopenharmony_ci { OUT_RPB9, RPB9R }, 2048c2ecf20Sopenharmony_ci { OUT_RPB10, RPB10R }, 2058c2ecf20Sopenharmony_ci { OUT_RPC14, RPC14R }, 2068c2ecf20Sopenharmony_ci { OUT_RPB5, RPB5R }, 2078c2ecf20Sopenharmony_ci { OUT_RPC1, RPC1R }, 2088c2ecf20Sopenharmony_ci { OUT_RPD14, RPD14R }, 2098c2ecf20Sopenharmony_ci { OUT_RPG1, RPG1R }, 2108c2ecf20Sopenharmony_ci { OUT_RPA14, RPA14R }, 2118c2ecf20Sopenharmony_ci { OUT_RPD6, RPD6R }, 2128c2ecf20Sopenharmony_ci { OUT_RPD3, RPD3R }, 2138c2ecf20Sopenharmony_ci { OUT_RPG7, RPG7R }, 2148c2ecf20Sopenharmony_ci { OUT_RPF5, RPF5R }, 2158c2ecf20Sopenharmony_ci { OUT_RPD11, RPD11R }, 2168c2ecf20Sopenharmony_ci { OUT_RPF0, RPF0R }, 2178c2ecf20Sopenharmony_ci { OUT_RPB1, RPB1R }, 2188c2ecf20Sopenharmony_ci { OUT_RPE5, RPE5R }, 2198c2ecf20Sopenharmony_ci { OUT_RPC13, RPC13R }, 2208c2ecf20Sopenharmony_ci { OUT_RPB3, RPB3R }, 2218c2ecf20Sopenharmony_ci { OUT_RPC4, RPC4R }, 2228c2ecf20Sopenharmony_ci { OUT_RPD15, RPD15R }, 2238c2ecf20Sopenharmony_ci { OUT_RPG0, RPG0R }, 2248c2ecf20Sopenharmony_ci { OUT_RPA15, RPA15R }, 2258c2ecf20Sopenharmony_ci { OUT_RPD7, RPD7R }, 2268c2ecf20Sopenharmony_ci { OUT_RPD9, RPD9R }, 2278c2ecf20Sopenharmony_ci { OUT_RPG6, RPG6R }, 2288c2ecf20Sopenharmony_ci { OUT_RPB8, RPB8R }, 2298c2ecf20Sopenharmony_ci { OUT_RPB15, RPB15R }, 2308c2ecf20Sopenharmony_ci { OUT_RPD4, RPD4R }, 2318c2ecf20Sopenharmony_ci { OUT_RPB0, RPB0R }, 2328c2ecf20Sopenharmony_ci { OUT_RPE3, RPE3R }, 2338c2ecf20Sopenharmony_ci { OUT_RPB7, RPB7R }, 2348c2ecf20Sopenharmony_ci { OUT_RPF12, RPF12R }, 2358c2ecf20Sopenharmony_ci { OUT_RPD12, RPD12R }, 2368c2ecf20Sopenharmony_ci { OUT_RPF8, RPF8R }, 2378c2ecf20Sopenharmony_ci { OUT_RPC3, RPC3R }, 2388c2ecf20Sopenharmony_ci { OUT_RPE9, RPE9R }, 2398c2ecf20Sopenharmony_ci { OUT_RPD1, RPD1R }, 2408c2ecf20Sopenharmony_ci { OUT_RPG9, RPG9R }, 2418c2ecf20Sopenharmony_ci { OUT_RPB14, RPB14R }, 2428c2ecf20Sopenharmony_ci { OUT_RPD0, RPD0R }, 2438c2ecf20Sopenharmony_ci { OUT_RPB6, RPB6R }, 2448c2ecf20Sopenharmony_ci { OUT_RPD5, RPD5R }, 2458c2ecf20Sopenharmony_ci { OUT_RPB2, RPB2R }, 2468c2ecf20Sopenharmony_ci { OUT_RPF3, RPF3R }, 2478c2ecf20Sopenharmony_ci { OUT_RPF13, RPF13R }, 2488c2ecf20Sopenharmony_ci { OUT_RPC2, RPC2R }, 2498c2ecf20Sopenharmony_ci { OUT_RPE8, RPE8R }, 2508c2ecf20Sopenharmony_ci { OUT_RPF2, RPF2R }, 2518c2ecf20Sopenharmony_ci}; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_civoid pic32_pps_output(int function, int pin) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci void __iomem *pps_base = ioremap(PPS_BASE, 0x170); 2568c2ecf20Sopenharmony_ci int i; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(output_pin_reg); i++) { 2598c2ecf20Sopenharmony_ci if (output_pin_reg[i].pin == pin) { 2608c2ecf20Sopenharmony_ci __raw_writel(function, 2618c2ecf20Sopenharmony_ci pps_base + output_pin_reg[i].reg); 2628c2ecf20Sopenharmony_ci return; 2638c2ecf20Sopenharmony_ci } 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci iounmap(pps_base); 2678c2ecf20Sopenharmony_ci} 268