| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Cobalt button interface driver. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2007-2008 Yoichi Yuasa <yuasa@linux-mips.org> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program; if not, write to the Free Software |
|---|
| 18 | | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | 6 | */ |
|---|
| 20 | | -#include <linux/input-polldev.h> |
|---|
| 7 | +#include <linux/input.h> |
|---|
| 8 | +#include <linux/io.h> |
|---|
| 21 | 9 | #include <linux/ioport.h> |
|---|
| 22 | 10 | #include <linux/module.h> |
|---|
| 23 | 11 | #include <linux/platform_device.h> |
|---|
| .. | .. |
|---|
| 39 | 27 | }; |
|---|
| 40 | 28 | |
|---|
| 41 | 29 | struct buttons_dev { |
|---|
| 42 | | - struct input_polled_dev *poll_dev; |
|---|
| 43 | 30 | unsigned short keymap[ARRAY_SIZE(cobalt_map)]; |
|---|
| 44 | 31 | int count[ARRAY_SIZE(cobalt_map)]; |
|---|
| 45 | 32 | void __iomem *reg; |
|---|
| 46 | 33 | }; |
|---|
| 47 | 34 | |
|---|
| 48 | | -static void handle_buttons(struct input_polled_dev *dev) |
|---|
| 35 | +static void handle_buttons(struct input_dev *input) |
|---|
| 49 | 36 | { |
|---|
| 50 | | - struct buttons_dev *bdev = dev->private; |
|---|
| 51 | | - struct input_dev *input = dev->input; |
|---|
| 37 | + struct buttons_dev *bdev = input_get_drvdata(input); |
|---|
| 52 | 38 | uint32_t status; |
|---|
| 53 | 39 | int i; |
|---|
| 54 | 40 | |
|---|
| .. | .. |
|---|
| 75 | 61 | static int cobalt_buttons_probe(struct platform_device *pdev) |
|---|
| 76 | 62 | { |
|---|
| 77 | 63 | struct buttons_dev *bdev; |
|---|
| 78 | | - struct input_polled_dev *poll_dev; |
|---|
| 79 | 64 | struct input_dev *input; |
|---|
| 80 | 65 | struct resource *res; |
|---|
| 81 | 66 | int error, i; |
|---|
| 82 | 67 | |
|---|
| 83 | | - bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL); |
|---|
| 84 | | - poll_dev = input_allocate_polled_device(); |
|---|
| 85 | | - if (!bdev || !poll_dev) { |
|---|
| 86 | | - error = -ENOMEM; |
|---|
| 87 | | - goto err_free_mem; |
|---|
| 88 | | - } |
|---|
| 68 | + bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL); |
|---|
| 69 | + if (!bdev) |
|---|
| 70 | + return -ENOMEM; |
|---|
| 71 | + |
|---|
| 72 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 73 | + if (!res) |
|---|
| 74 | + return -EBUSY; |
|---|
| 75 | + |
|---|
| 76 | + bdev->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
|---|
| 77 | + if (!bdev->reg) |
|---|
| 78 | + return -ENOMEM; |
|---|
| 89 | 79 | |
|---|
| 90 | 80 | memcpy(bdev->keymap, cobalt_map, sizeof(bdev->keymap)); |
|---|
| 91 | 81 | |
|---|
| 92 | | - poll_dev->private = bdev; |
|---|
| 93 | | - poll_dev->poll = handle_buttons; |
|---|
| 94 | | - poll_dev->poll_interval = BUTTONS_POLL_INTERVAL; |
|---|
| 82 | + input = devm_input_allocate_device(&pdev->dev); |
|---|
| 83 | + if (!input) |
|---|
| 84 | + return -ENOMEM; |
|---|
| 95 | 85 | |
|---|
| 96 | | - input = poll_dev->input; |
|---|
| 86 | + input_set_drvdata(input, bdev); |
|---|
| 87 | + |
|---|
| 97 | 88 | input->name = "Cobalt buttons"; |
|---|
| 98 | 89 | input->phys = "cobalt/input0"; |
|---|
| 99 | 90 | input->id.bustype = BUS_HOST; |
|---|
| 100 | | - input->dev.parent = &pdev->dev; |
|---|
| 101 | 91 | |
|---|
| 102 | 92 | input->keycode = bdev->keymap; |
|---|
| 103 | 93 | input->keycodemax = ARRAY_SIZE(bdev->keymap); |
|---|
| .. | .. |
|---|
| 109 | 99 | __set_bit(bdev->keymap[i], input->keybit); |
|---|
| 110 | 100 | __clear_bit(KEY_RESERVED, input->keybit); |
|---|
| 111 | 101 | |
|---|
| 112 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 113 | | - if (!res) { |
|---|
| 114 | | - error = -EBUSY; |
|---|
| 115 | | - goto err_free_mem; |
|---|
| 116 | | - } |
|---|
| 117 | 102 | |
|---|
| 118 | | - bdev->poll_dev = poll_dev; |
|---|
| 119 | | - bdev->reg = ioremap(res->start, resource_size(res)); |
|---|
| 120 | | - dev_set_drvdata(&pdev->dev, bdev); |
|---|
| 121 | | - |
|---|
| 122 | | - error = input_register_polled_device(poll_dev); |
|---|
| 103 | + error = input_setup_polling(input, handle_buttons); |
|---|
| 123 | 104 | if (error) |
|---|
| 124 | | - goto err_iounmap; |
|---|
| 105 | + return error; |
|---|
| 125 | 106 | |
|---|
| 126 | | - return 0; |
|---|
| 107 | + input_set_poll_interval(input, BUTTONS_POLL_INTERVAL); |
|---|
| 127 | 108 | |
|---|
| 128 | | - err_iounmap: |
|---|
| 129 | | - iounmap(bdev->reg); |
|---|
| 130 | | - err_free_mem: |
|---|
| 131 | | - input_free_polled_device(poll_dev); |
|---|
| 132 | | - kfree(bdev); |
|---|
| 133 | | - return error; |
|---|
| 134 | | -} |
|---|
| 135 | | - |
|---|
| 136 | | -static int cobalt_buttons_remove(struct platform_device *pdev) |
|---|
| 137 | | -{ |
|---|
| 138 | | - struct device *dev = &pdev->dev; |
|---|
| 139 | | - struct buttons_dev *bdev = dev_get_drvdata(dev); |
|---|
| 140 | | - |
|---|
| 141 | | - input_unregister_polled_device(bdev->poll_dev); |
|---|
| 142 | | - input_free_polled_device(bdev->poll_dev); |
|---|
| 143 | | - iounmap(bdev->reg); |
|---|
| 144 | | - kfree(bdev); |
|---|
| 109 | + error = input_register_device(input); |
|---|
| 110 | + if (error) |
|---|
| 111 | + return error; |
|---|
| 145 | 112 | |
|---|
| 146 | 113 | return 0; |
|---|
| 147 | 114 | } |
|---|
| .. | .. |
|---|
| 154 | 121 | |
|---|
| 155 | 122 | static struct platform_driver cobalt_buttons_driver = { |
|---|
| 156 | 123 | .probe = cobalt_buttons_probe, |
|---|
| 157 | | - .remove = cobalt_buttons_remove, |
|---|
| 158 | 124 | .driver = { |
|---|
| 159 | 125 | .name = "Cobalt buttons", |
|---|
| 160 | 126 | }, |
|---|