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