Skip to contentSkip to conversation

mfd: add U8500 STw4500 SPI device support

PATCH New srinidhi kasagar 3 participants 3 messages Sep 21, 2009 – Sep 22, 2009 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 mfd: add U8500 STw4500 SPI device support

From: srinidhi kasagar <[email protected]>

This adds core driver support for STw4500 mixed signal multimedia & power management chip. This connects to U8500 on the SSP (pl022) bus operating in SPI protocol and exports read/write functions for the device to get access to this chip.

---
 drivers/mfd/Kconfig   |   10 ++++
 drivers/mfd/Makefile  |    1 +
 drivers/mfd/stw4500.c |  137 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 0 deletions(-)
 create mode 100755 drivers/mfd/stw4500.c
drivers/mfd/Kconfig +10 -0
index 491ac0f..e3aec52 100644
@@ -256,6 +256,16 @@ config AB3100_CORE
 	  LEDs, vibrator, system power and temperature, power management
 	  and ALSA sound.
 
+config U8500_STW4500
+	tristate "ST-Ericsson U8500 Mixed Signal Power management chip"
+	depends on SPI
+	default y if ARCH_U8500
+	help
+	  Select this option to enable access to STw4500 power management
+	  chip. This connects to U8500 on the SSP/SPI bus and exports
+	  read/write functions for the devices to get access to this chip.
+	  This chip embeds various other multimedia funtionalities as well.
+
 config EZX_PCAP
 	bool "PCAP Support"
 	depends on GENERIC_HARDIRQS && SPI_MASTER
drivers/mfd/Makefile +1 -0
index 6f8a9a1..9b15e52 100644
@@ -44,3 +44,4 @@ obj-$(CONFIG_MFD_PCF50633)	+= pcf50633-core.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
 obj-$(CONFIG_PCF50633_GPIO)	+= pcf50633-gpio.o
 obj-$(CONFIG_AB3100_CORE)	+= ab3100-core.o
+obj-$(CONFIG_U8500_STW4500)	+= stw4500.o
drivers/mfd/stw4500.c new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
1.6.3.GIT
#1 lore raw

PATCH 2/3 mfd: add U8500 STw4500 SPI device support

Quoted 20 lines · srinidhi kasagar

From: srinidhi kasagar <[email protected]>

This adds core driver support for STw4500 mixed signal multimedia & power management chip. This connects to U8500 on the SSP (pl022) bus operating in SPI protocol and exports read/write functions for the device to get access to this chip.

---
 drivers/mfd/Kconfig   |   10 ++++
 drivers/mfd/Makefile  |    1 +
 drivers/mfd/stw4500.c |  137 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 0 deletions(-)
 create mode 100755 drivers/mfd/stw4500.c
drivers/mfd/Kconfig +0 -0
index 491ac0f..e3aec52 100644

drivers/mfd/Kconfig config AB3100_CORE · line 261

Quoted 6 lines
drivers/mfd/Kconfig +3 -0
@@ -256,6 +256,16 @@ config AB3100_CORE
 	  LEDs, vibrator, system power and temperature, power management
 	  and ALSA sound.
 
+config U8500_STW4500
+	tristate "ST-Ericsson U8500 Mixed Signal Power management chip"
+	depends on SPI

please put the depend on ARCH_U8500 here

drivers/mfd/Kconfig config AB3100_CORE · line 262

Quoted 1 line
drivers/mfd/Kconfig +1 -0
+	default y if ARCH_U8500

it will be better to select it at soc config not here

Quoted 37 lines
drivers/mfd/Kconfig +6 -0
+	help
+	  Select this option to enable access to STw4500 power management
+	  chip. This connects to U8500 on the SSP/SPI bus and exports
+	  read/write functions for the devices to get access to this chip.
+	  This chip embeds various other multimedia funtionalities as well.
+
 config EZX_PCAP
 	bool "PCAP Support"
 	depends on GENERIC_HARDIRQS && SPI_MASTER
