| 255 | } |
| 256 | |
| 257 | static int |
| 258 | mtk_gpio_attach(device_t dev) |
| 259 | { |
| 260 | struct mtk_gpio_softc *sc; |
| 261 | phandle_t node; |
| 262 | uint32_t i, num_pins; |
| 263 | |
| 264 | sc = device_get_softc(dev); |
| 265 | sc->dev = dev; |
| 266 | |
| 267 | if (bus_alloc_resources(dev, mtk_gpio_spec, sc->res)) { |
| 268 | device_printf(dev, "could not allocate resources for device\n"); |
| 269 | return (ENXIO); |
| 270 | } |
| 271 | |
| 272 | MTK_GPIO_LOCK_INIT(sc); |
| 273 | |
| 274 | node = ofw_bus_get_node(dev); |
| 275 | |
| 276 | if (OF_hasprop(node, "clocks")) |
| 277 | mtk_soc_start_clock(dev); |
| 278 | if (OF_hasprop(node, "resets")) |
| 279 | mtk_soc_reset_device(dev); |
| 280 | |
| 281 | if (OF_getprop(node, "ralink,register-map", sc->regs, |
| 282 | GPIO_PIOMAX) <= 0) { |
| 283 | device_printf(dev, "Failed to read register map\n"); |
| 284 | return (ENXIO); |
| 285 | } |
| 286 | |
| 287 | if (OF_hasprop(node, "ralink,num-gpios") && (OF_getencprop(node, |
| 288 | "ralink,num-gpios", &num_pins, sizeof(num_pins)) >= 0)) |
| 289 | sc->num_pins = num_pins; |
| 290 | else |
| 291 | sc->num_pins = MTK_GPIO_PINS; |
| 292 | |
| 293 | for (i = 0; i < sc->num_pins; i++) { |
| 294 | sc->pins[i].pin_caps |= GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | |
| 295 | GPIO_PIN_INVIN | GPIO_PIN_INVOUT | |
| 296 | GPIO_INTR_EDGE_RISING | GPIO_INTR_EDGE_FALLING; |
| 297 | sc->pins[i].intr_polarity = INTR_POLARITY_HIGH; |
| 298 | sc->pins[i].intr_trigger = INTR_TRIGGER_EDGE; |
| 299 | |
| 300 | snprintf(sc->pins[i].pin_name, GPIOMAXNAME - 1, "gpio%c%d", |
| 301 | device_get_unit(dev) + 'a', i); |
| 302 | sc->pins[i].pin_name[GPIOMAXNAME - 1] = '\0'; |
| 303 | |
| 304 | mtk_gpio_pin_probe(sc, i); |
| 305 | } |
| 306 | |
| 307 | if (mtk_pic_register_isrcs(sc) != 0) { |
| 308 | device_printf(dev, "could not register PIC ISRCs\n"); |
| 309 | goto fail; |
| 310 | } |
| 311 | |
| 312 | if (intr_pic_register(dev, OF_xref_from_node(node)) == NULL) { |
| 313 | device_printf(dev, "could not register PIC\n"); |
| 314 | goto fail; |
nothing calls this directly
no test coverage detected