Skip to content

Commit

Permalink
avr32: Clean up HMATRIX code
Browse files Browse the repository at this point in the history
Introduce a few helper functions for HMATRIX configuration and clean up
the register definitions. Also add definitions for the HMATRIX master
and slave IDs on the AT32AP700x chips.

Also make the definitions in hmatrix.h available to board code by moving
it to <mach/hmatrix.h>

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
  • Loading branch information
Haavard Skinnemoen committed Aug 8, 2008
1 parent a8d902d commit b47eb40
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 201 deletions.
1 change: 1 addition & 0 deletions arch/avr32/mach-at32ap/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
obj-y += pdc.o clock.o intc.o extint.o pio.o hsmc.o
obj-y += hmatrix.o
obj-$(CONFIG_CPU_AT32AP700X) += at32ap700x.o pm-at32ap700x.o
obj-$(CONFIG_CPU_FREQ_AT32AP) += cpufreq.o
obj-$(CONFIG_PM) += pm.o
Expand Down
26 changes: 7 additions & 19 deletions arch/avr32/mach-at32ap/at32ap700x.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

#include <mach/at32ap700x.h>
#include <mach/board.h>
#include <mach/hmatrix.h>
#include <mach/portmux.h>
#include <mach/sram.h>

#include <video/atmel_lcdc.h>

#include "clock.h"
#include "hmatrix.h"
#include "pio.h"
#include "pm.h"

Expand Down Expand Up @@ -725,20 +725,14 @@ static struct clk pico_clk = {
* HMATRIX
* -------------------------------------------------------------------- */

static struct clk hmatrix_clk = {
struct clk at32_hmatrix_clk = {
.name = "hmatrix_clk",
.parent = &pbb_clk,
.mode = pbb_clk_mode,
.get_rate = pbb_clk_get_rate,
.index = 2,
.users = 1,
};
#define HMATRIX_BASE ((void __iomem *)0xfff00800)

#define hmatrix_readl(reg) \
__raw_readl((HMATRIX_BASE) + HMATRIX_##reg)
#define hmatrix_writel(reg,value) \
__raw_writel((value), (HMATRIX_BASE) + HMATRIX_##reg)

/*
* Set bits in the HMATRIX Special Function Register (SFR) used by the
Expand All @@ -748,13 +742,7 @@ static struct clk hmatrix_clk = {
*/
static inline void set_ebi_sfr_bits(u32 mask)
{
u32 sfr;

clk_enable(&hmatrix_clk);
sfr = hmatrix_readl(SFR4);
sfr |= mask;
hmatrix_writel(SFR4, sfr);
clk_disable(&hmatrix_clk);
hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, mask);
}

/* --------------------------------------------------------------------
Expand Down Expand Up @@ -1779,7 +1767,7 @@ static int __init at32_init_ide_or_cf(struct platform_device *pdev,
return ret;

select_peripheral(PE(21), PERIPH_A, 0); /* NCS4 -> OE_N */
set_ebi_sfr_bits(HMATRIX_BIT(CS4A));
hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF0_ENABLE);
break;
case 5:
ret = platform_device_add_resources(pdev,
Expand All @@ -1789,7 +1777,7 @@ static int __init at32_init_ide_or_cf(struct platform_device *pdev,
return ret;

select_peripheral(PE(22), PERIPH_A, 0); /* NCS5 -> OE_N */
set_ebi_sfr_bits(HMATRIX_BIT(CS5A));
hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_CF1_ENABLE);
break;
default:
return -EINVAL;
Expand Down Expand Up @@ -1905,7 +1893,7 @@ at32_add_device_nand(unsigned int id, struct atmel_nand_data *data)
sizeof(struct atmel_nand_data)))
goto fail;

set_ebi_sfr_bits(HMATRIX_BIT(CS3A));
hmatrix_sfr_set_bits(HMATRIX_SLAVE_EBI, HMATRIX_EBI_NAND_ENABLE);
if (data->enable_pin)
at32_select_gpio(data->enable_pin,
AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
Expand Down Expand Up @@ -2097,7 +2085,7 @@ struct clk *at32_clock_list[] = {
&pbb_clk,
&at32_pm_pclk,
&at32_intc0_pclk,
&hmatrix_clk,
&at32_hmatrix_clk,
&ebi_clk,
&hramc_clk,
&sdramc_clk,
Expand Down
88 changes: 88 additions & 0 deletions arch/avr32/mach-at32ap/hmatrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* High-Speed Bus Matrix helper functions
*
* Copyright (C) 2008 Atmel Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/clk.h>
#include <linux/io.h>

#include <mach/chip.h>
#include <mach/hmatrix.h>

static inline void __hmatrix_write_reg(unsigned long offset, u32 value)
{
__raw_writel(value, (void __iomem __force *)(HMATRIX_BASE + offset));
}

static inline u32 __hmatrix_read_reg(unsigned long offset)
{
return __raw_readl((void __iomem __force *)(HMATRIX_BASE + offset));
}

/**
* hmatrix_write_reg - write HMATRIX configuration register
* @offset: register offset
* @value: value to be written to the register at @offset
*/
void hmatrix_write_reg(unsigned long offset, u32 value)
{
clk_enable(&at32_hmatrix_clk);
__hmatrix_write_reg(offset, value);
__hmatrix_read_reg(offset);
clk_disable(&at32_hmatrix_clk);
}

/**
* hmatrix_read_reg - read HMATRIX configuration register
* @offset: register offset
*
* Returns the value of the register at @offset.
*/
u32 hmatrix_read_reg(unsigned long offset)
{
u32 value;

clk_enable(&at32_hmatrix_clk);
value = __hmatrix_read_reg(offset);
clk_disable(&at32_hmatrix_clk);

return value;
}

/**
* hmatrix_sfr_set_bits - set bits in a slave's Special Function Register
* @slave_id: operate on the SFR belonging to this slave
* @mask: mask of bits to be set in the SFR
*/
void hmatrix_sfr_set_bits(unsigned int slave_id, u32 mask)
{
u32 value;

clk_enable(&at32_hmatrix_clk);
value = __hmatrix_read_reg(HMATRIX_SFR(slave_id));
value |= mask;
__hmatrix_write_reg(HMATRIX_SFR(slave_id), value);
__hmatrix_read_reg(HMATRIX_SFR(slave_id));
clk_disable(&at32_hmatrix_clk);
}

/**
* hmatrix_sfr_set_bits - clear bits in a slave's Special Function Register
* @slave_id: operate on the SFR belonging to this slave
* @mask: mask of bits to be cleared in the SFR
*/
void hmatrix_sfr_clear_bits(unsigned int slave_id, u32 mask)
{
u32 value;

clk_enable(&at32_hmatrix_clk);
value = __hmatrix_read_reg(HMATRIX_SFR(slave_id));
value &= ~mask;
__hmatrix_write_reg(HMATRIX_SFR(slave_id), value);
__hmatrix_read_reg(HMATRIX_SFR(slave_id));
clk_disable(&at32_hmatrix_clk);
}
182 changes: 0 additions & 182 deletions arch/avr32/mach-at32ap/hmatrix.h

This file was deleted.

Loading

0 comments on commit b47eb40

Please sign in to comment.