18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Apple Peripheral System Controller (PSC) 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * The PSC is used on the AV Macs to control IO functions not handled 68c2ecf20Sopenharmony_ci * by the VIAs (Ethernet, DSP, SCC, Sound). This includes nine DMA 78c2ecf20Sopenharmony_ci * channels. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * The first seven DMA channels appear to be "one-shot" and are actually 108c2ecf20Sopenharmony_ci * sets of two channels; one member is active while the other is being 118c2ecf20Sopenharmony_ci * configured, and then you flip the active member and start all over again. 128c2ecf20Sopenharmony_ci * The one-shot channels are grouped together and are: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * 1. SCSI 158c2ecf20Sopenharmony_ci * 2. Ethernet Read 168c2ecf20Sopenharmony_ci * 3. Ethernet Write 178c2ecf20Sopenharmony_ci * 4. Floppy Disk Controller 188c2ecf20Sopenharmony_ci * 5. SCC Channel A Receive 198c2ecf20Sopenharmony_ci * 6. SCC Channel B Receive 208c2ecf20Sopenharmony_ci * 7. SCC Channel A Transmit 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * The remaining two channels are handled somewhat differently. They appear 238c2ecf20Sopenharmony_ci * to be closely tied and share one set of registers. They also seem to run 248c2ecf20Sopenharmony_ci * continuously, although how you keep the buffer filled in this scenario is 258c2ecf20Sopenharmony_ci * not understood as there seems to be only one input and one output buffer 268c2ecf20Sopenharmony_ci * pointer. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * Much of this was extrapolated from what was known about the Ethernet 298c2ecf20Sopenharmony_ci * registers and subsequently confirmed using MacsBug (ie by pinging the 308c2ecf20Sopenharmony_ci * machine with easy-to-find patterns and looking for them in the DMA 318c2ecf20Sopenharmony_ci * buffers, or by sending a file over the serial ports and finding the 328c2ecf20Sopenharmony_ci * file in the buffers.) 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * 1999-05-25 (jmt) 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define PSC_BASE (0x50F31000) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * The IER/IFR registers work like the VIA, except that it has 4 418c2ecf20Sopenharmony_ci * of them each on different interrupt levels, and each register 428c2ecf20Sopenharmony_ci * set only seems to handle four interrupts instead of seven. 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * To access a particular set of registers, add 0xn0 to the base 458c2ecf20Sopenharmony_ci * where n = 3,4,5 or 6. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define pIFRbase 0x100 498c2ecf20Sopenharmony_ci#define pIERbase 0x104 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* 528c2ecf20Sopenharmony_ci * One-shot DMA control registers 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define PSC_MYSTERY 0x804 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define PSC_CTL_BASE 0xC00 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define PSC_SCSI_CTL 0xC00 608c2ecf20Sopenharmony_ci#define PSC_ENETRD_CTL 0xC10 618c2ecf20Sopenharmony_ci#define PSC_ENETWR_CTL 0xC20 628c2ecf20Sopenharmony_ci#define PSC_FDC_CTL 0xC30 638c2ecf20Sopenharmony_ci#define PSC_SCCA_CTL 0xC40 648c2ecf20Sopenharmony_ci#define PSC_SCCB_CTL 0xC50 658c2ecf20Sopenharmony_ci#define PSC_SCCATX_CTL 0xC60 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* 688c2ecf20Sopenharmony_ci * DMA channels. Add +0x10 for the second channel in the set. 698c2ecf20Sopenharmony_ci * You're supposed to use one channel while the other runs and 708c2ecf20Sopenharmony_ci * then flip channels and do the whole thing again. 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define PSC_ADDR_BASE 0x1000 748c2ecf20Sopenharmony_ci#define PSC_LEN_BASE 0x1004 758c2ecf20Sopenharmony_ci#define PSC_CMD_BASE 0x1008 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define PSC_SET0 0x00 788c2ecf20Sopenharmony_ci#define PSC_SET1 0x10 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define PSC_SCSI_ADDR 0x1000 /* confirmed */ 818c2ecf20Sopenharmony_ci#define PSC_SCSI_LEN 0x1004 /* confirmed */ 828c2ecf20Sopenharmony_ci#define PSC_SCSI_CMD 0x1008 /* confirmed */ 838c2ecf20Sopenharmony_ci#define PSC_ENETRD_ADDR 0x1020 /* confirmed */ 848c2ecf20Sopenharmony_ci#define PSC_ENETRD_LEN 0x1024 /* confirmed */ 858c2ecf20Sopenharmony_ci#define PSC_ENETRD_CMD 0x1028 /* confirmed */ 868c2ecf20Sopenharmony_ci#define PSC_ENETWR_ADDR 0x1040 /* confirmed */ 878c2ecf20Sopenharmony_ci#define PSC_ENETWR_LEN 0x1044 /* confirmed */ 888c2ecf20Sopenharmony_ci#define PSC_ENETWR_CMD 0x1048 /* confirmed */ 898c2ecf20Sopenharmony_ci#define PSC_FDC_ADDR 0x1060 /* strongly suspected */ 908c2ecf20Sopenharmony_ci#define PSC_FDC_LEN 0x1064 /* strongly suspected */ 918c2ecf20Sopenharmony_ci#define PSC_FDC_CMD 0x1068 /* strongly suspected */ 928c2ecf20Sopenharmony_ci#define PSC_SCCA_ADDR 0x1080 /* confirmed */ 938c2ecf20Sopenharmony_ci#define PSC_SCCA_LEN 0x1084 /* confirmed */ 948c2ecf20Sopenharmony_ci#define PSC_SCCA_CMD 0x1088 /* confirmed */ 958c2ecf20Sopenharmony_ci#define PSC_SCCB_ADDR 0x10A0 /* confirmed */ 968c2ecf20Sopenharmony_ci#define PSC_SCCB_LEN 0x10A4 /* confirmed */ 978c2ecf20Sopenharmony_ci#define PSC_SCCB_CMD 0x10A8 /* confirmed */ 988c2ecf20Sopenharmony_ci#define PSC_SCCATX_ADDR 0x10C0 /* confirmed */ 998c2ecf20Sopenharmony_ci#define PSC_SCCATX_LEN 0x10C4 /* confirmed */ 1008c2ecf20Sopenharmony_ci#define PSC_SCCATX_CMD 0x10C8 /* confirmed */ 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* 1038c2ecf20Sopenharmony_ci * Free-running DMA registers. The only part known for sure are the bits in 1048c2ecf20Sopenharmony_ci * the control register, the buffer addresses and the buffer length. Everything 1058c2ecf20Sopenharmony_ci * else is anybody's guess. 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * These registers seem to be mirrored every thirty-two bytes up until offset 1088c2ecf20Sopenharmony_ci * 0x300. It's safe to assume then that a new set of registers starts there. 1098c2ecf20Sopenharmony_ci */ 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define PSC_SND_CTL 0x200 /* 1128c2ecf20Sopenharmony_ci * [ 16-bit ] 1138c2ecf20Sopenharmony_ci * Sound (Singer?) control register. 1148c2ecf20Sopenharmony_ci * 1158c2ecf20Sopenharmony_ci * bit 0 : ???? 1168c2ecf20Sopenharmony_ci * bit 1 : ???? 1178c2ecf20Sopenharmony_ci * bit 2 : Set to one to enable sound 1188c2ecf20Sopenharmony_ci * output. Possibly a mute flag. 1198c2ecf20Sopenharmony_ci * bit 3 : ???? 1208c2ecf20Sopenharmony_ci * bit 4 : ???? 1218c2ecf20Sopenharmony_ci * bit 5 : ???? 1228c2ecf20Sopenharmony_ci * bit 6 : Set to one to enable pass-thru 1238c2ecf20Sopenharmony_ci * audio. In this mode the audio data 1248c2ecf20Sopenharmony_ci * seems to appear in both the input 1258c2ecf20Sopenharmony_ci * buffer and the output buffer. 1268c2ecf20Sopenharmony_ci * bit 7 : Set to one to activate the 1278c2ecf20Sopenharmony_ci * sound input DMA or zero to 1288c2ecf20Sopenharmony_ci * disable it. 1298c2ecf20Sopenharmony_ci * bit 8 : Set to one to activate the 1308c2ecf20Sopenharmony_ci * sound output DMA or zero to 1318c2ecf20Sopenharmony_ci * disable it. 1328c2ecf20Sopenharmony_ci * bit 9 : \ 1338c2ecf20Sopenharmony_ci * bit 11 : | 1348c2ecf20Sopenharmony_ci * These two bits control the sample 1358c2ecf20Sopenharmony_ci * rate. Usually set to binary 10 and 1368c2ecf20Sopenharmony_ci * MacOS 8.0 says I'm at 48 KHz. Using 1378c2ecf20Sopenharmony_ci * a binary value of 01 makes things 1388c2ecf20Sopenharmony_ci * sound about 1/2 speed (24 KHz?) and 1398c2ecf20Sopenharmony_ci * binary 00 is slower still (22 KHz?) 1408c2ecf20Sopenharmony_ci * 1418c2ecf20Sopenharmony_ci * Setting this to 0x0000 is a good way to 1428c2ecf20Sopenharmony_ci * kill all DMA at boot time so that the 1438c2ecf20Sopenharmony_ci * PSC won't overwrite the kernel image 1448c2ecf20Sopenharmony_ci * with sound data. 1458c2ecf20Sopenharmony_ci */ 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* 1488c2ecf20Sopenharmony_ci * 0x0202 - 0x0203 is unused. Writing there 1498c2ecf20Sopenharmony_ci * seems to clobber the control register. 1508c2ecf20Sopenharmony_ci */ 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define PSC_SND_SOURCE 0x204 /* 1538c2ecf20Sopenharmony_ci * [ 32-bit ] 1548c2ecf20Sopenharmony_ci * Controls input source and volume: 1558c2ecf20Sopenharmony_ci * 1568c2ecf20Sopenharmony_ci * bits 12-15 : input source volume, 0 - F 1578c2ecf20Sopenharmony_ci * bits 16-19 : unknown, always 0x5 1588c2ecf20Sopenharmony_ci * bits 20-23 : input source selection: 1598c2ecf20Sopenharmony_ci * 0x3 = CD Audio 1608c2ecf20Sopenharmony_ci * 0x4 = External Audio 1618c2ecf20Sopenharmony_ci * 1628c2ecf20Sopenharmony_ci * The volume is definitely not the general 1638c2ecf20Sopenharmony_ci * output volume as it doesn't affect the 1648c2ecf20Sopenharmony_ci * alert sound volume. 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ci#define PSC_SND_STATUS1 0x208 /* 1678c2ecf20Sopenharmony_ci * [ 32-bit ] 1688c2ecf20Sopenharmony_ci * Appears to be a read-only status register. 1698c2ecf20Sopenharmony_ci * The usual value is 0x00400002. 1708c2ecf20Sopenharmony_ci */ 1718c2ecf20Sopenharmony_ci#define PSC_SND_HUH3 0x20C /* 1728c2ecf20Sopenharmony_ci * [ 16-bit ] 1738c2ecf20Sopenharmony_ci * Unknown 16-bit value, always 0x0000. 1748c2ecf20Sopenharmony_ci */ 1758c2ecf20Sopenharmony_ci#define PSC_SND_BITS2GO 0x20E /* 1768c2ecf20Sopenharmony_ci * [ 16-bit ] 1778c2ecf20Sopenharmony_ci * Counts down to zero from some constant 1788c2ecf20Sopenharmony_ci * value. The value appears to be the 1798c2ecf20Sopenharmony_ci * number of _bits_ remaining before the 1808c2ecf20Sopenharmony_ci * buffer is full, which would make sense 1818c2ecf20Sopenharmony_ci * since Apple's docs say the sound DMA 1828c2ecf20Sopenharmony_ci * channels are 1 bit wide. 1838c2ecf20Sopenharmony_ci */ 1848c2ecf20Sopenharmony_ci#define PSC_SND_INADDR 0x210 /* 1858c2ecf20Sopenharmony_ci * [ 32-bit ] 1868c2ecf20Sopenharmony_ci * Address of the sound input DMA buffer 1878c2ecf20Sopenharmony_ci */ 1888c2ecf20Sopenharmony_ci#define PSC_SND_OUTADDR 0x214 /* 1898c2ecf20Sopenharmony_ci * [ 32-bit ] 1908c2ecf20Sopenharmony_ci * Address of the sound output DMA buffer 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_ci#define PSC_SND_LEN 0x218 /* 1938c2ecf20Sopenharmony_ci * [ 16-bit ] 1948c2ecf20Sopenharmony_ci * Length of both buffers in eight-byte units. 1958c2ecf20Sopenharmony_ci */ 1968c2ecf20Sopenharmony_ci#define PSC_SND_HUH4 0x21A /* 1978c2ecf20Sopenharmony_ci * [ 16-bit ] 1988c2ecf20Sopenharmony_ci * Unknown, always 0x0000. 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_ci#define PSC_SND_STATUS2 0x21C /* 2018c2ecf20Sopenharmony_ci * [ 16-bit ] 2028c2ecf20Sopenharmony_ci * Appears to e a read-only status register. 2038c2ecf20Sopenharmony_ci * The usual value is 0x0200. 2048c2ecf20Sopenharmony_ci */ 2058c2ecf20Sopenharmony_ci#define PSC_SND_HUH5 0x21E /* 2068c2ecf20Sopenharmony_ci * [ 16-bit ] 2078c2ecf20Sopenharmony_ci * Unknown, always 0x0000. 2088c2ecf20Sopenharmony_ci */ 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ciextern volatile __u8 *psc; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciextern void psc_register_interrupts(void); 2158c2ecf20Sopenharmony_ciextern void psc_irq_enable(int); 2168c2ecf20Sopenharmony_ciextern void psc_irq_disable(int); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci/* 2198c2ecf20Sopenharmony_ci * Access functions 2208c2ecf20Sopenharmony_ci */ 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic inline void psc_write_byte(int offset, __u8 data) 2238c2ecf20Sopenharmony_ci{ 2248c2ecf20Sopenharmony_ci *((volatile __u8 *)(psc + offset)) = data; 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_cistatic inline void psc_write_word(int offset, __u16 data) 2288c2ecf20Sopenharmony_ci{ 2298c2ecf20Sopenharmony_ci *((volatile __u16 *)(psc + offset)) = data; 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic inline void psc_write_long(int offset, __u32 data) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci *((volatile __u32 *)(psc + offset)) = data; 2358c2ecf20Sopenharmony_ci} 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistatic inline u8 psc_read_byte(int offset) 2388c2ecf20Sopenharmony_ci{ 2398c2ecf20Sopenharmony_ci return *((volatile __u8 *)(psc + offset)); 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic inline u16 psc_read_word(int offset) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci return *((volatile __u16 *)(psc + offset)); 2458c2ecf20Sopenharmony_ci} 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic inline u32 psc_read_long(int offset) 2488c2ecf20Sopenharmony_ci{ 2498c2ecf20Sopenharmony_ci return *((volatile __u32 *)(psc + offset)); 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 253