Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: ioc3: Add driver for SGI IOC3 chip

SGI IOC3 chip has integrated ethernet, keyboard and mouse interface.
It also supports connecting a SuperIO chip for serial and parallel
interfaces. IOC3 is used inside various SGI systemboards and add-on
cards with different equipped external interfaces.

Support for ethernet and serial interfaces were implemented inside
the network driver. This patchset moves out the not network related
parts to a new MFD driver, which takes care of card detection,
setup of platform devices and interrupt distribution for the subdevices.

Serial portion: Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
Network part: Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Network part: Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>

Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
Signed-off-by: Paul Burton <paulburton@kernel.org>
Cc: James Hogan <jhogan@kernel.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-serial@vger.kernel.org

authored by

Thomas Bogendoerfer and committed by
Paul Burton
0ce5ebd2 10cf8300

+894 -482
-20
arch/mips/sgi-ip27/ip27-timer.c
··· 168 168 LOCAL_HUB_S(PI_RT_PEND_B, 0); 169 169 } 170 170 } 171 - 172 - static int __init sgi_ip27_rtc_devinit(void) 173 - { 174 - struct resource res; 175 - 176 - memset(&res, 0, sizeof(res)); 177 - res.start = XPHYSADDR(KL_CONFIG_CH_CONS_INFO(master_nasid)->memory_base + 178 - IOC3_BYTEBUS_DEV0); 179 - res.end = res.start + 32767; 180 - res.flags = IORESOURCE_MEM; 181 - 182 - return IS_ERR(platform_device_register_simple("rtc-m48t35", -1, 183 - &res, 1)); 184 - } 185 - 186 - /* 187 - * kludge make this a device_initcall after ioc3 resource conflicts 188 - * are resolved 189 - */ 190 - late_initcall(sgi_ip27_rtc_devinit);
+13
drivers/mfd/Kconfig
··· 2004 2004 Select this to get support for the Supervisory Processor 2005 2005 device found on several devices in RAVE line of hardware. 2006 2006 2007 + config SGI_MFD_IOC3 2008 + tristate "SGI IOC3 core driver" 2009 + depends on PCI && MIPS && 64BIT 2010 + select MFD_CORE 2011 + help 2012 + This option enables basic support for the SGI IOC3-based 2013 + controller cards. This option does not enable any specific 2014 + functions on such a card, but provides necessary infrastructure 2015 + for other drivers to utilize. 2016 + 2017 + If you have an SGI Origin, Octane, or a PCI IOC3 card, 2018 + then say Y. Otherwise say N. 2019 + 2007 2020 endmenu 2008 2021 endif
+1
drivers/mfd/Makefile
··· 255 255 obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o 256 256 obj-$(CONFIG_MFD_STMFX) += stmfx.o 257 257 258 + obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
+669
drivers/mfd/ioc3.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * SGI IOC3 multifunction device driver 4 + * 5 + * Copyright (C) 2018, 2019 Thomas Bogendoerfer <tbogendoerfer@suse.de> 6 + * 7 + * Based on work by: 8 + * Stanislaw Skowronek <skylark@unaligned.org> 9 + * Joshua Kinard <kumba@gentoo.org> 10 + * Brent Casavant <bcasavan@sgi.com> - IOC4 master driver 11 + * Pat Gefre <pfg@sgi.com> - IOC3 serial port IRQ demuxer 12 + */ 13 + 14 + #include <linux/delay.h> 15 + #include <linux/errno.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/mfd/core.h> 18 + #include <linux/module.h> 19 + #include <linux/pci.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/platform_data/sgi-w1.h> 22 + #include <linux/rtc/ds1685.h> 23 + 24 + #include <asm/pci/bridge.h> 25 + #include <asm/sn/ioc3.h> 26 + 27 + #define IOC3_IRQ_SERIAL_A 6 28 + #define IOC3_IRQ_SERIAL_B 15 29 + #define IOC3_IRQ_KBD 22 30 + 31 + /* Bitmask for selecting which IRQs are level triggered */ 32 + #define IOC3_LVL_MASK (BIT(IOC3_IRQ_SERIAL_A) | BIT(IOC3_IRQ_SERIAL_B)) 33 + 34 + #define M48T35_REG_SIZE 32768 /* size of m48t35 registers */ 35 + 36 + /* 1.2 us latency timer (40 cycles at 33 MHz) */ 37 + #define IOC3_LATENCY 40 38 + 39 + struct ioc3_priv_data { 40 + struct irq_domain *domain; 41 + struct ioc3 __iomem *regs; 42 + struct pci_dev *pdev; 43 + int domain_irq; 44 + }; 45 + 46 + static void ioc3_irq_ack(struct irq_data *d) 47 + { 48 + struct ioc3_priv_data *ipd = irq_data_get_irq_chip_data(d); 49 + unsigned int hwirq = irqd_to_hwirq(d); 50 + 51 + writel(BIT(hwirq), &ipd->regs->sio_ir); 52 + } 53 + 54 + static void ioc3_irq_mask(struct irq_data *d) 55 + { 56 + struct ioc3_priv_data *ipd = irq_data_get_irq_chip_data(d); 57 + unsigned int hwirq = irqd_to_hwirq(d); 58 + 59 + writel(BIT(hwirq), &ipd->regs->sio_iec); 60 + } 61 + 62 + static void ioc3_irq_unmask(struct irq_data *d) 63 + { 64 + struct ioc3_priv_data *ipd = irq_data_get_irq_chip_data(d); 65 + unsigned int hwirq = irqd_to_hwirq(d); 66 + 67 + writel(BIT(hwirq), &ipd->regs->sio_ies); 68 + } 69 + 70 + static struct irq_chip ioc3_irq_chip = { 71 + .name = "IOC3", 72 + .irq_ack = ioc3_irq_ack, 73 + .irq_mask = ioc3_irq_mask, 74 + .irq_unmask = ioc3_irq_unmask, 75 + }; 76 + 77 + static int ioc3_irq_domain_map(struct irq_domain *d, unsigned int irq, 78 + irq_hw_number_t hwirq) 79 + { 80 + /* Set level IRQs for every interrupt contained in IOC3_LVL_MASK */ 81 + if (BIT(hwirq) & IOC3_LVL_MASK) 82 + irq_set_chip_and_handler(irq, &ioc3_irq_chip, handle_level_irq); 83 + else 84 + irq_set_chip_and_handler(irq, &ioc3_irq_chip, handle_edge_irq); 85 + 86 + irq_set_chip_data(irq, d->host_data); 87 + return 0; 88 + } 89 + 90 + static void ioc3_irq_domain_unmap(struct irq_domain *d, unsigned int irq) 91 + { 92 + irq_set_chip_and_handler(irq, NULL, NULL); 93 + irq_set_chip_data(irq, NULL); 94 + } 95 + 96 + static const struct irq_domain_ops ioc3_irq_domain_ops = { 97 + .map = ioc3_irq_domain_map, 98 + .unmap = ioc3_irq_domain_unmap, 99 + }; 100 + 101 + static void ioc3_irq_handler(struct irq_desc *desc) 102 + { 103 + struct irq_domain *domain = irq_desc_get_handler_data(desc); 104 + struct ioc3_priv_data *ipd = domain->host_data; 105 + struct ioc3 __iomem *regs = ipd->regs; 106 + u32 pending, mask; 107 + unsigned int irq; 108 + 109 + pending = readl(&regs->sio_ir); 110 + mask = readl(&regs->sio_ies); 111 + pending &= mask; /* Mask off not enabled interrupts */ 112 + 113 + if (pending) { 114 + irq = irq_find_mapping(domain, __ffs(pending)); 115 + if (irq) 116 + generic_handle_irq(irq); 117 + } else { 118 + spurious_interrupt(); 119 + } 120 + } 121 + 122 + /* 123 + * System boards/BaseIOs use more interrupt pins of the bridge ASIC 124 + * to which the IOC3 is connected. Since the IOC3 MFD driver 125 + * knows wiring of these extra pins, we use the map_irq function 126 + * to get interrupts activated 127 + */ 128 + static int ioc3_map_irq(struct pci_dev *pdev, int slot, int pin) 129 + { 130 + struct pci_host_bridge *hbrg = pci_find_host_bridge(pdev->bus); 131 + 132 + return hbrg->map_irq(pdev, slot, pin); 133 + } 134 + 135 + static int ioc3_irq_domain_setup(struct ioc3_priv_data *ipd, int irq) 136 + { 137 + struct irq_domain *domain; 138 + struct fwnode_handle *fn; 139 + 140 + fn = irq_domain_alloc_named_fwnode("IOC3"); 141 + if (!fn) 142 + goto err; 143 + 144 + domain = irq_domain_create_linear(fn, 24, &ioc3_irq_domain_ops, ipd); 145 + if (!domain) 146 + goto err; 147 + 148 + irq_domain_free_fwnode(fn); 149 + ipd->domain = domain; 150 + 151 + irq_set_chained_handler_and_data(irq, ioc3_irq_handler, domain); 152 + ipd->domain_irq = irq; 153 + return 0; 154 + 155 + err: 156 + dev_err(&ipd->pdev->dev, "irq domain setup failed\n"); 157 + return -ENOMEM; 158 + } 159 + 160 + static struct resource ioc3_uarta_resources[] = { 161 + DEFINE_RES_MEM(offsetof(struct ioc3, sregs.uarta), 162 + sizeof_field(struct ioc3, sregs.uarta)), 163 + DEFINE_RES_IRQ(IOC3_IRQ_SERIAL_A) 164 + }; 165 + 166 + static struct resource ioc3_uartb_resources[] = { 167 + DEFINE_RES_MEM(offsetof(struct ioc3, sregs.uartb), 168 + sizeof_field(struct ioc3, sregs.uartb)), 169 + DEFINE_RES_IRQ(IOC3_IRQ_SERIAL_B) 170 + }; 171 + 172 + static struct mfd_cell ioc3_serial_cells[] = { 173 + { 174 + .name = "ioc3-serial8250", 175 + .resources = ioc3_uarta_resources, 176 + .num_resources = ARRAY_SIZE(ioc3_uarta_resources), 177 + }, 178 + { 179 + .name = "ioc3-serial8250", 180 + .resources = ioc3_uartb_resources, 181 + .num_resources = ARRAY_SIZE(ioc3_uartb_resources), 182 + } 183 + }; 184 + 185 + static int ioc3_serial_setup(struct ioc3_priv_data *ipd) 186 + { 187 + int ret; 188 + 189 + /* Set gpio pins for RS232/RS422 mode selection */ 190 + writel(GPCR_UARTA_MODESEL | GPCR_UARTB_MODESEL, 191 + &ipd->regs->gpcr_s); 192 + /* Select RS232 mode for uart a */ 193 + writel(0, &ipd->regs->gppr[6]); 194 + /* Select RS232 mode for uart b */ 195 + writel(0, &ipd->regs->gppr[7]); 196 + 197 + /* Switch both ports to 16650 mode */ 198 + writel(readl(&ipd->regs->port_a.sscr) & ~SSCR_DMA_EN, 199 + &ipd->regs->port_a.sscr); 200 + writel(readl(&ipd->regs->port_b.sscr) & ~SSCR_DMA_EN, 201 + &ipd->regs->port_b.sscr); 202 + udelay(1000); /* Wait until mode switch is done */ 203 + 204 + ret = mfd_add_devices(&ipd->pdev->dev, PLATFORM_DEVID_AUTO, 205 + ioc3_serial_cells, ARRAY_SIZE(ioc3_serial_cells), 206 + &ipd->pdev->resource[0], 0, ipd->domain); 207 + if (ret) { 208 + dev_err(&ipd->pdev->dev, "Failed to add 16550 subdevs\n"); 209 + return ret; 210 + } 211 + 212 + return 0; 213 + } 214 + 215 + static struct resource ioc3_kbd_resources[] = { 216 + DEFINE_RES_MEM(offsetof(struct ioc3, serio), 217 + sizeof_field(struct ioc3, serio)), 218 + DEFINE_RES_IRQ(IOC3_IRQ_KBD) 219 + }; 220 + 221 + static struct mfd_cell ioc3_kbd_cells[] = { 222 + { 223 + .name = "ioc3-kbd", 224 + .resources = ioc3_kbd_resources, 225 + .num_resources = ARRAY_SIZE(ioc3_kbd_resources), 226 + } 227 + }; 228 + 229 + static int ioc3_kbd_setup(struct ioc3_priv_data *ipd) 230 + { 231 + int ret; 232 + 233 + ret = mfd_add_devices(&ipd->pdev->dev, PLATFORM_DEVID_AUTO, 234 + ioc3_kbd_cells, ARRAY_SIZE(ioc3_kbd_cells), 235 + &ipd->pdev->resource[0], 0, ipd->domain); 236 + if (ret) { 237 + dev_err(&ipd->pdev->dev, "Failed to add 16550 subdevs\n"); 238 + return ret; 239 + } 240 + 241 + return 0; 242 + } 243 + 244 + static struct resource ioc3_eth_resources[] = { 245 + DEFINE_RES_MEM(offsetof(struct ioc3, eth), 246 + sizeof_field(struct ioc3, eth)), 247 + DEFINE_RES_MEM(offsetof(struct ioc3, ssram), 248 + sizeof_field(struct ioc3, ssram)), 249 + DEFINE_RES_IRQ(0) 250 + }; 251 + 252 + static struct resource ioc3_w1_resources[] = { 253 + DEFINE_RES_MEM(offsetof(struct ioc3, mcr), 254 + sizeof_field(struct ioc3, mcr)), 255 + }; 256 + static struct sgi_w1_platform_data ioc3_w1_platform_data; 257 + 258 + static struct mfd_cell ioc3_eth_cells[] = { 259 + { 260 + .name = "ioc3-eth", 261 + .resources = ioc3_eth_resources, 262 + .num_resources = ARRAY_SIZE(ioc3_eth_resources), 263 + }, 264 + { 265 + .name = "sgi_w1", 266 + .resources = ioc3_w1_resources, 267 + .num_resources = ARRAY_SIZE(ioc3_w1_resources), 268 + .platform_data = &ioc3_w1_platform_data, 269 + .pdata_size = sizeof(ioc3_w1_platform_data), 270 + } 271 + }; 272 + 273 + static int ioc3_eth_setup(struct ioc3_priv_data *ipd) 274 + { 275 + int ret; 276 + 277 + /* Enable One-Wire bus */ 278 + writel(GPCR_MLAN_EN, &ipd->regs->gpcr_s); 279 + 280 + /* Generate unique identifier */ 281 + snprintf(ioc3_w1_platform_data.dev_id, 282 + sizeof(ioc3_w1_platform_data.dev_id), "ioc3-%012llx", 283 + ipd->pdev->resource->start); 284 + 285 + ret = mfd_add_devices(&ipd->pdev->dev, PLATFORM_DEVID_AUTO, 286 + ioc3_eth_cells, ARRAY_SIZE(ioc3_eth_cells), 287 + &ipd->pdev->resource[0], ipd->pdev->irq, NULL); 288 + if (ret) { 289 + dev_err(&ipd->pdev->dev, "Failed to add ETH/W1 subdev\n"); 290 + return ret; 291 + } 292 + 293 + return 0; 294 + } 295 + 296 + static struct resource ioc3_m48t35_resources[] = { 297 + DEFINE_RES_MEM(IOC3_BYTEBUS_DEV0, M48T35_REG_SIZE) 298 + }; 299 + 300 + static struct mfd_cell ioc3_m48t35_cells[] = { 301 + { 302 + .name = "rtc-m48t35", 303 + .resources = ioc3_m48t35_resources, 304 + .num_resources = ARRAY_SIZE(ioc3_m48t35_resources), 305 + } 306 + }; 307 + 308 + static int ioc3_m48t35_setup(struct ioc3_priv_data *ipd) 309 + { 310 + int ret; 311 + 312 + ret = mfd_add_devices(&ipd->pdev->dev, PLATFORM_DEVID_AUTO, 313 + ioc3_m48t35_cells, ARRAY_SIZE(ioc3_m48t35_cells), 314 + &ipd->pdev->resource[0], 0, ipd->domain); 315 + if (ret) 316 + dev_err(&ipd->pdev->dev, "Failed to add M48T35 subdev\n"); 317 + 318 + return ret; 319 + } 320 + 321 + static struct ds1685_rtc_platform_data ip30_rtc_platform_data = { 322 + .bcd_mode = false, 323 + .no_irq = false, 324 + .uie_unsupported = true, 325 + .access_type = ds1685_reg_indirect, 326 + }; 327 + 328 + static struct resource ioc3_rtc_ds1685_resources[] = { 329 + DEFINE_RES_MEM(IOC3_BYTEBUS_DEV1, 1), 330 + DEFINE_RES_MEM(IOC3_BYTEBUS_DEV2, 1), 331 + DEFINE_RES_IRQ(0) 332 + }; 333 + 334 + static struct mfd_cell ioc3_ds1685_cells[] = { 335 + { 336 + .name = "rtc-ds1685", 337 + .resources = ioc3_rtc_ds1685_resources, 338 + .num_resources = ARRAY_SIZE(ioc3_rtc_ds1685_resources), 339 + .platform_data = &ip30_rtc_platform_data, 340 + .pdata_size = sizeof(ip30_rtc_platform_data), 341 + .id = PLATFORM_DEVID_NONE, 342 + } 343 + }; 344 + 345 + static int ioc3_ds1685_setup(struct ioc3_priv_data *ipd) 346 + { 347 + int ret, irq; 348 + 349 + irq = ioc3_map_irq(ipd->pdev, 6, 0); 350 + 351 + ret = mfd_add_devices(&ipd->pdev->dev, 0, ioc3_ds1685_cells, 352 + ARRAY_SIZE(ioc3_ds1685_cells), 353 + &ipd->pdev->resource[0], irq, NULL); 354 + if (ret) 355 + dev_err(&ipd->pdev->dev, "Failed to add DS1685 subdev\n"); 356 + 357 + return ret; 358 + }; 359 + 360 + 361 + static struct resource ioc3_leds_resources[] = { 362 + DEFINE_RES_MEM(offsetof(struct ioc3, gppr[0]), 363 + sizeof_field(struct ioc3, gppr[0])), 364 + DEFINE_RES_MEM(offsetof(struct ioc3, gppr[1]), 365 + sizeof_field(struct ioc3, gppr[1])), 366 + }; 367 + 368 + static struct mfd_cell ioc3_led_cells[] = { 369 + { 370 + .name = "ip30-leds", 371 + .resources = ioc3_leds_resources, 372 + .num_resources = ARRAY_SIZE(ioc3_leds_resources), 373 + .id = PLATFORM_DEVID_NONE, 374 + } 375 + }; 376 + 377 + static int ioc3_led_setup(struct ioc3_priv_data *ipd) 378 + { 379 + int ret; 380 + 381 + ret = mfd_add_devices(&ipd->pdev->dev, 0, ioc3_led_cells, 382 + ARRAY_SIZE(ioc3_led_cells), 383 + &ipd->pdev->resource[0], 0, ipd->domain); 384 + if (ret) 385 + dev_err(&ipd->pdev->dev, "Failed to add LED subdev\n"); 386 + 387 + return ret; 388 + } 389 + 390 + static int ip27_baseio_setup(struct ioc3_priv_data *ipd) 391 + { 392 + int ret, io_irq; 393 + 394 + io_irq = ioc3_map_irq(ipd->pdev, PCI_SLOT(ipd->pdev->devfn), 395 + PCI_INTERRUPT_INTB); 396 + ret = ioc3_irq_domain_setup(ipd, io_irq); 397 + if (ret) 398 + return ret; 399 + 400 + ret = ioc3_eth_setup(ipd); 401 + if (ret) 402 + return ret; 403 + 404 + ret = ioc3_serial_setup(ipd); 405 + if (ret) 406 + return ret; 407 + 408 + return ioc3_m48t35_setup(ipd); 409 + } 410 + 411 + static int ip27_baseio6g_setup(struct ioc3_priv_data *ipd) 412 + { 413 + int ret, io_irq; 414 + 415 + io_irq = ioc3_map_irq(ipd->pdev, PCI_SLOT(ipd->pdev->devfn), 416 + PCI_INTERRUPT_INTB); 417 + ret = ioc3_irq_domain_setup(ipd, io_irq); 418 + if (ret) 419 + return ret; 420 + 421 + ret = ioc3_eth_setup(ipd); 422 + if (ret) 423 + return ret; 424 + 425 + ret = ioc3_serial_setup(ipd); 426 + if (ret) 427 + return ret; 428 + 429 + ret = ioc3_m48t35_setup(ipd); 430 + if (ret) 431 + return ret; 432 + 433 + return ioc3_kbd_setup(ipd); 434 + } 435 + 436 + static int ip27_mio_setup(struct ioc3_priv_data *ipd) 437 + { 438 + int ret; 439 + 440 + ret = ioc3_irq_domain_setup(ipd, ipd->pdev->irq); 441 + if (ret) 442 + return ret; 443 + 444 + ret = ioc3_serial_setup(ipd); 445 + if (ret) 446 + return ret; 447 + 448 + return ioc3_kbd_setup(ipd); 449 + } 450 + 451 + static int ip30_sysboard_setup(struct ioc3_priv_data *ipd) 452 + { 453 + int ret, io_irq; 454 + 455 + io_irq = ioc3_map_irq(ipd->pdev, PCI_SLOT(ipd->pdev->devfn), 456 + PCI_INTERRUPT_INTB); 457 + ret = ioc3_irq_domain_setup(ipd, io_irq); 458 + if (ret) 459 + return ret; 460 + 461 + ret = ioc3_eth_setup(ipd); 462 + if (ret) 463 + return ret; 464 + 465 + ret = ioc3_serial_setup(ipd); 466 + if (ret) 467 + return ret; 468 + 469 + ret = ioc3_kbd_setup(ipd); 470 + if (ret) 471 + return ret; 472 + 473 + ret = ioc3_ds1685_setup(ipd); 474 + if (ret) 475 + return ret; 476 + 477 + return ioc3_led_setup(ipd); 478 + } 479 + 480 + static int ioc3_menet_setup(struct ioc3_priv_data *ipd) 481 + { 482 + int ret, io_irq; 483 + 484 + io_irq = ioc3_map_irq(ipd->pdev, PCI_SLOT(ipd->pdev->devfn), 485 + PCI_INTERRUPT_INTB); 486 + ret = ioc3_irq_domain_setup(ipd, io_irq); 487 + if (ret) 488 + return ret; 489 + 490 + ret = ioc3_eth_setup(ipd); 491 + if (ret) 492 + return ret; 493 + 494 + return ioc3_serial_setup(ipd); 495 + } 496 + 497 + static int ioc3_menet4_setup(struct ioc3_priv_data *ipd) 498 + { 499 + return ioc3_eth_setup(ipd); 500 + } 501 + 502 + static int ioc3_cad_duo_setup(struct ioc3_priv_data *ipd) 503 + { 504 + int ret, io_irq; 505 + 506 + io_irq = ioc3_map_irq(ipd->pdev, PCI_SLOT(ipd->pdev->devfn), 507 + PCI_INTERRUPT_INTB); 508 + ret = ioc3_irq_domain_setup(ipd, io_irq); 509 + if (ret) 510 + return ret; 511 + 512 + ret = ioc3_eth_setup(ipd); 513 + if (ret) 514 + return ret; 515 + 516 + return ioc3_kbd_setup(ipd); 517 + } 518 + 519 + /* Helper macro for filling ioc3_info array */ 520 + #define IOC3_SID(_name, _sid, _setup) \ 521 + { \ 522 + .name = _name, \ 523 + .sid = PCI_VENDOR_ID_SGI | (IOC3_SUBSYS_ ## _sid << 16), \ 524 + .setup = _setup, \ 525 + } 526 + 527 + static struct { 528 + const char *name; 529 + u32 sid; 530 + int (*setup)(struct ioc3_priv_data *ipd); 531 + } ioc3_infos[] = { 532 + IOC3_SID("IP27 BaseIO6G", IP27_BASEIO6G, &ip27_baseio6g_setup), 533 + IOC3_SID("IP27 MIO", IP27_MIO, &ip27_mio_setup), 534 + IOC3_SID("IP27 BaseIO", IP27_BASEIO, &ip27_baseio_setup), 535 + IOC3_SID("IP29 System Board", IP29_SYSBOARD, &ip27_baseio6g_setup), 536 + IOC3_SID("IP30 System Board", IP30_SYSBOARD, &ip30_sysboard_setup), 537 + IOC3_SID("MENET", MENET, &ioc3_menet_setup), 538 + IOC3_SID("MENET4", MENET4, &ioc3_menet4_setup) 539 + }; 540 + #undef IOC3_SID 541 + 542 + static int ioc3_setup(struct ioc3_priv_data *ipd) 543 + { 544 + u32 sid; 545 + int i; 546 + 547 + /* Clear IRQs */ 548 + writel(~0, &ipd->regs->sio_iec); 549 + writel(~0, &ipd->regs->sio_ir); 550 + writel(0, &ipd->regs->eth.eier); 551 + writel(~0, &ipd->regs->eth.eisr); 552 + 553 + /* Read subsystem vendor id and subsystem id */ 554 + pci_read_config_dword(ipd->pdev, PCI_SUBSYSTEM_VENDOR_ID, &sid); 555 + 556 + for (i = 0; i < ARRAY_SIZE(ioc3_infos); i++) 557 + if (sid == ioc3_infos[i].sid) { 558 + pr_info("ioc3: %s\n", ioc3_infos[i].name); 559 + return ioc3_infos[i].setup(ipd); 560 + } 561 + 562 + /* Treat everything not identified by PCI subid as CAD DUO */ 563 + pr_info("ioc3: CAD DUO\n"); 564 + return ioc3_cad_duo_setup(ipd); 565 + } 566 + 567 + static int ioc3_mfd_probe(struct pci_dev *pdev, 568 + const struct pci_device_id *pci_id) 569 + { 570 + struct ioc3_priv_data *ipd; 571 + struct ioc3 __iomem *regs; 572 + int ret; 573 + 574 + ret = pci_enable_device(pdev); 575 + if (ret) 576 + return ret; 577 + 578 + pci_write_config_byte(pdev, PCI_LATENCY_TIMER, IOC3_LATENCY); 579 + pci_set_master(pdev); 580 + 581 + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 582 + if (ret) { 583 + pr_err("%s: No usable DMA configuration, aborting.\n", 584 + pci_name(pdev)); 585 + goto out_disable_device; 586 + } 587 + 588 + /* Set up per-IOC3 data */ 589 + ipd = devm_kzalloc(&pdev->dev, sizeof(struct ioc3_priv_data), 590 + GFP_KERNEL); 591 + if (!ipd) { 592 + ret = -ENOMEM; 593 + goto out_disable_device; 594 + } 595 + ipd->pdev = pdev; 596 + 597 + /* 598 + * Map all IOC3 registers. These are shared between subdevices 599 + * so the main IOC3 module manages them. 600 + */ 601 + regs = pci_ioremap_bar(pdev, 0); 602 + if (!regs) { 603 + dev_warn(&pdev->dev, "ioc3: Unable to remap PCI BAR for %s.\n", 604 + pci_name(pdev)); 605 + ret = -ENOMEM; 606 + goto out_disable_device; 607 + } 608 + ipd->regs = regs; 609 + 610 + /* Track PCI-device specific data */ 611 + pci_set_drvdata(pdev, ipd); 612 + 613 + ret = ioc3_setup(ipd); 614 + if (ret) { 615 + /* Remove all already added MFD devices */ 616 + mfd_remove_devices(&ipd->pdev->dev); 617 + if (ipd->domain) { 618 + irq_domain_remove(ipd->domain); 619 + free_irq(ipd->domain_irq, (void *)ipd); 620 + } 621 + pci_iounmap(pdev, regs); 622 + goto out_disable_device; 623 + } 624 + 625 + return 0; 626 + 627 + out_disable_device: 628 + pci_disable_device(pdev); 629 + return ret; 630 + } 631 + 632 + static void ioc3_mfd_remove(struct pci_dev *pdev) 633 + { 634 + struct ioc3_priv_data *ipd; 635 + 636 + ipd = pci_get_drvdata(pdev); 637 + 638 + /* Clear and disable all IRQs */ 639 + writel(~0, &ipd->regs->sio_iec); 640 + writel(~0, &ipd->regs->sio_ir); 641 + 642 + /* Release resources */ 643 + mfd_remove_devices(&ipd->pdev->dev); 644 + if (ipd->domain) { 645 + irq_domain_remove(ipd->domain); 646 + free_irq(ipd->domain_irq, (void *)ipd); 647 + } 648 + pci_iounmap(pdev, ipd->regs); 649 + pci_disable_device(pdev); 650 + } 651 + 652 + static struct pci_device_id ioc3_mfd_id_table[] = { 653 + { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, PCI_ANY_ID, PCI_ANY_ID }, 654 + { 0, }, 655 + }; 656 + MODULE_DEVICE_TABLE(pci, ioc3_mfd_id_table); 657 + 658 + static struct pci_driver ioc3_mfd_driver = { 659 + .name = "IOC3", 660 + .id_table = ioc3_mfd_id_table, 661 + .probe = ioc3_mfd_probe, 662 + .remove = ioc3_mfd_remove, 663 + }; 664 + 665 + module_pci_driver(ioc3_mfd_driver); 666 + 667 + MODULE_AUTHOR("Thomas Bogendoerfer <tbogendoerfer@suse.de>"); 668 + MODULE_DESCRIPTION("SGI IOC3 MFD driver"); 669 + MODULE_LICENSE("GPL v2");
+3 -2
drivers/net/ethernet/sgi/Kconfig
··· 6 6 config NET_VENDOR_SGI 7 7 bool "SGI devices" 8 8 default y 9 - depends on (PCI && SGI_IP27) || SGI_IP32 9 + depends on (PCI && SGI_MFD_IOC3) || SGI_IP32 10 10 ---help--- 11 11 If you have a network (Ethernet) card belonging to this class, say Y. 12 12 ··· 19 19 20 20 config SGI_IOC3_ETH 21 21 bool "SGI IOC3 Ethernet" 22 - depends on PCI && SGI_IP27 22 + depends on PCI && SGI_MFD_IOC3 23 + select CRC16 23 24 select CRC32 24 25 select MII 25 26 ---help---
+98 -460
drivers/net/ethernet/sgi/ioc3-eth.c
··· 14 14 * o Use prefetching for large packets. What is a good lower limit for 15 15 * prefetching? 16 16 * o Use hardware checksums. 17 - * o Convert to using a IOC3 meta driver. 18 17 * o Which PHYs might possibly be attached to the IOC3 in real live, 19 18 * which workarounds are required for them? Do we ever have Lucent's? 20 19 * o For the 2.5 branch kill the mii-tool ioctls. ··· 27 28 #include <linux/mm.h> 28 29 #include <linux/errno.h> 29 30 #include <linux/module.h> 30 - #include <linux/pci.h> 31 + #include <linux/init.h> 32 + #include <linux/crc16.h> 31 33 #include <linux/crc32.h> 32 34 #include <linux/mii.h> 33 35 #include <linux/in.h> ··· 37 37 #include <linux/tcp.h> 38 38 #include <linux/udp.h> 39 39 #include <linux/gfp.h> 40 - 41 - #ifdef CONFIG_SERIAL_8250 42 - #include <linux/serial_core.h> 43 - #include <linux/serial_8250.h> 44 - #include <linux/serial_reg.h> 45 - #endif 46 - 47 40 #include <linux/netdevice.h> 48 41 #include <linux/etherdevice.h> 49 42 #include <linux/ethtool.h> 50 43 #include <linux/skbuff.h> 51 44 #include <linux/dma-mapping.h> 45 + #include <linux/platform_device.h> 46 + #include <linux/nvmem-consumer.h> 52 47 53 48 #include <net/ip.h> 54 49 55 - #include <asm/byteorder.h> 56 - #include <asm/pgtable.h> 57 - #include <linux/uaccess.h> 58 - #include <asm/sn/types.h> 59 50 #include <asm/sn/ioc3.h> 60 51 #include <asm/pci/bridge.h> 52 + 53 + #define CRC16_INIT 0 54 + #define CRC16_VALID 0xb001 61 55 62 56 /* Number of RX buffers. This is tunable in the range of 16 <= x < 512. 63 57 * The value must be a power of two. ··· 79 85 /* Private per NIC data of the driver. */ 80 86 struct ioc3_private { 81 87 struct ioc3_ethregs *regs; 82 - struct ioc3 *all_regs; 83 88 struct device *dma_dev; 84 89 u32 *ssram; 85 90 unsigned long *rxr; /* pointer to receiver ring */ ··· 97 104 spinlock_t ioc3_lock; 98 105 struct mii_if_info mii; 99 106 100 - struct net_device *dev; 101 - struct pci_dev *pdev; 102 - 103 107 /* Members used by autonegotiation */ 104 108 struct timer_list ioc3_timer; 105 109 }; ··· 113 123 static void ioc3_free_rx_bufs(struct ioc3_private *ip); 114 124 static inline void ioc3_clean_tx_ring(struct ioc3_private *ip); 115 125 116 - static const char ioc3_str[] = "IOC3 Ethernet"; 117 126 static const struct ethtool_ops ioc3_ethtool_ops; 118 - 119 127 120 128 static inline unsigned long aligned_rx_skb_addr(unsigned long addr) 121 129 { ··· 167 179 #define ERBAR_VAL 0 168 180 #endif 169 181 170 - #define IOC3_SIZE 0x100000 171 - 172 - static inline u32 mcr_pack(u32 pulse, u32 sample) 182 + static int ioc3eth_nvmem_match(struct device *dev, const void *data) 173 183 { 174 - return (pulse << 10) | (sample << 2); 175 - } 184 + const char *name = dev_name(dev); 185 + const char *prefix = data; 186 + int prefix_len; 176 187 177 - static int nic_wait(u32 __iomem *mcr) 178 - { 179 - u32 m; 188 + prefix_len = strlen(prefix); 189 + if (strlen(name) < (prefix_len + 3)) 190 + return 0; 180 191 181 - do { 182 - m = readl(mcr); 183 - } while (!(m & 2)); 192 + if (memcmp(prefix, name, prefix_len) != 0) 193 + return 0; 184 194 185 - return m & 1; 186 - } 187 - 188 - static int nic_reset(u32 __iomem *mcr) 189 - { 190 - int presence; 191 - 192 - writel(mcr_pack(500, 65), mcr); 193 - presence = nic_wait(mcr); 194 - 195 - writel(mcr_pack(0, 500), mcr); 196 - nic_wait(mcr); 197 - 198 - return presence; 199 - } 200 - 201 - static inline int nic_read_bit(u32 __iomem *mcr) 202 - { 203 - int result; 204 - 205 - writel(mcr_pack(6, 13), mcr); 206 - result = nic_wait(mcr); 207 - writel(mcr_pack(0, 100), mcr); 208 - nic_wait(mcr); 209 - 210 - return result; 211 - } 212 - 213 - static inline void nic_write_bit(u32 __iomem *mcr, int bit) 214 - { 215 - if (bit) 216 - writel(mcr_pack(6, 110), mcr); 217 - else 218 - writel(mcr_pack(80, 30), mcr); 219 - 220 - nic_wait(mcr); 221 - } 222 - 223 - /* Read a byte from an iButton device 224 - */ 225 - static u32 nic_read_byte(u32 __iomem *mcr) 226 - { 227 - u32 result = 0; 228 - int i; 229 - 230 - for (i = 0; i < 8; i++) 231 - result = (result >> 1) | (nic_read_bit(mcr) << 7); 232 - 233 - return result; 234 - } 235 - 236 - /* Write a byte to an iButton device 237 - */ 238 - static void nic_write_byte(u32 __iomem *mcr, int byte) 239 - { 240 - int i, bit; 241 - 242 - for (i = 8; i; i--) { 243 - bit = byte & 1; 244 - byte >>= 1; 245 - 246 - nic_write_bit(mcr, bit); 247 - } 248 - } 249 - 250 - static u64 nic_find(u32 __iomem *mcr, int *last) 251 - { 252 - int a, b, index, disc; 253 - u64 address = 0; 254 - 255 - nic_reset(mcr); 256 - /* Search ROM. */ 257 - nic_write_byte(mcr, 0xf0); 258 - 259 - /* Algorithm from ``Book of iButton Standards''. */ 260 - for (index = 0, disc = 0; index < 64; index++) { 261 - a = nic_read_bit(mcr); 262 - b = nic_read_bit(mcr); 263 - 264 - if (a && b) { 265 - pr_warn("NIC search failed (not fatal).\n"); 266 - *last = 0; 267 - return 0; 268 - } 269 - 270 - if (!a && !b) { 271 - if (index == *last) { 272 - address |= 1UL << index; 273 - } else if (index > *last) { 274 - address &= ~(1UL << index); 275 - disc = index; 276 - } else if ((address & (1UL << index)) == 0) { 277 - disc = index; 278 - } 279 - nic_write_bit(mcr, address & (1UL << index)); 280 - continue; 281 - } else { 282 - if (a) 283 - address |= 1UL << index; 284 - else 285 - address &= ~(1UL << index); 286 - nic_write_bit(mcr, a); 287 - continue; 288 - } 289 - } 290 - 291 - *last = disc; 292 - 293 - return address; 294 - } 295 - 296 - static int nic_init(u32 __iomem *mcr) 297 - { 298 - const char *unknown = "unknown"; 299 - const char *type = unknown; 300 - u8 crc; 301 - u8 serial[6]; 302 - int save = 0, i; 303 - 304 - while (1) { 305 - u64 reg; 306 - 307 - reg = nic_find(mcr, &save); 308 - 309 - switch (reg & 0xff) { 310 - case 0x91: 311 - type = "DS1981U"; 312 - break; 313 - default: 314 - if (save == 0) { 315 - /* Let the caller try again. */ 316 - return -1; 317 - } 318 - continue; 319 - } 320 - 321 - nic_reset(mcr); 322 - 323 - /* Match ROM. */ 324 - nic_write_byte(mcr, 0x55); 325 - for (i = 0; i < 8; i++) 326 - nic_write_byte(mcr, (reg >> (i << 3)) & 0xff); 327 - 328 - reg >>= 8; /* Shift out type. */ 329 - for (i = 0; i < 6; i++) { 330 - serial[i] = reg & 0xff; 331 - reg >>= 8; 332 - } 333 - crc = reg & 0xff; 334 - break; 335 - } 336 - 337 - pr_info("Found %s NIC", type); 338 - if (type != unknown) 339 - pr_cont(" registration number %pM, CRC %02x", serial, crc); 340 - pr_cont(".\n"); 195 + /* found nvmem device which is attached to our ioc3 196 + * now check for one wire family code 09, 89 and 91 197 + */ 198 + if (memcmp(name + prefix_len, "09-", 3) == 0) 199 + return 1; 200 + if (memcmp(name + prefix_len, "89-", 3) == 0) 201 + return 1; 202 + if (memcmp(name + prefix_len, "91-", 3) == 0) 203 + return 1; 341 204 342 205 return 0; 343 206 } 344 207 345 - /* Read the NIC (Number-In-a-Can) device used to store the MAC address on 346 - * SN0 / SN00 nodeboards and PCI cards. 347 - */ 348 - static void ioc3_get_eaddr_nic(struct ioc3_private *ip) 208 + static int ioc3eth_get_mac_addr(struct resource *res, u8 mac_addr[6]) 349 209 { 350 - u32 __iomem *mcr = &ip->all_regs->mcr; 351 - int tries = 2; /* There may be some problem with the battery? */ 352 - u8 nic[14]; 210 + struct nvmem_device *nvmem; 211 + char prefix[24]; 212 + u8 prom[16]; 213 + int ret; 353 214 int i; 354 215 355 - writel(1 << 21, &ip->all_regs->gpcr_s); 216 + snprintf(prefix, sizeof(prefix), "ioc3-%012llx-", 217 + res->start & ~0xffff); 356 218 357 - while (tries--) { 358 - if (!nic_init(mcr)) 359 - break; 360 - udelay(500); 361 - } 219 + nvmem = nvmem_device_find(prefix, ioc3eth_nvmem_match); 220 + if (IS_ERR(nvmem)) 221 + return PTR_ERR(nvmem); 362 222 363 - if (tries < 0) { 364 - pr_err("Failed to read MAC address\n"); 365 - return; 366 - } 223 + ret = nvmem_device_read(nvmem, 0, 16, prom); 224 + nvmem_device_put(nvmem); 225 + if (ret < 0) 226 + return ret; 367 227 368 - /* Read Memory. */ 369 - nic_write_byte(mcr, 0xf0); 370 - nic_write_byte(mcr, 0x00); 371 - nic_write_byte(mcr, 0x00); 228 + /* check, if content is valid */ 229 + if (prom[0] != 0x0a || 230 + crc16(CRC16_INIT, prom, 13) != CRC16_VALID) 231 + return -EINVAL; 372 232 373 - for (i = 13; i >= 0; i--) 374 - nic[i] = nic_read_byte(mcr); 233 + for (i = 0; i < 6; i++) 234 + mac_addr[i] = prom[10 - i]; 375 235 376 - for (i = 2; i < 8; i++) 377 - ip->dev->dev_addr[i - 2] = nic[i]; 378 - } 379 - 380 - /* Ok, this is hosed by design. It's necessary to know what machine the 381 - * NIC is in in order to know how to read the NIC address. We also have 382 - * to know if it's a PCI card or a NIC in on the node board ... 383 - */ 384 - static void ioc3_get_eaddr(struct ioc3_private *ip) 385 - { 386 - ioc3_get_eaddr_nic(ip); 387 - 388 - pr_info("Ethernet address is %pM.\n", ip->dev->dev_addr); 236 + return 0; 389 237 } 390 238 391 239 static void __ioc3_set_mac_address(struct net_device *dev) ··· 594 770 u16 word; 595 771 596 772 for (i = 0; i < 32; i++) { 597 - word = ioc3_mdio_read(ip->dev, i, MII_PHYSID1); 773 + word = ioc3_mdio_read(ip->mii.dev, i, MII_PHYSID1); 598 774 599 775 if (word != 0xffff && word != 0x0000) { 600 776 found = 1; ··· 799 975 { 800 976 struct ioc3_private *ip = netdev_priv(dev); 801 977 802 - if (request_irq(dev->irq, ioc3_interrupt, IRQF_SHARED, ioc3_str, dev)) { 803 - netdev_err(dev, "Can't get irq %d\n", dev->irq); 804 - 805 - return -EAGAIN; 806 - } 807 - 808 978 ip->ehar_h = 0; 809 979 ip->ehar_l = 0; 810 980 ··· 831 1013 return 0; 832 1014 } 833 1015 834 - /* MENET cards have four IOC3 chips, which are attached to two sets of 835 - * PCI slot resources each: the primary connections are on slots 836 - * 0..3 and the secondaries are on 4..7 837 - * 838 - * All four ethernets are brought out to connectors; six serial ports 839 - * (a pair from each of the first three IOC3s) are brought out to 840 - * MiniDINs; all other subdevices are left swinging in the wind, leave 841 - * them disabled. 842 - */ 843 - 844 - static int ioc3_adjacent_is_ioc3(struct pci_dev *pdev, int slot) 845 - { 846 - struct pci_dev *dev = pci_get_slot(pdev->bus, PCI_DEVFN(slot, 0)); 847 - int ret = 0; 848 - 849 - if (dev) { 850 - if (dev->vendor == PCI_VENDOR_ID_SGI && 851 - dev->device == PCI_DEVICE_ID_SGI_IOC3) 852 - ret = 1; 853 - pci_dev_put(dev); 854 - } 855 - 856 - return ret; 857 - } 858 - 859 - static int ioc3_is_menet(struct pci_dev *pdev) 860 - { 861 - return !pdev->bus->parent && 862 - ioc3_adjacent_is_ioc3(pdev, 0) && 863 - ioc3_adjacent_is_ioc3(pdev, 1) && 864 - ioc3_adjacent_is_ioc3(pdev, 2); 865 - } 866 - 867 - #ifdef CONFIG_SERIAL_8250 868 - /* Note about serial ports and consoles: 869 - * For console output, everyone uses the IOC3 UARTA (offset 0x178) 870 - * connected to the master node (look in ip27_setup_console() and 871 - * ip27prom_console_write()). 872 - * 873 - * For serial (/dev/ttyS0 etc), we can not have hardcoded serial port 874 - * addresses on a partitioned machine. Since we currently use the ioc3 875 - * serial ports, we use dynamic serial port discovery that the serial.c 876 - * driver uses for pci/pnp ports (there is an entry for the SGI ioc3 877 - * boards in pci_boards[]). Unfortunately, UARTA's pio address is greater 878 - * than UARTB's, although UARTA on o200s has traditionally been known as 879 - * port 0. So, we just use one serial port from each ioc3 (since the 880 - * serial driver adds addresses to get to higher ports). 881 - * 882 - * The first one to do a register_console becomes the preferred console 883 - * (if there is no kernel command line console= directive). /dev/console 884 - * (ie 5, 1) is then "aliased" into the device number returned by the 885 - * "device" routine referred to in this console structure 886 - * (ip27prom_console_dev). 887 - * 888 - * Also look in ip27-pci.c:pci_fixup_ioc3() for some comments on working 889 - * around ioc3 oddities in this respect. 890 - * 891 - * The IOC3 serials use a 22MHz clock rate with an additional divider which 892 - * can be programmed in the SCR register if the DLAB bit is set. 893 - * 894 - * Register to interrupt zero because we share the interrupt with 895 - * the serial driver which we don't properly support yet. 896 - * 897 - * Can't use UPF_IOREMAP as the whole of IOC3 resources have already been 898 - * registered. 899 - */ 900 - static unsigned int ioc3_serial_in(struct uart_port *p, int offset) 901 - { 902 - return readb(p->membase + (offset ^ 3)); 903 - } 904 - 905 - static void ioc3_serial_out(struct uart_port *p, int offset, int value) 906 - { 907 - writeb(value, p->membase + (offset ^ 3)); 908 - } 909 - 910 - static void ioc3_8250_register(struct ioc3_uartregs __iomem *uart) 911 - { 912 - #define COSMISC_CONSTANT 6 913 - 914 - struct uart_8250_port port = { 915 - .port = { 916 - .irq = 0, 917 - .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, 918 - .iotype = UPIO_MEM, 919 - .regshift = 0, 920 - .uartclk = (22000000 << 1) / COSMISC_CONSTANT, 921 - 922 - .membase = (unsigned char __iomem *)uart, 923 - .mapbase = (unsigned long)uart, 924 - .serial_in = ioc3_serial_in, 925 - .serial_out = ioc3_serial_out, 926 - } 927 - }; 928 - unsigned char lcr; 929 - 930 - lcr = readb(&uart->iu_lcr); 931 - writeb(lcr | UART_LCR_DLAB, &uart->iu_lcr); 932 - writeb(COSMISC_CONSTANT, &uart->iu_scr); 933 - writeb(lcr, &uart->iu_lcr); 934 - readb(&uart->iu_lcr); 935 - serial8250_register_8250_port(&port); 936 - } 937 - 938 - static void ioc3_serial_probe(struct pci_dev *pdev, struct ioc3 *ioc3) 939 - { 940 - u32 sio_iec; 941 - 942 - /* We need to recognice and treat the fourth MENET serial as it 943 - * does not have an SuperIO chip attached to it, therefore attempting 944 - * to access it will result in bus errors. We call something an 945 - * MENET if PCI slot 0, 1, 2 and 3 of a master PCI bus all have an IOC3 946 - * in it. This is paranoid but we want to avoid blowing up on a 947 - * showhorn PCI box that happens to have 4 IOC3 cards in it so it's 948 - * not paranoid enough ... 949 - */ 950 - if (ioc3_is_menet(pdev) && PCI_SLOT(pdev->devfn) == 3) 951 - return; 952 - 953 - /* Switch IOC3 to PIO mode. It probably already was but let's be 954 - * paranoid 955 - */ 956 - writel(GPCR_UARTA_MODESEL | GPCR_UARTB_MODESEL, &ioc3->gpcr_s); 957 - readl(&ioc3->gpcr_s); 958 - writel(0, &ioc3->gppr[6]); 959 - readl(&ioc3->gppr[6]); 960 - writel(0, &ioc3->gppr[7]); 961 - readl(&ioc3->gppr[7]); 962 - writel(readl(&ioc3->port_a.sscr) & ~SSCR_DMA_EN, &ioc3->port_a.sscr); 963 - readl(&ioc3->port_a.sscr); 964 - writel(readl(&ioc3->port_b.sscr) & ~SSCR_DMA_EN, &ioc3->port_b.sscr); 965 - readl(&ioc3->port_b.sscr); 966 - /* Disable all SA/B interrupts except for SA/B_INT in SIO_IEC. */ 967 - sio_iec = readl(&ioc3->sio_iec); 968 - sio_iec &= ~(SIO_IR_SA_TX_MT | SIO_IR_SA_RX_FULL | 969 - SIO_IR_SA_RX_HIGH | SIO_IR_SA_RX_TIMER | 970 - SIO_IR_SA_DELTA_DCD | SIO_IR_SA_DELTA_CTS | 971 - SIO_IR_SA_TX_EXPLICIT | SIO_IR_SA_MEMERR); 972 - sio_iec |= SIO_IR_SA_INT; 973 - sio_iec &= ~(SIO_IR_SB_TX_MT | SIO_IR_SB_RX_FULL | 974 - SIO_IR_SB_RX_HIGH | SIO_IR_SB_RX_TIMER | 975 - SIO_IR_SB_DELTA_DCD | SIO_IR_SB_DELTA_CTS | 976 - SIO_IR_SB_TX_EXPLICIT | SIO_IR_SB_MEMERR); 977 - sio_iec |= SIO_IR_SB_INT; 978 - writel(sio_iec, &ioc3->sio_iec); 979 - writel(0, &ioc3->port_a.sscr); 980 - writel(0, &ioc3->port_b.sscr); 981 - 982 - ioc3_8250_register(&ioc3->sregs.uarta); 983 - ioc3_8250_register(&ioc3->sregs.uartb); 984 - } 985 - #endif 986 - 987 1016 static const struct net_device_ops ioc3_netdev_ops = { 988 1017 .ndo_open = ioc3_open, 989 1018 .ndo_stop = ioc3_close, ··· 843 1178 .ndo_set_mac_address = ioc3_set_mac_address, 844 1179 }; 845 1180 846 - static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1181 + static int ioc3eth_probe(struct platform_device *pdev) 847 1182 { 848 - unsigned int sw_physid1, sw_physid2; 849 - struct net_device *dev = NULL; 1183 + u32 sw_physid1, sw_physid2, vendor, model, rev; 850 1184 struct ioc3_private *ip; 851 - struct ioc3 *ioc3; 852 - unsigned long ioc3_base, ioc3_size; 853 - u32 vendor, model, rev; 1185 + struct net_device *dev; 1186 + struct resource *regs; 1187 + u8 mac_addr[6]; 854 1188 int err; 855 1189 856 - /* Configure DMA attributes. */ 857 - err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 858 - if (err) { 859 - pr_err("%s: No usable DMA configuration, aborting.\n", 860 - pci_name(pdev)); 861 - goto out; 862 - } 863 - 864 - if (pci_enable_device(pdev)) 865 - return -ENODEV; 1190 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1191 + /* get mac addr from one wire prom */ 1192 + if (ioc3eth_get_mac_addr(regs, mac_addr)) 1193 + return -EPROBE_DEFER; /* not available yet */ 866 1194 867 1195 dev = alloc_etherdev(sizeof(struct ioc3_private)); 868 - if (!dev) { 869 - err = -ENOMEM; 870 - goto out_disable; 871 - } 872 - 873 - err = pci_request_regions(pdev, "ioc3"); 874 - if (err) 875 - goto out_free; 1196 + if (!dev) 1197 + return -ENOMEM; 876 1198 877 1199 SET_NETDEV_DEV(dev, &pdev->dev); 878 1200 879 1201 ip = netdev_priv(dev); 880 - ip->dev = dev; 881 - ip->dma_dev = &pdev->dev; 882 - 883 - dev->irq = pdev->irq; 884 - 885 - ioc3_base = pci_resource_start(pdev, 0); 886 - ioc3_size = pci_resource_len(pdev, 0); 887 - ioc3 = (struct ioc3 *)ioremap(ioc3_base, ioc3_size); 888 - if (!ioc3) { 889 - pr_err("ioc3eth(%s): ioremap failed, goodbye.\n", 890 - pci_name(pdev)); 1202 + ip->dma_dev = pdev->dev.parent; 1203 + ip->regs = devm_platform_ioremap_resource(pdev, 0); 1204 + if (!ip->regs) { 891 1205 err = -ENOMEM; 892 - goto out_res; 1206 + goto out_free; 893 1207 } 894 - ip->regs = &ioc3->eth; 895 - ip->ssram = ioc3->ssram; 896 - ip->all_regs = ioc3; 897 1208 898 - #ifdef CONFIG_SERIAL_8250 899 - ioc3_serial_probe(pdev, ioc3); 900 - #endif 1209 + ip->ssram = devm_platform_ioremap_resource(pdev, 1); 1210 + if (!ip->ssram) { 1211 + err = -ENOMEM; 1212 + goto out_free; 1213 + } 1214 + 1215 + dev->irq = platform_get_irq(pdev, 0); 1216 + if (dev->irq < 0) { 1217 + err = dev->irq; 1218 + goto out_free; 1219 + } 1220 + 1221 + if (devm_request_irq(&pdev->dev, dev->irq, ioc3_interrupt, 1222 + IRQF_SHARED, "ioc3-eth", dev)) { 1223 + dev_err(&pdev->dev, "Can't get irq %d\n", dev->irq); 1224 + err = -ENODEV; 1225 + goto out_free; 1226 + } 901 1227 902 1228 spin_lock_init(&ip->ioc3_lock); 903 1229 timer_setup(&ip->ioc3_timer, ioc3_timer, 0); ··· 918 1262 919 1263 ioc3_init(dev); 920 1264 921 - ip->pdev = pdev; 922 - 923 1265 ip->mii.phy_id_mask = 0x1f; 924 1266 ip->mii.reg_num_mask = 0x1f; 925 1267 ip->mii.dev = dev; ··· 927 1273 ioc3_mii_init(ip); 928 1274 929 1275 if (ip->mii.phy_id == -1) { 930 - pr_err("ioc3-eth(%s): Didn't find a PHY, goodbye.\n", 931 - pci_name(pdev)); 1276 + netdev_err(dev, "Didn't find a PHY, goodbye.\n"); 932 1277 err = -ENODEV; 933 1278 goto out_stop; 934 1279 } 935 1280 936 1281 ioc3_mii_start(ip); 937 1282 ioc3_ssram_disc(ip); 938 - ioc3_get_eaddr(ip); 1283 + memcpy(dev->dev_addr, mac_addr, ETH_ALEN); 939 1284 940 1285 /* The IOC3-specific entries in the device structure. */ 941 1286 dev->watchdog_timeo = 5 * HZ; ··· 971 1318 if (ip->tx_ring) 972 1319 dma_free_coherent(ip->dma_dev, TX_RING_SIZE, ip->tx_ring, 973 1320 ip->txr_dma); 974 - out_res: 975 - pci_release_regions(pdev); 976 1321 out_free: 977 1322 free_netdev(dev); 978 - out_disable: 979 - /* We should call pci_disable_device(pdev); here if the IOC3 wasn't 980 - * such a weird device ... 981 - */ 982 - out: 983 1323 return err; 984 1324 } 985 1325 986 - static void ioc3_remove_one(struct pci_dev *pdev) 1326 + static int ioc3eth_remove(struct platform_device *pdev) 987 1327 { 988 - struct net_device *dev = pci_get_drvdata(pdev); 1328 + struct net_device *dev = platform_get_drvdata(pdev); 989 1329 struct ioc3_private *ip = netdev_priv(dev); 990 1330 991 1331 dma_free_coherent(ip->dma_dev, RX_RING_SIZE, ip->rxr, ip->rxr_dma); ··· 986 1340 987 1341 unregister_netdev(dev); 988 1342 del_timer_sync(&ip->ioc3_timer); 989 - 990 - iounmap(ip->all_regs); 991 - pci_release_regions(pdev); 992 1343 free_netdev(dev); 993 - /* We should call pci_disable_device(pdev); here if the IOC3 wasn't 994 - * such a weird device ... 995 - */ 1344 + 1345 + return 0; 996 1346 } 997 1347 998 - static const struct pci_device_id ioc3_pci_tbl[] = { 999 - { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, PCI_ANY_ID, PCI_ANY_ID }, 1000 - { 0 } 1001 - }; 1002 - MODULE_DEVICE_TABLE(pci, ioc3_pci_tbl); 1003 - 1004 - static struct pci_driver ioc3_driver = { 1005 - .name = "ioc3-eth", 1006 - .id_table = ioc3_pci_tbl, 1007 - .probe = ioc3_probe, 1008 - .remove = ioc3_remove_one, 1009 - }; 1010 1348 1011 1349 static netdev_tx_t ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev) 1012 1350 { ··· 1172 1542 static void ioc3_get_drvinfo(struct net_device *dev, 1173 1543 struct ethtool_drvinfo *info) 1174 1544 { 1175 - struct ioc3_private *ip = netdev_priv(dev); 1176 - 1177 1545 strlcpy(info->driver, IOC3_NAME, sizeof(info->driver)); 1178 1546 strlcpy(info->version, IOC3_VERSION, sizeof(info->version)); 1179 - strlcpy(info->bus_info, pci_name(ip->pdev), sizeof(info->bus_info)); 1547 + strlcpy(info->bus_info, pci_name(to_pci_dev(dev->dev.parent)), 1548 + sizeof(info->bus_info)); 1180 1549 } 1181 1550 1182 1551 static int ioc3_get_link_ksettings(struct net_device *dev, ··· 1287 1658 spin_unlock_irq(&ip->ioc3_lock); 1288 1659 } 1289 1660 1290 - module_pci_driver(ioc3_driver); 1661 + static struct platform_driver ioc3eth_driver = { 1662 + .probe = ioc3eth_probe, 1663 + .remove = ioc3eth_remove, 1664 + .driver = { 1665 + .name = "ioc3-eth", 1666 + } 1667 + }; 1668 + 1669 + module_platform_driver(ioc3eth_driver); 1670 + 1291 1671 MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>"); 1292 1672 MODULE_DESCRIPTION("SGI IOC3 Ethernet driver"); 1293 1673 MODULE_LICENSE("GPL");
+98
drivers/tty/serial/8250/8250_ioc3.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * SGI IOC3 8250 UART driver 4 + * 5 + * Copyright (C) 2019 Thomas Bogendoerfer <tbogendoerfer@suse.de> 6 + * 7 + * based on code Copyright (C) 2005 Stanislaw Skowronek <skylark@unaligned.org> 8 + * Copyright (C) 2014 Joshua Kinard <kumba@gentoo.org> 9 + */ 10 + 11 + #include <linux/module.h> 12 + #include <linux/errno.h> 13 + #include <linux/io.h> 14 + #include <linux/platform_device.h> 15 + 16 + #include "8250.h" 17 + 18 + #define IOC3_UARTCLK (22000000 / 3) 19 + 20 + struct ioc3_8250_data { 21 + int line; 22 + }; 23 + 24 + static unsigned int ioc3_serial_in(struct uart_port *p, int offset) 25 + { 26 + return readb(p->membase + (offset ^ 3)); 27 + } 28 + 29 + static void ioc3_serial_out(struct uart_port *p, int offset, int value) 30 + { 31 + writeb(value, p->membase + (offset ^ 3)); 32 + } 33 + 34 + static int serial8250_ioc3_probe(struct platform_device *pdev) 35 + { 36 + struct ioc3_8250_data *data; 37 + struct uart_8250_port up; 38 + struct resource *r; 39 + void __iomem *membase; 40 + int irq, line; 41 + 42 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 43 + if (!r) 44 + return -ENODEV; 45 + 46 + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 47 + if (!data) 48 + return -ENOMEM; 49 + 50 + membase = devm_ioremap_nocache(&pdev->dev, r->start, resource_size(r)); 51 + if (!membase) 52 + return -ENOMEM; 53 + 54 + irq = platform_get_irq(pdev, 0); 55 + if (irq < 0) 56 + irq = 0; /* no interrupt -> use polling */ 57 + 58 + /* Register serial ports with 8250.c */ 59 + memset(&up, 0, sizeof(struct uart_8250_port)); 60 + up.port.iotype = UPIO_MEM; 61 + up.port.uartclk = IOC3_UARTCLK; 62 + up.port.type = PORT_16550A; 63 + up.port.irq = irq; 64 + up.port.flags = (UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ); 65 + up.port.dev = &pdev->dev; 66 + up.port.membase = membase; 67 + up.port.mapbase = r->start; 68 + up.port.serial_in = ioc3_serial_in; 69 + up.port.serial_out = ioc3_serial_out; 70 + line = serial8250_register_8250_port(&up); 71 + if (line < 0) 72 + return line; 73 + 74 + platform_set_drvdata(pdev, data); 75 + return 0; 76 + } 77 + 78 + static int serial8250_ioc3_remove(struct platform_device *pdev) 79 + { 80 + struct ioc3_8250_data *data = platform_get_drvdata(pdev); 81 + 82 + serial8250_unregister_port(data->line); 83 + return 0; 84 + } 85 + 86 + static struct platform_driver serial8250_ioc3_driver = { 87 + .probe = serial8250_ioc3_probe, 88 + .remove = serial8250_ioc3_remove, 89 + .driver = { 90 + .name = "ioc3-serial8250", 91 + } 92 + }; 93 + 94 + module_platform_driver(serial8250_ioc3_driver); 95 + 96 + MODULE_AUTHOR("Thomas Bogendoerfer <tbogendoerfer@suse.de>"); 97 + MODULE_DESCRIPTION("SGI IOC3 8250 UART driver"); 98 + MODULE_LICENSE("GPL");
+11
drivers/tty/serial/8250/Kconfig
··· 371 371 port hardware found on the Emma Mobile line of processors. 372 372 If unsure, say N. 373 373 374 + config SERIAL_8250_IOC3 375 + tristate "SGI IOC3 8250 UART support" 376 + depends on SGI_MFD_IOC3 && SERIAL_8250 377 + select SERIAL_8250_EXTENDED 378 + select SERIAL_8250_SHARE_IRQ 379 + help 380 + Enable this if you have a SGI Origin or Octane machine. This module 381 + provides basic serial support by directly driving the UART chip 382 + behind the IOC3 device on those systems. Maximum baud speed is 383 + 38400bps using this driver. 384 + 374 385 config SERIAL_8250_RT288X 375 386 bool "Ralink RT288x/RT305x/RT3662/RT3883 serial port support" 376 387 depends on SERIAL_8250
+1
drivers/tty/serial/8250/Makefile
··· 28 28 obj-$(CONFIG_SERIAL_8250_MEN_MCB) += 8250_men_mcb.o 29 29 obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o 30 30 obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o 31 + obj-$(CONFIG_SERIAL_8250_IOC3) += 8250_ioc3.o 31 32 obj-$(CONFIG_SERIAL_8250_OMAP) += 8250_omap.o 32 33 obj-$(CONFIG_SERIAL_8250_LPC18XX) += 8250_lpc18xx.o 33 34 obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o