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

ptp: ocp: convert serial ports to array

Simplify serial port management code by using array of ports and helpers
to get the name of the port. This change is needed to make the next
patch simplier.

Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Vadim Fedorenko and committed by
Paolo Abeni
d7875b4b 2560db6e

+57 -63
+57 -63
drivers/ptp/ptp_ocp.c
··· 316 316 #define OCP_SERIAL_LEN 6 317 317 #define OCP_SMA_NUM 4 318 318 319 + enum { 320 + PORT_GNSS, 321 + PORT_GNSS2, 322 + PORT_MAC, /* miniature atomic clock */ 323 + PORT_NMEA, 324 + 325 + __PORT_COUNT, 326 + }; 327 + 319 328 struct ptp_ocp { 320 329 struct pci_dev *pdev; 321 330 struct device dev; ··· 366 357 struct delayed_work sync_work; 367 358 int id; 368 359 int n_irqs; 369 - struct ptp_ocp_serial_port gnss_port; 370 - struct ptp_ocp_serial_port gnss2_port; 371 - struct ptp_ocp_serial_port mac_port; /* miniature atomic clock */ 372 - struct ptp_ocp_serial_port nmea_port; 360 + struct ptp_ocp_serial_port port[__PORT_COUNT]; 373 361 bool fw_loader; 374 362 u8 fw_tag; 375 363 u16 fw_version; ··· 661 655 }, 662 656 }, 663 657 { 664 - OCP_SERIAL_RESOURCE(gnss_port), 658 + OCP_SERIAL_RESOURCE(port[PORT_GNSS]), 665 659 .offset = 0x00160000 + 0x1000, .irq_vec = 3, 666 660 .extra = &(struct ptp_ocp_serial_port) { 667 661 .baud = 115200, 668 662 }, 669 663 }, 670 664 { 671 - OCP_SERIAL_RESOURCE(gnss2_port), 665 + OCP_SERIAL_RESOURCE(port[PORT_GNSS2]), 672 666 .offset = 0x00170000 + 0x1000, .irq_vec = 4, 673 667 .extra = &(struct ptp_ocp_serial_port) { 674 668 .baud = 115200, 675 669 }, 676 670 }, 677 671 { 678 - OCP_SERIAL_RESOURCE(mac_port), 672 + OCP_SERIAL_RESOURCE(port[PORT_MAC]), 679 673 .offset = 0x00180000 + 0x1000, .irq_vec = 5, 680 674 .extra = &(struct ptp_ocp_serial_port) { 681 675 .baud = 57600, 682 676 }, 683 677 }, 684 678 { 685 - OCP_SERIAL_RESOURCE(nmea_port), 679 + OCP_SERIAL_RESOURCE(port[PORT_NMEA]), 686 680 .offset = 0x00190000 + 0x1000, .irq_vec = 10, 687 681 }, 688 682 { ··· 746 740 .offset = 0x01000000, .size = 0x10000, 747 741 }, 748 742 { 749 - OCP_SERIAL_RESOURCE(gnss_port), 743 + OCP_SERIAL_RESOURCE(port[PORT_GNSS]), 750 744 .offset = 0x00160000 + 0x1000, .irq_vec = 3, 751 745 .extra = &(struct ptp_ocp_serial_port) { 752 746 .baud = 115200, ··· 845 839 }, 846 840 }, 847 841 { 848 - OCP_SERIAL_RESOURCE(mac_port), 842 + OCP_SERIAL_RESOURCE(port[PORT_MAC]), 849 843 .offset = 0x00190000, .irq_vec = 7, 850 844 .extra = &(struct ptp_ocp_serial_port) { 851 845 .baud = 9600, ··· 956 950 .offset = 0x00220000, .size = 0x1000, 957 951 }, 958 952 { 959 - OCP_SERIAL_RESOURCE(gnss_port), 953 + OCP_SERIAL_RESOURCE(port[PORT_GNSS]), 960 954 .offset = 0x00160000 + 0x1000, .irq_vec = 3, 961 955 .extra = &(struct ptp_ocp_serial_port) { 962 956 .baud = 9600, 963 957 }, 964 958 }, 965 959 { 966 - OCP_SERIAL_RESOURCE(mac_port), 960 + OCP_SERIAL_RESOURCE(port[PORT_MAC]), 967 961 .offset = 0x00180000 + 0x1000, .irq_vec = 5, 968 962 .extra = &(struct ptp_ocp_serial_port) { 969 963 .baud = 115200, ··· 1653 1647 if (idx >= ARRAY_SIZE(gnss_name)) 1654 1648 idx = ARRAY_SIZE(gnss_name) - 1; 1655 1649 return gnss_name[idx]; 1650 + } 1651 + 1652 + static const char * 1653 + ptp_ocp_tty_port_name(int idx) 1654 + { 1655 + static const char * const tty_name[] = { 1656 + "GNSS", "GNSS2", "MAC", "NMEA" 1657 + }; 1658 + return tty_name[idx]; 1656 1659 } 1657 1660 1658 1661 struct ptp_ocp_nvmem_match_info { ··· 3975 3960 bp = dev_get_drvdata(dev); 3976 3961 3977 3962 seq_printf(s, "%7s: /dev/ptp%d\n", "PTP", ptp_clock_index(bp->ptp)); 3978 - if (bp->gnss_port.line != -1) 3979 - seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS1", 3980 - bp->gnss_port.line); 3981 - if (bp->gnss2_port.line != -1) 3982 - seq_printf(s, "%7s: /dev/ttyS%d\n", "GNSS2", 3983 - bp->gnss2_port.line); 3984 - if (bp->mac_port.line != -1) 3985 - seq_printf(s, "%7s: /dev/ttyS%d\n", "MAC", bp->mac_port.line); 3986 - if (bp->nmea_port.line != -1) 3987 - seq_printf(s, "%7s: /dev/ttyS%d\n", "NMEA", bp->nmea_port.line); 3963 + for (i = 0; i < __PORT_COUNT; i++) { 3964 + if (bp->port[i].line != -1) 3965 + seq_printf(s, "%7s: /dev/ttyS%d\n", ptp_ocp_tty_port_name(i), 3966 + bp->port[i].line); 3967 + } 3988 3968 3989 3969 memset(sma_val, 0xff, sizeof(sma_val)); 3990 3970 if (bp->sma_map1) { ··· 4289 4279 static int 4290 4280 ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev) 4291 4281 { 4292 - int err; 4282 + int i, err; 4293 4283 4294 4284 mutex_lock(&ptp_ocp_lock); 4295 4285 err = idr_alloc(&ptp_ocp_idr, bp, 0, 0, GFP_KERNEL); ··· 4302 4292 4303 4293 bp->ptp_info = ptp_ocp_clock_info; 4304 4294 spin_lock_init(&bp->lock); 4305 - bp->gnss_port.line = -1; 4306 - bp->gnss2_port.line = -1; 4307 - bp->mac_port.line = -1; 4308 - bp->nmea_port.line = -1; 4295 + 4296 + for (i = 0; i < __PORT_COUNT; i++) 4297 + bp->port[i].line = -1; 4298 + 4309 4299 bp->pdev = pdev; 4310 4300 4311 4301 device_initialize(&bp->dev); ··· 4361 4351 { 4362 4352 struct pps_device *pps; 4363 4353 char buf[32]; 4354 + int i; 4364 4355 4365 - if (bp->gnss_port.line != -1) { 4366 - sprintf(buf, "ttyS%d", bp->gnss_port.line); 4367 - ptp_ocp_link_child(bp, buf, "ttyGNSS"); 4356 + for (i = 0; i < __PORT_COUNT; i++) { 4357 + if (bp->port[i].line != -1) { 4358 + sprintf(buf, "ttyS%d", bp->port[i].line); 4359 + ptp_ocp_link_child(bp, buf, ptp_ocp_tty_port_name(i)); 4360 + } 4368 4361 } 4369 - if (bp->gnss2_port.line != -1) { 4370 - sprintf(buf, "ttyS%d", bp->gnss2_port.line); 4371 - ptp_ocp_link_child(bp, buf, "ttyGNSS2"); 4372 - } 4373 - if (bp->mac_port.line != -1) { 4374 - sprintf(buf, "ttyS%d", bp->mac_port.line); 4375 - ptp_ocp_link_child(bp, buf, "ttyMAC"); 4376 - } 4377 - if (bp->nmea_port.line != -1) { 4378 - sprintf(buf, "ttyS%d", bp->nmea_port.line); 4379 - ptp_ocp_link_child(bp, buf, "ttyNMEA"); 4380 - } 4362 + 4381 4363 sprintf(buf, "ptp%d", ptp_clock_index(bp->ptp)); 4382 4364 ptp_ocp_link_child(bp, buf, "ptp"); 4383 4365 ··· 4418 4416 }; 4419 4417 struct device *dev = &bp->pdev->dev; 4420 4418 u32 reg; 4419 + int i; 4421 4420 4422 4421 ptp_ocp_phc_info(bp); 4423 4422 4424 - ptp_ocp_serial_info(dev, "GNSS", bp->gnss_port.line, 4425 - bp->gnss_port.baud); 4426 - ptp_ocp_serial_info(dev, "GNSS2", bp->gnss2_port.line, 4427 - bp->gnss2_port.baud); 4428 - ptp_ocp_serial_info(dev, "MAC", bp->mac_port.line, bp->mac_port.baud); 4429 - if (bp->nmea_out && bp->nmea_port.line != -1) { 4430 - bp->nmea_port.baud = -1; 4423 + for (i = 0; i < __PORT_COUNT; i++) { 4424 + if (i == PORT_NMEA && bp->nmea_out && bp->port[PORT_NMEA].line != -1) { 4425 + bp->port[PORT_NMEA].baud = -1; 4431 4426 4432 - reg = ioread32(&bp->nmea_out->uart_baud); 4433 - if (reg < ARRAY_SIZE(nmea_baud)) 4434 - bp->nmea_port.baud = nmea_baud[reg]; 4435 - 4436 - ptp_ocp_serial_info(dev, "NMEA", bp->nmea_port.line, 4437 - bp->nmea_port.baud); 4427 + reg = ioread32(&bp->nmea_out->uart_baud); 4428 + if (reg < ARRAY_SIZE(nmea_baud)) 4429 + bp->port[PORT_NMEA].baud = nmea_baud[reg]; 4430 + } 4431 + ptp_ocp_serial_info(dev, ptp_ocp_tty_port_name(i), bp->port[i].line, 4432 + bp->port[i].baud); 4438 4433 } 4439 4434 } 4440 4435 ··· 4472 4473 for (i = 0; i < 4; i++) 4473 4474 if (bp->signal_out[i]) 4474 4475 ptp_ocp_unregister_ext(bp->signal_out[i]); 4475 - if (bp->gnss_port.line != -1) 4476 - serial8250_unregister_port(bp->gnss_port.line); 4477 - if (bp->gnss2_port.line != -1) 4478 - serial8250_unregister_port(bp->gnss2_port.line); 4479 - if (bp->mac_port.line != -1) 4480 - serial8250_unregister_port(bp->mac_port.line); 4481 - if (bp->nmea_port.line != -1) 4482 - serial8250_unregister_port(bp->nmea_port.line); 4476 + for (i = 0; i < __PORT_COUNT; i++) 4477 + if (bp->port[i].line != -1) 4478 + serial8250_unregister_port(bp->port[i].line); 4483 4479 platform_device_unregister(bp->spi_flash); 4484 4480 platform_device_unregister(bp->i2c_ctrl); 4485 4481 if (bp->i2c_clk)