2 * Qemu brightness emulator
4 * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * DoHyung Hong <don.hong@samsung.com>
8 * SeokYeon Hwang <syeon.hwang@samsung.com>
9 * Hyunjun Son <hj79.son@samsung.com>
10 * SangJin Kim <sangjin3.kim@samsung.com>
11 * MunKyu Im <munkyu.im@samsung.com>
12 * KiTae Kim <kt920.kim@samsung.com>
13 * JinHyung Jo <jinhyung.jo@samsung.com>
14 * SungMin Ha <sungmin82.ha@samsung.com>
15 * JiHye Kim <jihye1128.kim@samsung.com>
16 * GiWoong Kim <giwoong.kim@samsung.com>
17 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
18 * DongKyun Yun <dk77.yun@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.
44 #define QEMU_DEV_NAME "brightness"
46 #define BRIGHTNESS_MEM_SIZE (4 * 1024) /* 4KB */
47 #define BRIGHTNESS_REG_SIZE 256
49 #define BRIGHTNESS_MIN (0)
50 #define BRIGHTNESS_MAX (24)
52 typedef struct BrightnessState {
56 int brightness_mmio_io_addr;
58 uint32_t ioport_addr; // guest addr
59 uint32_t mmio_addr; // guest addr
63 BRIGHTNESS_LEVEL = 0x00,
64 BRIGHTNESS_OFF = 0x04,
67 //uint8_t* brightness_ptr; // pointer in qemu space
68 uint32_t brightness_level = 24;
69 uint32_t brightness_off = 0;
71 //#define DEBUG_BRIGHTNESS
73 #if defined (DEBUG_BRIGHTNESS)
74 # define DEBUG_PRINT(x) do { printf x ; } while (0)
76 # define DEBUG_PRINT(x)
79 static uint32_t brightness_reg_read(void *opaque, target_phys_addr_t addr)
81 switch (addr & 0xFF) {
82 case BRIGHTNESS_LEVEL:
83 DEBUG_PRINT(("brightness_reg_read: brightness_level = %d\n", brightness_level));
84 return brightness_level;
87 fprintf(stderr, "wrong brightness register read - addr : %d\n", addr);
93 static void brightness_reg_write(void *opaque, target_phys_addr_t addr, uint32_t val)
95 DEBUG_PRINT(("brightness_reg_write: addr = %d, val = %d\n", addr, val));
97 #if BRIGHTNESS_MIN > 0
98 if (val < BRIGHTNESS_MIN || val > BRIGHTNESS_MAX) {
100 if (val > BRIGHTNESS_MAX) {
102 fprintf(stderr, "brightness_reg_write: Invalide brightness level.\n");
105 switch (addr & 0xFF) {
106 case BRIGHTNESS_LEVEL:
107 brightness_level = val;
110 DEBUG_PRINT(("Brightness off : %d\n", val));
111 brightness_off = val;
114 fprintf(stderr, "wrong brightness register write - addr : %d\n", addr);
118 static CPUReadMemoryFunc * const brightness_reg_readfn[3] = {
124 static CPUWriteMemoryFunc * const brightness_reg_writefn[3] = {
125 brightness_reg_write,
126 brightness_reg_write,
127 brightness_reg_write,
131 static void brightness_ioport_map(PCIDevice *dev, int region_num,
132 pcibus_t addr, pcibus_t size, int type)
134 //BrightnessState *s = DO_UPCAST(BrightnessState, dev, dev);
136 //cpu_register_physical_memory(addr, BRIGHTNESS_MEM_SIZE,
139 //s->ioport_addr = addr;
143 static void brightness_mmio_map(PCIDevice *dev, int region_num,
144 pcibus_t addr, pcibus_t size, int type)
146 BrightnessState *s = DO_UPCAST(BrightnessState, dev, dev);
148 cpu_register_physical_memory(addr, BRIGHTNESS_REG_SIZE,
149 s->brightness_mmio_io_addr);
154 static int brightness_initfn(PCIDevice *dev)
156 BrightnessState *s = DO_UPCAST(BrightnessState, dev, dev);
157 uint8_t *pci_conf = s->dev.config;
159 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_TIZEN);
160 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_VIRTUAL_BRIGHTNESS);
161 pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_OTHER);
163 //s->offset = qemu_ram_alloc(NULL, "brightness", BRIGHTNESS_MEM_SIZE);
164 //brightness_ptr = qemu_get_ram_ptr(s->offset);
166 s->brightness_mmio_io_addr = cpu_register_io_memory(brightness_reg_readfn,
167 brightness_reg_writefn, s,
168 DEVICE_LITTLE_ENDIAN);
170 /* setup memory space */
171 /* memory #0 device memory (overlay surface) */
172 /* memory #1 memory-mapped I/O */
173 //pci_register_bar(&s->dev, 0, BRIGHTNESS_MEM_SIZE,
174 // PCI_BASE_ADDRESS_SPACE_IO, brightness_ioport_map);
176 pci_register_bar(&s->dev, 1, BRIGHTNESS_REG_SIZE,
177 PCI_BASE_ADDRESS_SPACE_MEMORY, brightness_mmio_map);
182 /* external interface */
183 int pci_get_brightness(void)
185 return brightness_level;
188 int pci_brightness_init(PCIBus *bus)
190 pci_create_simple(bus, -1, QEMU_DEV_NAME);
194 static PCIDeviceInfo brightness_info = {
195 .qdev.name = QEMU_DEV_NAME,
196 .qdev.size = sizeof(BrightnessState),
198 .init = brightness_initfn,
201 static void brightness_register(void)
203 pci_qdev_register(&brightness_info);
206 device_init(brightness_register);