summaryrefslogtreecommitdiffstats
path: root/drivers/mfd/rk808.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-15 20:18:40 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-15 20:18:40 -0700
commit8de262531f5fbb7458463224a7587429800c24bf (patch)
treec95d1d2bdeaff95cea17982f1c0e1e552591e40f /drivers/mfd/rk808.c
parentbe8454afc50f43016ca8b6130d9673bdd0bd56ec (diff)
parent7efd105c27fd2323789b41b64763a0e33ed79c08 (diff)
downloadlinux-8de262531f5fbb7458463224a7587429800c24bf.tar.gz
linux-8de262531f5fbb7458463224a7587429800c24bf.tar.bz2
linux-8de262531f5fbb7458463224a7587429800c24bf.zip
Merge tag 'mfd-next-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
Pull MFD updates from Lee Jones: "Core Frameworks: - Set 'struct device' fwnode when registering a new device New Drivers: - Add support for ROHM BD70528 PMIC New Device Support: - Add support for LP87561 4-Phase Regulator to TI LP87565 PMIC - Add support for RK809 and RK817 to Rockchip RK808 - Add support for Lid Angle to ChromeOS core - Add support for CS47L15 CODEC to Madera core - Add support for CS47L92 CODEC to Madera core - Add support for ChromeOS (legacy) Accelerometers in ChromeOS core - Add support for Add Intel Elkhart Lake PCH to Intel LPSS New Functionality: - Provide regulator supply information when registering; madera-core - Additional Device Tree support; lp87565, madera, cros-ec, rohm,bd71837-pmic - Allow over-riding power button press via Device Tree; rohm-bd718x7 - Differentiate between running processors; cros_ec_dev Fix-ups: - Big header file update; cros_ec_commands.h - Split header per-subsystem; rohm-bd718x7 - Remove superfluous code; menelaus, cs5535-mfd, cs47lXX-tables - Trivial; sorting, coding style; intel-lpss-pci - Only remove Power Off functionality if set locally; rk808 - Make use for Power Off Prepare(); rk808 - Fix spelling mistake in header guards; stmfx - Properly free IDA resources - SPDX fixups; cs47lXX-tables, madera - Error path fixups; hi655x-pmic Bug Fixes: - Add missing break in case() statement - Repair undefined behaviour when not initialising variables; arizona-core, madera-core - Fix reference to Device Tree documentation; madera" * tag 'mfd-next-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (45 commits) mfd: hi655x-pmic: Fix missing return value check for devm_regmap_init_mmio_clk mfd: madera: Fixup SPDX headers mfd: madera: Remove some unused registers and fix some defaults mfd: intel-lpss: Release IDA resources mfd: intel-lpss: Add Intel Elkhart Lake PCH PCI IDs mfd: cs5535-mfd: Remove ifdef OLPC noise mfd: stmfx: Fix macro definition spelling dt-bindings: mfd: Add link to ROHM BD71847 Datasheet MAINAINERS: Swap words in INTEL PMIC MULTIFUNCTION DEVICE DRIVERS mfd: cros_ec_dev: Register cros_ec_accel_legacy driver as a subdevice mfd: rk808: Prepare rk805 for poweroff mfd: rk808: Check pm_power_off pointer mfd: cros_ec: differentiate SCP from EC by feature bit dt-bindings: Add binding for cros-ec-rpmsg mfd: madera: Add Madera core support for CS47L92 mfd: madera: Add Madera core support for CS47L15 mfd: madera: Update DT bindings to add additional CODECs mfd: madera: Add supply mapping for MICVDD mfd: madera: Fix potential uninitialised use of variable mfd: madera: Fix bad reference to pinctrl.txt file ...
Diffstat (limited to 'drivers/mfd/rk808.c')
-rw-r--r--drivers/mfd/rk808.c257
1 files changed, 234 insertions, 23 deletions
diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c
index 908c1f45e64a..601cefb5c9d8 100644
--- a/drivers/mfd/rk808.c
+++ b/drivers/mfd/rk808.c
@@ -19,6 +19,7 @@
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/regmap.h>
+#include <linux/syscore_ops.h>
struct rk808_reg_data {
int addr;
@@ -54,6 +55,27 @@ static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
return false;
}
+static bool rk817_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+ /*
+ * Notes:
+ * - Technically the ROUND_30s bit makes RTC_CTRL_REG volatile, but
+ * we don't use that feature. It's better to cache.
+ */
+
+ switch (reg) {
+ case RK817_SECONDS_REG ... RK817_WEEKS_REG:
+ case RK817_RTC_STATUS_REG:
+ case RK817_INT_STS_REG0:
+ case RK817_INT_STS_REG1:
+ case RK817_INT_STS_REG2:
+ case RK817_SYS_STS:
+ return true;
+ }
+
+ return true;
+}
+
static const struct regmap_config rk818_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -78,6 +100,14 @@ static const struct regmap_config rk808_regmap_config = {
.volatile_reg = rk808_is_volatile_reg,
};
+static const struct regmap_config rk817_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = RK817_GPIO_INT_CFG,
+ .cache_type = REGCACHE_NONE,
+ .volatile_reg = rk817_is_volatile_reg,
+};
+
static struct resource rtc_resources[] = {
{
.start = RK808_IRQ_RTC_ALARM,
@@ -86,6 +116,10 @@ static struct resource rtc_resources[] = {
}
};
+static struct resource rk817_rtc_resources[] = {
+ DEFINE_RES_IRQ(RK817_IRQ_RTC_ALARM),
+};
+
static struct resource rk805_key_resources[] = {
{
.start = RK805_IRQ_PWRON_FALL,
@@ -99,6 +133,11 @@ static struct resource rk805_key_resources[] = {
}
};
+static struct resource rk817_pwrkey_resources[] = {
+ DEFINE_RES_IRQ(RK817_IRQ_PWRON_RISE),
+ DEFINE_RES_IRQ(RK817_IRQ_PWRON_FALL),
+};
+
static const struct mfd_cell rk805s[] = {
{ .name = "rk808-clkout", },
{ .name = "rk808-regulator", },
@@ -124,6 +163,21 @@ static const struct mfd_cell rk808s[] = {
},
};
+static const struct mfd_cell rk817s[] = {
+ { .name = "rk808-clkout",},
+ { .name = "rk808-regulator",},
+ {
+ .name = "rk8xx-pwrkey",
+ .num_resources = ARRAY_SIZE(rk817_pwrkey_resources),
+ .resources = &rk817_pwrkey_resources[0],
+ },
+ {
+ .name = "rk808-rtc",
+ .num_resources = ARRAY_SIZE(rk817_rtc_resources),
+ .resources = &rk817_rtc_resources[0],
+ },
+};
+
static const struct mfd_cell rk818s[] = {
{ .name = "rk808-clkout", },
{ .name = "rk808-regulator", },
@@ -159,6 +213,13 @@ static const struct rk808_reg_data rk808_pre_init_reg[] = {
VB_LO_SEL_3500MV },
};
+static const struct rk808_reg_data rk817_pre_init_reg[] = {
+ {RK817_RTC_CTRL_REG, RTC_STOP, RTC_STOP},
+ {RK817_GPIO_INT_CFG, RK817_INT_POL_MSK, RK817_INT_POL_H},
+ {RK817_SYS_CFG(1), RK817_HOTDIE_TEMP_MSK | RK817_TSD_TEMP_MSK,
+ RK817_HOTDIE_105 | RK817_TSD_140},
+};
+
static const struct rk808_reg_data rk818_pre_init_reg[] = {
/* improve efficiency */
{ RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_250MA },
@@ -324,6 +385,33 @@ static const struct regmap_irq rk818_irqs[] = {
},
};
+static const struct regmap_irq rk817_irqs[RK817_IRQ_END] = {
+ REGMAP_IRQ_REG_LINE(0, 8),
+ REGMAP_IRQ_REG_LINE(1, 8),
+ REGMAP_IRQ_REG_LINE(2, 8),
+ REGMAP_IRQ_REG_LINE(3, 8),
+ REGMAP_IRQ_REG_LINE(4, 8),
+ REGMAP_IRQ_REG_LINE(5, 8),
+ REGMAP_IRQ_REG_LINE(6, 8),
+ REGMAP_IRQ_REG_LINE(7, 8),
+ REGMAP_IRQ_REG_LINE(8, 8),
+ REGMAP_IRQ_REG_LINE(9, 8),
+ REGMAP_IRQ_REG_LINE(10, 8),
+ REGMAP_IRQ_REG_LINE(11, 8),
+ REGMAP_IRQ_REG_LINE(12, 8),
+ REGMAP_IRQ_REG_LINE(13, 8),
+ REGMAP_IRQ_REG_LINE(14, 8),
+ REGMAP_IRQ_REG_LINE(15, 8),
+ REGMAP_IRQ_REG_LINE(16, 8),
+ REGMAP_IRQ_REG_LINE(17, 8),
+ REGMAP_IRQ_REG_LINE(18, 8),
+ REGMAP_IRQ_REG_LINE(19, 8),
+ REGMAP_IRQ_REG_LINE(20, 8),
+ REGMAP_IRQ_REG_LINE(21, 8),
+ REGMAP_IRQ_REG_LINE(22, 8),
+ REGMAP_IRQ_REG_LINE(23, 8)
+};
+
static struct regmap_irq_chip rk805_irq_chip = {
.name = "rk805",
.irqs = rk805_irqs,
@@ -347,6 +435,18 @@ static const struct regmap_irq_chip rk808_irq_chip = {
.init_ack_masked = true,
};
+static struct regmap_irq_chip rk817_irq_chip = {
+ .name = "rk817",
+ .irqs = rk817_irqs,
+ .num_irqs = ARRAY_SIZE(rk817_irqs),
+ .num_regs = 3,
+ .irq_reg_stride = 2,
+ .status_base = RK817_INT_STS_REG0,
+ .mask_base = RK817_INT_STS_MSK_REG0,
+ .ack_base = RK817_INT_STS_REG0,
+ .init_ack_masked = true,
+};
+
static const struct regmap_irq_chip rk818_irq_chip = {
.name = "rk818",
.irqs = rk818_irqs,
@@ -366,17 +466,29 @@ static void rk805_device_shutdown(void)
int ret;
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
- if (!rk808) {
- dev_warn(&rk808_i2c_client->dev,
- "have no rk805, so do nothing here\n");
+ if (!rk808)
return;
- }
ret = regmap_update_bits(rk808->regmap,
RK805_DEV_CTRL_REG,
DEV_OFF, DEV_OFF);
if (ret)
- dev_err(&rk808_i2c_client->dev, "power off error!\n");
+ dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
+}
+
+static void rk805_device_shutdown_prepare(void)
+{
+ int ret;
+ struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+ if (!rk808)
+ return;
+
+ ret = regmap_update_bits(rk808->regmap,
+ RK805_GPIO_IO_POL_REG,
+ SLP_SD_MSK, SHUTDOWN_FUN);
+ if (ret)
+ dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
}
static void rk808_device_shutdown(void)
@@ -384,17 +496,14 @@ static void rk808_device_shutdown(void)
int ret;
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
- if (!rk808) {
- dev_warn(&rk808_i2c_client->dev,
- "have no rk808, so do nothing here\n");
+ if (!rk808)
return;
- }
ret = regmap_update_bits(rk808->regmap,
RK808_DEVCTRL_REG,
DEV_OFF_RST, DEV_OFF_RST);
if (ret)
- dev_err(&rk808_i2c_client->dev, "power off error!\n");
+ dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
}
static void rk818_device_shutdown(void)
@@ -402,22 +511,43 @@ static void rk818_device_shutdown(void)
int ret;
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
- if (!rk808) {
- dev_warn(&rk808_i2c_client->dev,
- "have no rk818, so do nothing here\n");
+ if (!rk808)
return;
- }
ret = regmap_update_bits(rk808->regmap,
RK818_DEVCTRL_REG,
DEV_OFF, DEV_OFF);
if (ret)
- dev_err(&rk808_i2c_client->dev, "power off error!\n");
+ dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
+}
+
+static void rk8xx_syscore_shutdown(void)
+{
+ struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+ int ret;
+
+ if (system_state == SYSTEM_POWER_OFF &&
+ (rk808->variant == RK809_ID || rk808->variant == RK817_ID)) {
+ ret = regmap_update_bits(rk808->regmap,
+ RK817_SYS_CFG(3),
+ RK817_SLPPIN_FUNC_MSK,
+ SLPPIN_DN_FUN);
+ if (ret) {
+ dev_warn(&rk808_i2c_client->dev,
+ "Cannot switch to power down function\n");
+ }
+ }
}
+static struct syscore_ops rk808_syscore_ops = {
+ .shutdown = rk8xx_syscore_shutdown,
+};
+
static const struct of_device_id rk808_of_match[] = {
{ .compatible = "rockchip,rk805" },
{ .compatible = "rockchip,rk808" },
+ { .compatible = "rockchip,rk809" },
+ { .compatible = "rockchip,rk817" },
{ .compatible = "rockchip,rk818" },
{ },
};
@@ -430,10 +560,10 @@ static int rk808_probe(struct i2c_client *client,
struct rk808 *rk808;
const struct rk808_reg_data *pre_init_reg;
const struct mfd_cell *cells;
- void (*pm_pwroff_fn)(void);
int nr_pre_init_regs;
int nr_cells;
int pm_off = 0, msb, lsb;
+ unsigned char pmic_id_msb, pmic_id_lsb;
int ret;
int i;
@@ -441,15 +571,24 @@ static int rk808_probe(struct i2c_client *client,
if (!rk808)
return -ENOMEM;
+ if (of_device_is_compatible(np, "rockchip,rk817") ||
+ of_device_is_compatible(np, "rockchip,rk809")) {
+ pmic_id_msb = RK817_ID_MSB;
+ pmic_id_lsb = RK817_ID_LSB;
+ } else {
+ pmic_id_msb = RK808_ID_MSB;
+ pmic_id_lsb = RK808_ID_LSB;
+ }
+
/* Read chip variant */
- msb = i2c_smbus_read_byte_data(client, RK808_ID_MSB);
+ msb = i2c_smbus_read_byte_data(client, pmic_id_msb);
if (msb < 0) {
dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
RK808_ID_MSB);
return msb;
}
- lsb = i2c_smbus_read_byte_data(client, RK808_ID_LSB);
+ lsb = i2c_smbus_read_byte_data(client, pmic_id_lsb);
if (lsb < 0) {
dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
RK808_ID_LSB);
@@ -467,7 +606,8 @@ static int rk808_probe(struct i2c_client *client,
nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
cells = rk805s;
nr_cells = ARRAY_SIZE(rk805s);
- pm_pwroff_fn = rk805_device_shutdown;
+ rk808->pm_pwroff_fn = rk805_device_shutdown;
+ rk808->pm_pwroff_prep_fn = rk805_device_shutdown_prepare;
break;
case RK808_ID:
rk808->regmap_cfg = &rk808_regmap_config;
@@ -476,7 +616,7 @@ static int rk808_probe(struct i2c_client *client,
nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
cells = rk808s;
nr_cells = ARRAY_SIZE(rk808s);
- pm_pwroff_fn = rk808_device_shutdown;
+ rk808->pm_pwroff_fn = rk808_device_shutdown;
break;
case RK818_ID:
rk808->regmap_cfg = &rk818_regmap_config;
@@ -485,7 +625,17 @@ static int rk808_probe(struct i2c_client *client,
nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
cells = rk818s;
nr_cells = ARRAY_SIZE(rk818s);
- pm_pwroff_fn = rk818_device_shutdown;
+ rk808->pm_pwroff_fn = rk818_device_shutdown;
+ break;
+ case RK809_ID:
+ case RK817_ID:
+ rk808->regmap_cfg = &rk817_regmap_config;
+ rk808->regmap_irq_chip = &rk817_irq_chip;
+ pre_init_reg = rk817_pre_init_reg;
+ nr_pre_init_regs = ARRAY_SIZE(rk817_pre_init_reg);
+ cells = rk817s;
+ nr_cells = ARRAY_SIZE(rk817s);
+ register_syscore_ops(&rk808_syscore_ops);
break;
default:
dev_err(&client->dev, "Unsupported RK8XX ID %lu\n",
@@ -540,7 +690,13 @@ static int rk808_probe(struct i2c_client *client,
"rockchip,system-power-controller");
if (pm_off && !pm_power_off) {
rk808_i2c_client = client;
- pm_power_off = pm_pwroff_fn;
+ pm_power_off = rk808->pm_pwroff_fn;
+ }
+
+ if (pm_off && !pm_power_off_prepare) {
+ if (!rk808_i2c_client)
+ rk808_i2c_client = client;
+ pm_power_off_prepare = rk808->pm_pwroff_prep_fn;
}
return 0;
@@ -555,15 +711,70 @@ static int rk808_remove(struct i2c_client *client)
struct rk808 *rk808 = i2c_get_clientdata(client);
regmap_del_irq_chip(client->irq, rk808->irq_data);
- pm_power_off = NULL;
+
+ /**
+ * pm_power_off may points to a function from another module.
+ * Check if the pointer is set by us and only then overwrite it.
+ */
+ if (rk808->pm_pwroff_fn && pm_power_off == rk808->pm_pwroff_fn)
+ pm_power_off = NULL;
+
+ /**
+ * As above, check if the pointer is set by us before overwrite.
+ */
+ if (rk808->pm_pwroff_prep_fn &&
+ pm_power_off_prepare == rk808->pm_pwroff_prep_fn)
+ pm_power_off_prepare = NULL;
return 0;
}
+static int rk8xx_suspend(struct device *dev)
+{
+ struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+ int ret = 0;
+
+ switch (rk808->variant) {
+ case RK809_ID:
+ case RK817_ID:
+ ret = regmap_update_bits(rk808->regmap,
+ RK817_SYS_CFG(3),
+ RK817_SLPPIN_FUNC_MSK,
+ SLPPIN_SLP_FUN);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+static int rk8xx_resume(struct device *dev)
+{
+ struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+ int ret = 0;
+
+ switch (rk808->variant) {
+ case RK809_ID:
+ case RK817_ID:
+ ret = regmap_update_bits(rk808->regmap,
+ RK817_SYS_CFG(3),
+ RK817_SLPPIN_FUNC_MSK,
+ SLPPIN_NULL_FUN);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+SIMPLE_DEV_PM_OPS(rk8xx_pm_ops, rk8xx_suspend, rk8xx_resume);
+
static struct i2c_driver rk808_i2c_driver = {
.driver = {
.name = "rk808",
.of_match_table = rk808_of_match,
+ .pm = &rk8xx_pm_ops,
},
.probe = rk808_probe,
.remove = rk808_remove,