Anson Huang | e95dddb | 2013-03-20 19:39:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * The code contained herein is licensed under the GNU General Public |
| 5 | * License. You may obtain a copy of the GNU General Public License |
| 6 | * Version 2 or later at the following locations: |
| 7 | * |
| 8 | * http://www.opensource.org/licenses/gpl-license.html |
| 9 | * http://www.gnu.org/copyleft/gpl.html |
| 10 | */ |
| 11 | |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <linux/mfd/syscon.h> |
| 17 | #include <linux/regmap.h> |
| 18 | |
| 19 | #define REG_SET 0x4 |
| 20 | #define REG_CLR 0x8 |
| 21 | |
| 22 | #define ANADIG_REG_CORE 0x140 |
| 23 | #define ANADIG_USB1_CHRG_DETECT 0x1b0 |
| 24 | #define ANADIG_USB2_CHRG_DETECT 0x210 |
| 25 | #define ANADIG_DIGPROG 0x260 |
| 26 | |
| 27 | #define BM_ANADIG_REG_CORE_FET_ODRIVE 0x20000000 |
| 28 | #define BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B 0x80000 |
| 29 | #define BM_ANADIG_USB_CHRG_DETECT_EN_B 0x100000 |
| 30 | |
| 31 | static struct regmap *anatop; |
| 32 | |
| 33 | static void imx_anatop_enable_fet_odrive(bool enable) |
| 34 | { |
| 35 | regmap_write(anatop, ANADIG_REG_CORE + (enable ? REG_SET : REG_CLR), |
| 36 | BM_ANADIG_REG_CORE_FET_ODRIVE); |
| 37 | } |
| 38 | |
| 39 | void imx_anatop_pre_suspend(void) |
| 40 | { |
| 41 | imx_anatop_enable_fet_odrive(true); |
| 42 | } |
| 43 | |
| 44 | void imx_anatop_post_resume(void) |
| 45 | { |
| 46 | imx_anatop_enable_fet_odrive(false); |
| 47 | } |
| 48 | |
| 49 | void imx_anatop_usb_chrg_detect_disable(void) |
| 50 | { |
| 51 | regmap_write(anatop, ANADIG_USB1_CHRG_DETECT, |
| 52 | BM_ANADIG_USB_CHRG_DETECT_EN_B |
| 53 | | BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B); |
| 54 | regmap_write(anatop, ANADIG_USB2_CHRG_DETECT, |
| 55 | BM_ANADIG_USB_CHRG_DETECT_EN_B | |
| 56 | BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B); |
| 57 | } |
| 58 | |
| 59 | u32 imx_anatop_get_digprog(void) |
| 60 | { |
| 61 | u32 val; |
| 62 | |
| 63 | regmap_read(anatop, ANADIG_DIGPROG, &val); |
| 64 | return val; |
| 65 | } |
| 66 | |
| 67 | void __init imx_anatop_init(void) |
| 68 | { |
| 69 | anatop = syscon_regmap_lookup_by_compatible("fsl,imx6q-anatop"); |
| 70 | if (IS_ERR(anatop)) { |
| 71 | pr_err("%s: failed to find imx6q-anatop regmap!\n", __func__); |
| 72 | return; |
| 73 | } |
| 74 | } |