Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.8 181 lines 4.0 kB view raw
1/* 2 * LCD / Backlight control code for Sharp SL-6000x (tosa) 3 * 4 * Copyright (c) 2005 Dirk Opfer 5 * Copyright (c) 2007,2008 Dmitry Baryshkov 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 */ 12 13#include <linux/kernel.h> 14#include <linux/module.h> 15#include <linux/device.h> 16#include <linux/spi/spi.h> 17#include <linux/i2c.h> 18#include <linux/gpio.h> 19#include <linux/fb.h> 20#include <linux/backlight.h> 21#include <linux/slab.h> 22 23#include <asm/mach/sharpsl_param.h> 24 25#include <mach/tosa.h> 26 27#define COMADJ_DEFAULT 97 28 29#define DAC_CH1 0 30#define DAC_CH2 1 31 32struct tosa_bl_data { 33 struct i2c_client *i2c; 34 struct backlight_device *bl; 35 36 int comadj; 37}; 38 39static void tosa_bl_set_backlight(struct tosa_bl_data *data, int brightness) 40{ 41 struct spi_device *spi = data->i2c->dev.platform_data; 42 43 i2c_smbus_write_byte_data(data->i2c, DAC_CH1, data->comadj); 44 45 /* SetBacklightDuty */ 46 i2c_smbus_write_byte_data(data->i2c, DAC_CH2, (u8)(brightness & 0xff)); 47 48 /* SetBacklightVR */ 49 gpio_set_value(TOSA_GPIO_BL_C20MA, brightness & 0x100); 50 51 tosa_bl_enable(spi, brightness); 52} 53 54static int tosa_bl_update_status(struct backlight_device *dev) 55{ 56 struct backlight_properties *props = &dev->props; 57 struct tosa_bl_data *data = dev_get_drvdata(&dev->dev); 58 int power = max(props->power, props->fb_blank); 59 int brightness = props->brightness; 60 61 if (power) 62 brightness = 0; 63 64 tosa_bl_set_backlight(data, brightness); 65 66 return 0; 67} 68 69static int tosa_bl_get_brightness(struct backlight_device *dev) 70{ 71 struct backlight_properties *props = &dev->props; 72 73 return props->brightness; 74} 75 76static const struct backlight_ops bl_ops = { 77 .get_brightness = tosa_bl_get_brightness, 78 .update_status = tosa_bl_update_status, 79}; 80 81static int tosa_bl_probe(struct i2c_client *client, 82 const struct i2c_device_id *id) 83{ 84 struct backlight_properties props; 85 struct tosa_bl_data *data; 86 int ret = 0; 87 88 data = devm_kzalloc(&client->dev, sizeof(struct tosa_bl_data), 89 GFP_KERNEL); 90 if (!data) 91 return -ENOMEM; 92 93 data->comadj = sharpsl_param.comadj == -1 ? COMADJ_DEFAULT : sharpsl_param.comadj; 94 95 ret = devm_gpio_request_one(&client->dev, TOSA_GPIO_BL_C20MA, 96 GPIOF_OUT_INIT_LOW, "backlight"); 97 if (ret) { 98 dev_dbg(&data->bl->dev, "Unable to request gpio!\n"); 99 return ret; 100 } 101 102 i2c_set_clientdata(client, data); 103 data->i2c = client; 104 105 memset(&props, 0, sizeof(struct backlight_properties)); 106 props.type = BACKLIGHT_RAW; 107 props.max_brightness = 512 - 1; 108 data->bl = backlight_device_register("tosa-bl", &client->dev, data, 109 &bl_ops, &props); 110 if (IS_ERR(data->bl)) { 111 ret = PTR_ERR(data->bl); 112 goto err_reg; 113 } 114 115 data->bl->props.brightness = 69; 116 data->bl->props.power = FB_BLANK_UNBLANK; 117 118 backlight_update_status(data->bl); 119 120 return 0; 121 122err_reg: 123 data->bl = NULL; 124 return ret; 125} 126 127static int tosa_bl_remove(struct i2c_client *client) 128{ 129 struct tosa_bl_data *data = i2c_get_clientdata(client); 130 131 backlight_device_unregister(data->bl); 132 data->bl = NULL; 133 134 return 0; 135} 136 137#ifdef CONFIG_PM 138static int tosa_bl_suspend(struct i2c_client *client, pm_message_t pm) 139{ 140 struct tosa_bl_data *data = i2c_get_clientdata(client); 141 142 tosa_bl_set_backlight(data, 0); 143 144 return 0; 145} 146 147static int tosa_bl_resume(struct i2c_client *client) 148{ 149 struct tosa_bl_data *data = i2c_get_clientdata(client); 150 151 backlight_update_status(data->bl); 152 return 0; 153} 154#else 155#define tosa_bl_suspend NULL 156#define tosa_bl_resume NULL 157#endif 158 159static const struct i2c_device_id tosa_bl_id[] = { 160 { "tosa-bl", 0 }, 161 { }, 162}; 163 164static struct i2c_driver tosa_bl_driver = { 165 .driver = { 166 .name = "tosa-bl", 167 .owner = THIS_MODULE, 168 }, 169 .probe = tosa_bl_probe, 170 .remove = tosa_bl_remove, 171 .suspend = tosa_bl_suspend, 172 .resume = tosa_bl_resume, 173 .id_table = tosa_bl_id, 174}; 175 176module_i2c_driver(tosa_bl_driver); 177 178MODULE_AUTHOR("Dmitry Baryshkov"); 179MODULE_LICENSE("GPL v2"); 180MODULE_DESCRIPTION("LCD/Backlight control for Sharp SL-6000 PDA"); 181