Re: [PATCH v4] MFD: PCAP driver
On Thu, May 28, 2009 at 03:43:37PM -0300, Daniel Ribeiro wrote: Changelog v3 - v4: * Pass struct pcap_chip * instead of void * * Fix initial PCAP_REG_INT_SEL value at probe Thanks Daniel, this one got applied to my for-next branch. Cheers, Samuel. The PCAP Asic as present on EZX phones is a multi function device with voltage regulators, ADC, touch screen controller, RTC, USB transceiver, leds controller, and audio codec. It has two SPI ports, typically one is connected to the application processor and another to the baseband, this driver provides read/write functions to its registers, irq demultiplexer and ADC queueing/abstraction. This chip is used on a lot of Motorola phones, it was manufactured by TI as a custom product with the name PTWL93017, later this design evolved into the ATLAS PMIC from Freescale (MC13783). Signed-off-by: Daniel Ribeiro drw...@gmail.com --- drivers/mfd/Kconfig |7 + drivers/mfd/Makefile |2 + drivers/mfd/ezx-pcap.c | 505 ++ include/linux/mfd/ezx-pcap.h | 256 + 4 files changed, 770 insertions(+), 0 deletions(-) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index ee3927a..060ee14 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -241,6 +241,13 @@ config PCF50633_GPIO Say yes here if you want to include support GPIO for pins on the PCF50633 chip. +config EZX_PCAP + bool PCAP Support + depends on SPI_MASTER + help + This enables the PCAP ASIC present on EZX Phones. This is + needed for MMC, TouchScreen, Sound, USB, etc.. + endmenu menu Multimedia Capabilities Port drivers diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 3afb519..b768962 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -26,6 +26,8 @@ obj-$(CONFIG_TWL4030_CORE) += twl4030-core.o twl4030-irq.o obj-$(CONFIG_MFD_CORE) += mfd-core.o +obj-$(CONFIG_EZX_PCAP) += ezx-pcap.o + obj-$(CONFIG_MCP)+= mcp-core.o obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o obj-$(CONFIG_MCP_UCB1200)+= ucb1x00-core.o diff --git a/drivers/mfd/ezx-pcap.c b/drivers/mfd/ezx-pcap.c new file mode 100644 index 000..671a7ef --- /dev/null +++ b/drivers/mfd/ezx-pcap.c @@ -0,0 +1,505 @@ +/* + * Driver for Motorola PCAP2 as present in EZX phones + * + * Copyright (C) 2006 Harald Welte lafo...@openezx.org + * Copyright (C) 2009 Daniel Ribeiro drw...@gmail.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/module.h +#include linux/kernel.h +#include linux/platform_device.h +#include linux/interrupt.h +#include linux/irq.h +#include linux/mfd/ezx-pcap.h +#include linux/spi/spi.h + +#define PCAP_ADC_MAXQ8 +struct pcap_adc_request { + u8 bank; + u8 ch[2]; + u32 flags; + void (*callback)(void *, u16[]); + void *data; +}; + +struct pcap_adc_sync_request { + u16 res[2]; + struct completion completion; +}; + +struct pcap_chip { + struct spi_device *spi; + + /* IO */ + u32 buf; + struct mutex io_mutex; + + /* IRQ */ + unsigned int irq_base; + u32 msr; + struct work_struct isr_work; + struct work_struct msr_work; + struct workqueue_struct *workqueue; + + /* ADC */ + struct pcap_adc_request *adc_queue[PCAP_ADC_MAXQ]; + u8 adc_head; + u8 adc_tail; + struct mutex adc_mutex; +}; + +/* IO */ +static int ezx_pcap_putget(struct pcap_chip *pcap, u32 *data) +{ + struct spi_transfer t; + struct spi_message m; + int status; + + memset(t, 0, sizeof t); + spi_message_init(m); + t.len = sizeof(u32); + spi_message_add_tail(t, m); + + pcap-buf = *data; + t.tx_buf = (u8 *) pcap-buf; + t.rx_buf = (u8 *) pcap-buf; + status = spi_sync(pcap-spi, m); + + if (status == 0) + *data = pcap-buf; + + return status; +} + +int ezx_pcap_write(struct pcap_chip *pcap, u8 reg_num, u32 value) +{ + int ret; + + mutex_lock(pcap-io_mutex); + value = PCAP_REGISTER_VALUE_MASK; + value |= PCAP_REGISTER_WRITE_OP_BIT + | (reg_num PCAP_REGISTER_ADDRESS_SHIFT); + ret = ezx_pcap_putget(pcap, value); + mutex_unlock(pcap-io_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(ezx_pcap_write); + +int ezx_pcap_read(struct pcap_chip *pcap, u8 reg_num, u32 *value) +{ + int ret; + + mutex_lock(pcap-io_mutex); + *value = PCAP_REGISTER_READ_OP_BIT + | (reg_num PCAP_REGISTER_ADDRESS_SHIFT); + + ret = ezx_pcap_putget(pcap, value); + mutex_unlock(pcap-io_mutex); + + return ret; +}
[PATCH v4] MFD: PCAP driver
Changelog v3 - v4: * Pass struct pcap_chip * instead of void * * Fix initial PCAP_REG_INT_SEL value at probe The PCAP Asic as present on EZX phones is a multi function device with voltage regulators, ADC, touch screen controller, RTC, USB transceiver, leds controller, and audio codec. It has two SPI ports, typically one is connected to the application processor and another to the baseband, this driver provides read/write functions to its registers, irq demultiplexer and ADC queueing/abstraction. This chip is used on a lot of Motorola phones, it was manufactured by TI as a custom product with the name PTWL93017, later this design evolved into the ATLAS PMIC from Freescale (MC13783). Signed-off-by: Daniel Ribeiro drw...@gmail.com --- drivers/mfd/Kconfig |7 + drivers/mfd/Makefile |2 + drivers/mfd/ezx-pcap.c | 505 ++ include/linux/mfd/ezx-pcap.h | 256 + 4 files changed, 770 insertions(+), 0 deletions(-) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index ee3927a..060ee14 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -241,6 +241,13 @@ config PCF50633_GPIO Say yes here if you want to include support GPIO for pins on the PCF50633 chip. +config EZX_PCAP + bool PCAP Support + depends on SPI_MASTER + help + This enables the PCAP ASIC present on EZX Phones. This is + needed for MMC, TouchScreen, Sound, USB, etc.. + endmenu menu Multimedia Capabilities Port drivers diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 3afb519..b768962 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -26,6 +26,8 @@ obj-$(CONFIG_TWL4030_CORE)+= twl4030-core.o twl4030-irq.o obj-$(CONFIG_MFD_CORE) += mfd-core.o +obj-$(CONFIG_EZX_PCAP) += ezx-pcap.o + obj-$(CONFIG_MCP) += mcp-core.o obj-$(CONFIG_MCP_SA11X0) += mcp-sa11x0.o obj-$(CONFIG_MCP_UCB1200) += ucb1x00-core.o diff --git a/drivers/mfd/ezx-pcap.c b/drivers/mfd/ezx-pcap.c new file mode 100644 index 000..671a7ef --- /dev/null +++ b/drivers/mfd/ezx-pcap.c @@ -0,0 +1,505 @@ +/* + * Driver for Motorola PCAP2 as present in EZX phones + * + * Copyright (C) 2006 Harald Welte lafo...@openezx.org + * Copyright (C) 2009 Daniel Ribeiro drw...@gmail.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/module.h +#include linux/kernel.h +#include linux/platform_device.h +#include linux/interrupt.h +#include linux/irq.h +#include linux/mfd/ezx-pcap.h +#include linux/spi/spi.h + +#define PCAP_ADC_MAXQ 8 +struct pcap_adc_request { + u8 bank; + u8 ch[2]; + u32 flags; + void (*callback)(void *, u16[]); + void *data; +}; + +struct pcap_adc_sync_request { + u16 res[2]; + struct completion completion; +}; + +struct pcap_chip { + struct spi_device *spi; + + /* IO */ + u32 buf; + struct mutex io_mutex; + + /* IRQ */ + unsigned int irq_base; + u32 msr; + struct work_struct isr_work; + struct work_struct msr_work; + struct workqueue_struct *workqueue; + + /* ADC */ + struct pcap_adc_request *adc_queue[PCAP_ADC_MAXQ]; + u8 adc_head; + u8 adc_tail; + struct mutex adc_mutex; +}; + +/* IO */ +static int ezx_pcap_putget(struct pcap_chip *pcap, u32 *data) +{ + struct spi_transfer t; + struct spi_message m; + int status; + + memset(t, 0, sizeof t); + spi_message_init(m); + t.len = sizeof(u32); + spi_message_add_tail(t, m); + + pcap-buf = *data; + t.tx_buf = (u8 *) pcap-buf; + t.rx_buf = (u8 *) pcap-buf; + status = spi_sync(pcap-spi, m); + + if (status == 0) + *data = pcap-buf; + + return status; +} + +int ezx_pcap_write(struct pcap_chip *pcap, u8 reg_num, u32 value) +{ + int ret; + + mutex_lock(pcap-io_mutex); + value = PCAP_REGISTER_VALUE_MASK; + value |= PCAP_REGISTER_WRITE_OP_BIT + | (reg_num PCAP_REGISTER_ADDRESS_SHIFT); + ret = ezx_pcap_putget(pcap, value); + mutex_unlock(pcap-io_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(ezx_pcap_write); + +int ezx_pcap_read(struct pcap_chip *pcap, u8 reg_num, u32 *value) +{ + int ret; + + mutex_lock(pcap-io_mutex); + *value = PCAP_REGISTER_READ_OP_BIT + | (reg_num PCAP_REGISTER_ADDRESS_SHIFT); + + ret = ezx_pcap_putget(pcap, value); + mutex_unlock(pcap-io_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(ezx_pcap_read); + +/* IRQ */ +static inline unsigned int irq2pcap(struct pcap_chip *pcap, int irq) +{ + return 1 (irq - pcap-irq_base); +} + +int pcap_to_irq(struct pcap_chip *pcap, int irq) +{ +