^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * sky81452-backlight.c SKY81452 backlight driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2014 Skyworks Solutions Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define SKY81452_REG0 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define SKY81452_REG1 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define SKY81452_REG2 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define SKY81452_REG4 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SKY81452_REG5 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* bit mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SKY81452_CS 0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SKY81452_EN 0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SKY81452_IGPW 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SKY81452_PWMMD 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define SKY81452_PHASE 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define SKY81452_ILIM 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define SKY81452_VSHRT 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define SKY81452_OCP 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define SKY81452_OTMP 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define SKY81452_SHRT 0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define SKY81452_OPN 0x3F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define SKY81452_DEFAULT_NAME "lcd-backlight"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define SKY81452_MAX_BRIGHTNESS (SKY81452_CS + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * struct sky81452_platform_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @name: backlight driver name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * If it is not defined, default name is lcd-backlight.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @gpiod_enable:GPIO descriptor which control EN pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @enable: Enable mask for current sink channel 1, 2, 3, 4, 5 and 6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @ignore_pwm: true if DPWMI should be ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @dpwm_mode: true is DPWM dimming mode, otherwise Analog dimming mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @phase_shift:true is phase shift mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @short_detection_threshold: It should be one of 4, 5, 6 and 7V.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @boost_current_limit: It should be one of 2300, 2750mA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct sky81452_bl_platform_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct gpio_desc *gpiod_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned int enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) bool ignore_pwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) bool dpwm_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) bool phase_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned int short_detection_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned int boost_current_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define CTZ(b) __builtin_ctz(b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int sky81452_bl_update_status(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) const struct sky81452_bl_platform_data *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dev_get_platdata(bd->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const unsigned int brightness = (unsigned int)bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct regmap *regmap = bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (brightness > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ret = regmap_write(regmap, SKY81452_REG0, brightness - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return regmap_update_bits(regmap, SKY81452_REG1, SKY81452_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) pdata->enable << CTZ(SKY81452_EN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return regmap_update_bits(regmap, SKY81452_REG1, SKY81452_EN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static const struct backlight_ops sky81452_bl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .update_status = sky81452_bl_update_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static ssize_t sky81452_bl_store_enable(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct regmap *regmap = bl_get_data(to_backlight_device(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ret = kstrtoul(buf, 16, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret = regmap_update_bits(regmap, SKY81452_REG1, SKY81452_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) value << CTZ(SKY81452_EN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static ssize_t sky81452_bl_show_open_short(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct regmap *regmap = bl_get_data(to_backlight_device(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unsigned int reg, value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) char tmp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) reg = !strcmp(attr->attr.name, "open") ? SKY81452_REG5 : SKY81452_REG4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = regmap_read(regmap, reg, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (value & SKY81452_SHRT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *buf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) for (i = 0; i < 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (value & 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) sprintf(tmp, "%d ", i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) strcat(buf, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) value >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) strcat(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) strcpy(buf, "none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return strlen(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static ssize_t sky81452_bl_show_fault(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct regmap *regmap = bl_get_data(to_backlight_device(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned int value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ret = regmap_read(regmap, SKY81452_REG4, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *buf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (value & SKY81452_OCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) strcat(buf, "over-current ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (value & SKY81452_OTMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) strcat(buf, "over-temperature");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) strcat(buf, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return strlen(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static DEVICE_ATTR(enable, S_IWGRP | S_IWUSR, NULL, sky81452_bl_store_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static DEVICE_ATTR(open, S_IRUGO, sky81452_bl_show_open_short, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static DEVICE_ATTR(short, S_IRUGO, sky81452_bl_show_open_short, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static DEVICE_ATTR(fault, S_IRUGO, sky81452_bl_show_fault, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static struct attribute *sky81452_bl_attribute[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) &dev_attr_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) &dev_attr_open.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) &dev_attr_short.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) &dev_attr_fault.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static const struct attribute_group sky81452_bl_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .attrs = sky81452_bl_attribute,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct device_node *np = of_node_get(dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct sky81452_bl_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int num_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) unsigned int sources[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_err(dev, "backlight node not found.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return ERR_PTR(-ENODATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) of_property_read_string(np, "name", &pdata->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) pdata->ignore_pwm = of_property_read_bool(np, "skyworks,ignore-pwm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) pdata->gpiod_enable = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ret = of_property_count_u32_elems(np, "led-sources");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pdata->enable = SKY81452_EN >> CTZ(SKY81452_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) num_entry = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (num_entry > 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) num_entry = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ret = of_property_read_u32_array(np, "led-sources", sources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) num_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dev_err(dev, "led-sources node is invalid.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pdata->enable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) while (--num_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pdata->enable |= (1 << sources[num_entry]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ret = of_property_read_u32(np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) "skyworks,short-detection-threshold-volt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) &pdata->short_detection_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) pdata->short_detection_threshold = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ret = of_property_read_u32(np, "skyworks,current-limit-mA",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) &pdata->boost_current_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pdata->boost_current_limit = 2750;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int sky81452_bl_init_device(struct regmap *regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct sky81452_bl_platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) value = pdata->ignore_pwm ? SKY81452_IGPW : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) value |= pdata->dpwm_mode ? SKY81452_PWMMD : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) value |= pdata->phase_shift ? 0 : SKY81452_PHASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (pdata->boost_current_limit == 2300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) value |= SKY81452_ILIM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) else if (pdata->boost_current_limit != 2750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (pdata->short_detection_threshold < 4 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) pdata->short_detection_threshold > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) value |= (7 - pdata->short_detection_threshold) << CTZ(SKY81452_VSHRT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return regmap_write(regmap, SKY81452_REG2, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static int sky81452_bl_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct regmap *regmap = dev_get_drvdata(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct sky81452_bl_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct backlight_device *bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) pdata = sky81452_bl_parse_dt(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (IS_ERR(pdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return PTR_ERR(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ret = sky81452_bl_init_device(regmap, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) dev_err(dev, "failed to initialize. err=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) memset(&props, 0, sizeof(props));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) props.max_brightness = SKY81452_MAX_BRIGHTNESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) name = pdata->name ? pdata->name : SKY81452_DEFAULT_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) bd = devm_backlight_device_register(dev, name, dev, regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) &sky81452_bl_ops, &props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (IS_ERR(bd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(bd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return PTR_ERR(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) platform_set_drvdata(pdev, bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ret = sysfs_create_group(&bd->dev.kobj, &sky81452_bl_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) dev_err(dev, "failed to create attribute. err=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int sky81452_bl_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) const struct sky81452_bl_platform_data *pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct backlight_device *bd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) sysfs_remove_group(&bd->dev.kobj, &sky81452_bl_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) bd->props.power = FB_BLANK_UNBLANK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) bd->props.brightness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) backlight_update_status(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (pdata->gpiod_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) gpiod_set_value_cansleep(pdata->gpiod_enable, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static const struct of_device_id sky81452_bl_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) { .compatible = "skyworks,sky81452-backlight", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) MODULE_DEVICE_TABLE(of, sky81452_bl_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static struct platform_driver sky81452_bl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .name = "sky81452-backlight",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .of_match_table = of_match_ptr(sky81452_bl_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .probe = sky81452_bl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .remove = sky81452_bl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) module_platform_driver(sky81452_bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) MODULE_DESCRIPTION("Skyworks SKY81452 backlight driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) MODULE_LICENSE("GPL v2");