diff options
| author | Kumar Gala <galak@gate.crashing.org> | 2006-01-23 17:58:04 -0500 |
|---|---|---|
| committer | Paul Mackerras <paulus@samba.org> | 2006-02-07 06:38:32 -0500 |
| commit | 2fb07d776b3c4473275eb225b6bf2a83755c9bfe (patch) | |
| tree | 0ba9f8cc0d61b61bd9b679fdfcdd66301a7d908a | |
| parent | d2515c806ea2b602e99b9aa19448577c7f0318fb (diff) | |
[PATCH] powerpc: cleaned up fsl_soc.c
Cleaned up fsl_soc.c based on comments from Olof Johansson. Ran through
Lindent, and split gfar_mdio init into its own function.
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
| -rw-r--r-- | arch/powerpc/sysdev/fsl_soc.c | 152 |
1 files changed, 94 insertions, 58 deletions
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c index 064c9de47732..e0887d5c3bb1 100644 --- a/arch/powerpc/sysdev/fsl_soc.c +++ b/arch/powerpc/sysdev/fsl_soc.c | |||
| @@ -40,7 +40,7 @@ phys_addr_t get_immrbase(void) | |||
| 40 | return immrbase; | 40 | return immrbase; |
| 41 | 41 | ||
| 42 | soc = of_find_node_by_type(NULL, "soc"); | 42 | soc = of_find_node_by_type(NULL, "soc"); |
| 43 | if (soc != 0) { | 43 | if (soc) { |
| 44 | unsigned int size; | 44 | unsigned int size; |
| 45 | void *prop = get_property(soc, "reg", &size); | 45 | void *prop = get_property(soc, "reg", &size); |
| 46 | immrbase = of_translate_address(soc, prop); | 46 | immrbase = of_translate_address(soc, prop); |
| @@ -49,21 +49,20 @@ phys_addr_t get_immrbase(void) | |||
| 49 | 49 | ||
| 50 | return immrbase; | 50 | return immrbase; |
| 51 | } | 51 | } |
| 52 | EXPORT_SYMBOL(get_immrbase); | ||
| 53 | 52 | ||
| 54 | static const char * gfar_tx_intr = "tx"; | 53 | EXPORT_SYMBOL(get_immrbase); |
| 55 | static const char * gfar_rx_intr = "rx"; | ||
| 56 | static const char * gfar_err_intr = "error"; | ||
| 57 | 54 | ||
| 58 | static int __init gfar_of_init(void) | 55 | static int __init gfar_mdio_of_init(void) |
| 59 | { | 56 | { |
| 60 | struct device_node *np; | 57 | struct device_node *np; |
| 61 | unsigned int i; | 58 | unsigned int i; |
| 62 | struct platform_device *mdio_dev, *gfar_dev; | 59 | struct platform_device *mdio_dev; |
| 63 | struct resource res; | 60 | struct resource res; |
| 64 | int ret; | 61 | int ret; |
| 65 | 62 | ||
| 66 | for (np = NULL, i = 0; (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; i++) { | 63 | for (np = NULL, i = 0; |
| 64 | (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL; | ||
| 65 | i++) { | ||
| 67 | int k; | 66 | int k; |
| 68 | struct device_node *child = NULL; | 67 | struct device_node *child = NULL; |
| 69 | struct gianfar_mdio_data mdio_data; | 68 | struct gianfar_mdio_data mdio_data; |
| @@ -73,12 +72,14 @@ static int __init gfar_of_init(void) | |||
| 73 | 72 | ||
| 74 | ret = of_address_to_resource(np, 0, &res); | 73 | ret = of_address_to_resource(np, 0, &res); |
| 75 | if (ret) | 74 | if (ret) |
| 76 | goto mdio_err; | 75 | goto err; |
| 77 | 76 | ||
| 78 | mdio_dev = platform_device_register_simple("fsl-gianfar_mdio", res.start, &res, 1); | 77 | mdio_dev = |
| 78 | platform_device_register_simple("fsl-gianfar_mdio", | ||
| 79 | res.start, &res, 1); | ||
| 79 | if (IS_ERR(mdio_dev)) { | 80 | if (IS_ERR(mdio_dev)) { |
| 80 | ret = PTR_ERR(mdio_dev); | 81 | ret = PTR_ERR(mdio_dev); |
| 81 | goto mdio_err; | 82 | goto err; |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | for (k = 0; k < 32; k++) | 85 | for (k = 0; k < 32; k++) |
| @@ -86,17 +87,44 @@ static int __init gfar_of_init(void) | |||
| 86 | 87 | ||
| 87 | while ((child = of_get_next_child(np, child)) != NULL) { | 88 | while ((child = of_get_next_child(np, child)) != NULL) { |
| 88 | if (child->n_intrs) { | 89 | if (child->n_intrs) { |
| 89 | u32 *id = (u32 *) get_property(child, "reg", NULL); | 90 | u32 *id = |
| 91 | (u32 *) get_property(child, "reg", NULL); | ||
| 90 | mdio_data.irq[*id] = child->intrs[0].line; | 92 | mdio_data.irq[*id] = child->intrs[0].line; |
| 91 | } | 93 | } |
| 92 | } | 94 | } |
| 93 | 95 | ||
| 94 | ret = platform_device_add_data(mdio_dev, &mdio_data, sizeof(struct gianfar_mdio_data)); | 96 | ret = |
| 97 | platform_device_add_data(mdio_dev, &mdio_data, | ||
| 98 | sizeof(struct gianfar_mdio_data)); | ||
| 95 | if (ret) | 99 | if (ret) |
| 96 | goto mdio_unreg; | 100 | goto unreg; |
| 97 | } | 101 | } |
| 98 | 102 | ||
| 99 | for (np = NULL, i = 0; (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; i++) { | 103 | return 0; |
| 104 | |||
| 105 | unreg: | ||
| 106 | platform_device_unregister(mdio_dev); | ||
| 107 | err: | ||
| 108 | return ret; | ||
| 109 | } | ||
| 110 | |||
| 111 | arch_initcall(gfar_mdio_of_init); | ||
| 112 | |||
| 113 | static const char *gfar_tx_intr = "tx"; | ||
| 114 | static const char *gfar_rx_intr = "rx"; | ||
| 115 | static const char *gfar_err_intr = "error"; | ||
| 116 | |||
| 117 | static int __init gfar_of_init(void) | ||
| 118 | { | ||
| 119 | struct device_node *np; | ||
| 120 | unsigned int i; | ||
| 121 | struct platform_device *gfar_dev; | ||
| 122 | struct resource res; | ||
| 123 | int ret; | ||
| 124 | |||
| 125 | for (np = NULL, i = 0; | ||
| 126 | (np = of_find_compatible_node(np, "network", "gianfar")) != NULL; | ||
| 127 | i++) { | ||
| 100 | struct resource r[4]; | 128 | struct resource r[4]; |
| 101 | struct device_node *phy, *mdio; | 129 | struct device_node *phy, *mdio; |
| 102 | struct gianfar_platform_data gfar_data; | 130 | struct gianfar_platform_data gfar_data; |
| @@ -110,7 +138,7 @@ static int __init gfar_of_init(void) | |||
| 110 | 138 | ||
| 111 | ret = of_address_to_resource(np, 0, &r[0]); | 139 | ret = of_address_to_resource(np, 0, &r[0]); |
| 112 | if (ret) | 140 | if (ret) |
| 113 | goto gfar_err; | 141 | goto err; |
| 114 | 142 | ||
| 115 | r[1].start = np->intrs[0].line; | 143 | r[1].start = np->intrs[0].line; |
| 116 | r[1].end = np->intrs[0].line; | 144 | r[1].end = np->intrs[0].line; |
| @@ -133,11 +161,13 @@ static int __init gfar_of_init(void) | |||
| 133 | r[3].flags = IORESOURCE_IRQ; | 161 | r[3].flags = IORESOURCE_IRQ; |
| 134 | } | 162 | } |
| 135 | 163 | ||
| 136 | gfar_dev = platform_device_register_simple("fsl-gianfar", i, &r[0], np->n_intrs + 1); | 164 | gfar_dev = |
| 165 | platform_device_register_simple("fsl-gianfar", i, &r[0], | ||
| 166 | np->n_intrs + 1); | ||
| 137 | 167 | ||
| 138 | if (IS_ERR(gfar_dev)) { | 168 | if (IS_ERR(gfar_dev)) { |
| 139 | ret = PTR_ERR(gfar_dev); | 169 | ret = PTR_ERR(gfar_dev); |
| 140 | goto gfar_err; | 170 | goto err; |
| 141 | } | 171 | } |
| 142 | 172 | ||
| 143 | mac_addr = get_property(np, "address", NULL); | 173 | mac_addr = get_property(np, "address", NULL); |
| @@ -145,26 +175,26 @@ static int __init gfar_of_init(void) | |||
| 145 | 175 | ||
| 146 | if (model && !strcasecmp(model, "TSEC")) | 176 | if (model && !strcasecmp(model, "TSEC")) |
| 147 | gfar_data.device_flags = | 177 | gfar_data.device_flags = |
| 148 | FSL_GIANFAR_DEV_HAS_GIGABIT | | 178 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 149 | FSL_GIANFAR_DEV_HAS_COALESCE | | 179 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 150 | FSL_GIANFAR_DEV_HAS_RMON | | 180 | FSL_GIANFAR_DEV_HAS_RMON | |
| 151 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; | 181 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; |
| 152 | if (model && !strcasecmp(model, "eTSEC")) | 182 | if (model && !strcasecmp(model, "eTSEC")) |
| 153 | gfar_data.device_flags = | 183 | gfar_data.device_flags = |
| 154 | FSL_GIANFAR_DEV_HAS_GIGABIT | | 184 | FSL_GIANFAR_DEV_HAS_GIGABIT | |
| 155 | FSL_GIANFAR_DEV_HAS_COALESCE | | 185 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 156 | FSL_GIANFAR_DEV_HAS_RMON | | 186 | FSL_GIANFAR_DEV_HAS_RMON | |
| 157 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | | 187 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | |
| 158 | FSL_GIANFAR_DEV_HAS_CSUM | | 188 | FSL_GIANFAR_DEV_HAS_CSUM | |
| 159 | FSL_GIANFAR_DEV_HAS_VLAN | | 189 | FSL_GIANFAR_DEV_HAS_VLAN | |
| 160 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; | 190 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; |
| 161 | 191 | ||
| 162 | ph = (phandle *) get_property(np, "phy-handle", NULL); | 192 | ph = (phandle *) get_property(np, "phy-handle", NULL); |
| 163 | phy = of_find_node_by_phandle(*ph); | 193 | phy = of_find_node_by_phandle(*ph); |
| 164 | 194 | ||
| 165 | if (phy == NULL) { | 195 | if (phy == NULL) { |
| 166 | ret = -ENODEV; | 196 | ret = -ENODEV; |
| 167 | goto gfar_unreg; | 197 | goto unreg; |
| 168 | } | 198 | } |
| 169 | 199 | ||
| 170 | mdio = of_get_parent(phy); | 200 | mdio = of_get_parent(phy); |
| @@ -174,7 +204,7 @@ static int __init gfar_of_init(void) | |||
| 174 | if (ret) { | 204 | if (ret) { |
| 175 | of_node_put(phy); | 205 | of_node_put(phy); |
| 176 | of_node_put(mdio); | 206 | of_node_put(mdio); |
| 177 | goto gfar_unreg; | 207 | goto unreg; |
| 178 | } | 208 | } |
| 179 | 209 | ||
| 180 | gfar_data.phy_id = *id; | 210 | gfar_data.phy_id = *id; |
| @@ -183,23 +213,22 @@ static int __init gfar_of_init(void) | |||
| 183 | of_node_put(phy); | 213 | of_node_put(phy); |
| 184 | of_node_put(mdio); | 214 | of_node_put(mdio); |
| 185 | 215 | ||
| 186 | ret = platform_device_add_data(gfar_dev, &gfar_data, sizeof(struct gianfar_platform_data)); | 216 | ret = |
| 217 | platform_device_add_data(gfar_dev, &gfar_data, | ||
| 218 | sizeof(struct | ||
| 219 | gianfar_platform_data)); | ||
| 187 | if (ret) | 220 | if (ret) |
| 188 | goto gfar_unreg; | 221 | goto unreg; |
| 189 | } | 222 | } |
| 190 | 223 | ||
| 191 | return 0; | 224 | return 0; |
| 192 | 225 | ||
| 193 | mdio_unreg: | 226 | unreg: |
| 194 | platform_device_unregister(mdio_dev); | ||
| 195 | mdio_err: | ||
| 196 | return ret; | ||
| 197 | |||
| 198 | gfar_unreg: | ||
| 199 | platform_device_unregister(gfar_dev); | 227 | platform_device_unregister(gfar_dev); |
| 200 | gfar_err: | 228 | err: |
| 201 | return ret; | 229 | return ret; |
| 202 | } | 230 | } |
| 231 | |||
| 203 | arch_initcall(gfar_of_init); | 232 | arch_initcall(gfar_of_init); |
| 204 | 233 | ||
| 205 | static int __init fsl_i2c_of_init(void) | 234 | static int __init fsl_i2c_of_init(void) |
| @@ -209,17 +238,19 @@ static int __init fsl_i2c_of_init(void) | |||
| 209 | struct platform_device *i2c_dev; | 238 | struct platform_device *i2c_dev; |
| 210 | int ret; | 239 | int ret; |
| 211 | 240 | ||
| 212 | for (np = NULL, i = 0; (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; i++) { | 241 | for (np = NULL, i = 0; |
| 242 | (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL; | ||
| 243 | i++) { | ||
| 213 | struct resource r[2]; | 244 | struct resource r[2]; |
| 214 | struct fsl_i2c_platform_data i2c_data; | 245 | struct fsl_i2c_platform_data i2c_data; |
| 215 | unsigned char * flags = NULL; | 246 | unsigned char *flags = NULL; |
| 216 | 247 | ||
| 217 | memset(&r, 0, sizeof(r)); | 248 | memset(&r, 0, sizeof(r)); |
| 218 | memset(&i2c_data, 0, sizeof(i2c_data)); | 249 | memset(&i2c_data, 0, sizeof(i2c_data)); |
| 219 | 250 | ||
| 220 | ret = of_address_to_resource(np, 0, &r[0]); | 251 | ret = of_address_to_resource(np, 0, &r[0]); |
| 221 | if (ret) | 252 | if (ret) |
| 222 | goto i2c_err; | 253 | goto err; |
| 223 | 254 | ||
| 224 | r[1].start = np->intrs[0].line; | 255 | r[1].start = np->intrs[0].line; |
| 225 | r[1].end = np->intrs[0].line; | 256 | r[1].end = np->intrs[0].line; |
| @@ -228,7 +259,7 @@ static int __init fsl_i2c_of_init(void) | |||
| 228 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); | 259 | i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2); |
| 229 | if (IS_ERR(i2c_dev)) { | 260 | if (IS_ERR(i2c_dev)) { |
| 230 | ret = PTR_ERR(i2c_dev); | 261 | ret = PTR_ERR(i2c_dev); |
| 231 | goto i2c_err; | 262 | goto err; |
| 232 | } | 263 | } |
| 233 | 264 | ||
| 234 | i2c_data.device_flags = 0; | 265 | i2c_data.device_flags = 0; |
| @@ -240,18 +271,22 @@ static int __init fsl_i2c_of_init(void) | |||
| 240 | if (flags) | 271 | if (flags) |
| 241 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; | 272 | i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200; |
| 242 | 273 | ||
| 243 | ret = platform_device_add_data(i2c_dev, &i2c_data, sizeof(struct fsl_i2c_platform_data)); | 274 | ret = |
| 275 | platform_device_add_data(i2c_dev, &i2c_data, | ||
| 276 | sizeof(struct | ||
| 277 | fsl_i2c_platform_data)); | ||
| 244 | if (ret) | 278 | if (ret) |
| 245 | goto i2c_unreg; | 279 | goto unreg; |
| 246 | } | 280 | } |
| 247 | 281 | ||
| 248 | return 0; | 282 | return 0; |
| 249 | 283 | ||
| 250 | i2c_unreg: | 284 | unreg: |
| 251 | platform_device_unregister(i2c_dev); | 285 | platform_device_unregister(i2c_dev); |
| 252 | i2c_err: | 286 | err: |
| 253 | return ret; | 287 | return ret; |
| 254 | } | 288 | } |
| 289 | |||
| 255 | arch_initcall(fsl_i2c_of_init); | 290 | arch_initcall(fsl_i2c_of_init); |
| 256 | 291 | ||
| 257 | #ifdef CONFIG_PPC_83xx | 292 | #ifdef CONFIG_PPC_83xx |
| @@ -267,51 +302,52 @@ static int __init mpc83xx_wdt_init(void) | |||
| 267 | 302 | ||
| 268 | if (!np) { | 303 | if (!np) { |
| 269 | ret = -ENODEV; | 304 | ret = -ENODEV; |
| 270 | goto mpc83xx_wdt_nodev; | 305 | goto nodev; |
| 271 | } | 306 | } |
| 272 | 307 | ||
| 273 | soc = of_find_node_by_type(NULL, "soc"); | 308 | soc = of_find_node_by_type(NULL, "soc"); |
| 274 | 309 | ||
| 275 | if (!soc) { | 310 | if (!soc) { |
| 276 | ret = -ENODEV; | 311 | ret = -ENODEV; |
| 277 | goto mpc83xx_wdt_nosoc; | 312 | goto nosoc; |
| 278 | } | 313 | } |
| 279 | 314 | ||
| 280 | freq = (unsigned int *)get_property(soc, "bus-frequency", NULL); | 315 | freq = (unsigned int *)get_property(soc, "bus-frequency", NULL); |
| 281 | if (!freq) { | 316 | if (!freq) { |
| 282 | ret = -ENODEV; | 317 | ret = -ENODEV; |
| 283 | goto mpc83xx_wdt_err; | 318 | goto err; |
| 284 | } | 319 | } |
| 285 | 320 | ||
| 286 | memset(&r, 0, sizeof(r)); | 321 | memset(&r, 0, sizeof(r)); |
| 287 | 322 | ||
| 288 | ret = of_address_to_resource(np, 0, &r); | 323 | ret = of_address_to_resource(np, 0, &r); |
| 289 | if (ret) | 324 | if (ret) |
| 290 | goto mpc83xx_wdt_err; | 325 | goto err; |
| 291 | 326 | ||
| 292 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); | 327 | dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1); |
| 293 | if (IS_ERR(dev)) { | 328 | if (IS_ERR(dev)) { |
| 294 | ret = PTR_ERR(dev); | 329 | ret = PTR_ERR(dev); |
| 295 | goto mpc83xx_wdt_err; | 330 | goto err; |
| 296 | } | 331 | } |
| 297 | 332 | ||
| 298 | ret = platform_device_add_data(dev, freq, sizeof(int)); | 333 | ret = platform_device_add_data(dev, freq, sizeof(int)); |
| 299 | if (ret) | 334 | if (ret) |
| 300 | goto mpc83xx_wdt_unreg; | 335 | goto unreg; |
| 301 | 336 | ||
| 302 | of_node_put(soc); | 337 | of_node_put(soc); |
| 303 | of_node_put(np); | 338 | of_node_put(np); |
| 304 | 339 | ||
| 305 | return 0; | 340 | return 0; |
| 306 | 341 | ||
| 307 | mpc83xx_wdt_unreg: | 342 | unreg: |
| 308 | platform_device_unregister(dev); | 343 | platform_device_unregister(dev); |
| 309 | mpc83xx_wdt_err: | 344 | err: |
| 310 | of_node_put(soc); | 345 | of_node_put(soc); |
| 311 | mpc83xx_wdt_nosoc: | 346 | nosoc: |
| 312 | of_node_put(np); | 347 | of_node_put(np); |
| 313 | mpc83xx_wdt_nodev: | 348 | nodev: |
| 314 | return ret; | 349 | return ret; |
| 315 | } | 350 | } |
| 351 | |||
| 316 | arch_initcall(mpc83xx_wdt_init); | 352 | arch_initcall(mpc83xx_wdt_init); |
| 317 | #endif | 353 | #endif |
