drivers/phy/st/phy-stm32-combophy.c

Source file repositories/reference/linux-study-clean/drivers/phy/st/phy-stm32-combophy.c

File Facts

System
Linux kernel
Corpus path
drivers/phy/st/phy-stm32-combophy.c
Extension
.c
Size
16533 bytes
Lines
606
Domain
Driver Families
Bucket
drivers/phy
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 stm32_combophy {
	struct phy *phy;
	struct regmap *regmap;
	struct device *dev;
	void __iomem *base;
	struct reset_control *phy_reset;
	struct clk_bulk_data clks[ARRAY_SIZE(combophy_clks)];
	int num_clks;
	bool have_pad_clk;
	unsigned int type;
	bool is_init;
	int irq_wakeup;
};

struct clk_impedance  {
	u32 microohm;
	u32 vswing[4];
};

/*
 * lookup table to hold the settings needed for a ref clock frequency
 * impedance, the offset is used to set the IMP_CTL and DE_EMP bit of the
 * PRG_IMP_CTRL register. Use ordered discrete values in the table
 */
static const struct clk_impedance imp_lookup[] = {
	{ 6090000, { 442000, 564000, 684000, 802000 } },
	{ 5662000, { 528000, 621000, 712000, 803000 } },
	{ 5292000, { 491000, 596000, 700000, 802000 } },
	{ 4968000, { 558000, 640000, 722000, 803000 } },
	{ 4684000, { 468000, 581000, 692000, 802000 } },
	{ 4429000, { 554000, 613000, 717000, 803000 } },
	{ 4204000, { 511000, 609000, 706000, 802000 } },
	{ 3999000, { 571000, 648000, 726000, 803000 } }
};
#define DEFAULT_IMP_INDEX 3 /* Default impedance is 50 Ohm */

static int stm32_impedance_tune(struct stm32_combophy *combophy)
{
	u8 imp_size = ARRAY_SIZE(imp_lookup);
	u8 vswing_size = ARRAY_SIZE(imp_lookup[0].vswing);
	u8 imp_of, vswing_of;
	u32 max_imp = imp_lookup[0].microohm;
	u32 min_imp = imp_lookup[imp_size - 1].microohm;
	u32 max_vswing;
	u32 min_vswing = imp_lookup[0].vswing[0];
	u32 val;

	if (!of_property_read_u32(combophy->dev->of_node, "st,output-micro-ohms", &val)) {
		if (val < min_imp || val > max_imp) {
			dev_err(combophy->dev, "Invalid value %u for output ohm\n", val);
			return -EINVAL;
		}

		for (imp_of = 0; imp_of < ARRAY_SIZE(imp_lookup); imp_of++)
			if (imp_lookup[imp_of].microohm <= val)
				break;

		if (WARN_ON(imp_of == ARRAY_SIZE(imp_lookup)))
			return -EINVAL;

		dev_dbg(combophy->dev, "Set %u micro-ohms output impedance\n",
			imp_lookup[imp_of].microohm);

		regmap_update_bits(combophy->regmap, SYSCFG_PCIEPRGCR,
				   STM32MP25_PCIEPRG_IMPCTRL_OHM,
				   FIELD_PREP(STM32MP25_PCIEPRG_IMPCTRL_OHM, imp_of));
	} else
		imp_of = DEFAULT_IMP_INDEX;

	if (!of_property_read_u32(combophy->dev->of_node, "st,output-vswing-microvolt", &val)) {
		max_vswing = imp_lookup[imp_of].vswing[vswing_size - 1];

		if (val < min_vswing || val > max_vswing) {
			dev_err(combophy->dev, "Invalid value %u for output vswing\n", val);
			return -EINVAL;
		}

		for (vswing_of = 0; vswing_of < ARRAY_SIZE(imp_lookup[imp_of].vswing); vswing_of++)
			if (imp_lookup[imp_of].vswing[vswing_of] >= val)
				break;

		if (WARN_ON(vswing_of == ARRAY_SIZE(imp_lookup[imp_of].vswing)))
			return -EINVAL;

		dev_dbg(combophy->dev, "Set %u microvolt swing\n",
			 imp_lookup[imp_of].vswing[vswing_of]);

		regmap_update_bits(combophy->regmap, SYSCFG_PCIEPRGCR,
				   STM32MP25_PCIEPRG_IMPCTRL_VSWING,
				   FIELD_PREP(STM32MP25_PCIEPRG_IMPCTRL_VSWING, vswing_of));

Annotation

Implementation Notes