2 * Maru brightness device for VGA
4 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * SeokYeon Hwang <syeon.hwang@samsung.com>
8 * SangJin Kim <sangjin3.kim@samsung.com>
9 * MunKyu Im <munkyu.im@samsung.com>
10 * KiTae Kim <kt920.kim@samsung.com>
11 * JinHyung Jo <jinhyung.jo@samsung.com>
12 * SungMin Ha <sungmin82.ha@samsung.com>
13 * JiHye Kim <jihye1128.kim@samsung.com>
14 * GiWoong Kim <giwoong.kim@samsung.com>
15 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version 2
23 * of the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
45 #include "maru_device_ids.h"
46 #include "maru_brightness.h"
49 MULTI_DEBUG_CHANNEL(qemu, maru_brightness);
51 #define QEMU_DEV_NAME "MARU_BRIGHTNESS"
53 #define BRIGHTNESS_MEM_SIZE (4 * 1024) /* 4KB */
54 #define BRIGHTNESS_REG_SIZE 256
56 typedef struct BrightnessState {
58 ram_addr_t vram_offset;
59 MemoryRegion mmio_addr;
63 BRIGHTNESS_LEVEL = 0x00,
64 BRIGHTNESS_OFF = 0x04,
67 uint32_t brightness_level = BRIGHTNESS_MAX;
68 uint32_t brightness_off;
70 /* level : 1 ~ 100, interval : 1 or 2 */
71 /* skip 100 level, set to default alpha */
72 uint8_t brightness_tbl[] = {100, /* level 0 : for dimming */
73 /* level 01 ~ 10 */ 106, 108, 109, 111, 112, 114, 115, 117, 118, 120,
74 /* level 11 ~ 20 */ 121, 123, 124, 126, 127, 129, 130, 132, 133, 135,
75 /* level 21 ~ 30 */ 136, 138, 139, 141, 142, 144, 145, 147, 148, 150,
76 /* level 31 ~ 40 */ 151, 153, 154, 156, 157, 159, 160, 162, 163, 165,
77 /* level 41 ~ 50 */ 166, 168, 169, 171, 172, 174, 175, 177, 178, 180,
78 /* level 51 ~ 60 */ 181, 183, 184, 186, 187, 189, 190, 192, 193, 195,
79 /* level 61 ~ 70 */ 196, 198, 199, 201, 202, 204, 205, 207, 208, 210,
80 /* level 71 ~ 80 */ 211, 213, 214, 216, 217, 219, 220, 222, 223, 225,
81 /* level 81 ~ 90 */ 226, 228, 229, 231, 232, 234, 235, 237, 238, 240,
82 /* level 91 ~ 99 */ 241, 243, 244, 246, 247, 249, 250, 252, 253};
84 static uint64_t brightness_reg_read(void *opaque,
85 target_phys_addr_t addr,
88 switch (addr & 0xFF) {
89 case BRIGHTNESS_LEVEL:
90 INFO("brightness_reg_read: brightness_level = %d\n", brightness_level);
91 return brightness_level;
93 INFO("brightness_reg_read: brightness_off = %d\n", brightness_off);
94 return brightness_off;
96 ERR("wrong brightness register read - addr : %d\n", (int)addr);
103 static void brightness_reg_write(void *opaque,
104 target_phys_addr_t addr,
108 switch (addr & 0xFF) {
109 case BRIGHTNESS_LEVEL:
110 #if BRIGHTNESS_MIN > 0
111 if (val < BRIGHTNESS_MIN || val > BRIGHTNESS_MAX) {
113 if (val > BRIGHTNESS_MAX) {
115 ERR("brightness_reg_write: Invalide brightness level.\n");
117 brightness_level = val;
118 INFO("brightness_level : %lld\n", val);
125 INFO("brightness_off : %lld\n", val);
126 brightness_off = val;
132 ERR("wrong brightness register write - addr : %d\n", (int)addr);
137 static const MemoryRegionOps brightness_mmio_ops = {
138 .read = brightness_reg_read,
139 .write = brightness_reg_write,
140 .endianness = DEVICE_LITTLE_ENDIAN,
143 static int brightness_initfn(PCIDevice *dev)
145 BrightnessState *s = DO_UPCAST(BrightnessState, dev, dev);
146 uint8_t *pci_conf = s->dev.config;
148 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_TIZEN);
149 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_VIRTUAL_BRIGHTNESS);
150 pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_OTHER);
152 memory_region_init_io(&s->mmio_addr, &brightness_mmio_ops, s,
153 "maru_brightness_mmio", BRIGHTNESS_REG_SIZE);
154 pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio_addr);
159 /* external interface */
160 int pci_get_brightness(void)
162 return brightness_level;
165 DeviceState *pci_maru_brightness_init(PCIBus *bus)
167 return &pci_create_simple(bus, -1, QEMU_DEV_NAME)->qdev;
170 static void brightness_classinit(ObjectClass *klass, void *data)
172 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
175 k->init = brightness_initfn;
178 static TypeInfo brightness_info = {
179 .name = QEMU_DEV_NAME,
180 .parent = TYPE_PCI_DEVICE,
181 .instance_size = sizeof(BrightnessState),
182 .class_init = brightness_classinit,
185 static void brightness_register_types(void)
187 type_register_static(&brightness_info);
190 type_init(brightness_register_types);