aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2012-02-13 18:25:44 -0500
committerArnd Bergmann <arnd@arndb.de>2012-02-13 18:25:44 -0500
commita5368e770c9ec58b9d18378844c149df8513e7b8 (patch)
tree2dc0953afd7f54f3269486fc0edbb41cd9cf804e
parent88fa269bedc3ae0f67426ea7fe9d306103b7fb1c (diff)
parentcf844751fb25e095d8fa30332cb173a73e5a736c (diff)
Merge branch 'at91-fixes' of git://github.com/at91linux/linux-at91 into fixes
* 'at91-fixes' of git://github.com/at91linux/linux-at91: ARM: at91: drop ide driver in favor of the pata one pata/at91: use newly introduced SMC accessors ARM: at91: add accessor to manage SMC ARM: at91:rtc/rtc-at91sam9: ioremap register bank ARM: at91: USB AT91 gadget registration for module
-rw-r--r--arch/arm/mach-at91/at91rm9200_devices.c2
-rw-r--r--arch/arm/mach-at91/at91sam9260_devices.c9
-rw-r--r--arch/arm/mach-at91/at91sam9261_devices.c2
-rw-r--r--arch/arm/mach-at91/at91sam9263_devices.c8
-rw-r--r--arch/arm/mach-at91/include/mach/at91sam9_smc.h29
-rw-r--r--arch/arm/mach-at91/sam9_smc.c76
-rw-r--r--arch/arm/mach-at91/sam9_smc.h23
-rw-r--r--drivers/ata/pata_at91.c48
-rw-r--r--drivers/ide/Makefile1
-rw-r--r--drivers/ide/at91_ide.c366
-rw-r--r--drivers/rtc/rtc-at91sam9.c13
11 files changed, 140 insertions, 437 deletions
diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c
index 18bacec2b09..97676bdae99 100644
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ b/arch/arm/mach-at91/at91rm9200_devices.c
@@ -83,7 +83,7 @@ void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
83 * USB Device (Gadget) 83 * USB Device (Gadget)
84 * -------------------------------------------------------------------- */ 84 * -------------------------------------------------------------------- */
85 85
86#ifdef CONFIG_USB_AT91 86#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
87static struct at91_udc_data udc_data; 87static struct at91_udc_data udc_data;
88 88
89static struct resource udc_resources[] = { 89static struct resource udc_resources[] = {
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
index 642ccb6d26b..5a24f0b4554 100644
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/at91sam9260_devices.c
@@ -84,7 +84,7 @@ void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
84 * USB Device (Gadget) 84 * USB Device (Gadget)
85 * -------------------------------------------------------------------- */ 85 * -------------------------------------------------------------------- */
86 86
87#ifdef CONFIG_USB_AT91 87#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
88static struct at91_udc_data udc_data; 88static struct at91_udc_data udc_data;
89 89
90static struct resource udc_resources[] = { 90static struct resource udc_resources[] = {
@@ -1215,8 +1215,7 @@ void __init at91_add_device_serial(void) {}
1215 * CF/IDE 1215 * CF/IDE
1216 * -------------------------------------------------------------------- */ 1216 * -------------------------------------------------------------------- */
1217 1217
1218#if defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE) || \ 1218#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
1219 defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
1220 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE) 1219 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
1221 1220
1222static struct at91_cf_data cf0_data; 1221static struct at91_cf_data cf0_data;
@@ -1313,10 +1312,8 @@ void __init at91_add_device_cf(struct at91_cf_data *data)
1313 if (data->flags & AT91_CF_TRUE_IDE) 1312 if (data->flags & AT91_CF_TRUE_IDE)
1314#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) 1313#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
1315 pdev->name = "pata_at91"; 1314 pdev->name = "pata_at91";
1316#elif defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE)
1317 pdev->name = "at91_ide";
1318#else 1315#else
1319#warning "board requires AT91_CF_TRUE_IDE: enable either at91_ide or pata_at91" 1316#warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
1320#endif 1317#endif
1321 else 1318 else
1322 pdev->name = "at91_cf"; 1319 pdev->name = "at91_cf";
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c b/arch/arm/mach-at91/at91sam9261_devices.c
index fc59cbdb0e3..1e28bed8f42 100644
--- a/arch/arm/mach-at91/at91sam9261_devices.c
+++ b/arch/arm/mach-at91/at91sam9261_devices.c
@@ -87,7 +87,7 @@ void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
87 * USB Device (Gadget) 87 * USB Device (Gadget)
88 * -------------------------------------------------------------------- */ 88 * -------------------------------------------------------------------- */
89 89
90#ifdef CONFIG_USB_AT91 90#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
91static struct at91_udc_data udc_data; 91static struct at91_udc_data udc_data;
92 92
93static struct resource udc_resources[] = { 93static struct resource udc_resources[] = {
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c
index 7b46b278702..366a7765635 100644
--- a/arch/arm/mach-at91/at91sam9263_devices.c
+++ b/arch/arm/mach-at91/at91sam9263_devices.c
@@ -92,7 +92,7 @@ void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
92 * USB Device (Gadget) 92 * USB Device (Gadget)
93 * -------------------------------------------------------------------- */ 93 * -------------------------------------------------------------------- */
94 94
95#ifdef CONFIG_USB_AT91 95#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
96static struct at91_udc_data udc_data; 96static struct at91_udc_data udc_data;
97 97
98static struct resource udc_resources[] = { 98static struct resource udc_resources[] = {
@@ -355,8 +355,8 @@ void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
355 * Compact Flash (PCMCIA or IDE) 355 * Compact Flash (PCMCIA or IDE)
356 * -------------------------------------------------------------------- */ 356 * -------------------------------------------------------------------- */
357 357
358#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE) || \ 358#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
359 defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE) 359 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
360 360
361static struct at91_cf_data cf0_data; 361static struct at91_cf_data cf0_data;
362 362
@@ -450,7 +450,7 @@ void __init at91_add_device_cf(struct at91_cf_data *data)
450 at91_set_A_periph(AT91_PIN_PD9, 0); /* CFCE2 */ 450 at91_set_A_periph(AT91_PIN_PD9, 0); /* CFCE2 */
451 at91_set_A_periph(AT91_PIN_PD14, 0); /* CFNRW */ 451 at91_set_A_periph(AT91_PIN_PD14, 0); /* CFNRW */
452 452
453 pdev->name = (data->flags & AT91_CF_TRUE_IDE) ? "at91_ide" : "at91_cf"; 453 pdev->name = (data->flags & AT91_CF_TRUE_IDE) ? "pata_at91" : "at91_cf";
454 platform_device_register(pdev); 454 platform_device_register(pdev);
455} 455}
456#else 456#else
diff --git a/arch/arm/mach-at91/include/mach/at91sam9_smc.h b/arch/arm/mach-at91/include/mach/at91sam9_smc.h
index eb18a70fa64..175e1fdd9fe 100644
--- a/arch/arm/mach-at91/include/mach/at91sam9_smc.h
+++ b/arch/arm/mach-at91/include/mach/at91sam9_smc.h
@@ -18,6 +18,35 @@
18 18
19#include <mach/cpu.h> 19#include <mach/cpu.h>
20 20
21#ifndef __ASSEMBLY__
22struct sam9_smc_config {
23 /* Setup register */
24 u8 ncs_read_setup;
25 u8 nrd_setup;
26 u8 ncs_write_setup;
27 u8 nwe_setup;
28
29 /* Pulse register */
30 u8 ncs_read_pulse;
31 u8 nrd_pulse;
32 u8 ncs_write_pulse;
33 u8 nwe_pulse;
34
35 /* Cycle register */
36 u16 read_cycle;
37 u16 write_cycle;
38
39 /* Mode register */
40 u32 mode;
41 u8 tdf_cycles:4;
42};
43
44extern void sam9_smc_configure(int id, int cs, struct sam9_smc_config *config);
45extern void sam9_smc_read(int id, int cs, struct sam9_smc_config *config);
46extern void sam9_smc_read_mode(int id, int cs, struct sam9_smc_config *config);
47extern void sam9_smc_write_mode(int id, int cs, struct sam9_smc_config *config);
48#endif
49
21#define AT91_SMC_SETUP 0x00 /* Setup Register for CS n */ 50#define AT91_SMC_SETUP 0x00 /* Setup Register for CS n */
22#define AT91_SMC_NWESETUP (0x3f << 0) /* NWE Setup Length */ 51#define AT91_SMC_NWESETUP (0x3f << 0) /* NWE Setup Length */
23#define AT91_SMC_NWESETUP_(x) ((x) << 0) 52#define AT91_SMC_NWESETUP_(x) ((x) << 0)
diff --git a/arch/arm/mach-at91/sam9_smc.c b/arch/arm/mach-at91/sam9_smc.c
index 8294783b679..99a0a1d2b7d 100644
--- a/arch/arm/mach-at91/sam9_smc.c
+++ b/arch/arm/mach-at91/sam9_smc.c
@@ -2,6 +2,7 @@
2 * linux/arch/arm/mach-at91/sam9_smc.c 2 * linux/arch/arm/mach-at91/sam9_smc.c
3 * 3 *
4 * Copyright (C) 2008 Andrew Victor 4 * Copyright (C) 2008 Andrew Victor
5 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -22,7 +23,22 @@
22 23
23static void __iomem *smc_base_addr[2]; 24static void __iomem *smc_base_addr[2];
24 25
25static void __init sam9_smc_cs_configure(void __iomem *base, struct sam9_smc_config* config) 26static void sam9_smc_cs_write_mode(void __iomem *base,
27 struct sam9_smc_config *config)
28{
29 __raw_writel(config->mode
30 | AT91_SMC_TDF_(config->tdf_cycles),
31 base + AT91_SMC_MODE);
32}
33
34void sam9_smc_write_mode(int id, int cs,
35 struct sam9_smc_config *config)
36{
37 sam9_smc_cs_write_mode(AT91_SMC_CS(id, cs), config);
38}
39
40static void sam9_smc_cs_configure(void __iomem *base,
41 struct sam9_smc_config *config)
26{ 42{
27 43
28 /* Setup register */ 44 /* Setup register */
@@ -45,16 +61,66 @@ static void __init sam9_smc_cs_configure(void __iomem *base, struct sam9_smc_con
45 base + AT91_SMC_CYCLE); 61 base + AT91_SMC_CYCLE);
46 62
47 /* Mode register */ 63 /* Mode register */
48 __raw_writel(config->mode 64 sam9_smc_cs_write_mode(base, config);
49 | AT91_SMC_TDF_(config->tdf_cycles),
50 base + AT91_SMC_MODE);
51} 65}
52 66
53void __init sam9_smc_configure(int id, int cs, struct sam9_smc_config* config) 67void sam9_smc_configure(int id, int cs,
68 struct sam9_smc_config *config)
54{ 69{
55 sam9_smc_cs_configure(AT91_SMC_CS(id, cs), config); 70 sam9_smc_cs_configure(AT91_SMC_CS(id, cs), config);
56} 71}
57 72
73static void sam9_smc_cs_read_mode(void __iomem *base,
74 struct sam9_smc_config *config)
75{
76 u32 val = __raw_readl(base + AT91_SMC_MODE);
77
78 config->mode = (val & ~AT91_SMC_NWECYCLE);
79 config->tdf_cycles = (val & AT91_SMC_NWECYCLE) >> 16 ;
80}
81
82void sam9_smc_read_mode(int id, int cs,
83 struct sam9_smc_config *config)
84{
85 sam9_smc_cs_read_mode(AT91_SMC_CS(id, cs), config);
86}
87
88static void sam9_smc_cs_read(void __iomem *base,
89 struct sam9_smc_config *config)
90{
91 u32 val;
92
93 /* Setup register */
94 val = __raw_readl(base + AT91_SMC_SETUP);
95
96 config->nwe_setup = val & AT91_SMC_NWESETUP;
97 config->ncs_write_setup = (val & AT91_SMC_NCS_WRSETUP) >> 8;
98 config->nrd_setup = (val & AT91_SMC_NRDSETUP) >> 16;
99 config->ncs_read_setup = (val & AT91_SMC_NCS_RDSETUP) >> 24;
100
101 /* Pulse register */
102 val = __raw_readl(base + AT91_SMC_PULSE);
103
104 config->nwe_setup = val & AT91_SMC_NWEPULSE;
105 config->ncs_write_pulse = (val & AT91_SMC_NCS_WRPULSE) >> 8;
106 config->nrd_pulse = (val & AT91_SMC_NRDPULSE) >> 16;
107 config->ncs_read_pulse = (val & AT91_SMC_NCS_RDPULSE) >> 24;
108
109 /* Cycle register */
110 val = __raw_readl(base + AT91_SMC_CYCLE);
111
112 config->write_cycle = val & AT91_SMC_NWECYCLE;
113 config->read_cycle = (val & AT91_SMC_NRDCYCLE) >> 16;
114
115 /* Mode register */
116 sam9_smc_cs_read_mode(base, config);
117}
118
119void sam9_smc_read(int id, int cs, struct sam9_smc_config *config)
120{
121 sam9_smc_cs_read(AT91_SMC_CS(id, cs), config);
122}
123
58void __init at91sam9_ioremap_smc(int id, u32 addr) 124void __init at91sam9_ioremap_smc(int id, u32 addr)
59{ 125{
60 if (id > 1) { 126 if (id > 1) {
diff --git a/arch/arm/mach-at91/sam9_smc.h b/arch/arm/mach-at91/sam9_smc.h
index 039c5ce17ae..3e52dcd4a59 100644
--- a/arch/arm/mach-at91/sam9_smc.h
+++ b/arch/arm/mach-at91/sam9_smc.h
@@ -8,27 +8,4 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11struct sam9_smc_config {
12 /* Setup register */
13 u8 ncs_read_setup;
14 u8 nrd_setup;
15 u8 ncs_write_setup;
16 u8 nwe_setup;
17
18 /* Pulse register */
19 u8 ncs_read_pulse;
20 u8 nrd_pulse;
21 u8 ncs_write_pulse;
22 u8 nwe_pulse;
23
24 /* Cycle register */
25 u16 read_cycle;
26 u16 write_cycle;
27
28 /* Mode register */
29 u32 mode;
30 u8 tdf_cycles:4;
31};
32
33extern void __init sam9_smc_configure(int id, int cs, struct sam9_smc_config* config);
34extern void __init at91sam9_ioremap_smc(int id, u32 addr); 11extern void __init at91sam9_ioremap_smc(int id, u32 addr);
diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
index a7d91a72ee3..53d3770a0b1 100644
--- a/drivers/ata/pata_at91.c
+++ b/drivers/ata/pata_at91.c
@@ -207,11 +207,11 @@ static void set_smc_timing(struct device *dev, struct ata_device *adev,
207{ 207{
208 int ret = 0; 208 int ret = 0;
209 int use_iordy; 209 int use_iordy;
210 struct sam9_smc_config smc;
210 unsigned int t6z; /* data tristate time in ns */ 211 unsigned int t6z; /* data tristate time in ns */
211 unsigned int cycle; /* SMC Cycle width in MCK ticks */ 212 unsigned int cycle; /* SMC Cycle width in MCK ticks */
212 unsigned int setup; /* SMC Setup width in MCK ticks */ 213 unsigned int setup; /* SMC Setup width in MCK ticks */
213 unsigned int pulse; /* CFIOR and CFIOW pulse width in MCK ticks */ 214 unsigned int pulse; /* CFIOR and CFIOW pulse width in MCK ticks */
214 unsigned int cs_setup = 0;/* CS4 or CS5 setup width in MCK ticks */
215 unsigned int cs_pulse; /* CS4 or CS5 pulse width in MCK ticks*/ 215 unsigned int cs_pulse; /* CS4 or CS5 pulse width in MCK ticks*/
216 unsigned int tdf_cycles; /* SMC TDF MCK ticks */ 216 unsigned int tdf_cycles; /* SMC TDF MCK ticks */
217 unsigned long mck_hz; /* MCK frequency in Hz */ 217 unsigned long mck_hz; /* MCK frequency in Hz */
@@ -244,26 +244,20 @@ static void set_smc_timing(struct device *dev, struct ata_device *adev,
244 } 244 }
245 245
246 dev_dbg(dev, "Use IORDY=%u, TDF Cycles=%u\n", use_iordy, tdf_cycles); 246 dev_dbg(dev, "Use IORDY=%u, TDF Cycles=%u\n", use_iordy, tdf_cycles);
247 info->mode |= AT91_SMC_TDF_(tdf_cycles); 247
248 248 /* SMC Setup Register */
249 /* write SMC Setup Register */ 249 smc.nwe_setup = smc.nrd_setup = setup;
250 at91_sys_write(AT91_SMC_SETUP(info->cs), 250 smc.ncs_write_setup = smc.ncs_read_setup = 0;
251 AT91_SMC_NWESETUP_(setup) | 251 /* SMC Pulse Register */
252 AT91_SMC_NRDSETUP_(setup) | 252 smc.nwe_pulse = smc.nrd_pulse = pulse;
253 AT91_SMC_NCS_WRSETUP_(cs_setup) | 253 smc.ncs_write_pulse = smc.ncs_read_pulse = cs_pulse;
254 AT91_SMC_NCS_RDSETUP_(cs_setup)); 254 /* SMC Cycle Register */
255 /* write SMC Pulse Register */ 255 smc.write_cycle = smc.read_cycle = cycle;
256 at91_sys_write(AT91_SMC_PULSE(info->cs), 256 /* SMC Mode Register*/
257 AT91_SMC_NWEPULSE_(pulse) | 257 smc.tdf_cycles = tdf_cycles;
258 AT91_SMC_NRDPULSE_(pulse) | 258 smc.mode = info->mode;
259 AT91_SMC_NCS_WRPULSE_(cs_pulse) | 259
260 AT91_SMC_NCS_RDPULSE_(cs_pulse)); 260 sam9_smc_configure(0, info->cs, &smc);
261 /* write SMC Cycle Register */
262 at91_sys_write(AT91_SMC_CYCLE(info->cs),
263 AT91_SMC_NWECYCLE_(cycle) |
264 AT91_SMC_NRDCYCLE_(cycle));
265 /* write SMC Mode Register*/
266 at91_sys_write(AT91_SMC_MODE(info->cs), info->mode);
267} 261}
268 262
269static void pata_at91_set_piomode(struct ata_port *ap, struct ata_device *adev) 263static void pata_at91_set_piomode(struct ata_port *ap, struct ata_device *adev)
@@ -288,20 +282,20 @@ static unsigned int pata_at91_data_xfer_noirq(struct ata_device *dev,
288 struct at91_ide_info *info = dev->link->ap->host->private_data; 282 struct at91_ide_info *info = dev->link->ap->host->private_data;
289 unsigned int consumed; 283 unsigned int consumed;
290 unsigned long flags; 284 unsigned long flags;
291 unsigned int mode; 285 struct sam9_smc_config smc;
292 286
293 local_irq_save(flags); 287 local_irq_save(flags);
294 mode = at91_sys_read(AT91_SMC_MODE(info->cs)); 288 sam9_smc_read_mode(0, info->cs, &smc);
295 289
296 /* set 16bit mode before writing data */ 290 /* set 16bit mode before writing data */
297 at91_sys_write(AT91_SMC_MODE(info->cs), 291 smc.mode = (smc.mode & ~AT91_SMC_DBW) | AT91_SMC_DBW_16;
298 (mode & ~AT91_SMC_DBW) | AT91_SMC_DBW_16); 292 sam9_smc_write_mode(0, info->cs, &smc);
299 293
300 consumed = ata_sff_data_xfer(dev, buf, buflen, rw); 294 consumed = ata_sff_data_xfer(dev, buf, buflen, rw);
301 295
302 /* restore 8bit mode after data is written */ 296 /* restore 8bit mode after data is written */
303 at91_sys_write(AT91_SMC_MODE(info->cs), 297 smc.mode = (smc.mode & ~AT91_SMC_DBW) | AT91_SMC_DBW_8;
304 (mode & ~AT91_SMC_DBW) | AT91_SMC_DBW_8); 298 sam9_smc_write_mode(0, info->cs, &smc);
305 299
306 local_irq_restore(flags); 300 local_irq_restore(flags);
307 return consumed; 301 return consumed;
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 7f879b2397b..af8d016c37e 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -116,4 +116,3 @@ obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o
116 116
117obj-$(CONFIG_BLK_DEV_IDE_TX4938) += tx4938ide.o 117obj-$(CONFIG_BLK_DEV_IDE_TX4938) += tx4938ide.o
118obj-$(CONFIG_BLK_DEV_IDE_TX4939) += tx4939ide.o 118obj-$(CONFIG_BLK_DEV_IDE_TX4939) += tx4939ide.o
119obj-$(CONFIG_BLK_DEV_IDE_AT91) += at91_ide.o
diff --git a/drivers/ide/at91_ide.c b/drivers/ide/at91_ide.c
deleted file mode 100644
index 41d41552947..00000000000
--- a/drivers/ide/at91_ide.c
+++ /dev/null
@@ -1,366 +0,0 @@
1/*
2 * IDE host driver for AT91 (SAM9, CAP9, AT572D940HF) Static Memory Controller
3 * with Compact Flash True IDE logic
4 *
5 * Copyright (c) 2008, 2009 Kelvatek Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/clk.h>
26#include <linux/err.h>
27#include <linux/ide.h>
28#include <linux/platform_device.h>
29
30#include <mach/board.h>
31#include <asm/gpio.h>
32#include <mach/at91sam9_smc.h>
33
34#define DRV_NAME "at91_ide"
35
36#define perr(fmt, args...) pr_err(DRV_NAME ": " fmt, ##args)
37#define pdbg(fmt, args...) pr_debug("%s " fmt, __func__, ##args)
38
39/*
40 * Access to IDE device is possible through EBI Static Memory Controller
41 * with Compact Flash logic. For details see EBI and SMC datasheet sections
42 * of any microcontroller from AT91SAM9 family.
43 *
44 * Within SMC chip select address space, lines A[23:21] distinguish Compact
45 * Flash modes (I/O, common memory, attribute memory, True IDE). IDE modes are:
46 * 0x00c0000 - True IDE
47 * 0x00e0000 - Alternate True IDE (Alt Status Register)
48 *
49 * On True IDE mode Task File and Data Register are mapped at the same address.
50 * To distinguish access between these two different bus data width is used:
51 * 8Bit for Task File, 16Bit for Data I/O.
52 *
53 * After initialization we do 8/16 bit flipping (changes in SMC MODE register)
54 * only inside IDE callback routines which are serialized by IDE layer,
55 * so no additional locking needed.
56 */
57
58#define TASK_FILE 0x00c00000
59#define ALT_MODE 0x00e00000
60#define REGS_SIZE 8
61
62#define enter_16bit(cs, mode) do { \
63 mode = at91_sys_read(AT91_SMC_MODE(cs)); \
64 at91_sys_write(AT91_SMC_MODE(cs), mode | AT91_SMC_DBW_16); \
65} while (0)
66
67#define leave_16bit(cs, mode) at91_sys_write(AT91_SMC_MODE(cs), mode);
68
69static void set_smc_timings(const u8 chipselect, const u16 cycle,
70 const u16 setup, const u16 pulse,
71 const u16 data_float, int use_iordy)
72{
73 unsigned long mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
74 AT91_SMC_BAT_SELECT;
75
76 /* disable or enable waiting for IORDY signal */
77 if (use_iordy)
78 mode |= AT91_SMC_EXNWMODE_READY;
79
80 /* add data float cycles if needed */
81 if (data_float)
82 mode |= AT91_SMC_TDF_(data_float);
83
84 at91_sys_write(AT91_SMC_MODE(chipselect), mode);
85
86 /* setup timings in SMC */
87 at91_sys_write(AT91_SMC_SETUP(chipselect), AT91_SMC_NWESETUP_(setup) |
88 AT91_SMC_NCS_WRSETUP_(0) |
89 AT91_SMC_NRDSETUP_(setup) |
90 AT91_SMC_NCS_RDSETUP_(0));
91 at91_sys_write(AT91_SMC_PULSE(chipselect), AT91_SMC_NWEPULSE_(pulse) |
92 AT91_SMC_NCS_WRPULSE_(cycle) |
93 AT91_SMC_NRDPULSE_(pulse) |
94 AT91_SMC_NCS_RDPULSE_(cycle));
95 at91_sys_write(AT91_SMC_CYCLE(chipselect), AT91_SMC_NWECYCLE_(cycle) |
96 AT91_SMC_NRDCYCLE_(cycle));
97}
98
99static unsigned int calc_mck_cycles(unsigned int ns, unsigned int mck_hz)
100{
101 u64 tmp = ns;
102
103 tmp *= mck_hz;
104 tmp += 1000*1000*1000 - 1; /* round up */
105 do_div(tmp, 1000*1000*1000);
106 return (unsigned int) tmp;
107}
108
109static void apply_timings(const u8 chipselect, const u8 pio,
110 const struct ide_timing *timing, int use_iordy)
111{
112 unsigned int t0, t1, t2, t6z;
113 unsigned int cycle, setup, pulse, data_float;
114 unsigned int mck_hz;
115 struct clk *mck;
116
117 /* see table 22 of Compact Flash standard 4.1 for the meaning,
118 * we do not stretch active (t2) time, so setup (t1) + hold time (th)
119 * assure at least minimal recovery (t2i) time */
120 t0 = timing->cyc8b;
121 t1 = timing->setup;
122 t2 = timing->act8b;
123 t6z = (pio < 5) ? 30 : 20;
124
125 pdbg("t0=%u t1=%u t2=%u t6z=%u\n", t0, t1, t2, t6z);
126
127 mck = clk_get(NULL, "mck");
128 BUG_ON(IS_ERR(mck));
129 mck_hz = clk_get_rate(mck);
130 pdbg("mck_hz=%u\n", mck_hz);
131
132 cycle = calc_mck_cycles(t0, mck_hz);
133 setup = calc_mck_cycles(t1, mck_hz);
134 pulse = calc_mck_cycles(t2, mck_hz);
135 data_float = calc_mck_cycles(t6z, mck_hz);
136
137 pdbg("cycle=%u setup=%u pulse=%u data_float=%u\n",
138 cycle, setup, pulse, data_float);
139
140 set_smc_timings(chipselect, cycle, setup, pulse, data_float, use_iordy);
141}
142
143static void at91_ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
144 void *buf, unsigned int len)
145{
146 ide_hwif_t *hwif = drive->hwif;
147 struct ide_io_ports *io_ports = &hwif->io_ports;
148 u8 chipselect = hwif->select_data;
149 unsigned long mode;
150
151 pdbg("cs %u buf %p len %d\n", chipselect, buf, len);
152
153 len++;
154
155 enter_16bit(chipselect, mode);
156 readsw((void __iomem *)io_ports->data_addr, buf, len / 2);
157 leave_16bit(chipselect, mode);
158}
159
160static void at91_ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
161 void *buf, unsigned int len)
162{
163 ide_hwif_t *hwif = drive->hwif;
164 struct ide_io_ports *io_ports = &hwif->io_ports;
165 u8 chipselect = hwif->select_data;
166 unsigned long mode;
167
168 pdbg("cs %u buf %p len %d\n", chipselect, buf, len);
169
170 enter_16bit(chipselect, mode);
171 writesw((void __iomem *)io_ports->data_addr, buf, len / 2);
172 leave_16bit(chipselect, mode);
173}
174
175static void at91_ide_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
176{
177 struct ide_timing *timing;
178 u8 chipselect = hwif->select_data;
179 int use_iordy = 0;
180 const u8 pio = drive->pio_mode - XFER_PIO_0;
181
182 pdbg("chipselect %u pio %u\n", chipselect, pio);
183
184 timing = ide_timing_find_mode(XFER_PIO_0 + pio);
185 BUG_ON(!timing);
186
187 if (ide_pio_need_iordy(drive, pio))
188 use_iordy = 1;
189
190 apply_timings(chipselect, pio, timing, use_iordy);
191}
192
193static const struct ide_tp_ops at91_ide_tp_ops = {
194 .exec_command = ide_exec_command,
195 .read_status = ide_read_status,
196 .read_altstatus = ide_read_altstatus,
197 .write_devctl = ide_write_devctl,
198
199 .dev_select = ide_dev_select,
200 .tf_load = ide_tf_load,
201 .tf_read = ide_tf_read,
202
203 .input_data = at91_ide_input_data,
204 .output_data = at91_ide_output_data,
205};
206
207static const struct ide_port_ops at91_ide_port_ops = {
208 .set_pio_mode = at91_ide_set_pio_mode,
209};
210
211static const struct ide_port_info at91_ide_port_info __initdata = {
212 .port_ops = &at91_ide_port_ops,
213 .tp_ops = &at91_ide_tp_ops,
214 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA | IDE_HFLAG_SINGLE |
215 IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_UNMASK_IRQS,
216 .pio_mask = ATA_PIO6,
217 .chipset = ide_generic,
218};
219
220/*
221 * If interrupt is delivered through GPIO, IRQ are triggered on falling
222 * and rising edge of signal. Whereas IDE device request interrupt on high
223 * level (rising edge in our case). This mean we have fake interrupts, so
224 * we need to check interrupt pin and exit instantly from ISR when line
225 * is on low level.
226 */
227
228irqreturn_t at91_irq_handler(int irq, void *dev_id)
229{
230 int ntries = 8;
231 int pin_val1, pin_val2;
232
233 /* additional deglitch, line can be noisy in badly designed PCB */
234 do {
235 pin_val1 = at91_get_gpio_value(irq);
236 pin_val2 = at91_get_gpio_value(irq);
237 } while (pin_val1 != pin_val2 && --ntries > 0);
238
239 if (pin_val1 == 0 || ntries <= 0)
240 return IRQ_HANDLED;
241
242 return ide_intr(irq, dev_id);
243}
244
245static int __init at91_ide_probe(struct platform_device *pdev)
246{
247 int ret;
248 struct ide_hw hw, *hws[] = { &hw };
249 struct ide_host *host;
250 struct resource *res;
251 unsigned long tf_base = 0, ctl_base = 0;
252 struct at91_cf_data *board = pdev->dev.platform_data;
253
254 if (!board)
255 return -ENODEV;
256
257 if (board->det_pin && at91_get_gpio_value(board->det_pin) != 0) {
258 perr("no device detected\n");
259 return -ENODEV;
260 }
261
262 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
263 if (!res) {
264 perr("can't get memory resource\n");
265 return -ENODEV;
266 }
267
268 if (!devm_request_mem_region(&pdev->dev, res->start + TASK_FILE,
269 REGS_SIZE, "ide") ||
270 !devm_request_mem_region(&pdev->dev, res->start + ALT_MODE,
271 REGS_SIZE, "alt")) {
272 perr("memory resources in use\n");
273 return -EBUSY;
274 }
275
276 pdbg("chipselect %u irq %u res %08lx\n", board->chipselect,
277 board->irq_pin, (unsigned long) res->start);
278
279 tf_base = (unsigned long) devm_ioremap(&pdev->dev, res->start + TASK_FILE,
280 REGS_SIZE);
281 ctl_base = (unsigned long) devm_ioremap(&pdev->dev, res->start + ALT_MODE,
282 REGS_SIZE);
283 if (!tf_base || !ctl_base) {
284 perr("can't map memory regions\n");
285 return -EBUSY;
286 }
287
288 memset(&hw, 0, sizeof(hw));
289
290 if (board->flags & AT91_IDE_SWAP_A0_A2) {
291 /* workaround for stupid hardware bug */
292 hw.io_ports.data_addr = tf_base + 0;
293 hw.io_ports.error_addr = tf_base + 4;
294 hw.io_ports.nsect_addr = tf_base + 2;
295 hw.io_ports.lbal_addr = tf_base + 6;
296 hw.io_ports.lbam_addr = tf_base + 1;
297 hw.io_ports.lbah_addr = tf_base + 5;
298 hw.io_ports.device_addr = tf_base + 3;
299 hw.io_ports.command_addr = tf_base + 7;
300 hw.io_ports.ctl_addr = ctl_base + 3;
301 } else
302 ide_std_init_ports(&hw, tf_base, ctl_base + 6);
303
304 hw.irq = board->irq_pin;
305 hw.dev = &pdev->dev;
306
307 host = ide_host_alloc(&at91_ide_port_info, hws, 1);
308 if (!host) {
309 perr("failed to allocate ide host\n");
310 return -ENOMEM;
311 }
312
313 /* setup Static Memory Controller - PIO 0 as default */
314 apply_timings(board->chipselect, 0, ide_timing_find_mode(XFER_PIO_0), 0);
315
316 /* with GPIO interrupt we have to do quirks in handler */
317 if (gpio_is_valid(board->irq_pin))
318 host->irq_handler = at91_irq_handler;
319
320 host->ports[0]->select_data = board->chipselect;
321
322 ret = ide_host_register(host, &at91_ide_port_info, hws);
323 if (ret) {
324 perr("failed to register ide host\n");
325 goto err_free_host;
326 }
327 platform_set_drvdata(pdev, host);
328 return 0;
329
330err_free_host:
331 ide_host_free(host);
332 return ret;
333}
334
335static int __exit at91_ide_remove(struct platform_device *pdev)
336{
337 struct ide_host *host = platform_get_drvdata(pdev);
338
339 ide_host_remove(host);
340 return 0;
341}
342
343static struct platform_driver at91_ide_driver = {
344 .driver = {
345 .name = DRV_NAME,
346 .owner = THIS_MODULE,
347 },
348 .remove = __exit_p(at91_ide_remove),
349};
350
351static int __init at91_ide_init(void)
352{
353 return platform_driver_probe(&at91_ide_driver, at91_ide_probe);
354}
355
356static void __exit at91_ide_exit(void)
357{
358 platform_driver_unregister(&at91_ide_driver);
359}
360
361module_init(at91_ide_init);
362module_exit(at91_ide_exit);
363
364MODULE_LICENSE("GPL");
365MODULE_AUTHOR("Stanislaw Gruszka <stf_xl@wp.pl>");
366
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index a3ad957507d..ee3c122c059 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -307,8 +307,12 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
307 device_init_wakeup(&pdev->dev, 1); 307 device_init_wakeup(&pdev->dev, 1);
308 308
309 platform_set_drvdata(pdev, rtc); 309 platform_set_drvdata(pdev, rtc);
310 rtc->rtt = (void __force __iomem *) (AT91_VA_BASE_SYS - AT91_BASE_SYS); 310 rtc->rtt = ioremap(r->start, resource_size(r));
311 rtc->rtt += r->start; 311 if (!rtc->rtt) {
312 dev_err(&pdev->dev, "failed to map registers, aborting.\n");
313 ret = -ENOMEM;
314 goto fail;
315 }
312 316
313 mr = rtt_readl(rtc, MR); 317 mr = rtt_readl(rtc, MR);
314 318
@@ -326,7 +330,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
326 &at91_rtc_ops, THIS_MODULE); 330 &at91_rtc_ops, THIS_MODULE);
327 if (IS_ERR(rtc->rtcdev)) { 331 if (IS_ERR(rtc->rtcdev)) {
328 ret = PTR_ERR(rtc->rtcdev); 332 ret = PTR_ERR(rtc->rtcdev);
329 goto fail; 333 goto fail_register;
330 } 334 }
331 335
332 /* register irq handler after we know what name we'll use */ 336 /* register irq handler after we know what name we'll use */
@@ -351,6 +355,8 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
351 355
352 return 0; 356 return 0;
353 357
358fail_register:
359 iounmap(rtc->rtt);
354fail: 360fail:
355 platform_set_drvdata(pdev, NULL); 361 platform_set_drvdata(pdev, NULL);
356 kfree(rtc); 362 kfree(rtc);
@@ -371,6 +377,7 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
371 377
372 rtc_device_unregister(rtc->rtcdev); 378 rtc_device_unregister(rtc->rtcdev);
373 379
380 iounmap(rtc->rtt);
374 platform_set_drvdata(pdev, NULL); 381 platform_set_drvdata(pdev, NULL);
375 kfree(rtc); 382 kfree(rtc);
376 return 0; 383 return 0;