^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Maxim MAX96745 MFD driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/i2c-mux.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mfd/max96745.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct max96745 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct i2c_mux_core *muxc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct gpio_desc *enable_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct gpio_desc *lock_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static const struct mfd_cell max96745_devs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .name = "max96745-pinctrl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .of_compatible = "maxim,max96745-pinctrl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .name = "max96745-bridge",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .of_compatible = "maxim,max96745-bridge",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static bool max96745_volatile_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) case 0x0028 ... 0x0029:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) case 0x0032 ... 0x0033:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) case 0x0076:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case 0x0086:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) case 0x0100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) case 0x0200 ... 0x02ce:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) case 0x7000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) case 0x7070:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) case 0x7074:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static const struct regmap_config max96745_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .name = "max96745",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .reg_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .max_register = 0x8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .volatile_reg = max96745_volatile_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .cache_type = REGCACHE_RBTREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int max96745_select(struct i2c_mux_core *muxc, u32 chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct max96745 *max96745 = dev_get_drvdata(muxc->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (chan == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) regmap_update_bits(max96745->regmap, 0x0086, DIS_REM_CC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) FIELD_PREP(DIS_REM_CC, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) regmap_update_bits(max96745->regmap, 0x0076, DIS_REM_CC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) FIELD_PREP(DIS_REM_CC, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int max96745_deselect(struct i2c_mux_core *muxc, u32 chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct max96745 *max96745 = dev_get_drvdata(muxc->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (chan == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) regmap_update_bits(max96745->regmap, 0x0086, DIS_REM_CC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) FIELD_PREP(DIS_REM_CC, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) regmap_update_bits(max96745->regmap, 0x0076, DIS_REM_CC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) FIELD_PREP(DIS_REM_CC, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static void max96745_power_off(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct max96745 *max96745 = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (max96745->enable_gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) gpiod_direction_output(max96745->enable_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void max96745_power_on(struct max96745 *max96745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret = regmap_read(max96745->regmap, 0x0107, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (!ret && FIELD_GET(VID_TX_ACTIVE_A | VID_TX_ACTIVE_B, val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (max96745->enable_gpio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) gpiod_direction_output(max96745->enable_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) msleep(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) regmap_update_bits(max96745->regmap, 0x0076, DIS_REM_CC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) FIELD_PREP(DIS_REM_CC, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) regmap_update_bits(max96745->regmap, 0x0086, DIS_REM_CC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) FIELD_PREP(DIS_REM_CC, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static ssize_t line_fault_monitor_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct max96745 *max96745 = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 pu_lf, lf, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) regmap_read(max96745->regmap, 0x0005, &pu_lf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Line-fault status of wire connected to LMN0/1/2/3 pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * 0b000: Short to battery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * 0b001: Short to GND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * 0b010: Normal operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * 0b011: Line open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * 0b1XX: Line-to-line short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) regmap_read(max96745->regmap, 0x0026, &lf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (FIELD_GET(PU_LF0, pu_lf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) status = (lf & LF_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return sprintf(buf, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (FIELD_GET(PU_LF1, pu_lf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) status = (lf & LF_1) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return sprintf(buf, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) regmap_read(max96745->regmap, 0x0027, &lf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (FIELD_GET(PU_LF2, pu_lf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) status = (lf & LF_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return sprintf(buf, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (FIELD_GET(PU_LF3, pu_lf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) status = (lf & LF_3) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return sprintf(buf, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return sprintf(buf, "%d\n", -EINVAL);
^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_RO(line_fault_monitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static struct attribute *max96745_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) &dev_attr_line_fault_monitor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static const struct attribute_group max96745_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .attrs = max96745_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int max96745_sysfs_add(struct max96745 *max96745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct device *dev = max96745->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u32 ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ret = of_property_read_u32(dev->of_node, "line-fault-monitor", &ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) regmap_update_bits(max96745->regmap, 0x0005,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) PU_LF0 << ch, PU_LF0 << ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ret = devm_device_add_group(dev, &max96745_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) dev_err(dev, "failed to register sysfs. err: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static int max96745_i2c_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct device_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct max96745 *max96745;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) unsigned int nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) bool idle_disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) for_each_available_child_of_node(dev->of_node, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!of_find_property(child, "reg", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) max96745 = devm_kzalloc(dev, sizeof(*max96745), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (!max96745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) idle_disc = device_property_read_bool(dev, "i2c-mux-idle-disconnect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) max96745->muxc = i2c_mux_alloc(client->adapter, dev, nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 0, I2C_MUX_LOCKED, max96745_select,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) idle_disc ? max96745_deselect : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!max96745->muxc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) max96745->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) i2c_set_clientdata(client, max96745);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) max96745->regmap = devm_regmap_init_i2c(client, &max96745_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (IS_ERR(max96745->regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return dev_err_probe(dev, PTR_ERR(max96745->regmap),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) "failed to initialize regmap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) max96745->enable_gpio = devm_gpiod_get_optional(dev, "enable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) GPIOD_ASIS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (IS_ERR(max96745->enable_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return dev_err_probe(dev, PTR_ERR(max96745->enable_gpio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) "failed to get enable GPIO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) max96745->lock_gpio = devm_gpiod_get_optional(dev, "lock", GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (IS_ERR(max96745->lock_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return dev_err_probe(dev, PTR_ERR(max96745->lock_gpio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) "failed to get lock GPIO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) max96745_power_on(max96745);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ret = devm_add_action_or_reset(dev, max96745_power_off, max96745);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, max96745_devs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ARRAY_SIZE(max96745_devs), NULL, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) for_each_available_child_of_node(dev->of_node, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (of_property_read_u32(child, "reg", &nr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ret = i2c_mux_add_adapter(max96745->muxc, 0, nr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) i2c_mux_del_adapters(max96745->muxc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ret = max96745_sysfs_add(max96745);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return dev_err_probe(dev, ret, "failed to registers sysfs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static int max96745_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct max96745 *max96745 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) i2c_mux_del_adapters(max96745->muxc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static void max96745_i2c_shutdown(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct max96745 *max96745 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) max96745_power_off(max96745);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int __maybe_unused max96745_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct max96745 *max96745 = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) regcache_mark_dirty(max96745->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) regcache_cache_only(max96745->regmap, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int __maybe_unused max96745_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct max96745 *max96745 = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) regcache_cache_only(max96745->regmap, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) regcache_sync(max96745->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static SIMPLE_DEV_PM_OPS(max96745_pm_ops, max96745_suspend, max96745_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static const struct of_device_id max96745_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) { .compatible = "maxim,max96745", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_DEVICE_TABLE(of, max96745_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static struct i2c_driver max96745_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) .name = "max96745",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .of_match_table = max96745_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .pm = &max96745_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .probe_new = max96745_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .remove = max96745_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .shutdown = max96745_i2c_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) module_i2c_driver(max96745_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) MODULE_AUTHOR("Wyon Bi <bivvy.bi@rock-chips.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) MODULE_DESCRIPTION("Maxim MAX96745 MFD driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) MODULE_LICENSE("GPL");