blob: c45a257fc8a19b8bd885c828fcf1434ee8ddf7d4 [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
xiaohu.huang2beac512022-05-07 15:10:04 +080015#define PMIC_ENBALE 1
16#define PMIC_DISABLE 0
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080017#define PMIC_OSC_ENABLE 1
18#define PMIC_OSC_DISENABLE 0
19#define PMIC_MAXNUM 5
20
xiaohu.huang2beac512022-05-07 15:10:04 +080021#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
22 { \
23 .min_uV = _min_uV, .min_sel = _min_sel, .max_sel = _max_sel, .uV_step = _step_uV, \
24 }
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080025
26/*
27 * Regulators can either control voltage or current.
28 */
29enum regulator_type {
30 REGULATOR_VOLTAGE,
31 REGULATOR_CURRENT,
32};
33
34struct regulator_desc {
35 const char *name;
36 int id;
37 const struct regulator_ops *ops;
38
xiaohu.huang2beac512022-05-07 15:10:04 +080039 /* buck ctrl reg */
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080040 unsigned int enable_reg;
41 unsigned int enable_mask;
42 unsigned int enable_val;
43 unsigned int disable_val;
xiaohu.huang2beac512022-05-07 15:10:04 +080044 /* buck out */
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080045 unsigned int vsel_reg;
46 unsigned int vsel_mask;
xiaohu.huang2beac512022-05-07 15:10:04 +080047 /* ldo ctrl */
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080048 unsigned int ldo_reg;
49 unsigned int ldo_mask_ctrl;
50 unsigned int ldo_val_ctrl;
51 unsigned int ldo_val_ctrl_disable;
52 unsigned int ldo_out_mask;
53 unsigned int n_linear_ranges;
54 const struct regulator_linear_range *linear_ranges;
55 const unsigned int *volt_table;
56 unsigned int n_voltages;
57};
58
59struct regulator_ops {
60 /* enable/disable regulator */
xiaohu.huang2beac512022-05-07 15:10:04 +080061 int (*ctrl)(struct regulator_desc *rdev, int status);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080062 /* get/set regulator voltage */
xiaohu.huang2beac512022-05-07 15:10:04 +080063 int (*set_voltage)(struct regulator_desc *rdev, unsigned int sel);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080064};
65
66struct regulator_linear_range {
67 unsigned int min_uV;
68 unsigned int min_sel;
69 unsigned int max_sel;
70 unsigned int uV_step;
71};
72
73struct pmic_i2c {
74 char *name;
75 int scl;
76 int scl_value;
77 int sda;
78 int sda_value;
79 int port;
80};
81
82struct pmic_regulator {
83 void (*pmic_i2c_config)(struct pmic_i2c *pmic_i2c);
84 /* set pmic enable/disable */
85 void (*osc_ctrl)(int status);
86 struct regulator_desc *rdev;
87 unsigned int num;
88};
89
90/**
91 *@ pmic_regulators_register() - Pmic i2c config and enable
92 *@ dev_id: regulator dev_id
93 */
xiaohu.huang2beac512022-05-07 15:10:04 +080094extern void pmic_i2c_init(int dev_id, struct pmic_i2c *pmic_i2c);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080095
96/**
97 * pmic_regulators_register() - Pmic regulators register
98 * @PmicRegulator: regulator device
99 * @dev_id: regulator dev_id
100 */
101extern int pmic_regulators_register(struct pmic_regulator *PmicRegulator, int *dev_id);
102
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +0800103/**
104 * pmic_regulator_ctrl() - Pmic regulators enable/disable
105 * @dev_id: regulator dev_id
106 * @id: buck/ldo id
107 * @status: regulators status, enable/disable
108 */
109
110extern int pmic_regulator_ctrl(int dev_id, int id, int status);
111
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +0800112/**
113 * pmic_regulator_set_voltage() - Pmic regulators set voltage
114 * @dev_id: regulator dev_id
115 * @id: buck/ldo id
116 * @sel: buck/ldo voltage(uv)
117 */
xiaohu.huang2beac512022-05-07 15:10:04 +0800118extern int pmic_regulator_set_voltage(int dev_id, int id, int sel);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +0800119
120/**
121 * pmic_osc() - Pmic Crystal oscillator
122 * @dev_id: regulator dev_id
123 * @status: regulators status, enable/disable
124 */
125extern void pmic_osc(int dev_id, int status);
126
127#endif /* __PMIC_H__ */