yang.li | 2477037 | 2022-01-11 15:21:49 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 6 | |
| 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.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 15 | #define PMIC_ENBALE 1 |
| 16 | #define PMIC_DISABLE 0 |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 17 | #define PMIC_OSC_ENABLE 1 |
| 18 | #define PMIC_OSC_DISENABLE 0 |
| 19 | #define PMIC_MAXNUM 5 |
| 20 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 21 | #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 Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * Regulators can either control voltage or current. |
| 28 | */ |
| 29 | enum regulator_type { |
| 30 | REGULATOR_VOLTAGE, |
| 31 | REGULATOR_CURRENT, |
| 32 | }; |
| 33 | |
| 34 | struct regulator_desc { |
| 35 | const char *name; |
| 36 | int id; |
| 37 | const struct regulator_ops *ops; |
| 38 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 39 | /* buck ctrl reg */ |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 40 | unsigned int enable_reg; |
| 41 | unsigned int enable_mask; |
| 42 | unsigned int enable_val; |
| 43 | unsigned int disable_val; |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 44 | /* buck out */ |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 45 | unsigned int vsel_reg; |
| 46 | unsigned int vsel_mask; |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 47 | /* ldo ctrl */ |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 48 | 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 | |
| 59 | struct regulator_ops { |
| 60 | /* enable/disable regulator */ |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 61 | int (*ctrl)(struct regulator_desc *rdev, int status); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 62 | /* get/set regulator voltage */ |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 63 | int (*set_voltage)(struct regulator_desc *rdev, unsigned int sel); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct 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 | |
| 73 | struct pmic_i2c { |
| 74 | char *name; |
| 75 | int scl; |
| 76 | int scl_value; |
| 77 | int sda; |
| 78 | int sda_value; |
| 79 | int port; |
| 80 | }; |
| 81 | |
| 82 | struct 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.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 94 | extern void pmic_i2c_init(int dev_id, struct pmic_i2c *pmic_i2c); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * pmic_regulators_register() - Pmic regulators register |
| 98 | * @PmicRegulator: regulator device |
| 99 | * @dev_id: regulator dev_id |
| 100 | */ |
| 101 | extern int pmic_regulators_register(struct pmic_regulator *PmicRegulator, int *dev_id); |
| 102 | |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 103 | /** |
| 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 | |
| 110 | extern int pmic_regulator_ctrl(int dev_id, int id, int status); |
| 111 | |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 112 | /** |
| 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.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 118 | extern int pmic_regulator_set_voltage(int dev_id, int id, int sel); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * pmic_osc() - Pmic Crystal oscillator |
| 122 | * @dev_id: regulator dev_id |
| 123 | * @status: regulators status, enable/disable |
| 124 | */ |
| 125 | extern void pmic_osc(int dev_id, int status); |
| 126 | |
| 127 | #endif /* __PMIC_H__ */ |