xref: /aosp_15_r20/external/coreboot/src/include/device/pnp_ops.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef __DEVICE_PNP_OPS_H__
4 #define __DEVICE_PNP_OPS_H__
5 
6 #include <stdint.h>
7 #include <device/pnp.h>
8 
9 #if ENV_PNP_SIMPLE_DEVICE
10 
pnp_write_config(pnp_devfn_t dev,uint8_t reg,uint8_t value)11 static __always_inline void pnp_write_config(
12 	pnp_devfn_t dev, uint8_t reg, uint8_t value)
13 {
14 	pnp_write_index(dev >> 8, reg, value);
15 }
16 
pnp_read_config(pnp_devfn_t dev,uint8_t reg)17 static __always_inline uint8_t pnp_read_config(
18 	pnp_devfn_t dev, uint8_t reg)
19 {
20 	return pnp_read_index(dev >> 8, reg);
21 }
22 
pnp_unset_and_set_config(pnp_devfn_t dev,uint8_t reg,uint8_t unset,uint8_t set)23 static __always_inline void pnp_unset_and_set_config(
24 	pnp_devfn_t dev, uint8_t reg, uint8_t unset, uint8_t set)
25 {
26 	pnp_unset_and_set_index(dev >> 8, reg, unset, set);
27 }
28 
29 static __always_inline
pnp_set_logical_device(pnp_devfn_t dev)30 void pnp_set_logical_device(pnp_devfn_t dev)
31 {
32 	unsigned int device = dev & 0xff;
33 	pnp_write_config(dev, 0x07, device);
34 }
35 
36 static __always_inline
pnp_set_enable(pnp_devfn_t dev,int enable)37 void pnp_set_enable(pnp_devfn_t dev, int enable)
38 {
39 	pnp_write_config(dev, PNP_IDX_EN, enable?0x1:0x0);
40 }
41 
42 static __always_inline
pnp_read_enable(pnp_devfn_t dev)43 int pnp_read_enable(pnp_devfn_t dev)
44 {
45 	return !!pnp_read_config(dev, PNP_IDX_EN);
46 }
47 
48 static __always_inline
pnp_set_iobase(pnp_devfn_t dev,unsigned int index,unsigned int iobase)49 void pnp_set_iobase(pnp_devfn_t dev, unsigned int index, unsigned int iobase)
50 {
51 	pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff);
52 	pnp_write_config(dev, index + 1, iobase & 0xff);
53 }
54 
55 static __always_inline
pnp_read_iobase(pnp_devfn_t dev,unsigned int index)56 uint16_t pnp_read_iobase(pnp_devfn_t dev, unsigned int index)
57 {
58 	return ((uint16_t)(pnp_read_config(dev, index)) << 8)
59 		| pnp_read_config(dev, index + 1);
60 }
61 
62 static __always_inline
pnp_set_irq(pnp_devfn_t dev,unsigned int index,unsigned int irq)63 void pnp_set_irq(pnp_devfn_t dev, unsigned int index, unsigned int irq)
64 {
65 	pnp_write_config(dev, index, irq);
66 }
67 
68 static __always_inline
pnp_set_drq(pnp_devfn_t dev,unsigned int index,unsigned int drq)69 void pnp_set_drq(pnp_devfn_t dev, unsigned int index, unsigned int drq)
70 {
71 	pnp_write_config(dev, index, drq & 0xff);
72 }
73 
74 #endif
75 
76 #endif
77