Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Backlight Driver for Frontpath ProGear HX1050+ |
| 3 | * |
| 4 | * Copyright (c) 2006 Marcin Juszkiewicz |
| 5 | * |
| 6 | * Based on Progear LCD driver by M Schacht |
| 7 | * <mschacht at alumni dot washington dot edu> |
| 8 | * |
| 9 | * Based on Sharp's Corgi Backlight Driver |
| 10 | * Based on Backlight Driver for HP Jornada 680 |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/mutex.h> |
| 23 | #include <linux/fb.h> |
| 24 | #include <linux/backlight.h> |
| 25 | #include <linux/pci.h> |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 26 | |
| 27 | #define PMU_LPCR 0xB0 |
| 28 | #define SB_MPS1 0x61 |
| 29 | #define HW_LEVEL_MAX 0x77 |
| 30 | #define HW_LEVEL_MIN 0x4f |
| 31 | |
| 32 | static struct pci_dev *pmu_dev = NULL; |
| 33 | static struct pci_dev *sb_dev = NULL; |
| 34 | |
| 35 | static int progearbl_set_intensity(struct backlight_device *bd) |
| 36 | { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 37 | int intensity = bd->props.brightness; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 38 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 39 | if (bd->props.power != FB_BLANK_UNBLANK) |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 40 | intensity = 0; |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 41 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 42 | intensity = 0; |
| 43 | |
| 44 | pci_write_config_byte(pmu_dev, PMU_LPCR, intensity + HW_LEVEL_MIN); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int progearbl_get_intensity(struct backlight_device *bd) |
| 50 | { |
| 51 | u8 intensity; |
| 52 | pci_read_config_byte(pmu_dev, PMU_LPCR, &intensity); |
| 53 | |
| 54 | return intensity - HW_LEVEL_MIN; |
| 55 | } |
| 56 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 57 | static const struct backlight_ops progearbl_ops = { |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 58 | .get_brightness = progearbl_get_intensity, |
| 59 | .update_status = progearbl_set_intensity, |
| 60 | }; |
| 61 | |
| 62 | static int progearbl_probe(struct platform_device *pdev) |
| 63 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame^] | 64 | struct backlight_properties props; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 65 | u8 temp; |
| 66 | struct backlight_device *progear_backlight_device; |
Jiri Slaby | a4ebb78 | 2010-02-02 14:44:50 -0800 | [diff] [blame] | 67 | int ret; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 68 | |
Al Viro | 89952d1 | 2007-03-14 09:17:59 +0000 | [diff] [blame] | 69 | pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, NULL); |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 70 | if (!pmu_dev) { |
| 71 | printk("ALI M7101 PMU not found.\n"); |
| 72 | return -ENODEV; |
| 73 | } |
| 74 | |
Al Viro | 89952d1 | 2007-03-14 09:17:59 +0000 | [diff] [blame] | 75 | sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 76 | if (!sb_dev) { |
| 77 | printk("ALI 1533 SB not found.\n"); |
Jiri Slaby | a4ebb78 | 2010-02-02 14:44:50 -0800 | [diff] [blame] | 78 | ret = -ENODEV; |
| 79 | goto put_pmu; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Set SB_MPS1 to enable brightness control. */ |
| 83 | pci_read_config_byte(sb_dev, SB_MPS1, &temp); |
| 84 | pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20); |
| 85 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame^] | 86 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 87 | props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 88 | progear_backlight_device = backlight_device_register("progear-bl", |
| 89 | &pdev->dev, NULL, |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame^] | 90 | &progearbl_ops, |
| 91 | &props); |
Jiri Slaby | a4ebb78 | 2010-02-02 14:44:50 -0800 | [diff] [blame] | 92 | if (IS_ERR(progear_backlight_device)) { |
| 93 | ret = PTR_ERR(progear_backlight_device); |
| 94 | goto put_sb; |
| 95 | } |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 96 | |
| 97 | platform_set_drvdata(pdev, progear_backlight_device); |
| 98 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 99 | progear_backlight_device->props.power = FB_BLANK_UNBLANK; |
| 100 | progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 101 | progearbl_set_intensity(progear_backlight_device); |
| 102 | |
| 103 | return 0; |
Jiri Slaby | a4ebb78 | 2010-02-02 14:44:50 -0800 | [diff] [blame] | 104 | put_sb: |
| 105 | pci_dev_put(sb_dev); |
| 106 | put_pmu: |
| 107 | pci_dev_put(pmu_dev); |
| 108 | return ret; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static int progearbl_remove(struct platform_device *pdev) |
| 112 | { |
| 113 | struct backlight_device *bd = platform_get_drvdata(pdev); |
| 114 | backlight_device_unregister(bd); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static struct platform_driver progearbl_driver = { |
| 120 | .probe = progearbl_probe, |
| 121 | .remove = progearbl_remove, |
| 122 | .driver = { |
| 123 | .name = "progear-bl", |
| 124 | }, |
| 125 | }; |
| 126 | |
| 127 | static struct platform_device *progearbl_device; |
| 128 | |
| 129 | static int __init progearbl_init(void) |
| 130 | { |
| 131 | int ret = platform_driver_register(&progearbl_driver); |
| 132 | |
Akinobu Mita | 6cd6f35 | 2008-11-17 15:19:29 +0000 | [diff] [blame] | 133 | if (ret) |
| 134 | return ret; |
| 135 | progearbl_device = platform_device_register_simple("progear-bl", -1, |
| 136 | NULL, 0); |
| 137 | if (IS_ERR(progearbl_device)) { |
| 138 | platform_driver_unregister(&progearbl_driver); |
| 139 | return PTR_ERR(progearbl_device); |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Akinobu Mita | 6cd6f35 | 2008-11-17 15:19:29 +0000 | [diff] [blame] | 142 | return 0; |
Marcin Juszkiewicz | 7a20846 | 2007-02-07 22:24:01 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static void __exit progearbl_exit(void) |
| 146 | { |
| 147 | pci_dev_put(pmu_dev); |
| 148 | pci_dev_put(sb_dev); |
| 149 | |
| 150 | platform_device_unregister(progearbl_device); |
| 151 | platform_driver_unregister(&progearbl_driver); |
| 152 | } |
| 153 | |
| 154 | module_init(progearbl_init); |
| 155 | module_exit(progearbl_exit); |
| 156 | |
| 157 | MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>"); |
| 158 | MODULE_DESCRIPTION("ProGear Backlight Driver"); |
| 159 | MODULE_LICENSE("GPL"); |