1
0
mirror of https://github.com/DigitalDevices/dddvb.git synced 2023-10-10 13:37:43 +02:00
dddvb/ddbridge/octonet-main.c

170 lines
4.5 KiB
C
Raw Permalink Normal View History

2015-08-05 17:22:42 +02:00
/*
* octonet.c: Digital Devices network tuner driver
*
2017-05-17 19:42:25 +02:00
* Copyright (C) 2012-17 Digital Devices GmbH
2015-08-05 17:22:42 +02:00
* Marcus Metzler <mocm@metzlerbros.de>
* Ralph Metzler <rjkm@metzlerbros.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 only, as published by the Free Software Foundation.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, point your browser to
* http://www.gnu.org/copyleft/gpl.html
2015-08-05 17:22:42 +02:00
*/
#include "ddbridge.h"
2017-08-02 20:22:52 +02:00
#include "ddbridge-io.h"
2015-08-05 17:22:42 +02:00
static int __exit octonet_remove(struct platform_device *pdev)
{
struct ddb *dev;
dev = platform_get_drvdata(pdev);
ddb_device_destroy(dev);
2015-08-05 17:22:42 +02:00
ddb_nsd_detach(dev);
ddb_ports_detach(dev);
ddb_i2c_release(dev);
2015-12-10 18:26:45 +01:00
if (dev->link[0].info->ns_num)
ddbwritel(dev, 0, ETHER_CONTROL);
2015-08-05 17:22:42 +02:00
ddbwritel(dev, 0, INTERRUPT_ENABLE);
2015-12-10 18:26:45 +01:00
free_irq(platform_get_irq(dev->pfdev, 0), dev);
2015-08-05 17:22:42 +02:00
ddb_ports_release(dev);
ddb_unmap(dev);
2015-08-05 17:22:42 +02:00
platform_set_drvdata(pdev, 0);
return 0;
}
static int __init octonet_probe(struct platform_device *pdev)
{
struct ddb *dev;
struct resource *regs;
int irq;
2017-08-26 22:04:37 +02:00
dev = vzalloc(sizeof(*dev));
2015-08-05 17:22:42 +02:00
if (!dev)
return -ENOMEM;
platform_set_drvdata(pdev, dev);
dev->dev = &pdev->dev;
dev->pfdev = pdev;
mutex_init(&dev->mutex);
regs = platform_get_resource(dev->pfdev, IORESOURCE_MEM, 0);
if (!regs)
return -ENXIO;
dev->regs_len = (regs->end - regs->start) + 1;
dev_info(dev->dev, "regs_start=%08x regs_len=%08x\n",
2017-08-26 22:04:37 +02:00
(u32)regs->start, (u32)dev->regs_len);
2015-08-05 17:22:42 +02:00
dev->regs = ioremap(regs->start, dev->regs_len);
if (!dev->regs) {
dev_err(dev->dev, "ioremap failed\n");
return -ENOMEM;
}
dev->link[0].ids.hwid = ddbreadl(dev, 0);
dev->link[0].ids.regmapid = ddbreadl(dev, 4);
dev->link[0].ids.devid = ddbreadl(dev, 8);
dev->link[0].ids.mac = ddbreadl(dev, 12);
2015-08-05 17:22:42 +02:00
dev->link[0].ids.vendor = dev->link[0].ids.devid & 0xffff;
dev->link[0].ids.device = dev->link[0].ids.devid >> 16;
dev->link[0].ids.subvendor = dev->link[0].ids.devid & 0xffff;
dev->link[0].ids.subdevice = dev->link[0].ids.devid >> 16;
2015-08-05 17:22:42 +02:00
dev->link[0].dev = dev;
dev->link[0].info = get_ddb_info(dev->link[0].ids.vendor,
dev->link[0].ids.device,
0xdd01, 0xffff);
dev_info(dev->dev, "DDBridge: HW %08x REGMAP %08x\n",
dev->link[0].ids.hwid, dev->link[0].ids.regmapid);
dev_info(dev->dev, "DDBridge: MAC %08x DEVID %08x\n",
dev->link[0].ids.mac, dev->link[0].ids.devid);
2015-08-05 17:22:42 +02:00
ddbwritel(dev, 0, ETHER_CONTROL);
ddbwritel(dev, 0x00000000, INTERRUPT_ENABLE);
ddbwritel(dev, 0xffffffff, INTERRUPT_STATUS);
2016-05-02 16:27:32 +02:00
ddb_reset_ios(dev);
2015-08-05 17:22:42 +02:00
irq = platform_get_irq(dev->pfdev, 0);
if (irq < 0)
goto fail;
if (request_irq(irq, ddb_irq_handler,
2015-08-05 17:22:42 +02:00
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2017-08-26 22:04:37 +02:00
"octonet-dvb", (void *)dev) < 0)
2015-08-05 17:22:42 +02:00
goto fail;
ddbwritel(dev, 0x0fffff0f, INTERRUPT_ENABLE);
if (ddb_init(dev) == 0)
return 0;
fail:
dev_err(dev->dev, "fail\n");
ddbwritel(dev, 0, ETHER_CONTROL);
ddbwritel(dev, 0, INTERRUPT_ENABLE);
ddb_unmap(dev);
2015-08-05 17:22:42 +02:00
platform_set_drvdata(pdev, 0);
return -1;
}
#ifdef CONFIG_OF
static const struct of_device_id octonet_dt_ids[] = {
{ .compatible = "digitaldevices,octonet-dvb" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, octonet_dt_ids);
#endif
2017-07-18 00:23:13 +02:00
static struct platform_driver octonet_driver __refdata = {
2015-08-05 17:22:42 +02:00
.remove = __exit_p(octonet_remove),
.probe = octonet_probe,
.driver = {
.name = "octonet-dvb",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = of_match_ptr(octonet_dt_ids),
#endif
},
};
static __init int init_octonet(void)
{
int stat;
2015-08-05 17:22:42 +02:00
2016-10-10 00:19:16 +02:00
pr_info("DDBridge: Digital Devices OctopusNet driver " DDBRIDGE_VERSION
", Copyright (C) 2010-17 Digital Devices GmbH\n");
stat = ddb_init_ddbridge();
if (stat < 0)
return stat;
stat = platform_driver_probe(&octonet_driver, octonet_probe);
if (stat < 0)
ddb_exit_ddbridge(0, stat);
return stat;
2015-08-05 17:22:42 +02:00
}
static __exit void exit_octonet(void)
{
platform_driver_unregister(&octonet_driver);
ddb_exit_ddbridge(0, 0);
2015-08-05 17:22:42 +02:00
}
module_init(init_octonet);
module_exit(exit_octonet);
MODULE_DESCRIPTION("GPL");
MODULE_AUTHOR("Marcus and Ralph Metzler, Metzler Brothers Systementwicklung GbR");
MODULE_LICENSE("GPL v2");
MODULE_VERSION(DDBRIDGE_VERSION);