Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,32 @@
config DRM_SSD130X
tristate "DRM support for Solomon SSD13xx OLED displays"
depends on DRM && MMU
select BACKLIGHT_CLASS_DEVICE
select DRM_CLIENT_SELECTION
select DRM_GEM_SHMEM_HELPER
select DRM_KMS_HELPER
help
DRM driver for the SSD13xx Solomon and SINO WEALTH SH110x OLED
controllers. This is only for the core driver, a driver for the
appropriate bus transport in your chip also must be selected.
If M is selected the module will be called ssd130x.
config DRM_SSD130X_I2C
tristate "DRM support for Solomon SSD13xx OLED displays (I2C bus)"
depends on DRM_SSD130X && I2C
select REGMAP_I2C
help
Say Y here if the SSD13xx or SH110x OLED display is connected via
I2C bus.
If M is selected the module will be called ssd130x-i2c.
config DRM_SSD130X_SPI
tristate "DRM support for Solomon SSD13xx OLED displays (SPI bus)"
depends on DRM_SSD130X && SPI
select REGMAP
help
Say Y here if the SSD13xx OLED display is connected via SPI bus.
If M is selected the module will be called ssd130x-spi.
@@ -0,0 +1,3 @@
obj-$(CONFIG_DRM_SSD130X) += ssd130x.o
obj-$(CONFIG_DRM_SSD130X_I2C) += ssd130x-i2c.o
obj-$(CONFIG_DRM_SSD130X_SPI) += ssd130x-spi.o
@@ -0,0 +1,126 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* DRM driver for Solomon SSD13xx OLED displays (I2C bus)
*
* Copyright 2022 Red Hat Inc.
* Author: Javier Martinez Canillas <javierm@redhat.com>
*
* Based on drivers/video/fbdev/ssd1307fb.c
* Copyright 2012 Free Electrons
*/
#include <linux/i2c.h>
#include <linux/module.h>
#include "ssd130x.h"
#define DRIVER_NAME "ssd130x-i2c"
#define DRIVER_DESC "DRM driver for Solomon SSD13xx OLED displays (I2C)"
static const struct regmap_config ssd130x_i2c_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
};
static int ssd130x_i2c_probe(struct i2c_client *client)
{
struct ssd130x_device *ssd130x;
struct regmap *regmap;
regmap = devm_regmap_init_i2c(client, &ssd130x_i2c_regmap_config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
ssd130x = ssd130x_probe(&client->dev, regmap);
if (IS_ERR(ssd130x))
return PTR_ERR(ssd130x);
i2c_set_clientdata(client, ssd130x);
return 0;
}
static void ssd130x_i2c_remove(struct i2c_client *client)
{
struct ssd130x_device *ssd130x = i2c_get_clientdata(client);
ssd130x_remove(ssd130x);
}
static void ssd130x_i2c_shutdown(struct i2c_client *client)
{
struct ssd130x_device *ssd130x = i2c_get_clientdata(client);
ssd130x_shutdown(ssd130x);
}
static const struct of_device_id ssd130x_of_match[] = {
/* ssd130x family */
{
.compatible = "sinowealth,sh1106",
.data = &ssd130x_variants[SH1106_ID],
},
{
.compatible = "solomon,ssd1305",
.data = &ssd130x_variants[SSD1305_ID],
},
{
.compatible = "solomon,ssd1306",
.data = &ssd130x_variants[SSD1306_ID],
},
{
.compatible = "solomon,ssd1307",
.data = &ssd130x_variants[SSD1307_ID],
},
{
.compatible = "solomon,ssd1309",
.data = &ssd130x_variants[SSD1309_ID],
},
/* Deprecated but kept for backward compatibility */
{
.compatible = "solomon,ssd1305fb-i2c",
.data = &ssd130x_variants[SSD1305_ID],
},
{
.compatible = "solomon,ssd1306fb-i2c",
.data = &ssd130x_variants[SSD1306_ID],
},
{
.compatible = "solomon,ssd1307fb-i2c",
.data = &ssd130x_variants[SSD1307_ID],
},
{
.compatible = "solomon,ssd1309fb-i2c",
.data = &ssd130x_variants[SSD1309_ID],
},
/* ssd132x family */
{
.compatible = "solomon,ssd1322",
.data = &ssd130x_variants[SSD1322_ID],
},
{
.compatible = "solomon,ssd1325",
.data = &ssd130x_variants[SSD1325_ID],
},
{
.compatible = "solomon,ssd1327",
.data = &ssd130x_variants[SSD1327_ID],
},
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, ssd130x_of_match);
static struct i2c_driver ssd130x_i2c_driver = {
.driver = {
.name = DRIVER_NAME,
.of_match_table = ssd130x_of_match,
},
.probe = ssd130x_i2c_probe,
.remove = ssd130x_i2c_remove,
.shutdown = ssd130x_i2c_shutdown,
};
module_i2c_driver(ssd130x_i2c_driver);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_AUTHOR("Javier Martinez Canillas <javierm@redhat.com>");
MODULE_LICENSE("GPL v2");
MODULE_IMPORT_NS("DRM_SSD130X");
@@ -0,0 +1,193 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* DRM driver for Solomon SSD13xx OLED displays (SPI bus)
*
* Copyright 2022 Red Hat Inc.
* Authors: Javier Martinez Canillas <javierm@redhat.com>
*/
#include <linux/spi/spi.h>
#include <linux/module.h>
#include "ssd130x.h"
#define DRIVER_NAME "ssd130x-spi"
#define DRIVER_DESC "DRM driver for Solomon SSD13xx OLED displays (SPI)"
struct ssd130x_spi_transport {
struct spi_device *spi;
struct gpio_desc *dc;
};
/*
* The regmap bus .write handler, it is just a wrapper around spi_write()
* but toggling the Data/Command control pin (D/C#). Since for 4-wire SPI
* a D/C# pin is used, in contrast with I2C where a control byte is sent,
* prior to every data byte, that contains a bit with the D/C# value.
*
* These control bytes are considered registers by the ssd130x core driver
* and can be used by the ssd130x SPI driver to determine if the data sent
* is for a command register or for the Graphic Display Data RAM (GDDRAM).
*/
static int ssd130x_spi_write(void *context, const void *data, size_t count)
{
struct ssd130x_spi_transport *t = context;
struct spi_device *spi = t->spi;
const u8 *reg = data;
if (*reg == SSD13XX_COMMAND)
gpiod_set_value_cansleep(t->dc, 0);
if (*reg == SSD13XX_DATA)
gpiod_set_value_cansleep(t->dc, 1);
/* Remove control byte since is not used in a 4-wire SPI interface */
return spi_write(spi, reg + 1, count - 1);
}
/* The ssd130x driver does not read registers but regmap expects a .read */
static int ssd130x_spi_read(void *context, const void *reg, size_t reg_size,
void *val, size_t val_size)
{
return -EOPNOTSUPP;
}
static const struct regmap_config ssd130x_spi_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.write = ssd130x_spi_write,
.read = ssd130x_spi_read,
.can_multi_write = true,
};
static int ssd130x_spi_probe(struct spi_device *spi)
{
struct ssd130x_spi_transport *t;
struct ssd130x_device *ssd130x;
struct regmap *regmap;
struct gpio_desc *dc;
struct device *dev = &spi->dev;
dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
if (IS_ERR(dc))
return dev_err_probe(dev, PTR_ERR(dc),
"Failed to get dc gpio\n");
t = devm_kzalloc(dev, sizeof(*t), GFP_KERNEL);
if (!t)
return -ENOMEM;
t->spi = spi;
t->dc = dc;
regmap = devm_regmap_init(dev, NULL, t, &ssd130x_spi_regmap_config);
if (IS_ERR(regmap))
return PTR_ERR(regmap);
ssd130x = ssd130x_probe(dev, regmap);
if (IS_ERR(ssd130x))
return PTR_ERR(ssd130x);
spi_set_drvdata(spi, ssd130x);
return 0;
}
static void ssd130x_spi_remove(struct spi_device *spi)
{
struct ssd130x_device *ssd130x = spi_get_drvdata(spi);
ssd130x_remove(ssd130x);
}
static void ssd130x_spi_shutdown(struct spi_device *spi)
{
struct ssd130x_device *ssd130x = spi_get_drvdata(spi);
ssd130x_shutdown(ssd130x);
}
static const struct of_device_id ssd130x_of_match[] = {
/* ssd130x family */
{
.compatible = "sinowealth,sh1106",
.data = &ssd130x_variants[SH1106_ID],
},
{
.compatible = "solomon,ssd1305",
.data = &ssd130x_variants[SSD1305_ID],
},
{
.compatible = "solomon,ssd1306",
.data = &ssd130x_variants[SSD1306_ID],
},
{
.compatible = "solomon,ssd1307",
.data = &ssd130x_variants[SSD1307_ID],
},
{
.compatible = "solomon,ssd1309",
.data = &ssd130x_variants[SSD1309_ID],
},
/* ssd132x family */
{
.compatible = "solomon,ssd1322",
.data = &ssd130x_variants[SSD1322_ID],
},
{
.compatible = "solomon,ssd1325",
.data = &ssd130x_variants[SSD1325_ID],
},
{
.compatible = "solomon,ssd1327",
.data = &ssd130x_variants[SSD1327_ID],
},
/* ssd133x family */
{
.compatible = "solomon,ssd1331",
.data = &ssd130x_variants[SSD1331_ID],
},
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, ssd130x_of_match);
/*
* The SPI core always reports a MODALIAS uevent of the form "spi:<dev>", even
* if the device was registered via OF. This means that the module will not be
* auto loaded, unless it contains an alias that matches the MODALIAS reported.
*
* To workaround this issue, add a SPI device ID table. Even when this should
* not be needed for this driver to match the registered SPI devices.
*/
static const struct spi_device_id ssd130x_spi_id[] = {
/* ssd130x family */
{ "sh1106", SH1106_ID },
{ "ssd1305", SSD1305_ID },
{ "ssd1306", SSD1306_ID },
{ "ssd1307", SSD1307_ID },
{ "ssd1309", SSD1309_ID },
/* ssd132x family */
{ "ssd1322", SSD1322_ID },
{ "ssd1325", SSD1325_ID },
{ "ssd1327", SSD1327_ID },
/* ssd133x family */
{ "ssd1331", SSD1331_ID },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(spi, ssd130x_spi_id);
static struct spi_driver ssd130x_spi_driver = {
.driver = {
.name = DRIVER_NAME,
.of_match_table = ssd130x_of_match,
},
.id_table = ssd130x_spi_id,
.probe = ssd130x_spi_probe,
.remove = ssd130x_spi_remove,
.shutdown = ssd130x_spi_shutdown,
};
module_spi_driver(ssd130x_spi_driver);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_AUTHOR("Javier Martinez Canillas <javierm@redhat.com>");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("DRM_SSD130X");
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,113 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Header file for:
* DRM driver for Solomon SSD130x OLED displays
*
* Copyright 2022 Red Hat Inc.
* Author: Javier Martinez Canillas <javierm@redhat.com>
*
* Based on drivers/video/fbdev/ssd1307fb.c
* Copyright 2012 Free Electrons
*/
#ifndef __SSD130X_H__
#define __SSD130X_H__
#include <drm/drm_connector.h>
#include <drm/drm_crtc.h>
#include <drm/drm_drv.h>
#include <drm/drm_encoder.h>
#include <linux/regmap.h>
#define SSD13XX_DATA 0x40
#define SSD13XX_COMMAND 0x80
enum ssd130x_family_ids {
SSD130X_FAMILY,
SSD132X_FAMILY,
SSD133X_FAMILY
};
enum ssd130x_variants {
/* ssd130x family */
SH1106_ID,
SSD1305_ID,
SSD1306_ID,
SSD1307_ID,
SSD1309_ID,
/* ssd132x family */
SSD1322_ID,
SSD1325_ID,
SSD1327_ID,
/* ssd133x family */
SSD1331_ID,
NR_SSD130X_VARIANTS
};
struct ssd130x_deviceinfo {
u32 default_vcomh;
u32 default_dclk_div;
u32 default_dclk_frq;
u32 default_width;
u32 default_height;
bool need_pwm;
bool need_chargepump;
bool page_mode_only;
enum ssd130x_family_ids family_id;
};
struct ssd130x_device {
struct drm_device drm;
struct device *dev;
struct drm_display_mode mode;
struct drm_plane primary_plane;
struct drm_crtc crtc;
struct drm_encoder encoder;
struct drm_connector connector;
struct i2c_client *client;
struct regmap *regmap;
const struct ssd130x_deviceinfo *device_info;
unsigned page_address_mode : 1;
unsigned area_color_enable : 1;
unsigned com_invdir : 1;
unsigned com_lrremap : 1;
unsigned com_seq : 1;
unsigned lookup_table_set : 1;
unsigned low_power : 1;
unsigned seg_remap : 1;
u32 com_offset;
u32 contrast;
u32 dclk_div;
u32 dclk_frq;
u32 height;
u8 lookup_table[4];
u32 page_offset;
u32 col_offset;
u32 prechargep1;
u32 prechargep2;
struct backlight_device *bl_dev;
struct pwm_device *pwm;
struct gpio_desc *reset;
struct regulator *vcc_reg;
u32 vcomh;
u32 width;
/* Cached address ranges */
u8 col_start;
u8 col_end;
u8 page_start;
u8 page_end;
};
extern const struct ssd130x_deviceinfo ssd130x_variants[];
struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap);
void ssd130x_remove(struct ssd130x_device *ssd130x);
void ssd130x_shutdown(struct ssd130x_device *ssd130x);
#endif /* __SSD130X_H__ */