aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/serio/altera_ps2.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/serio/altera_ps2.c')
-rw-r--r--drivers/input/serio/altera_ps2.c81
1 files changed, 24 insertions, 57 deletions
diff --git a/drivers/input/serio/altera_ps2.c b/drivers/input/serio/altera_ps2.c
index 8921c96589be..131d7826dc6b 100644
--- a/drivers/input/serio/altera_ps2.c
+++ b/drivers/input/serio/altera_ps2.c
@@ -24,9 +24,7 @@
24 24
25struct ps2if { 25struct ps2if {
26 struct serio *io; 26 struct serio *io;
27 struct resource *iomem_res;
28 void __iomem *base; 27 void __iomem *base;
29 unsigned irq;
30}; 28};
31 29
32/* 30/*
@@ -83,16 +81,34 @@ static void altera_ps2_close(struct serio *io)
83static int altera_ps2_probe(struct platform_device *pdev) 81static int altera_ps2_probe(struct platform_device *pdev)
84{ 82{
85 struct ps2if *ps2if; 83 struct ps2if *ps2if;
84 struct resource *res;
86 struct serio *serio; 85 struct serio *serio;
87 int error, irq; 86 int error, irq;
88 87
89 ps2if = kzalloc(sizeof(struct ps2if), GFP_KERNEL); 88 ps2if = devm_kzalloc(&pdev->dev, sizeof(struct ps2if), GFP_KERNEL);
90 serio = kzalloc(sizeof(struct serio), GFP_KERNEL); 89 if (!ps2if)
91 if (!ps2if || !serio) { 90 return -ENOMEM;
92 error = -ENOMEM; 91
93 goto err_free_mem; 92 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
93 ps2if->base = devm_ioremap_resource(&pdev->dev, res);
94 if (IS_ERR(ps2if->base))
95 return PTR_ERR(ps2if->base);
96
97 irq = platform_get_irq(pdev, 0);
98 if (irq < 0)
99 return -ENXIO;
100
101 error = devm_request_irq(&pdev->dev, irq, altera_ps2_rxint, 0,
102 pdev->name, ps2if);
103 if (error) {
104 dev_err(&pdev->dev, "could not request IRQ %d\n", irq);
105 return error;
94 } 106 }
95 107
108 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
109 if (!serio)
110 return -ENOMEM;
111
96 serio->id.type = SERIO_8042; 112 serio->id.type = SERIO_8042;
97 serio->write = altera_ps2_write; 113 serio->write = altera_ps2_write;
98 serio->open = altera_ps2_open; 114 serio->open = altera_ps2_open;
@@ -103,56 +119,12 @@ static int altera_ps2_probe(struct platform_device *pdev)
103 serio->dev.parent = &pdev->dev; 119 serio->dev.parent = &pdev->dev;
104 ps2if->io = serio; 120 ps2if->io = serio;
105 121
106 ps2if->iomem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 122 dev_info(&pdev->dev, "base %p, irq %d\n", ps2if->base, irq);
107 if (ps2if->iomem_res == NULL) {
108 error = -ENOENT;
109 goto err_free_mem;
110 }
111
112
113 irq = platform_get_irq(pdev, 0);
114 if (irq < 0) {
115 error = -ENXIO;
116 goto err_free_mem;
117 }
118 ps2if->irq = irq;
119
120 if (!request_mem_region(ps2if->iomem_res->start,
121 resource_size(ps2if->iomem_res), pdev->name)) {
122 error = -EBUSY;
123 goto err_free_mem;
124 }
125
126 ps2if->base = ioremap(ps2if->iomem_res->start,
127 resource_size(ps2if->iomem_res));
128 if (!ps2if->base) {
129 error = -ENOMEM;
130 goto err_free_res;
131 }
132
133 error = request_irq(ps2if->irq, altera_ps2_rxint, 0, pdev->name, ps2if);
134 if (error) {
135 dev_err(&pdev->dev, "could not allocate IRQ %d: %d\n",
136 ps2if->irq, error);
137 goto err_unmap;
138 }
139
140 dev_info(&pdev->dev, "base %p, irq %d\n", ps2if->base, ps2if->irq);
141 123
142 serio_register_port(ps2if->io); 124 serio_register_port(ps2if->io);
143 platform_set_drvdata(pdev, ps2if); 125 platform_set_drvdata(pdev, ps2if);
144 126
145 return 0; 127 return 0;
146
147 err_unmap:
148 iounmap(ps2if->base);
149 err_free_res:
150 release_mem_region(ps2if->iomem_res->start,
151 resource_size(ps2if->iomem_res));
152 err_free_mem:
153 kfree(ps2if);
154 kfree(serio);
155 return error;
156} 128}
157 129
158/* 130/*
@@ -163,11 +135,6 @@ static int altera_ps2_remove(struct platform_device *pdev)
163 struct ps2if *ps2if = platform_get_drvdata(pdev); 135 struct ps2if *ps2if = platform_get_drvdata(pdev);
164 136
165 serio_unregister_port(ps2if->io); 137 serio_unregister_port(ps2if->io);
166 free_irq(ps2if->irq, ps2if);
167 iounmap(ps2if->base);
168 release_mem_region(ps2if->iomem_res->start,
169 resource_size(ps2if->iomem_res));
170 kfree(ps2if);
171 138
172 return 0; 139 return 0;
173} 140}