mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-16 09:13:55 +08:00
Merge branch 'acpi-enumeration'
* acpi-enumeration: spi / ACPI: add ACPI enumeration support gpio / ACPI: add ACPI support
This commit is contained in:
commit
d9ba1025a4
@ -49,6 +49,10 @@ config OF_GPIO
|
||||
def_bool y
|
||||
depends on OF
|
||||
|
||||
config GPIO_ACPI
|
||||
def_bool y
|
||||
depends on ACPI
|
||||
|
||||
config DEBUG_GPIO
|
||||
bool "Debug GPIO calls"
|
||||
depends on DEBUG_KERNEL
|
||||
|
@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
|
||||
|
||||
obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o
|
||||
obj-$(CONFIG_OF_GPIO) += gpiolib-of.o
|
||||
obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o
|
||||
|
||||
# Device drivers. Generally keep list sorted alphabetically
|
||||
obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
|
||||
|
54
drivers/gpio/gpiolib-acpi.c
Normal file
54
drivers/gpio/gpiolib-acpi.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ACPI helpers for GPIO API
|
||||
*
|
||||
* Copyright (C) 2012, Intel Corporation
|
||||
* Authors: Mathias Nyman <mathias.nyman@linux.intel.com>
|
||||
* Mika Westerberg <mika.westerberg@linux.intel.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/acpi_gpio.h>
|
||||
#include <linux/acpi.h>
|
||||
|
||||
static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
|
||||
{
|
||||
if (!gc->dev)
|
||||
return false;
|
||||
|
||||
return ACPI_HANDLE(gc->dev) == data;
|
||||
}
|
||||
|
||||
/**
|
||||
* acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API
|
||||
* @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
|
||||
* @pin: ACPI GPIO pin number (0-based, controller-relative)
|
||||
*
|
||||
* Returns GPIO number to use with Linux generic GPIO API, or errno error value
|
||||
*/
|
||||
|
||||
int acpi_get_gpio(char *path, int pin)
|
||||
{
|
||||
struct gpio_chip *chip;
|
||||
acpi_handle handle;
|
||||
acpi_status status;
|
||||
|
||||
status = acpi_get_handle(NULL, path, &handle);
|
||||
if (ACPI_FAILURE(status))
|
||||
return -ENODEV;
|
||||
|
||||
chip = gpiochip_find(handle, acpi_gpiochip_find);
|
||||
if (!chip)
|
||||
return -ENODEV;
|
||||
|
||||
if (!gpio_is_valid(chip->base + pin))
|
||||
return -EINVAL;
|
||||
|
||||
return chip->base + pin;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(acpi_get_gpio);
|
@ -35,6 +35,8 @@
|
||||
#include <linux/sched.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/ioport.h>
|
||||
#include <linux/acpi.h>
|
||||
|
||||
static void spidev_release(struct device *dev)
|
||||
{
|
||||
@ -93,6 +95,10 @@ static int spi_match_device(struct device *dev, struct device_driver *drv)
|
||||
if (of_driver_match_device(dev, drv))
|
||||
return 1;
|
||||
|
||||
/* Then try ACPI */
|
||||
if (acpi_driver_match_device(dev, drv))
|
||||
return 1;
|
||||
|
||||
if (sdrv->id_table)
|
||||
return !!spi_match_id(sdrv->id_table, spi);
|
||||
|
||||
@ -888,6 +894,100 @@ static void of_register_spi_devices(struct spi_master *master)
|
||||
static void of_register_spi_devices(struct spi_master *master) { }
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ACPI
|
||||
static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
|
||||
{
|
||||
struct spi_device *spi = data;
|
||||
|
||||
if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
|
||||
struct acpi_resource_spi_serialbus *sb;
|
||||
|
||||
sb = &ares->data.spi_serial_bus;
|
||||
if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_SPI) {
|
||||
spi->chip_select = sb->device_selection;
|
||||
spi->max_speed_hz = sb->connection_speed;
|
||||
|
||||
if (sb->clock_phase == ACPI_SPI_SECOND_PHASE)
|
||||
spi->mode |= SPI_CPHA;
|
||||
if (sb->clock_polarity == ACPI_SPI_START_HIGH)
|
||||
spi->mode |= SPI_CPOL;
|
||||
if (sb->device_polarity == ACPI_SPI_ACTIVE_HIGH)
|
||||
spi->mode |= SPI_CS_HIGH;
|
||||
}
|
||||
} else if (spi->irq < 0) {
|
||||
struct resource r;
|
||||
|
||||
if (acpi_dev_resource_interrupt(ares, 0, &r))
|
||||
spi->irq = r.start;
|
||||
}
|
||||
|
||||
/* Always tell the ACPI core to skip this resource */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level,
|
||||
void *data, void **return_value)
|
||||
{
|
||||
struct spi_master *master = data;
|
||||
struct list_head resource_list;
|
||||
struct acpi_device *adev;
|
||||
struct spi_device *spi;
|
||||
int ret;
|
||||
|
||||
if (acpi_bus_get_device(handle, &adev))
|
||||
return AE_OK;
|
||||
if (acpi_bus_get_status(adev) || !adev->status.present)
|
||||
return AE_OK;
|
||||
|
||||
spi = spi_alloc_device(master);
|
||||
if (!spi) {
|
||||
dev_err(&master->dev, "failed to allocate SPI device for %s\n",
|
||||
dev_name(&adev->dev));
|
||||
return AE_NO_MEMORY;
|
||||
}
|
||||
|
||||
ACPI_HANDLE_SET(&spi->dev, handle);
|
||||
spi->irq = -1;
|
||||
|
||||
INIT_LIST_HEAD(&resource_list);
|
||||
ret = acpi_dev_get_resources(adev, &resource_list,
|
||||
acpi_spi_add_resource, spi);
|
||||
acpi_dev_free_resource_list(&resource_list);
|
||||
|
||||
if (ret < 0 || !spi->max_speed_hz) {
|
||||
spi_dev_put(spi);
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
strlcpy(spi->modalias, dev_name(&adev->dev), sizeof(spi->modalias));
|
||||
if (spi_add_device(spi)) {
|
||||
dev_err(&master->dev, "failed to add SPI device %s from ACPI\n",
|
||||
dev_name(&adev->dev));
|
||||
spi_dev_put(spi);
|
||||
}
|
||||
|
||||
return AE_OK;
|
||||
}
|
||||
|
||||
static void acpi_register_spi_devices(struct spi_master *master)
|
||||
{
|
||||
acpi_status status;
|
||||
acpi_handle handle;
|
||||
|
||||
handle = ACPI_HANDLE(&master->dev);
|
||||
if (!handle)
|
||||
return;
|
||||
|
||||
status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
|
||||
acpi_spi_add_device, NULL,
|
||||
master, NULL);
|
||||
if (ACPI_FAILURE(status))
|
||||
dev_warn(&master->dev, "failed to enumerate SPI slaves\n");
|
||||
}
|
||||
#else
|
||||
static inline void acpi_register_spi_devices(struct spi_master *master) {}
|
||||
#endif /* CONFIG_ACPI */
|
||||
|
||||
static void spi_master_release(struct device *dev)
|
||||
{
|
||||
struct spi_master *master;
|
||||
@ -1023,8 +1123,9 @@ int spi_register_master(struct spi_master *master)
|
||||
spi_match_master_to_boardinfo(master, &bi->board_info);
|
||||
mutex_unlock(&board_lock);
|
||||
|
||||
/* Register devices from the device tree */
|
||||
/* Register devices from the device tree and ACPI */
|
||||
of_register_spi_devices(master);
|
||||
acpi_register_spi_devices(master);
|
||||
done:
|
||||
return status;
|
||||
}
|
||||
|
19
include/linux/acpi_gpio.h
Normal file
19
include/linux/acpi_gpio.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef _LINUX_ACPI_GPIO_H_
|
||||
#define _LINUX_ACPI_GPIO_H_
|
||||
|
||||
#include <linux/errno.h>
|
||||
|
||||
#ifdef CONFIG_GPIO_ACPI
|
||||
|
||||
int acpi_get_gpio(char *path, int pin);
|
||||
|
||||
#else /* CONFIG_GPIO_ACPI */
|
||||
|
||||
static inline int acpi_get_gpio(char *path, int pin)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_GPIO_ACPI */
|
||||
|
||||
#endif /* _LINUX_ACPI_GPIO_H_ */
|
Loading…
Reference in New Issue
Block a user