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