[PATCH v2 2/2] regulator: sc2731: Add regulator driver to support Spreadtrum SC2731 PMIC

2017-12-04 Thread Erick Chen
Add regulator driver for Spreadtrum SC2731 device.
It has 17 general purpose LDOs, BUCKs generator and
digital output to control regulators.

Signed-off-by: Erick Chen 
Reviewed-by: Baolin Wang 
---
Changes since v1:
- Remove of_device_id table.
- Change subsys_init() to module_init().
- Change the file's license format.
---
 drivers/regulator/Kconfig|7 +
 drivers/regulator/Makefile   |1 +
 drivers/regulator/sc2731-regulator.c |  256 ++
 3 files changed, 264 insertions(+)
 create mode 100644 drivers/regulator/sc2731-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 96cd55f..b27417c 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -744,6 +744,13 @@ config REGULATOR_S5M8767
 via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and
 supports DVS mode with 8bits of output voltage control.
 
+config REGULATOR_SC2731
+   tristate "Spreadtrum SC2731 power regulator driver"
+   depends on MFD_SC27XX_PMIC || COMPILE_TEST
+   help
+ This driver provides support for the voltage regulators on the
+ SC2731 PMIC.
+
 config REGULATOR_SKY81452
tristate "Skyworks Solutions SKY81452 voltage regulator"
depends on MFD_SKY81452
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 80ffc57..19fea09 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_REGULATOR_RT5033)+= rt5033-regulator.o
 obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o
 obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
 obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
+obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
diff --git a/drivers/regulator/sc2731-regulator.c 
b/drivers/regulator/sc2731-regulator.c
new file mode 100644
index 000..794fcd5
--- /dev/null
+++ b/drivers/regulator/sc2731-regulator.c
@@ -0,0 +1,256 @@
+ //SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2017 Spreadtrum Communications Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SC2731 regulator lock register
+ */
+#define SC2731_PWR_WR_PROT_VALUE   0xf0c
+#define SC2731_WR_UNLOCK   0x6e7f
+
+/*
+ * SC2731 enable register
+ */
+#define SC2731_POWER_PD_SW 0xc28
+#define SC2731_LDO_CAMA0_PD0xcfc
+#define SC2731_LDO_CAMA1_PD0xd04
+#define SC2731_LDO_CAMMOT_PD   0xd0c
+#define SC2731_LDO_VLDO_PD 0xd6c
+#define SC2731_LDO_EMMCCORE_PD 0xd2c
+#define SC2731_LDO_SDCORE_PD   0xd74
+#define SC2731_LDO_SDIO_PD 0xd70
+#define SC2731_LDO_WIFIPA_PD   0xd4c
+#define SC2731_LDO_USB33_PD0xd5c
+#define SC2731_LDO_CAMD0_PD0xd7c
+#define SC2731_LDO_CAMD1_PD0xd84
+#define SC2731_LDO_CON_PD  0xd8c
+#define SC2731_LDO_CAMIO_PD0xd94
+#define SC2731_LDO_SRAM_PD 0xd78
+
+/*
+ * SC2731 enable mask
+ */
+#define SC2731_DCDC_CPU0_PD_MASK   BIT(4)
+#define SC2731_DCDC_CPU1_PD_MASK   BIT(3)
+#define SC2731_DCDC_RF_PD_MASK BIT(11)
+#define SC2731_LDO_CAMA0_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMA1_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMMOT_PD_MASK  BIT(0)
+#define SC2731_LDO_VLDO_PD_MASKBIT(0)
+#define SC2731_LDO_EMMCCORE_PD_MASKBIT(0)
+#define SC2731_LDO_SDCORE_PD_MASK  BIT(0)
+#define SC2731_LDO_SDIO_PD_MASKBIT(0)
+#define SC2731_LDO_WIFIPA_PD_MASK  BIT(0)
+#define SC2731_LDO_USB33_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMD0_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMD1_PD_MASK   BIT(0)
+#define SC2731_LDO_CON_PD_MASK BIT(0)
+#define SC2731_LDO_CAMIO_PD_MASK   BIT(0)
+#define SC2731_LDO_SRAM_PD_MASKBIT(0)
+
+/*
+ * SC2731 vsel register
+ */
+#define SC2731_DCDC_CPU0_VOL   0xc54
+#define SC2731_DCDC_CPU1_VOL   0xc64
+#define SC2731_DCDC_RF_VOL 0xcb8
+#define SC2731_LDO_CAMA0_VOL   0xd00
+#define SC2731_LDO_CAMA1_VOL   0xd08
+#define SC2731_LDO_CAMMOT_VOL  0xd10
+#define SC2731_LDO_VLDO_VOL0xd28
+#define SC2731_LDO_EMMCCORE_VOL0xd30
+#define SC2731_LDO_SDCORE_VOL  0xd38
+#define SC2731_LDO_SDIO_VOL0xd40
+#define SC2731_LDO_WIFIPA_VOL  0xd50
+#define SC2731_LDO_USB33_VOL   0xd60
+#define SC2731_LDO_CAMD0_VOL   0xd80
+#define SC2731_LDO_CAMD1_VOL   0xd88
+#define SC2731_LDO_CON_VOL 0xd90
+#define SC2731_LDO_CAMIO_VOL   0xd98
+#define SC2731_LDO_SRAM_VOL0xdB0
+
+/*
+ * SC2731 vsel register mask
+ */
+#define SC2731_DCDC_CPU0_VOL_MASK  GENMASK(8, 0)

[PATCH v2 2/2] regulator: sc2731: Add regulator driver to support Spreadtrum SC2731 PMIC

2017-12-04 Thread Erick Chen
Add regulator driver for Spreadtrum SC2731 device.
It has 17 general purpose LDOs, BUCKs generator and
digital output to control regulators.

Signed-off-by: Erick Chen 
Reviewed-by: Baolin Wang 
---
Changes since v1:
- Remove of_device_id table.
- Change subsys_init() to module_init().
- Change the file's license format.
---
 drivers/regulator/Kconfig|7 +
 drivers/regulator/Makefile   |1 +
 drivers/regulator/sc2731-regulator.c |  256 ++
 3 files changed, 264 insertions(+)
 create mode 100644 drivers/regulator/sc2731-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 96cd55f..b27417c 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -744,6 +744,13 @@ config REGULATOR_S5M8767
 via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and
 supports DVS mode with 8bits of output voltage control.
 
+config REGULATOR_SC2731
+   tristate "Spreadtrum SC2731 power regulator driver"
+   depends on MFD_SC27XX_PMIC || COMPILE_TEST
+   help
+ This driver provides support for the voltage regulators on the
+ SC2731 PMIC.
+
 config REGULATOR_SKY81452
tristate "Skyworks Solutions SKY81452 voltage regulator"
depends on MFD_SKY81452
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 80ffc57..19fea09 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_REGULATOR_RT5033)+= rt5033-regulator.o
 obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o
 obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
 obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
+obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
diff --git a/drivers/regulator/sc2731-regulator.c 
b/drivers/regulator/sc2731-regulator.c
new file mode 100644
index 000..794fcd5
--- /dev/null
+++ b/drivers/regulator/sc2731-regulator.c
@@ -0,0 +1,256 @@
+ //SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2017 Spreadtrum Communications Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SC2731 regulator lock register
+ */
+#define SC2731_PWR_WR_PROT_VALUE   0xf0c
+#define SC2731_WR_UNLOCK   0x6e7f
+
+/*
+ * SC2731 enable register
+ */
+#define SC2731_POWER_PD_SW 0xc28
+#define SC2731_LDO_CAMA0_PD0xcfc
+#define SC2731_LDO_CAMA1_PD0xd04
+#define SC2731_LDO_CAMMOT_PD   0xd0c
+#define SC2731_LDO_VLDO_PD 0xd6c
+#define SC2731_LDO_EMMCCORE_PD 0xd2c
+#define SC2731_LDO_SDCORE_PD   0xd74
+#define SC2731_LDO_SDIO_PD 0xd70
+#define SC2731_LDO_WIFIPA_PD   0xd4c
+#define SC2731_LDO_USB33_PD0xd5c
+#define SC2731_LDO_CAMD0_PD0xd7c
+#define SC2731_LDO_CAMD1_PD0xd84
+#define SC2731_LDO_CON_PD  0xd8c
+#define SC2731_LDO_CAMIO_PD0xd94
+#define SC2731_LDO_SRAM_PD 0xd78
+
+/*
+ * SC2731 enable mask
+ */
+#define SC2731_DCDC_CPU0_PD_MASK   BIT(4)
+#define SC2731_DCDC_CPU1_PD_MASK   BIT(3)
+#define SC2731_DCDC_RF_PD_MASK BIT(11)
+#define SC2731_LDO_CAMA0_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMA1_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMMOT_PD_MASK  BIT(0)
+#define SC2731_LDO_VLDO_PD_MASKBIT(0)
+#define SC2731_LDO_EMMCCORE_PD_MASKBIT(0)
+#define SC2731_LDO_SDCORE_PD_MASK  BIT(0)
+#define SC2731_LDO_SDIO_PD_MASKBIT(0)
+#define SC2731_LDO_WIFIPA_PD_MASK  BIT(0)
+#define SC2731_LDO_USB33_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMD0_PD_MASK   BIT(0)
+#define SC2731_LDO_CAMD1_PD_MASK   BIT(0)
+#define SC2731_LDO_CON_PD_MASK BIT(0)
+#define SC2731_LDO_CAMIO_PD_MASK   BIT(0)
+#define SC2731_LDO_SRAM_PD_MASKBIT(0)
+
+/*
+ * SC2731 vsel register
+ */
+#define SC2731_DCDC_CPU0_VOL   0xc54
+#define SC2731_DCDC_CPU1_VOL   0xc64
+#define SC2731_DCDC_RF_VOL 0xcb8
+#define SC2731_LDO_CAMA0_VOL   0xd00
+#define SC2731_LDO_CAMA1_VOL   0xd08
+#define SC2731_LDO_CAMMOT_VOL  0xd10
+#define SC2731_LDO_VLDO_VOL0xd28
+#define SC2731_LDO_EMMCCORE_VOL0xd30
+#define SC2731_LDO_SDCORE_VOL  0xd38
+#define SC2731_LDO_SDIO_VOL0xd40
+#define SC2731_LDO_WIFIPA_VOL  0xd50
+#define SC2731_LDO_USB33_VOL   0xd60
+#define SC2731_LDO_CAMD0_VOL   0xd80
+#define SC2731_LDO_CAMD1_VOL   0xd88
+#define SC2731_LDO_CON_VOL 0xd90
+#define SC2731_LDO_CAMIO_VOL   0xd98
+#define SC2731_LDO_SRAM_VOL0xdB0
+
+/*
+ * SC2731 vsel register mask
+ */
+#define SC2731_DCDC_CPU0_VOL_MASK  GENMASK(8, 0)
+#define SC2731_DCDC_CPU1_VOL_MASK  GENMASK(8, 0)