blob: 0dcdbad5832f82180aebd79223b04f9fc465f9b0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jaehoon Chung4997f6e2017-02-02 17:04:09 +09002/*
3 * Copyright (C) 2016 Samsung Electronics
4 * Jaehoon Chung <jh80.chung@samsung.com>
Jaehoon Chung4997f6e2017-02-02 17:04:09 +09005 */
6
7#include <common.h>
8#include <dm.h>
9#include <i2c.h>
10#include <power/pmic.h>
11#include <power/max8997_pmic.h>
12#include <errno.h>
13
Jaehoon Chung4997f6e2017-02-02 17:04:09 +090014static int max8997_reg_count(struct udevice *dev)
15{
16 return PMIC_NUM_OF_REGS;
17}
18
19static int max8997_write(struct udevice *dev, uint reg, const uint8_t *buff,
20 int len)
21{
22 int ret;
23
24 ret = dm_i2c_write(dev, reg, buff, len);
25 if (ret)
Masahiro Yamada81e10422017-09-16 14:10:41 +090026 pr_err("write error to device: %p register: %#x!", dev, reg);
Jaehoon Chung4997f6e2017-02-02 17:04:09 +090027
28 return ret;
29}
30
31static int max8997_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
32{
33 int ret;
34
35 ret = dm_i2c_read(dev, reg, buff, len);
36 if (ret)
Masahiro Yamada81e10422017-09-16 14:10:41 +090037 pr_err("read error from device: %p register: %#x!", dev, reg);
Jaehoon Chung4997f6e2017-02-02 17:04:09 +090038
39 return ret;
40}
41
42static struct dm_pmic_ops max8997_ops = {
43 .reg_count = max8997_reg_count,
44 .read = max8997_read,
45 .write = max8997_write,
46};
47
48static const struct udevice_id max8997_ids[] = {
49 { .compatible = "maxim,max8997" },
50 { },
51};
52
53U_BOOT_DRIVER(pmic_max8997) = {
54 .name = "max8997_pmic",
55 .id = UCLASS_PMIC,
56 .of_match = max8997_ids,
57 .ops = &max8997_ops,
58};