diff options
author | Haojian Zhuang <haojian.zhuang@gmail.com> | 2012-09-21 06:06:53 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-10-02 05:43:16 -0400 |
commit | fe1d38e80d1497a2b64685dd2e7a6018dc79b408 (patch) | |
tree | 19205799f6b7da7ffc7731e403c6730409dce34c /drivers/input | |
parent | 2e57d56747e601b3e0ff6697e524025d0504d161 (diff) |
mfd: 88pm860x: Move gpadc init into touch
The initilization of GPADC is moved from core driver to touch driver
with DT support.
Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/touchscreen/88pm860x-ts.c | 91 |
1 files changed, 85 insertions, 6 deletions
diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c index 4f81e6eb74b6..326218dbd6e6 100644 --- a/drivers/input/touchscreen/88pm860x-ts.c +++ b/drivers/input/touchscreen/88pm860x-ts.c | |||
@@ -116,9 +116,13 @@ static void pm860x_touch_close(struct input_dev *dev) | |||
116 | 116 | ||
117 | #ifdef CONFIG_OF | 117 | #ifdef CONFIG_OF |
118 | static int __devinit pm860x_touch_dt_init(struct platform_device *pdev, | 118 | static int __devinit pm860x_touch_dt_init(struct platform_device *pdev, |
119 | struct pm860x_chip *chip, | ||
119 | int *res_x) | 120 | int *res_x) |
120 | { | 121 | { |
121 | struct device_node *np = pdev->dev.parent->of_node; | 122 | struct device_node *np = pdev->dev.parent->of_node; |
123 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ | ||
124 | : chip->companion; | ||
125 | int data, n, ret; | ||
122 | if (!np) | 126 | if (!np) |
123 | return -ENODEV; | 127 | return -ENODEV; |
124 | np = of_find_node_by_name(np, "touch"); | 128 | np = of_find_node_by_name(np, "touch"); |
@@ -126,11 +130,43 @@ static int __devinit pm860x_touch_dt_init(struct platform_device *pdev, | |||
126 | dev_err(&pdev->dev, "Can't find touch node\n"); | 130 | dev_err(&pdev->dev, "Can't find touch node\n"); |
127 | return -EINVAL; | 131 | return -EINVAL; |
128 | } | 132 | } |
133 | /* set GPADC MISC1 register */ | ||
134 | data = 0; | ||
135 | if (!of_property_read_u32(np, "marvell,88pm860x-gpadc-prebias", &n)) | ||
136 | data |= (n << 1) & PM8607_GPADC_PREBIAS_MASK; | ||
137 | if (!of_property_read_u32(np, "marvell,88pm860x-gpadc-slot-cycle", &n)) | ||
138 | data |= (n << 3) & PM8607_GPADC_SLOT_CYCLE_MASK; | ||
139 | if (!of_property_read_u32(np, "marvell,88pm860x-gpadc-off-scale", &n)) | ||
140 | data |= (n << 5) & PM8607_GPADC_OFF_SCALE_MASK; | ||
141 | if (!of_property_read_u32(np, "marvell,88pm860x-gpadc-sw-cal", &n)) | ||
142 | data |= (n << 7) & PM8607_GPADC_SW_CAL_MASK; | ||
143 | if (data) { | ||
144 | ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); | ||
145 | if (ret < 0) | ||
146 | return -EINVAL; | ||
147 | } | ||
148 | /* set tsi prebias time */ | ||
149 | if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) { | ||
150 | ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); | ||
151 | if (ret < 0) | ||
152 | return -EINVAL; | ||
153 | } | ||
154 | /* set prebias & prechg time of pen detect */ | ||
155 | data = 0; | ||
156 | if (!of_property_read_u32(np, "marvell,88pm860x-pen-prebias", &n)) | ||
157 | data |= n & PM8607_PD_PREBIAS_MASK; | ||
158 | if (!of_property_read_u32(np, "marvell,88pm860x-pen-prechg", &n)) | ||
159 | data |= n & PM8607_PD_PRECHG_MASK; | ||
160 | if (data) { | ||
161 | ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); | ||
162 | if (ret < 0) | ||
163 | return -EINVAL; | ||
164 | } | ||
129 | of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x); | 165 | of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x); |
130 | return 0; | 166 | return 0; |
131 | } | 167 | } |
132 | #else | 168 | #else |
133 | #define pm860x_touch_dt_init(x, y) (-1) | 169 | #define pm860x_touch_dt_init(x, y, z) (-1) |
134 | #endif | 170 | #endif |
135 | 171 | ||
136 | static int __devinit pm860x_touch_probe(struct platform_device *pdev) | 172 | static int __devinit pm860x_touch_probe(struct platform_device *pdev) |
@@ -138,7 +174,9 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev) | |||
138 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); | 174 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
139 | struct pm860x_touch_pdata *pdata = pdev->dev.platform_data; | 175 | struct pm860x_touch_pdata *pdata = pdev->dev.platform_data; |
140 | struct pm860x_touch *touch; | 176 | struct pm860x_touch *touch; |
141 | int irq, ret, res_x = 0; | 177 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ |
178 | : chip->companion; | ||
179 | int irq, ret, res_x = 0, data = 0; | ||
142 | 180 | ||
143 | irq = platform_get_irq(pdev, 0); | 181 | irq = platform_get_irq(pdev, 0); |
144 | if (irq < 0) { | 182 | if (irq < 0) { |
@@ -146,14 +184,55 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev) | |||
146 | return -EINVAL; | 184 | return -EINVAL; |
147 | } | 185 | } |
148 | 186 | ||
149 | if (pm860x_touch_dt_init(pdev, &res_x)) { | 187 | if (pm860x_touch_dt_init(pdev, chip, &res_x)) { |
150 | if (pdata) | 188 | if (pdata) { |
189 | /* set GPADC MISC1 register */ | ||
190 | data = 0; | ||
191 | data |= (pdata->gpadc_prebias << 1) | ||
192 | & PM8607_GPADC_PREBIAS_MASK; | ||
193 | data |= (pdata->slot_cycle << 3) | ||
194 | & PM8607_GPADC_SLOT_CYCLE_MASK; | ||
195 | data |= (pdata->off_scale << 5) | ||
196 | & PM8607_GPADC_OFF_SCALE_MASK; | ||
197 | data |= (pdata->sw_cal << 7) | ||
198 | & PM8607_GPADC_SW_CAL_MASK; | ||
199 | if (data) { | ||
200 | ret = pm860x_reg_write(i2c, | ||
201 | PM8607_GPADC_MISC1, data); | ||
202 | if (ret < 0) | ||
203 | return -EINVAL; | ||
204 | } | ||
205 | /* set tsi prebias time */ | ||
206 | if (pdata->tsi_prebias) { | ||
207 | data = pdata->tsi_prebias; | ||
208 | ret = pm860x_reg_write(i2c, | ||
209 | PM8607_TSI_PREBIAS, data); | ||
210 | if (ret < 0) | ||
211 | return -EINVAL; | ||
212 | } | ||
213 | /* set prebias & prechg time of pen detect */ | ||
214 | data = 0; | ||
215 | data |= pdata->pen_prebias | ||
216 | & PM8607_PD_PREBIAS_MASK; | ||
217 | data |= (pdata->pen_prechg << 5) | ||
218 | & PM8607_PD_PRECHG_MASK; | ||
219 | if (data) { | ||
220 | ret = pm860x_reg_write(i2c, | ||
221 | PM8607_PD_PREBIAS, data); | ||
222 | if (ret < 0) | ||
223 | return -EINVAL; | ||
224 | } | ||
151 | res_x = pdata->res_x; | 225 | res_x = pdata->res_x; |
152 | else { | 226 | } else { |
153 | dev_err(&pdev->dev, "failed to get platform data\n"); | 227 | dev_err(&pdev->dev, "failed to get platform data\n"); |
154 | return -EINVAL; | 228 | return -EINVAL; |
155 | } | 229 | } |
156 | } | 230 | } |
231 | /* enable GPADC */ | ||
232 | ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1, PM8607_GPADC_EN, | ||
233 | PM8607_GPADC_EN); | ||
234 | if (ret) | ||
235 | return ret; | ||
157 | 236 | ||
158 | touch = kzalloc(sizeof(struct pm860x_touch), GFP_KERNEL); | 237 | touch = kzalloc(sizeof(struct pm860x_touch), GFP_KERNEL); |
159 | if (touch == NULL) | 238 | if (touch == NULL) |
@@ -174,7 +253,7 @@ static int __devinit pm860x_touch_probe(struct platform_device *pdev) | |||
174 | touch->idev->open = pm860x_touch_open; | 253 | touch->idev->open = pm860x_touch_open; |
175 | touch->idev->close = pm860x_touch_close; | 254 | touch->idev->close = pm860x_touch_close; |
176 | touch->chip = chip; | 255 | touch->chip = chip; |
177 | touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; | 256 | touch->i2c = i2c; |
178 | touch->irq = irq; | 257 | touch->irq = irq; |
179 | touch->res_x = res_x; | 258 | touch->res_x = res_x; |
180 | input_set_drvdata(touch->idev, touch); | 259 | input_set_drvdata(touch->idev, touch); |