1 /* 2 * Qualcomm pm8916 pmic driver 3 * 4 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> 5 * 6 * SPDX-License-Identifier: GPL-2.0+ 7 */ 8 #include <common.h> 9 #include <dm.h> 10 #include <power/pmic.h> 11 #include <spmi/spmi.h> 12 13 DECLARE_GLOBAL_DATA_PTR; 14 15 #define PID_SHIFT 8 16 #define PID_MASK (0xFF << PID_SHIFT) 17 #define REG_MASK 0xFF 18 19 struct pm8916_priv { 20 uint32_t usid; /* Slave ID on SPMI bus */ 21 }; 22 23 static int pm8916_reg_count(struct udevice *dev) 24 { 25 return 0xFFFF; 26 } 27 28 static int pm8916_write(struct udevice *dev, uint reg, const uint8_t *buff, 29 int len) 30 { 31 struct pm8916_priv *priv = dev_get_priv(dev); 32 33 if (len != 1) 34 return -EINVAL; 35 36 return spmi_reg_write(dev->parent, priv->usid, 37 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK, 38 *buff); 39 } 40 41 static int pm8916_read(struct udevice *dev, uint reg, uint8_t *buff, int len) 42 { 43 struct pm8916_priv *priv = dev_get_priv(dev); 44 int val; 45 46 if (len != 1) 47 return -EINVAL; 48 49 val = spmi_reg_read(dev->parent, priv->usid, 50 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK); 51 52 if (val < 0) 53 return val; 54 *buff = val; 55 return 0; 56 } 57 58 static struct dm_pmic_ops pm8916_ops = { 59 .reg_count = pm8916_reg_count, 60 .read = pm8916_read, 61 .write = pm8916_write, 62 }; 63 64 static const struct udevice_id pm8916_ids[] = { 65 { .compatible = "qcom,spmi-pmic" }, 66 { } 67 }; 68 69 static int pm8916_probe(struct udevice *dev) 70 { 71 struct pm8916_priv *priv = dev_get_priv(dev); 72 73 priv->usid = dev_get_addr(dev); 74 75 if (priv->usid == FDT_ADDR_T_NONE) 76 return -EINVAL; 77 78 return 0; 79 } 80 81 U_BOOT_DRIVER(pmic_pm8916) = { 82 .name = "pmic_pm8916", 83 .id = UCLASS_PMIC, 84 .of_match = pm8916_ids, 85 .bind = dm_scan_fdt_dev, 86 .probe = pm8916_probe, 87 .ops = &pm8916_ops, 88 .priv_auto_alloc_size = sizeof(struct pm8916_priv), 89 }; 90