diff --git a/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml b/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml index fbf2b14f69..a1d4603a57 100644 --- a/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml +++ b/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml @@ -26,6 +26,11 @@ properties: - st,st54l - const: nxp,nxp-nci-i2c + clocks: + maxItems: 1 + description: The controller's reference clock, or the SoC clock pad + that feeds it on the controller's request + enable-gpios: description: Output GPIO pin used for enabling/disabling the controller diff --git a/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml b/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml index 2f273e9e5a..9cec4a1375 100644 --- a/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml @@ -63,6 +63,10 @@ properties: '#clock-cells': const: 1 + description: + On the Exynos SoCs, one clock per CLKOUT mux input. On the Tensor G4 + PMU (google,zumapro-pmu), clock 0 is the NFC controller's reference + clock pad. clock-names: description: diff --git a/drivers/clk/samsung/clk-exynos-clkout.c b/drivers/clk/samsung/clk-exynos-clkout.c index 5f64d93b2f..cd3d09151a 100644 --- a/drivers/clk/samsung/clk-exynos-clkout.c +++ b/drivers/clk/samsung/clk-exynos-clkout.c @@ -11,11 +11,13 @@ #include #include #include +#include #include #include #include #include #include +#include #define DRV_NAME "exynos-clkout" @@ -28,6 +30,72 @@ #define EXYNOS4_CLKOUT_MUX_MASK 0xf #define EXYNOS5_CLKOUT_MUX_MASK 0x1f +/* + * GS101 and GS201 have one PAD_CTRL_CLKOUTn register per output pad in the + * PMU, written through the PMU regmap (the PMU is secured on these SoCs). + * Bit 0 drives the clock onto the pad, bits 13:8 select the source; source 0 + * is the TCXO. + */ +#define GS101_PAD_CTRL_CLKOUT(n) (0x3e80 + 4 * (n)) +#define GS101_CLKOUT_SEL_MASK GENMASK(13, 8) +#define GS101_CLKOUT_EN BIT(0) + +/* + * Tensor G4 (zumapro) feeds the NFC controller's reference clock from a PMU + * pad as well. With EXTPAD_EN set the PMU follows the controller's clock + * request line and drives the clock onto the pad, which is how Google's + * st21nfc driver runs it (pmu_clk_pad = <0x3e84>, st,extpad_control_en); + * without it the Pixel 9a's ST54L does not ACK its I2C address. Nothing + * else about this register is known, so its source field is left alone. + */ +#define ZUMAPRO_PAD_CTRL_NFC_CLK 0x3e84 +#define ZUMAPRO_CLKOUT_EXTPAD_EN BIT(16) + +#define EXYNOS_CLKOUT_MAX_PADS 2 + +/* A pad's register, the bit that puts the clock on it and the source field. */ +struct exynos_clkout_pad_desc { + unsigned int reg; + u32 en; + u32 sel_mask; +}; + +struct exynos_clkout_pad { + struct clk_hw hw; + struct regmap *regmap; + const struct exynos_clkout_pad_desc *desc; + bool en_bringup; +}; + +#define to_exynos_clkout_pad(_hw) container_of(_hw, struct exynos_clkout_pad, hw) + +/* + * Google's sources disagree on bit 0: the NFC driver sets it to run the + * clock, the clock framework code clears it. Until a board proves one, + * let bring-up pick at run time. + */ +static bool gs101_pad_en_active_low; +module_param(gs101_pad_en_active_low, bool, 0644); +MODULE_PARM_DESC(gs101_pad_en_active_low, + "GS101/GS201 CLKOUT pads run with bit 0 clear (default: set)"); + +static void exynos_clkout_pad_trace(struct exynos_clkout_pad *pad, + const char *what) +{ + unsigned int val = 0; + int ret; + + ret = regmap_read(pad->regmap, pad->desc->reg, &val); + pr_debug("%s: %s, PAD_CTRL 0x%x = 0x%08x (%d)\n", + clk_hw_get_name(&pad->hw), what, pad->desc->reg, val, ret); +} + +/* Only the GS101 pads' bit 0 is still being settled by bring-up. */ +static bool exynos_clkout_pad_active_low(struct exynos_clkout_pad *pad) +{ + return pad->en_bringup && gs101_pad_en_active_low; +} + struct exynos_clkout { struct clk_gate gate; struct clk_mux mux; @@ -35,11 +103,15 @@ struct exynos_clkout { void __iomem *reg; struct device_node *np; u32 pmu_debug_save; + struct exynos_clkout_pad pads[EXYNOS_CLKOUT_MAX_PADS]; struct clk_hw_onecell_data data; }; struct exynos_clkout_variant { u32 mux_mask; + const struct exynos_clkout_pad_desc *pads; + unsigned int nr_pads; + bool pad_en_bringup; }; static const struct exynos_clkout_variant exynos_clkout_exynos4 = { @@ -50,8 +122,51 @@ static const struct exynos_clkout_variant exynos_clkout_exynos5 = { .mux_mask = EXYNOS5_CLKOUT_MUX_MASK, }; +static const struct exynos_clkout_pad_desc exynos_clkout_gs101_pads[] = { + { + .reg = GS101_PAD_CTRL_CLKOUT(0), + .en = GS101_CLKOUT_EN, + .sel_mask = GS101_CLKOUT_SEL_MASK, + }, { + .reg = GS101_PAD_CTRL_CLKOUT(1), + .en = GS101_CLKOUT_EN, + .sel_mask = GS101_CLKOUT_SEL_MASK, + }, +}; + +static_assert(ARRAY_SIZE(exynos_clkout_gs101_pads) <= EXYNOS_CLKOUT_MAX_PADS); + +static const struct exynos_clkout_variant exynos_clkout_gs101 = { + .pads = exynos_clkout_gs101_pads, + .nr_pads = ARRAY_SIZE(exynos_clkout_gs101_pads), + .pad_en_bringup = true, +}; + +static const struct exynos_clkout_pad_desc exynos_clkout_zumapro_pads[] = { + { + .reg = ZUMAPRO_PAD_CTRL_NFC_CLK, + .en = ZUMAPRO_CLKOUT_EXTPAD_EN, + }, +}; + +static_assert(ARRAY_SIZE(exynos_clkout_zumapro_pads) <= EXYNOS_CLKOUT_MAX_PADS); + +static const struct exynos_clkout_variant exynos_clkout_zumapro = { + .pads = exynos_clkout_zumapro_pads, + .nr_pads = ARRAY_SIZE(exynos_clkout_zumapro_pads), +}; + static const struct of_device_id exynos_clkout_ids[] = { { + .compatible = "google,gs101-pmu", + .data = &exynos_clkout_gs101, + }, { + .compatible = "google,gs201-pmu", + .data = &exynos_clkout_gs101, + }, { + .compatible = "google,zumapro-pmu", + .data = &exynos_clkout_zumapro, + }, { .compatible = "samsung,exynos3250-pmu", .data = &exynos_clkout_exynos4, }, { @@ -82,9 +197,9 @@ static const struct of_device_id exynos_clkout_ids[] = { * Device will be instantiated as child of PMU device without its own * device node. Therefore match compatibles against parent. */ -static int exynos_clkout_match_parent_dev(struct device *dev, u32 *mux_mask) +static int exynos_clkout_match_parent_dev(struct device *dev, + const struct exynos_clkout_variant **variant) { - const struct exynos_clkout_variant *variant; const struct of_device_id *match; if (!dev->parent) { @@ -102,31 +217,139 @@ static int exynos_clkout_match_parent_dev(struct device *dev, u32 *mux_mask) dev_err(dev, "cannot match parent device\n"); return -EINVAL; } - variant = match->data; - - *mux_mask = variant->mux_mask; + *variant = match->data; return 0; } +static int exynos_clkout_pad_enable(struct clk_hw *hw) +{ + struct exynos_clkout_pad *pad = to_exynos_clkout_pad(hw); + const struct exynos_clkout_pad_desc *desc = pad->desc; + int ret; + + /* Select the TCXO (where the pad has a source field) and drive it. */ + ret = regmap_update_bits(pad->regmap, desc->reg, + desc->sel_mask | desc->en, + exynos_clkout_pad_active_low(pad) ? 0 : desc->en); + exynos_clkout_pad_trace(pad, "enable"); + + return ret; +} + +static void exynos_clkout_pad_disable(struct clk_hw *hw) +{ + struct exynos_clkout_pad *pad = to_exynos_clkout_pad(hw); + + regmap_update_bits(pad->regmap, pad->desc->reg, pad->desc->en, + exynos_clkout_pad_active_low(pad) ? pad->desc->en : 0); + exynos_clkout_pad_trace(pad, "disable"); +} + +static int exynos_clkout_pad_is_enabled(struct clk_hw *hw) +{ + struct exynos_clkout_pad *pad = to_exynos_clkout_pad(hw); + unsigned int val; + + if (regmap_read(pad->regmap, pad->desc->reg, &val)) + return 0; + + return !!(val & pad->desc->en) != exynos_clkout_pad_active_low(pad); +} + +static const struct clk_ops exynos_clkout_pad_ops = { + .enable = exynos_clkout_pad_enable, + .disable = exynos_clkout_pad_disable, + .is_enabled = exynos_clkout_pad_is_enabled, +}; + +/* + * GS101/GS201 and Tensor G4: one gate per pad, parented to mux input 0 (the + * TCXO, named "clkout0" in the PMU node) where the PMU node names it; a pad + * whose source the node does not describe is a root clock. The pads may be + * in use by devices that Linux does not describe, so leave them as the + * bootloader left them until a consumer asks for them. + */ +static int exynos_clkout_pad_probe(struct platform_device *pdev, + struct exynos_clkout *clkout, + const struct exynos_clkout_variant *variant) +{ + struct device *dev = &pdev->dev; + struct clk_init_data init = {}; + const char *parent_name = NULL; + struct regmap *regmap; + struct clk *parent; + int ret, i; + + regmap = syscon_node_to_regmap(clkout->np); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), + "failed to get PMU regmap\n"); + + /* + * Only a PMU node that names "clkout0" has a parent: without + * clock-names at all of_clk_get_by_name() returns -EINVAL, not + * -ENOENT, so look for the name first. + */ + parent = NULL; + if (of_property_match_string(clkout->np, "clock-names", "clkout0") >= 0) { + parent = of_clk_get_by_name(clkout->np, "clkout0"); + if (IS_ERR(parent)) + return dev_err_probe(dev, PTR_ERR(parent), + "failed to get TCXO clock\n"); + parent_name = __clk_get_name(parent); + } + + clkout->data.num = variant->nr_pads; + for (i = 0; i < variant->nr_pads; i++) { + struct exynos_clkout_pad *pad = &clkout->pads[i]; + char name[] = "pmu-clkoutX"; + + snprintf(name, sizeof(name), "pmu-clkout%d", i); + init.name = name; + init.ops = &exynos_clkout_pad_ops; + init.parent_names = parent ? &parent_name : NULL; + init.num_parents = parent ? 1 : 0; + init.flags = CLK_IGNORE_UNUSED; + + pad->regmap = regmap; + pad->desc = &variant->pads[i]; + pad->en_bringup = variant->pad_en_bringup; + pad->hw.init = &init; + + ret = devm_clk_hw_register(dev, &pad->hw); + if (ret) { + clk_put(parent); + return dev_err_probe(dev, ret, + "failed to register %s\n", name); + } + clkout->data.hws[i] = &pad->hw; + } + clk_put(parent); + + return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, + &clkout->data); +} + static int exynos_clkout_probe(struct platform_device *pdev) { const char *parent_names[EXYNOS_CLKOUT_PARENTS]; + const struct exynos_clkout_variant *variant; struct clk *parents[EXYNOS_CLKOUT_PARENTS]; struct exynos_clkout *clkout; int parent_count, ret, i; - u32 mux_mask; + + ret = exynos_clkout_match_parent_dev(&pdev->dev, &variant); + if (ret) + return ret; clkout = devm_kzalloc(&pdev->dev, - struct_size(clkout, data.hws, EXYNOS_CLKOUT_NR_CLKS), + struct_size(clkout, data.hws, + variant->nr_pads ?: EXYNOS_CLKOUT_NR_CLKS), GFP_KERNEL); if (!clkout) return -ENOMEM; - ret = exynos_clkout_match_parent_dev(&pdev->dev, &mux_mask); - if (ret) - return ret; - clkout->np = pdev->dev.of_node; if (!clkout->np) { /* @@ -138,6 +361,9 @@ static int exynos_clkout_probe(struct platform_device *pdev) platform_set_drvdata(pdev, clkout); + if (variant->nr_pads) + return exynos_clkout_pad_probe(pdev, clkout, variant); + spin_lock_init(&clkout->slock); parent_count = 0; @@ -170,7 +396,7 @@ static int exynos_clkout_probe(struct platform_device *pdev) clkout->gate.lock = &clkout->slock; clkout->mux.reg = clkout->reg + EXYNOS_PMU_DEBUG_REG; - clkout->mux.mask = mux_mask; + clkout->mux.mask = variant->mux_mask; clkout->mux.shift = EXYNOS_CLKOUT_MUX_SHIFT; clkout->mux.lock = &clkout->slock; @@ -209,6 +435,10 @@ static void exynos_clkout_remove(struct platform_device *pdev) { struct exynos_clkout *clkout = platform_get_drvdata(pdev); + /* The GS101 pads are managed by devres. */ + if (!clkout->reg) + return; + of_clk_del_provider(clkout->np); clk_hw_unregister(clkout->data.hws[0]); iounmap(clkout->reg); @@ -218,6 +448,9 @@ static int __maybe_unused exynos_clkout_suspend(struct device *dev) { struct exynos_clkout *clkout = dev_get_drvdata(dev); + if (!clkout->reg) + return 0; + clkout->pmu_debug_save = readl(clkout->reg + EXYNOS_PMU_DEBUG_REG); return 0; @@ -227,6 +460,9 @@ static int __maybe_unused exynos_clkout_resume(struct device *dev) { struct exynos_clkout *clkout = dev_get_drvdata(dev); + if (!clkout->reg) + return 0; + writel(clkout->pmu_debug_save, clkout->reg + EXYNOS_PMU_DEBUG_REG); return 0; diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index 92ce096e9b..6d81a97784 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -277,6 +278,7 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) struct device *dev = &client->dev; struct nxp_nci_i2c_phy *phy; unsigned long irqflags; + struct clk *clk; int r; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { @@ -308,6 +310,11 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) return PTR_ERR(phy->gpiod_fw); } + /* a reference clock (or its pad's enable) the controller asks for */ + clk = devm_clk_get_optional_enabled(dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "Failed to get the clock\n"); + r = nxp_nci_probe(phy, &client->dev, &i2c_phy_ops, NXP_NCI_I2C_MAX_PAYLOAD, &phy->ndev); if (r < 0) diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index e357744d4a..9ee77754d0 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -342,6 +342,7 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_CLUSTER1_NONCPU_OUT 0x1520 #define ZUMA_CLUSTER1_NONCPU_INT_EN 0x1544 #define ZUMA_HSI0_STATUS 0x2a84 +#define ZUMA_PAD_CTRL_NFC_CLK 0x3e84 #define ZUMA_PHY_CTRL_UFS 0x3ec0 static const struct regmap_range zuma_pmu_registers[] = { @@ -360,6 +361,8 @@ static const struct regmap_range zuma_pmu_registers[] = { regmap_reg_range(ZUMA_PHY_CTRL_UFS, ZUMA_PHY_CTRL_UFS), /* a hint TF-A reads, not a status register: see zuma_pmu_regmap_init() */ regmap_reg_range(ZUMA_PMU_INFORM0, ZUMA_PMU_INFORM0), + /* Tensor G4's NFC reference clock pad, a clock of clk-exynos-clkout */ + regmap_reg_range(ZUMA_PAD_CTRL_NFC_CLK, ZUMA_PAD_CTRL_NFC_CLK), }; static const struct regmap_range zuma_pmu_ro_registers[] = {