1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Author: Dan Scally <djrscally@gmail.com> */
3 
4 #ifndef _INTEL_SKL_INT3472_H
5 #define _INTEL_SKL_INT3472_H
6 
7 #include <linux/clk-provider.h>
8 #include <linux/gpio/machine.h>
9 #include <linux/leds.h>
10 #include <linux/regulator/driver.h>
11 #include <linux/regulator/machine.h>
12 #include <linux/types.h>
13 
14 /* FIXME drop this once the I2C_DEV_NAME_FORMAT macro has been added to include/linux/i2c.h */
15 #ifndef I2C_DEV_NAME_FORMAT
16 #define I2C_DEV_NAME_FORMAT					"i2c-%s"
17 #endif
18 
19 /* PMIC GPIO Types */
20 #define INT3472_GPIO_TYPE_RESET					0x00
21 #define INT3472_GPIO_TYPE_POWERDOWN				0x01
22 #define INT3472_GPIO_TYPE_POWER_ENABLE				0x0b
23 #define INT3472_GPIO_TYPE_CLK_ENABLE				0x0c
24 #define INT3472_GPIO_TYPE_PRIVACY_LED				0x0d
25 
26 #define INT3472_PDEV_MAX_NAME_LEN				23
27 #define INT3472_MAX_SENSOR_GPIOS				3
28 
29 #define GPIO_REGULATOR_NAME_LENGTH				21
30 #define GPIO_REGULATOR_SUPPLY_NAME_LENGTH			9
31 
32 #define INT3472_LED_MAX_NAME_LEN				32
33 
34 #define CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET			86
35 
36 #define INT3472_REGULATOR(_name, _supply, _ops)			\
37 	(const struct regulator_desc) {				\
38 		.name = _name,					\
39 		.supply_name = _supply,				\
40 		.type = REGULATOR_VOLTAGE,			\
41 		.ops = _ops,					\
42 		.owner = THIS_MODULE,				\
43 	}
44 
45 #define to_int3472_clk(hw)					\
46 	container_of(hw, struct int3472_gpio_clock, clk_hw)
47 
48 #define to_int3472_device(clk)					\
49 	container_of(clk, struct int3472_discrete_device, clock)
50 
51 struct acpi_device;
52 struct i2c_client;
53 struct platform_device;
54 
55 struct int3472_cldb {
56 	u8 version;
57 	/*
58 	 * control logic type
59 	 * 0: UNKNOWN
60 	 * 1: DISCRETE(CRD-D)
61 	 * 2: PMIC TPS68470
62 	 * 3: PMIC uP6641
63 	 */
64 	u8 control_logic_type;
65 	u8 control_logic_id;
66 	u8 sensor_card_sku;
67 	u8 reserved[28];
68 };
69 
70 struct int3472_gpio_function_remap {
71 	const char *documented;
72 	const char *actual;
73 };
74 
75 struct int3472_sensor_config {
76 	const char *sensor_module_name;
77 	struct regulator_consumer_supply supply_map;
78 	const struct int3472_gpio_function_remap *function_maps;
79 };
80 
81 struct int3472_discrete_device {
82 	struct acpi_device *adev;
83 	struct device *dev;
84 	struct acpi_device *sensor;
85 	const char *sensor_name;
86 
87 	const struct int3472_sensor_config *sensor_config;
88 
89 	struct int3472_gpio_regulator {
90 		char regulator_name[GPIO_REGULATOR_NAME_LENGTH];
91 		char supply_name[GPIO_REGULATOR_SUPPLY_NAME_LENGTH];
92 		struct gpio_desc *gpio;
93 		struct regulator_dev *rdev;
94 		struct regulator_desc rdesc;
95 	} regulator;
96 
97 	struct int3472_gpio_clock {
98 		struct clk *clk;
99 		struct clk_hw clk_hw;
100 		struct clk_lookup *cl;
101 		struct gpio_desc *ena_gpio;
102 		u32 frequency;
103 	} clock;
104 
105 	struct int3472_pled {
106 		struct led_classdev classdev;
107 		struct led_lookup_data lookup;
108 		char name[INT3472_LED_MAX_NAME_LEN];
109 		struct gpio_desc *gpio;
110 	} pled;
111 
112 	unsigned int ngpios; /* how many GPIOs have we seen */
113 	unsigned int n_sensor_gpios; /* how many have we mapped to sensor */
114 	struct gpiod_lookup_table gpios;
115 };
116 
117 union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
118 					       char *id);
119 int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
120 int skl_int3472_get_sensor_adev_and_name(struct device *dev,
121 					 struct acpi_device **sensor_adev_ret,
122 					 const char **name_ret);
123 
124 int skl_int3472_register_clock(struct int3472_discrete_device *int3472,
125 			       struct acpi_resource_gpio *agpio, u32 polarity);
126 void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472);
127 
128 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
129 				   struct acpi_resource_gpio *agpio);
130 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472);
131 
132 int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
133 			      struct acpi_resource_gpio *agpio, u32 polarity);
134 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472);
135 
136 #endif
137