1 // SPDX-License-Identifier: GPL-2.0-only
3 * Backlight Driver for the KB3886 Backlight
5 * Copyright (c) 2007-2008 Claudio Nieder
7 * Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/mutex.h>
16 #include <linux/backlight.h>
17 #include <linux/delay.h>
18 #include <linux/dmi.h>
20 #define KB3886_PARENT 0x64
21 #define KB3886_IO 0x60
22 #define KB3886_ADC_DAC_PWM 0xC4
23 #define KB3886_PWM0_WRITE 0x81
24 #define KB3886_PWM0_READ 0x41
26 static DEFINE_MUTEX(bl_mutex
);
28 static void kb3886_bl_set_intensity(int intensity
)
30 mutex_lock(&bl_mutex
);
31 intensity
= intensity
&0xff;
32 outb(KB3886_ADC_DAC_PWM
, KB3886_PARENT
);
33 usleep_range(10000, 11000);
34 outb(KB3886_PWM0_WRITE
, KB3886_IO
);
35 usleep_range(10000, 11000);
36 outb(intensity
, KB3886_IO
);
37 mutex_unlock(&bl_mutex
);
40 struct kb3886bl_machinfo
{
42 int default_intensity
;
44 void (*set_bl_intensity
)(int intensity
);
47 static struct kb3886bl_machinfo kb3886_bl_machinfo
= {
48 .max_intensity
= 0xff,
49 .default_intensity
= 0xa0,
51 .set_bl_intensity
= kb3886_bl_set_intensity
,
54 static struct platform_device kb3886bl_device
= {
57 .platform_data
= &kb3886_bl_machinfo
,
62 static struct platform_device
*devices
[] __initdata
= {
70 static int kb3886bl_intensity
;
71 static struct backlight_device
*kb3886_backlight_device
;
72 static struct kb3886bl_machinfo
*bl_machinfo
;
74 static unsigned long kb3886bl_flags
;
75 #define KB3886BL_SUSPENDED 0x01
77 static const struct dmi_system_id kb3886bl_device_table
[] __initconst
= {
79 .ident
= "Sahara Touch-iT",
81 DMI_MATCH(DMI_SYS_VENDOR
, "SDV"),
82 DMI_MATCH(DMI_PRODUCT_NAME
, "iTouch T201"),
88 static int kb3886bl_send_intensity(struct backlight_device
*bd
)
90 int intensity
= bd
->props
.brightness
;
92 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
94 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
96 if (kb3886bl_flags
& KB3886BL_SUSPENDED
)
99 bl_machinfo
->set_bl_intensity(intensity
);
101 kb3886bl_intensity
= intensity
;
105 #ifdef CONFIG_PM_SLEEP
106 static int kb3886bl_suspend(struct device
*dev
)
108 struct backlight_device
*bd
= dev_get_drvdata(dev
);
110 kb3886bl_flags
|= KB3886BL_SUSPENDED
;
111 backlight_update_status(bd
);
115 static int kb3886bl_resume(struct device
*dev
)
117 struct backlight_device
*bd
= dev_get_drvdata(dev
);
119 kb3886bl_flags
&= ~KB3886BL_SUSPENDED
;
120 backlight_update_status(bd
);
125 static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops
, kb3886bl_suspend
, kb3886bl_resume
);
127 static int kb3886bl_get_intensity(struct backlight_device
*bd
)
129 return kb3886bl_intensity
;
132 static const struct backlight_ops kb3886bl_ops
= {
133 .get_brightness
= kb3886bl_get_intensity
,
134 .update_status
= kb3886bl_send_intensity
,
137 static int kb3886bl_probe(struct platform_device
*pdev
)
139 struct backlight_properties props
;
140 struct kb3886bl_machinfo
*machinfo
= dev_get_platdata(&pdev
->dev
);
142 bl_machinfo
= machinfo
;
143 if (!machinfo
->limit_mask
)
144 machinfo
->limit_mask
= -1;
146 memset(&props
, 0, sizeof(struct backlight_properties
));
147 props
.type
= BACKLIGHT_RAW
;
148 props
.max_brightness
= machinfo
->max_intensity
;
149 kb3886_backlight_device
= devm_backlight_device_register(&pdev
->dev
,
150 "kb3886-bl", &pdev
->dev
,
153 if (IS_ERR(kb3886_backlight_device
))
154 return PTR_ERR(kb3886_backlight_device
);
156 platform_set_drvdata(pdev
, kb3886_backlight_device
);
158 kb3886_backlight_device
->props
.power
= FB_BLANK_UNBLANK
;
159 kb3886_backlight_device
->props
.brightness
= machinfo
->default_intensity
;
160 backlight_update_status(kb3886_backlight_device
);
165 static struct platform_driver kb3886bl_driver
= {
166 .probe
= kb3886bl_probe
,
169 .pm
= &kb3886bl_pm_ops
,
173 static int __init
kb3886_init(void)
175 if (!dmi_check_system(kb3886bl_device_table
))
178 platform_add_devices(devices
, ARRAY_SIZE(devices
));
179 return platform_driver_register(&kb3886bl_driver
);
182 static void __exit
kb3886_exit(void)
184 platform_driver_unregister(&kb3886bl_driver
);
187 module_init(kb3886_init
);
188 module_exit(kb3886_exit
);
190 MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
191 MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
192 MODULE_LICENSE("GPL");
193 MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");