2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2004-2009 Cavium Networks
7 * Copyright (C) 2008 Wind River Systems
10 #include <linux/init.h>
11 #include <linux/irq.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include <asm/octeon/octeon.h>
16 #include <asm/octeon/cvmx-rnm-defs.h>
18 static struct octeon_cf_data octeon_cf_data
;
20 static int __init
octeon_cf_device_init(void)
22 union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg
;
23 unsigned long base_ptr
, region_base
, region_size
;
24 struct platform_device
*pd
;
25 struct resource cf_resources
[3];
26 unsigned int num_resources
;
30 /* Setup octeon-cf platform device if present. */
32 if (octeon_bootinfo
->major_version
== 1
33 && octeon_bootinfo
->minor_version
>= 1) {
34 if (octeon_bootinfo
->compact_flash_common_base_addr
)
36 octeon_bootinfo
->compact_flash_common_base_addr
;
38 base_ptr
= 0x1d000800;
44 /* Find CS0 region. */
45 for (i
= 0; i
< 8; i
++) {
46 mio_boot_reg_cfg
.u64
= cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(i
));
47 region_base
= mio_boot_reg_cfg
.s
.base
<< 16;
48 region_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
49 if (mio_boot_reg_cfg
.s
.en
&& base_ptr
>= region_base
50 && base_ptr
< region_base
+ region_size
)
54 /* i and i + 1 are CS0 and CS1, both must be less than 8. */
57 octeon_cf_data
.base_region
= i
;
58 octeon_cf_data
.is16bit
= mio_boot_reg_cfg
.s
.width
;
59 octeon_cf_data
.base_region_bias
= base_ptr
- region_base
;
60 memset(cf_resources
, 0, sizeof(cf_resources
));
62 cf_resources
[num_resources
].flags
= IORESOURCE_MEM
;
63 cf_resources
[num_resources
].start
= region_base
;
64 cf_resources
[num_resources
].end
= region_base
+ region_size
- 1;
68 if (!(base_ptr
& 0xfffful
)) {
70 * Boot loader signals availability of DMA (true_ide
71 * mode) by setting low order bits of base_ptr to
75 /* Asume that CS1 immediately follows. */
76 mio_boot_reg_cfg
.u64
=
77 cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(i
+ 1));
78 region_base
= mio_boot_reg_cfg
.s
.base
<< 16;
79 region_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
80 if (!mio_boot_reg_cfg
.s
.en
)
83 cf_resources
[num_resources
].flags
= IORESOURCE_MEM
;
84 cf_resources
[num_resources
].start
= region_base
;
85 cf_resources
[num_resources
].end
= region_base
+ region_size
- 1;
88 octeon_cf_data
.dma_engine
= 0;
89 cf_resources
[num_resources
].flags
= IORESOURCE_IRQ
;
90 cf_resources
[num_resources
].start
= OCTEON_IRQ_BOOTDMA
;
91 cf_resources
[num_resources
].end
= OCTEON_IRQ_BOOTDMA
;
94 octeon_cf_data
.dma_engine
= -1;
97 pd
= platform_device_alloc("pata_octeon_cf", -1);
102 pd
->dev
.platform_data
= &octeon_cf_data
;
104 ret
= platform_device_add_resources(pd
, cf_resources
, num_resources
);
108 ret
= platform_device_add(pd
);
114 platform_device_put(pd
);
118 device_initcall(octeon_cf_device_init
);
120 /* Octeon Random Number Generator. */
121 static int __init
octeon_rng_device_init(void)
123 struct platform_device
*pd
;
126 struct resource rng_resources
[] = {
128 .flags
= IORESOURCE_MEM
,
129 .start
= XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS
),
130 .end
= XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS
) + 0xf
132 .flags
= IORESOURCE_MEM
,
133 .start
= cvmx_build_io_address(8, 0),
134 .end
= cvmx_build_io_address(8, 0) + 0x7
138 pd
= platform_device_alloc("octeon_rng", -1);
144 ret
= platform_device_add_resources(pd
, rng_resources
,
145 ARRAY_SIZE(rng_resources
));
149 ret
= platform_device_add(pd
);
155 platform_device_put(pd
);
160 device_initcall(octeon_rng_device_init
);
162 MODULE_AUTHOR("David Daney <ddaney@caviumnetworks.com>");
163 MODULE_LICENSE("GPL");
164 MODULE_DESCRIPTION("Platform driver for Octeon SOC");