Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * MEN Chameleon Bus.
  4 *
  5 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
  6 * Author: Johannes Thumshirn <johannes.thumshirn@men.de>
 
 
 
 
  7 */
  8
  9#include <linux/module.h>
 10#include <linux/pci.h>
 11#include <linux/mcb.h>
 12
 13#include "mcb-internal.h"
 14
 15struct priv {
 16	struct mcb_bus *bus;
 17	phys_addr_t mapbase;
 18	void __iomem *base;
 19};
 20
 21static int mcb_pci_get_irq(struct mcb_device *mdev)
 22{
 23	struct mcb_bus *mbus = mdev->bus;
 24	struct device *dev = mbus->carrier;
 25	struct pci_dev *pdev = to_pci_dev(dev);
 26
 27	return pdev->irq;
 28}
 29
 30static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 31{
 32	struct resource *res;
 33	struct priv *priv;
 34	int ret, table_size;
 
 35	unsigned long flags;
 36
 37	priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
 38	if (!priv)
 39		return -ENOMEM;
 40
 41	ret = pci_enable_device(pdev);
 42	if (ret) {
 43		dev_err(&pdev->dev, "Failed to enable PCI device\n");
 44		return -ENODEV;
 45	}
 46	pci_set_master(pdev);
 47
 48	priv->mapbase = pci_resource_start(pdev, 0);
 49	if (!priv->mapbase) {
 50		dev_err(&pdev->dev, "No PCI resource\n");
 51		ret = -ENODEV;
 52		goto out_disable;
 53	}
 54
 55	res = devm_request_mem_region(&pdev->dev, priv->mapbase,
 56				      CHAM_HEADER_SIZE,
 57				      KBUILD_MODNAME);
 58	if (!res) {
 59		dev_err(&pdev->dev, "Failed to request PCI memory\n");
 60		ret = -EBUSY;
 61		goto out_disable;
 62	}
 63
 64	priv->base = devm_ioremap(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE);
 65	if (!priv->base) {
 66		dev_err(&pdev->dev, "Cannot ioremap\n");
 67		ret = -ENOMEM;
 68		goto out_disable;
 69	}
 70
 71	flags = pci_resource_flags(pdev, 0);
 72	if (flags & IORESOURCE_IO) {
 73		ret = -ENOTSUPP;
 74		dev_err(&pdev->dev,
 75			"IO mapped PCI devices are not supported\n");
 76		goto out_disable;
 77	}
 78
 79	pci_set_drvdata(pdev, priv);
 80
 81	priv->bus = mcb_alloc_bus(&pdev->dev);
 82	if (IS_ERR(priv->bus)) {
 83		ret = PTR_ERR(priv->bus);
 84		goto out_disable;
 85	}
 86
 87	priv->bus->get_irq = mcb_pci_get_irq;
 88
 89	ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
 90	if (ret < 0)
 91		goto out_mcb_bus;
 
 92
 93	table_size = ret;
 94
 95	if (table_size < CHAM_HEADER_SIZE) {
 96		/* Release the previous resources */
 97		devm_iounmap(&pdev->dev, priv->base);
 98		devm_release_mem_region(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE);
 99
100		/* Then, allocate it again with the actual chameleon table size */
101		res = devm_request_mem_region(&pdev->dev, priv->mapbase,
102						table_size,
103						KBUILD_MODNAME);
104		if (!res) {
105			dev_err(&pdev->dev, "Failed to request PCI memory\n");
106			ret = -EBUSY;
107			goto out_mcb_bus;
108		}
109
110		priv->base = devm_ioremap(&pdev->dev, priv->mapbase, table_size);
111		if (!priv->base) {
112			dev_err(&pdev->dev, "Cannot ioremap\n");
113			ret = -ENOMEM;
114			goto out_mcb_bus;
115		}
116	}
117
118	mcb_bus_add_devices(priv->bus);
119
120	return 0;
121
122out_mcb_bus:
123	mcb_release_bus(priv->bus);
 
 
 
 
124out_disable:
125	pci_disable_device(pdev);
126	return ret;
127}
128
129static void mcb_pci_remove(struct pci_dev *pdev)
130{
131	struct priv *priv = pci_get_drvdata(pdev);
132
133	mcb_release_bus(priv->bus);
134
 
 
135	pci_disable_device(pdev);
136}
137
138static const struct pci_device_id mcb_pci_tbl[] = {
139	{ PCI_DEVICE(PCI_VENDOR_ID_MEN, PCI_DEVICE_ID_MEN_CHAMELEON) },
140	{ PCI_DEVICE(PCI_VENDOR_ID_ALTERA, PCI_DEVICE_ID_MEN_CHAMELEON) },
141	{ 0 },
142};
143MODULE_DEVICE_TABLE(pci, mcb_pci_tbl);
144
145static struct pci_driver mcb_pci_driver = {
146	.name = "mcb-pci",
147	.id_table = mcb_pci_tbl,
148	.probe = mcb_pci_probe,
149	.remove = mcb_pci_remove,
150};
151
152module_pci_driver(mcb_pci_driver);
153
154MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>");
155MODULE_LICENSE("GPL");
156MODULE_DESCRIPTION("MCB over PCI support");
157MODULE_IMPORT_NS(MCB);
v4.6
 
  1/*
  2 * MEN Chameleon Bus.
  3 *
  4 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
  5 * Author: Johannes Thumshirn <johannes.thumshirn@men.de>
  6 *
  7 * This program is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU General Public License as published by the Free
  9 * Software Foundation; version 2 of the License.
 10 */
 11
 12#include <linux/module.h>
 13#include <linux/pci.h>
 14#include <linux/mcb.h>
 15
 16#include "mcb-internal.h"
 17
 18struct priv {
 19	struct mcb_bus *bus;
 20	phys_addr_t mapbase;
 21	void __iomem *base;
 22};
 23
 24static int mcb_pci_get_irq(struct mcb_device *mdev)
 25{
 26	struct mcb_bus *mbus = mdev->bus;
 27	struct device *dev = mbus->carrier;
 28	struct pci_dev *pdev = to_pci_dev(dev);
 29
 30	return pdev->irq;
 31}
 32
 33static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 34{
 35	struct resource *res;
 36	struct priv *priv;
 37	int ret;
 38	int num_cells;
 39	unsigned long flags;
 40
 41	priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
 42	if (!priv)
 43		return -ENOMEM;
 44
 45	ret = pci_enable_device(pdev);
 46	if (ret) {
 47		dev_err(&pdev->dev, "Failed to enable PCI device\n");
 48		return -ENODEV;
 49	}
 
 50
 51	priv->mapbase = pci_resource_start(pdev, 0);
 52	if (!priv->mapbase) {
 53		dev_err(&pdev->dev, "No PCI resource\n");
 54		ret = -ENODEV;
 55		goto out_disable;
 56	}
 57
 58	res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE,
 59				 KBUILD_MODNAME);
 
 60	if (!res) {
 61		dev_err(&pdev->dev, "Failed to request PCI memory\n");
 62		ret = -EBUSY;
 63		goto out_disable;
 64	}
 65
 66	priv->base = ioremap(priv->mapbase, CHAM_HEADER_SIZE);
 67	if (!priv->base) {
 68		dev_err(&pdev->dev, "Cannot ioremap\n");
 69		ret = -ENOMEM;
 70		goto out_release;
 71	}
 72
 73	flags = pci_resource_flags(pdev, 0);
 74	if (flags & IORESOURCE_IO) {
 75		ret = -ENOTSUPP;
 76		dev_err(&pdev->dev,
 77			"IO mapped PCI devices are not supported\n");
 78		goto out_iounmap;
 79	}
 80
 81	pci_set_drvdata(pdev, priv);
 82
 83	priv->bus = mcb_alloc_bus(&pdev->dev);
 84	if (IS_ERR(priv->bus)) {
 85		ret = PTR_ERR(priv->bus);
 86		goto out_iounmap;
 87	}
 88
 89	priv->bus->get_irq = mcb_pci_get_irq;
 90
 91	ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
 92	if (ret < 0)
 93		goto out_mcb_bus;
 94	num_cells = ret;
 95
 96	dev_dbg(&pdev->dev, "Found %d cells\n", num_cells);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 97
 98	mcb_bus_add_devices(priv->bus);
 99
