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