2003-07-19 06:28:22 +02:00
|
|
|
#ifndef DEVICE_PNP_H
|
|
|
|
#define DEVICE_PNP_H
|
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <device/device.h>
|
2020-09-15 07:45:17 +02:00
|
|
|
/* When <device/pnp.h> is needed, it supposed to provide <device/pnp_{def,type}.h> */
|
2004-03-11 16:01:31 +01:00
|
|
|
#include <device/pnp_def.h>
|
2019-09-27 11:01:15 +02:00
|
|
|
#include <device/pnp_type.h>
|
2015-05-12 14:53:11 +02:00
|
|
|
#include <arch/io.h>
|
2004-03-11 16:01:31 +01:00
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#if !ENV_PNP_SIMPLE_DEVICE
|
2013-06-25 22:17:43 +02:00
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
/* Primitive PNP resource manipulation */
|
2018-09-19 14:42:02 +02:00
|
|
|
void pnp_write_config(struct device *dev, u8 reg, u8 value);
|
|
|
|
u8 pnp_read_config(struct device *dev, u8 reg);
|
|
|
|
void pnp_set_logical_device(struct device *dev);
|
|
|
|
void pnp_set_enable(struct device *dev, int enable);
|
|
|
|
int pnp_read_enable(struct device *dev);
|
|
|
|
void pnp_set_iobase(struct device *dev, u8 index, u16 iobase);
|
|
|
|
void pnp_set_irq(struct device *dev, u8 index, u8 irq);
|
|
|
|
void pnp_set_drq(struct device *dev, u8 index, u8 drq);
|
2004-03-11 16:01:31 +01:00
|
|
|
|
2019-09-27 11:01:15 +02:00
|
|
|
#endif
|
2019-08-17 17:29:02 +02:00
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
/* PNP device operations */
|
2018-09-19 14:42:02 +02:00
|
|
|
void pnp_read_resources(struct device *dev);
|
|
|
|
void pnp_set_resources(struct device *dev);
|
|
|
|
void pnp_enable_resources(struct device *dev);
|
|
|
|
void pnp_enable(struct device *dev);
|
|
|
|
void pnp_alt_enable(struct device *dev);
|
2004-03-11 16:01:31 +01:00
|
|
|
|
2009-03-13 16:42:27 +01:00
|
|
|
extern struct device_operations pnp_ops;
|
2004-03-11 16:01:31 +01:00
|
|
|
|
|
|
|
/* PNP helper operations */
|
|
|
|
|
|
|
|
struct pnp_info {
|
2018-07-06 19:38:24 +02:00
|
|
|
struct device_operations *ops; /* LDN-specific ops override */
|
2019-12-15 13:53:48 +01:00
|
|
|
#define PNP_SKIP_FUNCTION 0xffff
|
2019-12-15 13:51:19 +01:00
|
|
|
u16 function; /* Must be at least 16 bits (virtual LDNs)! */
|
2010-10-18 02:00:57 +02:00
|
|
|
unsigned int flags;
|
2015-12-28 13:04:47 +01:00
|
|
|
#define PNP_IO0 0x000001
|
|
|
|
#define PNP_IO1 0x000002
|
|
|
|
#define PNP_IO2 0x000004
|
|
|
|
#define PNP_IO3 0x000008
|
|
|
|
#define PNP_IRQ0 0x000010
|
|
|
|
#define PNP_IRQ1 0x000020
|
|
|
|
#define PNP_DRQ0 0x000040
|
|
|
|
#define PNP_DRQ1 0x000080
|
|
|
|
#define PNP_EN 0x000100
|
|
|
|
#define PNP_MSC0 0x000200
|
|
|
|
#define PNP_MSC1 0x000400
|
|
|
|
#define PNP_MSC2 0x000800
|
|
|
|
#define PNP_MSC3 0x001000
|
|
|
|
#define PNP_MSC4 0x002000
|
|
|
|
#define PNP_MSC5 0x004000
|
|
|
|
#define PNP_MSC6 0x008000
|
|
|
|
#define PNP_MSC7 0x010000
|
|
|
|
#define PNP_MSC8 0x020000
|
|
|
|
#define PNP_MSC9 0x040000
|
|
|
|
#define PNP_MSCA 0x080000
|
|
|
|
#define PNP_MSCB 0x100000
|
|
|
|
#define PNP_MSCC 0x200000
|
|
|
|
#define PNP_MSCD 0x400000
|
|
|
|
#define PNP_MSCE 0x800000
|
2017-06-07 05:55:01 +02:00
|
|
|
u16 io0, io1, io2, io3;
|
2004-03-11 16:01:31 +01:00
|
|
|
};
|
2018-09-19 14:42:02 +02:00
|
|
|
struct resource *pnp_get_resource(struct device *dev, unsigned int index);
|
2004-10-16 08:20:29 +02:00
|
|
|
void pnp_enable_devices(struct device *dev, struct device_operations *ops,
|
2010-10-18 02:00:57 +02:00
|
|
|
unsigned int functions, struct pnp_info *info);
|
2003-07-19 06:28:22 +02:00
|
|
|
|
2013-06-10 22:08:35 +02:00
|
|
|
struct pnp_mode_ops {
|
2018-09-19 14:42:02 +02:00
|
|
|
void (*enter_conf_mode)(struct device *dev);
|
|
|
|
void (*exit_conf_mode)(struct device *dev);
|
2019-12-10 13:15:42 +01:00
|
|
|
#if CONFIG(HAVE_ACPI_TABLES)
|
|
|
|
/*
|
|
|
|
* Generates ASL code to enter/exit config mode.
|
|
|
|
*
|
|
|
|
* @param idx The ACPI name of the SuperIO index port register. eg. 'INDX'.
|
|
|
|
* @param data The ACPI name of the SuperIO data port register. eg. 'DATA'.
|
|
|
|
*/
|
|
|
|
void (*ssdt_enter_conf_mode)(struct device *dev, const char *idx, const char *data);
|
|
|
|
void (*ssdt_exit_conf_mode)(struct device *dev, const char *idx, const char *data);
|
|
|
|
#endif
|
2013-06-10 22:08:35 +02:00
|
|
|
};
|
2018-09-19 14:42:02 +02:00
|
|
|
void pnp_enter_conf_mode(struct device *dev);
|
|
|
|
void pnp_exit_conf_mode(struct device *dev);
|
2019-12-10 13:15:42 +01:00
|
|
|
#if CONFIG(HAVE_ACPI_TABLES)
|
|
|
|
/*
|
|
|
|
* Generates ASL code to enter/exit config mode if supported.
|
|
|
|
* The calling code has to place this within an ASL MethodOP.
|
|
|
|
*
|
|
|
|
* @param idx The ACPI name of the SuperIO index port register. eg. 'INDX'.
|
|
|
|
* @param data The ACPI name of the SuperIO data port register. eg. 'DATA'.
|
|
|
|
*/
|
|
|
|
void pnp_ssdt_enter_conf_mode(struct device *dev, const char *idx, const char *data);
|
|
|
|
void pnp_ssdt_exit_conf_mode(struct device *dev, const char *idx, const char *data);
|
|
|
|
#endif
|
2015-05-12 14:53:11 +02:00
|
|
|
/* PNP indexed I/O operations */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* u8 pnp_read_index(u16 port, u8 reg)
|
|
|
|
* Description:
|
|
|
|
* This routine reads indexed I/O registers. The reg byte is written
|
|
|
|
* to the index register at I/O address = port. The result is then
|
|
|
|
* read from the data register at I/O address = port + 1.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* @param[in] u16 port = The I/O address of the port index register.
|
|
|
|
* @param[in] u8 reg = The offset within the indexed space.
|
|
|
|
* @param[out] u8 result = The value read back from the data register.
|
|
|
|
*/
|
|
|
|
static inline u8 pnp_read_index(u16 port, u8 reg)
|
|
|
|
{
|
|
|
|
outb(reg, port);
|
|
|
|
return inb(port + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void pnp_write_index(u16 port, u8 reg, u8 value)
|
|
|
|
* Description:
|
|
|
|
* This routine writes indexed I/O registers. The reg byte is written
|
|
|
|
* to the index register at I/O address = port. The value byte is then
|
|
|
|
* written to the data register at I/O address = port + 1.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* @param[in] u16 port = The address of the port index register.
|
|
|
|
* @param[in] u8 reg = The offset within the indexed space.
|
|
|
|
* @param[in] u8 value = The value to be written to the data register.
|
|
|
|
*/
|
|
|
|
static inline void pnp_write_index(u16 port, u8 reg, u8 value)
|
|
|
|
{
|
|
|
|
outb(reg, port);
|
|
|
|
outb(value, port + 1);
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:10:03 +02:00
|
|
|
/*
|
|
|
|
* void pnp_unset_and_set_index(u16 port, u8 reg, u8 unset, u8 set)
|
|
|
|
* Description:
|
|
|
|
* This routine unsets and sets bits from indexed I/O registers. The
|
|
|
|
* reg byte is written to the index register at I/O address = port.
|
|
|
|
* The value byte to update is data register at I/O address = port + 1.
|
|
|
|
*
|
|
|
|
* Unlike and-then-or style operations, no bitwise negation is necessary
|
|
|
|
* to specify the bits to unset. Because the bitwise negation implicitly
|
|
|
|
* promotes operands to int before operating, one may have to explicitly
|
|
|
|
* downcast the result if the data width is smaller than that of an int.
|
|
|
|
* Since warnings are errors in coreboot, explicit casting is necessary.
|
|
|
|
*
|
|
|
|
* Performing said negation inside this routine alleviates this problem,
|
|
|
|
* while allowing the compiler to warn if the input parameters overflow.
|
|
|
|
* Casting outside this function would silence valid compiler warnings.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* @param[in] u16 port = The address of the port index register.
|
|
|
|
* @param[in] u8 reg = The offset within the indexed space.
|
|
|
|
* @param[in] u8 unset = Bitmask with ones to the bits to unset from the data register.
|
|
|
|
* @param[in] u8 set = Bitmask with ones to the bits to set from the data register.
|
|
|
|
*/
|
|
|
|
static inline void pnp_unset_and_set_index(u16 port, u8 reg, u8 unset, u8 set)
|
|
|
|
{
|
|
|
|
outb(reg, port);
|
|
|
|
|
|
|
|
u8 value = inb(port + 1);
|
|
|
|
value &= (u8)~unset;
|
|
|
|
value |= set;
|
|
|
|
outb(value, port + 1);
|
|
|
|
}
|
|
|
|
|
2003-07-19 06:28:22 +02:00
|
|
|
#endif /* DEVICE_PNP_H */
|