pnp: Implement common handling for PnP config modes
Many super i/o chips only answer to PnP requests if they are in a configuration state (sometimes also called ext func mode). To cope with that, the code of many chips implements its own version of our default PnP functions like pnp_set_resource(), pnp_enable_resource() etc. To avoid this code duplication, this patch extends our PnP device interface with optional functions to enter and exit configuration mode. Change-Id: I9b7662a0db70ede93276764fa15020f251eb46bd Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: http://review.coreboot.org/3481 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
f898f7ba4d
commit
dd4715b6a5
|
@ -6,6 +6,7 @@
|
||||||
* Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov>
|
* Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov>
|
||||||
* Copyright (C) 2005 Tyan
|
* Copyright (C) 2005 Tyan
|
||||||
* (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
|
* (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
|
||||||
|
* Copyright (C) 2013 Nico Huber <nico.h@gmx.de>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -29,6 +30,20 @@
|
||||||
#include <device/device.h>
|
#include <device/device.h>
|
||||||
#include <device/pnp.h>
|
#include <device/pnp.h>
|
||||||
|
|
||||||
|
/* PNP config mode wrappers */
|
||||||
|
|
||||||
|
void pnp_enter_conf_mode(device_t dev)
|
||||||
|
{
|
||||||
|
if (dev->ops->ops_pnp_mode)
|
||||||
|
dev->ops->ops_pnp_mode->enter_conf_mode(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pnp_exit_conf_mode(device_t dev)
|
||||||
|
{
|
||||||
|
if (dev->ops->ops_pnp_mode)
|
||||||
|
dev->ops->ops_pnp_mode->exit_conf_mode(dev);
|
||||||
|
}
|
||||||
|
|
||||||
/* PNP fundamental operations */
|
/* PNP fundamental operations */
|
||||||
|
|
||||||
void pnp_write_config(device_t dev, u8 reg, u8 value)
|
void pnp_write_config(device_t dev, u8 reg, u8 value)
|
||||||
|
@ -133,32 +148,42 @@ void pnp_set_resources(device_t dev)
|
||||||
{
|
{
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
|
||||||
|
pnp_enter_conf_mode(dev);
|
||||||
|
|
||||||
/* Select the logical device (LDN). */
|
/* Select the logical device (LDN). */
|
||||||
pnp_set_logical_device(dev);
|
pnp_set_logical_device(dev);
|
||||||
|
|
||||||
/* Paranoia says I should disable the device here... */
|
/* Paranoia says I should disable the device here... */
|
||||||
for (res = dev->resource_list; res; res = res->next)
|
for (res = dev->resource_list; res; res = res->next)
|
||||||
pnp_set_resource(dev, res);
|
pnp_set_resource(dev, res);
|
||||||
|
|
||||||
|
pnp_exit_conf_mode(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pnp_enable_resources(device_t dev)
|
void pnp_enable_resources(device_t dev)
|
||||||
{
|
{
|
||||||
|
pnp_enter_conf_mode(dev);
|
||||||
pnp_set_logical_device(dev);
|
pnp_set_logical_device(dev);
|
||||||
pnp_set_enable(dev, 1);
|
pnp_set_enable(dev, 1);
|
||||||
|
pnp_exit_conf_mode(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pnp_enable(device_t dev)
|
void pnp_enable(device_t dev)
|
||||||
{
|
{
|
||||||
if (!dev->enabled) {
|
if (!dev->enabled) {
|
||||||
|
pnp_enter_conf_mode(dev);
|
||||||
pnp_set_logical_device(dev);
|
pnp_set_logical_device(dev);
|
||||||
pnp_set_enable(dev, 0);
|
pnp_set_enable(dev, 0);
|
||||||
|
pnp_exit_conf_mode(dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pnp_alt_enable(device_t dev)
|
void pnp_alt_enable(device_t dev)
|
||||||
{
|
{
|
||||||
|
pnp_enter_conf_mode(dev);
|
||||||
pnp_set_logical_device(dev);
|
pnp_set_logical_device(dev);
|
||||||
pnp_set_enable(dev, !!dev->enabled);
|
pnp_set_enable(dev, !!dev->enabled);
|
||||||
|
pnp_exit_conf_mode(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct device_operations pnp_ops = {
|
struct device_operations pnp_ops = {
|
||||||
|
|
|
@ -13,6 +13,7 @@ typedef struct device * device_t;
|
||||||
struct pci_operations;
|
struct pci_operations;
|
||||||
struct pci_bus_operations;
|
struct pci_bus_operations;
|
||||||
struct smbus_bus_operations;
|
struct smbus_bus_operations;
|
||||||
|
struct pnp_mode_ops;
|
||||||
|
|
||||||
/* Chip operations */
|
/* Chip operations */
|
||||||
struct chip_operations {
|
struct chip_operations {
|
||||||
|
@ -42,6 +43,7 @@ struct device_operations {
|
||||||
const struct pci_operations *ops_pci;
|
const struct pci_operations *ops_pci;
|
||||||
const struct smbus_bus_operations *ops_smbus_bus;
|
const struct smbus_bus_operations *ops_smbus_bus;
|
||||||
const struct pci_bus_operations *ops_pci_bus;
|
const struct pci_bus_operations *ops_pci_bus;
|
||||||
|
const struct pnp_mode_ops *ops_pnp_mode;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -52,5 +52,12 @@ struct resource *pnp_get_resource(device_t dev, unsigned index);
|
||||||
void pnp_enable_devices(struct device *dev, struct device_operations *ops,
|
void pnp_enable_devices(struct device *dev, struct device_operations *ops,
|
||||||
unsigned int functions, struct pnp_info *info);
|
unsigned int functions, struct pnp_info *info);
|
||||||
|
|
||||||
|
struct pnp_mode_ops {
|
||||||
|
void (*enter_conf_mode)(device_t dev);
|
||||||
|
void (*exit_conf_mode)(device_t dev);
|
||||||
|
};
|
||||||
|
void pnp_enter_conf_mode(device_t dev);
|
||||||
|
void pnp_exit_conf_mode(device_t dev);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif /* DEVICE_PNP_H */
|
#endif /* DEVICE_PNP_H */
|
||||||
|
|
Loading…
Reference in New Issue