drivers/spi/spi-altera-platform.c

Source file repositories/reference/linux-study-clean/drivers/spi/spi-altera-platform.c

File Facts

System
Linux kernel
Corpus path
drivers/spi/spi-altera-platform.c
Extension
.c
Size
3908 bytes
Lines
162
Domain
Driver Families
Bucket
drivers/spi
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (pdata->num_chipselect > ALTERA_SPI_MAX_CS) {
			dev_err(&pdev->dev,
				"Invalid number of chipselect: %u\n",
				pdata->num_chipselect);
			return -EINVAL;
		}

		host->num_chipselect = pdata->num_chipselect;
		host->mode_bits = pdata->mode_bits;
		host->bits_per_word_mask = pdata->bits_per_word_mask;
	} else {
		host->num_chipselect = 16;
		host->mode_bits = SPI_CS_HIGH;
		host->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
	}

	hw = spi_controller_get_devdata(host);
	hw->dev = &pdev->dev;

	if (platid)
		type = platid->driver_data;

	/* find and map our resources */
	if (type == ALTERA_SPI_TYPE_SUBDEV) {
		struct resource *regoff;

		hw->regmap = dev_get_regmap(pdev->dev.parent, NULL);
		if (!hw->regmap) {
			dev_err(&pdev->dev, "get regmap failed\n");
			return -ENODEV;
		}

		regoff = platform_get_resource(pdev, IORESOURCE_REG, 0);
		if (regoff)
			hw->regoff = regoff->start;
	} else {
		void __iomem *res;

		res = devm_platform_ioremap_resource(pdev, 0);
		if (IS_ERR(res))
			return PTR_ERR(res);

		hw->regmap = devm_regmap_init_mmio(&pdev->dev, res,
						   &spi_altera_config);
		if (IS_ERR(hw->regmap)) {
			dev_err(&pdev->dev, "regmap mmio init failed\n");
			return PTR_ERR(hw->regmap);
		}
	}

	altera_spi_init_host(host);

	/* irq is optional */
	hw->irq = platform_get_irq(pdev, 0);
	if (hw->irq >= 0) {
		err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0,
				       pdev->name, host);
		if (err)
			return err;
	}

	err = devm_spi_register_controller(&pdev->dev, host);
	if (err)
		return err;

	if (pdata) {
		for (i = 0; i < pdata->num_devices; i++) {
			if (!spi_new_device(host, pdata->devices + i))
				dev_warn(&pdev->dev,
					 "unable to create SPI device: %s\n",
					 pdata->devices[i].modalias);
		}
	}

	dev_info(&pdev->dev, "regoff %u, irq %d\n", hw->regoff, hw->irq);

	return 0;
}

#ifdef CONFIG_OF
static const struct of_device_id altera_spi_match[] = {
	{ .compatible = "ALTR,spi-1.0", },
	{ .compatible = "altr,spi-1.0", },
	{},
};
MODULE_DEVICE_TABLE(of, altera_spi_match);
#endif /* CONFIG_OF */

static const struct platform_device_id altera_spi_ids[] = {
	{ .name = DRV_NAME,		.driver_data = ALTERA_SPI_TYPE_UNKNOWN },

Annotation

Implementation Notes