diff options
Diffstat (limited to 'drivers/mfd/max8998.c')
-rw-r--r-- | drivers/mfd/max8998.c | 90 |
1 files changed, 69 insertions, 21 deletions
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c index 73e6f5c4efc9..bb9977bebe78 100644 --- a/drivers/mfd/max8998.c +++ b/drivers/mfd/max8998.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * max8698.c - mfd core driver for the Maxim 8998 | 2 | * max8998.c - mfd core driver for the Maxim 8998 |
3 | * | 3 | * |
4 | * Copyright (C) 2009-2010 Samsung Electronics | 4 | * Copyright (C) 2009-2010 Samsung Electronics |
5 | * Kyungmin Park <kyungmin.park@samsung.com> | 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
@@ -30,19 +30,23 @@ | |||
30 | #include <linux/mfd/max8998.h> | 30 | #include <linux/mfd/max8998.h> |
31 | #include <linux/mfd/max8998-private.h> | 31 | #include <linux/mfd/max8998-private.h> |
32 | 32 | ||
33 | #define RTC_I2C_ADDR (0x0c >> 1) | ||
34 | |||
33 | static struct mfd_cell max8998_devs[] = { | 35 | static struct mfd_cell max8998_devs[] = { |
34 | { | 36 | { |
35 | .name = "max8998-pmic", | 37 | .name = "max8998-pmic", |
36 | } | 38 | }, { |
39 | .name = "max8998-rtc", | ||
40 | }, | ||
37 | }; | 41 | }; |
38 | 42 | ||
39 | static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest) | 43 | int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) |
40 | { | 44 | { |
41 | struct i2c_client *client = max8998->i2c_client; | 45 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
42 | int ret; | 46 | int ret; |
43 | 47 | ||
44 | mutex_lock(&max8998->iolock); | 48 | mutex_lock(&max8998->iolock); |
45 | ret = i2c_smbus_read_byte_data(client, reg); | 49 | ret = i2c_smbus_read_byte_data(i2c, reg); |
46 | mutex_unlock(&max8998->iolock); | 50 | mutex_unlock(&max8998->iolock); |
47 | if (ret < 0) | 51 | if (ret < 0) |
48 | return ret; | 52 | return ret; |
@@ -51,40 +55,71 @@ static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest | |||
51 | *dest = ret; | 55 | *dest = ret; |
52 | return 0; | 56 | return 0; |
53 | } | 57 | } |
58 | EXPORT_SYMBOL(max8998_read_reg); | ||
54 | 59 | ||
55 | static int max8998_i2c_device_write(struct max8998_dev *max8998, u8 reg, u8 value) | 60 | int max8998_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf) |
56 | { | 61 | { |
57 | struct i2c_client *client = max8998->i2c_client; | 62 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
63 | int ret; | ||
64 | |||
65 | mutex_lock(&max8998->iolock); | ||
66 | ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf); | ||
67 | mutex_unlock(&max8998->iolock); | ||
68 | if (ret < 0) | ||
69 | return ret; | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | EXPORT_SYMBOL(max8998_bulk_read); | ||
74 | |||
75 | int max8998_write_reg(struct i2c_client *i2c, u8 reg, u8 value) | ||
76 | { | ||
77 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); | ||
58 | int ret; | 78 | int ret; |
59 | 79 | ||
60 | mutex_lock(&max8998->iolock); | 80 | mutex_lock(&max8998->iolock); |
61 | ret = i2c_smbus_write_byte_data(client, reg, value); | 81 | ret = i2c_smbus_write_byte_data(i2c, reg, value); |
62 | mutex_unlock(&max8998->iolock); | 82 | mutex_unlock(&max8998->iolock); |
63 | return ret; | 83 | return ret; |
64 | } | 84 | } |
85 | EXPORT_SYMBOL(max8998_write_reg); | ||
65 | 86 | ||
66 | static int max8998_i2c_device_update(struct max8998_dev *max8998, u8 reg, | 87 | int max8998_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf) |
67 | u8 val, u8 mask) | ||
68 | { | 88 | { |
69 | struct i2c_client *client = max8998->i2c_client; | 89 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
90 | int ret; | ||
91 | |||
92 | mutex_lock(&max8998->iolock); | ||
93 | ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf); | ||
94 | mutex_unlock(&max8998->iolock); | ||
95 | if (ret < 0) | ||
96 | return ret; | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | EXPORT_SYMBOL(max8998_bulk_write); | ||
101 | |||
102 | int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) | ||
103 | { | ||
104 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); | ||
70 | int ret; | 105 | int ret; |
71 | 106 | ||
72 | mutex_lock(&max8998->iolock); | 107 | mutex_lock(&max8998->iolock); |
73 | ret = i2c_smbus_read_byte_data(client, reg); | 108 | ret = i2c_smbus_read_byte_data(i2c, reg); |
74 | if (ret >= 0) { | 109 | if (ret >= 0) { |
75 | u8 old_val = ret & 0xff; | 110 | u8 old_val = ret & 0xff; |
76 | u8 new_val = (val & mask) | (old_val & (~mask)); | 111 | u8 new_val = (val & mask) | (old_val & (~mask)); |
77 | ret = i2c_smbus_write_byte_data(client, reg, new_val); | 112 | ret = i2c_smbus_write_byte_data(i2c, reg, new_val); |
78 | if (ret >= 0) | ||
79 | ret = 0; | ||
80 | } | 113 | } |
81 | mutex_unlock(&max8998->iolock); | 114 | mutex_unlock(&max8998->iolock); |
82 | return ret; | 115 | return ret; |
83 | } | 116 | } |
117 | EXPORT_SYMBOL(max8998_update_reg); | ||
84 | 118 | ||
85 | static int max8998_i2c_probe(struct i2c_client *i2c, | 119 | static int max8998_i2c_probe(struct i2c_client *i2c, |
86 | const struct i2c_device_id *id) | 120 | const struct i2c_device_id *id) |
87 | { | 121 | { |
122 | struct max8998_platform_data *pdata = i2c->dev.platform_data; | ||
88 | struct max8998_dev *max8998; | 123 | struct max8998_dev *max8998; |
89 | int ret = 0; | 124 | int ret = 0; |
90 | 125 | ||
@@ -94,12 +129,20 @@ static int max8998_i2c_probe(struct i2c_client *i2c, | |||
94 | 129 | ||
95 | i2c_set_clientdata(i2c, max8998); | 130 | i2c_set_clientdata(i2c, max8998); |
96 | max8998->dev = &i2c->dev; | 131 | max8998->dev = &i2c->dev; |
97 | max8998->i2c_client = i2c; | 132 | max8998->i2c = i2c; |
98 | max8998->dev_read = max8998_i2c_device_read; | 133 | max8998->irq = i2c->irq; |
99 | max8998->dev_write = max8998_i2c_device_write; | 134 | max8998->type = id->driver_data; |
100 | max8998->dev_update = max8998_i2c_device_update; | 135 | if (pdata) { |
136 | max8998->ono = pdata->ono; | ||
137 | max8998->irq_base = pdata->irq_base; | ||
138 | } | ||
101 | mutex_init(&max8998->iolock); | 139 | mutex_init(&max8998->iolock); |
102 | 140 | ||
141 | max8998->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); | ||
142 | i2c_set_clientdata(max8998->rtc, max8998); | ||
143 | |||
144 | max8998_irq_init(max8998); | ||
145 | |||
103 | ret = mfd_add_devices(max8998->dev, -1, | 146 | ret = mfd_add_devices(max8998->dev, -1, |
104 | max8998_devs, ARRAY_SIZE(max8998_devs), | 147 | max8998_devs, ARRAY_SIZE(max8998_devs), |
105 | NULL, 0); | 148 | NULL, 0); |
@@ -110,6 +153,8 @@ static int max8998_i2c_probe(struct i2c_client *i2c, | |||
110 | 153 | ||
111 | err: | 154 | err: |
112 | mfd_remove_devices(max8998->dev); | 155 | mfd_remove_devices(max8998->dev); |
156 | max8998_irq_exit(max8998); | ||
157 | i2c_unregister_device(max8998->rtc); | ||
113 | kfree(max8998); | 158 | kfree(max8998); |
114 | return ret; | 159 | return ret; |
115 | } | 160 | } |
@@ -119,14 +164,17 @@ static int max8998_i2c_remove(struct i2c_client *i2c) | |||
119 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); | 164 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
120 | 165 | ||
121 | mfd_remove_devices(max8998->dev); | 166 | mfd_remove_devices(max8998->dev); |
167 | max8998_irq_exit(max8998); | ||
168 | i2c_unregister_device(max8998->rtc); | ||
122 | kfree(max8998); | 169 | kfree(max8998); |
123 | 170 | ||
124 | return 0; | 171 | return 0; |
125 | } | 172 | } |
126 | 173 | ||
127 | static const struct i2c_device_id max8998_i2c_id[] = { | 174 | static const struct i2c_device_id max8998_i2c_id[] = { |
128 | { "max8998", 0 }, | 175 | { "max8998", TYPE_MAX8998 }, |
129 | { } | 176 | { "lp3974", TYPE_LP3974}, |
177 | { } | ||
130 | }; | 178 | }; |
131 | MODULE_DEVICE_TABLE(i2c, max8998_i2c_id); | 179 | MODULE_DEVICE_TABLE(i2c, max8998_i2c_id); |
132 | 180 | ||