2 * Nuvoton NPCM7xx PWM Module
4 * Copyright 2020 Google LLC
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 #include "hw/sysbus.h"
23 /* Each PWM module holds 4 PWM channels. */
24 #define NPCM7XX_PWM_PER_MODULE 4
27 * Number of registers in one pwm module. Don't change this without increasing
28 * the version_id in vmstate.
30 #define NPCM7XX_PWM_NR_REGS (0x54 / sizeof(uint32_t))
33 * The maximum duty values. Each duty unit represents 1/NPCM7XX_PWM_MAX_DUTY
34 * cycles. For example, if NPCM7XX_PWM_MAX_DUTY=1,000,000 and a PWM has a duty
35 * value of 100,000 the duty cycle for that PWM is 10%.
37 #define NPCM7XX_PWM_MAX_DUTY 1000000
39 typedef struct NPCM7xxPWMState NPCM7xxPWMState
;
42 * struct NPCM7xxPWM - The state of a single PWM channel.
43 * @module: The PWM module that contains this channel.
44 * @irq: GIC interrupt line to fire on expiration if enabled.
45 * @running: Whether this PWM channel is generating output.
46 * @inverted: Whether this PWM channel is inverted.
47 * @index: The index of this PWM channel.
48 * @cnr: The counter register.
49 * @cmr: The comparator register.
50 * @pdr: The data register.
51 * @pwdr: The watchdog register.
52 * @freq: The frequency of this PWM channel.
53 * @duty: The duty cycle of this PWM channel. One unit represents
54 * 1/NPCM7XX_MAX_DUTY cycles.
56 typedef struct NPCM7xxPWM
{
57 NPCM7xxPWMState
*module
;
75 * struct NPCM7xxPWMState - Pulse Width Modulation device state.
76 * @parent: System bus device.
77 * @iomem: Memory region through which registers are accessed.
78 * @clock: The PWM clock.
79 * @pwm: The PWM channels owned by this module.
80 * @duty_gpio_out: The duty cycle of each PWM channels as a output GPIO.
81 * @ppr: The prescaler register.
82 * @csr: The clock selector register.
83 * @pcr: The control register.
84 * @pier: The interrupt enable register.
85 * @piir: The interrupt indication register.
87 struct NPCM7xxPWMState
{
93 NPCM7xxPWM pwm
[NPCM7XX_PWM_PER_MODULE
];
94 qemu_irq duty_gpio_out
[NPCM7XX_PWM_PER_MODULE
];
103 #define TYPE_NPCM7XX_PWM "npcm7xx-pwm"
104 OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxPWMState
, NPCM7XX_PWM
)
106 #endif /* NPCM7XX_PWM_H */