Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 1 | /* |
Masanari Iida | a895d57 | 2013-04-09 02:06:50 +0900 | [diff] [blame] | 2 | * Driver for the Solomon SSD1307 OLED controller |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2012 Free Electrons |
| 5 | * |
| 6 | * Licensed under the GPLv2 or later. |
| 7 | */ |
| 8 | |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 9 | #include <linux/backlight.h> |
Olliver Schinagl | 48846ec | 2015-09-08 21:19:50 +0200 | [diff] [blame] | 10 | #include <linux/delay.h> |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 11 | #include <linux/fb.h> |
Olliver Schinagl | 48846ec | 2015-09-08 21:19:50 +0200 | [diff] [blame] | 12 | #include <linux/i2c.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 15 | #include <linux/of_device.h> |
| 16 | #include <linux/of_gpio.h> |
| 17 | #include <linux/pwm.h> |
Olliver Schinagl | 48846ec | 2015-09-08 21:19:50 +0200 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 19 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 20 | #define SSD1307FB_DATA 0x40 |
| 21 | #define SSD1307FB_COMMAND 0x80 |
| 22 | |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 23 | #define SSD1307FB_SET_ADDRESS_MODE 0x20 |
| 24 | #define SSD1307FB_SET_ADDRESS_MODE_HORIZONTAL (0x00) |
| 25 | #define SSD1307FB_SET_ADDRESS_MODE_VERTICAL (0x01) |
| 26 | #define SSD1307FB_SET_ADDRESS_MODE_PAGE (0x02) |
| 27 | #define SSD1307FB_SET_COL_RANGE 0x21 |
| 28 | #define SSD1307FB_SET_PAGE_RANGE 0x22 |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 29 | #define SSD1307FB_CONTRAST 0x81 |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 30 | #define SSD1307FB_CHARGE_PUMP 0x8d |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 31 | #define SSD1307FB_SEG_REMAP_ON 0xa1 |
| 32 | #define SSD1307FB_DISPLAY_OFF 0xae |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 33 | #define SSD1307FB_SET_MULTIPLEX_RATIO 0xa8 |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 34 | #define SSD1307FB_DISPLAY_ON 0xaf |
| 35 | #define SSD1307FB_START_PAGE_ADDRESS 0xb0 |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 36 | #define SSD1307FB_SET_DISPLAY_OFFSET 0xd3 |
| 37 | #define SSD1307FB_SET_CLOCK_FREQ 0xd5 |
| 38 | #define SSD1307FB_SET_PRECHARGE_PERIOD 0xd9 |
| 39 | #define SSD1307FB_SET_COM_PINS_CONFIG 0xda |
| 40 | #define SSD1307FB_SET_VCOMH 0xdb |
| 41 | |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 42 | #define MAX_CONTRAST 255 |
| 43 | |
Thomas Niederprüm | 3277e0b | 2015-03-31 20:27:13 +0200 | [diff] [blame] | 44 | #define REFRESHRATE 1 |
| 45 | |
| 46 | static u_int refreshrate = REFRESHRATE; |
| 47 | module_param(refreshrate, uint, 0); |
| 48 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 49 | struct ssd1307fb_par; |
| 50 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 51 | struct ssd1307fb_deviceinfo { |
| 52 | u32 default_vcomh; |
| 53 | u32 default_dclk_div; |
| 54 | u32 default_dclk_frq; |
| 55 | int need_pwm; |
| 56 | int need_chargepump; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 57 | }; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 58 | |
| 59 | struct ssd1307fb_par { |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 60 | u32 com_invdir; |
| 61 | u32 com_lrremap; |
| 62 | u32 com_offset; |
| 63 | u32 com_seq; |
| 64 | u32 contrast; |
| 65 | u32 dclk_div; |
| 66 | u32 dclk_frq; |
| 67 | struct ssd1307fb_deviceinfo *device_info; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 68 | struct i2c_client *client; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 69 | u32 height; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 70 | struct fb_info *info; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 71 | u32 page_offset; |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 72 | u32 prechargep1; |
| 73 | u32 prechargep2; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 74 | struct pwm_device *pwm; |
| 75 | u32 pwm_period; |
| 76 | int reset; |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 77 | u32 seg_remap; |
| 78 | u32 vcomh; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 79 | u32 width; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 82 | struct ssd1307fb_array { |
| 83 | u8 type; |
| 84 | u8 data[0]; |
| 85 | }; |
| 86 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 87 | static struct fb_fix_screeninfo ssd1307fb_fix = { |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 88 | .id = "Solomon SSD1307", |
| 89 | .type = FB_TYPE_PACKED_PIXELS, |
| 90 | .visual = FB_VISUAL_MONO10, |
| 91 | .xpanstep = 0, |
| 92 | .ypanstep = 0, |
| 93 | .ywrapstep = 0, |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 94 | .accel = FB_ACCEL_NONE, |
| 95 | }; |
| 96 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 97 | static struct fb_var_screeninfo ssd1307fb_var = { |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 98 | .bits_per_pixel = 1, |
| 99 | }; |
| 100 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 101 | static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type) |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 102 | { |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 103 | struct ssd1307fb_array *array; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 104 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 105 | array = kzalloc(sizeof(struct ssd1307fb_array) + len, GFP_KERNEL); |
| 106 | if (!array) |
| 107 | return NULL; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 108 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 109 | array->type = type; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 110 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 111 | return array; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 114 | static int ssd1307fb_write_array(struct i2c_client *client, |
| 115 | struct ssd1307fb_array *array, u32 len) |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 116 | { |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 117 | int ret; |
| 118 | |
| 119 | len += sizeof(struct ssd1307fb_array); |
| 120 | |
| 121 | ret = i2c_master_send(client, (u8 *)array, len); |
| 122 | if (ret != len) { |
| 123 | dev_err(&client->dev, "Couldn't send I2C command.\n"); |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | return 0; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static inline int ssd1307fb_write_cmd(struct i2c_client *client, u8 cmd) |
| 131 | { |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 132 | struct ssd1307fb_array *array; |
| 133 | int ret; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 134 | |
Maxime Ripard | 9f7714d | 2013-04-22 12:02:23 +0200 | [diff] [blame] | 135 | array = ssd1307fb_alloc_array(1, SSD1307FB_COMMAND); |
| 136 | if (!array) |
| 137 | return -ENOMEM; |
| 138 | |
| 139 | array->data[0] = cmd; |
| 140 | |
| 141 | ret = ssd1307fb_write_array(client, array, 1); |
| 142 | kfree(array); |
| 143 | |
| 144 | return ret; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 147 | static void ssd1307fb_update_display(struct ssd1307fb_par *par) |
| 148 | { |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 149 | struct ssd1307fb_array *array; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 150 | u8 *vmem = par->info->screen_base; |
| 151 | int i, j, k; |
| 152 | |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 153 | array = ssd1307fb_alloc_array(par->width * par->height / 8, |
| 154 | SSD1307FB_DATA); |
| 155 | if (!array) |
| 156 | return; |
| 157 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 158 | /* |
| 159 | * The screen is divided in pages, each having a height of 8 |
| 160 | * pixels, and the width of the screen. When sending a byte of |
| 161 | * data to the controller, it gives the 8 bits for the current |
| 162 | * column. I.e, the first byte are the 8 bits of the first |
| 163 | * column, then the 8 bits for the second column, etc. |
| 164 | * |
| 165 | * |
| 166 | * Representation of the screen, assuming it is 5 bits |
| 167 | * wide. Each letter-number combination is a bit that controls |
| 168 | * one pixel. |
| 169 | * |
| 170 | * A0 A1 A2 A3 A4 |
| 171 | * B0 B1 B2 B3 B4 |
| 172 | * C0 C1 C2 C3 C4 |
| 173 | * D0 D1 D2 D3 D4 |
| 174 | * E0 E1 E2 E3 E4 |
| 175 | * F0 F1 F2 F3 F4 |
| 176 | * G0 G1 G2 G3 G4 |
| 177 | * H0 H1 H2 H3 H4 |
| 178 | * |
| 179 | * If you want to update this screen, you need to send 5 bytes: |
| 180 | * (1) A0 B0 C0 D0 E0 F0 G0 H0 |
| 181 | * (2) A1 B1 C1 D1 E1 F1 G1 H1 |
| 182 | * (3) A2 B2 C2 D2 E2 F2 G2 H2 |
| 183 | * (4) A3 B3 C3 D3 E3 F3 G3 H3 |
| 184 | * (5) A4 B4 C4 D4 E4 F4 G4 H4 |
| 185 | */ |
| 186 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 187 | for (i = 0; i < (par->height / 8); i++) { |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 188 | for (j = 0; j < par->width; j++) { |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 189 | u32 array_idx = i * par->width + j; |
| 190 | array->data[array_idx] = 0; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 191 | for (k = 0; k < 8; k++) { |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 192 | u32 page_length = par->width * i; |
| 193 | u32 index = page_length + (par->width * k + j) / 8; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 194 | u8 byte = *(vmem + index); |
Maxime Ripard | 552f0cc | 2013-01-11 14:31:43 -0800 | [diff] [blame] | 195 | u8 bit = byte & (1 << (j % 8)); |
| 196 | bit = bit >> (j % 8); |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 197 | array->data[array_idx] |= bit << k; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 198 | } |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 199 | } |
| 200 | } |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 201 | |
| 202 | ssd1307fb_write_array(par->client, array, par->width * par->height / 8); |
| 203 | kfree(array); |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
| 207 | static ssize_t ssd1307fb_write(struct fb_info *info, const char __user *buf, |
| 208 | size_t count, loff_t *ppos) |
| 209 | { |
| 210 | struct ssd1307fb_par *par = info->par; |
| 211 | unsigned long total_size; |
| 212 | unsigned long p = *ppos; |
| 213 | u8 __iomem *dst; |
| 214 | |
| 215 | total_size = info->fix.smem_len; |
| 216 | |
| 217 | if (p > total_size) |
| 218 | return -EINVAL; |
| 219 | |
| 220 | if (count + p > total_size) |
| 221 | count = total_size - p; |
| 222 | |
| 223 | if (!count) |
| 224 | return -EINVAL; |
| 225 | |
| 226 | dst = (void __force *) (info->screen_base + p); |
| 227 | |
| 228 | if (copy_from_user(dst, buf, count)) |
| 229 | return -EFAULT; |
| 230 | |
| 231 | ssd1307fb_update_display(par); |
| 232 | |
| 233 | *ppos += count; |
| 234 | |
| 235 | return count; |
| 236 | } |
| 237 | |
Thomas Niederprüm | 550e768 | 2015-03-31 20:27:16 +0200 | [diff] [blame] | 238 | static int ssd1307fb_blank(int blank_mode, struct fb_info *info) |
| 239 | { |
| 240 | struct ssd1307fb_par *par = info->par; |
| 241 | |
| 242 | if (blank_mode != FB_BLANK_UNBLANK) |
| 243 | return ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_OFF); |
| 244 | else |
| 245 | return ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_ON); |
| 246 | } |
| 247 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 248 | static void ssd1307fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) |
| 249 | { |
| 250 | struct ssd1307fb_par *par = info->par; |
| 251 | sys_fillrect(info, rect); |
| 252 | ssd1307fb_update_display(par); |
| 253 | } |
| 254 | |
| 255 | static void ssd1307fb_copyarea(struct fb_info *info, const struct fb_copyarea *area) |
| 256 | { |
| 257 | struct ssd1307fb_par *par = info->par; |
| 258 | sys_copyarea(info, area); |
| 259 | ssd1307fb_update_display(par); |
| 260 | } |
| 261 | |
| 262 | static void ssd1307fb_imageblit(struct fb_info *info, const struct fb_image *image) |
| 263 | { |
| 264 | struct ssd1307fb_par *par = info->par; |
| 265 | sys_imageblit(info, image); |
| 266 | ssd1307fb_update_display(par); |
| 267 | } |
| 268 | |
| 269 | static struct fb_ops ssd1307fb_ops = { |
| 270 | .owner = THIS_MODULE, |
| 271 | .fb_read = fb_sys_read, |
| 272 | .fb_write = ssd1307fb_write, |
Thomas Niederprüm | 550e768 | 2015-03-31 20:27:16 +0200 | [diff] [blame] | 273 | .fb_blank = ssd1307fb_blank, |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 274 | .fb_fillrect = ssd1307fb_fillrect, |
| 275 | .fb_copyarea = ssd1307fb_copyarea, |
| 276 | .fb_imageblit = ssd1307fb_imageblit, |
| 277 | }; |
| 278 | |
| 279 | static void ssd1307fb_deferred_io(struct fb_info *info, |
| 280 | struct list_head *pagelist) |
| 281 | { |
| 282 | ssd1307fb_update_display(info->par); |
| 283 | } |
| 284 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 285 | static int ssd1307fb_init(struct ssd1307fb_par *par) |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 286 | { |
| 287 | int ret; |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 288 | u32 precharge, dclk, com_invdir, compins; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 289 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 290 | if (par->device_info->need_pwm) { |
| 291 | par->pwm = pwm_get(&par->client->dev, NULL); |
| 292 | if (IS_ERR(par->pwm)) { |
| 293 | dev_err(&par->client->dev, "Could not get PWM from device tree!\n"); |
| 294 | return PTR_ERR(par->pwm); |
| 295 | } |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 296 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 297 | par->pwm_period = pwm_get_period(par->pwm); |
| 298 | /* Enable the PWM */ |
| 299 | pwm_config(par->pwm, par->pwm_period / 2, par->pwm_period); |
| 300 | pwm_enable(par->pwm); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 301 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 302 | dev_dbg(&par->client->dev, "Using PWM%d with a %dns period.\n", |
| 303 | par->pwm->pwm, par->pwm_period); |
| 304 | }; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 305 | |
| 306 | /* Set initial contrast */ |
| 307 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CONTRAST); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 308 | if (ret < 0) |
| 309 | return ret; |
| 310 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 311 | ret = ssd1307fb_write_cmd(par->client, par->contrast); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 312 | if (ret < 0) |
| 313 | return ret; |
| 314 | |
| 315 | /* Set segment re-map */ |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 316 | if (par->seg_remap) { |
| 317 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SEG_REMAP_ON); |
| 318 | if (ret < 0) |
| 319 | return ret; |
| 320 | }; |
| 321 | |
| 322 | /* Set COM direction */ |
| 323 | com_invdir = 0xc0 | (par->com_invdir & 0x1) << 3; |
| 324 | ret = ssd1307fb_write_cmd(par->client, com_invdir); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 325 | if (ret < 0) |
| 326 | return ret; |
| 327 | |
| 328 | /* Set multiplex ratio value */ |
| 329 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_MULTIPLEX_RATIO); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 330 | if (ret < 0) |
| 331 | return ret; |
| 332 | |
| 333 | ret = ssd1307fb_write_cmd(par->client, par->height - 1); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 334 | if (ret < 0) |
| 335 | return ret; |
| 336 | |
| 337 | /* set display offset value */ |
| 338 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_DISPLAY_OFFSET); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 339 | if (ret < 0) |
| 340 | return ret; |
| 341 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 342 | ret = ssd1307fb_write_cmd(par->client, par->com_offset); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 343 | if (ret < 0) |
| 344 | return ret; |
| 345 | |
| 346 | /* Set clock frequency */ |
| 347 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_CLOCK_FREQ); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 348 | if (ret < 0) |
| 349 | return ret; |
| 350 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 351 | dclk = ((par->dclk_div - 1) & 0xf) | (par->dclk_frq & 0xf) << 4; |
| 352 | ret = ssd1307fb_write_cmd(par->client, dclk); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 353 | if (ret < 0) |
| 354 | return ret; |
| 355 | |
| 356 | /* Set precharge period in number of ticks from the internal clock */ |
| 357 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PRECHARGE_PERIOD); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 358 | if (ret < 0) |
| 359 | return ret; |
| 360 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 361 | precharge = (par->prechargep1 & 0xf) | (par->prechargep2 & 0xf) << 4; |
| 362 | ret = ssd1307fb_write_cmd(par->client, precharge); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 363 | if (ret < 0) |
| 364 | return ret; |
| 365 | |
| 366 | /* Set COM pins configuration */ |
| 367 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COM_PINS_CONFIG); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 368 | if (ret < 0) |
| 369 | return ret; |
| 370 | |
Thomas Niederprüm | 5e47932 | 2015-05-25 21:29:21 +0200 | [diff] [blame] | 371 | compins = 0x02 | !(par->com_seq & 0x1) << 4 |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 372 | | (par->com_lrremap & 0x1) << 5; |
| 373 | ret = ssd1307fb_write_cmd(par->client, compins); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 374 | if (ret < 0) |
| 375 | return ret; |
| 376 | |
| 377 | /* Set VCOMH */ |
| 378 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_VCOMH); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 379 | if (ret < 0) |
| 380 | return ret; |
| 381 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 382 | ret = ssd1307fb_write_cmd(par->client, par->vcomh); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 383 | if (ret < 0) |
| 384 | return ret; |
| 385 | |
| 386 | /* Turn on the DC-DC Charge Pump */ |
| 387 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CHARGE_PUMP); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 388 | if (ret < 0) |
| 389 | return ret; |
| 390 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 391 | ret = ssd1307fb_write_cmd(par->client, |
| 392 | (par->device_info->need_chargepump & 0x1 << 2) & 0x14); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 393 | if (ret < 0) |
| 394 | return ret; |
| 395 | |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 396 | /* Switch to horizontal addressing mode */ |
| 397 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_ADDRESS_MODE); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 398 | if (ret < 0) |
| 399 | return ret; |
| 400 | |
| 401 | ret = ssd1307fb_write_cmd(par->client, |
| 402 | SSD1307FB_SET_ADDRESS_MODE_HORIZONTAL); |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 403 | if (ret < 0) |
| 404 | return ret; |
| 405 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 406 | /* Set column range */ |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 407 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COL_RANGE); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 408 | if (ret < 0) |
| 409 | return ret; |
| 410 | |
| 411 | ret = ssd1307fb_write_cmd(par->client, 0x0); |
| 412 | if (ret < 0) |
| 413 | return ret; |
| 414 | |
| 415 | ret = ssd1307fb_write_cmd(par->client, par->width - 1); |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 416 | if (ret < 0) |
| 417 | return ret; |
| 418 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 419 | /* Set page range */ |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 420 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PAGE_RANGE); |
Prabhakar Lad | 5b72ae9 | 2015-01-15 19:05:37 +0000 | [diff] [blame] | 421 | if (ret < 0) |
| 422 | return ret; |
| 423 | |
| 424 | ret = ssd1307fb_write_cmd(par->client, 0x0); |
| 425 | if (ret < 0) |
| 426 | return ret; |
| 427 | |
| 428 | ret = ssd1307fb_write_cmd(par->client, |
| 429 | par->page_offset + (par->height / 8) - 1); |
Maxime Ripard | 301bc06 | 2013-04-22 12:02:25 +0200 | [diff] [blame] | 430 | if (ret < 0) |
| 431 | return ret; |
| 432 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 433 | /* Turn on the display */ |
| 434 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_ON); |
| 435 | if (ret < 0) |
| 436 | return ret; |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 441 | static int ssd1307fb_update_bl(struct backlight_device *bdev) |
| 442 | { |
| 443 | struct ssd1307fb_par *par = bl_get_data(bdev); |
| 444 | int ret; |
| 445 | int brightness = bdev->props.brightness; |
| 446 | |
| 447 | par->contrast = brightness; |
| 448 | |
| 449 | ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CONTRAST); |
| 450 | if (ret < 0) |
| 451 | return ret; |
| 452 | ret = ssd1307fb_write_cmd(par->client, par->contrast); |
| 453 | if (ret < 0) |
| 454 | return ret; |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int ssd1307fb_get_brightness(struct backlight_device *bdev) |
| 459 | { |
| 460 | struct ssd1307fb_par *par = bl_get_data(bdev); |
| 461 | |
| 462 | return par->contrast; |
| 463 | } |
| 464 | |
| 465 | static int ssd1307fb_check_fb(struct backlight_device *bdev, |
| 466 | struct fb_info *info) |
| 467 | { |
| 468 | return (info->bl_dev == bdev); |
| 469 | } |
| 470 | |
| 471 | static const struct backlight_ops ssd1307fb_bl_ops = { |
| 472 | .options = BL_CORE_SUSPENDRESUME, |
| 473 | .update_status = ssd1307fb_update_bl, |
| 474 | .get_brightness = ssd1307fb_get_brightness, |
| 475 | .check_fb = ssd1307fb_check_fb, |
| 476 | }; |
| 477 | |
Thomas Niederprüm | 5f2d36b | 2015-03-31 20:27:12 +0200 | [diff] [blame] | 478 | static struct ssd1307fb_deviceinfo ssd1307fb_ssd1305_deviceinfo = { |
| 479 | .default_vcomh = 0x34, |
| 480 | .default_dclk_div = 1, |
| 481 | .default_dclk_frq = 7, |
| 482 | }; |
| 483 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 484 | static struct ssd1307fb_deviceinfo ssd1307fb_ssd1306_deviceinfo = { |
| 485 | .default_vcomh = 0x20, |
| 486 | .default_dclk_div = 1, |
| 487 | .default_dclk_frq = 8, |
| 488 | .need_chargepump = 1, |
| 489 | }; |
| 490 | |
| 491 | static struct ssd1307fb_deviceinfo ssd1307fb_ssd1307_deviceinfo = { |
| 492 | .default_vcomh = 0x20, |
| 493 | .default_dclk_div = 2, |
| 494 | .default_dclk_frq = 12, |
| 495 | .need_pwm = 1, |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 496 | }; |
| 497 | |
Olliver Schinagl | 3ac58d5 | 2015-09-08 21:19:51 +0200 | [diff] [blame] | 498 | static struct ssd1307fb_deviceinfo ssd1307fb_ssd1309_deviceinfo = { |
| 499 | .default_vcomh = 0x34, |
| 500 | .default_dclk_div = 1, |
| 501 | .default_dclk_frq = 10, |
| 502 | }; |
| 503 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 504 | static const struct of_device_id ssd1307fb_of_match[] = { |
| 505 | { |
Thomas Niederprüm | 5f2d36b | 2015-03-31 20:27:12 +0200 | [diff] [blame] | 506 | .compatible = "solomon,ssd1305fb-i2c", |
| 507 | .data = (void *)&ssd1307fb_ssd1305_deviceinfo, |
| 508 | }, |
| 509 | { |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 510 | .compatible = "solomon,ssd1306fb-i2c", |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 511 | .data = (void *)&ssd1307fb_ssd1306_deviceinfo, |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 512 | }, |
| 513 | { |
| 514 | .compatible = "solomon,ssd1307fb-i2c", |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 515 | .data = (void *)&ssd1307fb_ssd1307_deviceinfo, |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 516 | }, |
Olliver Schinagl | 3ac58d5 | 2015-09-08 21:19:51 +0200 | [diff] [blame] | 517 | { |
| 518 | .compatible = "solomon,ssd1309fb-i2c", |
| 519 | .data = (void *)&ssd1307fb_ssd1309_deviceinfo, |
| 520 | }, |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 521 | {}, |
| 522 | }; |
| 523 | MODULE_DEVICE_TABLE(of, ssd1307fb_of_match); |
| 524 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 525 | static int ssd1307fb_probe(struct i2c_client *client, |
| 526 | const struct i2c_device_id *id) |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 527 | { |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 528 | struct backlight_device *bl; |
| 529 | char bl_name[12]; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 530 | struct fb_info *info; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 531 | struct device_node *node = client->dev.of_node; |
Thomas Niederprüm | 3277e0b | 2015-03-31 20:27:13 +0200 | [diff] [blame] | 532 | struct fb_deferred_io *ssd1307fb_defio; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 533 | u32 vmem_size; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 534 | struct ssd1307fb_par *par; |
| 535 | u8 *vmem; |
| 536 | int ret; |
| 537 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 538 | if (!node) { |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 539 | dev_err(&client->dev, "No device tree data found!\n"); |
| 540 | return -EINVAL; |
| 541 | } |
| 542 | |
| 543 | info = framebuffer_alloc(sizeof(struct ssd1307fb_par), &client->dev); |
| 544 | if (!info) { |
| 545 | dev_err(&client->dev, "Couldn't allocate framebuffer.\n"); |
| 546 | return -ENOMEM; |
| 547 | } |
| 548 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 549 | par = info->par; |
| 550 | par->info = info; |
| 551 | par->client = client; |
| 552 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 553 | par->device_info = (struct ssd1307fb_deviceinfo *)of_match_device( |
| 554 | ssd1307fb_of_match, &client->dev)->data; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 555 | |
| 556 | par->reset = of_get_named_gpio(client->dev.of_node, |
| 557 | "reset-gpios", 0); |
| 558 | if (!gpio_is_valid(par->reset)) { |
| 559 | ret = -EINVAL; |
| 560 | goto fb_alloc_error; |
| 561 | } |
| 562 | |
| 563 | if (of_property_read_u32(node, "solomon,width", &par->width)) |
| 564 | par->width = 96; |
| 565 | |
| 566 | if (of_property_read_u32(node, "solomon,height", &par->height)) |
Lad, Prabhakar | 9561def | 2015-01-08 08:17:58 +0000 | [diff] [blame] | 567 | par->height = 16; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 568 | |
| 569 | if (of_property_read_u32(node, "solomon,page-offset", &par->page_offset)) |
| 570 | par->page_offset = 1; |
| 571 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 572 | if (of_property_read_u32(node, "solomon,com-offset", &par->com_offset)) |
| 573 | par->com_offset = 0; |
| 574 | |
| 575 | if (of_property_read_u32(node, "solomon,prechargep1", &par->prechargep1)) |
| 576 | par->prechargep1 = 2; |
| 577 | |
| 578 | if (of_property_read_u32(node, "solomon,prechargep2", &par->prechargep2)) |
| 579 | par->prechargep2 = 2; |
| 580 | |
| 581 | par->seg_remap = !of_property_read_bool(node, "solomon,segment-no-remap"); |
| 582 | par->com_seq = of_property_read_bool(node, "solomon,com-seq"); |
| 583 | par->com_lrremap = of_property_read_bool(node, "solomon,com-lrremap"); |
| 584 | par->com_invdir = of_property_read_bool(node, "solomon,com-invdir"); |
| 585 | |
| 586 | par->contrast = 127; |
| 587 | par->vcomh = par->device_info->default_vcomh; |
| 588 | |
| 589 | /* Setup display timing */ |
| 590 | par->dclk_div = par->device_info->default_dclk_div; |
| 591 | par->dclk_frq = par->device_info->default_dclk_frq; |
| 592 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 593 | vmem_size = par->width * par->height / 8; |
| 594 | |
Thomas Niederprüm | facd94b | 2015-03-31 20:27:08 +0200 | [diff] [blame] | 595 | vmem = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 596 | get_order(vmem_size)); |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 597 | if (!vmem) { |
| 598 | dev_err(&client->dev, "Couldn't allocate graphical memory.\n"); |
| 599 | ret = -ENOMEM; |
| 600 | goto fb_alloc_error; |
| 601 | } |
| 602 | |
Thomas Niederprüm | 3277e0b | 2015-03-31 20:27:13 +0200 | [diff] [blame] | 603 | ssd1307fb_defio = devm_kzalloc(&client->dev, sizeof(struct fb_deferred_io), GFP_KERNEL); |
| 604 | if (!ssd1307fb_defio) { |
| 605 | dev_err(&client->dev, "Couldn't allocate deferred io.\n"); |
| 606 | ret = -ENOMEM; |
| 607 | goto fb_alloc_error; |
| 608 | } |
| 609 | |
| 610 | ssd1307fb_defio->delay = HZ / refreshrate; |
| 611 | ssd1307fb_defio->deferred_io = ssd1307fb_deferred_io; |
| 612 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 613 | info->fbops = &ssd1307fb_ops; |
| 614 | info->fix = ssd1307fb_fix; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 615 | info->fix.line_length = par->width / 8; |
Thomas Niederprüm | 3277e0b | 2015-03-31 20:27:13 +0200 | [diff] [blame] | 616 | info->fbdefio = ssd1307fb_defio; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 617 | |
| 618 | info->var = ssd1307fb_var; |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 619 | info->var.xres = par->width; |
| 620 | info->var.xres_virtual = par->width; |
| 621 | info->var.yres = par->height; |
| 622 | info->var.yres_virtual = par->height; |
| 623 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 624 | info->var.red.length = 1; |
| 625 | info->var.red.offset = 0; |
| 626 | info->var.green.length = 1; |
| 627 | info->var.green.offset = 0; |
| 628 | info->var.blue.length = 1; |
| 629 | info->var.blue.offset = 0; |
| 630 | |
| 631 | info->screen_base = (u8 __force __iomem *)vmem; |
Thomas Niederprüm | 258c0ea | 2015-03-31 20:27:07 +0200 | [diff] [blame] | 632 | info->fix.smem_start = __pa(vmem); |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 633 | info->fix.smem_len = vmem_size; |
| 634 | |
| 635 | fb_deferred_io_init(info); |
| 636 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 637 | ret = devm_gpio_request_one(&client->dev, par->reset, |
| 638 | GPIOF_OUT_INIT_HIGH, |
| 639 | "oled-reset"); |
| 640 | if (ret) { |
| 641 | dev_err(&client->dev, |
| 642 | "failed to request gpio %d: %d\n", |
| 643 | par->reset, ret); |
| 644 | goto reset_oled_error; |
| 645 | } |
| 646 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 647 | i2c_set_clientdata(client, info); |
| 648 | |
| 649 | /* Reset the screen */ |
| 650 | gpio_set_value(par->reset, 0); |
| 651 | udelay(4); |
| 652 | gpio_set_value(par->reset, 1); |
| 653 | udelay(4); |
| 654 | |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 655 | ret = ssd1307fb_init(par); |
| 656 | if (ret) |
| 657 | goto reset_oled_error; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 658 | |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 659 | ret = register_framebuffer(info); |
| 660 | if (ret) { |
| 661 | dev_err(&client->dev, "Couldn't register the framebuffer\n"); |
| 662 | goto panel_init_error; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 665 | snprintf(bl_name, sizeof(bl_name), "ssd1307fb%d", info->node); |
| 666 | bl = backlight_device_register(bl_name, &client->dev, par, |
| 667 | &ssd1307fb_bl_ops, NULL); |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 668 | if (IS_ERR(bl)) { |
Julia Lawall | c4e6774 | 2015-08-23 02:11:15 +0200 | [diff] [blame] | 669 | ret = PTR_ERR(bl); |
| 670 | dev_err(&client->dev, "unable to register backlight device: %d\n", |
| 671 | ret); |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 672 | goto bl_init_error; |
| 673 | } |
Dan Carpenter | c2b0002 | 2015-05-23 20:32:35 +0300 | [diff] [blame] | 674 | |
| 675 | bl->props.brightness = par->contrast; |
| 676 | bl->props.max_brightness = MAX_CONTRAST; |
| 677 | info->bl_dev = bl; |
| 678 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 679 | dev_info(&client->dev, "fb%d: %s framebuffer device registered, using %d bytes of video memory\n", info->node, info->fix.id, vmem_size); |
| 680 | |
| 681 | return 0; |
| 682 | |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 683 | bl_init_error: |
| 684 | unregister_framebuffer(info); |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 685 | panel_init_error: |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 686 | if (par->device_info->need_pwm) { |
| 687 | pwm_disable(par->pwm); |
| 688 | pwm_put(par->pwm); |
| 689 | }; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 690 | reset_oled_error: |
| 691 | fb_deferred_io_cleanup(info); |
| 692 | fb_alloc_error: |
| 693 | framebuffer_release(info); |
| 694 | return ret; |
| 695 | } |
| 696 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 697 | static int ssd1307fb_remove(struct i2c_client *client) |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 698 | { |
| 699 | struct fb_info *info = i2c_get_clientdata(client); |
| 700 | struct ssd1307fb_par *par = info->par; |
| 701 | |
Thomas Niederprüm | 13bad59 | 2015-03-31 20:27:14 +0200 | [diff] [blame] | 702 | ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_OFF); |
| 703 | |
Thomas Niederprüm | 6ed5e2d | 2015-03-31 20:27:15 +0200 | [diff] [blame] | 704 | backlight_device_unregister(info->bl_dev); |
| 705 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 706 | unregister_framebuffer(info); |
Thomas Niederprüm | c89eacf | 2015-03-31 20:27:10 +0200 | [diff] [blame] | 707 | if (par->device_info->need_pwm) { |
| 708 | pwm_disable(par->pwm); |
| 709 | pwm_put(par->pwm); |
| 710 | }; |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 711 | fb_deferred_io_cleanup(info); |
Thomas Niederprüm | facd94b | 2015-03-31 20:27:08 +0200 | [diff] [blame] | 712 | __free_pages(__va(info->fix.smem_start), get_order(info->fix.smem_len)); |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 713 | framebuffer_release(info); |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | static const struct i2c_device_id ssd1307fb_i2c_id[] = { |
Thomas Niederprüm | 5f2d36b | 2015-03-31 20:27:12 +0200 | [diff] [blame] | 719 | { "ssd1305fb", 0 }, |
Maxime Ripard | bbc7908 | 2013-04-22 11:55:54 +0200 | [diff] [blame] | 720 | { "ssd1306fb", 0 }, |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 721 | { "ssd1307fb", 0 }, |
Olliver Schinagl | 3ac58d5 | 2015-09-08 21:19:51 +0200 | [diff] [blame] | 722 | { "ssd1309fb", 0 }, |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 723 | { } |
| 724 | }; |
| 725 | MODULE_DEVICE_TABLE(i2c, ssd1307fb_i2c_id); |
| 726 | |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 727 | static struct i2c_driver ssd1307fb_driver = { |
| 728 | .probe = ssd1307fb_probe, |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 729 | .remove = ssd1307fb_remove, |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 730 | .id_table = ssd1307fb_i2c_id, |
| 731 | .driver = { |
| 732 | .name = "ssd1307fb", |
Sachin Kamat | d71f8cd | 2013-09-30 14:15:31 +0530 | [diff] [blame] | 733 | .of_match_table = ssd1307fb_of_match, |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 734 | }, |
| 735 | }; |
| 736 | |
| 737 | module_i2c_driver(ssd1307fb_driver); |
| 738 | |
Masanari Iida | a895d57 | 2013-04-09 02:06:50 +0900 | [diff] [blame] | 739 | MODULE_DESCRIPTION("FB driver for the Solomon SSD1307 OLED controller"); |
Maxime Ripard | a2ed00d | 2012-12-07 12:30:38 -0800 | [diff] [blame] | 740 | MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); |
| 741 | MODULE_LICENSE("GPL"); |