Dale Farnsworth | 52d3aff | 2007-05-12 10:55:53 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Platform device setup for Marvell mv64360/mv64460 host bridges (Discovery) |
| 3 | * |
| 4 | * Author: Dale Farnsworth <dale@farnsworth.org> |
| 5 | * |
| 6 | * 2007 (c) MontaVista, Software, Inc. This file is licensed under |
| 7 | * the terms of the GNU General Public License version 2. This program |
| 8 | * is licensed "as is" without any warranty of any kind, whether express |
| 9 | * or implied. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/stddef.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/mv643xx.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | |
| 18 | #include <asm/prom.h> |
| 19 | |
| 20 | /* |
| 21 | * These functions provide the necessary setup for the mv64x60 drivers. |
| 22 | * These drivers are unusual in that they work on both the MIPS and PowerPC |
| 23 | * architectures. Because of that, the drivers do not support the normal |
| 24 | * PowerPC of_platform_bus_type. They support platform_bus_type instead. |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * Create MPSC platform devices |
| 29 | */ |
| 30 | static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np) |
| 31 | { |
| 32 | struct platform_device *pdev; |
| 33 | struct resource r[2]; |
| 34 | struct mpsc_shared_pdata pdata; |
| 35 | const phandle *ph; |
| 36 | struct device_node *mpscrouting, *mpscintr; |
| 37 | int err; |
| 38 | |
| 39 | ph = of_get_property(np, "mpscrouting", NULL); |
| 40 | mpscrouting = of_find_node_by_phandle(*ph); |
| 41 | if (!mpscrouting) |
| 42 | return -ENODEV; |
| 43 | |
| 44 | err = of_address_to_resource(mpscrouting, 0, &r[0]); |
| 45 | of_node_put(mpscrouting); |
| 46 | if (err) |
| 47 | return err; |
| 48 | |
| 49 | ph = of_get_property(np, "mpscintr", NULL); |
| 50 | mpscintr = of_find_node_by_phandle(*ph); |
| 51 | if (!mpscintr) |
| 52 | return -ENODEV; |
| 53 | |
| 54 | err = of_address_to_resource(mpscintr, 0, &r[1]); |
| 55 | of_node_put(mpscintr); |
| 56 | if (err) |
| 57 | return err; |
| 58 | |
| 59 | memset(&pdata, 0, sizeof(pdata)); |
| 60 | |
| 61 | pdev = platform_device_alloc(MPSC_SHARED_NAME, 0); |
| 62 | if (!pdev) |
| 63 | return -ENOMEM; |
| 64 | |
| 65 | err = platform_device_add_resources(pdev, r, 2); |
| 66 | if (err) |
| 67 | goto error; |
| 68 | |
| 69 | err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 70 | if (err) |
| 71 | goto error; |
| 72 | |
| 73 | err = platform_device_add(pdev); |
| 74 | if (err) |
| 75 | goto error; |
| 76 | |
| 77 | return 0; |
| 78 | |
| 79 | error: |
| 80 | platform_device_put(pdev); |
| 81 | return err; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id) |
| 86 | { |
| 87 | struct resource r[5]; |
| 88 | struct mpsc_pdata pdata; |
| 89 | struct platform_device *pdev; |
| 90 | const unsigned int *prop; |
| 91 | const phandle *ph; |
| 92 | struct device_node *sdma, *brg; |
| 93 | int err; |
| 94 | int port_number; |
| 95 | |
| 96 | /* only register the shared platform device the first time through */ |
| 97 | if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np))) |
| 98 | return err; |
| 99 | |
| 100 | memset(r, 0, sizeof(r)); |
| 101 | |
| 102 | err = of_address_to_resource(np, 0, &r[0]); |
| 103 | if (err) |
| 104 | return err; |
| 105 | |
| 106 | of_irq_to_resource(np, 0, &r[4]); |
| 107 | |
| 108 | ph = of_get_property(np, "sdma", NULL); |
| 109 | sdma = of_find_node_by_phandle(*ph); |
| 110 | if (!sdma) |
| 111 | return -ENODEV; |
| 112 | |
| 113 | of_irq_to_resource(sdma, 0, &r[3]); |
| 114 | err = of_address_to_resource(sdma, 0, &r[1]); |
| 115 | of_node_put(sdma); |
| 116 | if (err) |
| 117 | return err; |
| 118 | |
| 119 | ph = of_get_property(np, "brg", NULL); |
| 120 | brg = of_find_node_by_phandle(*ph); |
| 121 | if (!brg) |
| 122 | return -ENODEV; |
| 123 | |
| 124 | err = of_address_to_resource(brg, 0, &r[2]); |
| 125 | of_node_put(brg); |
| 126 | if (err) |
| 127 | return err; |
| 128 | |
| 129 | prop = of_get_property(np, "block-index", NULL); |
| 130 | if (!prop) |
| 131 | return -ENODEV; |
| 132 | port_number = *(int *)prop; |
| 133 | |
| 134 | memset(&pdata, 0, sizeof(pdata)); |
| 135 | |
| 136 | pdata.cache_mgmt = 1; /* All current revs need this set */ |
| 137 | |
| 138 | prop = of_get_property(np, "max_idle", NULL); |
| 139 | if (prop) |
| 140 | pdata.max_idle = *prop; |
| 141 | |
| 142 | prop = of_get_property(brg, "current-speed", NULL); |
| 143 | if (prop) |
| 144 | pdata.default_baud = *prop; |
| 145 | |
| 146 | /* Default is 8 bits, no parity, no flow control */ |
| 147 | pdata.default_bits = 8; |
| 148 | pdata.default_parity = 'n'; |
| 149 | pdata.default_flow = 'n'; |
| 150 | |
| 151 | prop = of_get_property(np, "chr_1", NULL); |
| 152 | if (prop) |
| 153 | pdata.chr_1_val = *prop; |
| 154 | |
| 155 | prop = of_get_property(np, "chr_2", NULL); |
| 156 | if (prop) |
| 157 | pdata.chr_2_val = *prop; |
| 158 | |
| 159 | prop = of_get_property(np, "chr_10", NULL); |
| 160 | if (prop) |
| 161 | pdata.chr_10_val = *prop; |
| 162 | |
| 163 | prop = of_get_property(np, "mpcr", NULL); |
| 164 | if (prop) |
| 165 | pdata.mpcr_val = *prop; |
| 166 | |
| 167 | prop = of_get_property(brg, "bcr", NULL); |
| 168 | if (prop) |
| 169 | pdata.bcr_val = *prop; |
| 170 | |
| 171 | pdata.brg_can_tune = 1; /* All current revs need this set */ |
| 172 | |
| 173 | prop = of_get_property(brg, "clock-src", NULL); |
| 174 | if (prop) |
| 175 | pdata.brg_clk_src = *prop; |
| 176 | |
| 177 | prop = of_get_property(brg, "clock-frequency", NULL); |
| 178 | if (prop) |
| 179 | pdata.brg_clk_freq = *prop; |
| 180 | |
| 181 | pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number); |
| 182 | if (!pdev) |
| 183 | return -ENOMEM; |
| 184 | |
| 185 | err = platform_device_add_resources(pdev, r, 5); |
| 186 | if (err) |
| 187 | goto error; |
| 188 | |
| 189 | err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 190 | if (err) |
| 191 | goto error; |
| 192 | |
| 193 | err = platform_device_add(pdev); |
| 194 | if (err) |
| 195 | goto error; |
| 196 | |
| 197 | return 0; |
| 198 | |
| 199 | error: |
| 200 | platform_device_put(pdev); |
| 201 | return err; |
| 202 | } |
| 203 | |
Dale Farnsworth | 649c8e0 | 2007-05-12 10:56:24 +1000 | [diff] [blame] | 204 | /* |
| 205 | * Create mv64x60_eth platform devices |
| 206 | */ |
| 207 | static int __init eth_register_shared_pdev(struct device_node *np) |
| 208 | { |
| 209 | struct platform_device *pdev; |
| 210 | struct resource r[1]; |
| 211 | int err; |
| 212 | |
| 213 | np = of_get_parent(np); |
| 214 | if (!np) |
| 215 | return -ENODEV; |
| 216 | |
| 217 | err = of_address_to_resource(np, 0, &r[0]); |
| 218 | of_node_put(np); |
| 219 | if (err) |
| 220 | return err; |
| 221 | |
| 222 | pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0, |
| 223 | r, 1); |
| 224 | if (IS_ERR(pdev)) |
| 225 | return PTR_ERR(pdev); |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static int __init mv64x60_eth_device_setup(struct device_node *np, int id) |
| 231 | { |
| 232 | struct resource r[1]; |
| 233 | struct mv643xx_eth_platform_data pdata; |
| 234 | struct platform_device *pdev; |
| 235 | struct device_node *phy; |
| 236 | const u8 *mac_addr; |
| 237 | const int *prop; |
| 238 | const phandle *ph; |
| 239 | int err; |
| 240 | |
| 241 | /* only register the shared platform device the first time through */ |
| 242 | if (id == 0 && (err = eth_register_shared_pdev(np))) |
| 243 | return err;; |
| 244 | |
| 245 | memset(r, 0, sizeof(r)); |
| 246 | of_irq_to_resource(np, 0, &r[0]); |
| 247 | |
| 248 | memset(&pdata, 0, sizeof(pdata)); |
| 249 | |
| 250 | prop = of_get_property(np, "block-index", NULL); |
| 251 | if (!prop) |
| 252 | return -ENODEV; |
| 253 | pdata.port_number = *prop; |
| 254 | |
| 255 | mac_addr = of_get_mac_address(np); |
| 256 | if (mac_addr) |
| 257 | memcpy(pdata.mac_addr, mac_addr, 6); |
| 258 | |
| 259 | prop = of_get_property(np, "speed", NULL); |
| 260 | if (prop) |
| 261 | pdata.speed = *prop; |
| 262 | |
| 263 | prop = of_get_property(np, "tx_queue_size", NULL); |
| 264 | if (prop) |
| 265 | pdata.tx_queue_size = *prop; |
| 266 | |
| 267 | prop = of_get_property(np, "rx_queue_size", NULL); |
| 268 | if (prop) |
| 269 | pdata.rx_queue_size = *prop; |
| 270 | |
| 271 | prop = of_get_property(np, "tx_sram_addr", NULL); |
| 272 | if (prop) |
| 273 | pdata.tx_sram_addr = *prop; |
| 274 | |
| 275 | prop = of_get_property(np, "tx_sram_size", NULL); |
| 276 | if (prop) |
| 277 | pdata.tx_sram_size = *prop; |
| 278 | |
| 279 | prop = of_get_property(np, "rx_sram_addr", NULL); |
| 280 | if (prop) |
| 281 | pdata.rx_sram_addr = *prop; |
| 282 | |
| 283 | prop = of_get_property(np, "rx_sram_size", NULL); |
| 284 | if (prop) |
| 285 | pdata.rx_sram_size = *prop; |
| 286 | |
| 287 | ph = of_get_property(np, "phy", NULL); |
| 288 | if (!ph) |
| 289 | return -ENODEV; |
| 290 | |
| 291 | phy = of_find_node_by_phandle(*ph); |
| 292 | if (phy == NULL) |
| 293 | return -ENODEV; |
| 294 | |
| 295 | prop = of_get_property(phy, "reg", NULL); |
| 296 | if (prop) { |
| 297 | pdata.force_phy_addr = 1; |
| 298 | pdata.phy_addr = *prop; |
| 299 | } |
| 300 | |
| 301 | of_node_put(phy); |
| 302 | |
| 303 | pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number); |
| 304 | if (!pdev) |
| 305 | return -ENOMEM; |
| 306 | |
| 307 | err = platform_device_add_resources(pdev, r, 1); |
| 308 | if (err) |
| 309 | goto error; |
| 310 | |
| 311 | err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 312 | if (err) |
| 313 | goto error; |
| 314 | |
| 315 | err = platform_device_add(pdev); |
| 316 | if (err) |
| 317 | goto error; |
| 318 | |
| 319 | return 0; |
| 320 | |
| 321 | error: |
| 322 | platform_device_put(pdev); |
| 323 | return err; |
| 324 | } |
| 325 | |
Dale Farnsworth | 01f0e78 | 2007-05-12 10:56:47 +1000 | [diff] [blame^] | 326 | /* |
| 327 | * Create mv64x60_i2c platform devices |
| 328 | */ |
| 329 | static int __init mv64x60_i2c_device_setup(struct device_node *np, int id) |
| 330 | { |
| 331 | struct resource r[2]; |
| 332 | struct platform_device *pdev; |
| 333 | struct mv64xxx_i2c_pdata pdata; |
| 334 | const unsigned int *prop; |
| 335 | int err; |
| 336 | |
| 337 | memset(r, 0, sizeof(r)); |
| 338 | |
| 339 | err = of_address_to_resource(np, 0, &r[0]); |
| 340 | if (err) |
| 341 | return err; |
| 342 | |
| 343 | of_irq_to_resource(np, 0, &r[1]); |
| 344 | |
| 345 | memset(&pdata, 0, sizeof(pdata)); |
| 346 | |
| 347 | prop = of_get_property(np, "freq_m", NULL); |
| 348 | if (!prop) |
| 349 | return -ENODEV; |
| 350 | pdata.freq_m = *prop; |
| 351 | |
| 352 | prop = of_get_property(np, "freq_n", NULL); |
| 353 | if (!prop) |
| 354 | return -ENODEV; |
| 355 | pdata.freq_n = *prop; |
| 356 | |
| 357 | prop = of_get_property(np, "timeout", NULL); |
| 358 | if (prop) |
| 359 | pdata.timeout = *prop; |
| 360 | else |
| 361 | pdata.timeout = 1000; /* 1 second */ |
| 362 | |
| 363 | prop = of_get_property(np, "retries", NULL); |
| 364 | if (prop) |
| 365 | pdata.retries = *prop; |
| 366 | else |
| 367 | pdata.retries = 1; |
| 368 | |
| 369 | pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id); |
| 370 | if (!pdev) |
| 371 | return -ENOMEM; |
| 372 | |
| 373 | err = platform_device_add_resources(pdev, r, 2); |
| 374 | if (err) |
| 375 | goto error; |
| 376 | |
| 377 | err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); |
| 378 | if (err) |
| 379 | goto error; |
| 380 | |
| 381 | err = platform_device_add(pdev); |
| 382 | if (err) |
| 383 | goto error; |
| 384 | |
| 385 | return 0; |
| 386 | |
| 387 | error: |
| 388 | platform_device_put(pdev); |
| 389 | return err; |
| 390 | } |
| 391 | |
Dale Farnsworth | 52d3aff | 2007-05-12 10:55:53 +1000 | [diff] [blame] | 392 | static int __init mv64x60_device_setup(void) |
| 393 | { |
| 394 | struct device_node *np = NULL; |
| 395 | int id; |
| 396 | int err; |
| 397 | |
| 398 | for (id = 0; |
| 399 | (np = of_find_compatible_node(np, "serial", "marvell,mpsc")); id++) |
| 400 | if ((err = mv64x60_mpsc_device_setup(np, id))) |
| 401 | goto error; |
| 402 | |
Dale Farnsworth | 649c8e0 | 2007-05-12 10:56:24 +1000 | [diff] [blame] | 403 | for (id = 0; |
| 404 | (np = of_find_compatible_node(np, "network", |
| 405 | "marvell,mv64x60-eth")); |
| 406 | id++) |
| 407 | if ((err = mv64x60_eth_device_setup(np, id))) |
| 408 | goto error; |
| 409 | |
Dale Farnsworth | 01f0e78 | 2007-05-12 10:56:47 +1000 | [diff] [blame^] | 410 | for (id = 0; |
| 411 | (np = of_find_compatible_node(np, "i2c", "marvell,mv64x60-i2c")); |
| 412 | id++) |
| 413 | if ((err = mv64x60_i2c_device_setup(np, id))) |
| 414 | goto error; |
| 415 | |
Dale Farnsworth | 52d3aff | 2007-05-12 10:55:53 +1000 | [diff] [blame] | 416 | return 0; |
| 417 | |
| 418 | error: |
| 419 | of_node_put(np); |
| 420 | return err; |
| 421 | } |
| 422 | arch_initcall(mv64x60_device_setup); |