summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/solomon/ssd130x-i2c.c
blob: 45867ef2bc8b2d54be00acb5b92589049a0f24b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// SPDX-License-Identifier: GPL-2.0-only
/*
 * DRM driver for Solomon SSD130x 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 SSD130x 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 int ssd130x_i2c_remove(struct i2c_client *client)
{
	struct ssd130x_device *ssd130x = i2c_get_clientdata(client);

	return ssd130x_remove(ssd130x);
}

static void ssd130x_i2c_shutdown(struct i2c_client *client)
{
	struct ssd130x_device *ssd130x = i2c_get_clientdata(client);

	ssd130x_shutdown(ssd130x);
}

static struct ssd130x_deviceinfo ssd130x_sh1106_deviceinfo = {
	.default_vcomh = 0x40,
	.default_dclk_div = 1,
	.default_dclk_frq = 5,
	.page_mode_only = 1,
};

static struct ssd130x_deviceinfo ssd130x_ssd1305_deviceinfo = {
	.default_vcomh = 0x34,
	.default_dclk_div = 1,
	.default_dclk_frq = 7,
};

static struct ssd130x_deviceinfo ssd130x_ssd1306_deviceinfo = {
	.default_vcomh = 0x20,
	.default_dclk_div = 1,
	.default_dclk_frq = 8,
	.need_chargepump = 1,
};

static struct ssd130x_deviceinfo ssd130x_ssd1307_deviceinfo = {
	.default_vcomh = 0x20,
	.default_dclk_div = 2,
	.default_dclk_frq = 12,
	.need_pwm = 1,
};

static struct ssd130x_deviceinfo ssd130x_ssd1309_deviceinfo = {
	.default_vcomh = 0x34,
	.default_dclk_div = 1,
	.default_dclk_frq = 10,
};

static const struct of_device_id ssd130x_of_match[] = {
	{
		.compatible = "sinowealth,sh1106",
		.data = &ssd130x_sh1106_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1305",
		.data = &ssd130x_ssd1305_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1306",
		.data = &ssd130x_ssd1306_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1307",
		.data = &ssd130x_ssd1307_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1309",
		.data = &ssd130x_ssd1309_deviceinfo,
	},
	/* Deprecated but kept for backward compatibility */
	{
		.compatible = "solomon,ssd1305fb-i2c",
		.data = &ssd130x_ssd1305_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1306fb-i2c",
		.data = &ssd130x_ssd1306_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1307fb-i2c",
		.data = &ssd130x_ssd1307_deviceinfo,
	},
	{
		.compatible = "solomon,ssd1309fb-i2c",
		.data = &ssd130x_ssd1309_deviceinfo,
	},
	{ /* 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_new = 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");