Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 1 | /* |
yang.li | 2477037 | 2022-01-11 15:21:49 +0800 | [diff] [blame] | 2 | * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 3 | * |
yang.li | 2477037 | 2022-01-11 15:21:49 +0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: MIT |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include "pmic.h" |
| 8 | #include "myprintf.h" |
| 9 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 10 | struct pmic_regulator *pmic_regulators[PMIC_MAXNUM] = { NULL1, NULL1, NULL1, NULL1, NULL1 }; |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 11 | |
| 12 | int pmic_regulators_register(struct pmic_regulator *PmicRegulator, int *dev_id) |
| 13 | { |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 14 | for (int i = 0; i < PMIC_MAXNUM; i++) { |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 15 | if (pmic_regulators[i] == NULL1) { |
| 16 | pmic_regulators[i] = PmicRegulator; |
| 17 | *dev_id = i; |
| 18 | return 0; |
| 19 | } |
| 20 | } |
| 21 | printf("pmic_regulators has Greatered than PMIC_MAXNUM\n"); |
| 22 | return -1; |
| 23 | } |
| 24 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 25 | void pmic_i2c_init(int dev_id, struct pmic_i2c *pmic_i2c) |
| 26 | { |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 27 | ((pmic_regulators[dev_id])->pmic_i2c_config)(pmic_i2c); |
| 28 | } |
| 29 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 30 | int pmic_regulator_ctrl(int dev_id, int id, int status) |
| 31 | { |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 32 | struct regulator_desc pmic_desc = ((pmic_regulators[dev_id])->rdev)[id]; |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 33 | |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 34 | pmic_desc.ops->ctrl(&pmic_desc, status); |
| 35 | return 0; |
| 36 | } |
| 37 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 38 | int pmic_regulator_set_voltage(int dev_id, int id, int sel) |
| 39 | { |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 40 | struct regulator_desc pmic_desc = ((pmic_regulators[dev_id])->rdev)[id]; |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 41 | |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 42 | pmic_desc.ops->set_voltage(&pmic_desc, sel); |
| 43 | return 0; |
| 44 | } |
| 45 | |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame^] | 46 | void pmic_osc(int dev_id, int status) |
| 47 | { |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 48 | ((pmic_regulators[dev_id])->osc_ctrl)(status); |
| 49 | } |