xref: /linux/arch/arm/mach-imx/anatop.c (revision fcc4f9fc5b23e6bb80f2c7833da323a485cad1b6)
1e95dddb3SAnson Huang /*
2e95dddb3SAnson Huang  * Copyright (C) 2013 Freescale Semiconductor, Inc.
3e95dddb3SAnson Huang  *
4e95dddb3SAnson Huang  * The code contained herein is licensed under the GNU General Public
5e95dddb3SAnson Huang  * License. You may obtain a copy of the GNU General Public License
6e95dddb3SAnson Huang  * Version 2 or later at the following locations:
7e95dddb3SAnson Huang  *
8e95dddb3SAnson Huang  * http://www.opensource.org/licenses/gpl-license.html
9e95dddb3SAnson Huang  * http://www.gnu.org/copyleft/gpl.html
10e95dddb3SAnson Huang  */
11e95dddb3SAnson Huang 
12e95dddb3SAnson Huang #include <linux/err.h>
13e95dddb3SAnson Huang #include <linux/io.h>
14e95dddb3SAnson Huang #include <linux/of.h>
15e95dddb3SAnson Huang #include <linux/of_address.h>
16e95dddb3SAnson Huang #include <linux/mfd/syscon.h>
17e95dddb3SAnson Huang #include <linux/regmap.h>
18*fcc4f9fcSFabio Estevam #include "common.h"
19e95dddb3SAnson Huang 
20e95dddb3SAnson Huang #define REG_SET		0x4
21e95dddb3SAnson Huang #define REG_CLR		0x8
22e95dddb3SAnson Huang 
23263475d4SAnson Huang #define ANADIG_REG_2P5		0x130
24e95dddb3SAnson Huang #define ANADIG_REG_CORE		0x140
25263475d4SAnson Huang #define ANADIG_ANA_MISC0	0x150
26e95dddb3SAnson Huang #define ANADIG_USB1_CHRG_DETECT	0x1b0
27e95dddb3SAnson Huang #define ANADIG_USB2_CHRG_DETECT	0x210
28e95dddb3SAnson Huang #define ANADIG_DIGPROG		0x260
29e95dddb3SAnson Huang 
30263475d4SAnson Huang #define BM_ANADIG_REG_2P5_ENABLE_WEAK_LINREG	0x40000
31e95dddb3SAnson Huang #define BM_ANADIG_REG_CORE_FET_ODRIVE		0x20000000
32263475d4SAnson Huang #define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG	0x1000
33e95dddb3SAnson Huang #define BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B	0x80000
34e95dddb3SAnson Huang #define BM_ANADIG_USB_CHRG_DETECT_EN_B		0x100000
35e95dddb3SAnson Huang 
36e95dddb3SAnson Huang static struct regmap *anatop;
37e95dddb3SAnson Huang 
38263475d4SAnson Huang static void imx_anatop_enable_weak2p5(bool enable)
39263475d4SAnson Huang {
40263475d4SAnson Huang 	u32 reg, val;
41263475d4SAnson Huang 
42263475d4SAnson Huang 	regmap_read(anatop, ANADIG_ANA_MISC0, &val);
43263475d4SAnson Huang 
44263475d4SAnson Huang 	/* can only be enabled when stop_mode_config is clear. */
45263475d4SAnson Huang 	reg = ANADIG_REG_2P5;
46263475d4SAnson Huang 	reg += (enable && (val & BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG) == 0) ?
47263475d4SAnson Huang 		REG_SET : REG_CLR;
48263475d4SAnson Huang 	regmap_write(anatop, reg, BM_ANADIG_REG_2P5_ENABLE_WEAK_LINREG);
49263475d4SAnson Huang }
50263475d4SAnson Huang 
51e95dddb3SAnson Huang static void imx_anatop_enable_fet_odrive(bool enable)
52e95dddb3SAnson Huang {
53e95dddb3SAnson Huang 	regmap_write(anatop, ANADIG_REG_CORE + (enable ? REG_SET : REG_CLR),
54e95dddb3SAnson Huang 		BM_ANADIG_REG_CORE_FET_ODRIVE);
55e95dddb3SAnson Huang }
56e95dddb3SAnson Huang 
57e95dddb3SAnson Huang void imx_anatop_pre_suspend(void)
58e95dddb3SAnson Huang {
59263475d4SAnson Huang 	imx_anatop_enable_weak2p5(true);
60e95dddb3SAnson Huang 	imx_anatop_enable_fet_odrive(true);
61e95dddb3SAnson Huang }
62e95dddb3SAnson Huang 
63e95dddb3SAnson Huang void imx_anatop_post_resume(void)
64e95dddb3SAnson Huang {
65e95dddb3SAnson Huang 	imx_anatop_enable_fet_odrive(false);
66263475d4SAnson Huang 	imx_anatop_enable_weak2p5(false);
67e95dddb3SAnson Huang }
68e95dddb3SAnson Huang 
69e95dddb3SAnson Huang void imx_anatop_usb_chrg_detect_disable(void)
70e95dddb3SAnson Huang {
71e95dddb3SAnson Huang 	regmap_write(anatop, ANADIG_USB1_CHRG_DETECT,
72e95dddb3SAnson Huang 		BM_ANADIG_USB_CHRG_DETECT_EN_B
73e95dddb3SAnson Huang 		| BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B);
74e95dddb3SAnson Huang 	regmap_write(anatop, ANADIG_USB2_CHRG_DETECT,
75e95dddb3SAnson Huang 		BM_ANADIG_USB_CHRG_DETECT_EN_B |
76e95dddb3SAnson Huang 		BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B);
77e95dddb3SAnson Huang }
78e95dddb3SAnson Huang 
79e95dddb3SAnson Huang u32 imx_anatop_get_digprog(void)
80e95dddb3SAnson Huang {
81e95dddb3SAnson Huang 	u32  val;
82e95dddb3SAnson Huang 
83e95dddb3SAnson Huang 	regmap_read(anatop, ANADIG_DIGPROG, &val);
84e95dddb3SAnson Huang 	return val;
85e95dddb3SAnson Huang }
86e95dddb3SAnson Huang 
87e95dddb3SAnson Huang void __init imx_anatop_init(void)
88e95dddb3SAnson Huang {
89e95dddb3SAnson Huang 	anatop = syscon_regmap_lookup_by_compatible("fsl,imx6q-anatop");
90e95dddb3SAnson Huang 	if (IS_ERR(anatop)) {
91e95dddb3SAnson Huang 		pr_err("%s: failed to find imx6q-anatop regmap!\n", __func__);
92e95dddb3SAnson Huang 		return;
93e95dddb3SAnson Huang 	}
94e95dddb3SAnson Huang }
95