From 0162818a8a87413260a4a10eb4d5df1dd33b4993 Mon Sep 17 00:00:00 2001 From: tytung Date: Thu, 17 Feb 2011 21:09:15 +0800 Subject: [PATCH] =?UTF-8?q?New=20led=20driver=20compatible=20with=20Desire?= =?UTF-8?q?=20(Bravo)=20liblights=20=20-=20remove=20all=20lights.*.so=20fi?= =?UTF-8?q?les=20from=20/system/lib/hw=20(backup=20if=20u=20want)=20and=20?= =?UTF-8?q?replace=20with=20lights.qsd8k.so=20from=20Bravo=20ROM=20or=20do?= =?UTF-8?q?wnload=20from=20http://www.multiupload.com/2M5T02M3TU=20=20-=20?= =?UTF-8?q?if=20button=20backlight=20don=E2=80=99t=20work:=20turn=20screen?= =?UTF-8?q?=20on,=20press=20any=20key=20and=20put=20phone=20under=20bright?= =?UTF-8?q?=20light=20(=20this=20should=20activate=20light=20sensor=20and?= =?UTF-8?q?=20backlight)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Conflicts: arch/arm/configs/htcleo_defconfig arch/arm/mach-msm/board-htcleo.h Add commit from http://gitorious.org/linux-on-wince-htc/linux_on_wince_htc/commit/654ce990ab38bce777266ab423d1674b5e5c6873 --- arch/arm/configs/htcleo_defconfig | 6 +- arch/arm/mach-msm/Makefile | 2 +- arch/arm/mach-msm/atmega_microp_common.c | 6 + arch/arm/mach-msm/board-htcleo.c | 28 +++- arch/arm/mach-msm/board-htcleo.h | 19 +++ drivers/leds/Makefile | 2 +- drivers/leds/leds-microp.c | 162 ++++++++++++++++------- 7 files changed, 168 insertions(+), 57 deletions(-) mode change 100644 => 100755 drivers/leds/leds-microp.c diff --git a/arch/arm/configs/htcleo_defconfig b/arch/arm/configs/htcleo_defconfig index c1beeff0..43b9e44f 100644 --- a/arch/arm/configs/htcleo_defconfig +++ b/arch/arm/configs/htcleo_defconfig @@ -202,9 +202,7 @@ CONFIG_ARCH_MSM=y CONFIG_ARCH_QSD8X50=y CONFIG_ARCH_MSM_SCORPION=y CONFIG_MSM_MDP31=y -CONFIG_PERFLOCK=y -CONFIG_PERFLOCK_BOOT_LOCK=y -# CONFIG_PERFLOCK_SCREEN_POLICY is not set +# CONFIG_PERFLOCK is not set CONFIG_MSM_AMSS_VERSION=1550 # CONFIG_MSM_AMSS_VERSION_6210 is not set # CONFIG_MSM_AMSS_VERSION_6220 is not set @@ -239,8 +237,8 @@ CONFIG_MACH_HTCLEO=y # CONFIG_MACH_INCREDIBLE is not set # CONFIG_MACH_INCREDIBLEC is not set # CONFIG_MACH_SUPERSONIC is not set -# CONFIG_HTC_BATTCHG_SMEM is not set CONFIG_HTC_BATTCHG=y +# CONFIG_HTC_BATTCHG_SMEM is not set # CONFIG_HTC_PWRSINK is not set CONFIG_HTC_SLEEP_MODE_GPIO_DUMP=y # CONFIG_HTC_POWER_COLLAPSE_MAGIC is not set diff --git a/arch/arm/mach-msm/Makefile b/arch/arm/mach-msm/Makefile index a8f31f3a..3720b181 100644 --- a/arch/arm/mach-msm/Makefile +++ b/arch/arm/mach-msm/Makefile @@ -123,7 +123,7 @@ obj-$(CONFIG_MACH_HTCLEO) += board-htcleo-ts.o board-htcleo-mmc.o ieee754-df.o obj-$(CONFIG_MACH_HTCLEO) += board-htcleo-audio.o board-htcleo-acoustic.o obj-$(CONFIG_MACH_HTCLEO) += board-htcleo-rfkill.o board-htcleo-wifi.o board-htcleo-microp.o -obj-$(CONFIG_MACH_HTCLEO) += board-htcleo-proximity.o board-htcleo-leds.o board-htcleo-ls.o +obj-$(CONFIG_MACH_HTCLEO) += board-htcleo-proximity.o board-htcleo-ls.o obj-$(CONFIG_MACH_HTCLEO) += clock-wince.o obj-$(CONFIG_HTCLEO_BACKLIGHT) += board-htcleo-bl.o obj-$(CONFIG_HTCLEO_BACKLIGHT_LED) += board-htcleo-bl-led.o diff --git a/arch/arm/mach-msm/atmega_microp_common.c b/arch/arm/mach-msm/atmega_microp_common.c index c7b3f72f..ed8a60ec 100644 --- a/arch/arm/mach-msm/atmega_microp_common.c +++ b/arch/arm/mach-msm/atmega_microp_common.c @@ -144,6 +144,7 @@ static int i2c_write_block(struct i2c_client *client, uint8_t addr, return 0; } +#ifndef CONFIG_MACH_HTCLEO int microp_i2c_read(uint8_t addr, uint8_t *data, int length) { struct i2c_client *client = private_microp_client; @@ -179,6 +180,7 @@ int microp_i2c_write(uint8_t addr, uint8_t *data, int length) return 0; } EXPORT_SYMBOL(microp_i2c_write); +#endif void microp_mobeam_enable(int enable) { @@ -234,6 +236,7 @@ int microp_write_interrupt(struct i2c_client *client, return ret; } +#ifndef CONFIG_MACH_HTCLEO int microp_set_adc_req(uint8_t value) { struct i2c_client *client; @@ -274,6 +277,7 @@ int microp_get_remote_adc(uint32_t *val) printk("remote adc %d\n", *val); return 0; } +#endif int microp_read_adc(uint8_t *data) { @@ -360,6 +364,7 @@ static int microp_spi_enable(struct i2c_client *client, uint8_t enable) return ret; } +#ifndef CONFIG_MACH_HTCLEO int microp_spi_vote_enable(int spi_device, uint8_t enable) { struct i2c_client *client = private_microp_client; @@ -410,6 +415,7 @@ exit: } EXPORT_SYMBOL(microp_spi_vote_enable); +#endif static void microp_reset_microp(struct i2c_client *client) { diff --git a/arch/arm/mach-msm/board-htcleo.c b/arch/arm/mach-msm/board-htcleo.c index 19e42d60..de80a013 100644 --- a/arch/arm/mach-msm/board-htcleo.c +++ b/arch/arm/mach-msm/board-htcleo.c @@ -62,6 +62,7 @@ #include "proc_comm.h" #include "dex_comm.h" + #define ATAG_MAGLDR_BOOT 0x4C47414D struct tag_magldr_entry { @@ -191,6 +192,27 @@ static struct akm8973_platform_data compass_platform_data = .intr = HTCLEO_GPIO_COMPASS_INT_N, }; + +/////////////////////////////////////////////////////////////////////// +// LED Driver (drivers/leds/leds-microp.c - Atmega microp driver +/////////////////////////////////////////////////////////////////////// + +static struct microp_led_config led_config[] = { + { + .name = "amber", + .type = LED_RGB, + }, + { + .name = "green", + .type = LED_RGB, + }, +}; + +static struct microp_led_platform_data microp_leds_data = { + .num_leds = ARRAY_SIZE(led_config), + .led_config = led_config, +}; + /////////////////////////////////////////////////////////////////////// // Microp /////////////////////////////////////////////////////////////////////// @@ -216,8 +238,12 @@ static struct platform_device microp_devices[] = { .id = -1, }, { - .name = "htcleo-leds", + .name = "leds-microp", .id = -1, + .dev = { + .platform_data = µp_leds_data, + }, + }, { .name = "htcleo-lsensor", diff --git a/arch/arm/mach-msm/board-htcleo.h b/arch/arm/mach-msm/board-htcleo.h index c72a4ce1..4504550b 100644 --- a/arch/arm/mach-msm/board-htcleo.h +++ b/arch/arm/mach-msm/board-htcleo.h @@ -176,6 +176,25 @@ #define HTCLEO_TPS65023_MIN_UV_MV (800) #define HTCLEO_TPS65023_MAX_UV_MV (1350) +/* LEDS */ +#define LED_RGB (1 << 0) +struct microp_led_config { + const char *name; + uint32_t type; + uint8_t init_value; + uint8_t fade_time; + uint16_t led_pin; + uint8_t mask_w[3]; +}; + +struct microp_led_platform_data { + struct microp_led_config *led_config; + int num_leds; +}; + + + + int htcleo_pm_set_vreg(int enable, unsigned id); int __init htcleo_init_panel(void); int htcleo_is_nand_boot(void); diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index b49f47a8..5552d8c7 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -30,7 +30,7 @@ obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o obj-$(CONFIG_LEDS_PWM) += leds-pwm.o -obj-$(CONFIG_MICROP_COMMON) += leds-microp.o +obj-$(CONFIG_MACH_HTCLEO) += leds-microp.o obj-$(CONFIG_LEDS_PM8058) += leds-pm8058.o # LED SPI Drivers diff --git a/drivers/leds/leds-microp.c b/drivers/leds/leds-microp.c old mode 100644 new mode 100755 index acdead6e..be4b8643 --- a/drivers/leds/leds-microp.c +++ b/drivers/leds/leds-microp.c @@ -1,6 +1,7 @@ /* include/asm/mach-msm/leds-microp.c * * Copyright (C) 2009 HTC Corporation. + * Copyright (C) 2010 Danijel Posilovic - dan1j3l * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -13,7 +14,6 @@ * */ -#ifdef CONFIG_MICROP_COMMON #include #include #include @@ -22,42 +22,106 @@ #include #include -static int microp_write_led_mode(struct led_classdev *led_cdev, - uint8_t mode, uint16_t off_timer) -{ +int gl_state = 0; // Green led last state +int al_state = 0; // Amber led last state + +static int microp_write_led_mode(struct led_classdev *led_cdev,uint8_t mode, uint16_t off_timer){ + struct microp_led_data *ldata; uint8_t data[7]; int ret; ldata = container_of(led_cdev, struct microp_led_data, ldev); + //pr_warning("LEDS: set led: %s, mode: %d, brightness:%d\n", ldata->ldev.name, mode,ldata->brightness); + if (!strcmp(ldata->ldev.name, "green")) { - data[0] = 0x01; - data[1] = mode; - data[2] = off_timer >> 8; - data[3] = off_timer & 0xFF; - data[4] = 0x00; - data[5] = 0x00; - data[6] = 0x00; + + switch (mode){ + case 0: + case 1: + if (ldata->brightness){ + //pr_warning("LEDS: turning on green\n"); + data[1] = 0x01; + gl_state = 1; + al_state = 0; + }else{ + + if (gl_state !=0){ // Only reset led if green is on, and vice versa + //pr_warning("LEDS: turning off green\n"); + data[1] = 0x00; + gl_state = 0; + }else{ + //pr_warning("LEDS: braking green\n"); + return 0; + } + } + break; + + case 2: // Slow blink + data[1] = 0x03; + gl_state = 1; + al_state = 0; + break; + + case 3: // Fast blink + data[1] = 0x04; + gl_state = 1; + al_state = 0; + break; + + case 4: // Green / Amber + data[0] = 0x10; + data[1] = 0x10; + gl_state = 1; + al_state = 0; + break; + } } else if (!strcmp(ldata->ldev.name, "amber")) { - data[0] = 0x02; - data[1] = 0x00; - data[2] = 0x00; - data[3] = 0x00; - data[4] = mode; - data[5] = off_timer >> 8; - data[6] = off_timer & 0xFF; - } else if (!strcmp(ldata->ldev.name, "blue")) { - data[0] = 0x04; - data[1] = mode; - data[2] = off_timer >> 8; - data[3] = off_timer & 0xFF; - data[4] = 0x00; - data[5] = 0x00; - data[6] = 0x00; + + switch (mode){ + case 0: + case 1: + if (ldata->brightness){ + data[1] = 0x02; + al_state = 1; + gl_state = 0; + //pr_warning("LEDS: turning on amber\n"); + }else{ + if (al_state !=0){ + //pr_warning("LEDS: turning off amber\n"); + data[1] = 0x00; + al_state = 0; + }else{ + //pr_warning("LEDS: breaking amber\n"); + return 0; + } + } + break; + + case 2: // Amber fast flash + data[1] = 0x05; + al_state = 1; + gl_state = 0; + break; + + case 3: // Green / Amber + data[0] = 0x10; + data[1] = 0x10; + al_state = 1; + gl_state = 0; + break; + } } - ret = microp_i2c_write(MICROP_I2C_WCMD_LED_MODE, data, 7); + // Other default settings + data[2] = off_timer >> 8; + data[3] = off_timer & 0xFF; + data[4] = 0x00; + data[5] = 0x00; + data[6] = 0x00; + + ret = microp_i2c_write(MICROP_I2C_WCMD_LED_CTRL, data, 7); if (ret == 0) { mutex_lock(&ldata->led_data_mutex); if (mode > 1) @@ -68,9 +132,8 @@ static int microp_write_led_mode(struct led_classdev *led_cdev, return ret; } -static void microp_led_brightness_set(struct led_classdev *led_cdev, - enum led_brightness brightness) -{ +static void microp_led_brightness_set(struct led_classdev *led_cdev,enum led_brightness brightness){ + struct microp_led_data *ldata; unsigned long flags; int ret; @@ -96,9 +159,8 @@ static void microp_led_brightness_set(struct led_classdev *led_cdev, pr_err("%s: led_brightness_set failed to set mode\n", __func__); } -static void microp_led_jogball_brightness_set(struct led_classdev *led_cdev, - enum led_brightness brightness) -{ +static void microp_led_jogball_brightness_set(struct led_classdev *led_cdev,enum led_brightness brightness){ + struct microp_led_data *ldata; unsigned long flags; uint8_t data[3] = {0, 0, 0}; @@ -136,15 +198,12 @@ static void microp_led_jogball_brightness_set(struct led_classdev *led_cdev, pr_err("%s failed on set jogball mode:0x%2.2X\n", __func__, data[0]); } -static void microp_led_mobeam_brightness_set(struct led_classdev *led_cdev, - enum led_brightness brightness) -{ +static void microp_led_mobeam_brightness_set(struct led_classdev *led_cdev,enum led_brightness brightness){ ; } -static void microp_led_wimax_brightness_set(struct led_classdev *led_cdev, - enum led_brightness brightness) -{ +static void microp_led_wimax_brightness_set(struct led_classdev *led_cdev,enum led_brightness brightness){ + struct microp_led_data *ldata; unsigned long flags; uint8_t data[3] = {0, 0, 0}; @@ -275,24 +334,21 @@ static ssize_t microp_led_blink_store(struct device *dev, ldata = container_of(led_cdev, struct microp_led_data, ldev); mutex_lock(&ldata->led_data_mutex); + //pr_warning("LEDS: read blink: led: %s, value: %d",ldata->ldev.name,val); switch (val) { case 0: /* stop flashing */ + case 1: ldata->blink = 0; if (led_cdev->brightness) mode = 1; else mode = 0; break; - case 1: case 2: case 3: - mode = val + 1; - break; case 4: - if (!strcmp(ldata->ldev.name, "amber")) { - mode = val + 1; - break; - } + mode = val; + break; default: mutex_unlock(&ldata->led_data_mutex); return -EINVAL; @@ -426,6 +482,8 @@ static ssize_t microp_jogball_color_store(struct device *dev, static DEVICE_ATTR(color, 0644, NULL, microp_jogball_color_store); + +#ifdef CONFIG_MICROP_COMMON static ssize_t microp_mobeam_read_status_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -447,7 +505,7 @@ static ssize_t microp_mobeam_download_store(struct device *dev, const char *buf, size_t count) { int i, ret, num; - uint8_t data[73] ; /* Size of cbitstream array MAX 73 bytes. */ + uint8_t data[73] ; // Size of cbitstream array MAX 73 bytes. pr_info("%s\n", __func__); memset(data, 0x00, sizeof(data)); @@ -546,7 +604,7 @@ pr_info("%s\n", __func__); return count; } static DEVICE_ATTR(stop_led, 0644, NULL, microp_mobeam_stop_led); - +#endif static int microp_led_probe(struct platform_device *pdev) { @@ -634,6 +692,7 @@ static int microp_led_probe(struct platform_device *pdev) break; } +#ifdef CONFIG_MICROP_COMMON for (i = 0; i < pdata->num_leds; i++) { if (pdata->led_config[i].type != LED_MOBEAM) continue; @@ -678,10 +737,12 @@ static int microp_led_probe(struct platform_device *pdev) } break; } +#endif pr_info("%s: succeeded\n", __func__); return 0; - + +#ifdef CONFIG_MICROP_COMMON err_create_mo_stop_attr_file: device_remove_file(ldata[i].ldev.dev, &dev_attr_mobeam_enable); err_create_mo_enable_attr_file: @@ -692,6 +753,8 @@ err_create_mo_send_attr_file: device_remove_file(ldata[i].ldev.dev, &dev_attr_data_download); err_create_mo_download_attr_file: i = pdata->num_leds; +#endif + err_register_attr_color: for (i--; i >= 0; i--) { if (pdata->led_config[i].type != LED_JOGBALL) @@ -773,5 +836,4 @@ module_exit(microp_led_exit); MODULE_DESCRIPTION("Atmega MicroP led driver"); MODULE_LICENSE("GPL"); -#endif /* end of #ifdef CONFIG_MICROP_COMMON*/