GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — serial: dz: Convert to use a platform device · Corentinrhr/BPI-Router-Linux-L4S@6f59646

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • arch/mips/dec
    • platform.c
  • drivers/tty/serial
    • dz.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎arch/mips/dec/platform.c‎

Copy file name to clipboardExpand all lines: arch/mips/dec/platform.c
+54-1Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
#include <linux/mc146818rtc.h>
1111
#include <linux/platform_device.h>
1212

13+
#include <asm/bootinfo.h>
14+
15+
#include <asm/dec/interrupts.h>
16+
#include <asm/dec/kn01.h>
17+
#include <asm/dec/kn02.h>
18+
#include <asm/dec/system.h>
19+
1320
static struct resource dec_rtc_resources[] = {
1421
{
1522
.name = "rtc",
@@ -30,11 +37,57 @@ static struct platform_device dec_rtc_device = {
3037
.num_resources = ARRAY_SIZE(dec_rtc_resources),
3138
};
3239

40+
static struct resource dec_dz_resources[] = {
41+
{ .name = "dz", .flags = IORESOURCE_MEM, },
42+
{ .name = "dz", .flags = IORESOURCE_IRQ, },
43+
};
44+
45+
static struct platform_device dec_dz_device = {
46+
.name = "dz",
47+
.id = PLATFORM_DEVID_NONE,
48+
.resource = dec_dz_resources,
49+
.num_resources = ARRAY_SIZE(dec_dz_resources),
50+
};
51+
52+
static struct platform_device *dec_dz_devices[] __initdata = {
53+
&dec_dz_device,
54+
};
55+
3356
static int __init dec_add_devices(void)
3457
{
58+
int ret1, ret2;
59+
int num_dz;
60+
int irq, i;
61+
3562
dec_rtc_resources[0].start = RTC_PORT(0);
3663
dec_rtc_resources[0].end = RTC_PORT(0) + dec_kn_slot_size - 1;
37-
return platform_device_register(&dec_rtc_device);
64+
65+
i = 0;
66+
irq = dec_interrupt[DEC_IRQ_DZ11];
67+
if (IS_ENABLED(CONFIG_32BIT) && irq >= 0) {
68+
resource_size_t base;
69+
70+
switch (mips_machtype) {
71+
case MACH_DS23100:
72+
case MACH_DS5100:
73+
base = dec_kn_slot_base + KN01_DZ11;
74+
break;
75+
default:
76+
base = dec_kn_slot_base + KN02_DZ11;
77+
break;
78+
}
79+
dec_dz_device.resource[0].start = base;
80+
dec_dz_device.resource[0].end = base + dec_kn_slot_size - 1;
81+
dec_dz_device.resource[1].start = irq;
82+
dec_dz_device.resource[1].end = irq;
83+
i++;
84+
}
85+
num_dz = i;
86+
87+
ret1 = platform_device_register(&dec_rtc_device);
88+
ret2 = IS_ENABLED(CONFIG_32BIT) ?
89+
platform_add_devices(dec_dz_devices, num_dz) : 0;
90+
return ret1 ? ret1 : ret2;
3891
}
3992

4093
device_initcall(dec_add_devices);
Collapse file

‎drivers/tty/serial/dz.c‎

Copy file name to clipboardExpand all lines: drivers/tty/serial/dz.c
+56-60Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/kernel.h>
4141
#include <linux/major.h>
4242
#include <linux/module.h>
43+
#include <linux/platform_device.h>
4344
#include <linux/serial.h>
4445
#include <linux/serial_core.h>
4546
#include <linux/sysrq.h>
@@ -48,14 +49,6 @@
4849

4950
#include <linux/atomic.h>
5051
#include <linux/io.h>
51-
#include <asm/bootinfo.h>
52-
53-
#include <asm/dec/interrupts.h>
54-
#include <asm/dec/kn01.h>
55-
#include <asm/dec/kn02.h>
56-
#include <asm/dec/machtype.h>
57-
#include <asm/dec/prom.h>
58-
#include <asm/dec/system.h>
5952

6053
#include "dz.h"
6154

@@ -65,7 +58,9 @@ MODULE_LICENSE("GPL");
6558

6659

6760
static char dz_name[] __initdata = "DECstation DZ serial driver version ";
68-
static char dz_version[] __initdata = "1.04";
61+
static char dz_version[] __initdata = "1.05";
62+
63+
#define DZ_IO_SIZE 0x20 /* IOMEM space size. */
6964

7065
struct dz_port {
7166
struct dz_mux *mux;
@@ -81,6 +76,7 @@ struct dz_mux {
8176
};
8277

8378
static struct dz_mux dz_mux;
79+
static struct uart_driver dz_reg;
8480

8581
static inline struct dz_port *to_dport(struct uart_port *uport)
8682
{
@@ -564,7 +560,7 @@ static void dz_reset(struct dz_port *dport)
564560
iob();
565561
udelay(2); /* 1.4us TRDY recovery. */
566562
}
567-
udelay(1200); /* Transmitter drain. */
563+
fsleep(1200); /* Transmitter drain. */
568564
}
569565

570566
dz_out(dport, DZ_CSR, DZ_CLR);
@@ -681,14 +677,13 @@ static void dz_release_port(struct uart_port *uport)
681677

682678
map_guard = atomic_add_return(-1, &mux->map_guard);
683679
if (!map_guard)
684-
release_mem_region(uport->mapbase, dec_kn_slot_size);
680+
release_mem_region(uport->mapbase, DZ_IO_SIZE);
685681
}
686682

687683
static int dz_map_port(struct uart_port *uport)
688684
{
689685
if (!uport->membase)
690-
uport->membase = ioremap(uport->mapbase,
691-
dec_kn_slot_size);
686+
uport->membase = ioremap(uport->mapbase, DZ_IO_SIZE);
692687
if (!uport->membase) {
693688
printk(KERN_ERR "dz: Cannot map MMIO\n");
694689
return -ENOMEM;
@@ -704,8 +699,7 @@ static int dz_request_port(struct uart_port *uport)
704699

705700
map_guard = atomic_add_return(1, &mux->map_guard);
706701
if (map_guard == 1) {
707-
if (!request_mem_region(uport->mapbase, dec_kn_slot_size,
708-
"dz")) {
702+
if (!request_mem_region(uport->mapbase, DZ_IO_SIZE, "dz")) {
709703
atomic_add(-1, &mux->map_guard);
710704
printk(KERN_ERR
711705
"dz: Unable to reserve MMIO resource\n");
@@ -716,7 +710,7 @@ static int dz_request_port(struct uart_port *uport)
716710
if (ret) {
717711
map_guard = atomic_add_return(-1, &mux->map_guard);
718712
if (!map_guard)
719-
release_mem_region(uport->mapbase, dec_kn_slot_size);
713+
release_mem_region(uport->mapbase, DZ_IO_SIZE);
720714
return ret;
721715
}
722716
return 0;
@@ -768,35 +762,49 @@ static const struct uart_ops dz_ops = {
768762
.verify_port = dz_verify_port,
769763
};
770764

771-
static void __init dz_init_ports(void)
765+
static int __init dz_probe(struct platform_device *pdev)
772766
{
773-
static int first = 1;
774-
unsigned long base;
767+
struct resource *mem_resource, *irq_resource;
775768
int line;
776769

777-
if (!first)
778-
return;
779-
first = 0;
780-
781-
if (mips_machtype == MACH_DS23100 || mips_machtype == MACH_DS5100)
782-
base = dec_kn_slot_base + KN01_DZ11;
783-
else
784-
base = dec_kn_slot_base + KN02_DZ11;
770+
mem_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
771+
irq_resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
772+
if (!mem_resource || !irq_resource)
773+
return -ENODEV;
785774

786775
for (line = 0; line < DZ_NB_PORT; line++) {
787776
struct dz_port *dport = &dz_mux.dport[line];
788777
struct uart_port *uport = &dport->port;
789778

790779
dport->mux = &dz_mux;
791780

792-
uport->irq = dec_interrupt[DEC_IRQ_DZ11];
781+
uport->dev = &pdev->dev;
782+
uport->irq = irq_resource->start;
793783
uport->fifosize = 1;
794784
uport->iotype = UPIO_MEM;
795785
uport->flags = UPF_BOOT_AUTOCONF;
796786
uport->ops = &dz_ops;
797787
uport->line = line;
798-
uport->mapbase = base;
788+
uport->mapbase = mem_resource->start;
799789
uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_DZ_CONSOLE);
790+
791+
if (uart_add_one_port(&dz_reg, uport))
792+
uport->dev = NULL;
793+
}
794+
795+
return 0;
796+
}
797+
798+
static void __exit dz_remove(struct platform_device *pdev)
799+
{
800+
int line;
801+
802+
for (line = DZ_NB_PORT - 1; line >= 0; line--) {
803+
struct dz_port *dport = &dz_mux.dport[line];
804+
struct uart_port *uport = &dport->port;
805+
806+
if (uport->dev)
807+
uart_remove_one_port(&dz_reg, uport);
800808
}
801809
}
802810

@@ -879,21 +887,14 @@ static int __init dz_console_setup(struct console *co, char *options)
879887
int bits = 8;
880888
int parity = 'n';
881889
int flow = 'n';
882-
int ret;
883-
884-
ret = dz_map_port(uport);
885-
if (ret)
886-
return ret;
887-
888-
dz_reset(dport);
889890

891+
if (!dport->mux)
892+
return -ENODEV;
890893
if (options)
891894
uart_parse_options(options, &baud, &parity, &bits, &flow);
892-
893-
return uart_set_options(&dport->port, co, baud, parity, bits, flow);
895+
return uart_set_options(uport, co, baud, parity, bits, flow);
894896
}
895897

896-
static struct uart_driver dz_reg;
897898
static struct console dz_console = {
898899
.name = "ttyS",
899900
.write = dz_console_print,
@@ -904,18 +905,6 @@ static struct console dz_console = {
904905
.data = &dz_reg,
905906
};
906907

907-
static int __init dz_serial_console_init(void)
908-
{
909-
if (!IOASIC) {
910-
dz_init_ports();
911-
register_console(&dz_console);
912-
return 0;
913-
} else
914-
return -ENXIO;
915-
}
916-
917-
console_initcall(dz_serial_console_init);
918-
919908
#define SERIAL_DZ_CONSOLE &dz_console
920909
#else
921910
#define SERIAL_DZ_CONSOLE NULL
@@ -931,25 +920,32 @@ static struct uart_driver dz_reg = {
931920
.cons = SERIAL_DZ_CONSOLE,
932921
};
933922

923+
static struct platform_driver dz_driver = {
924+
.remove = __exit_p(dz_remove),
925+
.driver = { .name = "dz" },
926+
};
927+
934928
static int __init dz_init(void)
935929
{
936-
int ret, i;
937-
938-
if (IOASIC)
939-
return -ENXIO;
930+
int ret;
940931

941932
printk("%s%s\n", dz_name, dz_version);
942933

943-
dz_init_ports();
944-
945934
ret = uart_register_driver(&dz_reg);
946935
if (ret)
947936
return ret;
937+
ret = platform_driver_probe(&dz_driver, dz_probe);
938+
if (ret)
939+
uart_unregister_driver(&dz_reg);
948940

949-
for (i = 0; i < DZ_NB_PORT; i++)
950-
uart_add_one_port(&dz_reg, &dz_mux.dport[i].port);
941+
return ret;
942+
}
951943

952-
return 0;
944+
static void __exit dz_exit(void)
945+
{
946+
platform_driver_unregister(&dz_driver);
947+
uart_unregister_driver(&dz_reg);
953948
}
954949

955950
module_init(dz_init);
951+
module_exit(dz_exit);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.