power: supply: sc27xx: Add missing MODULE_DEVICE_TABLE
Subsystems (6)
Sasha Levin
maintainerPATCH 1/53 power: supply: sc27xx: Add missing MODULE_DEVICE_TABLE
From: Zou Wei <[email protected]>
[ Upstream commit 603fcfb9d4ec1cad8d66d3bb37f3613afa8a661a ]
This patch adds missing MODULE_DEVICE_TABLE definition which generates correct modalias for automatic loading of this driver when it is built as an external module.
--- drivers/power/supply/sc27xx_fuel_gauge.c | 1 + 1 file changed, 1 insertion(+)
drivers/power/supply/sc27xx_fuel_gauge.c +1 -0
@@ -1342,6 +1342,7 @@ static const struct of_device_id sc27xx_fgu_of_match[] = { { .compatible = "sprd,sc2731-fgu", }, { } }; +MODULE_DEVICE_TABLE (of, sc27xx_fgu_of_match);static struct platform_driver sc27xx_fgu_driver = { .probe = sc27xx_fgu_probe,
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 2/53 power: supply: sc2731_charger: Add missing MODULE_DEVICE_TABLE
From: Zou Wei <[email protected]>
[ Upstream commit 2aac79d14d76879c8e307820b31876e315b1b242 ]
This patch adds missing MODULE_DEVICE_TABLE definition which generates correct modalias for automatic loading of this driver when it is built as an external module.
--- drivers/power/supply/sc2731_charger.c | 1 + 1 file changed, 1 insertion(+)
drivers/power/supply/sc2731_charger.c +1 -0
@@ -524,6 +524,7 @@ static const struct of_device_id sc2731_charger_of_match[] = { { .compatible = "sprd,sc2731-charger", }, { } }; +MODULE_DEVICE_TABLE (of, sc2731_charger_of_match);static struct platform_driver sc2731_charger_driver = { .driver = {
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 3/53 f2fs: fix to avoid racing on fsync_entry_slab by multi filesystem instances
In reply to Sasha LevinFrom: Chao Yu <[email protected]>
[ Upstream commit cad83c968c2ebe97905f900326988ed37146c347 ]
As syzbot reported, there is an use-after-free issue during f2fs recovery:
Use-after-free write at 0xffff88823bc16040 (in kfence-#10):
kmem_cache_destroy+0x1f/0x120 mm/slab_common.c:486 f2fs_recover_fsync_data+0x75b0/0x8380 fs/f2fs/recovery.c:869 f2fs_fill_super+0x9393/0xa420 fs/f2fs/super.c:3945 mount_bdev+0x26c/0x3a0 fs/super.c:1367 legacy_get_tree+0xea/0x180 fs/fs_context.c:592 vfs_get_tree+0x86/0x270 fs/super.c:1497 do_new_mount fs/namespace.c:2905 [inline] path_mount+0x196f/0x2be0 fs/namespace.c:3235 do_mount fs/namespace.c:3248 [inline] __do_sys_mount fs/namespace.c:3456 [inline] __se_sys_mount+0x2f9/0x3b0 fs/namespace.c:3433 do_syscall_64+0x3f/0xb0 arch/x86/entry/common.c:47 entry_SYSCALL_64_after_hwframe+0x44/0xae
The root cause is multi f2fs filesystem instances can race on accessing global fsync_entry_slab pointer, result in use-after-free issue of slab cache, fixes to init/destroy this slab cache only once during module init/destroy procedure to avoid this issue.
--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/recovery.c | 23 ++++++++++++++--------- fs/f2fs/super.c | 8 +++++++- 3 files changed, 23 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -0
@@ -3566,6 +3566,8 @@ void f2fs_destroy_garbage_collection_cache(void);*/ int f2fs_recover_fsync_data (struct f2fs_sb_info *sbi,bool check_only);bool f2fs_space_for_roll_forward (struct f2fs_sb_info *sbi); +int __init f2fs_create_recovery_cache (void ); +void f2fs_destroy_recovery_cache (void );/* * debug.c
fs/f2fs/recovery.c +14 -9
@@ -788,13 +788,6 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only) quota_enabled =f2fs_enable_quota_files (sbi, s_flags &SB_RDONLY );#endif - fsync_entry_slab =f2fs_kmem_cache_create ("f2fs_fsync_inode_entry" , -sizeof (struct fsync_inode_entry )); -if (!fsync_entry_slab) { - err = -ENOMEM ; - goto out; - } -INIT_LIST_HEAD (&inode_list);INIT_LIST_HEAD (&tmp_inode_list);INIT_LIST_HEAD (&dir_list);
@@ -867,8 +860,6 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only) } } -kmem_cache_destroy (fsync_entry_slab); -out:#ifdef CONFIG_QUOTA /* Turn quotas off */ if (quota_enabled)
@@ -878,3 +869,17 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)return ret ? ret : err; } + +int __init f2fs_create_recovery_cache (void ) +{ + fsync_entry_slab =f2fs_kmem_cache_create ("f2fs_fsync_inode_entry" , +sizeof (struct fsync_inode_entry )); +if (!fsync_entry_slab) +return -ENOMEM ; +return 0 ; +} + +void f2fs_destroy_recovery_cache (void ) +{ +kmem_cache_destroy (fsync_entry_slab); +}
fs/f2fs/super.c +7 -1
@@ -4227,9 +4227,12 @@ static int __init init_f2fs_fs(void) err =f2fs_create_checkpoint_caches ();if (err) goto free_segment_manager_caches; - err =f2fs_create_extent_cache (); + err =f2fs_create_recovery_cache ();if (err) goto free_checkpoint_caches; + err =f2fs_create_extent_cache (); +if (err) + goto free_recovery_cache; err =f2fs_create_garbage_collection_cache ();if (err) goto free_extent_cache;
@@ -4278,6 +4281,8 @@ static int __init init_f2fs_fs(void)f2fs_destroy_garbage_collection_cache (); free_extent_cache:f2fs_destroy_extent_cache (); +free_recovery_cache: +f2fs_destroy_recovery_cache (); free_checkpoint_caches:f2fs_destroy_checkpoint_caches (); free_segment_manager_caches:
@@ -4303,6 +4308,7 @@ static void __exit exit_f2fs_fs(void)f2fs_exit_sysfs ();f2fs_destroy_garbage_collection_cache ();f2fs_destroy_extent_cache (); +f2fs_destroy_recovery_cache ();f2fs_destroy_checkpoint_caches ();f2fs_destroy_segment_manager_caches ();f2fs_destroy_node_manager_caches ();
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 4/53 pwm: spear: Don't modify HW state in .remove callback
In reply to Sasha LevinFrom: Uwe Kleine-König <[email protected]>
[ Upstream commit b601a18f12383001e7a8da238de7ca1559ebc450 ]
A consumer is expected to disable a PWM before calling pwm_put(). And if they didn't there is hopefully a good reason (or the consumer needs fixing). Also if disabling an enabled PWM was the right thing to do, this should better be done in the framework instead of in each low level driver.
So drop the hardware modification from the .remove() callback.
--- drivers/pwm/pwm-spear.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/pwm/pwm-spear.c +0 -4
@@ -228,10 +228,6 @@ static int spear_pwm_probe(struct platform_device *pdev)static int spear_pwm_remove (struct platform_device *pdev) {struct spear_pwm_chip *pc =platform_get_drvdata (pdev); -int i; - -for (i =0 ; i <NUM_PWM ; i++) -pwm_disable (&pc->chip.pwms[i]);/* clk was prepared in probe, hence unprepare it here */ clk_unprepare (pc->clk);
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 5/53 PCI: ftpci100: Rename macro name collision
In reply to Sasha LevinFrom: Randy Dunlap <[email protected]>
[ Upstream commit 5be967d5016ac5ffb9c4d0df51b48441ee4d5ed1 ]
PCI_IOSIZE is defined in mach-loongson64/spaces.h, so change the name of the PCI_* macros in pci-ftpci100.c to use FTPCI_* so that they are more localized and won't conflict with other drivers or arches.
../drivers/pci/controller/pci-ftpci100.c:37: warning: "PCI_IOSIZE" redefined
37 | #define PCI_IOSIZE 0x00
|
In file included from ../arch/mips/include/asm/addrspace.h:13,
... from ../drivers/pci/controller/pci-ftpci100.c:15:arch/mips/include/asm/mach-loongson64/spaces.h:11: note: this is the location of the previous definition
11 | #define PCI_IOSIZE SZ_16M
--- drivers/pci/controller/pci-ftpci100.c | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/pci/controller/pci-ftpci100.c +15 -15
@@ -34,12 +34,12 @@* Special configuration registers directly in the first few words * in I/O space. */ -#define PCI_IOSIZE 0x00 -#define PCI_PROT 0x04/* AHB protection */ -#define PCI_CTRL 0x08/* PCI control signal */ -#define PCI_SOFTRST 0x10/* Soft reset counter and response error enable */ -#define PCI_CONFIG 0x28/* PCI configuration command register */ -#define PCI_DATA 0x2C +#define FTPCI_IOSIZE 0x00 +#define FTPCI_PROT 0x04/* AHB protection */ +#define FTPCI_CTRL 0x08/* PCI control signal */ +#define FTPCI_SOFTRST 0x10/* Soft reset counter and response error enable */ +#define FTPCI_CONFIG 0x28/* PCI configuration command register */ +#define FTPCI_DATA 0x2C#define FARADAY_PCI_STATUS_CMD 0x04/* Status and command */ #define FARADAY_PCI_PMC 0x40/* Power management control */
@@ -195,9 +195,9 @@ static int faraday_raw_pci_read_config(struct faraday_pci *p, int bus_number,PCI_CONF_FUNCTION (PCI_FUNC (fn)) |PCI_CONF_WHERE (config) |PCI_CONF_ENABLE , - p->base + PCI_CONFIG); + p->base + FTPCI_CONFIG); - *value =readl (p->base +PCI_DATA ); + *value =readl (p->base +FTPCI_DATA );if (size ==1 ) *value = (*value >> (8 * (config &3 ))) &0xFF ;
@@ -230,17 +230,17 @@ static int faraday_raw_pci_write_config(struct faraday_pci *p, int bus_number,PCI_CONF_FUNCTION (PCI_FUNC (fn)) |PCI_CONF_WHERE (config) |PCI_CONF_ENABLE , - p->base + PCI_CONFIG); + p->base + FTPCI_CONFIG);switch (size) {case 4 : -writel (value, p->base +PCI_DATA ); +writel (value, p->base +FTPCI_DATA );break ;case 2 : -writew (value, p->base +PCI_DATA + (config &3 )); +writew (value, p->base +FTPCI_DATA + (config &3 ));break ;case 1 : -writeb (value, p->base +PCI_DATA + (config &3 )); +writeb (value, p->base +FTPCI_DATA + (config &3 ));break ;default : ret =PCIBIOS_BAD_REGISTER_NUMBER ;
@@ -469,7 +469,7 @@ static int faraday_pci_probe(struct platform_device *pdev)if (!faraday_res_to_memcfg (io->start - win->offset,resource_size (io), &val)) {/* setup I/O space size */ -writel (val, p->base +PCI_IOSIZE ); +writel (val, p->base +FTPCI_IOSIZE ); }else {dev_err (dev,"illegal IO mem size\n" );return -EINVAL ;
@@ -477,11 +477,11 @@ static int faraday_pci_probe(struct platform_device *pdev) }/* Setup hostbridge */ - val =readl (p->base +PCI_CTRL ); + val =readl (p->base +FTPCI_CTRL ); val |=PCI_COMMAND_IO ; val |=PCI_COMMAND_MEMORY ; val |=PCI_COMMAND_MASTER ; -writel (val, p->base +PCI_CTRL ); +writel (val, p->base +FTPCI_CTRL );/* Mask and clear all interrupts */ faraday_raw_pci_write_config (p,0 ,0 ,FARADAY_PCI_CTRL2 +2 ,2 ,0xF000 );if (variant->cascaded_irq) {
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 6/53 power: supply: ab8500: Move to componentized binding
In reply to Sasha LevinFrom: Linus Walleij <[email protected]>
[ Upstream commit 1c1f13a006ed0d71bb5664c8b7e3e77a28da3beb ]
The driver has problems with the different components of the charging code racing with each other to probe().
This results in all four subdrivers populating battery information to ascertain that it is populated for their own needs for example.
Fix this by using component probing and thus expressing to the kernel that these are dependent components. The probes can happen in any order and will only acquire resources such as state container, regulators and interrupts and initialize the data structures, but no execution happens until the .bind() callback is called.
The charging driver is the main component and binds first, then bind in order the three subcomponents:
ab8500-fg, ab8500-btemp and ab8500-chargalg.
Do some housekeeping while we are moving the code around. Like use devm_* for IRQs so as to cut down on some boilerplate.
--- drivers/power/supply/ab8500-bm.h | 4 + drivers/power/supply/ab8500_btemp.c | 118 ++++----- drivers/power/supply/ab8500_charger.c | 339 ++++++++++++++----------- drivers/power/supply/ab8500_fg.c | 136 +++++----- drivers/power/supply/abx500_chargalg.c | 116 +++++---- 5 files changed, 379 insertions(+), 334 deletions(-)
drivers/power/supply/ab8500-bm.h +4 -0
@@ -730,4 +730,8 @@ int ab8500_bm_of_probe(struct device *dev,struct device_node *np, struct abx500_bm_data *bm); +extern struct platform_driver ab8500_fg_driver; +extern struct platform_driver ab8500_btemp_driver; +extern struct platform_driver abx500_chargalg_driver; +#endif /* _AB8500_CHARGER_H_ */
drivers/power/supply/ab8500_btemp.c +51 -67
190 lines not on this page · raw message
drivers/power/supply/ab8500_charger.c +196 -143
467 lines not on this page · raw message
drivers/power/supply/ab8500_fg.c +64 -72
227 lines not on this page · raw message
drivers/power/supply/abx500_chargalg.c +64 -52
194 lines not on this page · raw message
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 7/53 power: supply: ab8500: Avoid NULL pointers
In reply to Sasha LevinFrom: Linus Walleij <[email protected]>
[ Upstream commit 5bcb5087c9dd3dca1ff0ebd8002c5313c9332b56 ]
Sometimes the code will crash because we haven't enabled AC or USB charging and thus not created the corresponding psy device. Fix it by checking that it is there before notifying.
--- drivers/power/supply/ab8500_charger.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/power/supply/ab8500_charger.c +17 -1
@@ -415,6 +415,14 @@ static void ab8500_enable_disable_sw_fallback(struct ab8500_charger *di,static void ab8500_power_supply_changed (struct ab8500_charger *di,struct power_supply *psy) { +/* +* This happens if we get notifications or interrupts and +* the platform has been configured not to support one or +* other type of charging. +*/ +if (!psy) +return ; +if (di->autopower_cfg) { if (!di->usb.charger_connected && !di->ac.charger_connected &&
@@ -441,7 +449,15 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,if (!connected) di->flags.vbus_drop_end = false; -sysfs_notify (&di->usb_chg.psy->dev.kobj,NULL ,"present" ); +/* +* Sometimes the platform is configured not to support +* USB charging and no psy has been created, but we still +* will get these notifications. +*/ +if (di->usb_chg.psy) { +sysfs_notify (&di->usb_chg.psy->dev.kobj,NULL , +"present" ); + }if (connected) {mutex_lock (&di->charger_attached_mutex);
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 8/53 power: supply: ab8500: Enable USB and AC
In reply to Sasha LevinFrom: Linus Walleij <[email protected]>
[ Upstream commit f9184a228d7a60ad56b810d549a7debb355f1be6 ]
The vendor code tree supplies platform data to enable he USB charging for AB8500 and AB8500 and disable the AC charging on the AB8505. This was missed when the driver was submitted to the mainline kernel.
Fix this by doing what the vendor kernel does: always register the USB charger, do not register the AC charger on the AB8505.
--- drivers/power/supply/ab8500-bm.h | 2 -- drivers/power/supply/ab8500_charger.c | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-)
drivers/power/supply/ab8500-bm.h +0 -2
@@ -507,8 +507,6 @@ struct abx500_bm_data {int bkup_bat_v;int bkup_bat_i;bool autopower_cfg; -bool ac_enabled; -bool usb_enabled;bool no_maintenance;bool capacity_scaling;bool chg_unknown_bat;
drivers/power/supply/ab8500_charger.c +14 -10
@@ -3511,7 +3511,14 @@ static int ab8500_charger_probe(struct platform_device *pdev) di->ac_chg.max_out_curr = di->bm->chg_output_curr[di->bm->n_chg_out_curr -1 ]; di->ac_chg.wdt_refresh =CHG_WD_INTERVAL ; - di->ac_chg.enabled = di->bm->ac_enabled; +/* +* The AB8505 only supports USB charging. If we are not the +* AB8505, register an AC charger. +* +* TODO: if this should be opt-in, add DT properties for this. +*/ +if (!is_ab8505 (di->parent)) + di->ac_chg.enabled = true; di->ac_chg.external = false;/* USB supply */
@@ -3525,7 +3532,6 @@ static int ab8500_charger_probe(struct platform_device *pdev) di->usb_chg.max_out_curr = di->bm->chg_output_curr[di->bm->n_chg_out_curr -1 ]; di->usb_chg.wdt_refresh =CHG_WD_INTERVAL ; - di->usb_chg.enabled = di->bm->usb_enabled; di->usb_chg.external = false; di->usb_state.usb_current =-1 ;
@@ -3599,14 +3605,12 @@ static int ab8500_charger_probe(struct platform_device *pdev) }/* Register USB charger class */ -if (di->usb_chg.enabled) { - di->usb_chg.psy =devm_power_supply_register (dev, - &ab8500_usb_chg_desc, - &usb_psy_cfg); -if (IS_ERR (di->usb_chg.psy)) { -dev_err (dev,"failed to register USB charger\n" ); -return PTR_ERR (di->usb_chg.psy); - } + di->usb_chg.psy =devm_power_supply_register (dev, + &ab8500_usb_chg_desc, + &usb_psy_cfg); +if (IS_ERR (di->usb_chg.psy)) { +dev_err (dev,"failed to register USB charger\n" ); +return PTR_ERR (di->usb_chg.psy); }/* Identify the connected charger types during startup */
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 9/53 PCI: hv: Fix a race condition when removing the device
In reply to Sasha LevinFrom: Long Li <[email protected]>
[ Upstream commit 94d22763207ac6633612b8d8e0ca4fba0f7aa139 ]
On removing the device, any work item (hv_pci_devices_present() or hv_pci_eject_device()) scheduled on workqueue hbus->wq may still be running and race with hv_pci_remove().
This can happen because the host may send PCI_EJECT or PCI_BUS_RELATIONS(2) and decide to rescind the channel immediately after that.
Fix this by flushing/destroying the workqueue of hbus before doing hbus remove.
--- drivers/pci/controller/pci-hyperv.c | 30 ++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
drivers/pci/controller/pci-hyperv.c +23 -7
@@ -444,7 +444,6 @@ enum hv_pcibus_state { hv_pcibus_probed, hv_pcibus_installed, hv_pcibus_removing, - hv_pcibus_removed, hv_pcibus_maximum };
@@ -3243,8 +3242,9 @@ static int hv_pci_bus_exit(struct hv_device *hdev, bool keep_devs)struct pci_packet teardown_packet;u8 buffer[sizeof (struct pci_message )]; } pkt; -struct hv_dr_state *dr;struct hv_pci_compl comp_pkt; +struct hv_pci_dev *hpdev, *tmp; +unsigned long flags;int ret;/*
@@ -3256,9 +3256,16 @@ static int hv_pci_bus_exit(struct hv_device *hdev, bool keep_devs)if (!keep_devs) {/* Delete any children which might still exist. */ - dr =kzalloc (sizeof (*dr),GFP_KERNEL ); -if (dr &&hv_pci_start_relations_work (hbus, dr)) -kfree (dr); +spin_lock_irqsave (&hbus->device_list_lock, flags); +list_for_each_entry_safe (hpdev, tmp, &hbus->children, list_entry) { +list_del (&hpdev->list_entry); +if (hpdev->pci_slot) +pci_destroy_slot (hpdev->pci_slot); +/* For the two refs got in new_pcichild_device() */ +put_pcichild (hpdev); +put_pcichild (hpdev); + } +spin_unlock_irqrestore (&hbus->device_list_lock, flags); } ret =hv_send_resources_released (hdev);
@@ -3301,13 +3308,23 @@ static int hv_pci_remove(struct hv_device *hdev) hbus =hv_get_drvdata (hdev);if (hbus->state == hv_pcibus_installed) { +tasklet_disable (&hdev->channel->callback_event); + hbus->state = hv_pcibus_removing; +tasklet_enable (&hdev->channel->callback_event); +destroy_workqueue (hbus->wq); + hbus->wq =NULL ; +/* +* At this point, no work is running or can be scheduled +* on hbus-wq. We can't race with hv_pci_devices_present() +* or hv_pci_eject_device(), it's safe to proceed. +*/ +/* Remove the bus from PCI's point of view. */ pci_lock_rescan_remove ();pci_stop_root_bus (hbus->pci_bus);hv_pci_remove_slots (hbus);pci_remove_root_bus (hbus->pci_bus);pci_unlock_rescan_remove (); - hbus->state = hv_pcibus_removed; } ret =hv_pci_bus_exit (hdev, false);
@@ -3322,7 +3339,6 @@ static int hv_pci_remove(struct hv_device *hdev)irq_domain_free_fwnode (hbus->sysdata.fwnode);put_hvpcibus (hbus);wait_for_completion (&hbus->remove_event); -destroy_workqueue (hbus->wq);hv_put_dom_num (hbus->sysdata.domain);
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 10/53 pwm: pca9685: Restrict period change for enabled PWMs
In reply to Sasha LevinFrom: Clemens Gruber <[email protected]>
[ Upstream commit 6d6e7050276d40b5de97aa950d5d71057f2e2a25 ]
Previously, the last used PWM channel could change the global prescale setting, even if other channels are already in use.
Fix it by only allowing the first enabled PWM to change the global chip-wide prescale setting. If there is more than one channel in use, the prescale settings resulting from the chosen periods must match.
GPIOs do not count as enabled PWMs as they are not using the prescaler and can't change it.
--- drivers/pwm/pwm-pca9685.c | 74 +++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 10 deletions(-)
drivers/pwm/pwm-pca9685.c +64 -10
@@ -23,11 +23,11 @@#include <linux/bitmap.h> /* -* Because the PCA9685 has only one prescaler per chip, changing the period of -* one channel affects the period of all 16 PWM outputs! -* However, the ratio between each configured duty cycle and the chip-wide -* period remains constant, because the OFF time is set in proportion to the -* counter range. +* Because the PCA9685 has only one prescaler per chip, only the first channel +* that is enabled is allowed to change the prescale register. +* PWM channels requested afterwards must use a period that results in the same +* prescale setting as the one set by the first requested channel. +* GPIOs do not count as enabled PWMs as they are not using the prescaler. */ #define PCA9685_MODE1 0x00
@@ -78,8 +78,9 @@struct pca9685 {struct pwm_chip chip;struct regmap *regmap; -#if IS_ENABLED (CONFIG_GPIOLIB )struct mutex lock; + DECLARE_BITMAP(pwms_enabled, PCA9685_MAXCHAN + 1); +#if IS_ENABLED (CONFIG_GPIOLIB )struct gpio_chip gpio; DECLARE_BITMAP(pwms_inuse, PCA9685_MAXCHAN + 1);#endif
@@ -90,6 +91,22 @@ static inline struct pca9685 *to_pca(struct pwm_chip *chip) return container_of(chip, struct pca9685, chip); } +/* This function is supposed to be called with the lock mutex held */ +static bool pca9685_prescaler_can_change (struct pca9685 *pca,int channel) +{ +/* No PWM enabled: Change allowed */ +if (bitmap_empty (pca->pwms_enabled,PCA9685_MAXCHAN +1 )) +return true; +/* More than one PWM enabled: Change not allowed */ +if (bitmap_weight (pca->pwms_enabled,PCA9685_MAXCHAN +1 ) >1 ) +return false; +/* +* Only one PWM enabled: Change allowed if the PWM about to +* be changed is the one that is already enabled +*/ +return test_bit (channel, pca->pwms_enabled); +} +/* Helper function to set the duty cycle ratio to duty/4096 (e.g. duty=2048 -> 50%) */ static void pca9685_pwm_set_duty (struct pca9685 *pca,int channel,unsigned int duty) {
@@ -240,8 +257,6 @@ static int pca9685_pwm_gpio_probe(struct pca9685 *pca) {struct device *dev = pca->chip.dev; -mutex_init (&pca->lock); - pca->gpio.label =dev_name (dev); pca->gpio.parent = dev; pca->gpio.request = pca9685_pwm_gpio_request;
@@ -285,8 +300,8 @@ static void pca9685_set_sleep_mode(struct pca9685 *pca, bool enable) } } -static int pca9685_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, -const struct pwm_state *state) +static int __pca9685_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) {struct pca9685 *pca =to_pca (chip);unsigned long long duty, prescale;
@@ -309,6 +324,12 @@ static int pca9685_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,regmap_read (pca->regmap,PCA9685_PRESCALE , &val);if (prescale != val) { +if (!pca9685_prescaler_can_change (pca, pwm->hwpwm)) { +dev_err (chip->dev, +"pwm not changed: periods of enabled pwms must match!\n" ); +return -EBUSY ; + } +/* * Putting the chip briefly into SLEEP mode * at this point won't interfere with the
@@ -331,6 +352,25 @@ static int pca9685_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,return 0 ; } +static int pca9685_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) +{ +struct pca9685 *pca =to_pca (chip); +int ret; + +mutex_lock (&pca->lock); + ret =__pca9685_pwm_apply (chip, pwm, state); +if (ret ==0 ) { +if (state->enabled) +set_bit (pwm->hwpwm, pca->pwms_enabled); +else +clear_bit (pwm->hwpwm, pca->pwms_enabled); + } +mutex_unlock (&pca->lock); + +return ret; +} +static void pca9685_pwm_get_state (struct pwm_chip *chip,struct pwm_device *pwm,struct pwm_state *state) {
@@ -372,6 +412,14 @@ static int pca9685_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)if (pca9685_pwm_test_and_set_inuse (pca, pwm->hwpwm))return -EBUSY ; + +if (pwm->hwpwm <PCA9685_MAXCHAN ) { +/* PWMs - except the "all LEDs" channel - default to enabled */ +mutex_lock (&pca->lock); +set_bit (pwm->hwpwm, pca->pwms_enabled); +mutex_unlock (&pca->lock); + } +pm_runtime_get_sync (chip->dev);return 0 ;
@@ -381,7 +429,11 @@ static void pca9685_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) {struct pca9685 *pca =to_pca (chip); +mutex_lock (&pca->lock);pca9685_pwm_set_duty (pca, pwm->hwpwm,0 ); +clear_bit (pwm->hwpwm, pca->pwms_enabled); +mutex_unlock (&pca->lock); +pm_runtime_put (chip->dev);pca9685_pwm_clear_inuse (pca, pwm->hwpwm); }
@@ -422,6 +474,8 @@ static int pca9685_pwm_probe(struct i2c_client *client,i2c_set_clientdata (client, pca); +mutex_init (&pca->lock); +regmap_read (pca->regmap,PCA9685_MODE2 , ®);if (device_property_read_bool (&client->dev,"invert" ))
Signature · 1 line
2.30.2
Sasha Levin
maintainerPATCH 11/53 power: supply: max17042: Do not enforce (incorrect) interrupt trigger type
In reply to Sasha LevinFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 7fbf6b731bca347700e460d94b130f9d734b33e9 ]
Interrupt line can be configured on different hardware in different way, even inverted. Therefore driver should not enforce specific trigger type - edge falling - but instead rely on Devicetree to configure it.
The Maxim 17047/77693 datasheets describe the interrupt line as active low with a requirement of acknowledge from the CPU therefore the edge falling is not correct.
The interrupt line is shared between PMIC and RTC driver, so using level sensitive interrupt is here especially important to avoid races. With an edge configuration in case if first PMIC signals interrupt followed shortly after by the RTC, the interrupt might not be yet cleared/acked thus the second one would not be noticed.
--- drivers/power/supply/max17042_battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/max17042_battery.c +1 -1
@@ -1104,7 +1104,7 @@ static int max17042_probe(struct i2c_client *client, }if (client->irq) { -unsigned int flags =IRQF_TRIGGER_FALLING |IRQF_ONESHOT ; +unsigned int flags =IRQF_ONESHOT ;/* * On ACPI systems the IRQ may be handled by ACPI-event code,
Signature · 1 line
2.30.2