1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ANALOG_HEADSET_H 17 #define ANALOG_HEADSET_H 18 19 #include <linux/gpio.h> 20 #include <linux/of_gpio.h> 21 #include "analog_headset_ev.h" 22 #include "audio_device_log.h" 23 #include "hdf_base.h" 24 #include "hdf_device_desc.h" 25 #include "platform_if.h" 26 27 #define HDF_HEADSET_WORK_QUEUE_NAME "hdf_headset_work_queue" 28 #define HEADSET 0 29 #define HOOK 1 30 #define HS_HOOK_COUNT 2 31 32 #define HEADSET_IN_HIGH 0x00000001 33 #define HEADSET_IN_LOW 0x00000000 34 35 #define HOOK_DOWN_HIGH 0x00000001 36 #define HOOK_DOWN_LOW 0x00000000 37 38 #define LEVEL_IN_HIGH 1 39 #define LEVEL_IN_LOW 0 40 41 #define DELAY_WORK_MS10 10 42 #define DELAY_WORK_MS50 50 43 #define DELAY_WORK_MS100 100 44 #define DELAY_WORK_MS200 200 45 #define DELAY_WORK_MS500 500 46 47 #define IRQ_CONFIRM_MS1 1 48 #define IRQ_CONFIRM_MS100 100 49 #define IRQ_CONFIRM_MS150 150 50 51 #define BIT_HEADSET_NULL 0 52 #define BIT_HEADSET 1 53 #define BIT_HEADSET_NO_MIC 2 54 55 #define GET_GPIO_REPEAT_TIMES 3 56 #define TIMER_EXPIRES_JIFFIES 100 57 58 struct AdcCtrlConfig { 59 DevHandle handle; 60 uint32_t devNum; 61 uint32_t chanNo; 62 }; 63 64 struct HeadsetPdata { 65 struct IDeviceIoService ioService; 66 struct HdfDeviceObject *device; 67 uint32_t devType; 68 const char *devName; 69 /* heaset about */ 70 uint32_t hsGpio; 71 enum of_gpio_flags hsGpioFlags; 72 /* Headphones into the state level */ 73 uint32_t hsInsertType; 74 uint32_t hsGpioFlag; 75 bool isHookAdcMode; 76 /* hook about */ 77 uint32_t hookGpio; 78 /* Hook key down status */ 79 uint32_t hookDownType; 80 #ifdef CONFIG_MODEM_MIC_SWITCH 81 /* mic about */ 82 enum of_gpio_flags micGpioFlags; 83 uint32_t micSwitchGpio; 84 uint32_t hpMicIoValue; 85 uint32_t mainMicIoValue; 86 #endif 87 struct iio_channel *chan; 88 struct AdcCtrlConfig adcConfig; 89 bool hsWakeup; 90 }; 91 92 #define HOOK_KEY_CODE 226 // KEY_MEDIA 93 94 int32_t AnalogHeadsetGpioInit(struct platform_device *pdev, struct HeadsetPdata *pdata); 95 void AnalogHeadsetGpioRelease(struct HeadsetPdata *pdata); 96 int32_t AnalogHeadsetAdcInit(struct platform_device *pdev, struct HeadsetPdata *pdata); 97 void AnalogHeadsetAdcRelease(struct HeadsetPdata *pdata); 98 int AnalogHeadsetAdcSuspend(struct platform_device *pdev, pm_message_t state); 99 int AnalogHeadsetAdcResume(struct platform_device *pdev); 100 #endif 101