aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/stmpe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd/stmpe.c')
-rw-r--r--drivers/mfd/stmpe.c208
1 files changed, 123 insertions, 85 deletions
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index bf1ba93f43a0..5e8e6927cfcd 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -7,11 +7,15 @@
7 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson 7 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
8 */ 8 */
9 9
10#include <linux/err.h>
10#include <linux/gpio.h> 11#include <linux/gpio.h>
11#include <linux/export.h> 12#include <linux/export.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/interrupt.h> 14#include <linux/interrupt.h>
14#include <linux/irq.h> 15#include <linux/irq.h>
16#include <linux/irqdomain.h>
17#include <linux/of.h>
18#include <linux/of_gpio.h>
15#include <linux/pm.h> 19#include <linux/pm.h>
16#include <linux/slab.h> 20#include <linux/slab.h>
17#include <linux/mfd/core.h> 21#include <linux/mfd/core.h>
@@ -294,12 +298,14 @@ static struct resource stmpe_gpio_resources[] = {
294 298
295static struct mfd_cell stmpe_gpio_cell = { 299static struct mfd_cell stmpe_gpio_cell = {
296 .name = "stmpe-gpio", 300 .name = "stmpe-gpio",
301 .of_compatible = "st,stmpe-gpio",
297 .resources = stmpe_gpio_resources, 302 .resources = stmpe_gpio_resources,
298 .num_resources = ARRAY_SIZE(stmpe_gpio_resources), 303 .num_resources = ARRAY_SIZE(stmpe_gpio_resources),
299}; 304};
300 305
301static struct mfd_cell stmpe_gpio_cell_noirq = { 306static struct mfd_cell stmpe_gpio_cell_noirq = {
302 .name = "stmpe-gpio", 307 .name = "stmpe-gpio",
308 .of_compatible = "st,stmpe-gpio",
303 /* gpio cell resources consist of an irq only so no resources here */ 309 /* gpio cell resources consist of an irq only so no resources here */
304}; 310};
305 311
@@ -310,14 +316,10 @@ static struct mfd_cell stmpe_gpio_cell_noirq = {
310static struct resource stmpe_keypad_resources[] = { 316static struct resource stmpe_keypad_resources[] = {
311 { 317 {
312 .name = "KEYPAD", 318 .name = "KEYPAD",
313 .start = 0,
314 .end = 0,
315 .flags = IORESOURCE_IRQ, 319 .flags = IORESOURCE_IRQ,
316 }, 320 },
317 { 321 {
318 .name = "KEYPAD_OVER", 322 .name = "KEYPAD_OVER",
319 .start = 1,
320 .end = 1,
321 .flags = IORESOURCE_IRQ, 323 .flags = IORESOURCE_IRQ,
322 }, 324 },
323}; 325};
@@ -398,14 +400,10 @@ static struct stmpe_variant_info stmpe801_noirq = {
398static struct resource stmpe_ts_resources[] = { 400static struct resource stmpe_ts_resources[] = {
399 { 401 {
400 .name = "TOUCH_DET", 402 .name = "TOUCH_DET",
401 .start = 0,
402 .end = 0,
403 .flags = IORESOURCE_IRQ, 403 .flags = IORESOURCE_IRQ,
404 }, 404 },
405 { 405 {
406 .name = "FIFO_TH", 406 .name = "FIFO_TH",
407 .start = 1,
408 .end = 1,
409 .flags = IORESOURCE_IRQ, 407 .flags = IORESOURCE_IRQ,
410 }, 408 },
411}; 409};
@@ -528,12 +526,12 @@ static const u8 stmpe1601_regs[] = {
528static struct stmpe_variant_block stmpe1601_blocks[] = { 526static struct stmpe_variant_block stmpe1601_blocks[] = {
529 { 527 {
530 .cell = &stmpe_gpio_cell, 528 .cell = &stmpe_gpio_cell,
531 .irq = STMPE24XX_IRQ_GPIOC, 529 .irq = STMPE1601_IRQ_GPIOC,
532 .block = STMPE_BLOCK_GPIO, 530 .block = STMPE_BLOCK_GPIO,
533 }, 531 },
534 { 532 {
535 .cell = &stmpe_keypad_cell, 533 .cell = &stmpe_keypad_cell,
536 .irq = STMPE24XX_IRQ_KEYPAD, 534 .irq = STMPE1601_IRQ_KEYPAD,
537 .block = STMPE_BLOCK_KEYPAD, 535 .block = STMPE_BLOCK_KEYPAD,
538 }, 536 },
539}; 537};
@@ -767,7 +765,9 @@ static irqreturn_t stmpe_irq(int irq, void *data)
767 int i; 765 int i;
768 766
769 if (variant->id_val == STMPE801_ID) { 767 if (variant->id_val == STMPE801_ID) {
770 handle_nested_irq(stmpe->irq_base); 768 int base = irq_create_mapping(stmpe->domain, 0);
769
770 handle_nested_irq(base);
771 return IRQ_HANDLED; 771 return IRQ_HANDLED;
772 } 772 }
773 773
@@ -788,8 +788,9 @@ static irqreturn_t stmpe_irq(int irq, void *data)
788 while (status) { 788 while (status) {
789 int bit = __ffs(status); 789 int bit = __ffs(status);
790 int line = bank * 8 + bit; 790 int line = bank * 8 + bit;
791 int nestedirq = irq_create_mapping(stmpe->domain, line);
791 792
792 handle_nested_irq(stmpe->irq_base + line); 793 handle_nested_irq(nestedirq);
793 status &= ~(1 << bit); 794 status &= ~(1 << bit);
794 } 795 }
795 796
@@ -830,7 +831,7 @@ static void stmpe_irq_sync_unlock(struct irq_data *data)
830static void stmpe_irq_mask(struct irq_data *data) 831static void stmpe_irq_mask(struct irq_data *data)
831{ 832{
832 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); 833 struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
833 int offset = data->irq - stmpe->irq_base; 834 int offset = data->hwirq;
834 int regoffset = offset / 8; 835 int regoffset = offset / 8;
835 int mask = 1 << (offset % 8); 836 int mask = 1 << (offset % 8);
836 837
@@ -840,7 +841,7 @@ static void stmpe_irq_mask(struct irq_data *data)
840static void stmpe_irq_unmask(struct irq_data *data) 841static void stmpe_irq_unmask(struct irq_data *data)
841{ 842{
842 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); 843 struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
843 int offset = data->irq - stmpe->irq_base; 844 int offset = data->hwirq;
844 int regoffset = offset / 8; 845 int regoffset = offset / 8;
845 int mask = 1 << (offset % 8); 846 int mask = 1 << (offset % 8);
846 847
@@ -855,43 +856,59 @@ static struct irq_chip stmpe_irq_chip = {
855 .irq_unmask = stmpe_irq_unmask, 856 .irq_unmask = stmpe_irq_unmask,
856}; 857};
857 858
858static int __devinit stmpe_irq_init(struct stmpe *stmpe) 859static int stmpe_irq_map(struct irq_domain *d, unsigned int virq,
860 irq_hw_number_t hwirq)
859{ 861{
862 struct stmpe *stmpe = d->host_data;
860 struct irq_chip *chip = NULL; 863 struct irq_chip *chip = NULL;
861 int num_irqs = stmpe->variant->num_irqs;
862 int base = stmpe->irq_base;
863 int irq;
864 864
865 if (stmpe->variant->id_val != STMPE801_ID) 865 if (stmpe->variant->id_val != STMPE801_ID)
866 chip = &stmpe_irq_chip; 866 chip = &stmpe_irq_chip;
867 867
868 for (irq = base; irq < base + num_irqs; irq++) { 868 irq_set_chip_data(virq, stmpe);
869 irq_set_chip_data(irq, stmpe); 869 irq_set_chip_and_handler(virq, chip, handle_edge_irq);
870 irq_set_chip_and_handler(irq, chip, handle_edge_irq); 870 irq_set_nested_thread(virq, 1);
871 irq_set_nested_thread(irq, 1);
872#ifdef CONFIG_ARM 871#ifdef CONFIG_ARM
873 set_irq_flags(irq, IRQF_VALID); 872 set_irq_flags(virq, IRQF_VALID);
874#else 873#else
875 irq_set_noprobe(irq); 874 irq_set_noprobe(virq);
876#endif 875#endif
877 }
878 876
879 return 0; 877 return 0;
880} 878}
881 879
882static void stmpe_irq_remove(struct stmpe *stmpe) 880static void stmpe_irq_unmap(struct irq_domain *d, unsigned int virq)
883{ 881{
884 int num_irqs = stmpe->variant->num_irqs;
885 int base = stmpe->irq_base;
886 int irq;
887
888 for (irq = base; irq < base + num_irqs; irq++) {
889#ifdef CONFIG_ARM 882#ifdef CONFIG_ARM
890 set_irq_flags(irq, 0); 883 set_irq_flags(virq, 0);
891#endif 884#endif
892 irq_set_chip_and_handler(irq, NULL, NULL); 885 irq_set_chip_and_handler(virq, NULL, NULL);
893 irq_set_chip_data(irq, NULL); 886 irq_set_chip_data(virq, NULL);
887}
888
889static struct irq_domain_ops stmpe_irq_ops = {
890 .map = stmpe_irq_map,
891 .unmap = stmpe_irq_unmap,
892 .xlate = irq_domain_xlate_twocell,
893};
894
895static int __devinit stmpe_irq_init(struct stmpe *stmpe,
896 struct device_node *np)
897{
898 int base = 0;
899 int num_irqs = stmpe->variant->num_irqs;
900
901 if (!np)
902 base = stmpe->irq_base;
903
904 stmpe->domain = irq_domain_add_simple(np, num_irqs, base,
905 &stmpe_irq_ops, stmpe);
906 if (!stmpe->domain) {
907 dev_err(stmpe->dev, "Failed to create irqdomain\n");
908 return -ENOSYS;
894 } 909 }
910
911 return 0;
895} 912}
896 913
897static int __devinit stmpe_chip_init(struct stmpe *stmpe) 914static int __devinit stmpe_chip_init(struct stmpe *stmpe)
@@ -942,13 +959,6 @@ static int __devinit stmpe_chip_init(struct stmpe *stmpe)
942 else 959 else
943 icr |= STMPE_ICR_LSB_HIGH; 960 icr |= STMPE_ICR_LSB_HIGH;
944 } 961 }
945
946 if (stmpe->pdata->irq_invert_polarity) {
947 if (id == STMPE801_ID)
948 icr ^= STMPE801_REG_SYS_CTRL_INT_HI;
949 else
950 icr ^= STMPE_ICR_LSB_HIGH;
951 }
952 } 962 }
953 963
954 if (stmpe->pdata->autosleep) { 964 if (stmpe->pdata->autosleep) {
@@ -961,10 +971,10 @@ static int __devinit stmpe_chip_init(struct stmpe *stmpe)
961} 971}
962 972
963static int __devinit stmpe_add_device(struct stmpe *stmpe, 973static int __devinit stmpe_add_device(struct stmpe *stmpe,
964 struct mfd_cell *cell, int irq) 974 struct mfd_cell *cell)
965{ 975{
966 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, 976 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1,
967 NULL, stmpe->irq_base + irq, NULL); 977 NULL, stmpe->irq_base, stmpe->domain);
968} 978}
969 979
970static int __devinit stmpe_devices_init(struct stmpe *stmpe) 980static int __devinit stmpe_devices_init(struct stmpe *stmpe)
@@ -972,7 +982,7 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
972 struct stmpe_variant_info *variant = stmpe->variant; 982 struct stmpe_variant_info *variant = stmpe->variant;
973 unsigned int platform_blocks = stmpe->pdata->blocks; 983 unsigned int platform_blocks = stmpe->pdata->blocks;
974 int ret = -EINVAL; 984 int ret = -EINVAL;
975 int i; 985 int i, j;
976 986
977 for (i = 0; i < variant->num_blocks; i++) { 987 for (i = 0; i < variant->num_blocks; i++) {
978 struct stmpe_variant_block *block = &variant->blocks[i]; 988 struct stmpe_variant_block *block = &variant->blocks[i];
@@ -980,8 +990,17 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
980 if (!(platform_blocks & block->block)) 990 if (!(platform_blocks & block->block))
981 continue; 991 continue;
982 992
993 for (j = 0; j < block->cell->num_resources; j++) {
994 struct resource *res =
995 (struct resource *) &block->cell->resources[j];
996
997 /* Dynamically fill in a variant's IRQ. */
998 if (res->flags & IORESOURCE_IRQ)
999 res->start = res->end = block->irq + j;
1000 }
1001
983 platform_blocks &= ~block->block; 1002 platform_blocks &= ~block->block;
984 ret = stmpe_add_device(stmpe, block->cell, block->irq); 1003 ret = stmpe_add_device(stmpe, block->cell);
985 if (ret) 1004 if (ret)
986 return ret; 1005 return ret;
987 } 1006 }
@@ -994,17 +1013,56 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
994 return ret; 1013 return ret;
995} 1014}
996 1015
1016void __devinit stmpe_of_probe(struct stmpe_platform_data *pdata,
1017 struct device_node *np)
1018{
1019 struct device_node *child;
1020
1021 pdata->id = -1;
1022 pdata->irq_trigger = IRQF_TRIGGER_NONE;
1023
1024 of_property_read_u32(np, "st,autosleep-timeout",
1025 &pdata->autosleep_timeout);
1026
1027 pdata->autosleep = (pdata->autosleep_timeout) ? true : false;
1028
1029 for_each_child_of_node(np, child) {
1030 if (!strcmp(child->name, "stmpe_gpio")) {
1031 pdata->blocks |= STMPE_BLOCK_GPIO;
1032 } else if (!strcmp(child->name, "stmpe_keypad")) {
1033 pdata->blocks |= STMPE_BLOCK_KEYPAD;
1034 } else if (!strcmp(child->name, "stmpe_touchscreen")) {
1035 pdata->blocks |= STMPE_BLOCK_TOUCHSCREEN;
1036 } else if (!strcmp(child->name, "stmpe_adc")) {
1037 pdata->blocks |= STMPE_BLOCK_ADC;
1038 } else if (!strcmp(child->name, "stmpe_pwm")) {
1039 pdata->blocks |= STMPE_BLOCK_PWM;
1040 } else if (!strcmp(child->name, "stmpe_rotator")) {
1041 pdata->blocks |= STMPE_BLOCK_ROTATOR;
1042 }
1043 }
1044}
1045
997/* Called from client specific probe routines */ 1046/* Called from client specific probe routines */
998int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum) 1047int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
999{ 1048{
1000 struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev); 1049 struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev);
1050 struct device_node *np = ci->dev->of_node;
1001 struct stmpe *stmpe; 1051 struct stmpe *stmpe;
1002 int ret; 1052 int ret;
1003 1053
1004 if (!pdata) 1054 if (!pdata) {
1005 return -EINVAL; 1055 if (!np)
1056 return -EINVAL;
1057
1058 pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL);
1059 if (!pdata)
1060 return -ENOMEM;
1061
1062 stmpe_of_probe(pdata, np);
1063 }
1006 1064
1007 stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL); 1065 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL);
1008 if (!stmpe) 1066 if (!stmpe)
1009 return -ENOMEM; 1067 return -ENOMEM;
1010 1068
@@ -1026,11 +1084,12 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
1026 ci->init(stmpe); 1084 ci->init(stmpe);
1027 1085
1028 if (pdata->irq_over_gpio) { 1086 if (pdata->irq_over_gpio) {
1029 ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe"); 1087 ret = devm_gpio_request_one(ci->dev, pdata->irq_gpio,
1088 GPIOF_DIR_IN, "stmpe");
1030 if (ret) { 1089 if (ret) {
1031 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", 1090 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
1032 ret); 1091 ret);
1033 goto out_free; 1092 return ret;
1034 } 1093 }
1035 1094
1036 stmpe->irq = gpio_to_irq(pdata->irq_gpio); 1095 stmpe->irq = gpio_to_irq(pdata->irq_gpio);
@@ -1047,51 +1106,40 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
1047 dev_err(stmpe->dev, 1106 dev_err(stmpe->dev,
1048 "%s does not support no-irq mode!\n", 1107 "%s does not support no-irq mode!\n",
1049 stmpe->variant->name); 1108 stmpe->variant->name);
1050 ret = -ENODEV; 1109 return -ENODEV;
1051 goto free_gpio;
1052 } 1110 }
1053 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; 1111 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum];
1112 } else if (pdata->irq_trigger == IRQF_TRIGGER_NONE) {
1113 pdata->irq_trigger =
1114 irqd_get_trigger_type(irq_get_irq_data(stmpe->irq));
1054 } 1115 }
1055 1116
1056 ret = stmpe_chip_init(stmpe); 1117 ret = stmpe_chip_init(stmpe);
1057 if (ret) 1118 if (ret)
1058 goto free_gpio; 1119 return ret;
1059 1120
1060 if (stmpe->irq >= 0) { 1121 if (stmpe->irq >= 0) {
1061 ret = stmpe_irq_init(stmpe); 1122 ret = stmpe_irq_init(stmpe, np);
1062 if (ret) 1123 if (ret)
1063 goto free_gpio; 1124 return ret;
1064 1125
1065 ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq, 1126 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL,
1066 pdata->irq_trigger | IRQF_ONESHOT, 1127 stmpe_irq, pdata->irq_trigger | IRQF_ONESHOT,
1067 "stmpe", stmpe); 1128 "stmpe", stmpe);
1068 if (ret) { 1129 if (ret) {
1069 dev_err(stmpe->dev, "failed to request IRQ: %d\n", 1130 dev_err(stmpe->dev, "failed to request IRQ: %d\n",
1070 ret); 1131 ret);
1071 goto out_removeirq; 1132 return ret;
1072 } 1133 }
1073 } 1134 }
1074 1135
1075 ret = stmpe_devices_init(stmpe); 1136 ret = stmpe_devices_init(stmpe);
1076 if (ret) { 1137 if (!ret)
1077 dev_err(stmpe->dev, "failed to add children\n"); 1138 return 0;
1078 goto out_removedevs;
1079 }
1080
1081 return 0;
1082 1139
1083out_removedevs: 1140 dev_err(stmpe->dev, "failed to add children\n");
1084 mfd_remove_devices(stmpe->dev); 1141 mfd_remove_devices(stmpe->dev);
1085 if (stmpe->irq >= 0) 1142
1086 free_irq(stmpe->irq, stmpe);
1087out_removeirq:
1088 if (stmpe->irq >= 0)
1089 stmpe_irq_remove(stmpe);
1090free_gpio:
1091 if (pdata->irq_over_gpio)
1092 gpio_free(pdata->irq_gpio);
1093out_free:
1094 kfree(stmpe);
1095 return ret; 1143 return ret;
1096} 1144}
1097 1145
@@ -1099,16 +1147,6 @@ int stmpe_remove(struct stmpe *stmpe)
1099{ 1147{
1100 mfd_remove_devices(stmpe->dev); 1148 mfd_remove_devices(stmpe->dev);
1101 1149
1102 if (stmpe->irq >= 0) {
1103 free_irq(stmpe->irq, stmpe);
1104 stmpe_irq_remove(stmpe);
1105 }
1106
1107 if (stmpe->pdata->irq_over_gpio)
1108 gpio_free(stmpe->pdata->irq_gpio);
1109
1110 kfree(stmpe);
1111
1112 return 0; 1150 return 0;
1113} 1151}
1114 1152