aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/88pm860x-core.c6
-rw-r--r--drivers/mfd/88pm860x-i2c.c2
-rw-r--r--drivers/mfd/Kconfig87
-rw-r--r--drivers/mfd/Makefile13
-rw-r--r--drivers/mfd/ab3100-core.c99
-rw-r--r--drivers/mfd/ab3100-otp.c13
-rw-r--r--drivers/mfd/ab3550-core.c1401
-rw-r--r--drivers/mfd/ab4500-core.c209
-rw-r--r--drivers/mfd/ab8500-core.c444
-rw-r--r--drivers/mfd/ab8500-spi.c133
-rw-r--r--drivers/mfd/abx500-core.c157
-rw-r--r--drivers/mfd/da903x.c1
-rw-r--r--drivers/mfd/janz-cmodio.c304
-rw-r--r--drivers/mfd/max8925-core.c7
-rw-r--r--drivers/mfd/max8925-i2c.c2
-rw-r--r--drivers/mfd/menelaus.c3
-rw-r--r--drivers/mfd/mfd-core.c2
-rw-r--r--drivers/mfd/pcf50633-adc.c39
-rw-r--r--drivers/mfd/pcf50633-core.c345
-rw-r--r--drivers/mfd/pcf50633-irq.c318
-rw-r--r--drivers/mfd/rdc321x-southbridge.c123
-rw-r--r--drivers/mfd/t7l66xb.c3
-rw-r--r--drivers/mfd/tc35892.c347
-rw-r--r--drivers/mfd/timberdale.c156
-rw-r--r--drivers/mfd/timberdale.h16
-rw-r--r--drivers/mfd/tps65010.c2
-rw-r--r--drivers/mfd/tps6507x.c159
-rw-r--r--drivers/mfd/twl4030-irq.c11
-rw-r--r--drivers/mfd/wm831x-core.c112
-rw-r--r--drivers/mfd/wm831x-irq.c18
-rw-r--r--drivers/mfd/wm8350-i2c.c6
-rw-r--r--drivers/mfd/wm8400-core.c4
32 files changed, 3855 insertions, 687 deletions
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 405d2d5183cf..2c65a2c57294 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -566,7 +566,7 @@ out:
566 return ret; 566 return ret;
567} 567}
568 568
569static void __devexit device_irq_exit(struct pm860x_chip *chip) 569static void device_irq_exit(struct pm860x_chip *chip)
570{ 570{
571 if (chip->core_irq) 571 if (chip->core_irq)
572 free_irq(chip->core_irq, chip); 572 free_irq(chip->core_irq, chip);
@@ -703,7 +703,7 @@ out:
703 return; 703 return;
704} 704}
705 705
706int pm860x_device_init(struct pm860x_chip *chip, 706int __devinit pm860x_device_init(struct pm860x_chip *chip,
707 struct pm860x_platform_data *pdata) 707 struct pm860x_platform_data *pdata)
708{ 708{
709 chip->core_irq = 0; 709 chip->core_irq = 0;
@@ -731,7 +731,7 @@ int pm860x_device_init(struct pm860x_chip *chip,
731 return 0; 731 return 0;
732} 732}
733 733
734void pm860x_device_exit(struct pm860x_chip *chip) 734void __devexit pm860x_device_exit(struct pm860x_chip *chip)
735{ 735{
736 device_irq_exit(chip); 736 device_irq_exit(chip);
737 mfd_remove_devices(chip->dev); 737 mfd_remove_devices(chip->dev);
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c
index 4a6e7186334e..c933b64d1283 100644
--- a/drivers/mfd/88pm860x-i2c.c
+++ b/drivers/mfd/88pm860x-i2c.c
@@ -200,8 +200,8 @@ static int __devexit pm860x_remove(struct i2c_client *client)
200 200
201 pm860x_device_exit(chip); 201 pm860x_device_exit(chip);
202 i2c_unregister_device(chip->companion); 202 i2c_unregister_device(chip->companion);
203 i2c_set_clientdata(chip->companion, NULL);
204 i2c_set_clientdata(chip->client, NULL); 203 i2c_set_clientdata(chip->client, NULL);
204 i2c_set_clientdata(client, NULL);
205 kfree(chip); 205 kfree(chip);
206 return 0; 206 return 0;
207} 207}
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3c6a9860dd9c..9da0e504bbe9 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2,8 +2,14 @@
2# Multifunction miscellaneous devices 2# Multifunction miscellaneous devices
3# 3#
4 4
5menu "Multifunction device drivers" 5menuconfig MFD_SUPPORT
6 bool "Multifunction device drivers"
6 depends on HAS_IOMEM 7 depends on HAS_IOMEM
8 default y
9 help
10 Configure MFD device drivers.
11
12if MFD_SUPPORT
7 13
8config MFD_CORE 14config MFD_CORE
9 tristate 15 tristate
@@ -116,6 +122,18 @@ config TPS65010
116 This driver can also be built as a module. If so, the module 122 This driver can also be built as a module. If so, the module
117 will be called tps65010. 123 will be called tps65010.
118 124
125config TPS6507X
126 tristate "TPS6507x Power Management / Touch Screen chips"
127 select MFD_CORE
128 depends on I2C
129 help
130 If you say yes here you get support for the TPS6507x series of
131 Power Management / Touch Screen chips. These include voltage
132 regulators, lithium ion/polymer battery charging, touch screen
133 and other features that are often used in portable devices.
134 This driver can also be built as a module. If so, the module
135 will be called tps6507x.
136
119config MENELAUS 137config MENELAUS
120 bool "Texas Instruments TWL92330/Menelaus PM chip" 138 bool "Texas Instruments TWL92330/Menelaus PM chip"
121 depends on I2C=y && ARCH_OMAP2 139 depends on I2C=y && ARCH_OMAP2
@@ -159,6 +177,17 @@ config TWL4030_CODEC
159 select MFD_CORE 177 select MFD_CORE
160 default n 178 default n
161 179
180config MFD_TC35892
181 bool "Support Toshiba TC35892"
182 depends on I2C=y && GENERIC_HARDIRQS
183 select MFD_CORE
184 help
185 Support for the Toshiba TC35892 I/O Expander.
186
187 This driver provides common support for accessing the device,
188 additional drivers must be enabled in order to use the
189 functionality of the device.
190
162config MFD_TMIO 191config MFD_TMIO
163 bool 192 bool
164 default n 193 default n
@@ -351,9 +380,19 @@ config PCF50633_GPIO
351 Say yes here if you want to include support GPIO for pins on 380 Say yes here if you want to include support GPIO for pins on
352 the PCF50633 chip. 381 the PCF50633 chip.
353 382
383config ABX500_CORE
384 bool "ST-Ericsson ABX500 Mixed Signal Circuit register functions"
385 default y if ARCH_U300
386 help
387 Say yes here if you have the ABX500 Mixed Signal IC family
388 chips. This core driver expose register access functions.
389 Functionality specific drivers using these functions can
390 remain unchanged when IC changes. Binding of the functions to
391 actual register access is done by the IC core driver.
392
354config AB3100_CORE 393config AB3100_CORE
355 bool "ST-Ericsson AB3100 Mixed Signal Circuit core functions" 394 bool "ST-Ericsson AB3100 Mixed Signal Circuit core functions"
356 depends on I2C=y 395 depends on I2C=y && ABX500_CORE
357 default y if ARCH_U300 396 default y if ARCH_U300
358 help 397 help
359 Select this to enable the AB3100 Mixed Signal IC core 398 Select this to enable the AB3100 Mixed Signal IC core
@@ -381,15 +420,30 @@ config EZX_PCAP
381 This enables the PCAP ASIC present on EZX Phones. This is 420 This enables the PCAP ASIC present on EZX Phones. This is
382 needed for MMC, TouchScreen, Sound, USB, etc.. 421 needed for MMC, TouchScreen, Sound, USB, etc..
383 422
384config AB4500_CORE 423config AB8500_CORE
385 tristate "ST-Ericsson's AB4500 Mixed Signal Power management chip" 424 bool "ST-Ericsson AB8500 Mixed Signal Power Management chip"
386 depends on SPI 425 depends on SPI=y && GENERIC_HARDIRQS
426 select MFD_CORE
387 help 427 help
388 Select this option to enable access to AB4500 power management 428 Select this option to enable access to AB8500 power management
389 chip. This connects to U8500 on the SSP/SPI bus and exports 429 chip. This connects to U8500 on the SSP/SPI bus and exports
390 read/write functions for the devices to get access to this chip. 430 read/write functions for the devices to get access to this chip.
391 This chip embeds various other multimedia funtionalities as well. 431 This chip embeds various other multimedia funtionalities as well.
392 432
433config AB3550_CORE
434 bool "ST-Ericsson AB3550 Mixed Signal Circuit core functions"
435 select MFD_CORE
436 depends on I2C=y && GENERIC_HARDIRQS && ABX500_CORE
437 help
438 Select this to enable the AB3550 Mixed Signal IC core
439 functionality. This connects to a AB3550 on the I2C bus
440 and expose a number of symbols needed for dependent devices
441 to read and write registers and subscribe to events from
442 this multi-functional IC. This is needed to use other features
443 of the AB3550 such as battery-backed RTC, charging control,
444 LEDs, vibrator, system power and temperature, power management
445 and ALSA sound.
446
393config MFD_TIMBERDALE 447config MFD_TIMBERDALE
394 tristate "Support for the Timberdale FPGA" 448 tristate "Support for the Timberdale FPGA"
395 select MFD_CORE 449 select MFD_CORE
@@ -409,7 +463,26 @@ config LPC_SCH
409 LPC bridge function of the Intel SCH provides support for 463 LPC bridge function of the Intel SCH provides support for
410 System Management Bus and General Purpose I/O. 464 System Management Bus and General Purpose I/O.
411 465
412endmenu 466config MFD_RDC321X
467 tristate "Support for RDC-R321x southbridge"
468 select MFD_CORE
469 depends on PCI
470 help
471 Say yes here if you want to have support for the RDC R-321x SoC
472 southbridge which provides access to GPIOs and Watchdog using the
473 southbridge PCI device configuration space.
474
475config MFD_JANZ_CMODIO
476 tristate "Support for Janz CMOD-IO PCI MODULbus Carrier Board"
477 select MFD_CORE
478 depends on PCI
479 help
480 This is the core driver for the Janz CMOD-IO PCI MODULbus
481 carrier board. This device is a PCI to MODULbus bridge which may
482 host many different types of MODULbus daughterboards, including
483 CAN and GPIO controllers.
484
485endif # MFD_SUPPORT
413 486
414menu "Multimedia Capabilities Port drivers" 487menu "Multimedia Capabilities Port drivers"
415 depends on ARCH_SA1100 488 depends on ARCH_SA1100
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 87935f967aa0..fb503e77dc60 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_HTC_I2CPLD) += htc-i2cpld.o
15obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o 15obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o
16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o 16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o
17 17
18obj-$(CONFIG_MFD_TC35892) += tc35892.o
18obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o 19obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o
19obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o 20obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o
20obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o tmio_core.o 21obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o tmio_core.o
@@ -29,6 +30,7 @@ obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
29obj-$(CONFIG_MFD_WM8994) += wm8994-core.o wm8994-irq.o 30obj-$(CONFIG_MFD_WM8994) += wm8994-core.o wm8994-irq.o
30 31
31obj-$(CONFIG_TPS65010) += tps65010.o 32obj-$(CONFIG_TPS65010) += tps65010.o
33obj-$(CONFIG_TPS6507X) += tps6507x.o
32obj-$(CONFIG_MENELAUS) += menelaus.o 34obj-$(CONFIG_MENELAUS) += menelaus.o
33 35
34obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o 36obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o
@@ -55,12 +57,17 @@ obj-$(CONFIG_PMIC_DA903X) += da903x.o
55max8925-objs := max8925-core.o max8925-i2c.o 57max8925-objs := max8925-core.o max8925-i2c.o
56obj-$(CONFIG_MFD_MAX8925) += max8925.o 58obj-$(CONFIG_MFD_MAX8925) += max8925.o
57 59
58obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o 60pcf50633-objs := pcf50633-core.o pcf50633-irq.o
61obj-$(CONFIG_MFD_PCF50633) += pcf50633.o
59obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o 62obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o
60obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o 63obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
64obj-$(CONFIG_ABX500_CORE) += abx500-core.o
61obj-$(CONFIG_AB3100_CORE) += ab3100-core.o 65obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
62obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o 66obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o
63obj-$(CONFIG_AB4500_CORE) += ab4500-core.o 67obj-$(CONFIG_AB3550_CORE) += ab3550-core.o
68obj-$(CONFIG_AB8500_CORE) += ab8500-core.o ab8500-spi.o
64obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o 69obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o
65obj-$(CONFIG_PMIC_ADP5520) += adp5520.o 70obj-$(CONFIG_PMIC_ADP5520) += adp5520.o
66obj-$(CONFIG_LPC_SCH) += lpc_sch.o \ No newline at end of file 71obj-$(CONFIG_LPC_SCH) += lpc_sch.o
72obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o
73obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o
diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
index e4ca5909e424..53ebfee548fa 100644
--- a/drivers/mfd/ab3100-core.c
+++ b/drivers/mfd/ab3100-core.c
@@ -19,7 +19,7 @@
19#include <linux/debugfs.h> 19#include <linux/debugfs.h>
20#include <linux/seq_file.h> 20#include <linux/seq_file.h>
21#include <linux/uaccess.h> 21#include <linux/uaccess.h>
22#include <linux/mfd/ab3100.h> 22#include <linux/mfd/abx500.h>
23 23
24/* These are the only registers inside AB3100 used in this main file */ 24/* These are the only registers inside AB3100 used in this main file */
25 25
@@ -59,24 +59,15 @@
59 * The AB3100 is usually assigned address 0x48 (7-bit) 59 * The AB3100 is usually assigned address 0x48 (7-bit)
60 * The chip is defined in the platform i2c_board_data section. 60 * The chip is defined in the platform i2c_board_data section.
61 */ 61 */
62 62static int ab3100_get_chip_id(struct device *dev)
63u8 ab3100_get_chip_type(struct ab3100 *ab3100)
64{ 63{
65 u8 chip = ABUNKNOWN; 64 struct ab3100 *ab3100 = dev_get_drvdata(dev->parent);
66 65
67 switch (ab3100->chip_id & 0xf0) { 66 return (int)ab3100->chip_id;
68 case 0xa0:
69 chip = AB3000;
70 break;
71 case 0xc0:
72 chip = AB3100;
73 break;
74 }
75 return chip;
76} 67}
77EXPORT_SYMBOL(ab3100_get_chip_type);
78 68
79int ab3100_set_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 regval) 69static int ab3100_set_register_interruptible(struct ab3100 *ab3100,
70 u8 reg, u8 regval)
80{ 71{
81 u8 regandval[2] = {reg, regval}; 72 u8 regandval[2] = {reg, regval};
82 int err; 73 int err;
@@ -108,8 +99,14 @@ int ab3100_set_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 regval)
108 mutex_unlock(&ab3100->access_mutex); 99 mutex_unlock(&ab3100->access_mutex);
109 return err; 100 return err;
110} 101}
111EXPORT_SYMBOL(ab3100_set_register_interruptible);
112 102
103static int set_register_interruptible(struct device *dev,
104 u8 bank, u8 reg, u8 value)
105{
106 struct ab3100 *ab3100 = dev_get_drvdata(dev->parent);
107
108 return ab3100_set_register_interruptible(ab3100, reg, value);
109}
113 110
114/* 111/*
115 * The test registers exist at an I2C bus address up one 112 * The test registers exist at an I2C bus address up one
@@ -148,8 +145,8 @@ static int ab3100_set_test_register_interruptible(struct ab3100 *ab3100,
148 return err; 145 return err;
149} 146}
150 147
151 148static int ab3100_get_register_interruptible(struct ab3100 *ab3100,
152int ab3100_get_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 *regval) 149 u8 reg, u8 *regval)
153{ 150{
154 int err; 151 int err;
155 152
@@ -203,10 +200,16 @@ int ab3100_get_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 *regval)
203 mutex_unlock(&ab3100->access_mutex); 200 mutex_unlock(&ab3100->access_mutex);
204 return err; 201 return err;
205} 202}
206EXPORT_SYMBOL(ab3100_get_register_interruptible);
207 203
204static int get_register_interruptible(struct device *dev, u8 bank, u8 reg,
205 u8 *value)
206{
207 struct ab3100 *ab3100 = dev_get_drvdata(dev->parent);
208
209 return ab3100_get_register_interruptible(ab3100, reg, value);
210}
208 211
209int ab3100_get_register_page_interruptible(struct ab3100 *ab3100, 212static int ab3100_get_register_page_interruptible(struct ab3100 *ab3100,
210 u8 first_reg, u8 *regvals, u8 numregs) 213 u8 first_reg, u8 *regvals, u8 numregs)
211{ 214{
212 int err; 215 int err;
@@ -260,10 +263,17 @@ int ab3100_get_register_page_interruptible(struct ab3100 *ab3100,
260 mutex_unlock(&ab3100->access_mutex); 263 mutex_unlock(&ab3100->access_mutex);
261 return err; 264 return err;
262} 265}
263EXPORT_SYMBOL(ab3100_get_register_page_interruptible);
264 266
267static int get_register_page_interruptible(struct device *dev, u8 bank,
268 u8 first_reg, u8 *regvals, u8 numregs)
269{
270 struct ab3100 *ab3100 = dev_get_drvdata(dev->parent);
271
272 return ab3100_get_register_page_interruptible(ab3100,
273 first_reg, regvals, numregs);
274}
265 275
266int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100, 276static int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100,
267 u8 reg, u8 andmask, u8 ormask) 277 u8 reg, u8 andmask, u8 ormask)
268{ 278{
269 u8 regandval[2] = {reg, 0}; 279 u8 regandval[2] = {reg, 0};
@@ -331,8 +341,15 @@ int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100,
331 mutex_unlock(&ab3100->access_mutex); 341 mutex_unlock(&ab3100->access_mutex);
332 return err; 342 return err;
333} 343}
334EXPORT_SYMBOL(ab3100_mask_and_set_register_interruptible);
335 344
345static int mask_and_set_register_interruptible(struct device *dev, u8 bank,
346 u8 reg, u8 bitmask, u8 bitvalues)
347{
348 struct ab3100 *ab3100 = dev_get_drvdata(dev->parent);
349
350 return ab3100_mask_and_set_register_interruptible(ab3100,
351 reg, bitmask, (bitmask & bitvalues));
352}
336 353
337/* 354/*
338 * Register a simple callback for handling any AB3100 events. 355 * Register a simple callback for handling any AB3100 events.
@@ -357,15 +374,27 @@ int ab3100_event_unregister(struct ab3100 *ab3100,
357EXPORT_SYMBOL(ab3100_event_unregister); 374EXPORT_SYMBOL(ab3100_event_unregister);
358 375
359 376
360int ab3100_event_registers_startup_state_get(struct ab3100 *ab3100, 377static int ab3100_event_registers_startup_state_get(struct device *dev,
361 u32 *fatevent) 378 u8 *event)
362{ 379{
380 struct ab3100 *ab3100 = dev_get_drvdata(dev->parent);
363 if (!ab3100->startup_events_read) 381 if (!ab3100->startup_events_read)
364 return -EAGAIN; /* Try again later */ 382 return -EAGAIN; /* Try again later */
365 *fatevent = ab3100->startup_events; 383 memcpy(event, ab3100->startup_events, 3);
366 return 0; 384 return 0;
367} 385}
368EXPORT_SYMBOL(ab3100_event_registers_startup_state_get); 386
387static struct abx500_ops ab3100_ops = {
388 .get_chip_id = ab3100_get_chip_id,
389 .set_register = set_register_interruptible,
390 .get_register = get_register_interruptible,
391 .get_register_page = get_register_page_interruptible,
392 .set_register_page = NULL,
393 .mask_and_set_register = mask_and_set_register_interruptible,
394 .event_registers_startup_state_get =
395 ab3100_event_registers_startup_state_get,
396 .startup_irq_enabled = NULL,
397};
369 398
370/* 399/*
371 * This is a threaded interrupt handler so we can make some 400 * This is a threaded interrupt handler so we can make some
@@ -390,7 +419,9 @@ static irqreturn_t ab3100_irq_handler(int irq, void *data)
390 event_regs[2]; 419 event_regs[2];
391 420
392 if (!ab3100->startup_events_read) { 421 if (!ab3100->startup_events_read) {
393 ab3100->startup_events = fatevent; 422 ab3100->startup_events[0] = event_regs[0];
423 ab3100->startup_events[1] = event_regs[1];
424 ab3100->startup_events[2] = event_regs[2];
394 ab3100->startup_events_read = true; 425 ab3100->startup_events_read = true;
395 } 426 }
396 /* 427 /*
@@ -703,7 +734,8 @@ static int __init ab3100_setup(struct ab3100 *ab3100)
703 dev_warn(ab3100->dev, 734 dev_warn(ab3100->dev,
704 "AB3100 P1E variant detected, " 735 "AB3100 P1E variant detected, "
705 "forcing chip to 32KHz\n"); 736 "forcing chip to 32KHz\n");
706 err = ab3100_set_test_register_interruptible(ab3100, 0x02, 0x08); 737 err = ab3100_set_test_register_interruptible(ab3100,
738 0x02, 0x08);
707 } 739 }
708 740
709 exit_no_setup: 741 exit_no_setup:
@@ -898,6 +930,10 @@ static int __init ab3100_probe(struct i2c_client *client,
898 if (err) 930 if (err)
899 goto exit_no_irq; 931 goto exit_no_irq;
900 932
933 err = abx500_register_ops(&client->dev, &ab3100_ops);
934 if (err)
935 goto exit_no_ops;
936
901 /* Set parent and a pointer back to the container in device data */ 937 /* Set parent and a pointer back to the container in device data */
902 for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++) { 938 for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++) {
903 ab3100_platform_devs[i]->dev.parent = 939 ab3100_platform_devs[i]->dev.parent =
@@ -915,11 +951,13 @@ static int __init ab3100_probe(struct i2c_client *client,
915 951
916 return 0; 952 return 0;
917 953
954 exit_no_ops:
918 exit_no_irq: 955 exit_no_irq:
919 exit_no_setup: 956 exit_no_setup:
920 i2c_unregister_device(ab3100->testreg_client); 957 i2c_unregister_device(ab3100->testreg_client);
921 exit_no_testreg_client: 958 exit_no_testreg_client:
922 exit_no_detect: 959 exit_no_detect:
960 i2c_set_clientdata(client, NULL);
923 kfree(ab3100); 961 kfree(ab3100);
924 return err; 962 return err;
925} 963}
@@ -941,6 +979,7 @@ static int __exit ab3100_remove(struct i2c_client *client)
941 * their notifiers so deactivate IRQ 979 * their notifiers so deactivate IRQ
942 */ 980 */
943 free_irq(client->irq, ab3100); 981 free_irq(client->irq, ab3100);
982 i2c_set_clientdata(client, NULL);
944 kfree(ab3100); 983 kfree(ab3100);
945 return 0; 984 return 0;
946} 985}
diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c
index 2d14655fdebd..63d2b727ddbb 100644
--- a/drivers/mfd/ab3100-otp.c
+++ b/drivers/mfd/ab3100-otp.c
@@ -12,7 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/mfd/ab3100.h> 15#include <linux/mfd/abx500.h>
16#include <linux/debugfs.h> 16#include <linux/debugfs.h>
17#include <linux/seq_file.h> 17#include <linux/seq_file.h>
18 18
@@ -30,7 +30,6 @@
30/** 30/**
31 * struct ab3100_otp 31 * struct ab3100_otp
32 * @dev containing device 32 * @dev containing device
33 * @ab3100 a pointer to the parent ab3100 device struct
34 * @locked whether the OTP is locked, after locking, no more bits 33 * @locked whether the OTP is locked, after locking, no more bits
35 * can be changed but before locking it is still possible 34 * can be changed but before locking it is still possible
36 * to change bits from 1->0. 35 * to change bits from 1->0.
@@ -49,7 +48,6 @@
49 */ 48 */
50struct ab3100_otp { 49struct ab3100_otp {
51 struct device *dev; 50 struct device *dev;
52 struct ab3100 *ab3100;
53 bool locked; 51 bool locked;
54 u32 freq; 52 u32 freq;
55 bool paf; 53 bool paf;
@@ -63,19 +61,19 @@ struct ab3100_otp {
63 61
64static int __init ab3100_otp_read(struct ab3100_otp *otp) 62static int __init ab3100_otp_read(struct ab3100_otp *otp)
65{ 63{
66 struct ab3100 *ab = otp->ab3100;
67 u8 otpval[8]; 64 u8 otpval[8];
68 u8 otpp; 65 u8 otpp;
69 int err; 66 int err;
70 67
71 err = ab3100_get_register_interruptible(ab, AB3100_OTPP, &otpp); 68 err = abx500_get_register_interruptible(otp->dev, 0,
69 AB3100_OTPP, &otpp);
72 if (err) { 70 if (err) {
73 dev_err(otp->dev, "unable to read OTPP register\n"); 71 dev_err(otp->dev, "unable to read OTPP register\n");
74 return err; 72 return err;
75 } 73 }
76 74
77 err = ab3100_get_register_page_interruptible(ab, AB3100_OTP0, 75 err = abx500_get_register_page_interruptible(otp->dev, 0,
78 otpval, 8); 76 AB3100_OTP0, otpval, 8);
79 if (err) { 77 if (err) {
80 dev_err(otp->dev, "unable to read OTP register page\n"); 78 dev_err(otp->dev, "unable to read OTP register page\n");
81 return err; 79 return err;
@@ -197,7 +195,6 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
197 otp->dev = &pdev->dev; 195 otp->dev = &pdev->dev;
198 196
199 /* Replace platform data coming in with a local struct */ 197 /* Replace platform data coming in with a local struct */
200 otp->ab3100 = platform_get_drvdata(pdev);
201 platform_set_drvdata(pdev, otp); 198 platform_set_drvdata(pdev, otp);
202 199
203 err = ab3100_otp_read(otp); 200 err = ab3100_otp_read(otp);
diff --git a/drivers/mfd/ab3550-core.c b/drivers/mfd/ab3550-core.c
new file mode 100644
index 000000000000..1060f8e1c40a
--- /dev/null
+++ b/drivers/mfd/ab3550-core.c
@@ -0,0 +1,1401 @@
1/*
2 * Copyright (C) 2007-2010 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Low-level core for exclusive access to the AB3550 IC on the I2C bus
5 * and some basic chip-configuration.
6 * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
7 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
8 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
9 * Author: Rickard Andersson <rickard.andersson@stericsson.com>
10 */
11
12#include <linux/i2c.h>
13#include <linux/mutex.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/device.h>
18#include <linux/irq.h>
19#include <linux/interrupt.h>
20#include <linux/random.h>
21#include <linux/workqueue.h>
22#include <linux/debugfs.h>
23#include <linux/seq_file.h>
24#include <linux/uaccess.h>
25#include <linux/mfd/abx500.h>
26#include <linux/list.h>
27#include <linux/bitops.h>
28#include <linux/spinlock.h>
29#include <linux/mfd/core.h>
30
31#define AB3550_NAME_STRING "ab3550"
32#define AB3550_ID_FORMAT_STRING "AB3550 %s"
33#define AB3550_NUM_BANKS 2
34#define AB3550_NUM_EVENT_REG 5
35
36/* These are the only registers inside AB3550 used in this main file */
37
38/* Chip ID register */
39#define AB3550_CID_REG 0x20
40
41/* Interrupt event registers */
42#define AB3550_EVENT_BANK 0
43#define AB3550_EVENT_REG 0x22
44
45/* Read/write operation values. */
46#define AB3550_PERM_RD (0x01)
47#define AB3550_PERM_WR (0x02)
48
49/* Read/write permissions. */
50#define AB3550_PERM_RO (AB3550_PERM_RD)
51#define AB3550_PERM_RW (AB3550_PERM_RD | AB3550_PERM_WR)
52
53/**
54 * struct ab3550
55 * @access_mutex: lock out concurrent accesses to the AB registers
56 * @i2c_client: I2C client for this chip
57 * @chip_name: name of this chip variant
58 * @chip_id: 8 bit chip ID for this chip variant
59 * @mask_work: a worker for writing to mask registers
60 * @event_lock: a lock to protect the event_mask
61 * @event_mask: a local copy of the mask event registers
62 * @startup_events: a copy of the first reading of the event registers
63 * @startup_events_read: whether the first events have been read
64 */
65struct ab3550 {
66 struct mutex access_mutex;
67 struct i2c_client *i2c_client[AB3550_NUM_BANKS];
68 char chip_name[32];
69 u8 chip_id;
70 struct work_struct mask_work;
71 spinlock_t event_lock;
72 u8 event_mask[AB3550_NUM_EVENT_REG];
73 u8 startup_events[AB3550_NUM_EVENT_REG];
74 bool startup_events_read;
75#ifdef CONFIG_DEBUG_FS
76 unsigned int debug_bank;
77 unsigned int debug_address;
78#endif
79};
80
81/**
82 * struct ab3550_reg_range
83 * @first: the first address of the range
84 * @last: the last address of the range
85 * @perm: access permissions for the range
86 */
87struct ab3550_reg_range {
88 u8 first;
89 u8 last;
90 u8 perm;
91};
92
93/**
94 * struct ab3550_reg_ranges
95 * @count: the number of ranges in the list
96 * @range: the list of register ranges
97 */
98struct ab3550_reg_ranges {
99 u8 count;
100 const struct ab3550_reg_range *range;
101};
102
103/*
104 * Permissible register ranges for reading and writing per device and bank.
105 *
106 * The ranges must be listed in increasing address order, and no overlaps are
107 * allowed. It is assumed that write permission implies read permission
108 * (i.e. only RO and RW permissions should be used). Ranges with write
109 * permission must not be split up.
110 */
111
112#define NO_RANGE {.count = 0, .range = NULL,}
113
114static struct
115ab3550_reg_ranges ab3550_reg_ranges[AB3550_NUM_DEVICES][AB3550_NUM_BANKS] = {
116 [AB3550_DEVID_DAC] = {
117 NO_RANGE,
118 {
119 .count = 2,
120 .range = (struct ab3550_reg_range[]) {
121 {
122 .first = 0xb0,
123 .last = 0xba,
124 .perm = AB3550_PERM_RW,
125 },
126 {
127 .first = 0xbc,
128 .last = 0xc3,
129 .perm = AB3550_PERM_RW,
130 },
131 },
132 },
133 },
134 [AB3550_DEVID_LEDS] = {
135 NO_RANGE,
136 {
137 .count = 2,
138 .range = (struct ab3550_reg_range[]) {
139 {
140 .first = 0x5a,
141 .last = 0x88,
142 .perm = AB3550_PERM_RW,
143 },
144 {
145 .first = 0x8a,
146 .last = 0xad,
147 .perm = AB3550_PERM_RW,
148 },
149 }
150 },
151 },
152 [AB3550_DEVID_POWER] = {
153 {
154 .count = 1,
155 .range = (struct ab3550_reg_range[]) {
156 {
157 .first = 0x21,
158 .last = 0x21,
159 .perm = AB3550_PERM_RO,
160 },
161 }
162 },
163 NO_RANGE,
164 },
165 [AB3550_DEVID_REGULATORS] = {
166 {
167 .count = 1,
168 .range = (struct ab3550_reg_range[]) {
169 {
170 .first = 0x69,
171 .last = 0xa3,
172 .perm = AB3550_PERM_RW,
173 },
174 }
175 },
176 {
177 .count = 1,
178 .range = (struct ab3550_reg_range[]) {
179 {
180 .first = 0x14,
181 .last = 0x16,
182 .perm = AB3550_PERM_RW,
183 },
184 }
185 },
186 },
187 [AB3550_DEVID_SIM] = {
188 {
189 .count = 1,
190 .range = (struct ab3550_reg_range[]) {
191 {
192 .first = 0x21,
193 .last = 0x21,
194 .perm = AB3550_PERM_RO,
195 },
196 }
197 },
198 {
199 .count = 1,
200 .range = (struct ab3550_reg_range[]) {
201 {
202 .first = 0x14,
203 .last = 0x17,
204 .perm = AB3550_PERM_RW,
205 },
206 }
207
208 },
209 },
210 [AB3550_DEVID_UART] = {
211 NO_RANGE,
212 NO_RANGE,
213 },
214 [AB3550_DEVID_RTC] = {
215 {
216 .count = 1,
217 .range = (struct ab3550_reg_range[]) {
218 {
219 .first = 0x00,
220 .last = 0x0c,
221 .perm = AB3550_PERM_RW,
222 },
223 }
224 },
225 NO_RANGE,
226 },
227 [AB3550_DEVID_CHARGER] = {
228 {
229 .count = 2,
230 .range = (struct ab3550_reg_range[]) {
231 {
232 .first = 0x10,
233 .last = 0x1a,
234 .perm = AB3550_PERM_RW,
235 },
236 {
237 .first = 0x21,
238 .last = 0x21,
239 .perm = AB3550_PERM_RO,
240 },
241 }
242 },
243 NO_RANGE,
244 },
245 [AB3550_DEVID_ADC] = {
246 NO_RANGE,
247 {
248 .count = 1,
249 .range = (struct ab3550_reg_range[]) {
250 {
251 .first = 0x20,
252 .last = 0x56,
253 .perm = AB3550_PERM_RW,
254 },
255
256 }
257 },
258 },
259 [AB3550_DEVID_FUELGAUGE] = {
260 {
261 .count = 1,
262 .range = (struct ab3550_reg_range[]) {
263 {
264 .first = 0x21,
265 .last = 0x21,
266 .perm = AB3550_PERM_RO,
267 },
268 }
269 },
270 {
271 .count = 1,
272 .range = (struct ab3550_reg_range[]) {
273 {
274 .first = 0x00,
275 .last = 0x0e,
276 .perm = AB3550_PERM_RW,
277 },
278 }
279 },
280 },
281 [AB3550_DEVID_VIBRATOR] = {
282 NO_RANGE,
283 {
284 .count = 1,
285 .range = (struct ab3550_reg_range[]) {
286 {
287 .first = 0x10,
288 .last = 0x13,
289 .perm = AB3550_PERM_RW,
290 },
291
292 }
293 },
294 },
295 [AB3550_DEVID_CODEC] = {
296 {
297 .count = 2,
298 .range = (struct ab3550_reg_range[]) {
299 {
300 .first = 0x31,
301 .last = 0x63,
302 .perm = AB3550_PERM_RW,
303 },
304 {
305 .first = 0x65,
306 .last = 0x68,
307 .perm = AB3550_PERM_RW,
308 },
309 }
310 },
311 NO_RANGE,
312 },
313};
314
315static struct mfd_cell ab3550_devs[AB3550_NUM_DEVICES] = {
316 [AB3550_DEVID_DAC] = {
317 .name = "ab3550-dac",
318 .id = AB3550_DEVID_DAC,
319 .num_resources = 0,
320 },
321 [AB3550_DEVID_LEDS] = {
322 .name = "ab3550-leds",
323 .id = AB3550_DEVID_LEDS,
324 },
325 [AB3550_DEVID_POWER] = {
326 .name = "ab3550-power",
327 .id = AB3550_DEVID_POWER,
328 },
329 [AB3550_DEVID_REGULATORS] = {
330 .name = "ab3550-regulators",
331 .id = AB3550_DEVID_REGULATORS,
332 },
333 [AB3550_DEVID_SIM] = {
334 .name = "ab3550-sim",
335 .id = AB3550_DEVID_SIM,
336 },
337 [AB3550_DEVID_UART] = {
338 .name = "ab3550-uart",
339 .id = AB3550_DEVID_UART,
340 },
341 [AB3550_DEVID_RTC] = {
342 .name = "ab3550-rtc",
343 .id = AB3550_DEVID_RTC,
344 },
345 [AB3550_DEVID_CHARGER] = {
346 .name = "ab3550-charger",
347 .id = AB3550_DEVID_CHARGER,
348 },
349 [AB3550_DEVID_ADC] = {
350 .name = "ab3550-adc",
351 .id = AB3550_DEVID_ADC,
352 .num_resources = 10,
353 .resources = (struct resource[]) {
354 {
355 .name = "TRIGGER-0",
356 .flags = IORESOURCE_IRQ,
357 .start = 16,
358 .end = 16,
359 },
360 {
361 .name = "TRIGGER-1",
362 .flags = IORESOURCE_IRQ,
363 .start = 17,
364 .end = 17,
365 },
366 {
367 .name = "TRIGGER-2",
368 .flags = IORESOURCE_IRQ,
369 .start = 18,
370 .end = 18,
371 },
372 {
373 .name = "TRIGGER-3",
374 .flags = IORESOURCE_IRQ,
375 .start = 19,
376 .end = 19,
377 },
378 {
379 .name = "TRIGGER-4",
380 .flags = IORESOURCE_IRQ,
381 .start = 20,
382 .end = 20,
383 },
384 {
385 .name = "TRIGGER-5",
386 .flags = IORESOURCE_IRQ,
387 .start = 21,
388 .end = 21,
389 },
390 {
391 .name = "TRIGGER-6",
392 .flags = IORESOURCE_IRQ,
393 .start = 22,
394 .end = 22,
395 },
396 {
397 .name = "TRIGGER-7",
398 .flags = IORESOURCE_IRQ,
399 .start = 23,
400 .end = 23,
401 },
402 {
403 .name = "TRIGGER-VBAT-TXON",
404 .flags = IORESOURCE_IRQ,
405 .start = 13,
406 .end = 13,
407 },
408 {
409 .name = "TRIGGER-VBAT",
410 .flags = IORESOURCE_IRQ,
411 .start = 12,
412 .end = 12,
413 },
414 },
415 },
416 [AB3550_DEVID_FUELGAUGE] = {
417 .name = "ab3550-fuelgauge",
418 .id = AB3550_DEVID_FUELGAUGE,
419 },
420 [AB3550_DEVID_VIBRATOR] = {
421 .name = "ab3550-vibrator",
422 .id = AB3550_DEVID_VIBRATOR,
423 },
424 [AB3550_DEVID_CODEC] = {
425 .name = "ab3550-codec",
426 .id = AB3550_DEVID_CODEC,
427 },
428};
429
430/*
431 * I2C transactions with error messages.
432 */
433static int ab3550_i2c_master_send(struct ab3550 *ab, u8 bank, u8 *data,
434 u8 count)
435{
436 int err;
437
438 err = i2c_master_send(ab->i2c_client[bank], data, count);
439 if (err < 0) {
440 dev_err(&ab->i2c_client[0]->dev, "send error: %d\n", err);
441 return err;
442 }
443 return 0;
444}
445
446static int ab3550_i2c_master_recv(struct ab3550 *ab, u8 bank, u8 *data,
447 u8 count)
448{
449 int err;
450
451 err = i2c_master_recv(ab->i2c_client[bank], data, count);
452 if (err < 0) {
453 dev_err(&ab->i2c_client[0]->dev, "receive error: %d\n", err);
454 return err;
455 }
456 return 0;
457}
458
459/*
460 * Functionality for getting/setting register values.
461 */
462static int get_register_interruptible(struct ab3550 *ab, u8 bank, u8 reg,
463 u8 *value)
464{
465 int err;
466
467 err = mutex_lock_interruptible(&ab->access_mutex);
468 if (err)
469 return err;
470
471 err = ab3550_i2c_master_send(ab, bank, &reg, 1);
472 if (!err)
473 err = ab3550_i2c_master_recv(ab, bank, value, 1);
474
475 mutex_unlock(&ab->access_mutex);
476 return err;
477}
478
479static int get_register_page_interruptible(struct ab3550 *ab, u8 bank,
480 u8 first_reg, u8 *regvals, u8 numregs)
481{
482 int err;
483
484 err = mutex_lock_interruptible(&ab->access_mutex);
485 if (err)
486 return err;
487
488 err = ab3550_i2c_master_send(ab, bank, &first_reg, 1);
489 if (!err)
490 err = ab3550_i2c_master_recv(ab, bank, regvals, numregs);
491
492 mutex_unlock(&ab->access_mutex);
493 return err;
494}
495
496static int mask_and_set_register_interruptible(struct ab3550 *ab, u8 bank,
497 u8 reg, u8 bitmask, u8 bitvalues)
498{
499 int err = 0;
500
501 if (likely(bitmask)) {
502 u8 reg_bits[2] = {reg, 0};
503
504 err = mutex_lock_interruptible(&ab->access_mutex);
505 if (err)
506 return err;
507
508 if (bitmask == 0xFF) /* No need to read in this case. */
509 reg_bits[1] = bitvalues;
510 else { /* Read and modify the register value. */
511 u8 bits;
512
513 err = ab3550_i2c_master_send(ab, bank, &reg, 1);
514 if (err)
515 goto unlock_and_return;
516 err = ab3550_i2c_master_recv(ab, bank, &bits, 1);
517 if (err)
518 goto unlock_and_return;
519 reg_bits[1] = ((~bitmask & bits) |
520 (bitmask & bitvalues));
521 }
522 /* Write the new value. */
523 err = ab3550_i2c_master_send(ab, bank, reg_bits, 2);
524unlock_and_return:
525 mutex_unlock(&ab->access_mutex);
526 }
527 return err;
528}
529
530/*
531 * Read/write permission checking functions.
532 */
533static bool page_write_allowed(const struct ab3550_reg_ranges *ranges,
534 u8 first_reg, u8 last_reg)
535{
536 u8 i;
537
538 if (last_reg < first_reg)
539 return false;
540
541 for (i = 0; i < ranges->count; i++) {
542 if (first_reg < ranges->range[i].first)
543 break;
544 if ((last_reg <= ranges->range[i].last) &&
545 (ranges->range[i].perm & AB3550_PERM_WR))
546 return true;
547 }
548 return false;
549}
550
551static bool reg_write_allowed(const struct ab3550_reg_ranges *ranges, u8 reg)
552{
553 return page_write_allowed(ranges, reg, reg);
554}
555
556static bool page_read_allowed(const struct ab3550_reg_ranges *ranges,
557 u8 first_reg, u8 last_reg)
558{
559 u8 i;
560
561 if (last_reg < first_reg)
562 return false;
563 /* Find the range (if it exists in the list) that includes first_reg. */
564 for (i = 0; i < ranges->count; i++) {
565 if (first_reg < ranges->range[i].first)
566 return false;
567 if (first_reg <= ranges->range[i].last)
568 break;
569 }
570 /* Make sure that the entire range up to and including last_reg is
571 * readable. This may span several of the ranges in the list.
572 */
573 while ((i < ranges->count) &&
574 (ranges->range[i].perm & AB3550_PERM_RD)) {
575 if (last_reg <= ranges->range[i].last)
576 return true;
577 if ((++i >= ranges->count) ||
578 (ranges->range[i].first !=
579 (ranges->range[i - 1].last + 1))) {
580 break;
581 }
582 }
583 return false;
584}
585
586static bool reg_read_allowed(const struct ab3550_reg_ranges *ranges, u8 reg)
587{
588 return page_read_allowed(ranges, reg, reg);
589}
590
591/*
592 * The exported register access functionality.
593 */
594int ab3550_get_chip_id(struct device *dev)
595{
596 struct ab3550 *ab = dev_get_drvdata(dev->parent);
597 return (int)ab->chip_id;
598}
599
600int ab3550_mask_and_set_register_interruptible(struct device *dev, u8 bank,
601 u8 reg, u8 bitmask, u8 bitvalues)
602{
603 struct ab3550 *ab;
604 struct platform_device *pdev = to_platform_device(dev);
605
606 if ((AB3550_NUM_BANKS <= bank) ||
607 !reg_write_allowed(&ab3550_reg_ranges[pdev->id][bank], reg))
608 return -EINVAL;
609
610 ab = dev_get_drvdata(dev->parent);
611 return mask_and_set_register_interruptible(ab, bank, reg,
612 bitmask, bitvalues);
613}
614
615int ab3550_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
616 u8 value)
617{
618 return ab3550_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
619 value);
620}
621
622int ab3550_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
623 u8 *value)
624{
625 struct ab3550 *ab;
626 struct platform_device *pdev = to_platform_device(dev);
627
628 if ((AB3550_NUM_BANKS <= bank) ||
629 !reg_read_allowed(&ab3550_reg_ranges[pdev->id][bank], reg))
630 return -EINVAL;
631
632 ab = dev_get_drvdata(dev->parent);
633 return get_register_interruptible(ab, bank, reg, value);
634}
635
636int ab3550_get_register_page_interruptible(struct device *dev, u8 bank,
637 u8 first_reg, u8 *regvals, u8 numregs)
638{
639 struct ab3550 *ab;
640 struct platform_device *pdev = to_platform_device(dev);
641
642 if ((AB3550_NUM_BANKS <= bank) ||
643 !page_read_allowed(&ab3550_reg_ranges[pdev->id][bank],
644 first_reg, (first_reg + numregs - 1)))
645 return -EINVAL;
646
647 ab = dev_get_drvdata(dev->parent);
648 return get_register_page_interruptible(ab, bank, first_reg, regvals,
649 numregs);
650}
651
652int ab3550_event_registers_startup_state_get(struct device *dev, u8 *event)
653{
654 struct ab3550 *ab;
655
656 ab = dev_get_drvdata(dev->parent);
657 if (!ab->startup_events_read)
658 return -EAGAIN; /* Try again later */
659
660 memcpy(event, ab->startup_events, AB3550_NUM_EVENT_REG);
661 return 0;
662}
663
664int ab3550_startup_irq_enabled(struct device *dev, unsigned int irq)
665{
666 struct ab3550 *ab;
667 struct ab3550_platform_data *plf_data;
668 bool val;
669
670 ab = get_irq_chip_data(irq);
671 plf_data = ab->i2c_client[0]->dev.platform_data;
672 irq -= plf_data->irq.base;
673 val = ((ab->startup_events[irq / 8] & BIT(irq % 8)) != 0);
674
675 return val;
676}
677
678static struct abx500_ops ab3550_ops = {
679 .get_chip_id = ab3550_get_chip_id,
680 .get_register = ab3550_get_register_interruptible,
681 .set_register = ab3550_set_register_interruptible,
682 .get_register_page = ab3550_get_register_page_interruptible,
683 .set_register_page = NULL,
684 .mask_and_set_register = ab3550_mask_and_set_register_interruptible,
685 .event_registers_startup_state_get =
686 ab3550_event_registers_startup_state_get,
687 .startup_irq_enabled = ab3550_startup_irq_enabled,
688};
689
690static irqreturn_t ab3550_irq_handler(int irq, void *data)
691{
692 struct ab3550 *ab = data;
693 int err;
694 unsigned int i;
695 u8 e[AB3550_NUM_EVENT_REG];
696 u8 *events;
697 unsigned long flags;
698
699 events = (ab->startup_events_read ? e : ab->startup_events);
700
701 err = get_register_page_interruptible(ab, AB3550_EVENT_BANK,
702 AB3550_EVENT_REG, events, AB3550_NUM_EVENT_REG);
703 if (err)
704 goto err_event_rd;
705
706 if (!ab->startup_events_read) {
707 dev_info(&ab->i2c_client[0]->dev,
708 "startup events 0x%x,0x%x,0x%x,0x%x,0x%x\n",
709 ab->startup_events[0], ab->startup_events[1],
710 ab->startup_events[2], ab->startup_events[3],
711 ab->startup_events[4]);
712 ab->startup_events_read = true;
713 goto out;
714 }
715
716 /* The two highest bits in event[4] are not used. */
717 events[4] &= 0x3f;
718
719 spin_lock_irqsave(&ab->event_lock, flags);
720 for (i = 0; i < AB3550_NUM_EVENT_REG; i++)
721 events[i] &= ~ab->event_mask[i];
722 spin_unlock_irqrestore(&ab->event_lock, flags);
723
724 for (i = 0; i < AB3550_NUM_EVENT_REG; i++) {
725 u8 bit;
726 u8 event_reg;
727
728 dev_dbg(&ab->i2c_client[0]->dev, "IRQ Event[%d]: 0x%2x\n",
729 i, events[i]);
730
731 event_reg = events[i];
732 for (bit = 0; event_reg; bit++, event_reg /= 2) {
733 if (event_reg % 2) {
734 unsigned int irq;
735 struct ab3550_platform_data *plf_data;
736
737 plf_data = ab->i2c_client[0]->dev.platform_data;
738 irq = plf_data->irq.base + (i * 8) + bit;
739 handle_nested_irq(irq);
740 }
741 }
742 }
743out:
744 return IRQ_HANDLED;
745
746err_event_rd:
747 dev_dbg(&ab->i2c_client[0]->dev, "error reading event registers\n");
748 return IRQ_HANDLED;
749}
750
751#ifdef CONFIG_DEBUG_FS
752static struct ab3550_reg_ranges debug_ranges[AB3550_NUM_BANKS] = {
753 {
754 .count = 6,
755 .range = (struct ab3550_reg_range[]) {
756 {
757 .first = 0x00,
758 .last = 0x0e,
759 },
760 {
761 .first = 0x10,
762 .last = 0x1a,
763 },
764 {
765 .first = 0x1e,
766 .last = 0x4f,
767 },
768 {
769 .first = 0x51,
770 .last = 0x63,
771 },
772 {
773 .first = 0x65,
774 .last = 0xa3,
775 },
776 {
777 .first = 0xa5,
778 .last = 0xa8,
779 },
780 }
781 },
782 {
783 .count = 8,
784 .range = (struct ab3550_reg_range[]) {
785 {
786 .first = 0x00,
787 .last = 0x0e,
788 },
789 {
790 .first = 0x10,
791 .last = 0x17,
792 },
793 {
794 .first = 0x1a,
795 .last = 0x1c,
796 },
797 {
798 .first = 0x20,
799 .last = 0x56,
800 },
801 {
802 .first = 0x5a,
803 .last = 0x88,
804 },
805 {
806 .first = 0x8a,
807 .last = 0xad,
808 },
809 {
810 .first = 0xb0,
811 .last = 0xba,
812 },
813 {
814 .first = 0xbc,
815 .last = 0xc3,
816 },
817 }
818 },
819};
820
821static int ab3550_registers_print(struct seq_file *s, void *p)
822{
823 struct ab3550 *ab = s->private;
824 int bank;
825
826 seq_printf(s, AB3550_NAME_STRING " register values:\n");
827
828 for (bank = 0; bank < AB3550_NUM_BANKS; bank++) {
829 unsigned int i;
830
831 seq_printf(s, " bank %d:\n", bank);
832 for (i = 0; i < debug_ranges[bank].count; i++) {
833 u8 reg;
834
835 for (reg = debug_ranges[bank].range[i].first;
836 reg <= debug_ranges[bank].range[i].last;
837 reg++) {
838 u8 value;
839
840 get_register_interruptible(ab, bank, reg,
841 &value);
842 seq_printf(s, " [%d/0x%02X]: 0x%02X\n", bank,
843 reg, value);
844 }
845 }
846 }
847 return 0;
848}
849
850static int ab3550_registers_open(struct inode *inode, struct file *file)
851{
852 return single_open(file, ab3550_registers_print, inode->i_private);
853}
854
855static const struct file_operations ab3550_registers_fops = {
856 .open = ab3550_registers_open,
857 .read = seq_read,
858 .llseek = seq_lseek,
859 .release = single_release,
860 .owner = THIS_MODULE,
861};
862
863static int ab3550_bank_print(struct seq_file *s, void *p)
864{
865 struct ab3550 *ab = s->private;
866
867 seq_printf(s, "%d\n", ab->debug_bank);
868 return 0;
869}
870
871static int ab3550_bank_open(struct inode *inode, struct file *file)
872{
873 return single_open(file, ab3550_bank_print, inode->i_private);
874}
875
876static ssize_t ab3550_bank_write(struct file *file,
877 const char __user *user_buf,
878 size_t count, loff_t *ppos)
879{
880 struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
881 char buf[32];
882 int buf_size;
883 unsigned long user_bank;
884 int err;
885
886 /* Get userspace string and assure termination */
887 buf_size = min(count, (sizeof(buf) - 1));
888 if (copy_from_user(buf, user_buf, buf_size))
889 return -EFAULT;
890 buf[buf_size] = 0;
891
892 err = strict_strtoul(buf, 0, &user_bank);
893 if (err)
894 return -EINVAL;
895
896 if (user_bank >= AB3550_NUM_BANKS) {
897 dev_err(&ab->i2c_client[0]->dev,
898 "debugfs error input > number of banks\n");
899 return -EINVAL;
900 }
901
902 ab->debug_bank = user_bank;
903
904 return buf_size;
905}
906
907static int ab3550_address_print(struct seq_file *s, void *p)
908{
909 struct ab3550 *ab = s->private;
910
911 seq_printf(s, "0x%02X\n", ab->debug_address);
912 return 0;
913}
914
915static int ab3550_address_open(struct inode *inode, struct file *file)
916{
917 return single_open(file, ab3550_address_print, inode->i_private);
918}
919
920static ssize_t ab3550_address_write(struct file *file,
921 const char __user *user_buf,
922 size_t count, loff_t *ppos)
923{
924 struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
925 char buf[32];
926 int buf_size;
927 unsigned long user_address;
928 int err;
929
930 /* Get userspace string and assure termination */
931 buf_size = min(count, (sizeof(buf) - 1));
932 if (copy_from_user(buf, user_buf, buf_size))
933 return -EFAULT;
934 buf[buf_size] = 0;
935
936 err = strict_strtoul(buf, 0, &user_address);
937 if (err)
938 return -EINVAL;
939 if (user_address > 0xff) {
940 dev_err(&ab->i2c_client[0]->dev,
941 "debugfs error input > 0xff\n");
942 return -EINVAL;
943 }
944 ab->debug_address = user_address;
945 return buf_size;
946}
947
948static int ab3550_val_print(struct seq_file *s, void *p)
949{
950 struct ab3550 *ab = s->private;
951 int err;
952 u8 regvalue;
953
954 err = get_register_interruptible(ab, (u8)ab->debug_bank,
955 (u8)ab->debug_address, &regvalue);
956 if (err)
957 return -EINVAL;
958 seq_printf(s, "0x%02X\n", regvalue);
959
960 return 0;
961}
962
963static int ab3550_val_open(struct inode *inode, struct file *file)
964{
965 return single_open(file, ab3550_val_print, inode->i_private);
966}
967
968static ssize_t ab3550_val_write(struct file *file,
969 const char __user *user_buf,
970 size_t count, loff_t *ppos)
971{
972 struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
973 char buf[32];
974 int buf_size;
975 unsigned long user_val;
976 int err;
977 u8 regvalue;
978
979 /* Get userspace string and assure termination */
980 buf_size = min(count, (sizeof(buf)-1));
981 if (copy_from_user(buf, user_buf, buf_size))
982 return -EFAULT;
983 buf[buf_size] = 0;
984
985 err = strict_strtoul(buf, 0, &user_val);
986 if (err)
987 return -EINVAL;
988 if (user_val > 0xff) {
989 dev_err(&ab->i2c_client[0]->dev,
990 "debugfs error input > 0xff\n");
991 return -EINVAL;
992 }
993 err = mask_and_set_register_interruptible(
994 ab, (u8)ab->debug_bank,
995 (u8)ab->debug_address, 0xFF, (u8)user_val);
996 if (err)
997 return -EINVAL;
998
999 get_register_interruptible(ab, (u8)ab->debug_bank,
1000 (u8)ab->debug_address, &regvalue);
1001 if (err)
1002 return -EINVAL;
1003
1004 return buf_size;
1005}
1006
1007static const struct file_operations ab3550_bank_fops = {
1008 .open = ab3550_bank_open,
1009 .write = ab3550_bank_write,
1010 .read = seq_read,
1011 .llseek = seq_lseek,
1012 .release = single_release,
1013 .owner = THIS_MODULE,
1014};
1015
1016static const struct file_operations ab3550_address_fops = {
1017 .open = ab3550_address_open,
1018 .write = ab3550_address_write,
1019 .read = seq_read,
1020 .llseek = seq_lseek,
1021 .release = single_release,
1022 .owner = THIS_MODULE,
1023};
1024
1025static const struct file_operations ab3550_val_fops = {
1026 .open = ab3550_val_open,
1027 .write = ab3550_val_write,
1028 .read = seq_read,
1029 .llseek = seq_lseek,
1030 .release = single_release,
1031 .owner = THIS_MODULE,
1032};
1033
1034static struct dentry *ab3550_dir;
1035static struct dentry *ab3550_reg_file;
1036static struct dentry *ab3550_bank_file;
1037static struct dentry *ab3550_address_file;
1038static struct dentry *ab3550_val_file;
1039
1040static inline void ab3550_setup_debugfs(struct ab3550 *ab)
1041{
1042 ab->debug_bank = 0;
1043 ab->debug_address = 0x00;
1044
1045 ab3550_dir = debugfs_create_dir(AB3550_NAME_STRING, NULL);
1046 if (!ab3550_dir)
1047 goto exit_no_debugfs;
1048
1049 ab3550_reg_file = debugfs_create_file("all-registers",
1050 S_IRUGO, ab3550_dir, ab, &ab3550_registers_fops);
1051 if (!ab3550_reg_file)
1052 goto exit_destroy_dir;
1053
1054 ab3550_bank_file = debugfs_create_file("register-bank",
1055 (S_IRUGO | S_IWUGO), ab3550_dir, ab, &ab3550_bank_fops);
1056 if (!ab3550_bank_file)
1057 goto exit_destroy_reg;
1058
1059 ab3550_address_file = debugfs_create_file("register-address",
1060 (S_IRUGO | S_IWUGO), ab3550_dir, ab, &ab3550_address_fops);
1061 if (!ab3550_address_file)
1062 goto exit_destroy_bank;
1063
1064 ab3550_val_file = debugfs_create_file("register-value",
1065 (S_IRUGO | S_IWUGO), ab3550_dir, ab, &ab3550_val_fops);
1066 if (!ab3550_val_file)
1067 goto exit_destroy_address;
1068
1069 return;
1070
1071exit_destroy_address:
1072 debugfs_remove(ab3550_address_file);
1073exit_destroy_bank:
1074 debugfs_remove(ab3550_bank_file);
1075exit_destroy_reg:
1076 debugfs_remove(ab3550_reg_file);
1077exit_destroy_dir:
1078 debugfs_remove(ab3550_dir);
1079exit_no_debugfs:
1080 dev_err(&ab->i2c_client[0]->dev, "failed to create debugfs entries.\n");
1081 return;
1082}
1083
1084static inline void ab3550_remove_debugfs(void)
1085{
1086 debugfs_remove(ab3550_val_file);
1087 debugfs_remove(ab3550_address_file);
1088 debugfs_remove(ab3550_bank_file);
1089 debugfs_remove(ab3550_reg_file);
1090 debugfs_remove(ab3550_dir);
1091}
1092
1093#else /* !CONFIG_DEBUG_FS */
1094static inline void ab3550_setup_debugfs(struct ab3550 *ab)
1095{
1096}
1097static inline void ab3550_remove_debugfs(void)
1098{
1099}
1100#endif
1101
1102/*
1103 * Basic set-up, datastructure creation/destruction and I2C interface.
1104 * This sets up a default config in the AB3550 chip so that it
1105 * will work as expected.
1106 */
1107static int __init ab3550_setup(struct ab3550 *ab)
1108{
1109 int err = 0;
1110 int i;
1111 struct ab3550_platform_data *plf_data;
1112 struct abx500_init_settings *settings;
1113
1114 plf_data = ab->i2c_client[0]->dev.platform_data;
1115 settings = plf_data->init_settings;
1116
1117 for (i = 0; i < plf_data->init_settings_sz; i++) {
1118 err = mask_and_set_register_interruptible(ab,
1119 settings[i].bank,
1120 settings[i].reg,
1121 0xFF, settings[i].setting);
1122 if (err)
1123 goto exit_no_setup;
1124
1125 /* If event mask register update the event mask in ab3550 */
1126 if ((settings[i].bank == 0) &&
1127 (AB3550_IMR1 <= settings[i].reg) &&
1128 (settings[i].reg <= AB3550_IMR5)) {
1129 ab->event_mask[settings[i].reg - AB3550_IMR1] =
1130 settings[i].setting;
1131 }
1132 }
1133exit_no_setup:
1134 return err;
1135}
1136
1137static void ab3550_mask_work(struct work_struct *work)
1138{
1139 struct ab3550 *ab = container_of(work, struct ab3550, mask_work);
1140 int i;
1141 unsigned long flags;
1142 u8 mask[AB3550_NUM_EVENT_REG];
1143
1144 spin_lock_irqsave(&ab->event_lock, flags);
1145 for (i = 0; i < AB3550_NUM_EVENT_REG; i++)
1146 mask[i] = ab->event_mask[i];
1147 spin_unlock_irqrestore(&ab->event_lock, flags);
1148
1149 for (i = 0; i < AB3550_NUM_EVENT_REG; i++) {
1150 int err;
1151
1152 err = mask_and_set_register_interruptible(ab, 0,
1153 (AB3550_IMR1 + i), ~0, mask[i]);
1154 if (err)
1155 dev_err(&ab->i2c_client[0]->dev,
1156 "ab3550_mask_work failed 0x%x,0x%x\n",
1157 (AB3550_IMR1 + i), mask[i]);
1158 }
1159}
1160
1161static void ab3550_mask(unsigned int irq)
1162{
1163 unsigned long flags;
1164 struct ab3550 *ab;
1165 struct ab3550_platform_data *plf_data;
1166
1167 ab = get_irq_chip_data(irq);
1168 plf_data = ab->i2c_client[0]->dev.platform_data;
1169 irq -= plf_data->irq.base;
1170
1171 spin_lock_irqsave(&ab->event_lock, flags);
1172 ab->event_mask[irq / 8] |= BIT(irq % 8);
1173 spin_unlock_irqrestore(&ab->event_lock, flags);
1174
1175 schedule_work(&ab->mask_work);
1176}
1177
1178static void ab3550_unmask(unsigned int irq)
1179{
1180 unsigned long flags;
1181 struct ab3550 *ab;
1182 struct ab3550_platform_data *plf_data;
1183
1184 ab = get_irq_chip_data(irq);
1185 plf_data = ab->i2c_client[0]->dev.platform_data;
1186 irq -= plf_data->irq.base;
1187
1188 spin_lock_irqsave(&ab->event_lock, flags);
1189 ab->event_mask[irq / 8] &= ~BIT(irq % 8);
1190 spin_unlock_irqrestore(&ab->event_lock, flags);
1191
1192 schedule_work(&ab->mask_work);
1193}
1194
1195static void noop(unsigned int irq)
1196{
1197}
1198
1199static struct irq_chip ab3550_irq_chip = {
1200 .name = "ab3550-core", /* Keep the same name as the request */
1201 .startup = NULL, /* defaults to enable */
1202 .shutdown = NULL, /* defaults to disable */
1203 .enable = NULL, /* defaults to unmask */
1204 .disable = ab3550_mask, /* No default to mask in chip.c */
1205 .ack = noop,
1206 .mask = ab3550_mask,
1207 .unmask = ab3550_unmask,
1208 .end = NULL,
1209};
1210
1211struct ab_family_id {
1212 u8 id;
1213 char *name;
1214};
1215
1216static const struct ab_family_id ids[] __initdata = {
1217 /* AB3550 */
1218 {
1219 .id = AB3550_P1A,
1220 .name = "P1A"
1221 },
1222 /* Terminator */
1223 {
1224 .id = 0x00,
1225 }
1226};
1227
1228static int __init ab3550_probe(struct i2c_client *client,
1229 const struct i2c_device_id *id)
1230{
1231 struct ab3550 *ab;
1232 struct ab3550_platform_data *ab3550_plf_data =
1233 client->dev.platform_data;
1234 int err;
1235 int i;
1236 int num_i2c_clients = 0;
1237
1238 ab = kzalloc(sizeof(struct ab3550), GFP_KERNEL);
1239 if (!ab) {
1240 dev_err(&client->dev,
1241 "could not allocate " AB3550_NAME_STRING " device\n");
1242 return -ENOMEM;
1243 }
1244
1245 /* Initialize data structure */
1246 mutex_init(&ab->access_mutex);
1247 spin_lock_init(&ab->event_lock);
1248 ab->i2c_client[0] = client;
1249
1250 i2c_set_clientdata(client, ab);
1251
1252 /* Read chip ID register */
1253 err = get_register_interruptible(ab, 0, AB3550_CID_REG, &ab->chip_id);
1254 if (err) {
1255 dev_err(&client->dev, "could not communicate with the analog "
1256 "baseband chip\n");
1257 goto exit_no_detect;
1258 }
1259
1260 for (i = 0; ids[i].id != 0x0; i++) {
1261 if (ids[i].id == ab->chip_id) {
1262 snprintf(&ab->chip_name[0], sizeof(ab->chip_name) - 1,
1263 AB3550_ID_FORMAT_STRING, ids[i].name);
1264 break;
1265 }
1266 }
1267
1268 if (ids[i].id == 0x0) {
1269 dev_err(&client->dev, "unknown analog baseband chip id: 0x%x\n",
1270 ab->chip_id);
1271 dev_err(&client->dev, "driver not started!\n");
1272 goto exit_no_detect;
1273 }
1274
1275 dev_info(&client->dev, "detected AB chip: %s\n", &ab->chip_name[0]);
1276
1277 /* Attach other dummy I2C clients. */
1278 while (++num_i2c_clients < AB3550_NUM_BANKS) {
1279 ab->i2c_client[num_i2c_clients] =
1280 i2c_new_dummy(client->adapter,
1281 (client->addr + num_i2c_clients));
1282 if (!ab->i2c_client[num_i2c_clients]) {
1283 err = -ENOMEM;
1284 goto exit_no_dummy_client;
1285 }
1286 strlcpy(ab->i2c_client[num_i2c_clients]->name, id->name,
1287 sizeof(ab->i2c_client[num_i2c_clients]->name));
1288 }
1289
1290 err = ab3550_setup(ab);
1291 if (err)
1292 goto exit_no_setup;
1293
1294 INIT_WORK(&ab->mask_work, ab3550_mask_work);
1295
1296 for (i = 0; i < ab3550_plf_data->irq.count; i++) {
1297 unsigned int irq;
1298
1299 irq = ab3550_plf_data->irq.base + i;
1300 set_irq_chip_data(irq, ab);
1301 set_irq_chip_and_handler(irq, &ab3550_irq_chip,
1302 handle_simple_irq);
1303 set_irq_nested_thread(irq, 1);
1304#ifdef CONFIG_ARM
1305 set_irq_flags(irq, IRQF_VALID);
1306#else
1307 set_irq_noprobe(irq);
1308#endif
1309 }
1310
1311 err = request_threaded_irq(client->irq, NULL, ab3550_irq_handler,
1312 IRQF_ONESHOT, "ab3550-core", ab);
1313 /* This real unpredictable IRQ is of course sampled for entropy */
1314 rand_initialize_irq(client->irq);
1315
1316 if (err)
1317 goto exit_no_irq;
1318
1319 err = abx500_register_ops(&client->dev, &ab3550_ops);
1320 if (err)
1321 goto exit_no_ops;
1322
1323 /* Set up and register the platform devices. */
1324 for (i = 0; i < AB3550_NUM_DEVICES; i++) {
1325 ab3550_devs[i].platform_data = ab3550_plf_data->dev_data[i];
1326 ab3550_devs[i].data_size = ab3550_plf_data->dev_data_sz[i];
1327 }
1328
1329 err = mfd_add_devices(&client->dev, 0, ab3550_devs,
1330 ARRAY_SIZE(ab3550_devs), NULL,
1331 ab3550_plf_data->irq.base);
1332
1333 ab3550_setup_debugfs(ab);
1334
1335 return 0;
1336
1337exit_no_ops:
1338exit_no_irq:
1339exit_no_setup:
1340exit_no_dummy_client:
1341 /* Unregister the dummy i2c clients. */
1342 while (--num_i2c_clients)
1343 i2c_unregister_device(ab->i2c_client[num_i2c_clients]);
1344exit_no_detect:
1345 kfree(ab);
1346 return err;
1347}
1348
1349static int __exit ab3550_remove(struct i2c_client *client)
1350{
1351 struct ab3550 *ab = i2c_get_clientdata(client);
1352 int num_i2c_clients = AB3550_NUM_BANKS;
1353
1354 mfd_remove_devices(&client->dev);
1355 ab3550_remove_debugfs();
1356
1357 while (--num_i2c_clients)
1358 i2c_unregister_device(ab->i2c_client[num_i2c_clients]);
1359
1360 /*
1361 * At this point, all subscribers should have unregistered
1362 * their notifiers so deactivate IRQ
1363 */
1364 free_irq(client->irq, ab);
1365 i2c_set_clientdata(client, NULL);
1366 kfree(ab);
1367 return 0;
1368}
1369
1370static const struct i2c_device_id ab3550_id[] = {
1371 {AB3550_NAME_STRING, 0},
1372 {}
1373};
1374MODULE_DEVICE_TABLE(i2c, ab3550_id);
1375
1376static struct i2c_driver ab3550_driver = {
1377 .driver = {
1378 .name = AB3550_NAME_STRING,
1379 .owner = THIS_MODULE,
1380 },
1381 .id_table = ab3550_id,
1382 .probe = ab3550_probe,
1383 .remove = __exit_p(ab3550_remove),
1384};
1385
1386static int __init ab3550_i2c_init(void)
1387{
1388 return i2c_add_driver(&ab3550_driver);
1389}
1390
1391static void __exit ab3550_i2c_exit(void)
1392{
1393 i2c_del_driver(&ab3550_driver);
1394}
1395
1396subsys_initcall(ab3550_i2c_init);
1397module_exit(ab3550_i2c_exit);
1398
1399MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
1400MODULE_DESCRIPTION("AB3550 core driver");
1401MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ab4500-core.c b/drivers/mfd/ab4500-core.c
deleted file mode 100644
index c275daa3ab1a..000000000000
--- a/drivers/mfd/ab4500-core.c
+++ /dev/null
@@ -1,209 +0,0 @@
1/*
2 * Copyright (C) 2009 ST-Ericsson
3 *
4 * Author: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
5 *
6 * This program is free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation.
9 *
10 * AB4500 is a companion power management chip used with U8500.
11 * On this platform, this is interfaced with SSP0 controller
12 * which is a ARM primecell pl022.
13 *
14 * At the moment the module just exports read/write features.
15 * Interrupt management to be added - TODO.
16 */
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/spi/spi.h>
23#include <linux/mfd/ab4500.h>
24
25/* just required if probe fails, we need to
26 * unregister the device
27 */
28static struct spi_driver ab4500_driver;
29
30/*
31 * This funtion writes to any AB4500 registers using
32 * SPI protocol & before it writes it packs the data
33 * in the below 24 bit frame format
34 *
35 * *|------------------------------------|
36 * *| 23|22...18|17.......10|9|8|7......0|
37 * *| r/w bank adr data |
38 * * ------------------------------------
39 *
40 * This function shouldn't be called from interrupt
41 * context
42 */
43int ab4500_write(struct ab4500 *ab4500, unsigned char block,
44 unsigned long addr, unsigned char data)
45{
46 struct spi_transfer xfer;
47 struct spi_message msg;
48 int err;
49 unsigned long spi_data =
50 block << 18 | addr << 10 | data;
51
52 mutex_lock(&ab4500->lock);
53 ab4500->tx_buf[0] = spi_data;
54 ab4500->rx_buf[0] = 0;
55
56 xfer.tx_buf = ab4500->tx_buf;
57 xfer.rx_buf = NULL;
58 xfer.len = sizeof(unsigned long);
59
60 spi_message_init(&msg);
61 spi_message_add_tail(&xfer, &msg);
62
63 err = spi_sync(ab4500->spi, &msg);
64 mutex_unlock(&ab4500->lock);
65
66 return err;
67}
68EXPORT_SYMBOL(ab4500_write);
69
70int ab4500_read(struct ab4500 *ab4500, unsigned char block,
71 unsigned long addr)
72{
73 struct spi_transfer xfer;
74 struct spi_message msg;
75 unsigned long spi_data =
76 1 << 23 | block << 18 | addr << 10;
77
78 mutex_lock(&ab4500->lock);
79 ab4500->tx_buf[0] = spi_data;
80 ab4500->rx_buf[0] = 0;
81
82 xfer.tx_buf = ab4500->tx_buf;
83 xfer.rx_buf = ab4500->rx_buf;
84 xfer.len = sizeof(unsigned long);
85
86 spi_message_init(&msg);
87 spi_message_add_tail(&xfer, &msg);
88
89 spi_sync(ab4500->spi, &msg);
90 mutex_unlock(&ab4500->lock);
91
92 return ab4500->rx_buf[0];
93}
94EXPORT_SYMBOL(ab4500_read);
95
96/* ref: ab3100 core */
97#define AB4500_DEVICE(devname, devid) \
98static struct platform_device ab4500_##devname##_device = { \
99 .name = devid, \
100 .id = -1, \
101}
102
103/* list of childern devices of ab4500 - all are
104 * not populated here - TODO
105 */
106AB4500_DEVICE(charger, "ab4500-charger");
107AB4500_DEVICE(audio, "ab4500-audio");
108AB4500_DEVICE(usb, "ab4500-usb");
109AB4500_DEVICE(tvout, "ab4500-tvout");
110AB4500_DEVICE(sim, "ab4500-sim");
111AB4500_DEVICE(gpadc, "ab4500-gpadc");
112AB4500_DEVICE(clkmgt, "ab4500-clkmgt");
113AB4500_DEVICE(misc, "ab4500-misc");
114
115static struct platform_device *ab4500_platform_devs[] = {
116 &ab4500_charger_device,
117 &ab4500_audio_device,
118 &ab4500_usb_device,
119 &ab4500_tvout_device,
120 &ab4500_sim_device,
121 &ab4500_gpadc_device,
122 &ab4500_clkmgt_device,
123 &ab4500_misc_device,
124};
125
126static int __init ab4500_probe(struct spi_device *spi)
127{
128 struct ab4500 *ab4500;
129 unsigned char revision;
130 int err = 0;
131 int i;
132
133 ab4500 = kzalloc(sizeof *ab4500, GFP_KERNEL);
134 if (!ab4500) {
135 dev_err(&spi->dev, "could not allocate AB4500\n");
136 err = -ENOMEM;
137 goto not_detect;
138 }
139
140 ab4500->spi = spi;
141 spi_set_drvdata(spi, ab4500);
142
143 mutex_init(&ab4500->lock);
144
145 /* read the revision register */
146 revision = ab4500_read(ab4500, AB4500_MISC, AB4500_REV_REG);
147
148 /* revision id 0x0 is for early drop, 0x10 is for cut1.0 */
149 if (revision == 0x0 || revision == 0x10)
150 dev_info(&spi->dev, "Detected chip: %s, revision = %x\n",
151 ab4500_driver.driver.name, revision);
152 else {
153 dev_err(&spi->dev, "unknown chip: 0x%x\n", revision);
154 goto not_detect;
155 }
156
157 for (i = 0; i < ARRAY_SIZE(ab4500_platform_devs); i++) {
158 ab4500_platform_devs[i]->dev.parent =
159 &spi->dev;
160 platform_set_drvdata(ab4500_platform_devs[i], ab4500);
161 }
162
163 /* register the ab4500 platform devices */
164 platform_add_devices(ab4500_platform_devs,
165 ARRAY_SIZE(ab4500_platform_devs));
166
167 return err;
168
169 not_detect:
170 spi_unregister_driver(&ab4500_driver);
171 kfree(ab4500);
172 return err;
173}
174
175static int __devexit ab4500_remove(struct spi_device *spi)
176{
177 struct ab4500 *ab4500 =
178 spi_get_drvdata(spi);
179
180 kfree(ab4500);
181
182 return 0;
183}
184
185static struct spi_driver ab4500_driver = {
186 .driver = {
187 .name = "ab4500",
188 .owner = THIS_MODULE,
189 },
190 .probe = ab4500_probe,
191 .remove = __devexit_p(ab4500_remove)
192};
193
194static int __devinit ab4500_init(void)
195{
196 return spi_register_driver(&ab4500_driver);
197}
198
199static void __exit ab4500_exit(void)
200{
201 spi_unregister_driver(&ab4500_driver);
202}
203
204subsys_initcall(ab4500_init);
205module_exit(ab4500_exit);
206
207MODULE_AUTHOR("Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com");
208MODULE_DESCRIPTION("AB4500 core driver");
209MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
new file mode 100644
index 000000000000..f3d26fa9c34d
--- /dev/null
+++ b/drivers/mfd/ab8500-core.c
@@ -0,0 +1,444 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com>
7 */
8
9#include <linux/kernel.h>
10#include <linux/slab.h>
11#include <linux/init.h>
12#include <linux/irq.h>
13#include <linux/delay.h>
14#include <linux/interrupt.h>
15#include <linux/module.h>
16#include <linux/platform_device.h>
17#include <linux/mfd/core.h>
18#include <linux/mfd/ab8500.h>
19
20/*
21 * Interrupt register offsets
22 * Bank : 0x0E
23 */
24#define AB8500_IT_SOURCE1_REG 0x0E00
25#define AB8500_IT_SOURCE2_REG 0x0E01
26#define AB8500_IT_SOURCE3_REG 0x0E02
27#define AB8500_IT_SOURCE4_REG 0x0E03
28#define AB8500_IT_SOURCE5_REG 0x0E04
29#define AB8500_IT_SOURCE6_REG 0x0E05
30#define AB8500_IT_SOURCE7_REG 0x0E06
31#define AB8500_IT_SOURCE8_REG 0x0E07
32#define AB8500_IT_SOURCE19_REG 0x0E12
33#define AB8500_IT_SOURCE20_REG 0x0E13
34#define AB8500_IT_SOURCE21_REG 0x0E14
35#define AB8500_IT_SOURCE22_REG 0x0E15
36#define AB8500_IT_SOURCE23_REG 0x0E16
37#define AB8500_IT_SOURCE24_REG 0x0E17
38
39/*
40 * latch registers
41 */
42#define AB8500_IT_LATCH1_REG 0x0E20
43#define AB8500_IT_LATCH2_REG 0x0E21
44#define AB8500_IT_LATCH3_REG 0x0E22
45#define AB8500_IT_LATCH4_REG 0x0E23
46#define AB8500_IT_LATCH5_REG 0x0E24
47#define AB8500_IT_LATCH6_REG 0x0E25
48#define AB8500_IT_LATCH7_REG 0x0E26
49#define AB8500_IT_LATCH8_REG 0x0E27
50#define AB8500_IT_LATCH9_REG 0x0E28
51#define AB8500_IT_LATCH10_REG 0x0E29
52#define AB8500_IT_LATCH19_REG 0x0E32
53#define AB8500_IT_LATCH20_REG 0x0E33
54#define AB8500_IT_LATCH21_REG 0x0E34
55#define AB8500_IT_LATCH22_REG 0x0E35
56#define AB8500_IT_LATCH23_REG 0x0E36
57#define AB8500_IT_LATCH24_REG 0x0E37
58
59/*
60 * mask registers
61 */
62
63#define AB8500_IT_MASK1_REG 0x0E40
64#define AB8500_IT_MASK2_REG 0x0E41
65#define AB8500_IT_MASK3_REG 0x0E42
66#define AB8500_IT_MASK4_REG 0x0E43
67#define AB8500_IT_MASK5_REG 0x0E44
68#define AB8500_IT_MASK6_REG 0x0E45
69#define AB8500_IT_MASK7_REG 0x0E46
70#define AB8500_IT_MASK8_REG 0x0E47
71#define AB8500_IT_MASK9_REG 0x0E48
72#define AB8500_IT_MASK10_REG 0x0E49
73#define AB8500_IT_MASK11_REG 0x0E4A
74#define AB8500_IT_MASK12_REG 0x0E4B
75#define AB8500_IT_MASK13_REG 0x0E4C
76#define AB8500_IT_MASK14_REG 0x0E4D
77#define AB8500_IT_MASK15_REG 0x0E4E
78#define AB8500_IT_MASK16_REG 0x0E4F
79#define AB8500_IT_MASK17_REG 0x0E50
80#define AB8500_IT_MASK18_REG 0x0E51
81#define AB8500_IT_MASK19_REG 0x0E52
82#define AB8500_IT_MASK20_REG 0x0E53
83#define AB8500_IT_MASK21_REG 0x0E54
84#define AB8500_IT_MASK22_REG 0x0E55
85#define AB8500_IT_MASK23_REG 0x0E56
86#define AB8500_IT_MASK24_REG 0x0E57
87
88#define AB8500_REV_REG 0x1080
89
90/*
91 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
92 * numbers are indexed into this array with (num / 8).
93 *
94 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
95 * offset 0.
96 */
97static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
98 0, 1, 2, 3, 4, 6, 7, 8, 9, 18, 19, 20, 21,
99};
100
101static int __ab8500_write(struct ab8500 *ab8500, u16 addr, u8 data)
102{
103 int ret;
104
105 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
106
107 ret = ab8500->write(ab8500, addr, data);
108 if (ret < 0)
109 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
110 addr, ret);
111
112 return ret;
113}
114
115/**
116 * ab8500_write() - write an AB8500 register
117 * @ab8500: device to write to
118 * @addr: address of the register
119 * @data: value to write
120 */
121int ab8500_write(struct ab8500 *ab8500, u16 addr, u8 data)
122{
123 int ret;
124
125 mutex_lock(&ab8500->lock);
126 ret = __ab8500_write(ab8500, addr, data);
127 mutex_unlock(&ab8500->lock);
128
129 return ret;
130}
131EXPORT_SYMBOL_GPL(ab8500_write);
132
133static int __ab8500_read(struct ab8500 *ab8500, u16 addr)
134{
135 int ret;
136
137 ret = ab8500->read(ab8500, addr);
138 if (ret < 0)
139 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
140 addr, ret);
141
142 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
143
144 return ret;
145}
146
147/**
148 * ab8500_read() - read an AB8500 register
149 * @ab8500: device to read from
150 * @addr: address of the register
151 */
152int ab8500_read(struct ab8500 *ab8500, u16 addr)
153{
154 int ret;
155
156 mutex_lock(&ab8500->lock);
157 ret = __ab8500_read(ab8500, addr);
158 mutex_unlock(&ab8500->lock);
159
160 return ret;
161}
162EXPORT_SYMBOL_GPL(ab8500_read);
163
164/**
165 * ab8500_set_bits() - set a bitfield in an AB8500 register
166 * @ab8500: device to read from
167 * @addr: address of the register
168 * @mask: mask of the bitfield to modify
169 * @data: value to set to the bitfield
170 */
171int ab8500_set_bits(struct ab8500 *ab8500, u16 addr, u8 mask, u8 data)
172{
173 int ret;
174
175 mutex_lock(&ab8500->lock);
176
177 ret = __ab8500_read(ab8500, addr);
178 if (ret < 0)
179 goto out;
180
181 ret &= ~mask;
182 ret |= data;
183
184 ret = __ab8500_write(ab8500, addr, ret);
185
186out:
187 mutex_unlock(&ab8500->lock);
188 return ret;
189}
190EXPORT_SYMBOL_GPL(ab8500_set_bits);
191
192static void ab8500_irq_lock(unsigned int irq)
193{
194 struct ab8500 *ab8500 = get_irq_chip_data(irq);
195
196 mutex_lock(&ab8500->irq_lock);
197}
198
199static void ab8500_irq_sync_unlock(unsigned int irq)
200{
201 struct ab8500 *ab8500 = get_irq_chip_data(irq);
202 int i;
203
204 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
205 u8 old = ab8500->oldmask[i];
206 u8 new = ab8500->mask[i];
207 int reg;
208
209 if (new == old)
210 continue;
211
212 ab8500->oldmask[i] = new;
213
214 reg = AB8500_IT_MASK1_REG + ab8500_irq_regoffset[i];
215 ab8500_write(ab8500, reg, new);
216 }
217
218 mutex_unlock(&ab8500->irq_lock);
219}
220
221static void ab8500_irq_mask(unsigned int irq)
222{
223 struct ab8500 *ab8500 = get_irq_chip_data(irq);
224 int offset = irq - ab8500->irq_base;
225 int index = offset / 8;
226 int mask = 1 << (offset % 8);
227
228 ab8500->mask[index] |= mask;
229}
230
231static void ab8500_irq_unmask(unsigned int irq)
232{
233 struct ab8500 *ab8500 = get_irq_chip_data(irq);
234 int offset = irq - ab8500->irq_base;
235 int index = offset / 8;
236 int mask = 1 << (offset % 8);
237
238 ab8500->mask[index] &= ~mask;
239}
240
241static struct irq_chip ab8500_irq_chip = {
242 .name = "ab8500",
243 .bus_lock = ab8500_irq_lock,
244 .bus_sync_unlock = ab8500_irq_sync_unlock,
245 .mask = ab8500_irq_mask,
246 .unmask = ab8500_irq_unmask,
247};
248
249static irqreturn_t ab8500_irq(int irq, void *dev)
250{
251 struct ab8500 *ab8500 = dev;
252 int i;
253
254 dev_vdbg(ab8500->dev, "interrupt\n");
255
256 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
257 int regoffset = ab8500_irq_regoffset[i];
258 int status;
259
260 status = ab8500_read(ab8500, AB8500_IT_LATCH1_REG + regoffset);
261 if (status <= 0)
262 continue;
263
264 do {
265 int bit = __ffs(status);
266 int line = i * 8 + bit;
267
268 handle_nested_irq(ab8500->irq_base + line);
269 status &= ~(1 << bit);
270 } while (status);
271 }
272
273 return IRQ_HANDLED;
274}
275
276static int ab8500_irq_init(struct ab8500 *ab8500)
277{
278 int base = ab8500->irq_base;
279 int irq;
280
281 for (irq = base; irq < base + AB8500_NR_IRQS; irq++) {
282 set_irq_chip_data(irq, ab8500);
283 set_irq_chip_and_handler(irq, &ab8500_irq_chip,
284 handle_simple_irq);
285 set_irq_nested_thread(irq, 1);
286#ifdef CONFIG_ARM
287 set_irq_flags(irq, IRQF_VALID);
288#else
289 set_irq_noprobe(irq);
290#endif
291 }
292
293 return 0;
294}
295
296static void ab8500_irq_remove(struct ab8500 *ab8500)
297{
298 int base = ab8500->irq_base;
299 int irq;
300
301 for (irq = base; irq < base + AB8500_NR_IRQS; irq++) {
302#ifdef CONFIG_ARM
303 set_irq_flags(irq, 0);
304#endif
305 set_irq_chip_and_handler(irq, NULL, NULL);
306 set_irq_chip_data(irq, NULL);
307 }
308}
309
310static struct resource ab8500_gpadc_resources[] = {
311 {
312 .name = "HW_CONV_END",
313 .start = AB8500_INT_GP_HW_ADC_CONV_END,
314 .end = AB8500_INT_GP_HW_ADC_CONV_END,
315 .flags = IORESOURCE_IRQ,
316 },
317 {
318 .name = "SW_CONV_END",
319 .start = AB8500_INT_GP_SW_ADC_CONV_END,
320 .end = AB8500_INT_GP_SW_ADC_CONV_END,
321 .flags = IORESOURCE_IRQ,
322 },
323};
324
325static struct resource ab8500_rtc_resources[] = {
326 {
327 .name = "60S",
328 .start = AB8500_INT_RTC_60S,
329 .end = AB8500_INT_RTC_60S,
330 .flags = IORESOURCE_IRQ,
331 },
332 {
333 .name = "ALARM",
334 .start = AB8500_INT_RTC_ALARM,
335 .end = AB8500_INT_RTC_ALARM,
336 .flags = IORESOURCE_IRQ,
337 },
338};
339
340static struct mfd_cell ab8500_devs[] = {
341 {
342 .name = "ab8500-gpadc",
343 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
344 .resources = ab8500_gpadc_resources,
345 },
346 {
347 .name = "ab8500-rtc",
348 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
349 .resources = ab8500_rtc_resources,
350 },
351 { .name = "ab8500-charger", },
352 { .name = "ab8500-audio", },
353 { .name = "ab8500-usb", },
354 { .name = "ab8500-pwm", },
355};
356
357int __devinit ab8500_init(struct ab8500 *ab8500)
358{
359 struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
360 int ret;
361 int i;
362
363 if (plat)
364 ab8500->irq_base = plat->irq_base;
365
366 mutex_init(&ab8500->lock);
367 mutex_init(&ab8500->irq_lock);
368
369 ret = ab8500_read(ab8500, AB8500_REV_REG);
370 if (ret < 0)
371 return ret;
372
373 /*
374 * 0x0 - Early Drop
375 * 0x10 - Cut 1.0
376 * 0x11 - Cut 1.1
377 */
378 if (ret == 0x0 || ret == 0x10 || ret == 0x11) {
379 ab8500->revision = ret;
380 dev_info(ab8500->dev, "detected chip, revision: %#x\n", ret);
381 } else {
382 dev_err(ab8500->dev, "unknown chip, revision: %#x\n", ret);
383 return -EINVAL;
384 }
385
386 if (plat && plat->init)
387 plat->init(ab8500);
388
389 /* Clear and mask all interrupts */
390 for (i = 0; i < 10; i++) {
391 ab8500_read(ab8500, AB8500_IT_LATCH1_REG + i);
392 ab8500_write(ab8500, AB8500_IT_MASK1_REG + i, 0xff);
393 }
394
395 for (i = 18; i < 24; i++) {
396 ab8500_read(ab8500, AB8500_IT_LATCH1_REG + i);
397 ab8500_write(ab8500, AB8500_IT_MASK1_REG + i, 0xff);
398 }
399
400 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++)
401 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
402
403 if (ab8500->irq_base) {
404 ret = ab8500_irq_init(ab8500);
405 if (ret)
406 return ret;
407
408 ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq,
409 IRQF_ONESHOT, "ab8500", ab8500);
410 if (ret)
411 goto out_removeirq;
412 }
413
414 ret = mfd_add_devices(ab8500->dev, -1, ab8500_devs,
415 ARRAY_SIZE(ab8500_devs), NULL,
416 ab8500->irq_base);
417 if (ret)
418 goto out_freeirq;
419
420 return ret;
421
422out_freeirq:
423 if (ab8500->irq_base) {
424 free_irq(ab8500->irq, ab8500);
425out_removeirq:
426 ab8500_irq_remove(ab8500);
427 }
428 return ret;
429}
430
431int __devexit ab8500_exit(struct ab8500 *ab8500)
432{
433 mfd_remove_devices(ab8500->dev);
434 if (ab8500->irq_base) {
435 free_irq(ab8500->irq, ab8500);
436 ab8500_irq_remove(ab8500);
437 }
438
439 return 0;
440}
441
442MODULE_AUTHOR("Srinidhi Kasagar, Rabin Vincent");
443MODULE_DESCRIPTION("AB8500 MFD core");
444MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/ab8500-spi.c b/drivers/mfd/ab8500-spi.c
new file mode 100644
index 000000000000..b81d4f768ef6
--- /dev/null
+++ b/drivers/mfd/ab8500-spi.c
@@ -0,0 +1,133 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
6 */
7
8#include <linux/kernel.h>
9#include <linux/slab.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
13#include <linux/spi/spi.h>
14#include <linux/mfd/ab8500.h>
15
16/*
17 * This funtion writes to any AB8500 registers using
18 * SPI protocol & before it writes it packs the data
19 * in the below 24 bit frame format
20 *
21 * *|------------------------------------|
22 * *| 23|22...18|17.......10|9|8|7......0|
23 * *| r/w bank adr data |
24 * * ------------------------------------
25 *
26 * This function shouldn't be called from interrupt
27 * context
28 */
29static int ab8500_spi_write(struct ab8500 *ab8500, u16 addr, u8 data)
30{
31 struct spi_device *spi = container_of(ab8500->dev, struct spi_device,
32 dev);
33 unsigned long spi_data = addr << 10 | data;
34 struct spi_transfer xfer;
35 struct spi_message msg;
36
37 ab8500->tx_buf[0] = spi_data;
38 ab8500->rx_buf[0] = 0;
39
40 xfer.tx_buf = ab8500->tx_buf;
41 xfer.rx_buf = NULL;
42 xfer.len = sizeof(unsigned long);
43
44 spi_message_init(&msg);
45 spi_message_add_tail(&xfer, &msg);
46
47 return spi_sync(spi, &msg);
48}
49
50static int ab8500_spi_read(struct ab8500 *ab8500, u16 addr)
51{
52 struct spi_device *spi = container_of(ab8500->dev, struct spi_device,
53 dev);
54 unsigned long spi_data = 1 << 23 | addr << 10;
55 struct spi_transfer xfer;
56 struct spi_message msg;
57 int ret;
58
59 ab8500->tx_buf[0] = spi_data;
60 ab8500->rx_buf[0] = 0;
61
62 xfer.tx_buf = ab8500->tx_buf;
63 xfer.rx_buf = ab8500->rx_buf;
64 xfer.len = sizeof(unsigned long);
65
66 spi_message_init(&msg);
67 spi_message_add_tail(&xfer, &msg);
68
69 ret = spi_sync(spi, &msg);
70 if (!ret)
71 ret = ab8500->rx_buf[0];
72
73 return ret;
74}
75
76static int __devinit ab8500_spi_probe(struct spi_device *spi)
77{
78 struct ab8500 *ab8500;
79 int ret;
80
81 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL);
82 if (!ab8500)
83 return -ENOMEM;
84
85 ab8500->dev = &spi->dev;
86 ab8500->irq = spi->irq;
87
88 ab8500->read = ab8500_spi_read;
89 ab8500->write = ab8500_spi_write;
90
91 spi_set_drvdata(spi, ab8500);
92
93 ret = ab8500_init(ab8500);
94 if (ret)
95 kfree(ab8500);
96
97 return ret;
98}
99
100static int __devexit ab8500_spi_remove(struct spi_device *spi)
101{
102 struct ab8500 *ab8500 = spi_get_drvdata(spi);
103
104 ab8500_exit(ab8500);
105 kfree(ab8500);
106
107 return 0;
108}
109
110static struct spi_driver ab8500_spi_driver = {
111 .driver = {
112 .name = "ab8500",
113 .owner = THIS_MODULE,
114 },
115 .probe = ab8500_spi_probe,
116 .remove = __devexit_p(ab8500_spi_remove)
117};
118
119static int __init ab8500_spi_init(void)
120{
121 return spi_register_driver(&ab8500_spi_driver);
122}
123subsys_initcall(ab8500_spi_init);
124
125static void __exit ab8500_spi_exit(void)
126{
127 spi_unregister_driver(&ab8500_spi_driver);
128}
129module_exit(ab8500_spi_exit);
130
131MODULE_AUTHOR("Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com");
132MODULE_DESCRIPTION("AB8500 SPI");
133MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
new file mode 100644
index 000000000000..3b3b97ec32a7
--- /dev/null
+++ b/drivers/mfd/abx500-core.c
@@ -0,0 +1,157 @@
1/*
2 * Copyright (C) 2007-2010 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Register access functions for the ABX500 Mixed Signal IC family.
5 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
6 */
7
8#include <linux/list.h>
9#include <linux/slab.h>
10#include <linux/err.h>
11#include <linux/mfd/abx500.h>
12
13static LIST_HEAD(abx500_list);
14
15struct abx500_device_entry {
16 struct list_head list;
17 struct abx500_ops ops;
18 struct device *dev;
19};
20
21static void lookup_ops(struct device *dev, struct abx500_ops **ops)
22{
23 struct abx500_device_entry *dev_entry;
24
25 *ops = NULL;
26 list_for_each_entry(dev_entry, &abx500_list, list) {
27 if (dev_entry->dev == dev) {
28 *ops = &dev_entry->ops;
29 return;
30 }
31 }
32}
33
34int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
35{
36 struct abx500_device_entry *dev_entry;
37
38 dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL);
39 if (IS_ERR(dev_entry)) {
40 dev_err(dev, "register_ops kzalloc failed");
41 return -ENOMEM;
42 }
43 dev_entry->dev = dev;
44 memcpy(&dev_entry->ops, ops, sizeof(struct abx500_ops));
45
46 list_add_tail(&dev_entry->list, &abx500_list);
47 return 0;
48}
49EXPORT_SYMBOL(abx500_register_ops);
50
51void abx500_remove_ops(struct device *dev)
52{
53 struct abx500_device_entry *dev_entry, *tmp;
54
55 list_for_each_entry_safe(dev_entry, tmp, &abx500_list, list)
56 {
57 if (dev_entry->dev == dev) {
58 list_del(&dev_entry->list);
59 kfree(dev_entry);
60 }
61 }
62}
63EXPORT_SYMBOL(abx500_remove_ops);
64
65int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
66 u8 value)
67{
68 struct abx500_ops *ops;
69
70 lookup_ops(dev->parent, &ops);
71 if ((ops != NULL) && (ops->set_register != NULL))
72 return ops->set_register(dev, bank, reg, value);
73 else
74 return -ENOTSUPP;
75}
76EXPORT_SYMBOL(abx500_set_register_interruptible);
77
78int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
79 u8 *value)
80{
81 struct abx500_ops *ops;
82
83 lookup_ops(dev->parent, &ops);
84 if ((ops != NULL) && (ops->get_register != NULL))
85 return ops->get_register(dev, bank, reg, value);
86 else
87 return -ENOTSUPP;
88}
89EXPORT_SYMBOL(abx500_get_register_interruptible);
90
91int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
92 u8 first_reg, u8 *regvals, u8 numregs)
93{
94 struct abx500_ops *ops;
95
96 lookup_ops(dev->parent, &ops);
97 if ((ops != NULL) && (ops->get_register_page != NULL))
98 return ops->get_register_page(dev, bank,
99 first_reg, regvals, numregs);
100 else
101 return -ENOTSUPP;
102}
103EXPORT_SYMBOL(abx500_get_register_page_interruptible);
104
105int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
106 u8 reg, u8 bitmask, u8 bitvalues)
107{
108 struct abx500_ops *ops;
109
110 lookup_ops(dev->parent, &ops);
111 if ((ops != NULL) && (ops->mask_and_set_register != NULL))
112 return ops->mask_and_set_register(dev, bank,
113 reg, bitmask, bitvalues);
114 else
115 return -ENOTSUPP;
116}
117EXPORT_SYMBOL(abx500_mask_and_set_register_interruptible);
118
119int abx500_get_chip_id(struct device *dev)
120{
121 struct abx500_ops *ops;
122
123 lookup_ops(dev->parent, &ops);
124 if ((ops != NULL) && (ops->get_chip_id != NULL))
125 return ops->get_chip_id(dev);
126 else
127 return -ENOTSUPP;
128}
129EXPORT_SYMBOL(abx500_get_chip_id);
130
131int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
132{
133 struct abx500_ops *ops;
134
135 lookup_ops(dev->parent, &ops);
136 if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
137 return ops->event_registers_startup_state_get(dev, event);
138 else
139 return -ENOTSUPP;
140}
141EXPORT_SYMBOL(abx500_event_registers_startup_state_get);
142
143int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
144{
145 struct abx500_ops *ops;
146
147 lookup_ops(dev->parent, &ops);
148 if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
149 return ops->startup_irq_enabled(dev, irq);
150 else
151 return -ENOTSUPP;
152}
153EXPORT_SYMBOL(abx500_startup_irq_enabled);
154
155MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
156MODULE_DESCRIPTION("ABX500 core driver");
157MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/da903x.c b/drivers/mfd/da903x.c
index 67181b147ab3..3ad915d0589c 100644
--- a/drivers/mfd/da903x.c
+++ b/drivers/mfd/da903x.c
@@ -544,6 +544,7 @@ static int __devexit da903x_remove(struct i2c_client *client)
544 struct da903x_chip *chip = i2c_get_clientdata(client); 544 struct da903x_chip *chip = i2c_get_clientdata(client);
545 545
546 da903x_remove_subdevs(chip); 546 da903x_remove_subdevs(chip);
547 i2c_set_clientdata(client, NULL);
547 kfree(chip); 548 kfree(chip);
548 return 0; 549 return 0;
549} 550}
diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
new file mode 100644
index 000000000000..9ed630799acc
--- /dev/null
+++ b/drivers/mfd/janz-cmodio.c
@@ -0,0 +1,304 @@
1/*
2 * Janz CMOD-IO MODULbus Carrier Board PCI Driver
3 *
4 * Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu>
5 *
6 * Lots of inspiration and code was copied from drivers/mfd/sm501.c
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/pci.h>
18#include <linux/interrupt.h>
19#include <linux/delay.h>
20#include <linux/platform_device.h>
21#include <linux/mfd/core.h>
22
23#include <linux/mfd/janz.h>
24
25#define DRV_NAME "janz-cmodio"
26
27/* Size of each MODULbus module in PCI BAR4 */
28#define CMODIO_MODULBUS_SIZE 0x200
29
30/* Maximum number of MODULbus modules on a CMOD-IO carrier board */
31#define CMODIO_MAX_MODULES 4
32
33/* Module Parameters */
34static unsigned int num_modules = CMODIO_MAX_MODULES;
35static unsigned char *modules[CMODIO_MAX_MODULES] = {
36 "empty", "empty", "empty", "empty",
37};
38
39module_param_array(modules, charp, &num_modules, S_IRUGO);
40MODULE_PARM_DESC(modules, "MODULbus modules attached to the carrier board");
41
42/* Unique Device Id */
43static unsigned int cmodio_id;
44
45struct cmodio_device {
46 /* Parent PCI device */
47 struct pci_dev *pdev;
48
49 /* PLX control registers */
50 struct janz_cmodio_onboard_regs __iomem *ctrl;
51
52 /* hex switch position */
53 u8 hex;
54
55 /* mfd-core API */
56 struct mfd_cell cells[CMODIO_MAX_MODULES];
57 struct resource resources[3 * CMODIO_MAX_MODULES];
58 struct janz_platform_data pdata[CMODIO_MAX_MODULES];
59};
60
61/*
62 * Subdevices using the mfd-core API
63 */
64
65static int __devinit cmodio_setup_subdevice(struct cmodio_device *priv,
66 char *name, unsigned int devno,
67 unsigned int modno)
68{
69 struct janz_platform_data *pdata;
70 struct mfd_cell *cell;
71 struct resource *res;
72 struct pci_dev *pci;
73
74 pci = priv->pdev;
75 cell = &priv->cells[devno];
76 res = &priv->resources[devno * 3];
77 pdata = &priv->pdata[devno];
78
79 cell->name = name;
80 cell->resources = res;
81 cell->num_resources = 3;
82
83 /* Setup the subdevice ID -- must be unique */
84 cell->id = cmodio_id++;
85
86 /* Add platform data */
87 pdata->modno = modno;
88 cell->platform_data = pdata;
89 cell->data_size = sizeof(*pdata);
90
91 /* MODULbus registers -- PCI BAR3 is big-endian MODULbus access */
92 res->flags = IORESOURCE_MEM;
93 res->parent = &pci->resource[3];
94 res->start = pci->resource[3].start + (CMODIO_MODULBUS_SIZE * modno);
95 res->end = res->start + CMODIO_MODULBUS_SIZE - 1;
96 res++;
97
98 /* PLX Control Registers -- PCI BAR4 is interrupt and other registers */
99 res->flags = IORESOURCE_MEM;
100 res->parent = &pci->resource[4];
101 res->start = pci->resource[4].start;
102 res->end = pci->resource[4].end;
103 res++;
104
105 /*
106 * IRQ
107 *
108 * The start and end fields are used as an offset to the irq_base
109 * parameter passed into the mfd_add_devices() function call. All
110 * devices share the same IRQ.
111 */
112 res->flags = IORESOURCE_IRQ;
113 res->parent = NULL;
114 res->start = 0;
115 res->end = 0;
116 res++;
117
118 return 0;
119}
120
121/* Probe each submodule using kernel parameters */
122static int __devinit cmodio_probe_submodules(struct cmodio_device *priv)
123{
124 struct pci_dev *pdev = priv->pdev;
125 unsigned int num_probed = 0;
126 char *name;
127 int i;
128
129 for (i = 0; i < num_modules; i++) {
130 name = modules[i];
131 if (!strcmp(name, "") || !strcmp(name, "empty"))
132 continue;
133
134 dev_dbg(&priv->pdev->dev, "MODULbus %d: name %s\n", i, name);
135 cmodio_setup_subdevice(priv, name, num_probed, i);
136 num_probed++;
137 }
138
139 /* print an error message if no modules were probed */
140 if (num_probed == 0) {
141 dev_err(&priv->pdev->dev, "no MODULbus modules specified, "
142 "please set the ``modules'' kernel "
143 "parameter according to your "
144 "hardware configuration\n");
145 return -ENODEV;
146 }
147
148 return mfd_add_devices(&pdev->dev, 0, priv->cells,
149 num_probed, NULL, pdev->irq);
150}
151
152/*
153 * SYSFS Attributes
154 */
155
156static ssize_t mbus_show(struct device *dev, struct device_attribute *attr,
157 char *buf)
158{
159 struct cmodio_device *priv = dev_get_drvdata(dev);
160
161 return snprintf(buf, PAGE_SIZE, "%x\n", priv->hex);
162}
163
164static DEVICE_ATTR(modulbus_number, S_IRUGO, mbus_show, NULL);
165
166static struct attribute *cmodio_sysfs_attrs[] = {
167 &dev_attr_modulbus_number.attr,
168 NULL,
169};
170
171static const struct attribute_group cmodio_sysfs_attr_group = {
172 .attrs = cmodio_sysfs_attrs,
173};
174
175/*
176 * PCI Driver
177 */
178
179static int __devinit cmodio_pci_probe(struct pci_dev *dev,
180 const struct pci_device_id *id)
181{
182 struct cmodio_device *priv;
183 int ret;
184
185 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
186 if (!priv) {
187 dev_err(&dev->dev, "unable to allocate private data\n");
188 ret = -ENOMEM;
189 goto out_return;
190 }
191
192 pci_set_drvdata(dev, priv);
193 priv->pdev = dev;
194
195 /* Hardware Initialization */
196 ret = pci_enable_device(dev);
197 if (ret) {
198 dev_err(&dev->dev, "unable to enable device\n");
199 goto out_free_priv;
200 }
201
202 pci_set_master(dev);
203 ret = pci_request_regions(dev, DRV_NAME);
204 if (ret) {
205 dev_err(&dev->dev, "unable to request regions\n");
206 goto out_pci_disable_device;
207 }
208
209 /* Onboard configuration registers */
210 priv->ctrl = pci_ioremap_bar(dev, 4);
211 if (!priv->ctrl) {
212 dev_err(&dev->dev, "unable to remap onboard regs\n");
213 ret = -ENOMEM;
214 goto out_pci_release_regions;
215 }
216
217 /* Read the hex switch on the carrier board */
218 priv->hex = ioread8(&priv->ctrl->int_enable);
219
220 /* Add the MODULbus number (hex switch value) to the device's sysfs */
221 ret = sysfs_create_group(&dev->dev.kobj, &cmodio_sysfs_attr_group);
222 if (ret) {
223 dev_err(&dev->dev, "unable to create sysfs attributes\n");
224 goto out_unmap_ctrl;
225 }
226
227 /*
228 * Disable all interrupt lines, each submodule will enable its
229 * own interrupt line if needed
230 */
231 iowrite8(0xf, &priv->ctrl->int_disable);
232
233 /* Register drivers for all submodules */
234 ret = cmodio_probe_submodules(priv);
235 if (ret) {
236 dev_err(&dev->dev, "unable to probe submodules\n");
237 goto out_sysfs_remove_group;
238 }
239
240 return 0;
241
242out_sysfs_remove_group:
243 sysfs_remove_group(&dev->dev.kobj, &cmodio_sysfs_attr_group);
244out_unmap_ctrl:
245 iounmap(priv->ctrl);
246out_pci_release_regions:
247 pci_release_regions(dev);
248out_pci_disable_device:
249 pci_disable_device(dev);
250out_free_priv:
251 kfree(priv);
252out_return:
253 return ret;
254}
255
256static void __devexit cmodio_pci_remove(struct pci_dev *dev)
257{
258 struct cmodio_device *priv = pci_get_drvdata(dev);
259
260 mfd_remove_devices(&dev->dev);
261 sysfs_remove_group(&dev->dev.kobj, &cmodio_sysfs_attr_group);
262 iounmap(priv->ctrl);
263 pci_release_regions(dev);
264 pci_disable_device(dev);
265 kfree(priv);
266}
267
268#define PCI_VENDOR_ID_JANZ 0x13c3
269
270/* The list of devices that this module will support */
271static DEFINE_PCI_DEVICE_TABLE(cmodio_pci_ids) = {
272 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030, PCI_VENDOR_ID_JANZ, 0x0101 },
273 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_VENDOR_ID_JANZ, 0x0100 },
274 { 0, }
275};
276MODULE_DEVICE_TABLE(pci, cmodio_pci_ids);
277
278static struct pci_driver cmodio_pci_driver = {
279 .name = DRV_NAME,
280 .id_table = cmodio_pci_ids,
281 .probe = cmodio_pci_probe,
282 .remove = __devexit_p(cmodio_pci_remove),
283};
284
285/*
286 * Module Init / Exit
287 */
288
289static int __init cmodio_init(void)
290{
291 return pci_register_driver(&cmodio_pci_driver);
292}
293
294static void __exit cmodio_exit(void)
295{
296 pci_unregister_driver(&cmodio_pci_driver);
297}
298
299MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>");
300MODULE_DESCRIPTION("Janz CMOD-IO PCI MODULbus Carrier Board Driver");
301MODULE_LICENSE("GPL");
302
303module_init(cmodio_init);
304module_exit(cmodio_exit);
diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
index 85d63c04749b..f621bcea3d02 100644
--- a/drivers/mfd/max8925-core.c
+++ b/drivers/mfd/max8925-core.c
@@ -508,7 +508,7 @@ static int max8925_irq_init(struct max8925_chip *chip, int irq,
508 max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ2); 508 max8925_reg_read(chip->i2c, MAX8925_ON_OFF_IRQ2);
509 max8925_reg_read(chip->rtc, MAX8925_RTC_IRQ); 509 max8925_reg_read(chip->rtc, MAX8925_RTC_IRQ);
510 max8925_reg_read(chip->adc, MAX8925_TSC_IRQ); 510 max8925_reg_read(chip->adc, MAX8925_TSC_IRQ);
511 /* mask all interrupts */ 511 /* mask all interrupts except for TSC */
512 max8925_reg_write(chip->rtc, MAX8925_ALARM0_CNTL, 0); 512 max8925_reg_write(chip->rtc, MAX8925_ALARM0_CNTL, 0);
513 max8925_reg_write(chip->rtc, MAX8925_ALARM1_CNTL, 0); 513 max8925_reg_write(chip->rtc, MAX8925_ALARM1_CNTL, 0);
514 max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, 0xff); 514 max8925_reg_write(chip->i2c, MAX8925_CHG_IRQ1_MASK, 0xff);
@@ -516,7 +516,6 @@ static int max8925_irq_init(struct max8925_chip *chip, int irq,
516 max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, 0xff); 516 max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ1_MASK, 0xff);
517 max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, 0xff); 517 max8925_reg_write(chip->i2c, MAX8925_ON_OFF_IRQ2_MASK, 0xff);
518 max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, 0xff); 518 max8925_reg_write(chip->rtc, MAX8925_RTC_IRQ_MASK, 0xff);
519 max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, 0xff);
520 519
521 mutex_init(&chip->irq_lock); 520 mutex_init(&chip->irq_lock);
522 chip->core_irq = irq; 521 chip->core_irq = irq;
@@ -547,7 +546,11 @@ static int max8925_irq_init(struct max8925_chip *chip, int irq,
547 dev_err(chip->dev, "Failed to request core IRQ: %d\n", ret); 546 dev_err(chip->dev, "Failed to request core IRQ: %d\n", ret);
548 chip->core_irq = 0; 547 chip->core_irq = 0;
549 } 548 }
549
550tsc_irq: 550tsc_irq:
551 /* mask TSC interrupt */
552 max8925_reg_write(chip->adc, MAX8925_TSC_IRQ_MASK, 0x0f);
553
551 if (!pdata->tsc_irq) { 554 if (!pdata->tsc_irq) {
552 dev_warn(chip->dev, "No interrupt support on TSC IRQ\n"); 555 dev_warn(chip->dev, "No interrupt support on TSC IRQ\n");
553 return 0; 556 return 0;
diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
index d9fd8785da4d..e73f3f5252a8 100644
--- a/drivers/mfd/max8925-i2c.c
+++ b/drivers/mfd/max8925-i2c.c
@@ -173,8 +173,6 @@ static int __devexit max8925_remove(struct i2c_client *client)
173 max8925_device_exit(chip); 173 max8925_device_exit(chip);
174 i2c_unregister_device(chip->adc); 174 i2c_unregister_device(chip->adc);
175 i2c_unregister_device(chip->rtc); 175 i2c_unregister_device(chip->rtc);
176 i2c_set_clientdata(chip->adc, NULL);
177 i2c_set_clientdata(chip->rtc, NULL);
178 i2c_set_clientdata(chip->i2c, NULL); 176 i2c_set_clientdata(chip->i2c, NULL);
179 kfree(chip); 177 kfree(chip);
180 return 0; 178 return 0;
diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c
index a94b131a18ef..721948be12c7 100644
--- a/drivers/mfd/menelaus.c
+++ b/drivers/mfd/menelaus.c
@@ -1228,6 +1228,7 @@ fail2:
1228 free_irq(client->irq, menelaus); 1228 free_irq(client->irq, menelaus);
1229 flush_scheduled_work(); 1229 flush_scheduled_work();
1230fail1: 1230fail1:
1231 i2c_set_clientdata(client, NULL);
1231 kfree(menelaus); 1232 kfree(menelaus);
1232 return err; 1233 return err;
1233} 1234}
@@ -1237,8 +1238,8 @@ static int __exit menelaus_remove(struct i2c_client *client)
1237 struct menelaus_chip *menelaus = i2c_get_clientdata(client); 1238 struct menelaus_chip *menelaus = i2c_get_clientdata(client);
1238 1239
1239 free_irq(client->irq, menelaus); 1240 free_irq(client->irq, menelaus);
1240 kfree(menelaus);
1241 i2c_set_clientdata(client, NULL); 1241 i2c_set_clientdata(client, NULL);
1242 kfree(menelaus);
1242 the_menelaus = NULL; 1243 the_menelaus = NULL;
1243 return 0; 1244 return 0;
1244} 1245}
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 8ffbb7a85a7e..7dd76bceaae8 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -48,7 +48,7 @@ static int mfd_add_device(struct device *parent, int id,
48 res[r].flags = cell->resources[r].flags; 48 res[r].flags = cell->resources[r].flags;
49 49
50 /* Find out base to use */ 50 /* Find out base to use */
51 if (cell->resources[r].flags & IORESOURCE_MEM) { 51 if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) {
52 res[r].parent = mem_base; 52 res[r].parent = mem_base;
53 res[r].start = mem_base->start + 53 res[r].start = mem_base->start +
54 cell->resources[r].start; 54 cell->resources[r].start;
diff --git a/drivers/mfd/pcf50633-adc.c b/drivers/mfd/pcf50633-adc.c
index fe8f922f6654..aed0d2a9b032 100644
--- a/drivers/mfd/pcf50633-adc.c
+++ b/drivers/mfd/pcf50633-adc.c
@@ -30,13 +30,13 @@
30struct pcf50633_adc_request { 30struct pcf50633_adc_request {
31 int mux; 31 int mux;
32 int avg; 32 int avg;
33 int result;
34 void (*callback)(struct pcf50633 *, void *, int); 33 void (*callback)(struct pcf50633 *, void *, int);
35 void *callback_param; 34 void *callback_param;
35};
36 36
37 /* Used in case of sync requests */ 37struct pcf50633_adc_sync_request {
38 int result;
38 struct completion completion; 39 struct completion completion;
39
40}; 40};
41 41
42#define PCF50633_MAX_ADC_FIFO_DEPTH 8 42#define PCF50633_MAX_ADC_FIFO_DEPTH 8
@@ -109,10 +109,10 @@ adc_enqueue_request(struct pcf50633 *pcf, struct pcf50633_adc_request *req)
109 return 0; 109 return 0;
110} 110}
111 111
112static void 112static void pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param,
113pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param, int result) 113 int result)
114{ 114{
115 struct pcf50633_adc_request *req = param; 115 struct pcf50633_adc_sync_request *req = param;
116 116
117 req->result = result; 117 req->result = result;
118 complete(&req->completion); 118 complete(&req->completion);
@@ -120,28 +120,19 @@ pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param, int result)
120 120
121int pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg) 121int pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg)
122{ 122{
123 struct pcf50633_adc_request *req; 123 struct pcf50633_adc_sync_request req;
124 int err; 124 int ret;
125 125
126 /* req is freed when the result is ready, in interrupt handler */ 126 init_completion(&req.completion);
127 req = kzalloc(sizeof(*req), GFP_KERNEL);
128 if (!req)
129 return -ENOMEM;
130
131 req->mux = mux;
132 req->avg = avg;
133 req->callback = pcf50633_adc_sync_read_callback;
134 req->callback_param = req;
135 127
136 init_completion(&req->completion); 128 ret = pcf50633_adc_async_read(pcf, mux, avg,
137 err = adc_enqueue_request(pcf, req); 129 pcf50633_adc_sync_read_callback, &req);
138 if (err) 130 if (ret)
139 return err; 131 return ret;
140 132
141 wait_for_completion(&req->completion); 133 wait_for_completion(&req.completion);
142 134
143 /* FIXME by this time req might be already freed */ 135 return req.result;
144 return req->result;
145} 136}
146EXPORT_SYMBOL_GPL(pcf50633_adc_sync_read); 137EXPORT_SYMBOL_GPL(pcf50633_adc_sync_read);
147 138
diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c
index dc95ddb708f1..704736e6e9b9 100644
--- a/drivers/mfd/pcf50633-core.c
+++ b/drivers/mfd/pcf50633-core.c
@@ -21,16 +21,16 @@
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/irq.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26 25
27#include <linux/mfd/pcf50633/core.h> 26#include <linux/mfd/pcf50633/core.h>
28 27
29/* Two MBCS registers used during cold start */ 28int pcf50633_irq_init(struct pcf50633 *pcf, int irq);
30#define PCF50633_REG_MBCS1 0x4b 29void pcf50633_irq_free(struct pcf50633 *pcf);
31#define PCF50633_REG_MBCS2 0x4c 30#ifdef CONFIG_PM
32#define PCF50633_MBCS1_USBPRES 0x01 31int pcf50633_irq_suspend(struct pcf50633 *pcf);
33#define PCF50633_MBCS1_ADAPTPRES 0x01 32int pcf50633_irq_resume(struct pcf50633 *pcf);
33#endif
34 34
35static int __pcf50633_read(struct pcf50633 *pcf, u8 reg, int num, u8 *data) 35static int __pcf50633_read(struct pcf50633 *pcf, u8 reg, int num, u8 *data)
36{ 36{
@@ -215,244 +215,6 @@ static struct attribute_group pcf_attr_group = {
215 .attrs = pcf_sysfs_entries, 215 .attrs = pcf_sysfs_entries,
216}; 216};
217 217
218int pcf50633_register_irq(struct pcf50633 *pcf, int irq,
219 void (*handler) (int, void *), void *data)
220{
221 if (irq < 0 || irq > PCF50633_NUM_IRQ || !handler)
222 return -EINVAL;
223
224 if (WARN_ON(pcf->irq_handler[irq].handler))
225 return -EBUSY;
226
227 mutex_lock(&pcf->lock);
228 pcf->irq_handler[irq].handler = handler;
229 pcf->irq_handler[irq].data = data;
230 mutex_unlock(&pcf->lock);
231
232 return 0;
233}
234EXPORT_SYMBOL_GPL(pcf50633_register_irq);
235
236int pcf50633_free_irq(struct pcf50633 *pcf, int irq)
237{
238 if (irq < 0 || irq > PCF50633_NUM_IRQ)
239 return -EINVAL;
240
241 mutex_lock(&pcf->lock);
242 pcf->irq_handler[irq].handler = NULL;
243 mutex_unlock(&pcf->lock);
244
245 return 0;
246}
247EXPORT_SYMBOL_GPL(pcf50633_free_irq);
248
249static int __pcf50633_irq_mask_set(struct pcf50633 *pcf, int irq, u8 mask)
250{
251 u8 reg, bits, tmp;
252 int ret = 0, idx;
253
254 idx = irq >> 3;
255 reg = PCF50633_REG_INT1M + idx;
256 bits = 1 << (irq & 0x07);
257
258 mutex_lock(&pcf->lock);
259
260 if (mask) {
261 ret = __pcf50633_read(pcf, reg, 1, &tmp);
262 if (ret < 0)
263 goto out;
264
265 tmp |= bits;
266
267 ret = __pcf50633_write(pcf, reg, 1, &tmp);
268 if (ret < 0)
269 goto out;
270
271 pcf->mask_regs[idx] &= ~bits;
272 pcf->mask_regs[idx] |= bits;
273 } else {
274 ret = __pcf50633_read(pcf, reg, 1, &tmp);
275 if (ret < 0)
276 goto out;
277
278 tmp &= ~bits;
279
280 ret = __pcf50633_write(pcf, reg, 1, &tmp);
281 if (ret < 0)
282 goto out;
283
284 pcf->mask_regs[idx] &= ~bits;
285 }
286out:
287 mutex_unlock(&pcf->lock);
288
289 return ret;
290}
291
292int pcf50633_irq_mask(struct pcf50633 *pcf, int irq)
293{
294 dev_dbg(pcf->dev, "Masking IRQ %d\n", irq);
295
296 return __pcf50633_irq_mask_set(pcf, irq, 1);
297}
298EXPORT_SYMBOL_GPL(pcf50633_irq_mask);
299
300int pcf50633_irq_unmask(struct pcf50633 *pcf, int irq)
301{
302 dev_dbg(pcf->dev, "Unmasking IRQ %d\n", irq);
303
304 return __pcf50633_irq_mask_set(pcf, irq, 0);
305}
306EXPORT_SYMBOL_GPL(pcf50633_irq_unmask);
307
308int pcf50633_irq_mask_get(struct pcf50633 *pcf, int irq)
309{
310 u8 reg, bits;
311
312 reg = irq >> 3;
313 bits = 1 << (irq & 0x07);
314
315 return pcf->mask_regs[reg] & bits;
316}
317EXPORT_SYMBOL_GPL(pcf50633_irq_mask_get);
318
319static void pcf50633_irq_call_handler(struct pcf50633 *pcf, int irq)
320{
321 if (pcf->irq_handler[irq].handler)
322 pcf->irq_handler[irq].handler(irq, pcf->irq_handler[irq].data);
323}
324
325/* Maximum amount of time ONKEY is held before emergency action is taken */
326#define PCF50633_ONKEY1S_TIMEOUT 8
327
328static void pcf50633_irq_worker(struct work_struct *work)
329{
330 struct pcf50633 *pcf;
331 int ret, i, j;
332 u8 pcf_int[5], chgstat;
333
334 pcf = container_of(work, struct pcf50633, irq_work);
335
336 /* Read the 5 INT regs in one transaction */
337 ret = pcf50633_read_block(pcf, PCF50633_REG_INT1,
338 ARRAY_SIZE(pcf_int), pcf_int);
339 if (ret != ARRAY_SIZE(pcf_int)) {
340 dev_err(pcf->dev, "Error reading INT registers\n");
341
342 /*
343 * If this doesn't ACK the interrupt to the chip, we'll be
344 * called once again as we're level triggered.
345 */
346 goto out;
347 }
348
349 /* defeat 8s death from lowsys on A5 */
350 pcf50633_reg_write(pcf, PCF50633_REG_OOCSHDWN, 0x04);
351
352 /* We immediately read the usb and adapter status. We thus make sure
353 * only of USBINS/USBREM IRQ handlers are called */
354 if (pcf_int[0] & (PCF50633_INT1_USBINS | PCF50633_INT1_USBREM)) {
355 chgstat = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
356 if (chgstat & (0x3 << 4))
357 pcf_int[0] &= ~(1 << PCF50633_INT1_USBREM);
358 else
359 pcf_int[0] &= ~(1 << PCF50633_INT1_USBINS);
360 }
361
362 /* Make sure only one of ADPINS or ADPREM is set */
363 if (pcf_int[0] & (PCF50633_INT1_ADPINS | PCF50633_INT1_ADPREM)) {
364 chgstat = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
365 if (chgstat & (0x3 << 4))
366 pcf_int[0] &= ~(1 << PCF50633_INT1_ADPREM);
367 else
368 pcf_int[0] &= ~(1 << PCF50633_INT1_ADPINS);
369 }
370
371 dev_dbg(pcf->dev, "INT1=0x%02x INT2=0x%02x INT3=0x%02x "
372 "INT4=0x%02x INT5=0x%02x\n", pcf_int[0],
373 pcf_int[1], pcf_int[2], pcf_int[3], pcf_int[4]);
374
375 /* Some revisions of the chip don't have a 8s standby mode on
376 * ONKEY1S press. We try to manually do it in such cases. */
377 if ((pcf_int[0] & PCF50633_INT1_SECOND) && pcf->onkey1s_held) {
378 dev_info(pcf->dev, "ONKEY1S held for %d secs\n",
379 pcf->onkey1s_held);
380 if (pcf->onkey1s_held++ == PCF50633_ONKEY1S_TIMEOUT)
381 if (pcf->pdata->force_shutdown)
382 pcf->pdata->force_shutdown(pcf);
383 }
384
385 if (pcf_int[2] & PCF50633_INT3_ONKEY1S) {
386 dev_info(pcf->dev, "ONKEY1S held\n");
387 pcf->onkey1s_held = 1 ;
388
389 /* Unmask IRQ_SECOND */
390 pcf50633_reg_clear_bits(pcf, PCF50633_REG_INT1M,
391 PCF50633_INT1_SECOND);
392
393 /* Unmask IRQ_ONKEYR */
394 pcf50633_reg_clear_bits(pcf, PCF50633_REG_INT2M,
395 PCF50633_INT2_ONKEYR);
396 }
397
398 if ((pcf_int[1] & PCF50633_INT2_ONKEYR) && pcf->onkey1s_held) {
399 pcf->onkey1s_held = 0;
400
401 /* Mask SECOND and ONKEYR interrupts */
402 if (pcf->mask_regs[0] & PCF50633_INT1_SECOND)
403 pcf50633_reg_set_bit_mask(pcf,
404 PCF50633_REG_INT1M,
405 PCF50633_INT1_SECOND,
406 PCF50633_INT1_SECOND);
407
408 if (pcf->mask_regs[1] & PCF50633_INT2_ONKEYR)
409 pcf50633_reg_set_bit_mask(pcf,
410 PCF50633_REG_INT2M,
411 PCF50633_INT2_ONKEYR,
412 PCF50633_INT2_ONKEYR);
413 }
414
415 /* Have we just resumed ? */
416 if (pcf->is_suspended) {
417 pcf->is_suspended = 0;
418
419 /* Set the resume reason filtering out non resumers */
420 for (i = 0; i < ARRAY_SIZE(pcf_int); i++)
421 pcf->resume_reason[i] = pcf_int[i] &
422 pcf->pdata->resumers[i];
423
424 /* Make sure we don't pass on any ONKEY events to
425 * userspace now */
426 pcf_int[1] &= ~(PCF50633_INT2_ONKEYR | PCF50633_INT2_ONKEYF);
427 }
428
429 for (i = 0; i < ARRAY_SIZE(pcf_int); i++) {
430 /* Unset masked interrupts */
431 pcf_int[i] &= ~pcf->mask_regs[i];
432
433 for (j = 0; j < 8 ; j++)
434 if (pcf_int[i] & (1 << j))
435 pcf50633_irq_call_handler(pcf, (i * 8) + j);
436 }
437
438out:
439 put_device(pcf->dev);
440 enable_irq(pcf->irq);
441}
442
443static irqreturn_t pcf50633_irq(int irq, void *data)
444{
445 struct pcf50633 *pcf = data;
446
447 dev_dbg(pcf->dev, "pcf50633_irq\n");
448
449 get_device(pcf->dev);
450 disable_irq_nosync(pcf->irq);
451 queue_work(pcf->work_queue, &pcf->irq_work);
452
453 return IRQ_HANDLED;
454}
455
456static void 218static void
457pcf50633_client_dev_register(struct pcf50633 *pcf, const char *name, 219pcf50633_client_dev_register(struct pcf50633 *pcf, const char *name,
458 struct platform_device **pdev) 220 struct platform_device **pdev)
@@ -479,70 +241,17 @@ pcf50633_client_dev_register(struct pcf50633 *pcf, const char *name,
479static int pcf50633_suspend(struct i2c_client *client, pm_message_t state) 241static int pcf50633_suspend(struct i2c_client *client, pm_message_t state)
480{ 242{
481 struct pcf50633 *pcf; 243 struct pcf50633 *pcf;
482 int ret = 0, i;
483 u8 res[5];
484
485 pcf = i2c_get_clientdata(client); 244 pcf = i2c_get_clientdata(client);
486 245
487 /* Make sure our interrupt handlers are not called 246 return pcf50633_irq_suspend(pcf);
488 * henceforth */
489 disable_irq(pcf->irq);
490
491 /* Make sure that any running IRQ worker has quit */
492 cancel_work_sync(&pcf->irq_work);
493
494 /* Save the masks */
495 ret = pcf50633_read_block(pcf, PCF50633_REG_INT1M,
496 ARRAY_SIZE(pcf->suspend_irq_masks),
497 pcf->suspend_irq_masks);
498 if (ret < 0) {
499 dev_err(pcf->dev, "error saving irq masks\n");
500 goto out;
501 }
502
503 /* Write wakeup irq masks */
504 for (i = 0; i < ARRAY_SIZE(res); i++)
505 res[i] = ~pcf->pdata->resumers[i];
506
507 ret = pcf50633_write_block(pcf, PCF50633_REG_INT1M,
508 ARRAY_SIZE(res), &res[0]);
509 if (ret < 0) {
510 dev_err(pcf->dev, "error writing wakeup irq masks\n");
511 goto out;
512 }
513
514 pcf->is_suspended = 1;
515
516out:
517 return ret;
518} 247}
519 248
520static int pcf50633_resume(struct i2c_client *client) 249static int pcf50633_resume(struct i2c_client *client)
521{ 250{
522 struct pcf50633 *pcf; 251 struct pcf50633 *pcf;
523 int ret;
524
525 pcf = i2c_get_clientdata(client); 252 pcf = i2c_get_clientdata(client);
526 253
527 /* Write the saved mask registers */ 254 return pcf50633_irq_resume(pcf);
528 ret = pcf50633_write_block(pcf, PCF50633_REG_INT1M,
529 ARRAY_SIZE(pcf->suspend_irq_masks),
530 pcf->suspend_irq_masks);
531 if (ret < 0)
532 dev_err(pcf->dev, "Error restoring saved suspend masks\n");
533
534 /* Restore regulators' state */
535
536
537 get_device(pcf->dev);
538
539 /*
540 * Clear any pending interrupts and set resume reason if any.
541 * This will leave with enable_irq()
542 */
543 pcf50633_irq_worker(&pcf->irq_work);
544
545 return 0;
546} 255}
547#else 256#else
548#define pcf50633_suspend NULL 257#define pcf50633_suspend NULL
@@ -573,43 +282,19 @@ static int __devinit pcf50633_probe(struct i2c_client *client,
573 i2c_set_clientdata(client, pcf); 282 i2c_set_clientdata(client, pcf);
574 pcf->dev = &client->dev; 283 pcf->dev = &client->dev;
575 pcf->i2c_client = client; 284 pcf->i2c_client = client;
576 pcf->irq = client->irq;
577 pcf->work_queue = create_singlethread_workqueue("pcf50633");
578
579 if (!pcf->work_queue) {
580 dev_err(&client->dev, "Failed to alloc workqueue\n");
581 ret = -ENOMEM;
582 goto err_free;
583 }
584
585 INIT_WORK(&pcf->irq_work, pcf50633_irq_worker);
586 285
587 version = pcf50633_reg_read(pcf, 0); 286 version = pcf50633_reg_read(pcf, 0);
588 variant = pcf50633_reg_read(pcf, 1); 287 variant = pcf50633_reg_read(pcf, 1);
589 if (version < 0 || variant < 0) { 288 if (version < 0 || variant < 0) {
590 dev_err(pcf->dev, "Unable to probe pcf50633\n"); 289 dev_err(pcf->dev, "Unable to probe pcf50633\n");
591 ret = -ENODEV; 290 ret = -ENODEV;
592 goto err_destroy_workqueue; 291 goto err_free;
593 } 292 }
594 293
595 dev_info(pcf->dev, "Probed device version %d variant %d\n", 294 dev_info(pcf->dev, "Probed device version %d variant %d\n",
596 version, variant); 295 version, variant);
597 296
598 /* Enable all interrupts except RTC SECOND */ 297 pcf50633_irq_init(pcf, client->irq);
599 pcf->mask_regs[0] = 0x80;
600 pcf50633_reg_write(pcf, PCF50633_REG_INT1M, pcf->mask_regs[0]);
601 pcf50633_reg_write(pcf, PCF50633_REG_INT2M, 0x00);
602 pcf50633_reg_write(pcf, PCF50633_REG_INT3M, 0x00);
603 pcf50633_reg_write(pcf, PCF50633_REG_INT4M, 0x00);
604 pcf50633_reg_write(pcf, PCF50633_REG_INT5M, 0x00);
605
606 ret = request_irq(client->irq, pcf50633_irq,
607 IRQF_TRIGGER_LOW, "pcf50633", pcf);
608
609 if (ret) {
610 dev_err(pcf->dev, "Failed to request IRQ %d\n", ret);
611 goto err_destroy_workqueue;
612 }
613 298
614 /* Create sub devices */ 299 /* Create sub devices */
615 pcf50633_client_dev_register(pcf, "pcf50633-input", 300 pcf50633_client_dev_register(pcf, "pcf50633-input",
@@ -641,10 +326,6 @@ static int __devinit pcf50633_probe(struct i2c_client *client,
641 platform_device_add(pdev); 326 platform_device_add(pdev);
642 } 327 }
643 328
644 if (enable_irq_wake(client->irq) < 0)
645 dev_err(pcf->dev, "IRQ %u cannot be enabled as wake-up source"
646 "in this hardware revision", client->irq);
647
648 ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group); 329 ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group);
649 if (ret) 330 if (ret)
650 dev_err(pcf->dev, "error creating sysfs entries\n"); 331 dev_err(pcf->dev, "error creating sysfs entries\n");
@@ -654,8 +335,6 @@ static int __devinit pcf50633_probe(struct i2c_client *client,
654 335
655 return 0; 336 return 0;
656 337
657err_destroy_workqueue:
658 destroy_workqueue(pcf->work_queue);
659err_free: 338err_free:
660 i2c_set_clientdata(client, NULL); 339 i2c_set_clientdata(client, NULL);
661 kfree(pcf); 340 kfree(pcf);
@@ -668,8 +347,7 @@ static int __devexit pcf50633_remove(struct i2c_client *client)
668 struct pcf50633 *pcf = i2c_get_clientdata(client); 347 struct pcf50633 *pcf = i2c_get_clientdata(client);
669 int i; 348 int i;
670 349
671 free_irq(pcf->irq, pcf); 350 pcf50633_irq_free(pcf);
672 destroy_workqueue(pcf->work_queue);
673 351
674 platform_device_unregister(pcf->input_pdev); 352 platform_device_unregister(pcf->input_pdev);
675 platform_device_unregister(pcf->rtc_pdev); 353 platform_device_unregister(pcf->rtc_pdev);
@@ -679,6 +357,7 @@ static int __devexit pcf50633_remove(struct i2c_client *client)
679 for (i = 0; i < PCF50633_NUM_REGULATORS; i++) 357 for (i = 0; i < PCF50633_NUM_REGULATORS; i++)
680 platform_device_unregister(pcf->regulator_pdev[i]); 358 platform_device_unregister(pcf->regulator_pdev[i]);
681 359
360 i2c_set_clientdata(client, NULL);
682 kfree(pcf); 361 kfree(pcf);
683 362
684 return 0; 363 return 0;
diff --git a/drivers/mfd/pcf50633-irq.c b/drivers/mfd/pcf50633-irq.c
new file mode 100644
index 000000000000..1b0192f1efff
--- /dev/null
+++ b/drivers/mfd/pcf50633-irq.c
@@ -0,0 +1,318 @@
1/* NXP PCF50633 Power Management Unit (PMU) driver
2 *
3 * (C) 2006-2008 by Openmoko, Inc.
4 * Author: Harald Welte <laforge@openmoko.org>
5 * Balaji Rao <balajirrao@openmoko.org>
6 * All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/interrupt.h>
16#include <linux/kernel.h>
17#include <linux/mutex.h>
18#include <linux/slab.h>
19
20#include <linux/mfd/pcf50633/core.h>
21
22/* Two MBCS registers used during cold start */
23#define PCF50633_REG_MBCS1 0x4b
24#define PCF50633_REG_MBCS2 0x4c
25#define PCF50633_MBCS1_USBPRES 0x01
26#define PCF50633_MBCS1_ADAPTPRES 0x01
27
28int pcf50633_register_irq(struct pcf50633 *pcf, int irq,
29 void (*handler) (int, void *), void *data)
30{
31 if (irq < 0 || irq >= PCF50633_NUM_IRQ || !handler)
32 return -EINVAL;
33
34 if (WARN_ON(pcf->irq_handler[irq].handler))
35 return -EBUSY;
36
37 mutex_lock(&pcf->lock);
38 pcf->irq_handler[irq].handler = handler;
39 pcf->irq_handler[irq].data = data;
40 mutex_unlock(&pcf->lock);
41
42 return 0;
43}
44EXPORT_SYMBOL_GPL(pcf50633_register_irq);
45
46int pcf50633_free_irq(struct pcf50633 *pcf, int irq)
47{
48 if (irq < 0 || irq >= PCF50633_NUM_IRQ)
49 return -EINVAL;
50
51 mutex_lock(&pcf->lock);
52 pcf->irq_handler[irq].handler = NULL;
53 mutex_unlock(&pcf->lock);
54
55 return 0;
56}
57EXPORT_SYMBOL_GPL(pcf50633_free_irq);
58
59static int __pcf50633_irq_mask_set(struct pcf50633 *pcf, int irq, u8 mask)
60{
61 u8 reg, bit;
62 int ret = 0, idx;
63
64 idx = irq >> 3;
65 reg = PCF50633_REG_INT1M + idx;
66 bit = 1 << (irq & 0x07);
67
68 pcf50633_reg_set_bit_mask(pcf, reg, bit, mask ? bit : 0);
69
70 mutex_lock(&pcf->lock);
71
72 if (mask)
73 pcf->mask_regs[idx] |= bit;
74 else
75 pcf->mask_regs[idx] &= ~bit;
76
77 mutex_unlock(&pcf->lock);
78
79 return ret;
80}
81
82int pcf50633_irq_mask(struct pcf50633 *pcf, int irq)
83{
84 dev_dbg(pcf->dev, "Masking IRQ %d\n", irq);
85
86 return __pcf50633_irq_mask_set(pcf, irq, 1);
87}
88EXPORT_SYMBOL_GPL(pcf50633_irq_mask);
89
90int pcf50633_irq_unmask(struct pcf50633 *pcf, int irq)
91{
92 dev_dbg(pcf->dev, "Unmasking IRQ %d\n", irq);
93
94 return __pcf50633_irq_mask_set(pcf, irq, 0);
95}
96EXPORT_SYMBOL_GPL(pcf50633_irq_unmask);
97
98int pcf50633_irq_mask_get(struct pcf50633 *pcf, int irq)
99{
100 u8 reg, bits;
101
102 reg = irq >> 3;
103 bits = 1 << (irq & 0x07);
104
105 return pcf->mask_regs[reg] & bits;
106}
107EXPORT_SYMBOL_GPL(pcf50633_irq_mask_get);
108
109static void pcf50633_irq_call_handler(struct pcf50633 *pcf, int irq)
110{
111 if (pcf->irq_handler[irq].handler)
112 pcf->irq_handler[irq].handler(irq, pcf->irq_handler[irq].data);
113}
114
115/* Maximum amount of time ONKEY is held before emergency action is taken */
116#define PCF50633_ONKEY1S_TIMEOUT 8
117
118static irqreturn_t pcf50633_irq(int irq, void *data)
119{
120 struct pcf50633 *pcf = data;
121 int ret, i, j;
122 u8 pcf_int[5], chgstat;
123
124 /* Read the 5 INT regs in one transaction */
125 ret = pcf50633_read_block(pcf, PCF50633_REG_INT1,
126 ARRAY_SIZE(pcf_int), pcf_int);
127 if (ret != ARRAY_SIZE(pcf_int)) {
128 dev_err(pcf->dev, "Error reading INT registers\n");
129
130 /*
131 * If this doesn't ACK the interrupt to the chip, we'll be
132 * called once again as we're level triggered.
133 */
134 goto out;
135 }
136
137 /* defeat 8s death from lowsys on A5 */
138 pcf50633_reg_write(pcf, PCF50633_REG_OOCSHDWN, 0x04);
139
140 /* We immediately read the usb and adapter status. We thus make sure
141 * only of USBINS/USBREM IRQ handlers are called */
142 if (pcf_int[0] & (PCF50633_INT1_USBINS | PCF50633_INT1_USBREM)) {
143 chgstat = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
144 if (chgstat & (0x3 << 4))
145 pcf_int[0] &= ~PCF50633_INT1_USBREM;
146 else
147 pcf_int[0] &= ~PCF50633_INT1_USBINS;
148 }
149
150 /* Make sure only one of ADPINS or ADPREM is set */
151 if (pcf_int[0] & (PCF50633_INT1_ADPINS | PCF50633_INT1_ADPREM)) {
152 chgstat = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
153 if (chgstat & (0x3 << 4))
154 pcf_int[0] &= ~PCF50633_INT1_ADPREM;
155 else
156 pcf_int[0] &= ~PCF50633_INT1_ADPINS;
157 }
158
159 dev_dbg(pcf->dev, "INT1=0x%02x INT2=0x%02x INT3=0x%02x "
160 "INT4=0x%02x INT5=0x%02x\n", pcf_int[0],
161 pcf_int[1], pcf_int[2], pcf_int[3], pcf_int[4]);
162
163 /* Some revisions of the chip don't have a 8s standby mode on
164 * ONKEY1S press. We try to manually do it in such cases. */
165 if ((pcf_int[0] & PCF50633_INT1_SECOND) && pcf->onkey1s_held) {
166 dev_info(pcf->dev, "ONKEY1S held for %d secs\n",
167 pcf->onkey1s_held);
168 if (pcf->onkey1s_held++ == PCF50633_ONKEY1S_TIMEOUT)
169 if (pcf->pdata->force_shutdown)
170 pcf->pdata->force_shutdown(pcf);
171 }
172
173 if (pcf_int[2] & PCF50633_INT3_ONKEY1S) {
174 dev_info(pcf->dev, "ONKEY1S held\n");
175 pcf->onkey1s_held = 1 ;
176
177 /* Unmask IRQ_SECOND */
178 pcf50633_reg_clear_bits(pcf, PCF50633_REG_INT1M,
179 PCF50633_INT1_SECOND);
180
181 /* Unmask IRQ_ONKEYR */
182 pcf50633_reg_clear_bits(pcf, PCF50633_REG_INT2M,
183 PCF50633_INT2_ONKEYR);
184 }
185
186 if ((pcf_int[1] & PCF50633_INT2_ONKEYR) && pcf->onkey1s_held) {
187 pcf->onkey1s_held = 0;
188
189 /* Mask SECOND and ONKEYR interrupts */
190 if (pcf->mask_regs[0] & PCF50633_INT1_SECOND)
191 pcf50633_reg_set_bit_mask(pcf,
192 PCF50633_REG_INT1M,
193 PCF50633_INT1_SECOND,
194 PCF50633_INT1_SECOND);
195
196 if (pcf->mask_regs[1] & PCF50633_INT2_ONKEYR)
197 pcf50633_reg_set_bit_mask(pcf,
198 PCF50633_REG_INT2M,
199 PCF50633_INT2_ONKEYR,
200 PCF50633_INT2_ONKEYR);
201 }
202
203 /* Have we just resumed ? */
204 if (pcf->is_suspended) {
205 pcf->is_suspended = 0;
206
207 /* Set the resume reason filtering out non resumers */
208 for (i = 0; i < ARRAY_SIZE(pcf_int); i++)
209 pcf->resume_reason[i] = pcf_int[i] &
210 pcf->pdata->resumers[i];
211
212 /* Make sure we don't pass on any ONKEY events to
213 * userspace now */
214 pcf_int[1] &= ~(PCF50633_INT2_ONKEYR | PCF50633_INT2_ONKEYF);
215 }
216
217 for (i = 0; i < ARRAY_SIZE(pcf_int); i++) {
218 /* Unset masked interrupts */
219 pcf_int[i] &= ~pcf->mask_regs[i];
220
221 for (j = 0; j < 8 ; j++)
222 if (pcf_int[i] & (1 << j))
223 pcf50633_irq_call_handler(pcf, (i * 8) + j);
224 }
225
226out:
227 return IRQ_HANDLED;
228}
229
230#ifdef CONFIG_PM
231
232int pcf50633_irq_suspend(struct pcf50633 *pcf)
233{
234 int ret;
235 int i;
236 u8 res[5];
237
238
239 /* Make sure our interrupt handlers are not called
240 * henceforth */
241 disable_irq(pcf->irq);
242
243 /* Save the masks */
244 ret = pcf50633_read_block(pcf, PCF50633_REG_INT1M,
245 ARRAY_SIZE(pcf->suspend_irq_masks),
246 pcf->suspend_irq_masks);
247 if (ret < 0) {
248 dev_err(pcf->dev, "error saving irq masks\n");
249 goto out;
250 }
251
252 /* Write wakeup irq masks */
253 for (i = 0; i < ARRAY_SIZE(res); i++)
254 res[i] = ~pcf->pdata->resumers[i];
255
256 ret = pcf50633_write_block(pcf, PCF50633_REG_INT1M,
257 ARRAY_SIZE(res), &res[0]);
258 if (ret < 0) {
259 dev_err(pcf->dev, "error writing wakeup irq masks\n");
260 goto out;
261 }
262
263 pcf->is_suspended = 1;
264
265out:
266 return ret;
267}
268
269int pcf50633_irq_resume(struct pcf50633 *pcf)
270{
271 int ret;
272
273 /* Write the saved mask registers */
274 ret = pcf50633_write_block(pcf, PCF50633_REG_INT1M,
275 ARRAY_SIZE(pcf->suspend_irq_masks),
276 pcf->suspend_irq_masks);
277 if (ret < 0)
278 dev_err(pcf->dev, "Error restoring saved suspend masks\n");
279
280 enable_irq(pcf->irq);
281
282 return ret;
283}
284
285#endif
286
287int pcf50633_irq_init(struct pcf50633 *pcf, int irq)
288{
289 int ret;
290
291 pcf->irq = irq;
292
293 /* Enable all interrupts except RTC SECOND */
294 pcf->mask_regs[0] = 0x80;
295 pcf50633_reg_write(pcf, PCF50633_REG_INT1M, pcf->mask_regs[0]);
296 pcf50633_reg_write(pcf, PCF50633_REG_INT2M, 0x00);
297 pcf50633_reg_write(pcf, PCF50633_REG_INT3M, 0x00);
298 pcf50633_reg_write(pcf, PCF50633_REG_INT4M, 0x00);
299 pcf50633_reg_write(pcf, PCF50633_REG_INT5M, 0x00);
300
301 ret = request_threaded_irq(irq, NULL, pcf50633_irq,
302 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
303 "pcf50633", pcf);
304
305 if (ret)
306 dev_err(pcf->dev, "Failed to request IRQ %d\n", ret);
307
308 if (enable_irq_wake(irq) < 0)
309 dev_err(pcf->dev, "IRQ %u cannot be enabled as wake-up source"
310 "in this hardware revision", irq);
311
312 return ret;
313}
314
315void pcf50633_irq_free(struct pcf50633 *pcf)
316{
317 free_irq(pcf->irq, pcf);
318}
diff --git a/drivers/mfd/rdc321x-southbridge.c b/drivers/mfd/rdc321x-southbridge.c
new file mode 100644
index 000000000000..50922975bda3
--- /dev/null
+++ b/drivers/mfd/rdc321x-southbridge.c
@@ -0,0 +1,123 @@
1/*
2 * RDC321x MFD southbrige driver
3 *
4 * Copyright (C) 2007-2010 Florian Fainelli <florian@openwrt.org>
5 * Copyright (C) 2010 Bernhard Loos <bernhardloos@googlemail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/platform_device.h>
26#include <linux/pci.h>
27#include <linux/mfd/core.h>
28#include <linux/mfd/rdc321x.h>
29
30static struct rdc321x_wdt_pdata rdc321x_wdt_pdata;
31
32static struct resource rdc321x_wdt_resource[] = {
33 {
34 .name = "wdt-reg",
35 .start = RDC321X_WDT_CTRL,
36 .end = RDC321X_WDT_CTRL + 0x3,
37 .flags = IORESOURCE_IO,
38 }
39};
40
41static struct rdc321x_gpio_pdata rdc321x_gpio_pdata = {
42 .max_gpios = RDC321X_MAX_GPIO,
43};
44
45static struct resource rdc321x_gpio_resources[] = {
46 {
47 .name = "gpio-reg1",
48 .start = RDC321X_GPIO_CTRL_REG1,
49 .end = RDC321X_GPIO_CTRL_REG1 + 0x7,
50 .flags = IORESOURCE_IO,
51 }, {
52 .name = "gpio-reg2",
53 .start = RDC321X_GPIO_CTRL_REG2,
54 .end = RDC321X_GPIO_CTRL_REG2 + 0x7,
55 .flags = IORESOURCE_IO,
56 }
57};
58
59static struct mfd_cell rdc321x_sb_cells[] = {
60 {
61 .name = "rdc321x-wdt",
62 .resources = rdc321x_wdt_resource,
63 .num_resources = ARRAY_SIZE(rdc321x_wdt_resource),
64 .driver_data = &rdc321x_wdt_pdata,
65 }, {
66 .name = "rdc321x-gpio",
67 .resources = rdc321x_gpio_resources,
68 .num_resources = ARRAY_SIZE(rdc321x_gpio_resources),
69 .driver_data = &rdc321x_gpio_pdata,
70 },
71};
72
73static int __devinit rdc321x_sb_probe(struct pci_dev *pdev,
74 const struct pci_device_id *ent)
75{
76 int err;
77
78 err = pci_enable_device(pdev);
79 if (err) {
80 dev_err(&pdev->dev, "failed to enable device\n");
81 return err;
82 }
83
84 rdc321x_gpio_pdata.sb_pdev = pdev;
85 rdc321x_wdt_pdata.sb_pdev = pdev;
86
87 return mfd_add_devices(&pdev->dev, -1,
88 rdc321x_sb_cells, ARRAY_SIZE(rdc321x_sb_cells), NULL, 0);
89}
90
91static void __devexit rdc321x_sb_remove(struct pci_dev *pdev)
92{
93 mfd_remove_devices(&pdev->dev);
94}
95
96static DEFINE_PCI_DEVICE_TABLE(rdc321x_sb_table) = {
97 { PCI_DEVICE(PCI_VENDOR_ID_RDC, PCI_DEVICE_ID_RDC_R6030) },
98 {}
99};
100
101static struct pci_driver rdc321x_sb_driver = {
102 .name = "RDC321x Southbridge",
103 .id_table = rdc321x_sb_table,
104 .probe = rdc321x_sb_probe,
105 .remove = __devexit_p(rdc321x_sb_remove),
106};
107
108static int __init rdc321x_sb_init(void)
109{
110 return pci_register_driver(&rdc321x_sb_driver);
111}
112
113static void __exit rdc321x_sb_exit(void)
114{
115 pci_unregister_driver(&rdc321x_sb_driver);
116}
117
118module_init(rdc321x_sb_init);
119module_exit(rdc321x_sb_exit);
120
121MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
122MODULE_LICENSE("GPL");
123MODULE_DESCRIPTION("RDC R-321x MFD southbridge driver");
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index da6383a934ac..5041d33adf0b 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -318,6 +318,9 @@ static int t7l66xb_probe(struct platform_device *dev)
318 struct resource *iomem, *rscr; 318 struct resource *iomem, *rscr;
319 int ret; 319 int ret;
320 320
321 if (pdata == NULL)
322 return -EINVAL;
323
321 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); 324 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
322 if (!iomem) 325 if (!iomem)
323 return -EINVAL; 326 return -EINVAL;
diff --git a/drivers/mfd/tc35892.c b/drivers/mfd/tc35892.c
new file mode 100644
index 000000000000..715f095dd7a6
--- /dev/null
+++ b/drivers/mfd/tc35892.c
@@ -0,0 +1,347 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
7 */
8
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/mfd/core.h>
15#include <linux/mfd/tc35892.h>
16
17/**
18 * tc35892_reg_read() - read a single TC35892 register
19 * @tc35892: Device to read from
20 * @reg: Register to read
21 */
22int tc35892_reg_read(struct tc35892 *tc35892, u8 reg)
23{
24 int ret;
25
26 ret = i2c_smbus_read_byte_data(tc35892->i2c, reg);
27 if (ret < 0)
28 dev_err(tc35892->dev, "failed to read reg %#x: %d\n",
29 reg, ret);
30
31 return ret;
32}
33EXPORT_SYMBOL_GPL(tc35892_reg_read);
34
35/**
36 * tc35892_reg_read() - write a single TC35892 register
37 * @tc35892: Device to write to
38 * @reg: Register to read
39 * @data: Value to write
40 */
41int tc35892_reg_write(struct tc35892 *tc35892, u8 reg, u8 data)
42{
43 int ret;
44
45 ret = i2c_smbus_write_byte_data(tc35892->i2c, reg, data);
46 if (ret < 0)
47 dev_err(tc35892->dev, "failed to write reg %#x: %d\n",
48 reg, ret);
49
50 return ret;
51}
52EXPORT_SYMBOL_GPL(tc35892_reg_write);
53
54/**
55 * tc35892_block_read() - read multiple TC35892 registers
56 * @tc35892: Device to read from
57 * @reg: First register
58 * @length: Number of registers
59 * @values: Buffer to write to
60 */
61int tc35892_block_read(struct tc35892 *tc35892, u8 reg, u8 length, u8 *values)
62{
63 int ret;
64
65 ret = i2c_smbus_read_i2c_block_data(tc35892->i2c, reg, length, values);
66 if (ret < 0)
67 dev_err(tc35892->dev, "failed to read regs %#x: %d\n",
68 reg, ret);
69
70 return ret;
71}
72EXPORT_SYMBOL_GPL(tc35892_block_read);
73
74/**
75 * tc35892_block_write() - write multiple TC35892 registers
76 * @tc35892: Device to write to
77 * @reg: First register
78 * @length: Number of registers
79 * @values: Values to write
80 */
81int tc35892_block_write(struct tc35892 *tc35892, u8 reg, u8 length,
82 const u8 *values)
83{
84 int ret;
85
86 ret = i2c_smbus_write_i2c_block_data(tc35892->i2c, reg, length,
87 values);
88 if (ret < 0)
89 dev_err(tc35892->dev, "failed to write regs %#x: %d\n",
90 reg, ret);
91
92 return ret;
93}
94EXPORT_SYMBOL_GPL(tc35892_block_write);
95
96/**
97 * tc35892_set_bits() - set the value of a bitfield in a TC35892 register
98 * @tc35892: Device to write to
99 * @reg: Register to write
100 * @mask: Mask of bits to set
101 * @values: Value to set
102 */
103int tc35892_set_bits(struct tc35892 *tc35892, u8 reg, u8 mask, u8 val)
104{
105 int ret;
106
107 mutex_lock(&tc35892->lock);
108
109 ret = tc35892_reg_read(tc35892, reg);
110 if (ret < 0)
111 goto out;
112
113 ret &= ~mask;
114 ret |= val;
115
116 ret = tc35892_reg_write(tc35892, reg, ret);
117
118out:
119 mutex_unlock(&tc35892->lock);
120 return ret;
121}
122EXPORT_SYMBOL_GPL(tc35892_set_bits);
123
124static struct resource gpio_resources[] = {
125 {
126 .start = TC35892_INT_GPIIRQ,
127 .end = TC35892_INT_GPIIRQ,
128 .flags = IORESOURCE_IRQ,
129 },
130};
131
132static struct mfd_cell tc35892_devs[] = {
133 {
134 .name = "tc35892-gpio",
135 .num_resources = ARRAY_SIZE(gpio_resources),
136 .resources = &gpio_resources[0],
137 },
138};
139
140static irqreturn_t tc35892_irq(int irq, void *data)
141{
142 struct tc35892 *tc35892 = data;
143 int status;
144
145 status = tc35892_reg_read(tc35892, TC35892_IRQST);
146 if (status < 0)
147 return IRQ_NONE;
148
149 while (status) {
150 int bit = __ffs(status);
151
152 handle_nested_irq(tc35892->irq_base + bit);
153 status &= ~(1 << bit);
154 }
155
156 /*
157 * A dummy read or write (to any register) appears to be necessary to
158 * have the last interrupt clear (for example, GPIO IC write) take
159 * effect.
160 */
161 tc35892_reg_read(tc35892, TC35892_IRQST);
162
163 return IRQ_HANDLED;
164}
165
166static void tc35892_irq_dummy(unsigned int irq)
167{
168 /* No mask/unmask at this level */
169}
170
171static struct irq_chip tc35892_irq_chip = {
172 .name = "tc35892",
173 .mask = tc35892_irq_dummy,
174 .unmask = tc35892_irq_dummy,
175};
176
177static int tc35892_irq_init(struct tc35892 *tc35892)
178{
179 int base = tc35892->irq_base;
180 int irq;
181
182 for (irq = base; irq < base + TC35892_NR_INTERNAL_IRQS; irq++) {
183 set_irq_chip_data(irq, tc35892);
184 set_irq_chip_and_handler(irq, &tc35892_irq_chip,
185 handle_edge_irq);
186 set_irq_nested_thread(irq, 1);
187#ifdef CONFIG_ARM
188 set_irq_flags(irq, IRQF_VALID);
189#else
190 set_irq_noprobe(irq);
191#endif
192 }
193
194 return 0;
195}
196
197static void tc35892_irq_remove(struct tc35892 *tc35892)
198{
199 int base = tc35892->irq_base;
200 int irq;
201
202 for (irq = base; irq < base + TC35892_NR_INTERNAL_IRQS; irq++) {
203#ifdef CONFIG_ARM
204 set_irq_flags(irq, 0);
205#endif
206 set_irq_chip_and_handler(irq, NULL, NULL);
207 set_irq_chip_data(irq, NULL);
208 }
209}
210
211static int tc35892_chip_init(struct tc35892 *tc35892)
212{
213 int manf, ver, ret;
214
215 manf = tc35892_reg_read(tc35892, TC35892_MANFCODE);
216 if (manf < 0)
217 return manf;
218
219 ver = tc35892_reg_read(tc35892, TC35892_VERSION);
220 if (ver < 0)
221 return ver;
222
223 if (manf != TC35892_MANFCODE_MAGIC) {
224 dev_err(tc35892->dev, "unknown manufacturer: %#x\n", manf);
225 return -EINVAL;
226 }
227
228 dev_info(tc35892->dev, "manufacturer: %#x, version: %#x\n", manf, ver);
229
230 /* Put everything except the IRQ module into reset */
231 ret = tc35892_reg_write(tc35892, TC35892_RSTCTRL,
232 TC35892_RSTCTRL_TIMRST
233 | TC35892_RSTCTRL_ROTRST
234 | TC35892_RSTCTRL_KBDRST
235 | TC35892_RSTCTRL_GPIRST);
236 if (ret < 0)
237 return ret;
238
239 /* Clear the reset interrupt. */
240 return tc35892_reg_write(tc35892, TC35892_RSTINTCLR, 0x1);
241}
242
243static int __devinit tc35892_probe(struct i2c_client *i2c,
244 const struct i2c_device_id *id)
245{
246 struct tc35892_platform_data *pdata = i2c->dev.platform_data;
247 struct tc35892 *tc35892;
248 int ret;
249
250 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA
251 | I2C_FUNC_SMBUS_I2C_BLOCK))
252 return -EIO;
253
254 tc35892 = kzalloc(sizeof(struct tc35892), GFP_KERNEL);
255 if (!tc35892)
256 return -ENOMEM;
257
258 mutex_init(&tc35892->lock);
259
260 tc35892->dev = &i2c->dev;
261 tc35892->i2c = i2c;
262 tc35892->pdata = pdata;
263 tc35892->irq_base = pdata->irq_base;
264 tc35892->num_gpio = id->driver_data;
265
266 i2c_set_clientdata(i2c, tc35892);
267
268 ret = tc35892_chip_init(tc35892);
269 if (ret)
270 goto out_free;
271
272 ret = tc35892_irq_init(tc35892);
273 if (ret)
274 goto out_free;
275
276 ret = request_threaded_irq(tc35892->i2c->irq, NULL, tc35892_irq,
277 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
278 "tc35892", tc35892);
279 if (ret) {
280 dev_err(tc35892->dev, "failed to request IRQ: %d\n", ret);
281 goto out_removeirq;
282 }
283
284 ret = mfd_add_devices(tc35892->dev, -1, tc35892_devs,
285 ARRAY_SIZE(tc35892_devs), NULL,
286 tc35892->irq_base);
287 if (ret) {
288 dev_err(tc35892->dev, "failed to add children\n");
289 goto out_freeirq;
290 }
291
292 return 0;
293
294out_freeirq:
295 free_irq(tc35892->i2c->irq, tc35892);
296out_removeirq:
297 tc35892_irq_remove(tc35892);
298out_free:
299 i2c_set_clientdata(i2c, NULL);
300 kfree(tc35892);
301 return ret;
302}
303
304static int __devexit tc35892_remove(struct i2c_client *client)
305{
306 struct tc35892 *tc35892 = i2c_get_clientdata(client);
307
308 mfd_remove_devices(tc35892->dev);
309
310 free_irq(tc35892->i2c->irq, tc35892);
311 tc35892_irq_remove(tc35892);
312
313 i2c_set_clientdata(client, NULL);
314 kfree(tc35892);
315
316 return 0;
317}
318
319static const struct i2c_device_id tc35892_id[] = {
320 { "tc35892", 24 },
321 { }
322};
323MODULE_DEVICE_TABLE(i2c, tc35892_id);
324
325static struct i2c_driver tc35892_driver = {
326 .driver.name = "tc35892",
327 .driver.owner = THIS_MODULE,
328 .probe = tc35892_probe,
329 .remove = __devexit_p(tc35892_remove),
330 .id_table = tc35892_id,
331};
332
333static int __init tc35892_init(void)
334{
335 return i2c_add_driver(&tc35892_driver);
336}
337subsys_initcall(tc35892_init);
338
339static void __exit tc35892_exit(void)
340{
341 i2c_del_driver(&tc35892_driver);
342}
343module_exit(tc35892_exit);
344
345MODULE_LICENSE("GPL v2");
346MODULE_DESCRIPTION("TC35892 MFD core driver");
347MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent");
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index 7f478ec4184b..ac5995026c88 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/i2c-ocores.h> 33#include <linux/i2c-ocores.h>
34#include <linux/i2c-xiic.h>
34#include <linux/i2c/tsc2007.h> 35#include <linux/i2c/tsc2007.h>
35 36
36#include <linux/spi/spi.h> 37#include <linux/spi/spi.h>
@@ -40,6 +41,8 @@
40 41
41#include <media/timb_radio.h> 42#include <media/timb_radio.h>
42 43
44#include <linux/timb_dma.h>
45
43#include "timberdale.h" 46#include "timberdale.h"
44 47
45#define DRIVER_NAME "timberdale" 48#define DRIVER_NAME "timberdale"
@@ -69,6 +72,12 @@ static struct i2c_board_info timberdale_i2c_board_info[] = {
69 }, 72 },
70}; 73};
71 74
75static __devinitdata struct xiic_i2c_platform_data
76timberdale_xiic_platform_data = {
77 .devices = timberdale_i2c_board_info,
78 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
79};
80
72static __devinitdata struct ocores_i2c_platform_data 81static __devinitdata struct ocores_i2c_platform_data
73timberdale_ocores_platform_data = { 82timberdale_ocores_platform_data = {
74 .regstep = 4, 83 .regstep = 4,
@@ -77,7 +86,20 @@ timberdale_ocores_platform_data = {
77 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info) 86 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
78}; 87};
79 88
80const static __devinitconst struct resource timberdale_ocores_resources[] = { 89static const __devinitconst struct resource timberdale_xiic_resources[] = {
90 {
91 .start = XIICOFFSET,
92 .end = XIICEND,
93 .flags = IORESOURCE_MEM,
94 },
95 {
96 .start = IRQ_TIMBERDALE_I2C,
97 .end = IRQ_TIMBERDALE_I2C,
98 .flags = IORESOURCE_IRQ,
99 },
100};
101
102static const __devinitconst struct resource timberdale_ocores_resources[] = {
81 { 103 {
82 .start = OCORESOFFSET, 104 .start = OCORESOFFSET,
83 .end = OCORESEND, 105 .end = OCORESEND,
@@ -126,7 +148,7 @@ static __devinitdata struct xspi_platform_data timberdale_xspi_platform_data = {
126 */ 148 */
127}; 149};
128 150
129const static __devinitconst struct resource timberdale_spi_resources[] = { 151static const __devinitconst struct resource timberdale_spi_resources[] = {
130 { 152 {
131 .start = SPIOFFSET, 153 .start = SPIOFFSET,
132 .end = SPIEND, 154 .end = SPIEND,
@@ -139,7 +161,7 @@ const static __devinitconst struct resource timberdale_spi_resources[] = {
139 }, 161 },
140}; 162};
141 163
142const static __devinitconst struct resource timberdale_eth_resources[] = { 164static const __devinitconst struct resource timberdale_eth_resources[] = {
143 { 165 {
144 .start = ETHOFFSET, 166 .start = ETHOFFSET,
145 .end = ETHEND, 167 .end = ETHEND,
@@ -159,7 +181,7 @@ static __devinitdata struct timbgpio_platform_data
159 .irq_base = 200, 181 .irq_base = 200,
160}; 182};
161 183
162const static __devinitconst struct resource timberdale_gpio_resources[] = { 184static const __devinitconst struct resource timberdale_gpio_resources[] = {
163 { 185 {
164 .start = GPIOOFFSET, 186 .start = GPIOOFFSET,
165 .end = GPIOEND, 187 .end = GPIOEND,
@@ -172,7 +194,7 @@ const static __devinitconst struct resource timberdale_gpio_resources[] = {
172 }, 194 },
173}; 195};
174 196
175const static __devinitconst struct resource timberdale_mlogicore_resources[] = { 197static const __devinitconst struct resource timberdale_mlogicore_resources[] = {
176 { 198 {
177 .start = MLCOREOFFSET, 199 .start = MLCOREOFFSET,
178 .end = MLCOREEND, 200 .end = MLCOREEND,
@@ -190,7 +212,7 @@ const static __devinitconst struct resource timberdale_mlogicore_resources[] = {
190 }, 212 },
191}; 213};
192 214
193const static __devinitconst struct resource timberdale_uart_resources[] = { 215static const __devinitconst struct resource timberdale_uart_resources[] = {
194 { 216 {
195 .start = UARTOFFSET, 217 .start = UARTOFFSET,
196 .end = UARTEND, 218 .end = UARTEND,
@@ -203,7 +225,7 @@ const static __devinitconst struct resource timberdale_uart_resources[] = {
203 }, 225 },
204}; 226};
205 227
206const static __devinitconst struct resource timberdale_uartlite_resources[] = { 228static const __devinitconst struct resource timberdale_uartlite_resources[] = {
207 { 229 {
208 .start = UARTLITEOFFSET, 230 .start = UARTLITEOFFSET,
209 .end = UARTLITEEND, 231 .end = UARTLITEEND,
@@ -216,7 +238,7 @@ const static __devinitconst struct resource timberdale_uartlite_resources[] = {
216 }, 238 },
217}; 239};
218 240
219const static __devinitconst struct resource timberdale_radio_resources[] = { 241static const __devinitconst struct resource timberdale_radio_resources[] = {
220 { 242 {
221 .start = RDSOFFSET, 243 .start = RDSOFFSET,
222 .end = RDSEND, 244 .end = RDSEND,
@@ -250,7 +272,66 @@ static __devinitdata struct timb_radio_platform_data
250 } 272 }
251}; 273};
252 274
253const static __devinitconst struct resource timberdale_dma_resources[] = { 275static __devinitdata struct timb_dma_platform_data timb_dma_platform_data = {
276 .nr_channels = 10,
277 .channels = {
278 {
279 /* UART RX */
280 .rx = true,
281 .descriptors = 2,
282 .descriptor_elements = 1
283 },
284 {
285 /* UART TX */
286 .rx = false,
287 .descriptors = 2,
288 .descriptor_elements = 1
289 },
290 {
291 /* MLB RX */
292 .rx = true,
293 .descriptors = 2,
294 .descriptor_elements = 1
295 },
296 {
297 /* MLB TX */
298 .rx = false,
299 .descriptors = 2,
300 .descriptor_elements = 1
301 },
302 {
303 /* Video RX */
304 .rx = true,
305 .bytes_per_line = 1440,
306 .descriptors = 2,
307 .descriptor_elements = 16
308 },
309 {
310 /* Video framedrop */
311 },
312 {
313 /* SDHCI RX */
314 .rx = true,
315 },
316 {
317 /* SDHCI TX */
318 },
319 {
320 /* ETH RX */
321 .rx = true,
322 .descriptors = 2,
323 .descriptor_elements = 1
324 },
325 {
326 /* ETH TX */
327 .rx = false,
328 .descriptors = 2,
329 .descriptor_elements = 1
330 },
331 }
332};
333
334static const __devinitconst struct resource timberdale_dma_resources[] = {
254 { 335 {
255 .start = DMAOFFSET, 336 .start = DMAOFFSET,
256 .end = DMAEND, 337 .end = DMAEND,
@@ -265,11 +346,25 @@ const static __devinitconst struct resource timberdale_dma_resources[] = {
265 346
266static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = { 347static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = {
267 { 348 {
349 .name = "timb-dma",
350 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
351 .resources = timberdale_dma_resources,
352 .platform_data = &timb_dma_platform_data,
353 .data_size = sizeof(timb_dma_platform_data),
354 },
355 {
268 .name = "timb-uart", 356 .name = "timb-uart",
269 .num_resources = ARRAY_SIZE(timberdale_uart_resources), 357 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
270 .resources = timberdale_uart_resources, 358 .resources = timberdale_uart_resources,
271 }, 359 },
272 { 360 {
361 .name = "xiic-i2c",
362 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
363 .resources = timberdale_xiic_resources,
364 .platform_data = &timberdale_xiic_platform_data,
365 .data_size = sizeof(timberdale_xiic_platform_data),
366 },
367 {
273 .name = "timb-gpio", 368 .name = "timb-gpio",
274 .num_resources = ARRAY_SIZE(timberdale_gpio_resources), 369 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
275 .resources = timberdale_gpio_resources, 370 .resources = timberdale_gpio_resources,
@@ -295,14 +390,16 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = {
295 .num_resources = ARRAY_SIZE(timberdale_eth_resources), 390 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
296 .resources = timberdale_eth_resources, 391 .resources = timberdale_eth_resources,
297 }, 392 },
393};
394
395static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
298 { 396 {
299 .name = "timb-dma", 397 .name = "timb-dma",
300 .num_resources = ARRAY_SIZE(timberdale_dma_resources), 398 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
301 .resources = timberdale_dma_resources, 399 .resources = timberdale_dma_resources,
400 .platform_data = &timb_dma_platform_data,
401 .data_size = sizeof(timb_dma_platform_data),
302 }, 402 },
303};
304
305static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
306 { 403 {
307 .name = "timb-uart", 404 .name = "timb-uart",
308 .num_resources = ARRAY_SIZE(timberdale_uart_resources), 405 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
@@ -314,6 +411,13 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
314 .resources = timberdale_uartlite_resources, 411 .resources = timberdale_uartlite_resources,
315 }, 412 },
316 { 413 {
414 .name = "xiic-i2c",
415 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
416 .resources = timberdale_xiic_resources,
417 .platform_data = &timberdale_xiic_platform_data,
418 .data_size = sizeof(timberdale_xiic_platform_data),
419 },
420 {
317 .name = "timb-gpio", 421 .name = "timb-gpio",
318 .num_resources = ARRAY_SIZE(timberdale_gpio_resources), 422 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
319 .resources = timberdale_gpio_resources, 423 .resources = timberdale_gpio_resources,
@@ -344,20 +448,29 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
344 .num_resources = ARRAY_SIZE(timberdale_eth_resources), 448 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
345 .resources = timberdale_eth_resources, 449 .resources = timberdale_eth_resources,
346 }, 450 },
451};
452
453static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
347 { 454 {
348 .name = "timb-dma", 455 .name = "timb-dma",
349 .num_resources = ARRAY_SIZE(timberdale_dma_resources), 456 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
350 .resources = timberdale_dma_resources, 457 .resources = timberdale_dma_resources,
458 .platform_data = &timb_dma_platform_data,
459 .data_size = sizeof(timb_dma_platform_data),
351 }, 460 },
352};
353
354static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
355 { 461 {
356 .name = "timb-uart", 462 .name = "timb-uart",
357 .num_resources = ARRAY_SIZE(timberdale_uart_resources), 463 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
358 .resources = timberdale_uart_resources, 464 .resources = timberdale_uart_resources,
359 }, 465 },
360 { 466 {
467 .name = "xiic-i2c",
468 .num_resources = ARRAY_SIZE(timberdale_xiic_resources),
469 .resources = timberdale_xiic_resources,
470 .platform_data = &timberdale_xiic_platform_data,
471 .data_size = sizeof(timberdale_xiic_platform_data),
472 },
473 {
361 .name = "timb-gpio", 474 .name = "timb-gpio",
362 .num_resources = ARRAY_SIZE(timberdale_gpio_resources), 475 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
363 .resources = timberdale_gpio_resources, 476 .resources = timberdale_gpio_resources,
@@ -378,14 +491,16 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
378 .platform_data = &timberdale_xspi_platform_data, 491 .platform_data = &timberdale_xspi_platform_data,
379 .data_size = sizeof(timberdale_xspi_platform_data), 492 .data_size = sizeof(timberdale_xspi_platform_data),
380 }, 493 },
494};
495
496static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
381 { 497 {
382 .name = "timb-dma", 498 .name = "timb-dma",
383 .num_resources = ARRAY_SIZE(timberdale_dma_resources), 499 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
384 .resources = timberdale_dma_resources, 500 .resources = timberdale_dma_resources,
501 .platform_data = &timb_dma_platform_data,
502 .data_size = sizeof(timb_dma_platform_data),
385 }, 503 },
386};
387
388static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
389 { 504 {
390 .name = "timb-uart", 505 .name = "timb-uart",
391 .num_resources = ARRAY_SIZE(timberdale_uart_resources), 506 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
@@ -424,11 +539,6 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
424 .num_resources = ARRAY_SIZE(timberdale_eth_resources), 539 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
425 .resources = timberdale_eth_resources, 540 .resources = timberdale_eth_resources,
426 }, 541 },
427 {
428 .name = "timb-dma",
429 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
430 .resources = timberdale_dma_resources,
431 },
432}; 542};
433 543
434static const __devinitconst struct resource timberdale_sdhc_resources[] = { 544static const __devinitconst struct resource timberdale_sdhc_resources[] = {
diff --git a/drivers/mfd/timberdale.h b/drivers/mfd/timberdale.h
index 8d27ffabc25d..c11bf6ebfe00 100644
--- a/drivers/mfd/timberdale.h
+++ b/drivers/mfd/timberdale.h
@@ -23,7 +23,7 @@
23#ifndef MFD_TIMBERDALE_H 23#ifndef MFD_TIMBERDALE_H
24#define MFD_TIMBERDALE_H 24#define MFD_TIMBERDALE_H
25 25
26#define DRV_VERSION "0.1" 26#define DRV_VERSION "0.2"
27 27
28/* This driver only support versions >= 3.8 and < 4.0 */ 28/* This driver only support versions >= 3.8 and < 4.0 */
29#define TIMB_SUPPORTED_MAJOR 3 29#define TIMB_SUPPORTED_MAJOR 3
@@ -66,7 +66,7 @@
66 66
67#define CHIPCTLOFFSET 0x800 67#define CHIPCTLOFFSET 0x800
68#define CHIPCTLEND 0x8ff 68#define CHIPCTLEND 0x8ff
69#define CHIPCTLSIZE (CHIPCTLEND - CHIPCTLOFFSET) 69#define CHIPCTLSIZE (CHIPCTLEND - CHIPCTLOFFSET + 1)
70 70
71#define INTCOFFSET 0xc00 71#define INTCOFFSET 0xc00
72#define INTCEND 0xfff 72#define INTCEND 0xfff
@@ -127,4 +127,16 @@
127#define GPIO_PIN_BT_RST 15 127#define GPIO_PIN_BT_RST 15
128#define GPIO_NR_PINS 16 128#define GPIO_NR_PINS 16
129 129
130/* DMA Channels */
131#define DMA_UART_RX 0
132#define DMA_UART_TX 1
133#define DMA_MLB_RX 2
134#define DMA_MLB_TX 3
135#define DMA_VIDEO_RX 4
136#define DMA_VIDEO_DROP 5
137#define DMA_SDHCI_RX 6
138#define DMA_SDHCI_TX 7
139#define DMA_ETH_RX 8
140#define DMA_ETH_TX 9
141
130#endif 142#endif
diff --git a/drivers/mfd/tps65010.c b/drivers/mfd/tps65010.c
index e5955306c2fa..9b22a77f70f5 100644
--- a/drivers/mfd/tps65010.c
+++ b/drivers/mfd/tps65010.c
@@ -530,8 +530,8 @@ static int __exit tps65010_remove(struct i2c_client *client)
530 cancel_delayed_work(&tps->work); 530 cancel_delayed_work(&tps->work);
531 flush_scheduled_work(); 531 flush_scheduled_work();
532 debugfs_remove(tps->file); 532 debugfs_remove(tps->file);
533 kfree(tps);
534 i2c_set_clientdata(client, NULL); 533 i2c_set_clientdata(client, NULL);
534 kfree(tps);
535 the_tps = NULL; 535 the_tps = NULL;
536 return 0; 536 return 0;
537} 537}
diff --git a/drivers/mfd/tps6507x.c b/drivers/mfd/tps6507x.c
new file mode 100644
index 000000000000..d859dffed39f
--- /dev/null
+++ b/drivers/mfd/tps6507x.c
@@ -0,0 +1,159 @@
1/*
2 * tps6507x.c -- TPS6507x chip family multi-function driver
3 *
4 * Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com)
5 *
6 * Author: Todd Fischer
7 * todd.fischer@ridgerun.com
8 *
9 * Credits:
10 *
11 * Using code from wm831x-*.c, wm8400-core, Wolfson Microelectronics PLC.
12 *
13 * For licencing details see kernel-base/COPYING
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/i2c.h>
22#include <linux/mfd/core.h>
23#include <linux/mfd/tps6507x.h>
24
25static struct mfd_cell tps6507x_devs[] = {
26 {
27 .name = "tps6507x-pmic",
28 },
29 {
30 .name = "tps6507x-ts",
31 },
32};
33
34
35static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
36 int bytes, void *dest)
37{
38 struct i2c_client *i2c = tps6507x->i2c_client;
39 struct i2c_msg xfer[2];
40 int ret;
41
42 /* Write register */
43 xfer[0].addr = i2c->addr;
44 xfer[0].flags = 0;
45 xfer[0].len = 1;
46 xfer[0].buf = &reg;
47
48 /* Read data */
49 xfer[1].addr = i2c->addr;
50 xfer[1].flags = I2C_M_RD;
51 xfer[1].len = bytes;
52 xfer[1].buf = dest;
53
54 ret = i2c_transfer(i2c->adapter, xfer, 2);
55 if (ret == 2)
56 ret = 0;
57 else if (ret >= 0)
58 ret = -EIO;
59
60 return ret;
61}
62
63static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
64 int bytes, void *src)
65{
66 struct i2c_client *i2c = tps6507x->i2c_client;
67 /* we add 1 byte for device register */
68 u8 msg[TPS6507X_MAX_REGISTER + 1];
69 int ret;
70
71 if (bytes > (TPS6507X_MAX_REGISTER + 1))
72 return -EINVAL;
73
74 msg[0] = reg;
75 memcpy(&msg[1], src, bytes);
76
77 ret = i2c_master_send(i2c, msg, bytes + 1);
78 if (ret < 0)
79 return ret;
80 if (ret != bytes + 1)
81 return -EIO;
82 return 0;
83}
84
85static int tps6507x_i2c_probe(struct i2c_client *i2c,
86 const struct i2c_device_id *id)
87{
88 struct tps6507x_dev *tps6507x;
89 int ret = 0;
90
91 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
92 if (tps6507x == NULL) {
93 kfree(i2c);
94 return -ENOMEM;
95 }
96
97 i2c_set_clientdata(i2c, tps6507x);
98 tps6507x->dev = &i2c->dev;
99 tps6507x->i2c_client = i2c;
100 tps6507x->read_dev = tps6507x_i2c_read_device;
101 tps6507x->write_dev = tps6507x_i2c_write_device;
102
103 ret = mfd_add_devices(tps6507x->dev, -1,
104 tps6507x_devs, ARRAY_SIZE(tps6507x_devs),
105 NULL, 0);
106
107 if (ret < 0)
108 goto err;
109
110 return ret;
111
112err:
113 mfd_remove_devices(tps6507x->dev);
114 kfree(tps6507x);
115 return ret;
116}
117
118static int tps6507x_i2c_remove(struct i2c_client *i2c)
119{
120 struct tps6507x_dev *tps6507x = i2c_get_clientdata(i2c);
121
122 mfd_remove_devices(tps6507x->dev);
123 kfree(tps6507x);
124
125 return 0;
126}
127
128static const struct i2c_device_id tps6507x_i2c_id[] = {
129 { "tps6507x", 0 },
130 { }
131};
132MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
133
134
135static struct i2c_driver tps6507x_i2c_driver = {
136 .driver = {
137 .name = "tps6507x",
138 .owner = THIS_MODULE,
139 },
140 .probe = tps6507x_i2c_probe,
141 .remove = tps6507x_i2c_remove,
142 .id_table = tps6507x_i2c_id,
143};
144
145static int __init tps6507x_i2c_init(void)
146{
147 return i2c_add_driver(&tps6507x_i2c_driver);
148}
149/* init early so consumer devices can complete system boot */
150subsys_initcall(tps6507x_i2c_init);
151
152static void __exit tps6507x_i2c_exit(void)
153{
154 i2c_del_driver(&tps6507x_i2c_driver);
155}
156module_exit(tps6507x_i2c_exit);
157
158MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
159MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
index 202bdd59632d..097f24d8bceb 100644
--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -232,10 +232,11 @@ static const struct sih sih_modules_twl5031[8] = {
232 }, 232 },
233 [6] = { 233 [6] = {
234 /* 234 /*
235 * ACI doesn't use the same SIH organization. 235 * ECI/DBI doesn't use the same SIH organization.
236 * For example, it supports only one interrupt line 236 * For example, it supports only one interrupt output line.
237 * That is, the interrupts are seen on both INT1 and INT2 lines.
237 */ 238 */
238 .name = "aci", 239 .name = "eci_dbi",
239 .module = TWL5031_MODULE_ACCESSORY, 240 .module = TWL5031_MODULE_ACCESSORY,
240 .bits = 9, 241 .bits = 9,
241 .bytes_ixr = 2, 242 .bytes_ixr = 2,
@@ -247,8 +248,8 @@ static const struct sih sih_modules_twl5031[8] = {
247 248
248 }, 249 },
249 [7] = { 250 [7] = {
250 /* Accessory */ 251 /* Audio accessory */
251 .name = "acc", 252 .name = "audio",
252 .module = TWL5031_MODULE_ACCESSORY, 253 .module = TWL5031_MODULE_ACCESSORY,
253 .control_offset = TWL5031_ACCSIHCTRL, 254 .control_offset = TWL5031_ACCSIHCTRL,
254 .bits = 2, 255 .bits = 2,
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index f2ab025ad97a..1a968f34d679 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -322,7 +322,11 @@ EXPORT_SYMBOL_GPL(wm831x_set_bits);
322 */ 322 */
323int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) 323int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
324{ 324{
325 int ret, src; 325 int ret, src, irq_masked, timeout;
326
327 /* Are we using the interrupt? */
328 irq_masked = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_1_MASK);
329 irq_masked &= WM831X_AUXADC_DATA_EINT;
326 330
327 mutex_lock(&wm831x->auxadc_lock); 331 mutex_lock(&wm831x->auxadc_lock);
328 332
@@ -342,6 +346,9 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
342 goto out; 346 goto out;
343 } 347 }
344 348
349 /* Clear any notification from a very late arriving interrupt */
350 try_wait_for_completion(&wm831x->auxadc_done);
351
345 ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, 352 ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
346 WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA); 353 WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA);
347 if (ret < 0) { 354 if (ret < 0) {
@@ -349,22 +356,46 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
349 goto disable; 356 goto disable;
350 } 357 }
351 358
352 /* If an interrupt arrived late clean up after it */ 359 if (irq_masked) {
353 try_wait_for_completion(&wm831x->auxadc_done); 360 /* If we're not using interrupts then poll the
354 361 * interrupt status register */
355 /* Ignore the result to allow us to soldier on without IRQ hookup */ 362 timeout = 5;
356 wait_for_completion_timeout(&wm831x->auxadc_done, msecs_to_jiffies(5)); 363 while (timeout) {
357 364 msleep(1);
358 ret = wm831x_reg_read(wm831x, WM831X_AUXADC_CONTROL); 365
359 if (ret < 0) { 366 ret = wm831x_reg_read(wm831x,
360 dev_err(wm831x->dev, "AUXADC status read failed: %d\n", ret); 367 WM831X_INTERRUPT_STATUS_1);
361 goto disable; 368 if (ret < 0) {
362 } 369 dev_err(wm831x->dev,
363 370 "ISR 1 read failed: %d\n", ret);
364 if (ret & WM831X_AUX_CVT_ENA) { 371 goto disable;
365 dev_err(wm831x->dev, "Timed out reading AUXADC\n"); 372 }
366 ret = -EBUSY; 373
367 goto disable; 374 /* Did it complete? */
375 if (ret & WM831X_AUXADC_DATA_EINT) {
376 wm831x_reg_write(wm831x,
377 WM831X_INTERRUPT_STATUS_1,
378 WM831X_AUXADC_DATA_EINT);
379 break;
380 } else {
381 dev_err(wm831x->dev,
382 "AUXADC conversion timeout\n");
383 ret = -EBUSY;
384 goto disable;
385 }
386 }
387 } else {
388 /* If we are using interrupts then wait for the
389 * interrupt to complete. Use an extremely long
390 * timeout to handle situations with heavy load where
391 * the notification of the interrupt may be delayed by
392 * threaded IRQ handling. */
393 if (!wait_for_completion_timeout(&wm831x->auxadc_done,
394 msecs_to_jiffies(500))) {
395 dev_err(wm831x->dev, "Timed out waiting for AUXADC\n");
396 ret = -EBUSY;
397 goto disable;
398 }
368 } 399 }
369 400
370 ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA); 401 ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
@@ -1463,6 +1494,7 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1463 case WM8310: 1494 case WM8310:
1464 parent = WM8310; 1495 parent = WM8310;
1465 wm831x->num_gpio = 16; 1496 wm831x->num_gpio = 16;
1497 wm831x->charger_irq_wake = 1;
1466 if (rev > 0) { 1498 if (rev > 0) {
1467 wm831x->has_gpio_ena = 1; 1499 wm831x->has_gpio_ena = 1;
1468 wm831x->has_cs_sts = 1; 1500 wm831x->has_cs_sts = 1;
@@ -1474,6 +1506,7 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1474 case WM8311: 1506 case WM8311:
1475 parent = WM8311; 1507 parent = WM8311;
1476 wm831x->num_gpio = 16; 1508 wm831x->num_gpio = 16;
1509 wm831x->charger_irq_wake = 1;
1477 if (rev > 0) { 1510 if (rev > 0) {
1478 wm831x->has_gpio_ena = 1; 1511 wm831x->has_gpio_ena = 1;
1479 wm831x->has_cs_sts = 1; 1512 wm831x->has_cs_sts = 1;
@@ -1485,6 +1518,7 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1485 case WM8312: 1518 case WM8312:
1486 parent = WM8312; 1519 parent = WM8312;
1487 wm831x->num_gpio = 16; 1520 wm831x->num_gpio = 16;
1521 wm831x->charger_irq_wake = 1;
1488 if (rev > 0) { 1522 if (rev > 0) {
1489 wm831x->has_gpio_ena = 1; 1523 wm831x->has_gpio_ena = 1;
1490 wm831x->has_cs_sts = 1; 1524 wm831x->has_cs_sts = 1;
@@ -1623,6 +1657,42 @@ static void wm831x_device_exit(struct wm831x *wm831x)
1623 kfree(wm831x); 1657 kfree(wm831x);
1624} 1658}
1625 1659
1660static int wm831x_device_suspend(struct wm831x *wm831x)
1661{
1662 int reg, mask;
1663
1664 /* If the charger IRQs are a wake source then make sure we ack
1665 * them even if they're not actively being used (eg, no power
1666 * driver or no IRQ line wired up) then acknowledge the
1667 * interrupts otherwise suspend won't last very long.
1668 */
1669 if (wm831x->charger_irq_wake) {
1670 reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
1671
1672 mask = WM831X_CHG_BATT_HOT_EINT |
1673 WM831X_CHG_BATT_COLD_EINT |
1674 WM831X_CHG_BATT_FAIL_EINT |
1675 WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
1676 WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
1677 WM831X_CHG_START_EINT;
1678
1679 /* If any of the interrupts are masked read the statuses */
1680 if (reg & mask)
1681 reg = wm831x_reg_read(wm831x,
1682 WM831X_INTERRUPT_STATUS_2);
1683
1684 if (reg & mask) {
1685 dev_info(wm831x->dev,
1686 "Acknowledging masked charger IRQs: %x\n",
1687 reg & mask);
1688 wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
1689 reg & mask);
1690 }
1691 }
1692
1693 return 0;
1694}
1695
1626static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg, 1696static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg,
1627 int bytes, void *dest) 1697 int bytes, void *dest)
1628{ 1698{
@@ -1697,6 +1767,13 @@ static int wm831x_i2c_remove(struct i2c_client *i2c)
1697 return 0; 1767 return 0;
1698} 1768}
1699 1769
1770static int wm831x_i2c_suspend(struct i2c_client *i2c, pm_message_t mesg)
1771{
1772 struct wm831x *wm831x = i2c_get_clientdata(i2c);
1773
1774 return wm831x_device_suspend(wm831x);
1775}
1776
1700static const struct i2c_device_id wm831x_i2c_id[] = { 1777static const struct i2c_device_id wm831x_i2c_id[] = {
1701 { "wm8310", WM8310 }, 1778 { "wm8310", WM8310 },
1702 { "wm8311", WM8311 }, 1779 { "wm8311", WM8311 },
@@ -1714,6 +1791,7 @@ static struct i2c_driver wm831x_i2c_driver = {
1714 }, 1791 },
1715 .probe = wm831x_i2c_probe, 1792 .probe = wm831x_i2c_probe,
1716 .remove = wm831x_i2c_remove, 1793 .remove = wm831x_i2c_remove,
1794 .suspend = wm831x_i2c_suspend,
1717 .id_table = wm831x_i2c_id, 1795 .id_table = wm831x_i2c_id,
1718}; 1796};
1719 1797
diff --git a/drivers/mfd/wm831x-irq.c b/drivers/mfd/wm831x-irq.c
index 4c1122ceb443..7dabe4dbd373 100644
--- a/drivers/mfd/wm831x-irq.c
+++ b/drivers/mfd/wm831x-irq.c
@@ -39,8 +39,6 @@ struct wm831x_irq_data {
39 int primary; 39 int primary;
40 int reg; 40 int reg;
41 int mask; 41 int mask;
42 irq_handler_t handler;
43 void *handler_data;
44}; 42};
45 43
46static struct wm831x_irq_data wm831x_irqs[] = { 44static struct wm831x_irq_data wm831x_irqs[] = {
@@ -492,6 +490,14 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq)
492 490
493 mutex_init(&wm831x->irq_lock); 491 mutex_init(&wm831x->irq_lock);
494 492
493 /* Mask the individual interrupt sources */
494 for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) {
495 wm831x->irq_masks_cur[i] = 0xffff;
496 wm831x->irq_masks_cache[i] = 0xffff;
497 wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_1_MASK + i,
498 0xffff);
499 }
500
495 if (!irq) { 501 if (!irq) {
496 dev_warn(wm831x->dev, 502 dev_warn(wm831x->dev,
497 "No interrupt specified - functionality limited\n"); 503 "No interrupt specified - functionality limited\n");
@@ -507,14 +513,6 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq)
507 wm831x->irq = irq; 513 wm831x->irq = irq;
508 wm831x->irq_base = pdata->irq_base; 514 wm831x->irq_base = pdata->irq_base;
509 515
510 /* Mask the individual interrupt sources */
511 for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) {
512 wm831x->irq_masks_cur[i] = 0xffff;
513 wm831x->irq_masks_cache[i] = 0xffff;
514 wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_1_MASK + i,
515 0xffff);
516 }
517
518 /* Register them with genirq */ 516 /* Register them with genirq */
519 for (cur_irq = wm831x->irq_base; 517 for (cur_irq = wm831x->irq_base;
520 cur_irq < ARRAY_SIZE(wm831x_irqs) + wm831x->irq_base; 518 cur_irq < ARRAY_SIZE(wm831x_irqs) + wm831x->irq_base;
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
index 65830f57c093..7795af4b1fe1 100644
--- a/drivers/mfd/wm8350-i2c.c
+++ b/drivers/mfd/wm8350-i2c.c
@@ -64,10 +64,8 @@ static int wm8350_i2c_probe(struct i2c_client *i2c,
64 int ret = 0; 64 int ret = 0;
65 65
66 wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL); 66 wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL);
67 if (wm8350 == NULL) { 67 if (wm8350 == NULL)
68 kfree(i2c);
69 return -ENOMEM; 68 return -ENOMEM;
70 }
71 69
72 i2c_set_clientdata(i2c, wm8350); 70 i2c_set_clientdata(i2c, wm8350);
73 wm8350->dev = &i2c->dev; 71 wm8350->dev = &i2c->dev;
@@ -82,6 +80,7 @@ static int wm8350_i2c_probe(struct i2c_client *i2c,
82 return ret; 80 return ret;
83 81
84err: 82err:
83 i2c_set_clientdata(i2c, NULL);
85 kfree(wm8350); 84 kfree(wm8350);
86 return ret; 85 return ret;
87} 86}
@@ -91,6 +90,7 @@ static int wm8350_i2c_remove(struct i2c_client *i2c)
91 struct wm8350 *wm8350 = i2c_get_clientdata(i2c); 90 struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
92 91
93 wm8350_device_exit(wm8350); 92 wm8350_device_exit(wm8350);
93 i2c_set_clientdata(i2c, NULL);
94 kfree(wm8350); 94 kfree(wm8350);
95 95
96 return 0; 96 return 0;
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
index 865ce013a821..e08aafa663dc 100644
--- a/drivers/mfd/wm8400-core.c
+++ b/drivers/mfd/wm8400-core.c
@@ -118,7 +118,7 @@ static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest)
118{ 118{
119 int i, ret = 0; 119 int i, ret = 0;
120 120
121 BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache)); 121 BUG_ON(reg + num_regs > ARRAY_SIZE(wm8400->reg_cache));
122 122
123 /* If there are any volatile reads then read back the entire block */ 123 /* If there are any volatile reads then read back the entire block */
124 for (i = reg; i < reg + num_regs; i++) 124 for (i = reg; i < reg + num_regs; i++)
@@ -144,7 +144,7 @@ static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs,
144{ 144{
145 int ret, i; 145 int ret, i;
146 146
147 BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache)); 147 BUG_ON(reg + num_regs > ARRAY_SIZE(wm8400->reg_cache));
148 148
149 for (i = 0; i < num_regs; i++) { 149 for (i = 0; i < num_regs; i++) {
150 BUG_ON(!reg_data[reg + i].writable); 150 BUG_ON(!reg_data[reg + i].writable);