ar71xx_cpudef.h revision 234907
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 234907 2012-05-02 04:51:43Z 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); 38234907Sadrian void (* ar71xx_chip_set_pll_ge) (int, int, uint32_t); 39233081Sadrian void (* ar71xx_chip_set_mii_speed) (uint32_t, uint32_t); 40234906Sadrian void (* ar71xx_chip_set_mii_if) (uint32_t, ar71xx_mii_mode); 41228018Sray void (* ar71xx_chip_ddr_flush_ge) (int); 42211447Sadrian uint32_t (* ar71xx_chip_get_eth_pll) (unsigned int, int); 43211447Sadrian 44211447Sadrian /* 45211447Sadrian * From Linux - Handling this IRQ is a bit special. 46211447Sadrian * AR71xx - AR71XX_DDR_REG_FLUSH_PCI 47211447Sadrian * AR724x - AR724X_DDR_REG_FLUSH_PCIE 48211447Sadrian * AR91xx - AR91XX_DDR_REG_FLUSH_WMAC 49211447Sadrian * 50211447Sadrian * These are set when STATUSF_IP2 is set in regiser c0. 51211447Sadrian * This flush is done before the IRQ is handled to make 52211447Sadrian * sure the driver correctly sees any memory updates. 53211447Sadrian */ 54221198Sadrian void (* ar71xx_chip_ddr_flush_ip2) (void); 55211447Sadrian /* 56211447Sadrian * The USB peripheral init code is subtly different for 57211447Sadrian * each chip. 58211447Sadrian */ 59211447Sadrian void (* ar71xx_chip_init_usb_peripheral) (void); 60211447Sadrian}; 61211447Sadrian 62211447Sadrianextern struct ar71xx_cpu_def * ar71xx_cpu_ops; 63211447Sadrian 64211447Sadrianstatic inline void ar71xx_detect_sys_frequency(void) 65211447Sadrian{ 66211447Sadrian ar71xx_cpu_ops->detect_sys_frequency(); 67211447Sadrian} 68211447Sadrian 69211447Sadrianstatic inline void ar71xx_device_stop(uint32_t mask) 70211447Sadrian{ 71211447Sadrian ar71xx_cpu_ops->ar71xx_chip_device_stop(mask); 72211447Sadrian} 73211447Sadrian 74211447Sadrianstatic inline void ar71xx_device_start(uint32_t mask) 75211447Sadrian{ 76211447Sadrian ar71xx_cpu_ops->ar71xx_chip_device_start(mask); 77211447Sadrian} 78211447Sadrian 79211447Sadrianstatic inline int ar71xx_device_stopped(uint32_t mask) 80211447Sadrian{ 81211447Sadrian return ar71xx_cpu_ops->ar71xx_chip_device_stopped(mask); 82211447Sadrian} 83211447Sadrian 84234907Sadrianstatic inline void ar71xx_device_set_pll_ge(int unit, int speed, uint32_t pll) 85211509Sadrian{ 86234907Sadrian ar71xx_cpu_ops->ar71xx_chip_set_pll_ge(unit, speed, pll); 87211509Sadrian} 88211509Sadrian 89233081Sadrianstatic inline void ar71xx_device_set_mii_speed(int unit, int speed) 90233081Sadrian{ 91233081Sadrian ar71xx_cpu_ops->ar71xx_chip_set_mii_speed(unit, speed); 92233081Sadrian} 93233081Sadrian 94234906Sadrianstatic inline void ar71xx_device_set_mii_if(int unit, ar71xx_mii_mode mii_cfg) 95234906Sadrian{ 96234906Sadrian ar71xx_cpu_ops->ar71xx_chip_set_mii_if(unit, mii_cfg); 97234906Sadrian} 98234906Sadrian 99228018Sraystatic inline void ar71xx_device_flush_ddr_ge(int unit) 100211509Sadrian{ 101228018Sray ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ge(unit); 102211509Sadrian} 103211509Sadrian 104234907Sadrianstatic inline uint32_t ar71xx_device_get_eth_pll(unsigned int unit, int speed) 105234907Sadrian{ 106234907Sadrian return (ar71xx_cpu_ops->ar71xx_chip_get_eth_pll(unit, speed)); 107234907Sadrian} 108234907Sadrian 109211447Sadrianstatic inline void ar71xx_init_usb_peripheral(void) 110211447Sadrian{ 111211447Sadrian ar71xx_cpu_ops->ar71xx_chip_init_usb_peripheral(); 112211447Sadrian} 113211447Sadrian 114221198Sadrianstatic inline void ar71xx_device_ddr_flush_ip2(void) 115221198Sadrian{ 116221198Sadrian ar71xx_cpu_ops->ar71xx_chip_ddr_flush_ip2(); 117221198Sadrian} 118221198Sadrian 119211447Sadrian/* XXX shouldn't be here! */ 120211447Sadrianextern uint32_t u_ar71xx_cpu_freq; 121211447Sadrianextern uint32_t u_ar71xx_ahb_freq; 122211447Sadrianextern uint32_t u_ar71xx_ddr_freq; 123211447Sadrian 124211447Sadrianstatic inline uint64_t ar71xx_cpu_freq(void) { return u_ar71xx_cpu_freq; } 125211447Sadrianstatic inline uint64_t ar71xx_ahb_freq(void) { return u_ar71xx_ahb_freq; } 126211447Sadrianstatic inline uint64_t ar71xx_ddr_freq(void) { return u_ar71xx_ddr_freq; } 127211447Sadrian 128211447Sadrian#endif 129