Skip to content

Commit 3c0820c

Browse files
authored
Add support for Raspberry Pi 4 (#22)
* Add support for Raspberry Pi 4 ref: RPi-Distro/raspi-gpio@80fa7d0#diff-43a345de26e51e739c07a172dd183d89 * Update README * Add PWM baseclock definition of Raspberry Pi 4 * Set Pi 2 as default * Fix gpio error on Pi 4 Error: "brcmfmac: brcmf_sdio_isr: failed backplane access." * Bump up version
1 parent db9cc31 commit 3c0820c

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,5 @@ This repository contains the code of the repository shown below.
8383
* GPL/BSD License
8484
* [mcp3204.c in Raspberry Piで学ぶARMデバイスドライバープログラミング](http://www.socym.co.jp/support/s-940#ttlDownload)
8585
* GPL v2 License
86+
* [RPi-Distro/raspi-gpio](https://github.com/RPi-Distro/raspi-gpio)
87+
* The 3-Clause BSD License

src/drivers/rtmouse.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* rtmouse.c
44
* Raspberry Pi Mouse device driver
55
*
6-
* Version: 1:1.4
6+
* Version: 1:1.5
77
*
8-
* Copyright (C) 2015-2018 RT Corporation <shop@rt-net.jp>
8+
* Copyright (C) 2015-2020 RT Corporation <shop@rt-net.jp>
99
*
1010
* This program is free software: you can redistribute it and/or modify
1111
* it under the terms of the GNU General Public License as published by
@@ -46,8 +46,12 @@
4646
#include <linux/uaccess.h>
4747
#include <linux/version.h>
4848

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
5155

5256
MODULE_AUTHOR("RT Corporation");
5357
MODULE_LICENSE("GPL");
@@ -168,10 +172,17 @@ static struct mutex lock;
168172

169173
/* --- Register Address --- */
170174
/* Base Addr */
171-
#ifdef RASPBERRYPI1
175+
#if RASPBERRYPI == 1
172176
#define RPI_REG_BASE 0x20000000
173-
#else
177+
#elif RASPBERRYPI == 2
174178
#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 */
175186
#endif
176187

177188
/* GPIO Addr */
@@ -198,9 +209,15 @@ static struct mutex lock;
198209
#define CLK_PWMDIV_INDEX 0xa4
199210

200211
/* GPIO PUPD select */
212+
#if RASPBERRYPI == 4
213+
#define GPIO_PULLNONE 0x0
214+
#define GPIO_PULLUP 0x1
215+
#define GPIO_PULLDOWN 0x2
216+
#else
201217
#define GPIO_PULLNONE 0x0
202218
#define GPIO_PULLDOWN 0x1
203219
#define GPIO_PULLUP 0x2
220+
#endif
204221

205222
/* GPIO Function */
206223
#define RPI_GPF_INPUT 0x00
@@ -236,7 +253,12 @@ static struct mutex lock;
236253
#define RPI_PWM_RNG2 0x20
237254
#define RPI_PWM_DAT2 0x24
238255

256+
257+
#if RASPBERRYPI == 4
258+
#define PWM_BASECLK 27000000
259+
#else
239260
#define PWM_BASECLK 9600000
261+
#endif
240262

241263
/* A/D Parameter */
242264
#define MCP320X_PACKET_SIZE 3
@@ -505,6 +527,12 @@ static ssize_t sw_read(struct file *filep, char __user *buf, size_t count,
505527
unsigned int pin = SW1_PIN;
506528
uint32_t mask;
507529
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
508536

509537
switch (minor) {
510538
case 0:
@@ -524,6 +552,13 @@ static ssize_t sw_read(struct file *filep, char __user *buf, size_t count,
524552
if (*f_pos > 0)
525553
return 0; /* End of file */
526554

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
527562
// プルモード (2bit)を書き込む NONE/DOWN/UP
528563
gpio_base[37] = GPIO_PULLUP & 0x3; // GPPUD
529564
// ピンにクロックを供給(前後にウェイト)
@@ -533,6 +568,7 @@ static ssize_t sw_read(struct file *filep, char __user *buf, size_t count,
533568
// プルモード・クロック状態をクリアして終了
534569
gpio_base[37] = 0;
535570
gpio_base[38] = 0;
571+
#endif
536572

537573
index = RPI_GPFSEL0_INDEX + pin / 10;
538574
mask = ~(0x7 << ((pin % 10) * 3));

0 commit comments

Comments
 (0)