Lines Matching +full:- +full:spi

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * controller. The interface to the display is SPI and the display's
20 #include <linux/spi/spi.h>
89 * ----------------------------------
91 * ----------------------------------
94 * - START_RS_INDEX set the index register
95 * - START_RS_REG write/read registers/GRAM
97 * - START_RW_WRITE write
98 * - START_RW_READ read
104 * CHECK_FREQ_REG(spi_device s, spi_transfer x) - Check the frequency
105 * for the SPI transfer. According to the datasheet, the controller
110 * @s: pointer to an SPI device
115 if (s->max_speed_hz > ILITEK_MAX_FREQ_REG) \
116 ((struct spi_transfer *)x)->speed_hz = \
127 * ili922x_id - id as set by manufacturer
139 struct spi_device *spi; member
145 * ili922x_read_status - read status register from display
146 * @spi: spi device
149 static int ili922x_read_status(struct spi_device *spi, u16 *rs) in ili922x_read_status() argument
162 CHECK_FREQ_REG(spi, &xfer); in ili922x_read_status()
167 * we need 4-byte xfer here due to invalid dummy byte in ili922x_read_status()
176 ret = spi_sync(spi, &msg); in ili922x_read_status()
178 dev_dbg(&spi->dev, "Error sending SPI message 0x%x", ret); in ili922x_read_status()
187 * ili922x_read - read register from display
188 * @spi: spi device
192 static int ili922x_read(struct spi_device *spi, u8 reg, u16 *rx) in ili922x_read() argument
206 CHECK_FREQ_REG(spi, &xfer_regindex); in ili922x_read()
227 CHECK_FREQ_REG(spi, &xfer_regvalue); in ili922x_read()
230 ret = spi_sync(spi, &msg); in ili922x_read()
232 dev_dbg(&spi->dev, "Error sending SPI message 0x%x", ret); in ili922x_read()
241 * ili922x_write - write a controller register
242 * @spi: struct spi_device *
246 static int ili922x_write(struct spi_device *spi, u8 reg, u16 value) in ili922x_write() argument
261 CHECK_FREQ_REG(spi, &xfer_regindex); in ili922x_write()
271 ret = spi_sync(spi, &msg); in ili922x_write()
273 dev_err(&spi->dev, "Error sending SPI message 0x%x", ret); in ili922x_write()
287 CHECK_FREQ_REG(spi, &xfer_regvalue); in ili922x_write()
291 ret = spi_sync(spi, &msg); in ili922x_write()
293 dev_err(&spi->dev, "Error sending SPI message 0x%x", ret); in ili922x_write()
301 * ili922x_reg_dump - dump all registers
303 * @spi: pointer to an SPI device
305 static void ili922x_reg_dump(struct spi_device *spi) in ili922x_reg_dump() argument
310 dev_dbg(&spi->dev, "ILI922x configuration registers:\n"); in ili922x_reg_dump()
313 ili922x_read(spi, reg, &rx); in ili922x_reg_dump()
314 dev_dbg(&spi->dev, "reg @ 0x%02X: 0x%04X\n", reg, rx); in ili922x_reg_dump()
318 static inline void ili922x_reg_dump(struct spi_device *spi) {} in ili922x_reg_dump() argument
322 * set_write_to_gram_reg - initialize the display to write the GRAM
323 * @spi: spi device
325 static void set_write_to_gram_reg(struct spi_device *spi) in set_write_to_gram_reg() argument
345 spi_sync(spi, &msg); in set_write_to_gram_reg()
349 * ili922x_poweron - turn the display on
350 * @spi: spi device
356 static int ili922x_poweron(struct spi_device *spi) in ili922x_poweron() argument
361 ret = ili922x_write(spi, REG_POWER_CONTROL_1, 0x0000); in ili922x_poweron()
363 ret += ili922x_write(spi, REG_POWER_CONTROL_2, 0x0000); in ili922x_poweron()
364 ret += ili922x_write(spi, REG_POWER_CONTROL_3, 0x0000); in ili922x_poweron()
366 ret += ili922x_write(spi, REG_POWER_CONTROL_4, 0x0000); in ili922x_poweron()
369 ret += ili922x_write(spi, 0x56, 0x080F); in ili922x_poweron()
370 ret += ili922x_write(spi, REG_POWER_CONTROL_1, 0x4240); in ili922x_poweron()
372 ret += ili922x_write(spi, REG_POWER_CONTROL_2, 0x0000); in ili922x_poweron()
373 ret += ili922x_write(spi, REG_POWER_CONTROL_3, 0x0014); in ili922x_poweron()
375 ret += ili922x_write(spi, REG_POWER_CONTROL_4, 0x1319); in ili922x_poweron()
382 * ili922x_poweroff - turn the display off
383 * @spi: spi device
385 static int ili922x_poweroff(struct spi_device *spi) in ili922x_poweroff() argument
390 ret = ili922x_write(spi, REG_POWER_CONTROL_1, 0x0000); in ili922x_poweroff()
392 ret += ili922x_write(spi, REG_POWER_CONTROL_2, 0x0000); in ili922x_poweroff()
393 ret += ili922x_write(spi, REG_POWER_CONTROL_3, 0x0000); in ili922x_poweroff()
395 ret += ili922x_write(spi, REG_POWER_CONTROL_4, 0x0000); in ili922x_poweroff()
402 * ili922x_display_init - initialize the display by setting
404 * @spi: spi device
406 static void ili922x_display_init(struct spi_device *spi) in ili922x_display_init() argument
408 ili922x_write(spi, REG_START_OSCILLATION, 1); in ili922x_display_init()
410 ili922x_write(spi, REG_DRIVER_OUTPUT_CONTROL, 0x691B); in ili922x_display_init()
411 ili922x_write(spi, REG_LCD_AC_DRIVEING_CONTROL, 0x0700); in ili922x_display_init()
412 ili922x_write(spi, REG_ENTRY_MODE, 0x1030); in ili922x_display_init()
413 ili922x_write(spi, REG_COMPARE_1, 0x0000); in ili922x_display_init()
414 ili922x_write(spi, REG_COMPARE_2, 0x0000); in ili922x_display_init()
415 ili922x_write(spi, REG_DISPLAY_CONTROL_1, 0x0037); in ili922x_display_init()
416 ili922x_write(spi, REG_DISPLAY_CONTROL_2, 0x0202); in ili922x_display_init()
417 ili922x_write(spi, REG_DISPLAY_CONTROL_3, 0x0000); in ili922x_display_init()
418 ili922x_write(spi, REG_FRAME_CYCLE_CONTROL, 0x0000); in ili922x_display_init()
421 ili922x_write(spi, REG_EXT_INTF_CONTROL, 0x0110); in ili922x_display_init()
423 ili922x_poweron(spi); in ili922x_display_init()
425 ili922x_write(spi, REG_GAMMA_CONTROL_1, 0x0302); in ili922x_display_init()
426 ili922x_write(spi, REG_GAMMA_CONTROL_2, 0x0407); in ili922x_display_init()
427 ili922x_write(spi, REG_GAMMA_CONTROL_3, 0x0304); in ili922x_display_init()
428 ili922x_write(spi, REG_GAMMA_CONTROL_4, 0x0203); in ili922x_display_init()
429 ili922x_write(spi, REG_GAMMA_CONTROL_5, 0x0706); in ili922x_display_init()
430 ili922x_write(spi, REG_GAMMA_CONTROL_6, 0x0407); in ili922x_display_init()
431 ili922x_write(spi, REG_GAMMA_CONTROL_7, 0x0706); in ili922x_display_init()
432 ili922x_write(spi, REG_GAMMA_CONTROL_8, 0x0000); in ili922x_display_init()
433 ili922x_write(spi, REG_GAMMA_CONTROL_9, 0x0C06); in ili922x_display_init()
434 ili922x_write(spi, REG_GAMMA_CONTROL_10, 0x0F00); in ili922x_display_init()
435 ili922x_write(spi, REG_RAM_ADDRESS_SET, 0x0000); in ili922x_display_init()
436 ili922x_write(spi, REG_GATE_SCAN_CONTROL, 0x0000); in ili922x_display_init()
437 ili922x_write(spi, REG_VERT_SCROLL_CONTROL, 0x0000); in ili922x_display_init()
438 ili922x_write(spi, REG_FIRST_SCREEN_DRIVE_POS, 0xDB00); in ili922x_display_init()
439 ili922x_write(spi, REG_SECOND_SCREEN_DRIVE_POS, 0xDB00); in ili922x_display_init()
440 ili922x_write(spi, REG_RAM_ADDR_POS_H, 0xAF00); in ili922x_display_init()
441 ili922x_write(spi, REG_RAM_ADDR_POS_V, 0xDB00); in ili922x_display_init()
442 ili922x_reg_dump(spi); in ili922x_display_init()
443 set_write_to_gram_reg(spi); in ili922x_display_init()
450 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power)) in ili922x_lcd_power()
451 ret = ili922x_poweron(lcd->spi); in ili922x_lcd_power()
452 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power)) in ili922x_lcd_power()
453 ret = ili922x_poweroff(lcd->spi); in ili922x_lcd_power()
456 lcd->power = power; in ili922x_lcd_power()
472 return ili->power; in ili922x_get_power()
480 static int ili922x_probe(struct spi_device *spi) in ili922x_probe() argument
487 ili = devm_kzalloc(&spi->dev, sizeof(*ili), GFP_KERNEL); in ili922x_probe()
489 return -ENOMEM; in ili922x_probe()
491 ili->spi = spi; in ili922x_probe()
492 spi_set_drvdata(spi, ili); in ili922x_probe()
495 ret = ili922x_read(spi, REG_DRIVER_CODE_READ, &reg); in ili922x_probe()
497 dev_err(&spi->dev, in ili922x_probe()
500 return -ENODEV; in ili922x_probe()
503 dev_info(&spi->dev, "ILI%x found, SPI freq %d, mode %d\n", in ili922x_probe()
504 reg, spi->max_speed_hz, spi->mode); in ili922x_probe()
506 ret = ili922x_read_status(spi, &reg); in ili922x_probe()
508 dev_err(&spi->dev, "reading RS failed...\n"); in ili922x_probe()
512 dev_dbg(&spi->dev, "status: 0x%x\n", reg); in ili922x_probe()
514 ili922x_display_init(spi); in ili922x_probe()
516 ili->power = FB_BLANK_POWERDOWN; in ili922x_probe()
518 lcd = devm_lcd_device_register(&spi->dev, "ili922xlcd", &spi->dev, ili, in ili922x_probe()
521 dev_err(&spi->dev, "cannot register LCD\n"); in ili922x_probe()
525 ili->ld = lcd; in ili922x_probe()
526 spi_set_drvdata(spi, ili); in ili922x_probe()
533 static void ili922x_remove(struct spi_device *spi) in ili922x_remove() argument
535 ili922x_poweroff(spi); in ili922x_remove()