Commit 865d7ec9 authored by Ondrej Zary's avatar Ondrej Zary Committed by Mauro Carvalho Chehab

[media] radio-isa: PnP support for the new ISA radio framework

Add PnP support to the new ISA radio framework.
Signed-off-by: default avatarOndrej Zary <linux@rainbow-software.org>
Reviewed-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 8766e865
...@@ -199,56 +199,31 @@ static bool radio_isa_valid_io(const struct radio_isa_driver *drv, int io) ...@@ -199,56 +199,31 @@ static bool radio_isa_valid_io(const struct radio_isa_driver *drv, int io)
return false; return false;
} }
int radio_isa_probe(struct device *pdev, unsigned int dev) struct radio_isa_card *radio_isa_alloc(struct radio_isa_driver *drv,
struct device *pdev)
{ {
struct radio_isa_driver *drv = pdev->platform_data;
const struct radio_isa_ops *ops = drv->ops;
struct v4l2_device *v4l2_dev; struct v4l2_device *v4l2_dev;
struct radio_isa_card *isa; struct radio_isa_card *isa = drv->ops->alloc();
int res; if (!isa)
return NULL;
isa = drv->ops->alloc();
if (isa == NULL)
return -ENOMEM;
dev_set_drvdata(pdev, isa); dev_set_drvdata(pdev, isa);
isa->drv = drv; isa->drv = drv;
isa->io = drv->io_params[dev];
v4l2_dev = &isa->v4l2_dev; v4l2_dev = &isa->v4l2_dev;
strlcpy(v4l2_dev->name, dev_name(pdev), sizeof(v4l2_dev->name)); strlcpy(v4l2_dev->name, dev_name(pdev), sizeof(v4l2_dev->name));
if (drv->probe && ops->probe) { return isa;
int i; }
for (i = 0; i < drv->num_of_io_ports; ++i) {
int io = drv->io_ports[i];
if (request_region(io, drv->region_size, v4l2_dev->name)) {
bool found = ops->probe(isa, io);
release_region(io, drv->region_size);
if (found) {
isa->io = io;
break;
}
}
}
}
if (!radio_isa_valid_io(drv, isa->io)) {
int i;
if (isa->io < 0) int radio_isa_common_probe(struct radio_isa_card *isa, struct device *pdev,
return -ENODEV; int radio_nr, unsigned region_size)
v4l2_err(v4l2_dev, "you must set an I/O address with io=0x%03x", {
drv->io_ports[0]); const struct radio_isa_driver *drv = isa->drv;
for (i = 1; i < drv->num_of_io_ports; i++) const struct radio_isa_ops *ops = drv->ops;
printk(KERN_CONT "/0x%03x", drv->io_ports[i]); struct v4l2_device *v4l2_dev = &isa->v4l2_dev;
printk(KERN_CONT ".\n"); int res;
kfree(isa);
return -EINVAL;
}
if (!request_region(isa->io, drv->region_size, v4l2_dev->name)) { if (!request_region(isa->io, region_size, v4l2_dev->name)) {
v4l2_err(v4l2_dev, "port 0x%x already in use\n", isa->io); v4l2_err(v4l2_dev, "port 0x%x already in use\n", isa->io);
kfree(isa); kfree(isa);
return -EBUSY; return -EBUSY;
...@@ -301,8 +276,8 @@ int radio_isa_probe(struct device *pdev, unsigned int dev) ...@@ -301,8 +276,8 @@ int radio_isa_probe(struct device *pdev, unsigned int dev)
v4l2_err(v4l2_dev, "Could not setup card\n"); v4l2_err(v4l2_dev, "Could not setup card\n");
goto err_node_reg; goto err_node_reg;
} }
res = video_register_device(&isa->vdev, VFL_TYPE_RADIO, res = video_register_device(&isa->vdev, VFL_TYPE_RADIO, radio_nr);
drv->radio_nr_params[dev]);
if (res < 0) { if (res < 0) {
v4l2_err(v4l2_dev, "Could not register device node\n"); v4l2_err(v4l2_dev, "Could not register device node\n");
goto err_node_reg; goto err_node_reg;
...@@ -317,24 +292,110 @@ int radio_isa_probe(struct device *pdev, unsigned int dev) ...@@ -317,24 +292,110 @@ int radio_isa_probe(struct device *pdev, unsigned int dev)
err_hdl: err_hdl:
v4l2_device_unregister(&isa->v4l2_dev); v4l2_device_unregister(&isa->v4l2_dev);
err_dev_reg: err_dev_reg:
release_region(isa->io, drv->region_size); release_region(isa->io, region_size);
kfree(isa); kfree(isa);
return res; return res;
} }
EXPORT_SYMBOL_GPL(radio_isa_probe);
int radio_isa_remove(struct device *pdev, unsigned int dev) int radio_isa_common_remove(struct radio_isa_card *isa, unsigned region_size)
{ {
struct radio_isa_card *isa = dev_get_drvdata(pdev);
const struct radio_isa_ops *ops = isa->drv->ops; const struct radio_isa_ops *ops = isa->drv->ops;
ops->s_mute_volume(isa, true, isa->volume ? isa->volume->cur.val : 0); ops->s_mute_volume(isa, true, isa->volume ? isa->volume->cur.val : 0);
video_unregister_device(&isa->vdev); video_unregister_device(&isa->vdev);
v4l2_ctrl_handler_free(&isa->hdl); v4l2_ctrl_handler_free(&isa->hdl);
v4l2_device_unregister(&isa->v4l2_dev); v4l2_device_unregister(&isa->v4l2_dev);
release_region(isa->io, isa->drv->region_size); release_region(isa->io, region_size);
v4l2_info(&isa->v4l2_dev, "Removed radio card %s\n", isa->drv->card); v4l2_info(&isa->v4l2_dev, "Removed radio card %s\n", isa->drv->card);
kfree(isa); kfree(isa);
return 0; return 0;
} }
int radio_isa_probe(struct device *pdev, unsigned int dev)
{
struct radio_isa_driver *drv = pdev->platform_data;
const struct radio_isa_ops *ops = drv->ops;
struct v4l2_device *v4l2_dev;
struct radio_isa_card *isa;
isa = radio_isa_alloc(drv, pdev);
if (!isa)
return -ENOMEM;
isa->io = drv->io_params[dev];
v4l2_dev = &isa->v4l2_dev;
if (drv->probe && ops->probe) {
int i;
for (i = 0; i < drv->num_of_io_ports; ++i) {
int io = drv->io_ports[i];
if (request_region(io, drv->region_size, v4l2_dev->name)) {
bool found = ops->probe(isa, io);
release_region(io, drv->region_size);
if (found) {
isa->io = io;
break;
}
}
}
}
if (!radio_isa_valid_io(drv, isa->io)) {
int i;
if (isa->io < 0)
return -ENODEV;
v4l2_err(v4l2_dev, "you must set an I/O address with io=0x%03x",
drv->io_ports[0]);
for (i = 1; i < drv->num_of_io_ports; i++)
printk(KERN_CONT "/0x%03x", drv->io_ports[i]);
printk(KERN_CONT ".\n");
kfree(isa);
return -EINVAL;
}
return radio_isa_common_probe(isa, pdev, drv->radio_nr_params[dev],
drv->region_size);
}
EXPORT_SYMBOL_GPL(radio_isa_probe);
int radio_isa_remove(struct device *pdev, unsigned int dev)
{
struct radio_isa_card *isa = dev_get_drvdata(pdev);
return radio_isa_common_remove(isa, isa->drv->region_size);
}
EXPORT_SYMBOL_GPL(radio_isa_remove); EXPORT_SYMBOL_GPL(radio_isa_remove);
#ifdef CONFIG_PNP
int radio_isa_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
{
struct pnp_driver *pnp_drv = to_pnp_driver(dev->dev.driver);
struct radio_isa_driver *drv = container_of(pnp_drv,
struct radio_isa_driver, pnp_driver);
struct radio_isa_card *isa;
if (!pnp_port_valid(dev, 0))
return -ENODEV;
isa = radio_isa_alloc(drv, &dev->dev);
if (!isa)
return -ENOMEM;
isa->io = pnp_port_start(dev, 0);
return radio_isa_common_probe(isa, &dev->dev, drv->radio_nr_params[0],
pnp_port_len(dev, 0));
}
EXPORT_SYMBOL_GPL(radio_isa_pnp_probe);
void radio_isa_pnp_remove(struct pnp_dev *dev)
{
struct radio_isa_card *isa = dev_get_drvdata(&dev->dev);
radio_isa_common_remove(isa, pnp_port_len(dev, 0));
}
EXPORT_SYMBOL_GPL(radio_isa_pnp_remove);
#endif
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define _RADIO_ISA_H_ #define _RADIO_ISA_H_
#include <linux/isa.h> #include <linux/isa.h>
#include <linux/pnp.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h> #include <media/v4l2-ctrls.h>
...@@ -76,6 +77,9 @@ struct radio_isa_ops { ...@@ -76,6 +77,9 @@ struct radio_isa_ops {
/* Top level structure needed to instantiate the cards */ /* Top level structure needed to instantiate the cards */
struct radio_isa_driver { struct radio_isa_driver {
struct isa_driver driver; struct isa_driver driver;
#ifdef CONFIG_PNP
struct pnp_driver pnp_driver;
#endif
const struct radio_isa_ops *ops; const struct radio_isa_ops *ops;
/* The module_param_array with the specified I/O ports */ /* The module_param_array with the specified I/O ports */
int *io_params; int *io_params;
...@@ -101,5 +105,10 @@ struct radio_isa_driver { ...@@ -101,5 +105,10 @@ struct radio_isa_driver {
int radio_isa_match(struct device *pdev, unsigned int dev); int radio_isa_match(struct device *pdev, unsigned int dev);
int radio_isa_probe(struct device *pdev, unsigned int dev); int radio_isa_probe(struct device *pdev, unsigned int dev);
int radio_isa_remove(struct device *pdev, unsigned int dev); int radio_isa_remove(struct device *pdev, unsigned int dev);
#ifdef CONFIG_PNP
int radio_isa_pnp_probe(struct pnp_dev *dev,
const struct pnp_device_id *dev_id);
void radio_isa_pnp_remove(struct pnp_dev *dev);
#endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment