How to defer device driver initialization?

Hello everyone
I've stuck in a problem of deferring initialization of a driver.
I need to initialize LCD panel driver after PMIC driver is done. But somehow kernel make them initialize vice versa. So, that's why I have to make special things in a driver code.
I made steps in two files:
dts:
/ { display-dsi { compatible = "simple-bus"; #interrupt-cells = <1>; #address-cells = <1>; #size-cells = <1>; ranges = <>; lcd_eldo: reg_eldo1 { compatible = "regulator-fixed"; regulator-name = "lcd_eldo"; regulator-always-on; regulator-min-microvolt = <3000000>; regulator-max-microvolt = <3000000>; }; [email protected] { compatible = "ingenic,ili9881"; power-supply = <&lcd_eldo>; ingenic,bl-gpio = <&gpd 2 GPIO_ACTIVE_HIGH INGENIC_GPIO_NOBIAS>; ingenic,rst-gpio = <&gpc 6 GPIO_ACTIVE_HIGH INGENIC_GPIO_NOBIAS>; ingenic,lcd_pwm-gpio = <&gpb 7 GPIO_ACTIVE_HIGH INGENIC_GPIO_NOBIAS>; status = "okay"; }; }; };
driver code:
static int panel_probe(struct platform_device *pdev) { panel = kzalloc(sizeof(struct panel_dev), GFP_KERNEL); if (IS_ERR_OR_NULL(panel)) { dev_err(&pdev->dev, "Failed to alloc memory!\n"); return -ENOMEM; } panel->dev = &pdev->dev; dev_set_drvdata(&pdev->dev, panel); ret = of_panel_parse(&pdev->dev); if (ret < 0) { printk("panel probe: err_of_parse\n"); goto err_of_parse; } struct regulator * pvcc; pvcc = devm_regulator_get(&pdev->dev, "lcd_eldo"); if (IS_ERR(pvcc)) { printk("---##&##--- lcd_eldo LCD: FAIL\n"); return -EPROBE_DEFER; } /* ... */ }
I expected the project work normally, but a system log shows following:
display-dsi:[email protected] supply lcd_eldo not found, using dummy regulator
As far as I understand it means:
- devm_regulator_get() can not find regulator name
- system should have returned an error, but it activates the dummy_regulator instead
Any ideas?
Best Answer
-
I've found a solution I guess
I should have used a devm_regulator_get_exclusive() function, because it does not activates dummy_regulator and returns an error instead. Then it becomes possible to operate the returning value to defer the driver initialization.The function body:
struct regulator *devm_regulator_get_exclusive(struct device *dev, char *id) { return _devm_regulator_get(dev, id, EXCLUSIVE_GET); }
Then in the function the system goes to case EXCLUSIVE_GET
static struct regulator *_devm_regulator_get(struct device *dev, const char *id, get_type) { struct regulator **ptr, *regulator; ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return ERR_PTR(-ENOMEM); switch (get_type) { case NORMAL_GET: regulator = regulator_get(dev, id); break; case EXCLUSIVE_GET: regulator = regulator_get_exclusive(dev, id); break; case OPTIONAL_GET: regulator = regulator_get_optional(dev, id); break; default: regulator = ERR_PTR(-EINVAL); } if (!IS_ERR(regulator)) { *ptr = regulator; devres_add(dev, ptr); } else devres_free(ptr); return regulator; }
Then
struct regulator *regulator_get_exclusive(struct device *dev, const char *id) { return _regulator_get(dev, id, true, false); } /* _regulator_get heading */ static struct regulator *_regulator_get ( struct device *dev, const char *id, bool exclusive, bool allow_dummy ) /* * allow_dummy = false */
That means the devm_regulator_get_exclusive() function returns what I need
struct regulator * pvcc; pvcc = devm_regulator_get_exclusive(&pdev->dev, "lcd_eldo"); if (IS_ERR(pvcc)) { printk("---##&##--- lcd_eldo LCD: FAIL\n"); return -EPROBE_DEFER; } /* ... */
It works normally:
- accroding to the error code of devm_regulator_get_exclusive() I can return EPROBE_DEFER in driver probe function
- if there is no error code, it's possible to make my driver initialize
0
Answers
-
@vanovsky777 said:
I've found a solution I guess
I should have used a devm_regulator_get_exclusive() function, because it does not activates dummy_regulator and returns an error instead. Then it becomes possible to operate the returning value to defer the driver initialization.The function body:
struct regulator *devm_regulator_get_exclusive(struct device *dev, char *id) { return _devm_regulator_get(dev, id, EXCLUSIVE_GET); }
Then in the function the system goes to case EXCLUSIVE_GET
static struct regulator *_devm_regulator_get(struct device *dev, const char *id, get_type) { struct regulator **ptr, *regulator; ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return ERR_PTR(-ENOMEM); switch (get_type) { case NORMAL_GET: regulator = regulator_get(dev, id); break; case EXCLUSIVE_GET: regulator = regulator_get_exclusive(dev, id); break; case OPTIONAL_GET: regulator = regulator_get_optional(dev, id); break; default: regulator = ERR_PTR(-EINVAL); } if (!IS_ERR(regulator)) { *ptr = regulator; devres_add(dev, ptr); } else devres_free(ptr); return regulator; }
Then
struct regulator *regulator_get_exclusive(struct device *dev, const char *id) { return _regulator_get(dev, it, true, false); } /* _regulator_get heading */ static struct regulator *_regulator_get ( struct device *dev, const char *id, bool exclusive, bool allow_dummy ) /* * allow_dummy = false */
That means the devm_regulator_get_exclusive() function returns what I need
struct regulator * pvcc; pvcc = devm_regulator_get_exclusive(&pdev->dev, "lcd_eldo"); if (IS_ERR(pvcc)) { printk("---##&##--- lcd_eldo LCD: FAIL\n"); return -EPROBE_DEFER; } /* ... */
It works normally:
- accroding to the error code of devm_regulator_get_exclusive() I can return EPROBE_DEFER in driver probe function
- if there is no error code, it's possible to make my driver initialize
Exactly, this is the best answer to the problem "How to defer device driver initialization?. Thanks to vanovsky777
vanovsky777.0
Categories
- 9.9K All Categories
- 29 LFX Mentorship
- 82 LFX Mentorship: Linux Kernel
- 465 Linux Foundation Boot Camps
- 266 Cloud Engineer Boot Camp
- 94 Advanced Cloud Engineer Boot Camp
- 43 DevOps Engineer Boot Camp
- 29 Cloud Native Developer Boot Camp
- 1 Express Training Courses
- 1 Express Courses - Discussion Forum
- 1.6K Training Courses
- 18 LFC110 Class Forum
- 4 LFC131 Class Forum
- 19 LFD102 Class Forum
- 133 LFD103 Class Forum
- 9 LFD121 Class Forum
- 60 LFD201 Class Forum
- LFD210 Class Forum
- 1 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum
- 23 LFD254 Class Forum
- 544 LFD259 Class Forum
- 100 LFD272 Class Forum
- 1 LFD272-JP クラス フォーラム
- 1 LFS145 Class Forum
- 20 LFS200 Class Forum
- 739 LFS201 Class Forum
- 1 LFS201-JP クラス フォーラム
- 1 LFS203 Class Forum
- 36 LFS207 Class Forum
- 295 LFS211 Class Forum
- 53 LFS216 Class Forum
- 45 LFS241 Class Forum
- 39 LFS242 Class Forum
- 33 LFS243 Class Forum
- 10 LFS244 Class Forum
- 27 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- 131 LFS253 Class Forum
- 964 LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 85 LFS260 Class Forum
- 124 LFS261 Class Forum
- 29 LFS262 Class Forum
- 78 LFS263 Class Forum
- 15 LFS264 Class Forum
- 10 LFS266 Class Forum
- 17 LFS267 Class Forum
- 16 LFS268 Class Forum
- 14 LFS269 Class Forum
- 194 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- 206 LFW211 Class Forum
- 148 LFW212 Class Forum
- 890 Hardware
- 212 Drivers
- 74 I/O Devices
- 44 Monitors
- 115 Multimedia
- 206 Networking
- 99 Printers & Scanners
- 85 Storage
- 747 Linux Distributions
- 88 Debian
- 64 Fedora
- 13 Linux Mint
- 13 Mageia
- 24 openSUSE
- 133 Red Hat Enterprise
- 33 Slackware
- 13 SUSE Enterprise
- 354 Ubuntu
- 468 Linux System Administration
- 38 Cloud Computing
- 67 Command Line/Scripting
- Github systems admin projects
- 93 Linux Security
- 77 Network Management
- 107 System Management
- 48 Web Management
- 62 Mobile Computing
- 22 Android
- 26 Development
- 1.2K New to Linux
- 1.1K Getting Started with Linux
- 525 Off Topic
- 127 Introductions
- 211 Small Talk
- 19 Study Material
- 782 Programming and Development
- 256 Kernel Development
- 492 Software Development
- 919 Software
- 255 Applications
- 181 Command Line
- 2 Compiling/Installing
- 76 Games
- 316 Installation
- 46 All In Program
- 46 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)