coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
sx9360.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/i2c_simple.h>
7 #include <device/device.h>
8 #include <device/path.h>
9 #include <string.h>
10 #include "chip.h"
11 
12 #define I2C_SX9360_ACPI_ID "STH9360"
13 #define I2C_SX9360_CHIP_NAME "Semtech SX9360"
14 
15 static void i2c_sx9360_fill_ssdt(const struct device *dev)
16 {
18  const char *scope = acpi_device_scope(dev);
19  struct acpi_i2c i2c = {
20  .address = dev->path.i2c.device,
21  .mode_10bit = dev->path.i2c.mode_10bit,
22  .speed = I2C_SPEED_FAST,
23  .resource = scope,
24  };
25  struct acpi_dp *dsd;
26 
27  if (!scope || !config)
28  return;
29 
30  if (config->speed)
31  i2c.speed = config->speed;
32 
33  /* Device */
34  acpigen_write_scope(scope);
37  acpigen_write_name_integer("_UID", config->uid);
38  acpigen_write_name_string("_DDN", config->desc);
40 
41  /* Resources */
42  acpigen_write_name("_CRS");
45 
46  if (config->irq_gpio.pin_count)
47  acpi_device_write_gpio(&config->irq_gpio);
48  else
50 
52 
53  /* DSD */
54  dsd = acpi_dp_new_table("_DSD");
55 
56  /*
57  * Format described in linux kernel documentation. See
58  * https://www.kernel.org/doc/Documentation/devicetree/bindings/iio/proximity/semtech%2Csx9360.yaml
59  */
60  acpi_dp_add_integer(dsd, "semtech,proxraw-strength",
61  config->proxraw_strength);
62  acpi_dp_add_integer(dsd, "semtech,avg-pos-strength",
63  config->avg_pos_strength);
64  acpi_dp_add_integer(dsd, "semtech,resolution",
65  config->resolution);
66 
67  acpi_dp_write(dsd);
68 
69  acpigen_pop_len(); /* Device */
70  acpigen_pop_len(); /* Scope */
71 
72  printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev),
73  config->desc ? : dev->chip_ops->name, dev_path(dev));
74 }
75 
76 static const char *i2c_sx9360_acpi_name(const struct device *dev)
77 {
78  static char name[5];
79 
80  snprintf(name, sizeof(name), "SX%02.2X", dev->path.i2c.device);
81  return name;
82 }
83 
84 static struct device_operations i2c_sx9360_ops = {
86  .set_resources = noop_set_resources,
87  .acpi_name = i2c_sx9360_acpi_name,
88  .acpi_fill_ssdt = i2c_sx9360_fill_ssdt,
89 };
90 
91 static void i2c_sx9360_enable(struct device *dev)
92 {
94 
95  if (!is_dev_enabled(dev))
96  return;
97 
98  dev->ops = &i2c_sx9360_ops;
99 
100  if (config->desc)
101  dev->name = config->desc;
102 }
103 
106  .enable_dev = i2c_sx9360_enable
107 };
void acpi_device_write_gpio(const struct acpi_gpio *gpio)
Definition: device.c:258
const char * acpi_device_path(const struct device *dev)
Definition: device.c:144
void acpi_device_write_interrupt(const struct acpi_irq *irq)
Definition: device.c:209
struct acpi_dp * acpi_dp_add_integer(struct acpi_dp *dp, const char *name, uint64_t value)
Definition: device.c:977
void acpi_device_write_i2c(const struct acpi_i2c *i2c)
Definition: device.c:399
void acpi_dp_write(struct acpi_dp *table)
Definition: device.c:898
int acpi_device_status(const struct device *dev)
Definition: device.c:193
const char * acpi_device_name(const struct device *dev)
Definition: device.c:49
struct acpi_dp * acpi_dp_new_table(const char *name)
Definition: device.c:930
const char * acpi_device_scope(const struct device *dev)
Definition: device.c:158
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_scope(const char *name)
Definition: acpigen.c:326
void acpigen_write_resourcetemplate_footer(void)
Definition: acpigen.c:1165
void acpigen_write_name_integer(const char *name, uint64_t val)
Definition: acpigen.c:170
void acpigen_write_STA(uint8_t status)
Definition: acpigen.c:783
void acpigen_write_resourcetemplate_header(void)
Definition: acpigen.c:1147
void acpigen_write_device(const char *name)
Definition: acpigen.c:769
void acpigen_write_name(const char *name)
Definition: acpigen.c:320
void acpigen_write_name_string(const char *name, const char *string)
Definition: acpigen.c:176
const char * name
Definition: mmu.c:92
#define printk(level,...)
Definition: stdlib.h:16
bool is_dev_enabled(const struct device *dev)
Definition: device_const.c:369
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
static DEVTREE_CONST void * config_of(const struct device *dev)
Definition: device.h:382
@ I2C_SPEED_FAST
Definition: i2c.h:45
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
enum board_config config
Definition: memory.c:448
enum i2c_speed speed
Definition: acpi_device.h:308
uint16_t address
Definition: acpi_device.h:304
const char * name
Definition: device.h:29
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct i2c_path i2c
Definition: path.h:118
Definition: device.h:107
struct chip_operations * chip_ops
Definition: device.h:144
const char * name
Definition: device.h:145
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int device
Definition: path.h:63
unsigned int mode_10bit
Definition: path.h:64
struct chip_operations drivers_i2c_sx9360_ops
Definition: sx9360.c:104
static const char * i2c_sx9360_acpi_name(const struct device *dev)
Definition: sx9360.c:76
#define I2C_SX9360_CHIP_NAME
Definition: sx9360.c:13
#define I2C_SX9360_ACPI_ID
Definition: sx9360.c:12
static void i2c_sx9360_enable(struct device *dev)
Definition: sx9360.c:91
static struct device_operations i2c_sx9360_ops
Definition: sx9360.c:84
static void i2c_sx9360_fill_ssdt(const struct device *dev)
Definition: sx9360.c:15
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35