diff mbox series

[v7,2/3] pwm: Add Allwinner's D1/T113-S3/R329 SoCs PWM support

Message ID 20240125072032.1151383-3-privatesub2@gmail.com
State Changes Requested
Headers show
Series Add support for Allwinner PWM on D1/T113s/R329 SoCs | expand

Commit Message

Aleksandr Shubin Jan. 25, 2024, 7:19 a.m. UTC
Allwinner's D1, T113-S3 and R329 SoCs have a quite different PWM
controllers with ones supported by pwm-sun4i driver.

This patch adds a PWM controller driver for Allwinner's D1,
T113-S3 and R329 SoCs. The main difference between these SoCs
is the number of channels defined by the DT property.

Co-developed-by: Brandon Cheo Fusi <fusibrandon13@gmail.com>
Signed-off-by: Brandon Cheo Fusi <fusibrandon13@gmail.com>
Signed-off-by: Aleksandr Shubin <privatesub2@gmail.com>
---
 drivers/pwm/Kconfig      |  10 ++
 drivers/pwm/Makefile     |   1 +
 drivers/pwm/pwm-sun20i.c | 380 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 391 insertions(+)
 create mode 100644 drivers/pwm/pwm-sun20i.c

Comments

kernel test robot Jan. 25, 2024, 3:11 p.m. UTC | #1
Hi Aleksandr,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on sunxi/sunxi/for-next linus/master v6.8-rc1 next-20240125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Aleksandr-Shubin/dt-bindings-pwm-Add-binding-for-Allwinner-D1-T113-S3-R329-PWM-controller/20240125-152445
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240125072032.1151383-3-privatesub2%40gmail.com
patch subject: [PATCH v7 2/3] pwm: Add Allwinner's D1/T113-S3/R329 SoCs PWM support
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20240125/202401252250.TYU33FhT-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240125/202401252250.TYU33FhT-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401252250.TYU33FhT-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/pwm/pwm-sun20i.c:288:10: error: 'const struct pwm_ops' has no member named 'owner'
     288 |         .owner = THIS_MODULE,
         |          ^~~~~
   In file included from include/linux/printk.h:6,
                    from include/linux/kernel.h:31,
                    from include/linux/clk.h:13,
                    from drivers/pwm/pwm-sun20i.c:14:
   include/linux/init.h:186:21: error: initialization of 'int (*)(struct pwm_chip *, struct pwm_device *, struct pwm_state *)' from incompatible pointer type 'struct module *' [-Werror=incompatible-pointer-types]
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   include/linux/init.h:186:21: note: (near initialization for 'sun20i_pwm_ops.get_state')
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   include/linux/init.h:186:21: warning: initialized field overwritten [-Woverride-init]
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   include/linux/init.h:186:21: note: (near initialization for 'sun20i_pwm_ops.get_state')
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:297:36: warning: 'struct platform_device' declared inside parameter list will not be visible outside of this definition or declaration
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c: In function 'sun20i_pwm_probe':
   drivers/pwm/pwm-sun20i.c:302:23: error: implicit declaration of function 'devm_kzalloc' [-Werror=implicit-function-declaration]
     302 |         sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
         |                       ^~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:302:41: error: invalid use of undefined type 'struct platform_device'
     302 |         sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
         |                                         ^~
   drivers/pwm/pwm-sun20i.c:306:29: error: implicit declaration of function 'devm_platform_ioremap_resource' [-Werror=implicit-function-declaration]
     306 |         sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
         |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:306:27: warning: assignment to 'void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     306 |         sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
         |                           ^
   drivers/pwm/pwm-sun20i.c:310:58: error: invalid use of undefined type 'struct platform_device'
     310 |         sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
         |                                                          ^~
   drivers/pwm/pwm-sun20i.c:312:24: error: implicit declaration of function 'dev_err_probe' [-Werror=implicit-function-declaration]
     312 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
         |                        ^~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:312:43: error: invalid use of undefined type 'struct platform_device'
     312 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:315:59: error: invalid use of undefined type 'struct platform_device'
     315 |         sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
         |                                                           ^~
   drivers/pwm/pwm-sun20i.c:317:43: error: invalid use of undefined type 'struct platform_device'
     317 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:320:59: error: invalid use of undefined type 'struct platform_device'
     320 |         sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
         |                                                           ^~
   drivers/pwm/pwm-sun20i.c:322:43: error: invalid use of undefined type 'struct platform_device'
     322 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:325:66: error: invalid use of undefined type 'struct platform_device'
     325 |         sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
         |                                                                  ^~
   drivers/pwm/pwm-sun20i.c:327:43: error: invalid use of undefined type 'struct platform_device'
     327 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:330:40: error: invalid use of undefined type 'struct platform_device'
     330 |         ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
         |                                        ^~
   drivers/pwm/pwm-sun20i.c:341:43: error: invalid use of undefined type 'struct platform_device'
     341 |                 return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:343:38: error: invalid use of undefined type 'struct platform_device'
     343 |         sun20i_chip->chip.dev = &pdev->dev;
         |                                      ^~
   drivers/pwm/pwm-sun20i.c:351:43: error: invalid use of undefined type 'struct platform_device'
     351 |                 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:354:9: error: implicit declaration of function 'platform_set_drvdata' [-Werror=implicit-function-declaration]
     354 |         platform_set_drvdata(pdev, sun20i_chip);
         |         ^~~~~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c: At top level:
   drivers/pwm/pwm-sun20i.c:359:38: warning: 'struct platform_device' declared inside parameter list will not be visible outside of this definition or declaration
     359 | static void sun20i_pwm_remove(struct platform_device *pdev)
         |                                      ^~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c: In function 'sun20i_pwm_remove':
   drivers/pwm/pwm-sun20i.c:361:47: error: implicit declaration of function 'platform_get_drvdata' [-Werror=implicit-function-declaration]
     361 |         struct sun20i_pwm_chip *sun20i_chip = platform_get_drvdata(pdev);
         |                                               ^~~~~~~~~~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:361:47: warning: initialization of 'struct sun20i_pwm_chip *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   drivers/pwm/pwm-sun20i.c: At top level:
   drivers/pwm/pwm-sun20i.c:368:15: error: variable 'sun20i_pwm_driver' has initializer but incomplete type
     368 | static struct platform_driver sun20i_pwm_driver = {
         |               ^~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:369:10: error: 'struct platform_driver' has no member named 'driver'
     369 |         .driver = {
         |          ^~~~~~
   drivers/pwm/pwm-sun20i.c:369:19: error: extra brace group at end of initializer
     369 |         .driver = {
         |                   ^
   drivers/pwm/pwm-sun20i.c:369:19: note: (near initialization for 'sun20i_pwm_driver')
>> drivers/pwm/pwm-sun20i.c:369:19: warning: excess elements in struct initializer
   drivers/pwm/pwm-sun20i.c:369:19: note: (near initialization for 'sun20i_pwm_driver')
   drivers/pwm/pwm-sun20i.c:373:10: error: 'struct platform_driver' has no member named 'probe'
     373 |         .probe = sun20i_pwm_probe,
         |          ^~~~~
   drivers/pwm/pwm-sun20i.c:373:18: warning: excess elements in struct initializer
     373 |         .probe = sun20i_pwm_probe,
         |                  ^~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:373:18: note: (near initialization for 'sun20i_pwm_driver')
   drivers/pwm/pwm-sun20i.c:374:10: error: 'struct platform_driver' has no member named 'remove_new'
     374 |         .remove_new = sun20i_pwm_remove,
         |          ^~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:374:23: warning: excess elements in struct initializer
     374 |         .remove_new = sun20i_pwm_remove,
         |                       ^~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:374:23: note: (near initialization for 'sun20i_pwm_driver')
>> drivers/pwm/pwm-sun20i.c:376:1: warning: data definition has no type or storage class
     376 | module_platform_driver(sun20i_pwm_driver);
         | ^~~~~~~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:376:1: error: type defaults to 'int' in declaration of 'module_platform_driver' [-Werror=implicit-int]
>> drivers/pwm/pwm-sun20i.c:376:1: warning: parameter names (without types) in function declaration
   drivers/pwm/pwm-sun20i.c:368:31: error: storage size of 'sun20i_pwm_driver' isn't known
     368 | static struct platform_driver sun20i_pwm_driver = {
         |                               ^~~~~~~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:368:31: warning: 'sun20i_pwm_driver' defined but not used [-Wunused-variable]
   cc1: some warnings being treated as errors


vim +297 drivers/pwm/pwm-sun20i.c

   296	
 > 297	static int sun20i_pwm_probe(struct platform_device *pdev)
   298	{
   299		struct sun20i_pwm_chip *sun20i_chip;
   300		int ret;
   301	
   302		sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
   303		if (!sun20i_chip)
   304			return -ENOMEM;
   305	
 > 306		sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
   307		if (IS_ERR(sun20i_chip->base))
   308			return PTR_ERR(sun20i_chip->base);
   309	
   310		sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
   311		if (IS_ERR(sun20i_chip->clk_bus))
   312			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
   313					     "failed to get bus clock\n");
   314	
   315		sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
   316		if (IS_ERR(sun20i_chip->clk_hosc))
   317			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
   318					     "failed to get hosc clock\n");
   319	
   320		sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
   321		if (IS_ERR(sun20i_chip->clk_apb0))
   322			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
   323					     "failed to get apb0 clock\n");
   324	
   325		sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
   326		if (IS_ERR(sun20i_chip->rst))
   327			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
   328					     "failed to get bus reset\n");
   329	
   330		ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
   331					   &sun20i_chip->chip.npwm);
   332		if (ret)
   333			sun20i_chip->chip.npwm = 8;
   334	
   335		if (sun20i_chip->chip.npwm > 16)
   336			sun20i_chip->chip.npwm = 16;
   337	
   338		/* Deassert reset */
   339		ret = reset_control_deassert(sun20i_chip->rst);
   340		if (ret)
   341			return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
   342	
   343		sun20i_chip->chip.dev = &pdev->dev;
   344		sun20i_chip->chip.ops = &sun20i_pwm_ops;
   345	
   346		mutex_init(&sun20i_chip->mutex);
   347	
   348		ret = pwmchip_add(&sun20i_chip->chip);
   349		if (ret < 0) {
   350			reset_control_assert(sun20i_chip->rst);
   351			return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
   352		}
   353	
   354		platform_set_drvdata(pdev, sun20i_chip);
   355	
   356		return 0;
   357	}
   358	
   359	static void sun20i_pwm_remove(struct platform_device *pdev)
   360	{
 > 361		struct sun20i_pwm_chip *sun20i_chip = platform_get_drvdata(pdev);
   362	
   363		pwmchip_remove(&sun20i_chip->chip);
   364	
   365		reset_control_assert(sun20i_chip->rst);
   366	}
   367	
 > 368	static struct platform_driver sun20i_pwm_driver = {
 > 369		.driver = {
   370			.name = "sun20i-pwm",
   371			.of_match_table = sun20i_pwm_dt_ids,
   372		},
   373		.probe = sun20i_pwm_probe,
   374		.remove_new = sun20i_pwm_remove,
   375	};
 > 376	module_platform_driver(sun20i_pwm_driver);
   377
kernel test robot Jan. 25, 2024, 11:13 p.m. UTC | #2
Hi Aleksandr,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on sunxi/sunxi/for-next linus/master v6.8-rc1 next-20240125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Aleksandr-Shubin/dt-bindings-pwm-Add-binding-for-Allwinner-D1-T113-S3-R329-PWM-controller/20240125-152445
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240125072032.1151383-3-privatesub2%40gmail.com
patch subject: [PATCH v7 2/3] pwm: Add Allwinner's D1/T113-S3/R329 SoCs PWM support
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20240126/202401260632.l2X5DTxa-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240126/202401260632.l2X5DTxa-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401260632.l2X5DTxa-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/pwm/pwm-sun20i.c:288:10: error: 'const struct pwm_ops' has no member named 'owner'
     288 |         .owner = THIS_MODULE,
         |          ^~~~~
   In file included from include/linux/printk.h:6,
                    from include/linux/kernel.h:31,
                    from include/linux/clk.h:13,
                    from drivers/pwm/pwm-sun20i.c:14:
>> include/linux/init.h:186:21: error: initialization of 'int (*)(struct pwm_chip *, struct pwm_device *, struct pwm_state *)' from incompatible pointer type 'struct module *' [-Werror=incompatible-pointer-types]
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   include/linux/init.h:186:21: note: (near initialization for 'sun20i_pwm_ops.get_state')
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   include/linux/init.h:186:21: warning: initialized field overwritten [-Woverride-init]
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   include/linux/init.h:186:21: note: (near initialization for 'sun20i_pwm_ops.get_state')
     186 | #define THIS_MODULE ((struct module *)0)
         |                     ^
   drivers/pwm/pwm-sun20i.c:288:18: note: in expansion of macro 'THIS_MODULE'
     288 |         .owner = THIS_MODULE,
         |                  ^~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:297:36: warning: 'struct platform_device' declared inside parameter list will not be visible outside of this definition or declaration
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c: In function 'sun20i_pwm_probe':
>> drivers/pwm/pwm-sun20i.c:302:23: error: implicit declaration of function 'devm_kzalloc' [-Werror=implicit-function-declaration]
     302 |         sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
         |                       ^~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:302:41: error: invalid use of undefined type 'struct platform_device'
     302 |         sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
         |                                         ^~
>> drivers/pwm/pwm-sun20i.c:306:29: error: implicit declaration of function 'devm_platform_ioremap_resource' [-Werror=implicit-function-declaration]
     306 |         sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
         |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:306:27: warning: assignment to 'void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     306 |         sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
         |                           ^
   drivers/pwm/pwm-sun20i.c:310:58: error: invalid use of undefined type 'struct platform_device'
     310 |         sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
         |                                                          ^~
>> drivers/pwm/pwm-sun20i.c:312:24: error: implicit declaration of function 'dev_err_probe' [-Werror=implicit-function-declaration]
     312 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
         |                        ^~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:312:43: error: invalid use of undefined type 'struct platform_device'
     312 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:315:59: error: invalid use of undefined type 'struct platform_device'
     315 |         sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
         |                                                           ^~
   drivers/pwm/pwm-sun20i.c:317:43: error: invalid use of undefined type 'struct platform_device'
     317 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:320:59: error: invalid use of undefined type 'struct platform_device'
     320 |         sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
         |                                                           ^~
   drivers/pwm/pwm-sun20i.c:322:43: error: invalid use of undefined type 'struct platform_device'
     322 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:325:66: error: invalid use of undefined type 'struct platform_device'
     325 |         sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
         |                                                                  ^~
   drivers/pwm/pwm-sun20i.c:327:43: error: invalid use of undefined type 'struct platform_device'
     327 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:330:40: error: invalid use of undefined type 'struct platform_device'
     330 |         ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
         |                                        ^~
   drivers/pwm/pwm-sun20i.c:341:43: error: invalid use of undefined type 'struct platform_device'
     341 |                 return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
         |                                           ^~
   drivers/pwm/pwm-sun20i.c:343:38: error: invalid use of undefined type 'struct platform_device'
     343 |         sun20i_chip->chip.dev = &pdev->dev;
         |                                      ^~
   drivers/pwm/pwm-sun20i.c:351:43: error: invalid use of undefined type 'struct platform_device'
     351 |                 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
         |                                           ^~
>> drivers/pwm/pwm-sun20i.c:354:9: error: implicit declaration of function 'platform_set_drvdata' [-Werror=implicit-function-declaration]
     354 |         platform_set_drvdata(pdev, sun20i_chip);
         |         ^~~~~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c: At top level:
   drivers/pwm/pwm-sun20i.c:359:38: warning: 'struct platform_device' declared inside parameter list will not be visible outside of this definition or declaration
     359 | static void sun20i_pwm_remove(struct platform_device *pdev)
         |                                      ^~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c: In function 'sun20i_pwm_remove':
>> drivers/pwm/pwm-sun20i.c:361:47: error: implicit declaration of function 'platform_get_drvdata' [-Werror=implicit-function-declaration]
     361 |         struct sun20i_pwm_chip *sun20i_chip = platform_get_drvdata(pdev);
         |                                               ^~~~~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:361:47: warning: initialization of 'struct sun20i_pwm_chip *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
   drivers/pwm/pwm-sun20i.c: At top level:
