176aefb22SNeil Armstrong // SPDX-License-Identifier: GPL-2.0
276aefb22SNeil Armstrong /*
376aefb22SNeil Armstrong * Meson AXG MIPI DPHY driver
476aefb22SNeil Armstrong *
576aefb22SNeil Armstrong * Copyright (C) 2018 Amlogic, Inc. All rights reserved
676aefb22SNeil Armstrong * Copyright (C) 2020 BayLibre, SAS
776aefb22SNeil Armstrong * Author: Neil Armstrong <narmstrong@baylibre.com>
876aefb22SNeil Armstrong */
976aefb22SNeil Armstrong
1076aefb22SNeil Armstrong #include <linux/bitfield.h>
1176aefb22SNeil Armstrong #include <linux/bitops.h>
129a8406baSLiu Ying #include <linux/bits.h>
1376aefb22SNeil Armstrong #include <linux/clk.h>
1476aefb22SNeil Armstrong #include <linux/delay.h>
1576aefb22SNeil Armstrong #include <linux/io.h>
16*7559e757SRob Herring #include <linux/mod_devicetable.h>
1776aefb22SNeil Armstrong #include <linux/module.h>
1876aefb22SNeil Armstrong #include <linux/regmap.h>
1976aefb22SNeil Armstrong #include <linux/reset.h>
2076aefb22SNeil Armstrong #include <linux/phy/phy.h>
2176aefb22SNeil Armstrong #include <linux/platform_device.h>
2276aefb22SNeil Armstrong
2376aefb22SNeil Armstrong /* [31] soft reset for the phy.
2476aefb22SNeil Armstrong * 1: reset. 0: dessert the reset.
2576aefb22SNeil Armstrong * [30] clock lane soft reset.
2676aefb22SNeil Armstrong * [29] data byte lane 3 soft reset.
2776aefb22SNeil Armstrong * [28] data byte lane 2 soft reset.
2876aefb22SNeil Armstrong * [27] data byte lane 1 soft reset.
2976aefb22SNeil Armstrong * [26] data byte lane 0 soft reset.
3076aefb22SNeil Armstrong * [25] mipi dsi pll clock selection.
3176aefb22SNeil Armstrong * 1: clock from fixed 850Mhz clock source. 0: from VID2 PLL.
3276aefb22SNeil Armstrong * [12] mipi HSbyteclk enable.
3376aefb22SNeil Armstrong * [11] mipi divider clk selection.
3476aefb22SNeil Armstrong * 1: select the mipi DDRCLKHS from clock divider.
3576aefb22SNeil Armstrong * 0: from PLL clock.
3676aefb22SNeil Armstrong * [10] mipi clock divider control.
3776aefb22SNeil Armstrong * 1: /4. 0: /2.
3876aefb22SNeil Armstrong * [9] mipi divider output enable.
3976aefb22SNeil Armstrong * [8] mipi divider counter enable.
4076aefb22SNeil Armstrong * [7] PLL clock enable.
4176aefb22SNeil Armstrong * [5] LPDT data endian.
4276aefb22SNeil Armstrong * 1 = transfer the high bit first. 0 : transfer the low bit first.
4376aefb22SNeil Armstrong * [4] HS data endian.
4476aefb22SNeil Armstrong * [3] force data byte lane in stop mode.
4576aefb22SNeil Armstrong * [2] force data byte lane 0 in receiver mode.
4676aefb22SNeil Armstrong * [1] write 1 to sync the txclkesc input. the internal logic have to
4776aefb22SNeil Armstrong * use txclkesc to decide Txvalid and Txready.
4876aefb22SNeil Armstrong * [0] enalbe the MIPI DPHY TxDDRClk.
4976aefb22SNeil Armstrong */
5076aefb22SNeil Armstrong #define MIPI_DSI_PHY_CTRL 0x0
5176aefb22SNeil Armstrong
5276aefb22SNeil Armstrong /* [31] clk lane tx_hs_en control selection.
5376aefb22SNeil Armstrong * 1: from register. 0: use clk lane state machine.
5476aefb22SNeil Armstrong * [30] register bit for clock lane tx_hs_en.
5576aefb22SNeil Armstrong * [29] clk lane tx_lp_en contrl selection.
5676aefb22SNeil Armstrong * 1: from register. 0: from clk lane state machine.
5776aefb22SNeil Armstrong * [28] register bit for clock lane tx_lp_en.
5876aefb22SNeil Armstrong * [27] chan0 tx_hs_en control selection.
5976aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
6076aefb22SNeil Armstrong * [26] register bit for chan0 tx_hs_en.
6176aefb22SNeil Armstrong * [25] chan0 tx_lp_en control selection.
6276aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
6376aefb22SNeil Armstrong * [24] register bit from chan0 tx_lp_en.
6476aefb22SNeil Armstrong * [23] chan0 rx_lp_en control selection.
6576aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
6676aefb22SNeil Armstrong * [22] register bit from chan0 rx_lp_en.
6776aefb22SNeil Armstrong * [21] chan0 contention detection enable control selection.
6876aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
6976aefb22SNeil Armstrong * [20] register bit from chan0 contention dectection enable.
7076aefb22SNeil Armstrong * [19] chan1 tx_hs_en control selection.
7176aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
7276aefb22SNeil Armstrong * [18] register bit for chan1 tx_hs_en.
7376aefb22SNeil Armstrong * [17] chan1 tx_lp_en control selection.
7476aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
7576aefb22SNeil Armstrong * [16] register bit from chan1 tx_lp_en.
7676aefb22SNeil Armstrong * [15] chan2 tx_hs_en control selection.
7776aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
7876aefb22SNeil Armstrong * [14] register bit for chan2 tx_hs_en.
7976aefb22SNeil Armstrong * [13] chan2 tx_lp_en control selection.
8076aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
8176aefb22SNeil Armstrong * [12] register bit from chan2 tx_lp_en.
8276aefb22SNeil Armstrong * [11] chan3 tx_hs_en control selection.
8376aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
8476aefb22SNeil Armstrong * [10] register bit for chan3 tx_hs_en.
8576aefb22SNeil Armstrong * [9] chan3 tx_lp_en control selection.
8676aefb22SNeil Armstrong * 1: from register. 0: from chan0 state machine.
8776aefb22SNeil Armstrong * [8] register bit from chan3 tx_lp_en.
8876aefb22SNeil Armstrong * [4] clk chan power down. this bit is also used as the power down
8976aefb22SNeil Armstrong * of the whole MIPI_DSI_PHY.
9076aefb22SNeil Armstrong * [3] chan3 power down.
9176aefb22SNeil Armstrong * [2] chan2 power down.
9276aefb22SNeil Armstrong * [1] chan1 power down.
9376aefb22SNeil Armstrong * [0] chan0 power down.
9476aefb22SNeil Armstrong */
9576aefb22SNeil Armstrong #define MIPI_DSI_CHAN_CTRL 0x4
9676aefb22SNeil Armstrong
9776aefb22SNeil Armstrong /* [24] rx turn watch dog triggered.
9876aefb22SNeil Armstrong * [23] rx esc watchdog triggered.
9976aefb22SNeil Armstrong * [22] mbias ready.
10076aefb22SNeil Armstrong * [21] txclkesc synced and ready.
10176aefb22SNeil Armstrong * [20:17] clk lane state. {mbias_ready, tx_stop, tx_ulps, tx_hs_active}
10276aefb22SNeil Armstrong * [16:13] chan3 state{0, tx_stop, tx_ulps, tx_hs_active}
10376aefb22SNeil Armstrong * [12:9] chan2 state.{0, tx_stop, tx_ulps, tx_hs_active}
10476aefb22SNeil Armstrong * [8:5] chan1 state. {0, tx_stop, tx_ulps, tx_hs_active}
10576aefb22SNeil Armstrong * [4:0] chan0 state. {TX_STOP, tx_ULPS, hs_active, direction, rxulpsesc}
10676aefb22SNeil Armstrong */
10776aefb22SNeil Armstrong #define MIPI_DSI_CHAN_STS 0x8
10876aefb22SNeil Armstrong
10976aefb22SNeil Armstrong /* [31:24] TCLK_PREPARE.
11076aefb22SNeil Armstrong * [23:16] TCLK_ZERO.
11176aefb22SNeil Armstrong * [15:8] TCLK_POST.
11276aefb22SNeil Armstrong * [7:0] TCLK_TRAIL.
11376aefb22SNeil Armstrong */
11476aefb22SNeil Armstrong #define MIPI_DSI_CLK_TIM 0xc
11576aefb22SNeil Armstrong
11676aefb22SNeil Armstrong /* [31:24] THS_PREPARE.
11776aefb22SNeil Armstrong * [23:16] THS_ZERO.
11876aefb22SNeil Armstrong * [15:8] THS_TRAIL.
11976aefb22SNeil Armstrong * [7:0] THS_EXIT.
12076aefb22SNeil Armstrong */
12176aefb22SNeil Armstrong #define MIPI_DSI_HS_TIM 0x10
12276aefb22SNeil Armstrong
12376aefb22SNeil Armstrong /* [31:24] tTA_GET.
12476aefb22SNeil Armstrong * [23:16] tTA_GO.
12576aefb22SNeil Armstrong * [15:8] tTA_SURE.
12676aefb22SNeil Armstrong * [7:0] tLPX.
12776aefb22SNeil Armstrong */
12876aefb22SNeil Armstrong #define MIPI_DSI_LP_TIM 0x14
12976aefb22SNeil Armstrong
13076aefb22SNeil Armstrong /* wait time to MIPI DIS analog ready. */
13176aefb22SNeil Armstrong #define MIPI_DSI_ANA_UP_TIM 0x18
13276aefb22SNeil Armstrong
13376aefb22SNeil Armstrong /* TINIT. */
13476aefb22SNeil Armstrong #define MIPI_DSI_INIT_TIM 0x1c
13576aefb22SNeil Armstrong
13676aefb22SNeil Armstrong /* TWAKEUP. */
13776aefb22SNeil Armstrong #define MIPI_DSI_WAKEUP_TIM 0x20
13876aefb22SNeil Armstrong
139f49f2eceSJiang Jian /* when in RxULPS check state, after the logic enable the analog,
14076aefb22SNeil Armstrong * how long we should wait to check the lP state .
14176aefb22SNeil Armstrong */
14276aefb22SNeil Armstrong #define MIPI_DSI_LPOK_TIM 0x24
14376aefb22SNeil Armstrong
14476aefb22SNeil Armstrong /* Watchdog for RX low power state no finished. */
14576aefb22SNeil Armstrong #define MIPI_DSI_LP_WCHDOG 0x28
14676aefb22SNeil Armstrong
14776aefb22SNeil Armstrong /* tMBIAS, after send power up signals to analog,
14876aefb22SNeil Armstrong * how long we should wait for analog powered up.
14976aefb22SNeil Armstrong */
15076aefb22SNeil Armstrong #define MIPI_DSI_ANA_CTRL 0x2c
15176aefb22SNeil Armstrong
15276aefb22SNeil Armstrong /* [31:8] reserved for future.
15376aefb22SNeil Armstrong * [7:0] tCLK_PRE.
15476aefb22SNeil Armstrong */
15576aefb22SNeil Armstrong #define MIPI_DSI_CLK_TIM1 0x30
15676aefb22SNeil Armstrong
15776aefb22SNeil Armstrong /* watchdog for turn around waiting time. */
15876aefb22SNeil Armstrong #define MIPI_DSI_TURN_WCHDOG 0x34
15976aefb22SNeil Armstrong
16076aefb22SNeil Armstrong /* When in RxULPS state, how frequency we should to check
16176aefb22SNeil Armstrong * if the TX side out of ULPS state.
16276aefb22SNeil Armstrong */
16376aefb22SNeil Armstrong #define MIPI_DSI_ULPS_CHECK 0x38
16476aefb22SNeil Armstrong #define MIPI_DSI_TEST_CTRL0 0x3c
16576aefb22SNeil Armstrong #define MIPI_DSI_TEST_CTRL1 0x40
16676aefb22SNeil Armstrong
16776aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv {
16876aefb22SNeil Armstrong struct device *dev;
16976aefb22SNeil Armstrong struct regmap *regmap;
17076aefb22SNeil Armstrong struct clk *clk;
17176aefb22SNeil Armstrong struct reset_control *reset;
17276aefb22SNeil Armstrong struct phy *analog;
17376aefb22SNeil Armstrong struct phy_configure_opts_mipi_dphy config;
17476aefb22SNeil Armstrong };
17576aefb22SNeil Armstrong
17676aefb22SNeil Armstrong static const struct regmap_config phy_meson_axg_mipi_dphy_regmap_conf = {
17776aefb22SNeil Armstrong .reg_bits = 8,
17876aefb22SNeil Armstrong .val_bits = 32,
17976aefb22SNeil Armstrong .reg_stride = 4,
18076aefb22SNeil Armstrong .max_register = MIPI_DSI_TEST_CTRL1,
18176aefb22SNeil Armstrong };
18276aefb22SNeil Armstrong
phy_meson_axg_mipi_dphy_init(struct phy * phy)18376aefb22SNeil Armstrong static int phy_meson_axg_mipi_dphy_init(struct phy *phy)
18476aefb22SNeil Armstrong {
18576aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv *priv = phy_get_drvdata(phy);
18676aefb22SNeil Armstrong int ret;
18776aefb22SNeil Armstrong
18876aefb22SNeil Armstrong ret = phy_init(priv->analog);
18976aefb22SNeil Armstrong if (ret)
19076aefb22SNeil Armstrong return ret;
19176aefb22SNeil Armstrong
19276aefb22SNeil Armstrong ret = reset_control_reset(priv->reset);
19376aefb22SNeil Armstrong if (ret)
19476aefb22SNeil Armstrong return ret;
19576aefb22SNeil Armstrong
19676aefb22SNeil Armstrong return 0;
19776aefb22SNeil Armstrong }
19876aefb22SNeil Armstrong
phy_meson_axg_mipi_dphy_configure(struct phy * phy,union phy_configure_opts * opts)19976aefb22SNeil Armstrong static int phy_meson_axg_mipi_dphy_configure(struct phy *phy,
20076aefb22SNeil Armstrong union phy_configure_opts *opts)
20176aefb22SNeil Armstrong {
20276aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv *priv = phy_get_drvdata(phy);
20376aefb22SNeil Armstrong int ret;
20476aefb22SNeil Armstrong
20576aefb22SNeil Armstrong ret = phy_mipi_dphy_config_validate(&opts->mipi_dphy);
20676aefb22SNeil Armstrong if (ret)
20776aefb22SNeil Armstrong return ret;
20876aefb22SNeil Armstrong
20976aefb22SNeil Armstrong ret = phy_configure(priv->analog, opts);
21076aefb22SNeil Armstrong if (ret)
21176aefb22SNeil Armstrong return ret;
21276aefb22SNeil Armstrong
21376aefb22SNeil Armstrong memcpy(&priv->config, opts, sizeof(priv->config));
21476aefb22SNeil Armstrong
21576aefb22SNeil Armstrong return 0;
21676aefb22SNeil Armstrong }
21776aefb22SNeil Armstrong
phy_meson_axg_mipi_dphy_power_on(struct phy * phy)21876aefb22SNeil Armstrong static int phy_meson_axg_mipi_dphy_power_on(struct phy *phy)
21976aefb22SNeil Armstrong {
22076aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv *priv = phy_get_drvdata(phy);
22176aefb22SNeil Armstrong int ret;
22276aefb22SNeil Armstrong unsigned long temp;
22376aefb22SNeil Armstrong
22476aefb22SNeil Armstrong ret = phy_power_on(priv->analog);
22576aefb22SNeil Armstrong if (ret)
22676aefb22SNeil Armstrong return ret;
22776aefb22SNeil Armstrong
22876aefb22SNeil Armstrong /* enable phy clock */
22976aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_PHY_CTRL, 0x1);
23076aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_PHY_CTRL,
23176aefb22SNeil Armstrong BIT(0) | /* enable the DSI PLL clock . */
23276aefb22SNeil Armstrong BIT(7) | /* enable pll clock which connected to DDR clock path */
23376aefb22SNeil Armstrong BIT(8)); /* enable the clock divider counter */
23476aefb22SNeil Armstrong
23576aefb22SNeil Armstrong /* enable the divider clock out */
23676aefb22SNeil Armstrong regmap_update_bits(priv->regmap, MIPI_DSI_PHY_CTRL, BIT(9), BIT(9));
23776aefb22SNeil Armstrong
23876aefb22SNeil Armstrong /* enable the byte clock generation. */
23976aefb22SNeil Armstrong regmap_update_bits(priv->regmap, MIPI_DSI_PHY_CTRL, BIT(12), BIT(12));
24076aefb22SNeil Armstrong regmap_update_bits(priv->regmap, MIPI_DSI_PHY_CTRL, BIT(31), BIT(31));
24176aefb22SNeil Armstrong regmap_update_bits(priv->regmap, MIPI_DSI_PHY_CTRL, BIT(31), 0);
24276aefb22SNeil Armstrong
24376aefb22SNeil Armstrong /* Calculate lanebyteclk period in ps */
24476aefb22SNeil Armstrong temp = (1000000 * 100) / (priv->config.hs_clk_rate / 1000);
24576aefb22SNeil Armstrong temp = temp * 8 * 10;
24676aefb22SNeil Armstrong
24776aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CLK_TIM,
24876aefb22SNeil Armstrong DIV_ROUND_UP(priv->config.clk_trail, temp) |
24976aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.clk_post +
25076aefb22SNeil Armstrong priv->config.hs_trail, temp) << 8) |
25176aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.clk_zero, temp) << 16) |
25276aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.clk_prepare, temp) << 24));
25376aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CLK_TIM1,
2549a8406baSLiu Ying DIV_ROUND_UP(priv->config.clk_pre, BITS_PER_BYTE));
25576aefb22SNeil Armstrong
25676aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_HS_TIM,
25776aefb22SNeil Armstrong DIV_ROUND_UP(priv->config.hs_exit, temp) |
25876aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.hs_trail, temp) << 8) |
25976aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.hs_zero, temp) << 16) |
26076aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.hs_prepare, temp) << 24));
26176aefb22SNeil Armstrong
26276aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_LP_TIM,
26376aefb22SNeil Armstrong DIV_ROUND_UP(priv->config.lpx, temp) |
26476aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.ta_sure, temp) << 8) |
26576aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.ta_go, temp) << 16) |
26676aefb22SNeil Armstrong (DIV_ROUND_UP(priv->config.ta_get, temp) << 24));
26776aefb22SNeil Armstrong
26876aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_ANA_UP_TIM, 0x0100);
26976aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_INIT_TIM,
27076aefb22SNeil Armstrong DIV_ROUND_UP(priv->config.init * NSEC_PER_MSEC, temp));
27176aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_WAKEUP_TIM,
27276aefb22SNeil Armstrong DIV_ROUND_UP(priv->config.wakeup * NSEC_PER_MSEC, temp));
27376aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_LPOK_TIM, 0x7C);
27476aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_ULPS_CHECK, 0x927C);
27576aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_LP_WCHDOG, 0x1000);
27676aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_TURN_WCHDOG, 0x1000);
27776aefb22SNeil Armstrong
27876aefb22SNeil Armstrong /* Powerup the analog circuit */
27976aefb22SNeil Armstrong switch (priv->config.lanes) {
28076aefb22SNeil Armstrong case 1:
28176aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CHAN_CTRL, 0xe);
28276aefb22SNeil Armstrong break;
28376aefb22SNeil Armstrong case 2:
28476aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CHAN_CTRL, 0xc);
28576aefb22SNeil Armstrong break;
28676aefb22SNeil Armstrong case 3:
28776aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CHAN_CTRL, 0x8);
28876aefb22SNeil Armstrong break;
28976aefb22SNeil Armstrong case 4:
29076aefb22SNeil Armstrong default:
29176aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CHAN_CTRL, 0);
29276aefb22SNeil Armstrong break;
29376aefb22SNeil Armstrong }
29476aefb22SNeil Armstrong
29576aefb22SNeil Armstrong /* Trigger a sync active for esc_clk */
29676aefb22SNeil Armstrong regmap_update_bits(priv->regmap, MIPI_DSI_PHY_CTRL, BIT(1), BIT(1));
29776aefb22SNeil Armstrong
29876aefb22SNeil Armstrong return 0;
29976aefb22SNeil Armstrong }
30076aefb22SNeil Armstrong
phy_meson_axg_mipi_dphy_power_off(struct phy * phy)30176aefb22SNeil Armstrong static int phy_meson_axg_mipi_dphy_power_off(struct phy *phy)
30276aefb22SNeil Armstrong {
30376aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv *priv = phy_get_drvdata(phy);
30476aefb22SNeil Armstrong
30576aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_CHAN_CTRL, 0xf);
30676aefb22SNeil Armstrong regmap_write(priv->regmap, MIPI_DSI_PHY_CTRL, BIT(31));
30776aefb22SNeil Armstrong
30876aefb22SNeil Armstrong phy_power_off(priv->analog);
30976aefb22SNeil Armstrong
31076aefb22SNeil Armstrong return 0;
31176aefb22SNeil Armstrong }
31276aefb22SNeil Armstrong
phy_meson_axg_mipi_dphy_exit(struct phy * phy)31376aefb22SNeil Armstrong static int phy_meson_axg_mipi_dphy_exit(struct phy *phy)
31476aefb22SNeil Armstrong {
31576aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv *priv = phy_get_drvdata(phy);
31676aefb22SNeil Armstrong int ret;
31776aefb22SNeil Armstrong
31876aefb22SNeil Armstrong ret = phy_exit(priv->analog);
31976aefb22SNeil Armstrong if (ret)
32076aefb22SNeil Armstrong return ret;
32176aefb22SNeil Armstrong
32276aefb22SNeil Armstrong return reset_control_reset(priv->reset);
32376aefb22SNeil Armstrong }
32476aefb22SNeil Armstrong
32576aefb22SNeil Armstrong static const struct phy_ops phy_meson_axg_mipi_dphy_ops = {
32676aefb22SNeil Armstrong .configure = phy_meson_axg_mipi_dphy_configure,
32776aefb22SNeil Armstrong .init = phy_meson_axg_mipi_dphy_init,
32876aefb22SNeil Armstrong .exit = phy_meson_axg_mipi_dphy_exit,
32976aefb22SNeil Armstrong .power_on = phy_meson_axg_mipi_dphy_power_on,
33076aefb22SNeil Armstrong .power_off = phy_meson_axg_mipi_dphy_power_off,
33176aefb22SNeil Armstrong .owner = THIS_MODULE,
33276aefb22SNeil Armstrong };
33376aefb22SNeil Armstrong
phy_meson_axg_mipi_dphy_probe(struct platform_device * pdev)33476aefb22SNeil Armstrong static int phy_meson_axg_mipi_dphy_probe(struct platform_device *pdev)
33576aefb22SNeil Armstrong {
33676aefb22SNeil Armstrong struct device *dev = &pdev->dev;
33776aefb22SNeil Armstrong struct phy_provider *phy_provider;
33876aefb22SNeil Armstrong struct phy_meson_axg_mipi_dphy_priv *priv;
33976aefb22SNeil Armstrong struct phy *phy;
34076aefb22SNeil Armstrong void __iomem *base;
34176aefb22SNeil Armstrong int ret;
34276aefb22SNeil Armstrong
34376aefb22SNeil Armstrong priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
34476aefb22SNeil Armstrong if (!priv)
34576aefb22SNeil Armstrong return -ENOMEM;
34676aefb22SNeil Armstrong
34776aefb22SNeil Armstrong priv->dev = dev;
34876aefb22SNeil Armstrong platform_set_drvdata(pdev, priv);
34976aefb22SNeil Armstrong
350d414c14cSYang Li base = devm_platform_ioremap_resource(pdev, 0);
35176aefb22SNeil Armstrong if (IS_ERR(base))
35276aefb22SNeil Armstrong return PTR_ERR(base);
35376aefb22SNeil Armstrong
35476aefb22SNeil Armstrong priv->regmap = devm_regmap_init_mmio(dev, base,
35576aefb22SNeil Armstrong &phy_meson_axg_mipi_dphy_regmap_conf);
35676aefb22SNeil Armstrong if (IS_ERR(priv->regmap))
35776aefb22SNeil Armstrong return PTR_ERR(priv->regmap);
35876aefb22SNeil Armstrong
35976aefb22SNeil Armstrong priv->clk = devm_clk_get(dev, "pclk");
36076aefb22SNeil Armstrong if (IS_ERR(priv->clk))
36176aefb22SNeil Armstrong return PTR_ERR(priv->clk);
36276aefb22SNeil Armstrong
36376aefb22SNeil Armstrong priv->reset = devm_reset_control_get(dev, "phy");
36476aefb22SNeil Armstrong if (IS_ERR(priv->reset))
36576aefb22SNeil Armstrong return PTR_ERR(priv->reset);
36676aefb22SNeil Armstrong
36776aefb22SNeil Armstrong priv->analog = devm_phy_get(dev, "analog");
36876aefb22SNeil Armstrong if (IS_ERR(priv->analog))
36976aefb22SNeil Armstrong return PTR_ERR(priv->analog);
37076aefb22SNeil Armstrong
37176aefb22SNeil Armstrong ret = clk_prepare_enable(priv->clk);
37276aefb22SNeil Armstrong if (ret)
37376aefb22SNeil Armstrong return ret;
37476aefb22SNeil Armstrong
37576aefb22SNeil Armstrong ret = reset_control_deassert(priv->reset);
37676aefb22SNeil Armstrong if (ret)
37776aefb22SNeil Armstrong return ret;
37876aefb22SNeil Armstrong
37976aefb22SNeil Armstrong phy = devm_phy_create(dev, NULL, &phy_meson_axg_mipi_dphy_ops);
38076aefb22SNeil Armstrong if (IS_ERR(phy)) {
38176aefb22SNeil Armstrong ret = PTR_ERR(phy);
38276aefb22SNeil Armstrong if (ret != -EPROBE_DEFER)
38376aefb22SNeil Armstrong dev_err(dev, "failed to create PHY\n");
38476aefb22SNeil Armstrong
38576aefb22SNeil Armstrong return ret;
38676aefb22SNeil Armstrong }
38776aefb22SNeil Armstrong
38876aefb22SNeil Armstrong phy_set_drvdata(phy, priv);
38976aefb22SNeil Armstrong
39076aefb22SNeil Armstrong phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
39176aefb22SNeil Armstrong
39276aefb22SNeil Armstrong return PTR_ERR_OR_ZERO(phy_provider);
39376aefb22SNeil Armstrong }
39476aefb22SNeil Armstrong
39576aefb22SNeil Armstrong static const struct of_device_id phy_meson_axg_mipi_dphy_of_match[] = {
39676aefb22SNeil Armstrong { .compatible = "amlogic,axg-mipi-dphy", },
39776aefb22SNeil Armstrong { },
39876aefb22SNeil Armstrong };
39976aefb22SNeil Armstrong MODULE_DEVICE_TABLE(of, phy_meson_axg_mipi_dphy_of_match);
40076aefb22SNeil Armstrong
40176aefb22SNeil Armstrong static struct platform_driver phy_meson_axg_mipi_dphy_driver = {
40276aefb22SNeil Armstrong .probe = phy_meson_axg_mipi_dphy_probe,
40376aefb22SNeil Armstrong .driver = {
40476aefb22SNeil Armstrong .name = "phy-meson-axg-mipi-dphy",
40576aefb22SNeil Armstrong .of_match_table = phy_meson_axg_mipi_dphy_of_match,
40676aefb22SNeil Armstrong },
40776aefb22SNeil Armstrong };
40876aefb22SNeil Armstrong module_platform_driver(phy_meson_axg_mipi_dphy_driver);
40976aefb22SNeil Armstrong
41076aefb22SNeil Armstrong MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
41176aefb22SNeil Armstrong MODULE_DESCRIPTION("Meson AXG MIPI DPHY driver");
41276aefb22SNeil Armstrong MODULE_LICENSE("GPL v2");
413