drivers/fpga/dfl-n3000-nios.c

Source file repositories/reference/linux-study-clean/drivers/fpga/dfl-n3000-nios.c

File Facts

System
Linux kernel
Corpus path
drivers/fpga/dfl-n3000-nios.c
Extension
.c
Size
18088 bytes
Lines
589
Domain
Driver Families
Bucket
drivers/fpga
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 n3000_nios {
	void __iomem *base;
	struct regmap *regmap;
	struct device *dev;
	struct platform_device *altera_spi;
};

static ssize_t nios_fw_version_show(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct n3000_nios *nn = dev_get_drvdata(dev);
	unsigned int val;
	int ret;

	ret = regmap_read(nn->regmap, N3000_NIOS_FW_VERSION, &val);
	if (ret)
		return ret;

	return sysfs_emit(buf, "%x.%x.%x\n",
			  (u8)FIELD_GET(N3000_NIOS_FW_VERSION_MAJOR, val),
			  (u8)FIELD_GET(N3000_NIOS_FW_VERSION_MINOR, val),
			  (u8)FIELD_GET(N3000_NIOS_FW_VERSION_PATCH, val));
}
static DEVICE_ATTR_RO(nios_fw_version);

#define IS_MODE_STATUS_OK(mode_stat)					\
	(FIELD_GET(N3000_NIOS_PKVL_MODE_STS_GROUP_MSK, (mode_stat)) ==	\
	 N3000_NIOS_PKVL_MODE_STS_GROUP_OK)

#define IS_RETIMER_FEC_SUPPORTED(retimer_mode)			\
	((retimer_mode) != N3000_NIOS_PKVL_MODE_ID_RESET &&	\
	 (retimer_mode) != N3000_NIOS_PKVL_MODE_ID_4X10G)

static int get_retimer_mode(struct n3000_nios *nn, unsigned int mode_stat_reg,
			    unsigned int *retimer_mode)
{
	unsigned int val;
	int ret;

	ret = regmap_read(nn->regmap, mode_stat_reg, &val);
	if (ret)
		return ret;

	if (!IS_MODE_STATUS_OK(val))
		return -EFAULT;

	*retimer_mode = FIELD_GET(N3000_NIOS_PKVL_MODE_STS_ID_MSK, val);

	return 0;
}

static ssize_t retimer_A_mode_show(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct n3000_nios *nn = dev_get_drvdata(dev);
	unsigned int mode;
	int ret;

	ret = get_retimer_mode(nn, N3000_NIOS_PKVL_A_MODE_STS, &mode);
	if (ret)
		return ret;

	return sysfs_emit(buf, "0x%x\n", mode);
}
static DEVICE_ATTR_RO(retimer_A_mode);

static ssize_t retimer_B_mode_show(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct n3000_nios *nn = dev_get_drvdata(dev);
	unsigned int mode;
	int ret;

	ret = get_retimer_mode(nn, N3000_NIOS_PKVL_B_MODE_STS, &mode);
	if (ret)
		return ret;

	return sysfs_emit(buf, "0x%x\n", mode);
}
static DEVICE_ATTR_RO(retimer_B_mode);

static ssize_t fec_mode_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{
	unsigned int val, retimer_a_mode, retimer_b_mode, fec_modes;
	struct n3000_nios *nn = dev_get_drvdata(dev);
	int ret;

	/* FEC mode setting is not supported in early FW versions */
	ret = regmap_read(nn->regmap, N3000_NIOS_FW_VERSION, &val);

Annotation

Implementation Notes