Blame view

drivers/pwm/pwm-lpss-platform.c 2.86 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
2
3
4
5
6
7
  /*
   * Intel Low Power Subsystem PWM controller driver
   *
   * Copyright (C) 2014, Intel Corporation
   *
   * Derived from the original pwm-lpss.c
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
8
9
10
11
12
13
   */
  
  #include <linux/acpi.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/platform_device.h>
f080be27d   Qipeng Zha   pwm: lpss: Add su...
14
  #include <linux/pm_runtime.h>
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
15
16
  
  #include "pwm-lpss.h"
9900073cf   Andy Shevchenko   pwm: lpss: Do not...
17
18
19
20
21
22
23
24
25
26
27
28
  /* BayTrail */
  static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
  	.clk_rate = 25000000,
  	.npwm = 1,
  	.base_unit_bits = 16,
  };
  
  /* Braswell */
  static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
  	.clk_rate = 19200000,
  	.npwm = 1,
  	.base_unit_bits = 16,
4743765ba   Hans de Goede   pwm: lpss: Force ...
29
  	.other_devices_aml_touches_pwm_regs = true,
9900073cf   Andy Shevchenko   pwm: lpss: Do not...
30
31
32
33
34
35
36
  };
  
  /* Broxton */
  static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
  	.clk_rate = 19200000,
  	.npwm = 4,
  	.base_unit_bits = 22,
b997e3edc   Hans de Goede   pwm: lpss: Set en...
37
  	.bypass = true,
9900073cf   Andy Shevchenko   pwm: lpss: Do not...
38
  };
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  static int pwm_lpss_probe_platform(struct platform_device *pdev)
  {
  	const struct pwm_lpss_boardinfo *info;
  	const struct acpi_device_id *id;
  	struct pwm_lpss_chip *lpwm;
  	struct resource *r;
  
  	id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
  	if (!id)
  		return -ENODEV;
  
  	info = (const struct pwm_lpss_boardinfo *)id->driver_data;
  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  
  	lpwm = pwm_lpss_probe(&pdev->dev, r, info);
  	if (IS_ERR(lpwm))
  		return PTR_ERR(lpwm);
  
  	platform_set_drvdata(pdev, lpwm);
f080be27d   Qipeng Zha   pwm: lpss: Add su...
58

4743765ba   Hans de Goede   pwm: lpss: Force ...
59
  	dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_SMART_PREPARE);
f080be27d   Qipeng Zha   pwm: lpss: Add su...
60
61
  	pm_runtime_set_active(&pdev->dev);
  	pm_runtime_enable(&pdev->dev);
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
62
63
64
65
66
67
  	return 0;
  }
  
  static int pwm_lpss_remove_platform(struct platform_device *pdev)
  {
  	struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev);
f080be27d   Qipeng Zha   pwm: lpss: Add su...
68
  	pm_runtime_disable(&pdev->dev);
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
69
70
  	return pwm_lpss_remove(lpwm);
  }
4743765ba   Hans de Goede   pwm: lpss: Force ...
71
  static int pwm_lpss_prepare(struct device *dev)
6a425ecd1   Hans de Goede   pwm: lpss: Check ...
72
73
  {
  	struct pwm_lpss_chip *lpwm = dev_get_drvdata(dev);
6a425ecd1   Hans de Goede   pwm: lpss: Check ...
74

4743765ba   Hans de Goede   pwm: lpss: Force ...
75
76
77
78
79
80
  	/*
  	 * If other device's AML code touches the PWM regs on suspend/resume
  	 * force runtime-resume the PWM controller to allow this.
  	 */
  	if (lpwm->info->other_devices_aml_touches_pwm_regs)
  		return 0; /* Force runtime-resume */
6a425ecd1   Hans de Goede   pwm: lpss: Check ...
81

4743765ba   Hans de Goede   pwm: lpss: Force ...
82
  	return 1; /* If runtime-suspended leave as is */
6a425ecd1   Hans de Goede   pwm: lpss: Check ...
83
84
85
  }
  
  static const struct dev_pm_ops pwm_lpss_platform_pm_ops = {
4743765ba   Hans de Goede   pwm: lpss: Force ...
86
  	.prepare = pwm_lpss_prepare,
6a425ecd1   Hans de Goede   pwm: lpss: Check ...
87
  };
1d375b58c   Hans de Goede   pwm: lpss: platfo...
88

c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
89
90
91
  static const struct acpi_device_id pwm_lpss_acpi_match[] = {
  	{ "80860F09", (unsigned long)&pwm_lpss_byt_info },
  	{ "80862288", (unsigned long)&pwm_lpss_bsw_info },
1688c8717   Hans de Goede   pwm: lpss: Add AC...
92
  	{ "80862289", (unsigned long)&pwm_lpss_bsw_info },
03f00e531   Mika Westerberg   pwm: lpss: Add mo...
93
  	{ "80865AC8", (unsigned long)&pwm_lpss_bxt_info },
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
94
95
96
97
98
99
100
101
  	{ },
  };
  MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
  
  static struct platform_driver pwm_lpss_driver_platform = {
  	.driver = {
  		.name = "pwm-lpss",
  		.acpi_match_table = pwm_lpss_acpi_match,
1d375b58c   Hans de Goede   pwm: lpss: platfo...
102
  		.pm = &pwm_lpss_platform_pm_ops,
c558e39e1   Andy Shevchenko   pwm: lpss: Proper...
103
104
105
106
107
108
109
110
111
  	},
  	.probe = pwm_lpss_probe_platform,
  	.remove = pwm_lpss_remove_platform,
  };
  module_platform_driver(pwm_lpss_driver_platform);
  
  MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
  MODULE_LICENSE("GPL v2");
  MODULE_ALIAS("platform:pwm-lpss");