1 /* 2 * Copyright (C) 2015 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <fdtdec.h> 9 #include <errno.h> 10 #include <dm.h> 11 #include <i2c.h> 12 #include <power/pmic.h> 13 #include <power/regulator.h> 14 #include <power/s5m8767.h> 15 16 DECLARE_GLOBAL_DATA_PTR; 17 18 static const struct pmic_child_info pmic_children_info[] = { 19 { .prefix = "LDO", .driver = S5M8767_LDO_DRIVER }, 20 { .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER }, 21 { }, 22 }; 23 24 static int s5m8767_reg_count(struct udevice *dev) 25 { 26 return S5M8767_NUM_OF_REGS; 27 } 28 29 static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff, 30 int len) 31 { 32 if (dm_i2c_write(dev, reg, buff, len)) { 33 error("write error to device: %p register: %#x!", dev, reg); 34 return -EIO; 35 } 36 37 return 0; 38 } 39 40 static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len) 41 { 42 if (dm_i2c_read(dev, reg, buff, len)) { 43 error("read error from device: %p register: %#x!", dev, reg); 44 return -EIO; 45 } 46 47 return 0; 48 } 49 50 int s5m8767_enable_32khz_cp(struct udevice *dev) 51 { 52 return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1); 53 } 54 55 static int s5m8767_bind(struct udevice *dev) 56 { 57 int node; 58 const void *blob = gd->fdt_blob; 59 int children; 60 61 node = fdt_subnode_offset(blob, dev->of_offset, "regulators"); 62 if (node <= 0) { 63 debug("%s: %s regulators subnode not found!", __func__, 64 dev->name); 65 return -ENXIO; 66 } 67 68 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); 69 70 children = pmic_bind_children(dev, node, pmic_children_info); 71 if (!children) 72 debug("%s: %s - no child found\n", __func__, dev->name); 73 74 /* Always return success for this device */ 75 return 0; 76 } 77 78 static struct dm_pmic_ops s5m8767_ops = { 79 .reg_count = s5m8767_reg_count, 80 .read = s5m8767_read, 81 .write = s5m8767_write, 82 }; 83 84 static const struct udevice_id s5m8767_ids[] = { 85 { .compatible = "samsung,s5m8767-pmic" }, 86 { } 87 }; 88 89 U_BOOT_DRIVER(pmic_s5m8767) = { 90 .name = "s5m8767_pmic", 91 .id = UCLASS_PMIC, 92 .of_match = s5m8767_ids, 93 .bind = s5m8767_bind, 94 .ops = &s5m8767_ops, 95 }; 96