1 /* 2 * (c) 2018 Paul Boddie <paul@boddie.org.uk> 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation; either version 2 of 7 * the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA 18 */ 19 20 #pragma once 21 22 #include <l4/sys/types.h> 23 #include <stdint.h> 24 25 26 27 /* Value types. */ 28 29 enum Jz4730_pwm_shutdown_mode 30 { 31 Jz4730_pwm_shutdown_graceful = 0, 32 Jz4730_pwm_shutdown_abrupt = 1, 33 }; 34 35 36 37 #ifdef __cplusplus 38 39 #include <l4/devices/hw_register_block.h> 40 41 /* A simple abstraction for accessing the PWM registers. */ 42 43 class Pwm_jz4730_chip 44 { 45 private: 46 l4_addr_t _start, _end; 47 Hw::Register_block<32> _regs; 48 49 public: 50 Pwm_jz4730_chip(l4_addr_t start, l4_addr_t end); 51 52 void disable(); 53 void enable(); 54 void set_shutdown_mode(enum Jz4730_pwm_shutdown_mode mode); 55 56 void set_control(uint8_t control); 57 void set_duty(uint16_t duty); 58 void set_period(uint16_t period); 59 }; 60 61 #endif /* __cplusplus */ 62 63 64 65 /* C language interface. */ 66 67 EXTERN_C_BEGIN 68 69 void *jz4730_pwm_init(l4_addr_t start, l4_addr_t end); 70 71 void jz4730_pwm_disable(void *pwm); 72 void jz4730_pwm_enable(void *pwm); 73 void jz4730_pwm_set_shutdown_mode(void *pwm, enum Jz4730_pwm_shutdown_mode mode); 74 75 void jz4730_pwm_set_control(void *pwm, uint8_t control); 76 void jz4730_pwm_set_duty(void *pwm, uint16_t duty); 77 void jz4730_pwm_set_period(void *pwm, uint16_t period); 78 79 EXTERN_C_END