2 * Copyright (C) 2015 - 2016 Samsung Electronics Co., Ltd.
4 * Authors: Inha Song <ideal.song@samsung.com>
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
7 * Samsung Exynos SoC series Low Power Audio Subsystem driver.
9 * This module provides regmap for the Top SFR region and instantiates
10 * devices for IP blocks like DMAC, I2S, UART.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 and
14 * only version 2 as published by the Free Software Foundation.
17 #include <linux/delay.h>
19 #include <linux/module.h>
20 #include <linux/mfd/syscon.h>
21 #include <linux/mfd/syscon/exynos5-pmu.h>
23 #include <linux/of_platform.h>
24 #include <linux/platform_device.h>
25 #include <linux/regmap.h>
26 #include <linux/types.h>
28 /* LPASS Top register definitions */
29 #define SFR_LPASS_CORE_SW_RESET 0x08
30 #define LPASS_SB_SW_RESET BIT(11)
31 #define LPASS_UART_SW_RESET BIT(10)
32 #define LPASS_PCM_SW_RESET BIT(9)
33 #define LPASS_I2S_SW_RESET BIT(8)
34 #define LPASS_WDT1_SW_RESET BIT(4)
35 #define LPASS_WDT0_SW_RESET BIT(3)
36 #define LPASS_TIMER_SW_RESET BIT(2)
37 #define LPASS_MEM_SW_RESET BIT(1)
38 #define LPASS_DMA_SW_RESET BIT(0)
40 #define SFR_LPASS_INTR_CA5_MASK 0x48
41 #define SFR_LPASS_INTR_CPU_MASK 0x58
42 #define LPASS_INTR_APM BIT(9)
43 #define LPASS_INTR_MIF BIT(8)
44 #define LPASS_INTR_TIMER BIT(7)
45 #define LPASS_INTR_DMA BIT(6)
46 #define LPASS_INTR_GPIO BIT(5)
47 #define LPASS_INTR_I2S BIT(4)
48 #define LPASS_INTR_PCM BIT(3)
49 #define LPASS_INTR_SLIMBUS BIT(2)
50 #define LPASS_INTR_UART BIT(1)
51 #define LPASS_INTR_SFR BIT(0)
54 /* pointer to the Power Management Unit regmap */
56 /* pointer to the LPASS TOP regmap */
60 static void exynos_lpass_core_sw_reset(struct exynos_lpass
*lpass
, int mask
)
64 regmap_read(lpass
->top
, SFR_LPASS_CORE_SW_RESET
, &val
);
67 regmap_write(lpass
->top
, SFR_LPASS_CORE_SW_RESET
, val
);
69 usleep_range(100, 150);
72 regmap_write(lpass
->top
, SFR_LPASS_CORE_SW_RESET
, val
);
75 static void exynos_lpass_enable(struct exynos_lpass
*lpass
)
77 /* Unmask SFR, DMA and I2S interrupt */
78 regmap_write(lpass
->top
, SFR_LPASS_INTR_CA5_MASK
,
79 LPASS_INTR_SFR
| LPASS_INTR_DMA
| LPASS_INTR_I2S
);
81 regmap_write(lpass
->top
, SFR_LPASS_INTR_CPU_MASK
,
82 LPASS_INTR_SFR
| LPASS_INTR_DMA
| LPASS_INTR_I2S
);
84 /* Activate related PADs from retention state */
85 regmap_write(lpass
->pmu
, EXYNOS5433_PAD_RETENTION_AUD_OPTION
,
86 EXYNOS5433_PAD_INITIATE_WAKEUP_FROM_LOWPWR
);
88 exynos_lpass_core_sw_reset(lpass
, LPASS_I2S_SW_RESET
);
89 exynos_lpass_core_sw_reset(lpass
, LPASS_DMA_SW_RESET
);
90 exynos_lpass_core_sw_reset(lpass
, LPASS_MEM_SW_RESET
);
93 static void exynos_lpass_disable(struct exynos_lpass
*lpass
)
95 /* Mask any unmasked IP interrupt sources */
96 regmap_write(lpass
->top
, SFR_LPASS_INTR_CPU_MASK
, 0);
97 regmap_write(lpass
->top
, SFR_LPASS_INTR_CA5_MASK
, 0);
99 /* Deactivate related PADs from retention state */
100 regmap_write(lpass
->pmu
, EXYNOS5433_PAD_RETENTION_AUD_OPTION
, 0);
103 static const struct regmap_config exynos_lpass_reg_conf
= {
107 .max_register
= 0xfc,
111 static int exynos_lpass_probe(struct platform_device
*pdev
)
113 struct device
*dev
= &pdev
->dev
;
114 struct exynos_lpass
*lpass
;
115 void __iomem
*base_top
;
116 struct resource
*res
;
118 lpass
= devm_kzalloc(dev
, sizeof(*lpass
), GFP_KERNEL
);
122 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
123 base_top
= devm_ioremap_resource(dev
, res
);
124 if (IS_ERR(base_top
))
125 return PTR_ERR(base_top
);
127 lpass
->top
= regmap_init_mmio(dev
, base_top
,
128 &exynos_lpass_reg_conf
);
129 if (IS_ERR(lpass
->top
)) {
130 dev_err(dev
, "LPASS top regmap initialization failed\n");
131 return PTR_ERR(lpass
->top
);
134 lpass
->pmu
= syscon_regmap_lookup_by_phandle(dev
->of_node
,
135 "samsung,pmu-syscon");
136 if (IS_ERR(lpass
->pmu
)) {
137 dev_err(dev
, "Failed to lookup PMU regmap\n");
138 return PTR_ERR(lpass
->pmu
);
141 platform_set_drvdata(pdev
, lpass
);
142 exynos_lpass_enable(lpass
);
144 return of_platform_populate(dev
->of_node
, NULL
, NULL
, dev
);
147 static int __maybe_unused
exynos_lpass_suspend(struct device
*dev
)
149 struct exynos_lpass
*lpass
= dev_get_drvdata(dev
);
151 exynos_lpass_disable(lpass
);
156 static int __maybe_unused
exynos_lpass_resume(struct device
*dev
)
158 struct exynos_lpass
*lpass
= dev_get_drvdata(dev
);
160 exynos_lpass_enable(lpass
);
165 static SIMPLE_DEV_PM_OPS(lpass_pm_ops
, exynos_lpass_suspend
,
166 exynos_lpass_resume
);
168 static const struct of_device_id exynos_lpass_of_match
[] = {
169 { .compatible
= "samsung,exynos5433-lpass" },
172 MODULE_DEVICE_TABLE(of
, exynos_lpass_of_match
);
174 static struct platform_driver exynos_lpass_driver
= {
176 .name
= "exynos-lpass",
178 .of_match_table
= exynos_lpass_of_match
,
180 .probe
= exynos_lpass_probe
,
182 module_platform_driver(exynos_lpass_driver
);
184 MODULE_DESCRIPTION("Samsung Low Power Audio Subsystem driver");
185 MODULE_LICENSE("GPL v2");