Commit 91db9311 authored by Su Sung Chung's avatar Su Sung Chung Committed by Alex Deucher

drm/amd/display: refactor gpio to allocate hw_container in constructor

[why]
if dynamic allocation fails during gpio_open, it will cause crash due to
page fault.

[how]
handle allocation when gpio object gets created and prevent from calling
gpio_open if allocation failed
Signed-off-by: default avatarSu Sung Chung <Su.Chung@amd.com>
Reviewed-by: default avatarJun Lei <Jun.Lei@amd.com>
Acked-by: default avatarLeo Li <sunpeng.li@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 37495fbd
...@@ -24,9 +24,15 @@ ...@@ -24,9 +24,15 @@
*/ */
#include "dm_services.h" #include "dm_services.h"
#include "include/gpio_types.h" #include "include/gpio_types.h"
#include "../hw_factory.h" #include "../hw_factory.h"
#include "../hw_gpio.h"
#include "../hw_ddc.h"
#include "../hw_hpd.h"
#include "../hw_generic.h"
#include "hw_factory_dce110.h" #include "hw_factory_dce110.h"
#include "dce/dce_11_0_d.h" #include "dce/dce_11_0_d.h"
...@@ -143,12 +149,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en) ...@@ -143,12 +149,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
} }
static const struct hw_factory_funcs funcs = { static const struct hw_factory_funcs funcs = {
.create_ddc_data = dal_hw_ddc_create, .init_ddc_data = dal_hw_ddc_init,
.create_ddc_clock = dal_hw_ddc_create, .init_generic = NULL,
.create_generic = NULL, .init_hpd = dal_hw_hpd_init,
.create_hpd = dal_hw_hpd_create, .get_ddc_pin = dal_hw_ddc_get_pin,
.create_sync = NULL, .get_hpd_pin = dal_hw_hpd_get_pin,
.create_gsl = NULL, .get_generic_pin = NULL,
.define_hpd_registers = define_hpd_registers, .define_hpd_registers = define_hpd_registers,
.define_ddc_registers = define_ddc_registers .define_ddc_registers = define_ddc_registers
}; };
......
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
#include "include/gpio_types.h" #include "include/gpio_types.h"
#include "../hw_factory.h" #include "../hw_factory.h"
#include "../hw_gpio.h" #include "../hw_gpio.h"
#include "../hw_ddc.h" #include "../hw_ddc.h"
#include "../hw_hpd.h" #include "../hw_hpd.h"
#include "../hw_generic.h"
#include "hw_factory_dce120.h" #include "hw_factory_dce120.h"
...@@ -164,12 +164,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en) ...@@ -164,12 +164,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
/* fucntion table */ /* fucntion table */
static const struct hw_factory_funcs funcs = { static const struct hw_factory_funcs funcs = {
.create_ddc_data = dal_hw_ddc_create, .init_ddc_data = dal_hw_ddc_init,
.create_ddc_clock = dal_hw_ddc_create, .init_generic = NULL,
.create_generic = NULL, .init_hpd = dal_hw_hpd_init,
.create_hpd = dal_hw_hpd_create, .get_ddc_pin = dal_hw_ddc_get_pin,
.create_sync = NULL, .get_hpd_pin = dal_hw_hpd_get_pin,
.create_gsl = NULL, .get_generic_pin = NULL,
.define_hpd_registers = define_hpd_registers, .define_hpd_registers = define_hpd_registers,
.define_ddc_registers = define_ddc_registers .define_ddc_registers = define_ddc_registers
}; };
......
...@@ -32,10 +32,12 @@ ...@@ -32,10 +32,12 @@
#include "../hw_gpio.h" #include "../hw_gpio.h"
#include "../hw_ddc.h" #include "../hw_ddc.h"
#include "../hw_hpd.h" #include "../hw_hpd.h"
#include "../hw_generic.h"
#include "dce/dce_8_0_d.h" #include "dce/dce_8_0_d.h"
#include "dce/dce_8_0_sh_mask.h" #include "dce/dce_8_0_sh_mask.h"
#define REG(reg_name)\ #define REG(reg_name)\
mm ## reg_name mm ## reg_name
...@@ -147,12 +149,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en) ...@@ -147,12 +149,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
} }
static const struct hw_factory_funcs funcs = { static const struct hw_factory_funcs funcs = {
.create_ddc_data = dal_hw_ddc_create, .init_ddc_data = dal_hw_ddc_init,
.create_ddc_clock = dal_hw_ddc_create, .init_generic = NULL,
.create_generic = NULL, .init_hpd = dal_hw_hpd_init,
.create_hpd = dal_hw_hpd_create, .get_ddc_pin = dal_hw_ddc_get_pin,
.create_sync = NULL, .get_hpd_pin = dal_hw_hpd_get_pin,
.create_gsl = NULL, .get_generic_pin = NULL,
.define_hpd_registers = define_hpd_registers, .define_hpd_registers = define_hpd_registers,
.define_ddc_registers = define_ddc_registers .define_ddc_registers = define_ddc_registers
}; };
......
...@@ -196,12 +196,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en) ...@@ -196,12 +196,12 @@ static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
/* fucntion table */ /* fucntion table */
static const struct hw_factory_funcs funcs = { static const struct hw_factory_funcs funcs = {
.create_ddc_data = dal_hw_ddc_create, .init_ddc_data = dal_hw_ddc_init,
.create_ddc_clock = dal_hw_ddc_create, .init_generic = dal_hw_generic_init,
.create_generic = dal_hw_generic_create, .init_hpd = dal_hw_hpd_init,
.create_hpd = dal_hw_hpd_create, .get_ddc_pin = dal_hw_ddc_get_pin,
.create_sync = NULL, .get_hpd_pin = dal_hw_hpd_get_pin,
.create_gsl = NULL, .get_generic_pin = dal_hw_generic_get_pin,
.define_hpd_registers = define_hpd_registers, .define_hpd_registers = define_hpd_registers,
.define_ddc_registers = define_ddc_registers, .define_ddc_registers = define_ddc_registers,
.define_generic_registers = define_generic_registers .define_generic_registers = define_generic_registers
......
...@@ -212,12 +212,12 @@ static void define_generic_registers(struct hw_gpio_pin *pin, uint32_t en) ...@@ -212,12 +212,12 @@ static void define_generic_registers(struct hw_gpio_pin *pin, uint32_t en)
/* fucntion table */ /* fucntion table */
static const struct hw_factory_funcs funcs = { static const struct hw_factory_funcs funcs = {
.create_ddc_data = dal_hw_ddc_create, .init_ddc_data = dal_hw_ddc_init,
.create_ddc_clock = dal_hw_ddc_create, .init_generic = dal_hw_generic_init,
.create_generic = dal_hw_generic_create, .init_hpd = dal_hw_hpd_init,
.create_hpd = dal_hw_hpd_create, .get_ddc_pin = dal_hw_ddc_get_pin,
.create_sync = NULL, .get_hpd_pin = dal_hw_hpd_get_pin,
.create_gsl = NULL, .get_generic_pin = dal_hw_generic_get_pin,
.define_hpd_registers = define_hpd_registers, .define_hpd_registers = define_hpd_registers,
.define_ddc_registers = define_ddc_registers, .define_ddc_registers = define_ddc_registers,
.define_generic_registers = define_generic_registers, .define_generic_registers = define_generic_registers,
......
...@@ -42,12 +42,9 @@ ...@@ -42,12 +42,9 @@
/* function table */ /* function table */
static const struct hw_factory_funcs funcs = { static const struct hw_factory_funcs funcs = {
.create_ddc_data = NULL, .init_ddc_data = NULL,
.create_ddc_clock = NULL, .init_generic = NULL,
.create_generic = NULL, .init_hpd = NULL,
.create_hpd = NULL,
.create_sync = NULL,
.create_gsl = NULL,
}; };
void dal_hw_factory_diag_fpga_init(struct hw_factory *factory) void dal_hw_factory_diag_fpga_init(struct hw_factory *factory)
......
...@@ -67,10 +67,14 @@ enum gpio_result dal_gpio_open_ex( ...@@ -67,10 +67,14 @@ enum gpio_result dal_gpio_open_ex(
return GPIO_RESULT_ALREADY_OPENED; return GPIO_RESULT_ALREADY_OPENED;
} }
// No action if allocation failed during gpio construct
if (!gpio->hw_container.ddc) {
ASSERT_CRITICAL(false);
return GPIO_RESULT_NON_SPECIFIC_ERROR;
}
gpio->mode = mode; gpio->mode = mode;
return dal_gpio_service_open( return dal_gpio_service_open(gpio);
gpio->service, gpio->id, gpio->en, mode, &gpio->pin);
} }
enum gpio_result dal_gpio_get_value( enum gpio_result dal_gpio_get_value(
...@@ -231,6 +235,21 @@ enum gpio_pin_output_state dal_gpio_get_output_state( ...@@ -231,6 +235,21 @@ enum gpio_pin_output_state dal_gpio_get_output_state(
return gpio->output_state; return gpio->output_state;
} }
struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio)
{
return gpio->hw_container.ddc;
}
struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio)
{
return gpio->hw_container.hpd;
}
struct hw_generic *dal_gpio_get_generic(struct gpio *gpio)
{
return gpio->hw_container.generic;
}
void dal_gpio_close( void dal_gpio_close(
struct gpio *gpio) struct gpio *gpio)
{ {
...@@ -267,6 +286,30 @@ struct gpio *dal_gpio_create( ...@@ -267,6 +286,30 @@ struct gpio *dal_gpio_create(
gpio->mode = GPIO_MODE_UNKNOWN; gpio->mode = GPIO_MODE_UNKNOWN;
gpio->output_state = output_state; gpio->output_state = output_state;
//initialize hw_container union based on id
switch (gpio->id) {
case GPIO_ID_DDC_DATA:
gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
break;
case GPIO_ID_DDC_CLOCK:
gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
break;
case GPIO_ID_GENERIC:
gpio->service->factory.funcs->init_generic(&gpio->hw_container.generic, service->ctx, id, en);
break;
case GPIO_ID_HPD:
gpio->service->factory.funcs->init_hpd(&gpio->hw_container.hpd, service->ctx, id, en);
break;
// TODO: currently gpio for sync and gsl does not get created, might need it later
case GPIO_ID_SYNC:
break;
case GPIO_ID_GSL:
break;
default:
ASSERT_CRITICAL(false);
gpio->pin = NULL;
}
return gpio; return gpio;
} }
...@@ -280,6 +323,33 @@ void dal_gpio_destroy( ...@@ -280,6 +323,33 @@ void dal_gpio_destroy(
dal_gpio_close(*gpio); dal_gpio_close(*gpio);
switch ((*gpio)->id) {
case GPIO_ID_DDC_DATA:
kfree((*gpio)->hw_container.ddc);
(*gpio)->hw_container.ddc = NULL;
break;
case GPIO_ID_DDC_CLOCK:
//TODO: might want to change it to init_ddc_clock
kfree((*gpio)->hw_container.ddc);
(*gpio)->hw_container.ddc = NULL;
break;
case GPIO_ID_GENERIC:
kfree((*gpio)->hw_container.generic);
(*gpio)->hw_container.generic = NULL;
break;
case GPIO_ID_HPD:
kfree((*gpio)->hw_container.hpd);
(*gpio)->hw_container.hpd = NULL;
break;
// TODO: currently gpio for sync and gsl does not get created, might need it later
case GPIO_ID_SYNC:
break;
case GPIO_ID_GSL:
break;
default:
break;
}
kfree(*gpio); kfree(*gpio);
*gpio = NULL; *gpio = NULL;
......
...@@ -290,13 +290,15 @@ enum gpio_result dal_gpio_service_unlock( ...@@ -290,13 +290,15 @@ enum gpio_result dal_gpio_service_unlock(
} }
enum gpio_result dal_gpio_service_open( enum gpio_result dal_gpio_service_open(
struct gpio_service *service, struct gpio *gpio)
enum gpio_id id,
uint32_t en,
enum gpio_mode mode,
struct hw_gpio_pin **ptr)
{ {
struct hw_gpio_pin *pin; struct gpio_service *service = gpio->service;
enum gpio_id id = gpio->id;
uint32_t en = gpio->en;
enum gpio_mode mode = gpio->mode;
struct hw_gpio_pin **pin = &gpio->pin;
if (!service->busyness[id]) { if (!service->busyness[id]) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
...@@ -310,51 +312,43 @@ enum gpio_result dal_gpio_service_open( ...@@ -310,51 +312,43 @@ enum gpio_result dal_gpio_service_open(
switch (id) { switch (id) {
case GPIO_ID_DDC_DATA: case GPIO_ID_DDC_DATA:
pin = service->factory.funcs->create_ddc_data( *pin = service->factory.funcs->get_ddc_pin(gpio);
service->ctx, id, en); service->factory.funcs->define_ddc_registers(*pin, en);
service->factory.funcs->define_ddc_registers(pin, en);
break; break;
case GPIO_ID_DDC_CLOCK: case GPIO_ID_DDC_CLOCK:
pin = service->factory.funcs->create_ddc_clock( *pin = service->factory.funcs->get_ddc_pin(gpio);
service->ctx, id, en); service->factory.funcs->define_ddc_registers(*pin, en);
service->factory.funcs->define_ddc_registers(pin, en);
break; break;
case GPIO_ID_GENERIC: case GPIO_ID_GENERIC:
pin = service->factory.funcs->create_generic( *pin = service->factory.funcs->get_generic_pin(gpio);
service->ctx, id, en); service->factory.funcs->define_generic_registers(*pin, en);
service->factory.funcs->define_generic_registers(pin, en);
break; break;
case GPIO_ID_HPD: case GPIO_ID_HPD:
pin = service->factory.funcs->create_hpd( *pin = service->factory.funcs->get_hpd_pin(gpio);
service->ctx, id, en); service->factory.funcs->define_hpd_registers(*pin, en);
service->factory.funcs->define_hpd_registers(pin, en);
break; break;
//TODO: gsl and sync support? create_sync and create_gsl are NULL
case GPIO_ID_SYNC: case GPIO_ID_SYNC:
pin = service->factory.funcs->create_sync(
service->ctx, id, en);
break;
case GPIO_ID_GSL: case GPIO_ID_GSL:
pin = service->factory.funcs->create_gsl(
service->ctx, id, en);
break; break;
default: default:
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return GPIO_RESULT_NON_SPECIFIC_ERROR; return GPIO_RESULT_NON_SPECIFIC_ERROR;
} }
if (!pin) { if (!*pin) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return GPIO_RESULT_NON_SPECIFIC_ERROR; return GPIO_RESULT_NON_SPECIFIC_ERROR;
} }
if (!pin->funcs->open(pin, mode)) { if (!(*pin)->funcs->open(*pin, mode)) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
dal_gpio_service_close(service, &pin); dal_gpio_service_close(service, pin);
return GPIO_RESULT_OPEN_FAILED; return GPIO_RESULT_OPEN_FAILED;
} }
set_pin_busy(service, id, en); set_pin_busy(service, id, en);
*ptr = pin;
return GPIO_RESULT_OK; return GPIO_RESULT_OK;
} }
...@@ -376,11 +370,10 @@ void dal_gpio_service_close( ...@@ -376,11 +370,10 @@ void dal_gpio_service_close(
pin->funcs->close(pin); pin->funcs->close(pin);
pin->funcs->destroy(ptr); *ptr = NULL;
} }
} }
enum dc_irq_source dal_irq_get_source( enum dc_irq_source dal_irq_get_source(
const struct gpio *irq) const struct gpio *irq)
{ {
......
...@@ -42,11 +42,7 @@ struct gpio_service { ...@@ -42,11 +42,7 @@ struct gpio_service {
}; };
enum gpio_result dal_gpio_service_open( enum gpio_result dal_gpio_service_open(
struct gpio_service *service, struct gpio *gpio);
enum gpio_id id,
uint32_t en,
enum gpio_mode mode,
struct hw_gpio_pin **ptr);
void dal_gpio_service_close( void dal_gpio_service_close(
struct gpio_service *service, struct gpio_service *service,
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "dm_services.h" #include "dm_services.h"
#include "include/gpio_interface.h"
#include "include/gpio_types.h" #include "include/gpio_types.h"
#include "hw_gpio.h" #include "hw_gpio.h"
#include "hw_ddc.h" #include "hw_ddc.h"
...@@ -45,6 +46,8 @@ ...@@ -45,6 +46,8 @@
#define REG(reg)\ #define REG(reg)\
(ddc->regs->reg) (ddc->regs->reg)
struct gpio;
static void destruct( static void destruct(
struct hw_ddc *pin) struct hw_ddc *pin)
{ {
...@@ -227,24 +230,29 @@ static void construct( ...@@ -227,24 +230,29 @@ static void construct(
ddc->base.base.funcs = &funcs; ddc->base.base.funcs = &funcs;
} }
struct hw_gpio_pin *dal_hw_ddc_create( void dal_hw_ddc_init(
struct hw_ddc **hw_ddc,
struct dc_context *ctx, struct dc_context *ctx,
enum gpio_id id, enum gpio_id id,
uint32_t en) uint32_t en)
{ {
struct hw_ddc *pin;
if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) { if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; *hw_ddc = NULL;
} }
pin = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL); *hw_ddc = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL);
if (!pin) { if (!*hw_ddc) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; return;
} }
construct(pin, id, en, ctx); construct(*hw_ddc, id, en, ctx);
return &pin->base.base; }
struct hw_gpio_pin *dal_hw_ddc_get_pin(struct gpio *gpio)
{
struct hw_ddc *hw_ddc = dal_gpio_get_ddc(gpio);
return &hw_ddc->base.base;
} }
...@@ -38,9 +38,12 @@ struct hw_ddc { ...@@ -38,9 +38,12 @@ struct hw_ddc {
#define HW_DDC_FROM_BASE(hw_gpio) \ #define HW_DDC_FROM_BASE(hw_gpio) \
container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_ddc, base) container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_ddc, base)
struct hw_gpio_pin *dal_hw_ddc_create( void dal_hw_ddc_init(
struct hw_ddc **hw_ddc,
struct dc_context *ctx, struct dc_context *ctx,
enum gpio_id id, enum gpio_id id,
uint32_t en); uint32_t en);
struct hw_gpio_pin *dal_hw_ddc_get_pin(struct gpio *gpio);
#endif #endif
...@@ -28,35 +28,35 @@ ...@@ -28,35 +28,35 @@
struct hw_gpio_pin; struct hw_gpio_pin;
struct hw_hpd; struct hw_hpd;
struct hw_ddc;
struct hw_generic;
struct gpio;
struct hw_factory { struct hw_factory {
uint32_t number_of_pins[GPIO_ID_COUNT]; uint32_t number_of_pins[GPIO_ID_COUNT];
const struct hw_factory_funcs { const struct hw_factory_funcs {
struct hw_gpio_pin *(*create_ddc_data)( void (*init_ddc_data)(
struct dc_context *ctx, struct hw_ddc **hw_ddc,
enum gpio_id id, struct dc_context *ctx,
uint32_t en); enum gpio_id id,
struct hw_gpio_pin *(*create_ddc_clock)( uint32_t en);
struct dc_context *ctx, void (*init_generic)(
enum gpio_id id, struct hw_generic **hw_generic,
uint32_t en); struct dc_context *ctx,
struct hw_gpio_pin *(*create_generic)( enum gpio_id id,
struct dc_context *ctx, uint32_t en);
enum gpio_id id, void (*init_hpd)(
uint32_t en); struct hw_hpd **hw_hpd,
struct hw_gpio_pin *(*create_hpd)( struct dc_context *ctx,
struct dc_context *ctx, enum gpio_id id,
enum gpio_id id, uint32_t en);
uint32_t en); struct hw_gpio_pin *(*get_hpd_pin)(
struct hw_gpio_pin *(*create_sync)( struct gpio *gpio);
struct dc_context *ctx, struct hw_gpio_pin *(*get_ddc_pin)(
enum gpio_id id, struct gpio *gpio);
uint32_t en); struct hw_gpio_pin *(*get_generic_pin)(
struct hw_gpio_pin *(*create_gsl)( struct gpio *gpio);
struct dc_context *ctx,
enum gpio_id id,
uint32_t en);
void (*define_hpd_registers)( void (*define_hpd_registers)(
struct hw_gpio_pin *pin, struct hw_gpio_pin *pin,
uint32_t en); uint32_t en);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "dm_services.h" #include "dm_services.h"
#include "include/gpio_interface.h"
#include "include/gpio_types.h" #include "include/gpio_types.h"
#include "hw_gpio.h" #include "hw_gpio.h"
#include "hw_generic.h" #include "hw_generic.h"
...@@ -43,6 +44,8 @@ ...@@ -43,6 +44,8 @@
#define REG(reg)\ #define REG(reg)\
(generic->regs->reg) (generic->regs->reg)
struct gpio;
static void dal_hw_generic_construct( static void dal_hw_generic_construct(
struct hw_generic *pin, struct hw_generic *pin,
enum gpio_id id, enum gpio_id id,
...@@ -106,29 +109,30 @@ static void construct( ...@@ -106,29 +109,30 @@ static void construct(
generic->base.base.funcs = &funcs; generic->base.base.funcs = &funcs;
} }
struct hw_gpio_pin *dal_hw_generic_create( void dal_hw_generic_init(
struct hw_generic **hw_generic,
struct dc_context *ctx, struct dc_context *ctx,
enum gpio_id id, enum gpio_id id,
uint32_t en) uint32_t en)
{ {
struct hw_generic *generic; if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
if (id != GPIO_ID_GENERIC) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; *hw_generic = NULL;
} }
if ((en < GPIO_GENERIC_MIN) || (en > GPIO_GENERIC_MAX)) { *hw_generic = kzalloc(sizeof(struct hw_generic), GFP_KERNEL);
if (!*hw_generic) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; return;
} }
generic = kzalloc(sizeof(struct hw_generic), GFP_KERNEL); construct(*hw_generic, id, en, ctx);
if (!generic) { }
ASSERT_CRITICAL(false);
return NULL;
} struct hw_gpio_pin *dal_hw_generic_get_pin(struct gpio *gpio)
{
struct hw_generic *hw_generic = dal_gpio_get_generic(gpio);
construct(generic, id, en, ctx); return &hw_generic->base.base;
return &generic->base.base;
} }
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define __DAL_HW_generic_H__ #define __DAL_HW_generic_H__
#include "generic_regs.h" #include "generic_regs.h"
#include "hw_gpio.h"
struct hw_generic { struct hw_generic {
struct hw_gpio base; struct hw_gpio base;
...@@ -38,9 +39,12 @@ struct hw_generic { ...@@ -38,9 +39,12 @@ struct hw_generic {
#define HW_GENERIC_FROM_BASE(hw_gpio) \ #define HW_GENERIC_FROM_BASE(hw_gpio) \
container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_generic, base) container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_generic, base)
struct hw_gpio_pin *dal_hw_generic_create( void dal_hw_generic_init(
struct hw_generic **hw_generic,
struct dc_context *ctx, struct dc_context *ctx,
enum gpio_id id, enum gpio_id id,
uint32_t en); uint32_t en);
struct hw_gpio_pin *dal_hw_generic_get_pin(struct gpio *gpio);
#endif #endif
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "dm_services.h" #include "dm_services.h"
#include "include/gpio_interface.h"
#include "include/gpio_types.h" #include "include/gpio_types.h"
#include "hw_gpio.h" #include "hw_gpio.h"
#include "hw_hpd.h" #include "hw_hpd.h"
...@@ -43,6 +44,8 @@ ...@@ -43,6 +44,8 @@
#define REG(reg)\ #define REG(reg)\
(hpd->regs->reg) (hpd->regs->reg)
struct gpio;
static void dal_hw_hpd_construct( static void dal_hw_hpd_construct(
struct hw_hpd *pin, struct hw_hpd *pin,
enum gpio_id id, enum gpio_id id,
...@@ -136,29 +139,29 @@ static void construct( ...@@ -136,29 +139,29 @@ static void construct(
hpd->base.base.funcs = &funcs; hpd->base.base.funcs = &funcs;
} }
struct hw_gpio_pin *dal_hw_hpd_create( void dal_hw_hpd_init(
struct hw_hpd **hw_hpd,
struct dc_context *ctx, struct dc_context *ctx,
enum gpio_id id, enum gpio_id id,
uint32_t en) uint32_t en)
{ {
struct hw_hpd *hpd; if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
if (id != GPIO_ID_HPD) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; *hw_hpd = NULL;
} }
if ((en < GPIO_HPD_MIN) || (en > GPIO_HPD_MAX)) { *hw_hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL);
if (!*hw_hpd) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; return;
} }
hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL); construct(*hw_hpd, id, en, ctx);
if (!hpd) { }
ASSERT_CRITICAL(false);
return NULL; struct hw_gpio_pin *dal_hw_hpd_get_pin(struct gpio *gpio)
} {
struct hw_hpd *hw_hpd = dal_gpio_get_hpd(gpio);
construct(hpd, id, en, ctx); return &hw_hpd->base.base;
return &hpd->base.base;
} }
...@@ -38,9 +38,12 @@ struct hw_hpd { ...@@ -38,9 +38,12 @@ struct hw_hpd {
#define HW_HPD_FROM_BASE(hw_gpio) \ #define HW_HPD_FROM_BASE(hw_gpio) \
container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_hpd, base) container_of((HW_GPIO_FROM_BASE(hw_gpio)), struct hw_hpd, base)
struct hw_gpio_pin *dal_hw_hpd_create( void dal_hw_hpd_init(
struct hw_hpd **hw_hpd,
struct dc_context *ctx, struct dc_context *ctx,
enum gpio_id id, enum gpio_id id,
uint32_t en); uint32_t en);
struct hw_gpio_pin *dal_hw_hpd_get_pin(struct gpio *gpio);
#endif #endif
...@@ -28,12 +28,22 @@ ...@@ -28,12 +28,22 @@
#include "gpio_types.h" #include "gpio_types.h"
union gpio_hw_container {
struct hw_ddc *ddc;
struct hw_generic *generic;
struct hw_hpd *hpd;
};
struct gpio { struct gpio {
struct gpio_service *service; struct gpio_service *service;
struct hw_gpio_pin *pin; struct hw_gpio_pin *pin;
enum gpio_id id; enum gpio_id id;
uint32_t en; uint32_t en;
union gpio_hw_container hw_container;
enum gpio_mode mode; enum gpio_mode mode;
/* when GPIO comes from VBIOS, it has defined output state */ /* when GPIO comes from VBIOS, it has defined output state */
enum gpio_pin_output_state output_state; enum gpio_pin_output_state output_state;
}; };
......
...@@ -93,8 +93,17 @@ enum sync_source dal_gpio_get_sync_source( ...@@ -93,8 +93,17 @@ enum sync_source dal_gpio_get_sync_source(
enum gpio_pin_output_state dal_gpio_get_output_state( enum gpio_pin_output_state dal_gpio_get_output_state(
const struct gpio *gpio); const struct gpio *gpio);
struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio);
struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio);
struct hw_generic *dal_gpio_get_generic(struct gpio *gpio);
/* Close the handle */ /* Close the handle */
void dal_gpio_close( void dal_gpio_close(
struct gpio *gpio); struct gpio *gpio);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment