162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Author: Dan Scally <djrscally@gmail.com> */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#ifndef _INTEL_SKL_INT3472_H 562306a36Sopenharmony_ci#define _INTEL_SKL_INT3472_H 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/clk-provider.h> 862306a36Sopenharmony_ci#include <linux/gpio/machine.h> 962306a36Sopenharmony_ci#include <linux/leds.h> 1062306a36Sopenharmony_ci#include <linux/regulator/driver.h> 1162306a36Sopenharmony_ci#include <linux/regulator/machine.h> 1262306a36Sopenharmony_ci#include <linux/types.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* FIXME drop this once the I2C_DEV_NAME_FORMAT macro has been added to include/linux/i2c.h */ 1562306a36Sopenharmony_ci#ifndef I2C_DEV_NAME_FORMAT 1662306a36Sopenharmony_ci#define I2C_DEV_NAME_FORMAT "i2c-%s" 1762306a36Sopenharmony_ci#endif 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* PMIC GPIO Types */ 2062306a36Sopenharmony_ci#define INT3472_GPIO_TYPE_RESET 0x00 2162306a36Sopenharmony_ci#define INT3472_GPIO_TYPE_POWERDOWN 0x01 2262306a36Sopenharmony_ci#define INT3472_GPIO_TYPE_POWER_ENABLE 0x0b 2362306a36Sopenharmony_ci#define INT3472_GPIO_TYPE_CLK_ENABLE 0x0c 2462306a36Sopenharmony_ci#define INT3472_GPIO_TYPE_PRIVACY_LED 0x0d 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define INT3472_PDEV_MAX_NAME_LEN 23 2762306a36Sopenharmony_ci#define INT3472_MAX_SENSOR_GPIOS 3 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#define GPIO_REGULATOR_NAME_LENGTH 21 3062306a36Sopenharmony_ci#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9 3162306a36Sopenharmony_ci#define GPIO_REGULATOR_SUPPLY_MAP_COUNT 2 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define INT3472_LED_MAX_NAME_LEN 32 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET 86 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define INT3472_REGULATOR(_name, _supply, _ops) \ 3862306a36Sopenharmony_ci (const struct regulator_desc) { \ 3962306a36Sopenharmony_ci .name = _name, \ 4062306a36Sopenharmony_ci .supply_name = _supply, \ 4162306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 4262306a36Sopenharmony_ci .ops = _ops, \ 4362306a36Sopenharmony_ci .owner = THIS_MODULE, \ 4462306a36Sopenharmony_ci } 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define to_int3472_clk(hw) \ 4762306a36Sopenharmony_ci container_of(hw, struct int3472_clock, clk_hw) 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#define to_int3472_device(clk) \ 5062306a36Sopenharmony_ci container_of(clk, struct int3472_discrete_device, clock) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistruct acpi_device; 5362306a36Sopenharmony_cistruct i2c_client; 5462306a36Sopenharmony_cistruct platform_device; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_cistruct int3472_cldb { 5762306a36Sopenharmony_ci u8 version; 5862306a36Sopenharmony_ci /* 5962306a36Sopenharmony_ci * control logic type 6062306a36Sopenharmony_ci * 0: UNKNOWN 6162306a36Sopenharmony_ci * 1: DISCRETE(CRD-D) 6262306a36Sopenharmony_ci * 2: PMIC TPS68470 6362306a36Sopenharmony_ci * 3: PMIC uP6641 6462306a36Sopenharmony_ci */ 6562306a36Sopenharmony_ci u8 control_logic_type; 6662306a36Sopenharmony_ci u8 control_logic_id; 6762306a36Sopenharmony_ci u8 sensor_card_sku; 6862306a36Sopenharmony_ci u8 reserved[10]; 6962306a36Sopenharmony_ci u8 clock_source; 7062306a36Sopenharmony_ci u8 reserved2[17]; 7162306a36Sopenharmony_ci}; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cistruct int3472_discrete_device { 7462306a36Sopenharmony_ci struct acpi_device *adev; 7562306a36Sopenharmony_ci struct device *dev; 7662306a36Sopenharmony_ci struct acpi_device *sensor; 7762306a36Sopenharmony_ci const char *sensor_name; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci const struct int3472_sensor_config *sensor_config; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci struct int3472_gpio_regulator { 8262306a36Sopenharmony_ci /* SUPPLY_MAP_COUNT * 2 to make room for second sensor mappings */ 8362306a36Sopenharmony_ci struct regulator_consumer_supply supply_map[GPIO_REGULATOR_SUPPLY_MAP_COUNT * 2]; 8462306a36Sopenharmony_ci char regulator_name[GPIO_REGULATOR_NAME_LENGTH]; 8562306a36Sopenharmony_ci char supply_name[GPIO_REGULATOR_SUPPLY_NAME_LENGTH]; 8662306a36Sopenharmony_ci struct gpio_desc *gpio; 8762306a36Sopenharmony_ci struct regulator_dev *rdev; 8862306a36Sopenharmony_ci struct regulator_desc rdesc; 8962306a36Sopenharmony_ci } regulator; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci struct int3472_clock { 9262306a36Sopenharmony_ci struct clk *clk; 9362306a36Sopenharmony_ci struct clk_hw clk_hw; 9462306a36Sopenharmony_ci struct clk_lookup *cl; 9562306a36Sopenharmony_ci struct gpio_desc *ena_gpio; 9662306a36Sopenharmony_ci u32 frequency; 9762306a36Sopenharmony_ci u8 imgclk_index; 9862306a36Sopenharmony_ci } clock; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci struct int3472_pled { 10162306a36Sopenharmony_ci struct led_classdev classdev; 10262306a36Sopenharmony_ci struct led_lookup_data lookup; 10362306a36Sopenharmony_ci char name[INT3472_LED_MAX_NAME_LEN]; 10462306a36Sopenharmony_ci struct gpio_desc *gpio; 10562306a36Sopenharmony_ci } pled; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci unsigned int ngpios; /* how many GPIOs have we seen */ 10862306a36Sopenharmony_ci unsigned int n_sensor_gpios; /* how many have we mapped to sensor */ 10962306a36Sopenharmony_ci struct gpiod_lookup_table gpios; 11062306a36Sopenharmony_ci}; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciunion acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, 11362306a36Sopenharmony_ci char *id); 11462306a36Sopenharmony_ciint skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb); 11562306a36Sopenharmony_ciint skl_int3472_get_sensor_adev_and_name(struct device *dev, 11662306a36Sopenharmony_ci struct acpi_device **sensor_adev_ret, 11762306a36Sopenharmony_ci const char **name_ret); 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ciint skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472, 12062306a36Sopenharmony_ci struct acpi_resource_gpio *agpio, u32 polarity); 12162306a36Sopenharmony_ciint skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472); 12262306a36Sopenharmony_civoid skl_int3472_unregister_clock(struct int3472_discrete_device *int3472); 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciint skl_int3472_register_regulator(struct int3472_discrete_device *int3472, 12562306a36Sopenharmony_ci struct acpi_resource_gpio *agpio); 12662306a36Sopenharmony_civoid skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472); 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciint skl_int3472_register_pled(struct int3472_discrete_device *int3472, 12962306a36Sopenharmony_ci struct acpi_resource_gpio *agpio, u32 polarity); 13062306a36Sopenharmony_civoid skl_int3472_unregister_pled(struct int3472_discrete_device *int3472); 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#endif 133