Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jelle van der Waa | 3f3a309 | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 |
| 4 | * Jelle van der Waa <jelle@vdwaa.nl> |
Jelle van der Waa | 3f3a309 | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 5 | */ |
Jelle van der Waa | 3f3a309 | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 6 | #include <i2c.h> |
| 7 | #include <sy8106a.h> |
| 8 | |
| 9 | #define SY8106A_I2C_ADDR 0x65 |
| 10 | #define SY8106A_VOUT1_SEL 1 |
| 11 | #define SY8106A_VOUT1_SEL_ENABLE (1 << 7) |
| 12 | |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 13 | #ifdef CONFIG_XPL_BUILD |
Jelle van der Waa | 3f3a309 | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 14 | static u8 sy8106a_mvolt_to_cfg(int mvolt, int min, int max, int div) |
| 15 | { |
| 16 | if (mvolt < min) |
| 17 | mvolt = min; |
| 18 | else if (mvolt > max) |
| 19 | mvolt = max; |
| 20 | |
| 21 | return (mvolt - min) / div; |
| 22 | } |
| 23 | |
| 24 | int sy8106a_set_vout1(unsigned int mvolt) |
| 25 | { |
| 26 | u8 data = sy8106a_mvolt_to_cfg(mvolt, 680, 1950, 10) | SY8106A_VOUT1_SEL_ENABLE; |
| 27 | return i2c_write(SY8106A_I2C_ADDR, SY8106A_VOUT1_SEL, 1, &data, 1); |
| 28 | } |
Jernej Skrabec | cb7d2b8 | 2017-04-27 00:03:34 +0200 | [diff] [blame] | 29 | #endif |