RFC: Mixel DPHY support for i.MX8
Subsystems (2)
cover RFC: Mixel DPHY support for i.MX8
This adds initial support for the Mixel IP based mipi dphy as found on i.MX8 processors. It has support for the i.MX8MQ, support for other variants can be added - once the necessary parts are in - via the provided hooks. The driver is somewhat based on what's found in NXPs BSP.
Documentation on the DPHY's registers is currently thin in the i.MX8 reference manuals (even on the i.MX8QXP form 11/18) so most of the values were taken from existing drivers.
This is based on linux-next as of 2019-01-21 and Maxime Ripard's dphy configuration helper patches which would need to go in first.
To get DSI working on the imx8MQ there's a driver for the nwl dsi host controller missing which I intend to looking at too.
Guido Günther (2):
dt-bindings: phy: Add documentation for mixel dphy
phy: Add driver for mixel dphy
.../bindings/phy/mixel,mipi-dsi-phy.txt | 29 ++ drivers/phy/Kconfig | 7 + drivers/phy/Makefile | 1 + drivers/phy/phy-mixel-mipi-dphy.c | 449 ++++++++++++++++++ 4 files changed, 486 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt create mode 100644 drivers/phy/phy-mixel-mipi-dphy.c
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/2 dt-bindings: phy: Add documentation for mixel dphy
--- .../bindings/phy/mixel,mipi-dsi-phy.txt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt
Documentation/devicetree/bindings/phy/mixel,mipi-dsi-phy.txt new file +29 -0
@@ -0,0 +1,29 @@ +Mixel DSI PHY for i.MX8 + +The Mixel MIPI-DSI PHY IP block is e.g. found on MX8 platforms (along +the MIPI-DSI IP from Northwest Logic). It represents the physical +layer for the electrical signals for DSI. + +Required properties: +- compatible: Must be: + - "mixel,imx8mq-mipi-dphy" +- clocks: Must contain an entry for each entry in clock-names. +- clock-names: Must contain the following entries: + - "phy_ref": phandle and specifier referring to the DPHY ref clock +- reg: the register range of the PHY controller +- #phy-cells: number of cells in PHY, as defined in + Documentation/devicetree/bindings/phy/phy-bindings.txt + this must be <0> + +Optional properties: +- power-domains: phandle to power domain + +Example: + mipi_dphy: mipi_dphy@30A0030 { + compatible = "mixel,imx8mq-mipi-dphy"; + clocks = <&clk IMX8MQ_CLK_DSI_PHY_REF>; + clock-names = "phy_ref"; + reg = <0x30A00300 0x100>; + power-domains = <&pd_mipi0>; + #phy-cells = <0>; + };
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 2/2 phy: Add driver for mixel dphy
In reply to Guido GüntherThis adds support for the Mixel DPHY as found on i.MX8 CPUs but since this is an IP core it will likely be found on others in the future. So instead of adding this to the nwl host driver make it a generic PHY driver.
The driver supports the i.MX8MQ. Support for i.MX8QM and i.MX8QXP can be added once the necessary system controller bits are in via mixel_dpy_ops.
--- drivers/phy/Kconfig | 7 + drivers/phy/Makefile | 1 + drivers/phy/phy-mixel-mipi-dphy.c | 449 ++++++++++++++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 drivers/phy/phy-mixel-mipi-dphy.c
drivers/phy/Kconfig +7 -0
@@ -48,6 +48,13 @@ config PHY_XGENE help This option enables support for APM X-Gene SoC multi-purpose PHY. +config PHY_MIXEL_MIPI_DPHY + bool + depends on OF + select GENERIC_PHY + select GENERIC_PHY_MIPI_DPHY + default ARCH_MXC && ARM64 + source "drivers/phy/allwinner/Kconfig" source "drivers/phy/amlogic/Kconfig" source "drivers/phy/broadcom/Kconfig"
drivers/phy/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ obj-$(CONFIG_ARCH_RENESAS) += renesas/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_ARCH_TEGRA) += tegra/ +obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-mixel-mipi-dphy.o obj-y += broadcom/ \ cadence/ \ freescale/ \
drivers/phy/phy-mixel-mipi-dphy.c new file +449 -0
449 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/2] phy: Add driver for mixel dphy
Hi Guido.
Patch looks good but a few comments below.
Sam
Quoted 22 lines · Guido Günther
This adds support for the Mixel DPHY as found on i.MX8 CPUs but since this is an IP core it will likely be found on others in the future. So instead of adding this to the nwl host driver make it a generic PHY driver.
The driver supports the i.MX8MQ. Support for i.MX8QM and i.MX8QXP can be added once the necessary system controller bits are in via
mixel_dpy_ops.Signed-off-by Guido Günther <[email protected]>--- drivers/phy/Kconfig | 7 + drivers/phy/Makefile | 1 + drivers/phy/phy-mixel-mipi-dphy.c | 449 ++++++++++++++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 drivers/phy/phy-mixel-mipi-dphy.cdrivers/phy/Kconfig +0
-0
drivers/phy/Kconfig config PHY_XGENE · line 56
Quoted 9 lines
drivers/phy/Kconfig +6
-0@@ -48,6 +48,13 @@ config PHY_XGENE help This option enables support for APM X-Gene SoC multi-purpose PHY. +config PHY_MIXEL_MIPI_DPHY + bool + depends on OF + select GENERIC_PHY + select GENERIC_PHY_MIPI_DPHY + default ARCH_MXC && ARM64
Is it correct that driver is mandatory if ARCH_MXC is y? There is no prompt to allow the user to select it. Or in other words - will all i.MX8 user need it?
drivers/phy/phy-mixel-mipi-dphy.c
Quoted 21 lines
drivers/phy/Kconfig +1
-0+ source "drivers/phy/allwinner/Kconfig" source "drivers/phy/amlogic/Kconfig" source "drivers/phy/broadcom/Kconfig"drivers/phy/Makefile +1
-0@@ -15,6 +15,7 @@ obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ obj-$(CONFIG_ARCH_RENESAS) += renesas/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_ARCH_TEGRA) += tegra/ +obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-mixel-mipi-dphy.o obj-y += broadcom/ \ cadence/ \ freescale/ \drivers/phy/phy-mixel-mipi-dphy.c new file +0
-0
There is already a PHY named phy-fsl-imx8mq-usb, located in the freescale subdirectory.
Why locate another imx8 PHY in the top level directory with another naming convention?
drivers/phy/phy-mixel-mipi-dphy.c line 6
Quoted 7 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +6
-0@@ -0,0 +1,449 @@ +/* +* Copyright 2017 NXP +* Copyright 2019 Purism SPC +* +* SPDX-License-Identifier: GPL-2.0 +*/
SPDX-License-Identifier goes in at first line with //. It is documented somewhere.
Also, did you double check that GPL 2.0 is correct?
drivers/phy/phy-mixel-mipi-dphy.c line 8
Quoted 2 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +2
-0+ +/* #define DEBUG 1 */
There is no reference to DEBUG in this file - delete?
Quoted 53 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +53
-0+ +#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> + +/* DPHY registers */ +#define DPHY_PD_DPHY 0x00 +#define DPHY_M_PRG_HS_PREPARE 0x04 +#define DPHY_MC_PRG_HS_PREPARE 0x08 +#define DPHY_M_PRG_HS_ZERO 0x0c +#define DPHY_MC_PRG_HS_ZERO 0x10 +#define DPHY_M_PRG_HS_TRAIL 0x14 +#define DPHY_MC_PRG_HS_TRAIL 0x18 +#define DPHY_PD_PLL 0x1c +#define DPHY_TST 0x20 +#define DPHY_CN 0x24 +#define DPHY_CM 0x28 +#define DPHY_CO 0x2c +#define DPHY_LOCK 0x30 +#define DPHY_LOCK_BYP 0x34 +#define DPHY_TX_RCAL 0x38 +#define DPHY_AUTO_PD_EN 0x3c +#define DPHY_RXLPRP 0x40 +#define DPHY_RXCDRP 0x44 + +#define MBPS (x) ((x) * 1000000) + +#define DATA_RATE_MAX_SPEED MBPS(1500) +#define DATA_RATE_MIN_SPEED MBPS(80) + +#define CN_BUF 0xcb7a89c0 +#define CO_BUF 0x63 +#define CM (x) ( \ + ((x) < 32)?0xe0|((x)-16) : \ + ((x) < 64)?0xc0|((x)-32) : \ + ((x) < 128)?0x80|((x)-64) : \ + ((x) - 128)) +#define CN (x) (((x) == 1)?0x1f : (((CN_BUF)>>((x)-1))&0x1f)) +#define CO (x) ((CO_BUF)>>(8-(x))&0x3) + +/* PHY power on is LOW_ENABLE */ +#define PWR_ON 0 +#define PWR_OFF 1 + +struct mixel_dphy_cfg { +u32 cm;
drivers/phy/phy-mixel-mipi-dphy.c line 71
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+u32 cn; +u32 co; +unsigned long hs_clk_rate; +u8 mc_prg_hs_prepare; +u8 m_prg_hs_prepare; +u8 mc_prg_hs_zero; +u8 m_prg_hs_zero; +u8 mc_prg_hs_trail; +u8 m_prg_hs_trail; +};
For the naive reader it would be helpful to spell out the names in a comment. As I assume the names comes from the data sheet the short names are OK - but let others know the purpose.
drivers/phy/phy-mixel-mipi-dphy.c line 78
Quoted 7 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +7
-0+ +struct mixel_dphy_priv ; +struct mixel_dphy_ops { +int (*probe)(struct mixel_dphy_priv *priv); +int (*power_on)(struct phy *phy); +int (*power_off)(struct phy *phy); +};
Consider same argument for all three ops, less suprises. But then probe() is called before we have a phy, so this may be the best option.
drivers/phy/phy-mixel-mipi-dphy.c line 86
Quoted 8 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +8
-0+ +struct mixel_dphy_priv { +struct mixel_dphy_cfg cfg; +void __iomem *regs; +struct clk *phy_ref_clk; +struct mutex lock; +const struct mixel_dphy_ops *ops; +};
Document what the lock protects, or find a better name for the lock to document it
drivers/phy/phy-mixel-mipi-dphy.c line 104
Quoted 4 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +4
-0+ +/* Find a ratio close to the desired one using continued fraction +approximation ending either at exact match or maximum allowed +nominator, denominator. */
Use kernel style comments
/*
* Bla bla
* more bla
*/
drivers/phy/phy-mixel-mipi-dphy.c line 105
Quoted 1 line
drivers/phy/phy-mixel-mipi-dphy.c new file +1
-0+static void get_best_ratio (unsigned long *pnum,unsigned long *pdenom,unsigned max_n,unsigned max_d)
Wrap line to stay below 80 chars.
Use checkpatch to help you sport things like this.
drivers/phy/phy-mixel-mipi-dphy.c line 114
Quoted 9 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +9
-0+{ +unsigned long a = *pnum; +unsigned long b = *pdenom; +unsigned long c; +unsigned n[] = {0 ,1 }; +unsigned d[] = {1 ,0 }; +unsigned whole; +unsigned i =1 ; +while (b) {
Add empty line after last local variable.
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ i ^=1 ; + whole = a / b; + n[i] += (n[i ^1 ] * whole); + d[i] += (d[i ^1 ] * whole); +if ((n[i] > max_n) || (d[i] > max_d)) { + i ^=1 ; +break ; + } + c = a - (b * whole); + a = b;
drivers/phy/phy-mixel-mipi-dphy.c line 134
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ b = c; + } + *pnum = n[i]; + *pdenom = d[i]; +} + +static int mixel_dphy_config_from_opts (struct phy *phy, +struct phy_configure_opts_mipi_dphy *dphy_opts, +struct mixel_dphy_cfg *cfg) +{
Align extra paratmers below the first parameter using tabs and add necessary spaces.
Quoted 16 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +16
-0+struct mixel_dphy_priv *priv =dev_get_drvdata (phy->dev.parent); +unsigned long ref_clk =clk_get_rate (priv->phy_ref_clk); +int i; +unsigned long numerator, denominator, frequency; +unsigned step; + +static int mixel_dphy_ref_power_on (struct phy *phy) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); +u32 lock, timeout; +int ret =0 ; + +mutex_lock (&priv->lock); +clk_prepare_enable (priv->phy_ref_clk); + +phy_write (phy,PWR_ON ,DPHY_PD_DPHY );
drivers/phy/phy-mixel-mipi-dphy.c line 146
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+phy_write (phy,PWR_ON ,DPHY_PD_PLL ); + + timeout =100 ; +while (!(lock =phy_read (phy,DPHY_LOCK ))) { +udelay (10 ); +if (--timeout ==0 ) { +dev_err (&phy->dev,"Could not get DPHY lock!\n" ); +mutex_unlock (&priv->lock); +return -EINVAL ; + }
USe goto to have a single exit path where you do mutex_unlock()
Quoted 12 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +12
-0+ } +mutex_unlock (&priv->lock); + +return ret; +} + + +mutex_lock (&priv->lock); + +phy_write (phy,0x00 ,DPHY_LOCK_BYP ); +phy_write (phy,0x01 ,DPHY_TX_RCAL ); +phy_write (phy,0x00 ,DPHY_AUTO_PD_EN );
drivers/phy/phy-mixel-mipi-dphy.c line 321
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+phy_write (phy,0x01 ,DPHY_RXLPRP ); +phy_write (phy,0x01 ,DPHY_RXCDRP ); +phy_write (phy,0x25 ,DPHY_TST ); + +mixel_phy_set_hs_timings (phy); + ret =mixel_dphy_set_pll_params (phy); +if (ret <0 ) { +mutex_unlock (&priv->lock); +return ret; + }
USe goto to have a single exit path where you do mutex_unlock()
Quoted 14 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +14
-0+ +mutex_unlock (&priv->lock); + +return 0 ; +} + + +/* +* This is the reference implementation of DPHY hooks. Specific integration of +* this IP may have to re-implement some of them depending on how they decided +* to wire things in the SoC. +*/ +static const struct mixel_dphy_ops mixel_dphy_ref_ops = { + .power_on = mixel_dphy_ref_power_on,
drivers/phy/phy-mixel-mipi-dphy.c line 373
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ .power_off = mixel_dphy_ref_power_off, +}; + +static const struct phy_ops mixel_dphy_ops = { + .power_on = mixel_dphy_power_on, + .power_off = mixel_dphy_power_off, + .configure = mixel_dphy_configure, + .validate = mixel_dphy_validate, + .owner =THIS_MODULE , +};
This is confusing.
We have struct mixel_dphy_ops => mixel_dphy_ref_ops And then struct phy_ops => mixel_dphy_ops
So reading this there are to uses of mixel_dphy_ops, one is a struct, and another is an instance of another type. Try to find a niming scheme that is less confusing.
drivers/phy/phy-mixel-mipi-dphy.c line 378
Quoted 5 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +5
-0+ +static const struct of_device_id mixel_dphy_of_match[] = { + { .compatible ="mixel,imx8mq-mipi-dphy" , .data = &mixel_dphy_ref_ops }, + {/* sentinel */ }, +};
Multi-line to keep line shorter?
Quoted 78 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +71
-0+MODULE_DEVICE_TABLE (of, mixel_dphy_of_match); + +static int mixel_dphy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct phy_provider *phy_provider; +struct mixel_dphy_priv *priv; +struct resource *res; +struct phy *phy; +int ret; + +if (!np) +return -ENODEV ; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->ops =of_device_get_match_data (&pdev->dev); +if (!priv->ops) +return -EINVAL ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -ENODEV ; + + priv->regs =devm_ioremap (dev, res->start,SZ_256 ); +if (IS_ERR (priv->regs)) +return PTR_ERR (priv->regs); + + priv->phy_ref_clk =devm_clk_get (&pdev->dev,"phy_ref" ); +if (IS_ERR (priv->phy_ref_clk)) { +dev_err (dev,"No phy_ref clock found" ); +return PTR_ERR (priv->phy_ref_clk); + } +dev_dbg (dev,"phy_ref clock rate: %lu" ,clk_get_rate (priv->phy_ref_clk)); + +mutex_init (&priv->lock); +dev_set_drvdata (dev, priv); + +if (priv->ops->probe) { + ret = priv->ops->probe (priv); +if (ret) +return ret; + } + + phy =devm_phy_create (dev, np, &mixel_dphy_ops); +if (IS_ERR (phy)) { +dev_err (dev,"Failed to create phy %ld\n" ,PTR_ERR (phy)); +return PTR_ERR (phy); + } +phy_set_drvdata (phy, priv); + + phy_provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); + +return PTR_ERR_OR_ZERO (phy_provider); +} + +static struct platform_driver mixel_dphy_driver = { + .probe = mixel_dphy_probe, + .driver = { + .name ="mixel-mipi-dphy" , + .of_match_table = mixel_dphy_of_match, + } +}; +module_platform_driver (mixel_dphy_driver); + +MODULE_AUTHOR ("NXP Semiconductor" ); +MODULE_DESCRIPTION ("Mixel MIPI-DSI PHY driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] phy: Add driver for mixel dphy
In reply to Guido GüntherHi Guido,
drivers/phy/Kconfig config PHY_XGENE · line 56
Quoted 6 lines · Guido Günther
drivers/phy/Kconfig +6
-0+config PHY_MIXEL_MIPI_DPHY + bool + depends on OF + select GENERIC_PHY + select GENERIC_PHY_MIPI_DPHY + default ARCH_MXC && ARM64
No need to force this selection for all i.MX8M boards, as not everyone is interested in using Mixel DSI.
drivers/phy/phy-mixel-mipi-dphy.c line 5
Quoted 8 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +5
-0@@ -0,0 +1,449 @@ +/* +* Copyright 2017 NXP +* Copyright 2019 Purism SPC +* +* SPDX-License-Identifier: GPL-2.0
SPDX line should be in the first line and start with //
drivers/phy/phy-mixel-mipi-dphy.c line 8
Quoted 3 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +3
-0+*/ + +/* #define DEBUG 1 */
Please remove it.
Quoted 9 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +9
-0+/* DPHY registers */ +#define DPHY_PD_DPHY 0x00 +#define DPHY_M_PRG_HS_PREPARE 0x04 +#define DPHY_MC_PRG_HS_PREPARE 0x08 +#define DPHY_M_PRG_HS_ZERO 0x0c +#define DPHY_MC_PRG_HS_ZERO 0x10 +#define DPHY_M_PRG_HS_TRAIL 0x14 +#define DPHY_MC_PRG_HS_TRAIL 0x18 +#define DPHY_PD_PLL 0x1c
drivers/phy/phy-mixel-mipi-dphy.c line 39
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+#define DPHY_TST 0x20 +#define DPHY_CN 0x24 +#define DPHY_CM 0x28 +#define DPHY_CO 0x2c +#define DPHY_LOCK 0x30 +#define DPHY_LOCK_BYP 0x34 +#define DPHY_TX_RCAL 0x38 +#define DPHY_AUTO_PD_EN 0x3c +#define DPHY_RXLPRP 0x40 +#define DPHY_RXCDRP 0x44
In the NXP vendor tree we have these additional offsets for imx8m that are missing here:
.reg_rxhs_settle = 0x48,
.reg_bypass_pll = 0x4c,
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+#define MBPS (x) ((x) * 1000000) + +#define DATA_RATE_MAX_SPEED MBPS(1500) +#define DATA_RATE_MIN_SPEED MBPS(80) + +#define CN_BUF 0xcb7a89c0 +#define CO_BUF 0x63 +#define CM (x) ( \ + ((x) < 32)?0xe0|((x)-16) : \ + ((x) < 64)?0xc0|((x)-32) : \
drivers/phy/phy-mixel-mipi-dphy.c line 92
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ ((x) < 128)?0x80|((x)-64) : \ + ((x) - 128)) +#define CN (x) (((x) == 1)?0x1f : (((CN_BUF)>>((x)-1))&0x1f)) +#define CO (x) ((CO_BUF)>>(8-(x))&0x3) + +static inline u32 phy_read (struct phy *phy,unsigned int reg) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); + +return readl (priv->regs + reg);
Maybe it's worth using regmap here. It makes it very easy to dump all the MIXEL registers at once.
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+static int mixel_dphy_config_from_opts (struct phy *phy, +struct phy_configure_opts_mipi_dphy *dphy_opts, +struct mixel_dphy_cfg *cfg) +{ +struct mixel_dphy_priv *priv =dev_get_drvdata (phy->dev.parent); +unsigned long ref_clk =clk_get_rate (priv->phy_ref_clk); +int i; +unsigned long numerator, denominator, frequency; +unsigned step; +
drivers/phy/phy-mixel-mipi-dphy.c line 150
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+if (dphy_opts->hs_clk_rate >DATA_RATE_MAX_SPEED || + dphy_opts->hs_clk_rate <DATA_RATE_MIN_SPEED ) +return -EINVAL ; + cfg->hs_clk_rate = dphy_opts->hs_clk_rate; + + numerator = dphy_opts->hs_clk_rate; + denominator = ref_clk; +get_best_ratio (&numerator, &denominator,255 ,256 ); +if (!numerator || !denominator) { + dev_dbg(&phy->dev, "Invalid %ld/%ld for %ld/%ld\n",
dev_err should be more appropriate here.
Quoted 9 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +9
-0+static int mixel_dphy_ref_power_on (struct phy *phy) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); +u32 lock, timeout; +int ret =0 ; + +mutex_lock (&priv->lock); +clk_prepare_enable (priv->phy_ref_clk); +
drivers/phy/phy-mixel-mipi-dphy.c line 267
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+phy_write (phy,PWR_ON ,DPHY_PD_DPHY ); +phy_write (phy,PWR_ON ,DPHY_PD_PLL ); + + timeout =100 ; +while (!(lock =phy_read (phy,DPHY_LOCK ))) { +udelay (10 ); +if (--timeout ==0 ) { +dev_err (&phy->dev,"Could not get DPHY lock!\n" ); +mutex_unlock (&priv->lock); +return -EINVAL ;
Could you use readl_poll_timeout() instead?
drivers/phy/phy-mixel-mipi-dphy.c line 278
Quoted 4 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +4
-0+static int mixel_dphy_ref_power_off (struct phy *phy) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); +int ret =0 ;
This variable is not needed.
drivers/phy/phy-mixel-mipi-dphy.c line 288
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ +mutex_lock (&priv->lock); + +phy_write (phy,PWR_OFF ,DPHY_PD_PLL ); +phy_write (phy,PWR_OFF ,DPHY_PD_DPHY ); + +clk_disable_unprepare (priv->phy_ref_clk); +mutex_unlock (&priv->lock); + +return ret;
and you could simply do a 'return 0' instead.
drivers/phy/phy-mixel-mipi-dphy.c line 313
Quoted 5 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +5
-0+phy_write (phy,0x00 ,DPHY_LOCK_BYP ); +phy_write (phy,0x01 ,DPHY_TX_RCAL ); +phy_write (phy,0x00 ,DPHY_AUTO_PD_EN ); +phy_write (phy,0x01 ,DPHY_RXLPRP ); +phy_write (phy,0x01 ,DPHY_RXCDRP );
In the NXP vendor code the value 2 is written to this register:
phy_write(phy, 0x02, priv->plat_data->reg_rxcdrp);
It would be good to dump all Mixel DSI PHY registers in the NXP vendor and in mainline and make sure they match.
drivers/phy/phy-mixel-mipi-dphy.c line 406
Quoted 1 line
drivers/phy/phy-mixel-mipi-dphy.c new file +1
-0+ priv->regs =devm_ioremap (dev, res->start,SZ_256 );
No need to hardcode SZ_256 here and the size should come from the device tree.
You could also use devm_ioremap_resource() instead.
_______________________________________________
dri-devel mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] phy: Add driver for mixel dphy
Hi,
Quoted 152 lines · Fabio Estevam
Hi Guido,
drivers/phy/Kconfig config PHY_XGENE · line 56
Quoted 6 lines · Guido Günther
drivers/phy/Kconfig +6
-0+config PHY_MIXEL_MIPI_DPHY + bool + depends on OF + select GENERIC_PHY + select GENERIC_PHY_MIPI_DPHY + default ARCH_MXC && ARM64No need to force this selection for all i.MX8M boards, as not everyone is interested in using Mixel DSI.
drivers/phy/phy-mixel-mipi-dphy.c line 5
Quoted 8 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +5
-0@@ -0,0 +1,449 @@ +/* +* Copyright 2017 NXP +* Copyright 2019 Purism SPC +* +* SPDX-License-Identifier: GPL-2.0 SPDX line should be in the first line and start with //
drivers/phy/phy-mixel-mipi-dphy.c line 8
Quoted 3 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +3
-0+*/ + +/* #define DEBUG 1 */ Please remove it.
Quoted 9 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +9
-0+/* DPHY registers */ +#define DPHY_PD_DPHY 0x00 +#define DPHY_M_PRG_HS_PREPARE 0x04 +#define DPHY_MC_PRG_HS_PREPARE 0x08 +#define DPHY_M_PRG_HS_ZERO 0x0c +#define DPHY_MC_PRG_HS_ZERO 0x10 +#define DPHY_M_PRG_HS_TRAIL 0x14 +#define DPHY_MC_PRG_HS_TRAIL 0x18 +#define DPHY_PD_PLL 0x1cdrivers/phy/phy-mixel-mipi-dphy.c line 39
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+#define DPHY_TST 0x20 +#define DPHY_CN 0x24 +#define DPHY_CM 0x28 +#define DPHY_CO 0x2c +#define DPHY_LOCK 0x30 +#define DPHY_LOCK_BYP 0x34 +#define DPHY_TX_RCAL 0x38 +#define DPHY_AUTO_PD_EN 0x3c +#define DPHY_RXLPRP 0x40 +#define DPHY_RXCDRP 0x44In the NXP vendor tree we have these additional offsets for imx8m that are missing here:
.reg_rxhs_settle =
0x48,
.reg_bypass_pll =0x4c,Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+#define MBPS (x) ((x) * 1000000) + +#define DATA_RATE_MAX_SPEED MBPS(1500) +#define DATA_RATE_MIN_SPEED MBPS(80) + +#define CN_BUF 0xcb7a89c0 +#define CO_BUF 0x63 +#define CM (x) ( \ + ((x) < 32)?0xe0|((x)-16) : \ + ((x) < 64)?0xc0|((x)-32) : \drivers/phy/phy-mixel-mipi-dphy.c line 92
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ ((x) < 128)?0x80|((x)-64) : \ + ((x) - 128)) +#define CN (x) (((x) == 1)?0x1f : (((CN_BUF)>>((x)-1))&0x1f)) +#define CO (x) ((CO_BUF)>>(8-(x))&0x3) + +static inline u32 phy_read (struct phy *phy,unsigned int reg) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); + +return readl (priv->regs + reg);Maybe it's worth using regmap here. It makes it very easy to dump all the MIXEL registers at once.
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+static int mixel_dphy_config_from_opts (struct phy *phy, +struct phy_configure_opts_mipi_dphy *dphy_opts, +struct mixel_dphy_cfg *cfg) +{ +struct mixel_dphy_priv *priv =dev_get_drvdata (phy->dev.parent); +unsigned long ref_clk =clk_get_rate (priv->phy_ref_clk); +int i; +unsigned long numerator, denominator, frequency; +unsigned step; +drivers/phy/phy-mixel-mipi-dphy.c line 150
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+if (dphy_opts->hs_clk_rate >DATA_RATE_MAX_SPEED || + dphy_opts->hs_clk_rate <DATA_RATE_MIN_SPEED ) +return -EINVAL ; + cfg->hs_clk_rate = dphy_opts->hs_clk_rate; + + numerator = dphy_opts->hs_clk_rate; + denominator = ref_clk; +get_best_ratio (&numerator, &denominator,255 ,256 ); +if (!numerator || !denominator) { + dev_dbg(&phy->dev, "Invalid %ld/%ld for %ld/%ld\n",
dev_errshould be more appropriate here.Quoted 9 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +9
-0+static int mixel_dphy_ref_power_on (struct phy *phy) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); +u32 lock, timeout; +int ret =0 ; + +mutex_lock (&priv->lock); +clk_prepare_enable (priv->phy_ref_clk); +drivers/phy/phy-mixel-mipi-dphy.c line 267
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+phy_write (phy,PWR_ON ,DPHY_PD_DPHY ); +phy_write (phy,PWR_ON ,DPHY_PD_PLL ); + + timeout =100 ; +while (!(lock =phy_read (phy,DPHY_LOCK ))) { +udelay (10 ); +if (--timeout ==0 ) { +dev_err (&phy->dev,"Could not get DPHY lock!\n" ); +mutex_unlock (&priv->lock); +return -EINVAL ;Could you use
readl_poll_timeout()instead?drivers/phy/phy-mixel-mipi-dphy.c line 278
Quoted 4 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +4
-0+static int mixel_dphy_ref_power_off (struct phy *phy) +{ +struct mixel_dphy_priv *priv =phy_get_drvdata (phy); +int ret =0 ;This variable is not needed.
drivers/phy/phy-mixel-mipi-dphy.c line 288
Quoted 10 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +10
-0+ +mutex_lock (&priv->lock); + +phy_write (phy,PWR_OFF ,DPHY_PD_PLL ); +phy_write (phy,PWR_OFF ,DPHY_PD_DPHY ); + +clk_disable_unprepare (priv->phy_ref_clk); +mutex_unlock (&priv->lock); + +return ret;and you could simply do a 'return 0' instead.
drivers/phy/phy-mixel-mipi-dphy.c line 313
Quoted 5 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +5
-0+phy_write (phy,0x00 ,DPHY_LOCK_BYP ); +phy_write (phy,0x01 ,DPHY_TX_RCAL ); +phy_write (phy,0x00 ,DPHY_AUTO_PD_EN ); +phy_write (phy,0x01 ,DPHY_RXLPRP ); +phy_write (phy,0x01 ,DPHY_RXCDRP );
Quoted 6 lines
In the NXP vendor code the value 2 is written to this register:
phy_write(phy, 0x02, priv->plat_data->reg_rxcdrp);It would be good to dump all Mixel DSI PHY registers in the NXP vendor and in mainline and make sure they match.
Seems some of these changed quite a bit between the 4.9 and 4.14 NXP tree. I'll update things accordingly (and address the other stuff as well).
-- Guido
Quoted 7 lines
drivers/phy/phy-mixel-mipi-dphy.c line 406
Quoted 2 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +1
-0+ priv->regs =devm_ioremap (dev, res->start,SZ_256 );No need to hardcode
SZ_256here and the size should come from the device tree.You could also use
devm_ioremap_resource()instead.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] phy: Add driver for mixel dphy
In reply to Sam RavnborgHi Sam,
On Fri, Jan 25, 2019 at 05:53:55PM +0100, Sam Ravnborg wrote:
[..snip..]
Quoted 8 lines
Quoted 8 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +8
-0+struct mixel_dphy_cfg { +u32 cm; +u32 cn; +u32 co; +unsigned long hs_clk_rate; +u8 mc_prg_hs_prepare; +u8 m_prg_hs_prepare; +u8 mc_prg_hs_zero;
Quoted 8 lines
drivers/phy/phy-mixel-mipi-dphy.c line 71
Quoted 4 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +4
-0+u8 m_prg_hs_zero; +u8 mc_prg_hs_trail; +u8 m_prg_hs_trail; +};For the naive reader it would be helpful to spell out the names in a comment. As I assume the names comes from the data sheet the short names are OK - but let others know the purpose.
These are actual register names so I added comment just saying that.
[..snip..]
Quoted 6 lines
drivers/phy/phy-mixel-mipi-dphy.c line 134
Quoted 4 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +4
-0+static int mixel_dphy_config_from_opts (struct phy *phy, +struct phy_configure_opts_mipi_dphy *dphy_opts, +struct mixel_dphy_cfg *cfg) +{Align extra paratmers below the first parameter using tabs and add necessary spaces.
Due to the long phy_configure_opts_mipi_dpy this whole hit the 80 char limit so I left it like that to make checkpatch happy.
Quoted 20 lines
Quoted 20 lines
(quoted diff) +19
-0+ struct mixel_dphy_priv *priv = dev_get_drvdata(phy->dev.parent); + unsigned long ref_clk = clk_get_rate(priv->phy_ref_clk); + int i; + unsigned long numerator, denominator, frequency; + unsigned step; + +static int mixel_dphy_ref_power_on(struct phy *phy) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + u32 lock, timeout; + int ret = 0; + + mutex_lock(&priv->lock); + clk_prepare_enable(priv->phy_ref_clk); + + phy_write(phy, PWR_ON, DPHY_PD_DPHY); + phy_write(phy, PWR_ON, DPHY_PD_PLL); + + timeout = 100;
Quoted 8 lines
drivers/phy/phy-mixel-mipi-dphy.c line 268
Quoted 7 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +7
-0+while (!(lock =phy_read (phy,DPHY_LOCK ))) { +udelay (10 ); +if (--timeout ==0 ) { +dev_err (&phy->dev,"Could not get DPHY lock!\n" ); +mutex_unlock (&priv->lock); +return -EINVAL ; + }USe goto to have a single exit path where you do
mutex_unlock()
Using regmap I could drop the lock entirely.
[..snip..]
Quoted 16 lines
drivers/phy/phy-mixel-mipi-dphy.c line 373
Quoted 12 lines
drivers/phy/phy-mixel-mipi-dphy.c new file +12
-0+static const struct mixel_dphy_ops mixel_dphy_ref_ops = { + .power_on = mixel_dphy_ref_power_on, + .power_off = mixel_dphy_ref_power_off, +}; + +static const struct phy_ops mixel_dphy_ops = { + .power_on = mixel_dphy_power_on, + .power_off = mixel_dphy_power_off, + .configure = mixel_dphy_configure, + .validate = mixel_dphy_validate, + .owner =THIS_MODULE , +};This is confusing.
We have structmixel_dphy_ops=>mixel_dphy_ref_opsAnd then structphy_ops=>mixel_dphy_ops
Quoted 3 lines
So reading this there are to uses of
mixel_dphy_ops, one is a struct, and another is an instance of another type. Try to find a niming scheme that is less confusing.
Yeah, that's true. I found in another driver other imx8 variants have different register offsets so I went for register offsets in devdata rather than function pointer table which make this ambiguity go away too. I hope I have tackled all your other comments.
Thanks!
-- Guido
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel