Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Intel Low Power Subsystem PWM controller driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2014, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Derived from the original pwm-lpss.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "pwm-lpss.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* BayTrail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	.clk_rate = 25000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	.npwm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	.base_unit_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* Braswell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	.clk_rate = 19200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.npwm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.base_unit_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.other_devices_aml_touches_pwm_regs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* Broxton */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.clk_rate = 19200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.npwm = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	.base_unit_bits = 22,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	.bypass = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int pwm_lpss_probe_platform(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	const struct pwm_lpss_boardinfo *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	const struct acpi_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct pwm_lpss_chip *lpwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	info = (const struct pwm_lpss_boardinfo *)id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	lpwm = pwm_lpss_probe(&pdev->dev, r, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (IS_ERR(lpwm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return PTR_ERR(lpwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	platform_set_drvdata(pdev, lpwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_SMART_PREPARE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	pm_runtime_set_active(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	pm_runtime_enable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static int pwm_lpss_remove_platform(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	pm_runtime_disable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return pwm_lpss_remove(lpwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static int pwm_lpss_prepare(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct pwm_lpss_chip *lpwm = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * If other device's AML code touches the PWM regs on suspend/resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * force runtime-resume the PWM controller to allow this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (lpwm->info->other_devices_aml_touches_pwm_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return 0; /* Force runtime-resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return 1; /* If runtime-suspended leave as is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static const struct dev_pm_ops pwm_lpss_platform_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.prepare = pwm_lpss_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static const struct acpi_device_id pwm_lpss_acpi_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	{ "80860F09", (unsigned long)&pwm_lpss_byt_info },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	{ "80862288", (unsigned long)&pwm_lpss_bsw_info },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	{ "80862289", (unsigned long)&pwm_lpss_bsw_info },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	{ "80865AC8", (unsigned long)&pwm_lpss_bxt_info },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static struct platform_driver pwm_lpss_driver_platform = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		.name = "pwm-lpss",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		.acpi_match_table = pwm_lpss_acpi_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		.pm = &pwm_lpss_platform_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.probe = pwm_lpss_probe_platform,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	.remove = pwm_lpss_remove_platform,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) module_platform_driver(pwm_lpss_driver_platform);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) MODULE_ALIAS("platform:pwm-lpss");