stmpe.c (73de16db43f8dcb833ab032ed274b60b23676680) stmpe.c (1a6e4b7415339e3b11a87cff0d701b8a2e55f062)
1/*
1/*
2 * ST Microelectronics MFD: stmpe's driver
3 *
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/gpio.h>
9#include <linux/kernel.h>
4 * Copyright (C) ST-Ericsson SA 2010
5 *
6 * License Terms: GNU General Public License, version 2
7 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
8 */
9
10#include <linux/gpio.h>
11#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/interrupt.h>
12#include <linux/irq.h>
12#include <linux/interrupt.h>
13#include <linux/irq.h>
14#include <linux/pm.h>
13#include <linux/slab.h>
15#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/mfd/core.h>
16#include <linux/mfd/core.h>
16#include <linux/mfd/stmpe.h>
17#include "stmpe.h"
18
19static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
20{
21 return stmpe->variant->enable(stmpe, blocks, true);
22}
23
24static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
25{
26 return stmpe->variant->enable(stmpe, blocks, false);
27}
28
29static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
30{
31 int ret;
32
17#include "stmpe.h"
18
19static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
20{
21 return stmpe->variant->enable(stmpe, blocks, true);
22}
23
24static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
25{
26 return stmpe->variant->enable(stmpe, blocks, false);
27}
28
29static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
30{
31 int ret;
32
33 ret = i2c_smbus_read_byte_data(stmpe->i2c, reg);
33 ret = stmpe->ci->read_byte(stmpe, reg);
34 if (ret < 0)
34 if (ret < 0)
35 dev_err(stmpe->dev, "failed to read reg %#x: %d\n",
36 reg, ret);
35 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret);
37
38 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
39
40 return ret;
41}
42
43static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
44{
45 int ret;
46
47 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
48
36
37 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
38
39 return ret;
40}
41
42static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
43{
44 int ret;
45
46 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
47
49 ret = i2c_smbus_write_byte_data(stmpe->i2c, reg, val);
48 ret = stmpe->ci->write_byte(stmpe, reg, val);
50 if (ret < 0)
49 if (ret < 0)
51 dev_err(stmpe->dev, "failed to write reg %#x: %d\n",
52 reg, ret);
50 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret);
53
54 return ret;
55}
56
57static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
58{
59 int ret;
60

--- 7 unchanged lines hidden (view full) ---

68 return __stmpe_reg_write(stmpe, reg, ret);
69}
70
71static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
72 u8 *values)
73{
74 int ret;
75
51
52 return ret;
53}
54
55static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
56{
57 int ret;
58

--- 7 unchanged lines hidden (view full) ---

66 return __stmpe_reg_write(stmpe, reg, ret);
67}
68
69static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
70 u8 *values)
71{
72 int ret;
73
76 ret = i2c_smbus_read_i2c_block_data(stmpe->i2c, reg, length, values);
74 ret = stmpe->ci->read_block(stmpe, reg, length, values);
77 if (ret < 0)
75 if (ret < 0)
78 dev_err(stmpe->dev, "failed to read regs %#x: %d\n",
79 reg, ret);
76 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret);
80
81 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
82 stmpe_dump_bytes("stmpe rd: ", values, length);
83
84 return ret;
85}
86
87static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
88 const u8 *values)
89{
90 int ret;
91
92 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
93 stmpe_dump_bytes("stmpe wr: ", values, length);
94
77
78 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
79 stmpe_dump_bytes("stmpe rd: ", values, length);
80
81 return ret;
82}
83
84static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
85 const u8 *values)
86{
87 int ret;
88
89 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
90 stmpe_dump_bytes("stmpe wr: ", values, length);
91
95 ret = i2c_smbus_write_i2c_block_data(stmpe->i2c, reg, length,
96 values);
92 ret = stmpe->ci->write_block(stmpe, reg, length, values);
97 if (ret < 0)
93 if (ret < 0)
98 dev_err(stmpe->dev, "failed to write regs %#x: %d\n",
99 reg, ret);
94 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret);
100
101 return ret;
102}
103
104/**
105 * stmpe_enable - enable blocks on an STMPE device
106 * @stmpe: Device to work on
107 * @blocks: Mask of blocks (enum stmpe_block values) to enable

--- 761 unchanged lines hidden (view full) ---

869 if (platform_blocks)
870 dev_warn(stmpe->dev,
871 "platform wants blocks (%#x) not present on variant",
872 platform_blocks);
873
874 return ret;
875}
876
95
96 return ret;
97}
98
99/**
100 * stmpe_enable - enable blocks on an STMPE device
101 * @stmpe: Device to work on
102 * @blocks: Mask of blocks (enum stmpe_block values) to enable

--- 761 unchanged lines hidden (view full) ---

864 if (platform_blocks)
865 dev_warn(stmpe->dev,
866 "platform wants blocks (%#x) not present on variant",
867 platform_blocks);
868
869 return ret;
870}
871
877#ifdef CONFIG_PM
878static int stmpe_suspend(struct device *dev)
872/* Called from client specific probe routines */
873int stmpe_probe(struct stmpe_client_info *ci, int partnum)
879{
874{
880 struct i2c_client *i2c = to_i2c_client(dev);
881 struct stmpe *stmpe = i2c_get_clientdata(i2c);
882
883 if (device_may_wakeup(&i2c->dev))
884 enable_irq_wake(stmpe->irq);
885
886 return 0;
887}
888
889static int stmpe_resume(struct device *dev)
890{
891 struct i2c_client *i2c = to_i2c_client(dev);
892 struct stmpe *stmpe = i2c_get_clientdata(i2c);
893
894 if (device_may_wakeup(&i2c->dev))
895 disable_irq_wake(stmpe->irq);
896
897 return 0;
898}
899#endif
900
901static int __devinit stmpe_probe(struct i2c_client *i2c,
902 const struct i2c_device_id *id)
903{
904 struct stmpe_platform_data *pdata = i2c->dev.platform_data;
875 struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev);
905 struct stmpe *stmpe;
906 int ret;
907
908 if (!pdata)
909 return -EINVAL;
910
911 stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
912 if (!stmpe)
913 return -ENOMEM;
914
915 mutex_init(&stmpe->irq_lock);
916 mutex_init(&stmpe->lock);
917
876 struct stmpe *stmpe;
877 int ret;
878
879 if (!pdata)
880 return -EINVAL;
881
882 stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
883 if (!stmpe)
884 return -ENOMEM;
885
886 mutex_init(&stmpe->irq_lock);
887 mutex_init(&stmpe->lock);
888
918 stmpe->dev = &i2c->dev;
919 stmpe->i2c = i2c;
920
889 stmpe->dev = ci->dev;
890 stmpe->client = ci->client;
921 stmpe->pdata = pdata;
922 stmpe->irq_base = pdata->irq_base;
891 stmpe->pdata = pdata;
892 stmpe->irq_base = pdata->irq_base;
923
924 stmpe->partnum = id->driver_data;
925 stmpe->variant = stmpe_variant_info[stmpe->partnum];
893 stmpe->ci = ci;
894 stmpe->partnum = partnum;
895 stmpe->variant = stmpe_variant_info[partnum];
926 stmpe->regs = stmpe->variant->regs;
927 stmpe->num_gpios = stmpe->variant->num_gpios;
896 stmpe->regs = stmpe->variant->regs;
897 stmpe->num_gpios = stmpe->variant->num_gpios;
898 dev_set_drvdata(stmpe->dev, stmpe);
928
899
929 i2c_set_clientdata(i2c, stmpe);
900 if (ci->init)
901 ci->init(stmpe);
930
931 if (pdata->irq_over_gpio) {
932 ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
933 if (ret) {
934 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
935 ret);
936 goto out_free;
937 }
938
939 stmpe->irq = gpio_to_irq(pdata->irq_gpio);
940 } else {
902
903 if (pdata->irq_over_gpio) {
904 ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
905 if (ret) {
906 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
907 ret);
908 goto out_free;
909 }
910
911 stmpe->irq = gpio_to_irq(pdata->irq_gpio);
912 } else {
941 stmpe->irq = i2c->irq;
913 stmpe->irq = ci->irq;
942 }
943
944 ret = stmpe_chip_init(stmpe);
945 if (ret)
946 goto free_gpio;
947
948 ret = stmpe_irq_init(stmpe);
949 if (ret)
950 goto free_gpio;
951
952 ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
914 }
915
916 ret = stmpe_chip_init(stmpe);
917 if (ret)
918 goto free_gpio;
919
920 ret = stmpe_irq_init(stmpe);
921 if (ret)
922 goto free_gpio;
923
924 ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
953 pdata->irq_trigger | IRQF_ONESHOT,
954 "stmpe", stmpe);
925 pdata->irq_trigger | IRQF_ONESHOT, "stmpe", stmpe);
955 if (ret) {
956 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
957 goto out_removeirq;
958 }
959
960 ret = stmpe_devices_init(stmpe);
961 if (ret) {
962 dev_err(stmpe->dev, "failed to add children\n");

--- 10 unchanged lines hidden (view full) ---

973free_gpio:
974 if (pdata->irq_over_gpio)
975 gpio_free(pdata->irq_gpio);
976out_free:
977 kfree(stmpe);
978 return ret;
979}
980
926 if (ret) {
927 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
928 goto out_removeirq;
929 }
930
931 ret = stmpe_devices_init(stmpe);
932 if (ret) {
933 dev_err(stmpe->dev, "failed to add children\n");

--- 10 unchanged lines hidden (view full) ---

944free_gpio:
945 if (pdata->irq_over_gpio)
946 gpio_free(pdata->irq_gpio);
947out_free:
948 kfree(stmpe);
949 return ret;
950}
951
981static int __devexit stmpe_remove(struct i2c_client *client)
952int stmpe_remove(struct stmpe *stmpe)
982{
953{
983 struct stmpe *stmpe = i2c_get_clientdata(client);
984
985 mfd_remove_devices(stmpe->dev);
986
987 free_irq(stmpe->irq, stmpe);
988 stmpe_irq_remove(stmpe);
989
990 if (stmpe->pdata->irq_over_gpio)
991 gpio_free(stmpe->pdata->irq_gpio);
992
993 kfree(stmpe);
994
995 return 0;
996}
997
954 mfd_remove_devices(stmpe->dev);
955
956 free_irq(stmpe->irq, stmpe);
957 stmpe_irq_remove(stmpe);
958
959 if (stmpe->pdata->irq_over_gpio)
960 gpio_free(stmpe->pdata->irq_gpio);
961
962 kfree(stmpe);
963
964 return 0;
965}
966
998static const struct i2c_device_id stmpe_id[] = {
999 { "stmpe811", STMPE811 },
1000 { "stmpe1601", STMPE1601 },
1001 { "stmpe2401", STMPE2401 },
1002 { "stmpe2403", STMPE2403 },
1003 { }
1004};
1005MODULE_DEVICE_TABLE(i2c, stmpe_id);
1006
1007#ifdef CONFIG_PM
967#ifdef CONFIG_PM
1008static const struct dev_pm_ops stmpe_dev_pm_ops = {
1009 .suspend = stmpe_suspend,
1010 .resume = stmpe_resume,
1011};
1012#endif
968static int stmpe_suspend(struct device *dev)
969{
970 struct stmpe *stmpe = dev_get_drvdata(dev);
1013
971
1014static struct i2c_driver stmpe_driver = {
1015 .driver.name = "stmpe",
1016 .driver.owner = THIS_MODULE,
1017#ifdef CONFIG_PM
1018 .driver.pm = &stmpe_dev_pm_ops,
1019#endif
1020 .probe = stmpe_probe,
1021 .remove = __devexit_p(stmpe_remove),
1022 .id_table = stmpe_id,
1023};
972 if (device_may_wakeup(dev))
973 enable_irq_wake(stmpe->irq);
1024
974
1025static int __init stmpe_init(void)
1026{
1027 return i2c_add_driver(&stmpe_driver);
975 return 0;
1028}
976}
1029subsys_initcall(stmpe_init);
1030
977
1031static void __exit stmpe_exit(void)
978static int stmpe_resume(struct device *dev)
1032{
979{
1033 i2c_del_driver(&stmpe_driver);
980 struct stmpe *stmpe = dev_get_drvdata(dev);
981
982 if (device_may_wakeup(dev))
983 disable_irq_wake(stmpe->irq);
984
985 return 0;
1034}
986}
1035module_exit(stmpe_exit);
1036
987
1037MODULE_LICENSE("GPL v2");
1038MODULE_DESCRIPTION("STMPE MFD core driver");
1039MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
988const struct dev_pm_ops stmpe_dev_pm_ops = {
989 .suspend = stmpe_suspend,
990 .resume = stmpe_resume,
991};
992#endif