Skip to content

Commit e4b3d38

Browse files
Sylwester Nawrockikishon
authored andcommitted
phy: exynos-video-mipi: Fix regression by adding support for PMU regmap
After the Exynos Power Management Unit (PMU) driver was converted to the platform device driver in commit 14fc8b9 ("ARM: EXYNOS: Add platform driver support for Exynos PMU") and then PMU device nodes added to Exynos4 DTs in commit 7b9613a ("ARM: dts: add PMU syscon node for exynos4") the mipi video phy driver started failing probing, due to overlapping memory mapped register region resources. Now all the Exynos peripheral devices which have registers in the PMU region are supposed to use the regmap provided by the syscon driver. So support for regmap is added in this patch, this unfortunately creates yet another indirection into that supposedly trivial driver. The additional mutex is required because single register is used by PHY pairs (they share bit in a register). An improvement here could be to allow a PHY instance be created with a driver custom mutex, which would then be common for each PHY pair. This would eliminate one of 3 mutexes which need to be taken in the phy_power_on/ phy_power_off code path. However, I tried to keep this bug fix patch possibly simple. This change is needed to make MIPI DSI displays and MIPI CSI-2 camera sensors working again on Exynos4 boards. Cc: Pankaj Dubey <pankaj.dubey@samsung.com> Cc: Kukjin Kim <kgene.kim@samsung.com> Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
1 parent 64d1140 commit e4b3d38

3 files changed

Lines changed: 79 additions & 33 deletions

File tree

‎Documentation/devicetree/bindings/phy/samsung-phy.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY
33

44
Required properties:
55
- compatible : should be "samsung,s5pv210-mipi-video-phy";
6-
- reg : offset and length of the MIPI DPHY register set;
76
- #phy-cells : from the generic phy bindings, must be 1;
7+
- syscon - phandle to the PMU system controller;
88

99
For "samsung,s5pv210-mipi-video-phy" compatible PHYs the second cell in
1010
the PHY specifier identifies the PHY and its meaning is as follows:

‎drivers/phy/phy-exynos-mipi-video.c‎

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
#include <linux/err.h>
1313
#include <linux/io.h>
1414
#include <linux/kernel.h>
15+
#include <linux/mfd/syscon/exynos4-pmu.h>
1516
#include <linux/module.h>
1617
#include <linux/of.h>
1718
#include <linux/of_address.h>
1819
#include <linux/phy/phy.h>
1920
#include <linux/platform_device.h>
21+
#include <linux/regmap.h>
2022
#include <linux/spinlock.h>
23+
#include <linux/mfd/syscon.h>
2124

22-
/* MIPI_PHYn_CONTROL register offset: n = 0..1 */
25+
/* MIPI_PHYn_CONTROL reg. offset (for base address from ioremap): n = 0..1 */
2326
#define EXYNOS_MIPI_PHY_CONTROL(n) ((n) * 4)
24-
#define EXYNOS_MIPI_PHY_ENABLE (1 << 0)
25-
#define EXYNOS_MIPI_PHY_SRESETN (1 << 1)
26-
#define EXYNOS_MIPI_PHY_MRESETN (1 << 2)
27-
#define EXYNOS_MIPI_PHY_RESET_MASK (3 << 1)
2827

