1 From 9fb57f6b8920a8aceb74ceb3e171a7e5769205a5 Mon Sep 17 00:00:00 2001
2 From: Dom Cobley <popcornmix@gmail.com>
3 Date: Thu, 10 Oct 2024 17:18:39 +0100
4 Subject: [PATCH 1313/1350] Reapply "drivers: Remove downstream SenseHAT core
7 This reverts commit e6493e2d6a1f572fbb4a1d724e54715cb748b424.
9 drivers/input/joystick/Kconfig | 8 --
10 drivers/input/joystick/Makefile | 1 -
11 drivers/input/joystick/rpisense-js.c | 153 ---------------------
12 drivers/mfd/Kconfig | 8 --
13 drivers/mfd/Makefile | 1 -
14 drivers/mfd/rpisense-core.c | 163 -----------------------
15 drivers/video/fbdev/Kconfig | 4 +-
16 drivers/video/fbdev/rpisense-fb.c | 53 ++++----
17 include/linux/mfd/rpisense/core.h | 47 -------
18 include/linux/mfd/rpisense/framebuffer.h | 5 +-
19 10 files changed, 32 insertions(+), 411 deletions(-)
20 delete mode 100644 drivers/input/joystick/rpisense-js.c
21 delete mode 100644 drivers/mfd/rpisense-core.c
22 delete mode 100644 include/linux/mfd/rpisense/core.h
24 --- a/drivers/input/joystick/Kconfig
25 +++ b/drivers/input/joystick/Kconfig
26 @@ -412,12 +412,4 @@ config JOYSTICK_SENSEHAT
27 To compile this driver as a module, choose M here: the
28 module will be called sensehat_joystick.
30 -config JOYSTICK_RPISENSE
31 - tristate "Raspberry Pi Sense HAT joystick"
32 - depends on GPIOLIB && INPUT
33 - select MFD_RPISENSE_CORE
36 - This is the joystick driver for the Raspberry Pi Sense HAT
39 --- a/drivers/input/joystick/Makefile
40 +++ b/drivers/input/joystick/Makefile
41 @@ -40,4 +40,3 @@ obj-$(CONFIG_JOYSTICK_WARRIOR) += warri
42 obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o
43 obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
44 obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
45 -obj-$(CONFIG_JOYSTICK_RPISENSE) += rpisense-js.o
46 --- a/drivers/input/joystick/rpisense-js.c
50 - * Raspberry Pi Sense HAT joystick driver
51 - * http://raspberrypi.org
53 - * Copyright (C) 2015 Raspberry Pi
55 - * Author: Serge Schneider
57 - * This program is free software; you can redistribute it and/or modify it
58 - * under the terms of the GNU General Public License as published by the
59 - * Free Software Foundation; either version 2 of the License, or (at your
60 - * option) any later version.
64 -#include <linux/module.h>
66 -#include <linux/mfd/rpisense/joystick.h>
67 -#include <linux/mfd/rpisense/core.h>
69 -static struct rpisense *rpisense;
70 -static unsigned char keymap[5] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};
72 -static void keys_work_fn(struct work_struct *work)
75 - static s32 prev_keys;
76 - struct rpisense_js *rpisense_js = &rpisense->joystick;
77 - s32 keys = rpisense_reg_read(rpisense, RPISENSE_KEYS);
78 - s32 changes = keys ^ prev_keys;
81 - for (i = 0; i < 5; i++) {
83 - input_report_key(rpisense_js->keys_dev,
84 - keymap[i], keys & 1);
89 - input_sync(rpisense_js->keys_dev);
92 -static irqreturn_t keys_irq_handler(int irq, void *pdev)
94 - struct rpisense_js *rpisense_js = &rpisense->joystick;
96 - schedule_work(&rpisense_js->keys_work_s);
100 -static int rpisense_js_probe(struct platform_device *pdev)
104 - struct rpisense_js *rpisense_js;
106 - rpisense = rpisense_get_dev();
107 - rpisense_js = &rpisense->joystick;
109 - INIT_WORK(&rpisense_js->keys_work_s, keys_work_fn);
111 - rpisense_js->keys_dev = input_allocate_device();
112 - if (!rpisense_js->keys_dev) {
113 - dev_err(&pdev->dev, "Could not allocate input device.\n");
117 - rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY);
118 - for (i = 0; i < ARRAY_SIZE(keymap); i++) {
120 - rpisense_js->keys_dev->keybit);
123 - rpisense_js->keys_dev->name = "Raspberry Pi Sense HAT Joystick";
124 - rpisense_js->keys_dev->phys = "rpi-sense-joy/input0";
125 - rpisense_js->keys_dev->id.bustype = BUS_I2C;
126 - rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
127 - rpisense_js->keys_dev->keycode = keymap;
128 - rpisense_js->keys_dev->keycodesize = sizeof(unsigned char);
129 - rpisense_js->keys_dev->keycodemax = ARRAY_SIZE(keymap);
131 - ret = input_register_device(rpisense_js->keys_dev);
133 - dev_err(&pdev->dev, "Could not register input device.\n");
134 - goto err_keys_alloc;
137 - ret = gpiod_direction_input(rpisense_js->keys_desc);
139 - dev_err(&pdev->dev, "Could not set keys-int direction.\n");
143 - rpisense_js->keys_irq = gpiod_to_irq(rpisense_js->keys_desc);
144 - if (rpisense_js->keys_irq < 0) {
145 - dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n");
146 - ret = rpisense_js->keys_irq;
150 - ret = devm_request_irq(&pdev->dev, rpisense_js->keys_irq,
151 - keys_irq_handler, IRQF_TRIGGER_RISING,
152 - "keys", &pdev->dev);
154 - dev_err(&pdev->dev, "IRQ request failed.\n");
159 - input_unregister_device(rpisense_js->keys_dev);
161 - input_free_device(rpisense_js->keys_dev);
165 -static int rpisense_js_remove(struct platform_device *pdev)
167 - struct rpisense_js *rpisense_js = &rpisense->joystick;
169 - input_unregister_device(rpisense_js->keys_dev);
170 - input_free_device(rpisense_js->keys_dev);
175 -static const struct of_device_id rpisense_js_id[] = {
176 - { .compatible = "rpi,rpi-sense-js" },
179 -MODULE_DEVICE_TABLE(of, rpisense_js_id);
182 -static struct platform_device_id rpisense_js_device_id[] = {
183 - { .name = "rpi-sense-js" },
186 -MODULE_DEVICE_TABLE(platform, rpisense_js_device_id);
188 -static struct platform_driver rpisense_js_driver = {
189 - .probe = rpisense_js_probe,
190 - .remove = rpisense_js_remove,
192 - .name = "rpi-sense-js",
193 - .owner = THIS_MODULE,
197 -module_platform_driver(rpisense_js_driver);
199 -MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
200 -MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
201 -MODULE_LICENSE("GPL");
202 --- a/drivers/mfd/Kconfig
203 +++ b/drivers/mfd/Kconfig
204 @@ -11,14 +11,6 @@ config MFD_CORE
208 -config MFD_RPISENSE_CORE
209 - tristate "Raspberry Pi Sense HAT core functions"
213 - This is the core driver for the Raspberry Pi Sense HAT. This provides
214 - the necessary functions to communicate with the hardware.
217 tristate "AMD CS5535 and CS5536 southbridge core functions"
219 --- a/drivers/mfd/Makefile
220 +++ b/drivers/mfd/Makefile
221 @@ -268,7 +268,6 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o
222 obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o
223 obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o
224 obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
225 -obj-$(CONFIG_MFD_RPISENSE_CORE) += rpisense-core.o
227 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
228 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
229 --- a/drivers/mfd/rpisense-core.c
233 - * Raspberry Pi Sense HAT core driver
234 - * http://raspberrypi.org
236 - * Copyright (C) 2015 Raspberry Pi
238 - * Author: Serge Schneider
240 - * This program is free software; you can redistribute it and/or modify it
241 - * under the terms of the GNU General Public License as published by the
242 - * Free Software Foundation; either version 2 of the License, or (at your
243 - * option) any later version.
245 - * This driver is based on wm8350 implementation.
248 -#include <linux/module.h>
249 -#include <linux/moduleparam.h>
250 -#include <linux/err.h>
251 -#include <linux/init.h>
252 -#include <linux/i2c.h>
253 -#include <linux/platform_device.h>
254 -#include <linux/mfd/rpisense/core.h>
255 -#include <linux/slab.h>
257 -static struct rpisense *rpisense;
259 -static void rpisense_client_dev_register(struct rpisense *rpisense,
261 - struct platform_device **pdev)
265 - *pdev = platform_device_alloc(name, -1);
266 - if (*pdev == NULL) {
267 - dev_err(rpisense->dev, "Failed to allocate %s\n", name);
271 - (*pdev)->dev.parent = rpisense->dev;
272 - platform_set_drvdata(*pdev, rpisense);
273 - ret = platform_device_add(*pdev);
275 - dev_err(rpisense->dev, "Failed to register %s: %d\n",
277 - platform_device_put(*pdev);
282 -static int rpisense_probe(struct i2c_client *i2c)
285 - struct rpisense_js *rpisense_js;
287 - rpisense = devm_kzalloc(&i2c->dev, sizeof(struct rpisense), GFP_KERNEL);
288 - if (rpisense == NULL)
291 - i2c_set_clientdata(i2c, rpisense);
292 - rpisense->dev = &i2c->dev;
293 - rpisense->i2c_client = i2c;
295 - ret = rpisense_reg_read(rpisense, RPISENSE_WAI);
302 - ret = rpisense_reg_read(rpisense, RPISENSE_VER);
306 - dev_info(rpisense->dev,
307 - "Raspberry Pi Sense HAT firmware version %i\n", ret);
309 - rpisense_js = &rpisense->joystick;
310 - rpisense_js->keys_desc = devm_gpiod_get(&i2c->dev,
311 - "keys-int", GPIOD_IN);
312 - if (IS_ERR(rpisense_js->keys_desc)) {
313 - dev_warn(&i2c->dev, "Failed to get keys-int descriptor.\n");
314 - rpisense_js->keys_desc = gpio_to_desc(23);
315 - if (rpisense_js->keys_desc == NULL) {
316 - dev_err(&i2c->dev, "GPIO23 fallback failed.\n");
317 - return PTR_ERR(rpisense_js->keys_desc);
320 - rpisense_client_dev_register(rpisense, "rpi-sense-js",
321 - &(rpisense->joystick.pdev));
322 - rpisense_client_dev_register(rpisense, "rpi-sense-fb",
323 - &(rpisense->framebuffer.pdev));
328 -static void rpisense_remove(struct i2c_client *i2c)
330 - struct rpisense *rpisense = i2c_get_clientdata(i2c);
332 - platform_device_unregister(rpisense->joystick.pdev);
335 -struct rpisense *rpisense_get_dev(void)
339 -EXPORT_SYMBOL_GPL(rpisense_get_dev);
341 -s32 rpisense_reg_read(struct rpisense *rpisense, int reg)
343 - int ret = i2c_smbus_read_byte_data(rpisense->i2c_client, reg);
346 - dev_err(rpisense->dev, "Read from reg %d failed\n", reg);
347 - /* Due to the BCM270x I2C clock stretching bug, some values
348 - * may have MSB set. Clear it to avoid incorrect values.
352 -EXPORT_SYMBOL_GPL(rpisense_reg_read);
354 -int rpisense_block_write(struct rpisense *rpisense, const char *buf, int count)
356 - int ret = i2c_master_send(rpisense->i2c_client, buf, count);
359 - dev_err(rpisense->dev, "Block write failed\n");
362 -EXPORT_SYMBOL_GPL(rpisense_block_write);
364 -static const struct i2c_device_id rpisense_i2c_id[] = {
365 - { "rpi-sense", 0 },
368 -MODULE_DEVICE_TABLE(i2c, rpisense_i2c_id);
371 -static const struct of_device_id rpisense_core_id[] = {
372 - { .compatible = "rpi,rpi-sense" },
375 -MODULE_DEVICE_TABLE(of, rpisense_core_id);
379 -static struct i2c_driver rpisense_driver = {
381 - .name = "rpi-sense",
382 - .owner = THIS_MODULE,
384 - .probe = rpisense_probe,
385 - .remove = rpisense_remove,
386 - .id_table = rpisense_i2c_id,
389 -module_i2c_driver(rpisense_driver);
391 -MODULE_DESCRIPTION("Raspberry Pi Sense HAT core driver");
392 -MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
393 -MODULE_LICENSE("GPL");
395 --- a/drivers/video/fbdev/Kconfig
396 +++ b/drivers/video/fbdev/Kconfig
397 @@ -1967,8 +1967,8 @@ config FB_SM712
400 tristate "Raspberry Pi Sense HAT framebuffer"
402 - select MFD_RPISENSE_CORE
403 + depends on FB && I2C
404 + select MFD_SIMPLE_MFD_I2C
406 select FB_SYS_FILLRECT
407 select FB_SYS_COPYAREA
408 --- a/drivers/video/fbdev/rpisense-fb.c
409 +++ b/drivers/video/fbdev/rpisense-fb.c
411 #include <linux/delay.h>
412 #include <linux/fb.h>
413 #include <linux/init.h>
414 +#include <linux/platform_device.h>
416 #include <linux/mfd/rpisense/framebuffer.h>
417 -#include <linux/mfd/rpisense/core.h>
419 static bool lowlight;
420 module_param(lowlight, bool, 0);
421 MODULE_PARM_DESC(lowlight, "Reduce LED matrix brightness to one third");
423 -static struct rpisense *rpisense;
425 struct rpisense_fb_param {
428 @@ -116,26 +114,26 @@ static void rpisense_fb_imageblit(struct
431 static void rpisense_fb_deferred_io(struct fb_info *info,
432 - struct list_head *pagelist)
433 + struct list_head *pagelist)
437 u8 *vmem_work = rpisense_fb_param.vmem_work;
438 u16 *mem = (u16 *)rpisense_fb_param.vmem;
439 u8 *gamma = rpisense_fb_param.gamma;
440 + struct rpisense_fb *rpisense_fb = info->par;
443 for (j = 0; j < 8; j++) {
444 for (i = 0; i < 8; i++) {
445 - vmem_work[(j * 24) + i + 1] =
446 + vmem_work[(j * 24) + i] =
447 gamma[(mem[(j * 8) + i] >> 11) & 0x1F];
448 - vmem_work[(j * 24) + (i + 8) + 1] =
449 + vmem_work[(j * 24) + (i + 8)] =
450 gamma[(mem[(j * 8) + i] >> 6) & 0x1F];
451 - vmem_work[(j * 24) + (i + 16) + 1] =
452 + vmem_work[(j * 24) + (i + 16)] =
453 gamma[(mem[(j * 8) + i]) & 0x1F];
456 - rpisense_block_write(rpisense, vmem_work, 193);
457 + regmap_bulk_write(rpisense_fb->regmap, 0, vmem_work, 192);
460 static struct fb_deferred_io rpisense_fb_defio = {
461 @@ -200,8 +198,22 @@ static int rpisense_fb_probe(struct plat
463 struct rpisense_fb *rpisense_fb;
465 - rpisense = rpisense_get_dev();
466 - rpisense_fb = &rpisense->framebuffer;
467 + info = framebuffer_alloc(sizeof(*rpisense_fb), &pdev->dev);
469 + dev_err(&pdev->dev, "Could not allocate framebuffer.\n");
473 + rpisense_fb = info->par;
474 + platform_set_drvdata(pdev, rpisense_fb);
476 + rpisense_fb->pdev = pdev;
477 + rpisense_fb->regmap = dev_get_regmap(pdev->dev.parent, NULL);
478 + if (!rpisense_fb->regmap) {
479 + dev_err(&pdev->dev,
480 + "unable to get sensehat regmap");
484 rpisense_fb_param.vmem = vzalloc(rpisense_fb_param.vmemsize);
485 if (!rpisense_fb_param.vmem)
486 @@ -211,12 +223,6 @@ static int rpisense_fb_probe(struct plat
487 if (!rpisense_fb_param.vmem_work)
490 - info = framebuffer_alloc(0, &pdev->dev);
492 - dev_err(&pdev->dev, "Could not allocate framebuffer.\n");
495 - rpisense_fb->info = info;
497 rpisense_fb_fix.smem_start = (unsigned long)rpisense_fb_param.vmem;
498 rpisense_fb_fix.smem_len = rpisense_fb_param.vmemsize;
499 @@ -253,7 +259,7 @@ err_malloc:
501 static int rpisense_fb_remove(struct platform_device *pdev)
503 - struct rpisense_fb *rpisense_fb = &rpisense->framebuffer;
504 + struct rpisense_fb *rpisense_fb = platform_get_drvdata(pdev);
505 struct fb_info *info = rpisense_fb->info;
508 @@ -266,19 +272,11 @@ static int rpisense_fb_remove(struct pla
513 static const struct of_device_id rpisense_fb_id[] = {
514 - { .compatible = "rpi,rpi-sense-fb" },
515 + { .compatible = "raspberrypi,rpi-sense-fb" },
518 MODULE_DEVICE_TABLE(of, rpisense_fb_id);
521 -static struct platform_device_id rpisense_fb_device_id[] = {
522 - { .name = "rpi-sense-fb" },
525 -MODULE_DEVICE_TABLE(platform, rpisense_fb_device_id);
527 static struct platform_driver rpisense_fb_driver = {
528 .probe = rpisense_fb_probe,
529 @@ -286,6 +284,7 @@ static struct platform_driver rpisense_f
531 .name = "rpi-sense-fb",
532 .owner = THIS_MODULE,
533 + .of_match_table = rpisense_fb_id,
537 --- a/include/linux/mfd/rpisense/core.h
541 - * Raspberry Pi Sense HAT core driver
542 - * http://raspberrypi.org
544 - * Copyright (C) 2015 Raspberry Pi
546 - * Author: Serge Schneider
548 - * This program is free software; you can redistribute it and/or modify it
549 - * under the terms of the GNU General Public License as published by the
550 - * Free Software Foundation; either version 2 of the License, or (at your
551 - * option) any later version.
555 -#ifndef __LINUX_MFD_RPISENSE_CORE_H_
556 -#define __LINUX_MFD_RPISENSE_CORE_H_
558 -#include <linux/mfd/rpisense/joystick.h>
559 -#include <linux/mfd/rpisense/framebuffer.h>
564 -#define RPISENSE_FB 0x00
565 -#define RPISENSE_WAI 0xF0
566 -#define RPISENSE_VER 0xF1
567 -#define RPISENSE_KEYS 0xF2
568 -#define RPISENSE_EE_WP 0xF3
570 -#define RPISENSE_ID 's'
573 - struct device *dev;
574 - struct i2c_client *i2c_client;
576 - /* Client devices */
577 - struct rpisense_js joystick;
578 - struct rpisense_fb framebuffer;
581 -struct rpisense *rpisense_get_dev(void);
582 -s32 rpisense_reg_read(struct rpisense *rpisense, int reg);
583 -int rpisense_reg_write(struct rpisense *rpisense, int reg, u16 val);
584 -int rpisense_block_write(struct rpisense *rpisense, const char *buf, int count);
587 --- a/include/linux/mfd/rpisense/framebuffer.h
588 +++ b/include/linux/mfd/rpisense/framebuffer.h
590 #ifndef __LINUX_RPISENSE_FB_H_
591 #define __LINUX_RPISENSE_FB_H_
593 +#include <linux/regmap.h>
595 #define SENSEFB_FBIO_IOC_MAGIC 0xF1
597 #define SENSEFB_FBIOGET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 0)
602 - struct platform_device *pdev;
603 struct fb_info *info;
604 + struct platform_device *pdev;
605 + struct regmap *regmap;