drivers/mfd/Makefile +1 -0
index 6f8a9a1..9b15e52 100644
@@ -44,3 +44,4 @@ obj-$(CONFIG_MFD_PCF50633)	+= pcf50633-core.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
 obj-$(CONFIG_PCF50633_GPIO)	+= pcf50633-gpio.o
 obj-$(CONFIG_AB3100_CORE)	+= ab3100-core.o
+obj-$(CONFIG_U8500_STW4500)	+= stw4500.o
drivers/mfd/stw4500.c new file +13 -0
new file mode 100755
index 0000000..a8c1d39
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2009 ST-Ericsson
+ *
+ * Author: Srinidhi KASAGAR <[email protected]>
+ *
+ * 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.
+ *
+ * STw4500 is a companion power management chip used with U8500. On this
+ * platform, this is interfaced with SSP0 controller which is a ARM
+ * primecell pl022.
+ *

drivers/mfd/stw4500.c line 23

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+ * At the moment the module just exports read/write features.
+ * Interrupt management to be added.
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/spi/spi.h>
+
+static struct spi_driver stw4500_driver;

currently you support only one instance of the driver why? also you do not add an header for those read/write why?

Quoted 13 lines
drivers/mfd/stw4500.c new file +13 -0
+
+struct stw4500_chip {
+	struct spi_device	*spi;
+	unsigned long		tx_buf[4];
+	unsigned long		rx_buf[4];
+};
+
+struct stw4500_chip *the_stw4500;
+
+/*
+ * This funtion writes to any STw4500 registers using SPI protocol &
+ * before it writes it packs the data in the below 24 bit frame format
+ *

drivers/mfd/stw4500.c line 46

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+ *	 *|------------------------------------|
+ *	 *| 23|22...18|17.......10|9|8|7......0|
+ *	 *| r/w  bank       adr          data  |
+ *	 * ------------------------------------
+ *
+ * This function shouldn't be called from interrupt context
+ */
+int stw4500_write(unsigned char block, unsigned long addr,
+		unsigned char data)
+{

you may need to add a spinlock to avoid concurent acess problem

Quoted 11 lines
drivers/mfd/stw4500.c new file +11 -0
+	struct spi_transfer xfer;
+	struct spi_message	msg;
+	unsigned long spi_data =
+		block << 18 | addr << 10 | data;
+
+	the_stw4500->tx_buf[0] = spi_data;
+	the_stw4500->rx_buf[0] = 0;
+
+	xfer.tx_buf	= the_stw4500->tx_buf;
+	xfer.rx_buf 	= NULL;
+	xfer.len	= sizeof(unsigned long);

drivers/mfd/stw4500.c line 67

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+
+	spi_message_init(&msg);
+	spi_message_add_tail(&xfer, &msg);
+
+	return spi_sync(the_stw4500->spi, &msg);
+}
+EXPORT_SYMBOL(stw4500_write);
+
+int stw4500_read(unsigned char block, unsigned long addr)
+{

ditto here

Quoted 26 lines
drivers/mfd/stw4500.c new file +26 -0
+	struct spi_transfer xfer;
+	struct spi_message	msg;
+	unsigned long spi_data =
+		1 << 23 | block << 18 | addr << 10;
+
+	the_stw4500->tx_buf[0] = spi_data;
+	the_stw4500->rx_buf[0] = 0;
+
+	xfer.tx_buf	= the_stw4500->tx_buf;
+	xfer.rx_buf 	= the_stw4500->rx_buf;
+	xfer.len	= sizeof(unsigned long);
+
+	spi_message_init(&msg);
+	spi_message_add_tail(&xfer, &msg);
+
+	spi_sync(the_stw4500->spi, &msg);
+
+	return  the_stw4500->rx_buf[0];
+}
+EXPORT_SYMBOL(stw4500_read);
+
+static int __init stw4500_probe(struct spi_device *spi)
+{
+	struct stw4500_chip	*chip;
+	unsigned char revision;
+

drivers/mfd/stw4500.c line 103

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+	chip = kzalloc(sizeof *chip, GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+
+	chip->spi = spi;
+	spi_set_drvdata(spi, chip);
+	the_stw4500 = chip;
+
+	/* read the revision register */
+	revision = stw4500_read(0x10, 0x1080);

could you use macro here to describe what register you use

drivers/mfd/stw4500.c line 104

Quoted 1 line
drivers/mfd/stw4500.c new file +1 -0
+	printk(KERN_INFO "STw4500 PMU Initialized, revision = %x\n", revision);

is there any way to check if the companion work fine and that it's really a STw4500 and in this case only return 0

drivers/mfd/stw4500.c line 112

Quoted 8 lines
drivers/mfd/stw4500.c new file +8 -0
+
+	return 0;
+}
+
+static int __devexit stw4500_remove(struct spi_device *spi)
+{
+	struct stw4500_chip *chip =
+		spi_get_drvdata(spi);

please add an empty line
put NULL in the_stw4500 will be good too

drivers/mfd/stw4500.c line 116

Quoted 4 lines
drivers/mfd/stw4500.c new file +4 -0
+	kfree(chip);
+
+	return 0;
+}

Best Regards,
J.

#2 lore raw

PATCH 2/3 mfd: add U8500 STw4500 SPI device support

In reply to srinidhi kasagar
Quoted 4 lines · srinidhi kasagar

From: srinidhi kasagar <[email protected]>

This adds core driver support for STw4500 mixed signal multimedia & power management chip. This connects to U8500

MFD patches should be sent to Samuel Ortiz (added to the CCs here).

Quoted 2 lines

on the SSP (pl022) bus operating in SPI protocol and exports read/write functions for the device to get access to this chip.

I guess this would work with any SPI controller, though obviously it'd be rare to find other configurations?

Quoted 57 lines
---
 drivers/mfd/Kconfig   |   10 ++++
 drivers/mfd/Makefile  |    1 +
 drivers/mfd/stw4500.c |  137 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 0 deletions(-)
 create mode 100755 drivers/mfd/stw4500.c
drivers/mfd/Kconfig +10 -0
index 491ac0f..e3aec52 100644
@@ -256,6 +256,16 @@ config AB3100_CORE
 	  LEDs, vibrator, system power and temperature, power management
 	  and ALSA sound.
 
+config U8500_STW4500
+	tristate "ST-Ericsson U8500 Mixed Signal Power management chip"
+	depends on SPI
+	default y if ARCH_U8500
+	help
+	  Select this option to enable access to STw4500 power management
+	  chip. This connects to U8500 on the SSP/SPI bus and exports
+	  read/write functions for the devices to get access to this chip.
+	  This chip embeds various other multimedia funtionalities as well.
+
 config EZX_PCAP
 	bool "PCAP Support"
 	depends on GENERIC_HARDIRQS && SPI_MASTER
drivers/mfd/Makefile +1 -0
index 6f8a9a1..9b15e52 100644
@@ -44,3 +44,4 @@ obj-$(CONFIG_MFD_PCF50633)	+= pcf50633-core.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
 obj-$(CONFIG_PCF50633_GPIO)	+= pcf50633-gpio.o
 obj-$(CONFIG_AB3100_CORE)	+= ab3100-core.o
+obj-$(CONFIG_U8500_STW4500)	+= stw4500.o
drivers/mfd/stw4500.c new file +13 -0
new file mode 100755
index 0000000..a8c1d39
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2009 ST-Ericsson
+ *
+ * Author: Srinidhi KASAGAR <[email protected]>
+ *
+ * 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.
+ *
+ * STw4500 is a companion power management chip used with U8500. On this
+ * platform, this is interfaced with SSP0 controller which is a ARM
+ * primecell pl022.
+ *

drivers/mfd/stw4500.c line 23

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+ * At the moment the module just exports read/write features.
+ * Interrupt management to be added.
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/spi/spi.h>
+
+static struct spi_driver stw4500_driver;

Is there any need to forward declare this?

drivers/mfd/stw4500.c line 31

Quoted 8 lines
drivers/mfd/stw4500.c new file +8 -0
+
+struct stw4500_chip {
+	struct spi_device	*spi;
+	unsigned long		tx_buf[4];
+	unsigned long		rx_buf[4];
+};
+
+struct stw4500_chip *the_stw4500;

This should be static.

Quoted 5 lines
drivers/mfd/stw4500.c new file +5 -0
+
+/*
+ * This funtion writes to any STw4500 registers using SPI protocol &
+ * before it writes it packs the data in the below 24 bit frame format
+ *

drivers/mfd/stw4500.c line 46

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+ *	 *|------------------------------------|
+ *	 *| 23|22...18|17.......10|9|8|7......0|
+ *	 *| r/w  bank       adr          data  |
+ *	 * ------------------------------------
+ *
+ * This function shouldn't be called from interrupt context
+ */
+int stw4500_write(unsigned char block, unsigned long addr,
+		unsigned char data)
+{

Normally the read and write functions would take the device as an argument, though I guess it's probably not the end of the world for this hardware.

Quoted 51 lines
drivers/mfd/stw4500.c new file +51 -0
+	struct spi_transfer xfer;
+	struct spi_message	msg;
+	unsigned long spi_data =
+		block << 18 | addr << 10 | data;
+
+	the_stw4500->tx_buf[0] = spi_data;
+	the_stw4500->rx_buf[0] = 0;
+
+	xfer.tx_buf	= the_stw4500->tx_buf;
+	xfer.rx_buf 	= NULL;
+	xfer.len	= sizeof(unsigned long);
+
+	spi_message_init(&msg);
+	spi_message_add_tail(&xfer, &msg);
+
+	return spi_sync(the_stw4500->spi, &msg);
+}
+EXPORT_SYMBOL(stw4500_write);
+
+int stw4500_read(unsigned char block, unsigned long addr)
+{
+	struct spi_transfer xfer;
+	struct spi_message	msg;
+	unsigned long spi_data =
+		1 << 23 | block << 18 | addr << 10;
+
+	the_stw4500->tx_buf[0] = spi_data;
+	the_stw4500->rx_buf[0] = 0;
+
+	xfer.tx_buf	= the_stw4500->tx_buf;
+	xfer.rx_buf 	= the_stw4500->rx_buf;
+	xfer.len	= sizeof(unsigned long);
+
+	spi_message_init(&msg);
+	spi_message_add_tail(&xfer, &msg);
+
+	spi_sync(the_stw4500->spi, &msg);
+
+	return  the_stw4500->rx_buf[0];
+}
+EXPORT_SYMBOL(stw4500_read);
+
+static int __init stw4500_probe(struct spi_device *spi)
+{
+	struct stw4500_chip	*chip;
+	unsigned char revision;
+
+	chip = kzalloc(sizeof *chip, GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+

drivers/mfd/stw4500.c line 107

Quoted 10 lines
drivers/mfd/stw4500.c new file +10 -0
+	chip->spi = spi;
+	spi_set_drvdata(spi, chip);
+	the_stw4500 = chip;
+
+	/* read the revision register */
+	revision = stw4500_read(0x10, 0x1080);
+	printk(KERN_INFO "STw4500 PMU Initialized, revision = %x\n", revision);
+
+	return 0;
+}

I'd expect this function to register child devices for the STW4500 functionality?

Quoted 41 lines
drivers/mfd/stw4500.c new file +30 -0
+
+static int __devexit stw4500_remove(struct spi_device *spi)
+{
+	struct stw4500_chip *chip =
+		spi_get_drvdata(spi);
+	kfree(chip);
+
+	return 0;
+}
+
+static struct spi_driver stw4500_driver = {
+	.driver = {
+		.name = "stw4500",
+		.owner = THIS_MODULE,
+	},
+	.probe = stw4500_probe,
+	.remove = __devexit_p(stw4500_remove)
+};
+
+static int __devinit stw4500_init(void)
+{
+	return spi_register_driver(&stw4500_driver);
+}
+
+static void __exit stw4500_exit(void)
+{
+	spi_unregister_driver(&stw4500_driver);
+}
+
+subsys_initcall_sync(stw4500_init);
Signature · 9 lines
1.6.3.GIT




_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel