Re: [PATCH 0/3] Modernize tasklet callback API
> > I have a patch set to convert the remaining tasklet usage in sound > drivers to either the threaded IRQ or the work, but it wasn't > submitted / merged for 5.8 due to the obvious conflict with your API > changes. > Each conversion is rather simple, but it's always a question of the > nature of each tasklet usage which alternative is the best fit. > > FWIW, the current version is found in test/kill-tasklet branch of > sound git tree > git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git Great. Currently my tree has these converted to use the new tasklet_setup() api. I will add these to my threaded IRQ/work tree (which is still wip). Thanks. -- - Allen ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 0/3] Modernize tasklet callback API
Kees, > Was a Coccinelle script used for any of these conversions? I wonder if > it'd be easier to do a single treewide patch for the more mechanical > changes. No, I should have written one. Will do it. > And, actually, I still think the "prepare" patches should just be > collapsed into the actual "covert" patches -- there are only a few. Okay. It's been done and pushed to: https://github.com/allenpais/tasklets/tree/V4 > After those, yeah, I think getting these sent to their respective > maintainers is the next step. Please look at the above branch, if it looks fine, let me know if I can add your ACK on the patches. > > Sure! I will add it to the tracker. Here's for the refactoring: > https://github.com/KSPP/linux/issues/30 > > and here's for the removal: > https://github.com/KSPP/linux/issues/94 > > if you can added details/examples of how they should be removed, that'd > help other folks too, if they wanted to jump in. :) Sure, Thank you. - Allen ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 20/44] staging: mfd: hi6421-spmi-pmic: fix some coding style issues
Checkpatch complains about some minor issues inside this driver that were not addressed by the previous patch. Address them. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 4 ++-- include/linux/mfd/hi6421-spmi-pmic.h| 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 09cedfa1e4bb..d8b84d64041e 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -189,7 +189,7 @@ static struct irq_chip hi6421_spmi_pmu_irqchip = { }; static int hi6421_spmi_irq_map(struct irq_domain *d, unsigned int virq, - irq_hw_number_t hw) + irq_hw_number_t hw) { struct hi6421_spmi_pmic *pmic = d->host_data; @@ -350,7 +350,7 @@ static int hi6421_spmi_pmic_probe(struct spmi_device *pdev) * The logic below will rely that the pmic is already stored at * drvdata. */ - dev_dbg(&pdev->dev, "SPMI-PMIC: adding childs for %pOF\n", + dev_dbg(&pdev->dev, "SPMI-PMIC: adding children for %pOF\n", pdev->dev.of_node); ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs), diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index d12ad7484018..aeff96c4a37e 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -38,7 +38,8 @@ struct hi6421_spmi_pmic { unsigned int*irqs; int irqnum; int irqarray; - struct hi6421_spmi_irq_mask_infoirq_mask_addr; + + struct hi6421_spmi_irq_mask_infoirq_mask_addr; struct hi6421_spmi_irq_info irq_addr; }; -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 18/44] staging: mfd: hi6421-spmi-pmic: cleanup OF properties
Simplify the names of the DT properties and do some cleanups, in order to better document them. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index f523b2d844b9..aed2d3ec2227 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -209,37 +209,37 @@ static int get_pmic_device_tree_data(struct device_node *np, struct hisi_pmic *p int ret = 0; /*get pmic irq num*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-irq-num", + ret = of_property_read_u32_array(np, "irq-num", &pmic->irqnum, 1); if (ret) { - pr_err("no hisilicon,hisi-pmic-irq-num property set\n"); + pr_err("no irq-num property set\n"); ret = -ENODEV; return ret; } /*get pmic irq array number*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-irq-array", + ret = of_property_read_u32_array(np, "irq-array", &pmic->irqarray, 1); if (ret) { - pr_err("no hisilicon,hisi-pmic-irq-array property set\n"); + pr_err("no irq-array property set\n"); ret = -ENODEV; return ret; } /*SOC_PMIC_IRQ_MASK_0_ADDR*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-irq-mask-addr", + ret = of_property_read_u32_array(np, "irq-mask-addr", (int *)&pmic->irq_mask_addr, 2); if (ret) { - pr_err("no hisilicon,hisi-pmic-irq-mask-addr property set\n"); + pr_err("no irq-mask-addr property set\n"); ret = -ENODEV; return ret; } /*SOC_PMIC_IRQ0_ADDR*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-irq-addr", + ret = of_property_read_u32_array(np, "irq-addr", (int *)&pmic->irq_addr, 2); if (ret) { - pr_err("no hisilicon,hisi-pmic-irq-addr property set\n"); + pr_err("no irq-addr property set\n"); ret = -ENODEV; return ret; } -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 06/44] staging: spmi: hisi-spmi-controller: use le32 macros where needed
Instead of manually using bswap_32(), just use the le32 macros. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hisi-spmi-controller.c | 20 +++ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index 7fae267a6062..cacd28150b49 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -11,7 +11,6 @@ #include #include #include -#include #define SPMI_CONTROLLER_NAME "spmi_controller" @@ -43,11 +42,6 @@ #define SPMI_APB_SPMI_CMD_TYPE_OFFSET 24 #define SPMI_APB_SPMI_CMD_LENGTH_OFFSET20 -#define bswap_32(X) \ -u32)(X) & 0xff00) >> 24) | \ - (((u32)(X) & 0x00ff) >> 8) | \ - (((u32)(X) & 0xff00) << 8) | \ - (((u32)(X) & 0x00ff) << 24)) #define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 #define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 @@ -179,14 +173,15 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, writel(cmd, spmi_controller->base + chnl_ofst + SPMI_APB_SPMI_CMD_BASE_ADDR); - rc = spmi_controller_wait_for_done(spmi_controller, spmi_controller->base, sid, addr); + rc = spmi_controller_wait_for_done(spmi_controller, + spmi_controller->base, sid, addr); if (rc) goto done; i = 0; do { data = readl(spmi_controller->base + chnl_ofst + SPMI_SLAVE_OFFSET * sid + SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * SPMI_PER_DATAREG_BYTE); - data = bswap_32(data); + data = be32_to_cpu((__be32)data); if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { memcpy(buf, &data, sizeof(data)); buf += sizeof(data); @@ -210,8 +205,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, { struct spmi_controller_dev *spmi_controller = dev_get_drvdata(&ctrl->dev); unsigned long flags; - u32 cmd; - u32 data = 0; + u32 cmd, data; int rc; u32 chnl_ofst = SPMI_CHANNEL_OFFSET * spmi_controller->channel; u8 op_code, i; @@ -246,7 +240,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, i = 0; do { - memset(&data, 0, sizeof(data)); + data = 0; if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { memcpy(&data, buf, sizeof(data)); buf += sizeof(data); @@ -255,8 +249,8 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, buf += (bc % SPMI_PER_DATAREG_BYTE); } - data = bswap_32(data); - writel(data, spmi_controller->base + chnl_ofst + SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); + writel((u32)cpu_to_be32(data), + spmi_controller->base + chnl_ofst + SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); i++; } while (bc > i * SPMI_PER_DATAREG_BYTE); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 36/44] staging: regulator: hi6421v600-regulator: initialize ramp_delay
Without that, the regulator's core complains with: ldo17: ramp_delay not set For now, use the enable time, as we don't have any datasheets from this device. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421v600-regulator.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 5ddaf7f8cacc..21467fce9980 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -267,6 +267,9 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, return ret; } + /* FIXME: are there a better value for this? */ + rdesc->ramp_delay = rdesc->enable_time; + /* parse .eco_uA */ ret = of_property_read_u32(np, "eco-microamp", &sreg->eco_uA); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 00/44] SPMI patches needed by Hikey 970
Hi Greg, This patch series is part of a work I'm doing in order to be able to support a HiKey 970 board that I recently got on my hands. I received some freedback from Mark and from Jonathan on a first attempt I made to upstream this. I'm opting to submit it via staging, because I had to start from the patch that originally added this driver on a 4.9 Kernel tree: https://github.com/96boards-hikey/linux/tree/hikey970-v4.9 In order to preserve the original SOB from the driver's author. The patches following it are on the standard way: one patch per logical change. This is part of a bigger work whose goal is to have upstream support for USB and DRM/KMS on such boards. I suspect that, maybe except for the DT part, those 3 specific drivers are more or less ready to be moved from staging, but the other drivers that are also part of this attempt aren't ready. Specially the DRM driver has some bugs that came from the OOT version. So, my current plan is to submit those drivers to staging for 5.9 and move the ones that are ok out of staging on Kernel 5.10. Regards, Mauro. Mauro Carvalho Chehab (41): staging: spmi: hisi-spmi-controller: coding style fixup staging: spmi: hisi-spmi-controller: fix it to probe successfully staging: spmi: hisi-spmi-controller: fix a typo staging: spmi: hisi-spmi-controller: adjust whitespaces at defines staging: spmi: hisi-spmi-controller: use le32 macros where needed staging: spmi: hisi-spmi-controller: add debug when values are read/write staging: spmi: hisi-spmi-controller: fix the dev_foo() logic staging: spmi: hisi-spmi-controller: add it to the building system staging: spmi: hisi-spmi-controller: do some code cleanups staging: mfd: hi6421-spmi-pmic: get rid of unused code staging: mfd: hi6421-spmi-pmic: deal with non-static functions staging: mfd: hi6421-spmi-pmic: get rid of the static vars staging: mfd: hi6421-spmi-pmic: cleanup hi6421-spmi-pmic.h header staging: mfd: hi6421-spmi-pmic: change the binding logic staging: mfd: hi6421-spmi-pmic: get rid of unused OF properties staging: mfd: hi6421-spmi-pmic: cleanup OF properties staging: mfd: hi6421-spmi-pmic: change namespace on its functions staging: mfd: hi6421-spmi-pmic: fix some coding style issues staging: mfd: hi6421-spmi-pmic: add it to the building system staging: mfd: hi6421-spmi-pmic: cleanup the code staging: regulator: hi6421v600-regulator: get rid of unused code staging: regulator: hi6421v600-regulator: port it to upstream staging: regulator: hi6421v600-regulator: coding style fixups staging: regulator: hi6421v600-regulator: change the binding logic staging: regulator: hi6421v600-regulator: cleanup struct hisi_regulator staging: regulator: hi6421v600-regulator: cleanup debug messages staging: regulator: hi6421v600-regulator: use shorter names for OF properties staging: regulator: hi6421v600-regulator: better handle modes staging: regulator: hi6421v600-regulator: change namespace staging: regulator: hi6421v600-regulator: convert to use get/set voltage_sel staging: regulator: hi6421v600-regulator: don't use usleep_range for off_on_delay staging: regulator: hi6421v600-regulator: add a driver-specific debug macro staging: regulator: hi6421v600-regulator: initialize ramp_delay staging: regulator: hi6421v600-regulator: cleanup DT settings staging: regulator: hi6421v600-regulator: fix some coding style issues staging: regulator: hi6421v600-regulator: add it to the building system staging: regulator: hi6421v600-regulator: code cleanup staging: hikey9xx: add a TODO list MAINTAINERS: add an entry for HiSilicon 6421v600 drivers dt: document HiSilicon SPMI controller and mfd/regulator properties dt: hisilicon: add support for the PMIC found on Hikey 970 Mayulong (3): staging: spmi: add Hikey 970 SPMI controller driver staging: mfd: add a PMIC driver for HiSilicon 6421 SPMI version staging: regulator: add a regulator driver for HiSilicon 6421v600 SPMI PMIC .../mfd/hisilicon,hi6421-spmi-pmic.yaml | 182 +++ .../spmi/hisilicon,hisi-spmi-controller.yaml | 54 ++ MAINTAINERS | 6 + .../boot/dts/hisilicon/hi3670-hikey970.dts| 16 +- .../boot/dts/hisilicon/hikey970-pmic.dtsi | 200 drivers/staging/Kconfig | 2 + drivers/staging/Makefile | 1 + drivers/staging/hikey9xx/Kconfig | 35 ++ drivers/staging/hikey9xx/Makefile | 5 + drivers/staging/hikey9xx/TODO | 5 + drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 381 ++ .../staging/hikey9xx/hi6421v600-regulator.c | 479 ++ .../staging/hikey9xx/hisi-spmi-controller.c | 351 + include/linux/mfd/hi6421-spmi-pmic.h | 68 +++ 14 files changed, 1773 insertions(+), 12 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/hisilicon,
[PATCH 24/44] staging: regulator: hi6421v600-regulator: get rid of unused code
Get rid of the sysfs code and other parts of the driver which aren't needed upstream. If needed later, this patch can be (partially?) reversed. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 196 +- 1 file changed, 8 insertions(+), 188 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 941bfe32bf5b..7bc0ae27b110 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -34,19 +34,10 @@ #include #include #include -#ifdef CONFIG_HISI_PMIC_DEBUG -#include -#endif #include #include #include -#if 1 -#define BRAND_DEBUG(args...) pr_debug(args); -#else -#define BRAND_DEBUG(args...) -#endif - struct hisi_regulator_register_info { u32 ctrl_reg; u32 enable_mask; @@ -110,7 +101,7 @@ static int hisi_regulator_is_enabled(struct regulator_dev *dev) struct hisi_pmic *pmic = rdev_to_pmic(dev); reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); - BRAND_DEBUG("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", __func__, sreg->register_info.ctrl_reg,\ + pr_debug("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", __func__, sreg->register_info.ctrl_reg,\ (reg_val & sreg->register_info.enable_mask)); return ((reg_val & sreg->register_info.enable_mask) != 0); @@ -124,7 +115,7 @@ static int hisi_regulator_enable(struct regulator_dev *dev) /* keep a distance of off_on_delay from last time disabled */ ensured_time_after(sreg->last_off_time, sreg->off_on_delay); - BRAND_DEBUG("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay); + pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay); /* cannot enable more than one regulator at one time */ mutex_lock(&enable_mutex); @@ -134,7 +125,7 @@ static int hisi_regulator_enable(struct regulator_dev *dev) hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, sreg->register_info.enable_mask, sreg->register_info.enable_mask); - BRAND_DEBUG("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\ + pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\ sreg->register_info.enable_mask); do_gettimeofday(&last_enabled); @@ -165,7 +156,7 @@ static int hisi_regulator_get_voltage(struct regulator_dev *dev) /* get voltage selector */ reg_val = hisi_pmic_read(pmic, sreg->register_info.vset_reg); - BRAND_DEBUG("<[%s]: vset_reg=0x%x>\n", __func__, sreg->register_info.vset_reg); + pr_debug("<[%s]: vset_reg=0x%x>\n", __func__, sreg->register_info.vset_reg); selector = (reg_val & sreg->register_info.vset_mask) >> (ffs(sreg->register_info.vset_mask) - 1); @@ -198,7 +189,7 @@ static int hisi_regulator_set_voltage(struct regulator_dev *dev, sreg->register_info.vset_mask, vsel << (ffs(sreg->register_info.vset_mask) - 1)); - BRAND_DEBUG("<[%s]: vset_reg=0x%x, vset_mask=0x%x, value=0x%x>\n", __func__,\ + pr_debug("<[%s]: vset_reg=0x%x, vset_mask=0x%x, value=0x%x>\n", __func__,\ sreg->register_info.vset_reg,\ sreg->register_info.vset_mask,\ vsel << (ffs(sreg->register_info.vset_mask) - 1)\ @@ -214,7 +205,7 @@ static unsigned int hisi_regulator_get_mode(struct regulator_dev *dev) u32 reg_val; reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); - BRAND_DEBUG("<[%s]: reg_val=%d, ctrl_reg=0x%x, eco_mode_mask=0x%x>\n", __func__, reg_val,\ + pr_debug("<[%s]: reg_val=%d, ctrl_reg=0x%x, eco_mode_mask=0x%x>\n", __func__, reg_val,\ sreg->register_info.ctrl_reg,\ sreg->register_info.eco_mode_mask\ ); @@ -248,7 +239,7 @@ static int hisi_regulator_set_mode(struct regulator_dev *dev, sreg->register_info.eco_mode_mask, eco_mode << (ffs(sreg->register_info.eco_mode_mask) - 1)); - BRAND_DEBUG("<[%s]: ctrl_reg=0x%x, eco_mode_mask=0x%x, value=0x%x>\n", __func__,\ + pr_debug("<[%s]: ctrl_reg=0x%x, eco_mode_mask=0x%x, value=0x%x>\n", __func__,\ sreg->register_info.ctrl_reg,\ sreg->register_info.eco_mode_mask,\ eco_mode << (ffs(sreg->register_info.eco_mode_mask) - 1)\ @@ -403,147 +394,6 @@ static struct of_device_id of_hisi_regulator_match_tbl[] = { { /* end */ } }; -#ifdef CONFIG_HISI_PMIC_DEBUG -extern void get_current_regulator_dev(struct seq_file *s); -extern void set_regulator_state(char *ldo_name, int value); -extern void get_regulator_state(char *ldo_name);
[PATCH 25/44] staging: regulator: hi6421v600-regulator: port it to upstream
The driver was originally written for Kernel 4.9. It needs to be ported to upstream: - Got rid of timeval; - Removed a bogus dependency; - Did cleanups at the header file. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 34 +++ 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 7bc0ae27b110..904cb64b1dcd 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -49,7 +49,6 @@ struct hisi_regulator_register_info { struct hisi_regulator { const char *name; struct hisi_regulator_register_info register_info; - struct timeval last_off_time; u32 off_on_delay; u32 eco_uA; struct regulator_desc rdesc; @@ -57,8 +56,6 @@ struct hisi_regulator { }; static DEFINE_MUTEX(enable_mutex); -struct timeval last_enabled; - static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev) { @@ -72,27 +69,6 @@ static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev) /* helper function to ensure when it returns it is at least 'delay_us' * microseconds after 'since'. */ -static void ensured_time_after(struct timeval since, u32 delay_us) -{ - struct timeval now; - u64 elapsed_ns64, delay_ns64; - u32 actual_us32; - - delay_ns64 = delay_us * NSEC_PER_USEC; - do_gettimeofday(&now); - elapsed_ns64 = timeval_to_ns(&now) - timeval_to_ns(&since); - if (delay_ns64 > elapsed_ns64) { - actual_us32 = ((u32)(delay_ns64 - elapsed_ns64) / - NSEC_PER_USEC); - if (actual_us32 >= 1000) { - mdelay(actual_us32 / 1000); /*lint !e647 */ - udelay(actual_us32 % 1000); - } else if (actual_us32 > 0) { - udelay(actual_us32); - } - } - return; -} static int hisi_regulator_is_enabled(struct regulator_dev *dev) { @@ -113,13 +89,16 @@ static int hisi_regulator_enable(struct regulator_dev *dev) struct hisi_pmic *pmic = rdev_to_pmic(dev); /* keep a distance of off_on_delay from last time disabled */ - ensured_time_after(sreg->last_off_time, sreg->off_on_delay); + usleep_range(sreg->off_on_delay, sreg->off_on_delay + 1000); pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay); /* cannot enable more than one regulator at one time */ mutex_lock(&enable_mutex); - ensured_time_after(last_enabled, HISI_REGS_ENA_PROTECT_TIME); + usleep_range(HISI_REGS_ENA_PROTECT_TIME, +HISI_REGS_ENA_PROTECT_TIME + 1000); + + /* set enable register */ hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, @@ -128,7 +107,6 @@ static int hisi_regulator_enable(struct regulator_dev *dev) pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\ sreg->register_info.enable_mask); - do_gettimeofday(&last_enabled); mutex_unlock(&enable_mutex); return 0; @@ -143,8 +121,6 @@ static int hisi_regulator_disable(struct regulator_dev *dev) hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, sreg->register_info.enable_mask, 0); - do_gettimeofday(&sreg->last_off_time); - return 0; } -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 05/44] staging: spmi: hisi-spmi-controller: adjust whitespaces at defines
Some defines are not aligned with tab=8, which is the style defined on Linux. Adjust them. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hisi-spmi-controller.c | 26 ++- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index 99cf757d76fe..7fae267a6062 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -18,10 +18,10 @@ /* * SPMI register addr */ -#define SPMI_CHANNEL_OFFSET0x0300 -#define SPMI_SLAVE_OFFSET 0x20 +#define SPMI_CHANNEL_OFFSET0x0300 +#define SPMI_SLAVE_OFFSET 0x20 -#define SPMI_APB_SPMI_CMD_BASE_ADDR0x0100 +#define SPMI_APB_SPMI_CMD_BASE_ADDR0x0100 #define SPMI_APB_SPMI_WDATA0_BASE_ADDR 0x0104 #define SPMI_APB_SPMI_WDATA1_BASE_ADDR 0x0108 @@ -35,21 +35,21 @@ #define SPMI_APB_SPMI_RDATA2_BASE_ADDR 0x020c #define SPMI_APB_SPMI_RDATA3_BASE_ADDR 0x0210 -#define SPMI_PER_DATAREG_BYTE 4 +#define SPMI_PER_DATAREG_BYTE 4 /* * SPMI cmd register */ -#define SPMI_APB_SPMI_CMD_EN BIT(31) +#define SPMI_APB_SPMI_CMD_EN BIT(31) #define SPMI_APB_SPMI_CMD_TYPE_OFFSET 24 #define SPMI_APB_SPMI_CMD_LENGTH_OFFSET20 -#define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 -#define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 #define bswap_32(X) \ u32)(X) & 0xff00) >> 24) | \ (((u32)(X) & 0x00ff) >> 8) | \ (((u32)(X) & 0xff00) << 8) | \ (((u32)(X) & 0x00ff) << 24)) +#define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 +#define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 /* Command Opcodes */ @@ -70,15 +70,15 @@ enum spmi_controller_cmd_op_code { /* * SPMI status register */ -#define SPMI_APB_TRANS_DONEBIT(0) -#define SPMI_APB_TRANS_FAILBIT(2) +#define SPMI_APB_TRANS_DONEBIT(0) +#define SPMI_APB_TRANS_FAILBIT(2) /* Command register fields */ #define SPMI_CONTROLLER_CMD_MAX_BYTE_COUNT 16 /* Maximum number of support PMIC peripherals */ #define SPMI_CONTROLLER_TIMEOUT_US 1000 -#define SPMI_CONTROLLER_MAX_TRANS_BYTES(16) +#define SPMI_CONTROLLER_MAX_TRANS_BYTES16 /* * @base base address of the PMIC Arbiter core registers. @@ -114,8 +114,10 @@ static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, { u32 status = 0; u32 timeout = SPMI_CONTROLLER_TIMEOUT_US; - u32 offset = SPMI_APB_SPMI_STATUS_BASE_ADDR + SPMI_CHANNEL_OFFSET * ctrl_dev->channel - + SPMI_SLAVE_OFFSET * sid; + u32 offset; + + offset = SPMI_APB_SPMI_STATUS_BASE_ADDR; + offset += SPMI_CHANNEL_OFFSET * ctrl_dev->channel + SPMI_SLAVE_OFFSET * sid; while (timeout--) { status = readl(base + offset); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 02/44] staging: spmi: hisi-spmi-controller: coding style fixup
In order to prepare for upstream, fix most coding style issues. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hisi-spmi-controller.c | 179 -- 1 file changed, 82 insertions(+), 97 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index 987526c8b49f..3af0bd1b379f 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 #include #include @@ -21,7 +22,7 @@ #define SPMI_SLAVE_OFFSET 0x20 #define SPMI_APB_SPMI_CMD_BASE_ADDR0x0100 -/*lint -e750 -esym(750,*)*/ + #define SPMI_APB_SPMI_WDATA0_BASE_ADDR 0x0104 #define SPMI_APB_SPMI_WDATA1_BASE_ADDR 0x0108 #define SPMI_APB_SPMI_WDATA2_BASE_ADDR 0x010c @@ -33,25 +34,25 @@ #define SPMI_APB_SPMI_RDATA1_BASE_ADDR 0x0208 #define SPMI_APB_SPMI_RDATA2_BASE_ADDR 0x020c #define SPMI_APB_SPMI_RDATA3_BASE_ADDR 0x0210 -/*lint +e750 -esym(750,*)*/ #define SPMI_PER_DATAREG_BYTE 4 /* * SPMI cmd register */ -#define SPMI_APB_SPMI_CMD_EN (1 << 31) +#define SPMI_APB_SPMI_CMD_EN BIT(31) #define SPMI_APB_SPMI_CMD_TYPE_OFFSET 24 #define SPMI_APB_SPMI_CMD_LENGTH_OFFSET20 #define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 #define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 -#define Tranverse32(X) u32)(X) & 0xff00) >> 24) | \ - (((u32)(X) & 0x00ff) >> 8) | \ - (((u32)(X) & 0xff00) << 8) | \ - (((u32)(X) & 0x00ff) << 24)) +#define bswap_32(X) \ +u32)(X) & 0xff00) >> 24) | \ + (((u32)(X) & 0x00ff) >> 8) | \ + (((u32)(X) & 0xff00) << 8) | \ + (((u32)(X) & 0x00ff) << 24)) /* Command Opcodes */ -/*lint -e749 -esym(749,*)*/ + enum spmi_controller_cmd_op_code { SPMI_CMD_REG_ZERO_WRITE = 0, SPMI_CMD_REG_WRITE = 1, @@ -65,13 +66,12 @@ enum spmi_controller_cmd_op_code { SPMI_CMD_REG_SHUTDOWN = 9, SPMI_CMD_REG_WAKEUP = 10, }; -/*lint +e749 -esym(749,*)*/ /* * SPMI status register */ -#define SPMI_APB_TRANS_DONE(1 << 0) -#define SPMI_APB_TRANS_FAIL(1 << 2) +#define SPMI_APB_TRANS_DONEBIT(0) +#define SPMI_APB_TRANS_FAILBIT(2) /* Command register fields */ #define SPMI_CONTROLLER_CMD_MAX_BYTE_COUNT 16 @@ -80,16 +80,6 @@ enum spmi_controller_cmd_op_code { #define SPMI_CONTROLLER_TIMEOUT_US 1000 #define SPMI_CONTROLLER_MAX_TRANS_BYTES(16) -#define SPMI_WRITEL( dev, reg, addr ) \ - do { \ - writel( ( reg ), ( addr ) ); \ - } while (0) - -#define SPMI_READL( dev, reg, addr ) \ - do { \ - reg = readl( addr ); \ - } while (0) - /* * @base base address of the PMIC Arbiter core registers. * @rdbase, @wrbase base address of the PMIC Arbiter read core registers. @@ -120,7 +110,7 @@ struct spmi_controller_dev { }; static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, - void __iomem *base, u8 sid, u16 addr) +void __iomem *base, u8 sid, u16 addr) { u32 status = 0; u32 timeout = SPMI_CONTROLLER_TIMEOUT_US; @@ -128,7 +118,7 @@ static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, + SPMI_SLAVE_OFFSET * sid; while (timeout--) { - SPMI_READL(ctrl_dev->dev, status, base + offset);/*lint !e732 */ + status = readl(base + offset); if (status & SPMI_APB_TRANS_DONE) { if (status & SPMI_APB_TRANS_FAIL) { @@ -139,23 +129,23 @@ static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, } return 0; } - udelay(1);/*lint !e778 !e774 !e747*/ + udelay(1); } dev_err(ctrl_dev->dev, "%s: timeout, status 0x%x\n", __func__, status); - return -ETIMEDOUT;/*lint !e438*/ -}/*lint !e715 !e529*/ + return -ETIMEDOUT; +} static int spmi_read_cmd(struct spmi_controller *ctrl, - u8 opc, u8 sid, u16 addr, u8 *buf, size_t bc) +u8 opc, u8 sid,
[PATCH 41/44] staging: hikey9xx: add a TODO list
Place the things that are needed to be able to move those drivers out of staging. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/TODO | 5 + 1 file changed, 5 insertions(+) create mode 100644 drivers/staging/hikey9xx/TODO diff --git a/drivers/staging/hikey9xx/TODO b/drivers/staging/hikey9xx/TODO new file mode 100644 index ..65e7996a3066 --- /dev/null +++ b/drivers/staging/hikey9xx/TODO @@ -0,0 +1,5 @@ +ToDo list: + +- Port other drivers needed by Hikey 960/970; +- Test drivers on Hikey 960; +- Validate device tree bindings. -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 17/44] staging: mfd: hi6421-spmi-pmic: get rid of unused OF properties
There are several OF properties that aren't used by Hikey 970, and some are not even used inside the driver. So, drop them, as as this makes easier to document what's actually used. If latter needed, those could be re-added later. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 145 +--- include/linux/mfd/hi6421-spmi-pmic.h| 14 +- 2 files changed, 7 insertions(+), 152 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 939f7bd5d8ba..f523b2d844b9 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -49,7 +49,6 @@ /*#define HISI_NR_IRQ 25*/ #define HISI_MASK_FIELD0xFF #define HISI_BITS 8 -#define PMIC_FPGA_FLAG 1 /*define the first group interrupt register number*/ #define HISI_PMIC_FIRST_GROUP_INT_NUM2 @@ -144,24 +143,6 @@ static irqreturn_t hisi_irq_handler(int irq, void *data) } } - /*Handle the second group irq if analysis the second group irq from dtsi*/ - if (pmic->g_extinterrupt_flag == 1) { - for (i = 0; i < pmic->irqarray1; i++) { - pending = hisi_pmic_read(pmic, (i + pmic->irq_addr1.start_addr)); - pending &= HISI_MASK_FIELD; - if (pending != 0) - pr_debug("pending[%d]=0x%lx\n\r", i, pending); - - hisi_pmic_write(pmic, (i + pmic->irq_addr1.start_addr), pending); - - if (!pending) - continue; - - for_each_set_bit(offset, &pending, HISI_BITS) - generic_handle_irq(pmic->irqs[offset + (i + HISI_PMIC_FIRST_GROUP_INT_NUM) * HISI_BITS]); - } - } - return IRQ_HANDLED; } @@ -172,19 +153,8 @@ static void hisi_irq_mask(struct irq_data *d) unsigned long flags; offset = (irqd_to_hwirq(d) >> 3); - if (pmic->g_extinterrupt_flag == 1) { - if (offset < HISI_PMIC_FIRST_GROUP_INT_NUM) { - offset += pmic->irq_mask_addr.start_addr; - } else { - /* -* Change addr when irq num larger than 16 because -* interrupt addr is nonsequence -*/ - offset = offset + (pmic->irq_mask_addr1.start_addr) - HISI_PMIC_FIRST_GROUP_INT_NUM; - } - } else { - offset += pmic->irq_mask_addr.start_addr; - } + offset += pmic->irq_mask_addr.start_addr; + spin_lock_irqsave(&pmic->lock, flags); data = hisi_pmic_read(pmic, offset); data |= (1 << (irqd_to_hwirq(d) & 0x07)); @@ -199,14 +169,8 @@ static void hisi_irq_unmask(struct irq_data *d) unsigned long flags; offset = (irqd_to_hwirq(d) >> 3); - if (pmic->g_extinterrupt_flag == 1) { - if (offset < HISI_PMIC_FIRST_GROUP_INT_NUM) - offset += pmic->irq_mask_addr.start_addr; - else - offset = offset + (pmic->irq_mask_addr1.start_addr) - HISI_PMIC_FIRST_GROUP_INT_NUM; - } else { - offset += pmic->irq_mask_addr.start_addr; - } + offset += pmic->irq_mask_addr.start_addr; + spin_lock_irqsave(&pmic->lock, flags); data = hisi_pmic_read(pmic, offset); data &= ~(1 << (irqd_to_hwirq(d) & 0x07)); @@ -280,69 +244,6 @@ static int get_pmic_device_tree_data(struct device_node *np, struct hisi_pmic *p return ret; } - /*pmic lock*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-lock", -(int *)&pmic->normal_lock, 2); - if (ret) { - pr_err("no hisilicon,hisi-pmic-lock property set\n"); - ret = -ENODEV; - return ret; - } - - /*pmic debug lock*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-debug-lock", -(int *)&pmic->debug_lock, 2); - if (ret) { - pr_err("no hisilicon,hisi-pmic-debug-lock property set\n"); - ret = -ENODEV; - return ret; - } - - return ret; -} - -static int get_pmic_device_tree_data1(struct device_node *np, struct hisi_pmic *pmic) -{ - int ret = 0; - - /*get pmic irq num*/ - ret = of_property_read_u32_array(np, "hisilicon,hisi-pmic-irq-num1", -&pmic->irqnum1, 1); - if (ret) { - pr_err("no hisilicon,hisi-pmic-irq-num1 property set\n"); - ret = -ENODEV; - pmic->irqnum1 = 0; - return ret; - } - - /*get pmic irq array number*/ -
[PATCH 09/44] staging: spmi: hisi-spmi-controller: add it to the building system
Now that the driver was ported to upstream, add it as a SPMI controller. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/Kconfig | 2 ++ drivers/staging/Makefile | 1 + drivers/staging/hikey9xx/Kconfig | 10 ++ drivers/staging/hikey9xx/Makefile | 3 +++ 4 files changed, 16 insertions(+) create mode 100644 drivers/staging/hikey9xx/Kconfig create mode 100644 drivers/staging/hikey9xx/Makefile diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 4ec5528f89fa..dfce8e39dbc3 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -120,4 +120,6 @@ source "drivers/staging/qlge/Kconfig" source "drivers/staging/wfx/Kconfig" +source "drivers/staging/hikey9xx/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index 4d34198151b3..e369a4f5e14a 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -50,3 +50,4 @@ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_KPC2000) += kpc2000/ obj-$(CONFIG_QLGE) += qlge/ obj-$(CONFIG_WFX) += wfx/ +obj-y += hikey9xx/ diff --git a/drivers/staging/hikey9xx/Kconfig b/drivers/staging/hikey9xx/Kconfig new file mode 100644 index ..31eb01b5ef2b --- /dev/null +++ b/drivers/staging/hikey9xx/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +config SPMI_HISI3670 + tristate "Hisilicon 3670 SPMI Controller" + select IRQ_DOMAIN_HIERARCHY + depends on HAS_IOMEM + help + If you say yes to this option, support will be included for the + built-in SPMI PMIC Arbiter interface on Hisilicon 3670 + processors. diff --git a/drivers/staging/hikey9xx/Makefile b/drivers/staging/hikey9xx/Makefile new file mode 100644 index ..e8085abce444 --- /dev/null +++ b/drivers/staging/hikey9xx/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_SPMI_HISI3670) += hisi-spmi-controller.o -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 04/44] staging: spmi: hisi-spmi-controller: fix a typo
chanel -> channel Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hisi-spmi-controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index bc6847f9a5e7..99cf757d76fe 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -306,7 +306,7 @@ static int spmi_controller_probe(struct platform_device *pdev) ret = of_property_read_u32(pdev->dev.of_node, "spmi-channel", &spmi_controller->channel); if (ret) { - dev_err(&pdev->dev, "can not get chanel\n"); + dev_err(&pdev->dev, "can not get channel\n"); return -ENODEV; } -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 07/44] staging: spmi: hisi-spmi-controller: add debug when values are read/write
It is interesting to be able to check if the driver is doing the right thing. So, add some debug macros to allow checking it. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hisi-spmi-controller.c | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index cacd28150b49..e996114bc717 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -41,7 +41,6 @@ #define SPMI_APB_SPMI_CMD_EN BIT(31) #define SPMI_APB_SPMI_CMD_TYPE_OFFSET 24 #define SPMI_APB_SPMI_CMD_LENGTH_OFFSET20 - #define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 #define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 @@ -135,10 +134,11 @@ static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, } static int spmi_read_cmd(struct spmi_controller *ctrl, -u8 opc, u8 sid, u16 addr, u8 *buf, size_t bc) +u8 opc, u8 sid, u16 addr, u8 *__buf, size_t bc) { struct spmi_controller_dev *spmi_controller = dev_get_drvdata(&ctrl->dev); unsigned long flags; + u8 *buf = __buf; u32 cmd, data; int rc; u32 chnl_ofst = SPMI_CHANNEL_OFFSET * spmi_controller->channel; @@ -197,13 +197,18 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, if (rc) dev_err(spmi_controller->dev, "spmi read wait timeout op:0x%x sid:%d addr:0x%x bc:%ld\n", opc, sid, addr, bc + 1); + else + dev_dbg(spmi_controller->dev, "%s: id:%d addr:0x%x, read value: %*ph\n", + __func__, sid, addr, (int)bc, __buf); + return rc; } static int spmi_write_cmd(struct spmi_controller *ctrl, - u8 opc, u8 sid, u16 addr, const u8 *buf, size_t bc) + u8 opc, u8 sid, u16 addr, const u8 *__buf, size_t bc) { struct spmi_controller_dev *spmi_controller = dev_get_drvdata(&ctrl->dev); + const u8 *buf = __buf; unsigned long flags; u32 cmd, data; int rc; @@ -263,6 +268,9 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, if (rc) dev_err(spmi_controller->dev, "spmi write wait timeout op:0x%x sid:%d addr:0x%x bc:%ld\n", opc, sid, addr, bc); + else + dev_dbg(spmi_controller->dev, "%s: id:%d addr:0x%x, wrote value: %*ph\n", + __func__, sid, addr, (int)bc, __buf); return rc; } @@ -275,6 +283,7 @@ static int spmi_controller_probe(struct platform_device *pdev) int ret = 0; dev_info(&pdev->dev, "HISI SPMI probe\n"); + ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller)); if (!ctrl) { dev_err(&pdev->dev, "can not allocate spmi_controller data\n"); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 35/44] staging: regulator: hi6421v600-regulator: add a driver-specific debug macro
Using dev_dbg() is not too nice, as, instead of printing the name of the regulator, it prints "regulator.", making harder to associate what is happening with each ldo line. So, add a debug-specific macro, which will print the rdev's name, just like the regulator core. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 61 ++- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 31b8ff19fd31..5ddaf7f8cacc 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -39,6 +39,9 @@ #include #include +#define rdev_dbg(rdev, fmt, arg...)\ +pr_debug("%s: %s: " fmt, rdev->desc->name, __func__, ##arg) + struct hi6421v600_regulator { struct regulator_desc rdesc; struct hi6421_spmi_pmic *pmic; @@ -60,10 +63,10 @@ static int hi6421_spmi_regulator_is_enabled(struct regulator_dev *rdev) reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); - dev_dbg(&rdev->dev, - "%s: enable_reg=0x%x, val= 0x%x, enable_state=%d\n", -__func__, rdev->desc->enable_reg, - reg_val, (reg_val & rdev->desc->enable_mask)); + rdev_dbg(rdev, +"enable_reg=0x%x, val= 0x%x, enable_state=%d\n", +rdev->desc->enable_reg, +reg_val, (reg_val & rdev->desc->enable_mask)); return ((reg_val & rdev->desc->enable_mask) != 0); } @@ -73,21 +76,20 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - dev_dbg(&rdev->dev, "%s: off_on_delay=%d us\n", - __func__, rdev->desc->off_on_delay); - /* cannot enable more than one regulator at one time */ mutex_lock(&enable_mutex); usleep_range(HISI_REGS_ENA_PROTECT_TIME, HISI_REGS_ENA_PROTECT_TIME + 1000); /* set enable register */ + rdev_dbg(rdev, +"off_on_delay=%d us, enable_reg=0x%x, enable_mask=0x%x\n", +rdev->desc->off_on_delay, rdev->desc->enable_reg, +rdev->desc->enable_mask); + hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, rdev->desc->enable_mask, rdev->desc->enable_mask); - dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, enable_mask=0x%x\n", -__func__, rdev->desc->enable_reg, -rdev->desc->enable_mask); mutex_unlock(&enable_mutex); @@ -100,6 +102,9 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) struct hi6421_spmi_pmic *pmic = sreg->pmic; /* set enable register to 0 */ + rdev_dbg(rdev, "enable_reg=0x%x, enable_mask=0x%x\n", +rdev->desc->enable_reg, rdev->desc->enable_mask); + hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, rdev->desc->enable_mask, 0); @@ -117,9 +122,9 @@ static int hi6421_spmi_regulator_get_voltage_sel(struct regulator_dev *rdev) selector = (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1); - dev_dbg(&rdev->dev, - "%s: vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n", -__func__, rdev->desc->vsel_reg, reg_val, selector, + rdev_dbg(rdev, + "vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n", +rdev->desc->vsel_reg, reg_val, selector, rdev->desc->ops->list_voltage(rdev, selector) / 1000); return selector; @@ -139,15 +144,14 @@ static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev, reg_val = selector << (ffs(rdev->desc->vsel_mask) - 1); /* set voltage selector */ - hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg, -rdev->desc->vsel_mask, reg_val); - - dev_dbg(&rdev->dev, - "%s: vsel_reg=0x%x, mask=0x%x, value=0x%x, voltage=%d mV\n", -__func__, + rdev_dbg(rdev, + "vsel_reg=0x%x, mask=0x%x, value=0x%x, voltage=%d mV\n", rdev->desc->vsel_reg, rdev->desc->vsel_mask, reg_val, rdev->desc->ops->list_voltage(rdev, selector) / 1000); + hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg, +rdev->desc->vsel_mask, reg_val); + return 0; } @@ -165,9 +169,9 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) else mode = REGULATOR_MODE_NORMAL; - dev_dbg(&rdev->dev, - "%s: enable_reg=0x%x, eco_mode_mask=0x%x, reg_val=0x%x, %s mode\n", -__func__, rdev->desc->enable_reg, sreg->eco_mode_mask, reg_val, +
[PATCH 13/44] staging: mfd: hi6421-spmi-pmic: deal with non-static functions
Several functions aren't used outside the mfd driver. So, either remove or make them static. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 147 1 file changed, 24 insertions(+), 123 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 809381eb6043..8b87d48b88b5 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -73,21 +73,21 @@ u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) u8 read_value = 0; struct spmi_device *pdev; - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); + if (!g_pmic) { + pr_err("%s: g_pmic is NULL\n", __func__); return 0; } pdev = to_spmi_device(g_pmic->dev); - if (NULL == pdev) { - pr_err("%s:pdev get failed!\n", __func__); + if (!pdev) { + pr_err("%s: pdev get failed!\n", __func__); return 0; } ret = spmi_ext_register_readl(pdev, reg, (unsigned char*)&read_value, 1);/*lint !e734 !e732 */ if (ret) { - pr_err("%s:spmi_ext_register_readl failed!\n", __func__); - return ret; + pr_err("%s: spmi_ext_register_readl failed!\n", __func__); + return 0; } return (u32)read_value; } @@ -98,34 +98,32 @@ void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) u32 ret; struct spmi_device *pdev; - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); + if (!g_pmic) { + pr_err("%s: g_pmic is NULL\n", __func__); return; } pdev = to_spmi_device(g_pmic->dev); - if (NULL == pdev) { - pr_err("%s:pdev get failed!\n", __func__); + if (!pdev) { + pr_err("%s: pdev get failed!\n", __func__); return; } ret = spmi_ext_register_writel(pdev, reg, (unsigned char*)&val, 1);/*lint !e734 !e732 */ if (ret) { - pr_err("%s:spmi_ext_register_writel failed!\n", __func__); - return ; + pr_err("%s: spmi_ext_register_writel failed!\n", __func__); + return; } } EXPORT_SYMBOL(hisi_pmic_write); - -void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, -u32 mask, u32 bits) +void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, u32 mask, u32 bits) { u32 data; unsigned long flags; - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); + if (!g_pmic) { + pr_err("%s: g_pmic is NULL\n", __func__); return; } @@ -137,75 +135,6 @@ void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, } EXPORT_SYMBOL(hisi_pmic_rmw); -unsigned int hisi_pmic_reg_read(int addr) -{ - return (unsigned int)hisi_pmic_read(g_pmic, addr); -} -EXPORT_SYMBOL(hisi_pmic_reg_read); - -void hisi_pmic_reg_write(int addr, int val) -{ - hisi_pmic_write(g_pmic, addr, val); -} -EXPORT_SYMBOL(hisi_pmic_reg_write); - -void hisi_pmic_reg_write_lock(int addr, int val) -{ - unsigned long flags; - - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); - return; - } - - spin_lock_irqsave(&g_pmic->lock, flags); - hisi_pmic_write(g_pmic, g_pmic->normal_lock.addr, g_pmic->normal_lock.val); - hisi_pmic_write(g_pmic, g_pmic->debug_lock.addr, g_pmic->debug_lock.val); - hisi_pmic_write(g_pmic, addr, val); - hisi_pmic_write(g_pmic, g_pmic->normal_lock.addr, 0); - hisi_pmic_write(g_pmic, g_pmic->debug_lock.addr, 0); - spin_unlock_irqrestore(&g_pmic->lock, flags); -} - -int hisi_pmic_array_read(int addr, char *buff, unsigned int len) -{ - unsigned int i; - - if ((len > 32) || (NULL == buff)) { - return -EINVAL; - } - - /* -* Here is a bug in the pmu die. -* the coul driver will read 4 bytes, -* but the ssi bus only read 1 byte, and the pmu die -* will make sampling 1/10669us about vol cur,so the driver -* read the data is not the same sampling -*/ - for (i = 0; i < len; i++) - { - *(buff + i) = hisi_pmic_reg_read(addr+i); - } - - return 0; -} - -int hisi_pmic_array_write(int addr, char *buff, unsigned int len) -{ -unsigned int i; - - if ((len > 32) || (NULL == buff)) { - return -EINVAL; - } - - for (i = 0; i < len; i++) - { - hisi_pmic_reg_write(addr+i, *(buff + i)); - } - - return 0; -} - static irqreturn_t hisi_irq_handler(int irq, void *data) { struct hisi_pmic *pmic = (struct hisi_pmic *)data; @@ -213,13 +142,13 @@ static irqreturn_t hisi_irq_handler(int irq, void *data) int i, offset;
[PATCH 03/44] staging: spmi: hisi-spmi-controller: fix it to probe successfully
Add a MODULE_DEVICE_TABLE() to the driver. Also, the current logic calls platform_set_drvdata(pdev, NULL) if the driver succeeds loading. While here, remove the .owner, as it is not needed upstream anymore. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hisi-spmi-controller.c | 11 +++ 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index 3af0bd1b379f..bc6847f9a5e7 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -324,11 +324,14 @@ static int spmi_controller_probe(struct platform_device *pdev) ctrl->write_cmd = spmi_write_cmd; ret = spmi_controller_add(ctrl); - if (ret) { - dev_err(&pdev->dev, "spmi_add_controller failed!\n"); + if (ret) goto err_add_controller; - } + + dev_info(&pdev->dev, "spmi_add_controller initialized\n"); + return 0; + err_add_controller: + dev_err(&pdev->dev, "spmi_add_controller failed!\n"); platform_set_drvdata(pdev, NULL); return ret; } @@ -347,13 +350,13 @@ static const struct of_device_id spmi_controller_match_table[] = { }, {} }; +MODULE_DEVICE_TABLE(of, spmi_controller_match_table); static struct platform_driver spmi_controller_driver = { .probe = spmi_controller_probe, .remove = spmi_del_controller, .driver = { .name = SPMI_CONTROLLER_NAME, - .owner = THIS_MODULE, .of_match_table = spmi_controller_match_table, }, }; -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 21/44] staging: mfd: hi6421-spmi-pmic: add it to the building system
Now that the driver is ready, place it at the build system. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/Kconfig | 17 + drivers/staging/hikey9xx/Makefile | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/staging/hikey9xx/Kconfig b/drivers/staging/hikey9xx/Kconfig index 31eb01b5ef2b..7ca083b7e94d 100644 --- a/drivers/staging/hikey9xx/Kconfig +++ b/drivers/staging/hikey9xx/Kconfig @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +# to be placed at drivers/spmi config SPMI_HISI3670 tristate "Hisilicon 3670 SPMI Controller" select IRQ_DOMAIN_HIERARCHY @@ -8,3 +9,19 @@ config SPMI_HISI3670 If you say yes to this option, support will be included for the built-in SPMI PMIC Arbiter interface on Hisilicon 3670 processors. + +# to be placed at drivers/mfd +config MFD_HI6421_SPMI + tristate "HiSilicon Hi6421v600 SPMI PMU/Codec IC" + depends on OF + select MFD_CORE + select REGMAP_MMIO + help + Add support for HiSilicon Hi6421v600 SPMI PMIC. Hi6421 includes + multi-functions, such as regulators, RTC, codec, Coulomb counter, + etc. + + This driver includes core APIs _only_. You have to select + individual components like voltage regulators under corresponding + menus in order to enable them. + We communicate with the Hi6421v600 via a SPMI bus. diff --git a/drivers/staging/hikey9xx/Makefile b/drivers/staging/hikey9xx/Makefile index e8085abce444..79de37da7a8f 100644 --- a/drivers/staging/hikey9xx/Makefile +++ b/drivers/staging/hikey9xx/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_SPMI_HISI3670) += hisi-spmi-controller.o +obj-$(CONFIG_SPMI_HISI3670)+= hisi-spmi-controller.o +obj-$(CONFIG_MFD_HI6421_SPMI) += hi6421-spmi-pmic.o -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 08/44] staging: spmi: hisi-spmi-controller: fix the dev_foo() logic
Right now, driver is printing some messages as: [ 33.833026] (NULL device *): spmi_read_cmd: id:0 addr:0x17, read value: 00 This is because dev_foo() are not using a device with a name set. Change the logic for it to print it right. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hisi-spmi-controller.c | 41 ++- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index e996114bc717..153bcdb0cde4 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -102,7 +102,8 @@ struct spmi_controller_dev { u32 channel; }; -static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, +static int spmi_controller_wait_for_done(struct device *dev, +struct spmi_controller_dev *ctrl_dev, void __iomem *base, u8 sid, u16 addr) { u32 status = 0; @@ -117,19 +118,17 @@ static int spmi_controller_wait_for_done(struct spmi_controller_dev *ctrl_dev, if (status & SPMI_APB_TRANS_DONE) { if (status & SPMI_APB_TRANS_FAIL) { - dev_err(ctrl_dev->dev, - "%s: transaction failed (0x%x)\n", + dev_err(dev, "%s: transaction failed (0x%x)\n", __func__, status); return -EIO; } + dev_dbg(dev, "%s: status 0x%x\n", __func__, status); return 0; } udelay(1); } - dev_err(ctrl_dev->dev, - "%s: timeout, status 0x%x\n", - __func__, status); + dev_err(dev, "%s: timeout, status 0x%x\n", __func__, status); return -ETIMEDOUT; } @@ -145,9 +144,9 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 op_code, i; if (bc > SPMI_CONTROLLER_MAX_TRANS_BYTES) { - dev_err(spmi_controller->dev - , "spmi_controller supports 1..%d bytes per trans, but:%ld requested" - , SPMI_CONTROLLER_MAX_TRANS_BYTES, bc); + dev_err(&ctrl->dev, + "spmi_controller supports 1..%d bytes per trans, but:%ld requested", + SPMI_CONTROLLER_MAX_TRANS_BYTES, bc); return -EINVAL; } @@ -159,7 +158,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, } else if (opc == SPMI_CMD_EXT_READL) { op_code = SPMI_CMD_EXT_REG_READ_L; } else { - dev_err(spmi_controller->dev, "invalid read cmd 0x%x", opc); + dev_err(&ctrl->dev, "invalid read cmd 0x%x", opc); return -EINVAL; } @@ -173,7 +172,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, writel(cmd, spmi_controller->base + chnl_ofst + SPMI_APB_SPMI_CMD_BASE_ADDR); - rc = spmi_controller_wait_for_done(spmi_controller, + rc = spmi_controller_wait_for_done(&ctrl->dev, spmi_controller, spmi_controller->base, sid, addr); if (rc) goto done; @@ -195,10 +194,11 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, done: spin_unlock_irqrestore(&spmi_controller->lock, flags); if (rc) - dev_err(spmi_controller->dev, "spmi read wait timeout op:0x%x sid:%d addr:0x%x bc:%ld\n", + dev_err(&ctrl->dev, + "spmi read wait timeout op:0x%x sid:%d addr:0x%x bc:%ld\n", opc, sid, addr, bc + 1); else - dev_dbg(spmi_controller->dev, "%s: id:%d addr:0x%x, read value: %*ph\n", + dev_dbg(&ctrl->dev, "%s: id:%d addr:0x%x, read value: %*ph\n", __func__, sid, addr, (int)bc, __buf); return rc; @@ -216,9 +216,9 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 op_code, i; if (bc > SPMI_CONTROLLER_MAX_TRANS_BYTES) { - dev_err(spmi_controller->dev - , "spmi_controller supports 1..%d bytes per trans, but:%ld requested" - , SPMI_CONTROLLER_MAX_TRANS_BYTES, bc); + dev_err(&ctrl->dev, + "spmi_controller supports 1..%d bytes per trans, but:%ld requested", + SPMI_CONTROLLER_MAX_TRANS_BYTES, bc); return -EINVAL; } @@ -230,7 +230,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, } else if (opc == SPMI_CMD_EXT_WRITEL) { op_code = SPMI_CMD_EXT_REG_WRITE_L; } else { - dev_err(spmi_controller->dev, "invalid write cmd
[PATCH 28/44] staging: regulator: hi6421v600-regulator: cleanup struct hisi_regulator
There are several fields on this struct that can be removed, as they already exists at struct regulator_desc. Remove them, cleaning up the code in the process. While here, rename it to hi6421v600_regulator_info, in order to better match the driver's name. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 226 +++--- 1 file changed, 92 insertions(+), 134 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 9aaafcbb1a36..7d82d11f4b52 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -39,21 +39,11 @@ #include #include -struct hisi_regulator_register_info { - u32 ctrl_reg; - u32 enable_mask; - u32 eco_mode_mask; - u32 vset_reg; - u32 vset_mask; -}; - -struct hisi_regulator { - const char *name; - struct hisi_regulator_register_info register_info; - u32 off_on_delay; - u32 eco_uA; +struct hi6421v600_regulator { struct regulator_desc rdesc; struct hisi_pmic *pmic; + u8 eco_mode_mask; + u32 eco_uA; }; static DEFINE_MUTEX(enable_mutex); @@ -62,29 +52,29 @@ static DEFINE_MUTEX(enable_mutex); * microseconds after 'since'. */ -static int hisi_regulator_is_enabled(struct regulator_dev *dev) +static int hisi_regulator_is_enabled(struct regulator_dev *rdev) { u32 reg_val; - struct hisi_regulator *sreg = rdev_get_drvdata(dev); + struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; - reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); - pr_debug("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", -__func__, sreg->register_info.ctrl_reg, - (reg_val & sreg->register_info.enable_mask)); + reg_val = hisi_pmic_read(pmic, rdev->desc->enable_reg); + pr_debug("<[%s]: enable_reg=0x%x,enable_state=%d>\n", +__func__, rdev->desc->enable_reg, + (reg_val & rdev->desc->enable_mask)); - return ((reg_val & sreg->register_info.enable_mask) != 0); + return ((reg_val & rdev->desc->enable_mask) != 0); } -static int hisi_regulator_enable(struct regulator_dev *dev) +static int hisi_regulator_enable(struct regulator_dev *rdev) { - struct hisi_regulator *sreg = rdev_get_drvdata(dev); + struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; /* keep a distance of off_on_delay from last time disabled */ - usleep_range(sreg->off_on_delay, sreg->off_on_delay + 1000); + usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 1000); - pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay); + pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, rdev->desc->off_on_delay); /* cannot enable more than one regulator at one time */ mutex_lock(&enable_mutex); @@ -92,103 +82,103 @@ static int hisi_regulator_enable(struct regulator_dev *dev) HISI_REGS_ENA_PROTECT_TIME + 1000); /* set enable register */ - hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, - sreg->register_info.enable_mask, - sreg->register_info.enable_mask); - pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", -__func__, sreg->register_info.ctrl_reg, -sreg->register_info.enable_mask); + hisi_pmic_rmw(pmic, rdev->desc->enable_reg, + rdev->desc->enable_mask, + rdev->desc->enable_mask); + pr_debug("<[%s]: enable_reg=0x%x,enable_mask=0x%x>\n", +__func__, rdev->desc->enable_reg, +rdev->desc->enable_mask); mutex_unlock(&enable_mutex); return 0; } -static int hisi_regulator_disable(struct regulator_dev *dev) +static int hisi_regulator_disable(struct regulator_dev *rdev) { - struct hisi_regulator *sreg = rdev_get_drvdata(dev); + struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; /* set enable register to 0 */ - hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, - sreg->register_info.enable_mask, 0); + hisi_pmic_rmw(pmic, rdev->desc->enable_reg, + rdev->desc->enable_mask, 0); return 0; } -static int hisi_regulator_get_voltage(struct regulator_dev *dev) +static int hisi_regulator_get_voltage(struct regulator_dev *rdev) { - struct hisi_regulator *sreg = rdev_get_drvdata(dev); + struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; u32 reg_val, selector; /* get voltage selector */ - reg_val = hisi_pmic_read(pmic, sreg->register_info.vset_r
[PATCH 33/44] staging: regulator: hi6421v600-regulator: convert to use get/set voltage_sel
As the supported LDOs on this driver are all using a selector, change the implementation to use get_voltage_sel and set_voltage_sel ops. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 58 +++ 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index f77ecea78597..abd1f43dd5ec 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -86,8 +86,8 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) /* set enable register */ hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, - rdev->desc->enable_mask, - rdev->desc->enable_mask); +rdev->desc->enable_mask, +rdev->desc->enable_mask); dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, enable_mask=0x%x\n", __func__, rdev->desc->enable_reg, rdev->desc->enable_mask); @@ -109,64 +109,49 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) return 0; } -static int hi6421_spmi_regulator_get_voltage(struct regulator_dev *rdev) +static int hi6421_spmi_regulator_get_voltage_sel(struct regulator_dev *rdev) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val, selector; - int vol; /* get voltage selector */ reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->vsel_reg); - selector = (reg_val & rdev->desc->vsel_mask) >> - (ffs(rdev->desc->vsel_mask) - 1); - vol = rdev->desc->ops->list_voltage(rdev, selector); + selector = (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1); dev_dbg(&rdev->dev, - "%s: vsel_reg=0x%x, val=0x%x, entry=0x%x, voltage=%d mV\n", -__func__, rdev->desc->vsel_reg, reg_val, selector, vol/ 1000); + "%s: vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n", +__func__, rdev->desc->vsel_reg, reg_val, selector, + rdev->desc->ops->list_voltage(rdev, selector) / 1000); - return vol; + return selector; } -static int hi6421_spmi_regulator_set_voltage(struct regulator_dev *rdev, - int min_uV, int max_uV, unsigned int *selector) +static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev, +unsigned int selector) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - u32 vsel; - int uV, ret = 0; - - for (vsel = 0; vsel < rdev->desc->n_voltages; vsel++) { - uV = rdev->desc->volt_table[vsel]; - dev_dbg(&rdev->dev, - "%s: min %d, max %d, value[%u] = %d\n", - __func__, min_uV, max_uV, vsel, uV); - - /* Break at the first in-range value */ - if (min_uV <= uV && uV <= max_uV) - break; - } + u32 reg_val; /* unlikely to happen. sanity test done by regulator core */ - if (unlikely(vsel == rdev->desc->n_voltages)) + if (unlikely(selector >= rdev->desc->n_voltages)) return -EINVAL; - *selector = vsel; + reg_val = selector << (ffs(rdev->desc->vsel_mask) - 1); + /* set voltage selector */ hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg, - rdev->desc->vsel_mask, - vsel << (ffs(rdev->desc->vsel_mask) - 1)); +rdev->desc->vsel_mask, reg_val); dev_dbg(&rdev->dev, - "%s: vsel_reg=0x%x, vsel_mask=0x%x, value=0x%x, voltage=%d mV\n", + "%s: vsel_reg=0x%x, mask=0x%x, value=0x%x, voltage=%d mV\n", __func__, -rdev->desc->vsel_reg, -rdev->desc->vsel_mask, -vsel << (ffs(rdev->desc->vsel_mask) - 1), uV / 1000); +rdev->desc->vsel_reg, rdev->desc->vsel_mask, reg_val, +rdev->desc->ops->list_voltage(rdev, selector) / 1000); - return ret; + return 0; } static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) @@ -315,8 +300,9 @@ static struct regulator_ops hi6421_spmi_ldo_rops = { .enable = hi6421_spmi_regulator_enable, .disable = hi6421_spmi_regulator_disable, .list_voltage = regulator_list_voltage_table, - .get_voltage = hi6421_spmi_regulator_get_voltage, - .set_voltage = hi6421_spmi_regulator_set_voltage, + .map_voltage = regulator_map_voltage_iterate, + .get_voltage_sel = hi6421_spmi_regulator_get_voltage_sel, +
[PATCH 34/44] staging: regulator: hi6421v600-regulator: don't use usleep_range for off_on_delay
The regulator's core already handles it. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421v600-regulator.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index abd1f43dd5ec..31b8ff19fd31 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -73,9 +73,6 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - /* keep a distance of off_on_delay from last time disabled */ - usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 1000); - dev_dbg(&rdev->dev, "%s: off_on_delay=%d us\n", __func__, rdev->desc->off_on_delay); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 32/44] staging: regulator: hi6421v600-regulator: change namespace
Rename the functions used internally inside the driver in order for them to follow the driver's name. While here, get rid of some unused definitions at the header file. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 94 +-- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index bde7fa4d7e8f..f77ecea78597 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -41,7 +41,7 @@ struct hi6421v600_regulator { struct regulator_desc rdesc; - struct hisi_pmic *pmic; + struct hi6421_spmi_pmic *pmic; u8 eco_mode_mask; u32 eco_uA; }; @@ -52,13 +52,13 @@ static DEFINE_MUTEX(enable_mutex); * microseconds after 'since'. */ -static int hisi_regulator_is_enabled(struct regulator_dev *rdev) +static int hi6421_spmi_regulator_is_enabled(struct regulator_dev *rdev) { u32 reg_val; struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - struct hisi_pmic *pmic = sreg->pmic; + struct hi6421_spmi_pmic *pmic = sreg->pmic; - reg_val = hisi_pmic_read(pmic, rdev->desc->enable_reg); + reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, val= 0x%x, enable_state=%d\n", @@ -68,10 +68,10 @@ static int hisi_regulator_is_enabled(struct regulator_dev *rdev) return ((reg_val & rdev->desc->enable_mask) != 0); } -static int hisi_regulator_enable(struct regulator_dev *rdev) +static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - struct hisi_pmic *pmic = sreg->pmic; + struct hi6421_spmi_pmic *pmic = sreg->pmic; /* keep a distance of off_on_delay from last time disabled */ usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 1000); @@ -85,7 +85,7 @@ static int hisi_regulator_enable(struct regulator_dev *rdev) HISI_REGS_ENA_PROTECT_TIME + 1000); /* set enable register */ - hisi_pmic_rmw(pmic, rdev->desc->enable_reg, + hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, rdev->desc->enable_mask, rdev->desc->enable_mask); dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, enable_mask=0x%x\n", @@ -97,27 +97,27 @@ static int hisi_regulator_enable(struct regulator_dev *rdev) return 0; } -static int hisi_regulator_disable(struct regulator_dev *rdev) +static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - struct hisi_pmic *pmic = sreg->pmic; + struct hi6421_spmi_pmic *pmic = sreg->pmic; /* set enable register to 0 */ - hisi_pmic_rmw(pmic, rdev->desc->enable_reg, + hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, rdev->desc->enable_mask, 0); return 0; } -static int hisi_regulator_get_voltage(struct regulator_dev *rdev) +static int hi6421_spmi_regulator_get_voltage(struct regulator_dev *rdev) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - struct hisi_pmic *pmic = sreg->pmic; + struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val, selector; int vol; /* get voltage selector */ - reg_val = hisi_pmic_read(pmic, rdev->desc->vsel_reg); + reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->vsel_reg); selector = (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1); @@ -130,11 +130,11 @@ static int hisi_regulator_get_voltage(struct regulator_dev *rdev) return vol; } -static int hisi_regulator_set_voltage(struct regulator_dev *rdev, +static int hi6421_spmi_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, unsigned int *selector) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - struct hisi_pmic *pmic = sreg->pmic; + struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 vsel; int uV, ret = 0; @@ -155,7 +155,7 @@ static int hisi_regulator_set_voltage(struct regulator_dev *rdev, *selector = vsel; /* set voltage selector */ - hisi_pmic_rmw(pmic, rdev->desc->vsel_reg, + hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg, rdev->desc->vsel_mask, vsel << (ffs(rdev->desc->vsel_mask) - 1)); @@ -169,14 +169,14 @@ static int hisi_regulator_set_voltage(struct regulator_dev *rdev, return ret; } -static unsigned int hisi_regulator_get_mode(struct regulator_dev *rdev) +static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev)
[PATCH 29/44] staging: regulator: hi6421v600-regulator: cleanup debug messages
- use dev_foo() instead of pr_foo(); - cleanup the messages, making them more standard and easier to understand. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 76 --- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 7d82d11f4b52..2d1096ecb277 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -59,9 +59,11 @@ static int hisi_regulator_is_enabled(struct regulator_dev *rdev) struct hisi_pmic *pmic = sreg->pmic; reg_val = hisi_pmic_read(pmic, rdev->desc->enable_reg); - pr_debug("<[%s]: enable_reg=0x%x,enable_state=%d>\n", + + dev_dbg(&rdev->dev, + "%s: enable_reg=0x%x, val= 0x%x, enable_state=%d\n", __func__, rdev->desc->enable_reg, - (reg_val & rdev->desc->enable_mask)); + reg_val, (reg_val & rdev->desc->enable_mask)); return ((reg_val & rdev->desc->enable_mask) != 0); } @@ -74,7 +76,8 @@ static int hisi_regulator_enable(struct regulator_dev *rdev) /* keep a distance of off_on_delay from last time disabled */ usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 1000); - pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, rdev->desc->off_on_delay); + dev_dbg(&rdev->dev, "%s: off_on_delay=%d us\n", + __func__, rdev->desc->off_on_delay); /* cannot enable more than one regulator at one time */ mutex_lock(&enable_mutex); @@ -85,7 +88,7 @@ static int hisi_regulator_enable(struct regulator_dev *rdev) hisi_pmic_rmw(pmic, rdev->desc->enable_reg, rdev->desc->enable_mask, rdev->desc->enable_mask); - pr_debug("<[%s]: enable_reg=0x%x,enable_mask=0x%x>\n", + dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, enable_mask=0x%x\n", __func__, rdev->desc->enable_reg, rdev->desc->enable_mask); @@ -111,16 +114,20 @@ static int hisi_regulator_get_voltage(struct regulator_dev *rdev) struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; u32 reg_val, selector; + int vol; /* get voltage selector */ reg_val = hisi_pmic_read(pmic, rdev->desc->vsel_reg); - pr_debug("<[%s]: vsel_reg=0x%x>\n", -__func__, rdev->desc->vsel_reg); - selector = (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1); - return rdev->desc->ops->list_voltage(rdev, selector); + vol = rdev->desc->ops->list_voltage(rdev, selector); + + dev_dbg(&rdev->dev, + "%s: vsel_reg=0x%x, val=0x%x, entry=0x%x, voltage=%d mV\n", +__func__, rdev->desc->vsel_reg, reg_val, selector, vol/ 1000); + + return vol; } static int hisi_regulator_set_voltage(struct regulator_dev *rdev, @@ -129,10 +136,14 @@ static int hisi_regulator_set_voltage(struct regulator_dev *rdev, struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; u32 vsel; - int ret = 0; + int uV, ret = 0; for (vsel = 0; vsel < rdev->desc->n_voltages; vsel++) { - int uV = rdev->desc->volt_table[vsel]; + uV = rdev->desc->volt_table[vsel]; + dev_dbg(&rdev->dev, + "%s: min %d, max %d, value[%u] = %d\n", + __func__, min_uV, max_uV, vsel, uV); + /* Break at the first in-range value */ if (min_uV <= uV && uV <= max_uV) break; @@ -146,13 +157,14 @@ static int hisi_regulator_set_voltage(struct regulator_dev *rdev, /* set voltage selector */ hisi_pmic_rmw(pmic, rdev->desc->vsel_reg, rdev->desc->vsel_mask, - vsel << (ffs(rdev->desc->vsel_mask) - 1)); + vsel << (ffs(rdev->desc->vsel_mask) - 1)); - pr_debug("<[%s]: vsel_reg=0x%x, vsel_mask=0x%x, value=0x%x>\n", + dev_dbg(&rdev->dev, + "%s: vsel_reg=0x%x, vsel_mask=0x%x, value=0x%x, voltage=%d mV\n", __func__, rdev->desc->vsel_reg, rdev->desc->vsel_mask, -vsel << (ffs(rdev->desc->vsel_mask) - 1)); +vsel << (ffs(rdev->desc->vsel_mask) - 1), uV / 1000); return ret; } @@ -162,17 +174,21 @@ static unsigned int hisi_regulator_get_mode(struct regulator_dev *rdev) struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; u32 reg_val; + unsigned int mode; reg_val = hisi_pmic_read(pmic, rdev->desc->enable_reg); - pr_debug("<[%s]: reg_val=%d, enable_reg=0x%x
[PATCH 16/44] staging: mfd: hi6421-spmi-pmic: change the binding logic
Change the binding logic to ensure that the MFD driver will be load after having the SPMI controller registered. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 84 +++-- 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index be42fed16bd2..939f7bd5d8ba 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -24,13 +24,14 @@ #include #include #include +#include #include #include #include #include #include #include -#include +#include #include #include #ifndef NO_IRQ @@ -53,11 +54,8 @@ /*define the first group interrupt register number*/ #define HISI_PMIC_FIRST_GROUP_INT_NUM2 -static const struct of_device_id of_hisi_pmic_match_tbl[] = { - { - .compatible = "hisilicon-hisi-pmic-spmi", - }, - { /* end */ } +static const struct mfd_cell hi6421v600_devs[] = { + { .name = "hi6421v600-regulator", }, }; /* @@ -477,6 +475,22 @@ static int hisi_pmic_probe(struct spmi_device *pdev) goto request_theaded_irq; } + dev_set_drvdata(&pdev->dev, pmic); + + /* +* The logic below will rely that the pmic is already stored at +* drvdata. +*/ + dev_dbg(&pdev->dev, "SPMI-PMIC: adding childs for %pOF\n", + pdev->dev.of_node); + ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, + hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs), + NULL, 0, NULL); + if (ret) { + dev_err(&pdev->dev, "Failed to add child devices: %d\n", ret); + return ret; + } + after_irq_register: return 0; @@ -497,61 +511,21 @@ static void hisi_pmic_remove(struct spmi_device *pdev) devm_kfree(&pdev->dev, pmic); } -static int hisi_pmic_suspend(struct device *dev, pm_message_t state) -{ - struct hisi_pmic *pmic = dev_get_drvdata(dev); +static const struct of_device_id pmic_spmi_id_table[] = { + { .compatible = "hisilicon,hi6421-spmi-pmic" }, + { } +}; +MODULE_DEVICE_TABLE(of, pmic_spmi_id_table); - if (!pmic) { - pr_err("%s:pmic is NULL\n", __func__); - return -ENOMEM; - } - - pr_info("%s:+\n", __func__); - pr_info("%s:-\n", __func__); - - return 0; -} - -static int hisi_pmic_resume(struct device *dev) -{ - struct hisi_pmic *pmic = dev_get_drvdata(dev); - - if (!pmic) { - pr_err("%s:pmic is NULL\n", __func__); - return -ENOMEM; - } - - pr_info("%s:+\n", __func__); - pr_info("%s:-\n", __func__); - - return 0; -} - -MODULE_DEVICE_TABLE(spmi, pmic_spmi_id); static struct spmi_driver hisi_pmic_driver = { .driver = { - .name = "hisi_pmic", - .owner = THIS_MODULE, - .of_match_table = of_hisi_pmic_match_tbl, - .suspend = hisi_pmic_suspend, - .resume = hisi_pmic_resume, + .name = "hi6421-spmi-pmic", + .of_match_table = pmic_spmi_id_table, }, .probe = hisi_pmic_probe, .remove = hisi_pmic_remove, }; +module_spmi_driver(hisi_pmic_driver); -static int __init hisi_pmic_init(void) -{ - return spmi_driver_register(&hisi_pmic_driver); -} - -static void __exit hisi_pmic_exit(void) -{ - spmi_driver_unregister(&hisi_pmic_driver); -} - -subsys_initcall_sync(hisi_pmic_init); -module_exit(hisi_pmic_exit); - -MODULE_DESCRIPTION("PMIC driver"); +MODULE_DESCRIPTION("HiSilicon Hi6421v600 SPMI PMIC driver"); MODULE_LICENSE("GPL v2"); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 30/44] staging: regulator: hi6421v600-regulator: use shorter names for OF properties
Simplify the names of the OF properties, in order to make them similar to other drivers and to make easier to understand what each property means. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 52 --- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 2d1096ecb277..e4a64893a7ad 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -196,14 +196,14 @@ static int hisi_regulator_set_mode(struct regulator_dev *rdev, { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hisi_pmic *pmic = sreg->pmic; - u32 eco_mode; + u32 val; switch (mode) { case REGULATOR_MODE_NORMAL: - eco_mode = HISI_ECO_MODE_DISABLE; + val = 0; break; case REGULATOR_MODE_IDLE: - eco_mode = HISI_ECO_MODE_ENABLE; + val = sreg->eco_mode_mask << (ffs(sreg->eco_mode_mask) - 1); break; default: return -EINVAL; @@ -211,15 +211,12 @@ static int hisi_regulator_set_mode(struct regulator_dev *rdev, /* set mode */ hisi_pmic_rmw(pmic, rdev->desc->enable_reg, - sreg->eco_mode_mask, - eco_mode << (ffs(sreg->eco_mode_mask) - 1)); + sreg->eco_mode_mask, val); dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, eco_mode_mask=0x%x, value=0x%x\n", -__func__, - rdev->desc->enable_reg, - sreg->eco_mode_mask, - eco_mode << (ffs(sreg->eco_mode_mask) - 1)); +__func__, rdev->desc->enable_reg, sreg->eco_mode_mask, val); + return 0; } @@ -249,10 +246,10 @@ static int hisi_dt_parse(struct platform_device *pdev, int ret; /* parse .register_info.enable_reg */ - ret = of_property_read_u32_array(np, "hisilicon,hisi-ctrl", + ret = of_property_read_u32_array(np, "hi6421-ctrl", register_info, 3); if (ret) { - dev_err(dev, "no hisilicon,hisi-ctrl property set\n"); + dev_err(dev, "no hi6421-ctrl property set\n"); return ret; } rdesc->enable_reg = register_info[0]; @@ -260,33 +257,33 @@ static int hisi_dt_parse(struct platform_device *pdev, sreg->eco_mode_mask = register_info[2]; /* parse .register_info.vsel_reg */ - ret = of_property_read_u32_array(np, "hisilicon,hisi-vset", + ret = of_property_read_u32_array(np, "hi6421-vsel", register_info, 2); if (ret) { - dev_err(dev, "no hisilicon,hisi-vset property set\n"); + dev_err(dev, "no hi6421-vsel property set\n"); return ret; } rdesc->vsel_reg = register_info[0]; rdesc->vsel_mask = register_info[1]; /* parse .off-on-delay */ - ret = of_property_read_u32(np, "hisilicon,hisi-off-on-delay-us", + ret = of_property_read_u32(np, "off-on-delay-us", &rdesc->off_on_delay); if (ret) { - dev_err(dev, "no hisilicon,hisi-off-on-delay-us property set\n"); + dev_err(dev, "no off-on-delay-us property set\n"); return ret; } /* parse .enable_time */ - ret = of_property_read_u32(np, "hisilicon,hisi-enable-time-us", + ret = of_property_read_u32(np, "startup-delay-us", &rdesc->enable_time); if (ret) { - dev_err(dev, "no hisilicon,hisi-enable-time-us property set\n"); + dev_err(dev, "no startup-delay-us property set\n"); return ret; } /* parse .eco_uA */ - ret = of_property_read_u32(np, "hisilicon,hisi-eco-microamp", + ret = of_property_read_u32(np, "eco-microamp", &sreg->eco_uA); if (ret) { sreg->eco_uA = 0; @@ -295,7 +292,7 @@ static int hisi_dt_parse(struct platform_device *pdev, /* parse volt_table */ - rdesc->n_voltages = of_property_count_u32_elems(np, "hisilicon,hisi-vset-table"); + rdesc->n_voltages = of_property_count_u32_elems(np, "voltage-table"); v_table = devm_kzalloc(dev, sizeof(unsigned int) * rdesc->n_voltages, GFP_KERNEL); @@ -303,10 +300,10 @@ static int hisi_dt_parse(struct platform_device *pdev, return -ENOMEM; rdesc->volt_table = v_table; - ret = of_property_read_u32_array(np, "hisilicon,hisi-vset-table", + ret = of_property_read_u32_array(np, "voltage-table", v_table, rdesc->n_voltages); if (ret) { -
[PATCH 39/44] staging: regulator: hi6421v600-regulator: add it to the building system
Change the binding logic to ensure that the PMIC SPMI driver will run before the regulator code and add it to the building system. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/Kconfig | 10 +- drivers/staging/hikey9xx/Makefile | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/staging/hikey9xx/Kconfig b/drivers/staging/hikey9xx/Kconfig index 7ca083b7e94d..76267b9be562 100644 --- a/drivers/staging/hikey9xx/Kconfig +++ b/drivers/staging/hikey9xx/Kconfig @@ -15,7 +15,6 @@ config MFD_HI6421_SPMI tristate "HiSilicon Hi6421v600 SPMI PMU/Codec IC" depends on OF select MFD_CORE - select REGMAP_MMIO help Add support for HiSilicon Hi6421v600 SPMI PMIC. Hi6421 includes multi-functions, such as regulators, RTC, codec, Coulomb counter, @@ -25,3 +24,12 @@ config MFD_HI6421_SPMI individual components like voltage regulators under corresponding menus in order to enable them. We communicate with the Hi6421v600 via a SPMI bus. + +# to be placed at drivers/regulator +config REGULATOR_HI6421V600 + tristate "HiSilicon Hi6421v600 PMIC voltage regulator support" + depends on MFD_HI6421_PMIC && OF + help + This driver provides support for the voltage regulators on + HiSilicon Hi6421v600 PMU / Codec IC. + This is used on Kirin 3670 boards, like HiKey 970. diff --git a/drivers/staging/hikey9xx/Makefile b/drivers/staging/hikey9xx/Makefile index 79de37da7a8f..9371dcc3d35b 100644 --- a/drivers/staging/hikey9xx/Makefile +++ b/drivers/staging/hikey9xx/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_SPMI_HISI3670)+= hisi-spmi-controller.o -obj-$(CONFIG_MFD_HI6421_SPMI) += hi6421-spmi-pmic.o +obj-$(CONFIG_SPMI_HISI3670)+= hisi-spmi-controller.o +obj-$(CONFIG_MFD_HI6421_SPMI) += hi6421-spmi-pmic.o +obj-$(CONFIG_REGULATOR_HI6421V600) += hi6421v600-regulator.o -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 26/44] staging: regulator: hi6421v600-regulator: coding style fixups
There are several issues on those drivers related to their coding style. Solve most of them. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 110 +- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 904cb64b1dcd..5f6e4ba4b99e 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Device driver for regulators in Hisi IC * @@ -52,7 +53,7 @@ struct hisi_regulator { u32 off_on_delay; u32 eco_uA; struct regulator_desc rdesc; - int (*dt_parse)(struct hisi_regulator *, struct spmi_device *); + int (*dt_parse)(struct hisi_regulator *reg, struct spmi_device *spmi); }; static DEFINE_MUTEX(enable_mutex); @@ -77,8 +78,9 @@ static int hisi_regulator_is_enabled(struct regulator_dev *dev) struct hisi_pmic *pmic = rdev_to_pmic(dev); reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); - pr_debug("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", __func__, sreg->register_info.ctrl_reg,\ - (reg_val & sreg->register_info.enable_mask)); + pr_debug("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", +__func__, sreg->register_info.ctrl_reg, + (reg_val & sreg->register_info.enable_mask)); return ((reg_val & sreg->register_info.enable_mask) != 0); } @@ -98,14 +100,13 @@ static int hisi_regulator_enable(struct regulator_dev *dev) usleep_range(HISI_REGS_ENA_PROTECT_TIME, HISI_REGS_ENA_PROTECT_TIME + 1000); - - /* set enable register */ hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, - sreg->register_info.enable_mask, + sreg->register_info.enable_mask, sreg->register_info.enable_mask); - pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\ - sreg->register_info.enable_mask); + pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", +__func__, sreg->register_info.ctrl_reg, +sreg->register_info.enable_mask); mutex_unlock(&enable_mutex); @@ -119,7 +120,7 @@ static int hisi_regulator_disable(struct regulator_dev *dev) /* set enable register to 0 */ hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, - sreg->register_info.enable_mask, 0); + sreg->register_info.enable_mask, 0); return 0; } @@ -132,7 +133,8 @@ static int hisi_regulator_get_voltage(struct regulator_dev *dev) /* get voltage selector */ reg_val = hisi_pmic_read(pmic, sreg->register_info.vset_reg); - pr_debug("<[%s]: vset_reg=0x%x>\n", __func__, sreg->register_info.vset_reg); + pr_debug("<[%s]: vset_reg=0x%x>\n", +__func__, sreg->register_info.vset_reg); selector = (reg_val & sreg->register_info.vset_mask) >> (ffs(sreg->register_info.vset_mask) - 1); @@ -141,7 +143,7 @@ static int hisi_regulator_get_voltage(struct regulator_dev *dev) } static int hisi_regulator_set_voltage(struct regulator_dev *dev, - int min_uV, int max_uV, unsigned *selector) + int min_uV, int max_uV, unsigned int *selector) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); struct hisi_pmic *pmic = rdev_to_pmic(dev); @@ -162,14 +164,14 @@ static int hisi_regulator_set_voltage(struct regulator_dev *dev, *selector = vsel; /* set voltage selector */ hisi_pmic_rmw(pmic, sreg->register_info.vset_reg, - sreg->register_info.vset_mask, + sreg->register_info.vset_mask, vsel << (ffs(sreg->register_info.vset_mask) - 1)); - pr_debug("<[%s]: vset_reg=0x%x, vset_mask=0x%x, value=0x%x>\n", __func__,\ - sreg->register_info.vset_reg,\ - sreg->register_info.vset_mask,\ - vsel << (ffs(sreg->register_info.vset_mask) - 1)\ - ); + pr_debug("<[%s]: vset_reg=0x%x, vset_mask=0x%x, value=0x%x>\n", +__func__, +sreg->register_info.vset_reg, +sreg->register_info.vset_mask, +vsel << (ffs(sreg->register_info.vset_mask) - 1)); return ret; } @@ -181,10 +183,10 @@ static unsigned int hisi_regulator_get_mode(struct regulator_dev *dev) u32 reg_val; reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); - pr_debug("<[%s]: reg_val=%d, ctrl_reg=0x%x, eco_mode_mask=0x%x>\n", __func__, reg_val,\ - sreg->register_info.ctrl_reg,
[PATCH 01/44] staging: spmi: add Hikey 970 SPMI controller driver
From: Mayulong Add the SPMI controller code required to use the Kirin 970 SPMI bus. [mchehab+hua...@kernel.org: added just the SPMI controller on this patch] The complete patch is at: https://github.com/96boards-hikey/linux/commit/08464419fba2 Signed-off-by: Mayulong Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hisi-spmi-controller.c | 390 ++ 1 file changed, 390 insertions(+) create mode 100644 drivers/staging/hikey9xx/hisi-spmi-controller.c diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c new file mode 100644 index ..987526c8b49f --- /dev/null +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -0,0 +1,390 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPMI_CONTROLLER_NAME "spmi_controller" + +/* + * SPMI register addr + */ +#define SPMI_CHANNEL_OFFSET0x0300 +#define SPMI_SLAVE_OFFSET 0x20 + +#define SPMI_APB_SPMI_CMD_BASE_ADDR0x0100 +/*lint -e750 -esym(750,*)*/ +#define SPMI_APB_SPMI_WDATA0_BASE_ADDR 0x0104 +#define SPMI_APB_SPMI_WDATA1_BASE_ADDR 0x0108 +#define SPMI_APB_SPMI_WDATA2_BASE_ADDR 0x010c +#define SPMI_APB_SPMI_WDATA3_BASE_ADDR 0x0110 + +#define SPMI_APB_SPMI_STATUS_BASE_ADDR 0x0200 + +#define SPMI_APB_SPMI_RDATA0_BASE_ADDR 0x0204 +#define SPMI_APB_SPMI_RDATA1_BASE_ADDR 0x0208 +#define SPMI_APB_SPMI_RDATA2_BASE_ADDR 0x020c +#define SPMI_APB_SPMI_RDATA3_BASE_ADDR 0x0210 +/*lint +e750 -esym(750,*)*/ + +#define SPMI_PER_DATAREG_BYTE 4 +/* + * SPMI cmd register + */ +#define SPMI_APB_SPMI_CMD_EN (1 << 31) +#define SPMI_APB_SPMI_CMD_TYPE_OFFSET 24 +#define SPMI_APB_SPMI_CMD_LENGTH_OFFSET20 +#define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 +#define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 + +#define Tranverse32(X) u32)(X) & 0xff00) >> 24) | \ + (((u32)(X) & 0x00ff) >> 8) | \ + (((u32)(X) & 0xff00) << 8) | \ + (((u32)(X) & 0x00ff) << 24)) + +/* Command Opcodes */ +/*lint -e749 -esym(749,*)*/ +enum spmi_controller_cmd_op_code { + SPMI_CMD_REG_ZERO_WRITE = 0, + SPMI_CMD_REG_WRITE = 1, + SPMI_CMD_REG_READ = 2, + SPMI_CMD_EXT_REG_WRITE = 3, + SPMI_CMD_EXT_REG_READ = 4, + SPMI_CMD_EXT_REG_WRITE_L = 5, + SPMI_CMD_EXT_REG_READ_L = 6, + SPMI_CMD_REG_RESET = 7, + SPMI_CMD_REG_SLEEP = 8, + SPMI_CMD_REG_SHUTDOWN = 9, + SPMI_CMD_REG_WAKEUP = 10, +}; +/*lint +e749 -esym(749,*)*/ + +/* + * SPMI status register + */ +#define SPMI_APB_TRANS_DONE(1 << 0) +#define SPMI_APB_TRANS_FAIL(1 << 2) + +/* Command register fields */ +#define SPMI_CONTROLLER_CMD_MAX_BYTE_COUNT 16 + +/* Maximum number of support PMIC peripherals */ +#define SPMI_CONTROLLER_TIMEOUT_US 1000 +#define SPMI_CONTROLLER_MAX_TRANS_BYTES(16) + +#define SPMI_WRITEL( dev, reg, addr ) \ + do { \ + writel( ( reg ), ( addr ) ); \ + } while (0) + +#define SPMI_READL( dev, reg, addr ) \ + do { \ + reg = readl( addr ); \ + } while (0) + +/* + * @base base address of the PMIC Arbiter core registers. + * @rdbase, @wrbase base address of the PMIC Arbiter read core registers. + * For HW-v1 these are equal to base. + * For HW-v2, the value is the same in eeraly probing, in order to read + * PMIC_ARB_CORE registers, then chnls, and obsrvr are set to + * PMIC_ARB_CORE_REGISTERS and PMIC_ARB_CORE_REGISTERS_OBS respectivly. + * @intr base address of the SPMI interrupt control registers + * @ppid_2_chnl_tbl lookup table f(SID, Periph-ID) -> channel num + * entry is only valid if corresponding bit is set in valid_ppid_bitmap. + * @valid_ppid_bitmap bit is set only for valid ppids. + * @fmt_cmd formats a command to be set into PMIC_ARBq_CHNLn_CMD + * @chnl_ofst calculates offset of the base of a channel reg space + * @ee execution environment id + * @irq_acc0_init_val initial value of the interrupt accumulator at probe time. + * Use for an HW workaround. On handling interrupts, the first accumulator + * register will be compared against this value, and bits which are set at + * boot will be ignored. + * @reserved_chnl entry of ppid_2_chnl_tbl that this driver should n
[PATCH 37/44] staging: regulator: hi6421v600-regulator: cleanup DT settings
Currently, an array is used to store both vsel and enable settings, mixing registers, masks and bit settings. Change it in order to have one separate property for each. This makes easier to understand the contents of the DT file, and to describe it at the Documentation/. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 69 +++ 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 21467fce9980..72f51594b5ff 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -45,8 +45,7 @@ struct hi6421v600_regulator { struct regulator_desc rdesc; struct hi6421_spmi_pmic *pmic; - u8 eco_mode_mask; - u32 eco_uA; + u32 eco_mode_mask, eco_uA; }; static DEFINE_MUTEX(enable_mutex); @@ -226,36 +225,49 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - unsigned int register_info[3] = {0}; unsigned int *v_table; int ret; - /* parse .register_info.enable_reg */ - ret = of_property_read_u32_array(np, "hi6421-ctrl", -register_info, 3); + ret = of_property_read_u32(np, "reg", &rdesc->enable_reg); if (ret) { - dev_err(dev, "no hi6421-ctrl property set\n"); + dev_err(dev, "missing reg property\nn"); return ret; } - rdesc->enable_reg = register_info[0]; - rdesc->enable_mask = register_info[1]; - sreg->eco_mode_mask = register_info[2]; - /* parse .register_info.vsel_reg */ - ret = of_property_read_u32_array(np, "hi6421-vsel", -register_info, 2); + ret = of_property_read_u32(np, "vsel-reg", &rdesc->vsel_reg); if (ret) { - dev_err(dev, "no hi6421-vsel property set\n"); + dev_err(dev, "missing vsel-reg property\n"); return ret; } - rdesc->vsel_reg = register_info[0]; - rdesc->vsel_mask = register_info[1]; + + ret = of_property_read_u32(np, "enable-mask", &rdesc->enable_mask); + if (ret) { + dev_err(dev, "missing enable-mask property\n"); + return ret; + } + + /* +* Not all regulators work on idle mode +*/ + ret = of_property_read_u32(np, "idle-mode-mask", &sreg->eco_mode_mask); + if (ret) { + dev_dbg(dev, "LDO doesn't support economy mode.\n"); + sreg->eco_mode_mask = 0; + sreg->eco_uA = 0; + } else { + ret = of_property_read_u32(np, "eco-microamp", + &sreg->eco_uA); + if (ret) { + dev_err(dev, "missing eco-microamp property\n"); + return ret; + } + } /* parse .off-on-delay */ ret = of_property_read_u32(np, "off-on-delay-us", &rdesc->off_on_delay); if (ret) { - dev_err(dev, "no off-on-delay-us property set\n"); + dev_err(dev, "missing off-on-delay-us property\n"); return ret; } @@ -263,21 +275,13 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, ret = of_property_read_u32(np, "startup-delay-us", &rdesc->enable_time); if (ret) { - dev_err(dev, "no startup-delay-us property set\n"); + dev_err(dev, "missing startup-delay-us property\n"); return ret; } /* FIXME: are there a better value for this? */ rdesc->ramp_delay = rdesc->enable_time; - /* parse .eco_uA */ - ret = of_property_read_u32(np, "eco-microamp", - &sreg->eco_uA); - if (ret) { - sreg->eco_uA = 0; - ret = 0; - } - /* parse volt_table */ rdesc->n_voltages = of_property_count_u32_elems(np, "voltage-table"); @@ -291,10 +295,21 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, ret = of_property_read_u32_array(np, "voltage-table", v_table, rdesc->n_voltages); if (ret) { - dev_err(dev, "no voltage-table property set\n"); + dev_err(dev, "missing voltage-table property\n"); return ret; } + /* +* Instead of explicitly requiring a mask for the voltage selector, +* as they all start from bit zero (at least on the known LDOs), +* just use the number of voltages at the voltage table, getting the +* minimal mask that would pick everything. +*/ + rdesc->
[PATCH 11/44] staging: mfd: add a PMIC driver for HiSilicon 6421 SPMI version
From: Mayulong Add the PMIC SPMI driver for the HiSilicon 6421v600. [mchehab+hua...@kernel.org: keep just the MFD driver on this patch, and renamed filenames to better match other upstream drivers] The compete patch is at: https://github.com/96boards-hikey/linux/commit/08464419fba2 Signed-off-by: Mayulong Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 759 include/linux/mfd/hi6421-spmi-pmic.h| 165 + 2 files changed, 924 insertions(+) create mode 100644 drivers/staging/hikey9xx/hi6421-spmi-pmic.c create mode 100644 include/linux/mfd/hi6421-spmi-pmic.h diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c new file mode 100644 index ..6bb0bc4b203b --- /dev/null +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -0,0 +1,759 @@ +/* + * Device driver for regulators in HISI PMIC IC + * + * Copyright (c) 2013 Linaro Ltd. + * Copyright (c) 2011 Hisilicon. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef NO_IRQ +#define NO_IRQ 0 +#endif + +/* 8-bit register offset in PMIC */ +#define HISI_MASK_STATE0xff + +#define HISI_IRQ_KEY_NUM 0 +#define HISI_IRQ_KEY_VALUE 0xc0 +#define HISI_IRQ_KEY_DOWN 7 +#define HISI_IRQ_KEY_UP6 + +/*#define HISI_NR_IRQ 25*/ +#define HISI_MASK_FIELD0xFF +#define HISI_BITS 8 +#define PMIC_FPGA_FLAG 1 + +/*define the first group interrupt register number*/ +#define HISI_PMIC_FIRST_GROUP_INT_NUM2 + +static struct bit_info g_pmic_vbus = {0}; +#ifndef BIT +#define BIT(x) (0x1U << (x)) +#endif + +static struct hisi_pmic *g_pmic; +static unsigned int g_extinterrupt_flag = 0; +static struct of_device_id of_hisi_pmic_match_tbl[] = { + { + .compatible = "hisilicon-hisi-pmic-spmi", + }, + { /* end */ } +}; + +/* + * The PMIC register is only 8-bit. + * Hisilicon SoC use hardware to map PMIC register into SoC mapping. + * At here, we are accessing SoC register with 32-bit. + */ +u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) +{ + u32 ret; + u8 read_value = 0; + struct spmi_device *pdev; + + if (NULL == g_pmic) { + pr_err(" g_pmic is NULL\n"); + return 0; + } + + pdev = to_spmi_device(g_pmic->dev); + if (NULL == pdev) { + pr_err("%s:pdev get failed!\n", __func__); + return 0; + } + + ret = spmi_ext_register_readl(pdev, reg, (unsigned char*)&read_value, 1);/*lint !e734 !e732 */ + if (ret) { + pr_err("%s:spmi_ext_register_readl failed!\n", __func__); + return ret; + } + return (u32)read_value; +} +EXPORT_SYMBOL(hisi_pmic_read); + +void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) +{ + u32 ret; + struct spmi_device *pdev; + + if (NULL == g_pmic) { + pr_err(" g_pmic is NULL\n"); + return; + } + + pdev = to_spmi_device(g_pmic->dev); + if (NULL == pdev) { + pr_err("%s:pdev get failed!\n", __func__); + return; + } + + ret = spmi_ext_register_writel(pdev, reg, (unsigned char*)&val, 1);/*lint !e734 !e732 */ + if (ret) { + pr_err("%s:spmi_ext_register_writel failed!\n", __func__); + return ; + } +} +EXPORT_SYMBOL(hisi_pmic_write); + +#ifdef CONFIG_HISI_DIEID +u32 hisi_pmic_read_sub_pmu(u8 sid, int reg) +{ + u32 ret; + u8 read_value = 0; + struct spmi_device *pdev; + + if(strstr(saved_command_line, "androidboot.swtype=factory")) + { + if (NULL == g_pmic) { + pr_err(" g_pmic is NULL\n"); + return -1;/*lint !e570 */ + } + + pdev = to_spmi_device(g_pmic->dev); + if (NULL == pdev) { + pr_err("%s:pdev get failed!\n", __func__); + return -1;/*lint !e570 */ + } + + ret = spmi_ext_register_readl(pdev->ctrl, sid, reg, (unsigned char*)&read_value, 1);/*lint !e734 !e732 */ + if (ret) { + pr_err("%s:spmi_ext_register_readl failed!\n
[PATCH 19/44] staging: mfd: hi6421-spmi-pmic: change namespace on its functions
Rename the functions used internally inside the driver in order for them to follow the driver's name. While here, get rid of some unused definitions at the header file. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 97 +++-- include/linux/mfd/hi6421-spmi-pmic.h| 51 --- 2 files changed, 70 insertions(+), 78 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index aed2d3ec2227..09cedfa1e4bb 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -62,7 +62,7 @@ static const struct mfd_cell hi6421v600_devs[] = { * Hisilicon SoC use hardware to map PMIC register into SoC mapping. * At here, we are accessing SoC register with 32-bit. */ -u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) +u32 hi6421_spmi_pmic_read(struct hi6421_spmi_pmic *pmic, int reg) { u32 ret; u8 read_value = 0; @@ -82,9 +82,9 @@ u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) } return (u32)read_value; } -EXPORT_SYMBOL(hisi_pmic_read); +EXPORT_SYMBOL(hi6421_spmi_pmic_read); -void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) +void hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, int reg, u32 val) { u32 ret; struct spmi_device *pdev; @@ -101,34 +101,36 @@ void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) return; } } -EXPORT_SYMBOL(hisi_pmic_write); +EXPORT_SYMBOL(hi6421_spmi_pmic_write); -void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, u32 mask, u32 bits) +void hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, + u32 mask, u32 bits) { u32 data; unsigned long flags; spin_lock_irqsave(&pmic->lock, flags); - data = hisi_pmic_read(pmic, reg) & ~mask; + data = hi6421_spmi_pmic_read(pmic, reg) & ~mask; data |= mask & bits; - hisi_pmic_write(pmic, reg, data); + hi6421_spmi_pmic_write(pmic, reg, data); spin_unlock_irqrestore(&pmic->lock, flags); } -EXPORT_SYMBOL(hisi_pmic_rmw); +EXPORT_SYMBOL(hi6421_spmi_pmic_rmw); -static irqreturn_t hisi_irq_handler(int irq, void *data) +static irqreturn_t hi6421_spmi_irq_handler(int irq, void *data) { - struct hisi_pmic *pmic = (struct hisi_pmic *)data; + struct hi6421_spmi_pmic *pmic = (struct hi6421_spmi_pmic *)data; unsigned long pending; int i, offset; for (i = 0; i < pmic->irqarray; i++) { - pending = hisi_pmic_read(pmic, (i + pmic->irq_addr.start_addr)); + pending = hi6421_spmi_pmic_read(pmic, (i + pmic->irq_addr.start_addr)); pending &= HISI_MASK_FIELD; if (pending != 0) pr_debug("pending[%d]=0x%lx\n\r", i, pending); - hisi_pmic_write(pmic, (i + pmic->irq_addr.start_addr), pending); + hi6421_spmi_pmic_write(pmic, (i + pmic->irq_addr.start_addr), + pending); /* solve powerkey order */ if ((i == HISI_IRQ_KEY_NUM) && ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { @@ -146,9 +148,9 @@ static irqreturn_t hisi_irq_handler(int irq, void *data) return IRQ_HANDLED; } -static void hisi_irq_mask(struct irq_data *d) +static void hi6421_spmi_irq_mask(struct irq_data *d) { - struct hisi_pmic *pmic = irq_data_get_irq_chip_data(d); + struct hi6421_spmi_pmic *pmic = irq_data_get_irq_chip_data(d); u32 data, offset; unsigned long flags; @@ -156,15 +158,15 @@ static void hisi_irq_mask(struct irq_data *d) offset += pmic->irq_mask_addr.start_addr; spin_lock_irqsave(&pmic->lock, flags); - data = hisi_pmic_read(pmic, offset); + data = hi6421_spmi_pmic_read(pmic, offset); data |= (1 << (irqd_to_hwirq(d) & 0x07)); - hisi_pmic_write(pmic, offset, data); + hi6421_spmi_pmic_write(pmic, offset, data); spin_unlock_irqrestore(&pmic->lock, flags); } -static void hisi_irq_unmask(struct irq_data *d) +static void hi6421_spmi_irq_unmask(struct irq_data *d) { - struct hisi_pmic *pmic = irq_data_get_irq_chip_data(d); + struct hi6421_spmi_pmic *pmic = irq_data_get_irq_chip_data(d); u32 data, offset; unsigned long flags; @@ -172,26 +174,26 @@ static void hisi_irq_unmask(struct irq_data *d) offset += pmic->irq_mask_addr.start_addr; spin_lock_irqsave(&pmic->lock, flags); - data = hisi_pmic_read(pmic, offset); + data = hi6421_spmi_pmic_read(pmic, offset); data &= ~(1 << (irqd_to_hwirq(d) & 0x07)); - hisi_pmic_write(pmic, offset, data); + hi6421_spmi_pmic_write(pmic, offset, data); spin_unlock_irqrestore(&pmic->lock, flags); } -static struct irq_chip hisi_pmu_irqchip = { +static struct irq_chip hi6421_spmi_p
[PATCH 27/44] staging: regulator: hi6421v600-regulator: change the binding logic
Change the binding logic to ensure that the PMIC SPMI driver will run before the regulator code and add it to the building system. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 186 +- 1 file changed, 91 insertions(+), 95 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 5f6e4ba4b99e..9aaafcbb1a36 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,20 +53,11 @@ struct hisi_regulator { u32 off_on_delay; u32 eco_uA; struct regulator_desc rdesc; - int (*dt_parse)(struct hisi_regulator *reg, struct spmi_device *spmi); + struct hisi_pmic *pmic; }; static DEFINE_MUTEX(enable_mutex); -static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev) -{ - /* regulator_dev parent to-> -* hisi regulator platform device_dev parent to-> -* hisi pmic platform device_dev -*/ - return dev_get_drvdata(rdev_get_dev(dev)->parent->parent); -} - /* helper function to ensure when it returns it is at least 'delay_us' * microseconds after 'since'. */ @@ -75,7 +66,7 @@ static int hisi_regulator_is_enabled(struct regulator_dev *dev) { u32 reg_val; struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); pr_debug("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", @@ -88,7 +79,7 @@ static int hisi_regulator_is_enabled(struct regulator_dev *dev) static int hisi_regulator_enable(struct regulator_dev *dev) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; /* keep a distance of off_on_delay from last time disabled */ usleep_range(sreg->off_on_delay, sreg->off_on_delay + 1000); @@ -116,7 +107,7 @@ static int hisi_regulator_enable(struct regulator_dev *dev) static int hisi_regulator_disable(struct regulator_dev *dev) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; /* set enable register to 0 */ hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, @@ -128,7 +119,7 @@ static int hisi_regulator_disable(struct regulator_dev *dev) static int hisi_regulator_get_voltage(struct regulator_dev *dev) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; u32 reg_val, selector; /* get voltage selector */ @@ -146,7 +137,7 @@ static int hisi_regulator_set_voltage(struct regulator_dev *dev, int min_uV, int max_uV, unsigned int *selector) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; u32 vsel; int ret = 0; @@ -179,7 +170,7 @@ static int hisi_regulator_set_voltage(struct regulator_dev *dev, static unsigned int hisi_regulator_get_mode(struct regulator_dev *dev) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; u32 reg_val; reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); @@ -198,7 +189,7 @@ static int hisi_regulator_set_mode(struct regulator_dev *dev, unsigned int mode) { struct hisi_regulator *sreg = rdev_get_drvdata(dev); - struct hisi_pmic *pmic = rdev_to_pmic(dev); + struct hisi_pmic *pmic = sreg->pmic; u32 eco_mode; switch (mode) { @@ -238,7 +229,7 @@ static unsigned int hisi_regulator_get_optimum_mode(struct regulator_dev *dev, } static int hisi_dt_parse_common(struct hisi_regulator *sreg, - struct spmi_device *pdev) + struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; @@ -296,7 +287,7 @@ static int hisi_dt_parse_common(struct hisi_regulator *sreg, } static int hisi_dt_parse_ldo(struct hisi_regulator *sreg, -struct spmi_device *pdev) +struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; @@ -355,47 +346,32 @@ static struct regulator_ops hisi_ldo_rops = { .get_optimum_mode = hisi_regulator_get_optimum_mode, }; -static const struct hisi_regul
[PATCH 14/44] staging: mfd: hi6421-spmi-pmic: get rid of the static vars
There are several static vars inside this driver. Get rid of them. While here, add a SPDX header file. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 224 include/linux/mfd/hi6421-spmi-pmic.h| 20 +- 2 files changed, 97 insertions(+), 147 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 8b87d48b88b5..be42fed16bd2 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Device driver for regulators in HISI PMIC IC * @@ -52,10 +53,7 @@ /*define the first group interrupt register number*/ #define HISI_PMIC_FIRST_GROUP_INT_NUM2 -static struct bit_info g_pmic_vbus = {0}; -static struct hisi_pmic *g_pmic; -static unsigned int g_extinterrupt_flag = 0; -static struct of_device_id of_hisi_pmic_match_tbl[] = { +static const struct of_device_id of_hisi_pmic_match_tbl[] = { { .compatible = "hisilicon-hisi-pmic-spmi", }, @@ -73,18 +71,14 @@ u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) u8 read_value = 0; struct spmi_device *pdev; - if (!g_pmic) { - pr_err("%s: g_pmic is NULL\n", __func__); - return 0; - } - - pdev = to_spmi_device(g_pmic->dev); + pdev = to_spmi_device(pmic->dev); if (!pdev) { pr_err("%s: pdev get failed!\n", __func__); return 0; } - ret = spmi_ext_register_readl(pdev, reg, (unsigned char*)&read_value, 1);/*lint !e734 !e732 */ + ret = spmi_ext_register_readl(pdev, reg, + (unsigned char *)&read_value, 1); if (ret) { pr_err("%s: spmi_ext_register_readl failed!\n", __func__); return 0; @@ -98,18 +92,13 @@ void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) u32 ret; struct spmi_device *pdev; - if (!g_pmic) { - pr_err("%s: g_pmic is NULL\n", __func__); - return; - } - - pdev = to_spmi_device(g_pmic->dev); + pdev = to_spmi_device(pmic->dev); if (!pdev) { pr_err("%s: pdev get failed!\n", __func__); return; } - ret = spmi_ext_register_writel(pdev, reg, (unsigned char*)&val, 1);/*lint !e734 !e732 */ + ret = spmi_ext_register_writel(pdev, reg, (unsigned char *)&val, 1); if (ret) { pr_err("%s: spmi_ext_register_writel failed!\n", __func__); return; @@ -122,16 +111,11 @@ void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, u32 mask, u32 bits) u32 data; unsigned long flags; - if (!g_pmic) { - pr_err("%s: g_pmic is NULL\n", __func__); - return; - } - - spin_lock_irqsave(&g_pmic->lock, flags); + spin_lock_irqsave(&pmic->lock, flags); data = hisi_pmic_read(pmic, reg) & ~mask; data |= mask & bits; hisi_pmic_write(pmic, reg, data); - spin_unlock_irqrestore(&g_pmic->lock, flags); + spin_unlock_irqrestore(&pmic->lock, flags); } EXPORT_SYMBOL(hisi_pmic_rmw); @@ -142,16 +126,15 @@ static irqreturn_t hisi_irq_handler(int irq, void *data) int i, offset; for (i = 0; i < pmic->irqarray; i++) { - pending = hisi_pmic_read(g_pmic, (i + pmic->irq_addr.start_addr)); + pending = hisi_pmic_read(pmic, (i + pmic->irq_addr.start_addr)); pending &= HISI_MASK_FIELD; - if (pending != 0) { - pr_info("pending[%d]=0x%lx\n\r", i, pending); - } + if (pending != 0) + pr_debug("pending[%d]=0x%lx\n\r", i, pending); - hisi_pmic_write(g_pmic, (i + pmic->irq_addr.start_addr), pending); + hisi_pmic_write(pmic, (i + pmic->irq_addr.start_addr), pending); - /*solve powerkey order*/ - if ((HISI_IRQ_KEY_NUM == i) && ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { + /* solve powerkey order */ + if ((i == HISI_IRQ_KEY_NUM) && ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_DOWN]); generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_UP]); pending &= (~HISI_IRQ_KEY_VALUE); @@ -159,25 +142,25 @@ static irqreturn_t hisi_irq_handler(int irq, void *data) if (pending) { for_each_set_bit(offset, &pending, HISI_BITS) - generic_handle_irq(pmic->irqs[offset + i * HISI_BITS]);/*lint !e679 */ + generic_handle_irq(pmic->irqs[offset + i * HISI_BITS]); } } /*Handle the second gro
[PATCH 12/44] staging: mfd: hi6421-spmi-pmic: get rid of unused code
There are some checks there which could make sense for downstream builds, but doesn't make much sense for upstream ones. They came from the official Hikey970 tree from Linaro, but even there, the commented-out code is not set via other Kconfig vars. So, let's just get rid of that. If needed later, this patch can be (partially?) reversed. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 63 - include/linux/mfd/hi6421-spmi-pmic.h| 42 -- 2 files changed, 105 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 6bb0bc4b203b..809381eb6043 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -53,10 +53,6 @@ #define HISI_PMIC_FIRST_GROUP_INT_NUM2 static struct bit_info g_pmic_vbus = {0}; -#ifndef BIT -#define BIT(x) (0x1U << (x)) -#endif - static struct hisi_pmic *g_pmic; static unsigned int g_extinterrupt_flag = 0; static struct of_device_id of_hisi_pmic_match_tbl[] = { @@ -121,65 +117,6 @@ void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) } EXPORT_SYMBOL(hisi_pmic_write); -#ifdef CONFIG_HISI_DIEID -u32 hisi_pmic_read_sub_pmu(u8 sid, int reg) -{ - u32 ret; - u8 read_value = 0; - struct spmi_device *pdev; - - if(strstr(saved_command_line, "androidboot.swtype=factory")) - { - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); - return -1;/*lint !e570 */ - } - - pdev = to_spmi_device(g_pmic->dev); - if (NULL == pdev) { - pr_err("%s:pdev get failed!\n", __func__); - return -1;/*lint !e570 */ - } - - ret = spmi_ext_register_readl(pdev->ctrl, sid, reg, (unsigned char*)&read_value, 1);/*lint !e734 !e732 */ - if (ret) { - pr_err("%s:spmi_ext_register_readl failed!\n", __func__); - return ret; - } - return (u32)read_value; - } - return 0; -} -EXPORT_SYMBOL(hisi_pmic_read_sub_pmu); - -void hisi_pmic_write_sub_pmu(u8 sid, int reg, u32 val) -{ - u32 ret; - struct spmi_device *pdev; - if(strstr(saved_command_line, "androidboot.swtype=factory")) - { - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); - return; - } - - pdev = to_spmi_device(g_pmic->dev); - if (NULL == pdev) { - pr_err("%s:pdev get failed!\n", __func__); - return; - } - - ret = spmi_ext_register_writel(pdev->ctrl, sid, reg, (unsigned char*)&val, 1);/*lint !e734 !e732 */ - if (ret) { - pr_err("%s:spmi_ext_register_writel failed!\n", __func__); - return ; - } - } - - return ; -} -EXPORT_SYMBOL(hisi_pmic_write_sub_pmu); -#endif void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, u32 mask, u32 bits) diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h index 939b36f617c1..5be9b4d3f207 100644 --- a/include/linux/mfd/hi6421-spmi-pmic.h +++ b/include/linux/mfd/hi6421-spmi-pmic.h @@ -78,7 +78,6 @@ unsigned int get_uv_mntn_status(void); void clear_uv_mntn_resered_reg_bit(void); void set_uv_mntn_resered_reg_bit(void); -#if defined(CONFIG_HISI_PMIC) || defined(CONFIG_HISI_PMIC_PMU_SPMI) /* Register Access Helpers */ u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg); void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val); @@ -90,11 +89,6 @@ int hisi_pmic_array_read(int addr, char *buff, unsigned int len); int hisi_pmic_array_write(int addr, char *buff, unsigned int len); extern int hisi_get_pmic_irq_byname(unsigned int pmic_irq_list); extern int hisi_pmic_get_vbus_status(void); -#if defined(CONFIG_HISI_DIEID) -u32 hisi_pmic_read_sub_pmu(u8 sid ,int reg); -void hisi_pmic_write_sub_pmu(u8 sid ,int reg, u32 val); -#endif -#else static inline u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) { return 0; } static inline void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) {} static inline void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, u32 mask, u32 bits) {} @@ -107,38 +101,7 @@ static inline int hisi_get_pmic_irq_byname(unsigned int pmic_irq_list) { return static inline int hisi_pmic_get_vbus_status(void) { return 1; } static inline u32 hisi_pmic_read_sub_pmu(u8 sid ,int reg) { return 0; } static inline void hisi_pmic_write_sub_pmu(u8 sid ,int reg, u32 val) {} -#endif -#ifdef CONFIG_HISI_HI6421V500_PMU -enum pmic_irq_list { - POR_D45MR = 0, - VBUS_CONNECT, - VBUS_DISCONNECT, - ALARMON_R, - HOLD_6S, - HOLD_1S
[PATCH 40/44] staging: regulator: hi6421v600-regulator: code cleanup
Do some code cleanup in order to make it cleaner for moving it out of staging in the future. Suggested-by: Jonathan Cameron Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 74 --- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index c80dfac1e4c3..29ef6bcadd84 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -15,29 +15,28 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * */ -#include +#include #include -#include #include #include -#include -#include -#include +#include +#include #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include #include -#include +#include #include +#include +#include +#include #define rdev_dbg(rdev, fmt, arg...)\ pr_debug("%s: %s: " fmt, (rdev)->desc->name, __func__, ##arg) @@ -50,15 +49,16 @@ struct hi6421v600_regulator { static DEFINE_MUTEX(enable_mutex); -/* helper function to ensure when it returns it is at least 'delay_us' +/* + * helper function to ensure when it returns it is at least 'delay_us' * microseconds after 'since'. */ static int hi6421_spmi_regulator_is_enabled(struct regulator_dev *rdev) { - u32 reg_val; struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; + u32 reg_val; reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); @@ -136,7 +136,6 @@ static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev, struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val; - /* unlikely to happen. sanity test done by regulator core */ if (unlikely(selector >= rdev->desc->n_voltages)) return -EINVAL; @@ -158,8 +157,8 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - u32 reg_val; unsigned int mode; + u32 reg_val; reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); @@ -211,13 +210,10 @@ hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev *rdev, { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - if (load_uA || ((unsigned int)load_uA > sreg->eco_uA)) { - rdev_dbg(rdev, "normal mode"); + if (load_uA || ((unsigned int)load_uA > sreg->eco_uA)) return REGULATOR_MODE_NORMAL; - } else { - rdev_dbg(rdev, "idle mode"); - return REGULATOR_MODE_IDLE; - } + + return REGULATOR_MODE_IDLE; } static int hi6421_spmi_dt_parse(struct platform_device *pdev, @@ -256,8 +252,7 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, sreg->eco_mode_mask = 0; sreg->eco_uA = 0; } else { - ret = of_property_read_u32(np, "eco-microamp", - &sreg->eco_uA); + ret = of_property_read_u32(np, "eco-microamp", &sreg->eco_uA); if (ret) { dev_err(dev, "missing eco-microamp property\n"); return ret; @@ -327,23 +322,19 @@ static struct regulator_ops hi6421_spmi_ldo_rops = { .get_optimum_mode = hi6421_spmi_regulator_get_optimum_mode, }; -/* - * Used only for parsing the DT properties - */ - static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, struct device_node *np, struct hi6421_spmi_pmic *pmic) { - struct device *dev = &pdev->dev; - struct regulator_desc *rdesc; - struct regulator_dev *rdev; - struct hi6421v600_regulator *sreg = NULL; + struct regulation_constraints *constraint; struct regulator_init_data *initdata; struct regulator_config config = { }; - struct regulation_constraints *constraint; - const char *supplyname = NULL; - int ret = 0; + struct hi6421v600_regulator *sreg; + struct device *dev = &pdev->dev; + struct regulator_desc *rdesc; + struct regulator_dev *rdev; + const char *supplyname; + int ret; initdata = of_get_regulator_init_data(dev, np, NULL); if (!initdata) { @@ -351,7 +342,7 @@ static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, return -EINVAL; } - sreg = kzalloc(sizeof(*sreg), GFP_KERNEL); + sreg = devm_kzalloc(dev, sizeof(*sreg)
[PATCH 38/44] staging: regulator: hi6421v600-regulator: fix some coding style issues
Fix the remaining issues complained by checkpatch. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 28 +-- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 72f51594b5ff..c80dfac1e4c3 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -40,7 +40,7 @@ #include #define rdev_dbg(rdev, fmt, arg...)\ -pr_debug("%s: %s: " fmt, rdev->desc->name, __func__, ##arg) +pr_debug("%s: %s: " fmt, (rdev)->desc->name, __func__, ##arg) struct hi6421v600_regulator { struct regulator_desc rdesc; @@ -105,7 +105,7 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) rdev->desc->enable_reg, rdev->desc->enable_mask); hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, - rdev->desc->enable_mask, 0); +rdev->desc->enable_mask, 0); return 0; } @@ -122,7 +122,7 @@ static int hi6421_spmi_regulator_get_voltage_sel(struct regulator_dev *rdev) selector = (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1); rdev_dbg(rdev, - "vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n", +"vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n", rdev->desc->vsel_reg, reg_val, selector, rdev->desc->ops->list_voltage(rdev, selector) / 1000); @@ -144,7 +144,7 @@ static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev, /* set voltage selector */ rdev_dbg(rdev, - "vsel_reg=0x%x, mask=0x%x, value=0x%x, voltage=%d mV\n", +"vsel_reg=0x%x, mask=0x%x, value=0x%x, voltage=%d mV\n", rdev->desc->vsel_reg, rdev->desc->vsel_mask, reg_val, rdev->desc->ops->list_voltage(rdev, selector) / 1000); @@ -169,7 +169,7 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) mode = REGULATOR_MODE_NORMAL; rdev_dbg(rdev, - "enable_reg=0x%x, eco_mode_mask=0x%x, reg_val=0x%x, %s mode\n", +"enable_reg=0x%x, eco_mode_mask=0x%x, reg_val=0x%x, %s mode\n", rdev->desc->enable_reg, sreg->eco_mode_mask, reg_val, mode == REGULATOR_MODE_IDLE ? "idle" : "normal"); @@ -177,7 +177,7 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) } static int hi6421_spmi_regulator_set_mode(struct regulator_dev *rdev, - unsigned int mode) + unsigned int mode) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; @@ -204,9 +204,10 @@ static int hi6421_spmi_regulator_set_mode(struct regulator_dev *rdev, return 0; } -static unsigned int hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev *rdev, - int input_uV, int output_uV, - int load_uA) +static unsigned int +hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev *rdev, + int input_uV, int output_uV, + int load_uA) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); @@ -220,7 +221,7 @@ static unsigned int hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev } static int hi6421_spmi_dt_parse(struct platform_device *pdev, -struct hi6421v600_regulator *sreg, + struct hi6421v600_regulator *sreg, struct regulator_desc *rdesc) { struct device *dev = &pdev->dev; @@ -256,7 +257,7 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, sreg->eco_uA = 0; } else { ret = of_property_read_u32(np, "eco-microamp", - &sreg->eco_uA); + &sreg->eco_uA); if (ret) { dev_err(dev, "missing eco-microamp property\n"); return ret; @@ -331,8 +332,8 @@ static struct regulator_ops hi6421_spmi_ldo_rops = { */ static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, - struct device_node *np, - struct hi6421_spmi_pmic *pmic) + struct device_node *np, + struct hi6421_spmi_pmic *pmic) { struct device *dev = &pdev->dev; struct regulator_desc *rdesc; @@ -404,7 +405,6 @@ static int hi6421_spmi_regulator_probe_ldo(
[PATCH 23/44] staging: regulator: add a regulator driver for HiSilicon 6421v600 SPMI PMIC
From: Mayulong Add the regulator driver for the LDO lines provided by the HiSilicon 6421v600 SPMI PMIC device. [mchehab+hua...@kernel.org: keep just the regulator driver on this patch, renaming it to better fit at upstream namespace] The compete patch is at: https://github.com/96boards-hikey/linux/commit/08464419fba2 Signed-off-by: Mayulong Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 741 ++ 1 file changed, 741 insertions(+) create mode 100644 drivers/staging/hikey9xx/hi6421v600-regulator.c diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c new file mode 100644 index ..941bfe32bf5b --- /dev/null +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -0,0 +1,741 @@ +/* + * Device driver for regulators in Hisi IC + * + * Copyright (c) 2013 Linaro Ltd. + * Copyright (c) 2011 Hisilicon. + * + * Guodong Xu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_HISI_PMIC_DEBUG +#include +#endif +#include +#include +#include + +#if 1 +#define BRAND_DEBUG(args...) pr_debug(args); +#else +#define BRAND_DEBUG(args...) +#endif + +struct hisi_regulator_register_info { + u32 ctrl_reg; + u32 enable_mask; + u32 eco_mode_mask; + u32 vset_reg; + u32 vset_mask; +}; + +struct hisi_regulator { + const char *name; + struct hisi_regulator_register_info register_info; + struct timeval last_off_time; + u32 off_on_delay; + u32 eco_uA; + struct regulator_desc rdesc; + int (*dt_parse)(struct hisi_regulator *, struct spmi_device *); +}; + +static DEFINE_MUTEX(enable_mutex); +struct timeval last_enabled; + + +static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev) +{ + /* regulator_dev parent to-> +* hisi regulator platform device_dev parent to-> +* hisi pmic platform device_dev +*/ + return dev_get_drvdata(rdev_get_dev(dev)->parent->parent); +} + +/* helper function to ensure when it returns it is at least 'delay_us' + * microseconds after 'since'. + */ +static void ensured_time_after(struct timeval since, u32 delay_us) +{ + struct timeval now; + u64 elapsed_ns64, delay_ns64; + u32 actual_us32; + + delay_ns64 = delay_us * NSEC_PER_USEC; + do_gettimeofday(&now); + elapsed_ns64 = timeval_to_ns(&now) - timeval_to_ns(&since); + if (delay_ns64 > elapsed_ns64) { + actual_us32 = ((u32)(delay_ns64 - elapsed_ns64) / + NSEC_PER_USEC); + if (actual_us32 >= 1000) { + mdelay(actual_us32 / 1000); /*lint !e647 */ + udelay(actual_us32 % 1000); + } else if (actual_us32 > 0) { + udelay(actual_us32); + } + } + return; +} + +static int hisi_regulator_is_enabled(struct regulator_dev *dev) +{ + u32 reg_val; + struct hisi_regulator *sreg = rdev_get_drvdata(dev); + struct hisi_pmic *pmic = rdev_to_pmic(dev); + + reg_val = hisi_pmic_read(pmic, sreg->register_info.ctrl_reg); + BRAND_DEBUG("<[%s]: ctrl_reg=0x%x,enable_state=%d>\n", __func__, sreg->register_info.ctrl_reg,\ + (reg_val & sreg->register_info.enable_mask)); + + return ((reg_val & sreg->register_info.enable_mask) != 0); +} + +static int hisi_regulator_enable(struct regulator_dev *dev) +{ + struct hisi_regulator *sreg = rdev_get_drvdata(dev); + struct hisi_pmic *pmic = rdev_to_pmic(dev); + + /* keep a distance of off_on_delay from last time disabled */ + ensured_time_after(sreg->last_off_time, sreg->off_on_delay); + + BRAND_DEBUG("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay); + + /* cannot enable more than one regulator at one time */ + mutex_lock(&enable_mutex); + ensured_time_after(last_enabled, HISI_REGS_ENA_PROTECT_TIME); + + /* set enable register */ + hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, + sreg->register_info.enable_mask, + sreg->register_info.enable_mask); + BRAND_DEBUG("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\ + sreg->r
[PATCH 10/44] staging: spmi: hisi-spmi-controller: do some code cleanups
There are several minor things that can be cleanup in order to make this driver more prepared for leaving staging. Suggested-by: Jonathan Cameron Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hisi-spmi-controller.c | 135 +++--- 1 file changed, 51 insertions(+), 84 deletions(-) diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index 153bcdb0cde4..583df10cbf1a 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -2,18 +2,16 @@ #include #include +#include #include #include -#include -#include -#include -#include #include +#include +#include #include +#include #include -#define SPMI_CONTROLLER_NAME "spmi_controller" - /* * SPMI register addr */ @@ -73,27 +71,6 @@ enum spmi_controller_cmd_op_code { #define SPMI_CONTROLLER_TIMEOUT_US 1000 #define SPMI_CONTROLLER_MAX_TRANS_BYTES16 -/* - * @base base address of the PMIC Arbiter core registers. - * @rdbase, @wrbase base address of the PMIC Arbiter read core registers. - * For HW-v1 these are equal to base. - * For HW-v2, the value is the same in eeraly probing, in order to read - * PMIC_ARB_CORE registers, then chnls, and obsrvr are set to - * PMIC_ARB_CORE_REGISTERS and PMIC_ARB_CORE_REGISTERS_OBS respectivly. - * @intr base address of the SPMI interrupt control registers - * @ppid_2_chnl_tbl lookup table f(SID, Periph-ID) -> channel num - * entry is only valid if corresponding bit is set in valid_ppid_bitmap. - * @valid_ppid_bitmap bit is set only for valid ppids. - * @fmt_cmd formats a command to be set into PMIC_ARBq_CHNLn_CMD - * @chnl_ofst calculates offset of the base of a channel reg space - * @ee execution environment id - * @irq_acc0_init_val initial value of the interrupt accumulator at probe time. - * Use for an HW workaround. On handling interrupts, the first accumulator - * register will be compared against this value, and bits which are set at - * boot will be ignored. - * @reserved_chnl entry of ppid_2_chnl_tbl that this driver should never touch. - * value is positive channel number or negative to mark it unused. - */ struct spmi_controller_dev { struct spmi_controller *controller; struct device *dev; @@ -106,14 +83,13 @@ static int spmi_controller_wait_for_done(struct device *dev, struct spmi_controller_dev *ctrl_dev, void __iomem *base, u8 sid, u16 addr) { - u32 status = 0; u32 timeout = SPMI_CONTROLLER_TIMEOUT_US; - u32 offset; + u32 status, offset; offset = SPMI_APB_SPMI_STATUS_BASE_ADDR; offset += SPMI_CHANNEL_OFFSET * ctrl_dev->channel + SPMI_SLAVE_OFFSET * sid; - while (timeout--) { + do { status = readl(base + offset); if (status & SPMI_APB_TRANS_DONE) { @@ -126,21 +102,21 @@ static int spmi_controller_wait_for_done(struct device *dev, return 0; } udelay(1); - } + } while(timeout--); dev_err(dev, "%s: timeout, status 0x%x\n", __func__, status); return -ETIMEDOUT; } static int spmi_read_cmd(struct spmi_controller *ctrl, -u8 opc, u8 sid, u16 addr, u8 *__buf, size_t bc) +u8 opc, u8 slave_id, u16 slave_addr, u8 *__buf, size_t bc) { struct spmi_controller_dev *spmi_controller = dev_get_drvdata(&ctrl->dev); + u32 chnl_ofst = SPMI_CHANNEL_OFFSET * spmi_controller->channel; unsigned long flags; u8 *buf = __buf; u32 cmd, data; int rc; - u32 chnl_ofst = SPMI_CHANNEL_OFFSET * spmi_controller->channel; u8 op_code, i; if (bc > SPMI_CONTROLLER_MAX_TRANS_BYTES) { @@ -150,14 +126,17 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, return -EINVAL; } - /* Check the opcode */ - if (opc == SPMI_CMD_READ) { + switch (opc) { + case SPMI_CMD_READ: op_code = SPMI_CMD_REG_READ; - } else if (opc == SPMI_CMD_EXT_READ) { + break; + case SPMI_CMD_EXT_READ: op_code = SPMI_CMD_EXT_REG_READ; - } else if (opc == SPMI_CMD_EXT_READL) { + break; + case SPMI_CMD_EXT_READL: op_code = SPMI_CMD_EXT_REG_READ_L; - } else { + break; + default: dev_err(&ctrl->dev, "invalid read cmd 0x%x", opc); return -EINVAL; } @@ -165,21 +144,20 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, cmd = SPMI_APB_SPMI_CMD_EN | (op_code << SPMI_APB_SPMI_CMD_TYPE_OFFSET) | ((bc - 1) << SPMI_APB_SPMI_CMD_LENGTH_OFFSET) | -((sid & 0xf) << SPMI_APB_S
[PATCH 31/44] staging: regulator: hi6421v600-regulator: better handle modes
Instead of implementing a custom set of properties, set valid_modes_mask based on having or not a mask for enabling the eco_mode. This makes the code clearer, and remove some uneeded props from DT. Signed-off-by: Mauro Carvalho Chehab --- .../staging/hikey9xx/hi6421v600-regulator.c | 32 ++- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index e4a64893a7ad..bde7fa4d7e8f 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -338,7 +338,6 @@ static int hisi_regulator_probe_ldo(struct platform_device *pdev, struct regulator_config config = { }; struct regulation_constraints *constraint; const char *supplyname = NULL; - unsigned int temp_modes; int ret = 0; initdata = of_get_regulator_init_data(dev, np, NULL); @@ -347,25 +346,6 @@ static int hisi_regulator_probe_ldo(struct platform_device *pdev, return -EINVAL; } - /* hisi regulator supports two modes */ - constraint = &initdata->constraints; - - ret = of_property_read_u32_array(np, "valid-modes-mask", -&constraint->valid_modes_mask, 1); - if (ret) { - dev_err(dev, "no valid modes mask\n"); - ret = -ENODEV; - return ret; - } - ret = of_property_read_u32_array(np, "valid-idle-mask", -&temp_modes, 1); - if (ret) { - dev_err(dev, "no valid idle mask\n"); - ret = -ENODEV; - return ret; - } - constraint->valid_ops_mask |= temp_modes; - sreg = kzalloc(sizeof(*sreg), GFP_KERNEL); if (!sreg) return -ENOMEM; @@ -387,6 +367,15 @@ static int hisi_regulator_probe_ldo(struct platform_device *pdev, if (ret) goto hisi_probe_end; + /* hisi regulator supports two modes */ + constraint = &initdata->constraints; + + constraint->valid_modes_mask = REGULATOR_MODE_NORMAL; + if (sreg->eco_mode_mask) { + constraint->valid_modes_mask |= REGULATOR_MODE_IDLE; + constraint->valid_ops_mask |= REGULATOR_CHANGE_MODE; + } + config.dev = &pdev->dev; config.init_data = initdata; config.driver_data = sreg; @@ -401,8 +390,7 @@ static int hisi_regulator_probe_ldo(struct platform_device *pdev, goto hisi_probe_end; } - dev_dbg(dev, "%s:valid_modes_mask: 0x%x, valid_ops_mask: 0x%x\n", -rdesc->name, + dev_dbg(dev, "valid_modes_mask: 0x%x, valid_ops_mask: 0x%x\n", constraint->valid_modes_mask, constraint->valid_ops_mask); dev_set_drvdata(dev, rdev); -- 2.26.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 22/44] staging: mfd: hi6421-spmi-pmic: cleanup the code
There are several small cleanups that can be done in order to make the code more prepared to be upstreamed. Suggested-by: Jonathan Cameron Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 146 +--- include/linux/mfd/hi6421-spmi-pmic.h| 13 +- 2 files changed, 71 insertions(+), 88 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index d8b84d64041e..76766e7b8bf9 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -17,26 +17,23 @@ * */ -#include #include #include -#include #include #include #include +#include #include -#include -#include +#include +#include #include #include #include +#include #include -#include -#include +#include +#include #include -#ifndef NO_IRQ -#define NO_IRQ 0 -#endif /* 8-bit register offset in PMIC */ #define HISI_MASK_STATE0xff @@ -46,12 +43,11 @@ #define HISI_IRQ_KEY_DOWN 7 #define HISI_IRQ_KEY_UP6 -/*#define HISI_NR_IRQ 25*/ -#define HISI_MASK_FIELD0xFF +#define HISI_MASK_FIELD0xFF #define HISI_BITS 8 /*define the first group interrupt register number*/ -#define HISI_PMIC_FIRST_GROUP_INT_NUM2 +#define HISI_PMIC_FIRST_GROUP_INT_NUM 2 static const struct mfd_cell hi6421v600_devs[] = { { .name = "hi6421v600-regulator", }, @@ -62,58 +58,60 @@ static const struct mfd_cell hi6421v600_devs[] = { * Hisilicon SoC use hardware to map PMIC register into SoC mapping. * At here, we are accessing SoC register with 32-bit. */ -u32 hi6421_spmi_pmic_read(struct hi6421_spmi_pmic *pmic, int reg) +int hi6421_spmi_pmic_read(struct hi6421_spmi_pmic *pmic, int reg) { - u32 ret; + struct spmi_device *pdev; u8 read_value = 0; - struct spmi_device *pdev; + u32 ret; pdev = to_spmi_device(pmic->dev); if (!pdev) { pr_err("%s: pdev get failed!\n", __func__); - return 0; + return -ENODEV; } - ret = spmi_ext_register_readl(pdev, reg, - (unsigned char *)&read_value, 1); + ret = spmi_ext_register_readl(pdev, reg, &read_value, 1); if (ret) { pr_err("%s: spmi_ext_register_readl failed!\n", __func__); - return 0; + return ret; } - return (u32)read_value; + return read_value; } EXPORT_SYMBOL(hi6421_spmi_pmic_read); -void hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, int reg, u32 val) +int hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, int reg, u32 val) { - u32 ret; struct spmi_device *pdev; + u32 ret; pdev = to_spmi_device(pmic->dev); if (!pdev) { pr_err("%s: pdev get failed!\n", __func__); - return; + return -ENODEV; } ret = spmi_ext_register_writel(pdev, reg, (unsigned char *)&val, 1); - if (ret) { + if (ret) pr_err("%s: spmi_ext_register_writel failed!\n", __func__); - return; - } + + return ret; } EXPORT_SYMBOL(hi6421_spmi_pmic_write); -void hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, +int hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, u32 mask, u32 bits) { + unsigned long flags; u32 data; - unsigned long flags; + int ret; spin_lock_irqsave(&pmic->lock, flags); data = hi6421_spmi_pmic_read(pmic, reg) & ~mask; data |= mask & bits; - hi6421_spmi_pmic_write(pmic, reg, data); + ret = hi6421_spmi_pmic_write(pmic, reg, data); spin_unlock_irqrestore(&pmic->lock, flags); + + return ret; } EXPORT_SYMBOL(hi6421_spmi_pmic_rmw); @@ -124,13 +122,12 @@ static irqreturn_t hi6421_spmi_irq_handler(int irq, void *data) int i, offset; for (i = 0; i < pmic->irqarray; i++) { - pending = hi6421_spmi_pmic_read(pmic, (i + pmic->irq_addr.start_addr)); + pending = hi6421_spmi_pmic_read(pmic, (i + pmic->irq_addr)); pending &= HISI_MASK_FIELD; if (pending != 0) pr_debug("pending[%d]=0x%lx\n\r", i, pending); - hi6421_spmi_pmic_write(pmic, (i + pmic->irq_addr.start_addr), - pending); + hi6421_spmi_pmic_write(pmic, (i + pmic->irq_addr), pending); /* solve powerkey order */ if ((i == HISI_IRQ_KEY_NUM) && ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { @@ -155,7 +152,7 @@ static void hi6421_spmi_irq_mask(struct irq_data *d) unsigned long flags; offset = (irqd_to_hwirq(d) >> 3
[PATCH] staging: rtl8723bs: os_dep: fix function-name print using __func__
This patch to the os_intfs.c fixes the printing of function names using the preferred '"%s...", __func__' and alignment issues as pointed out by the checkpatch.pl tool. Signed-off-by: Mohammed Rushad --- drivers/staging/rtl8723bs/os_dep/os_intfs.c | 56 +++-- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c index 27f990a01a23..0460db4ae660 100644 --- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c +++ b/drivers/staging/rtl8723bs/os_dep/os_intfs.c @@ -400,17 +400,17 @@ u16 rtw_recv_select_queue(struct sk_buff *skb) memcpy(ð_type, pdata + (ETH_ALEN << 1), 2); switch (be16_to_cpu(eth_type)) { - case ETH_P_IP: + case ETH_P_IP: - piphdr = (struct iphdr *)(pdata + ETH_HLEN); + piphdr = (struct iphdr *)(pdata + ETH_HLEN); - dscp = piphdr->tos & 0xfc; + dscp = piphdr->tos & 0xfc; - priority = dscp >> 5; + priority = dscp >> 5; - break; - default: - priority = 0; + break; + default: + priority = 0; } return rtw_1d_to_queue[priority]; @@ -539,7 +539,7 @@ u32 rtw_start_drv_threads(struct adapter *padapter) { u32 _status = _SUCCESS; - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_start_drv_threads\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+%s\n", __func__)); padapter->xmitThread = kthread_run(rtw_xmit_thread, padapter, "RTW_XMIT_THREAD"); if (IS_ERR(padapter->xmitThread)) _status = _FAIL; @@ -556,7 +556,7 @@ u32 rtw_start_drv_threads(struct adapter *padapter) void rtw_stop_drv_threads(struct adapter *padapter) { - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+%s\n", __func__)); rtw_stop_cmd_thread(padapter); @@ -710,7 +710,7 @@ u8 rtw_init_drv_sw(struct adapter *padapter) { u8 ret8 = _SUCCESS; - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_init_drv_sw\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+%s\n", __func__)); rtw_init_default_value(padapter); @@ -773,29 +773,29 @@ u8 rtw_init_drv_sw(struct adapter *padapter) exit: - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_init_drv_sw\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-%s\n", __func__)); return ret8; } void rtw_cancel_all_timer(struct adapter *padapter) { - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_cancel_all_timer\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+%s\n", __func__)); del_timer_sync(&padapter->mlmepriv.assoc_timer); - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel association timer complete!\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("%s:cancel association timer complete!\n", __func__)); del_timer_sync(&padapter->mlmepriv.scan_to_timer); - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel scan_to_timer!\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("%s:cancel scan_to_timer!\n", __func__)); del_timer_sync(&padapter->mlmepriv.dynamic_chk_timer); - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel dynamic_chk_timer!\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("%s:cancel dynamic_chk_timer!\n", __func__)); del_timer_sync(&(adapter_to_pwrctl(padapter)->pwr_state_check_timer)); del_timer_sync(&padapter->mlmepriv.set_scan_deny_timer); rtw_clear_scan_deny(padapter); - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel set_scan_deny_timer!\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("%s:cancel set_scan_deny_timer!\n", __func__)); del_timer_sync(&padapter->recvpriv.signal_stat_timer); @@ -805,7 +805,7 @@ void rtw_cancel_all_timer(struct adapter *padapter) u8 rtw_free_drv_sw(struct adapter *padapter) { - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("==>rtw_free_drv_sw")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("==>%s", __func__)); free_mlme_ext_priv(&padapter->mlmeextpriv); @@ -829,7 +829,7 @@ u8 rtw_free_drv_sw(struct adapter *padapter) rtw_hal_free_data(padapter); - RT_TRACE(_module_os_intfs_c_, _drv_info_, ("<==rtw_free_drv_sw\n")); + RT_TRACE(_module_os_intfs_c_, _drv_info_, ("<==%s\n", __func__)); /* free the old_pnetdev */ if (padapter->rereg_nd_name_priv.old_pnetdev) { @@ -841,7 +841,7 @@ u8 rtw_free_drv_sw(struct adapter *padapter) if (padapter->pbuddy_adapter != NULL) padapter->pbuddy_adapter->pbuddy_adapter = NULL; - RT_TRACE(_module_os_intfs_c_, _drv_in
Re: [PATCH 35/44] staging: regulator: hi6421v600-regulator: add a driver-specific debug macro
On Wed, 2020-08-12 at 17:56 +0200, Mauro Carvalho Chehab wrote: > Using dev_dbg() is not too nice, as, instead of printing the > name of the regulator, it prints "regulator.", making > harder to associate what is happening with each ldo line. > > So, add a debug-specific macro, which will print the rdev's > name, just like the regulator core. Seems sensible, but trivially: > diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c > b/drivers/staging/hikey9xx/hi6421v600-regulator.c [] > @@ -209,10 +212,10 @@ static unsigned int > hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev > struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); > > if (load_uA || ((unsigned int)load_uA > sreg->eco_uA)) { > - dev_dbg(&rdev->dev, "%s: normal mode", __func__); > + rdev_dbg(rdev, "normal mode"); > return REGULATOR_MODE_NORMAL; > } else { > - dev_dbg(&rdev->dev, "%s: idle mode", __func__); > + rdev_dbg(rdev, "idle mode"); missing terminating newlines ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 20/44] staging: mfd: hi6421-spmi-pmic: fix some coding style issues
On Wed, 2020-08-12 at 17:56 +0200, Mauro Carvalho Chehab wrote: > Checkpatch complains about some minor issues inside this > driver that were not addressed by the previous patch. > > Address them. [] > diff --git a/include/linux/mfd/hi6421-spmi-pmic.h > b/include/linux/mfd/hi6421-spmi-pmic.h [] > @@ -38,7 +38,8 @@ struct hi6421_spmi_pmic { > unsigned int*irqs; > int irqnum; > int irqarray; > - struct hi6421_spmi_irq_mask_infoirq_mask_addr; > + > + struct hi6421_spmi_irq_mask_infoirq_mask_addr; > struct hi6421_spmi_irq_info irq_addr; > }; Was adding a blank line one of checkpatch complaints? I doubt it. ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 10/44] staging: spmi: hisi-spmi-controller: do some code cleanups
On Wed, 2020-08-12 at 17:56 +0200, Mauro Carvalho Chehab wrote: > There are several minor things that can be cleanup in > order to make this driver more prepared for leaving staging. trivial style notes: > diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c > b/drivers/staging/hikey9xx/hisi-spmi-controller.c [] > @@ -106,14 +83,13 @@ static int spmi_controller_wait_for_done(struct device > *dev, >struct spmi_controller_dev *ctrl_dev, >void __iomem *base, u8 sid, u16 addr) > { > - u32 status = 0; > u32 timeout = SPMI_CONTROLLER_TIMEOUT_US; > - u32 offset; > + u32 status, offset; > > offset = SPMI_APB_SPMI_STATUS_BASE_ADDR; > offset += SPMI_CHANNEL_OFFSET * ctrl_dev->channel + SPMI_SLAVE_OFFSET * > sid; > > - while (timeout--) { > + do { > status = readl(base + offset); > > if (status & SPMI_APB_TRANS_DONE) { > @@ -126,21 +102,21 @@ static int spmi_controller_wait_for_done(struct device > *dev, > return 0; > } > udelay(1); > - } > + } while(timeout--); Odd spacing. Two spaces after close brace, none before open parenthesis. > @@ -237,14 +217,13 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, [] > - i = 0; > - do { > + for (i = 0; bc > i * SPMI_PER_DATAREG_BYTE; i++) { > data = 0; > if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { > memcpy(&data, buf, sizeof(data)); > @@ -256,22 +235,22 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > > writel((u32)cpu_to_be32(data), > spmi_controller->base + chnl_ofst + > SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); > - i++; > - } while (bc > i * SPMI_PER_DATAREG_BYTE); > + }; Unnecessary semicolon after for loop close brace. ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 01/44] staging: spmi: add Hikey 970 SPMI controller driver
On Wed, Aug 12, 2020 at 05:56:11PM +0200, Mauro Carvalho Chehab wrote: > From: Mayulong > > Add the SPMI controller code required to use the Kirin 970 > SPMI bus. > > [mchehab+hua...@kernel.org: added just the SPMI controller on this patch] > > The complete patch is at: > > https://github.com/96boards-hikey/linux/commit/08464419fba2 > > Signed-off-by: Mayulong > Signed-off-by: Mauro Carvalho Chehab > --- > .../staging/hikey9xx/hisi-spmi-controller.c | 390 ++ > 1 file changed, 390 insertions(+) > create mode 100644 drivers/staging/hikey9xx/hisi-spmi-controller.c > > diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c > b/drivers/staging/hikey9xx/hisi-spmi-controller.c > new file mode 100644 > index ..987526c8b49f > --- /dev/null > +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c > @@ -0,0 +1,390 @@ > + > +#include No SPDX line at all? :( ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 06/44] staging: spmi: hisi-spmi-controller: use le32 macros where needed
On Wed, 2020-08-12 at 17:56 +0200, Mauro Carvalho Chehab wrote: > Instead of manually using bswap_32(), just use the > le32 macros. Are you certain this code will now work on any endian cpu? Maybe just use __swab32 instead > diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c > b/drivers/staging/hikey9xx/hisi-spmi-controller.c [] > @@ -43,11 +42,6 @@ > #define SPMI_APB_SPMI_CMD_TYPE_OFFSET24 > #define SPMI_APB_SPMI_CMD_LENGTH_OFFSET 20 > > -#define bswap_32(X) \ > -u32)(X) & 0xff00) >> 24) | \ > - (((u32)(X) & 0x00ff) >> 8) | \ > - (((u32)(X) & 0xff00) << 8) | \ > - (((u32)(X) & 0x00ff) << 24)) > #define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 > #define SPMI_APB_SPMI_CMD_ADDR_OFFSET0 > > @@ -179,14 +173,15 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, > > writel(cmd, spmi_controller->base + chnl_ofst + > SPMI_APB_SPMI_CMD_BASE_ADDR); > > - rc = spmi_controller_wait_for_done(spmi_controller, > spmi_controller->base, sid, addr); > + rc = spmi_controller_wait_for_done(spmi_controller, > +spmi_controller->base, sid, addr); > if (rc) > goto done; > > i = 0; > do { > data = readl(spmi_controller->base + chnl_ofst + > SPMI_SLAVE_OFFSET * sid + SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * > SPMI_PER_DATAREG_BYTE); > - data = bswap_32(data); > + data = be32_to_cpu((__be32)data); > if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { > memcpy(buf, &data, sizeof(data)); > buf += sizeof(data); > @@ -210,8 +205,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > { > struct spmi_controller_dev *spmi_controller = > dev_get_drvdata(&ctrl->dev); > unsigned long flags; > - u32 cmd; > - u32 data = 0; > + u32 cmd, data; > int rc; > u32 chnl_ofst = SPMI_CHANNEL_OFFSET * spmi_controller->channel; > u8 op_code, i; > @@ -246,7 +240,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > > i = 0; > do { > - memset(&data, 0, sizeof(data)); > + data = 0; > if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { > memcpy(&data, buf, sizeof(data)); > buf += sizeof(data); > @@ -255,8 +249,8 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > buf += (bc % SPMI_PER_DATAREG_BYTE); > } > > - data = bswap_32(data); > - writel(data, spmi_controller->base + chnl_ofst + > SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); > + writel((u32)cpu_to_be32(data), > +spmi_controller->base + chnl_ofst + > SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); > i++; > } while (bc > i * SPMI_PER_DATAREG_BYTE); > ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 00/44] SPMI patches needed by Hikey 970
Perhaps these trivial bits on top: --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 5 +++-- drivers/staging/hikey9xx/hi6421v600-regulator.c | 6 +++--- drivers/staging/hikey9xx/hisi-spmi-controller.c | 21 + 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 76766e7b8bf9..9d73458ca65a 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -99,7 +99,7 @@ int hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, int reg, u32 val) EXPORT_SYMBOL(hi6421_spmi_pmic_write); int hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, - u32 mask, u32 bits) +u32 mask, u32 bits) { unsigned long flags; u32 data; @@ -130,7 +130,8 @@ static irqreturn_t hi6421_spmi_irq_handler(int irq, void *data) hi6421_spmi_pmic_write(pmic, (i + pmic->irq_addr), pending); /* solve powerkey order */ - if ((i == HISI_IRQ_KEY_NUM) && ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { + if ((i == HISI_IRQ_KEY_NUM) && + ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_DOWN]); generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_UP]); pending &= (~HISI_IRQ_KEY_VALUE); diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index 29ef6bcadd84..82635ff54a74 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -227,7 +227,7 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, ret = of_property_read_u32(np, "reg", &rdesc->enable_reg); if (ret) { - dev_err(dev, "missing reg property\nn"); + dev_err(dev, "missing reg property\n"); return ret; } @@ -303,13 +303,13 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, */ rdesc->vsel_mask = (1 << (fls(rdesc->n_voltages) - 1)) - 1; - dev_dbg(dev, "voltage selector settings: reg: 0x%x, mask: 0x%x", + dev_dbg(dev, "voltage selector settings: reg: 0x%x, mask: 0x%x\n", rdesc->vsel_reg, rdesc->vsel_mask); return 0; } -static struct regulator_ops hi6421_spmi_ldo_rops = { +static const struct regulator_ops hi6421_spmi_ldo_rops = { .is_enabled = hi6421_spmi_regulator_is_enabled, .enable = hi6421_spmi_regulator_enable, .disable = hi6421_spmi_regulator_disable, diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c b/drivers/staging/hikey9xx/hisi-spmi-controller.c index 583df10cbf1a..513d962b8bce 100644 --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c @@ -102,7 +102,7 @@ static int spmi_controller_wait_for_done(struct device *dev, return 0; } udelay(1); - } while(timeout--); + } while (timeout--); dev_err(dev, "%s: timeout, status 0x%x\n", __func__, status); return -ETIMEDOUT; @@ -121,7 +121,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, if (bc > SPMI_CONTROLLER_MAX_TRANS_BYTES) { dev_err(&ctrl->dev, - "spmi_controller supports 1..%d bytes per trans, but:%ld requested", + "spmi_controller supports 1..%d bytes per trans, but:%ld requested\n", SPMI_CONTROLLER_MAX_TRANS_BYTES, bc); return -EINVAL; } @@ -137,7 +137,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, op_code = SPMI_CMD_EXT_REG_READ_L; break; default: - dev_err(&ctrl->dev, "invalid read cmd 0x%x", opc); + dev_err(&ctrl->dev, "invalid read cmd 0x%x\n", opc); return -EINVAL; } @@ -157,7 +157,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, goto done; for (i = 0; bc > i * SPMI_PER_DATAREG_BYTE; i++) { - data = readl(spmi_controller->base + chnl_ofst + SPMI_SLAVE_OFFSET * slave_id + SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * SPMI_PER_DATAREG_BYTE); + data = readl(spmi_controller->base + chnl_ofst + +SPMI_SLAVE_OFFSET * slave_id + +SPMI_APB_SPMI_RDATA0_BASE_ADDR + +i * SPMI_PER_DATAREG_BYTE); data = be32_to_cpu((__be32)data); if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { memcpy(buf, &data, sizeof(data)); @@ -194,7 +197,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, if (bc > SPMI_CONTROLLER_MAX_
Re: [PATCH 00/44] SPMI patches needed by Hikey 970
Em Wed, 12 Aug 2020 10:13:51 -0700 Joe Perches escreveu: > Perhaps these trivial bits on top: Sounds fine for me. Feel free to send it with your SOB, adding my reviewed by: Reviewed-by: Mauro Carvalho Chehab > --- > drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 5 +++-- > drivers/staging/hikey9xx/hi6421v600-regulator.c | 6 +++--- > drivers/staging/hikey9xx/hisi-spmi-controller.c | 21 + > 3 files changed, 19 insertions(+), 13 deletions(-) > > diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c > b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c > index 76766e7b8bf9..9d73458ca65a 100644 > --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c > +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c > @@ -99,7 +99,7 @@ int hi6421_spmi_pmic_write(struct hi6421_spmi_pmic *pmic, > int reg, u32 val) > EXPORT_SYMBOL(hi6421_spmi_pmic_write); > > int hi6421_spmi_pmic_rmw(struct hi6421_spmi_pmic *pmic, int reg, > - u32 mask, u32 bits) > + u32 mask, u32 bits) > { > unsigned long flags; > u32 data; > @@ -130,7 +130,8 @@ static irqreturn_t hi6421_spmi_irq_handler(int irq, void > *data) > hi6421_spmi_pmic_write(pmic, (i + pmic->irq_addr), pending); > > /* solve powerkey order */ > - if ((i == HISI_IRQ_KEY_NUM) && ((pending & HISI_IRQ_KEY_VALUE) > == HISI_IRQ_KEY_VALUE)) { > + if ((i == HISI_IRQ_KEY_NUM) && > + ((pending & HISI_IRQ_KEY_VALUE) == HISI_IRQ_KEY_VALUE)) { > generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_DOWN]); > generic_handle_irq(pmic->irqs[HISI_IRQ_KEY_UP]); > pending &= (~HISI_IRQ_KEY_VALUE); > diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c > b/drivers/staging/hikey9xx/hi6421v600-regulator.c > index 29ef6bcadd84..82635ff54a74 100644 > --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c > +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c > @@ -227,7 +227,7 @@ static int hi6421_spmi_dt_parse(struct platform_device > *pdev, > > ret = of_property_read_u32(np, "reg", &rdesc->enable_reg); > if (ret) { > - dev_err(dev, "missing reg property\nn"); > + dev_err(dev, "missing reg property\n"); > return ret; > } > > @@ -303,13 +303,13 @@ static int hi6421_spmi_dt_parse(struct platform_device > *pdev, >*/ > rdesc->vsel_mask = (1 << (fls(rdesc->n_voltages) - 1)) - 1; > > - dev_dbg(dev, "voltage selector settings: reg: 0x%x, mask: 0x%x", > + dev_dbg(dev, "voltage selector settings: reg: 0x%x, mask: 0x%x\n", > rdesc->vsel_reg, rdesc->vsel_mask); > > return 0; > } > > -static struct regulator_ops hi6421_spmi_ldo_rops = { > +static const struct regulator_ops hi6421_spmi_ldo_rops = { > .is_enabled = hi6421_spmi_regulator_is_enabled, > .enable = hi6421_spmi_regulator_enable, > .disable = hi6421_spmi_regulator_disable, > diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c > b/drivers/staging/hikey9xx/hisi-spmi-controller.c > index 583df10cbf1a..513d962b8bce 100644 > --- a/drivers/staging/hikey9xx/hisi-spmi-controller.c > +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c > @@ -102,7 +102,7 @@ static int spmi_controller_wait_for_done(struct device > *dev, > return 0; > } > udelay(1); > - } while(timeout--); > + } while (timeout--); > > dev_err(dev, "%s: timeout, status 0x%x\n", __func__, status); > return -ETIMEDOUT; > @@ -121,7 +121,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, > > if (bc > SPMI_CONTROLLER_MAX_TRANS_BYTES) { > dev_err(&ctrl->dev, > - "spmi_controller supports 1..%d bytes per trans, > but:%ld requested", > + "spmi_controller supports 1..%d bytes per trans, > but:%ld requested\n", > SPMI_CONTROLLER_MAX_TRANS_BYTES, bc); > return -EINVAL; > } > @@ -137,7 +137,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, > op_code = SPMI_CMD_EXT_REG_READ_L; > break; > default: > - dev_err(&ctrl->dev, "invalid read cmd 0x%x", opc); > + dev_err(&ctrl->dev, "invalid read cmd 0x%x\n", opc); > return -EINVAL; > } > > @@ -157,7 +157,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, > goto done; > > for (i = 0; bc > i * SPMI_PER_DATAREG_BYTE; i++) { > - data = readl(spmi_controller->base + chnl_ofst + > SPMI_SLAVE_OFFSET * slave_id + SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * > SPMI_PER_DATAREG_BYTE); > + data = readl(spmi_controller->base + chnl_ofst + > + SPMI_SLAVE_OFFSET * slave_id + > + SPMI_APB_SPMI_RDATA0_BASE_ADDR + > + i * SPMI_PER_DATAREG
Re: [PATCH 01/44] staging: spmi: add Hikey 970 SPMI controller driver
Em Wed, 12 Aug 2020 18:28:14 +0200 Greg Kroah-Hartman escreveu: > On Wed, Aug 12, 2020 at 05:56:11PM +0200, Mauro Carvalho Chehab wrote: > > From: Mayulong > > > > Add the SPMI controller code required to use the Kirin 970 > > SPMI bus. > > > > [mchehab+hua...@kernel.org: added just the SPMI controller on this patch] > > > > The complete patch is at: > > > > https://github.com/96boards-hikey/linux/commit/08464419fba2 > > > > Signed-off-by: Mayulong > > Signed-off-by: Mauro Carvalho Chehab > > --- > > .../staging/hikey9xx/hisi-spmi-controller.c | 390 ++ > > 1 file changed, 390 insertions(+) > > create mode 100644 drivers/staging/hikey9xx/hisi-spmi-controller.c > > > > diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c > > b/drivers/staging/hikey9xx/hisi-spmi-controller.c > > new file mode 100644 > > index ..987526c8b49f > > --- /dev/null > > +++ b/drivers/staging/hikey9xx/hisi-spmi-controller.c > > @@ -0,0 +1,390 @@ > > + > > +#include > > > > No SPDX line at all? > > :( This is added later on at this series. The first patch came from a 4.9 tree, where such tags weren't used yet. The next patches on this series will add SPDX to all files. Regards, Mauro ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 06/44] staging: spmi: hisi-spmi-controller: use le32 macros where needed
Em Wed, 12 Aug 2020 09:21:54 -0700 Joe Perches escreveu: > On Wed, 2020-08-12 at 17:56 +0200, Mauro Carvalho Chehab wrote: > > Instead of manually using bswap_32(), just use the > > le32 macros. > > Are you certain this code will now work on any endian cpu? > > Maybe just use __swab32 instead Well, I didn't test, because this driver is for an specific hardware (arm64). Yet, what happens in practice is that just one byte is written by the PMIC drivers. If the order is not LE, the byte written at the buffer will always be zero. > > > diff --git a/drivers/staging/hikey9xx/hisi-spmi-controller.c > > b/drivers/staging/hikey9xx/hisi-spmi-controller.c > [] > > @@ -43,11 +42,6 @@ > > #define SPMI_APB_SPMI_CMD_TYPE_OFFSET 24 > > #define SPMI_APB_SPMI_CMD_LENGTH_OFFSET20 > > > > -#define bswap_32(X) \ > > -u32)(X) & 0xff00) >> 24) | \ > > - (((u32)(X) & 0x00ff) >> 8) | \ > > - (((u32)(X) & 0xff00) << 8) | \ > > - (((u32)(X) & 0x00ff) << 24)) > > #define SPMI_APB_SPMI_CMD_SLAVEID_OFFSET 16 > > #define SPMI_APB_SPMI_CMD_ADDR_OFFSET 0 > > > > @@ -179,14 +173,15 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, > > > > writel(cmd, spmi_controller->base + chnl_ofst + > > SPMI_APB_SPMI_CMD_BASE_ADDR); > > > > - rc = spmi_controller_wait_for_done(spmi_controller, > > spmi_controller->base, sid, addr); > > + rc = spmi_controller_wait_for_done(spmi_controller, > > + spmi_controller->base, sid, addr); > > if (rc) > > goto done; > > > > i = 0; > > do { > > data = readl(spmi_controller->base + chnl_ofst + > > SPMI_SLAVE_OFFSET * sid + SPMI_APB_SPMI_RDATA0_BASE_ADDR + i * > > SPMI_PER_DATAREG_BYTE); > > - data = bswap_32(data); > > + data = be32_to_cpu((__be32)data); > > if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { > > memcpy(buf, &data, sizeof(data)); > > buf += sizeof(data); > > @@ -210,8 +205,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > > { > > struct spmi_controller_dev *spmi_controller = > > dev_get_drvdata(&ctrl->dev); > > unsigned long flags; > > - u32 cmd; > > - u32 data = 0; > > + u32 cmd, data; > > int rc; > > u32 chnl_ofst = SPMI_CHANNEL_OFFSET * spmi_controller->channel; > > u8 op_code, i; > > @@ -246,7 +240,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > > > > i = 0; > > do { > > - memset(&data, 0, sizeof(data)); > > + data = 0; > > if ((bc - i * SPMI_PER_DATAREG_BYTE) >> 2) { > > memcpy(&data, buf, sizeof(data)); > > buf += sizeof(data); > > @@ -255,8 +249,8 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, > > buf += (bc % SPMI_PER_DATAREG_BYTE); > > } > > > > - data = bswap_32(data); > > - writel(data, spmi_controller->base + chnl_ofst + > > SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); > > + writel((u32)cpu_to_be32(data), > > + spmi_controller->base + chnl_ofst + > > SPMI_APB_SPMI_WDATA0_BASE_ADDR + SPMI_PER_DATAREG_BYTE * i); > > i++; > > } while (bc > i * SPMI_PER_DATAREG_BYTE); > > > ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 00/44] SPMI patches needed by Hikey 970
Em Wed, 12 Aug 2020 11:58:55 -0700 Joe Perches escreveu: > On Wed, 2020-08-12 at 15:47 -0300, Mauro Carvalho Chehab wrote: > > Em Wed, 12 Aug 2020 10:13:51 -0700 > > Joe Perches escreveu: > > > > > Perhaps these trivial bits on top: > > > > Sounds fine for me. Feel free to send it with your SOB, adding my reviewed > > by: > > > > Reviewed-by: Mauro Carvalho Chehab > > I don't know that your original > series is going to be applied as-is > so I think you should carry it. Ok. I'll then add the hunks you wrote to the affected changesets. > > cheers, Joe > > ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 00/44] SPMI patches needed by Hikey 970
On Wed, 2020-08-12 at 15:47 -0300, Mauro Carvalho Chehab wrote: > Em Wed, 12 Aug 2020 10:13:51 -0700 > Joe Perches escreveu: > > > Perhaps these trivial bits on top: > > Sounds fine for me. Feel free to send it with your SOB, adding my reviewed by: > > Reviewed-by: Mauro Carvalho Chehab I don't know that your original series is going to be applied as-is so I think you should carry it. cheers, Joe ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH] staging: rtl8723bs: remove 5 GHz code
According to the TODO 5 GHz code should be removed. - find and remove remaining code valid only for 5 GHz. Most of the obvious ones have been removed, but things like channel > 14 still exist. Remove code for channels > 14 from rtw_get_center_ch(). Signed-off-by: Michael Straube --- drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 15 +-- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c index a3ea7ce3e12e..a5790a648a5b 100644 --- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c +++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c @@ -374,20 +374,7 @@ u8 rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset) u8 center_ch = channel; if (chnl_bw == CHANNEL_WIDTH_80) { - if ((channel == 36) || (channel == 40) || (channel == 44) || (channel == 48)) - center_ch = 42; - if ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64)) - center_ch = 58; - if ((channel == 100) || (channel == 104) || (channel == 108) || (channel == 112)) - center_ch = 106; - if ((channel == 116) || (channel == 120) || (channel == 124) || (channel == 128)) - center_ch = 122; - if ((channel == 132) || (channel == 136) || (channel == 140) || (channel == 144)) - center_ch = 138; - if ((channel == 149) || (channel == 153) || (channel == 157) || (channel == 161)) - center_ch = 155; - else if (channel <= 14) - center_ch = 7; + center_ch = 7; } else if (chnl_bw == CHANNEL_WIDTH_40) { if (chnl_offset == HAL_PRIME_CHNL_OFFSET_LOWER) center_ch = channel + 2; -- 2.28.0 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel