xref: /linux/drivers/gpu/drm/amd/display/dc/gpio/hw_gpio.h (revision 0e1c42fd)
14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2012-15 Advanced Micro Devices, Inc.
34562236bSHarry Wentland  *
44562236bSHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
54562236bSHarry Wentland  * copy of this software and associated documentation files (the "Software"),
64562236bSHarry Wentland  * to deal in the Software without restriction, including without limitation
74562236bSHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
84562236bSHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
94562236bSHarry Wentland  * Software is furnished to do so, subject to the following conditions:
104562236bSHarry Wentland  *
114562236bSHarry Wentland  * The above copyright notice and this permission notice shall be included in
124562236bSHarry Wentland  * all copies or substantial portions of the Software.
134562236bSHarry Wentland  *
144562236bSHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154562236bSHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164562236bSHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
174562236bSHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
184562236bSHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
194562236bSHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
204562236bSHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
214562236bSHarry Wentland  *
224562236bSHarry Wentland  * Authors: AMD
234562236bSHarry Wentland  *
244562236bSHarry Wentland  */
254562236bSHarry Wentland 
264562236bSHarry Wentland #ifndef __DAL_HW_GPIO_H__
274562236bSHarry Wentland #define __DAL_HW_GPIO_H__
284562236bSHarry Wentland 
294562236bSHarry Wentland #include "gpio_regs.h"
304562236bSHarry Wentland 
314562236bSHarry Wentland #define FROM_HW_GPIO_PIN(ptr) \
324562236bSHarry Wentland 	container_of((ptr), struct hw_gpio, base)
334562236bSHarry Wentland 
344562236bSHarry Wentland struct addr_mask {
354562236bSHarry Wentland 	uint32_t addr;
364562236bSHarry Wentland 	uint32_t mask;
374562236bSHarry Wentland };
384562236bSHarry Wentland 
394562236bSHarry Wentland struct hw_gpio_pin {
404562236bSHarry Wentland 	const struct hw_gpio_pin_funcs *funcs;
414562236bSHarry Wentland 	enum gpio_id id;
424562236bSHarry Wentland 	uint32_t en;
434562236bSHarry Wentland 	enum gpio_mode mode;
444562236bSHarry Wentland 	bool opened;
454562236bSHarry Wentland 	struct dc_context *ctx;
464562236bSHarry Wentland };
474562236bSHarry Wentland 
484562236bSHarry Wentland struct hw_gpio_pin_funcs {
494562236bSHarry Wentland 	void (*destroy)(
504562236bSHarry Wentland 		struct hw_gpio_pin **ptr);
514562236bSHarry Wentland 	bool (*open)(
524562236bSHarry Wentland 		struct hw_gpio_pin *pin,
534562236bSHarry Wentland 		enum gpio_mode mode);
544562236bSHarry Wentland 	enum gpio_result (*get_value)(
554562236bSHarry Wentland 		const struct hw_gpio_pin *pin,
564562236bSHarry Wentland 		uint32_t *value);
574562236bSHarry Wentland 	enum gpio_result (*set_value)(
584562236bSHarry Wentland 		const struct hw_gpio_pin *pin,
594562236bSHarry Wentland 		uint32_t value);
604562236bSHarry Wentland 	enum gpio_result (*set_config)(
614562236bSHarry Wentland 		struct hw_gpio_pin *pin,
624562236bSHarry Wentland 		const struct gpio_config_data *config_data);
634562236bSHarry Wentland 	enum gpio_result (*change_mode)(
644562236bSHarry Wentland 		struct hw_gpio_pin *pin,
654562236bSHarry Wentland 		enum gpio_mode mode);
664562236bSHarry Wentland 	void (*close)(
674562236bSHarry Wentland 		struct hw_gpio_pin *pin);
684562236bSHarry Wentland };
694562236bSHarry Wentland 
704562236bSHarry Wentland 
714562236bSHarry Wentland struct hw_gpio;
724562236bSHarry Wentland 
734562236bSHarry Wentland /* Register indices are represented by member variables
744562236bSHarry Wentland  * and are to be filled in by constructors of derived classes.
754562236bSHarry Wentland  * These members permit the use of common code
764562236bSHarry Wentland  * for programming registers, where the sequence is the same
774562236bSHarry Wentland  * but register sets are different.
784562236bSHarry Wentland  * Some GPIOs have HW mux which allows to choose
794562236bSHarry Wentland  * what is the source of the signal in HW mode */
804562236bSHarry Wentland 
814562236bSHarry Wentland struct hw_gpio_pin_reg {
824562236bSHarry Wentland 	struct addr_mask DC_GPIO_DATA_MASK;
834562236bSHarry Wentland 	struct addr_mask DC_GPIO_DATA_A;
844562236bSHarry Wentland 	struct addr_mask DC_GPIO_DATA_EN;
854562236bSHarry Wentland 	struct addr_mask DC_GPIO_DATA_Y;
864562236bSHarry Wentland };
874562236bSHarry Wentland 
884562236bSHarry Wentland struct hw_gpio_mux_reg {
894562236bSHarry Wentland 	struct addr_mask GPIO_MUX_CONTROL;
904562236bSHarry Wentland 	struct addr_mask GPIO_MUX_STEREO_SEL;
914562236bSHarry Wentland };
924562236bSHarry Wentland 
934562236bSHarry Wentland struct hw_gpio {
944562236bSHarry Wentland 	struct hw_gpio_pin base;
954562236bSHarry Wentland 
964562236bSHarry Wentland 	/* variables to save register value */
974562236bSHarry Wentland 	struct {
984562236bSHarry Wentland 		uint32_t mask;
994562236bSHarry Wentland 		uint32_t a;
1004562236bSHarry Wentland 		uint32_t en;
1014562236bSHarry Wentland 		uint32_t mux;
1024562236bSHarry Wentland 	} store;
1034562236bSHarry Wentland 
1044562236bSHarry Wentland 	/* GPIO MUX support */
1054562236bSHarry Wentland 	bool mux_supported;
1064562236bSHarry Wentland 	const struct gpio_registers *regs;
1074562236bSHarry Wentland };
1084562236bSHarry Wentland 
1094562236bSHarry Wentland #define HW_GPIO_FROM_BASE(hw_gpio_pin) \
1104562236bSHarry Wentland 	container_of((hw_gpio_pin), struct hw_gpio, base)
1114562236bSHarry Wentland 
112*0e1c42fdSDave Airlie void dal_hw_gpio_construct(
1134562236bSHarry Wentland 	struct hw_gpio *pin,
1144562236bSHarry Wentland 	enum gpio_id id,
1154562236bSHarry Wentland 	uint32_t en,
1164562236bSHarry Wentland 	struct dc_context *ctx);
1174562236bSHarry Wentland 
1184562236bSHarry Wentland bool dal_hw_gpio_open(
1194562236bSHarry Wentland 	struct hw_gpio_pin *pin,
1204562236bSHarry Wentland 	enum gpio_mode mode);
1214562236bSHarry Wentland 
1224562236bSHarry Wentland enum gpio_result dal_hw_gpio_get_value(
1234562236bSHarry Wentland 	const struct hw_gpio_pin *pin,
1244562236bSHarry Wentland 	uint32_t *value);
1254562236bSHarry Wentland 
1264562236bSHarry Wentland enum gpio_result dal_hw_gpio_config_mode(
1274562236bSHarry Wentland 	struct hw_gpio *pin,
1284562236bSHarry Wentland 	enum gpio_mode mode);
1294562236bSHarry Wentland 
1304562236bSHarry Wentland void dal_hw_gpio_destruct(
1314562236bSHarry Wentland 	struct hw_gpio *pin);
1324562236bSHarry Wentland 
1334562236bSHarry Wentland enum gpio_result dal_hw_gpio_set_value(
1344562236bSHarry Wentland 	const struct hw_gpio_pin *ptr,
1354562236bSHarry Wentland 	uint32_t value);
1364562236bSHarry Wentland 
1374562236bSHarry Wentland enum gpio_result dal_hw_gpio_change_mode(
1384562236bSHarry Wentland 	struct hw_gpio_pin *ptr,
1394562236bSHarry Wentland 	enum gpio_mode mode);
1404562236bSHarry Wentland 
1414562236bSHarry Wentland void dal_hw_gpio_close(
1424562236bSHarry Wentland 	struct hw_gpio_pin *ptr);
1434562236bSHarry Wentland 
1444562236bSHarry Wentland #endif
145