blob: 73d81da93efc19975095ebbe47ef8d05f023c0a8 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2015 MediaTek Inc.
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 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14/******************************************************************************
15 * pmic_wrapper.c - Linux pmic_wrapper Driver
16 *
17 *
18 * DESCRIPTION:
19 * This file provid the other drivers PMIC wrapper relative functions
20 *
21 ******************************************************************************/
22
23#include <linux/kernel.h>
24#include <linux/platform_device.h>
25#include <linux/types.h>
26#include <linux/device.h>
27#include <linux/fs.h>
28#include <linux/module.h>
29/*#include <mach/mt_typedefs.h>*/
30#include <linux/timer.h>
31//#include <mtk_pmic_wrap.h>
32#include <linux/syscore_ops.h>
33#include <linux/regmap.h>
34#include <linux/soc/mediatek/pmic_wrap.h>
35#include <linux/of_address.h>
36#include <linux/of_fdt.h>
37#include <linux/of.h>
38#include <linux/of_irq.h>
39#include <linux/of_address.h>
40#include <linux/spinlock.h>
41
42static struct regmap *pmic_regmap;
43static spinlock_t wrp_lock = __SPIN_LOCK_UNLOCKED(lock);
44
45s32 pwrap_read(u32 adr, u32 *rdata)
46{
47 int ret = 0;
48 unsigned long flags = 0;
49
50 if (pmic_regmap) {
51 spin_lock_irqsave(&wrp_lock, flags);
52 ret = regmap_read(pmic_regmap, adr, rdata);
53 spin_unlock_irqrestore(&wrp_lock, flags);
54 } else
55 pr_notice("%s %d rec.\n", __func__, __LINE__);
56 return ret;
57}
58EXPORT_SYMBOL(pwrap_read);
59
60s32 pwrap_write(u32 adr, u32 wdata)
61{
62 int ret = 0;
63 unsigned long flags = 0;
64
65 if (pmic_regmap) {
66 spin_lock_irqsave(&wrp_lock, flags);
67 ret = regmap_write(pmic_regmap, adr, wdata);
68 spin_unlock_irqrestore(&wrp_lock, flags);
69 } else
70 pr_notice("%s %d Error.\n", __func__, __LINE__);
71 return ret;
72}
73EXPORT_SYMBOL(pwrap_write);
74
75static int __init mt_pwrap_init(void)
76{
77 struct device_node *node, *pwrap_node;
78
79 pr_info("%s\n", __func__);
80 node = of_find_compatible_node(NULL, NULL, "mediatek,pwraph");
81 pwrap_node = of_parse_phandle(node, "mediatek,pwrap-regmap", 0);
82 if (pwrap_node) {
83 pmic_regmap = pwrap_node_to_regmap(pwrap_node);
84 if (IS_ERR(pmic_regmap)) {
85 pr_notice("%s %d Error.\n", __func__, __LINE__);
86 return PTR_ERR(pmic_regmap);
87 }
88 } else {
89 pr_notice("%s %d Error.\n", __func__, __LINE__);
90 return -EINVAL;
91 }
92 return 0;
93}
94subsys_initcall(mt_pwrap_init);
95
96MODULE_AUTHOR("mediatek");
97MODULE_DESCRIPTION("pmic_wrapper Driver Revision");
98MODULE_LICENSE("GPL");