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/i2c.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #include <asm/octeon/octeon.h>
17 #include <asm/octeon/cvmx-rnm-defs.h>
19 static struct octeon_cf_data octeon_cf_data
;
21 static int __init
octeon_cf_device_init(void)
23 union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg
;
24 unsigned long base_ptr
, region_base
, region_size
;
25 struct platform_device
*pd
;
26 struct resource cf_resources
[3];
27 unsigned int num_resources
;
31 /* Setup octeon-cf platform device if present. */
33 if (octeon_bootinfo
->major_version
== 1
34 && octeon_bootinfo
->minor_version
>= 1) {
35 if (octeon_bootinfo
->compact_flash_common_base_addr
)
37 octeon_bootinfo
->compact_flash_common_base_addr
;
39 base_ptr
= 0x1d000800;
45 /* Find CS0 region. */
46 for (i
= 0; i
< 8; i
++) {
47 mio_boot_reg_cfg
.u64
= cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(i
));
48 region_base
= mio_boot_reg_cfg
.s
.base
<< 16;
49 region_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
50 if (mio_boot_reg_cfg
.s
.en
&& base_ptr
>= region_base
51 && base_ptr
< region_base
+ region_size
)
55 /* i and i + 1 are CS0 and CS1, both must be less than 8. */
58 octeon_cf_data
.base_region
= i
;
59 octeon_cf_data
.is16bit
= mio_boot_reg_cfg
.s
.width
;
60 octeon_cf_data
.base_region_bias
= base_ptr
- region_base
;
61 memset(cf_resources
, 0, sizeof(cf_resources
));
63 cf_resources
[num_resources
].flags
= IORESOURCE_MEM
;
64 cf_resources
[num_resources
].start
= region_base
;
65 cf_resources
[num_resources
].end
= region_base
+ region_size
- 1;
69 if (!(base_ptr
& 0xfffful
)) {
71 * Boot loader signals availability of DMA (true_ide
72 * mode) by setting low order bits of base_ptr to
76 /* Asume that CS1 immediately follows. */
77 mio_boot_reg_cfg
.u64
=
78 cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(i
+ 1));
79 region_base
= mio_boot_reg_cfg
.s
.base
<< 16;
80 region_size
= (mio_boot_reg_cfg
.s
.size
+ 1) << 16;
81 if (!mio_boot_reg_cfg
.s
.en
)
84 cf_resources
[num_resources
].flags
= IORESOURCE_MEM
;
85 cf_resources
[num_resources
].start
= region_base
;
86 cf_resources
[num_resources
].end
= region_base
+ region_size
- 1;
89 octeon_cf_data
.dma_engine
= 0;
90 cf_resources
[num_resources
].flags
= IORESOURCE_IRQ
;
91 cf_resources
[num_resources
].start
= OCTEON_IRQ_BOOTDMA
;
92 cf_resources
[num_resources
].end
= OCTEON_IRQ_BOOTDMA
;
95 octeon_cf_data
.dma_engine
= -1;
98 pd
= platform_device_alloc("pata_octeon_cf", -1);
103 pd
->dev
.platform_data
= &octeon_cf_data
;
105 ret
= platform_device_add_resources(pd
, cf_resources
, num_resources
);
109 ret
= platform_device_add(pd
);
115 platform_device_put(pd
);
119 device_initcall(octeon_cf_device_init
);
121 /* Octeon Random Number Generator. */
122 static int __init
octeon_rng_device_init(void)
124 struct platform_device
*pd
;
127 struct resource rng_resources
[] = {
129 .flags
= IORESOURCE_MEM
,
130 .start
= XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS
),
131 .end
= XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS
) + 0xf
133 .flags
= IORESOURCE_MEM
,
134 .start
= cvmx_build_io_address(8, 0),
135 .end
= cvmx_build_io_address(8, 0) + 0x7
139 pd
= platform_device_alloc("octeon_rng", -1);
145 ret
= platform_device_add_resources(pd
, rng_resources
,
146 ARRAY_SIZE(rng_resources
));
150 ret
= platform_device_add(pd
);
156 platform_device_put(pd
);
161 device_initcall(octeon_rng_device_init
);
163 static struct i2c_board_info __initdata octeon_i2c_devices
[] = {
165 I2C_BOARD_INFO("ds1337", 0x68),
169 static int __init
octeon_i2c_devices_init(void)
171 return i2c_register_board_info(0, octeon_i2c_devices
,
172 ARRAY_SIZE(octeon_i2c_devices
));
174 arch_initcall(octeon_i2c_devices_init
);
176 #define OCTEON_I2C_IO_BASE 0x1180000001000ull
177 #define OCTEON_I2C_IO_UNIT_OFFSET 0x200
179 static struct octeon_i2c_data octeon_i2c_data
[2];
181 static int __init
octeon_i2c_device_init(void)
183 struct platform_device
*pd
;
187 struct resource i2c_resources
[] = {
189 .flags
= IORESOURCE_MEM
,
191 .flags
= IORESOURCE_IRQ
,
195 if (OCTEON_IS_MODEL(OCTEON_CN56XX
) || OCTEON_IS_MODEL(OCTEON_CN52XX
))
200 for (port
= 0; port
< num_ports
; port
++) {
201 octeon_i2c_data
[port
].sys_freq
= octeon_get_clock_rate();
202 /*FIXME: should be examined. At the moment is set for 100Khz */
203 octeon_i2c_data
[port
].i2c_freq
= 100000;
205 pd
= platform_device_alloc("i2c-octeon", port
);
211 pd
->dev
.platform_data
= octeon_i2c_data
+ port
;
213 i2c_resources
[0].start
=
214 OCTEON_I2C_IO_BASE
+ (port
* OCTEON_I2C_IO_UNIT_OFFSET
);
215 i2c_resources
[0].end
= i2c_resources
[0].start
+ 0x1f;
218 i2c_resources
[1].start
= OCTEON_IRQ_TWSI
;
219 i2c_resources
[1].end
= OCTEON_IRQ_TWSI
;
222 i2c_resources
[1].start
= OCTEON_IRQ_TWSI2
;
223 i2c_resources
[1].end
= OCTEON_IRQ_TWSI2
;
229 ret
= platform_device_add_resources(pd
,
231 ARRAY_SIZE(i2c_resources
));
235 ret
= platform_device_add(pd
);
241 platform_device_put(pd
);
245 device_initcall(octeon_i2c_device_init
);
247 /* Octeon SMI/MDIO interface. */
248 static int __init
octeon_mdiobus_device_init(void)
250 struct platform_device
*pd
;
253 if (octeon_is_simulation())
254 return 0; /* No mdio in the simulator. */
256 /* The bus number is the platform_device id. */
257 pd
= platform_device_alloc("mdio-octeon", 0);
263 ret
= platform_device_add(pd
);
269 platform_device_put(pd
);
275 device_initcall(octeon_mdiobus_device_init
);
277 /* Octeon mgmt port Ethernet interface. */
278 static int __init
octeon_mgmt_device_init(void)
280 struct platform_device
*pd
;
284 struct resource mgmt_port_resource
= {
285 .flags
= IORESOURCE_IRQ
,
290 if (!OCTEON_IS_MODEL(OCTEON_CN56XX
) && !OCTEON_IS_MODEL(OCTEON_CN52XX
))
293 if (OCTEON_IS_MODEL(OCTEON_CN56XX
))
298 for (port
= 0; port
< num_ports
; port
++) {
299 pd
= platform_device_alloc("octeon_mgmt", port
);
306 mgmt_port_resource
.start
= OCTEON_IRQ_MII0
;
309 mgmt_port_resource
.start
= OCTEON_IRQ_MII1
;
314 mgmt_port_resource
.end
= mgmt_port_resource
.start
;
316 ret
= platform_device_add_resources(pd
, &mgmt_port_resource
, 1);
321 ret
= platform_device_add(pd
);
327 platform_device_put(pd
);
333 device_initcall(octeon_mgmt_device_init
);
335 MODULE_AUTHOR("David Daney <ddaney@caviumnetworks.com>");
336 MODULE_LICENSE("GPL");
337 MODULE_DESCRIPTION("Platform driver for Octeon SOC");