100	return 0;
101
102out_mcb_bus:
103	mcb_release_bus(priv->bus);
104out_iounmap:
105	iounmap(priv->base);
106out_release:
107	pci_release_region(pdev, 0);
108out_disable:
109	pci_disable_device(pdev);
110	return ret;
111}
112
113static void mcb_pci_remove(struct pci_dev *pdev)
114{
115	struct priv *priv = pci_get_drvdata(pdev);
116
117	mcb_release_bus(priv->bus);
118
119	iounmap(priv->base);
120	release_region(priv->mapbase, CHAM_HEADER_SIZE);
121	pci_disable_device(pdev);
122}
123
124static const struct pci_device_id mcb_pci_tbl[] = {
125	{ PCI_DEVICE(PCI_VENDOR_ID_MEN, PCI_DEVICE_ID_MEN_CHAMELEON) },
 
126	{ 0 },
127};
128MODULE_DEVICE_TABLE(pci, mcb_pci_tbl);
129
130static struct pci_driver mcb_pci_driver = {
131	.name = "mcb-pci",
132	.id_table = mcb_pci_tbl,
133	.probe = mcb_pci_probe,
134	.remove = mcb_pci_remove,
135};
136
137module_pci_driver(mcb_pci_driver);
138
139MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>");
140MODULE_LICENSE("GPL");
141MODULE_DESCRIPTION("MCB over PCI support");