Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for kernel v 5.15.61 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions platform/plat_raspberrypi.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,79 +70,11 @@ struct spi_rfm12_board_config board_configs[NUM_RFM12_BOARDS] = {
}
};

static int
spi_rfm12_init_pinmux_settings(void);
static int
spi_rfm12_init_irq_pin_settings(rfm12_module_type_t module_type);
static int
spi_rfm12_cleanup_pinmux_settings(void);
static int
spi_rfm12_cleanup_irq_pin_settings(rfm12_module_type_t module_type);

static int
spi_rfm12_init_pinmux_settings(void)
{
// taken from https://github.com/bootc/linux/blob/rpi-i2cspi/drivers/spi/spi-bcm2708.c

#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
#define GPIO_PULL *(gpio+37)
#define GPIO_PULLCLK0 *(gpio+38)

int pin;
u32* gpio = ioremap(GPIO_MEM_BASE, SZ_16K);

// SPI0 is on gpio 7..11
for (pin = 7; pin <= 11; pin++) {
INP_GPIO(pin);
SET_GPIO_ALT(pin, 0);
}

iounmap(gpio);

return 0;
}

static int
spi_rfm12_init_irq_pin_settings(rfm12_module_type_t module_type)
{
u8 pull_mode = 0;
u32* gpio = NULL;

switch (module_type) {
case RFM12_TYPE_RF12:
pull_mode = 0x2; // pullup
break;
case RFM12_TYPE_RF69:
default:
pull_mode = 0; // no pull
break;
}

gpio = ioremap(GPIO_MEM_BASE, SZ_16K);

if (NULL != gpio) {
INP_GPIO(25);
SET_GPIO_ALT(25, 0);

GPIO_PULL = pull_mode;
udelay(500);
GPIO_PULLCLK0 = (1 << 25);
udelay(500);
GPIO_PULL = 0;
GPIO_PULLCLK0 = 0;

iounmap(gpio);
}

return 0;
}

#undef INP_GPIO
#undef SET_GPIO_ALT
#undef GPIO_PULL
#undef GPIO_PULLCLK0

static int
spi_rfm12_cleanup_pinmux_settings(void)
{
Expand Down
43 changes: 15 additions & 28 deletions platform/plat_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
#include <linux/irq.h>
#include <linux/spi/spi.h>

#if !defined(IRQF_DISABLED)
#define IRQF_DISABLED 0
#endif

struct spi_rfm12_active_board {
u16 irq;
void* irq_data;
Expand All @@ -53,8 +49,6 @@ struct spi_rfm12_active_board {

static struct spi_rfm12_active_board active_boards[NUM_RFM12_BOARDS];

static int
spi_rfm12_init_pinmux_settings(void);
static int
spi_rfm12_cleanup_pinmux_settings(void);

Expand Down Expand Up @@ -100,7 +94,6 @@ platform_irq_handled(void* identifier)
rfmXX_handle_interrupt((struct rfm12_data*)brd->irq_data);
else {
brd->state.irq_enabled = 1;
enable_irq(brd->irq);
}
}

Expand All @@ -113,20 +106,23 @@ spi_rfm12_setup_irq_pins(void)
int err, i;

for (i=0; i<NUM_RFM12_BOARDS; i++) {
err = gpio_request_one(board_configs[i].irq_pin, GPIOF_IN,
RFM12B_DRV_NAME " irq pin");
if (0 != err) {
printk(KERN_ALERT RFM12B_DRV_NAME
" : unable to obtain GPIO pin %u.\n",
board_configs[i].irq_pin
);

goto errReturn;
err = gpio_request(board_configs[i].irq_pin, RFM12B_DRV_NAME " irq pin");

if(err) {
printk("Error!\nCan not allocate GPIO %d\n", board_configs[i].irq_pin);
goto errReturn;
}

err = gpio_direction_input(board_configs[i].irq_pin);
if(err) {
printk("Error!\nCan not set GPIO %d to input!\n", board_configs[i].irq_pin);
goto errReturn;
}

active_boards[i].state.gpio_claimed = 1;

err = gpio_to_irq(board_configs[i].irq_pin);

if (err < 0) {
printk(
KERN_ALERT RFM12B_DRV_NAME
Expand Down Expand Up @@ -180,9 +176,6 @@ platform_module_init(void)
active_boards[i].idx = i;
}

err = spi_rfm12_init_pinmux_settings();
if (0 != err) goto muxFailed;

err = spi_rfm12_setup_irq_pins();
if (0 != err) goto irqFailed;

Expand All @@ -195,7 +188,7 @@ platform_module_init(void)
spi_rfm12_cleanup_irq_pins();
irqFailed:
spi_rfm12_cleanup_pinmux_settings();
muxFailed:

return err;
}

Expand Down Expand Up @@ -235,12 +228,6 @@ platform_irq_init(void* identifier, rfm12_module_type_t module_type,
if (brd->state.irq_claimed)
return -EBUSY;

err = spi_rfm12_init_irq_pin_settings(module_type);

if (err) {
return err;
}

brd->state.irq_pinmuxed = 1;
brd->module_type = module_type;

Expand All @@ -261,7 +248,7 @@ platform_irq_init(void* identifier, rfm12_module_type_t module_type,
err = request_any_context_irq(
brd->irq,
spi_rfm12_irq_handler,
irq_trigger | IRQF_DISABLED,
irq_trigger,
RFM12B_DRV_NAME,
(void*)brd
);
Expand Down Expand Up @@ -424,7 +411,7 @@ spi_rfm12_deregister_spi_devices(void)
for (i=0; i<NUM_RFM12_BOARDS; i++) {
if (NULL != active_boards[i].spi_device) {
spi_unregister_device(active_boards[i].spi_device);
spi_dev_put(active_boards[i].spi_device);
//spi_dev_put(active_boards[i].spi_device);

active_boards[i].spi_device = NULL;
}
Expand Down
Loading