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