summaryrefslogtreecommitdiff
path: root/drivers/button/button-qcom-pmic.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2024-04-23 08:33:37 -0600
committerTom Rini <trini@konsulko.com>2024-04-23 14:13:51 -0600
commite78210231924bd28e13c3ed6fd647585117c3fdb (patch)
tree5e466e3b700a4823ac4c18465d0e10adf4a643dc /drivers/button/button-qcom-pmic.c
parent18e791c4046a9a636052984df7d287bb5e00990f (diff)
parentad12acd7a8f5aeea5816d5c2fc37c205c403eee0 (diff)
Merge https://source.denx.de/u-boot/custodians/u-boot-snapdragon
Support is added for 5 new Qualcomm SoCs: * QCM2290 and SM6115 are low and mid range SoCs used on the RB1 and RB2 respectively. SM6115 is also used in some mid-range smartphones/tablets. Initial support includes buttons and USB (host and gadget). * SM8250 is a flagship SoC from 2020 used on the RB5, as well as many flagship smartphones. The board can boot to a U-Boot prompt, but is missing regulators necessary for USB support. * SM8550, and SM8650 are flagship mobile SoCs from 2023 and 2024 respectively. Found on many high end smartphones. In addition: * Support is added for the Schneider HMIBSC board. * mach-snapdragon switches to OF_UPSTREAM * IPQ40xx gets several regressions fixed and some overall cleanup. * The MSM serial driver gains the ability to generate the bit-clock automatically, no longer relying on a custom DT property. * The Qualcomm SMMU driver gets a generic compatible (so per-SoC compatibles don't need to be added). * Support for the GENI I2C controller is added. * The qcom SPMI driver has SPMI v5 support fixed, and v7 support added. * The qcom sdhci driver gets some fixes for SDCC v5 support. * SDM845 gains sdcard support * Support is added for the Synopsys eUSB2 PHY driver (used on SM8550 and SM8650) * SYS_INIT_SP_BSS_OFFSET is set to 1.5M to give us more space for FDTs. * RB2 gets a work-around to fix the USB dr_mode property before booting Linux.
Diffstat (limited to 'drivers/button/button-qcom-pmic.c')
-rw-r--r--drivers/button/button-qcom-pmic.c99
1 files changed, 71 insertions, 28 deletions
diff --git a/drivers/button/button-qcom-pmic.c b/drivers/button/button-qcom-pmic.c
index bad445efa86..ad7fed3ddaa 100644
--- a/drivers/button/button-qcom-pmic.c
+++ b/drivers/button/button-qcom-pmic.c
@@ -19,6 +19,13 @@
#define REG_TYPE 0x4
#define REG_SUBTYPE 0x5
+struct qcom_pmic_btn_data {
+ char *compatible;
+ unsigned int status_bit;
+ int code;
+ char *label;
+};
+
struct qcom_pmic_btn_priv {
u32 base;
u32 status_bit;
@@ -27,11 +34,10 @@ struct qcom_pmic_btn_priv {
};
#define PON_INT_RT_STS 0x10
-#define KPDPWR_ON_INT_BIT 0
-#define RESIN_ON_INT_BIT 1
-
-#define NODE_IS_PWRKEY(node) (!strncmp(ofnode_get_name(node), "pwrkey", strlen("pwrkey")))
-#define NODE_IS_RESIN(node) (!strncmp(ofnode_get_name(node), "resin", strlen("resin")))
+#define PON_KPDPWR_N_SET 0
+#define PON_RESIN_N_SET 1
+#define PON_GEN3_RESIN_N_SET 6
+#define PON_GEN3_KPDPWR_N_SET 7
static enum button_state_t qcom_pwrkey_get_state(struct udevice *dev)
{
@@ -52,10 +58,51 @@ static int qcom_pwrkey_get_code(struct udevice *dev)
return priv->code;
}
+static const struct qcom_pmic_btn_data qcom_pmic_btn_data_table[] = {
+ {
+ .compatible = "qcom,pm8941-pwrkey",
+ .status_bit = PON_KPDPWR_N_SET,
+ .code = KEY_ENTER,
+ .label = "pwrkey",
+ },
+ {
+ .compatible = "qcom,pm8941-resin",
+ .status_bit = PON_RESIN_N_SET,
+ .code = KEY_DOWN,
+ .label = "vol_down",
+ },
+ {
+ .compatible = "qcom,pmk8350-pwrkey",
+ .status_bit = PON_GEN3_KPDPWR_N_SET,
+ .code = KEY_ENTER,
+ .label = "pwrkey",
+ },
+ {
+ .compatible = "qcom,pmk8350-resin",
+ .status_bit = PON_GEN3_RESIN_N_SET,
+ .code = KEY_DOWN,
+ .label = "vol_down",
+ },
+};
+
+static const struct qcom_pmic_btn_data *button_qcom_pmic_match(ofnode node)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(qcom_pmic_btn_data_table); ++i) {
+ if (ofnode_device_is_compatible(node,
+ qcom_pmic_btn_data_table[i].compatible))
+ return &qcom_pmic_btn_data_table[i];
+ }
+
+ return NULL;
+}
+
static int qcom_pwrkey_probe(struct udevice *dev)
{
struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
struct qcom_pmic_btn_priv *priv = dev_get_priv(dev);
+ const struct qcom_pmic_btn_data *btn_data;
ofnode node = dev_ofnode(dev);
int ret;
u64 base;
@@ -64,6 +111,14 @@ static int qcom_pwrkey_probe(struct udevice *dev)
if (!uc_plat->label)
return 0;
+ /* Get the data for the node compatible */
+ btn_data = button_qcom_pmic_match(node);
+ if (!btn_data)
+ return -EINVAL;
+
+ priv->status_bit = btn_data->status_bit;
+ priv->code = btn_data->code;
+
/* the pwrkey and resin nodes are children of the "pon" node, get the
* PMIC device to use in pmic_reg_* calls.
*/
@@ -87,23 +142,10 @@ static int qcom_pwrkey_probe(struct udevice *dev)
ret = pmic_reg_read(priv->pmic, priv->base + REG_SUBTYPE);
if (ret < 0 || (ret & 0x7) == 0) {
- printf("%s: unexpected PMCI function subtype %d\n", dev->name, ret);
+ printf("%s: unexpected PMIC function subtype %d\n", dev->name, ret);
return -ENXIO;
}
- if (NODE_IS_PWRKEY(node)) {
- priv->status_bit = 0;
- priv->code = KEY_ENTER;
- } else if (NODE_IS_RESIN(node)) {
- priv->status_bit = 1;
- priv->code = KEY_DOWN;
- } else {
- /* Should not get here! */
- printf("Invalid pon node '%s' should be 'pwrkey' or 'resin'\n",
- ofnode_get_name(node));
- return -EINVAL;
- }
-
return 0;
}
@@ -114,12 +156,20 @@ static int button_qcom_pmic_bind(struct udevice *parent)
int ret;
dev_for_each_subnode(node, parent) {
+ const struct qcom_pmic_btn_data *btn_data;
struct button_uc_plat *uc_plat;
const char *label;
if (!ofnode_is_enabled(node))
continue;
+ /* Get the data for the node compatible */
+ btn_data = button_qcom_pmic_match(node);
+ if (!btn_data) {
+ debug("Unknown button node '%s'\n", ofnode_get_name(node));
+ continue;
+ }
+
ret = device_bind_driver_to_node(parent, "qcom_pwrkey",
ofnode_get_name(node),
node, &dev);
@@ -128,15 +178,7 @@ static int button_qcom_pmic_bind(struct udevice *parent)
return ret;
}
uc_plat = dev_get_uclass_plat(dev);
- if (NODE_IS_PWRKEY(node)) {
- uc_plat->label = "pwrkey";
- } else if (NODE_IS_RESIN(node)) {
- uc_plat->label = "vol_down";
- } else {
- debug("Unknown button node '%s' should be 'pwrkey' or 'resin'\n",
- ofnode_get_name(node));
- device_unbind(dev);
- }
+ uc_plat->label = btn_data->label;
}
return 0;
@@ -151,6 +193,7 @@ static const struct udevice_id qcom_pwrkey_ids[] = {
{ .compatible = "qcom,pm8916-pon" },
{ .compatible = "qcom,pm8941-pon" },
{ .compatible = "qcom,pm8998-pon" },
+ { .compatible = "qcom,pmk8350-pon" },
{ }
};