1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Intel INT3472 ACPI camera sensor power-management support 4 * 5 * Author: Dan Scally <djrscally@gmail.com> 6 */ 7 8 #ifndef __PLATFORM_DATA_X86_INT3472_H 9 #define __PLATFORM_DATA_X86_INT3472_H 10 11 #include <linux/clk-provider.h> 12 #include <linux/gpio/machine.h> 13 #include <linux/leds.h> 14 #include <linux/regulator/driver.h> 15 #include <linux/regulator/machine.h> 16 #include <linux/types.h> 17 18 /* FIXME drop this once the I2C_DEV_NAME_FORMAT macro has been added to include/linux/i2c.h */ 19 #ifndef I2C_DEV_NAME_FORMAT 20 #define I2C_DEV_NAME_FORMAT "i2c-%s" 21 #endif 22 23 /* PMIC GPIO Types */ 24 #define INT3472_GPIO_TYPE_RESET 0x00 25 #define INT3472_GPIO_TYPE_POWERDOWN 0x01 26 #define INT3472_GPIO_TYPE_POWER_ENABLE 0x0b 27 #define INT3472_GPIO_TYPE_CLK_ENABLE 0x0c 28 #define INT3472_GPIO_TYPE_PRIVACY_LED 0x0d 29 #define INT3472_GPIO_TYPE_HANDSHAKE 0x12 30 #define INT3472_GPIO_TYPE_HOTPLUG_DETECT 0x13 31 32 #define INT3472_PDEV_MAX_NAME_LEN 23 33 #define INT3472_MAX_SENSOR_GPIOS 3 34 #define INT3472_MAX_REGULATORS 3 35 36 /* E.g. "avdd\0" */ 37 #define GPIO_SUPPLY_NAME_LENGTH 5 38 /* 12 chars for acpi_dev_name() + "-", e.g. "ABCD1234:00-" */ 39 #define GPIO_REGULATOR_NAME_LENGTH (12 + GPIO_SUPPLY_NAME_LENGTH) 40 /* lower- and upper-case mapping */ 41 #define GPIO_REGULATOR_SUPPLY_MAP_COUNT 2 42 /* 43 * Ensure the GPIO is driven low/high for at least 2 ms before changing. 44 * 45 * 2 ms has been chosen because it is the minimum time ovXXXX sensors need to 46 * have their reset line driven logical high to properly register a reset. 47 */ 48 #define GPIO_REGULATOR_ENABLE_TIME (2 * USEC_PER_MSEC) 49 #define GPIO_REGULATOR_OFF_ON_DELAY (2 * USEC_PER_MSEC) 50 51 #define INT3472_LED_MAX_NAME_LEN 32 52 53 #define CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET 86 54 55 #define INT3472_REGULATOR(_name, _ops, _enable_time, _off_on_delay) \ 56 (const struct regulator_desc) { \ 57 .name = _name, \ 58 .type = REGULATOR_VOLTAGE, \ 59 .ops = _ops, \ 60 .owner = THIS_MODULE, \ 61 .enable_time = _enable_time, \ 62 .off_on_delay = _off_on_delay, \ 63 } 64 65 #define to_int3472_clk(hw) \ 66 container_of(hw, struct int3472_clock, clk_hw) 67 68 #define to_int3472_device(clk) \ 69 container_of(clk, struct int3472_discrete_device, clock) 70 71 struct acpi_device; 72 struct dmi_system_id; 73 struct i2c_client; 74 struct platform_device; 75 76 struct int3472_cldb { 77 u8 version; 78 /* 79 * control logic type 80 * 0: UNKNOWN 81 * 1: DISCRETE(CRD-D) 82 * 2: PMIC TPS68470 83 * 3: PMIC uP6641 84 */ 85 u8 control_logic_type; 86 u8 control_logic_id; 87 u8 sensor_card_sku; 88 u8 reserved[10]; 89 u8 clock_source; 90 u8 reserved2[17]; 91 }; 92 93 struct int3472_discrete_quirks { 94 /* For models where AVDD GPIO is shared between sensors */ 95 const char *avdd_second_sensor; 96 }; 97 98 struct int3472_gpio_regulator { 99 /* SUPPLY_MAP_COUNT * 2 to make room for second sensor mappings */ 100 struct regulator_consumer_supply supply_map[GPIO_REGULATOR_SUPPLY_MAP_COUNT * 2]; 101 char supply_name_upper[GPIO_SUPPLY_NAME_LENGTH]; 102 char regulator_name[GPIO_REGULATOR_NAME_LENGTH]; 103 struct gpio_desc *ena_gpio; 104 struct regulator_dev *rdev; 105 struct regulator_desc rdesc; 106 }; 107 108 struct int3472_discrete_device { 109 struct acpi_device *adev; 110 struct device *dev; 111 struct acpi_device *sensor; 112 const char *sensor_name; 113 114 struct int3472_gpio_regulator regulators[INT3472_MAX_REGULATORS]; 115 116 struct int3472_clock { 117 struct clk *clk; 118 struct clk_hw clk_hw; 119 struct clk_lookup *cl; 120 struct gpio_desc *ena_gpio; 121 u32 frequency; 122 u8 imgclk_index; 123 } clock; 124 125 struct int3472_pled { 126 struct led_classdev classdev; 127 struct led_lookup_data lookup; 128 char name[INT3472_LED_MAX_NAME_LEN]; 129 struct gpio_desc *gpio; 130 } pled; 131 132 struct int3472_discrete_quirks quirks; 133 134 unsigned int ngpios; /* how many GPIOs have we seen */ 135 unsigned int n_sensor_gpios; /* how many have we mapped to sensor */ 136 unsigned int n_regulator_gpios; /* how many have we mapped to a regulator */ 137 struct gpiod_lookup_table gpios; 138 }; 139 140 extern const struct dmi_system_id skl_int3472_discrete_quirks[]; 141 142 union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, 143 char *id); 144 int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb); 145 int skl_int3472_get_sensor_adev_and_name(struct device *dev, 146 struct acpi_device **sensor_adev_ret, 147 const char **name_ret); 148 149 int int3472_discrete_parse_crs(struct int3472_discrete_device *int3472); 150 void int3472_discrete_cleanup(struct int3472_discrete_device *int3472); 151 152 int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, 153 struct gpio_desc *gpio); 154 int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472); 155 void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472); 156 157 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472, 158 struct gpio_desc *gpio, 159 unsigned int enable_time, 160 const char *supply_name, 161 const char *second_sensor); 162 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472); 163 164 int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio); 165 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472); 166 167 #endif 168