[PATCH v1 2/4] ata: ahci_imx: Clean up code by using i.MX8Q HSIO PHY driver
Damien Le Moal
dlemoal at kernel.org
Thu Jul 11 03:22:23 PDT 2024
On 7/11/24 17:11, Richard Zhu wrote:
> Clean up code by using PHY interface.
>
> Signed-off-by: Richard Zhu <hongxing.zhu at nxp.com>
> ---
> + ret = phy_init(imxpriv->cali_phy0);
> + if (ret) {
> + dev_err(dev, "cali PHY init failed\n");
> return ret;
> }
> - ret = clk_prepare_enable(imxpriv->phy_pclk1);
> - if (ret < 0) {
> - dev_err(dev, "can't enable phy_pclk1.\n");
> - goto disable_phy_pclk0;
> + ret = phy_power_on(imxpriv->cali_phy0);
> + if (ret) {
> + dev_err(dev, "cali PHY power on failed\n");
> + goto err_cali_phy0_power_on;
Very confusing lable name. "goto err_phy_exit;" would be better.
> }
> - ret = clk_prepare_enable(imxpriv->epcs_tx_clk);
> - if (ret < 0) {
> - dev_err(dev, "can't enable epcs_tx_clk.\n");
> - goto disable_phy_pclk1;
> + ret = phy_init(imxpriv->cali_phy1);
> + if (ret) {
> + dev_err(dev, "cali PHY1 init failed\n");
> + goto err_cali_phy1_init;
Same here. The usual thing to do is to have a label name descriptive of what is
going to be done at the label definition, so phy1 power off in this case. That
also corresponds to undoing the previous operation, which makes reading the code
and checking it less confusing.
> }
> - ret = clk_prepare_enable(imxpriv->epcs_rx_clk);
> - if (ret < 0) {
> - dev_err(dev, "can't enable epcs_rx_clk.\n");
> - goto disable_epcs_tx_clk;
> + ret = phy_power_on(imxpriv->cali_phy1);
> + if (ret) {
> + dev_err(dev, "cali PHY1 power on failed\n");
> + goto err_cali_phy1_power_on;
same here.
> }
> - ret = clk_prepare_enable(imxpriv->phy_apbclk);
> - if (ret < 0) {
> - dev_err(dev, "can't enable phy_apbclk.\n");
> - goto disable_epcs_rx_clk;
> + ret = phy_init(imxpriv->sata_phy);
> + if (ret) {
> + dev_err(dev, "sata PHY init failed\n");
> + goto err_sata_phy_init;
And here too. And many other labels after that.
[...]
> - imxpriv->phy_apbclk = devm_clk_get(dev, "phy_apbclk");
> - if (IS_ERR(imxpriv->phy_apbclk)) {
> - dev_err(dev, "can't get phy_apbclk clock.\n");
> - return PTR_ERR(imxpriv->phy_apbclk);
> + if (!(dev->bus_dma_limit)) {
> + dev->bus_dma_limit = DMA_BIT_MASK(32);
> + dev_dbg(dev, "imx8qm sata only supports 32bit dma.\n");
I do not think this is a useful debug message.
> }
>
> - /* Fetch GPIO, then enable the external OSC */
> - imxpriv->clkreq_gpiod = devm_gpiod_get_optional(dev, "clkreq",
> - GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
> - if (IS_ERR(imxpriv->clkreq_gpiod))
> - return PTR_ERR(imxpriv->clkreq_gpiod);
> - if (imxpriv->clkreq_gpiod)
> - gpiod_set_consumer_name(imxpriv->clkreq_gpiod, "SATA CLKREQ");
> -
> + imxpriv->sata_phy = devm_phy_get(dev, "sata-phy");
> + if (IS_ERR(imxpriv->sata_phy))
> + return dev_err_probe(dev, PTR_ERR(imxpriv->sata_phy),
> + "failed to get sata_phy\n");
> +
> + imxpriv->cali_phy0 = devm_phy_get(dev, "cali-phy0");
> + if (IS_ERR(imxpriv->cali_phy0))
> + return dev_err_probe(dev, PTR_ERR(imxpriv->cali_phy0),
> + "failed to get cali_phy0\n");
> + imxpriv->cali_phy1 = devm_phy_get(dev, "cali-phy1");
> + if (IS_ERR(imxpriv->cali_phy1))
> + return dev_err_probe(dev, PTR_ERR(imxpriv->cali_phy1),
> + "failed to get cali_phy1\n");
> return 0;
> }
>
> @@ -1077,12 +877,6 @@ static int imx_ahci_probe(struct platform_device *pdev)
> return PTR_ERR(imxpriv->sata_ref_clk);
> }
>
> - imxpriv->ahb_clk = devm_clk_get(dev, "ahb");
> - if (IS_ERR(imxpriv->ahb_clk)) {
> - dev_err(dev, "can't get ahb clock.\n");
s/can't/Failed to/
and drop the period.
> - return PTR_ERR(imxpriv->ahb_clk);
> - }
> -
> if (imxpriv->type == AHCI_IMX6Q || imxpriv->type == AHCI_IMX6QP) {
> u32 reg_value;
>
> @@ -1142,11 +936,8 @@ static int imx_ahci_probe(struct platform_device *pdev)
> goto disable_clk;
>
> /*
> - * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL,
> - * and IP vendor specific register IMX_TIMER1MS.
> - * Configure CAP_SSS (support stagered spin up).
> - * Implement the port0.
> - * Get the ahb clock rate, and configure the TIMER1MS register.
> + * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL.
> + * Set CAP_SSS (support stagered spin up) and Implement the port0.
> */
> reg_val = readl(hpriv->mmio + HOST_CAP);
> if (!(reg_val & HOST_CAP_SSS)) {
> @@ -1159,8 +950,19 @@ static int imx_ahci_probe(struct platform_device *pdev)
> writel(reg_val, hpriv->mmio + HOST_PORTS_IMPL);
> }
>
> - reg_val = clk_get_rate(imxpriv->ahb_clk) / 1000;
> - writel(reg_val, hpriv->mmio + IMX_TIMER1MS);
> + if (imxpriv->type != AHCI_IMX8QM) {
> + /*
> + * Get AHB clock rate and configure the vendor specified
> + * TIMER1MS register on i.MX53, i.MX6Q and i.MX6QP only.
> + */
> + imxpriv->ahb_clk = devm_clk_get(dev, "ahb");
> + if (IS_ERR(imxpriv->ahb_clk)) {
> + dev_err(dev, "can't get ahb clock.\n");
Same here.
> + goto disable_sata;
> + }
> + reg_val = clk_get_rate(imxpriv->ahb_clk) / 1000;
> + writel(reg_val, hpriv->mmio + IMX_TIMER1MS);
> + }
>
> ret = ahci_platform_init_host(pdev, hpriv, &ahci_imx_port_info,
> &ahci_platform_sht);
--
Damien Le Moal
Western Digital Research
More information about the linux-arm-kernel
mailing list