aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHaojian Zhuang <haojian.zhuang@marvell.com>2009-12-15 16:04:36 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2010-03-07 16:17:04 -0500
commita16122bcacf050e7f83015183053cf799713cc37 (patch)
treeecbeff86882200fc32d787388cd7aa902bf61505 /drivers
parent5c42e8c4a9c86ea26ed4ecb732a842dea0dfb6b6 (diff)
mfd: Append subdev into 88pm860x driver
Append backlight, led & touch subdevs into 88pm860x driver. Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mfd/88pm860x-core.c217
1 files changed, 205 insertions, 12 deletions
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 9185f0d945f4..16f0dca707a7 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -17,6 +17,100 @@
17#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
18#include <linux/mfd/88pm860x.h> 18#include <linux/mfd/88pm860x.h>
19 19
20char pm860x_backlight_name[][MFD_NAME_SIZE] = {
21 "backlight-0",
22 "backlight-1",
23 "backlight-2",
24};
25EXPORT_SYMBOL(pm860x_backlight_name);
26
27char pm860x_led_name[][MFD_NAME_SIZE] = {
28 "led0-red",
29 "led0-green",
30 "led0-blue",
31 "led1-red",
32 "led1-green",
33 "led1-blue",
34};
35EXPORT_SYMBOL(pm860x_led_name);
36
37#define PM8606_BACKLIGHT_RESOURCE(_i, _x) \
38{ \
39 .name = pm860x_backlight_name[_i], \
40 .start = PM8606_##_x, \
41 .end = PM8606_##_x, \
42 .flags = IORESOURCE_IO, \
43}
44
45static struct resource backlight_resources[] = {
46 PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT1, WLED1A),
47 PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT2, WLED2A),
48 PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT3, WLED3A),
49};
50
51#define PM8606_BACKLIGHT_DEVS(_i) \
52{ \
53 .name = "88pm860x-backlight", \
54 .num_resources = 1, \
55 .resources = &backlight_resources[_i], \
56 .id = _i, \
57}
58
59static struct mfd_cell backlight_devs[] = {
60 PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT1),
61 PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT2),
62 PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT3),
63};
64
65#define PM8606_LED_RESOURCE(_i, _x) \
66{ \
67 .name = pm860x_led_name[_i], \
68 .start = PM8606_##_x, \
69 .end = PM8606_##_x, \
70 .flags = IORESOURCE_IO, \
71}
72
73static struct resource led_resources[] = {
74 PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB2B),
75 PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB2C),
76 PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB2D),
77 PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB1B),
78 PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB1C),
79 PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB1D),
80};
81
82#define PM8606_LED_DEVS(_i) \
83{ \
84 .name = "88pm860x-led", \
85 .num_resources = 1, \
86 .resources = &led_resources[_i], \
87 .id = _i, \
88}
89
90static struct mfd_cell led_devs[] = {
91 PM8606_LED_DEVS(PM8606_LED1_RED),
92 PM8606_LED_DEVS(PM8606_LED1_GREEN),
93 PM8606_LED_DEVS(PM8606_LED1_BLUE),
94 PM8606_LED_DEVS(PM8606_LED2_RED),
95 PM8606_LED_DEVS(PM8606_LED2_GREEN),
96 PM8606_LED_DEVS(PM8606_LED2_BLUE),
97};
98
99static struct resource touch_resources[] = {
100 {
101 .start = PM8607_IRQ_PEN,
102 .end = PM8607_IRQ_PEN,
103 .flags = IORESOURCE_IRQ,
104 },
105};
106
107static struct mfd_cell touch_devs[] = {
108 {
109 .name = "88pm860x-touch",
110 .num_resources = 1,
111 .resources = &touch_resources[0],
112 },
113};
20 114
21#define PM8607_REG_RESOURCE(_start, _end) \ 115#define PM8607_REG_RESOURCE(_start, _end) \
22{ \ 116{ \
@@ -25,7 +119,7 @@
25 .flags = IORESOURCE_IO, \ 119 .flags = IORESOURCE_IO, \
26} 120}
27 121
28static struct resource pm8607_regulator_resources[] = { 122static struct resource regulator_resources[] = {
29 PM8607_REG_RESOURCE(BUCK1, BUCK1), 123 PM8607_REG_RESOURCE(BUCK1, BUCK1),
30 PM8607_REG_RESOURCE(BUCK2, BUCK2), 124 PM8607_REG_RESOURCE(BUCK2, BUCK2),
31 PM8607_REG_RESOURCE(BUCK3, BUCK3), 125 PM8607_REG_RESOURCE(BUCK3, BUCK3),
@@ -47,10 +141,11 @@ static struct resource pm8607_regulator_resources[] = {
47{ \ 141{ \
48 .name = "88pm8607-" #_name, \ 142 .name = "88pm8607-" #_name, \
49 .num_resources = 1, \ 143 .num_resources = 1, \
50 .resources = &pm8607_regulator_resources[PM8607_ID_##_id], \ 144 .resources = &regulator_resources[PM8607_ID_##_id], \
145 .id = PM8607_ID_##_id, \
51} 146}
52 147
53static struct mfd_cell pm8607_devs[] = { 148static struct mfd_cell regulator_devs[] = {
54 PM8607_REG_DEVS(buck1, BUCK1), 149 PM8607_REG_DEVS(buck1, BUCK1),
55 PM8607_REG_DEVS(buck2, BUCK2), 150 PM8607_REG_DEVS(buck2, BUCK2),
56 PM8607_REG_DEVS(buck3, BUCK3), 151 PM8607_REG_DEVS(buck3, BUCK3),
@@ -192,6 +287,61 @@ int pm860x_free_irq(struct pm860x_chip *chip, int irq)
192} 287}
193EXPORT_SYMBOL(pm860x_free_irq); 288EXPORT_SYMBOL(pm860x_free_irq);
194 289
290static int __devinit device_gpadc_init(struct pm860x_chip *chip,
291 struct pm860x_platform_data *pdata)
292{
293 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
294 : chip->companion;
295 int use_gpadc = 0, data, ret;
296
297 /* initialize GPADC without activating it */
298
299 if (pdata && pdata->touch) {
300 /* set GPADC MISC1 register */
301 data = 0;
302 data |= (pdata->touch->gpadc_prebias << 1)
303 & PM8607_GPADC_PREBIAS_MASK;
304 data |= (pdata->touch->slot_cycle << 3)
305 & PM8607_GPADC_SLOT_CYCLE_MASK;
306 data |= (pdata->touch->off_scale << 5)
307 & PM8607_GPADC_OFF_SCALE_MASK;
308 data |= (pdata->touch->sw_cal << 7)
309 & PM8607_GPADC_SW_CAL_MASK;
310 if (data) {
311 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
312 if (ret < 0)
313 goto out;
314 }
315 /* set tsi prebias time */
316 if (pdata->touch->tsi_prebias) {
317 data = pdata->touch->tsi_prebias;
318 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
319 if (ret < 0)
320 goto out;
321 }
322 /* set prebias & prechg time of pen detect */
323 data = 0;
324 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
325 data |= (pdata->touch->pen_prechg << 5)
326 & PM8607_PD_PRECHG_MASK;
327 if (data) {
328 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
329 if (ret < 0)
330 goto out;
331 }
332
333 use_gpadc = 1;
334 }
335
336 /* turn on GPADC */
337 if (use_gpadc) {
338 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
339 PM8607_GPADC_EN, PM8607_GPADC_EN);
340 }
341out:
342 return ret;
343}
344
195static int __devinit device_irq_init(struct pm860x_chip *chip, 345static int __devinit device_irq_init(struct pm860x_chip *chip,
196 struct pm860x_platform_data *pdata) 346 struct pm860x_platform_data *pdata)
197{ 347{
@@ -264,14 +414,40 @@ static void __devinit device_8606_init(struct pm860x_chip *chip,
264 struct i2c_client *i2c, 414 struct i2c_client *i2c,
265 struct pm860x_platform_data *pdata) 415 struct pm860x_platform_data *pdata)
266{ 416{
417 int ret;
418
419 if (pdata && pdata->backlight) {
420 ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
421 ARRAY_SIZE(backlight_devs),
422 &backlight_resources[0], 0);
423 if (ret < 0) {
424 dev_err(chip->dev, "Failed to add backlight "
425 "subdev\n");
426 goto out_dev;
427 }
428 }
429
430 if (pdata && pdata->led) {
431 ret = mfd_add_devices(chip->dev, 0, &led_devs[0],
432 ARRAY_SIZE(led_devs),
433 &led_resources[0], 0);
434 if (ret < 0) {
435 dev_err(chip->dev, "Failed to add led "
436 "subdev\n");
437 goto out_dev;
438 }
439 }
440 return;
441out_dev:
442 mfd_remove_devices(chip->dev);
443 device_irq_exit(chip);
267} 444}
268 445
269static void __devinit device_8607_init(struct pm860x_chip *chip, 446static void __devinit device_8607_init(struct pm860x_chip *chip,
270 struct i2c_client *i2c, 447 struct i2c_client *i2c,
271 struct pm860x_platform_data *pdata) 448 struct pm860x_platform_data *pdata)
272{ 449{
273 int i, count, data; 450 int data, ret;
274 int ret;
275 451
276 ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); 452 ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
277 if (ret < 0) { 453 if (ret < 0) {
@@ -311,19 +487,36 @@ static void __devinit device_8607_init(struct pm860x_chip *chip,
311 goto out; 487 goto out;
312 } 488 }
313 489
490 ret = device_gpadc_init(chip, pdata);
491 if (ret < 0)
492 goto out;
493
314 ret = device_irq_init(chip, pdata); 494 ret = device_irq_init(chip, pdata);
315 if (ret < 0) 495 if (ret < 0)
316 goto out; 496 goto out;
317 497
318 count = ARRAY_SIZE(pm8607_devs); 498 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
319 for (i = 0; i < count; i++) { 499 ARRAY_SIZE(regulator_devs),
320 ret = mfd_add_devices(chip->dev, i, &pm8607_devs[i], 500 &regulator_resources[0], 0);
321 1, NULL, 0); 501 if (ret < 0) {
322 if (ret != 0) { 502 dev_err(chip->dev, "Failed to add regulator subdev\n");
323 dev_err(chip->dev, "Failed to add subdevs\n"); 503 goto out_dev;
324 goto out; 504 }
505
506 if (pdata && pdata->touch) {
507 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
508 ARRAY_SIZE(touch_devs),
509 &touch_resources[0], 0);
510 if (ret < 0) {
511 dev_err(chip->dev, "Failed to add touch "
512 "subdev\n");
513 goto out_dev;
325 } 514 }
326 } 515 }
516 return;
517out_dev:
518 mfd_remove_devices(chip->dev);
519 device_irq_exit(chip);
327out: 520out:
328 return; 521 return;
329} 522}
askfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) { ide_task_request_t *req_task; ide_task_t args; u8 *outbuf = NULL; u8 *inbuf = NULL; task_ioreg_t *argsptr = args.tfRegister; task_ioreg_t *hobsptr = args.hobRegister; int err = 0; int tasksize = sizeof(struct ide_task_request_s); unsigned int taskin = 0; unsigned int taskout = 0; u8 io_32bit = drive->io_32bit; char __user *buf = (char __user *)arg; // printk("IDE Taskfile ...\n"); req_task = kzalloc(tasksize, GFP_KERNEL); if (req_task == NULL) return -ENOMEM; if (copy_from_user(req_task, buf, tasksize)) { kfree(req_task); return -EFAULT; } taskout = req_task->out_size; taskin = req_task->in_size; if (taskin > 65536 || taskout > 65536) { err = -EINVAL; goto abort; } if (taskout) { int outtotal = tasksize; outbuf = kzalloc(taskout, GFP_KERNEL); if (outbuf == NULL) { err = -ENOMEM; goto abort; } if (copy_from_user(outbuf, buf + outtotal, taskout)) { err = -EFAULT; goto abort; } } if (taskin) { int intotal = tasksize + taskout; inbuf = kzalloc(taskin, GFP_KERNEL); if (inbuf == NULL) { err = -ENOMEM; goto abort; } if (copy_from_user(inbuf, buf + intotal, taskin)) { err = -EFAULT; goto abort; } } memset(&args, 0, sizeof(ide_task_t)); memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE); memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE); args.tf_in_flags = req_task->in_flags; args.tf_out_flags = req_task->out_flags; args.data_phase = req_task->data_phase; args.command_type = req_task->req_cmd; drive->io_32bit = 0; switch(req_task->data_phase) { case TASKFILE_OUT_DMAQ: case TASKFILE_OUT_DMA: err = ide_diag_taskfile(drive, &args, taskout, outbuf); break; case TASKFILE_IN_DMAQ: case TASKFILE_IN_DMA: err = ide_diag_taskfile(drive, &args, taskin, inbuf); break; case TASKFILE_MULTI_OUT: if (!drive->mult_count) { /* (hs): give up if multcount is not set */ printk(KERN_ERR "%s: %s Multimode Write " \ "multcount is not set\n", drive->name, __FUNCTION__); err = -EPERM; goto abort; } /* fall through */ case TASKFILE_OUT: args.prehandler = &pre_task_out_intr; args.handler = &task_out_intr; err = ide_diag_taskfile(drive, &args, taskout, outbuf); break; case TASKFILE_MULTI_IN: if (!drive->mult_count) { /* (hs): give up if multcount is not set */ printk(KERN_ERR "%s: %s Multimode Read failure " \ "multcount is not set\n", drive->name, __FUNCTION__); err = -EPERM; goto abort; } /* fall through */ case TASKFILE_IN: args.handler = &task_in_intr; err = ide_diag_taskfile(drive, &args, taskin, inbuf); break; case TASKFILE_NO_DATA: args.handler = &task_no_data_intr; err = ide_diag_taskfile(drive, &args, 0, NULL); break; default: err = -EFAULT; goto abort; } memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE); memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE); req_task->in_flags = args.tf_in_flags; req_task->out_flags = args.tf_out_flags; if (copy_to_user(buf, req_task, tasksize)) { err = -EFAULT; goto abort; } if (taskout) { int outtotal = tasksize; if (copy_to_user(buf + outtotal, outbuf, taskout)) { err = -EFAULT; goto abort; } } if (taskin) { int intotal = tasksize + taskout; if (copy_to_user(buf + intotal, inbuf, taskin)) { err = -EFAULT; goto abort; } } abort: kfree(req_task); kfree(outbuf); kfree(inbuf); // printk("IDE Taskfile ioctl ended. rc = %i\n", err); drive->io_32bit = io_32bit; return err; } int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf) { struct request rq; u8 buffer[4]; if (!buf) buf = buffer; memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors); ide_init_drive_cmd(&rq); rq.buffer = buf; *buf++ = cmd; *buf++ = nsect; *buf++ = feature; *buf++ = sectors; return ide_do_drive_cmd(drive, &rq, ide_wait); } /* * FIXME : this needs to map into at taskfile. <andre@linux-ide.org> */ int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) { int err = 0; u8 args[4], *argbuf = args; u8 xfer_rate = 0; int argsize = 4; ide_task_t tfargs; if (NULL == (void *) arg) { struct request rq; ide_init_drive_cmd(&rq); return ide_do_drive_cmd(drive, &rq, ide_wait); } if (copy_from_user(args, (void __user *)arg, 4)) return -EFAULT; memset(&tfargs, 0, sizeof(ide_task_t)); tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2]; tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3]; tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1]; tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00; tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00; tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00; tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0]; if (args[3]) { argsize = 4 + (SECTOR_WORDS * 4 * args[3]); argbuf = kzalloc(argsize, GFP_KERNEL); if (argbuf == NULL) return -ENOMEM; } if (set_transfer(drive, &tfargs)) { xfer_rate = args[1]; if (ide_ata66_check(drive, &tfargs)) goto abort; } err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf); if (!err && xfer_rate) { /* active-retuning-calls future */ ide_set_xfer_rate(drive, xfer_rate); ide_driveid_update(drive); } abort: if (copy_to_user((void __user *)arg, argbuf, argsize)) err = -EFAULT; if (argsize > 4) kfree(argbuf);