xref: /netbsd-src/sys/arch/arm/imx/imx51_pwm.c (revision 2bd1432c88573054d9e5d00b69e495cb3aaef816)
1*2bd1432cShkenken /*	$NetBSD: imx51_pwm.c,v 1.2 2020/05/20 05:10:42 hkenken Exp $	*/
2b9040788Shkenken 
3b9040788Shkenken /*-
4b9040788Shkenken  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
5b9040788Shkenken  * Written by Hashimoto Kenichi for Genetec Corporation.
6b9040788Shkenken  *
7b9040788Shkenken  * Redistribution and use in source and binary forms, with or without
8b9040788Shkenken  * modification, are permitted provided that the following conditions
9b9040788Shkenken  * are met:
10b9040788Shkenken  * 1. Redistributions of source code must retain the above copyright
11b9040788Shkenken  *    notice, this list of conditions and the following disclaimer.
12b9040788Shkenken  * 2. Redistributions in binary form must reproduce the above copyright
13b9040788Shkenken  *    notice, this list of conditions and the following disclaimer in the
14b9040788Shkenken  *    documentation and/or other materials provided with the distribution.
15b9040788Shkenken  *
16b9040788Shkenken  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17b9040788Shkenken  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b9040788Shkenken  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b9040788Shkenken  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20b9040788Shkenken  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b9040788Shkenken  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b9040788Shkenken  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b9040788Shkenken  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b9040788Shkenken  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b9040788Shkenken  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b9040788Shkenken  * SUCH DAMAGE.
27b9040788Shkenken  */
28b9040788Shkenken 
29b9040788Shkenken #include <sys/cdefs.h>
30*2bd1432cShkenken __KERNEL_RCSID(0, "$NetBSD: imx51_pwm.c,v 1.2 2020/05/20 05:10:42 hkenken Exp $");
31b9040788Shkenken 
32b9040788Shkenken #include "locators.h"
33b9040788Shkenken #include "opt_imx.h"
34b9040788Shkenken 
35b9040788Shkenken #include <sys/param.h>
36b9040788Shkenken #include <sys/bus.h>
37b9040788Shkenken #include <sys/device.h>
38b9040788Shkenken 
39b9040788Shkenken #include <arm/imx/imxpwmvar.h>
40b9040788Shkenken #include <arm/imx/imx51reg.h>
41b9040788Shkenken #include <arm/imx/imx51var.h>
42b9040788Shkenken #include <arm/imx/imx51_ccmvar.h>
43b9040788Shkenken 
44b9040788Shkenken int
imxpwm_match(device_t parent,cfdata_t cf,void * aux)45b9040788Shkenken imxpwm_match(device_t parent, cfdata_t cf, void *aux)
46b9040788Shkenken {
47b9040788Shkenken 	struct axi_attach_args *aa = aux;
48b9040788Shkenken 
49b9040788Shkenken 	switch (aa->aa_addr) {
50b9040788Shkenken 	case PWM1_BASE:
51b9040788Shkenken 	case PWM2_BASE:
52b9040788Shkenken 		return 1;
53b9040788Shkenken 	}
54b9040788Shkenken 
55b9040788Shkenken 	return 0;
56b9040788Shkenken }
57b9040788Shkenken 
58b9040788Shkenken void
imxpwm_attach(struct imxpwm_softc * sc,void * aux)59b9040788Shkenken imxpwm_attach(struct imxpwm_softc *sc, void *aux)
60b9040788Shkenken {
61b9040788Shkenken 	struct axi_attach_args *aa = aux;
62b9040788Shkenken 
63b9040788Shkenken 	if (aa->aa_size == AXICF_SIZE_DEFAULT)
64b9040788Shkenken 		aa->aa_size = PWM_SIZE;
65*2bd1432cShkenken 
66b9040788Shkenken 	sc->sc_iot = aa->aa_iot;
67b9040788Shkenken 	sc->sc_intr = aa->aa_irq;
68b9040788Shkenken 	sc->sc_freq = imx51_get_clock(IMX51CLK_IPG_CLK_ROOT);
69*2bd1432cShkenken 
70b9040788Shkenken 	if (bus_space_map(aa->aa_iot, aa->aa_addr, aa->aa_size, 0, &sc->sc_ioh))
71b9040788Shkenken 		panic("%s: couldn't map", device_xname(sc->sc_dev));
72*2bd1432cShkenken 
73*2bd1432cShkenken 	sc->sc_ih = intr_establish(sc->sc_intr, IPL_BIO, IST_LEVEL,
74*2bd1432cShkenken 	    imxpwm_intr, sc);
75*2bd1432cShkenken 
76b9040788Shkenken 	imxpwm_attach_common(sc);
77b9040788Shkenken }
78