phy: amlogic: Add support for the G12A Analog MIPI D-PHY
v4 cover phy: amlogic: Add support for the G12A Analog MIPI D-PHY
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY to communicate with DSI panels, this adds the bindings.
This Analog D-PHY works with a separate Digital MIPI D-PHY.
This serie adds the Bindings and the PHY driver.
Changes from v3 at [3]:
- Add sentinel comment as requested by Martin
Changes from v2 at [2]:
- Bindings example fix
Changes from v1 at [1]:
- Bindings fixes
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]
Neil Armstrong (2):
dt-bindings: phy: add Amlogic G12A Analog MIPI D-PHY bindings
phy: amlogic: Add G12A Analog MIPI D-PHY driver
.../phy/amlogic,g12a-mipi-dphy-analog.yaml | 35 ++++ drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 4 files changed, 225 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml create mode 100644 drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c
Signature · 7 lines
2.25.1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
PATCH v4 1/2 dt-bindings: phy: add Amlogic G12A Analog MIPI D-PHY bindings
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY to communicate with DSI panels, this adds the bindings.
This Analog D-PHY works with a separate Digital MIPI D-PHY.
--- .../phy/amlogic,g12a-mipi-dphy-analog.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml
Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/phy/amlogic,g12a-mipi-dphy-analog.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Amlogic G12A MIPI analog PHY + +maintainers: + - Neil Armstrong <[email protected]> + +properties: + compatible: + const: amlogic,g12a-mipi-dphy-analog + + "#phy-cells": + const: 0 + + reg: + maxItems: 1 + +required: + - compatible + - reg + - "#phy-cells" + +additionalProperties: false + +examples: + - | + phy@0 { + compatible = "amlogic,g12a-mipi-dphy-analog"; + reg = <0x0 0xc>; + #phy-cells = <0>; + };
Signature · 1 line
2.25.1
Re: [PATCH v4 1/2] dt-bindings: phy: add Amlogic G12A Analog MIPI D-PHY bindings
Quoted 11 lines · Neil Armstrong
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY to communicate with DSI panels, this adds the bindings.
This Analog D-PHY works with a separate Digital MIPI D-PHY.
Signed-off-by Neil Armstrong <[email protected]>--- .../phy/amlogic,g12a-mipi-dphy-analog.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml
PATCH v4 2/2 phy: amlogic: Add G12A Analog MIPI D-PHY driver
In reply to Neil ArmstrongThe Amlogic G12A SoCs embeds an Analog MIPI D-PHY used to communicate with DSI panels.
--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c
drivers/phy/amlogic/Kconfig +12 -0
@@ -59,6 +59,18 @@ config PHY_MESON_G12A_USB3_PCIE in Meson G12A SoCs. If unsure, say N. +config PHY_MESON_G12A_MIPI_DPHY_ANALOG + tristate "Meson G12A MIPI Analog DPHY driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIO + select GENERIC_PHY_MIPI_DPHY + help + Enable this to support the Meson MIPI Analog DPHY found in Meson G12A + SoCs. + If unsure, say N. + config PHY_MESON_AXG_PCIE tristate "Meson AXG PCIE PHY driver" default ARCH_MESON
drivers/phy/amlogic/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.o +obj-$(CONFIG_PHY_MESON_G12A_MIPI_DPHY_ANALOG) += phy-meson-g12a-mipi-dphy-analog.o obj-$(CONFIG_PHY_MESON_AXG_PCIE) += phy-meson-axg-pcie.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_PCIE_ANALOG) += phy-meson-axg-mipi-pcie-analog.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_DPHY) += phy-meson-axg-mipi-dphy.o
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
2.25.1
Martin Blumenstingl
reviewerRe: [PATCH v4 2/2] phy: amlogic: Add G12A Analog MIPI D-PHY driver
Hi Neil,
Quoted 17 lines · Neil Armstrong
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY used to communicate with DSI panels.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.cdrivers/phy/amlogic/Kconfig +0
-0
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 67
Quoted 9 lines
drivers/phy/amlogic/Kconfig +6
-0@@ -59,6 +59,18 @@ config PHY_MESON_G12A_USB3_PCIE in Meson G12A SoCs. If unsure, say N. +config PHY_MESON_G12A_MIPI_DPHY_ANALOG + tristate "Meson G12A MIPI Analog DPHY driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIO
I think this should be "select MFD_SYSCON" as we're not using REGMAP_MMIO directly
[...]
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 69
Quoted 2 lines
drivers/phy/amlogic/Kconfig +2
-0+ /* Get the hhi system controller node */ + map = syscon_node_to_regmap(of_get_parent(dev->of_node));
I just reviewed a patch that adds of_node_put() for the node returned by of_get_parent() (after (syscon_node_to_regmap() has been used). I think we need the same here
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 73
Quoted 4 lines
drivers/phy/amlogic/Kconfig +4
-0+ if (IS_ERR(map)) { + dev_err(dev, + "failed to get HHI regmap\n"); + return PTR_ERR(map);
to simplify we can use:
return dev_err_probe(dev, PTR_ERR(map), "failed to get HHI regmap\n");
doesn't make much difference for this one though, but...
[...]
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE
Quoted 6 lines
drivers/phy/amlogic/Kconfig +6
-0+ priv->phy = devm_phy_create(dev, np, &phy_g12a_mipi_dphy_analog_ops); + if (IS_ERR(priv->phy)) { + ret = PTR_ERR(priv->phy); + if (ret != -EPROBE_DEFER) + dev_err(dev, "failed to create PHY\n"); + return ret;
here dev_err_probe() would simplify the code a lot
[...]
drivers/phy/amlogic/Kconfig
Quoted 5 lines
drivers/phy/amlogic/Kconfig +5
-0+static const struct of_device_id phy_g12a_mipi_dphy_analog_of_match[] = { + { + .compatible = "amlogic,g12a-mipi-dphy-analog", + }, + { /* sentinel */ },
super nit-pick: no comma here
Best regards,
Martin
Re: [PATCH v4 2/2] phy: amlogic: Add G12A Analog MIPI D-PHY driver
Quoted 62 lines · Martin Blumenstingl
Hi Neil,
Quoted 17 lines · Neil Armstrong
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY used to communicate with DSI panels.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 3 files changed, 190 insertions(+)create mode 100644
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.cdrivers/phy/amlogic/Kconfig +0
-0drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 67
Quoted 9 lines
drivers/phy/amlogic/Kconfig +6
-0@@ -59,6 +59,18 @@ config PHY_MESON_G12A_USB3_PCIE in Meson G12A SoCs. If unsure, say N. +config PHY_MESON_G12A_MIPI_DPHY_ANALOG + tristate "Meson G12A MIPI Analog DPHY driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIOI think this should be "select
MFD_SYSCON" as we're not usingREGMAP_MMIOdirectly[...]
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 69
Quoted 2 lines
drivers/phy/amlogic/Kconfig +2
-0+ /* Get the hhi system controller node */ + map = syscon_node_to_regmap(of_get_parent(dev->of_node));I just reviewed a patch that adds
of_node_put()for the node returned byof_get_parent()(after (syscon_node_to_regmap()has been used). I think we need the same heredrivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 73
Quoted 4 lines
drivers/phy/amlogic/Kconfig +4
-0+ if (IS_ERR(map)) { + dev_err(dev, + "failed to get HHI regmap\n"); + return PTR_ERR(map);to simplify we can use:
return dev_err_probe(dev, PTR_ERR(map), "failed to get HHI regmap\n");doesn't make much difference for this one though, but...
[...]
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE
Quoted 6 lines
drivers/phy/amlogic/Kconfig +6
-0+ priv->phy = devm_phy_create(dev, np, &phy_g12a_mipi_dphy_analog_ops); + if (IS_ERR(priv->phy)) { + ret = PTR_ERR(priv->phy); + if (ret != -EPROBE_DEFER) + dev_err(dev, "failed to create PHY\n"); + return ret;here
dev_err_probe()would simplify the code a lot[...]
drivers/phy/amlogic/Kconfig
Quoted 5 lines
drivers/phy/amlogic/Kconfig +5
-0+static const struct of_device_id phy_g12a_mipi_dphy_analog_of_match[] = { + { + .compatible = "amlogic,g12a-mipi-dphy-analog", + }, + { /* sentinel */ },
Quoted 5 lines
super nit-pick: no comma here
Best regards,
Martin
Thanks,
will fix all that.
Neil
Vinod Koul
maintainerRe: [PATCH v4 2/2] phy: amlogic: Add G12A Analog MIPI D-PHY driver
In reply to Neil ArmstrongQuoted 16 lines · Neil Armstrong
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY used to communicate with DSI panels.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.cdrivers/phy/amlogic/Kconfig +0
-0
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 62
Quoted 4 lines
drivers/phy/amlogic/Kconfig +1
-0@@ -59,6 +59,18 @@ config PHY_MESON_G12A_USB3_PCIE in Meson G12A SoCs. If unsure, say N. +config PHY_MESON_G12A_MIPI_DPHY_ANALOG
this should be sorted alphabetically, so before PHY_MESON_G12A_USB3_PCIE
Quoted 32 lines
drivers/phy/amlogic/Kconfig +11
-0+ tristate "Meson G12A MIPI Analog DPHY driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIO + select GENERIC_PHY_MIPI_DPHY + help + Enable this to support the Meson MIPI Analog DPHY found in Meson G12A + SoCs. + If unsure, say N. + config PHY_MESON_AXG_PCIE tristate "Meson AXG PCIE PHY driver" default ARCH_MESONdrivers/phy/amlogic/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.o +obj-$(CONFIG_PHY_MESON_G12A_MIPI_DPHY_ANALOG) += phy-meson-g12a-mipi-dphy-analog.o obj-$(CONFIG_PHY_MESON_AXG_PCIE) += phy-meson-axg-pcie.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_PCIE_ANALOG) += phy-meson-axg-mipi-pcie-analog.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_DPHY) += phy-meson-axg-mipi-dphy.odrivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +0
-0
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c line 6
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +6
-0@@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Meson G12A MIPI DSI Analog PHY +* +* Copyright (C) 2018 Amlogic, Inc. All rights reserved +* Copyright (C) 2020 BayLibre, SAS
2022 now?
Quoted 130 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +130
-0+* Author: Neil Armstrong <[email protected]> +*/ +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/module.h> +#include <linux/phy/phy.h> +#include <linux/regmap.h> +#include <linux/delay.h> +#include <linux/mfd/syscon.h> +#include <linux/platform_device.h> +#include <dt-bindings/phy/phy.h> + +#define HHI_MIPI_CNTL0 0x00 +#define HHI_MIPI_CNTL0_DIF_REF_CTL1 GENMASK(31, 16) +#define HHI_MIPI_CNTL0_DIF_REF_CTL0 GENMASK(15, 0) + +#define HHI_MIPI_CNTL1 0x04 +#define HHI_MIPI_CNTL1_BANDGAP BIT(16) +#define HHI_MIPI_CNTL2_DIF_REF_CTL2 GENMASK(15, 0) + +#define HHI_MIPI_CNTL2 0x08 +#define HHI_MIPI_CNTL2_DIF_TX_CTL1 GENMASK(31, 16) +#define HHI_MIPI_CNTL2_CH_EN GENMASK(15, 11) +#define HHI_MIPI_CNTL2_DIF_TX_CTL0 GENMASK(10, 0) + +#define DSI_LANE_0 BIT(4) +#define DSI_LANE_1 BIT(3) +#define DSI_LANE_CLK BIT(2) +#define DSI_LANE_2 BIT(1) +#define DSI_LANE_3 BIT(0) + +struct phy_g12a_mipi_dphy_analog_priv { +struct phy *phy; +struct regmap *regmap; +struct phy_configure_opts_mipi_dphy config; +}; + +static int phy_g12a_mipi_dphy_analog_configure (struct phy *phy, +union phy_configure_opts *opts) +{ +struct phy_g12a_mipi_dphy_analog_priv *priv =phy_get_drvdata (phy); +int ret; + + ret =phy_mipi_dphy_config_validate (&opts->mipi_dphy); +if (ret) +return ret; + +memcpy (&priv->config, opts,sizeof (priv->config)); + +return 0 ; +} + +static int phy_g12a_mipi_dphy_analog_power_on (struct phy *phy) +{ +struct phy_g12a_mipi_dphy_analog_priv *priv =phy_get_drvdata (phy); +unsigned int reg; + +regmap_write (priv->regmap,HHI_MIPI_CNTL0 , +FIELD_PREP (HHI_MIPI_CNTL0_DIF_REF_CTL0 ,0x8 ) | +FIELD_PREP (HHI_MIPI_CNTL0_DIF_REF_CTL1 ,0xa487 )); + +regmap_write (priv->regmap,HHI_MIPI_CNTL1 , +FIELD_PREP (HHI_MIPI_CNTL2_DIF_REF_CTL2 ,0x2e ) | +HHI_MIPI_CNTL1_BANDGAP ); + +regmap_write (priv->regmap,HHI_MIPI_CNTL2 , +FIELD_PREP (HHI_MIPI_CNTL2_DIF_TX_CTL0 ,0x459 ) | +FIELD_PREP (HHI_MIPI_CNTL2_DIF_TX_CTL1 ,0x2680 )); + + reg =DSI_LANE_CLK ; +switch (priv->config.lanes) { +case 4 : + reg |=DSI_LANE_3 ; + fallthrough; +case 3 : + reg |=DSI_LANE_2 ; + fallthrough; +case 2 : + reg |=DSI_LANE_1 ; + fallthrough; +case 1 : + reg |=DSI_LANE_0 ; +break ; +default : + reg =0 ; + } + +regmap_update_bits (priv->regmap,HHI_MIPI_CNTL2 , +HHI_MIPI_CNTL2_CH_EN , +FIELD_PREP (HHI_MIPI_CNTL2_CH_EN , reg)); + +return 0 ; +} + +static int phy_g12a_mipi_dphy_analog_power_off (struct phy *phy) +{ +struct phy_g12a_mipi_dphy_analog_priv *priv =phy_get_drvdata (phy); + +regmap_write (priv->regmap,HHI_MIPI_CNTL0 ,0 ); +regmap_write (priv->regmap,HHI_MIPI_CNTL1 ,0 ); +regmap_write (priv->regmap,HHI_MIPI_CNTL2 ,0 ); + +return 0 ; +} + +static const struct phy_ops phy_g12a_mipi_dphy_analog_ops = { + .configure = phy_g12a_mipi_dphy_analog_configure, + .power_on = phy_g12a_mipi_dphy_analog_power_on, + .power_off = phy_g12a_mipi_dphy_analog_power_off, + .owner =THIS_MODULE , +}; + +static int phy_g12a_mipi_dphy_analog_probe (struct platform_device *pdev) +{ +struct phy_provider *phy; +struct device *dev = &pdev->dev; +struct phy_g12a_mipi_dphy_analog_priv *priv; +struct device_node *np = dev->of_node; +struct regmap *map; +int ret; + + priv =devm_kmalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +/* Get the hhi system controller node */ + map =syscon_node_to_regmap (of_get_parent (dev->of_node)); +if (IS_ERR (map)) { +dev_err (dev, +"failed to get HHI regmap\n" );
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c line 146
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +10
-0+return PTR_ERR (map); + } + + priv->regmap = map; + + priv->phy =devm_phy_create (dev, np, &phy_g12a_mipi_dphy_analog_ops); +if (IS_ERR (priv->phy)) { + ret =PTR_ERR (priv->phy); +if (ret != -EPROBE_DEFER ) +dev_err (dev,"failed to create PHY\n" );
log the error ?
Quoted 33 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +31
-0+return ret; + } + +phy_set_drvdata (priv->phy, priv); +dev_set_drvdata (dev, priv); + + phy =devm_of_phy_provider_register (dev, of_phy_simple_xlate); + +return PTR_ERR_OR_ZERO (phy); +} + +static const struct of_device_id phy_g12a_mipi_dphy_analog_of_match[] = { + { + .compatible ="amlogic,g12a-mipi-dphy-analog" , + }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, phy_g12a_mipi_dphy_analog_of_match); + +static struct platform_driver phy_g12a_mipi_dphy_analog_driver = { + .probe = phy_g12a_mipi_dphy_analog_probe, + .driver = { + .name ="phy-meson-g12a-mipi-dphy-analog" , + .of_match_table = phy_g12a_mipi_dphy_analog_of_match, + }, +}; +module_platform_driver (phy_g12a_mipi_dphy_analog_driver); + +MODULE_AUTHOR ("Neil Armstrong <[email protected]>" ); +MODULE_DESCRIPTION ("Meson G12A MIPI Analog D-PHY driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.25.1
Signature · 1 line
~Vinod
Re: [PATCH v4 2/2] phy: amlogic: Add G12A Analog MIPI D-PHY driver
Hi,
Quoted 20 lines · Vinod Koul
Quoted 19 lines · Neil Armstrong
The Amlogic G12A SoCs embeds an Analog MIPI D-PHY used to communicate with DSI panels.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 3 files changed, 190 insertions(+)create mode 100644
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.cdrivers/phy/amlogic/Kconfig +0
-0@@ -59,6 +59,18 @@ config PHY_MESON_G12A_USB3_PCIE in Meson G12A SoCs. If unsure, say N.
Quoted 3 lines
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB3_PCIE · line 62
Quoted 1 line
drivers/phy/amlogic/Kconfig +1
-0+config PHY_MESON_G12A_MIPI_DPHY_ANALOGthis should be sorted alphabetically, so before
PHY_MESON_G12A_USB3_PCIE
Ack
Quoted 33 lines
Quoted 33 lines
drivers/phy/amlogic/Kconfig +11
-0+ tristate "Meson G12A MIPI Analog DPHY driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIO + select GENERIC_PHY_MIPI_DPHY + help + Enable this to support the Meson MIPI Analog DPHY found in Meson G12A + SoCs. + If unsure, say N. + config PHY_MESON_AXG_PCIE tristate "Meson AXG PCIE PHY driver" default ARCH_MESONdrivers/phy/amlogic/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.o +obj-$(CONFIG_PHY_MESON_G12A_MIPI_DPHY_ANALOG) += phy-meson-g12a-mipi-dphy-analog.o obj-$(CONFIG_PHY_MESON_AXG_PCIE) += phy-meson-axg-pcie.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_PCIE_ANALOG) += phy-meson-axg-mipi-pcie-analog.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_DPHY) += phy-meson-axg-mipi-dphy.odrivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +0
-0@@ -0,0 +1,177 @@
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c line 6
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +6
-0+// SPDX-License-Identifier: GPL-2.0 +/* +* Meson G12A MIPI DSI Analog PHY +* +* Copyright (C) 2018 Amlogic, Inc. All rights reserved +* Copyright (C) 2020 BayLibre, SAS 2022 now?
Well it was developed in 2020, but I'll update it anyway
Quoted 135 lines
Quoted 135 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +134
-0+* Author: Neil Armstrong <[email protected]> +*/ +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/module.h> +#include <linux/phy/phy.h> +#include <linux/regmap.h> +#include <linux/delay.h> +#include <linux/mfd/syscon.h> +#include <linux/platform_device.h> +#include <dt-bindings/phy/phy.h> + +#define HHI_MIPI_CNTL0 0x00 +#define HHI_MIPI_CNTL0_DIF_REF_CTL1 GENMASK(31, 16) +#define HHI_MIPI_CNTL0_DIF_REF_CTL0 GENMASK(15, 0) + +#define HHI_MIPI_CNTL1 0x04 +#define HHI_MIPI_CNTL1_BANDGAP BIT(16) +#define HHI_MIPI_CNTL2_DIF_REF_CTL2 GENMASK(15, 0) + +#define HHI_MIPI_CNTL2 0x08 +#define HHI_MIPI_CNTL2_DIF_TX_CTL1 GENMASK(31, 16) +#define HHI_MIPI_CNTL2_CH_EN GENMASK(15, 11) +#define HHI_MIPI_CNTL2_DIF_TX_CTL0 GENMASK(10, 0) + +#define DSI_LANE_0 BIT(4) +#define DSI_LANE_1 BIT(3) +#define DSI_LANE_CLK BIT(2) +#define DSI_LANE_2 BIT(1) +#define DSI_LANE_3 BIT(0) + +struct phy_g12a_mipi_dphy_analog_priv { +struct phy *phy; +struct regmap *regmap; +struct phy_configure_opts_mipi_dphy config; +}; + +static int phy_g12a_mipi_dphy_analog_configure (struct phy *phy, +union phy_configure_opts *opts) +{ +struct phy_g12a_mipi_dphy_analog_priv *priv =phy_get_drvdata (phy); +int ret; + + ret =phy_mipi_dphy_config_validate (&opts->mipi_dphy); +if (ret) +return ret; + +memcpy (&priv->config, opts,sizeof (priv->config)); + +return 0 ; +} + +static int phy_g12a_mipi_dphy_analog_power_on (struct phy *phy) +{ +struct phy_g12a_mipi_dphy_analog_priv *priv =phy_get_drvdata (phy); +unsigned int reg; + +regmap_write (priv->regmap,HHI_MIPI_CNTL0 , +FIELD_PREP (HHI_MIPI_CNTL0_DIF_REF_CTL0 ,0x8 ) | +FIELD_PREP (HHI_MIPI_CNTL0_DIF_REF_CTL1 ,0xa487 )); + +regmap_write (priv->regmap,HHI_MIPI_CNTL1 , +FIELD_PREP (HHI_MIPI_CNTL2_DIF_REF_CTL2 ,0x2e ) | +HHI_MIPI_CNTL1_BANDGAP ); + +regmap_write (priv->regmap,HHI_MIPI_CNTL2 , +FIELD_PREP (HHI_MIPI_CNTL2_DIF_TX_CTL0 ,0x459 ) | +FIELD_PREP (HHI_MIPI_CNTL2_DIF_TX_CTL1 ,0x2680 )); + + reg =DSI_LANE_CLK ; +switch (priv->config.lanes) { +case 4 : + reg |=DSI_LANE_3 ; + fallthrough; +case 3 : + reg |=DSI_LANE_2 ; + fallthrough; +case 2 : + reg |=DSI_LANE_1 ; + fallthrough; +case 1 : + reg |=DSI_LANE_0 ; +break ; +default : + reg =0 ; + } + +regmap_update_bits (priv->regmap,HHI_MIPI_CNTL2 , +HHI_MIPI_CNTL2_CH_EN , +FIELD_PREP (HHI_MIPI_CNTL2_CH_EN , reg)); + +return 0 ; +} + +static int phy_g12a_mipi_dphy_analog_power_off (struct phy *phy) +{ +struct phy_g12a_mipi_dphy_analog_priv *priv =phy_get_drvdata (phy); + +regmap_write (priv->regmap,HHI_MIPI_CNTL0 ,0 ); +regmap_write (priv->regmap,HHI_MIPI_CNTL1 ,0 ); +regmap_write (priv->regmap,HHI_MIPI_CNTL2 ,0 ); + +return 0 ; +} + +static const struct phy_ops phy_g12a_mipi_dphy_analog_ops = { + .configure = phy_g12a_mipi_dphy_analog_configure, + .power_on = phy_g12a_mipi_dphy_analog_power_on, + .power_off = phy_g12a_mipi_dphy_analog_power_off, + .owner =THIS_MODULE , +}; + +static int phy_g12a_mipi_dphy_analog_probe (struct platform_device *pdev) +{ +struct phy_provider *phy; +struct device *dev = &pdev->dev; +struct phy_g12a_mipi_dphy_analog_priv *priv; +struct device_node *np = dev->of_node; +struct regmap *map; +int ret; + + priv =devm_kmalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +/* Get the hhi system controller node */ + map =syscon_node_to_regmap (of_get_parent (dev->of_node)); +if (IS_ERR (map)) { +dev_err (dev, +"failed to get HHI regmap\n" ); +return PTR_ERR (map); + } + + priv->regmap = map;
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c line 146
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +6
-0+ + priv->phy =devm_phy_create (dev, np, &phy_g12a_mipi_dphy_analog_ops); +if (IS_ERR (priv->phy)) { + ret =PTR_ERR (priv->phy); +if (ret != -EPROBE_DEFER ) +dev_err (dev,"failed to create PHY\n" );log the error ?
Ack
Quoted 26 lines
Quoted 26 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +25
-0+return ret; + } + +phy_set_drvdata (priv->phy, priv); +dev_set_drvdata (dev, priv); + + phy =devm_of_phy_provider_register (dev, of_phy_simple_xlate); + +return PTR_ERR_OR_ZERO (phy); +} + +static const struct of_device_id phy_g12a_mipi_dphy_analog_of_match[] = { + { + .compatible ="amlogic,g12a-mipi-dphy-analog" , + }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, phy_g12a_mipi_dphy_analog_of_match); + +static struct platform_driver phy_g12a_mipi_dphy_analog_driver = { + .probe = phy_g12a_mipi_dphy_analog_probe, + .driver = { + .name ="phy-meson-g12a-mipi-dphy-analog" , + .of_match_table = phy_g12a_mipi_dphy_analog_of_match, + },
Quoted 9 lines
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file +6
-0+}; +module_platform_driver (phy_g12a_mipi_dphy_analog_driver); + +MODULE_AUTHOR ("Neil Armstrong <[email protected]>" ); +MODULE_DESCRIPTION ("Meson G12A MIPI Analog D-PHY driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.25.1
Thanks for ther review,
Neil