2928
enum exynos_mipi_phy_id {
3029
EXYNOS_MIPI_PHY_ID_CSIS0,
@@ -38,43 +37,62 @@ enum exynos_mipi_phy_id {
3837
((id) == EXYNOS_MIPI_PHY_ID_DSIM0 || (id) == EXYNOS_MIPI_PHY_ID_DSIM1)
3938

4039
struct exynos_mipi_video_phy {
41-
spinlock_t slock;
4240
struct video_phy_desc {
4341
struct phy *phy;
4442
unsigned int index;
4543
} phys[EXYNOS_MIPI_PHYS_NUM];
44+
spinlock_t slock;
4645
void __iomem *regs;
46+
struct mutex mutex;
47+
struct regmap *regmap;
4748
};
4849

4950
static int __set_phy_state(struct exynos_mipi_video_phy *state,
5051
enum exynos_mipi_phy_id id, unsigned int on)
5152
{
53+
const unsigned int offset = EXYNOS4_MIPI_PHY_CONTROL(id / 2);
5254
void __iomem *addr;
53-
u32 reg, reset;
54-
55-
addr = state->regs + EXYNOS_MIPI_PHY_CONTROL(id / 2);
55+
u32 val, reset;
5656

5757
if (is_mipi_dsim_phy_id(id))
58-
reset = EXYNOS_MIPI_PHY_MRESETN;
59-
else
60-
reset = EXYNOS_MIPI_PHY_SRESETN;
61-
62-
spin_lock(&state->slock);
63-
reg = readl(addr);
64-
if (on)
65-
reg |= reset;
58+
reset = EXYNOS4_MIPI_PHY_MRESETN;
6659
else
67-
reg &= ~reset;
68-
writel(reg, addr);
69-
70-
/* Clear ENABLE bit only if MRESETN, SRESETN bits are not set. */
71-
if (on)
72-
reg |= EXYNOS_MIPI_PHY_ENABLE;
73-
else if (!(reg & EXYNOS_MIPI_PHY_RESET_MASK))
74-
reg &= ~EXYNOS_MIPI_PHY_ENABLE;
60+
reset = EXYNOS4_MIPI_PHY_SRESETN;
61+
62+
if (state->regmap) {
63+
mutex_lock(&state->mutex);
64+
regmap_read(state->regmap, offset, &val);
65+
if (on)
66+
val |= reset;
67+
else
68+
val &= ~reset;
69+
regmap_write(state->regmap, offset, val);
70+
if (on)
71+
val |= EXYNOS4_MIPI_PHY_ENABLE;
72+
else if (!(val & EXYNOS4_MIPI_PHY_RESET_MASK))
73+
val &= ~EXYNOS4_MIPI_PHY_ENABLE;
74+
regmap_write(state->regmap, offset, val);
75+
mutex_unlock(&state->mutex);
76+
} else {
77+
addr = state->regs + EXYNOS_MIPI_PHY_CONTROL(id / 2);
78+
79+
spin_lock(&state->slock);
80+
val = readl(addr);
81+
if (on)
82+
val |= reset;
83+
else
84+
val &= ~reset;
85+
writel(val, addr);
86+
/* Clear ENABLE bit only if MRESETN, SRESETN bits are not set */
87+
if (on)
88+
val |= EXYNOS4_MIPI_PHY_ENABLE;
89+
else if (!(val & EXYNOS4_MIPI_PHY_RESET_MASK))
90+
val &= ~EXYNOS4_MIPI_PHY_ENABLE;
91+
92+
writel(val, addr);
93+
spin_unlock(&state->slock);
94+
}
7595

76-
writel(reg, addr);
77-
spin_unlock(&state->slock);
7896
return 0;
7997
}
8098

@@ -118,22 +136,29 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev)
118136
{
119137
struct exynos_mipi_video_phy *state;
120138
struct device *dev = &pdev->dev;
121-
struct resource *res;
122139
struct phy_provider *phy_provider;
123140
unsigned int i;
124141

125142
state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
126143
if (!state)
127144
return -ENOMEM;
128145

129-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146+
state->regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
147+
if (IS_ERR(state->regmap)) {
148+
struct resource *res;
130149

131-
state->regs = devm_ioremap_resource(dev, res);
132-
if (IS_ERR(state->regs))
133-
return PTR_ERR(state->regs);
150+
dev_info(dev, "regmap lookup failed: %ld\n",
151+
PTR_ERR(state->regmap));
152+
153+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
154+
state->regs = devm_ioremap_resource(dev, res);
155+
if (IS_ERR(state->regs))
156+
return PTR_ERR(state->regs);
157+
}
134158

135159
dev_set_drvdata(dev, state);
136160
spin_lock_init(&state->slock);
161+
mutex_init(&state->mutex);
137162

138163
for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) {
139164
struct phy *phy = devm_phy_create(dev, NULL,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2015 Samsung Electronics Co., Ltd.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef _LINUX_MFD_SYSCON_PMU_EXYNOS4_H_
10+
#define _LINUX_MFD_SYSCON_PMU_EXYNOS4_H_
11+
12+
/* Exynos4 PMU register definitions */
13+
14+
/* MIPI_PHYn_CONTROL register offset: n = 0..1 */
15+
#define EXYNOS4_MIPI_PHY_CONTROL(n) (0x710 + (n) * 4)
16+
#define EXYNOS4_MIPI_PHY_ENABLE (1 << 0)
17+
#define EXYNOS4_MIPI_PHY_SRESETN (1 << 1)
18+
#define EXYNOS4_MIPI_PHY_MRESETN (1 << 2)
19+
#define EXYNOS4_MIPI_PHY_RESET_MASK (3 << 1)
20+
21+
#endif /* _LINUX_MFD_SYSCON_PMU_EXYNOS4_H_ */

0 commit comments

Comments
 (0)