drivers/spi/spi-bcm63xx-hsspi.c

Source file repositories/reference/linux-study-clean/drivers/spi/spi-bcm63xx-hsspi.c

File Facts

System
Linux kernel
Corpus path
drivers/spi/spi-bcm63xx-hsspi.c
Extension
.c
Size
26660 bytes
Lines
950
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

struct bcm63xx_hsspi {
	struct completion done;
	struct mutex bus_mutex;
	struct mutex msg_mutex;
	struct platform_device *pdev;
	struct clk *clk;
	struct clk *pll_clk;
	void __iomem *regs;
	u8 __iomem *fifo;

	u32 speed_hz;
	u8 cs_polarity;
	u32 wait_mode;
	u32 xfer_mode;
	u32 prepend_cnt;
	u32 md_start;
	u8 *prepend_buf;
};

static ssize_t wait_mode_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{
	struct spi_controller *ctrl = dev_get_drvdata(dev);
	struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl);

	return sprintf(buf, "%d\n", bs->wait_mode);
}

static ssize_t wait_mode_store(struct device *dev, struct device_attribute *attr,
			  const char *buf, size_t count)
{
	struct spi_controller *ctrl = dev_get_drvdata(dev);
	struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl);
	u32 val;

	if (kstrtou32(buf, 10, &val))
		return -EINVAL;

	if (val > HSSPI_WAIT_MODE_MAX) {
		dev_warn(dev, "invalid wait mode %u\n", val);
		return -EINVAL;
	}

	mutex_lock(&bs->msg_mutex);
	bs->wait_mode = val;
	/* clear interrupt status to avoid spurious int on next transfer */
	if (val == HSSPI_WAIT_MODE_INTR)
		__raw_writel(HSSPI_INT_CLEAR_ALL, bs->regs + HSSPI_INT_STATUS_REG);
	mutex_unlock(&bs->msg_mutex);

	return count;
}

static DEVICE_ATTR_RW(wait_mode);

static ssize_t xfer_mode_show(struct device *dev, struct device_attribute *attr,
			 char *buf)
{
	struct spi_controller *ctrl = dev_get_drvdata(dev);
	struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl);

	return sprintf(buf, "%d\n", bs->xfer_mode);
}

static ssize_t xfer_mode_store(struct device *dev, struct device_attribute *attr,
			  const char *buf, size_t count)
{
	struct spi_controller *ctrl = dev_get_drvdata(dev);
	struct bcm63xx_hsspi *bs = spi_controller_get_devdata(ctrl);
	u32 val;

	if (kstrtou32(buf, 10, &val))
		return -EINVAL;

	if (val > HSSPI_XFER_MODE_MAX) {
		dev_warn(dev, "invalid xfer mode %u\n", val);
		return -EINVAL;
	}

	mutex_lock(&bs->msg_mutex);
	bs->xfer_mode = val;
	mutex_unlock(&bs->msg_mutex);

	return count;
}

static DEVICE_ATTR_RW(xfer_mode);

static struct attribute *bcm63xx_hsspi_attrs[] = {
	&dev_attr_wait_mode.attr,

Annotation

Implementation Notes