xref: /linux-6.15/include/linux/cs5535.h (revision 25763b3c)
1*25763b3cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
25f0a96b0SAndres Salomon /*
35f0a96b0SAndres Salomon  * AMD CS5535/CS5536 definitions
45f0a96b0SAndres Salomon  * Copyright (C) 2006  Advanced Micro Devices, Inc.
55f0a96b0SAndres Salomon  * Copyright (C) 2009  Andres Salomon <[email protected]>
65f0a96b0SAndres Salomon  */
75f0a96b0SAndres Salomon 
85f0a96b0SAndres Salomon #ifndef _CS5535_H
95f0a96b0SAndres Salomon #define _CS5535_H
105f0a96b0SAndres Salomon 
117bc74b3dSDaniel Drake #include <asm/msr.h>
127bc74b3dSDaniel Drake 
135f0a96b0SAndres Salomon /* MSRs */
14f3a57a60SAndres Salomon #define MSR_GLIU_P2D_RO0	0x10000029
15f3a57a60SAndres Salomon 
16f3a57a60SAndres Salomon #define MSR_LX_GLD_MSR_CONFIG	0x48002001
17f3a57a60SAndres Salomon #define MSR_LX_MSR_PADSEL	0x48002011	/* NOT 0x48000011; the data
18f3a57a60SAndres Salomon 						 * sheet has the wrong value */
19f3a57a60SAndres Salomon #define MSR_GLCP_SYS_RSTPLL	0x4C000014
20f3a57a60SAndres Salomon #define MSR_GLCP_DOTPLL		0x4C000015
21f3a57a60SAndres Salomon 
225f0a96b0SAndres Salomon #define MSR_LBAR_SMB		0x5140000B
235f0a96b0SAndres Salomon #define MSR_LBAR_GPIO		0x5140000C
245f0a96b0SAndres Salomon #define MSR_LBAR_MFGPT		0x5140000D
255f0a96b0SAndres Salomon #define MSR_LBAR_ACPI		0x5140000E
265f0a96b0SAndres Salomon #define MSR_LBAR_PMS		0x5140000F
275f0a96b0SAndres Salomon 
282e8c1243SAndres Salomon #define MSR_DIVIL_SOFT_RESET	0x51400017
292e8c1243SAndres Salomon 
3082dca611SAndres Salomon #define MSR_PIC_YSEL_LOW	0x51400020
3182dca611SAndres Salomon #define MSR_PIC_YSEL_HIGH	0x51400021
3282dca611SAndres Salomon #define MSR_PIC_ZSEL_LOW	0x51400022
3382dca611SAndres Salomon #define MSR_PIC_ZSEL_HIGH	0x51400023
3482dca611SAndres Salomon #define MSR_PIC_IRQM_LPC	0x51400025
3582dca611SAndres Salomon 
3682dca611SAndres Salomon #define MSR_MFGPT_IRQ		0x51400028
3782dca611SAndres Salomon #define MSR_MFGPT_NR		0x51400029
3882dca611SAndres Salomon #define MSR_MFGPT_SETUP		0x5140002B
3982dca611SAndres Salomon 
40cfee9597SDaniel Drake #define MSR_RTC_DOMA_OFFSET	0x51400055
41cfee9597SDaniel Drake #define MSR_RTC_MONA_OFFSET	0x51400056
42cfee9597SDaniel Drake #define MSR_RTC_CEN_OFFSET	0x51400057
43cfee9597SDaniel Drake 
44f3a57a60SAndres Salomon #define MSR_LX_SPARE_MSR	0x80000011	/* DC-specific */
45f3a57a60SAndres Salomon 
46f3a57a60SAndres Salomon #define MSR_GX_GLD_MSR_CONFIG	0xC0002001
47f3a57a60SAndres Salomon #define MSR_GX_MSR_PADSEL	0xC0002011
48f3a57a60SAndres Salomon 
cs5535_pic_unreqz_select_high(unsigned int group,unsigned int irq)497bc74b3dSDaniel Drake static inline int cs5535_pic_unreqz_select_high(unsigned int group,
507bc74b3dSDaniel Drake 						unsigned int irq)
517bc74b3dSDaniel Drake {
527bc74b3dSDaniel Drake 	uint32_t lo, hi;
537bc74b3dSDaniel Drake 
547bc74b3dSDaniel Drake 	rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
557bc74b3dSDaniel Drake 	lo &= ~(0xF << (group * 4));
567bc74b3dSDaniel Drake 	lo |= (irq & 0xF) << (group * 4);
577bc74b3dSDaniel Drake 	wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
587bc74b3dSDaniel Drake 	return 0;
597bc74b3dSDaniel Drake }
607bc74b3dSDaniel Drake 
617feda8e9SDaniel Drake /* PIC registers */
627feda8e9SDaniel Drake #define CS5536_PIC_INT_SEL1	0x4d0
637feda8e9SDaniel Drake #define CS5536_PIC_INT_SEL2	0x4d1
647feda8e9SDaniel Drake 
655f0a96b0SAndres Salomon /* resource sizes */
665f0a96b0SAndres Salomon #define LBAR_GPIO_SIZE		0xFF
675f0a96b0SAndres Salomon #define LBAR_MFGPT_SIZE		0x40
685f0a96b0SAndres Salomon #define LBAR_ACPI_SIZE		0x40
695f0a96b0SAndres Salomon #define LBAR_PMS_SIZE		0x80
705f0a96b0SAndres Salomon 
717a0d4fcfSDaniel Drake /*
727a0d4fcfSDaniel Drake  * PMC registers (PMS block)
737a0d4fcfSDaniel Drake  * It is only safe to access these registers as dword accesses.
747a0d4fcfSDaniel Drake  * See CS5536 Specification Update erratas 17 & 18
757a0d4fcfSDaniel Drake  */
767a0d4fcfSDaniel Drake #define CS5536_PM_SCLK		0x10
777a0d4fcfSDaniel Drake #define CS5536_PM_IN_SLPCTL	0x20
787a0d4fcfSDaniel Drake #define CS5536_PM_WKXD		0x34
797a0d4fcfSDaniel Drake #define CS5536_PM_WKD		0x30
807a0d4fcfSDaniel Drake #define CS5536_PM_SSC		0x54
817a0d4fcfSDaniel Drake 
827a0d4fcfSDaniel Drake /*
837a0d4fcfSDaniel Drake  * PM registers (ACPI block)
847a0d4fcfSDaniel Drake  * It is only safe to access these registers as dword accesses.
857a0d4fcfSDaniel Drake  * See CS5536 Specification Update erratas 17 & 18
867a0d4fcfSDaniel Drake  */
877a0d4fcfSDaniel Drake #define CS5536_PM1_STS		0x00
887a0d4fcfSDaniel Drake #define CS5536_PM1_EN		0x02
897a0d4fcfSDaniel Drake #define CS5536_PM1_CNT		0x08
907a0d4fcfSDaniel Drake #define CS5536_PM_GPE0_STS	0x18
917bc74b3dSDaniel Drake #define CS5536_PM_GPE0_EN	0x1c
927a0d4fcfSDaniel Drake 
937feda8e9SDaniel Drake /* CS5536_PM1_STS bits */
947feda8e9SDaniel Drake #define CS5536_WAK_FLAG		(1 << 15)
95c2c21e9bSDaniel Drake #define CS5536_RTC_FLAG		(1 << 10)
967feda8e9SDaniel Drake #define CS5536_PWRBTN_FLAG	(1 << 8)
977feda8e9SDaniel Drake 
9897c4cb71SDaniel Drake /* CS5536_PM1_EN bits */
9997c4cb71SDaniel Drake #define CS5536_PM_PWRBTN	(1 << 8)
100cfee9597SDaniel Drake #define CS5536_PM_RTC		(1 << 10)
10197c4cb71SDaniel Drake 
1027bc74b3dSDaniel Drake /* CS5536_PM_GPE0_STS bits */
1037bc74b3dSDaniel Drake #define CS5536_GPIOM7_PME_FLAG	(1 << 31)
1047bc74b3dSDaniel Drake #define CS5536_GPIOM6_PME_FLAG	(1 << 30)
1057bc74b3dSDaniel Drake 
1067bc74b3dSDaniel Drake /* CS5536_PM_GPE0_EN bits */
1077bc74b3dSDaniel Drake #define CS5536_GPIOM7_PME_EN	(1 << 31)
1082cf2baeaSDaniel Drake #define CS5536_GPIOM6_PME_EN	(1 << 30)
1097bc74b3dSDaniel Drake 
110f060f270SAndres Salomon /* VSA2 magic values */
111f060f270SAndres Salomon #define VSA_VRC_INDEX		0xAC1C
112f060f270SAndres Salomon #define VSA_VRC_DATA		0xAC1E
113f060f270SAndres Salomon #define VSA_VR_UNLOCK		0xFC53  /* unlock virtual register */
114f060f270SAndres Salomon #define VSA_VR_SIGNATURE	0x0003
115f060f270SAndres Salomon #define VSA_VR_MEM_SIZE		0x0200
116f060f270SAndres Salomon #define AMD_VSA_SIG		0x4132  /* signature is ascii 'VSA2' */
117f060f270SAndres Salomon #define GSW_VSA_SIG		0x534d  /* General Software signature */
118f060f270SAndres Salomon 
119f060f270SAndres Salomon #include <linux/io.h>
120f060f270SAndres Salomon 
cs5535_has_vsa2(void)121f060f270SAndres Salomon static inline int cs5535_has_vsa2(void)
122f060f270SAndres Salomon {
123f060f270SAndres Salomon 	static int has_vsa2 = -1;
124f060f270SAndres Salomon 
125f060f270SAndres Salomon 	if (has_vsa2 == -1) {
126f060f270SAndres Salomon 		uint16_t val;
127f060f270SAndres Salomon 
128f060f270SAndres Salomon 		/*
129f060f270SAndres Salomon 		 * The VSA has virtual registers that we can query for a
130f060f270SAndres Salomon 		 * signature.
131f060f270SAndres Salomon 		 */
132f060f270SAndres Salomon 		outw(VSA_VR_UNLOCK, VSA_VRC_INDEX);
133f060f270SAndres Salomon 		outw(VSA_VR_SIGNATURE, VSA_VRC_INDEX);
134f060f270SAndres Salomon 
135f060f270SAndres Salomon 		val = inw(VSA_VRC_DATA);
136f060f270SAndres Salomon 		has_vsa2 = (val == AMD_VSA_SIG || val == GSW_VSA_SIG);
137f060f270SAndres Salomon 	}
138f060f270SAndres Salomon 
139f060f270SAndres Salomon 	return has_vsa2;
140f060f270SAndres Salomon }
141f060f270SAndres Salomon 
1425f0a96b0SAndres Salomon /* GPIOs */
1435f0a96b0SAndres Salomon #define GPIO_OUTPUT_VAL		0x00
1445f0a96b0SAndres Salomon #define GPIO_OUTPUT_ENABLE	0x04
1455f0a96b0SAndres Salomon #define GPIO_OUTPUT_OPEN_DRAIN	0x08
1465f0a96b0SAndres Salomon #define GPIO_OUTPUT_INVERT	0x0C
1475f0a96b0SAndres Salomon #define GPIO_OUTPUT_AUX1	0x10
1485f0a96b0SAndres Salomon #define GPIO_OUTPUT_AUX2	0x14
1495f0a96b0SAndres Salomon #define GPIO_PULL_UP		0x18
1505f0a96b0SAndres Salomon #define GPIO_PULL_DOWN		0x1C
1515f0a96b0SAndres Salomon #define GPIO_INPUT_ENABLE	0x20
1525f0a96b0SAndres Salomon #define GPIO_INPUT_INVERT	0x24
1535f0a96b0SAndres Salomon #define GPIO_INPUT_FILTER	0x28
1545f0a96b0SAndres Salomon #define GPIO_INPUT_EVENT_COUNT	0x2C
1555f0a96b0SAndres Salomon #define GPIO_READ_BACK		0x30
1565f0a96b0SAndres Salomon #define GPIO_INPUT_AUX1		0x34
1575f0a96b0SAndres Salomon #define GPIO_EVENTS_ENABLE	0x38
1585f0a96b0SAndres Salomon #define GPIO_LOCK_ENABLE	0x3C
1595f0a96b0SAndres Salomon #define GPIO_POSITIVE_EDGE_EN	0x40
1605f0a96b0SAndres Salomon #define GPIO_NEGATIVE_EDGE_EN	0x44
1615f0a96b0SAndres Salomon #define GPIO_POSITIVE_EDGE_STS	0x48
1625f0a96b0SAndres Salomon #define GPIO_NEGATIVE_EDGE_STS	0x4C
1635f0a96b0SAndres Salomon 
1647637c925SAndres Salomon #define GPIO_FLTR7_AMOUNT	0xD8
1657637c925SAndres Salomon 
1665f0a96b0SAndres Salomon #define GPIO_MAP_X		0xE0
1675f0a96b0SAndres Salomon #define GPIO_MAP_Y		0xE4
1685f0a96b0SAndres Salomon #define GPIO_MAP_Z		0xE8
1695f0a96b0SAndres Salomon #define GPIO_MAP_W		0xEC
1705f0a96b0SAndres Salomon 
1717637c925SAndres Salomon #define GPIO_FE7_SEL		0xF7
1727637c925SAndres Salomon 
1735f0a96b0SAndres Salomon void cs5535_gpio_set(unsigned offset, unsigned int reg);
1745f0a96b0SAndres Salomon void cs5535_gpio_clear(unsigned offset, unsigned int reg);
1755f0a96b0SAndres Salomon int cs5535_gpio_isset(unsigned offset, unsigned int reg);
1761b912c1bSAndres Salomon int cs5535_gpio_set_irq(unsigned group, unsigned irq);
1771b912c1bSAndres Salomon void cs5535_gpio_setup_event(unsigned offset, int pair, int pme);
1785f0a96b0SAndres Salomon 
17982dca611SAndres Salomon /* MFGPTs */
18082dca611SAndres Salomon 
18182dca611SAndres Salomon #define MFGPT_MAX_TIMERS	8
18282dca611SAndres Salomon #define MFGPT_TIMER_ANY		(-1)
18382dca611SAndres Salomon 
18482dca611SAndres Salomon #define MFGPT_DOMAIN_WORKING	1
18582dca611SAndres Salomon #define MFGPT_DOMAIN_STANDBY	2
18682dca611SAndres Salomon #define MFGPT_DOMAIN_ANY	(MFGPT_DOMAIN_WORKING | MFGPT_DOMAIN_STANDBY)
18782dca611SAndres Salomon 
18882dca611SAndres Salomon #define MFGPT_CMP1		0
18982dca611SAndres Salomon #define MFGPT_CMP2		1
19082dca611SAndres Salomon 
19182dca611SAndres Salomon #define MFGPT_EVENT_IRQ		0
19282dca611SAndres Salomon #define MFGPT_EVENT_NMI		1
19382dca611SAndres Salomon #define MFGPT_EVENT_RESET	3
19482dca611SAndres Salomon 
19582dca611SAndres Salomon #define MFGPT_REG_CMP1		0
19682dca611SAndres Salomon #define MFGPT_REG_CMP2		2
19782dca611SAndres Salomon #define MFGPT_REG_COUNTER	4
19882dca611SAndres Salomon #define MFGPT_REG_SETUP		6
19982dca611SAndres Salomon 
20082dca611SAndres Salomon #define MFGPT_SETUP_CNTEN	(1 << 15)
20182dca611SAndres Salomon #define MFGPT_SETUP_CMP2	(1 << 14)
20282dca611SAndres Salomon #define MFGPT_SETUP_CMP1	(1 << 13)
20382dca611SAndres Salomon #define MFGPT_SETUP_SETUP	(1 << 12)
20482dca611SAndres Salomon #define MFGPT_SETUP_STOPEN	(1 << 11)
20582dca611SAndres Salomon #define MFGPT_SETUP_EXTEN	(1 << 10)
20682dca611SAndres Salomon #define MFGPT_SETUP_REVEN	(1 << 5)
20782dca611SAndres Salomon #define MFGPT_SETUP_CLKSEL	(1 << 4)
20882dca611SAndres Salomon 
20982dca611SAndres Salomon struct cs5535_mfgpt_timer;
21082dca611SAndres Salomon 
21182dca611SAndres Salomon extern uint16_t cs5535_mfgpt_read(struct cs5535_mfgpt_timer *timer,
21282dca611SAndres Salomon 		uint16_t reg);
21382dca611SAndres Salomon extern void cs5535_mfgpt_write(struct cs5535_mfgpt_timer *timer, uint16_t reg,
21482dca611SAndres Salomon 		uint16_t value);
21582dca611SAndres Salomon 
21682dca611SAndres Salomon extern int cs5535_mfgpt_toggle_event(struct cs5535_mfgpt_timer *timer, int cmp,
21782dca611SAndres Salomon 		int event, int enable);
21882dca611SAndres Salomon extern int cs5535_mfgpt_set_irq(struct cs5535_mfgpt_timer *timer, int cmp,
21982dca611SAndres Salomon 		int *irq, int enable);
22082dca611SAndres Salomon extern struct cs5535_mfgpt_timer *cs5535_mfgpt_alloc_timer(int timer,
22182dca611SAndres Salomon 		int domain);
22282dca611SAndres Salomon extern void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer);
22382dca611SAndres Salomon 
cs5535_mfgpt_setup_irq(struct cs5535_mfgpt_timer * timer,int cmp,int * irq)22482dca611SAndres Salomon static inline int cs5535_mfgpt_setup_irq(struct cs5535_mfgpt_timer *timer,
22582dca611SAndres Salomon 		int cmp, int *irq)
22682dca611SAndres Salomon {
22782dca611SAndres Salomon 	return cs5535_mfgpt_set_irq(timer, cmp, irq, 1);
22882dca611SAndres Salomon }
22982dca611SAndres Salomon 
cs5535_mfgpt_release_irq(struct cs5535_mfgpt_timer * timer,int cmp,int * irq)23082dca611SAndres Salomon static inline int cs5535_mfgpt_release_irq(struct cs5535_mfgpt_timer *timer,
23182dca611SAndres Salomon 		int cmp, int *irq)
23282dca611SAndres Salomon {
23382dca611SAndres Salomon 	return cs5535_mfgpt_set_irq(timer, cmp, irq, 0);
23482dca611SAndres Salomon }
23582dca611SAndres Salomon 
2365f0a96b0SAndres Salomon #endif
237