blob: 2ec16deb2397763d34003a0ba9a491a57deb7fd5 [file] [log] [blame]
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +00001/*
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 Juszkiewicz7a208462007-02-07 22:24:01 +000026
27#define PMU_LPCR 0xB0
28#define SB_MPS1 0x61
29#define HW_LEVEL_MAX 0x77
30#define HW_LEVEL_MIN 0x4f
31
32static struct pci_dev *pmu_dev = NULL;
33static struct pci_dev *sb_dev = NULL;
34
35static int progearbl_set_intensity(struct backlight_device *bd)
36{
Richard Purdie599a52d2007-02-10 23:07:48 +000037 int intensity = bd->props.brightness;
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000038
Richard Purdie599a52d2007-02-10 23:07:48 +000039 if (bd->props.power != FB_BLANK_UNBLANK)
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000040 intensity = 0;
Richard Purdie599a52d2007-02-10 23:07:48 +000041 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000042 intensity = 0;
43
44 pci_write_config_byte(pmu_dev, PMU_LPCR, intensity + HW_LEVEL_MIN);
45
46 return 0;
47}
48
49static 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 Revfy9905a432009-12-14 00:58:57 +010057static const struct backlight_ops progearbl_ops = {
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000058 .get_brightness = progearbl_get_intensity,
59 .update_status = progearbl_set_intensity,
60};
61
62static int progearbl_probe(struct platform_device *pdev)
63{
64 u8 temp;
65 struct backlight_device *progear_backlight_device;
Jiri Slabya4ebb782010-02-02 14:44:50 -080066 int ret;
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000067
Al Viro89952d12007-03-14 09:17:59 +000068 pmu_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, NULL);
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000069 if (!pmu_dev) {
70 printk("ALI M7101 PMU not found.\n");
71 return -ENODEV;
72 }
73
Al Viro89952d12007-03-14 09:17:59 +000074 sb_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000075 if (!sb_dev) {
76 printk("ALI 1533 SB not found.\n");
Jiri Slabya4ebb782010-02-02 14:44:50 -080077 ret = -ENODEV;
78 goto put_pmu;
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000079 }
80
81 /* Set SB_MPS1 to enable brightness control. */
82 pci_read_config_byte(sb_dev, SB_MPS1, &temp);
83 pci_write_config_byte(sb_dev, SB_MPS1, temp | 0x20);
84
85 progear_backlight_device = backlight_device_register("progear-bl",
86 &pdev->dev, NULL,
Richard Purdie599a52d2007-02-10 23:07:48 +000087 &progearbl_ops);
Jiri Slabya4ebb782010-02-02 14:44:50 -080088 if (IS_ERR(progear_backlight_device)) {
89 ret = PTR_ERR(progear_backlight_device);
90 goto put_sb;
91 }
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000092
93 platform_set_drvdata(pdev, progear_backlight_device);
94
Richard Purdie599a52d2007-02-10 23:07:48 +000095 progear_backlight_device->props.power = FB_BLANK_UNBLANK;
96 progear_backlight_device->props.brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
97 progear_backlight_device->props.max_brightness = HW_LEVEL_MAX - HW_LEVEL_MIN;
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +000098 progearbl_set_intensity(progear_backlight_device);
99
100 return 0;
Jiri Slabya4ebb782010-02-02 14:44:50 -0800101put_sb:
102 pci_dev_put(sb_dev);
103put_pmu:
104 pci_dev_put(pmu_dev);
105 return ret;
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +0000106}
107
108static int progearbl_remove(struct platform_device *pdev)
109{
110 struct backlight_device *bd = platform_get_drvdata(pdev);
111 backlight_device_unregister(bd);
112
113 return 0;
114}
115
116static struct platform_driver progearbl_driver = {
117 .probe = progearbl_probe,
118 .remove = progearbl_remove,
119 .driver = {
120 .name = "progear-bl",
121 },
122};
123
124static struct platform_device *progearbl_device;
125
126static int __init progearbl_init(void)
127{
128 int ret = platform_driver_register(&progearbl_driver);
129
Akinobu Mita6cd6f352008-11-17 15:19:29 +0000130 if (ret)
131 return ret;
132 progearbl_device = platform_device_register_simple("progear-bl", -1,
133 NULL, 0);
134 if (IS_ERR(progearbl_device)) {
135 platform_driver_unregister(&progearbl_driver);
136 return PTR_ERR(progearbl_device);
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +0000137 }
138
Akinobu Mita6cd6f352008-11-17 15:19:29 +0000139 return 0;
Marcin Juszkiewicz7a208462007-02-07 22:24:01 +0000140}
141
142static void __exit progearbl_exit(void)
143{
144 pci_dev_put(pmu_dev);
145 pci_dev_put(sb_dev);
146
147 platform_device_unregister(progearbl_device);
148 platform_driver_unregister(&progearbl_driver);
149}
150
151module_init(progearbl_init);
152module_exit(progearbl_exit);
153
154MODULE_AUTHOR("Marcin Juszkiewicz <linux@hrw.one.pl>");
155MODULE_DESCRIPTION("ProGear Backlight Driver");
156MODULE_LICENSE("GPL");