ar71xx_cpudef.h revision 233081
1211447Sadrian/*- 2211447Sadrian * Copyright (c) 2010 Adrian Chadd 3211447Sadrian * All rights reserved. 4211447Sadrian * 5211447Sadrian * Redistribution and use in source and binary forms, with or without 6211447Sadrian * modification, are permitted provided that the following conditions 7211447Sadrian * are met: 8211447Sadrian * 1. Redistributions of source code must retain the above copyright 9211447Sadrian * notice, this list of conditions and the following disclaimer. 10211447Sadrian * 2. Redistributions in binary form must reproduce the above copyright 11211447Sadrian * notice, this list of conditions and the following disclaimer in the 12211447Sadrian * documentation and/or other materials provided with the distribution. 13211447Sadrian * 14211447Sadrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15211447Sadrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16211447Sadrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17211447Sadrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18211447Sadrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19211447Sadrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20211447Sadrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21211447Sadrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22211447Sadrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23211447Sadrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24211447Sadrian * SUCH DAMAGE. 25211447Sadrian */ 26211447Sadrian 27211447Sadrian/* $FreeBSD: head/sys/mips/atheros/ar71xx_cpudef.h 233081 2012-03-17 07:25:23Z adrian $ */ 28211447Sadrian 29211447Sadrian#ifndef __AR71XX_CPUDEF_H__ 30211447Sadrian#define __AR71XX_CPUDEF_H__ 31211447Sadrian 32211447Sadrianstruct ar71xx_cpu_def { 33211447Sadrian void (* detect_mem_size) (void); 34211447Sadrian void (* detect_sys_frequency) (void); 35211447Sadrian void (* ar71xx_chip_device_stop) (uint32_t); 36211447Sadrian void (* ar71xx_chip_device_start) (uint32_t); 37211447Sadrian int (* ar71xx_chip_device_stopped) (uint32_t); 38228018Sray void (* ar71xx_chip_set_pll_ge) (int, int); 39233081Sadrian void (* ar71xx_chip_set_mii_speed) (uint32_t, uint32_t); 40228018Sray void (* ar71xx_chip_ddr_flush_ge) (int); 41211447Sadrian uint32_t (* ar71xx_chip_get_eth_pll) (unsigned int, int); 42211447Sadrian 43211447Sadrian /* 44211447Sadrian * From Linux - Handling this IRQ is a bit special. 45211447Sadrian * AR71xx - AR71XX_DDR_REG_FLUSH_PCI 46211447Sadrian * AR724x - AR724X_DDR_REG_FLUSH_PCIE 47211447Sadrian * AR91xx - AR91XX_DDR_REG_FLUSH_WMAC 48211447Sadrian * 49211447Sadrian * These are set when STATUSF_IP2 is set in regiser c0. 50211447Sadrian * This flush is done before the IRQ is handled to make 51211447Sadrian * sure the driver correctly sees any memory updates. 52211447Sadrian */ 53221198Sadrian void (* ar71xx_chip_ddr_flush_ip2) (void); 54211447Sadrian /* 55211447Sadrian * The USB peripheral init code is subtly different for 56211447Sadrian * each chip. 57211447Sadrian */ 58211447Sadrian void (* ar71xx_chip_init_usb_peripheral) (void); 59211447Sadrian}; 60211447Sadrian 61211447Sadrianextern struct ar71xx_cpu_def * ar71xx_cpu_ops; 62211447Sadrian 63211447Sadrianstatic inline void ar71xx_detect_sys_frequency(void) 64211447Sadrian{ 65211447Sadrian ar71xx_cpu_ops->detect_sys_frequency(); 66211447Sadrian} 67211447Sadrian 68211447Sadrianstatic inline void ar71xx_device_stop(uint32_t mask) 69211447Sadrian{ 70211447Sadrian ar71xx_cpu_ops->ar71xx_chip_device_stop(mask); 71211447Sadrian} 72211447Sadrian 73211447Sadrianstatic inline void ar71xx_device_start(uint32_t mask) 74211447Sadrian{ 75211447Sadrian ar71xx_cpu_ops->ar71xx_chip_device_start(mask); 76211447Sadrian} 77211447Sadrian 78211447Sadrianstatic inline int ar71xx_device_stopped(uint32_t mask) 79211447Sadrian{ 80211447Sadrian return ar71xx_cpu_ops->ar71xx_chip_device_stopped(mask); 81211447Sadrian} 82211447Sadrian 83228018Sraystatic inline void ar71xx_device_set_pll_ge(int unit, int speed) 84211509Sadrian{ 85228018Sray ar71xx_cpu_ops->ar71xx_chip_set_pll_ge(unit, speed); 86211509Sadrian} 87211509Sadrian 88233081Sadrianstatic inline void ar71xx_device_set_mii_speed(int unit, int speed) 89233081Sadrian{ 90233081Sadrian ar71xx_cpu_ops->ar71xx_chip_set_mii_speed(unit, speed); 91233081Sadrian} 92233081Sadrian 93228018Sraystatic inline void ar71xx_device_flush_ddr_ge(int unit) 94211509Sadrian{ 95228018Sray ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ge(unit); 96211509Sadrian} 97211509Sadrian 98211447Sadrianstatic inline void ar71xx_init_usb_peripheral(void) 99211447Sadrian{ 100211447Sadrian ar71xx_cpu_ops->ar71xx_chip_init_usb_peripheral(); 101211447Sadrian} 102211447Sadrian 103221198Sadrianstatic inline void ar71xx_device_ddr_flush_ip2(void) 104221198Sadrian{ 105221198Sadrian ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ip2(); 106221198Sadrian} 107221198Sadrian 108211447Sadrian/* XXX shouldn't be here! */ 109211447Sadrianextern uint32_t u_ar71xx_cpu_freq; 110211447Sadrianextern uint32_t u_ar71xx_ahb_freq; 111211447Sadrianextern uint32_t u_ar71xx_ddr_freq; 112211447Sadrian 113211447Sadrianstatic inline uint64_t ar71xx_cpu_freq(void) { return u_ar71xx_cpu_freq; } 114211447Sadrianstatic inline uint64_t ar71xx_ahb_freq(void) { return u_ar71xx_ahb_freq; } 115211447Sadrianstatic inline uint64_t ar71xx_ddr_freq(void) { return u_ar71xx_ddr_freq; } 116211447Sadrian 117211447Sadrian#endif 118