Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Backlight driver for HP Jornada 700 series (710/720/728) |
| 4 | * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License version |
| 8 | * 2 or any later version as published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 14 | #include <linux/backlight.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/fb.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | |
| 21 | #include <mach/jornada720.h> |
| 22 | #include <mach/hardware.h> |
| 23 | |
| 24 | #include <video/s1d13xxxfb.h> |
| 25 | |
| 26 | #define BL_MAX_BRIGHT 255 |
| 27 | #define BL_DEF_BRIGHT 25 |
| 28 | |
| 29 | static int jornada_bl_get_brightness(struct backlight_device *bd) |
| 30 | { |
| 31 | int ret; |
| 32 | |
| 33 | /* check if backlight is on */ |
| 34 | if (!(PPSR & PPC_LDD1)) |
| 35 | return 0; |
| 36 | |
| 37 | jornada_ssp_start(); |
| 38 | |
| 39 | /* cmd should return txdummy */ |
| 40 | ret = jornada_ssp_byte(GETBRIGHTNESS); |
| 41 | |
| 42 | if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) { |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 43 | pr_err("get brightness timeout\n"); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 44 | jornada_ssp_end(); |
| 45 | return -ETIMEDOUT; |
| 46 | } else /* exchange txdummy for value */ |
| 47 | ret = jornada_ssp_byte(TXDUMMY); |
| 48 | |
| 49 | jornada_ssp_end(); |
| 50 | |
| 51 | return (BL_MAX_BRIGHT - ret); |
| 52 | } |
| 53 | |
| 54 | static int jornada_bl_update_status(struct backlight_device *bd) |
| 55 | { |
| 56 | int ret = 0; |
| 57 | |
| 58 | jornada_ssp_start(); |
| 59 | |
| 60 | /* If backlight is off then really turn it off */ |
| 61 | if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) { |
| 62 | ret = jornada_ssp_byte(BRIGHTNESSOFF); |
| 63 | if (ret != TXDUMMY) { |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 64 | pr_info("brightness off timeout\n"); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 65 | /* turn off backlight */ |
| 66 | PPSR &= ~PPC_LDD1; |
| 67 | PPDR |= PPC_LDD1; |
| 68 | ret = -ETIMEDOUT; |
| 69 | } |
| 70 | } else /* turn on backlight */ |
| 71 | PPSR |= PPC_LDD1; |
| 72 | |
| 73 | /* send command to our mcu */ |
| 74 | if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) { |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 75 | pr_info("failed to set brightness\n"); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 76 | ret = -ETIMEDOUT; |
Kristoffer Ericson | b317c833 | 2009-07-29 15:04:03 -0700 | [diff] [blame] | 77 | goto out; |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /* at this point we expect that the mcu has accepted |
| 81 | our command and is waiting for our new value |
| 82 | please note that maximum brightness is 255, |
| 83 | but due to physical layout it is equal to 0, so we simply |
| 84 | invert the value (MAX VALUE - NEW VALUE). */ |
| 85 | if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness) != TXDUMMY) { |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 86 | pr_err("set brightness failed\n"); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 87 | ret = -ETIMEDOUT; |
| 88 | } |
| 89 | |
| 90 | /* If infact we get an TXDUMMY as output we are happy and dont |
| 91 | make any further comments about it */ |
| 92 | out: |
| 93 | jornada_ssp_end(); |
| 94 | |
| 95 | return ret; |
| 96 | } |
| 97 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 98 | static const struct backlight_ops jornada_bl_ops = { |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 99 | .get_brightness = jornada_bl_get_brightness, |
| 100 | .update_status = jornada_bl_update_status, |
| 101 | .options = BL_CORE_SUSPENDRESUME, |
| 102 | }; |
| 103 | |
| 104 | static int jornada_bl_probe(struct platform_device *pdev) |
| 105 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 106 | struct backlight_properties props; |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 107 | int ret; |
| 108 | struct backlight_device *bd; |
| 109 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 110 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 111 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 112 | props.max_brightness = BL_MAX_BRIGHT; |
| 113 | bd = backlight_device_register(S1D_DEVICENAME, &pdev->dev, NULL, |
| 114 | &jornada_bl_ops, &props); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 115 | |
| 116 | if (IS_ERR(bd)) { |
| 117 | ret = PTR_ERR(bd); |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 118 | pr_err("failed to register device, err=%x\n", ret); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | bd->props.power = FB_BLANK_UNBLANK; |
| 123 | bd->props.brightness = BL_DEF_BRIGHT; |
| 124 | /* note. make sure max brightness is set otherwise |
| 125 | you will get seemingly non-related errors when |
| 126 | trying to change brightness */ |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 127 | jornada_bl_update_status(bd); |
| 128 | |
| 129 | platform_set_drvdata(pdev, bd); |
Jingoo Han | 20c225c | 2012-05-29 15:07:18 -0700 | [diff] [blame] | 130 | pr_info("HP Jornada 700 series backlight driver\n"); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static int jornada_bl_remove(struct platform_device *pdev) |
| 136 | { |
| 137 | struct backlight_device *bd = platform_get_drvdata(pdev); |
| 138 | |
| 139 | backlight_device_unregister(bd); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static struct platform_driver jornada_bl_driver = { |
| 145 | .probe = jornada_bl_probe, |
| 146 | .remove = jornada_bl_remove, |
| 147 | .driver = { |
| 148 | .name = "jornada_bl", |
| 149 | }, |
| 150 | }; |
| 151 | |
Axel Lin | 81178e0 | 2012-01-10 15:09:11 -0800 | [diff] [blame] | 152 | module_platform_driver(jornada_bl_driver); |
Kristoffer Ericson | 13a7b5d | 2009-02-18 11:50:43 +0000 | [diff] [blame] | 153 | |
| 154 | MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>"); |
| 155 | MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver"); |
| 156 | MODULE_LICENSE("GPL"); |