ar71xx_cpudef.h revision 211447
1164022Sdds/*-
2164022Sdds * Copyright (c) 2010 Adrian Chadd
3164022Sdds * All rights reserved.
4164022Sdds *
5164022Sdds * Redistribution and use in source and binary forms, with or without
6164022Sdds * modification, are permitted provided that the following conditions
7164022Sdds * are met:
8164022Sdds * 1. Redistributions of source code must retain the above copyright
9164022Sdds *    notice, this list of conditions and the following disclaimer.
10164022Sdds * 2. Redistributions in binary form must reproduce the above copyright
11164022Sdds *    notice, this list of conditions and the following disclaimer in the
12164022Sdds *    documentation and/or other materials provided with the distribution.
13164022Sdds *
14164022Sdds * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15164022Sdds * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16164022Sdds * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17164022Sdds * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18164022Sdds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19164022Sdds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20164022Sdds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21164022Sdds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22164022Sdds * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23164022Sdds * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24164022Sdds * SUCH DAMAGE.
25164022Sdds */
26164022Sdds
27164022Sdds/* $FreeBSD: head/sys/mips/atheros/ar71xx_cpudef.h 211447 2010-08-18 08:22:09Z adrian $ */
28164022Sdds
29164022Sdds#ifndef	__AR71XX_CPUDEF_H__
30164022Sdds#define	__AR71XX_CPUDEF_H__
31164022Sdds
32164022Sddsstruct ar71xx_cpu_def {
33164022Sdds	void (* detect_mem_size) (void);
34164022Sdds	void (* detect_sys_frequency) (void);
35164022Sdds	void (* ar71xx_chip_device_stop) (uint32_t);
36164022Sdds	void (* ar71xx_chip_device_start) (uint32_t);
37164022Sdds	int (* ar71xx_chip_device_stopped) (uint32_t);
38164022Sdds	void (* ar71xx_chip_set_pll_ge0) (int);
39164022Sdds	void (* ar71xx_chip_set_pll_ge1) (int);
40164022Sdds	void (* ar71xx_chip_ddr_flush_ge0) (void);
41164022Sdds	void (* ar71xx_chip_ddr_flush_ge1) (void);
42164022Sdds	uint32_t (* ar71xx_chip_get_eth_pll) (unsigned int, int);
43164022Sdds
44164022Sdds	/*
45164022Sdds	 * From Linux - Handling this IRQ is a bit special.
46164022Sdds	 * AR71xx - AR71XX_DDR_REG_FLUSH_PCI
47164022Sdds	 * AR724x - AR724X_DDR_REG_FLUSH_PCIE
48164022Sdds	 * AR91xx - AR91XX_DDR_REG_FLUSH_WMAC
49164022Sdds	 *
50164022Sdds	 * These are set when STATUSF_IP2 is set in regiser c0.
51164022Sdds	 * This flush is done before the IRQ is handled to make
52	 * sure the driver correctly sees any memory updates.
53	 */
54	void (* ar71xx_chip_irq_flush_ip2) (void);
55	/*
56	 * The USB peripheral init code is subtly different for
57	 * each chip.
58	 */
59	void (* ar71xx_chip_init_usb_peripheral) (void);
60};
61
62extern struct ar71xx_cpu_def * ar71xx_cpu_ops;
63
64static inline void ar71xx_detect_sys_frequency(void)
65{
66	ar71xx_cpu_ops->detect_sys_frequency();
67}
68
69static inline void ar71xx_device_stop(uint32_t mask)
70{
71	ar71xx_cpu_ops->ar71xx_chip_device_stop(mask);
72}
73
74static inline void ar71xx_device_start(uint32_t mask)
75{
76	ar71xx_cpu_ops->ar71xx_chip_device_start(mask);
77}
78
79static inline int ar71xx_device_stopped(uint32_t mask)
80{
81	return ar71xx_cpu_ops->ar71xx_chip_device_stopped(mask);
82}
83
84static inline void ar71xx_device_flush_ddr_ge0(void)
85{
86	ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ge0();
87}
88
89static inline void ar71xx_device_flush_ddr_ge1(void)
90{
91	ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ge1();
92}
93
94static inline void ar71xx_init_usb_peripheral(void)
95{
96	ar71xx_cpu_ops->ar71xx_chip_init_usb_peripheral();
97}
98
99/* XXX shouldn't be here! */
100extern uint32_t u_ar71xx_cpu_freq;
101extern uint32_t u_ar71xx_ahb_freq;
102extern uint32_t u_ar71xx_ddr_freq;
103
104static inline uint64_t ar71xx_cpu_freq(void) { return u_ar71xx_cpu_freq; }
105static inline uint64_t ar71xx_ahb_freq(void) { return u_ar71xx_ahb_freq; }
106static inline uint64_t ar71xx_ddr_freq(void) { return u_ar71xx_ddr_freq; }
107
108#endif
109