Add VIA VX855 multi-function device support
PATCH 1/1 Add VIA VX855 multi-function device support
From: Harald Welte <[email protected]>
Initially we add support for the south bridge GPIO lines via GPIOLIB as well as some skeleton for the SPI controllers.
This hardware can be found in the OLPC XO-1.5 laptop.
--- drivers/mfd/Kconfig | 27 ++++ drivers/mfd/Makefile | 3 + drivers/mfd/vx855-core.c | 132 +++++++++++++++++ drivers/mfd/vx855-gpio.c | 350 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/mfd/vx855-spi.c | 302 +++++++++++++++++++++++++++++++++++++++ drivers/mfd/vx855.h | 16 ++ 6 files changed, 830 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/vx855-core.c create mode 100644 drivers/mfd/vx855-gpio.c create mode 100644 drivers/mfd/vx855-spi.c create mode 100644 drivers/mfd/vx855.h
drivers/mfd/Kconfig +27 -0
@@ -555,6 +555,33 @@ config MFD_TPS6586X This driver can also be built as a module. If so, the module will be called tps6586x. +config MFD_VX855 + tristate "Support for VIA VX855/VX875 integrated south bridge" + depends on X86 + help + Say yes here to enable support for various functions of the + VIA VX855/VX875 south bridge. + +config MFD_VX855_GPIO + tristate "Support for VIA VX855/VX875 GPIO" + depends on GPIOLIB + help + Support access to the VX855/VX975 GPIO lines through the gpio library. + + This driver provides common support for accessing the device, + additional drivers must be enabled in order to use the + functionality of the device. + +config MFD_VX855_SPI + tristate "Support for VIA VX855/VX875 SPI" + depends on SPI_MASTER + help + Support access to the SPI bus on the VX855/VX875 south bridge. + + This driver provides common support for accessing the device, + additional drivers must be enabled in order to use the + functionality of the device. + endif # MFD_SUPPORT menu "Multimedia Capabilities Port drivers"
drivers/mfd/Makefile +3 -0
@@ -76,3 +76,6 @@ obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o +obj-$(CONFIG_MFD_VX855) += vx855-core.o +obj-$(CONFIG_MFD_VX855_GPIO) += vx855-gpio.o +obj-$(CONFIG_MFD_VX855_SPI) += vx855-spi.o
drivers/mfd/vx855-core.c new file +132 -0
132 lines not on this page · raw message
drivers/mfd/vx855-gpio.c new file +350 -0
350 lines not on this page · raw message
drivers/mfd/vx855-spi.c new file +302 -0
302 lines not on this page · raw message
drivers/mfd/vx855.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _VX855_H +#define _VX855_H + +struct vx855 { +spinlock_t lock; +struct pci_dev *pdev; +struct platform_device *gpio_pdev; +struct platform_device *spi_pdev; +struct platform_device *i2c_pdev; +}; + +struct vx855_subdev_pdata { +struct vx855 *vx855; +}; + +#endif /* _VX855_H */
Signature · 1 line
1.7.2.2
Hi Daniel,
Quoted 6 lines · Daniel Drake
From: Harald Welte <[email protected]>
Initially we add support for the south bridge GPIO lines via GPIOLIB as well as some skeleton for the SPI controllers.
This hardware can be found in the OLPC XO-1.5 laptop.
Some comments below:
Quoted 23 lines
drivers/mfd/vx855-core.c new file +23
-0+static int vx855_client_dev_register (struct vx855 *vg,const char *name, +struct platform_device **pdev) +{ +struct vx855_subdev_pdata *subdev_pdata; +int ret; + + *pdev =platform_device_alloc (name,-1 ); +if (!*pdev) { +dev_err (&vg->pdev->dev,"Failed to allocate pdev %s\n" , name); +return -ENOMEM ; + } + + subdev_pdata =kmalloc (sizeof (*subdev_pdata),GFP_KERNEL ); +if (!subdev_pdata) { +platform_device_put (*pdev); +return -ENOMEM ; + } + + subdev_pdata->vx855 = vg; + (*pdev)->dev.platform_data = subdev_pdata; + (*pdev)->dev.parent = &vg->pdev->dev; + + ret =platform_device_add (*pdev);
drivers/mfd/vx855-core.c line 66
Quoted 10 lines
drivers/mfd/vx855-core.c new file +10
-0+if (ret) { +dev_err (&vg->pdev->dev,"Failed to register pdev %s\n" , name); +kfree (subdev_pdata); +platform_device_put (*pdev); + *pdev =NULL ; +return ret; + } + +return 0 ; +}
We do have an MFD API for registering sub devices as platform devices. See mfd_add_devices(). You'd have to define cells (statically or not) and set the cell->platform_data pointer properly. I'd prefer to see this driver using this API.
You will also need to depend on MFD_CORE.
Quoted 6 lines
drivers/mfd/vx855-gpio.c new file +6
-0+static __devinit int vx855gpio_probe (struct platform_device *pdev) +{ +struct vx855_gpio *vg; +struct vx855_subdev_pdata *pdata = pdev->dev.platform_data; +u_int16_t io_offset; +int ret;
drivers/mfd/vx855-gpio.c line 260
Quoted 10 lines
drivers/mfd/vx855-gpio.c new file +10
-0+ + vg =kzalloc (sizeof (*vg),GFP_KERNEL ); +if (!vg) +return -ENOMEM ; + + vg->vx855 = pdata->vx855; +platform_set_drvdata (pdev, vg); + + ret =pci_read_config_word (vg->vx855->pdev, +VX855_CFG_PMIO_OFFSET , &io_offset);
So it seems the only thing you need from the parent device is the I/O region. If that really is the case then you may want to pass it from the actual MFD driver as a platform resource (you do the pci_read_config_word() from the MFD driver). The drivers/mfd/lcp_sch.c driver is a good example for that. The benefit you get from that design is that your sub devices drivers are completely independent from the parent one, they don't even have to share any data structure, you could get rid of vx855.h.
Quoted 15 lines
drivers/mfd/vx855-gpio.c new file +15
-0+if (ret) { + ret = -EIO ; + goto out_free; + } + +if (!io_offset) { +dev_warn (&pdev->dev,"BIOS did not assign PMIO base offset?!?\n" ); + ret = -ENODEV ; + goto out_free; + } + +/* mask out the lowest seven bits, as they are always zero, but +* hardware returns them as 0x01 */ + io_offset &=0xff80 ; + io_offset +=VX855_PMIO_GPPM ;
drivers/mfd/vx855-gpio.c line 285
Quoted 10 lines
drivers/mfd/vx855-gpio.c new file +10
-0+ +dev_info (&pdev->dev,"found VX855 PMIO at base 0x%x\n" , io_offset); + + vg->io_base = io_offset; +spin_lock_init (&vg->lock); + +/* Typically the ACPI code will already have requested this +* region, so we have to skip requesting it. If you run a +* system without ACPI, you should enable VX855GPIO_REQUEST_REGION */ +#ifdef VX855GPIO_REQUEST_REGION
Is this something you want to define in Kconfig ?
Quoted 7 lines
drivers/mfd/vx855-spi.c new file +7
-0+static int __init via_spi_probe (struct platform_device *pdev) +{ +struct vx855_subdev_pdata *pdata = pdev->dev.platform_data; +struct via_spi *vspi; +struct spi_master *master; +u_int32_t ctrlreg; +int err;
drivers/mfd/vx855-spi.c line 137
Quoted 10 lines
drivers/mfd/vx855-spi.c new file +10
-0+ + vspi =kzalloc (sizeof (*vspi),GFP_KERNEL ); +if (!vspi) +return -ENOMEM ; + + vspi->vx855 = pdata->vx855; +platform_set_drvdata (pdev, vspi); + +/* First we determine the MMIO base of the control registers */ +pci_read_config_dword (vspi->vx855->pdev,0xbc , &vspi->ctrl.mmio_base);
Same comment applies to this SPI driver, it seems the onyl thing it needs from the parent is the MMIO base address.
Cheers,
Samuel.
Signature · 2 lines
Intel Open Source Technology Centre http://oss.intel.com/
Quoted 4 lines · Samuel Ortiz
We do have an MFD API for registering sub devices as platform devices. See
mfd_add_devices(). You'd have to define cells (statically or not) and set thecell->platform_datapointer properly. I'd prefer to see this driver using this API.
Thanks. I've made the change locally but have run into a problem.
mfd_add_devices calls acpi_check_resource_conflict() on each resource. And as noted in the earlier patch, ACPI also has a region reserved. Because acpi_check_resource_conflict() says there is a conflict, mfd_add_devices() bails out before registering the devices.
So I've researched the conflict.
The GPIO driver is trying to reserve region 0x420 - 0x452 ACPI reports a conflict on "PRIE" 0x434
Indeed, 0x434 is something ACPI-specific, so ACPI is right to say "get off my turf", and actually there are a whole host of non-GPIO things intermixed with GPIO things within the region 0x420 - 0x452.
So, I thought about making the driver only reserve the 2 ports that it
uses: 0x448, 0x44c
However, ACPI has also reserved 0x448. This is because the XO-1.5 also uses GPIOs for the lid switch and ebook switch, which are basically presented to the OS as normal ACPI buttons. This particular byte includes a range of GPIOs including the ones that ACPI uses internally (the switches) plus the ones that we want to make available through the gpio driver.
So, we're running into a limitation with Linux's model that
Sorry, hit send too early.
Quoted 18 lines · Daniel Drake
Thanks. I've made the change locally but have run into a problem.
mfd_add_devicescallsacpi_check_resource_conflict()on each resource. And as noted in the earlier patch, ACPI also has a region reserved. Becauseacpi_check_resource_conflict()says there is a conflict,mfd_add_devices()bails out before registering the devices.So I've researched the conflict.
The GPIO driver is trying to reserve region0x420-0x452ACPI reports a conflict on "PRIE"0x434Indeed,
0x434is something ACPI-specific, so ACPI is right to say "get off my turf", and actually there are a whole host of non-GPIO things intermixed with GPIO things within the region0x420-0x452.So, I thought about making the driver only reserve the 2 ports that it
uses:0x448, 0x44c
Quoted 8 lines
However, ACPI has also reserved
0x448. This is because the XO-1.5 also uses GPIOs for the lid switch and ebook switch, which are basically presented to the OS as normal ACPI buttons. This particular byte includes a range of GPIOs including the ones that ACPI uses internally (the switches) plus the ones that we want to make available through the gpio driver.So, we're running into a limitation with Linux's model that
...an individual byte is either owned by one driver or another. In this case, we want certain bits to belong to ACPI and other bits to belong to the gpio driver. And given that these are "general purpose" I/Os, this sharing even seems reasonable.
Any thoughts on what we can do?
Perhaps we could avoid using the mfd cell resource mechanism for the GPIO ports, go back to passing them some other way, and attempting to reserve the 2 needed ports but not bailing out if they can't be reserved.
Thanks,
Daniel