]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/power/sy8106a.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / drivers / power / sy8106a.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
0d8382ae
JW
2/*
3 * (C) Copyright 2016
4 * Jelle van der Waa <jelle@vdwaa.nl>
0d8382ae 5 */
d678a59d 6#include <common.h>
0d8382ae
JW
7#include <i2c.h>
8#include <sy8106a.h>
9
10#define SY8106A_I2C_ADDR 0x65
11#define SY8106A_VOUT1_SEL 1
12#define SY8106A_VOUT1_SEL_ENABLE (1 << 7)
13
ae4e4dde 14#ifdef CONFIG_SPL_BUILD
0d8382ae
JW
15static u8 sy8106a_mvolt_to_cfg(int mvolt, int min, int max, int div)
16{
17 if (mvolt < min)
18 mvolt = min;
19 else if (mvolt > max)
20 mvolt = max;
21
22 return (mvolt - min) / div;
23}
24
25int sy8106a_set_vout1(unsigned int mvolt)
26{
27 u8 data = sy8106a_mvolt_to_cfg(mvolt, 680, 1950, 10) | SY8106A_VOUT1_SEL_ENABLE;
28 return i2c_write(SY8106A_I2C_ADDR, SY8106A_VOUT1_SEL, 1, &data, 1);
29}
ae4e4dde 30#endif