1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#ifndef _IOKIT_IODISPLAY_H
24#define _IOKIT_IODISPLAY_H
25
26#include <IOKit/IOService.h>
27#include <IOKit/graphics/IOFramebuffer.h>
28
29extern const OSSymbol * gIODisplayParametersKey;
30extern const OSSymbol * gIODisplayGUIDKey;
31
32extern const OSSymbol * gIODisplayValueKey;
33extern const OSSymbol * gIODisplayMinValueKey;
34extern const OSSymbol * gIODisplayMaxValueKey;
35
36extern const OSSymbol * gIODisplayContrastKey;
37extern const OSSymbol * gIODisplayBrightnessKey;
38extern const OSSymbol * gIODisplayLinearBrightnessKey;
39extern const OSSymbol * gIODisplayUsableLinearBrightnessKey;
40extern const OSSymbol * gIODisplayBrightnessFadeKey;
41extern const OSSymbol * gIODisplayHorizontalPositionKey;
42extern const OSSymbol * gIODisplayHorizontalSizeKey;
43extern const OSSymbol * gIODisplayVerticalPositionKey;
44extern const OSSymbol * gIODisplayVerticalSizeKey;
45extern const OSSymbol * gIODisplayTrapezoidKey;
46extern const OSSymbol * gIODisplayPincushionKey;
47extern const OSSymbol * gIODisplayParallelogramKey;
48extern const OSSymbol * gIODisplayRotationKey;
49extern const OSSymbol * gIODisplayOverscanKey;
50extern const OSSymbol * gIODisplayVideoBestKey;
51extern const OSSymbol * gIODisplaySelectedColorModeKey;
52
53extern const OSSymbol * gIODisplayRedGammaScaleKey;
54extern const OSSymbol * gIODisplayGreenGammaScaleKey;
55extern const OSSymbol * gIODisplayBlueGammaScaleKey;
56extern const OSSymbol * gIODisplayGammaScaleKey;
57
58extern const OSSymbol * gIODisplayParametersTheatreModeKey;
59extern const OSSymbol * gIODisplayParametersTheatreModeWindowKey;
60
61extern const OSSymbol * gIODisplayMCCSVersionKey;
62extern const OSSymbol * gIODisplayTechnologyTypeKey;
63extern const OSSymbol * gIODisplayUsageTimeKey;
64extern const OSSymbol * gIODisplayFirmwareLevelKey;
65
66extern const OSSymbol * gIODisplaySpeakerVolumeKey;
67extern const OSSymbol * gIODisplaySpeakerSelectKey;
68extern const OSSymbol * gIODisplayMicrophoneVolumeKey;
69extern const OSSymbol * gIODisplayAmbientLightSensorKey;
70extern const OSSymbol * gIODisplayAudioMuteAndScreenBlankKey;
71extern const OSSymbol * gIODisplayAudioTrebleKey;
72extern const OSSymbol * gIODisplayAudioBassKey;
73extern const OSSymbol * gIODisplayAudioBalanceLRKey;
74extern const OSSymbol * gIODisplayAudioProcessorModeKey;
75extern const OSSymbol * gIODisplayPowerModeKey;
76extern const OSSymbol * gIODisplayManufacturerSpecificKey;
77
78extern const OSSymbol * gIODisplayPowerStateKey;
79extern const OSSymbol * gIODisplayControllerIDKey;
80extern const OSSymbol * gIODisplayCapabilityStringKey;
81
82extern const OSSymbol * gIODisplayParametersCommitKey;
83extern const OSSymbol * gIODisplayParametersDefaultKey;
84extern const OSSymbol * gIODisplayParametersFlushKey;
85
86extern const OSSymbol * gIODisplayFadeTime1Key;
87extern const OSSymbol * gIODisplayFadeTime2Key;
88extern const OSSymbol * gIODisplayFadeTime3Key;
89extern const OSSymbol * gIODisplayFadeStyleKey;
90
91extern UInt32 gIODisplayFadeTime1;
92extern UInt32 gIODisplayFadeTime2;
93extern UInt32 gIODisplayFadeTime3;
94extern UInt32 gIODisplayFadeStyle;
95
96enum {
97    kIODisplayNumPowerStates = 4,
98    kIODisplayMaxPowerState  = kIODisplayNumPowerStates - 1
99};
100
101class IODisplayConnect : public IOService
102{
103    OSDeclareDefaultStructors(IODisplayConnect)
104
105private:
106    IOIndex     connection;
107
108protected:
109/*  Reserved for future use.  (Internal use only)  */
110    struct ExpansionData { };
111
112/*  Reserved for future use.  (Internal use only)  */
113    ExpansionData * reserved;
114
115public:
116    virtual bool initWithConnection( IOIndex connection );
117    virtual IOFramebuffer * getFramebuffer( void );
118    virtual IOIndex getConnection( void );
119    virtual IOReturn getAttributeForConnection( IOSelect selector, uintptr_t * value );
120    virtual IOReturn setAttributeForConnection( IOSelect selector, uintptr_t value );
121    virtual void joinPMtree ( IOService * driver );
122};
123
124class IODisplay : public IOService
125{
126    OSDeclareAbstractStructors(IODisplay)
127
128public:
129    static void initialize( void );
130
131protected:
132    // used to query the framebuffer controller
133    IODisplayConnect *                  fConnection;
134    class IODisplayParameterHandler *   fParameterHandler;
135    void *                      __resv;
136    IONotifier *                        fNotifier;
137
138    // pointer to protected instance variables for power management
139    struct IODisplayPMVars *              fDisplayPMVars;
140
141    // reserved for future expansion
142    void *                              _IODisplay_reserved[32];
143
144public:
145    virtual IOService * probe(  IOService *     provider,
146                                SInt32 *        score );
147
148    virtual bool start( IOService * provider );
149    virtual void stop( IOService * provider );
150    virtual void free();
151
152    virtual IODisplayConnect * getConnection( void );
153
154    virtual IOReturn getConnectFlagsForDisplayMode(
155                IODisplayModeID mode, UInt32 * flags );
156
157    virtual IOReturn getGammaTableByIndex(
158        UInt32 * channelCount, UInt32 * dataCount,
159        UInt32 * dataWidth, void ** data );
160
161    virtual IOReturn readFramebufferEDID( void );
162
163    //
164    virtual IOReturn framebufferEvent( IOFramebuffer * framebuffer,
165                                        IOIndex event, void * info );
166
167    // parameter setting
168    virtual IOReturn setProperties( OSObject * properties );
169    virtual bool setForKey( OSDictionary * params, const OSSymbol * key,
170                            SInt32 value, SInt32 min, SInt32 max );
171
172    static bool addParameter( OSDictionary * params, const OSSymbol * paramName, SInt32 min, SInt32 max );
173    static bool setParameter( OSDictionary * params, const OSSymbol * paramName, SInt32 value );
174    static OSDictionary * getIntegerRange( OSDictionary * params, const OSSymbol * sym,
175                                      SInt32 * value, SInt32 * min, SInt32 * max );
176
177    // low level set/get
178    virtual bool doIntegerSet( OSDictionary * params,
179                               const OSSymbol * paramName, UInt32 value );
180    virtual bool doDataSet( const OSSymbol * paramName, OSData * value );
181    virtual bool doUpdate( void );
182
183    // power management methods
184    virtual IOReturn setPowerState( unsigned long, IOService * );
185    virtual unsigned long maxCapabilityForDomainState( IOPMPowerFlags );
186    virtual unsigned long initialPowerStateForDomainState( IOPMPowerFlags );
187    virtual unsigned long powerStateForDomainState( IOPMPowerFlags );
188
189    //
190    virtual void initPowerManagement( IOService * provider);
191    virtual void dropOneLevel( void );
192    virtual void makeDisplayUsable( void );
193    void setDisplayPowerState(unsigned long state);
194
195private:
196    OSMetaClassDeclareReservedUnused(IODisplay, 0);
197    OSMetaClassDeclareReservedUnused(IODisplay, 1);
198    OSMetaClassDeclareReservedUnused(IODisplay, 2);
199    OSMetaClassDeclareReservedUnused(IODisplay, 3);
200    OSMetaClassDeclareReservedUnused(IODisplay, 4);
201    OSMetaClassDeclareReservedUnused(IODisplay, 5);
202    OSMetaClassDeclareReservedUnused(IODisplay, 6);
203    OSMetaClassDeclareReservedUnused(IODisplay, 7);
204    OSMetaClassDeclareReservedUnused(IODisplay, 8);
205    OSMetaClassDeclareReservedUnused(IODisplay, 9);
206    OSMetaClassDeclareReservedUnused(IODisplay, 10);
207    OSMetaClassDeclareReservedUnused(IODisplay, 11);
208    OSMetaClassDeclareReservedUnused(IODisplay, 12);
209    OSMetaClassDeclareReservedUnused(IODisplay, 13);
210    OSMetaClassDeclareReservedUnused(IODisplay, 14);
211    OSMetaClassDeclareReservedUnused(IODisplay, 15);
212    OSMetaClassDeclareReservedUnused(IODisplay, 16);
213    OSMetaClassDeclareReservedUnused(IODisplay, 17);
214    OSMetaClassDeclareReservedUnused(IODisplay, 18);
215    OSMetaClassDeclareReservedUnused(IODisplay, 19);
216
217private:
218    static IOReturn _framebufferEvent( OSObject * self, void * ref,
219                    IOFramebuffer *framebuffer, IOIndex event, void * info );
220
221	void searchParameterHandlers(IORegistryEntry * entry);
222    bool addParameterHandler( IODisplayParameterHandler * parameterHandler );
223    bool removeParameterHandler( IODisplayParameterHandler * parameterHandler );
224    static bool updateNumber( OSDictionary * params, const OSSymbol * key, SInt32 value );
225};
226
227/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
228
229class IOBacklightDisplay : public IODisplay
230{
231    OSDeclareDefaultStructors(IOBacklightDisplay)
232
233    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 0);
234    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 1);
235    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 2);
236    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 3);
237    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 4);
238    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 5);
239    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 6);
240    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 7);
241    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 8);
242    OSMetaClassDeclareReservedUnused(IOBacklightDisplay, 9);
243};
244
245/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
246
247class IODisplayParameterHandler : public IOService
248{
249    OSDeclareDefaultStructors(IODisplayParameterHandler)
250
251public:
252    virtual bool setDisplay( IODisplay * display ) = 0;
253    virtual bool doIntegerSet( OSDictionary * params,
254                               const OSSymbol * paramName, UInt32 value ) = 0;
255    virtual bool doDataSet( const OSSymbol * paramName, OSData * value ) = 0;
256    virtual bool doUpdate( void ) = 0;
257
258private:
259    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 0);
260    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 1);
261    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 2);
262    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 3);
263    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 4);
264    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 5);
265    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 6);
266    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 7);
267    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 8);
268    OSMetaClassDeclareReservedUnused(IODisplayParameterHandler, 9);
269};
270
271/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
272
273#endif /* ! _IOKIT_IODISPLAY_H */
274
275