3
3
* rtmouse.c
4
4
* Raspberry Pi Mouse device driver
5
5
*
6
- * Version: 1:1.4
6
+ * Version: 1:1.5
7
7
*
8
- * Copyright (C) 2015-2018 RT Corporation <shop@rt-net.jp>
8
+ * Copyright (C) 2015-2020 RT Corporation <shop@rt-net.jp>
9
9
*
10
10
* This program is free software: you can redistribute it and/or modify
11
11
* it under the terms of the GNU General Public License as published by
46
46
#include <linux/uaccess.h>
47
47
#include <linux/version.h>
48
48
49
- #define RASPBERRYPI2
50
- #undef RASPBERRYPI1
49
+ // define the Raspberry Pi version here
50
+ // Raspberry Pi 1 B/A/B+/A+: 1
51
+ // Raspberry Pi 2 B : 2
52
+ // Raspberry Pi 3 B/A+/B+ : 2
53
+ // Raspberry Pi 4 B : 4
54
+ #define RASPBERRYPI 2
51
55
52
56
MODULE_AUTHOR ("RT Corporation" );
53
57
MODULE_LICENSE ("GPL" );
@@ -168,10 +172,17 @@ static struct mutex lock;
168
172
169
173
/* --- Register Address --- */
170
174
/* Base Addr */
171
- #ifdef RASPBERRYPI1
175
+ #if RASPBERRYPI == 1
172
176
#define RPI_REG_BASE 0x20000000
173
- #else
177
+ #elif RASPBERRYPI == 2
174
178
#define RPI_REG_BASE 0x3f000000
179
+ #elif RASPBERRYPI == 4
180
+ #define RPI_REG_BASE 0xfe000000
181
+ /* 2711 has a different mechanism for pin pull-up/down/enable */
182
+ #define GPPUPPDN0 57 /* Pin pull-up/down for pins 15:0 */
183
+ #define GPPUPPDN1 58 /* Pin pull-up/down for pins 31:16 */
184
+ #define GPPUPPDN2 59 /* Pin pull-up/down for pins 47:32 */
185
+ #define GPPUPPDN3 60 /* Pin pull-up/down for pins 57:48 */
175
186
#endif
176
187
177
188
/* GPIO Addr */
@@ -198,9 +209,15 @@ static struct mutex lock;
198
209
#define CLK_PWMDIV_INDEX 0xa4
199
210
200
211
/* GPIO PUPD select */
212
+ #if RASPBERRYPI == 4
213
+ #define GPIO_PULLNONE 0x0
214
+ #define GPIO_PULLUP 0x1
215
+ #define GPIO_PULLDOWN 0x2
216
+ #else
201
217
#define GPIO_PULLNONE 0x0
202
218
#define GPIO_PULLDOWN 0x1
203
219
#define GPIO_PULLUP 0x2
220
+ #endif
204
221
205
222
/* GPIO Function */
206
223
#define RPI_GPF_INPUT 0x00
@@ -236,7 +253,12 @@ static struct mutex lock;
236
253
#define RPI_PWM_RNG2 0x20
237
254
#define RPI_PWM_DAT2 0x24
238
255
256
+
257
+ #if RASPBERRYPI == 4
258
+ #define PWM_BASECLK 27000000
259
+ #else
239
260
#define PWM_BASECLK 9600000
261
+ #endif
240
262
241
263
/* A/D Parameter */
242
264
#define MCP320X_PACKET_SIZE 3
@@ -505,6 +527,12 @@ static ssize_t sw_read(struct file *filep, char __user *buf, size_t count,
505
527
unsigned int pin = SW1_PIN ;
506
528
uint32_t mask ;
507
529
int minor = * ((int * )filep -> private_data );
530
+ #if RASPBERRYPI == 4
531
+ int pullreg = GPPUPPDN1 + (pin >> 4 ); // SW1, 2, 3 is between GPIO16-31
532
+ int pullshift = (pin & 0xf ) << 1 ;
533
+ unsigned int pullbits ;
534
+ unsigned int pull ;
535
+ #endif
508
536
509
537
switch (minor ) {
510
538
case 0 :
@@ -524,6 +552,13 @@ static ssize_t sw_read(struct file *filep, char __user *buf, size_t count,
524
552
if (* f_pos > 0 )
525
553
return 0 ; /* End of file */
526
554
555
+ #if RASPBERRYPI == 4
556
+ pull = GPIO_PULLUP ;
557
+ pullbits = * (gpio_base + pullreg );
558
+ pullbits &= ~(3 << pullshift );
559
+ pullbits |= (pull << pullshift );
560
+ * (gpio_base + pullreg ) = pullbits ;
561
+ #else
527
562
// プルモード (2bit)を書き込む NONE/DOWN/UP
528
563
gpio_base [37 ] = GPIO_PULLUP & 0x3 ; // GPPUD
529
564
// ピンにクロックを供給(前後にウェイト)
@@ -533,6 +568,7 @@ static ssize_t sw_read(struct file *filep, char __user *buf, size_t count,
533
568
// プルモード・クロック状態をクリアして終了
534
569
gpio_base [37 ] = 0 ;
535
570
gpio_base [38 ] = 0 ;
571
+ #endif
536
572
537
573
index = RPI_GPFSEL0_INDEX + pin / 10 ;
538
574
mask = ~(0x7 << ((pin % 10 ) * 3 ));
0 commit comments