Path: blob/master/arch/avr32/mach-at32ap/hmatrix.c
10817 views
/*1* High-Speed Bus Matrix helper functions2*3* Copyright (C) 2008 Atmel Corporation4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/9#include <linux/clk.h>10#include <linux/io.h>1112#include <mach/chip.h>13#include <mach/hmatrix.h>1415static inline void __hmatrix_write_reg(unsigned long offset, u32 value)16{17__raw_writel(value, (void __iomem __force *)(HMATRIX_BASE + offset));18}1920static inline u32 __hmatrix_read_reg(unsigned long offset)21{22return __raw_readl((void __iomem __force *)(HMATRIX_BASE + offset));23}2425/**26* hmatrix_write_reg - write HMATRIX configuration register27* @offset: register offset28* @value: value to be written to the register at @offset29*/30void hmatrix_write_reg(unsigned long offset, u32 value)31{32clk_enable(&at32_hmatrix_clk);33__hmatrix_write_reg(offset, value);34__hmatrix_read_reg(offset);35clk_disable(&at32_hmatrix_clk);36}3738/**39* hmatrix_read_reg - read HMATRIX configuration register40* @offset: register offset41*42* Returns the value of the register at @offset.43*/44u32 hmatrix_read_reg(unsigned long offset)45{46u32 value;4748clk_enable(&at32_hmatrix_clk);49value = __hmatrix_read_reg(offset);50clk_disable(&at32_hmatrix_clk);5152return value;53}5455/**56* hmatrix_sfr_set_bits - set bits in a slave's Special Function Register57* @slave_id: operate on the SFR belonging to this slave58* @mask: mask of bits to be set in the SFR59*/60void hmatrix_sfr_set_bits(unsigned int slave_id, u32 mask)61{62u32 value;6364clk_enable(&at32_hmatrix_clk);65value = __hmatrix_read_reg(HMATRIX_SFR(slave_id));66value |= mask;67__hmatrix_write_reg(HMATRIX_SFR(slave_id), value);68__hmatrix_read_reg(HMATRIX_SFR(slave_id));69clk_disable(&at32_hmatrix_clk);70}7172/**73* hmatrix_sfr_set_bits - clear bits in a slave's Special Function Register74* @slave_id: operate on the SFR belonging to this slave75* @mask: mask of bits to be cleared in the SFR76*/77void hmatrix_sfr_clear_bits(unsigned int slave_id, u32 mask)78{79u32 value;8081clk_enable(&at32_hmatrix_clk);82value = __hmatrix_read_reg(HMATRIX_SFR(slave_id));83value &= ~mask;84__hmatrix_write_reg(HMATRIX_SFR(slave_id), value);85__hmatrix_read_reg(HMATRIX_SFR(slave_id));86clk_disable(&at32_hmatrix_clk);87}888990