>> drivers/pwm/pwm-sun20i.c:368:15: error: variable 'sun20i_pwm_driver' has initializer but incomplete type
     368 | static struct platform_driver sun20i_pwm_driver = {
         |               ^~~~~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:369:10: error: 'struct platform_driver' has no member named 'driver'
     369 |         .driver = {
         |          ^~~~~~
>> drivers/pwm/pwm-sun20i.c:369:19: error: extra brace group at end of initializer
     369 |         .driver = {
         |                   ^
   drivers/pwm/pwm-sun20i.c:369:19: note: (near initialization for 'sun20i_pwm_driver')
   drivers/pwm/pwm-sun20i.c:369:19: warning: excess elements in struct initializer
   drivers/pwm/pwm-sun20i.c:369:19: note: (near initialization for 'sun20i_pwm_driver')
>> drivers/pwm/pwm-sun20i.c:373:10: error: 'struct platform_driver' has no member named 'probe'
     373 |         .probe = sun20i_pwm_probe,
         |          ^~~~~
   drivers/pwm/pwm-sun20i.c:373:18: warning: excess elements in struct initializer
     373 |         .probe = sun20i_pwm_probe,
         |                  ^~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:373:18: note: (near initialization for 'sun20i_pwm_driver')
>> drivers/pwm/pwm-sun20i.c:374:10: error: 'struct platform_driver' has no member named 'remove_new'
     374 |         .remove_new = sun20i_pwm_remove,
         |          ^~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:374:23: warning: excess elements in struct initializer
     374 |         .remove_new = sun20i_pwm_remove,
         |                       ^~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:374:23: note: (near initialization for 'sun20i_pwm_driver')
   drivers/pwm/pwm-sun20i.c:376:1: warning: data definition has no type or storage class
     376 | module_platform_driver(sun20i_pwm_driver);
         | ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:376:1: error: type defaults to 'int' in declaration of 'module_platform_driver' [-Werror=implicit-int]
   drivers/pwm/pwm-sun20i.c:376:1: warning: parameter names (without types) in function declaration
>> drivers/pwm/pwm-sun20i.c:368:31: error: storage size of 'sun20i_pwm_driver' isn't known
     368 | static struct platform_driver sun20i_pwm_driver = {
         |                               ^~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:368:31: warning: 'sun20i_pwm_driver' defined but not used [-Wunused-variable]
   cc1: some warnings being treated as errors


vim +288 drivers/pwm/pwm-sun20i.c

   284	
   285	static const struct pwm_ops sun20i_pwm_ops = {
   286		.get_state = sun20i_pwm_get_state,
   287		.apply = sun20i_pwm_apply,
 > 288		.owner = THIS_MODULE,
   289	};
   290	
   291	static const struct of_device_id sun20i_pwm_dt_ids[] = {
   292		{ .compatible = "allwinner,sun20i-d1-pwm" },
   293		{ },
   294	};
   295	MODULE_DEVICE_TABLE(of, sun20i_pwm_dt_ids);
   296	
   297	static int sun20i_pwm_probe(struct platform_device *pdev)
   298	{
   299		struct sun20i_pwm_chip *sun20i_chip;
   300		int ret;
   301	
 > 302		sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
   303		if (!sun20i_chip)
   304			return -ENOMEM;
   305	
 > 306		sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
   307		if (IS_ERR(sun20i_chip->base))
   308			return PTR_ERR(sun20i_chip->base);
   309	
   310		sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
   311		if (IS_ERR(sun20i_chip->clk_bus))
 > 312			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
   313					     "failed to get bus clock\n");
   314	
   315		sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
   316		if (IS_ERR(sun20i_chip->clk_hosc))
   317			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
   318					     "failed to get hosc clock\n");
   319	
   320		sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
   321		if (IS_ERR(sun20i_chip->clk_apb0))
   322			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
   323					     "failed to get apb0 clock\n");
   324	
   325		sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
   326		if (IS_ERR(sun20i_chip->rst))
   327			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
   328					     "failed to get bus reset\n");
   329	
   330		ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
   331					   &sun20i_chip->chip.npwm);
   332		if (ret)
   333			sun20i_chip->chip.npwm = 8;
   334	
   335		if (sun20i_chip->chip.npwm > 16)
   336			sun20i_chip->chip.npwm = 16;
   337	
   338		/* Deassert reset */
   339		ret = reset_control_deassert(sun20i_chip->rst);
   340		if (ret)
   341			return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
   342	
   343		sun20i_chip->chip.dev = &pdev->dev;
   344		sun20i_chip->chip.ops = &sun20i_pwm_ops;
   345	
   346		mutex_init(&sun20i_chip->mutex);
   347	
   348		ret = pwmchip_add(&sun20i_chip->chip);
   349		if (ret < 0) {
   350			reset_control_assert(sun20i_chip->rst);
   351			return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
   352		}
   353	
 > 354		platform_set_drvdata(pdev, sun20i_chip);
   355	
   356		return 0;
   357	}
   358	
   359	static void sun20i_pwm_remove(struct platform_device *pdev)
   360	{
 > 361		struct sun20i_pwm_chip *sun20i_chip = platform_get_drvdata(pdev);
   362	
   363		pwmchip_remove(&sun20i_chip->chip);
   364	
   365		reset_control_assert(sun20i_chip->rst);
   366	}
   367	
 > 368	static struct platform_driver sun20i_pwm_driver = {
 > 369		.driver = {
   370			.name = "sun20i-pwm",
   371			.of_match_table = sun20i_pwm_dt_ids,
   372		},
 > 373		.probe = sun20i_pwm_probe,
 > 374		.remove_new = sun20i_pwm_remove,
   375	};
 > 376	module_platform_driver(sun20i_pwm_driver);
   377
kernel test robot Jan. 26, 2024, 12:38 a.m. UTC | #3
Hi Aleksandr,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on sunxi/sunxi/for-next linus/master v6.8-rc1 next-20240125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Aleksandr-Shubin/dt-bindings-pwm-Add-binding-for-Allwinner-D1-T113-S3-R329-PWM-controller/20240125-152445
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20240125072032.1151383-3-privatesub2%40gmail.com
patch subject: [PATCH v7 2/3] pwm: Add Allwinner's D1/T113-S3/R329 SoCs PWM support
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20240126/202401260832.fN2PCI3u-lkp@intel.com/config)
compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project a31a60074717fc40887cfe132b77eec93bedd307)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240126/202401260832.fN2PCI3u-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401260832.fN2PCI3u-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   In file included from drivers/pwm/pwm-sun20i.c:16:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     547 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     560 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/pwm/pwm-sun20i.c:16:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     573 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/pwm/pwm-sun20i.c:16:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     584 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     594 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     604 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
>> drivers/pwm/pwm-sun20i.c:288:3: error: field designator 'owner' does not refer to any field in type 'const struct pwm_ops'
     288 |         .owner = THIS_MODULE,
         |         ~^~~~~~~~~~~~~~~~~~~
>> drivers/pwm/pwm-sun20i.c:297:36: warning: declaration of 'struct platform_device' will not be visible outside of this function [-Wvisibility]
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
>> drivers/pwm/pwm-sun20i.c:302:16: error: call to undeclared function 'devm_kzalloc'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     302 |         sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
         |                       ^
>> drivers/pwm/pwm-sun20i.c:302:34: error: incomplete definition of type 'struct platform_device'
     302 |         sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
         |                                     ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
>> drivers/pwm/pwm-sun20i.c:306:22: error: call to undeclared function 'devm_platform_ioremap_resource'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     306 |         sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
         |                             ^
>> drivers/pwm/pwm-sun20i.c:306:20: error: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
     306 |         sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
         |                           ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/pwm/pwm-sun20i.c:310:51: error: incomplete definition of type 'struct platform_device'
     310 |         sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
         |                                                      ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
>> drivers/pwm/pwm-sun20i.c:312:10: error: call to undeclared function 'dev_err_probe'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     312 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
         |                        ^
   drivers/pwm/pwm-sun20i.c:312:29: error: incomplete definition of type 'struct platform_device'
     312 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
         |                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:315:52: error: incomplete definition of type 'struct platform_device'
     315 |         sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
         |                                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:317:29: error: incomplete definition of type 'struct platform_device'
     317 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
         |                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:320:52: error: incomplete definition of type 'struct platform_device'
     320 |         sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
         |                                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:322:29: error: incomplete definition of type 'struct platform_device'
     322 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
         |                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:325:59: error: incomplete definition of type 'struct platform_device'
     325 |         sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
         |                                                              ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:327:29: error: incomplete definition of type 'struct platform_device'
     327 |                 return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
         |                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:330:33: error: incomplete definition of type 'struct platform_device'
     330 |         ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
         |                                    ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:341:29: error: incomplete definition of type 'struct platform_device'
     341 |                 return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
         |                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:343:31: error: incomplete definition of type 'struct platform_device'
     343 |         sun20i_chip->chip.dev = &pdev->dev;
         |                                  ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
   drivers/pwm/pwm-sun20i.c:351:29: error: incomplete definition of type 'struct platform_device'
     351 |                 return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
         |                                       ~~~~^
   drivers/pwm/pwm-sun20i.c:297:36: note: forward declaration of 'struct platform_device'
     297 | static int sun20i_pwm_probe(struct platform_device *pdev)
         |                                    ^
>> drivers/pwm/pwm-sun20i.c:354:2: error: call to undeclared function 'platform_set_drvdata'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     354 |         platform_set_drvdata(pdev, sun20i_chip);
         |         ^
   drivers/pwm/pwm-sun20i.c:359:38: warning: declaration of 'struct platform_device' will not be visible outside of this function [-Wvisibility]
     359 | static void sun20i_pwm_remove(struct platform_device *pdev)
         |                                      ^
   fatal error: too many errors emitted, stopping now [-ferror-limit=]
   8 warnings and 20 errors generated.


vim +288 drivers/pwm/pwm-sun20i.c

   284	
   285	static const struct pwm_ops sun20i_pwm_ops = {
   286		.get_state = sun20i_pwm_get_state,
   287		.apply = sun20i_pwm_apply,
 > 288		.owner = THIS_MODULE,
   289	};
   290	
   291	static const struct of_device_id sun20i_pwm_dt_ids[] = {
   292		{ .compatible = "allwinner,sun20i-d1-pwm" },
   293		{ },
   294	};
   295	MODULE_DEVICE_TABLE(of, sun20i_pwm_dt_ids);
   296	
 > 297	static int sun20i_pwm_probe(struct platform_device *pdev)
   298	{
   299		struct sun20i_pwm_chip *sun20i_chip;
   300		int ret;
   301	
 > 302		sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
   303		if (!sun20i_chip)
   304			return -ENOMEM;
   305	
 > 306		sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
   307		if (IS_ERR(sun20i_chip->base))
   308			return PTR_ERR(sun20i_chip->base);
   309	
   310		sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
   311		if (IS_ERR(sun20i_chip->clk_bus))
 > 312			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
   313					     "failed to get bus clock\n");
   314	
   315		sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
   316		if (IS_ERR(sun20i_chip->clk_hosc))
   317			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
   318					     "failed to get hosc clock\n");
   319	
   320		sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
   321		if (IS_ERR(sun20i_chip->clk_apb0))
   322			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
   323					     "failed to get apb0 clock\n");
   324	
   325		sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
   326		if (IS_ERR(sun20i_chip->rst))
   327			return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
   328					     "failed to get bus reset\n");
   329	
   330		ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
   331					   &sun20i_chip->chip.npwm);
   332		if (ret)
   333			sun20i_chip->chip.npwm = 8;
   334	
   335		if (sun20i_chip->chip.npwm > 16)
   336			sun20i_chip->chip.npwm = 16;
   337	
   338		/* Deassert reset */
   339		ret = reset_control_deassert(sun20i_chip->rst);
   340		if (ret)
   341			return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
   342	
   343		sun20i_chip->chip.dev = &pdev->dev;
   344		sun20i_chip->chip.ops = &sun20i_pwm_ops;
   345	
   346		mutex_init(&sun20i_chip->mutex);
   347	
   348		ret = pwmchip_add(&sun20i_chip->chip);
   349		if (ret < 0) {
   350			reset_control_assert(sun20i_chip->rst);
   351			return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
   352		}
   353	
 > 354		platform_set_drvdata(pdev, sun20i_chip);
   355	
   356		return 0;
   357	}
   358
diff mbox series

Patch

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 4b956d661755..d2e0a080eb3c 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -625,6 +625,16 @@  config PWM_SUN4I
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-sun4i.
 
+config PWM_SUN20I
+	tristate "Allwinner D1/T113s/R329 PWM support"
+	depends on ARCH_SUNXI || COMPILE_TEST
+	depends on COMMON_CLK
+	help
+	  Generic PWM framework driver for Allwinner D1/T113s/R329 SoCs.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-sun20i.
+
 config PWM_SUNPLUS
 	tristate "Sunplus PWM support"
 	depends on ARCH_SUNPLUS || COMPILE_TEST
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index c5ec9e168ee7..dcad0d5a2430 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -58,6 +58,7 @@  obj-$(CONFIG_PWM_STM32)		+= pwm-stm32.o
 obj-$(CONFIG_PWM_STM32_LP)	+= pwm-stm32-lp.o
 obj-$(CONFIG_PWM_STMPE)		+= pwm-stmpe.o
 obj-$(CONFIG_PWM_SUN4I)		+= pwm-sun4i.o
