1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * DRM driver for Solomon SSD130x OLED displays (I2C bus)
4  *
5  * Copyright 2022 Red Hat Inc.
6  * Author: Javier Martinez Canillas <javierm@redhat.com>
7  *
8  * Based on drivers/video/fbdev/ssd1307fb.c
9  * Copyright 2012 Free Electrons
10  */
11 #include <linux/i2c.h>
12 #include <linux/module.h>
13 
14 #include "ssd130x.h"
15 
16 #define DRIVER_NAME	"ssd130x-i2c"
17 #define DRIVER_DESC	"DRM driver for Solomon SSD130x OLED displays (I2C)"
18 
19 static const struct regmap_config ssd130x_i2c_regmap_config = {
20 	.reg_bits = 8,
21 	.val_bits = 8,
22 };
23 
24 static int ssd130x_i2c_probe(struct i2c_client *client)
25 {
26 	struct ssd130x_device *ssd130x;
27 	struct regmap *regmap;
28 
29 	regmap = devm_regmap_init_i2c(client, &ssd130x_i2c_regmap_config);
30 	if (IS_ERR(regmap))
31 		return PTR_ERR(regmap);
32 
33 	ssd130x = ssd130x_probe(&client->dev, regmap);
34 	if (IS_ERR(ssd130x))
35 		return PTR_ERR(ssd130x);
36 
37 	i2c_set_clientdata(client, ssd130x);
38 
39 	return 0;
40 }
41 
42 static int ssd130x_i2c_remove(struct i2c_client *client)
43 {
44 	struct ssd130x_device *ssd130x = i2c_get_clientdata(client);
45 
46 	return ssd130x_remove(ssd130x);
47 }
48 
49 static void ssd130x_i2c_shutdown(struct i2c_client *client)
50 {
51 	struct ssd130x_device *ssd130x = i2c_get_clientdata(client);
52 
53 	ssd130x_shutdown(ssd130x);
54 }
55 
56 static struct ssd130x_deviceinfo ssd130x_ssd1305_deviceinfo = {
57 	.default_vcomh = 0x34,
58 	.default_dclk_div = 1,
59 	.default_dclk_frq = 7,
60 };
61 
62 static struct ssd130x_deviceinfo ssd130x_ssd1306_deviceinfo = {
63 	.default_vcomh = 0x20,
64 	.default_dclk_div = 1,
65 	.default_dclk_frq = 8,
66 	.need_chargepump = 1,
67 };
68 
69 static struct ssd130x_deviceinfo ssd130x_ssd1307_deviceinfo = {
70 	.default_vcomh = 0x20,
71 	.default_dclk_div = 2,
72 	.default_dclk_frq = 12,
73 	.need_pwm = 1,
74 };
75 
76 static struct ssd130x_deviceinfo ssd130x_ssd1309_deviceinfo = {
77 	.default_vcomh = 0x34,
78 	.default_dclk_div = 1,
79 	.default_dclk_frq = 10,
80 };
81 
82 static const struct of_device_id ssd130x_of_match[] = {
83 	{
84 		.compatible = "solomon,ssd1305fb-i2c",
85 		.data = &ssd130x_ssd1305_deviceinfo,
86 	},
87 	{
88 		.compatible = "solomon,ssd1306fb-i2c",
89 		.data = &ssd130x_ssd1306_deviceinfo,
90 	},
91 	{
92 		.compatible = "solomon,ssd1307fb-i2c",
93 		.data = &ssd130x_ssd1307_deviceinfo,
94 	},
95 	{
96 		.compatible = "solomon,ssd1309fb-i2c",
97 		.data = &ssd130x_ssd1309_deviceinfo,
98 	},
99 	{ /* sentinel */ }
100 };
101 MODULE_DEVICE_TABLE(of, ssd130x_of_match);
102 
103 static struct i2c_driver ssd130x_i2c_driver = {
104 	.driver = {
105 		.name = DRIVER_NAME,
106 		.of_match_table = ssd130x_of_match,
107 	},
108 	.probe_new = ssd130x_i2c_probe,
109 	.remove = ssd130x_i2c_remove,
110 	.shutdown = ssd130x_i2c_shutdown,
111 };
112 module_i2c_driver(ssd130x_i2c_driver);
113 
114 MODULE_DESCRIPTION(DRIVER_DESC);
115 MODULE_AUTHOR("Javier Martinez Canillas <javierm@redhat.com>");
116 MODULE_LICENSE("GPL v2");
117