xref: /freebsd/sys/dev/pwm/pwmbus_if.m (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
19312900fSEmmanuel Vadot#-
2*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
39312900fSEmmanuel Vadot#
49312900fSEmmanuel Vadot# Copyright (c) 2018 Emmanuel Vadot <manu@FreeBSD.org>
59312900fSEmmanuel Vadot#
69312900fSEmmanuel Vadot# Redistribution and use in source and binary forms, with or without
79312900fSEmmanuel Vadot# modification, are permitted provided that the following conditions
89312900fSEmmanuel Vadot# are met:
99312900fSEmmanuel Vadot# 1. Redistributions of source code must retain the above copyright
109312900fSEmmanuel Vadot#    notice, this list of conditions and the following disclaimer.
119312900fSEmmanuel Vadot# 2. Redistributions in binary form must reproduce the above copyright
129312900fSEmmanuel Vadot#    notice, this list of conditions and the following disclaimer in the
139312900fSEmmanuel Vadot#    documentation and/or other materials provided with the distribution.
149312900fSEmmanuel Vadot#
159312900fSEmmanuel Vadot# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169312900fSEmmanuel Vadot# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179312900fSEmmanuel Vadot# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189312900fSEmmanuel Vadot# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199312900fSEmmanuel Vadot# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209312900fSEmmanuel Vadot# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219312900fSEmmanuel Vadot# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229312900fSEmmanuel Vadot# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239312900fSEmmanuel Vadot# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249312900fSEmmanuel Vadot# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259312900fSEmmanuel Vadot# SUCH DAMAGE.
269312900fSEmmanuel Vadot#
279312900fSEmmanuel Vadot#
289312900fSEmmanuel Vadot
299312900fSEmmanuel Vadot#include <sys/bus.h>
309312900fSEmmanuel Vadot
319312900fSEmmanuel VadotINTERFACE pwmbus;
329312900fSEmmanuel Vadot
339312900fSEmmanuel VadotCODE {
349312900fSEmmanuel Vadot	static int
357d4a5de8SOskar Holmund	pwm_default_set_flags(device_t bus, u_int channel, uint32_t flags)
369312900fSEmmanuel Vadot	{
379312900fSEmmanuel Vadot
389312900fSEmmanuel Vadot		return (EOPNOTSUPP);
399312900fSEmmanuel Vadot	}
409312900fSEmmanuel Vadot
419312900fSEmmanuel Vadot	static int
427d4a5de8SOskar Holmund	pwm_default_get_flags(device_t bus, u_int channel, uint32_t *flags)
439312900fSEmmanuel Vadot	{
449312900fSEmmanuel Vadot
459312900fSEmmanuel Vadot		*flags = 0;
469312900fSEmmanuel Vadot		return (0);
479312900fSEmmanuel Vadot	}
489312900fSEmmanuel Vadot};
499312900fSEmmanuel Vadot
509312900fSEmmanuel Vadot#
519312900fSEmmanuel Vadot# Config the period (Total number of cycle in ns) and
529312900fSEmmanuel Vadot# the duty (active number of cycle in ns)
539312900fSEmmanuel Vadot#
549312900fSEmmanuel VadotMETHOD int channel_config {
559312900fSEmmanuel Vadot	device_t bus;
566cdbe2bfSIan Lepore	u_int channel;
577d4a5de8SOskar Holmund	u_int period;
587d4a5de8SOskar Holmund	u_int duty;
599312900fSEmmanuel Vadot};
609312900fSEmmanuel Vadot
619312900fSEmmanuel Vadot#
629312900fSEmmanuel Vadot# Get the period (Total number of cycle in ns) and
639312900fSEmmanuel Vadot# the duty (active number of cycle in ns)
649312900fSEmmanuel Vadot#
659312900fSEmmanuel VadotMETHOD int channel_get_config {
669312900fSEmmanuel Vadot	device_t bus;
676cdbe2bfSIan Lepore	u_int channel;
687d4a5de8SOskar Holmund	u_int *period;
697d4a5de8SOskar Holmund	u_int *duty;
709312900fSEmmanuel Vadot};
719312900fSEmmanuel Vadot
729312900fSEmmanuel Vadot#
739312900fSEmmanuel Vadot# Set the flags
749312900fSEmmanuel Vadot#
759312900fSEmmanuel VadotMETHOD int channel_set_flags {
769312900fSEmmanuel Vadot	device_t bus;
776cdbe2bfSIan Lepore	u_int channel;
789312900fSEmmanuel Vadot	uint32_t flags;
799312900fSEmmanuel Vadot} DEFAULT pwm_default_set_flags;
809312900fSEmmanuel Vadot
819312900fSEmmanuel Vadot#
829312900fSEmmanuel Vadot# Get the flags
839312900fSEmmanuel Vadot#
849312900fSEmmanuel VadotMETHOD int channel_get_flags {
857d4a5de8SOskar Holmund	device_t bus;
866cdbe2bfSIan Lepore	u_int channel;
879312900fSEmmanuel Vadot	uint32_t *flags;
889312900fSEmmanuel Vadot} DEFAULT pwm_default_get_flags;
899312900fSEmmanuel Vadot
909312900fSEmmanuel Vadot#
919312900fSEmmanuel Vadot# Enable the pwm output
929312900fSEmmanuel Vadot#
939312900fSEmmanuel VadotMETHOD int channel_enable {
949312900fSEmmanuel Vadot	device_t bus;
956cdbe2bfSIan Lepore	u_int channel;
969312900fSEmmanuel Vadot	bool enable;
979312900fSEmmanuel Vadot};
989312900fSEmmanuel Vadot
999312900fSEmmanuel Vadot#
1009312900fSEmmanuel Vadot# Is the pwm output enabled
1019312900fSEmmanuel Vadot#
1029312900fSEmmanuel VadotMETHOD int channel_is_enabled {
1039312900fSEmmanuel Vadot	device_t bus;
1046cdbe2bfSIan Lepore	u_int channel;
1059312900fSEmmanuel Vadot	bool *enabled;
1069312900fSEmmanuel Vadot};
107f8f8d87cSIan Lepore
108f8f8d87cSIan Lepore#
109f8f8d87cSIan Lepore# Get the number of channels
110f8f8d87cSIan Lepore#
111f8f8d87cSIan LeporeMETHOD int channel_count {
112f8f8d87cSIan Lepore	device_t bus;
1136cdbe2bfSIan Lepore	u_int *nchannel;
114f8f8d87cSIan Lepore};
115