Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v4.10 400 lines 9.6 kB view raw
1/* 2 * NEC NL8048HL11 Panel driver 3 * 4 * Copyright (C) 2010 Texas Instruments Inc. 5 * Author: Erik Gilling <konkers@android.com> 6 * Converted to new DSS device model: Tomi Valkeinen <tomi.valkeinen@ti.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 */ 13 14#include <linux/module.h> 15#include <linux/delay.h> 16#include <linux/spi/spi.h> 17#include <linux/gpio/consumer.h> 18#include <linux/of_gpio.h> 19 20#include "../dss/omapdss.h" 21 22struct panel_drv_data { 23 struct omap_dss_device dssdev; 24 struct omap_dss_device *in; 25 26 struct videomode vm; 27 28 int data_lines; 29 30 int res_gpio; 31 int qvga_gpio; 32 33 struct spi_device *spi; 34}; 35 36#define LCD_XRES 800 37#define LCD_YRES 480 38/* 39 * NEC PIX Clock Ratings 40 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz 41 */ 42#define LCD_PIXEL_CLOCK 23800000 43 44static const struct { 45 unsigned char addr; 46 unsigned char dat; 47} nec_8048_init_seq[] = { 48 { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 }, 49 { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 }, 50 { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 }, 51 { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F }, 52 { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F }, 53 { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F }, 54 { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F }, 55 { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 }, 56 { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 }, 57 { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C }, 58 { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 }, 59 { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 }, 60 { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 }, 61 { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 }, 62 { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC }, 63 { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 }, 64 { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 }, 65 { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 }, 66}; 67 68static const struct videomode nec_8048_panel_vm = { 69 .hactive = LCD_XRES, 70 .vactive = LCD_YRES, 71 .pixelclock = LCD_PIXEL_CLOCK, 72 .hfront_porch = 6, 73 .hsync_len = 1, 74 .hback_porch = 4, 75 .vfront_porch = 3, 76 .vsync_len = 1, 77 .vback_porch = 4, 78 79 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 80 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE | 81 DISPLAY_FLAGS_PIXDATA_POSEDGE, 82}; 83 84#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 85 86static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr, 87 unsigned char reg_data) 88{ 89 int ret = 0; 90 unsigned int cmd = 0, data = 0; 91 92 cmd = 0x0000 | reg_addr; /* register address write */ 93 data = 0x0100 | reg_data; /* register data write */ 94 data = (cmd << 16) | data; 95 96 ret = spi_write(spi, (unsigned char *)&data, 4); 97 if (ret) 98 pr_err("error in spi_write %x\n", data); 99 100 return ret; 101} 102 103static int init_nec_8048_wvga_lcd(struct spi_device *spi) 104{ 105 unsigned int i; 106 /* Initialization Sequence */ 107 /* nec_8048_spi_send(spi, REG, VAL) */ 108 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++) 109 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr, 110 nec_8048_init_seq[i].dat); 111 udelay(20); 112 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr, 113 nec_8048_init_seq[i].dat); 114 return 0; 115} 116 117static int nec_8048_connect(struct omap_dss_device *dssdev) 118{ 119 struct panel_drv_data *ddata = to_panel_data(dssdev); 120 struct omap_dss_device *in = ddata->in; 121 int r; 122 123 if (omapdss_device_is_connected(dssdev)) 124 return 0; 125 126 r = in->ops.dpi->connect(in, dssdev); 127 if (r) 128 return r; 129 130 return 0; 131} 132 133static void nec_8048_disconnect(struct omap_dss_device *dssdev) 134{ 135 struct panel_drv_data *ddata = to_panel_data(dssdev); 136 struct omap_dss_device *in = ddata->in; 137 138 if (!omapdss_device_is_connected(dssdev)) 139 return; 140 141 in->ops.dpi->disconnect(in, dssdev); 142} 143 144static int nec_8048_enable(struct omap_dss_device *dssdev) 145{ 146 struct panel_drv_data *ddata = to_panel_data(dssdev); 147 struct omap_dss_device *in = ddata->in; 148 int r; 149 150 if (!omapdss_device_is_connected(dssdev)) 151 return -ENODEV; 152 153 if (omapdss_device_is_enabled(dssdev)) 154 return 0; 155 156 if (ddata->data_lines) 157 in->ops.dpi->set_data_lines(in, ddata->data_lines); 158 in->ops.dpi->set_timings(in, &ddata->vm); 159 160 r = in->ops.dpi->enable(in); 161 if (r) 162 return r; 163 164 if (gpio_is_valid(ddata->res_gpio)) 165 gpio_set_value_cansleep(ddata->res_gpio, 1); 166 167 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 168 169 return 0; 170} 171 172static void nec_8048_disable(struct omap_dss_device *dssdev) 173{ 174 struct panel_drv_data *ddata = to_panel_data(dssdev); 175 struct omap_dss_device *in = ddata->in; 176 177 if (!omapdss_device_is_enabled(dssdev)) 178 return; 179 180 if (gpio_is_valid(ddata->res_gpio)) 181 gpio_set_value_cansleep(ddata->res_gpio, 0); 182 183 in->ops.dpi->disable(in); 184 185 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 186} 187 188static void nec_8048_set_timings(struct omap_dss_device *dssdev, 189 struct videomode *vm) 190{ 191 struct panel_drv_data *ddata = to_panel_data(dssdev); 192 struct omap_dss_device *in = ddata->in; 193 194 ddata->vm = *vm; 195 dssdev->panel.vm = *vm; 196 197 in->ops.dpi->set_timings(in, vm); 198} 199 200static void nec_8048_get_timings(struct omap_dss_device *dssdev, 201 struct videomode *vm) 202{ 203 struct panel_drv_data *ddata = to_panel_data(dssdev); 204 205 *vm = ddata->vm; 206} 207 208static int nec_8048_check_timings(struct omap_dss_device *dssdev, 209 struct videomode *vm) 210{ 211 struct panel_drv_data *ddata = to_panel_data(dssdev); 212 struct omap_dss_device *in = ddata->in; 213 214 return in->ops.dpi->check_timings(in, vm); 215} 216 217static struct omap_dss_driver nec_8048_ops = { 218 .connect = nec_8048_connect, 219 .disconnect = nec_8048_disconnect, 220 221 .enable = nec_8048_enable, 222 .disable = nec_8048_disable, 223 224 .set_timings = nec_8048_set_timings, 225 .get_timings = nec_8048_get_timings, 226 .check_timings = nec_8048_check_timings, 227 228 .get_resolution = omapdss_default_get_resolution, 229}; 230 231static int nec_8048_probe_of(struct spi_device *spi) 232{ 233 struct device_node *node = spi->dev.of_node; 234 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev); 235 struct omap_dss_device *in; 236 int gpio; 237 238 gpio = of_get_named_gpio(node, "reset-gpios", 0); 239 if (!gpio_is_valid(gpio)) { 240 dev_err(&spi->dev, "failed to parse enable gpio\n"); 241 return gpio; 242 } 243 ddata->res_gpio = gpio; 244 245 /* XXX the panel spec doesn't mention any QVGA pin?? */ 246 ddata->qvga_gpio = -ENOENT; 247 248 in = omapdss_of_find_source_for_first_ep(node); 249 if (IS_ERR(in)) { 250 dev_err(&spi->dev, "failed to find video source\n"); 251 return PTR_ERR(in); 252 } 253 254 ddata->in = in; 255 256 return 0; 257} 258 259static int nec_8048_probe(struct spi_device *spi) 260{ 261 struct panel_drv_data *ddata; 262 struct omap_dss_device *dssdev; 263 int r; 264 265 dev_dbg(&spi->dev, "%s\n", __func__); 266 267 spi->mode = SPI_MODE_0; 268 spi->bits_per_word = 32; 269 270 r = spi_setup(spi); 271 if (r < 0) { 272 dev_err(&spi->dev, "spi_setup failed: %d\n", r); 273 return r; 274 } 275 276 init_nec_8048_wvga_lcd(spi); 277 278 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL); 279 if (ddata == NULL) 280 return -ENOMEM; 281 282 dev_set_drvdata(&spi->dev, ddata); 283 284 ddata->spi = spi; 285 286 if (!spi->dev.of_node) 287 return -ENODEV; 288 289 r = nec_8048_probe_of(spi); 290 if (r) 291 return r; 292 293 if (gpio_is_valid(ddata->qvga_gpio)) { 294 r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio, 295 GPIOF_OUT_INIT_HIGH, "lcd QVGA"); 296 if (r) 297 goto err_gpio; 298 } 299 300 if (gpio_is_valid(ddata->res_gpio)) { 301 r = devm_gpio_request_one(&spi->dev, ddata->res_gpio, 302 GPIOF_OUT_INIT_LOW, "lcd RES"); 303 if (r) 304 goto err_gpio; 305 } 306 307 ddata->vm = nec_8048_panel_vm; 308 309 dssdev = &ddata->dssdev; 310 dssdev->dev = &spi->dev; 311 dssdev->driver = &nec_8048_ops; 312 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 313 dssdev->owner = THIS_MODULE; 314 dssdev->panel.vm = ddata->vm; 315 316 r = omapdss_register_display(dssdev); 317 if (r) { 318 dev_err(&spi->dev, "Failed to register panel\n"); 319 goto err_reg; 320 } 321 322 return 0; 323 324err_reg: 325err_gpio: 326 omap_dss_put_device(ddata->in); 327 return r; 328} 329 330static int nec_8048_remove(struct spi_device *spi) 331{ 332 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev); 333 struct omap_dss_device *dssdev = &ddata->dssdev; 334 struct omap_dss_device *in = ddata->in; 335 336 dev_dbg(&ddata->spi->dev, "%s\n", __func__); 337 338 omapdss_unregister_display(dssdev); 339 340 nec_8048_disable(dssdev); 341 nec_8048_disconnect(dssdev); 342 343 omap_dss_put_device(in); 344 345 return 0; 346} 347 348#ifdef CONFIG_PM_SLEEP 349static int nec_8048_suspend(struct device *dev) 350{ 351 struct spi_device *spi = to_spi_device(dev); 352 353 nec_8048_spi_send(spi, 2, 0x01); 354 mdelay(40); 355 356 return 0; 357} 358 359static int nec_8048_resume(struct device *dev) 360{ 361 struct spi_device *spi = to_spi_device(dev); 362 363 /* reinitialize the panel */ 364 spi_setup(spi); 365 nec_8048_spi_send(spi, 2, 0x00); 366 init_nec_8048_wvga_lcd(spi); 367 368 return 0; 369} 370static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend, 371 nec_8048_resume); 372#define NEC_8048_PM_OPS (&nec_8048_pm_ops) 373#else 374#define NEC_8048_PM_OPS NULL 375#endif 376 377static const struct of_device_id nec_8048_of_match[] = { 378 { .compatible = "omapdss,nec,nl8048hl11", }, 379 {}, 380}; 381 382MODULE_DEVICE_TABLE(of, nec_8048_of_match); 383 384static struct spi_driver nec_8048_driver = { 385 .driver = { 386 .name = "panel-nec-nl8048hl11", 387 .pm = NEC_8048_PM_OPS, 388 .of_match_table = nec_8048_of_match, 389 .suppress_bind_attrs = true, 390 }, 391 .probe = nec_8048_probe, 392 .remove = nec_8048_remove, 393}; 394 395module_spi_driver(nec_8048_driver); 396 397MODULE_ALIAS("spi:nec,nl8048hl11"); 398MODULE_AUTHOR("Erik Gilling <konkers@android.com>"); 399MODULE_DESCRIPTION("NEC-NL8048HL11 Driver"); 400MODULE_LICENSE("GPL");