···11-/*22- * arch/arm/mach-at91/include/mach/at91sam9_smc.h33- *44- * Copyright (C) 2007 Andrew Victor55- * Copyright (C) 2007 Atmel Corporation.66- *77- * Static Memory Controllers (SMC) - System peripherals registers.88- * Based on AT91SAM9261 datasheet revision D.99- *1010- * This program is free software; you can redistribute it and/or modify1111- * it under the terms of the GNU General Public License as published by1212- * the Free Software Foundation; either version 2 of the License, or1313- * (at your option) any later version.1414- */1515-1616-#ifndef AT91SAM9_SMC_H1717-#define AT91SAM9_SMC_H1818-1919-#ifndef __ASSEMBLY__2020-struct sam9_smc_config {2121- /* Setup register */2222- u8 ncs_read_setup;2323- u8 nrd_setup;2424- u8 ncs_write_setup;2525- u8 nwe_setup;2626-2727- /* Pulse register */2828- u8 ncs_read_pulse;2929- u8 nrd_pulse;3030- u8 ncs_write_pulse;3131- u8 nwe_pulse;3232-3333- /* Cycle register */3434- u16 read_cycle;3535- u16 write_cycle;3636-3737- /* Mode register */3838- u32 mode;3939- u8 tdf_cycles:4;4040-};4141-4242-extern void sam9_smc_configure(int id, int cs, struct sam9_smc_config *config);4343-extern void sam9_smc_read(int id, int cs, struct sam9_smc_config *config);4444-extern void sam9_smc_read_mode(int id, int cs, struct sam9_smc_config *config);4545-extern void sam9_smc_write_mode(int id, int cs, struct sam9_smc_config *config);4646-#endif4747-4848-#define AT91_SMC_SETUP 0x00 /* Setup Register for CS n */4949-#define AT91_SMC_NWESETUP (0x3f << 0) /* NWE Setup Length */5050-#define AT91_SMC_NWESETUP_(x) ((x) << 0)5151-#define AT91_SMC_NCS_WRSETUP (0x3f << 8) /* NCS Setup Length in Write Access */5252-#define AT91_SMC_NCS_WRSETUP_(x) ((x) << 8)5353-#define AT91_SMC_NRDSETUP (0x3f << 16) /* NRD Setup Length */5454-#define AT91_SMC_NRDSETUP_(x) ((x) << 16)5555-#define AT91_SMC_NCS_RDSETUP (0x3f << 24) /* NCS Setup Length in Read Access */5656-#define AT91_SMC_NCS_RDSETUP_(x) ((x) << 24)5757-5858-#define AT91_SMC_PULSE 0x04 /* Pulse Register for CS n */5959-#define AT91_SMC_NWEPULSE (0x7f << 0) /* NWE Pulse Length */6060-#define AT91_SMC_NWEPULSE_(x) ((x) << 0)6161-#define AT91_SMC_NCS_WRPULSE (0x7f << 8) /* NCS Pulse Length in Write Access */6262-#define AT91_SMC_NCS_WRPULSE_(x)((x) << 8)6363-#define AT91_SMC_NRDPULSE (0x7f << 16) /* NRD Pulse Length */6464-#define AT91_SMC_NRDPULSE_(x) ((x) << 16)6565-#define AT91_SMC_NCS_RDPULSE (0x7f << 24) /* NCS Pulse Length in Read Access */6666-#define AT91_SMC_NCS_RDPULSE_(x)((x) << 24)6767-6868-#define AT91_SMC_CYCLE 0x08 /* Cycle Register for CS n */6969-#define AT91_SMC_NWECYCLE (0x1ff << 0 ) /* Total Write Cycle Length */7070-#define AT91_SMC_NWECYCLE_(x) ((x) << 0)7171-#define AT91_SMC_NRDCYCLE (0x1ff << 16) /* Total Read Cycle Length */7272-#define AT91_SMC_NRDCYCLE_(x) ((x) << 16)7373-7474-#define AT91_SMC_MODE 0x0c /* Mode Register for CS n */7575-#define AT91_SMC_READMODE (1 << 0) /* Read Mode */7676-#define AT91_SMC_WRITEMODE (1 << 1) /* Write Mode */7777-#define AT91_SMC_EXNWMODE (3 << 4) /* NWAIT Mode */7878-#define AT91_SMC_EXNWMODE_DISABLE (0 << 4)7979-#define AT91_SMC_EXNWMODE_FROZEN (2 << 4)8080-#define AT91_SMC_EXNWMODE_READY (3 << 4)8181-#define AT91_SMC_BAT (1 << 8) /* Byte Access Type */8282-#define AT91_SMC_BAT_SELECT (0 << 8)8383-#define AT91_SMC_BAT_WRITE (1 << 8)8484-#define AT91_SMC_DBW (3 << 12) /* Data Bus Width */8585-#define AT91_SMC_DBW_8 (0 << 12)8686-#define AT91_SMC_DBW_16 (1 << 12)8787-#define AT91_SMC_DBW_32 (2 << 12)8888-#define AT91_SMC_TDF (0xf << 16) /* Data Float Time. */8989-#define AT91_SMC_TDF_(x) ((x) << 16)9090-#define AT91_SMC_TDFMODE (1 << 20) /* TDF Optimization - Enabled */9191-#define AT91_SMC_PMEN (1 << 24) /* Page Mode Enabled */9292-#define AT91_SMC_PS (3 << 28) /* Page Size */9393-#define AT91_SMC_PS_4 (0 << 28)9494-#define AT91_SMC_PS_8 (1 << 28)9595-#define AT91_SMC_PS_16 (2 << 28)9696-#define AT91_SMC_PS_32 (3 << 28)9797-9898-#endif
-136
arch/arm/mach-at91/sam9_smc.c
···11-/*22- * linux/arch/arm/mach-at91/sam9_smc.c33- *44- * Copyright (C) 2008 Andrew Victor55- * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>66- *77- * This program is free software; you can redistribute it and/or modify88- * it under the terms of the GNU General Public License version 2 as99- * published by the Free Software Foundation.1010- */1111-1212-#include <linux/module.h>1313-#include <linux/io.h>1414-#include <linux/of.h>1515-#include <linux/of_address.h>1616-1717-#include <mach/at91sam9_smc.h>1818-1919-#include "sam9_smc.h"2020-2121-2222-#define AT91_SMC_CS(id, n) (smc_base_addr[id] + ((n) * 0x10))2323-2424-static void __iomem *smc_base_addr[2];2525-2626-static void sam9_smc_cs_write_mode(void __iomem *base,2727- struct sam9_smc_config *config)2828-{2929- __raw_writel(config->mode3030- | AT91_SMC_TDF_(config->tdf_cycles),3131- base + AT91_SMC_MODE);3232-}3333-3434-void sam9_smc_write_mode(int id, int cs,3535- struct sam9_smc_config *config)3636-{3737- sam9_smc_cs_write_mode(AT91_SMC_CS(id, cs), config);3838-}3939-EXPORT_SYMBOL_GPL(sam9_smc_write_mode);4040-4141-static void sam9_smc_cs_configure(void __iomem *base,4242- struct sam9_smc_config *config)4343-{4444-4545- /* Setup register */4646- __raw_writel(AT91_SMC_NWESETUP_(config->nwe_setup)4747- | AT91_SMC_NCS_WRSETUP_(config->ncs_write_setup)4848- | AT91_SMC_NRDSETUP_(config->nrd_setup)4949- | AT91_SMC_NCS_RDSETUP_(config->ncs_read_setup),5050- base + AT91_SMC_SETUP);5151-5252- /* Pulse register */5353- __raw_writel(AT91_SMC_NWEPULSE_(config->nwe_pulse)5454- | AT91_SMC_NCS_WRPULSE_(config->ncs_write_pulse)5555- | AT91_SMC_NRDPULSE_(config->nrd_pulse)5656- | AT91_SMC_NCS_RDPULSE_(config->ncs_read_pulse),5757- base + AT91_SMC_PULSE);5858-5959- /* Cycle register */6060- __raw_writel(AT91_SMC_NWECYCLE_(config->write_cycle)6161- | AT91_SMC_NRDCYCLE_(config->read_cycle),6262- base + AT91_SMC_CYCLE);6363-6464- /* Mode register */6565- sam9_smc_cs_write_mode(base, config);6666-}6767-6868-void sam9_smc_configure(int id, int cs,6969- struct sam9_smc_config *config)7070-{7171- sam9_smc_cs_configure(AT91_SMC_CS(id, cs), config);7272-}7373-EXPORT_SYMBOL_GPL(sam9_smc_configure);7474-7575-static void sam9_smc_cs_read_mode(void __iomem *base,7676- struct sam9_smc_config *config)7777-{7878- u32 val = __raw_readl(base + AT91_SMC_MODE);7979-8080- config->mode = (val & ~AT91_SMC_NWECYCLE);8181- config->tdf_cycles = (val & AT91_SMC_NWECYCLE) >> 16 ;8282-}8383-8484-void sam9_smc_read_mode(int id, int cs,8585- struct sam9_smc_config *config)8686-{8787- sam9_smc_cs_read_mode(AT91_SMC_CS(id, cs), config);8888-}8989-EXPORT_SYMBOL_GPL(sam9_smc_read_mode);9090-9191-static void sam9_smc_cs_read(void __iomem *base,9292- struct sam9_smc_config *config)9393-{9494- u32 val;9595-9696- /* Setup register */9797- val = __raw_readl(base + AT91_SMC_SETUP);9898-9999- config->nwe_setup = val & AT91_SMC_NWESETUP;100100- config->ncs_write_setup = (val & AT91_SMC_NCS_WRSETUP) >> 8;101101- config->nrd_setup = (val & AT91_SMC_NRDSETUP) >> 16;102102- config->ncs_read_setup = (val & AT91_SMC_NCS_RDSETUP) >> 24;103103-104104- /* Pulse register */105105- val = __raw_readl(base + AT91_SMC_PULSE);106106-107107- config->nwe_pulse = val & AT91_SMC_NWEPULSE;108108- config->ncs_write_pulse = (val & AT91_SMC_NCS_WRPULSE) >> 8;109109- config->nrd_pulse = (val & AT91_SMC_NRDPULSE) >> 16;110110- config->ncs_read_pulse = (val & AT91_SMC_NCS_RDPULSE) >> 24;111111-112112- /* Cycle register */113113- val = __raw_readl(base + AT91_SMC_CYCLE);114114-115115- config->write_cycle = val & AT91_SMC_NWECYCLE;116116- config->read_cycle = (val & AT91_SMC_NRDCYCLE) >> 16;117117-118118- /* Mode register */119119- sam9_smc_cs_read_mode(base, config);120120-}121121-122122-void sam9_smc_read(int id, int cs, struct sam9_smc_config *config)123123-{124124- sam9_smc_cs_read(AT91_SMC_CS(id, cs), config);125125-}126126-127127-void __init at91sam9_ioremap_smc(int id, u32 addr)128128-{129129- if (id > 1) {130130- pr_warn("%s: id > 2\n", __func__);131131- return;132132- }133133- smc_base_addr[id] = ioremap(addr, 512);134134- if (!smc_base_addr[id])135135- pr_warn("Impossible to ioremap smc.%d 0x%x\n", id, addr);136136-}
-11
arch/arm/mach-at91/sam9_smc.h
···11-/*22- * linux/arch/arm/mach-at91/sam9_smc.33- *44- * Copyright (C) 2008 Andrew Victor55- *66- * This program is free software; you can redistribute it and/or modify77- * it under the terms of the GNU General Public License version 2 as88- * published by the Free Software Foundation.99- */1010-1111-extern void __init at91sam9_ioremap_smc(int id, u32 addr);