blob: 70794d7631fecaa1254f9f3f6f9b098eafdf3927 [file] [log] [blame]
yang.li24770372022-01-11 15:21:49 +08001/*
2 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: MIT
5 */
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08006
7#ifndef __PMIC_H__
8
9#define __PMIC_H__
10
11//#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
12
13#define NULL1 ((void *)0)
14
15#define PMIC_ENBALE 1
16#define PMIC_DISABLE 0
17#define PMIC_OSC_ENABLE 1
18#define PMIC_OSC_DISENABLE 0
19#define PMIC_MAXNUM 5
20
21#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
22{ \
23 .min_uV = _min_uV, \
24 .min_sel = _min_sel, \
25 .max_sel = _max_sel, \
26 .uV_step = _step_uV, \
27}
28
29/*
30 * Regulators can either control voltage or current.
31 */
32enum regulator_type {
33 REGULATOR_VOLTAGE,
34 REGULATOR_CURRENT,
35};
36
37struct regulator_desc {
38 const char *name;
39 int id;
40 const struct regulator_ops *ops;
41
42/* buck ctrl reg */
43 unsigned int enable_reg;
44 unsigned int enable_mask;
45 unsigned int enable_val;
46 unsigned int disable_val;
47/* buck out */
48 unsigned int vsel_reg;
49 unsigned int vsel_mask;
50/* ldo ctrl */
51 unsigned int ldo_reg;
52 unsigned int ldo_mask_ctrl;
53 unsigned int ldo_val_ctrl;
54 unsigned int ldo_val_ctrl_disable;
55 unsigned int ldo_out_mask;
56 unsigned int n_linear_ranges;
57 const struct regulator_linear_range *linear_ranges;
58 const unsigned int *volt_table;
59 unsigned int n_voltages;
60};
61
62struct regulator_ops {
63 /* enable/disable regulator */
64 int (*ctrl) (struct regulator_desc *rdev,int status);
65 /* get/set regulator voltage */
66 int (*set_voltage) (struct regulator_desc *rdev,unsigned int sel);
67};
68
69struct regulator_linear_range {
70 unsigned int min_uV;
71 unsigned int min_sel;
72 unsigned int max_sel;
73 unsigned int uV_step;
74};
75
76struct pmic_i2c {
77 char *name;
78 int scl;
79 int scl_value;
80 int sda;
81 int sda_value;
82 int port;
83};
84
85struct pmic_regulator {
86 void (*pmic_i2c_config)(struct pmic_i2c *pmic_i2c);
87 /* set pmic enable/disable */
88 void (*osc_ctrl)(int status);
89 struct regulator_desc *rdev;
90 unsigned int num;
91};
92
93/**
94 *@ pmic_regulators_register() - Pmic i2c config and enable
95 *@ dev_id: regulator dev_id
96 */
97extern void pmic_i2c_init(int dev_id,struct pmic_i2c *pmic_i2c);
98
99/**
100 * pmic_regulators_register() - Pmic regulators register
101 * @PmicRegulator: regulator device
102 * @dev_id: regulator dev_id
103 */
104extern int pmic_regulators_register(struct pmic_regulator *PmicRegulator, int *dev_id);
105
106
107/**
108 * pmic_regulator_ctrl() - Pmic regulators enable/disable
109 * @dev_id: regulator dev_id
110 * @id: buck/ldo id
111 * @status: regulators status, enable/disable
112 */
113
114extern int pmic_regulator_ctrl(int dev_id, int id, int status);
115
116
117/**
118 * pmic_regulator_set_voltage() - Pmic regulators set voltage
119 * @dev_id: regulator dev_id
120 * @id: buck/ldo id
121 * @sel: buck/ldo voltage(uv)
122 */
123extern int pmic_regulator_set_voltage(int dev_id, int id,int sel);
124
125/**
126 * pmic_osc() - Pmic Crystal oscillator
127 * @dev_id: regulator dev_id
128 * @status: regulators status, enable/disable
129 */
130extern void pmic_osc(int dev_id, int status);
131
132#endif /* __PMIC_H__ */