Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* Copyright (C) 2018 ROHM Semiconductors */ |
| 3 | |
| 4 | #ifndef __PMIC_H__ |
| 5 | |
| 6 | #define __PMIC_H__ |
| 7 | |
| 8 | //#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 9 | |
| 10 | #define NULL1 ((void *)0) |
| 11 | |
| 12 | #define PMIC_ENBALE 1 |
| 13 | #define PMIC_DISABLE 0 |
| 14 | #define PMIC_OSC_ENABLE 1 |
| 15 | #define PMIC_OSC_DISENABLE 0 |
| 16 | #define PMIC_MAXNUM 5 |
| 17 | |
| 18 | #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \ |
| 19 | { \ |
| 20 | .min_uV = _min_uV, \ |
| 21 | .min_sel = _min_sel, \ |
| 22 | .max_sel = _max_sel, \ |
| 23 | .uV_step = _step_uV, \ |
| 24 | } |
| 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 | |
| 39 | /* buck ctrl reg */ |
| 40 | unsigned int enable_reg; |
| 41 | unsigned int enable_mask; |
| 42 | unsigned int enable_val; |
| 43 | unsigned int disable_val; |
| 44 | /* buck out */ |
| 45 | unsigned int vsel_reg; |
| 46 | unsigned int vsel_mask; |
| 47 | /* ldo ctrl */ |
| 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 */ |
| 61 | int (*ctrl) (struct regulator_desc *rdev,int status); |
| 62 | /* get/set regulator voltage */ |
| 63 | int (*set_voltage) (struct regulator_desc *rdev,unsigned int sel); |
| 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 | */ |
| 94 | extern void pmic_i2c_init(int dev_id,struct pmic_i2c *pmic_i2c); |
| 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 | |
| 103 | |
| 104 | /** |
| 105 | * pmic_regulator_ctrl() - Pmic regulators enable/disable |
| 106 | * @dev_id: regulator dev_id |
| 107 | * @id: buck/ldo id |
| 108 | * @status: regulators status, enable/disable |
| 109 | */ |
| 110 | |
| 111 | extern int pmic_regulator_ctrl(int dev_id, int id, int status); |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * pmic_regulator_set_voltage() - Pmic regulators set voltage |
| 116 | * @dev_id: regulator dev_id |
| 117 | * @id: buck/ldo id |
| 118 | * @sel: buck/ldo voltage(uv) |
| 119 | */ |
| 120 | extern int pmic_regulator_set_voltage(int dev_id, int id,int sel); |
| 121 | |
| 122 | /** |
| 123 | * pmic_osc() - Pmic Crystal oscillator |
| 124 | * @dev_id: regulator dev_id |
| 125 | * @status: regulators status, enable/disable |
| 126 | */ |
| 127 | extern void pmic_osc(int dev_id, int status); |
| 128 | |
| 129 | #endif /* __PMIC_H__ */ |