Subject: [PATCH] [acpi video] Add exported functions to attach/detach video devices to bus - Create bus-lib.c - Create video_bus_{attach,detach}() that will associate an ACPI video device (that has been bound) to the corresponding entry in the bus's array of attached devices (got via _DOD) - Export functions, so video driver can use them Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/video/Makefile | 2 + drivers/acpi/drivers/video/bus-lib.c | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletions(-) create mode 100644 drivers/acpi/drivers/video/bus-lib.c applies-to: 9329c66da499389077cdf2bb58fb8918c1109946 637eefdb91fa684bfcb4e916ac09e7141360c47b diff --git a/drivers/acpi/drivers/video/Makefile b/drivers/acpi/drivers/video/Makefile index 715e390..4157305 100644 --- a/drivers/acpi/drivers/video/Makefile +++ b/drivers/acpi/drivers/video/Makefile @@ -4,7 +4,7 @@ obj-$(CONFIG_ACPI_VIDEO) += video-bus.o # Video Bus Driver # video-bus-y := bus-driver.o bus-device.o -video-bus-y += bus-event.o +video-bus-y += bus-event.o bus-lib.o video-bus-$(CONFIG_ACPI_DM_PROC) += bus-proc.o video-bus-$(CONFIG_ACPI_DM_SYSFS) += bus-sysfs.o diff --git a/drivers/acpi/drivers/video/bus-lib.c b/drivers/acpi/drivers/video/bus-lib.c new file mode 100644 index 0000000..3e413e5 --- /dev/null +++ b/drivers/acpi/drivers/video/bus-lib.c @@ -0,0 +1,63 @@ +/*** + * drivers/acpi/drivers/video/bus-lib.c - Exported functions for video devices + * + * Copyright (C) 2006 Patrick Mochel + * + * Based on drivers/acpi/video.c, which was + * Copyright (C) 2004 Luming Yu + * Copyright (C) 2004 Bruno Ducrot + * + * This file is released under the GPLv2. + */ + +#include "video.h" + + +static struct acpi_video_bus * get_video_bus(struct acpi_video_dev * vd) +{ + if (vd->v_ad->dev.parent && vd->v_ad->dev.parent->driver) + return dev_get_drvdata(vd->v_ad->dev.parent); + return NULL; +} + + +int video_bus_attach(struct acpi_video_dev * vd) +{ + struct acpi_video_bus * vb; + int i; + + vb = get_video_bus(vd); + if (!vb) + return -EINVAL; + + for (i = 0; i < vb->v_dev_num; i++) { + if (!vb->v_dev[i].v_device) { + if (vb->v_dev[i].v_device_id == vd->v_id) { + vd->v_bus_id = i; + vb->v_dev[i].v_device = vd; + return 0; + } + } + } + return -ENODEV; +} + +EXPORT_SYMBOL_GPL(video_bus_attach); + + +void video_bus_detach(struct acpi_video_dev * vd) +{ + struct acpi_video_bus * vb; + int i = vd->v_bus_id; + + vb = get_video_bus(vd); + if (vb) { + if (i < vb->v_dev_num && vb->v_dev[i].v_device == vd) { + vb->v_dev[i].v_device = NULL; + vd->v_bus_id = 0; + } + } +} + +EXPORT_SYMBOL_GPL(video_bus_detach); + --- 0.99.9.GIT