+obj-$(CONFIG_PWM_SUN20I)	+= pwm-sun20i.o
 obj-$(CONFIG_PWM_SUNPLUS)	+= pwm-sunplus.o
 obj-$(CONFIG_PWM_TEGRA)		+= pwm-tegra.o
 obj-$(CONFIG_PWM_TIECAP)	+= pwm-tiecap.o
diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c
new file mode 100644
index 000000000000..d9e151f27f20
--- /dev/null
+++ b/drivers/pwm/pwm-sun20i.c
@@ -0,0 +1,380 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PWM Controller Driver for sunxi platforms (D1, T113-S3 and R329)
+ *
+ * Limitations:
+ * - When the parameters change, current running period will not be completed
+ *   and run new settings immediately.
+ * - It output HIGH-Z state when PWM channel disabled.
+ *
+ * Copyright (c) 2023 Aleksandr Shubin <privatesub2@gmail.com>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/pwm.h>
+#include <linux/reset.h>
+
+#define SUN20I_PWM_CLK_CFG(chan)		(0x20 + (((chan) >> 1) * 0x4))
+#define SUN20I_PWM_CLK_CFG_SRC			GENMASK(8, 7)
+#define SUN20I_PWM_CLK_CFG_DIV_M		GENMASK(3, 0)
+#define SUN20I_PWM_CLK_DIV_M_MAX		8
+
+#define SUN20I_PWM_CLK_GATE			0x40
+#define SUN20I_PWM_CLK_GATE_BYPASS(chan)	BIT((chan) + 16)
+#define SUN20I_PWM_CLK_GATE_GATING(chan)	BIT(chan)
+
+#define SUN20I_PWM_ENABLE			0x80
+#define SUN20I_PWM_ENABLE_EN(chan)		BIT(chan)
+
+#define SUN20I_PWM_CTL(chan)			(0x100 + (chan) * 0x20)
+#define SUN20I_PWM_CTL_ACT_STA			BIT(8)
+#define SUN20I_PWM_CTL_PRESCAL_K		GENMASK(7, 0)
+#define SUN20I_PWM_CTL_PRESCAL_K_MAX		0xff
+
+#define SUN20I_PWM_PERIOD(chan)			(0x104 + (chan) * 0x20)
+#define SUN20I_PWM_PERIOD_ENTIRE_CYCLE		GENMASK(31, 16)
+#define SUN20I_PWM_PERIOD_ACT_CYCLE		GENMASK(15, 0)
+
+#define SUN20I_PWM_PCNTR_SIZE			BIT(16)
+
+/**
+ * SUN20I_PWM_MAGIC is used to quickly compute the values of the clock dividers
+ * div_m (SUN20I_PWM_CLK_CFG_DIV_M) & prescale_k (SUN20I_PWM_CTL_PRESCAL_K)
+ * without using a loop. These dividers limit the # of cycles in a period
+ * to SUN20I_PWM_PCNTR_SIZE by applying a scaling factor of
+ * 1/(div_m * (prescale_k + 1)) to the clock source.
+ *
+ * SUN20I_PWM_MAGIC is derived by solving for div_m and prescale_k
+ * such that for a given requested period,
+ *
+ * i) div_m is minimized for any prescale_k ≤ SUN20I_PWM_CTL_PRESCAL_K_MAX,
+ * ii) prescale_k is minimized.
+ *
+ * The derivation proceeds as follows, with val = # of cycles for reqested
+ * period:
+ *
+ * for a given value of div_m we want the smallest prescale_k such that
+ *
+ * (val >> div_m) // (prescale_k + 1) ≤ 65536 (SUN20I_PWM_PCNTR_SIZE)
+ *
+ * This is equivalent to:
+ *
+ * (val >> div_m) ≤ 65536 * (prescale_k + 1) + prescale_k
+ * ⟺ (val >> div_m) ≤ 65537 * prescale_k + 65536
+ * ⟺ (val >> div_m) - 65536 ≤ 65537 * prescale_k
+ * ⟺ ((val >> div_m) - 65536) / 65537 ≤ prescale_k
+ *
+ * As prescale_k is integer, this becomes
+ *
+ * ((val >> div_m) - 65536) // 65537 ≤ prescale_k
+ *
+ * And is minimized at
+ *
+ * ((val >> div_m) - 65536) // 65537
+ *
+ * Now we pick the smallest div_m that satifies prescale_k ≤ 255
+ * (i.e SUN20I_PWM_CTL_PRESCAL_K_MAX),
+ *
+ * ((val >> div_m) - 65536) // 65537 ≤ 255
+ * ⟺ (val >> div_m) - 65536 ≤ 255 * 65537 + 65536
+ * ⟺ val >> div_m ≤ 255 * 65537 + 2 * 65536
+ * ⟺ val >> div_m < (255 * 65537 + 2 * 65536 + 1)
+ * ⟺ div_m = fls((val) / (255 * 65537 + 2 * 65536 + 1))
+ *
+ * Suggested by Uwe Kleine-König
+ */
+#define SUN20I_PWM_MAGIC			(255 * 65537 + 2 * 65536 + 1)
+
+struct sun20i_pwm_chip {
+	struct clk *clk_bus, *clk_hosc, *clk_apb0;
+	struct reset_control *rst;
+	struct pwm_chip chip;
+	void __iomem *base;
+	/* Mutex to protect pwm apply state */
+	struct mutex mutex;
+};
+
+static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip)
+{
+	return container_of(chip, struct sun20i_pwm_chip, chip);
+}
+
+static inline u32 sun20i_pwm_readl(struct sun20i_pwm_chip *chip,
+				   unsigned long offset)
+{
+	return readl(chip->base + offset);
+}
+
+static inline void sun20i_pwm_writel(struct sun20i_pwm_chip *chip,
+				     u32 val, unsigned long offset)
+{
+	writel(val, chip->base + offset);
+}
+
+static int sun20i_pwm_get_state(struct pwm_chip *chip,
+				struct pwm_device *pwm,
+				struct pwm_state *state)
+{
+	struct sun20i_pwm_chip *sun20i_chip = to_sun20i_pwm_chip(chip);
+	u16 ent_cycle, act_cycle, prescale_k;
+	u64 clk_rate, tmp;
+	u8 div_m;
+	u32 val;
+
+	mutex_lock(&sun20i_chip->mutex);
+
+	val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm));
+	div_m = FIELD_GET(SUN20I_PWM_CLK_CFG_DIV_M, val);
+	if (div_m > SUN20I_PWM_CLK_DIV_M_MAX)
+		div_m = SUN20I_PWM_CLK_DIV_M_MAX;
+
+	if (FIELD_GET(SUN20I_PWM_CLK_CFG_SRC, val) == 0)
+		clk_rate = clk_get_rate(sun20i_chip->clk_hosc);
+	else
+		clk_rate = clk_get_rate(sun20i_chip->clk_apb0);
+
+	val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(pwm->hwpwm));
+	state->polarity = (SUN20I_PWM_CTL_ACT_STA & val) ?
+			   PWM_POLARITY_NORMAL : PWM_POLARITY_INVERSED;
+
+	prescale_k = FIELD_GET(SUN20I_PWM_CTL_PRESCAL_K, val) + 1;
+
+	val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_ENABLE);
+	state->enabled = (SUN20I_PWM_ENABLE_EN(pwm->hwpwm) & val) ? true : false;
+
+	val = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_PERIOD(pwm->hwpwm));
+
+	mutex_unlock(&sun20i_chip->mutex);
+
+	act_cycle = FIELD_GET(SUN20I_PWM_PERIOD_ACT_CYCLE, val);
+	ent_cycle = FIELD_GET(SUN20I_PWM_PERIOD_ENTIRE_CYCLE, val);
+
+	/*
+	 * The duration of the active phase should not be longer
+	 * than the duration of the period
+	 */
+	if (act_cycle > ent_cycle)
+		act_cycle = ent_cycle;
+
+	tmp = ((u64)(act_cycle) * prescale_k << div_m) * NSEC_PER_SEC;
+	state->duty_cycle = DIV_ROUND_UP_ULL(tmp, clk_rate);
+	tmp = ((u64)(ent_cycle) * prescale_k << div_m) * NSEC_PER_SEC;
+	state->period = DIV_ROUND_UP_ULL(tmp, clk_rate);
+
+	return 0;
+}
+
+static int sun20i_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+			    const struct pwm_state *state)
+{
+	struct sun20i_pwm_chip *sun20i_chip = to_sun20i_pwm_chip(chip);
+	u64 bus_rate, hosc_rate, val, ent_cycle, act_cycle;
+	u32 clk_gate, clk_cfg, pwm_en, ctl, reg_period;
+	u32 prescale_k, div_m;
+	bool use_bus_clk;
+	int ret = 0;
+
+	mutex_lock(&sun20i_chip->mutex);
+
+	pwm_en = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_ENABLE);
+
+	if (state->enabled != pwm->state.enabled) {
+		clk_gate = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_GATE);
+
+		if (!state->enabled) {
+			clk_gate &= ~SUN20I_PWM_CLK_GATE_GATING(pwm->hwpwm);
+			pwm_en &= ~SUN20I_PWM_ENABLE_EN(pwm->hwpwm);
+			sun20i_pwm_writel(sun20i_chip, pwm_en, SUN20I_PWM_ENABLE);
+			sun20i_pwm_writel(sun20i_chip, clk_gate, SUN20I_PWM_CLK_GATE);
+		}
+	}
+
+	if (state->polarity != pwm->state.polarity ||
+	    state->duty_cycle != pwm->state.duty_cycle ||
+	    state->period != pwm->state.period) {
+		ctl = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CTL(pwm->hwpwm));
+		clk_cfg = sun20i_pwm_readl(sun20i_chip, SUN20I_PWM_CLK_CFG(pwm->hwpwm));
+		hosc_rate = clk_get_rate(sun20i_chip->clk_hosc);
+		bus_rate = clk_get_rate(sun20i_chip->clk_apb0);
+		if (pwm_en & SUN20I_PWM_ENABLE_EN(pwm->hwpwm ^ 1)) {
+			/* if the neighbor channel is enable, check period only */
+			use_bus_clk = FIELD_GET(SUN20I_PWM_CLK_CFG_SRC, clk_cfg) != 0;
+			val = mul_u64_u64_div_u64(state->period,
+						  (use_bus_clk ? bus_rate : hosc_rate),
+						  NSEC_PER_SEC);
+
+			div_m = FIELD_GET(SUN20I_PWM_CLK_CFG_DIV_M, clk_cfg);
+		} else {
+			/* check period and select clock source */
+			use_bus_clk = false;
+			val = mul_u64_u64_div_u64(state->period, hosc_rate, NSEC_PER_SEC);
+			if (val <= 1) {
+				use_bus_clk = true;
+				val = mul_u64_u64_div_u64(state->period, bus_rate, NSEC_PER_SEC);
+				if (val <= 1) {
+					ret = -EINVAL;
+					goto unlock_mutex;
+				}
+			}
+			div_m = fls(DIV_ROUND_DOWN_ULL(val, SUN20I_PWM_MAGIC));
+			if (div_m > SUN20I_PWM_CLK_DIV_M_MAX) {
+				ret = -EINVAL;
+				goto unlock_mutex;
+			}
+
+			/* set up the CLK_DIV_M and clock CLK_SRC */
+			clk_cfg = FIELD_PREP(SUN20I_PWM_CLK_CFG_DIV_M, div_m);
+			clk_cfg |= FIELD_PREP(SUN20I_PWM_CLK_CFG_SRC, use_bus_clk);
+
+			sun20i_pwm_writel(sun20i_chip, clk_cfg, SUN20I_PWM_CLK_CFG(pwm->hwpwm));
+		}
+
+		/* calculate prescale_k, PWM entire cycle */
+		ent_cycle = val >> div_m;
+		prescale_k = DIV_ROUND_DOWN_ULL(ent_cycle, 65537);
+		if (prescale_k > SUN20I_PWM_CTL_PRESCAL_K_MAX)
+			prescale_k = SUN20I_PWM_CTL_PRESCAL_K_MAX;
+
+		do_div(ent_cycle, prescale_k + 1);
+
+		/* for N cycles, PPRx.PWM_ENTIRE_CYCLE = (N-1) */
+		reg_period = FIELD_PREP(SUN20I_PWM_PERIOD_ENTIRE_CYCLE, ent_cycle - 1);
+
+		/* set duty cycle */
+		val = mul_u64_u64_div_u64(state->duty_cycle,
+					  (use_bus_clk ? bus_rate : hosc_rate),
+					  NSEC_PER_SEC);
+		act_cycle = val >> div_m;
+		do_div(act_cycle, prescale_k + 1);
+
+		/*
+		 * The formula of the output period and the duty-cycle for PWM are as follows.
+		 * T period = (PWM01_CLK / PWM0_PRESCALE_K)^-1 * (PPR0.PWM_ENTIRE_CYCLE + 1)
+		 * T high-level = (PWM01_CLK / PWM0_PRESCALE_K)^-1 * PPR0.PWM_ACT_CYCLE
+		 * Duty-cycle = T high-level / T period
+		 */
+		reg_period |= FIELD_PREP(SUN20I_PWM_PERIOD_ACT_CYCLE, act_cycle);
+		sun20i_pwm_writel(sun20i_chip, reg_period, SUN20I_PWM_PERIOD(pwm->hwpwm));
+
+		ctl = FIELD_PREP(SUN20I_PWM_CTL_PRESCAL_K, prescale_k);
+		if (state->polarity == PWM_POLARITY_NORMAL)
+			ctl |= SUN20I_PWM_CTL_ACT_STA;
+
+		sun20i_pwm_writel(sun20i_chip, ctl, SUN20I_PWM_CTL(pwm->hwpwm));
+	}
+
+	if (state->enabled != pwm->state.enabled && state->enabled) {
+		clk_gate &= ~SUN20I_PWM_CLK_GATE_BYPASS(pwm->hwpwm);
+		clk_gate |= SUN20I_PWM_CLK_GATE_GATING(pwm->hwpwm);
+		pwm_en |= SUN20I_PWM_ENABLE_EN(pwm->hwpwm);
+		sun20i_pwm_writel(sun20i_chip, pwm_en, SUN20I_PWM_ENABLE);
+		sun20i_pwm_writel(sun20i_chip, clk_gate, SUN20I_PWM_CLK_GATE);
+	}
+
+unlock_mutex:
+	mutex_unlock(&sun20i_chip->mutex);
+
+	return ret;
+}
+
+static const struct pwm_ops sun20i_pwm_ops = {
+	.get_state = sun20i_pwm_get_state,
+	.apply = sun20i_pwm_apply,
+	.owner = THIS_MODULE,
+};
+
+static const struct of_device_id sun20i_pwm_dt_ids[] = {
+	{ .compatible = "allwinner,sun20i-d1-pwm" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, sun20i_pwm_dt_ids);
+
+static int sun20i_pwm_probe(struct platform_device *pdev)
+{
+	struct sun20i_pwm_chip *sun20i_chip;
+	int ret;
+
+	sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
+	if (!sun20i_chip)
+		return -ENOMEM;
+
+	sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(sun20i_chip->base))
+		return PTR_ERR(sun20i_chip->base);
+
+	sun20i_chip->clk_bus = devm_clk_get_enabled(&pdev->dev, "bus");
+	if (IS_ERR(sun20i_chip->clk_bus))
+		return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_bus),
+				     "failed to get bus clock\n");
+
+	sun20i_chip->clk_hosc = devm_clk_get_enabled(&pdev->dev, "hosc");
+	if (IS_ERR(sun20i_chip->clk_hosc))
+		return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_hosc),
+				     "failed to get hosc clock\n");
+
+	sun20i_chip->clk_apb0 = devm_clk_get_enabled(&pdev->dev, "apb0");
+	if (IS_ERR(sun20i_chip->clk_apb0))
+		return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->clk_apb0),
+				     "failed to get apb0 clock\n");
+
+	sun20i_chip->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(sun20i_chip->rst))
+		return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
+				     "failed to get bus reset\n");
+
+	ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
+				   &sun20i_chip->chip.npwm);
+	if (ret)
+		sun20i_chip->chip.npwm = 8;
+
+	if (sun20i_chip->chip.npwm > 16)
+		sun20i_chip->chip.npwm = 16;
+
+	/* Deassert reset */
+	ret = reset_control_deassert(sun20i_chip->rst);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "failed to deassert reset\n");
+
+	sun20i_chip->chip.dev = &pdev->dev;
+	sun20i_chip->chip.ops = &sun20i_pwm_ops;
+
+	mutex_init(&sun20i_chip->mutex);
+
+	ret = pwmchip_add(&sun20i_chip->chip);
+	if (ret < 0) {
+		reset_control_assert(sun20i_chip->rst);
+		return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
+	}
+
+	platform_set_drvdata(pdev, sun20i_chip);
+
+	return 0;
+}
+
+static void sun20i_pwm_remove(struct platform_device *pdev)
+{
+	struct sun20i_pwm_chip *sun20i_chip = platform_get_drvdata(pdev);
+
+	pwmchip_remove(&sun20i_chip->chip);
+
+	reset_control_assert(sun20i_chip->rst);
+}
+
+static struct platform_driver sun20i_pwm_driver = {
+	.driver = {
+		.name = "sun20i-pwm",
+		.of_match_table = sun20i_pwm_dt_ids,
+	},
+	.probe = sun20i_pwm_probe,
+	.remove_new = sun20i_pwm_remove,
+};
+module_platform_driver(sun20i_pwm_driver);
+
+MODULE_AUTHOR("Aleksandr Shubin <privatesub2@gmail.com>");
+MODULE_DESCRIPTION("Allwinner sun20i PWM driver");
+MODULE_LICENSE("GPL");